Advertisement
Guest User

Untitled

a guest
Nov 20th, 2019
165
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.57 KB | None | 0 0
  1. verify(InputFileName) :- see(InputFileName),
  2. read(Prems), read(Goal), read(Proof),
  3. seen,
  4. valid_proof(Prems, Goal, Proof).
  5.  
  6. valid_proof([H|T], G, Proof) :- findlast(Proof, _, [_|[G|_]]), check_rules([H|T], Proof, Proof, 1).
  7.  
  8. findlast([X], [], X).
  9. findlast([H | T], [H | N], X) :- findlast(T, N, X).
  10.  
  11. check_rules([_|_], [[]], _, _).
  12. check_rules([_|_], [], _, _).
  13. check_rules([H|T], [[_|[T1|_]]|T2], Proof, Count) :- get_rule(Proof, Count, [R|_]), (R == premise, get_prop(Proof, Count, Prop), check_premise(Prop, [H|T]) ;
  14. R == assumption, check_assumption(Proof, Count) ;
  15. R = copy(_), get_pred_of_prop(R, [_|[Num|_]]), copy(Num, Count, Proof) ;
  16. R = andint(_, _), get_pred_of_prop(R, [_|[A|[B|_]]]), andint(A, B, Count, Proof) ;
  17. R = andel1(_), get_pred_of_prop(R, [_|[Num|_]]), andel1(Num, Count, Proof) ;
  18. R = andel2(_), get_pred_of_prop(R, [_|[Num|_]]), andel2(Num, Count, Proof) ;
  19. R = orint1(_), get_pred_of_prop(R, [_|[Num|_]]), orint1(Num, Count, Proof) ;
  20. R = orint2(_), get_pred_of_prop(R, [_|[Num|_]]), orint2(Num, Count, Proof) ;
  21. R = orel(_, _, _, _, _), get_pred_of_prop(R, [_|[X|[A|[B|[C|[D|_]]]]]]), orel(X, A, B, C, D, Count, Proof) ;
  22. R = impint(_, _), get_pred_of_prop(R, [_|[A|[B|_]]]), impint(A, B, Count, Proof) ;
  23. R = impel(_, _), get_pred_of_prop(R, [_|[A|[B|_]]]), impel(A, B, Count, Proof) ;
  24. R = negint(_, _), get_pred_of_prop(R, [_|[A|[B|_]]]), negint(A, B, Count, Proof) ;
  25. R = negel(_, _), get_pred_of_prop(R, [_|[A|[B|_]]]), negel(A, B, Count, Proof) ;
  26. R = contel(_), get_pred_of_prop(R, [_|[Num|_]]), contel(Num, Count, Proof) ;
  27. R = negnegint(_), get_pred_of_prop(R, [_|[Num|_]]), negnegint(Num, Count, Proof) ;
  28. R = negnegel(_), get_pred_of_prop(R, [_|[Num|_]]), negnegel(Num, Count, Proof) ;
  29. R = mt(_, _), get_pred_of_prop(R, [_|[A|[B|_]]]), mt(A, B, Count, Proof) ;
  30. R = pbc(_, _), get_pred_of_prop(R, [_|[A|[B|_]]]), pbc(A, B, Count, Proof) ;
  31. R == lem, lem(Count, Proof)),
  32. C1 is Count + 1,
  33. (not(is_list(T1)), check_rules([H|T], T2, Proof, C1) ; check_rules([H|T], [T1|T2], Proof, C1)).
  34.  
  35. check_assumption(Proof, Num) :- row_depth(Proof, Num, Depth), is_list(Depth), findlast(Depth, [_|_], 1).
  36.  
  37. check_premise(Result, H) :- Result == H.
  38. check_premise(Result, [H|T]) :- Result == H ; check_premise(Result, T).
  39.  
  40.  
  41. find_row([[[[H|T]|_]|_]|_], H, [H|T]).
  42. find_row([[[H|T]|_]|_], H, [H|T]).
  43. find_row([[H|T]|_], H, [H|T]).
  44. find_row([[[Hf|Tf]|T2]|[[H|T3]|T4]], Num, Result) :- less_than(H, Num), find_row([[H|T3]|T4], Num, Result) ; find_row([[Hf|Tf]|T2], Num, Result).
  45. find_row([[_|[T1|_]]|T2], Num, Result) :- (not(is_list(T1)), find_row(T2, Num, Result) ; find_row([T1|T2], Num, Result)).
  46.  
  47. less_than(H, Num) :- is_list(H), get_list_head(H, P), less_than(P, Num) ; not(is_list(H)), H =< Num.
  48.  
  49. get_list_head([H|_], H).
  50.  
  51. depth(X, [X|_], [C], C).
  52. depth(X, [H|_], [C|D], C) :- depth(X, H, D, 1).
  53. depth(X, [_|T], D, C) :- C1 is C+1, depth(X, T, D, C1).
  54.  
  55. row_depth(Proof, Row, Depth) :- find_row(Proof, Row, FullRow), depth(FullRow, Proof, Depth, 1).
  56.  
  57. find_row_and_depth(Proof, Num, Row, Depth) :- find_row(Proof, Num, Row), row_depth(Row, Proof, Depth).
  58.  
  59. get_prop(Proof, Num, Prop) :- find_row(Proof, Num, [_|[Prop|_]]).
  60.  
  61. get_rule(Proof, Num, Rule) :- find_row(Proof, Num, [_|[_|Rule]]).
  62.  
  63. get_pred_of_prop(L, List) :- L =.. List.
  64.  
  65. lesser_depth([_], _).
  66. lesser_depth([Ha|Ta], [Hb|Tb]) :- Ha is Hb, lesser_depth(Ta, Tb).
  67.  
  68. valid_depth(Proof, RowA, RowB) :- row_depth(Proof, RowA, DepthA), row_depth(Proof, RowB, DepthB),
  69. lesser_depth(DepthA, DepthB).
  70. valid_depth_box(Proof, DepthBox, RowB) :- row_depth(Proof, RowB, DepthB),
  71. lesser_depth(DepthBox, DepthB).
  72.  
  73. check_box(Proof, Start, End, R) :- Start < End, row_depth(Proof, Start, [Hs|Ts]), row_depth(Proof, End, [He|Te]), findlast([Hs|Ts], Rs, _), findlast([He|Te], Re, _), Rs = Re, C1 is End+1, row_depth(Proof, C1, [H|T]), findlast([H|T], Rc, _), not(Rc = Re), findlast([Hs|Ts], R, _).
  74.  
  75. copy(A, B, Proof) :-
  76. A < B,
  77. get_prop(Proof, A, PropA),
  78. get_prop(Proof, B, PropB),
  79. PropA==PropB, valid_depth(Proof, A, B).
  80.  
  81. andint(A, B, C, Proof) :-
  82. A < C,
  83. B < C,
  84. get_prop(Proof, A, PropA),
  85. get_prop(Proof, B, PropB),
  86. get_prop(Proof, C, PropC),
  87.  
  88. and(PropA, PropB) = PropC,
  89. valid_depth(Proof, A, C), valid_depth(Proof, B, C).
  90.  
  91. andel1(A, B, Proof) :-
  92. A < B,
  93.  
  94. get_prop(Proof, A, PropA),
  95. get_prop(Proof, B, PropB),
  96.  
  97. get_pred_of_prop(PropA, [_ | [PredLeftA | _]]),
  98.  
  99. PredLeftA = PropB,
  100. valid_depth(Proof, A, B).
  101.  
  102. andel2(A, B, Proof) :-
  103. A < B,
  104.  
  105. get_prop(Proof, A, PropA),
  106. get_prop(Proof, B, PropB),
  107.  
  108. get_pred_of_prop(PropA, [_ | [_ | [PredRightA | _]]]),
  109.  
  110. PredRightA = PropB,
  111. valid_depth(Proof, A, B).
  112.  
  113. orint1(A, B, Proof) :-
  114. A < B,
  115.  
  116. get_prop(Proof, A, PropA),
  117. get_prop(Proof, B, PropB),
  118.  
  119. get_pred_of_prop(PropB, [_ | [PredLeftB | _]]),
  120.  
  121. PredLeftB = PropA,
  122. valid_depth(Proof, A, B).
  123.  
  124. orint2(A, B, Proof) :-
  125. A < B,
  126.  
  127. get_prop(Proof, A, PropA),
  128. get_prop(Proof, B, PropB),
  129.  
  130. get_pred_of_prop(PropB, [_ | [_ | [PredRightB | _]]]),
  131.  
  132. PredRightB = PropA,
  133. valid_depth(Proof, A, B).
  134.  
  135. orel(X, A, B, C, D, E, Proof) :-
  136. A < B,
  137. C < D,
  138. B < E,
  139. D < E,
  140. X < E,
  141.  
  142. check_box(Proof, A, B, Il1),
  143. valid_depth_box(Proof, Il1, E),
  144.  
  145. check_box(Proof, C, D, Il2),
  146. valid_depth_box(Proof, Il2, E),
  147.  
  148. get_prop(Proof, A, PropA),
  149. get_prop(Proof, B, PropB),
  150. get_prop(Proof, C, PropC),
  151. get_prop(Proof, D, PropD),
  152. get_prop(Proof, X, PropX),
  153.  
  154. PropB = PropD,
  155. (PropX = or(PropA, PropC) ; PropX = or(PropC, PropA)).
  156.  
  157. impint(A, B, C, Proof) :-
  158. A < B,
  159. B < C,
  160.  
  161. check_box(Proof, A, B, Indexlist),
  162. valid_depth_box(Proof, Indexlist, C),
  163.  
  164. get_prop(Proof, A, PropA),
  165. get_prop(Proof, B, PropB),
  166. get_prop(Proof, C, PropC),
  167.  
  168. get_pred_of_prop(PropC, [_ | [PredLeftC | [PredRightC | _]]]),
  169.  
  170. PropA = PredLeftC,
  171. PropB = PredRightC.
  172.  
  173. impel(A, B, C, Proof) :-
  174. A < C,
  175. B < C,
  176.  
  177. get_prop(Proof, A, PropA),
  178. get_prop(Proof, B, PropB),
  179. get_prop(Proof, C, PropC),
  180.  
  181. ((get_pred_of_prop(PropB, [_ | [PredLeftB | [PredRightB | _]]]),
  182. PropA = PredLeftB,
  183. PropC = PredRightB) ;
  184. (get_pred_of_prop(PropA, [_ | [PredLeftA | [PredRightA | _]]]),
  185. PropB = PredLeftA,
  186. PropC = PredRightA)),
  187.  
  188. valid_depth(Proof, A, C), valid_depth(Proof, B, C).
  189.  
  190. negint(A, B, C, Proof) :-
  191. A < B,
  192. A < C,
  193. B < C,
  194.  
  195. check_box(Proof, A, B, Indexlist),
  196. valid_depth_box(Proof, Indexlist, C),
  197.  
  198. get_prop(Proof, A, PropA),
  199. get_prop(Proof, B, PropB),
  200. get_prop(Proof, C, PropC),
  201.  
  202. get_pred_of_prop(PropC, [_ | [PredLeftC | _]]),
  203.  
  204. PropA = PredLeftC,
  205. PropB = cont.
  206.  
  207. negel(A, B, C, Proof) :-
  208. A < C,
  209. B < C,
  210.  
  211. get_prop(Proof, A, PropA),
  212. get_prop(Proof, B, PropB),
  213. get_prop(Proof, C, PropC),
  214.  
  215. ((PropB = neg(_), get_pred_of_prop(PropB, [_ | [PredLeftB | _]]),
  216. PropA = PredLeftB) ;
  217. (PropA = neg(_), get_pred_of_prop(PropA, [_ | [PredLeftA | _]]),
  218. PropB = PredLeftA)),
  219.  
  220. PropC = cont,
  221. valid_depth(Proof, A, C), valid_depth(Proof, B, C).
  222.  
  223. contel(A, B, Proof) :-
  224. A < B,
  225.  
  226. get_prop(Proof, A, PropA),
  227.  
  228. PropA = cont,
  229. valid_depth(Proof, A, B).
  230.  
  231. negnegint(A, B, Proof) :-
  232. A < B,
  233.  
  234. get_prop(Proof, A, PropA),
  235. get_prop(Proof, B, PropB),
  236.  
  237. get_pred_of_prop(PropB, [_ | [PredLeftB | _]]),
  238.  
  239. PropA = PredLeftB,
  240. valid_depth(Proof, A, B).
  241.  
  242. negnegel(A, B, Proof) :-
  243. A < B,
  244.  
  245. get_prop(Proof, A, PropA),
  246. get_prop(Proof, B, PropB),
  247.  
  248. get_pred_of_prop(PropA, [_ | [PredLeftA | _]]),
  249.  
  250. PropB = PredLeftA.
  251.  
  252. mt(A, B, C, Proof) :-
  253. A < C,
  254. B < C,
  255.  
  256. get_prop(Proof, A, PropA),
  257. get_prop(Proof, B, PropB),
  258. get_prop(Proof, C, PropC),
  259.  
  260. get_pred_of_prop(PropA, [_ | [PredLeftA | [PredRightA | _]]]),
  261.  
  262. neg(PredLeftA) = PropC,
  263. neg(PredRightA) = PropB,
  264. valid_depth(Proof, A, C), valid_depth(Proof, B, C).
  265.  
  266. pbc(A, B, C, Proof) :-
  267. A < B,
  268. B < C,
  269.  
  270. check_box(Proof, A, B, Indexlist),
  271. valid_depth_box(Proof, Indexlist, C),
  272.  
  273. get_prop(Proof, A, PropA),
  274. get_prop(Proof, B, PropB),
  275. get_prop(Proof, C, PropC),
  276.  
  277. (PropC = neg(PropA) ;
  278. get_pred_of_prop(PropA, [_ | [PredLeftA | _]]),
  279. PropC = PredLeftA),
  280. PropB == cont.
  281.  
  282. lem(A, Proof) :-
  283.  
  284. get_prop(Proof, A, PropA),
  285.  
  286. get_pred_of_prop(PropA, [_ | [PredLeftA | [PredRightA | _]]]),
  287.  
  288. (neg(PredLeftA) = PredRightA ; PredLeftA = neg(PredRightA)),
  289. (PropA = or(PredLeftA, PredRightA) ; PropA = or(PredRightA, PredLeftA)).
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement