| author | wenzelm | 
| Fri, 11 Dec 2009 20:43:41 +0100 | |
| changeset 34075 | 451b0c8a15cf | 
| parent 33595 | 7264824baf66 | 
| child 34151 | 8d57ce46b3f7 | 
| permissions | -rw-r--r-- | 
| 4870 
cc36acb5b114
Extensible records with structural subtyping in HOL.  See
 wenzelm parents: diff
changeset | 1 | (* Title: HOL/Record.thy | 
| 32763 | 2 | Author: Wolfgang Naraschewski, TU Muenchen | 
| 3 | Author: Markus Wenzel, TU Muenchen | |
| 4 | Author: Norbert Schirmer, TU Muenchen | |
| 5 | Author: Thomas Sewell, NICTA | |
| 33595 
7264824baf66
substantial simplification restores code generation
 haftmann parents: 
32799diff
changeset | 6 | Author: Florian Haftmann, TU Muenchen | 
| 4870 
cc36acb5b114
Extensible records with structural subtyping in HOL.  See
 wenzelm parents: diff
changeset | 7 | *) | 
| 
cc36acb5b114
Extensible records with structural subtyping in HOL.  See
 wenzelm parents: diff
changeset | 8 | |
| 22817 | 9 | header {* Extensible records with structural subtyping *}
 | 
| 10 | ||
| 15131 | 11 | theory Record | 
| 33595 
7264824baf66
substantial simplification restores code generation
 haftmann parents: 
32799diff
changeset | 12 | imports Datatype | 
| 32744 
50406c4951d9
Record patch imported and working.
 Thomas Sewell <tsewell@nicta.com.au> parents: 
32743diff
changeset | 13 | uses ("Tools/record.ML")
 | 
| 15131 | 14 | begin | 
| 4870 
cc36acb5b114
Extensible records with structural subtyping in HOL.  See
 wenzelm parents: diff
changeset | 15 | |
| 33595 
7264824baf66
substantial simplification restores code generation
 haftmann parents: 
32799diff
changeset | 16 | subsection {* Introduction *}
 | 
| 
7264824baf66
substantial simplification restores code generation
 haftmann parents: 
32799diff
changeset | 17 | |
| 
7264824baf66
substantial simplification restores code generation
 haftmann parents: 
