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
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
//! InformationUniverse trait — the top-level abstraction.
//!
//! Per the Mathematical Constitution:
//! An Information Universe is a 6-tuple U = (S, T, O, R, I, K).
//! This module defines the trait that binds these components
//! together into a single type that the scientific cycle can
//! operate on.
//!
//! # The InformationUniverse trait
//!
//! A type implementing `InformationUniverse` represents a complete
//! experimental system. It owns or references:
//!
//! - **S** (state space): A collection of possible states, accessed
//! via `state_space()`.
//! - **T** (transformation set): The rules available for evolution,
//! accessed via `rules()`.
//! - **O** (observation operators): How states are perceived, accessed
//! via `observation()`.
//! - **K** (update schedule): The temporal structure, accessed via
//! `schedule()`.
//!
//! **R** (resource constraints) and **I** (invariant structure) are
//! not yet represented in the trait — they are placeholders for
//! future extensions.
//!
//! # Why a trait?
//!
//! The scientific cycle (`run_cycle`) operates on any type that
//! implements `InformationUniverse`. This means:
//!
//! - The Binary Graph Universe, Cellular Automata, and user-defined
//! substrates all use the same pipeline.
//! - The cycle doesn't need to know substrate-specific details.
//! - New substrates require only trait implementations, not changes
//! to ARCO's core.
//!
//! # Implementing InformationUniverse
//!
//! ```rust
//! use arco::observation::Observation;
//! use arco::rules::{NoContext, Rule};
//! use arco::schedule::Schedule;
//! use arco::state::State;
//! use arco::universe::InformationUniverse;
//!
//! use rand::Rng;
//!
//! fn main() {
//! let universe = MyUniverse {
//! states: vec![],
//! rules: vec![],
//! observer: MyObserver,
//! schedule: MySchedule,
//! };
//!
//! println!("{:?}", universe);
//! }
//!
//! #[derive(Clone, Debug, PartialEq, Eq, Hash)]
//! struct MyState {
//! data: Vec<u8>,
//! }
//!
//! impl State for MyState {
//! type Encoding = Vec<u8>;
//!
//! fn canonical_encoding(&self) -> Self::Encoding {
//! self.data.clone()
//! }
//!
//! fn distance(&self, other: &Self) -> u32 {
//! let mut d = 0u32;
//! for (a, b) in self.data.iter().zip(other.data.iter()) {
//! if a != b {
//! d += 1;
//! }
//! }
//!
//! d
//! }
//! }
//!
//! #[derive(Clone, Debug)]
//! struct MyRule;
//!
//! impl Rule<MyState> for MyRule {
//! type Context = NoContext;
//!
//! fn name(&self) -> &str {
//! "Rule"
//! }
//!
//! fn apply(&self, state: &MyState, _context: &Self::Context, _rng: &mut dyn Rng) -> MyState {
//! state.clone()
//! }
//! }
//!
//! #[derive(Debug)]
//! struct MyObserver;
//!
//! impl Observation<MyState> for MyObserver {
//! type Output = Vec<u8>;
//!
//! fn observe(&self, state: &MyState) -> Self::Output {
//! state.data.clone()
//! }
//! }
//!
//! #[derive(Debug)]
//! struct MySchedule;
//!
//! impl Schedule<MyState, MyRule> for MySchedule {
//! fn name(&self) -> &str {
//! "Schedule"
//! }
//!
//! fn selection(&self) -> &str {
//! "exhaustive"
//! }
//!
//! fn timing(&self) -> &str {
//! "asynchronous"
//! }
//!
//! fn step(&self, state: &MyState, rules: &[MyRule], rng: &mut dyn Rng) -> MyState {
//! let mut current = state.clone();
//! let context = NoContext;
//! for rule in rules {
//! current = rule.apply(state, &context, rng);
//! }
//! current
//! }
//! }
//!
//! #[derive(Debug)]
//! struct MyUniverse {
//! states: Vec<MyState>,
//! rules: Vec<MyRule>,
//! observer: MyObserver,
//! schedule: MySchedule,
//! }
//!
//! impl InformationUniverse for MyUniverse {
//! type State = MyState;
//! type Rule = MyRule;
//! type Observation = MyObserver;
//! type Schedule = MySchedule;
//!
//! fn state_space(&self) -> &[Self::State] {
//! &self.states
//! }
//! fn rules(&self) -> &[Self::Rule] {
//! &self.rules
//! }
//! fn observation(&self) -> &Self::Observation {
//! &self.observer
//! }
//! fn schedule(&self) -> &Self::Schedule {
//! &self.schedule
//! }
//! fn null_rules(&self, _rng: &mut dyn Rng) -> Vec<Self::Rule> {
//! self.rules.to_vec()
//! }
//! }
//! ```
use Rng;
use crateObservation;
use crateRule;
use crateSchedule;
use crateState;
/// The top-level abstraction for an Information Universe.
///
/// Bundles the four core components — state space, transformation
/// rules, observation operators, and update schedule — into a single
/// type. The scientific cycle operates on any implementor of this
/// trait.
///
/// # Type parameters
///
/// - `State`: The state type (must implement [`State`]).
/// - `Rule`: The rule type (must implement [`Rule<State>`]).
/// - `Observation`: The observer type (must implement
/// [`Observation<State>`]).
/// - `Schedule`: The schedule type (must implement
/// [`Schedule<State, Rule>`]).
///
/// # Design notes
///
/// - **R** (resource constraints) and **I** (invariant structure)
/// are not yet represented. They are placeholders for future
/// extensions.
/// - The trait uses associated types rather than generic parameters
/// so that a single type can represent a complete universe.
/// `run_cycle::<U: InformationUniverse>(&config)` is cleaner than
/// `run_cycle::<S, R, O, K>(&config)`.