Nominal/FSet.thy
author Christian Urban <urbanc@in.tum.de>
Sun, 25 Apr 2010 01:31:22 +0200
changeset 1943 48add8d4d7e5
parent 1938 3641d055b260
child 1952 27cdc0a3a763
permissions -rw-r--r--
slight tuning
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1823
91ba55dba5e0 added header and more tuning
Christian Urban <urbanc@in.tum.de>
parents: 1822
diff changeset
     1
(*  Title:      Quotient.thy
91ba55dba5e0 added header and more tuning
Christian Urban <urbanc@in.tum.de>
parents: 1822
diff changeset
     2
    Author:     Cezary Kaliszyk 
91ba55dba5e0 added header and more tuning
Christian Urban <urbanc@in.tum.de>
parents: 1822
diff changeset
     3
    Author:     Christian Urban
91ba55dba5e0 added header and more tuning
Christian Urban <urbanc@in.tum.de>
parents: 1822
diff changeset
     4
91ba55dba5e0 added header and more tuning
Christian Urban <urbanc@in.tum.de>
parents: 1822
diff changeset
     5
    provides a reasoning infrastructure for the type of finite sets
91ba55dba5e0 added header and more tuning
Christian Urban <urbanc@in.tum.de>
parents: 1822
diff changeset
     6
*)
1518
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
     7
theory FSet
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
     8
imports Quotient Quotient_List List
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
     9
begin
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    10
1909
9972dc5bd7ad Reorder FSet
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1907
diff changeset
    11
text {* Definiton of List relation and the quotient type *}
9972dc5bd7ad Reorder FSet
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1907
diff changeset
    12
1518
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    13
fun
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    14
  list_eq :: "'a list \<Rightarrow> 'a list \<Rightarrow> bool" (infix "\<approx>" 50)
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    15
where
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    16
  "list_eq xs ys = (\<forall>x. x \<in> set xs \<longleftrightarrow> x \<in> set ys)"
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    17
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    18
lemma list_eq_equivp:
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    19
  shows "equivp list_eq"
1909
9972dc5bd7ad Reorder FSet
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1907
diff changeset
    20
  unfolding equivp_reflp_symp_transp
1889
6c5b5ec53a0b sub_list definition and respects
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1888
diff changeset
    21
  unfolding reflp_def symp_def transp_def
6c5b5ec53a0b sub_list definition and respects
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1888
diff changeset
    22
  by auto
6c5b5ec53a0b sub_list definition and respects
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1888
diff changeset
    23
1909
9972dc5bd7ad Reorder FSet
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1907
diff changeset
    24
quotient_type
9972dc5bd7ad Reorder FSet
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1907
diff changeset
    25
  'a fset = "'a list" / "list_eq"
9972dc5bd7ad Reorder FSet
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1907
diff changeset
    26
  by (rule list_eq_equivp)
9972dc5bd7ad Reorder FSet
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1907
diff changeset
    27
9972dc5bd7ad Reorder FSet
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1907
diff changeset
    28
text {* Raw definitions *}
9972dc5bd7ad Reorder FSet
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1907
diff changeset
    29
1889
6c5b5ec53a0b sub_list definition and respects
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1888
diff changeset
    30
definition
6c5b5ec53a0b sub_list definition and respects
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1888
diff changeset
    31
  memb :: "'a \<Rightarrow> 'a list \<Rightarrow> bool"
6c5b5ec53a0b sub_list definition and respects
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1888
diff changeset
    32
where
6c5b5ec53a0b sub_list definition and respects
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1888
diff changeset
    33
  "memb x xs \<equiv> x \<in> set xs"
6c5b5ec53a0b sub_list definition and respects
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1888
diff changeset
    34
6c5b5ec53a0b sub_list definition and respects
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1888
diff changeset
    35
definition
6c5b5ec53a0b sub_list definition and respects
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1888
diff changeset
    36
  sub_list :: "'a list \<Rightarrow> 'a list \<Rightarrow> bool"
6c5b5ec53a0b sub_list definition and respects
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1888
diff changeset
    37
where
6c5b5ec53a0b sub_list definition and respects
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1888
diff changeset
    38
  "sub_list xs ys \<equiv> (\<forall>x. x \<in> set xs \<longrightarrow> x \<in> set ys)"
6c5b5ec53a0b sub_list definition and respects
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1888
diff changeset
    39
1909
9972dc5bd7ad Reorder FSet
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1907
diff changeset
    40
fun
9972dc5bd7ad Reorder FSet
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1907
diff changeset
    41
  fcard_raw :: "'a list \<Rightarrow> nat"
9972dc5bd7ad Reorder FSet
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1907
diff changeset
    42
where
9972dc5bd7ad Reorder FSet
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1907
diff changeset
    43
  fcard_raw_nil:  "fcard_raw [] = 0"
9972dc5bd7ad Reorder FSet
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1907
diff changeset
    44
| fcard_raw_cons: "fcard_raw (x # xs) = (if memb x xs then fcard_raw xs else Suc (fcard_raw xs))"
1518
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    45
1909
9972dc5bd7ad Reorder FSet
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1907
diff changeset
    46
primrec
9972dc5bd7ad Reorder FSet
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1907
diff changeset
    47
  finter_raw :: "'a list \<Rightarrow> 'a list \<Rightarrow> 'a list"
9972dc5bd7ad Reorder FSet
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1907
diff changeset
    48
where
9972dc5bd7ad Reorder FSet
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1907
diff changeset
    49
  "finter_raw [] l = []"
9972dc5bd7ad Reorder FSet
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1907
diff changeset
    50
| "finter_raw (h # t) l =
9972dc5bd7ad Reorder FSet
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1907
diff changeset
    51
     (if memb h l then h # (finter_raw t l) else finter_raw t l)"
1893
464dd13efff6 Putting FSet in bot typeclass.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1892
diff changeset
    52
1909
9972dc5bd7ad Reorder FSet
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1907
diff changeset
    53
fun
9972dc5bd7ad Reorder FSet
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1907
diff changeset
    54
  delete_raw :: "'a list \<Rightarrow> 'a \<Rightarrow> 'a list"
9972dc5bd7ad Reorder FSet
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1907
diff changeset
    55
where
9972dc5bd7ad Reorder FSet
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1907
diff changeset
    56
  "delete_raw [] x = []"
9972dc5bd7ad Reorder FSet
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1907
diff changeset
    57
| "delete_raw (a # A) x = (if (a = x) then delete_raw A x else a # (delete_raw A x))"
9972dc5bd7ad Reorder FSet
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1907
diff changeset
    58
9972dc5bd7ad Reorder FSet
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1907
diff changeset
    59
definition
9972dc5bd7ad Reorder FSet
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1907
diff changeset
    60
  rsp_fold
9972dc5bd7ad Reorder FSet
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1907
diff changeset
    61
where
9972dc5bd7ad Reorder FSet
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1907
diff changeset
    62
  "rsp_fold f = (\<forall>u v w. (f u (f v w) = f v (f u w)))"
1893
464dd13efff6 Putting FSet in bot typeclass.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1892
diff changeset
    63
1909
9972dc5bd7ad Reorder FSet
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1907
diff changeset
    64
primrec
9972dc5bd7ad Reorder FSet
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1907
diff changeset
    65
  ffold_raw :: "('a \<Rightarrow> 'b \<Rightarrow> 'b) \<Rightarrow> 'b \<Rightarrow> 'a list \<Rightarrow> 'b"
9972dc5bd7ad Reorder FSet
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1907
diff changeset
    66
where
9972dc5bd7ad Reorder FSet
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1907
diff changeset
    67
  "ffold_raw f z [] = z"
9972dc5bd7ad Reorder FSet
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1907
diff changeset
    68
| "ffold_raw f z (a # A) =
9972dc5bd7ad Reorder FSet
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1907
diff changeset
    69
     (if (rsp_fold f) then
9972dc5bd7ad Reorder FSet
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1907
diff changeset
    70
       if memb a A then ffold_raw f z A
9972dc5bd7ad Reorder FSet
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1907
diff changeset
    71
       else f a (ffold_raw f z A)
9972dc5bd7ad Reorder FSet
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1907
diff changeset
    72
     else z)"
9972dc5bd7ad Reorder FSet
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1907
diff changeset
    73
1935
266abc3ee228 Moved working Fset3 properties to FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1927
diff changeset
    74
text {* Composition Quotient *}
266abc3ee228 Moved working Fset3 properties to FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1927
diff changeset
    75
1938
3641d055b260 Further cleaning of proofs in FSet
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1936
diff changeset
    76
lemma list_rel_refl:
3641d055b260 Further cleaning of proofs in FSet
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1936
diff changeset
    77
  shows "(list_rel op \<approx>) r r"
3641d055b260 Further cleaning of proofs in FSet
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1936
diff changeset
    78
  by (rule list_rel_refl) (metis equivp_def fset_equivp)
3641d055b260 Further cleaning of proofs in FSet
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1936
diff changeset
    79
1935
266abc3ee228 Moved working Fset3 properties to FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1927
diff changeset
    80
lemma compose_list_refl:
266abc3ee228 Moved working Fset3 properties to FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1927
diff changeset
    81
  shows "(list_rel op \<approx> OOO op \<approx>) r r"
266abc3ee228 Moved working Fset3 properties to FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1927
diff changeset
    82
proof
1938
3641d055b260 Further cleaning of proofs in FSet
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1936
diff changeset
    83
  show c: "list_rel op \<approx> r r" by (rule list_rel_refl)
1935
266abc3ee228 Moved working Fset3 properties to FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1927
diff changeset
    84
  have d: "r \<approx> r" by (rule equivp_reflp[OF fset_equivp])
266abc3ee228 Moved working Fset3 properties to FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1927
diff changeset
    85
  show b: "(op \<approx> OO list_rel op \<approx>) r r" by (rule pred_compI) (rule d, rule c)
266abc3ee228 Moved working Fset3 properties to FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1927
diff changeset
    86
qed
266abc3ee228 Moved working Fset3 properties to FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1927
diff changeset
    87
266abc3ee228 Moved working Fset3 properties to FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1927
diff changeset
    88
lemma Quotient_fset_list:
266abc3ee228 Moved working Fset3 properties to FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1927
diff changeset
    89
  shows "Quotient (list_rel op \<approx>) (map abs_fset) (map rep_fset)"
266abc3ee228 Moved working Fset3 properties to FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1927
diff changeset
    90
  by (fact list_quotient[OF Quotient_fset])
266abc3ee228 Moved working Fset3 properties to FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1927
diff changeset
    91
266abc3ee228 Moved working Fset3 properties to FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1927
diff changeset
    92
lemma set_in_eq: "(\<forall>e. ((e \<in> A) \<longleftrightarrow> (e \<in> B))) \<equiv> A = B"
266abc3ee228 Moved working Fset3 properties to FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1927
diff changeset
    93
  by (rule eq_reflection) auto
266abc3ee228 Moved working Fset3 properties to FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1927
diff changeset
    94
266abc3ee228 Moved working Fset3 properties to FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1927
diff changeset
    95
lemma map_rel_cong: "b \<approx> ba \<Longrightarrow> map f b \<approx> map f ba"
266abc3ee228 Moved working Fset3 properties to FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1927
diff changeset
    96
  unfolding list_eq.simps
266abc3ee228 Moved working Fset3 properties to FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1927
diff changeset
    97
  by (simp only: set_map set_in_eq)
266abc3ee228 Moved working Fset3 properties to FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1927
diff changeset
    98
266abc3ee228 Moved working Fset3 properties to FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1927
diff changeset
    99
lemma quotient_compose_list[quot_thm]:
266abc3ee228 Moved working Fset3 properties to FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1927
diff changeset
   100
  shows  "Quotient ((list_rel op \<approx>) OOO (op \<approx>))
266abc3ee228 Moved working Fset3 properties to FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1927
diff changeset
   101
    (abs_fset \<circ> (map abs_fset)) ((map rep_fset) \<circ> rep_fset)"
266abc3ee228 Moved working Fset3 properties to FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1927
diff changeset
   102
  unfolding Quotient_def comp_def
266abc3ee228 Moved working Fset3 properties to FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1927
diff changeset
   103
proof (intro conjI allI)
266abc3ee228 Moved working Fset3 properties to FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1927
diff changeset
   104
  fix a r s
266abc3ee228 Moved working Fset3 properties to FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1927
diff changeset
   105
  show "abs_fset (map abs_fset (map rep_fset (rep_fset a))) = a"
266abc3ee228 Moved working Fset3 properties to FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1927
diff changeset
   106
    by (simp add: abs_o_rep[OF Quotient_fset] Quotient_abs_rep[OF Quotient_fset] map_id)
266abc3ee228 Moved working Fset3 properties to FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1927
diff changeset
   107
  have b: "list_rel op \<approx> (map rep_fset (rep_fset a)) (map rep_fset (rep_fset a))"
266abc3ee228 Moved working Fset3 properties to FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1927
diff changeset
   108
    by (rule list_rel_refl)
266abc3ee228 Moved working Fset3 properties to FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1927
diff changeset
   109
  have c: "(op \<approx> OO list_rel op \<approx>) (map rep_fset (rep_fset a)) (map rep_fset (rep_fset a))"
266abc3ee228 Moved working Fset3 properties to FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1927
diff changeset
   110
    by (rule, rule equivp_reflp[OF fset_equivp]) (rule b)
266abc3ee228 Moved working Fset3 properties to FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1927
diff changeset
   111
  show "(list_rel op \<approx> OOO op \<approx>) (map rep_fset (rep_fset a)) (map rep_fset (rep_fset a))"
266abc3ee228 Moved working Fset3 properties to FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1927
diff changeset
   112
    by (rule, rule list_rel_refl) (rule c)
266abc3ee228 Moved working Fset3 properties to FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1927
diff changeset
   113
  show "(list_rel op \<approx> OOO op \<approx>) r s = ((list_rel op \<approx> OOO op \<approx>) r r \<and>
266abc3ee228 Moved working Fset3 properties to FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1927
diff changeset
   114
        (list_rel op \<approx> OOO op \<approx>) s s \<and> abs_fset (map abs_fset r) = abs_fset (map abs_fset s))"
266abc3ee228 Moved working Fset3 properties to FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1927
diff changeset
   115
  proof (intro iffI conjI)
266abc3ee228 Moved working Fset3 properties to FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1927
diff changeset
   116
    show "(list_rel op \<approx> OOO op \<approx>) r r" by (rule compose_list_refl)
266abc3ee228 Moved working Fset3 properties to FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1927
diff changeset
   117
    show "(list_rel op \<approx> OOO op \<approx>) s s" by (rule compose_list_refl)
266abc3ee228 Moved working Fset3 properties to FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1927
diff changeset
   118
  next
266abc3ee228 Moved working Fset3 properties to FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1927
diff changeset
   119
    assume a: "(list_rel op \<approx> OOO op \<approx>) r s"
266abc3ee228 Moved working Fset3 properties to FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1927
diff changeset
   120
    then have b: "map abs_fset r \<approx> map abs_fset s" proof (elim pred_compE)
266abc3ee228 Moved working Fset3 properties to FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1927
diff changeset
   121
      fix b ba
266abc3ee228 Moved working Fset3 properties to FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1927
diff changeset
   122
      assume c: "list_rel op \<approx> r b"
266abc3ee228 Moved working Fset3 properties to FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1927
diff changeset
   123
      assume d: "b \<approx> ba"
266abc3ee228 Moved working Fset3 properties to FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1927
diff changeset
   124
      assume e: "list_rel op \<approx> ba s"
266abc3ee228 Moved working Fset3 properties to FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1927
diff changeset
   125
      have f: "map abs_fset r = map abs_fset b"
1938
3641d055b260 Further cleaning of proofs in FSet
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1936
diff changeset
   126
        using Quotient_rel[OF Quotient_fset_list] c by blast
3641d055b260 Further cleaning of proofs in FSet
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1936
diff changeset
   127
      have "map abs_fset ba = map abs_fset s"
3641d055b260 Further cleaning of proofs in FSet
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1936
diff changeset
   128
        using Quotient_rel[OF Quotient_fset_list] e by blast
3641d055b260 Further cleaning of proofs in FSet
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1936
diff changeset
   129
      then have g: "map abs_fset s = map abs_fset ba" by simp
3641d055b260 Further cleaning of proofs in FSet
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1936
diff changeset
   130
      then show "map abs_fset r \<approx> map abs_fset s" using d f map_rel_cong by simp
1935
266abc3ee228 Moved working Fset3 properties to FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1927
diff changeset
   131
    qed
266abc3ee228 Moved working Fset3 properties to FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1927
diff changeset
   132
    then show "abs_fset (map abs_fset r) = abs_fset (map abs_fset s)"
1938
3641d055b260 Further cleaning of proofs in FSet
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1936
diff changeset
   133
      using Quotient_rel[OF Quotient_fset] by blast
1935
266abc3ee228 Moved working Fset3 properties to FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1927
diff changeset
   134
  next
