Quot/Nominal/Fv.thy
author Cezary Kaliszyk <kaliszyk@in.tum.de>
Tue, 23 Feb 2010 09:31:59 +0100
changeset 1217 74e2b9b95add
parent 1216 06ace3a1eedd
child 1221 526fad251a8e
permissions -rw-r--r--
Fixes for auxiliary datatypes.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1168
5c1e16806901 Code for generating the fv function, no bindings yet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
     1
theory Fv
1193
a228acf2907e Full alpha equivalence + testing in terms. Some differ but it seems the generated version is more correct.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1192
diff changeset
     2
imports "Nominal2_Atoms" "Abs"
1168
5c1e16806901 Code for generating the fv function, no bindings yet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
     3
begin
5c1e16806901 Code for generating the fv function, no bindings yet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
     4
1169
b9d02e0800e9 Description of intended bindings.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1168
diff changeset
     5
(* Bindings are given as a list which has a length being equal
1172
9a609fefcf24 Simplified format of bindings.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1169
diff changeset
     6
   to the length of the number of constructors.
9a609fefcf24 Simplified format of bindings.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1169
diff changeset
     7
9a609fefcf24 Simplified format of bindings.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1169
diff changeset
     8
   Each element is a list whose length is equal to the number
9a609fefcf24 Simplified format of bindings.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1169
diff changeset
     9
   of arguents.
9a609fefcf24 Simplified format of bindings.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1169
diff changeset
    10
9a609fefcf24 Simplified format of bindings.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1169
diff changeset
    11
   Every element specifies bindings of this argument given as
9a609fefcf24 Simplified format of bindings.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1169
diff changeset
    12
   a tuple: function, bound argument.
1169
b9d02e0800e9 Description of intended bindings.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1168
diff changeset
    13
b9d02e0800e9 Description of intended bindings.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1168
diff changeset
    14
  Eg:
b9d02e0800e9 Description of intended bindings.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1168
diff changeset
    15
nominal_datatype
b9d02e0800e9 Description of intended bindings.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1168
diff changeset
    16
b9d02e0800e9 Description of intended bindings.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1168
diff changeset
    17
   C1
b9d02e0800e9 Description of intended bindings.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1168
diff changeset
    18
 | C2 x y z bind x in z
1172
9a609fefcf24 Simplified format of bindings.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1169
diff changeset
    19
 | C3 x y z bind f x in z bind g y in z
1169
b9d02e0800e9 Description of intended bindings.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1168
diff changeset
    20
b9d02e0800e9 Description of intended bindings.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1168
diff changeset
    21
yields:
1172
9a609fefcf24 Simplified format of bindings.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1169
diff changeset
    22
[
9a609fefcf24 Simplified format of bindings.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1169
diff changeset
    23
 [],
9a609fefcf24 Simplified format of bindings.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1169
diff changeset
    24
 [[], [], [(NONE, 0)]],
1173
9cb99a28b40e Some optimizations and fixes.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1172
diff changeset
    25
 [[], [], [(SOME (Const f), 0), (Some (Const g), 1)]]]
1185
7566b899ca6a Code for handling atom sets.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1180
diff changeset
    26
7566b899ca6a Code for handling atom sets.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1180
diff changeset
    27
A SOME binding has to have a function returning an atom set,
7566b899ca6a Code for handling atom sets.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1180
diff changeset
    28
and a NONE binding has to be on an argument that is an atom
7566b899ca6a Code for handling atom sets.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1180
diff changeset
    29
or an atom set.
7566b899ca6a Code for handling atom sets.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1180
diff changeset
    30
1191
15362b433d64 Description of the fv procedure.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1185
diff changeset
    31
How the procedure works:
15362b433d64 Description of the fv procedure.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1185
diff changeset
    32
  For each of the defined datatypes,
15362b433d64 Description of the fv procedure.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1185
diff changeset
    33
  For each of the constructors,
15362b433d64 Description of the fv procedure.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1185
diff changeset
    34
  It creates a union of free variables for each argument.
15362b433d64 Description of the fv procedure.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1185
diff changeset
    35
15362b433d64 Description of the fv procedure.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1185
diff changeset
    36
  For an argument the free variables are the variables minus
15362b433d64 Description of the fv procedure.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1185
diff changeset
    37
  bound variables.
15362b433d64 Description of the fv procedure.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1185
diff changeset
    38
15362b433d64 Description of the fv procedure.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1185
diff changeset
    39
  The variables are:
15362b433d64 Description of the fv procedure.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1185
diff changeset
    40
    For an atom, a singleton set with the atom itself.
15362b433d64 Description of the fv procedure.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1185
diff changeset
    41
    For an atom set, the atom set itself.
15362b433d64 Description of the fv procedure.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1185
diff changeset
    42
    For a recursive argument, the appropriate fv function applied to it.
15362b433d64 Description of the fv procedure.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1185
diff changeset
    43
    (* TODO: This one is not implemented *)
15362b433d64 Description of the fv procedure.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1185
diff changeset
    44
    For other arguments it should be an appropriate fv function stored
15362b433d64 Description of the fv procedure.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1185
diff changeset
    45
      in the database.
15362b433d64 Description of the fv procedure.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1185
diff changeset
    46
  The bound variables are a union of results of all bindings that
15362b433d64 Description of the fv procedure.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1185
diff changeset
    47
  involve the given argument. For a paricular binding the result is:
15362b433d64 Description of the fv procedure.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1185
diff changeset
    48
    For a function applied to an argument this function with the argument.
15362b433d64 Description of the fv procedure.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1185
diff changeset
    49
    For an atom, a singleton set with the atom itself.
15362b433d64 Description of the fv procedure.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1185
diff changeset
    50
    For an atom set, the atom set itself.
15362b433d64 Description of the fv procedure.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1185
diff changeset
    51
    For a recursive argument, the appropriate fv function applied to it.
15362b433d64 Description of the fv procedure.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1185
diff changeset
    52
    (* TODO: This one is not implemented *)
15362b433d64 Description of the fv procedure.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1185
diff changeset
    53
    For other arguments it should be an appropriate fv function stored
15362b433d64 Description of the fv procedure.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1185
diff changeset
    54
      in the database.
1169
b9d02e0800e9 Description of intended bindings.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1168
diff changeset
    55
*)
b9d02e0800e9 Description of intended bindings.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1168
diff changeset
    56
