| author | wenzelm |
| Sat, 06 Jan 2001 21:28:30 +0100 | |
| changeset 10808 | cc4a3ed7e70b |
| parent 10377 | 6b595f9ae37e |
| child 11764 | fd780dd6e0b4 |
| permissions | -rw-r--r-- |
|
6783
9cf9c17d9e35
renamed object_logic.ML to Isar/auto_bind.ML and tuned this module;
wenzelm
parents:
diff
changeset
|
1 |
(* Title: Pure/Isar/auto_bind.ML |
|
9cf9c17d9e35
renamed object_logic.ML to Isar/auto_bind.ML and tuned this module;
wenzelm
parents:
diff
changeset
|
2 |
ID: $Id$ |
|
9cf9c17d9e35
renamed object_logic.ML to Isar/auto_bind.ML and tuned this module;
wenzelm
parents:
diff
changeset
|
3 |
Author: Markus Wenzel, TU Muenchen |
| 8807 | 4 |
License: GPL (GNU GENERAL PUBLIC LICENSE) |
|
6783
9cf9c17d9e35
renamed object_logic.ML to Isar/auto_bind.ML and tuned this module;
wenzelm
parents:
diff
changeset
|
5 |
|
| 10359 | 6 |
Logic specific patterns and automatic term bindings. |
| 7675 | 7 |
|
| 8227 | 8 |
Note: the current implementation is not quite 'generic', but works |
| 10359 | 9 |
fine with common object-logics (HOL, FOL, ZF etc.). |
|
6783
9cf9c17d9e35
renamed object_logic.ML to Isar/auto_bind.ML and tuned this module;
wenzelm
parents:
diff
changeset
|
10 |
*) |
|
9cf9c17d9e35
renamed object_logic.ML to Isar/auto_bind.ML and tuned this module;
wenzelm
parents:
diff
changeset
|
11 |
|
|
9cf9c17d9e35
renamed object_logic.ML to Isar/auto_bind.ML and tuned this module;
wenzelm
parents:
diff
changeset
|
12 |
signature AUTO_BIND = |
|
9cf9c17d9e35
renamed object_logic.ML to Isar/auto_bind.ML and tuned this module;
wenzelm
parents:
diff
changeset
|
13 |
sig |
| 10359 | 14 |
val is_judgment: term -> bool |
| 10808 | 15 |
val drop_judgment: term -> term |
| 10377 | 16 |
val atomic_judgment: theory -> string -> term |
| 10359 | 17 |
val add_judgment: bstring * string * mixfix -> theory -> theory |
18 |
val add_judgment_i: bstring * typ * mixfix -> theory -> theory |
|
| 7599 | 19 |
val goal: term -> (indexname * term option) list |
20 |
val facts: string -> term list -> (indexname * term option) list |
|
| 9296 | 21 |
val thesisN: string |
|
6783
9cf9c17d9e35
renamed object_logic.ML to Isar/auto_bind.ML and tuned this module;
wenzelm
parents:
diff
changeset
|
22 |
end; |
|
9cf9c17d9e35
renamed object_logic.ML to Isar/auto_bind.ML and tuned this module;
wenzelm
parents:
diff
changeset
|
23 |
|
|
9cf9c17d9e35
renamed object_logic.ML to Isar/auto_bind.ML and tuned this module;
wenzelm
parents:
diff
changeset
|
24 |
structure AutoBind: AUTO_BIND = |
|
9cf9c17d9e35
renamed object_logic.ML to Isar/auto_bind.ML and tuned this module;
wenzelm
parents:
diff
changeset
|
25 |
struct |
|
9cf9c17d9e35
renamed object_logic.ML to Isar/auto_bind.ML and tuned this module;
wenzelm
parents:
diff
changeset
|
26 |
|
| 9464 | 27 |
|
28 |
(** judgments **) |
|
| 7675 | 29 |
|
| 10377 | 30 |
val TruepropN = "Trueprop"; |
31 |
||
32 |
fun is_judgment (Const (c, _) $ _) = c = TruepropN |
|
33 |
| is_judgment _ = false; |
|
| 10359 | 34 |
|
| 10808 | 35 |
fun drop_judgment (Abs (x, T, t)) = Abs (x, T, drop_judgment t) |
36 |
| drop_judgment (tm as (Const (c, _) $ t)) = if c = TruepropN then t else tm |
|
37 |
| drop_judgment tm = tm; |
|
38 |
||
39 |
val strip_judgment = drop_judgment o Logic.strip_assums_concl; |
|
40 |
||
| 10377 | 41 |
fun atomic_judgment thy x = |
42 |
let (*be robust wrt. low-level errors*) |
|
43 |
val aT = TFree ("'a", logicS);
|
|
44 |
val T = |
|
45 |
if_none (Sign.const_type (Theory.sign_of thy) TruepropN) (aT --> propT) |
|
46 |
|> Term.map_type_tvar (fn ((x, _), S) => TFree (x, S)); |
|
47 |
val U = Term.domain_type T handle Match => aT; |
|
48 |
in Const (TruepropN, T) $ Free (x, U) end; |
|
| 8227 | 49 |
|
50 |
||
| 9464 | 51 |
fun gen_add_judgment add (name, T, syn) thy = |
| 10377 | 52 |
if name = TruepropN then |
| 9464 | 53 |
thy |> PureThy.global_path |> add [(name, T, syn)] |> PureThy.local_path |
| 10377 | 54 |
else error ("Judgment name has to be " ^ quote TruepropN);
|
| 8227 | 55 |
|
56 |
val add_judgment = gen_add_judgment Theory.add_consts; |
|
57 |
val add_judgment_i = gen_add_judgment Theory.add_consts_i; |
|
58 |
||
| 6796 | 59 |
|
| 10359 | 60 |
|
61 |
(** bindings **) |
|
62 |
||
63 |
val thesisN = "thesis"; |
|
64 |
val thisN = "this"; |
|
65 |
||
66 |
fun statement_binds name prop = |
|
| 10808 | 67 |
[((name, 0), Some (Term.list_abs (Logic.strip_params prop, strip_judgment prop)))]; |
| 10359 | 68 |
|
69 |
||
70 |
(* goal *) |
|
71 |
||
72 |
fun goal prop = statement_binds thesisN prop; |
|
73 |
||
74 |
||
75 |
(* facts *) |
|
76 |
||
77 |
fun get_arg prop = |
|
78 |
(case strip_judgment prop of |
|
| 10808 | 79 |
_ $ t => Some (Term.list_abs (Logic.strip_params prop, t)) |
| 10359 | 80 |
| _ => None); |
81 |
||
82 |
fun facts _ [] = [] |
|
83 |
| facts name props = |
|
84 |
let val prop = Library.last_elem props |
|
85 |
in [(Syntax.dddot_indexname, get_arg prop)] @ statement_binds thisN prop end; |
|
86 |
||
| 10808 | 87 |
|
|
6783
9cf9c17d9e35
renamed object_logic.ML to Isar/auto_bind.ML and tuned this module;
wenzelm
parents:
diff
changeset
|
88 |
end; |