src/HOL/Transfer.thy
author kuncar
Sat, 16 Mar 2013 20:51:23 +0100
changeset 51437 8739f8abbecb
parent 51112 da97167e03f7
child 51955 04d9381bebff
permissions -rw-r--r--
fixing transfer tactic - unfold fully identity relation by using relator_eq
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
47325
ec6187036495 new transfer proof method
huffman
parents:
diff changeset
     1
(*  Title:      HOL/Transfer.thy
ec6187036495 new transfer proof method
huffman
parents:
diff changeset
     2
    Author:     Brian Huffman, TU Muenchen
ec6187036495 new transfer proof method
huffman
parents:
diff changeset
     3
*)
ec6187036495 new transfer proof method
huffman
parents:
diff changeset
     4
ec6187036495 new transfer proof method
huffman
parents:
diff changeset
     5
header {* Generic theorem transfer using relations *}
ec6187036495 new transfer proof method
huffman
parents:
diff changeset
     6
ec6187036495 new transfer proof method
huffman
parents:
diff changeset
     7
theory Transfer
51112
da97167e03f7 abandoned theory Plain
haftmann
parents: 49975
diff changeset
     8
imports Hilbert_Choice
47325
ec6187036495 new transfer proof method
huffman
parents:
diff changeset
     9
begin
ec6187036495 new transfer proof method
huffman
parents:
diff changeset
    10
ec6187036495 new transfer proof method
huffman
parents:
diff changeset
    11
subsection {* Relator for function space *}
ec6187036495 new transfer proof method
huffman
parents:
diff changeset
    12
ec6187036495 new transfer proof method
huffman
parents:
diff changeset
    13
definition
ec6187036495 new transfer proof method
huffman
parents:
diff changeset
    14
  fun_rel :: "('a \<Rightarrow> 'c \<Rightarrow> bool) \<Rightarrow> ('b \<Rightarrow> 'd \<Rightarrow> bool) \<Rightarrow> ('a \<Rightarrow> 'b) \<Rightarrow> ('c \<Rightarrow> 'd) \<Rightarrow> bool" (infixr "===>" 55)
ec6187036495 new transfer proof method
huffman
parents:
diff changeset
    15
where
ec6187036495 new transfer proof method
huffman
parents:
diff changeset
    16
  "fun_rel A B = (\<lambda>f g. \<forall>x y. A x y \<longrightarrow> B (f x) (g y))"
ec6187036495 new transfer proof method
huffman
parents:
diff changeset
    17
ec6187036495 new transfer proof method
huffman
parents:
diff changeset
    18
lemma fun_relI [intro]:
ec6187036495 new transfer proof method
huffman
parents:
diff changeset
    19
  assumes "\<And>x y. A x y \<Longrightarrow> B (f x) (g y)"
ec6187036495 new transfer proof method
huffman
parents:
diff changeset
    20
  shows "(A ===> B) f g"
ec6187036495 new transfer proof method
huffman
parents:
diff changeset
    21
  using assms by (simp add: fun_rel_def)
ec6187036495 new transfer proof method
huffman
parents:
diff changeset
    22
ec6187036495 new transfer proof method
huffman
parents:
diff changeset
    23
lemma fun_relD:
ec6187036495 new transfer proof method
huffman
parents:
diff changeset
    24
  assumes "(A ===> B) f g" and "A x y"
ec6187036495 new transfer proof method
huffman
parents:
diff changeset
    25
  shows "B (f x) (g y)"
ec6187036495 new transfer proof method
huffman
parents:
diff changeset
    26
  using assms by (simp add: fun_rel_def)
ec6187036495 new transfer proof method
huffman
parents:
diff changeset
    27
47937
70375fa2679d generate abs_eq, use it as a code equation for total quotients; no_abs_code renamed to no_code; added no_code for quotient_type command
kuncar
parents: 47924
diff changeset
    28
lemma fun_relD2:
70375fa2679d generate abs_eq, use it as a code equation for total quotients; no_abs_code renamed to no_code; added no_code for quotient_type command
kuncar
parents: 47924
diff changeset
    29
  assumes "(A ===> B) f g" and "A x x"
70375fa2679d generate abs_eq, use it as a code equation for total quotients; no_abs_code renamed to no_code; added no_code for quotient_type command
kuncar
parents: 47924
diff changeset
    30
  shows "B (f x) (g x)"
70375fa2679d generate abs_eq, use it as a code equation for total quotients; no_abs_code renamed to no_code; added no_code for quotient_type command
kuncar
parents: 47924
diff changeset
    31
  using assms unfolding fun_rel_def by auto
70375fa2679d generate abs_eq, use it as a code equation for total quotients; no_abs_code renamed to no_code; added no_code for quotient_type command
kuncar
parents: 47924
diff changeset
    32
47325
ec6187036495 new transfer proof method
huffman
parents:
diff changeset
    33
lemma fun_relE:
ec6187036495 new transfer proof method
huffman
parents:
diff changeset
    34
  assumes "(A ===> B) f g" and "A x y"
ec6187036495 new transfer proof method
huffman
parents:
diff changeset
    35
  obtains "B (f x) (g y)"
ec6187036495 new transfer proof method
huffman
parents:
diff changeset
    36
  using assms by (simp add: fun_rel_def)
ec6187036495 new transfer proof method
huffman
parents:
diff changeset
    37
ec6187036495 new transfer proof method
huffman
parents:
diff changeset
    38
lemma fun_rel_eq:
ec6187036495 new transfer proof method
huffman
parents:
diff changeset
    39
  shows "((op =) ===> (op =)) = (op =)"
ec6187036495 new transfer proof method
huffman
parents:
diff changeset
    40
  by (auto simp add: fun_eq_iff elim: fun_relE)
ec6187036495 new transfer proof method
huffman
parents:
diff changeset
    41
