Nominal/nominal_library.ML
author Christian Urban <urbanc@in.tum.de>
Sun, 14 Nov 2010 16:34:47 +0000
changeset 2568 8193bbaa07fe
parent 2560 Nominal-General/nominal_library.ML@82e37a4595c7
child 2569 94750b31a97d
permissions -rw-r--r--
merged Nominal-General directory into Nominal; renamed Abs.thy to Nominal2_Abs.thy
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1833
2050b5723c04 added a library for basic nominal functions; separated nominal_eqvt file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     1
(*  Title:      nominal_library.ML
2050b5723c04 added a library for basic nominal functions; separated nominal_eqvt file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     2
    Author:     Christian Urban
2050b5723c04 added a library for basic nominal functions; separated nominal_eqvt file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     3
1979
760257a66604 added basic functions for constructing supp-terms
Christian Urban <urbanc@in.tum.de>
parents: 1963
diff changeset
     4
  Basic functions for nominal.
1833
2050b5723c04 added a library for basic nominal functions; separated nominal_eqvt file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     5
*)
2050b5723c04 added a library for basic nominal functions; separated nominal_eqvt file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     6
2050b5723c04 added a library for basic nominal functions; separated nominal_eqvt file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     7
signature NOMINAL_LIBRARY =
2050b5723c04 added a library for basic nominal functions; separated nominal_eqvt file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     8
sig
2480
ac7dff1194e8 introduced a general procedure for structural inductions; simplified reflexivity proof
Christian Urban <urbanc@in.tum.de>
parents: 2477
diff changeset
     9
  val is_true: term -> bool
ac7dff1194e8 introduced a general procedure for structural inductions; simplified reflexivity proof
Christian Urban <urbanc@in.tum.de>
parents: 2477
diff changeset
    10
2313
25d2cdf7d7e4 transitivity proofs done
Christian Urban <urbanc@in.tum.de>
parents: 2311
diff changeset
    11
  val last2: 'a list -> 'a * 'a
25d2cdf7d7e4 transitivity proofs done
Christian Urban <urbanc@in.tum.de>
parents: 2311
diff changeset
    12
2288
3b83960f9544 new fv/fv_bn function (supp breaks now); exported raw perms and raw funs into separate ML-files
Christian Urban <urbanc@in.tum.de>
parents: 1979
diff changeset
    13
  val dest_listT: typ -> typ
3b83960f9544 new fv/fv_bn function (supp breaks now); exported raw perms and raw funs into separate ML-files
Christian Urban <urbanc@in.tum.de>
parents: 1979
diff changeset
    14
2399
107c06267f33 simplified code
Christian Urban <urbanc@in.tum.de>
parents: 2398
diff changeset
    15
  val size_const: typ -> term 
107c06267f33 simplified code
Christian Urban <urbanc@in.tum.de>
parents: 2398
diff changeset
    16
2410
2bbdb9c427b5 improved runtime slightly, by constructing an explicit size measure for the function definitions
Christian Urban <urbanc@in.tum.de>
parents: 2408
diff changeset
    17
  val sum_case_const: typ -> typ -> typ -> term
2bbdb9c427b5 improved runtime slightly, by constructing an explicit size measure for the function definitions
Christian Urban <urbanc@in.tum.de>
parents: 2408
diff changeset
    18
  val mk_sum_case: term -> term -> term
2bbdb9c427b5 improved runtime slightly, by constructing an explicit size measure for the function definitions
Christian Urban <urbanc@in.tum.de>
parents: 2408
diff changeset
    19
 
1833
2050b5723c04 added a library for basic nominal functions; separated nominal_eqvt file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    20
  val mk_minus: term -> term
1896
996d4411e95e tuned; fleshed out some library functions about permutations; closed Datatype_Aux structure (increases readability)
Christian Urban <urbanc@in.tum.de>
parents: 1871
diff changeset
    21
  val mk_plus: term -> term -> term
996d4411e95e tuned; fleshed out some library functions about permutations; closed Datatype_Aux structure (increases readability)
Christian Urban <urbanc@in.tum.de>
parents: 1871
diff changeset
    22
1899
8e0bfb14f6bf optimised the code of define_raw_perm
Christian Urban <urbanc@in.tum.de>
parents: 1896
diff changeset
    23
  val perm_ty: typ -> typ 
1871
c704d129862b moved some general function into nominal_library.ML
Christian Urban <urbanc@in.tum.de>
parents: 1834
diff changeset
    24
  val mk_perm_ty: typ -> term -> term -> term
1833
2050b5723c04 added a library for basic nominal functions; separated nominal_eqvt file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    25
  val mk_perm: term -> term -> term
1834
9909cc3566c5 moved a couple of more functions to the library
Christian Urban <urbanc@in.tum.de>
parents: 1833
diff changeset
    26
  val dest_perm: term -> term * term
9909cc3566c5 moved a couple of more functions to the library
Christian Urban <urbanc@in.tum.de>
parents: 1833
diff changeset
    27
1962
84a13d1e2511 moved mk_atom into the library; that meant that concrete atom classes need to be in Nominal2_Base
Christian Urban <urbanc@in.tum.de>
parents: 1899
diff changeset
    28
  val mk_sort_of: term -> term
1979
760257a66604 added basic functions for constructing supp-terms
Christian Urban <urbanc@in.tum.de>
parents: 1963
diff changeset
    29
  val atom_ty: typ -> typ
1962
84a13d1e2511 moved mk_atom into the library; that meant that concrete atom classes need to be in Nominal2_Base
Christian Urban <urbanc@in.tum.de>
parents: 1899
diff changeset
    30
  val mk_atom_ty: typ -> term -> term
84a13d1e2511 moved mk_atom into the library; that meant that concrete atom classes need to be in Nominal2_Base
Christian Urban <urbanc@in.tum.de>
parents: 1899
diff changeset
    31
  val mk_atom: term -> term
84a13d1e2511 moved mk_atom into the library; that meant that concrete atom classes need to be in Nominal2_Base
Christian Urban <urbanc@in.tum.de>
parents: 1899
diff changeset
    32
1979
760257a66604 added basic functions for constructing supp-terms
Christian Urban <urbanc@in.tum.de>
parents: 1963
diff changeset
    33
  val supp_ty: typ -> typ
2296
45a69c9cc4cc alpha works now
Christian Urban <urbanc@in.tum.de>
parents: 2289
diff changeset
    34
  val supp_const: typ -> term
1979
760257a66604 added basic functions for constructing supp-terms
Christian Urban <urbanc@in.tum.de>
parents: 1963
diff changeset
    35
  val mk_supp_ty: typ -> term -> term
760257a66604 added basic functions for constructing supp-terms
Christian Urban <urbanc@in.tum.de>
parents: 1963
diff changeset
    36
  val mk_supp: term -> term
760257a66604 added basic functions for constructing supp-terms
Christian Urban <urbanc@in.tum.de>
parents: 1963
diff changeset
    37
2475
486d4647bb37 supp-proofs work except for CoreHaskell and Modules (induct is probably not finding the correct instance)
Christian Urban <urbanc@in.tum.de>
parents: 2464
diff changeset
    38
  val supp_rel_ty: typ -> typ
486d4647bb37 supp-proofs work except for CoreHaskell and Modules (induct is probably not finding the correct instance)
Christian Urban <urbanc@in.tum.de>
parents: 2464
diff changeset
    39
  val supp_rel_const: typ -> term
486d4647bb37 supp-proofs work except for CoreHaskell and Modules (induct is probably not finding the correct instance)
Christian Urban <urbanc@in.tum.de>
parents: 2464
diff changeset
    40
  val mk_supp_rel_ty: typ -> term -> term -> term
486d4647bb37 supp-proofs work except for CoreHaskell and Modules (induct is probably not finding the correct instance)
Christian Urban <urbanc@in.tum.de>
parents: 2464
diff changeset
    41
  val mk_supp_rel: term -> term -> term		       
486d4647bb37 supp-proofs work except for CoreHaskell and Modules (induct is probably not finding the correct instance)
Christian Urban <urbanc@in.tum.de>
parents: 2464
diff changeset
    42
2448
b9d9c4540265 proved supports lemmas
Christian Urban <urbanc@in.tum.de>
parents: 2446
diff changeset
    43
  val supports_const: typ -> term
b9d9c4540265 proved supports lemmas
Christian Urban <urbanc@in.tum.de>
parents: 2446
diff changeset
    44
  val mk_supports_ty: typ -> term -> term -> term
b9d9c4540265 proved supports lemmas
Christian Urban <urbanc@in.tum.de>
parents: 2446
diff changeset
    45
  val mk_supports: term -> term -> term
b9d9c4540265 proved supports lemmas
Christian Urban <urbanc@in.tum.de>
parents: 2446
diff changeset
    46
2450
217ef3e4282e added proofs for fsupp properties
Christian Urban <urbanc@in.tum.de>
parents: 2448
diff changeset
    47
  val finite_const: typ -> term
217ef3e4282e added proofs for fsupp properties
Christian Urban <urbanc@in.tum.de>
parents: 2448
diff changeset
    48
  val mk_finite_ty: typ -> term -> term
217ef3e4282e added proofs for fsupp properties
Christian Urban <urbanc@in.tum.de>
parents: 2448
diff changeset
    49
  val mk_finite: term -> term
217ef3e4282e added proofs for fsupp properties
Christian Urban <urbanc@in.tum.de>
parents: 2448
diff changeset
    50
217ef3e4282e added proofs for fsupp properties
Christian Urban <urbanc@in.tum.de>
parents: 2448
diff changeset
    51
1834
9909cc3566c5 moved a couple of more functions to the library
Christian Urban <urbanc@in.tum.de>
parents: 1833
diff changeset
    52
  val mk_equiv: thm -> thm
9909cc3566c5 moved a couple of more functions to the library
Christian Urban <urbanc@in.tum.de>
parents: 1833
diff changeset
    53
  val safe_mk_equiv: thm -> thm
2288
3b83960f9544 new fv/fv_bn function (supp breaks now); exported raw perms and raw funs into separate ML-files
Christian Urban <urbanc@in.tum.de>
parents: 1979
diff changeset
    54
2289
bf748be70109 moved some mk_union and mk_diff into the library
Christian Urban <urbanc@in.tum.de>
parents: 2288
diff changeset
    55
  val mk_diff: term * term -> term
2296
45a69c9cc4cc alpha works now
Christian Urban <urbanc@in.tum.de>
parents: 2289
diff changeset
    56
  val mk_append: term * term -> term
2289
bf748be70109 moved some mk_union and mk_diff into the library
Christian Urban <urbanc@in.tum.de>
parents: 2288
diff changeset
    57
  val mk_union: term * term -> term
bf748be70109 moved some mk_union and mk_diff into the library
Christian Urban <urbanc@in.tum.de>
parents: 2288
diff changeset
    58
  val fold_union: term list -> term
2464
f4eba60cbd69 made the fv-definition aggree more with alpha (needed in the support proofs)
Christian Urban <urbanc@in.tum.de>
parents: 2450
diff changeset
    59
  val fold_append: term list -> term
2389
0f24c961b5f6 introduced a general alpha_prove method
Christian Urban <urbanc@in.tum.de>
parents: 2384
diff changeset
    60
  val mk_conj: term * term -> term
0f24c961b5f6 introduced a general alpha_prove method
Christian Urban <urbanc@in.tum.de>
parents: 2384
diff changeset
    61
  val fold_conj: term list -> term
2289
bf748be70109 moved some mk_union and mk_diff into the library
Christian Urban <urbanc@in.tum.de>
parents: 2288
diff changeset
    62
2448
b9d9c4540265 proved supports lemmas
Christian Urban <urbanc@in.tum.de>
parents: 2446
diff changeset
    63
  (* fresh arguments for a term *)
b9d9c4540265 proved supports lemmas
Christian Urban <urbanc@in.tum.de>
parents: 2446
diff changeset
    64
  val fresh_args: Proof.context -> term -> term list
b9d9c4540265 proved supports lemmas
Christian Urban <urbanc@in.tum.de>
parents: 2446
diff changeset
    65
2288
3b83960f9544 new fv/fv_bn function (supp breaks now); exported raw perms and raw funs into separate ML-files
Christian Urban <urbanc@in.tum.de>
parents: 1979
diff changeset
    66
  (* datatype operations *)
2407
49ab06c0ca64 improved code
Christian Urban <urbanc@in.tum.de>
parents: 2399
diff changeset
    67
  type cns_info = (term * typ * typ list * bool list) list
49ab06c0ca64 improved code
Christian Urban <urbanc@in.tum.de>
parents: 2399
diff changeset
    68
2296
45a69c9cc4cc alpha works now
Christian Urban <urbanc@in.tum.de>
parents: 2289
diff changeset
    69
  val all_dtyps: Datatype_Aux.descr -> (string * sort) list -> typ list
2288
3b83960f9544 new fv/fv_bn function (supp breaks now); exported raw perms and raw funs into separate ML-files
Christian Urban <urbanc@in.tum.de>
parents: 1979
diff changeset
    70
  val nth_dtyp: Datatype_Aux.descr -> (string * sort) list -> int -> typ
2407
49ab06c0ca64 improved code
Christian Urban <urbanc@in.tum.de>
parents: 2399
diff changeset
    71
  val all_dtyp_constrs_types: Datatype_Aux.descr -> (string * sort) list -> cns_info list
49ab06c0ca64 improved code
Christian Urban <urbanc@in.tum.de>
parents: 2399
diff changeset
    72
  val nth_dtyp_constrs_types: Datatype_Aux.descr -> (string * sort) list -> int -> cns_info
2288
3b83960f9544 new fv/fv_bn function (supp breaks now); exported raw perms and raw funs into separate ML-files
Christian Urban <urbanc@in.tum.de>
parents: 1979
diff changeset
    73
  val prefix_dt_names: Datatype_Aux.descr -> (string * sort) list -> string -> string list
3b83960f9544 new fv/fv_bn function (supp breaks now); exported raw perms and raw funs into separate ML-files
Christian Urban <urbanc@in.tum.de>
parents: 1979
diff changeset
    74
2304
8a98171ba1fc all raw definitions are defined using function
Christian Urban <urbanc@in.tum.de>
parents: 2296
diff changeset
    75
  (* tactics for function package *)
8a98171ba1fc all raw definitions are defined using function
Christian Urban <urbanc@in.tum.de>
parents: 2296
diff changeset
    76
  val pat_completeness_simp: thm list -> Proof.context -> tactic
2410
2bbdb9c427b5 improved runtime slightly, by constructing an explicit size measure for the function definitions
Christian Urban <urbanc@in.tum.de>
parents: 2408
diff changeset
    77
  val prove_termination: thm list -> Proof.context -> Function.info * local_theory
2304
8a98171ba1fc all raw definitions are defined using function
Christian Urban <urbanc@in.tum.de>
parents: 2296
diff changeset
    78
2311
4da5c5c29009 work on transitivity proof
Christian Urban <urbanc@in.tum.de>
parents: 2304
diff changeset
    79
  (* transformations of premises in inductions *)
4da5c5c29009 work on transitivity proof
Christian Urban <urbanc@in.tum.de>
parents: 2304
diff changeset
    80
  val transform_prem1: Proof.context -> string list -> thm -> thm
4da5c5c29009 work on transitivity proof
Christian Urban <urbanc@in.tum.de>
parents: 2304
diff changeset
    81
  val transform_prem2: Proof.context -> string list -> thm -> thm
2397
c670a849af65 more experiments with lifting
Christian Urban <urbanc@in.tum.de>
parents: 2389
diff changeset
    82
c670a849af65 more experiments with lifting
Christian Urban <urbanc@in.tum.de>
parents: 2389
diff changeset
    83
  (* transformation into the object logic *)
c670a849af65 more experiments with lifting
Christian Urban <urbanc@in.tum.de>
parents: 2389
diff changeset
    84
  val atomize: thm -> thm
2398
1e6160690546 improved code
Christian Urban <urbanc@in.tum.de>
parents: 2397
diff changeset
    85
1833
2050b5723c04 added a library for basic nominal functions; separated nominal_eqvt file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    86
end
2050b5723c04 added a library for basic nominal functions; separated nominal_eqvt file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    87
2050b5723c04 added a library for basic nominal functions; separated nominal_eqvt file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    88
2050b5723c04 added a library for basic nominal functions; separated nominal_eqvt file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    89
structure Nominal_Library: NOMINAL_LIBRARY =
2050b5723c04 added a library for basic nominal functions; separated nominal_eqvt file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    90
struct
2050b5723c04 added a library for basic nominal functions; separated nominal_eqvt file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    91
2480
ac7dff1194e8 introduced a general procedure for structural inductions; simplified reflexivity proof
Christian Urban <urbanc@in.tum.de>
parents: 2477
diff changeset
    92
fun is_true @{term "Trueprop True"} = true
ac7dff1194e8 introduced a general procedure for structural inductions; simplified reflexivity proof
Christian Urban <urbanc@in.tum.de>
parents: 2477
diff changeset
    93
  | is_true _ = false 
ac7dff1194e8 introduced a general procedure for structural inductions; simplified reflexivity proof
Christian Urban <urbanc@in.tum.de>
parents: 2477
diff changeset
    94
2313
25d2cdf7d7e4 transitivity proofs done
Christian Urban <urbanc@in.tum.de>
parents: 2311
diff changeset
    95
fun last2 [] = raise Empty
25d2cdf7d7e4 transitivity proofs done
Christian Urban <urbanc@in.tum.de>
parents: 2311
diff changeset
    96
  | last2 [_] = raise Empty
