equal
deleted
inserted
replaced
33 end; |
33 end; |
34 |
34 |
35 structure Quotient_Term: QUOTIENT_TERM = |
35 structure Quotient_Term: QUOTIENT_TERM = |
36 struct |
36 struct |
37 |
37 |
38 open Quotient_Info; |
|
39 |
|
40 exception LIFT_MATCH of string |
38 exception LIFT_MATCH of string |
41 |
39 |
42 |
40 |
43 |
41 |
44 (*** Aggregate Rep/Abs Function ***) |
42 (*** Aggregate Rep/Abs Function ***) |
65 | RepF => Const (@{const_name comp}, dummyT) $ trm2 $ trm1 |
63 | RepF => Const (@{const_name comp}, dummyT) $ trm2 $ trm1 |
66 |
64 |
67 fun get_mapfun ctxt s = |
65 fun get_mapfun ctxt s = |
68 let |
66 let |
69 val thy = ProofContext.theory_of ctxt |
67 val thy = ProofContext.theory_of ctxt |
70 val mapfun = #mapfun (maps_lookup thy s) handle Quotient_Info.NotFound => |
68 val mapfun = #mapfun (Quotient_Info.maps_lookup thy s) handle Quotient_Info.NotFound => |
71 raise LIFT_MATCH ("No map function for type " ^ quote s ^ " found.") |
69 raise LIFT_MATCH ("No map function for type " ^ quote s ^ " found.") |
72 in |
70 in |
73 Const (mapfun, dummyT) |
71 Const (mapfun, dummyT) |
74 end |
72 end |
75 |
73 |
102 a quotient definition |
100 a quotient definition |
103 *) |
101 *) |
104 fun get_rty_qty ctxt s = |
102 fun get_rty_qty ctxt s = |
105 let |
103 let |
106 val thy = ProofContext.theory_of ctxt |
104 val thy = ProofContext.theory_of ctxt |
107 val qdata = quotdata_lookup thy s handle Quotient_Info.NotFound => |
105 val qdata = Quotient_Info.quotdata_lookup thy s handle Quotient_Info.NotFound => |
108 raise LIFT_MATCH ("No quotient type " ^ quote s ^ " found.") |
106 raise LIFT_MATCH ("No quotient type " ^ quote s ^ " found.") |
109 in |
107 in |
110 (#rtyp qdata, #qtyp qdata) |
108 (#rtyp qdata, #qtyp qdata) |
111 end |
109 end |
112 |
110 |
274 Const (@{const_abbrev "rel_conj"}, dummyT) $ trm1 $ trm2 |
272 Const (@{const_abbrev "rel_conj"}, dummyT) $ trm1 $ trm2 |
275 |
273 |
276 fun get_relmap ctxt s = |
274 fun get_relmap ctxt s = |
277 let |
275 let |
278 val thy = ProofContext.theory_of ctxt |
276 val thy = ProofContext.theory_of ctxt |
279 val relmap = #relmap (maps_lookup thy s) handle Quotient_Info.NotFound => |
277 val relmap = #relmap (Quotient_Info.maps_lookup thy s) handle Quotient_Info.NotFound => |
280 raise LIFT_MATCH ("get_relmap (no relation map function found for type " ^ s ^ ")") |
278 raise LIFT_MATCH ("get_relmap (no relation map function found for type " ^ s ^ ")") |
281 in |
279 in |
282 Const (relmap, dummyT) |
280 Const (relmap, dummyT) |
283 end |
281 end |
284 |
282 |
298 |
296 |
299 fun get_equiv_rel ctxt s = |
297 fun get_equiv_rel ctxt s = |
300 let |
298 let |
301 val thy = ProofContext.theory_of ctxt |
299 val thy = ProofContext.theory_of ctxt |
302 in |
300 in |
303 #equiv_rel (quotdata_lookup thy s) handle Quotient_Info.NotFound => |
301 #equiv_rel (Quotient_Info.quotdata_lookup thy s) handle Quotient_Info.NotFound => |
304 raise LIFT_MATCH ("get_quotdata (no quotient found for type " ^ s ^ ")") |
302 raise LIFT_MATCH ("get_quotdata (no quotient found for type " ^ s ^ ")") |
305 end |
303 end |
306 |
304 |
307 fun equiv_match_err ctxt ty_pat ty = |
305 fun equiv_match_err ctxt ty_pat ty = |
308 let |
306 let |
435 (Type (rs, rtys), Type (qs, qtys)) => |
433 (Type (rs, rtys), Type (qs, qtys)) => |
436 if rs = qs then |
434 if rs = qs then |
437 if length rtys <> length qtys then false |
435 if length rtys <> length qtys then false |
438 else forall (fn x => x = true) (map2 (matches_typ thy) rtys qtys) |
436 else forall (fn x => x = true) (map2 (matches_typ thy) rtys qtys) |
439 else |
437 else |
440 (case quotdata_lookup_raw thy qs of |
438 (case Quotient_Info.quotdata_lookup_raw thy qs of |
441 SOME quotinfo => Sign.typ_instance thy (rT, #rtyp quotinfo) |
439 SOME quotinfo => Sign.typ_instance thy (rT, #rtyp quotinfo) |
442 | NONE => false) |
440 | NONE => false) |
443 | _ => false) |
441 | _ => false) |
444 |
442 |
445 |
443 |
561 | same_const _ _ = false |
559 | same_const _ _ = false |
562 in |
560 in |
563 if same_const rtrm qtrm then rtrm |
561 if same_const rtrm qtrm then rtrm |
564 else |
562 else |
565 let |
563 let |
566 val rtrm' = #rconst (qconsts_lookup thy qtrm) |
564 val rtrm' = #rconst (Quotient_Info.qconsts_lookup thy qtrm) |
567 handle Quotient_Info.NotFound => |
565 handle Quotient_Info.NotFound => |
568 term_mismatch "regularize (constant not found)" ctxt rtrm qtrm |
566 term_mismatch "regularize (constant not found)" ctxt rtrm qtrm |
569 in |
567 in |
570 if Pattern.matches thy (rtrm', rtrm) |
568 if Pattern.matches thy (rtrm', rtrm) |
571 then rtrm else term_mismatch "regularize (constant mismatch)" ctxt rtrm qtrm |
569 then rtrm else term_mismatch "regularize (constant mismatch)" ctxt rtrm qtrm |
751 *) |
749 *) |
752 fun mk_ty_subst qtys direction ctxt = |
750 fun mk_ty_subst qtys direction ctxt = |
753 let |
751 let |
754 val thy = ProofContext.theory_of ctxt |
752 val thy = ProofContext.theory_of ctxt |
755 in |
753 in |
756 quotdata_dest ctxt |
754 Quotient_Info.quotdata_dest ctxt |
757 |> map (fn x => (#rtyp x, #qtyp x)) |
755 |> map (fn x => (#rtyp x, #qtyp x)) |
758 |> filter (fn (_, qty) => member (Sign.typ_instance thy o swap) qtys qty) |
756 |> filter (fn (_, qty) => member (Sign.typ_instance thy o swap) qtys qty) |
759 |> map (if direction then swap else I) |
757 |> map (if direction then swap else I) |
760 end |
758 end |
761 |
759 |
763 let |
761 let |
764 val subst_typ' = subst_typ ctxt (mk_ty_subst qtys direction ctxt) |
762 val subst_typ' = subst_typ ctxt (mk_ty_subst qtys direction ctxt) |
765 fun proper (t1, t2) = subst_typ' (fastype_of t1) = fastype_of t2 |
763 fun proper (t1, t2) = subst_typ' (fastype_of t1) = fastype_of t2 |
766 |
764 |
767 val const_substs = |
765 val const_substs = |
768 qconsts_dest ctxt |
766 Quotient_Info.qconsts_dest ctxt |
769 |> map (fn x => (#rconst x, #qconst x)) |
767 |> map (fn x => (#rconst x, #qconst x)) |
770 |> map (if direction then swap else I) |
768 |> map (if direction then swap else I) |
771 |
769 |
772 val rel_substs = |
770 val rel_substs = |
773 quotdata_dest ctxt |
771 Quotient_Info.quotdata_dest ctxt |
774 |> map (fn x => (#equiv_rel x, HOLogic.eq_const (#qtyp x))) |
772 |> map (fn x => (#equiv_rel x, HOLogic.eq_const (#qtyp x))) |
775 |> map (if direction then swap else I) |
773 |> map (if direction then swap else I) |
776 in |
774 in |
777 filter proper (const_substs @ rel_substs) |
775 filter proper (const_substs @ rel_substs) |
778 end |
776 end |