| author | huffman | 
| Wed, 20 Sep 2006 07:42:12 +0200 | |
| changeset 20634 | 45fe31e72391 | 
| parent 19617 | 7cb4b67d4b97 | 
| child 22578 | b0eb5652f210 | 
| permissions | -rw-r--r-- | 
| 14398 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 1 | (* | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 2 | Title: Transitivity reasoner for partial and linear orders | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 3 | Id: $Id$ | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 4 | Author: Oliver Kutter | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 5 | Copyright: TU Muenchen | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 6 | *) | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 7 | |
| 14445 | 8 | (* TODO: reduce number of input thms *) | 
| 14398 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 9 | |
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 10 | (* | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 11 | |
| 15103 
79846e8792eb
New transitivity reasoners for transitivity only and quasi orders.
 ballarin parents: 
15098diff
changeset | 12 | The package provides tactics partial_tac and linear_tac that use all | 
| 14398 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 13 | premises of the form | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 14 | |
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 15 | t = u, t ~= u, t < u, t <= u, ~(t < u) and ~(t <= u) | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 16 | |
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 17 | to | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 18 | 1. either derive a contradiction, | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 19 | in which case the conclusion can be any term, | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 20 | 2. or prove the conclusion, which must be of the same form as the | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 21 | premises (excluding ~(t < u) and ~(t <= u) for partial orders) | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 22 | |
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 23 | The package is implemented as an ML functor and thus not limited to the | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 24 | relation <= and friends. It can be instantiated to any partial and/or | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 25 | linear order --- for example, the divisibility relation "dvd". In | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 26 | order to instantiate the package for a partial order only, supply | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 27 | dummy theorems to the rules for linear orders, and don't use | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 28 | linear_tac! | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 29 | |
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 30 | *) | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 31 | |
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 32 | signature LESS_ARITH = | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 33 | sig | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 34 | (* Theorems for partial orders *) | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 35 | val less_reflE: thm (* x < x ==> P *) | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 36 | val le_refl: thm (* x <= x *) | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 37 | val less_imp_le: thm (* x < y ==> x <= y *) | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 38 | val eqI: thm (* [| x <= y; y <= x |] ==> x = y *) | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 39 | val eqD1: thm (* x = y ==> x <= y *) | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 40 | val eqD2: thm (* x = y ==> y <= x *) | 
| 15098 | 41 | val less_trans: thm (* [| x < y; y < z |] ==> x < z *) | 
| 42 | val less_le_trans: thm (* [| x < y; y <= z |] ==> x < z *) | |
| 43 | val le_less_trans: thm (* [| x <= y; y < z |] ==> x < z *) | |
| 44 | val le_trans: thm (* [| x <= y; y <= z |] ==> x <= z *) | |
| 14398 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 45 | val le_neq_trans : thm (* [| x <= y ; x ~= y |] ==> x < y *) | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 46 | val neq_le_trans : thm (* [| x ~= y ; x <= y |] ==> x < y *) | 
| 16743 
21dbff595bf6
1) all theorems in Orderings can now be given as a parameter
 obua parents: 
15574diff
changeset | 47 | val not_sym : thm (* x ~= y ==> y ~= x *) | 
| 14398 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 48 | |
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 49 | (* Additional theorems for linear orders *) | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 50 | val not_lessD: thm (* ~(x < y) ==> y <= x *) | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 51 | val not_leD: thm (* ~(x <= y) ==> y < x *) | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 52 | val not_lessI: thm (* y <= x ==> ~(x < y) *) | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 53 | val not_leI: thm (* y < x ==> ~(x <= y) *) | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 54 | |
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 55 | (* Additional theorems for subgoals of form x ~= y *) | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 56 | val less_imp_neq : thm (* x < y ==> x ~= y *) | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 57 | val eq_neq_eq_imp_neq : thm (* [| x = u ; u ~= v ; v = z|] ==> x ~= z *) | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 58 | |
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 59 | (* Analysis of premises and conclusion *) | 
| 15103 
79846e8792eb
New transitivity reasoners for transitivity only and quasi orders.
 ballarin parents: 
