1930 |
1930 |
1931 |
1931 |
1932 subsubsection{* Semi-Lattices *} |
1932 subsubsection{* Semi-Lattices *} |
1933 |
1933 |
1934 locale ACIfSL = ACIf + |
1934 locale ACIfSL = ACIf + |
1935 fixes below :: "'a \<Rightarrow> 'a \<Rightarrow> bool" (infixl "\<preceq>" 50) |
1935 fixes below :: "'a \<Rightarrow> 'a \<Rightarrow> bool" (infixl "\<sqsubseteq>" 50) |
1936 assumes below_def: "x \<preceq> y = (x\<cdot>y = x)" |
1936 assumes below_def: "(x \<sqsubseteq> y) = (x\<cdot>y = x)" |
1937 |
1937 |
1938 locale ACIfSLlin = ACIfSL + |
1938 locale ACIfSLlin = ACIfSL + |
1939 assumes lin: "x\<cdot>y \<in> {x,y}" |
1939 assumes lin: "x\<cdot>y \<in> {x,y}" |
1940 |
1940 |
1941 lemma (in ACIfSL) below_refl[simp]: "x \<preceq> x" |
1941 lemma (in ACIfSL) below_refl[simp]: "x \<sqsubseteq> x" |
1942 by(simp add: below_def idem) |
1942 by(simp add: below_def idem) |
1943 |
1943 |
1944 lemma (in ACIfSL) below_f_conv[simp]: "x \<preceq> y \<cdot> z = (x \<preceq> y \<and> x \<preceq> z)" |
1944 lemma (in ACIfSL) below_f_conv[simp]: "x \<sqsubseteq> y \<cdot> z = (x \<sqsubseteq> y \<and> x \<sqsubseteq> z)" |
1945 proof |
1945 proof |
1946 assume "x \<preceq> y \<cdot> z" |
1946 assume "x \<sqsubseteq> y \<cdot> z" |
1947 hence xyzx: "x \<cdot> (y \<cdot> z) = x" by(simp add: below_def) |
1947 hence xyzx: "x \<cdot> (y \<cdot> z) = x" by(simp add: below_def) |
1948 have "x \<cdot> y = x" |
1948 have "x \<cdot> y = x" |
1949 proof - |
1949 proof - |
1950 have "x \<cdot> y = (x \<cdot> (y \<cdot> z)) \<cdot> y" by(rule subst[OF xyzx], rule refl) |
1950 have "x \<cdot> y = (x \<cdot> (y \<cdot> z)) \<cdot> y" by(rule subst[OF xyzx], rule refl) |
1951 also have "\<dots> = x \<cdot> (y \<cdot> z)" by(simp add:ACI) |
1951 also have "\<dots> = x \<cdot> (y \<cdot> z)" by(simp add:ACI) |
1957 have "x \<cdot> z = (x \<cdot> (y \<cdot> z)) \<cdot> z" by(rule subst[OF xyzx], rule refl) |
1957 have "x \<cdot> z = (x \<cdot> (y \<cdot> z)) \<cdot> z" by(rule subst[OF xyzx], rule refl) |
1958 also have "\<dots> = x \<cdot> (y \<cdot> z)" by(simp add:ACI) |
1958 also have "\<dots> = x \<cdot> (y \<cdot> z)" by(simp add:ACI) |
1959 also have "\<dots> = x" by(rule xyzx) |
1959 also have "\<dots> = x" by(rule xyzx) |
1960 finally show ?thesis . |
1960 finally show ?thesis . |
1961 qed |
1961 qed |
1962 ultimately show "x \<preceq> y \<and> x \<preceq> z" by(simp add: below_def) |
1962 ultimately show "x \<sqsubseteq> y \<and> x \<sqsubseteq> z" by(simp add: below_def) |
1963 next |
1963 next |
1964 assume a: "x \<preceq> y \<and> x \<preceq> z" |
1964 assume a: "x \<sqsubseteq> y \<and> x \<sqsubseteq> z" |
1965 hence y: "x \<cdot> y = x" and z: "x \<cdot> z = x" by(simp_all add: below_def) |
1965 hence y: "x \<cdot> y = x" and z: "x \<cdot> z = x" by(simp_all add: below_def) |
1966 have "x \<cdot> (y \<cdot> z) = (x \<cdot> y) \<cdot> z" by(simp add:assoc) |
1966 have "x \<cdot> (y \<cdot> z) = (x \<cdot> y) \<cdot> z" by(simp add:assoc) |
1967 also have "x \<cdot> y = x" using a by(simp_all add: below_def) |
1967 also have "x \<cdot> y = x" using a by(simp_all add: below_def) |
1968 also have "x \<cdot> z = x" using a by(simp_all add: below_def) |
1968 also have "x \<cdot> z = x" using a by(simp_all add: below_def) |
1969 finally show "x \<preceq> y \<cdot> z" by(simp_all add: below_def) |
1969 finally show "x \<sqsubseteq> y \<cdot> z" by(simp_all add: below_def) |
1970 qed |
1970 qed |
1971 |
1971 |
1972 lemma (in ACIfSLlin) above_f_conv: |
1972 lemma (in ACIfSLlin) above_f_conv: |
1973 "x \<cdot> y \<preceq> z = (x \<preceq> z \<or> y \<preceq> z)" |
1973 "x \<cdot> y \<sqsubseteq> z = (x \<sqsubseteq> z \<or> y \<sqsubseteq> z)" |
1974 proof |
1974 proof |
1975 assume a: "x \<cdot> y \<preceq> z" |
1975 assume a: "x \<cdot> y \<sqsubseteq> z" |
1976 have "x \<cdot> y = x \<or> x \<cdot> y = y" using lin[of x y] by simp |
1976 have "x \<cdot> y = x \<or> x \<cdot> y = y" using lin[of x y] by simp |
1977 thus "x \<preceq> z \<or> y \<preceq> z" |
1977 thus "x \<sqsubseteq> z \<or> y \<sqsubseteq> z" |
1978 proof |
1978 proof |
1979 assume "x \<cdot> y = x" hence "x \<preceq> z" by(rule subst)(rule a) thus ?thesis .. |
1979 assume "x \<cdot> y = x" hence "x \<sqsubseteq> z" by(rule subst)(rule a) thus ?thesis .. |
1980 next |
1980 next |
1981 assume "x \<cdot> y = y" hence "y \<preceq> z" by(rule subst)(rule a) thus ?thesis .. |
1981 assume "x \<cdot> y = y" hence "y \<sqsubseteq> z" by(rule subst)(rule a) thus ?thesis .. |
1982 qed |
1982 qed |
1983 next |
1983 next |
1984 assume "x \<preceq> z \<or> y \<preceq> z" |
1984 assume "x \<sqsubseteq> z \<or> y \<sqsubseteq> z" |
1985 thus "x \<cdot> y \<preceq> z" |
1985 thus "x \<cdot> y \<sqsubseteq> z" |
1986 proof |
1986 proof |
1987 assume a: "x \<preceq> z" |
1987 assume a: "x \<sqsubseteq> z" |
1988 have "(x \<cdot> y) \<cdot> z = (x \<cdot> z) \<cdot> y" by(simp add:ACI) |
1988 have "(x \<cdot> y) \<cdot> z = (x \<cdot> z) \<cdot> y" by(simp add:ACI) |
1989 also have "x \<cdot> z = x" using a by(simp add:below_def) |
1989 also have "x \<cdot> z = x" using a by(simp add:below_def) |
1990 finally show "x \<cdot> y \<preceq> z" by(simp add:below_def) |
1990 finally show "x \<cdot> y \<sqsubseteq> z" by(simp add:below_def) |
1991 next |
1991 next |
1992 assume a: "y \<preceq> z" |
1992 assume a: "y \<sqsubseteq> z" |
1993 have "(x \<cdot> y) \<cdot> z = x \<cdot> (y \<cdot> z)" by(simp add:ACI) |
1993 have "(x \<cdot> y) \<cdot> z = x \<cdot> (y \<cdot> z)" by(simp add:ACI) |
1994 also have "y \<cdot> z = y" using a by(simp add:below_def) |
1994 also have "y \<cdot> z = y" using a by(simp add:below_def) |
1995 finally show "x \<cdot> y \<preceq> z" by(simp add:below_def) |
1995 finally show "x \<cdot> y \<sqsubseteq> z" by(simp add:below_def) |
1996 qed |
1996 qed |
1997 qed |
1997 qed |
1998 |
1998 |
1999 |
1999 |
2000 subsubsection{* Lemmas about {@text fold1} *} |
2000 subsubsection{* Lemmas about {@text fold1} *} |
2062 qed |
2062 qed |
2063 qed |
2063 qed |
2064 |
2064 |
2065 lemma (in ACIfSLlin) fold1_below_iff: |
2065 lemma (in ACIfSLlin) fold1_below_iff: |
2066 assumes A: "finite A" "A \<noteq> {}" |
2066 assumes A: "finite A" "A \<noteq> {}" |
2067 shows "fold1 f A \<preceq> x = (\<exists>a\<in>A. a \<preceq> x)" |
2067 shows "fold1 f A \<sqsubseteq> x = (\<exists>a\<in>A. a \<sqsubseteq> x)" |
2068 using A |
2068 using A |
2069 by(induct rule:finite_ne_induct)(simp_all add:above_f_conv) |
2069 by(induct rule:finite_ne_induct)(simp_all add:above_f_conv) |
|
2070 |
|
2071 subsubsection{* Lattices *} |
|
2072 |
|
2073 locale Lattice = |
|
2074 fixes below :: "'a \<Rightarrow> 'a \<Rightarrow> bool" (infixl "\<sqsubseteq>" 50) |
|
2075 and inf :: "'a \<Rightarrow> 'a \<Rightarrow> 'a" (infixl "\<sqinter>" 70) |
|
2076 and sup :: "'a \<Rightarrow> 'a \<Rightarrow> 'a" (infixl "\<squnion>" 65) |
|
2077 and Inf :: "'a set \<Rightarrow> 'a" ("\<Sqinter>_" [900] 900) |
|
2078 and Sup :: "'a set \<Rightarrow> 'a" ("\<Squnion>_" [900] 900) |
|
2079 assumes refl: "x \<sqsubseteq> x" |
|
2080 and trans: "x \<sqsubseteq> y \<Longrightarrow> y \<sqsubseteq> z \<Longrightarrow> x \<sqsubseteq> z" |
|
2081 and antisym: "x \<sqsubseteq> y \<Longrightarrow> y \<sqsubseteq> x \<Longrightarrow> x = y" |
|
2082 and inf_le1: "x \<sqinter> y \<sqsubseteq> x" and inf_le2: "x \<sqinter> y \<sqsubseteq> y" |
|
2083 and inf_least: "x \<sqsubseteq> y \<Longrightarrow> x \<sqsubseteq> z \<Longrightarrow> x \<sqsubseteq> y \<sqinter> z" |
|
2084 and sup_ge1: "x \<sqsubseteq> x \<squnion> y" and sup_ge2: "y \<sqsubseteq> x \<squnion> y" |
|
2085 and sup_greatest: "y \<sqsubseteq> x \<Longrightarrow> z \<sqsubseteq> x \<Longrightarrow> y \<squnion> z \<sqsubseteq> x" |
|
2086 (* FIXME *) |
|
2087 and sup_inf_distrib1: "x \<squnion> y \<sqinter> z = (x \<squnion> y) \<sqinter> (x \<squnion> z)" |
|
2088 and sup_inf_distrib2: "x \<sqinter> y \<squnion> z = (x \<squnion> z) \<sqinter> (y \<squnion> z)" |
|
2089 defines "Inf == fold1 inf" and "Sup == fold1 sup" |
|
2090 |
|
2091 |
|
2092 lemma (in Lattice) inf_comm: "(x \<sqinter> y) = (y \<sqinter> x)" |
|
2093 by(blast intro: antisym inf_le1 inf_le2 inf_least) |
|
2094 |
|
2095 lemma (in Lattice) sup_comm: "(x \<squnion> y) = (y \<squnion> x)" |
|
2096 by(blast intro: antisym sup_ge1 sup_ge2 sup_greatest) |
|
2097 |
|
2098 lemma (in Lattice) inf_assoc: "(x \<sqinter> y) \<sqinter> z = x \<sqinter> (y \<sqinter> z)" |
|
2099 by(blast intro: antisym inf_le1 inf_le2 inf_least trans) |
|
2100 |
|
2101 lemma (in Lattice) sup_assoc: "(x \<squnion> y) \<squnion> z = x \<squnion> (y \<squnion> z)" |
|
2102 by(blast intro!: antisym sup_ge1 sup_ge2 intro: sup_greatest trans) |
|
2103 |
|
2104 lemma (in Lattice) inf_idem: "x \<sqinter> x = x" |
|
2105 by(blast intro: antisym inf_le1 inf_le2 inf_least refl) |
|
2106 |
|
2107 lemma (in Lattice) sup_idem: "x \<squnion> x = x" |
|
2108 by(blast intro: antisym sup_ge1 sup_ge2 sup_greatest refl) |
|
2109 |
|
2110 text{* Lattices are semilattices *} |
|
2111 |
|
2112 lemma (in Lattice) ACf_inf: "ACf inf" |
|
2113 by(blast intro: ACf.intro inf_comm inf_assoc) |
|
2114 |
|
2115 lemma (in Lattice) ACf_sup: "ACf sup" |
|
2116 by(blast intro: ACf.intro sup_comm sup_assoc) |
|
2117 |
|
2118 lemma (in Lattice) ACIf_inf: "ACIf inf" |
|
2119 apply(rule ACIf.intro) |
|
2120 apply(rule ACf_inf) |
|
2121 apply(rule ACIf_axioms.intro) |
|
2122 apply(rule inf_idem) |
|
2123 done |
|
2124 |
|
2125 lemma (in Lattice) ACIf_sup: "ACIf sup" |
|
2126 apply(rule ACIf.intro) |
|
2127 apply(rule ACf_sup) |
|
2128 apply(rule ACIf_axioms.intro) |
|
2129 apply(rule sup_idem) |
|
2130 done |
|
2131 |
|
2132 lemma (in Lattice) ACIfSL_inf: "ACIfSL inf (op \<sqsubseteq>)" |
|
2133 apply(rule ACIfSL.intro) |
|
2134 apply(rule ACf_inf) |
|
2135 apply(rule ACIf.axioms[OF ACIf_inf]) |
|
2136 apply(rule ACIfSL_axioms.intro) |
|
2137 apply(rule iffI) |
|
2138 apply(blast intro: antisym inf_le1 inf_le2 inf_least refl) |
|
2139 apply(erule subst) |
|
2140 apply(rule inf_le2) |
|
2141 done |
|
2142 |
|
2143 lemma (in Lattice) ACIfSL_sup: "ACIfSL sup (%x y. y \<sqsubseteq> x)" |
|
2144 apply(rule ACIfSL.intro) |
|
2145 apply(rule ACf_sup) |
|
2146 apply(rule ACIf.axioms[OF ACIf_sup]) |
|
2147 apply(rule ACIfSL_axioms.intro) |
|
2148 apply(rule iffI) |
|
2149 apply(blast intro: antisym sup_ge1 sup_ge2 sup_greatest refl) |
|
2150 apply(erule subst) |
|
2151 apply(rule sup_ge2) |
|
2152 done |
|
2153 |
|
2154 text{* Fold laws in lattices *} |
|
2155 |
|
2156 lemma (in Lattice) Inf_le_Sup: "\<lbrakk> finite A; A \<noteq> {} \<rbrakk> \<Longrightarrow> \<Sqinter>A \<sqsubseteq> \<Squnion>A" |
|
2157 apply(unfold Sup_def Inf_def) |
|
2158 apply(subgoal_tac "EX a. a:A") |
|
2159 prefer 2 apply blast |
|
2160 apply(erule exE) |
|
2161 apply(rule trans) |
|
2162 apply(erule (2) ACIfSL.fold1_belowI[OF ACIfSL_inf]) |
|
2163 apply(erule (2) ACIfSL.fold1_belowI[OF ACIfSL_sup]) |
|
2164 done |
|
2165 |
|
2166 lemma (in Lattice) sup_Inf1_distrib: |
|
2167 assumes A: "finite A" "A \<noteq> {}" |
|
2168 shows "(x \<squnion> \<Sqinter>A) = \<Sqinter>{x \<squnion> a|a. a \<in> A}" |
|
2169 using A |
|
2170 proof (induct rule: finite_ne_induct) |
|
2171 case singleton thus ?case by(simp add:Inf_def) |
|
2172 next |
|
2173 case (insert y A) |
|
2174 have fin: "finite {x \<squnion> a |a. a \<in> A}" |
|
2175 by(fast intro: finite_surj[where f = "%a. x \<squnion> a", OF insert(0)]) |
|
2176 have "x \<squnion> \<Sqinter> (insert y A) = x \<squnion> (y \<sqinter> \<Sqinter> A)" |
|
2177 using insert by(simp add:ACf.fold1_insert_def[OF ACf_inf Inf_def]) |
|
2178 also have "\<dots> = (x \<squnion> y) \<sqinter> (x \<squnion> \<Sqinter> A)" by(rule sup_inf_distrib1) |
|
2179 also have "x \<squnion> \<Sqinter> A = \<Sqinter>{x \<squnion> a|a. a \<in> A}" using insert by simp |
|
2180 also have "(x \<squnion> y) \<sqinter> \<dots> = \<Sqinter> (insert (x \<squnion> y) {x \<squnion> a |a. a \<in> A})" |
|
2181 using insert by(simp add:ACIf.fold1_insert2_def[OF ACIf_inf Inf_def fin]) |
|
2182 also have "insert (x\<squnion>y) {x\<squnion>a |a. a \<in> A} = {x\<squnion>a |a. a \<in> insert y A}" |
|
2183 by blast |
|
2184 finally show ?case . |
|
2185 qed |
|
2186 |
|
2187 |
|
2188 lemma (in Lattice) sup_Inf2_distrib: |
|
2189 assumes A: "finite A" "A \<noteq> {}" and B: "finite B" "B \<noteq> {}" |
|
2190 shows "(\<Sqinter>A \<squnion> \<Sqinter>B) = \<Sqinter>{a \<squnion> b|a b. a \<in> A \<and> b \<in> B}" |
|
2191 using A |
|
2192 proof (induct rule: finite_ne_induct) |
|
2193 case singleton thus ?case |
|
2194 by(simp add: sup_Inf1_distrib[OF B] fold1_singleton_def[OF Inf_def]) |
|
2195 next |
|
2196 case (insert x A) |
|
2197 have finB: "finite {x \<squnion> b |b. b \<in> B}" |
|
2198 by(fast intro: finite_surj[where f = "%b. x \<squnion> b", OF B(0)]) |
|
2199 have finAB: "finite {a \<squnion> b |a b. a \<in> A \<and> b \<in> B}" |
|
2200 proof - |
|
2201 have "{a \<squnion> b |a b. a \<in> A \<and> b \<in> B} = (UN a:A. UN b:B. {a \<squnion> b})" |
|
2202 by blast |
|
2203 thus ?thesis by(simp add: insert(0) B(0)) |
|
2204 qed |
|
2205 have ne: "{a \<squnion> b |a b. a \<in> A \<and> b \<in> B} \<noteq> {}" using insert B by blast |
|
2206 have "\<Sqinter>(insert x A) \<squnion> \<Sqinter>B = (x \<sqinter> \<Sqinter>A) \<squnion> \<Sqinter>B" |
|
2207 using insert by(simp add:ACIf.fold1_insert2_def[OF ACIf_inf Inf_def]) |
|
2208 also have "\<dots> = (x \<squnion> \<Sqinter>B) \<sqinter> (\<Sqinter>A \<squnion> \<Sqinter>B)" by(rule sup_inf_distrib2) |
|
2209 also have "\<dots> = \<Sqinter>{x \<squnion> b|b. b \<in> B} \<sqinter> \<Sqinter>{a \<squnion> b|a b. a \<in> A \<and> b \<in> B}" |
|
2210 using insert by(simp add:sup_Inf1_distrib[OF B]) |
|
2211 also have "\<dots> = \<Sqinter>({x\<squnion>b |b. b \<in> B} \<union> {a\<squnion>b |a b. a \<in> A \<and> b \<in> B})" |
|
2212 (is "_ = \<Sqinter>?M") |
|
2213 using B insert |
|
2214 by(simp add:Inf_def ACIf.fold1_Un2[OF ACIf_inf finB _ finAB ne]) |
|
2215 also have "?M = {a \<squnion> b |a b. a \<in> insert x A \<and> b \<in> B}" |
|
2216 by blast |
|
2217 finally show ?case . |
|
2218 qed |
|
2219 |
2070 |
2220 |
2071 |
2221 |
2072 subsection{*Min and Max*} |
2222 subsection{*Min and Max*} |
2073 |
2223 |
2074 text{* As an application of @{text fold1} we define the minimal and |
2224 text{* As an application of @{text fold1} we define the minimal and |
2139 apply(rule ACIfSL.axioms[OF ACIfSL_max]) |
2289 apply(rule ACIfSL.axioms[OF ACIfSL_max]) |
2140 apply(rule ACIfSLlin_axioms.intro) |
2290 apply(rule ACIfSLlin_axioms.intro) |
2141 apply(auto simp:max_def) |
2291 apply(auto simp:max_def) |
2142 done |
2292 done |
2143 |
2293 |
|
2294 lemma Lattice_min_max: "Lattice (op \<le>) (min :: 'a::linorder \<Rightarrow> 'a \<Rightarrow> 'a) max" |
|
2295 apply(rule Lattice.intro) |
|
2296 apply simp |
|
2297 apply(erule (1) order_trans) |
|
2298 apply(erule (1) order_antisym) |
|
2299 apply(simp add:min_def max_def linorder_not_le order_less_imp_le) |
|
2300 apply(simp add:min_def max_def linorder_not_le order_less_imp_le) |
|
2301 apply(simp add:min_def max_def linorder_not_le order_less_imp_le) |
|
2302 apply(simp add:min_def max_def linorder_not_le order_less_imp_le) |
|
2303 apply(simp add:min_def max_def linorder_not_le order_less_imp_le) |
|
2304 apply(simp add:min_def max_def linorder_not_le order_less_imp_le) |
|
2305 apply(rule_tac x=x and y=y in linorder_le_cases) |
|
2306 apply(rule_tac x=x and y=z in linorder_le_cases) |
|
2307 apply(rule_tac x=y and y=z in linorder_le_cases) |
|
2308 apply(simp add:min_def max_def) |
|
2309 apply(simp add:min_def max_def) |
|
2310 apply(rule_tac x=y and y=z in linorder_le_cases) |
|
2311 apply(simp add:min_def max_def) |
|
2312 apply(simp add:min_def max_def) |
|
2313 apply(rule_tac x=x and y=z in linorder_le_cases) |
|
2314 apply(rule_tac x=y and y=z in linorder_le_cases) |
|
2315 apply(simp add:min_def max_def) |
|
2316 apply(simp add:min_def max_def) |
|
2317 apply(rule_tac x=y and y=z in linorder_le_cases) |
|
2318 apply(simp add:min_def max_def) |
|
2319 apply(simp add:min_def max_def) |
|
2320 |
|
2321 apply(rule_tac x=x and y=y in linorder_le_cases) |
|
2322 apply(rule_tac x=x and y=z in linorder_le_cases) |
|
2323 apply(rule_tac x=y and y=z in linorder_le_cases) |
|
2324 apply(simp add:min_def max_def) |
|
2325 apply(simp add:min_def max_def) |
|
2326 apply(rule_tac x=y and y=z in linorder_le_cases) |
|
2327 apply(simp add:min_def max_def) |
|
2328 apply(simp add:min_def max_def) |
|
2329 apply(rule_tac x=x and y=z in linorder_le_cases) |
|
2330 apply(rule_tac x=y and y=z in linorder_le_cases) |
|
2331 apply(simp add:min_def max_def) |
|
2332 apply(simp add:min_def max_def) |
|
2333 apply(rule_tac x=y and y=z in linorder_le_cases) |
|
2334 apply(simp add:min_def max_def) |
|
2335 apply(simp add:min_def max_def) |
|
2336 done |
|
2337 |
2144 text{* Now we instantiate the recursion equations and declare them |
2338 text{* Now we instantiate the recursion equations and declare them |
2145 simplification rules: *} |
2339 simplification rules: *} |
2146 |
2340 |
2147 declare |
2341 declare |
2148 fold1_singleton_def[OF Min_def, simp] |
2342 fold1_singleton_def[OF Min_def, simp] |