Advertisement
mikaelec

Exercise13

Dec 10th, 2014
197
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
F# 0.72 KB | None | 0 0
  1. //1
  2. type Prop =
  3.     | A of string
  4.     | Dis of Prop * Prop
  5.     | Con of Prop * Prop
  6.     | Neg of Prop
  7.  
  8. //2
  9. let rec nnf p =
  10.     let rec negate p =
  11.         match p with
  12.         | A a -> Neg (A a)
  13.         | Dis (p1,p2) -> Con (negate p1, negate p2)
  14.         | Con (p1,p2) -> Dis (negate p1, negate p2)
  15.         | Neg p -> nnf p
  16.     match p with
  17.     | A a -> A a
  18.     | Neg p -> negate p
  19.     | Con (p1,p2) -> Con (negate p1, negate p2)
  20.     | Dis (p1,p2) -> Dis (negate p1, negate p2)
  21.  
  22. //examples
  23. let p = A "p"
  24. let q = A "q"
  25. let s1 = Neg p
  26. let s2 = Neg (Neg p)
  27. let s3 = Neg (Dis (p,q))
  28. let s4 = Neg (Neg s3)
  29.  
  30. let rec dnf p =
  31.     match p with
  32.     | Con(A a, Dis(p1,p2)) -> Dis(Con(A a, p1), Con(A a, p2))
  33.     | _ -> p
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement