• R/O
  • SSH

Joypy: Commit

Main interpreter and library.


Commit MetaInfo

Revisione82375b0d716a2445f1e3b5c5a8d021e04a5ac7e (tree)
Time2019-07-22 03:50:27
AuthorSimon Forman <sforman@hush...>
CommiterSimon Forman

Log Message

Messing with TLA+ in Prolog.

Change Summary

Incremental Difference

diff -r 8825021cd713 -r e82375b0d716 thun/TLA.pl
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/thun/TLA.pl Sun Jul 21 11:50:27 2019 -0700
@@ -0,0 +1,102 @@
1+
2+:- use_module(library(clpfd)).
3+
4+
5+% relly(PC, I, PCnext, Inext).
6+
7+initial_state :- relly(start, 0, _, _).
8+
9+relly(start, _I, middle, Inext) :- Inext in 0..1000.
10+relly(middle, I, done, Inext) :- Inext #= I + 1.
11+
12+
13+% next(PC, I) :-
14+next(done, _).
15+next(PC, I) :- PC \= done, relly(PC, I, PCnext, Inext), next(PCnext, Inext).
16+
17+
18+% ?- relly(start, 17, middle, 534).
19+% true.
20+
21+% ?- relly(middle, 534, 77, done).
22+% false.
23+
24+% ?- initial_state.
25+% true.
26+
27+% ?- relly(start, 0, PC, I).
28+% PC = middle,
29+% I in 0..1000.
30+
31+% ?- relly(start, 0, PC, I), relly(PC, I, PCnext, Inext).
32+% PC = middle,
33+% PCnext = done,
34+% I in 0..1000,
35+% I+1#=Inext,
36+% Inext in 1..1001.
37+
38+
39+
40+type_ok(Small, Big) :- Small in 0..3, Big in 0..5.
41+
42+initi :- die_hard(0, 0, _, _).
43+
44+next_dh(Small, Big, S, B) :-
45+ B #\= 4,
46+ type_ok(Small, Big),
47+ die_hard(Small, Big, Si, Bi),
48+ write(Small), write(" "), write(Big), write(" -> "), write(Si), write(" "), writeln(Bi),
49+ (Bi = 4 -> true ; next_dh(Si, Bi, S, B)).
50+next_dh(_, _, _, 4).
51+
52+
53+
54+% die_hard(Small, Big, S, B).
55+die_hard(Small, Big, 3, Big) :- Small #\= 3, writeln("fill small"). % Fill small.
56+die_hard(Small, Big, Small, 5) :- Big #\= 5, writeln("fill big"). % Fill big.
57+
58+die_hard(Small, Big, 0, Big) :- Small #> 0, writeln("empty small"). % empty small.
59+die_hard(Small, Big, Small, 0) :- Big #> 0, writeln("empty big"). % empty big.
60+
61+die_hard(Small, Big, 0, B) :- % small to big.
62+ Big #< 5, Small #> 0,
63+ Small + Big #=< 5,
64+ B is Small + Big, writeln("small to big").
65+die_hard(Small, Big, S, 5) :- % small to big.
66+ Big #< 5, Small #> 0,
67+ Small + Big #> 5,
68+ N is 5 - Big,
69+ (N #< Small -> S is Small - N ; S=0), writeln("small to big").
70+
71+die_hard(Small, Big, S, 0) :- % big to small.
72+ Small #< 3, Big #> 0,
73+ Small + Big #=< 3,
74+ S is Small + Big, writeln("big to small").
75+
76+die_hard(Small, Big, 3, B) :- % big to small.
77+ Small #< 3, Big #> 0,
78+ Small + Big #> 3,
79+ N is 3 - Small,
80+ (N #< Big -> B is Big - N ; B=0), writeln("big to small").
81+
82+/*
83+
84+call_with_depth_limit(next_dh(0, 0, S, B), 12, REsult).
85+
86+find...
87+
88+fill big
89+0 0 -> 0 5
90+big to small
91+0 5 -> 3 2
92+empty small
93+3 2 -> 0 2
94+big to small
95+0 2 -> 2 0
96+fill big
97+2 0 -> 2 5
98+big to small
99+2 5 -> 3 4
100+
101+
102+*/
\ No newline at end of file
Show on old repository browser