Nominal/nominal_basics.ML
author Christian Urban <urbanc@in.tum.de>
Thu, 16 Feb 2012 07:14:28 +0000
changeset 3120 368fc38321fc
parent 3108 61db5ad429bb
child 3214 13ab4f0a0b0e
permissions -rw-r--r--
same as in function_common
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2733
5f6fefdbf055 split the library into a basics file; merged Nominal_Eqvt into Nominal_Base
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     1
(*  Title:      nominal_basic.ML
5f6fefdbf055 split the library into a basics file; merged Nominal_Eqvt into Nominal_Base
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     2
    Author:     Christian Urban
5f6fefdbf055 split the library into a basics file; merged Nominal_Eqvt into Nominal_Base
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     3
5f6fefdbf055 split the library into a basics file; merged Nominal_Eqvt into Nominal_Base
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     4
  Basic functions for nominal.
5f6fefdbf055 split the library into a basics file; merged Nominal_Eqvt into Nominal_Base
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     5
*)
5f6fefdbf055 split the library into a basics file; merged Nominal_Eqvt into Nominal_Base
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     6
2962
7a24d827cba9 combinators for local theories and lists
Christian Urban <urbanc@in.tum.de>
parents: 2959
diff changeset
     7
infix 1 ||>>> |>>>
7a24d827cba9 combinators for local theories and lists
Christian Urban <urbanc@in.tum.de>
parents: 2959
diff changeset
     8
2733
5f6fefdbf055 split the library into a basics file; merged Nominal_Eqvt into Nominal_Base
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     9
signature NOMINAL_BASIC =
5f6fefdbf055 split the library into a basics file; merged Nominal_Eqvt into Nominal_Base
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    10
sig
5f6fefdbf055 split the library into a basics file; merged Nominal_Eqvt into Nominal_Base
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    11
  val trace: bool Unsynchronized.ref
5f6fefdbf055 split the library into a basics file; merged Nominal_Eqvt into Nominal_Base
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    12
  val trace_msg: (unit -> string) -> unit
5f6fefdbf055 split the library into a basics file; merged Nominal_Eqvt into Nominal_Base
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    13
2962
7a24d827cba9 combinators for local theories and lists
Christian Urban <urbanc@in.tum.de>
parents: 2959
diff changeset
    14
  val |>>> : 'a * ('a -> 'b * 'c) -> 'b list * 'c