ec6187036495 new transfer proof method
huffman
parents:
diff changeset
    42
lemma fun_rel_eq_rel:
ec6187036495 new transfer proof method
huffman
parents:
diff changeset
    43
  shows "((op =) ===> R) = (\<lambda>f g. \<forall>x. R (f x) (g x))"
ec6187036495 new transfer proof method
huffman
parents:
diff changeset
    44
  by (simp add: fun_rel_def)
ec6187036495 new transfer proof method
huffman
parents:
diff changeset
    45
ec6187036495 new transfer proof method
huffman
parents:
diff changeset
    46
ec6187036495 new transfer proof method
huffman
parents:
diff changeset
    47
subsection {* Transfer method *}
ec6187036495 new transfer proof method
huffman
parents:
diff changeset
    48
47789
71a526ee569a implement transfer tactic with more scalable forward proof methods
huffman
parents: 47684
diff changeset
    49
text {* Explicit tag for relation membership allows for
71a526ee569a implement transfer tactic with more scalable forward proof methods
huffman
parents: 47684
diff changeset
    50
  backward proof methods. *}
47325
ec6187036495 new transfer proof method
huffman
parents:
diff changeset
    51
ec6187036495 new transfer proof method
huffman
parents:
diff changeset
    52
definition Rel :: "('a \<Rightarrow> 'b \<Rightarrow> bool) \<Rightarrow> 'a \<Rightarrow> 'b \<Rightarrow> bool"
ec6187036495 new transfer proof method
huffman
parents:
diff changeset
    53
  where "Rel r \<equiv> r"
ec6187036495 new transfer proof method
huffman
parents:
diff changeset
    54
49975
faf4afed009f transfer package: more flexible handling of equality relations using is_equality predicate
huffman
parents: 48891
diff changeset
    55
text {* Handling of equality relations *}
faf4afed009f transfer package: more flexible handling of equality relations using is_equality predicate
huffman
parents: 48891
diff changeset
    56
faf4afed009f transfer package: more flexible handling of equality relations using is_equality predicate
huffman
parents: 48891
diff changeset
    57
definition is_equality :: "('a \<Rightarrow> 'a \<Rightarrow> bool) \<Rightarrow> bool"
faf4afed009f transfer package: more flexible handling of equality relations using is_equality predicate
huffman
parents: 48891
diff changeset
    58
  where "is_equality R \<longleftrightarrow> R = (op =)"
faf4afed009f transfer package: more flexible handling of equality relations using is_equality predicate
huffman
parents: 48891
diff changeset
    59
51437
8739f8abbecb fixing transfer tactic - unfold fully identity relation by using relator_eq
kuncar
parents: 51112
diff changeset
    60
lemma is_equality_eq: "is_equality (op =)"
8739f8abbecb fixing transfer tactic - unfold fully identity relation by using relator_eq
kuncar
parents: 51112
diff changeset
    61
  unfolding is_equality_def by simp
8739f8abbecb fixing transfer tactic - unfold fully identity relation by using relator_eq
kuncar
parents: 51112
diff changeset
    62
47325
ec6187036495 new transfer proof method
huffman
parents:
diff changeset
    63
text {* Handling of meta-logic connectives *}
ec6187036495 new transfer proof method
huffman
parents:
diff changeset
    64
ec6187036495 new transfer proof method
huffman
parents:
diff changeset
    65
definition transfer_forall where
ec6187036495 new transfer proof method
huffman
parents:
diff changeset
    66
  "transfer_forall \<equiv> All"
ec6187036495 new transfer proof method
huffman
parents:
diff changeset
    67
ec6187036495 new transfer proof method
huffman
parents:
diff changeset
    68
definition transfer_implies where
ec6187036495 new transfer proof method
huffman
parents:
diff changeset
    69
  "transfer_implies \<equiv> op \<longrightarrow>"
ec6187036495 new transfer proof method
huffman
parents:
diff changeset
    70
47355
3d9d98e0f1a4 add bounded quantifier constant transfer_bforall, whose definition is unfolded after transfer
huffman
parents: 47325
diff changeset
    71
definition transfer_bforall :: "('a \<Rightarrow> bool) \<Rightarrow> ('a \<Rightarrow> bool) \<Rightarrow> bool"
3d9d98e0f1a4 add bounded quantifier constant transfer_bforall, whose definition is unfolded after transfer
huffman
parents: 47325
diff changeset
    72
  where "transfer_bforall \<equiv> (\<lambda>P Q. \<forall>x. P x \<longrightarrow> Q x)"
3d9d98e0f1a4 add bounded quantifier constant transfer_bforall, whose definition is unfolded after transfer
huffman
parents: 47325
diff changeset
    73
47325
ec6187036495 new transfer proof method
huffman
parents:
diff changeset
    74
lemma transfer_forall_eq: "(\<And>x. P x) \<equiv> Trueprop (transfer_forall (\<lambda>x. P x))"
ec6187036495 new transfer proof method
huffman
parents:
diff changeset
    75
  unfolding atomize_all transfer_forall_def ..
ec6187036495 new transfer proof method
huffman
parents:
diff changeset
    76
ec6187036495 new transfer proof method
huffman
parents:
diff changeset
    77
lemma transfer_implies_eq: "(A \<Longrightarrow> B) \<equiv> Trueprop (transfer_implies A B)"
ec6187036495 new transfer proof method
huffman
parents:
diff changeset
    78
  unfolding atomize_imp transfer_implies_def ..
ec6187036495 new transfer proof method
huffman
parents:
diff changeset
    79
47355
3d9d98e0f1a4 add bounded quantifier constant transfer_bforall, whose definition is unfolded after transfer
huffman
parents: 47325
diff changeset
    80
lemma transfer_bforall_unfold:
3d9d98e0f1a4 add bounded quantifier constant transfer_bforall, whose definition is unfolded after transfer
huffman
parents: 47325
diff changeset
    81
  "Trueprop (transfer_bforall P (\<lambda>x. Q x)) \<equiv> (\<And>x. P x \<Longrightarrow> Q x)"