1168
5c1e16806901 Code for generating the fv function, no bindings yet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    57
ML {*
1175
6a3be6ef348d Reorganization
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1174
diff changeset
    58
  open Datatype_Aux; (* typ_of_dtyp, DtRec, ... *);
1178
275a1cb3f2ba Reorder
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1177
diff changeset
    59
  (* TODO: It is the same as one in 'nominal_atoms' *)
1175
6a3be6ef348d Reorganization
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1174
diff changeset
    60
  fun mk_atom ty = Const (@{const_name atom}, ty --> @{typ atom});
6a3be6ef348d Reorganization
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1174
diff changeset
    61
  val noatoms = @{term "{} :: atom set"};
6a3be6ef348d Reorganization
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1174
diff changeset
    62
  fun mk_single_atom x = HOLogic.mk_set @{typ atom} [mk_atom (type_of x) $ x];
6a3be6ef348d Reorganization
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1174
diff changeset
    63
  fun mk_union sets =
6a3be6ef348d Reorganization
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1174
diff changeset
    64
    fold (fn a => fn b =>
6a3be6ef348d Reorganization
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1174
diff changeset
    65
      if a = noatoms then b else
6a3be6ef348d Reorganization
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1174
diff changeset
    66
      if b = noatoms then a else
6a3be6ef348d Reorganization
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1174
diff changeset
    67
      HOLogic.mk_binop @{const_name union} (a, b)) (rev sets) noatoms;
6a3be6ef348d Reorganization
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1174
diff changeset
    68
  fun mk_diff a b =
6a3be6ef348d Reorganization
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1174
diff changeset
    69
    if b = noatoms then a else
6a3be6ef348d Reorganization
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1174
diff changeset
    70
    if b = a then noatoms else
6a3be6ef348d Reorganization
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1174
diff changeset
    71
    HOLogic.mk_binop @{const_name minus} (a, b);
1185
7566b899ca6a Code for handling atom sets.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1180
diff changeset
    72
  fun mk_atoms t =
7566b899ca6a Code for handling atom sets.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1180
diff changeset
    73
    let
7566b899ca6a Code for handling atom sets.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1180
diff changeset
    74
      val ty = fastype_of t;
7566b899ca6a Code for handling atom sets.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1180
diff changeset
    75
      val atom_ty = HOLogic.dest_setT ty --> @{typ atom};
7566b899ca6a Code for handling atom sets.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1180
diff changeset
    76
      val img_ty = atom_ty --> ty --> @{typ "atom set"};
7566b899ca6a Code for handling atom sets.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1180
diff changeset
    77
    in
7566b899ca6a Code for handling atom sets.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1180
diff changeset
    78
      (Const (@{const_name image}, img_ty) $ Const (@{const_name atom}, atom_ty) $ t)
7566b899ca6a Code for handling atom sets.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1180
diff changeset
    79
    end;
7566b899ca6a Code for handling atom sets.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1180
diff changeset
    80
  (* Copy from Term *)
7566b899ca6a Code for handling atom sets.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1180
diff changeset
    81
  fun is_funtype (Type ("fun", [_, _])) = true
7566b899ca6a Code for handling atom sets.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1180
diff changeset
    82
    | is_funtype _ = false;
1193
a228acf2907e Full alpha equivalence + testing in terms. Some differ but it seems the generated version is more correct.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1192
diff changeset
    83
  (* Similar to one in USyntax *)
a228acf2907e Full alpha equivalence + testing in terms. Some differ but it seems the generated version is more correct.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1192
diff changeset
    84
  fun mk_pair (fst, snd) =
a228acf2907e Full alpha equivalence + testing in terms. Some differ but it seems the generated version is more correct.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1192
diff changeset
    85
    let val ty1 = fastype_of fst
a228acf2907e Full alpha equivalence + testing in terms. Some differ but it seems the generated version is more correct.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1192
diff changeset
    86
      val ty2 = fastype_of snd
a228acf2907e Full alpha equivalence + testing in terms. Some differ but it seems the generated version is more correct.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1192
diff changeset
    87
      val c = HOLogic.pair_const ty1 ty2
a228acf2907e Full alpha equivalence + testing in terms. Some differ but it seems the generated version is more correct.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1192
diff changeset
    88
    in c $ fst $ snd
a228acf2907e Full alpha equivalence + testing in terms. Some differ but it seems the generated version is more correct.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1192
diff changeset
    89
    end;
a228acf2907e Full alpha equivalence + testing in terms. Some differ but it seems the generated version is more correct.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1192
diff changeset
    90
1175
6a3be6ef348d Reorganization
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1174
diff changeset
    91
*}
6a3be6ef348d Reorganization
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1174
diff changeset
    92
1206
9c968284553c Renaming.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1199
diff changeset
    93
(* TODO: Notice datatypes without bindings and replace alpha with equality *)
1175
6a3be6ef348d Reorganization
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1174
diff changeset
    94
