-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathlogic.sml
62 lines (51 loc) · 1.29 KB
/
logic.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
59
60
61
62
(*
Problems from https://sites.google.com/site/prologsite/prolog-problems/3
*)
datatype exp = Var of string
| Not of exp
| And of exp * exp
| Or of exp * exp
fun eval e =
case e of
Var x => true
| Not e1 => not (eval e1)
| And (e1, e2) => (eval e1) andalso (eval e2)
| Or (e1, e2) => (eval e1) orelse (eval e2)
(* testing::
val val1 = Var "x"
val val2 = Not(Var "y")
val and1 = And(Var "x", Var "y")
val and2 = And(Var "x", Not (Var "y"))
val and3 = And(Not (Var "x"), Not (Var "y"))
val or1 = Or(Var "x", Not (Var "y"))
val or2 = Or (Not (Var "x"), Not (Var "y"))
val or3 = Or (Var "x", Var "y")
val eval_val1 = eval val1
val eval_val2 = eval val2
val eval_and1 = eval and1
val eval_and2 = eval and2
val eval_and3 = eval and3
val eval_or1 = eval or1
val eval_or2 = eval or2
val eval_or3 = eval or3
*)
(*3.01*)
fun table1 (a:exp, b:exp, operator) =
let fun rt(m,n) =
let val expr = operator(m,n)
in
[eval m, eval n, eval expr]
(*
(Bool.toString(eval m), Bool.toString(eval n),Bool.toString(eval expr))
*)
end
in
[rt(a,b),
rt(Not(a),b),
rt(a, Not(b)),
rt(Not(a), Not(b))]
end
(*example*)
val x_and1 = table1 (Var "x", Var "x", And);
val x_and2 = table1 (Var "x", Not(Var "x"), And);
val y_or = table1 (Var "x", Var "x", Or);