3d9d98e0f1a4 add bounded quantifier constant transfer_bforall, whose definition is unfolded after transfer
huffman
parents: 47325
diff changeset
    82
  unfolding transfer_bforall_def atomize_imp atomize_all ..
3d9d98e0f1a4 add bounded quantifier constant transfer_bforall, whose definition is unfolded after transfer
huffman
parents: 47325
diff changeset
    83
47658
7631f6f7873d enable variant of transfer method that proves an implication instead of an equivalence
huffman
parents: 47637
diff changeset
    84
lemma transfer_start: "\<lbrakk>P; Rel (op =) P Q\<rbrakk> \<Longrightarrow> Q"
47325
ec6187036495 new transfer proof method
huffman
parents:
diff changeset
    85
  unfolding Rel_def by simp
ec6187036495 new transfer proof method
huffman
parents:
diff changeset
    86
47658
7631f6f7873d enable variant of transfer method that proves an implication instead of an equivalence
huffman
parents: 47637
diff changeset
    87
lemma transfer_start': "\<lbrakk>P; Rel (op \<longrightarrow>) P Q\<rbrakk> \<Longrightarrow> Q"
47325
ec6187036495 new transfer proof method
huffman
parents:
diff changeset
    88
  unfolding Rel_def by simp
ec6187036495 new transfer proof method
huffman
parents:
diff changeset
    89
47635
ebb79474262c rename 'correspondence' method to 'transfer_prover'
huffman
parents: 47627
diff changeset
    90
lemma transfer_prover_start: "\<lbrakk>x = x'; Rel R x' y\<rbrakk> \<Longrightarrow> Rel R x y"
47618
1568dadd598a make correspondence tactic more robust by replacing lhs with schematic variable before applying intro rules
huffman
parents: 47612
diff changeset
    91
  by simp
1568dadd598a make correspondence tactic more robust by replacing lhs with schematic variable before applying intro rules
huffman
parents: 47612
diff changeset
    92
47325
ec6187036495 new transfer proof method
huffman
parents:
diff changeset
    93
lemma Rel_eq_refl: "Rel (op =) x x"
ec6187036495 new transfer proof method
huffman
parents:
diff changeset
    94
  unfolding Rel_def ..
ec6187036495 new transfer proof method
huffman
parents:
diff changeset
    95
47789
71a526ee569a implement transfer tactic with more scalable forward proof methods
huffman
parents: 47684
diff changeset
    96
lemma Rel_app:
47523
1bf0e92c1ca0 make transfer method more deterministic by using SOLVED' on some subgoals
huffman
parents: 47503
diff changeset
    97
  assumes "Rel (A ===> B) f g" and "Rel A x y"
47789
71a526ee569a implement transfer tactic with more scalable forward proof methods
huffman
parents: 47684
diff changeset
    98
  shows "Rel B (f x) (g y)"
71a526ee569a implement transfer tactic with more scalable forward proof methods
huffman
parents: 47684
diff changeset
    99
  using assms unfolding Rel_def fun_rel_def by fast
47523
1bf0e92c1ca0 make transfer method more deterministic by using SOLVED' on some subgoals
huffman
parents: 47503
diff changeset
   100
47789
71a526ee569a implement transfer tactic with more scalable forward proof methods
huffman
parents: 47684
diff changeset
   101
lemma Rel_abs:
47523
1bf0e92c1ca0 make transfer method more deterministic by using SOLVED' on some subgoals
huffman
parents: 47503
diff changeset
   102
  assumes "\<And>x y. Rel A x y \<Longrightarrow> Rel B (f x) (g y)"
47789
71a526ee569a implement transfer tactic with more scalable forward proof methods
huffman
parents: 47684
diff changeset
   103
  shows "Rel (A ===> B) (\<lambda>x. f x) (\<lambda>y. g y)"
71a526ee569a implement transfer tactic with more scalable forward proof methods
huffman
parents: 47684
diff changeset
   104
  using assms unfolding Rel_def fun_rel_def by fast
47523
1bf0e92c1ca0 make transfer method more deterministic by using SOLVED' on some subgoals
huffman
parents: 47503
diff changeset
   105
48891
c0eafbd55de3 prefer ML_file over old uses;
wenzelm
parents: 47937
diff changeset
   106
ML_file "Tools/transfer.ML"
47325
ec6187036495 new transfer proof method
huffman
parents:
diff changeset
   107
setup Transfer.setup
ec6187036495 new transfer proof method
huffman
parents:
diff changeset
   108
49975
faf4afed009f transfer package: more flexible handling of equality relations using is_equality predicate
huffman
parents: 48891
diff changeset
   109
declare refl [transfer_rule]
faf4afed009f transfer package: more flexible handling of equality relations using is_equality predicate
huffman
parents: 48891
diff changeset
   110
47503
cb44d09d9d22 add theory data for relator identity rules;
huffman
parents: 47355
diff changeset
   111
declare fun_rel_eq [relator_eq]
cb44d09d9d22 add theory data for relator identity rules;
huffman
parents: 47355
diff changeset
   112
47789
71a526ee569a implement transfer tactic with more scalable forward proof methods
huffman
parents: 47684
diff changeset
   113
hide_const (open) Rel
47325
ec6187036495 new transfer proof method
huffman
parents:
diff changeset
   114
ec6187036495 new transfer proof method
huffman
parents:
diff changeset
   115
ec6187036495 new transfer proof method
huffman
parents:
diff changeset
   116
subsection {* Predicates on relations, i.e. ``class constraints'' *}
ec6187036495 new transfer proof method
huffman
parents:
diff changeset
   117
ec6187036495 new transfer proof method
huffman
parents:
diff changeset
   118