ML {*
1178
275a1cb3f2ba Reorder
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1177
diff changeset
    95
(* Currently needs just one full_tname to access Datatype *)
1193
a228acf2907e Full alpha equivalence + testing in terms. Some differ but it seems the generated version is more correct.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1192
diff changeset
    96
fun define_fv_alpha full_tname bindsall lthy =
1178
275a1cb3f2ba Reorder
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1177
diff changeset
    97
let
1185
7566b899ca6a Code for handling atom sets.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1180
diff changeset
    98
  val thy = ProofContext.theory_of lthy;
1178
275a1cb3f2ba Reorder
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1177
diff changeset
    99
  val {descr, ...} = Datatype.the_info thy full_tname;
275a1cb3f2ba Reorder
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1177
diff changeset
   100
  val sorts = []; (* TODO *)
1168
5c1e16806901 Code for generating the fv function, no bindings yet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   101
  fun nth_dtyp i = typ_of_dtyp descr sorts (DtRec i);
5c1e16806901 Code for generating the fv function, no bindings yet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   102
  val fv_names = Datatype_Prop.indexify_names (map (fn (i, _) =>
5c1e16806901 Code for generating the fv function, no bindings yet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   103
    "fv_" ^ name_of_typ (nth_dtyp i)) descr);
5c1e16806901 Code for generating the fv function, no bindings yet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   104
  val fv_types = map (fn (i, _) => nth_dtyp i --> @{typ "atom set"}) descr;
5c1e16806901 Code for generating the fv function, no bindings yet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   105
  val fv_frees = map Free (fv_names ~~ fv_types);
1193
a228acf2907e Full alpha equivalence + testing in terms. Some differ but it seems the generated version is more correct.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1192
diff changeset
   106
  val alpha_names = Datatype_Prop.indexify_names (map (fn (i, _) =>
a228acf2907e Full alpha equivalence + testing in terms. Some differ but it seems the generated version is more correct.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1192
diff changeset
   107
    "alpha_" ^ name_of_typ (nth_dtyp i)) descr);
a228acf2907e Full alpha equivalence + testing in terms. Some differ but it seems the generated version is more correct.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1192
diff changeset
   108
  val alpha_types = map (fn (i, _) => nth_dtyp i --> nth_dtyp i --> @{typ bool}) descr;
a228acf2907e Full alpha equivalence + testing in terms. Some differ but it seems the generated version is more correct.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1192
diff changeset
   109
  val alpha_frees = map Free (alpha_names ~~ alpha_types);
a228acf2907e Full alpha equivalence + testing in terms. Some differ but it seems the generated version is more correct.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1192
diff changeset
   110
  fun fv_alpha_constr i (cname, dts) bindcs =
1168
5c1e16806901 Code for generating the fv function, no bindings yet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   111
    let
5c1e16806901 Code for generating the fv function, no bindings yet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   112
      val Ts = map (typ_of_dtyp descr sorts) dts;
5c1e16806901 Code for generating the fv function, no bindings yet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   113
      val names = Name.variant_list ["pi"] (Datatype_Prop.make_tnames Ts);
5c1e16806901 Code for generating the fv function, no bindings yet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   114
      val args = map Free (names ~~ Ts);
1193
a228acf2907e Full alpha equivalence + testing in terms. Some differ but it seems the generated version is more correct.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1192
diff changeset
   115
      val names2 = Name.variant_list ("pi" :: names) (Datatype_Prop.make_tnames Ts);
a228acf2907e Full alpha equivalence + testing in terms. Some differ but it seems the generated version is more correct.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1192
diff changeset
   116
      val args2 = map Free (names2 ~~ Ts);
1168
5c1e16806901 Code for generating the fv function, no bindings yet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   117
      val c = Const (cname, Ts ---> (nth_dtyp i));
1192
6fd072d3acd2 First (non-working) version of alpha-equivalence
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1191
diff changeset
   118
      val fv_c = nth fv_frees i;
1193
a228acf2907e Full alpha equivalence + testing in terms. Some differ but it seems the generated version is more correct.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1192
diff changeset
   119
      val alpha = nth alpha_frees i;
a228acf2907e Full alpha equivalence + testing in terms. Some differ but it seems the generated version is more correct.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1192
diff changeset
   120
      fun fv_bind args (NONE, i) =
1177
6f01720fe520 Add bindings of recursive types by free_variables.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1176
diff changeset
   121
            if is_rec_type (nth dts i) then (nth fv_frees (body_index (nth dts i))) $ (nth args i) else
6f01720fe520 Add bindings of recursive types by free_variables.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1176
diff changeset
   122
            (* TODO we assume that all can be 'atomized' *)
1185
7566b899ca6a Code for handling atom sets.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1180
diff changeset
   123
            if (is_funtype o fastype_of) (nth args i) then mk_atoms (nth args i) else
1177
6f01720fe520 Add bindings of recursive types by free_variables.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1176
diff changeset
   124
            mk_single_atom (nth args i)
1193
a228acf2907e Full alpha equivalence + testing in terms. Some differ but it seems the generated version is more correct.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1192
diff changeset
   125
        | fv_bind args (SOME f, i) = f $ (nth args i);
1173
9cb99a28b40e Some optimizations and fixes.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1172
diff changeset
   126
      fun fv_arg ((dt, x), bindxs) =
1172
9a609fefcf24 Simplified format of bindings.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1169
diff changeset
   127
        let
9a609fefcf24 Simplified format of bindings.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1169
diff changeset
   128
          val arg =
1175
6a3be6ef348d Reorganization
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1174
diff changeset
   129
            if is_rec_type dt then nth fv_frees (body_index dt) $ x else
1174
f6e9ae54b855 Now should work.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1173
diff changeset
   130
            (* TODO: we just assume everything can be 'atomized' *)
1185
7566b899ca6a Code for handling atom sets.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1180
diff changeset
   131
            if (is_funtype o fastype_of) x then mk_atoms x else
7566b899ca6a Code for handling atom sets.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1180
diff changeset
   132
            HOLogic.mk_set @{typ atom} [mk_atom (fastype_of x) $ x]
1193
a228acf2907e Full alpha equivalence + testing in terms. Some differ but it seems the generated version is more correct.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1192
diff changeset
   133
          val sub = mk_union (map (fv_bind args) bindxs)
1172
9a609fefcf24 Simplified format of bindings.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1169
diff changeset
   134
        in
1173
9cb99a28b40e Some optimizations and fixes.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1172
diff changeset
   135
          mk_diff arg sub
9cb99a28b40e Some optimizations and fixes.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1172
diff changeset
   136
        end;
1193
a228acf2907e Full alpha equivalence + testing in terms. Some differ but it seems the generated version is more correct.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1192
diff changeset
   137
      val fv_eq = HOLogic.mk_Trueprop (HOLogic.mk_eq
a228acf2907e Full alpha equivalence + testing in terms. Some differ but it seems the generated version is more correct.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1192
diff changeset
   138
        (fv_c $ list_comb (c, args), mk_union (map fv_arg (dts ~~ args ~~ bindcs))))
a228acf2907e Full alpha equivalence + testing in terms. Some differ but it seems the generated version is more correct.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1192
diff changeset
   139
      val alpha_rhs =
a228acf2907e Full alpha equivalence + testing in terms. Some differ but it seems the generated version is more correct.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1192
diff changeset
   140
        HOLogic.mk_Trueprop (alpha $ (list_comb (c, args)) $ (list_comb (c, args2)));
a228acf2907e Full alpha equivalence + testing in terms. Some differ but it seems the generated version is more correct.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1192
diff changeset
   141
      fun alpha_arg ((dt, bindxs), (arg, arg2)) =
a228acf2907e Full alpha equivalence + testing in terms. Some differ but it seems the generated version is more correct.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1192
diff changeset
   142
        if bindxs = [] then (
a228acf2907e Full alpha equivalence + testing in terms. Some differ but it seems the generated version is more correct.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1192
diff changeset
   143
          if is_rec_type dt then (nth alpha_frees (body_index dt) $ arg $ arg2)
a228acf2907e Full alpha equivalence + testing in terms. Some differ but it seems the generated version is more correct.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1192
diff changeset
   144
          else (HOLogic.mk_eq (arg, arg2)))
a228acf2907e Full alpha equivalence + testing in terms. Some differ but it seems the generated version is more correct.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1192
diff changeset
   145
        else
a228acf2907e Full alpha equivalence + testing in terms. Some differ but it seems the generated version is more correct.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1192
diff changeset
   146
          if is_rec_type dt then let
a228acf2907e Full alpha equivalence + testing in terms. Some differ but it seems the generated version is more correct.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1192
diff changeset
   147
            (* THE HARD CASE *)
a228acf2907e Full alpha equivalence + testing in terms. Some differ but it seems the generated version is more correct.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1192
diff changeset
   148
            val lhs_binds = mk_union (map (fv_bind args) bindxs);
a228acf2907e Full alpha equivalence + testing in terms. Some differ but it seems the generated version is more correct.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1192
diff changeset
   149
            val lhs = mk_pair (lhs_binds, arg);
a228acf2907e Full alpha equivalence + testing in terms. Some differ but it seems the generated version is more correct.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1192
diff changeset
   150
            val rhs_binds = mk_union (map (fv_bind args2) bindxs);
a228acf2907e Full alpha equivalence + testing in terms. Some differ but it seems the generated version is more correct.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1192
diff changeset
   151
            val rhs = mk_pair (rhs_binds, arg2);
a228acf2907e Full alpha equivalence + testing in terms. Some differ but it seems the generated version is more correct.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1192
diff changeset
   152
            val alpha = nth alpha_frees (body_index dt);
a228acf2907e Full alpha equivalence + testing in terms. Some differ but it seems the generated version is more correct.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1192
diff changeset
   153
            val fv = nth fv_frees (body_index dt);
a228acf2907e Full alpha equivalence + testing in terms. Some differ but it seems the generated version is more correct.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1192
diff changeset
   154
            val alpha_gen_pre = Const (@{const_name alpha_gen}, dummyT) $ lhs $ alpha $ fv $ (Free ("pi", @{typ perm})) $ rhs;
a228acf2907e Full alpha equivalence + testing in terms. Some differ but it seems the generated version is more correct.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1192
diff changeset
   155
            val alpha_gen_t = Syntax.check_term lthy alpha_gen_pre
a228acf2907e Full alpha equivalence + testing in terms. Some differ but it seems the generated version is more correct.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1192
diff changeset
   156
          in
a228acf2907e Full alpha equivalence + testing in terms. Some differ but it seems the generated version is more correct.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1192
diff changeset
   157
            HOLogic.mk_exists ("pi", @{typ perm}, alpha_gen_t)
a228acf2907e Full alpha equivalence + testing in terms. Some differ but it seems the generated version is more correct.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1192
diff changeset
   158
          (* TODO Add some test that is makes sense *)
a228acf2907e Full alpha equivalence + testing in terms. Some differ but it seems the generated version is more correct.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1192
diff changeset
   159
          end else @{term "True"}
a228acf2907e Full alpha equivalence + testing in terms. Some differ but it seems the generated version is more correct.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1192
diff changeset
   160
      val alpha_lhss = map (HOLogic.mk_Trueprop o alpha_arg) (dts ~~ bindcs ~~ (args ~~ args2))
a228acf2907e Full alpha equivalence + testing in terms. Some differ but it seems the generated version is more correct.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1192
diff changeset
   161
      val alpha_eq = Logic.list_implies (alpha_lhss, alpha_rhs)
1173
9cb99a28b40e Some optimizations and fixes.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1172
diff changeset
   162
    in
1193
a228acf2907e Full alpha equivalence + testing in terms. Some differ but it seems the generated version is more correct.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1192
diff changeset
   163
      (fv_eq, alpha_eq)
1168
5c1e16806901 Code for generating the fv function, no bindings yet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   164
    end;
1193
a228acf2907e Full alpha equivalence + testing in terms. Some differ but it seems the generated version is more correct.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1192
diff changeset
   165
  fun fv_alpha_eq (i, (_, _, constrs)) binds = map2 (fv_alpha_constr i) constrs binds;
a228acf2907e Full alpha equivalence + testing in terms. Some differ but it seems the generated version is more correct.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1192
diff changeset
   166
  val (fv_eqs, alpha_eqs) = split_list (flat (map2 fv_alpha_eq descr bindsall))
a228acf2907e Full alpha equivalence + testing in terms. Some differ but it seems the generated version is more correct.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1192
diff changeset
   167
  val add_binds = map (fn x => (Attrib.empty_binding, x))
a228acf2907e Full alpha equivalence + testing in terms. Some differ but it seems the generated version is more correct.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1192
diff changeset
   168
  val (fvs, lthy') = (Primrec.add_primrec
a228acf2907e Full alpha equivalence + testing in terms. Some differ but it seems the generated version is more correct.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1192
diff changeset
   169
    (map (fn s => (Binding.name s, NONE, NoSyn)) fv_names) (add_binds fv_eqs) lthy)
a228acf2907e Full alpha equivalence + testing in terms. Some differ but it seems the generated version is more correct.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1192
diff changeset
   170
  val (alphas, lthy'') = (Inductive.add_inductive_i
a228acf2907e Full alpha equivalence + testing in terms. Some differ but it seems the generated version is more correct.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1192
diff changeset
   171
     {quiet_mode = false, verbose = true, alt_name = Binding.empty,
a228acf2907e Full alpha equivalence + testing in terms. Some differ but it seems the generated version is more correct.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1192
diff changeset
   172
      coind = false, no_elim = false, no_ind = false, skip_mono = true, fork_mono = false}
a228acf2907e Full alpha equivalence + testing in terms. Some differ but it seems the generated version is more correct.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1192
diff changeset
   173
     (map2 (fn x => fn y => ((Binding.name x, y), NoSyn)) alpha_names alpha_types) []
a228acf2907e Full alpha equivalence + testing in terms. Some differ but it seems the generated version is more correct.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1192
diff changeset
   174
     (add_binds alpha_eqs) [] lthy')
1178
275a1cb3f2ba Reorder
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1177
diff changeset
   175
in
1193
a228acf2907e Full alpha equivalence + testing in terms. Some differ but it seems the generated version is more correct.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1192
diff changeset
   176
  ((fvs, alphas), lthy'')
1178
275a1cb3f2ba Reorder
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1177
diff changeset
   177
end
1168
5c1e16806901 Code for generating the fv function, no bindings yet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   178
*}
5c1e16806901 Code for generating the fv function, no bindings yet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   179
1193
a228acf2907e Full alpha equivalence + testing in terms. Some differ but it seems the generated version is more correct.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1192
diff changeset
   180
(* tests
1178
275a1cb3f2ba Reorder
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1177
diff changeset
   181
atom_decl name
275a1cb3f2ba Reorder
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1177
diff changeset
   182
1193
a228acf2907e Full alpha equivalence + testing in terms. Some differ but it seems the generated version is more correct.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1192
diff changeset
   183
datatype ty =
1185
7566b899ca6a Code for handling atom sets.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1180
diff changeset
   184
  Var "name set"
7566b899ca6a Code for handling atom sets.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1180
diff changeset
   185
7566b899ca6a Code for handling atom sets.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1180
diff changeset
   186
ML {* Syntax.check_term @{context} (mk_atoms @{term "a :: name set"}) *}
7566b899ca6a Code for handling atom sets.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1180
diff changeset
   187
1193
a228acf2907e Full alpha equivalence + testing in terms. Some differ but it seems the generated version is more correct.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1192
diff changeset
   188
local_setup {* define_fv_alpha "Fv.ty" [[[[]]]] *}
1185
7566b899ca6a Code for handling atom sets.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1180
diff changeset
   189
print_theorems
1193
a228acf2907e Full alpha equivalence + testing in terms. Some differ but it seems the generated version is more correct.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1192
diff changeset
   190
1185
7566b899ca6a Code for handling atom sets.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1180
diff changeset
   191
1178
275a1cb3f2ba Reorder
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1177
diff changeset
   192
datatype rtrm1 =
275a1cb3f2ba Reorder
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1177
diff changeset
   193
  rVr1 "name"
275a1cb3f2ba Reorder
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1177
diff changeset
   194
| rAp1 "rtrm1" "rtrm1"
275a1cb3f2ba Reorder
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1177
diff changeset
   195
| rLm1 "name" "rtrm1"        --"name is bound in trm1"
275a1cb3f2ba Reorder
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1177
diff changeset
   196
| rLt1 "bp" "rtrm1" "rtrm1"   --"all variables in bp are bound in the 2nd trm1"
275a1cb3f2ba Reorder
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1177
diff changeset
   197
and bp =
275a1cb3f2ba Reorder
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1177
diff changeset
   198
  BUnit
275a1cb3f2ba Reorder
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1177
diff changeset
   199
| BVr "name"
275a1cb3f2ba Reorder
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1177
diff changeset
   200
| BPr "bp" "bp"
275a1cb3f2ba Reorder
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1177
diff changeset
   201
275a1cb3f2ba Reorder
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1177
diff changeset
   202
(* to be given by the user *)
275a1cb3f2ba Reorder
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1177
diff changeset
   203
275a1cb3f2ba Reorder
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1177
diff changeset
   204
primrec 
275a1cb3f2ba Reorder
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1177
diff changeset
   205
  bv1
275a1cb3f2ba Reorder
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1177
diff changeset
   206
where
275a1cb3f2ba Reorder
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1177
diff changeset
   207
  "bv1 (BUnit) = {}"
275a1cb3f2ba Reorder
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1177
diff changeset
   208
| "bv1 (BVr x) = {atom x}"
275a1cb3f2ba Reorder
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1177
diff changeset
   209
| "bv1 (BPr bp1 bp2) = (bv1 bp1) \<union> (bv1 bp1)"
275a1cb3f2ba Reorder
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1177
diff changeset
   210
1193
a228acf2907e Full alpha equivalence + testing in terms. Some differ but it seems the generated version is more correct.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1192
diff changeset
   211
setup {* snd o define_raw_perms ["rtrm1", "bp"] ["Fv.rtrm1", "Fv.bp"] *}
a228acf2907e Full alpha equivalence + testing in terms. Some differ but it seems the generated version is more correct.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1192
diff changeset
   212
a228acf2907e Full alpha equivalence + testing in terms. Some differ but it seems the generated version is more correct.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1192
diff changeset
   213
local_setup {* define_fv_alpha "Fv.rtrm1"
a228acf2907e Full alpha equivalence + testing in terms. Some differ but it seems the generated version is more correct.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1192
diff changeset
   214
  [[[[]], [[], []], [[(NONE, 0)], [(NONE, 0)]], [[(SOME @{term bv1}, 0)], [], [(SOME @{term bv1}, 0)]]],
1178
275a1cb3f2ba Reorder
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1177
diff changeset
   215
   [[], [[]], [[], []]]] *}
1168
5c1e16806901 Code for generating the fv function, no bindings yet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   216
print_theorems
1193
a228acf2907e Full alpha equivalence + testing in terms. Some differ but it seems the generated version is more correct.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1192
diff changeset
   217
*)
1180
3f36936f1280 Testing Fv
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1178
diff changeset
   218
1199
5770c73f2415 Automatic production and proving of pseudo-injectivity.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1196
diff changeset
   219
1196
4efbaba9d754 Constructing alpha_inj goal.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1193
diff changeset
   220
ML {*
1199
5770c73f2415 Automatic production and proving of pseudo-injectivity.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1196
diff changeset
   221
fun alpha_inj_tac dist_inj intrs elims =
5770c73f2415 Automatic production and proving of pseudo-injectivity.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1196
diff changeset
   222
  SOLVED' (asm_full_simp_tac (HOL_ss addsimps intrs)) ORELSE'
1216
06ace3a1eedd Fixed pseudo_injectivity for trm4
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1215
diff changeset
   223
  (rtac @{thm iffI} THEN' RANGE [
1199
5770c73f2415 Automatic production and proving of pseudo-injectivity.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1196
diff changeset
   224
     (eresolve_tac elims THEN_ALL_NEW
5770c73f2415 Automatic production and proving of pseudo-injectivity.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1196
diff changeset
   225
       asm_full_simp_tac (HOL_ss addsimps dist_inj)
5770c73f2415 Automatic production and proving of pseudo-injectivity.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1196
diff changeset
   226
     ),
1216
06ace3a1eedd Fixed pseudo_injectivity for trm4
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1215
diff changeset
   227
     asm_full_simp_tac (HOL_ss addsimps intrs)])
1199
5770c73f2415 Automatic production and proving of pseudo-injectivity.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1196
diff changeset
   228
*}
5770c73f2415 Automatic production and proving of pseudo-injectivity.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1196
diff changeset
   229
