| author | wenzelm | 
| Wed, 17 Jun 2009 17:06:07 +0200 | |
| changeset 31686 | e54ae15335a1 | 
| parent 30763 | 6976521b4263 | 
| child 32661 | f4d179d91af2 | 
| permissions | -rw-r--r-- | 
| 
18620
 
fc8b5f275359
Theory specifications --- with type-inference, but no internal polymorphism.
 
wenzelm 
parents:  
diff
changeset
 | 
1  | 
(* Title: Pure/Isar/specification.ML  | 
| 
 
fc8b5f275359
Theory specifications --- with type-inference, but no internal polymorphism.
 
wenzelm 
parents:  
diff
changeset
 | 
2  | 
Author: Makarius  | 
| 
 
fc8b5f275359
Theory specifications --- with type-inference, but no internal polymorphism.
 
wenzelm 
parents:  
diff
changeset
 | 
3  | 
|
| 21036 | 4  | 
Derived local theory specifications --- with type-inference and  | 
| 18810 | 5  | 
toplevel polymorphism.  | 
| 
18620
 
fc8b5f275359
Theory specifications --- with type-inference, but no internal polymorphism.
 
wenzelm 
parents:  
diff
changeset
 | 
6  | 
*)  | 
| 
 
fc8b5f275359
Theory specifications --- with type-inference, but no internal polymorphism.
 
wenzelm 
parents:  
diff
changeset
 | 
7  | 
|
| 
 
fc8b5f275359
Theory specifications --- with type-inference, but no internal polymorphism.
 
wenzelm 
parents:  
diff
changeset
 | 
8  | 
signature SPECIFICATION =  | 
| 
 
fc8b5f275359
Theory specifications --- with type-inference, but no internal polymorphism.
 
wenzelm 
parents:  
diff
changeset
 | 
9  | 
sig  | 
| 20890 | 10  | 
val print_consts: local_theory -> (string * typ -> bool) -> (string * typ) list -> unit  | 
| 
30482
 
6e3c92de4a7d
simplified versions check_spec, read_spec, check_free_spec, read_free_spec: operate on list of singleton statements;
 
wenzelm 
parents: 
30472 
diff
changeset
 | 
11  | 
val check_spec:  | 
| 
 
6e3c92de4a7d
simplified versions check_spec, read_spec, check_free_spec, read_free_spec: operate on list of singleton statements;
 
wenzelm 
parents: 
30472 
diff
changeset
 | 
12  | 
(binding * typ option * mixfix) list -> (Attrib.binding * term) list -> Proof.context ->  | 
| 
 
6e3c92de4a7d
simplified versions check_spec, read_spec, check_free_spec, read_free_spec: operate on list of singleton statements;
 
wenzelm 
parents: 
30472 
diff
changeset
 | 
13  | 
(((binding * typ) * mixfix) list * (Attrib.binding * term) list) * Proof.context  | 
| 
 
6e3c92de4a7d
simplified versions check_spec, read_spec, check_free_spec, read_free_spec: operate on list of singleton statements;
 
wenzelm 
parents: 
30472 
diff
changeset
 | 
14  | 
val read_spec:  | 
| 
 
6e3c92de4a7d
simplified versions check_spec, read_spec, check_free_spec, read_free_spec: operate on list of singleton statements;
 
wenzelm 
parents: 
30472 
diff
changeset
 | 
15  | 
(binding * string option * mixfix) list -> (Attrib.binding * string) list -> Proof.context ->  | 
| 
 
6e3c92de4a7d
simplified versions check_spec, read_spec, check_free_spec, read_free_spec: operate on list of singleton statements;
 
wenzelm 
parents: 
30472 
diff
changeset
 | 
16  | 
(((binding * typ) * mixfix) list * (Attrib.binding * term) list) * Proof.context  | 
| 
 
6e3c92de4a7d
simplified versions check_spec, read_spec, check_free_spec, read_free_spec: operate on list of singleton statements;
 
wenzelm 
parents: 
30472 
diff
changeset
 | 
17  | 
val check_free_spec:  | 
| 
 
6e3c92de4a7d
simplified versions check_spec, read_spec, check_free_spec, read_free_spec: operate on list of singleton statements;
 
wenzelm 
parents: 
30472 
diff
changeset
 | 
18  | 
(binding * typ option * mixfix) list -> (Attrib.binding * term) list -> Proof.context ->  | 
| 
 
6e3c92de4a7d
simplified versions check_spec, read_spec, check_free_spec, read_free_spec: operate on list of singleton statements;
 
wenzelm 
parents: 
30472 
diff
changeset
 | 
19  | 
(((binding * typ) * mixfix) list * (Attrib.binding * term) list) * Proof.context  | 
| 
 
6e3c92de4a7d
simplified versions check_spec, read_spec, check_free_spec, read_free_spec: operate on list of singleton statements;
 
wenzelm 
parents: 
30472 
diff
changeset
 | 
20  | 
val read_free_spec:  | 
| 
 
6e3c92de4a7d
simplified versions check_spec, read_spec, check_free_spec, read_free_spec: operate on list of singleton statements;
 
wenzelm 
parents: 
30472 
diff
changeset
 | 
21  | 
(binding * string option * mixfix) list -> (Attrib.binding * string) list -> Proof.context ->  | 
| 
 
6e3c92de4a7d
simplified versions check_spec, read_spec, check_free_spec, read_free_spec: operate on list of singleton statements;
 
wenzelm 
parents: 
30472 
diff
changeset
 | 
22  | 
(((binding * typ) * mixfix) list * (Attrib.binding * term) list) * Proof.context  | 
| 29581 | 23  | 
val check_specification: (binding * typ option * mixfix) list ->  | 
| 
30482
 
6e3c92de4a7d
simplified versions check_spec, read_spec, check_free_spec, read_free_spec: operate on list of singleton statements;
 
wenzelm 
parents: 
30472 
diff
changeset
 | 
24  | 
(Attrib.binding * term list) list -> Proof.context ->  | 
| 29581 | 25  | 
(((binding * typ) * mixfix) list * (Attrib.binding * term list) list) * Proof.context  | 
26  | 
val read_specification: (binding * string option * mixfix) list ->  | 
|
| 
28084
 
a05ca48ef263
type Attrib.binding abbreviates Name.binding without attributes;
 
wenzelm 
parents: 
28080 
diff
changeset
 | 
27  | 
(Attrib.binding * string list) list -> Proof.context ->  | 
| 29581 | 28  | 
(((binding * typ) * mixfix) list * (Attrib.binding * term list) list) * Proof.context  | 
29  | 
val axiomatization: (binding * typ option * mixfix) list ->  | 
|
| 28114 | 30  | 
(Attrib.binding * term list) list -> theory ->  | 
31  | 
(term list * (string * thm list) list) * theory  | 
|
| 29581 | 32  | 
val axiomatization_cmd: (binding * string option * mixfix) list ->  | 
| 28114 | 33  | 
(Attrib.binding * string list) list -> theory ->  | 
34  | 
(term list * (string * thm list) list) * theory  | 
|
| 18954 | 35  | 
val definition:  | 
| 29581 | 36  | 
(binding * typ option * mixfix) option * (Attrib.binding * term) ->  | 
| 
28080
 
4723eb2456ce
explicit type Name.binding for higher-specification elements;
 
wenzelm 
parents: 
27858 
diff
changeset
 | 
37  | 
local_theory -> (term * (string * thm)) * local_theory  | 
| 
24927
 
48e08f37ce92
Specification: renamed XXX_i to XXX, and XXX to XXX_cmd;
 
wenzelm 
parents: 
24848 
diff
changeset
 | 
38  | 
val definition_cmd:  | 
| 29581 | 39  | 
(binding * string option * mixfix) option * (Attrib.binding * string) ->  | 
| 
28080
 
4723eb2456ce
explicit type Name.binding for higher-specification elements;
 
wenzelm 
parents: 
27858 
diff
changeset
 | 
40  | 
local_theory -> (term * (string * thm)) * local_theory  | 
| 29581 | 41  | 
val abbreviation: Syntax.mode -> (binding * typ option * mixfix) option * term ->  | 
| 21532 | 42  | 
local_theory -> local_theory  | 
| 29581 | 43  | 
val abbreviation_cmd: Syntax.mode -> (binding * string option * mixfix) option * string ->  | 
| 
24927
 
48e08f37ce92
Specification: renamed XXX_i to XXX, and XXX to XXX_cmd;
 
wenzelm 
parents: 
24848 
diff
changeset
 | 
44  | 
local_theory -> local_theory  | 
| 24949 | 45  | 
val notation: bool -> Syntax.mode -> (term * mixfix) list -> local_theory -> local_theory  | 
46  | 
val notation_cmd: bool -> Syntax.mode -> (string * mixfix) list -> local_theory -> local_theory  | 
|
| 
28080
 
4723eb2456ce
explicit type Name.binding for higher-specification elements;
 
wenzelm 
parents: 
27858 
diff
changeset
 | 
47  | 
val theorems: string ->  | 
| 
28084
 
a05ca48ef263
type Attrib.binding abbreviates Name.binding without attributes;
 
wenzelm 
parents: 
28080 
diff
changeset
 | 
48  | 
(Attrib.binding * (thm list * Attrib.src list) list) list ->  | 
| 
28080
 
4723eb2456ce
explicit type Name.binding for higher-specification elements;
 
wenzelm 
parents: 
27858 
diff
changeset
 | 
49  | 
local_theory -> (string * thm list) list * local_theory  | 
| 
26336
 
a0e2b706ce73
renamed datatype thmref to Facts.ref, tuned interfaces;
 
wenzelm 
parents: 
25371 
diff
changeset
 | 
50  | 
val theorems_cmd: string ->  | 
| 
28084
 
a05ca48ef263
type Attrib.binding abbreviates Name.binding without attributes;
 
wenzelm 
parents: 
28080 
diff
changeset
 | 
51  | 
(Attrib.binding * (Facts.ref * Attrib.src list) list) list ->  | 
| 
28080
 
4723eb2456ce
explicit type Name.binding for higher-specification elements;
 
wenzelm 
parents: 
27858 
diff
changeset
 | 
52  | 
local_theory -> (string * thm list) list * local_theory  | 
| 24986 | 53  | 
val theorem: string -> Method.text option ->  | 
| 
28084
 
a05ca48ef263
type Attrib.binding abbreviates Name.binding without attributes;
 
wenzelm 
parents: 
28080 
diff
changeset
 | 
54  | 
(thm list list -> local_theory -> local_theory) -> Attrib.binding ->  | 
| 28710 | 55  | 
Element.context_i list -> Element.statement_i ->  | 
| 
24452
 
93b113c5ac33
- theorem(_i) now also takes "interactive" flag as argument
 
berghofe 
parents: 
24219 
diff
changeset
 | 
56  | 
bool -> local_theory -> Proof.state  | 
| 24986 | 57  | 
val theorem_cmd: string -> Method.text option ->  | 
| 
28084
 
a05ca48ef263
type Attrib.binding abbreviates Name.binding without attributes;
 
wenzelm 
parents: 
28080 
diff
changeset
 | 
58  | 
(thm list list -> local_theory -> local_theory) -> Attrib.binding ->  | 
| 28710 | 59  | 
Element.context list -> Element.statement ->  | 
| 
24452
 
93b113c5ac33
- theorem(_i) now also takes "interactive" flag as argument
 
berghofe 
parents: 
24219 
diff
changeset
 | 
60  | 
bool -> local_theory -> Proof.state  | 
| 
 
93b113c5ac33
- theorem(_i) now also takes "interactive" flag as argument
 
berghofe 
parents: 
24219 
diff
changeset
 | 
61  | 
val add_theorem_hook: (bool -> Proof.state -> Proof.state) -> Context.generic -> Context.generic  | 
| 
18620
 
fc8b5f275359
Theory specifications --- with type-inference, but no internal polymorphism.
 
wenzelm 
parents:  
diff
changeset
 | 
62  | 
end;  | 
| 
 
fc8b5f275359
Theory specifications --- with type-inference, but no internal polymorphism.
 
wenzelm 
parents:  
diff
changeset
 | 
63  | 
|
| 
 
fc8b5f275359
Theory specifications --- with type-inference, but no internal polymorphism.
 
wenzelm 
parents:  
diff
changeset
 | 
64  | 
structure Specification: SPECIFICATION =  | 
| 
 
fc8b5f275359
Theory specifications --- with type-inference, but no internal polymorphism.
 
wenzelm 
parents:  
diff
changeset
 | 
65  | 
struct  | 
| 
 
fc8b5f275359
Theory specifications --- with type-inference, but no internal polymorphism.
 
wenzelm 
parents:  
diff
changeset
 | 
66  | 
|
| 20890 | 67  | 
(* diagnostics *)  | 
68  | 
||
69  | 
fun print_consts _ _ [] = ()  | 
|
| 24986 | 70  | 
| print_consts ctxt pred cs = Pretty.writeln (ProofDisplay.pretty_consts ctxt pred cs);  | 
| 20914 | 71  | 
|
| 19664 | 72  | 
|
| 
18620
 
fc8b5f275359
Theory specifications --- with type-inference, but no internal polymorphism.
 
wenzelm 
parents:  
diff
changeset
 | 
73  | 
(* prepare specification *)  | 
| 
 
fc8b5f275359
Theory specifications --- with type-inference, but no internal polymorphism.
 
wenzelm 
parents:  
diff
changeset
 | 
74  | 
|
| 
24724
 
0df74bb87a13
read/check_specification: proper type inference across multiple sections, result is in closed form;
 
wenzelm 
parents: 
24676 
diff
changeset
 | 
75  | 
local  | 
| 
 
0df74bb87a13
read/check_specification: proper type inference across multiple sections, result is in closed form;
 
wenzelm 
parents: 
24676 
diff
changeset
 | 
76  | 
|
| 
 
0df74bb87a13
read/check_specification: proper type inference across multiple sections, result is in closed form;
 
wenzelm 
parents: 
24676 
diff
changeset
 | 
77  | 
fun close_forms ctxt i xs As =  | 
| 
 
0df74bb87a13
read/check_specification: proper type inference across multiple sections, result is in closed form;
 
wenzelm 
parents: 
24676 
diff
changeset
 | 
78  | 
let  | 
| 
 
0df74bb87a13
read/check_specification: proper type inference across multiple sections, result is in closed form;
 
wenzelm 
parents: 
24676 
diff
changeset
 | 
79  | 
fun add_free (Free (x, _)) = if Variable.is_fixed ctxt x then I else insert (op =) x  | 
| 
 
0df74bb87a13
read/check_specification: proper type inference across multiple sections, result is in closed form;
 
wenzelm 
parents: 
24676 
diff
changeset
 | 
80  | 
| add_free _ = I;  | 
| 
 
0df74bb87a13
read/check_specification: proper type inference across multiple sections, result is in closed form;
 
wenzelm 
parents: 
24676 
diff
changeset
 | 
81  | 
|
| 
 
0df74bb87a13
read/check_specification: proper type inference across multiple sections, result is in closed form;
 
wenzelm 
parents: 
24676 
diff
changeset
 | 
82  | 
val commons = map #1 xs;  | 
| 
 
0df74bb87a13
read/check_specification: proper type inference across multiple sections, result is in closed form;
 
wenzelm 
parents: 
24676 
diff
changeset
 | 
83  | 
val _ =  | 
| 
 
0df74bb87a13
read/check_specification: proper type inference across multiple sections, result is in closed form;
 
wenzelm 
parents: 
24676 
diff
changeset
 | 
84  | 
(case duplicates (op =) commons of [] => ()  | 
| 
 
0df74bb87a13
read/check_specification: proper type inference across multiple sections, result is in closed form;
 
wenzelm 
parents: 
24676 
diff
changeset
 | 
85  | 
      | dups => error ("Duplicate local variables " ^ commas_quote dups));
 | 
| 
 
0df74bb87a13
read/check_specification: proper type inference across multiple sections, result is in closed form;
 
wenzelm 
parents: 
24676 
diff
changeset
 | 
86  | 
val frees = rev ((fold o fold_aterms) add_free As (rev commons));  | 
| 24848 | 87  | 
val types = map (TypeInfer.param i o rpair []) (Name.invents Name.context Name.aT (length frees));  | 
| 
24724
 
0df74bb87a13
read/check_specification: proper type inference across multiple sections, result is in closed form;
 
wenzelm 
parents: 
24676 
diff
changeset
 | 
88  | 
val uniform_typing = the o AList.lookup (op =) (frees ~~ types);  | 
| 
 
0df74bb87a13
read/check_specification: proper type inference across multiple sections, result is in closed form;
 
wenzelm 
parents: 
24676 
diff
changeset
 | 
89  | 
|
| 
 
0df74bb87a13
read/check_specification: proper type inference across multiple sections, result is in closed form;
 
wenzelm 
parents: 
24676 
diff
changeset
 | 
90  | 
fun abs_body lev y (Abs (x, T, b)) = Abs (x, T, abs_body (lev + 1) y b)  | 
| 
 
0df74bb87a13
read/check_specification: proper type inference across multiple sections, result is in closed form;
 
wenzelm 
parents: 
24676 
diff
changeset
 | 
91  | 
| abs_body lev y (t $ u) = abs_body lev y t $ abs_body lev y u  | 
| 
 
0df74bb87a13
read/check_specification: proper type inference across multiple sections, result is in closed form;
 
wenzelm 
parents: 
24676 
diff
changeset
 | 
92  | 
| abs_body lev y (t as Free (x, T)) =  | 
| 
 
0df74bb87a13
read/check_specification: proper type inference across multiple sections, result is in closed form;
 
wenzelm 
parents: 
24676 
diff
changeset
 | 
93  | 
if x = y then TypeInfer.constrain (uniform_typing x) (TypeInfer.constrain T (Bound lev))  | 
| 
 
0df74bb87a13
read/check_specification: proper type inference across multiple sections, result is in closed form;
 
wenzelm 
parents: 
24676 
diff
changeset
 | 
94  | 
else t  | 
| 
 
0df74bb87a13
read/check_specification: proper type inference across multiple sections, result is in closed form;
 
wenzelm 
parents: 
24676 
diff
changeset
 | 
95  | 
| abs_body _ _ a = a;  | 
| 
 
0df74bb87a13
read/check_specification: proper type inference across multiple sections, result is in closed form;
 
wenzelm 
parents: 
24676 
diff
changeset
 | 
96  | 
fun close (y, U) B =  | 
| 
 
0df74bb87a13
read/check_specification: proper type inference across multiple sections, result is in closed form;
 
wenzelm 
parents: 
24676 
diff
changeset
 | 
97  | 
let val B' = abs_body 0 y (Term.incr_boundvars 1 B)  | 
| 
 
0df74bb87a13
read/check_specification: proper type inference across multiple sections, result is in closed form;
 
wenzelm 
parents: 
24676 
diff
changeset
 | 
98  | 
in if Term.loose_bvar1 (B', 0) then Term.all dummyT $ Abs (y, U, B') else B end;  | 
| 
 
0df74bb87a13
read/check_specification: proper type inference across multiple sections, result is in closed form;
 
wenzelm 
parents: 
24676 
diff
changeset
 | 
99  | 
fun close_form A =  | 
| 
 
0df74bb87a13
read/check_specification: proper type inference across multiple sections, result is in closed form;
 
wenzelm 
parents: 
24676 
diff
changeset
 | 
100  | 
let  | 
| 
 
0df74bb87a13
read/check_specification: proper type inference across multiple sections, result is in closed form;
 
wenzelm 
parents: 
24676 
diff
changeset
 | 
101  | 
val occ_frees = rev (fold_aterms add_free A []);  | 
| 
 
0df74bb87a13
read/check_specification: proper type inference across multiple sections, result is in closed form;
 
wenzelm 
parents: 
24676 
diff
changeset
 | 
102  | 
val bounds = xs @ map (rpair dummyT) (subtract (op =) commons occ_frees);  | 
| 
 
0df74bb87a13
read/check_specification: proper type inference across multiple sections, result is in closed form;
 
wenzelm 
parents: 
24676 
diff
changeset
 | 
103  | 
in fold_rev close bounds A end;  | 
| 
 
0df74bb87a13
read/check_specification: proper type inference across multiple sections, result is in closed form;
 
wenzelm 
parents: 
24676 
diff
changeset
 | 
104  | 
in map close_form As end;  | 
| 
 
0df74bb87a13
read/check_specification: proper type inference across multiple sections, result is in closed form;
 
wenzelm 
parents: 
24676 
diff
changeset
 | 
105  | 
|
| 
30482
 
6e3c92de4a7d
simplified versions check_spec, read_spec, check_free_spec, read_free_spec: operate on list of singleton statements;
 
wenzelm 
parents: 
30472 
diff
changeset
 | 
106  | 
fun prepare prep_vars parse_prop prep_att do_close raw_vars raw_specss ctxt =  | 
| 
18620
 
fc8b5f275359
Theory specifications --- with type-inference, but no internal polymorphism.
 
wenzelm 
parents:  
diff
changeset
 | 
107  | 
let  | 
| 18670 | 108  | 
val thy = ProofContext.theory_of ctxt;  | 
| 
18620
 
fc8b5f275359
Theory specifications --- with type-inference, but no internal polymorphism.
 
wenzelm 
parents:  
diff
changeset
 | 
109  | 
|
| 18670 | 110  | 
val (vars, vars_ctxt) = ctxt |> prep_vars raw_vars;  | 
| 
30763
 
6976521b4263
renamed ProofContext.add_fixes_i to ProofContext.add_fixes, eliminated obsolete external version;
 
wenzelm 
parents: 
30761 
diff
changeset
 | 
111  | 
val (xs, params_ctxt) = vars_ctxt |> ProofContext.add_fixes vars;  | 
| 
18620
 
fc8b5f275359
Theory specifications --- with type-inference, but no internal polymorphism.
 
wenzelm 
parents:  
diff
changeset
 | 
112  | 
|
| 
24724
 
0df74bb87a13
read/check_specification: proper type inference across multiple sections, result is in closed form;
 
wenzelm 
parents: 
24676 
diff
changeset
 | 
113  | 
val Asss = (map o map) (map (parse_prop params_ctxt) o snd) raw_specss;  | 
| 24734 | 114  | 
val names = Variable.names_of (params_ctxt |> (fold o fold o fold) Variable.declare_term Asss)  | 
115  | 
|> fold Name.declare xs;  | 
|
116  | 
val Asss' = #1 ((fold_map o fold_map o fold_map) Term.free_dummy_patterns Asss names);  | 
|
117  | 
val idx = (fold o fold o fold) Term.maxidx_term Asss' ~1 + 1;  | 
|
| 
24724
 
0df74bb87a13
read/check_specification: proper type inference across multiple sections, result is in closed form;
 
wenzelm 
parents: 
24676 
diff
changeset
 | 
118  | 
val specs =  | 
| 
 
0df74bb87a13
read/check_specification: proper type inference across multiple sections, result is in closed form;
 
wenzelm 
parents: 
24676 
diff
changeset
 | 
119  | 
(if do_close then  | 
| 24734 | 120  | 
#1 (fold_map  | 
121  | 
(fn Ass => fn i => (burrow (close_forms params_ctxt i []) Ass, i + 1)) Asss' idx)  | 
|
122  | 
else Asss')  | 
|
| 
24724
 
0df74bb87a13
read/check_specification: proper type inference across multiple sections, result is in closed form;
 
wenzelm 
parents: 
24676 
diff
changeset
 | 
123  | 
|> flat |> burrow (Syntax.check_props params_ctxt);  | 
| 
 
0df74bb87a13
read/check_specification: proper type inference across multiple sections, result is in closed form;
 
wenzelm 
parents: 
24676 
diff
changeset
 | 
124  | 
val specs_ctxt = params_ctxt |> (fold o fold) Variable.declare_term specs;  | 
| 
 
0df74bb87a13
read/check_specification: proper type inference across multiple sections, result is in closed form;
 
wenzelm 
parents: 
24676 
diff
changeset
 | 
125  | 
|
| 
28080
 
4723eb2456ce
explicit type Name.binding for higher-specification elements;
 
wenzelm 
parents: 
27858 
diff
changeset
 | 
126  | 
val Ts = specs_ctxt |> fold_map ProofContext.inferred_param xs |> fst;  | 
| 
 
4723eb2456ce
explicit type Name.binding for higher-specification elements;
 
wenzelm 
parents: 
27858 
diff
changeset
 | 
127  | 
val params = map2 (fn (b, _, mx) => fn T => ((b, T), mx)) vars Ts;  | 
| 
24724
 
0df74bb87a13
read/check_specification: proper type inference across multiple sections, result is in closed form;
 
wenzelm 
parents: 
24676 
diff
changeset
 | 
128  | 
val name_atts = map (fn ((name, atts), _) => (name, map (prep_att thy) atts)) (flat raw_specss);  | 
| 
 
0df74bb87a13
read/check_specification: proper type inference across multiple sections, result is in closed form;
 
wenzelm 
parents: 
24676 
diff
changeset
 | 
129  | 
in ((params, name_atts ~~ specs), specs_ctxt) end;  | 
| 
 
0df74bb87a13
read/check_specification: proper type inference across multiple sections, result is in closed form;
 
wenzelm 
parents: 
24676 
diff
changeset
 | 
130  | 
|
| 
30482
 
6e3c92de4a7d
simplified versions check_spec, read_spec, check_free_spec, read_free_spec: operate on list of singleton statements;
 
wenzelm 
parents: 
30472 
diff
changeset
 | 
131  | 
|
| 
 
6e3c92de4a7d
simplified versions check_spec, read_spec, check_free_spec, read_free_spec: operate on list of singleton statements;
 
wenzelm 
parents: 
30472 
diff
changeset
 | 
132  | 
fun single_spec (a, prop) = [(a, [prop])];  | 
| 
 
6e3c92de4a7d
simplified versions check_spec, read_spec, check_free_spec, read_free_spec: operate on list of singleton statements;
 
wenzelm 
parents: 
30472 
diff
changeset
 | 
133  | 
fun the_spec (a, [prop]) = (a, prop);  | 
| 
 
6e3c92de4a7d
simplified versions check_spec, read_spec, check_free_spec, read_free_spec: operate on list of singleton statements;
 
wenzelm 
parents: 
30472 
diff
changeset
 | 
134  | 
|
| 
 
6e3c92de4a7d
simplified versions check_spec, read_spec, check_free_spec, read_free_spec: operate on list of singleton statements;
 
wenzelm 
parents: 
30472 
diff
changeset
 | 
135  | 
fun prep_spec prep_vars parse_prop prep_att do_close vars specs =  | 
| 
 
6e3c92de4a7d
simplified versions check_spec, read_spec, check_free_spec, read_free_spec: operate on list of singleton statements;
 
wenzelm 
parents: 
30472 
diff
changeset
 | 
136  | 
prepare prep_vars parse_prop prep_att do_close  | 
| 
 
6e3c92de4a7d
simplified versions check_spec, read_spec, check_free_spec, read_free_spec: operate on list of singleton statements;
 
wenzelm 
parents: 
30472 
diff
changeset
 | 
137  | 
vars (map single_spec specs) #>> apsnd (map the_spec);  | 
| 
 
6e3c92de4a7d
simplified versions check_spec, read_spec, check_free_spec, read_free_spec: operate on list of singleton statements;
 
wenzelm 
parents: 
30472 
diff
changeset
 | 
138  | 
|
| 
 
6e3c92de4a7d
simplified versions check_spec, read_spec, check_free_spec, read_free_spec: operate on list of singleton statements;
 
wenzelm 
parents: 
30472 
diff
changeset
 | 
139  | 
fun prep_specification prep_vars parse_prop prep_att vars specs =  | 
| 
 
6e3c92de4a7d
simplified versions check_spec, read_spec, check_free_spec, read_free_spec: operate on list of singleton statements;
 
wenzelm 
parents: 
30472 
diff
changeset
 | 
140  | 
prepare prep_vars parse_prop prep_att true [specs];  | 
| 
18620
 
fc8b5f275359
Theory specifications --- with type-inference, but no internal polymorphism.
 
wenzelm 
parents:  
diff
changeset
 | 
141  | 
|
| 
24724
 
0df74bb87a13
read/check_specification: proper type inference across multiple sections, result is in closed form;
 
wenzelm 
parents: 
24676 
diff
changeset
 | 
142  | 
in  | 
| 
21370
 
d9dd7b4e5e69
replaced Variable.fix_frees by Variable.auto_fixes (depends on body mode);
 
wenzelm 
parents: 
21359 
diff
changeset
 | 
143  | 
|
| 
30482
 
6e3c92de4a7d
simplified versions check_spec, read_spec, check_free_spec, read_free_spec: operate on list of singleton statements;
 
wenzelm 
parents: 
30472 
diff
changeset
 | 
144  | 
fun check_spec x = prep_spec ProofContext.cert_vars (K I) (K I) true x;  | 
| 
 
6e3c92de4a7d
simplified versions check_spec, read_spec, check_free_spec, read_free_spec: operate on list of singleton statements;
 
wenzelm 
parents: 
30472 
diff
changeset
 | 
145  | 
fun read_spec x = prep_spec ProofContext.read_vars Syntax.parse_prop Attrib.intern_src true x;  | 
| 
 
6e3c92de4a7d
simplified versions check_spec, read_spec, check_free_spec, read_free_spec: operate on list of singleton statements;
 
wenzelm 
parents: 
30472 
diff
changeset
 | 
146  | 
|
| 
 
6e3c92de4a7d
simplified versions check_spec, read_spec, check_free_spec, read_free_spec: operate on list of singleton statements;
 
wenzelm 
parents: 
30472 
diff
changeset
 | 
147  | 
fun check_free_spec x = prep_spec ProofContext.cert_vars (K I) (K I) false x;  | 
| 
 
6e3c92de4a7d
simplified versions check_spec, read_spec, check_free_spec, read_free_spec: operate on list of singleton statements;
 
wenzelm 
parents: 
30472 
diff
changeset
 | 
148  | 
fun read_free_spec x = prep_spec ProofContext.read_vars Syntax.parse_prop Attrib.intern_src false x;  | 
| 
 
6e3c92de4a7d
simplified versions check_spec, read_spec, check_free_spec, read_free_spec: operate on list of singleton statements;
 
wenzelm 
parents: 
30472 
diff
changeset
 | 
149  | 
|
| 
 
6e3c92de4a7d
simplified versions check_spec, read_spec, check_free_spec, read_free_spec: operate on list of singleton statements;
 
wenzelm 
parents: 
30472 
diff
changeset
 | 
150  | 
fun check_specification vars specs =  | 
| 
 
6e3c92de4a7d
simplified versions check_spec, read_spec, check_free_spec, read_free_spec: operate on list of singleton statements;
 
wenzelm 
parents: 
30472 
diff
changeset
 | 
151  | 
prepare ProofContext.cert_vars (K I) (K I) true vars [specs];  | 
| 
 
6e3c92de4a7d
simplified versions check_spec, read_spec, check_free_spec, read_free_spec: operate on list of singleton statements;
 
wenzelm 
parents: 
30472 
diff
changeset
 | 
152  | 
|
| 
 
6e3c92de4a7d
simplified versions check_spec, read_spec, check_free_spec, read_free_spec: operate on list of singleton statements;
 
wenzelm 
parents: 
30472 
diff
changeset
 | 
153  | 
fun read_specification vars specs =  | 
| 
 
6e3c92de4a7d
simplified versions check_spec, read_spec, check_free_spec, read_free_spec: operate on list of singleton statements;
 
wenzelm 
parents: 
30472 
diff
changeset
 | 
154  | 
prepare ProofContext.read_vars Syntax.parse_prop Attrib.intern_src true vars [specs];  | 
| 
24724
 
0df74bb87a13
read/check_specification: proper type inference across multiple sections, result is in closed form;
 
wenzelm 
parents: 
24676 
diff
changeset
 | 
155  | 
|
| 
 
0df74bb87a13
read/check_specification: proper type inference across multiple sections, result is in closed form;
 
wenzelm 
parents: 
24676 
diff
changeset
 | 
156  | 
end;  | 
| 
18620
 
fc8b5f275359
Theory specifications --- with type-inference, but no internal polymorphism.
 
wenzelm 
parents:  
diff
changeset
 | 
157  | 
|
| 
 
fc8b5f275359
Theory specifications --- with type-inference, but no internal polymorphism.
 
wenzelm 
parents:  
diff
changeset
 | 
158  | 
|
| 28114 | 159  | 
(* axiomatization -- within global theory *)  | 
| 
18620
 
fc8b5f275359
Theory specifications --- with type-inference, but no internal polymorphism.
 
wenzelm 
parents:  
diff
changeset
 | 
160  | 
|
| 28114 | 161  | 
fun gen_axioms do_print prep raw_vars raw_specs thy =  | 
| 
18620
 
fc8b5f275359
Theory specifications --- with type-inference, but no internal polymorphism.
 
wenzelm 
parents:  
diff
changeset
 | 
162  | 
let  | 
| 
30482
 
6e3c92de4a7d
simplified versions check_spec, read_spec, check_free_spec, read_free_spec: operate on list of singleton statements;
 
wenzelm 
parents: 
30472 
diff
changeset
 | 
163  | 
val ((vars, specs), _) = prep raw_vars raw_specs (ProofContext.init thy);  | 
| 
30585
 
6b2ba4666336
use Name.of_binding for basic logical entities without name space (fixes, case names etc.);
 
wenzelm 
parents: 
30482 
diff
changeset
 | 
164  | 
val xs = map (fn ((b, T), _) => (Name.of_binding b, T)) vars;  | 
| 28114 | 165  | 
|
166  | 
(*consts*)  | 
|
167  | 
val (consts, consts_thy) = thy |> fold_map (Theory.specify_const []) vars;  | 
|
168  | 
val subst = Term.subst_atomic (map Free xs ~~ consts);  | 
|
169  | 
||
170  | 
(*axioms*)  | 
|
| 
30470
 
9ae8f9d78cd3
axiomatization: more precise treatment of binding;
 
wenzelm 
parents: 
30434 
diff
changeset
 | 
171  | 
val (axioms, axioms_thy) = (specs, consts_thy) |-> fold_map (fn ((b, atts), props) =>  | 
| 
 
9ae8f9d78cd3
axiomatization: more precise treatment of binding;
 
wenzelm 
parents: 
30434 
diff
changeset
 | 
172  | 
fold_map Thm.add_axiom  | 
| 
 
9ae8f9d78cd3
axiomatization: more precise treatment of binding;
 
wenzelm 
parents: 
30434 
diff
changeset
 | 
173  | 
(map (apfst (fn a => Binding.map_name (K a) b))  | 
| 
30585
 
6b2ba4666336
use Name.of_binding for basic logical entities without name space (fixes, case names etc.);
 
wenzelm 
parents: 
30482 
diff
changeset
 | 
174  | 
(PureThy.name_multi (Name.of_binding b) (map subst props)))  | 
| 
30470
 
9ae8f9d78cd3
axiomatization: more precise treatment of binding;
 
wenzelm 
parents: 
30434 
diff
changeset
 | 
175  | 
#>> (fn ths => ((b, atts), [(map Drule.standard' ths, [])])));  | 
| 
 
9ae8f9d78cd3
axiomatization: more precise treatment of binding;
 
wenzelm 
parents: 
30434 
diff
changeset
 | 
176  | 
|
| 
 
9ae8f9d78cd3
axiomatization: more precise treatment of binding;
 
wenzelm 
parents: 
30434 
diff
changeset
 | 
177  | 
(*facts*)  | 
| 28114 | 178  | 
val (facts, thy') = axioms_thy |> PureThy.note_thmss Thm.axiomK  | 
179  | 
(Attrib.map_facts (Attrib.attribute_i axioms_thy) axioms);  | 
|
| 
30470
 
9ae8f9d78cd3
axiomatization: more precise treatment of binding;
 
wenzelm 
parents: 
30434 
diff
changeset
 | 
180  | 
|
| 26595 | 181  | 
val _ =  | 
182  | 
if not do_print then ()  | 
|
| 28114 | 183  | 
else print_consts (ProofContext.init thy') (K false) xs;  | 
184  | 
in ((consts, facts), thy') end;  | 
|
| 18786 | 185  | 
|
| 26595 | 186  | 
val axiomatization = gen_axioms false check_specification;  | 
187  | 
val axiomatization_cmd = gen_axioms true read_specification;  | 
|
| 
18620
 
fc8b5f275359
Theory specifications --- with type-inference, but no internal polymorphism.
 
wenzelm 
parents:  
diff
changeset
 | 
188  | 
|
| 18786 | 189  | 
|
190  | 
(* definition *)  | 
|
191  | 
||
| 
30482
 
6e3c92de4a7d
simplified versions check_spec, read_spec, check_free_spec, read_free_spec: operate on list of singleton statements;
 
wenzelm 
parents: 
30472 
diff
changeset
 | 
192  | 
fun gen_def do_print prep (raw_var, raw_spec) lthy =  | 
| 18786 | 193  | 
let  | 
| 
30482
 
6e3c92de4a7d
simplified versions check_spec, read_spec, check_free_spec, read_free_spec: operate on list of singleton statements;
 
wenzelm 
parents: 
30472 
diff
changeset
 | 
194  | 
val (vars, [((raw_name, atts), prop)]) = fst (prep (the_list raw_var) [raw_spec] lthy);  | 
| 21705 | 195  | 
val (((x, T), rhs), prove) = LocalDefs.derived_def lthy true prop;  | 
| 30434 | 196  | 
val var as (b, _) =  | 
| 
28080
 
4723eb2456ce
explicit type Name.binding for higher-specification elements;
 
wenzelm 
parents: 
27858 
diff
changeset
 | 
197  | 
(case vars of  | 
| 28965 | 198  | 
[] => (Binding.name x, NoSyn)  | 
| 
28080
 
4723eb2456ce
explicit type Name.binding for higher-specification elements;
 
wenzelm 
parents: 
27858 
diff
changeset
 | 
199  | 
| [((b, _), mx)] =>  | 
| 
 
4723eb2456ce
explicit type Name.binding for higher-specification elements;
 
wenzelm 
parents: 
27858 
diff
changeset
 | 
200  | 
let  | 
| 
30585
 
6b2ba4666336
use Name.of_binding for basic logical entities without name space (fixes, case names etc.);
 
wenzelm 
parents: 
30482 
diff
changeset
 | 
201  | 
val y = Name.of_binding b;  | 
| 
28080
 
4723eb2456ce
explicit type Name.binding for higher-specification elements;
 
wenzelm 
parents: 
27858 
diff
changeset
 | 
202  | 
val _ = x = y orelse  | 
| 
 
4723eb2456ce
explicit type Name.binding for higher-specification elements;
 
wenzelm 
parents: 
27858 
diff
changeset
 | 
203  | 
              error ("Head of definition " ^ quote x ^ " differs from declaration " ^ quote y ^
 | 
| 28941 | 204  | 
Position.str_of (Binding.pos_of b));  | 
| 
28080
 
4723eb2456ce
explicit type Name.binding for higher-specification elements;
 
wenzelm 
parents: 
27858 
diff
changeset
 | 
205  | 
in (b, mx) end);  | 
| 30434 | 206  | 
val name = Thm.def_binding_optional b raw_name;  | 
207  | 
val ((lhs, (_, th)), lthy2) = lthy  | 
|
208  | 
|> LocalTheory.define Thm.definitionK  | 
|
| 
30344
 
10a67c5ddddb
more uniform handling of binding in targets and derived elements;
 
wenzelm 
parents: 
30223 
diff
changeset
 | 
209  | 
(var, ((Binding.suffix_name "_raw" name, []), rhs));  | 
| 30434 | 210  | 
val ((def_name, [th']), lthy3) = lthy2  | 
211  | 
|> LocalTheory.note Thm.definitionK  | 
|
| 28703 | 212  | 
((name, Code.add_default_eqn_attrib :: atts), [prove lthy2 th]);  | 
| 18786 | 213  | 
|
| 21705 | 214  | 
val lhs' = Morphism.term (LocalTheory.target_morphism lthy3) lhs;  | 
| 26595 | 215  | 
val _ =  | 
216  | 
if not do_print then ()  | 
|
217  | 
else print_consts lthy3 (member (op =) (Term.add_frees lhs' [])) [(x, T)];  | 
|
| 
28080
 
4723eb2456ce
explicit type Name.binding for higher-specification elements;
 
wenzelm 
parents: 
27858 
diff
changeset
 | 
218  | 
in ((lhs, (def_name, th')), lthy3) end;  | 
| 18786 | 219  | 
|
| 
30482
 
6e3c92de4a7d
simplified versions check_spec, read_spec, check_free_spec, read_free_spec: operate on list of singleton statements;
 
wenzelm 
parents: 
30472 
diff
changeset
 | 
220  | 
val definition = gen_def false check_free_spec;  | 
| 
 
6e3c92de4a7d
simplified versions check_spec, read_spec, check_free_spec, read_free_spec: operate on list of singleton statements;
 
wenzelm 
parents: 
30472 
diff
changeset
 | 
221  | 
val definition_cmd = gen_def true read_free_spec;  | 
| 18786 | 222  | 
|
| 19080 | 223  | 
|
224  | 
(* abbreviation *)  | 
|
225  | 
||
| 26595 | 226  | 
fun gen_abbrev do_print prep mode (raw_var, raw_prop) lthy =  | 
| 19080 | 227  | 
let  | 
| 
30482
 
6e3c92de4a7d
simplified versions check_spec, read_spec, check_free_spec, read_free_spec: operate on list of singleton statements;
 
wenzelm 
parents: 
30472 
diff
changeset
 | 
228  | 
val ((vars, [(_, prop)]), _) =  | 
| 
 
6e3c92de4a7d
simplified versions check_spec, read_spec, check_free_spec, read_free_spec: operate on list of singleton statements;
 
wenzelm 
parents: 
30472 
diff
changeset
 | 
229  | 
prep (the_list raw_var) [(Attrib.empty_binding, raw_prop)]  | 
| 24676 | 230  | 
(lthy |> ProofContext.set_mode ProofContext.mode_abbrev);  | 
| 21705 | 231  | 
val ((x, T), rhs) = LocalDefs.abs_def (#2 (LocalDefs.cert_def lthy prop));  | 
| 
28080
 
4723eb2456ce
explicit type Name.binding for higher-specification elements;
 
wenzelm 
parents: 
27858 
diff
changeset
 | 
232  | 
val var =  | 
| 
 
4723eb2456ce
explicit type Name.binding for higher-specification elements;
 
wenzelm 
parents: 
27858 
diff
changeset
 | 
233  | 
(case vars of  | 
| 28965 | 234  | 
[] => (Binding.name x, NoSyn)  | 
| 
28080
 
4723eb2456ce
explicit type Name.binding for higher-specification elements;
 
wenzelm 
parents: 
27858 
diff
changeset
 | 
235  | 
| [((b, _), mx)] =>  | 
| 
 
4723eb2456ce
explicit type Name.binding for higher-specification elements;
 
wenzelm 
parents: 
27858 
diff
changeset
 | 
236  | 
let  | 
| 
30585
 
6b2ba4666336
use Name.of_binding for basic logical entities without name space (fixes, case names etc.);
 
wenzelm 
parents: 
30482 
diff
changeset
 | 
237  | 
val y = Name.of_binding b;  | 
| 
28080
 
4723eb2456ce
explicit type Name.binding for higher-specification elements;
 
wenzelm 
parents: 
27858 
diff
changeset
 | 
238  | 
val _ = x = y orelse  | 
| 
 
4723eb2456ce
explicit type Name.binding for higher-specification elements;
 
wenzelm 
parents: 
27858 
diff
changeset
 | 
239  | 
              error ("Head of abbreviation " ^ quote x ^ " differs from declaration " ^ quote y ^
 | 
| 28941 | 240  | 
Position.str_of (Binding.pos_of b));  | 
| 
28080
 
4723eb2456ce
explicit type Name.binding for higher-specification elements;
 
wenzelm 
parents: 
27858 
diff
changeset
 | 
241  | 
in (b, mx) end);  | 
| 21705 | 242  | 
val lthy' = lthy  | 
| 24986 | 243  | 
|> ProofContext.set_syntax_mode mode (* FIXME ?!? *)  | 
| 
28080
 
4723eb2456ce
explicit type Name.binding for higher-specification elements;
 
wenzelm 
parents: 
27858 
diff
changeset
 | 
244  | 
|> LocalTheory.abbrev mode (var, rhs) |> snd  | 
| 21705 | 245  | 
|> ProofContext.restore_syntax_mode lthy;  | 
| 
24724
 
0df74bb87a13
read/check_specification: proper type inference across multiple sections, result is in closed form;
 
wenzelm 
parents: 
24676 
diff
changeset
 | 
246  | 
|
| 26595 | 247  | 
val _ = if not do_print then () else print_consts lthy' (K false) [(x, T)];  | 
| 21532 | 248  | 
in lthy' end;  | 
| 19080 | 249  | 
|
| 
30482
 
6e3c92de4a7d
simplified versions check_spec, read_spec, check_free_spec, read_free_spec: operate on list of singleton statements;
 
wenzelm 
parents: 
30472 
diff
changeset
 | 
250  | 
val abbreviation = gen_abbrev false check_free_spec;  | 
| 
 
6e3c92de4a7d
simplified versions check_spec, read_spec, check_free_spec, read_free_spec: operate on list of singleton statements;
 
wenzelm 
parents: 
30472 
diff
changeset
 | 
251  | 
val abbreviation_cmd = gen_abbrev true read_free_spec;  | 
| 19080 | 252  | 
|
| 19664 | 253  | 
|
| 
21230
 
abfdce60b371
theorem statements: incorporate Obtain.statement, tuned;
 
wenzelm 
parents: 
21206 
diff
changeset
 | 
254  | 
(* notation *)  | 
| 19664 | 255  | 
|
| 24949 | 256  | 
fun gen_notation prep_const add mode args lthy =  | 
| 
25371
 
26d349416c4f
notation: improved ProofContext.read_const does the job;
 
wenzelm 
parents: 
25211 
diff
changeset
 | 
257  | 
lthy |> LocalTheory.notation add mode (map (apfst (prep_const lthy)) args);  | 
| 19664 | 258  | 
|
| 
24927
 
48e08f37ce92
Specification: renamed XXX_i to XXX, and XXX to XXX_cmd;
 
wenzelm 
parents: 
24848 
diff
changeset
 | 
259  | 
val notation = gen_notation (K I);  | 
| 
 
48e08f37ce92
Specification: renamed XXX_i to XXX, and XXX to XXX_cmd;
 
wenzelm 
parents: 
24848 
diff
changeset
 | 
260  | 
val notation_cmd = gen_notation ProofContext.read_const;  | 
| 19664 | 261  | 
|
| 20914 | 262  | 
|
| 21036 | 263  | 
(* fact statements *)  | 
| 20914 | 264  | 
|
| 
26345
 
f70620a4cf81
renamed former get_thms(_silent) to get_fact(_silent);
 
wenzelm 
parents: 
26336 
diff
changeset
 | 
265  | 
fun gen_theorems prep_fact prep_att kind raw_facts lthy =  | 
| 20914 | 266  | 
let  | 
267  | 
val attrib = prep_att (ProofContext.theory_of lthy);  | 
|
268  | 
val facts = raw_facts |> map (fn ((name, atts), bs) =>  | 
|
269  | 
((name, map attrib atts),  | 
|
| 
26345
 
f70620a4cf81
renamed former get_thms(_silent) to get_fact(_silent);
 
wenzelm 
parents: 
26336 
diff
changeset
 | 
270  | 
bs |> map (fn (b, more_atts) => (prep_fact lthy b, map attrib more_atts))));  | 
| 21435 | 271  | 
val (res, lthy') = lthy |> LocalTheory.notes kind facts;  | 
| 28093 | 272  | 
val _ = ProofDisplay.print_results true lthy' ((kind, ""), res);  | 
| 20914 | 273  | 
in (res, lthy') end;  | 
274  | 
||
| 
24927
 
48e08f37ce92
Specification: renamed XXX_i to XXX, and XXX to XXX_cmd;
 
wenzelm 
parents: 
24848 
diff
changeset
 | 
275  | 
val theorems = gen_theorems (K I) (K I);  | 
| 
26345
 
f70620a4cf81
renamed former get_thms(_silent) to get_fact(_silent);
 
wenzelm 
parents: 
26336 
diff
changeset
 | 
276  | 
val theorems_cmd = gen_theorems ProofContext.get_fact Attrib.intern_src;  | 
| 20914 | 277  | 
|
| 21036 | 278  | 
|
| 
21230
 
abfdce60b371
theorem statements: incorporate Obtain.statement, tuned;
 
wenzelm 
parents: 
21206 
diff
changeset
 | 
279  | 
(* complex goal statements *)  | 
| 21036 | 280  | 
|
281  | 
local  | 
|
282  | 
||
| 21236 | 283  | 
fun prep_statement prep_att prep_stmt elems concl ctxt =  | 
284  | 
(case concl of  | 
|
285  | 
Element.Shows shows =>  | 
|
| 
21230
 
abfdce60b371
theorem statements: incorporate Obtain.statement, tuned;
 
wenzelm 
parents: 
21206 
diff
changeset
 | 
286  | 
let  | 
| 28880 | 287  | 
val (propp, elems_ctxt) = prep_stmt elems (map snd shows) ctxt;  | 
| 30472 | 288  | 
val prems = Assumption.local_prems_of elems_ctxt ctxt;  | 
| 21450 | 289  | 
val stmt = Attrib.map_specs prep_att (map fst shows ~~ propp);  | 
| 
21370
 
d9dd7b4e5e69
replaced Variable.fix_frees by Variable.auto_fixes (depends on body mode);
 
wenzelm 
parents: 
21359 
diff
changeset
 | 
290  | 
val goal_ctxt = fold (fold (Variable.auto_fixes o fst)) propp elems_ctxt;  | 
| 21450 | 291  | 
in ((prems, stmt, []), goal_ctxt) end  | 
| 21236 | 292  | 
| Element.Obtains obtains =>  | 
| 
21230
 
abfdce60b371
theorem statements: incorporate Obtain.statement, tuned;
 
wenzelm 
parents: 
21206 
diff
changeset
 | 
293  | 
let  | 
| 28862 | 294  | 
val case_names = obtains |> map_index (fn (i, (b, _)) =>  | 
| 
30585
 
6b2ba4666336
use Name.of_binding for basic logical entities without name space (fixes, case names etc.);
 
wenzelm 
parents: 
30482 
diff
changeset
 | 
295  | 
if Binding.is_empty b then string_of_int (i + 1) else Name.of_binding b);  | 
| 21236 | 296  | 
val constraints = obtains |> map (fn (_, (vars, _)) =>  | 
| 28710 | 297  | 
Element.Constrains  | 
| 
30585
 
6b2ba4666336
use Name.of_binding for basic logical entities without name space (fixes, case names etc.);
 
wenzelm 
parents: 
30482 
diff
changeset
 | 
298  | 
(vars |> map_filter (fn (x, SOME T) => SOME (Name.of_binding x, T) | _ => NONE)));  | 
| 21036 | 299  | 
|
| 21236 | 300  | 
val raw_propp = obtains |> map (fn (_, (_, props)) => map (rpair []) props);  | 
| 28880 | 301  | 
val (propp, elems_ctxt) = prep_stmt (elems @ constraints) raw_propp ctxt;  | 
| 21236 | 302  | 
|
303  | 
val thesis = ObjectLogic.fixed_judgment (ProofContext.theory_of ctxt) AutoBind.thesisN;  | 
|
| 21036 | 304  | 
|
| 21236 | 305  | 
fun assume_case ((name, (vars, _)), asms) ctxt' =  | 
306  | 
let  | 
|
| 
28080
 
4723eb2456ce
explicit type Name.binding for higher-specification elements;
 
wenzelm 
parents: 
27858 
diff
changeset
 | 
307  | 
val bs = map fst vars;  | 
| 
30585
 
6b2ba4666336
use Name.of_binding for basic logical entities without name space (fixes, case names etc.);
 
wenzelm 
parents: 
30482 
diff
changeset
 | 
308  | 
val xs = map Name.of_binding bs;  | 
| 21236 | 309  | 
val props = map fst asms;  | 
| 
28080
 
4723eb2456ce
explicit type Name.binding for higher-specification elements;
 
wenzelm 
parents: 
27858 
diff
changeset
 | 
310  | 
val (Ts, _) = ctxt'  | 
| 21236 | 311  | 
|> fold Variable.declare_term props  | 
312  | 
|> fold_map ProofContext.inferred_param xs;  | 
|
| 
28080
 
4723eb2456ce
explicit type Name.binding for higher-specification elements;
 
wenzelm 
parents: 
27858 
diff
changeset
 | 
313  | 
val asm = Term.list_all_free (xs ~~ Ts, Logic.list_implies (props, thesis));  | 
| 21236 | 314  | 
in  | 
| 
30763
 
6976521b4263
renamed ProofContext.add_fixes_i to ProofContext.add_fixes, eliminated obsolete external version;
 
wenzelm 
parents: 
30761 
diff
changeset
 | 
315  | 
ctxt' |> (snd o ProofContext.add_fixes (map (fn b => (b, NONE, NoSyn)) bs));  | 
| 
21370
 
d9dd7b4e5e69
replaced Variable.fix_frees by Variable.auto_fixes (depends on body mode);
 
wenzelm 
parents: 
21359 
diff
changeset
 | 
316  | 
ctxt' |> Variable.auto_fixes asm  | 
| 21236 | 317  | 
|> ProofContext.add_assms_i Assumption.assume_export  | 
318  | 
[((name, [ContextRules.intro_query NONE]), [(asm, [])])]  | 
|
319  | 
|>> (fn [(_, [th])] => th)  | 
|
320  | 
end;  | 
|
321  | 
||
| 21658 | 322  | 
val atts = map (Attrib.internal o K)  | 
| 21236 | 323  | 
[RuleCases.consumes (~ (length obtains)), RuleCases.case_names case_names];  | 
| 30472 | 324  | 
val prems = Assumption.local_prems_of elems_ctxt ctxt;  | 
| 28965 | 325  | 
val stmt = [((Binding.empty, atts), [(thesis, [])])];  | 
| 21236 | 326  | 
|
327  | 
val (facts, goal_ctxt) = elems_ctxt  | 
|
| 
30763
 
6976521b4263
renamed ProofContext.add_fixes_i to ProofContext.add_fixes, eliminated obsolete external version;
 
wenzelm 
parents: 
30761 
diff
changeset
 | 
328  | 
|> (snd o ProofContext.add_fixes [(Binding.name AutoBind.thesisN, NONE, NoSyn)])  | 
| 21236 | 329  | 
|> fold_map assume_case (obtains ~~ propp)  | 
| 
30761
 
ac7570d80c3d
renamed ProofContext.note_thmss_i to ProofContext.note_thmss, eliminated obsolete external version;
 
wenzelm 
parents: 
30585 
diff
changeset
 | 
330  | 
|-> (fn ths => ProofContext.note_thmss Thm.assumptionK  | 
| 28965 | 331  | 
[((Binding.name Obtain.thatN, []), [(ths, [])])] #> #2 #> pair ths);  | 
| 21450 | 332  | 
in ((prems, stmt, facts), goal_ctxt) end);  | 
| 21036 | 333  | 
|
| 
24452
 
93b113c5ac33
- theorem(_i) now also takes "interactive" flag as argument
 
berghofe 
parents: 
24219 
diff
changeset
 | 
334  | 
structure TheoremHook = GenericDataFun  | 
| 
 
93b113c5ac33
- theorem(_i) now also takes "interactive" flag as argument
 
berghofe 
parents: 
24219 
diff
changeset
 | 
335  | 
(  | 
| 
 
93b113c5ac33
- theorem(_i) now also takes "interactive" flag as argument
 
berghofe 
parents: 
24219 
diff
changeset
 | 
336  | 
type T = ((bool -> Proof.state -> Proof.state) * stamp) list;  | 
| 
 
93b113c5ac33
- theorem(_i) now also takes "interactive" flag as argument
 
berghofe 
parents: 
24219 
diff
changeset
 | 
337  | 
val empty = [];  | 
| 
 
93b113c5ac33
- theorem(_i) now also takes "interactive" flag as argument
 
berghofe 
parents: 
24219 
diff
changeset
 | 
338  | 
val extend = I;  | 
| 24464 | 339  | 
fun merge _ hooks : T = Library.merge (eq_snd op =) hooks;  | 
| 
24452
 
93b113c5ac33
- theorem(_i) now also takes "interactive" flag as argument
 
berghofe 
parents: 
24219 
diff
changeset
 | 
340  | 
);  | 
| 
 
93b113c5ac33
- theorem(_i) now also takes "interactive" flag as argument
 
berghofe 
parents: 
24219 
diff
changeset
 | 
341  | 
|
| 21036 | 342  | 
fun gen_theorem prep_att prep_stmt  | 
| 28858 | 343  | 
kind before_qed after_qed (name, raw_atts) raw_elems raw_concl int lthy =  | 
| 21036 | 344  | 
let  | 
| 28858 | 345  | 
val _ = LocalTheory.affirm lthy;  | 
346  | 
val thy = ProofContext.theory_of lthy;  | 
|
| 21036 | 347  | 
|
| 21435 | 348  | 
val attrib = prep_att thy;  | 
349  | 
val atts = map attrib raw_atts;  | 
|
| 28710 | 350  | 
val elems = raw_elems |> map (Element.map_ctxt_attrib attrib);  | 
| 21450 | 351  | 
val ((prems, stmt, facts), goal_ctxt) =  | 
| 28880 | 352  | 
prep_statement attrib prep_stmt elems raw_concl lthy;  | 
| 21036 | 353  | 
|
354  | 
fun after_qed' results goal_ctxt' =  | 
|
| 21602 | 355  | 
let val results' =  | 
356  | 
burrow (map Goal.norm_result o ProofContext.export goal_ctxt' lthy) results  | 
|
357  | 
in  | 
|
| 21036 | 358  | 
lthy  | 
| 21435 | 359  | 
|> LocalTheory.notes kind (map2 (fn (a, _) => fn ths => (a, [(ths, [])])) stmt results')  | 
| 21036 | 360  | 
|> (fn (res, lthy') =>  | 
| 28965 | 361  | 
if Binding.is_empty name andalso null atts then  | 
| 28093 | 362  | 
(ProofDisplay.print_results true lthy' ((kind, ""), res); lthy')  | 
| 
28080
 
4723eb2456ce
explicit type Name.binding for higher-specification elements;
 
wenzelm 
parents: 
27858 
diff
changeset
 | 
363  | 
else  | 
| 
 
4723eb2456ce
explicit type Name.binding for higher-specification elements;
 
wenzelm 
parents: 
27858 
diff
changeset
 | 
364  | 
let  | 
| 
 
4723eb2456ce
explicit type Name.binding for higher-specification elements;
 
wenzelm 
parents: 
27858 
diff
changeset
 | 
365  | 
val ([(res_name, _)], lthy'') = lthy'  | 
| 
 
4723eb2456ce
explicit type Name.binding for higher-specification elements;
 
wenzelm 
parents: 
27858 
diff
changeset
 | 
366  | 
|> LocalTheory.notes kind [((name, atts), [(maps #2 res, [])])];  | 
| 28093 | 367  | 
val _ = ProofDisplay.print_results true lthy' ((kind, res_name), res);  | 
| 
28080
 
4723eb2456ce
explicit type Name.binding for higher-specification elements;
 
wenzelm 
parents: 
27858 
diff
changeset
 | 
368  | 
in lthy'' end)  | 
| 21036 | 369  | 
|> after_qed results'  | 
370  | 
end;  | 
|
371  | 
in  | 
|
372  | 
goal_ctxt  | 
|
| 
30761
 
ac7570d80c3d
renamed ProofContext.note_thmss_i to ProofContext.note_thmss, eliminated obsolete external version;
 
wenzelm 
parents: 
30585 
diff
changeset
 | 
373  | 
|> ProofContext.note_thmss Thm.assumptionK  | 
| 28965 | 374  | 
[((Binding.name AutoBind.assmsN, []), [(prems, [])])]  | 
| 21450 | 375  | 
|> snd  | 
| 21435 | 376  | 
|> Proof.theorem_i before_qed after_qed' (map snd stmt)  | 
| 24557 | 377  | 
|> Proof.refine_insert facts  | 
| 24542 | 378  | 
|> Library.apply (map (fn (f, _) => f int) (rev (TheoremHook.get (Context.Proof goal_ctxt))))  | 
| 21036 | 379  | 
end;  | 
380  | 
||
| 
21230
 
abfdce60b371
theorem statements: incorporate Obtain.statement, tuned;
 
wenzelm 
parents: 
21206 
diff
changeset
 | 
381  | 
in  | 
| 
 
abfdce60b371
theorem statements: incorporate Obtain.statement, tuned;
 
wenzelm 
parents: 
21206 
diff
changeset
 | 
382  | 
|
| 29249 | 383  | 
val theorem = gen_theorem (K I) Expression.cert_statement;  | 
384  | 
val theorem_cmd = gen_theorem Attrib.intern_src Expression.read_statement;  | 
|
| 21036 | 385  | 
|
| 
24452
 
93b113c5ac33
- theorem(_i) now also takes "interactive" flag as argument
 
berghofe 
parents: 
24219 
diff
changeset
 | 
386  | 
fun add_theorem_hook f = TheoremHook.map (cons (f, stamp ()));  | 
| 
 
93b113c5ac33
- theorem(_i) now also takes "interactive" flag as argument
 
berghofe 
parents: 
24219 
diff
changeset
 | 
387  | 
|
| 
18620
 
fc8b5f275359
Theory specifications --- with type-inference, but no internal polymorphism.
 
wenzelm 
parents:  
diff
changeset
 | 
388  | 
end;  | 
| 21036 | 389  | 
|
390  | 
end;  |