definition right_total :: "('a \<Rightarrow> 'b \<Rightarrow> bool) \<Rightarrow> bool"
ec6187036495 new transfer proof method
huffman
parents:
diff changeset
   119
  where "right_total R \<longleftrightarrow> (\<forall>y. \<exists>x. R x y)"
ec6187036495 new transfer proof method
huffman
parents:
diff changeset
   120
ec6187036495 new transfer proof method
huffman
parents:
diff changeset
   121
definition right_unique :: "('a \<Rightarrow> 'b \<Rightarrow> bool) \<Rightarrow> bool"
ec6187036495 new transfer proof method
huffman
parents:
diff changeset
   122
  where "right_unique R \<longleftrightarrow> (\<forall>x y z. R x y \<longrightarrow> R x z \<longrightarrow> y = z)"
ec6187036495 new transfer proof method
huffman
parents:
diff changeset
   123
ec6187036495 new transfer proof method
huffman
parents:
diff changeset
   124
definition bi_total :: "('a \<Rightarrow> 'b \<Rightarrow> bool) \<Rightarrow> bool"
ec6187036495 new transfer proof method
huffman
parents:
diff changeset
   125
  where "bi_total R \<longleftrightarrow> (\<forall>x. \<exists>y. R x y) \<and> (\<forall>y. \<exists>x. R x y)"
ec6187036495 new transfer proof method
huffman
parents:
diff changeset
   126
ec6187036495 new transfer proof method
huffman
parents:
diff changeset
   127
definition bi_unique :: "('a \<Rightarrow> 'b \<Rightarrow> bool) \<Rightarrow> bool"
ec6187036495 new transfer proof method
huffman
parents:
diff changeset
   128
  where "bi_unique R \<longleftrightarrow>
ec6187036495 new transfer proof method
huffman
parents:
diff changeset
   129
    (\<forall>x y z. R x y \<longrightarrow> R x z \<longrightarrow> y = z) \<and>
ec6187036495 new transfer proof method
huffman
parents:
diff changeset
   130
    (\<forall>x y z. R x z \<longrightarrow> R y z \<longrightarrow> x = y)"
ec6187036495 new transfer proof method
huffman
parents:
diff changeset
   131
ec6187036495 new transfer proof method
huffman
parents:
diff changeset
   132
lemma right_total_alt_def:
ec6187036495 new transfer proof method
huffman
parents:
diff changeset
   133
  "right_total R \<longleftrightarrow> ((R ===> op \<longrightarrow>) ===> op \<longrightarrow>) All All"
ec6187036495 new transfer proof method
huffman
parents:
diff changeset
   134
  unfolding right_total_def fun_rel_def
ec6187036495 new transfer proof method
huffman
parents:
diff changeset
   135
  apply (rule iffI, fast)
ec6187036495 new transfer proof method
huffman
parents:
diff changeset
   136
  apply (rule allI)
ec6187036495 new transfer proof method
huffman
parents:
diff changeset
   137
  apply (drule_tac x="\<lambda>x. True" in spec)
ec6187036495 new transfer proof method
huffman
parents:
diff changeset
   138
  apply (drule_tac x="\<lambda>y. \<exists>x. R x y" in spec)
ec6187036495 new transfer proof method
huffman
parents:
diff changeset
   139
  apply fast
ec6187036495 new transfer proof method
huffman
parents:
diff changeset
   140
  done
ec6187036495 new transfer proof method
huffman
parents:
diff changeset
   141
ec6187036495 new transfer proof method
huffman
parents:
diff changeset
   142
lemma right_unique_alt_def:
ec6187036495 new transfer proof method
huffman
parents:
diff changeset
   143
  "right_unique R \<longleftrightarrow> (R ===> R ===> op \<longrightarrow>) (op =) (op =)"
ec6187036495 new transfer proof method
huffman
parents:
diff changeset
   144
  unfolding right_unique_def fun_rel_def by auto
ec6187036495 new transfer proof method
huffman
parents:
diff changeset
   145
ec6187036495 new transfer proof method
huffman
parents:
diff changeset
   146
lemma bi_total_alt_def:
ec6187036495 new transfer proof method
huffman
parents:
diff changeset
   147
  "bi_total R \<longleftrightarrow> ((R ===> op =) ===> op =) All All"
ec6187036495 new transfer proof method
huffman
parents:
diff changeset
   148
  unfolding bi_total_def fun_rel_def
ec6187036495 new transfer proof method
huffman
parents:
diff changeset
   149
  apply (rule iffI, fast)
ec6187036495 new transfer proof method
huffman
parents:
diff changeset
   150
  apply safe
ec6187036495 new transfer proof method
huffman
parents:
diff changeset
   151
  apply (drule_tac x="\<lambda>x. \<exists>y. R x y" in spec)
ec6187036495 new transfer proof method
huffman
parents:
diff changeset
   152
  apply (drule_tac x="\<lambda>y. True" in spec)
ec6187036495 new transfer proof method
huffman
parents:
diff changeset
   153
  apply fast
ec6187036495 new transfer proof method
huffman
parents:
diff changeset
   154
  apply (drule_tac x="\<lambda>x. True" in spec)
ec6187036495 new transfer proof method
huffman
parents:
diff changeset
   155
  apply (drule_tac x="\<lambda>y. \<exists>x. R x y" in spec)
ec6187036495 new transfer proof method
huffman
parents:
diff changeset
   156
  apply fast
ec6187036495 new transfer proof method
huffman
parents:
diff changeset
   157
  done
ec6187036495 new transfer proof method
huffman
parents:
diff changeset
   158
ec6187036495 new transfer proof method
huffman
parents:
diff changeset
   159
lemma bi_unique_alt_def:
ec6187036495 new transfer proof method
huffman
parents:
diff changeset
   160
  "bi_unique R \<longleftrightarrow> (R ===> R ===> op =) (op =) (op =)"
