author | wenzelm |
Thu, 08 Aug 2024 22:49:40 +0200 | |
changeset 80677 | 6fedd6d3fa41 |
parent 80675 | e9beaa28645d |
child 80687 | 9b29c5d7aae4 |
permissions | -rw-r--r-- |
37744 | 1 |
(* Title: HOL/Tools/Quotient/quotient_term.ML |
35222
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
2 |
Author: Cezary Kaliszyk and Christian Urban |
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
3 |
|
35788 | 4 |
Constructs terms corresponding to goals from lifting theorems to |
5 |
quotient types. |
|
35222
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
6 |
*) |
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
7 |
|
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
8 |
signature QUOTIENT_TERM = |
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
9 |
sig |
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
10 |
exception LIFT_MATCH of string |
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
11 |
|
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
12 |
datatype flag = AbsF | RepF |
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
13 |
|
45797 | 14 |
val absrep_fun: Proof.context -> flag -> typ * typ -> term |
15 |
val absrep_fun_chk: Proof.context -> flag -> typ * typ -> term |
|
35222
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
16 |
|
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
17 |
(* Allows Nitpick to represent quotient types as single elements from raw type *) |
45797 | 18 |
val absrep_const_chk: Proof.context -> flag -> string -> term |
35222
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
19 |
|
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
20 |
val equiv_relation: Proof.context -> typ * typ -> term |
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
21 |
val equiv_relation_chk: Proof.context -> typ * typ -> term |
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
22 |
|
47096
3ea48c19673e
generation of a code certificate from a respectfulness theorem for constants lifted by the quotient_definition command & setup_lifting command: setups Quotient infrastructure from a typedef theorem
kuncar
parents:
47095
diff
changeset
|
23 |
val get_rel_from_quot_thm: thm -> term |
47504
aa1b8a59017f
go back to the explicit compisition of quotient theorems
kuncar
parents:
47308
diff
changeset
|
24 |
val prove_quot_thm: Proof.context -> typ * typ -> thm |
47096
3ea48c19673e
generation of a code certificate from a respectfulness theorem for constants lifted by the quotient_definition command & setup_lifting command: setups Quotient infrastructure from a typedef theorem
kuncar
parents:
47095
diff
changeset
|
25 |
|
35222
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
26 |
val regularize_trm: Proof.context -> term * term -> term |
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
27 |
val regularize_trm_chk: Proof.context -> term * term -> term |
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
28 |
|
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
29 |
val inj_repabs_trm: Proof.context -> term * term -> term |
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
30 |
val inj_repabs_trm_chk: Proof.context -> term * term -> term |
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
31 |
|
38624
9bb0016f7e60
changed to a more convenient argument order
Christian Urban <urbanc@in.tum.de>
parents:
38558
diff
changeset
|
32 |
val derive_qtyp: Proof.context -> typ list -> typ -> typ |
9bb0016f7e60
changed to a more convenient argument order
Christian Urban <urbanc@in.tum.de>
parents:
38558
diff
changeset
|
33 |
val derive_qtrm: Proof.context -> typ list -> term -> term |
9bb0016f7e60
changed to a more convenient argument order
Christian Urban <urbanc@in.tum.de>
parents:
38558
diff
changeset
|
34 |
val derive_rtyp: Proof.context -> typ list -> typ -> typ |
9bb0016f7e60
changed to a more convenient argument order
Christian Urban <urbanc@in.tum.de>
parents:
38558
diff
changeset
|
35 |
val derive_rtrm: Proof.context -> typ list -> term -> term |
35222
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
36 |
end; |
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
37 |
|
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
38 |
structure Quotient_Term: QUOTIENT_TERM = |
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
39 |
struct |
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
40 |
|
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
41 |
exception LIFT_MATCH of string |
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
42 |
|
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
43 |
|
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
44 |
|
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
45 |
(*** Aggregate Rep/Abs Function ***) |
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
46 |
|
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
47 |
|
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
48 |
(* The flag RepF is for types in negative position; AbsF is for types |
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
49 |
in positive position. Because of this, function types need to be |
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
50 |
treated specially, since there the polarity changes. |
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
51 |
*) |
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
52 |
|
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
53 |
datatype flag = AbsF | RepF |
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
54 |
|
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
55 |
fun negF AbsF = RepF |
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
56 |
| negF RepF = AbsF |
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
57 |
|
80677 | 58 |
fun is_identity \<^Const_>\<open>id _\<close> = true |
35222
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
59 |
| is_identity _ = false |
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
60 |
|
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
61 |
fun mk_fun_compose flag (trm1, trm2) = |
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
62 |
case flag of |
69593 | 63 |
AbsF => Const (\<^const_name>\<open>comp\<close>, dummyT) $ trm1 $ trm2 |
64 |
| RepF => Const (\<^const_name>\<open>comp\<close>, dummyT) $ trm2 $ trm1 |
|
35222
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
65 |
|
45796 | 66 |
fun get_mapfun_data ctxt s = |
55467
a5c9002bc54d
renamed 'enriched_type' to more informative 'functor' (following the renaming of enriched type constructors to bounded natural functors)
blanchet
parents:
55414
diff
changeset
|
67 |
(case Symtab.lookup (Functor.entries ctxt) s of |
80636
4041e7c8059d
tuned: more explicit dest_Const_name and dest_Const_type;
wenzelm
parents:
74525
diff
changeset
|
68 |
SOME [map_data] => (case try dest_Const_name (#mapper map_data) of |
4041e7c8059d
tuned: more explicit dest_Const_name and dest_Const_type;
wenzelm
parents:
74525
diff
changeset
|
69 |
SOME c => (Const (c, dummyT), #variances map_data) |
45795
2d8949268303
maps are taken from enriched type infrastracture, rewritten lifting of constants, now we can lift even contravariant and co/contravariant types
kuncar
parents:
45628
diff
changeset
|
70 |
| NONE => raise LIFT_MATCH ("map function for type " ^ quote s ^ " is not a constant.")) |
2d8949268303
maps are taken from enriched type infrastracture, rewritten lifting of constants, now we can lift even contravariant and co/contravariant types
kuncar
parents:
45628
diff
changeset
|
71 |
| SOME _ => raise LIFT_MATCH ("map function for type " ^ quote s ^ " is non-singleton entry.") |
2d8949268303
maps are taken from enriched type infrastracture, rewritten lifting of constants, now we can lift even contravariant and co/contravariant types
kuncar
parents:
45628
diff
changeset
|
72 |
| NONE => raise LIFT_MATCH ("No map function for type " ^ quote s ^ " found.")) |
35222
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
73 |
|
55467
a5c9002bc54d
renamed 'enriched_type' to more informative 'functor' (following the renaming of enriched type constructors to bounded natural functors)
blanchet
parents:
55414
diff
changeset
|
74 |
fun defined_mapfun_data ctxt = Symtab.defined (Functor.entries ctxt) |
35222
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
75 |
|
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
76 |
(* looks up the (varified) rty and qty for |
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
77 |
a quotient definition |
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
78 |
*) |
45796 | 79 |
fun get_rty_qty ctxt s = |
80 |
let |
|
81 |
val thy = Proof_Context.theory_of ctxt |
|
82 |
in |
|
83 |
(case Quotient_Info.lookup_quotients_global thy s of |
|
67632 | 84 |
SOME {rtyp, qtyp, ...} => (rtyp, qtyp) |
45796 | 85 |
| NONE => raise LIFT_MATCH ("No quotient type " ^ quote s ^ " found.")) |
86 |
end |
|
35222
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
87 |
|
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
88 |
(* matches a type pattern with a type *) |
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
89 |
fun match ctxt err ty_pat ty = |
41444 | 90 |
let |
42361 | 91 |
val thy = Proof_Context.theory_of ctxt |
41444 | 92 |
in |
93 |
Sign.typ_match thy (ty_pat, ty) Vartab.empty |
|
94 |
handle Type.TYPE_MATCH => err ctxt ty_pat ty |
|
95 |
end |
|
35222
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
96 |
|
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
97 |
(* produces the rep or abs constant for a qty *) |
45797 | 98 |
fun absrep_const ctxt flag qty_str = |
41444 | 99 |
let |
45534
4ab21521b393
adding database of abs and rep terms to the quotient package; registering abs and rep terms in quotient_type and using them in quotient_definition
bulwahn
parents:
45340
diff
changeset
|
100 |
(* FIXME *) |
4ab21521b393
adding database of abs and rep terms to the quotient package; registering abs and rep terms in quotient_type and using them in quotient_definition
bulwahn
parents:
45340
diff
changeset
|
101 |
fun mk_dummyT (Const (c, _)) = Const (c, dummyT) |
45628
f21eb7073895
in a local context, also the free variable case needs to be analysed default tip
Christian Urban <urbanc@in.tum.de>
parents:
45534
diff
changeset
|
102 |
| mk_dummyT (Free (c, _)) = Free (c, dummyT) |
f21eb7073895
in a local context, also the free variable case needs to be analysed default tip
Christian Urban <urbanc@in.tum.de>
parents:
45534
diff
changeset
|
103 |
| mk_dummyT _ = error "Expecting abs/rep term to be a constant or a free variable" |
41444 | 104 |
in |
67632 | 105 |
(case Quotient_Info.lookup_abs_rep ctxt qty_str of |
106 |
SOME {abs, rep} => mk_dummyT (case flag of AbsF => abs | RepF => rep) |
|
107 |
| NONE => error ("No abs/rep terms for " ^ quote qty_str)) |
|
41444 | 108 |
end |
45534
4ab21521b393
adding database of abs and rep terms to the quotient package; registering abs and rep terms in quotient_type and using them in quotient_definition
bulwahn
parents:
45340
diff
changeset
|
109 |
|
35222
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
110 |
(* Lets Nitpick represent elements of quotient types as elements of the raw type *) |
45797 | 111 |
fun absrep_const_chk ctxt flag qty_str = |
112 |
Syntax.check_term ctxt (absrep_const ctxt flag qty_str) |
|
35222
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
113 |
|
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
114 |
fun absrep_match_err ctxt ty_pat ty = |
41444 | 115 |
let |
116 |
val ty_pat_str = Syntax.string_of_typ ctxt ty_pat |
|
117 |
val ty_str = Syntax.string_of_typ ctxt ty |
|
118 |
in |
|
119 |
raise LIFT_MATCH (space_implode " " |
|
120 |
["absrep_fun (Types ", quote ty_pat_str, "and", quote ty_str, " do not match.)"]) |
|
121 |
end |
|
35222
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
122 |
|
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
123 |
|
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
124 |
(** generation of an aggregate absrep function **) |
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
125 |
|
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
126 |
(* - In case of equal types we just return the identity. |
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
127 |
|
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
128 |
- In case of TFrees we also return the identity. |
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
129 |
|
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
130 |
- In case of function types we recurse taking |
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
131 |
the polarity change into account. |
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
132 |
|
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
133 |
- If the type constructors are equal, we recurse for the |
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
134 |
arguments and build the appropriate map function. |
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
135 |
|
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
136 |
- If the type constructors are unequal, there must be an |
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
137 |
instance of quotient types: |
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
138 |
|
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
139 |
- we first look up the corresponding rty_pat and qty_pat |
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
140 |
from the quotient definition; the arguments of qty_pat |
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
141 |
must be some distinct TVars |
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
142 |
- we then match the rty_pat with rty and qty_pat with qty; |
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
143 |
if matching fails the types do not correspond -> error |
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
144 |
- the matching produces two environments; we look up the |
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
145 |
assignments for the qty_pat variables and recurse on the |
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
146 |
assignments |
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
147 |
- we prefix the aggregate map function for the rty_pat, |
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
148 |
which is an abstraction over all type variables |
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
149 |
- finally we compose the result with the appropriate |
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
150 |
absrep function in case at least one argument produced |
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
151 |
a non-identity function / |
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
152 |
otherwise we just return the appropriate absrep |
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
153 |
function |
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
154 |
|
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
155 |
The composition is necessary for types like |
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
156 |
|
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
157 |
('a list) list / ('a foo) foo |
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
158 |
|
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
159 |
The matching is necessary for types like |
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
160 |
|
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
161 |
('a * 'a) list / 'a bar |
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
162 |
|
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
163 |
The test is necessary in order to eliminate superfluous |
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
164 |
identity maps. |
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
165 |
*) |
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
166 |
|
45797 | 167 |
fun absrep_fun ctxt flag (rty, qty) = |
45340
98ec8b51af9c
prefer global Quotient_Info lookup to accomodate Quotient_Term, which is not quite localized yet (cf. 9fd6fce8a230);
wenzelm
parents:
45280
diff
changeset
|
168 |
let |
45795
2d8949268303
maps are taken from enriched type infrastracture, rewritten lifting of constants, now we can lift even contravariant and co/contravariant types
kuncar
parents:
45628
diff
changeset
|
169 |
fun absrep_args tys tys' variances = |
2d8949268303
maps are taken from enriched type infrastracture, rewritten lifting of constants, now we can lift even contravariant and co/contravariant types
kuncar
parents:
45628
diff
changeset
|
170 |
let |
2d8949268303
maps are taken from enriched type infrastracture, rewritten lifting of constants, now we can lift even contravariant and co/contravariant types
kuncar
parents:
45628
diff
changeset
|
171 |
fun absrep_arg (types, (_, variant)) = |
2d8949268303
maps are taken from enriched type infrastracture, rewritten lifting of constants, now we can lift even contravariant and co/contravariant types
kuncar
parents:
45628
diff
changeset
|
172 |
(case variant of |
2d8949268303
maps are taken from enriched type infrastracture, rewritten lifting of constants, now we can lift even contravariant and co/contravariant types
kuncar
parents:
45628
diff
changeset
|
173 |
(false, false) => [] |
45797 | 174 |
| (true, false) => [(absrep_fun ctxt flag types)] |
175 |
| (false, true) => [(absrep_fun ctxt (negF flag) types)] |
|
176 |
| (true, true) => [(absrep_fun ctxt flag types),(absrep_fun ctxt (negF flag) types)]) |
|
45795
2d8949268303
maps are taken from enriched type infrastracture, rewritten lifting of constants, now we can lift even contravariant and co/contravariant types
kuncar
parents:
45628
diff
changeset
|
177 |
in |
2d8949268303
maps are taken from enriched type infrastracture, rewritten lifting of constants, now we can lift even contravariant and co/contravariant types
kuncar
parents:
45628
diff
changeset
|
178 |
maps absrep_arg ((tys ~~ tys') ~~ variances) |
2d8949268303
maps are taken from enriched type infrastracture, rewritten lifting of constants, now we can lift even contravariant and co/contravariant types
kuncar
parents:
45628
diff
changeset
|
179 |
end |
2d8949268303
maps are taken from enriched type infrastracture, rewritten lifting of constants, now we can lift even contravariant and co/contravariant types
kuncar
parents:
45628
diff
changeset
|
180 |
fun test_identities tys rtys' s s' = |
2d8949268303
maps are taken from enriched type infrastracture, rewritten lifting of constants, now we can lift even contravariant and co/contravariant types
kuncar
parents:
45628
diff
changeset
|
181 |
let |
45797 | 182 |
val args = map (absrep_fun ctxt flag) (tys ~~ rtys') |
45795
2d8949268303
maps are taken from enriched type infrastracture, rewritten lifting of constants, now we can lift even contravariant and co/contravariant types
kuncar
parents:
45628
diff
changeset
|
183 |
in |
2d8949268303
maps are taken from enriched type infrastracture, rewritten lifting of constants, now we can lift even contravariant and co/contravariant types
kuncar
parents:
45628
diff
changeset
|
184 |
if forall is_identity args |
2d8949268303
maps are taken from enriched type infrastracture, rewritten lifting of constants, now we can lift even contravariant and co/contravariant types
kuncar
parents:
45628
diff
changeset
|
185 |
then |
45797 | 186 |
absrep_const ctxt flag s' |
45795
2d8949268303
maps are taken from enriched type infrastracture, rewritten lifting of constants, now we can lift even contravariant and co/contravariant types
kuncar
parents:
45628
diff
changeset
|
187 |
else |
2d8949268303
maps are taken from enriched type infrastracture, rewritten lifting of constants, now we can lift even contravariant and co/contravariant types
kuncar
parents:
45628
diff
changeset
|
188 |
raise LIFT_MATCH ("No map function for type " ^ quote s ^ " found.") |
2d8949268303
maps are taken from enriched type infrastracture, rewritten lifting of constants, now we can lift even contravariant and co/contravariant types
kuncar
parents:
45628
diff
changeset
|
189 |
end |
45340
98ec8b51af9c
prefer global Quotient_Info lookup to accomodate Quotient_Term, which is not quite localized yet (cf. 9fd6fce8a230);
wenzelm
parents:
45280
diff
changeset
|
190 |
in |
98ec8b51af9c
prefer global Quotient_Info lookup to accomodate Quotient_Term, which is not quite localized yet (cf. 9fd6fce8a230);
wenzelm
parents:
45280
diff
changeset
|
191 |
if rty = qty |
80677 | 192 |
then \<^Const>\<open>id rty\<close> |
45340
98ec8b51af9c
prefer global Quotient_Info lookup to accomodate Quotient_Term, which is not quite localized yet (cf. 9fd6fce8a230);
wenzelm
parents:
45280
diff
changeset
|
193 |
else |
98ec8b51af9c
prefer global Quotient_Info lookup to accomodate Quotient_Term, which is not quite localized yet (cf. 9fd6fce8a230);
wenzelm
parents:
45280
diff
changeset
|
194 |
case (rty, qty) of |
45795
2d8949268303
maps are taken from enriched type infrastracture, rewritten lifting of constants, now we can lift even contravariant and co/contravariant types
kuncar
parents:
45628
diff
changeset
|
195 |
(Type (s, tys), Type (s', tys')) => |
45340
98ec8b51af9c
prefer global Quotient_Info lookup to accomodate Quotient_Term, which is not quite localized yet (cf. 9fd6fce8a230);
wenzelm
parents:
45280
diff
changeset
|
196 |
if s = s' |
98ec8b51af9c
prefer global Quotient_Info lookup to accomodate Quotient_Term, which is not quite localized yet (cf. 9fd6fce8a230);
wenzelm
parents:
45280
diff
changeset
|
197 |
then |
98ec8b51af9c
prefer global Quotient_Info lookup to accomodate Quotient_Term, which is not quite localized yet (cf. 9fd6fce8a230);
wenzelm
parents:
45280
diff
changeset
|
198 |
let |
45796 | 199 |
val (map_fun, variances) = get_mapfun_data ctxt s |
45795
2d8949268303
maps are taken from enriched type infrastracture, rewritten lifting of constants, now we can lift even contravariant and co/contravariant types
kuncar
parents:
45628
diff
changeset
|
200 |
val args = absrep_args tys tys' variances |
45340
98ec8b51af9c
prefer global Quotient_Info lookup to accomodate Quotient_Term, which is not quite localized yet (cf. 9fd6fce8a230);
wenzelm
parents:
45280
diff
changeset
|
201 |
in |
45795
2d8949268303
maps are taken from enriched type infrastracture, rewritten lifting of constants, now we can lift even contravariant and co/contravariant types
kuncar
parents:
45628
diff
changeset
|
202 |
list_comb (map_fun, args) |
45340
98ec8b51af9c
prefer global Quotient_Info lookup to accomodate Quotient_Term, which is not quite localized yet (cf. 9fd6fce8a230);
wenzelm
parents:
45280
diff
changeset
|
203 |
end |
98ec8b51af9c
prefer global Quotient_Info lookup to accomodate Quotient_Term, which is not quite localized yet (cf. 9fd6fce8a230);
wenzelm
parents:
45280
diff
changeset
|
204 |
else |
98ec8b51af9c
prefer global Quotient_Info lookup to accomodate Quotient_Term, which is not quite localized yet (cf. 9fd6fce8a230);
wenzelm
parents:
45280
diff
changeset
|
205 |
let |
45796 | 206 |
val (Type (_, rtys), qty_pat) = get_rty_qty ctxt s' |
45340
98ec8b51af9c
prefer global Quotient_Info lookup to accomodate Quotient_Term, which is not quite localized yet (cf. 9fd6fce8a230);
wenzelm
parents:
45280
diff
changeset
|
207 |
val qtyenv = match ctxt absrep_match_err qty_pat qty |
45795
2d8949268303
maps are taken from enriched type infrastracture, rewritten lifting of constants, now we can lift even contravariant and co/contravariant types
kuncar
parents:
45628
diff
changeset
|
208 |
val rtys' = map (Envir.subst_type qtyenv) rtys |
45340
98ec8b51af9c
prefer global Quotient_Info lookup to accomodate Quotient_Term, which is not quite localized yet (cf. 9fd6fce8a230);
wenzelm
parents:
45280
diff
changeset
|
209 |
in |
45796 | 210 |
if not (defined_mapfun_data ctxt s) |
45795
2d8949268303
maps are taken from enriched type infrastracture, rewritten lifting of constants, now we can lift even contravariant and co/contravariant types
kuncar
parents:
45628
diff
changeset
|
211 |
then |
2d8949268303
maps are taken from enriched type infrastracture, rewritten lifting of constants, now we can lift even contravariant and co/contravariant types
kuncar
parents:
45628
diff
changeset
|
212 |
(* |
2d8949268303
maps are taken from enriched type infrastracture, rewritten lifting of constants, now we can lift even contravariant and co/contravariant types
kuncar
parents:
45628
diff
changeset
|
213 |
If we don't know a map function for the raw type, |
2d8949268303
maps are taken from enriched type infrastracture, rewritten lifting of constants, now we can lift even contravariant and co/contravariant types
kuncar
parents:
45628
diff
changeset
|
214 |
we are not necessarilly in troubles because |
2d8949268303
maps are taken from enriched type infrastracture, rewritten lifting of constants, now we can lift even contravariant and co/contravariant types
kuncar
parents:
45628
diff
changeset
|
215 |
it can still be the case we don't need the map |
2d8949268303
maps are taken from enriched type infrastracture, rewritten lifting of constants, now we can lift even contravariant and co/contravariant types
kuncar
parents:
45628
diff
changeset
|
216 |
function <=> all abs/rep functions are identities. |
2d8949268303
maps are taken from enriched type infrastracture, rewritten lifting of constants, now we can lift even contravariant and co/contravariant types
kuncar
parents:
45628
diff
changeset
|
217 |
*) |
2d8949268303
maps are taken from enriched type infrastracture, rewritten lifting of constants, now we can lift even contravariant and co/contravariant types
kuncar
parents:
45628
diff
changeset
|
218 |
test_identities tys rtys' s s' |
45340
98ec8b51af9c
prefer global Quotient_Info lookup to accomodate Quotient_Term, which is not quite localized yet (cf. 9fd6fce8a230);
wenzelm
parents:
45280
diff
changeset
|
219 |
else |
98ec8b51af9c
prefer global Quotient_Info lookup to accomodate Quotient_Term, which is not quite localized yet (cf. 9fd6fce8a230);
wenzelm
parents:
45280
diff
changeset
|
220 |
let |
45796 | 221 |
val (map_fun, variances) = get_mapfun_data ctxt s |
45795
2d8949268303
maps are taken from enriched type infrastracture, rewritten lifting of constants, now we can lift even contravariant and co/contravariant types
kuncar
parents:
45628
diff
changeset
|
222 |
val args = absrep_args tys rtys' variances |
45340
98ec8b51af9c
prefer global Quotient_Info lookup to accomodate Quotient_Term, which is not quite localized yet (cf. 9fd6fce8a230);
wenzelm
parents:
45280
diff
changeset
|
223 |
in |
45795
2d8949268303
maps are taken from enriched type infrastracture, rewritten lifting of constants, now we can lift even contravariant and co/contravariant types
kuncar
parents:
45628
diff
changeset
|
224 |
if forall is_identity args |
45797 | 225 |
then absrep_const ctxt flag s' |
45795
2d8949268303
maps are taken from enriched type infrastracture, rewritten lifting of constants, now we can lift even contravariant and co/contravariant types
kuncar
parents:
45628
diff
changeset
|
226 |
else |
2d8949268303
maps are taken from enriched type infrastracture, rewritten lifting of constants, now we can lift even contravariant and co/contravariant types
kuncar
parents:
45628
diff
changeset
|
227 |
let |
2d8949268303
maps are taken from enriched type infrastracture, rewritten lifting of constants, now we can lift even contravariant and co/contravariant types
kuncar
parents:
45628
diff
changeset
|
228 |
val result = list_comb (map_fun, args) |
2d8949268303
maps are taken from enriched type infrastracture, rewritten lifting of constants, now we can lift even contravariant and co/contravariant types
kuncar
parents:
45628
diff
changeset
|
229 |
in |
45797 | 230 |
mk_fun_compose flag (absrep_const ctxt flag s', result) |
45795
2d8949268303
maps are taken from enriched type infrastracture, rewritten lifting of constants, now we can lift even contravariant and co/contravariant types
kuncar
parents:
45628
diff
changeset
|
231 |
end |
45340
98ec8b51af9c
prefer global Quotient_Info lookup to accomodate Quotient_Term, which is not quite localized yet (cf. 9fd6fce8a230);
wenzelm
parents:
45280
diff
changeset
|
232 |
end |
98ec8b51af9c
prefer global Quotient_Info lookup to accomodate Quotient_Term, which is not quite localized yet (cf. 9fd6fce8a230);
wenzelm
parents:
45280
diff
changeset
|
233 |
end |
98ec8b51af9c
prefer global Quotient_Info lookup to accomodate Quotient_Term, which is not quite localized yet (cf. 9fd6fce8a230);
wenzelm
parents:
45280
diff
changeset
|
234 |
| (TFree x, TFree x') => |
98ec8b51af9c
prefer global Quotient_Info lookup to accomodate Quotient_Term, which is not quite localized yet (cf. 9fd6fce8a230);
wenzelm
parents:
45280
diff
changeset
|
235 |
if x = x' |
80677 | 236 |
then \<^Const>\<open>id rty\<close> |
45340
98ec8b51af9c
prefer global Quotient_Info lookup to accomodate Quotient_Term, which is not quite localized yet (cf. 9fd6fce8a230);
wenzelm
parents:
45280
diff
changeset
|
237 |
else raise (LIFT_MATCH "absrep_fun (frees)") |
98ec8b51af9c
prefer global Quotient_Info lookup to accomodate Quotient_Term, which is not quite localized yet (cf. 9fd6fce8a230);
wenzelm
parents:
45280
diff
changeset
|
238 |
| (TVar _, TVar _) => raise (LIFT_MATCH "absrep_fun (vars)") |
98ec8b51af9c
prefer global Quotient_Info lookup to accomodate Quotient_Term, which is not quite localized yet (cf. 9fd6fce8a230);
wenzelm
parents:
45280
diff
changeset
|
239 |
| _ => raise (LIFT_MATCH "absrep_fun (default)") |
98ec8b51af9c
prefer global Quotient_Info lookup to accomodate Quotient_Term, which is not quite localized yet (cf. 9fd6fce8a230);
wenzelm
parents:
45280
diff
changeset
|
240 |
end |
35222
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
241 |
|
45797 | 242 |
fun absrep_fun_chk ctxt flag (rty, qty) = |
243 |
absrep_fun ctxt flag (rty, qty) |
|
35222
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
244 |
|> Syntax.check_term ctxt |
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
245 |
|
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
246 |
|
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
247 |
|
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
248 |
(*** Aggregate Equivalence Relation ***) |
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
249 |
|
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
250 |
|
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
251 |
(* works very similar to the absrep generation, |
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
252 |
except there is no need for polarities |
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
253 |
*) |
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
254 |
|
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
255 |
(* instantiates TVars so that the term is of type ty *) |
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
256 |
fun force_typ ctxt trm ty = |
41444 | 257 |
let |
42361 | 258 |
val thy = Proof_Context.theory_of ctxt |
41444 | 259 |
val trm_ty = fastype_of trm |
260 |
val ty_inst = Sign.typ_match thy (trm_ty, ty) Vartab.empty |
|
261 |
in |
|
262 |
map_types (Envir.subst_type ty_inst) trm |
|
263 |
end |
|
35222
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
264 |
|
80677 | 265 |
fun is_eq \<^Const_>\<open>HOL.eq _\<close> = true |
35222
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
266 |
| is_eq _ = false |
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
267 |
|
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
268 |
fun mk_rel_compose (trm1, trm2) = |
69593 | 269 |
Const (\<^const_abbrev>\<open>rel_conj\<close>, dummyT) $ trm1 $ trm2 |
35222
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
270 |
|
67632 | 271 |
fun get_relmap ctxt s = |
272 |
(case Quotient_Info.lookup_quotmaps ctxt s of |
|
273 |
SOME {relmap, ...} => Const (relmap, dummyT) |
|
45279 | 274 |
| NONE => raise LIFT_MATCH ("get_relmap (no relation map function found for type " ^ s ^ ")")) |
35222
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
275 |
|
67632 | 276 |
fun get_equiv_rel ctxt s = |
277 |
(case Quotient_Info.lookup_quotients ctxt s of |
|
278 |
SOME {equiv_rel, ...} => equiv_rel |
|
47095
b43ddeea727f
simplified code of generation of aggregate relations
kuncar
parents:
46416
diff
changeset
|
279 |
| NONE => raise LIFT_MATCH ("get_equiv_rel (no quotient found for type " ^ s ^ ")")) |
35222
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
280 |
|
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
281 |
fun equiv_match_err ctxt ty_pat ty = |
41444 | 282 |
let |
283 |
val ty_pat_str = Syntax.string_of_typ ctxt ty_pat |
|
284 |
val ty_str = Syntax.string_of_typ ctxt ty |
|
285 |
in |
|
286 |
raise LIFT_MATCH (space_implode " " |
|
287 |
["equiv_relation (Types ", quote ty_pat_str, "and", quote ty_str, " do not match.)"]) |
|
288 |
end |
|
35222
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
289 |
|
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
290 |
(* builds the aggregate equivalence relation |
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
291 |
that will be the argument of Respects |
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
292 |
*) |
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
293 |
fun equiv_relation ctxt (rty, qty) = |
45796 | 294 |
if rty = qty |
295 |
then HOLogic.eq_const rty |
|
296 |
else |
|
297 |
case (rty, qty) of |
|
298 |
(Type (s, tys), Type (s', tys')) => |
|
299 |
if s = s' |
|
300 |
then |
|
301 |
let |
|
302 |
val args = map (equiv_relation ctxt) (tys ~~ tys') |
|
303 |
in |
|
304 |
list_comb (get_relmap ctxt s, args) |
|
305 |
end |
|
306 |
else |
|
307 |
let |
|
47095
b43ddeea727f
simplified code of generation of aggregate relations
kuncar
parents:
46416
diff
changeset
|
308 |
val (Type (_, rtys), qty_pat) = get_rty_qty ctxt s' |
45796 | 309 |
val qtyenv = match ctxt equiv_match_err qty_pat qty |
47095
b43ddeea727f
simplified code of generation of aggregate relations
kuncar
parents:
46416
diff
changeset
|
310 |
val rtys' = map (Envir.subst_type qtyenv) rtys |
b43ddeea727f
simplified code of generation of aggregate relations
kuncar
parents:
46416
diff
changeset
|
311 |
val args = map (equiv_relation ctxt) (tys ~~ rtys') |
45796 | 312 |
val eqv_rel = get_equiv_rel ctxt s' |
69593 | 313 |
val eqv_rel' = force_typ ctxt eqv_rel ([rty, rty] ---> \<^typ>\<open>bool\<close>) |
45796 | 314 |
in |
315 |
if forall is_eq args |
|
316 |
then eqv_rel' |
|
317 |
else |
|
318 |
let |
|
47095
b43ddeea727f
simplified code of generation of aggregate relations
kuncar
parents:
46416
diff
changeset
|
319 |
val result = list_comb (get_relmap ctxt s, args) |
45796 | 320 |
in |
321 |
mk_rel_compose (result, eqv_rel') |
|
322 |
end |
|
323 |
end |
|
324 |
| _ => HOLogic.eq_const rty |
|
325 |
||
35222
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
326 |
|
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
327 |
fun equiv_relation_chk ctxt (rty, qty) = |
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
328 |
equiv_relation ctxt (rty, qty) |
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
329 |
|> Syntax.check_term ctxt |
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
330 |
|
47096
3ea48c19673e
generation of a code certificate from a respectfulness theorem for constants lifted by the quotient_definition command & setup_lifting command: setups Quotient infrastructure from a typedef theorem
kuncar
parents:
47095
diff
changeset
|
331 |
(* generation of the Quotient theorem *) |
3ea48c19673e
generation of a code certificate from a respectfulness theorem for constants lifted by the quotient_definition command & setup_lifting command: setups Quotient infrastructure from a typedef theorem
kuncar
parents:
47095
diff
changeset
|
332 |
|
47106
dfa5ed8d94b4
use Thm.transfer for thms stored in generic context data storage
kuncar
parents:
47096
diff
changeset
|
333 |
exception CODE_GEN of string |
dfa5ed8d94b4
use Thm.transfer for thms stored in generic context data storage
kuncar
parents:
47096
diff
changeset
|
334 |
|
47096
3ea48c19673e
generation of a code certificate from a respectfulness theorem for constants lifted by the quotient_definition command & setup_lifting command: setups Quotient infrastructure from a typedef theorem
kuncar
parents:
47095
diff
changeset
|
335 |
fun get_quot_thm ctxt s = |
67633
9a1212f4393e
clarified data operations, with trim_context and transfer;
wenzelm
parents:
67632
diff
changeset
|
336 |
(case Quotient_Info.lookup_quotients ctxt s of |
9a1212f4393e
clarified data operations, with trim_context and transfer;
wenzelm
parents:
67632
diff
changeset
|
337 |
SOME {quot_thm, ...} => quot_thm |
9a1212f4393e
clarified data operations, with trim_context and transfer;
wenzelm
parents:
67632
diff
changeset
|
338 |
| NONE => raise CODE_GEN ("No quotient type " ^ quote s ^ " found.")); |
47096
3ea48c19673e
generation of a code certificate from a respectfulness theorem for constants lifted by the quotient_definition command & setup_lifting command: setups Quotient infrastructure from a typedef theorem
kuncar
parents:
47095
diff
changeset
|
339 |
|
47106
dfa5ed8d94b4
use Thm.transfer for thms stored in generic context data storage
kuncar
parents:
47096
diff
changeset
|
340 |
fun get_rel_quot_thm ctxt s = |
67633
9a1212f4393e
clarified data operations, with trim_context and transfer;
wenzelm
parents:
67632
diff
changeset
|
341 |
(case Quotient_Info.lookup_quotmaps ctxt s of |
9a1212f4393e
clarified data operations, with trim_context and transfer;
wenzelm
parents:
67632
diff
changeset
|
342 |
SOME {quot_thm, ...} => quot_thm |
9a1212f4393e
clarified data operations, with trim_context and transfer;
wenzelm
parents:
67632
diff
changeset
|
343 |
| NONE => raise CODE_GEN ("get_relmap (no relation map function found for type " ^ s ^ ")")); |
47096
3ea48c19673e
generation of a code certificate from a respectfulness theorem for constants lifted by the quotient_definition command & setup_lifting command: setups Quotient infrastructure from a typedef theorem
kuncar
parents:
47095
diff
changeset
|
344 |
|
59848 | 345 |
fun is_id_quot thm = Thm.eq_thm_prop (thm, @{thm identity_quotient3}) |
47096
3ea48c19673e
generation of a code certificate from a respectfulness theorem for constants lifted by the quotient_definition command & setup_lifting command: setups Quotient infrastructure from a typedef theorem
kuncar
parents:
47095
diff
changeset
|
346 |
|
47698 | 347 |
open Lifting_Util |
47096
3ea48c19673e
generation of a code certificate from a respectfulness theorem for constants lifted by the quotient_definition command & setup_lifting command: setups Quotient infrastructure from a typedef theorem
kuncar
parents:
47095
diff
changeset
|
348 |
|
47698 | 349 |
infix 0 MRSL |
47096
3ea48c19673e
generation of a code certificate from a respectfulness theorem for constants lifted by the quotient_definition command & setup_lifting command: setups Quotient infrastructure from a typedef theorem
kuncar
parents:
47095
diff
changeset
|
350 |
|
3ea48c19673e
generation of a code certificate from a respectfulness theorem for constants lifted by the quotient_definition command & setup_lifting command: setups Quotient infrastructure from a typedef theorem
kuncar
parents:
47095
diff
changeset
|
351 |
exception NOT_IMPL of string |
3ea48c19673e
generation of a code certificate from a respectfulness theorem for constants lifted by the quotient_definition command & setup_lifting command: setups Quotient infrastructure from a typedef theorem
kuncar
parents:
47095
diff
changeset
|
352 |
|
3ea48c19673e
generation of a code certificate from a respectfulness theorem for constants lifted by the quotient_definition command & setup_lifting command: setups Quotient infrastructure from a typedef theorem
kuncar
parents:
47095
diff
changeset
|
353 |
fun get_rel_from_quot_thm quot_thm = |
3ea48c19673e
generation of a code certificate from a respectfulness theorem for constants lifted by the quotient_definition command & setup_lifting command: setups Quotient infrastructure from a typedef theorem
kuncar
parents:
47095
diff
changeset
|
354 |
let |
59582 | 355 |
val (_ $ rel $ _ $ _) = (HOLogic.dest_Trueprop o Thm.prop_of) quot_thm |
47096
3ea48c19673e
generation of a code certificate from a respectfulness theorem for constants lifted by the quotient_definition command & setup_lifting command: setups Quotient infrastructure from a typedef theorem
kuncar
parents:
47095
diff
changeset
|
356 |
in |
3ea48c19673e
generation of a code certificate from a respectfulness theorem for constants lifted by the quotient_definition command & setup_lifting command: setups Quotient infrastructure from a typedef theorem
kuncar
parents:
47095
diff
changeset
|
357 |
rel |
3ea48c19673e
generation of a code certificate from a respectfulness theorem for constants lifted by the quotient_definition command & setup_lifting command: setups Quotient infrastructure from a typedef theorem
kuncar
parents:
47095
diff
changeset
|
358 |
end |
3ea48c19673e
generation of a code certificate from a respectfulness theorem for constants lifted by the quotient_definition command & setup_lifting command: setups Quotient infrastructure from a typedef theorem
kuncar
parents:
47095
diff
changeset
|
359 |
|
3ea48c19673e
generation of a code certificate from a respectfulness theorem for constants lifted by the quotient_definition command & setup_lifting command: setups Quotient infrastructure from a typedef theorem
kuncar
parents:
47095
diff
changeset
|
360 |
fun mk_quot_thm_compose (rel_quot_thm, quot_thm) = |
3ea48c19673e
generation of a code certificate from a respectfulness theorem for constants lifted by the quotient_definition command & setup_lifting command: setups Quotient infrastructure from a typedef theorem
kuncar
parents:
47095
diff
changeset
|
361 |
let |
3ea48c19673e
generation of a code certificate from a respectfulness theorem for constants lifted by the quotient_definition command & setup_lifting command: setups Quotient infrastructure from a typedef theorem
kuncar
parents:
47095
diff
changeset
|
362 |
val quot_thm_rel = get_rel_from_quot_thm quot_thm |
3ea48c19673e
generation of a code certificate from a respectfulness theorem for constants lifted by the quotient_definition command & setup_lifting command: setups Quotient infrastructure from a typedef theorem
kuncar
parents:
47095
diff
changeset
|
363 |
in |
47308 | 364 |
if is_eq quot_thm_rel then [rel_quot_thm, quot_thm] MRSL @{thm OOO_eq_quotient3} |
47096
3ea48c19673e
generation of a code certificate from a respectfulness theorem for constants lifted by the quotient_definition command & setup_lifting command: setups Quotient infrastructure from a typedef theorem
kuncar
parents:
47095
diff
changeset
|
365 |
else raise NOT_IMPL "nested quotients: not implemented yet" |
3ea48c19673e
generation of a code certificate from a respectfulness theorem for constants lifted by the quotient_definition command & setup_lifting command: setups Quotient infrastructure from a typedef theorem
kuncar
parents:
47095
diff
changeset
|
366 |
end |
3ea48c19673e
generation of a code certificate from a respectfulness theorem for constants lifted by the quotient_definition command & setup_lifting command: setups Quotient infrastructure from a typedef theorem
kuncar
parents:
47095
diff
changeset
|
367 |
|
47504
aa1b8a59017f
go back to the explicit compisition of quotient theorems
kuncar
parents:
47308
diff
changeset
|
368 |
fun prove_quot_thm ctxt (rty, qty) = |
47096
3ea48c19673e
generation of a code certificate from a respectfulness theorem for constants lifted by the quotient_definition command & setup_lifting command: setups Quotient infrastructure from a typedef theorem
kuncar
parents:
47095
diff
changeset
|
369 |
if rty = qty |
47308 | 370 |
then @{thm identity_quotient3} |
47096
3ea48c19673e
generation of a code certificate from a respectfulness theorem for constants lifted by the quotient_definition command & setup_lifting command: setups Quotient infrastructure from a typedef theorem
kuncar
parents:
47095
diff
changeset
|
371 |
else |
3ea48c19673e
generation of a code certificate from a respectfulness theorem for constants lifted by the quotient_definition command & setup_lifting command: setups Quotient infrastructure from a typedef theorem
kuncar
parents:
47095
diff
changeset
|
372 |
case (rty, qty) of |
3ea48c19673e
generation of a code certificate from a respectfulness theorem for constants lifted by the quotient_definition command & setup_lifting command: setups Quotient infrastructure from a typedef theorem
kuncar
parents:
47095
diff
changeset
|
373 |
(Type (s, tys), Type (s', tys')) => |
3ea48c19673e
generation of a code certificate from a respectfulness theorem for constants lifted by the quotient_definition command & setup_lifting command: setups Quotient infrastructure from a typedef theorem
kuncar
parents:
47095
diff
changeset
|
374 |
if s = s' |
3ea48c19673e
generation of a code certificate from a respectfulness theorem for constants lifted by the quotient_definition command & setup_lifting command: setups Quotient infrastructure from a typedef theorem
kuncar
parents:
47095
diff
changeset
|
375 |
then |
3ea48c19673e
generation of a code certificate from a respectfulness theorem for constants lifted by the quotient_definition command & setup_lifting command: setups Quotient infrastructure from a typedef theorem
kuncar
parents:
47095
diff
changeset
|
376 |
let |
47504
aa1b8a59017f
go back to the explicit compisition of quotient theorems
kuncar
parents:
47308
diff
changeset
|
377 |
val args = map (prove_quot_thm ctxt) (tys ~~ tys') |
47096
3ea48c19673e
generation of a code certificate from a respectfulness theorem for constants lifted by the quotient_definition command & setup_lifting command: setups Quotient infrastructure from a typedef theorem
kuncar
parents:
47095
diff
changeset
|
378 |
in |
3ea48c19673e
generation of a code certificate from a respectfulness theorem for constants lifted by the quotient_definition command & setup_lifting command: setups Quotient infrastructure from a typedef theorem
kuncar
parents:
47095
diff
changeset
|
379 |
args MRSL (get_rel_quot_thm ctxt s) |
3ea48c19673e
generation of a code certificate from a respectfulness theorem for constants lifted by the quotient_definition command & setup_lifting command: setups Quotient infrastructure from a typedef theorem
kuncar
parents:
47095
diff
changeset
|
380 |
end |
3ea48c19673e
generation of a code certificate from a respectfulness theorem for constants lifted by the quotient_definition command & setup_lifting command: setups Quotient infrastructure from a typedef theorem
kuncar
parents:
47095
diff
changeset
|
381 |
else |
3ea48c19673e
generation of a code certificate from a respectfulness theorem for constants lifted by the quotient_definition command & setup_lifting command: setups Quotient infrastructure from a typedef theorem
kuncar
parents:
47095
diff
changeset
|
382 |
let |
3ea48c19673e
generation of a code certificate from a respectfulness theorem for constants lifted by the quotient_definition command & setup_lifting command: setups Quotient infrastructure from a typedef theorem
kuncar
parents:
47095
diff
changeset
|
383 |
val (Type (_, rtys), qty_pat) = get_rty_qty ctxt s' |
3ea48c19673e
generation of a code certificate from a respectfulness theorem for constants lifted by the quotient_definition command & setup_lifting command: setups Quotient infrastructure from a typedef theorem
kuncar
parents:
47095
diff
changeset
|
384 |
val qtyenv = match ctxt equiv_match_err qty_pat qty |
3ea48c19673e
generation of a code certificate from a respectfulness theorem for constants lifted by the quotient_definition command & setup_lifting command: setups Quotient infrastructure from a typedef theorem
kuncar
parents:
47095
diff
changeset
|
385 |
val rtys' = map (Envir.subst_type qtyenv) rtys |
47504
aa1b8a59017f
go back to the explicit compisition of quotient theorems
kuncar
parents:
47308
diff
changeset
|
386 |
val args = map (prove_quot_thm ctxt) (tys ~~ rtys') |
47096
3ea48c19673e
generation of a code certificate from a respectfulness theorem for constants lifted by the quotient_definition command & setup_lifting command: setups Quotient infrastructure from a typedef theorem
kuncar
parents:
47095
diff
changeset
|
387 |
val quot_thm = get_quot_thm ctxt s' |
3ea48c19673e
generation of a code certificate from a respectfulness theorem for constants lifted by the quotient_definition command & setup_lifting command: setups Quotient infrastructure from a typedef theorem
kuncar
parents:
47095
diff
changeset
|
388 |
in |
3ea48c19673e
generation of a code certificate from a respectfulness theorem for constants lifted by the quotient_definition command & setup_lifting command: setups Quotient infrastructure from a typedef theorem
kuncar
parents:
47095
diff
changeset
|
389 |
if forall is_id_quot args |
3ea48c19673e
generation of a code certificate from a respectfulness theorem for constants lifted by the quotient_definition command & setup_lifting command: setups Quotient infrastructure from a typedef theorem
kuncar
parents:
47095
diff
changeset
|
390 |
then |
3ea48c19673e
generation of a code certificate from a respectfulness theorem for constants lifted by the quotient_definition command & setup_lifting command: setups Quotient infrastructure from a typedef theorem
kuncar
parents:
47095
diff
changeset
|
391 |
quot_thm |
3ea48c19673e
generation of a code certificate from a respectfulness theorem for constants lifted by the quotient_definition command & setup_lifting command: setups Quotient infrastructure from a typedef theorem
kuncar
parents:
47095
diff
changeset
|
392 |
else |
3ea48c19673e
generation of a code certificate from a respectfulness theorem for constants lifted by the quotient_definition command & setup_lifting command: setups Quotient infrastructure from a typedef theorem
kuncar
parents:
47095
diff
changeset
|
393 |
let |
3ea48c19673e
generation of a code certificate from a respectfulness theorem for constants lifted by the quotient_definition command & setup_lifting command: setups Quotient infrastructure from a typedef theorem
kuncar
parents:
47095
diff
changeset
|
394 |
val rel_quot_thm = args MRSL (get_rel_quot_thm ctxt s) |
3ea48c19673e
generation of a code certificate from a respectfulness theorem for constants lifted by the quotient_definition command & setup_lifting command: setups Quotient infrastructure from a typedef theorem
kuncar
parents:
47095
diff
changeset
|
395 |
in |
3ea48c19673e
generation of a code certificate from a respectfulness theorem for constants lifted by the quotient_definition command & setup_lifting command: setups Quotient infrastructure from a typedef theorem
kuncar
parents:
47095
diff
changeset
|
396 |
mk_quot_thm_compose (rel_quot_thm, quot_thm) |
3ea48c19673e
generation of a code certificate from a respectfulness theorem for constants lifted by the quotient_definition command & setup_lifting command: setups Quotient infrastructure from a typedef theorem
kuncar
parents:
47095
diff
changeset
|
397 |
end |
3ea48c19673e
generation of a code certificate from a respectfulness theorem for constants lifted by the quotient_definition command & setup_lifting command: setups Quotient infrastructure from a typedef theorem
kuncar
parents:
47095
diff
changeset
|
398 |
end |
47308 | 399 |
| _ => @{thm identity_quotient3} |
47096
3ea48c19673e
generation of a code certificate from a respectfulness theorem for constants lifted by the quotient_definition command & setup_lifting command: setups Quotient infrastructure from a typedef theorem
kuncar
parents:
47095
diff
changeset
|
400 |
|
35222
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
401 |
|
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
402 |
|
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
403 |
(*** Regularization ***) |
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
404 |
|
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
405 |
(* Regularizing an rtrm means: |
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
406 |
|
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
407 |
- Quantifiers over types that need lifting are replaced |
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
408 |
by bounded quantifiers, for example: |
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
409 |
|
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
410 |
All P ----> All (Respects R) P |
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
411 |
|
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
412 |
where the aggregate relation R is given by the rty and qty; |
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
413 |
|
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
414 |
- Abstractions over types that need lifting are replaced |
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
415 |
by bounded abstractions, for example: |
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
416 |
|
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
417 |
%x. P ----> Ball (Respects R) %x. P |
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
418 |
|
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
419 |
- Equalities over types that need lifting are replaced by |
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
420 |
corresponding equivalence relations, for example: |
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
421 |
|
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
422 |
A = B ----> R A B |
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
423 |
|
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
424 |
or |
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
425 |
|
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
426 |
A = B ----> (R ===> R) A B |
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
427 |
|
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
428 |
for more complicated types of A and B |
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
429 |
|
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
430 |
|
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
431 |
The regularize_trm accepts raw theorems in which equalities |
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
432 |
and quantifiers match exactly the ones in the lifted theorem |
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
433 |
but also accepts partially regularized terms. |
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
434 |
|
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
435 |
This means that the raw theorems can have: |
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
436 |
Ball (Respects R), Bex (Respects R), Bex1_rel (Respects R), Babs, R |
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
437 |
in the places where: |
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
438 |
All, Ex, Ex1, %, (op =) |
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
439 |
is required the lifted theorem. |
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
440 |
|
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
441 |
*) |
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
442 |
|
69593 | 443 |
val mk_babs = Const (\<^const_name>\<open>Babs\<close>, dummyT) |
444 |
val mk_ball = Const (\<^const_name>\<open>Ball\<close>, dummyT) |
|
445 |
val mk_bex = Const (\<^const_name>\<open>Bex\<close>, dummyT) |
|
446 |
val mk_bex1_rel = Const (\<^const_name>\<open>Bex1_rel\<close>, dummyT) |
|
447 |
val mk_resp = Const (\<^const_name>\<open>Respects\<close>, dummyT) |
|
35222
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
448 |
|
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
449 |
(* - applies f to the subterm of an abstraction, |
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
450 |
otherwise to the given term, |
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
451 |
- used by regularize, therefore abstracted |
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
452 |
variables do not have to be treated specially |
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
453 |
*) |
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
454 |
fun apply_subt f (trm1, trm2) = |
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
455 |
case (trm1, trm2) of |
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
456 |
(Abs (x, T, t), Abs (_ , _, t')) => Abs (x, T, f (t, t')) |
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
457 |
| _ => f (trm1, trm2) |
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
458 |
|
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
459 |
fun term_mismatch str ctxt t1 t2 = |
41444 | 460 |
let |
461 |
val t1_str = Syntax.string_of_term ctxt t1 |
|
462 |
val t2_str = Syntax.string_of_term ctxt t2 |
|
463 |
val t1_ty_str = Syntax.string_of_typ ctxt (fastype_of t1) |
|
464 |
val t2_ty_str = Syntax.string_of_typ ctxt (fastype_of t2) |
|
465 |
in |
|
466 |
raise LIFT_MATCH (cat_lines [str, t1_str ^ "::" ^ t1_ty_str, t2_str ^ "::" ^ t2_ty_str]) |
|
467 |
end |
|
35222
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
468 |
|
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
469 |
(* the major type of All and Ex quantifiers *) |
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
470 |
fun qnt_typ ty = domain_type (domain_type ty) |
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
471 |
|
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
472 |
(* Checks that two types match, for example: |
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
473 |
rty -> rty matches qty -> qty *) |
45280 | 474 |
fun matches_typ ctxt rT qT = |
45340
98ec8b51af9c
prefer global Quotient_Info lookup to accomodate Quotient_Term, which is not quite localized yet (cf. 9fd6fce8a230);
wenzelm
parents:
45280
diff
changeset
|
475 |
let |
98ec8b51af9c
prefer global Quotient_Info lookup to accomodate Quotient_Term, which is not quite localized yet (cf. 9fd6fce8a230);
wenzelm
parents:
45280
diff
changeset
|
476 |
val thy = Proof_Context.theory_of ctxt |
98ec8b51af9c
prefer global Quotient_Info lookup to accomodate Quotient_Term, which is not quite localized yet (cf. 9fd6fce8a230);
wenzelm
parents:
45280
diff
changeset
|
477 |
in |
98ec8b51af9c
prefer global Quotient_Info lookup to accomodate Quotient_Term, which is not quite localized yet (cf. 9fd6fce8a230);
wenzelm
parents:
45280
diff
changeset
|
478 |
if rT = qT then true |
98ec8b51af9c
prefer global Quotient_Info lookup to accomodate Quotient_Term, which is not quite localized yet (cf. 9fd6fce8a230);
wenzelm
parents:
45280
diff
changeset
|
479 |
else |
98ec8b51af9c
prefer global Quotient_Info lookup to accomodate Quotient_Term, which is not quite localized yet (cf. 9fd6fce8a230);
wenzelm
parents:
45280
diff
changeset
|
480 |
(case (rT, qT) of |
98ec8b51af9c
prefer global Quotient_Info lookup to accomodate Quotient_Term, which is not quite localized yet (cf. 9fd6fce8a230);
wenzelm
parents:
45280
diff
changeset
|
481 |
(Type (rs, rtys), Type (qs, qtys)) => |
98ec8b51af9c
prefer global Quotient_Info lookup to accomodate Quotient_Term, which is not quite localized yet (cf. 9fd6fce8a230);
wenzelm
parents:
45280
diff
changeset
|
482 |
if rs = qs then |
98ec8b51af9c
prefer global Quotient_Info lookup to accomodate Quotient_Term, which is not quite localized yet (cf. 9fd6fce8a230);
wenzelm
parents:
45280
diff
changeset
|
483 |
if length rtys <> length qtys then false |
98ec8b51af9c
prefer global Quotient_Info lookup to accomodate Quotient_Term, which is not quite localized yet (cf. 9fd6fce8a230);
wenzelm
parents:
45280
diff
changeset
|
484 |
else forall (fn x => x = true) (map2 (matches_typ ctxt) rtys qtys) |
98ec8b51af9c
prefer global Quotient_Info lookup to accomodate Quotient_Term, which is not quite localized yet (cf. 9fd6fce8a230);
wenzelm
parents:
45280
diff
changeset
|
485 |
else |
98ec8b51af9c
prefer global Quotient_Info lookup to accomodate Quotient_Term, which is not quite localized yet (cf. 9fd6fce8a230);
wenzelm
parents:
45280
diff
changeset
|
486 |
(case Quotient_Info.lookup_quotients_global thy qs of |
67632 | 487 |
SOME {rtyp, ...} => Sign.typ_instance thy (rT, rtyp) |
45340
98ec8b51af9c
prefer global Quotient_Info lookup to accomodate Quotient_Term, which is not quite localized yet (cf. 9fd6fce8a230);
wenzelm
parents:
45280
diff
changeset
|
488 |
| NONE => false) |
98ec8b51af9c
prefer global Quotient_Info lookup to accomodate Quotient_Term, which is not quite localized yet (cf. 9fd6fce8a230);
wenzelm
parents:
45280
diff
changeset
|
489 |
| _ => false) |
98ec8b51af9c
prefer global Quotient_Info lookup to accomodate Quotient_Term, which is not quite localized yet (cf. 9fd6fce8a230);
wenzelm
parents:
45280
diff
changeset
|
490 |
end |
35222
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
491 |
|
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
492 |
|
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
493 |
(* produces a regularized version of rtrm |
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
494 |
|
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
495 |
- the result might contain dummyTs |
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
496 |
|
38718 | 497 |
- for regularization we do not need any |
35222
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
498 |
special treatment of bound variables |
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
499 |
*) |
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
500 |
fun regularize_trm ctxt (rtrm, qtrm) = |
45280 | 501 |
(case (rtrm, qtrm) of |
35222
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
502 |
(Abs (x, ty, t), Abs (_, ty', t')) => |
41444 | 503 |
let |
504 |
val subtrm = Abs(x, ty, regularize_trm ctxt (t, t')) |
|
505 |
in |
|
506 |
if ty = ty' then subtrm |
|
507 |
else mk_babs $ (mk_resp $ equiv_relation ctxt (ty, ty')) $ subtrm |
|
508 |
end |
|
45280 | 509 |
|
69593 | 510 |
| (Const (\<^const_name>\<open>Babs\<close>, T) $ resrel $ (t as (Abs (_, ty, _))), t' as (Abs (_, ty', _))) => |
41444 | 511 |
let |
512 |
val subtrm = regularize_trm ctxt (t, t') |
|
513 |
val needres = mk_resp $ equiv_relation_chk ctxt (ty, ty') |
|
514 |
in |
|
515 |
if resrel <> needres |
|
516 |
then term_mismatch "regularize (Babs)" ctxt resrel needres |
|
517 |
else mk_babs $ resrel $ subtrm |
|
518 |
end |
|
35222
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
519 |
|
69593 | 520 |
| (Const (\<^const_name>\<open>All\<close>, ty) $ t, Const (\<^const_name>\<open>All\<close>, ty') $ t') => |
41444 | 521 |
let |
522 |
val subtrm = apply_subt (regularize_trm ctxt) (t, t') |
|
523 |
in |
|
69593 | 524 |
if ty = ty' then Const (\<^const_name>\<open>All\<close>, ty) $ subtrm |
41444 | 525 |
else mk_ball $ (mk_resp $ equiv_relation ctxt (qnt_typ ty, qnt_typ ty')) $ subtrm |
526 |
end |
|
35222
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
527 |
|
69593 | 528 |
| (Const (\<^const_name>\<open>Ex\<close>, ty) $ t, Const (\<^const_name>\<open>Ex\<close>, ty') $ t') => |
41444 | 529 |
let |
530 |
val subtrm = apply_subt (regularize_trm ctxt) (t, t') |
|
531 |
in |
|
69593 | 532 |
if ty = ty' then Const (\<^const_name>\<open>Ex\<close>, ty) $ subtrm |
41444 | 533 |
else mk_bex $ (mk_resp $ equiv_relation ctxt (qnt_typ ty, qnt_typ ty')) $ subtrm |
534 |
end |
|
35222
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
535 |
|
69593 | 536 |
| (Const (\<^const_name>\<open>Ex1\<close>, ty) $ (Abs (_, _, |
537 |
(Const (\<^const_name>\<open>HOL.conj\<close>, _) $ (Const (\<^const_name>\<open>Set.member\<close>, _) $ _ $ |
|
538 |
(Const (\<^const_name>\<open>Respects\<close>, _) $ resrel)) $ (t $ _)))), |
|
539 |
Const (\<^const_name>\<open>Ex1\<close>, ty') $ t') => |
|
41444 | 540 |
let |
541 |
val t_ = incr_boundvars (~1) t |
|
542 |
val subtrm = apply_subt (regularize_trm ctxt) (t_, t') |
|
543 |
val needrel = equiv_relation_chk ctxt (qnt_typ ty, qnt_typ ty') |
|
544 |
in |
|
545 |
if resrel <> needrel |
|
546 |
then term_mismatch "regularize (Bex1)" ctxt resrel needrel |
|
547 |
else mk_bex1_rel $ resrel $ subtrm |
|
548 |
end |
|
35222
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
549 |
|
69593 | 550 |
| (Const (\<^const_name>\<open>Ex1\<close>, ty) $ t, Const (\<^const_name>\<open>Ex1\<close>, ty') $ t') => |
41444 | 551 |
let |
552 |
val subtrm = apply_subt (regularize_trm ctxt) (t, t') |
|
553 |
in |
|
69593 | 554 |
if ty = ty' then Const (\<^const_name>\<open>Ex1\<close>, ty) $ subtrm |
41444 | 555 |
else mk_bex1_rel $ (equiv_relation ctxt (qnt_typ ty, qnt_typ ty')) $ subtrm |
556 |
end |
|
35222
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
557 |
|
69593 | 558 |
| (Const (\<^const_name>\<open>Ball\<close>, ty) $ (Const (\<^const_name>\<open>Respects\<close>, _) $ resrel) $ t, |
559 |
Const (\<^const_name>\<open>All\<close>, ty') $ t') => |
|
41444 | 560 |
let |
561 |
val subtrm = apply_subt (regularize_trm ctxt) (t, t') |
|
562 |
val needrel = equiv_relation_chk ctxt (qnt_typ ty, qnt_typ ty') |
|
563 |
in |
|
564 |
if resrel <> needrel |
|
565 |
then term_mismatch "regularize (Ball)" ctxt resrel needrel |
|
566 |
else mk_ball $ (mk_resp $ resrel) $ subtrm |
|
567 |
end |
|
35222
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
568 |
|
69593 | 569 |
| (Const (\<^const_name>\<open>Bex\<close>, ty) $ (Const (\<^const_name>\<open>Respects\<close>, _) $ resrel) $ t, |
570 |
Const (\<^const_name>\<open>Ex\<close>, ty') $ t') => |
|
41444 | 571 |
let |
572 |
val subtrm = apply_subt (regularize_trm ctxt) (t, t') |
|
573 |
val needrel = equiv_relation_chk ctxt (qnt_typ ty, qnt_typ ty') |
|
574 |
in |
|
575 |
if resrel <> needrel |
|
576 |
then term_mismatch "regularize (Bex)" ctxt resrel needrel |
|
577 |
else mk_bex $ (mk_resp $ resrel) $ subtrm |
|
578 |
end |
|
35222
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
579 |
|
69593 | 580 |
| (Const (\<^const_name>\<open>Bex1_rel\<close>, ty) $ resrel $ t, Const (\<^const_name>\<open>Ex1\<close>, ty') $ t') => |
41444 | 581 |
let |
582 |
val subtrm = apply_subt (regularize_trm ctxt) (t, t') |
|
583 |
val needrel = equiv_relation_chk ctxt (qnt_typ ty, qnt_typ ty') |
|
584 |
in |
|
585 |
if resrel <> needrel |
|
586 |
then term_mismatch "regularize (Bex1_res)" ctxt resrel needrel |
|
587 |
else mk_bex1_rel $ resrel $ subtrm |
|
588 |
end |
|
35222
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
589 |
|
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
590 |
| (* equalities need to be replaced by appropriate equivalence relations *) |
69593 | 591 |
(Const (\<^const_name>\<open>HOL.eq\<close>, ty), Const (\<^const_name>\<open>HOL.eq\<close>, ty')) => |
41444 | 592 |
if ty = ty' then rtrm |
593 |
else equiv_relation ctxt (domain_type ty, domain_type ty') |
|
35222
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
594 |
|
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
595 |
| (* in this case we just check whether the given equivalence relation is correct *) |
69593 | 596 |
(rel, Const (\<^const_name>\<open>HOL.eq\<close>, ty')) => |
41444 | 597 |
let |
598 |
val rel_ty = fastype_of rel |
|
599 |
val rel' = equiv_relation_chk ctxt (domain_type rel_ty, domain_type ty') |
|
600 |
in |
|
601 |
if rel' aconv rel then rtrm |
|
602 |
else term_mismatch "regularize (relation mismatch)" ctxt rel rel' |
|
603 |
end |
|
35222
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
604 |
|
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
605 |
| (_, Const _) => |
41444 | 606 |
let |
42361 | 607 |
val thy = Proof_Context.theory_of ctxt |
80675 | 608 |
fun same_const t u = |
609 |
eq_Const_name (t, u) andalso matches_typ ctxt (dest_Const_type t) (dest_Const_type u) |
|
41444 | 610 |
in |
611 |
if same_const rtrm qtrm then rtrm |
|
612 |
else |
|
613 |
let |
|
45279 | 614 |
val rtrm' = |
45340
98ec8b51af9c
prefer global Quotient_Info lookup to accomodate Quotient_Term, which is not quite localized yet (cf. 9fd6fce8a230);
wenzelm
parents:
45280
diff
changeset
|
615 |
(case Quotient_Info.lookup_quotconsts_global thy qtrm of |
67632 | 616 |
SOME {rconst, ...} => rconst |
45279 | 617 |
| NONE => term_mismatch "regularize (constant not found)" ctxt rtrm qtrm) |
41444 | 618 |
in |
619 |
if Pattern.matches thy (rtrm', rtrm) |
|
620 |
then rtrm else term_mismatch "regularize (constant mismatch)" ctxt rtrm qtrm |
|
621 |
end |
|
622 |
end |
|
35222
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
623 |
|
69593 | 624 |
| (((t1 as Const (\<^const_name>\<open>case_prod\<close>, _)) $ Abs (v1, ty, Abs(v1', ty', s1))), |
625 |
((t2 as Const (\<^const_name>\<open>case_prod\<close>, _)) $ Abs (v2, _ , Abs(v2', _ , s2)))) => |
|
35222
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
626 |
regularize_trm ctxt (t1, t2) $ Abs (v1, ty, Abs (v1', ty', regularize_trm ctxt (s1, s2))) |
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
627 |
|
69593 | 628 |
| (((t1 as Const (\<^const_name>\<open>case_prod\<close>, _)) $ Abs (v1, ty, s1)), |
629 |
((t2 as Const (\<^const_name>\<open>case_prod\<close>, _)) $ Abs (v2, _ , s2))) => |
|
35222
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
630 |
regularize_trm ctxt (t1, t2) $ Abs (v1, ty, regularize_trm ctxt (s1, s2)) |
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
631 |
|
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
632 |
| (t1 $ t2, t1' $ t2') => |
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
633 |
regularize_trm ctxt (t1, t1') $ regularize_trm ctxt (t2, t2') |
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
634 |
|
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
635 |
| (Bound i, Bound i') => |
41444 | 636 |
if i = i' then rtrm |
637 |
else raise (LIFT_MATCH "regularize (bounds mismatch)") |
|
35222
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
638 |
|
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
639 |
| _ => |
41444 | 640 |
let |
641 |
val rtrm_str = Syntax.string_of_term ctxt rtrm |
|
642 |
val qtrm_str = Syntax.string_of_term ctxt qtrm |
|
643 |
in |
|
644 |
raise (LIFT_MATCH ("regularize failed (default: " ^ rtrm_str ^ "," ^ qtrm_str ^ ")")) |
|
45280 | 645 |
end) |
35222
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
646 |
|
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
647 |
fun regularize_trm_chk ctxt (rtrm, qtrm) = |
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
648 |
regularize_trm ctxt (rtrm, qtrm) |
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
649 |
|> Syntax.check_term ctxt |
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
650 |
|
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
651 |
|
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
652 |
|
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
653 |
(*** Rep/Abs Injection ***) |
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
654 |
|
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
655 |
(* |
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
656 |
Injection of Rep/Abs means: |
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
657 |
|
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
658 |
For abstractions: |
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
659 |
|
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
660 |
* If the type of the abstraction needs lifting, then we add Rep/Abs |
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
661 |
around the abstraction; otherwise we leave it unchanged. |
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
662 |
|
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
663 |
For applications: |
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
664 |
|
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
665 |
* If the application involves a bounded quantifier, we recurse on |
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
666 |
the second argument. If the application is a bounded abstraction, |
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
667 |
we always put an Rep/Abs around it (since bounded abstractions |
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
668 |
are assumed to always need lifting). Otherwise we recurse on both |
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
669 |
arguments. |
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
670 |
|
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
671 |
For constants: |
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
672 |
|
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
673 |
* If the constant is (op =), we leave it always unchanged. |
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
674 |
Otherwise the type of the constant needs lifting, we put |
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
675 |
and Rep/Abs around it. |
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
676 |
|
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
677 |
For free variables: |
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
678 |
|
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
679 |
* We put a Rep/Abs around it if the type needs lifting. |
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
680 |
|
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
681 |
Vars case cannot occur. |
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
682 |
*) |
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
683 |
|
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
684 |
fun mk_repabs ctxt (T, T') trm = |
45797 | 685 |
absrep_fun ctxt RepF (T, T') $ (absrep_fun ctxt AbsF (T, T') $ trm) |
35222
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
686 |
|
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
687 |
fun inj_repabs_err ctxt msg rtrm qtrm = |
41444 | 688 |
let |
689 |
val rtrm_str = Syntax.string_of_term ctxt rtrm |
|
690 |
val qtrm_str = Syntax.string_of_term ctxt qtrm |
|
691 |
in |
|
692 |
raise LIFT_MATCH (space_implode " " [msg, quote rtrm_str, "and", quote qtrm_str]) |
|
693 |
end |
|
35222
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
694 |
|
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
695 |
|
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
696 |
(* bound variables need to be treated properly, |
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
697 |
as the type of subterms needs to be calculated *) |
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
698 |
fun inj_repabs_trm ctxt (rtrm, qtrm) = |
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
699 |
case (rtrm, qtrm) of |
69593 | 700 |
(Const (\<^const_name>\<open>Ball\<close>, T) $ r $ t, Const (\<^const_name>\<open>All\<close>, _) $ t') => |
701 |
Const (\<^const_name>\<open>Ball\<close>, T) $ r $ (inj_repabs_trm ctxt (t, t')) |
|
35222
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
702 |
|
69593 | 703 |
| (Const (\<^const_name>\<open>Bex\<close>, T) $ r $ t, Const (\<^const_name>\<open>Ex\<close>, _) $ t') => |
704 |
Const (\<^const_name>\<open>Bex\<close>, T) $ r $ (inj_repabs_trm ctxt (t, t')) |
|
35222
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
705 |
|
69593 | 706 |
| (Const (\<^const_name>\<open>Babs\<close>, T) $ r $ t, t' as (Abs _)) => |
35222
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
707 |
let |
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
708 |
val rty = fastype_of rtrm |
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
709 |
val qty = fastype_of qtrm |
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
710 |
in |
69593 | 711 |
mk_repabs ctxt (rty, qty) (Const (\<^const_name>\<open>Babs\<close>, T) $ r $ (inj_repabs_trm ctxt (t, t'))) |
35222
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
712 |
end |
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
713 |
|
74525
c960bfcb91db
discontinued Term.dest_abs / Logic.dest_all, which are officially superseded by Variable.dest_abs etc., but there are also Term.dest_abs_global to recover existing tools easily;
wenzelm
parents:
69593
diff
changeset
|
714 |
| (t as Abs _, t' as Abs _) => |
35222
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
715 |
let |
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
716 |
val rty = fastype_of rtrm |
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
717 |
val qty = fastype_of qtrm |
74525
c960bfcb91db
discontinued Term.dest_abs / Logic.dest_all, which are officially superseded by Variable.dest_abs etc., but there are also Term.dest_abs_global to recover existing tools easily;
wenzelm
parents:
69593
diff
changeset
|
718 |
val ((y, T), s) = Term.dest_abs_global t |
c960bfcb91db
discontinued Term.dest_abs / Logic.dest_all, which are officially superseded by Variable.dest_abs etc., but there are also Term.dest_abs_global to recover existing tools easily;
wenzelm
parents:
69593
diff
changeset
|
719 |
val (_, s') = Term.dest_abs_global t' |
35222
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
720 |
val yvar = Free (y, T) |
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
721 |
val result = Term.lambda_name (y, yvar) (inj_repabs_trm ctxt (s, s')) |
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
722 |
in |
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
723 |
if rty = qty then result |
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
724 |
else mk_repabs ctxt (rty, qty) result |
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
725 |
end |
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
726 |
|
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
727 |
| (t $ s, t' $ s') => |
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
728 |
(inj_repabs_trm ctxt (t, t')) $ (inj_repabs_trm ctxt (s, s')) |
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
729 |
|
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
730 |
| (Free (_, T), Free (_, T')) => |
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
731 |
if T = T' then rtrm |
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
732 |
else mk_repabs ctxt (T, T') rtrm |
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
733 |
|
69593 | 734 |
| (_, Const (\<^const_name>\<open>HOL.eq\<close>, _)) => rtrm |
35222
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
735 |
|
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
736 |
| (_, Const (_, T')) => |
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
737 |
let |
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
738 |
val rty = fastype_of rtrm |
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
739 |
in |
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
740 |
if rty = T' then rtrm |
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
741 |
else mk_repabs ctxt (rty, T') rtrm |
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
742 |
end |
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
743 |
|
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
744 |
| _ => inj_repabs_err ctxt "injection (default):" rtrm qtrm |
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
745 |
|
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
746 |
fun inj_repabs_trm_chk ctxt (rtrm, qtrm) = |
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
747 |
inj_repabs_trm ctxt (rtrm, qtrm) |
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
748 |
|> Syntax.check_term ctxt |
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
749 |
|
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
750 |
|
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
751 |
|
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
752 |
(*** Wrapper for automatically transforming an rthm into a qthm ***) |
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
753 |
|
37592
e16495cfdde0
separation of translations in derive_qtrm / derive_rtrm (similarly for types)
Christian Urban <urbanc@in.tum.de>
parents:
37591
diff
changeset
|
754 |
(* substitutions functions for r/q-types and |
e16495cfdde0
separation of translations in derive_qtrm / derive_rtrm (similarly for types)
Christian Urban <urbanc@in.tum.de>
parents:
37591
diff
changeset
|
755 |
r/q-constants, respectively |
37560
1b5bbc4a14bc
streamlined the generation of quotient theorems out of raw theorems
Christian Urban <urbanc@in.tum.de>
parents:
37532
diff
changeset
|
756 |
*) |
37592
e16495cfdde0
separation of translations in derive_qtrm / derive_rtrm (similarly for types)
Christian Urban <urbanc@in.tum.de>
parents:
37591
diff
changeset
|
757 |
fun subst_typ ctxt ty_subst rty = |
37560
1b5bbc4a14bc
streamlined the generation of quotient theorems out of raw theorems
Christian Urban <urbanc@in.tum.de>
parents:
37532
diff
changeset
|
758 |
case rty of |
1b5bbc4a14bc
streamlined the generation of quotient theorems out of raw theorems
Christian Urban <urbanc@in.tum.de>
parents:
37532
diff
changeset
|
759 |
Type (s, rtys) => |
1b5bbc4a14bc
streamlined the generation of quotient theorems out of raw theorems
Christian Urban <urbanc@in.tum.de>
parents:
37532
diff
changeset
|
760 |
let |
42361 | 761 |
val thy = Proof_Context.theory_of ctxt |
37592
e16495cfdde0
separation of translations in derive_qtrm / derive_rtrm (similarly for types)
Christian Urban <urbanc@in.tum.de>
parents:
37591
diff
changeset
|
762 |
val rty' = Type (s, map (subst_typ ctxt ty_subst) rtys) |
37560
1b5bbc4a14bc
streamlined the generation of quotient theorems out of raw theorems
Christian Urban <urbanc@in.tum.de>
parents:
37532
diff
changeset
|
763 |
|
1b5bbc4a14bc
streamlined the generation of quotient theorems out of raw theorems
Christian Urban <urbanc@in.tum.de>
parents:
37532
diff
changeset
|
764 |
fun matches [] = rty' |
1b5bbc4a14bc
streamlined the generation of quotient theorems out of raw theorems
Christian Urban <urbanc@in.tum.de>
parents:
37532
diff
changeset
|
765 |
| matches ((rty, qty)::tail) = |
45280 | 766 |
(case try (Sign.typ_match thy (rty, rty')) Vartab.empty of |
37560
1b5bbc4a14bc
streamlined the generation of quotient theorems out of raw theorems
Christian Urban <urbanc@in.tum.de>
parents:
37532
diff
changeset
|
767 |
NONE => matches tail |
46416
5f5665a0b973
Make automatic derivation of raw/quotient types more greedy to allow descending and quot_lifted for compound quotients.
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
45797
diff
changeset
|
768 |
| SOME inst => subst_typ ctxt ty_subst (Envir.subst_type inst qty)) |
37560
1b5bbc4a14bc
streamlined the generation of quotient theorems out of raw theorems
Christian Urban <urbanc@in.tum.de>
parents:
37532
diff
changeset
|
769 |
in |
41444 | 770 |
matches ty_subst |
771 |
end |
|
37560
1b5bbc4a14bc
streamlined the generation of quotient theorems out of raw theorems
Christian Urban <urbanc@in.tum.de>
parents:
37532
diff
changeset
|
772 |
| _ => rty |
1b5bbc4a14bc
streamlined the generation of quotient theorems out of raw theorems
Christian Urban <urbanc@in.tum.de>
parents:
37532
diff
changeset
|
773 |
|
37592
e16495cfdde0
separation of translations in derive_qtrm / derive_rtrm (similarly for types)
Christian Urban <urbanc@in.tum.de>
parents:
37591
diff
changeset
|
774 |
fun subst_trm ctxt ty_subst trm_subst rtrm = |
37560
1b5bbc4a14bc
streamlined the generation of quotient theorems out of raw theorems
Christian Urban <urbanc@in.tum.de>
parents:
37532
diff
changeset
|
775 |
case rtrm of |
37592
e16495cfdde0
separation of translations in derive_qtrm / derive_rtrm (similarly for types)
Christian Urban <urbanc@in.tum.de>
parents:
37591
diff
changeset
|
776 |
t1 $ t2 => (subst_trm ctxt ty_subst trm_subst t1) $ (subst_trm ctxt ty_subst trm_subst t2) |
e16495cfdde0
separation of translations in derive_qtrm / derive_rtrm (similarly for types)
Christian Urban <urbanc@in.tum.de>
parents:
37591
diff
changeset
|
777 |
| Abs (x, ty, t) => Abs (x, subst_typ ctxt ty_subst ty, subst_trm ctxt ty_subst trm_subst t) |
e16495cfdde0
separation of translations in derive_qtrm / derive_rtrm (similarly for types)
Christian Urban <urbanc@in.tum.de>
parents:
37591
diff
changeset
|
778 |
| Free(n, ty) => Free(n, subst_typ ctxt ty_subst ty) |
e16495cfdde0
separation of translations in derive_qtrm / derive_rtrm (similarly for types)
Christian Urban <urbanc@in.tum.de>
parents:
37591
diff
changeset
|
779 |
| Var(n, ty) => Var(n, subst_typ ctxt ty_subst ty) |
37560
1b5bbc4a14bc
streamlined the generation of quotient theorems out of raw theorems
Christian Urban <urbanc@in.tum.de>
parents:
37532
diff
changeset
|
780 |
| Bound i => Bound i |
41444 | 781 |
| Const (a, ty) => |
37560
1b5bbc4a14bc
streamlined the generation of quotient theorems out of raw theorems
Christian Urban <urbanc@in.tum.de>
parents:
37532
diff
changeset
|
782 |
let |
42361 | 783 |
val thy = Proof_Context.theory_of ctxt |
35222
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
784 |
|
37592
e16495cfdde0
separation of translations in derive_qtrm / derive_rtrm (similarly for types)
Christian Urban <urbanc@in.tum.de>
parents:
37591
diff
changeset
|
785 |
fun matches [] = Const (a, subst_typ ctxt ty_subst ty) |
37560
1b5bbc4a14bc
streamlined the generation of quotient theorems out of raw theorems
Christian Urban <urbanc@in.tum.de>
parents:
37532
diff
changeset
|
786 |
| matches ((rconst, qconst)::tail) = |
45280 | 787 |
(case try (Pattern.match thy (rconst, rtrm)) (Vartab.empty, Vartab.empty) of |
37560
1b5bbc4a14bc
streamlined the generation of quotient theorems out of raw theorems
Christian Urban <urbanc@in.tum.de>
parents:
37532
diff
changeset
|
788 |
NONE => matches tail |
46416
5f5665a0b973
Make automatic derivation of raw/quotient types more greedy to allow descending and quot_lifted for compound quotients.
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
45797
diff
changeset
|
789 |
| SOME inst => subst_trm ctxt ty_subst trm_subst (Envir.subst_term inst qconst)) |
37560
1b5bbc4a14bc
streamlined the generation of quotient theorems out of raw theorems
Christian Urban <urbanc@in.tum.de>
parents:
37532
diff
changeset
|
790 |
in |
1b5bbc4a14bc
streamlined the generation of quotient theorems out of raw theorems
Christian Urban <urbanc@in.tum.de>
parents:
37532
diff
changeset
|
791 |
matches trm_subst |
1b5bbc4a14bc
streamlined the generation of quotient theorems out of raw theorems
Christian Urban <urbanc@in.tum.de>
parents:
37532
diff
changeset
|
792 |
end |
1b5bbc4a14bc
streamlined the generation of quotient theorems out of raw theorems
Christian Urban <urbanc@in.tum.de>
parents:
37532
diff
changeset
|
793 |
|
37592
e16495cfdde0
separation of translations in derive_qtrm / derive_rtrm (similarly for types)
Christian Urban <urbanc@in.tum.de>
parents:
37591
diff
changeset
|
794 |
(* generate type and term substitutions out of the |
41444 | 795 |
qtypes involved in a quotient; the direction flag |
796 |
indicates in which direction the substitutions work: |
|
797 |
||
37592
e16495cfdde0
separation of translations in derive_qtrm / derive_rtrm (similarly for types)
Christian Urban <urbanc@in.tum.de>
parents:
37591
diff
changeset
|
798 |
true: quotient -> raw |
e16495cfdde0
separation of translations in derive_qtrm / derive_rtrm (similarly for types)
Christian Urban <urbanc@in.tum.de>
parents:
37591
diff
changeset
|
799 |
false: raw -> quotient |
37560
1b5bbc4a14bc
streamlined the generation of quotient theorems out of raw theorems
Christian Urban <urbanc@in.tum.de>
parents:
37532
diff
changeset
|
800 |
*) |
37592
e16495cfdde0
separation of translations in derive_qtrm / derive_rtrm (similarly for types)
Christian Urban <urbanc@in.tum.de>
parents:
37591
diff
changeset
|
801 |
fun mk_ty_subst qtys direction ctxt = |
41444 | 802 |
let |
42361 | 803 |
val thy = Proof_Context.theory_of ctxt |
41444 | 804 |
in |
45279 | 805 |
Quotient_Info.dest_quotients ctxt |
41444 | 806 |
|> map (fn x => (#rtyp x, #qtyp x)) |
807 |
|> filter (fn (_, qty) => member (Sign.typ_instance thy o swap) qtys qty) |
|
808 |
|> map (if direction then swap else I) |
|
809 |
end |
|
35222
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
810 |
|
37592
e16495cfdde0
separation of translations in derive_qtrm / derive_rtrm (similarly for types)
Christian Urban <urbanc@in.tum.de>
parents:
37591
diff
changeset
|
811 |
fun mk_trm_subst qtys direction ctxt = |
41444 | 812 |
let |
813 |
val subst_typ' = subst_typ ctxt (mk_ty_subst qtys direction ctxt) |
|
814 |
fun proper (t1, t2) = subst_typ' (fastype_of t1) = fastype_of t2 |
|
37563
6cf28a1dfd75
Add reverse lifting flag to automated theorem derivation
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
37560
diff
changeset
|
815 |
|
41444 | 816 |
val const_substs = |
45279 | 817 |
Quotient_Info.dest_quotconsts ctxt |
41444 | 818 |
|> map (fn x => (#rconst x, #qconst x)) |
819 |
|> map (if direction then swap else I) |
|
37560
1b5bbc4a14bc
streamlined the generation of quotient theorems out of raw theorems
Christian Urban <urbanc@in.tum.de>
parents:
37532
diff
changeset
|
820 |
|
41444 | 821 |
val rel_substs = |
45279 | 822 |
Quotient_Info.dest_quotients ctxt |
41444 | 823 |
|> map (fn x => (#equiv_rel x, HOLogic.eq_const (#qtyp x))) |
824 |
|> map (if direction then swap else I) |
|
825 |
in |
|
826 |
filter proper (const_substs @ rel_substs) |
|
827 |
end |
|
35222
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
828 |
|
37592
e16495cfdde0
separation of translations in derive_qtrm / derive_rtrm (similarly for types)
Christian Urban <urbanc@in.tum.de>
parents:
37591
diff
changeset
|
829 |
|
37560
1b5bbc4a14bc
streamlined the generation of quotient theorems out of raw theorems
Christian Urban <urbanc@in.tum.de>
parents:
37532
diff
changeset
|
830 |
(* derives a qtyp and qtrm out of a rtyp and rtrm, |
41444 | 831 |
respectively |
37560
1b5bbc4a14bc
streamlined the generation of quotient theorems out of raw theorems
Christian Urban <urbanc@in.tum.de>
parents:
37532
diff
changeset
|
832 |
*) |
38624
9bb0016f7e60
changed to a more convenient argument order
Christian Urban <urbanc@in.tum.de>
parents:
38558
diff
changeset
|
833 |
fun derive_qtyp ctxt qtys rty = |
37592
e16495cfdde0
separation of translations in derive_qtrm / derive_rtrm (similarly for types)
Christian Urban <urbanc@in.tum.de>
parents:
37591
diff
changeset
|
834 |
subst_typ ctxt (mk_ty_subst qtys false ctxt) rty |
e16495cfdde0
separation of translations in derive_qtrm / derive_rtrm (similarly for types)
Christian Urban <urbanc@in.tum.de>
parents:
37591
diff
changeset
|
835 |
|
38624
9bb0016f7e60
changed to a more convenient argument order
Christian Urban <urbanc@in.tum.de>
parents:
38558
diff
changeset
|
836 |
fun derive_qtrm ctxt qtys rtrm = |
37592
e16495cfdde0
separation of translations in derive_qtrm / derive_rtrm (similarly for types)
Christian Urban <urbanc@in.tum.de>
parents:
37591
diff
changeset
|
837 |
subst_trm ctxt (mk_ty_subst qtys false ctxt) (mk_trm_subst qtys false ctxt) rtrm |
35222
4f1fba00f66d
Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
838 |
|
37592
e16495cfdde0
separation of translations in derive_qtrm / derive_rtrm (similarly for types)
Christian Urban <urbanc@in.tum.de>
parents:
37591
diff
changeset
|
839 |
(* derives a rtyp and rtrm out of a qtyp and qtrm, |
41444 | 840 |
respectively |
37592
e16495cfdde0
separation of translations in derive_qtrm / derive_rtrm (similarly for types)
Christian Urban <urbanc@in.tum.de>
parents:
37591
diff
changeset
|
841 |
*) |
38624
9bb0016f7e60
changed to a more convenient argument order
Christian Urban <urbanc@in.tum.de>
parents:
38558
diff
changeset
|
842 |
fun derive_rtyp ctxt qtys qty = |
37592
e16495cfdde0
separation of translations in derive_qtrm / derive_rtrm (similarly for types)
Christian Urban <urbanc@in.tum.de>
parents:
37591
diff
changeset
|
843 |
subst_typ ctxt (mk_ty_subst qtys true ctxt) qty |
e16495cfdde0
separation of translations in derive_qtrm / derive_rtrm (similarly for types)
Christian Urban <urbanc@in.tum.de>
parents:
37591
diff
changeset
|
844 |
|
38624
9bb0016f7e60
changed to a more convenient argument order
Christian Urban <urbanc@in.tum.de>
parents:
38558
diff
changeset
|
845 |
fun derive_rtrm ctxt qtys qtrm = |
37592
e16495cfdde0
separation of translations in derive_qtrm / derive_rtrm (similarly for types)
Christian Urban <urbanc@in.tum.de>
parents:
37591
diff
changeset
|
846 |
subst_trm ctxt (mk_ty_subst qtys true ctxt) (mk_trm_subst qtys true ctxt) qtrm |
37560
1b5bbc4a14bc
streamlined the generation of quotient theorems out of raw theorems
Christian Urban <urbanc@in.tum.de>
parents:
37532
diff
changeset
|
847 |
|
45279 | 848 |
end; |