src/HOLCF/Tools/Domain/domain_isomorphism.ML
author huffman
Sun, 28 Feb 2010 18:33:57 -0800
changeset 35479 dffffe36344a
parent 35478 90dd1d63ae54
child 35480 7a1f285cad25
permissions -rw-r--r--
store deflation thms for map functions in theory data
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
33774
e11e05b32548 automate solution of domain equations
huffman
parents:
diff changeset
     1
(*  Title:      HOLCF/Tools/domain/domain_isomorphism.ML
e11e05b32548 automate solution of domain equations
huffman
parents:
diff changeset
     2
    Author:     Brian Huffman
e11e05b32548 automate solution of domain equations
huffman
parents:
diff changeset
     3
e11e05b32548 automate solution of domain equations
huffman
parents:
diff changeset
     4
Defines new types satisfying the given domain equations.
e11e05b32548 automate solution of domain equations
huffman
parents:
diff changeset
     5
*)
e11e05b32548 automate solution of domain equations
huffman
parents:
diff changeset
     6
e11e05b32548 automate solution of domain equations
huffman
parents:
diff changeset
     7
signature DOMAIN_ISOMORPHISM =
e11e05b32548 automate solution of domain equations
huffman
parents:
diff changeset
     8
sig
35467
561d8e98d9d3 domain_isomorphism function returns iso_info record
huffman
parents: 35021
diff changeset
     9
  type iso_info =
561d8e98d9d3 domain_isomorphism function returns iso_info record
huffman
parents: 35021
diff changeset
    10
    {
561d8e98d9d3 domain_isomorphism function returns iso_info record
huffman
parents: 35021
diff changeset
    11
      repT : typ,
561d8e98d9d3 domain_isomorphism function returns iso_info record
huffman
parents: 35021
diff changeset
    12
      absT : typ,
561d8e98d9d3 domain_isomorphism function returns iso_info record
huffman
parents: 35021
diff changeset
    13
      rep_const : term,
561d8e98d9d3 domain_isomorphism function returns iso_info record
huffman
parents: 35021
diff changeset
    14
      abs_const : term,
561d8e98d9d3 domain_isomorphism function returns iso_info record
huffman
parents: 35021
diff changeset
    15
      rep_inverse : thm,
561d8e98d9d3 domain_isomorphism function returns iso_info record
huffman
parents: 35021
diff changeset
    16
      abs_inverse : thm
561d8e98d9d3 domain_isomorphism function returns iso_info record
huffman
parents: 35021
diff changeset
    17
    }
33774
e11e05b32548 automate solution of domain equations
huffman
parents:
diff changeset
    18
  val domain_isomorphism:
34149
a0efb4754cb7 add 'morphisms' option to domain_isomorphism command
huffman
parents: 33971
diff changeset
    19
    (string list * binding * mixfix * typ * (binding * binding) option) list
35467
561d8e98d9d3 domain_isomorphism function returns iso_info record
huffman
parents: 35021
diff changeset
    20
      -> theory -> iso_info list * theory
33774
e11e05b32548 automate solution of domain equations
huffman
parents:
diff changeset
    21
  val domain_isomorphism_cmd:
34149
a0efb4754cb7 add 'morphisms' option to domain_isomorphism command
huffman
parents: 33971
diff changeset
    22
    (string list * binding * mixfix * string * (binding * binding) option) list
a0efb4754cb7 add 'morphisms' option to domain_isomorphism command
huffman
parents: 33971
diff changeset
    23
      -> theory -> theory
33791
fef59343b4b3 use theory data for REP_simps and isodefl_rules
huffman
parents: 33790
diff changeset
    24
  val add_type_constructor:
35479
dffffe36344a store deflation thms for map functions in theory data
huffman
parents: 35478
diff changeset
    25
    (string * term * string * thm  * thm * thm * thm) -> theory -> theory
33801
e8535acd302c copy_of_dtyp uses map table from theory data
huffman
parents: 33797
diff changeset
    26
  val get_map_tab:
e8535acd302c copy_of_dtyp uses map table from theory data
huffman
parents: 33797
diff changeset
    27
    theory -> string Symtab.table
33774
e11e05b32548 automate solution of domain equations
huffman
parents:
diff changeset
    28
end;
e11e05b32548 automate solution of domain equations
huffman
parents:
diff changeset
    29
e11e05b32548 automate solution of domain equations
huffman
parents:
diff changeset
    30
structure Domain_Isomorphism :> DOMAIN_ISOMORPHISM =
e11e05b32548 automate solution of domain equations
huffman
parents:
diff changeset
    31
struct
e11e05b32548 automate solution of domain equations
huffman
parents:
diff changeset
    32
33775
7a1518c42c56 cleaned up; factored out fixed-point definition code
huffman
parents: 33774
diff changeset
    33
val beta_ss =
7a1518c42c56 cleaned up; factored out fixed-point definition code
huffman
parents: 33774
diff changeset
    34
  HOL_basic_ss
7a1518c42c56 cleaned up; factored out fixed-point definition code
huffman
parents: 33774
diff changeset
    35
    addsimps simp_thms
7a1518c42c56 cleaned up; factored out fixed-point definition code
huffman
parents: 33774
diff changeset
    36
    addsimps [@{thm beta_cfun}]
7a1518c42c56 cleaned up; factored out fixed-point definition code
huffman
parents: 33774
diff changeset
    37
    addsimprocs [@{simproc cont_proc}];
7a1518c42c56 cleaned up; factored out fixed-point definition code
huffman
parents: 33774
diff changeset
    38
7a1518c42c56 cleaned up; factored out fixed-point definition code
huffman
parents: 33774
diff changeset
    39
val beta_tac = simp_tac beta_ss;
7a1518c42c56 cleaned up; factored out fixed-point definition code
huffman
parents: 33774
diff changeset
    40
33774
e11e05b32548 automate solution of domain equations
huffman
parents:
diff changeset
    41
(******************************************************************************)
33791
fef59343b4b3 use theory data for REP_simps and isodefl_rules
huffman
parents: 33790
diff changeset
    42
(******************************** theory data *********************************)
fef59343b4b3 use theory data for REP_simps and isodefl_rules
huffman
parents: 33790
diff changeset
    43
(******************************************************************************)
fef59343b4b3 use theory data for REP_simps and isodefl_rules
huffman
parents: 33790
diff changeset
    44
fef59343b4b3 use theory data for REP_simps and isodefl_rules
huffman
parents: 33790
diff changeset
    45
structure DeflData = Theory_Data
fef59343b4b3 use theory data for REP_simps and isodefl_rules
huffman
parents: 33790
diff changeset
    46
(
fef59343b4b3 use theory data for REP_simps and isodefl_rules
huffman
parents: 33790
diff changeset
    47
  type T = term Symtab.table;
fef59343b4b3 use theory data for REP_simps and isodefl_rules
huffman
parents: 33790
diff changeset
    48
  val empty = Symtab.empty;
fef59343b4b3 use theory data for REP_simps and isodefl_rules
huffman
parents: 33790
diff changeset
    49
  val extend = I;
fef59343b4b3 use theory data for REP_simps and isodefl_rules
huffman
parents: 33790
diff changeset
    50
  fun merge data = Symtab.merge (K true) data;
fef59343b4b3 use theory data for REP_simps and isodefl_rules
huffman
parents: 33790
diff changeset
    51
);
fef59343b4b3 use theory data for REP_simps and isodefl_rules
huffman
parents: 33790
diff changeset
    52
fef59343b4b3 use theory data for REP_simps and isodefl_rules
huffman
parents: 33790
diff changeset
    53
structure MapData = Theory_Data
fef59343b4b3 use theory data for REP_simps and isodefl_rules
huffman
parents: 33790
diff changeset
    54
(
fef59343b4b3 use theory data for REP_simps and isodefl_rules
huffman
parents: 33790
diff changeset
    55
  type T = string Symtab.table;
fef59343b4b3 use theory data for REP_simps and isodefl_rules
huffman
parents: 33790
diff changeset
    56
  val empty = Symtab.empty;
fef59343b4b3 use theory data for REP_simps and isodefl_rules
huffman
parents: 33790
diff changeset
    57
  val extend = I;
fef59343b4b3 use theory data for REP_simps and isodefl_rules
huffman
parents: 33790
diff changeset
    58
  fun merge data = Symtab.merge (K true) data;
fef59343b4b3 use theory data for REP_simps and isodefl_rules
huffman
parents: 33790
diff changeset
    59
);
fef59343b4b3 use theory data for REP_simps and isodefl_rules
huffman
parents: 33790
diff changeset
    60
35479
dffffe36344a store deflation thms for map functions in theory data
huffman
parents: 35478
diff changeset
    61
structure Thm_List : THEORY_DATA_ARGS =
dffffe36344a store deflation thms for map functions in theory data
huffman
parents: 35478
diff changeset
    62
struct
33791
fef59343b4b3 use theory data for REP_simps and isodefl_rules
huffman
parents: 33790
diff changeset
    63
  type T = thm list;
fef59343b4b3 use theory data for REP_simps and isodefl_rules
huffman
parents: 33790
diff changeset
    64
  val empty = [];
fef59343b4b3 use theory data for REP_simps and isodefl_rules
huffman
parents: 33790
diff changeset
    65
  val extend = I;
fef59343b4b3 use theory data for REP_simps and isodefl_rules
huffman
parents: 33790
diff changeset
    66
  val merge = Thm.merge_thms;
35479
dffffe36344a store deflation thms for map functions in theory data
huffman
parents: 35478
diff changeset
    67
end;
dffffe36344a store deflation thms for map functions in theory data
huffman
parents: 35478
diff changeset
    68
dffffe36344a store deflation thms for map functions in theory data
huffman
parents: 35478
diff changeset
    69
structure RepData = Theory_Data (Thm_List);
33791
fef59343b4b3 use theory data for REP_simps and isodefl_rules
huffman
parents: 33790
diff changeset
    70
35479
dffffe36344a store deflation thms for map functions in theory data
huffman
parents: 35478
diff changeset
    71
structure IsodeflData = Theory_Data (Thm_List);
dffffe36344a store deflation thms for map functions in theory data
huffman
parents: 35478
diff changeset
    72
dffffe36344a store deflation thms for map functions in theory data
huffman
parents: 35478
diff changeset
    73
structure MapIdData = Theory_Data (Thm_List);
dffffe36344a store deflation thms for map functions in theory data
huffman
parents: 35478
diff changeset
    74
dffffe36344a store deflation thms for map functions in theory data
huffman
parents: 35478
diff changeset
    75
structure DeflMapData = Theory_Data (Thm_List);
33809
033831fd9ef3 store map_ID thms in theory data; automate proofs of reach lemmas
huffman
parents: 33807
diff changeset
    76
33791
fef59343b4b3 use theory data for REP_simps and isodefl_rules
huffman
parents: 33790
diff changeset
    77
fun add_type_constructor
35479
dffffe36344a store deflation thms for map functions in theory data
huffman
parents: 35478
diff changeset
    78
  (tname, defl_const, map_name, REP_thm,
dffffe36344a store deflation thms for map functions in theory data
huffman
parents: 35478
diff changeset
    79
   isodefl_thm, map_ID_thm, defl_map_thm) =
33791
fef59343b4b3 use theory data for REP_simps and isodefl_rules
huffman
parents: 33790
diff changeset
    80
    DeflData.map (Symtab.insert (K true) (tname, defl_const))
fef59343b4b3 use theory data for REP_simps and isodefl_rules
huffman
parents: 33790
diff changeset
    81
    #> MapData.map (Symtab.insert (K true) (tname, map_name))
fef59343b4b3 use theory data for REP_simps and isodefl_rules
huffman
parents: 33790
diff changeset
    82
    #> RepData.map (Thm.add_thm REP_thm)
33809
033831fd9ef3 store map_ID thms in theory data; automate proofs of reach lemmas
huffman
parents: 33807
diff changeset
    83
    #> IsodeflData.map (Thm.add_thm isodefl_thm)
35479
dffffe36344a store deflation thms for map functions in theory data
huffman
parents: 35478
diff changeset
    84
    #> MapIdData.map (Thm.add_thm map_ID_thm)
dffffe36344a store deflation thms for map functions in theory data
huffman
parents: 35478
diff changeset
    85
    #> DeflMapData.map (Thm.add_thm defl_map_thm);
33791
fef59343b4b3 use theory data for REP_simps and isodefl_rules
huffman
parents: 33790
diff changeset
    86
33801
e8535acd302c copy_of_dtyp uses map table from theory data
huffman
parents: 33797
diff changeset
    87
val get_map_tab = MapData.get;
e8535acd302c copy_of_dtyp uses map table from theory data
huffman
parents: 33797
diff changeset
    88
33791
fef59343b4b3 use theory data for REP_simps and isodefl_rules
huffman
parents: 33790
diff changeset
    89
fef59343b4b3 use theory data for REP_simps and isodefl_rules
huffman
parents: 33790
diff changeset
    90
