src/HOL/Tools/typedef_package.ML
changeset 5180 d82a70766af0
parent 5104 230cca8452c7
child 5697 e816c4f1a396
equal deleted inserted replaced
5179:819f90f278db 5180:d82a70766af0
    10   val add_typedecls: (bstring * string list * mixfix) list -> theory -> theory
    10   val add_typedecls: (bstring * string list * mixfix) list -> theory -> theory
    11   val prove_nonempty: cterm -> thm list -> tactic option -> thm
    11   val prove_nonempty: cterm -> thm list -> tactic option -> thm
    12   val add_typedef: string -> bstring * string list * mixfix ->
    12   val add_typedef: string -> bstring * string list * mixfix ->
    13     string -> string list -> thm list -> tactic option -> theory -> theory
    13     string -> string list -> thm list -> tactic option -> theory -> theory
    14   val add_typedef_i: string -> bstring * string list * mixfix ->
    14   val add_typedef_i: string -> bstring * string list * mixfix ->
       
    15     term -> string list -> thm list -> tactic option -> theory -> theory
       
    16   val add_typedef_i_no_def: string -> bstring * string list * mixfix ->
    15     term -> string list -> thm list -> tactic option -> theory -> theory
    17     term -> string list -> thm list -> tactic option -> theory -> theory
    16 end;
    18 end;
    17 
    19 
    18 structure TypedefPackage: TYPEDEF_PACKAGE =
    20 structure TypedefPackage: TYPEDEF_PACKAGE =
    19 struct
    21 struct
    58     error ("Failed to prove nonemptiness of " ^ quote (string_of_cterm cset));
    60     error ("Failed to prove nonemptiness of " ^ quote (string_of_cterm cset));
    59 
    61 
    60 
    62 
    61 (* gen_add_typedef *)
    63 (* gen_add_typedef *)
    62 
    64 
    63 fun gen_add_typedef prep_term name (t, vs, mx) raw_set axms thms usr_tac thy =
    65 fun gen_add_typedef prep_term no_def name (t, vs, mx) raw_set axms thms usr_tac thy =
    64   let
    66   let
    65     val _ = Theory.requires thy "Set" "typedefs";
    67     val _ = Theory.requires thy "Set" "typedefs";
    66     val sign = sign_of thy;
    68     val sign = sign_of thy;
    67     val full_name = Sign.full_name sign;
    69     val full_name = Sign.full_name sign;
    68 
    70 
    85     val setC = Const (full_name name, setT);
    87     val setC = Const (full_name name, setT);
    86     val RepC = Const (full_name Rep_name, newT --> oldT);
    88     val RepC = Const (full_name Rep_name, newT --> oldT);
    87     val AbsC = Const (full_name Abs_name, oldT --> newT);
    89     val AbsC = Const (full_name Abs_name, oldT --> newT);
    88     val x_new = Free ("x", newT);
    90     val x_new = Free ("x", newT);
    89     val y_old = Free ("y", oldT);
    91     val y_old = Free ("y", oldT);
       
    92     val set' = if no_def then set else setC;
    90 
    93 
    91     (*axioms*)
    94     (*axioms*)
    92     val rep_type = HOLogic.mk_Trueprop (HOLogic.mk_mem (RepC $ x_new, setC));
    95     val rep_type = HOLogic.mk_Trueprop (HOLogic.mk_mem (RepC $ x_new, set'));
    93     val rep_type_inv = HOLogic.mk_Trueprop (HOLogic.mk_eq (AbsC $ (RepC $ x_new), x_new));
    96     val rep_type_inv = HOLogic.mk_Trueprop (HOLogic.mk_eq (AbsC $ (RepC $ x_new), x_new));
    94     val abs_type_inv = Logic.mk_implies (HOLogic.mk_Trueprop (HOLogic.mk_mem (y_old, setC)),
    97     val abs_type_inv = Logic.mk_implies (HOLogic.mk_Trueprop (HOLogic.mk_mem (y_old, set')),
    95       HOLogic.mk_Trueprop (HOLogic.mk_eq (RepC $ (AbsC $ y_old), y_old)));
    98       HOLogic.mk_Trueprop (HOLogic.mk_eq (RepC $ (AbsC $ y_old), y_old)));
    96 
    99 
    97 
   100 
    98     (* errors *)
   101     (* errors *)
    99 
   102 
   126     thy
   129     thy
   127     |> PureThy.add_typedecls [(t, vs, mx)]
   130     |> PureThy.add_typedecls [(t, vs, mx)]
   128     |> Theory.add_arities_i
   131     |> Theory.add_arities_i
   129      [(full_name tname, replicate (length vs) HOLogic.termS, HOLogic.termS)]
   132      [(full_name tname, replicate (length vs) HOLogic.termS, HOLogic.termS)]
   130     |> Theory.add_consts_i
   133     |> Theory.add_consts_i
   131      [(name, setT, NoSyn),
   134      ((if no_def then [] else [(name, setT, NoSyn)]) @
   132       (Rep_name, newT --> oldT, NoSyn),
   135       [(Rep_name, newT --> oldT, NoSyn),
   133       (Abs_name, oldT --> newT, NoSyn)]
   136        (Abs_name, oldT --> newT, NoSyn)])
   134     |> (PureThy.add_defs_i o map Attribute.none)
   137     |> (if no_def then I else (PureThy.add_defs_i o map Attribute.none)
   135      [(name ^ "_def", Logic.mk_equals (setC, set))]
   138      [(name ^ "_def", Logic.mk_equals (setC, set))])
   136     |> (PureThy.add_axioms_i o map Attribute.none)
   139     |> (PureThy.add_axioms_i o map Attribute.none)
   137      [(Rep_name, rep_type),
   140      [(Rep_name, rep_type),
   138       (Rep_name ^ "_inverse", rep_type_inv),
   141       (Rep_name ^ "_inverse", rep_type_inv),
   139       (Abs_name ^ "_inverse", abs_type_inv)]
   142       (Abs_name ^ "_inverse", abs_type_inv)]
   140   end
   143   end
   148   read_cterm sg (str, HOLogic.termTVar);
   151   read_cterm sg (str, HOLogic.termTVar);
   149 
   152 
   150 fun cert_term sg tm =
   153 fun cert_term sg tm =
   151   cterm_of sg tm handle TERM (msg, _) => error msg;
   154   cterm_of sg tm handle TERM (msg, _) => error msg;
   152 
   155 
   153 val add_typedef = gen_add_typedef read_term;
   156 val add_typedef = gen_add_typedef read_term false;
   154 val add_typedef_i = gen_add_typedef cert_term;
   157 val add_typedef_i = gen_add_typedef cert_term false;
       
   158 val add_typedef_i_no_def = gen_add_typedef cert_term true;
   155 
   159 
   156 
   160 
   157 end;
   161 end;