5770c73f2415 Automatic production and proving of pseudo-injectivity.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1196
diff changeset
   230
ML {*
5770c73f2415 Automatic production and proving of pseudo-injectivity.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1196
diff changeset
   231
fun build_alpha_inj_gl thm =
5770c73f2415 Automatic production and proving of pseudo-injectivity.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1196
diff changeset
   232
  let
5770c73f2415 Automatic production and proving of pseudo-injectivity.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1196
diff changeset
   233
    val prop = prop_of thm;
5770c73f2415 Automatic production and proving of pseudo-injectivity.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1196
diff changeset
   234
    val concl = HOLogic.dest_Trueprop (Logic.strip_imp_concl prop);
5770c73f2415 Automatic production and proving of pseudo-injectivity.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1196
diff changeset
   235
    val hyps = map HOLogic.dest_Trueprop (Logic.strip_imp_prems prop);
5770c73f2415 Automatic production and proving of pseudo-injectivity.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1196
diff changeset
   236
    fun list_conj l = foldr1 HOLogic.mk_conj l;
5770c73f2415 Automatic production and proving of pseudo-injectivity.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1196
diff changeset
   237
  in
5770c73f2415 Automatic production and proving of pseudo-injectivity.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1196
diff changeset
   238
    if hyps = [] then concl
5770c73f2415 Automatic production and proving of pseudo-injectivity.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1196
diff changeset
   239
    else HOLogic.mk_eq (concl, list_conj hyps)
5770c73f2415 Automatic production and proving of pseudo-injectivity.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1196
diff changeset
   240
  end;
5770c73f2415 Automatic production and proving of pseudo-injectivity.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1196
diff changeset
   241
*}
5770c73f2415 Automatic production and proving of pseudo-injectivity.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1196
diff changeset
   242
