-
Notifications
You must be signed in to change notification settings - Fork 0
/
syn.cat
40 lines (40 loc) · 1.85 KB
/
syn.cat
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
true = "T"
false = "F"
0 = "0"
1 = "S0"
2 = "SS0"
3 = "SSS0"
4 = "SSSS0"
5 = "SSSSS0"
6 = "SSSSSS0"
7 = "SSSSSSS0"
8 = "SSSSSSSS0"
9 = "SSSSSSSSS0"
10 = "SSSSSSSSSS0"
succ x = cat "S" x
pred x = let 1 0 x
add x y = let 0 y x
sub x y = let y 0 x
mul x y = let "S" let 0 "" y x
dr x y z = let y x let x y z
encode s = cat cat "#$" let "$" "\$" let "#" "\#" let "\" "\\" s "$#"
decode s = let "\\" "\" let "\#" "#" let "\$" "$" let "$#" "" let "#$" "" s
enraw s = let "#$" "" let "$#" "" encode s
enrep s x y = let enraw x y s
rep2 s x xr y yr = decode let "x#" enraw xr let "y#" enraw yr enrep enrep encode s x "x#" y "y#"
eq x y = let encode x "F" let encode y "T" encode x
if c x y = decode let "T#" encode x let "F#" encode y cat c "#"
in x y = not eq y let x "" y
not x = if x false true
eq0 x = eq x 0
factorial x = if eq x 1 1 mul x factorial pred x
digit x = let "1" 1 let "2" 2 let "3" 3 let "4" 4 let "5" 5 let "6" 6 let "7" 7 let "8" 8 let "9" 9 x
exp x y = if eq0 y 1 mul x exp x pred y
nrep x p = let "0" p let "1" p let "2" p let "3" p let "4" p let "5" p let "6" p let "7" p let "8" p let "9" p x
len x = cat nrep x "S" 0
revdigit x = let 1 "1" let 2 "2" let 3 "3" let 4 "4" let 5 "5" let 6 "6" let 7 "7" let 8 "8" let 9 "9" x
head x = pred cat nrep let "$0" let "0" "" cat "S" 0 let "$1" let "0" "" cat "S" 1 let "$2" let "0" "" cat "S" 2 let "$3" let "0" "" cat "S" 3 let "$4" let "0" "" cat "S" 4 let "$5" let "0" "" cat "S" 5 let "$6" let "0" "" cat "S" 6 let "$7" let "0" "" cat "S" 7 let "$8" let "0" "" cat "S" 8 let "$9" let "0" "" cat "S" 9 cat "$" x "" 0
num x = if eq len x 1 digit x add mul head x exp succ 9 pred len x num let cat "$" revdigit head x "" cat "$" x
leq x y = in x y
show x = if leq len x 10 revdigit x cat show let "SSSSSSSSSS" "S" sub x let "SSSSSSSSSS" "" x revdigit let "SSSSSSSSSS" "" x
fib x = if eq0 x 0 if leq x 2 1 add fib pred x fib pred pred x