Nominal/Fv.thy
author Cezary Kaliszyk <kaliszyk@in.tum.de>
Thu, 25 Mar 2010 17:30:46 +0100
changeset 1650 4b949985cf57
parent 1625 6ad74d73e1b1
child 1651 f731e9aff866
permissions -rw-r--r--
Gathering things to prove by induction together; removed cheat_bn_eqvt.
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
1534
984ea1299cd7 The nominal infrastructure for fset. 'fs' missing, but not needed so far.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1516
diff changeset
     2
imports "Nominal2_Atoms" "Abs" "Perm" "Rsp" "Nominal2_FSet"
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
1505
e12ebfa745f6 Update the description of the generation of fv function.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1498
diff changeset
     5
(* The bindings data structure:
e12ebfa745f6 Update the description of the generation of fv function.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1498
diff changeset
     6
e12ebfa745f6 Update the description of the generation of fv function.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1498
diff changeset
     7
  Bindings are a list of lists of lists of triples.
1172
9a609fefcf24 Simplified format of bindings.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1169
diff changeset
     8
1358
0c843fcb1d7b Update the comments
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1357
diff changeset
     9
   The first list represents the datatypes defined.
0c843fcb1d7b Update the comments
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1357
diff changeset
    10
   The second list represents the constructors.
0c843fcb1d7b Update the comments
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1357
diff changeset
    11
   The internal list is a list of all the bndings that
0c843fcb1d7b Update the comments
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1357
diff changeset
    12
   concern the constructor.
1172
9a609fefcf24 Simplified format of bindings.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1169
diff changeset
    13
1358
0c843fcb1d7b Update the comments
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1357
diff changeset
    14
   Every triple consists of a function, the binding and
0c843fcb1d7b Update the comments
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1357
diff changeset
    15
   the body.
1169
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
  Eg:
b9d02e0800e9 Description of intended bindings.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1168
diff changeset
    18
nominal_datatype
b9d02e0800e9 Description of intended bindings.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1168
diff changeset
    19
b9d02e0800e9 Description of intended bindings.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1168
diff changeset
    20
   C1
b9d02e0800e9 Description of intended bindings.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1168
diff changeset
    21
 | C2 x y z bind x in z
1172
9a609fefcf24 Simplified format of bindings.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1169
diff changeset
    22
 | 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
    23
b9d02e0800e9 Description of intended bindings.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1168
diff changeset
    24
yields:
1172
9a609fefcf24 Simplified format of bindings.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1169
diff changeset
    25
[
9a609fefcf24 Simplified format of bindings.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1169
diff changeset
    26
 [],
1358
0c843fcb1d7b Update the comments
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1357
diff changeset
    27
 [(NONE, 0, 2)],
0c843fcb1d7b Update the comments
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1357
diff changeset
    28
 [(SOME (Const f), 0, 2), (Some (Const g), 1, 2)]]
1185
7566b899ca6a Code for handling atom sets.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1180
diff changeset
    29
1358
0c843fcb1d7b Update the comments
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1357
diff changeset
    30
A SOME binding has to have a function which takes an appropriate
0c843fcb1d7b Update the comments
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1357
diff changeset
    31
argument and returns an atom set. A NONE binding has to be on an
0c843fcb1d7b Update the comments
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1357
diff changeset
    32
argument that is an atom or an atom set.
1505
e12ebfa745f6 Update the description of the generation of fv function.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1498
diff changeset
    33
*)
1185
7566b899ca6a Code for handling atom sets.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1180
diff changeset
    34
1505
e12ebfa745f6 Update the description of the generation of fv function.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1498
diff changeset
    35
(*
1510
be911e869fde Added fv,bn,distinct,perm to the simplifier.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1508
diff changeset
    36
An overview of the generation of free variables:
1505
e12ebfa745f6 Update the description of the generation of fv function.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1498
diff changeset
    37
e12ebfa745f6 Update the description of the generation of fv function.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1498
diff changeset
    38
1) fv_bn functions are generated only for the non-recursive binds.
e12ebfa745f6 Update the description of the generation of fv function.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1498
diff changeset
    39
e12ebfa745f6 Update the description of the generation of fv function.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1498
diff changeset
    40
   An fv_bn for a constructor is a union of values for the arguments:
1191
15362b433d64 Description of the fv procedure.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1185
diff changeset
    41
1505
e12ebfa745f6 Update the description of the generation of fv function.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1498
diff changeset
    42
   For an argument x that is in the bn function
e12ebfa745f6 Update the description of the generation of fv function.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1498
diff changeset
    43
   - if it is a recursive argument bn' we return: fv_bn' x
e12ebfa745f6 Update the description of the generation of fv function.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1498
diff changeset
    44
   - otherwise empty
e12ebfa745f6 Update the description of the generation of fv function.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1498
diff changeset
    45
e12ebfa745f6 Update the description of the generation of fv function.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1498
diff changeset
    46
   For an argument x that is not in the bn function
e12ebfa745f6 Update the description of the generation of fv function.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1498
diff changeset
    47
   - for atom we return: {atom x}
e12ebfa745f6 Update the description of the generation of fv function.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1498
diff changeset
    48
   - for atom set we return: atom ` x
e12ebfa745f6 Update the description of the generation of fv function.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1498
diff changeset
    49
   - for a recursive call to type ty' we return: fv_ty' x
e12ebfa745f6 Update the description of the generation of fv function.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1498
diff changeset
    50
     with fv of the appropriate type
e12ebfa745f6 Update the description of the generation of fv function.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1498
diff changeset
    51
   - otherwise empty
e12ebfa745f6 Update the description of the generation of fv function.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1498
diff changeset
    52
1514
b52b72676e20 First part of the description of alpha_ty.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1513
diff changeset
    53
2) fv_ty functions generated for all types being defined:
1191
15362b433d64 Description of the fv procedure.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1185
diff changeset
    54
1514
b52b72676e20 First part of the description of alpha_ty.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1513
diff changeset
    55
   fv_ty for a constructor is a union of values for the arguments.
1505
e12ebfa745f6 Update the description of the generation of fv function.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1498
diff changeset
    56
1508
883b38196dba Simplified the description.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1505
diff changeset
    57
   For an argument that is bound in a shallow binding we return empty.
883b38196dba Simplified the description.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1505
diff changeset
    58
883b38196dba Simplified the description.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1505
diff changeset
    59
   For an argument x that bound in a non-recursive deep binding
1505
e12ebfa745f6 Update the description of the generation of fv function.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1498
diff changeset
    60
   we return: fv_bn x.
e12ebfa745f6 Update the description of the generation of fv function.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1498
diff changeset
    61
e12ebfa745f6 Update the description of the generation of fv function.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1498
diff changeset
    62
   Otherwise we return the free variables of the argument minus the
e12ebfa745f6 Update the description of the generation of fv function.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1498
diff changeset
    63
   bound variables of the argument.
1358
0c843fcb1d7b Update the comments
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1357
diff changeset
    64
1505
e12ebfa745f6 Update the description of the generation of fv function.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1498
diff changeset
    65
   The free variables for an argument x are:
e12ebfa745f6 Update the description of the generation of fv function.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1498
diff changeset
    66
   - for an atom: {atom x}
e12ebfa745f6 Update the description of the generation of fv function.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1498
diff changeset
    67
   - for atom set: atom ` x
e12ebfa745f6 Update the description of the generation of fv function.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1498
diff changeset
    68
   - for recursive call to type ty' return: fv_ty' x
e12ebfa745f6 Update the description of the generation of fv function.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1498
diff changeset
    69
   - for nominal datatype ty' return: fv_ty' x
e12ebfa745f6 Update the description of the generation of fv function.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1498
diff changeset
    70
e12ebfa745f6 Update the description of the generation of fv function.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1498
diff changeset
    71
   The bound variables are a union of results of all bindings that
e12ebfa745f6 Update the description of the generation of fv function.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1498
diff changeset
    72
   involve the given argument. For a paricular binding:
e12ebfa745f6 Update the description of the generation of fv function.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1498
diff changeset
    73
e12ebfa745f6 Update the description of the generation of fv function.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1498
diff changeset
    74
   - for a binding function bn: bn x
e12ebfa745f6 Update the description of the generation of fv function.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1498
diff changeset
    75
   - for a recursive argument of type ty': fv_fy' x
e12ebfa745f6 Update the description of the generation of fv function.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1498
diff changeset
    76
   - for nominal datatype ty' return: fv_ty' x
1169
b9d02e0800e9 Description of intended bindings.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1168
diff changeset
    77
*)
b9d02e0800e9 Description of intended bindings.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1168
diff changeset
    78
1510
be911e869fde Added fv,bn,distinct,perm to the simplifier.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1508
diff changeset
    79
(*
be911e869fde Added fv,bn,distinct,perm to the simplifier.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1508
diff changeset
    80
An overview of the generation of alpha-equivalence:
1513
44840614ea0c Description of generation of alpha_bn.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1510
diff changeset
    81
44840614ea0c Description of generation of alpha_bn.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1510
diff changeset
    82
1) alpha_bn relations are generated for binding functions.
44840614ea0c Description of generation of alpha_bn.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1510
diff changeset
    83
44840614ea0c Description of generation of alpha_bn.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1510
diff changeset
    84
   An alpha_bn for a constructor is true if a conjunction of
44840614ea0c Description of generation of alpha_bn.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1510
diff changeset
    85
   propositions for each argument holds.
44840614ea0c Description of generation of alpha_bn.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1510
diff changeset
    86
44840614ea0c Description of generation of alpha_bn.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1510
diff changeset
    87
   For an argument a proposition is build as follows from
44840614ea0c Description of generation of alpha_bn.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1510
diff changeset
    88
   th:
44840614ea0c Description of generation of alpha_bn.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1510
diff changeset
    89
44840614ea0c Description of generation of alpha_bn.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1510
diff changeset
    90
   - for a recursive argument in the bn function, we return: alpha_bn argl argr
44840614ea0c Description of generation of alpha_bn.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1510
diff changeset
    91
   - for a recursive argument for type ty not in bn, we return: alpha_ty argl argr
44840614ea0c Description of generation of alpha_bn.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1510
diff changeset
    92
   - for other arguments in the bn function we return: True
44840614ea0c Description of generation of alpha_bn.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1510
diff changeset
    93
   - for other arguments not in the bn function we return: argl = argr
44840614ea0c Description of generation of alpha_bn.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1510
diff changeset
    94
1514
b52b72676e20 First part of the description of alpha_ty.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1513
diff changeset
    95
2) alpha_ty relations are generated for all the types being defined:
b52b72676e20 First part of the description of alpha_ty.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1513
diff changeset
    96
1516
e3a82a3529ce Continued description of alpha.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1514
diff changeset
    97
   For each constructor we gather all the arguments that are bound,
e3a82a3529ce Continued description of alpha.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1514
diff changeset
    98
   and for each of those we add a permutation. We associate those
e3a82a3529ce Continued description of alpha.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1514
diff changeset
    99
   permutations with the bindings. Note that two bindings can have
e3a82a3529ce Continued description of alpha.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1514
diff changeset
   100
   the same permutation if the arguments being bound are the same.
1514
b52b72676e20 First part of the description of alpha_ty.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1513
diff changeset
   101
1516
e3a82a3529ce Continued description of alpha.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1514
diff changeset
   102
   An alpha_ty for a constructor is true if there exist permutations
e3a82a3529ce Continued description of alpha.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1514
diff changeset
   103
   as above such that a conjunction of propositions for all arguments holds.
1514
b52b72676e20 First part of the description of alpha_ty.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1513
diff changeset
   104
b52b72676e20 First part of the description of alpha_ty.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1513
diff changeset
   105
   For an argument we allow bindings where only one of the following
b52b72676e20 First part of the description of alpha_ty.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1513
diff changeset
   106
   holds:
b52b72676e20 First part of the description of alpha_ty.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1513
diff changeset
   107
b52b72676e20 First part of the description of alpha_ty.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1513
diff changeset
   108
   - Argument is bound in some shallow bindings: We return true
1516
e3a82a3529ce Continued description of alpha.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1514
diff changeset
   109
   - Argument of type ty is bound recursively in some other
e3a82a3529ce Continued description of alpha.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1514
diff changeset
   110
     arguments [i1, .. in] with one binding function bn.
e3a82a3529ce Continued description of alpha.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1514
diff changeset
   111
     We return:
e3a82a3529ce Continued description of alpha.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1514
diff changeset
   112
e3a82a3529ce Continued description of alpha.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1514
diff changeset
   113
     (bn argl, (argl, argl_i1, ..., argl_in)) \<approx>gen
e3a82a3529ce Continued description of alpha.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1514
diff changeset
   114
     \<lambda>(argl,argl1,..,argln) (argr,argr1,..,argrn). 
e3a82a3529ce Continued description of alpha.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1514
diff changeset
   115
         (alpha_ty argl argr) \<and> (alpha_i1 argl1 argr1) \<and> .. \<and> (alpha_in argln argrn)
e3a82a3529ce Continued description of alpha.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1514
diff changeset
   116
     \<lambda>(arg,arg1,..,argn). (fv_ty arg) \<union> (fv_i1 arg1) \<union> .. \<union> (fv_in argn)
e3a82a3529ce Continued description of alpha.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1514
diff changeset
   117
     pi
e3a82a3529ce Continued description of alpha.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1514
diff changeset
   118
     (bn argr, (argr, argr_i1, ..., argr_in))
e3a82a3529ce Continued description of alpha.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1514
diff changeset
   119
1514
b52b72676e20 First part of the description of alpha_ty.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1513
diff changeset
   120
   - Argument is bound in some deep non-recursive bindings.
b52b72676e20 First part of the description of alpha_ty.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1513
diff changeset
   121
     We return: alpha_bn argl argr
1516
e3a82a3529ce Continued description of alpha.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1514
diff changeset
   122
   - Argument of type ty has some shallow bindings [b1..bn] and/or
e3a82a3529ce Continued description of alpha.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1514
diff changeset
   123
     non-recursive bindings [f1 a1, .., fm am], where the bindings
e3a82a3529ce Continued description of alpha.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1514
diff changeset
   124
     have the permutations p1..pl. We return:
e3a82a3529ce Continued description of alpha.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1514
diff changeset
   125
e3a82a3529ce Continued description of alpha.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1514
diff changeset
   126
     (b1l \<union>..\<union> bnl \<union> f1 a1l \<union>..\<union> fn anl, argl) \<approx>gen
e3a82a3529ce Continued description of alpha.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1514
diff changeset
   127
     alpha_ty fv_ty (p1 +..+ pl)
e3a82a3529ce Continued description of alpha.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1514
diff changeset
   128
     (b1r \<union>..\<union> bnr \<union> f1 a1r \<union>..\<union> fn anr, argr)
e3a82a3529ce Continued description of alpha.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1514
diff changeset
   129
1514
b52b72676e20 First part of the description of alpha_ty.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1513
diff changeset
   130
   - Argument has some recursive bindings. The bindings were
b52b72676e20 First part of the description of alpha_ty.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1513
diff changeset
   131
     already treated in 2nd case so we return: True
b52b72676e20 First part of the description of alpha_ty.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1513
diff changeset
   132
   - Argument has no bindings and is not bound.
b52b72676e20 First part of the description of alpha_ty.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1513
diff changeset
   133
     If it is recursive for type ty, we return: alpha_ty argl argr
b52b72676e20 First part of the description of alpha_ty.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1513
diff changeset
   134
     Otherwise we return: argl = argr
b52b72676e20 First part of the description of alpha_ty.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1513
diff changeset
   135
1510
be911e869fde Added fv,bn,distinct,perm to the simplifier.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1508
diff changeset
   136
*)
be911e869fde Added fv,bn,distinct,perm to the simplifier.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1508
diff changeset
   137
1362
e72d9d9eada3 Term5 written as nominal_datatype is the recursive let.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1359
diff changeset
   138
ML {*
e72d9d9eada3 Term5 written as nominal_datatype is the recursive let.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1359
diff changeset
   139
fun is_atom thy typ =
e72d9d9eada3 Term5 written as nominal_datatype is the recursive let.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1359
diff changeset
   140
  Sign.of_sort thy (typ, @{sort at})
1366
2bf82fa871e7 Proper recognition of atoms and atom sets.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1362
diff changeset
   141
2bf82fa871e7 Proper recognition of atoms and atom sets.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1362
diff changeset
   142
fun is_atom_set thy (Type ("fun", [t, @{typ bool}])) = is_atom thy t
2bf82fa871e7 Proper recognition of atoms and atom sets.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1362
diff changeset
   143
  | is_atom_set thy _ = false;
1534
984ea1299cd7 The nominal infrastructure for fset. 'fs' missing, but not needed so far.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1516
diff changeset
   144
984ea1299cd7 The nominal infrastructure for fset. 'fs' missing, but not needed so far.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1516
diff changeset
   145
fun is_atom_fset thy (Type ("FSet.fset", [t])) = is_atom thy t
984ea1299cd7 The nominal infrastructure for fset. 'fs' missing, but not needed so far.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1516
diff changeset
   146
  | is_atom_fset thy _ = false;
984ea1299cd7 The nominal infrastructure for fset. 'fs' missing, but not needed so far.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1516
diff changeset
   147
984ea1299cd7 The nominal infrastructure for fset. 'fs' missing, but not needed so far.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1516
diff changeset
   148
val fset_to_set = @{term "fset_to_set :: atom fset \<Rightarrow> atom set"}
1362
e72d9d9eada3 Term5 written as nominal_datatype is the recursive let.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1359
diff changeset
   149
*}
e72d9d9eada3 Term5 written as nominal_datatype is the recursive let.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1359
diff changeset
   150
e72d9d9eada3 Term5 written as nominal_datatype is the recursive let.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1359
diff changeset
   151
1366
2bf82fa871e7 Proper recognition of atoms and atom sets.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1362
diff changeset
   152
1534
984ea1299cd7 The nominal infrastructure for fset. 'fs' missing, but not needed so far.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1516
diff changeset
   153
1358
0c843fcb1d7b Update the comments
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1357
diff changeset
   154
(* Like map2, only if the second list is empty passes empty lists insted of error *)
1302
d3101a5b9c4d Length fix for nested recursions.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1301
diff changeset
   155
ML {*
d3101a5b9c4d Length fix for nested recursions.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1301
diff changeset
   156
fun map2i _ [] [] = []
d3101a5b9c4d Length fix for nested recursions.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1301
diff changeset
   157
  | map2i f (x :: xs) (y :: ys) = f x y :: map2i f xs ys
d3101a5b9c4d Length fix for nested recursions.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1301
diff changeset
   158
  | map2i f (x :: xs) [] = f x [] :: map2i f xs []
d3101a5b9c4d Length fix for nested recursions.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1301
diff changeset
   159
  | map2i _ _ _ = raise UnequalLengths;
d3101a5b9c4d Length fix for nested recursions.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1301
diff changeset
   160
*}
d3101a5b9c4d Length fix for nested recursions.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1301
diff changeset
   161
1358
0c843fcb1d7b Update the comments
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1357
diff changeset
   162
(* Finds bindings with the same function and binding, and gathers all
1375
aa787c9b6955 A version of Fv that takes into account recursive and non-recursive bindings.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1366
diff changeset
   163
   bodys for such pairs
aa787c9b6955 A version of Fv that takes into account recursive and non-recursive bindings.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1366
diff changeset
   164
 *)
1168
5c1e16806901 Code for generating the fv function, no bindings yet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   165
ML {*
1357
42b7abf779ec Gather bindings with same binder, and generate only one permutation for them.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1339
diff changeset
   166
fun gather_binds binds =
42b7abf779ec Gather bindings with same binder, and generate only one permutation for them.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1339
diff changeset
   167
let
42b7abf779ec Gather bindings with same binder, and generate only one permutation for them.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1339
diff changeset
   168
  fun gather_binds_cons binds =
42b7abf779ec Gather bindings with same binder, and generate only one permutation for them.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1339
diff changeset
   169
    let
42b7abf779ec Gather bindings with same binder, and generate only one permutation for them.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1339
diff changeset
   170
      val common = map (fn (f, bi, _) => (f, bi)) binds
42b7abf779ec Gather bindings with same binder, and generate only one permutation for them.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1339
diff changeset
   171
      val nodups = distinct (op =) common
42b7abf779ec Gather bindings with same binder, and generate only one permutation for them.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1339
diff changeset
   172
      fun find_bodys (sf, sbi) =
42b7abf779ec Gather bindings with same binder, and generate only one permutation for them.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1339
diff changeset
   173
        filter (fn (f, bi, _) => f = sf andalso bi = sbi) binds
42b7abf779ec Gather bindings with same binder, and generate only one permutation for them.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1339
diff changeset
   174
      val bodys = map ((map (fn (_, _, bo) => bo)) o find_bodys) nodups
42b7abf779ec Gather bindings with same binder, and generate only one permutation for them.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1339
diff changeset
   175
    in
42b7abf779ec Gather bindings with same binder, and generate only one permutation for them.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1339
diff changeset
   176
      nodups ~~ bodys
42b7abf779ec Gather bindings with same binder, and generate only one permutation for them.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1339
diff changeset
   177
    end
42b7abf779ec Gather bindings with same binder, and generate only one permutation for them.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1339
diff changeset
   178
in
42b7abf779ec Gather bindings with same binder, and generate only one permutation for them.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1339
diff changeset
   179
  map (map gather_binds_cons) binds
42b7abf779ec Gather bindings with same binder, and generate only one permutation for them.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1339
diff changeset
   180
end
42b7abf779ec Gather bindings with same binder, and generate only one permutation for them.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1339
diff changeset
   181
*}
42b7abf779ec Gather bindings with same binder, and generate only one permutation for them.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1339
diff changeset
   182
42b7abf779ec Gather bindings with same binder, and generate only one permutation for them.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1339
diff changeset
   183
ML {*
42b7abf779ec Gather bindings with same binder, and generate only one permutation for them.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1339
diff changeset
   184
fun un_gather_binds_cons binds =
42b7abf779ec Gather bindings with same binder, and generate only one permutation for them.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1339
diff changeset
   185
  flat (map (fn (((f, bi), bos), pi) => map (fn bo => ((f, bi, bo), pi)) bos) binds)
42b7abf779ec Gather bindings with same binder, and generate only one permutation for them.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1339
diff changeset
   186
*}
42b7abf779ec Gather bindings with same binder, and generate only one permutation for them.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1339
diff changeset
   187
42b7abf779ec Gather bindings with same binder, and generate only one permutation for them.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1339
diff changeset
   188
ML {*
1175
6a3be6ef348d Reorganization
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1174
diff changeset
   189
  open Datatype_Aux; (* typ_of_dtyp, DtRec, ... *);
1178
275a1cb3f2ba Reorder
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1177
diff changeset
   190
  (* TODO: It is the same as one in 'nominal_atoms' *)
1175
6a3be6ef348d Reorganization
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1174
diff changeset
   191
  fun mk_atom ty = Const (@{const_name atom}, ty --> @{typ atom});
6a3be6ef348d Reorganization
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1174
diff changeset
   192
  val noatoms = @{term "{} :: atom set"};
6a3be6ef348d Reorganization
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1174
diff changeset
   193
  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
   194
  fun mk_union sets =
6a3be6ef348d Reorganization
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1174
diff changeset
   195
    fold (fn a => fn b =>
6a3be6ef348d Reorganization
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1174
diff changeset
   196
      if a = noatoms then b else
6a3be6ef348d Reorganization
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1174
diff changeset
   197
      if b = noatoms then a else
1323
acf262971303 Fixes for the fv problem and alpha problem.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1308
diff changeset
   198
      if a = b then a else
1325
0be098c61d00 Add the supp intersection conditions.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1323
diff changeset
   199
      HOLogic.mk_binop @{const_name sup} (a, b)) (rev sets) noatoms;
0be098c61d00 Add the supp intersection conditions.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1323
diff changeset
   200
  val mk_inter = foldr1 (HOLogic.mk_binop @{const_name inf})
1288
0203cd5cfd6c The new alpha-equivalence and testing in Trm2 and Trm5.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1277
diff changeset
   201
  fun mk_conjl props =
0203cd5cfd6c The new alpha-equivalence and testing in Trm2 and Trm5.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1277
diff changeset
   202
    fold (fn a => fn b =>
0203cd5cfd6c The new alpha-equivalence and testing in Trm2 and Trm5.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1277
diff changeset
   203
      if a = @{term True} then b else
0203cd5cfd6c The new alpha-equivalence and testing in Trm2 and Trm5.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1277
diff changeset
   204
      if b = @{term True} then a else
1428
4029105011ca Show that the new types are in finite support typeclass.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1427
diff changeset
   205
      HOLogic.mk_conj (a, b)) (rev props) @{term True};
1175
6a3be6ef348d Reorganization
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1174
diff changeset
   206
  fun mk_diff a b =
6a3be6ef348d Reorganization
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1174
diff changeset
   207
    if b = noatoms then a else
6a3be6ef348d Reorganization
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1174
diff changeset
   208
    if b = a then noatoms else
6a3be6ef348d Reorganization
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1174
diff changeset
   209
    HOLogic.mk_binop @{const_name minus} (a, b);
1534
984ea1299cd7 The nominal infrastructure for fset. 'fs' missing, but not needed so far.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1516
diff changeset
   210
  fun mk_atom_set t =
1185
7566b899ca6a Code for handling atom sets.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1180
diff changeset
   211
    let
7566b899ca6a Code for handling atom sets.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1180
diff changeset
   212
      val ty = fastype_of t;
7566b899ca6a Code for handling atom sets.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1180
diff changeset
   213
      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
   214
      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
   215
    in
7566b899ca6a Code for handling atom sets.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1180
diff changeset
   216
      (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
   217
    end;
1534
984ea1299cd7 The nominal infrastructure for fset. 'fs' missing, but not needed so far.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1516
diff changeset
   218
  fun mk_atom_fset t =
984ea1299cd7 The nominal infrastructure for fset. 'fs' missing, but not needed so far.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1516
diff changeset
   219
    let
984ea1299cd7 The nominal infrastructure for fset. 'fs' missing, but not needed so far.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1516
diff changeset
   220
      val ty = fastype_of t;
984ea1299cd7 The nominal infrastructure for fset. 'fs' missing, but not needed so far.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1516
diff changeset
   221
      val atom_ty = dest_fsetT ty --> @{typ atom};
984ea1299cd7 The nominal infrastructure for fset. 'fs' missing, but not needed so far.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1516
diff changeset
   222
      val fmap_ty = atom_ty --> ty --> @{typ "atom fset"};
984ea1299cd7 The nominal infrastructure for fset. 'fs' missing, but not needed so far.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1516
diff changeset
   223
    in
984ea1299cd7 The nominal infrastructure for fset. 'fs' missing, but not needed so far.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1516
diff changeset
   224
      fset_to_set $ ((Const (@{const_name fmap}, fmap_ty) $ Const (@{const_name atom}, atom_ty) $ t))
984ea1299cd7 The nominal infrastructure for fset. 'fs' missing, but not needed so far.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1516
diff changeset
   225
    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
   226
  (* 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
   227
  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
   228
    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
   229
      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
   230
      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
   231
    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
   232
    end;
1468
416c9c5a1126 Generate compound FV and Alpha for recursive bindings.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1464
diff changeset
   233
*}
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
   234
1468
416c9c5a1126 Generate compound FV and Alpha for recursive bindings.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1464
diff changeset
   235
(* Given [fv1, fv2, fv3] creates %(x, y, z). fv1 x u fv2 y u fv3 z *)
416c9c5a1126 Generate compound FV and Alpha for recursive bindings.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1464
diff changeset
   236
ML {*
416c9c5a1126 Generate compound FV and Alpha for recursive bindings.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1464
diff changeset
   237
fun mk_compound_fv fvs =
416c9c5a1126 Generate compound FV and Alpha for recursive bindings.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1464
diff changeset
   238
let
416c9c5a1126 Generate compound FV and Alpha for recursive bindings.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1464
diff changeset
   239
  val nos = (length fvs - 1) downto 0;
416c9c5a1126 Generate compound FV and Alpha for recursive bindings.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1464
diff changeset
   240
  val fvs_applied = map (fn (fv, no) => fv $ Bound no) (fvs ~~ nos);
416c9c5a1126 Generate compound FV and Alpha for recursive bindings.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1464
diff changeset
   241
  val fvs_union = mk_union fvs_applied;
416c9c5a1126 Generate compound FV and Alpha for recursive bindings.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1464
diff changeset
   242
  val (tyh :: tys) = rev (map (domain_type o fastype_of) fvs);
416c9c5a1126 Generate compound FV and Alpha for recursive bindings.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1464
diff changeset
   243
  fun fold_fun ty t = HOLogic.mk_split (Abs ("", ty, t))
416c9c5a1126 Generate compound FV and Alpha for recursive bindings.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1464
diff changeset
   244
in
416c9c5a1126 Generate compound FV and Alpha for recursive bindings.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1464
diff changeset
   245
  fold fold_fun tys (Abs ("", tyh, fvs_union))
416c9c5a1126 Generate compound FV and Alpha for recursive bindings.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1464
diff changeset
   246
end;
1175
6a3be6ef348d Reorganization
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1174
diff changeset
   247
*}
6a3be6ef348d Reorganization
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1174
diff changeset
   248
1468
416c9c5a1126 Generate compound FV and Alpha for recursive bindings.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1464
diff changeset
   249
ML {* @{term "\<lambda>(x, y, z). \<lambda>(x', y', z'). R x x' \<and> R2 y y' \<and> R3 z z'"} *}
416c9c5a1126 Generate compound FV and Alpha for recursive bindings.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1464
diff changeset
   250
416c9c5a1126 Generate compound FV and Alpha for recursive bindings.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1464
diff changeset
   251
(* Given [R1, R2, R3] creates %(x,x'). %(y,y'). %(z,z'). R x x' \<and> R y y' \<and> R z z' *)
416c9c5a1126 Generate compound FV and Alpha for recursive bindings.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1464
diff changeset
   252
ML {*
416c9c5a1126 Generate compound FV and Alpha for recursive bindings.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1464
diff changeset
   253
fun mk_compound_alpha Rs =
416c9c5a1126 Generate compound FV and Alpha for recursive bindings.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1464
diff changeset
   254
let
416c9c5a1126 Generate compound FV and Alpha for recursive bindings.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1464
diff changeset
   255
  val nos = (length Rs - 1) downto 0;
416c9c5a1126 Generate compound FV and Alpha for recursive bindings.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1464
diff changeset
   256
  val nos2 = (2 * length Rs - 1) downto length Rs;
416c9c5a1126 Generate compound FV and Alpha for recursive bindings.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1464
diff changeset
   257
  val Rs_applied = map (fn (R, (no2, no)) => R $ Bound no2 $ Bound no) (Rs ~~ (nos2 ~~ nos));
416c9c5a1126 Generate compound FV and Alpha for recursive bindings.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1464
diff changeset
   258
  val Rs_conj = mk_conjl Rs_applied;
416c9c5a1126 Generate compound FV and Alpha for recursive bindings.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1464
diff changeset
   259
  val (tyh :: tys) = rev (map (domain_type o fastype_of) Rs);
416c9c5a1126 Generate compound FV and Alpha for recursive bindings.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1464
diff changeset
   260
  fun fold_fun ty t = HOLogic.mk_split (Abs ("", ty, t))
416c9c5a1126 Generate compound FV and Alpha for recursive bindings.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1464
diff changeset
   261
  val abs_rhs = fold fold_fun tys (Abs ("", tyh, Rs_conj))
416c9c5a1126 Generate compound FV and Alpha for recursive bindings.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1464
diff changeset
   262
in
416c9c5a1126 Generate compound FV and Alpha for recursive bindings.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1464
diff changeset
   263
  fold fold_fun tys (Abs ("", tyh, abs_rhs))
416c9c5a1126 Generate compound FV and Alpha for recursive bindings.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1464
diff changeset
   264
end;
416c9c5a1126 Generate compound FV and Alpha for recursive bindings.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1464
diff changeset
   265
*}
416c9c5a1126 Generate compound FV and Alpha for recursive bindings.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1464
diff changeset
   266
416c9c5a1126 Generate compound FV and Alpha for recursive bindings.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1464
diff changeset
   267
ML {* cterm_of @{theory} (mk_compound_alpha [@{term "R :: 'a \<Rightarrow> 'a \<Rightarrow> bool"}, @{term "R2 :: 'b \<Rightarrow> 'b \<Rightarrow> bool"}, @{term "R3 :: 'b \<Rightarrow> 'b \<Rightarrow> bool"}]) *}
416c9c5a1126 Generate compound FV and Alpha for recursive bindings.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1464
diff changeset
   268
1288
0203cd5cfd6c The new alpha-equivalence and testing in Trm2 and Trm5.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1277
diff changeset
   269
ML {* fun add_perm (p1, p2) = Const(@{const_name plus}, @{typ "perm \<Rightarrow> perm \<Rightarrow> perm"}) $ p1 $ p2 *}
0203cd5cfd6c The new alpha-equivalence and testing in Trm2 and Trm5.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1277
diff changeset
   270
1375
aa787c9b6955 A version of Fv that takes into account recursive and non-recursive bindings.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1366
diff changeset
   271
ML {*
aa787c9b6955 A version of Fv that takes into account recursive and non-recursive bindings.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1366
diff changeset
   272
fun non_rec_binds l =
aa787c9b6955 A version of Fv that takes into account recursive and non-recursive bindings.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1366
diff changeset
   273
let
aa787c9b6955 A version of Fv that takes into account recursive and non-recursive bindings.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1366
diff changeset
   274
  fun is_non_rec (SOME (f, false), _, _) = SOME f
aa787c9b6955 A version of Fv that takes into account recursive and non-recursive bindings.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1366
diff changeset
   275
    | is_non_rec _ = NONE
aa787c9b6955 A version of Fv that takes into account recursive and non-recursive bindings.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1366
diff changeset
   276
in
aa787c9b6955 A version of Fv that takes into account recursive and non-recursive bindings.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1366
diff changeset
   277
  distinct (op =) (map_filter is_non_rec (flat (flat l)))
aa787c9b6955 A version of Fv that takes into account recursive and non-recursive bindings.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1366
diff changeset
   278
end
aa787c9b6955 A version of Fv that takes into account recursive and non-recursive bindings.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1366
diff changeset
   279
*}
aa787c9b6955 A version of Fv that takes into account recursive and non-recursive bindings.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1366
diff changeset
   280
aa787c9b6955 A version of Fv that takes into account recursive and non-recursive bindings.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1366
diff changeset
   281
(* We assume no bindings in the type on which bn is defined *)
1505
e12ebfa745f6 Update the description of the generation of fv function.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1498
diff changeset
   282
(* TODO: currently works only with current fv_bn function *)
1375
aa787c9b6955 A version of Fv that takes into account recursive and non-recursive bindings.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1366
diff changeset
   283
ML {*
1615
0ea578c6dae3 Parsing bn functions that call other bn functions and transmitting this information to fv/alpha.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1609
diff changeset
   284
fun fv_bn thy (dt_info : Datatype_Aux.info) fv_frees bn_fvbn (fvbn, (bn, ith_dtyp, args_in_bns)) =
1375
aa787c9b6955 A version of Fv that takes into account recursive and non-recursive bindings.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1366
diff changeset
   285
let
aa787c9b6955 A version of Fv that takes into account recursive and non-recursive bindings.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1366
diff changeset
   286
  val {descr, sorts, ...} = dt_info;
aa787c9b6955 A version of Fv that takes into account recursive and non-recursive bindings.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1366
diff changeset
   287
  fun nth_dtyp i = typ_of_dtyp descr sorts (DtRec i);
1379
5bb0149329ee Separate lists for separate constructors, to match bn_eqs.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1377
diff changeset
   288
  fun fv_bn_constr (cname, dts) args_in_bn =
1375
aa787c9b6955 A version of Fv that takes into account recursive and non-recursive bindings.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1366
diff changeset
   289
  let
aa787c9b6955 A version of Fv that takes into account recursive and non-recursive bindings.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1366
diff changeset
   290
    val Ts = map (typ_of_dtyp descr sorts) dts;
aa787c9b6955 A version of Fv that takes into account recursive and non-recursive bindings.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1366
diff changeset
   291
    val names = Datatype_Prop.make_tnames Ts;
aa787c9b6955 A version of Fv that takes into account recursive and non-recursive bindings.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1366
diff changeset
   292
    val args = map Free (names ~~ Ts);
aa787c9b6955 A version of Fv that takes into account recursive and non-recursive bindings.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1366
diff changeset
   293
    val c = Const (cname, Ts ---> (nth_dtyp ith_dtyp));
aa787c9b6955 A version of Fv that takes into account recursive and non-recursive bindings.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1366
diff changeset
   294
    fun fv_arg ((dt, x), arg_no) =
aa787c9b6955 A version of Fv that takes into account recursive and non-recursive bindings.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1366
diff changeset
   295
      let
aa787c9b6955 A version of Fv that takes into account recursive and non-recursive bindings.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1366
diff changeset
   296
        val ty = fastype_of x
1622
006d81399f6a Compute Fv for non-recursive bn functions calling other bn functions
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1615
diff changeset
   297
(*        val _ = tracing ("B 1" ^ PolyML.makestring args_in_bn);*)
006d81399f6a Compute Fv for non-recursive bn functions calling other bn functions
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1615
diff changeset
   298
(*        val _ = tracing ("B 2" ^ PolyML.makestring bn_fvbn);*)
1375
aa787c9b6955 A version of Fv that takes into account recursive and non-recursive bindings.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1366
diff changeset
   299
      in
1615
0ea578c6dae3 Parsing bn functions that call other bn functions and transmitting this information to fv/alpha.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1609
diff changeset
   300
        case AList.lookup (op=) args_in_bn arg_no of
0ea578c6dae3 Parsing bn functions that call other bn functions and transmitting this information to fv/alpha.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1609
diff changeset
   301
          SOME NONE => @{term "{} :: atom set"}
0ea578c6dae3 Parsing bn functions that call other bn functions and transmitting this information to fv/alpha.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1609
diff changeset
   302
        | SOME (SOME (f : term)) => (the (AList.lookup (op=) bn_fvbn f)) $ x
0ea578c6dae3 Parsing bn functions that call other bn functions and transmitting this information to fv/alpha.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1609
diff changeset
   303
        | NONE =>
0ea578c6dae3 Parsing bn functions that call other bn functions and transmitting this information to fv/alpha.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1609
diff changeset
   304
            if is_atom thy ty then mk_single_atom x else
0ea578c6dae3 Parsing bn functions that call other bn functions and transmitting this information to fv/alpha.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1609
diff changeset
   305
            if is_atom_set thy ty then mk_atom_set x else
0ea578c6dae3 Parsing bn functions that call other bn functions and transmitting this information to fv/alpha.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1609
diff changeset
   306
            if is_atom_fset thy ty then mk_atom_fset x else
0ea578c6dae3 Parsing bn functions that call other bn functions and transmitting this information to fv/alpha.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1609
diff changeset
   307
            if is_rec_type dt then nth fv_frees (body_index dt) $ x else
0ea578c6dae3 Parsing bn functions that call other bn functions and transmitting this information to fv/alpha.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1609
diff changeset
   308
            @{term "{} :: atom set"}
1375
aa787c9b6955 A version of Fv that takes into account recursive and non-recursive bindings.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1366
diff changeset
   309
      end;
aa787c9b6955 A version of Fv that takes into account recursive and non-recursive bindings.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1366
diff changeset
   310
    val arg_nos = 0 upto (length dts - 1)
aa787c9b6955 A version of Fv that takes into account recursive and non-recursive bindings.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1366
diff changeset
   311
  in
aa787c9b6955 A version of Fv that takes into account recursive and non-recursive bindings.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1366
diff changeset
   312
    HOLogic.mk_Trueprop (HOLogic.mk_eq
aa787c9b6955 A version of Fv that takes into account recursive and non-recursive bindings.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1366
diff changeset
   313
      (fvbn $ list_comb (c, args), mk_union (map fv_arg (dts ~~ args ~~ arg_nos))))
aa787c9b6955 A version of Fv that takes into account recursive and non-recursive bindings.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1366
diff changeset
   314
  end;
aa787c9b6955 A version of Fv that takes into account recursive and non-recursive bindings.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1366
diff changeset
   315
  val (_, (_, _, constrs)) = nth descr ith_dtyp;
1379
5bb0149329ee Separate lists for separate constructors, to match bn_eqs.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1377
diff changeset
   316
  val eqs = map2i fv_bn_constr constrs args_in_bns
1375
aa787c9b6955 A version of Fv that takes into account recursive and non-recursive bindings.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1366
diff changeset
   317
in
1615
0ea578c6dae3 Parsing bn functions that call other bn functions and transmitting this information to fv/alpha.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1609
diff changeset
   318
  ((bn, fvbn), eqs)
1375
aa787c9b6955 A version of Fv that takes into account recursive and non-recursive bindings.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1366
diff changeset
   319
end
aa787c9b6955 A version of Fv that takes into account recursive and non-recursive bindings.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1366
diff changeset
   320
*}
aa787c9b6955 A version of Fv that takes into account recursive and non-recursive bindings.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1366
diff changeset
   321
1385
51b8e6dd72d5 exported template for alpha_bn
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1383
diff changeset
   322
ML {*
1615
0ea578c6dae3 Parsing bn functions that call other bn functions and transmitting this information to fv/alpha.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1609
diff changeset
   323
fun fv_bns thy dt_info fv_frees rel_bns =
0ea578c6dae3 Parsing bn functions that call other bn functions and transmitting this information to fv/alpha.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1609
diff changeset
   324
let
0ea578c6dae3 Parsing bn functions that call other bn functions and transmitting this information to fv/alpha.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1609
diff changeset
   325
  fun mk_fvbn_free (bn, ith, _) =
0ea578c6dae3 Parsing bn functions that call other bn functions and transmitting this information to fv/alpha.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1609
diff changeset
   326
    let
0ea578c6dae3 Parsing bn functions that call other bn functions and transmitting this information to fv/alpha.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1609
diff changeset
   327
      val fvbn_name = "fv_" ^ (Long_Name.base_name (fst (dest_Const bn)));
0ea578c6dae3 Parsing bn functions that call other bn functions and transmitting this information to fv/alpha.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1609
diff changeset
   328
    in
0ea578c6dae3 Parsing bn functions that call other bn functions and transmitting this information to fv/alpha.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1609
diff changeset
   329
      (fvbn_name, Free (fvbn_name, fastype_of (nth fv_frees ith)))
0ea578c6dae3 Parsing bn functions that call other bn functions and transmitting this information to fv/alpha.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1609
diff changeset
   330
    end;
0ea578c6dae3 Parsing bn functions that call other bn functions and transmitting this information to fv/alpha.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1609
diff changeset
   331
  val (fvbn_names, fvbn_frees) = split_list (map mk_fvbn_free rel_bns);
0ea578c6dae3 Parsing bn functions that call other bn functions and transmitting this information to fv/alpha.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1609
diff changeset
   332
  val bn_fvbn = (map (fn (bn, _, _) => bn) rel_bns) ~~ fvbn_frees
0ea578c6dae3 Parsing bn functions that call other bn functions and transmitting this information to fv/alpha.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1609
diff changeset
   333
  val (l1, l2) = split_list (map (fv_bn thy dt_info fv_frees bn_fvbn) (fvbn_frees ~~ rel_bns));
0ea578c6dae3 Parsing bn functions that call other bn functions and transmitting this information to fv/alpha.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1609
diff changeset
   334
in
0ea578c6dae3 Parsing bn functions that call other bn functions and transmitting this information to fv/alpha.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1609
diff changeset
   335
  (l1, (fvbn_names ~~ l2))
0ea578c6dae3 Parsing bn functions that call other bn functions and transmitting this information to fv/alpha.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1609
diff changeset
   336
end
0ea578c6dae3 Parsing bn functions that call other bn functions and transmitting this information to fv/alpha.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1609
diff changeset
   337
*}
0ea578c6dae3 Parsing bn functions that call other bn functions and transmitting this information to fv/alpha.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1609
diff changeset
   338
0ea578c6dae3 Parsing bn functions that call other bn functions and transmitting this information to fv/alpha.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1609
diff changeset
   339
0ea578c6dae3 Parsing bn functions that call other bn functions and transmitting this information to fv/alpha.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1609
diff changeset
   340
ML {*
0ea578c6dae3 Parsing bn functions that call other bn functions and transmitting this information to fv/alpha.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1609
diff changeset
   341
fun alpha_bn thy (dt_info : Datatype_Aux.info) alpha_frees bn_alphabn ((bn, ith_dtyp, args_in_bns), (alpha_bn_free, is_rec)) =
1385
51b8e6dd72d5 exported template for alpha_bn
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1383
diff changeset
   342
let
51b8e6dd72d5 exported template for alpha_bn
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1383
diff changeset
   343
  val {descr, sorts, ...} = dt_info;
51b8e6dd72d5 exported template for alpha_bn
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1383
diff changeset
   344
  fun nth_dtyp i = typ_of_dtyp descr sorts (DtRec i);
1457
91fe914e1bef alpha_bn doesn't need the permutation in non-recursive case.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1454
diff changeset
   345
  val pi = Free("pi", @{typ perm})
1386
0511e879a687 alpha_bn_constr template
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1385
diff changeset
   346
  fun alpha_bn_constr (cname, dts) args_in_bn =
0511e879a687 alpha_bn_constr template
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1385
diff changeset
   347
  let
0511e879a687 alpha_bn_constr template
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1385
diff changeset
   348
    val Ts = map (typ_of_dtyp descr sorts) dts;
0511e879a687 alpha_bn_constr template
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1385
diff changeset
   349
    val names = Name.variant_list ["pi"] (Datatype_Prop.make_tnames Ts);
0511e879a687 alpha_bn_constr template
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1385
diff changeset
   350
    val names2 = Name.variant_list ("pi" :: names) (Datatype_Prop.make_tnames Ts);
0511e879a687 alpha_bn_constr template
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1385
diff changeset
   351
    val args = map Free (names ~~ Ts);
0511e879a687 alpha_bn_constr template
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1385
diff changeset
   352
    val args2 = map Free (names2 ~~ Ts);
0511e879a687 alpha_bn_constr template
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1385
diff changeset
   353
    val c = Const (cname, Ts ---> (nth_dtyp ith_dtyp));
1387
9d70a0733786 rhs of alpha_bn, and template for the arguments.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1386
diff changeset
   354
    val rhs = HOLogic.mk_Trueprop
1462
7c59dd8e5435 The old recursive alpha works fine.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1457
diff changeset
   355
      (alpha_bn_free $ (list_comb (c, args)) $ (list_comb (c, args2)));
1387
9d70a0733786 rhs of alpha_bn, and template for the arguments.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1386
diff changeset
   356
    fun lhs_arg ((dt, arg_no), (arg, arg2)) =
1388
ad38ca4213f4 Filled the algorithm for alpha_bn_arg
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1387
diff changeset
   357
      let
ad38ca4213f4 Filled the algorithm for alpha_bn_arg
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1387
diff changeset
   358
        val argty = fastype_of arg;
ad38ca4213f4 Filled the algorithm for alpha_bn_arg
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1387
diff changeset
   359
        val permute = Const (@{const_name permute}, @{typ perm} --> argty --> argty);
ad38ca4213f4 Filled the algorithm for alpha_bn_arg
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1387
diff changeset
   360
      in
1615
0ea578c6dae3 Parsing bn functions that call other bn functions and transmitting this information to fv/alpha.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1609
diff changeset
   361
        case AList.lookup (op=) args_in_bn arg_no of
0ea578c6dae3 Parsing bn functions that call other bn functions and transmitting this information to fv/alpha.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1609
diff changeset
   362
          SOME NONE => @{term True}
0ea578c6dae3 Parsing bn functions that call other bn functions and transmitting this information to fv/alpha.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1609
diff changeset
   363
        | SOME (SOME f) => (the (AList.lookup (op=) bn_alphabn f)) $ arg $ arg2
0ea578c6dae3 Parsing bn functions that call other bn functions and transmitting this information to fv/alpha.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1609
diff changeset
   364
        | NONE =>
0ea578c6dae3 Parsing bn functions that call other bn functions and transmitting this information to fv/alpha.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1609
diff changeset
   365
            if is_rec_type dt then (nth alpha_frees (body_index dt)) $ arg $ arg2
0ea578c6dae3 Parsing bn functions that call other bn functions and transmitting this information to fv/alpha.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1609
diff changeset
   366
            else HOLogic.mk_eq (arg, arg2)
1388
ad38ca4213f4 Filled the algorithm for alpha_bn_arg
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1387
diff changeset
   367
      end
1387
9d70a0733786 rhs of alpha_bn, and template for the arguments.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1386
diff changeset
   368
    val arg_nos = 0 upto (length dts - 1)
9d70a0733786 rhs of alpha_bn, and template for the arguments.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1386
diff changeset
   369
    val lhss = mk_conjl (map lhs_arg (dts ~~ arg_nos ~~ (args ~~ args2)))
9d70a0733786 rhs of alpha_bn, and template for the arguments.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1386
diff changeset
   370
    val eq = Logic.mk_implies (HOLogic.mk_Trueprop lhss, rhs)
1386
0511e879a687 alpha_bn_constr template
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1385
diff changeset
   371
  in
1387
9d70a0733786 rhs of alpha_bn, and template for the arguments.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1386
diff changeset
   372
    eq
1386
0511e879a687 alpha_bn_constr template
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1385
diff changeset
   373
  end
1385
51b8e6dd72d5 exported template for alpha_bn
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1383
diff changeset
   374
  val (_, (_, _, constrs)) = nth descr ith_dtyp;
1386
0511e879a687 alpha_bn_constr template
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1385
diff changeset
   375
  val eqs = map2i alpha_bn_constr constrs args_in_bns
1385
51b8e6dd72d5 exported template for alpha_bn
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1383
diff changeset
   376
in
1615
0ea578c6dae3 Parsing bn functions that call other bn functions and transmitting this information to fv/alpha.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1609
diff changeset
   377
  ((bn, alpha_bn_free), eqs)
1385
51b8e6dd72d5 exported template for alpha_bn
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1383
diff changeset
   378
end
51b8e6dd72d5 exported template for alpha_bn
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1383
diff changeset
   379
*}
51b8e6dd72d5 exported template for alpha_bn
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1383
diff changeset
   380
1615
0ea578c6dae3 Parsing bn functions that call other bn functions and transmitting this information to fv/alpha.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1609
diff changeset
   381
ML {*
0ea578c6dae3 Parsing bn functions that call other bn functions and transmitting this information to fv/alpha.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1609
diff changeset
   382
fun alpha_bns thy dt_info alpha_frees rel_bns bns_rec =
0ea578c6dae3 Parsing bn functions that call other bn functions and transmitting this information to fv/alpha.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1609
diff changeset
   383
let
0ea578c6dae3 Parsing bn functions that call other bn functions and transmitting this information to fv/alpha.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1609
diff changeset
   384
  val {descr, sorts, ...} = dt_info;
0ea578c6dae3 Parsing bn functions that call other bn functions and transmitting this information to fv/alpha.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1609
diff changeset
   385
  fun nth_dtyp i = typ_of_dtyp descr sorts (DtRec i);
0ea578c6dae3 Parsing bn functions that call other bn functions and transmitting this information to fv/alpha.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1609
diff changeset
   386
  fun mk_alphabn_free (bn, ith, _) =
0ea578c6dae3 Parsing bn functions that call other bn functions and transmitting this information to fv/alpha.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1609
diff changeset
   387
    let
0ea578c6dae3 Parsing bn functions that call other bn functions and transmitting this information to fv/alpha.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1609
diff changeset
   388
      val alphabn_name = "alpha_" ^ (Long_Name.base_name (fst (dest_Const bn)));
0ea578c6dae3 Parsing bn functions that call other bn functions and transmitting this information to fv/alpha.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1609
diff changeset
   389
      val alphabn_type = nth_dtyp ith --> nth_dtyp ith --> @{typ bool};
0ea578c6dae3 Parsing bn functions that call other bn functions and transmitting this information to fv/alpha.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1609
diff changeset
   390
      val alphabn_free = Free(alphabn_name, alphabn_type);
0ea578c6dae3 Parsing bn functions that call other bn functions and transmitting this information to fv/alpha.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1609
diff changeset
   391
    in
0ea578c6dae3 Parsing bn functions that call other bn functions and transmitting this information to fv/alpha.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1609
diff changeset
   392
      (alphabn_name, alphabn_free)
0ea578c6dae3 Parsing bn functions that call other bn functions and transmitting this information to fv/alpha.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1609
diff changeset
   393
    end;
0ea578c6dae3 Parsing bn functions that call other bn functions and transmitting this information to fv/alpha.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1609
diff changeset
   394
  val (alphabn_names, alphabn_frees) = split_list (map mk_alphabn_free rel_bns);
0ea578c6dae3 Parsing bn functions that call other bn functions and transmitting this information to fv/alpha.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1609
diff changeset
   395
  val bn_alphabn = (map (fn (bn, _, _) => bn) rel_bns) ~~ alphabn_frees;
0ea578c6dae3 Parsing bn functions that call other bn functions and transmitting this information to fv/alpha.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1609
diff changeset
   396
  val pair = split_list (map (alpha_bn thy dt_info alpha_frees bn_alphabn)
0ea578c6dae3 Parsing bn functions that call other bn functions and transmitting this information to fv/alpha.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1609
diff changeset
   397
    (rel_bns ~~ (alphabn_frees ~~ bns_rec)))
0ea578c6dae3 Parsing bn functions that call other bn functions and transmitting this information to fv/alpha.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1609
diff changeset
   398
in
0ea578c6dae3 Parsing bn functions that call other bn functions and transmitting this information to fv/alpha.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1609
diff changeset
   399
  (alphabn_names, pair)
0ea578c6dae3 Parsing bn functions that call other bn functions and transmitting this information to fv/alpha.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1609
diff changeset
   400
end
0ea578c6dae3 Parsing bn functions that call other bn functions and transmitting this information to fv/alpha.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1609
diff changeset
   401
*}
0ea578c6dae3 Parsing bn functions that call other bn functions and transmitting this information to fv/alpha.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1609
diff changeset
   402
0ea578c6dae3 Parsing bn functions that call other bn functions and transmitting this information to fv/alpha.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1609
diff changeset
   403
1397
6e2dfe52b271 Allows multiple bindings with same lhs.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1394
diff changeset
   404
(* Checks that a list of bindings contains only compatible ones *)
6e2dfe52b271 Allows multiple bindings with same lhs.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1394
diff changeset
   405
ML {*
6e2dfe52b271 Allows multiple bindings with same lhs.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1394
diff changeset
   406
fun bns_same l =
6e2dfe52b271 Allows multiple bindings with same lhs.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1394
diff changeset
   407
  length (distinct (op =) (map (fn ((b, _, _), _) => b) l)) = 1
6e2dfe52b271 Allows multiple bindings with same lhs.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1394
diff changeset
   408
*}
6e2dfe52b271 Allows multiple bindings with same lhs.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1394
diff changeset
   409
1206
9c968284553c Renaming.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1199
diff changeset
   410
(* TODO: Notice datatypes without bindings and replace alpha with equality *)
1175
6a3be6ef348d Reorganization
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1174
diff changeset
   411
ML {*
1375
aa787c9b6955 A version of Fv that takes into account recursive and non-recursive bindings.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1366
diff changeset
   412
fun define_fv_alpha (dt_info : Datatype_Aux.info) bindsall bns lthy =
1178
275a1cb3f2ba Reorder
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1177
diff changeset
   413
let
1366
2bf82fa871e7 Proper recognition of atoms and atom sets.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1362
diff changeset
   414
  val thy = ProofContext.theory_of lthy;
1277
6eacf60ce41d Permutation and FV_Alpha interface change.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1258
diff changeset
   415
  val {descr, sorts, ...} = dt_info;
1168
5c1e16806901 Code for generating the fv function, no bindings yet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   416
  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
   417
  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
   418
    "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
   419
  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
   420
  val fv_frees = map Free (fv_names ~~ fv_types);
1622
006d81399f6a Compute Fv for non-recursive bn functions calling other bn functions
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1615
diff changeset
   421
(* TODO: We need a transitive closure, but instead we do this hack considering
006d81399f6a Compute Fv for non-recursive bn functions calling other bn functions
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1615
diff changeset
   422
   all binding functions as recursive or not *)
006d81399f6a Compute Fv for non-recursive bn functions calling other bn functions
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1615
diff changeset
   423
  val nr_bns =
006d81399f6a Compute Fv for non-recursive bn functions calling other bn functions
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1615
diff changeset
   424
    if (non_rec_binds bindsall) = [] then []
006d81399f6a Compute Fv for non-recursive bn functions calling other bn functions
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1615
diff changeset
   425
    else map (fn (bn, _, _) => bn) bns;
1464
1850361efb8f Revert 7c8cd6eae8e2, now all proofs in Term5 go through, both recursive and not.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1462
diff changeset
   426
  val rel_bns = filter (fn (bn, _, _) => bn mem nr_bns) bns;
1615
0ea578c6dae3 Parsing bn functions that call other bn functions and transmitting this information to fv/alpha.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1609
diff changeset
   427
  val (bn_fv_bns, fv_bn_names_eqs) = fv_bns thy dt_info fv_frees rel_bns;
1553
4355eb3b7161 Automatically derive support for datatypes with at-most one binding per constructor.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1547
diff changeset
   428
  val fvbns = map snd bn_fv_bns;
1375
aa787c9b6955 A version of Fv that takes into account recursive and non-recursive bindings.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1366
diff changeset
   429
  val (fv_bn_names, fv_bn_eqs) = split_list fv_bn_names_eqs;
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
   430
  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
   431
    "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
   432
  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
   433
  val alpha_frees = map Free (alpha_names ~~ alpha_types);
1385
51b8e6dd72d5 exported template for alpha_bn
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1383
diff changeset
   434
  (* We assume that a bn is either recursive or not *)
51b8e6dd72d5 exported template for alpha_bn
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1383
diff changeset
   435
  val bns_rec = map (fn (bn, _, _) => not (bn mem nr_bns)) bns;
1615
0ea578c6dae3 Parsing bn functions that call other bn functions and transmitting this information to fv/alpha.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1609
diff changeset
   436
  val (alpha_bn_names, (bn_alpha_bns, alpha_bn_eqs)) =
0ea578c6dae3 Parsing bn functions that call other bn functions and transmitting this information to fv/alpha.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1609
diff changeset
   437
    alpha_bns thy dt_info alpha_frees bns bns_rec
1389
d0ba4829a76c include alpha in the definitions.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1388
diff changeset
   438
  val alpha_bn_frees = map snd bn_alpha_bns;
d0ba4829a76c include alpha in the definitions.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1388
diff changeset
   439
  val alpha_bn_types = map fastype_of alpha_bn_frees;
1288
0203cd5cfd6c The new alpha-equivalence and testing in Trm2 and Trm5.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1277
diff changeset
   440
  fun fv_alpha_constr ith_dtyp (cname, dts) bindcs =
1168
5c1e16806901 Code for generating the fv function, no bindings yet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   441
    let
5c1e16806901 Code for generating the fv function, no bindings yet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   442
      val Ts = map (typ_of_dtyp descr sorts) dts;
1288
0203cd5cfd6c The new alpha-equivalence and testing in Trm2 and Trm5.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1277
diff changeset
   443
      val bindslen = length bindcs
1323
acf262971303 Fixes for the fv problem and alpha problem.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1308
diff changeset
   444
      val pi_strs_same = replicate bindslen "pi"
acf262971303 Fixes for the fv problem and alpha problem.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1308
diff changeset
   445
      val pi_strs = Name.variant_list [] pi_strs_same;
1288
0203cd5cfd6c The new alpha-equivalence and testing in Trm2 and Trm5.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1277
diff changeset
   446
      val pis = map (fn ps => Free (ps, @{typ perm})) pi_strs;
1357
42b7abf779ec Gather bindings with same binder, and generate only one permutation for them.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1339
diff changeset
   447
      val bind_pis_gath = bindcs ~~ pis;
42b7abf779ec Gather bindings with same binder, and generate only one permutation for them.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1339
diff changeset
   448
      val bind_pis = un_gather_binds_cons bind_pis_gath;
42b7abf779ec Gather bindings with same binder, and generate only one permutation for them.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1339
diff changeset
   449
      val bindcs = map fst bind_pis;
1288
0203cd5cfd6c The new alpha-equivalence and testing in Trm2 and Trm5.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1277
diff changeset
   450
      val names = Name.variant_list pi_strs (Datatype_Prop.make_tnames Ts);
1168
5c1e16806901 Code for generating the fv function, no bindings yet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   451
      val args = map Free (names ~~ Ts);
1288
0203cd5cfd6c The new alpha-equivalence and testing in Trm2 and Trm5.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1277
diff changeset
   452
      val names2 = Name.variant_list (pi_strs @ names) (Datatype_Prop.make_tnames 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
   453
      val args2 = map Free (names2 ~~ Ts);
1288
0203cd5cfd6c The new alpha-equivalence and testing in Trm2 and Trm5.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1277
diff changeset
   454
      val c = Const (cname, Ts ---> (nth_dtyp ith_dtyp));
0203cd5cfd6c The new alpha-equivalence and testing in Trm2 and Trm5.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1277
diff changeset
   455
      val fv_c = nth fv_frees ith_dtyp;
0203cd5cfd6c The new alpha-equivalence and testing in Trm2 and Trm5.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1277
diff changeset
   456
      val alpha = nth alpha_frees ith_dtyp;
0203cd5cfd6c The new alpha-equivalence and testing in Trm2 and Trm5.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1277
diff changeset
   457
      val arg_nos = 0 upto (length dts - 1)
0203cd5cfd6c The new alpha-equivalence and testing in Trm2 and Trm5.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1277
diff changeset
   458
      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
   459
            if is_rec_type (nth dts i) then (nth fv_frees (body_index (nth dts i))) $ (nth args i) else
1366
2bf82fa871e7 Proper recognition of atoms and atom sets.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1362
diff changeset
   460
            if ((is_atom thy) o fastype_of) (nth args i) then mk_single_atom (nth args i) else
1534
984ea1299cd7 The nominal infrastructure for fset. 'fs' missing, but not needed so far.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1516
diff changeset
   461
            if ((is_atom_set thy) o fastype_of) (nth args i) then mk_atom_set (nth args i) else
984ea1299cd7 The nominal infrastructure for fset. 'fs' missing, but not needed so far.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1516
diff changeset
   462
            if ((is_atom_fset thy) o fastype_of) (nth args i) then mk_atom_fset (nth args i) else
1366
2bf82fa871e7 Proper recognition of atoms and atom sets.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1362
diff changeset
   463
            (* TODO we do not know what to do with non-atomizable things *)
2bf82fa871e7 Proper recognition of atoms and atom sets.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1362
diff changeset
   464
            @{term "{} :: atom set"}
1375
aa787c9b6955 A version of Fv that takes into account recursive and non-recursive bindings.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1366
diff changeset
   465
        | fv_bind args (SOME (f, _), i, _) = f $ (nth args i);
1288
0203cd5cfd6c The new alpha-equivalence and testing in Trm2 and Trm5.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1277
diff changeset
   466
      fun fv_binds args relevant = mk_union (map (fv_bind args) relevant)
1464
1850361efb8f Revert 7c8cd6eae8e2, now all proofs in Term5 go through, both recursive and not.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1462
diff changeset
   467
      fun find_nonrec_binder j (SOME (f, false), i, _) = if i = j then SOME f else NONE
1850361efb8f Revert 7c8cd6eae8e2, now all proofs in Term5 go through, both recursive and not.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1462
diff changeset
   468
        | find_nonrec_binder _ _ = NONE
1288
0203cd5cfd6c The new alpha-equivalence and testing in Trm2 and Trm5.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1277
diff changeset
   469
      fun fv_arg ((dt, x), arg_no) =
1464
1850361efb8f Revert 7c8cd6eae8e2, now all proofs in Term5 go through, both recursive and not.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1462
diff changeset
   470
        case get_first (find_nonrec_binder arg_no) bindcs of
1850361efb8f Revert 7c8cd6eae8e2, now all proofs in Term5 go through, both recursive and not.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1462
diff changeset
   471
          SOME f =>
1375
aa787c9b6955 A version of Fv that takes into account recursive and non-recursive bindings.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1366
diff changeset
   472
            (case get_first (fn (x, y) => if x = f then SOME y else NONE) bn_fv_bns of
1464
1850361efb8f Revert 7c8cd6eae8e2, now all proofs in Term5 go through, both recursive and not.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1462
diff changeset
   473
                SOME fv_bn => fv_bn $ x
1375
aa787c9b6955 A version of Fv that takes into account recursive and non-recursive bindings.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1366
diff changeset
   474
              | NONE => error "bn specified in a non-rec binding but not in bn list")
aa787c9b6955 A version of Fv that takes into account recursive and non-recursive bindings.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1366
diff changeset
   475
        | NONE =>
aa787c9b6955 A version of Fv that takes into account recursive and non-recursive bindings.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1366
diff changeset
   476
            let
aa787c9b6955 A version of Fv that takes into account recursive and non-recursive bindings.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1366
diff changeset
   477
              val arg =
aa787c9b6955 A version of Fv that takes into account recursive and non-recursive bindings.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1366
diff changeset
   478
                if is_rec_type dt then nth fv_frees (body_index dt) $ x else
aa787c9b6955 A version of Fv that takes into account recursive and non-recursive bindings.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1366
diff changeset
   479
                if ((is_atom thy) o fastype_of) x then mk_single_atom x else
1534
984ea1299cd7 The nominal infrastructure for fset. 'fs' missing, but not needed so far.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1516
diff changeset
   480
                if ((is_atom_set thy) o fastype_of) x then mk_atom_set x else
984ea1299cd7 The nominal infrastructure for fset. 'fs' missing, but not needed so far.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1516
diff changeset
   481
                if ((is_atom_fset thy) o fastype_of) x then mk_atom_fset x else
1375
aa787c9b6955 A version of Fv that takes into account recursive and non-recursive bindings.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1366
diff changeset
   482
                (* TODO we do not know what to do with non-atomizable things *)
1454
7c8cd6eae8e2 FV_bn generated for recursive functions as well, and used in main fv for bindings.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1452
diff changeset
   483
                @{term "{} :: atom set"};
1375
aa787c9b6955 A version of Fv that takes into account recursive and non-recursive bindings.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1366
diff changeset
   484
              (* If i = j then we generate it only once *)
aa787c9b6955 A version of Fv that takes into account recursive and non-recursive bindings.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1366
diff changeset
   485
              val relevant = filter (fn (_, i, j) => ((i = arg_no) orelse (j = arg_no))) bindcs;
aa787c9b6955 A version of Fv that takes into account recursive and non-recursive bindings.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1366
diff changeset
   486
              val sub = fv_binds args relevant
aa787c9b6955 A version of Fv that takes into account recursive and non-recursive bindings.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1366
diff changeset
   487
            in
aa787c9b6955 A version of Fv that takes into account recursive and non-recursive bindings.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1366
diff changeset
   488
              mk_diff arg sub
aa787c9b6955 A version of Fv that takes into account recursive and non-recursive bindings.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1366
diff changeset
   489
            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
   490
      val fv_eq = HOLogic.mk_Trueprop (HOLogic.mk_eq
1288
0203cd5cfd6c The new alpha-equivalence and testing in Trm2 and Trm5.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1277
diff changeset
   491
        (fv_c $ list_comb (c, args), mk_union (map fv_arg  (dts ~~ args ~~ arg_nos))))
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
   492
      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
   493
        HOLogic.mk_Trueprop (alpha $ (list_comb (c, args)) $ (list_comb (c, args2)));
1288
0203cd5cfd6c The new alpha-equivalence and testing in Trm2 and Trm5.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1277
diff changeset
   494
      fun alpha_arg ((dt, arg_no), (arg, arg2)) =
0203cd5cfd6c The new alpha-equivalence and testing in Trm2 and Trm5.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1277
diff changeset
   495
        let
1383
8399236f901b Use alpha_bns in normal alpha defs.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1382
diff changeset
   496
          val rel_in_simp_binds = filter (fn ((NONE, i, _), _) => i = arg_no | _ => false) bind_pis;
8399236f901b Use alpha_bns in normal alpha defs.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1382
diff changeset
   497
          val rel_in_comp_binds = filter (fn ((SOME _, i, _), _) => i = arg_no | _ => false) bind_pis;
1468
416c9c5a1126 Generate compound FV and Alpha for recursive bindings.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1464
diff changeset
   498
          val rel_has_binds = filter (fn ((NONE, _, j), _) => j = arg_no
416c9c5a1126 Generate compound FV and Alpha for recursive bindings.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1464
diff changeset
   499
                                       | ((SOME (_, false), _, j), _) => j = arg_no
416c9c5a1126 Generate compound FV and Alpha for recursive bindings.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1464
diff changeset
   500
                                       | _ => false) bind_pis;
1472
4fa5365cd871 Fix in alpha; support of the recursive Let works :)
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1468
diff changeset
   501
          val rel_has_rec_binds = filter 
4fa5365cd871 Fix in alpha; support of the recursive Let works :)
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1468
diff changeset
   502
            (fn ((SOME (_, true), _, j), _) => j = arg_no | _ => false) bind_pis;
1288
0203cd5cfd6c The new alpha-equivalence and testing in Trm2 and Trm5.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1277
diff changeset
   503
        in
1472
4fa5365cd871 Fix in alpha; support of the recursive Let works :)
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1468
diff changeset
   504
          case (rel_in_simp_binds, rel_in_comp_binds, rel_has_binds, rel_has_rec_binds) of
4fa5365cd871 Fix in alpha; support of the recursive Let works :)
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1468
diff changeset
   505
            ([], [], [], []) =>
1383
8399236f901b Use alpha_bns in normal alpha defs.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1382
diff changeset
   506
              if is_rec_type dt then (nth alpha_frees (body_index dt) $ arg $ arg2)
8399236f901b Use alpha_bns in normal alpha defs.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1382
diff changeset
   507
              else (HOLogic.mk_eq (arg, arg2))
1472
4fa5365cd871 Fix in alpha; support of the recursive Let works :)
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1468
diff changeset
   508
          | (_, [], [], []) => @{term True}