7a24d827cba9 combinators for local theories and lists
Christian Urban <urbanc@in.tum.de>
parents: 2959
diff changeset
    15
  val ||>>> : ('a list * 'b) * ('b -> 'a * 'b) -> 'a list * 'b
7a24d827cba9 combinators for local theories and lists
Christian Urban <urbanc@in.tum.de>
parents: 2959
diff changeset
    16
2733
5f6fefdbf055 split the library into a basics file; merged Nominal_Eqvt into Nominal_Base
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    17
  val last2: 'a list -> 'a * 'a
2959
9bd97ed202f7 some code refactoring
Christian Urban <urbanc@in.tum.de>
parents: 2733
diff changeset
    18
  val split_triples: ('a * 'b * 'c) list -> ('a list * 'b list * 'c list)
2733
5f6fefdbf055 split the library into a basics file; merged Nominal_Eqvt into Nominal_Base
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    19
  val split_last2: 'a list -> 'a list * 'a * 'a
5f6fefdbf055 split the library into a basics file; merged Nominal_Eqvt into Nominal_Base
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    20
  val order: ('a * 'a -> bool) -> 'a list -> ('a * 'b) list -> 'b list
5f6fefdbf055 split the library into a basics file; merged Nominal_Eqvt into Nominal_Base
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    21
  val order_default: ('a * 'a -> bool) -> 'b -> 'a list -> ('a * 'b) list -> 'b list
5f6fefdbf055 split the library into a basics file; merged Nominal_Eqvt into Nominal_Base
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    22
  val remove_dups: ('a * 'a -> bool) -> 'a list -> 'a list
5f6fefdbf055 split the library into a basics file; merged Nominal_Eqvt into Nominal_Base
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    23
  val map4: ('a -> 'b -> 'c -> 'd -> 'e) -> 'a list -> 'b list -> 'c list -> 'd list -> 'e list
5f6fefdbf055 split the library into a basics file; merged Nominal_Eqvt into Nominal_Base
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    24
  val split_filter: ('a -> bool) -> 'a list -> 'a list * 'a list
5f6fefdbf055 split the library into a basics file; merged Nominal_Eqvt into Nominal_Base
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    25
  val fold_left: ('a * 'a -> 'a) -> 'a list -> 'a -> 'a
5f6fefdbf055 split the library into a basics file; merged Nominal_Eqvt into Nominal_Base
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    26
  
5f6fefdbf055 split the library into a basics file; merged Nominal_Eqvt into Nominal_Base
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    27
  val is_true: term -> bool
5f6fefdbf055 split the library into a basics file; merged Nominal_Eqvt into Nominal_Base
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    28
 
5f6fefdbf055 split the library into a basics file; merged Nominal_Eqvt into Nominal_Base
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    29
  val dest_listT: typ -> typ
5f6fefdbf055 split the library into a basics file; merged Nominal_Eqvt into Nominal_Base
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    30
  val dest_fsetT: typ -> typ
5f6fefdbf055 split the library into a basics file; merged Nominal_Eqvt into Nominal_Base
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    31
5f6fefdbf055 split the library into a basics file; merged Nominal_Eqvt into Nominal_Base
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    32
  val mk_id: term -> term
5f6fefdbf055 split the library into a basics file; merged Nominal_Eqvt into Nominal_Base
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    33
  val mk_all: (string * typ) -> term -> term
5f6fefdbf055 split the library into a basics file; merged Nominal_Eqvt into Nominal_Base
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    34
  val mk_All: (string * typ) -> term -> term
5f6fefdbf055 split the library into a basics file; merged Nominal_Eqvt into Nominal_Base
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    35
  val mk_exists: (string * typ) -> term -> term
5f6fefdbf055 split the library into a basics file; merged Nominal_Eqvt into Nominal_Base
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    36
5f6fefdbf055 split the library into a basics file; merged Nominal_Eqvt into Nominal_Base
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    37
  val sum_case_const: typ -> typ -> typ -> term
5f6fefdbf055 split the library into a basics file; merged Nominal_Eqvt into Nominal_Base
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    38
  val mk_sum_case: term -> term -> term
5f6fefdbf055 split the library into a basics file; merged Nominal_Eqvt into Nominal_Base
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    39
 
5f6fefdbf055 split the library into a basics file; merged Nominal_Eqvt into Nominal_Base
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    40
  val mk_equiv: thm -> thm
5f6fefdbf055 split the library into a basics file; merged Nominal_Eqvt into Nominal_Base
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    41
  val safe_mk_equiv: thm -> thm
5f6fefdbf055 split the library into a basics file; merged Nominal_Eqvt into Nominal_Base
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    42
5f6fefdbf055 split the library into a basics file; merged Nominal_Eqvt into Nominal_Base
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    43
  val mk_minus: term -> term
5f6fefdbf055 split the library into a basics file; merged Nominal_Eqvt into Nominal_Base
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    44
  val mk_plus: term -> term -> term
5f6fefdbf055 split the library into a basics file; merged Nominal_Eqvt into Nominal_Base
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    45
5f6fefdbf055 split the library into a basics file; merged Nominal_Eqvt into Nominal_Base
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    46
  val perm_ty: typ -> typ 
5f6fefdbf055 split the library into a basics file; merged Nominal_Eqvt into Nominal_Base
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    47
  val perm_const: typ -> term
5f6fefdbf055 split the library into a basics file; merged Nominal_Eqvt into Nominal_Base
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    48
  val mk_perm_ty: typ -> term -> term -> term
5f6fefdbf055 split the library into a basics file; merged Nominal_Eqvt into Nominal_Base
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    49
  val mk_perm: term -> term -> term
5f6fefdbf055 split the library into a basics file; merged Nominal_Eqvt into Nominal_Base
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    50
  val dest_perm: term -> term * term
5f6fefdbf055 split the library into a basics file; merged Nominal_Eqvt into Nominal_Base
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    51
5f6fefdbf055 split the library into a basics file; merged Nominal_Eqvt into Nominal_Base
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    52
end
5f6fefdbf055 split the library into a basics file; merged Nominal_Eqvt into Nominal_Base
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    53
5f6fefdbf055 split the library into a basics file; merged Nominal_Eqvt into Nominal_Base
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    54
5f6fefdbf055 split the library into a basics file; merged Nominal_Eqvt into Nominal_Base
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    55
structure Nominal_Basic: NOMINAL_BASIC =
5f6fefdbf055 split the library into a basics file; merged Nominal_Eqvt into Nominal_Base
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    56
struct
5f6fefdbf055 split the library into a basics file; merged Nominal_Eqvt into Nominal_Base
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    57
5f6fefdbf055 split the library into a basics file; merged Nominal_Eqvt into Nominal_Base
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    58
val trace = Unsynchronized.ref false
5f6fefdbf055 split the library into a basics file; merged Nominal_Eqvt into Nominal_Base
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    59
fun trace_msg msg = if ! trace then tracing (msg ()) else ()
5f6fefdbf055 split the library into a basics file; merged Nominal_Eqvt into Nominal_Base
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    60
5f6fefdbf055 split the library into a basics file; merged Nominal_Eqvt into Nominal_Base
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    61
2962
7a24d827cba9 combinators for local theories and lists
Christian Urban <urbanc@in.tum.de>
parents: 2959
diff changeset
    62
infix 1 ||>>> |>>>
7a24d827cba9 combinators for local theories and lists
Christian Urban <urbanc@in.tum.de>
parents: 2959
diff changeset
    63
7a24d827cba9 combinators for local theories and lists
Christian Urban <urbanc@in.tum.de>
parents: 2959
diff changeset
    64
fun (x |>>> f) = 
7a24d827cba9 combinators for local theories and lists
Christian Urban <urbanc@in.tum.de>
parents: 2959
diff changeset
    65
  let 
7a24d827cba9 combinators for local theories and lists
Christian Urban <urbanc@in.tum.de>
parents: 2959
diff changeset
    66
    val (x', y') = f x 
7a24d827cba9 combinators for local theories and lists
Christian Urban <urbanc@in.tum.de>
parents: 2959
diff changeset
    67
  in
7a24d827cba9 combinators for local theories and lists
Christian Urban <urbanc@in.tum.de>
parents: 2959
diff changeset
    68
    ([x'], y')
7a24d827cba9 combinators for local theories and lists
Christian Urban <urbanc@in.tum.de>
parents: 2959
diff changeset
    69
  end
7a24d827cba9 combinators for local theories and lists
Christian Urban <urbanc@in.tum.de>
parents: 2959
diff changeset
    70
7a24d827cba9 combinators for local theories and lists
Christian Urban <urbanc@in.tum.de>
parents: 2959
diff changeset
    71
fun (([], y) ||>>> f) = ([], y)  
7a24d827cba9 combinators for local theories and lists
Christian Urban <urbanc@in.tum.de>
parents: 2959
diff changeset
    72
  | ((xs, y) ||>>> f) =
7a24d827cba9 combinators for local theories and lists
Christian Urban <urbanc@in.tum.de>
parents: 2959
diff changeset
    73
       let
7a24d827cba9 combinators for local theories and lists
Christian Urban <urbanc@in.tum.de>
parents: 2959
diff changeset
    74
         val (x', y') = f y
7a24d827cba9 combinators for local theories and lists
Christian Urban <urbanc@in.tum.de>
parents: 2959
diff changeset
    75
       in
7a24d827cba9 combinators for local theories and lists
Christian Urban <urbanc@in.tum.de>
parents: 2959
diff changeset
    76
         (xs @ [x'], y')
7a24d827cba9 combinators for local theories and lists
Christian Urban <urbanc@in.tum.de>
parents: 2959
diff changeset
    77
       end
7a24d827cba9 combinators for local theories and lists
Christian Urban <urbanc@in.tum.de>
parents: 2959
diff changeset
    78
7a24d827cba9 combinators for local theories and lists
Christian Urban <urbanc@in.tum.de>
parents: 2959
diff changeset
    79
2733
5f6fefdbf055 split the library into a basics file; merged Nominal_Eqvt into Nominal_Base
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    80
(* orders an AList according to keys - every key needs to be there *)
5f6fefdbf055 split the library into a basics file; merged Nominal_Eqvt into Nominal_Base
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    81
fun order eq keys list = 
5f6fefdbf055 split the library into a basics file; merged Nominal_Eqvt into Nominal_Base
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    82
  map (the o AList.lookup eq list) keys
5f6fefdbf055 split the library into a basics file; merged Nominal_Eqvt into Nominal_Base
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    83
5f6fefdbf055 split the library into a basics file; merged Nominal_Eqvt into Nominal_Base
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    84
(* orders an AList according to keys - returns default for non-existing keys *)
5f6fefdbf055 split the library into a basics file; merged Nominal_Eqvt into Nominal_Base
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    85
fun order_default eq default keys list = 
5f6fefdbf055 split the library into a basics file; merged Nominal_Eqvt into Nominal_Base
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    86
  map (the_default default o AList.lookup eq list) keys
5f6fefdbf055 split the library into a basics file; merged Nominal_Eqvt into Nominal_Base
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    87
5f6fefdbf055 split the library into a basics file; merged Nominal_Eqvt into Nominal_Base
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    88
(* remove duplicates *)
5f6fefdbf055 split the library into a basics file; merged Nominal_Eqvt into Nominal_Base
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    89
fun remove_dups eq [] = []
5f6fefdbf055 split the library into a basics file; merged Nominal_Eqvt into Nominal_Base
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    90
  | remove_dups eq (x :: xs) = 
5f6fefdbf055 split the library into a basics file; merged Nominal_Eqvt into Nominal_Base
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    91
      if member eq xs x 
5f6fefdbf055 split the library into a basics file; merged Nominal_Eqvt into Nominal_Base
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    92
      then remove_dups eq xs 
5f6fefdbf055 split the library into a basics file; merged Nominal_Eqvt into Nominal_Base
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    93
      else x :: remove_dups eq xs
5f6fefdbf055 split the library into a basics file; merged Nominal_Eqvt into Nominal_Base
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    94
2959
9bd97ed202f7 some code refactoring
Christian Urban <urbanc@in.tum.de>
parents: 2733
diff changeset
    95
fun split_triples xs =
9bd97ed202f7 some code refactoring
Christian Urban <urbanc@in.tum.de>
parents: 2733
diff changeset
    96
  fold (fn (a, b, c) => fn (axs, bxs, cxs) => (a :: axs, b :: bxs, c :: cxs)) xs ([], [], [])
9bd97ed202f7 some code refactoring
Christian Urban <urbanc@in.tum.de>
parents: 2733
diff changeset
    97
2733
5f6fefdbf055 split the library into a basics file; merged Nominal_Eqvt into Nominal_Base
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    98
fun last2 [] = raise Empty
5f6fefdbf055 split the library into a basics file; merged Nominal_Eqvt into Nominal_Base
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    99
  | last2 [_] = raise Empty
5f6fefdbf055 split the library into a basics file; merged Nominal_Eqvt into Nominal_Base
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   100
  | last2 [x, y] = (x, y)
5f6fefdbf055 split the library into a basics file; merged Nominal_Eqvt into Nominal_Base
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   101
  | last2 (_ :: xs) = last2 xs
5f6fefdbf055 split the library into a basics file; merged Nominal_Eqvt into Nominal_Base
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   102
5f6fefdbf055 split the library into a basics file; merged Nominal_Eqvt into Nominal_Base
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   103
fun split_last2 xs = 
5f6fefdbf055 split the library into a basics file; merged Nominal_Eqvt into Nominal_Base
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   104
  let
5f6fefdbf055 split the library into a basics file; merged Nominal_Eqvt into Nominal_Base
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   105
    val (xs', x) = split_last xs
5f6fefdbf055 split the library into a basics file; merged Nominal_Eqvt into Nominal_Base
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   106
    val (xs'', y) = split_last xs'
5f6fefdbf055 split the library into a basics file; merged Nominal_Eqvt into Nominal_Base
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   107
  in
5f6fefdbf055 split the library into a basics file; merged Nominal_Eqvt into Nominal_Base
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   108
    (xs'', y, x)
5f6fefdbf055 split the library into a basics file; merged Nominal_Eqvt into Nominal_Base
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   109
  end
5f6fefdbf055 split the library into a basics file; merged Nominal_Eqvt into Nominal_Base
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   110
5f6fefdbf055 split the library into a basics file; merged Nominal_Eqvt into Nominal_Base
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   111
fun map4 _ [] [] [] [] = []
5f6fefdbf055 split the library into a basics file; merged Nominal_Eqvt into Nominal_Base
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   112
  | map4 f (x :: xs) (y :: ys) (z :: zs) (u :: us) = f x y z u :: map4 f xs ys zs us
5f6fefdbf055 split the library into a basics file; merged Nominal_Eqvt into Nominal_Base
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   113
5f6fefdbf055 split the library into a basics file; merged Nominal_Eqvt into Nominal_Base
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   114
fun split_filter f [] = ([], [])
5f6fefdbf055 split the library into a basics file; merged Nominal_Eqvt into Nominal_Base
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   115
  | split_filter f (x :: xs) =
5f6fefdbf055 split the library into a basics file; merged Nominal_Eqvt into Nominal_Base
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   116
      let 
5f6fefdbf055 split the library into a basics file; merged Nominal_Eqvt into Nominal_Base
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   117
        val (r, l) = split_filter f xs 
5f6fefdbf055 split the library into a basics file; merged Nominal_Eqvt into Nominal_Base
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   118
      in 
5f6fefdbf055 split the library into a basics file; merged Nominal_Eqvt into Nominal_Base
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   119
        if f x 
5f6fefdbf055 split the library into a basics file; merged Nominal_Eqvt into Nominal_Base
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   120
        then (x :: r, l) 
5f6fefdbf055 split the library into a basics file; merged Nominal_Eqvt into Nominal_Base
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   121
        else (r, x :: l) 
5f6fefdbf055 split the library into a basics file; merged Nominal_Eqvt into Nominal_Base
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   122
      end
5f6fefdbf055 split the library into a basics file; merged Nominal_Eqvt into Nominal_Base
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   123
5f6fefdbf055 split the library into a basics file; merged Nominal_Eqvt into Nominal_Base
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   124
(* to be used with left-infix binop-operations *)
5f6fefdbf055 split the library into a basics file; merged Nominal_Eqvt into Nominal_Base
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   125
fun fold_left f [] z = z
5f6fefdbf055 split the library into a basics file; merged Nominal_Eqvt into Nominal_Base
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   126
  | fold_left f [x] z = x
5f6fefdbf055 split the library into a basics file; merged Nominal_Eqvt into Nominal_Base
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   127
  | fold_left f (x :: y :: xs) z = fold_left f (f (x, y) :: xs) z
5f6fefdbf055 split the library into a basics file; merged Nominal_Eqvt into Nominal_Base
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   128
5f6fefdbf055 split the library into a basics file; merged Nominal_Eqvt into Nominal_Base
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   129
5f6fefdbf055 split the library into a basics file; merged Nominal_Eqvt into Nominal_Base
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   130
5f6fefdbf055 split the library into a basics file; merged Nominal_Eqvt into Nominal_Base
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   131
fun is_true @{term "Trueprop True"} = true
5f6fefdbf055 split the library into a basics file; merged Nominal_Eqvt into Nominal_Base
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   132
  | is_true _ = false 
5f6fefdbf055 split the library into a basics file; merged Nominal_Eqvt into Nominal_Base
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   133
5f6fefdbf055 split the library into a basics file; merged Nominal_Eqvt into Nominal_Base
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   134
fun dest_listT (Type (@{type_name list}, [T])) = T
5f6fefdbf055 split the library into a basics file; merged Nominal_Eqvt into Nominal_Base
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   135
  | dest_listT T = raise TYPE ("dest_listT: list type expected", [T], [])
5f6fefdbf055 split the library into a basics file; merged Nominal_Eqvt into Nominal_Base
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   136
5f6fefdbf055 split the library into a basics file; merged Nominal_Eqvt into Nominal_Base
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   137
fun dest_fsetT (Type (@{type_name fset}, [T])) = T
5f6fefdbf055 split the library into a basics file; merged Nominal_Eqvt into Nominal_Base
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   138
  | dest_fsetT T = raise TYPE ("dest_fsetT: fset type expected", [T], []);
5f6fefdbf055 split the library into a basics file; merged Nominal_Eqvt into Nominal_Base
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   139
5f6fefdbf055 split the library into a basics file; merged Nominal_Eqvt into Nominal_Base
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   140
5f6fefdbf055 split the library into a basics file; merged Nominal_Eqvt into Nominal_Base
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   141
fun mk_id trm = HOLogic.id_const (fastype_of trm) $ trm
5f6fefdbf055 split the library into a basics file; merged Nominal_Eqvt into Nominal_Base
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   142
3108
61db5ad429bb updated to Isabelle 16 January
Christian Urban <urbanc@in.tum.de>
parents: 2962
diff changeset
   143
fun mk_all (a, T) t =  Logic.all_const T $ Abs (a, T, t)
2733
5f6fefdbf055 split the library into a basics file; merged Nominal_Eqvt into Nominal_Base
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   144
5f6fefdbf055 split the library into a basics file; merged Nominal_Eqvt into Nominal_Base
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   145
fun mk_All (a, T) t =  HOLogic.all_const T $ Abs (a, T, t)
5f6fefdbf055 split the library into a basics file; merged Nominal_Eqvt into Nominal_Base
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   146
5f6fefdbf055 split the library into a basics file; merged Nominal_Eqvt into Nominal_Base
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   147
fun mk_exists (a, T) t =  HOLogic.exists_const T $ Abs (a, T, t)
5f6fefdbf055 split the library into a basics file; merged Nominal_Eqvt into Nominal_Base
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   148
5f6fefdbf055 split the library into a basics file; merged Nominal_Eqvt into Nominal_Base
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   149
fun sum_case_const ty1 ty2 ty3 = 
5f6fefdbf055 split the library into a basics file; merged Nominal_Eqvt into Nominal_Base
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   150
  Const (@{const_name sum_case}, [ty1 --> ty3, ty2 --> ty3, Type (@{type_name sum}, [ty1, ty2])] ---> ty3)
5f6fefdbf055 split the library into a basics file; merged Nominal_Eqvt into Nominal_Base
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   151
5f6fefdbf055 split the library into a basics file; merged Nominal_Eqvt into Nominal_Base
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   152
fun mk_sum_case trm1 trm2 =
5f6fefdbf055 split the library into a basics file; merged Nominal_Eqvt into Nominal_Base
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   153
  let
5f6fefdbf055 split the library into a basics file; merged Nominal_Eqvt into Nominal_Base
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   154
    val ([ty1], ty3) = strip_type (fastype_of trm1)
5f6fefdbf055 split the library into a basics file; merged Nominal_Eqvt into Nominal_Base
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   155
    val ty2 = domain_type (fastype_of trm2)
5f6fefdbf055 split the library into a basics file; merged Nominal_Eqvt into Nominal_Base
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   156
  in
5f6fefdbf055 split the library into a basics file; merged Nominal_Eqvt into Nominal_Base
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   157
    sum_case_const ty1 ty2 ty3 $ trm1 $ trm2
5f6fefdbf055 split the library into a basics file; merged Nominal_Eqvt into Nominal_Base
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   158
  end 
5f6fefdbf055 split the library into a basics file; merged Nominal_Eqvt into Nominal_Base
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   159
5f6fefdbf055 split the library into a basics file; merged Nominal_Eqvt into Nominal_Base
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   160
5f6fefdbf055 split the library into a basics file; merged Nominal_Eqvt into Nominal_Base
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   161
fun mk_equiv r = r RS @{thm eq_reflection};
5f6fefdbf055 split the library into a basics file; merged Nominal_Eqvt into Nominal_Base
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   162
fun safe_mk_equiv r = mk_equiv r handle Thm.THM _ => r;
5f6fefdbf055 split the library into a basics file; merged Nominal_Eqvt into Nominal_Base
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   163
5f6fefdbf055 split the library into a basics file; merged Nominal_Eqvt into Nominal_Base
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   164
5f6fefdbf055 split the library into a basics file; merged Nominal_Eqvt into Nominal_Base
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   165
fun mk_minus p = @{term "uminus::perm => perm"} $ p
5f6fefdbf055 split the library into a basics file; merged Nominal_Eqvt into Nominal_Base
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   166
5f6fefdbf055 split the library into a basics file; merged Nominal_Eqvt into Nominal_Base
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   167
fun mk_plus p q = @{term "plus::perm => perm => perm"} $ p $ q
5f6fefdbf055 split the library into a basics file; merged Nominal_Eqvt into Nominal_Base
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   168
5f6fefdbf055 split the library into a basics file; merged Nominal_Eqvt into Nominal_Base
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   169
fun perm_ty ty = @{typ "perm"} --> ty --> ty
5f6fefdbf055 split the library into a basics file; merged Nominal_Eqvt into Nominal_Base
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   170
fun perm_const ty  = Const (@{const_name "permute"}, perm_ty ty)
5f6fefdbf055 split the library into a basics file; merged Nominal_Eqvt into Nominal_Base
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   171
fun mk_perm_ty ty p trm = perm_const ty $ p $ trm
5f6fefdbf055 split the library into a basics file; merged Nominal_Eqvt into Nominal_Base
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   172
fun mk_perm p trm = mk_perm_ty (fastype_of trm) p trm
5f6fefdbf055 split the library into a basics file; merged Nominal_Eqvt into Nominal_Base
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   173
5f6fefdbf055 split the library into a basics file; merged Nominal_Eqvt into Nominal_Base
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   174
fun dest_perm (Const (@{const_name "permute"}, _) $ p $ t) = (p, t)
5f6fefdbf055 split the library into a basics file; merged Nominal_Eqvt into Nominal_Base
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   175
  | dest_perm t = raise TERM ("dest_perm", [t]);
5f6fefdbf055 split the library into a basics file; merged Nominal_Eqvt into Nominal_Base
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   176
5f6fefdbf055 split the library into a basics file; merged Nominal_Eqvt into Nominal_Base
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   177
end (* structure *)
5f6fefdbf055 split the library into a basics file; merged Nominal_Eqvt into Nominal_Base
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   178
5f6fefdbf055 split the library into a basics file; merged Nominal_Eqvt into Nominal_Base
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   179
open Nominal_Basic;