266abc3ee228 Moved working Fset3 properties to FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1927
diff changeset
   135
    assume a: "(list_rel op \<approx> OOO op \<approx>) r r \<and> (list_rel op \<approx> OOO op \<approx>) s s
266abc3ee228 Moved working Fset3 properties to FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1927
diff changeset
   136
      \<and> abs_fset (map abs_fset r) = abs_fset (map abs_fset s)"
266abc3ee228 Moved working Fset3 properties to FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1927
diff changeset
   137
    then have s: "(list_rel op \<approx> OOO op \<approx>) s s" by simp
266abc3ee228 Moved working Fset3 properties to FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1927
diff changeset
   138
    have d: "map abs_fset r \<approx> map abs_fset s"
266abc3ee228 Moved working Fset3 properties to FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1927
diff changeset
   139
      by (subst Quotient_rel[OF Quotient_fset]) (simp add: a)
266abc3ee228 Moved working Fset3 properties to FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1927
diff changeset
   140
    have b: "map rep_fset (map abs_fset r) \<approx> map rep_fset (map abs_fset s)"
266abc3ee228 Moved working Fset3 properties to FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1927
diff changeset
   141
      by (rule map_rel_cong[OF d])
266abc3ee228 Moved working Fset3 properties to FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1927
diff changeset
   142
    have y: "list_rel op \<approx> (map rep_fset (map abs_fset s)) s"
266abc3ee228 Moved working Fset3 properties to FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1927
diff changeset
   143
      by (fact rep_abs_rsp_left[OF Quotient_fset_list, OF list_rel_refl[of s]])
266abc3ee228 Moved working Fset3 properties to FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1927
diff changeset
   144
    have c: "(op \<approx> OO list_rel op \<approx>) (map rep_fset (map abs_fset r)) s"
266abc3ee228 Moved working Fset3 properties to FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1927
diff changeset
   145
      by (rule pred_compI) (rule b, rule y)
266abc3ee228 Moved working Fset3 properties to FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1927
diff changeset
   146
    have z: "list_rel op \<approx> r (map rep_fset (map abs_fset r))"
266abc3ee228 Moved working Fset3 properties to FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1927
diff changeset
   147
      by (fact rep_abs_rsp[OF Quotient_fset_list, OF list_rel_refl[of r]])
266abc3ee228 Moved working Fset3 properties to FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1927
diff changeset
   148
    then show "(list_rel op \<approx> OOO op \<approx>) r s"
266abc3ee228 Moved working Fset3 properties to FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1927
diff changeset
   149
      using a c pred_compI by simp
266abc3ee228 Moved working Fset3 properties to FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1927
diff changeset
   150
  qed
266abc3ee228 Moved working Fset3 properties to FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1927
diff changeset
   151
qed
266abc3ee228 Moved working Fset3 properties to FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1927
diff changeset
   152
1909
9972dc5bd7ad Reorder FSet
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1907
diff changeset
   153
text {* Respectfullness *}
1893
464dd13efff6 Putting FSet in bot typeclass.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1892
diff changeset
   154
1895
91d67240c9c1 FSet is a semi-lattice
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1893
diff changeset
   155
lemma [quot_respect]:
91d67240c9c1 FSet is a semi-lattice
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1893
diff changeset
   156
  shows "(op \<approx> ===> op \<approx> ===> op \<approx>) op @ op @"
91d67240c9c1 FSet is a semi-lattice
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1893
diff changeset
   157
  by auto
91d67240c9c1 FSet is a semi-lattice
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1893
diff changeset
   158
1909
9972dc5bd7ad Reorder FSet
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1907
diff changeset
   159
lemma [quot_respect]:
9972dc5bd7ad Reorder FSet
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1907
diff changeset
   160
  shows "(op \<approx> ===> op \<approx> ===> op =) sub_list sub_list"
9972dc5bd7ad Reorder FSet
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1907
diff changeset
   161
  by (auto simp add: sub_list_def)
9972dc5bd7ad Reorder FSet
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1907
diff changeset
   162
9972dc5bd7ad Reorder FSet
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1907
diff changeset
   163
lemma memb_rsp[quot_respect]:
9972dc5bd7ad Reorder FSet
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1907
diff changeset
   164
  shows "(op = ===> op \<approx> ===> op =) memb memb"
9972dc5bd7ad Reorder FSet
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1907
diff changeset
   165
  by (auto simp add: memb_def)
9972dc5bd7ad Reorder FSet
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1907
diff changeset
   166
9972dc5bd7ad Reorder FSet
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1907
diff changeset
   167
lemma nil_rsp[quot_respect]:
9972dc5bd7ad Reorder FSet
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1907
diff changeset
   168
  shows "[] \<approx> []"
9972dc5bd7ad Reorder FSet
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1907
diff changeset
   169
  by simp
9972dc5bd7ad Reorder FSet
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1907
diff changeset
   170
9972dc5bd7ad Reorder FSet
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1907
diff changeset
   171
lemma cons_rsp[quot_respect]:
9972dc5bd7ad Reorder FSet
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1907
diff changeset
   172
  shows "(op = ===> op \<approx> ===> op \<approx>) op # op #"
9972dc5bd7ad Reorder FSet
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1907
diff changeset
   173
  by simp
9972dc5bd7ad Reorder FSet
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1907
diff changeset
   174
9972dc5bd7ad Reorder FSet
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1907
diff changeset
   175
lemma map_rsp[quot_respect]:
9972dc5bd7ad Reorder FSet
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1907
diff changeset
   176
  shows "(op = ===> op \<approx> ===> op \<approx>) map map"
9972dc5bd7ad Reorder FSet
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1907
diff changeset
   177
  by auto
9972dc5bd7ad Reorder FSet
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1907
diff changeset
   178
9972dc5bd7ad Reorder FSet
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1907
diff changeset
   179
lemma set_rsp[quot_respect]:
9972dc5bd7ad Reorder FSet
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1907
diff changeset
   180
  "(op \<approx> ===> op =) set set"
9972dc5bd7ad Reorder FSet
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1907
diff changeset
   181
  by auto
9972dc5bd7ad Reorder FSet
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1907
diff changeset
   182
9972dc5bd7ad Reorder FSet
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1907
diff changeset
   183
lemma list_equiv_rsp[quot_respect]:
9972dc5bd7ad Reorder FSet
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1907
diff changeset
   184
  shows "(op \<approx> ===> op \<approx> ===> op =) op \<approx> op \<approx>"
9972dc5bd7ad Reorder FSet
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1907
diff changeset
   185
  by auto
9972dc5bd7ad Reorder FSet
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1907
diff changeset
   186
9972dc5bd7ad Reorder FSet
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1907
diff changeset
   187
lemma not_memb_nil:
9972dc5bd7ad Reorder FSet
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1907
diff changeset
   188
  shows "\<not> memb x []"
9972dc5bd7ad Reorder FSet
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1907
diff changeset
   189
  by (simp add: memb_def)
9972dc5bd7ad Reorder FSet
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1907
diff changeset
   190
9972dc5bd7ad Reorder FSet
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1907
diff changeset
   191
lemma memb_cons_iff:
9972dc5bd7ad Reorder FSet
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1907
diff changeset
   192
  shows "memb x (y # xs) = (x = y \<or> memb x xs)"
9972dc5bd7ad Reorder FSet
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1907
diff changeset
   193
  by (induct xs) (auto simp add: memb_def)
9972dc5bd7ad Reorder FSet
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1907
diff changeset
   194
9972dc5bd7ad Reorder FSet
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1907
diff changeset
   195
lemma memb_finter_raw:
9972dc5bd7ad Reorder FSet
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1907
diff changeset
   196
  "memb x (finter_raw xs ys) \<longleftrightarrow> memb x xs \<and> memb x ys"
9972dc5bd7ad Reorder FSet
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1907
diff changeset
   197
  by (induct xs) (auto simp add: not_memb_nil memb_cons_iff)
9972dc5bd7ad Reorder FSet
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1907
diff changeset
   198
9972dc5bd7ad Reorder FSet
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1907
diff changeset
   199
lemma [quot_respect]:
9972dc5bd7ad Reorder FSet
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1907
diff changeset
   200
  "(op \<approx> ===> op \<approx> ===> op \<approx>) finter_raw finter_raw"
9972dc5bd7ad Reorder FSet
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1907
diff changeset
   201
  by (simp add: memb_def[symmetric] memb_finter_raw)
9972dc5bd7ad Reorder FSet
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1907
diff changeset
   202
9972dc5bd7ad Reorder FSet
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1907
diff changeset
   203
lemma memb_delete_raw:
9972dc5bd7ad Reorder FSet
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1907
diff changeset
   204
  "memb x (delete_raw xs y) = (memb x xs \<and> x \<noteq> y)"
9972dc5bd7ad Reorder FSet
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1907
diff changeset
   205
  by (induct xs arbitrary: x y) (auto simp add: memb_def)
9972dc5bd7ad Reorder FSet
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1907
diff changeset
   206
9972dc5bd7ad Reorder FSet
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1907
diff changeset
   207
lemma [quot_respect]:
9972dc5bd7ad Reorder FSet
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1907
diff changeset
   208
  "(op \<approx> ===> op = ===> op \<approx>) delete_raw delete_raw"
9972dc5bd7ad Reorder FSet
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1907
diff changeset
   209
  by (simp add: memb_def[symmetric] memb_delete_raw)
9972dc5bd7ad Reorder FSet
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1907
diff changeset
   210
9972dc5bd7ad Reorder FSet
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1907
diff changeset
   211
lemma fcard_raw_gt_0:
9972dc5bd7ad Reorder FSet
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1907
diff changeset
   212
  assumes a: "x \<in> set xs"
9972dc5bd7ad Reorder FSet
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1907
diff changeset
   213
  shows "0 < fcard_raw xs"
9972dc5bd7ad Reorder FSet
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1907
diff changeset
   214
  using a by (induct xs) (auto simp add: memb_def)
9972dc5bd7ad Reorder FSet
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1907
diff changeset
   215
9972dc5bd7ad Reorder FSet
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1907
diff changeset
   216
lemma fcard_raw_delete_one:
9972dc5bd7ad Reorder FSet
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1907
diff changeset
   217
  shows "fcard_raw ([x \<leftarrow> xs. x \<noteq> y]) = (if memb y xs then fcard_raw xs - 1 else fcard_raw xs)"
9972dc5bd7ad Reorder FSet
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1907
diff changeset
   218
  by (induct xs) (auto dest: fcard_raw_gt_0 simp add: memb_def)
9972dc5bd7ad Reorder FSet
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1907
diff changeset
   219
9972dc5bd7ad Reorder FSet
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1907
diff changeset
   220
lemma fcard_raw_rsp_aux:
9972dc5bd7ad Reorder FSet
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1907
diff changeset
   221
  assumes a: "xs \<approx> ys"
9972dc5bd7ad Reorder FSet
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1907
diff changeset
   222
  shows "fcard_raw xs = fcard_raw ys"
9972dc5bd7ad Reorder FSet
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1907
diff changeset
   223
  using a
9972dc5bd7ad Reorder FSet
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1907
diff changeset
   224
  apply (induct xs arbitrary: ys)
9972dc5bd7ad Reorder FSet
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1907
diff changeset
   225
  apply (auto simp add: memb_def)
9972dc5bd7ad Reorder FSet
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1907
diff changeset
   226
  apply (subgoal_tac "\<forall>x. (x \<in> set xs) = (x \<in> set ys)")
9972dc5bd7ad Reorder FSet
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1907
diff changeset
   227
  apply (auto)
9972dc5bd7ad Reorder FSet
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1907
diff changeset
   228
  apply (drule_tac x="x" in spec)
9972dc5bd7ad Reorder FSet
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1907
diff changeset
   229
  apply (blast)
9972dc5bd7ad Reorder FSet
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1907
diff changeset
   230
  apply (drule_tac x="[x \<leftarrow> ys. x \<noteq> a]" in meta_spec)
9972dc5bd7ad Reorder FSet
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1907
diff changeset
   231
  apply (simp add: fcard_raw_delete_one memb_def)
9972dc5bd7ad Reorder FSet
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1907
diff changeset
   232
  apply (case_tac "a \<in> set ys")
9972dc5bd7ad Reorder FSet
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1907
diff changeset
   233
  apply (simp only: if_True)
9972dc5bd7ad Reorder FSet
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1907
diff changeset
   234
  apply (subgoal_tac "\<forall>x. (x \<in> set xs) = (x \<in> set ys \<and> x \<noteq> a)")