4fa5365cd871 Fix in alpha; support of the recursive Let works :)
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1468
diff changeset
   509
          | ([], [], [], _) => @{term True}
4fa5365cd871 Fix in alpha; support of the recursive Let works :)
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1468
diff changeset
   510
          | ([], ((((SOME (bn, is_rec)), _, _), pi) :: _), [], []) =>
1462
7c59dd8e5435 The old recursive alpha works fine.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1457
diff changeset
   511
            if not (bns_same rel_in_comp_binds) then error "incompatible bindings for an argument" else
7c59dd8e5435 The old recursive alpha works fine.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1457
diff changeset
   512
            if is_rec then
7c59dd8e5435 The old recursive alpha works fine.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1457
diff changeset
   513
              let
7c59dd8e5435 The old recursive alpha works fine.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1457
diff changeset
   514
                val (rbinds, rpis) = split_list rel_in_comp_binds
1468
416c9c5a1126 Generate compound FV and Alpha for recursive bindings.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1464
diff changeset
   515
                val bound_in_nos = map (fn (_, _, i) => i) rbinds
416c9c5a1126 Generate compound FV and Alpha for recursive bindings.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1464
diff changeset
   516
                val bound_in_ty_nos = map (fn i => body_index (nth dts i)) bound_in_nos;
416c9c5a1126 Generate compound FV and Alpha for recursive bindings.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1464
diff changeset
   517
                val bound_args = arg :: map (nth args) bound_in_nos;
416c9c5a1126 Generate compound FV and Alpha for recursive bindings.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1464
diff changeset
   518
                val bound_args2 = arg2 :: map (nth args2) bound_in_nos;
416c9c5a1126 Generate compound FV and Alpha for recursive bindings.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1464
diff changeset
   519
                fun bound_in args (_, _, i) = nth args i;
1462
7c59dd8e5435 The old recursive alpha works fine.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1457
diff changeset
   520
                val lhs_binds = fv_binds args rbinds
1468
416c9c5a1126 Generate compound FV and Alpha for recursive bindings.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1464
diff changeset
   521
                val lhs_arg = foldr1 HOLogic.mk_prod bound_args
416c9c5a1126 Generate compound FV and Alpha for recursive bindings.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1464
diff changeset
   522
                val lhs = mk_pair (lhs_binds, lhs_arg);
1462
7c59dd8e5435 The old recursive alpha works fine.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1457
diff changeset
   523
                val rhs_binds = fv_binds args2 rbinds;
1468
416c9c5a1126 Generate compound FV and Alpha for recursive bindings.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1464
diff changeset
   524
                val rhs_arg = foldr1 HOLogic.mk_prod bound_args2;
416c9c5a1126 Generate compound FV and Alpha for recursive bindings.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1464
diff changeset
   525
                val rhs = mk_pair (rhs_binds, rhs_arg);
416c9c5a1126 Generate compound FV and Alpha for recursive bindings.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1464
diff changeset
   526
                val fvs = map (nth fv_frees) ((body_index dt) :: bound_in_ty_nos);
416c9c5a1126 Generate compound FV and Alpha for recursive bindings.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1464
diff changeset
   527
                val fv = mk_compound_fv fvs;
416c9c5a1126 Generate compound FV and Alpha for recursive bindings.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1464
diff changeset
   528
                val alphas = map (nth alpha_frees) ((body_index dt) :: bound_in_ty_nos);
416c9c5a1126 Generate compound FV and Alpha for recursive bindings.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1464
diff changeset
   529
                val alpha = mk_compound_alpha alphas;
1462
7c59dd8e5435 The old recursive alpha works fine.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1457
diff changeset
   530
                val pi = foldr1 add_perm (distinct (op =) rpis);
7c59dd8e5435 The old recursive alpha works fine.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1457
diff changeset
   531
                val alpha_gen_pre = Const (@{const_name alpha_gen}, dummyT) $ lhs $ alpha $ fv $ pi $ rhs;
7c59dd8e5435 The old recursive alpha works fine.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1457
diff changeset
   532
                val alpha_gen = Syntax.check_term lthy alpha_gen_pre
7c59dd8e5435 The old recursive alpha works fine.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1457
diff changeset
   533
              in
7c59dd8e5435 The old recursive alpha works fine.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1457
diff changeset
   534
                alpha_gen
7c59dd8e5435 The old recursive alpha works fine.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1457
diff changeset
   535
              end
7c59dd8e5435 The old recursive alpha works fine.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1457
diff changeset
   536
            else
7c59dd8e5435 The old recursive alpha works fine.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1457
diff changeset
   537
              let
7c59dd8e5435 The old recursive alpha works fine.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1457
diff changeset
   538
                val alpha_bn_const =
7c59dd8e5435 The old recursive alpha works fine.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1457
diff changeset
   539
                  nth alpha_bn_frees (find_index (fn (b, _, _) => b = bn) bns)
7c59dd8e5435 The old recursive alpha works fine.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1457
diff changeset
   540
              in
7c59dd8e5435 The old recursive alpha works fine.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1457
diff changeset
   541
                alpha_bn_const $ arg $ arg2
7c59dd8e5435 The old recursive alpha works fine.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1457
diff changeset
   542
              end
1472
4fa5365cd871 Fix in alpha; support of the recursive Let works :)
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1468
diff changeset
   543
          | ([], [], relevant, []) =>
1383
8399236f901b Use alpha_bns in normal alpha defs.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1382
diff changeset
   544
            let
1288
0203cd5cfd6c The new alpha-equivalence and testing in Trm2 and Trm5.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1277
diff changeset
   545
              val (rbinds, rpis) = split_list relevant
0203cd5cfd6c The new alpha-equivalence and testing in Trm2 and Trm5.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1277
diff changeset
   546
              val lhs_binds = fv_binds args rbinds
0203cd5cfd6c The new alpha-equivalence and testing in Trm2 and Trm5.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1277
diff changeset
   547
              val lhs = mk_pair (lhs_binds, arg);
0203cd5cfd6c The new alpha-equivalence and testing in Trm2 and Trm5.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1277
diff changeset
   548
              val rhs_binds = fv_binds args2 rbinds;
0203cd5cfd6c The new alpha-equivalence and testing in Trm2 and Trm5.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1277
diff changeset
   549
              val rhs = mk_pair (rhs_binds, arg2);
0203cd5cfd6c The new alpha-equivalence and testing in Trm2 and Trm5.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1277
diff changeset
   550
              val alpha = nth alpha_frees (body_index dt);
0203cd5cfd6c The new alpha-equivalence and testing in Trm2 and Trm5.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1277
diff changeset
   551
              val fv = nth fv_frees (body_index dt);
1359
3bf496a971c6 Fix permutation addition.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1358
diff changeset
   552
              val pi = foldr1 add_perm (distinct (op =) rpis);
1288
0203cd5cfd6c The new alpha-equivalence and testing in Trm2 and Trm5.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1277
diff changeset
   553
              val alpha_gen_pre = Const (@{const_name alpha_gen}, dummyT) $ lhs $ alpha $ fv $ pi $ rhs;
1325
0be098c61d00 Add the supp intersection conditions.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1323
diff changeset
   554
              val alpha_gen = Syntax.check_term lthy alpha_gen_pre
1288
0203cd5cfd6c The new alpha-equivalence and testing in Trm2 and Trm5.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1277
diff changeset
   555
            in
1357
42b7abf779ec Gather bindings with same binder, and generate only one permutation for them.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1339
diff changeset
   556
              alpha_gen
1383
8399236f901b Use alpha_bns in normal alpha defs.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1382
diff changeset
   557
            end
1385
51b8e6dd72d5 exported template for alpha_bn
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1383
diff changeset
   558
          | _ => error "Fv.alpha: not supported binding structure"
1288
0203cd5cfd6c The new alpha-equivalence and testing in Trm2 and Trm5.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1277
diff changeset
   559
        end
0203cd5cfd6c The new alpha-equivalence and testing in Trm2 and Trm5.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1277
diff changeset
   560
      val alphas = map alpha_arg (dts ~~ arg_nos ~~ (args ~~ args2))
0203cd5cfd6c The new alpha-equivalence and testing in Trm2 and Trm5.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1277
diff changeset
   561
      val alpha_lhss = mk_conjl alphas
0203cd5cfd6c The new alpha-equivalence and testing in Trm2 and Trm5.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1277
diff changeset
   562
      val alpha_lhss_ex =
0203cd5cfd6c The new alpha-equivalence and testing in Trm2 and Trm5.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1277
diff changeset
   563
        fold (fn pi_str => fn t => HOLogic.mk_exists (pi_str, @{typ perm}, t)) pi_strs alpha_lhss
0203cd5cfd6c The new alpha-equivalence and testing in Trm2 and Trm5.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1277
diff changeset
   564
      val alpha_eq = Logic.mk_implies (HOLogic.mk_Trueprop alpha_lhss_ex, alpha_rhs)
1173
9cb99a28b40e Some optimizations and fixes.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1172
diff changeset
   565
    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
   566
      (fv_eq, alpha_eq)
1168
5c1e16806901 Code for generating the fv function, no bindings yet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   567
    end;
1302
d3101a5b9c4d Length fix for nested recursions.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1301
diff changeset
   568
  fun fv_alpha_eq (i, (_, _, constrs)) binds = map2i (fv_alpha_constr i) constrs binds;
1376
56efa1e854bf Separate primrecs in Fv.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1375
diff changeset
   569
  val fveqs_alphaeqs = map2i fv_alpha_eq descr (gather_binds bindsall)
56efa1e854bf Separate primrecs in Fv.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1375
diff changeset
   570
  val (fv_eqs_perfv, alpha_eqs) = apsnd flat (split_list (map split_list fveqs_alphaeqs))
56efa1e854bf Separate primrecs in Fv.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1375
diff changeset
   571
  val rel_bns_nos = map (fn (_, i, _) => i) rel_bns;
1385
51b8e6dd72d5 exported template for alpha_bn
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1383
diff changeset
   572
  fun filter_fun (_, b) = b mem rel_bns_nos;
1376
56efa1e854bf Separate primrecs in Fv.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1375
diff changeset
   573
  val all_fvs = (fv_names ~~ fv_eqs_perfv) ~~ (0 upto (length fv_names - 1))
56efa1e854bf Separate primrecs in Fv.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1375
diff changeset
   574
  val (fv_names_fst, fv_eqs_fst) = apsnd flat (split_list (map fst (filter_out filter_fun all_fvs)))
56efa1e854bf Separate primrecs in Fv.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1375
diff changeset
   575
  val (fv_names_snd, fv_eqs_snd) = apsnd flat (split_list (map fst (filter filter_fun all_fvs)))
56efa1e854bf Separate primrecs in Fv.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1375
diff changeset
   576
  val fv_eqs_all = fv_eqs_fst @ (flat fv_bn_eqs);
56efa1e854bf Separate primrecs in Fv.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1375
diff changeset
   577
  val fv_names_all = fv_names_fst @ fv_bn_names;
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
   578
  val add_binds = map (fn x => (Attrib.empty_binding, x))
1375
aa787c9b6955 A version of Fv that takes into account recursive and non-recursive bindings.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1366
diff changeset
   579
(* Function_Fun.add_fun Function_Common.default_config ... true *)
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
   580
  val (fvs, lthy') = (Primrec.add_primrec
1375
aa787c9b6955 A version of Fv that takes into account recursive and non-recursive bindings.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1366
diff changeset
   581
    (map (fn s => (Binding.name s, NONE, NoSyn)) fv_names_all) (add_binds fv_eqs_all) lthy)
1376
56efa1e854bf Separate primrecs in Fv.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1375
diff changeset
   582
  val (fvs2, lthy'') =