32799diff
changeset | 18 | text {*
 | 
| 
7264824baf66
substantial simplification restores code generation
 haftmann parents: 
32799diff
changeset | 19 | Records are isomorphic to compound tuple types. To implement | 
| 
7264824baf66
substantial simplification restores code generation
 haftmann parents: 
32799diff
changeset | 20 | efficient records, we make this isomorphism explicit. Consider the | 
| 
7264824baf66
substantial simplification restores code generation
 haftmann parents: 
32799diff
changeset | 21 |   record access/update simplification @{text "alpha (beta_update f
 | 
| 
7264824baf66
substantial simplification restores code generation
 haftmann parents: 
32799diff
changeset | 22 | rec) = alpha rec"} for distinct fields alpha and beta of some record | 
| 
7264824baf66
substantial simplification restores code generation
 haftmann parents: 
32799diff
changeset | 23 |   rec with n fields. There are @{text "n ^ 2"} such theorems, which
 | 
| 
7264824baf66
substantial simplification restores code generation
 haftmann parents: 
32799diff
changeset | 24 | prohibits storage of all of them for large n. The rules can be | 
| 
7264824baf66
substantial simplification restores code generation
 haftmann parents: 
32799diff
changeset | 25 | proved on the fly by case decomposition and simplification in O(n) | 
| 
7264824baf66
substantial simplification restores code generation
 haftmann parents: 
32799diff
changeset | 26 | time. By creating O(n) isomorphic-tuple types while defining the | 
| 
7264824baf66
substantial simplification restores code generation
 haftmann parents: 
32799diff
changeset | 27 | record, however, we can prove the access/update simplification in | 
| 
7264824baf66
substantial simplification restores code generation
 haftmann parents: 
32799diff
changeset | 28 |   @{text "O(log(n)^2)"} time.
 | 
| 
7264824baf66
substantial simplification restores code generation
 haftmann parents: 
32799diff
changeset | 29 | |
| 
7264824baf66
substantial simplification restores code generation
 haftmann parents: 
32799diff
changeset | 30 | The O(n) cost of case decomposition is not because O(n) steps are | 
| 
7264824baf66
substantial simplification restores code generation
 haftmann parents: 
32799diff
changeset | 31 | taken, but rather because the resulting rule must contain O(n) new | 
| 
7264824baf66
substantial simplification restores code generation
 haftmann parents: 
32799diff
changeset | 32 | variables and an O(n) size concrete record construction. To sidestep | 
| 
7264824baf66
substantial simplification restores code generation
 haftmann parents: 
32799diff
changeset | 33 | this cost, we would like to avoid case decomposition in proving | 
| 
7264824baf66
substantial simplification restores code generation
 haftmann parents: 
32799diff
changeset | 34 | access/update theorems. | 
| 
7264824baf66
substantial simplification restores code generation
 haftmann parents: 
32799diff
changeset | 35 | |
| 
7264824baf66
substantial simplification restores code generation
 haftmann parents: 
32799diff
changeset | 36 | Record types are defined as isomorphic to tuple types. For instance, | 
| 
7264824baf66
substantial simplification restores code generation
 haftmann parents: 
32799diff
changeset | 37 |   a record type with fields @{text "'a"}, @{text "'b"}, @{text "'c"}
 | 
| 
7264824baf66
substantial simplification restores code generation
 haftmann parents: 
32799diff
changeset | 38 |   and @{text "'d"} might be introduced as isomorphic to @{text "'a \<times>
 | 
| 
7264824baf66
substantial simplification restores code generation
 haftmann parents: 
32799diff
changeset | 39 |   ('b \<times> ('c \<times> 'd))"}. If we balance the tuple tree to @{text "('a \<times>
 | 
| 
7264824baf66
substantial simplification restores code generation
 haftmann parents: 
32799diff
changeset | 40 |   'b) \<times> ('c \<times> 'd)"} then accessors can be defined by converting to the
 | 
| 
7264824baf66
substantial simplification restores code generation
 haftmann parents: 
32799diff
changeset | 41 | underlying type then using O(log(n)) fst or snd operations. | 
| 
7264824baf66
substantial simplification restores code generation
 haftmann parents: 
32799diff
changeset | 42 |   Updators can be defined similarly, if we introduce a @{text
 | 
| 
7264824baf66
substantial simplification restores code generation
 haftmann parents: 
32799diff
changeset | 43 |   "fst_update"} and @{text "snd_update"} function. Furthermore, we can
 | 
| 
7264824baf66
substantial simplification restores code generation
 haftmann parents: 
32799diff
changeset | 44 | prove the access/update theorem in O(log(n)) steps by using simple | 
| 
7264824baf66
substantial simplification restores code generation
 haftmann parents: 
32799diff
changeset | 45 |   rewrites on fst, snd, @{text "fst_update"} and @{text "snd_update"}.
 | 
| 
7264824baf66
substantial simplification restores code generation
 haftmann parents: 
32799diff
changeset | 46 | |
| 
7264824baf66
substantial simplification restores code generation
 haftmann parents: 
32799diff
changeset | 47 | The catch is that, although O(log(n)) steps were taken, the | 
| 
7264824baf66
substantial simplification restores code generation
 haftmann parents: 
32799diff
changeset | 48 | underlying type we converted to is a tuple tree of size | 
| 
7264824baf66
substantial simplification restores code generation
 haftmann parents: 
32799diff
changeset | 49 | O(n). Processing this term type wastes performance. We avoid this | 
| 
7264824baf66
substantial simplification restores code generation
 haftmann parents: 
32799diff
changeset | 50 | for large n by taking each subtree of size K and defining a new type | 
| 
7264824baf66
substantial simplification restores code generation
 haftmann parents: 
32799diff
changeset | 51 | isomorphic to that tuple subtree. A record can now be defined as | 
| 
7264824baf66
substantial simplification restores code generation
 haftmann parents: 
32799diff
changeset | 52 |   isomorphic to a tuple tree of these O(n/K) new types, or, if @{text
 | 
| 
7264824baf66
substantial simplification restores code generation
 haftmann parents: 
32799diff
changeset | 53 | "n > K*K"}, we can repeat the process, until the record can be | 
| 
7264824baf66
substantial simplification restores code generation
 haftmann parents: 
32799diff
changeset | 54 | defined in terms of a tuple tree of complexity less than the | 
| 
7264824baf66
substantial simplification restores code generation
 haftmann parents: 
32799diff
changeset | 55 | constant K. | 
| 
7264824baf66
substantial simplification restores code generation
 haftmann parents: 
32799diff
changeset | 56 | |
| 
7264824baf66
substantial simplification restores code generation
 haftmann parents: 
32799diff
changeset | 57 | If we prove the access/update theorem on this type with the | 
| 
7264824baf66
substantial simplification restores code generation
 haftmann parents: 
32799diff
changeset | 58 |   analagous steps to the tuple tree, we consume @{text "O(log(n)^2)"}
 | 
| 
7264824baf66
substantial simplification restores code generation
 haftmann parents: 
32799diff
changeset | 59 |   time as the intermediate terms are @{text "O(log(n))"} in size and
 | 
| 
7264824baf66
substantial simplification restores code generation
 haftmann parents: 
32799diff
changeset | 60 | the types needed have size bounded by K. To enable this analagous | 
| 
7264824baf66
substantial simplification restores code generation
 haftmann parents: 
32799diff
changeset | 61 |   traversal, we define the functions seen below: @{text
 | 
| 
7264824baf66
substantial simplification restores code generation
 haftmann parents: 
32799diff
changeset | 62 |   "istuple_fst"}, @{text "istuple_snd"}, @{text "istuple_fst_update"}
 | 
| 
7264824baf66
substantial simplification restores code generation
 haftmann parents: 
32799diff
changeset | 63 |   and @{text "istuple_snd_update"}. These functions generalise tuple
 | 
| 
7264824baf66
substantial simplification restores code generation
 haftmann parents: 
32799diff
changeset | 64 | operations by taking a parameter that encapsulates a tuple | 
| 
7264824baf66
substantial simplification restores code generation
 haftmann parents: 
32799diff
changeset | 65 | isomorphism. The rewrites needed on these functions now need an | 
| 
7264824baf66
substantial simplification restores code generation
 haftmann parents: 
32799diff
changeset | 66 | additional assumption which is that the isomorphism works. | 
| 
7264824baf66
substantial simplification restores code generation
 haftmann parents: 
32799diff
changeset | 67 | |
| 
7264824baf66
substantial simplification restores code generation
 haftmann parents: 
32799diff
changeset | 68 | These rewrites are typically used in a structured way. They are here | 
| 
7264824baf66
substantial simplification restores code generation
 haftmann parents: 
32799diff
changeset | 69 |   presented as the introduction rule @{text "isomorphic_tuple.intros"}
 | 
| 
7264824baf66
substantial simplification restores code generation
 haftmann parents: 
32799diff
changeset | 70 | rather than as a rewrite rule set. The introduction form is an | 
| 
7264824baf66
substantial simplification restores code generation
 haftmann parents: 
32799diff
changeset | 71 | optimisation, as net matching can be performed at one term location | 
| 
7264824baf66
substantial simplification restores code generation
 haftmann parents: 
32799diff
changeset | 72 | for each step rather than the simplifier searching the term for | 
| 
7264824baf66
substantial simplification restores code generation
 haftmann parents: 
32799diff
changeset | 73 | possible pattern matches. The rule set is used as it is viewed | 
| 
7264824baf66
substantial simplification restores code generation
 haftmann parents: 
32799diff
changeset | 74 | outside the locale, with the locale assumption (that the isomorphism | 
| 
7264824baf66
substantial simplification restores code generation
 haftmann parents: 
32799diff
changeset | 75 | is valid) left as a rule assumption. All rules are structured to aid | 
| 
7264824baf66
substantial simplification restores code generation
 haftmann parents: 
32799diff
changeset | 76 | net matching, using either a point-free form or an encapsulating | 
| 
7264824baf66
substantial simplification restores code generation
 haftmann parents: 
32799diff
changeset | 77 | predicate. | 
| 
7264824baf66
substantial simplification restores code generation
 haftmann parents: 
32799diff
changeset | 78 | *} | 
| 
7264824baf66
substantial simplification restores code generation
 haftmann parents: 
32799diff
changeset | 79 | |
| 
7264824baf66
substantial simplification restores code generation
 haftmann parents: 
32799diff
changeset | 80 | subsection {* Operators and lemmas for types isomorphic to tuples *}
 | 
| 
7264824baf66
substantial simplification restores code generation
 haftmann parents: 
32799diff
changeset | 81 | |
| 
7264824baf66
substantial simplification restores code generation
 haftmann parents: 
32799diff
changeset | 82 | datatype ('a, 'b, 'c) tuple_isomorphism = TupleIsomorphism "'a \<Rightarrow> 'b \<times> 'c" "'b \<times> 'c \<Rightarrow> 'a"
 | 
| 
7264824baf66
substantial simplification restores code generation
 haftmann parents: 
32799diff
changeset | 83 | |
| 
7264824baf66
substantial simplification restores code generation
 haftmann parents: 
32799diff
changeset | 84 | primrec repr :: "('a, 'b, 'c) tuple_isomorphism \<Rightarrow> 'a \<Rightarrow> 'b \<times> 'c" where
 | 
| 
7264824baf66
substantial simplification restores code generation
 haftmann parents: 
32799diff
changeset | 85 | "repr (TupleIsomorphism r a) = r" | 
| 
7264824baf66
substantial simplification restores code generation
 haftmann parents: 
32799diff
changeset | 86 | |
| 
7264824baf66
substantial simplification restores code generation
 haftmann parents: 
32799diff
changeset | 87 | primrec abst :: "('a, 'b, 'c) tuple_isomorphism \<Rightarrow> 'b \<times> 'c \<Rightarrow> 'a" where
 | 
| 
7264824baf66
substantial simplification restores code generation
 haftmann parents: 
32799diff
changeset | 88 | "abst (TupleIsomorphism r a) = a" | 
| 
7264824baf66
substantial simplification restores code generation
 haftmann parents: 
32799diff
changeset | 89 | |
| 
7264824baf66
substantial simplification restores code generation
 haftmann parents: 
32799diff
changeset | 90 | definition istuple_fst :: "('a, 'b, 'c) tuple_isomorphism \<Rightarrow> 'a \<Rightarrow> 'b" where
 | 
| 
7264824baf66
substantial simplification restores code generation
 haftmann parents: 
32799diff
changeset | 91 | "istuple_fst isom = fst \<circ> repr isom" | 
| 
7264824baf66
substantial simplification restores code generation
 haftmann parents: 
32799diff
changeset | 92 | |
| 
7264824baf66
substantial simplification restores code generation
 haftmann parents: 
32799diff
changeset | 93 | definition istuple_snd :: "('a, 'b, 'c) tuple_isomorphism \<Rightarrow> 'a \<Rightarrow> 'c" where
 | 
| 
7264824baf66
substantial simplification restores code generation
 haftmann parents: 
32799diff
changeset | 94 | "istuple_snd isom = snd \<circ> repr isom" | 
| 
7264824baf66
substantial simplification restores code generation
 haftmann parents: 
32799diff
changeset | 95 | |
| 
7264824baf66
substantial simplification restores code generation
 haftmann parents: 
32799diff
changeset | 96 | definition istuple_fst_update :: "('a, 'b, 'c) tuple_isomorphism \<Rightarrow> ('b \<Rightarrow> 'b) \<Rightarrow> ('a \<Rightarrow> 'a)" where
 | 
| 
7264824baf66
substantial simplification restores code generation
 haftmann parents: 
32799diff
changeset | 97 | "istuple_fst_update isom f = abst isom \<circ> apfst f \<circ> repr isom" | 
| 
7264824baf66
substantial simplification restores code generation
 haftmann parents: 
32799diff
changeset | 98 | |
| 
7264824baf66
substantial simplification restores code generation
 haftmann parents: 
32799diff
changeset | 99 | definition istuple_snd_update :: "('a, 'b, 'c) tuple_isomorphism \<Rightarrow> ('c \<Rightarrow> 'c) \<Rightarrow> ('a \<Rightarrow> 'a)" where
 | 
| 
7264824baf66
substantial simplification restores code generation
 haftmann parents: 
32799diff
changeset | 100 | "istuple_snd_update isom f = abst isom \<circ> apsnd f \<circ> repr isom" | 
| 
7264824baf66
substantial simplification restores code generation
 haftmann parents: 
32799diff
changeset | 101 | |
| 
7264824baf66
substantial simplification restores code generation
 haftmann parents: 
32799diff
changeset | 102 | definition istuple_cons :: "('a, 'b, 'c) tuple_isomorphism \<Rightarrow> 'b \<Rightarrow> 'c \<Rightarrow> 'a" where
 | 
| 
7264824baf66
substantial simplification restores code generation
 haftmann parents: 
32799diff
changeset | 103 | "istuple_cons isom = curry (abst isom)" | 
| 
7264824baf66
substantial simplification restores code generation
 haftmann parents: 
32799diff
changeset | 104 | |
| 
7264824baf66
substantial simplification restores code generation
 haftmann parents: 
32799diff
changeset | 105 | |
| 
7264824baf66
substantial simplification restores code generation
 haftmann parents: 
32799diff
changeset | 106 | subsection {* Logical infrastructure for records *}
 | 
| 
7264824baf66
substantial simplification restores code generation
 haftmann parents: 
32799diff
changeset | 107 | |
| 
7264824baf66
substantial simplification restores code generation
 haftmann parents: 
32799diff
changeset | 108 | definition istuple_surjective_proof_assist :: "'a \<Rightarrow> 'b \<Rightarrow> ('a \<Rightarrow> 'b) \<Rightarrow> bool" where
 | 
| 
7264824baf66
substantial simplification restores code generation
 haftmann parents: 
32799diff
changeset | 109 | "istuple_surjective_proof_assist x y f \<longleftrightarrow> f x = y" | 
| 
7264824baf66
substantial simplification restores code generation
 haftmann parents: 
32799diff
changeset | 110 | |
| 
7264824baf66
substantial simplification restores code generation
 haftmann parents: 
32799diff
changeset | 111 | definition istuple_update_accessor_cong_assist :: "(('b \<Rightarrow> 'b) \<Rightarrow> ('a \<Rightarrow> 'a)) \<Rightarrow> ('a \<Rightarrow> 'b) \<Rightarrow> bool" where
 | 
| 
7264824baf66
substantial simplification restores code generation
 haftmann parents: 
32799diff
changeset | 112 | "istuple_update_accessor_cong_assist upd acc \<longleftrightarrow> | 
| 
7264824baf66
substantial simplification restores code generation
 haftmann parents: 
32799diff
changeset | 113 | (\<forall>f v. upd (\<lambda>x. f (acc v)) v = upd f v) \<and> (\<forall>v. upd id v = v)" | 
| 
7264824baf66
substantial simplification restores code generation
 haftmann parents: 
32799diff
changeset | 114 | |
| 
7264824baf66
substantial simplification restores code generation
 haftmann parents: 
32799diff
changeset | 115 | definition istuple_update_accessor_eq_assist :: "(('b \<Rightarrow> 'b) \<Rightarrow> ('a \<Rightarrow> 'a)) \<Rightarrow> ('a \<Rightarrow> 'b) \<Rightarrow> 'a \<Rightarrow> ('b \<Rightarrow> 'b) \<Rightarrow> 'a \<Rightarrow> 'b \<Rightarrow> bool" where
 | 
| 
7264824baf66
substantial simplification restores code generation
 haftmann parents: 
32799diff
changeset | 116 | "istuple_update_accessor_eq_assist upd acc v f v' x \<longleftrightarrow> | 
| 
7264824baf66
substantial simplification restores code generation
 haftmann parents: 
32799diff
changeset | 117 | upd f v = v' \<and> acc v = x \<and> istuple_update_accessor_cong_assist upd acc" | 
| 
7264824baf66
substantial simplification restores code generation
 haftmann parents: 
32799diff
changeset | 118 | |
| 
7264824baf66
substantial simplification restores code generation
 haftmann parents: 
32799diff
changeset | 119 | lemma update_accessor_congruence_foldE: | 
| 
7264824baf66
substantial simplification restores code generation
 haftmann parents: 
32799diff
changeset | 120 | assumes uac: "istuple_update_accessor_cong_assist upd acc" | 
| 
7264824baf66
substantial simplification restores code generation
 haftmann parents: 
32799diff
changeset | 121 | and r: "r = r'" and v: "acc r' = v'" | 
| 
7264824baf66
substantial simplification restores code generation
 haftmann parents: 
32799diff
changeset | 122 | and f: "\<And>v. v' = v \<Longrightarrow> f v = f' v" | 
| 
7264824baf66
substantial simplification restores code generation
 haftmann parents: 
32799diff
changeset | 123 | shows "upd f r = upd f' r'" | 
| 
7264824baf66
substantial simplification restores code generation
 haftmann parents: 
32799diff
changeset | 124 | using uac r v [symmetric] | 
| 
7264824baf66
substantial simplification restores code generation
 haftmann parents: 
32799diff
changeset | 125 | apply (subgoal_tac "upd (\<lambda>x. f (acc r')) r' = upd (\<lambda>x. f' (acc r')) r'") | 
| 
7264824baf66
substantial simplification restores code generation
 haftmann parents: 
32799diff
changeset | 126 | apply (simp add: istuple_update_accessor_cong_assist_def) | 
| 
7264824baf66
substantial simplification restores code generation
 haftmann parents: 
32799diff
changeset | 127 | apply (simp add: f) | 
| 
7264824baf66
substantial simplification restores code generation
 haftmann parents: 
32799diff
changeset | 128 | done | 
| 
7264824baf66
substantial simplification restores code generation
 haftmann parents: 
32799diff
changeset | 129 | |
| 
7264824baf66
substantial simplification restores code generation
 haftmann parents: 
32799diff
changeset | 130 | lemma update_accessor_congruence_unfoldE: | 
| 
7264824baf66
substantial simplification restores code generation
 haftmann parents: 
32799diff
changeset | 131 | "istuple_update_accessor_cong_assist upd acc \<Longrightarrow> r = r' \<Longrightarrow> acc r' = v' \<Longrightarrow> (\<And>v. v = v' \<Longrightarrow> f v = f' v) | 
| 
7264824baf66
substantial simplification restores code generation
 haftmann parents: 
32799diff
changeset | 132 | \<Longrightarrow> upd f r = upd f' r'" | 
| 
7264824baf66
substantial simplification restores code generation
 haftmann parents: 
32799diff
changeset | 133 | apply (erule(2) update_accessor_congruence_foldE) | 
| 
7264824baf66
substantial simplification restores code generation
 haftmann parents: 
32799diff
changeset | 134 | apply simp | 
| 
7264824baf66
substantial simplification restores code generation
 haftmann parents: 
32799diff
changeset | 135 | done | 
| 
7264824baf66
substantial simplification restores code generation
 haftmann parents: 
32799diff
changeset | 136 | |
| 
7264824baf66
substantial simplification restores code generation
 haftmann parents: 
32799diff
changeset | 137 | lemma istuple_update_accessor_cong_assist_id: | 
| 
7264824baf66
substantial simplification restores code generation
 haftmann parents: 
32799diff
changeset | 138 | "istuple_update_accessor_cong_assist upd acc \<Longrightarrow> upd id = id" | 
| 
7264824baf66
substantial simplification restores code generation
 haftmann parents: 
32799diff
changeset | 139 | by rule (simp add: istuple_update_accessor_cong_assist_def) | 
| 
7264824baf66
substantial simplification restores code generation
 haftmann parents: 
32799diff
changeset | 140 | |
| 
7264824baf66
substantial simplification restores code generation
 haftmann parents: 
32799diff
changeset | 141 | lemma update_accessor_noopE: | 
| 
7264824baf66
substantial simplification restores code generation
 haftmann parents: 
32799diff
changeset | 142 | assumes uac: "istuple_update_accessor_cong_assist upd acc" | 
| 
7264824baf66
substantial simplification restores code generation
 haftmann parents: 
32799diff
changeset | 143 | and acc: "f (acc x) = acc x" | 
| 
7264824baf66
substantial simplification restores code generation
 haftmann parents: 
32799diff
changeset | 144 | shows "upd f x = x" | 
| 
7264824baf66
substantial simplification restores code generation
 haftmann parents: 
32799diff
changeset | 145 | using uac by (simp add: acc istuple_update_accessor_cong_assist_id [OF uac, unfolded id_def] | 
| 
7264824baf66
substantial simplification restores code generation
 haftmann parents: 
32799diff
changeset | 146 | cong: update_accessor_congruence_unfoldE [OF uac]) | 
| 
7264824baf66
substantial simplification restores code generation
 haftmann parents: 
32799diff
changeset | 147 | |
| 
7264824baf66
substantial simplification restores code generation
 haftmann parents: 
32799diff
changeset | 148 | lemma update_accessor_noop_compE: | 
| 
7264824baf66
substantial simplification restores code generation
 haftmann parents: 
32799diff
changeset | 149 | assumes uac: "istuple_update_accessor_cong_assist upd acc" | 
| 
7264824baf66
substantial simplification restores code generation
 haftmann parents: 
32799diff
changeset | 150 | assumes acc: "f (acc x) = acc x" | 
| 
7264824baf66
substantial simplification restores code generation
 haftmann parents: 
32799diff
changeset | 151 | shows "upd (g \<circ> f) x = upd g x" | 
| 
7264824baf66
substantial simplification restores code generation
 haftmann parents: 
32799diff
changeset | 152 | by (simp add: acc cong: update_accessor_congruence_unfoldE[OF uac]) | 
| 
7264824baf66
substantial simplification restores code generation
 haftmann parents: 
32799diff
changeset | 153 | |
| 
7264824baf66
substantial simplification restores code generation
 haftmann parents: 
32799diff
changeset | 154 | lemma update_accessor_cong_assist_idI: | 
| 
7264824baf66
substantial simplification restores code generation
 haftmann parents: 
32799diff
changeset | 155 | "istuple_update_accessor_cong_assist id id" | 
| 
7264824baf66
substantial simplification restores code generation
 haftmann parents: 
32799diff
changeset | 156 | by (simp add: istuple_update_accessor_cong_assist_def) | 
| 
7264824baf66
substantial simplification restores code generation
 haftmann parents: 
32799diff
changeset | 157 | |
| 
7264824baf66
substantial simplification restores code generation
 haftmann parents: 
32799diff
changeset | 158 | lemma update_accessor_cong_assist_triv: | 
| 
7264824baf66
substantial simplification restores code generation
 haftmann parents: 
32799diff
changeset | 159 | "istuple_update_accessor_cong_assist upd acc \<Longrightarrow> istuple_update_accessor_cong_assist upd acc" | 
| 
7264824baf66
substantial simplification restores code generation
 haftmann parents: 
32799diff
changeset | 160 | by assumption | 
| 
7264824baf66
substantial simplification restores code generation
 haftmann parents: 
32799diff
changeset | 161 | |
| 
7264824baf66
substantial simplification restores code generation
 haftmann parents: 
32799diff
changeset | 162 | lemma update_accessor_accessor_eqE: | 
| 
7264824baf66
substantial simplification restores code generation
 haftmann parents: 
32799diff
changeset | 163 | "istuple_update_accessor_eq_assist upd acc v f v' x \<Longrightarrow> acc v = x" | 
| 
7264824baf66
substantial simplification restores code generation
 haftmann parents: 
32799diff
changeset | 164 | by (simp add: istuple_update_accessor_eq_assist_def) | 
| 
7264824baf66
substantial simplification restores code generation
 haftmann parents: 
32799diff
changeset | 165 | |
| 
7264824baf66
substantial simplification restores code generation
 haftmann parents: 
32799diff
changeset | 166 | lemma update_accessor_updator_eqE: | 
| 
7264824baf66
substantial simplification restores code generation
 haftmann parents: 
32799diff
changeset | 167 | "istuple_update_accessor_eq_assist upd acc v f v' x \<Longrightarrow> upd f v = v'" | 
| 
7264824baf66
substantial simplification restores code generation
 haftmann parents: 
32799diff
changeset | 168 | by (simp add: istuple_update_accessor_eq_assist_def) | 
| 
7264824baf66
substantial simplification restores code generation
 haftmann parents: 
32799diff
changeset | 169 | |
| 
7264824baf66
substantial simplification restores code generation
 haftmann parents: 
32799diff
changeset | 170 | lemma istuple_update_accessor_eq_assist_idI: | 
| 
7264824baf66
substantial simplification restores code generation
 haftmann parents: 
32799diff
changeset | 171 | "v' = f v \<Longrightarrow> istuple_update_accessor_eq_assist id id v f v' v" | 
| 
7264824baf66
substantial simplification restores code generation
 haftmann parents: 
32799diff
changeset | 172 | by (simp add: istuple_update_accessor_eq_assist_def update_accessor_cong_assist_idI) | 
| 
7264824baf66
substantial simplification restores code generation
 haftmann parents: 
32799diff
changeset | 173 | |
| 
7264824baf66
substantial simplification restores code generation
 haftmann parents: 
32799diff
changeset | 174 | lemma istuple_update_accessor_eq_assist_triv: | 
| 
7264824baf66
substantial simplification restores code generation
 haftmann parents: 
32799diff
changeset | 175 | "istuple_update_accessor_eq_assist upd acc v f v' x \<Longrightarrow> istuple_update_accessor_eq_assist upd acc v f v' x" | 
| 
7264824baf66
substantial simplification restores code generation
 haftmann parents: 
32799diff
changeset | 176 | by assumption | 
| 
7264824baf66
substantial simplification restores code generation
 haftmann parents: 
32799diff
changeset | 177 | |
| 
7264824baf66
substantial simplification restores code generation
 haftmann parents: 
32799diff
changeset | 178 | lemma istuple_update_accessor_cong_from_eq: | 
| 
7264824baf66
substantial simplification restores code generation
 haftmann parents: 
32799diff
changeset | 179 | "istuple_update_accessor_eq_assist upd acc v f v' x \<Longrightarrow> istuple_update_accessor_cong_assist upd acc" | 
| 
7264824baf66
substantial simplification restores code generation
 haftmann parents: 
32799diff
changeset | 180 | by (simp add: istuple_update_accessor_eq_assist_def) | 
| 
7264824baf66
substantial simplification restores code generation
 haftmann parents: 
32799diff
changeset | 181 | |
| 
7264824baf66
substantial simplification restores code generation
 haftmann parents: 
32799diff
changeset | 182 | lemma o_eq_dest: | 
| 
7264824baf66
substantial simplification restores code generation
 haftmann parents: 
32799diff
changeset | 183 | "a o b = c o d \<Longrightarrow> a (b v) = c (d v)" | 
| 
7264824baf66
substantial simplification restores code generation
 haftmann parents: 
32799diff
changeset | 184 | apply (clarsimp simp: o_def) | 
| 
7264824baf66
substantial simplification restores code generation
 haftmann parents: 
32799diff
changeset | 185 | apply (erule fun_cong) | 
| 
7264824baf66
substantial simplification restores code generation
 haftmann parents: 
32799diff
changeset | 186 | done | 
| 
7264824baf66
substantial simplification restores code generation
 haftmann parents: 
32799diff
changeset | 187 | |
| 
7264824baf66
substantial simplification restores code generation
 haftmann parents: 
32799diff
changeset | 188 | lemma o_eq_elim: | 
| 
7264824baf66
substantial simplification restores code generation
 haftmann parents: 
32799diff
changeset | 189 | "a o b = c o d \<Longrightarrow> ((\<And>v. a (b v) = c (d v)) \<Longrightarrow> R) \<Longrightarrow> R" | 
| 
7264824baf66
substantial simplification restores code generation
 haftmann parents: 
32799diff
changeset | 190 | apply (erule meta_mp) | 
| 
7264824baf66
substantial simplification restores code generation
 haftmann parents: 
32799diff
changeset | 191 | apply (erule o_eq_dest) | 
| 
7264824baf66
substantial simplification restores code generation
 haftmann parents: 
32799diff
changeset | 192 | done | 
| 
7264824baf66
substantial simplification restores code generation
 haftmann parents: 
32799diff
changeset | 193 | |
| 
7264824baf66
substantial simplification restores code generation
 haftmann parents: 
32799diff
changeset | 194 | lemma istuple_surjective_proof_assistI: | 
| 
7264824baf66
substantial simplification restores code generation
 haftmann parents: 
32799diff
changeset | 195 | "f x = y \<Longrightarrow> istuple_surjective_proof_assist x y f" | 
| 
7264824baf66
substantial simplification restores code generation
 haftmann parents: 
32799diff
changeset | 196 | by (simp add: istuple_surjective_proof_assist_def) | 
| 
7264824baf66
substantial simplification restores code generation
 haftmann parents: 
32799diff
changeset | 197 | |
| 
7264824baf66
substantial simplification restores code generation
 haftmann parents: 
32799diff
changeset | 198 | lemma istuple_surjective_proof_assist_idE: | 
| 
7264824baf66
substantial simplification restores code generation
 haftmann parents: 
32799diff
changeset | 199 | "istuple_surjective_proof_assist x y id \<Longrightarrow> x = y" | 
| 
7264824baf66
substantial simplification restores code generation
 haftmann parents: 
32799diff
changeset | 200 | by (simp add: istuple_surjective_proof_assist_def) | 
| 
7264824baf66
substantial simplification restores code generation
 haftmann parents: 
32799diff
changeset | 201 | |
| 
7264824baf66
substantial simplification restores code generation
 haftmann parents: 
32799diff
changeset | 202 | locale isomorphic_tuple = | 
| 
7264824baf66
substantial simplification restores code generation
 haftmann parents: 
32799diff
changeset | 203 |   fixes isom :: "('a, 'b, 'c) tuple_isomorphism"
 | 
| 
7264824baf66
substantial simplification restores code generation
 haftmann parents: 
32799diff
changeset | 204 | and repr and abst | 
| 
7264824baf66
substantial simplification restores code generation
 haftmann parents: 
32799diff
changeset | 205 | defines "repr \<equiv> Record.repr isom" | 
| 
7264824baf66
substantial simplification restores code generation
 haftmann parents: 
32799diff
changeset | 206 | defines "abst \<equiv> Record.abst isom" | 
| 
7264824baf66
substantial simplification restores code generation
 haftmann parents: 
32799diff
changeset | 207 | assumes repr_inv: "\<And>x. abst (repr x) = x" | 
| 
7264824baf66
substantial simplification restores code generation
 haftmann parents: 
32799diff
changeset | 208 | assumes abst_inv: "\<And>y. repr (abst y) = y" | 
| 
7264824baf66
substantial simplification restores code generation
 haftmann parents: 
32799diff
changeset | 209 | begin | 
| 
7264824baf66
substantial simplification restores code generation
 haftmann parents: 
32799diff
changeset | 210 | |
| 
7264824baf66
substantial simplification restores code generation
 haftmann parents: 
32799diff
changeset | 211 | lemma repr_inj: | 
| 
7264824baf66
substantial simplification restores code generation
 haftmann parents: 
32799diff
changeset | 212 | "repr x = repr y \<longleftrightarrow> x = y" | 
| 
7264824baf66
substantial simplification restores code generation
 haftmann parents: 
32799diff
changeset | 213 | apply (rule iffI, simp_all) | 
| 
7264824baf66
substantial simplification restores code generation
 haftmann parents: 
32799diff
changeset | 214 | apply (drule_tac f=abst in arg_cong, simp add: repr_inv) | 
| 
7264824baf66
substantial simplification restores code generation
 haftmann parents: 
32799diff
changeset | 215 | done | 
| 
7264824baf66
substantial simplification restores code generation
 haftmann parents: 
32799diff
changeset | 216 | |
| 
7264824baf66
substantial simplification restores code generation
 haftmann parents: 
32799diff
changeset | 217 | lemma abst_inj: | 
| 
7264824baf66
substantial simplification restores code generation
 haftmann parents: 
32799diff
changeset | 218 | "abst x = abst y \<longleftrightarrow> x = y" | 
| 
7264824baf66
substantial simplification restores code generation
 haftmann parents: 
32799diff
changeset | 219 | apply (rule iffI, simp_all) | 
| 
7264824baf66
substantial simplification restores code generation
 haftmann parents: 
32799diff
changeset | 220 | apply (drule_tac f=repr in arg_cong, simp add: abst_inv) | 
| 
7264824baf66
substantial simplification restores code generation
 haftmann parents: 
32799diff
changeset | 221 | done | 
| 
7264824baf66
substantial simplification restores code generation
 haftmann parents: 
32799diff
changeset | 222 | |
| 
7264824baf66
substantial simplification restores code generation
 haftmann parents: 
32799diff
changeset | 223 | lemmas simps = Let_def repr_inv abst_inv repr_inj abst_inj repr_def [symmetric] abst_def [symmetric] | 
| 
7264824baf66
substantial simplification restores code generation
 haftmann parents: 
32799diff
changeset | 224 | |
| 
7264824baf66
substantial simplification restores code generation
 haftmann parents: 
32799diff
changeset | 225 | lemma istuple_access_update_fst_fst: | 
| 
7264824baf66
substantial simplification restores code generation
 haftmann parents: 
32799diff
changeset | 226 | "f o h g = j o f \<Longrightarrow> | 
| 
7264824baf66
substantial simplification restores code generation
 haftmann parents: 
32799diff
changeset | 227 | (f o istuple_fst isom) o (istuple_fst_update isom o h) g | 
| 
7264824baf66
substantial simplification restores code generation
 haftmann parents: 
32799diff
changeset | 228 | = j o (f o istuple_fst isom)" | 
| 
7264824baf66
substantial simplification restores code generation
 haftmann parents: 
32799diff
changeset | 229 | by (clarsimp simp: istuple_fst_update_def istuple_fst_def simps | 
| 
7264824baf66
substantial simplification restores code generation
 haftmann parents: 
32799diff
changeset | 230 | intro!: ext elim!: o_eq_elim) | 
| 
7264824baf66
substantial simplification restores code generation
 haftmann parents: 
32799diff
changeset | 231 | |
| 
7264824baf66
substantial simplification restores code generation
 haftmann parents: 
32799diff
changeset | 232 | lemma istuple_access_update_snd_snd: | 
| 
7264824baf66
substantial simplification restores code generation
 haftmann parents: 
32799diff
changeset | 233 | "f o h g = j o f \<Longrightarrow> | 
| 
7264824baf66
substantial simplification restores code generation
 haftmann parents: 
32799diff
changeset | 234 | (f o istuple_snd isom) o (istuple_snd_update isom o h) g | 
| 
7264824baf66
substantial simplification restores code generation
 haftmann parents: 
32799diff
changeset | 235 | = j o (f o istuple_snd isom)" | 
| 
7264824baf66
substantial simplification restores code generation
 haftmann parents: 
32799diff
changeset | 236 | by (clarsimp simp: istuple_snd_update_def istuple_snd_def simps | 
| 
7264824baf66
substantial simplification restores code generation
 haftmann parents: 
32799diff
changeset | 237 | intro!: ext elim!: o_eq_elim) | 
| 
7264824baf66
substantial simplification restores code generation
 haftmann parents: 
32799diff
changeset | 238 | |
| 
7264824baf66
substantial simplification restores code generation
 haftmann parents: 
32799diff
changeset | 239 | lemma istuple_access_update_fst_snd: | 
| 
7264824baf66
substantial simplification restores code generation
 haftmann parents: 
32799diff
changeset | 240 | "(f o istuple_fst isom) o (istuple_snd_update isom o h) g | 
| 
7264824baf66
substantial simplification restores code generation
 haftmann parents: 
32799diff
changeset | 241 | = id o (f o istuple_fst isom)" | 
| 
7264824baf66
substantial simplification restores code generation
 haftmann parents: 
32799diff
changeset | 242 | by (clarsimp simp: istuple_snd_update_def istuple_fst_def simps | 
| 
7264824baf66
substantial simplification restores code generation
 haftmann parents: 
32799diff
changeset | 243 | intro!: ext elim!: o_eq_elim) | 
| 
7264824baf66
substantial simplification restores code generation
 haftmann parents: 
32799diff
changeset | 244 | |
| 
7264824baf66
substantial simplification restores code generation
 haftmann parents: 
32799diff
changeset | 245 | lemma istuple_access_update_snd_fst: | 
| 
7264824baf66
substantial simplification restores code generation
 haftmann parents: 
32799diff
changeset | 246 | "(f o istuple_snd isom) o (istuple_fst_update isom o h) g | 
| 
7264824baf66
substantial simplification restores code generation
 haftmann parents: 
32799diff
changeset | 247 | = id o (f o istuple_snd isom)" | 
| 
7264824baf66
substantial simplification restores code generation
 haftmann parents: 
32799diff
changeset | 248 | by (clarsimp simp: istuple_fst_update_def istuple_snd_def simps | 
| 
7264824baf66
substantial simplification restores code generation
 haftmann parents: 
32799diff
changeset | 249 | intro!: ext elim!: o_eq_elim) | 
| 
7264824baf66
substantial simplification restores code generation
 haftmann parents: 
32799diff
changeset | 250 | |
| 
7264824baf66
substantial simplification restores code generation
 haftmann parents: 
32799diff
changeset | 251 | lemma istuple_update_swap_fst_fst: | 
| 
7264824baf66
substantial simplification restores code generation
 haftmann parents: 
32799diff
changeset | 252 | "h f o j g = j g o h f \<Longrightarrow> | 
| 
7264824baf66
substantial simplification restores code generation
 haftmann parents: 
32799diff
changeset | 253 | (istuple_fst_update isom o h) f o (istuple_fst_update isom o j) g | 
| 
7264824baf66
substantial simplification restores code generation
 haftmann parents: 
32799diff
changeset | 254 | = (istuple_fst_update isom o j) g o (istuple_fst_update isom o h) f" | 
| 
7264824baf66
substantial simplification restores code generation
 haftmann parents: 
32799diff
changeset | 255 | by (clarsimp simp: istuple_fst_update_def simps apfst_compose intro!: ext) | 
| 
7264824baf66
substantial simplification restores code generation
 haftmann parents: 
32799diff
changeset | 256 | |
| 
7264824baf66
substantial simplification restores code generation
 haftmann parents: 
32799diff
changeset | 257 | lemma istuple_update_swap_snd_snd: | 
| 
7264824baf66
substantial simplification restores code generation
 haftmann parents: 
32799diff
changeset | 258 | "h f o j g = j g o h f \<Longrightarrow> | 
| 
7264824baf66
substantial simplification restores code generation
 haftmann parents: 
32799diff
changeset | 259 | (istuple_snd_update isom o h) f o (istuple_snd_update isom o j) g | 
| 
7264824baf66
substantial simplification restores code generation
 haftmann parents: 
32799diff
changeset | 260 | = (istuple_snd_update isom o j) g o (istuple_snd_update isom o h) f" | 
| 
7264824baf66
substantial simplification restores code generation
 haftmann parents: 
32799diff
changeset | 261 | by (clarsimp simp: istuple_snd_update_def simps apsnd_compose intro!: ext) | 
| 
7264824baf66
substantial simplification restores code generation
 haftmann parents: 
32799diff
changeset | 262 | |
| 
7264824baf66
substantial simplification restores code generation
 haftmann parents: 
32799diff
changeset | 263 | lemma istuple_update_swap_fst_snd: | 
| 
7264824baf66
substantial simplification restores code generation
 haftmann parents: 
32799diff
changeset | 264 | "(istuple_snd_update isom o h) f o (istuple_fst_update isom o j) g | 
| 
7264824baf66
substantial simplification restores code generation
 haftmann parents: 
32799diff
changeset | 265 | = (istuple_fst_update isom o j) g o (istuple_snd_update isom o h) f" | 
| 
7264824baf66
substantial simplification restores code generation
 haftmann parents: 
32799diff
changeset | 266 | by (clarsimp simp: istuple_fst_update_def istuple_snd_update_def simps intro!: ext) | 
| 
7264824baf66
substantial simplification restores code generation
 haftmann parents: 
32799diff
changeset | 267 | |
| 
7264824baf66
substantial simplification restores code generation
 haftmann parents: 
32799diff
changeset | 268 | lemma istuple_update_swap_snd_fst: | 
| 
7264824baf66
substantial simplification restores code generation
 haftmann parents: 
32799diff
changeset | 269 | "(istuple_fst_update isom o h) f o (istuple_snd_update isom o j) g | 
| 
7264824baf66
substantial simplification restores code generation
 haftmann parents: 
32799diff
changeset | 270 | = (istuple_snd_update isom o j) g o (istuple_fst_update isom o h) f" | 
| 
7264824baf66
substantial simplification restores code generation
 haftmann parents: 
32799diff
changeset | 271 | by (clarsimp simp: istuple_fst_update_def istuple_snd_update_def simps intro!: ext) | 
| 
7264824baf66
substantial simplification restores code generation
 haftmann parents: 
32799diff
changeset | 272 | |
| 
7264824baf66
substantial simplification restores code generation
 haftmann parents: 
32799diff
changeset | 273 | lemma istuple_update_compose_fst_fst: | 
| 
7264824baf66
substantial simplification restores code generation
 haftmann parents: 
32799diff
changeset | 274 | "h f o j g = k (f o g) \<Longrightarrow> | 
| 
7264824baf66
substantial simplification restores code generation
 haftmann parents: 
32799diff
changeset | 275 | (istuple_fst_update isom o h) f o (istuple_fst_update isom o j) g | 
| 
7264824baf66
substantial simplification restores code generation
 haftmann parents: 
32799diff
changeset | 276 | = (istuple_fst_update isom o k) (f o g)" | 
| 
7264824baf66
substantial simplification restores code generation
 haftmann parents: 
32799diff
changeset | 277 | by (clarsimp simp: istuple_fst_update_def simps apfst_compose intro!: ext) | 
| 
7264824baf66
substantial simplification restores code generation
 haftmann parents: 
32799diff
changeset | 278 | |
| 
7264824baf66
substantial simplification restores code generation
 haftmann parents: 
32799diff
changeset | 279 | lemma istuple_update_compose_snd_snd: | 
| 
7264824baf66
substantial simplification restores code generation
 haftmann parents: 
32799diff
changeset | 280 | "h f o j g = k (f o g) \<Longrightarrow> | 
| 
7264824baf66
substantial simplification restores code generation
 haftmann parents: 
32799diff
changeset | 281 | (istuple_snd_update isom o h) f o (istuple_snd_update isom o j) g | 
| 
7264824baf66
substantial simplification restores code generation
 haftmann parents: 
32799diff
changeset | 282 | = (istuple_snd_update isom o k) (f o g)" | 
| 
7264824baf66
substantial simplification restores code generation
 haftmann parents: 
32799diff
changeset | 283 | by (clarsimp simp: istuple_snd_update_def simps apsnd_compose intro!: ext) | 
| 
7264824baf66
substantial simplification restores code generation
 haftmann parents: 
32799diff
changeset | 284 | |
| 
7264824baf66
substantial simplification restores code generation
 haftmann parents: 
32799diff
changeset | 285 | lemma istuple_surjective_proof_assist_step: | 
| 
7264824baf66
substantial simplification restores code generation
 haftmann parents: 
32799diff
changeset | 286 | "istuple_surjective_proof_assist v a (istuple_fst isom o f) \<Longrightarrow> | 
| 
7264824baf66
substantial simplification restores code generation
 haftmann parents: 
32799diff
changeset | 287 | istuple_surjective_proof_assist v b (istuple_snd isom o f) | 
| 
7264824baf66
substantial simplification restores code generation
 haftmann parents: 
32799diff
changeset | 288 | \<Longrightarrow> istuple_surjective_proof_assist v (istuple_cons isom a b) f" | 
| 
7264824baf66
substantial simplification restores code generation
 haftmann parents: 
32799diff
changeset | 289 | by (clarsimp simp: istuple_surjective_proof_assist_def simps | 
| 
7264824baf66
substantial simplification restores code generation
 haftmann parents: 
32799diff
changeset | 290 | istuple_fst_def istuple_snd_def istuple_cons_def) | 
| 
7264824baf66
substantial simplification restores code generation
 haftmann parents: 
32799diff
changeset | 291 | |
| 
7264824baf66
substantial simplification restores code generation
 haftmann parents: 
32799diff
changeset | 292 | lemma istuple_fst_update_accessor_cong_assist: | 
| 
7264824baf66
substantial simplification restores code generation
 haftmann parents: 
32799diff
changeset | 293 | assumes "istuple_update_accessor_cong_assist f g" | 
| 
7264824baf66
substantial simplification restores code generation
 haftmann parents: 
32799diff
changeset | 294 | shows "istuple_update_accessor_cong_assist (istuple_fst_update isom o f) (g o istuple_fst isom)" | 
| 
7264824baf66
substantial simplification restores code generation
 haftmann parents: 
32799diff
changeset | 295 | proof - | 
| 
7264824baf66
substantial simplification restores code generation
 haftmann parents: 
32799diff
changeset | 296 | from assms have "f id = id" by (rule istuple_update_accessor_cong_assist_id) | 
| 
7264824baf66
substantial simplification restores code generation
 haftmann parents: 
32799diff
changeset | 297 | with assms show ?thesis by (clarsimp simp: istuple_update_accessor_cong_assist_def simps | 
| 
7264824baf66
substantial simplification restores code generation
 haftmann parents: 
32799diff
changeset | 298 | istuple_fst_update_def istuple_fst_def) | 
| 
7264824baf66
substantial simplification restores code generation
 haftmann parents: 
32799diff
changeset | 299 | qed | 
| 
7264824baf66
substantial simplification restores code generation
 haftmann parents: 
32799diff
changeset | 300 | |
| 
7264824baf66
substantial simplification restores code generation
 haftmann parents: 
32799diff
changeset | 301 | lemma istuple_snd_update_accessor_cong_assist: | 
| 
7264824baf66
substantial simplification restores code generation
 haftmann parents: 
32799diff
changeset | 302 | assumes "istuple_update_accessor_cong_assist f g" | 
| 
7264824baf66
substantial simplification restores code generation
 haftmann parents: 
32799diff
changeset | 303 | shows "istuple_update_accessor_cong_assist (istuple_snd_update isom o f) (g o istuple_snd isom)" | 
| 
7264824baf66
substantial simplification restores code generation
 haftmann parents: 
32799diff
changeset | 304 | proof - | 
| 
7264824baf66
substantial simplification restores code generation
 haftmann parents: 
32799diff
changeset | 305 | from assms have "f id = id" by (rule istuple_update_accessor_cong_assist_id) | 
| 
7264824baf66
substantial simplification restores code generation
 haftmann parents: 
32799diff
changeset | 306 | with assms show ?thesis by (clarsimp simp: istuple_update_accessor_cong_assist_def simps | 
| 
7264824baf66
substantial simplification restores code generation
 haftmann parents: 
32799diff
changeset | 307 | istuple_snd_update_def istuple_snd_def) | 
| 
7264824baf66
substantial simplification restores code generation
 haftmann parents: 
32799diff
changeset | 308 | qed | 
| 
7264824baf66
substantial simplification restores code generation
 haftmann parents: 
32799diff
changeset | 309 | |
| 
7264824baf66
substantial simplification restores code generation
 haftmann parents: 
32799diff
changeset | 310 | lemma istuple_fst_update_accessor_eq_assist: | 
| 
7264824baf66
substantial simplification restores code generation
 haftmann parents: 
32799diff
changeset | 311 | assumes "istuple_update_accessor_eq_assist f g a u a' v" | 
| 
7264824baf66
substantial simplification restores code generation
 haftmann parents: 
32799diff
changeset | 312 | shows "istuple_update_accessor_eq_assist (istuple_fst_update isom o f) (g o istuple_fst isom) | 
| 
7264824baf66
substantial simplification restores code generation
 haftmann parents: 
32799diff
changeset | 313 | (istuple_cons isom a b) u (istuple_cons isom a' b) v" | 
| 
7264824baf66
substantial simplification restores code generation
 haftmann parents: 
32799diff
changeset | 314 | proof - | 
| 
7264824baf66
substantial simplification restores code generation
 haftmann parents: 
32799diff
changeset | 315 | from assms have "f id = id" | 
| 
7264824baf66
substantial simplification restores code generation
 haftmann parents: 
32799diff
changeset | 316 | by (auto simp add: istuple_update_accessor_eq_assist_def intro: istuple_update_accessor_cong_assist_id) | 
| 
7264824baf66
substantial simplification restores code generation
 haftmann parents: 
32799diff
changeset | 317 | with assms show ?thesis by (clarsimp simp: istuple_update_accessor_eq_assist_def | 
| 
7264824baf66
substantial simplification restores code generation
 haftmann parents: 
32799diff
changeset | 318 | istuple_fst_update_def istuple_fst_def istuple_update_accessor_cong_assist_def istuple_cons_def simps) | 
| 
7264824baf66
substantial simplification restores code generation
 haftmann parents: 
32799diff
changeset | 319 | qed | 
| 
7264824baf66
substantial simplification restores code generation
 haftmann parents: 
32799diff
changeset | 320 | |
| 
7264824baf66
substantial simplification restores code generation
 haftmann parents: 
32799diff
changeset | 321 | lemma istuple_snd_update_accessor_eq_assist: | 
| 
7264824baf66
substantial simplification restores code generation
 haftmann parents: 
32799diff
changeset | 322 | assumes "istuple_update_accessor_eq_assist f g b u b' v" | 
| 
7264824baf66
substantial simplification restores code generation
 haftmann parents: 
32799diff
changeset | 323 | shows "istuple_update_accessor_eq_assist (istuple_snd_update isom o f) (g o istuple_snd isom) | 
| 
7264824baf66
substantial simplification restores code generation
 haftmann parents: 
32799diff
changeset | 324 | (istuple_cons isom a b) u (istuple_cons isom a b') v" | 
| 
7264824baf66
substantial simplification restores code generation
 haftmann parents: 
32799diff
changeset | 325 | proof - | 
| 
7264824baf66
substantial simplification restores code generation
 haftmann parents: 
32799diff
changeset | 326 | from assms have "f id = id" | 
| 
7264824baf66
substantial simplification restores code generation
 haftmann parents: 
32799diff
changeset | 327 | by (auto simp add: istuple_update_accessor_eq_assist_def intro: istuple_update_accessor_cong_assist_id) | 
| 
7264824baf66
substantial simplification restores code generation
 haftmann parents: 
32799diff
changeset | 328 | with assms show ?thesis by (clarsimp simp: istuple_update_accessor_eq_assist_def | 
| 
7264824baf66
substantial simplification restores code generation
 haftmann parents: 
32799diff
changeset | 329 | istuple_snd_update_def istuple_snd_def istuple_update_accessor_cong_assist_def istuple_cons_def simps) | 
| 
7264824baf66
substantial simplification restores code generation
 haftmann parents: 
32799diff
changeset | 330 | qed | 
| 
7264824baf66
substantial simplification restores code generation
 haftmann parents: 
32799diff
changeset | 331 | |
| 
7264824baf66
substantial simplification restores code generation
 haftmann parents: 
32799diff
changeset | 332 | lemma istuple_cons_conj_eqI: | 
| 
7264824baf66
substantial simplification restores code generation
 haftmann parents: 
32799diff
changeset | 333 | "a = c \<and> b = d \<and> P \<longleftrightarrow> Q \<Longrightarrow> | 
| 
7264824baf66
substantial simplification restores code generation
 haftmann parents: 
32799diff
changeset | 334 | istuple_cons isom a b = istuple_cons isom c d \<and> P \<longleftrightarrow> Q" | 
| 
7264824baf66
substantial simplification restores code generation
 haftmann parents: 
32799diff
changeset | 335 | by (clarsimp simp: istuple_cons_def simps) | 
| 
7264824baf66
substantial simplification restores code generation
 haftmann parents: 
32799diff
changeset | 336 | |
| 
7264824baf66
substantial simplification restores code generation
 haftmann parents: 
32799diff
changeset | 337 | lemmas intros = | 
| 
7264824baf66
substantial simplification restores code generation
 haftmann parents: 
32799diff
changeset | 338 | istuple_access_update_fst_fst | 
| 
7264824baf66
substantial simplification restores code generation
 haftmann parents: 
32799diff
changeset | 339 | istuple_access_update_snd_snd | 
| 
7264824baf66
substantial simplification restores code generation
 haftmann parents: 
32799diff
changeset | 340 | istuple_access_update_fst_snd | 
| 
7264824baf66
substantial simplification restores code generation
 haftmann parents: 
32799diff
changeset | 341 | istuple_access_update_snd_fst | 
| 
7264824baf66
substantial simplification restores code generation
 haftmann parents: 
32799diff
changeset | 342 | istuple_update_swap_fst_fst | 
| 
7264824baf66
substantial simplification restores code generation
 haftmann parents: 
32799diff
changeset | 343 | istuple_update_swap_snd_snd | 
| 
7264824baf66
substantial simplification restores code generation
 haftmann parents: 
32799diff
changeset | 344 | istuple_update_swap_fst_snd | 
| 
7264824baf66
substantial simplification restores code generation
 haftmann parents: 
32799diff
changeset | 345 | istuple_update_swap_snd_fst | 
| 
7264824baf66
substantial simplification restores code generation
 haftmann parents: 
32799diff
changeset | 346 | istuple_update_compose_fst_fst | 
| 
7264824baf66
substantial simplification restores code generation
 haftmann parents: 
32799diff
changeset | 347 | istuple_update_compose_snd_snd | 
| 
7264824baf66
substantial simplification restores code generation
 haftmann parents: 
32799diff
changeset | 348 | istuple_surjective_proof_assist_step | 
| 
7264824baf66
substantial simplification restores code generation
 haftmann parents: 
32799diff
changeset | 349 | istuple_fst_update_accessor_eq_assist | 
| 
7264824baf66
substantial simplification restores code generation
 haftmann parents: 
32799diff
changeset | 350 | istuple_snd_update_accessor_eq_assist | 
| 
7264824baf66
substantial simplification restores code generation
 haftmann parents: 
32799diff
changeset | 351 | istuple_fst_update_accessor_cong_assist | 
| 
7264824baf66
substantial simplification restores code generation
 haftmann parents: 
32799diff
changeset | 352 | istuple_snd_update_accessor_cong_assist | 
| 
7264824baf66
substantial simplification restores code generation
 haftmann parents: 
32799diff
changeset | 353 | istuple_cons_conj_eqI | 
| 
7264824baf66
substantial simplification restores code generation
 haftmann parents: 
32799diff
changeset | 354 | |
| 
7264824baf66
substantial simplification restores code generation
 haftmann parents: 
32799diff
changeset | 355 | end | 
| 
7264824baf66
substantial simplification restores code generation
 haftmann parents: 
32799diff
changeset | 356 | |
| 
7264824baf66
substantial simplification restores code generation
 haftmann parents: 
32799diff
changeset | 357 | lemma isomorphic_tuple_intro: | 
| 
7264824baf66
substantial simplification restores code generation
 haftmann parents: 
32799diff
changeset | 358 | fixes repr abst | 
| 
7264824baf66
substantial simplification restores code generation
 haftmann parents: 
32799diff
changeset | 359 | assumes repr_inj: "\<And>x y. repr x = repr y \<longleftrightarrow> x = y" | 
| 
7264824baf66
substantial simplification restores code generation
 haftmann parents: 
32799diff
changeset | 360 | and abst_inv: "\<And>z. repr (abst z) = z" | 
| 
7264824baf66
substantial simplification restores code generation
 haftmann parents: 
32799diff
changeset | 361 | assumes v: "v \<equiv> TupleIsomorphism repr abst" | 
| 
7264824baf66
substantial simplification restores code generation
 haftmann parents: 
32799diff
changeset | 362 | shows "isomorphic_tuple v" | 
| 
7264824baf66
substantial simplification restores code generation
 haftmann parents: 
32799diff
changeset | 363 | apply (rule isomorphic_tuple.intro) | 
| 
7264824baf66
substantial simplification restores code generation
 haftmann parents: 
32799diff
changeset | 364 | apply (simp_all add: abst_inv v) | 
| 
7264824baf66
substantial simplification restores code generation
 haftmann parents: 
32799diff
changeset | 365 | apply (cut_tac x="abst (repr x)" and y="x" in repr_inj) | 
| 
7264824baf66
substantial simplification restores code generation
 haftmann parents: 
32799diff
changeset | 366 | apply (simp add: abst_inv) | 
| 
7264824baf66
substantial simplification restores code generation
 haftmann parents: 
32799diff
changeset | 367 | done | 
| 
7264824baf66
substantial simplification restores code generation
 haftmann parents: 
32799diff
changeset | 368 | |
| 
7264824baf66
substantial simplification restores code generation
 haftmann parents: 
32799diff
changeset | 369 | definition | 
| 
7264824baf66
substantial simplification restores code generation
 haftmann parents: 
32799diff
changeset | 370 | "tuple_istuple \<equiv> TupleIsomorphism id id" | 
| 
7264824baf66
substantial simplification restores code generation
 haftmann parents: 
32799diff
changeset | 371 | |
| 
7264824baf66
substantial simplification restores code generation
 haftmann parents: 
32799diff
changeset | 372 | lemma tuple_istuple: | 
| 
7264824baf66
substantial simplification restores code generation
 haftmann parents: 
32799diff
changeset | 373 | "isomorphic_tuple tuple_istuple" | 
| 
7264824baf66
substantial simplification restores code generation
 haftmann parents: 
32799diff
changeset | 374 | by (simp add: isomorphic_tuple_intro [OF _ _ reflexive] tuple_istuple_def) | 
| 
7264824baf66
substantial simplification restores code generation
 haftmann parents: 
32799diff
changeset | 375 | |
| 
7264824baf66
substantial simplification restores code generation
 haftmann parents: 
32799diff
changeset | 376 | lemma refl_conj_eq: | 
| 
7264824baf66
substantial simplification restores code generation
 haftmann parents: 
32799diff
changeset | 377 | "Q = R \<Longrightarrow> P \<and> Q \<longleftrightarrow> P \<and> R" | 
| 
7264824baf66
substantial simplification restores code generation
 haftmann parents: 
32799diff
changeset | 378 | by simp | 
| 
7264824baf66
substantial simplification restores code generation
 haftmann parents: 
32799diff
changeset | 379 | |
| 
7264824baf66
substantial simplification restores code generation
 haftmann parents: 
32799diff
changeset | 380 | lemma istuple_UNIV_I: "x \<in> UNIV \<equiv> True" | 
| 
7264824baf66
substantial simplification restores code generation
 haftmann parents: 
32799diff
changeset | 381 | by simp | 
| 
7264824baf66
substantial simplification restores code generation
 haftmann parents: 
32799diff
changeset | 382 | |
| 
7264824baf66
substantial simplification restores code generation
 haftmann parents: 
32799diff
changeset | 383 | lemma istuple_True_simp: "(True \<Longrightarrow> PROP P) \<equiv> PROP P" | 
| 
7264824baf66
substantial simplification restores code generation
 haftmann parents: 
32799diff
changeset | 384 | by simp | 
| 
7264824baf66
substantial simplification restores code generation
 haftmann parents: 
32799diff
changeset | 385 | |
| 14700 
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
 schirmer parents: 
14080diff
changeset | 386 | lemma prop_subst: "s = t \<Longrightarrow> PROP P t \<Longrightarrow> PROP P s" | 
| 
2f885b7e5ba7
reimplementation of HOL records; only one type is created for
 schirmer parents: 
14080diff
changeset | 387 | by simp | 
| 11826 | 388 | |
| 25705 | 389 | lemma K_record_comp: "(\<lambda>x. c) \<circ> f = (\<lambda>x. c)" | 
| 390 | by (simp add: comp_def) | |
| 11821 | 391 | |
| 32743 
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
 tsewell@rubicon.NSW.bigpond.net.au parents: 
31723diff
changeset | 392 | lemma o_eq_dest_lhs: | 
| 
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
 tsewell@rubicon.NSW.bigpond.net.au parents: 
31723diff
changeset | 393 | "a o b = c \<Longrightarrow> a (b v) = c v" | 
| 
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
 tsewell@rubicon.NSW.bigpond.net.au parents: 
31723diff
changeset | 394 | by clarsimp | 
| 
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
 tsewell@rubicon.NSW.bigpond.net.au parents: 
31723diff
changeset | 395 | |
| 
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
 tsewell@rubicon.NSW.bigpond.net.au parents: 
31723diff
changeset | 396 | lemma o_eq_id_dest: | 
| 
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
 tsewell@rubicon.NSW.bigpond.net.au parents: 
31723diff
changeset | 397 | "a o b = id o c \<Longrightarrow> a (b v) = c v" | 
| 
c4e9a48bc50e
Initial attempt at porting record update to repository Isabelle.
 tsewell@rubicon.NSW.bigpond.net.au parents: 
31723diff
changeset | 398 | by clarsimp | 
| 22817 | 399 | |
| 33595 
7264824baf66
substantial simplification restores code generation
 haftmann parents: 
32799diff
changeset | 400 | |
| 11833 | 401 | subsection {* Concrete record syntax *}
 | 
| 4870 
cc36acb5b114
Extensible records with structural subtyping in HOL.  See
 wenzelm parents: diff
changeset | 402 | |
| 
cc36acb5b114
Extensible records with structural subtyping in HOL.  See
 wenzelm parents: diff
changeset | 403 | nonterminals | 
| 5198 | 404 | ident field_type field_types field fields update updates | 
| 4870 
cc36acb5b114
Extensible records with structural subtyping in HOL.  See
 wenzelm parents: diff
changeset | 405 | syntax | 
| 11821 | 406 |   "_constify"           :: "id => ident"                        ("_")
 | 
| 407 |   "_constify"           :: "longid => ident"                    ("_")
 | |
| 5198 | 408 | |
| 11821 | 409 |   "_field_type"         :: "[ident, type] => field_type"        ("(2_ ::/ _)")
 | 
| 410 |   ""                    :: "field_type => field_types"          ("_")
 | |
| 411 |   "_field_types"        :: "[field_type, field_types] => field_types"    ("_,/ _")
 | |
| 412 |   "_record_type"        :: "field_types => type"                ("(3'(| _ |'))")
 | |
| 10093 | 413 |   "_record_type_scheme" :: "[field_types, type] => type"        ("(3'(| _,/ (2... ::/ _) |'))")
 | 
| 5198 | 414 | |
| 11821 | 415 |   "_field"              :: "[ident, 'a] => field"               ("(2_ =/ _)")
 | 
| 416 |   ""                    :: "field => fields"                    ("_")
 | |
| 417 |   "_fields"             :: "[field, fields] => fields"          ("_,/ _")
 | |
| 418 |   "_record"             :: "fields => 'a"                       ("(3'(| _ |'))")
 | |
| 10093 | 419 |   "_record_scheme"      :: "[fields, 'a] => 'a"                 ("(3'(| _,/ (2... =/ _) |'))")
 | 
| 5198 | 420 | |
| 10641 | 421 | "_update_name" :: idt | 
| 11821 | 422 |   "_update"             :: "[ident, 'a] => update"              ("(2_ :=/ _)")
 | 
| 423 |   ""                    :: "update => updates"                  ("_")
 | |
| 424 |   "_updates"            :: "[update, updates] => updates"       ("_,/ _")
 | |
| 10093 | 425 |   "_record_update"      :: "['a, updates] => 'b"                ("_/(3'(| _ |'))" [900,0] 900)
 | 
| 4870 
cc36acb5b114
Extensible records with structural subtyping in HOL.  See
 wenzelm parents: diff
changeset | 426 | |
| 10331 | 427 | syntax (xsymbols) | 
| 11821 | 428 |   "_record_type"        :: "field_types => type"                ("(3\<lparr>_\<rparr>)")
 | 
| 10093 | 429 |   "_record_type_scheme" :: "[field_types, type] => type"        ("(3\<lparr>_,/ (2\<dots> ::/ _)\<rparr>)")
 | 
| 430 |   "_record"             :: "fields => 'a"                               ("(3\<lparr>_\<rparr>)")
 | |
| 431 |   "_record_scheme"      :: "[fields, 'a] => 'a"                 ("(3\<lparr>_,/ (2\<dots> =/ _)\<rparr>)")
 | |
| 432 |   "_record_update"      :: "['a, updates] => 'b"                ("_/(3\<lparr>_\<rparr>)" [900,0] 900)
 | |
| 9729 | 433 | |
| 32752 
f65d74a264dd
Initial response to feedback from Norbert, Makarius on record patch
 tsewell@rubicon.NSW.bigpond.net.au parents: 
32745diff
changeset | 434 | |
| 33595 
7264824baf66
substantial simplification restores code generation
 haftmann parents: 
32799diff
changeset | 435 | subsection {* Record package *}
 | 
| 32752 
f65d74a264dd
Initial response to feedback from Norbert, Makarius on record patch
 tsewell@rubicon.NSW.bigpond.net.au parents: 
32745diff
changeset | 436 | |
| 32744 
50406c4951d9
Record patch imported and working.
 Thomas Sewell <tsewell@nicta.com.au> parents: 
32743diff
changeset | 437 | use "Tools/record.ML" | 
| 
50406c4951d9
Record patch imported and working.
 Thomas Sewell <tsewell@nicta.com.au> parents: 
32743diff
changeset | 438 | setup Record.setup | 
| 10641 | 439 | |
| 33595 
7264824baf66
substantial simplification restores code generation
 haftmann parents: 
32799diff
changeset | 440 | hide (open) const TupleIsomorphism repr abst istuple_fst istuple_snd | 
| 
7264824baf66
substantial simplification restores code generation
 haftmann parents: 
32799diff
changeset | 441 | istuple_fst_update istuple_snd_update istuple_cons | 
| 
7264824baf66
substantial simplification restores code generation
 haftmann parents: 
32799diff
changeset | 442 | istuple_surjective_proof_assist istuple_update_accessor_cong_assist | 
| 
7264824baf66
substantial simplification restores code generation
 haftmann parents: 
32799diff
changeset | 443 | istuple_update_accessor_eq_assist tuple_istuple | 
| 
7264824baf66
substantial simplification restores code generation
 haftmann parents: 
32799diff
changeset | 444 | |
| 4870 
cc36acb5b114
Extensible records with structural subtyping in HOL.  See
 wenzelm parents: diff
changeset | 445 | end |