2375
e163fd99de44 minor polishing
Christian Urban <urbanc@in.tum.de>
parents: 2313
diff changeset
    97
  | last2 [x, y] = (x, y)
2313
25d2cdf7d7e4 transitivity proofs done
Christian Urban <urbanc@in.tum.de>
parents: 2311
diff changeset
    98
  | last2 (_ :: xs) = last2 xs
25d2cdf7d7e4 transitivity proofs done
Christian Urban <urbanc@in.tum.de>
parents: 2311
diff changeset
    99
2288
3b83960f9544 new fv/fv_bn function (supp breaks now); exported raw perms and raw funs into separate ML-files
Christian Urban <urbanc@in.tum.de>
parents: 1979
diff changeset
   100
fun dest_listT (Type (@{type_name list}, [T])) = T
3b83960f9544 new fv/fv_bn function (supp breaks now); exported raw perms and raw funs into separate ML-files
Christian Urban <urbanc@in.tum.de>
parents: 1979
diff changeset
   101
  | dest_listT T = raise TYPE ("dest_listT: list type expected", [T], [])
3b83960f9544 new fv/fv_bn function (supp breaks now); exported raw perms and raw funs into separate ML-files
Christian Urban <urbanc@in.tum.de>
parents: 1979
diff changeset
   102
2399
107c06267f33 simplified code
Christian Urban <urbanc@in.tum.de>
parents: 2398
diff changeset
   103
fun size_const ty = Const (@{const_name size}, ty --> @{typ nat})
1979
760257a66604 added basic functions for constructing supp-terms
Christian Urban <urbanc@in.tum.de>
parents: 1963
diff changeset
   104
2410
2bbdb9c427b5 improved runtime slightly, by constructing an explicit size measure for the function definitions
Christian Urban <urbanc@in.tum.de>
parents: 2408
diff changeset
   105
fun sum_case_const ty1 ty2 ty3 = 
2bbdb9c427b5 improved runtime slightly, by constructing an explicit size measure for the function definitions
Christian Urban <urbanc@in.tum.de>
parents: 2408
diff changeset
   106
  Const (@{const_name sum_case}, [ty1 --> ty3, ty2 --> ty3, Type (@{type_name sum}, [ty1, ty2])] ---> ty3)
2bbdb9c427b5 improved runtime slightly, by constructing an explicit size measure for the function definitions
Christian Urban <urbanc@in.tum.de>
parents: 2408
diff changeset
   107
fun mk_sum_case trm1 trm2 =
2477
2f289c1f6cf1 tuned code
Christian Urban <urbanc@in.tum.de>
parents: 2475
diff changeset
   108
  let
2f289c1f6cf1 tuned code
Christian Urban <urbanc@in.tum.de>
parents: 2475
diff changeset
   109
    val ([ty1], ty3) = strip_type (fastype_of trm1)
2f289c1f6cf1 tuned code
Christian Urban <urbanc@in.tum.de>
parents: 2475
diff changeset
   110
    val ty2 = domain_type (fastype_of trm2)
2f289c1f6cf1 tuned code
Christian Urban <urbanc@in.tum.de>
parents: 2475
diff changeset
   111
  in
2f289c1f6cf1 tuned code
Christian Urban <urbanc@in.tum.de>
parents: 2475
diff changeset
   112
    sum_case_const ty1 ty2 ty3 $ trm1 $ trm2
2f289c1f6cf1 tuned code
Christian Urban <urbanc@in.tum.de>
parents: 2475
diff changeset
   113
  end 
2410
2bbdb9c427b5 improved runtime slightly, by constructing an explicit size measure for the function definitions
Christian Urban <urbanc@in.tum.de>
parents: 2408
diff changeset
   114
2bbdb9c427b5 improved runtime slightly, by constructing an explicit size measure for the function definitions
Christian Urban <urbanc@in.tum.de>
parents: 2408
diff changeset
   115
2bbdb9c427b5 improved runtime slightly, by constructing an explicit size measure for the function definitions
Christian Urban <urbanc@in.tum.de>
parents: 2408
diff changeset
   116
2399
107c06267f33 simplified code
Christian Urban <urbanc@in.tum.de>
parents: 2398
diff changeset
   117
fun mk_minus p = @{term "uminus::perm => perm"} $ p
1896
996d4411e95e tuned; fleshed out some library functions about permutations; closed Datatype_Aux structure (increases readability)
Christian Urban <urbanc@in.tum.de>
parents: 1871
diff changeset
   118
2399
107c06267f33 simplified code
Christian Urban <urbanc@in.tum.de>
parents: 2398
diff changeset
   119
fun mk_plus p q = @{term "plus::perm => perm => perm"} $ p $ q
107c06267f33 simplified code
Christian Urban <urbanc@in.tum.de>
parents: 2398
diff changeset
   120
107c06267f33 simplified code
Christian Urban <urbanc@in.tum.de>
parents: 2398
diff changeset
   121
fun perm_ty ty = @{typ "perm"} --> ty --> ty
107c06267f33 simplified code
Christian Urban <urbanc@in.tum.de>
parents: 2398
diff changeset
   122
fun mk_perm_ty ty p trm = Const (@{const_name "permute"}, perm_ty ty) $ p $ trm
107c06267f33 simplified code
Christian Urban <urbanc@in.tum.de>
parents: 2398
diff changeset
   123
fun mk_perm p trm = mk_perm_ty (fastype_of trm) p trm
1833
2050b5723c04 added a library for basic nominal functions; separated nominal_eqvt file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   124
1834
9909cc3566c5 moved a couple of more functions to the library
Christian Urban <urbanc@in.tum.de>
parents: 1833
diff changeset
   125
fun dest_perm (Const (@{const_name "permute"}, _) $ p $ t) = (p, t)
1979
760257a66604 added basic functions for constructing supp-terms
Christian Urban <urbanc@in.tum.de>
parents: 1963
diff changeset
   126
  | dest_perm t = raise TERM ("dest_perm", [t]);
1833
2050b5723c04 added a library for basic nominal functions; separated nominal_eqvt file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   127
1962
84a13d1e2511 moved mk_atom into the library; that meant that concrete atom classes need to be in Nominal2_Base
Christian Urban <urbanc@in.tum.de>
parents: 1899
diff changeset
   128
fun mk_sort_of t = @{term "sort_of"} $ t;
84a13d1e2511 moved mk_atom into the library; that meant that concrete atom classes need to be in Nominal2_Base
Christian Urban <urbanc@in.tum.de>
parents: 1899
diff changeset
   129
1979
760257a66604 added basic functions for constructing supp-terms
Christian Urban <urbanc@in.tum.de>
parents: 1963
diff changeset
   130
fun atom_ty ty = ty --> @{typ "atom"};
1963
0c9ef14e9ba4 some tuning
Christian Urban <urbanc@in.tum.de>
parents: 1962
diff changeset
   131
fun mk_atom_ty ty t = Const (@{const_name "atom"}, atom_ty ty) $ t;
1962
84a13d1e2511 moved mk_atom into the library; that meant that concrete atom classes need to be in Nominal2_Base
Christian Urban <urbanc@in.tum.de>
parents: 1899
diff changeset
   132
fun mk_atom t = mk_atom_ty (fastype_of t) t;
84a13d1e2511 moved mk_atom into the library; that meant that concrete atom classes need to be in Nominal2_Base
Christian Urban <urbanc@in.tum.de>
parents: 1899
diff changeset
   133
1979
760257a66604 added basic functions for constructing supp-terms
Christian Urban <urbanc@in.tum.de>
parents: 1963
diff changeset
   134
760257a66604 added basic functions for constructing supp-terms
Christian Urban <urbanc@in.tum.de>
parents: 1963
diff changeset
   135
fun supp_ty ty = ty --> @{typ "atom set"};
2450
217ef3e4282e added proofs for fsupp properties
Christian Urban <urbanc@in.tum.de>
parents: 2448
diff changeset
   136
fun supp_const ty = Const (@{const_name supp}, supp_ty ty)
2475
486d4647bb37 supp-proofs work except for CoreHaskell and Modules (induct is probably not finding the correct instance)
Christian Urban <urbanc@in.tum.de>
parents: 2464
diff changeset
   137
fun mk_supp_ty ty t = supp_const ty $ t
486d4647bb37 supp-proofs work except for CoreHaskell and Modules (induct is probably not finding the correct instance)
Christian Urban <urbanc@in.tum.de>
parents: 2464
diff changeset
   138
fun mk_supp t = mk_supp_ty (fastype_of t) t
486d4647bb37 supp-proofs work except for CoreHaskell and Modules (induct is probably not finding the correct instance)
Christian Urban <urbanc@in.tum.de>
parents: 2464
diff changeset
   139
