src/HOL/Lifting_Set.thy
author paulson <lp15@cam.ac.uk>
Thu, 26 Sep 2024 14:44:37 +0100
changeset 80948 572970d15ab0
parent 74979 4d77dd3019d1
permissions -rw-r--r--
To tiny but maybe useful lemmas (moved in from the AFP, Word_Lib)
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
53012
cb82606b8215 move Lifting/Transfer relevant parts of Library/Quotient_* to Main
kuncar
parents:
diff changeset
     1
(*  Title:      HOL/Lifting_Set.thy
cb82606b8215 move Lifting/Transfer relevant parts of Library/Quotient_* to Main
kuncar
parents:
diff changeset
     2
    Author:     Brian Huffman and Ondrej Kuncar
cb82606b8215 move Lifting/Transfer relevant parts of Library/Quotient_* to Main
kuncar
parents:
diff changeset
     3
*)
cb82606b8215 move Lifting/Transfer relevant parts of Library/Quotient_* to Main
kuncar
parents:
diff changeset
     4
60758
d8d85a8172b5 isabelle update_cartouches;
wenzelm
parents: 60676
diff changeset
     5
section \<open>Setup for Lifting/Transfer for the set type\<close>
53012
cb82606b8215 move Lifting/Transfer relevant parts of Library/Quotient_* to Main
kuncar
parents:
diff changeset
     6
cb82606b8215 move Lifting/Transfer relevant parts of Library/Quotient_* to Main
kuncar
parents:
diff changeset
     7
theory Lifting_Set
74979
4d77dd3019d1 earlier availability of lifting
haftmann
parents: 73832
diff changeset
     8
imports Lifting Groups_Big
53012
cb82606b8215 move Lifting/Transfer relevant parts of Library/Quotient_* to Main
kuncar
parents:
diff changeset
     9
begin
cb82606b8215 move Lifting/Transfer relevant parts of Library/Quotient_* to Main
kuncar
parents:
diff changeset
    10
60758
d8d85a8172b5 isabelle update_cartouches;
wenzelm
parents: 60676
diff changeset
    11
subsection \<open>Relator and predicator properties\<close>
53012
cb82606b8215 move Lifting/Transfer relevant parts of Library/Quotient_* to Main
kuncar
parents:
diff changeset
    12
55938
f20d1db5aa3c renamed 'set_rel' to 'rel_set'
blanchet
parents: 55564
diff changeset
    13
lemma rel_setD1: "\<lbrakk> rel_set R A B; x \<in> A \<rbrakk> \<Longrightarrow> \<exists>y \<in> B. R x y"
f20d1db5aa3c renamed 'set_rel' to 'rel_set'
blanchet
parents: 55564
diff changeset
    14
  and rel_setD2: "\<lbrakk> rel_set R A B; y \<in> B \<rbrakk> \<Longrightarrow> \<exists>x \<in> A. R x y"
60676
92fd47ae2a67 tuned proofs;
wenzelm
parents: 60229
diff changeset
    15
  by (simp_all add: rel_set_def)
53927
abe2b313f0e5 add lemmas
Andreas Lochbihler
parents: 53012
diff changeset
    16
55938
f20d1db5aa3c renamed 'set_rel' to 'rel_set'
blanchet
parents: 55564
diff changeset
    17
lemma rel_set_conversep [simp]: "rel_set A\<inverse>\<inverse> = (rel_set A)\<inverse>\<inverse>"
f20d1db5aa3c renamed 'set_rel' to 'rel_set'
blanchet
parents: 55564
diff changeset
    18
  unfolding rel_set_def by auto
53012
cb82606b8215 move Lifting/Transfer relevant parts of Library/Quotient_* to Main
kuncar
parents:
diff changeset
    19
67399
eab6ce8368fa ran isabelle update_op on all sources
nipkow
parents: 64272
diff changeset
    20
lemma rel_set_eq [relator_eq]: "rel_set (=) = (=)"
55938
f20d1db5aa3c renamed 'set_rel' to 'rel_set'
blanchet
parents: 55564
diff changeset
    21
  unfolding rel_set_def fun_eq_iff by auto
53012
cb82606b8215 move Lifting/Transfer relevant parts of Library/Quotient_* to Main
kuncar
parents:
diff changeset
    22
55938
f20d1db5aa3c renamed 'set_rel' to 'rel_set'
blanchet
parents: 55564
diff changeset
    23
lemma rel_set_mono[relator_mono]:
53012
cb82606b8215 move Lifting/Transfer relevant parts of Library/Quotient_* to Main
kuncar
parents:
diff changeset
    24
  assumes "A \<le> B"
55938
f20d1db5aa3c renamed 'set_rel' to 'rel_set'
blanchet
parents: 55564
diff changeset
    25
  shows "rel_set A \<le> rel_set B"
60676
92fd47ae2a67 tuned proofs;
wenzelm
parents: 60229
diff changeset
    26
  using assms unfolding rel_set_def by blast
53012
cb82606b8215 move Lifting/Transfer relevant parts of Library/Quotient_* to Main
kuncar
parents:
diff changeset
    27
55938
f20d1db5aa3c renamed 'set_rel' to 'rel_set'
blanchet
parents: 55564
diff changeset
    28
lemma rel_set_OO[relator_distr]: "rel_set R OO rel_set S = rel_set (R OO S)"
53012
cb82606b8215 move Lifting/Transfer relevant parts of Library/Quotient_* to Main
kuncar
parents:
diff changeset
    29
  apply (rule sym)
60676
92fd47ae2a67 tuned proofs;
wenzelm
parents: 60229
diff changeset
    30
  apply (intro ext)
92fd47ae2a67 tuned proofs;
wenzelm
parents: 60229
diff changeset
    31
  subgoal for X Z
92fd47ae2a67 tuned proofs;
wenzelm
parents: 60229
diff changeset
    32
    apply (rule iffI)
92fd47ae2a67 tuned proofs;
wenzelm
parents: 60229
diff changeset
    33
    apply (rule relcomppI [where b="{y. (\<exists>x\<in>X. R x y) \<and> (\<exists>z\<in>Z. S y z)}"])
92fd47ae2a67 tuned proofs;
wenzelm
parents: 60229
diff changeset
    34
    apply (simp add: rel_set_def, fast)+
92fd47ae2a67 tuned proofs;
wenzelm
parents: 60229
diff changeset
    35
    done
53012
cb82606b8215 move Lifting/Transfer relevant parts of Library/Quotient_* to Main
kuncar
parents:
diff changeset
    36
  done
cb82606b8215 move Lifting/Transfer relevant parts of Library/Quotient_* to Main
kuncar
parents:
diff changeset
    37
cb82606b8215 move Lifting/Transfer relevant parts of Library/Quotient_* to Main
kuncar
parents:
diff changeset
    38
lemma Domainp_set[relator_domain]:
56520
3373f5d1e074 abstract Domainp in relator_domain rules => more natural statement of the rule
kuncar
parents: 56519
diff changeset
    39
  "Domainp (rel_set T) = (\<lambda>A. Ball A (Domainp T))"
60676
92fd47ae2a67 tuned proofs;
wenzelm
parents: 60229
diff changeset
    40
  unfolding rel_set_def Domainp_iff[abs_def]
92fd47ae2a67 tuned proofs;
wenzelm
parents: 60229
diff changeset
    41
  apply (intro ext)
92fd47ae2a67 tuned proofs;
wenzelm
parents: 60229
diff changeset
    42
  apply (rule iffI) 
92fd47ae2a67 tuned proofs;
wenzelm
parents: 60229
diff changeset
    43
  apply blast
92fd47ae2a67 tuned proofs;
wenzelm
parents: 60229
diff changeset
    44
  subgoal for A by (rule exI [where x="{y. \<exists>x\<in>A. T x y}"]) fast
92fd47ae2a67 tuned proofs;
wenzelm
parents: 60229
diff changeset
    45
  done
53012
cb82606b8215 move Lifting/Transfer relevant parts of Library/Quotient_* to Main
kuncar
parents:
diff changeset
    46
56518
beb3b6851665 left_total and left_unique rules are now transfer rules (cleaner solution, reflexvity_rule attribute not needed anymore)
kuncar
parents: 56482
diff changeset
    47
lemma left_total_rel_set[transfer_rule]: 
55938
f20d1db5aa3c renamed 'set_rel' to 'rel_set'
blanchet
parents: 55564
diff changeset
    48
  "left_total A \<Longrightarrow> left_total (rel_set A)"
f20d1db5aa3c renamed 'set_rel' to 'rel_set'
blanchet
parents: 55564
diff changeset
    49
  unfolding left_total_def rel_set_def
53012
cb82606b8215 move Lifting/Transfer relevant parts of Library/Quotient_* to Main
kuncar
parents:
diff changeset
    50
  apply safe
60676
92fd47ae2a67 tuned proofs;
wenzelm
parents: 60229
diff changeset
    51
  subgoal for X by (rule exI [where x="{y. \<exists>x\<in>X. A x y}"]) fast
92fd47ae2a67 tuned proofs;
wenzelm
parents: 60229
diff changeset
    52
  done
53012
cb82606b8215 move Lifting/Transfer relevant parts of Library/Quotient_* to Main
kuncar
parents:
diff changeset
    53
56518
beb3b6851665 left_total and left_unique rules are now transfer rules (cleaner solution, reflexvity_rule attribute not needed anymore)
kuncar
parents: 56482
diff changeset
    54
lemma left_unique_rel_set[transfer_rule]: 
55938
f20d1db5aa3c renamed 'set_rel' to 'rel_set'
blanchet
parents: 55564
diff changeset
    55
  "left_unique A \<Longrightarrow> left_unique (rel_set A)"
f20d1db5aa3c renamed 'set_rel' to 'rel_set'
blanchet
parents: 55564
diff changeset
    56
  unfolding left_unique_def rel_set_def
53012
cb82606b8215 move Lifting/Transfer relevant parts of Library/Quotient_* to Main
kuncar
parents:
diff changeset
    57
  by fast
cb82606b8215 move Lifting/Transfer relevant parts of Library/Quotient_* to Main
kuncar
parents:
diff changeset
    58
55938
f20d1db5aa3c renamed 'set_rel' to 'rel_set'
blanchet
parents: 55564
diff changeset
    59
lemma right_total_rel_set [transfer_rule]:
f20d1db5aa3c renamed 'set_rel' to 'rel_set'
blanchet
parents: 55564
diff changeset
    60
  "right_total A \<Longrightarrow> right_total (rel_set A)"
60676
92fd47ae2a67 tuned proofs;
wenzelm
parents: 60229
diff changeset
    61
  using left_total_rel_set[of "A\<inverse>\<inverse>"] by simp
53012
cb82606b8215 move Lifting/Transfer relevant parts of Library/Quotient_* to Main
kuncar
parents:
diff changeset
    62
55938
f20d1db5aa3c renamed 'set_rel' to 'rel_set'
blanchet
parents: 55564
diff changeset
    63
lemma right_unique_rel_set [transfer_rule]:
f20d1db5aa3c renamed 'set_rel' to 'rel_set'
blanchet
parents: 55564
diff changeset
    64
  "right_unique A \<Longrightarrow> right_unique (rel_set A)"
f20d1db5aa3c renamed 'set_rel' to 'rel_set'
blanchet
parents: 55564
diff changeset
    65
  unfolding right_unique_def rel_set_def by fast
53012
cb82606b8215 move Lifting/Transfer relevant parts of Library/Quotient_* to Main
kuncar
parents:
diff changeset
    66
55938
f20d1db5aa3c renamed 'set_rel' to 'rel_set'
blanchet
parents: 55564
diff changeset
    67
lemma bi_total_rel_set [transfer_rule]:
f20d1db5aa3c renamed 'set_rel' to 'rel_set'
blanchet
parents: 55564
diff changeset
    68
  "bi_total A \<Longrightarrow> bi_total (rel_set A)"
60676
92fd47ae2a67 tuned proofs;
wenzelm
parents: 60229
diff changeset
    69
  by(simp add: bi_total_alt_def left_total_rel_set right_total_rel_set)
53012
cb82606b8215 move Lifting/Transfer relevant parts of Library/Quotient_* to Main
kuncar
parents:
diff changeset
    70
55938
f20d1db5aa3c renamed 'set_rel' to 'rel_set'
blanchet
parents: 55564
diff changeset
    71
lemma bi_unique_rel_set [transfer_rule]:
f20d1db5aa3c renamed 'set_rel' to 'rel_set'
blanchet
parents: 55564
diff changeset
    72
  "bi_unique A \<Longrightarrow> bi_unique (rel_set A)"
f20d1db5aa3c renamed 'set_rel' to 'rel_set'
blanchet
parents: 55564
diff changeset
    73
  unfolding bi_unique_def rel_set_def by fast
53012
cb82606b8215 move Lifting/Transfer relevant parts of Library/Quotient_* to Main
kuncar
parents:
diff changeset
    74
56519
c1048f5bbb45 more appropriate name (Lifting.invariant -> eq_onp)
kuncar
parents: 56518
diff changeset
    75
lemma set_relator_eq_onp [relator_eq_onp]:
c1048f5bbb45 more appropriate name (Lifting.invariant -> eq_onp)
kuncar
parents: 56518
diff changeset
    76
  "rel_set (eq_onp P) = eq_onp (\<lambda>A. Ball A P)"
c1048f5bbb45 more appropriate name (Lifting.invariant -> eq_onp)
kuncar
parents: 56518
diff changeset
    77
  unfolding fun_eq_iff rel_set_def eq_onp_def Ball_def by fast
53012
cb82606b8215 move Lifting/Transfer relevant parts of Library/Quotient_* to Main
kuncar
parents:
diff changeset
    78
57129
7edb7550663e introduce more powerful reindexing rules for big operators
hoelzl
parents: 56524
diff changeset
    79
lemma bi_unique_rel_set_lemma:
7edb7550663e introduce more powerful reindexing rules for big operators
hoelzl
parents: 56524
diff changeset
    80
  assumes "bi_unique R" and "rel_set R X Y"
7edb7550663e introduce more powerful reindexing rules for big operators
hoelzl
parents: 56524
diff changeset
    81
  obtains f where "Y = image f X" and "inj_on f X" and "\<forall>x\<in>X. R x (f x)"
7edb7550663e introduce more powerful reindexing rules for big operators
hoelzl
parents: 56524
diff changeset
    82
proof
63040
eb4ddd18d635 eliminated old 'def';
wenzelm
parents: 62343
diff changeset
    83
  define f where "f x = (THE y. R x y)" for x
57129
7edb7550663e introduce more powerful reindexing rules for big operators
hoelzl
parents: 56524
diff changeset
    84
  { fix x assume "x \<in> X"
60758
d8d85a8172b5 isabelle update_cartouches;
wenzelm
parents: 60676
diff changeset
    85
    with \<open>rel_set R X Y\<close> \<open>bi_unique R\<close> have "R x (f x)"
57129
7edb7550663e introduce more powerful reindexing rules for big operators
hoelzl
parents: 56524
diff changeset
    86
      by (simp add: bi_unique_def rel_set_def f_def) (metis theI)
60758
d8d85a8172b5 isabelle update_cartouches;
wenzelm
parents: 60676
diff changeset
    87
    with assms \<open>x \<in> X\<close> 
57129
7edb7550663e introduce more powerful reindexing rules for big operators
hoelzl
parents: 56524
diff changeset
    88
    have  "R x (f x)" "\<forall>x'\<in>X. R x' (f x) \<longrightarrow> x = x'" "\<forall>y\<in>Y. R x y \<longrightarrow> y = f x" "f x \<in> Y"
7edb7550663e introduce more powerful reindexing rules for big operators
hoelzl
parents: 56524
diff changeset
    89
      by (fastforce simp add: bi_unique_def rel_set_def)+ }
7edb7550663e introduce more powerful reindexing rules for big operators
hoelzl
parents: 56524
diff changeset
    90
  note * = this
7edb7550663e introduce more powerful reindexing rules for big operators
hoelzl
parents: 56524
diff changeset
    91
  moreover
7edb7550663e introduce more powerful reindexing rules for big operators
hoelzl
parents: 56524
diff changeset
    92
  { fix y assume "y \<in> Y"
60758
d8d85a8172b5 isabelle update_cartouches;
wenzelm
parents: 60676
diff changeset
    93
    with \<open>rel_set R X Y\<close> *(3) \<open>y \<in> Y\<close> have "\<exists>x\<in>X. y = f x"
57129
7edb7550663e introduce more powerful reindexing rules for big operators
hoelzl
parents: 56524
diff changeset
    94
      by (fastforce simp: rel_set_def) }
7edb7550663e introduce more powerful reindexing rules for big operators
hoelzl
parents: 56524
diff changeset
    95
  ultimately show "\<forall>x\<in>X. R x (f x)" "Y = image f X" "inj_on f X"
7edb7550663e introduce more powerful reindexing rules for big operators
hoelzl
parents: 56524
diff changeset
    96
    by (auto simp: inj_on_def image_iff)
7edb7550663e introduce more powerful reindexing rules for big operators
hoelzl
parents: 56524
diff changeset
    97
qed
7edb7550663e introduce more powerful reindexing rules for big operators
hoelzl
parents: 56524
diff changeset
    98
60758
d8d85a8172b5 isabelle update_cartouches;
wenzelm
parents: 60676
diff changeset
    99
subsection \<open>Quotient theorem for the Lifting package\<close>
53012
cb82606b8215 move Lifting/Transfer relevant parts of Library/Quotient_* to Main
kuncar
parents:
diff changeset
   100
cb82606b8215 move Lifting/Transfer relevant parts of Library/Quotient_* to Main
kuncar
parents:
diff changeset
   101
lemma Quotient_set[quot_map]:
cb82606b8215 move Lifting/Transfer relevant parts of Library/Quotient_* to Main
kuncar
parents:
diff changeset
   102
  assumes "Quotient R Abs Rep T"
55938
f20d1db5aa3c renamed 'set_rel' to 'rel_set'
blanchet
parents: 55564
diff changeset
   103
  shows "Quotient (rel_set R) (image Abs) (image Rep) (rel_set T)"
53012
cb82606b8215 move Lifting/Transfer relevant parts of Library/Quotient_* to Main
kuncar
parents:
diff changeset
   104
  using assms unfolding Quotient_alt_def4
55938
f20d1db5aa3c renamed 'set_rel' to 'rel_set'
blanchet
parents: 55564
diff changeset
   105
  apply (simp add: rel_set_OO[symmetric])
60676
92fd47ae2a67 tuned proofs;
wenzelm
parents: 60229
diff changeset
   106
  apply (simp add: rel_set_def)
92fd47ae2a67 tuned proofs;
wenzelm
parents: 60229
diff changeset
   107
  apply fast
53012
cb82606b8215 move Lifting/Transfer relevant parts of Library/Quotient_* to Main
kuncar
parents:
diff changeset
   108
  done
cb82606b8215 move Lifting/Transfer relevant parts of Library/Quotient_* to Main
kuncar
parents:
diff changeset
   109
60676
92fd47ae2a67 tuned proofs;
wenzelm
parents: 60229
diff changeset
   110
60758
d8d85a8172b5 isabelle update_cartouches;
wenzelm
parents: 60676
diff changeset
   111
subsection \<open>Transfer rules for the Transfer package\<close>
53012
cb82606b8215 move Lifting/Transfer relevant parts of Library/Quotient_* to Main
kuncar
parents:
diff changeset
   112
60758
d8d85a8172b5 isabelle update_cartouches;
wenzelm
parents: 60676
diff changeset
   113
subsubsection \<open>Unconditional transfer rules\<close>
53012
cb82606b8215 move Lifting/Transfer relevant parts of Library/Quotient_* to Main
kuncar
parents:
diff changeset
   114
63343
fb5d8a50c641 bundle lifting_syntax;
wenzelm
parents: 63040
diff changeset
   115
context includes lifting_syntax
53012
cb82606b8215 move Lifting/Transfer relevant parts of Library/Quotient_* to Main
kuncar
parents:
diff changeset
   116
begin
60676
92fd47ae2a67 tuned proofs;
wenzelm
parents: 60229
diff changeset
   117
55938
f20d1db5aa3c renamed 'set_rel' to 'rel_set'
blanchet
parents: 55564
diff changeset
   118
lemma empty_transfer [transfer_rule]: "(rel_set A) {} {}"
f20d1db5aa3c renamed 'set_rel' to 'rel_set'
blanchet
parents: 55564
diff changeset
   119
  unfolding rel_set_def by simp
53012
cb82606b8215 move Lifting/Transfer relevant parts of Library/Quotient_* to Main
kuncar
parents:
diff changeset
   120
cb82606b8215 move Lifting/Transfer relevant parts of Library/Quotient_* to Main
kuncar
parents:
diff changeset
   121
lemma insert_transfer [transfer_rule]:
55938
f20d1db5aa3c renamed 'set_rel' to 'rel_set'
blanchet
parents: 55564
diff changeset
   122
  "(A ===> rel_set A ===> rel_set A) insert insert"
55945
e96383acecf9 renamed 'fun_rel' to 'rel_fun'
blanchet
parents: 55938
diff changeset
   123
  unfolding rel_fun_def rel_set_def by auto
53012
cb82606b8215 move Lifting/Transfer relevant parts of Library/Quotient_* to Main
kuncar
parents:
diff changeset
   124
cb82606b8215 move Lifting/Transfer relevant parts of Library/Quotient_* to Main
kuncar
parents:
diff changeset
   125
lemma union_transfer [transfer_rule]:
55938
f20d1db5aa3c renamed 'set_rel' to 'rel_set'
blanchet
parents: 55564
diff changeset
   126
  "(rel_set A ===> rel_set A ===> rel_set A) union union"
55945
e96383acecf9 renamed 'fun_rel' to 'rel_fun'
blanchet
parents: 55938
diff changeset
   127
  unfolding rel_fun_def rel_set_def by auto
53012
cb82606b8215 move Lifting/Transfer relevant parts of Library/Quotient_* to Main
kuncar
parents:
diff changeset
   128
cb82606b8215 move Lifting/Transfer relevant parts of Library/Quotient_* to Main
kuncar
parents:
diff changeset
   129
lemma Union_transfer [transfer_rule]:
55938
f20d1db5aa3c renamed 'set_rel' to 'rel_set'
blanchet
parents: 55564
diff changeset
   130
  "(rel_set (rel_set A) ===> rel_set A) Union Union"
55945
e96383acecf9 renamed 'fun_rel' to 'rel_fun'
blanchet
parents: 55938
diff changeset
   131
  unfolding rel_fun_def rel_set_def by simp fast
53012
cb82606b8215 move Lifting/Transfer relevant parts of Library/Quotient_* to Main
kuncar
parents:
diff changeset
   132
cb82606b8215 move Lifting/Transfer relevant parts of Library/Quotient_* to Main
kuncar
parents:
diff changeset
   133
lemma image_transfer [transfer_rule]:
55938
f20d1db5aa3c renamed 'set_rel' to 'rel_set'
blanchet
parents: 55564
diff changeset
   134
  "((A ===> B) ===> rel_set A ===> rel_set B) image image"
55945
e96383acecf9 renamed 'fun_rel' to 'rel_fun'
blanchet
parents: 55938
diff changeset
   135
  unfolding rel_fun_def rel_set_def by simp fast
53012
cb82606b8215 move Lifting/Transfer relevant parts of Library/Quotient_* to Main
kuncar
parents:
diff changeset
   136
69275
9bbd5497befd clarified status of legacy input abbreviations
haftmann
parents: 68521
diff changeset
   137
lemma UNION_transfer [transfer_rule]: \<comment> \<open>TODO deletion candidate\<close>
9bbd5497befd clarified status of legacy input abbreviations
haftmann
parents: 68521
diff changeset
   138
  "(rel_set A ===> (A ===> rel_set B) ===> rel_set B) (\<lambda>A f. \<Union>(f ` A)) (\<lambda>A f. \<Union>(f ` A))"
62343
24106dc44def prefer abbreviations for compound operators INFIMUM and SUPREMUM
haftmann
parents: 61952
diff changeset
   139
  by transfer_prover
53012
cb82606b8215 move Lifting/Transfer relevant parts of Library/Quotient_* to Main
kuncar
parents:
diff changeset
   140
cb82606b8215 move Lifting/Transfer relevant parts of Library/Quotient_* to Main
kuncar
parents:
diff changeset
   141
lemma Ball_transfer [transfer_rule]:
67399
eab6ce8368fa ran isabelle update_op on all sources
nipkow
parents: 64272
diff changeset
   142
  "(rel_set A ===> (A ===> (=)) ===> (=)) Ball Ball"
55945
e96383acecf9 renamed 'fun_rel' to 'rel_fun'
blanchet
parents: 55938
diff changeset
   143
  unfolding rel_set_def rel_fun_def by fast
53012
cb82606b8215 move Lifting/Transfer relevant parts of Library/Quotient_* to Main
kuncar
parents:
diff changeset
   144
cb82606b8215 move Lifting/Transfer relevant parts of Library/Quotient_* to Main
kuncar
parents:
diff changeset
   145
lemma Bex_transfer [transfer_rule]:
67399
eab6ce8368fa ran isabelle update_op on all sources
nipkow
parents: 64272
diff changeset
   146
  "(rel_set A ===> (A ===> (=)) ===> (=)) Bex Bex"
55945
e96383acecf9 renamed 'fun_rel' to 'rel_fun'
blanchet
parents: 55938
diff changeset
   147
  unfolding rel_set_def rel_fun_def by fast
53012
cb82606b8215 move Lifting/Transfer relevant parts of Library/Quotient_* to Main
kuncar
parents:
diff changeset
   148
cb82606b8215 move Lifting/Transfer relevant parts of Library/Quotient_* to Main
kuncar
parents:
diff changeset
   149
lemma Pow_transfer [transfer_rule]:
55938
f20d1db5aa3c renamed 'set_rel' to 'rel_set'
blanchet
parents: 55564
diff changeset
   150
  "(rel_set A ===> rel_set (rel_set A)) Pow Pow"
60676
92fd47ae2a67 tuned proofs;
wenzelm
parents: 60229
diff changeset
   151
  apply (rule rel_funI)
92fd47ae2a67 tuned proofs;
wenzelm
parents: 60229
diff changeset
   152
  apply (rule rel_setI)
92fd47ae2a67 tuned proofs;
wenzelm
parents: 60229
diff changeset
   153
  subgoal for X Y X'
92fd47ae2a67 tuned proofs;
wenzelm
parents: 60229
diff changeset
   154
    apply (rule rev_bexI [where x="{y\<in>Y. \<exists>x\<in>X'. A x y}"])
92fd47ae2a67 tuned proofs;
wenzelm
parents: 60229
diff changeset
   155
    apply clarsimp
92fd47ae2a67 tuned proofs;
wenzelm
parents: 60229
diff changeset
   156
    apply (simp add: rel_set_def)
92fd47ae2a67 tuned proofs;
wenzelm
parents: 60229
diff changeset
   157
    apply fast
92fd47ae2a67 tuned proofs;
wenzelm
parents: 60229
diff changeset
   158
    done
92fd47ae2a67 tuned proofs;
wenzelm
parents: 60229
diff changeset
   159
  subgoal for X Y Y'
92fd47ae2a67 tuned proofs;
wenzelm
parents: 60229
diff changeset
   160
    apply (rule rev_bexI [where x="{x\<in>X. \<exists>y\<in>Y'. A x y}"])
92fd47ae2a67 tuned proofs;
wenzelm
parents: 60229
diff changeset
   161
    apply clarsimp
92fd47ae2a67 tuned proofs;
wenzelm
parents: 60229
diff changeset
   162
    apply (simp add: rel_set_def)
92fd47ae2a67 tuned proofs;
wenzelm
parents: 60229
diff changeset
   163
    apply fast
92fd47ae2a67 tuned proofs;
wenzelm
parents: 60229
diff changeset
   164
    done
53012
cb82606b8215 move Lifting/Transfer relevant parts of Library/Quotient_* to Main
kuncar
parents:
diff changeset
   165
  done
cb82606b8215 move Lifting/Transfer relevant parts of Library/Quotient_* to Main
kuncar
parents:
diff changeset
   166
55938
f20d1db5aa3c renamed 'set_rel' to 'rel_set'
blanchet
parents: 55564
diff changeset
   167
lemma rel_set_transfer [transfer_rule]:
67399
eab6ce8368fa ran isabelle update_op on all sources
nipkow
parents: 64272
diff changeset
   168
  "((A ===> B ===> (=)) ===> rel_set A ===> rel_set B ===> (=)) rel_set rel_set"
55945
e96383acecf9 renamed 'fun_rel' to 'rel_fun'
blanchet
parents: 55938
diff changeset
   169
  unfolding rel_fun_def rel_set_def by fast
53012
cb82606b8215 move Lifting/Transfer relevant parts of Library/Quotient_* to Main
kuncar
parents:
diff changeset
   170
53952
b2781a3ce958 new parametricity rules and useful lemmas
kuncar
parents: 53945
diff changeset
   171
lemma bind_transfer [transfer_rule]:
55938
f20d1db5aa3c renamed 'set_rel' to 'rel_set'
blanchet
parents: 55564
diff changeset
   172
  "(rel_set A ===> (A ===> rel_set B) ===> rel_set B) Set.bind Set.bind"
56482
39ac12b655ab parametricity transfer rule for INFIMUM, SUPREMUM
haftmann
parents: 56218
diff changeset
   173
  unfolding bind_UNION [abs_def] by transfer_prover
39ac12b655ab parametricity transfer rule for INFIMUM, SUPREMUM
haftmann
parents: 56218
diff changeset
   174
69275
9bbd5497befd clarified status of legacy input abbreviations
haftmann
parents: 68521
diff changeset
   175
lemma INF_parametric [transfer_rule]: \<comment> \<open>TODO deletion candidate\<close>
9bbd5497befd clarified status of legacy input abbreviations
haftmann
parents: 68521
diff changeset
   176
  "(rel_set A ===> (A ===> HOL.eq) ===> HOL.eq) (\<lambda>A f. Inf (f ` A)) (\<lambda>A f. Inf (f ` A))"
62343
24106dc44def prefer abbreviations for compound operators INFIMUM and SUPREMUM
haftmann
parents: 61952
diff changeset
   177
  by transfer_prover
56482
39ac12b655ab parametricity transfer rule for INFIMUM, SUPREMUM
haftmann
parents: 56218
diff changeset
   178
69275
9bbd5497befd clarified status of legacy input abbreviations
haftmann
parents: 68521
diff changeset
   179
lemma SUP_parametric [transfer_rule]: \<comment> \<open>TODO deletion candidate\<close>
9bbd5497befd clarified status of legacy input abbreviations
haftmann
parents: 68521
diff changeset
   180
  "(rel_set R ===> (R ===> HOL.eq) ===> HOL.eq) (\<lambda>A f. Sup (f ` A)) (\<lambda>A f. Sup (f ` A))"
