113 val ps = map (fn (_, n, _, _) => |
113 val ps = map (fn (_, n, _, _) => |
114 (Sign.full_name sign n, Sign.full_name sign (n ^ "_Rep"))) dts; |
114 (Sign.full_name sign n, Sign.full_name sign (n ^ "_Rep"))) dts; |
115 val rps = map Library.swap ps; |
115 val rps = map Library.swap ps; |
116 |
116 |
117 fun replace_types (Type ("nominal.ABS", [T, U])) = |
117 fun replace_types (Type ("nominal.ABS", [T, U])) = |
118 Type ("fun", [T, Type ("nominal.nOption", [replace_types U])]) |
118 Type ("fun", [T, Type ("nominal.noption", [replace_types U])]) |
119 | replace_types (Type (s, Ts)) = |
119 | replace_types (Type (s, Ts)) = |
120 Type (getOpt (AList.lookup op = ps s, s), map replace_types Ts) |
120 Type (getOpt (AList.lookup op = ps s, s), map replace_types Ts) |
121 | replace_types T = T; |
121 | replace_types T = T; |
122 |
122 |
123 fun replace_types' (Type (s, Ts)) = |
123 fun replace_types' (Type (s, Ts)) = |
384 |
384 |
385 val rep_set_names = map (Sign.full_name thy3) (DatatypeProp.indexify_names |
385 val rep_set_names = map (Sign.full_name thy3) (DatatypeProp.indexify_names |
386 (map (fn (i, _) => name_of_typ (nth_dtyp i) ^ "_set") descr)); |
386 (map (fn (i, _) => name_of_typ (nth_dtyp i) ^ "_set") descr)); |
387 val big_rep_name = |
387 val big_rep_name = |
388 space_implode "_" (DatatypeProp.indexify_names (List.mapPartial |
388 space_implode "_" (DatatypeProp.indexify_names (List.mapPartial |
389 (fn (i, ("nominal.nOption", _, _)) => NONE |
389 (fn (i, ("nominal.noption", _, _)) => NONE |
390 | (i, _) => SOME (name_of_typ (nth_dtyp i))) descr)) ^ "_set"; |
390 | (i, _) => SOME (name_of_typ (nth_dtyp i))) descr)) ^ "_set"; |
391 val _ = warning ("big_rep_name: " ^ big_rep_name); |
391 val _ = warning ("big_rep_name: " ^ big_rep_name); |
392 |
392 |
393 fun strip_option (dtf as DtType ("fun", [dt, DtRec i])) = |
393 fun strip_option (dtf as DtType ("fun", [dt, DtRec i])) = |
394 (case AList.lookup op = descr i of |
394 (case AList.lookup op = descr i of |
395 SOME ("nominal.nOption", _, [(_, [dt']), _]) => |
395 SOME ("nominal.noption", _, [(_, [dt']), _]) => |
396 apfst (cons dt) (strip_option dt') |
396 apfst (cons dt) (strip_option dt') |
397 | _ => ([], dtf)) |
397 | _ => ([], dtf)) |
398 | strip_option (DtType ("fun", [dt, DtType ("nominal.nOption", [dt'])])) = |
398 | strip_option (DtType ("fun", [dt, DtType ("nominal.noption", [dt'])])) = |
399 apfst (cons dt) (strip_option dt') |
399 apfst (cons dt) (strip_option dt') |
400 | strip_option dt = ([], dt); |
400 | strip_option dt = ([], dt); |
401 |
401 |
402 val dt_atomTs = distinct (map (typ_of_dtyp descr sorts') |
402 val dt_atomTs = distinct (map (typ_of_dtyp descr sorts') |
403 (List.concat (map (fn (_, (_, _, cs)) => List.concat |
403 (List.concat (map (fn (_, (_, _, cs)) => List.concat |
415 val free = mk_Free "x" (Us ---> T) j; |
415 val free = mk_Free "x" (Us ---> T) j; |
416 val free' = app_bnds free (length Us); |
416 val free' = app_bnds free (length Us); |
417 fun mk_abs_fun (T, (i, t)) = |
417 fun mk_abs_fun (T, (i, t)) = |
418 let val U = fastype_of t |
418 let val U = fastype_of t |
419 in (i + 1, Const ("nominal.abs_fun", [T, U, T] ---> |
419 in (i + 1, Const ("nominal.abs_fun", [T, U, T] ---> |
420 Type ("nominal.nOption", [U])) $ mk_Free "y" T i $ t) |
420 Type ("nominal.noption", [U])) $ mk_Free "y" T i $ t) |
421 end |
421 end |
422 in (j + 1, j' + length Ts, |
422 in (j + 1, j' + length Ts, |
423 case dt'' of |
423 case dt'' of |
424 DtRec k => list_all (map (pair "x") Us, |
424 DtRec k => list_all (map (pair "x") Us, |
425 HOLogic.mk_Trueprop (HOLogic.mk_mem (free', |
425 HOLogic.mk_Trueprop (HOLogic.mk_mem (free', |
436 in Logic.list_implies (prems, concl) |
436 in Logic.list_implies (prems, concl) |
437 end; |
437 end; |
438 |
438 |
439 val (intr_ts, ind_consts) = |
439 val (intr_ts, ind_consts) = |
440 apfst List.concat (ListPair.unzip (List.mapPartial |
440 apfst List.concat (ListPair.unzip (List.mapPartial |
441 (fn ((_, ("nominal.nOption", _, _)), _) => NONE |
441 (fn ((_, ("nominal.noption", _, _)), _) => NONE |
442 | ((i, (_, _, constrs)), rep_set_name) => |
442 | ((i, (_, _, constrs)), rep_set_name) => |
443 let val T = nth_dtyp i |
443 let val T = nth_dtyp i |
444 in SOME (map (make_intr rep_set_name T) constrs, |
444 in SOME (map (make_intr rep_set_name T) constrs, |
445 Const (rep_set_name, HOLogic.mk_setT T)) |
445 Const (rep_set_name, HOLogic.mk_setT T)) |
446 end) |
446 end) |
454 (**** Prove that representing set is closed under permutation ****) |
454 (**** Prove that representing set is closed under permutation ****) |
455 |
455 |
456 val _ = warning "proving closure under permutation..."; |
456 val _ = warning "proving closure under permutation..."; |
457 |
457 |
458 val perm_indnames' = List.mapPartial |
458 val perm_indnames' = List.mapPartial |
459 (fn (x, (_, ("nominal.nOption", _, _))) => NONE | (x, _) => SOME x) |
459 (fn (x, (_, ("nominal.noption", _, _))) => NONE | (x, _) => SOME x) |
460 (perm_indnames ~~ descr); |
460 (perm_indnames ~~ descr); |
461 |
461 |
462 fun mk_perm_closed name = map (fn th => standard (th RS mp)) |
462 fun mk_perm_closed name = map (fn th => standard (th RS mp)) |
463 (List.take (split_conj_thm (Goal.prove thy4 [] [] |
463 (List.take (split_conj_thm (Goal.prove thy4 [] [] |
464 (HOLogic.mk_Trueprop (foldr1 HOLogic.mk_conj (map |
464 (HOLogic.mk_Trueprop (foldr1 HOLogic.mk_conj (map |
578 let |
578 let |
579 val T = fastype_of x; |
579 val T = fastype_of x; |
580 val U = fastype_of t |
580 val U = fastype_of t |
581 in |
581 in |
582 Const ("nominal.abs_fun", T --> U --> T --> |
582 Const ("nominal.abs_fun", T --> U --> T --> |
583 Type ("nominal.nOption", [U])) $ x $ t |
583 Type ("nominal.noption", [U])) $ x $ t |
584 end; |
584 end; |
585 |
585 |
586 val (ty_idxs, _) = foldl |
586 val (ty_idxs, _) = foldl |
587 (fn ((i, ("nominal.nOption", _, _)), p) => p |
587 (fn ((i, ("nominal.noption", _, _)), p) => p |
588 | ((i, _), (ty_idxs, j)) => (ty_idxs @ [(i, j)], j + 1)) ([], 0) descr; |
588 | ((i, _), (ty_idxs, j)) => (ty_idxs @ [(i, j)], j + 1)) ([], 0) descr; |
589 |
589 |
590 fun reindex (DtType (s, dts)) = DtType (s, map reindex dts) |
590 fun reindex (DtType (s, dts)) = DtType (s, map reindex dts) |
591 | reindex (DtRec i) = DtRec (the (AList.lookup op = ty_idxs i)) |
591 | reindex (DtRec i) = DtRec (the (AList.lookup op = ty_idxs i)) |
592 | reindex dt = dt; |
592 | reindex dt = dt; |
597 fun strip_nth_name i s = |
597 fun strip_nth_name i s = |
598 let val xs = NameSpace.unpack s; |
598 let val xs = NameSpace.unpack s; |
599 in NameSpace.pack (Library.nth_map (length xs - i) (strip_suffix 4) xs) end; |
599 in NameSpace.pack (Library.nth_map (length xs - i) (strip_suffix 4) xs) end; |
600 |
600 |
601 val (descr'', ndescr) = ListPair.unzip (List.mapPartial |
601 val (descr'', ndescr) = ListPair.unzip (List.mapPartial |
602 (fn (i, ("nominal.nOption", _, _)) => NONE |
602 (fn (i, ("nominal.noption", _, _)) => NONE |
603 | (i, (s, dts, constrs)) => |
603 | (i, (s, dts, constrs)) => |
604 let |
604 let |
605 val SOME index = AList.lookup op = ty_idxs i; |
605 val SOME index = AList.lookup op = ty_idxs i; |
606 val (constrs1, constrs2) = ListPair.unzip |
606 val (constrs1, constrs2) = ListPair.unzip |
607 (map (fn (cname, cargs) => apfst (pair (strip_nth_name 2 cname)) |
607 (map (fn (cname, cargs) => apfst (pair (strip_nth_name 2 cname)) |
622 Sign.intern_const thy7 ("Rep_" ^ s)) new_type_names; |
622 Sign.intern_const thy7 ("Rep_" ^ s)) new_type_names; |
623 val abs_names = map (fn s => |
623 val abs_names = map (fn s => |
624 Sign.intern_const thy7 ("Abs_" ^ s)) new_type_names; |
624 Sign.intern_const thy7 ("Abs_" ^ s)) new_type_names; |
625 |
625 |
626 val recTs' = List.mapPartial |
626 val recTs' = List.mapPartial |
627 (fn ((_, ("nominal.nOption", _, _)), T) => NONE |
627 (fn ((_, ("nominal.noption", _, _)), T) => NONE |
628 | (_, T) => SOME T) (descr ~~ get_rec_types descr sorts'); |
628 | (_, T) => SOME T) (descr ~~ get_rec_types descr sorts'); |
629 val recTs = get_rec_types descr'' sorts'; |
629 val recTs = get_rec_types descr'' sorts'; |
630 val newTs' = Library.take (length new_type_names, recTs'); |
630 val newTs' = Library.take (length new_type_names, recTs'); |
631 val newTs = Library.take (length new_type_names, recTs); |
631 val newTs = Library.take (length new_type_names, recTs); |
632 |
632 |