486d4647bb37 supp-proofs work except for CoreHaskell and Modules (induct is probably not finding the correct instance)
Christian Urban <urbanc@in.tum.de>
parents: 2464
diff changeset
   140
fun supp_rel_ty ty = ([ty, ty] ---> @{typ bool}) --> ty --> @{typ "atom set"};
486d4647bb37 supp-proofs work except for CoreHaskell and Modules (induct is probably not finding the correct instance)
Christian Urban <urbanc@in.tum.de>
parents: 2464
diff changeset
   141
fun supp_rel_const ty = Const (@{const_name supp_rel}, supp_rel_ty ty)
486d4647bb37 supp-proofs work except for CoreHaskell and Modules (induct is probably not finding the correct instance)
Christian Urban <urbanc@in.tum.de>
parents: 2464
diff changeset
   142
fun mk_supp_rel_ty ty r t = supp_rel_const ty $ r $ t
486d4647bb37 supp-proofs work except for CoreHaskell and Modules (induct is probably not finding the correct instance)
Christian Urban <urbanc@in.tum.de>
parents: 2464
diff changeset
   143
fun mk_supp_rel r t = mk_supp_rel_ty (fastype_of t) r t
1979
760257a66604 added basic functions for constructing supp-terms
Christian Urban <urbanc@in.tum.de>
parents: 1963
diff changeset
   144
2450
217ef3e4282e added proofs for fsupp properties
Christian Urban <urbanc@in.tum.de>
parents: 2448
diff changeset
   145
fun supports_const ty = Const (@{const_name supports}, [@{typ "atom set"}, ty] ---> @{typ bool});
2448
b9d9c4540265 proved supports lemmas
Christian Urban <urbanc@in.tum.de>
parents: 2446
diff changeset
   146
fun mk_supports_ty ty t1 t2 = supports_const ty $ t1 $ t2;
b9d9c4540265 proved supports lemmas
Christian Urban <urbanc@in.tum.de>
parents: 2446
diff changeset
   147
fun mk_supports t1 t2 = mk_supports_ty (fastype_of t2) t1 t2;
1979
760257a66604 added basic functions for constructing supp-terms
Christian Urban <urbanc@in.tum.de>
parents: 1963
diff changeset
   148
2450
217ef3e4282e added proofs for fsupp properties
Christian Urban <urbanc@in.tum.de>
parents: 2448
diff changeset
   149
fun finite_const ty = Const (@{const_name finite}, ty --> @{typ bool})
217ef3e4282e added proofs for fsupp properties
Christian Urban <urbanc@in.tum.de>
parents: 2448
diff changeset
   150
fun mk_finite_ty ty t = finite_const ty $ t
217ef3e4282e added proofs for fsupp properties
Christian Urban <urbanc@in.tum.de>
parents: 2448
diff changeset
   151
fun mk_finite t = mk_finite_ty (fastype_of t) t
217ef3e4282e added proofs for fsupp properties
Christian Urban <urbanc@in.tum.de>
parents: 2448
diff changeset
   152
217ef3e4282e added proofs for fsupp properties
Christian Urban <urbanc@in.tum.de>
parents: 2448
diff changeset
   153
1834
9909cc3566c5 moved a couple of more functions to the library
Christian Urban <urbanc@in.tum.de>
parents: 1833
diff changeset
   154
fun mk_equiv r = r RS @{thm eq_reflection};
9909cc3566c5 moved a couple of more functions to the library
Christian Urban <urbanc@in.tum.de>
parents: 1833
diff changeset
   155
fun safe_mk_equiv r = mk_equiv r handle Thm.THM _ => r;
1833
2050b5723c04 added a library for basic nominal functions; separated nominal_eqvt file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   156
1962
84a13d1e2511 moved mk_atom into the library; that meant that concrete atom classes need to be in Nominal2_Base
Christian Urban <urbanc@in.tum.de>
parents: 1899
diff changeset
   157
2296
45a69c9cc4cc alpha works now
Christian Urban <urbanc@in.tum.de>
parents: 2289
diff changeset
   158
(* functions that construct differences, appends and unions
45a69c9cc4cc alpha works now
Christian Urban <urbanc@in.tum.de>
parents: 2289
diff changeset
   159
   but avoid producing empty atom sets or empty atom lists *)
2289
bf748be70109 moved some mk_union and mk_diff into the library
Christian Urban <urbanc@in.tum.de>
parents: 2288
diff changeset
   160
bf748be70109 moved some mk_union and mk_diff into the library
Christian Urban <urbanc@in.tum.de>
parents: 2288
diff changeset
   161
fun mk_diff (@{term "{}::atom set"}, _) = @{term "{}::atom set"}
bf748be70109 moved some mk_union and mk_diff into the library
Christian Urban <urbanc@in.tum.de>
parents: 2288
diff changeset
   162
  | mk_diff (t1, @{term "{}::atom set"}) = t1
2464
f4eba60cbd69 made the fv-definition aggree more with alpha (needed in the support proofs)
Christian Urban <urbanc@in.tum.de>
parents: 2450
diff changeset
   163
  | mk_diff (@{term "set ([]::atom list)"}, _) = @{term "set ([]::atom list)"}
f4eba60cbd69 made the fv-definition aggree more with alpha (needed in the support proofs)
Christian Urban <urbanc@in.tum.de>
parents: 2450
diff changeset
   164
  | mk_diff (t1, @{term "set ([]::atom list)"}) = t1
2289
bf748be70109 moved some mk_union and mk_diff into the library
Christian Urban <urbanc@in.tum.de>
parents: 2288
diff changeset
   165
  | mk_diff (t1, t2) = HOLogic.mk_binop @{const_name minus} (t1, t2)
bf748be70109 moved some mk_union and mk_diff into the library
Christian Urban <urbanc@in.tum.de>
parents: 2288
diff changeset
   166
2389
0f24c961b5f6 introduced a general alpha_prove method
Christian Urban <urbanc@in.tum.de>
parents: 2384
diff changeset
   167
fun mk_append (t1, @{term "[]::atom list"}) = t1
2296
45a69c9cc4cc alpha works now
Christian Urban <urbanc@in.tum.de>
parents: 2289
diff changeset
   168
  | mk_append (@{term "[]::atom list"}, t2) = t2
45a69c9cc4cc alpha works now
Christian Urban <urbanc@in.tum.de>
parents: 2289
diff changeset
   169
  | mk_append (t1, t2) = HOLogic.mk_binop @{const_name "append"} (t1, t2) 
45a69c9cc4cc alpha works now
Christian Urban <urbanc@in.tum.de>
parents: 2289
diff changeset
   170
2389
0f24c961b5f6 introduced a general alpha_prove method
Christian Urban <urbanc@in.tum.de>
parents: 2384
diff changeset
   171
fun mk_union (t1, @{term "{}::atom set"}) = t1
2289
bf748be70109 moved some mk_union and mk_diff into the library
Christian Urban <urbanc@in.tum.de>
parents: 2288
diff changeset
   172
  | mk_union (@{term "{}::atom set"}, t2) = t2
2464
f4eba60cbd69 made the fv-definition aggree more with alpha (needed in the support proofs)
Christian Urban <urbanc@in.tum.de>
parents: 2450
diff changeset
   173
  | mk_union (t1, @{term "set ([]::atom list)"}) = t1
f4eba60cbd69 made the fv-definition aggree more with alpha (needed in the support proofs)
Christian Urban <urbanc@in.tum.de>
parents: 2450
diff changeset
   174
  | mk_union (@{term "set ([]::atom list)"}, t2) = t2
2296
45a69c9cc4cc alpha works now
Christian Urban <urbanc@in.tum.de>
parents: 2289
diff changeset
   175
  | mk_union (t1, t2) = HOLogic.mk_binop @{const_name "sup"} (t1, t2)  
2289
bf748be70109 moved some mk_union and mk_diff into the library
Christian Urban <urbanc@in.tum.de>
parents: 2288
diff changeset
   176
 
2384
841b7e34e70a fixed order of fold_union to make alpha and fv agree
Christian Urban <urbanc@in.tum.de>
parents: 2375
diff changeset
   177
fun fold_union trms = fold_rev (curry mk_union) trms @{term "{}::atom set"}
2464
f4eba60cbd69 made the fv-definition aggree more with alpha (needed in the support proofs)
Christian Urban <urbanc@in.tum.de>
parents: 2450
diff changeset
   178
fun fold_append trms = fold_rev (curry mk_append) trms @{term "[]::atom list"}
2289
bf748be70109 moved some mk_union and mk_diff into the library
Christian Urban <urbanc@in.tum.de>
parents: 2288
diff changeset
   179
2389
0f24c961b5f6 introduced a general alpha_prove method
Christian Urban <urbanc@in.tum.de>
parents: 2384
diff changeset
   180
fun mk_conj (t1, @{term "True"}) = t1
0f24c961b5f6 introduced a general alpha_prove method
Christian Urban <urbanc@in.tum.de>
parents: 2384
diff changeset
   181
  | mk_conj (@{term "True"}, t2) = t2
0f24c961b5f6 introduced a general alpha_prove method
Christian Urban <urbanc@in.tum.de>
parents: 2384
diff changeset
   182
  | mk_conj (t1, t2) = HOLogic.mk_conj (t1, t2)
2289
bf748be70109 moved some mk_union and mk_diff into the library
Christian Urban <urbanc@in.tum.de>
parents: 2288
diff changeset
   183
2389
0f24c961b5f6 introduced a general alpha_prove method
Christian Urban <urbanc@in.tum.de>
parents: 2384
diff changeset
   184
fun fold_conj trms = fold_rev (curry mk_conj) trms @{term "True"}
2296
45a69c9cc4cc alpha works now
Christian Urban <urbanc@in.tum.de>
parents: 2289
diff changeset
   185
2448
b9d9c4540265 proved supports lemmas
Christian Urban <urbanc@in.tum.de>
parents: 2446
diff changeset
   186
b9d9c4540265 proved supports lemmas
Christian Urban <urbanc@in.tum.de>
parents: 2446
diff changeset
   187
(* produces fresh arguments for a term *)
b9d9c4540265 proved supports lemmas
Christian Urban <urbanc@in.tum.de>
parents: 2446
diff changeset
   188
b9d9c4540265 proved supports lemmas
Christian Urban <urbanc@in.tum.de>
parents: 2446
diff changeset
   189
fun fresh_args ctxt f =
b9d9c4540265 proved supports lemmas
Christian Urban <urbanc@in.tum.de>
parents: 2446
diff changeset
   190
    f |> fastype_of
b9d9c4540265 proved supports lemmas
Christian Urban <urbanc@in.tum.de>
parents: 2446
diff changeset
   191
      |> binder_types
b9d9c4540265 proved supports lemmas
Christian Urban <urbanc@in.tum.de>
parents: 2446
diff changeset
   192
      |> map (pair "z")
b9d9c4540265 proved supports lemmas
Christian Urban <urbanc@in.tum.de>
parents: 2446
diff changeset
   193
      |> Variable.variant_frees ctxt [f]
b9d9c4540265 proved supports lemmas
Christian Urban <urbanc@in.tum.de>
parents: 2446
diff changeset
   194
      |> map Free
b9d9c4540265 proved supports lemmas
Christian Urban <urbanc@in.tum.de>
parents: 2446
diff changeset
   195
b9d9c4540265 proved supports lemmas
Christian Urban <urbanc@in.tum.de>
parents: 2446
diff changeset
   196
b9d9c4540265 proved supports lemmas
Christian Urban <urbanc@in.tum.de>
parents: 2446
diff changeset
   197
2288
3b83960f9544 new fv/fv_bn function (supp breaks now); exported raw perms and raw funs into separate ML-files
Christian Urban <urbanc@in.tum.de>
parents: 1979
diff changeset
   198
(** datatypes **)
3b83960f9544 new fv/fv_bn function (supp breaks now); exported raw perms and raw funs into separate ML-files
Christian Urban <urbanc@in.tum.de>
parents: 1979
diff changeset
   199
2407
49ab06c0ca64 improved code
Christian Urban <urbanc@in.tum.de>
parents: 2399
diff changeset
   200
(* constructor infos *)
49ab06c0ca64 improved code
Christian Urban <urbanc@in.tum.de>
parents: 2399
diff changeset
   201
type cns_info = (term * typ * typ list * bool list) list
2288
3b83960f9544 new fv/fv_bn function (supp breaks now); exported raw perms and raw funs into separate ML-files
Christian Urban <urbanc@in.tum.de>
parents: 1979
diff changeset
   202
3b83960f9544 new fv/fv_bn function (supp breaks now); exported raw perms and raw funs into separate ML-files
Christian Urban <urbanc@in.tum.de>
parents: 1979
diff changeset
   203
(* returns the type of the nth datatype *)
2296
45a69c9cc4cc alpha works now
Christian Urban <urbanc@in.tum.de>
parents: 2289
diff changeset
   204
fun all_dtyps descr sorts = 
45a69c9cc4cc alpha works now
Christian Urban <urbanc@in.tum.de>
parents: 2289
diff changeset
   205
  map (fn n => Datatype_Aux.typ_of_dtyp descr sorts (Datatype_Aux.DtRec n)) (0 upto (length descr - 1))
45a69c9cc4cc alpha works now
Christian Urban <urbanc@in.tum.de>
parents: 2289
diff changeset
   206
2288
3b83960f9544 new fv/fv_bn function (supp breaks now); exported raw perms and raw funs into separate ML-files
Christian Urban <urbanc@in.tum.de>
parents: 1979
diff changeset
   207
fun nth_dtyp descr sorts n = 
3b83960f9544 new fv/fv_bn function (supp breaks now); exported raw perms and raw funs into separate ML-files
Christian Urban <urbanc@in.tum.de>
parents: 1979
diff changeset
   208
  Datatype_Aux.typ_of_dtyp descr sorts (Datatype_Aux.DtRec n);
3b83960f9544 new fv/fv_bn function (supp breaks now); exported raw perms and raw funs into separate ML-files
Christian Urban <urbanc@in.tum.de>
parents: 1979
diff changeset
   209
3b83960f9544 new fv/fv_bn function (supp breaks now); exported raw perms and raw funs into separate ML-files
Christian Urban <urbanc@in.tum.de>
parents: 1979
diff changeset
   210
(* returns info about constructors in a datatype *)
3b83960f9544 new fv/fv_bn function (supp breaks now); exported raw perms and raw funs into separate ML-files
Christian Urban <urbanc@in.tum.de>
parents: 1979
diff changeset
   211
fun all_dtyp_constrs_info descr = 
3b83960f9544 new fv/fv_bn function (supp breaks now); exported raw perms and raw funs into separate ML-files
Christian Urban <urbanc@in.tum.de>
parents: 1979
diff changeset
   212
  map (fn (_, (ty, vs, constrs)) => map (pair (ty, vs)) constrs) descr
3b83960f9544 new fv/fv_bn function (supp breaks now); exported raw perms and raw funs into separate ML-files
Christian Urban <urbanc@in.tum.de>
parents: 1979
diff changeset
   213
3b83960f9544 new fv/fv_bn function (supp breaks now); exported raw perms and raw funs into separate ML-files
Christian Urban <urbanc@in.tum.de>
parents: 1979
diff changeset
   214
(* returns the constants of the constructors plus the 
3b83960f9544 new fv/fv_bn function (supp breaks now); exported raw perms and raw funs into separate ML-files
Christian Urban <urbanc@in.tum.de>
parents: 1979
diff changeset
   215
   corresponding type and types of arguments *)
3b83960f9544 new fv/fv_bn function (supp breaks now); exported raw perms and raw funs into separate ML-files
Christian Urban <urbanc@in.tum.de>
parents: 1979
diff changeset
   216
fun all_dtyp_constrs_types descr sorts = 
3b83960f9544 new fv/fv_bn function (supp breaks now); exported raw perms and raw funs into separate ML-files
Christian Urban <urbanc@in.tum.de>
parents: 1979
diff changeset
   217
  let
2477
2f289c1f6cf1 tuned code
Christian Urban <urbanc@in.tum.de>
parents: 2475
diff changeset
   218
    fun aux ((ty_name, vs), (cname, args)) =
2f289c1f6cf1 tuned code
Christian Urban <urbanc@in.tum.de>
parents: 2475
diff changeset
   219
      let
2f289c1f6cf1 tuned code
Christian Urban <urbanc@in.tum.de>
parents: 2475
diff changeset
   220
        val vs_tys = map (Datatype_Aux.typ_of_dtyp descr sorts) vs
2f289c1f6cf1 tuned code
Christian Urban <urbanc@in.tum.de>
parents: 2475
diff changeset
   221
        val ty = Type (ty_name, vs_tys)
2f289c1f6cf1 tuned code
Christian Urban <urbanc@in.tum.de>
parents: 2475
diff changeset
   222
        val arg_tys = map (Datatype_Aux.typ_of_dtyp descr sorts) args
2f289c1f6cf1 tuned code
Christian Urban <urbanc@in.tum.de>
parents: 2475
diff changeset
   223
        val is_rec = map Datatype_Aux.is_rec_type args
2f289c1f6cf1 tuned code
Christian Urban <urbanc@in.tum.de>
parents: 2475
diff changeset
   224
      in
2f289c1f6cf1 tuned code
Christian Urban <urbanc@in.tum.de>
parents: 2475
diff changeset
   225
        (Const (cname, arg_tys ---> ty), ty, arg_tys, is_rec)
2f289c1f6cf1 tuned code
Christian Urban <urbanc@in.tum.de>
parents: 2475
diff changeset
   226
      end
2288
3b83960f9544 new fv/fv_bn function (supp breaks now); exported raw perms and raw funs into separate ML-files
Christian Urban <urbanc@in.tum.de>
parents: 1979
diff changeset
   227
  in
2477
2f289c1f6cf1 tuned code
Christian Urban <urbanc@in.tum.de>
parents: 2475
diff changeset
   228
    map (map aux) (all_dtyp_constrs_info descr)
2288
3b83960f9544 new fv/fv_bn function (supp breaks now); exported raw perms and raw funs into separate ML-files
Christian Urban <urbanc@in.tum.de>
parents: 1979
diff changeset
   229
  end
3b83960f9544 new fv/fv_bn function (supp breaks now); exported raw perms and raw funs into separate ML-files
Christian Urban <urbanc@in.tum.de>
parents: 1979
diff changeset
   230
3b83960f9544 new fv/fv_bn function (supp breaks now); exported raw perms and raw funs into separate ML-files
Christian Urban <urbanc@in.tum.de>
parents: 1979
diff changeset
   231
fun nth_dtyp_constrs_types descr sorts n =
3b83960f9544 new fv/fv_bn function (supp breaks now); exported raw perms and raw funs into separate ML-files
Christian Urban <urbanc@in.tum.de>
parents: 1979
diff changeset
   232
  nth (all_dtyp_constrs_types descr sorts) n
3b83960f9544 new fv/fv_bn function (supp breaks now); exported raw perms and raw funs into separate ML-files
Christian Urban <urbanc@in.tum.de>
parents: 1979
diff changeset
   233
3b83960f9544 new fv/fv_bn function (supp breaks now); exported raw perms and raw funs into separate ML-files
Christian Urban <urbanc@in.tum.de>
parents: 1979
diff changeset
   234
3b83960f9544 new fv/fv_bn function (supp breaks now); exported raw perms and raw funs into separate ML-files
Christian Urban <urbanc@in.tum.de>
parents: 1979
diff changeset
   235
(* generates for every datatype a name str ^ dt_name 
3b83960f9544 new fv/fv_bn function (supp breaks now); exported raw perms and raw funs into separate ML-files
Christian Urban <urbanc@in.tum.de>
parents: 1979
diff changeset
   236
   plus and index for multiple occurences of a string *)
3b83960f9544 new fv/fv_bn function (supp breaks now); exported raw perms and raw funs into separate ML-files
Christian Urban <urbanc@in.tum.de>
parents: 1979
diff changeset
   237
fun prefix_dt_names descr sorts str = 
2477
2f289c1f6cf1 tuned code
Christian Urban <urbanc@in.tum.de>
parents: 2475
diff changeset
   238
  let
2f289c1f6cf1 tuned code
Christian Urban <urbanc@in.tum.de>
parents: 2475
diff changeset
   239
    fun get_nth_name (i, _) = 
2f289c1f6cf1 tuned code
Christian Urban <urbanc@in.tum.de>
parents: 2475
diff changeset
   240
      Datatype_Aux.name_of_typ (nth_dtyp descr sorts i) 
2f289c1f6cf1 tuned code
Christian Urban <urbanc@in.tum.de>
parents: 2475
diff changeset
   241
  in
2f289c1f6cf1 tuned code
Christian Urban <urbanc@in.tum.de>
parents: 2475
diff changeset
   242
    Datatype_Prop.indexify_names 
2f289c1f6cf1 tuned code
Christian Urban <urbanc@in.tum.de>
parents: 2475
diff changeset
   243
      (map (prefix str o get_nth_name) descr)
2f289c1f6cf1 tuned code
Christian Urban <urbanc@in.tum.de>
parents: 2475
diff changeset
   244
  end
2288
3b83960f9544 new fv/fv_bn function (supp breaks now); exported raw perms and raw funs into separate ML-files
Christian Urban <urbanc@in.tum.de>
parents: 1979
diff changeset
   245
3b83960f9544 new fv/fv_bn function (supp breaks now); exported raw perms and raw funs into separate ML-files
Christian Urban <urbanc@in.tum.de>
parents: 1979
diff changeset
   246
2311
4da5c5c29009 work on transitivity proof
Christian Urban <urbanc@in.tum.de>
parents: 2304
diff changeset
   247
4da5c5c29009 work on transitivity proof
Christian Urban <urbanc@in.tum.de>
parents: 2304
diff changeset
   248
(** function package tactics **)
4da5c5c29009 work on transitivity proof
Christian Urban <urbanc@in.tum.de>
parents: 2304
diff changeset
   249
2304
8a98171ba1fc all raw definitions are defined using function
Christian Urban <urbanc@in.tum.de>
parents: 2296
diff changeset
   250
fun pat_completeness_simp simps lthy =
2477
2f289c1f6cf1 tuned code
Christian Urban <urbanc@in.tum.de>
parents: 2475
diff changeset
   251
  let
2f289c1f6cf1 tuned code
Christian Urban <urbanc@in.tum.de>
parents: 2475
diff changeset
   252
    val simp_set = HOL_basic_ss addsimps (@{thms sum.inject sum.distinct} @ simps)
2f289c1f6cf1 tuned code
Christian Urban <urbanc@in.tum.de>
parents: 2475
diff changeset
   253
  in
2f289c1f6cf1 tuned code
Christian Urban <urbanc@in.tum.de>
parents: 2475
diff changeset
   254
    Pat_Completeness.pat_completeness_tac lthy 1
2f289c1f6cf1 tuned code
Christian Urban <urbanc@in.tum.de>
parents: 2475
diff changeset
   255
      THEN ALLGOALS (asm_full_simp_tac simp_set)
2f289c1f6cf1 tuned code
Christian Urban <urbanc@in.tum.de>
parents: 2475
diff changeset
   256
  end
2304
8a98171ba1fc all raw definitions are defined using function
Christian Urban <urbanc@in.tum.de>
parents: 2296
diff changeset
   257
2557
781fbc8c0591 fixed locally the problem with the function package; all tests work again
Christian Urban <urbanc@in.tum.de>
parents: 2480
diff changeset
   258
2559
add799cf0817 adapted to changes by Florian on the quotient package and removed local fix for function package
Christian Urban <urbanc@in.tum.de>
parents: 2557
diff changeset
   259
fun prove_termination_tac size_simps ctxt =
2477
2f289c1f6cf1 tuned code
Christian Urban <urbanc@in.tum.de>
parents: 2475
diff changeset
   260
  let
2560
82e37a4595c7 automated permute_bn functions (raw ones first)
Christian Urban <urbanc@in.tum.de>
parents: 2559
diff changeset
   261
    val natT = @{typ nat}
82e37a4595c7 automated permute_bn functions (raw ones first)
Christian Urban <urbanc@in.tum.de>
parents: 2559
diff changeset
   262
    fun prod_size_const fT sT = 
82e37a4595c7 automated permute_bn functions (raw ones first)
Christian Urban <urbanc@in.tum.de>
parents: 2559
diff changeset
   263
      let
82e37a4595c7 automated permute_bn functions (raw ones first)
Christian Urban <urbanc@in.tum.de>
parents: 2559
diff changeset
   264
        val fT_fun = fT --> natT
82e37a4595c7 automated permute_bn functions (raw ones first)
Christian Urban <urbanc@in.tum.de>
parents: 2559
diff changeset
   265
        val sT_fun = sT --> natT
82e37a4595c7 automated permute_bn functions (raw ones first)
Christian Urban <urbanc@in.tum.de>
parents: 2559
diff changeset
   266
        val prodT = Type (@{type_name prod}, [fT, sT])
82e37a4595c7 automated permute_bn functions (raw ones first)
Christian Urban <urbanc@in.tum.de>
parents: 2559
diff changeset
   267
      in
82e37a4595c7 automated permute_bn functions (raw ones first)
Christian Urban <urbanc@in.tum.de>
parents: 2559
diff changeset
   268
        Const (@{const_name prod_size}, [fT_fun, sT_fun, prodT] ---> natT)
82e37a4595c7 automated permute_bn functions (raw ones first)
Christian Urban <urbanc@in.tum.de>
parents: 2559
diff changeset
   269
      end
82e37a4595c7 automated permute_bn functions (raw ones first)
Christian Urban <urbanc@in.tum.de>
parents: 2559
diff changeset
   270
82e37a4595c7 automated permute_bn functions (raw ones first)
Christian Urban <urbanc@in.tum.de>
parents: 2559
diff changeset
   271
    fun mk_size_measure T =
82e37a4595c7 automated permute_bn functions (raw ones first)
Christian Urban <urbanc@in.tum.de>
parents: 2559
diff changeset
   272
      case T of    
82e37a4595c7 automated permute_bn functions (raw ones first)
Christian Urban <urbanc@in.tum.de>
parents: 2559
diff changeset
   273
        (Type (@{type_name Sum_Type.sum}, [fT, sT])) =>
82e37a4595c7 automated permute_bn functions (raw ones first)
Christian Urban <urbanc@in.tum.de>
parents: 2559
diff changeset
   274
           SumTree.mk_sumcase fT sT natT (mk_size_measure fT) (mk_size_measure sT)
82e37a4595c7 automated permute_bn functions (raw ones first)
Christian Urban <urbanc@in.tum.de>
parents: 2559
diff changeset
   275
      | (Type (@{type_name Product_Type.prod}, [fT, sT])) =>
82e37a4595c7 automated permute_bn functions (raw ones first)
Christian Urban <urbanc@in.tum.de>
parents: 2559
diff changeset
   276
           prod_size_const fT sT $ (mk_size_measure fT) $ (mk_size_measure sT)
82e37a4595c7 automated permute_bn functions (raw ones first)
Christian Urban <urbanc@in.tum.de>
parents: 2559
diff changeset
   277
      | _ => size_const T
2304
8a98171ba1fc all raw definitions are defined using function
Christian Urban <urbanc@in.tum.de>
parents: 2296
diff changeset
   278
2559
add799cf0817 adapted to changes by Florian on the quotient package and removed local fix for function package
Christian Urban <urbanc@in.tum.de>
parents: 2557
diff changeset
   279
    fun mk_measure_trm T = 
add799cf0817 adapted to changes by Florian on the quotient package and removed local fix for function package
Christian Urban <urbanc@in.tum.de>
parents: 2557
diff changeset
   280
      HOLogic.dest_setT T
add799cf0817 adapted to changes by Florian on the quotient package and removed local fix for function package
Christian Urban <urbanc@in.tum.de>
parents: 2557
diff changeset
   281
      |> fst o HOLogic.dest_prodT
2477
2f289c1f6cf1 tuned code
Christian Urban <urbanc@in.tum.de>
parents: 2475
diff changeset
   282
      |> mk_size_measure 
2560
82e37a4595c7 automated permute_bn functions (raw ones first)
Christian Urban <urbanc@in.tum.de>
parents: 2559
diff changeset
   283
      |> curry (op $) (Const (@{const_name "measure"}, dummyT))
2477
2f289c1f6cf1 tuned code
Christian Urban <urbanc@in.tum.de>
parents: 2475
diff changeset
   284
      |> Syntax.check_term ctxt
2560
82e37a4595c7 automated permute_bn functions (raw ones first)
Christian Urban <urbanc@in.tum.de>
parents: 2559
diff changeset
   285
      
2477
2f289c1f6cf1 tuned code
Christian Urban <urbanc@in.tum.de>
parents: 2475
diff changeset
   286
    val ss = HOL_ss addsimps @{thms in_measure wf_measure sum.cases add_Suc_right add.right_neutral 
2560
82e37a4595c7 automated permute_bn functions (raw ones first)
Christian Urban <urbanc@in.tum.de>
parents: 2559
diff changeset
   287
      zero_less_Suc prod.size(1) mult_Suc_right} @ size_simps 
82e37a4595c7 automated permute_bn functions (raw ones first)
Christian Urban <urbanc@in.tum.de>
parents: 2559
diff changeset
   288
    val ss' = ss addsimprocs Nat_Numeral_Simprocs.cancel_numerals
2477
2f289c1f6cf1 tuned code
Christian Urban <urbanc@in.tum.de>
parents: 2475
diff changeset
   289
  in
2559
add799cf0817 adapted to changes by Florian on the quotient package and removed local fix for function package
Christian Urban <urbanc@in.tum.de>
parents: 2557
diff changeset
   290
    Function_Relation.relation_tac ctxt mk_measure_trm
2560
82e37a4595c7 automated permute_bn functions (raw ones first)
Christian Urban <urbanc@in.tum.de>
parents: 2559
diff changeset
   291
    THEN_ALL_NEW simp_tac ss'
2477
2f289c1f6cf1 tuned code
Christian Urban <urbanc@in.tum.de>
parents: 2475
diff changeset
   292
  end
2410
2bbdb9c427b5 improved runtime slightly, by constructing an explicit size measure for the function definitions
Christian Urban <urbanc@in.tum.de>
parents: 2408
diff changeset
   293
2bbdb9c427b5 improved runtime slightly, by constructing an explicit size measure for the function definitions
Christian Urban <urbanc@in.tum.de>
parents: 2408
diff changeset
   294
fun prove_termination size_simps ctxt = 
2bbdb9c427b5 improved runtime slightly, by constructing an explicit size measure for the function definitions
Christian Urban <urbanc@in.tum.de>
parents: 2408
diff changeset
   295
  Function.prove_termination NONE 
2bbdb9c427b5 improved runtime slightly, by constructing an explicit size measure for the function definitions
Christian Urban <urbanc@in.tum.de>
parents: 2408
diff changeset
   296
    (HEADGOAL (prove_termination_tac size_simps ctxt)) ctxt
2311
4da5c5c29009 work on transitivity proof
Christian Urban <urbanc@in.tum.de>
parents: 2304
diff changeset
   297
4da5c5c29009 work on transitivity proof
Christian Urban <urbanc@in.tum.de>
parents: 2304
diff changeset
   298
(** transformations of premises (in inductive proofs) **)
4da5c5c29009 work on transitivity proof
Christian Urban <urbanc@in.tum.de>
parents: 2304
diff changeset
   299
4da5c5c29009 work on transitivity proof
Christian Urban <urbanc@in.tum.de>
parents: 2304
diff changeset
   300
(* 
4da5c5c29009 work on transitivity proof
Christian Urban <urbanc@in.tum.de>
parents: 2304
diff changeset
   301
 given the theorem F[t]; proves the theorem F[f t] 
4da5c5c29009 work on transitivity proof
Christian Urban <urbanc@in.tum.de>
parents: 2304
diff changeset
   302
4da5c5c29009 work on transitivity proof
Christian Urban <urbanc@in.tum.de>
parents: 2304
diff changeset
   303
  - F needs to be monotone
4da5c5c29009 work on transitivity proof
Christian Urban <urbanc@in.tum.de>
parents: 2304
diff changeset
   304
  - f returns either SOME for a term it fires on 
4da5c5c29009 work on transitivity proof
Christian Urban <urbanc@in.tum.de>
parents: 2304
diff changeset
   305
    and NONE elsewhere 
4da5c5c29009 work on transitivity proof
Christian Urban <urbanc@in.tum.de>
parents: 2304
diff changeset
   306
*)
4da5c5c29009 work on transitivity proof
Christian Urban <urbanc@in.tum.de>
parents: 2304
diff changeset
   307
fun map_term f t = 
4da5c5c29009 work on transitivity proof
Christian Urban <urbanc@in.tum.de>
parents: 2304
diff changeset
   308
  (case f t of
4da5c5c29009 work on transitivity proof
Christian Urban <urbanc@in.tum.de>
parents: 2304
diff changeset
   309
     NONE => map_term' f t 
4da5c5c29009 work on transitivity proof
Christian Urban <urbanc@in.tum.de>
parents: 2304
diff changeset
   310
   | x => x)
4da5c5c29009 work on transitivity proof
Christian Urban <urbanc@in.tum.de>
parents: 2304
diff changeset
   311
and map_term' f (t $ u) = 
4da5c5c29009 work on transitivity proof
Christian Urban <urbanc@in.tum.de>
parents: 2304
diff changeset
   312
    (case (map_term f t, map_term f u) of
4da5c5c29009 work on transitivity proof
Christian Urban <urbanc@in.tum.de>
parents: 2304
diff changeset
   313
        (NONE, NONE) => NONE
4da5c5c29009 work on transitivity proof
Christian Urban <urbanc@in.tum.de>
parents: 2304
diff changeset
   314
      | (SOME t'', NONE) => SOME (t'' $ u)
4da5c5c29009 work on transitivity proof
Christian Urban <urbanc@in.tum.de>
parents: 2304
diff changeset
   315
      | (NONE, SOME u'') => SOME (t $ u'')
4da5c5c29009 work on transitivity proof
Christian Urban <urbanc@in.tum.de>
parents: 2304
diff changeset
   316
      | (SOME t'', SOME u'') => SOME (t'' $ u''))
4da5c5c29009 work on transitivity proof
Christian Urban <urbanc@in.tum.de>
parents: 2304
diff changeset
   317
  | map_term' f (Abs (s, T, t)) = 
4da5c5c29009 work on transitivity proof
Christian Urban <urbanc@in.tum.de>
parents: 2304
diff changeset
   318
      (case map_term f t of
4da5c5c29009 work on transitivity proof
Christian Urban <urbanc@in.tum.de>
parents: 2304
diff changeset
   319
        NONE => NONE
4da5c5c29009 work on transitivity proof
Christian Urban <urbanc@in.tum.de>
parents: 2304
diff changeset
   320
      | SOME t'' => SOME (Abs (s, T, t'')))
4da5c5c29009 work on transitivity proof
Christian Urban <urbanc@in.tum.de>
parents: 2304
diff changeset
   321
  | map_term' _ _  = NONE;
4da5c5c29009 work on transitivity proof
Christian Urban <urbanc@in.tum.de>
parents: 2304
diff changeset
   322
4da5c5c29009 work on transitivity proof
Christian Urban <urbanc@in.tum.de>
parents: 2304
diff changeset
   323
fun map_thm_tac ctxt tac thm =
2477
2f289c1f6cf1 tuned code
Christian Urban <urbanc@in.tum.de>
parents: 2475
diff changeset
   324
  let
2f289c1f6cf1 tuned code
Christian Urban <urbanc@in.tum.de>
parents: 2475
diff changeset
   325
    val monos = Inductive.get_monos ctxt
2f289c1f6cf1 tuned code
Christian Urban <urbanc@in.tum.de>
parents: 2475
diff changeset
   326
    val simps = HOL_basic_ss addsimps @{thms split_def}
2f289c1f6cf1 tuned code
Christian Urban <urbanc@in.tum.de>
parents: 2475
diff changeset
   327
  in
2f289c1f6cf1 tuned code
Christian Urban <urbanc@in.tum.de>
parents: 2475
diff changeset
   328
    EVERY [cut_facts_tac [thm] 1, etac rev_mp 1, 
2f289c1f6cf1 tuned code
Christian Urban <urbanc@in.tum.de>
parents: 2475
diff changeset
   329
      REPEAT_DETERM (FIRSTGOAL (simp_tac simps THEN' resolve_tac monos)),
2f289c1f6cf1 tuned code
Christian Urban <urbanc@in.tum.de>
parents: 2475
diff changeset
   330
      REPEAT_DETERM (rtac impI 1 THEN (atac 1 ORELSE tac))]
2f289c1f6cf1 tuned code
Christian Urban <urbanc@in.tum.de>
parents: 2475
diff changeset
   331
  end
2311
4da5c5c29009 work on transitivity proof
Christian Urban <urbanc@in.tum.de>
parents: 2304
diff changeset
   332
4da5c5c29009 work on transitivity proof
Christian Urban <urbanc@in.tum.de>
parents: 2304
diff changeset
   333
fun map_thm ctxt f tac thm =
2477
2f289c1f6cf1 tuned code
Christian Urban <urbanc@in.tum.de>
parents: 2475
diff changeset
   334
  let
2f289c1f6cf1 tuned code
Christian Urban <urbanc@in.tum.de>
parents: 2475
diff changeset
   335
    val opt_goal_trm = map_term f (prop_of thm)
2f289c1f6cf1 tuned code
Christian Urban <urbanc@in.tum.de>
parents: 2475
diff changeset
   336
  in
2f289c1f6cf1 tuned code
Christian Urban <urbanc@in.tum.de>
parents: 2475
diff changeset
   337
    case opt_goal_trm of
2f289c1f6cf1 tuned code
Christian Urban <urbanc@in.tum.de>
parents: 2475
diff changeset
   338
      NONE => thm
2f289c1f6cf1 tuned code
Christian Urban <urbanc@in.tum.de>
parents: 2475
diff changeset
   339
    | SOME goal =>
2f289c1f6cf1 tuned code
Christian Urban <urbanc@in.tum.de>
parents: 2475
diff changeset
   340
        Goal.prove ctxt [] [] goal (fn _ => map_thm_tac ctxt tac thm) 
2f289c1f6cf1 tuned code
Christian Urban <urbanc@in.tum.de>
parents: 2475
diff changeset
   341
  end
2311
4da5c5c29009 work on transitivity proof
Christian Urban <urbanc@in.tum.de>
parents: 2304
diff changeset
   342
4da5c5c29009 work on transitivity proof
Christian Urban <urbanc@in.tum.de>
parents: 2304
diff changeset
   343
(*
4da5c5c29009 work on transitivity proof
Christian Urban <urbanc@in.tum.de>
parents: 2304
diff changeset
   344
 inductive premises can be of the form
4da5c5c29009 work on transitivity proof
Christian Urban <urbanc@in.tum.de>
parents: 2304
diff changeset
   345
 R ... /\ P ...; split_conj_i picks out
4da5c5c29009 work on transitivity proof
Christian Urban <urbanc@in.tum.de>
parents: 2304
diff changeset
   346
 the part R or P part
4da5c5c29009 work on transitivity proof
Christian Urban <urbanc@in.tum.de>
parents: 2304
diff changeset
   347
*)
2480
ac7dff1194e8 introduced a general procedure for structural inductions; simplified reflexivity proof
Christian Urban <urbanc@in.tum.de>
parents: 2477
diff changeset
   348
fun split_conj1 names (Const (@{const_name "conj"}, _) $ f1 $ _) = 
2311
4da5c5c29009 work on transitivity proof
Christian Urban <urbanc@in.tum.de>
parents: 2304
diff changeset
   349
  (case head_of f1 of
4da5c5c29009 work on transitivity proof
Christian Urban <urbanc@in.tum.de>
parents: 2304
diff changeset
   350
     Const (name, _) => if member (op =) names name then SOME f1 else NONE
4da5c5c29009 work on transitivity proof
Christian Urban <urbanc@in.tum.de>
parents: 2304
diff changeset
   351
   | _ => NONE)
4da5c5c29009 work on transitivity proof
Christian Urban <urbanc@in.tum.de>
parents: 2304
diff changeset
   352
| split_conj1 _ _ = NONE;
4da5c5c29009 work on transitivity proof
Christian Urban <urbanc@in.tum.de>
parents: 2304
diff changeset
   353
2446
63c936b09764 updated to new Isabelle
Christian Urban <urbanc@in.tum.de>
parents: 2420
diff changeset
   354
fun split_conj2 names (Const (@{const_name "conj"}, _) $ f1 $ f2) = 
2311
4da5c5c29009 work on transitivity proof
Christian Urban <urbanc@in.tum.de>
parents: 2304
diff changeset
   355
  (case head_of f1 of
4da5c5c29009 work on transitivity proof
Christian Urban <urbanc@in.tum.de>
parents: 2304
diff changeset
   356
     Const (name, _) => if member (op =) names name then SOME f2 else NONE
4da5c5c29009 work on transitivity proof
Christian Urban <urbanc@in.tum.de>
parents: 2304
diff changeset
   357
   | _ => NONE)
4da5c5c29009 work on transitivity proof
Christian Urban <urbanc@in.tum.de>
parents: 2304
diff changeset
   358
| split_conj2 _ _ = NONE;
4da5c5c29009 work on transitivity proof
Christian Urban <urbanc@in.tum.de>
parents: 2304
diff changeset
   359
4da5c5c29009 work on transitivity proof
Christian Urban <urbanc@in.tum.de>
parents: 2304
diff changeset
   360
fun transform_prem1 ctxt names thm =
4da5c5c29009 work on transitivity proof
Christian Urban <urbanc@in.tum.de>
parents: 2304
diff changeset
   361
  map_thm ctxt (split_conj1 names) (etac conjunct1 1) thm
4da5c5c29009 work on transitivity proof
Christian Urban <urbanc@in.tum.de>
parents: 2304
diff changeset
   362
4da5c5c29009 work on transitivity proof
Christian Urban <urbanc@in.tum.de>
parents: 2304
diff changeset
   363
fun transform_prem2 ctxt names thm =
4da5c5c29009 work on transitivity proof
Christian Urban <urbanc@in.tum.de>
parents: 2304
diff changeset
   364
  map_thm ctxt (split_conj2 names) (etac conjunct2 1) thm
4da5c5c29009 work on transitivity proof
Christian Urban <urbanc@in.tum.de>
parents: 2304
diff changeset
   365
4da5c5c29009 work on transitivity proof
Christian Urban <urbanc@in.tum.de>
parents: 2304
diff changeset
   366
2397
c670a849af65 more experiments with lifting
Christian Urban <urbanc@in.tum.de>
parents: 2389
diff changeset
   367
(* transformes a theorem into one of the object logic *)
c670a849af65 more experiments with lifting
Christian Urban <urbanc@in.tum.de>
parents: 2389
diff changeset
   368
val atomize = Conv.fconv_rule Object_Logic.atomize o forall_intr_vars
c670a849af65 more experiments with lifting
Christian Urban <urbanc@in.tum.de>
parents: 2389
diff changeset
   369
1833
2050b5723c04 added a library for basic nominal functions; separated nominal_eqvt file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   370
end (* structure *)
2050b5723c04 added a library for basic nominal functions; separated nominal_eqvt file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   371
2050b5723c04 added a library for basic nominal functions; separated nominal_eqvt file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   372
open Nominal_Library;