ec6187036495 new transfer proof method
huffman
parents:
diff changeset
   161
  unfolding bi_unique_def fun_rel_def by auto
ec6187036495 new transfer proof method
huffman
parents:
diff changeset
   162
47660
7a5c681c0265 new example theory for quotient/transfer
huffman
parents: 47658
diff changeset
   163
text {* Properties are preserved by relation composition. *}
7a5c681c0265 new example theory for quotient/transfer
huffman
parents: 47658
diff changeset
   164
7a5c681c0265 new example theory for quotient/transfer
huffman
parents: 47658
diff changeset
   165
lemma OO_def: "R OO S = (\<lambda>x z. \<exists>y. R x y \<and> S y z)"
7a5c681c0265 new example theory for quotient/transfer
huffman
parents: 47658
diff changeset
   166
  by auto
7a5c681c0265 new example theory for quotient/transfer
huffman
parents: 47658
diff changeset
   167
7a5c681c0265 new example theory for quotient/transfer
huffman
parents: 47658
diff changeset
   168
lemma bi_total_OO: "\<lbrakk>bi_total A; bi_total B\<rbrakk> \<Longrightarrow> bi_total (A OO B)"
7a5c681c0265 new example theory for quotient/transfer
huffman
parents: 47658
diff changeset
   169
  unfolding bi_total_def OO_def by metis
7a5c681c0265 new example theory for quotient/transfer
huffman
parents: 47658
diff changeset
   170
7a5c681c0265 new example theory for quotient/transfer
huffman
parents: 47658
diff changeset
   171
lemma bi_unique_OO: "\<lbrakk>bi_unique A; bi_unique B\<rbrakk> \<Longrightarrow> bi_unique (A OO B)"
7a5c681c0265 new example theory for quotient/transfer
huffman
parents: 47658
diff changeset
   172
  unfolding bi_unique_def OO_def by metis
7a5c681c0265 new example theory for quotient/transfer
huffman
parents: 47658
diff changeset
   173
7a5c681c0265 new example theory for quotient/transfer
huffman
parents: 47658
diff changeset
   174
lemma right_total_OO:
7a5c681c0265 new example theory for quotient/transfer
huffman
parents: 47658
diff changeset
   175
  "\<lbrakk>right_total A; right_total B\<rbrakk> \<Longrightarrow> right_total (A OO B)"
7a5c681c0265 new example theory for quotient/transfer
huffman
parents: 47658
diff changeset
   176
  unfolding right_total_def OO_def by metis
7a5c681c0265 new example theory for quotient/transfer
huffman
parents: 47658
diff changeset
   177
7a5c681c0265 new example theory for quotient/transfer
huffman
parents: 47658
diff changeset
   178
lemma right_unique_OO:
7a5c681c0265 new example theory for quotient/transfer
huffman
parents: 47658
diff changeset
   179
  "\<lbrakk>right_unique A; right_unique B\<rbrakk> \<Longrightarrow> right_unique (A OO B)"
7a5c681c0265 new example theory for quotient/transfer
huffman
parents: 47658
diff changeset
   180
  unfolding right_unique_def OO_def by metis
7a5c681c0265 new example theory for quotient/transfer
huffman
parents: 47658
diff changeset
   181
47325
ec6187036495 new transfer proof method
huffman
parents:
diff changeset
   182
ec6187036495 new transfer proof method
huffman
parents:
diff changeset
   183
subsection {* Properties of relators *}
ec6187036495 new transfer proof method
huffman
parents:
diff changeset
   184
ec6187036495 new transfer proof method
huffman
parents:
diff changeset
   185
lemma right_total_eq [transfer_rule]: "right_total (op =)"
ec6187036495 new transfer proof method
huffman
parents:
diff changeset
   186
  unfolding right_total_def by simp
ec6187036495 new transfer proof method
huffman
parents:
diff changeset
   187
ec6187036495 new transfer proof method
huffman
parents:
diff changeset
   188
lemma right_unique_eq [transfer_rule]: "right_unique (op =)"
ec6187036495 new transfer proof method
huffman
parents:
diff changeset
   189
  unfolding right_unique_def by simp
ec6187036495 new transfer proof method
huffman
parents:
diff changeset
   190
ec6187036495 new transfer proof method
huffman
parents:
diff changeset
   191
lemma bi_total_eq [transfer_rule]: "bi_total (op =)"
ec6187036495 new transfer proof method
huffman
parents:
diff changeset
   192
  unfolding bi_total_def by simp
ec6187036495 new transfer proof method
huffman
parents:
diff changeset
   193
ec6187036495 new transfer proof method
huffman
parents:
diff changeset
   194
lemma bi_unique_eq [transfer_rule]: "bi_unique (op =)"
ec6187036495 new transfer proof method
huffman
parents:
diff changeset
   195
  unfolding bi_unique_def by simp
ec6187036495 new transfer proof method
huffman
parents:
diff changeset
   196
ec6187036495 new transfer proof method
huffman
parents:
diff changeset
   197
lemma right_total_fun [transfer_rule]:
ec6187036495 new transfer proof method
huffman
parents:
diff changeset
   198
  "\<lbrakk>right_unique A; right_total B\<rbrakk> \<Longrightarrow> right_total (A ===> B)"
ec6187036495 new transfer proof method
huffman
parents:
diff changeset
   199
  unfolding right_total_def fun_rel_def
ec6187036495 new transfer proof method
huffman
parents:
diff changeset
   200
  apply (rule allI, rename_tac g)
ec6187036495 new transfer proof method
huffman
parents:
diff changeset
   201
  apply (rule_tac x="\<lambda>x. SOME z. B z (g (THE y. A x y))" in exI)
ec6187036495 new transfer proof method
huffman
parents:
diff changeset
   202
  apply clarify
