Nominal/FSet.thy
author Christian Urban <urbanc@in.tum.de>
Fri, 15 Oct 2010 23:45:54 +0100
changeset 2539 a8f5611dbd65
parent 2538 c9deccd12476
child 2540 135ac0fb2686
permissions -rw-r--r--
more cleaning
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2084
72b777cc5479 Synchronize FSet with repository
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1952
diff changeset
     1
(*  Title:      HOL/Quotient_Examples/FSet.thy
72b777cc5479 Synchronize FSet with repository
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1952
diff changeset
     2
    Author:     Cezary Kaliszyk, TU Munich
72b777cc5479 Synchronize FSet with repository
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1952
diff changeset
     3
    Author:     Christian Urban, TU Munich
1823
91ba55dba5e0 added header and more tuning
Christian Urban <urbanc@in.tum.de>
parents: 1822
diff changeset
     4
2533
767161329839 further cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2532
diff changeset
     5
    Type of finite sets.
1823
91ba55dba5e0 added header and more tuning
Christian Urban <urbanc@in.tum.de>
parents: 1822
diff changeset
     6
*)
2084
72b777cc5479 Synchronize FSet with repository
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1952
diff changeset
     7
1518
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
     8
theory FSet
2528
9bde8a508594 Partially merging changes from Isabelle
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2525
diff changeset
     9
imports Quotient_List
1518
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    10
begin
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    11
2533
767161329839 further cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2532
diff changeset
    12
text {* Definiton of the list equivalence relation *}
1909
9972dc5bd7ad Reorder FSet
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1907
diff changeset
    13
1518
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    14
fun
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    15
  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
    16
where
2524
693562f03eee major reorganisation of fset (renamed fset_to_set to fset, changed the definition of list_eq and fcard_raw)
Christian Urban <urbanc@in.tum.de>
parents: 2479
diff changeset
    17
  "list_eq xs ys = (set xs = set ys)"
1518
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    18
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    19
lemma list_eq_equivp:
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    20
  shows "equivp list_eq"
1909
9972dc5bd7ad Reorder FSet
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1907
diff changeset
    21
  unfolding equivp_reflp_symp_transp
1889
6c5b5ec53a0b sub_list definition and respects
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1888
diff changeset
    22
  unfolding reflp_def symp_def transp_def
6c5b5ec53a0b sub_list definition and respects
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1888
diff changeset
    23
  by auto
6c5b5ec53a0b sub_list definition and respects
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1888
diff changeset
    24
2533
767161329839 further cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2532
diff changeset
    25
text {* Fset type *}
767161329839 further cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2532
diff changeset
    26
1909
9972dc5bd7ad Reorder FSet
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1907
diff changeset
    27
quotient_type
9972dc5bd7ad Reorder FSet
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1907
diff changeset
    28
  'a fset = "'a list" / "list_eq"
9972dc5bd7ad Reorder FSet
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1907
diff changeset
    29
  by (rule list_eq_equivp)
9972dc5bd7ad Reorder FSet
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1907
diff changeset
    30
2533
767161329839 further cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2532
diff changeset
    31
text {* 
2538
c9deccd12476 further tuning
Christian Urban <urbanc@in.tum.de>
parents: 2537
diff changeset
    32
  Definitions of membership, sublist, cardinality, intersection, 
c9deccd12476 further tuning
Christian Urban <urbanc@in.tum.de>
parents: 2537
diff changeset
    33
  difference and respectful fold over lists
2372
Christian Urban <urbanc@in.tum.de>
parents: 2371
diff changeset
    34
*}
1909
9972dc5bd7ad Reorder FSet
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1907
diff changeset
    35
1889
6c5b5ec53a0b sub_list definition and respects
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1888
diff changeset
    36
definition
6c5b5ec53a0b sub_list definition and respects
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1888
diff changeset
    37
  "memb x xs \<equiv> x \<in> set xs"
6c5b5ec53a0b sub_list definition and respects
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1888
diff changeset
    38
6c5b5ec53a0b sub_list definition and respects
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1888
diff changeset
    39
definition
2524
693562f03eee major reorganisation of fset (renamed fset_to_set to fset, changed the definition of list_eq and fcard_raw)
Christian Urban <urbanc@in.tum.de>
parents: 2479
diff changeset
    40
  "sub_list xs ys \<equiv> set xs \<subseteq> set ys"
1889
6c5b5ec53a0b sub_list definition and respects
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1888
diff changeset
    41
2524
693562f03eee major reorganisation of fset (renamed fset_to_set to fset, changed the definition of list_eq and fcard_raw)
Christian Urban <urbanc@in.tum.de>
parents: 2479
diff changeset
    42
definition
2536
98e84b56543f renamed fcard_raw to card_list
Christian Urban <urbanc@in.tum.de>
parents: 2534
diff changeset
    43
  "card_list xs = card (set xs)"
1518
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    44
2538
c9deccd12476 further tuning
Christian Urban <urbanc@in.tum.de>
parents: 2537
diff changeset
    45
definition
c9deccd12476 further tuning
Christian Urban <urbanc@in.tum.de>
parents: 2537
diff changeset
    46
  "inter_list xs ys = [x \<leftarrow> xs. x \<in> set xs \<and> x \<in> set ys]"
2534
f99578469d08 Further reorganisation and cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2533
diff changeset
    47
f99578469d08 Further reorganisation and cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2533
diff changeset
    48
definition
2537
d73fa7a3e04b renamed fminus_raw to diff_list
Christian Urban <urbanc@in.tum.de>
parents: 2536
diff changeset
    49
  "diff_list xs ys \<equiv> [x \<leftarrow> xs. x\<notin>set ys]"
2534
f99578469d08 Further reorganisation and cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2533
diff changeset
    50
1909
9972dc5bd7ad Reorder FSet
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1907
diff changeset
    51
definition
9972dc5bd7ad Reorder FSet
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1907
diff changeset
    52
  rsp_fold
9972dc5bd7ad Reorder FSet
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1907
diff changeset
    53
where
2538
c9deccd12476 further tuning
Christian Urban <urbanc@in.tum.de>
parents: 2537
diff changeset
    54
  "rsp_fold f \<equiv> \<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
    55
1909
9972dc5bd7ad Reorder FSet
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1907
diff changeset
    56
primrec
2539
a8f5611dbd65 more cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2538
diff changeset
    57
  ffold_list :: "('a \<Rightarrow> 'b \<Rightarrow> 'b) \<Rightarrow> 'b \<Rightarrow> 'a list \<Rightarrow> 'b"
1909
9972dc5bd7ad Reorder FSet
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1907
diff changeset
    58
where
2539
a8f5611dbd65 more cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2538
diff changeset
    59
  "ffold_list f z [] = z"
a8f5611dbd65 more cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2538
diff changeset
    60
| "ffold_list f z (a # xs) =
1909
9972dc5bd7ad Reorder FSet
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1907
diff changeset
    61
     (if (rsp_fold f) then
2539
a8f5611dbd65 more cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2538
diff changeset
    62
       if a \<in> set xs then ffold_list f z xs
a8f5611dbd65 more cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2538
diff changeset
    63
       else f a (ffold_list f z xs)
1909
9972dc5bd7ad Reorder FSet
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1907
diff changeset
    64
     else z)"
9972dc5bd7ad Reorder FSet
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1907
diff changeset
    65
2533
767161329839 further cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2532
diff changeset
    66
767161329839 further cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2532
diff changeset
    67
section {* Quotient composition lemmas *}
1935
266abc3ee228 Moved working Fset3 properties to FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1927
diff changeset
    68
2326
b51532dd5689 Changes for PER and list_all2 committed to Isabelle
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2278
diff changeset
    69
lemma list_all2_refl1:
b51532dd5689 Changes for PER and list_all2 committed to Isabelle
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2278
diff changeset
    70
  shows "(list_all2 op \<approx>) r r"
b51532dd5689 Changes for PER and list_all2 committed to Isabelle
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2278
diff changeset
    71
  by (rule list_all2_refl) (metis equivp_def fset_equivp)
1938
3641d055b260 Further cleaning of proofs in FSet
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1936
diff changeset
    72
1935
266abc3ee228 Moved working Fset3 properties to FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1927
diff changeset
    73
lemma compose_list_refl:
2326
b51532dd5689 Changes for PER and list_all2 committed to Isabelle
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2278
diff changeset
    74
  shows "(list_all2 op \<approx> OOO op \<approx>) r r"
1935
266abc3ee228 Moved working Fset3 properties to FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1927
diff changeset
    75
proof
2084
72b777cc5479 Synchronize FSet with repository
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1952
diff changeset
    76
  have *: "r \<approx> r" by (rule equivp_reflp[OF fset_equivp])
2326
b51532dd5689 Changes for PER and list_all2 committed to Isabelle
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2278
diff changeset
    77
  show "list_all2 op \<approx> r r" by (rule list_all2_refl1)
b51532dd5689 Changes for PER and list_all2 committed to Isabelle
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2278
diff changeset
    78
  with * show "(op \<approx> OO list_all2 op \<approx>) r r" ..
1935
266abc3ee228 Moved working Fset3 properties to FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1927
diff changeset
    79
qed
266abc3ee228 Moved working Fset3 properties to FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1927
diff changeset
    80
266abc3ee228 Moved working Fset3 properties to FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1927
diff changeset
    81
lemma Quotient_fset_list:
2326
b51532dd5689 Changes for PER and list_all2 committed to Isabelle
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2278
diff changeset
    82
  shows "Quotient (list_all2 op \<approx>) (map abs_fset) (map rep_fset)"
1935
266abc3ee228 Moved working Fset3 properties to FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1927
diff changeset
    83
  by (fact list_quotient[OF Quotient_fset])
266abc3ee228 Moved working Fset3 properties to FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1927
diff changeset
    84
266abc3ee228 Moved working Fset3 properties to FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1927
diff changeset
    85
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
    86
  unfolding list_eq.simps
2524
693562f03eee major reorganisation of fset (renamed fset_to_set to fset, changed the definition of list_eq and fcard_raw)
Christian Urban <urbanc@in.tum.de>
parents: 2479
diff changeset
    87
  by (simp only: set_map)
1935
266abc3ee228 Moved working Fset3 properties to FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1927
diff changeset
    88
266abc3ee228 Moved working Fset3 properties to FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1927
diff changeset
    89
lemma quotient_compose_list[quot_thm]:
2326
b51532dd5689 Changes for PER and list_all2 committed to Isabelle
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2278
diff changeset
    90
  shows  "Quotient ((list_all2 op \<approx>) OOO (op \<approx>))
1935
266abc3ee228 Moved working Fset3 properties to FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1927
diff changeset
    91
    (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
    92
  unfolding Quotient_def comp_def
266abc3ee228 Moved working Fset3 properties to FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1927
diff changeset
    93
proof (intro conjI allI)
266abc3ee228 Moved working Fset3 properties to FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1927
diff changeset
    94
  fix a r s
266abc3ee228 Moved working Fset3 properties to FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1927
diff changeset
    95
  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
    96
    by (simp add: abs_o_rep[OF Quotient_fset] Quotient_abs_rep[OF Quotient_fset] map_id)
2326
b51532dd5689 Changes for PER and list_all2 committed to Isabelle
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2278
diff changeset
    97
  have b: "list_all2 op \<approx> (map rep_fset (rep_fset a)) (map rep_fset (rep_fset a))"
b51532dd5689 Changes for PER and list_all2 committed to Isabelle
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2278
diff changeset
    98
    by (rule list_all2_refl1)
b51532dd5689 Changes for PER and list_all2 committed to Isabelle
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2278
diff changeset
    99
  have c: "(op \<approx> OO list_all2 op \<approx>) (map rep_fset (rep_fset a)) (map rep_fset (rep_fset a))"
1935
266abc3ee228 Moved working Fset3 properties to FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1927
diff changeset
   100
    by (rule, rule equivp_reflp[OF fset_equivp]) (rule b)
2326
b51532dd5689 Changes for PER and list_all2 committed to Isabelle
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2278
diff changeset
   101
  show "(list_all2 op \<approx> OOO op \<approx>) (map rep_fset (rep_fset a)) (map rep_fset (rep_fset a))"
b51532dd5689 Changes for PER and list_all2 committed to Isabelle
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2278
diff changeset
   102
    by (rule, rule list_all2_refl1) (rule c)
b51532dd5689 Changes for PER and list_all2 committed to Isabelle
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2278
diff changeset
   103
  show "(list_all2 op \<approx> OOO op \<approx>) r s = ((list_all2 op \<approx> OOO op \<approx>) r r \<and>
b51532dd5689 Changes for PER and list_all2 committed to Isabelle
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2278
diff changeset
   104
        (list_all2 op \<approx> OOO op \<approx>) s s \<and> abs_fset (map abs_fset r) = abs_fset (map abs_fset s))"
1935
266abc3ee228 Moved working Fset3 properties to FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1927
diff changeset
   105
  proof (intro iffI conjI)
2326
b51532dd5689 Changes for PER and list_all2 committed to Isabelle
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2278
diff changeset
   106
    show "(list_all2 op \<approx> OOO op \<approx>) r r" by (rule compose_list_refl)
b51532dd5689 Changes for PER and list_all2 committed to Isabelle
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2278
diff changeset
   107
    show "(list_all2 op \<approx> OOO op \<approx>) s s" by (rule compose_list_refl)
1935
266abc3ee228 Moved working Fset3 properties to FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1927
diff changeset
   108
  next
2326
b51532dd5689 Changes for PER and list_all2 committed to Isabelle
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2278
diff changeset
   109
    assume a: "(list_all2 op \<approx> OOO op \<approx>) r s"
2084
72b777cc5479 Synchronize FSet with repository
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1952
diff changeset
   110
    then have b: "map abs_fset r \<approx> map abs_fset s"
72b777cc5479 Synchronize FSet with repository
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1952
diff changeset
   111
    proof (elim pred_compE)
1935
266abc3ee228 Moved working Fset3 properties to FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1927
diff changeset
   112
      fix b ba
2326
b51532dd5689 Changes for PER and list_all2 committed to Isabelle
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2278
diff changeset
   113
      assume c: "list_all2 op \<approx> r b"
1935
266abc3ee228 Moved working Fset3 properties to FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1927
diff changeset
   114
      assume d: "b \<approx> ba"
2326
b51532dd5689 Changes for PER and list_all2 committed to Isabelle
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2278
diff changeset
   115
      assume e: "list_all2 op \<approx> ba s"
1935
266abc3ee228 Moved working Fset3 properties to FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1927
diff changeset
   116
      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
   117
        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
   118
      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
   119
        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
   120
      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
   121
      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
   122
    qed
266abc3ee228 Moved working Fset3 properties to FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1927
diff changeset
   123
    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
   124
      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
   125
  next
2326
b51532dd5689 Changes for PER and list_all2 committed to Isabelle
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2278
diff changeset
   126
    assume a: "(list_all2 op \<approx> OOO op \<approx>) r r \<and> (list_all2 op \<approx> OOO op \<approx>) s s
1935
266abc3ee228 Moved working Fset3 properties to FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1927
diff changeset
   127
      \<and> abs_fset (map abs_fset r) = abs_fset (map abs_fset s)"
2326
b51532dd5689 Changes for PER and list_all2 committed to Isabelle
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2278
diff changeset
   128
    then have s: "(list_all2 op \<approx> OOO op \<approx>) s s" by simp
1935
266abc3ee228 Moved working Fset3 properties to FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1927
diff changeset
   129
    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
   130
      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
   131
    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
   132
      by (rule map_rel_cong[OF d])
2326
b51532dd5689 Changes for PER and list_all2 committed to Isabelle
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2278
diff changeset
   133
    have y: "list_all2 op \<approx> (map rep_fset (map abs_fset s)) s"
b51532dd5689 Changes for PER and list_all2 committed to Isabelle
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2278
diff changeset
   134
      by (fact rep_abs_rsp_left[OF Quotient_fset_list, OF list_all2_refl1[of s]])
b51532dd5689 Changes for PER and list_all2 committed to Isabelle
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2278
diff changeset
   135
    have c: "(op \<approx> OO list_all2 op \<approx>) (map rep_fset (map abs_fset r)) s"
1935
266abc3ee228 Moved working Fset3 properties to FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1927
diff changeset
   136
      by (rule pred_compI) (rule b, rule y)
2326
b51532dd5689 Changes for PER and list_all2 committed to Isabelle
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2278
diff changeset
   137
    have z: "list_all2 op \<approx> r (map rep_fset (map abs_fset r))"
b51532dd5689 Changes for PER and list_all2 committed to Isabelle
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2278
diff changeset
   138
      by (fact rep_abs_rsp[OF Quotient_fset_list, OF list_all2_refl1[of r]])
b51532dd5689 Changes for PER and list_all2 committed to Isabelle
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2278
diff changeset
   139
    then show "(list_all2 op \<approx> OOO op \<approx>) r s"
1935
266abc3ee228 Moved working Fset3 properties to FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1927
diff changeset
   140
      using a c pred_compI by simp
266abc3ee228 Moved working Fset3 properties to FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1927
diff changeset
   141
  qed
266abc3ee228 Moved working Fset3 properties to FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1927
diff changeset
   142
qed
266abc3ee228 Moved working Fset3 properties to FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1927
diff changeset
   143
2525
c848f93807b9 deleted some unused lemmas
Christian Urban <urbanc@in.tum.de>
parents: 2524
diff changeset
   144
2538
c9deccd12476 further tuning
Christian Urban <urbanc@in.tum.de>
parents: 2537
diff changeset
   145
subsection {* Respectfulness lemmas for list operations *}
1893
464dd13efff6 Putting FSet in bot typeclass.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1892
diff changeset
   146
2538
c9deccd12476 further tuning
Christian Urban <urbanc@in.tum.de>
parents: 2537
diff changeset
   147
lemma list_equiv_rsp [quot_respect]:
c9deccd12476 further tuning
Christian Urban <urbanc@in.tum.de>
parents: 2537
diff changeset
   148
  shows "(op \<approx> ===> op \<approx> ===> op =) op \<approx> op \<approx>"
c9deccd12476 further tuning
Christian Urban <urbanc@in.tum.de>
parents: 2537
diff changeset
   149
  by auto
c9deccd12476 further tuning
Christian Urban <urbanc@in.tum.de>
parents: 2537
diff changeset
   150
c9deccd12476 further tuning
Christian Urban <urbanc@in.tum.de>
parents: 2537
diff changeset
   151
lemma append_rsp [quot_respect]:
2524
693562f03eee major reorganisation of fset (renamed fset_to_set to fset, changed the definition of list_eq and fcard_raw)
Christian Urban <urbanc@in.tum.de>
parents: 2479
diff changeset
   152
  shows "(op \<approx> ===> op \<approx> ===> op \<approx>) append append"
2533
767161329839 further cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2532
diff changeset
   153
  by simp
1895
91d67240c9c1 FSet is a semi-lattice
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1893
diff changeset
   154
2538
c9deccd12476 further tuning
Christian Urban <urbanc@in.tum.de>
parents: 2537
diff changeset
   155
lemma sub_list_rsp [quot_respect]:
1909
9972dc5bd7ad Reorder FSet
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1907
diff changeset
   156
  shows "(op \<approx> ===> op \<approx> ===> op =) sub_list sub_list"
9972dc5bd7ad Reorder FSet
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1907
diff changeset
   157
  by (auto simp add: sub_list_def)
9972dc5bd7ad Reorder FSet
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1907
diff changeset
   158
2538
c9deccd12476 further tuning
Christian Urban <urbanc@in.tum.de>
parents: 2537
diff changeset
   159
lemma memb_rsp [quot_respect]:
1909
9972dc5bd7ad Reorder FSet
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1907
diff changeset
   160
  shows "(op = ===> op \<approx> ===> op =) memb memb"
