1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
// Copyright 2026 Mahmoud Harmouch.
//
// Licensed under the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
//! # Core Traits
//!
//! This module defines the foundational behavioural contracts used throughout the `lmm` crate.
//! Each trait abstracts a distinct capability - simulation, discovery, perception, prediction,
//! encoding, learning, and causal intervention - so that concrete types can be composed and
//! swapped without coupling algorithms to specific data structures.
use crateExpression;
use crateResult;
use crateTensor;
/// Implemented by any physical or mathematical system that can produce time-derivatives
/// of its own state vector, enabling numerical integration by [`crate::simulation::Simulator`].
///
/// # Required Methods
/// - `state` - returns a reference to the current state [`Tensor`].
/// - `evaluate_derivatives` - given a state vector, returns the corresponding derivatives.
///
/// # Examples
///
/// ```
/// use lmm::traits::Simulatable;
/// use lmm::tensor::Tensor;
/// use lmm::error::Result;
///
/// struct FreeParticle { state: Tensor }
///
/// impl Simulatable for FreeParticle {
/// fn state(&self) -> &Tensor { &self.state }
/// fn evaluate_derivatives(&self, state: &Tensor) -> Result<Tensor> {
/// Tensor::new(state.shape.clone(), vec![1.0; state.data.len()])
/// }
/// }
/// ```
/// use lmm::traits::Simulatable;
/// Implemented by algorithms that can infer governing [`Expression`]s from observed data.
///
/// # Examples
///
/// ```
/// use lmm::traits::Simulatable;
/// use lmm::tensor::Tensor;
/// use lmm::equation::Expression;
/// use lmm::traits::Discoverable;
/// use lmm::error::Result;
/// use lmm::discovery::SymbolicRegression;
///
/// let data = vec![Tensor::from_vec(vec![1.0]), Tensor::from_vec(vec![2.0])];
/// let targets = vec![2.0, 4.0];
/// let expr = SymbolicRegression::discover(&data, &targets).unwrap();
/// // Discovered expression should approximate 2*x
/// ```
/// use lmm::traits::Simulatable;
/// Implemented by sensors or modalities that can convert raw byte streams into [`Tensor`]s.
///
/// # Examples
///
/// ```
/// use lmm::traits::Simulatable;
/// use lmm::perception::MultiModalPerception;
/// use lmm::traits::Perceivable;
///
/// let raw = &[128u8, 64, 255, 0];
/// let tensor = MultiModalPerception::ingest(raw).unwrap();
/// assert_eq!(tensor.data.len(), 4);
/// assert!((tensor.data[0] - 128.0 / 255.0).abs() < 1e-9);
/// ```
/// Implemented by models that can extrapolate their state forward in time.
/// Implemented by models that can project an input [`Tensor`] into a latent representation.
/// Implemented by models whose parameters can be updated via gradient descent.
/// Implemented by causal models that support the `do(·)` intervention operator.
///
/// # See Also
/// - [Pearl, J. (2009). Causality. Cambridge University Press.](https://doi.org/10.1017/CBO9780511803161) - formalizes the `do(x)` operator semantic representing structural interventions.
// Copyright 2026 Mahmoud Harmouch.
//
// Licensed under the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.