-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgol_rulesScript.sml
58 lines (46 loc) · 1.76 KB
/
gol_rulesScript.sml
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
(*
A formalisation of the rules of Conway's Game of Life (GOL).
*)
open HolKernel bossLib boolLib Parse;
open integerTheory;
val _ = new_theory "gol_rules";
(*---------------------------------------------------------------*
Definition of the semantics of Conway's Game of Life (GOL)
*---------------------------------------------------------------*)
(* There is an unbounded 2D plane of cells *)
Type state[pp] = “:(int # int) set”;
Definition adj_def:
adj i j = { (i',j') | int_max (ABS (i'-i)) (ABS (j'-j)) = 1 }
End
Definition live_adj_def:
live_adj s i j = CARD (s ∩ adj i j)
End
(* For each tick, the game takes a simultaneous step forward in time *)
Definition step_def:
step (s:state) = { (i,j) | if (i,j) ∈ s then live_adj s i j ∈ {2;3}
else live_adj s i j = 3 }
End
Theorem IN_step:
(i,j) ∈ step s ⇔ if (i,j) ∈ s then live_adj s i j ∈ {2;3}
else live_adj s i j = 3
Proof
fs [step_def]
QED
(*---------------------------------------------------------------*
Define what it means to simulate GOL in GOL.
s0 --step---> s1 --step---> ... --step---> sN
| ∧ ∧ ∧
| encode | | | extract
∨ | | |
t0 --steps--> s1 --steps--> ... --steps--> tN
Here --steps--> is a fixed number of --step---> transitions.
*---------------------------------------------------------------*)
Definition gol_in_gol_def:
gol_in_gol encode step_count extract ⇔
∀ n s0 s1 t0 t1 .
t0 = encode s0 ∧
t1 = FUNPOW step (n * step_count) t0 ∧
s1 = FUNPOW step n s0 ⇒
s1 = extract t1
End
val _ = export_theory();