9972dc5bd7ad Reorder FSet
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1907
diff changeset
   161
  by (auto simp add: memb_def)
9972dc5bd7ad Reorder FSet
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1907
diff changeset
   162
2538
c9deccd12476 further tuning
Christian Urban <urbanc@in.tum.de>
parents: 2537
diff changeset
   163
lemma nil_rsp [quot_respect]:
2525
c848f93807b9 deleted some unused lemmas
Christian Urban <urbanc@in.tum.de>
parents: 2524
diff changeset
   164
  shows "(op \<approx>) Nil Nil"
1909
9972dc5bd7ad Reorder FSet
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1907
diff changeset
   165
  by simp
9972dc5bd7ad Reorder FSet
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1907
diff changeset
   166
2538
c9deccd12476 further tuning
Christian Urban <urbanc@in.tum.de>
parents: 2537
diff changeset
   167
lemma cons_rsp [quot_respect]:
2524
693562f03eee major reorganisation of fset (renamed fset_to_set to fset, changed the definition of list_eq and fcard_raw)
Christian Urban <urbanc@in.tum.de>
parents: 2479
diff changeset
   168
  shows "(op = ===> op \<approx> ===> op \<approx>) Cons Cons"
1909
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
2538
c9deccd12476 further tuning
Christian Urban <urbanc@in.tum.de>
parents: 2537
diff changeset
   171
lemma map_rsp [quot_respect]:
1909
9972dc5bd7ad Reorder FSet
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1907
diff changeset
   172
  shows "(op = ===> op \<approx> ===> op \<approx>) map map"
9972dc5bd7ad Reorder FSet
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1907
diff changeset
   173
  by auto
9972dc5bd7ad Reorder FSet
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1907
diff changeset
   174
2538
c9deccd12476 further tuning
Christian Urban <urbanc@in.tum.de>
parents: 2537
diff changeset
   175
lemma set_rsp [quot_respect]:
1909
9972dc5bd7ad Reorder FSet
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1907
diff changeset
   176
  "(op \<approx> ===> op =) set set"
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
2538
c9deccd12476 further tuning
Christian Urban <urbanc@in.tum.de>
parents: 2537
diff changeset
   179
lemma inter_list_rsp [quot_respect]:
c9deccd12476 further tuning
Christian Urban <urbanc@in.tum.de>
parents: 2537
diff changeset
   180
  shows "(op \<approx> ===> op \<approx> ===> op \<approx>) inter_list inter_list"
c9deccd12476 further tuning
Christian Urban <urbanc@in.tum.de>
parents: 2537
diff changeset
   181
  by (simp add: inter_list_def)
1909
9972dc5bd7ad Reorder FSet
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1907
diff changeset
   182
2538
c9deccd12476 further tuning
Christian Urban <urbanc@in.tum.de>
parents: 2537
diff changeset
   183
lemma removeAll_rsp [quot_respect]:
2525
c848f93807b9 deleted some unused lemmas
Christian Urban <urbanc@in.tum.de>
parents: 2524
diff changeset
   184
  shows "(op = ===> op \<approx> ===> op \<approx>) removeAll removeAll"
c848f93807b9 deleted some unused lemmas
Christian Urban <urbanc@in.tum.de>
parents: 2524
diff changeset
   185
  by simp
c848f93807b9 deleted some unused lemmas
Christian Urban <urbanc@in.tum.de>
parents: 2524
diff changeset
   186
2538
c9deccd12476 further tuning
Christian Urban <urbanc@in.tum.de>
parents: 2537
diff changeset
   187
lemma diff_list_rsp [quot_respect]:
2537
d73fa7a3e04b renamed fminus_raw to diff_list
Christian Urban <urbanc@in.tum.de>
parents: 2536
diff changeset
   188
  shows "(op \<approx> ===> op \<approx> ===> op \<approx>) diff_list diff_list"
2538
c9deccd12476 further tuning
Christian Urban <urbanc@in.tum.de>
parents: 2537
diff changeset
   189
  by (simp add: diff_list_def)
2525
c848f93807b9 deleted some unused lemmas
Christian Urban <urbanc@in.tum.de>
parents: 2524
diff changeset
   190
2538
c9deccd12476 further tuning
Christian Urban <urbanc@in.tum.de>
parents: 2537
diff changeset
   191
lemma card_list_rsp [quot_respect]:
2536
98e84b56543f renamed fcard_raw to card_list
Christian Urban <urbanc@in.tum.de>
parents: 2534
diff changeset
   192
  shows "(op \<approx> ===> op =) card_list card_list"
98e84b56543f renamed fcard_raw to card_list
Christian Urban <urbanc@in.tum.de>
parents: 2534
diff changeset
   193
  by (simp add: card_list_def)
2525
c848f93807b9 deleted some unused lemmas
Christian Urban <urbanc@in.tum.de>
parents: 2524
diff changeset
   194
2538
c9deccd12476 further tuning
Christian Urban <urbanc@in.tum.de>
parents: 2537
diff changeset
   195
lemma filter_rsp [quot_respect]:
c9deccd12476 further tuning
Christian Urban <urbanc@in.tum.de>
parents: 2537
diff changeset
   196
  shows "(op = ===> op \<approx> ===> op \<approx>) filter filter"
c9deccd12476 further tuning
Christian Urban <urbanc@in.tum.de>
parents: 2537
diff changeset
   197
  by simp
2525
c848f93807b9 deleted some unused lemmas
Christian Urban <urbanc@in.tum.de>
parents: 2524
diff changeset
   198
2539
a8f5611dbd65 more cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2538
diff changeset
   199
lemma memb_commute_ffold_list:
a8f5611dbd65 more cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2538
diff changeset
   200
  "rsp_fold f \<Longrightarrow> h \<in> set b \<Longrightarrow> ffold_list f z b = f h (ffold_list f z (removeAll h b))"
1909
9972dc5bd7ad Reorder FSet
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1907
diff changeset
   201
  apply (induct b)
2524
693562f03eee major reorganisation of fset (renamed fset_to_set to fset, changed the definition of list_eq and fcard_raw)
Christian Urban <urbanc@in.tum.de>
parents: 2479
diff changeset
   202
  apply (auto simp add: rsp_fold_def)
1909
9972dc5bd7ad Reorder FSet
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1907
diff changeset
   203
  done
9972dc5bd7ad Reorder FSet
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1907
diff changeset
   204
2539
a8f5611dbd65 more cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2538
diff changeset
   205
lemma ffold_list_rsp_pre:
a8f5611dbd65 more cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2538
diff changeset
   206
  "set a = set b \<Longrightarrow> ffold_list f z a = ffold_list f z b"
1909
9972dc5bd7ad Reorder FSet
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1907
diff changeset
   207
  apply (induct a arbitrary: b)
9972dc5bd7ad Reorder FSet
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1907
diff changeset
   208
  apply (simp)
2524
693562f03eee major reorganisation of fset (renamed fset_to_set to fset, changed the definition of list_eq and fcard_raw)
Christian Urban <urbanc@in.tum.de>
parents: 2479
diff changeset
   209
  apply (simp (no_asm_use))
1909
9972dc5bd7ad Reorder FSet
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1907
diff changeset
   210
  apply (rule conjI)
9972dc5bd7ad Reorder FSet
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1907
diff changeset
   211
  apply (rule_tac [!] impI)
9972dc5bd7ad Reorder FSet
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1907
diff changeset
   212
  apply (rule_tac [!] conjI)
9972dc5bd7ad Reorder FSet
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1907
diff changeset
   213
  apply (rule_tac [!] impI)
2524
693562f03eee major reorganisation of fset (renamed fset_to_set to fset, changed the definition of list_eq and fcard_raw)
Christian Urban <urbanc@in.tum.de>
parents: 2479
diff changeset
   214
  apply (metis insert_absorb)
2539
a8f5611dbd65 more cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2538
diff changeset
   215
  apply (metis List.insert_def List.set.simps(2) List.set_insert ffold_list.simps(2))
a8f5611dbd65 more cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2538
diff changeset
   216
  apply (metis Diff_insert_absorb insertI1 memb_commute_ffold_list set_removeAll)
2524
693562f03eee major reorganisation of fset (renamed fset_to_set to fset, changed the definition of list_eq and fcard_raw)
Christian Urban <urbanc@in.tum.de>
parents: 2479
diff changeset
   217
  apply(drule_tac x="removeAll a1 b" in meta_spec)
693562f03eee major reorganisation of fset (renamed fset_to_set to fset, changed the definition of list_eq and fcard_raw)
Christian Urban <urbanc@in.tum.de>
parents: 2479
diff changeset
   218
  apply(auto)
693562f03eee major reorganisation of fset (renamed fset_to_set to fset, changed the definition of list_eq and fcard_raw)
Christian Urban <urbanc@in.tum.de>
parents: 2479
diff changeset
   219
  apply(drule meta_mp)
693562f03eee major reorganisation of fset (renamed fset_to_set to fset, changed the definition of list_eq and fcard_raw)
Christian Urban <urbanc@in.tum.de>
parents: 2479
diff changeset
   220
  apply(blast)
2539
a8f5611dbd65 more cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2538
diff changeset
   221
  by (metis List.set.simps(2) emptyE ffold_list.simps(2) in_listsp_conv_set listsp.simps mem_def)
1909
9972dc5bd7ad Reorder FSet
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1907
diff changeset
   222
2539
a8f5611dbd65 more cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2538
diff changeset
   223
lemma ffold_list_rsp [quot_respect]:
a8f5611dbd65 more cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2538
diff changeset
   224
  shows "(op = ===> op = ===> op \<approx> ===> op =) ffold_list ffold_list"
2524
693562f03eee major reorganisation of fset (renamed fset_to_set to fset, changed the definition of list_eq and fcard_raw)
Christian Urban <urbanc@in.tum.de>
parents: 2479
diff changeset
   225
  unfolding fun_rel_def
2539
a8f5611dbd65 more cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2538
diff changeset
   226
  by(auto intro: ffold_list_rsp_pre)
1909
9972dc5bd7ad Reorder FSet
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1907
diff changeset
   227
1935
266abc3ee228 Moved working Fset3 properties to FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1927
diff changeset
   228
lemma concat_rsp_pre:
2326
b51532dd5689 Changes for PER and list_all2 committed to Isabelle
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2278
diff changeset
   229
  assumes a: "list_all2 op \<approx> x x'"
1935
266abc3ee228 Moved working Fset3 properties to FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1927
diff changeset
   230
  and     b: "x' \<approx> y'"
2326
b51532dd5689 Changes for PER and list_all2 committed to Isabelle
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2278
diff changeset
   231
  and     c: "list_all2 op \<approx> y' y"
1935
266abc3ee228 Moved working Fset3 properties to FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1927
diff changeset
   232
  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
   233
  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
   234
proof -
266abc3ee228 Moved working Fset3 properties to FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1927
diff changeset
   235
  obtain xb where e: "xb \<in> set x" and f: "xa \<in> set xb" using d by auto
2326
b51532dd5689 Changes for PER and list_all2 committed to Isabelle
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2278
diff changeset
   236
  have "\<exists>y. y \<in> set x' \<and> xb \<approx> y" by (rule list_all2_find_element[OF e a])
1935
266abc3ee228 Moved working Fset3 properties to FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1927
diff changeset
   237
  then obtain ya where h: "ya \<in> set x'" and i: "xb \<approx> ya" by auto
2084
72b777cc5479 Synchronize FSet with repository
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1952
diff changeset
   238
  have "ya \<in> set y'" using b h by simp
2326
b51532dd5689 Changes for PER and list_all2 committed to Isabelle
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2278
diff changeset
   239
  then have "\<exists>yb. yb \<in> set y \<and> ya \<approx> yb" using c by (rule list_all2_find_element)
1935
266abc3ee228 Moved working Fset3 properties to FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1927
diff changeset
   240
  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
   241
qed
266abc3ee228 Moved working Fset3 properties to FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1927
diff changeset
   242
2538
c9deccd12476 further tuning
Christian Urban <urbanc@in.tum.de>
parents: 2537
diff changeset
   243
lemma concat_rsp [quot_respect]:
2326
b51532dd5689 Changes for PER and list_all2 committed to Isabelle
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2278
diff changeset
   244
  shows "(list_all2 op \<approx> OOO op \<approx> ===> op \<approx>) concat concat"
1935
266abc3ee228 Moved working Fset3 properties to FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1927
diff changeset
   245
proof (rule fun_relI, elim pred_compE)
266abc3ee228 Moved working Fset3 properties to FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1927
diff changeset
   246
  fix a b ba bb
2326
b51532dd5689 Changes for PER and list_all2 committed to Isabelle
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2278
diff changeset
   247
  assume a: "list_all2 op \<approx> a ba"
1935
266abc3ee228 Moved working Fset3 properties to FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1927
diff changeset
   248
  assume b: "ba \<approx> bb"
2326
b51532dd5689 Changes for PER and list_all2 committed to Isabelle
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2278
diff changeset
   249
  assume c: "list_all2 op \<approx> bb b"
2524
693562f03eee major reorganisation of fset (renamed fset_to_set to fset, changed the definition of list_eq and fcard_raw)
Christian Urban <urbanc@in.tum.de>
parents: 2479
diff changeset
   250
  have "\<forall>x. (\<exists>xa\<in>set a. x \<in> set xa) = (\<exists>xa\<in>set b. x \<in> set xa)" 
693562f03eee major reorganisation of fset (renamed fset_to_set to fset, changed the definition of list_eq and fcard_raw)
Christian Urban <urbanc@in.tum.de>
parents: 2479
diff changeset
   251
  proof
1935
266abc3ee228 Moved working Fset3 properties to FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1927
diff changeset
   252
    fix x
2524
693562f03eee major reorganisation of fset (renamed fset_to_set to fset, changed the definition of list_eq and fcard_raw)
Christian Urban <urbanc@in.tum.de>
parents: 2479
diff changeset
   253
    show "(\<exists>xa\<in>set a. x \<in> set xa) = (\<exists>xa\<in>set b. x \<in> set xa)" 
693562f03eee major reorganisation of fset (renamed fset_to_set to fset, changed the definition of list_eq and fcard_raw)
Christian Urban <urbanc@in.tum.de>
parents: 2479
diff changeset
   254
    proof
1935
266abc3ee228 Moved working Fset3 properties to FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1927
diff changeset
   255
      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
   256
      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
   257
    next
266abc3ee228 Moved working Fset3 properties to FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1927
diff changeset
   258
      assume e: "\<exists>xa\<in>set b. x \<in> set xa"
2326
b51532dd5689 Changes for PER and list_all2 committed to Isabelle
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2278
diff changeset
   259
      have a': "list_all2 op \<approx> ba a" by (rule list_all2_symp[OF list_eq_equivp, OF a])
1935
266abc3ee228 Moved working Fset3 properties to FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1927
diff changeset
   260
      have b': "bb \<approx> ba" by (rule equivp_symp[OF list_eq_equivp, OF b])
2326
b51532dd5689 Changes for PER and list_all2 committed to Isabelle
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2278
diff changeset
   261
      have c': "list_all2 op \<approx> b bb" by (rule list_all2_symp[OF list_eq_equivp, OF c])
1935
266abc3ee228 Moved working Fset3 properties to FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1927
diff changeset
   262
      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
   263
    qed
266abc3ee228 Moved working Fset3 properties to FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1927
diff changeset
   264
  qed
2524
693562f03eee major reorganisation of fset (renamed fset_to_set to fset, changed the definition of list_eq and fcard_raw)
Christian Urban <urbanc@in.tum.de>
parents: 2479
diff changeset
   265
  then show "concat a \<approx> concat b" by auto
1935
266abc3ee228 Moved working Fset3 properties to FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1927
diff changeset
   266
qed
266abc3ee228 Moved working Fset3 properties to FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1927
diff changeset
   267
2084
72b777cc5479 Synchronize FSet with repository
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1952
diff changeset
   268
2539
a8f5611dbd65 more cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2538
diff changeset
   269
a8f5611dbd65 more cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2538
diff changeset
   270
section {* Quotient definitions for fsets *}
a8f5611dbd65 more cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2538
diff changeset
   271
a8f5611dbd65 more cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2538
diff changeset
   272
2538
c9deccd12476 further tuning
Christian Urban <urbanc@in.tum.de>
parents: 2537
diff changeset
   273
subsection {* Finite sets are a bounded, distributive lattice with minus *}
1905
dbc9e88c44da fsets are distributive lattices.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1895
diff changeset
   274
2528
9bde8a508594 Partially merging changes from Isabelle
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2525
diff changeset
   275
instantiation fset :: (type) "{bounded_lattice_bot, distrib_lattice, minus}"
1893
464dd13efff6 Putting FSet in bot typeclass.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1892
diff changeset
   276
begin
464dd13efff6 Putting FSet in bot typeclass.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1892
diff changeset
   277
464dd13efff6 Putting FSet in bot typeclass.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1892
diff changeset
   278
quotient_definition
2538
c9deccd12476 further tuning
Christian Urban <urbanc@in.tum.de>
parents: 2537
diff changeset
   279
  "bot :: 'a fset" 
c9deccd12476 further tuning
Christian Urban <urbanc@in.tum.de>
parents: 2537
diff changeset
   280
  is "Nil :: 'a list"
1893
464dd13efff6 Putting FSet in bot typeclass.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1892
diff changeset
   281
464dd13efff6 Putting FSet in bot typeclass.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1892
diff changeset
   282
abbreviation
464dd13efff6 Putting FSet in bot typeclass.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1892
diff changeset
   283
  fempty  ("{||}")
464dd13efff6 Putting FSet in bot typeclass.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1892
diff changeset
   284
where
464dd13efff6 Putting FSet in bot typeclass.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1892
diff changeset
   285
  "{||} \<equiv> bot :: 'a fset"
464dd13efff6 Putting FSet in bot typeclass.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1892
diff changeset
   286
464dd13efff6 Putting FSet in bot typeclass.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1892
diff changeset
   287
quotient_definition
2538
c9deccd12476 further tuning
Christian Urban <urbanc@in.tum.de>
parents: 2537
diff changeset
   288
  "less_eq_fset :: ('a fset \<Rightarrow> 'a fset \<Rightarrow> bool)"
c9deccd12476 further tuning
Christian Urban <urbanc@in.tum.de>
parents: 2537
diff changeset
   289
  is "sub_list :: ('a list \<Rightarrow> 'a list \<Rightarrow> bool)"
1893
464dd13efff6 Putting FSet in bot typeclass.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1892
diff changeset
   290
464dd13efff6 Putting FSet in bot typeclass.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1892
diff changeset
   291
abbreviation
464dd13efff6 Putting FSet in bot typeclass.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1892
diff changeset
   292
  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
   293
where
464dd13efff6 Putting FSet in bot typeclass.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1892
diff changeset
   294
  "xs |\<subseteq>| ys \<equiv> xs \<le> ys"
464dd13efff6 Putting FSet in bot typeclass.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1892
diff changeset
   295
464dd13efff6 Putting FSet in bot typeclass.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1892
diff changeset
   296
definition
2524
693562f03eee major reorganisation of fset (renamed fset_to_set to fset, changed the definition of list_eq and fcard_raw)
Christian Urban <urbanc@in.tum.de>
parents: 2479
diff changeset
   297
  less_fset :: "'a fset \<Rightarrow> 'a fset \<Rightarrow> bool"
693562f03eee major reorganisation of fset (renamed fset_to_set to fset, changed the definition of list_eq and fcard_raw)
Christian Urban <urbanc@in.tum.de>
parents: 2479
diff changeset
   298
where  
693562f03eee major reorganisation of fset (renamed fset_to_set to fset, changed the definition of list_eq and fcard_raw)
Christian Urban <urbanc@in.tum.de>
parents: 2479
diff changeset
   299
  "xs < ys \<equiv> xs \<le> ys \<and> xs \<noteq> (ys::'a fset)"
1893
464dd13efff6 Putting FSet in bot typeclass.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1892
diff changeset
   300
464dd13efff6 Putting FSet in bot typeclass.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1892
diff changeset
   301
abbreviation
2524
693562f03eee major reorganisation of fset (renamed fset_to_set to fset, changed the definition of list_eq and fcard_raw)
Christian Urban <urbanc@in.tum.de>
parents: 2479
diff changeset
   302
  fsubset :: "'a fset \<Rightarrow> 'a fset \<Rightarrow> bool" (infix "|\<subset>|" 50)
1893
464dd13efff6 Putting FSet in bot typeclass.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1892
diff changeset
   303
where
464dd13efff6 Putting FSet in bot typeclass.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1892
diff changeset
   304
  "xs |\<subset>| ys \<equiv> xs < ys"
464dd13efff6 Putting FSet in bot typeclass.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1892
diff changeset
   305
1895
91d67240c9c1 FSet is a semi-lattice
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1893
diff changeset
   306
quotient_definition
2524
693562f03eee major reorganisation of fset (renamed fset_to_set to fset, changed the definition of list_eq and fcard_raw)
Christian Urban <urbanc@in.tum.de>
parents: 2479
diff changeset
   307
  "sup :: 'a fset \<Rightarrow> 'a fset \<Rightarrow> 'a fset"
2538
c9deccd12476 further tuning
Christian Urban <urbanc@in.tum.de>
parents: 2537
diff changeset
   308
  is "append :: 'a list \<Rightarrow> 'a list \<Rightarrow> 'a list"
1895
91d67240c9c1 FSet is a semi-lattice
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1893
diff changeset
   309
91d67240c9c1 FSet is a semi-lattice
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1893
diff changeset
   310
abbreviation
2084
72b777cc5479 Synchronize FSet with repository
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1952
diff changeset
   311
  funion (infixl "|\<union>|" 65)
1895
91d67240c9c1 FSet is a semi-lattice
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1893
diff changeset
   312
where
2524
693562f03eee major reorganisation of fset (renamed fset_to_set to fset, changed the definition of list_eq and fcard_raw)
Christian Urban <urbanc@in.tum.de>
parents: 2479
diff changeset
   313
  "xs |\<union>| ys \<equiv> sup xs (ys::'a fset)"
1895
91d67240c9c1 FSet is a semi-lattice
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1893
diff changeset
   314
1905
dbc9e88c44da fsets are distributive lattices.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1895
diff changeset
   315
quotient_definition
2524
693562f03eee major reorganisation of fset (renamed fset_to_set to fset, changed the definition of list_eq and fcard_raw)
Christian Urban <urbanc@in.tum.de>
parents: 2479
diff changeset
   316
  "inf :: 'a fset \<Rightarrow> 'a fset \<Rightarrow> 'a fset"
2538
c9deccd12476 further tuning
Christian Urban <urbanc@in.tum.de>
parents: 2537
diff changeset
   317
  is "inter_list :: 'a list \<Rightarrow> 'a list \<Rightarrow> 'a list"
1905
dbc9e88c44da fsets are distributive lattices.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1895
diff changeset
   318
dbc9e88c44da fsets are distributive lattices.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1895
diff changeset
   319
abbreviation
dbc9e88c44da fsets are distributive lattices.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1895
diff changeset
   320
  finter (infixl "|\<inter>|" 65)
dbc9e88c44da fsets are distributive lattices.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1895
diff changeset
   321
where
2524
693562f03eee major reorganisation of fset (renamed fset_to_set to fset, changed the definition of list_eq and fcard_raw)
Christian Urban <urbanc@in.tum.de>
parents: 2479
diff changeset
   322
  "xs |\<inter>| ys \<equiv> inf xs (ys::'a fset)"
1905
dbc9e88c44da fsets are distributive lattices.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1895
diff changeset
   323
2084
72b777cc5479 Synchronize FSet with repository
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1952
diff changeset
   324
quotient_definition
2524
693562f03eee major reorganisation of fset (renamed fset_to_set to fset, changed the definition of list_eq and fcard_raw)
Christian Urban <urbanc@in.tum.de>
parents: 2479
diff changeset
   325
  "minus :: 'a fset \<Rightarrow> 'a fset \<Rightarrow> 'a fset"
2538
c9deccd12476 further tuning
Christian Urban <urbanc@in.tum.de>
parents: 2537
diff changeset
   326
  is "diff_list :: 'a list \<Rightarrow> 'a list \<Rightarrow> 'a list"
2084
72b777cc5479 Synchronize FSet with repository
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1952
diff changeset
   327
2533
767161329839 further cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2532
diff changeset
   328
1895
91d67240c9c1 FSet is a semi-lattice
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1893
diff changeset
   329
instance
91d67240c9c1 FSet is a semi-lattice
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1893
diff changeset
   330
proof
1905
dbc9e88c44da fsets are distributive lattices.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1895
diff changeset
   331
  fix x y z :: "'a fset"
2528
9bde8a508594 Partially merging changes from Isabelle
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2525
diff changeset
   332
  show "x |\<subset>| y \<longleftrightarrow> x |\<subseteq>| y \<and> \<not> y |\<subseteq>| x"
2530
3b8741ecfda3 FSet synchronizing
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2529
diff changeset
   333
    unfolding less_fset_def 
3b8741ecfda3 FSet synchronizing
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2529
diff changeset
   334
    by (descending) (auto simp add: sub_list_def)
2528
9bde8a508594 Partially merging changes from Isabelle
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2525
diff changeset
   335
  show "x |\<subseteq>| x"  by (descending) (simp add: sub_list_def)
9bde8a508594 Partially merging changes from Isabelle
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2525
diff changeset
   336
  show "{||} |\<subseteq>| x" by (descending) (simp add: sub_list_def)
9bde8a508594 Partially merging changes from Isabelle
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2525
diff changeset
   337
  show "x |\<subseteq>| x |\<union>| y" by (descending) (simp add: sub_list_def)
9bde8a508594 Partially merging changes from Isabelle
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2525
diff changeset
   338
  show "y |\<subseteq>| x |\<union>| y" by (descending) (simp add: sub_list_def)
9bde8a508594 Partially merging changes from Isabelle
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2525
diff changeset
   339
  show "x |\<inter>| y |\<subseteq>| x"
2538
c9deccd12476 further tuning
Christian Urban <urbanc@in.tum.de>
parents: 2537
diff changeset
   340
    by (descending) (auto simp add: inter_list_def sub_list_def memb_def)
2528
9bde8a508594 Partially merging changes from Isabelle
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2525
diff changeset
   341
  show "x |\<inter>| y |\<subseteq>| y" 
2538
c9deccd12476 further tuning
Christian Urban <urbanc@in.tum.de>
parents: 2537
diff changeset
   342
    by (descending) (auto simp add: inter_list_def sub_list_def memb_def)
2528
9bde8a508594 Partially merging changes from Isabelle
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2525
diff changeset
   343
  show "x |\<union>| (y |\<inter>| z) = x |\<union>| y |\<inter>| (x |\<union>| z)" 
2538
c9deccd12476 further tuning
Christian Urban <urbanc@in.tum.de>
parents: 2537
diff changeset
   344
    by (descending) (auto simp add: inter_list_def)
1905
dbc9e88c44da fsets are distributive lattices.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1895
diff changeset
   345
next
dbc9e88c44da fsets are distributive lattices.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1895
diff changeset
   346
  fix x y z :: "'a fset"
dbc9e88c44da fsets are distributive lattices.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1895
diff changeset
   347
  assume a: "x |\<subseteq>| y"
dbc9e88c44da fsets are distributive lattices.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1895
diff changeset
   348
  assume b: "y |\<subseteq>| z"
2528
9bde8a508594 Partially merging changes from Isabelle
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2525
diff changeset
   349
  show "x |\<subseteq>| z" using a b 
9bde8a508594 Partially merging changes from Isabelle
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2525
diff changeset
   350
    by (descending) (simp add: sub_list_def)
1895
91d67240c9c1 FSet is a semi-lattice
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1893
diff changeset
   351
next
91d67240c9c1 FSet is a semi-lattice
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1893
diff changeset
   352
  fix x y :: "'a fset"
91d67240c9c1 FSet is a semi-lattice
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1893
diff changeset
   353
  assume a: "x |\<subseteq>| y"
91d67240c9c1 FSet is a semi-lattice
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1893
diff changeset
   354
  assume b: "y |\<subseteq>| x"
2528
9bde8a508594 Partially merging changes from Isabelle
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2525
diff changeset
   355
  show "x = y" using a b 
9bde8a508594 Partially merging changes from Isabelle
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2525
diff changeset
   356
    by (descending) (unfold sub_list_def list_eq.simps, blast)
1895
91d67240c9c1 FSet is a semi-lattice
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1893
diff changeset
   357
next
91d67240c9c1 FSet is a semi-lattice
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1893
diff changeset
   358
  fix x y z :: "'a fset"
91d67240c9c1 FSet is a semi-lattice
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1893
diff changeset
   359
  assume a: "y |\<subseteq>| x"
91d67240c9c1 FSet is a semi-lattice
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1893
diff changeset
   360
  assume b: "z |\<subseteq>| x"
2528
9bde8a508594 Partially merging changes from Isabelle
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2525
diff changeset
   361
  show "y |\<union>| z |\<subseteq>| x" using a b 
9bde8a508594 Partially merging changes from Isabelle
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2525
diff changeset
   362
    by (descending) (simp add: sub_list_def)
1905
dbc9e88c44da fsets are distributive lattices.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1895
diff changeset
   363
next
dbc9e88c44da fsets are distributive lattices.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1895
diff changeset
   364
  fix x y z :: "'a fset"
dbc9e88c44da fsets are distributive lattices.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1895
diff changeset
   365
  assume a: "x |\<subseteq>| y"
dbc9e88c44da fsets are distributive lattices.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1895
diff changeset
   366
  assume b: "x |\<subseteq>| z"
2528
9bde8a508594 Partially merging changes from Isabelle
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2525
diff changeset
   367
  show "x |\<subseteq>| y |\<inter>| z" using a b 
2538
c9deccd12476 further tuning
Christian Urban <urbanc@in.tum.de>
parents: 2537
diff changeset
   368
    by (descending) (auto simp add: inter_list_def sub_list_def memb_def)
1895
91d67240c9c1 FSet is a semi-lattice
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1893
diff changeset
   369
qed
1905
dbc9e88c44da fsets are distributive lattices.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1895
diff changeset
   370
1893
464dd13efff6 Putting FSet in bot typeclass.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1892
diff changeset
   371
end
464dd13efff6 Putting FSet in bot typeclass.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1892
diff changeset
   372
1518
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   373
quotient_definition
1893
464dd13efff6 Putting FSet in bot typeclass.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1892
diff changeset
   374
  "finsert :: 'a \<Rightarrow> 'a fset \<Rightarrow> 'a fset"
2534
f99578469d08 Further reorganisation and cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2533
diff changeset
   375
  is "Cons"
1518
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   376
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   377
syntax
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   378
  "@Finset"     :: "args => 'a fset"  ("{|(_)|}")
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   379
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   380
translations
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   381
  "{|x, xs|}" == "CONST finsert x {|xs|}"
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   382
  "{|x|}"     == "CONST finsert x {||}"
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   383
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   384
quotient_definition
1938
3641d055b260 Further cleaning of proofs in FSet
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1936
diff changeset
   385
  fin (infix "|\<in>|" 50)
1518
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   386
where
1816
56cebe7f8e24 some small tunings (incompleted work in Lambda.thy)
Christian Urban <urbanc@in.tum.de>
parents: 1682
diff changeset
   387
  "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
   388
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   389
abbreviation
1938
3641d055b260 Further cleaning of proofs in FSet
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1936
diff changeset
   390
  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
   391
where
1860
d3fe17786640 some tuning of proofs
Christian Urban <urbanc@in.tum.de>
parents: 1826
diff changeset
   392
  "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
   393
2084
72b777cc5479 Synchronize FSet with repository
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1952
diff changeset
   394
section {* Other constants on the Quotient Type *}
1935
266abc3ee228 Moved working Fset3 properties to FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1927
diff changeset
   395
266abc3ee228 Moved working Fset3 properties to FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1927
diff changeset
   396
quotient_definition
2084
72b777cc5479 Synchronize FSet with repository
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1952
diff changeset
   397
  "fcard :: 'a fset \<Rightarrow> nat"
2536
98e84b56543f renamed fcard_raw to card_list
Christian Urban <urbanc@in.tum.de>
parents: 2534
diff changeset
   398
  is card_list
1935
266abc3ee228 Moved working Fset3 properties to FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1927
diff changeset
   399
266abc3ee228 Moved working Fset3 properties to FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1927
diff changeset
   400
quotient_definition
266abc3ee228 Moved working Fset3 properties to FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1927
diff changeset
   401
  "fmap :: ('a \<Rightarrow> 'b) \<Rightarrow> 'a fset \<Rightarrow> 'b fset"
2534
f99578469d08 Further reorganisation and cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2533
diff changeset
   402
  is map
1935
266abc3ee228 Moved working Fset3 properties to FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1927
diff changeset
   403
266abc3ee228 Moved working Fset3 properties to FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1927
diff changeset
   404
quotient_definition
2524
693562f03eee major reorganisation of fset (renamed fset_to_set to fset, changed the definition of list_eq and fcard_raw)
Christian Urban <urbanc@in.tum.de>
parents: 2479
diff changeset
   405
  "fdelete :: 'a \<Rightarrow> 'a fset \<Rightarrow> 'a fset"
693562f03eee major reorganisation of fset (renamed fset_to_set to fset, changed the definition of list_eq and fcard_raw)
Christian Urban <urbanc@in.tum.de>
parents: 2479
diff changeset
   406
  is removeAll
1935
266abc3ee228 Moved working Fset3 properties to FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1927
diff changeset
   407
266abc3ee228 Moved working Fset3 properties to FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1927
diff changeset
   408
quotient_definition
2524
693562f03eee major reorganisation of fset (renamed fset_to_set to fset, changed the definition of list_eq and fcard_raw)
Christian Urban <urbanc@in.tum.de>
parents: 2479
diff changeset
   409
  "fset :: 'a fset \<Rightarrow> 'a set"
1935
266abc3ee228 Moved working Fset3 properties to FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1927
diff changeset
   410
  is "set"
266abc3ee228 Moved working Fset3 properties to FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1927
diff changeset
   411
266abc3ee228 Moved working Fset3 properties to FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1927
diff changeset
   412
quotient_definition
266abc3ee228 Moved working Fset3 properties to FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1927
diff changeset
   413
  "ffold :: ('a \<Rightarrow> 'b \<Rightarrow> 'b) \<Rightarrow> 'b \<Rightarrow> 'a fset \<Rightarrow> 'b"
2539
a8f5611dbd65 more cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2538
diff changeset
   414
  is ffold_list
1935
266abc3ee228 Moved working Fset3 properties to FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1927
diff changeset
   415
266abc3ee228 Moved working Fset3 properties to FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1927
diff changeset
   416
quotient_definition
266abc3ee228 Moved working Fset3 properties to FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1927
diff changeset
   417
  "fconcat :: ('a fset) fset \<Rightarrow> 'a fset"
2534
f99578469d08 Further reorganisation and cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2533
diff changeset
   418
  is concat
1935
266abc3ee228 Moved working Fset3 properties to FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1927
diff changeset
   419
2084
72b777cc5479 Synchronize FSet with repository
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1952
diff changeset
   420
quotient_definition
72b777cc5479 Synchronize FSet with repository
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1952
diff changeset
   421
  "ffilter :: ('a \<Rightarrow> bool) \<Rightarrow> 'a fset \<Rightarrow> 'a fset"
2534
f99578469d08 Further reorganisation and cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2533
diff changeset
   422
  is filter
2084
72b777cc5479 Synchronize FSet with repository
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1952
diff changeset
   423
2534
f99578469d08 Further reorganisation and cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2533
diff changeset
   424
2539
a8f5611dbd65 more cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2538
diff changeset
   425
section {* Compositional respectfulness and preservation lemmas *}
1935
266abc3ee228 Moved working Fset3 properties to FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1927
diff changeset
   426
2539
a8f5611dbd65 more cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2538
diff changeset
   427
lemma Nil_rsp2 [quot_respect]: 
a8f5611dbd65 more cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2538
diff changeset
   428
  shows "(list_all2 op \<approx> OOO op \<approx>) Nil Nil"
1938
3641d055b260 Further cleaning of proofs in FSet
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1936
diff changeset
   429
  by (fact compose_list_refl)
1935
266abc3ee228 Moved working Fset3 properties to FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1927
diff changeset
   430
2539
a8f5611dbd65 more cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2538
diff changeset
   431
lemma Cons_rsp2 [quot_respect]:
2524
693562f03eee major reorganisation of fset (renamed fset_to_set to fset, changed the definition of list_eq and fcard_raw)
Christian Urban <urbanc@in.tum.de>
parents: 2479
diff changeset
   432
  shows "(op \<approx> ===> list_all2 op \<approx> OOO op \<approx> ===> list_all2 op \<approx> OOO op \<approx>) Cons Cons"
1935
266abc3ee228 Moved working Fset3 properties to FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1927
diff changeset
   433
  apply auto
266abc3ee228 Moved working Fset3 properties to FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1927
diff changeset
   434
  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
   435
  apply auto
266abc3ee228 Moved working Fset3 properties to FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1927
diff changeset
   436
  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
   437
  apply auto
266abc3ee228 Moved working Fset3 properties to FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1927
diff changeset
   438
  done
266abc3ee228 Moved working Fset3 properties to FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1927
diff changeset
   439
2539
a8f5611dbd65 more cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2538
diff changeset
   440
lemma map_prs [quot_preserve]: 
a8f5611dbd65 more cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2538
diff changeset
   441
  shows "(abs_fset \<circ> map f) [] = abs_fset []"
a8f5611dbd65 more cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2538
diff changeset
   442
  by simp
a8f5611dbd65 more cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2538
diff changeset
   443
a8f5611dbd65 more cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2538
diff changeset
   444
lemma finsert_rsp [quot_preserve]:
1935
266abc3ee228 Moved working Fset3 properties to FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1927
diff changeset
   445
  "(rep_fset ---> (map rep_fset \<circ> rep_fset) ---> (abs_fset \<circ> map abs_fset)) op # = finsert"