(******************************************************************************)
35475
979019ab92eb move common functions into new file holcf_library.ML
huffman
parents: 35474
diff changeset
    91
(************************** building types and terms **************************)
33774
e11e05b32548 automate solution of domain equations
huffman
parents:
diff changeset
    92
(******************************************************************************)
e11e05b32548 automate solution of domain equations
huffman
parents:
diff changeset
    93
35475
979019ab92eb move common functions into new file holcf_library.ML
huffman
parents: 35474
diff changeset
    94
open HOLCF_Library;
33774
e11e05b32548 automate solution of domain equations
huffman
parents:
diff changeset
    95
35475
979019ab92eb move common functions into new file holcf_library.ML
huffman
parents: 35474
diff changeset
    96
infixr 6 ->>;
979019ab92eb move common functions into new file holcf_library.ML
huffman
parents: 35474
diff changeset
    97
infix -->>;
33774
e11e05b32548 automate solution of domain equations
huffman
parents:
diff changeset
    98
e11e05b32548 automate solution of domain equations
huffman
parents:
diff changeset
    99
val deflT = @{typ "udom alg_defl"};
e11e05b32548 automate solution of domain equations
huffman
parents:
diff changeset
   100
33785
2f2d9eb37084 automate definition of map functions; remove unused code
huffman
parents: 33784
diff changeset
   101
fun mapT (T as Type (_, Ts)) =
35475
979019ab92eb move common functions into new file holcf_library.ML
huffman
parents: 35474
diff changeset
   102
    (map (fn T => T ->> T) Ts) -->> (T ->> T)
35474
7675a41e755a get rid of incomplete pattern match warnings
huffman
parents: 35467
diff changeset
   103
  | mapT T = T ->> T;
33785
2f2d9eb37084 automate definition of map functions; remove unused code
huffman
parents: 33784
diff changeset
   104
33774
e11e05b32548 automate solution of domain equations
huffman
parents:
diff changeset
   105
fun mk_Rep_of T =
e11e05b32548 automate solution of domain equations
huffman
parents:
diff changeset
   106
  Const (@{const_name Rep_of}, Term.itselfT T --> deflT) $ Logic.mk_type T;
e11e05b32548 automate solution of domain equations
huffman
parents:
diff changeset
   107
33778
9121ea165a40 automate definition of rep/abs functions
huffman
parents: 33777
diff changeset
   108
fun coerce_const T = Const (@{const_name coerce}, T);
9121ea165a40 automate definition of rep/abs functions
huffman
parents: 33777
diff changeset
   109
33788
481bc899febf automate isodefl proof
huffman
parents: 33785
diff changeset
   110
fun isodefl_const T =
481bc899febf automate isodefl proof
huffman
parents: 33785
diff changeset
   111
  Const (@{const_name isodefl}, (T ->> T) --> deflT --> HOLogic.boolT);
481bc899febf automate isodefl proof
huffman
parents: 33785
diff changeset
   112
33775
7a1518c42c56 cleaned up; factored out fixed-point definition code
huffman
parents: 33774
diff changeset
   113
(* splits a cterm into the right and lefthand sides of equality *)
7a1518c42c56 cleaned up; factored out fixed-point definition code
huffman
parents: 33774
diff changeset
   114
fun dest_eqs t = HOLogic.dest_eq (HOLogic.dest_Trueprop t);
7a1518c42c56 cleaned up; factored out fixed-point definition code
huffman
parents: 33774
diff changeset
   115
7a1518c42c56 cleaned up; factored out fixed-point definition code
huffman
parents: 33774
diff changeset
   116
fun mk_eqs (t, u) = HOLogic.mk_Trueprop (HOLogic.mk_eq (t, u));
7a1518c42c56 cleaned up; factored out fixed-point definition code
huffman
parents: 33774
diff changeset
   117
7a1518c42c56 cleaned up; factored out fixed-point definition code
huffman
parents: 33774
diff changeset
   118
(******************************************************************************)
7a1518c42c56 cleaned up; factored out fixed-point definition code
huffman
parents: 33774
diff changeset
   119
(*************** fixed-point definitions and unfolding theorems ***************)
7a1518c42c56 cleaned up; factored out fixed-point definition code
huffman
parents: 33774
diff changeset
   120
(******************************************************************************)
7a1518c42c56 cleaned up; factored out fixed-point definition code
huffman
parents: 33774
diff changeset
   121
7a1518c42c56 cleaned up; factored out fixed-point definition code
huffman
parents: 33774
diff changeset
   122
fun add_fixdefs
7a1518c42c56 cleaned up; factored out fixed-point definition code
huffman
parents: 33774
diff changeset
   123
    (spec : (binding * term) list)
33788
481bc899febf automate isodefl proof
huffman
parents: 33785
diff changeset
   124
    (thy : theory) : (thm list * thm list) * theory =
33775
7a1518c42c56 cleaned up; factored out fixed-point definition code
huffman
parents: 33774
diff changeset
   125
  let
7a1518c42c56 cleaned up; factored out fixed-point definition code
huffman
parents: 33774
diff changeset
   126
    val binds = map fst spec;
7a1518c42c56 cleaned up; factored out fixed-point definition code
huffman
parents: 33774
diff changeset
   127
    val (lhss, rhss) = ListPair.unzip (map (dest_eqs o snd) spec);
7a1518c42c56 cleaned up; factored out fixed-point definition code
huffman
parents: 33774
diff changeset
   128
    val functional = lambda_tuple lhss (mk_tuple rhss);
7a1518c42c56 cleaned up; factored out fixed-point definition code
huffman
parents: 33774
diff changeset
   129
    val fixpoint = mk_fix (mk_cabs functional);
7a1518c42c56 cleaned up; factored out fixed-point definition code
huffman
parents: 33774
diff changeset
   130
7a1518c42c56 cleaned up; factored out fixed-point definition code
huffman
parents: 33774
diff changeset
   131
    (* project components of fixpoint *)
35474
7675a41e755a get rid of incomplete pattern match warnings
huffman
parents: 35467
diff changeset
   132
    fun mk_projs []      t = []
7675a41e755a get rid of incomplete pattern match warnings
huffman
parents: 35467
diff changeset
   133
      | mk_projs (x::[]) t = [(x, t)]
33775
7a1518c42c56 cleaned up; factored out fixed-point definition code
huffman
parents: 33774
diff changeset
   134
      | mk_projs (x::xs) t = (x, mk_fst t) :: mk_projs xs (mk_snd t);
7a1518c42c56 cleaned up; factored out fixed-point definition code
huffman
parents: 33774
diff changeset
   135
    val projs = mk_projs lhss fixpoint;
7a1518c42c56 cleaned up; factored out fixed-point definition code
huffman
parents: 33774
diff changeset
   136
7a1518c42c56 cleaned up; factored out fixed-point definition code
huffman
parents: 33774
diff changeset
   137
    (* convert parameters to lambda abstractions *)
7a1518c42c56 cleaned up; factored out fixed-point definition code
huffman
parents: 33774
diff changeset
   138
    fun mk_eqn (lhs, rhs) =
7a1518c42c56 cleaned up; factored out fixed-point definition code
huffman
parents: 33774
diff changeset
   139
        case lhs of
7a1518c42c56 cleaned up; factored out fixed-point definition code
huffman
parents: 33774
diff changeset
   140
          Const (@{const_name Rep_CFun}, _) $ f $ (x as Free _) =>
7a1518c42c56 cleaned up; factored out fixed-point definition code
huffman
parents: 33774
diff changeset
   141
            mk_eqn (f, big_lambda x rhs)
7a1518c42c56 cleaned up; factored out fixed-point definition code
huffman
parents: 33774
diff changeset
   142
        | Const _ => Logic.mk_equals (lhs, rhs)
7a1518c42c56 cleaned up; factored out fixed-point definition code
huffman
parents: 33774
diff changeset
   143
        | _ => raise TERM ("lhs not of correct form", [lhs, rhs]);
7a1518c42c56 cleaned up; factored out fixed-point definition code
huffman
parents: 33774
diff changeset
   144
    val eqns = map mk_eqn projs;
7a1518c42c56 cleaned up; factored out fixed-point definition code
huffman
parents: 33774
diff changeset
   145
7a1518c42c56 cleaned up; factored out fixed-point definition code
huffman
parents: 33774
diff changeset
   146
    (* register constant definitions *)
33777
69eae9bca167 get rid of numbers on thy variables
huffman
parents: 33776
diff changeset
   147
    val (fixdef_thms, thy) =
33775
7a1518c42c56 cleaned up; factored out fixed-point definition code
huffman
parents: 33774
diff changeset
   148
      (PureThy.add_defs false o map Thm.no_attributes)
7a1518c42c56 cleaned up; factored out fixed-point definition code
huffman
parents: 33774
diff changeset
   149
        (map (Binding.suffix_name "_def") binds ~~ eqns) thy;
7a1518c42c56 cleaned up; factored out fixed-point definition code
huffman
parents: 33774
diff changeset
   150
7a1518c42c56 cleaned up; factored out fixed-point definition code
huffman
parents: 33774
diff changeset
   151
    (* prove applied version of definitions *)
7a1518c42c56 cleaned up; factored out fixed-point definition code
huffman
parents: 33774
diff changeset
   152
    fun prove_proj (lhs, rhs) =
7a1518c42c56 cleaned up; factored out fixed-point definition code
huffman
parents: 33774
diff changeset
   153
      let
7a1518c42c56 cleaned up; factored out fixed-point definition code
huffman
parents: 33774
diff changeset
   154
        val tac = rewrite_goals_tac fixdef_thms THEN beta_tac 1;
7a1518c42c56 cleaned up; factored out fixed-point definition code
huffman
parents: 33774
diff changeset
   155
        val goal = Logic.mk_equals (lhs, rhs);
33777
69eae9bca167 get rid of numbers on thy variables
huffman
parents: 33776
diff changeset
   156
      in Goal.prove_global thy [] [] goal (K tac) end;
33775
7a1518c42c56 cleaned up; factored out fixed-point definition code
huffman
parents: 33774
diff changeset
   157
    val proj_thms = map prove_proj projs;
7a1518c42c56 cleaned up; factored out fixed-point definition code
huffman
parents: 33774
diff changeset
   158
7a1518c42c56 cleaned up; factored out fixed-point definition code
huffman
parents: 33774
diff changeset
   159
    (* mk_tuple lhss == fixpoint *)
7a1518c42c56 cleaned up; factored out fixed-point definition code
huffman
parents: 33774
diff changeset
   160
    fun pair_equalI (thm1, thm2) = @{thm Pair_equalI} OF [thm1, thm2];
7a1518c42c56 cleaned up; factored out fixed-point definition code
huffman
parents: 33774
diff changeset
   161
    val tuple_fixdef_thm = foldr1 pair_equalI proj_thms;
7a1518c42c56 cleaned up; factored out fixed-point definition code
huffman
parents: 33774
diff changeset
   162
7a1518c42c56 cleaned up; factored out fixed-point definition code
huffman
parents: 33774
diff changeset
   163
    val cont_thm =
33777
69eae9bca167 get rid of numbers on thy variables
huffman
parents: 33776
diff changeset
   164
      Goal.prove_global thy [] [] (mk_trp (mk_cont functional))
33775
7a1518c42c56 cleaned up; factored out fixed-point definition code
huffman
parents: 33774
diff changeset
   165
        (K (beta_tac 1));
7a1518c42c56 cleaned up; factored out fixed-point definition code
huffman
parents: 33774
diff changeset
   166
    val tuple_unfold_thm =
7a1518c42c56 cleaned up; factored out fixed-point definition code
huffman
parents: 33774
diff changeset
   167
      (@{thm def_cont_fix_eq} OF [tuple_fixdef_thm, cont_thm])
33777
69eae9bca167 get rid of numbers on thy variables
huffman
parents: 33776
diff changeset
   168
      |> LocalDefs.unfold (ProofContext.init thy) @{thms split_conv};
33775
7a1518c42c56 cleaned up; factored out fixed-point definition code
huffman
parents: 33774
diff changeset
   169
7a1518c42c56 cleaned up; factored out fixed-point definition code
huffman
parents: 33774
diff changeset
   170
    fun mk_unfold_thms [] thm = []
7a1518c42c56 cleaned up; factored out fixed-point definition code
huffman
parents: 33774
diff changeset
   171
      | mk_unfold_thms (n::[]) thm = [(n, thm)]
7a1518c42c56 cleaned up; factored out fixed-point definition code
huffman
parents: 33774
diff changeset
   172
      | mk_unfold_thms (n::ns) thm = let
7a1518c42c56 cleaned up; factored out fixed-point definition code
huffman
parents: 33774
diff changeset
   173
          val thmL = thm RS @{thm Pair_eqD1};
7a1518c42c56 cleaned up; factored out fixed-point definition code
huffman
parents: 33774
diff changeset
   174
          val thmR = thm RS @{thm Pair_eqD2};