9972dc5bd7ad Reorder FSet
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1907
diff changeset
   235
  apply (drule Suc_pred'[OF fcard_raw_gt_0])
9972dc5bd7ad Reorder FSet
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1907
diff changeset
   236
  apply (auto)
9972dc5bd7ad Reorder FSet
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1907
diff changeset
   237
  done
9972dc5bd7ad Reorder FSet
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1907
diff changeset
   238
9972dc5bd7ad Reorder FSet
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1907
diff changeset
   239
lemma fcard_raw_rsp[quot_respect]:
9972dc5bd7ad Reorder FSet
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1907
diff changeset
   240
  shows "(op \<approx> ===> op =) fcard_raw fcard_raw"
9972dc5bd7ad Reorder FSet
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1907
diff changeset
   241
  by (simp add: fcard_raw_rsp_aux)
9972dc5bd7ad Reorder FSet
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1907
diff changeset
   242
9972dc5bd7ad Reorder FSet
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1907
diff changeset
   243
lemma memb_absorb:
9972dc5bd7ad Reorder FSet
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1907
diff changeset
   244
  shows "memb x xs \<Longrightarrow> x # xs \<approx> xs"
9972dc5bd7ad Reorder FSet
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1907
diff changeset
   245
  by (induct xs) (auto simp add: memb_def)
9972dc5bd7ad Reorder FSet
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1907
diff changeset
   246
9972dc5bd7ad Reorder FSet
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1907
diff changeset
   247
lemma none_memb_nil:
9972dc5bd7ad Reorder FSet
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1907
diff changeset
   248
  "(\<forall>x. \<not> memb x xs) = (xs \<approx> [])"
9972dc5bd7ad Reorder FSet
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1907
diff changeset
   249
  by (simp add: memb_def)
9972dc5bd7ad Reorder FSet
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1907
diff changeset
   250
9972dc5bd7ad Reorder FSet
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1907
diff changeset
   251
lemma not_memb_delete_raw_ident:
9972dc5bd7ad Reorder FSet
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1907
diff changeset
   252
  shows "\<not> memb x xs \<Longrightarrow> delete_raw xs x = xs"
9972dc5bd7ad Reorder FSet
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1907
diff changeset
   253
  by (induct xs) (auto simp add: memb_def)
9972dc5bd7ad Reorder FSet
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1907
diff changeset
   254
9972dc5bd7ad Reorder FSet
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1907
diff changeset
   255
lemma memb_commute_ffold_raw:
9972dc5bd7ad Reorder FSet
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1907
diff changeset
   256
  "rsp_fold f \<Longrightarrow> memb h b \<Longrightarrow> ffold_raw f z b = f h (ffold_raw f z (delete_raw b h))"
9972dc5bd7ad Reorder FSet
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1907
diff changeset
   257
  apply (induct b)
9972dc5bd7ad Reorder FSet
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1907
diff changeset
   258
  apply (simp_all add: not_memb_nil)
9972dc5bd7ad Reorder FSet
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1907
diff changeset
   259
  apply (auto)
1938
3641d055b260 Further cleaning of proofs in FSet
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1936
diff changeset
   260
  apply (simp_all add: memb_delete_raw not_memb_delete_raw_ident rsp_fold_def  memb_cons_iff)
1909
9972dc5bd7ad Reorder FSet
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1907
diff changeset
   261
  done
9972dc5bd7ad Reorder FSet
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1907
diff changeset
   262
9972dc5bd7ad Reorder FSet
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1907
diff changeset
   263
lemma ffold_raw_rsp_pre:
9972dc5bd7ad Reorder FSet
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1907
diff changeset
   264
  "\<forall>e. memb e a = memb e b \<Longrightarrow> ffold_raw f z a = ffold_raw f z b"
9972dc5bd7ad Reorder FSet
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1907
diff changeset
   265
  apply (induct a arbitrary: b)
9972dc5bd7ad Reorder FSet
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1907
diff changeset
   266
  apply (simp add: memb_absorb memb_def none_memb_nil)
9972dc5bd7ad Reorder FSet
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1907
diff changeset
   267
  apply (simp)
9972dc5bd7ad Reorder FSet
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1907
diff changeset
   268
  apply (rule conjI)
9972dc5bd7ad Reorder FSet
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1907
diff changeset
   269
  apply (rule_tac [!] impI)
9972dc5bd7ad Reorder FSet
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1907
diff changeset
   270
  apply (rule_tac [!] conjI)
9972dc5bd7ad Reorder FSet
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1907
diff changeset
   271
  apply (rule_tac [!] impI)
9972dc5bd7ad Reorder FSet
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1907
diff changeset
   272
  apply (subgoal_tac "\<forall>e. memb e a2 = memb e b")
9972dc5bd7ad Reorder FSet
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1907
diff changeset
   273
  apply (simp)
9972dc5bd7ad Reorder FSet
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1907
diff changeset
   274
  apply (simp add: memb_cons_iff memb_def)
9972dc5bd7ad Reorder FSet
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1907
diff changeset
   275
  apply (auto)[1]
9972dc5bd7ad Reorder FSet
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1907
diff changeset
   276
  apply (drule_tac x="e" in spec)
9972dc5bd7ad Reorder FSet
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1907
diff changeset
   277
  apply (blast)
9972dc5bd7ad Reorder FSet
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1907
diff changeset
   278
  apply (case_tac b)
9972dc5bd7ad Reorder FSet
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1907
diff changeset
   279
  apply (simp_all)
9972dc5bd7ad Reorder FSet
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1907
diff changeset
   280
  apply (subgoal_tac "ffold_raw f z b = f a1 (ffold_raw f z (delete_raw b a1))")
9972dc5bd7ad Reorder FSet
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1907
diff changeset
   281
  apply (simp only:)
9972dc5bd7ad Reorder FSet
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1907
diff changeset
   282
  apply (rule_tac f="f a1" in arg_cong)
9972dc5bd7ad Reorder FSet
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1907
diff changeset
   283
  apply (subgoal_tac "\<forall>e. memb e a2 = memb e (delete_raw b a1)")
9972dc5bd7ad Reorder FSet
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1907
diff changeset
   284
  apply (simp)
9972dc5bd7ad Reorder FSet
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1907
diff changeset
   285
  apply (simp add: memb_delete_raw)
9972dc5bd7ad Reorder FSet
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1907
diff changeset
   286
  apply (auto simp add: memb_cons_iff)[1]
9972dc5bd7ad Reorder FSet
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1907
diff changeset
   287
  apply (erule memb_commute_ffold_raw)
9972dc5bd7ad Reorder FSet
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1907
diff changeset
   288
  apply (drule_tac x="a1" in spec)
9972dc5bd7ad Reorder FSet
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1907
diff changeset
   289
  apply (simp add: memb_cons_iff)
9972dc5bd7ad Reorder FSet
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1907
diff changeset
   290
  apply (simp add: memb_cons_iff)
9972dc5bd7ad Reorder FSet
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1907
diff changeset
   291
  apply (case_tac b)
9972dc5bd7ad Reorder FSet
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1907
diff changeset
   292
  apply (simp_all)
9972dc5bd7ad Reorder FSet
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1907
diff changeset
   293
  done
9972dc5bd7ad Reorder FSet
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1907
diff changeset
   294
9972dc5bd7ad Reorder FSet
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1907
diff changeset
   295
lemma [quot_respect]:
9972dc5bd7ad Reorder FSet
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1907
diff changeset
   296
  "(op = ===> op = ===> op \<approx> ===> op =) ffold_raw ffold_raw"
9972dc5bd7ad Reorder FSet
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1907
diff changeset
   297
  by (simp add: memb_def[symmetric] ffold_raw_rsp_pre)
9972dc5bd7ad Reorder FSet
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1907
diff changeset
   298
1935
266abc3ee228 Moved working Fset3 properties to FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1927
diff changeset
   299
lemma concat_rsp_pre:
266abc3ee228 Moved working Fset3 properties to FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1927
diff changeset
   300
  assumes a: "list_rel op \<approx> x x'"
266abc3ee228 Moved working Fset3 properties to FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1927
diff changeset
   301
  and     b: "x' \<approx> y'"
266abc3ee228 Moved working Fset3 properties to FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1927
diff changeset
   302
  and     c: "list_rel op \<approx> y' y"
266abc3ee228 Moved working Fset3 properties to FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1927
diff changeset
   303
  and     d: "\<exists>x\<in>set x. xa \<in> set x"
266abc3ee228 Moved working Fset3 properties to FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1927
diff changeset
   304
  shows "\<exists>x\<in>set y. xa \<in> set x"
266abc3ee228 Moved working Fset3 properties to FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1927
diff changeset
   305
proof -
266abc3ee228 Moved working Fset3 properties to FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1927
diff changeset
   306
  obtain xb where e: "xb \<in> set x" and f: "xa \<in> set xb" using d by auto
266abc3ee228 Moved working Fset3 properties to FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1927
diff changeset
   307
  have "\<exists>y. y \<in> set x' \<and> xb \<approx> y" by (rule list_rel_find_element[OF e a])
266abc3ee228 Moved working Fset3 properties to FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1927
diff changeset
   308
  then obtain ya where h: "ya \<in> set x'" and i: "xb \<approx> ya" by auto
266abc3ee228 Moved working Fset3 properties to FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1927
diff changeset
   309
  have j: "ya \<in> set y'" using b h by simp
266abc3ee228 Moved working Fset3 properties to FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1927
diff changeset
   310
  have "\<exists>yb. yb \<in> set y \<and> ya \<approx> yb" by (rule list_rel_find_element[OF j c])
266abc3ee228 Moved working Fset3 properties to FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1927
diff changeset
   311
  then show ?thesis using f i by auto
266abc3ee228 Moved working Fset3 properties to FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1927
diff changeset
   312
qed
266abc3ee228 Moved working Fset3 properties to FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1927
diff changeset
   313
266abc3ee228 Moved working Fset3 properties to FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1927
diff changeset
   314
lemma [quot_respect]:
266abc3ee228 Moved working Fset3 properties to FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1927
diff changeset
   315
  shows "(list_rel op \<approx> OOO op \<approx> ===> op \<approx>) concat concat"
266abc3ee228 Moved working Fset3 properties to FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1927
diff changeset
   316
proof (rule fun_relI, elim pred_compE)
266abc3ee228 Moved working Fset3 properties to FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1927
diff changeset
   317
  fix a b ba bb
266abc3ee228 Moved working Fset3 properties to FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1927
diff changeset
   318
  assume a: "list_rel op \<approx> a ba"
266abc3ee228 Moved working Fset3 properties to FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1927
diff changeset
   319
  assume b: "ba \<approx> bb"
266abc3ee228 Moved working Fset3 properties to FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1927
diff changeset
   320
  assume c: "list_rel op \<approx> bb b"
266abc3ee228 Moved working Fset3 properties to FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1927
diff changeset
   321
  have "\<forall>x. (\<exists>xa\<in>set a. x \<in> set xa) = (\<exists>xa\<in>set b. x \<in> set xa)" proof
266abc3ee228 Moved working Fset3 properties to FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1927
diff changeset
   322
    fix x
266abc3ee228 Moved working Fset3 properties to FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1927
diff changeset
   323
    show "(\<exists>xa\<in>set a. x \<in> set xa) = (\<exists>xa\<in>set b. x \<in> set xa)" proof
266abc3ee228 Moved working Fset3 properties to FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1927
diff changeset
   324
      assume d: "\<exists>xa\<in>set a. x \<in> set xa"
266abc3ee228 Moved working Fset3 properties to FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1927
diff changeset
   325
      show "\<exists>xa\<in>set b. x \<in> set xa" by (rule concat_rsp_pre[OF a b c d])
266abc3ee228 Moved working Fset3 properties to FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1927
diff changeset
   326
    next
266abc3ee228 Moved working Fset3 properties to FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1927
diff changeset
   327
      assume e: "\<exists>xa\<in>set b. x \<in> set xa"
266abc3ee228 Moved working Fset3 properties to FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1927
diff changeset
   328
      have a': "list_rel op \<approx> ba a" by (rule list_rel_symp[OF list_eq_equivp, OF a])
266abc3ee228 Moved working Fset3 properties to FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1927
diff changeset
   329
      have b': "bb \<approx> ba" by (rule equivp_symp[OF list_eq_equivp, OF b])
266abc3ee228 Moved working Fset3 properties to FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1927
diff changeset
   330
      have c': "list_rel op \<approx> b bb" by (rule list_rel_symp[OF list_eq_equivp, OF c])
266abc3ee228 Moved working Fset3 properties to FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1927
diff changeset
   331
      show "\<exists>xa\<in>set a. x \<in> set xa" by (rule concat_rsp_pre[OF c' b' a' e])
266abc3ee228 Moved working Fset3 properties to FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1927
diff changeset
   332
    qed
266abc3ee228 Moved working Fset3 properties to FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1927
diff changeset
   333
  qed
266abc3ee228 Moved working Fset3 properties to FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1927
diff changeset
   334
  then show "concat a \<approx> concat b" by simp
266abc3ee228 Moved working Fset3 properties to FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1927
diff changeset
   335
qed
266abc3ee228 Moved working Fset3 properties to FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1927
diff changeset
   336
1909
9972dc5bd7ad Reorder FSet
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1907
diff changeset
   337
text {* Distributive lattice with bot *}
9972dc5bd7ad Reorder FSet
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1907
diff changeset
   338
1893
464dd13efff6 Putting FSet in bot typeclass.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1892
diff changeset
   339
lemma sub_list_not_eq:
464dd13efff6 Putting FSet in bot typeclass.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1892
diff changeset
   340
  "(sub_list x y \<and> \<not> list_eq x y) = (sub_list x y \<and> \<not> sub_list y x)"
464dd13efff6 Putting FSet in bot typeclass.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1892
diff changeset
   341
  by (auto simp add: sub_list_def)
464dd13efff6 Putting FSet in bot typeclass.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1892
diff changeset
   342
464dd13efff6 Putting FSet in bot typeclass.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1892
diff changeset
   343
lemma sub_list_refl:
464dd13efff6 Putting FSet in bot typeclass.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1892
diff changeset
   344
  "sub_list x x"
464dd13efff6 Putting FSet in bot typeclass.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1892
diff changeset
   345
  by (simp add: sub_list_def)
464dd13efff6 Putting FSet in bot typeclass.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1892
diff changeset
   346
464dd13efff6 Putting FSet in bot typeclass.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1892
diff changeset
   347
lemma sub_list_trans:
464dd13efff6 Putting FSet in bot typeclass.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1892
diff changeset
   348
  "sub_list x y \<Longrightarrow> sub_list y z \<Longrightarrow> sub_list x z"
464dd13efff6 Putting FSet in bot typeclass.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1892
diff changeset
   349
  by (simp add: sub_list_def)
464dd13efff6 Putting FSet in bot typeclass.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1892
diff changeset
   350
464dd13efff6 Putting FSet in bot typeclass.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1892
diff changeset
   351
lemma sub_list_empty:
464dd13efff6 Putting FSet in bot typeclass.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1892
diff changeset
   352
  "sub_list [] x"
464dd13efff6 Putting FSet in bot typeclass.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1892
diff changeset
   353
  by (simp add: sub_list_def)
464dd13efff6 Putting FSet in bot typeclass.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1892
diff changeset
   354
1905
dbc9e88c44da fsets are distributive lattices.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1895
diff changeset
   355
lemma sub_list_append_left:
dbc9e88c44da fsets are distributive lattices.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1895
diff changeset
   356
  "sub_list x (x @ y)"
dbc9e88c44da fsets are distributive lattices.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1895
diff changeset
   357
  by (simp add: sub_list_def)
dbc9e88c44da fsets are distributive lattices.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1895
diff changeset
   358
dbc9e88c44da fsets are distributive lattices.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1895
diff changeset
   359
lemma sub_list_append_right:
dbc9e88c44da fsets are distributive lattices.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1895
diff changeset
   360
  "sub_list y (x @ y)"
dbc9e88c44da fsets are distributive lattices.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1895
diff changeset
   361
  by (simp add: sub_list_def)
dbc9e88c44da fsets are distributive lattices.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1895
diff changeset
   362
dbc9e88c44da fsets are distributive lattices.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1895
diff changeset
   363
lemma sub_list_inter_left:
dbc9e88c44da fsets are distributive lattices.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1895
diff changeset
   364
  shows "sub_list (finter_raw x y) x"
dbc9e88c44da fsets are distributive lattices.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1895
diff changeset
   365
  by (simp add: sub_list_def memb_def[symmetric] memb_finter_raw)
dbc9e88c44da fsets are distributive lattices.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1895
diff changeset
   366
dbc9e88c44da fsets are distributive lattices.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1895
diff changeset
   367
lemma sub_list_inter_right:
dbc9e88c44da fsets are distributive lattices.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1895
diff changeset
   368
  shows "sub_list (finter_raw x y) y"
dbc9e88c44da fsets are distributive lattices.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1895
diff changeset
   369
  by (simp add: sub_list_def memb_def[symmetric] memb_finter_raw)
dbc9e88c44da fsets are distributive lattices.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1895
diff changeset
   370
dbc9e88c44da fsets are distributive lattices.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1895
diff changeset
   371
lemma sub_list_list_eq:
dbc9e88c44da fsets are distributive lattices.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1895
diff changeset
   372
  "sub_list x y \<Longrightarrow> sub_list y x \<Longrightarrow> list_eq x y"
dbc9e88c44da fsets are distributive lattices.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1895
diff changeset
   373
  unfolding sub_list_def list_eq.simps by blast
dbc9e88c44da fsets are distributive lattices.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1895
diff changeset
   374
dbc9e88c44da fsets are distributive lattices.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1895
diff changeset
   375
lemma sub_list_append:
dbc9e88c44da fsets are distributive lattices.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1895
diff changeset
   376
  "sub_list y x \<Longrightarrow> sub_list z x \<Longrightarrow> sub_list (y @ z) x"
dbc9e88c44da fsets are distributive lattices.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1895
diff changeset
   377
  unfolding sub_list_def by auto
dbc9e88c44da fsets are distributive lattices.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1895
diff changeset
   378
dbc9e88c44da fsets are distributive lattices.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1895
diff changeset
   379
lemma sub_list_inter:
dbc9e88c44da fsets are distributive lattices.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1895
diff changeset
   380
  "sub_list x y \<Longrightarrow> sub_list x z \<Longrightarrow> sub_list x (finter_raw y z)"
dbc9e88c44da fsets are distributive lattices.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1895
diff changeset
   381
  by (simp add: sub_list_def memb_def[symmetric] memb_finter_raw)
dbc9e88c44da fsets are distributive lattices.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1895
diff changeset
   382
dbc9e88c44da fsets are distributive lattices.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1895
diff changeset
   383
lemma append_inter_distrib:
dbc9e88c44da fsets are distributive lattices.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1895
diff changeset
   384
  "x @ (finter_raw y z) \<approx> finter_raw (x @ y) (x @ z)"
dbc9e88c44da fsets are distributive lattices.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1895
diff changeset
   385
  apply (induct x)
dbc9e88c44da fsets are distributive lattices.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1895
diff changeset
   386
  apply (simp_all add: memb_def)
dbc9e88c44da fsets are distributive lattices.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1895
diff changeset
   387
  apply (simp add: memb_def[symmetric] memb_finter_raw)
1909
9972dc5bd7ad Reorder FSet
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1907
diff changeset
   388
  by (auto simp add: memb_def)
1905
dbc9e88c44da fsets are distributive lattices.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1895
diff changeset
   389
dbc9e88c44da fsets are distributive lattices.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1895
diff changeset
   390
instantiation fset :: (type) "{bot,distrib_lattice}"
1893
464dd13efff6 Putting FSet in bot typeclass.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1892
diff changeset
   391
begin
464dd13efff6 Putting FSet in bot typeclass.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1892
diff changeset
   392
464dd13efff6 Putting FSet in bot typeclass.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1892
diff changeset
   393
quotient_definition
464dd13efff6 Putting FSet in bot typeclass.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1892
diff changeset
   394
  "bot :: 'a fset" is "[] :: 'a list"
464dd13efff6 Putting FSet in bot typeclass.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1892
diff changeset
   395
464dd13efff6 Putting FSet in bot typeclass.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1892
diff changeset
   396
abbreviation
464dd13efff6 Putting FSet in bot typeclass.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1892
diff changeset
   397
  fempty  ("{||}")
464dd13efff6 Putting FSet in bot typeclass.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1892
diff changeset
   398
where
464dd13efff6 Putting FSet in bot typeclass.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1892
diff changeset
   399
  "{||} \<equiv> bot :: 'a fset"
464dd13efff6 Putting FSet in bot typeclass.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1892
diff changeset
   400
464dd13efff6 Putting FSet in bot typeclass.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1892
diff changeset
   401
quotient_definition
464dd13efff6 Putting FSet in bot typeclass.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1892
diff changeset
   402
  "less_eq_fset \<Colon> ('a fset \<Rightarrow> 'a fset \<Rightarrow> bool)"
464dd13efff6 Putting FSet in bot typeclass.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1892
diff changeset
   403
is
464dd13efff6 Putting FSet in bot typeclass.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1892
diff changeset
   404
  "sub_list \<Colon> ('a list \<Rightarrow> 'a list \<Rightarrow> bool)"
464dd13efff6 Putting FSet in bot typeclass.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1892
diff changeset
   405
464dd13efff6 Putting FSet in bot typeclass.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1892
diff changeset
   406
abbreviation
464dd13efff6 Putting FSet in bot typeclass.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1892
diff changeset
   407
  f_subset_eq :: "'a fset \<Rightarrow> 'a fset \<Rightarrow> bool" (infix "|\<subseteq>|" 50)
464dd13efff6 Putting FSet in bot typeclass.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1892
diff changeset
   408
where
464dd13efff6 Putting FSet in bot typeclass.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1892
diff changeset
   409
  "xs |\<subseteq>| ys \<equiv> xs \<le> ys"
464dd13efff6 Putting FSet in bot typeclass.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1892
diff changeset
   410
464dd13efff6 Putting FSet in bot typeclass.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1892
diff changeset
   411
definition
464dd13efff6 Putting FSet in bot typeclass.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1892
diff changeset
   412
  less_fset:
464dd13efff6 Putting FSet in bot typeclass.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1892
diff changeset
   413
  "(xs :: 'a fset) < ys \<equiv> xs \<le> ys \<and> xs \<noteq> ys"
464dd13efff6 Putting FSet in bot typeclass.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1892
diff changeset
   414
464dd13efff6 Putting FSet in bot typeclass.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1892
diff changeset
   415
abbreviation
464dd13efff6 Putting FSet in bot typeclass.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1892
diff changeset
   416
  f_subset :: "'a fset \<Rightarrow> 'a fset \<Rightarrow> bool" (infix "|\<subset>|" 50)
464dd13efff6 Putting FSet in bot typeclass.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1892
diff changeset
   417
where
464dd13efff6 Putting FSet in bot typeclass.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1892
diff changeset
   418
  "xs |\<subset>| ys \<equiv> xs < ys"
464dd13efff6 Putting FSet in bot typeclass.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1892
diff changeset
   419
1895
91d67240c9c1 FSet is a semi-lattice
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1893
diff changeset
   420
quotient_definition
91d67240c9c1 FSet is a semi-lattice
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1893
diff changeset
   421
  "sup  \<Colon> ('a fset \<Rightarrow> 'a fset \<Rightarrow> 'a fset)"
91d67240c9c1 FSet is a semi-lattice
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1893
diff changeset
   422
is
91d67240c9c1 FSet is a semi-lattice
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1893
diff changeset
   423
  "(op @) \<Colon> ('a list \<Rightarrow> 'a list \<Rightarrow> 'a list)"
91d67240c9c1 FSet is a semi-lattice
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1893
diff changeset
   424
91d67240c9c1 FSet is a semi-lattice
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1893
diff changeset
   425
abbreviation
91d67240c9c1 FSet is a semi-lattice
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1893
diff changeset
   426
  funion  (infixl "|\<union>|" 65)
91d67240c9c1 FSet is a semi-lattice
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1893
diff changeset
   427
where
91d67240c9c1 FSet is a semi-lattice
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1893
diff changeset
   428
  "xs |\<union>| ys \<equiv> sup (xs :: 'a fset) ys"
91d67240c9c1 FSet is a semi-lattice
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1893
diff changeset
   429
1905
dbc9e88c44da fsets are distributive lattices.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1895
diff changeset
   430
quotient_definition
dbc9e88c44da fsets are distributive lattices.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1895
diff changeset
   431
  "inf  \<Colon> ('a fset \<Rightarrow> 'a fset \<Rightarrow> 'a fset)"
dbc9e88c44da fsets are distributive lattices.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1895
diff changeset
   432
is
dbc9e88c44da fsets are distributive lattices.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1895
diff changeset
   433
  "finter_raw \<Colon> ('a list \<Rightarrow> 'a list \<Rightarrow> 'a list)"
dbc9e88c44da fsets are distributive lattices.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1895
diff changeset
   434
dbc9e88c44da fsets are distributive lattices.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1895
diff changeset
   435
abbreviation
dbc9e88c44da fsets are distributive lattices.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1895
diff changeset
   436
  finter (infixl "|\<inter>|" 65)
dbc9e88c44da fsets are distributive lattices.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1895
diff changeset
   437
where
dbc9e88c44da fsets are distributive lattices.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1895
diff changeset
   438
  "xs |\<inter>| ys \<equiv> inf (xs :: 'a fset) ys"
dbc9e88c44da fsets are distributive lattices.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1895
diff changeset
   439
1895
91d67240c9c1 FSet is a semi-lattice
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1893
diff changeset
   440
instance
91d67240c9c1 FSet is a semi-lattice
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1893
diff changeset
   441
proof
1905
dbc9e88c44da fsets are distributive lattices.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1895
diff changeset
   442
  fix x y z :: "'a fset"
dbc9e88c44da fsets are distributive lattices.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1895
diff changeset
   443
  show "(x |\<subset>| y) = (x |\<subseteq>| y \<and> \<not> y |\<subseteq>| x)"
dbc9e88c44da fsets are distributive lattices.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1895
diff changeset
   444
    unfolding less_fset by (lifting sub_list_not_eq)
dbc9e88c44da fsets are distributive lattices.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1895
diff changeset
   445
  show "x |\<subseteq>| x" by (lifting sub_list_refl)
dbc9e88c44da fsets are distributive lattices.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1895
diff changeset
   446
  show "{||} |\<subseteq>| x" by (lifting sub_list_empty)
1895
91d67240c9c1 FSet is a semi-lattice
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1893
diff changeset
   447
  show "x |\<subseteq>| x |\<union>| y" by (lifting sub_list_append_left)
91d67240c9c1 FSet is a semi-lattice
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1893
diff changeset
   448
  show "y |\<subseteq>| x |\<union>| y" by (lifting sub_list_append_right)
1905
dbc9e88c44da fsets are distributive lattices.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1895
diff changeset
   449
  show "x |\<inter>| y |\<subseteq>| x" by (lifting sub_list_inter_left)
dbc9e88c44da fsets are distributive lattices.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1895
diff changeset
   450
  show "x |\<inter>| y |\<subseteq>| y" by (lifting sub_list_inter_right)
dbc9e88c44da fsets are distributive lattices.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1895
diff changeset
   451
  show "x |\<union>| (y |\<inter>| z) = x |\<union>| y |\<inter>| (x |\<union>| z)" by (lifting append_inter_distrib)
dbc9e88c44da fsets are distributive lattices.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1895
diff changeset
   452
next
dbc9e88c44da fsets are distributive lattices.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1895
diff changeset
   453
  fix x y z :: "'a fset"
dbc9e88c44da fsets are distributive lattices.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1895
diff changeset
   454
  assume a: "x |\<subseteq>| y"
dbc9e88c44da fsets are distributive lattices.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1895
diff changeset
   455
  assume b: "y |\<subseteq>| z"
dbc9e88c44da fsets are distributive lattices.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1895
diff changeset
   456
  show "x |\<subseteq>| z" using a b by (lifting sub_list_trans)
1895
91d67240c9c1 FSet is a semi-lattice
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1893
diff changeset
   457
next
91d67240c9c1 FSet is a semi-lattice
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1893
diff changeset
   458
  fix x y :: "'a fset"
91d67240c9c1 FSet is a semi-lattice
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1893
diff changeset
   459
  assume a: "x |\<subseteq>| y"
91d67240c9c1 FSet is a semi-lattice
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1893
diff changeset
   460
  assume b: "y |\<subseteq>| x"
91d67240c9c1 FSet is a semi-lattice
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1893
diff changeset
   461
  show "x = y" using a b by (lifting sub_list_list_eq)
91d67240c9c1 FSet is a semi-lattice
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1893
diff changeset
   462
next
91d67240c9c1 FSet is a semi-lattice
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1893
diff changeset
   463
  fix x y z :: "'a fset"
91d67240c9c1 FSet is a semi-lattice
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1893
diff changeset
   464
  assume a: "y |\<subseteq>| x"
91d67240c9c1 FSet is a semi-lattice
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1893
diff changeset
   465
  assume b: "z |\<subseteq>| x"
91d67240c9c1 FSet is a semi-lattice
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1893
diff changeset
   466
  show "y |\<union>| z |\<subseteq>| x" using a b by (lifting sub_list_append)
1905
dbc9e88c44da fsets are distributive lattices.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1895
diff changeset
   467
next
dbc9e88c44da fsets are distributive lattices.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1895
diff changeset
   468
  fix x y z :: "'a fset"
dbc9e88c44da fsets are distributive lattices.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1895
diff changeset
   469
  assume a: "x |\<subseteq>| y"
dbc9e88c44da fsets are distributive lattices.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1895
diff changeset
   470
  assume b: "x |\<subseteq>| z"
dbc9e88c44da fsets are distributive lattices.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1895
diff changeset
   471
  show "x |\<subseteq>| y |\<inter>| z" using a b by (lifting sub_list_inter)
1895
91d67240c9c1 FSet is a semi-lattice
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1893
diff changeset
   472
qed
1905
dbc9e88c44da fsets are distributive lattices.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1895
diff changeset
   473
1893
464dd13efff6 Putting FSet in bot typeclass.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1892
diff changeset
   474
end
464dd13efff6 Putting FSet in bot typeclass.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1892
diff changeset
   475
1909
9972dc5bd7ad Reorder FSet
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1907
diff changeset
   476
section {* Finsert and Membership *}
1518
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   477
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   478
quotient_definition
1893
464dd13efff6 Putting FSet in bot typeclass.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1892
diff changeset
   479
  "finsert :: 'a \<Rightarrow> 'a fset \<Rightarrow> 'a fset"
1518
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   480
is "op #"
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   481
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   482
syntax
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   483
  "@Finset"     :: "args => 'a fset"  ("{|(_)|}")
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   484
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   485
translations
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   486
  "{|x, xs|}" == "CONST finsert x {|xs|}"
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   487
  "{|x|}"     == "CONST finsert x {||}"
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   488
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   489
quotient_definition
1938
3641d055b260 Further cleaning of proofs in FSet
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1936
diff changeset
   490
  fin (infix "|\<in>|" 50)
1518
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   491
where
1816
56cebe7f8e24 some small tunings (incompleted work in Lambda.thy)
Christian Urban <urbanc@in.tum.de>
parents: 1682
diff changeset
   492
  "fin :: 'a \<Rightarrow> 'a fset \<Rightarrow> bool" is "memb"
1518
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   493
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   494
abbreviation
1938
3641d055b260 Further cleaning of proofs in FSet
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1936
diff changeset
   495
  fnotin :: "'a \<Rightarrow> 'a fset \<Rightarrow> bool" (infix "|\<notin>|" 50)
1518
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   496
where
1860
d3fe17786640 some tuning of proofs
Christian Urban <urbanc@in.tum.de>
parents: 1826
diff changeset
   497
  "x |\<notin>| S \<equiv> \<not> (x |\<in>| S)"
1518
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   498
1935
266abc3ee228 Moved working Fset3 properties to FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1927
diff changeset
   499
section {* Other constants on the Quotient Type *} 
266abc3ee228 Moved working Fset3 properties to FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1927
diff changeset
   500
266abc3ee228 Moved working Fset3 properties to FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1927
diff changeset
   501
quotient_definition
266abc3ee228 Moved working Fset3 properties to FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1927
diff changeset
   502
  "fcard :: 'a fset \<Rightarrow> nat" 
266abc3ee228 Moved working Fset3 properties to FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1927
diff changeset
   503
is
266abc3ee228 Moved working Fset3 properties to FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1927
diff changeset
   504
  "fcard_raw"
266abc3ee228 Moved working Fset3 properties to FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1927
diff changeset
   505
266abc3ee228 Moved working Fset3 properties to FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1927
diff changeset
   506
quotient_definition
266abc3ee228 Moved working Fset3 properties to FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1927
diff changeset
   507
  "fmap :: ('a \<Rightarrow> 'b) \<Rightarrow> 'a fset \<Rightarrow> 'b fset"
266abc3ee228 Moved working Fset3 properties to FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1927
diff changeset
   508
is
266abc3ee228 Moved working Fset3 properties to FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1927
diff changeset
   509
 "map"
266abc3ee228 Moved working Fset3 properties to FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1927
diff changeset
   510
266abc3ee228 Moved working Fset3 properties to FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1927
diff changeset
   511
quotient_definition
266abc3ee228 Moved working Fset3 properties to FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1927
diff changeset
   512
  "fdelete :: 'a fset \<Rightarrow> 'a \<Rightarrow> 'a fset" 
266abc3ee228 Moved working Fset3 properties to FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1927
diff changeset
   513
  is "delete_raw"
266abc3ee228 Moved working Fset3 properties to FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1927
diff changeset
   514
266abc3ee228 Moved working Fset3 properties to FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1927
diff changeset
   515
quotient_definition
266abc3ee228 Moved working Fset3 properties to FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1927
diff changeset
   516
  "fset_to_set :: 'a fset \<Rightarrow> 'a set" 
266abc3ee228 Moved working Fset3 properties to FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1927
diff changeset
   517
  is "set"
266abc3ee228 Moved working Fset3 properties to FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1927
diff changeset
   518
266abc3ee228 Moved working Fset3 properties to FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1927
diff changeset
   519
quotient_definition
266abc3ee228 Moved working Fset3 properties to FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1927
diff changeset
   520
  "ffold :: ('a \<Rightarrow> 'b \<Rightarrow> 'b) \<Rightarrow> 'b \<Rightarrow> 'a fset \<Rightarrow> 'b"
266abc3ee228 Moved working Fset3 properties to FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1927
diff changeset
   521
  is "ffold_raw"
266abc3ee228 Moved working Fset3 properties to FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1927
diff changeset
   522
266abc3ee228 Moved working Fset3 properties to FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1927
diff changeset
   523
quotient_definition
266abc3ee228 Moved working Fset3 properties to FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1927
diff changeset
   524
  "fconcat :: ('a fset) fset \<Rightarrow> 'a fset"
266abc3ee228 Moved working Fset3 properties to FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1927
diff changeset
   525
is
266abc3ee228 Moved working Fset3 properties to FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1927
diff changeset
   526
  "concat"
266abc3ee228 Moved working Fset3 properties to FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1927
diff changeset
   527
266abc3ee228 Moved working Fset3 properties to FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1927
diff changeset
   528
text {* Compositional Respectfullness and Preservation *}
266abc3ee228 Moved working Fset3 properties to FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1927
diff changeset
   529
266abc3ee228 Moved working Fset3 properties to FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1927
diff changeset
   530
lemma [quot_respect]: "(list_rel op \<approx> OOO op \<approx>) [] []"
1938
3641d055b260 Further cleaning of proofs in FSet
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1936
diff changeset
   531
  by (fact compose_list_refl)
1935
266abc3ee228 Moved working Fset3 properties to FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1927
diff changeset
   532
266abc3ee228 Moved working Fset3 properties to FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1927
diff changeset
   533
lemma [quot_preserve]: "(abs_fset \<circ> map f) [] = abs_fset []"
266abc3ee228 Moved working Fset3 properties to FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1927
diff changeset
   534
  by simp
266abc3ee228 Moved working Fset3 properties to FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1927
diff changeset
   535
266abc3ee228 Moved working Fset3 properties to FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1927
diff changeset
   536
lemma [quot_respect]:
266abc3ee228 Moved working Fset3 properties to FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1927
diff changeset
   537
  "(op \<approx> ===> list_rel op \<approx> OOO op \<approx> ===> list_rel op \<approx> OOO op \<approx>) op # op #"
266abc3ee228 Moved working Fset3 properties to FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1927
diff changeset
   538
  apply auto
266abc3ee228 Moved working Fset3 properties to FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1927
diff changeset
   539
  apply (simp add: set_in_eq)
266abc3ee228 Moved working Fset3 properties to FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1927
diff changeset
   540
  apply (rule_tac b="x # b" in pred_compI)
266abc3ee228 Moved working Fset3 properties to FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1927
diff changeset
   541
  apply auto
266abc3ee228 Moved working Fset3 properties to FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1927
diff changeset
   542
  apply (rule_tac b="x # ba" in pred_compI)
266abc3ee228 Moved working Fset3 properties to FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1927
diff changeset
   543
  apply auto
266abc3ee228 Moved working Fset3 properties to FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1927
diff changeset
   544
  done
266abc3ee228 Moved working Fset3 properties to FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1927
diff changeset
   545
266abc3ee228 Moved working Fset3 properties to FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1927
diff changeset
   546
lemma [quot_preserve]:
266abc3ee228 Moved working Fset3 properties to FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1927
diff changeset
   547
  "(rep_fset ---> (map rep_fset \<circ> rep_fset) ---> (abs_fset \<circ> map abs_fset)) op # = finsert"
266abc3ee228 Moved working Fset3 properties to FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1927
diff changeset
   548
  by (simp add: expand_fun_eq Quotient_abs_rep[OF Quotient_fset]
266abc3ee228 Moved working Fset3 properties to FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1927
diff changeset
   549
      abs_o_rep[OF Quotient_fset] map_id finsert_def)
266abc3ee228 Moved working Fset3 properties to FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1927
diff changeset
   550
266abc3ee228 Moved working Fset3 properties to FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1927
diff changeset
   551
lemma [quot_preserve]:
1938
3641d055b260 Further cleaning of proofs in FSet
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1936
diff changeset
   552
  "((map rep_fset \<circ> rep_fset) ---> (map rep_fset \<circ> rep_fset) ---> (abs_fset \<circ> map abs_fset)) op @ = funion"
1935
266abc3ee228 Moved working Fset3 properties to FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1927
diff changeset
   553
  by (simp add: expand_fun_eq Quotient_abs_rep[OF Quotient_fset]
266abc3ee228 Moved working Fset3 properties to FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1927
diff changeset
   554
      abs_o_rep[OF Quotient_fset] map_id sup_fset_def)
266abc3ee228 Moved working Fset3 properties to FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1927
diff changeset
   555
266abc3ee228 Moved working Fset3 properties to FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1927
diff changeset
   556
lemma list_rel_app_l:
266abc3ee228 Moved working Fset3 properties to FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1927
diff changeset
   557
  assumes a: "reflp R"
266abc3ee228 Moved working Fset3 properties to FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1927
diff changeset
   558
  and b: "list_rel R l r"
266abc3ee228 Moved working Fset3 properties to FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1927
diff changeset
   559
  shows "list_rel R (z @ l) (z @ r)"
1938
3641d055b260 Further cleaning of proofs in FSet
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1936
diff changeset
   560
  by (induct z) (simp_all add: b rev_iffD1[OF a meta_eq_to_obj_eq[OF reflp_def]])
1935
266abc3ee228 Moved working Fset3 properties to FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1927
diff changeset
   561
266abc3ee228 Moved working Fset3 properties to FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1927
diff changeset
   562
lemma append_rsp2_pre0:
266abc3ee228 Moved working Fset3 properties to FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1927
diff changeset
   563
  assumes a:"list_rel op \<approx> x x'"
266abc3ee228 Moved working Fset3 properties to FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1927
diff changeset
   564
  shows "list_rel op \<approx> (x @ z) (x' @ z)"
266abc3ee228 Moved working Fset3 properties to FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1927
diff changeset
   565
  using a apply (induct x x' rule: list_induct2')
1938
3641d055b260 Further cleaning of proofs in FSet
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1936
diff changeset
   566
  by simp_all (rule list_rel_refl)
1935
266abc3ee228 Moved working Fset3 properties to FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1927
diff changeset
   567
266abc3ee228 Moved working Fset3 properties to FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1927
diff changeset
   568
lemma append_rsp2_pre1:
266abc3ee228 Moved working Fset3 properties to FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1927
diff changeset
   569
  assumes a:"list_rel op \<approx> x x'"
266abc3ee228 Moved working Fset3 properties to FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1927
diff changeset
   570
  shows "list_rel op \<approx> (z @ x) (z @ x')"
266abc3ee228 Moved working Fset3 properties to FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1927
diff changeset
   571
  using a apply (induct x x' arbitrary: z rule: list_induct2')
266abc3ee228 Moved working Fset3 properties to FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1927
diff changeset
   572
  apply (rule list_rel_refl)
266abc3ee228 Moved working Fset3 properties to FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1927
diff changeset
   573
  apply (simp_all del: list_eq.simps)
266abc3ee228 Moved working Fset3 properties to FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1927
diff changeset
   574
  apply (rule list_rel_app_l)
266abc3ee228 Moved working Fset3 properties to FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1927
diff changeset
   575
  apply (simp_all add: reflp_def)
266abc3ee228 Moved working Fset3 properties to FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1927
diff changeset
   576
  done
266abc3ee228 Moved working Fset3 properties to FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1927
diff changeset
   577
266abc3ee228 Moved working Fset3 properties to FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1927
diff changeset
   578
lemma append_rsp2_pre:
266abc3ee228 Moved working Fset3 properties to FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1927
diff changeset
   579
  assumes a:"list_rel op \<approx> x x'"
266abc3ee228 Moved working Fset3 properties to FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1927
diff changeset
   580
  and     b: "list_rel op \<approx> z z'"
266abc3ee228 Moved working Fset3 properties to FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1927
diff changeset
   581
  shows "list_rel op \<approx> (x @ z) (x' @ z')"
266abc3ee228 Moved working Fset3 properties to FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1927
diff changeset
   582
  apply (rule list_rel_transp[OF fset_equivp])
266abc3ee228 Moved working Fset3 properties to FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1927
diff changeset
   583
  apply (rule append_rsp2_pre0)
266abc3ee228 Moved working Fset3 properties to FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1927
diff changeset
   584
  apply (rule a)
266abc3ee228 Moved working Fset3 properties to FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1927
diff changeset
   585
  using b apply (induct z z' rule: list_induct2')
266abc3ee228 Moved working Fset3 properties to FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1927
diff changeset
   586
  apply (simp_all only: append_Nil2)
266abc3ee228 Moved working Fset3 properties to FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1927
diff changeset
   587
  apply (rule list_rel_refl)
266abc3ee228 Moved working Fset3 properties to FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1927
diff changeset
   588
  apply simp_all
266abc3ee228 Moved working Fset3 properties to FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1927
diff changeset
   589
  apply (rule append_rsp2_pre1)
266abc3ee228 Moved working Fset3 properties to FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1927
diff changeset
   590
  apply simp
266abc3ee228 Moved working Fset3 properties to FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1927
diff changeset
   591
  done
266abc3ee228 Moved working Fset3 properties to FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1927
diff changeset
   592
266abc3ee228 Moved working Fset3 properties to FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1927
diff changeset
   593
lemma [quot_respect]:
266abc3ee228 Moved working Fset3 properties to FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1927
diff changeset
   594
  "(list_rel op \<approx> OOO op \<approx> ===> list_rel op \<approx> OOO op \<approx> ===> list_rel op \<approx> OOO op \<approx>) op @ op @"
266abc3ee228 Moved working Fset3 properties to FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1927
diff changeset
   595
proof (intro fun_relI, elim pred_compE)
266abc3ee228 Moved working Fset3 properties to FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1927
diff changeset
   596
  fix x y z w x' z' y' w' :: "'a list list"
266abc3ee228 Moved working Fset3 properties to FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1927
diff changeset
   597
  assume a:"list_rel op \<approx> x x'"
266abc3ee228 Moved working Fset3 properties to FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1927
diff changeset
   598
  and b:    "x' \<approx> y'"
266abc3ee228 Moved working Fset3 properties to FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1927
diff changeset
   599
  and c:    "list_rel op \<approx> y' y"
266abc3ee228 Moved working Fset3 properties to FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1927
diff changeset
   600
  assume aa: "list_rel op \<approx> z z'"
266abc3ee228 Moved working Fset3 properties to FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1927
diff changeset
   601
  and bb:   "z' \<approx> w'"
266abc3ee228 Moved working Fset3 properties to FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1927
diff changeset
   602
  and cc:   "list_rel op \<approx> w' w"
266abc3ee228 Moved working Fset3 properties to FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1927
diff changeset
   603
  have a': "list_rel op \<approx> (x @ z) (x' @ z')" using a aa append_rsp2_pre by auto
266abc3ee228 Moved working Fset3 properties to FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1927
diff changeset
   604
  have b': "x' @ z' \<approx> y' @ w'" using b bb by simp
266abc3ee228 Moved working Fset3 properties to FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1927
diff changeset
   605
  have c': "list_rel op \<approx> (y' @ w') (y @ w)" using c cc append_rsp2_pre by auto
266abc3ee228 Moved working Fset3 properties to FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1927
diff changeset
   606
  have d': "(op \<approx> OO list_rel op \<approx>) (x' @ z') (y @ w)"
266abc3ee228 Moved working Fset3 properties to FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1927
diff changeset
   607
    by (rule pred_compI) (rule b', rule c')
266abc3ee228 Moved working Fset3 properties to FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1927
diff changeset
   608
  show "(list_rel op \<approx> OOO op \<approx>) (x @ z) (y @ w)"
266abc3ee228 Moved working Fset3 properties to FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1927
diff changeset
   609
    by (rule pred_compI) (rule a', rule d')
266abc3ee228 Moved working Fset3 properties to FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1927
diff changeset
   610
qed
266abc3ee228 Moved working Fset3 properties to FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1927
diff changeset
   611
266abc3ee228 Moved working Fset3 properties to FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1927
diff changeset
   612
text {* Raw theorems. Finsert, memb, singleron, sub_list *}
1518
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   613
1892
4df853f5879f reorder
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1889
diff changeset
   614
lemma nil_not_cons:
4df853f5879f reorder
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1889
diff changeset
   615
  shows "\<not> ([] \<approx> x # xs)"
4df853f5879f reorder
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1889
diff changeset
   616
  and   "\<not> (x # xs \<approx> [])"
4df853f5879f reorder
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1889
diff changeset
   617
  by auto
4df853f5879f reorder
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1889
diff changeset
   618
1878
c22947214948 2 more lifted lemmas needed for second representation
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1860
diff changeset
   619
lemma no_memb_nil:
c22947214948 2 more lifted lemmas needed for second representation
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1860
diff changeset
   620
  "(\<forall>x. \<not> memb x xs) = (xs = [])"
c22947214948 2 more lifted lemmas needed for second representation
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1860
diff changeset
   621
  by (simp add: memb_def)
c22947214948 2 more lifted lemmas needed for second representation
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1860
diff changeset
   622
1518
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   623
lemma memb_consI1:
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   624
  shows "memb x (x # xs)"
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   625
  by (simp add: memb_def)
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   626
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   627
lemma memb_consI2:
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   628
  shows "memb x xs \<Longrightarrow> memb x (y # xs)"
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   629
  by (simp add: memb_def)
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   630
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   631
lemma singleton_list_eq:
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   632
  shows "[x] \<approx> [y] \<longleftrightarrow> x = y"
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   633
  by (simp add: id_simps) auto
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   634
1892
4df853f5879f reorder
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1889
diff changeset
   635
lemma sub_list_cons:
4df853f5879f reorder
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1889
diff changeset
   636
  "sub_list (x # xs) ys = (memb x ys \<and> sub_list xs ys)"
4df853f5879f reorder
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1889
diff changeset
   637
  by (auto simp add: memb_def sub_list_def)
4df853f5879f reorder
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1889
diff changeset
   638
1935
266abc3ee228 Moved working Fset3 properties to FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1927
diff changeset
   639
text {* Cardinality of finite sets *}
1518
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   640
1813
69fff336dd18 Porting lemmas from Quotient package FSet to new FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1682
diff changeset
   641
lemma fcard_raw_0:
1860
d3fe17786640 some tuning of proofs
Christian Urban <urbanc@in.tum.de>
parents: 1826
diff changeset
   642
  shows "fcard_raw xs = 0 \<longleftrightarrow> xs \<approx> []"
1821
Christian Urban <urbanc@in.tum.de>
parents: 1820
diff changeset
   643
  by (induct xs) (auto simp add: memb_def)
1813
69fff336dd18 Porting lemmas from Quotient package FSet to new FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1682
diff changeset
   644
69fff336dd18 Porting lemmas from Quotient package FSet to new FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1682
diff changeset
   645
lemma fcard_raw_not_memb:
1860
d3fe17786640 some tuning of proofs
Christian Urban <urbanc@in.tum.de>
parents: 1826
diff changeset
   646
  shows "\<not> memb x xs \<longleftrightarrow> fcard_raw (x # xs) = Suc (fcard_raw xs)"
1813
69fff336dd18 Porting lemmas from Quotient package FSet to new FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1682
diff changeset
   647
  by auto
69fff336dd18 Porting lemmas from Quotient package FSet to new FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1682
diff changeset
   648
69fff336dd18 Porting lemmas from Quotient package FSet to new FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1682
diff changeset
   649
lemma fcard_raw_suc:
1860
d3fe17786640 some tuning of proofs
Christian Urban <urbanc@in.tum.de>
parents: 1826
diff changeset
   650
  assumes a: "fcard_raw xs = Suc n"
d3fe17786640 some tuning of proofs
Christian Urban <urbanc@in.tum.de>
parents: 1826
diff changeset
   651
  shows "\<exists>x ys. \<not> (memb x ys) \<and> xs \<approx> (x # ys) \<and> fcard_raw ys = n"
d3fe17786640 some tuning of proofs
Christian Urban <urbanc@in.tum.de>
parents: 1826
diff changeset
   652
  using a
d3fe17786640 some tuning of proofs
Christian Urban <urbanc@in.tum.de>
parents: 1826
diff changeset
   653
  by (induct xs) (auto simp add: memb_def split: if_splits)
1819
63dd459dbc0d Much more in FSet (currently non-working)
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1817
diff changeset
   654
1935
266abc3ee228 Moved working Fset3 properties to FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1927
diff changeset
   655
lemma singleton_fcard_1:
1860
d3fe17786640 some tuning of proofs
Christian Urban <urbanc@in.tum.de>
parents: 1826
diff changeset
   656
  shows "set xs = {x} \<Longrightarrow> fcard_raw xs = 1"
d3fe17786640 some tuning of proofs
Christian Urban <urbanc@in.tum.de>
parents: 1826
diff changeset
   657
  by (induct xs) (auto simp add: memb_def subset_insert)
1819
63dd459dbc0d Much more in FSet (currently non-working)
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1817
diff changeset
   658
63dd459dbc0d Much more in FSet (currently non-working)
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1817
diff changeset
   659
lemma fcard_raw_1:
1823
91ba55dba5e0 added header and more tuning
Christian Urban <urbanc@in.tum.de>
parents: 1822
diff changeset
   660
  shows "fcard_raw xs = 1 \<longleftrightarrow> (\<exists>x. xs \<approx> [x])"
91ba55dba5e0 added header and more tuning
Christian Urban <urbanc@in.tum.de>
parents: 1822
diff changeset
   661
  apply (auto dest!: fcard_raw_suc)
1819
63dd459dbc0d Much more in FSet (currently non-working)
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1817
diff changeset
   662
  apply (simp add: fcard_raw_0)
1821
Christian Urban <urbanc@in.tum.de>
parents: 1820
diff changeset
   663
  apply (rule_tac x="x" in exI)
1819
63dd459dbc0d Much more in FSet (currently non-working)
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1817
diff changeset
   664
  apply simp
1821
Christian Urban <urbanc@in.tum.de>
parents: 1820
diff changeset
   665
  apply (subgoal_tac "set xs = {x}")
1860
d3fe17786640 some tuning of proofs
Christian Urban <urbanc@in.tum.de>
parents: 1826
diff changeset
   666
  apply (drule singleton_fcard_1)
1819
63dd459dbc0d Much more in FSet (currently non-working)
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1817
diff changeset
   667
  apply auto
1813
69fff336dd18 Porting lemmas from Quotient package FSet to new FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1682
diff changeset
   668
  done
69fff336dd18 Porting lemmas from Quotient package FSet to new FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1682
diff changeset
   669
1878
c22947214948 2 more lifted lemmas needed for second representation
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1860
diff changeset
   670
lemma fcard_raw_suc_memb:
c22947214948 2 more lifted lemmas needed for second representation
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1860
diff changeset
   671
  assumes a: "fcard_raw A = Suc n"
c22947214948 2 more lifted lemmas needed for second representation
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1860
diff changeset
   672
  shows "\<exists>a. memb a A"
c22947214948 2 more lifted lemmas needed for second representation
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1860
diff changeset
   673
  using a
1938
3641d055b260 Further cleaning of proofs in FSet
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1936
diff changeset
   674
  by (induct A) (auto simp add: memb_def)
1878
c22947214948 2 more lifted lemmas needed for second representation
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1860
diff changeset
   675
1884
5fd2ed815144 more metis cleaning
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1883
diff changeset
   676
lemma memb_card_not_0:
1878
c22947214948 2 more lifted lemmas needed for second representation
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1860
diff changeset
   677
  assumes a: "memb a A"
c22947214948 2 more lifted lemmas needed for second representation
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1860
diff changeset
   678
  shows "\<not>(fcard_raw A = 0)"
1883
b2fa5de30a73 Getting rid of 'metis'.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1881
diff changeset
   679
proof -
b2fa5de30a73 Getting rid of 'metis'.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1881
diff changeset
   680
  have "\<not>(\<forall>x. \<not> memb x A)" using a by auto
b2fa5de30a73 Getting rid of 'metis'.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1881
diff changeset
   681
  then have "\<not>A \<approx> []" using none_memb_nil[of A] by simp
b2fa5de30a73 Getting rid of 'metis'.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1881
diff changeset
   682
  then show ?thesis using fcard_raw_0[of A] by simp
b2fa5de30a73 Getting rid of 'metis'.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1881
diff changeset
   683
qed
1878
c22947214948 2 more lifted lemmas needed for second representation
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1860
diff changeset
   684
1935
266abc3ee228 Moved working Fset3 properties to FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1927
diff changeset
   685
text {* fmap *}
1518
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   686
1813
69fff336dd18 Porting lemmas from Quotient package FSet to new FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1682
diff changeset
   687
lemma map_append:
1821
Christian Urban <urbanc@in.tum.de>
parents: 1820
diff changeset
   688
  "map f (xs @ ys) \<approx> (map f xs) @ (map f ys)"
1813
69fff336dd18 Porting lemmas from Quotient package FSet to new FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1682
diff changeset
   689
  by simp
69fff336dd18 Porting lemmas from Quotient package FSet to new FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1682
diff changeset
   690
1819
63dd459dbc0d Much more in FSet (currently non-working)
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1817
diff changeset
   691
lemma memb_append:
1823
91ba55dba5e0 added header and more tuning
Christian Urban <urbanc@in.tum.de>
parents: 1822
diff changeset
   692
  "memb x (xs @ ys) \<longleftrightarrow> memb x xs \<or> memb x ys"
1821
Christian Urban <urbanc@in.tum.de>
parents: 1820
diff changeset
   693
  by (induct xs) (simp_all add: not_memb_nil memb_cons_iff)
1819
63dd459dbc0d Much more in FSet (currently non-working)
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1817
diff changeset
   694
1518
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   695
lemma cons_left_comm:
1821
Christian Urban <urbanc@in.tum.de>
parents: 1820
diff changeset
   696
  "x # y # xs \<approx> y # x # xs"
Christian Urban <urbanc@in.tum.de>
parents: 1820
diff changeset
   697
  by auto
1518
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   698
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   699
lemma cons_left_idem:
1821
Christian Urban <urbanc@in.tum.de>
parents: 1820
diff changeset
   700
  "x # x # xs \<approx> x # xs"
Christian Urban <urbanc@in.tum.de>
parents: 1820
diff changeset
   701
  by auto
1518
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   702
1819
63dd459dbc0d Much more in FSet (currently non-working)
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1817
diff changeset
   703
lemma fset_raw_strong_cases:
1822
4465723e35e7 more tuning
Christian Urban <urbanc@in.tum.de>
parents: 1821
diff changeset
   704
  "(xs = []) \<or> (\<exists>x ys. ((\<not> memb x ys) \<and> (xs \<approx> x # ys)))"
1821
Christian Urban <urbanc@in.tum.de>
parents: 1820
diff changeset
   705
  apply (induct xs)
1518
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   706
  apply (simp)
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   707
  apply (rule disjI2)
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   708
  apply (erule disjE)
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   709
  apply (rule_tac x="a" in exI)
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   710
  apply (rule_tac x="[]" in exI)
1822
4465723e35e7 more tuning
Christian Urban <urbanc@in.tum.de>
parents: 1821
diff changeset
   711
  apply (simp add: memb_def)
1518
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   712
  apply (erule exE)+
1821
Christian Urban <urbanc@in.tum.de>
parents: 1820
diff changeset
   713
  apply (case_tac "x = a")
1518
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   714
  apply (rule_tac x="a" in exI)
1821
Christian Urban <urbanc@in.tum.de>
parents: 1820
diff changeset
   715
  apply (rule_tac x="ys" in exI)
1518
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   716
  apply (simp)
1821
Christian Urban <urbanc@in.tum.de>
parents: 1820
diff changeset
   717
  apply (rule_tac x="x" in exI)
Christian Urban <urbanc@in.tum.de>
parents: 1820
diff changeset
   718
  apply (rule_tac x="a # ys" in exI)
1822
4465723e35e7 more tuning
Christian Urban <urbanc@in.tum.de>
parents: 1821
diff changeset
   719
  apply (auto simp add: memb_def)
1518
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   720
  done
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   721
1860
d3fe17786640 some tuning of proofs
Christian Urban <urbanc@in.tum.de>
parents: 1826
diff changeset
   722
section {* deletion *}
d3fe17786640 some tuning of proofs
Christian Urban <urbanc@in.tum.de>
parents: 1826
diff changeset
   723
1819
63dd459dbc0d Much more in FSet (currently non-working)
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1817
diff changeset
   724
lemma memb_delete_raw_ident:
1860
d3fe17786640 some tuning of proofs
Christian Urban <urbanc@in.tum.de>
parents: 1826
diff changeset
   725
  shows "\<not> memb x (delete_raw xs x)"
1821
Christian Urban <urbanc@in.tum.de>
parents: 1820
diff changeset
   726
  by (induct xs) (auto simp add: memb_def)
1518
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   727
1819
63dd459dbc0d Much more in FSet (currently non-working)
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1817
diff changeset
   728
lemma fset_raw_delete_raw_cases:
1821
Christian Urban <urbanc@in.tum.de>
parents: 1820
diff changeset
   729
  "xs = [] \<or> (\<exists>x. memb x xs \<and> xs \<approx> x # delete_raw xs x)"
Christian Urban <urbanc@in.tum.de>
parents: 1820
diff changeset
   730
  by (induct xs) (auto simp add: memb_def)
1518
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   731
1819
63dd459dbc0d Much more in FSet (currently non-working)
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1817
diff changeset
   732
lemma fdelete_raw_filter:
63dd459dbc0d Much more in FSet (currently non-working)
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1817
diff changeset
   733
  "delete_raw xs y = [x \<leftarrow> xs. x \<noteq> y]"
63dd459dbc0d Much more in FSet (currently non-working)
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1817
diff changeset
   734
  by (induct xs) simp_all
1518
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   735
1819
63dd459dbc0d Much more in FSet (currently non-working)
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1817
diff changeset
   736
lemma fcard_raw_delete:
63dd459dbc0d Much more in FSet (currently non-working)
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1817
diff changeset
   737
  "fcard_raw (delete_raw xs y) = (if memb y xs then fcard_raw xs - 1 else fcard_raw xs)"
63dd459dbc0d Much more in FSet (currently non-working)
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1817
diff changeset
   738
  by (simp add: fdelete_raw_filter fcard_raw_delete_one)
1518
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   739
1819
63dd459dbc0d Much more in FSet (currently non-working)
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1817
diff changeset
   740
lemma finter_raw_empty:
63dd459dbc0d Much more in FSet (currently non-working)
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1817
diff changeset
   741
  "finter_raw l [] = []"
63dd459dbc0d Much more in FSet (currently non-working)
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1817
diff changeset
   742
  by (induct l) (simp_all add: not_memb_nil)
63dd459dbc0d Much more in FSet (currently non-working)
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1817
diff changeset
   743
1821
Christian Urban <urbanc@in.tum.de>
parents: 1820
diff changeset
   744
lemma set_cong: 
Christian Urban <urbanc@in.tum.de>
parents: 1820
diff changeset
   745
  shows "(set x = set y) = (x \<approx> y)"
Christian Urban <urbanc@in.tum.de>
parents: 1820
diff changeset
   746
  by auto
1533
5f5e99a11f66 A few more theorems in FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1518
diff changeset
   747
5f5e99a11f66 A few more theorems in FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1518
diff changeset
   748
lemma inj_map_eq_iff:
5f5e99a11f66 A few more theorems in FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1518
diff changeset
   749
  "inj f \<Longrightarrow> (map f l \<approx> map f m) = (l \<approx> m)"
5f5e99a11f66 A few more theorems in FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1518
diff changeset
   750
  by (simp add: expand_set_eq[symmetric] inj_image_eq_iff)
5f5e99a11f66 A few more theorems in FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1518
diff changeset
   751
1888
59f41804b3f8 Alternate list_eq and equivalence
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1887
diff changeset
   752
text {* alternate formulation with a different decomposition principle
59f41804b3f8 Alternate list_eq and equivalence
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1887
diff changeset
   753
  and a proof of equivalence *}
59f41804b3f8 Alternate list_eq and equivalence
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1887
diff changeset
   754
59f41804b3f8 Alternate list_eq and equivalence
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1887
diff changeset
   755
inductive
59f41804b3f8 Alternate list_eq and equivalence
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1887
diff changeset
   756
  list_eq2
59f41804b3f8 Alternate list_eq and equivalence
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1887
diff changeset
   757
where
59f41804b3f8 Alternate list_eq and equivalence
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1887
diff changeset
   758
  "list_eq2 (a # b # xs) (b # a # xs)"
59f41804b3f8 Alternate list_eq and equivalence
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1887
diff changeset
   759
| "list_eq2 [] []"
59f41804b3f8 Alternate list_eq and equivalence
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1887
diff changeset
   760
| "list_eq2 xs ys \<Longrightarrow> list_eq2 ys xs"
59f41804b3f8 Alternate list_eq and equivalence
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1887
diff changeset
   761
| "list_eq2 (a # a # xs) (a # xs)"
59f41804b3f8 Alternate list_eq and equivalence
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1887
diff changeset
   762
| "list_eq2 xs ys \<Longrightarrow> list_eq2 (a # xs) (a # ys)"
59f41804b3f8 Alternate list_eq and equivalence
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1887
diff changeset
   763
| "\<lbrakk>list_eq2 xs1 xs2; list_eq2 xs2 xs3\<rbrakk> \<Longrightarrow> list_eq2 xs1 xs3"
59f41804b3f8 Alternate list_eq and equivalence
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1887
diff changeset
   764
59f41804b3f8 Alternate list_eq and equivalence
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1887
diff changeset
   765
lemma list_eq2_refl:
59f41804b3f8 Alternate list_eq and equivalence
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1887
diff changeset
   766
  shows "list_eq2 xs xs"
59f41804b3f8 Alternate list_eq and equivalence
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1887
diff changeset
   767
  by (induct xs) (auto intro: list_eq2.intros)
59f41804b3f8 Alternate list_eq and equivalence
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1887
diff changeset
   768
59f41804b3f8 Alternate list_eq and equivalence
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1887
diff changeset
   769
lemma cons_delete_list_eq2:
59f41804b3f8 Alternate list_eq and equivalence
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1887
diff changeset
   770
  shows "list_eq2 (a # (delete_raw A a)) (if memb a A then A else a # A)"
59f41804b3f8 Alternate list_eq and equivalence
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1887
diff changeset
   771
  apply (induct A)
59f41804b3f8 Alternate list_eq and equivalence
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1887
diff changeset
   772
  apply (simp add: memb_def list_eq2_refl)
59f41804b3f8 Alternate list_eq and equivalence
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1887
diff changeset
   773
  apply (case_tac "memb a (aa # A)")
59f41804b3f8 Alternate list_eq and equivalence
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1887
diff changeset
   774
  apply (simp_all only: memb_cons_iff)
59f41804b3f8 Alternate list_eq and equivalence
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1887
diff changeset
   775
  apply (case_tac [!] "a = aa")
1909
9972dc5bd7ad Reorder FSet
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1907
diff changeset
   776
  apply (simp_all)
1888
59f41804b3f8 Alternate list_eq and equivalence
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1887
diff changeset
   777
  apply (case_tac "memb a A")
59f41804b3f8 Alternate list_eq and equivalence
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1887
diff changeset
   778
  apply (auto simp add: memb_def)[2]
59f41804b3f8 Alternate list_eq and equivalence
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1887
diff changeset
   779
  apply (metis list_eq2.intros(3) list_eq2.intros(4) list_eq2.intros(5) list_eq2.intros(6))
1895
91d67240c9c1 FSet is a semi-lattice
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1893
diff changeset
   780
  apply (metis list_eq2.intros(1) list_eq2.intros(5) list_eq2.intros(6))
1888
59f41804b3f8 Alternate list_eq and equivalence
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1887
diff changeset
   781
  apply (auto simp add: list_eq2_refl not_memb_delete_raw_ident)
59f41804b3f8 Alternate list_eq and equivalence
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1887
diff changeset
   782
  done
59f41804b3f8 Alternate list_eq and equivalence
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1887
diff changeset
   783
59f41804b3f8 Alternate list_eq and equivalence
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1887
diff changeset
   784
lemma memb_delete_list_eq2:
59f41804b3f8 Alternate list_eq and equivalence
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1887
diff changeset
   785
  assumes a: "memb e r"
59f41804b3f8 Alternate list_eq and equivalence
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1887
diff changeset
   786
  shows "list_eq2 (e # delete_raw r e) r"
59f41804b3f8 Alternate list_eq and equivalence
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1887
diff changeset
   787
  using a cons_delete_list_eq2[of e r]
59f41804b3f8 Alternate list_eq and equivalence
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1887
diff changeset
   788
  by simp
59f41804b3f8 Alternate list_eq and equivalence
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1887
diff changeset
   789
1909
9972dc5bd7ad Reorder FSet
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1907
diff changeset
   790
lemma delete_raw_rsp:
9972dc5bd7ad Reorder FSet
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1907
diff changeset
   791
  "xs \<approx> ys \<Longrightarrow> delete_raw xs x \<approx> delete_raw ys x"
9972dc5bd7ad Reorder FSet
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1907
diff changeset
   792
  by (simp add: memb_def[symmetric] memb_delete_raw)
9972dc5bd7ad Reorder FSet
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1907
diff changeset
   793
1888
59f41804b3f8 Alternate list_eq and equivalence
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1887
diff changeset
   794
lemma list_eq2_equiv:
59f41804b3f8 Alternate list_eq and equivalence
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1887
diff changeset
   795
  "(l \<approx> r) \<longleftrightarrow> (list_eq2 l r)"
59f41804b3f8 Alternate list_eq and equivalence
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1887
diff changeset
   796
proof
59f41804b3f8 Alternate list_eq and equivalence
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1887
diff changeset
   797
  show "list_eq2 l r \<Longrightarrow> l \<approx> r" by (induct rule: list_eq2.induct) auto
1938
3641d055b260 Further cleaning of proofs in FSet
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1936
diff changeset
   798
next
3641d055b260 Further cleaning of proofs in FSet
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1936
diff changeset
   799
  {
3641d055b260 Further cleaning of proofs in FSet
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1936
diff changeset
   800
    fix n
3641d055b260 Further cleaning of proofs in FSet
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1936
diff changeset
   801
    assume a: "fcard_raw l = n" and b: "l \<approx> r"
3641d055b260 Further cleaning of proofs in FSet
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1936
diff changeset
   802
    have "list_eq2 l r"
3641d055b260 Further cleaning of proofs in FSet
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1936
diff changeset
   803
      using a b
3641d055b260 Further cleaning of proofs in FSet
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1936
diff changeset
   804
    proof (induct n arbitrary: l r)
3641d055b260 Further cleaning of proofs in FSet
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1936
diff changeset
   805
      case 0
3641d055b260 Further cleaning of proofs in FSet
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1936
diff changeset
   806
      have "fcard_raw l = 0" by fact
3641d055b260 Further cleaning of proofs in FSet
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1936
diff changeset
   807
      then have "\<forall>x. \<not> memb x l" using memb_card_not_0[of _ l] by auto
3641d055b260 Further cleaning of proofs in FSet
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1936
diff changeset
   808
      then have z: "l = []" using no_memb_nil by auto
3641d055b260 Further cleaning of proofs in FSet
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1936
diff changeset
   809
      then have "r = []" using `l \<approx> r` by simp
3641d055b260 Further cleaning of proofs in FSet
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1936
diff changeset
   810
      then show ?case using z list_eq2_refl by simp
3641d055b260 Further cleaning of proofs in FSet
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1936
diff changeset
   811
    next
3641d055b260 Further cleaning of proofs in FSet
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1936
diff changeset
   812
      case (Suc m)
3641d055b260 Further cleaning of proofs in FSet
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1936
diff changeset
   813
      have b: "l \<approx> r" by fact
3641d055b260 Further cleaning of proofs in FSet
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1936
diff changeset
   814
      have d: "fcard_raw l = Suc m" by fact
3641d055b260 Further cleaning of proofs in FSet
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1936
diff changeset
   815
      have "\<exists>a. memb a l" by (rule fcard_raw_suc_memb[OF d])
3641d055b260 Further cleaning of proofs in FSet
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1936
diff changeset
   816
      then obtain a where e: "memb a l" by auto
3641d055b260 Further cleaning of proofs in FSet
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1936
diff changeset
   817
      then have e': "memb a r" using list_eq.simps[simplified memb_def[symmetric], of l r] b by auto
3641d055b260 Further cleaning of proofs in FSet
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1936
diff changeset
   818
      have f: "fcard_raw (delete_raw l a) = m" using fcard_raw_delete[of l a] e d by simp
3641d055b260 Further cleaning of proofs in FSet
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1936
diff changeset
   819
      have g: "delete_raw l a \<approx> delete_raw r a" using delete_raw_rsp[OF b] by simp
3641d055b260 Further cleaning of proofs in FSet
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1936
diff changeset
   820
      have g': "list_eq2 (delete_raw l a) (delete_raw r a)" by (rule Suc.hyps[OF f g])
3641d055b260 Further cleaning of proofs in FSet
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1936
diff changeset
   821
      have h: "list_eq2 (a # delete_raw l a) (a # delete_raw r a)" by (rule list_eq2.intros(5)[OF g'])
3641d055b260 Further cleaning of proofs in FSet
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1936
diff changeset
   822
      have i: "list_eq2 l (a # delete_raw l a)"
3641d055b260 Further cleaning of proofs in FSet
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1936
diff changeset
   823
        by (rule list_eq2.intros(3)[OF memb_delete_list_eq2[OF e]])
3641d055b260 Further cleaning of proofs in FSet
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1936
diff changeset
   824
      have "list_eq2 l (a # delete_raw r a)" by (rule list_eq2.intros(6)[OF i h])
3641d055b260 Further cleaning of proofs in FSet
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1936
diff changeset
   825
      then show ?case using list_eq2.intros(6)[OF _ memb_delete_list_eq2[OF e']] by simp
3641d055b260 Further cleaning of proofs in FSet
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1936
diff changeset
   826
    qed
3641d055b260 Further cleaning of proofs in FSet
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1936
diff changeset
   827
    }
3641d055b260 Further cleaning of proofs in FSet
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1936
diff changeset
   828
  then show "l \<approx> r \<Longrightarrow> list_eq2 l r" by blast
1888
59f41804b3f8 Alternate list_eq and equivalence
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1887
diff changeset
   829
qed
59f41804b3f8 Alternate list_eq and equivalence
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1887
diff changeset
   830
1935
266abc3ee228 Moved working Fset3 properties to FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1927
diff changeset
   831
text {* Lifted theorems *}
1518
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   832
1819
63dd459dbc0d Much more in FSet (currently non-working)
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1817
diff changeset
   833
lemma not_fin_fnil: "x |\<notin>| {||}"
63dd459dbc0d Much more in FSet (currently non-working)
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1817
diff changeset
   834
  by (lifting not_memb_nil)
1518
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   835
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   836
lemma fin_finsert_iff[simp]:
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   837
  "x |\<in>| finsert y S = (x = y \<or> x |\<in>| S)"
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   838
  by (lifting memb_cons_iff)
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   839
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   840
lemma
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   841
  shows finsertI1: "x |\<in>| finsert x S"
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   842
  and   finsertI2: "x |\<in>| S \<Longrightarrow> x |\<in>| finsert y S"
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   843
  by (lifting memb_consI1, lifting memb_consI2)
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   844
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   845
lemma finsert_absorb[simp]:
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   846
  shows "x |\<in>| S \<Longrightarrow> finsert x S = S"
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   847
  by (lifting memb_absorb)
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   848
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   849
lemma fempty_not_finsert[simp]:
1533
5f5e99a11f66 A few more theorems in FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1518
diff changeset
   850
  "{||} \<noteq> finsert x S"
5f5e99a11f66 A few more theorems in FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1518
diff changeset
   851
  "finsert x S \<noteq> {||}"
1518
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   852
  by (lifting nil_not_cons)
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   853
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   854
lemma finsert_left_comm:
1822
4465723e35e7 more tuning
Christian Urban <urbanc@in.tum.de>
parents: 1821
diff changeset
   855
  "finsert x (finsert y S) = finsert y (finsert x S)"
1518
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   856
  by (lifting cons_left_comm)
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   857
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   858
lemma finsert_left_idem:
1822
4465723e35e7 more tuning
Christian Urban <urbanc@in.tum.de>
parents: 1821
diff changeset
   859
  "finsert x (finsert x S) = finsert x S"
1518
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   860
  by (lifting cons_left_idem)
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   861
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   862
lemma fsingleton_eq[simp]:
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   863
  shows "{|x|} = {|y|} \<longleftrightarrow> x = y"
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   864
  by (lifting singleton_list_eq)
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   865
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   866
text {* fset_to_set *}
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   867
1533
5f5e99a11f66 A few more theorems in FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1518
diff changeset
   868
lemma fset_to_set_simps[simp]:
1819
63dd459dbc0d Much more in FSet (currently non-working)
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1817
diff changeset
   869
  "fset_to_set {||} = ({} :: 'a set)"
63dd459dbc0d Much more in FSet (currently non-working)
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1817
diff changeset
   870
  "fset_to_set (finsert (h :: 'a) t) = insert h (fset_to_set t)"
63dd459dbc0d Much more in FSet (currently non-working)
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1817
diff changeset
   871
  by (lifting set.simps)
1518
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   872
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   873
lemma in_fset_to_set:
1822
4465723e35e7 more tuning
Christian Urban <urbanc@in.tum.de>
parents: 1821
diff changeset
   874
  "x \<in> fset_to_set S \<equiv> x |\<in>| S"
1518
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   875
  by (lifting memb_def[symmetric])
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   876
1819
63dd459dbc0d Much more in FSet (currently non-working)
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1817
diff changeset
   877
lemma none_fin_fempty:
1824
2ccc1b00377c merge part1: none_memb_nil
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1823
diff changeset
   878
  "(\<forall>x. x |\<notin>| S) = (S = {||})"
2ccc1b00377c merge part1: none_memb_nil
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1823
diff changeset
   879
  by (lifting none_memb_nil)
1518
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   880
1533
5f5e99a11f66 A few more theorems in FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1518
diff changeset
   881
lemma fset_cong:
1822
4465723e35e7 more tuning
Christian Urban <urbanc@in.tum.de>
parents: 1821
diff changeset
   882
  "(fset_to_set S = fset_to_set T) = (S = T)"
1533
5f5e99a11f66 A few more theorems in FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1518
diff changeset
   883
  by (lifting set_cong)
5f5e99a11f66 A few more theorems in FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1518
diff changeset
   884
1518
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   885
text {* fcard *}
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   886
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   887
lemma fcard_fempty [simp]:
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   888
  shows "fcard {||} = 0"
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   889
  by (lifting fcard_raw_nil)
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   890
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   891
lemma fcard_finsert_if [simp]:
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   892
  shows "fcard (finsert x S) = (if x |\<in>| S then fcard S else Suc (fcard S))"
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   893
  by (lifting fcard_raw_cons)
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   894
1822
4465723e35e7 more tuning
Christian Urban <urbanc@in.tum.de>
parents: 1821
diff changeset
   895
lemma fcard_0: "(fcard S = 0) = (S = {||})"
1813
69fff336dd18 Porting lemmas from Quotient package FSet to new FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1682
diff changeset
   896
  by (lifting fcard_raw_0)
69fff336dd18 Porting lemmas from Quotient package FSet to new FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1682
diff changeset
   897
1821
Christian Urban <urbanc@in.tum.de>
parents: 1820
diff changeset
   898
lemma fcard_1:
1822
4465723e35e7 more tuning
Christian Urban <urbanc@in.tum.de>
parents: 1821
diff changeset
   899
  shows "(fcard S = 1) = (\<exists>x. S = {|x|})"
1819
63dd459dbc0d Much more in FSet (currently non-working)
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1817
diff changeset
   900
  by (lifting fcard_raw_1)
63dd459dbc0d Much more in FSet (currently non-working)
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1817
diff changeset
   901
1860
d3fe17786640 some tuning of proofs
Christian Urban <urbanc@in.tum.de>
parents: 1826
diff changeset
   902
lemma fcard_gt_0: 
d3fe17786640 some tuning of proofs
Christian Urban <urbanc@in.tum.de>
parents: 1826
diff changeset
   903
  shows "x \<in> fset_to_set S \<Longrightarrow> 0 < fcard S"
1518
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   904
  by (lifting fcard_raw_gt_0)
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   905
1860
d3fe17786640 some tuning of proofs
Christian Urban <urbanc@in.tum.de>
parents: 1826
diff changeset
   906
lemma fcard_not_fin: 
d3fe17786640 some tuning of proofs
Christian Urban <urbanc@in.tum.de>
parents: 1826
diff changeset
   907
  shows "(x |\<notin>| S) = (fcard (finsert x S) = Suc (fcard S))"
1813
69fff336dd18 Porting lemmas from Quotient package FSet to new FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1682
diff changeset
   908
  by (lifting fcard_raw_not_memb)
69fff336dd18 Porting lemmas from Quotient package FSet to new FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1682
diff changeset
   909
1822
4465723e35e7 more tuning
Christian Urban <urbanc@in.tum.de>
parents: 1821
diff changeset
   910
lemma fcard_suc: "fcard S = Suc n \<Longrightarrow> \<exists>x T. x |\<notin>| T \<and> S = finsert x T \<and> fcard T = n"
1813
69fff336dd18 Porting lemmas from Quotient package FSet to new FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1682
diff changeset
   911
  by (lifting fcard_raw_suc)
69fff336dd18 Porting lemmas from Quotient package FSet to new FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1682
diff changeset
   912
1819
63dd459dbc0d Much more in FSet (currently non-working)
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1817
diff changeset
   913
lemma fcard_delete:
1822
4465723e35e7 more tuning
Christian Urban <urbanc@in.tum.de>
parents: 1821
diff changeset
   914
  "fcard (fdelete S y) = (if y |\<in>| S then fcard S - 1 else fcard S)"
1819
63dd459dbc0d Much more in FSet (currently non-working)
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1817
diff changeset
   915
  by (lifting fcard_raw_delete)
63dd459dbc0d Much more in FSet (currently non-working)
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1817
diff changeset
   916
1878
c22947214948 2 more lifted lemmas needed for second representation
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1860
diff changeset
   917
lemma fcard_suc_memb: "fcard A = Suc n \<Longrightarrow> \<exists>a. a |\<in>| A"
c22947214948 2 more lifted lemmas needed for second representation
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1860
diff changeset
   918
  by (lifting fcard_raw_suc_memb)
c22947214948 2 more lifted lemmas needed for second representation
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1860
diff changeset
   919
c22947214948 2 more lifted lemmas needed for second representation
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1860
diff changeset
   920
lemma fin_fcard_not_0: "a |\<in>| A \<Longrightarrow> fcard A \<noteq> 0"
1887
7abd8c1d9f4b Some new lemmas
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1886
diff changeset
   921
  by (lifting memb_card_not_0)
1878
c22947214948 2 more lifted lemmas needed for second representation
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1860
diff changeset
   922
1518
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   923
text {* funion *}
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   924
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   925
lemma funion_simps[simp]:
1860
d3fe17786640 some tuning of proofs
Christian Urban <urbanc@in.tum.de>
parents: 1826
diff changeset
   926
  shows "{||} |\<union>| S = S"
d3fe17786640 some tuning of proofs
Christian Urban <urbanc@in.tum.de>
parents: 1826
diff changeset
   927
  and   "finsert x S |\<union>| T = finsert x (S |\<union>| T)"
1518
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   928
  by (lifting append.simps)
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   929
1887
7abd8c1d9f4b Some new lemmas
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1886
diff changeset
   930
lemma funion_empty[simp]:
7abd8c1d9f4b Some new lemmas
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1886
diff changeset
   931
  shows "S |\<union>| {||} = S"
7abd8c1d9f4b Some new lemmas
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1886
diff changeset
   932
  by (lifting append_Nil2)
7abd8c1d9f4b Some new lemmas
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1886
diff changeset
   933
7abd8c1d9f4b Some new lemmas
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1886
diff changeset
   934
lemma singleton_union_left:
7abd8c1d9f4b Some new lemmas
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1886
diff changeset
   935
  "{|a|} |\<union>| S = finsert a S"
7abd8c1d9f4b Some new lemmas
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1886
diff changeset
   936
  by simp
7abd8c1d9f4b Some new lemmas
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1886
diff changeset
   937
7abd8c1d9f4b Some new lemmas
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1886
diff changeset
   938
lemma singleton_union_right:
7abd8c1d9f4b Some new lemmas
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1886
diff changeset
   939
  "S |\<union>| {|a|} = finsert a S"
1907
7b74cf843942 lattice properties.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1905
diff changeset
   940
  by (subst sup.commute) simp
1887
7abd8c1d9f4b Some new lemmas
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1886
diff changeset
   941
1518
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   942
section {* Induction and Cases rules for finite sets *}
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   943
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   944
lemma fset_strong_cases:
1822
4465723e35e7 more tuning
Christian Urban <urbanc@in.tum.de>
parents: 1821
diff changeset
   945
  "S = {||} \<or> (\<exists>x T. x |\<notin>| T \<and> S = finsert x T)"
1819
63dd459dbc0d Much more in FSet (currently non-working)
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1817
diff changeset
   946
  by (lifting fset_raw_strong_cases)
1518
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   947
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   948
lemma fset_exhaust[case_names fempty finsert, cases type: fset]:
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   949
  shows "\<lbrakk>S = {||} \<Longrightarrow> P; \<And>x S'. S = finsert x S' \<Longrightarrow> P\<rbrakk> \<Longrightarrow> P"
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   950
  by (lifting list.exhaust)
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   951
1533
5f5e99a11f66 A few more theorems in FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1518
diff changeset
   952
lemma fset_induct_weak[case_names fempty finsert]:
1518
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   953
  shows "\<lbrakk>P {||}; \<And>x S. P S \<Longrightarrow> P (finsert x S)\<rbrakk> \<Longrightarrow> P S"
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   954
  by (lifting list.induct)
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   955
1533
5f5e99a11f66 A few more theorems in FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1518
diff changeset
   956
lemma fset_induct[case_names fempty finsert, induct type: fset]:
1518
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   957
  assumes prem1: "P {||}" 
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   958
  and     prem2: "\<And>x S. \<lbrakk>x |\<notin>| S; P S\<rbrakk> \<Longrightarrow> P (finsert x S)"
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   959
  shows "P S"
1533
5f5e99a11f66 A few more theorems in FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1518
diff changeset
   960
proof(induct S rule: fset_induct_weak)
1518
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   961
  case fempty
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   962
  show "P {||}" by (rule prem1)
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   963
next
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   964
  case (finsert x S)
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   965
  have asm: "P S" by fact
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   966
  show "P (finsert x S)"
1938
3641d055b260 Further cleaning of proofs in FSet
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1936
diff changeset
   967
    by (cases "x |\<in>| S") (simp_all add: asm prem2)
1518
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   968
qed
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   969
1533
5f5e99a11f66 A few more theorems in FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1518
diff changeset
   970
lemma fset_induct2:
5f5e99a11f66 A few more theorems in FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1518
diff changeset
   971
  "P {||} {||} \<Longrightarrow>
5f5e99a11f66 A few more theorems in FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1518
diff changeset
   972
  (\<And>x xs. x |\<notin>| xs \<Longrightarrow> P (finsert x xs) {||}) \<Longrightarrow>
5f5e99a11f66 A few more theorems in FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1518
diff changeset
   973
  (\<And>y ys. y |\<notin>| ys \<Longrightarrow> P {||} (finsert y ys)) \<Longrightarrow>
5f5e99a11f66 A few more theorems in FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1518
diff changeset
   974
  (\<And>x xs y ys. \<lbrakk>P xs ys; x |\<notin>| xs; y |\<notin>| ys\<rbrakk> \<Longrightarrow> P (finsert x xs) (finsert y ys)) \<Longrightarrow>
5f5e99a11f66 A few more theorems in FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1518
diff changeset
   975
  P xsa ysa"
5f5e99a11f66 A few more theorems in FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1518
diff changeset
   976
  apply (induct xsa arbitrary: ysa)
5f5e99a11f66 A few more theorems in FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1518
diff changeset
   977
  apply (induct_tac x rule: fset_induct)
5f5e99a11f66 A few more theorems in FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1518
diff changeset
   978
  apply simp_all
5f5e99a11f66 A few more theorems in FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1518
diff changeset
   979
  apply (induct_tac xa rule: fset_induct)
5f5e99a11f66 A few more theorems in FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1518
diff changeset
   980
  apply simp_all
5f5e99a11f66 A few more theorems in FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1518
diff changeset
   981
  done
1518
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   982
1819
63dd459dbc0d Much more in FSet (currently non-working)
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1817
diff changeset
   983
text {* fmap *}
63dd459dbc0d Much more in FSet (currently non-working)
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1817
diff changeset
   984
1533
5f5e99a11f66 A few more theorems in FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1518
diff changeset
   985
lemma fmap_simps[simp]:
5f5e99a11f66 A few more theorems in FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1518
diff changeset
   986
  "fmap (f :: 'a \<Rightarrow> 'b) {||} = {||}"
1822
4465723e35e7 more tuning
Christian Urban <urbanc@in.tum.de>
parents: 1821
diff changeset
   987
  "fmap f (finsert x S) = finsert (f x) (fmap f S)"
1533
5f5e99a11f66 A few more theorems in FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1518
diff changeset
   988
  by (lifting map.simps)
5f5e99a11f66 A few more theorems in FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1518
diff changeset
   989
5f5e99a11f66 A few more theorems in FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1518
diff changeset
   990
lemma fmap_set_image:
1822
4465723e35e7 more tuning
Christian Urban <urbanc@in.tum.de>
parents: 1821
diff changeset
   991
  "fset_to_set (fmap f S) = f ` (fset_to_set S)"
4465723e35e7 more tuning
Christian Urban <urbanc@in.tum.de>
parents: 1821
diff changeset
   992
  by (induct S) (simp_all)
1533
5f5e99a11f66 A few more theorems in FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1518
diff changeset
   993
5f5e99a11f66 A few more theorems in FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1518
diff changeset
   994
lemma inj_fmap_eq_iff:
1822
4465723e35e7 more tuning
Christian Urban <urbanc@in.tum.de>
parents: 1821
diff changeset
   995
  "inj f \<Longrightarrow> (fmap f S = fmap f T) = (S = T)"
1533
5f5e99a11f66 A few more theorems in FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1518
diff changeset
   996
  by (lifting inj_map_eq_iff)
5f5e99a11f66 A few more theorems in FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1518
diff changeset
   997
1822
4465723e35e7 more tuning
Christian Urban <urbanc@in.tum.de>
parents: 1821
diff changeset
   998
lemma fmap_funion: "fmap f (S |\<union>| T) = fmap f S |\<union>| fmap f T"
1813
69fff336dd18 Porting lemmas from Quotient package FSet to new FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1682
diff changeset
   999
  by (lifting map_append)
69fff336dd18 Porting lemmas from Quotient package FSet to new FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1682
diff changeset
  1000
1819
63dd459dbc0d Much more in FSet (currently non-working)
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1817
diff changeset
  1001
lemma fin_funion:
1822
4465723e35e7 more tuning
Christian Urban <urbanc@in.tum.de>
parents: 1821
diff changeset
  1002
  "x |\<in>| S |\<union>| T \<longleftrightarrow> x |\<in>| S \<or> x |\<in>| T"
1819
63dd459dbc0d Much more in FSet (currently non-working)
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1817
diff changeset
  1003
  by (lifting memb_append)
63dd459dbc0d Much more in FSet (currently non-working)
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1817
diff changeset
  1004
63dd459dbc0d Much more in FSet (currently non-working)
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1817
diff changeset
  1005
text {* ffold *}
63dd459dbc0d Much more in FSet (currently non-working)
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1817
diff changeset
  1006
63dd459dbc0d Much more in FSet (currently non-working)
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1817
diff changeset
  1007
lemma ffold_nil: "ffold f z {||} = z"
63dd459dbc0d Much more in FSet (currently non-working)
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1817
diff changeset
  1008
  by (lifting ffold_raw.simps(1)[where 'a="'b" and 'b="'a"])
63dd459dbc0d Much more in FSet (currently non-working)
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1817
diff changeset
  1009
63dd459dbc0d Much more in FSet (currently non-working)
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1817
diff changeset
  1010
lemma ffold_finsert: "ffold f z (finsert a A) =
63dd459dbc0d Much more in FSet (currently non-working)
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1817
diff changeset
  1011
  (if rsp_fold f then if a |\<in>| A then ffold f z A else f a (ffold f z A) else z)"
63dd459dbc0d Much more in FSet (currently non-working)
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1817
diff changeset
  1012
  by (lifting ffold_raw.simps(2)[where 'a="'b" and 'b="'a"])
63dd459dbc0d Much more in FSet (currently non-working)
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1817
diff changeset
  1013
63dd459dbc0d Much more in FSet (currently non-working)
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1817
diff changeset
  1014
lemma fin_commute_ffold:
63dd459dbc0d Much more in FSet (currently non-working)
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1817
diff changeset
  1015
  "\<lbrakk>rsp_fold f; h |\<in>| b\<rbrakk> \<Longrightarrow> ffold f z b = f h (ffold f z (fdelete b h))"
63dd459dbc0d Much more in FSet (currently non-working)
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1817
diff changeset
  1016
  by (lifting memb_commute_ffold_raw)
63dd459dbc0d Much more in FSet (currently non-working)
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1817
diff changeset
  1017
63dd459dbc0d Much more in FSet (currently non-working)
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1817
diff changeset
  1018
text {* fdelete *}
63dd459dbc0d Much more in FSet (currently non-working)
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1817
diff changeset
  1019
1822
4465723e35e7 more tuning
Christian Urban <urbanc@in.tum.de>
parents: 1821
diff changeset
  1020
lemma fin_fdelete: 
4465723e35e7 more tuning
Christian Urban <urbanc@in.tum.de>
parents: 1821
diff changeset
  1021
  shows "x |\<in>| fdelete S y \<longleftrightarrow> x |\<in>| S \<and> x \<noteq> y"
1819
63dd459dbc0d Much more in FSet (currently non-working)
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1817
diff changeset
  1022
  by (lifting memb_delete_raw)
63dd459dbc0d Much more in FSet (currently non-working)
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1817
diff changeset
  1023
1822
4465723e35e7 more tuning
Christian Urban <urbanc@in.tum.de>
parents: 1821
diff changeset
  1024
lemma fin_fdelete_ident: 
4465723e35e7 more tuning
Christian Urban <urbanc@in.tum.de>
parents: 1821
diff changeset
  1025
  shows "x |\<notin>| fdelete S x"
1819
63dd459dbc0d Much more in FSet (currently non-working)
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1817
diff changeset
  1026
  by (lifting memb_delete_raw_ident)
63dd459dbc0d Much more in FSet (currently non-working)
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1817
diff changeset
  1027
1822
4465723e35e7 more tuning
Christian Urban <urbanc@in.tum.de>
parents: 1821
diff changeset
  1028
lemma not_memb_fdelete_ident: 
4465723e35e7 more tuning
Christian Urban <urbanc@in.tum.de>
parents: 1821
diff changeset
  1029
  shows "x |\<notin>| S \<Longrightarrow> fdelete S x = S"
1819
63dd459dbc0d Much more in FSet (currently non-working)
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1817
diff changeset
  1030
  by (lifting not_memb_delete_raw_ident)
63dd459dbc0d Much more in FSet (currently non-working)
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1817
diff changeset
  1031
63dd459dbc0d Much more in FSet (currently non-working)
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1817
diff changeset
  1032
lemma fset_fdelete_cases:
1822
4465723e35e7 more tuning
Christian Urban <urbanc@in.tum.de>
parents: 1821
diff changeset
  1033
  shows "S = {||} \<or> (\<exists>x. x |\<in>| S \<and> S = finsert x (fdelete S x))"
1819
63dd459dbc0d Much more in FSet (currently non-working)
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1817
diff changeset
  1034
  by (lifting fset_raw_delete_raw_cases)
63dd459dbc0d Much more in FSet (currently non-working)
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1817
diff changeset
  1035
63dd459dbc0d Much more in FSet (currently non-working)
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1817
diff changeset
  1036
text {* inter *}
63dd459dbc0d Much more in FSet (currently non-working)
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1817
diff changeset
  1037
1822
4465723e35e7 more tuning
Christian Urban <urbanc@in.tum.de>
parents: 1821
diff changeset
  1038
lemma finter_empty_l: "({||} |\<inter>| S) = {||}"
1819
63dd459dbc0d Much more in FSet (currently non-working)
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1817
diff changeset
  1039
  by (lifting finter_raw.simps(1))
63dd459dbc0d Much more in FSet (currently non-working)
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1817
diff changeset
  1040
1822
4465723e35e7 more tuning
Christian Urban <urbanc@in.tum.de>
parents: 1821
diff changeset
  1041
lemma finter_empty_r: "(S |\<inter>| {||}) = {||}"
1819
63dd459dbc0d Much more in FSet (currently non-working)
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1817
diff changeset
  1042
  by (lifting finter_raw_empty)
63dd459dbc0d Much more in FSet (currently non-working)
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1817
diff changeset
  1043
63dd459dbc0d Much more in FSet (currently non-working)
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1817
diff changeset
  1044
lemma finter_finsert:
1822
4465723e35e7 more tuning
Christian Urban <urbanc@in.tum.de>
parents: 1821
diff changeset
  1045
  "finsert x S |\<inter>| T = (if x |\<in>| T then finsert x (S |\<inter>| T) else S |\<inter>| T)"
1819
63dd459dbc0d Much more in FSet (currently non-working)
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1817
diff changeset
  1046
  by (lifting finter_raw.simps(2))
63dd459dbc0d Much more in FSet (currently non-working)
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1817
diff changeset
  1047
63dd459dbc0d Much more in FSet (currently non-working)
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1817
diff changeset
  1048
lemma fin_finter:
1822
4465723e35e7 more tuning
Christian Urban <urbanc@in.tum.de>
parents: 1821
diff changeset
  1049
  "x |\<in>| (S |\<inter>| T) \<longleftrightarrow> x |\<in>| S \<and> x |\<in>| T"
1819
63dd459dbc0d Much more in FSet (currently non-working)
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1817
diff changeset
  1050
  by (lifting memb_finter_raw)
63dd459dbc0d Much more in FSet (currently non-working)
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1817
diff changeset
  1051
1893
464dd13efff6 Putting FSet in bot typeclass.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1892
diff changeset
  1052
lemma fsubset_finsert:
464dd13efff6 Putting FSet in bot typeclass.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1892
diff changeset
  1053
  "(finsert x xs |\<subseteq>| ys) = (x |\<in>| ys \<and> xs |\<subseteq>| ys)"
464dd13efff6 Putting FSet in bot typeclass.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1892
diff changeset
  1054
  by (lifting sub_list_cons)
464dd13efff6 Putting FSet in bot typeclass.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1892
diff changeset
  1055
1936
99367d481f78 Converted 'thm' to a lemma.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1935
diff changeset
  1056
lemma "xs |\<subseteq>| ys \<equiv> \<forall>x. x |\<in>| xs \<longrightarrow> x |\<in>| ys"
99367d481f78 Converted 'thm' to a lemma.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1935
diff changeset
  1057
  by (lifting sub_list_def[simplified memb_def[symmetric]])
1893
464dd13efff6 Putting FSet in bot typeclass.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1892
diff changeset
  1058
464dd13efff6 Putting FSet in bot typeclass.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1892
diff changeset
  1059
lemma fsubset_fin: "xs |\<subseteq>| ys = (\<forall>x. x |\<in>| xs \<longrightarrow> x |\<in>| ys)"
464dd13efff6 Putting FSet in bot typeclass.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1892
diff changeset
  1060
by (rule meta_eq_to_obj_eq)
464dd13efff6 Putting FSet in bot typeclass.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1892
diff changeset
  1061
   (lifting sub_list_def[simplified memb_def[symmetric]])
464dd13efff6 Putting FSet in bot typeclass.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1892
diff changeset
  1062
1820
de28a91eaca3 Working FSet with additional lemmas.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1819
diff changeset
  1063
lemma expand_fset_eq:
1822
4465723e35e7 more tuning
Christian Urban <urbanc@in.tum.de>
parents: 1821
diff changeset
  1064
  "(S = T) = (\<forall>x. (x |\<in>| S) = (x |\<in>| T))"
1820
de28a91eaca3 Working FSet with additional lemmas.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1819
diff changeset
  1065
  by (lifting list_eq.simps[simplified memb_def[symmetric]])
de28a91eaca3 Working FSet with additional lemmas.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1819
diff changeset
  1066
1888
59f41804b3f8 Alternate list_eq and equivalence
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1887
diff changeset
  1067
(* We cannot write it as "assumes .. shows" since Isabelle changes
59f41804b3f8 Alternate list_eq and equivalence
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1887
diff changeset
  1068
   the quantifiers to schematic variables and reintroduces them in
59f41804b3f8 Alternate list_eq and equivalence
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1887
diff changeset
  1069
   a different order *)
59f41804b3f8 Alternate list_eq and equivalence
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1887
diff changeset
  1070
lemma fset_eq_cases:
59f41804b3f8 Alternate list_eq and equivalence
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1887
diff changeset
  1071
 "\<lbrakk>a1 = a2;
59f41804b3f8 Alternate list_eq and equivalence
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1887
diff changeset
  1072
   \<And>a b xs. \<lbrakk>a1 = finsert a (finsert b xs); a2 = finsert b (finsert a xs)\<rbrakk> \<Longrightarrow> P;
59f41804b3f8 Alternate list_eq and equivalence
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1887
diff changeset
  1073
   \<lbrakk>a1 = {||}; a2 = {||}\<rbrakk> \<Longrightarrow> P; \<And>xs ys. \<lbrakk>a1 = ys; a2 = xs; xs = ys\<rbrakk> \<Longrightarrow> P;
59f41804b3f8 Alternate list_eq and equivalence
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1887
diff changeset
  1074
   \<And>a xs. \<lbrakk>a1 = finsert a (finsert a xs); a2 = finsert a xs\<rbrakk> \<Longrightarrow> P;
59f41804b3f8 Alternate list_eq and equivalence
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1887
diff changeset
  1075
   \<And>xs ys a. \<lbrakk>a1 = finsert a xs; a2 = finsert a ys; xs = ys\<rbrakk> \<Longrightarrow> P;
59f41804b3f8 Alternate list_eq and equivalence
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1887
diff changeset
  1076
   \<And>xs1 xs2 xs3. \<lbrakk>a1 = xs1; a2 = xs3; xs1 = xs2; xs2 = xs3\<rbrakk> \<Longrightarrow> P\<rbrakk>
59f41804b3f8 Alternate list_eq and equivalence
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1887
diff changeset
  1077
  \<Longrightarrow> P"
59f41804b3f8 Alternate list_eq and equivalence
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1887
diff changeset
  1078
  by (lifting list_eq2.cases[simplified list_eq2_equiv[symmetric]])
59f41804b3f8 Alternate list_eq and equivalence
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1887
diff changeset
  1079
59f41804b3f8 Alternate list_eq and equivalence
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1887
diff changeset
  1080
lemma fset_eq_induct:
59f41804b3f8 Alternate list_eq and equivalence
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1887
diff changeset
  1081
  assumes "x1 = x2"
59f41804b3f8 Alternate list_eq and equivalence
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1887
diff changeset
  1082
  and "\<And>a b xs. P (finsert a (finsert b xs)) (finsert b (finsert a xs))"
59f41804b3f8 Alternate list_eq and equivalence
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1887
diff changeset
  1083
  and "P {||} {||}"
59f41804b3f8 Alternate list_eq and equivalence
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1887
diff changeset
  1084
  and "\<And>xs ys. \<lbrakk>xs = ys; P xs ys\<rbrakk> \<Longrightarrow> P ys xs"
59f41804b3f8 Alternate list_eq and equivalence
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1887
diff changeset
  1085
  and "\<And>a xs. P (finsert a (finsert a xs)) (finsert a xs)"
59f41804b3f8 Alternate list_eq and equivalence
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1887
diff changeset
  1086
  and "\<And>xs ys a. \<lbrakk>xs = ys; P xs ys\<rbrakk> \<Longrightarrow> P (finsert a xs) (finsert a ys)"
59f41804b3f8 Alternate list_eq and equivalence
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1887
diff changeset
  1087
  and "\<And>xs1 xs2 xs3. \<lbrakk>xs1 = xs2; P xs1 xs2; xs2 = xs3; P xs2 xs3\<rbrakk> \<Longrightarrow> P xs1 xs3"
59f41804b3f8 Alternate list_eq and equivalence
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1887
diff changeset
  1088
  shows "P x1 x2"
59f41804b3f8 Alternate list_eq and equivalence
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1887
diff changeset
  1089
  using assms
59f41804b3f8 Alternate list_eq and equivalence
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1887
diff changeset
  1090
  by (lifting list_eq2.induct[simplified list_eq2_equiv[symmetric]])
1820
de28a91eaca3 Working FSet with additional lemmas.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1819
diff changeset
  1091
1935
266abc3ee228 Moved working Fset3 properties to FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1927
diff changeset
  1092
text {* concat *}
266abc3ee228 Moved working Fset3 properties to FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1927
diff changeset
  1093
266abc3ee228 Moved working Fset3 properties to FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1927
diff changeset
  1094
lemma fconcat_empty:
266abc3ee228 Moved working Fset3 properties to FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1927
diff changeset
  1095
  shows "fconcat {||} = {||}"
266abc3ee228 Moved working Fset3 properties to FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1927
diff changeset
  1096
  by (lifting concat.simps(1))
266abc3ee228 Moved working Fset3 properties to FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1927
diff changeset
  1097
266abc3ee228 Moved working Fset3 properties to FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1927
diff changeset
  1098
lemma fconcat_insert:
266abc3ee228 Moved working Fset3 properties to FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1927
diff changeset
  1099
  shows "fconcat (finsert x S) = x |\<union>| fconcat S"
266abc3ee228 Moved working Fset3 properties to FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1927
diff changeset
  1100
  by (lifting concat.simps(2))
266abc3ee228 Moved working Fset3 properties to FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1927
diff changeset
  1101
266abc3ee228 Moved working Fset3 properties to FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1927
diff changeset
  1102
lemma "fconcat (xs |\<union>| ys) = fconcat xs |\<union>| fconcat ys"
266abc3ee228 Moved working Fset3 properties to FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1927
diff changeset
  1103
  by (lifting concat_append)
266abc3ee228 Moved working Fset3 properties to FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1927
diff changeset
  1104
1533
5f5e99a11f66 A few more theorems in FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1518
diff changeset
  1105
ML {*
5f5e99a11f66 A few more theorems in FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1518
diff changeset
  1106
fun dest_fsetT (Type ("FSet.fset", [T])) = T
5f5e99a11f66 A few more theorems in FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1518
diff changeset
  1107
  | dest_fsetT T = raise TYPE ("dest_fsetT: fset type expected", [T], []);
5f5e99a11f66 A few more theorems in FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1518
diff changeset
  1108
*}
1518
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
  1109
1682
ae54ce4cde54 Remove list_eq notation.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1533
diff changeset
  1110
no_notation
ae54ce4cde54 Remove list_eq notation.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1533
diff changeset
  1111
  list_eq (infix "\<approx>" 50)
ae54ce4cde54 Remove list_eq notation.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1533
diff changeset
  1112
1518
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
  1113
end