2479
a9b6a00b1ba0 updated to Isabelle Sept 16
Christian Urban <urbanc@in.tum.de>
parents: 2378
diff changeset
   446
  by (simp add: fun_eq_iff Quotient_abs_rep[OF Quotient_fset]
1935
266abc3ee228 Moved working Fset3 properties to FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1927
diff changeset
   447
      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
   448
2539
a8f5611dbd65 more cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2538
diff changeset
   449
lemma funion_rsp [quot_preserve]:
1938
3641d055b260 Further cleaning of proofs in FSet
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1936
diff changeset
   450
  "((map rep_fset \<circ> rep_fset) ---> (map rep_fset \<circ> rep_fset) ---> (abs_fset \<circ> map abs_fset)) op @ = funion"
2479
a9b6a00b1ba0 updated to Isabelle Sept 16
Christian Urban <urbanc@in.tum.de>
parents: 2378
diff changeset
   451
  by (simp add: fun_eq_iff Quotient_abs_rep[OF Quotient_fset]
1935
266abc3ee228 Moved working Fset3 properties to FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1927
diff changeset
   452
      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
   453
2326
b51532dd5689 Changes for PER and list_all2 committed to Isabelle
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2278
diff changeset
   454
lemma list_all2_app_l:
1935
266abc3ee228 Moved working Fset3 properties to FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1927
diff changeset
   455
  assumes a: "reflp R"
2326
b51532dd5689 Changes for PER and list_all2 committed to Isabelle
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2278
diff changeset
   456
  and b: "list_all2 R l r"
b51532dd5689 Changes for PER and list_all2 committed to Isabelle
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2278
diff changeset
   457
  shows "list_all2 R (z @ l) (z @ r)"
1938
3641d055b260 Further cleaning of proofs in FSet
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1936
diff changeset
   458
  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
   459
266abc3ee228 Moved working Fset3 properties to FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1927
diff changeset
   460
lemma append_rsp2_pre0:
2326
b51532dd5689 Changes for PER and list_all2 committed to Isabelle
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2278
diff changeset
   461
  assumes a:"list_all2 op \<approx> x x'"
b51532dd5689 Changes for PER and list_all2 committed to Isabelle
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2278
diff changeset
   462
  shows "list_all2 op \<approx> (x @ z) (x' @ z)"
1935
266abc3ee228 Moved working Fset3 properties to FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1927
diff changeset
   463
  using a apply (induct x x' rule: list_induct2')
2326
b51532dd5689 Changes for PER and list_all2 committed to Isabelle
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2278
diff changeset
   464
  by simp_all (rule list_all2_refl1)
1935
266abc3ee228 Moved working Fset3 properties to FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1927
diff changeset
   465
266abc3ee228 Moved working Fset3 properties to FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1927
diff changeset
   466
lemma append_rsp2_pre1:
2326
b51532dd5689 Changes for PER and list_all2 committed to Isabelle
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2278
diff changeset
   467
  assumes a:"list_all2 op \<approx> x x'"
b51532dd5689 Changes for PER and list_all2 committed to Isabelle
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2278
diff changeset
   468
  shows "list_all2 op \<approx> (z @ x) (z @ x')"
1935
266abc3ee228 Moved working Fset3 properties to FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1927
diff changeset
   469
  using a apply (induct x x' arbitrary: z rule: list_induct2')
2326
b51532dd5689 Changes for PER and list_all2 committed to Isabelle
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2278
diff changeset
   470
  apply (rule list_all2_refl1)
1935
266abc3ee228 Moved working Fset3 properties to FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1927
diff changeset
   471
  apply (simp_all del: list_eq.simps)
2326
b51532dd5689 Changes for PER and list_all2 committed to Isabelle
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2278
diff changeset
   472
  apply (rule list_all2_app_l)
1935
266abc3ee228 Moved working Fset3 properties to FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1927
diff changeset
   473
  apply (simp_all add: reflp_def)
266abc3ee228 Moved working Fset3 properties to FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1927
diff changeset
   474
  done
266abc3ee228 Moved working Fset3 properties to FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1927
diff changeset
   475
266abc3ee228 Moved working Fset3 properties to FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1927
diff changeset
   476
lemma append_rsp2_pre:
2326
b51532dd5689 Changes for PER and list_all2 committed to Isabelle
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2278
diff changeset
   477
  assumes a:"list_all2 op \<approx> x x'"
b51532dd5689 Changes for PER and list_all2 committed to Isabelle
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2278
diff changeset
   478
  and     b: "list_all2 op \<approx> z z'"
b51532dd5689 Changes for PER and list_all2 committed to Isabelle
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2278
diff changeset
   479
  shows "list_all2 op \<approx> (x @ z) (x' @ z')"
b51532dd5689 Changes for PER and list_all2 committed to Isabelle
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2278
diff changeset
   480
  apply (rule list_all2_transp[OF fset_equivp])
1935
266abc3ee228 Moved working Fset3 properties to FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1927
diff changeset
   481
  apply (rule append_rsp2_pre0)
266abc3ee228 Moved working Fset3 properties to FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1927
diff changeset
   482
  apply (rule a)
266abc3ee228 Moved working Fset3 properties to FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1927
diff changeset
   483
  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
   484
  apply (simp_all only: append_Nil2)
2326
b51532dd5689 Changes for PER and list_all2 committed to Isabelle
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2278
diff changeset
   485
  apply (rule list_all2_refl1)
1935
266abc3ee228 Moved working Fset3 properties to FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1927
diff changeset
   486
  apply simp_all
266abc3ee228 Moved working Fset3 properties to FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1927
diff changeset
   487
  apply (rule append_rsp2_pre1)
266abc3ee228 Moved working Fset3 properties to FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1927
diff changeset
   488
  apply simp
266abc3ee228 Moved working Fset3 properties to FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1927
diff changeset
   489
  done
266abc3ee228 Moved working Fset3 properties to FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1927
diff changeset
   490
266abc3ee228 Moved working Fset3 properties to FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1927
diff changeset
   491
lemma [quot_respect]:
2539
a8f5611dbd65 more cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2538
diff changeset
   492
  "(list_all2 op \<approx> OOO op \<approx> ===> list_all2 op \<approx> OOO op \<approx> ===> list_all2 op \<approx> OOO op \<approx>) append append"
1935
266abc3ee228 Moved working Fset3 properties to FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1927
diff changeset
   493
proof (intro fun_relI, elim pred_compE)
266abc3ee228 Moved working Fset3 properties to FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1927
diff changeset
   494
  fix x y z w x' z' y' w' :: "'a list list"
2326
b51532dd5689 Changes for PER and list_all2 committed to Isabelle
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2278
diff changeset
   495
  assume a:"list_all2 op \<approx> x x'"
1935
266abc3ee228 Moved working Fset3 properties to FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1927
diff changeset
   496
  and b:    "x' \<approx> y'"
2326
b51532dd5689 Changes for PER and list_all2 committed to Isabelle
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2278
diff changeset
   497
  and c:    "list_all2 op \<approx> y' y"
b51532dd5689 Changes for PER and list_all2 committed to Isabelle
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2278
diff changeset
   498
  assume aa: "list_all2 op \<approx> z z'"
1935
266abc3ee228 Moved working Fset3 properties to FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1927
diff changeset
   499
  and bb:   "z' \<approx> w'"
2326
b51532dd5689 Changes for PER and list_all2 committed to Isabelle
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2278
diff changeset
   500
  and cc:   "list_all2 op \<approx> w' w"
b51532dd5689 Changes for PER and list_all2 committed to Isabelle
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2278
diff changeset
   501
  have a': "list_all2 op \<approx> (x @ z) (x' @ z')" using a aa append_rsp2_pre by auto
1935
266abc3ee228 Moved working Fset3 properties to FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1927
diff changeset
   502
  have b': "x' @ z' \<approx> y' @ w'" using b bb by simp
2326
b51532dd5689 Changes for PER and list_all2 committed to Isabelle
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2278
diff changeset
   503
  have c': "list_all2 op \<approx> (y' @ w') (y @ w)" using c cc append_rsp2_pre by auto
b51532dd5689 Changes for PER and list_all2 committed to Isabelle
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2278
diff changeset
   504
  have d': "(op \<approx> OO list_all2 op \<approx>) (x' @ z') (y @ w)"
1935
266abc3ee228 Moved working Fset3 properties to FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1927
diff changeset
   505
    by (rule pred_compI) (rule b', rule c')
2326
b51532dd5689 Changes for PER and list_all2 committed to Isabelle
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2278
diff changeset
   506
  show "(list_all2 op \<approx> OOO op \<approx>) (x @ z) (y @ w)"
1935
266abc3ee228 Moved working Fset3 properties to FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1927
diff changeset
   507
    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
   508
qed
266abc3ee228 Moved working Fset3 properties to FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1927
diff changeset
   509
1878
c22947214948 2 more lifted lemmas needed for second representation
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1860
diff changeset
   510
2524
693562f03eee major reorganisation of fset (renamed fset_to_set to fset, changed the definition of list_eq and fcard_raw)
Christian Urban <urbanc@in.tum.de>
parents: 2479
diff changeset
   511
2534
f99578469d08 Further reorganisation and cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2533
diff changeset
   512
section {* Lifted theorems *}
f99578469d08 Further reorganisation and cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2533
diff changeset
   513
f99578469d08 Further reorganisation and cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2533
diff changeset
   514
f99578469d08 Further reorganisation and cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2533
diff changeset
   515
subsection {* fin *}
1518
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   516
2534
f99578469d08 Further reorganisation and cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2533
diff changeset
   517
lemma not_fin_fnil: 
f99578469d08 Further reorganisation and cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2533
diff changeset
   518
  shows "x |\<notin>| {||}"
f99578469d08 Further reorganisation and cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2533
diff changeset
   519
  by (descending) (simp add: memb_def)
f99578469d08 Further reorganisation and cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2533
diff changeset
   520
f99578469d08 Further reorganisation and cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2533
diff changeset
   521
lemma fin_set: 
f99578469d08 Further reorganisation and cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2533
diff changeset
   522
  shows "x |\<in>| S \<longleftrightarrow> x \<in> fset S"
2529
775d0bfd99fd Synchronizing FSet further.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2528
diff changeset
   523
  by (descending) (simp add: memb_def)
1518
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   524
2534
f99578469d08 Further reorganisation and cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2533
diff changeset
   525
lemma fnotin_set: 
f99578469d08 Further reorganisation and cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2533
diff changeset
   526
  shows "x |\<notin>| S \<longleftrightarrow> x \<notin> fset S"
f99578469d08 Further reorganisation and cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2533
diff changeset
   527
  by (descending) (simp add: memb_def)
f99578469d08 Further reorganisation and cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2533
diff changeset
   528
f99578469d08 Further reorganisation and cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2533
diff changeset
   529
lemma fset_eq_iff:
f99578469d08 Further reorganisation and cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2533
diff changeset
   530
  shows "S = T \<longleftrightarrow> (\<forall>x. (x |\<in>| S) = (x |\<in>| T))"
f99578469d08 Further reorganisation and cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2533
diff changeset
   531
  by (descending) (auto simp add: memb_def)
f99578469d08 Further reorganisation and cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2533
diff changeset
   532
f99578469d08 Further reorganisation and cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2533
diff changeset
   533
lemma none_fin_fempty:
f99578469d08 Further reorganisation and cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2533
diff changeset
   534
  shows "(\<forall>x. x |\<notin>| S) \<longleftrightarrow> S = {||}"
f99578469d08 Further reorganisation and cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2533
diff changeset
   535
  by (descending) (simp add: memb_def)
f99578469d08 Further reorganisation and cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2533
diff changeset
   536
f99578469d08 Further reorganisation and cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2533
diff changeset
   537
f99578469d08 Further reorganisation and cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2533
diff changeset
   538
subsection {* finsert *}
f99578469d08 Further reorganisation and cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2533
diff changeset
   539
1518
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   540
lemma fin_finsert_iff[simp]:
2534
f99578469d08 Further reorganisation and cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2533
diff changeset
   541
  shows "x |\<in>| finsert y S \<longleftrightarrow> x = y \<or> x |\<in>| S"
2528
9bde8a508594 Partially merging changes from Isabelle
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2525
diff changeset
   542
  by (descending) (simp add: memb_def)
1518
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   543
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   544
lemma
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   545
  shows finsertI1: "x |\<in>| finsert x S"
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   546
  and   finsertI2: "x |\<in>| S \<Longrightarrow> x |\<in>| finsert y S"
2534
f99578469d08 Further reorganisation and cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2533
diff changeset
   547
  by (descending, simp add: memb_def)+
1518
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   548
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   549
lemma finsert_absorb[simp]:
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   550
  shows "x |\<in>| S \<Longrightarrow> finsert x S = S"
2528
9bde8a508594 Partially merging changes from Isabelle
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2525
diff changeset
   551
  by (descending) (auto simp add: memb_def)
1518
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   552
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   553
lemma fempty_not_finsert[simp]:
2534
f99578469d08 Further reorganisation and cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2533
diff changeset
   554
  shows "{||} \<noteq> finsert x S"
f99578469d08 Further reorganisation and cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2533
diff changeset
   555
  and   "finsert x S \<noteq> {||}"
f99578469d08 Further reorganisation and cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2533
diff changeset
   556
  by (descending, simp)+
1518
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   557
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   558
lemma finsert_left_comm:
2534
f99578469d08 Further reorganisation and cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2533
diff changeset
   559
  shows "finsert x (finsert y S) = finsert y (finsert x S)"
2528
9bde8a508594 Partially merging changes from Isabelle
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2525
diff changeset
   560
  by (descending) (auto)
1518
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   561
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   562
lemma finsert_left_idem:
2534
f99578469d08 Further reorganisation and cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2533
diff changeset
   563
  shows "finsert x (finsert x S) = finsert x S"
2528
9bde8a508594 Partially merging changes from Isabelle
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2525
diff changeset
   564
  by (descending) (auto)
1518
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   565
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   566
lemma fsingleton_eq[simp]:
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   567
  shows "{|x|} = {|y|} \<longleftrightarrow> x = y"
2528
9bde8a508594 Partially merging changes from Isabelle
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2525
diff changeset
   568
  by (descending) (auto)
1518
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   569
2524
693562f03eee major reorganisation of fset (renamed fset_to_set to fset, changed the definition of list_eq and fcard_raw)
Christian Urban <urbanc@in.tum.de>
parents: 2479
diff changeset
   570
2534
f99578469d08 Further reorganisation and cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2533
diff changeset
   571
(* FIXME: is this in any case a useful lemma *)
f99578469d08 Further reorganisation and cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2533
diff changeset
   572
lemma fin_mdef:
f99578469d08 Further reorganisation and cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2533
diff changeset
   573
  shows "x |\<in>| F \<longleftrightarrow> x |\<notin>| (F - {|x|}) \<and> F = finsert x (F - {|x|})"
2537
d73fa7a3e04b renamed fminus_raw to diff_list
Christian Urban <urbanc@in.tum.de>
parents: 2536
diff changeset
   574
  by (descending) (auto simp add: memb_def diff_list_def)
2534
f99578469d08 Further reorganisation and cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2533
diff changeset
   575
f99578469d08 Further reorganisation and cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2533
diff changeset
   576
f99578469d08 Further reorganisation and cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2533
diff changeset
   577
subsection {* fset *}
1518
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   578
2524
693562f03eee major reorganisation of fset (renamed fset_to_set to fset, changed the definition of list_eq and fcard_raw)
Christian Urban <urbanc@in.tum.de>
parents: 2479
diff changeset
   579
lemma fset_simps[simp]:
693562f03eee major reorganisation of fset (renamed fset_to_set to fset, changed the definition of list_eq and fcard_raw)
Christian Urban <urbanc@in.tum.de>
parents: 2479
diff changeset
   580
  "fset {||} = ({} :: 'a set)"
2533
767161329839 further cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2532
diff changeset
   581
  "fset (finsert (x :: 'a) S) = insert x (fset S)"
1819
63dd459dbc0d Much more in FSet (currently non-working)
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1817
diff changeset
   582
  by (lifting set.simps)
1518
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   583
2534
f99578469d08 Further reorganisation and cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2533
diff changeset
   584
lemma finite_fset [simp]: 
f99578469d08 Further reorganisation and cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2533
diff changeset
   585
  shows "finite (fset S)"
f99578469d08 Further reorganisation and cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2533
diff changeset
   586
  by (descending) (simp)
f99578469d08 Further reorganisation and cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2533
diff changeset
   587
f99578469d08 Further reorganisation and cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2533
diff changeset
   588
lemma fset_cong:
f99578469d08 Further reorganisation and cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2533
diff changeset
   589
  shows "fset S = fset T \<longleftrightarrow> S = T"
f99578469d08 Further reorganisation and cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2533
diff changeset
   590
  by (descending) (simp)
f99578469d08 Further reorganisation and cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2533
diff changeset
   591
f99578469d08 Further reorganisation and cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2533
diff changeset
   592
lemma ffilter_set [simp]: 
f99578469d08 Further reorganisation and cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2533
diff changeset
   593
  shows "fset (ffilter P xs) = P \<inter> fset xs"
f99578469d08 Further reorganisation and cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2533
diff changeset
   594
  by (descending) (auto simp add: mem_def)
f99578469d08 Further reorganisation and cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2533
diff changeset
   595
f99578469d08 Further reorganisation and cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2533
diff changeset
   596
lemma fdelete_set [simp]: 
f99578469d08 Further reorganisation and cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2533
diff changeset
   597
  shows "fset (fdelete x xs) = fset xs - {x}"
f99578469d08 Further reorganisation and cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2533
diff changeset
   598
  by (descending) (simp)
f99578469d08 Further reorganisation and cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2533
diff changeset
   599
f99578469d08 Further reorganisation and cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2533
diff changeset
   600
lemma finter_set [simp]: 
f99578469d08 Further reorganisation and cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2533
diff changeset
   601
  shows "fset (xs |\<inter>| ys) = fset xs \<inter> fset ys"
2538
c9deccd12476 further tuning
Christian Urban <urbanc@in.tum.de>
parents: 2537
diff changeset
   602
  by (descending) (auto simp add: inter_list_def)
2534
f99578469d08 Further reorganisation and cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2533
diff changeset
   603
f99578469d08 Further reorganisation and cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2533
diff changeset
   604
lemma funion_set [simp]: 
f99578469d08 Further reorganisation and cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2533
diff changeset
   605
  shows "fset (xs |\<union>| ys) = fset xs \<union> fset ys"
f99578469d08 Further reorganisation and cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2533
diff changeset
   606
  by (lifting set_append)
f99578469d08 Further reorganisation and cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2533
diff changeset
   607
f99578469d08 Further reorganisation and cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2533
diff changeset
   608
lemma fminus_set [simp]: 
f99578469d08 Further reorganisation and cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2533
diff changeset
   609
  shows "fset (xs - ys) = fset xs - fset ys"
2538
c9deccd12476 further tuning
Christian Urban <urbanc@in.tum.de>
parents: 2537
diff changeset
   610
  by (descending) (auto simp add: diff_list_def)
2534
f99578469d08 Further reorganisation and cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2533
diff changeset
   611
f99578469d08 Further reorganisation and cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2533
diff changeset
   612
f99578469d08 Further reorganisation and cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2533
diff changeset
   613
subsection {* funion *}
f99578469d08 Further reorganisation and cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2533
diff changeset
   614
f99578469d08 Further reorganisation and cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2533
diff changeset
   615
lemmas [simp] =
f99578469d08 Further reorganisation and cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2533
diff changeset
   616
  sup_bot_left[where 'a="'a fset", standard]
f99578469d08 Further reorganisation and cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2533
diff changeset
   617
  sup_bot_right[where 'a="'a fset", standard]
f99578469d08 Further reorganisation and cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2533
diff changeset
   618
f99578469d08 Further reorganisation and cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2533
diff changeset
   619
lemma funion_finsert[simp]:
f99578469d08 Further reorganisation and cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2533
diff changeset
   620
  shows "finsert x S |\<union>| T = finsert x (S |\<union>| T)"
f99578469d08 Further reorganisation and cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2533
diff changeset
   621
  by (lifting append.simps(2))
f99578469d08 Further reorganisation and cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2533
diff changeset
   622
f99578469d08 Further reorganisation and cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2533
diff changeset
   623
lemma singleton_funion_left:
f99578469d08 Further reorganisation and cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2533
diff changeset
   624
  shows "{|a|} |\<union>| S = finsert a S"
f99578469d08 Further reorganisation and cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2533
diff changeset
   625
  by simp
1518
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   626
2534
f99578469d08 Further reorganisation and cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2533
diff changeset
   627
lemma singleton_funion_right:
f99578469d08 Further reorganisation and cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2533
diff changeset
   628
  shows "S |\<union>| {|a|} = finsert a S"
f99578469d08 Further reorganisation and cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2533
diff changeset
   629
  by (subst sup.commute) simp
f99578469d08 Further reorganisation and cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2533
diff changeset
   630
f99578469d08 Further reorganisation and cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2533
diff changeset
   631
lemma fin_funion:
f99578469d08 Further reorganisation and cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2533
diff changeset
   632
  shows "x |\<in>| S |\<union>| T \<longleftrightarrow> x |\<in>| S \<or> x |\<in>| T"
f99578469d08 Further reorganisation and cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2533
diff changeset
   633
  by (descending) (simp add: memb_def)
f99578469d08 Further reorganisation and cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2533
diff changeset
   634
f99578469d08 Further reorganisation and cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2533
diff changeset
   635
f99578469d08 Further reorganisation and cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2533
diff changeset
   636
subsection {* fminus *}
f99578469d08 Further reorganisation and cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2533
diff changeset
   637
f99578469d08 Further reorganisation and cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2533
diff changeset
   638
lemma fminus_fin: 
f99578469d08 Further reorganisation and cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2533
diff changeset
   639
  shows "x |\<in>| (xs - ys) \<longleftrightarrow> x |\<in>| xs \<and> x |\<notin>| ys"
2538
c9deccd12476 further tuning
Christian Urban <urbanc@in.tum.de>
parents: 2537
diff changeset
   640
  by (descending) (simp add: diff_list_def memb_def)
2534
f99578469d08 Further reorganisation and cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2533
diff changeset
   641
f99578469d08 Further reorganisation and cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2533
diff changeset
   642
lemma fminus_red: 
f99578469d08 Further reorganisation and cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2533
diff changeset
   643
  shows "finsert x xs - ys = (if x |\<in>| ys then xs - ys else finsert x (xs - ys))"
2538
c9deccd12476 further tuning
Christian Urban <urbanc@in.tum.de>
parents: 2537
diff changeset
   644
  by (descending) (auto simp add: diff_list_def memb_def)
2534
f99578469d08 Further reorganisation and cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2533
diff changeset
   645
f99578469d08 Further reorganisation and cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2533
diff changeset
   646
lemma fminus_red_fin[simp]: 
f99578469d08 Further reorganisation and cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2533
diff changeset
   647
  shows "x |\<in>| ys \<Longrightarrow> finsert x xs - ys = xs - ys"
f99578469d08 Further reorganisation and cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2533
diff changeset
   648
  by (simp add: fminus_red)
f99578469d08 Further reorganisation and cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2533
diff changeset
   649
f99578469d08 Further reorganisation and cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2533
diff changeset
   650
lemma fminus_red_fnotin[simp]: 
f99578469d08 Further reorganisation and cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2533
diff changeset
   651
  shows "x |\<notin>| ys \<Longrightarrow> finsert x xs - ys = finsert x (xs - ys)"
f99578469d08 Further reorganisation and cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2533
diff changeset
   652
  by (simp add: fminus_red)
f99578469d08 Further reorganisation and cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2533
diff changeset
   653
f99578469d08 Further reorganisation and cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2533
diff changeset
   654
lemma fin_fminus_fnotin: 
f99578469d08 Further reorganisation and cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2533
diff changeset
   655
  shows "x |\<in>| F - S \<Longrightarrow> x |\<notin>| S"
f99578469d08 Further reorganisation and cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2533
diff changeset
   656
  unfolding fin_set fminus_set
f99578469d08 Further reorganisation and cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2533
diff changeset
   657
  by blast
f99578469d08 Further reorganisation and cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2533
diff changeset
   658
f99578469d08 Further reorganisation and cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2533
diff changeset
   659
lemma fin_fnotin_fminus: 
f99578469d08 Further reorganisation and cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2533
diff changeset
   660
  shows "x |\<in>| S \<Longrightarrow> x |\<notin>| F - S"
f99578469d08 Further reorganisation and cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2533
diff changeset
   661
  unfolding fin_set fminus_set
f99578469d08 Further reorganisation and cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2533
diff changeset
   662
  by blast
f99578469d08 Further reorganisation and cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2533
diff changeset
   663
f99578469d08 Further reorganisation and cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2533
diff changeset
   664
f99578469d08 Further reorganisation and cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2533
diff changeset
   665
section {* fdelete *}
f99578469d08 Further reorganisation and cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2533
diff changeset
   666
f99578469d08 Further reorganisation and cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2533
diff changeset
   667
lemma fin_fdelete:
f99578469d08 Further reorganisation and cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2533
diff changeset
   668
  shows "x |\<in>| fdelete y S \<longleftrightarrow> x |\<in>| S \<and> x \<noteq> y"
2533
767161329839 further cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2532
diff changeset
   669
  by (descending) (simp add: memb_def)
1518
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   670
2534
f99578469d08 Further reorganisation and cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2533
diff changeset
   671
lemma fnotin_fdelete:
f99578469d08 Further reorganisation and cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2533
diff changeset
   672
  shows "x |\<notin>| fdelete x S"
f99578469d08 Further reorganisation and cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2533
diff changeset
   673
  by (descending) (simp add: memb_def)
f99578469d08 Further reorganisation and cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2533
diff changeset
   674
f99578469d08 Further reorganisation and cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2533
diff changeset
   675
lemma fnotin_fdelete_ident:
f99578469d08 Further reorganisation and cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2533
diff changeset
   676
  shows "x |\<notin>| S \<Longrightarrow> fdelete x S = S"
f99578469d08 Further reorganisation and cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2533
diff changeset
   677
  by (descending) (simp add: memb_def)
f99578469d08 Further reorganisation and cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2533
diff changeset
   678
f99578469d08 Further reorganisation and cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2533
diff changeset
   679
lemma fset_fdelete_cases:
f99578469d08 Further reorganisation and cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2533
diff changeset
   680
  shows "S = {||} \<or> (\<exists>x. x |\<in>| S \<and> S = finsert x (fdelete x S))"
f99578469d08 Further reorganisation and cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2533
diff changeset
   681
  by (descending) (auto simp add: memb_def insert_absorb)
f99578469d08 Further reorganisation and cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2533
diff changeset
   682
  
f99578469d08 Further reorganisation and cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2533
diff changeset
   683
f99578469d08 Further reorganisation and cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2533
diff changeset
   684
section {* finter *}
f99578469d08 Further reorganisation and cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2533
diff changeset
   685
f99578469d08 Further reorganisation and cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2533
diff changeset
   686
lemma finter_empty_l:
f99578469d08 Further reorganisation and cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2533
diff changeset
   687
  shows "{||} |\<inter>| S = {||}"
f99578469d08 Further reorganisation and cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2533
diff changeset
   688
  by simp
f99578469d08 Further reorganisation and cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2533
diff changeset
   689
f99578469d08 Further reorganisation and cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2533
diff changeset
   690
lemma finter_empty_r:
f99578469d08 Further reorganisation and cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2533
diff changeset
   691
  shows "S |\<inter>| {||} = {||}"
f99578469d08 Further reorganisation and cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2533
diff changeset
   692
  by simp
f99578469d08 Further reorganisation and cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2533
diff changeset
   693
f99578469d08 Further reorganisation and cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2533
diff changeset
   694
lemma finter_finsert:
f99578469d08 Further reorganisation and cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2533
diff changeset
   695
  shows "finsert x S |\<inter>| T = (if x |\<in>| T then finsert x (S |\<inter>| T) else S |\<inter>| T)"
2538
c9deccd12476 further tuning
Christian Urban <urbanc@in.tum.de>
parents: 2537
diff changeset
   696
  by (descending) (auto simp add: inter_list_def memb_def)
2534
f99578469d08 Further reorganisation and cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2533
diff changeset
   697
f99578469d08 Further reorganisation and cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2533
diff changeset
   698
lemma fin_finter:
f99578469d08 Further reorganisation and cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2533
diff changeset
   699
  shows "x |\<in>| (S |\<inter>| T) \<longleftrightarrow> x |\<in>| S \<and> x |\<in>| T"
2538
c9deccd12476 further tuning
Christian Urban <urbanc@in.tum.de>
parents: 2537
diff changeset
   700
  by (descending) (simp add: inter_list_def memb_def)
1533
5f5e99a11f66 A few more theorems in FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1518
diff changeset
   701
1518
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   702
2534
f99578469d08 Further reorganisation and cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2533
diff changeset
   703
subsection {* fsubset *}
f99578469d08 Further reorganisation and cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2533
diff changeset
   704
f99578469d08 Further reorganisation and cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2533
diff changeset
   705
lemma fsubseteq_set: 
f99578469d08 Further reorganisation and cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2533
diff changeset
   706
  shows "xs |\<subseteq>| ys \<longleftrightarrow> fset xs \<subseteq> fset ys"
f99578469d08 Further reorganisation and cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2533
diff changeset
   707
  by (descending) (simp add: sub_list_def)
f99578469d08 Further reorganisation and cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2533
diff changeset
   708
f99578469d08 Further reorganisation and cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2533
diff changeset
   709
lemma fsubset_set: 
f99578469d08 Further reorganisation and cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2533
diff changeset
   710
  shows "xs |\<subset>| ys \<longleftrightarrow> fset xs \<subset> fset ys"
f99578469d08 Further reorganisation and cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2533
diff changeset
   711
  unfolding less_fset_def 
f99578469d08 Further reorganisation and cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2533
diff changeset
   712
  by (descending) (auto simp add: sub_list_def)
f99578469d08 Further reorganisation and cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2533
diff changeset
   713
f99578469d08 Further reorganisation and cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2533
diff changeset
   714
lemma fsubseteq_finsert:
f99578469d08 Further reorganisation and cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2533
diff changeset
   715
  shows "(finsert x xs) |\<subseteq>| ys \<longleftrightarrow> x |\<in>| ys \<and> xs |\<subseteq>| ys"
f99578469d08 Further reorganisation and cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2533
diff changeset
   716
  by (descending) (simp add: sub_list_def memb_def)
f99578469d08 Further reorganisation and cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2533
diff changeset
   717
f99578469d08 Further reorganisation and cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2533
diff changeset
   718
lemma fsubset_fin: 
f99578469d08 Further reorganisation and cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2533
diff changeset
   719
  shows "xs |\<subseteq>| ys = (\<forall>x. x |\<in>| xs \<longrightarrow> x |\<in>| ys)"
f99578469d08 Further reorganisation and cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2533
diff changeset
   720
  by (descending) (auto simp add: sub_list_def memb_def)
f99578469d08 Further reorganisation and cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2533
diff changeset
   721
f99578469d08 Further reorganisation and cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2533
diff changeset
   722
lemma fsubseteq_fempty:
f99578469d08 Further reorganisation and cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2533
diff changeset
   723
  shows "xs |\<subseteq>| {||} \<longleftrightarrow> xs = {||}"
f99578469d08 Further reorganisation and cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2533
diff changeset
   724
  by (descending) (simp add: sub_list_def)
f99578469d08 Further reorganisation and cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2533
diff changeset
   725
f99578469d08 Further reorganisation and cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2533
diff changeset
   726
lemma not_fsubset_fnil: 
f99578469d08 Further reorganisation and cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2533
diff changeset
   727
  shows "\<not> xs |\<subset>| {||}"
f99578469d08 Further reorganisation and cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2533
diff changeset
   728
  by (metis fset_simps(1) fsubset_set not_psubset_empty)
f99578469d08 Further reorganisation and cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2533
diff changeset
   729
f99578469d08 Further reorganisation and cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2533
diff changeset
   730
f99578469d08 Further reorganisation and cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2533
diff changeset
   731
section {* fmap *}
f99578469d08 Further reorganisation and cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2533
diff changeset
   732
f99578469d08 Further reorganisation and cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2533
diff changeset
   733
lemma fmap_simps [simp]:
f99578469d08 Further reorganisation and cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2533
diff changeset
   734
   shows "fmap f {||} = {||}"
f99578469d08 Further reorganisation and cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2533
diff changeset
   735
  and   "fmap f (finsert x S) = finsert (f x) (fmap f S)"
f99578469d08 Further reorganisation and cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2533
diff changeset
   736
  by (descending, simp)+
f99578469d08 Further reorganisation and cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2533
diff changeset
   737
f99578469d08 Further reorganisation and cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2533
diff changeset
   738
lemma fmap_set_image [simp]:
f99578469d08 Further reorganisation and cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2533
diff changeset
   739
  shows "fset (fmap f S) = f ` (fset S)"
f99578469d08 Further reorganisation and cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2533
diff changeset
   740
  by (descending) (simp)
f99578469d08 Further reorganisation and cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2533
diff changeset
   741
f99578469d08 Further reorganisation and cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2533
diff changeset
   742
lemma inj_fmap_eq_iff:
f99578469d08 Further reorganisation and cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2533
diff changeset
   743
  shows "inj f \<Longrightarrow> fmap f S = fmap f T \<longleftrightarrow> S = T"
f99578469d08 Further reorganisation and cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2533
diff changeset
   744
  by (descending) (metis inj_vimage_image_eq list_eq.simps set_map)
f99578469d08 Further reorganisation and cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2533
diff changeset
   745
f99578469d08 Further reorganisation and cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2533
diff changeset
   746
lemma fmap_funion: 
f99578469d08 Further reorganisation and cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2533
diff changeset
   747
  shows "fmap f (S |\<union>| T) = fmap f S |\<union>| fmap f T"
f99578469d08 Further reorganisation and cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2533
diff changeset
   748
  by (descending) (simp)
f99578469d08 Further reorganisation and cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2533
diff changeset
   749
f99578469d08 Further reorganisation and cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2533
diff changeset
   750
f99578469d08 Further reorganisation and cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2533
diff changeset
   751
subsection {* fcard *}
f99578469d08 Further reorganisation and cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2533
diff changeset
   752
f99578469d08 Further reorganisation and cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2533
diff changeset
   753
lemma fcard_set: 
f99578469d08 Further reorganisation and cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2533
diff changeset
   754
  shows "fcard xs = card (fset xs)"
2536
98e84b56543f renamed fcard_raw to card_list
Christian Urban <urbanc@in.tum.de>
parents: 2534
diff changeset
   755
  by (lifting card_list_def)
1518
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   756
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   757
lemma fcard_finsert_if [simp]:
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   758
  shows "fcard (finsert x S) = (if x |\<in>| S then fcard S else Suc (fcard S))"
2536
98e84b56543f renamed fcard_raw to card_list
Christian Urban <urbanc@in.tum.de>
parents: 2534
diff changeset
   759
  by (descending) (auto simp add: card_list_def memb_def insert_absorb)
1518
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   760
2530
3b8741ecfda3 FSet synchronizing
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2529
diff changeset
   761
lemma fcard_0[simp]:
2524
693562f03eee major reorganisation of fset (renamed fset_to_set to fset, changed the definition of list_eq and fcard_raw)
Christian Urban <urbanc@in.tum.de>
parents: 2479
diff changeset
   762
  shows "fcard S = 0 \<longleftrightarrow> S = {||}"
2536
98e84b56543f renamed fcard_raw to card_list
Christian Urban <urbanc@in.tum.de>
parents: 2534
diff changeset
   763
  by (descending) (simp add: card_list_def)
2524
693562f03eee major reorganisation of fset (renamed fset_to_set to fset, changed the definition of list_eq and fcard_raw)
Christian Urban <urbanc@in.tum.de>
parents: 2479
diff changeset
   764
693562f03eee major reorganisation of fset (renamed fset_to_set to fset, changed the definition of list_eq and fcard_raw)
Christian Urban <urbanc@in.tum.de>
parents: 2479
diff changeset
   765
lemma fcard_fempty[simp]:
693562f03eee major reorganisation of fset (renamed fset_to_set to fset, changed the definition of list_eq and fcard_raw)
Christian Urban <urbanc@in.tum.de>
parents: 2479
diff changeset
   766
  shows "fcard {||} = 0"
693562f03eee major reorganisation of fset (renamed fset_to_set to fset, changed the definition of list_eq and fcard_raw)
Christian Urban <urbanc@in.tum.de>
parents: 2479
diff changeset
   767
  by (simp add: fcard_0)
1813
69fff336dd18 Porting lemmas from Quotient package FSet to new FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1682
diff changeset
   768
1821
Christian Urban <urbanc@in.tum.de>
parents: 1820
diff changeset
   769
lemma fcard_1:
2524
693562f03eee major reorganisation of fset (renamed fset_to_set to fset, changed the definition of list_eq and fcard_raw)
Christian Urban <urbanc@in.tum.de>
parents: 2479
diff changeset
   770
  shows "fcard S = 1 \<longleftrightarrow> (\<exists>x. S = {|x|})"
2536
98e84b56543f renamed fcard_raw to card_list
Christian Urban <urbanc@in.tum.de>
parents: 2534
diff changeset
   771
  by (descending) (auto simp add: card_list_def card_Suc_eq)
1819
63dd459dbc0d Much more in FSet (currently non-working)
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1817
diff changeset
   772
2084
72b777cc5479 Synchronize FSet with repository
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1952
diff changeset
   773
lemma fcard_gt_0:
2524
693562f03eee major reorganisation of fset (renamed fset_to_set to fset, changed the definition of list_eq and fcard_raw)
Christian Urban <urbanc@in.tum.de>
parents: 2479
diff changeset
   774
  shows "x \<in> fset S \<Longrightarrow> 0 < fcard S"
2536
98e84b56543f renamed fcard_raw to card_list
Christian Urban <urbanc@in.tum.de>
parents: 2534
diff changeset
   775
  by (descending) (auto simp add: card_list_def card_gt_0_iff)
2524
693562f03eee major reorganisation of fset (renamed fset_to_set to fset, changed the definition of list_eq and fcard_raw)
Christian Urban <urbanc@in.tum.de>
parents: 2479
diff changeset
   776
  
2084
72b777cc5479 Synchronize FSet with repository
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1952
diff changeset
   777
lemma fcard_not_fin:
2531
8054f4988672 FSet: stronger fact in Isabelle.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2530
diff changeset
   778
  shows "(x |\<notin>| S) = (fcard (finsert x S) = Suc (fcard S))"
2536
98e84b56543f renamed fcard_raw to card_list
Christian Urban <urbanc@in.tum.de>
parents: 2534
diff changeset
   779
  by (descending) (auto simp add: memb_def card_list_def insert_absorb)
1813
69fff336dd18 Porting lemmas from Quotient package FSet to new FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1682
diff changeset
   780
2524
693562f03eee major reorganisation of fset (renamed fset_to_set to fset, changed the definition of list_eq and fcard_raw)
Christian Urban <urbanc@in.tum.de>
parents: 2479
diff changeset
   781
lemma fcard_suc: 
693562f03eee major reorganisation of fset (renamed fset_to_set to fset, changed the definition of list_eq and fcard_raw)
Christian Urban <urbanc@in.tum.de>
parents: 2479
diff changeset
   782
  shows "fcard S = Suc n \<Longrightarrow> \<exists>x T. x |\<notin>| T \<and> S = finsert x T \<and> fcard T = n"
693562f03eee major reorganisation of fset (renamed fset_to_set to fset, changed the definition of list_eq and fcard_raw)
Christian Urban <urbanc@in.tum.de>
parents: 2479
diff changeset
   783
  apply(descending)
2536
98e84b56543f renamed fcard_raw to card_list
Christian Urban <urbanc@in.tum.de>
parents: 2534
diff changeset
   784
  apply(auto simp add: card_list_def memb_def)
2524
693562f03eee major reorganisation of fset (renamed fset_to_set to fset, changed the definition of list_eq and fcard_raw)
Christian Urban <urbanc@in.tum.de>
parents: 2479
diff changeset
   785
  apply(drule card_eq_SucD)
693562f03eee major reorganisation of fset (renamed fset_to_set to fset, changed the definition of list_eq and fcard_raw)
Christian Urban <urbanc@in.tum.de>
parents: 2479
diff changeset
   786
  apply(auto)
693562f03eee major reorganisation of fset (renamed fset_to_set to fset, changed the definition of list_eq and fcard_raw)
Christian Urban <urbanc@in.tum.de>
parents: 2479
diff changeset
   787
  apply(rule_tac x="b" in exI)
693562f03eee major reorganisation of fset (renamed fset_to_set to fset, changed the definition of list_eq and fcard_raw)
Christian Urban <urbanc@in.tum.de>
parents: 2479
diff changeset
   788
  apply(rule_tac x="removeAll b S" in exI)
693562f03eee major reorganisation of fset (renamed fset_to_set to fset, changed the definition of list_eq and fcard_raw)
Christian Urban <urbanc@in.tum.de>
parents: 2479
diff changeset
   789
  apply(auto)
693562f03eee major reorganisation of fset (renamed fset_to_set to fset, changed the definition of list_eq and fcard_raw)
Christian Urban <urbanc@in.tum.de>
parents: 2479
diff changeset
   790
  done
1813
69fff336dd18 Porting lemmas from Quotient package FSet to new FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1682
diff changeset
   791
1819
63dd459dbc0d Much more in FSet (currently non-working)
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1817
diff changeset
   792
lemma fcard_delete:
2534
f99578469d08 Further reorganisation and cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2533
diff changeset
   793
  shows "fcard (fdelete y S) = (if y |\<in>| S then fcard S - 1 else fcard S)"
2536
98e84b56543f renamed fcard_raw to card_list
Christian Urban <urbanc@in.tum.de>
parents: 2534
diff changeset
   794
  by (descending) (simp add: card_list_def memb_def)
1819
63dd459dbc0d Much more in FSet (currently non-working)
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1817
diff changeset
   795
2524
693562f03eee major reorganisation of fset (renamed fset_to_set to fset, changed the definition of list_eq and fcard_raw)
Christian Urban <urbanc@in.tum.de>
parents: 2479
diff changeset
   796
lemma fcard_suc_memb: 
693562f03eee major reorganisation of fset (renamed fset_to_set to fset, changed the definition of list_eq and fcard_raw)
Christian Urban <urbanc@in.tum.de>
parents: 2479
diff changeset
   797
  shows "fcard A = Suc n \<Longrightarrow> \<exists>a. a |\<in>| A"
693562f03eee major reorganisation of fset (renamed fset_to_set to fset, changed the definition of list_eq and fcard_raw)
Christian Urban <urbanc@in.tum.de>
parents: 2479
diff changeset
   798
  apply(descending)
2536
98e84b56543f renamed fcard_raw to card_list
Christian Urban <urbanc@in.tum.de>
parents: 2534
diff changeset
   799
  apply(simp add: card_list_def memb_def)
2524
693562f03eee major reorganisation of fset (renamed fset_to_set to fset, changed the definition of list_eq and fcard_raw)
Christian Urban <urbanc@in.tum.de>
parents: 2479
diff changeset
   800
  apply(drule card_eq_SucD)
693562f03eee major reorganisation of fset (renamed fset_to_set to fset, changed the definition of list_eq and fcard_raw)
Christian Urban <urbanc@in.tum.de>
parents: 2479
diff changeset
   801
  apply(auto)
693562f03eee major reorganisation of fset (renamed fset_to_set to fset, changed the definition of list_eq and fcard_raw)
Christian Urban <urbanc@in.tum.de>
parents: 2479
diff changeset
   802
  done
1878
c22947214948 2 more lifted lemmas needed for second representation
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1860
diff changeset
   803
2524
693562f03eee major reorganisation of fset (renamed fset_to_set to fset, changed the definition of list_eq and fcard_raw)
Christian Urban <urbanc@in.tum.de>
parents: 2479
diff changeset
   804
lemma fin_fcard_not_0: 
693562f03eee major reorganisation of fset (renamed fset_to_set to fset, changed the definition of list_eq and fcard_raw)
Christian Urban <urbanc@in.tum.de>
parents: 2479
diff changeset
   805
  shows "a |\<in>| A \<Longrightarrow> fcard A \<noteq> 0"
2536
98e84b56543f renamed fcard_raw to card_list
Christian Urban <urbanc@in.tum.de>
parents: 2534
diff changeset
   806
  by (descending) (auto simp add: card_list_def memb_def)
1878
c22947214948 2 more lifted lemmas needed for second representation
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1860
diff changeset
   807
2534
f99578469d08 Further reorganisation and cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2533
diff changeset
   808
lemma fcard_mono: 
f99578469d08 Further reorganisation and cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2533
diff changeset
   809
  shows "xs |\<subseteq>| ys \<Longrightarrow> fcard xs \<le> fcard ys"
f99578469d08 Further reorganisation and cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2533
diff changeset
   810
  unfolding fcard_set fsubseteq_set
f99578469d08 Further reorganisation and cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2533
diff changeset
   811
  by (simp add: card_mono[OF finite_fset])
2524
693562f03eee major reorganisation of fset (renamed fset_to_set to fset, changed the definition of list_eq and fcard_raw)
Christian Urban <urbanc@in.tum.de>
parents: 2479
diff changeset
   812
2534
f99578469d08 Further reorganisation and cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2533
diff changeset
   813
lemma fcard_fsubset_eq: 
f99578469d08 Further reorganisation and cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2533
diff changeset
   814
  shows "xs |\<subseteq>| ys \<Longrightarrow> fcard ys \<le> fcard xs \<Longrightarrow> xs = ys"
f99578469d08 Further reorganisation and cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2533
diff changeset
   815
  unfolding fcard_set fsubseteq_set
f99578469d08 Further reorganisation and cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2533
diff changeset
   816
  by (auto dest: card_seteq[OF finite_fset] simp add: fset_cong)
f99578469d08 Further reorganisation and cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2533
diff changeset
   817
f99578469d08 Further reorganisation and cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2533
diff changeset
   818
lemma psubset_fcard_mono: 
f99578469d08 Further reorganisation and cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2533
diff changeset
   819
  shows "xs |\<subset>| ys \<Longrightarrow> fcard xs < fcard ys"
f99578469d08 Further reorganisation and cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2533
diff changeset
   820
  unfolding fcard_set fsubset_set
f99578469d08 Further reorganisation and cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2533
diff changeset
   821
  by (rule psubset_card_mono[OF finite_fset])
f99578469d08 Further reorganisation and cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2533
diff changeset
   822
f99578469d08 Further reorganisation and cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2533
diff changeset
   823
lemma fcard_funion_finter: 
f99578469d08 Further reorganisation and cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2533
diff changeset
   824
  shows "fcard xs + fcard ys = fcard (xs |\<union>| ys) + fcard (xs |\<inter>| ys)"
f99578469d08 Further reorganisation and cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2533
diff changeset
   825
  unfolding fcard_set funion_set finter_set
f99578469d08 Further reorganisation and cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2533
diff changeset
   826
  by (rule card_Un_Int[OF finite_fset finite_fset])
f99578469d08 Further reorganisation and cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2533
diff changeset
   827
f99578469d08 Further reorganisation and cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2533
diff changeset
   828
lemma fcard_funion_disjoint: 
f99578469d08 Further reorganisation and cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2533
diff changeset
   829
  shows "xs |\<inter>| ys = {||} \<Longrightarrow> fcard (xs |\<union>| ys) = fcard xs + fcard ys"
f99578469d08 Further reorganisation and cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2533
diff changeset
   830
  unfolding fcard_set funion_set 
f99578469d08 Further reorganisation and cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2533
diff changeset
   831
  apply (rule card_Un_disjoint[OF finite_fset finite_fset])
f99578469d08 Further reorganisation and cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2533
diff changeset
   832
  by (metis finter_set fset_simps(1))
f99578469d08 Further reorganisation and cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2533
diff changeset
   833
f99578469d08 Further reorganisation and cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2533
diff changeset
   834
lemma fcard_delete1_less: 
f99578469d08 Further reorganisation and cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2533
diff changeset
   835
  shows "x |\<in>| xs \<Longrightarrow> fcard (fdelete x xs) < fcard xs"
f99578469d08 Further reorganisation and cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2533
diff changeset
   836
  unfolding fcard_set fin_set fdelete_set 
f99578469d08 Further reorganisation and cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2533
diff changeset
   837
  by (rule card_Diff1_less[OF finite_fset])
1518
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   838
2534
f99578469d08 Further reorganisation and cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2533
diff changeset
   839
lemma fcard_delete2_less: 
f99578469d08 Further reorganisation and cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2533
diff changeset
   840
  shows "x |\<in>| xs \<Longrightarrow> y |\<in>| xs \<Longrightarrow> fcard (fdelete y (fdelete x xs)) < fcard xs"
f99578469d08 Further reorganisation and cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2533
diff changeset
   841
  unfolding fcard_set fdelete_set fin_set
f99578469d08 Further reorganisation and cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2533
diff changeset
   842
  by (rule card_Diff2_less[OF finite_fset])
f99578469d08 Further reorganisation and cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2533
diff changeset
   843
f99578469d08 Further reorganisation and cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2533
diff changeset
   844
lemma fcard_delete1_le: 
f99578469d08 Further reorganisation and cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2533
diff changeset
   845
  shows "fcard (fdelete x xs) \<le> fcard xs"
f99578469d08 Further reorganisation and cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2533
diff changeset
   846
  unfolding fdelete_set fcard_set
f99578469d08 Further reorganisation and cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2533
diff changeset
   847
  by (rule card_Diff1_le[OF finite_fset])
f99578469d08 Further reorganisation and cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2533
diff changeset
   848
f99578469d08 Further reorganisation and cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2533
diff changeset
   849
lemma fcard_psubset: 
f99578469d08 Further reorganisation and cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2533
diff changeset
   850
  shows "ys |\<subseteq>| xs \<Longrightarrow> fcard ys < fcard xs \<Longrightarrow> ys |\<subset>| xs"
f99578469d08 Further reorganisation and cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2533
diff changeset
   851
  unfolding fcard_set fsubseteq_set fsubset_set
f99578469d08 Further reorganisation and cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2533
diff changeset
   852
  by (rule card_psubset[OF finite_fset])
f99578469d08 Further reorganisation and cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2533
diff changeset
   853
f99578469d08 Further reorganisation and cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2533
diff changeset
   854
lemma fcard_fmap_le: 
f99578469d08 Further reorganisation and cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2533
diff changeset
   855
  shows "fcard (fmap f xs) \<le> fcard xs"
f99578469d08 Further reorganisation and cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2533
diff changeset
   856
  unfolding fcard_set fmap_set_image
f99578469d08 Further reorganisation and cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2533
diff changeset
   857
  by (rule card_image_le[OF finite_fset])
f99578469d08 Further reorganisation and cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2533
diff changeset
   858
f99578469d08 Further reorganisation and cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2533
diff changeset
   859
lemma fcard_fminus_finsert[simp]:
f99578469d08 Further reorganisation and cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2533
diff changeset
   860
  assumes "a |\<in>| A" and "a |\<notin>| B"
f99578469d08 Further reorganisation and cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2533
diff changeset
   861
  shows "fcard (A - finsert a B) = fcard (A - B) - 1"
f99578469d08 Further reorganisation and cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2533
diff changeset
   862
  using assms 
f99578469d08 Further reorganisation and cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2533
diff changeset
   863
  unfolding fin_set fcard_set fminus_set
f99578469d08 Further reorganisation and cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2533
diff changeset
   864
  by (simp add: card_Diff_insert[OF finite_fset])
f99578469d08 Further reorganisation and cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2533
diff changeset
   865
f99578469d08 Further reorganisation and cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2533
diff changeset
   866
lemma fcard_fminus_fsubset:
f99578469d08 Further reorganisation and cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2533
diff changeset
   867
  assumes "B |\<subseteq>| A"
f99578469d08 Further reorganisation and cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2533
diff changeset
   868
  shows "fcard (A - B) = fcard A - fcard B"
f99578469d08 Further reorganisation and cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2533
diff changeset
   869
  using assms 
f99578469d08 Further reorganisation and cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2533
diff changeset
   870
  unfolding fsubseteq_set fcard_set fminus_set
f99578469d08 Further reorganisation and cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2533
diff changeset
   871
  by (rule card_Diff_subset[OF finite_fset])
1518
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   872
2534
f99578469d08 Further reorganisation and cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2533
diff changeset
   873
lemma fcard_fminus_subset_finter:
f99578469d08 Further reorganisation and cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2533
diff changeset
   874
  shows "fcard (A - B) = fcard A - fcard (A |\<inter>| B)"
f99578469d08 Further reorganisation and cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2533
diff changeset
   875
  unfolding finter_set fcard_set fminus_set
f99578469d08 Further reorganisation and cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2533
diff changeset
   876
  by (rule card_Diff_subset_Int) (simp)
f99578469d08 Further reorganisation and cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2533
diff changeset
   877
f99578469d08 Further reorganisation and cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2533
diff changeset
   878
f99578469d08 Further reorganisation and cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2533
diff changeset
   879
section {* fconcat *}
f99578469d08 Further reorganisation and cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2533
diff changeset
   880
f99578469d08 Further reorganisation and cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2533
diff changeset
   881
lemma fconcat_fempty:
f99578469d08 Further reorganisation and cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2533
diff changeset
   882
  shows "fconcat {||} = {||}"
f99578469d08 Further reorganisation and cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2533
diff changeset
   883
  by (lifting concat.simps(1))
f99578469d08 Further reorganisation and cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2533
diff changeset
   884
f99578469d08 Further reorganisation and cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2533
diff changeset
   885
lemma fconcat_finsert:
f99578469d08 Further reorganisation and cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2533
diff changeset
   886
  shows "fconcat (finsert x S) = x |\<union>| fconcat S"
f99578469d08 Further reorganisation and cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2533
diff changeset
   887
  by (lifting concat.simps(2))
f99578469d08 Further reorganisation and cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2533
diff changeset
   888
f99578469d08 Further reorganisation and cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2533
diff changeset
   889
lemma fconcat_finter:
f99578469d08 Further reorganisation and cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2533
diff changeset
   890
  shows "fconcat (xs |\<union>| ys) = fconcat xs |\<union>| fconcat ys"
f99578469d08 Further reorganisation and cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2533
diff changeset
   891
  by (lifting concat_append)
f99578469d08 Further reorganisation and cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2533
diff changeset
   892
f99578469d08 Further reorganisation and cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2533
diff changeset
   893
f99578469d08 Further reorganisation and cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2533
diff changeset
   894
section {* ffilter *}
f99578469d08 Further reorganisation and cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2533
diff changeset
   895
f99578469d08 Further reorganisation and cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2533
diff changeset
   896
lemma subseteq_filter: 
f99578469d08 Further reorganisation and cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2533
diff changeset
   897
  shows "ffilter P xs <= ffilter Q xs = (\<forall> x. x |\<in>| xs \<longrightarrow> P x \<longrightarrow> Q x)"
f99578469d08 Further reorganisation and cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2533
diff changeset
   898
  by  (descending) (auto simp add: memb_def sub_list_def)
f99578469d08 Further reorganisation and cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2533
diff changeset
   899
f99578469d08 Further reorganisation and cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2533
diff changeset
   900
lemma eq_ffilter: 
f99578469d08 Further reorganisation and cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2533
diff changeset
   901
  shows "(ffilter P xs = ffilter Q xs) = (\<forall>x. x |\<in>| xs \<longrightarrow> P x = Q x)"
f99578469d08 Further reorganisation and cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2533
diff changeset
   902
  by (descending) (auto simp add: memb_def)
1887
7abd8c1d9f4b Some new lemmas
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1886
diff changeset
   903
2534
f99578469d08 Further reorganisation and cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2533
diff changeset
   904
lemma subset_ffilter:
f99578469d08 Further reorganisation and cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2533
diff changeset
   905
  shows "(\<And>x. x |\<in>| xs \<Longrightarrow> P x \<Longrightarrow> Q x) \<Longrightarrow> (x |\<in>| xs & \<not> P x & Q x) \<Longrightarrow> ffilter P xs < ffilter Q xs"
f99578469d08 Further reorganisation and cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2533
diff changeset
   906
  unfolding less_fset_def by (auto simp add: subseteq_filter eq_ffilter)
f99578469d08 Further reorganisation and cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2533
diff changeset
   907
f99578469d08 Further reorganisation and cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2533
diff changeset
   908
f99578469d08 Further reorganisation and cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2533
diff changeset
   909
subsection {* ffold *}
f99578469d08 Further reorganisation and cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2533
diff changeset
   910
f99578469d08 Further reorganisation and cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2533
diff changeset
   911
lemma ffold_nil: 
f99578469d08 Further reorganisation and cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2533
diff changeset
   912
  shows "ffold f z {||} = z"
f99578469d08 Further reorganisation and cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2533
diff changeset
   913
  by (descending) (simp)
f99578469d08 Further reorganisation and cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2533
diff changeset
   914
f99578469d08 Further reorganisation and cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2533
diff changeset
   915
lemma ffold_finsert: "ffold f z (finsert a A) =
f99578469d08 Further reorganisation and cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2533
diff changeset
   916
  (if rsp_fold f then if a |\<in>| A then ffold f z A else f a (ffold f z A) else z)"
f99578469d08 Further reorganisation and cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2533
diff changeset
   917
  by (descending) (simp add: memb_def)
1887
7abd8c1d9f4b Some new lemmas
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1886
diff changeset
   918
2534
f99578469d08 Further reorganisation and cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2533
diff changeset
   919
lemma fin_commute_ffold:
f99578469d08 Further reorganisation and cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2533
diff changeset
   920
  "\<lbrakk>rsp_fold f; h |\<in>| b\<rbrakk> \<Longrightarrow> ffold f z b = f h (ffold f z (fdelete h b))"
2539
a8f5611dbd65 more cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2538
diff changeset
   921
  by (descending) (simp add: memb_def memb_commute_ffold_list)
2534
f99578469d08 Further reorganisation and cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2533
diff changeset
   922
f99578469d08 Further reorganisation and cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2533
diff changeset
   923
f99578469d08 Further reorganisation and cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2533
diff changeset
   924
subsection {* Choice in fsets *}
f99578469d08 Further reorganisation and cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2533
diff changeset
   925
f99578469d08 Further reorganisation and cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2533
diff changeset
   926
lemma fset_choice: 
f99578469d08 Further reorganisation and cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2533
diff changeset
   927
  assumes a: "\<forall>x. x |\<in>| A \<longrightarrow> (\<exists>y. P x y)"
f99578469d08 Further reorganisation and cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2533
diff changeset
   928
  shows "\<exists>f. \<forall>x. x |\<in>| A \<longrightarrow> P x (f x)"
f99578469d08 Further reorganisation and cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2533
diff changeset
   929
  using a
f99578469d08 Further reorganisation and cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2533
diff changeset
   930
  apply(descending)
f99578469d08 Further reorganisation and cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2533
diff changeset
   931
  using finite_set_choice
f99578469d08 Further reorganisation and cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2533
diff changeset
   932
  by (auto simp add: memb_def Ball_def)
f99578469d08 Further reorganisation and cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2533
diff changeset
   933
f99578469d08 Further reorganisation and cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2533
diff changeset
   934
2539
a8f5611dbd65 more cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2538
diff changeset
   935
section {* Induction and Cases rules for fsets *}
a8f5611dbd65 more cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2538
diff changeset
   936
a8f5611dbd65 more cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2538
diff changeset
   937
lemma fset_exhaust [case_names fempty finsert, cases type: fset]:
a8f5611dbd65 more cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2538
diff changeset
   938
  assumes fempty_case: "S = {||} \<Longrightarrow> P" 
a8f5611dbd65 more cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2538
diff changeset
   939
  and     finsert_case: "\<And>x S'. S = finsert x S' \<Longrightarrow> P"
a8f5611dbd65 more cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2538
diff changeset
   940
  shows "P"
a8f5611dbd65 more cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2538
diff changeset
   941
  using assms by (lifting list.exhaust)
2534
f99578469d08 Further reorganisation and cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2533
diff changeset
   942
2539
a8f5611dbd65 more cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2538
diff changeset
   943
lemma fset_induct [case_names fempty finsert]:
a8f5611dbd65 more cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2538
diff changeset
   944
  assumes fempty_case: "P {||}"
a8f5611dbd65 more cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2538
diff changeset
   945
  and     finsert_case: "\<And>x S. P S \<Longrightarrow> P (finsert x S)"
a8f5611dbd65 more cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2538
diff changeset
   946
  shows "P S"
a8f5611dbd65 more cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2538
diff changeset
   947
  using assms 
a8f5611dbd65 more cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2538
diff changeset
   948
  by (descending) (blast intro: list.induct)
a8f5611dbd65 more cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2538
diff changeset
   949
a8f5611dbd65 more cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2538
diff changeset
   950
lemma fset_induct_stronger [case_names fempty finsert, induct type: fset]:
a8f5611dbd65 more cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2538
diff changeset
   951
  assumes fempty_case: "P {||}"
a8f5611dbd65 more cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2538
diff changeset
   952
  and     finsert_case: "\<And>x S. \<lbrakk>x |\<notin>| S; P S\<rbrakk> \<Longrightarrow> P (finsert x S)"
a8f5611dbd65 more cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2538
diff changeset
   953
  shows "P S"
a8f5611dbd65 more cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2538
diff changeset
   954
proof(induct S rule: fset_induct)
a8f5611dbd65 more cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2538
diff changeset
   955
  case fempty
a8f5611dbd65 more cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2538
diff changeset
   956
  show "P {||}" using fempty_case by simp
a8f5611dbd65 more cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2538
diff changeset
   957
next
a8f5611dbd65 more cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2538
diff changeset
   958
  case (finsert x S)
a8f5611dbd65 more cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2538
diff changeset
   959
  have "P S" by fact
a8f5611dbd65 more cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2538
diff changeset
   960
  then show "P (finsert x S)" using finsert_case 
a8f5611dbd65 more cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2538
diff changeset
   961
    by (cases "x |\<in>| S") (simp_all)
a8f5611dbd65 more cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2538
diff changeset
   962
qed
1887
7abd8c1d9f4b Some new lemmas
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1886
diff changeset
   963
2539
a8f5611dbd65 more cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2538
diff changeset
   964
lemma fcard_induct:
a8f5611dbd65 more cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2538
diff changeset
   965
  assumes fempty_case: "P {||}"
a8f5611dbd65 more cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2538
diff changeset
   966
  and     fcard_Suc_case: "\<And>S T. Suc (fcard S) = (fcard T) \<Longrightarrow> P S \<Longrightarrow> P T"
a8f5611dbd65 more cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2538
diff changeset
   967
  shows "P S"
a8f5611dbd65 more cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2538
diff changeset
   968
proof (induct S)
a8f5611dbd65 more cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2538
diff changeset
   969
  case fempty
a8f5611dbd65 more cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2538
diff changeset
   970
  show "P {||}" by (rule fempty_case)
a8f5611dbd65 more cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2538
diff changeset
   971
next
a8f5611dbd65 more cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2538
diff changeset
   972
  case (finsert x S)
a8f5611dbd65 more cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2538
diff changeset
   973
  have h: "P S" by fact
a8f5611dbd65 more cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2538
diff changeset
   974
  have "x |\<notin>| S" by fact
a8f5611dbd65 more cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2538
diff changeset
   975
  then have "Suc (fcard S) = fcard (finsert x S)" 
a8f5611dbd65 more cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2538
diff changeset
   976
    using fcard_suc by auto
a8f5611dbd65 more cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2538
diff changeset
   977
  then show "P (finsert x S)" 
a8f5611dbd65 more cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2538
diff changeset
   978
    using h fcard_Suc_case by simp
a8f5611dbd65 more cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2538
diff changeset
   979
qed
2524
693562f03eee major reorganisation of fset (renamed fset_to_set to fset, changed the definition of list_eq and fcard_raw)
Christian Urban <urbanc@in.tum.de>
parents: 2479
diff changeset
   980
2539
a8f5611dbd65 more cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2538
diff changeset
   981
lemma fset_raw_strong_cases:
a8f5611dbd65 more cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2538
diff changeset
   982
  obtains "xs = []"
a8f5611dbd65 more cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2538
diff changeset
   983
    | x ys where "\<not> memb x ys" and "xs \<approx> x # ys"
a8f5611dbd65 more cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2538
diff changeset
   984
proof (induct xs arbitrary: x ys)
a8f5611dbd65 more cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2538
diff changeset
   985
  case Nil
a8f5611dbd65 more cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2538
diff changeset
   986
  then show thesis by simp
a8f5611dbd65 more cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2538
diff changeset
   987
next
a8f5611dbd65 more cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2538
diff changeset
   988
  case (Cons a xs)
a8f5611dbd65 more cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2538
diff changeset
   989
  have a: "\<lbrakk>xs = [] \<Longrightarrow> thesis; \<And>x ys. \<lbrakk>\<not> memb x ys; xs \<approx> x # ys\<rbrakk> \<Longrightarrow> thesis\<rbrakk> \<Longrightarrow> thesis" by fact
a8f5611dbd65 more cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2538
diff changeset
   990
  have b: "\<And>x' ys'. \<lbrakk>\<not> memb x' ys'; a # xs \<approx> x' # ys'\<rbrakk> \<Longrightarrow> thesis" by fact
a8f5611dbd65 more cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2538
diff changeset
   991
  have c: "xs = [] \<Longrightarrow> thesis" using b unfolding memb_def
a8f5611dbd65 more cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2538
diff changeset
   992
    by (metis in_set_conv_nth less_zeroE list.size(3) list_eq.simps member_set)
a8f5611dbd65 more cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2538
diff changeset
   993
  have "\<And>x ys. \<lbrakk>\<not> memb x ys; xs \<approx> x # ys\<rbrakk> \<Longrightarrow> thesis"
a8f5611dbd65 more cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2538
diff changeset
   994
  proof -
a8f5611dbd65 more cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2538
diff changeset
   995
    fix x :: 'a
a8f5611dbd65 more cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2538
diff changeset
   996
    fix ys :: "'a list"
a8f5611dbd65 more cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2538
diff changeset
   997
    assume d:"\<not> memb x ys"
a8f5611dbd65 more cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2538
diff changeset
   998
    assume e:"xs \<approx> x # ys"
a8f5611dbd65 more cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2538
diff changeset
   999
    show thesis
a8f5611dbd65 more cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2538
diff changeset
  1000
    proof (cases "x = a")
a8f5611dbd65 more cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2538
diff changeset
  1001
      assume h: "x = a"
a8f5611dbd65 more cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2538
diff changeset
  1002
      then have f: "\<not> memb a ys" using d by simp
a8f5611dbd65 more cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2538
diff changeset
  1003
      have g: "a # xs \<approx> a # ys" using e h by auto
a8f5611dbd65 more cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2538
diff changeset
  1004
      show thesis using b f g by simp
a8f5611dbd65 more cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2538
diff changeset
  1005
    next
a8f5611dbd65 more cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2538
diff changeset
  1006
      assume h: "x \<noteq> a"
a8f5611dbd65 more cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2538
diff changeset
  1007
      then have f: "\<not> memb x (a # ys)" using d unfolding memb_def by auto
a8f5611dbd65 more cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2538
diff changeset
  1008
      have g: "a # xs \<approx> x # (a # ys)" using e h by auto
a8f5611dbd65 more cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2538
diff changeset
  1009
      show thesis using b f g by simp
a8f5611dbd65 more cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2538
diff changeset
  1010
    qed
a8f5611dbd65 more cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2538
diff changeset
  1011
  qed
a8f5611dbd65 more cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2538
diff changeset
  1012
  then show thesis using a c by blast
a8f5611dbd65 more cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2538
diff changeset
  1013
qed
a8f5611dbd65 more cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2538
diff changeset
  1014
1518
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
  1015
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
  1016
lemma fset_strong_cases:
2084
72b777cc5479 Synchronize FSet with repository
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1952
diff changeset
  1017
  obtains "xs = {||}"
72b777cc5479 Synchronize FSet with repository
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1952
diff changeset
  1018
    | x ys where "x |\<notin>| ys" and "xs = finsert x ys"
1819
63dd459dbc0d Much more in FSet (currently non-working)
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1817
diff changeset
  1019
  by (lifting fset_raw_strong_cases)
1518
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
  1020
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
  1021
1533
5f5e99a11f66 A few more theorems in FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1518
diff changeset
  1022
lemma fset_induct2:
5f5e99a11f66 A few more theorems in FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1518
diff changeset
  1023
  "P {||} {||} \<Longrightarrow>
5f5e99a11f66 A few more theorems in FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1518
diff changeset
  1024
  (\<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
  1025
  (\<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
  1026
  (\<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
  1027
  P xsa ysa"
5f5e99a11f66 A few more theorems in FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1518
diff changeset
  1028
  apply (induct xsa arbitrary: ysa)
2539
a8f5611dbd65 more cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2538
diff changeset
  1029
  apply (induct_tac x rule: fset_induct_stronger)
1533
5f5e99a11f66 A few more theorems in FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1518
diff changeset
  1030
  apply simp_all
2539
a8f5611dbd65 more cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2538
diff changeset
  1031
  apply (induct_tac xa rule: fset_induct_stronger)
1533
5f5e99a11f66 A few more theorems in FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1518
diff changeset
  1032
  apply simp_all
5f5e99a11f66 A few more theorems in FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1518
diff changeset
  1033
  done
1518
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
  1034
2539
a8f5611dbd65 more cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2538
diff changeset
  1035
a8f5611dbd65 more cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2538
diff changeset
  1036
a8f5611dbd65 more cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2538
diff changeset
  1037
subsection {* alternate formulation with a different decomposition principle
a8f5611dbd65 more cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2538
diff changeset
  1038
  and a proof of equivalence *}
a8f5611dbd65 more cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2538
diff changeset
  1039
a8f5611dbd65 more cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2538
diff changeset
  1040
inductive
a8f5611dbd65 more cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2538
diff changeset
  1041
  list_eq2 ("_ \<approx>2 _")
a8f5611dbd65 more cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2538
diff changeset
  1042
where
a8f5611dbd65 more cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2538
diff changeset
  1043
  "(a # b # xs) \<approx>2 (b # a # xs)"
a8f5611dbd65 more cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2538
diff changeset
  1044
| "[] \<approx>2 []"
a8f5611dbd65 more cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2538
diff changeset
  1045
| "xs \<approx>2 ys \<Longrightarrow>  ys \<approx>2 xs"
a8f5611dbd65 more cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2538
diff changeset
  1046
| "(a # a # xs) \<approx>2 (a # xs)"
a8f5611dbd65 more cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2538
diff changeset
  1047
| "xs \<approx>2 ys \<Longrightarrow>  (a # xs) \<approx>2 (a # ys)"
a8f5611dbd65 more cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2538
diff changeset
  1048
| "\<lbrakk>xs1 \<approx>2 xs2;  xs2 \<approx>2 xs3\<rbrakk> \<Longrightarrow> xs1 \<approx>2 xs3"
a8f5611dbd65 more cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2538
diff changeset
  1049
a8f5611dbd65 more cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2538
diff changeset
  1050
lemma list_eq2_refl:
a8f5611dbd65 more cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2538
diff changeset
  1051
  shows "xs \<approx>2 xs"
a8f5611dbd65 more cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2538
diff changeset
  1052
  by (induct xs) (auto intro: list_eq2.intros)
a8f5611dbd65 more cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2538
diff changeset
  1053
a8f5611dbd65 more cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2538
diff changeset
  1054
lemma list_eq2_set:
a8f5611dbd65 more cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2538
diff changeset
  1055
  assumes a: "xs \<approx>2 ys"
a8f5611dbd65 more cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2538
diff changeset
  1056
  shows "set xs = set ys"
a8f5611dbd65 more cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2538
diff changeset
  1057
using a by (induct) (auto)
a8f5611dbd65 more cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2538
diff changeset
  1058
a8f5611dbd65 more cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2538
diff changeset
  1059
lemma list_eq2_card:
a8f5611dbd65 more cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2538
diff changeset
  1060
  assumes a: "xs \<approx>2 ys"
a8f5611dbd65 more cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2538
diff changeset
  1061
  shows "card_list xs = card_list ys"
a8f5611dbd65 more cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2538
diff changeset
  1062
using a 
a8f5611dbd65 more cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2538
diff changeset
  1063
apply(induct) 
a8f5611dbd65 more cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2538
diff changeset
  1064
apply(auto simp add: card_list_def)
a8f5611dbd65 more cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2538
diff changeset
  1065
apply(metis insert_commute)
a8f5611dbd65 more cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2538
diff changeset
  1066
apply(metis list_eq2_set)
a8f5611dbd65 more cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2538
diff changeset
  1067
done
a8f5611dbd65 more cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2538
diff changeset
  1068
a8f5611dbd65 more cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2538
diff changeset
  1069
lemma list_eq2_equiv1:
a8f5611dbd65 more cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2538
diff changeset
  1070
  assumes a: "xs \<approx>2 ys"
a8f5611dbd65 more cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2538
diff changeset
  1071
  shows "xs \<approx> ys"
a8f5611dbd65 more cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2538
diff changeset
  1072
using a by (induct) (auto)
a8f5611dbd65 more cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2538
diff changeset
  1073
a8f5611dbd65 more cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2538
diff changeset
  1074
a8f5611dbd65 more cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2538
diff changeset
  1075
lemma cons_delete_list_eq2:
a8f5611dbd65 more cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2538
diff changeset
  1076
  shows "(a # (removeAll a A)) \<approx>2 (if memb a A then A else a # A)"
a8f5611dbd65 more cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2538
diff changeset
  1077
  apply (induct A)
a8f5611dbd65 more cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2538
diff changeset
  1078
  apply (simp add: memb_def list_eq2_refl)
a8f5611dbd65 more cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2538
diff changeset
  1079
  apply (case_tac "memb a (aa # A)")
a8f5611dbd65 more cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2538
diff changeset
  1080
  apply (simp_all only: memb_def)
a8f5611dbd65 more cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2538
diff changeset
  1081
  apply (case_tac [!] "a = aa")
a8f5611dbd65 more cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2538
diff changeset
  1082
  apply (simp_all)
a8f5611dbd65 more cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2538
diff changeset
  1083
  apply (case_tac "memb a A")
a8f5611dbd65 more cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2538
diff changeset
  1084
  apply (auto simp add: memb_def)[2]
a8f5611dbd65 more cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2538
diff changeset
  1085
  apply (metis list_eq2.intros(3) list_eq2.intros(4) list_eq2.intros(5) list_eq2.intros(6))
a8f5611dbd65 more cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2538
diff changeset
  1086
  apply (metis list_eq2.intros(1) list_eq2.intros(5) list_eq2.intros(6))
a8f5611dbd65 more cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2538
diff changeset
  1087
  apply (auto simp add: list_eq2_refl memb_def)
a8f5611dbd65 more cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2538
diff changeset
  1088
  done
a8f5611dbd65 more cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2538
diff changeset
  1089
a8f5611dbd65 more cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2538
diff changeset
  1090
lemma memb_delete_list_eq2:
a8f5611dbd65 more cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2538
diff changeset
  1091
  assumes a: "memb e r"
a8f5611dbd65 more cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2538
diff changeset
  1092
  shows "(e # removeAll e r) \<approx>2 r"
a8f5611dbd65 more cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2538
diff changeset
  1093
  using a cons_delete_list_eq2[of e r]
a8f5611dbd65 more cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2538
diff changeset
  1094
  by simp
a8f5611dbd65 more cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2538
diff changeset
  1095
a8f5611dbd65 more cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2538
diff changeset
  1096
(*
a8f5611dbd65 more cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2538
diff changeset
  1097
lemma list_eq2_equiv2:
a8f5611dbd65 more cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2538
diff changeset
  1098
  assumes a: "xs \<approx> ys"
a8f5611dbd65 more cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2538
diff changeset
  1099
  shows "xs \<approx>2 ys"
a8f5611dbd65 more cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2538
diff changeset
  1100
using a
a8f5611dbd65 more cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2538
diff changeset
  1101
apply(induct xs arbitrary: ys taking: "card o set" rule: measure_induct)
a8f5611dbd65 more cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2538
diff changeset
  1102
apply(simp)
a8f5611dbd65 more cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2538
diff changeset
  1103
apply(case_tac x)
a8f5611dbd65 more cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2538
diff changeset
  1104
apply(simp)
a8f5611dbd65 more cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2538
diff changeset
  1105
apply(auto intro: list_eq2.intros)[1]
a8f5611dbd65 more cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2538
diff changeset
  1106
apply(simp)
a8f5611dbd65 more cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2538
diff changeset
  1107
apply(case_tac "a \<in> set list")
a8f5611dbd65 more cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2538
diff changeset
  1108
apply(simp add: insert_absorb)
a8f5611dbd65 more cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2538
diff changeset
  1109
apply(drule_tac x="removeAll a ys" in spec)
a8f5611dbd65 more cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2538
diff changeset
  1110
apply(drule mp)
a8f5611dbd65 more cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2538
diff changeset
  1111
apply(simp)
a8f5611dbd65 more cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2538
diff changeset
  1112
apply(subgoal_tac "0 < card (set ys)")
a8f5611dbd65 more cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2538
diff changeset
  1113
apply(simp)
a8f5611dbd65 more cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2538
diff changeset
  1114
apply(metis length_pos_if_in_set length_remdups_card_conv set_remdups)
a8f5611dbd65 more cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2538
diff changeset
  1115
apply(simp)
a8f5611dbd65 more cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2538
diff changeset
  1116
apply(clarify)
a8f5611dbd65 more cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2538
diff changeset
  1117
apply(drule_tac x="removeAll a list" in spec)
a8f5611dbd65 more cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2538
diff changeset
  1118
apply(drule mp)
a8f5611dbd65 more cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2538
diff changeset
  1119
apply(simp)
a8f5611dbd65 more cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2538
diff changeset
  1120
oops
a8f5611dbd65 more cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2538
diff changeset
  1121
*)
a8f5611dbd65 more cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2538
diff changeset
  1122
a8f5611dbd65 more cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2538
diff changeset
  1123
lemma list_eq2_equiv:
a8f5611dbd65 more cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2538
diff changeset
  1124
  "(l \<approx> r) \<longleftrightarrow> (list_eq2 l r)"
a8f5611dbd65 more cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2538
diff changeset
  1125
proof
a8f5611dbd65 more cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2538
diff changeset
  1126
  show "list_eq2 l r \<Longrightarrow> l \<approx> r" by (induct rule: list_eq2.induct) auto
2084
72b777cc5479 Synchronize FSet with repository
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1952
diff changeset
  1127
next
2539
a8f5611dbd65 more cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2538
diff changeset
  1128
  {
a8f5611dbd65 more cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2538
diff changeset
  1129
    fix n
a8f5611dbd65 more cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2538
diff changeset
  1130
    assume a: "card_list l = n" and b: "l \<approx> r"
a8f5611dbd65 more cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2538
diff changeset
  1131
    have "l \<approx>2 r"
a8f5611dbd65 more cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2538
diff changeset
  1132
      using a b
a8f5611dbd65 more cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2538
diff changeset
  1133
    proof (induct n arbitrary: l r)
a8f5611dbd65 more cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2538
diff changeset
  1134
      case 0
a8f5611dbd65 more cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2538
diff changeset
  1135
      have "card_list l = 0" by fact
a8f5611dbd65 more cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2538
diff changeset
  1136
      then have "\<forall>x. \<not> memb x l" unfolding card_list_def memb_def by auto
a8f5611dbd65 more cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2538
diff changeset
  1137
      then have z: "l = []" unfolding memb_def by auto
a8f5611dbd65 more cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2538
diff changeset
  1138
      then have "r = []" using `l \<approx> r` by simp
a8f5611dbd65 more cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2538
diff changeset
  1139
      then show ?case using z list_eq2_refl by simp
a8f5611dbd65 more cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2538
diff changeset
  1140
    next
a8f5611dbd65 more cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2538
diff changeset
  1141
      case (Suc m)
a8f5611dbd65 more cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2538
diff changeset
  1142
      have b: "l \<approx> r" by fact
a8f5611dbd65 more cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2538
diff changeset
  1143
      have d: "card_list l = Suc m" by fact
a8f5611dbd65 more cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2538
diff changeset
  1144
      then have "\<exists>a. memb a l" 
a8f5611dbd65 more cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2538
diff changeset
  1145
	apply(simp add: card_list_def memb_def)
a8f5611dbd65 more cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2538
diff changeset
  1146
	apply(drule card_eq_SucD)
a8f5611dbd65 more cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2538
diff changeset
  1147
	apply(blast)
a8f5611dbd65 more cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2538
diff changeset
  1148
	done
a8f5611dbd65 more cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2538
diff changeset
  1149
      then obtain a where e: "memb a l" by auto
a8f5611dbd65 more cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2538
diff changeset
  1150
      then have e': "memb a r" using list_eq.simps[simplified memb_def[symmetric], of l r] b 
a8f5611dbd65 more cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2538
diff changeset
  1151
	unfolding memb_def by auto
a8f5611dbd65 more cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2538
diff changeset
  1152
      have f: "card_list (removeAll a l) = m" using e d by (simp add: card_list_def memb_def)
a8f5611dbd65 more cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2538
diff changeset
  1153
      have g: "removeAll a l \<approx> removeAll a r" using removeAll_rsp b by simp
a8f5611dbd65 more cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2538
diff changeset
  1154
      have "list_eq2 (removeAll a l) (removeAll a r)" by (rule Suc.hyps[OF f g])
a8f5611dbd65 more cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2538
diff changeset
  1155
      then have h: "list_eq2 (a # removeAll a l) (a # removeAll a r)" by (rule list_eq2.intros(5))
a8f5611dbd65 more cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2538
diff changeset
  1156
      have i: "list_eq2 l (a # removeAll a l)"	
a8f5611dbd65 more cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2538
diff changeset
  1157
        by (rule list_eq2.intros(3)[OF memb_delete_list_eq2[OF e]])
a8f5611dbd65 more cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2538
diff changeset
  1158
      have "list_eq2 l (a # removeAll a r)" by (rule list_eq2.intros(6)[OF i h])
a8f5611dbd65 more cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2538
diff changeset
  1159
      then show ?case using list_eq2.intros(6)[OF _ memb_delete_list_eq2[OF e']] by simp
a8f5611dbd65 more cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2538
diff changeset
  1160
    qed
a8f5611dbd65 more cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2538
diff changeset
  1161
    }
a8f5611dbd65 more cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2538
diff changeset
  1162
  then show "l \<approx> r \<Longrightarrow> list_eq2 l r" by blast
2084
72b777cc5479 Synchronize FSet with repository
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1952
diff changeset
  1163
qed
72b777cc5479 Synchronize FSet with repository
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1952
diff changeset
  1164
2524
693562f03eee major reorganisation of fset (renamed fset_to_set to fset, changed the definition of list_eq and fcard_raw)
Christian Urban <urbanc@in.tum.de>
parents: 2479
diff changeset
  1165
1888
59f41804b3f8 Alternate list_eq and equivalence
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1887
diff changeset
  1166
(* 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
  1167
   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
  1168
   a different order *)
59f41804b3f8 Alternate list_eq and equivalence
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1887
diff changeset
  1169
lemma fset_eq_cases:
59f41804b3f8 Alternate list_eq and equivalence
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1887
diff changeset
  1170
 "\<lbrakk>a1 = a2;
59f41804b3f8 Alternate list_eq and equivalence
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1887
diff changeset
  1171
   \<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
  1172
   \<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
  1173
   \<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
  1174
   \<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
  1175
   \<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
  1176
  \<Longrightarrow> P"
59f41804b3f8 Alternate list_eq and equivalence
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1887
diff changeset
  1177
  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
  1178
59f41804b3f8 Alternate list_eq and equivalence
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1887
diff changeset
  1179
lemma fset_eq_induct:
59f41804b3f8 Alternate list_eq and equivalence
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1887
diff changeset
  1180
  assumes "x1 = x2"
59f41804b3f8 Alternate list_eq and equivalence
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1887
diff changeset
  1181
  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
  1182
  and "P {||} {||}"
59f41804b3f8 Alternate list_eq and equivalence
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1887
diff changeset
  1183
  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
  1184
  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
  1185
  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
  1186
  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
  1187
  shows "P x1 x2"
59f41804b3f8 Alternate list_eq and equivalence
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1887
diff changeset
  1188
  using assms
59f41804b3f8 Alternate list_eq and equivalence
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1887
diff changeset
  1189
  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
  1190
2524
693562f03eee major reorganisation of fset (renamed fset_to_set to fset, changed the definition of list_eq and fcard_raw)
Christian Urban <urbanc@in.tum.de>
parents: 2479
diff changeset
  1191
2326
b51532dd5689 Changes for PER and list_all2 committed to Isabelle
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2278
diff changeset
  1192
lemma list_all2_refl:
2266
dcffc2f132c9 Qpaper / Clarify the typing system and composition of quotients issue.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2250
diff changeset
  1193
  assumes q: "equivp R"
2326
b51532dd5689 Changes for PER and list_all2 committed to Isabelle
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2278
diff changeset
  1194
  shows "(list_all2 R) r r"
2378
2f13fe48c877 updated to new Isabelle; made FSet more "quiet"
Christian Urban <urbanc@in.tum.de>
parents: 2372
diff changeset
  1195
  by (rule list_all2_refl) (metis equivp_def q)
2266
dcffc2f132c9 Qpaper / Clarify the typing system and composition of quotients issue.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2250
diff changeset
  1196
dcffc2f132c9 Qpaper / Clarify the typing system and composition of quotients issue.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2250
diff changeset
  1197
lemma compose_list_refl2:
dcffc2f132c9 Qpaper / Clarify the typing system and composition of quotients issue.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2250
diff changeset
  1198
  assumes q: "equivp R"
2326
b51532dd5689 Changes for PER and list_all2 committed to Isabelle
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2278
diff changeset
  1199
  shows "(list_all2 R OOO op \<approx>) r r"
2266
dcffc2f132c9 Qpaper / Clarify the typing system and composition of quotients issue.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2250
diff changeset
  1200
proof
dcffc2f132c9 Qpaper / Clarify the typing system and composition of quotients issue.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2250
diff changeset
  1201
  have *: "r \<approx> r" by (rule equivp_reflp[OF fset_equivp])
2326
b51532dd5689 Changes for PER and list_all2 committed to Isabelle
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2278
diff changeset
  1202
  show "list_all2 R r r" by (rule list_all2_refl[OF q])
b51532dd5689 Changes for PER and list_all2 committed to Isabelle
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2278
diff changeset
  1203
  with * show "(op \<approx> OO list_all2 R) r r" ..
2266
dcffc2f132c9 Qpaper / Clarify the typing system and composition of quotients issue.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2250
diff changeset
  1204
qed
dcffc2f132c9 Qpaper / Clarify the typing system and composition of quotients issue.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2250
diff changeset
  1205
2285
965ee8f08d4c eliminated a quot_thm flag
Christian Urban <urbanc@in.tum.de>
parents: 2278
diff changeset
  1206
lemma quotient_compose_list_g:
2266
dcffc2f132c9 Qpaper / Clarify the typing system and composition of quotients issue.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2250
diff changeset
  1207
  assumes q: "Quotient R Abs Rep"
dcffc2f132c9 Qpaper / Clarify the typing system and composition of quotients issue.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2250
diff changeset
  1208
  and     e: "equivp R"
2326
b51532dd5689 Changes for PER and list_all2 committed to Isabelle
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2278
diff changeset
  1209
  shows  "Quotient ((list_all2 R) OOO (op \<approx>))
2266
dcffc2f132c9 Qpaper / Clarify the typing system and composition of quotients issue.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2250
diff changeset
  1210
    (abs_fset \<circ> (map Abs)) ((map Rep) \<circ> rep_fset)"
dcffc2f132c9 Qpaper / Clarify the typing system and composition of quotients issue.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2250
diff changeset
  1211
  unfolding Quotient_def comp_def
dcffc2f132c9 Qpaper / Clarify the typing system and composition of quotients issue.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2250
diff changeset
  1212
proof (intro conjI allI)
dcffc2f132c9 Qpaper / Clarify the typing system and composition of quotients issue.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2250
diff changeset
  1213
  fix a r s
dcffc2f132c9 Qpaper / Clarify the typing system and composition of quotients issue.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2250
diff changeset
  1214
  show "abs_fset (map Abs (map Rep (rep_fset a))) = a"
dcffc2f132c9 Qpaper / Clarify the typing system and composition of quotients issue.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2250
diff changeset
  1215
    by (simp add: abs_o_rep[OF q] Quotient_abs_rep[OF Quotient_fset] map_id)
2326
b51532dd5689 Changes for PER and list_all2 committed to Isabelle
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2278
diff changeset
  1216
  have b: "list_all2 R (map Rep (rep_fset a)) (map Rep (rep_fset a))"
b51532dd5689 Changes for PER and list_all2 committed to Isabelle
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2278
diff changeset
  1217
    by (rule list_all2_refl[OF e])
b51532dd5689 Changes for PER and list_all2 committed to Isabelle
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2278
diff changeset
  1218
  have c: "(op \<approx> OO list_all2 R) (map Rep (rep_fset a)) (map Rep (rep_fset a))"
2266
dcffc2f132c9 Qpaper / Clarify the typing system and composition of quotients issue.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2250
diff changeset
  1219
    by (rule, rule equivp_reflp[OF fset_equivp]) (rule b)
2326
b51532dd5689 Changes for PER and list_all2 committed to Isabelle
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2278
diff changeset
  1220
  show "(list_all2 R OOO op \<approx>) (map Rep (rep_fset a)) (map Rep (rep_fset a))"
b51532dd5689 Changes for PER and list_all2 committed to Isabelle
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2278
diff changeset
  1221
    by (rule, rule list_all2_refl[OF e]) (rule c)
b51532dd5689 Changes for PER and list_all2 committed to Isabelle
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2278
diff changeset
  1222
  show "(list_all2 R OOO op \<approx>) r s = ((list_all2 R OOO op \<approx>) r r \<and>
b51532dd5689 Changes for PER and list_all2 committed to Isabelle
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2278
diff changeset
  1223
        (list_all2 R OOO op \<approx>) s s \<and> abs_fset (map Abs r) = abs_fset (map Abs s))"
2266
dcffc2f132c9 Qpaper / Clarify the typing system and composition of quotients issue.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2250
diff changeset
  1224
  proof (intro iffI conjI)
2326
b51532dd5689 Changes for PER and list_all2 committed to Isabelle
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2278
diff changeset
  1225
    show "(list_all2 R OOO op \<approx>) r r" by (rule compose_list_refl2[OF e])
b51532dd5689 Changes for PER and list_all2 committed to Isabelle
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2278
diff changeset
  1226
    show "(list_all2 R OOO op \<approx>) s s" by (rule compose_list_refl2[OF e])
2266
dcffc2f132c9 Qpaper / Clarify the typing system and composition of quotients issue.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2250
diff changeset
  1227
  next
2326
b51532dd5689 Changes for PER and list_all2 committed to Isabelle
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2278
diff changeset
  1228
    assume a: "(list_all2 R OOO op \<approx>) r s"
2266
dcffc2f132c9 Qpaper / Clarify the typing system and composition of quotients issue.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2250
diff changeset
  1229
    then have b: "map Abs r \<approx> map Abs s"
dcffc2f132c9 Qpaper / Clarify the typing system and composition of quotients issue.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2250
diff changeset
  1230
    proof (elim pred_compE)
dcffc2f132c9 Qpaper / Clarify the typing system and composition of quotients issue.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2250
diff changeset
  1231
      fix b ba
2326
b51532dd5689 Changes for PER and list_all2 committed to Isabelle
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2278
diff changeset
  1232
      assume c: "list_all2 R r b"
2266
dcffc2f132c9 Qpaper / Clarify the typing system and composition of quotients issue.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2250
diff changeset
  1233
      assume d: "b \<approx> ba"
2326
b51532dd5689 Changes for PER and list_all2 committed to Isabelle
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2278
diff changeset
  1234
      assume e: "list_all2 R ba s"
2266
dcffc2f132c9 Qpaper / Clarify the typing system and composition of quotients issue.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2250
diff changeset
  1235
      have f: "map Abs r = map Abs b"
dcffc2f132c9 Qpaper / Clarify the typing system and composition of quotients issue.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2250
diff changeset
  1236
        using Quotient_rel[OF list_quotient[OF q]] c by blast
dcffc2f132c9 Qpaper / Clarify the typing system and composition of quotients issue.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2250
diff changeset
  1237
      have "map Abs ba = map Abs s"
dcffc2f132c9 Qpaper / Clarify the typing system and composition of quotients issue.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2250
diff changeset
  1238
        using Quotient_rel[OF list_quotient[OF q]] e by blast
dcffc2f132c9 Qpaper / Clarify the typing system and composition of quotients issue.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2250
diff changeset
  1239
      then have g: "map Abs s = map Abs ba" by simp
dcffc2f132c9 Qpaper / Clarify the typing system and composition of quotients issue.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2250
diff changeset
  1240
      then show "map Abs r \<approx> map Abs s" using d f map_rel_cong by simp
dcffc2f132c9 Qpaper / Clarify the typing system and composition of quotients issue.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2250
diff changeset
  1241
    qed
dcffc2f132c9 Qpaper / Clarify the typing system and composition of quotients issue.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2250
diff changeset
  1242
    then show "abs_fset (map Abs r) = abs_fset (map Abs s)"
dcffc2f132c9 Qpaper / Clarify the typing system and composition of quotients issue.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2250
diff changeset
  1243
      using Quotient_rel[OF Quotient_fset] by blast
dcffc2f132c9 Qpaper / Clarify the typing system and composition of quotients issue.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2250
diff changeset
  1244
  next
2326
b51532dd5689 Changes for PER and list_all2 committed to Isabelle
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2278
diff changeset
  1245
    assume a: "(list_all2 R OOO op \<approx>) r r \<and> (list_all2 R OOO op \<approx>) s s
2266
dcffc2f132c9 Qpaper / Clarify the typing system and composition of quotients issue.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2250
diff changeset
  1246
      \<and> abs_fset (map Abs r) = abs_fset (map Abs s)"
2326
b51532dd5689 Changes for PER and list_all2 committed to Isabelle
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2278
diff changeset
  1247
    then have s: "(list_all2 R OOO op \<approx>) s s" by simp
2266
dcffc2f132c9 Qpaper / Clarify the typing system and composition of quotients issue.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2250
diff changeset
  1248
    have d: "map Abs r \<approx> map Abs s"
dcffc2f132c9 Qpaper / Clarify the typing system and composition of quotients issue.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2250
diff changeset
  1249
      by (subst Quotient_rel[OF Quotient_fset]) (simp add: a)
dcffc2f132c9 Qpaper / Clarify the typing system and composition of quotients issue.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2250
diff changeset
  1250
    have b: "map Rep (map Abs r) \<approx> map Rep (map Abs s)"
dcffc2f132c9 Qpaper / Clarify the typing system and composition of quotients issue.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2250
diff changeset
  1251
      by (rule map_rel_cong[OF d])
2326
b51532dd5689 Changes for PER and list_all2 committed to Isabelle
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2278
diff changeset
  1252
    have y: "list_all2 R (map Rep (map Abs s)) s"
b51532dd5689 Changes for PER and list_all2 committed to Isabelle
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2278
diff changeset
  1253
      by (fact rep_abs_rsp_left[OF list_quotient[OF q], OF list_all2_refl[OF e, of s]])
b51532dd5689 Changes for PER and list_all2 committed to Isabelle
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2278
diff changeset
  1254
    have c: "(op \<approx> OO list_all2 R) (map Rep (map Abs r)) s"
2266
dcffc2f132c9 Qpaper / Clarify the typing system and composition of quotients issue.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2250
diff changeset
  1255
      by (rule pred_compI) (rule b, rule y)
2326
b51532dd5689 Changes for PER and list_all2 committed to Isabelle
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2278
diff changeset
  1256
    have z: "list_all2 R r (map Rep (map Abs r))"
b51532dd5689 Changes for PER and list_all2 committed to Isabelle
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2278
diff changeset
  1257
      by (fact rep_abs_rsp[OF list_quotient[OF q], OF list_all2_refl[OF e, of r]])
b51532dd5689 Changes for PER and list_all2 committed to Isabelle
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2278
diff changeset
  1258
    then show "(list_all2 R OOO op \<approx>) r s"
2266
dcffc2f132c9 Qpaper / Clarify the typing system and composition of quotients issue.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2250
diff changeset
  1259
      using a c pred_compI by simp
dcffc2f132c9 Qpaper / Clarify the typing system and composition of quotients issue.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2250
diff changeset
  1260
  qed
dcffc2f132c9 Qpaper / Clarify the typing system and composition of quotients issue.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2250
diff changeset
  1261
qed
dcffc2f132c9 Qpaper / Clarify the typing system and composition of quotients issue.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2250
diff changeset
  1262
2528
9bde8a508594 Partially merging changes from Isabelle
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2525
diff changeset
  1263
9bde8a508594 Partially merging changes from Isabelle
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2525
diff changeset
  1264
ML {*
9bde8a508594 Partially merging changes from Isabelle
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2525
diff changeset
  1265
fun dest_fsetT (Type (@{type_name fset}, [T])) = T
9bde8a508594 Partially merging changes from Isabelle
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2525
diff changeset
  1266
  | dest_fsetT T = raise TYPE ("dest_fsetT: fset type expected", [T], []);
9bde8a508594 Partially merging changes from Isabelle
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2525
diff changeset
  1267
*}
9bde8a508594 Partially merging changes from Isabelle
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2525
diff changeset
  1268
2266
dcffc2f132c9 Qpaper / Clarify the typing system and composition of quotients issue.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2250
diff changeset
  1269
no_notation
dcffc2f132c9 Qpaper / Clarify the typing system and composition of quotients issue.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2250
diff changeset
  1270
  list_eq (infix "\<approx>" 50)
2539
a8f5611dbd65 more cleaning
Christian Urban <urbanc@in.tum.de>
parents: 2538
diff changeset
  1271
and list_eq2 (infix "\<approx>2" 50)
2266
dcffc2f132c9 Qpaper / Clarify the typing system and composition of quotients issue.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2250
diff changeset
  1272
2234
8035515bbbc6 something about the quotient ype definitions
Christian Urban <urbanc@in.tum.de>
parents: 2222
diff changeset
  1273
end