15098diff
changeset | 60 | (* decomp_x (`x Rel y') should yield (x, Rel, y) | 
| 14398 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 61 | where Rel is one of "<", "<=", "~<", "~<=", "=" and "~=", | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 62 | other relation symbols cause an error message *) | 
| 15103 
79846e8792eb
New transitivity reasoners for transitivity only and quasi orders.
 ballarin parents: 
15098diff
changeset | 63 | (* decomp_part is used by partial_tac *) | 
| 19250 | 64 | val decomp_part: theory -> term -> (term * string * term) option | 
| 15103 
79846e8792eb
New transitivity reasoners for transitivity only and quasi orders.
 ballarin parents: 
15098diff
changeset | 65 | (* decomp_lin is used by linear_tac *) | 
| 19250 | 66 | val decomp_lin: theory -> term -> (term * string * term) option | 
| 14398 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 67 | end; | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 68 | |
| 15103 
79846e8792eb
New transitivity reasoners for transitivity only and quasi orders.
 ballarin parents: 
15098diff
changeset | 69 | signature ORDER_TAC = | 
| 14398 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 70 | sig | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 71 | val partial_tac: int -> tactic | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 72 | val linear_tac: int -> tactic | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 73 | end; | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 74 | |
| 15103 
79846e8792eb
New transitivity reasoners for transitivity only and quasi orders.
 ballarin parents: 
15098diff
changeset | 75 | functor Order_Tac_Fun (Less: LESS_ARITH): ORDER_TAC = | 
| 14398 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 76 | struct | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 77 | |
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 78 | (* Extract subgoal with signature *) | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 79 | fun SUBGOAL goalfun i st = | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 80 | goalfun (List.nth(prems_of st, i-1), i, sign_of_thm st) st | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 81 | handle Subscript => Seq.empty; | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 82 | |
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 83 | (* Internal datatype for the proof *) | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 84 | datatype proof | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 85 | = Asm of int | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 86 | | Thm of proof list * thm; | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 87 | |
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 88 | exception Cannot; | 
| 14445 | 89 | (* Internal exception, raised if conclusion cannot be derived from | 
| 14398 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 90 | assumptions. *) | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 91 | exception Contr of proof; | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 92 | (* Internal exception, raised if contradiction ( x < x ) was derived *) | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 93 | |
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 94 | fun prove asms = | 
| 15570 | 95 | let fun pr (Asm i) = List.nth (asms, i) | 
| 14398 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 96 | | pr (Thm (prfs, thm)) = (map pr prfs) MRS thm | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 97 | in pr end; | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 98 | |
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 99 | (* Internal datatype for inequalities *) | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 100 | datatype less | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 101 | = Less of term * term * proof | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 102 | | Le of term * term * proof | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 103 | | NotEq of term * term * proof; | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 104 | |
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 105 | (* Misc functions for datatype less *) | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 106 | fun lower (Less (x, _, _)) = x | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 107 | | lower (Le (x, _, _)) = x | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 108 | | lower (NotEq (x,_,_)) = x; | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 109 | |
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 110 | fun upper (Less (_, y, _)) = y | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 111 | | upper (Le (_, y, _)) = y | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 112 | | upper (NotEq (_,y,_)) = y; | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 113 | |
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 114 | fun getprf (Less (_, _, p)) = p | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 115 | | getprf (Le (_, _, p)) = p | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 116 | | getprf (NotEq (_,_, p)) = p; | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 117 | |
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 118 | (* ************************************************************************ *) | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 119 | (* *) | 
| 19250 | 120 | (* mkasm_partial sign (t, n) : theory -> (Term.term * int) -> less *) | 
| 14398 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 121 | (* *) | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 122 | (* Tuple (t, n) (t an assumption, n its index in the assumptions) is *) | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 123 | (* translated to an element of type less. *) | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 124 | (* Partial orders only. *) | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 125 | (* *) | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 126 | (* ************************************************************************ *) | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 127 | |
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 128 | fun mkasm_partial sign (t, n) = | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 129 | case Less.decomp_part sign t of | 
| 15531 | 130 | SOME (x, rel, y) => (case rel of | 
| 14398 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 131 | "<" => if (x aconv y) then raise Contr (Thm ([Asm n], Less.less_reflE)) | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 132 | else [Less (x, y, Asm n)] | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 133 | | "~<" => [] | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 134 | | "<=" => [Le (x, y, Asm n)] | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 135 | | "~<=" => [] | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 136 | | "=" => [Le (x, y, Thm ([Asm n], Less.eqD1)), | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 137 | Le (y, x, Thm ([Asm n], Less.eqD2))] | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 138 | | "~=" => if (x aconv y) then | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 139 | raise Contr (Thm ([(Thm ([(Thm ([], Less.le_refl)) ,(Asm n)], Less.le_neq_trans))], Less.less_reflE)) | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 140 | else [ NotEq (x, y, Asm n), | 
| 16743 
21dbff595bf6
1) all theorems in Orderings can now be given as a parameter
 obua parents: 
15574diff
changeset | 141 | NotEq (y, x,Thm ( [Asm n], Less.not_sym))] | 
| 14398 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 142 |     | _     => error ("partial_tac: unknown relation symbol ``" ^ rel ^
 | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 143 | "''returned by decomp_part.")) | 
| 15531 | 144 | | NONE => []; | 
| 14398 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 145 | |
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 146 | (* ************************************************************************ *) | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 147 | (* *) | 
| 19250 | 148 | (* mkasm_linear sign (t, n) : theory -> (Term.term * int) -> less *) | 
| 14398 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 149 | (* *) | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 150 | (* Tuple (t, n) (t an assumption, n its index in the assumptions) is *) | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 151 | (* translated to an element of type less. *) | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 152 | (* Linear orders only. *) | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 153 | (* *) | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 154 | (* ************************************************************************ *) | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 155 | |
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 156 | fun mkasm_linear sign (t, n) = | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 157 | case Less.decomp_lin sign t of | 
| 15531 | 158 | SOME (x, rel, y) => (case rel of | 
| 14398 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 159 | "<" => if (x aconv y) then raise Contr (Thm ([Asm n], Less.less_reflE)) | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 160 | else [Less (x, y, Asm n)] | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 161 | | "~<" => [Le (y, x, Thm ([Asm n], Less.not_lessD))] | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 162 | | "<=" => [Le (x, y, Asm n)] | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 163 | | "~<=" => if (x aconv y) then | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 164 | raise (Contr (Thm ([Thm ([Asm n], Less.not_leD)], Less.less_reflE))) | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 165 | else [Less (y, x, Thm ([Asm n], Less.not_leD))] | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 166 | | "=" => [Le (x, y, Thm ([Asm n], Less.eqD1)), | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 167 | Le (y, x, Thm ([Asm n], Less.eqD2))] | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 168 | | "~=" => if (x aconv y) then | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 169 | raise Contr (Thm ([(Thm ([(Thm ([], Less.le_refl)) ,(Asm n)], Less.le_neq_trans))], Less.less_reflE)) | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 170 | else [ NotEq (x, y, Asm n), | 
| 16743 
21dbff595bf6
1) all theorems in Orderings can now be given as a parameter
 obua parents: 
15574diff
changeset | 171 | NotEq (y, x,Thm ( [Asm n], Less.not_sym))] | 
| 14398 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 172 |     | _     => error ("linear_tac: unknown relation symbol ``" ^ rel ^
 | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 173 | "''returned by decomp_lin.")) | 
| 15531 | 174 | | NONE => []; | 
| 14398 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 175 | |
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 176 | (* ************************************************************************ *) | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 177 | (* *) | 
| 19250 | 178 | (* mkconcl_partial sign t : theory -> Term.term -> less *) | 
| 14398 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 179 | (* *) | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 180 | (* Translates conclusion t to an element of type less. *) | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 181 | (* Partial orders only. *) | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 182 | (* *) | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 183 | (* ************************************************************************ *) | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 184 | |
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 185 | fun mkconcl_partial sign t = | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 186 | case Less.decomp_part sign t of | 
| 15531 | 187 | SOME (x, rel, y) => (case rel of | 
| 14398 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 188 | "<" => ([Less (x, y, Asm ~1)], Asm 0) | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 189 | | "<=" => ([Le (x, y, Asm ~1)], Asm 0) | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 190 | | "=" => ([Le (x, y, Asm ~1), Le (y, x, Asm ~1)], | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 191 | Thm ([Asm 0, Asm 1], Less.eqI)) | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 192 | | "~=" => ([NotEq (x,y, Asm ~1)], Asm 0) | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 193 | | _ => raise Cannot) | 
| 15531 | 194 | | NONE => raise Cannot; | 
| 14398 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 195 | |
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 196 | (* ************************************************************************ *) | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 197 | (* *) | 
| 19250 | 198 | (* mkconcl_linear sign t : theory -> Term.term -> less *) | 
| 14398 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 199 | (* *) | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 200 | (* Translates conclusion t to an element of type less. *) | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 201 | (* Linear orders only. *) | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 202 | (* *) | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 203 | (* ************************************************************************ *) | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 204 | |
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 205 | fun mkconcl_linear sign t = | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 206 | case Less.decomp_lin sign t of | 
| 15531 | 207 | SOME (x, rel, y) => (case rel of | 
| 14398 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 208 | "<" => ([Less (x, y, Asm ~1)], Asm 0) | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 209 | | "~<" => ([Le (y, x, Asm ~1)], Thm ([Asm 0], Less.not_lessI)) | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 210 | | "<=" => ([Le (x, y, Asm ~1)], Asm 0) | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 211 | | "~<=" => ([Less (y, x, Asm ~1)], Thm ([Asm 0], Less.not_leI)) | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 212 | | "=" => ([Le (x, y, Asm ~1), Le (y, x, Asm ~1)], | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 213 | Thm ([Asm 0, Asm 1], Less.eqI)) | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 214 | | "~=" => ([NotEq (x,y, Asm ~1)], Asm 0) | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 215 | | _ => raise Cannot) | 
| 15531 | 216 | | NONE => raise Cannot; | 
| 14398 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 217 | |
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 218 | (* ******************************************************************* *) | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 219 | (* *) | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 220 | (* mergeLess (less1,less2): less * less -> less *) | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 221 | (* *) | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 222 | (* Merge to elements of type less according to the following rules *) | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 223 | (* *) | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 224 | (* x < y && y < z ==> x < z *) | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 225 | (* x < y && y <= z ==> x < z *) | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 226 | (* x <= y && y < z ==> x < z *) | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 227 | (* x <= y && y <= z ==> x <= z *) | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 228 | (* x <= y && x ~= y ==> x < y *) | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 229 | (* x ~= y && x <= y ==> x < y *) | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 230 | (* x < y && x ~= y ==> x < y *) | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 231 | (* x ~= y && x < y ==> x < y *) | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 232 | (* *) | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 233 | (* ******************************************************************* *) | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 234 | |
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 235 | fun mergeLess (Less (x, _, p) , Less (_ , z, q)) = | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 236 | Less (x, z, Thm ([p,q] , Less.less_trans)) | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 237 | | mergeLess (Less (x, _, p) , Le (_ , z, q)) = | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 238 | Less (x, z, Thm ([p,q] , Less.less_le_trans)) | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 239 | | mergeLess (Le (x, _, p) , Less (_ , z, q)) = | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 240 | Less (x, z, Thm ([p,q] , Less.le_less_trans)) | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 241 | | mergeLess (Le (x, z, p) , NotEq (x', z', q)) = | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 242 | if (x aconv x' andalso z aconv z' ) | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 243 | then Less (x, z, Thm ([p,q] , Less.le_neq_trans)) | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 244 | else error "linear/partial_tac: internal error le_neq_trans" | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 245 | | mergeLess (NotEq (x, z, p) , Le (x' , z', q)) = | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 246 | if (x aconv x' andalso z aconv z') | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 247 | then Less (x, z, Thm ([p,q] , Less.neq_le_trans)) | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 248 | else error "linear/partial_tac: internal error neq_le_trans" | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 249 | | mergeLess (NotEq (x, z, p) , Less (x' , z', q)) = | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 250 | if (x aconv x' andalso z aconv z') | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 251 | then Less ((x' , z', q)) | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 252 | else error "linear/partial_tac: internal error neq_less_trans" | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 253 | | mergeLess (Less (x, z, p) , NotEq (x', z', q)) = | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 254 | if (x aconv x' andalso z aconv z') | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 255 | then Less (x, z, p) | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 256 | else error "linear/partial_tac: internal error less_neq_trans" | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 257 | | mergeLess (Le (x, _, p) , Le (_ , z, q)) = | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 258 | Le (x, z, Thm ([p,q] , Less.le_trans)) | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 259 | | mergeLess (_, _) = | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 260 | error "linear/partial_tac: internal error: undefined case"; | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 261 | |
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 262 | |
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 263 | (* ******************************************************************** *) | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 264 | (* tr checks for valid transitivity step *) | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 265 | (* ******************************************************************** *) | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 266 | |
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 267 | infix tr; | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 268 | fun (Less (_, y, _)) tr (Le (x', _, _)) = ( y aconv x' ) | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 269 | | (Le (_, y, _)) tr (Less (x', _, _)) = ( y aconv x' ) | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 270 | | (Less (_, y, _)) tr (Less (x', _, _)) = ( y aconv x' ) | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 271 | | (Le (_, y, _)) tr (Le (x', _, _)) = ( y aconv x' ) | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 272 | | _ tr _ = false; | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 273 | |
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 274 | |
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 275 | (* ******************************************************************* *) | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 276 | (* *) | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 277 | (* transPath (Lesslist, Less): (less list * less) -> less *) | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 278 | (* *) | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 279 | (* If a path represented by a list of elements of type less is found, *) | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 280 | (* this needs to be contracted to a single element of type less. *) | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 281 | (* Prior to each transitivity step it is checked whether the step is *) | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 282 | (* valid. *) | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 283 | (* *) | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 284 | (* ******************************************************************* *) | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 285 | |
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 286 | fun transPath ([],lesss) = lesss | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 287 | | transPath (x::xs,lesss) = | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 288 | if lesss tr x then transPath (xs, mergeLess(lesss,x)) | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 289 | else error "linear/partial_tac: internal error transpath"; | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 290 | |
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 291 | (* ******************************************************************* *) | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 292 | (* *) | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 293 | (* less1 subsumes less2 : less -> less -> bool *) | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 294 | (* *) | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 295 | (* subsumes checks whether less1 implies less2 *) | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 296 | (* *) | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 297 | (* ******************************************************************* *) | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 298 | |
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 299 | infix subsumes; | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 300 | fun (Less (x, y, _)) subsumes (Le (x', y', _)) = | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 301 | (x aconv x' andalso y aconv y') | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 302 | | (Less (x, y, _)) subsumes (Less (x', y', _)) = | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 303 | (x aconv x' andalso y aconv y') | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 304 | | (Le (x, y, _)) subsumes (Le (x', y', _)) = | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 305 | (x aconv x' andalso y aconv y') | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 306 | | (Less (x, y, _)) subsumes (NotEq (x', y', _)) = | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 307 | (x aconv x' andalso y aconv y') orelse (y aconv x' andalso x aconv y') | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 308 | | (NotEq (x, y, _)) subsumes (NotEq (x', y', _)) = | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 309 | (x aconv x' andalso y aconv y') orelse (y aconv x' andalso x aconv y') | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 310 | | (Le _) subsumes (Less _) = | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 311 | error "linear/partial_tac: internal error: Le cannot subsume Less" | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 312 | | _ subsumes _ = false; | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 313 | |
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 314 | (* ******************************************************************* *) | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 315 | (* *) | 
| 15531 | 316 | (* triv_solv less1 : less -> proof option *) | 
| 14398 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 317 | (* *) | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 318 | (* Solves trivial goal x <= x. *) | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 319 | (* *) | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 320 | (* ******************************************************************* *) | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 321 | |
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 322 | fun triv_solv (Le (x, x', _)) = | 
| 15531 | 323 | if x aconv x' then SOME (Thm ([], Less.le_refl)) | 
| 324 | else NONE | |
| 325 | | triv_solv _ = NONE; | |
| 14398 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 326 | |
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 327 | (* ********************************************************************* *) | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 328 | (* Graph functions *) | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 329 | (* ********************************************************************* *) | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 330 | |
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 331 | |
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 332 | |
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 333 | (* ******************************************************************* *) | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 334 | (* *) | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 335 | (* General: *) | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 336 | (* *) | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 337 | (* Inequalities are represented by various types of graphs. *) | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 338 | (* *) | 
| 14445 | 339 | (* 1. (Term.term * (Term.term * less) list) list *) | 
| 14398 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 340 | (* - Graph of this type is generated from the assumptions, *) | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 341 | (* it does contain information on which edge stems from which *) | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 342 | (* assumption. *) | 
| 14445 | 343 | (* - Used to compute strongly connected components *) | 
| 344 | (* - Used to compute component subgraphs *) | |
| 345 | (* - Used for component subgraphs to reconstruct paths in components*) | |
| 14398 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 346 | (* *) | 
| 14445 | 347 | (* 2. (int * (int * less) list ) list *) | 
| 14398 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 348 | (* - Graph of this type is generated from the strong components of *) | 
| 14445 | 349 | (* graph of type 1. It consists of the strong components of *) | 
| 350 | (* graph 1, where nodes are indices of the components. *) | |
| 14398 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 351 | (* Only edges between components are part of this graph. *) | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 352 | (* - Used to reconstruct paths between several components. *) | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 353 | (* *) | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 354 | (* ******************************************************************* *) | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 355 | |
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 356 | |
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 357 | (* *********************************************************** *) | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 358 | (* Functions for constructing graphs *) | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 359 | (* *********************************************************** *) | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 360 | |
| 14445 | 361 | fun addEdge (v,d,[]) = [(v,d)] | 
| 362 | | addEdge (v,d,((u,dl)::el)) = if v aconv u then ((v,d@dl)::el) | |
| 363 | else (u,dl):: (addEdge(v,d,el)); | |
| 14398 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 364 | |
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 365 | (* ********************************************************************* *) | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 366 | (* *) | 
| 14445 | 367 | (* mkGraphs constructs from a list of objects of type less a graph g, *) | 
| 368 | (* by taking all edges that are candidate for a <=, and a list neqE, by *) | |
| 369 | (* taking all edges that are candiate for a ~= *) | |
| 14398 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 370 | (* *) | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 371 | (* ********************************************************************* *) | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 372 | |
| 14445 | 373 | fun mkGraphs [] = ([],[],[]) | 
| 374 | | mkGraphs lessList = | |
| 375 | let | |
| 14398 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 376 | |
| 14445 | 377 | fun buildGraphs ([],leqG,neqG,neqE) = (leqG, neqG, neqE) | 
| 378 | | buildGraphs (l::ls, leqG,neqG, neqE) = case l of | |
| 379 | (Less (x,y,p)) => | |
| 380 | buildGraphs (ls, addEdge (x,[(y,(Less (x, y, p)))],leqG) , | |
| 381 | addEdge (x,[(y,(Less (x, y, p)))],neqG), l::neqE) | |
| 14398 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 382 | | (Le (x,y,p)) => | 
| 14445 | 383 | buildGraphs (ls, addEdge (x,[(y,(Le (x, y,p)))],leqG) , neqG, neqE) | 
| 384 | | (NotEq (x,y,p)) => | |
| 385 | buildGraphs (ls, leqG , addEdge (x,[(y,(NotEq (x, y, p)))],neqG), l::neqE) ; | |
| 386 | ||
| 387 | in buildGraphs (lessList, [], [], []) end; | |
| 14398 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 388 | |
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 389 | |
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 390 | (* *********************************************************************** *) | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 391 | (* *) | 
| 14445 | 392 | (* adjacent g u : (''a * 'b list ) list -> ''a -> 'b list                  *)
 | 
| 14398 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 393 | (* *) | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 394 | (* List of successors of u in graph g *) | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 395 | (* *) | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 396 | (* *********************************************************************** *) | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 397 | |
| 14445 | 398 | fun adjacent eq_comp ((v,adj)::el) u = | 
| 399 | if eq_comp (u, v) then adj else adjacent eq_comp el u | |
| 400 | | adjacent _ [] _ = [] | |
| 14398 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 401 | |
| 14445 | 402 | |
| 14398 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 403 | (* *********************************************************************** *) | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 404 | (* *) | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 405 | (* transpose g: *) | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 406 | (* (''a * ''a list) list -> (''a * ''a list) list                          *)
 | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 407 | (* *) | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 408 | (* Computes transposed graph g' from g *) | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 409 | (* by reversing all edges u -> v to v -> u *) | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 410 | (* *) | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 411 | (* *********************************************************************** *) | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 412 | |
| 14445 | 413 | fun transpose eq_comp g = | 
| 14398 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 414 | let | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 415 | (* Compute list of reversed edges for each adjacency list *) | 
| 14445 | 416 | fun flip (u,(v,l)::el) = (v,(u,l)) :: flip (u,el) | 
| 14398 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 417 | | flip (_,nil) = nil | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 418 | |
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 419 | (* Compute adjacency list for node u from the list of edges | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 420 | and return a likewise reduced list of edges. The list of edges | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 421 | is searches for edges starting from u, and these edges are removed. *) | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 422 | fun gather (u,(v,w)::el) = | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 423 | let | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 424 | val (adj,edges) = gather (u,el) | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 425 | in | 
| 14445 | 426 | if eq_comp (u, v) then (w::adj,edges) | 
| 14398 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 427 | else (adj,(v,w)::edges) | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 428 | end | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 429 | | gather (_,nil) = (nil,nil) | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 430 | |
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 431 | (* For every node in the input graph, call gather to find all reachable | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 432 | nodes in the list of edges *) | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 433 | fun assemble ((u,_)::el) edges = | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 434 | let val (adj,edges) = gather (u,edges) | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 435 | in (u,adj) :: assemble el edges | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 436 | end | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 437 | | assemble nil _ = nil | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 438 | |
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 439 | (* Compute, for each adjacency list, the list with reversed edges, | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 440 | and concatenate these lists. *) | 
| 15574 
b1d1b5bfc464
Removed practically all references to Library.foldr.
 skalberg parents: 
15570diff
changeset | 441 | val flipped = foldr (op @) nil (map flip g) | 
| 14398 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 442 | |
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 443 | in assemble g flipped end | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 444 | |
| 14445 | 445 | (* *********************************************************************** *) | 
| 446 | (* *) | |
| 447 | (* scc_term : (term * term list) list -> term list list *) | |
| 448 | (* *) | |
| 449 | (* The following is based on the algorithm for finding strongly connected *) | |
| 450 | (* components described in Introduction to Algorithms, by Cormon, Leiserson*) | |
| 451 | (* and Rivest, section 23.5. The input G is an adjacency list description *) | |
| 452 | (* of a directed graph. The output is a list of the strongly connected *) | |
| 453 | (* components (each a list of vertices). *) | |
| 454 | (* *) | |
| 455 | (* *) | |
| 456 | (* *********************************************************************** *) | |
| 14398 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 457 | |
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 458 | fun scc_term G = | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 459 | let | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 460 | (* Ordered list of the vertices that DFS has finished with; | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 461 | most recently finished goes at the head. *) | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 462 | val finish : term list ref = ref nil | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 463 | |
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 464 | (* List of vertices which have been visited. *) | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 465 | val visited : term list ref = ref nil | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 466 | |
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 467 | fun been_visited v = exists (fn w => w aconv v) (!visited) | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 468 | |
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 469 | (* Given the adjacency list rep of a graph (a list of pairs), | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 470 | return just the first element of each pair, yielding the | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 471 | vertex list. *) | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 472 | val members = map (fn (v,_) => v) | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 473 | |
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 474 | (* Returns the nodes in the DFS tree rooted at u in g *) | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 475 | fun dfs_visit g u : term list = | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 476 | let | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 477 | val _ = visited := u :: !visited | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 478 | val descendents = | 
| 15574 
b1d1b5bfc464
Removed practically all references to Library.foldr.
 skalberg parents: 
15570diff
changeset | 479 | foldr (fn ((v,l),ds) => if been_visited v then ds | 
| 14398 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 480 | else v :: dfs_visit g v @ ds) | 
| 15574 
b1d1b5bfc464
Removed practically all references to Library.foldr.
 skalberg parents: 
15570diff
changeset | 481 | nil (adjacent (op aconv) g u) | 
| 14398 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 482 | in | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 483 | finish := u :: !finish; | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 484 | descendents | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 485 | end | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 486 | in | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 487 | |
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 488 | (* DFS on the graph; apply dfs_visit to each vertex in | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 489 | the graph, checking first to make sure the vertex is | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 490 | as yet unvisited. *) | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 491 | app (fn u => if been_visited u then () | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 492 | else (dfs_visit G u; ())) (members G); | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 493 | visited := nil; | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 494 | |
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 495 | (* We don't reset finish because its value is used by | 
| 14445 | 496 | foldl below, and it will never be used again (even | 
| 14398 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 497 | though dfs_visit will continue to modify it). *) | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 498 | |
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 499 | (* DFS on the transpose. The vertices returned by | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 500 | dfs_visit along with u form a connected component. We | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 501 | collect all the connected components together in a | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 502 | list, which is what is returned. *) | 
| 15570 | 503 | Library.foldl (fn (comps,u) => | 
| 14398 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 504 | if been_visited u then comps | 
| 14445 | 505 | else ((u :: dfs_visit (transpose (op aconv) G) u) :: comps)) (nil,(!finish)) | 
| 14398 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 506 | end; | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 507 | |
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 508 | |
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 509 | (* *********************************************************************** *) | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 510 | (* *) | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 511 | (* dfs_int_reachable g u: *) | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 512 | (* (int * int list) list -> int -> int list *) | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 513 | (* *) | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 514 | (* Computes list of all nodes reachable from u in g. *) | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 515 | (* *) | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 516 | (* *********************************************************************** *) | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 517 | |
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 518 | fun dfs_int_reachable g u = | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 519 | let | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 520 | (* List of vertices which have been visited. *) | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 521 | val visited : int list ref = ref nil | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 522 | |
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 523 | fun been_visited v = exists (fn w => w = v) (!visited) | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 524 | |
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 525 | fun dfs_visit g u : int list = | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 526 | let | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 527 | val _ = visited := u :: !visited | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 528 | val descendents = | 
| 15574 
b1d1b5bfc464
Removed practically all references to Library.foldr.
 skalberg parents: 
15570diff
changeset | 529 | foldr (fn ((v,l),ds) => if been_visited v then ds | 
| 14398 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 530 | else v :: dfs_visit g v @ ds) | 
| 15574 
b1d1b5bfc464
Removed practically all references to Library.foldr.
 skalberg parents: 
15570diff
changeset | 531 | nil (adjacent (op =) g u) | 
| 14398 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 532 | in descendents end | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 533 | |
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 534 | in u :: dfs_visit g u end; | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 535 | |
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 536 | |
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 537 | fun indexComps components = | 
| 14445 | 538 | ListPair.map (fn (a,b) => (a,b)) (0 upto (length components -1), components); | 
| 14398 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 539 | |
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 540 | fun indexNodes IndexComp = | 
| 15570 | 541 | List.concat (map (fn (index, comp) => (map (fn v => (v,index)) comp)) IndexComp); | 
| 14398 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 542 | |
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 543 | fun getIndex v [] = ~1 | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 544 | | getIndex v ((v',k)::vs) = if v aconv v' then k else getIndex v vs; | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 545 | |
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 546 | |
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 547 | |
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 548 | (* *********************************************************************** *) | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 549 | (* *) | 
| 14445 | 550 | (* dfs eq_comp g u v: *) | 
| 551 | (* ('a * 'a -> bool) -> ('a  *( 'a * less) list) list ->                   *)
 | |
| 552 | (* 'a -> 'a -> (bool * ('a * less) list)                                   *) 
 | |
| 14398 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 553 | (* *) | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 554 | (* Depth first search of v from u. *) | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 555 | (* Returns (true, path(u, v)) if successful, otherwise (false, []). *) | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 556 | (* *) | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 557 | (* *********************************************************************** *) | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 558 | |
| 14445 | 559 | fun dfs eq_comp g u v = | 
| 14398 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 560 | let | 
| 14445 | 561 | val pred = ref nil; | 
| 562 | val visited = ref nil; | |
| 14398 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 563 | |
| 14445 | 564 | fun been_visited v = exists (fn w => eq_comp (w, v)) (!visited) | 
| 14398 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 565 | |
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 566 | fun dfs_visit u' = | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 567 | let val _ = visited := u' :: (!visited) | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 568 | |
| 14445 | 569 | fun update (x,l) = let val _ = pred := (x,l) ::(!pred) in () end; | 
| 14398 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 570 | |
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 571 | in if been_visited v then () | 
| 14445 | 572 | else (app (fn (v',l) => if been_visited v' then () else ( | 
| 573 | update (v',l); | |
| 574 | dfs_visit v'; ()) )) (adjacent eq_comp g u') | |
| 575 | end | |
| 14398 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 576 | in | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 577 | dfs_visit u; | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 578 | if (been_visited v) then (true, (!pred)) else (false , []) | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 579 | end; | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 580 | |
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 581 | |
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 582 | (* *********************************************************************** *) | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 583 | (* *) | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 584 | (* completeTermPath u v g: *) | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 585 | (* Term.term -> Term.term -> (Term.term * (Term.term * less) list) list *) | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 586 | (* -> less list *) | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 587 | (* *) | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 588 | (* Complete the path from u to v in graph g. Path search is performed *) | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 589 | (* with dfs_term g u v. This yields for each node v' its predecessor u' *) | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 590 | (* and the edge u' -> v'. Allows traversing graph backwards from v and *) | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 591 | (* finding the path u -> v. *) | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 592 | (* *) | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 593 | (* *********************************************************************** *) | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 594 | |
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 595 | |
| 14445 | 596 | fun completeTermPath u v g = | 
| 14398 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 597 | let | 
| 14445 | 598 | val (found, tmp) = dfs (op aconv) g u v ; | 
| 599 | val pred = map snd tmp; | |
| 14398 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 600 | |
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 601 | fun path x y = | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 602 | let | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 603 | |
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 604 | (* find predecessor u of node v and the edge u -> v *) | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 605 | |
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 606 | fun lookup v [] = raise Cannot | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 607 | | lookup v (e::es) = if (upper e) aconv v then e else lookup v es; | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 608 | |
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 609 | (* traverse path backwards and return list of visited edges *) | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 610 | fun rev_path v = | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 611 | let val l = lookup v pred | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 612 | val u = lower l; | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 613 | in | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 614 | if u aconv x then [l] | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 615 | else (rev_path u) @ [l] | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 616 | end | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 617 | in rev_path y end; | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 618 | |
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 619 | in | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 620 | if found then (if u aconv v then [(Le (u, v, (Thm ([], Less.le_refl))))] | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 621 | else path u v ) else raise Cannot | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 622 | end; | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 623 | |
| 14445 | 624 | |
| 14398 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 625 | (* *********************************************************************** *) | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 626 | (* *) | 
| 14445 | 627 | (* findProof (sccGraph, neqE, ntc, sccSubgraphs) subgoal: *) | 
| 14398 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 628 | (* *) | 
| 14445 | 629 | (* (int * (int * less) list) list * less list * (Term.term * int) list *) | 
| 630 | (* * ((term * (term * less) list) list) list -> Less -> proof *) | |
| 14398 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 631 | (* *) | 
| 14445 | 632 | (* findProof constructs from graphs (sccGraph, sccSubgraphs) and neqE a *) | 
| 633 | (* proof for subgoal. Raises exception Cannot if this is not possible. *) | |
| 14398 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 634 | (* *) | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 635 | (* *********************************************************************** *) | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 636 | |
| 14445 | 637 | fun findProof (sccGraph, neqE, ntc, sccSubgraphs) subgoal = | 
| 14398 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 638 | let | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 639 | |
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 640 | (* complete path x y from component graph *) | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 641 | fun completeComponentPath x y predlist = | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 642 | let | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 643 | val xi = getIndex x ntc | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 644 | val yi = getIndex y ntc | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 645 | |
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 646 | fun lookup k [] = raise Cannot | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 647 | | lookup k ((h,l)::us) = if k = h then l else lookup k us; | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 648 | |
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 649 | fun rev_completeComponentPath y' = | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 650 | let val edge = lookup (getIndex y' ntc) predlist | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 651 | val u = lower edge | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 652 | val v = upper edge | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 653 | in | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 654 | if (getIndex u ntc) = xi then | 
| 15570 | 655 | (completeTermPath x u (List.nth(sccSubgraphs, xi)) )@[edge] | 
| 656 | @(completeTermPath v y' (List.nth(sccSubgraphs, getIndex y' ntc)) ) | |
| 14445 | 657 | else (rev_completeComponentPath u)@[edge] | 
| 15570 | 658 | @(completeTermPath v y' (List.nth(sccSubgraphs, getIndex y' ntc)) ) | 
| 14398 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 659 | end | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 660 | in | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 661 | if x aconv y then | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 662 | [(Le (x, y, (Thm ([], Less.le_refl))))] | 
| 15570 | 663 | else ( if xi = yi then completeTermPath x y (List.nth(sccSubgraphs, xi)) | 
| 14398 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 664 | else rev_completeComponentPath y ) | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 665 | end; | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 666 | |
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 667 | (* ******************************************************************* *) | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 668 | (* findLess e x y xi yi xreachable yreachable *) | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 669 | (* *) | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 670 | (* Find a path from x through e to y, of weight < *) | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 671 | (* ******************************************************************* *) | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 672 | |
| 14445 | 673 | fun findLess e x y xi yi xreachable yreachable = | 
| 14398 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 674 | let val u = lower e | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 675 | val v = upper e | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 676 | val ui = getIndex u ntc | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 677 | val vi = getIndex v ntc | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 678 | |
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 679 | in | 
| 14445 | 680 | if ui mem xreachable andalso vi mem xreachable andalso | 
| 681 | ui mem yreachable andalso vi mem yreachable then ( | |
| 14398 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 682 | |
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 683 | (case e of (Less (_, _, _)) => | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 684 | let | 
| 14445 | 685 | val (xufound, xupred) = dfs (op =) sccGraph xi (getIndex u ntc) | 
| 14398 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 686 | in | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 687 | if xufound then ( | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 688 | let | 
| 14445 | 689 | val (vyfound, vypred) = dfs (op =) sccGraph (getIndex v ntc) yi | 
| 14398 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 690 | in | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 691 | if vyfound then ( | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 692 | let | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 693 | val xypath = (completeComponentPath x u xupred)@[e]@(completeComponentPath v y vypred) | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 694 | val xyLesss = transPath (tl xypath, hd xypath) | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 695 | in | 
| 15531 | 696 | if xyLesss subsumes subgoal then SOME (getprf xyLesss) | 
| 697 | else NONE | |
| 14398 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 698 | end) | 
| 15531 | 699 | else NONE | 
| 14398 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 700 | end) | 
| 15531 | 701 | else NONE | 
| 14398 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 702 | end | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 703 | | _ => | 
| 14445 | 704 | let val (uvfound, uvpred) = dfs (op =) sccGraph (getIndex u ntc) (getIndex v ntc) | 
| 14398 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 705 | in | 
| 14445 | 706 | if uvfound then ( | 
| 14398 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 707 | let | 
| 14445 | 708 | val (xufound, xupred) = dfs (op =) sccGraph xi (getIndex u ntc) | 
| 14398 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 709 | in | 
| 14445 | 710 | if xufound then ( | 
| 14398 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 711 | let | 
| 14445 | 712 | val (vyfound, vypred) = dfs (op =) sccGraph (getIndex v ntc) yi | 
| 14398 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 713 | in | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 714 | if vyfound then ( | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 715 | let | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 716 | val uvpath = completeComponentPath u v uvpred | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 717 | val uvLesss = mergeLess ( transPath (tl uvpath, hd uvpath), e) | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 718 | val xypath = (completeComponentPath x u xupred)@[uvLesss]@(completeComponentPath v y vypred) | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 719 | val xyLesss = transPath (tl xypath, hd xypath) | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 720 | in | 
| 15531 | 721 | if xyLesss subsumes subgoal then SOME (getprf xyLesss) | 
| 722 | else NONE | |
| 14398 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 723 | end ) | 
| 15531 | 724 | else NONE | 
| 14398 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 725 | end) | 
| 15531 | 726 | else NONE | 
| 14398 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 727 | end ) | 
| 15531 | 728 | else NONE | 
| 14398 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 729 | end ) | 
| 15531 | 730 | ) else NONE | 
| 14398 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 731 | end; | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 732 | |
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 733 | |
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 734 | in | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 735 | (* looking for x <= y: any path from x to y is sufficient *) | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 736 | case subgoal of (Le (x, y, _)) => ( | 
| 19617 | 737 | if null sccGraph then raise Cannot else ( | 
| 14398 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 738 | let | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 739 | val xi = getIndex x ntc | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 740 | val yi = getIndex y ntc | 
| 14445 | 741 | (* searches in sccGraph a path from xi to yi *) | 
| 742 | val (found, pred) = dfs (op =) sccGraph xi yi | |
| 14398 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 743 | in | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 744 | if found then ( | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 745 | let val xypath = completeComponentPath x y pred | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 746 | val xyLesss = transPath (tl xypath, hd xypath) | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 747 | in | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 748 | (case xyLesss of | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 749 | (Less (_, _, q)) => if xyLesss subsumes subgoal then (Thm ([q], Less.less_imp_le)) | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 750 | else raise Cannot | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 751 | | _ => if xyLesss subsumes subgoal then (getprf xyLesss) | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 752 | else raise Cannot) | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 753 | end ) | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 754 | else raise Cannot | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 755 | end | 
| 14445 | 756 | ) | 
| 14398 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 757 | ) | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 758 | (* looking for x < y: particular path required, which is not necessarily | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 759 | found by normal dfs *) | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 760 | | (Less (x, y, _)) => ( | 
| 19617 | 761 | if null sccGraph then raise Cannot else ( | 
| 14398 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 762 | let | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 763 | val xi = getIndex x ntc | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 764 | val yi = getIndex y ntc | 
| 14445 | 765 | val sccGraph_transpose = transpose (op =) sccGraph | 
| 766 | (* all components that can be reached from component xi *) | |
| 767 | val xreachable = dfs_int_reachable sccGraph xi | |
| 768 | (* all comonents reachable from y in the transposed graph sccGraph' *) | |
| 769 | val yreachable = dfs_int_reachable sccGraph_transpose yi | |
| 14398 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 770 | (* for all edges u ~= v or u < v check if they are part of path x < y *) | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 771 | fun processNeqEdges [] = raise Cannot | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 772 | | processNeqEdges (e::es) = | 
| 15531 | 773 | case (findLess e x y xi yi xreachable yreachable) of (SOME prf) => prf | 
| 14398 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 774 | | _ => processNeqEdges es | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 775 | |
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 776 | in | 
| 14445 | 777 | processNeqEdges neqE | 
| 14398 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 778 | end | 
| 14445 | 779 | ) | 
| 14398 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 780 | ) | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 781 | | (NotEq (x, y, _)) => ( | 
| 14445 | 782 | (* if there aren't any edges that are candidate for a ~= raise Cannot *) | 
| 19617 | 783 | if null neqE then raise Cannot | 
| 14445 | 784 | (* if there aren't any edges that are candidate for <= then just search a edge in neqE that implies the subgoal *) | 
| 19617 | 785 | else if null sccSubgraphs then ( | 
| 14445 | 786 | (case (Library.find_first (fn fact => fact subsumes subgoal) neqE, subgoal) of | 
| 15531 | 787 | ( SOME (NotEq (x, y, p)), NotEq (x', y', _)) => | 
| 14445 | 788 | if (x aconv x' andalso y aconv y') then p | 
| 16743 
21dbff595bf6
1) all theorems in Orderings can now be given as a parameter
 obua parents: 
15574diff
changeset | 789 | else Thm ([p], Less.not_sym) | 
| 15531 | 790 | | ( SOME (Less (x, y, p)), NotEq (x', y', _)) => | 
| 14445 | 791 | if x aconv x' andalso y aconv y' then (Thm ([p], Less.less_imp_neq)) | 
| 16743 
21dbff595bf6
1) all theorems in Orderings can now be given as a parameter
 obua parents: 
15574diff
changeset | 792 | else (Thm ([(Thm ([p], Less.less_imp_neq))], Less.not_sym)) | 
| 14445 | 793 | | _ => raise Cannot) | 
| 794 | ) else ( | |
| 795 | ||
| 796 | let val xi = getIndex x ntc | |
| 14398 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 797 | val yi = getIndex y ntc | 
| 14445 | 798 | val sccGraph_transpose = transpose (op =) sccGraph | 
| 799 | val xreachable = dfs_int_reachable sccGraph xi | |
| 800 | val yreachable = dfs_int_reachable sccGraph_transpose yi | |
| 14398 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 801 | |
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 802 | fun processNeqEdges [] = raise Cannot | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 803 | | processNeqEdges (e::es) = ( | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 804 | let val u = lower e | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 805 | val v = upper e | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 806 | val ui = getIndex u ntc | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 807 | val vi = getIndex v ntc | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 808 | |
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 809 | in | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 810 | (* if x ~= y follows from edge e *) | 
| 14445 | 811 | if e subsumes subgoal then ( | 
| 14398 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 812 | case e of (Less (u, v, q)) => ( | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 813 | if u aconv x andalso v aconv y then (Thm ([q], Less.less_imp_neq)) | 
| 16743 
21dbff595bf6
1) all theorems in Orderings can now be given as a parameter
 obua parents: 
15574diff
changeset | 814 | else (Thm ([(Thm ([q], Less.less_imp_neq))], Less.not_sym)) | 
| 14398 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 815 | ) | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 816 | | (NotEq (u,v, q)) => ( | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 817 | if u aconv x andalso v aconv y then q | 
| 16743 
21dbff595bf6
1) all theorems in Orderings can now be given as a parameter
 obua parents: 
15574diff
changeset | 818 | else (Thm ([q], Less.not_sym)) | 
| 14398 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 819 | ) | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 820 | ) | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 821 | (* if SCC_x is linked to SCC_y via edge e *) | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 822 | else if ui = xi andalso vi = yi then ( | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 823 | case e of (Less (_, _,_)) => ( | 
| 15570 | 824 | let val xypath = (completeTermPath x u (List.nth(sccSubgraphs, ui)) ) @ [e] @ (completeTermPath v y (List.nth(sccSubgraphs, vi)) ) | 
| 14398 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 825 | val xyLesss = transPath (tl xypath, hd xypath) | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 826 | in (Thm ([getprf xyLesss], Less.less_imp_neq)) end) | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 827 | | _ => ( | 
| 14445 | 828 | let | 
| 15570 | 829 | val xupath = completeTermPath x u (List.nth(sccSubgraphs, ui)) | 
| 830 | val uxpath = completeTermPath u x (List.nth(sccSubgraphs, ui)) | |
| 831 | val vypath = completeTermPath v y (List.nth(sccSubgraphs, vi)) | |
| 832 | val yvpath = completeTermPath y v (List.nth(sccSubgraphs, vi)) | |
| 14398 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 833 | val xuLesss = transPath (tl xupath, hd xupath) | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 834 | val uxLesss = transPath (tl uxpath, hd uxpath) | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 835 | val vyLesss = transPath (tl vypath, hd vypath) | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 836 | val yvLesss = transPath (tl yvpath, hd yvpath) | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 837 | val x_eq_u = (Thm ([(getprf xuLesss),(getprf uxLesss)], Less.eqI)) | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 838 | val v_eq_y = (Thm ([(getprf vyLesss),(getprf yvLesss)], Less.eqI)) | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 839 | in | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 840 | (Thm ([x_eq_u , (getprf e), v_eq_y ], Less.eq_neq_eq_imp_neq)) | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 841 | end | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 842 | ) | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 843 | ) else if ui = yi andalso vi = xi then ( | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 844 | case e of (Less (_, _,_)) => ( | 
| 15570 | 845 | let val xypath = (completeTermPath y u (List.nth(sccSubgraphs, ui)) ) @ [e] @ (completeTermPath v x (List.nth(sccSubgraphs, vi)) ) | 
| 14398 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 846 | val xyLesss = transPath (tl xypath, hd xypath) | 
| 16743 
21dbff595bf6
1) all theorems in Orderings can now be given as a parameter
 obua parents: 
15574diff
changeset | 847 | in (Thm ([(Thm ([getprf xyLesss], Less.less_imp_neq))] , Less.not_sym)) end ) | 
| 14398 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 848 | | _ => ( | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 849 | |
| 15570 | 850 | let val yupath = completeTermPath y u (List.nth(sccSubgraphs, ui)) | 
| 851 | val uypath = completeTermPath u y (List.nth(sccSubgraphs, ui)) | |
| 852 | val vxpath = completeTermPath v x (List.nth(sccSubgraphs, vi)) | |
| 853 | val xvpath = completeTermPath x v (List.nth(sccSubgraphs, vi)) | |
| 14398 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 854 | val yuLesss = transPath (tl yupath, hd yupath) | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 855 | val uyLesss = transPath (tl uypath, hd uypath) | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 856 | val vxLesss = transPath (tl vxpath, hd vxpath) | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 857 | val xvLesss = transPath (tl xvpath, hd xvpath) | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 858 | val y_eq_u = (Thm ([(getprf yuLesss),(getprf uyLesss)], Less.eqI)) | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 859 | val v_eq_x = (Thm ([(getprf vxLesss),(getprf xvLesss)], Less.eqI)) | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 860 | in | 
| 16743 
21dbff595bf6
1) all theorems in Orderings can now be given as a parameter
 obua parents: 
15574diff
changeset | 861 | (Thm ([(Thm ([y_eq_u , (getprf e), v_eq_x ], Less.eq_neq_eq_imp_neq))], Less.not_sym)) | 
| 14398 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 862 | end | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 863 | ) | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 864 | ) else ( | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 865 | (* there exists a path x < y or y < x such that | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 866 | x ~= y may be concluded *) | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 867 | case (findLess e x y xi yi xreachable yreachable) of | 
| 15531 | 868 | (SOME prf) => (Thm ([prf], Less.less_imp_neq)) | 
| 869 | | NONE => ( | |
| 14398 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 870 | let | 
| 14445 | 871 | val yr = dfs_int_reachable sccGraph yi | 
| 872 | val xr = dfs_int_reachable sccGraph_transpose xi | |
| 14398 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 873 | in | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 874 | case (findLess e y x yi xi yr xr) of | 
| 16743 
21dbff595bf6
1) all theorems in Orderings can now be given as a parameter
 obua parents: 
15574diff
changeset | 875 | (SOME prf) => (Thm ([(Thm ([prf], Less.less_imp_neq))], Less.not_sym)) | 
| 14398 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 876 | | _ => processNeqEdges es | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 877 | end) | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 878 | ) end) | 
| 14445 | 879 | in processNeqEdges neqE end) | 
| 14398 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 880 | ) | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 881 | end; | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 882 | |
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 883 | |
| 14445 | 884 | (* ******************************************************************* *) | 
| 885 | (* *) | |
| 886 | (* mk_sccGraphs components leqG neqG ntc : *) | |
| 887 | (* Term.term list list -> *) | |
| 888 | (* (Term.term * (Term.term * less) list) list -> *) | |
| 889 | (* (Term.term * (Term.term * less) list) list -> *) | |
| 890 | (* (Term.term * int) list -> *) | |
| 891 | (* (int * (int * less) list) list * *) | |
| 892 | (* ((Term.term * (Term.term * less) list) list) list *) | |
| 893 | (* *) | |
| 894 | (* *) | |
| 895 | (* Computes, from graph leqG, list of all its components and the list *) | |
| 896 | (* ntc (nodes, index of component) a graph whose nodes are the *) | |
| 897 | (* indices of the components of g. Egdes of the new graph are *) | |
| 898 | (* only the edges of g linking two components. Also computes for each *) | |
| 899 | (* component the subgraph of leqG that forms this component. *) | |
| 900 | (* *) | |
| 901 | (* For each component SCC_i is checked if there exists a edge in neqG *) | |
| 902 | (* that leads to a contradiction. *) | |
| 903 | (* *) | |
| 904 | (* We have a contradiction for edge u ~= v and u < v if: *) | |
| 905 | (* - u and v are in the same component, *) | |
| 906 | (* that is, a path u <= v and a path v <= u exist, hence u = v. *) | |
| 907 | (* From irreflexivity of < follows u < u or v < v. Ex false quodlibet. *) | |
| 908 | (* *) | |
| 909 | (* ******************************************************************* *) | |
| 14398 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 910 | |
| 14445 | 911 | fun mk_sccGraphs _ [] _ _ = ([],[]) | 
| 912 | | mk_sccGraphs components leqG neqG ntc = | |
| 913 | let | |
| 914 | (* Liste (Index der Komponente, Komponente *) | |
| 915 | val IndexComp = indexComps components; | |
| 14398 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 916 | |
| 14445 | 917 | |
| 918 | fun handleContr edge g = | |
| 14398 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 919 | (case edge of | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 920 | (Less (x, y, _)) => ( | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 921 | let | 
| 14445 | 922 | val xxpath = edge :: (completeTermPath y x g ) | 
| 14398 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 923 | val xxLesss = transPath (tl xxpath, hd xxpath) | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 924 | val q = getprf xxLesss | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 925 | in | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 926 | raise (Contr (Thm ([q], Less.less_reflE ))) | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 927 | end | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 928 | ) | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 929 | | (NotEq (x, y, _)) => ( | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 930 | let | 
| 14445 | 931 | val xypath = (completeTermPath x y g ) | 
| 932 | val yxpath = (completeTermPath y x g ) | |
| 14398 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 933 | val xyLesss = transPath (tl xypath, hd xypath) | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 934 | val yxLesss = transPath (tl yxpath, hd yxpath) | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 935 | val q = getprf (mergeLess ((mergeLess (edge, xyLesss)),yxLesss )) | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 936 | in | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 937 | raise (Contr (Thm ([q], Less.less_reflE ))) | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 938 | end | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 939 | ) | 
| 14445 | 940 | | _ => error "trans_tac/handleContr: invalid Contradiction"); | 
| 941 | ||
| 942 | ||
| 943 | (* k is index of the actual component *) | |
| 944 | ||
| 945 | fun processComponent (k, comp) = | |
| 946 | let | |
| 947 | (* all edges with weight <= of the actual component *) | |
| 15570 | 948 | val leqEdges = List.concat (map (adjacent (op aconv) leqG) comp); | 
| 14445 | 949 | (* all edges with weight ~= of the actual component *) | 
| 15570 | 950 | val neqEdges = map snd (List.concat (map (adjacent (op aconv) neqG) comp)); | 
| 14398 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 951 | |
| 14445 | 952 | (* find an edge leading to a contradiction *) | 
| 15531 | 953 | fun findContr [] = NONE | 
| 14445 | 954 | | findContr (e::es) = | 
| 955 | let val ui = (getIndex (lower e) ntc) | |
| 956 | val vi = (getIndex (upper e) ntc) | |
| 957 | in | |
| 15531 | 958 | if ui = vi then SOME e | 
| 14445 | 959 | else findContr es | 
| 960 | end; | |
| 961 | ||
| 962 | (* sort edges into component internal edges and | |
| 963 | edges pointing away from the component *) | |
| 964 | fun sortEdges [] (intern,extern) = (intern,extern) | |
| 965 | | sortEdges ((v,l)::es) (intern, extern) = | |
| 966 | let val k' = getIndex v ntc in | |
| 967 | if k' = k then | |
| 968 | sortEdges es (l::intern, extern) | |
| 969 | else sortEdges es (intern, (k',l)::extern) end; | |
| 970 | ||
| 971 | (* Insert edge into sorted list of edges, where edge is | |
| 972 | only added if | |
| 973 | - it is found for the first time | |
| 974 | - it is a <= edge and no parallel < edge was found earlier | |
| 975 | - it is a < edge | |
| 976 | *) | |
| 977 | fun insert (h,l) [] = [(h,l)] | |
| 978 | | insert (h,l) ((k',l')::es) = if h = k' then ( | |
| 979 | case l of (Less (_, _, _)) => (h,l)::es | |
| 980 | | _ => (case l' of (Less (_, _, _)) => (h,l')::es | |
| 981 | | _ => (k',l)::es) ) | |
| 982 | else (k',l'):: insert (h,l) es; | |
| 983 | ||
| 984 | (* Reorganise list of edges such that | |
| 985 | - duplicate edges are removed | |
| 986 | - if a < edge and a <= edge exist at the same time, | |
| 987 | remove <= edge *) | |
| 988 | fun reOrganizeEdges [] sorted = sorted: (int * less) list | |
| 989 | | reOrganizeEdges (e::es) sorted = reOrganizeEdges es (insert e sorted); | |
| 990 | ||
| 991 | (* construct the subgraph forming the strongly connected component | |
| 992 | from the edge list *) | |
| 993 | fun sccSubGraph [] g = g | |
| 994 | | sccSubGraph (l::ls) g = | |
| 995 | sccSubGraph ls (addEdge ((lower l),[((upper l),l)],g)) | |
| 996 | ||
| 997 | val (intern, extern) = sortEdges leqEdges ([], []); | |
| 998 | val subGraph = sccSubGraph intern []; | |
| 999 | ||
| 1000 | in | |
| 15531 | 1001 | case findContr neqEdges of SOME e => handleContr e subGraph | 
| 14445 | 1002 | | _ => ((k, (reOrganizeEdges (extern) [])), subGraph) | 
| 1003 | end; | |
| 1004 | ||
| 1005 | val tmp = map processComponent IndexComp | |
| 1006 | in | |
| 1007 | ( (map fst tmp), (map snd tmp)) | |
| 1008 | end; | |
| 14398 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 1009 | |
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 1010 | (* *********************************************************************** *) | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 1011 | (* *) | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 1012 | (* solvePartialOrder sign (asms,concl) : *) | 
| 19250 | 1013 | (* theory -> less list * Term.term -> proof list *) | 
| 14398 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 1014 | (* *) | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 1015 | (* Find proof if possible for partial orders. *) | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 1016 | (* *) | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 1017 | (* *********************************************************************** *) | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 1018 | |
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 1019 | fun solvePartialOrder sign (asms, concl) = | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 1020 | let | 
| 14445 | 1021 | val (leqG, neqG, neqE) = mkGraphs asms | 
| 1022 | val components = scc_term leqG | |
| 14398 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 1023 | val ntc = indexNodes (indexComps components) | 
| 14445 | 1024 | val (sccGraph, sccSubgraphs) = mk_sccGraphs components leqG neqG ntc | 
| 14398 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 1025 | in | 
| 14445 | 1026 | let | 
| 14398 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 1027 | val (subgoals, prf) = mkconcl_partial sign concl | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 1028 | fun solve facts less = | 
| 15531 | 1029 | (case triv_solv less of NONE => findProof (sccGraph, neqE, ntc, sccSubgraphs ) less | 
| 1030 | | SOME prf => prf ) | |
| 14398 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 1031 | in | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 1032 | map (solve asms) subgoals | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 1033 | end | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 1034 | end; | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 1035 | |
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 1036 | (* *********************************************************************** *) | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 1037 | (* *) | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 1038 | (* solveTotalOrder sign (asms,concl) : *) | 
| 19250 | 1039 | (* theory -> less list * Term.term -> proof list *) | 
| 14398 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 1040 | (* *) | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 1041 | (* Find proof if possible for linear orders. *) | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 1042 | (* *) | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 1043 | (* *********************************************************************** *) | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 1044 | |
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 1045 | fun solveTotalOrder sign (asms, concl) = | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 1046 | let | 
| 14445 | 1047 | val (leqG, neqG, neqE) = mkGraphs asms | 
| 1048 | val components = scc_term leqG | |
| 14398 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 1049 | val ntc = indexNodes (indexComps components) | 
| 14445 | 1050 | val (sccGraph, sccSubgraphs) = mk_sccGraphs components leqG neqG ntc | 
| 14398 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 1051 | in | 
| 14445 | 1052 | let | 
| 14398 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 1053 | val (subgoals, prf) = mkconcl_linear sign concl | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 1054 | fun solve facts less = | 
| 15531 | 1055 | (case triv_solv less of NONE => findProof (sccGraph, neqE, ntc, sccSubgraphs) less | 
| 1056 | | SOME prf => prf ) | |
| 14398 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 1057 | in | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 1058 | map (solve asms) subgoals | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 1059 | end | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 1060 | end; | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 1061 | |
| 14445 | 1062 | (* partial_tac - solves partial orders *) | 
| 14398 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 1063 | val partial_tac = SUBGOAL (fn (A, n, sign) => | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 1064 | let | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 1065 | val rfrees = map Free (rename_wrt_term A (Logic.strip_params A)) | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 1066 | val Hs = map (fn H => subst_bounds (rfrees, H)) (Logic.strip_assums_hyp A) | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 1067 | val C = subst_bounds (rfrees, Logic.strip_assums_concl A) | 
| 15570 | 1068 | val lesss = List.concat (ListPair.map (mkasm_partial sign) (Hs, 0 upto (length Hs - 1))) | 
| 14398 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 1069 | val prfs = solvePartialOrder sign (lesss, C); | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 1070 | val (subgoals, prf) = mkconcl_partial sign C; | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 1071 | in | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 1072 | METAHYPS (fn asms => | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 1073 | let val thms = map (prove asms) prfs | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 1074 | in rtac (prove thms prf) 1 end) n | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 1075 | end | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 1076 | handle Contr p => METAHYPS (fn asms => rtac (prove asms p) 1) n | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 1077 | | Cannot => no_tac | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 1078 | ); | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 1079 | |
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 1080 | (* linear_tac - solves linear/total orders *) | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 1081 | val linear_tac = SUBGOAL (fn (A, n, sign) => | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 1082 | let | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 1083 | val rfrees = map Free (rename_wrt_term A (Logic.strip_params A)) | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 1084 | val Hs = map (fn H => subst_bounds (rfrees, H)) (Logic.strip_assums_hyp A) | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 1085 | val C = subst_bounds (rfrees, Logic.strip_assums_concl A) | 
| 15570 | 1086 | val lesss = List.concat (ListPair.map (mkasm_linear sign) (Hs, 0 upto (length Hs - 1))) | 
| 14398 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 1087 | val prfs = solveTotalOrder sign (lesss, C); | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 1088 | val (subgoals, prf) = mkconcl_linear sign C; | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 1089 | in | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 1090 | METAHYPS (fn asms => | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 1091 | let val thms = map (prove asms) prfs | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 1092 | in rtac (prove thms prf) 1 end) n | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 1093 | end | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 1094 | handle Contr p => METAHYPS (fn asms => rtac (prove asms p) 1) n | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 1095 | | Cannot => no_tac); | 
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 1096 | |
| 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: diff
changeset | 1097 | end; |