Nominal/nominal_library.ML
author Christian Urban <christian dot urban at kcl dot ac dot uk>
Tue, 22 Mar 2016 12:18:30 +0000
changeset 3244 a44479bde681
parent 3239 67370521c09c
child 3245 017e33849f4d
permissions -rw-r--r--
fixed a problem with two example theories
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
2733
5f6fefdbf055 split the library into a basics file; merged Nominal_Eqvt into Nominal_Base
Christian Urban <urbanc@in.tum.de>
parents: 2647
diff changeset
     4
  Library 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
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
     9
  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
    10
  val atom_ty: typ -> typ
2569
94750b31a97d fixed bug in fv function where a shallow binder binds lists of names
Christian Urban <urbanc@in.tum.de>
parents: 2568
diff changeset
    11
  val atom_const: typ -> term
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
    12
  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
    13
  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
    14
2607
7430e07a5d61 moved setify and listify functions into the library; introduced versions that have a type argument
Christian Urban <urbanc@in.tum.de>
parents: 2603
diff changeset
    15
  val mk_atom_set_ty: typ -> term -> term
7430e07a5d61 moved setify and listify functions into the library; introduced versions that have a type argument
Christian Urban <urbanc@in.tum.de>
parents: 2603
diff changeset
    16
  val mk_atom_set: term -> term
7430e07a5d61 moved setify and listify functions into the library; introduced versions that have a type argument
Christian Urban <urbanc@in.tum.de>
parents: 2603
diff changeset
    17
  val mk_atom_fset_ty: typ -> term -> term
7430e07a5d61 moved setify and listify functions into the library; introduced versions that have a type argument
Christian Urban <urbanc@in.tum.de>
parents: 2603
diff changeset
    18
  val mk_atom_fset: term -> term
7430e07a5d61 moved setify and listify functions into the library; introduced versions that have a type argument
Christian Urban <urbanc@in.tum.de>
parents: 2603
diff changeset
    19
  val mk_atom_list_ty: typ -> term -> term
7430e07a5d61 moved setify and listify functions into the library; introduced versions that have a type argument
Christian Urban <urbanc@in.tum.de>
parents: 2603
diff changeset
    20
  val mk_atom_list: term -> term
7430e07a5d61 moved setify and listify functions into the library; introduced versions that have a type argument
Christian Urban <urbanc@in.tum.de>
parents: 2603
diff changeset
    21
7430e07a5d61 moved setify and listify functions into the library; introduced versions that have a type argument
Christian Urban <urbanc@in.tum.de>
parents: 2603
diff changeset
    22
  val is_atom: Proof.context -> typ -> bool
7430e07a5d61 moved setify and listify functions into the library; introduced versions that have a type argument
Christian Urban <urbanc@in.tum.de>
parents: 2603
diff changeset
    23
  val is_atom_set: Proof.context -> typ -> bool
7430e07a5d61 moved setify and listify functions into the library; introduced versions that have a type argument
Christian Urban <urbanc@in.tum.de>
parents: 2603
diff changeset
    24
  val is_atom_fset: Proof.context -> typ -> bool
7430e07a5d61 moved setify and listify functions into the library; introduced versions that have a type argument
Christian Urban <urbanc@in.tum.de>
parents: 2603
diff changeset
    25
  val is_atom_list: Proof.context -> typ -> bool
7430e07a5d61 moved setify and listify functions into the library; introduced versions that have a type argument
Christian Urban <urbanc@in.tum.de>
parents: 2603
diff changeset
    26
2608
86e3b39c2a60 created strong_exhausts terms
Christian Urban <urbanc@in.tum.de>
parents: 2607
diff changeset
    27
  val to_set_ty: typ -> term -> term
86e3b39c2a60 created strong_exhausts terms
Christian Urban <urbanc@in.tum.de>
parents: 2607
diff changeset
    28
  val to_set: term -> term
86e3b39c2a60 created strong_exhausts terms
Christian Urban <urbanc@in.tum.de>
parents: 2607
diff changeset
    29
  
2611
3d101f2f817c simple cases for strong inducts done; infrastructure for the difficult ones is there
Christian Urban <urbanc@in.tum.de>
parents: 2609
diff changeset
    30
  val atomify_ty: Proof.context -> typ -> term -> term
3d101f2f817c simple cases for strong inducts done; infrastructure for the difficult ones is there
Christian Urban <urbanc@in.tum.de>
parents: 2609
diff changeset
    31
  val atomify: Proof.context -> term -> term
2607
7430e07a5d61 moved setify and listify functions into the library; introduced versions that have a type argument
Christian Urban <urbanc@in.tum.de>
parents: 2603
diff changeset
    32
  val setify_ty: Proof.context -> typ -> term -> term
7430e07a5d61 moved setify and listify functions into the library; introduced versions that have a type argument
Christian Urban <urbanc@in.tum.de>
parents: 2603
diff changeset
    33
  val setify: Proof.context -> term -> term
7430e07a5d61 moved setify and listify functions into the library; introduced versions that have a type argument
Christian Urban <urbanc@in.tum.de>
parents: 2603
diff changeset
    34
  val listify_ty: Proof.context -> typ -> term -> term
7430e07a5d61 moved setify and listify functions into the library; introduced versions that have a type argument
Christian Urban <urbanc@in.tum.de>
parents: 2603
diff changeset
    35
  val listify: Proof.context -> term -> term
7430e07a5d61 moved setify and listify functions into the library; introduced versions that have a type argument
Christian Urban <urbanc@in.tum.de>
parents: 2603
diff changeset
    36
3177
c25e4c9481f2 added library routines for the constant fresh
Christian Urban <urbanc@in.tum.de>
parents: 3062
diff changeset
    37
  val fresh_ty: typ -> typ
c25e4c9481f2 added library routines for the constant fresh
Christian Urban <urbanc@in.tum.de>
parents: 3062
diff changeset
    38
  val fresh_const: typ -> term
c25e4c9481f2 added library routines for the constant fresh
Christian Urban <urbanc@in.tum.de>
parents: 3062
diff changeset
    39
  val mk_fresh_ty: typ -> term -> term -> term
c25e4c9481f2 added library routines for the constant fresh
Christian Urban <urbanc@in.tum.de>
parents: 3062
diff changeset
    40
  val mk_fresh: term -> term -> term
c25e4c9481f2 added library routines for the constant fresh
Christian Urban <urbanc@in.tum.de>
parents: 3062
diff changeset
    41
2608
86e3b39c2a60 created strong_exhausts terms
Christian Urban <urbanc@in.tum.de>
parents: 2607
diff changeset
    42
  val fresh_star_ty: typ -> typ
86e3b39c2a60 created strong_exhausts terms
Christian Urban <urbanc@in.tum.de>
parents: 2607
diff changeset
    43
  val fresh_star_const: typ -> term
86e3b39c2a60 created strong_exhausts terms
Christian Urban <urbanc@in.tum.de>
parents: 2607
diff changeset
    44
  val mk_fresh_star_ty: typ -> term -> term -> term
2607
7430e07a5d61 moved setify and listify functions into the library; introduced versions that have a type argument
Christian Urban <urbanc@in.tum.de>
parents: 2603
diff changeset
    45
  val mk_fresh_star: term -> term -> term
7430e07a5d61 moved setify and listify functions into the library; introduced versions that have a type argument
Christian Urban <urbanc@in.tum.de>
parents: 2603
diff changeset
    46
1979
760257a66604 added basic functions for constructing supp-terms
Christian Urban <urbanc@in.tum.de>
parents: 1963
diff changeset
    47
  val supp_ty: typ -> typ
2296
45a69c9cc4cc alpha works now
Christian Urban <urbanc@in.tum.de>
parents: 2289
diff changeset
    48
  val supp_const: typ -> term
1979
760257a66604 added basic functions for constructing supp-terms
Christian Urban <urbanc@in.tum.de>
parents: 1963
diff changeset
    49
  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
    50
  val mk_supp: term -> term
760257a66604 added basic functions for constructing supp-terms
Christian Urban <urbanc@in.tum.de>
parents: 1963
diff changeset
    51
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
    52
  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
    53
  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
    54
  val mk_supp_rel_ty: typ -> term -> term -> term
3229
b52e8651591f updated to Isabelle changes
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 3226
diff changeset
    55
  val mk_supp_rel: term -> term -> term
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
    56
2448
b9d9c4540265 proved supports lemmas
Christian Urban <urbanc@in.tum.de>
parents: 2446
diff changeset
    57
  val supports_const: typ -> term
b9d9c4540265 proved supports lemmas
Christian Urban <urbanc@in.tum.de>
parents: 2446
diff changeset
    58
  val mk_supports_ty: typ -> term -> term -> term
b9d9c4540265 proved supports lemmas
Christian Urban <urbanc@in.tum.de>
parents: 2446
diff changeset
    59
  val mk_supports: term -> term -> term
b9d9c4540265 proved supports lemmas
Christian Urban <urbanc@in.tum.de>
parents: 2446
diff changeset
    60
2450
217ef3e4282e added proofs for fsupp properties
Christian Urban <urbanc@in.tum.de>
parents: 2448
diff changeset
    61
  val finite_const: typ -> term
217ef3e4282e added proofs for fsupp properties
Christian Urban <urbanc@in.tum.de>
parents: 2448
diff changeset
    62
  val mk_finite_ty: typ -> term -> term
217ef3e4282e added proofs for fsupp properties
Christian Urban <urbanc@in.tum.de>
parents: 2448
diff changeset
    63
  val mk_finite: term -> term
217ef3e4282e added proofs for fsupp properties
Christian Urban <urbanc@in.tum.de>
parents: 2448
diff changeset
    64
2289
bf748be70109 moved some mk_union and mk_diff into the library
Christian Urban <urbanc@in.tum.de>
parents: 2288
diff changeset
    65
  val mk_diff: term * term -> term
2296
45a69c9cc4cc alpha works now
Christian Urban <urbanc@in.tum.de>
parents: 2289
diff changeset
    66
  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
    67
  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
    68
  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
    69
  val fold_append: term list -> term
2389
0f24c961b5f6 introduced a general alpha_prove method
Christian Urban <urbanc@in.tum.de>
parents: 2384
diff changeset
    70
  val mk_conj: term * term -> term
0f24c961b5f6 introduced a general alpha_prove method
Christian Urban <urbanc@in.tum.de>
parents: 2384
diff changeset
    71
  val fold_conj: term list -> term
2982
4a00077c008f completed the eqvt-proofs for functions; they are stored under the name function_name.eqvt and added to the eqvt-list
Christian Urban <urbanc@in.tum.de>
parents: 2887
diff changeset
    72
  val fold_conj_balanced: 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
    73
2625
478c5648e73f moved generic functions into nominal_library
Christian Urban <urbanc@in.tum.de>
parents: 2620
diff changeset
    74
  (* functions for de-Bruijn open terms *)
478c5648e73f moved generic functions into nominal_library
Christian Urban <urbanc@in.tum.de>
parents: 2620
diff changeset
    75
  val mk_binop_env: typ list -> string -> term * term -> term
478c5648e73f moved generic functions into nominal_library
Christian Urban <urbanc@in.tum.de>
parents: 2620
diff changeset
    76
  val mk_union_env: typ list -> term * term -> term
478c5648e73f moved generic functions into nominal_library
Christian Urban <urbanc@in.tum.de>
parents: 2620
diff changeset
    77
  val fold_union_env: typ list -> term list -> term
478c5648e73f moved generic functions into nominal_library
Christian Urban <urbanc@in.tum.de>
parents: 2620
diff changeset
    78
2448
b9d9c4540265 proved supports lemmas
Christian Urban <urbanc@in.tum.de>
parents: 2446
diff changeset
    79
  (* fresh arguments for a term *)
b9d9c4540265 proved supports lemmas
Christian Urban <urbanc@in.tum.de>
parents: 2446
diff changeset
    80
  val fresh_args: Proof.context -> term -> term list
b9d9c4540265 proved supports lemmas
Christian Urban <urbanc@in.tum.de>
parents: 2446
diff changeset
    81
2625
478c5648e73f moved generic functions into nominal_library
Christian Urban <urbanc@in.tum.de>
parents: 2620
diff changeset
    82
  (* some logic operations *)
478c5648e73f moved generic functions into nominal_library
Christian Urban <urbanc@in.tum.de>
parents: 2620
diff changeset
    83
  val strip_full_horn: term -> (string * typ) list * term list * term
478c5648e73f moved generic functions into nominal_library
Christian Urban <urbanc@in.tum.de>
parents: 2620
diff changeset
    84
  val mk_full_horn: (string * typ) list -> term list -> term -> term
478c5648e73f moved generic functions into nominal_library
Christian Urban <urbanc@in.tum.de>
parents: 2620
diff changeset
    85
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
    86
  (* datatype operations *)
2407
49ab06c0ca64 improved code
Christian Urban <urbanc@in.tum.de>
parents: 2399
diff changeset
    87
  type cns_info = (term * typ * typ list * bool list) list
49ab06c0ca64 improved code
Christian Urban <urbanc@in.tum.de>
parents: 2399
diff changeset
    88
3239
67370521c09c updated for Isabelle 2015
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 3233
diff changeset
    89
  val all_dtyp_constrs_types: Old_Datatype_Aux.descr -> cns_info 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
    90
2304
8a98171ba1fc all raw definitions are defined using function
Christian Urban <urbanc@in.tum.de>
parents: 2296
diff changeset
    91
  (* tactics for function package *)
3218
89158f401b07 updated to simplifier changes
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 3214
diff changeset
    92
  val size_ss: simpset
2304
8a98171ba1fc all raw definitions are defined using function
Christian Urban <urbanc@in.tum.de>
parents: 2296
diff changeset
    93
  val pat_completeness_simp: thm list -> Proof.context -> tactic
2630
8268b277d240 automated all strong induction lemmas
Christian Urban <urbanc@in.tum.de>
parents: 2625
diff changeset
    94
  val prove_termination_ind: Proof.context -> int -> tactic
8268b277d240 automated all strong induction lemmas
Christian Urban <urbanc@in.tum.de>
parents: 2625
diff changeset
    95
  val prove_termination_fun: 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
    96
2311
4da5c5c29009 work on transitivity proof
Christian Urban <urbanc@in.tum.de>
parents: 2304
diff changeset
    97
  (* transformations of premises in inductions *)
4da5c5c29009 work on transitivity proof
Christian Urban <urbanc@in.tum.de>
parents: 2304
diff changeset
    98
  val transform_prem1: Proof.context -> string list -> thm -> thm
4da5c5c29009 work on transitivity proof
Christian Urban <urbanc@in.tum.de>
parents: 2304
diff changeset
    99
  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
   100
c670a849af65 more experiments with lifting
Christian Urban <urbanc@in.tum.de>
parents: 2389
diff changeset
   101
  (* transformation into the object logic *)
3226
780b7a2c50b6 updated to changes in Isabelle
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 3218
diff changeset
   102
  val atomize: Proof.context -> thm -> thm
780b7a2c50b6 updated to changes in Isabelle
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 3218
diff changeset
   103
  val atomize_rule: Proof.context -> int -> thm -> thm 
780b7a2c50b6 updated to changes in Isabelle
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 3218
diff changeset
   104
  val atomize_concl: Proof.context -> thm -> thm
2398
1e6160690546 improved code
Christian Urban <urbanc@in.tum.de>
parents: 2397
diff changeset
   105
2625
478c5648e73f moved generic functions into nominal_library
Christian Urban <urbanc@in.tum.de>
parents: 2620
diff changeset
   106
  (* applies a tactic to a formula composed of conjunctions *)
3244
a44479bde681 fixed a problem with two example theories
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 3239
diff changeset
   107
  val conj_tac: Proof.context -> (int -> tactic) -> int -> tactic
1833
2050b5723c04 added a library for basic nominal functions; separated nominal_eqvt file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   108
end
2050b5723c04 added a library for basic nominal functions; separated nominal_eqvt file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   109
2050b5723c04 added a library for basic nominal functions; separated nominal_eqvt file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   110
2050b5723c04 added a library for basic nominal functions; separated nominal_eqvt file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   111
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
   112
struct
2050b5723c04 added a library for basic nominal functions; separated nominal_eqvt file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   113
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
   114
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
   115
1979
760257a66604 added basic functions for constructing supp-terms
Christian Urban <urbanc@in.tum.de>
parents: 1963
diff changeset
   116
fun atom_ty ty = ty --> @{typ "atom"};
2569
94750b31a97d fixed bug in fv function where a shallow binder binds lists of names
Christian Urban <urbanc@in.tum.de>
parents: 2568
diff changeset
   117
fun atom_const ty = Const (@{const_name "atom"}, atom_ty ty)
94750b31a97d fixed bug in fv function where a shallow binder binds lists of names
Christian Urban <urbanc@in.tum.de>
parents: 2568
diff changeset
   118
fun mk_atom_ty ty t = atom_const 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
   119
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
   120
2607
7430e07a5d61 moved setify and listify functions into the library; introduced versions that have a type argument
Christian Urban <urbanc@in.tum.de>
parents: 2603
diff changeset
   121
fun mk_atom_set_ty ty t =
7430e07a5d61 moved setify and listify functions into the library; introduced versions that have a type argument
Christian Urban <urbanc@in.tum.de>
parents: 2603
diff changeset
   122
  let
2611
3d101f2f817c simple cases for strong inducts done; infrastructure for the difficult ones is there
Christian Urban <urbanc@in.tum.de>
parents: 2609
diff changeset
   123
    val atom_ty = HOLogic.dest_setT ty 
3d101f2f817c simple cases for strong inducts done; infrastructure for the difficult ones is there
Christian Urban <urbanc@in.tum.de>
parents: 2609
diff changeset
   124
    val img_ty = (atom_ty --> @{typ atom}) --> ty --> @{typ "atom set"};
2607
7430e07a5d61 moved setify and listify functions into the library; introduced versions that have a type argument
Christian Urban <urbanc@in.tum.de>
parents: 2603
diff changeset
   125
  in
2611
3d101f2f817c simple cases for strong inducts done; infrastructure for the difficult ones is there
Christian Urban <urbanc@in.tum.de>
parents: 2609
diff changeset
   126
    Const (@{const_name image}, img_ty) $ atom_const atom_ty $ t
2607
7430e07a5d61 moved setify and listify functions into the library; introduced versions that have a type argument
Christian Urban <urbanc@in.tum.de>
parents: 2603
diff changeset
   127
  end
7430e07a5d61 moved setify and listify functions into the library; introduced versions that have a type argument
Christian Urban <urbanc@in.tum.de>
parents: 2603
diff changeset
   128
7430e07a5d61 moved setify and listify functions into the library; introduced versions that have a type argument
Christian Urban <urbanc@in.tum.de>
parents: 2603
diff changeset
   129
fun mk_atom_fset_ty ty t =
7430e07a5d61 moved setify and listify functions into the library; introduced versions that have a type argument
Christian Urban <urbanc@in.tum.de>
parents: 2603
diff changeset
   130
  let
7430e07a5d61 moved setify and listify functions into the library; introduced versions that have a type argument
Christian Urban <urbanc@in.tum.de>
parents: 2603
diff changeset
   131
    val atom_ty = dest_fsetT ty
7430e07a5d61 moved setify and listify functions into the library; introduced versions that have a type argument
Christian Urban <urbanc@in.tum.de>
parents: 2603
diff changeset
   132
    val fmap_ty = (atom_ty --> @{typ atom}) --> ty --> @{typ "atom fset"};
7430e07a5d61 moved setify and listify functions into the library; introduced versions that have a type argument
Christian Urban <urbanc@in.tum.de>
parents: 2603
diff changeset
   133
  in
2611
3d101f2f817c simple cases for strong inducts done; infrastructure for the difficult ones is there
Christian Urban <urbanc@in.tum.de>
parents: 2609
diff changeset
   134
    Const (@{const_name map_fset}, fmap_ty) $ atom_const atom_ty $ t
2607
7430e07a5d61 moved setify and listify functions into the library; introduced versions that have a type argument
Christian Urban <urbanc@in.tum.de>
parents: 2603
diff changeset
   135
  end
7430e07a5d61 moved setify and listify functions into the library; introduced versions that have a type argument
Christian Urban <urbanc@in.tum.de>
parents: 2603
diff changeset
   136
7430e07a5d61 moved setify and listify functions into the library; introduced versions that have a type argument
Christian Urban <urbanc@in.tum.de>
parents: 2603
diff changeset
   137
fun mk_atom_list_ty ty t =
7430e07a5d61 moved setify and listify functions into the library; introduced versions that have a type argument
Christian Urban <urbanc@in.tum.de>
parents: 2603
diff changeset
   138
  let
7430e07a5d61 moved setify and listify functions into the library; introduced versions that have a type argument
Christian Urban <urbanc@in.tum.de>
parents: 2603
diff changeset
   139
    val atom_ty = dest_listT ty
7430e07a5d61 moved setify and listify functions into the library; introduced versions that have a type argument
Christian Urban <urbanc@in.tum.de>
parents: 2603
diff changeset
   140
    val map_ty = (atom_ty --> @{typ atom}) --> ty --> @{typ "atom list"}
7430e07a5d61 moved setify and listify functions into the library; introduced versions that have a type argument
Christian Urban <urbanc@in.tum.de>
parents: 2603
diff changeset
   141
  in
2611
3d101f2f817c simple cases for strong inducts done; infrastructure for the difficult ones is there
Christian Urban <urbanc@in.tum.de>
parents: 2609
diff changeset
   142
    Const (@{const_name map}, map_ty) $ atom_const atom_ty $ t
2607
7430e07a5d61 moved setify and listify functions into the library; introduced versions that have a type argument
Christian Urban <urbanc@in.tum.de>
parents: 2603
diff changeset
   143
  end
7430e07a5d61 moved setify and listify functions into the library; introduced versions that have a type argument
Christian Urban <urbanc@in.tum.de>
parents: 2603
diff changeset
   144
7430e07a5d61 moved setify and listify functions into the library; introduced versions that have a type argument
Christian Urban <urbanc@in.tum.de>
parents: 2603
diff changeset
   145
fun mk_atom_set t = mk_atom_set_ty (fastype_of t) t
7430e07a5d61 moved setify and listify functions into the library; introduced versions that have a type argument
Christian Urban <urbanc@in.tum.de>
parents: 2603
diff changeset
   146
fun mk_atom_fset t = mk_atom_fset_ty (fastype_of t) t
7430e07a5d61 moved setify and listify functions into the library; introduced versions that have a type argument
Christian Urban <urbanc@in.tum.de>
parents: 2603
diff changeset
   147
fun mk_atom_list t = mk_atom_list_ty (fastype_of t) t
7430e07a5d61 moved setify and listify functions into the library; introduced versions that have a type argument
Christian Urban <urbanc@in.tum.de>
parents: 2603
diff changeset
   148
2608
86e3b39c2a60 created strong_exhausts terms
Christian Urban <urbanc@in.tum.de>
parents: 2607
diff changeset
   149
(* coerces a list into a set *)
86e3b39c2a60 created strong_exhausts terms
Christian Urban <urbanc@in.tum.de>
parents: 2607
diff changeset
   150
  
86e3b39c2a60 created strong_exhausts terms
Christian Urban <urbanc@in.tum.de>
parents: 2607
diff changeset
   151
fun to_set_ty ty t =
2611
3d101f2f817c simple cases for strong inducts done; infrastructure for the difficult ones is there
Christian Urban <urbanc@in.tum.de>
parents: 2609
diff changeset
   152
  case ty of
3d101f2f817c simple cases for strong inducts done; infrastructure for the difficult ones is there
Christian Urban <urbanc@in.tum.de>
parents: 2609
diff changeset
   153
    @{typ "atom list"} => @{term "set :: atom list => atom set"} $ t
3d101f2f817c simple cases for strong inducts done; infrastructure for the difficult ones is there
Christian Urban <urbanc@in.tum.de>
parents: 2609
diff changeset
   154
  | @{typ "atom fset"} => @{term "fset :: atom fset => atom set"} $ t
3d101f2f817c simple cases for strong inducts done; infrastructure for the difficult ones is there
Christian Urban <urbanc@in.tum.de>
parents: 2609
diff changeset
   155
  | _ => t
2608
86e3b39c2a60 created strong_exhausts terms
Christian Urban <urbanc@in.tum.de>
parents: 2607
diff changeset
   156
86e3b39c2a60 created strong_exhausts terms
Christian Urban <urbanc@in.tum.de>
parents: 2607
diff changeset
   157
fun to_set t = to_set_ty (fastype_of t) t
2607
7430e07a5d61 moved setify and listify functions into the library; introduced versions that have a type argument
Christian Urban <urbanc@in.tum.de>
parents: 2603
diff changeset
   158
7430e07a5d61 moved setify and listify functions into the library; introduced versions that have a type argument
Christian Urban <urbanc@in.tum.de>
parents: 2603
diff changeset
   159
7430e07a5d61 moved setify and listify functions into the library; introduced versions that have a type argument
Christian Urban <urbanc@in.tum.de>
parents: 2603
diff changeset
   160
(* testing for concrete atom types *)
7430e07a5d61 moved setify and listify functions into the library; introduced versions that have a type argument
Christian Urban <urbanc@in.tum.de>
parents: 2603
diff changeset
   161
fun is_atom ctxt ty =
3045
d0ad264f8c4f updated to Isabelle 3 Nov; it includes a hack to work around a bug in the localised version of the quotient package
Christian Urban <urbanc@in.tum.de>
parents: 2982
diff changeset
   162
  Sign.of_sort (Proof_Context.theory_of ctxt) (ty, @{sort at_base})
2607
7430e07a5d61 moved setify and listify functions into the library; introduced versions that have a type argument
Christian Urban <urbanc@in.tum.de>
parents: 2603
diff changeset
   163
2608
86e3b39c2a60 created strong_exhausts terms
Christian Urban <urbanc@in.tum.de>
parents: 2607
diff changeset
   164
fun is_atom_set ctxt (Type ("fun", [ty, @{typ bool}])) = is_atom ctxt ty
2607
7430e07a5d61 moved setify and listify functions into the library; introduced versions that have a type argument
Christian Urban <urbanc@in.tum.de>
parents: 2603
diff changeset
   165
  | is_atom_set _ _ = false;
7430e07a5d61 moved setify and listify functions into the library; introduced versions that have a type argument
Christian Urban <urbanc@in.tum.de>
parents: 2603
diff changeset
   166
2608
86e3b39c2a60 created strong_exhausts terms
Christian Urban <urbanc@in.tum.de>
parents: 2607
diff changeset
   167
fun is_atom_fset ctxt (Type (@{type_name "fset"}, [ty])) = is_atom ctxt ty
2607
7430e07a5d61 moved setify and listify functions into the library; introduced versions that have a type argument
Christian Urban <urbanc@in.tum.de>
parents: 2603
diff changeset
   168
  | is_atom_fset _ _ = false;
7430e07a5d61 moved setify and listify functions into the library; introduced versions that have a type argument
Christian Urban <urbanc@in.tum.de>
parents: 2603
diff changeset
   169
2608
86e3b39c2a60 created strong_exhausts terms
Christian Urban <urbanc@in.tum.de>
parents: 2607
diff changeset
   170
fun is_atom_list ctxt (Type (@{type_name "list"}, [ty])) = is_atom ctxt ty
2607
7430e07a5d61 moved setify and listify functions into the library; introduced versions that have a type argument
Christian Urban <urbanc@in.tum.de>
parents: 2603
diff changeset
   171
  | is_atom_list _ _ = false
7430e07a5d61 moved setify and listify functions into the library; introduced versions that have a type argument
Christian Urban <urbanc@in.tum.de>
parents: 2603
diff changeset
   172
7430e07a5d61 moved setify and listify functions into the library; introduced versions that have a type argument
Christian Urban <urbanc@in.tum.de>
parents: 2603
diff changeset
   173
2611
3d101f2f817c simple cases for strong inducts done; infrastructure for the difficult ones is there
Christian Urban <urbanc@in.tum.de>
parents: 2609
diff changeset
   174
(* functions that coerce singletons, sets, fsets and lists of concrete 
3d101f2f817c simple cases for strong inducts done; infrastructure for the difficult ones is there
Christian Urban <urbanc@in.tum.de>
parents: 2609
diff changeset
   175
   atoms into general atoms sets / lists *)
3d101f2f817c simple cases for strong inducts done; infrastructure for the difficult ones is there
Christian Urban <urbanc@in.tum.de>
parents: 2609
diff changeset
   176
fun atomify_ty ctxt ty t =
3d101f2f817c simple cases for strong inducts done; infrastructure for the difficult ones is there
Christian Urban <urbanc@in.tum.de>
parents: 2609
diff changeset
   177
  if is_atom ctxt ty
3d101f2f817c simple cases for strong inducts done; infrastructure for the difficult ones is there
Christian Urban <urbanc@in.tum.de>
parents: 2609
diff changeset
   178
    then  mk_atom_ty ty t
3d101f2f817c simple cases for strong inducts done; infrastructure for the difficult ones is there
Christian Urban <urbanc@in.tum.de>
parents: 2609
diff changeset
   179
  else if is_atom_set ctxt ty
3d101f2f817c simple cases for strong inducts done; infrastructure for the difficult ones is there
Christian Urban <urbanc@in.tum.de>
parents: 2609
diff changeset
   180
    then mk_atom_set_ty ty t
3d101f2f817c simple cases for strong inducts done; infrastructure for the difficult ones is there
Christian Urban <urbanc@in.tum.de>
parents: 2609
diff changeset
   181
  else if is_atom_fset ctxt ty
3d101f2f817c simple cases for strong inducts done; infrastructure for the difficult ones is there
Christian Urban <urbanc@in.tum.de>
parents: 2609
diff changeset
   182
    then mk_atom_fset_ty ty t
