src/HOL/Library/ExecutableSet.thy
author berghofe
Sun, 25 Sep 2005 20:12:26 +0200
changeset 17632 13d6a689efe9
child 18702 7dc7dcd63224
permissions -rw-r--r--
New theory for implementing finite sets by lists.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
17632
13d6a689efe9 New theory for implementing finite sets by lists.
berghofe
parents:
diff changeset
     1
(*  Title:      HOL/Library/ExecutableSet.thy
13d6a689efe9 New theory for implementing finite sets by lists.
berghofe
parents:
diff changeset
     2
    ID:         $Id$
13d6a689efe9 New theory for implementing finite sets by lists.
berghofe
parents:
diff changeset
     3
    Author:     Stefan Berghofer, TU Muenchen
13d6a689efe9 New theory for implementing finite sets by lists.
berghofe
parents:
diff changeset
     4
*)
13d6a689efe9 New theory for implementing finite sets by lists.
berghofe
parents:
diff changeset
     5
13d6a689efe9 New theory for implementing finite sets by lists.
berghofe
parents:
diff changeset
     6
header {* Implementation of finite sets by lists *}
13d6a689efe9 New theory for implementing finite sets by lists.
berghofe
parents:
diff changeset
     7
13d6a689efe9 New theory for implementing finite sets by lists.
berghofe
parents:
diff changeset
     8
theory ExecutableSet
13d6a689efe9 New theory for implementing finite sets by lists.
berghofe
parents:
diff changeset
     9
imports Main
13d6a689efe9 New theory for implementing finite sets by lists.
berghofe
parents:
diff changeset
    10
begin
13d6a689efe9 New theory for implementing finite sets by lists.
berghofe
parents:
diff changeset
    11
13d6a689efe9 New theory for implementing finite sets by lists.
berghofe
parents:
diff changeset
    12
lemma [code target: Set]: "(A = B) = (A \<subseteq> B \<and> B \<subseteq> A)"
13d6a689efe9 New theory for implementing finite sets by lists.
berghofe
parents:
diff changeset
    13
  by blast
13d6a689efe9 New theory for implementing finite sets by lists.
berghofe
parents:
diff changeset
    14
13d6a689efe9 New theory for implementing finite sets by lists.
berghofe
parents:
diff changeset
    15
declare bex_triv_one_point1 [symmetric, standard, code]
13d6a689efe9 New theory for implementing finite sets by lists.
berghofe
parents:
diff changeset
    16
13d6a689efe9 New theory for implementing finite sets by lists.
berghofe
parents:
diff changeset
    17
types_code
13d6a689efe9 New theory for implementing finite sets by lists.
berghofe
parents:
diff changeset
    18
  set ("_ list")
13d6a689efe9 New theory for implementing finite sets by lists.
berghofe
parents:
diff changeset
    19
attach (term_of) {*
13d6a689efe9 New theory for implementing finite sets by lists.
berghofe
parents:
diff changeset
    20
fun term_of_set f T [] = Const ("{}", Type ("set", [T]))
13d6a689efe9 New theory for implementing finite sets by lists.
berghofe
parents:
diff changeset
    21
  | term_of_set f T (x :: xs) = Const ("insert",
13d6a689efe9 New theory for implementing finite sets by lists.
berghofe
parents:
diff changeset
    22
      T --> Type ("set", [T]) --> Type ("set", [T])) $ f x $ term_of_set f T xs;
13d6a689efe9 New theory for implementing finite sets by lists.
berghofe
parents:
diff changeset
    23
*}
13d6a689efe9 New theory for implementing finite sets by lists.
berghofe
parents:
diff changeset
    24