7a1518c42c56 cleaned up; factored out fixed-point definition code
huffman
parents: 33774
diff changeset
   175
        in (n, thmL) :: mk_unfold_thms ns thmR end;
7a1518c42c56 cleaned up; factored out fixed-point definition code
huffman
parents: 33774
diff changeset
   176
    val unfold_binds = map (Binding.suffix_name "_unfold") binds;
7a1518c42c56 cleaned up; factored out fixed-point definition code
huffman
parents: 33774
diff changeset
   177
7a1518c42c56 cleaned up; factored out fixed-point definition code
huffman
parents: 33774
diff changeset
   178
    (* register unfold theorems *)
33777
69eae9bca167 get rid of numbers on thy variables
huffman
parents: 33776
diff changeset
   179
    val (unfold_thms, thy) =
35021
c839a4c670c6 renamed old-style Drule.standard to Drule.export_without_context, to emphasize that this is in no way a standard operation;
wenzelm
parents: 34149
diff changeset
   180
      (PureThy.add_thms o map (Thm.no_attributes o apsnd Drule.export_without_context))
33777
69eae9bca167 get rid of numbers on thy variables
huffman
parents: 33776
diff changeset
   181
        (mk_unfold_thms unfold_binds tuple_unfold_thm) thy;
33775
7a1518c42c56 cleaned up; factored out fixed-point definition code
huffman
parents: 33774
diff changeset
   182
  in
33788
481bc899febf automate isodefl proof
huffman
parents: 33785
diff changeset
   183
    ((proj_thms, unfold_thms), thy)
33775
7a1518c42c56 cleaned up; factored out fixed-point definition code
huffman
parents: 33774
diff changeset
   184
  end;
7a1518c42c56 cleaned up; factored out fixed-point definition code
huffman
parents: 33774
diff changeset
   185
7a1518c42c56 cleaned up; factored out fixed-point definition code
huffman
parents: 33774
diff changeset
   186
33774
e11e05b32548 automate solution of domain equations
huffman
parents:
diff changeset
   187
(******************************************************************************)
33790
b2ff505e30f8 replace defl_tab and map_tab with theory data
huffman
parents: 33789
diff changeset
   188
(****************** deflation combinators and map functions *******************)
b2ff505e30f8 replace defl_tab and map_tab with theory data
huffman
parents: 33789
diff changeset
   189
(******************************************************************************)
33774
e11e05b32548 automate solution of domain equations
huffman
parents:
diff changeset
   190
e11e05b32548 automate solution of domain equations
huffman
parents:
diff changeset
   191
fun defl_of_typ
e11e05b32548 automate solution of domain equations
huffman
parents:
diff changeset
   192
    (tab : term Symtab.table)
e11e05b32548 automate solution of domain equations
huffman
parents:
diff changeset
   193
    (T : typ) : term =
e11e05b32548 automate solution of domain equations
huffman
parents:
diff changeset
   194
  let
e11e05b32548 automate solution of domain equations
huffman
parents:
diff changeset
   195
    fun is_closed_typ (Type (_, Ts)) = forall is_closed_typ Ts
e11e05b32548 automate solution of domain equations
huffman
parents:
diff changeset
   196
      | is_closed_typ _ = false;
33785
2f2d9eb37084 automate definition of map functions; remove unused code
huffman
parents: 33784
diff changeset
   197
    fun defl_of (TFree (a, _)) = Free (Library.unprefix "'" a, deflT)
33774
e11e05b32548 automate solution of domain equations
huffman
parents:
diff changeset
   198
      | defl_of (TVar _) = error ("defl_of_typ: TVar")
e11e05b32548 automate solution of domain equations
huffman
parents:
diff changeset
   199
      | defl_of (T as Type (c, Ts)) =
33775
7a1518c42c56 cleaned up; factored out fixed-point definition code
huffman
parents: 33774
diff changeset
   200
        case Symtab.lookup tab c of
35478
90dd1d63ae54 use function list_ccomb
huffman
parents: 35477
diff changeset
   201
          SOME t => list_ccomb (t, map defl_of Ts)
33774
e11e05b32548 automate solution of domain equations
huffman
parents:
diff changeset
   202
        | NONE => if is_closed_typ T
e11e05b32548 automate solution of domain equations
huffman
parents:
diff changeset
   203
                  then mk_Rep_of T
e11e05b32548 automate solution of domain equations
huffman
parents:
diff changeset
   204
                  else error ("defl_of_typ: type variable under unsupported type constructor " ^ c);
e11e05b32548 automate solution of domain equations
huffman
parents:
diff changeset
   205
  in defl_of T end;
e11e05b32548 automate solution of domain equations
huffman
parents:
diff changeset
   206
33785
2f2d9eb37084 automate definition of map functions; remove unused code
huffman
parents: 33784
diff changeset
   207
fun map_of_typ
2f2d9eb37084 automate definition of map functions; remove unused code
huffman
parents: 33784
diff changeset
   208
    (tab : string Symtab.table)
2f2d9eb37084 automate definition of map functions; remove unused code
huffman
parents: 33784
diff changeset
   209
    (T : typ) : term =
33774
e11e05b32548 automate solution of domain equations
huffman
parents:
diff changeset
   210
  let
33785
2f2d9eb37084 automate definition of map functions; remove unused code
huffman
parents: 33784
diff changeset
   211
    fun is_closed_typ (Type (_, Ts)) = forall is_closed_typ Ts
2f2d9eb37084 automate definition of map functions; remove unused code
huffman
parents: 33784
diff changeset
   212
      | is_closed_typ _ = false;
2f2d9eb37084 automate definition of map functions; remove unused code
huffman
parents: 33784
diff changeset
   213
    fun map_of (T as TFree (a, _)) = Free (Library.unprefix "'" a, T ->> T)
2f2d9eb37084 automate definition of map functions; remove unused code
huffman
parents: 33784
diff changeset
   214
      | map_of (T as TVar _) = error ("map_of_typ: TVar")
2f2d9eb37084 automate definition of map functions; remove unused code
huffman
parents: 33784
diff changeset
   215
      | map_of (T as Type (c, Ts)) =
2f2d9eb37084 automate definition of map functions; remove unused code
huffman
parents: 33784
diff changeset
   216
        case Symtab.lookup tab c of
35478
90dd1d63ae54 use function list_ccomb
huffman
parents: 35477
diff changeset
   217
          SOME t => list_ccomb (Const (t, mapT T), map map_of Ts)
33785
2f2d9eb37084 automate definition of map functions; remove unused code
huffman
parents: 33784
diff changeset
   218
        | NONE => if is_closed_typ T
35475
979019ab92eb move common functions into new file holcf_library.ML
huffman
parents: 35474
diff changeset
   219
                  then mk_ID T
33785
2f2d9eb37084 automate definition of map functions; remove unused code
huffman
parents: 33784
diff changeset
   220
                  else error ("map_of_typ: type variable under unsupported type constructor " ^ c);
2f2d9eb37084 automate definition of map functions; remove unused code
huffman
parents: 33784
diff changeset
   221
  in map_of T end;
2f2d9eb37084 automate definition of map functions; remove unused code
huffman
parents: 33784
diff changeset
   222
33774
e11e05b32548 automate solution of domain equations
huffman
parents:
diff changeset
   223
e11e05b32548 automate solution of domain equations
huffman
parents:
diff changeset
   224
(******************************************************************************)
35477
b972233773dd add function define_const
huffman
parents: 35475
diff changeset
   225
(********************* declaring definitions and theorems *********************)
b972233773dd add function define_const
huffman
parents: 35475
diff changeset
   226
(******************************************************************************)
b972233773dd add function define_const
huffman
parents: 35475
diff changeset
   227
b972233773dd add function define_const
huffman
parents: 35475
diff changeset
   228
fun define_const
b972233773dd add function define_const
huffman
parents: 35475
diff changeset
   229
    (bind : binding, rhs : term)
b972233773dd add function define_const
huffman
parents: 35475
diff changeset
   230
    (thy : theory)
b972233773dd add function define_const
huffman
parents: 35475
diff changeset
   231
    : (term * thm) * theory =
b972233773dd add function define_const
huffman
parents: 35475
diff changeset
   232
  let
b972233773dd add function define_const
huffman
parents: 35475
diff changeset
   233
    val typ = Term.fastype_of rhs;
b972233773dd add function define_const
huffman
parents: 35475
diff changeset
   234
    val (const, thy) = Sign.declare_const ((bind, typ), NoSyn) thy;
b972233773dd add function define_const
huffman
parents: 35475
diff changeset
   235
    val eqn = Logic.mk_equals (const, rhs);
b972233773dd add function define_const
huffman
parents: 35475
diff changeset
   236
    val def = Thm.no_attributes (Binding.suffix_name "_def" bind, eqn);
b972233773dd add function define_const
huffman
parents: 35475
diff changeset
   237
    val (def_thm, thy) = yield_singleton (PureThy.add_defs false) def thy;
b972233773dd add function define_const
huffman
parents: 35475
diff changeset
   238
  in
b972233773dd add function define_const
huffman
parents: 35475
diff changeset
   239
    ((const, def_thm), thy)
b972233773dd add function define_const
huffman
parents: 35475
diff changeset
   240
  end;
b972233773dd add function define_const
huffman
parents: 35475
diff changeset
   241
b972233773dd add function define_const
huffman
parents: 35475
diff changeset
   242
(******************************************************************************)
b972233773dd add function define_const
huffman
parents: 35475
diff changeset
   243
(******************************* main function ********************************)
b972233773dd add function define_const
huffman
parents: 35475
diff changeset
   244
(******************************************************************************)
33774
e11e05b32548 automate solution of domain equations
huffman
parents:
diff changeset
   245
35467
561d8e98d9d3 domain_isomorphism function returns iso_info record
huffman
parents: 35021
diff changeset
   246
type iso_info =
561d8e98d9d3 domain_isomorphism function returns iso_info record
huffman
parents: 35021
diff changeset
   247
  {
561d8e98d9d3 domain_isomorphism function returns iso_info record
huffman
parents: 35021
diff changeset
   248
    repT : typ,
561d8e98d9d3 domain_isomorphism function returns iso_info record
huffman
parents: 35021
diff changeset
   249
    absT : typ,
561d8e98d9d3 domain_isomorphism function returns iso_info record
huffman
parents: 35021
diff changeset
   250
    rep_const : term,
561d8e98d9d3 domain_isomorphism function returns iso_info record
huffman
parents: 35021
diff changeset
   251
    abs_const : term,
561d8e98d9d3 domain_isomorphism function returns iso_info record
huffman
parents: 35021
diff changeset
   252
    rep_inverse : thm,
561d8e98d9d3 domain_isomorphism function returns iso_info record
huffman
parents: 35021
diff changeset
   253
    abs_inverse : thm
561d8e98d9d3 domain_isomorphism function returns iso_info record
huffman
parents: 35021
diff changeset
   254
  }
561d8e98d9d3 domain_isomorphism function returns iso_info record
huffman
parents: 35021
diff changeset
   255
33774
e11e05b32548 automate solution of domain equations
huffman
parents:
diff changeset
   256
fun read_typ thy str sorts =
e11e05b32548 automate solution of domain equations
huffman
parents:
diff changeset
   257
  let
e11e05b32548 automate solution of domain equations
huffman
parents:
diff changeset
   258
    val ctxt = ProofContext.init thy
e11e05b32548 automate solution of domain equations
huffman
parents:
diff changeset
   259
      |> fold (Variable.declare_typ o TFree) sorts;
e11e05b32548 automate solution of domain equations
huffman
parents:
diff changeset
   260
    val T = Syntax.read_typ ctxt str;
e11e05b32548 automate solution of domain equations
huffman
parents:
diff changeset
   261
  in (T, Term.add_tfreesT T sorts) end;
e11e05b32548 automate solution of domain equations
huffman
parents:
diff changeset
   262
e11e05b32548 automate solution of domain equations
huffman
parents:
diff changeset
   263
fun cert_typ sign raw_T sorts =
e11e05b32548 automate solution of domain equations
huffman
parents:
diff changeset
   264
  let
e11e05b32548 automate solution of domain equations
huffman
parents:
diff changeset
   265
    val T = Type.no_tvars (Sign.certify_typ sign raw_T)
e11e05b32548 automate solution of domain equations
huffman
parents:
diff changeset
   266
      handle TYPE (msg, _, _) => error msg;
e11e05b32548 automate solution of domain equations
huffman
parents:
diff changeset
   267
    val sorts' = Term.add_tfreesT T sorts;
e11e05b32548 automate solution of domain equations
huffman
parents:
diff changeset
   268
    val _ =