3d101f2f817c simple cases for strong inducts done; infrastructure for the difficult ones is there
Christian Urban <urbanc@in.tum.de>
parents: 2609
diff changeset
   183
  else if is_atom_list ctxt ty
3d101f2f817c simple cases for strong inducts done; infrastructure for the difficult ones is there
Christian Urban <urbanc@in.tum.de>
parents: 2609
diff changeset
   184
    then mk_atom_list_ty ty t
3214
13ab4f0a0b0e Various changes to support Nominal2 commands in local contexts.
webertj
parents: 3177
diff changeset
   185
  else raise TERM ("atomify: term is not an atom, set or list of atoms", [t])
2611
3d101f2f817c simple cases for strong inducts done; infrastructure for the difficult ones is there
Christian Urban <urbanc@in.tum.de>
parents: 2609
diff changeset
   186
2607
7430e07a5d61 moved setify and listify functions into the library; introduced versions that have a type argument
Christian Urban <urbanc@in.tum.de>
parents: 2603
diff changeset
   187
fun setify_ty ctxt ty t =
7430e07a5d61 moved setify and listify functions into the library; introduced versions that have a type argument
Christian Urban <urbanc@in.tum.de>
parents: 2603
diff changeset
   188
  if is_atom ctxt ty
3214
13ab4f0a0b0e Various changes to support Nominal2 commands in local contexts.
webertj
parents: 3177
diff changeset
   189
    then HOLogic.mk_set @{typ atom} [mk_atom_ty ty t]
2607
7430e07a5d61 moved setify and listify functions into the library; introduced versions that have a type argument
Christian Urban <urbanc@in.tum.de>
parents: 2603
diff changeset
   190
  else if is_atom_set ctxt ty
7430e07a5d61 moved setify and listify functions into the library; introduced versions that have a type argument
Christian Urban <urbanc@in.tum.de>
parents: 2603
diff changeset
   191
    then mk_atom_set_ty ty t
7430e07a5d61 moved setify and listify functions into the library; introduced versions that have a type argument
Christian Urban <urbanc@in.tum.de>
parents: 2603
diff changeset
   192
  else if is_atom_fset ctxt ty
2611
3d101f2f817c simple cases for strong inducts done; infrastructure for the difficult ones is there
Christian Urban <urbanc@in.tum.de>
parents: 2609
diff changeset
   193
    then @{term "fset :: atom fset => atom set"} $ mk_atom_fset_ty ty t
2608
86e3b39c2a60 created strong_exhausts terms
Christian Urban <urbanc@in.tum.de>
parents: 2607
diff changeset
   194
  else if is_atom_list ctxt ty
2611
3d101f2f817c simple cases for strong inducts done; infrastructure for the difficult ones is there
Christian Urban <urbanc@in.tum.de>
parents: 2609
diff changeset
   195
    then @{term "set :: atom list => atom set"} $ mk_atom_list_ty ty t
3214
13ab4f0a0b0e Various changes to support Nominal2 commands in local contexts.
webertj
parents: 3177
diff changeset
   196
  else raise TERM ("setify: term is not an atom, set or list of atoms", [t])
2607
7430e07a5d61 moved setify and listify functions into the library; introduced versions that have a type argument
Christian Urban <urbanc@in.tum.de>
parents: 2603
diff changeset
   197
7430e07a5d61 moved setify and listify functions into the library; introduced versions that have a type argument
Christian Urban <urbanc@in.tum.de>
parents: 2603
diff changeset
   198
fun listify_ty ctxt ty t =
7430e07a5d61 moved setify and listify functions into the library; introduced versions that have a type argument
Christian Urban <urbanc@in.tum.de>
parents: 2603
diff changeset
   199
  if is_atom ctxt ty
7430e07a5d61 moved setify and listify functions into the library; introduced versions that have a type argument
Christian Urban <urbanc@in.tum.de>
parents: 2603
diff changeset
   200
    then HOLogic.mk_list @{typ atom} [mk_atom_ty ty t]
7430e07a5d61 moved setify and listify functions into the library; introduced versions that have a type argument
Christian Urban <urbanc@in.tum.de>
parents: 2603
diff changeset
   201
  else if is_atom_list ctxt ty
7430e07a5d61 moved setify and listify functions into the library; introduced versions that have a type argument
Christian Urban <urbanc@in.tum.de>
parents: 2603
diff changeset
   202
    then mk_atom_list_ty ty t
3214
13ab4f0a0b0e Various changes to support Nominal2 commands in local contexts.
webertj
parents: 3177
diff changeset
   203
  else raise TERM ("listify: term is not an atom or list of atoms", [t])
2607
7430e07a5d61 moved setify and listify functions into the library; introduced versions that have a type argument
Christian Urban <urbanc@in.tum.de>
parents: 2603
diff changeset
   204
2611
3d101f2f817c simple cases for strong inducts done; infrastructure for the difficult ones is there
Christian Urban <urbanc@in.tum.de>
parents: 2609
diff changeset
   205
fun atomify ctxt t = atomify_ty ctxt (fastype_of t) t
3d101f2f817c simple cases for strong inducts done; infrastructure for the difficult ones is there
Christian Urban <urbanc@in.tum.de>
parents: 2609
diff changeset
   206
fun setify ctxt t  = setify_ty ctxt (fastype_of t) t
2607
7430e07a5d61 moved setify and listify functions into the library; introduced versions that have a type argument
Christian Urban <urbanc@in.tum.de>
parents: 2603
diff changeset
   207
fun listify ctxt t = listify_ty ctxt (fastype_of t) t
7430e07a5d61 moved setify and listify functions into the library; introduced versions that have a type argument
Christian Urban <urbanc@in.tum.de>
parents: 2603
diff changeset
   208
3177
c25e4c9481f2 added library routines for the constant fresh
Christian Urban <urbanc@in.tum.de>
parents: 3062
diff changeset
   209
fun fresh_ty ty = [@{typ atom}, ty] ---> @{typ bool}
c25e4c9481f2 added library routines for the constant fresh
Christian Urban <urbanc@in.tum.de>
parents: 3062
diff changeset
   210
fun fresh_const ty = Const (@{const_name fresh}, fresh_ty ty)
c25e4c9481f2 added library routines for the constant fresh
Christian Urban <urbanc@in.tum.de>
parents: 3062
diff changeset
   211
fun mk_fresh_ty ty t1 t2 = fresh_const ty $ t1 $ t2
c25e4c9481f2 added library routines for the constant fresh
Christian Urban <urbanc@in.tum.de>
parents: 3062
diff changeset
   212
fun mk_fresh t1 t2 = mk_fresh_ty (fastype_of t2) t1 t2
c25e4c9481f2 added library routines for the constant fresh
Christian Urban <urbanc@in.tum.de>
parents: 3062
diff changeset
   213
2608
86e3b39c2a60 created strong_exhausts terms
Christian Urban <urbanc@in.tum.de>
parents: 2607
diff changeset
   214
fun fresh_star_ty ty = [@{typ "atom set"}, ty] ---> @{typ bool}
86e3b39c2a60 created strong_exhausts terms
Christian Urban <urbanc@in.tum.de>
parents: 2607
diff changeset
   215
fun fresh_star_const ty = Const (@{const_name fresh_star}, fresh_star_ty ty)
86e3b39c2a60 created strong_exhausts terms
Christian Urban <urbanc@in.tum.de>
parents: 2607
diff changeset
   216
fun mk_fresh_star_ty ty t1 t2 = fresh_star_const ty $ t1 $ t2
86e3b39c2a60 created strong_exhausts terms
Christian Urban <urbanc@in.tum.de>
parents: 2607
diff changeset
   217
fun mk_fresh_star t1 t2 = mk_fresh_star_ty (fastype_of t2) t1 t2
2607
7430e07a5d61 moved setify and listify functions into the library; introduced versions that have a type argument
Christian Urban <urbanc@in.tum.de>
parents: 2603
diff changeset
   218
1979
760257a66604 added basic functions for constructing supp-terms
Christian Urban <urbanc@in.tum.de>
parents: 1963
diff changeset
   219
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
   220
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
   221
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
   222
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
   223
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
   224
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
   225
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
   226
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
   227
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
   228
2450
217ef3e4282e added proofs for fsupp properties
Christian Urban <urbanc@in.tum.de>
parents: 2448
diff changeset
   229
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
   230
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
   231
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
   232
2450
217ef3e4282e added proofs for fsupp properties
Christian Urban <urbanc@in.tum.de>
parents: 2448
diff changeset
   233
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
   234
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
   235
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
   236
217ef3e4282e added proofs for fsupp properties
Christian Urban <urbanc@in.tum.de>
parents: 2448
diff changeset
   237
2296
45a69c9cc4cc alpha works now
Christian Urban <urbanc@in.tum.de>
parents: 2289
diff changeset
   238
(* functions that construct differences, appends and unions
45a69c9cc4cc alpha works now
Christian Urban <urbanc@in.tum.de>
parents: 2289
diff changeset
   239
   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
   240
bf748be70109 moved some mk_union and mk_diff into the library
Christian Urban <urbanc@in.tum.de>
parents: 2288
diff changeset
   241
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
   242
  | 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
   243
  | 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
   244
  | 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
   245
  | 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
   246
2389
0f24c961b5f6 introduced a general alpha_prove method
Christian Urban <urbanc@in.tum.de>
parents: 2384
diff changeset
   247
fun mk_append (t1, @{term "[]::atom list"}) = t1
2296
45a69c9cc4cc alpha works now
Christian Urban <urbanc@in.tum.de>
parents: 2289
diff changeset
   248
  | mk_append (@{term "[]::atom list"}, t2) = t2
45a69c9cc4cc alpha works now
Christian Urban <urbanc@in.tum.de>
parents: 2289
diff changeset
   249
  | 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
   250
2389
0f24c961b5f6 introduced a general alpha_prove method
Christian Urban <urbanc@in.tum.de>
parents: 2384
diff changeset
   251
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
   252
  | 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
   253
  | 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
   254
  | mk_union (@{term "set ([]::atom list)"}, t2) = t2
2296
45a69c9cc4cc alpha works now
Christian Urban <urbanc@in.tum.de>
parents: 2289
diff changeset
   255
  | 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
   256
 
2384
841b7e34e70a fixed order of fold_union to make alpha and fv agree
Christian Urban <urbanc@in.tum.de>
parents: 2375
diff changeset
   257
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
   258
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
   259
2389
0f24c961b5f6 introduced a general alpha_prove method
Christian Urban <urbanc@in.tum.de>
parents: 2384
diff changeset
   260
fun mk_conj (t1, @{term "True"}) = t1
0f24c961b5f6 introduced a general alpha_prove method
Christian Urban <urbanc@in.tum.de>
parents: 2384
diff changeset
   261
  | mk_conj (@{term "True"}, t2) = t2
0f24c961b5f6 introduced a general alpha_prove method
Christian Urban <urbanc@in.tum.de>
parents: 2384
diff changeset
   262
  | 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
   263
2389
0f24c961b5f6 introduced a general alpha_prove method
Christian Urban <urbanc@in.tum.de>
parents: 2384
diff changeset
   264
fun fold_conj trms = fold_rev (curry mk_conj) trms @{term "True"}
2982
4a00077c008f completed the eqvt-proofs for functions; they are stored under the name function_name.eqvt and added to the eqvt-list
Christian Urban <urbanc@in.tum.de>
parents: 2887
diff changeset
   265
fun fold_conj_balanced ts = Balanced_Tree.make HOLogic.mk_conj ts
2296
45a69c9cc4cc alpha works now
Christian Urban <urbanc@in.tum.de>
parents: 2289
diff changeset
   266
2448
b9d9c4540265 proved supports lemmas
Christian Urban <urbanc@in.tum.de>
parents: 2446
diff changeset
   267
2625
478c5648e73f moved generic functions into nominal_library
Christian Urban <urbanc@in.tum.de>
parents: 2620
diff changeset
   268
(* functions for de-Bruijn open terms *)
478c5648e73f moved generic functions into nominal_library
Christian Urban <urbanc@in.tum.de>
parents: 2620
diff changeset
   269
478c5648e73f moved generic functions into nominal_library
Christian Urban <urbanc@in.tum.de>
parents: 2620
diff changeset
   270
fun mk_binop_env tys c (t, u) =
478c5648e73f moved generic functions into nominal_library
Christian Urban <urbanc@in.tum.de>
parents: 2620
diff changeset
   271
  let 
478c5648e73f moved generic functions into nominal_library
Christian Urban <urbanc@in.tum.de>
parents: 2620
diff changeset
   272
    val ty = fastype_of1 (tys, t) 
478c5648e73f moved generic functions into nominal_library
Christian Urban <urbanc@in.tum.de>
parents: 2620
diff changeset
   273
  in
478c5648e73f moved generic functions into nominal_library
Christian Urban <urbanc@in.tum.de>
parents: 2620
diff changeset
   274
    Const (c, [ty, ty] ---> ty) $ t $ u
478c5648e73f moved generic functions into nominal_library
Christian Urban <urbanc@in.tum.de>
parents: 2620
diff changeset
   275
  end
478c5648e73f moved generic functions into nominal_library
Christian Urban <urbanc@in.tum.de>
parents: 2620
diff changeset
   276
478c5648e73f moved generic functions into nominal_library
Christian Urban <urbanc@in.tum.de>
parents: 2620
diff changeset
   277
fun mk_union_env tys (t1, @{term "{}::atom set"}) = t1
478c5648e73f moved generic functions into nominal_library
Christian Urban <urbanc@in.tum.de>
parents: 2620
diff changeset
   278
  | mk_union_env tys (@{term "{}::atom set"}, t2) = t2
478c5648e73f moved generic functions into nominal_library
Christian Urban <urbanc@in.tum.de>
parents: 2620
diff changeset
   279
  | mk_union_env tys (t1, @{term "set ([]::atom list)"}) = t1
478c5648e73f moved generic functions into nominal_library
Christian Urban <urbanc@in.tum.de>
parents: 2620
diff changeset
   280
  | mk_union_env tys (@{term "set ([]::atom list)"}, t2) = t2
478c5648e73f moved generic functions into nominal_library
Christian Urban <urbanc@in.tum.de>
parents: 2620
diff changeset
   281
  | mk_union_env tys (t1, t2) = mk_binop_env tys @{const_name "sup"} (t1, t2)  
478c5648e73f moved generic functions into nominal_library
Christian Urban <urbanc@in.tum.de>
parents: 2620
diff changeset
   282
478c5648e73f moved generic functions into nominal_library
Christian Urban <urbanc@in.tum.de>
parents: 2620
diff changeset
   283
fun fold_union_env tys trms = fold_left (mk_union_env tys) trms @{term "{}::atom set"} 
478c5648e73f moved generic functions into nominal_library
Christian Urban <urbanc@in.tum.de>
parents: 2620
diff changeset
   284
478c5648e73f moved generic functions into nominal_library
Christian Urban <urbanc@in.tum.de>
parents: 2620
diff changeset
   285
2448
b9d9c4540265 proved supports lemmas
Christian Urban <urbanc@in.tum.de>
parents: 2446
diff changeset
   286
(* produces fresh arguments for a term *)
b9d9c4540265 proved supports lemmas
Christian Urban <urbanc@in.tum.de>
parents: 2446
diff changeset
   287
b9d9c4540265 proved supports lemmas
Christian Urban <urbanc@in.tum.de>
parents: 2446
diff changeset
   288
fun fresh_args ctxt f =
b9d9c4540265 proved supports lemmas
Christian Urban <urbanc@in.tum.de>
parents: 2446
diff changeset
   289
    f |> fastype_of
b9d9c4540265 proved supports lemmas
Christian Urban <urbanc@in.tum.de>
parents: 2446
diff changeset
   290
      |> binder_types
b9d9c4540265 proved supports lemmas
Christian Urban <urbanc@in.tum.de>
parents: 2446
diff changeset
   291
      |> map (pair "z")
b9d9c4540265 proved supports lemmas
Christian Urban <urbanc@in.tum.de>
parents: 2446
diff changeset
   292
      |> Variable.variant_frees ctxt [f]
b9d9c4540265 proved supports lemmas
Christian Urban <urbanc@in.tum.de>
parents: 2446
diff changeset
   293
      |> map Free
b9d9c4540265 proved supports lemmas
Christian Urban <urbanc@in.tum.de>
parents: 2446
diff changeset
   294
b9d9c4540265 proved supports lemmas
Christian Urban <urbanc@in.tum.de>
parents: 2446
diff changeset
   295
2625
478c5648e73f moved generic functions into nominal_library
Christian Urban <urbanc@in.tum.de>
parents: 2620
diff changeset
   296
(** some logic operations **)
478c5648e73f moved generic functions into nominal_library
Christian Urban <urbanc@in.tum.de>
parents: 2620
diff changeset
   297
478c5648e73f moved generic functions into nominal_library
Christian Urban <urbanc@in.tum.de>
parents: 2620
diff changeset
   298
(* decompses a formula into params, premises and a conclusion *)
478c5648e73f moved generic functions into nominal_library
Christian Urban <urbanc@in.tum.de>
parents: 2620
diff changeset
   299
fun strip_full_horn trm =
478c5648e73f moved generic functions into nominal_library
Christian Urban <urbanc@in.tum.de>
parents: 2620
diff changeset
   300
  let
3233
9ae285ce814e updated changes from upstream (AFP)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 3231
diff changeset
   301
    fun strip_outer_params (Const (@{const_name Pure.all}, _) $ Abs (a, T, t)) = strip_outer_params t |>> cons (a, T)
2625
478c5648e73f moved generic functions into nominal_library
Christian Urban <urbanc@in.tum.de>
parents: 2620
diff changeset
   302
    | strip_outer_params B = ([], B)
478c5648e73f moved generic functions into nominal_library
Christian Urban <urbanc@in.tum.de>
parents: 2620
diff changeset
   303
478c5648e73f moved generic functions into nominal_library
Christian Urban <urbanc@in.tum.de>
parents: 2620
diff changeset
   304
    val (params, body) = strip_outer_params trm
478c5648e73f moved generic functions into nominal_library
Christian Urban <urbanc@in.tum.de>
parents: 2620
diff changeset
   305
    val (prems, concl) = Logic.strip_horn body
478c5648e73f moved generic functions into nominal_library
Christian Urban <urbanc@in.tum.de>
parents: 2620
diff changeset
   306
  in
478c5648e73f moved generic functions into nominal_library
Christian Urban <urbanc@in.tum.de>
parents: 2620
diff changeset
   307
    (params, prems, concl)
478c5648e73f moved generic functions into nominal_library
Christian Urban <urbanc@in.tum.de>
parents: 2620
diff changeset
   308
  end
478c5648e73f moved generic functions into nominal_library
Christian Urban <urbanc@in.tum.de>
parents: 2620
diff changeset
   309
478c5648e73f moved generic functions into nominal_library
Christian Urban <urbanc@in.tum.de>
parents: 2620
diff changeset
   310
(* composes a formula out of params, premises and a conclusion *)
478c5648e73f moved generic functions into nominal_library
Christian Urban <urbanc@in.tum.de>
parents: 2620
diff changeset
   311
fun mk_full_horn params prems concl =
478c5648e73f moved generic functions into nominal_library
Christian Urban <urbanc@in.tum.de>
parents: 2620
diff changeset
   312
  Logic.list_implies (prems, concl)
478c5648e73f moved generic functions into nominal_library
Christian Urban <urbanc@in.tum.de>
parents: 2620
diff changeset
   313
  |> fold_rev mk_all params
2448
b9d9c4540265 proved supports lemmas
Christian Urban <urbanc@in.tum.de>
parents: 2446
diff changeset
   314
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
   315
(** 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
   316
2407
49ab06c0ca64 improved code
Christian Urban <urbanc@in.tum.de>
parents: 2399
diff changeset
   317
(* constructor infos *)
49ab06c0ca64 improved code
Christian Urban <urbanc@in.tum.de>
parents: 2399
diff changeset
   318
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
   319
2602
bcf558c445a4 moved some code into the nominal_library
Christian Urban <urbanc@in.tum.de>
parents: 2593
diff changeset
   320
(*  - term for constructor constant
bcf558c445a4 moved some code into the nominal_library
Christian Urban <urbanc@in.tum.de>
parents: 2593
diff changeset
   321
    - type of the constructor
bcf558c445a4 moved some code into the nominal_library
Christian Urban <urbanc@in.tum.de>
parents: 2593
diff changeset
   322
    - types of the arguments
bcf558c445a4 moved some code into the nominal_library
Christian Urban <urbanc@in.tum.de>
parents: 2593
diff changeset
   323
    - flags indicating whether the argument is recursive
bcf558c445a4 moved some code into the nominal_library
Christian Urban <urbanc@in.tum.de>
parents: 2593
diff changeset
   324
*)
bcf558c445a4 moved some code into the nominal_library
Christian Urban <urbanc@in.tum.de>
parents: 2593
diff changeset
   325
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
   326
(* 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
   327
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
   328
  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
   329
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
   330
(* 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
   331
   corresponding type and types of arguments *)
3062
b4b71c167e06 updated to Isabelle 13 Dec
Christian Urban <urbanc@in.tum.de>
parents: 3053
diff changeset
   332
fun all_dtyp_constrs_types 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
   333
  let
2477
2f289c1f6cf1 tuned code
Christian Urban <urbanc@in.tum.de>
parents: 2475
diff changeset
   334
    fun aux ((ty_name, vs), (cname, args)) =
2f289c1f6cf1 tuned code
Christian Urban <urbanc@in.tum.de>
parents: 2475
diff changeset
   335
      let
3239
67370521c09c updated for Isabelle 2015
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 3233
diff changeset
   336
        val vs_tys = map (Old_Datatype_Aux.typ_of_dtyp descr) vs
2477
2f289c1f6cf1 tuned code
Christian Urban <urbanc@in.tum.de>
parents: 2475
diff changeset
   337
        val ty = Type (ty_name, vs_tys)
3239
67370521c09c updated for Isabelle 2015
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 3233
diff changeset
   338
        val arg_tys = map (Old_Datatype_Aux.typ_of_dtyp descr) args
67370521c09c updated for Isabelle 2015
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 3233
diff changeset
   339
        val is_rec = map Old_Datatype_Aux.is_rec_type args
2477
2f289c1f6cf1 tuned code
Christian Urban <urbanc@in.tum.de>
parents: 2475
diff changeset
   340
      in
2f289c1f6cf1 tuned code
Christian Urban <urbanc@in.tum.de>
parents: 2475
diff changeset
   341
        (Const (cname, arg_tys ---> ty), ty, arg_tys, is_rec)
2f289c1f6cf1 tuned code
Christian Urban <urbanc@in.tum.de>
parents: 2475
diff changeset
   342
      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
   343
  in
2477
2f289c1f6cf1 tuned code
Christian Urban <urbanc@in.tum.de>
parents: 2475
diff changeset
   344
    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
   345
  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
   346
2311
4da5c5c29009 work on transitivity proof
Christian Urban <urbanc@in.tum.de>
parents: 2304
diff changeset
   347
(** function package tactics **)
4da5c5c29009 work on transitivity proof
Christian Urban <urbanc@in.tum.de>
parents: 2304
diff changeset
   348
3218
89158f401b07 updated to simplifier changes
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 3214
diff changeset
   349
fun pat_completeness_simp simps ctxt =
2477
2f289c1f6cf1 tuned code
Christian Urban <urbanc@in.tum.de>
parents: 2475
diff changeset
   350
  let
3218
89158f401b07 updated to simplifier changes
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 3214
diff changeset
   351
    val simpset =
89158f401b07 updated to simplifier changes
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 3214
diff changeset
   352
      put_simpset HOL_basic_ss ctxt addsimps (@{thms sum.inject sum.distinct} @ simps)
2477
2f289c1f6cf1 tuned code
Christian Urban <urbanc@in.tum.de>
parents: 2475
diff changeset
   353
  in
3218
89158f401b07 updated to simplifier changes
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 3214
diff changeset
   354
    Pat_Completeness.pat_completeness_tac ctxt 1
89158f401b07 updated to simplifier changes
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 3214
diff changeset
   355
      THEN ALLGOALS (asm_full_simp_tac simpset)
2477
2f289c1f6cf1 tuned code
Christian Urban <urbanc@in.tum.de>
parents: 2475
diff changeset
   356
  end
2304
8a98171ba1fc all raw definitions are defined using function
Christian Urban <urbanc@in.tum.de>
parents: 2296
diff changeset
   357
2630
8268b277d240 automated all strong induction lemmas
Christian Urban <urbanc@in.tum.de>
parents: 2625
diff changeset
   358
(* simpset for size goals *)
3218
89158f401b07 updated to simplifier changes
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 3214
diff changeset
   359
val size_ss =
89158f401b07 updated to simplifier changes
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 3214
diff changeset
   360
  simpset_of (put_simpset HOL_ss @{context}
3053
324b148fc6b5 used simproc-antiquotation
Christian Urban <urbanc@in.tum.de>
parents: 3045
diff changeset
   361
   addsimprocs [@{simproc natless_cancel_numerals}]
3229
b52e8651591f updated to Isabelle changes
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 3226
diff changeset
   362
   addsimps @{thms in_measure wf_measure sum.case add_Suc_right add.right_neutral 
3218
89158f401b07 updated to simplifier changes
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 3214
diff changeset
   363
     zero_less_Suc prod.size(1) mult_Suc_right})
2557
781fbc8c0591 fixed locally the problem with the function package; all tests work again
Christian Urban <urbanc@in.tum.de>
parents: 2480
diff changeset
   364
2630
8268b277d240 automated all strong induction lemmas
Christian Urban <urbanc@in.tum.de>
parents: 2625
diff changeset
   365
val natT = @{typ nat}
8268b277d240 automated all strong induction lemmas
Christian Urban <urbanc@in.tum.de>
parents: 2625
diff changeset
   366
    
3233
9ae285ce814e updated changes from upstream (AFP)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 3231
diff changeset
   367
fun size_prod_const T1 T2 = 
2477
2f289c1f6cf1 tuned code
Christian Urban <urbanc@in.tum.de>
parents: 2475
diff changeset
   368
  let
2630
8268b277d240 automated all strong induction lemmas
Christian Urban <urbanc@in.tum.de>
parents: 2625
diff changeset
   369
    val T1_fun = T1 --> natT
8268b277d240 automated all strong induction lemmas
Christian Urban <urbanc@in.tum.de>
parents: 2625
diff changeset
   370
    val T2_fun = T2 --> natT
8268b277d240 automated all strong induction lemmas
Christian Urban <urbanc@in.tum.de>
parents: 2625
diff changeset
   371
    val prodT = HOLogic.mk_prodT (T1, T2)
8268b277d240 automated all strong induction lemmas
Christian Urban <urbanc@in.tum.de>
parents: 2625
diff changeset
   372
  in
3233
9ae285ce814e updated changes from upstream (AFP)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 3231
diff changeset
   373
    Const (@{const_name size_prod}, [T1_fun, T2_fun, prodT] ---> natT)
2630
8268b277d240 automated all strong induction lemmas
Christian Urban <urbanc@in.tum.de>
parents: 2625
diff changeset
   374
  end
8268b277d240 automated all strong induction lemmas
Christian Urban <urbanc@in.tum.de>
parents: 2625
diff changeset
   375
8268b277d240 automated all strong induction lemmas
Christian Urban <urbanc@in.tum.de>
parents: 2625
diff changeset
   376
fun snd_const T1 T2 =
3229
b52e8651591f updated to Isabelle changes
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 3226
diff changeset
   377
  Const (@{const_name Product_Type.snd}, HOLogic.mk_prodT (T1, T2) --> T2) 
2630
8268b277d240 automated all strong induction lemmas
Christian Urban <urbanc@in.tum.de>
parents: 2625
diff changeset
   378
2560
82e37a4595c7 automated permute_bn functions (raw ones first)
Christian Urban <urbanc@in.tum.de>
parents: 2559
diff changeset
   379
2630
8268b277d240 automated all strong induction lemmas
Christian Urban <urbanc@in.tum.de>
parents: 2625
diff changeset
   380
fun mk_measure_trm f ctxt T = 
8268b277d240 automated all strong induction lemmas
Christian Urban <urbanc@in.tum.de>
parents: 2625
diff changeset
   381
  HOLogic.dest_setT T
8268b277d240 automated all strong induction lemmas
Christian Urban <urbanc@in.tum.de>
parents: 2625
diff changeset
   382
  |> fst o HOLogic.dest_prodT
8268b277d240 automated all strong induction lemmas
Christian Urban <urbanc@in.tum.de>
parents: 2625
diff changeset
   383
  |> f
8268b277d240 automated all strong induction lemmas
Christian Urban <urbanc@in.tum.de>
parents: 2625
diff changeset
   384
  |> curry (op $) (Const (@{const_name "measure"}, dummyT))
8268b277d240 automated all strong induction lemmas
Christian Urban <urbanc@in.tum.de>
parents: 2625
diff changeset
   385
  |> Syntax.check_term ctxt
8268b277d240 automated all strong induction lemmas
Christian Urban <urbanc@in.tum.de>
parents: 2625
diff changeset
   386
  
8268b277d240 automated all strong induction lemmas
Christian Urban <urbanc@in.tum.de>
parents: 2625
diff changeset
   387
(* wf-goal arising in induction_schema *)    
8268b277d240 automated all strong induction lemmas
Christian Urban <urbanc@in.tum.de>
parents: 2625
diff changeset
   388
fun prove_termination_ind ctxt =
8268b277d240 automated all strong induction lemmas
Christian Urban <urbanc@in.tum.de>
parents: 2625
diff changeset
   389
  let
2560
82e37a4595c7 automated permute_bn functions (raw ones first)
Christian Urban <urbanc@in.tum.de>
parents: 2559
diff changeset
   390
    fun mk_size_measure T =
82e37a4595c7 automated permute_bn functions (raw ones first)
Christian Urban <urbanc@in.tum.de>
parents: 2559
diff changeset
   391
      case T of    
2630
8268b277d240 automated all strong induction lemmas
Christian Urban <urbanc@in.tum.de>
parents: 2625
diff changeset
   392
        (Type (@{type_name Sum_Type.sum}, [T1, T2])) =>
3229
b52e8651591f updated to Isabelle changes
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 3226
diff changeset
   393
           Sum_Tree.mk_sumcase T1 T2 natT (mk_size_measure T1) (mk_size_measure T2)
2630
8268b277d240 automated all strong induction lemmas
Christian Urban <urbanc@in.tum.de>
parents: 2625
diff changeset
   394
      | (Type (@{type_name Product_Type.prod}, [T1, T2])) =>
8268b277d240 automated all strong induction lemmas
Christian Urban <urbanc@in.tum.de>
parents: 2625
diff changeset
   395
           HOLogic.mk_comp (mk_size_measure T2, snd_const T1 T2)
2611
3d101f2f817c simple cases for strong inducts done; infrastructure for the difficult ones is there
Christian Urban <urbanc@in.tum.de>
parents: 2609
diff changeset
   396
      | _ => HOLogic.size_const T
2304
8a98171ba1fc all raw definitions are defined using function
Christian Urban <urbanc@in.tum.de>
parents: 2296
diff changeset
   397
2630
8268b277d240 automated all strong induction lemmas
Christian Urban <urbanc@in.tum.de>
parents: 2625
diff changeset
   398
    val measure_trm = mk_measure_trm (mk_size_measure) ctxt
8268b277d240 automated all strong induction lemmas
Christian Urban <urbanc@in.tum.de>
parents: 2625
diff changeset
   399
  in 
8268b277d240 automated all strong induction lemmas
Christian Urban <urbanc@in.tum.de>
parents: 2625
diff changeset
   400
    Function_Relation.relation_tac ctxt measure_trm
2477
2f289c1f6cf1 tuned code
Christian Urban <urbanc@in.tum.de>
parents: 2475
diff changeset
   401
  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
   402
2630
8268b277d240 automated all strong induction lemmas
Christian Urban <urbanc@in.tum.de>
parents: 2625
diff changeset
   403
(* wf-goal arising in function definitions *)
8268b277d240 automated all strong induction lemmas
Christian Urban <urbanc@in.tum.de>
parents: 2625
diff changeset
   404
fun prove_termination_fun size_simps ctxt =
8268b277d240 automated all strong induction lemmas
Christian Urban <urbanc@in.tum.de>
parents: 2625
diff changeset
   405
let
8268b277d240 automated all strong induction lemmas
Christian Urban <urbanc@in.tum.de>
parents: 2625
diff changeset
   406
  fun mk_size_measure T =
8268b277d240 automated all strong induction lemmas
Christian Urban <urbanc@in.tum.de>
parents: 2625
diff changeset
   407
    case T of    
8268b277d240 automated all strong induction lemmas
Christian Urban <urbanc@in.tum.de>
parents: 2625
diff changeset
   408
      (Type (@{type_name Sum_Type.sum}, [T1, T2])) =>
3229
b52e8651591f updated to Isabelle changes
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 3226
diff changeset
   409
         Sum_Tree.mk_sumcase T1 T2 natT (mk_size_measure T1) (mk_size_measure T2)
2630
8268b277d240 automated all strong induction lemmas
Christian Urban <urbanc@in.tum.de>
parents: 2625
diff changeset
   410
    | (Type (@{type_name Product_Type.prod}, [T1, T2])) =>
3233
9ae285ce814e updated changes from upstream (AFP)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 3231
diff changeset
   411
         size_prod_const T1 T2 $ (mk_size_measure T1) $ (mk_size_measure T2)
2630
8268b277d240 automated all strong induction lemmas
Christian Urban <urbanc@in.tum.de>
parents: 2625
diff changeset
   412
    | _ => HOLogic.size_const T
8268b277d240 automated all strong induction lemmas
Christian Urban <urbanc@in.tum.de>
parents: 2625
diff changeset
   413
8268b277d240 automated all strong induction lemmas
Christian Urban <urbanc@in.tum.de>
parents: 2625
diff changeset
   414
  val measure_trm = mk_measure_trm (mk_size_measure) ctxt
8268b277d240 automated all strong induction lemmas
Christian Urban <urbanc@in.tum.de>
parents: 2625
diff changeset
   415
8268b277d240 automated all strong induction lemmas
Christian Urban <urbanc@in.tum.de>
parents: 2625
diff changeset
   416
  val tac = 
8268b277d240 automated all strong induction lemmas
Christian Urban <urbanc@in.tum.de>
parents: 2625
diff changeset
   417
    Function_Relation.relation_tac ctxt measure_trm
3218
89158f401b07 updated to simplifier changes
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 3214
diff changeset
   418
    THEN_ALL_NEW simp_tac (put_simpset size_ss ctxt addsimps size_simps)
2630
8268b277d240 automated all strong induction lemmas
Christian Urban <urbanc@in.tum.de>
parents: 2625
diff changeset
   419
  in 
8268b277d240 automated all strong induction lemmas
Christian Urban <urbanc@in.tum.de>
parents: 2625
diff changeset
   420
    Function.prove_termination NONE (HEADGOAL tac) ctxt
8268b277d240 automated all strong induction lemmas
Christian Urban <urbanc@in.tum.de>
parents: 2625
diff changeset
   421
  end
2311
4da5c5c29009 work on transitivity proof
Christian Urban <urbanc@in.tum.de>
parents: 2304
diff changeset
   422
4da5c5c29009 work on transitivity proof
Christian Urban <urbanc@in.tum.de>
parents: 2304
diff changeset
   423
(** transformations of premises (in inductive proofs) **)
4da5c5c29009 work on transitivity proof
Christian Urban <urbanc@in.tum.de>
parents: 2304
diff changeset
   424
4da5c5c29009 work on transitivity proof
Christian Urban <urbanc@in.tum.de>
parents: 2304
diff changeset
   425
(* 
4da5c5c29009 work on transitivity proof
Christian Urban <urbanc@in.tum.de>
parents: 2304
diff changeset
   426
 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
   427
4da5c5c29009 work on transitivity proof
Christian Urban <urbanc@in.tum.de>
parents: 2304
diff changeset
   428
  - F needs to be monotone
4da5c5c29009 work on transitivity proof
Christian Urban <urbanc@in.tum.de>
parents: 2304
diff changeset
   429
  - 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
   430
    and NONE elsewhere 
4da5c5c29009 work on transitivity proof
Christian Urban <urbanc@in.tum.de>
parents: 2304
diff changeset
   431
*)
4da5c5c29009 work on transitivity proof
Christian Urban <urbanc@in.tum.de>
parents: 2304
diff changeset
   432
fun map_term f t = 
4da5c5c29009 work on transitivity proof
Christian Urban <urbanc@in.tum.de>
parents: 2304
diff changeset
   433
  (case f t of
4da5c5c29009 work on transitivity proof
Christian Urban <urbanc@in.tum.de>
parents: 2304
diff changeset
   434
     NONE => map_term' f t 
4da5c5c29009 work on transitivity proof
Christian Urban <urbanc@in.tum.de>
parents: 2304
diff changeset
   435
   | x => x)
4da5c5c29009 work on transitivity proof
Christian Urban <urbanc@in.tum.de>
parents: 2304
diff changeset
   436
and map_term' f (t $ u) = 
4da5c5c29009 work on transitivity proof
Christian Urban <urbanc@in.tum.de>
parents: 2304
diff changeset
   437
    (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
   438
        (NONE, NONE) => NONE
4da5c5c29009 work on transitivity proof
Christian Urban <urbanc@in.tum.de>
parents: 2304
diff changeset
   439
      | (SOME t'', NONE) => SOME (t'' $ u)
4da5c5c29009 work on transitivity proof
Christian Urban <urbanc@in.tum.de>
parents: 2304
diff changeset
   440
      | (NONE, SOME u'') => SOME (t $ u'')
4da5c5c29009 work on transitivity proof
Christian Urban <urbanc@in.tum.de>
parents: 2304
diff changeset
   441
      | (SOME t'', SOME u'') => SOME (t'' $ u''))
4da5c5c29009 work on transitivity proof
Christian Urban <urbanc@in.tum.de>
parents: 2304
diff changeset
   442
  | map_term' f (Abs (s, T, t)) = 
4da5c5c29009 work on transitivity proof
Christian Urban <urbanc@in.tum.de>
parents: 2304
diff changeset
   443
      (case map_term f t of
4da5c5c29009 work on transitivity proof
Christian Urban <urbanc@in.tum.de>
parents: 2304
diff changeset
   444
        NONE => NONE
4da5c5c29009 work on transitivity proof
Christian Urban <urbanc@in.tum.de>
parents: 2304
diff changeset
   445
      | SOME t'' => SOME (Abs (s, T, t'')))
4da5c5c29009 work on transitivity proof
Christian Urban <urbanc@in.tum.de>
parents: 2304
diff changeset
   446
  | map_term' _ _  = NONE;
4da5c5c29009 work on transitivity proof
Christian Urban <urbanc@in.tum.de>
parents: 2304
diff changeset
   447
4da5c5c29009 work on transitivity proof
Christian Urban <urbanc@in.tum.de>
parents: 2304
diff changeset
   448
fun map_thm_tac ctxt tac thm =
2477
2f289c1f6cf1 tuned code
Christian Urban <urbanc@in.tum.de>
parents: 2475
diff changeset
   449
  let
2f289c1f6cf1 tuned code
Christian Urban <urbanc@in.tum.de>
parents: 2475
diff changeset
   450
    val monos = Inductive.get_monos ctxt
3218
89158f401b07 updated to simplifier changes
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 3214
diff changeset
   451
    val simpset = put_simpset HOL_basic_ss ctxt addsimps @{thms split_def}
2477
2f289c1f6cf1 tuned code
Christian Urban <urbanc@in.tum.de>
parents: 2475
diff changeset
   452
  in
3244
a44479bde681 fixed a problem with two example theories
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 3239
diff changeset
   453
    EVERY [cut_facts_tac [thm] 1, eresolve_tac ctxt [rev_mp] 1, 
3239
67370521c09c updated for Isabelle 2015
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 3233
diff changeset
   454
      REPEAT_DETERM (FIRSTGOAL (simp_tac simpset THEN' resolve_tac ctxt monos)),
3244
a44479bde681 fixed a problem with two example theories
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 3239
diff changeset
   455
      REPEAT_DETERM (resolve_tac ctxt [impI] 1 THEN (assume_tac ctxt 1 ORELSE tac))]
2477
2f289c1f6cf1 tuned code
Christian Urban <urbanc@in.tum.de>
parents: 2475
diff changeset
   456
  end
2311
4da5c5c29009 work on transitivity proof
Christian Urban <urbanc@in.tum.de>
parents: 2304
diff changeset
   457
4da5c5c29009 work on transitivity proof
Christian Urban <urbanc@in.tum.de>
parents: 2304
diff changeset
   458
fun map_thm ctxt f tac thm =
2477
2f289c1f6cf1 tuned code
Christian Urban <urbanc@in.tum.de>
parents: 2475
diff changeset
   459
  let
3239
67370521c09c updated for Isabelle 2015
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 3233
diff changeset
   460
    val opt_goal_trm = map_term f (Thm.prop_of thm)
2477
2f289c1f6cf1 tuned code
Christian Urban <urbanc@in.tum.de>
parents: 2475
diff changeset
   461
  in
2f289c1f6cf1 tuned code
Christian Urban <urbanc@in.tum.de>
parents: 2475
diff changeset
   462
    case opt_goal_trm of
2f289c1f6cf1 tuned code
Christian Urban <urbanc@in.tum.de>
parents: 2475
diff changeset
   463
      NONE => thm
2f289c1f6cf1 tuned code
Christian Urban <urbanc@in.tum.de>
parents: 2475
diff changeset
   464
    | SOME goal =>
2f289c1f6cf1 tuned code
Christian Urban <urbanc@in.tum.de>
parents: 2475
diff changeset
   465
        Goal.prove ctxt [] [] goal (fn _ => map_thm_tac ctxt tac thm) 
2f289c1f6cf1 tuned code
Christian Urban <urbanc@in.tum.de>
parents: 2475
diff changeset
   466
  end
2311
4da5c5c29009 work on transitivity proof
Christian Urban <urbanc@in.tum.de>
parents: 2304
diff changeset
   467
4da5c5c29009 work on transitivity proof
Christian Urban <urbanc@in.tum.de>
parents: 2304
diff changeset
   468
(*
4da5c5c29009 work on transitivity proof
Christian Urban <urbanc@in.tum.de>
parents: 2304
diff changeset
   469
 inductive premises can be of the form
2868
2b8e387d2dfc got rid of the boolean flag in the raw_equivariance function
Christian Urban <urbanc@in.tum.de>
parents: 2733
diff changeset
   470
2b8e387d2dfc got rid of the boolean flag in the raw_equivariance function
Christian Urban <urbanc@in.tum.de>
parents: 2733
diff changeset
   471
     R ... /\ P ...; 
2b8e387d2dfc got rid of the boolean flag in the raw_equivariance function
Christian Urban <urbanc@in.tum.de>
parents: 2733
diff changeset
   472
 
2b8e387d2dfc got rid of the boolean flag in the raw_equivariance function
Christian Urban <urbanc@in.tum.de>
parents: 2733
diff changeset
   473
 split_conj_i picks out the part R or P part
2311
4da5c5c29009 work on transitivity proof
Christian Urban <urbanc@in.tum.de>
parents: 2304
diff changeset
   474
*)
2480
ac7dff1194e8 introduced a general procedure for structural inductions; simplified reflexivity proof
Christian Urban <urbanc@in.tum.de>
parents: 2477
diff changeset
   475
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
   476
  (case head_of f1 of
4da5c5c29009 work on transitivity proof
Christian Urban <urbanc@in.tum.de>
parents: 2304
diff changeset
   477
     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
   478
   | _ => NONE)
4da5c5c29009 work on transitivity proof
Christian Urban <urbanc@in.tum.de>
parents: 2304
diff changeset
   479
| split_conj1 _ _ = NONE;
4da5c5c29009 work on transitivity proof
Christian Urban <urbanc@in.tum.de>
parents: 2304
diff changeset
   480
2446
63c936b09764 updated to new Isabelle
Christian Urban <urbanc@in.tum.de>
parents: 2420
diff changeset
   481
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
   482
  (case head_of f1 of
4da5c5c29009 work on transitivity proof
Christian Urban <urbanc@in.tum.de>
parents: 2304
diff changeset
   483
     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
   484
   | _ => NONE)
4da5c5c29009 work on transitivity proof
Christian Urban <urbanc@in.tum.de>
parents: 2304
diff changeset
   485
| split_conj2 _ _ = NONE;
4da5c5c29009 work on transitivity proof
Christian Urban <urbanc@in.tum.de>
parents: 2304
diff changeset
   486
4da5c5c29009 work on transitivity proof
Christian Urban <urbanc@in.tum.de>
parents: 2304
diff changeset
   487
fun transform_prem1 ctxt names thm =
3244
a44479bde681 fixed a problem with two example theories
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 3239
diff changeset
   488
  map_thm ctxt (split_conj1 names) (eresolve_tac ctxt [conjunct1] 1) thm
2311
4da5c5c29009 work on transitivity proof
Christian Urban <urbanc@in.tum.de>
parents: 2304
diff changeset
   489
4da5c5c29009 work on transitivity proof
Christian Urban <urbanc@in.tum.de>
parents: 2304
diff changeset
   490
fun transform_prem2 ctxt names thm =
3244
a44479bde681 fixed a problem with two example theories
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 3239
diff changeset
   491
  map_thm ctxt (split_conj2 names) (eresolve_tac ctxt [conjunct2] 1) thm
2311
4da5c5c29009 work on transitivity proof
Christian Urban <urbanc@in.tum.de>
parents: 2304
diff changeset
   492
4da5c5c29009 work on transitivity proof
Christian Urban <urbanc@in.tum.de>
parents: 2304
diff changeset
   493
3214
13ab4f0a0b0e Various changes to support Nominal2 commands in local contexts.
webertj
parents: 3177
diff changeset
   494
(* transforms a theorem into one of the object logic *)
3226
780b7a2c50b6 updated to changes in Isabelle
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 3218
diff changeset
   495
fun atomize ctxt = Conv.fconv_rule (Object_Logic.atomize ctxt) o forall_intr_vars;
780b7a2c50b6 updated to changes in Isabelle
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 3218
diff changeset
   496
fun atomize_rule ctxt i thm =
780b7a2c50b6 updated to changes in Isabelle
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 3218
diff changeset
   497
  Conv.fconv_rule (Conv.concl_conv i (Object_Logic.atomize ctxt)) thm
3239
67370521c09c updated for Isabelle 2015
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 3233
diff changeset
   498
fun atomize_concl ctxt thm = atomize_rule ctxt (length (Thm.prems_of thm)) thm
2982
4a00077c008f completed the eqvt-proofs for functions; they are stored under the name function_name.eqvt and added to the eqvt-list
Christian Urban <urbanc@in.tum.de>
parents: 2887
diff changeset
   499
4a00077c008f completed the eqvt-proofs for functions; they are stored under the name function_name.eqvt and added to the eqvt-list
Christian Urban <urbanc@in.tum.de>
parents: 2887
diff changeset
   500
2625
478c5648e73f moved generic functions into nominal_library
Christian Urban <urbanc@in.tum.de>
parents: 2620
diff changeset
   501
(* applies a tactic to a formula composed of conjunctions *)
3244
a44479bde681 fixed a problem with two example theories
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 3239
diff changeset
   502
fun conj_tac ctxt tac i =
2625
478c5648e73f moved generic functions into nominal_library
Christian Urban <urbanc@in.tum.de>
parents: 2620
diff changeset
   503
  let
478c5648e73f moved generic functions into nominal_library
Christian Urban <urbanc@in.tum.de>
parents: 2620
diff changeset
   504
     fun select (trm, i) =
478c5648e73f moved generic functions into nominal_library
Christian Urban <urbanc@in.tum.de>
parents: 2620
diff changeset
   505
       case trm of
478c5648e73f moved generic functions into nominal_library
Christian Urban <urbanc@in.tum.de>
parents: 2620
diff changeset
   506
         @{term "Trueprop"} $ t' => select (t', i)
3244
a44479bde681 fixed a problem with two example theories
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 3239
diff changeset
   507
       | @{term "op &"} $ _ $ _ =>
a44479bde681 fixed a problem with two example theories
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 3239
diff changeset
   508
          EVERY' [resolve_tac ctxt @{thms conjI}, RANGE [conj_tac ctxt tac, conj_tac ctxt tac]] i
2625
478c5648e73f moved generic functions into nominal_library
Christian Urban <urbanc@in.tum.de>
parents: 2620
diff changeset
   509
       | _ => tac i
478c5648e73f moved generic functions into nominal_library
Christian Urban <urbanc@in.tum.de>
parents: 2620
diff changeset
   510
  in
478c5648e73f moved generic functions into nominal_library
Christian Urban <urbanc@in.tum.de>
parents: 2620
diff changeset
   511
    SUBGOAL select i
478c5648e73f moved generic functions into nominal_library
Christian Urban <urbanc@in.tum.de>
parents: 2620
diff changeset
   512
  end
478c5648e73f moved generic functions into nominal_library
Christian Urban <urbanc@in.tum.de>
parents: 2620
diff changeset
   513
1833
2050b5723c04 added a library for basic nominal functions; separated nominal_eqvt file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   514
end (* structure *)
2050b5723c04 added a library for basic nominal functions; separated nominal_eqvt file
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   515
3229
b52e8651591f updated to Isabelle changes
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 3226
diff changeset
   516
open Nominal_Library;