62343
24106dc44def prefer abbreviations for compound operators INFIMUM and SUPREMUM
haftmann
parents: 61952
diff changeset
   181
  by transfer_prover
56482
39ac12b655ab parametricity transfer rule for INFIMUM, SUPREMUM
haftmann
parents: 56218
diff changeset
   182
53952
b2781a3ce958 new parametricity rules and useful lemmas
kuncar
parents: 53945
diff changeset
   183
60758
d8d85a8172b5 isabelle update_cartouches;
wenzelm
parents: 60676
diff changeset
   184
subsubsection \<open>Rules requiring bi-unique, bi-total or right-total relations\<close>
53012
cb82606b8215 move Lifting/Transfer relevant parts of Library/Quotient_* to Main
kuncar
parents:
diff changeset
   185
cb82606b8215 move Lifting/Transfer relevant parts of Library/Quotient_* to Main
kuncar
parents:
diff changeset
   186
lemma member_transfer [transfer_rule]:
cb82606b8215 move Lifting/Transfer relevant parts of Library/Quotient_* to Main
kuncar
parents:
diff changeset
   187
  assumes "bi_unique A"
67399
eab6ce8368fa ran isabelle update_op on all sources
nipkow
parents: 64272
diff changeset
   188
  shows "(A ===> rel_set A ===> (=)) (\<in>) (\<in>)"
55945
e96383acecf9 renamed 'fun_rel' to 'rel_fun'
blanchet
parents: 55938
diff changeset
   189
  using assms unfolding rel_fun_def rel_set_def bi_unique_def by fast
53012
cb82606b8215 move Lifting/Transfer relevant parts of Library/Quotient_* to Main
kuncar
parents:
diff changeset
   190
cb82606b8215 move Lifting/Transfer relevant parts of Library/Quotient_* to Main
kuncar
parents:
diff changeset
   191
lemma right_total_Collect_transfer[transfer_rule]:
cb82606b8215 move Lifting/Transfer relevant parts of Library/Quotient_* to Main
kuncar
parents:
diff changeset
   192
  assumes "right_total A"
67399
eab6ce8368fa ran isabelle update_op on all sources
nipkow
parents: 64272
diff changeset
   193
  shows "((A ===> (=)) ===> rel_set A) (\<lambda>P. Collect (\<lambda>x. P x \<and> Domainp A x)) Collect"
55945
e96383acecf9 renamed 'fun_rel' to 'rel_fun'
blanchet
parents: 55938
diff changeset
   194
  using assms unfolding right_total_def rel_set_def rel_fun_def Domainp_iff by fast
53012
cb82606b8215 move Lifting/Transfer relevant parts of Library/Quotient_* to Main
kuncar
parents:
diff changeset
   195
cb82606b8215 move Lifting/Transfer relevant parts of Library/Quotient_* to Main
kuncar
parents:
diff changeset
   196
lemma Collect_transfer [transfer_rule]:
cb82606b8215 move Lifting/Transfer relevant parts of Library/Quotient_* to Main
kuncar
parents:
diff changeset
   197
  assumes "bi_total A"
67399
eab6ce8368fa ran isabelle update_op on all sources
nipkow
parents: 64272
diff changeset
   198
  shows "((A ===> (=)) ===> rel_set A) Collect Collect"
55945
e96383acecf9 renamed 'fun_rel' to 'rel_fun'
blanchet
parents: 55938
diff changeset
   199
  using assms unfolding rel_fun_def rel_set_def bi_total_def by fast
53012
cb82606b8215 move Lifting/Transfer relevant parts of Library/Quotient_* to Main
kuncar
parents:
diff changeset
   200
cb82606b8215 move Lifting/Transfer relevant parts of Library/Quotient_* to Main
kuncar
parents:
diff changeset
   201
lemma inter_transfer [transfer_rule]:
cb82606b8215 move Lifting/Transfer relevant parts of Library/Quotient_* to Main
kuncar
parents:
diff changeset
   202
  assumes "bi_unique A"
55938
f20d1db5aa3c renamed 'set_rel' to 'rel_set'
blanchet
parents: 55564
diff changeset
   203
  shows "(rel_set A ===> rel_set A ===> rel_set A) inter inter"
55945
e96383acecf9 renamed 'fun_rel' to 'rel_fun'
blanchet
parents: 55938
diff changeset
   204
  using assms unfolding rel_fun_def rel_set_def bi_unique_def by fast
53012
cb82606b8215 move Lifting/Transfer relevant parts of Library/Quotient_* to Main
kuncar
parents:
diff changeset
   205
cb82606b8215 move Lifting/Transfer relevant parts of Library/Quotient_* to Main
kuncar
parents:
diff changeset
   206
lemma Diff_transfer [transfer_rule]:
cb82606b8215 move Lifting/Transfer relevant parts of Library/Quotient_* to Main
kuncar
parents:
diff changeset
   207
  assumes "bi_unique A"
67399
eab6ce8368fa ran isabelle update_op on all sources
nipkow
parents: 64272
diff changeset
   208
  shows "(rel_set A ===> rel_set A ===> rel_set A) (-) (-)"
55945
e96383acecf9 renamed 'fun_rel' to 'rel_fun'
blanchet
parents: 55938
diff changeset
   209
  using assms unfolding rel_fun_def rel_set_def bi_unique_def
53012
cb82606b8215 move Lifting/Transfer relevant parts of Library/Quotient_* to Main
kuncar
parents:
diff changeset
   210
  unfolding Ball_def Bex_def Diff_eq
cb82606b8215 move Lifting/Transfer relevant parts of Library/Quotient_* to Main
kuncar
parents:
diff changeset
   211
  by (safe, simp, metis, simp, metis)
cb82606b8215 move Lifting/Transfer relevant parts of Library/Quotient_* to Main
kuncar
parents:
diff changeset
   212
cb82606b8215 move Lifting/Transfer relevant parts of Library/Quotient_* to Main
kuncar
parents:
diff changeset
   213
lemma subset_transfer [transfer_rule]:
cb82606b8215 move Lifting/Transfer relevant parts of Library/Quotient_* to Main
kuncar
parents:
diff changeset
   214
  assumes [transfer_rule]: "bi_unique A"
67399
eab6ce8368fa ran isabelle update_op on all sources
nipkow
parents: 64272
diff changeset
   215
  shows "(rel_set A ===> rel_set A ===> (=)) (\<subseteq>) (\<subseteq>)"
53012
cb82606b8215 move Lifting/Transfer relevant parts of Library/Quotient_* to Main
kuncar
parents:
diff changeset
   216
  unfolding subset_eq [abs_def] by transfer_prover
cb82606b8215 move Lifting/Transfer relevant parts of Library/Quotient_* to Main
kuncar
parents:
diff changeset
   217
70927
cc204e10385c tuned syntax
haftmann
parents: 69275
diff changeset
   218
context
cc204e10385c tuned syntax
haftmann
parents: 69275
diff changeset
   219
  includes lifting_syntax
cc204e10385c tuned syntax
haftmann
parents: 69275
diff changeset
   220
begin
cc204e10385c tuned syntax
haftmann
parents: 69275
diff changeset
   221
68521
1bad08165162 added lemmas and transfer rules
immler
parents: 67399
diff changeset
   222
lemma strict_subset_transfer [transfer_rule]:
1bad08165162 added lemmas and transfer rules
immler
parents: 67399
diff changeset
   223
  assumes [transfer_rule]: "bi_unique A"
1bad08165162 added lemmas and transfer rules
immler
parents: 67399
diff changeset
   224
  shows "(rel_set A ===> rel_set A ===> (=)) (\<subset>) (\<subset>)"
1bad08165162 added lemmas and transfer rules
immler
parents: 67399
diff changeset
   225
  unfolding subset_not_subset_eq by transfer_prover
1bad08165162 added lemmas and transfer rules
immler
parents: 67399
diff changeset
   226
70927
cc204e10385c tuned syntax
haftmann
parents: 69275
diff changeset
   227
end
cc204e10385c tuned syntax
haftmann
parents: 69275
diff changeset
   228
60229
4cd6462c1fda Workaround that allows us to execute lifted constants that have as a return type a datatype containing a subtype
kuncar
parents: 60057
diff changeset
   229
declare right_total_UNIV_transfer[transfer_rule]
53012
cb82606b8215 move Lifting/Transfer relevant parts of Library/Quotient_* to Main
kuncar
parents:
diff changeset
   230
cb82606b8215 move Lifting/Transfer relevant parts of Library/Quotient_* to Main
kuncar
parents:
diff changeset
   231
lemma UNIV_transfer [transfer_rule]:
cb82606b8215 move Lifting/Transfer relevant parts of Library/Quotient_* to Main
kuncar
parents:
diff changeset
   232
  assumes "bi_total A"
55938
f20d1db5aa3c renamed 'set_rel' to 'rel_set'
blanchet
parents: 55564
diff changeset
   233
  shows "(rel_set A) UNIV UNIV"
f20d1db5aa3c renamed 'set_rel' to 'rel_set'
blanchet
parents: 55564
diff changeset
   234
  using assms unfolding rel_set_def bi_total_def by simp
53012
cb82606b8215 move Lifting/Transfer relevant parts of Library/Quotient_* to Main
kuncar
parents:
diff changeset
   235
cb82606b8215 move Lifting/Transfer relevant parts of Library/Quotient_* to Main
kuncar
parents:
diff changeset
   236
lemma right_total_Compl_transfer [transfer_rule]:
cb82606b8215 move Lifting/Transfer relevant parts of Library/Quotient_* to Main
kuncar
parents:
diff changeset
   237
  assumes [transfer_rule]: "bi_unique A" and [transfer_rule]: "right_total A"
55938
f20d1db5aa3c renamed 'set_rel' to 'rel_set'
blanchet
parents: 55564
diff changeset
   238
  shows "(rel_set A ===> rel_set A) (\<lambda>S. uminus S \<inter> Collect (Domainp A)) uminus"
53012
cb82606b8215 move Lifting/Transfer relevant parts of Library/Quotient_* to Main
kuncar
parents:
diff changeset
   239
  unfolding Compl_eq [abs_def]
cb82606b8215 move Lifting/Transfer relevant parts of Library/Quotient_* to Main
kuncar
parents:
diff changeset
   240
  by (subst Collect_conj_eq[symmetric]) transfer_prover
cb82606b8215 move Lifting/Transfer relevant parts of Library/Quotient_* to Main
kuncar
parents:
diff changeset
   241
cb82606b8215 move Lifting/Transfer relevant parts of Library/Quotient_* to Main
kuncar
parents:
diff changeset
   242
lemma Compl_transfer [transfer_rule]:
cb82606b8215 move Lifting/Transfer relevant parts of Library/Quotient_* to Main
kuncar
parents:
diff changeset
   243
  assumes [transfer_rule]: "bi_unique A" and [transfer_rule]: "bi_total A"
55938
f20d1db5aa3c renamed 'set_rel' to 'rel_set'
blanchet
parents: 55564
diff changeset
   244
  shows "(rel_set A ===> rel_set A) uminus uminus"
53012
cb82606b8215 move Lifting/Transfer relevant parts of Library/Quotient_* to Main
kuncar
parents:
diff changeset
   245
  unfolding Compl_eq [abs_def] by transfer_prover
cb82606b8215 move Lifting/Transfer relevant parts of Library/Quotient_* to Main
kuncar
parents:
diff changeset
   246
cb82606b8215 move Lifting/Transfer relevant parts of Library/Quotient_* to Main
kuncar
parents:
diff changeset
   247
lemma right_total_Inter_transfer [transfer_rule]:
cb82606b8215 move Lifting/Transfer relevant parts of Library/Quotient_* to Main
kuncar
parents:
diff changeset
   248
  assumes [transfer_rule]: "bi_unique A" and [transfer_rule]: "right_total A"
61952
546958347e05 prefer symbols for "Union", "Inter";
wenzelm
parents: 60758
diff changeset
   249
  shows "(rel_set (rel_set A) ===> rel_set A) (\<lambda>S. \<Inter>S \<inter> Collect (Domainp A)) Inter"
53012
cb82606b8215 move Lifting/Transfer relevant parts of Library/Quotient_* to Main
kuncar
parents:
diff changeset
   250
  unfolding Inter_eq[abs_def]
cb82606b8215 move Lifting/Transfer relevant parts of Library/Quotient_* to Main
kuncar
parents:
diff changeset
   251
  by (subst Collect_conj_eq[symmetric]) transfer_prover
cb82606b8215 move Lifting/Transfer relevant parts of Library/Quotient_* to Main
kuncar
parents:
diff changeset
   252
cb82606b8215 move Lifting/Transfer relevant parts of Library/Quotient_* to Main
kuncar
parents:
diff changeset
   253
lemma Inter_transfer [transfer_rule]:
cb82606b8215 move Lifting/Transfer relevant parts of Library/Quotient_* to Main
kuncar
parents:
diff changeset
   254
  assumes [transfer_rule]: "bi_unique A" and [transfer_rule]: "bi_total A"
55938
f20d1db5aa3c renamed 'set_rel' to 'rel_set'
blanchet
parents: 55564
diff changeset
   255
  shows "(rel_set (rel_set A) ===> rel_set A) Inter Inter"
53012
cb82606b8215 move Lifting/Transfer relevant parts of Library/Quotient_* to Main
kuncar
parents:
diff changeset
   256
  unfolding Inter_eq [abs_def] by transfer_prover
cb82606b8215 move Lifting/Transfer relevant parts of Library/Quotient_* to Main
kuncar
parents:
diff changeset
   257
cb82606b8215 move Lifting/Transfer relevant parts of Library/Quotient_* to Main
kuncar
parents:
diff changeset
   258
lemma filter_transfer [transfer_rule]:
cb82606b8215 move Lifting/Transfer relevant parts of Library/Quotient_* to Main
kuncar
parents:
diff changeset
   259
  assumes [transfer_rule]: "bi_unique A"
67399
eab6ce8368fa ran isabelle update_op on all sources
nipkow
parents: 64272
diff changeset
   260
  shows "((A ===> (=)) ===> rel_set A ===> rel_set A) Set.filter Set.filter"
55945
e96383acecf9 renamed 'fun_rel' to 'rel_fun'
blanchet
parents: 55938
diff changeset
   261
  unfolding Set.filter_def[abs_def] rel_fun_def rel_set_def by blast
53012
cb82606b8215 move Lifting/Transfer relevant parts of Library/Quotient_* to Main
kuncar
parents:
diff changeset
   262
cb82606b8215 move Lifting/Transfer relevant parts of Library/Quotient_* to Main
kuncar
parents:
diff changeset
   263
lemma finite_transfer [transfer_rule]:
67399
eab6ce8368fa ran isabelle update_op on all sources
nipkow
parents: 64272
diff changeset
   264
  "bi_unique A \<Longrightarrow> (rel_set A ===> (=)) finite finite"
57129
7edb7550663e introduce more powerful reindexing rules for big operators
hoelzl
parents: 56524
diff changeset
   265
  by (rule rel_funI, erule (1) bi_unique_rel_set_lemma)
7edb7550663e introduce more powerful reindexing rules for big operators
hoelzl
parents: 56524
diff changeset
   266
     (auto dest: finite_imageD)
53012
cb82606b8215 move Lifting/Transfer relevant parts of Library/Quotient_* to Main
kuncar
parents:
diff changeset
   267
cb82606b8215 move Lifting/Transfer relevant parts of Library/Quotient_* to Main
kuncar
parents:
diff changeset
   268