ec6187036495 new transfer proof method
huffman
parents:
diff changeset
   203
  apply (subgoal_tac "(THE y. A x y) = y", simp)
ec6187036495 new transfer proof method
huffman
parents:
diff changeset
   204
  apply (rule someI_ex)
ec6187036495 new transfer proof method
huffman
parents:
diff changeset
   205
  apply (simp)
ec6187036495 new transfer proof method
huffman
parents:
diff changeset
   206
  apply (rule the_equality)
ec6187036495 new transfer proof method
huffman
parents:
diff changeset
   207
  apply assumption
ec6187036495 new transfer proof method
huffman
parents:
diff changeset
   208
  apply (simp add: right_unique_def)
ec6187036495 new transfer proof method
huffman
parents:
diff changeset
   209
  done
ec6187036495 new transfer proof method
huffman
parents:
diff changeset
   210
ec6187036495 new transfer proof method
huffman
parents:
diff changeset
   211
lemma right_unique_fun [transfer_rule]:
ec6187036495 new transfer proof method
huffman
parents:
diff changeset
   212
  "\<lbrakk>right_total A; right_unique B\<rbrakk> \<Longrightarrow> right_unique (A ===> B)"
ec6187036495 new transfer proof method
huffman
parents:
diff changeset
   213
  unfolding right_total_def right_unique_def fun_rel_def
ec6187036495 new transfer proof method
huffman
parents:
diff changeset
   214
  by (clarify, rule ext, fast)
ec6187036495 new transfer proof method
huffman
parents:
diff changeset
   215
ec6187036495 new transfer proof method
huffman
parents:
diff changeset
   216
lemma bi_total_fun [transfer_rule]:
ec6187036495 new transfer proof method
huffman
parents:
diff changeset
   217
  "\<lbrakk>bi_unique A; bi_total B\<rbrakk> \<Longrightarrow> bi_total (A ===> B)"
ec6187036495 new transfer proof method
huffman
parents:
diff changeset
   218
  unfolding bi_total_def fun_rel_def
ec6187036495 new transfer proof method
huffman
parents:
diff changeset
   219
  apply safe
ec6187036495 new transfer proof method
huffman
parents:
diff changeset
   220
  apply (rename_tac f)
ec6187036495 new transfer proof method
huffman
parents:
diff changeset
   221
  apply (rule_tac x="\<lambda>y. SOME z. B (f (THE x. A x y)) z" in exI)
ec6187036495 new transfer proof method
huffman
parents:
diff changeset
   222
  apply clarify
ec6187036495 new transfer proof method
huffman
parents:
diff changeset
   223
  apply (subgoal_tac "(THE x. A x y) = x", simp)
ec6187036495 new transfer proof method
huffman
parents:
diff changeset
   224
  apply (rule someI_ex)
ec6187036495 new transfer proof method
huffman
parents:
diff changeset
   225
  apply (simp)
ec6187036495 new transfer proof method
huffman
parents:
diff changeset
   226
  apply (rule the_equality)
ec6187036495 new transfer proof method
huffman
parents:
diff changeset
   227
  apply assumption
ec6187036495 new transfer proof method
huffman
parents:
diff changeset
   228
  apply (simp add: bi_unique_def)
ec6187036495 new transfer proof method
huffman
parents:
diff changeset
   229
  apply (rename_tac g)
ec6187036495 new transfer proof method
huffman
parents:
diff changeset
   230
  apply (rule_tac x="\<lambda>x. SOME z. B z (g (THE y. A x y))" in exI)
ec6187036495 new transfer proof method
huffman
parents:
diff changeset
   231
  apply clarify
ec6187036495 new transfer proof method
huffman
parents:
diff changeset
   232
  apply (subgoal_tac "(THE y. A x y) = y", simp)
ec6187036495 new transfer proof method
huffman
parents:
diff changeset
   233
  apply (rule someI_ex)
ec6187036495 new transfer proof method
huffman
parents:
diff changeset
   234
  apply (simp)
ec6187036495 new transfer proof method
huffman
parents:
diff changeset
   235
  apply (rule the_equality)
ec6187036495 new transfer proof method
huffman
parents:
diff changeset
   236
  apply assumption
ec6187036495 new transfer proof method
huffman
parents:
diff changeset
   237
  apply (simp add: bi_unique_def)
ec6187036495 new transfer proof method
huffman
parents:
diff changeset
   238
  done
ec6187036495 new transfer proof method
huffman
parents:
diff changeset
   239
ec6187036495 new transfer proof method
huffman
parents:
diff changeset
   240
lemma bi_unique_fun [transfer_rule]:
ec6187036495 new transfer proof method
huffman
parents:
diff changeset
   241
  "\<lbrakk>bi_total A; bi_unique B\<rbrakk> \<Longrightarrow> bi_unique (A ===> B)"
ec6187036495 new transfer proof method
huffman
parents:
diff changeset
   242
  unfolding bi_total_def bi_unique_def fun_rel_def fun_eq_iff
ec6187036495 new transfer proof method
huffman
parents:
diff changeset
   243
  by (safe, metis, fast)
ec6187036495 new transfer proof method
huffman
parents:
diff changeset
   244
ec6187036495 new transfer proof method
huffman
parents:
diff changeset
   245
47635
ebb79474262c rename 'correspondence' method to 'transfer_prover'
huffman
parents: 47627
diff changeset
   246
subsection {* Transfer rules *}
47325
ec6187036495 new transfer proof method
huffman
parents:
diff changeset
   247
47684
ead185e60b8c tuned precedence order of transfer rules
huffman
parents: 47660
diff changeset
   248
text {* Transfer rules using implication instead of equality on booleans. *}
ead185e60b8c tuned precedence order of transfer rules
huffman
parents: 47660
diff changeset
   249
ead185e60b8c tuned precedence order of transfer rules
huffman
parents: 47660
diff changeset
   250