attach (test) {*
13d6a689efe9 New theory for implementing finite sets by lists.
berghofe
parents:
diff changeset
    25
fun gen_set' aG i j = frequency
13d6a689efe9 New theory for implementing finite sets by lists.
berghofe
parents:
diff changeset
    26
  [(i, fn () => aG j :: gen_set' aG (i-1) j), (1, fn () => [])] ()
13d6a689efe9 New theory for implementing finite sets by lists.
berghofe
parents:
diff changeset
    27
and gen_set aG i = gen_set' aG i i;
13d6a689efe9 New theory for implementing finite sets by lists.
berghofe
parents:
diff changeset
    28
*}
13d6a689efe9 New theory for implementing finite sets by lists.
berghofe
parents:
diff changeset
    29
13d6a689efe9 New theory for implementing finite sets by lists.
berghofe
parents:
diff changeset
    30
consts_code
13d6a689efe9 New theory for implementing finite sets by lists.
berghofe
parents:
diff changeset
    31
  "{}"      ("[]")
13d6a689efe9 New theory for implementing finite sets by lists.
berghofe
parents:
diff changeset
    32
  "insert"  ("(_ ins _)")
13d6a689efe9 New theory for implementing finite sets by lists.
berghofe
parents:
diff changeset
    33
  "op Un"   ("(_ union _)")
13d6a689efe9 New theory for implementing finite sets by lists.
berghofe
parents:
diff changeset
    34
  "op Int"  ("(_ inter _)")
13d6a689efe9 New theory for implementing finite sets by lists.
berghofe
parents:
diff changeset
    35
  "op -" :: "'a set \<Rightarrow> 'a set \<Rightarrow> 'a set" ("(_ \\\\ _)")
13d6a689efe9 New theory for implementing finite sets by lists.
berghofe
parents:
diff changeset
    36
  "image"   ("\<module>image")
13d6a689efe9 New theory for implementing finite sets by lists.
berghofe
parents:
diff changeset
    37
attach {*
13d6a689efe9 New theory for implementing finite sets by lists.
berghofe
parents:
diff changeset
    38
fun image f S = distinct (map f S);
13d6a689efe9 New theory for implementing finite sets by lists.
berghofe
parents:
diff changeset
    39
*}
13d6a689efe9 New theory for implementing finite sets by lists.
berghofe
parents:
diff changeset
    40
  "UNION"   ("\<module>UNION")
13d6a689efe9 New theory for implementing finite sets by lists.
berghofe
parents:
diff changeset
    41
attach {*
13d6a689efe9 New theory for implementing finite sets by lists.
berghofe
parents:
diff changeset
    42
fun UNION S f = Library.foldr Library.union (map f S, []);
13d6a689efe9 New theory for implementing finite sets by lists.
berghofe
parents:
diff changeset
    43
*}
13d6a689efe9 New theory for implementing finite sets by lists.
berghofe
parents:
diff changeset
    44
  "INTER"   ("\<module>INTER")
13d6a689efe9 New theory for implementing finite sets by lists.
berghofe
parents:
diff changeset
    45
attach {*
13d6a689efe9 New theory for implementing finite sets by lists.
berghofe
parents:
diff changeset
    46
fun INTER S f = Library.foldr1 Library.inter (map f S);
13d6a689efe9 New theory for implementing finite sets by lists.
berghofe
parents:
diff changeset
    47
*}
13d6a689efe9 New theory for implementing finite sets by lists.
berghofe
parents:
diff changeset
    48
  "Bex"     ("\<module>Bex")
13d6a689efe9 New theory for implementing finite sets by lists.
berghofe
parents:
diff changeset
    49
attach {*
13d6a689efe9 New theory for implementing finite sets by lists.
berghofe
parents:
diff changeset
    50
fun Bex S P = Library.exists P S;
13d6a689efe9 New theory for implementing finite sets by lists.
berghofe
parents:
diff changeset
    51
*}
13d6a689efe9 New theory for implementing finite sets by lists.
berghofe
parents:
diff changeset
    52
  "Ball"     ("\<module>Ball")
13d6a689efe9 New theory for implementing finite sets by lists.
berghofe
parents:
diff changeset
    53
attach {*
13d6a689efe9 New theory for implementing finite sets by lists.
berghofe
parents:
diff changeset
    54
fun Ball S P = Library.forall P S;
13d6a689efe9 New theory for implementing finite sets by lists.
berghofe
parents:
diff changeset
    55
*}
13d6a689efe9 New theory for implementing finite sets by lists.
berghofe
parents:
diff changeset
    56
13d6a689efe9 New theory for implementing finite sets by lists.
berghofe
parents:
diff changeset
    57
end