author | Christian Urban <urbanc@in.tum.de> |
Mon, 11 Jan 2010 01:03:34 +0100 | |
changeset 834 | fb7fe6aca6f0 |
parent 833 | 129caba33c03 |
child 835 | c4fa87dd0208 |
permissions | -rw-r--r-- |
758
3104d62e7a16
moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
1 |
signature QUOTIENT_TERM = |
3104d62e7a16
moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
2 |
sig |
774
b4ffb8826105
moved get_fun into quotient_term; this simplifies the overall including structure of the package
Christian Urban <urbanc@in.tum.de>
parents:
762
diff
changeset
|
3 |
exception LIFT_MATCH of string |
b4ffb8826105
moved get_fun into quotient_term; this simplifies the overall including structure of the package
Christian Urban <urbanc@in.tum.de>
parents:
762
diff
changeset
|
4 |
|
b4ffb8826105
moved get_fun into quotient_term; this simplifies the overall including structure of the package
Christian Urban <urbanc@in.tum.de>
parents:
762
diff
changeset
|
5 |
datatype flag = absF | repF |
776
d1064fa29424
renamed get_fun to absrep_fun; introduced explicit checked versions of the term functions
Christian Urban <urbanc@in.tum.de>
parents:
775
diff
changeset
|
6 |
|
d1064fa29424
renamed get_fun to absrep_fun; introduced explicit checked versions of the term functions
Christian Urban <urbanc@in.tum.de>
parents:
775
diff
changeset
|
7 |
val absrep_fun: flag -> Proof.context -> (typ * typ) -> term |
d1064fa29424
renamed get_fun to absrep_fun; introduced explicit checked versions of the term functions
Christian Urban <urbanc@in.tum.de>
parents:
775
diff
changeset
|
8 |
val absrep_fun_chk: flag -> Proof.context -> (typ * typ) -> term |
774
b4ffb8826105
moved get_fun into quotient_term; this simplifies the overall including structure of the package
Christian Urban <urbanc@in.tum.de>
parents:
762
diff
changeset
|
9 |
|
795
a28f805df355
renamed mk_resp_arg to equiv_relation and exported it in the signature; added tests in AbsRepFun.thy
Christian Urban <urbanc@in.tum.de>
parents:
792
diff
changeset
|
10 |
val equiv_relation: Proof.context -> (typ * typ) -> term |
a28f805df355
renamed mk_resp_arg to equiv_relation and exported it in the signature; added tests in AbsRepFun.thy
Christian Urban <urbanc@in.tum.de>
parents:
792
diff
changeset
|
11 |
val equiv_relation_chk: Proof.context -> (typ * typ) -> term |
a28f805df355
renamed mk_resp_arg to equiv_relation and exported it in the signature; added tests in AbsRepFun.thy
Christian Urban <urbanc@in.tum.de>
parents:
792
diff
changeset
|
12 |
|
775 | 13 |
val regularize_trm: Proof.context -> (term * term) -> term |
776
d1064fa29424
renamed get_fun to absrep_fun; introduced explicit checked versions of the term functions
Christian Urban <urbanc@in.tum.de>
parents:
775
diff
changeset
|
14 |
val regularize_trm_chk: Proof.context -> (term * term) -> term |
d1064fa29424
renamed get_fun to absrep_fun; introduced explicit checked versions of the term functions
Christian Urban <urbanc@in.tum.de>
parents:
775
diff
changeset
|
15 |
|
774
b4ffb8826105
moved get_fun into quotient_term; this simplifies the overall including structure of the package
Christian Urban <urbanc@in.tum.de>
parents:
762
diff
changeset
|
16 |
val inj_repabs_trm: Proof.context -> (term * term) -> term |
776
d1064fa29424
renamed get_fun to absrep_fun; introduced explicit checked versions of the term functions
Christian Urban <urbanc@in.tum.de>
parents:
775
diff
changeset
|
17 |
val inj_repabs_trm_chk: Proof.context -> (term * term) -> term |
758
3104d62e7a16
moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
18 |
end; |
3104d62e7a16
moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
19 |
|
3104d62e7a16
moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
20 |
structure Quotient_Term: QUOTIENT_TERM = |
3104d62e7a16
moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
21 |
struct |
3104d62e7a16
moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
22 |
|
762
baac4639ecef
avoided global "open"s - replaced by local "open"s
Christian Urban <urbanc@in.tum.de>
parents:
761
diff
changeset
|
23 |
open Quotient_Info; |
774
b4ffb8826105
moved get_fun into quotient_term; this simplifies the overall including structure of the package
Christian Urban <urbanc@in.tum.de>
parents:
762
diff
changeset
|
24 |
|
b4ffb8826105
moved get_fun into quotient_term; this simplifies the overall including structure of the package
Christian Urban <urbanc@in.tum.de>
parents:
762
diff
changeset
|
25 |
exception LIFT_MATCH of string |
b4ffb8826105
moved get_fun into quotient_term; this simplifies the overall including structure of the package
Christian Urban <urbanc@in.tum.de>
parents:
762
diff
changeset
|
26 |
|
833
129caba33c03
the chk-functions in quotient_term also simplify the result according to the id_simps; had to remove id_def from this theorem list though; this caused in FSet3 that relied on this rule; the problem is marked with "ID PROBLEM"
Christian Urban <urbanc@in.tum.de>
parents:
832
diff
changeset
|
27 |
(* simplifies a term according to the id_rules *) |
129caba33c03
the chk-functions in quotient_term also simplify the result according to the id_simps; had to remove id_def from this theorem list though; this caused in FSet3 that relied on this rule; the problem is marked with "ID PROBLEM"
Christian Urban <urbanc@in.tum.de>
parents:
832
diff
changeset
|
28 |
fun id_simplify ctxt trm = |
129caba33c03
the chk-functions in quotient_term also simplify the result according to the id_simps; had to remove id_def from this theorem list though; this caused in FSet3 that relied on this rule; the problem is marked with "ID PROBLEM"
Christian Urban <urbanc@in.tum.de>
parents:
832
diff
changeset
|
29 |
let |
129caba33c03
the chk-functions in quotient_term also simplify the result according to the id_simps; had to remove id_def from this theorem list though; this caused in FSet3 that relied on this rule; the problem is marked with "ID PROBLEM"
Christian Urban <urbanc@in.tum.de>
parents:
832
diff
changeset
|
30 |
val thy = ProofContext.theory_of ctxt |
129caba33c03
the chk-functions in quotient_term also simplify the result according to the id_simps; had to remove id_def from this theorem list though; this caused in FSet3 that relied on this rule; the problem is marked with "ID PROBLEM"
Christian Urban <urbanc@in.tum.de>
parents:
832
diff
changeset
|
31 |
val id_thms = id_simps_get ctxt |
129caba33c03
the chk-functions in quotient_term also simplify the result according to the id_simps; had to remove id_def from this theorem list though; this caused in FSet3 that relied on this rule; the problem is marked with "ID PROBLEM"
Christian Urban <urbanc@in.tum.de>
parents:
832
diff
changeset
|
32 |
in |
129caba33c03
the chk-functions in quotient_term also simplify the result according to the id_simps; had to remove id_def from this theorem list though; this caused in FSet3 that relied on this rule; the problem is marked with "ID PROBLEM"
Christian Urban <urbanc@in.tum.de>
parents:
832
diff
changeset
|
33 |
MetaSimplifier.rewrite_term thy id_thms [] trm |
129caba33c03
the chk-functions in quotient_term also simplify the result according to the id_simps; had to remove id_def from this theorem list though; this caused in FSet3 that relied on this rule; the problem is marked with "ID PROBLEM"
Christian Urban <urbanc@in.tum.de>
parents:
832
diff
changeset
|
34 |
end |
129caba33c03
the chk-functions in quotient_term also simplify the result according to the id_simps; had to remove id_def from this theorem list though; this caused in FSet3 that relied on this rule; the problem is marked with "ID PROBLEM"
Christian Urban <urbanc@in.tum.de>
parents:
832
diff
changeset
|
35 |
|
791
fb4bfbb1a291
commeted the absrep function
Christian Urban <urbanc@in.tum.de>
parents:
790
diff
changeset
|
36 |
(******************************) |
fb4bfbb1a291
commeted the absrep function
Christian Urban <urbanc@in.tum.de>
parents:
790
diff
changeset
|
37 |
(* Aggregate Rep/Abs Function *) |
fb4bfbb1a291
commeted the absrep function
Christian Urban <urbanc@in.tum.de>
parents:
790
diff
changeset
|
38 |
(******************************) |
779
3b21b24a5fb6
corrected map declarations for Sum and Prod; moved absrep_fun examples in separate file
Christian Urban <urbanc@in.tum.de>
parents:
776
diff
changeset
|
39 |
|
791
fb4bfbb1a291
commeted the absrep function
Christian Urban <urbanc@in.tum.de>
parents:
790
diff
changeset
|
40 |
(* The flag repF is for types in negative position; absF is for types *) |
fb4bfbb1a291
commeted the absrep function
Christian Urban <urbanc@in.tum.de>
parents:
790
diff
changeset
|
41 |
(* in positive position. Because of this, function types need to be *) |
fb4bfbb1a291
commeted the absrep function
Christian Urban <urbanc@in.tum.de>
parents:
790
diff
changeset
|
42 |
(* treated specially, since there the polarity changes. *) |
774
b4ffb8826105
moved get_fun into quotient_term; this simplifies the overall including structure of the package
Christian Urban <urbanc@in.tum.de>
parents:
762
diff
changeset
|
43 |
|
b4ffb8826105
moved get_fun into quotient_term; this simplifies the overall including structure of the package
Christian Urban <urbanc@in.tum.de>
parents:
762
diff
changeset
|
44 |
datatype flag = absF | repF |
b4ffb8826105
moved get_fun into quotient_term; this simplifies the overall including structure of the package
Christian Urban <urbanc@in.tum.de>
parents:
762
diff
changeset
|
45 |
|
b4ffb8826105
moved get_fun into quotient_term; this simplifies the overall including structure of the package
Christian Urban <urbanc@in.tum.de>
parents:
762
diff
changeset
|
46 |
fun negF absF = repF |
b4ffb8826105
moved get_fun into quotient_term; this simplifies the overall including structure of the package
Christian Urban <urbanc@in.tum.de>
parents:
762
diff
changeset
|
47 |
| negF repF = absF |
b4ffb8826105
moved get_fun into quotient_term; this simplifies the overall including structure of the package
Christian Urban <urbanc@in.tum.de>
parents:
762
diff
changeset
|
48 |
|
b4ffb8826105
moved get_fun into quotient_term; this simplifies the overall including structure of the package
Christian Urban <urbanc@in.tum.de>
parents:
762
diff
changeset
|
49 |
fun mk_identity ty = Const (@{const_name "id"}, ty --> ty) |
b4ffb8826105
moved get_fun into quotient_term; this simplifies the overall including structure of the package
Christian Urban <urbanc@in.tum.de>
parents:
762
diff
changeset
|
50 |
|
807
a5495a323b49
added a new version of equiv_relation (is not yet used anywhere except in AbsRepTest)
Christian Urban <urbanc@in.tum.de>
parents:
804
diff
changeset
|
51 |
fun mk_fun_compose flag (trm1, trm2) = |
774
b4ffb8826105
moved get_fun into quotient_term; this simplifies the overall including structure of the package
Christian Urban <urbanc@in.tum.de>
parents:
762
diff
changeset
|
52 |
case flag of |
b4ffb8826105
moved get_fun into quotient_term; this simplifies the overall including structure of the package
Christian Urban <urbanc@in.tum.de>
parents:
762
diff
changeset
|
53 |
absF => Const (@{const_name "comp"}, dummyT) $ trm1 $ trm2 |
b4ffb8826105
moved get_fun into quotient_term; this simplifies the overall including structure of the package
Christian Urban <urbanc@in.tum.de>
parents:
762
diff
changeset
|
54 |
| repF => Const (@{const_name "comp"}, dummyT) $ trm2 $ trm1 |
b4ffb8826105
moved get_fun into quotient_term; this simplifies the overall including structure of the package
Christian Urban <urbanc@in.tum.de>
parents:
762
diff
changeset
|
55 |
|
790
3a48ffcf0f9a
generalised absrep function; needs consolidation
Christian Urban <urbanc@in.tum.de>
parents:
786
diff
changeset
|
56 |
fun get_mapfun ctxt s = |
774
b4ffb8826105
moved get_fun into quotient_term; this simplifies the overall including structure of the package
Christian Urban <urbanc@in.tum.de>
parents:
762
diff
changeset
|
57 |
let |
779
3b21b24a5fb6
corrected map declarations for Sum and Prod; moved absrep_fun examples in separate file
Christian Urban <urbanc@in.tum.de>
parents:
776
diff
changeset
|
58 |
val thy = ProofContext.theory_of ctxt |
790
3a48ffcf0f9a
generalised absrep function; needs consolidation
Christian Urban <urbanc@in.tum.de>
parents:
786
diff
changeset
|
59 |
val exc = LIFT_MATCH ("No map function for type " ^ (quote s) ^ " found.") |
3a48ffcf0f9a
generalised absrep function; needs consolidation
Christian Urban <urbanc@in.tum.de>
parents:
786
diff
changeset
|
60 |
val mapfun = #mapfun (maps_lookup thy s) handle NotFound => raise exc |
774
b4ffb8826105
moved get_fun into quotient_term; this simplifies the overall including structure of the package
Christian Urban <urbanc@in.tum.de>
parents:
762
diff
changeset
|
61 |
in |
784
da75568e7f12
renamed some fields in the info records
Christian Urban <urbanc@in.tum.de>
parents:
783
diff
changeset
|
62 |
Const (mapfun, dummyT) |
774
b4ffb8826105
moved get_fun into quotient_term; this simplifies the overall including structure of the package
Christian Urban <urbanc@in.tum.de>
parents:
762
diff
changeset
|
63 |
end |
b4ffb8826105
moved get_fun into quotient_term; this simplifies the overall including structure of the package
Christian Urban <urbanc@in.tum.de>
parents:
762
diff
changeset
|
64 |
|
800 | 65 |
(* makes a Free out of a TVar *) |
66 |
fun mk_Free (TVar ((x, i), _)) = Free (unprefix "'" x ^ string_of_int i, dummyT) |
|
67 |
||
791
fb4bfbb1a291
commeted the absrep function
Christian Urban <urbanc@in.tum.de>
parents:
790
diff
changeset
|
68 |
(* produces an aggregate map function for the *) |
fb4bfbb1a291
commeted the absrep function
Christian Urban <urbanc@in.tum.de>
parents:
790
diff
changeset
|
69 |
(* rty-part of a quotient definition; abstracts *) |
fb4bfbb1a291
commeted the absrep function
Christian Urban <urbanc@in.tum.de>
parents:
790
diff
changeset
|
70 |
(* over all variables listed in vs (these variables *) |
795
a28f805df355
renamed mk_resp_arg to equiv_relation and exported it in the signature; added tests in AbsRepFun.thy
Christian Urban <urbanc@in.tum.de>
parents:
792
diff
changeset
|
71 |
(* correspond to the type variables in rty) *) |
800 | 72 |
(* *) |
803
6f6ee78c7357
a slight change to abs/rep generation
Christian Urban <urbanc@in.tum.de>
parents:
801
diff
changeset
|
73 |
(* for example for: (?'a list * ?'b) *) |
6f6ee78c7357
a slight change to abs/rep generation
Christian Urban <urbanc@in.tum.de>
parents:
801
diff
changeset
|
74 |
(* it produces: %a b. prod_map (map a) b *) |
6f6ee78c7357
a slight change to abs/rep generation
Christian Urban <urbanc@in.tum.de>
parents:
801
diff
changeset
|
75 |
fun mk_mapfun ctxt vs rty = |
790
3a48ffcf0f9a
generalised absrep function; needs consolidation
Christian Urban <urbanc@in.tum.de>
parents:
786
diff
changeset
|
76 |
let |
3a48ffcf0f9a
generalised absrep function; needs consolidation
Christian Urban <urbanc@in.tum.de>
parents:
786
diff
changeset
|
77 |
val vs' = map (mk_Free) vs |
3a48ffcf0f9a
generalised absrep function; needs consolidation
Christian Urban <urbanc@in.tum.de>
parents:
786
diff
changeset
|
78 |
|
803
6f6ee78c7357
a slight change to abs/rep generation
Christian Urban <urbanc@in.tum.de>
parents:
801
diff
changeset
|
79 |
fun mk_mapfun_aux rty = |
6f6ee78c7357
a slight change to abs/rep generation
Christian Urban <urbanc@in.tum.de>
parents:
801
diff
changeset
|
80 |
case rty of |
6f6ee78c7357
a slight change to abs/rep generation
Christian Urban <urbanc@in.tum.de>
parents:
801
diff
changeset
|
81 |
TVar _ => mk_Free rty |
6f6ee78c7357
a slight change to abs/rep generation
Christian Urban <urbanc@in.tum.de>
parents:
801
diff
changeset
|
82 |
| Type (_, []) => mk_identity rty |
790
3a48ffcf0f9a
generalised absrep function; needs consolidation
Christian Urban <urbanc@in.tum.de>
parents:
786
diff
changeset
|
83 |
| Type (s, tys) => list_comb (get_mapfun ctxt s, map mk_mapfun_aux tys) |
804 | 84 |
| _ => raise LIFT_MATCH ("mk_mapfun (default)") |
790
3a48ffcf0f9a
generalised absrep function; needs consolidation
Christian Urban <urbanc@in.tum.de>
parents:
786
diff
changeset
|
85 |
in |
803
6f6ee78c7357
a slight change to abs/rep generation
Christian Urban <urbanc@in.tum.de>
parents:
801
diff
changeset
|
86 |
fold_rev Term.lambda vs' (mk_mapfun_aux rty) |
790
3a48ffcf0f9a
generalised absrep function; needs consolidation
Christian Urban <urbanc@in.tum.de>
parents:
786
diff
changeset
|
87 |
end |
3a48ffcf0f9a
generalised absrep function; needs consolidation
Christian Urban <urbanc@in.tum.de>
parents:
786
diff
changeset
|
88 |
|
791
fb4bfbb1a291
commeted the absrep function
Christian Urban <urbanc@in.tum.de>
parents:
790
diff
changeset
|
89 |
(* looks up the (varified) rty and qty for *) |
fb4bfbb1a291
commeted the absrep function
Christian Urban <urbanc@in.tum.de>
parents:
790
diff
changeset
|
90 |
(* a quotient definition *) |
790
3a48ffcf0f9a
generalised absrep function; needs consolidation
Christian Urban <urbanc@in.tum.de>
parents:
786
diff
changeset
|
91 |
fun get_rty_qty ctxt s = |
774
b4ffb8826105
moved get_fun into quotient_term; this simplifies the overall including structure of the package
Christian Urban <urbanc@in.tum.de>
parents:
762
diff
changeset
|
92 |
let |
779
3b21b24a5fb6
corrected map declarations for Sum and Prod; moved absrep_fun examples in separate file
Christian Urban <urbanc@in.tum.de>
parents:
776
diff
changeset
|
93 |
val thy = ProofContext.theory_of ctxt |
790
3a48ffcf0f9a
generalised absrep function; needs consolidation
Christian Urban <urbanc@in.tum.de>
parents:
786
diff
changeset
|
94 |
val exc = LIFT_MATCH ("No quotient type " ^ (quote s) ^ " found.") |
3a48ffcf0f9a
generalised absrep function; needs consolidation
Christian Urban <urbanc@in.tum.de>
parents:
786
diff
changeset
|
95 |
val qdata = (quotdata_lookup thy s) handle NotFound => raise exc |
3a48ffcf0f9a
generalised absrep function; needs consolidation
Christian Urban <urbanc@in.tum.de>
parents:
786
diff
changeset
|
96 |
in |
3a48ffcf0f9a
generalised absrep function; needs consolidation
Christian Urban <urbanc@in.tum.de>
parents:
786
diff
changeset
|
97 |
(#rtyp qdata, #qtyp qdata) |
3a48ffcf0f9a
generalised absrep function; needs consolidation
Christian Urban <urbanc@in.tum.de>
parents:
786
diff
changeset
|
98 |
end |
3a48ffcf0f9a
generalised absrep function; needs consolidation
Christian Urban <urbanc@in.tum.de>
parents:
786
diff
changeset
|
99 |
|
795
a28f805df355
renamed mk_resp_arg to equiv_relation and exported it in the signature; added tests in AbsRepFun.thy
Christian Urban <urbanc@in.tum.de>
parents:
792
diff
changeset
|
100 |
(* takes two type-environments and looks *) |
a28f805df355
renamed mk_resp_arg to equiv_relation and exported it in the signature; added tests in AbsRepFun.thy
Christian Urban <urbanc@in.tum.de>
parents:
792
diff
changeset
|
101 |
(* up in both of them the variable v, which *) |
a28f805df355
renamed mk_resp_arg to equiv_relation and exported it in the signature; added tests in AbsRepFun.thy
Christian Urban <urbanc@in.tum.de>
parents:
792
diff
changeset
|
102 |
(* must be listed in the environment *) |
790
3a48ffcf0f9a
generalised absrep function; needs consolidation
Christian Urban <urbanc@in.tum.de>
parents:
786
diff
changeset
|
103 |
fun double_lookup rtyenv qtyenv v = |
3a48ffcf0f9a
generalised absrep function; needs consolidation
Christian Urban <urbanc@in.tum.de>
parents:
786
diff
changeset
|
104 |
let |
3a48ffcf0f9a
generalised absrep function; needs consolidation
Christian Urban <urbanc@in.tum.de>
parents:
786
diff
changeset
|
105 |
val v' = fst (dest_TVar v) |
3a48ffcf0f9a
generalised absrep function; needs consolidation
Christian Urban <urbanc@in.tum.de>
parents:
786
diff
changeset
|
106 |
in |
3a48ffcf0f9a
generalised absrep function; needs consolidation
Christian Urban <urbanc@in.tum.de>
parents:
786
diff
changeset
|
107 |
(snd (the (Vartab.lookup rtyenv v')), snd (the (Vartab.lookup qtyenv v'))) |
3a48ffcf0f9a
generalised absrep function; needs consolidation
Christian Urban <urbanc@in.tum.de>
parents:
786
diff
changeset
|
108 |
end |
3a48ffcf0f9a
generalised absrep function; needs consolidation
Christian Urban <urbanc@in.tum.de>
parents:
786
diff
changeset
|
109 |
|
832
b3bb2bad952f
introduced separate match function
Christian Urban <urbanc@in.tum.de>
parents:
831
diff
changeset
|
110 |
(* matches a type pattern with a type *) |
b3bb2bad952f
introduced separate match function
Christian Urban <urbanc@in.tum.de>
parents:
831
diff
changeset
|
111 |
fun match ctxt err ty_pat ty = |
b3bb2bad952f
introduced separate match function
Christian Urban <urbanc@in.tum.de>
parents:
831
diff
changeset
|
112 |
let |
b3bb2bad952f
introduced separate match function
Christian Urban <urbanc@in.tum.de>
parents:
831
diff
changeset
|
113 |
val thy = ProofContext.theory_of ctxt |
b3bb2bad952f
introduced separate match function
Christian Urban <urbanc@in.tum.de>
parents:
831
diff
changeset
|
114 |
in |
b3bb2bad952f
introduced separate match function
Christian Urban <urbanc@in.tum.de>
parents:
831
diff
changeset
|
115 |
Sign.typ_match thy (ty_pat, ty) Vartab.empty |
b3bb2bad952f
introduced separate match function
Christian Urban <urbanc@in.tum.de>
parents:
831
diff
changeset
|
116 |
handle MATCH_TYPE => err ctxt ty_pat ty |
b3bb2bad952f
introduced separate match function
Christian Urban <urbanc@in.tum.de>
parents:
831
diff
changeset
|
117 |
end |
b3bb2bad952f
introduced separate match function
Christian Urban <urbanc@in.tum.de>
parents:
831
diff
changeset
|
118 |
|
800 | 119 |
(* produces the rep or abs constant for a qty *) |
790
3a48ffcf0f9a
generalised absrep function; needs consolidation
Christian Urban <urbanc@in.tum.de>
parents:
786
diff
changeset
|
120 |
fun absrep_const flag ctxt qty_str = |
3a48ffcf0f9a
generalised absrep function; needs consolidation
Christian Urban <urbanc@in.tum.de>
parents:
786
diff
changeset
|
121 |
let |
3a48ffcf0f9a
generalised absrep function; needs consolidation
Christian Urban <urbanc@in.tum.de>
parents:
786
diff
changeset
|
122 |
val thy = ProofContext.theory_of ctxt |
3a48ffcf0f9a
generalised absrep function; needs consolidation
Christian Urban <urbanc@in.tum.de>
parents:
786
diff
changeset
|
123 |
val qty_name = Long_Name.base_name qty_str |
774
b4ffb8826105
moved get_fun into quotient_term; this simplifies the overall including structure of the package
Christian Urban <urbanc@in.tum.de>
parents:
762
diff
changeset
|
124 |
in |
b4ffb8826105
moved get_fun into quotient_term; this simplifies the overall including structure of the package
Christian Urban <urbanc@in.tum.de>
parents:
762
diff
changeset
|
125 |
case flag of |
b4ffb8826105
moved get_fun into quotient_term; this simplifies the overall including structure of the package
Christian Urban <urbanc@in.tum.de>
parents:
762
diff
changeset
|
126 |
absF => Const (Sign.full_bname thy ("abs_" ^ qty_name), dummyT) |
b4ffb8826105
moved get_fun into quotient_term; this simplifies the overall including structure of the package
Christian Urban <urbanc@in.tum.de>
parents:
762
diff
changeset
|
127 |
| repF => Const (Sign.full_bname thy ("rep_" ^ qty_name), dummyT) |
b4ffb8826105
moved get_fun into quotient_term; this simplifies the overall including structure of the package
Christian Urban <urbanc@in.tum.de>
parents:
762
diff
changeset
|
128 |
end |
b4ffb8826105
moved get_fun into quotient_term; this simplifies the overall including structure of the package
Christian Urban <urbanc@in.tum.de>
parents:
762
diff
changeset
|
129 |
|
795
a28f805df355
renamed mk_resp_arg to equiv_relation and exported it in the signature; added tests in AbsRepFun.thy
Christian Urban <urbanc@in.tum.de>
parents:
792
diff
changeset
|
130 |
fun absrep_match_err ctxt ty_pat ty = |
a28f805df355
renamed mk_resp_arg to equiv_relation and exported it in the signature; added tests in AbsRepFun.thy
Christian Urban <urbanc@in.tum.de>
parents:
792
diff
changeset
|
131 |
let |
a28f805df355
renamed mk_resp_arg to equiv_relation and exported it in the signature; added tests in AbsRepFun.thy
Christian Urban <urbanc@in.tum.de>
parents:
792
diff
changeset
|
132 |
val ty_pat_str = Syntax.string_of_typ ctxt ty_pat |
a28f805df355
renamed mk_resp_arg to equiv_relation and exported it in the signature; added tests in AbsRepFun.thy
Christian Urban <urbanc@in.tum.de>
parents:
792
diff
changeset
|
133 |
val ty_str = Syntax.string_of_typ ctxt ty |
a28f805df355
renamed mk_resp_arg to equiv_relation and exported it in the signature; added tests in AbsRepFun.thy
Christian Urban <urbanc@in.tum.de>
parents:
792
diff
changeset
|
134 |
in |
a28f805df355
renamed mk_resp_arg to equiv_relation and exported it in the signature; added tests in AbsRepFun.thy
Christian Urban <urbanc@in.tum.de>
parents:
792
diff
changeset
|
135 |
raise LIFT_MATCH (space_implode " " |
a28f805df355
renamed mk_resp_arg to equiv_relation and exported it in the signature; added tests in AbsRepFun.thy
Christian Urban <urbanc@in.tum.de>
parents:
792
diff
changeset
|
136 |
["absrep_fun (Types ", quote ty_pat_str, "and", quote ty_str, " do not match.)"]) |
a28f805df355
renamed mk_resp_arg to equiv_relation and exported it in the signature; added tests in AbsRepFun.thy
Christian Urban <urbanc@in.tum.de>
parents:
792
diff
changeset
|
137 |
end |
a28f805df355
renamed mk_resp_arg to equiv_relation and exported it in the signature; added tests in AbsRepFun.thy
Christian Urban <urbanc@in.tum.de>
parents:
792
diff
changeset
|
138 |
|
a28f805df355
renamed mk_resp_arg to equiv_relation and exported it in the signature; added tests in AbsRepFun.thy
Christian Urban <urbanc@in.tum.de>
parents:
792
diff
changeset
|
139 |
(* produces an aggregate absrep function *) |
791
fb4bfbb1a291
commeted the absrep function
Christian Urban <urbanc@in.tum.de>
parents:
790
diff
changeset
|
140 |
(* *) |
804 | 141 |
(* - In case of equal types we just return the identity. *) |
803
6f6ee78c7357
a slight change to abs/rep generation
Christian Urban <urbanc@in.tum.de>
parents:
801
diff
changeset
|
142 |
(* *) |
791
fb4bfbb1a291
commeted the absrep function
Christian Urban <urbanc@in.tum.de>
parents:
790
diff
changeset
|
143 |
(* - In case of function types and TFrees, we recurse, taking in *) |
fb4bfbb1a291
commeted the absrep function
Christian Urban <urbanc@in.tum.de>
parents:
790
diff
changeset
|
144 |
(* the first case the polarity change into account. *) |
fb4bfbb1a291
commeted the absrep function
Christian Urban <urbanc@in.tum.de>
parents:
790
diff
changeset
|
145 |
(* *) |
fb4bfbb1a291
commeted the absrep function
Christian Urban <urbanc@in.tum.de>
parents:
790
diff
changeset
|
146 |
(* - If the type constructors are equal, we recurse for the *) |
804 | 147 |
(* arguments and build the appropriate map function. *) |
791
fb4bfbb1a291
commeted the absrep function
Christian Urban <urbanc@in.tum.de>
parents:
790
diff
changeset
|
148 |
(* *) |
fb4bfbb1a291
commeted the absrep function
Christian Urban <urbanc@in.tum.de>
parents:
790
diff
changeset
|
149 |
(* - If the type constructors are unequal, there must be an *) |
fb4bfbb1a291
commeted the absrep function
Christian Urban <urbanc@in.tum.de>
parents:
790
diff
changeset
|
150 |
(* instance of quotient types: *) |
fb4bfbb1a291
commeted the absrep function
Christian Urban <urbanc@in.tum.de>
parents:
790
diff
changeset
|
151 |
(* - we first look up the corresponding rty_pat and qty_pat *) |
fb4bfbb1a291
commeted the absrep function
Christian Urban <urbanc@in.tum.de>
parents:
790
diff
changeset
|
152 |
(* from the quotient definition; the arguments of qty_pat *) |
fb4bfbb1a291
commeted the absrep function
Christian Urban <urbanc@in.tum.de>
parents:
790
diff
changeset
|
153 |
(* must be some distinct TVars *) |
fb4bfbb1a291
commeted the absrep function
Christian Urban <urbanc@in.tum.de>
parents:
790
diff
changeset
|
154 |
(* - we then match the rty_pat with rty and qty_pat with qty; *) |
fb4bfbb1a291
commeted the absrep function
Christian Urban <urbanc@in.tum.de>
parents:
790
diff
changeset
|
155 |
(* if matching fails the types do not match *) |
804 | 156 |
(* - the matching produces two environments; we look up the *) |
791
fb4bfbb1a291
commeted the absrep function
Christian Urban <urbanc@in.tum.de>
parents:
790
diff
changeset
|
157 |
(* assignments for the qty_pat variables and recurse on the *) |
804 | 158 |
(* assignments *) |
791
fb4bfbb1a291
commeted the absrep function
Christian Urban <urbanc@in.tum.de>
parents:
790
diff
changeset
|
159 |
(* - we prefix the aggregate map function for the rty_pat, *) |
fb4bfbb1a291
commeted the absrep function
Christian Urban <urbanc@in.tum.de>
parents:
790
diff
changeset
|
160 |
(* which is an abstraction over all type variables *) |
804 | 161 |
(* - finally we compose the result with the appropriate *) |
791
fb4bfbb1a291
commeted the absrep function
Christian Urban <urbanc@in.tum.de>
parents:
790
diff
changeset
|
162 |
(* absrep function *) |
fb4bfbb1a291
commeted the absrep function
Christian Urban <urbanc@in.tum.de>
parents:
790
diff
changeset
|
163 |
(* *) |
fb4bfbb1a291
commeted the absrep function
Christian Urban <urbanc@in.tum.de>
parents:
790
diff
changeset
|
164 |
(* The composition is necessary for types like *) |
fb4bfbb1a291
commeted the absrep function
Christian Urban <urbanc@in.tum.de>
parents:
790
diff
changeset
|
165 |
(* *) |
fb4bfbb1a291
commeted the absrep function
Christian Urban <urbanc@in.tum.de>
parents:
790
diff
changeset
|
166 |
(* ('a list) list / ('a foo) foo *) |
fb4bfbb1a291
commeted the absrep function
Christian Urban <urbanc@in.tum.de>
parents:
790
diff
changeset
|
167 |
(* *) |
fb4bfbb1a291
commeted the absrep function
Christian Urban <urbanc@in.tum.de>
parents:
790
diff
changeset
|
168 |
(* The matching is necessary for types like *) |
fb4bfbb1a291
commeted the absrep function
Christian Urban <urbanc@in.tum.de>
parents:
790
diff
changeset
|
169 |
(* *) |
fb4bfbb1a291
commeted the absrep function
Christian Urban <urbanc@in.tum.de>
parents:
790
diff
changeset
|
170 |
(* ('a * 'a) list / 'a bar *) |
fb4bfbb1a291
commeted the absrep function
Christian Urban <urbanc@in.tum.de>
parents:
790
diff
changeset
|
171 |
|
779
3b21b24a5fb6
corrected map declarations for Sum and Prod; moved absrep_fun examples in separate file
Christian Urban <urbanc@in.tum.de>
parents:
776
diff
changeset
|
172 |
fun absrep_fun flag ctxt (rty, qty) = |
790
3a48ffcf0f9a
generalised absrep function; needs consolidation
Christian Urban <urbanc@in.tum.de>
parents:
786
diff
changeset
|
173 |
if rty = qty |
803
6f6ee78c7357
a slight change to abs/rep generation
Christian Urban <urbanc@in.tum.de>
parents:
801
diff
changeset
|
174 |
then mk_identity rty |
790
3a48ffcf0f9a
generalised absrep function; needs consolidation
Christian Urban <urbanc@in.tum.de>
parents:
786
diff
changeset
|
175 |
else |
3a48ffcf0f9a
generalised absrep function; needs consolidation
Christian Urban <urbanc@in.tum.de>
parents:
786
diff
changeset
|
176 |
case (rty, qty) of |
3a48ffcf0f9a
generalised absrep function; needs consolidation
Christian Urban <urbanc@in.tum.de>
parents:
786
diff
changeset
|
177 |
(Type ("fun", [ty1, ty2]), Type ("fun", [ty1', ty2'])) => |
3a48ffcf0f9a
generalised absrep function; needs consolidation
Christian Urban <urbanc@in.tum.de>
parents:
786
diff
changeset
|
178 |
let |
3a48ffcf0f9a
generalised absrep function; needs consolidation
Christian Urban <urbanc@in.tum.de>
parents:
786
diff
changeset
|
179 |
val arg1 = absrep_fun (negF flag) ctxt (ty1, ty1') |
3a48ffcf0f9a
generalised absrep function; needs consolidation
Christian Urban <urbanc@in.tum.de>
parents:
786
diff
changeset
|
180 |
val arg2 = absrep_fun flag ctxt (ty2, ty2') |
3a48ffcf0f9a
generalised absrep function; needs consolidation
Christian Urban <urbanc@in.tum.de>
parents:
786
diff
changeset
|
181 |
in |
3a48ffcf0f9a
generalised absrep function; needs consolidation
Christian Urban <urbanc@in.tum.de>
parents:
786
diff
changeset
|
182 |
list_comb (get_mapfun ctxt "fun", [arg1, arg2]) |
3a48ffcf0f9a
generalised absrep function; needs consolidation
Christian Urban <urbanc@in.tum.de>
parents:
786
diff
changeset
|
183 |
end |
3a48ffcf0f9a
generalised absrep function; needs consolidation
Christian Urban <urbanc@in.tum.de>
parents:
786
diff
changeset
|
184 |
| (Type (s, tys), Type (s', tys')) => |
774
b4ffb8826105
moved get_fun into quotient_term; this simplifies the overall including structure of the package
Christian Urban <urbanc@in.tum.de>
parents:
762
diff
changeset
|
185 |
if s = s' |
790
3a48ffcf0f9a
generalised absrep function; needs consolidation
Christian Urban <urbanc@in.tum.de>
parents:
786
diff
changeset
|
186 |
then |
3a48ffcf0f9a
generalised absrep function; needs consolidation
Christian Urban <urbanc@in.tum.de>
parents:
786
diff
changeset
|
187 |
let |
3a48ffcf0f9a
generalised absrep function; needs consolidation
Christian Urban <urbanc@in.tum.de>
parents:
786
diff
changeset
|
188 |
val args = map (absrep_fun flag ctxt) (tys ~~ tys') |
3a48ffcf0f9a
generalised absrep function; needs consolidation
Christian Urban <urbanc@in.tum.de>
parents:
786
diff
changeset
|
189 |
in |
3a48ffcf0f9a
generalised absrep function; needs consolidation
Christian Urban <urbanc@in.tum.de>
parents:
786
diff
changeset
|
190 |
list_comb (get_mapfun ctxt s, args) |
832
b3bb2bad952f
introduced separate match function
Christian Urban <urbanc@in.tum.de>
parents:
831
diff
changeset
|
191 |
end |
790
3a48ffcf0f9a
generalised absrep function; needs consolidation
Christian Urban <urbanc@in.tum.de>
parents:
786
diff
changeset
|
192 |
else |
3a48ffcf0f9a
generalised absrep function; needs consolidation
Christian Urban <urbanc@in.tum.de>
parents:
786
diff
changeset
|
193 |
let |
3a48ffcf0f9a
generalised absrep function; needs consolidation
Christian Urban <urbanc@in.tum.de>
parents:
786
diff
changeset
|
194 |
val (rty_pat, qty_pat as Type (_, vs)) = get_rty_qty ctxt s' |
832
b3bb2bad952f
introduced separate match function
Christian Urban <urbanc@in.tum.de>
parents:
831
diff
changeset
|
195 |
val rtyenv = match ctxt absrep_match_err rty_pat rty |
b3bb2bad952f
introduced separate match function
Christian Urban <urbanc@in.tum.de>
parents:
831
diff
changeset
|
196 |
val qtyenv = match ctxt absrep_match_err qty_pat qty |
800 | 197 |
val args_aux = map (double_lookup rtyenv qtyenv) vs |
790
3a48ffcf0f9a
generalised absrep function; needs consolidation
Christian Urban <urbanc@in.tum.de>
parents:
786
diff
changeset
|
198 |
val args = map (absrep_fun flag ctxt) args_aux |
3a48ffcf0f9a
generalised absrep function; needs consolidation
Christian Urban <urbanc@in.tum.de>
parents:
786
diff
changeset
|
199 |
val map_fun = mk_mapfun ctxt vs rty_pat |
3a48ffcf0f9a
generalised absrep function; needs consolidation
Christian Urban <urbanc@in.tum.de>
parents:
786
diff
changeset
|
200 |
val result = list_comb (map_fun, args) |
3a48ffcf0f9a
generalised absrep function; needs consolidation
Christian Urban <urbanc@in.tum.de>
parents:
786
diff
changeset
|
201 |
in |
834
fb7fe6aca6f0
tuned previous commit further
Christian Urban <urbanc@in.tum.de>
parents:
833
diff
changeset
|
202 |
mk_fun_compose flag (absrep_const flag ctxt s', result) |
830
89d772dae4d4
New_relations, all works again including concat examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
826
diff
changeset
|
203 |
end |
790
3a48ffcf0f9a
generalised absrep function; needs consolidation
Christian Urban <urbanc@in.tum.de>
parents:
786
diff
changeset
|
204 |
| (TFree x, TFree x') => |
3a48ffcf0f9a
generalised absrep function; needs consolidation
Christian Urban <urbanc@in.tum.de>
parents:
786
diff
changeset
|
205 |
if x = x' |
803
6f6ee78c7357
a slight change to abs/rep generation
Christian Urban <urbanc@in.tum.de>
parents:
801
diff
changeset
|
206 |
then mk_identity rty |
790
3a48ffcf0f9a
generalised absrep function; needs consolidation
Christian Urban <urbanc@in.tum.de>
parents:
786
diff
changeset
|
207 |
else raise (LIFT_MATCH "absrep_fun (frees)") |
3a48ffcf0f9a
generalised absrep function; needs consolidation
Christian Urban <urbanc@in.tum.de>
parents:
786
diff
changeset
|
208 |
| (TVar _, TVar _) => raise (LIFT_MATCH "absrep_fun (vars)") |
791
fb4bfbb1a291
commeted the absrep function
Christian Urban <urbanc@in.tum.de>
parents:
790
diff
changeset
|
209 |
| _ => raise (LIFT_MATCH "absrep_fun (default)") |
774
b4ffb8826105
moved get_fun into quotient_term; this simplifies the overall including structure of the package
Christian Urban <urbanc@in.tum.de>
parents:
762
diff
changeset
|
210 |
|
779
3b21b24a5fb6
corrected map declarations for Sum and Prod; moved absrep_fun examples in separate file
Christian Urban <urbanc@in.tum.de>
parents:
776
diff
changeset
|
211 |
fun absrep_fun_chk flag ctxt (rty, qty) = |
3b21b24a5fb6
corrected map declarations for Sum and Prod; moved absrep_fun examples in separate file
Christian Urban <urbanc@in.tum.de>
parents:
776
diff
changeset
|
212 |
absrep_fun flag ctxt (rty, qty) |
3b21b24a5fb6
corrected map declarations for Sum and Prod; moved absrep_fun examples in separate file
Christian Urban <urbanc@in.tum.de>
parents:
776
diff
changeset
|
213 |
|> Syntax.check_term ctxt |
833
129caba33c03
the chk-functions in quotient_term also simplify the result according to the id_simps; had to remove id_def from this theorem list though; this caused in FSet3 that relied on this rule; the problem is marked with "ID PROBLEM"
Christian Urban <urbanc@in.tum.de>
parents:
832
diff
changeset
|
214 |
|> id_simplify ctxt |
779
3b21b24a5fb6
corrected map declarations for Sum and Prod; moved absrep_fun examples in separate file
Christian Urban <urbanc@in.tum.de>
parents:
776
diff
changeset
|
215 |
|
795
a28f805df355
renamed mk_resp_arg to equiv_relation and exported it in the signature; added tests in AbsRepFun.thy
Christian Urban <urbanc@in.tum.de>
parents:
792
diff
changeset
|
216 |
(**********************************) |
a28f805df355
renamed mk_resp_arg to equiv_relation and exported it in the signature; added tests in AbsRepFun.thy
Christian Urban <urbanc@in.tum.de>
parents:
792
diff
changeset
|
217 |
(* Aggregate Equivalence Relation *) |
a28f805df355
renamed mk_resp_arg to equiv_relation and exported it in the signature; added tests in AbsRepFun.thy
Christian Urban <urbanc@in.tum.de>
parents:
792
diff
changeset
|
218 |
(**********************************) |
758
3104d62e7a16
moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
219 |
|
783
06e17083e90b
modified mk_resp_arg so that the user can give terms as equivalence relations, not just constants
Christian Urban <urbanc@in.tum.de>
parents:
782
diff
changeset
|
220 |
(* instantiates TVars so that the term is of type ty *) |
792 | 221 |
fun force_typ ctxt trm ty = |
783
06e17083e90b
modified mk_resp_arg so that the user can give terms as equivalence relations, not just constants
Christian Urban <urbanc@in.tum.de>
parents:
782
diff
changeset
|
222 |
let |
792 | 223 |
val thy = ProofContext.theory_of ctxt |
783
06e17083e90b
modified mk_resp_arg so that the user can give terms as equivalence relations, not just constants
Christian Urban <urbanc@in.tum.de>
parents:
782
diff
changeset
|
224 |
val trm_ty = fastype_of trm |
06e17083e90b
modified mk_resp_arg so that the user can give terms as equivalence relations, not just constants
Christian Urban <urbanc@in.tum.de>
parents:
782
diff
changeset
|
225 |
val ty_inst = Sign.typ_match thy (trm_ty, ty) Vartab.empty |
06e17083e90b
modified mk_resp_arg so that the user can give terms as equivalence relations, not just constants
Christian Urban <urbanc@in.tum.de>
parents:
782
diff
changeset
|
226 |
in |
06e17083e90b
modified mk_resp_arg so that the user can give terms as equivalence relations, not just constants
Christian Urban <urbanc@in.tum.de>
parents:
782
diff
changeset
|
227 |
map_types (Envir.subst_type ty_inst) trm |
06e17083e90b
modified mk_resp_arg so that the user can give terms as equivalence relations, not just constants
Christian Urban <urbanc@in.tum.de>
parents:
782
diff
changeset
|
228 |
end |
06e17083e90b
modified mk_resp_arg so that the user can give terms as equivalence relations, not just constants
Christian Urban <urbanc@in.tum.de>
parents:
782
diff
changeset
|
229 |
|
825
970e86082cd7
Modifictaions for new_relation.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
808
diff
changeset
|
230 |
fun mk_rel_compose (trm1, trm2) = |
970e86082cd7
Modifictaions for new_relation.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
808
diff
changeset
|
231 |
Const (@{const_name "pred_comp"}, dummyT) $ trm1 $ |
970e86082cd7
Modifictaions for new_relation.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
808
diff
changeset
|
232 |
(Const (@{const_name "pred_comp"}, dummyT) $ trm2 $ trm1) |
807
a5495a323b49
added a new version of equiv_relation (is not yet used anywhere except in AbsRepTest)
Christian Urban <urbanc@in.tum.de>
parents:
804
diff
changeset
|
233 |
|
792 | 234 |
fun get_relmap ctxt s = |
235 |
let |
|
236 |
val thy = ProofContext.theory_of ctxt |
|
237 |
val exc = LIFT_MATCH ("get_relmap (no relation map function found for type " ^ s ^ ")") |
|
238 |
val relmap = #relmap (maps_lookup thy s) handle NotFound => raise exc |
|
239 |
in |
|
240 |
Const (relmap, dummyT) |
|
241 |
end |
|
242 |
||
807
a5495a323b49
added a new version of equiv_relation (is not yet used anywhere except in AbsRepTest)
Christian Urban <urbanc@in.tum.de>
parents:
804
diff
changeset
|
243 |
fun mk_relmap ctxt vs rty = |
a5495a323b49
added a new version of equiv_relation (is not yet used anywhere except in AbsRepTest)
Christian Urban <urbanc@in.tum.de>
parents:
804
diff
changeset
|
244 |
let |
a5495a323b49
added a new version of equiv_relation (is not yet used anywhere except in AbsRepTest)
Christian Urban <urbanc@in.tum.de>
parents:
804
diff
changeset
|
245 |
val vs' = map (mk_Free) vs |
a5495a323b49
added a new version of equiv_relation (is not yet used anywhere except in AbsRepTest)
Christian Urban <urbanc@in.tum.de>
parents:
804
diff
changeset
|
246 |
|
a5495a323b49
added a new version of equiv_relation (is not yet used anywhere except in AbsRepTest)
Christian Urban <urbanc@in.tum.de>
parents:
804
diff
changeset
|
247 |
fun mk_relmap_aux rty = |
a5495a323b49
added a new version of equiv_relation (is not yet used anywhere except in AbsRepTest)
Christian Urban <urbanc@in.tum.de>
parents:
804
diff
changeset
|
248 |
case rty of |
a5495a323b49
added a new version of equiv_relation (is not yet used anywhere except in AbsRepTest)
Christian Urban <urbanc@in.tum.de>
parents:
804
diff
changeset
|
249 |
TVar _ => mk_Free rty |
a5495a323b49
added a new version of equiv_relation (is not yet used anywhere except in AbsRepTest)
Christian Urban <urbanc@in.tum.de>
parents:
804
diff
changeset
|
250 |
| Type (_, []) => HOLogic.eq_const rty |
a5495a323b49
added a new version of equiv_relation (is not yet used anywhere except in AbsRepTest)
Christian Urban <urbanc@in.tum.de>
parents:
804
diff
changeset
|
251 |
| Type (s, tys) => list_comb (get_relmap ctxt s, map mk_relmap_aux tys) |
a5495a323b49
added a new version of equiv_relation (is not yet used anywhere except in AbsRepTest)
Christian Urban <urbanc@in.tum.de>
parents:
804
diff
changeset
|
252 |
| _ => raise LIFT_MATCH ("mk_relmap (default)") |
a5495a323b49
added a new version of equiv_relation (is not yet used anywhere except in AbsRepTest)
Christian Urban <urbanc@in.tum.de>
parents:
804
diff
changeset
|
253 |
in |
a5495a323b49
added a new version of equiv_relation (is not yet used anywhere except in AbsRepTest)
Christian Urban <urbanc@in.tum.de>
parents:
804
diff
changeset
|
254 |
fold_rev Term.lambda vs' (mk_relmap_aux rty) |
a5495a323b49
added a new version of equiv_relation (is not yet used anywhere except in AbsRepTest)
Christian Urban <urbanc@in.tum.de>
parents:
804
diff
changeset
|
255 |
end |
a5495a323b49
added a new version of equiv_relation (is not yet used anywhere except in AbsRepTest)
Christian Urban <urbanc@in.tum.de>
parents:
804
diff
changeset
|
256 |
|
792 | 257 |
fun get_equiv_rel ctxt s = |
258 |
let |
|
259 |
val thy = ProofContext.theory_of ctxt |
|
260 |
val exc = LIFT_MATCH ("get_quotdata (no quotient found for type " ^ s ^ ")") |
|
261 |
in |
|
262 |
#equiv_rel (quotdata_lookup thy s) handle NotFound => raise exc |
|
263 |
end |
|
264 |
||
808
90bde96f5dd1
proper handling of error messages (code copy - maybe this can be avoided)
Christian Urban <urbanc@in.tum.de>
parents:
807
diff
changeset
|
265 |
fun equiv_match_err ctxt ty_pat ty = |
90bde96f5dd1
proper handling of error messages (code copy - maybe this can be avoided)
Christian Urban <urbanc@in.tum.de>
parents:
807
diff
changeset
|
266 |
let |
90bde96f5dd1
proper handling of error messages (code copy - maybe this can be avoided)
Christian Urban <urbanc@in.tum.de>
parents:
807
diff
changeset
|
267 |
val ty_pat_str = Syntax.string_of_typ ctxt ty_pat |
90bde96f5dd1
proper handling of error messages (code copy - maybe this can be avoided)
Christian Urban <urbanc@in.tum.de>
parents:
807
diff
changeset
|
268 |
val ty_str = Syntax.string_of_typ ctxt ty |
90bde96f5dd1
proper handling of error messages (code copy - maybe this can be avoided)
Christian Urban <urbanc@in.tum.de>
parents:
807
diff
changeset
|
269 |
in |
90bde96f5dd1
proper handling of error messages (code copy - maybe this can be avoided)
Christian Urban <urbanc@in.tum.de>
parents:
807
diff
changeset
|
270 |
raise LIFT_MATCH (space_implode " " |
90bde96f5dd1
proper handling of error messages (code copy - maybe this can be avoided)
Christian Urban <urbanc@in.tum.de>
parents:
807
diff
changeset
|
271 |
["equiv_relation (Types ", quote ty_pat_str, "and", quote ty_str, " do not match.)"]) |
90bde96f5dd1
proper handling of error messages (code copy - maybe this can be avoided)
Christian Urban <urbanc@in.tum.de>
parents:
807
diff
changeset
|
272 |
end |
90bde96f5dd1
proper handling of error messages (code copy - maybe this can be avoided)
Christian Urban <urbanc@in.tum.de>
parents:
807
diff
changeset
|
273 |
|
760
c1989de100b4
various tunings; map_lookup now raises an exception; addition to FIXME-TODO
Christian Urban <urbanc@in.tum.de>
parents:
758
diff
changeset
|
274 |
(* builds the aggregate equivalence relation *) |
c1989de100b4
various tunings; map_lookup now raises an exception; addition to FIXME-TODO
Christian Urban <urbanc@in.tum.de>
parents:
758
diff
changeset
|
275 |
(* that will be the argument of Respects *) |
795
a28f805df355
renamed mk_resp_arg to equiv_relation and exported it in the signature; added tests in AbsRepFun.thy
Christian Urban <urbanc@in.tum.de>
parents:
792
diff
changeset
|
276 |
fun equiv_relation ctxt (rty, qty) = |
758
3104d62e7a16
moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
277 |
if rty = qty |
3104d62e7a16
moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
278 |
then HOLogic.eq_const rty |
3104d62e7a16
moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
279 |
else |
3104d62e7a16
moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
280 |
case (rty, qty) of |
3104d62e7a16
moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
281 |
(Type (s, tys), Type (s', tys')) => |
3104d62e7a16
moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
282 |
if s = s' |
761 | 283 |
then |
284 |
let |
|
795
a28f805df355
renamed mk_resp_arg to equiv_relation and exported it in the signature; added tests in AbsRepFun.thy
Christian Urban <urbanc@in.tum.de>
parents:
792
diff
changeset
|
285 |
val args = map (equiv_relation ctxt) (tys ~~ tys') |
761 | 286 |
in |
792 | 287 |
list_comb (get_relmap ctxt s, args) |
761 | 288 |
end |
289 |
else |
|
784
da75568e7f12
renamed some fields in the info records
Christian Urban <urbanc@in.tum.de>
parents:
783
diff
changeset
|
290 |
let |
831
224909b9399f
removed obsolete equiv_relation and rnamed new_equiv_relation
Christian Urban <urbanc@in.tum.de>
parents:
830
diff
changeset
|
291 |
val (rty_pat, qty_pat as Type (_, vs)) = get_rty_qty ctxt s' |
832
b3bb2bad952f
introduced separate match function
Christian Urban <urbanc@in.tum.de>
parents:
831
diff
changeset
|
292 |
val rtyenv = match ctxt equiv_match_err rty_pat rty |
b3bb2bad952f
introduced separate match function
Christian Urban <urbanc@in.tum.de>
parents:
831
diff
changeset
|
293 |
val qtyenv = match ctxt equiv_match_err qty_pat qty |
831
224909b9399f
removed obsolete equiv_relation and rnamed new_equiv_relation
Christian Urban <urbanc@in.tum.de>
parents:
830
diff
changeset
|
294 |
val args_aux = map (double_lookup rtyenv qtyenv) vs |
224909b9399f
removed obsolete equiv_relation and rnamed new_equiv_relation
Christian Urban <urbanc@in.tum.de>
parents:
830
diff
changeset
|
295 |
val args = map (equiv_relation ctxt) args_aux |
224909b9399f
removed obsolete equiv_relation and rnamed new_equiv_relation
Christian Urban <urbanc@in.tum.de>
parents:
830
diff
changeset
|
296 |
val rel_map = mk_relmap ctxt vs rty_pat |
224909b9399f
removed obsolete equiv_relation and rnamed new_equiv_relation
Christian Urban <urbanc@in.tum.de>
parents:
830
diff
changeset
|
297 |
val result = list_comb (rel_map, args) |
792 | 298 |
val eqv_rel = get_equiv_rel ctxt s' |
831
224909b9399f
removed obsolete equiv_relation and rnamed new_equiv_relation
Christian Urban <urbanc@in.tum.de>
parents:
830
diff
changeset
|
299 |
val eqv_rel' = force_typ ctxt eqv_rel ([rty, rty] ---> @{typ bool}) |
761 | 300 |
in |
834
fb7fe6aca6f0
tuned previous commit further
Christian Urban <urbanc@in.tum.de>
parents:
833
diff
changeset
|
301 |
mk_rel_compose (result, eqv_rel') |
761 | 302 |
end |
783
06e17083e90b
modified mk_resp_arg so that the user can give terms as equivalence relations, not just constants
Christian Urban <urbanc@in.tum.de>
parents:
782
diff
changeset
|
303 |
| _ => HOLogic.eq_const rty |
795
a28f805df355
renamed mk_resp_arg to equiv_relation and exported it in the signature; added tests in AbsRepFun.thy
Christian Urban <urbanc@in.tum.de>
parents:
792
diff
changeset
|
304 |
|
a28f805df355
renamed mk_resp_arg to equiv_relation and exported it in the signature; added tests in AbsRepFun.thy
Christian Urban <urbanc@in.tum.de>
parents:
792
diff
changeset
|
305 |
fun equiv_relation_chk ctxt (rty, qty) = |
a28f805df355
renamed mk_resp_arg to equiv_relation and exported it in the signature; added tests in AbsRepFun.thy
Christian Urban <urbanc@in.tum.de>
parents:
792
diff
changeset
|
306 |
equiv_relation ctxt (rty, qty) |
a28f805df355
renamed mk_resp_arg to equiv_relation and exported it in the signature; added tests in AbsRepFun.thy
Christian Urban <urbanc@in.tum.de>
parents:
792
diff
changeset
|
307 |
|> Syntax.check_term ctxt |
833
129caba33c03
the chk-functions in quotient_term also simplify the result according to the id_simps; had to remove id_def from this theorem list though; this caused in FSet3 that relied on this rule; the problem is marked with "ID PROBLEM"
Christian Urban <urbanc@in.tum.de>
parents:
832
diff
changeset
|
308 |
|> id_simplify ctxt |
795
a28f805df355
renamed mk_resp_arg to equiv_relation and exported it in the signature; added tests in AbsRepFun.thy
Christian Urban <urbanc@in.tum.de>
parents:
792
diff
changeset
|
309 |
|
a28f805df355
renamed mk_resp_arg to equiv_relation and exported it in the signature; added tests in AbsRepFun.thy
Christian Urban <urbanc@in.tum.de>
parents:
792
diff
changeset
|
310 |
|
a28f805df355
renamed mk_resp_arg to equiv_relation and exported it in the signature; added tests in AbsRepFun.thy
Christian Urban <urbanc@in.tum.de>
parents:
792
diff
changeset
|
311 |
(******************) |
a28f805df355
renamed mk_resp_arg to equiv_relation and exported it in the signature; added tests in AbsRepFun.thy
Christian Urban <urbanc@in.tum.de>
parents:
792
diff
changeset
|
312 |
(* Regularization *) |
a28f805df355
renamed mk_resp_arg to equiv_relation and exported it in the signature; added tests in AbsRepFun.thy
Christian Urban <urbanc@in.tum.de>
parents:
792
diff
changeset
|
313 |
(******************) |
a28f805df355
renamed mk_resp_arg to equiv_relation and exported it in the signature; added tests in AbsRepFun.thy
Christian Urban <urbanc@in.tum.de>
parents:
792
diff
changeset
|
314 |
|
a28f805df355
renamed mk_resp_arg to equiv_relation and exported it in the signature; added tests in AbsRepFun.thy
Christian Urban <urbanc@in.tum.de>
parents:
792
diff
changeset
|
315 |
(* Regularizing an rtrm means: |
a28f805df355
renamed mk_resp_arg to equiv_relation and exported it in the signature; added tests in AbsRepFun.thy
Christian Urban <urbanc@in.tum.de>
parents:
792
diff
changeset
|
316 |
|
a28f805df355
renamed mk_resp_arg to equiv_relation and exported it in the signature; added tests in AbsRepFun.thy
Christian Urban <urbanc@in.tum.de>
parents:
792
diff
changeset
|
317 |
- Quantifiers over types that need lifting are replaced |
a28f805df355
renamed mk_resp_arg to equiv_relation and exported it in the signature; added tests in AbsRepFun.thy
Christian Urban <urbanc@in.tum.de>
parents:
792
diff
changeset
|
318 |
by bounded quantifiers, for example: |
a28f805df355
renamed mk_resp_arg to equiv_relation and exported it in the signature; added tests in AbsRepFun.thy
Christian Urban <urbanc@in.tum.de>
parents:
792
diff
changeset
|
319 |
|
a28f805df355
renamed mk_resp_arg to equiv_relation and exported it in the signature; added tests in AbsRepFun.thy
Christian Urban <urbanc@in.tum.de>
parents:
792
diff
changeset
|
320 |
All P ----> All (Respects R) P |
a28f805df355
renamed mk_resp_arg to equiv_relation and exported it in the signature; added tests in AbsRepFun.thy
Christian Urban <urbanc@in.tum.de>
parents:
792
diff
changeset
|
321 |
|
a28f805df355
renamed mk_resp_arg to equiv_relation and exported it in the signature; added tests in AbsRepFun.thy
Christian Urban <urbanc@in.tum.de>
parents:
792
diff
changeset
|
322 |
where the aggregate relation R is given by the rty and qty; |
a28f805df355
renamed mk_resp_arg to equiv_relation and exported it in the signature; added tests in AbsRepFun.thy
Christian Urban <urbanc@in.tum.de>
parents:
792
diff
changeset
|
323 |
|
a28f805df355
renamed mk_resp_arg to equiv_relation and exported it in the signature; added tests in AbsRepFun.thy
Christian Urban <urbanc@in.tum.de>
parents:
792
diff
changeset
|
324 |
- Abstractions over types that need lifting are replaced |
a28f805df355
renamed mk_resp_arg to equiv_relation and exported it in the signature; added tests in AbsRepFun.thy
Christian Urban <urbanc@in.tum.de>
parents:
792
diff
changeset
|
325 |
by bounded abstractions, for example: |
a28f805df355
renamed mk_resp_arg to equiv_relation and exported it in the signature; added tests in AbsRepFun.thy
Christian Urban <urbanc@in.tum.de>
parents:
792
diff
changeset
|
326 |
|
a28f805df355
renamed mk_resp_arg to equiv_relation and exported it in the signature; added tests in AbsRepFun.thy
Christian Urban <urbanc@in.tum.de>
parents:
792
diff
changeset
|
327 |
%x. P ----> Ball (Respects R) %x. P |
a28f805df355
renamed mk_resp_arg to equiv_relation and exported it in the signature; added tests in AbsRepFun.thy
Christian Urban <urbanc@in.tum.de>
parents:
792
diff
changeset
|
328 |
|
a28f805df355
renamed mk_resp_arg to equiv_relation and exported it in the signature; added tests in AbsRepFun.thy
Christian Urban <urbanc@in.tum.de>
parents:
792
diff
changeset
|
329 |
- Equalities over types that need lifting are replaced by |
a28f805df355
renamed mk_resp_arg to equiv_relation and exported it in the signature; added tests in AbsRepFun.thy
Christian Urban <urbanc@in.tum.de>
parents:
792
diff
changeset
|
330 |
corresponding equivalence relations, for example: |
a28f805df355
renamed mk_resp_arg to equiv_relation and exported it in the signature; added tests in AbsRepFun.thy
Christian Urban <urbanc@in.tum.de>
parents:
792
diff
changeset
|
331 |
|
a28f805df355
renamed mk_resp_arg to equiv_relation and exported it in the signature; added tests in AbsRepFun.thy
Christian Urban <urbanc@in.tum.de>
parents:
792
diff
changeset
|
332 |
A = B ----> R A B |
a28f805df355
renamed mk_resp_arg to equiv_relation and exported it in the signature; added tests in AbsRepFun.thy
Christian Urban <urbanc@in.tum.de>
parents:
792
diff
changeset
|
333 |
|
a28f805df355
renamed mk_resp_arg to equiv_relation and exported it in the signature; added tests in AbsRepFun.thy
Christian Urban <urbanc@in.tum.de>
parents:
792
diff
changeset
|
334 |
or |
a28f805df355
renamed mk_resp_arg to equiv_relation and exported it in the signature; added tests in AbsRepFun.thy
Christian Urban <urbanc@in.tum.de>
parents:
792
diff
changeset
|
335 |
|
a28f805df355
renamed mk_resp_arg to equiv_relation and exported it in the signature; added tests in AbsRepFun.thy
Christian Urban <urbanc@in.tum.de>
parents:
792
diff
changeset
|
336 |
A = B ----> (R ===> R) A B |
a28f805df355
renamed mk_resp_arg to equiv_relation and exported it in the signature; added tests in AbsRepFun.thy
Christian Urban <urbanc@in.tum.de>
parents:
792
diff
changeset
|
337 |
|
a28f805df355
renamed mk_resp_arg to equiv_relation and exported it in the signature; added tests in AbsRepFun.thy
Christian Urban <urbanc@in.tum.de>
parents:
792
diff
changeset
|
338 |
for more complicated types of A and B |
a28f805df355
renamed mk_resp_arg to equiv_relation and exported it in the signature; added tests in AbsRepFun.thy
Christian Urban <urbanc@in.tum.de>
parents:
792
diff
changeset
|
339 |
*) |
a28f805df355
renamed mk_resp_arg to equiv_relation and exported it in the signature; added tests in AbsRepFun.thy
Christian Urban <urbanc@in.tum.de>
parents:
792
diff
changeset
|
340 |
|
792 | 341 |
|
758
3104d62e7a16
moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
342 |
val mk_babs = Const (@{const_name Babs}, dummyT) |
3104d62e7a16
moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
343 |
val mk_ball = Const (@{const_name Ball}, dummyT) |
3104d62e7a16
moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
344 |
val mk_bex = Const (@{const_name Bex}, dummyT) |
3104d62e7a16
moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
345 |
val mk_resp = Const (@{const_name Respects}, dummyT) |
3104d62e7a16
moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
346 |
|
3104d62e7a16
moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
347 |
(* - applies f to the subterm of an abstraction, *) |
3104d62e7a16
moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
348 |
(* otherwise to the given term, *) |
3104d62e7a16
moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
349 |
(* - used by regularize, therefore abstracted *) |
3104d62e7a16
moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
350 |
(* variables do not have to be treated specially *) |
775 | 351 |
fun apply_subt f (trm1, trm2) = |
758
3104d62e7a16
moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
352 |
case (trm1, trm2) of |
775 | 353 |
(Abs (x, T, t), Abs (_ , _, t')) => Abs (x, T, f (t, t')) |
354 |
| _ => f (trm1, trm2) |
|
758
3104d62e7a16
moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
355 |
|
3104d62e7a16
moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
356 |
(* the major type of All and Ex quantifiers *) |
3104d62e7a16
moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
357 |
fun qnt_typ ty = domain_type (domain_type ty) |
3104d62e7a16
moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
358 |
|
3104d62e7a16
moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
359 |
|
3104d62e7a16
moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
360 |
(* produces a regularized version of rtrm *) |
3104d62e7a16
moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
361 |
(* *) |
785 | 362 |
(* - the result might contain dummyTs *) |
758
3104d62e7a16
moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
363 |
(* *) |
3104d62e7a16
moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
364 |
(* - for regularisation we do not need any *) |
3104d62e7a16
moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
365 |
(* special treatment of bound variables *) |
3104d62e7a16
moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
366 |
|
779
3b21b24a5fb6
corrected map declarations for Sum and Prod; moved absrep_fun examples in separate file
Christian Urban <urbanc@in.tum.de>
parents:
776
diff
changeset
|
367 |
fun regularize_trm ctxt (rtrm, qtrm) = |
758
3104d62e7a16
moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
368 |
case (rtrm, qtrm) of |
3104d62e7a16
moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
369 |
(Abs (x, ty, t), Abs (_, ty', t')) => |
3104d62e7a16
moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
370 |
let |
779
3b21b24a5fb6
corrected map declarations for Sum and Prod; moved absrep_fun examples in separate file
Christian Urban <urbanc@in.tum.de>
parents:
776
diff
changeset
|
371 |
val subtrm = Abs(x, ty, regularize_trm ctxt (t, t')) |
758
3104d62e7a16
moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
372 |
in |
3104d62e7a16
moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
373 |
if ty = ty' then subtrm |
831
224909b9399f
removed obsolete equiv_relation and rnamed new_equiv_relation
Christian Urban <urbanc@in.tum.de>
parents:
830
diff
changeset
|
374 |
else mk_babs $ (mk_resp $ equiv_relation ctxt (ty, ty')) $ subtrm |
758
3104d62e7a16
moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
375 |
end |
3104d62e7a16
moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
376 |
|
3104d62e7a16
moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
377 |
| (Const (@{const_name "All"}, ty) $ t, Const (@{const_name "All"}, ty') $ t') => |
3104d62e7a16
moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
378 |
let |
779
3b21b24a5fb6
corrected map declarations for Sum and Prod; moved absrep_fun examples in separate file
Christian Urban <urbanc@in.tum.de>
parents:
776
diff
changeset
|
379 |
val subtrm = apply_subt (regularize_trm ctxt) (t, t') |
758
3104d62e7a16
moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
380 |
in |
3104d62e7a16
moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
381 |
if ty = ty' then Const (@{const_name "All"}, ty) $ subtrm |
831
224909b9399f
removed obsolete equiv_relation and rnamed new_equiv_relation
Christian Urban <urbanc@in.tum.de>
parents:
830
diff
changeset
|
382 |
else mk_ball $ (mk_resp $ equiv_relation ctxt (qnt_typ ty, qnt_typ ty')) $ subtrm |
758
3104d62e7a16
moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
383 |
end |
3104d62e7a16
moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
384 |
|
3104d62e7a16
moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
385 |
| (Const (@{const_name "Ex"}, ty) $ t, Const (@{const_name "Ex"}, ty') $ t') => |
3104d62e7a16
moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
386 |
let |
779
3b21b24a5fb6
corrected map declarations for Sum and Prod; moved absrep_fun examples in separate file
Christian Urban <urbanc@in.tum.de>
parents:
776
diff
changeset
|
387 |
val subtrm = apply_subt (regularize_trm ctxt) (t, t') |
758
3104d62e7a16
moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
388 |
in |
3104d62e7a16
moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
389 |
if ty = ty' then Const (@{const_name "Ex"}, ty) $ subtrm |
831
224909b9399f
removed obsolete equiv_relation and rnamed new_equiv_relation
Christian Urban <urbanc@in.tum.de>
parents:
830
diff
changeset
|
390 |
else mk_bex $ (mk_resp $ equiv_relation ctxt (qnt_typ ty, qnt_typ ty')) $ subtrm |
758
3104d62e7a16
moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
391 |
end |
3104d62e7a16
moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
392 |
|
3104d62e7a16
moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
393 |
| (* equalities need to be replaced by appropriate equivalence relations *) |
3104d62e7a16
moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
394 |
(Const (@{const_name "op ="}, ty), Const (@{const_name "op ="}, ty')) => |
3104d62e7a16
moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
395 |
if ty = ty' then rtrm |
831
224909b9399f
removed obsolete equiv_relation and rnamed new_equiv_relation
Christian Urban <urbanc@in.tum.de>
parents:
830
diff
changeset
|
396 |
else equiv_relation ctxt (domain_type ty, domain_type ty') |
758
3104d62e7a16
moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
397 |
|
760
c1989de100b4
various tunings; map_lookup now raises an exception; addition to FIXME-TODO
Christian Urban <urbanc@in.tum.de>
parents:
758
diff
changeset
|
398 |
| (* in this case we just check whether the given equivalence relation is correct *) |
758
3104d62e7a16
moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
399 |
(rel, Const (@{const_name "op ="}, ty')) => |
3104d62e7a16
moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
400 |
let |
834
fb7fe6aca6f0
tuned previous commit further
Christian Urban <urbanc@in.tum.de>
parents:
833
diff
changeset
|
401 |
(* FIXME: better exception handling *) |
830
89d772dae4d4
New_relations, all works again including concat examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
826
diff
changeset
|
402 |
fun exc rel rel' = LIFT_MATCH ("regularise (relation mismatch)\n[" ^ |
89d772dae4d4
New_relations, all works again including concat examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
826
diff
changeset
|
403 |
Syntax.string_of_term ctxt rel ^ " :: " ^ |
89d772dae4d4
New_relations, all works again including concat examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
826
diff
changeset
|
404 |
Syntax.string_of_typ ctxt (fastype_of rel) ^ "]\n[" ^ |
89d772dae4d4
New_relations, all works again including concat examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
826
diff
changeset
|
405 |
Syntax.string_of_term ctxt rel' ^ " :: " ^ |
89d772dae4d4
New_relations, all works again including concat examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
826
diff
changeset
|
406 |
Syntax.string_of_typ ctxt (fastype_of rel') ^ "]") |
785 | 407 |
val rel_ty = fastype_of rel |
831
224909b9399f
removed obsolete equiv_relation and rnamed new_equiv_relation
Christian Urban <urbanc@in.tum.de>
parents:
830
diff
changeset
|
408 |
val rel' = equiv_relation_chk ctxt (domain_type rel_ty, domain_type ty') |
758
3104d62e7a16
moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
409 |
in |
830
89d772dae4d4
New_relations, all works again including concat examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
826
diff
changeset
|
410 |
if rel' aconv rel then rtrm else raise (exc rel rel') |
758
3104d62e7a16
moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
411 |
end |
3104d62e7a16
moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
412 |
|
3104d62e7a16
moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
413 |
| (_, Const _) => |
3104d62e7a16
moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
414 |
let |
3104d62e7a16
moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
415 |
fun same_name (Const (s, T)) (Const (s', T')) = (s = s') (*andalso (T = T')*) |
3104d62e7a16
moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
416 |
| same_name _ _ = false |
3104d62e7a16
moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
417 |
(* TODO/FIXME: This test is not enough. *) |
3104d62e7a16
moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
418 |
(* Why? *) |
3104d62e7a16
moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
419 |
(* Because constants can have the same name but not be the same |
3104d62e7a16
moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
420 |
constant. All overloaded constants have the same name but because |
3104d62e7a16
moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
421 |
of different types they do differ. |
3104d62e7a16
moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
422 |
|
3104d62e7a16
moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
423 |
This code will let one write a theorem where plus on nat is |
3104d62e7a16
moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
424 |
matched to plus on int, even if the latter is defined differently. |
3104d62e7a16
moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
425 |
|
3104d62e7a16
moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
426 |
This would result in hard to understand failures in injection and |
3104d62e7a16
moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
427 |
cleaning. *) |
3104d62e7a16
moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
428 |
(* cu: if I also test the type, then something else breaks *) |
3104d62e7a16
moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
429 |
in |
3104d62e7a16
moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
430 |
if same_name rtrm qtrm then rtrm |
3104d62e7a16
moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
431 |
else |
3104d62e7a16
moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
432 |
let |
779
3b21b24a5fb6
corrected map declarations for Sum and Prod; moved absrep_fun examples in separate file
Christian Urban <urbanc@in.tum.de>
parents:
776
diff
changeset
|
433 |
val thy = ProofContext.theory_of ctxt |
3b21b24a5fb6
corrected map declarations for Sum and Prod; moved absrep_fun examples in separate file
Christian Urban <urbanc@in.tum.de>
parents:
776
diff
changeset
|
434 |
val qtrm_str = Syntax.string_of_term ctxt qtrm |
758
3104d62e7a16
moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
435 |
val exc1 = LIFT_MATCH ("regularize (constant " ^ qtrm_str ^ " not found)") |
3104d62e7a16
moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
436 |
val exc2 = LIFT_MATCH ("regularize (constant " ^ qtrm_str ^ " mismatch)") |
785 | 437 |
val rtrm' = #rconst (qconsts_lookup thy qtrm) handle NotFound => raise exc1 |
758
3104d62e7a16
moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
438 |
in |
3104d62e7a16
moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
439 |
if Pattern.matches thy (rtrm', rtrm) |
3104d62e7a16
moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
440 |
then rtrm else raise exc2 |
3104d62e7a16
moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
441 |
end |
3104d62e7a16
moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
442 |
end |
3104d62e7a16
moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
443 |
|
3104d62e7a16
moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
444 |
| (t1 $ t2, t1' $ t2') => |
779
3b21b24a5fb6
corrected map declarations for Sum and Prod; moved absrep_fun examples in separate file
Christian Urban <urbanc@in.tum.de>
parents:
776
diff
changeset
|
445 |
(regularize_trm ctxt (t1, t1')) $ (regularize_trm ctxt (t2, t2')) |
758
3104d62e7a16
moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
446 |
|
3104d62e7a16
moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
447 |
| (Bound i, Bound i') => |
3104d62e7a16
moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
448 |
if i = i' then rtrm |
3104d62e7a16
moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
449 |
else raise (LIFT_MATCH "regularize (bounds mismatch)") |
3104d62e7a16
moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
450 |
|
3104d62e7a16
moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
451 |
| _ => |
3104d62e7a16
moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
452 |
let |
779
3b21b24a5fb6
corrected map declarations for Sum and Prod; moved absrep_fun examples in separate file
Christian Urban <urbanc@in.tum.de>
parents:
776
diff
changeset
|
453 |
val rtrm_str = Syntax.string_of_term ctxt rtrm |
3b21b24a5fb6
corrected map declarations for Sum and Prod; moved absrep_fun examples in separate file
Christian Urban <urbanc@in.tum.de>
parents:
776
diff
changeset
|
454 |
val qtrm_str = Syntax.string_of_term ctxt qtrm |
758
3104d62e7a16
moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
455 |
in |
3104d62e7a16
moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
456 |
raise (LIFT_MATCH ("regularize failed (default: " ^ rtrm_str ^ "," ^ qtrm_str ^ ")")) |
3104d62e7a16
moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
457 |
end |
3104d62e7a16
moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
458 |
|
779
3b21b24a5fb6
corrected map declarations for Sum and Prod; moved absrep_fun examples in separate file
Christian Urban <urbanc@in.tum.de>
parents:
776
diff
changeset
|
459 |
fun regularize_trm_chk ctxt (rtrm, qtrm) = |
3b21b24a5fb6
corrected map declarations for Sum and Prod; moved absrep_fun examples in separate file
Christian Urban <urbanc@in.tum.de>
parents:
776
diff
changeset
|
460 |
regularize_trm ctxt (rtrm, qtrm) |
3b21b24a5fb6
corrected map declarations for Sum and Prod; moved absrep_fun examples in separate file
Christian Urban <urbanc@in.tum.de>
parents:
776
diff
changeset
|
461 |
|> Syntax.check_term ctxt |
833
129caba33c03
the chk-functions in quotient_term also simplify the result according to the id_simps; had to remove id_def from this theorem list though; this caused in FSet3 that relied on this rule; the problem is marked with "ID PROBLEM"
Christian Urban <urbanc@in.tum.de>
parents:
832
diff
changeset
|
462 |
|> id_simplify ctxt |
758
3104d62e7a16
moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
463 |
|
797
35436401f00d
added a functor that allows checking what is added to the theorem lists
Christian Urban <urbanc@in.tum.de>
parents:
796
diff
changeset
|
464 |
|
795
a28f805df355
renamed mk_resp_arg to equiv_relation and exported it in the signature; added tests in AbsRepFun.thy
Christian Urban <urbanc@in.tum.de>
parents:
792
diff
changeset
|
465 |
(*********************) |
a28f805df355
renamed mk_resp_arg to equiv_relation and exported it in the signature; added tests in AbsRepFun.thy
Christian Urban <urbanc@in.tum.de>
parents:
792
diff
changeset
|
466 |
(* Rep/Abs Injection *) |
a28f805df355
renamed mk_resp_arg to equiv_relation and exported it in the signature; added tests in AbsRepFun.thy
Christian Urban <urbanc@in.tum.de>
parents:
792
diff
changeset
|
467 |
(*********************) |
a28f805df355
renamed mk_resp_arg to equiv_relation and exported it in the signature; added tests in AbsRepFun.thy
Christian Urban <urbanc@in.tum.de>
parents:
792
diff
changeset
|
468 |
|
758
3104d62e7a16
moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
469 |
(* |
760
c1989de100b4
various tunings; map_lookup now raises an exception; addition to FIXME-TODO
Christian Urban <urbanc@in.tum.de>
parents:
758
diff
changeset
|
470 |
Injection of Rep/Abs means: |
758
3104d62e7a16
moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
471 |
|
3104d62e7a16
moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
472 |
For abstractions |
3104d62e7a16
moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
473 |
: |
760
c1989de100b4
various tunings; map_lookup now raises an exception; addition to FIXME-TODO
Christian Urban <urbanc@in.tum.de>
parents:
758
diff
changeset
|
474 |
* If the type of the abstraction needs lifting, then we add Rep/Abs |
c1989de100b4
various tunings; map_lookup now raises an exception; addition to FIXME-TODO
Christian Urban <urbanc@in.tum.de>
parents:
758
diff
changeset
|
475 |
around the abstraction; otherwise we leave it unchanged. |
758
3104d62e7a16
moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
476 |
|
3104d62e7a16
moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
477 |
For applications: |
3104d62e7a16
moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
478 |
|
760
c1989de100b4
various tunings; map_lookup now raises an exception; addition to FIXME-TODO
Christian Urban <urbanc@in.tum.de>
parents:
758
diff
changeset
|
479 |
* If the application involves a bounded quantifier, we recurse on |
c1989de100b4
various tunings; map_lookup now raises an exception; addition to FIXME-TODO
Christian Urban <urbanc@in.tum.de>
parents:
758
diff
changeset
|
480 |
the second argument. If the application is a bounded abstraction, |
782
86c7ed9f354f
cleaed a bit function mk_typedef_main
Christian Urban <urbanc@in.tum.de>
parents:
779
diff
changeset
|
481 |
we always put an Rep/Abs around it (since bounded abstractions |
86c7ed9f354f
cleaed a bit function mk_typedef_main
Christian Urban <urbanc@in.tum.de>
parents:
779
diff
changeset
|
482 |
are assumed to always need lifting). Otherwise we recurse on both |
86c7ed9f354f
cleaed a bit function mk_typedef_main
Christian Urban <urbanc@in.tum.de>
parents:
779
diff
changeset
|
483 |
arguments. |
758
3104d62e7a16
moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
484 |
|
760
c1989de100b4
various tunings; map_lookup now raises an exception; addition to FIXME-TODO
Christian Urban <urbanc@in.tum.de>
parents:
758
diff
changeset
|
485 |
For constants: |
758
3104d62e7a16
moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
486 |
|
760
c1989de100b4
various tunings; map_lookup now raises an exception; addition to FIXME-TODO
Christian Urban <urbanc@in.tum.de>
parents:
758
diff
changeset
|
487 |
* If the constant is (op =), we leave it always unchanged. |
c1989de100b4
various tunings; map_lookup now raises an exception; addition to FIXME-TODO
Christian Urban <urbanc@in.tum.de>
parents:
758
diff
changeset
|
488 |
Otherwise the type of the constant needs lifting, we put |
c1989de100b4
various tunings; map_lookup now raises an exception; addition to FIXME-TODO
Christian Urban <urbanc@in.tum.de>
parents:
758
diff
changeset
|
489 |
and Rep/Abs around it. |
758
3104d62e7a16
moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
490 |
|
760
c1989de100b4
various tunings; map_lookup now raises an exception; addition to FIXME-TODO
Christian Urban <urbanc@in.tum.de>
parents:
758
diff
changeset
|
491 |
For free variables: |
c1989de100b4
various tunings; map_lookup now raises an exception; addition to FIXME-TODO
Christian Urban <urbanc@in.tum.de>
parents:
758
diff
changeset
|
492 |
|
797
35436401f00d
added a functor that allows checking what is added to the theorem lists
Christian Urban <urbanc@in.tum.de>
parents:
796
diff
changeset
|
493 |
* We put a Rep/Abs around it if the type needs lifting. |
760
c1989de100b4
various tunings; map_lookup now raises an exception; addition to FIXME-TODO
Christian Urban <urbanc@in.tum.de>
parents:
758
diff
changeset
|
494 |
|
c1989de100b4
various tunings; map_lookup now raises an exception; addition to FIXME-TODO
Christian Urban <urbanc@in.tum.de>
parents:
758
diff
changeset
|
495 |
Vars case cannot occur. |
758
3104d62e7a16
moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
496 |
*) |
3104d62e7a16
moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
497 |
|
779
3b21b24a5fb6
corrected map declarations for Sum and Prod; moved absrep_fun examples in separate file
Christian Urban <urbanc@in.tum.de>
parents:
776
diff
changeset
|
498 |
fun mk_repabs ctxt (T, T') trm = |
3b21b24a5fb6
corrected map declarations for Sum and Prod; moved absrep_fun examples in separate file
Christian Urban <urbanc@in.tum.de>
parents:
776
diff
changeset
|
499 |
absrep_fun repF ctxt (T, T') $ (absrep_fun absF ctxt (T, T') $ trm) |
758
3104d62e7a16
moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
500 |
|
833
129caba33c03
the chk-functions in quotient_term also simplify the result according to the id_simps; had to remove id_def from this theorem list though; this caused in FSet3 that relied on this rule; the problem is marked with "ID PROBLEM"
Christian Urban <urbanc@in.tum.de>
parents:
832
diff
changeset
|
501 |
fun inj_repabs_err ctxt msg rtrm qtrm = |
129caba33c03
the chk-functions in quotient_term also simplify the result according to the id_simps; had to remove id_def from this theorem list though; this caused in FSet3 that relied on this rule; the problem is marked with "ID PROBLEM"
Christian Urban <urbanc@in.tum.de>
parents:
832
diff
changeset
|
502 |
let |
129caba33c03
the chk-functions in quotient_term also simplify the result according to the id_simps; had to remove id_def from this theorem list though; this caused in FSet3 that relied on this rule; the problem is marked with "ID PROBLEM"
Christian Urban <urbanc@in.tum.de>
parents:
832
diff
changeset
|
503 |
val rtrm_str = Syntax.string_of_term ctxt rtrm |
129caba33c03
the chk-functions in quotient_term also simplify the result according to the id_simps; had to remove id_def from this theorem list though; this caused in FSet3 that relied on this rule; the problem is marked with "ID PROBLEM"
Christian Urban <urbanc@in.tum.de>
parents:
832
diff
changeset
|
504 |
val qtrm_str = Syntax.string_of_term ctxt qtrm |
129caba33c03
the chk-functions in quotient_term also simplify the result according to the id_simps; had to remove id_def from this theorem list though; this caused in FSet3 that relied on this rule; the problem is marked with "ID PROBLEM"
Christian Urban <urbanc@in.tum.de>
parents:
832
diff
changeset
|
505 |
in |
129caba33c03
the chk-functions in quotient_term also simplify the result according to the id_simps; had to remove id_def from this theorem list though; this caused in FSet3 that relied on this rule; the problem is marked with "ID PROBLEM"
Christian Urban <urbanc@in.tum.de>
parents:
832
diff
changeset
|
506 |
raise LIFT_MATCH (space_implode " " [msg, quote rtrm_str, "and", quote qtrm_str]) |
129caba33c03
the chk-functions in quotient_term also simplify the result according to the id_simps; had to remove id_def from this theorem list though; this caused in FSet3 that relied on this rule; the problem is marked with "ID PROBLEM"
Christian Urban <urbanc@in.tum.de>
parents:
832
diff
changeset
|
507 |
end |
129caba33c03
the chk-functions in quotient_term also simplify the result according to the id_simps; had to remove id_def from this theorem list though; this caused in FSet3 that relied on this rule; the problem is marked with "ID PROBLEM"
Christian Urban <urbanc@in.tum.de>
parents:
832
diff
changeset
|
508 |
|
758
3104d62e7a16
moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
509 |
|
3104d62e7a16
moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
510 |
(* bound variables need to be treated properly, *) |
3104d62e7a16
moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
511 |
(* as the type of subterms needs to be calculated *) |
3104d62e7a16
moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
512 |
|
779
3b21b24a5fb6
corrected map declarations for Sum and Prod; moved absrep_fun examples in separate file
Christian Urban <urbanc@in.tum.de>
parents:
776
diff
changeset
|
513 |
fun inj_repabs_trm ctxt (rtrm, qtrm) = |
758
3104d62e7a16
moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
514 |
case (rtrm, qtrm) of |
3104d62e7a16
moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
515 |
(Const (@{const_name "Ball"}, T) $ r $ t, Const (@{const_name "All"}, _) $ t') => |
779
3b21b24a5fb6
corrected map declarations for Sum and Prod; moved absrep_fun examples in separate file
Christian Urban <urbanc@in.tum.de>
parents:
776
diff
changeset
|
516 |
Const (@{const_name "Ball"}, T) $ r $ (inj_repabs_trm ctxt (t, t')) |
758
3104d62e7a16
moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
517 |
|
3104d62e7a16
moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
518 |
| (Const (@{const_name "Bex"}, T) $ r $ t, Const (@{const_name "Ex"}, _) $ t') => |
779
3b21b24a5fb6
corrected map declarations for Sum and Prod; moved absrep_fun examples in separate file
Christian Urban <urbanc@in.tum.de>
parents:
776
diff
changeset
|
519 |
Const (@{const_name "Bex"}, T) $ r $ (inj_repabs_trm ctxt (t, t')) |
758
3104d62e7a16
moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
520 |
|
3104d62e7a16
moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
521 |
| (Const (@{const_name "Babs"}, T) $ r $ t, t' as (Abs _)) => |
3104d62e7a16
moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
522 |
let |
3104d62e7a16
moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
523 |
val rty = fastype_of rtrm |
3104d62e7a16
moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
524 |
val qty = fastype_of qtrm |
3104d62e7a16
moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
525 |
in |
779
3b21b24a5fb6
corrected map declarations for Sum and Prod; moved absrep_fun examples in separate file
Christian Urban <urbanc@in.tum.de>
parents:
776
diff
changeset
|
526 |
mk_repabs ctxt (rty, qty) (Const (@{const_name "Babs"}, T) $ r $ (inj_repabs_trm ctxt (t, t'))) |
758
3104d62e7a16
moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
527 |
end |
3104d62e7a16
moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
528 |
|
3104d62e7a16
moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
529 |
| (Abs (x, T, t), Abs (x', T', t')) => |
3104d62e7a16
moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
530 |
let |
3104d62e7a16
moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
531 |
val rty = fastype_of rtrm |
3104d62e7a16
moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
532 |
val qty = fastype_of qtrm |
3104d62e7a16
moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
533 |
val (y, s) = Term.dest_abs (x, T, t) |
3104d62e7a16
moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
534 |
val (_, s') = Term.dest_abs (x', T', t') |
3104d62e7a16
moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
535 |
val yvar = Free (y, T) |
779
3b21b24a5fb6
corrected map declarations for Sum and Prod; moved absrep_fun examples in separate file
Christian Urban <urbanc@in.tum.de>
parents:
776
diff
changeset
|
536 |
val result = Term.lambda_name (y, yvar) (inj_repabs_trm ctxt (s, s')) |
758
3104d62e7a16
moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
537 |
in |
3104d62e7a16
moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
538 |
if rty = qty then result |
779
3b21b24a5fb6
corrected map declarations for Sum and Prod; moved absrep_fun examples in separate file
Christian Urban <urbanc@in.tum.de>
parents:
776
diff
changeset
|
539 |
else mk_repabs ctxt (rty, qty) result |
758
3104d62e7a16
moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
540 |
end |
3104d62e7a16
moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
541 |
|
3104d62e7a16
moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
542 |
| (t $ s, t' $ s') => |
779
3b21b24a5fb6
corrected map declarations for Sum and Prod; moved absrep_fun examples in separate file
Christian Urban <urbanc@in.tum.de>
parents:
776
diff
changeset
|
543 |
(inj_repabs_trm ctxt (t, t')) $ (inj_repabs_trm ctxt (s, s')) |
758
3104d62e7a16
moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
544 |
|
3104d62e7a16
moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
545 |
| (Free (_, T), Free (_, T')) => |
3104d62e7a16
moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
546 |
if T = T' then rtrm |
779
3b21b24a5fb6
corrected map declarations for Sum and Prod; moved absrep_fun examples in separate file
Christian Urban <urbanc@in.tum.de>
parents:
776
diff
changeset
|
547 |
else mk_repabs ctxt (T, T') rtrm |
758
3104d62e7a16
moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
548 |
|
3104d62e7a16
moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
549 |
| (_, Const (@{const_name "op ="}, _)) => rtrm |
3104d62e7a16
moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
550 |
|
3104d62e7a16
moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
551 |
| (_, Const (_, T')) => |
3104d62e7a16
moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
552 |
let |
3104d62e7a16
moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
553 |
val rty = fastype_of rtrm |
3104d62e7a16
moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
554 |
in |
3104d62e7a16
moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
555 |
if rty = T' then rtrm |
779
3b21b24a5fb6
corrected map declarations for Sum and Prod; moved absrep_fun examples in separate file
Christian Urban <urbanc@in.tum.de>
parents:
776
diff
changeset
|
556 |
else mk_repabs ctxt (rty, T') rtrm |
758
3104d62e7a16
moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
557 |
end |
3104d62e7a16
moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
558 |
|
833
129caba33c03
the chk-functions in quotient_term also simplify the result according to the id_simps; had to remove id_def from this theorem list though; this caused in FSet3 that relied on this rule; the problem is marked with "ID PROBLEM"
Christian Urban <urbanc@in.tum.de>
parents:
832
diff
changeset
|
559 |
| _ => inj_repabs_err ctxt "injection (default):" rtrm qtrm |
758
3104d62e7a16
moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
560 |
|
779
3b21b24a5fb6
corrected map declarations for Sum and Prod; moved absrep_fun examples in separate file
Christian Urban <urbanc@in.tum.de>
parents:
776
diff
changeset
|
561 |
fun inj_repabs_trm_chk ctxt (rtrm, qtrm) = |
3b21b24a5fb6
corrected map declarations for Sum and Prod; moved absrep_fun examples in separate file
Christian Urban <urbanc@in.tum.de>
parents:
776
diff
changeset
|
562 |
inj_repabs_trm ctxt (rtrm, qtrm) |
3b21b24a5fb6
corrected map declarations for Sum and Prod; moved absrep_fun examples in separate file
Christian Urban <urbanc@in.tum.de>
parents:
776
diff
changeset
|
563 |
|> Syntax.check_term ctxt |
833
129caba33c03
the chk-functions in quotient_term also simplify the result according to the id_simps; had to remove id_def from this theorem list though; this caused in FSet3 that relied on this rule; the problem is marked with "ID PROBLEM"
Christian Urban <urbanc@in.tum.de>
parents:
832
diff
changeset
|
564 |
|> id_simplify ctxt |
776
d1064fa29424
renamed get_fun to absrep_fun; introduced explicit checked versions of the term functions
Christian Urban <urbanc@in.tum.de>
parents:
775
diff
changeset
|
565 |
|
758
3104d62e7a16
moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
566 |
end; (* structure *) |
3104d62e7a16
moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
567 |
|
3104d62e7a16
moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
568 |
|
3104d62e7a16
moved the QuotMain code into two ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
569 |