56efa1e854bf Separate primrecs in Fv.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1375
diff changeset
   583
    if fv_eqs_snd = [] then (([], []), lthy') else
56efa1e854bf Separate primrecs in Fv.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1375
diff changeset
   584
   (Primrec.add_primrec
56efa1e854bf Separate primrecs in Fv.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1375
diff changeset
   585
    (map (fn s => (Binding.name s, NONE, NoSyn)) fv_names_snd) (add_binds fv_eqs_snd) lthy')
56efa1e854bf Separate primrecs in Fv.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1375
diff changeset
   586
  val (alphas, lthy''') = (Inductive.add_inductive_i
1325
0be098c61d00 Add the supp intersection conditions.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1323
diff changeset
   587
     {quiet_mode = true, verbose = false, alt_name = Binding.empty,
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
   588
      coind = false, no_elim = false, no_ind = false, skip_mono = true, fork_mono = false}
1389
d0ba4829a76c include alpha in the definitions.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1388
diff changeset
   589
     (map2 (fn x => fn y => ((Binding.name x, y), NoSyn)) (alpha_names @ alpha_bn_names)
d0ba4829a76c include alpha in the definitions.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1388
diff changeset
   590
     (alpha_types @ alpha_bn_types)) []
d0ba4829a76c include alpha in the definitions.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1388
diff changeset
   591
     (add_binds (alpha_eqs @ flat alpha_bn_eqs)) [] lthy'')
1553
4355eb3b7161 Automatically derive support for datatypes with at-most one binding per constructor.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1547
diff changeset
   592
  val ordered_fvs = fv_frees @ fvbns;
4355eb3b7161 Automatically derive support for datatypes with at-most one binding per constructor.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1547
diff changeset
   593
  val exported_fvs = map (Morphism.term (ProofContext.export_morphism lthy''' lthy)) ordered_fvs;
1385
51b8e6dd72d5 exported template for alpha_bn
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1383
diff changeset
   594
  val all_fvs = (fst fvs @ fst fvs2, snd fvs @ snd fvs2)
1178
275a1cb3f2ba Reorder
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1177
diff changeset
   595
in
1553
4355eb3b7161 Automatically derive support for datatypes with at-most one binding per constructor.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1547
diff changeset
   596
  (((all_fvs, ordered_fvs), alphas), lthy''')
1178
275a1cb3f2ba Reorder
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1177
diff changeset
   597
end
1168
5c1e16806901 Code for generating the fv function, no bindings yet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   598
*}
5c1e16806901 Code for generating the fv function, no bindings yet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   599
1375
aa787c9b6955 A version of Fv that takes into account recursive and non-recursive bindings.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1366
diff changeset
   600
(*
1178
275a1cb3f2ba Reorder
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1177
diff changeset
   601
atom_decl name
1375
aa787c9b6955 A version of Fv that takes into account recursive and non-recursive bindings.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1366
diff changeset
   602
datatype lam =
aa787c9b6955 A version of Fv that takes into account recursive and non-recursive bindings.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1366
diff changeset
   603
  VAR "name"
aa787c9b6955 A version of Fv that takes into account recursive and non-recursive bindings.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1366
diff changeset
   604
| APP "lam" "lam"
aa787c9b6955 A version of Fv that takes into account recursive and non-recursive bindings.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1366
diff changeset
   605
| LET "bp" "lam"
aa787c9b6955 A version of Fv that takes into account recursive and non-recursive bindings.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1366
diff changeset
   606
and bp =
aa787c9b6955 A version of Fv that takes into account recursive and non-recursive bindings.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1366
diff changeset
   607
  BP "name" "lam"
aa787c9b6955 A version of Fv that takes into account recursive and non-recursive bindings.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1366
diff changeset
   608
primrec
aa787c9b6955 A version of Fv that takes into account recursive and non-recursive bindings.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1366
diff changeset
   609
  bi::"bp \<Rightarrow> atom set"
aa787c9b6955 A version of Fv that takes into account recursive and non-recursive bindings.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1366
diff changeset
   610
where
aa787c9b6955 A version of Fv that takes into account recursive and non-recursive bindings.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1366
diff changeset
   611
  "bi (BP x t) = {atom x}"
aa787c9b6955 A version of Fv that takes into account recursive and non-recursive bindings.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1366
diff changeset
   612
setup {* snd o define_raw_perms (Datatype.the_info @{theory} "Fv.lam") 2 *}
aa787c9b6955 A version of Fv that takes into account recursive and non-recursive bindings.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1366
diff changeset
   613
local_setup {*
aa787c9b6955 A version of Fv that takes into account recursive and non-recursive bindings.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1366
diff changeset
   614
  snd o define_fv_alpha (Datatype.the_info @{theory} "Fv.lam")
1389
d0ba4829a76c include alpha in the definitions.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1388
diff changeset
   615
  [[[], [], [(SOME (@{term bi}, true), 0, 1)]], [[]]] [(@{term bi}, 1, [[0]])] *}
1375
aa787c9b6955 A version of Fv that takes into account recursive and non-recursive bindings.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1366
diff changeset
   616
print_theorems
aa787c9b6955 A version of Fv that takes into account recursive and non-recursive bindings.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1366
diff changeset
   617
*)
aa787c9b6955 A version of Fv that takes into account recursive and non-recursive bindings.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1366
diff changeset
   618
1389
d0ba4829a76c include alpha in the definitions.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1388
diff changeset
   619
(*atom_decl name
1178
275a1cb3f2ba Reorder
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1177
diff changeset
   620
datatype rtrm1 =
275a1cb3f2ba Reorder
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1177
diff changeset
   621
  rVr1 "name"
275a1cb3f2ba Reorder
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1177
diff changeset
   622
| rAp1 "rtrm1" "rtrm1"
275a1cb3f2ba Reorder
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1177
diff changeset
   623
| rLm1 "name" "rtrm1"        --"name is bound in trm1"
275a1cb3f2ba Reorder
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1177
diff changeset
   624
| 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
   625
and bp =
275a1cb3f2ba Reorder
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1177
diff changeset
   626
  BUnit
275a1cb3f2ba Reorder
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1177
diff changeset
   627
| BVr "name"
275a1cb3f2ba Reorder
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1177
diff changeset
   628
| BPr "bp" "bp"
1358
0c843fcb1d7b Update the comments
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1357
diff changeset
   629
primrec
1178
275a1cb3f2ba Reorder
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1177
diff changeset
   630
  bv1
275a1cb3f2ba Reorder
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1177
diff changeset
   631
where
275a1cb3f2ba Reorder
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1177
diff changeset
   632
  "bv1 (BUnit) = {}"
275a1cb3f2ba Reorder
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1177
diff changeset
   633
| "bv1 (BVr x) = {atom x}"
275a1cb3f2ba Reorder
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1177
diff changeset
   634
| "bv1 (BPr bp1 bp2) = (bv1 bp1) \<union> (bv1 bp1)"
1389
d0ba4829a76c include alpha in the definitions.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1388
diff changeset
   635
setup {* snd o define_raw_perms (Datatype.the_info @{theory} "Fv.rtrm1") 2 *}
d0ba4829a76c include alpha in the definitions.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1388
diff changeset
   636
local_setup {*
d0ba4829a76c include alpha in the definitions.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1388
diff changeset
   637
  snd o define_fv_alpha (Datatype.the_info @{theory} "Fv.rtrm1")
d0ba4829a76c include alpha in the definitions.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1388
diff changeset
   638
  [[[], [], [(NONE, 0, 1)], [(SOME (@{term bv1}, false), 0, 2)]],
d0ba4829a76c include alpha in the definitions.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1388
diff changeset
   639
  [[], [], []]] [(@{term bv1}, 1, [[], [0], [0, 1]])] *}
1168
5c1e16806901 Code for generating the fv function, no bindings yet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   640
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
   641
*)
1180
3f36936f1280 Testing Fv
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1178
diff changeset
   642
1389
d0ba4829a76c include alpha in the definitions.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1388
diff changeset
   643
(*
d0ba4829a76c include alpha in the definitions.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1388
diff changeset
   644
atom_decl name
d0ba4829a76c include alpha in the definitions.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1388
diff changeset
   645
datatype rtrm5 =
d0ba4829a76c include alpha in the definitions.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1388
diff changeset
   646
  rVr5 "name"
d0ba4829a76c include alpha in the definitions.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1388
diff changeset
   647
| rLt5 "rlts" "rtrm5" --"bind (bv5 lts) in (rtrm5)"
d0ba4829a76c include alpha in the definitions.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1388
diff changeset
   648
and rlts =
d0ba4829a76c include alpha in the definitions.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1388
diff changeset
   649
  rLnil
d0ba4829a76c include alpha in the definitions.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1388
diff changeset
   650
| rLcons "name" "rtrm5" "rlts"
d0ba4829a76c include alpha in the definitions.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1388
diff changeset
   651
primrec
d0ba4829a76c include alpha in the definitions.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1388
diff changeset
   652
  rbv5
d0ba4829a76c include alpha in the definitions.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1388
diff changeset
   653
where
d0ba4829a76c include alpha in the definitions.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1388
diff changeset
   654
  "rbv5 rLnil = {}"
d0ba4829a76c include alpha in the definitions.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1388
diff changeset
   655
| "rbv5 (rLcons n t ltl) = {atom n} \<union> (rbv5 ltl)"
d0ba4829a76c include alpha in the definitions.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1388
diff changeset
   656
setup {* snd o define_raw_perms (Datatype.the_info @{theory} "Fv.rtrm5") 2 *}
d0ba4829a76c include alpha in the definitions.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1388
diff changeset
   657
local_setup {* snd o define_fv_alpha (Datatype.the_info @{theory} "Fv.rtrm5")
d0ba4829a76c include alpha in the definitions.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1388
diff changeset
   658
  [[[], [(SOME (@{term rbv5}, false), 0, 1)]], [[], []]] [(@{term rbv5}, 1, [[], [0, 2]])] *}
d0ba4829a76c include alpha in the definitions.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1388
diff changeset
   659
print_theorems
d0ba4829a76c include alpha in the definitions.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1388
diff changeset
   660
*)
1199
5770c73f2415 Automatic production and proving of pseudo-injectivity.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1196
diff changeset
   661
1196
4efbaba9d754 Constructing alpha_inj goal.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1193
diff changeset
   662
ML {*
1199
5770c73f2415 Automatic production and proving of pseudo-injectivity.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1196
diff changeset
   663
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
   664
  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
   665
  (rtac @{thm iffI} THEN' RANGE [
1199
5770c73f2415 Automatic production and proving of pseudo-injectivity.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1196
diff changeset
   666
     (eresolve_tac elims THEN_ALL_NEW
5770c73f2415 Automatic production and proving of pseudo-injectivity.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1196
diff changeset
   667
       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
   668
     ),
1216
06ace3a1eedd Fixed pseudo_injectivity for trm4
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1215
diff changeset
   669
     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
   670
*}
5770c73f2415 Automatic production and proving of pseudo-injectivity.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1196
diff changeset
   671
5770c73f2415 Automatic production and proving of pseudo-injectivity.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1196
diff changeset
   672
ML {*
5770c73f2415 Automatic production and proving of pseudo-injectivity.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1196
diff changeset
   673
fun build_alpha_inj_gl thm =
5770c73f2415 Automatic production and proving of pseudo-injectivity.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1196
diff changeset
   674
  let
5770c73f2415 Automatic production and proving of pseudo-injectivity.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1196
diff changeset
   675
    val prop = prop_of thm;
5770c73f2415 Automatic production and proving of pseudo-injectivity.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1196
diff changeset
   676
    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
   677
    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
   678
    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
   679
  in
5770c73f2415 Automatic production and proving of pseudo-injectivity.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1196
diff changeset
   680
    if hyps = [] then concl
5770c73f2415 Automatic production and proving of pseudo-injectivity.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1196
diff changeset
   681
    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
   682
  end;
5770c73f2415 Automatic production and proving of pseudo-injectivity.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1196
diff changeset
   683
*}
5770c73f2415 Automatic production and proving of pseudo-injectivity.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1196
diff changeset
   684
5770c73f2415 Automatic production and proving of pseudo-injectivity.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1196
diff changeset
   685
ML {*
5770c73f2415 Automatic production and proving of pseudo-injectivity.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1196
diff changeset
   686
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
   687
let
1199
5770c73f2415 Automatic production and proving of pseudo-injectivity.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1196
diff changeset
   688
  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
   689
  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
   690
  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
   691
  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
   692
in
1199
5770c73f2415 Automatic production and proving of pseudo-injectivity.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1196
diff changeset
   693
  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
   694
end
1196
4efbaba9d754 Constructing alpha_inj goal.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1193
diff changeset
   695
*}
4efbaba9d754 Constructing alpha_inj goal.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1193
diff changeset
   696
1207
fb33684e4ece alpha reflexivity
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1206
diff changeset
   697
ML {*
1559
d375804ce6ba Prove reflp for all relations.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1553
diff changeset
   698
fun build_alpha_sym_trans_gl alphas (x, y, z) =
1207
fb33684e4ece alpha reflexivity
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1206
diff changeset
   699
let
fb33684e4ece alpha reflexivity
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1206
diff changeset
   700
  fun build_alpha alpha =
fb33684e4ece alpha reflexivity
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1206
diff changeset
   701
    let
fb33684e4ece alpha reflexivity
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1206
diff changeset
   702
      val ty = domain_type (fastype_of alpha);
1214
0f92257edeee A tactic for final equivp
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1213
diff changeset
   703
      val var = Free(x, ty);
0f92257edeee A tactic for final equivp
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1213
diff changeset
   704
      val var2 = Free(y, ty);
0f92257edeee A tactic for final equivp
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1213
diff changeset
   705
      val var3 = Free(z, ty);
1209
7b1a3df239cd Some progress about transp
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1208
diff changeset
   706
      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
   707
      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
   708
        HOLogic.mk_all (z, ty,
1209
7b1a3df239cd Some progress about transp
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1208
diff changeset
   709
          HOLogic.mk_imp (alpha $ var2 $ var3, alpha $ var $ var3)))
1207
fb33684e4ece alpha reflexivity
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1206
diff changeset
   710
    in
1559
d375804ce6ba Prove reflp for all relations.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1553
diff changeset
   711
      (symp, transp)
1208
cc86faf0d2a0 alpha-symmetric addons.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1207
diff changeset
   712
    end;
1559
d375804ce6ba Prove reflp for all relations.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1553
diff changeset
   713
  val eqs = map build_alpha alphas
1209
7b1a3df239cd Some progress about transp
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1208
diff changeset
   714
  val (sym_eqs, trans_eqs) = split_list eqs
7b1a3df239cd Some progress about transp
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1208
diff changeset
   715
  fun conj l = @{term Trueprop} $ foldr1 HOLogic.mk_conj l
1207
fb33684e4ece alpha reflexivity
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1206
diff changeset
   716
in
1559
d375804ce6ba Prove reflp for all relations.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1553
diff changeset
   717
  (conj sym_eqs, conj trans_eqs)
1196
4efbaba9d754 Constructing alpha_inj goal.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1193
diff changeset
   718
end
1207
fb33684e4ece alpha reflexivity
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1206
diff changeset
   719
*}
fb33684e4ece alpha reflexivity
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1206
diff changeset
   720
1213
43bd70786f9f More equivp infrastructure.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1209
diff changeset
   721
ML {*
1581
6b1eea8dcdc0 equivp_cheat can be removed for all one-permutation examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1560
diff changeset
   722
fun build_alpha_refl_gl fv_alphas_lst alphas =
1559
d375804ce6ba Prove reflp for all relations.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1553
diff changeset
   723
let
1581
6b1eea8dcdc0 equivp_cheat can be removed for all one-permutation examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1560
diff changeset
   724
  val (fvs_alphas, _) = split_list fv_alphas_lst;
1559
d375804ce6ba Prove reflp for all relations.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1553
diff changeset
   725
  val (_, alpha_ts) = split_list fvs_alphas;
d375804ce6ba Prove reflp for all relations.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1553
diff changeset
   726
  val tys = map (domain_type o fastype_of) alpha_ts;
d375804ce6ba Prove reflp for all relations.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1553
diff changeset
   727
  val names = Datatype_Prop.make_tnames tys;
d375804ce6ba Prove reflp for all relations.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1553
diff changeset
   728
  val args = map Free (names ~~ tys);
1581
6b1eea8dcdc0 equivp_cheat can be removed for all one-permutation examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1560
diff changeset
   729
  fun find_alphas ty x =
6b1eea8dcdc0 equivp_cheat can be removed for all one-permutation examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1560
diff changeset
   730
    domain_type (fastype_of x) = ty;
1559
d375804ce6ba Prove reflp for all relations.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1553
diff changeset
   731
  fun mk_alpha_refl arg (_, alpha) = alpha $ arg $ arg;
1581
6b1eea8dcdc0 equivp_cheat can be removed for all one-permutation examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1560
diff changeset
   732
  fun refl_eq_arg (ty, arg) =
6b1eea8dcdc0 equivp_cheat can be removed for all one-permutation examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1560
diff changeset
   733
    let
6b1eea8dcdc0 equivp_cheat can be removed for all one-permutation examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1560
diff changeset
   734
      val rel_alphas = filter (find_alphas ty) alphas;
6b1eea8dcdc0 equivp_cheat can be removed for all one-permutation examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1560
diff changeset
   735
    in
6b1eea8dcdc0 equivp_cheat can be removed for all one-permutation examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1560
diff changeset
   736
      map (fn x => x $ arg $ arg) rel_alphas
6b1eea8dcdc0 equivp_cheat can be removed for all one-permutation examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1560
diff changeset
   737
    end;
6b1eea8dcdc0 equivp_cheat can be removed for all one-permutation examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1560
diff changeset
   738
  (* Flattening loses the induction structure *)
6b1eea8dcdc0 equivp_cheat can be removed for all one-permutation examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1560
diff changeset
   739
  val eqs = map (foldr1 HOLogic.mk_conj) (map refl_eq_arg (tys ~~ args))
1559
d375804ce6ba Prove reflp for all relations.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1553
diff changeset
   740
in
d375804ce6ba Prove reflp for all relations.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1553
diff changeset
   741
  (names, HOLogic.mk_Trueprop (foldr1 HOLogic.mk_conj eqs))
d375804ce6ba Prove reflp for all relations.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1553
diff changeset
   742
end
d375804ce6ba Prove reflp for all relations.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1553
diff changeset
   743
*}
d375804ce6ba Prove reflp for all relations.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1553
diff changeset
   744
d375804ce6ba Prove reflp for all relations.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1553
diff changeset
   745
ML {*
d375804ce6ba Prove reflp for all relations.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1553
diff changeset
   746
fun reflp_tac induct eq_iff ctxt =
1213
43bd70786f9f More equivp infrastructure.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1209
diff changeset
   747
  rtac induct THEN_ALL_NEW
1559
d375804ce6ba Prove reflp for all relations.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1553
diff changeset
   748
  simp_tac ((mk_minimal_ss ctxt) addsimps eq_iff) THEN_ALL_NEW
1333
c6e521a2a0b1 reflp for multiple quantifiers.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1325
diff changeset
   749
  split_conjs THEN_ALL_NEW REPEAT o rtac @{thm exI[of _ "0 :: perm"]}
c6e521a2a0b1 reflp for multiple quantifiers.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1325
diff changeset
   750
  THEN_ALL_NEW split_conjs THEN_ALL_NEW asm_full_simp_tac (HOL_ss addsimps
c6e521a2a0b1 reflp for multiple quantifiers.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1325
diff changeset
   751
     @{thms alpha_gen fresh_star_def fresh_zero_perm permute_zero ball_triv
1482
a98c15866300 Trying to find a compose lemma for 2 arguments.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1480
diff changeset
   752
       add_0_left supp_zero_perm Int_empty_left split_conv})
1213
43bd70786f9f More equivp infrastructure.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1209
diff changeset
   753
*}
43bd70786f9f More equivp infrastructure.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1209
diff changeset
   754
1559
d375804ce6ba Prove reflp for all relations.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1553
diff changeset
   755
ML {*
1581
6b1eea8dcdc0 equivp_cheat can be removed for all one-permutation examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1560
diff changeset
   756
fun build_alpha_refl fv_alphas_lst alphas induct eq_iff ctxt =
1559
d375804ce6ba Prove reflp for all relations.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1553
diff changeset
   757
let
1581
6b1eea8dcdc0 equivp_cheat can be removed for all one-permutation examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1560
diff changeset
   758
  val (names, gl) = build_alpha_refl_gl fv_alphas_lst alphas;
1559
d375804ce6ba Prove reflp for all relations.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1553
diff changeset
   759
  val refl_conj = Goal.prove ctxt names [] gl (fn _ => reflp_tac induct eq_iff ctxt 1);
d375804ce6ba Prove reflp for all relations.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1553
diff changeset
   760
in
d375804ce6ba Prove reflp for all relations.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1553
diff changeset
   761
  HOLogic.conj_elims refl_conj
d375804ce6ba Prove reflp for all relations.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1553
diff changeset
   762
end
d375804ce6ba Prove reflp for all relations.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1553
diff changeset
   763
*}
1333
c6e521a2a0b1 reflp for multiple quantifiers.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1325
diff changeset
   764
1560
604c4cffc5b9 Build alpha-->alphabn implications
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1559
diff changeset
   765
ML {*
604c4cffc5b9 Build alpha-->alphabn implications
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1559
diff changeset
   766
fun build_alpha_alphabn fv_alphas_lst inducts eq_iff ctxt  =
604c4cffc5b9 Build alpha-->alphabn implications
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1559
diff changeset
   767
let
604c4cffc5b9 Build alpha-->alphabn implications
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1559
diff changeset
   768
  val (fvs_alphas, ls) = split_list fv_alphas_lst;
604c4cffc5b9 Build alpha-->alphabn implications
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1559
diff changeset
   769
  val (_, alpha_ts) = split_list fvs_alphas;
604c4cffc5b9 Build alpha-->alphabn implications
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1559
diff changeset
   770
  val tys = map (domain_type o fastype_of) alpha_ts;
604c4cffc5b9 Build alpha-->alphabn implications
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1559
diff changeset
   771
  val names = Datatype_Prop.make_tnames tys;
604c4cffc5b9 Build alpha-->alphabn implications
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1559
diff changeset
   772
  val names2 = Name.variant_list names names;
604c4cffc5b9 Build alpha-->alphabn implications
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1559
diff changeset
   773
  val args = map Free (names ~~ tys);
604c4cffc5b9 Build alpha-->alphabn implications
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1559
diff changeset
   774
  val args2 = map Free (names2 ~~ tys);
604c4cffc5b9 Build alpha-->alphabn implications
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1559
diff changeset
   775
  fun alpha_alphabn ((alpha, (arg, arg2)), (no, l)) =
604c4cffc5b9 Build alpha-->alphabn implications
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1559
diff changeset
   776
    if l = [] then [] else
604c4cffc5b9 Build alpha-->alphabn implications
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1559
diff changeset
   777
    let
604c4cffc5b9 Build alpha-->alphabn implications
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1559
diff changeset
   778
      val alpha_bns = map snd l;
604c4cffc5b9 Build alpha-->alphabn implications
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1559
diff changeset
   779
      val lhs = alpha $ arg $ arg2;
604c4cffc5b9 Build alpha-->alphabn implications
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1559
diff changeset
   780
      val rhs = foldr1 HOLogic.mk_conj (map (fn x => x $ arg $ arg2) alpha_bns);
604c4cffc5b9 Build alpha-->alphabn implications
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1559
diff changeset
   781
      val gl = Logic.mk_implies (HOLogic.mk_Trueprop lhs, HOLogic.mk_Trueprop rhs);
604c4cffc5b9 Build alpha-->alphabn implications
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1559
diff changeset
   782
      fun tac _ = (etac (nth inducts no) THEN_ALL_NEW TRY o rtac @{thm TrueI}
604c4cffc5b9 Build alpha-->alphabn implications
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1559
diff changeset
   783
        THEN_ALL_NEW asm_full_simp_tac (HOL_ss addsimps eq_iff)) 1
604c4cffc5b9 Build alpha-->alphabn implications
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1559
diff changeset
   784
      val th = Goal.prove ctxt (names @ names2) [] gl tac;
604c4cffc5b9 Build alpha-->alphabn implications
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1559
diff changeset
   785
    in
604c4cffc5b9 Build alpha-->alphabn implications
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1559
diff changeset
   786
      Project_Rule.projects ctxt (1 upto length l) th
604c4cffc5b9 Build alpha-->alphabn implications
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1559
diff changeset
   787
    end;
604c4cffc5b9 Build alpha-->alphabn implications
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1559
diff changeset
   788
  val eqs = map alpha_alphabn ((alpha_ts ~~ (args ~~ args2)) ~~ ((0 upto (length ls - 1)) ~~ ls));
604c4cffc5b9 Build alpha-->alphabn implications
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1559
diff changeset
   789
in
604c4cffc5b9 Build alpha-->alphabn implications
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1559
diff changeset
   790
  flat eqs
604c4cffc5b9 Build alpha-->alphabn implications
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1559
diff changeset
   791
end
604c4cffc5b9 Build alpha-->alphabn implications
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1559
diff changeset
   792
*}
604c4cffc5b9 Build alpha-->alphabn implications
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1559
diff changeset
   793
604c4cffc5b9 Build alpha-->alphabn implications
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1559
diff changeset
   794
1301
c145c380e195 Fix equivp.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1288
diff changeset
   795
lemma exi_neg: "\<exists>(pi :: perm). P pi \<Longrightarrow> (\<And>(p :: perm). P p \<Longrightarrow> Q (- p)) \<Longrightarrow> \<exists>pi. Q pi"
c145c380e195 Fix equivp.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1288
diff changeset
   796
apply (erule exE)
c145c380e195 Fix equivp.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1288
diff changeset
   797
apply (rule_tac x="-pi" in exI)
c145c380e195 Fix equivp.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1288
diff changeset
   798
by auto
c145c380e195 Fix equivp.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1288
diff changeset
   799
1213
43bd70786f9f More equivp infrastructure.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1209
diff changeset
   800
ML {*
1334
80441e27dfd6 Code for solving symp goals with multiple existentials.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1333
diff changeset
   801
fun symp_tac induct inj eqvt ctxt =
80441e27dfd6 Code for solving symp goals with multiple existentials.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1333
diff changeset
   802
  ind_tac induct THEN_ALL_NEW
80441e27dfd6 Code for solving symp goals with multiple existentials.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1333
diff changeset
   803
  simp_tac ((mk_minimal_ss ctxt) addsimps inj) THEN_ALL_NEW split_conjs
80441e27dfd6 Code for solving symp goals with multiple existentials.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1333
diff changeset
   804
  THEN_ALL_NEW
80441e27dfd6 Code for solving symp goals with multiple existentials.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1333
diff changeset
   805
  REPEAT o etac @{thm exi_neg}
80441e27dfd6 Code for solving symp goals with multiple existentials.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1333
diff changeset
   806
  THEN_ALL_NEW
80441e27dfd6 Code for solving symp goals with multiple existentials.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1333
diff changeset
   807
  split_conjs THEN_ALL_NEW
80441e27dfd6 Code for solving symp goals with multiple existentials.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1333
diff changeset
   808
  asm_full_simp_tac (HOL_ss addsimps @{thms supp_minus_perm minus_add[symmetric]}) THEN_ALL_NEW
1487
b55b78e63913 Proper compose_sym2
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1482
diff changeset
   809
  TRY o (rtac @{thm alpha_gen_compose_sym2} ORELSE' rtac @{thm alpha_gen_compose_sym}) THEN_ALL_NEW
b55b78e63913 Proper compose_sym2
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1482
diff changeset
   810
  (asm_full_simp_tac (HOL_ss addsimps (eqvt @ all_eqvts ctxt)))
1213
43bd70786f9f More equivp infrastructure.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1209
diff changeset
   811
*}
43bd70786f9f More equivp infrastructure.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1209
diff changeset
   812
43bd70786f9f More equivp infrastructure.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1209
diff changeset
   813
ML {*
1217
74e2b9b95add Fixes for auxiliary datatypes.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1216
diff changeset
   814
fun imp_elim_tac case_rules =
74e2b9b95add Fixes for auxiliary datatypes.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1216
diff changeset
   815
  Subgoal.FOCUS (fn {concl, context, ...} =>
74e2b9b95add Fixes for auxiliary datatypes.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1216
diff changeset
   816
    case term_of concl of
74e2b9b95add Fixes for auxiliary datatypes.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1216
diff changeset
   817
      _ $ (_ $ asm $ _) =>
74e2b9b95add Fixes for auxiliary datatypes.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1216
diff changeset
   818
        let
74e2b9b95add Fixes for auxiliary datatypes.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1216
diff changeset
   819
          fun filter_fn case_rule = (
74e2b9b95add Fixes for auxiliary datatypes.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1216
diff changeset
   820
            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
   821
              ((_ $ asmc) :: _) =>
74e2b9b95add Fixes for auxiliary datatypes.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1216
diff changeset
   822
                let
74e2b9b95add Fixes for auxiliary datatypes.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1216
diff changeset
   823
                  val thy = ProofContext.theory_of context
74e2b9b95add Fixes for auxiliary datatypes.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1216
diff changeset
   824
                in
74e2b9b95add Fixes for auxiliary datatypes.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1216
diff changeset
   825
                  Pattern.matches thy (asmc, asm)
74e2b9b95add Fixes for auxiliary datatypes.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1216
diff changeset
   826
                end
74e2b9b95add Fixes for auxiliary datatypes.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1216
diff changeset
   827
            | _ => false)
74e2b9b95add Fixes for auxiliary datatypes.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1216
diff changeset
   828
          val matching_rules = filter filter_fn case_rules
74e2b9b95add Fixes for auxiliary datatypes.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1216
diff changeset
   829
        in
74e2b9b95add Fixes for auxiliary datatypes.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1216
diff changeset
   830
         (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
   831
        end
74e2b9b95add Fixes for auxiliary datatypes.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1216
diff changeset
   832
    | _ => no_tac
74e2b9b95add Fixes for auxiliary datatypes.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1216
diff changeset
   833
  )
74e2b9b95add Fixes for auxiliary datatypes.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1216
diff changeset
   834
*}
74e2b9b95add Fixes for auxiliary datatypes.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1216
diff changeset
   835
1301
c145c380e195 Fix equivp.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1288
diff changeset
   836
c145c380e195 Fix equivp.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1288
diff changeset
   837
lemma exi_sum: "\<exists>(pi :: perm). P pi \<Longrightarrow> \<exists>(pi :: perm). Q pi \<Longrightarrow> (\<And>(p :: perm) (pi :: perm). P p \<Longrightarrow> Q pi \<Longrightarrow> R (pi + p)) \<Longrightarrow> \<exists>pi. R pi"
c145c380e195 Fix equivp.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1288
diff changeset
   838
apply (erule exE)+
c145c380e195 Fix equivp.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1288
diff changeset
   839
apply (rule_tac x="pia + pi" in exI)
c145c380e195 Fix equivp.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1288
diff changeset
   840
by auto
c145c380e195 Fix equivp.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1288
diff changeset
   841
1217
74e2b9b95add Fixes for auxiliary datatypes.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1216
diff changeset
   842
ML {*
1339
5256f256edd8 Comment out Weird and Phd until we have an idea how to handle multiple permutations. Transp that works for multiple existentials.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1338
diff changeset
   843
fun is_ex (Const ("Ex", _) $ Abs _) = true
5256f256edd8 Comment out Weird and Phd until we have an idea how to handle multiple permutations. Transp that works for multiple existentials.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1338
diff changeset
   844
  | is_ex _ = false;
5256f256edd8 Comment out Weird and Phd until we have an idea how to handle multiple permutations. Transp that works for multiple existentials.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1338
diff changeset
   845
*}
5256f256edd8 Comment out Weird and Phd until we have an idea how to handle multiple permutations. Transp that works for multiple existentials.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1338
diff changeset
   846
5256f256edd8 Comment out Weird and Phd until we have an idea how to handle multiple permutations. Transp that works for multiple existentials.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1338
diff changeset
   847
ML {*
5256f256edd8 Comment out Weird and Phd until we have an idea how to handle multiple permutations. Transp that works for multiple existentials.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1338
diff changeset
   848
fun eetac rule = Subgoal.FOCUS_PARAMS 
5256f256edd8 Comment out Weird and Phd until we have an idea how to handle multiple permutations. Transp that works for multiple existentials.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1338
diff changeset
   849
  (fn (focus) =>
5256f256edd8 Comment out Weird and Phd until we have an idea how to handle multiple permutations. Transp that works for multiple existentials.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1338
diff changeset
   850
     let
5256f256edd8 Comment out Weird and Phd until we have an idea how to handle multiple permutations. Transp that works for multiple existentials.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1338
diff changeset
   851
       val concl = #concl focus
5256f256edd8 Comment out Weird and Phd until we have an idea how to handle multiple permutations. Transp that works for multiple existentials.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1338
diff changeset
   852
       val prems = Logic.strip_imp_prems (term_of concl)
5256f256edd8 Comment out Weird and Phd until we have an idea how to handle multiple permutations. Transp that works for multiple existentials.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1338
diff changeset
   853
       val exs = filter (fn x => is_ex (HOLogic.dest_Trueprop x)) prems
5256f256edd8 Comment out Weird and Phd until we have an idea how to handle multiple permutations. Transp that works for multiple existentials.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1338
diff changeset
   854
       val cexs = map (SOME o (cterm_of (ProofContext.theory_of (#context focus)))) exs
5256f256edd8 Comment out Weird and Phd until we have an idea how to handle multiple permutations. Transp that works for multiple existentials.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1338
diff changeset
   855
       val thins = map (fn cex => Drule.instantiate' [] [cex] Drule.thin_rl) cexs
5256f256edd8 Comment out Weird and Phd until we have an idea how to handle multiple permutations. Transp that works for multiple existentials.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1338
diff changeset
   856
     in
5256f256edd8 Comment out Weird and Phd until we have an idea how to handle multiple permutations. Transp that works for multiple existentials.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1338
diff changeset
   857
     (etac rule THEN' RANGE[
5256f256edd8 Comment out Weird and Phd until we have an idea how to handle multiple permutations. Transp that works for multiple existentials.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1338
diff changeset
   858
        atac,
5256f256edd8 Comment out Weird and Phd until we have an idea how to handle multiple permutations. Transp that works for multiple existentials.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1338
diff changeset
   859
        eresolve_tac thins
5256f256edd8 Comment out Weird and Phd until we have an idea how to handle multiple permutations. Transp that works for multiple existentials.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1338
diff changeset
   860
     ]) 1
5256f256edd8 Comment out Weird and Phd until we have an idea how to handle multiple permutations. Transp that works for multiple existentials.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1338
diff changeset
   861
     end
5256f256edd8 Comment out Weird and Phd until we have an idea how to handle multiple permutations. Transp that works for multiple existentials.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1338
diff changeset
   862
  )
5256f256edd8 Comment out Weird and Phd until we have an idea how to handle multiple permutations. Transp that works for multiple existentials.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1338
diff changeset
   863
*}
5256f256edd8 Comment out Weird and Phd until we have an idea how to handle multiple permutations. Transp that works for multiple existentials.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1338
diff changeset
   864
5256f256edd8 Comment out Weird and Phd until we have an idea how to handle multiple permutations. Transp that works for multiple existentials.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1338
diff changeset
   865
ML {*
1217
74e2b9b95add Fixes for auxiliary datatypes.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1216
diff changeset
   866
fun transp_tac ctxt induct alpha_inj term_inj distinct cases eqvt =
1339
5256f256edd8 Comment out Weird and Phd until we have an idea how to handle multiple permutations. Transp that works for multiple existentials.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1338
diff changeset
   867
  ind_tac induct THEN_ALL_NEW
1217
74e2b9b95add Fixes for auxiliary datatypes.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1216
diff changeset
   868
  (TRY o rtac allI THEN' imp_elim_tac cases ctxt) THEN_ALL_NEW
1339
5256f256edd8 Comment out Weird and Phd until we have an idea how to handle multiple permutations. Transp that works for multiple existentials.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1338
diff changeset
   869
  asm_full_simp_tac ((mk_minimal_ss ctxt) addsimps alpha_inj) THEN_ALL_NEW
5256f256edd8 Comment out Weird and Phd until we have an idea how to handle multiple permutations. Transp that works for multiple existentials.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1338
diff changeset
   870
  split_conjs THEN_ALL_NEW REPEAT o (eetac @{thm exi_sum} ctxt) THEN_ALL_NEW split_conjs
5256f256edd8 Comment out Weird and Phd until we have an idea how to handle multiple permutations. Transp that works for multiple existentials.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1338
diff changeset
   871
  THEN_ALL_NEW (asm_full_simp_tac (HOL_ss addsimps (term_inj @ distinct)))
5256f256edd8 Comment out Weird and Phd until we have an idea how to handle multiple permutations. Transp that works for multiple existentials.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1338
diff changeset
   872
  THEN_ALL_NEW split_conjs THEN_ALL_NEW
1581
6b1eea8dcdc0 equivp_cheat can be removed for all one-permutation examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1560
diff changeset
   873
  TRY o (etac @{thm alpha_gen_compose_trans2} ORELSE' etac @{thm alpha_gen_compose_trans}) THEN_ALL_NEW
1339
5256f256edd8 Comment out Weird and Phd until we have an idea how to handle multiple permutations. Transp that works for multiple existentials.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1338
diff changeset
   874
  (asm_full_simp_tac (HOL_ss addsimps (all_eqvts ctxt @ eqvt @ term_inj @ distinct)))
1213
43bd70786f9f More equivp infrastructure.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1209
diff changeset
   875
*}
43bd70786f9f More equivp infrastructure.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1209
diff changeset
   876
1581
6b1eea8dcdc0 equivp_cheat can be removed for all one-permutation examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1560
diff changeset
   877
lemma transpI:
1215
aec9576b3950 Testing auto equivp code.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1214
diff changeset
   878
  "(\<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
   879
  unfolding transp_def
aec9576b3950 Testing auto equivp code.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1214
diff changeset
   880
  by blast
aec9576b3950 Testing auto equivp code.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1214
diff changeset
   881
aec9576b3950 Testing auto equivp code.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1214
diff changeset
   882
ML {*
aec9576b3950 Testing auto equivp code.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1214
diff changeset
   883
fun equivp_tac reflps symps transps =
1609
c9bc3b61046c Modification to Core Haskell to make it accepted with an empty binding function.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1581
diff changeset
   884
  (*let val _ = tracing (PolyML.makestring (reflps, symps, transps)) in *)
1215
aec9576b3950 Testing auto equivp code.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1214
diff changeset
   885
  simp_tac (HOL_ss addsimps @{thms equivp_reflp_symp_transp reflp_def symp_def})
1221
526fad251a8e Minor beutification.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1217
diff changeset
   886
  THEN' rtac conjI THEN' rtac allI THEN'
1215
aec9576b3950 Testing auto equivp code.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1214
diff changeset
   887
  resolve_tac reflps THEN'
1221
526fad251a8e Minor beutification.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1217
diff changeset
   888
  rtac conjI THEN' rtac allI THEN' rtac allI THEN'
1215
aec9576b3950 Testing auto equivp code.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1214
diff changeset
   889
  resolve_tac symps THEN'
1581
6b1eea8dcdc0 equivp_cheat can be removed for all one-permutation examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1560
diff changeset
   890
  rtac @{thm transpI} THEN' resolve_tac transps
1215
aec9576b3950 Testing auto equivp code.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1214
diff changeset
   891
*}
aec9576b3950 Testing auto equivp code.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1214
diff changeset
   892
1213
43bd70786f9f More equivp infrastructure.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1209
diff changeset
   893
ML {*
1559
d375804ce6ba Prove reflp for all relations.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1553
diff changeset
   894
fun build_equivps alphas reflps 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
   895
let
1214
0f92257edeee A tactic for final equivp
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1213
diff changeset
   896
  val ([x, y, z], ctxt') = Variable.variant_fixes ["x","y","z"] ctxt;
1559
d375804ce6ba Prove reflp for all relations.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1553
diff changeset
   897
  val (symg, transg) = build_alpha_sym_trans_gl alphas (x, y, z)
1334
80441e27dfd6 Code for solving symp goals with multiple existentials.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1333
diff changeset
   898
  fun symp_tac' _ = symp_tac alpha_induct alpha_inj eqvt ctxt 1;
1217
74e2b9b95add Fixes for auxiliary datatypes.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1216
diff changeset
   899
  fun transp_tac' _ = transp_tac ctxt alpha_induct alpha_inj term_inj distinct cases eqvt 1;
1559
d375804ce6ba Prove reflp for all relations.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1553
diff changeset
   900
  val symp_loc = Goal.prove ctxt' [] [] symg symp_tac';
d375804ce6ba Prove reflp for all relations.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1553
diff changeset
   901
  val transp_loc = Goal.prove ctxt' [] [] transg transp_tac';
d375804ce6ba Prove reflp for all relations.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1553
diff changeset
   902
  val [symp, transp] = Variable.export ctxt' ctxt [symp_loc, transp_loc]
d375804ce6ba Prove reflp for all relations.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1553
diff changeset
   903
  val symps = HOLogic.conj_elims symp
d375804ce6ba Prove reflp for all relations.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1553
diff changeset
   904
  val transps = HOLogic.conj_elims transp
1214
0f92257edeee A tactic for final equivp
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1213
diff changeset
   905
  fun equivp alpha =
0f92257edeee A tactic for final equivp
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1213
diff changeset
   906
    let
1215
aec9576b3950 Testing auto equivp code.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1214
diff changeset
   907
      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
   908
      val goal = @{term Trueprop} $ (equivp $ alpha)
1559
d375804ce6ba Prove reflp for all relations.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1553
diff changeset
   909
      fun tac _ = equivp_tac reflps symps transps 1
1215
aec9576b3950 Testing auto equivp code.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1214
diff changeset
   910
    in
aec9576b3950 Testing auto equivp code.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1214
diff changeset
   911
      Goal.prove ctxt [] [] goal tac
aec9576b3950 Testing auto equivp code.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1214
diff changeset
   912
    end
1213
43bd70786f9f More equivp infrastructure.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1209
diff changeset
   913
in
1215
aec9576b3950 Testing auto equivp code.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1214
diff changeset
   914
  map equivp alphas
1213
43bd70786f9f More equivp infrastructure.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1209
diff changeset
   915
end
43bd70786f9f More equivp infrastructure.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1209
diff changeset
   916
*}
1207
fb33684e4ece alpha reflexivity
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1206
diff changeset
   917
1217
74e2b9b95add Fixes for auxiliary datatypes.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1216
diff changeset
   918
(*
74e2b9b95add Fixes for auxiliary datatypes.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1216
diff changeset
   919
Tests:
74e2b9b95add Fixes for auxiliary datatypes.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1216
diff changeset
   920
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
   921
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
   922
74e2b9b95add Fixes for auxiliary datatypes.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1216
diff changeset
   923
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
   924
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
   925
74e2b9b95add Fixes for auxiliary datatypes.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1216
diff changeset
   926
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
   927
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
   928
74e2b9b95add Fixes for auxiliary datatypes.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1216
diff changeset
   929
lemma alpha1_equivp:
74e2b9b95add Fixes for auxiliary datatypes.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1216
diff changeset
   930
  "equivp alpha_rtrm1"
74e2b9b95add Fixes for auxiliary datatypes.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1216
diff changeset
   931
  "equivp alpha_bp"
74e2b9b95add Fixes for auxiliary datatypes.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1216
diff changeset
   932
apply (tactic {*
74e2b9b95add Fixes for auxiliary datatypes.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1216
diff changeset
   933
  (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
   934
  THEN' rtac @{thm conjI} THEN' rtac @{thm allI} THEN'
74e2b9b95add Fixes for auxiliary datatypes.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1216
diff changeset
   935
  resolve_tac (HOLogic.conj_elims @{thm alpha1_reflp_aux})
74e2b9b95add Fixes for auxiliary datatypes.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1216
diff changeset
   936
  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
   937
  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
   938
  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
   939
)
74e2b9b95add Fixes for auxiliary datatypes.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1216
diff changeset
   940
1 *})
74e2b9b95add Fixes for auxiliary datatypes.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1216
diff changeset
   941
done*)
74e2b9b95add Fixes for auxiliary datatypes.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1216
diff changeset
   942
1308
80dabcaafc38 Moving wrappers out of Lift.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1303
diff changeset
   943
ML {*
80dabcaafc38 Moving wrappers out of Lift.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1303
diff changeset
   944
fun dtyp_no_of_typ _ (TFree (n, _)) = error "dtyp_no_of_typ: Illegal free"
80dabcaafc38 Moving wrappers out of Lift.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1303
diff changeset
   945
  | dtyp_no_of_typ _ (TVar _) = error "dtyp_no_of_typ: Illegal schematic"
80dabcaafc38 Moving wrappers out of Lift.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1303
diff changeset
   946
  | dtyp_no_of_typ dts (Type (tname, Ts)) =
80dabcaafc38 Moving wrappers out of Lift.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1303
diff changeset
   947
      case try (find_index (curry op = tname o fst)) dts of
80dabcaafc38 Moving wrappers out of Lift.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1303
diff changeset
   948
        NONE => error "dtyp_no_of_typ: Illegal recursion"
80dabcaafc38 Moving wrappers out of Lift.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1303
diff changeset
   949
      | SOME i => i
80dabcaafc38 Moving wrappers out of Lift.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1303
diff changeset
   950
*}
80dabcaafc38 Moving wrappers out of Lift.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1303
diff changeset
   951
1427
b355cab42841 mk_supports_eq and supports_tac.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1422
diff changeset
   952
lemma not_in_union: "c \<notin> a \<union> b \<equiv> (c \<notin> a \<and> c \<notin> b)"
b355cab42841 mk_supports_eq and supports_tac.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1422
diff changeset
   953
by auto
b355cab42841 mk_supports_eq and supports_tac.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1422
diff changeset
   954
b355cab42841 mk_supports_eq and supports_tac.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1422
diff changeset
   955
ML {*
b355cab42841 mk_supports_eq and supports_tac.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1422
diff changeset
   956
fun supports_tac perm =
b355cab42841 mk_supports_eq and supports_tac.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1422
diff changeset
   957
  simp_tac (HOL_ss addsimps @{thms supports_def not_in_union} @ perm) THEN_ALL_NEW (
b355cab42841 mk_supports_eq and supports_tac.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1422
diff changeset
   958
    REPEAT o rtac allI THEN' REPEAT o rtac impI THEN' split_conjs THEN'
b355cab42841 mk_supports_eq and supports_tac.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1422
diff changeset
   959
    asm_full_simp_tac (HOL_ss addsimps @{thms fresh_def[symmetric]
1534
984ea1299cd7 The nominal infrastructure for fset. 'fs' missing, but not needed so far.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1516
diff changeset
   960
      swap_fresh_fresh fresh_atom swap_at_base_simps(3) swap_atom_image_fresh
984ea1299cd7 The nominal infrastructure for fset. 'fs' missing, but not needed so far.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1516
diff changeset
   961
      supp_fset_to_set supp_fmap_atom}))
1427
b355cab42841 mk_supports_eq and supports_tac.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1422
diff changeset
   962
*}
b355cab42841 mk_supports_eq and supports_tac.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1422
diff changeset
   963
b355cab42841 mk_supports_eq and supports_tac.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1422
diff changeset
   964
ML {*
1428
4029105011ca Show that the new types are in finite support typeclass.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1427
diff changeset
   965
fun mk_supp ty x =
4029105011ca Show that the new types are in finite support typeclass.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1427
diff changeset
   966
  Const (@{const_name supp}, ty --> @{typ "atom set"}) $ x
4029105011ca Show that the new types are in finite support typeclass.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1427
diff changeset
   967
*}
4029105011ca Show that the new types are in finite support typeclass.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1427
diff changeset
   968
4029105011ca Show that the new types are in finite support typeclass.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1427
diff changeset
   969
ML {*
4029105011ca Show that the new types are in finite support typeclass.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1427
diff changeset
   970
fun mk_supports_eq thy cnstr =
1427
b355cab42841 mk_supports_eq and supports_tac.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1422
diff changeset
   971
let
b355cab42841 mk_supports_eq and supports_tac.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1422
diff changeset
   972
  val (tys, ty) = (strip_type o fastype_of) cnstr
b355cab42841 mk_supports_eq and supports_tac.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1422
diff changeset
   973
  val names = Datatype_Prop.make_tnames tys
b355cab42841 mk_supports_eq and supports_tac.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1422
diff changeset
   974
  val frees = map Free (names ~~ tys)
b355cab42841 mk_supports_eq and supports_tac.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1422
diff changeset
   975
  val rhs = list_comb (cnstr, frees)
1428
4029105011ca Show that the new types are in finite support typeclass.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1427
diff changeset
   976
1427
b355cab42841 mk_supports_eq and supports_tac.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1422
diff changeset
   977
  fun mk_supp_arg (x, ty) =
1428
4029105011ca Show that the new types are in finite support typeclass.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1427
diff changeset
   978
    if is_atom thy ty then mk_supp @{typ atom} (mk_atom ty $ x) else
1534
984ea1299cd7 The nominal infrastructure for fset. 'fs' missing, but not needed so far.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1516
diff changeset
   979
    if is_atom_set thy ty then mk_supp @{typ "atom set"} (mk_atom_set x) else
984ea1299cd7 The nominal infrastructure for fset. 'fs' missing, but not needed so far.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1516
diff changeset
   980
    if is_atom_fset thy ty then mk_supp @{typ "atom set"} (mk_atom_fset x)
1427
b355cab42841 mk_supports_eq and supports_tac.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1422
diff changeset
   981
    else mk_supp ty x
b355cab42841 mk_supports_eq and supports_tac.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1422
diff changeset
   982
  val lhss = map mk_supp_arg (frees ~~ tys)
b355cab42841 mk_supports_eq and supports_tac.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1422
diff changeset
   983
  val supports = Const(@{const_name "supports"}, @{typ "atom set"} --> ty --> @{typ bool})
b355cab42841 mk_supports_eq and supports_tac.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1422
diff changeset
   984
  val eq = HOLogic.mk_Trueprop (supports $ mk_union lhss $ rhs)
b355cab42841 mk_supports_eq and supports_tac.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1422
diff changeset
   985
in
b355cab42841 mk_supports_eq and supports_tac.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1422
diff changeset
   986
  (names, eq)
1422
a26cb19375e8 Remove "_raw" from lifted theorems.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1415
diff changeset
   987
end
1427
b355cab42841 mk_supports_eq and supports_tac.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1422
diff changeset
   988
*}
b355cab42841 mk_supports_eq and supports_tac.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1422
diff changeset
   989
1428
4029105011ca Show that the new types are in finite support typeclass.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1427
diff changeset
   990
ML {*
4029105011ca Show that the new types are in finite support typeclass.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1427
diff changeset
   991
fun prove_supports ctxt perms cnst =
4029105011ca Show that the new types are in finite support typeclass.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1427
diff changeset
   992
let
4029105011ca Show that the new types are in finite support typeclass.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1427
diff changeset
   993
  val (names, eq) = mk_supports_eq (ProofContext.theory_of ctxt) cnst
4029105011ca Show that the new types are in finite support typeclass.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1427
diff changeset
   994
in
4029105011ca Show that the new types are in finite support typeclass.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1427
diff changeset
   995
  Goal.prove ctxt names [] eq (fn _ => supports_tac perms 1)
1427
b355cab42841 mk_supports_eq and supports_tac.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1422
diff changeset
   996
end
1428
4029105011ca Show that the new types are in finite support typeclass.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1427
diff changeset
   997
*}
4029105011ca Show that the new types are in finite support typeclass.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1427
diff changeset
   998
4029105011ca Show that the new types are in finite support typeclass.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1427
diff changeset
   999
ML {*
4029105011ca Show that the new types are in finite support typeclass.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1427
diff changeset
  1000
fun mk_fs tys =
4029105011ca Show that the new types are in finite support typeclass.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1427
diff changeset
  1001
let
4029105011ca Show that the new types are in finite support typeclass.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1427
diff changeset
  1002
  val names = Datatype_Prop.make_tnames tys
4029105011ca Show that the new types are in finite support typeclass.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1427
diff changeset
  1003
  val frees = map Free (names ~~ tys)
4029105011ca Show that the new types are in finite support typeclass.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1427
diff changeset
  1004
  val supps = map2 mk_supp tys frees
4029105011ca Show that the new types are in finite support typeclass.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1427
diff changeset
  1005
  val fin_supps = map (fn x => @{term "finite :: atom set \<Rightarrow> bool"} $ x) supps
4029105011ca Show that the new types are in finite support typeclass.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1427
diff changeset
  1006
in
4029105011ca Show that the new types are in finite support typeclass.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1427
diff changeset
  1007
  (names, HOLogic.mk_Trueprop (mk_conjl fin_supps))
4029105011ca Show that the new types are in finite support typeclass.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1427
diff changeset
  1008
end
4029105011ca Show that the new types are in finite support typeclass.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1427
diff changeset
  1009
*}
4029105011ca Show that the new types are in finite support typeclass.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1427
diff changeset
  1010
4029105011ca Show that the new types are in finite support typeclass.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1427
diff changeset
  1011
ML {*
4029105011ca Show that the new types are in finite support typeclass.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1427
diff changeset
  1012
fun fs_tac induct supports = ind_tac induct THEN_ALL_NEW (
4029105011ca Show that the new types are in finite support typeclass.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1427
diff changeset
  1013
  rtac @{thm supports_finite} THEN' resolve_tac supports) THEN_ALL_NEW
1534
984ea1299cd7 The nominal infrastructure for fset. 'fs' missing, but not needed so far.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1516
diff changeset
  1014
  asm_full_simp_tac (HOL_ss addsimps @{thms supp_atom supp_atom_image supp_fset_to_set
1547
57f7af5d7564 Use fs typeclass in showing finite support + some cheat cleaning.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1534
diff changeset
  1015
    supp_fmap_atom finite_insert finite.emptyI finite_Un finite_supp})
1428
4029105011ca Show that the new types are in finite support typeclass.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1427
diff changeset
  1016
*}
4029105011ca Show that the new types are in finite support typeclass.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1427
diff changeset
  1017
4029105011ca Show that the new types are in finite support typeclass.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1427
diff changeset
  1018
ML {*
4029105011ca Show that the new types are in finite support typeclass.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1427
diff changeset
  1019
fun prove_fs ctxt induct supports tys =
4029105011ca Show that the new types are in finite support typeclass.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1427
diff changeset
  1020
let
4029105011ca Show that the new types are in finite support typeclass.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1427
diff changeset
  1021
  val (names, eq) = mk_fs tys
4029105011ca Show that the new types are in finite support typeclass.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1427
diff changeset
  1022
in
4029105011ca Show that the new types are in finite support typeclass.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1427
diff changeset
  1023
  Goal.prove ctxt names [] eq (fn _ => fs_tac induct supports 1)
4029105011ca Show that the new types are in finite support typeclass.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1427
diff changeset
  1024
end
4029105011ca Show that the new types are in finite support typeclass.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1427
diff changeset
  1025
*}
4029105011ca Show that the new types are in finite support typeclass.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1427
diff changeset
  1026
1553
4355eb3b7161 Automatically derive support for datatypes with at-most one binding per constructor.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1547
diff changeset
  1027
ML {*
4355eb3b7161 Automatically derive support for datatypes with at-most one binding per constructor.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1547
diff changeset
  1028
fun mk_supp x = Const (@{const_name supp}, fastype_of x --> @{typ "atom set"}) $ x;
4355eb3b7161 Automatically derive support for datatypes with at-most one binding per constructor.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1547
diff changeset
  1029
4355eb3b7161 Automatically derive support for datatypes with at-most one binding per constructor.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1547
diff changeset
  1030
fun mk_supp_neq arg (fv, alpha) =
4355eb3b7161 Automatically derive support for datatypes with at-most one binding per constructor.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1547
diff changeset
  1031
let
4355eb3b7161 Automatically derive support for datatypes with at-most one binding per constructor.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1547
diff changeset
  1032
  val collect = Const ("Collect", @{typ "(atom \<Rightarrow> bool) \<Rightarrow> atom \<Rightarrow> bool"});
4355eb3b7161 Automatically derive support for datatypes with at-most one binding per constructor.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1547
diff changeset
  1033
  val ty = fastype_of arg;
4355eb3b7161 Automatically derive support for datatypes with at-most one binding per constructor.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1547
diff changeset
  1034
  val perm = Const ("Nominal2_Base.pt_class.permute", @{typ perm} --> ty --> ty);
4355eb3b7161 Automatically derive support for datatypes with at-most one binding per constructor.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1547
diff changeset
  1035
  val finite = @{term "finite :: atom set \<Rightarrow> bool"}
4355eb3b7161 Automatically derive support for datatypes with at-most one binding per constructor.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1547
diff changeset
  1036
  val rhs = collect $ Abs ("a", @{typ atom},
4355eb3b7161 Automatically derive support for datatypes with at-most one binding per constructor.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1547
diff changeset
  1037
    HOLogic.mk_not (finite $
4355eb3b7161 Automatically derive support for datatypes with at-most one binding per constructor.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1547
diff changeset
  1038
      (collect $ Abs ("b", @{typ atom},
4355eb3b7161 Automatically derive support for datatypes with at-most one binding per constructor.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1547
diff changeset
  1039
        HOLogic.mk_not (alpha $ (perm $ (@{term swap} $ Bound 1 $ Bound 0) $ arg) $ arg)))))
4355eb3b7161 Automatically derive support for datatypes with at-most one binding per constructor.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1547
diff changeset
  1040
in
4355eb3b7161 Automatically derive support for datatypes with at-most one binding per constructor.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1547
diff changeset
  1041
  HOLogic.mk_eq (fv $ arg, rhs)
4355eb3b7161 Automatically derive support for datatypes with at-most one binding per constructor.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1547
diff changeset
  1042
end;
4355eb3b7161 Automatically derive support for datatypes with at-most one binding per constructor.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1547
diff changeset
  1043
4355eb3b7161 Automatically derive support for datatypes with at-most one binding per constructor.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1547
diff changeset
  1044
fun supp_eq fv_alphas_lst =
4355eb3b7161 Automatically derive support for datatypes with at-most one binding per constructor.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1547
diff changeset
  1045
let
4355eb3b7161 Automatically derive support for datatypes with at-most one binding per constructor.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1547
diff changeset
  1046
  val (fvs_alphas, ls) = split_list fv_alphas_lst;
4355eb3b7161 Automatically derive support for datatypes with at-most one binding per constructor.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1547
diff changeset
  1047
  val (fv_ts, _) = split_list fvs_alphas;
4355eb3b7161 Automatically derive support for datatypes with at-most one binding per constructor.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1547
diff changeset
  1048
  val tys = map (domain_type o fastype_of) fv_ts;
4355eb3b7161 Automatically derive support for datatypes with at-most one binding per constructor.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1547
diff changeset
  1049
  val names = Datatype_Prop.make_tnames tys;
4355eb3b7161 Automatically derive support for datatypes with at-most one binding per constructor.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1547
diff changeset
  1050
  val args = map Free (names ~~ tys);
4355eb3b7161 Automatically derive support for datatypes with at-most one binding per constructor.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1547
diff changeset
  1051
  fun supp_eq_arg ((fv, arg), l) =
4355eb3b7161 Automatically derive support for datatypes with at-most one binding per constructor.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1547
diff changeset
  1052
    mk_conjl
4355eb3b7161 Automatically derive support for datatypes with at-most one binding per constructor.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1547
diff changeset
  1053
      ((HOLogic.mk_eq (fv $ arg, mk_supp arg)) ::
4355eb3b7161 Automatically derive support for datatypes with at-most one binding per constructor.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1547
diff changeset
  1054
       (map (mk_supp_neq arg) l))
4355eb3b7161 Automatically derive support for datatypes with at-most one binding per constructor.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1547
diff changeset
  1055
  val eqs = mk_conjl (map supp_eq_arg ((fv_ts ~~ args) ~~ ls))
4355eb3b7161 Automatically derive support for datatypes with at-most one binding per constructor.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1547
diff changeset
  1056
in
4355eb3b7161 Automatically derive support for datatypes with at-most one binding per constructor.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1547
diff changeset
  1057
  (names, HOLogic.mk_Trueprop eqs)
1428
4029105011ca Show that the new types are in finite support typeclass.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1427
diff changeset
  1058
end
1553
4355eb3b7161 Automatically derive support for datatypes with at-most one binding per constructor.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1547
diff changeset
  1059
*}
4355eb3b7161 Automatically derive support for datatypes with at-most one binding per constructor.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1547
diff changeset
  1060
4355eb3b7161 Automatically derive support for datatypes with at-most one binding per constructor.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1547
diff changeset
  1061
ML {*
4355eb3b7161 Automatically derive support for datatypes with at-most one binding per constructor.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1547
diff changeset
  1062
fun combine_fv_alpha_bns (fv_ts_nobn, fv_ts_bn) (alpha_ts_nobn, alpha_ts_bn) bn_nos =
4355eb3b7161 Automatically derive support for datatypes with at-most one binding per constructor.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1547
diff changeset
  1063
if length fv_ts_bn < length alpha_ts_bn then
4355eb3b7161 Automatically derive support for datatypes with at-most one binding per constructor.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1547
diff changeset
  1064
  (fv_ts_nobn ~~ alpha_ts_nobn) ~~ (replicate (length fv_ts_nobn) [])
4355eb3b7161 Automatically derive support for datatypes with at-most one binding per constructor.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1547
diff changeset
  1065
else let
4355eb3b7161 Automatically derive support for datatypes with at-most one binding per constructor.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1547
diff changeset
  1066
  val fv_alpha_nos = 0 upto (length fv_ts_nobn - 1);
4355eb3b7161 Automatically derive support for datatypes with at-most one binding per constructor.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1547
diff changeset
  1067
  fun filter_fn i (x, j) = if j = i then SOME x else NONE;
4355eb3b7161 Automatically derive support for datatypes with at-most one binding per constructor.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1547
diff changeset
  1068
  val fv_alpha_bn_nos = (fv_ts_bn ~~ alpha_ts_bn) ~~ bn_nos;
4355eb3b7161 Automatically derive support for datatypes with at-most one binding per constructor.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1547
diff changeset
  1069
  val fv_alpha_bn_all = map (fn i => map_filter (filter_fn i) fv_alpha_bn_nos) fv_alpha_nos;
4355eb3b7161 Automatically derive support for datatypes with at-most one binding per constructor.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1547
diff changeset
  1070
in
4355eb3b7161 Automatically derive support for datatypes with at-most one binding per constructor.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1547
diff changeset
  1071
  (fv_ts_nobn ~~ alpha_ts_nobn) ~~ fv_alpha_bn_all
4355eb3b7161 Automatically derive support for datatypes with at-most one binding per constructor.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1547
diff changeset
  1072
end
4355eb3b7161 Automatically derive support for datatypes with at-most one binding per constructor.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1547
diff changeset
  1073
*}
4355eb3b7161 Automatically derive support for datatypes with at-most one binding per constructor.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1547
diff changeset
  1074
4355eb3b7161 Automatically derive support for datatypes with at-most one binding per constructor.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1547
diff changeset
  1075
lemma supp_abs_sum: "supp (Abs x (a :: 'a :: fs)) \<union> supp (Abs x (b :: 'b :: fs)) = supp (Abs x (a, b))"
4355eb3b7161 Automatically derive support for datatypes with at-most one binding per constructor.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1547
diff changeset
  1076
  apply (simp add: supp_Abs supp_Pair)
4355eb3b7161 Automatically derive support for datatypes with at-most one binding per constructor.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1547
diff changeset
  1077
  apply blast
4355eb3b7161 Automatically derive support for datatypes with at-most one binding per constructor.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1547
diff changeset
  1078
  done
4355eb3b7161 Automatically derive support for datatypes with at-most one binding per constructor.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1547
diff changeset
  1079
4355eb3b7161 Automatically derive support for datatypes with at-most one binding per constructor.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1547
diff changeset
  1080
ML {*
4355eb3b7161 Automatically derive support for datatypes with at-most one binding per constructor.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1547
diff changeset
  1081
fun supp_eq_tac ind fv perm eqiff ctxt =
4355eb3b7161 Automatically derive support for datatypes with at-most one binding per constructor.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1547
diff changeset
  1082
  ind_tac ind THEN_ALL_NEW
4355eb3b7161 Automatically derive support for datatypes with at-most one binding per constructor.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1547
diff changeset
  1083
  asm_full_simp_tac (HOL_basic_ss addsimps fv) THEN_ALL_NEW
4355eb3b7161 Automatically derive support for datatypes with at-most one binding per constructor.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1547
diff changeset
  1084
  asm_full_simp_tac (HOL_basic_ss addsimps @{thms supp_Abs[symmetric]}) THEN_ALL_NEW
4355eb3b7161 Automatically derive support for datatypes with at-most one binding per constructor.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1547
diff changeset
  1085
  simp_tac (HOL_basic_ss addsimps @{thms supp_abs_sum}) THEN_ALL_NEW
4355eb3b7161 Automatically derive support for datatypes with at-most one binding per constructor.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1547
diff changeset
  1086
  simp_tac (HOL_basic_ss addsimps @{thms supp_def}) THEN_ALL_NEW
4355eb3b7161 Automatically derive support for datatypes with at-most one binding per constructor.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1547
diff changeset
  1087
  simp_tac (HOL_basic_ss addsimps (@{thm permute_ABS} :: perm)) THEN_ALL_NEW
4355eb3b7161 Automatically derive support for datatypes with at-most one binding per constructor.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1547
diff changeset
  1088
  simp_tac (HOL_basic_ss addsimps (@{thm Abs_eq_iff} :: eqiff)) THEN_ALL_NEW
4355eb3b7161 Automatically derive support for datatypes with at-most one binding per constructor.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1547
diff changeset
  1089
  simp_tac (HOL_basic_ss addsimps @{thms alpha_gen2}) THEN_ALL_NEW
4355eb3b7161 Automatically derive support for datatypes with at-most one binding per constructor.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1547
diff changeset
  1090
  simp_tac (HOL_basic_ss addsimps @{thms alpha_gen}) THEN_ALL_NEW
4355eb3b7161 Automatically derive support for datatypes with at-most one binding per constructor.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1547
diff changeset
  1091
  asm_full_simp_tac (HOL_basic_ss addsimps (@{thm supp_Pair} :: sym_eqvts ctxt)) THEN_ALL_NEW
4355eb3b7161 Automatically derive support for datatypes with at-most one binding per constructor.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1547
diff changeset
  1092
  asm_full_simp_tac (HOL_basic_ss addsimps (@{thm Pair_eq} :: all_eqvts ctxt)) THEN_ALL_NEW
4355eb3b7161 Automatically derive support for datatypes with at-most one binding per constructor.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1547
diff changeset
  1093
  simp_tac (HOL_basic_ss addsimps @{thms supp_at_base[symmetric,simplified supp_def]}) THEN_ALL_NEW
1625
6ad74d73e1b1 Support proof modification for Core Haskell.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1622
diff changeset
  1094
  simp_tac (HOL_basic_ss addsimps @{thms Collect_disj_eq[symmetric]}) THEN_ALL_NEW
6ad74d73e1b1 Support proof modification for Core Haskell.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1622
diff changeset
  1095
  simp_tac (HOL_basic_ss addsimps @{thms infinite_Un[symmetric]}) THEN_ALL_NEW
6ad74d73e1b1 Support proof modification for Core Haskell.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1622
diff changeset
  1096
  simp_tac (HOL_basic_ss addsimps @{thms Collect_disj_eq[symmetric]}) THEN_ALL_NEW
1553
4355eb3b7161 Automatically derive support for datatypes with at-most one binding per constructor.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1547
diff changeset
  1097
  simp_tac (HOL_basic_ss addsimps @{thms de_Morgan_conj[symmetric]}) THEN_ALL_NEW
1625
6ad74d73e1b1 Support proof modification for Core Haskell.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1622
diff changeset
  1098
  simp_tac (HOL_basic_ss addsimps @{thms ex_simps(1,2)[symmetric]}) THEN_ALL_NEW
1553
4355eb3b7161 Automatically derive support for datatypes with at-most one binding per constructor.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1547
diff changeset
  1099
  simp_tac (HOL_ss addsimps @{thms Collect_const finite.emptyI})
4355eb3b7161 Automatically derive support for datatypes with at-most one binding per constructor.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1547
diff changeset
  1100
*}
4355eb3b7161 Automatically derive support for datatypes with at-most one binding per constructor.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1547
diff changeset
  1101
1650
4b949985cf57 Gathering things to prove by induction together; removed cheat_bn_eqvt.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1625
diff changeset
  1102
(* Given function for buildng a goal for an input, prepares a
4b949985cf57 Gathering things to prove by induction together; removed cheat_bn_eqvt.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1625
diff changeset
  1103
   one common goals for all the inputs and proves it by induction
4b949985cf57 Gathering things to prove by induction together; removed cheat_bn_eqvt.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1625
diff changeset
  1104
   together *)
4b949985cf57 Gathering things to prove by induction together; removed cheat_bn_eqvt.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1625
diff changeset
  1105
ML {*
4b949985cf57 Gathering things to prove by induction together; removed cheat_bn_eqvt.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1625
diff changeset
  1106
fun prove_by_induct tys build_goal ind utac inputs ctxt =
4b949985cf57 Gathering things to prove by induction together; removed cheat_bn_eqvt.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1625
diff changeset
  1107
let
4b949985cf57 Gathering things to prove by induction together; removed cheat_bn_eqvt.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1625
diff changeset
  1108
  val names = Datatype_Prop.make_tnames tys;
4b949985cf57 Gathering things to prove by induction together; removed cheat_bn_eqvt.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1625
diff changeset
  1109
  val (names', ctxt') = Variable.variant_fixes names ctxt;
4b949985cf57 Gathering things to prove by induction together; removed cheat_bn_eqvt.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1625
diff changeset
  1110
  val frees = map Free (names' ~~ tys);
4b949985cf57 Gathering things to prove by induction together; removed cheat_bn_eqvt.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1625
diff changeset
  1111
  val (gls_lists, ctxt'') = fold_map (build_goal (tys ~~ frees)) inputs ctxt';
4b949985cf57 Gathering things to prove by induction together; removed cheat_bn_eqvt.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1625
diff changeset
  1112
  val gls = flat gls_lists;
4b949985cf57 Gathering things to prove by induction together; removed cheat_bn_eqvt.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1625
diff changeset
  1113
  fun trm_gls_map t = filter (exists_subterm (fn s => s = t)) gls;
4b949985cf57 Gathering things to prove by induction together; removed cheat_bn_eqvt.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1625
diff changeset
  1114
  val trm_gl_lists = map trm_gls_map frees;
4b949985cf57 Gathering things to prove by induction together; removed cheat_bn_eqvt.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1625
diff changeset
  1115
  val trm_gl_insts = map2 (fn n => fn l => [NONE, if l = [] then NONE else SOME n]) names' trm_gl_lists
4b949985cf57 Gathering things to prove by induction together; removed cheat_bn_eqvt.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1625
diff changeset
  1116
  val trm_gls = map mk_conjl trm_gl_lists;
4b949985cf57 Gathering things to prove by induction together; removed cheat_bn_eqvt.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1625
diff changeset
  1117
  val gl = HOLogic.mk_Trueprop (foldr1 HOLogic.mk_conj trm_gls);
4b949985cf57 Gathering things to prove by induction together; removed cheat_bn_eqvt.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1625
diff changeset
  1118
  fun tac {context,...} = ((fn _ => print_tac (PolyML.makestring names')) THEN'
4b949985cf57 Gathering things to prove by induction together; removed cheat_bn_eqvt.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1625
diff changeset
  1119
    InductTacs.induct_rules_tac context [(flat trm_gl_insts)] [ind]
4b949985cf57 Gathering things to prove by induction together; removed cheat_bn_eqvt.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1625
diff changeset
  1120
    THEN_ALL_NEW split_conjs THEN_ALL_NEW utac) 1
4b949985cf57 Gathering things to prove by induction together; removed cheat_bn_eqvt.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1625
diff changeset
  1121
  val th_loc = Goal.prove ctxt'' [] [] gl tac
4b949985cf57 Gathering things to prove by induction together; removed cheat_bn_eqvt.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1625
diff changeset
  1122
  val ths_loc = HOLogic.conj_elims th_loc
4b949985cf57 Gathering things to prove by induction together; removed cheat_bn_eqvt.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1625
diff changeset
  1123
  val ths = Variable.export ctxt'' ctxt ths_loc
4b949985cf57 Gathering things to prove by induction together; removed cheat_bn_eqvt.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1625
diff changeset
  1124
in
4b949985cf57 Gathering things to prove by induction together; removed cheat_bn_eqvt.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1625
diff changeset
  1125
  filter (fn x => not (prop_of x = prop_of @{thm TrueI})) ths
1553
4355eb3b7161 Automatically derive support for datatypes with at-most one binding per constructor.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1547
diff changeset
  1126
end
1650
4b949985cf57 Gathering things to prove by induction together; removed cheat_bn_eqvt.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1625
diff changeset
  1127
*}
4b949985cf57 Gathering things to prove by induction together; removed cheat_bn_eqvt.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1625
diff changeset
  1128
4b949985cf57 Gathering things to prove by induction together; removed cheat_bn_eqvt.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1625
diff changeset
  1129
ML {*
4b949985cf57 Gathering things to prove by induction together; removed cheat_bn_eqvt.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1625
diff changeset
  1130
fun build_eqvt_gl pi frees fnctn ctxt =
4b949985cf57 Gathering things to prove by induction together; removed cheat_bn_eqvt.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1625
diff changeset
  1131
let
4b949985cf57 Gathering things to prove by induction together; removed cheat_bn_eqvt.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1625
diff changeset
  1132
  val typ = domain_type (fastype_of fnctn);
4b949985cf57 Gathering things to prove by induction together; removed cheat_bn_eqvt.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1625
diff changeset
  1133
  val arg = the (AList.lookup (op=) frees typ);
4b949985cf57 Gathering things to prove by induction together; removed cheat_bn_eqvt.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1625
diff changeset
  1134
in
4b949985cf57 Gathering things to prove by induction together; removed cheat_bn_eqvt.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1625
diff changeset
  1135
  ([HOLogic.mk_eq ((perm_at $ pi $ (fnctn $ arg)), (fnctn $ (perm_arg arg $ pi $ arg)))], ctxt)
4b949985cf57 Gathering things to prove by induction together; removed cheat_bn_eqvt.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1625
diff changeset
  1136
end
4b949985cf57 Gathering things to prove by induction together; removed cheat_bn_eqvt.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1625
diff changeset
  1137
*}
4b949985cf57 Gathering things to prove by induction together; removed cheat_bn_eqvt.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1625
diff changeset
  1138
4b949985cf57 Gathering things to prove by induction together; removed cheat_bn_eqvt.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1625
diff changeset
  1139
ML {*
4b949985cf57 Gathering things to prove by induction together; removed cheat_bn_eqvt.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1625
diff changeset
  1140
fun prove_eqvt tys ind simps funs ctxt =
4b949985cf57 Gathering things to prove by induction together; removed cheat_bn_eqvt.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1625
diff changeset
  1141
let
4b949985cf57 Gathering things to prove by induction together; removed cheat_bn_eqvt.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1625
diff changeset
  1142
  val ([pi], ctxt') = Variable.variant_fixes ["p"] ctxt;
4b949985cf57 Gathering things to prove by induction together; removed cheat_bn_eqvt.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1625
diff changeset
  1143
  val pi = Free (pi, @{typ perm});
4b949985cf57 Gathering things to prove by induction together; removed cheat_bn_eqvt.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1625
diff changeset
  1144
  val tac = asm_full_simp_tac (HOL_ss addsimps (@{thm atom_eqvt} :: simps @ all_eqvts ctxt'))
4b949985cf57 Gathering things to prove by induction together; removed cheat_bn_eqvt.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1625
diff changeset
  1145
  val ths_loc = prove_by_induct tys (build_eqvt_gl pi) ind tac funs ctxt'
4b949985cf57 Gathering things to prove by induction together; removed cheat_bn_eqvt.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1625
diff changeset
  1146
  val ths = Variable.export ctxt' ctxt ths_loc
4b949985cf57 Gathering things to prove by induction together; removed cheat_bn_eqvt.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1625
diff changeset
  1147
  val add_eqvt = Attrib.internal (fn _ => Nominal_ThmDecls.eqvt_add)
4b949985cf57 Gathering things to prove by induction together; removed cheat_bn_eqvt.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1625
diff changeset
  1148
in
4b949985cf57 Gathering things to prove by induction together; removed cheat_bn_eqvt.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1625
diff changeset
  1149
  (ths, snd (Local_Theory.note ((Binding.empty, [add_eqvt]), ths) ctxt))
4b949985cf57 Gathering things to prove by induction together; removed cheat_bn_eqvt.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1625
diff changeset
  1150
end
4b949985cf57 Gathering things to prove by induction together; removed cheat_bn_eqvt.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1625
diff changeset
  1151
*}
4b949985cf57 Gathering things to prove by induction together; removed cheat_bn_eqvt.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1625
diff changeset
  1152
4b949985cf57 Gathering things to prove by induction together; removed cheat_bn_eqvt.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1625
diff changeset
  1153
end