Advertisement
Guest User

Untitled

a guest
Nov 20th, 2018
146
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
OCaml 3.83 KB | None | 0 0
  1. open Syntax
  2. open Printf
  3.  
  4.  
  5. let rec proof_checker tree lst =
  6.   match tree with
  7.   | Ax(p) -> if List.mem p lst
  8.              then p
  9.              else failwith "Not on list"
  10.   | TopI -> Top
  11.   | ConjI(p1, p2) -> Conj((proof_checker p1 lst), (proof_checker p2 lst))
  12.   | DisjIL(p1, prop) -> Disj((proof_checker p1 lst) , prop)
  13.   | DisjIR(prop, p2) -> Disj(prop, (proof_checker p2 lst))
  14.   | ImplI((prop, pt)) -> Impl(prop, proof_checker pt (prop::lst))
  15.   | BotE(prop) -> prop
  16.   | ConjEL(pt) -> let assump = proof_checker pt lst in
  17.                   begin
  18.                   match assump with
  19.                   | Conj(p1, p2) -> p1
  20.                   | _ -> failwith "Not a conjuction"
  21.                   end
  22.   | ConjER(pt) -> let assump = proof_checker pt lst in
  23.                   begin
  24.                   match assump with
  25.                   | Conj(p1, p2) -> p2
  26.                   | _ -> failwith "Not a conjuction"
  27.                   end
  28.   | DisjE(pt, (prop1, hpt1), (prop2, hpt2)) ->
  29.               let assump = proof_checker pt lst in
  30.                   begin
  31.                   match assump with
  32.                   | Disj(p1, p2) -> if (p1 = prop1) && (p2 = prop2)
  33.                                     then let proof1 = proof_checker hpt1 (p1::lst)
  34.                                     in let proof2 = proof_checker hpt2 (p2::lst)
  35.                                     in if proof1 = proof2
  36.                                        then proof1
  37.                                        else failwith "Proposals not equal"
  38.                                     else failwith "Wrong hypothesis"
  39.                   | _ -> failwith "Not a disjunction"
  40.                   end
  41.   |ImplE(pt1, pt2) -> let alpha = proof_checker pt1 lst
  42.                           in let impli = proof_checker pt2 lst
  43.                             in begin match impli with
  44.                                | Impl(p1, p2) -> if p1 = alpha
  45.                                                  then p2
  46.                                                  else failwith "Wrong implication"
  47.                                | _ -> failwith "Not an implication"  end
  48.  
  49.  
  50.  
  51. let is_in prop lst =
  52.   List.mem prop lst;;
  53.  
  54. let intro prop lst =
  55.   match prop with
  56.   | Conj(p1, p2) -> (is_in p1 lst) && (is_in p2 lst)
  57.   | Disj(p1, p2) -> (is_in p1 lst) || (is_in p2 lst)
  58.   | _ -> false
  59.  
  60. let elim prop lst =
  61.   let aux axiom =
  62.     match prop with
  63.     | Conj(p1, p2) -> (prop = p1) || (prop = p2)
  64.     | Impl(p1, p2) -> (is_in p1 lst) && (prop = p2)
  65.     | Disj(p1, p2) -> is_in (Impl(p1, prop)) lst && is_in (Impl(p2, prop)) lst  
  66.     | Bot -> true
  67.     | _ -> false
  68.   in List.exists aux lst
  69.  
  70. let check prop lst =
  71.   is_in prop lst ||
  72.   intro prop lst ||
  73.   elim prop lst;;
  74.  
  75. let rec proof_checker_s script lst =
  76.   match script with
  77.   | PDone(prop) ->
  78.     if (check prop lst)
  79.     then prop
  80.     else failwith "Pdone error"
  81.   | PConc(prop, ps) ->
  82.     if (check prop lst)
  83.     then proof_checker_s ps (prop::lst)
  84.     else failwith "PConc error"
  85.   | PHyp((hprop, hps1), ps) ->
  86.     let temp = proof_checker_s hps1 (hprop::lst)
  87.       in proof_checker_s ps (Impl(hprop, temp)::lst)
  88.  
  89. let proofs_checker proofs =
  90.   let aux proof =
  91.     try
  92.     begin
  93.     match proof with
  94.     | TGoal(name, prop, pt) ->
  95.       if prop = proof_checker pt []
  96.       then printf "%s OK\n" name
  97.       else printf "%s FAIL\n" name
  98.     | SGoal(name, prop, ps) ->
  99.       if prop = proof_checker_s ps []
  100.       then printf "%s OK\n" name
  101.       else printf "%s FAIL\n" name
  102.     end
  103.     with (Failure msg) ->
  104.       printf "EXCEPTION: %s\n" msg
  105.   in List.map aux proofs
  106.  
  107. let _ =
  108.   let lexbuf = Lexing.from_channel stdin in
  109.   let proofs = Parser.file Lexer.token lexbuf
  110.   (* powyższe wiersze wczytują listę dowodów ze standardowego wejścia
  111.      i parsują ją do postaci zdefiniowanej w module Syntax *)
  112.   in proofs_checker proofs
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement