| author | immler | 
| Mon, 13 Oct 2014 18:55:05 +0200 | |
| changeset 58656 | 7f14d5d9b933 | 
| parent 51717 | 9e7d1c139569 | 
| child 58811 | 19382bbfa93a | 
| permissions | -rw-r--r-- | 
| 35849 | 1  | 
(* Author: Clemens Ballarin  | 
| 21505 | 2  | 
|
3  | 
Normalisation method for locales ring and cring.  | 
|
| 13854 | 4  | 
*)  | 
5  | 
||
| 
20168
 
ed7bced29e1b
Reimplemented algebra method; now controlled by attribute.
 
ballarin 
parents: 
20129 
diff
changeset
 | 
6  | 
signature ALGEBRA =  | 
| 
 
ed7bced29e1b
Reimplemented algebra method; now controlled by attribute.
 
ballarin 
parents: 
20129 
diff
changeset
 | 
7  | 
sig  | 
| 21505 | 8  | 
val print_structures: Proof.context -> unit  | 
| 47701 | 9  | 
val attrib_setup: theory -> theory  | 
10  | 
val algebra_tac: Proof.context -> int -> tactic  | 
|
| 
20168
 
ed7bced29e1b
Reimplemented algebra method; now controlled by attribute.
 
ballarin 
parents: 
20129 
diff
changeset
 | 
11  | 
end;  | 
| 
 
ed7bced29e1b
Reimplemented algebra method; now controlled by attribute.
 
ballarin 
parents: 
20129 
diff
changeset
 | 
12  | 
|
| 
 
ed7bced29e1b
Reimplemented algebra method; now controlled by attribute.
 
ballarin 
parents: 
20129 
diff
changeset
 | 
13  | 
structure Algebra: ALGEBRA =  | 
| 
 
ed7bced29e1b
Reimplemented algebra method; now controlled by attribute.
 
ballarin 
parents: 
20129 
diff
changeset
 | 
14  | 
struct  | 
| 
 
ed7bced29e1b
Reimplemented algebra method; now controlled by attribute.
 
ballarin 
parents: 
20129 
diff
changeset
 | 
15  | 
|
| 
 
ed7bced29e1b
Reimplemented algebra method; now controlled by attribute.
 
ballarin 
parents: 
20129 
diff
changeset
 | 
16  | 
|
| 
 
ed7bced29e1b
Reimplemented algebra method; now controlled by attribute.
 
ballarin 
parents: 
20129 
diff
changeset
 | 
17  | 
(** Theory and context data **)  | 
| 
 
ed7bced29e1b
Reimplemented algebra method; now controlled by attribute.
 
ballarin 
parents: 
20129 
diff
changeset
 | 
18  | 
|
| 20547 | 19  | 
fun struct_eq ((s1: string, ts1), (s2, ts2)) =  | 
| 20348 | 20  | 
(s1 = s2) andalso eq_list (op aconv) (ts1, ts2);  | 
| 13854 | 21  | 
|
| 33519 | 22  | 
structure Data = Generic_Data  | 
| 22846 | 23  | 
(  | 
| 
20168
 
ed7bced29e1b
Reimplemented algebra method; now controlled by attribute.
 
ballarin 
parents: 
20129 
diff
changeset
 | 
24  | 
type T = ((string * term list) * thm list) list;  | 
| 
 
ed7bced29e1b
Reimplemented algebra method; now controlled by attribute.
 
ballarin 
parents: 
20129 
diff
changeset
 | 
25  | 
(* Algebraic structures:  | 
| 
 
ed7bced29e1b
Reimplemented algebra method; now controlled by attribute.
 
ballarin 
parents: 
20129 
diff
changeset
 | 
26  | 
identifier of the structure, list of operations and simp rules,  | 
| 
 
ed7bced29e1b
Reimplemented algebra method; now controlled by attribute.
 
ballarin 
parents: 
20129 
diff
changeset
 | 
27  | 
identifier and operations identify the structure uniquely. *)  | 
| 
 
ed7bced29e1b
Reimplemented algebra method; now controlled by attribute.
 
ballarin 
parents: 
20129 
diff
changeset
 | 
28  | 
val empty = [];  | 
| 
 
ed7bced29e1b
Reimplemented algebra method; now controlled by attribute.
 
ballarin 
parents: 
20129 
diff
changeset
 | 
29  | 
val extend = I;  | 
| 33520 | 30  | 
val merge = AList.join struct_eq (K Thm.merge_thms);  | 
| 22846 | 31  | 
);  | 
| 13854 | 32  | 
|
| 22846 | 33  | 
fun print_structures ctxt =  | 
34  | 
let  | 
|
35  | 
val structs = Data.get (Context.Proof ctxt);  | 
|
| 24920 | 36  | 
val pretty_term = Pretty.quote o Syntax.pretty_term ctxt;  | 
| 22846 | 37  | 
fun pretty_struct ((s, ts), _) = Pretty.block  | 
38  | 
[Pretty.str s, Pretty.str ":", Pretty.brk 1,  | 
|
39  | 
       Pretty.enclose "(" ")" (Pretty.breaks (map pretty_term ts))];
 | 
|
40  | 
in Pretty.writeln (Pretty.big_list "Algebraic structures:" (map pretty_struct structs)) end;  | 
|
| 13854 | 41  | 
|
| 
20168
 
ed7bced29e1b
Reimplemented algebra method; now controlled by attribute.
 
ballarin 
parents: 
20129 
diff
changeset
 | 
42  | 
|
| 
 
ed7bced29e1b
Reimplemented algebra method; now controlled by attribute.
 
ballarin 
parents: 
20129 
diff
changeset
 | 
43  | 
(** Method **)  | 
| 13854 | 44  | 
|
| 
51717
 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 
wenzelm 
parents: 
47701 
diff
changeset
 | 
45  | 
fun struct_tac ctxt ((s, ts), simps) =  | 
| 
20168
 
ed7bced29e1b
Reimplemented algebra method; now controlled by attribute.
 
ballarin 
parents: 
20129 
diff
changeset
 | 
46  | 
let  | 
| 
 
ed7bced29e1b
Reimplemented algebra method; now controlled by attribute.
 
ballarin 
parents: 
20129 
diff
changeset
 | 
47  | 
val ops = map (fst o Term.strip_comb) ts;  | 
| 
 
ed7bced29e1b
Reimplemented algebra method; now controlled by attribute.
 
ballarin 
parents: 
20129 
diff
changeset
 | 
48  | 
fun ord (Const (a, _)) = find_index (fn (Const (b, _)) => a=b | _ => false) ops  | 
| 
 
ed7bced29e1b
Reimplemented algebra method; now controlled by attribute.
 
ballarin 
parents: 
20129 
diff
changeset
 | 
49  | 
| ord (Free (a, _)) = find_index (fn (Free (b, _)) => a=b | _ => false) ops;  | 
| 35408 | 50  | 
fun less (a, b) = (Term_Ord.term_lpo ord (a, b) = LESS);  | 
| 
51717
 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 
wenzelm 
parents: 
47701 
diff
changeset
 | 
51  | 
in asm_full_simp_tac (put_simpset HOL_ss ctxt addsimps simps |> Simplifier.set_termless less) end;  | 
| 
20168
 
ed7bced29e1b
Reimplemented algebra method; now controlled by attribute.
 
ballarin 
parents: 
20129 
diff
changeset
 | 
52  | 
|
| 
 
ed7bced29e1b
Reimplemented algebra method; now controlled by attribute.
 
ballarin 
parents: 
20129 
diff
changeset
 | 
53  | 
fun algebra_tac ctxt =  | 
| 
51717
 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 
wenzelm 
parents: 
47701 
diff
changeset
 | 
54  | 
EVERY' (map (fn s => TRY o struct_tac ctxt s) (Data.get (Context.Proof ctxt)));  | 
| 
20168
 
ed7bced29e1b
Reimplemented algebra method; now controlled by attribute.
 
ballarin 
parents: 
20129 
diff
changeset
 | 
55  | 
|
| 
 
ed7bced29e1b
Reimplemented algebra method; now controlled by attribute.
 
ballarin 
parents: 
20129 
diff
changeset
 | 
56  | 
|
| 
 
ed7bced29e1b
Reimplemented algebra method; now controlled by attribute.
 
ballarin 
parents: 
20129 
diff
changeset
 | 
57  | 
(** Attribute **)  | 
| 
14399
 
dc677b35e54f
New lemmas about inversion of restricted functions.
 
ballarin 
parents: 
13936 
diff
changeset
 | 
58  | 
|
| 
20168
 
ed7bced29e1b
Reimplemented algebra method; now controlled by attribute.
 
ballarin 
parents: 
20129 
diff
changeset
 | 
59  | 
fun add_struct_thm s =  | 
| 22634 | 60  | 
Thm.declaration_attribute  | 
| 22846 | 61  | 
(fn thm => Data.map (AList.map_default struct_eq (s, []) (insert Thm.eq_thm_prop thm)));  | 
| 47701 | 62  | 
|
| 
20168
 
ed7bced29e1b
Reimplemented algebra method; now controlled by attribute.
 
ballarin 
parents: 
20129 
diff
changeset
 | 
63  | 
fun del_struct s =  | 
| 22634 | 64  | 
Thm.declaration_attribute  | 
| 22846 | 65  | 
(fn _ => Data.map (AList.delete struct_eq s));  | 
| 13854 | 66  | 
|
| 
30722
 
623d4831c8cf
simplified attribute and method setup: eliminating bottom-up styles makes it easier to keep things in one place, and also SML/NJ happy;
 
wenzelm 
parents: 
30528 
diff
changeset
 | 
67  | 
val attrib_setup =  | 
| 
 
623d4831c8cf
simplified attribute and method setup: eliminating bottom-up styles makes it easier to keep things in one place, and also SML/NJ happy;
 
wenzelm 
parents: 
30528 
diff
changeset
 | 
68  | 
  Attrib.setup @{binding algebra}
 | 
| 
 
623d4831c8cf
simplified attribute and method setup: eliminating bottom-up styles makes it easier to keep things in one place, and also SML/NJ happy;
 
wenzelm 
parents: 
30528 
diff
changeset
 | 
69  | 
(Scan.lift ((Args.add >> K true || Args.del >> K false) --| Args.colon || Scan.succeed true)  | 
| 
 
623d4831c8cf
simplified attribute and method setup: eliminating bottom-up styles makes it easier to keep things in one place, and also SML/NJ happy;
 
wenzelm 
parents: 
30528 
diff
changeset
 | 
70  | 
-- Scan.lift Args.name -- Scan.repeat Args.term  | 
| 
 
623d4831c8cf
simplified attribute and method setup: eliminating bottom-up styles makes it easier to keep things in one place, and also SML/NJ happy;
 
wenzelm 
parents: 
30528 
diff
changeset
 | 
71  | 
>> (fn ((b, n), ts) => if b then add_struct_thm (n, ts) else del_struct (n, ts)))  | 
| 
 
623d4831c8cf
simplified attribute and method setup: eliminating bottom-up styles makes it easier to keep things in one place, and also SML/NJ happy;
 
wenzelm 
parents: 
30528 
diff
changeset
 | 
72  | 
"theorems controlling algebra method";  | 
| 
 
623d4831c8cf
simplified attribute and method setup: eliminating bottom-up styles makes it easier to keep things in one place, and also SML/NJ happy;
 
wenzelm 
parents: 
30528 
diff
changeset
 | 
73  | 
|
| 21505 | 74  | 
end;  |