lemma eq_imp_transfer [transfer_rule]:
ead185e60b8c tuned precedence order of transfer rules
huffman
parents: 47660
diff changeset
   251
  "right_unique A \<Longrightarrow> (A ===> A ===> op \<longrightarrow>) (op =) (op =)"
ead185e60b8c tuned precedence order of transfer rules
huffman
parents: 47660
diff changeset
   252
  unfolding right_unique_alt_def .
ead185e60b8c tuned precedence order of transfer rules
huffman
parents: 47660
diff changeset
   253
ead185e60b8c tuned precedence order of transfer rules
huffman
parents: 47660
diff changeset
   254
lemma forall_imp_transfer [transfer_rule]:
ead185e60b8c tuned precedence order of transfer rules
huffman
parents: 47660
diff changeset
   255
  "right_total A \<Longrightarrow> ((A ===> op \<longrightarrow>) ===> op \<longrightarrow>) transfer_forall transfer_forall"
ead185e60b8c tuned precedence order of transfer rules
huffman
parents: 47660
diff changeset
   256
  unfolding right_total_alt_def transfer_forall_def .
ead185e60b8c tuned precedence order of transfer rules
huffman
parents: 47660
diff changeset
   257
47636
b786388b4b3a uniform naming scheme for transfer rules
huffman
parents: 47635
diff changeset
   258
lemma eq_transfer [transfer_rule]:
47325
ec6187036495 new transfer proof method
huffman
parents:
diff changeset
   259
  assumes "bi_unique A"
ec6187036495 new transfer proof method
huffman
parents:
diff changeset
   260
  shows "(A ===> A ===> op =) (op =) (op =)"
ec6187036495 new transfer proof method
huffman
parents:
diff changeset
   261
  using assms unfolding bi_unique_def fun_rel_def by auto
ec6187036495 new transfer proof method
huffman
parents:
diff changeset
   262
47636
b786388b4b3a uniform naming scheme for transfer rules
huffman
parents: 47635
diff changeset
   263
lemma All_transfer [transfer_rule]:
47325
ec6187036495 new transfer proof method
huffman
parents:
diff changeset
   264
  assumes "bi_total A"
ec6187036495 new transfer proof method
huffman
parents:
diff changeset
   265
  shows "((A ===> op =) ===> op =) All All"
ec6187036495 new transfer proof method
huffman
parents:
diff changeset
   266
  using assms unfolding bi_total_def fun_rel_def by fast
ec6187036495 new transfer proof method
huffman
parents:
diff changeset
   267
47636
b786388b4b3a uniform naming scheme for transfer rules
huffman
parents: 47635
diff changeset
   268
lemma Ex_transfer [transfer_rule]:
47325
ec6187036495 new transfer proof method
huffman
parents:
diff changeset
   269
  assumes "bi_total A"
ec6187036495 new transfer proof method
huffman
parents:
diff changeset
   270
  shows "((A ===> op =) ===> op =) Ex Ex"
ec6187036495 new transfer proof method
huffman
parents:
diff changeset
   271
  using assms unfolding bi_total_def fun_rel_def by fast
ec6187036495 new transfer proof method
huffman
parents:
diff changeset
   272
47636
b786388b4b3a uniform naming scheme for transfer rules
huffman
parents: 47635
diff changeset
   273
lemma If_transfer [transfer_rule]: "(op = ===> A ===> A ===> A) If If"
47325
ec6187036495 new transfer proof method
huffman
parents:
diff changeset
   274
  unfolding fun_rel_def by simp
ec6187036495 new transfer proof method
huffman
parents:
diff changeset
   275
47636
b786388b4b3a uniform naming scheme for transfer rules
huffman
parents: 47635
diff changeset
   276
lemma Let_transfer [transfer_rule]: "(A ===> (A ===> B) ===> B) Let Let"
47612
bc9c7b5c26fd add transfer rule for Let
huffman
parents: 47523
diff changeset
   277
  unfolding fun_rel_def by simp
bc9c7b5c26fd add transfer rule for Let
huffman
parents: 47523
diff changeset
   278
47636
b786388b4b3a uniform naming scheme for transfer rules
huffman
parents: 47635
diff changeset
   279
lemma id_transfer [transfer_rule]: "(A ===> A) id id"
47625
10cfaf771687 add transfer rule for 'id'
huffman
parents: 47618
diff changeset
   280
  unfolding fun_rel_def by simp
10cfaf771687 add transfer rule for 'id'
huffman
parents: 47618
diff changeset
   281
47636
b786388b4b3a uniform naming scheme for transfer rules
huffman
parents: 47635
diff changeset
   282
lemma comp_transfer [transfer_rule]:
47325
ec6187036495 new transfer proof method
huffman
parents:
diff changeset
   283
  "((B ===> C) ===> (A ===> B) ===> (A ===> C)) (op \<circ>) (op \<circ>)"
ec6187036495 new transfer proof method
huffman
parents:
diff changeset
   284
  unfolding fun_rel_def by simp
ec6187036495 new transfer proof method
huffman
parents:
diff changeset
   285
47636
b786388b4b3a uniform naming scheme for transfer rules
huffman
parents: 47635
diff changeset
   286
lemma fun_upd_transfer [transfer_rule]:
47325
ec6187036495 new transfer proof method
huffman
parents:
diff changeset
   287
  assumes [transfer_rule]: "bi_unique A"
ec6187036495 new transfer proof method
huffman
parents:
diff changeset
   288
  shows "((A ===> B) ===> A ===> B ===> A ===> B) fun_upd fun_upd"
47635
ebb79474262c rename 'correspondence' method to 'transfer_prover'
huffman
parents: 47627
diff changeset
   289
  unfolding fun_upd_def [abs_def] by transfer_prover
47325
ec6187036495 new transfer proof method
huffman
parents:
diff changeset
   290
47637
7a34395441ff add transfer rule for nat_case
huffman
parents: 47636
diff changeset
   291
