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
//! 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 provides:
//!
//! - **S** (state space): A collection of possible states for
//! sampling initial conditions, via [`state_space()`].
//! - **T** (transformation set): Rules generated on demand via
//! [`generate_rules()`] and [`null_rules()`].
//! - **O** (observation operators): How states are perceived, via
//! [`observation()`].
//! - **K** (update schedule): The temporal structure, 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.
//!
//! # Quick start
//!
//! ```rust
//! use arco::state::State;
//! use arco::rules::{Rule, NoContext};
//! use arco::observation::Observation;
//! use arco::schedule::SequentialSchedule;
//! use arco::universe::InformationUniverse;
//! use rand::{Rng, RngExt};
//!
//! #[derive(Clone, PartialEq, Eq, Hash, Debug)]
//! struct BitState { value: u8 }
//!
//! impl State for BitState {
//! type Encoding = Vec<u8>;
//! fn canonical_encoding(&self) -> Self::Encoding { vec![self.value] }
//! fn distance(&self, other: &Self) -> u32 {
//! if self.value == other.value { 0 } else { 1 }
//! }
//! }
//!
//! #[derive(Debug, Clone)]
//! struct FlipRule;
//! impl Rule<BitState> for FlipRule {
//! type Context = NoContext;
//! fn name(&self) -> &str { "Flip" }
//! fn apply(&self, state: &BitState, _ctx: &NoContext, _rng: &mut dyn Rng) -> BitState {
//! BitState { value: 1 - state.value }
//! }
//! }
//!
//! #[derive(Debug, Clone)]
//! struct BitObserver;
//! impl Observation<BitState> for BitObserver {
//! type Output = u8;
//! fn observe(&self, state: &BitState) -> Self::Output { state.value }
//! }
//!
//! struct MyUniverse {
//! states: Vec<BitState>,
//! schedule: SequentialSchedule,
//! }
//!
//! impl InformationUniverse for MyUniverse {
//! type State = BitState;
//! type Rule = FlipRule;
//! type Observation = BitObserver;
//! type Schedule = SequentialSchedule;
//!
//! fn state_space(&self) -> &[Self::State] { &self.states }
//! fn observation(&self) -> &Self::Observation { &BitObserver }
//! fn schedule(&self) -> &Self::Schedule { &self.schedule }
//!
//! fn generate_rules(&self, rng: &mut dyn Rng) -> (Vec<Self::Rule>, f64) {
//! let n = rng.random_range(1..=3);
//! let rules: Vec<FlipRule> = (0..n).map(|_| FlipRule).collect();
//! (rules, 1.0)
//! }
//!
//! fn null_rules(&self, _rng: &mut dyn Rng) -> Vec<Self::Rule> {
//! vec![FlipRule] // flipping is maximally destructive in this universe
//! }
//! }
//! ```
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.