104 val abs_type = fastype_of abs |
104 val abs_type = fastype_of abs |
105 in |
105 in |
106 (domain_type abs_type, range_type abs_type) |
106 (domain_type abs_type, range_type abs_type) |
107 end |
107 end |
108 |
108 |
109 fun prove_quot_theorem ctxt (rty, qty) = |
109 fun prove_quot_theorem' ctxt (rty, qty) = |
110 case (rty, qty) of |
110 case (rty, qty) of |
111 (Type (s, tys), Type (s', tys')) => |
111 (Type (s, tys), Type (s', tys')) => |
112 if s = s' |
112 if s = s' |
113 then |
113 then |
114 let |
114 let |
115 val args = map (prove_quot_theorem ctxt) (tys ~~ tys') |
115 val args = map (prove_quot_theorem' ctxt) (tys ~~ tys') |
116 in |
116 in |
117 if forall is_id_quot args |
117 if forall is_id_quot args |
118 then |
118 then |
119 @{thm identity_quotient} |
119 @{thm identity_quotient} |
120 else |
120 else |
124 let |
124 let |
125 val quot_thm = get_quot_thm ctxt s' |
125 val quot_thm = get_quot_thm ctxt s' |
126 val (Type (_, rtys), qty_pat) = quot_thm_rty_qty quot_thm |
126 val (Type (_, rtys), qty_pat) = quot_thm_rty_qty quot_thm |
127 val qtyenv = match ctxt equiv_match_err qty_pat qty |
127 val qtyenv = match ctxt equiv_match_err qty_pat qty |
128 val rtys' = map (Envir.subst_type qtyenv) rtys |
128 val rtys' = map (Envir.subst_type qtyenv) rtys |
129 val args = map (prove_quot_theorem ctxt) (tys ~~ rtys') |
129 val args = map (prove_quot_theorem' ctxt) (tys ~~ rtys') |
130 in |
130 in |
131 if forall is_id_quot args |
131 if forall is_id_quot args |
132 then |
132 then |
133 quot_thm |
133 quot_thm |
134 else |
134 else |
150 val ty_inst = Vartab.fold (cons o (prep_ty thy)) match_env [] |
150 val ty_inst = Vartab.fold (cons o (prep_ty thy)) match_env [] |
151 in |
151 in |
152 Thm.instantiate (ty_inst, []) quot_thm |
152 Thm.instantiate (ty_inst, []) quot_thm |
153 end |
153 end |
154 |
154 |
155 fun absrep_fun ctxt (rty, qty) = |
155 fun prove_quot_theorem ctxt (rty, qty) = |
156 let |
156 let |
157 val thy = Proof_Context.theory_of ctxt |
157 val thy = Proof_Context.theory_of ctxt |
158 val quot_thm = prove_quot_theorem ctxt (rty, qty) |
158 val quot_thm = prove_quot_theorem' ctxt (rty, qty) |
159 val forced_quot_thm = force_qty_type thy qty quot_thm |
|
160 in |
159 in |
161 quot_thm_abs forced_quot_thm |
160 force_qty_type thy qty quot_thm |
162 end |
161 end |
163 |
162 |
|
163 fun absrep_fun ctxt (rty, qty) = |
|
164 quot_thm_abs (prove_quot_theorem ctxt (rty, qty)) |
|
165 |
164 fun equiv_relation ctxt (rty, qty) = |
166 fun equiv_relation ctxt (rty, qty) = |
165 let |
167 quot_thm_rel (prove_quot_theorem ctxt (rty, qty)) |
166 val thy = Proof_Context.theory_of ctxt |
|
167 val quot_thm = prove_quot_theorem ctxt (rty, qty) |
|
168 val forced_quot_thm = force_qty_type thy qty quot_thm |
|
169 in |
|
170 quot_thm_rel forced_quot_thm |
|
171 end |
|
172 |
168 |
173 end; |
169 end; |