lemma nat_case_transfer [transfer_rule]:
7a34395441ff add transfer rule for nat_case
huffman
parents: 47636
diff changeset
   292
  "(A ===> (op = ===> A) ===> op = ===> A) nat_case nat_case"
7a34395441ff add transfer rule for nat_case
huffman
parents: 47636
diff changeset
   293
  unfolding fun_rel_def by (simp split: nat.split)
47627
2b1d3eda59eb add secondary transfer rule for universal quantifiers on non-bi-total relations
huffman
parents: 47625
diff changeset
   294
47924
4e951258204b add transfer rules for nat_rec and funpow
huffman
parents: 47789
diff changeset
   295
lemma nat_rec_transfer [transfer_rule]:
4e951258204b add transfer rules for nat_rec and funpow
huffman
parents: 47789
diff changeset
   296
  "(A ===> (op = ===> A ===> A) ===> op = ===> A) nat_rec nat_rec"
4e951258204b add transfer rules for nat_rec and funpow
huffman
parents: 47789
diff changeset
   297
  unfolding fun_rel_def by (clarsimp, rename_tac n, induct_tac n, simp_all)
4e951258204b add transfer rules for nat_rec and funpow
huffman
parents: 47789
diff changeset
   298
4e951258204b add transfer rules for nat_rec and funpow
huffman
parents: 47789
diff changeset
   299
lemma funpow_transfer [transfer_rule]:
4e951258204b add transfer rules for nat_rec and funpow
huffman
parents: 47789
diff changeset
   300
  "(op = ===> (A ===> A) ===> (A ===> A)) compow compow"
4e951258204b add transfer rules for nat_rec and funpow
huffman
parents: 47789
diff changeset
   301
  unfolding funpow_def by transfer_prover
4e951258204b add transfer rules for nat_rec and funpow
huffman
parents: 47789
diff changeset
   302
47627
2b1d3eda59eb add secondary transfer rule for universal quantifiers on non-bi-total relations
huffman
parents: 47625
diff changeset
   303
text {* Fallback rule for transferring universal quantifiers over
2b1d3eda59eb add secondary transfer rule for universal quantifiers on non-bi-total relations
huffman
parents: 47625
diff changeset
   304
  correspondence relations that are not bi-total, and do not have
2b1d3eda59eb add secondary transfer rule for universal quantifiers on non-bi-total relations
huffman
parents: 47625
diff changeset
   305
  custom transfer rules (e.g. relations between function types). *}
2b1d3eda59eb add secondary transfer rule for universal quantifiers on non-bi-total relations
huffman
parents: 47625
diff changeset
   306
47637
7a34395441ff add transfer rule for nat_case
huffman
parents: 47636
diff changeset
   307
lemma Domainp_iff: "Domainp T x \<longleftrightarrow> (\<exists>y. T x y)"
7a34395441ff add transfer rule for nat_case
huffman
parents: 47636
diff changeset
   308
  by auto
7a34395441ff add transfer rule for nat_case
huffman
parents: 47636
diff changeset
   309
47627
2b1d3eda59eb add secondary transfer rule for universal quantifiers on non-bi-total relations
huffman
parents: 47625
diff changeset
   310
lemma Domainp_forall_transfer [transfer_rule]:
2b1d3eda59eb add secondary transfer rule for universal quantifiers on non-bi-total relations
huffman
parents: 47625
diff changeset
   311
  assumes "right_total A"
2b1d3eda59eb add secondary transfer rule for universal quantifiers on non-bi-total relations
huffman
parents: 47625
diff changeset
   312
  shows "((A ===> op =) ===> op =)
2b1d3eda59eb add secondary transfer rule for universal quantifiers on non-bi-total relations
huffman
parents: 47625
diff changeset
   313
    (transfer_bforall (Domainp A)) transfer_forall"
2b1d3eda59eb add secondary transfer rule for universal quantifiers on non-bi-total relations
huffman
parents: 47625
diff changeset
   314
  using assms unfolding right_total_def
2b1d3eda59eb add secondary transfer rule for universal quantifiers on non-bi-total relations
huffman
parents: 47625
diff changeset
   315
  unfolding transfer_forall_def transfer_bforall_def fun_rel_def Domainp_iff
2b1d3eda59eb add secondary transfer rule for universal quantifiers on non-bi-total relations
huffman
parents: 47625
diff changeset
   316
  by metis
2b1d3eda59eb add secondary transfer rule for universal quantifiers on non-bi-total relations
huffman
parents: 47625
diff changeset
   317
2b1d3eda59eb add secondary transfer rule for universal quantifiers on non-bi-total relations
huffman
parents: 47625
diff changeset
   318
text {* Preferred rule for transferring universal quantifiers over
2b1d3eda59eb add secondary transfer rule for universal quantifiers on non-bi-total relations
huffman
parents: 47625
diff changeset
   319
  bi-total correspondence relations (later rules are tried first). *}
2b1d3eda59eb add secondary transfer rule for universal quantifiers on non-bi-total relations
huffman
parents: 47625
diff changeset
   320
47636
b786388b4b3a uniform naming scheme for transfer rules
huffman
parents: 47635
diff changeset
   321
lemma forall_transfer [transfer_rule]:
47627
2b1d3eda59eb add secondary transfer rule for universal quantifiers on non-bi-total relations
huffman
parents: 47625
diff changeset
   322
  "bi_total A \<Longrightarrow> ((A ===> op =) ===> op =) transfer_forall transfer_forall"
47636
b786388b4b3a uniform naming scheme for transfer rules
huffman
parents: 47635
diff changeset
   323
  unfolding transfer_forall_def by (rule All_transfer)
47325
ec6187036495 new transfer proof method
huffman
parents:
diff changeset
   324
ec6187036495 new transfer proof method
huffman
parents:
diff changeset
   325
end