e11e05b32548 automate solution of domain equations
huffman
parents:
diff changeset
   269
      case duplicates (op =) (map fst sorts') of
e11e05b32548 automate solution of domain equations
huffman
parents:
diff changeset
   270
        [] => ()
e11e05b32548 automate solution of domain equations
huffman
parents:
diff changeset
   271
      | dups => error ("Inconsistent sort constraints for " ^ commas dups)
e11e05b32548 automate solution of domain equations
huffman
parents:
diff changeset
   272
  in (T, sorts') end;
e11e05b32548 automate solution of domain equations
huffman
parents:
diff changeset
   273
e11e05b32548 automate solution of domain equations
huffman
parents:
diff changeset
   274
fun gen_domain_isomorphism
e11e05b32548 automate solution of domain equations
huffman
parents:
diff changeset
   275
    (prep_typ: theory -> 'a -> (string * sort) list -> typ * (string * sort) list)
34149
a0efb4754cb7 add 'morphisms' option to domain_isomorphism command
huffman
parents: 33971
diff changeset
   276
    (doms_raw: (string list * binding * mixfix * 'a * (binding * binding) option) list)
33774
e11e05b32548 automate solution of domain equations
huffman
parents:
diff changeset
   277
    (thy: theory)
35467
561d8e98d9d3 domain_isomorphism function returns iso_info record
huffman
parents: 35021
diff changeset
   278
    : iso_info list * theory =
33774
e11e05b32548 automate solution of domain equations
huffman
parents:
diff changeset
   279
  let
33792
002e0e017311 change Theory.requires
huffman
parents: 33791
diff changeset
   280
    val _ = Theory.requires thy "Representable" "domain isomorphisms";
33774
e11e05b32548 automate solution of domain equations
huffman
parents:
diff changeset
   281
e11e05b32548 automate solution of domain equations
huffman
parents:
diff changeset
   282
    (* this theory is used just for parsing *)
e11e05b32548 automate solution of domain equations
huffman
parents:
diff changeset
   283
    val tmp_thy = thy |>
e11e05b32548 automate solution of domain equations
huffman
parents:
diff changeset
   284
      Theory.copy |>
34149
a0efb4754cb7 add 'morphisms' option to domain_isomorphism command
huffman
parents: 33971
diff changeset
   285
      Sign.add_types (map (fn (tvs, tname, mx, _, morphs) =>
33774
e11e05b32548 automate solution of domain equations
huffman
parents:
diff changeset
   286
        (tname, length tvs, mx)) doms_raw);
e11e05b32548 automate solution of domain equations
huffman
parents:
diff changeset
   287
34149
a0efb4754cb7 add 'morphisms' option to domain_isomorphism command
huffman
parents: 33971
diff changeset
   288
    fun prep_dom thy (vs, t, mx, typ_raw, morphs) sorts =
33774
e11e05b32548 automate solution of domain equations
huffman
parents:
diff changeset
   289
      let val (typ, sorts') = prep_typ thy typ_raw sorts
34149
a0efb4754cb7 add 'morphisms' option to domain_isomorphism command
huffman
parents: 33971
diff changeset
   290
      in ((vs, t, mx, typ, morphs), sorts') end;
33774
e11e05b32548 automate solution of domain equations
huffman
parents:
diff changeset
   291
34149
a0efb4754cb7 add 'morphisms' option to domain_isomorphism command
huffman
parents: 33971
diff changeset
   292
    val (doms : (string list * binding * mixfix * typ * (binding * binding) option) list,
33774
e11e05b32548 automate solution of domain equations
huffman
parents:
diff changeset
   293
         sorts : (string * sort) list) =
e11e05b32548 automate solution of domain equations
huffman
parents:
diff changeset
   294
      fold_map (prep_dom tmp_thy) doms_raw [];
e11e05b32548 automate solution of domain equations
huffman
parents:
diff changeset
   295
33775
7a1518c42c56 cleaned up; factored out fixed-point definition code
huffman
parents: 33774
diff changeset
   296
    (* domain equations *)
34149
a0efb4754cb7 add 'morphisms' option to domain_isomorphism command
huffman
parents: 33971
diff changeset
   297
    fun mk_dom_eqn (vs, tbind, mx, rhs, morphs) =
33775
7a1518c42c56 cleaned up; factored out fixed-point definition code
huffman
parents: 33774
diff changeset
   298
      let fun arg v = TFree (v, the (AList.lookup (op =) sorts v));
7a1518c42c56 cleaned up; factored out fixed-point definition code
huffman
parents: 33774
diff changeset
   299
      in (Type (Sign.full_name tmp_thy tbind, map arg vs), rhs) end;
7a1518c42c56 cleaned up; factored out fixed-point definition code
huffman
parents: 33774
diff changeset
   300
    val dom_eqns = map mk_dom_eqn doms;
7a1518c42c56 cleaned up; factored out fixed-point definition code
huffman
parents: 33774
diff changeset
   301
7a1518c42c56 cleaned up; factored out fixed-point definition code
huffman
parents: 33774
diff changeset
   302
    (* check for valid type parameters *)
35474
7675a41e755a get rid of incomplete pattern match warnings
huffman
parents: 35467
diff changeset
   303
    val (tyvars, _, _, _, _) = hd doms;
34149
a0efb4754cb7 add 'morphisms' option to domain_isomorphism command
huffman
parents: 33971
diff changeset
   304
    val new_doms = map (fn (tvs, tname, mx, _, _) =>
33774
e11e05b32548 automate solution of domain equations
huffman
parents:
diff changeset
   305
      let val full_tname = Sign.full_name tmp_thy tname
e11e05b32548 automate solution of domain equations
huffman
parents:
diff changeset
   306
      in
e11e05b32548 automate solution of domain equations
huffman
parents:
diff changeset
   307
        (case duplicates (op =) tvs of
e11e05b32548 automate solution of domain equations
huffman
parents:
diff changeset
   308
          [] =>
33775
7a1518c42c56 cleaned up; factored out fixed-point definition code
huffman
parents: 33774
diff changeset
   309
            if eq_set (op =) (tyvars, tvs) then (full_tname, tvs)
33774
e11e05b32548 automate solution of domain equations
huffman
parents:
diff changeset
   310
            else error ("Mutually recursive domains must have same type parameters")
e11e05b32548 automate solution of domain equations
huffman
parents:
diff changeset
   311
        | dups => error ("Duplicate parameter(s) for domain " ^ quote (Binding.str_of tname) ^
e11e05b32548 automate solution of domain equations
huffman
parents:
diff changeset
   312
            " : " ^ commas dups))
33775
7a1518c42c56 cleaned up; factored out fixed-point definition code
huffman
parents: 33774
diff changeset
   313
      end) doms;
34149
a0efb4754cb7 add 'morphisms' option to domain_isomorphism command
huffman
parents: 33971
diff changeset
   314
    val dom_binds = map (fn (_, tbind, _, _, _) => tbind) doms;
a0efb4754cb7 add 'morphisms' option to domain_isomorphism command
huffman
parents: 33971
diff changeset
   315
    val morphs = map (fn (_, _, _, _, morphs) => morphs) doms;
33774
e11e05b32548 automate solution of domain equations
huffman
parents:
diff changeset
   316
33784
7e434813752f change naming convention for deflation combinators
huffman
parents: 33782
diff changeset
   317
    (* declare deflation combinator constants *)
34149
a0efb4754cb7 add 'morphisms' option to domain_isomorphism command
huffman
parents: 33971
diff changeset
   318
    fun declare_defl_const (vs, tbind, mx, rhs, morphs) thy =
33774
e11e05b32548 automate solution of domain equations
huffman
parents:
diff changeset
   319
      let
35475
979019ab92eb move common functions into new file holcf_library.ML
huffman
parents: 35474
diff changeset
   320
        val defl_type = map (K deflT) vs -->> deflT;
33784
7e434813752f change naming convention for deflation combinators
huffman
parents: 33782
diff changeset
   321
        val defl_bind = Binding.suffix_name "_defl" tbind;
33774
e11e05b32548 automate solution of domain equations
huffman
parents:
diff changeset
   322
      in
33784
7e434813752f change naming convention for deflation combinators
huffman
parents: 33782
diff changeset
   323
        Sign.declare_const ((defl_bind, defl_type), NoSyn) thy
33774
e11e05b32548 automate solution of domain equations
huffman
parents:
diff changeset
   324
      end;
33784
7e434813752f change naming convention for deflation combinators
huffman
parents: 33782
diff changeset
   325
    val (defl_consts, thy) = fold_map declare_defl_const doms thy;
33774
e11e05b32548 automate solution of domain equations
huffman
parents:
diff changeset
   326
33775
7a1518c42c56 cleaned up; factored out fixed-point definition code
huffman
parents: 33774
diff changeset
   327
    (* defining equations for type combinators *)
33790
b2ff505e30f8 replace defl_tab and map_tab with theory data
huffman
parents: 33789
diff changeset
   328
    val defl_tab1 = DeflData.get thy;
33775
7a1518c42c56 cleaned up; factored out fixed-point definition code
huffman
parents: 33774
diff changeset
   329
    val defl_tab2 =
33784
7e434813752f change naming convention for deflation combinators
huffman
parents: 33782
diff changeset
   330
      Symtab.make (map (fst o dest_Type o fst) dom_eqns ~~ defl_consts);
33775
7a1518c42c56 cleaned up; factored out fixed-point definition code
huffman
parents: 33774
diff changeset
   331
    val defl_tab' = Symtab.merge (K true) (defl_tab1, defl_tab2);
33790
b2ff505e30f8 replace defl_tab and map_tab with theory data
huffman
parents: 33789
diff changeset
   332
    val thy = DeflData.put defl_tab' thy;
33776
5048b02c2bbb automate proofs of REP equations
huffman
parents: 33775
diff changeset
   333
    fun mk_defl_spec (lhsT, rhsT) =
33785
2f2d9eb37084 automate definition of map functions; remove unused code
huffman
parents: 33784
diff changeset
   334
      mk_eqs (defl_of_typ defl_tab' lhsT,
2f2d9eb37084 automate definition of map functions; remove unused code
huffman
parents: 33784
diff changeset
   335
              defl_of_typ defl_tab' rhsT);
33775
7a1518c42c56 cleaned up; factored out fixed-point definition code
huffman
parents: 33774
diff changeset
   336
    val defl_specs = map mk_defl_spec dom_eqns;
33774
e11e05b32548 automate solution of domain equations
huffman
parents:
diff changeset
   337
33784
7e434813752f change naming convention for deflation combinators
huffman
parents: 33782
diff changeset
   338
    (* register recursive definition of deflation combinators *)
7e434813752f change naming convention for deflation combinators
huffman
parents: 33782
diff changeset
   339
    val defl_binds = map (Binding.suffix_name "_defl") dom_binds;
33788
481bc899febf automate isodefl proof
huffman
parents: 33785
diff changeset
   340
    val ((defl_apply_thms, defl_unfold_thms), thy) =
481bc899febf automate isodefl proof
huffman
parents: 33785
diff changeset
   341
      add_fixdefs (defl_binds ~~ defl_specs) thy;
33774
e11e05b32548 automate solution of domain equations
huffman
parents:
diff changeset
   342
33776
5048b02c2bbb automate proofs of REP equations
huffman
parents: 33775
diff changeset
   343
    (* define types using deflation combinators *)
34149
a0efb4754cb7 add 'morphisms' option to domain_isomorphism command
huffman
parents: 33971
diff changeset
   344
    fun make_repdef ((vs, tbind, mx, _, _), defl_const) thy =
33774
e11e05b32548 automate solution of domain equations
huffman
parents:
diff changeset
   345
      let
e11e05b32548 automate solution of domain equations
huffman
parents:
diff changeset
   346
        fun tfree a = TFree (a, the (AList.lookup (op =) sorts a))
e11e05b32548 automate solution of domain equations
huffman
parents:
diff changeset
   347
        val reps = map (mk_Rep_of o tfree) vs;
35478
90dd1d63ae54 use function list_ccomb
huffman
parents: 35477
diff changeset
   348
        val defl = list_ccomb (defl_const, reps);
33777
69eae9bca167 get rid of numbers on thy variables
huffman
parents: 33776
diff changeset
   349
        val ((_, _, _, {REP, ...}), thy) =
33774
e11e05b32548 automate solution of domain equations
huffman
parents:
diff changeset
   350
          Repdef.add_repdef false NONE (tbind, vs, mx) defl NONE thy;
e11e05b32548 automate solution of domain equations
huffman
parents:
diff changeset
   351
      in
33777
69eae9bca167 get rid of numbers on thy variables
huffman
parents: 33776
diff changeset
   352
        (REP, thy)
33774
e11e05b32548 automate solution of domain equations
huffman
parents:
diff changeset
   353
      end;
33784
7e434813752f change naming convention for deflation combinators
huffman
parents: 33782
diff changeset
   354
    val (REP_thms, thy) = fold_map make_repdef (doms ~~ defl_consts) thy;
33791
fef59343b4b3 use theory data for REP_simps and isodefl_rules
huffman
parents: 33790
diff changeset
   355
    val thy = RepData.map (fold Thm.add_thm REP_thms) thy;
33776
5048b02c2bbb automate proofs of REP equations
huffman
parents: 33775
diff changeset
   356
5048b02c2bbb automate proofs of REP equations
huffman
parents: 33775
diff changeset
   357
    (* prove REP equations *)
33782
cdb3ca1a765d prove isomorphism and isodefl rules
huffman
parents: 33778
diff changeset
   358
    fun mk_REP_eq_thm (lhsT, rhsT) =
33776
5048b02c2bbb automate proofs of REP equations
huffman
parents: 33775
diff changeset
   359
      let
5048b02c2bbb automate proofs of REP equations
huffman
parents: 33775
diff changeset
   360
        val goal = mk_eqs (mk_Rep_of lhsT, mk_Rep_of rhsT);
33791
fef59343b4b3 use theory data for REP_simps and isodefl_rules
huffman
parents: 33790
diff changeset
   361
        val REP_simps = RepData.get thy;
33776
5048b02c2bbb automate proofs of REP equations
huffman
parents: 33775
diff changeset
   362
        val tac =
5048b02c2bbb automate proofs of REP equations
huffman
parents: 33775
diff changeset
   363
          simp_tac (HOL_basic_ss addsimps REP_simps) 1
33784
7e434813752f change naming convention for deflation combinators
huffman
parents: 33782
diff changeset
   364
          THEN resolve_tac defl_unfold_thms 1;
33776
5048b02c2bbb automate proofs of REP equations
huffman
parents: 33775
diff changeset
   365
      in
33777
69eae9bca167 get rid of numbers on thy variables
huffman
parents: 33776
diff changeset
   366
        Goal.prove_global thy [] [] goal (K tac)
33776
5048b02c2bbb automate proofs of REP equations
huffman
parents: 33775
diff changeset
   367
      end;
33782
cdb3ca1a765d prove isomorphism and isodefl rules
huffman
parents: 33778
diff changeset
   368
    val REP_eq_thms = map mk_REP_eq_thm dom_eqns;
cdb3ca1a765d prove isomorphism and isodefl rules
huffman
parents: 33778
diff changeset
   369
cdb3ca1a765d prove isomorphism and isodefl rules
huffman
parents: 33778
diff changeset
   370
    (* register REP equations *)
cdb3ca1a765d prove isomorphism and isodefl rules
huffman
parents: 33778
diff changeset
   371
    val REP_eq_binds = map (Binding.prefix_name "REP_eq_") dom_binds;
cdb3ca1a765d prove isomorphism and isodefl rules
huffman
parents: 33778
diff changeset
   372
    val (_, thy) = thy |>
cdb3ca1a765d prove isomorphism and isodefl rules
huffman
parents: 33778
diff changeset
   373
      (PureThy.add_thms o map Thm.no_attributes)
cdb3ca1a765d prove isomorphism and isodefl rules
huffman
parents: 33778
diff changeset
   374
        (REP_eq_binds ~~ REP_eq_thms);
33776
5048b02c2bbb automate proofs of REP equations
huffman
parents: 33775
diff changeset
   375
33778
9121ea165a40 automate definition of rep/abs functions
huffman
parents: 33777
diff changeset
   376
    (* define rep/abs functions *)
34149
a0efb4754cb7 add 'morphisms' option to domain_isomorphism command
huffman
parents: 33971
diff changeset
   377
    fun mk_rep_abs ((tbind, morphs), (lhsT, rhsT)) thy =
33778
9121ea165a40 automate definition of rep/abs functions
huffman
parents: 33777
diff changeset
   378
      let
9121ea165a40 automate definition of rep/abs functions
huffman
parents: 33777
diff changeset
   379
        val rep_bind = Binding.suffix_name "_rep" tbind;
9121ea165a40 automate definition of rep/abs functions
huffman
parents: 33777
diff changeset
   380
        val abs_bind = Binding.suffix_name "_abs" tbind;
35477
b972233773dd add function define_const
huffman
parents: 35475
diff changeset
   381
        val ((rep_const, rep_def), thy) =
b972233773dd add function define_const
huffman
parents: 35475
diff changeset
   382
            define_const (rep_bind, coerce_const (lhsT ->> rhsT)) thy;
b972233773dd add function define_const
huffman
parents: 35475
diff changeset
   383
        val ((abs_const, abs_def), thy) =
b972233773dd add function define_const
huffman
parents: 35475
diff changeset
   384
            define_const (abs_bind, coerce_const (rhsT ->> lhsT)) thy;
33778
9121ea165a40 automate definition of rep/abs functions
huffman
parents: 33777
diff changeset
   385
      in
33785
2f2d9eb37084 automate definition of map functions; remove unused code
huffman
parents: 33784
diff changeset
   386
        (((rep_const, abs_const), (rep_def, abs_def)), thy)
33778
9121ea165a40 automate definition of rep/abs functions
huffman
parents: 33777
diff changeset
   387
      end;
33785
2f2d9eb37084 automate definition of map functions; remove unused code
huffman
parents: 33784
diff changeset
   388
    val ((rep_abs_consts, rep_abs_defs), thy) = thy
34149
a0efb4754cb7 add 'morphisms' option to domain_isomorphism command
huffman
parents: 33971
diff changeset
   389
      |> fold_map mk_rep_abs (dom_binds ~~ morphs ~~ dom_eqns)
33785
2f2d9eb37084 automate definition of map functions; remove unused code
huffman
parents: 33784
diff changeset
   390
      |>> ListPair.unzip;
33782
cdb3ca1a765d prove isomorphism and isodefl rules
huffman
parents: 33778
diff changeset
   391
cdb3ca1a765d prove isomorphism and isodefl rules
huffman
parents: 33778
diff changeset
   392
    (* prove isomorphism and isodefl rules *)
cdb3ca1a765d prove isomorphism and isodefl rules
huffman
parents: 33778
diff changeset
   393
    fun mk_iso_thms ((tbind, REP_eq), (rep_def, abs_def)) thy =
cdb3ca1a765d prove isomorphism and isodefl rules
huffman
parents: 33778
diff changeset
   394
      let
35021
c839a4c670c6 renamed old-style Drule.standard to Drule.export_without_context, to emphasize that this is in no way a standard operation;
wenzelm
parents: 34149
diff changeset
   395
        fun make thm = Drule.export_without_context (thm OF [REP_eq, abs_def, rep_def]);
33782
cdb3ca1a765d prove isomorphism and isodefl rules
huffman
parents: 33778
diff changeset
   396
        val rep_iso_thm = make @{thm domain_rep_iso};
cdb3ca1a765d prove isomorphism and isodefl rules
huffman
parents: 33778
diff changeset
   397
        val abs_iso_thm = make @{thm domain_abs_iso};
cdb3ca1a765d prove isomorphism and isodefl rules
huffman
parents: 33778
diff changeset
   398
        val isodefl_thm = make @{thm isodefl_abs_rep};
33797
d3616f61c5c4 rename generated abs_iso, rep_iso lemmas
huffman
parents: 33793
diff changeset
   399
        val rep_iso_bind = Binding.name "rep_iso";
d3616f61c5c4 rename generated abs_iso, rep_iso lemmas
huffman
parents: 33793
diff changeset
   400
        val abs_iso_bind = Binding.name "abs_iso";
d3616f61c5c4 rename generated abs_iso, rep_iso lemmas
huffman
parents: 33793
diff changeset
   401
        val isodefl_bind = Binding.name "isodefl_abs_rep";
d3616f61c5c4 rename generated abs_iso, rep_iso lemmas
huffman
parents: 33793
diff changeset
   402
        val (_, thy) = thy
d3616f61c5c4 rename generated abs_iso, rep_iso lemmas
huffman
parents: 33793
diff changeset
   403
          |> Sign.add_path (Binding.name_of tbind)
d3616f61c5c4 rename generated abs_iso, rep_iso lemmas
huffman
parents: 33793
diff changeset
   404
          |> (PureThy.add_thms o map Thm.no_attributes)
d3616f61c5c4 rename generated abs_iso, rep_iso lemmas
huffman
parents: 33793
diff changeset
   405
              [(rep_iso_bind, rep_iso_thm),
d3616f61c5c4 rename generated abs_iso, rep_iso lemmas
huffman
parents: 33793
diff changeset
   406
               (abs_iso_bind, abs_iso_thm),
d3616f61c5c4 rename generated abs_iso, rep_iso lemmas
huffman
parents: 33793
diff changeset
   407
               (isodefl_bind, isodefl_thm)]
d3616f61c5c4 rename generated abs_iso, rep_iso lemmas
huffman
parents: 33793
diff changeset
   408
          ||> Sign.parent_path;
33782
cdb3ca1a765d prove isomorphism and isodefl rules
huffman
parents: 33778
diff changeset
   409
      in
cdb3ca1a765d prove isomorphism and isodefl rules
huffman
parents: 33778
diff changeset
   410
        (((rep_iso_thm, abs_iso_thm), isodefl_thm), thy)
cdb3ca1a765d prove isomorphism and isodefl rules
huffman
parents: 33778
diff changeset
   411
      end;
cdb3ca1a765d prove isomorphism and isodefl rules
huffman
parents: 33778
diff changeset
   412
    val ((iso_thms, isodefl_abs_rep_thms), thy) = thy
cdb3ca1a765d prove isomorphism and isodefl rules
huffman
parents: 33778
diff changeset
   413
      |> fold_map mk_iso_thms (dom_binds ~~ REP_eq_thms ~~ rep_abs_defs)
cdb3ca1a765d prove isomorphism and isodefl rules
huffman
parents: 33778
diff changeset
   414
      |>> ListPair.unzip;
33778
9121ea165a40 automate definition of rep/abs functions
huffman
parents: 33777
diff changeset
   415
35467
561d8e98d9d3 domain_isomorphism function returns iso_info record
huffman
parents: 35021
diff changeset
   416
    (* collect info about rep/abs *)
561d8e98d9d3 domain_isomorphism function returns iso_info record
huffman
parents: 35021
diff changeset
   417
    val iso_info : iso_info list =
561d8e98d9d3 domain_isomorphism function returns iso_info record
huffman
parents: 35021
diff changeset
   418
      let
561d8e98d9d3 domain_isomorphism function returns iso_info record
huffman
parents: 35021
diff changeset
   419
        fun mk_info (((lhsT, rhsT), (repC, absC)), (rep_iso, abs_iso)) =
561d8e98d9d3 domain_isomorphism function returns iso_info record
huffman
parents: 35021
diff changeset
   420
          {
561d8e98d9d3 domain_isomorphism function returns iso_info record
huffman
parents: 35021
diff changeset
   421
            repT = rhsT,
561d8e98d9d3 domain_isomorphism function returns iso_info record
huffman
parents: 35021
diff changeset
   422
            absT = lhsT,
561d8e98d9d3 domain_isomorphism function returns iso_info record
huffman
parents: 35021
diff changeset
   423
            rep_const = repC,
561d8e98d9d3 domain_isomorphism function returns iso_info record
huffman
parents: 35021
diff changeset
   424
            abs_const = absC,
561d8e98d9d3 domain_isomorphism function returns iso_info record
huffman
parents: 35021
diff changeset
   425
            rep_inverse = rep_iso,
561d8e98d9d3 domain_isomorphism function returns iso_info record
huffman
parents: 35021
diff changeset
   426
            abs_inverse = abs_iso
561d8e98d9d3 domain_isomorphism function returns iso_info record
huffman
parents: 35021
diff changeset
   427
          };
561d8e98d9d3 domain_isomorphism function returns iso_info record
huffman
parents: 35021
diff changeset
   428
      in
561d8e98d9d3 domain_isomorphism function returns iso_info record
huffman
parents: 35021
diff changeset
   429
        map mk_info (dom_eqns ~~ rep_abs_consts ~~ iso_thms)
561d8e98d9d3 domain_isomorphism function returns iso_info record
huffman
parents: 35021
diff changeset
   430
      end
561d8e98d9d3 domain_isomorphism function returns iso_info record
huffman
parents: 35021
diff changeset
   431
33785
2f2d9eb37084 automate definition of map functions; remove unused code
huffman
parents: 33784
diff changeset
   432
    (* declare map functions *)
2f2d9eb37084 automate definition of map functions; remove unused code
huffman
parents: 33784
diff changeset
   433
    fun declare_map_const (tbind, (lhsT, rhsT)) thy =
2f2d9eb37084 automate definition of map functions; remove unused code
huffman
parents: 33784
diff changeset
   434
      let
2f2d9eb37084 automate definition of map functions; remove unused code
huffman
parents: 33784
diff changeset
   435
        val map_type = mapT lhsT;
2f2d9eb37084 automate definition of map functions; remove unused code
huffman
parents: 33784
diff changeset
   436
        val map_bind = Binding.suffix_name "_map" tbind;
2f2d9eb37084 automate definition of map functions; remove unused code
huffman
parents: 33784
diff changeset
   437
      in
2f2d9eb37084 automate definition of map functions; remove unused code
huffman
parents: 33784
diff changeset
   438
        Sign.declare_const ((map_bind, map_type), NoSyn) thy
2f2d9eb37084 automate definition of map functions; remove unused code
huffman
parents: 33784
diff changeset
   439
      end;
2f2d9eb37084 automate definition of map functions; remove unused code
huffman
parents: 33784
diff changeset
   440
    val (map_consts, thy) = thy |>
2f2d9eb37084 automate definition of map functions; remove unused code
huffman
parents: 33784
diff changeset
   441
      fold_map declare_map_const (dom_binds ~~ dom_eqns);
2f2d9eb37084 automate definition of map functions; remove unused code
huffman
parents: 33784
diff changeset
   442
2f2d9eb37084 automate definition of map functions; remove unused code
huffman
parents: 33784
diff changeset
   443
    (* defining equations for map functions *)
33790
b2ff505e30f8 replace defl_tab and map_tab with theory data
huffman
parents: 33789
diff changeset
   444
    val map_tab1 = MapData.get thy;
33785
2f2d9eb37084 automate definition of map functions; remove unused code
huffman
parents: 33784
diff changeset
   445
    val map_tab2 =
2f2d9eb37084 automate definition of map functions; remove unused code
huffman
parents: 33784
diff changeset
   446
      Symtab.make (map (fst o dest_Type o fst) dom_eqns
2f2d9eb37084 automate definition of map functions; remove unused code
huffman
parents: 33784
diff changeset
   447
                   ~~ map (fst o dest_Const) map_consts);
2f2d9eb37084 automate definition of map functions; remove unused code
huffman
parents: 33784
diff changeset
   448
    val map_tab' = Symtab.merge (K true) (map_tab1, map_tab2);
33790
b2ff505e30f8 replace defl_tab and map_tab with theory data
huffman
parents: 33789
diff changeset
   449
    val thy = MapData.put map_tab' thy;
33785
2f2d9eb37084 automate definition of map functions; remove unused code
huffman
parents: 33784
diff changeset
   450
    fun mk_map_spec ((rep_const, abs_const), (lhsT, rhsT)) =
2f2d9eb37084 automate definition of map functions; remove unused code
huffman
parents: 33784
diff changeset
   451
      let
2f2d9eb37084 automate definition of map functions; remove unused code
huffman
parents: 33784
diff changeset
   452
        val lhs = map_of_typ map_tab' lhsT;
2f2d9eb37084 automate definition of map functions; remove unused code
huffman
parents: 33784
diff changeset
   453
        val body = map_of_typ map_tab' rhsT;
2f2d9eb37084 automate definition of map functions; remove unused code
huffman
parents: 33784
diff changeset
   454
        val rhs = mk_cfcomp (abs_const, mk_cfcomp (body, rep_const));
2f2d9eb37084 automate definition of map functions; remove unused code
huffman
parents: 33784
diff changeset
   455
      in mk_eqs (lhs, rhs) end;
2f2d9eb37084 automate definition of map functions; remove unused code
huffman
parents: 33784
diff changeset
   456
    val map_specs = map mk_map_spec (rep_abs_consts ~~ dom_eqns);
2f2d9eb37084 automate definition of map functions; remove unused code
huffman
parents: 33784
diff changeset
   457
2f2d9eb37084 automate definition of map functions; remove unused code
huffman
parents: 33784
diff changeset
   458
    (* register recursive definition of map functions *)
2f2d9eb37084 automate definition of map functions; remove unused code
huffman
parents: 33784
diff changeset
   459
    val map_binds = map (Binding.suffix_name "_map") dom_binds;
33788
481bc899febf automate isodefl proof
huffman
parents: 33785
diff changeset
   460
    val ((map_apply_thms, map_unfold_thms), thy) =
481bc899febf automate isodefl proof
huffman
parents: 33785
diff changeset
   461
      add_fixdefs (map_binds ~~ map_specs) thy;
481bc899febf automate isodefl proof
huffman
parents: 33785
diff changeset
   462
481bc899febf automate isodefl proof
huffman
parents: 33785
diff changeset
   463
    (* prove isodefl rules for map functions *)
481bc899febf automate isodefl proof
huffman
parents: 33785
diff changeset
   464
    val isodefl_thm =
481bc899febf automate isodefl proof
huffman
parents: 33785
diff changeset
   465
      let
481bc899febf automate isodefl proof
huffman
parents: 33785
diff changeset
   466
        fun unprime a = Library.unprefix "'" a;
35474
7675a41e755a get rid of incomplete pattern match warnings
huffman
parents: 35467
diff changeset
   467
        fun mk_d T = Free ("d" ^ unprime (fst (dest_TFree T)), deflT);
7675a41e755a get rid of incomplete pattern match warnings
huffman
parents: 35467
diff changeset
   468
        fun mk_f T = Free ("f" ^ unprime (fst (dest_TFree T)), T ->> T);
33788
481bc899febf automate isodefl proof
huffman
parents: 33785
diff changeset
   469
        fun mk_assm T = mk_trp (isodefl_const T $ mk_f T $ mk_d T);
35474
7675a41e755a get rid of incomplete pattern match warnings
huffman
parents: 35467
diff changeset
   470
        fun mk_goal ((map_const, defl_const), (T, rhsT)) =
33788
481bc899febf automate isodefl proof
huffman
parents: 33785
diff changeset
   471
          let
35474
7675a41e755a get rid of incomplete pattern match warnings
huffman
parents: 35467
diff changeset
   472
            val (_, Ts) = dest_Type T;
35478
90dd1d63ae54 use function list_ccomb
huffman
parents: 35477
diff changeset
   473
            val map_term = list_ccomb (map_const, map mk_f Ts);
90dd1d63ae54 use function list_ccomb
huffman
parents: 35477
diff changeset
   474
            val defl_term = list_ccomb (defl_const, map mk_d Ts);
33788
481bc899febf automate isodefl proof
huffman
parents: 33785
diff changeset
   475
          in isodefl_const T $ map_term $ defl_term end;
481bc899febf automate isodefl proof
huffman
parents: 33785
diff changeset
   476
        val assms = (map mk_assm o snd o dest_Type o fst o hd) dom_eqns;
481bc899febf automate isodefl proof
huffman
parents: 33785
diff changeset
   477
        val goals = map mk_goal (map_consts ~~ defl_consts ~~ dom_eqns);
481bc899febf automate isodefl proof
huffman
parents: 33785
diff changeset
   478
        val goal = mk_trp (foldr1 HOLogic.mk_conj goals);
481bc899febf automate isodefl proof
huffman
parents: 33785
diff changeset
   479
        val start_thms =
481bc899febf automate isodefl proof
huffman
parents: 33785
diff changeset
   480
          @{thm split_def} :: defl_apply_thms @ map_apply_thms;
481bc899febf automate isodefl proof
huffman
parents: 33785
diff changeset
   481
        val adm_rules =
481bc899febf automate isodefl proof
huffman
parents: 33785
diff changeset
   482
          @{thms adm_conj adm_isodefl cont2cont_fst cont2cont_snd cont_id};
481bc899febf automate isodefl proof
huffman
parents: 33785
diff changeset
   483
        val bottom_rules =
481bc899febf automate isodefl proof
huffman
parents: 33785
diff changeset
   484
          @{thms fst_strict snd_strict isodefl_bottom simp_thms};
481bc899febf automate isodefl proof
huffman
parents: 33785
diff changeset
   485
        val isodefl_rules =
33791
fef59343b4b3 use theory data for REP_simps and isodefl_rules
huffman
parents: 33790
diff changeset
   486
          @{thms conjI isodefl_ID_REP}
fef59343b4b3 use theory data for REP_simps and isodefl_rules
huffman
parents: 33790
diff changeset
   487
          @ isodefl_abs_rep_thms
fef59343b4b3 use theory data for REP_simps and isodefl_rules
huffman
parents: 33790
diff changeset
   488
          @ IsodeflData.get thy;
33845
91f3fc0364cf made SML/NJ happy;
wenzelm
parents: 33809
diff changeset
   489
      in
91f3fc0364cf made SML/NJ happy;
wenzelm
parents: 33809
diff changeset
   490
        Goal.prove_global thy [] assms goal (fn {prems, ...} =>
91f3fc0364cf made SML/NJ happy;
wenzelm
parents: 33809
diff changeset
   491
         EVERY
33788
481bc899febf automate isodefl proof
huffman
parents: 33785
diff changeset
   492
          [simp_tac (HOL_basic_ss addsimps start_thms) 1,
33791
fef59343b4b3 use theory data for REP_simps and isodefl_rules
huffman
parents: 33790
diff changeset
   493
           (* FIXME: how reliable is unification here? *)
fef59343b4b3 use theory data for REP_simps and isodefl_rules
huffman
parents: 33790
diff changeset
   494
           (* Maybe I should instantiate the rule. *)
33788
481bc899febf automate isodefl proof
huffman
parents: 33785
diff changeset
   495
           rtac @{thm parallel_fix_ind} 1,
481bc899febf automate isodefl proof
huffman
parents: 33785
diff changeset
   496
           REPEAT (resolve_tac adm_rules 1),
481bc899febf automate isodefl proof
huffman
parents: 33785
diff changeset
   497
           simp_tac (HOL_basic_ss addsimps bottom_rules) 1,
481bc899febf automate isodefl proof
huffman
parents: 33785
diff changeset
   498
           simp_tac beta_ss 1,
481bc899febf automate isodefl proof
huffman
parents: 33785
diff changeset
   499
           simp_tac (HOL_basic_ss addsimps @{thms fst_conv snd_conv}) 1,
481bc899febf automate isodefl proof
huffman
parents: 33785
diff changeset
   500
           REPEAT (etac @{thm conjE} 1),
33845
91f3fc0364cf made SML/NJ happy;
wenzelm
parents: 33809
diff changeset
   501
           REPEAT (resolve_tac (isodefl_rules @ prems) 1 ORELSE atac 1)])
33788
481bc899febf automate isodefl proof
huffman
parents: 33785
diff changeset
   502
      end;
33789
c3fbdff7aed0 separate conjuncts of isodefl theorem
huffman
parents: 33788
diff changeset
   503
    val isodefl_binds = map (Binding.prefix_name "isodefl_") dom_binds;
c3fbdff7aed0 separate conjuncts of isodefl theorem
huffman
parents: 33788
diff changeset
   504
    fun conjuncts [] thm = []
c3fbdff7aed0 separate conjuncts of isodefl theorem
huffman
parents: 33788
diff changeset
   505
      | conjuncts (n::[]) thm = [(n, thm)]
c3fbdff7aed0 separate conjuncts of isodefl theorem
huffman
parents: 33788
diff changeset
   506
      | conjuncts (n::ns) thm = let
c3fbdff7aed0 separate conjuncts of isodefl theorem
huffman
parents: 33788
diff changeset
   507
          val thmL = thm RS @{thm conjunct1};
c3fbdff7aed0 separate conjuncts of isodefl theorem
huffman
parents: 33788
diff changeset
   508
          val thmR = thm RS @{thm conjunct2};
c3fbdff7aed0 separate conjuncts of isodefl theorem
huffman
parents: 33788
diff changeset
   509
        in (n, thmL):: conjuncts ns thmR end;
c3fbdff7aed0 separate conjuncts of isodefl theorem
huffman
parents: 33788
diff changeset
   510
    val (isodefl_thms, thy) = thy |>
35021
c839a4c670c6 renamed old-style Drule.standard to Drule.export_without_context, to emphasize that this is in no way a standard operation;
wenzelm
parents: 34149
diff changeset
   511
      (PureThy.add_thms o map (Thm.no_attributes o apsnd Drule.export_without_context))
33789
c3fbdff7aed0 separate conjuncts of isodefl theorem
huffman
parents: 33788
diff changeset
   512
        (conjuncts isodefl_binds isodefl_thm);
33791
fef59343b4b3 use theory data for REP_simps and isodefl_rules
huffman
parents: 33790
diff changeset
   513
    val thy = IsodeflData.map (fold Thm.add_thm isodefl_thms) thy;
33793
5beafabffa07 automate proofs of map_ID theorems
huffman
parents: 33792
diff changeset
   514
5beafabffa07 automate proofs of map_ID theorems
huffman
parents: 33792
diff changeset
   515
    (* prove map_ID theorems *)
5beafabffa07 automate proofs of map_ID theorems
huffman
parents: 33792
diff changeset
   516
    fun prove_map_ID_thm
5beafabffa07 automate proofs of map_ID theorems
huffman
parents: 33792
diff changeset
   517
        (((map_const, (lhsT, _)), REP_thm), isodefl_thm) =
5beafabffa07 automate proofs of map_ID theorems
huffman
parents: 33792
diff changeset
   518
      let
5beafabffa07 automate proofs of map_ID theorems
huffman
parents: 33792
diff changeset
   519
        val Ts = snd (dest_Type lhsT);
35478
90dd1d63ae54 use function list_ccomb
huffman
parents: 35477
diff changeset
   520
        val lhs = list_ccomb (map_const, map mk_ID Ts);
35475
979019ab92eb move common functions into new file holcf_library.ML
huffman
parents: 35474
diff changeset
   521
        val goal = mk_eqs (lhs, mk_ID lhsT);
33793
5beafabffa07 automate proofs of map_ID theorems
huffman
parents: 33792
diff changeset
   522
        val tac = EVERY
5beafabffa07 automate proofs of map_ID theorems
huffman
parents: 33792
diff changeset
   523
          [rtac @{thm isodefl_REP_imp_ID} 1,
5beafabffa07 automate proofs of map_ID theorems
huffman
parents: 33792
diff changeset
   524
           stac REP_thm 1,
5beafabffa07 automate proofs of map_ID theorems
huffman
parents: 33792
diff changeset
   525
           rtac isodefl_thm 1,
5beafabffa07 automate proofs of map_ID theorems
huffman
parents: 33792
diff changeset
   526
           REPEAT (rtac @{thm isodefl_ID_REP} 1)];
5beafabffa07 automate proofs of map_ID theorems
huffman
parents: 33792
diff changeset
   527
      in
5beafabffa07 automate proofs of map_ID theorems
huffman
parents: 33792
diff changeset
   528
        Goal.prove_global thy [] [] goal (K tac)
5beafabffa07 automate proofs of map_ID theorems
huffman
parents: 33792
diff changeset
   529
      end;
5beafabffa07 automate proofs of map_ID theorems
huffman
parents: 33792
diff changeset
   530
    val map_ID_binds = map (Binding.suffix_name "_map_ID") dom_binds;
5beafabffa07 automate proofs of map_ID theorems
huffman
parents: 33792
diff changeset
   531
    val map_ID_thms =
5beafabffa07 automate proofs of map_ID theorems
huffman
parents: 33792
diff changeset
   532
      map prove_map_ID_thm
5beafabffa07 automate proofs of map_ID theorems
huffman
parents: 33792
diff changeset
   533
        (map_consts ~~ dom_eqns ~~ REP_thms ~~ isodefl_thms);
5beafabffa07 automate proofs of map_ID theorems
huffman
parents: 33792
diff changeset
   534
    val (_, thy) = thy |>
5beafabffa07 automate proofs of map_ID theorems
huffman
parents: 33792
diff changeset
   535
      (PureThy.add_thms o map Thm.no_attributes)
5beafabffa07 automate proofs of map_ID theorems
huffman
parents: 33792
diff changeset
   536
        (map_ID_binds ~~ map_ID_thms);
33809
033831fd9ef3 store map_ID thms in theory data; automate proofs of reach lemmas
huffman
parents: 33807
diff changeset
   537
    val thy = MapIdData.map (fold Thm.add_thm map_ID_thms) thy;
33802
48ce3a1063f2 domain_isomorphism package defines copy functions
huffman
parents: 33801
diff changeset
   538
48ce3a1063f2 domain_isomorphism package defines copy functions
huffman
parents: 33801
diff changeset
   539
    (* define copy combinators *)
48ce3a1063f2 domain_isomorphism package defines copy functions
huffman
parents: 33801
diff changeset
   540
    val new_dts =
48ce3a1063f2 domain_isomorphism package defines copy functions
huffman
parents: 33801
diff changeset
   541
      map (apsnd (map (fst o dest_TFree)) o dest_Type o fst) dom_eqns;
35475
979019ab92eb move common functions into new file holcf_library.ML
huffman
parents: 35474
diff changeset
   542
    val copy_arg_type = mk_tupleT (map (fn (T, _) => T ->> T) dom_eqns);
33807
ce8d2e8bca21 domain_isomorphism package defines combined copy function
huffman
parents: 33802
diff changeset
   543
    val copy_arg = Free ("f", copy_arg_type);
33802
48ce3a1063f2 domain_isomorphism package defines copy functions
huffman
parents: 33801
diff changeset
   544
    val copy_args =
48ce3a1063f2 domain_isomorphism package defines copy functions
huffman
parents: 33801
diff changeset
   545
      let fun mk_copy_args [] t = []
48ce3a1063f2 domain_isomorphism package defines copy functions
huffman
parents: 33801
diff changeset
   546
            | mk_copy_args (_::[]) t = [t]
48ce3a1063f2 domain_isomorphism package defines copy functions
huffman
parents: 33801
diff changeset
   547
            | mk_copy_args (_::xs) t =
33809
033831fd9ef3 store map_ID thms in theory data; automate proofs of reach lemmas
huffman
parents: 33807
diff changeset
   548
                mk_fst t :: mk_copy_args xs (mk_snd t);
33807
ce8d2e8bca21 domain_isomorphism package defines combined copy function
huffman
parents: 33802
diff changeset
   549
      in mk_copy_args doms copy_arg end;
33802
48ce3a1063f2 domain_isomorphism package defines copy functions
huffman
parents: 33801
diff changeset
   550
    fun copy_of_dtyp (T, dt) =
33971
9c7fa7f76950 modernized structure Datatype_Aux
haftmann
parents: 33845
diff changeset
   551
        if Datatype_Aux.is_rec_type dt
33802
48ce3a1063f2 domain_isomorphism package defines copy functions
huffman
parents: 33801
diff changeset
   552
        then copy_of_dtyp' (T, dt)
35475
979019ab92eb move common functions into new file holcf_library.ML
huffman
parents: 35474
diff changeset
   553
        else mk_ID T
33971
9c7fa7f76950 modernized structure Datatype_Aux
haftmann
parents: 33845
diff changeset
   554
    and copy_of_dtyp' (T, Datatype_Aux.DtRec i) = nth copy_args i
35475
979019ab92eb move common functions into new file holcf_library.ML
huffman
parents: 35474
diff changeset
   555
      | copy_of_dtyp' (T, Datatype_Aux.DtTFree a) = mk_ID T
35474
7675a41e755a get rid of incomplete pattern match warnings
huffman
parents: 35467
diff changeset
   556
      | copy_of_dtyp' (T, Datatype_Aux.DtType (c, ds)) =
33802
48ce3a1063f2 domain_isomorphism package defines copy functions
huffman
parents: 33801
diff changeset
   557
        case Symtab.lookup map_tab' c of
48ce3a1063f2 domain_isomorphism package defines copy functions
huffman
parents: 33801
diff changeset
   558
          SOME f =>
35478
90dd1d63ae54 use function list_ccomb
huffman
parents: 35477
diff changeset
   559
          list_ccomb
35474
7675a41e755a get rid of incomplete pattern match warnings
huffman
parents: 35467
diff changeset
   560
            (Const (f, mapT T), map copy_of_dtyp (snd (dest_Type T) ~~ ds))
33802
48ce3a1063f2 domain_isomorphism package defines copy functions
huffman
parents: 33801
diff changeset
   561
        | NONE =>
35475
979019ab92eb move common functions into new file holcf_library.ML
huffman
parents: 35474
diff changeset
   562
          (warning ("copy_of_dtyp: unknown type constructor " ^ c); mk_ID T);
33802
48ce3a1063f2 domain_isomorphism package defines copy functions
huffman
parents: 33801
diff changeset
   563
    fun define_copy ((tbind, (rep_const, abs_const)), (lhsT, rhsT)) thy =
48ce3a1063f2 domain_isomorphism package defines copy functions
huffman
parents: 33801
diff changeset
   564
      let
48ce3a1063f2 domain_isomorphism package defines copy functions
huffman
parents: 33801
diff changeset
   565
        val copy_type = copy_arg_type ->> (lhsT ->> lhsT);
48ce3a1063f2 domain_isomorphism package defines copy functions
huffman
parents: 33801
diff changeset
   566
        val copy_bind = Binding.suffix_name "_copy" tbind;
48ce3a1063f2 domain_isomorphism package defines copy functions
huffman
parents: 33801
diff changeset
   567
        val (copy_const, thy) = thy |>
48ce3a1063f2 domain_isomorphism package defines copy functions
huffman
parents: 33801
diff changeset
   568
          Sign.declare_const ((copy_bind, copy_type), NoSyn);
33971
9c7fa7f76950 modernized structure Datatype_Aux
haftmann
parents: 33845
diff changeset
   569
        val dtyp = Datatype_Aux.dtyp_of_typ new_dts rhsT;
33802
48ce3a1063f2 domain_isomorphism package defines copy functions
huffman
parents: 33801
diff changeset
   570
        val body = copy_of_dtyp (rhsT, dtyp);
48ce3a1063f2 domain_isomorphism package defines copy functions
huffman
parents: 33801
diff changeset
   571
        val comp = mk_cfcomp (abs_const, mk_cfcomp (body, rep_const));
33807
ce8d2e8bca21 domain_isomorphism package defines combined copy function
huffman
parents: 33802
diff changeset
   572
        val rhs = big_lambda copy_arg comp;
33802
48ce3a1063f2 domain_isomorphism package defines copy functions
huffman
parents: 33801
diff changeset
   573
        val eqn = Logic.mk_equals (copy_const, rhs);
35474
7675a41e755a get rid of incomplete pattern match warnings
huffman
parents: 35467
diff changeset
   574
        val (copy_def, thy) =
33802
48ce3a1063f2 domain_isomorphism package defines copy functions
huffman
parents: 33801
diff changeset
   575
          thy
48ce3a1063f2 domain_isomorphism package defines copy functions
huffman
parents: 33801
diff changeset
   576
          |> Sign.add_path (Binding.name_of tbind)
35474
7675a41e755a get rid of incomplete pattern match warnings
huffman
parents: 35467
diff changeset
   577
          |> yield_singleton (PureThy.add_defs false o map Thm.no_attributes)
7675a41e755a get rid of incomplete pattern match warnings
huffman
parents: 35467
diff changeset
   578
              (Binding.name "copy_def", eqn)
33802
48ce3a1063f2 domain_isomorphism package defines copy functions
huffman
parents: 33801
diff changeset
   579
          ||> Sign.parent_path;
48ce3a1063f2 domain_isomorphism package defines copy functions
huffman
parents: 33801
diff changeset
   580
      in ((copy_const, copy_def), thy) end;
48ce3a1063f2 domain_isomorphism package defines copy functions
huffman
parents: 33801
diff changeset
   581
    val ((copy_consts, copy_defs), thy) = thy
48ce3a1063f2 domain_isomorphism package defines copy functions
huffman
parents: 33801
diff changeset
   582
      |> fold_map define_copy (dom_binds ~~ rep_abs_consts ~~ dom_eqns)
48ce3a1063f2 domain_isomorphism package defines copy functions
huffman
parents: 33801
diff changeset
   583
      |>> ListPair.unzip;
48ce3a1063f2 domain_isomorphism package defines copy functions
huffman
parents: 33801
diff changeset
   584
33807
ce8d2e8bca21 domain_isomorphism package defines combined copy function
huffman
parents: 33802
diff changeset
   585
    (* define combined copy combinator *)
ce8d2e8bca21 domain_isomorphism package defines combined copy function
huffman
parents: 33802
diff changeset
   586
    val ((c_const, c_def_thms), thy) =
ce8d2e8bca21 domain_isomorphism package defines combined copy function
huffman
parents: 33802
diff changeset
   587
      if length doms = 1
ce8d2e8bca21 domain_isomorphism package defines combined copy function
huffman
parents: 33802
diff changeset
   588
      then ((hd copy_consts, []), thy)
ce8d2e8bca21 domain_isomorphism package defines combined copy function
huffman
parents: 33802
diff changeset
   589
      else
ce8d2e8bca21 domain_isomorphism package defines combined copy function
huffman
parents: 33802
diff changeset
   590
        let
ce8d2e8bca21 domain_isomorphism package defines combined copy function
huffman
parents: 33802
diff changeset
   591
          val c_type = copy_arg_type ->> copy_arg_type;
ce8d2e8bca21 domain_isomorphism package defines combined copy function
huffman
parents: 33802
diff changeset
   592
          val c_name = space_implode "_" (map Binding.name_of dom_binds);
ce8d2e8bca21 domain_isomorphism package defines combined copy function
huffman
parents: 33802
diff changeset
   593
          val c_bind = Binding.name (c_name ^ "_copy");
ce8d2e8bca21 domain_isomorphism package defines combined copy function
huffman
parents: 33802
diff changeset
   594
          val c_body =
ce8d2e8bca21 domain_isomorphism package defines combined copy function
huffman
parents: 33802
diff changeset
   595
              mk_tuple (map (mk_capply o rpair copy_arg) copy_consts);
ce8d2e8bca21 domain_isomorphism package defines combined copy function
huffman
parents: 33802
diff changeset
   596
          val c_rhs = big_lambda copy_arg c_body;
ce8d2e8bca21 domain_isomorphism package defines combined copy function
huffman
parents: 33802
diff changeset
   597
          val (c_const, thy) =
ce8d2e8bca21 domain_isomorphism package defines combined copy function
huffman
parents: 33802
diff changeset
   598
            Sign.declare_const ((c_bind, c_type), NoSyn) thy;
ce8d2e8bca21 domain_isomorphism package defines combined copy function
huffman
parents: 33802
diff changeset
   599
          val c_eqn = Logic.mk_equals (c_const, c_rhs);
ce8d2e8bca21 domain_isomorphism package defines combined copy function
huffman
parents: 33802
diff changeset
   600
          val (c_def_thms, thy) =
ce8d2e8bca21 domain_isomorphism package defines combined copy function
huffman
parents: 33802
diff changeset
   601
            thy
ce8d2e8bca21 domain_isomorphism package defines combined copy function
huffman
parents: 33802
diff changeset
   602
            |> Sign.add_path c_name
ce8d2e8bca21 domain_isomorphism package defines combined copy function
huffman
parents: 33802
diff changeset
   603
            |> (PureThy.add_defs false o map Thm.no_attributes)
ce8d2e8bca21 domain_isomorphism package defines combined copy function
huffman
parents: 33802
diff changeset
   604
                [(Binding.name "copy_def", c_eqn)]
ce8d2e8bca21 domain_isomorphism package defines combined copy function
huffman
parents: 33802
diff changeset
   605
            ||> Sign.parent_path;
ce8d2e8bca21 domain_isomorphism package defines combined copy function
huffman
parents: 33802
diff changeset
   606
        in ((c_const, c_def_thms), thy) end;
ce8d2e8bca21 domain_isomorphism package defines combined copy function
huffman
parents: 33802
diff changeset
   607
33809
033831fd9ef3 store map_ID thms in theory data; automate proofs of reach lemmas
huffman
parents: 33807
diff changeset
   608
    (* fixed-point lemma for combined copy combinator *)
033831fd9ef3 store map_ID thms in theory data; automate proofs of reach lemmas
huffman
parents: 33807
diff changeset
   609
    val fix_copy_lemma =
033831fd9ef3 store map_ID thms in theory data; automate proofs of reach lemmas
huffman
parents: 33807
diff changeset
   610
      let
35474
7675a41e755a get rid of incomplete pattern match warnings
huffman
parents: 35467
diff changeset
   611
        fun mk_map_ID (map_const, (T, rhsT)) =
35478
90dd1d63ae54 use function list_ccomb
huffman
parents: 35477
diff changeset
   612
          list_ccomb (map_const, map mk_ID (snd (dest_Type T)));
33809
033831fd9ef3 store map_ID thms in theory data; automate proofs of reach lemmas
huffman
parents: 33807
diff changeset
   613
        val rhs = mk_tuple (map mk_map_ID (map_consts ~~ dom_eqns));
033831fd9ef3 store map_ID thms in theory data; automate proofs of reach lemmas
huffman
parents: 33807
diff changeset
   614
        val goal = mk_eqs (mk_fix c_const, rhs);
033831fd9ef3 store map_ID thms in theory data; automate proofs of reach lemmas
huffman
parents: 33807
diff changeset
   615
        val rules =
033831fd9ef3 store map_ID thms in theory data; automate proofs of reach lemmas
huffman
parents: 33807
diff changeset
   616
          [@{thm pair_collapse}, @{thm split_def}]
033831fd9ef3 store map_ID thms in theory data; automate proofs of reach lemmas
huffman
parents: 33807
diff changeset
   617
          @ map_apply_thms
033831fd9ef3 store map_ID thms in theory data; automate proofs of reach lemmas
huffman
parents: 33807
diff changeset
   618
          @ c_def_thms @ copy_defs
033831fd9ef3 store map_ID thms in theory data; automate proofs of reach lemmas
huffman
parents: 33807
diff changeset
   619
          @ MapIdData.get thy;
033831fd9ef3 store map_ID thms in theory data; automate proofs of reach lemmas
huffman
parents: 33807
diff changeset
   620
        val tac = simp_tac (beta_ss addsimps rules) 1;
033831fd9ef3 store map_ID thms in theory data; automate proofs of reach lemmas
huffman
parents: 33807
diff changeset
   621
      in
033831fd9ef3 store map_ID thms in theory data; automate proofs of reach lemmas
huffman
parents: 33807
diff changeset
   622
        Goal.prove_global thy [] [] goal (K tac)
033831fd9ef3 store map_ID thms in theory data; automate proofs of reach lemmas
huffman
parents: 33807
diff changeset
   623
      end;
033831fd9ef3 store map_ID thms in theory data; automate proofs of reach lemmas
huffman
parents: 33807
diff changeset
   624
033831fd9ef3 store map_ID thms in theory data; automate proofs of reach lemmas
huffman
parents: 33807
diff changeset
   625
    (* prove reach lemmas *)
033831fd9ef3 store map_ID thms in theory data; automate proofs of reach lemmas
huffman
parents: 33807
diff changeset
   626
    val reach_thm_projs =
35474
7675a41e755a get rid of incomplete pattern match warnings
huffman
parents: 35467
diff changeset
   627
      let fun mk_projs []      t = []
7675a41e755a get rid of incomplete pattern match warnings
huffman
parents: 35467
diff changeset
   628
            | mk_projs (x::[]) t = [(x, t)]
33809
033831fd9ef3 store map_ID thms in theory data; automate proofs of reach lemmas
huffman
parents: 33807
diff changeset
   629
            | mk_projs (x::xs) t = (x, mk_fst t) :: mk_projs xs (mk_snd t);
033831fd9ef3 store map_ID thms in theory data; automate proofs of reach lemmas
huffman
parents: 33807
diff changeset
   630
      in mk_projs dom_binds (mk_fix c_const) end;
033831fd9ef3 store map_ID thms in theory data; automate proofs of reach lemmas
huffman
parents: 33807
diff changeset
   631
    fun prove_reach_thm (((bind, t), map_ID_thm), (lhsT, rhsT)) thy =
033831fd9ef3 store map_ID thms in theory data; automate proofs of reach lemmas
huffman
parents: 33807
diff changeset
   632
      let
033831fd9ef3 store map_ID thms in theory data; automate proofs of reach lemmas
huffman
parents: 33807
diff changeset
   633
        val x = Free ("x", lhsT);
033831fd9ef3 store map_ID thms in theory data; automate proofs of reach lemmas
huffman
parents: 33807
diff changeset
   634
        val goal = mk_eqs (mk_capply (t, x), x);
033831fd9ef3 store map_ID thms in theory data; automate proofs of reach lemmas
huffman
parents: 33807
diff changeset
   635
        val rules =
033831fd9ef3 store map_ID thms in theory data; automate proofs of reach lemmas
huffman
parents: 33807
diff changeset
   636
          fix_copy_lemma :: map_ID_thm :: @{thms fst_conv snd_conv ID1};
033831fd9ef3 store map_ID thms in theory data; automate proofs of reach lemmas
huffman
parents: 33807
diff changeset
   637
        val tac = simp_tac (HOL_basic_ss addsimps rules) 1;
033831fd9ef3 store map_ID thms in theory data; automate proofs of reach lemmas
huffman
parents: 33807
diff changeset
   638
        val reach_thm = Goal.prove_global thy [] [] goal (K tac);
033831fd9ef3 store map_ID thms in theory data; automate proofs of reach lemmas
huffman
parents: 33807
diff changeset
   639
      in
033831fd9ef3 store map_ID thms in theory data; automate proofs of reach lemmas
huffman
parents: 33807
diff changeset
   640
        thy
033831fd9ef3 store map_ID thms in theory data; automate proofs of reach lemmas
huffman
parents: 33807
diff changeset
   641
        |> Sign.add_path (Binding.name_of bind)
033831fd9ef3 store map_ID thms in theory data; automate proofs of reach lemmas
huffman
parents: 33807
diff changeset
   642
        |> yield_singleton (PureThy.add_thms o map Thm.no_attributes)
033831fd9ef3 store map_ID thms in theory data; automate proofs of reach lemmas
huffman
parents: 33807
diff changeset
   643
            (Binding.name "reach", reach_thm)
033831fd9ef3 store map_ID thms in theory data; automate proofs of reach lemmas
huffman
parents: 33807
diff changeset
   644
        ||> Sign.parent_path
033831fd9ef3 store map_ID thms in theory data; automate proofs of reach lemmas
huffman
parents: 33807
diff changeset
   645
      end;
033831fd9ef3 store map_ID thms in theory data; automate proofs of reach lemmas
huffman
parents: 33807
diff changeset
   646
    val (reach_thms, thy) = thy |>
033831fd9ef3 store map_ID thms in theory data; automate proofs of reach lemmas
huffman
parents: 33807
diff changeset
   647
      fold_map prove_reach_thm (reach_thm_projs ~~ map_ID_thms ~~ dom_eqns);
033831fd9ef3 store map_ID thms in theory data; automate proofs of reach lemmas
huffman
parents: 33807
diff changeset
   648
33774
e11e05b32548 automate solution of domain equations
huffman
parents:
diff changeset
   649
  in
35467
561d8e98d9d3 domain_isomorphism function returns iso_info record
huffman
parents: 35021
diff changeset
   650
    (iso_info, thy)
33774
e11e05b32548 automate solution of domain equations
huffman
parents:
diff changeset
   651
  end;
e11e05b32548 automate solution of domain equations
huffman
parents:
diff changeset
   652
e11e05b32548 automate solution of domain equations
huffman
parents:
diff changeset
   653
val domain_isomorphism = gen_domain_isomorphism cert_typ;
35467
561d8e98d9d3 domain_isomorphism function returns iso_info record
huffman
parents: 35021
diff changeset
   654
val domain_isomorphism_cmd = snd oo gen_domain_isomorphism read_typ;
33774
e11e05b32548 automate solution of domain equations
huffman
parents:
diff changeset
   655
e11e05b32548 automate solution of domain equations
huffman
parents:
diff changeset
   656
(******************************************************************************)
e11e05b32548 automate solution of domain equations
huffman
parents:
diff changeset
   657
(******************************** outer syntax ********************************)
e11e05b32548 automate solution of domain equations
huffman
parents:
diff changeset
   658
(******************************************************************************)
e11e05b32548 automate solution of domain equations
huffman
parents:
diff changeset
   659
e11e05b32548 automate solution of domain equations
huffman
parents:
diff changeset
   660
local
e11e05b32548 automate solution of domain equations
huffman
parents:
diff changeset
   661
e11e05b32548 automate solution of domain equations
huffman
parents:
diff changeset
   662
structure P = OuterParse and K = OuterKeyword
e11e05b32548 automate solution of domain equations
huffman
parents:
diff changeset
   663
34149
a0efb4754cb7 add 'morphisms' option to domain_isomorphism command
huffman
parents: 33971
diff changeset
   664
val parse_domain_iso :
a0efb4754cb7 add 'morphisms' option to domain_isomorphism command
huffman
parents: 33971
diff changeset
   665
    (string list * binding * mixfix * string * (binding * binding) option)
a0efb4754cb7 add 'morphisms' option to domain_isomorphism command
huffman
parents: 33971
diff changeset
   666
      parser =
a0efb4754cb7 add 'morphisms' option to domain_isomorphism command
huffman
parents: 33971
diff changeset
   667
  (P.type_args -- P.binding -- P.opt_infix -- (P.$$$ "=" |-- P.typ) --
a0efb4754cb7 add 'morphisms' option to domain_isomorphism command
huffman
parents: 33971
diff changeset
   668
    Scan.option (P.$$$ "morphisms" |-- P.!!! (P.binding -- P.binding)))
a0efb4754cb7 add 'morphisms' option to domain_isomorphism command
huffman
parents: 33971
diff changeset
   669
    >> (fn ((((vs, t), mx), rhs), morphs) => (vs, t, mx, rhs, morphs));
33774
e11e05b32548 automate solution of domain equations
huffman
parents:
diff changeset
   670
e11e05b32548 automate solution of domain equations
huffman
parents:
diff changeset
   671
val parse_domain_isos = P.and_list1 parse_domain_iso;
e11e05b32548 automate solution of domain equations
huffman
parents:
diff changeset
   672
e11e05b32548 automate solution of domain equations
huffman
parents:
diff changeset
   673
in
e11e05b32548 automate solution of domain equations
huffman
parents:
diff changeset
   674
e11e05b32548 automate solution of domain equations
huffman
parents:
diff changeset
   675
val _ =
e11e05b32548 automate solution of domain equations
huffman
parents:
diff changeset
   676
  OuterSyntax.command "domain_isomorphism" "define domain isomorphisms (HOLCF)" K.thy_decl
e11e05b32548 automate solution of domain equations
huffman
parents:
diff changeset
   677
    (parse_domain_isos >> (Toplevel.theory o domain_isomorphism_cmd));
e11e05b32548 automate solution of domain equations
huffman
parents:
diff changeset
   678
e11e05b32548 automate solution of domain equations
huffman
parents:
diff changeset
   679
end;
e11e05b32548 automate solution of domain equations
huffman
parents:
diff changeset
   680
e11e05b32548 automate solution of domain equations
huffman
parents:
diff changeset
   681
end;