author | wenzelm |
Mon, 21 Aug 2023 13:01:45 +0200 | |
changeset 78553 | 66fc98b4557b |
parent 78095 | bc42c074e58f |
permissions | -rw-r--r-- |
73526
a3cc9fa1295d
new automatic order prover: stateless, complete, verified
nipkow
parents:
diff
changeset
|
1 |
signature REIFY_TABLE = |
a3cc9fa1295d
new automatic order prover: stateless, complete, verified
nipkow
parents:
diff
changeset
|
2 |
sig |
a3cc9fa1295d
new automatic order prover: stateless, complete, verified
nipkow
parents:
diff
changeset
|
3 |
type table |
a3cc9fa1295d
new automatic order prover: stateless, complete, verified
nipkow
parents:
diff
changeset
|
4 |
val empty : table |
a3cc9fa1295d
new automatic order prover: stateless, complete, verified
nipkow
parents:
diff
changeset
|
5 |
val get_var : term -> table -> (int * table) |
a3cc9fa1295d
new automatic order prover: stateless, complete, verified
nipkow
parents:
diff
changeset
|
6 |
val get_term : int -> table -> term option |
a3cc9fa1295d
new automatic order prover: stateless, complete, verified
nipkow
parents:
diff
changeset
|
7 |
end |
a3cc9fa1295d
new automatic order prover: stateless, complete, verified
nipkow
parents:
diff
changeset
|
8 |
|
a3cc9fa1295d
new automatic order prover: stateless, complete, verified
nipkow
parents:
diff
changeset
|
9 |
structure Reifytab: REIFY_TABLE = |
a3cc9fa1295d
new automatic order prover: stateless, complete, verified
nipkow
parents:
diff
changeset
|
10 |
struct |
74625
e6f0c9bf966c
order_tac: prevent potential bug, improve perf and tracing
Lukas Stevens <mail@lukas-stevens.de>
parents:
74561
diff
changeset
|
11 |
type table = (int * (term * int) list) |
73526
a3cc9fa1295d
new automatic order prover: stateless, complete, verified
nipkow
parents:
diff
changeset
|
12 |
|
74625
e6f0c9bf966c
order_tac: prevent potential bug, improve perf and tracing
Lukas Stevens <mail@lukas-stevens.de>
parents:
74561
diff
changeset
|
13 |
val empty = (0, []) |
73526
a3cc9fa1295d
new automatic order prover: stateless, complete, verified
nipkow
parents:
diff
changeset
|
14 |
|
74625
e6f0c9bf966c
order_tac: prevent potential bug, improve perf and tracing
Lukas Stevens <mail@lukas-stevens.de>
parents:
74561
diff
changeset
|
15 |
fun get_var t (max_var, tis) = |
e6f0c9bf966c
order_tac: prevent potential bug, improve perf and tracing
Lukas Stevens <mail@lukas-stevens.de>
parents:
74561
diff
changeset
|
16 |
(case AList.lookup Envir.aeconv tis t of |
e6f0c9bf966c
order_tac: prevent potential bug, improve perf and tracing
Lukas Stevens <mail@lukas-stevens.de>
parents:
74561
diff
changeset
|
17 |
SOME v => (v, (max_var, tis)) |
e6f0c9bf966c
order_tac: prevent potential bug, improve perf and tracing
Lukas Stevens <mail@lukas-stevens.de>
parents:
74561
diff
changeset
|
18 |
| NONE => (max_var, (max_var + 1, (t, max_var) :: tis)) |
73526
a3cc9fa1295d
new automatic order prover: stateless, complete, verified
nipkow
parents:
diff
changeset
|
19 |
) |
a3cc9fa1295d
new automatic order prover: stateless, complete, verified
nipkow
parents:
diff
changeset
|
20 |
|
74625
e6f0c9bf966c
order_tac: prevent potential bug, improve perf and tracing
Lukas Stevens <mail@lukas-stevens.de>
parents:
74561
diff
changeset
|
21 |
fun get_term v (_, tis) = Library.find_first (fn (_, v2) => v = v2) tis |
e6f0c9bf966c
order_tac: prevent potential bug, improve perf and tracing
Lukas Stevens <mail@lukas-stevens.de>
parents:
74561
diff
changeset
|
22 |
|> Option.map fst |
73526
a3cc9fa1295d
new automatic order prover: stateless, complete, verified
nipkow
parents:
diff
changeset
|
23 |
end |
a3cc9fa1295d
new automatic order prover: stateless, complete, verified
nipkow
parents:
diff
changeset
|
24 |
|
a3cc9fa1295d
new automatic order prover: stateless, complete, verified
nipkow
parents:
diff
changeset
|
25 |
signature LOGIC_SIGNATURE = |
a3cc9fa1295d
new automatic order prover: stateless, complete, verified
nipkow
parents:
diff
changeset
|
26 |
sig |
a3cc9fa1295d
new automatic order prover: stateless, complete, verified
nipkow
parents:
diff
changeset
|
27 |
val mk_Trueprop : term -> term |
a3cc9fa1295d
new automatic order prover: stateless, complete, verified
nipkow
parents:
diff
changeset
|
28 |
val dest_Trueprop : term -> term |
a3cc9fa1295d
new automatic order prover: stateless, complete, verified
nipkow
parents:
diff
changeset
|
29 |
val Trueprop_conv : conv -> conv |
a3cc9fa1295d
new automatic order prover: stateless, complete, verified
nipkow
parents:
diff
changeset
|
30 |
val Not : term |
a3cc9fa1295d
new automatic order prover: stateless, complete, verified
nipkow
parents:
diff
changeset
|
31 |
val conj : term |
a3cc9fa1295d
new automatic order prover: stateless, complete, verified
nipkow
parents:
diff
changeset
|
32 |
val disj : term |
a3cc9fa1295d
new automatic order prover: stateless, complete, verified
nipkow
parents:
diff
changeset
|
33 |
|
a3cc9fa1295d
new automatic order prover: stateless, complete, verified
nipkow
parents:
diff
changeset
|
34 |
val notI : thm (* (P \<Longrightarrow> False) \<Longrightarrow> \<not> P *) |
a3cc9fa1295d
new automatic order prover: stateless, complete, verified
nipkow
parents:
diff
changeset
|
35 |
val ccontr : thm (* (\<not> P \<Longrightarrow> False) \<Longrightarrow> P *) |
a3cc9fa1295d
new automatic order prover: stateless, complete, verified
nipkow
parents:
diff
changeset
|
36 |
val conjI : thm (* P \<Longrightarrow> Q \<Longrightarrow> P \<and> Q *) |
a3cc9fa1295d
new automatic order prover: stateless, complete, verified
nipkow
parents:
diff
changeset
|
37 |
val conjE : thm (* P \<and> Q \<Longrightarrow> (P \<Longrightarrow> Q \<Longrightarrow> R) \<Longrightarrow> R *) |
a3cc9fa1295d
new automatic order prover: stateless, complete, verified
nipkow
parents:
diff
changeset
|
38 |
val disjE : thm (* P \<or> Q \<Longrightarrow> (P \<Longrightarrow> R) \<Longrightarrow> (Q \<Longrightarrow> R) \<Longrightarrow> R *) |
a3cc9fa1295d
new automatic order prover: stateless, complete, verified
nipkow
parents:
diff
changeset
|
39 |
|
a3cc9fa1295d
new automatic order prover: stateless, complete, verified
nipkow
parents:
diff
changeset
|
40 |
val not_not_conv : conv (* \<not> (\<not> P) \<equiv> P *) |
a3cc9fa1295d
new automatic order prover: stateless, complete, verified
nipkow
parents:
diff
changeset
|
41 |
val de_Morgan_conj_conv : conv (* \<not> (P \<and> Q) \<equiv> \<not> P \<or> \<not> Q *) |
a3cc9fa1295d
new automatic order prover: stateless, complete, verified
nipkow
parents:
diff
changeset
|
42 |
val de_Morgan_disj_conv : conv (* \<not> (P \<or> Q) \<equiv> \<not> P \<and> \<not> Q *) |
a3cc9fa1295d
new automatic order prover: stateless, complete, verified
nipkow
parents:
diff
changeset
|
43 |
val conj_disj_distribL_conv : conv (* P \<and> (Q \<or> R) \<equiv> (P \<and> Q) \<or> (P \<and> R) *) |
a3cc9fa1295d
new automatic order prover: stateless, complete, verified
nipkow
parents:
diff
changeset
|
44 |
val conj_disj_distribR_conv : conv (* (Q \<or> R) \<and> P \<equiv> (Q \<and> P) \<or> (R \<and> P) *) |
a3cc9fa1295d
new automatic order prover: stateless, complete, verified
nipkow
parents:
diff
changeset
|
45 |
end |
a3cc9fa1295d
new automatic order prover: stateless, complete, verified
nipkow
parents:
diff
changeset
|
46 |
|
a3cc9fa1295d
new automatic order prover: stateless, complete, verified
nipkow
parents:
diff
changeset
|
47 |
(* Control tracing output of the solver. *) |
a3cc9fa1295d
new automatic order prover: stateless, complete, verified
nipkow
parents:
diff
changeset
|
48 |
val order_trace_cfg = Attrib.setup_config_bool @{binding "order_trace"} (K false) |
a3cc9fa1295d
new automatic order prover: stateless, complete, verified
nipkow
parents:
diff
changeset
|
49 |
(* In partial orders, literals of the form \<not> x < y will force the order solver to perform case |
a3cc9fa1295d
new automatic order prover: stateless, complete, verified
nipkow
parents:
diff
changeset
|
50 |
distinctions, which leads to an exponential blowup of the runtime. The split limit controls |
a3cc9fa1295d
new automatic order prover: stateless, complete, verified
nipkow
parents:
diff
changeset
|
51 |
the number of literals of this form that are passed to the solver. |
a3cc9fa1295d
new automatic order prover: stateless, complete, verified
nipkow
parents:
diff
changeset
|
52 |
*) |
a3cc9fa1295d
new automatic order prover: stateless, complete, verified
nipkow
parents:
diff
changeset
|
53 |
val order_split_limit_cfg = Attrib.setup_config_int @{binding "order_split_limit"} (K 8) |
a3cc9fa1295d
new automatic order prover: stateless, complete, verified
nipkow
parents:
diff
changeset
|
54 |
|
a3cc9fa1295d
new automatic order prover: stateless, complete, verified
nipkow
parents:
diff
changeset
|
55 |
datatype order_kind = Order | Linorder |
a3cc9fa1295d
new automatic order prover: stateless, complete, verified
nipkow
parents:
diff
changeset
|
56 |
|
74625
e6f0c9bf966c
order_tac: prevent potential bug, improve perf and tracing
Lukas Stevens <mail@lukas-stevens.de>
parents:
74561
diff
changeset
|
57 |
type order_literal = (bool * Order_Procedure.order_atom) |
73526
a3cc9fa1295d
new automatic order prover: stateless, complete, verified
nipkow
parents:
diff
changeset
|
58 |
|
a3cc9fa1295d
new automatic order prover: stateless, complete, verified
nipkow
parents:
diff
changeset
|
59 |
type order_context = { |
a3cc9fa1295d
new automatic order prover: stateless, complete, verified
nipkow
parents:
diff
changeset
|
60 |
kind : order_kind, |
a3cc9fa1295d
new automatic order prover: stateless, complete, verified
nipkow
parents:
diff
changeset
|
61 |
ops : term list, thms : (string * thm) list, conv_thms : (string * thm) list |
a3cc9fa1295d
new automatic order prover: stateless, complete, verified
nipkow
parents:
diff
changeset
|
62 |
} |
a3cc9fa1295d
new automatic order prover: stateless, complete, verified
nipkow
parents:
diff
changeset
|
63 |
|
a3cc9fa1295d
new automatic order prover: stateless, complete, verified
nipkow
parents:
diff
changeset
|
64 |
signature BASE_ORDER_TAC = |
a3cc9fa1295d
new automatic order prover: stateless, complete, verified
nipkow
parents:
diff
changeset
|
65 |
sig |
a3cc9fa1295d
new automatic order prover: stateless, complete, verified
nipkow
parents:
diff
changeset
|
66 |
|
a3cc9fa1295d
new automatic order prover: stateless, complete, verified
nipkow
parents:
diff
changeset
|
67 |
val tac : |
a3cc9fa1295d
new automatic order prover: stateless, complete, verified
nipkow
parents:
diff
changeset
|
68 |
(order_literal Order_Procedure.fm -> Order_Procedure.prf_trm option) |
a3cc9fa1295d
new automatic order prover: stateless, complete, verified
nipkow
parents:
diff
changeset
|
69 |
-> order_context -> thm list |
a3cc9fa1295d
new automatic order prover: stateless, complete, verified
nipkow
parents:
diff
changeset
|
70 |
-> Proof.context -> int -> tactic |
a3cc9fa1295d
new automatic order prover: stateless, complete, verified
nipkow
parents:
diff
changeset
|
71 |
end |
a3cc9fa1295d
new automatic order prover: stateless, complete, verified
nipkow
parents:
diff
changeset
|
72 |
|
a3cc9fa1295d
new automatic order prover: stateless, complete, verified
nipkow
parents:
diff
changeset
|
73 |
functor Base_Order_Tac( |
a3cc9fa1295d
new automatic order prover: stateless, complete, verified
nipkow
parents:
diff
changeset
|
74 |
structure Logic_Sig : LOGIC_SIGNATURE; val excluded_types : typ list) : BASE_ORDER_TAC = |
a3cc9fa1295d
new automatic order prover: stateless, complete, verified
nipkow
parents:
diff
changeset
|
75 |
struct |
a3cc9fa1295d
new automatic order prover: stateless, complete, verified
nipkow
parents:
diff
changeset
|
76 |
open Order_Procedure |
a3cc9fa1295d
new automatic order prover: stateless, complete, verified
nipkow
parents:
diff
changeset
|
77 |
|
a3cc9fa1295d
new automatic order prover: stateless, complete, verified
nipkow
parents:
diff
changeset
|
78 |
fun expect _ (SOME x) = x |
a3cc9fa1295d
new automatic order prover: stateless, complete, verified
nipkow
parents:
diff
changeset
|
79 |
| expect f NONE = f () |
a3cc9fa1295d
new automatic order prover: stateless, complete, verified
nipkow
parents:
diff
changeset
|
80 |
|
a3cc9fa1295d
new automatic order prover: stateless, complete, verified
nipkow
parents:
diff
changeset
|
81 |
fun list_curry0 f = (fn [] => f, 0) |
a3cc9fa1295d
new automatic order prover: stateless, complete, verified
nipkow
parents:
diff
changeset
|
82 |
fun list_curry1 f = (fn [x] => f x, 1) |
a3cc9fa1295d
new automatic order prover: stateless, complete, verified
nipkow
parents:
diff
changeset
|
83 |
fun list_curry2 f = (fn [x, y] => f x y, 2) |
a3cc9fa1295d
new automatic order prover: stateless, complete, verified
nipkow
parents:
diff
changeset
|
84 |
|
a3cc9fa1295d
new automatic order prover: stateless, complete, verified
nipkow
parents:
diff
changeset
|
85 |
fun dereify_term consts reifytab t = |
a3cc9fa1295d
new automatic order prover: stateless, complete, verified
nipkow
parents:
diff
changeset
|
86 |
let |
a3cc9fa1295d
new automatic order prover: stateless, complete, verified
nipkow
parents:
diff
changeset
|
87 |
fun dereify_term' (App (t1, t2)) = (dereify_term' t1) $ (dereify_term' t2) |
a3cc9fa1295d
new automatic order prover: stateless, complete, verified
nipkow
parents:
diff
changeset
|
88 |
| dereify_term' (Const s) = |
a3cc9fa1295d
new automatic order prover: stateless, complete, verified
nipkow
parents:
diff
changeset
|
89 |
AList.lookup (op =) consts s |
a3cc9fa1295d
new automatic order prover: stateless, complete, verified
nipkow
parents:
diff
changeset
|
90 |
|> expect (fn () => raise TERM ("Const " ^ s ^ " not in", map snd consts)) |
a3cc9fa1295d
new automatic order prover: stateless, complete, verified
nipkow
parents:
diff
changeset
|
91 |
| dereify_term' (Var v) = Reifytab.get_term (integer_of_int v) reifytab |> the |
a3cc9fa1295d
new automatic order prover: stateless, complete, verified
nipkow
parents:
diff
changeset
|
92 |
in |
a3cc9fa1295d
new automatic order prover: stateless, complete, verified
nipkow
parents:
diff
changeset
|
93 |
dereify_term' t |
a3cc9fa1295d
new automatic order prover: stateless, complete, verified
nipkow
parents:
diff
changeset
|
94 |
end |
a3cc9fa1295d
new automatic order prover: stateless, complete, verified
nipkow
parents:
diff
changeset
|
95 |
|
a3cc9fa1295d
new automatic order prover: stateless, complete, verified
nipkow
parents:
diff
changeset
|
96 |
fun dereify_order_fm (eq, le, lt) reifytab t = |
a3cc9fa1295d
new automatic order prover: stateless, complete, verified
nipkow
parents:
diff
changeset
|
97 |
let |
a3cc9fa1295d
new automatic order prover: stateless, complete, verified
nipkow
parents:
diff
changeset
|
98 |
val consts = [ |
a3cc9fa1295d
new automatic order prover: stateless, complete, verified
nipkow
parents:
diff
changeset
|
99 |
("eq", eq), ("le", le), ("lt", lt), |
a3cc9fa1295d
new automatic order prover: stateless, complete, verified
nipkow
parents:
diff
changeset
|
100 |
("Not", Logic_Sig.Not), ("disj", Logic_Sig.disj), ("conj", Logic_Sig.conj) |
a3cc9fa1295d
new automatic order prover: stateless, complete, verified
nipkow
parents:
diff
changeset
|
101 |
] |
a3cc9fa1295d
new automatic order prover: stateless, complete, verified
nipkow
parents:
diff
changeset
|
102 |
in |
a3cc9fa1295d
new automatic order prover: stateless, complete, verified
nipkow
parents:
diff
changeset
|
103 |
dereify_term consts reifytab t |
a3cc9fa1295d
new automatic order prover: stateless, complete, verified
nipkow
parents:
diff
changeset
|
104 |
end |
a3cc9fa1295d
new automatic order prover: stateless, complete, verified
nipkow
parents:
diff
changeset
|
105 |
|
a3cc9fa1295d
new automatic order prover: stateless, complete, verified
nipkow
parents:
diff
changeset
|
106 |
fun strip_AppP t = |
a3cc9fa1295d
new automatic order prover: stateless, complete, verified
nipkow
parents:
diff
changeset
|
107 |
let fun strip (AppP (f, s), ss) = strip (f, s::ss) |
a3cc9fa1295d
new automatic order prover: stateless, complete, verified
nipkow
parents:
diff
changeset
|
108 |
| strip x = x |
a3cc9fa1295d
new automatic order prover: stateless, complete, verified
nipkow
parents:
diff
changeset
|
109 |
in strip (t, []) end |
a3cc9fa1295d
new automatic order prover: stateless, complete, verified
nipkow
parents:
diff
changeset
|
110 |
|
a3cc9fa1295d
new automatic order prover: stateless, complete, verified
nipkow
parents:
diff
changeset
|
111 |
fun replay_conv convs cvp = |
a3cc9fa1295d
new automatic order prover: stateless, complete, verified
nipkow
parents:
diff
changeset
|
112 |
let |
a3cc9fa1295d
new automatic order prover: stateless, complete, verified
nipkow
parents:
diff
changeset
|
113 |
val convs = convs @ |
a3cc9fa1295d
new automatic order prover: stateless, complete, verified
nipkow
parents:
diff
changeset
|
114 |
[("all_conv", list_curry0 Conv.all_conv)] @ |
a3cc9fa1295d
new automatic order prover: stateless, complete, verified
nipkow
parents:
diff
changeset
|
115 |
map (apsnd list_curry1) [ |
a3cc9fa1295d
new automatic order prover: stateless, complete, verified
nipkow
parents:
diff
changeset
|
116 |
("atom_conv", I), |
a3cc9fa1295d
new automatic order prover: stateless, complete, verified
nipkow
parents:
diff
changeset
|
117 |
("neg_atom_conv", I), |
a3cc9fa1295d
new automatic order prover: stateless, complete, verified
nipkow
parents:
diff
changeset
|
118 |
("arg_conv", Conv.arg_conv)] @ |
a3cc9fa1295d
new automatic order prover: stateless, complete, verified
nipkow
parents:
diff
changeset
|
119 |
map (apsnd list_curry2) [ |
a3cc9fa1295d
new automatic order prover: stateless, complete, verified
nipkow
parents:
diff
changeset
|
120 |
("combination_conv", Conv.combination_conv), |
a3cc9fa1295d
new automatic order prover: stateless, complete, verified
nipkow
parents:
diff
changeset
|
121 |
("then_conv", curry (op then_conv))] |
a3cc9fa1295d
new automatic order prover: stateless, complete, verified
nipkow
parents:
diff
changeset
|
122 |
|
a3cc9fa1295d
new automatic order prover: stateless, complete, verified
nipkow
parents:
diff
changeset
|
123 |
fun lookup_conv convs c = AList.lookup (op =) convs c |
a3cc9fa1295d
new automatic order prover: stateless, complete, verified
nipkow
parents:
diff
changeset
|
124 |
|> expect (fn () => error ("Can't replay conversion: " ^ c)) |
a3cc9fa1295d
new automatic order prover: stateless, complete, verified
nipkow
parents:
diff
changeset
|
125 |
|
a3cc9fa1295d
new automatic order prover: stateless, complete, verified
nipkow
parents:
diff
changeset
|
126 |
fun rp_conv t = |
a3cc9fa1295d
new automatic order prover: stateless, complete, verified
nipkow
parents:
diff
changeset
|
127 |
(case strip_AppP t ||> map rp_conv of |
a3cc9fa1295d
new automatic order prover: stateless, complete, verified
nipkow
parents:
diff
changeset
|
128 |
(PThm c, cvs) => |
a3cc9fa1295d
new automatic order prover: stateless, complete, verified
nipkow
parents:
diff
changeset
|
129 |
let val (conv, arity) = lookup_conv convs c |
a3cc9fa1295d
new automatic order prover: stateless, complete, verified
nipkow
parents:
diff
changeset
|
130 |
in if arity = length cvs |
a3cc9fa1295d
new automatic order prover: stateless, complete, verified
nipkow
parents:
diff
changeset
|
131 |
then conv cvs |
a3cc9fa1295d
new automatic order prover: stateless, complete, verified
nipkow
parents:
diff
changeset
|
132 |
else error ("Expected " ^ Int.toString arity ^ " arguments for conversion " ^ |
a3cc9fa1295d
new automatic order prover: stateless, complete, verified
nipkow
parents:
diff
changeset
|
133 |
c ^ " but got " ^ (length cvs |> Int.toString) ^ " arguments") |
a3cc9fa1295d
new automatic order prover: stateless, complete, verified
nipkow
parents:
diff
changeset
|
134 |
end |
a3cc9fa1295d
new automatic order prover: stateless, complete, verified
nipkow
parents:
diff
changeset
|
135 |
| _ => error "Unexpected constructor in conversion proof") |
a3cc9fa1295d
new automatic order prover: stateless, complete, verified
nipkow
parents:
diff
changeset
|
136 |
in |
a3cc9fa1295d
new automatic order prover: stateless, complete, verified
nipkow
parents:
diff
changeset
|
137 |
rp_conv cvp |
a3cc9fa1295d
new automatic order prover: stateless, complete, verified
nipkow
parents:
diff
changeset
|
138 |
end |
a3cc9fa1295d
new automatic order prover: stateless, complete, verified
nipkow
parents:
diff
changeset
|
139 |
|
a3cc9fa1295d
new automatic order prover: stateless, complete, verified
nipkow
parents:
diff
changeset
|
140 |
fun replay_prf_trm replay_conv dereify ctxt thmtab assmtab p = |
a3cc9fa1295d
new automatic order prover: stateless, complete, verified
nipkow
parents:
diff
changeset
|
141 |
let |
a3cc9fa1295d
new automatic order prover: stateless, complete, verified
nipkow
parents:
diff
changeset
|
142 |
fun replay_prf_trm' _ (PThm s) = |
a3cc9fa1295d
new automatic order prover: stateless, complete, verified
nipkow
parents:
diff
changeset
|
143 |
AList.lookup (op =) thmtab s |
a3cc9fa1295d
new automatic order prover: stateless, complete, verified
nipkow
parents:
diff
changeset
|
144 |
|> expect (fn () => error ("Cannot replay theorem: " ^ s)) |
a3cc9fa1295d
new automatic order prover: stateless, complete, verified
nipkow
parents:
diff
changeset
|
145 |
| replay_prf_trm' assmtab (Appt (p, t)) = |
a3cc9fa1295d
new automatic order prover: stateless, complete, verified
nipkow
parents:
diff
changeset
|
146 |
replay_prf_trm' assmtab p |
a3cc9fa1295d
new automatic order prover: stateless, complete, verified
nipkow
parents:
diff
changeset
|
147 |
|> Drule.infer_instantiate' ctxt [SOME (Thm.cterm_of ctxt (dereify t))] |
a3cc9fa1295d
new automatic order prover: stateless, complete, verified
nipkow
parents:
diff
changeset
|
148 |
| replay_prf_trm' assmtab (AppP (p1, p2)) = |
74625
e6f0c9bf966c
order_tac: prevent potential bug, improve perf and tracing
Lukas Stevens <mail@lukas-stevens.de>
parents:
74561
diff
changeset
|
149 |
apply2 (replay_prf_trm' assmtab) (p2, p1) |> op COMP |
73526
a3cc9fa1295d
new automatic order prover: stateless, complete, verified
nipkow
parents:
diff
changeset
|
150 |
| replay_prf_trm' assmtab (AbsP (reified_t, p)) = |
a3cc9fa1295d
new automatic order prover: stateless, complete, verified
nipkow
parents:
diff
changeset
|
151 |
let |
a3cc9fa1295d
new automatic order prover: stateless, complete, verified
nipkow
parents:
diff
changeset
|
152 |
val t = dereify reified_t |
a3cc9fa1295d
new automatic order prover: stateless, complete, verified
nipkow
parents:
diff
changeset
|
153 |
val t_thm = Logic_Sig.mk_Trueprop t |> Thm.cterm_of ctxt |> Assumption.assume ctxt |
a3cc9fa1295d
new automatic order prover: stateless, complete, verified
nipkow
parents:
diff
changeset
|
154 |
val rp = replay_prf_trm' (Termtab.update (Thm.prop_of t_thm, t_thm) assmtab) p |
a3cc9fa1295d
new automatic order prover: stateless, complete, verified
nipkow
parents:
diff
changeset
|
155 |
in |
a3cc9fa1295d
new automatic order prover: stateless, complete, verified
nipkow
parents:
diff
changeset
|
156 |
Thm.implies_intr (Thm.cprop_of t_thm) rp |
a3cc9fa1295d
new automatic order prover: stateless, complete, verified
nipkow
parents:
diff
changeset
|
157 |
end |
a3cc9fa1295d
new automatic order prover: stateless, complete, verified
nipkow
parents:
diff
changeset
|
158 |
| replay_prf_trm' assmtab (Bound reified_t) = |
a3cc9fa1295d
new automatic order prover: stateless, complete, verified
nipkow
parents:
diff
changeset
|
159 |
let |
a3cc9fa1295d
new automatic order prover: stateless, complete, verified
nipkow
parents:
diff
changeset
|
160 |
val t = dereify reified_t |> Logic_Sig.mk_Trueprop |
a3cc9fa1295d
new automatic order prover: stateless, complete, verified
nipkow
parents:
diff
changeset
|
161 |
in |
a3cc9fa1295d
new automatic order prover: stateless, complete, verified
nipkow
parents:
diff
changeset
|
162 |
Termtab.lookup assmtab t |
a3cc9fa1295d
new automatic order prover: stateless, complete, verified
nipkow
parents:
diff
changeset
|
163 |
|> expect (fn () => raise TERM ("Assumption not found:", t::Termtab.keys assmtab)) |
a3cc9fa1295d
new automatic order prover: stateless, complete, verified
nipkow
parents:
diff
changeset
|
164 |
end |
a3cc9fa1295d
new automatic order prover: stateless, complete, verified
nipkow
parents:
diff
changeset
|
165 |
| replay_prf_trm' assmtab (Conv (t, cp, p)) = |
a3cc9fa1295d
new automatic order prover: stateless, complete, verified
nipkow
parents:
diff
changeset
|
166 |
let |
a3cc9fa1295d
new automatic order prover: stateless, complete, verified
nipkow
parents:
diff
changeset
|
167 |
val thm = replay_prf_trm' assmtab (Bound t) |
a3cc9fa1295d
new automatic order prover: stateless, complete, verified
nipkow
parents:
diff
changeset
|
168 |
val conv = Logic_Sig.Trueprop_conv (replay_conv cp) |
a3cc9fa1295d
new automatic order prover: stateless, complete, verified
nipkow
parents:
diff
changeset
|
169 |
val conv_thm = Conv.fconv_rule conv thm |
a3cc9fa1295d
new automatic order prover: stateless, complete, verified
nipkow
parents:
diff
changeset
|
170 |
val conv_term = Thm.prop_of conv_thm |
a3cc9fa1295d
new automatic order prover: stateless, complete, verified
nipkow
parents:
diff
changeset
|
171 |
in |
a3cc9fa1295d
new automatic order prover: stateless, complete, verified
nipkow
parents:
diff
changeset
|
172 |
replay_prf_trm' (Termtab.update (conv_term, conv_thm) assmtab) p |
a3cc9fa1295d
new automatic order prover: stateless, complete, verified
nipkow
parents:
diff
changeset
|
173 |
end |
a3cc9fa1295d
new automatic order prover: stateless, complete, verified
nipkow
parents:
diff
changeset
|
174 |
in |
a3cc9fa1295d
new automatic order prover: stateless, complete, verified
nipkow
parents:
diff
changeset
|
175 |
replay_prf_trm' assmtab p |
a3cc9fa1295d
new automatic order prover: stateless, complete, verified
nipkow
parents:
diff
changeset
|
176 |
end |
a3cc9fa1295d
new automatic order prover: stateless, complete, verified
nipkow
parents:
diff
changeset
|
177 |
|
a3cc9fa1295d
new automatic order prover: stateless, complete, verified
nipkow
parents:
diff
changeset
|
178 |
fun replay_order_prf_trm ord_ops {thms = thms, conv_thms = conv_thms, ...} ctxt reifytab assmtab = |
a3cc9fa1295d
new automatic order prover: stateless, complete, verified
nipkow
parents:
diff
changeset
|
179 |
let |
a3cc9fa1295d
new automatic order prover: stateless, complete, verified
nipkow
parents:
diff
changeset
|
180 |
val thmtab = thms @ [ |
a3cc9fa1295d
new automatic order prover: stateless, complete, verified
nipkow
parents:
diff
changeset
|
181 |
("conjE", Logic_Sig.conjE), ("conjI", Logic_Sig.conjI), ("disjE", Logic_Sig.disjE) |
a3cc9fa1295d
new automatic order prover: stateless, complete, verified
nipkow
parents:
diff
changeset
|
182 |
] |
a3cc9fa1295d
new automatic order prover: stateless, complete, verified
nipkow
parents:
diff
changeset
|
183 |
val convs = map (apsnd list_curry0) ( |
a3cc9fa1295d
new automatic order prover: stateless, complete, verified
nipkow
parents:
diff
changeset
|
184 |
map (apsnd Conv.rewr_conv) conv_thms @ |
a3cc9fa1295d
new automatic order prover: stateless, complete, verified
nipkow
parents:
diff
changeset
|
185 |
[ |
a3cc9fa1295d
new automatic order prover: stateless, complete, verified
nipkow
parents:
diff
changeset
|
186 |
("not_not_conv", Logic_Sig.not_not_conv), |
a3cc9fa1295d
new automatic order prover: stateless, complete, verified
nipkow
parents:
diff
changeset
|
187 |
("de_Morgan_conj_conv", Logic_Sig.de_Morgan_conj_conv), |
a3cc9fa1295d
new automatic order prover: stateless, complete, verified
nipkow
parents:
diff
changeset
|
188 |
("de_Morgan_disj_conv", Logic_Sig.de_Morgan_disj_conv), |
a3cc9fa1295d
new automatic order prover: stateless, complete, verified
nipkow
parents:
diff
changeset
|
189 |
("conj_disj_distribR_conv", Logic_Sig.conj_disj_distribR_conv), |
a3cc9fa1295d
new automatic order prover: stateless, complete, verified
nipkow
parents:
diff
changeset
|
190 |
("conj_disj_distribL_conv", Logic_Sig.conj_disj_distribL_conv) |
a3cc9fa1295d
new automatic order prover: stateless, complete, verified
nipkow
parents:
diff
changeset
|
191 |
]) |
a3cc9fa1295d
new automatic order prover: stateless, complete, verified
nipkow
parents:
diff
changeset
|
192 |
|
a3cc9fa1295d
new automatic order prover: stateless, complete, verified
nipkow
parents:
diff
changeset
|
193 |
val dereify = dereify_order_fm ord_ops reifytab |
a3cc9fa1295d
new automatic order prover: stateless, complete, verified
nipkow
parents:
diff
changeset
|
194 |
in |
a3cc9fa1295d
new automatic order prover: stateless, complete, verified
nipkow
parents:
diff
changeset
|
195 |
replay_prf_trm (replay_conv convs) dereify ctxt thmtab assmtab |
a3cc9fa1295d
new automatic order prover: stateless, complete, verified
nipkow
parents:
diff
changeset
|
196 |
end |
a3cc9fa1295d
new automatic order prover: stateless, complete, verified
nipkow
parents:
diff
changeset
|
197 |
|
74625
e6f0c9bf966c
order_tac: prevent potential bug, improve perf and tracing
Lukas Stevens <mail@lukas-stevens.de>
parents:
74561
diff
changeset
|
198 |
fun strip_Not (nt $ t) = if nt = Logic_Sig.Not then t else nt $ t |
e6f0c9bf966c
order_tac: prevent potential bug, improve perf and tracing
Lukas Stevens <mail@lukas-stevens.de>
parents:
74561
diff
changeset
|
199 |
| strip_Not t = t |
73526
a3cc9fa1295d
new automatic order prover: stateless, complete, verified
nipkow
parents:
diff
changeset
|
200 |
|
74625
e6f0c9bf966c
order_tac: prevent potential bug, improve perf and tracing
Lukas Stevens <mail@lukas-stevens.de>
parents:
74561
diff
changeset
|
201 |
fun limit_not_less [_, _, lt] ctxt decomp_prems = |
73526
a3cc9fa1295d
new automatic order prover: stateless, complete, verified
nipkow
parents:
diff
changeset
|
202 |
let |
a3cc9fa1295d
new automatic order prover: stateless, complete, verified
nipkow
parents:
diff
changeset
|
203 |
val thy = Proof_Context.theory_of ctxt |
a3cc9fa1295d
new automatic order prover: stateless, complete, verified
nipkow
parents:
diff
changeset
|
204 |
val trace = Config.get ctxt order_trace_cfg |
a3cc9fa1295d
new automatic order prover: stateless, complete, verified
nipkow
parents:
diff
changeset
|
205 |
val limit = Config.get ctxt order_split_limit_cfg |
a3cc9fa1295d
new automatic order prover: stateless, complete, verified
nipkow
parents:
diff
changeset
|
206 |
|
a3cc9fa1295d
new automatic order prover: stateless, complete, verified
nipkow
parents:
diff
changeset
|
207 |
fun is_not_less_term t = |
74625
e6f0c9bf966c
order_tac: prevent potential bug, improve perf and tracing
Lukas Stevens <mail@lukas-stevens.de>
parents:
74561
diff
changeset
|
208 |
case try (strip_Not o Logic_Sig.dest_Trueprop) t of |
e6f0c9bf966c
order_tac: prevent potential bug, improve perf and tracing
Lukas Stevens <mail@lukas-stevens.de>
parents:
74561
diff
changeset
|
209 |
SOME (binop $ _ $ _) => Pattern.matches thy (lt, binop) |
e6f0c9bf966c
order_tac: prevent potential bug, improve perf and tracing
Lukas Stevens <mail@lukas-stevens.de>
parents:
74561
diff
changeset
|
210 |
| NONE => false |
73526
a3cc9fa1295d
new automatic order prover: stateless, complete, verified
nipkow
parents:
diff
changeset
|
211 |
|
74625
e6f0c9bf966c
order_tac: prevent potential bug, improve perf and tracing
Lukas Stevens <mail@lukas-stevens.de>
parents:
74561
diff
changeset
|
212 |
val not_less_prems = filter (is_not_less_term o Thm.prop_of o fst) decomp_prems |
73526
a3cc9fa1295d
new automatic order prover: stateless, complete, verified
nipkow
parents:
diff
changeset
|
213 |
val _ = if trace andalso length not_less_prems > limit |
a3cc9fa1295d
new automatic order prover: stateless, complete, verified
nipkow
parents:
diff
changeset
|
214 |
then tracing "order split limit exceeded" |
a3cc9fa1295d
new automatic order prover: stateless, complete, verified
nipkow
parents:
diff
changeset
|
215 |
else () |
a3cc9fa1295d
new automatic order prover: stateless, complete, verified
nipkow
parents:
diff
changeset
|
216 |
in |
74625
e6f0c9bf966c
order_tac: prevent potential bug, improve perf and tracing
Lukas Stevens <mail@lukas-stevens.de>
parents:
74561
diff
changeset
|
217 |
filter_out (is_not_less_term o Thm.prop_of o fst) decomp_prems @ |
73526
a3cc9fa1295d
new automatic order prover: stateless, complete, verified
nipkow
parents:
diff
changeset
|
218 |
take limit not_less_prems |
a3cc9fa1295d
new automatic order prover: stateless, complete, verified
nipkow
parents:
diff
changeset
|
219 |
end |
74625
e6f0c9bf966c
order_tac: prevent potential bug, improve perf and tracing
Lukas Stevens <mail@lukas-stevens.de>
parents:
74561
diff
changeset
|
220 |
|
e6f0c9bf966c
order_tac: prevent potential bug, improve perf and tracing
Lukas Stevens <mail@lukas-stevens.de>
parents:
74561
diff
changeset
|
221 |
fun decomp [eq, le, lt] ctxt t = |
e6f0c9bf966c
order_tac: prevent potential bug, improve perf and tracing
Lukas Stevens <mail@lukas-stevens.de>
parents:
74561
diff
changeset
|
222 |
let |
e6f0c9bf966c
order_tac: prevent potential bug, improve perf and tracing
Lukas Stevens <mail@lukas-stevens.de>
parents:
74561
diff
changeset
|
223 |
fun is_excluded t = exists (fn ty => ty = fastype_of t) excluded_types |
e6f0c9bf966c
order_tac: prevent potential bug, improve perf and tracing
Lukas Stevens <mail@lukas-stevens.de>
parents:
74561
diff
changeset
|
224 |
|
e6f0c9bf966c
order_tac: prevent potential bug, improve perf and tracing
Lukas Stevens <mail@lukas-stevens.de>
parents:
74561
diff
changeset
|
225 |
fun decomp'' (binop $ t1 $ t2) = |
e6f0c9bf966c
order_tac: prevent potential bug, improve perf and tracing
Lukas Stevens <mail@lukas-stevens.de>
parents:
74561
diff
changeset
|
226 |
let |
e6f0c9bf966c
order_tac: prevent potential bug, improve perf and tracing
Lukas Stevens <mail@lukas-stevens.de>
parents:
74561
diff
changeset
|
227 |
open Order_Procedure |
e6f0c9bf966c
order_tac: prevent potential bug, improve perf and tracing
Lukas Stevens <mail@lukas-stevens.de>
parents:
74561
diff
changeset
|
228 |
val thy = Proof_Context.theory_of ctxt |
e6f0c9bf966c
order_tac: prevent potential bug, improve perf and tracing
Lukas Stevens <mail@lukas-stevens.de>
parents:
74561
diff
changeset
|
229 |
fun try_match pat = try (Pattern.match thy (pat, binop)) (Vartab.empty, Vartab.empty) |
e6f0c9bf966c
order_tac: prevent potential bug, improve perf and tracing
Lukas Stevens <mail@lukas-stevens.de>
parents:
74561
diff
changeset
|
230 |
in if is_excluded t1 then NONE |
e6f0c9bf966c
order_tac: prevent potential bug, improve perf and tracing
Lukas Stevens <mail@lukas-stevens.de>
parents:
74561
diff
changeset
|
231 |
else case (try_match eq, try_match le, try_match lt) of |
e6f0c9bf966c
order_tac: prevent potential bug, improve perf and tracing
Lukas Stevens <mail@lukas-stevens.de>
parents:
74561
diff
changeset
|
232 |
(SOME env, _, _) => SOME (true, EQ, (t1, t2), env) |
e6f0c9bf966c
order_tac: prevent potential bug, improve perf and tracing
Lukas Stevens <mail@lukas-stevens.de>
parents:
74561
diff
changeset
|
233 |
| (_, SOME env, _) => SOME (true, LEQ, (t1, t2), env) |
e6f0c9bf966c
order_tac: prevent potential bug, improve perf and tracing
Lukas Stevens <mail@lukas-stevens.de>
parents:
74561
diff
changeset
|
234 |
| (_, _, SOME env) => SOME (true, LESS, (t1, t2), env) |
e6f0c9bf966c
order_tac: prevent potential bug, improve perf and tracing
Lukas Stevens <mail@lukas-stevens.de>
parents:
74561
diff
changeset
|
235 |
| _ => NONE |
e6f0c9bf966c
order_tac: prevent potential bug, improve perf and tracing
Lukas Stevens <mail@lukas-stevens.de>
parents:
74561
diff
changeset
|
236 |
end |
e6f0c9bf966c
order_tac: prevent potential bug, improve perf and tracing
Lukas Stevens <mail@lukas-stevens.de>
parents:
74561
diff
changeset
|
237 |
| decomp'' _ = NONE |
e6f0c9bf966c
order_tac: prevent potential bug, improve perf and tracing
Lukas Stevens <mail@lukas-stevens.de>
parents:
74561
diff
changeset
|
238 |
|
e6f0c9bf966c
order_tac: prevent potential bug, improve perf and tracing
Lukas Stevens <mail@lukas-stevens.de>
parents:
74561
diff
changeset
|
239 |
fun decomp' (nt $ t) = |
e6f0c9bf966c
order_tac: prevent potential bug, improve perf and tracing
Lukas Stevens <mail@lukas-stevens.de>
parents:
74561
diff
changeset
|
240 |
if nt = Logic_Sig.Not |
e6f0c9bf966c
order_tac: prevent potential bug, improve perf and tracing
Lukas Stevens <mail@lukas-stevens.de>
parents:
74561
diff
changeset
|
241 |
then decomp'' t |> Option.map (fn (b, c, p, e) => (not b, c, p, e)) |
e6f0c9bf966c
order_tac: prevent potential bug, improve perf and tracing
Lukas Stevens <mail@lukas-stevens.de>
parents:
74561
diff
changeset
|
242 |
else decomp'' (nt $ t) |
e6f0c9bf966c
order_tac: prevent potential bug, improve perf and tracing
Lukas Stevens <mail@lukas-stevens.de>
parents:
74561
diff
changeset
|
243 |
| decomp' t = decomp'' t |
e6f0c9bf966c
order_tac: prevent potential bug, improve perf and tracing
Lukas Stevens <mail@lukas-stevens.de>
parents:
74561
diff
changeset
|
244 |
|
e6f0c9bf966c
order_tac: prevent potential bug, improve perf and tracing
Lukas Stevens <mail@lukas-stevens.de>
parents:
74561
diff
changeset
|
245 |
in |
e6f0c9bf966c
order_tac: prevent potential bug, improve perf and tracing
Lukas Stevens <mail@lukas-stevens.de>
parents:
74561
diff
changeset
|
246 |
try Logic_Sig.dest_Trueprop t |> Option.mapPartial decomp' |
e6f0c9bf966c
order_tac: prevent potential bug, improve perf and tracing
Lukas Stevens <mail@lukas-stevens.de>
parents:
74561
diff
changeset
|
247 |
end |
e6f0c9bf966c
order_tac: prevent potential bug, improve perf and tracing
Lukas Stevens <mail@lukas-stevens.de>
parents:
74561
diff
changeset
|
248 |
|
e6f0c9bf966c
order_tac: prevent potential bug, improve perf and tracing
Lukas Stevens <mail@lukas-stevens.de>
parents:
74561
diff
changeset
|
249 |
fun maximal_envs envs = |
e6f0c9bf966c
order_tac: prevent potential bug, improve perf and tracing
Lukas Stevens <mail@lukas-stevens.de>
parents:
74561
diff
changeset
|
250 |
let |
e6f0c9bf966c
order_tac: prevent potential bug, improve perf and tracing
Lukas Stevens <mail@lukas-stevens.de>
parents:
74561
diff
changeset
|
251 |
fun test_opt p (SOME x) = p x |
e6f0c9bf966c
order_tac: prevent potential bug, improve perf and tracing
Lukas Stevens <mail@lukas-stevens.de>
parents:
74561
diff
changeset
|
252 |
| test_opt _ NONE = false |
e6f0c9bf966c
order_tac: prevent potential bug, improve perf and tracing
Lukas Stevens <mail@lukas-stevens.de>
parents:
74561
diff
changeset
|
253 |
|
e6f0c9bf966c
order_tac: prevent potential bug, improve perf and tracing
Lukas Stevens <mail@lukas-stevens.de>
parents:
74561
diff
changeset
|
254 |
fun leq_env (tyenv1, tenv1) (tyenv2, tenv2) = |
e6f0c9bf966c
order_tac: prevent potential bug, improve perf and tracing
Lukas Stevens <mail@lukas-stevens.de>
parents:
74561
diff
changeset
|
255 |
Vartab.forall (fn (v, ty) => |
e6f0c9bf966c
order_tac: prevent potential bug, improve perf and tracing
Lukas Stevens <mail@lukas-stevens.de>
parents:
74561
diff
changeset
|
256 |
Vartab.lookup tyenv2 v |> test_opt (fn ty2 => ty2 = ty)) tyenv1 |
e6f0c9bf966c
order_tac: prevent potential bug, improve perf and tracing
Lukas Stevens <mail@lukas-stevens.de>
parents:
74561
diff
changeset
|
257 |
andalso |
e6f0c9bf966c
order_tac: prevent potential bug, improve perf and tracing
Lukas Stevens <mail@lukas-stevens.de>
parents:
74561
diff
changeset
|
258 |
Vartab.forall (fn (v, (ty, t)) => |
e6f0c9bf966c
order_tac: prevent potential bug, improve perf and tracing
Lukas Stevens <mail@lukas-stevens.de>
parents:
74561
diff
changeset
|
259 |
Vartab.lookup tenv2 v |> test_opt (fn (ty2, t2) => ty2 = ty andalso t2 aconv t)) tenv1 |
e6f0c9bf966c
order_tac: prevent potential bug, improve perf and tracing
Lukas Stevens <mail@lukas-stevens.de>
parents:
74561
diff
changeset
|
260 |
|
e6f0c9bf966c
order_tac: prevent potential bug, improve perf and tracing
Lukas Stevens <mail@lukas-stevens.de>
parents:
74561
diff
changeset
|
261 |
fun fold_env (i, env) es = fold_index (fn (i2, env2) => fn es => |
e6f0c9bf966c
order_tac: prevent potential bug, improve perf and tracing
Lukas Stevens <mail@lukas-stevens.de>
parents:
74561
diff
changeset
|
262 |
if i = i2 then es else if leq_env env env2 then (i, i2) :: es else es) envs es |
e6f0c9bf966c
order_tac: prevent potential bug, improve perf and tracing
Lukas Stevens <mail@lukas-stevens.de>
parents:
74561
diff
changeset
|
263 |
|
e6f0c9bf966c
order_tac: prevent potential bug, improve perf and tracing
Lukas Stevens <mail@lukas-stevens.de>
parents:
74561
diff
changeset
|
264 |
val env_order = fold_index fold_env envs [] |
e6f0c9bf966c
order_tac: prevent potential bug, improve perf and tracing
Lukas Stevens <mail@lukas-stevens.de>
parents:
74561
diff
changeset
|
265 |
|
e6f0c9bf966c
order_tac: prevent potential bug, improve perf and tracing
Lukas Stevens <mail@lukas-stevens.de>
parents:
74561
diff
changeset
|
266 |
val graph = fold_index (fn (i, env) => fn g => Int_Graph.new_node (i, env) g) |
e6f0c9bf966c
order_tac: prevent potential bug, improve perf and tracing
Lukas Stevens <mail@lukas-stevens.de>
parents:
74561
diff
changeset
|
267 |
envs Int_Graph.empty |
e6f0c9bf966c
order_tac: prevent potential bug, improve perf and tracing
Lukas Stevens <mail@lukas-stevens.de>
parents:
74561
diff
changeset
|
268 |
val graph = fold Int_Graph.add_edge env_order graph |
e6f0c9bf966c
order_tac: prevent potential bug, improve perf and tracing
Lukas Stevens <mail@lukas-stevens.de>
parents:
74561
diff
changeset
|
269 |
|
e6f0c9bf966c
order_tac: prevent potential bug, improve perf and tracing
Lukas Stevens <mail@lukas-stevens.de>
parents:
74561
diff
changeset
|
270 |
val strong_conns = Int_Graph.strong_conn graph |
e6f0c9bf966c
order_tac: prevent potential bug, improve perf and tracing
Lukas Stevens <mail@lukas-stevens.de>
parents:
74561
diff
changeset
|
271 |
val maximals = |
e6f0c9bf966c
order_tac: prevent potential bug, improve perf and tracing
Lukas Stevens <mail@lukas-stevens.de>
parents:
74561
diff
changeset
|
272 |
filter (fn comp => length comp = length (Int_Graph.all_succs graph comp)) strong_conns |
e6f0c9bf966c
order_tac: prevent potential bug, improve perf and tracing
Lukas Stevens <mail@lukas-stevens.de>
parents:
74561
diff
changeset
|
273 |
in |
e6f0c9bf966c
order_tac: prevent potential bug, improve perf and tracing
Lukas Stevens <mail@lukas-stevens.de>
parents:
74561
diff
changeset
|
274 |
map (Int_Graph.all_preds graph) maximals |
e6f0c9bf966c
order_tac: prevent potential bug, improve perf and tracing
Lukas Stevens <mail@lukas-stevens.de>
parents:
74561
diff
changeset
|
275 |
end |
73526
a3cc9fa1295d
new automatic order prover: stateless, complete, verified
nipkow
parents:
diff
changeset
|
276 |
|
a3cc9fa1295d
new automatic order prover: stateless, complete, verified
nipkow
parents:
diff
changeset
|
277 |
fun order_tac raw_order_proc octxt simp_prems = |
a3cc9fa1295d
new automatic order prover: stateless, complete, verified
nipkow
parents:
diff
changeset
|
278 |
Subgoal.FOCUS (fn {prems=prems, context=ctxt, ...} => |
a3cc9fa1295d
new automatic order prover: stateless, complete, verified
nipkow
parents:
diff
changeset
|
279 |
let |
a3cc9fa1295d
new automatic order prover: stateless, complete, verified
nipkow
parents:
diff
changeset
|
280 |
val trace = Config.get ctxt order_trace_cfg |
a3cc9fa1295d
new automatic order prover: stateless, complete, verified
nipkow
parents:
diff
changeset
|
281 |
|
74625
e6f0c9bf966c
order_tac: prevent potential bug, improve perf and tracing
Lukas Stevens <mail@lukas-stevens.de>
parents:
74561
diff
changeset
|
282 |
fun these' _ [] = [] |
e6f0c9bf966c
order_tac: prevent potential bug, improve perf and tracing
Lukas Stevens <mail@lukas-stevens.de>
parents:
74561
diff
changeset
|
283 |
| these' f (x :: xs) = case f x of NONE => these' f xs | SOME y => (x, y) :: these' f xs |
73526
a3cc9fa1295d
new automatic order prover: stateless, complete, verified
nipkow
parents:
diff
changeset
|
284 |
|
74625
e6f0c9bf966c
order_tac: prevent potential bug, improve perf and tracing
Lukas Stevens <mail@lukas-stevens.de>
parents:
74561
diff
changeset
|
285 |
val prems = simp_prems @ prems |
e6f0c9bf966c
order_tac: prevent potential bug, improve perf and tracing
Lukas Stevens <mail@lukas-stevens.de>
parents:
74561
diff
changeset
|
286 |
|> filter (fn p => null (Term.add_vars (Thm.prop_of p) [])) |
e6f0c9bf966c
order_tac: prevent potential bug, improve perf and tracing
Lukas Stevens <mail@lukas-stevens.de>
parents:
74561
diff
changeset
|
287 |
|> map (Conv.fconv_rule Thm.eta_conversion) |
e6f0c9bf966c
order_tac: prevent potential bug, improve perf and tracing
Lukas Stevens <mail@lukas-stevens.de>
parents:
74561
diff
changeset
|
288 |
val decomp_prems = these' (decomp (#ops octxt) ctxt o Thm.prop_of) prems |
e6f0c9bf966c
order_tac: prevent potential bug, improve perf and tracing
Lukas Stevens <mail@lukas-stevens.de>
parents:
74561
diff
changeset
|
289 |
|
e6f0c9bf966c
order_tac: prevent potential bug, improve perf and tracing
Lukas Stevens <mail@lukas-stevens.de>
parents:
74561
diff
changeset
|
290 |
fun env_of (_, (_, _, _, env)) = env |
e6f0c9bf966c
order_tac: prevent potential bug, improve perf and tracing
Lukas Stevens <mail@lukas-stevens.de>
parents:
74561
diff
changeset
|
291 |
val env_groups = maximal_envs (map env_of decomp_prems) |
e6f0c9bf966c
order_tac: prevent potential bug, improve perf and tracing
Lukas Stevens <mail@lukas-stevens.de>
parents:
74561
diff
changeset
|
292 |
|
73526
a3cc9fa1295d
new automatic order prover: stateless, complete, verified
nipkow
parents:
diff
changeset
|
293 |
fun order_tac' (_, []) = no_tac |
74625
e6f0c9bf966c
order_tac: prevent potential bug, improve perf and tracing
Lukas Stevens <mail@lukas-stevens.de>
parents:
74561
diff
changeset
|
294 |
| order_tac' (env, decomp_prems) = |
73526
a3cc9fa1295d
new automatic order prover: stateless, complete, verified
nipkow
parents:
diff
changeset
|
295 |
let |
74625
e6f0c9bf966c
order_tac: prevent potential bug, improve perf and tracing
Lukas Stevens <mail@lukas-stevens.de>
parents:
74561
diff
changeset
|
296 |
val [eq, le, lt] = #ops octxt |> map (Envir.eta_contract o Envir.subst_term env) |
e6f0c9bf966c
order_tac: prevent potential bug, improve perf and tracing
Lukas Stevens <mail@lukas-stevens.de>
parents:
74561
diff
changeset
|
297 |
|
e6f0c9bf966c
order_tac: prevent potential bug, improve perf and tracing
Lukas Stevens <mail@lukas-stevens.de>
parents:
74561
diff
changeset
|
298 |
val decomp_prems = case #kind octxt of |
e6f0c9bf966c
order_tac: prevent potential bug, improve perf and tracing
Lukas Stevens <mail@lukas-stevens.de>
parents:
74561
diff
changeset
|
299 |
Order => limit_not_less (#ops octxt) ctxt decomp_prems |
e6f0c9bf966c
order_tac: prevent potential bug, improve perf and tracing
Lukas Stevens <mail@lukas-stevens.de>
parents:
74561
diff
changeset
|
300 |
| _ => decomp_prems |
e6f0c9bf966c
order_tac: prevent potential bug, improve perf and tracing
Lukas Stevens <mail@lukas-stevens.de>
parents:
74561
diff
changeset
|
301 |
|
e6f0c9bf966c
order_tac: prevent potential bug, improve perf and tracing
Lukas Stevens <mail@lukas-stevens.de>
parents:
74561
diff
changeset
|
302 |
fun reify_prem (_, (b, ctor, (x, y), _)) (ps, reifytab) = |
e6f0c9bf966c
order_tac: prevent potential bug, improve perf and tracing
Lukas Stevens <mail@lukas-stevens.de>
parents:
74561
diff
changeset
|
303 |
(Reifytab.get_var x ##>> Reifytab.get_var y) reifytab |
e6f0c9bf966c
order_tac: prevent potential bug, improve perf and tracing
Lukas Stevens <mail@lukas-stevens.de>
parents:
74561
diff
changeset
|
304 |
|>> (fn vp => (b, ctor (apply2 Int_of_integer vp)) :: ps) |
e6f0c9bf966c
order_tac: prevent potential bug, improve perf and tracing
Lukas Stevens <mail@lukas-stevens.de>
parents:
74561
diff
changeset
|
305 |
val (reified_prems, reifytab) = fold_rev reify_prem decomp_prems ([], Reifytab.empty) |
e6f0c9bf966c
order_tac: prevent potential bug, improve perf and tracing
Lukas Stevens <mail@lukas-stevens.de>
parents:
74561
diff
changeset
|
306 |
|
e6f0c9bf966c
order_tac: prevent potential bug, improve perf and tracing
Lukas Stevens <mail@lukas-stevens.de>
parents:
74561
diff
changeset
|
307 |
val reified_prems_conj = foldl1 (fn (x, a) => And (x, a)) (map Atom reified_prems) |
e6f0c9bf966c
order_tac: prevent potential bug, improve perf and tracing
Lukas Stevens <mail@lukas-stevens.de>
parents:
74561
diff
changeset
|
308 |
val prems_conj_thm = map fst decomp_prems |
e6f0c9bf966c
order_tac: prevent potential bug, improve perf and tracing
Lukas Stevens <mail@lukas-stevens.de>
parents:
74561
diff
changeset
|
309 |
|> foldl1 (fn (x, a) => Logic_Sig.conjI OF [x, a]) |
e6f0c9bf966c
order_tac: prevent potential bug, improve perf and tracing
Lukas Stevens <mail@lukas-stevens.de>
parents:
74561
diff
changeset
|
310 |
|> Conv.fconv_rule Thm.eta_conversion |
73526
a3cc9fa1295d
new automatic order prover: stateless, complete, verified
nipkow
parents:
diff
changeset
|
311 |
val prems_conj = prems_conj_thm |> Thm.prop_of |
74625
e6f0c9bf966c
order_tac: prevent potential bug, improve perf and tracing
Lukas Stevens <mail@lukas-stevens.de>
parents:
74561
diff
changeset
|
312 |
|
73526
a3cc9fa1295d
new automatic order prover: stateless, complete, verified
nipkow
parents:
diff
changeset
|
313 |
val proof = raw_order_proc reified_prems_conj |
74625
e6f0c9bf966c
order_tac: prevent potential bug, improve perf and tracing
Lukas Stevens <mail@lukas-stevens.de>
parents:
74561
diff
changeset
|
314 |
|
e6f0c9bf966c
order_tac: prevent potential bug, improve perf and tracing
Lukas Stevens <mail@lukas-stevens.de>
parents:
74561
diff
changeset
|
315 |
val pretty_term_list = |
e6f0c9bf966c
order_tac: prevent potential bug, improve perf and tracing
Lukas Stevens <mail@lukas-stevens.de>
parents:
74561
diff
changeset
|
316 |
Pretty.list "" "" o map (Syntax.pretty_term (Config.put show_types true ctxt)) |
e6f0c9bf966c
order_tac: prevent potential bug, improve perf and tracing
Lukas Stevens <mail@lukas-stevens.de>
parents:
74561
diff
changeset
|
317 |
val pretty_thm_list = Pretty.list "" "" o map (Thm.pretty_thm ctxt) |
e6f0c9bf966c
order_tac: prevent potential bug, improve perf and tracing
Lukas Stevens <mail@lukas-stevens.de>
parents:
74561
diff
changeset
|
318 |
fun pretty_type_of t = Pretty.block [ Pretty.str "::", Pretty.brk 1, |
e6f0c9bf966c
order_tac: prevent potential bug, improve perf and tracing
Lukas Stevens <mail@lukas-stevens.de>
parents:
74561
diff
changeset
|
319 |
Pretty.quote (Syntax.pretty_typ ctxt (Term.fastype_of t)) ] |
e6f0c9bf966c
order_tac: prevent potential bug, improve perf and tracing
Lukas Stevens <mail@lukas-stevens.de>
parents:
74561
diff
changeset
|
320 |
fun pretty_trace () = |
e6f0c9bf966c
order_tac: prevent potential bug, improve perf and tracing
Lukas Stevens <mail@lukas-stevens.de>
parents:
74561
diff
changeset
|
321 |
[ ("order kind:", Pretty.str (@{make_string} (#kind octxt))) |
e6f0c9bf966c
order_tac: prevent potential bug, improve perf and tracing
Lukas Stevens <mail@lukas-stevens.de>
parents:
74561
diff
changeset
|
322 |
, ("order operators:", Pretty.block [ pretty_term_list [eq, le, lt], Pretty.brk 1 |
e6f0c9bf966c
order_tac: prevent potential bug, improve perf and tracing
Lukas Stevens <mail@lukas-stevens.de>
parents:
74561
diff
changeset
|
323 |
, pretty_type_of le ]) |
e6f0c9bf966c
order_tac: prevent potential bug, improve perf and tracing
Lukas Stevens <mail@lukas-stevens.de>
parents:
74561
diff
changeset
|
324 |
, ("premises:", pretty_thm_list prems) |
e6f0c9bf966c
order_tac: prevent potential bug, improve perf and tracing
Lukas Stevens <mail@lukas-stevens.de>
parents:
74561
diff
changeset
|
325 |
, ("selected premises:", pretty_thm_list (map fst decomp_prems)) |
e6f0c9bf966c
order_tac: prevent potential bug, improve perf and tracing
Lukas Stevens <mail@lukas-stevens.de>
parents:
74561
diff
changeset
|
326 |
, ("reified premises:", Pretty.str (@{make_string} reified_prems)) |
e6f0c9bf966c
order_tac: prevent potential bug, improve perf and tracing
Lukas Stevens <mail@lukas-stevens.de>
parents:
74561
diff
changeset
|
327 |
, ("contradiction:", Pretty.str (@{make_string} (Option.isSome proof))) |
e6f0c9bf966c
order_tac: prevent potential bug, improve perf and tracing
Lukas Stevens <mail@lukas-stevens.de>
parents:
74561
diff
changeset
|
328 |
] |> map (fn (t, pp) => Pretty.block [Pretty.str t, Pretty.brk 1, pp]) |
e6f0c9bf966c
order_tac: prevent potential bug, improve perf and tracing
Lukas Stevens <mail@lukas-stevens.de>
parents:
74561
diff
changeset
|
329 |
|> Pretty.big_list "order solver called with the parameters" |
e6f0c9bf966c
order_tac: prevent potential bug, improve perf and tracing
Lukas Stevens <mail@lukas-stevens.de>
parents:
74561
diff
changeset
|
330 |
val _ = if trace then tracing (Pretty.string_of (pretty_trace ())) else () |
e6f0c9bf966c
order_tac: prevent potential bug, improve perf and tracing
Lukas Stevens <mail@lukas-stevens.de>
parents:
74561
diff
changeset
|
331 |
|
73526
a3cc9fa1295d
new automatic order prover: stateless, complete, verified
nipkow
parents:
diff
changeset
|
332 |
val assmtab = Termtab.make [(prems_conj, prems_conj_thm)] |
74625
e6f0c9bf966c
order_tac: prevent potential bug, improve perf and tracing
Lukas Stevens <mail@lukas-stevens.de>
parents:
74561
diff
changeset
|
333 |
val replay = replay_order_prf_trm (eq, le, lt) octxt ctxt reifytab assmtab |
73526
a3cc9fa1295d
new automatic order prover: stateless, complete, verified
nipkow
parents:
diff
changeset
|
334 |
in |
a3cc9fa1295d
new automatic order prover: stateless, complete, verified
nipkow
parents:
diff
changeset
|
335 |
case proof of |
a3cc9fa1295d
new automatic order prover: stateless, complete, verified
nipkow
parents:
diff
changeset
|
336 |
NONE => no_tac |
a3cc9fa1295d
new automatic order prover: stateless, complete, verified
nipkow
parents:
diff
changeset
|
337 |
| SOME p => SOLVED' (resolve_tac ctxt [replay p]) 1 |
a3cc9fa1295d
new automatic order prover: stateless, complete, verified
nipkow
parents:
diff
changeset
|
338 |
end |
a3cc9fa1295d
new automatic order prover: stateless, complete, verified
nipkow
parents:
diff
changeset
|
339 |
in |
74625
e6f0c9bf966c
order_tac: prevent potential bug, improve perf and tracing
Lukas Stevens <mail@lukas-stevens.de>
parents:
74561
diff
changeset
|
340 |
map (fn is => ` (env_of o hd) (map (nth decomp_prems) is) |> order_tac') env_groups |
e6f0c9bf966c
order_tac: prevent potential bug, improve perf and tracing
Lukas Stevens <mail@lukas-stevens.de>
parents:
74561
diff
changeset
|
341 |
|> FIRST |
73526
a3cc9fa1295d
new automatic order prover: stateless, complete, verified
nipkow
parents:
diff
changeset
|
342 |
end) |
a3cc9fa1295d
new automatic order prover: stateless, complete, verified
nipkow
parents:
diff
changeset
|
343 |
|
a3cc9fa1295d
new automatic order prover: stateless, complete, verified
nipkow
parents:
diff
changeset
|
344 |
val ad_absurdum_tac = SUBGOAL (fn (A, i) => |
74625
e6f0c9bf966c
order_tac: prevent potential bug, improve perf and tracing
Lukas Stevens <mail@lukas-stevens.de>
parents:
74561
diff
changeset
|
345 |
case try (Logic_Sig.dest_Trueprop o Logic.strip_assums_concl) A of |
e6f0c9bf966c
order_tac: prevent potential bug, improve perf and tracing
Lukas Stevens <mail@lukas-stevens.de>
parents:
74561
diff
changeset
|
346 |
SOME (nt $ _) => |
e6f0c9bf966c
order_tac: prevent potential bug, improve perf and tracing
Lukas Stevens <mail@lukas-stevens.de>
parents:
74561
diff
changeset
|
347 |
if nt = Logic_Sig.Not |
e6f0c9bf966c
order_tac: prevent potential bug, improve perf and tracing
Lukas Stevens <mail@lukas-stevens.de>
parents:
74561
diff
changeset
|
348 |
then resolve0_tac [Logic_Sig.notI] i |
e6f0c9bf966c
order_tac: prevent potential bug, improve perf and tracing
Lukas Stevens <mail@lukas-stevens.de>
parents:
74561
diff
changeset
|
349 |
else resolve0_tac [Logic_Sig.ccontr] i |
e6f0c9bf966c
order_tac: prevent potential bug, improve perf and tracing
Lukas Stevens <mail@lukas-stevens.de>
parents:
74561
diff
changeset
|
350 |
| _ => resolve0_tac [Logic_Sig.ccontr] i) |
73526
a3cc9fa1295d
new automatic order prover: stateless, complete, verified
nipkow
parents:
diff
changeset
|
351 |
|
a3cc9fa1295d
new automatic order prover: stateless, complete, verified
nipkow
parents:
diff
changeset
|
352 |
fun tac raw_order_proc octxt simp_prems ctxt = |
74625
e6f0c9bf966c
order_tac: prevent potential bug, improve perf and tracing
Lukas Stevens <mail@lukas-stevens.de>
parents:
74561
diff
changeset
|
353 |
ad_absurdum_tac THEN' order_tac raw_order_proc octxt simp_prems ctxt |
73526
a3cc9fa1295d
new automatic order prover: stateless, complete, verified
nipkow
parents:
diff
changeset
|
354 |
|
a3cc9fa1295d
new automatic order prover: stateless, complete, verified
nipkow
parents:
diff
changeset
|
355 |
end |
a3cc9fa1295d
new automatic order prover: stateless, complete, verified
nipkow
parents:
diff
changeset
|
356 |
|
a3cc9fa1295d
new automatic order prover: stateless, complete, verified
nipkow
parents:
diff
changeset
|
357 |
functor Order_Tac(structure Base_Tac : BASE_ORDER_TAC) = struct |
a3cc9fa1295d
new automatic order prover: stateless, complete, verified
nipkow
parents:
diff
changeset
|
358 |
|
a3cc9fa1295d
new automatic order prover: stateless, complete, verified
nipkow
parents:
diff
changeset
|
359 |
fun order_context_eq ({kind = kind1, ops = ops1, ...}, {kind = kind2, ops = ops2, ...}) = |
a3cc9fa1295d
new automatic order prover: stateless, complete, verified
nipkow
parents:
diff
changeset
|
360 |
kind1 = kind2 andalso eq_list (op aconv) (ops1, ops2) |
a3cc9fa1295d
new automatic order prover: stateless, complete, verified
nipkow
parents:
diff
changeset
|
361 |
|
a3cc9fa1295d
new automatic order prover: stateless, complete, verified
nipkow
parents:
diff
changeset
|
362 |
fun order_data_eq (x, y) = order_context_eq (fst x, fst y) |
a3cc9fa1295d
new automatic order prover: stateless, complete, verified
nipkow
parents:
diff
changeset
|
363 |
|
a3cc9fa1295d
new automatic order prover: stateless, complete, verified
nipkow
parents:
diff
changeset
|
364 |
structure Data = Generic_Data( |
a3cc9fa1295d
new automatic order prover: stateless, complete, verified
nipkow
parents:
diff
changeset
|
365 |
type T = (order_context * (order_context -> thm list -> Proof.context -> int -> tactic)) list |
a3cc9fa1295d
new automatic order prover: stateless, complete, verified
nipkow
parents:
diff
changeset
|
366 |
val empty = [] |
a3cc9fa1295d
new automatic order prover: stateless, complete, verified
nipkow
parents:
diff
changeset
|
367 |
fun merge data = Library.merge order_data_eq data |
a3cc9fa1295d
new automatic order prover: stateless, complete, verified
nipkow
parents:
diff
changeset
|
368 |
) |
a3cc9fa1295d
new automatic order prover: stateless, complete, verified
nipkow
parents:
diff
changeset
|
369 |
|
a3cc9fa1295d
new automatic order prover: stateless, complete, verified
nipkow
parents:
diff
changeset
|
370 |
fun declare (octxt as {kind = kind, raw_proc = raw_proc, ...}) lthy = |
78095 | 371 |
lthy |> Local_Theory.declaration {syntax = false, pervasive = false, pos = \<^here>} |
372 |
(fn phi => fn context => |
|
373 |
let |
|
374 |
val ops = map (Morphism.term phi) (#ops octxt) |
|
375 |
val thms = map (fn (s, thm) => (s, Morphism.thm phi thm)) (#thms octxt) |
|
376 |
val conv_thms = map (fn (s, thm) => (s, Morphism.thm phi thm)) (#conv_thms octxt) |
|
377 |
val octxt' = {kind = kind, ops = ops, thms = thms, conv_thms = conv_thms} |
|
378 |
in |
|
379 |
context |> Data.map (Library.insert order_data_eq (octxt', raw_proc)) |
|
380 |
end) |
|
73526
a3cc9fa1295d
new automatic order prover: stateless, complete, verified
nipkow
parents:
diff
changeset
|
381 |
|
a3cc9fa1295d
new automatic order prover: stateless, complete, verified
nipkow
parents:
diff
changeset
|
382 |
fun declare_order { |
a3cc9fa1295d
new automatic order prover: stateless, complete, verified
nipkow
parents:
diff
changeset
|
383 |
ops = {eq = eq, le = le, lt = lt}, |
a3cc9fa1295d
new automatic order prover: stateless, complete, verified
nipkow
parents:
diff
changeset
|
384 |
thms = { |
a3cc9fa1295d
new automatic order prover: stateless, complete, verified
nipkow
parents:
diff
changeset
|
385 |
trans = trans, (* x \<le> y \<Longrightarrow> y \<le> z \<Longrightarrow> x \<le> z *) |
a3cc9fa1295d
new automatic order prover: stateless, complete, verified
nipkow
parents:
diff
changeset
|
386 |
refl = refl, (* x \<le> x *) |
a3cc9fa1295d
new automatic order prover: stateless, complete, verified
nipkow
parents:
diff
changeset
|
387 |
eqD1 = eqD1, (* x = y \<Longrightarrow> x \<le> y *) |
a3cc9fa1295d
new automatic order prover: stateless, complete, verified
nipkow
parents:
diff
changeset
|
388 |
eqD2 = eqD2, (* x = y \<Longrightarrow> y \<le> x *) |
a3cc9fa1295d
new automatic order prover: stateless, complete, verified
nipkow
parents:
diff
changeset
|
389 |
antisym = antisym, (* x \<le> y \<Longrightarrow> y \<le> x \<Longrightarrow> x = y *) |
a3cc9fa1295d
new automatic order prover: stateless, complete, verified
nipkow
parents:
diff
changeset
|
390 |
contr = contr (* \<not> P \<Longrightarrow> P \<Longrightarrow> R *) |
a3cc9fa1295d
new automatic order prover: stateless, complete, verified
nipkow
parents:
diff
changeset
|
391 |
}, |
a3cc9fa1295d
new automatic order prover: stateless, complete, verified
nipkow
parents:
diff
changeset
|
392 |
conv_thms = { |
a3cc9fa1295d
new automatic order prover: stateless, complete, verified
nipkow
parents:
diff
changeset
|
393 |
less_le = less_le, (* x < y \<equiv> x \<le> y \<and> x \<noteq> y *) |
a3cc9fa1295d
new automatic order prover: stateless, complete, verified
nipkow
parents:
diff
changeset
|
394 |
nless_le = nless_le (* \<not> a < b \<equiv> \<not> a \<le> b \<or> a = b *) |
a3cc9fa1295d
new automatic order prover: stateless, complete, verified
nipkow
parents:
diff
changeset
|
395 |
} |
a3cc9fa1295d
new automatic order prover: stateless, complete, verified
nipkow
parents:
diff
changeset
|
396 |
} = |
a3cc9fa1295d
new automatic order prover: stateless, complete, verified
nipkow
parents:
diff
changeset
|
397 |
declare { |
a3cc9fa1295d
new automatic order prover: stateless, complete, verified
nipkow
parents:
diff
changeset
|
398 |
kind = Order, |
a3cc9fa1295d
new automatic order prover: stateless, complete, verified
nipkow
parents:
diff
changeset
|
399 |
ops = [eq, le, lt], |
a3cc9fa1295d
new automatic order prover: stateless, complete, verified
nipkow
parents:
diff
changeset
|
400 |
thms = [("trans", trans), ("refl", refl), ("eqD1", eqD1), ("eqD2", eqD2), |
a3cc9fa1295d
new automatic order prover: stateless, complete, verified
nipkow
parents:
diff
changeset
|
401 |
("antisym", antisym), ("contr", contr)], |
a3cc9fa1295d
new automatic order prover: stateless, complete, verified
nipkow
parents:
diff
changeset
|
402 |
conv_thms = [("less_le", less_le), ("nless_le", nless_le)], |
a3cc9fa1295d
new automatic order prover: stateless, complete, verified
nipkow
parents:
diff
changeset
|
403 |
raw_proc = Base_Tac.tac Order_Procedure.po_contr_prf |
a3cc9fa1295d
new automatic order prover: stateless, complete, verified
nipkow
parents:
diff
changeset
|
404 |
} |
a3cc9fa1295d
new automatic order prover: stateless, complete, verified
nipkow
parents:
diff
changeset
|
405 |
|
a3cc9fa1295d
new automatic order prover: stateless, complete, verified
nipkow
parents:
diff
changeset
|
406 |
fun declare_linorder { |
a3cc9fa1295d
new automatic order prover: stateless, complete, verified
nipkow
parents:
diff
changeset
|
407 |
ops = {eq = eq, le = le, lt = lt}, |
a3cc9fa1295d
new automatic order prover: stateless, complete, verified
nipkow
parents:
diff
changeset
|
408 |
thms = { |
a3cc9fa1295d
new automatic order prover: stateless, complete, verified
nipkow
parents:
diff
changeset
|
409 |
trans = trans, (* x \<le> y \<Longrightarrow> y \<le> z \<Longrightarrow> x \<le> z *) |
a3cc9fa1295d
new automatic order prover: stateless, complete, verified
nipkow
parents:
diff
changeset
|
410 |
refl = refl, (* x \<le> x *) |
a3cc9fa1295d
new automatic order prover: stateless, complete, verified
nipkow
parents:
diff
changeset
|
411 |
eqD1 = eqD1, (* x = y \<Longrightarrow> x \<le> y *) |
a3cc9fa1295d
new automatic order prover: stateless, complete, verified
nipkow
parents:
diff
changeset
|
412 |
eqD2 = eqD2, (* x = y \<Longrightarrow> y \<le> x *) |
a3cc9fa1295d
new automatic order prover: stateless, complete, verified
nipkow
parents:
diff
changeset
|
413 |
antisym = antisym, (* x \<le> y \<Longrightarrow> y \<le> x \<Longrightarrow> x = y *) |
a3cc9fa1295d
new automatic order prover: stateless, complete, verified
nipkow
parents:
diff
changeset
|
414 |
contr = contr (* \<not> P \<Longrightarrow> P \<Longrightarrow> R *) |
a3cc9fa1295d
new automatic order prover: stateless, complete, verified
nipkow
parents:
diff
changeset
|
415 |
}, |
a3cc9fa1295d
new automatic order prover: stateless, complete, verified
nipkow
parents:
diff
changeset
|
416 |
conv_thms = { |
a3cc9fa1295d
new automatic order prover: stateless, complete, verified
nipkow
parents:
diff
changeset
|
417 |
less_le = less_le, (* x < y \<equiv> x \<le> y \<and> x \<noteq> y *) |
a3cc9fa1295d
new automatic order prover: stateless, complete, verified
nipkow
parents:
diff
changeset
|
418 |
nless_le = nless_le, (* \<not> x < y \<equiv> y \<le> x *) |
a3cc9fa1295d
new automatic order prover: stateless, complete, verified
nipkow
parents:
diff
changeset
|
419 |
nle_le = nle_le (* \<not> a \<le> b \<equiv> b \<le> a \<and> b \<noteq> a *) |
a3cc9fa1295d
new automatic order prover: stateless, complete, verified
nipkow
parents:
diff
changeset
|
420 |
} |
a3cc9fa1295d
new automatic order prover: stateless, complete, verified
nipkow
parents:
diff
changeset
|
421 |
} = |
a3cc9fa1295d
new automatic order prover: stateless, complete, verified
nipkow
parents:
diff
changeset
|
422 |
declare { |
a3cc9fa1295d
new automatic order prover: stateless, complete, verified
nipkow
parents:
diff
changeset
|
423 |
kind = Linorder, |
a3cc9fa1295d
new automatic order prover: stateless, complete, verified
nipkow
parents:
diff
changeset
|
424 |
ops = [eq, le, lt], |
a3cc9fa1295d
new automatic order prover: stateless, complete, verified
nipkow
parents:
diff
changeset
|
425 |
thms = [("trans", trans), ("refl", refl), ("eqD1", eqD1), ("eqD2", eqD2), |
a3cc9fa1295d
new automatic order prover: stateless, complete, verified
nipkow
parents:
diff
changeset
|
426 |
("antisym", antisym), ("contr", contr)], |
a3cc9fa1295d
new automatic order prover: stateless, complete, verified
nipkow
parents:
diff
changeset
|
427 |
conv_thms = [("less_le", less_le), ("nless_le", nless_le), ("nle_le", nle_le)], |
a3cc9fa1295d
new automatic order prover: stateless, complete, verified
nipkow
parents:
diff
changeset
|
428 |
raw_proc = Base_Tac.tac Order_Procedure.lo_contr_prf |
a3cc9fa1295d
new automatic order prover: stateless, complete, verified
nipkow
parents:
diff
changeset
|
429 |
} |
a3cc9fa1295d
new automatic order prover: stateless, complete, verified
nipkow
parents:
diff
changeset
|
430 |
|
a3cc9fa1295d
new automatic order prover: stateless, complete, verified
nipkow
parents:
diff
changeset
|
431 |
(* Try to solve the goal by calling the order solver with each of the declared orders. *) |
a3cc9fa1295d
new automatic order prover: stateless, complete, verified
nipkow
parents:
diff
changeset
|
432 |
fun tac simp_prems ctxt = |
a3cc9fa1295d
new automatic order prover: stateless, complete, verified
nipkow
parents:
diff
changeset
|
433 |
let fun app_tac (octxt, tac0) = CHANGED o tac0 octxt simp_prems ctxt |
a3cc9fa1295d
new automatic order prover: stateless, complete, verified
nipkow
parents:
diff
changeset
|
434 |
in FIRST' (map app_tac (Data.get (Context.Proof ctxt))) end |
a3cc9fa1295d
new automatic order prover: stateless, complete, verified
nipkow
parents:
diff
changeset
|
435 |
end |