5770c73f2415 Automatic production and proving of pseudo-injectivity.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1196
diff changeset
   243
ML {*
5770c73f2415 Automatic production and proving of pseudo-injectivity.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1196
diff changeset
   244
fun build_alpha_inj intrs dist_inj elims ctxt =
1196
4efbaba9d754 Constructing alpha_inj goal.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1193
diff changeset
   245
let
1199
5770c73f2415 Automatic production and proving of pseudo-injectivity.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1196
diff changeset
   246
  val ((_, thms_imp), ctxt') = Variable.import false intrs ctxt;
5770c73f2415 Automatic production and proving of pseudo-injectivity.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1196
diff changeset
   247
  val gls = map (HOLogic.mk_Trueprop o build_alpha_inj_gl) thms_imp;
5770c73f2415 Automatic production and proving of pseudo-injectivity.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1196
diff changeset
   248
  fun tac _ = alpha_inj_tac dist_inj intrs elims 1;
5770c73f2415 Automatic production and proving of pseudo-injectivity.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1196
diff changeset
   249
  val thms = map (fn gl => Goal.prove ctxt' [] [] gl tac) gls;
1196
4efbaba9d754 Constructing alpha_inj goal.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1193
diff changeset
   250
in
1199
5770c73f2415 Automatic production and proving of pseudo-injectivity.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1196
diff changeset
   251
  Variable.export ctxt' ctxt thms
1168
5c1e16806901 Code for generating the fv function, no bindings yet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   252
end
1196
4efbaba9d754 Constructing alpha_inj goal.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1193
diff changeset
   253
*}
4efbaba9d754 Constructing alpha_inj goal.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1193
diff changeset
   254
1207
fb33684e4ece alpha reflexivity
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1206
diff changeset
   255
ML {*
1214
0f92257edeee A tactic for final equivp
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1213
diff changeset
   256
fun build_alpha_refl_gl alphas (x, y, z) =
1207
fb33684e4ece alpha reflexivity
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1206
diff changeset
   257
let
fb33684e4ece alpha reflexivity
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1206
diff changeset
   258
  fun build_alpha alpha =
fb33684e4ece alpha reflexivity
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1206
diff changeset
   259
    let
fb33684e4ece alpha reflexivity
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1206
diff changeset
   260
      val ty = domain_type (fastype_of alpha);
1214
0f92257edeee A tactic for final equivp
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1213
diff changeset
   261
      val var = Free(x, ty);
0f92257edeee A tactic for final equivp
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1213
diff changeset
   262
      val var2 = Free(y, ty);
0f92257edeee A tactic for final equivp
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1213
diff changeset
   263
      val var3 = Free(z, ty);
1209
7b1a3df239cd Some progress about transp
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1208
diff changeset
   264
      val symp = HOLogic.mk_imp (alpha $ var $ var2, alpha $ var2 $ var);
7b1a3df239cd Some progress about transp
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1208
diff changeset
   265
      val transp = HOLogic.mk_imp (alpha $ var $ var2,
1214
0f92257edeee A tactic for final equivp
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1213
diff changeset
   266
        HOLogic.mk_all (z, ty,
1209
7b1a3df239cd Some progress about transp
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1208
diff changeset
   267
          HOLogic.mk_imp (alpha $ var2 $ var3, alpha $ var $ var3)))
1207
fb33684e4ece alpha reflexivity
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1206
diff changeset
   268
    in
1209
7b1a3df239cd Some progress about transp
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1208
diff changeset
   269
      ((alpha $ var $ var), (symp, transp))
1208
cc86faf0d2a0 alpha-symmetric addons.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1207
diff changeset
   270
    end;
1209
7b1a3df239cd Some progress about transp
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1208
diff changeset
   271
  val (refl_eqs, eqs) = split_list (map build_alpha alphas)
7b1a3df239cd Some progress about transp
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1208
diff changeset
   272
  val (sym_eqs, trans_eqs) = split_list eqs
7b1a3df239cd Some progress about transp
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1208
diff changeset
   273
  fun conj l = @{term Trueprop} $ foldr1 HOLogic.mk_conj l
1207
fb33684e4ece alpha reflexivity
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1206
diff changeset
   274
in
1209
7b1a3df239cd Some progress about transp
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1208
diff changeset
   275
  (conj refl_eqs, (conj sym_eqs, conj trans_eqs))
1196
4efbaba9d754 Constructing alpha_inj goal.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1193
diff changeset
   276
end
1207
fb33684e4ece alpha reflexivity
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1206
diff changeset
   277
*}
fb33684e4ece alpha reflexivity
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1206
diff changeset
   278
1213
43bd70786f9f More equivp infrastructure.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1209
diff changeset
   279
ML {*
43bd70786f9f More equivp infrastructure.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1209
diff changeset
   280
fun reflp_tac induct inj =
43bd70786f9f More equivp infrastructure.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1209
diff changeset
   281
  rtac induct THEN_ALL_NEW
43bd70786f9f More equivp infrastructure.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1209
diff changeset
   282
  asm_full_simp_tac (HOL_ss addsimps inj) THEN_ALL_NEW
43bd70786f9f More equivp infrastructure.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1209
diff changeset
   283
  TRY o REPEAT_ALL_NEW (CHANGED o rtac @{thm conjI}) THEN_ALL_NEW
43bd70786f9f More equivp infrastructure.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1209
diff changeset
   284
  (rtac @{thm exI[of _ "0 :: perm"]} THEN'
43bd70786f9f More equivp infrastructure.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1209
diff changeset
   285
   asm_full_simp_tac (HOL_ss addsimps
43bd70786f9f More equivp infrastructure.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1209
diff changeset
   286
     @{thms alpha_gen fresh_star_def fresh_zero_perm permute_zero ball_triv}))
43bd70786f9f More equivp infrastructure.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1209
diff changeset
   287
*}
43bd70786f9f More equivp infrastructure.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1209
diff changeset
   288
43bd70786f9f More equivp infrastructure.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1209
diff changeset
   289
ML {*
43bd70786f9f More equivp infrastructure.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1209
diff changeset
   290
fun symp_tac induct inj eqvt =
1215
aec9576b3950 Testing auto equivp code.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1214
diff changeset
   291
  ((rtac @{thm impI} THEN' etac induct) ORELSE' rtac induct) THEN_ALL_NEW
1213
43bd70786f9f More equivp infrastructure.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1209
diff changeset
   292
  asm_full_simp_tac (HOL_ss addsimps inj) THEN_ALL_NEW
43bd70786f9f More equivp infrastructure.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1209
diff changeset
   293
  TRY o REPEAT_ALL_NEW (CHANGED o rtac @{thm conjI}) THEN_ALL_NEW
43bd70786f9f More equivp infrastructure.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1209
diff changeset
   294
  (etac @{thm alpha_gen_compose_sym} THEN' eresolve_tac eqvt)
43bd70786f9f More equivp infrastructure.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1209
diff changeset
   295
*}
43bd70786f9f More equivp infrastructure.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1209
diff changeset
   296
43bd70786f9f More equivp infrastructure.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1209
diff changeset
   297
ML {*
1217
74e2b9b95add Fixes for auxiliary datatypes.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1216
diff changeset
   298
fun imp_elim_tac case_rules =
74e2b9b95add Fixes for auxiliary datatypes.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1216
diff changeset
   299
  Subgoal.FOCUS (fn {concl, context, ...} =>
74e2b9b95add Fixes for auxiliary datatypes.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1216
diff changeset
   300
    case term_of concl of
74e2b9b95add Fixes for auxiliary datatypes.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1216
diff changeset
   301
      _ $ (_ $ asm $ _) =>
74e2b9b95add Fixes for auxiliary datatypes.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1216
diff changeset
   302
        let
74e2b9b95add Fixes for auxiliary datatypes.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1216
diff changeset
   303
          fun filter_fn case_rule = (
74e2b9b95add Fixes for auxiliary datatypes.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1216
diff changeset
   304
            case Logic.strip_assums_hyp (prop_of case_rule) of
74e2b9b95add Fixes for auxiliary datatypes.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1216
diff changeset
   305
              ((_ $ asmc) :: _) =>
74e2b9b95add Fixes for auxiliary datatypes.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1216
diff changeset
   306
                let
74e2b9b95add Fixes for auxiliary datatypes.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1216
diff changeset
   307
                  val thy = ProofContext.theory_of context
74e2b9b95add Fixes for auxiliary datatypes.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1216
diff changeset
   308
                in
74e2b9b95add Fixes for auxiliary datatypes.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1216
diff changeset
   309
                  Pattern.matches thy (asmc, asm)
74e2b9b95add Fixes for auxiliary datatypes.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1216
diff changeset
   310
                end
74e2b9b95add Fixes for auxiliary datatypes.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1216
diff changeset
   311
            | _ => false)
74e2b9b95add Fixes for auxiliary datatypes.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1216
diff changeset
   312
          val matching_rules = filter filter_fn case_rules
74e2b9b95add Fixes for auxiliary datatypes.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1216
diff changeset
   313
        in
74e2b9b95add Fixes for auxiliary datatypes.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1216
diff changeset
   314
         (rtac impI THEN' rotate_tac (~1) THEN' eresolve_tac matching_rules) 1
74e2b9b95add Fixes for auxiliary datatypes.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1216
diff changeset
   315
        end
74e2b9b95add Fixes for auxiliary datatypes.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1216
diff changeset
   316
    | _ => no_tac
74e2b9b95add Fixes for auxiliary datatypes.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1216
diff changeset
   317
  )
74e2b9b95add Fixes for auxiliary datatypes.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1216
diff changeset
   318
*}
74e2b9b95add Fixes for auxiliary datatypes.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1216
diff changeset
   319
74e2b9b95add Fixes for auxiliary datatypes.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1216
diff changeset
   320
ML {*
74e2b9b95add Fixes for auxiliary datatypes.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1216
diff changeset
   321
fun transp_tac ctxt induct alpha_inj term_inj distinct cases eqvt =
74e2b9b95add Fixes for auxiliary datatypes.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1216
diff changeset
   322
  ((rtac impI THEN' etac induct) ORELSE' rtac induct) THEN_ALL_NEW
74e2b9b95add Fixes for auxiliary datatypes.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1216
diff changeset
   323
  (TRY o rtac allI THEN' imp_elim_tac cases ctxt) THEN_ALL_NEW
1213
43bd70786f9f More equivp infrastructure.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1209
diff changeset
   324
  (
43bd70786f9f More equivp infrastructure.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1209
diff changeset
   325
    asm_full_simp_tac (HOL_ss addsimps alpha_inj @ term_inj @ distinct) THEN'
43bd70786f9f More equivp infrastructure.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1209
diff changeset
   326
    TRY o REPEAT_ALL_NEW (CHANGED o rtac @{thm conjI}) THEN_ALL_NEW
43bd70786f9f More equivp infrastructure.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1209
diff changeset
   327
    (etac @{thm alpha_gen_compose_trans} THEN' RANGE [atac, eresolve_tac eqvt])
43bd70786f9f More equivp infrastructure.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1209
diff changeset
   328
  )
43bd70786f9f More equivp infrastructure.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1209
diff changeset
   329
*}
43bd70786f9f More equivp infrastructure.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1209
diff changeset
   330
1215
aec9576b3950 Testing auto equivp code.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1214
diff changeset
   331
lemma transp_aux:
aec9576b3950 Testing auto equivp code.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1214
diff changeset
   332
  "(\<And>xa ya. R xa ya \<longrightarrow> (\<forall>z. R ya z \<longrightarrow> R xa z)) \<Longrightarrow> transp R"
aec9576b3950 Testing auto equivp code.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1214
diff changeset
   333
  unfolding transp_def
aec9576b3950 Testing auto equivp code.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1214
diff changeset
   334
  by blast
aec9576b3950 Testing auto equivp code.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1214
diff changeset
   335
aec9576b3950 Testing auto equivp code.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1214
diff changeset
   336
ML {*
aec9576b3950 Testing auto equivp code.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1214
diff changeset
   337
fun equivp_tac reflps symps transps =
aec9576b3950 Testing auto equivp code.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1214
diff changeset
   338
  simp_tac (HOL_ss addsimps @{thms equivp_reflp_symp_transp reflp_def symp_def})
aec9576b3950 Testing auto equivp code.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1214
diff changeset
   339
  THEN' rtac @{thm conjI} THEN' rtac @{thm allI} THEN'
aec9576b3950 Testing auto equivp code.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1214
diff changeset
   340
  resolve_tac reflps THEN'
aec9576b3950 Testing auto equivp code.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1214
diff changeset
   341
  rtac @{thm conjI} THEN' rtac @{thm allI} THEN' rtac @{thm allI} THEN'
aec9576b3950 Testing auto equivp code.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1214
diff changeset
   342
  resolve_tac symps THEN'
aec9576b3950 Testing auto equivp code.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1214
diff changeset
   343
  rtac @{thm transp_aux} THEN' resolve_tac transps
aec9576b3950 Testing auto equivp code.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1214
diff changeset
   344
*}
aec9576b3950 Testing auto equivp code.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1214
diff changeset
   345
1213
43bd70786f9f More equivp infrastructure.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1209
diff changeset
   346
ML {*
1214
0f92257edeee A tactic for final equivp
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1213
diff changeset
   347
fun build_equivps alphas term_induct alpha_induct term_inj alpha_inj distinct cases eqvt ctxt =
1213
43bd70786f9f More equivp infrastructure.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1209
diff changeset
   348
let
1214
0f92257edeee A tactic for final equivp
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1213
diff changeset
   349
  val ([x, y, z], ctxt') = Variable.variant_fixes ["x","y","z"] ctxt;
0f92257edeee A tactic for final equivp
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1213
diff changeset
   350
  val (reflg, (symg, transg)) = build_alpha_refl_gl alphas (x, y, z)
0f92257edeee A tactic for final equivp
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1213
diff changeset
   351
  fun reflp_tac' _ = reflp_tac term_induct alpha_inj 1;
0f92257edeee A tactic for final equivp
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1213
diff changeset
   352
  fun symp_tac' _ = symp_tac alpha_induct alpha_inj eqvt 1;
1217
74e2b9b95add Fixes for auxiliary datatypes.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1216
diff changeset
   353
  fun transp_tac' _ = transp_tac ctxt alpha_induct alpha_inj term_inj distinct cases eqvt 1;
1214
0f92257edeee A tactic for final equivp
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1213
diff changeset
   354
  val reflt = Goal.prove ctxt' [] [] reflg reflp_tac';
0f92257edeee A tactic for final equivp
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1213
diff changeset
   355
  val symt = Goal.prove ctxt' [] [] symg symp_tac';
0f92257edeee A tactic for final equivp
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1213
diff changeset
   356
  val transt = Goal.prove ctxt' [] [] transg transp_tac';
0f92257edeee A tactic for final equivp
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1213
diff changeset
   357
  val [refltg, symtg, transtg] = Variable.export ctxt' ctxt [reflt, symt, transt]
1215
aec9576b3950 Testing auto equivp code.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1214
diff changeset
   358
  val reflts = HOLogic.conj_elims refltg
aec9576b3950 Testing auto equivp code.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1214
diff changeset
   359
  val symts = HOLogic.conj_elims symtg
aec9576b3950 Testing auto equivp code.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1214
diff changeset
   360
  val transts = HOLogic.conj_elims transtg
1214
0f92257edeee A tactic for final equivp
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1213
diff changeset
   361
  fun equivp alpha =
0f92257edeee A tactic for final equivp
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1213
diff changeset
   362
    let
1215
aec9576b3950 Testing auto equivp code.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1214
diff changeset
   363
      val equivp = Const (@{const_name equivp}, fastype_of alpha --> @{typ bool})
aec9576b3950 Testing auto equivp code.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1214
diff changeset
   364
      val goal = @{term Trueprop} $ (equivp $ alpha)
aec9576b3950 Testing auto equivp code.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1214
diff changeset
   365
      fun tac _ = equivp_tac reflts symts transts 1
aec9576b3950 Testing auto equivp code.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1214
diff changeset
   366
    in
aec9576b3950 Testing auto equivp code.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1214
diff changeset
   367
      Goal.prove ctxt [] [] goal tac
aec9576b3950 Testing auto equivp code.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1214
diff changeset
   368
    end
1213
43bd70786f9f More equivp infrastructure.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1209
diff changeset
   369
in
1215
aec9576b3950 Testing auto equivp code.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1214
diff changeset
   370
  map equivp alphas
1213
43bd70786f9f More equivp infrastructure.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1209
diff changeset
   371
end
43bd70786f9f More equivp infrastructure.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1209
diff changeset
   372
*}
1207
fb33684e4ece alpha reflexivity
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1206
diff changeset
   373
1217
74e2b9b95add Fixes for auxiliary datatypes.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1216
diff changeset
   374
(*
74e2b9b95add Fixes for auxiliary datatypes.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1216
diff changeset
   375
Tests:
74e2b9b95add Fixes for auxiliary datatypes.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1216
diff changeset
   376
prove alpha1_reflp_aux: {* fst (build_alpha_refl_gl [@{term alpha_rtrm1}, @{term alpha_bp}] ("x","y","z")) *}
74e2b9b95add Fixes for auxiliary datatypes.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1216
diff changeset
   377
by (tactic {* reflp_tac @{thm rtrm1_bp.induct} @{thms alpha1_inj} 1 *})
74e2b9b95add Fixes for auxiliary datatypes.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1216
diff changeset
   378
74e2b9b95add Fixes for auxiliary datatypes.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1216
diff changeset
   379
prove alpha1_symp_aux: {* (fst o snd) (build_alpha_refl_gl [@{term alpha_rtrm1}, @{term alpha_bp}] ("x","y","z")) *}
74e2b9b95add Fixes for auxiliary datatypes.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1216
diff changeset
   380
by (tactic {* symp_tac @{thm alpha_rtrm1_alpha_bp.induct} @{thms alpha1_inj} @{thms alpha1_eqvt} 1 *})
74e2b9b95add Fixes for auxiliary datatypes.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1216
diff changeset
   381
74e2b9b95add Fixes for auxiliary datatypes.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1216
diff changeset
   382
prove alpha1_transp_aux: {* (snd o snd) (build_alpha_refl_gl [@{term alpha_rtrm1}, @{term alpha_bp}] ("x","y","z")) *}
74e2b9b95add Fixes for auxiliary datatypes.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1216
diff changeset
   383
by (tactic {* transp_tac @{context} @{thm alpha_rtrm1_alpha_bp.induct} @{thms alpha1_inj} @{thms rtrm1.inject bp.inject} @{thms rtrm1.distinct bp.distinct} @{thms alpha_rtrm1.cases alpha_bp.cases} @{thms alpha1_eqvt} 1 *})
74e2b9b95add Fixes for auxiliary datatypes.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1216
diff changeset
   384
74e2b9b95add Fixes for auxiliary datatypes.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1216
diff changeset
   385
lemma alpha1_equivp:
74e2b9b95add Fixes for auxiliary datatypes.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1216
diff changeset
   386
  "equivp alpha_rtrm1"
74e2b9b95add Fixes for auxiliary datatypes.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1216
diff changeset
   387
  "equivp alpha_bp"
74e2b9b95add Fixes for auxiliary datatypes.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1216
diff changeset
   388
apply (tactic {*
74e2b9b95add Fixes for auxiliary datatypes.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1216
diff changeset
   389
  (simp_tac (HOL_ss addsimps @{thms equivp_reflp_symp_transp reflp_def symp_def})
74e2b9b95add Fixes for auxiliary datatypes.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1216
diff changeset
   390
  THEN' rtac @{thm conjI} THEN' rtac @{thm allI} THEN'
74e2b9b95add Fixes for auxiliary datatypes.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1216
diff changeset
   391
  resolve_tac (HOLogic.conj_elims @{thm alpha1_reflp_aux})
74e2b9b95add Fixes for auxiliary datatypes.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1216
diff changeset
   392
  THEN' rtac @{thm conjI} THEN' rtac @{thm allI} THEN' rtac @{thm allI} THEN'
74e2b9b95add Fixes for auxiliary datatypes.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1216
diff changeset
   393
  resolve_tac (HOLogic.conj_elims @{thm alpha1_symp_aux}) THEN' rtac @{thm transp_aux}
74e2b9b95add Fixes for auxiliary datatypes.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1216
diff changeset
   394
  THEN' resolve_tac (HOLogic.conj_elims @{thm alpha1_transp_aux})
74e2b9b95add Fixes for auxiliary datatypes.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1216
diff changeset
   395
)
74e2b9b95add Fixes for auxiliary datatypes.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1216
diff changeset
   396
1 *})
74e2b9b95add Fixes for auxiliary datatypes.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1216
diff changeset
   397
done*)
74e2b9b95add Fixes for auxiliary datatypes.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1216
diff changeset
   398
1207
fb33684e4ece alpha reflexivity
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1206
diff changeset
   399
end