lemma card_transfer [transfer_rule]:
67399
eab6ce8368fa ran isabelle update_op on all sources
nipkow
parents: 64272
diff changeset
   269
  "bi_unique A \<Longrightarrow> (rel_set A ===> (=)) card card"
57129
7edb7550663e introduce more powerful reindexing rules for big operators
hoelzl
parents: 56524
diff changeset
   270
  by (rule rel_funI, erule (1) bi_unique_rel_set_lemma)
7edb7550663e introduce more powerful reindexing rules for big operators
hoelzl
parents: 56524
diff changeset
   271
     (simp add: card_image)
53012
cb82606b8215 move Lifting/Transfer relevant parts of Library/Quotient_* to Main
kuncar
parents:
diff changeset
   272
70927
cc204e10385c tuned syntax
haftmann
parents: 69275
diff changeset
   273
context
cc204e10385c tuned syntax
haftmann
parents: 69275
diff changeset
   274
  includes lifting_syntax
cc204e10385c tuned syntax
haftmann
parents: 69275
diff changeset
   275
begin
cc204e10385c tuned syntax
haftmann
parents: 69275
diff changeset
   276
68521
1bad08165162 added lemmas and transfer rules
immler
parents: 67399
diff changeset
   277
lemma vimage_right_total_transfer[transfer_rule]:
1bad08165162 added lemmas and transfer rules
immler
parents: 67399
diff changeset
   278
  assumes [transfer_rule]: "bi_unique B" "right_total A"
1bad08165162 added lemmas and transfer rules
immler
parents: 67399
diff changeset
   279
  shows "((A ===> B) ===> rel_set B ===> rel_set A) (\<lambda>f X. f -` X \<inter> Collect (Domainp A)) vimage"
1bad08165162 added lemmas and transfer rules
immler
parents: 67399
diff changeset
   280
proof -
1bad08165162 added lemmas and transfer rules
immler
parents: 67399
diff changeset
   281
  let ?vimage = "(\<lambda>f B. {x. f x \<in> B \<and> Domainp A x})"
1bad08165162 added lemmas and transfer rules
immler
parents: 67399
diff changeset
   282
  have "((A ===> B) ===> rel_set B ===> rel_set A) ?vimage vimage"
1bad08165162 added lemmas and transfer rules
immler
parents: 67399
diff changeset
   283
    unfolding vimage_def
1bad08165162 added lemmas and transfer rules
immler
parents: 67399
diff changeset
   284
    by transfer_prover
1bad08165162 added lemmas and transfer rules
immler
parents: 67399
diff changeset
   285
  also have "?vimage = (\<lambda>f X. f -` X \<inter> Collect (Domainp A))"
1bad08165162 added lemmas and transfer rules
immler
parents: 67399
diff changeset
   286
    by auto
1bad08165162 added lemmas and transfer rules
immler
parents: 67399
diff changeset
   287
  finally show ?thesis .
1bad08165162 added lemmas and transfer rules
immler
parents: 67399
diff changeset
   288
qed
1bad08165162 added lemmas and transfer rules
immler
parents: 67399
diff changeset
   289
70927
cc204e10385c tuned syntax
haftmann
parents: 69275
diff changeset
   290
end
cc204e10385c tuned syntax
haftmann
parents: 69275
diff changeset
   291
53927
abe2b313f0e5 add lemmas
Andreas Lochbihler
parents: 53012
diff changeset
   292
lemma vimage_parametric [transfer_rule]:
abe2b313f0e5 add lemmas
Andreas Lochbihler
parents: 53012
diff changeset
   293
  assumes [transfer_rule]: "bi_total A" "bi_unique B"
55938
f20d1db5aa3c renamed 'set_rel' to 'rel_set'
blanchet
parents: 55564
diff changeset
   294
  shows "((A ===> B) ===> rel_set B ===> rel_set A) vimage vimage"
57129
7edb7550663e introduce more powerful reindexing rules for big operators
hoelzl
parents: 56524
diff changeset
   295
  unfolding vimage_def[abs_def] by transfer_prover
53927
abe2b313f0e5 add lemmas
Andreas Lochbihler
parents: 53012
diff changeset
   296
57599
7ef939f89776 add parametricity lemmas
Andreas Lochbihler
parents: 57129
diff changeset
   297
lemma Image_parametric [transfer_rule]:
7ef939f89776 add parametricity lemmas
Andreas Lochbihler
parents: 57129
diff changeset
   298
  assumes "bi_unique A"
67399
eab6ce8368fa ran isabelle update_op on all sources
nipkow
parents: 64272
diff changeset
   299
  shows "(rel_set (rel_prod A B) ===> rel_set A ===> rel_set B) (``) (``)"
60676
92fd47ae2a67 tuned proofs;
wenzelm
parents: 60229
diff changeset
   300
  by (intro rel_funI rel_setI)
92fd47ae2a67 tuned proofs;
wenzelm
parents: 60229
diff changeset
   301
    (force dest: rel_setD1 bi_uniqueDr[OF assms], force dest: rel_setD2 bi_uniqueDl[OF assms])
57599
7ef939f89776 add parametricity lemmas
Andreas Lochbihler
parents: 57129
diff changeset
   302
68521
1bad08165162 added lemmas and transfer rules
immler
parents: 67399
diff changeset
   303
lemma inj_on_transfer[transfer_rule]:
1bad08165162 added lemmas and transfer rules
immler
parents: 67399
diff changeset
   304
  "((A ===> B) ===> rel_set A ===> (=)) inj_on inj_on"
1bad08165162 added lemmas and transfer rules
immler
parents: 67399
diff changeset
   305
  if [transfer_rule]: "bi_unique A" "bi_unique B"
1bad08165162 added lemmas and transfer rules
immler
parents: 67399
diff changeset
   306
  unfolding inj_on_def
1bad08165162 added lemmas and transfer rules
immler
parents: 67399
diff changeset
   307
  by transfer_prover
1bad08165162 added lemmas and transfer rules
immler
parents: 67399
diff changeset
   308
53012
cb82606b8215 move Lifting/Transfer relevant parts of Library/Quotient_* to Main
kuncar
parents:
diff changeset
   309
end
cb82606b8215 move Lifting/Transfer relevant parts of Library/Quotient_* to Main
kuncar
parents:
diff changeset
   310
57129
7edb7550663e introduce more powerful reindexing rules for big operators
hoelzl
parents: 56524
diff changeset
   311
lemma (in comm_monoid_set) F_parametric [transfer_rule]:
7edb7550663e introduce more powerful reindexing rules for big operators
hoelzl
parents: 56524
diff changeset
   312
  fixes A :: "'b \<Rightarrow> 'c \<Rightarrow> bool"
7edb7550663e introduce more powerful reindexing rules for big operators
hoelzl
parents: 56524
diff changeset
   313
  assumes "bi_unique A"
67399
eab6ce8368fa ran isabelle update_op on all sources
nipkow
parents: 64272
diff changeset
   314
  shows "rel_fun (rel_fun A (=)) (rel_fun (rel_set A) (=)) F F"
60676
92fd47ae2a67 tuned proofs;
wenzelm
parents: 60229
diff changeset
   315
proof (rule rel_funI)+
57129
7edb7550663e introduce more powerful reindexing rules for big operators
hoelzl
parents: 56524
diff changeset
   316
  fix f :: "'b \<Rightarrow> 'a" and g S T
67399
eab6ce8368fa ran isabelle update_op on all sources
nipkow
parents: 64272
diff changeset
   317
  assume "rel_fun A (=) f g" "rel_set A S T"
60758
d8d85a8172b5 isabelle update_cartouches;
wenzelm
parents: 60676
diff changeset
   318
  with \<open>bi_unique A\<close> obtain i where "bij_betw i S T" "\<And>x. x \<in> S \<Longrightarrow> f x = g (i x)"
57129
7edb7550663e introduce more powerful reindexing rules for big operators
hoelzl
parents: 56524
diff changeset
   319
    by (auto elim: bi_unique_rel_set_lemma simp: rel_fun_def bij_betw_def)
7edb7550663e introduce more powerful reindexing rules for big operators
hoelzl
parents: 56524
diff changeset
   320
  then show "F f S = F g T"
7edb7550663e introduce more powerful reindexing rules for big operators
hoelzl
parents: 56524
diff changeset
   321
    by (simp add: reindex_bij_betw)
7edb7550663e introduce more powerful reindexing rules for big operators
hoelzl
parents: 56524
diff changeset
   322
qed
7edb7550663e introduce more powerful reindexing rules for big operators
hoelzl
parents: 56524
diff changeset
   323
64267
b9a1486e79be setsum -> sum
nipkow
parents: 63343
diff changeset
   324
lemmas sum_parametric = sum.F_parametric
64272
f76b6dda2e56 setprod -> prod
nipkow
parents: 64267
diff changeset
   325
lemmas prod_parametric = prod.F_parametric
57129
7edb7550663e introduce more powerful reindexing rules for big operators
hoelzl
parents: 56524
diff changeset
   326
60057
86fa63ce8156 add lemmas
Andreas Lochbihler
parents: 58889
diff changeset
   327
lemma rel_set_UNION:
86fa63ce8156 add lemmas
Andreas Lochbihler
parents: 58889
diff changeset
   328
  assumes [transfer_rule]: "rel_set Q A B" "rel_fun Q (rel_set R) f g"
69275
9bbd5497befd clarified status of legacy input abbreviations
haftmann
parents: 68521
diff changeset
   329
  shows "rel_set R (\<Union>(f ` A)) (\<Union>(g ` B))"
60676
92fd47ae2a67 tuned proofs;
wenzelm
parents: 60229
diff changeset
   330
  by transfer_prover
60057
86fa63ce8156 add lemmas
Andreas Lochbihler
parents: 58889
diff changeset
   331
73832
9db620f007fa More general fold function for maps
nipkow
parents: 70927
diff changeset
   332
context
9db620f007fa More general fold function for maps
nipkow
parents: 70927
diff changeset
   333
  includes lifting_syntax
9db620f007fa More general fold function for maps
nipkow
parents: 70927
diff changeset
   334
begin
9db620f007fa More general fold function for maps
nipkow
parents: 70927
diff changeset
   335
9db620f007fa More general fold function for maps
nipkow
parents: 70927
diff changeset
   336
lemma fold_graph_transfer[transfer_rule]:
9db620f007fa More general fold function for maps
nipkow
parents: 70927
diff changeset
   337
  assumes "bi_unique R" "right_total R"
9db620f007fa More general fold function for maps
nipkow
parents: 70927
diff changeset
   338
  shows "((R ===> (=) ===> (=)) ===> (=) ===> rel_set R ===> (=) ===> (=)) fold_graph fold_graph"
9db620f007fa More general fold function for maps
nipkow
parents: 70927
diff changeset
   339
proof(intro rel_funI)
9db620f007fa More general fold function for maps
nipkow
parents: 70927
diff changeset
   340
  fix f1 :: "'a \<Rightarrow> 'c \<Rightarrow> 'c" and f2 :: "'b \<Rightarrow> 'c \<Rightarrow> 'c"
9db620f007fa More general fold function for maps
nipkow
parents: 70927
diff changeset
   341
  assume rel_f: "(R ===> (=) ===> (=)) f1 f2"
9db620f007fa More general fold function for maps
nipkow
parents: 70927
diff changeset
   342
  fix z1 z2 :: 'c assume [simp]: "z1 = z2"
9db620f007fa More general fold function for maps
nipkow
parents: 70927
diff changeset
   343
  fix A1 A2 assume rel_A: "rel_set R A1 A2"
9db620f007fa More general fold function for maps
nipkow
parents: 70927
diff changeset
   344
  fix y1 y2 :: 'c assume [simp]: "y1 = y2"
9db620f007fa More general fold function for maps
nipkow
parents: 70927
diff changeset
   345
9db620f007fa More general fold function for maps
nipkow
parents: 70927
diff changeset
   346
  from \<open>bi_unique R\<close> \<open>right_total R\<close> have The_y: "\<forall>y. \<exists>!x. R x y"
9db620f007fa More general fold function for maps
nipkow
parents: 70927
diff changeset
   347
    unfolding bi_unique_def right_total_def by auto
9db620f007fa More general fold function for maps
nipkow
parents: 70927
diff changeset
   348
  define r where "r \<equiv> \<lambda>y. THE x. R x y"
9db620f007fa More general fold function for maps
nipkow
parents: 70927
diff changeset
   349
  
9db620f007fa More general fold function for maps
nipkow
parents: 70927
diff changeset
   350
  from The_y have r_y: "R (r y) y" for y
9db620f007fa More general fold function for maps
nipkow
parents: 70927
diff changeset
   351
    unfolding r_def using the_equality by fastforce
9db620f007fa More general fold function for maps
nipkow
parents: 70927
diff changeset
   352
  with assms rel_A have "inj_on r A2" "A1 = r ` A2"
9db620f007fa More general fold function for maps
nipkow
parents: 70927
diff changeset
   353
    unfolding r_def rel_set_def inj_on_def bi_unique_def
9db620f007fa More general fold function for maps
nipkow
parents: 70927
diff changeset
   354
      apply(auto simp: image_iff) by metis+
9db620f007fa More general fold function for maps
nipkow
parents: 70927
diff changeset
   355
  with \<open>bi_unique R\<close> rel_f r_y have "(f1 o r) y = f2 y" for y
9db620f007fa More general fold function for maps
nipkow
parents: 70927
diff changeset
   356
    unfolding bi_unique_def rel_fun_def by auto
9db620f007fa More general fold function for maps
nipkow
parents: 70927
diff changeset
   357
  then have "(f1 o r) = f2"
9db620f007fa More general fold function for maps
nipkow
parents: 70927
diff changeset
   358
    by blast
9db620f007fa More general fold function for maps
nipkow
parents: 70927
diff changeset
   359
  then show "fold_graph f1 z1 A1 y1 = fold_graph f2 z2 A2 y2"
9db620f007fa More general fold function for maps
nipkow
parents: 70927
diff changeset
   360
    by (fastforce simp: fold_graph_image[OF \<open>inj_on r A2\<close>] \<open>A1 = r ` A2\<close>)
9db620f007fa More general fold function for maps
nipkow
parents: 70927
diff changeset
   361
qed
9db620f007fa More general fold function for maps
nipkow
parents: 70927
diff changeset
   362
9db620f007fa More general fold function for maps
nipkow
parents: 70927
diff changeset
   363
lemma fold_transfer[transfer_rule]:
9db620f007fa More general fold function for maps
nipkow
parents: 70927
diff changeset
   364
  assumes [transfer_rule]: "bi_unique R" "right_total R"
9db620f007fa More general fold function for maps
nipkow
parents: 70927
diff changeset
   365
  shows "((R ===> (=) ===> (=)) ===> (=) ===> rel_set R ===> (=)) Finite_Set.fold Finite_Set.fold"
9db620f007fa More general fold function for maps
nipkow
parents: 70927
diff changeset
   366
  unfolding Finite_Set.fold_def
9db620f007fa More general fold function for maps
nipkow
parents: 70927
diff changeset
   367
  by transfer_prover
9db620f007fa More general fold function for maps
nipkow
parents: 70927
diff changeset
   368
53012
cb82606b8215 move Lifting/Transfer relevant parts of Library/Quotient_* to Main
kuncar
parents:
diff changeset
   369
end
73832
9db620f007fa More general fold function for maps
nipkow
parents: 70927
diff changeset
   370
9db620f007fa More general fold function for maps
nipkow
parents: 70927
diff changeset
   371
9db620f007fa More general fold function for maps
nipkow
parents: 70927
diff changeset
   372
end