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
//! Schedule trait — temporal structure in Information Universes.
//!
//! Per the Mathematical Constitution:
//! K is the update schedule — a rule specifying the order and
//! selection of transformations at each timestep. Two universes
//! differing only in schedule are distinct objects of study.
//!
//! # The Schedule trait
//!
//! A schedule determines how rules are applied over time. It answers:
//! which rules fire, in what order, and with what concurrency?
//! The schedule is a first-class component — changing the schedule
//! can change whether computation is detected.
//!
//! # Schedule Semantics
//!
//! Schedules are classified along two axes:
//!
//! **Timing**
//! - *Synchronous*: All updates within a timestep are computed from
//! the same pre-timestep state. No update within the timestep
//! sees any other update.
//! - *Asynchronous*: Updates are applied immediately. Later updates
//! within the same timestep see the results of earlier updates.
//!
//! **Selection**
//! - *Exhaustive*: Every update site is visited exactly once per
//! timestep.
//! - *Stochastic*: Sites are sampled probabilistically.
//! - *Priority*: Sites are ordered by a fixed criterion.
//!
//! # Implementing Schedule
//!
//! ```rust
//! use arco::state::State;
//! use arco::rules::{Rule, NoContext};
//! use arco::schedule::Schedule;
//! use rand::Rng;
//!
//! #[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(Debug)]
//! struct MyRule;
//! impl Rule<MyState> for MyRule {
//! type Context = NoContext;
//!
//! fn name(&self) -> &str { "MyRule" }
//! fn apply(&self, state: &MyState, context: &Self::Context, rng: &mut dyn Rng) -> MyState {
//! state.clone()
//! }
//! }
//!
//! /// A schedule that applies all rules in sequence, once per timestep.
//! #[derive(Clone, Debug)]
//! struct SequentialSchedule;
//!
//! impl Schedule<MyState, MyRule> for SequentialSchedule {
//! fn name(&self) -> &str { "sequential" }
//! fn timing(&self) -> &str { "asynchronous" }
//! fn selection(&self) -> &str { "exhaustive" }
//!
//! 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(¤t, &context, rng);
//! }
//! current
//! }
//! }
//! ```
//!
//! # Built-in schedules
//!
//! Substrate-specific schedules live in their substrate modules.
//! See [`arco::substrates::graph::AllVerticesSchedule`] for the
//! asynchronous exhaustive schedule used in the Binary Graph Universe.
//!
//! Generic schedules (sequential, random) can be defined in
//! [`arco::schedule::generic`] and reused across substrates.
use crate;
use crateState;
use ;
use Debug;
/// The temporal structure of an Information Universe.
///
/// A schedule determines the order and selection of rule applications
/// at each timestep.
///
/// # Type parameters
///
/// - `S: State` — The state type.
/// - `R: Rule<S>` — The rule type.
///
/// # Design contracts
///
/// - **Determinism**: Given the same state, rules, and RNG seed,
/// the schedule must produce the same next state. The RNG is
/// the sole source of stochasticity.
/// - **Immutability**: The schedule returns a new state. The input
/// state is not modified.
/// - **Send + Sync**: Schedules must be shareable across threads.
// ===================================================================
// Generic schedules (substrate-independent)
// ===================================================================
/// A schedule that applies all rules in sequence.
///
/// Every rule is applied exactly once per timestep, in the order
/// they appear in the rule set. Updates are asynchronous — each
/// rule sees the results of previous rules within the same timestep.
///
/// # Semantics
/// - Timing: asynchronous
/// - Selection: exhaustive (all rules fire, in order)
///
/// This is the simplest possible schedule and works with any rule
/// type.
;
/// A schedule that selects one rule at random per timestep.
///
/// At each timestep, a single rule is chosen uniformly at random
/// from the rule set and applied once. The same rule may be selected
/// across multiple timesteps — each timestep is an independent
/// random draw.
///
/// This models stochastic asynchronous dynamics where one
/// transformation event occurs per timestep.
///
/// # Semantics
/// - Timing: asynchronous (single update per timestep)
/// - Selection: stochastic (one rule drawn uniformly per timestep)
;