Datasets:
AI4M
/

text
stringlengths
0
3.34M
a : Monad m => (Unit -> Unit) -> m $ Maybe () f : Monad m => m () f = do Just _ <- a id | Nothing => pure () Just _ <- a id | Nothing => pure () Just _ <- a $ \() => () | Nothing => pure () Just _ <- a $ \() => () | Nothing => pure () pure ()
lemma Re_sgn [simp]: "Re(sgn z) = Re(z)/cmod z"
(* Title: Category theory using Isar and Locales Author: Greg O'Keefe, June, July, August 2003 License: LGPL Define homfunctors, prove that they are functors. *) section HomFunctors theory HomFunctors imports SetCat Functors begin locale into_set = two_cats AA BB for AA :: "('o,'a,'m)category_scheme" (structure) and BB (structure) + fixes U and Set defines "U \<equiv> (UNIV::'a set)" defines "Set \<equiv> set_cat U" assumes BB_Set: "BB = Set" fixes homf ("Hom'(_,'_')") defines "homf A \<equiv> \<lparr> om = (\<lambda>B\<in>Ob. Hom A B), am = (\<lambda>f\<in>Ar. \<lparr>set_dom=Hom A (Dom f),set_func=(\<lambda>g\<in>Hom A (Dom f). f \<bullet> g),set_cod=Hom A (Cod f)\<rparr>) \<rparr>" lemma (in into_set) homf_preserves_objects: "Hom(A,_)\<^bsub>\<o>\<^esub> : Ob \<rightarrow> ob Set" proof (rule funcsetI) fix B assume B: "B \<in> Ob" have "Hom(A,_)\<^bsub>\<o>\<^esub> B = Hom A B" using B by (simp add: homf_def) moreover have "\<dots> \<in> ob Set" by (simp add: U_def Set_def set_cat_def) ultimately show "Hom(A,_)\<^bsub>\<o>\<^esub> B \<in> ob Set" by simp qed lemma (in into_set) homf_preserves_dom: assumes f: "f \<in> Ar" shows "Hom(A,_)\<^bsub>\<o>\<^esub> (Dom f) = dom Set (Hom(A,_)\<^bsub>\<a>\<^esub> f)" proof- have "Dom f \<in> Ob" using f .. hence 1: "Hom(A,_)\<^bsub>\<o>\<^esub> (Dom f) = Hom A (Dom f)" using f by (simp add: homf_def) have 2: "dom Set (Hom(A,_)\<^bsub>\<a>\<^esub> f) = Hom A (Dom f)" using f by (simp add: Set_def homf_def) from 1 and 2 show ?thesis by simp qed lemma (in into_set) homf_preserves_cod: assumes f: "f \<in> Ar" shows "Hom(A,_)\<^bsub>\<o>\<^esub> (Cod f) = cod Set (Hom(A,_)\<^bsub>\<a>\<^esub> f)" proof- have "Cod f \<in> Ob" using f .. hence 1: "Hom(A,_)\<^bsub>\<o>\<^esub> (Cod f) = Hom A (Cod f)" using f by (simp add: homf_def) have 2: "cod Set (Hom(A,_)\<^bsub>\<a>\<^esub> f) = Hom A (Cod f)" using f by (simp add: Set_def homf_def) from 1 and 2 show ?thesis by simp qed lemma (in into_set) homf_preserves_id: assumes B: "B \<in> Ob" shows "Hom(A,_)\<^bsub>\<a>\<^esub> (Id B) = id Set (Hom(A,_)\<^bsub>\<o>\<^esub> B)" proof- have 1: "Id B \<in> Ar" using B .. have 2: "Dom (Id B) = B" using B by (rule AA.id_dom_cod) have 3: "Cod (Id B) = B" using B by (rule AA.id_dom_cod) have 4: "(\<lambda>g\<in>Hom A B. (Id B) \<bullet> g) = (\<lambda>g\<in>Hom A B. g)" by (rule ext) (auto simp add: hom_def) have "Hom(A,_)\<^bsub>\<a>\<^esub> (Id B) = \<lparr> set_dom=Hom A B, set_func=(\<lambda>g\<in>Hom A B. g), set_cod=Hom A B\<rparr>" by (simp add: homf_def 1 2 3 4) also have "\<dots>= id Set (Hom(A,_)\<^bsub>\<o>\<^esub> B)" using B by (simp add: Set_def U_def set_cat_def set_id_def homf_def) finally show ?thesis . qed lemma (in into_set) homf_preserves_comp: assumes f: "f \<in> Ar" and g: "g \<in> Ar" and fg: "Cod f = Dom g" shows "Hom(A,_)\<^bsub>\<a>\<^esub> (g \<bullet> f) = (Hom(A,_)\<^bsub>\<a>\<^esub> g) \<odot> (Hom(A,_)\<^bsub>\<a>\<^esub> f)" proof- have 1: "g \<bullet> f \<in> Ar" using assms .. have 2: "Dom (g \<bullet> f) = Dom f" using f g fg .. have 3: "Cod (g \<bullet> f) = Cod g" using f g fg .. have lhs: "Hom(A,_)\<^bsub>\<a>\<^esub> (g \<bullet> f) = \<lparr> set_dom=Hom A (Dom f), set_func=(\<lambda>h\<in>Hom A (Dom f). (g \<bullet> f) \<bullet> h), set_cod=Hom A (Cod g)\<rparr>" by (simp add: homf_def 1 2 3) have 4: "set_dom ((Hom(A,_)\<^bsub>\<a>\<^esub> g) \<odot> (Hom(A,_)\<^bsub>\<a>\<^esub> f)) = Hom A (Dom f)" using f by (simp add: set_comp_def homf_def) have 5: "set_cod ((Hom(A,_)\<^bsub>\<a>\<^esub> g) \<odot> (Hom(A,_)\<^bsub>\<a>\<^esub> f)) = Hom A (Cod g)" using g by (simp add: set_comp_def homf_def) have "set_func ((Hom(A,_)\<^bsub>\<a>\<^esub> g) \<odot> (Hom(A,_)\<^bsub>\<a>\<^esub> f)) = compose (Hom A (Dom f)) (\<lambda>y\<in>Hom A (Dom g). g \<bullet> y) (\<lambda>x\<in>Hom A (Dom f). f \<bullet> x)" using f g by (simp add: set_comp_def homf_def) also have "\<dots> = (\<lambda>h\<in>Hom A (Dom f). (g \<bullet> f) \<bullet> h)" proof ( rule extensionalityI, rule compose_extensional, rule restrict_extensional, simp) fix h assume 10: "h \<in> Hom A (Dom f)" hence 11: "f \<bullet> h \<in> Hom A (Dom g)" proof- from 10 have "h \<in> Ar" by (simp add: hom_def) have 100: "(\<bullet>) : Hom (Dom f) (Dom g) \<rightarrow> Hom A (Dom f) \<rightarrow> Hom A (Dom g)" by (rule AA.comp_types) have "f \<in> Hom (Dom f) (Cod f)" using f by (simp add: hom_def) hence 101: "f \<in> Hom (Dom f) (Dom g)" using fg by simp from 100 and 101 have "(\<bullet>) f : Hom A (Dom f) \<rightarrow> Hom A (Dom g)" by (rule funcset_mem) from this and 10 show "f \<bullet> h \<in> Hom A (Dom g)" by (rule funcset_mem) qed hence "Cod (f \<bullet> h) = Dom g" and "Dom (f \<bullet> h) = A" and "f \<bullet> h \<in> Ar" by (simp_all add: hom_def) thus "compose (Hom A (Dom f)) (\<lambda>y\<in>Hom A (Dom g). g \<bullet> y) (\<lambda>x\<in>Hom A (Dom f). f \<bullet> x) h = (g \<bullet> f) \<bullet> h" using f g fg 10 by (simp add: compose_def 10 11 hom_def) qed finally have 6: "set_func ((Hom(A,_)\<^bsub>\<a>\<^esub> g) \<odot> (Hom(A,_)\<^bsub>\<a>\<^esub> f)) = (\<lambda>h\<in>Hom A (Dom f). (g \<bullet> f) \<bullet> h)" . from 4 and 5 and 6 have rhs: "(Hom(A,_)\<^bsub>\<a>\<^esub> g) \<odot> (Hom(A,_)\<^bsub>\<a>\<^esub> f) = \<lparr> set_dom=Hom A (Dom f), set_func=(\<lambda>h\<in>Hom A (Dom f). (g \<bullet> f) \<bullet> h), set_cod=Hom A (Cod g)\<rparr>" by simp show ?thesis by (simp add: lhs rhs) qed theorem (in into_set) homf_into_set: "Functor Hom(A,_) : AA \<longrightarrow> Set" proof (intro functor.intro functor_axioms.intro) show "Hom(A,_)\<^bsub>\<a>\<^esub> : Ar \<rightarrow> ar Set" by (rule homf_preserves_arrows) show "Hom(A,_)\<^bsub>\<o>\<^esub> : Ob \<rightarrow> ob Set" by (rule homf_preserves_objects) show "\<forall>f\<in>Ar. Hom(A,_)\<^bsub>\<o>\<^esub> (Dom f) = dom Set (Hom(A,_)\<^bsub>\<a>\<^esub> f)" by (intro ballI) (rule homf_preserves_dom) show "\<forall>f\<in>Ar. Hom(A,_)\<^bsub>\<o>\<^esub> (Cod f) = cod Set (Hom(A,_)\<^bsub>\<a>\<^esub> f)" by (intro ballI) (rule homf_preserves_cod) show "\<forall>B\<in>Ob. Hom(A,_)\<^bsub>\<a>\<^esub> (Id B) = id Set (Hom(A,_)\<^bsub>\<o>\<^esub> B)" by (intro ballI) (rule homf_preserves_id) show "\<forall>f\<in>Ar. \<forall>g\<in>Ar. Cod f = Dom g \<longrightarrow> Hom(A,_)\<^bsub>\<a>\<^esub> (g \<bullet> f) = comp Set (Hom(A,_)\<^bsub>\<a>\<^esub> g) (Hom(A,_)\<^bsub>\<a>\<^esub> f)" by (intro ballI impI, simp add: Set_def set_cat_def) (rule homf_preserves_comp) show "two_cats AA Set" proof intro_locales show "category Set" by (unfold Set_def, rule set_cat_cat) qed qed end
namespace List @[simp] theorem filter_nil {p : α → Bool} : filter p [] = [] := by simp! theorem cons_eq_append (a : α) (as : List α) : a :: as = [a] ++ as := rfl theorem filter_cons (a : α) (as : List α) : filter p (a :: as) = if p a then a :: filter p as else filter p as := sorry @[simp] theorem filter_append {as bs : List α} {p : α → Bool} : filter p (as ++ bs) = filter p as ++ filter p bs := match as with | [] => by simp | a :: as => by rw [filter_cons, cons_append, filter_cons] cases p a simp [filter_append] simp [filter_append] -- the previous contains a more complicated version of def f : Nat → Nat | 0 => 1 | i+1 => (fun x => f x) i
variable A : Set f : A f = {!!} -- The goal type should be printed as A, not A₁. -- Introducing the hidden variable with C-c C-c should choose name A.
theory DemoITPFull imports "$HIPSTER_HOME/IsaHipster" begin (* Normal list datatype *) datatype 'a Lst = Nil | Cons "'a" "'a Lst" (infix ";" 65) (* The append function. Syntactic sugar: we use +++ instead of Haskell's ++ *) fun app :: "'a Lst \<Rightarrow> 'a Lst \<Rightarrow> 'a Lst" (infix "+++" 60) where "Nil +++ xs = xs" | "(x;xs) +++ ys = x;(xs +++ ys)" (* The reverse function *) fun rev :: "'a Lst \<Rightarrow> 'a Lst" where "rev Nil = Nil" | "rev (x;xs) = (rev xs) +++ (x;Nil)" (* Datatype for binary trees from your exercises *) datatype 'a Tree = Empty | Node "'a" "'a Tree" "'a Tree" (* The swap function: swaps the left and right subtree. *) fun swap :: "'a Tree => 'a Tree" where "swap Empty = Empty" | "swap (Node data l r) = Node data (swap r) (swap l)" (* The flatten function: turn a tree into a list *) fun flatten :: "'a Tree \<Rightarrow> 'a Lst" where "flatten Empty = Nil" | "flatten (Node data l r) = ((flatten l) +++ (data;Nil)) +++ (flatten r)" hipster app rev lemma lemma_a [thy_expl]: "y +++ Lst.Nil = y" apply (induct y) apply simp apply simp done lemma lemma_aa [thy_expl]: "(y +++ z) +++ x2 = y +++ (z +++ x2)" apply (induct y arbitrary: x2 z) apply simp apply simp done lemma lemma_ab [thy_expl]: "DemoITPFull.rev z +++ DemoITPFull.rev y = DemoITPFull.rev (y +++ z)" apply (induct y arbitrary: z) apply simp apply (simp add: DemoITPFull.lemma_a) apply simp apply (metis lemma_aa) done lemma lemma_ac [thy_expl]: "DemoITPFull.rev (DemoITPFull.rev y) = y" apply (induct y) apply simp apply simp apply (metis DemoITPFull.lemma_ab DemoITPFull.rev.simps(1) DemoITPFull.rev.simps(2) Lst.distinct(1) app.elims app.simps(2)) done hipster swap flatten lemma lemma_ad [thy_expl]: "swap (swap y) = y" apply (induct y) apply simp apply simp done (* Last week's exercise 10 *) theorem exercise10: "flatten (swap p) = rev (flatten p)" apply (induct p) apply simp apply simp apply (metis DemoITPFull.rev.simps(1) DemoITPFull.rev.simps(2) lemma_a lemma_aa lemma_ab) done (* Hard exercise (optional) *) fun qrev :: "'a Lst \<Rightarrow> 'a Lst \<Rightarrow> 'a Lst" where "qrev Nil acc = acc" | "qrev (x;xs) acc = qrev xs (x;acc)" hipster qrev rev lemma lemma_ae [thy_expl]: "qrev (qrev z y) Lst.Nil = qrev y z" apply (induct z arbitrary: y) apply simp apply simp done lemma lemma_af [thy_expl]: "DemoITPFull.rev y +++ z = qrev y z" apply (induct y arbitrary: z) apply simp apply simp apply (metis DemoITPFull.rev.simps(2) app.simps(1) lemma_aa lemma_ab lemma_ac) done theorem hardExercise: "rev xs = qrev xs Nil" sledgehammer by (metis lemma_a lemma_af) (* The spine function: turns a list into a tree. *) (* fun spine :: "'a Lst \<Rightarrow> 'a Tree" where "spine Nil = Empty" | "spine (x;xs) = Node x Empty (spine xs)" hipster spine flatten lemma lemma_af [thy_expl]: "flatten (spine y) = y" apply (induct y) by simp_all *) end
lemma inverse_i [simp]: "inverse \<i> = - \<i>"
[STATEMENT] lemma pred_entailment_refl [simp]: "P \<turnstile> P" [PROOF STATE] proof (prove) goal (1 subgoal): 1. P \<turnstile> P [PROOF STEP] by(simp add: pred_entailment_def)
variables (α : Type) (p q : α → Prop) example (h : ∃ x, p x ∧ q x) : ∃ x, q x ∧ p x := let ⟨w, hpw, hqw⟩ := h in ⟨w, hqw, hpw⟩
import topology.basic import topology.compact_open import data.nat.prime import data.real.basic import data.real.irrational import data.complex.basic import data.fin.basic import geometry.euclidean.basic import analysis.inner_product_space.pi_L2 import algebra.group.defs import algebra.field.basic import combinatorics.configuration import ring_theory.polynomial.basic import group_theory.free_group import combinatorics.simple_graph.basic import ring_theory.integral_closure import data.fintype.card import category_theory.category.basic import ring_theory.discrete_valuation_ring import group_theory.torsion import linear_algebra.matrix.charpoly.basic import algebra.order.absolute_value import analysis.convex.basic import topology.uniform_space.uniform_convergence_topology import topology.sequences import analysis.normed.group.infinite_sum import data.nat.choose.sum import group_theory.specific_groups.cyclic import group_theory.order_of_element import analysis.mean_inequalities import analysis.normed_space.banach import topology.algebra.continuous_monoid_hom import linear_algebra.matrix.symmetric import analysis.inner_product_space.spectrum import ring_theory.class_group import ring_theory.dedekind_domain.basic import ring_theory.principal_ideal_domain import model_theory.satisfiability import probability.integration import ring_theory.simple_module import category_theory.preadditive.schur import representation_theory.maschke import topology.paracompact import combinatorics.simple_graph.coloring --Prove that Schur's lemma in Lean mathlib --OUTPUT 1 theorem schur_lemma {R : Type*} [comm_ring R] (M : Type*) [add_comm_group M] [module R M] (N : submodule R M) : (∀ (x : M), x ∈ N → ∀ (r : R), r • x = 0) → N = ⊥ := begin intro h, apply submodule.ext, intro x, apply iff.intro, intro hx, apply submodule.mem_bot, intro r, apply h, apply hx, intro hx, apply submodule.mem_bot_iff.mp, intro r, apply h, apply hx, --OUTPUT 2 theorem schur_lemma (R : Type*) [comm_ring R] (M : Type*) [add_comm_group M] [module R M] (N : submodule R M) : (∀ (x : M), x ∈ N → ∀ (r : R), r • x = 0) → N = ⊥ := begin intro h, apply submodule.ext, intro x, split, { intro hx, rw mem_bot at hx, rw hx, exact zero_smul R x, }, { intro hx, rw mem_bot, rw hx, exact h x hx 0, } --OUTPUT 3 theorem schur_lemma (R : Type) [comm_ring R] (M : Type) [add_comm_group M] [module R M] (N : submodule R M) : (∀ (x : M), x ∈ N → x = 0) → N = ⊥ := begin intro h, apply submodule.ext, intro x, apply submodule.mem_bot_iff.mpr, intro y, apply h, apply submodule.smul_mem, exact y, exact x,
theory prop_79 imports Main "$HIPSTER_HOME/IsaHipster" begin datatype Nat = Z | S "Nat" fun minus :: "Nat => Nat => Nat" where "minus (Z) y = Z" | "minus (S z) (Z) = S z" | "minus (S z) (S x2) = minus z x2" (*hipster minus *) lemma lemma_a [thy_expl]: "prop_79.minus x2 x2 = Z" by (hipster_induct_schemes prop_79.minus.simps) lemma lemma_aa [thy_expl]: "prop_79.minus x3 Z = x3" by (hipster_induct_schemes prop_79.minus.simps) lemma lemma_ab [thy_expl]: "prop_79.minus x2 (S x2) = Z" by (hipster_induct_schemes) lemma lemma_ac [thy_expl]: "prop_79.minus (S x2) x2 = S Z" by (hipster_induct_schemes) lemma lemma_ad [thy_expl]: "prop_79.minus (prop_79.minus x3 y3) (prop_79.minus y3 x3) = prop_79.minus x3 y3" by (hipster_induct_schemes prop_79.minus.simps) lemma lemma_ae [thy_expl]: "prop_79.minus (prop_79.minus x3 y3) (S Z) = prop_79.minus x3 (S y3)" by (hipster_induct_schemes prop_79.minus.simps) lemma lemma_af [thy_expl]: "prop_79.minus (prop_79.minus x4 y4) x4 = Z" by (hipster_induct_schemes prop_79.minus.simps) theorem x0 : "(minus (minus (S m) n) (S k)) = (minus (minus m n) k)" by (tactic \<open>Subgoal.FOCUS_PARAMS (K (Tactic_Data.hard_tac @{context})) @{context} 1\<close>) end
[STATEMENT] lemma quotient_of_number [simp]: "quotient_of 0 = (0, 1)" "quotient_of 1 = (1, 1)" "quotient_of (numeral k) = (numeral k, 1)" "quotient_of (- 1) = (- 1, 1)" "quotient_of (- numeral k) = (- numeral k, 1)" [PROOF STATE] proof (prove) goal (1 subgoal): 1. (quotient_of 0 = (0, 1) &&& quotient_of 1 = (1, 1)) &&& quotient_of (numeral k) = (numeral k, 1) &&& quotient_of (- 1) = (- 1, 1) &&& quotient_of (- numeral k) = (- numeral k, 1) [PROOF STEP] by (simp_all add: rat_number_expand quotient_of_Fract)
theory HF_Extras imports HereditarilyFinite.Rank begin lemma hcard_ord_of[simp]: "hcard (ord_of n) = n" unfolding hcard_def hfset_ord_of card_image[OF inj_ord_of] by simp lemma hcard_HF: "finite A \<Longrightarrow> hcard (HF A) = card A" unfolding hcard_def using hfset_HF by simp end
Formal statement is: lemma coeff_0_reflect_poly_0_iff [simp]: "coeff (reflect_poly p) 0 = 0 \<longleftrightarrow> p = 0" Informal statement is: The coefficient of the constant term of the reflected polynomial is zero if and only if the original polynomial is zero.
def isEven : ℕ → Prop := λ n, ∃ m : ℕ, m * 2 = n lemma eightIsEven : isEven 8 := begin unfold isEven, exact ⟨4, dec_trivial⟩, end -- def isNonZ : ℕ → Prop := λ n, n ≠ 0 def isnonz : Prop := ∃ n : ℕ, n ≠ 0 lemma isNonZ : isnonz := ⟨1, dec_trivial⟩ lemma isNonZ' : isnonz := begin apply exists.intro 1, assume : 1 = 0, show false, from nat.no_confusion this, end example : ∀ {P S : ℕ → Prop}, (∃ n : ℕ, P n ∧ S n) → (∃ n : ℕ, S n ∧ P n) := begin assume P S, assume ex, apply exists.elim ex, assume x, assume px_sx, apply exists.intro x, apply and.comm.mpr, assumption, end example : ∀ {P S : ℕ → Prop}, (∃ n : ℕ, P n ∧ S n) → (∃ n : ℕ, S n ∧ P n) := begin assume P S, assume ex, apply exists.elim ex, assume x, assume px_sx, apply exists.intro x, apply and.intro, exact px_sx.2, exact px_sx.1, end def isSquare : ℕ → Prop := λ n, ∃ m : ℕ, n * n = m example : isSquare 9 := ⟨81, dec_trivial⟩ example : isSquare 9 := begin apply exists.intro 81, apply rfl end
{-# LANGUAGE AllowAmbiguousTypes #-} {-# LANGUAGE ConstraintKinds #-} {-# LANGUAGE DataKinds #-} {-# LANGUAGE DeriveDataTypeable #-} {-# LANGUAGE FlexibleContexts #-} {-# LANGUAGE FlexibleInstances #-} {-# LANGUAGE GADTs #-} {-# LANGUAGE InstanceSigs #-} {-# LANGUAGE KindSignatures #-} {-# LANGUAGE LambdaCase #-} {-# LANGUAGE MultiParamTypeClasses #-} {-# LANGUAGE PatternSynonyms #-} {-# LANGUAGE RankNTypes #-} {-# LANGUAGE ScopedTypeVariables #-} {-# LANGUAGE TupleSections #-} {-# LANGUAGE TypeApplications #-} {-# LANGUAGE TypeFamilies #-} {-# LANGUAGE TypeFamilyDependencies #-} {-# LANGUAGE TypeInType #-} {-# LANGUAGE TypeOperators #-} {-# LANGUAGE UndecidableInstances #-} {-# LANGUAGE ViewPatterns #-} module Backprop.Learn.Model.Combinator ( Chain(..) , (~++) , chainParamLength , chainStateLength , LearnFunc(..), learnFunc , LMap(..), RMap(..) , Dimap, pattern DM, _dmPre, _dmPost, _dmLearn , (.~) , nilLF, onlyLF , (:.~)(..) , (:&&&)(..) , KAutoencoder, kAutoencoder, kaeEncoder, kaeDecoder , Feedback(..), feedbackId , FeedbackTrace(..), feedbackTraceId ) where import Backprop.Learn.Model.Class import Backprop.Learn.Model.Function import Control.Applicative import Control.Category import Control.Monad import Control.Monad.Primitive import Control.Monad.Trans.State import Data.Bifunctor import Data.Kind import Data.Type.Equality import Data.Type.Length import Data.Type.Mayb as Mayb import Data.Type.NonEmpty import Data.Type.Tuple hiding (T2(..), T3(..)) import Data.Typeable import GHC.TypeNats import Numeric.Backprop import Numeric.LinearAlgebra.Static.Backprop import Prelude hiding ((.), id) import Type.Class.Known import Type.Class.Witness import Type.Family.List as List import qualified Data.Type.Tuple as T import qualified Data.Vector.Sized as SV import qualified System.Random.MWC as MWC -- | Chain components linearly, retaining the ability to deconstruct at -- a later time. data Chain :: [Type] -> Type -> Type -> Type where CNil :: Chain '[] a a (:~>) :: (Learn a b l, KnownMayb (LParamMaybe l), KnownMayb (LStateMaybe l)) => l -> Chain ls b c -> Chain (l ': ls) a c deriving (Typeable) infixr 5 :~> instance ( ListC (Backprop List.<$> LParams ls) , ListC (Backprop List.<$> LStates ls) ) => Learn a b (Chain ls a b) where type LParamMaybe (Chain ls a b) = NETup Mayb.<$> ToNonEmpty (LParams ls) type LStateMaybe (Chain ls a b) = NETup Mayb.<$> ToNonEmpty (LStates ls) runLearn = runChainLearn runLearnStoch = runChainLearnStoch runChainLearn :: (Reifies s W, ListC (Backprop List.<$> LParams ls), ListC (Backprop List.<$> LStates ls)) => Chain ls a b -> Mayb (BVar s) (NETup Mayb.<$> ToNonEmpty (LParams ls)) -> BVar s a -> Mayb (BVar s) (NETup Mayb.<$> ToNonEmpty (LStates ls)) -> (BVar s b, Mayb (BVar s) (NETup Mayb.<$> ToNonEmpty (LStates ls))) runChainLearn = \case CNil -> \_ x _ -> (x, N_) (l :: l) :~> ls -> let lenPs = chainParamLength ls lenSs = chainStateLength ls in case knownMayb @(LParamMaybe l) of N_ -> \ps x -> case knownMayb @(LStateMaybe l) of N_ -> \ss -> flip (runChainLearn ls ps) ss . runLearnStateless l N_ $ x J_ _ -> case lenSs of LZ -> \case J_ (isoVar (tOnly . netT) (NETT . onlyT)->s) -> let (y, J_ s') = runLearn l N_ x (J_ s) (z, _ ) = runChainLearn ls ps y N_ in (z, J_ $ isoVar (NETT . onlyT) (tOnly . netT) s') LS _ -> \case J_ ss -> lenSs // let (y, J_ s' ) = runLearn l N_ x (J_ (ss ^^. netHead)) ssTail = isoVar NETT netT $ ss ^^. netTail (z, J_ ss') = runChainLearn ls ps y (J_ ssTail) in (z, J_ $ isoVar2 NET unNet s' $ isoVar netT NETT ss') J_ _ -> case lenPs of LZ -> \case J_ (isoVar (tOnly . netT) (NETT . onlyT)->p) -> \x -> case knownMayb @(LStateMaybe l) of N_ -> \ss -> flip (runChainLearn ls N_) ss . runLearnStateless l (J_ p) $ x J_ _ -> case lenSs of LZ -> \case J_ (isoVar (tOnly . netT) (NETT . onlyT)->s) -> let (y, J_ s') = runLearn l (J_ p) x (J_ s) (z, _ ) = runChainLearn ls N_ y N_ in (z, J_ $ isoVar (NETT . onlyT) (tOnly . netT) s') LS _ -> \case J_ ss -> lenSs // let (y, J_ s' ) = runLearn l (J_ p) x (J_ (ss ^^. netHead)) ssTail = isoVar NETT netT $ ss ^^. netTail (z, J_ ss') = runChainLearn ls N_ y (J_ ssTail) in (z, J_ $ isoVar2 NET unNet s' $ isoVar netT NETT ss') LS _ -> \case J_ ps -> \x -> lenPs // let psHead = ps ^^. netHead psTail = isoVar NETT netT $ ps ^^. netTail in case knownMayb @(LStateMaybe l) of N_ -> \ss -> flip (runChainLearn ls (J_ psTail)) ss . runLearnStateless l (J_ psHead) $ x J_ _ -> case lenSs of LZ -> \case J_ (isoVar (tOnly . netT) (NETT . onlyT)->s) -> let (y, J_ s') = runLearn l (J_ psHead) x (J_ s) (z, _ ) = runChainLearn ls (J_ psTail) y N_ in (z, J_ $ isoVar (NETT . onlyT) (tOnly . netT) s') LS _ -> \case J_ ss -> lenSs // let (y, J_ s' ) = runLearn l (J_ psHead) x (J_ (ss ^^. netHead)) ssTail = isoVar NETT netT $ ss ^^. netTail (z, J_ ss') = runChainLearn ls (J_ psTail) y (J_ ssTail) in (z, J_ $ isoVar2 NET unNet s' $ isoVar netT NETT ss') runChainLearnStoch :: ( Reifies s W , ListC (Backprop List.<$> LParams ls) , ListC (Backprop List.<$> LStates ls) , PrimMonad m ) => Chain ls a b -> MWC.Gen (PrimState m) -> Mayb (BVar s) (NETup Mayb.<$> ToNonEmpty (LParams ls)) -> BVar s a -> Mayb (BVar s) (NETup Mayb.<$> ToNonEmpty (LStates ls)) -> m (BVar s b, Mayb (BVar s) (NETup Mayb.<$> ToNonEmpty (LStates ls))) runChainLearnStoch = \case CNil -> \_ _ x _ -> pure (x, N_) (l :: l) :~> ls -> \g -> let lenPs = chainParamLength ls lenSs = chainStateLength ls in case knownMayb @(LParamMaybe l) of N_ -> \ps x -> case knownMayb @(LStateMaybe l) of N_ -> \ss -> flip (runChainLearnStoch ls g ps) ss <=< runLearnStochStateless l g N_ $ x J_ _ -> case lenSs of LZ -> \case J_ (isoVar (tOnly . netT) (NETT . onlyT)->s) -> do (y, s') <- second fromJ_ <$> runLearnStoch l g N_ x (J_ s) (z, _ ) <- runChainLearnStoch ls g ps y N_ pure (z, J_ $ isoVar (NETT . onlyT) (tOnly . netT) s') LS _ -> \case J_ ss -> lenSs // do (y, s' ) <- second fromJ_ <$> runLearnStoch l g N_ x (J_ (ss ^^. netHead)) let ssTail = isoVar NETT netT $ ss ^^. netTail (z, ss') <- second fromJ_ <$> runChainLearnStoch ls g ps y (J_ ssTail) pure (z, J_ $ isoVar2 NET unNet s' $ isoVar netT NETT ss') J_ _ -> case lenPs of LZ -> \case J_ (isoVar (tOnly . netT) (NETT . onlyT)->p) -> \x -> case knownMayb @(LStateMaybe l) of N_ -> \ss -> flip (runChainLearnStoch ls g N_) ss <=< runLearnStochStateless l g (J_ p) $ x J_ _ -> case lenSs of LZ -> \case J_ (isoVar (tOnly . netT) (NETT . onlyT)->s) -> do (y, s') <- second fromJ_ <$> runLearnStoch l g (J_ p) x (J_ s) (z, _ ) <- runChainLearnStoch ls g N_ y N_ pure (z, J_ $ isoVar (NETT . onlyT) (tOnly . netT) s') LS _ -> \case J_ ss -> lenSs // do (y, s' ) <- second fromJ_ <$> runLearnStoch l g (J_ p) x (J_ (ss ^^. netHead)) let ssTail = isoVar NETT netT $ ss ^^. netTail (z, ss') <- second fromJ_ <$> runChainLearnStoch ls g N_ y (J_ ssTail) pure (z, J_ $ isoVar2 NET unNet s' $ isoVar netT NETT ss') LS _ -> \case J_ ps -> \x -> lenPs // let psHead = ps ^^. netHead psTail = isoVar NETT netT $ ps ^^. netTail in case knownMayb @(LStateMaybe l) of N_ -> \ss -> flip (runChainLearnStoch ls g (J_ psTail)) ss <=< runLearnStochStateless l g (J_ psHead) $ x J_ _ -> case lenSs of LZ -> \case J_ (isoVar (tOnly . netT) (NETT . onlyT)->s) -> do (y, s') <- second fromJ_ <$> runLearnStoch l g (J_ psHead) x (J_ s) (z, _ ) <- runChainLearnStoch ls g (J_ psTail) y N_ pure (z, J_ $ isoVar (NETT . onlyT) (tOnly . netT) s') LS _ -> \case J_ ss -> lenSs // do (y, s' ) <- second fromJ_ <$> runLearnStoch l g (J_ psHead) x (J_ (ss ^^. netHead)) let ssTail = isoVar NETT netT $ ss ^^. netTail (z, ss') <- second fromJ_ <$> runChainLearnStoch ls g (J_ psTail) y (J_ ssTail) pure (z, J_ $ isoVar2 NET unNet s' $ isoVar netT NETT ss') -- | Appending 'Chain' (~++) :: forall ls ms a b c. () => Chain ls a b -> Chain ms b c -> Chain (ls ++ ms) a c (~++) = \case CNil -> id (l :: l) :~> (ls :: Chain ls' a' b) -> case assocMaybAppend @(LParamMaybe l) @(LParams ls') @(LParams ms) known of Refl -> case assocMaybAppend @(LStateMaybe l) @(LStates ls') @(LStates ls) known of Refl -> \ms -> (l :~> (ls ~++ ms)) \\ appendLength (chainParamLength ls) (chainParamLength ms) \\ appendLength (chainStateLength ls) (chainStateLength ms) chainParamLength :: Chain ls a b -> Length (LParams ls) chainParamLength = \case CNil -> LZ (_ :: l) :~> ls -> case knownMayb @(LParamMaybe l) of N_ -> chainParamLength ls J_ _ -> LS $ chainParamLength ls chainStateLength :: Chain ls a b -> Length (LStates ls) chainStateLength = \case CNil -> LZ (_ :: l) :~> ls -> case knownMayb @(LStateMaybe l) of N_ -> chainStateLength ls J_ _ -> LS $ chainStateLength ls appendLength :: forall as bs. () => Length as -> Length bs -> Length (as ++ bs) appendLength LZ = id appendLength (LS l) = LS . appendLength l assocMaybAppend :: forall a bs cs. () => Mayb P a -> (MaybeToList a ++ (bs ++ cs)) :~: ((MaybeToList a ++ bs) ++ cs) assocMaybAppend = \case N_ -> Refl J_ _ -> Refl -- | Data type representing trainable models. -- -- Useful for performant composition, but you lose the ability to decompose -- parts. data LearnFunc :: Maybe Type -> Maybe Type -> Type -> Type -> Type where LF :: { _lfRunLearn :: forall q. Reifies q W => Mayb (BVar q) p -> BVar q a -> Mayb (BVar q) s -> (BVar q b, Mayb (BVar q) s) , _lfRunLearnStoch :: forall m q. (PrimMonad m, Reifies q W) => MWC.Gen (PrimState m) -> Mayb (BVar q) p -> BVar q a -> Mayb (BVar q) s -> m (BVar q b, Mayb (BVar q) s) } -> LearnFunc p s a b deriving (Typeable) learnFunc :: Learn a b l => l -> LearnFunc (LParamMaybe l) (LStateMaybe l) a b learnFunc l = LF { _lfRunLearn = runLearn l , _lfRunLearnStoch = runLearnStoch l } instance Learn a b (LearnFunc p s a b) where type LParamMaybe (LearnFunc p s a b) = p type LStateMaybe (LearnFunc p s a b) = s runLearn = _lfRunLearn runLearnStoch = _lfRunLearnStoch instance Category (LearnFunc p s) where id = LF { _lfRunLearn = \_ -> (,) , _lfRunLearnStoch = \_ _ x -> pure . (x,) } f . g = LF { _lfRunLearn = \p x s0 -> let (y, s1) = _lfRunLearn g p x s0 in _lfRunLearn f p y s1 , _lfRunLearnStoch = \gen p x s0 -> do (y, s1) <- _lfRunLearnStoch g gen p x s0 _lfRunLearnStoch f gen p y s1 } -- | Compose two 'LearnFunc' on lists. (.~) :: forall ps qs ss ts a b c. ( ListC (Backprop List.<$> ps) , ListC (Backprop List.<$> qs) , ListC (Backprop List.<$> ss) , ListC (Backprop List.<$> ts) , ListC (Backprop List.<$> (ss ++ ts)) , Known Length ps , Known Length ss , Known Length ts ) => LearnFunc ('Just (T ps )) ('Just (T ss )) b c -> LearnFunc ('Just (T qs )) ('Just (T ts )) a b -> LearnFunc ('Just (T (ps ++ qs))) ('Just (T (ss ++ ts ))) a c f .~ g = LF { _lfRunLearn = \(J_ psqs) x (J_ ssts) -> appendLength @ss @ts known known // let (y, J_ ts) = _lfRunLearn g (J_ (psqs ^^. tDrop @ps @qs known)) x (J_ (ssts ^^. tDrop @ss @ts known)) (z, J_ ss) = _lfRunLearn f (J_ (psqs ^^. tTake @ps @qs known)) y (J_ (ssts ^^. tTake @ss @ts known)) in (z, J_ $ isoVar2 (tAppend @ss @ts) (tSplit @ss @ts known) ss ts ) , _lfRunLearnStoch = \gen (J_ psqs) x (J_ ssts) -> appendLength @ss @ts known known // do (y, ts) <- second fromJ_ <$> _lfRunLearnStoch g gen (J_ (psqs ^^. tDrop @ps @qs known)) x (J_ (ssts ^^. tDrop @ss @ts known)) (z, ss) <- second fromJ_ <$> _lfRunLearnStoch f gen (J_ (psqs ^^. tTake @ps @qs known)) y (J_ (ssts ^^. tTake @ss @ts known)) pure (z, J_ $ isoVar2 (tAppend @ss @ts) (tSplit @ss @ts known) ss ts ) } -- | Identity of '.~' nilLF :: LearnFunc ('Just (T '[])) ('Just (T '[])) a a nilLF = id -- | 'LearnFunc' with singleton lists; meant to be used with '.~' onlyLF :: forall p s a b. (KnownMayb p, MaybeC Backprop p, KnownMayb s, MaybeC Backprop s) => LearnFunc p s a b -> LearnFunc ('Just (T (MaybeToList p))) ('Just (T (MaybeToList s))) a b onlyLF f = LF { _lfRunLearn = \(J_ ps) x ssM@(J_ ss) -> case knownMayb @p of N_ -> case knownMayb @s of N_ -> (second . const) ssM $ _lfRunLearn f N_ x N_ J_ _ -> second (J_ . isoVar onlyT tOnly . fromJ_) $ _lfRunLearn f N_ x (J_ (isoVar tOnly onlyT ss)) J_ _ -> let p = isoVar tOnly onlyT ps in case knownMayb @s of N_ -> (second . const) ssM $ _lfRunLearn f (J_ p) x N_ J_ _ -> second (J_ . isoVar onlyT tOnly . fromJ_) $ _lfRunLearn f (J_ p) x (J_ (isoVar tOnly onlyT ss)) , _lfRunLearnStoch = \g (J_ ps) x ssM@(J_ ss) -> case knownMayb @p of N_ -> case knownMayb @s of N_ -> (fmap . second . const) ssM $ _lfRunLearnStoch f g N_ x N_ J_ _ -> (fmap . second) (J_ . isoVar onlyT tOnly . fromJ_) $ _lfRunLearnStoch f g N_ x (J_ (isoVar tOnly onlyT ss)) J_ _ -> let p = isoVar tOnly onlyT ps in case knownMayb @s of N_ -> (fmap . second . const) ssM $ _lfRunLearnStoch f g (J_ p) x N_ J_ _ -> (fmap . second) (J_ . isoVar onlyT tOnly . fromJ_) $ _lfRunLearnStoch f g (J_ p) x (J_ (isoVar tOnly onlyT ss)) } -- | Compose two layers sequentially -- -- Note that this composes in the opposite order of '.' and ':.:', for -- consistency with the rest of the library. -- -- The basic autoencoder is simply @l ':.~' m@, where @'Learn' a b l@ and -- @'Learn' b a m@. However, for sparse autoencoder, look at -- 'Autoencoder'. data (:.~) :: Type -> Type -> Type where (:.~) :: l -> m -> l :.~ m infixr 5 :.~ instance ( Learn a b l , Learn b c m , KnownMayb (LParamMaybe l) , KnownMayb (LParamMaybe m) , KnownMayb (LStateMaybe l) , KnownMayb (LStateMaybe m) , MaybeC Backprop (LParamMaybe l) , MaybeC Backprop (LParamMaybe m) , MaybeC Backprop (LStateMaybe l) , MaybeC Backprop (LStateMaybe m) ) => Learn a c (l :.~ m) where type LParamMaybe (l :.~ m) = TupMaybe (LParamMaybe l) (LParamMaybe m) type LStateMaybe (l :.~ m) = TupMaybe (LStateMaybe l) (LStateMaybe m) runLearn (l :.~ m) pq x st = (z, tupMaybe T2B s' t') where (p, q) = splitTupMaybe @_ @(LParamMaybe l) @(LParamMaybe m) (\(T2B v u) -> (v, u)) pq (s, t) = splitTupMaybe @_ @(LStateMaybe l) @(LStateMaybe m) (\(T2B v u) -> (v, u)) st (y, s') = runLearn l p x s (z, t') = runLearn m q y t runLearnStoch (l :.~ m) g pq x st = do (y, s') <- runLearnStoch l g p x s (z, t') <- runLearnStoch m g q y t pure (z, tupMaybe T2B s' t') where (p, q) = splitTupMaybe @_ @(LParamMaybe l) @(LParamMaybe m) (\(T2B v u) -> (v, u)) pq (s, t) = splitTupMaybe @_ @(LStateMaybe l) @(LStateMaybe m) (\(T2B v u) -> (v, u)) st -- | Pre-compose a pure parameterless function to a model. -- -- An @'LMap' b a@ takes a model from @b@ and turns it into a model from -- @a@. data LMap :: Type -> Type -> Type -> Type where LM :: { _lmPre :: forall s. Reifies s W => BVar s a -> BVar s b , _lmLearn :: l } -> LMap b a l -- | Post-compose a pure parameterless function to a model. -- -- An @'Rmap' b c@ takes a model returning @b@ and turns it into -- a model returning @c@. data RMap :: Type -> Type -> Type -> Type where RM :: { _rmPost :: forall s. Reifies s W => BVar s b -> BVar s c , _rmLearn :: l } -> RMap b c l -- | Pre- and post-compose pure parameterless functions to a model. -- -- A @'Dimap' b c a d@ takes a model from @b@ to @c@ and turns it into -- a model from @a@ to @d@. -- -- @ -- instance 'Learn' b c => Learn a d ('Dimap' b c a d l) where -- type 'LParamMaybe' (Dimap b c a d l) = LParamMaybe l -- type 'LStateMaybe' (Dimap b c a d l) = LStateMaybe l -- @ type Dimap b c a d l = RMap c d (LMap b a l) -- | Constructor for 'Dimap' pattern DM :: (forall s. Reifies s W => BVar s a -> BVar s b) -> (forall s. Reifies s W => BVar s c -> BVar s d) -> l -> Dimap b c a d l pattern DM { _dmPre, _dmPost, _dmLearn } = RM _dmPost (LM _dmPre _dmLearn) instance Learn b c l => Learn a c (LMap b a l) where type LParamMaybe (LMap b a l) = LParamMaybe l type LStateMaybe (LMap b a l) = LStateMaybe l runLearn (LM f l) p x = runLearn l p (f x) runLearnStoch (LM f l) g p x = runLearnStoch l g p (f x) instance Learn a b l => Learn a c (RMap b c l) where type LParamMaybe (RMap b c l) = LParamMaybe l type LStateMaybe (RMap b c l) = LStateMaybe l runLearn (RM f l) p x = first f . runLearn l p x runLearnStoch (RM f l) g p x = (fmap . first) f . runLearnStoch l g p x -- | Take a model and turn it into a model that runs its output into itself -- several times, returning the final result. Parameterized by the number -- of repeats, and the function to process the output to become the next -- input. -- -- I don't know why anyone would ever want this. -- -- See 'FeedbackTrace' if you want to observe all of the intermediate -- outputs. data Feedback :: Type -> Type -> Type -> Type where FB :: { _fbTimes :: Int , _fbFeed :: forall s. Reifies s W => BVar s b -> BVar s a , _fbLearn :: l } -> Feedback a b l deriving (Typeable) -- | Construct a 'Feedback' from an endofunction (a function that returns -- a value fo the same type as its input) by simply providing the output -- directly as the next intput. feedbackId :: Int -> l -> Feedback a a l feedbackId n = FB n id instance Learn a b l => Learn a b (Feedback a b l) where type LParamMaybe (Feedback a b l) = LParamMaybe l type LStateMaybe (Feedback a b l) = LStateMaybe l runLearn (FB n f l) p = runState . foldr (>=>) go (replicate (n - 1) (fmap f . go)) where go = state . runLearn l p runLearnStoch (FB n f l) g p = runStateT . foldr (>=>) go (replicate (n - 1) (fmap f . go)) where go = StateT . runLearnStoch l g p -- | Take a model and turn it into a model that runs its output into itself -- several times, and returns all of the intermediate outputs. -- Parameterized by the function to process the output to become the next -- input. -- -- See 'Feedback' if you only need the final result. -- -- Compare also to 'Unroll'. data FeedbackTrace :: Nat -> Type -> Type -> Type -> Type where FBT :: { _fbtFeed :: forall s. Reifies s W => BVar s b -> BVar s a , _fbtLearn :: l } -> FeedbackTrace n a b l deriving (Typeable) -- | Construct a 'FeedbackTrace' from an endofunction (a function that -- returns a value fo the same type as its input) by simply providing the -- output directly as the next intput. feedbackTraceId :: l -> FeedbackTrace n a a l feedbackTraceId = FBT id instance (Learn a b l, KnownNat n, Backprop b) => Learn a (ABP (SV.Vector n) b) (FeedbackTrace n a b l) where type LParamMaybe (FeedbackTrace n a b l) = LParamMaybe l type LStateMaybe (FeedbackTrace n a b l) = LStateMaybe l runLearn (FBT f l) p x0 = second snd . runState (collectVar . ABP <$> SV.replicateM (state go)) . (x0,) where go (x, s) = (y, (f y, s')) where (y, s') = runLearn l p x s runLearnStoch (FBT f l) g p x0 = (fmap . second) snd . runStateT (collectVar . ABP <$> SV.replicateM (StateT go)) . (x0,) where go (x, s) = do (y, s') <- runLearnStoch l g p x s pure (y, (f y, s')) -- | "Fork"/"Fan out" two models from the same input. Useful for data (:&&&) :: Type -> Type -> Type where (:&&&) :: l -> m -> l :&&& m infixr 3 :&&& instance ( Learn a b l , Learn a c m , KnownMayb (LParamMaybe l) , KnownMayb (LParamMaybe m) , KnownMayb (LStateMaybe l) , KnownMayb (LStateMaybe m) , MaybeC Backprop (LParamMaybe l) , MaybeC Backprop (LParamMaybe m) , MaybeC Backprop (LStateMaybe l) , MaybeC Backprop (LStateMaybe m) , Backprop b , Backprop c ) => Learn a (T.T2 b c) (l :&&& m) where type LParamMaybe (l :&&& m) = TupMaybe (LParamMaybe l) (LParamMaybe m) type LStateMaybe (l :&&& m) = TupMaybe (LStateMaybe l) (LStateMaybe m) runLearn (l :&&& m) pq x st = ( T2B y z , tupMaybe T2B s' t' ) where (p, q) = splitTupMaybe @_ @(LParamMaybe l) @(LParamMaybe m) (\(T2B v u) -> (v, u)) pq (s, t) = splitTupMaybe @_ @(LStateMaybe l) @(LStateMaybe m) (\(T2B v u) -> (v, u)) st (y, s') = runLearn l p x s (z, t') = runLearn m q x t runLearnStoch (l :&&& m) g pq x st = do (y, s') <- runLearnStoch l g p x s (z, t') <- runLearnStoch m g q x t pure ( T2B y z , tupMaybe T2B s' t' ) where (p, q) = splitTupMaybe @_ @(LParamMaybe l) @(LParamMaybe m) (\(T2B v u) -> (v, u)) pq (s, t) = splitTupMaybe @_ @(LStateMaybe l) @(LStateMaybe m) (\(T2B v u) -> (v, u)) st -- | K-sparse autoencoder. A normal autoencoder is simply @l ':.~' m@; -- however a k-sparse autoencoder attempts to ensure that the encoding has -- about @k@ active components for every input. -- -- <http://www.ericlwilkinson.com/blog/2014/11/19/deep-learning-sparse-autoencoders> -- -- @ -- instance ('Learn' a ('R' n) l, Learn (R n) a m) => Learn a a ('KAutoencoder' n l m) where -- type 'LParamMaybe' ('KAutoencoder' n l m) = 'TupMaybe' (LParamMaybe l) (LParamMaybe m) -- type 'LStateMaybe' ('KAutoencoder' n l m) = 'TupMaybe' (LStateMaybe l) (LStateMaybe m) -- @ -- -- To "encode" after training this, get the encoder with 'kaeEncoder'. type KAutoencoder n l m = RMap (R n) (R n) l :.~ m -- | Construct a 'KAutoencoder'. -- -- Note that this only has a 'Learn' instance of @l@ outputs @'R' n@ and -- @m@ takes @'R' n@. Also, for this to be an actual autoencoder, the -- input of @l@ has to be the same as the output of @m@. kAutoencoder :: KnownNat n => l -> m -> Int -> KAutoencoder n l m kAutoencoder l m k = RM (kSparse k) l :.~ m kaeEncoder :: KAutoencoder n l m -> l kaeEncoder (RM _ l :.~ _) = l kaeDecoder :: KAutoencoder n l m -> m kaeDecoder (_ :.~ m) = m -- TODO: KL-divergence autoencoders, a la -- <http://ufldl.stanford.edu/tutorial/unsupervised/Autoencoders/>. -- -- | Simple /sparse/ autoencoder that outputs the average activation of -- -- a vector encoding as well as the result. -- -- -- -- The traditional autoencoder is simply @l ':.~' m@. However, the enforce -- -- sparsity, you have to also be able to observe the average activation of -- -- your encoding for your loss function (typically 'klDivergence' for -- -- Kullback-Leibler divergence) -- -- -- -- See <http://ufldl.stanford.edu/tutorial/unsupervised/Autoencoders/>. -- -- -- -- @ -- -- instance ('Learn' a ('R' n) l, Learn (R n) a l, 1 '<=' n) => Learn a ('T2' 'Double' a) where -- -- type 'LParamMaybe' ('Autoencoder' n l m) = 'TupMaybe' (LParamMaybe l) (LParamMaybe m) -- -- type 'LStateMaybe' ('Autoencoder' n l m) = 'TupMaybe' (LStateMaybe l) (LStateMaybe m) -- -- @ -- -- -- -- To /use/ the autoencoder after training it, just pattern match on 'AE' -- -- or use '_aeEncode' (or '_aeDecode') -- type Autoencoder n l m = l :.~ (FixedFunc (R n) Double :&&& m) -- -- -- | Construct an 'Autoencoder' by giving the encoder and decoder. -- pattern AE -- :: (Learn a (R n) l, Learn (R n) a m, 1 <= n, KnownNat n) -- => l -- ^ '_aeEncode' -- -> m -- ^ '_aeDecode' -- -> Autoencoder n l m -- pattern AE { _aeEncode, _aeDecode } <- _aeEncode :.~ (_ :&&& _aeDecode) -- where -- AE e d = e :.~ (FF mean :&&& d)
/** * @file * $Revision$ * $Date$ * * Unless noted otherwise, the portions of Isis written by the USGS are public * domain. See individual third-party library and package descriptions for * intellectual property information,user agreements, and related information. * * Although Isis has been used by the USGS, no warranty, expressed or implied, * is made by the USGS as to the accuracy and functioning of such software * and related material nor shall the fact of distribution constitute any such * warranty, and no responsibility is assumed by the USGS in connection * therewith. * * For additional information, launch * $ISISROOT/doc//documents/Disclaimers/Disclaimers.html in a browser or see * the Privacy &amp; Disclaimers page on the Isis website, * http://isis.astrogeology.usgs.gov, and the USGS privacy and disclaimers on * http://www.usgs.gov/privacy.html. */ #include <boost/foreach.hpp> #include "opencv2/opencv.hpp" #include "opencv2/xfeatures2d.hpp" #include "BRISKAlgorithm.h" #include <QVariant> namespace Isis { /** * Constructs the algorithm with default variables. */ BRISKAlgorithm::BRISKAlgorithm() : Feature2DAlgorithm("BRISK", "Feature2D", BRISKType::create()) { setupParameters(); } /** * Constructs the algorithm with the input variables * * @param cvars The variables and values the algorithm will use. * Variables that are not included will be set to their default. * @param config The config string used to construct cvars. */ BRISKAlgorithm::BRISKAlgorithm(const PvlFlatMap &cvars, const QString &config) : Feature2DAlgorithm("BRISK", "Feature2D", BRISKType::create(), cvars) { setConfig(config); PvlFlatMap variables = setupParameters(); variables.merge(cvars); // Constructs the algorithm for a custom pattern if (variables.exists("RadiusList") && variables.exists("NumberList")) { std::vector<float> radiusList; QStringList radiusStrings = variables.get("RadiusList").split(","); BOOST_FOREACH(QString radius, radiusStrings) { radiusList.push_back(radius.toFloat()); } std::vector<int> numberList; QStringList numberStrings = variables.get("NumberList").split(","); BOOST_FOREACH(QString number, numberStrings) { numberList.push_back(toInt(number)); } const float dMax = variables.get("DMax", "5.85").toFloat(); const float dMin = variables.get("DMin", "8.2").toFloat(); std::vector<int> indexChange; if (!variables.get("IndexChange", "").isEmpty()) { QStringList indexStrings = variables.get("IndexChange").split(","); BOOST_FOREACH(QString index, indexStrings) { indexChange.push_back(toInt(index)); } } m_algorithm = BRISKType::create(radiusList, numberList, dMax, dMin, indexChange); } // Constructs the algorithm with the input variables else { const int thresh = toInt(variables.get("Threshold")); const int octaves = toInt(variables.get("NOctaves")); const float patternScale = variables.get("PatternScale").toFloat(); m_algorithm = BRISKType::create(thresh, octaves, patternScale); } m_variables.merge(variables); } /** * Destroys the algorithm */ BRISKAlgorithm::~BRISKAlgorithm() { } /** * Sets up the algorithm parameters with default values. * * @return PvlFlatMap Algorithm parameters and their default values. */ PvlFlatMap BRISKAlgorithm::setupParameters() { PvlFlatMap variables; variables.add("Threshold", "30"); variables.add("NOctaves", "3"); variables.add("PatternScale", "1.0"); m_variables = variables; return (m_variables); } /** * Returns a description of the algorithm. * * @return @b QString A description of the algorithm. */ QString BRISKAlgorithm::description() const { QString desc = "The OpenCV BRISK Feature2D detector/extractor algorithm." " See the documentation at " "http://docs.opencv.org/3.1.0/de/dbf/classcv_1_1BRISK.html"; return (desc); } /** * Creates an instance of the algorithm. * * @param cvars The variables and values the algorithm will use. * Variables that are not included will be set to their default. * @param config The config string used to construct cvars. */ Feature2DAlgorithm *BRISKAlgorithm::create(const PvlFlatMap &vars, const QString &config) { return ( new BRISKAlgorithm(vars, config) ); } /** * Returns true if the algorithm has a detector. * * @return @b true if the algorithm has a detector. */ bool BRISKAlgorithm::hasDetector() const { return true; } /** * Returns true if the algorithm has an extractor. * * @return @b true if the algorithm has an extractor. */ bool BRISKAlgorithm::hasExtractor() const { return true; } /** * Returns true if the algorithm has a matcher. * * @return @b true if the algorithm has a matcher. */ bool BRISKAlgorithm::hasMatcher() const { return false; } /** * Returns the variables and their values used by the algorithm. * * @return @b PvlFlatMap The variables and their values as keyword, value pairs. */ PvlFlatMap BRISKAlgorithm::getAlgorithmVariables( ) const { return (variables()); } /** * @brief Set parameters as provided by the variables * * @param variables Container of parameters to set * * @return @b int Always -1, variables cannot be set after initialization. * * @throws IException::Programmer "BRISKAlgorithm does not have the ability * to set algorithm parameters." */ int BRISKAlgorithm::setAlgorithmVariables(const PvlFlatMap &variables) { QString msg = "BRISKAlgorithm does not have the ability to set algorithm parameters."; throw IException(IException::Programmer, msg, _FILEINFO_); return (-1); } }; // namespace Isis
[STATEMENT] lemma fut_terminate: "fut_invariant \<phi>\<Phi> \<Longrightarrow> \<not> fut_test \<phi>\<Phi> \<Longrightarrow> fut_spec \<phi>\<Phi>" [PROOF STATE] proof (prove) goal (1 subgoal): 1. \<lbrakk>fut_invariant \<phi>\<Phi>; \<not> (case \<phi>\<Phi> of (\<phi>, \<Phi>) \<Rightarrow> \<phi> \<notin> set \<Phi>)\<rbrakk> \<Longrightarrow> fut_spec \<phi>\<Phi> [PROOF STEP] proof (induct \<phi>\<Phi>, unfold prod.case not_not) [PROOF STATE] proof (state) goal (1 subgoal): 1. \<And>a b. \<lbrakk>fut_invariant (a, b); a \<in> set b\<rbrakk> \<Longrightarrow> fut_spec (a, b) [PROOF STEP] fix \<phi> \<Phi> [PROOF STATE] proof (state) goal (1 subgoal): 1. \<And>a b. \<lbrakk>fut_invariant (a, b); a \<in> set b\<rbrakk> \<Longrightarrow> fut_spec (a, b) [PROOF STEP] assume "fut_invariant (\<phi>, \<Phi>)" "\<phi> \<in> set \<Phi>" [PROOF STATE] proof (state) this: fut_invariant (\<phi>, \<Phi>) \<phi> \<in> set \<Phi> goal (1 subgoal): 1. \<And>a b. \<lbrakk>fut_invariant (a, b); a \<in> set b\<rbrakk> \<Longrightarrow> fut_spec (a, b) [PROOF STEP] then [PROOF STATE] proof (chain) picking this: fut_invariant (\<phi>, \<Phi>) \<phi> \<in> set \<Phi> [PROOF STEP] obtain i k where "i < k" and \<phi>_def: "\<phi> = fut_derivs i \<psi>" and \<Phi>_def: "\<Phi> = map (\<lambda>i. fut_derivs i \<psi>) (rev [0..<k])" and *: "fut_derivs k \<psi> = fut_derivs i \<psi>" [PROOF STATE] proof (prove) using this: fut_invariant (\<phi>, \<Phi>) \<phi> \<in> set \<Phi> goal (1 subgoal): 1. (\<And>i k. \<lbrakk>i < k; \<phi> = fut_derivs i \<psi>; \<Phi> = map (\<lambda>i. fut_derivs i \<psi>) (rev [0..<k]); fut_derivs k \<psi> = fut_derivs i \<psi>\<rbrakk> \<Longrightarrow> thesis) \<Longrightarrow> thesis [PROOF STEP] unfolding fut_invariant_def [PROOF STATE] proof (prove) using this: case (\<phi>, \<Phi>) of (\<phi>, \<Phi>) \<Rightarrow> local.wf idx \<phi> \<and> Ball (set \<Phi>) (local.wf idx) \<and> (\<exists>k. \<phi> = fut_derivs k \<psi> \<and> \<Phi> = map (\<lambda>i. fut_derivs i \<psi>) (rev [0..<k])) \<phi> \<in> set \<Phi> goal (1 subgoal): 1. (\<And>i k. \<lbrakk>i < k; \<phi> = fut_derivs i \<psi>; \<Phi> = map (\<lambda>i. fut_derivs i \<psi>) (rev [0..<k]); fut_derivs k \<psi> = fut_derivs i \<psi>\<rbrakk> \<Longrightarrow> thesis) \<Longrightarrow> thesis [PROOF STEP] by auto [PROOF STATE] proof (state) this: i < k \<phi> = fut_derivs i \<psi> \<Phi> = map (\<lambda>i. fut_derivs i \<psi>) (rev [0..<k]) fut_derivs k \<psi> = fut_derivs i \<psi> goal (1 subgoal): 1. \<And>a b. \<lbrakk>fut_invariant (a, b); a \<in> set b\<rbrakk> \<Longrightarrow> fut_spec (a, b) [PROOF STEP] have "set \<Phi> = {fut_derivs k \<psi> | k . True}" [PROOF STATE] proof (prove) goal (1 subgoal): 1. set \<Phi> = {fut_derivs k \<psi> |k. True} [PROOF STEP] unfolding \<Phi>_def set_map set_rev set_upt [PROOF STATE] proof (prove) goal (1 subgoal): 1. (\<lambda>i. fut_derivs i \<psi>) ` {0..<k} = {fut_derivs k \<psi> |k. True} [PROOF STEP] proof safe [PROOF STATE] proof (state) goal (2 subgoals): 1. \<And>x i. i \<in> {0..<k} \<Longrightarrow> \<exists>k. fut_derivs i \<psi> = fut_derivs k \<psi> \<and> True 2. \<And>x ka. True \<Longrightarrow> fut_derivs ka \<psi> \<in> (\<lambda>i. fut_derivs i \<psi>) ` {0..<k} [PROOF STEP] fix j [PROOF STATE] proof (state) goal (2 subgoals): 1. \<And>x i. i \<in> {0..<k} \<Longrightarrow> \<exists>k. fut_derivs i \<psi> = fut_derivs k \<psi> \<and> True 2. \<And>x ka. True \<Longrightarrow> fut_derivs ka \<psi> \<in> (\<lambda>i. fut_derivs i \<psi>) ` {0..<k} [PROOF STEP] show "fut_derivs j \<psi> \<in> (\<lambda>i. fut_derivs i \<psi>) ` {0..<k}" [PROOF STATE] proof (prove) goal (1 subgoal): 1. fut_derivs j \<psi> \<in> (\<lambda>i. fut_derivs i \<psi>) ` {0..<k} [PROOF STEP] proof (cases "j < k") [PROOF STATE] proof (state) goal (2 subgoals): 1. j < k \<Longrightarrow> fut_derivs j \<psi> \<in> (\<lambda>i. fut_derivs i \<psi>) ` {0..<k} 2. \<not> j < k \<Longrightarrow> fut_derivs j \<psi> \<in> (\<lambda>i. fut_derivs i \<psi>) ` {0..<k} [PROOF STEP] case False [PROOF STATE] proof (state) this: \<not> j < k goal (2 subgoals): 1. j < k \<Longrightarrow> fut_derivs j \<psi> \<in> (\<lambda>i. fut_derivs i \<psi>) ` {0..<k} 2. \<not> j < k \<Longrightarrow> fut_derivs j \<psi> \<in> (\<lambda>i. fut_derivs i \<psi>) ` {0..<k} [PROOF STEP] with * \<open>i < k\<close> [PROOF STATE] proof (chain) picking this: fut_derivs k \<psi> = fut_derivs i \<psi> i < k \<not> j < k [PROOF STEP] have "fut_derivs j \<psi> = fut_derivs ((j - i) mod (k - i) + i) \<psi>" [PROOF STATE] proof (prove) using this: fut_derivs k \<psi> = fut_derivs i \<psi> i < k \<not> j < k goal (1 subgoal): 1. fut_derivs j \<psi> = fut_derivs ((j - i) mod (k - i) + i) \<psi> [PROOF STEP] unfolding fut_derivs_def [PROOF STATE] proof (prove) using this: ((norm \<circ> rderiv (zero idx)) ^^ k) \<psi> = ((norm \<circ> rderiv (zero idx)) ^^ i) \<psi> i < k \<not> j < k goal (1 subgoal): 1. ((norm \<circ> rderiv (zero idx)) ^^ j) \<psi> = ((norm \<circ> rderiv (zero idx)) ^^ ((j - i) mod (k - i) + i)) \<psi> [PROOF STEP] by (auto intro: funpow_cycle_offset) [PROOF STATE] proof (state) this: fut_derivs j \<psi> = fut_derivs ((j - i) mod (k - i) + i) \<psi> goal (2 subgoals): 1. j < k \<Longrightarrow> fut_derivs j \<psi> \<in> (\<lambda>i. fut_derivs i \<psi>) ` {0..<k} 2. \<not> j < k \<Longrightarrow> fut_derivs j \<psi> \<in> (\<lambda>i. fut_derivs i \<psi>) ` {0..<k} [PROOF STEP] then [PROOF STATE] proof (chain) picking this: fut_derivs j \<psi> = fut_derivs ((j - i) mod (k - i) + i) \<psi> [PROOF STEP] show ?thesis [PROOF STATE] proof (prove) using this: fut_derivs j \<psi> = fut_derivs ((j - i) mod (k - i) + i) \<psi> goal (1 subgoal): 1. fut_derivs j \<psi> \<in> (\<lambda>i. fut_derivs i \<psi>) ` {0..<k} [PROOF STEP] using \<open>i < k\<close> \<open>\<not> j < k\<close> [PROOF STATE] proof (prove) using this: fut_derivs j \<psi> = fut_derivs ((j - i) mod (k - i) + i) \<psi> i < k \<not> j < k goal (1 subgoal): 1. fut_derivs j \<psi> \<in> (\<lambda>i. fut_derivs i \<psi>) ` {0..<k} [PROOF STEP] by (metis image_eqI atLeastLessThan_iff le0 less_diff_conv mod_less_divisor zero_less_diff) [PROOF STATE] proof (state) this: fut_derivs j \<psi> \<in> (\<lambda>i. fut_derivs i \<psi>) ` {0..<k} goal (1 subgoal): 1. j < k \<Longrightarrow> fut_derivs j \<psi> \<in> (\<lambda>i. fut_derivs i \<psi>) ` {0..<k} [PROOF STEP] qed simp [PROOF STATE] proof (state) this: fut_derivs j \<psi> \<in> (\<lambda>i. fut_derivs i \<psi>) ` {0..<k} goal (1 subgoal): 1. \<And>x i. i \<in> {0..<k} \<Longrightarrow> \<exists>k. fut_derivs i \<psi> = fut_derivs k \<psi> \<and> True [PROOF STEP] qed (blast intro: *) [PROOF STATE] proof (state) this: set \<Phi> = {fut_derivs k \<psi> |k. True} goal (1 subgoal): 1. \<And>a b. \<lbrakk>fut_invariant (a, b); a \<in> set b\<rbrakk> \<Longrightarrow> fut_spec (a, b) [PROOF STEP] then [PROOF STATE] proof (chain) picking this: set \<Phi> = {fut_derivs k \<psi> |k. True} [PROOF STEP] show "fut_spec (\<phi>, \<Phi>)" [PROOF STATE] proof (prove) using this: set \<Phi> = {fut_derivs k \<psi> |k. True} goal (1 subgoal): 1. fut_spec (\<phi>, \<Phi>) [PROOF STEP] unfolding fut_spec_def [PROOF STATE] proof (prove) using this: set \<Phi> = {fut_derivs k \<psi> |k. True} goal (1 subgoal): 1. (\<forall>\<phi>\<in>set (snd (\<phi>, \<Phi>)). local.wf idx \<phi>) \<and> (\<forall>\<AA>. #\<^sub>V \<AA> = idx \<longrightarrow> (if b then (\<exists>k. (SNOC (zero idx) ^^ k) \<AA> \<Turnstile>\<^sub>b \<psi>) = (\<exists>\<phi>\<in>set (snd (\<phi>, \<Phi>)). \<AA> \<Turnstile>\<^sub>b \<phi>) else (\<forall>k. (SNOC (zero idx) ^^ k) \<AA> \<Turnstile>\<^sub>b \<psi>) = (\<forall>\<phi>\<in>set (snd (\<phi>, \<Phi>)). \<AA> \<Turnstile>\<^sub>b \<phi>))) [PROOF STEP] using satisfies_bounded_fut_derivs [PROOF STATE] proof (prove) using this: set \<Phi> = {fut_derivs k \<psi> |k. True} #\<^sub>V ?\<AA> = idx \<Longrightarrow> (?\<AA> \<Turnstile>\<^sub>b fut_derivs ?k \<psi>) = ((SNOC (zero idx) ^^ ?k) ?\<AA> \<Turnstile>\<^sub>b \<psi>) goal (1 subgoal): 1. (\<forall>\<phi>\<in>set (snd (\<phi>, \<Phi>)). local.wf idx \<phi>) \<and> (\<forall>\<AA>. #\<^sub>V \<AA> = idx \<longrightarrow> (if b then (\<exists>k. (SNOC (zero idx) ^^ k) \<AA> \<Turnstile>\<^sub>b \<psi>) = (\<exists>\<phi>\<in>set (snd (\<phi>, \<Phi>)). \<AA> \<Turnstile>\<^sub>b \<phi>) else (\<forall>k. (SNOC (zero idx) ^^ k) \<AA> \<Turnstile>\<^sub>b \<psi>) = (\<forall>\<phi>\<in>set (snd (\<phi>, \<Phi>)). \<AA> \<Turnstile>\<^sub>b \<phi>))) [PROOF STEP] by (auto simp: wf_fut_derivs) [PROOF STATE] proof (state) this: fut_spec (\<phi>, \<Phi>) goal: No subgoals! [PROOF STEP] qed
/- Copyright (c) 2019 Chris Hughes. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Chris Hughes -/ import number_theory.zsqrtd.gaussian_int /-! # Sums of two squares Proof of Fermat's theorem on the sum of two squares. Every prime congruent to 1 mod 4 is the sum of two squares. # Todo Fully characterize the natural numbers that are the sum of two squares: those such that for every prime p congruent to 3 mod 4, the largest power of p dividing them is even. -/ open gaussian_int /-- **Fermat's theorem on the sum of two squares**. Every prime congruent to 1 mod 4 is the sum of two squares. Also known as **Fermat's Christmas theorem**. -/ lemma nat.prime.sq_add_sq {p : ℕ} [fact p.prime] (hp : p % 4 = 1) : ∃ a b : ℕ, a ^ 2 + b ^ 2 = p := begin apply sq_add_sq_of_nat_prime_of_not_irreducible p, rw [principal_ideal_ring.irreducible_iff_prime, prime_iff_mod_four_eq_three_of_nat_prime p, hp], norm_num end
module _ {A : Set} where postulate B : Set postulate H : {A : Set} → Set test-H : Set test-H = H {A = B} record R {A : Set} : Set where constructor rc field f : A test-R : Set test-R = R {A = B} test-f : ∀ B → R {A = B} → B test-f B = R.f {A = B} module N {A : Set} where module test-N = N {A = B}
module Issue160 where data Bool : Set where true : Bool false : Bool data _≡_ {A : Set}(x : A) : A → Set where refl : x ≡ x inj : ∀ {A} (f : A -> A) {a b : A} → f a ≡ f b -> a ≡ b inj f refl = refl absurd : true ≡ false absurd = inj (λ _ → true) refl
lemma complex_Im_of_int [simp]: "Im (of_int z) = 0"
IF (ALLOCATED(this%outer_index)) THEN DEALLOCATE(this%outer_index) END IF IF (ALLOCATED(this%inner_index)) THEN DEALLOCATE(this%inner_index) END IF IF (ALLOCATED(this%values)) THEN DEALLOCATE(this%values) END IF
/- Copyright (c) 2019 Jean Lo. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Jean Lo -/ import Mathlib.PrePort import Mathlib.Lean3Lib.init.default import Mathlib.topology.metric_space.hausdorff_distance import Mathlib.PostPort universes u_1 u_2 namespace Mathlib /-! # Riesz's lemma Riesz's lemma, stated for a normed space over a normed field: for any closed proper subspace F of E, there is a nonzero x such that ∥x - F∥ is at least r * ∥x∥ for any r < 1. -/ /-- Riesz's lemma, which usually states that it is possible to find a vector with norm 1 whose distance to a closed proper subspace is arbitrarily close to 1. The statement here is in terms of multiples of norms, since in general the existence of an element of norm exactly 1 is not guaranteed. -/ theorem riesz_lemma {𝕜 : Type u_1} [normed_field 𝕜] {E : Type u_2} [normed_group E] [normed_space 𝕜 E] {F : subspace 𝕜 E} (hFc : is_closed ↑F) (hF : ∃ (x : E), ¬x ∈ F) {r : ℝ} (hr : r < 1) : ∃ (x₀ : E), ¬x₀ ∈ F ∧ ∀ (y : E), y ∈ F → r * norm x₀ ≤ norm (x₀ - y) := sorry end Mathlib
{-# OPTIONS --without-K #-} module Types where open import Level using (_⊔_; Lift; lift; lower) public infix 1 _≡_ infixr 1 _⊎_ infixr 2 _×_ infix 3 ¬_ infixr 4 _,_ infixr 9 _∘_ -- The negative fragment. Π : ∀ {a b} (A : Set a) → (A → Set b) → Set _ Π A B = (x : A) → B x record Σ {a b} (A : Set a) (B : A → Set b) : Set (a ⊔ b) where constructor _,_ field π₁ : A π₂ : B π₁ open Σ public -- Projections are defined automatically. _×_ : ∀ {a b} → Set a → Set b → Set _ A × B = Σ A λ _ → B -- Unit type with definitional η. record ⊤ : Set where constructor tt id : ∀ {a} {A : Set a} → A → A id x = x _∘_ : ∀ {a b c} {A : Set a} {B : A → Set b} {C : ∀ a → B a → Set c} (f : ∀ {a} (b : B a) → C a b) (g : ∀ a → B a) → ∀ x → C x (g x) (f ∘ g) x = f (g x) -- The positive fragment. data ⊥ : Set where -- Ex falso quodlibet. 0-elim : ∀ {p} {P : Set p} → ⊥ → P 0-elim () ¬_ : ∀ {a} → Set a → Set a ¬ A = A → ⊥ -- Unit type without definitional η. data Unit : Set where tt : Unit 1-elim : ∀ {p} (P : Unit → Set p) → P tt → ∀ z → P z 1-elim P c tt = c data _⊎_ {a b} (A : Set a) (B : Set b) : Set (a ⊔ b) where inl : A → A ⊎ B inr : B → A ⊎ B -- Case analysis. case : ∀ {a b p} {A : Set a} {B : Set b} (P : A ⊎ B → Set p) (f : ∀ a → P (inl a)) (g : ∀ b → P (inr b)) → ∀ z → P z case P f g (inl a) = f a case P f g (inr b) = g b -- Simga as a positive type. data Σ′ {a b} (A : Set a) (B : A → Set b) : Set (a ⊔ b) where _,_ : (a : A) → B a → Σ′ A B split : ∀ {a b p} {A : Set a} {B : A → Set b} (P : Σ′ A B → Set p) (f : (a : A) (b : B a) → P (a , b)) → ∀ z → P z split P f (a , b) = f a b -- Natural numbers. data ℕ : Set where zero : ℕ suc : ℕ → ℕ {-# BUILTIN NATURAL ℕ #-} ind : ∀ {p} (P : ℕ → Set p) (s : ∀ n → P n → P (suc n)) (z : P zero) → ∀ z → P z ind P s z zero = z ind P s z (suc n) = s n (ind P s z n) -- Identity type. data _≡_ {a} {A : Set a} (x : A) : A → Set a where refl : x ≡ x -- When the type cannot be infered. Id : ∀ {a} (A : Set a) (x y : A) → Set _ Id _ x y = x ≡ y -- Path induction. J : ∀ {a p} {A : Set a} (P : ∀ (x : A) y → x ≡ y → Set p) (f : ∀ x → P x x refl) → ∀ x y → (p : x ≡ y) → P x y p J P f x .x refl = f x
/- Spatial Reasoning Problem 04 -/ /- it can be found at: SpatialQs.txt -/ /- (4) John is carrying a vase. There is a flower in the vase. Is John carrying a flower?-/ constant U : Type constants John Inside Carrying Flower Container Transfer On : U constant objectTransferred : U → U → Prop constant orientation : U → U → U → Prop constant subclass : U → U → Prop constant agent : U → U → Prop constant ins : U → U → Prop /- axioms from SUMO -/ axiom a1 : ∀ VAR1 VAR2 VAR3, (orientation VAR2 VAR1 Inside) ∧ (objectTransferred VAR3 VAR1) ∧ (ins VAR3 Transfer) → (objectTransferred VAR3 VAR2) axiom a2 : subclass Carrying Transfer axiom a3 : ∀ X Y Z, (subclass X Y) ∧ (ins Z X) → (ins Z Y) /- axioms from problem -/ axiom a4 : ∃ C V F, (ins C Carrying) ∧ (objectTransferred C V) ∧ (agent C John) ∧ (ins F Flower) ∧ (ins V Container) ∧ (orientation F V Inside) /- axioms to be added to SUMO -/ axiom a5 : ∀ T O O2, (ins T Transfer) ∧ (objectTransferred T O) ∧ (orientation O2 O Inside) → (objectTransferred T O2) axiom a6 : ∀ T O O2, (ins T Transfer) ∧ (objectTransferred T O) ∧ (orientation O O2 On) → (objectTransferred T O2) /- demonstration start -/ theorem john_is_carrying_a_flower : ∃ C F, (ins C Carrying) ∧ (agent C John) ∧ (ins F Flower) ∧ (objectTransferred C F) := begin apply exists.elim a4, assume C r1, apply exists.elim r1, assume V r2, apply exists.elim r2, assume F h, have h1, from h.left, have h2, from h.right.right.left, have h3, from h.right.right.right.left, have s1, from (a3 _ _ _) ⟨a2,h1⟩, have s2, from h.right.left, have s3, from h.right.right.right.right.right, have h4, from (a5 _ _ _) ⟨s1,⟨s2,s3⟩⟩, have h5 : ∃ F, ins C Carrying ∧ agent C John ∧ ins F Flower ∧ objectTransferred C F, from exists.intro F ⟨h1,⟨h2,⟨h3,h4⟩⟩⟩, have h6 : ∃ C F, ins C Carrying ∧ agent C John ∧ ins F Flower ∧ objectTransferred C F, from exists.intro C h5, assumption end
function [cov] = mne_read_noise_cov(fname) % % [cov] = mne_read_noise_cov(fname) % % Reads a noise-covariance matrix from a fiff file % % fname - The name of the file % % % % % Author : Matti Hamalainen, MGH Martinos Center % License : BSD 3-clause % % Revision 1.5 2006/05/03 19:09:03 msh % Fixed even more compatibility issues. % % Revision 1.4 2006/04/23 15:29:41 msh % Added MGH to the copyright % % Revision 1.3 2006/04/20 21:49:38 msh % Added mne_read_inverse_operator % Changed some of the routines accordingly for more flexibility. % % Revision 1.2 2006/04/18 20:44:46 msh % Added reading of forward solution. % Use length instead of size when appropriate % % Revision 1.1 2006/04/12 17:09:28 msh % Added routines for reading noise-covariance matrices % % me='MNE:mne_read_noise_cov'; global FIFF; if isempty(FIFF) FIFF = fiff_define_constants(); end % % Open the file, create directory % [ fid, tree ] = fiff_open(fname); try cov = mne_read_cov(fid,tree,FIFF.FIFFV_MNE_NOISE_COV); catch fclose(fid); error(me,'%s',mne_omit_first_line(lasterr)); end return; end
[GOAL] G : Type u_1 inst✝ : CommGroup G sets : Set (Set G) nonempty : Set.Nonempty sets inter_sets : ∀ (x y : Set G), x ∈ sets → y ∈ sets → ∃ z, z ∈ sets ∧ z ⊆ x ∩ y one : ∀ (U : Set G), U ∈ sets → 1 ∈ U mul : ∀ (U : Set G), U ∈ sets → ∃ V, V ∈ sets ∧ V * V ⊆ U inv : ∀ (U : Set G), U ∈ sets → ∃ V, V ∈ sets ∧ V ⊆ (fun x => x⁻¹) ⁻¹' U x : G U : Set G U_in : U ∈ { sets := sets, nonempty := nonempty, inter_sets := (_ : ∀ {x y : Set G}, x ∈ sets → y ∈ sets → ∃ z, z ∈ sets ∧ z ⊆ x ∩ y) }.sets ⊢ U ⊆ (fun x_1 => x * x_1 * x⁻¹) ⁻¹' U [PROOFSTEP] simp only [mul_inv_cancel_comm, preimage_id'] [GOAL] G : Type u_1 inst✝ : CommGroup G sets : Set (Set G) nonempty : Set.Nonempty sets inter_sets : ∀ (x y : Set G), x ∈ sets → y ∈ sets → ∃ z, z ∈ sets ∧ z ⊆ x ∩ y one : ∀ (U : Set G), U ∈ sets → 1 ∈ U mul : ∀ (U : Set G), U ∈ sets → ∃ V, V ∈ sets ∧ V * V ⊆ U inv : ∀ (U : Set G), U ∈ sets → ∃ V, V ∈ sets ∧ V ⊆ (fun x => x⁻¹) ⁻¹' U x : G U : Set G U_in : U ∈ { sets := sets, nonempty := nonempty, inter_sets := (_ : ∀ {x y : Set G}, x ∈ sets → y ∈ sets → ∃ z, z ∈ sets ∧ z ⊆ x ∩ y) }.sets ⊢ U ⊆ U [PROOFSTEP] rfl [GOAL] G : Type u inst✝ : Group G B : GroupFilterBasis G ⊢ GroupFilterBasis G [PROOFSTEP] refine' { sets := {{1}} nonempty := singleton_nonempty _ .. } [GOAL] case refine'_1 G : Type u inst✝ : Group G B : GroupFilterBasis G ⊢ ∀ {x y : Set G}, x ∈ {{1}} → y ∈ {{1}} → ∃ z, z ∈ {{1}} ∧ z ⊆ x ∩ y case refine'_2 G : Type u inst✝ : Group G B : GroupFilterBasis G ⊢ ∀ {U : Set G}, U ∈ { sets := {{1}}, nonempty := (_ : Set.Nonempty {{1}}), inter_sets := ?refine'_1 }.sets → 1 ∈ U case refine'_3 G : Type u inst✝ : Group G B : GroupFilterBasis G ⊢ ∀ {U : Set G}, U ∈ { sets := {{1}}, nonempty := (_ : Set.Nonempty {{1}}), inter_sets := ?refine'_1 }.sets → ∃ V, V ∈ { sets := {{1}}, nonempty := (_ : Set.Nonempty {{1}}), inter_sets := ?refine'_1 }.sets ∧ V * V ⊆ U case refine'_4 G : Type u inst✝ : Group G B : GroupFilterBasis G ⊢ ∀ {U : Set G}, U ∈ { sets := {{1}}, nonempty := (_ : Set.Nonempty {{1}}), inter_sets := ?refine'_1 }.sets → ∃ V, V ∈ { sets := {{1}}, nonempty := (_ : Set.Nonempty {{1}}), inter_sets := ?refine'_1 }.sets ∧ V ⊆ (fun x => x⁻¹) ⁻¹' U case refine'_5 G : Type u inst✝ : Group G B : GroupFilterBasis G ⊢ ∀ (x₀ : G) {U : Set G}, U ∈ { sets := {{1}}, nonempty := (_ : Set.Nonempty {{1}}), inter_sets := ?refine'_1 }.sets → ∃ V, V ∈ { sets := {{1}}, nonempty := (_ : Set.Nonempty {{1}}), inter_sets := ?refine'_1 }.sets ∧ V ⊆ (fun x => x₀ * x * x₀⁻¹) ⁻¹' U [PROOFSTEP] all_goals simp only [exists_prop, mem_singleton_iff] [GOAL] case refine'_1 G : Type u inst✝ : Group G B : GroupFilterBasis G ⊢ ∀ {x y : Set G}, x ∈ {{1}} → y ∈ {{1}} → ∃ z, z ∈ {{1}} ∧ z ⊆ x ∩ y [PROOFSTEP] simp only [exists_prop, mem_singleton_iff] [GOAL] case refine'_2 G : Type u inst✝ : Group G B : GroupFilterBasis G ⊢ ∀ {U : Set G}, U ∈ { sets := {{1}}, nonempty := (_ : Set.Nonempty {{1}}), inter_sets := (_ : ∀ {x y : Set G}, x ∈ {{1}} → y ∈ {{1}} → ∃ z, z ∈ {{1}} ∧ z ⊆ x ∩ y) }.sets → 1 ∈ U [PROOFSTEP] simp only [exists_prop, mem_singleton_iff] [GOAL] case refine'_3 G : Type u inst✝ : Group G B : GroupFilterBasis G ⊢ ∀ {U : Set G}, U ∈ { sets := {{1}}, nonempty := (_ : Set.Nonempty {{1}}), inter_sets := (_ : ∀ {x y : Set G}, x ∈ {{1}} → y ∈ {{1}} → ∃ z, z ∈ {{1}} ∧ z ⊆ x ∩ y) }.sets → ∃ V, V ∈ { sets := {{1}}, nonempty := (_ : Set.Nonempty {{1}}), inter_sets := (_ : ∀ {x y : Set G}, x ∈ {{1}} → y ∈ {{1}} → ∃ z, z ∈ {{1}} ∧ z ⊆ x ∩ y) }.sets ∧ V * V ⊆ U [PROOFSTEP] simp only [exists_prop, mem_singleton_iff] [GOAL] case refine'_4 G : Type u inst✝ : Group G B : GroupFilterBasis G ⊢ ∀ {U : Set G}, U ∈ { sets := {{1}}, nonempty := (_ : Set.Nonempty {{1}}), inter_sets := (_ : ∀ {x y : Set G}, x ∈ {{1}} → y ∈ {{1}} → ∃ z, z ∈ {{1}} ∧ z ⊆ x ∩ y) }.sets → ∃ V, V ∈ { sets := {{1}}, nonempty := (_ : Set.Nonempty {{1}}), inter_sets := (_ : ∀ {x y : Set G}, x ∈ {{1}} → y ∈ {{1}} → ∃ z, z ∈ {{1}} ∧ z ⊆ x ∩ y) }.sets ∧ V ⊆ (fun x => x⁻¹) ⁻¹' U [PROOFSTEP] simp only [exists_prop, mem_singleton_iff] [GOAL] case refine'_5 G : Type u inst✝ : Group G B : GroupFilterBasis G ⊢ ∀ (x₀ : G) {U : Set G}, U ∈ { sets := {{1}}, nonempty := (_ : Set.Nonempty {{1}}), inter_sets := (_ : ∀ {x y : Set G}, x ∈ {{1}} → y ∈ {{1}} → ∃ z, z ∈ {{1}} ∧ z ⊆ x ∩ y) }.sets → ∃ V, V ∈ { sets := {{1}}, nonempty := (_ : Set.Nonempty {{1}}), inter_sets := (_ : ∀ {x y : Set G}, x ∈ {{1}} → y ∈ {{1}} → ∃ z, z ∈ {{1}} ∧ z ⊆ x ∩ y) }.sets ∧ V ⊆ (fun x => x₀ * x * x₀⁻¹) ⁻¹' U [PROOFSTEP] simp only [exists_prop, mem_singleton_iff] [GOAL] case refine'_1 G : Type u inst✝ : Group G B : GroupFilterBasis G ⊢ ∀ {x y : Set G}, x = {1} → y = {1} → ∃ z, z = {1} ∧ z ⊆ x ∩ y [PROOFSTEP] rintro - - rfl rfl [GOAL] case refine'_1 G : Type u inst✝ : Group G B : GroupFilterBasis G ⊢ ∃ z, z = {1} ∧ z ⊆ {1} ∩ {1} [PROOFSTEP] use{1} [GOAL] case h G : Type u inst✝ : Group G B : GroupFilterBasis G ⊢ {1} = {1} ∧ {1} ⊆ {1} ∩ {1} [PROOFSTEP] simp [GOAL] case refine'_2 G : Type u inst✝ : Group G B : GroupFilterBasis G ⊢ ∀ {U : Set G}, U = {1} → 1 ∈ U [PROOFSTEP] simp [GOAL] case refine'_3 G : Type u inst✝ : Group G B : GroupFilterBasis G ⊢ ∀ {U : Set G}, U = {1} → ∃ V, V = {1} ∧ V * V ⊆ U [PROOFSTEP] rintro - rfl [GOAL] case refine'_3 G : Type u inst✝ : Group G B : GroupFilterBasis G ⊢ ∃ V, V = {1} ∧ V * V ⊆ {1} [PROOFSTEP] use{1} [GOAL] case h G : Type u inst✝ : Group G B : GroupFilterBasis G ⊢ {1} = {1} ∧ {1} * {1} ⊆ {1} [PROOFSTEP] simp [GOAL] case refine'_4 G : Type u inst✝ : Group G B : GroupFilterBasis G ⊢ ∀ {U : Set G}, U = {1} → ∃ V, V = {1} ∧ V ⊆ (fun x => x⁻¹) ⁻¹' U [PROOFSTEP] rintro - rfl [GOAL] case refine'_4 G : Type u inst✝ : Group G B : GroupFilterBasis G ⊢ ∃ V, V = {1} ∧ V ⊆ (fun x => x⁻¹) ⁻¹' {1} [PROOFSTEP] use{1} [GOAL] case h G : Type u inst✝ : Group G B : GroupFilterBasis G ⊢ {1} = {1} ∧ {1} ⊆ (fun x => x⁻¹) ⁻¹' {1} [PROOFSTEP] simp [GOAL] case refine'_5 G : Type u inst✝ : Group G B : GroupFilterBasis G ⊢ ∀ (x₀ : G) {U : Set G}, U = {1} → ∃ V, V = {1} ∧ V ⊆ (fun x => x₀ * x * x₀⁻¹) ⁻¹' U [PROOFSTEP] rintro x₀ - rfl [GOAL] case refine'_5 G : Type u inst✝ : Group G B : GroupFilterBasis G x₀ : G ⊢ ∃ V, V = {1} ∧ V ⊆ (fun x => x₀ * x * x₀⁻¹) ⁻¹' {1} [PROOFSTEP] use{1} [GOAL] case h G : Type u inst✝ : Group G B : GroupFilterBasis G x₀ : G ⊢ {1} = {1} ∧ {1} ⊆ (fun x => x₀ * x * x₀⁻¹) ⁻¹' {1} [PROOFSTEP] simp [GOAL] G : Type u inst✝ : Group G B✝ B : GroupFilterBasis G ⊢ N B 1 = FilterBasis.filter toFilterBasis [PROOFSTEP] simp only [N, one_mul, map_id'] [GOAL] G : Type u inst✝ : Group G B✝ B : GroupFilterBasis G x₀ : G ⊢ 𝓝 x₀ = N B x₀ [PROOFSTEP] rw [TopologicalSpace.nhds_mkOfNhds] [GOAL] case h₀ G : Type u inst✝ : Group G B✝ B : GroupFilterBasis G x₀ : G ⊢ pure ≤ N B [PROOFSTEP] intro x U U_in [GOAL] case h₀ G : Type u inst✝ : Group G B✝ B : GroupFilterBasis G x₀ x : G U : Set G U_in : U ∈ N B x ⊢ U ∈ pure x [PROOFSTEP] rw [(B.hasBasis x).mem_iff] at U_in [GOAL] case h₀ G : Type u inst✝ : Group G B✝ B : GroupFilterBasis G x₀ x : G U : Set G U_in : ∃ i, i ∈ B ∧ (fun y => x * y) '' i ⊆ U ⊢ U ∈ pure x [PROOFSTEP] rcases U_in with ⟨V, V_in, H⟩ [GOAL] case h₀.intro.intro G : Type u inst✝ : Group G B✝ B : GroupFilterBasis G x₀ x : G U V : Set G V_in : V ∈ B H : (fun y => x * y) '' V ⊆ U ⊢ U ∈ pure x [PROOFSTEP] simpa [mem_pure] using H (mem_image_of_mem _ (GroupFilterBasis.one V_in)) [GOAL] case h₁ G : Type u inst✝ : Group G B✝ B : GroupFilterBasis G x₀ : G ⊢ ∀ (a : G) (s : Set G), s ∈ N B a → ∃ t, t ∈ N B a ∧ t ⊆ s ∧ ∀ (a' : G), a' ∈ t → s ∈ N B a' [PROOFSTEP] intro x U U_in [GOAL] case h₁ G : Type u inst✝ : Group G B✝ B : GroupFilterBasis G x₀ x : G U : Set G U_in : U ∈ N B x ⊢ ∃ t, t ∈ N B x ∧ t ⊆ U ∧ ∀ (a' : G), a' ∈ t → U ∈ N B a' [PROOFSTEP] rw [(B.hasBasis x).mem_iff] at U_in [GOAL] case h₁ G : Type u inst✝ : Group G B✝ B : GroupFilterBasis G x₀ x : G U : Set G U_in : ∃ i, i ∈ B ∧ (fun y => x * y) '' i ⊆ U ⊢ ∃ t, t ∈ N B x ∧ t ⊆ U ∧ ∀ (a' : G), a' ∈ t → U ∈ N B a' [PROOFSTEP] rcases U_in with ⟨V, V_in, H⟩ [GOAL] case h₁.intro.intro G : Type u inst✝ : Group G B✝ B : GroupFilterBasis G x₀ x : G U V : Set G V_in : V ∈ B H : (fun y => x * y) '' V ⊆ U ⊢ ∃ t, t ∈ N B x ∧ t ⊆ U ∧ ∀ (a' : G), a' ∈ t → U ∈ N B a' [PROOFSTEP] rcases GroupFilterBasis.mul V_in with ⟨W, W_in, hW⟩ [GOAL] case h₁.intro.intro.intro.intro G : Type u inst✝ : Group G B✝ B : GroupFilterBasis G x₀ x : G U V : Set G V_in : V ∈ B H : (fun y => x * y) '' V ⊆ U W : Set G W_in : W ∈ B hW : W * W ⊆ V ⊢ ∃ t, t ∈ N B x ∧ t ⊆ U ∧ ∀ (a' : G), a' ∈ t → U ∈ N B a' [PROOFSTEP] use(fun y ↦ x * y) '' W, image_mem_map (FilterBasis.mem_filter_of_mem _ W_in) [GOAL] case right G : Type u inst✝ : Group G B✝ B : GroupFilterBasis G x₀ x : G U V : Set G V_in : V ∈ B H : (fun y => x * y) '' V ⊆ U W : Set G W_in : W ∈ B hW : W * W ⊆ V ⊢ (fun y => x * y) '' W ⊆ U ∧ ∀ (a' : G), a' ∈ (fun y => x * y) '' W → U ∈ N B a' [PROOFSTEP] constructor [GOAL] case right.left G : Type u inst✝ : Group G B✝ B : GroupFilterBasis G x₀ x : G U V : Set G V_in : V ∈ B H : (fun y => x * y) '' V ⊆ U W : Set G W_in : W ∈ B hW : W * W ⊆ V ⊢ (fun y => x * y) '' W ⊆ U [PROOFSTEP] rw [image_subset_iff] at H ⊢ [GOAL] case right.left G : Type u inst✝ : Group G B✝ B : GroupFilterBasis G x₀ x : G U V : Set G V_in : V ∈ B H : V ⊆ (fun y => x * y) ⁻¹' U W : Set G W_in : W ∈ B hW : W * W ⊆ V ⊢ W ⊆ (fun y => x * y) ⁻¹' U [PROOFSTEP] exact ((B.prod_subset_self W_in).trans hW).trans H [GOAL] case right.right G : Type u inst✝ : Group G B✝ B : GroupFilterBasis G x₀ x : G U V : Set G V_in : V ∈ B H : (fun y => x * y) '' V ⊆ U W : Set G W_in : W ∈ B hW : W * W ⊆ V ⊢ ∀ (a' : G), a' ∈ (fun y => x * y) '' W → U ∈ N B a' [PROOFSTEP] rintro y ⟨t, tW, rfl⟩ [GOAL] case right.right.intro.intro G : Type u inst✝ : Group G B✝ B : GroupFilterBasis G x₀ x : G U V : Set G V_in : V ∈ B H : (fun y => x * y) '' V ⊆ U W : Set G W_in : W ∈ B hW : W * W ⊆ V t : G tW : t ∈ W ⊢ U ∈ N B ((fun y => x * y) t) [PROOFSTEP] rw [(B.hasBasis _).mem_iff] [GOAL] case right.right.intro.intro G : Type u inst✝ : Group G B✝ B : GroupFilterBasis G x₀ x : G U V : Set G V_in : V ∈ B H : (fun y => x * y) '' V ⊆ U W : Set G W_in : W ∈ B hW : W * W ⊆ V t : G tW : t ∈ W ⊢ ∃ i, i ∈ B ∧ (fun y => (fun y => x * y) t * y) '' i ⊆ U [PROOFSTEP] use W, W_in [GOAL] case right G : Type u inst✝ : Group G B✝ B : GroupFilterBasis G x₀ x : G U V : Set G V_in : V ∈ B H : (fun y => x * y) '' V ⊆ U W : Set G W_in : W ∈ B hW : W * W ⊆ V t : G tW : t ∈ W ⊢ (fun y => (fun y => x * y) t * y) '' W ⊆ U [PROOFSTEP] apply Subset.trans _ H [GOAL] G : Type u inst✝ : Group G B✝ B : GroupFilterBasis G x₀ x : G U V : Set G V_in : V ∈ B H : (fun y => x * y) '' V ⊆ U W : Set G W_in : W ∈ B hW : W * W ⊆ V t : G tW : t ∈ W ⊢ (fun y => (fun y => x * y) t * y) '' W ⊆ (fun y => x * y) '' V [PROOFSTEP] clear H [GOAL] G : Type u inst✝ : Group G B✝ B : GroupFilterBasis G x₀ x : G U V : Set G V_in : V ∈ B W : Set G W_in : W ∈ B hW : W * W ⊆ V t : G tW : t ∈ W ⊢ (fun y => (fun y => x * y) t * y) '' W ⊆ (fun y => x * y) '' V [PROOFSTEP] rintro z ⟨w, wW, rfl⟩ [GOAL] case intro.intro G : Type u inst✝ : Group G B✝ B : GroupFilterBasis G x₀ x : G U V : Set G V_in : V ∈ B W : Set G W_in : W ∈ B hW : W * W ⊆ V t : G tW : t ∈ W w : G wW : w ∈ W ⊢ (fun y => (fun y => x * y) t * y) w ∈ (fun y => x * y) '' V [PROOFSTEP] exact ⟨t * w, hW (mul_mem_mul tW wW), by simp [mul_assoc]⟩ [GOAL] G : Type u inst✝ : Group G B✝ B : GroupFilterBasis G x₀ x : G U V : Set G V_in : V ∈ B W : Set G W_in : W ∈ B hW : W * W ⊆ V t : G tW : t ∈ W w : G wW : w ∈ W ⊢ (fun y => x * y) (t * w) = (fun y => (fun y => x * y) t * y) w [PROOFSTEP] simp [mul_assoc] [GOAL] G : Type u inst✝ : Group G B✝ B : GroupFilterBasis G ⊢ 𝓝 1 = FilterBasis.filter toFilterBasis [PROOFSTEP] rw [B.nhds_eq] [GOAL] G : Type u inst✝ : Group G B✝ B : GroupFilterBasis G ⊢ N B 1 = FilterBasis.filter toFilterBasis [PROOFSTEP] simp only [N, one_mul] [GOAL] G : Type u inst✝ : Group G B✝ B : GroupFilterBasis G ⊢ map (fun y => y) (FilterBasis.filter toFilterBasis) = FilterBasis.filter toFilterBasis [PROOFSTEP] exact map_id [GOAL] G : Type u inst✝ : Group G B✝ B : GroupFilterBasis G x₀ : G ⊢ HasBasis (𝓝 x₀) (fun V => V ∈ B) fun V => (fun y => x₀ * y) '' V [PROOFSTEP] rw [B.nhds_eq] [GOAL] G : Type u inst✝ : Group G B✝ B : GroupFilterBasis G x₀ : G ⊢ HasBasis (N B x₀) (fun V => V ∈ B) fun V => (fun y => x₀ * y) '' V [PROOFSTEP] apply B.hasBasis [GOAL] G : Type u inst✝ : Group G B✝ B : GroupFilterBasis G ⊢ HasBasis (𝓝 1) (fun V => V ∈ B) id [PROOFSTEP] rw [B.nhds_one_eq] [GOAL] G : Type u inst✝ : Group G B✝ B : GroupFilterBasis G ⊢ HasBasis (FilterBasis.filter toFilterBasis) (fun V => V ∈ B) id [PROOFSTEP] exact B.toFilterBasis.hasBasis [GOAL] G : Type u inst✝ : Group G B✝ B : GroupFilterBasis G U : Set G hU : U ∈ B ⊢ U ∈ 𝓝 1 [PROOFSTEP] rw [B.nhds_one_hasBasis.mem_iff] [GOAL] G : Type u inst✝ : Group G B✝ B : GroupFilterBasis G U : Set G hU : U ∈ B ⊢ ∃ i, i ∈ B ∧ id i ⊆ U [PROOFSTEP] exact ⟨U, hU, rfl.subset⟩ [GOAL] G : Type u inst✝ : Group G B✝ B : GroupFilterBasis G ⊢ TopologicalGroup G [PROOFSTEP] letI := B.topology [GOAL] G : Type u inst✝ : Group G B✝ B : GroupFilterBasis G this : TopologicalSpace G := topology B ⊢ TopologicalGroup G [PROOFSTEP] have basis := B.nhds_one_hasBasis [GOAL] G : Type u inst✝ : Group G B✝ B : GroupFilterBasis G this : TopologicalSpace G := topology B basis : HasBasis (𝓝 1) (fun V => V ∈ B) id ⊢ TopologicalGroup G [PROOFSTEP] have basis' := basis.prod basis [GOAL] G : Type u inst✝ : Group G B✝ B : GroupFilterBasis G this : TopologicalSpace G := topology B basis : HasBasis (𝓝 1) (fun V => V ∈ B) id basis' : HasBasis (𝓝 1 ×ˢ 𝓝 1) (fun i => i.fst ∈ B ∧ i.snd ∈ B) fun i => id i.fst ×ˢ id i.snd ⊢ TopologicalGroup G [PROOFSTEP] refine' TopologicalGroup.of_nhds_one _ _ _ _ [GOAL] case refine'_1 G : Type u inst✝ : Group G B✝ B : GroupFilterBasis G this : TopologicalSpace G := topology B basis : HasBasis (𝓝 1) (fun V => V ∈ B) id basis' : HasBasis (𝓝 1 ×ˢ 𝓝 1) (fun i => i.fst ∈ B ∧ i.snd ∈ B) fun i => id i.fst ×ˢ id i.snd ⊢ Tendsto (uncurry fun x x_1 => x * x_1) (𝓝 1 ×ˢ 𝓝 1) (𝓝 1) [PROOFSTEP] rw [basis'.tendsto_iff basis] [GOAL] case refine'_1 G : Type u inst✝ : Group G B✝ B : GroupFilterBasis G this : TopologicalSpace G := topology B basis : HasBasis (𝓝 1) (fun V => V ∈ B) id basis' : HasBasis (𝓝 1 ×ˢ 𝓝 1) (fun i => i.fst ∈ B ∧ i.snd ∈ B) fun i => id i.fst ×ˢ id i.snd ⊢ ∀ (ib : Set G), ib ∈ B → ∃ ia, (ia.fst ∈ B ∧ ia.snd ∈ B) ∧ ∀ (x : G × G), x ∈ id ia.fst ×ˢ id ia.snd → uncurry (fun x x_1 => x * x_1) x ∈ id ib [PROOFSTEP] suffices ∀ U ∈ B, ∃ V W, (V ∈ B ∧ W ∈ B) ∧ ∀ a b, a ∈ V → b ∈ W → a * b ∈ U by simpa [GOAL] G : Type u inst✝ : Group G B✝ B : GroupFilterBasis G this✝ : TopologicalSpace G := topology B basis : HasBasis (𝓝 1) (fun V => V ∈ B) id basis' : HasBasis (𝓝 1 ×ˢ 𝓝 1) (fun i => i.fst ∈ B ∧ i.snd ∈ B) fun i => id i.fst ×ˢ id i.snd this : ∀ (U : Set G), U ∈ B → ∃ V W, (V ∈ B ∧ W ∈ B) ∧ ∀ (a b : G), a ∈ V → b ∈ W → a * b ∈ U ⊢ ∀ (ib : Set G), ib ∈ B → ∃ ia, (ia.fst ∈ B ∧ ia.snd ∈ B) ∧ ∀ (x : G × G), x ∈ id ia.fst ×ˢ id ia.snd → uncurry (fun x x_1 => x * x_1) x ∈ id ib [PROOFSTEP] simpa [GOAL] case refine'_1 G : Type u inst✝ : Group G B✝ B : GroupFilterBasis G this : TopologicalSpace G := topology B basis : HasBasis (𝓝 1) (fun V => V ∈ B) id basis' : HasBasis (𝓝 1 ×ˢ 𝓝 1) (fun i => i.fst ∈ B ∧ i.snd ∈ B) fun i => id i.fst ×ˢ id i.snd ⊢ ∀ (U : Set G), U ∈ B → ∃ V W, (V ∈ B ∧ W ∈ B) ∧ ∀ (a b : G), a ∈ V → b ∈ W → a * b ∈ U [PROOFSTEP] intro U U_in [GOAL] case refine'_1 G : Type u inst✝ : Group G B✝ B : GroupFilterBasis G this : TopologicalSpace G := topology B basis : HasBasis (𝓝 1) (fun V => V ∈ B) id basis' : HasBasis (𝓝 1 ×ˢ 𝓝 1) (fun i => i.fst ∈ B ∧ i.snd ∈ B) fun i => id i.fst ×ˢ id i.snd U : Set G U_in : U ∈ B ⊢ ∃ V W, (V ∈ B ∧ W ∈ B) ∧ ∀ (a b : G), a ∈ V → b ∈ W → a * b ∈ U [PROOFSTEP] rcases mul U_in with ⟨V, V_in, hV⟩ [GOAL] case refine'_1.intro.intro G : Type u inst✝ : Group G B✝ B : GroupFilterBasis G this : TopologicalSpace G := topology B basis : HasBasis (𝓝 1) (fun V => V ∈ B) id basis' : HasBasis (𝓝 1 ×ˢ 𝓝 1) (fun i => i.fst ∈ B ∧ i.snd ∈ B) fun i => id i.fst ×ˢ id i.snd U : Set G U_in : U ∈ B V : Set G V_in : V ∈ B hV : V * V ⊆ U ⊢ ∃ V W, (V ∈ B ∧ W ∈ B) ∧ ∀ (a b : G), a ∈ V → b ∈ W → a * b ∈ U [PROOFSTEP] refine' ⟨V, V, ⟨V_in, V_in⟩, _⟩ [GOAL] case refine'_1.intro.intro G : Type u inst✝ : Group G B✝ B : GroupFilterBasis G this : TopologicalSpace G := topology B basis : HasBasis (𝓝 1) (fun V => V ∈ B) id basis' : HasBasis (𝓝 1 ×ˢ 𝓝 1) (fun i => i.fst ∈ B ∧ i.snd ∈ B) fun i => id i.fst ×ˢ id i.snd U : Set G U_in : U ∈ B V : Set G V_in : V ∈ B hV : V * V ⊆ U ⊢ ∀ (a b : G), a ∈ V → b ∈ V → a * b ∈ U [PROOFSTEP] intro a b a_in b_in [GOAL] case refine'_1.intro.intro G : Type u inst✝ : Group G B✝ B : GroupFilterBasis G this : TopologicalSpace G := topology B basis : HasBasis (𝓝 1) (fun V => V ∈ B) id basis' : HasBasis (𝓝 1 ×ˢ 𝓝 1) (fun i => i.fst ∈ B ∧ i.snd ∈ B) fun i => id i.fst ×ˢ id i.snd U : Set G U_in : U ∈ B V : Set G V_in : V ∈ B hV : V * V ⊆ U a b : G a_in : a ∈ V b_in : b ∈ V ⊢ a * b ∈ U [PROOFSTEP] exact hV ⟨a, b, a_in, b_in, rfl⟩ [GOAL] case refine'_2 G : Type u inst✝ : Group G B✝ B : GroupFilterBasis G this : TopologicalSpace G := topology B basis : HasBasis (𝓝 1) (fun V => V ∈ B) id basis' : HasBasis (𝓝 1 ×ˢ 𝓝 1) (fun i => i.fst ∈ B ∧ i.snd ∈ B) fun i => id i.fst ×ˢ id i.snd ⊢ Tendsto (fun x => x⁻¹) (𝓝 1) (𝓝 1) [PROOFSTEP] rw [basis.tendsto_iff basis] [GOAL] case refine'_2 G : Type u inst✝ : Group G B✝ B : GroupFilterBasis G this : TopologicalSpace G := topology B basis : HasBasis (𝓝 1) (fun V => V ∈ B) id basis' : HasBasis (𝓝 1 ×ˢ 𝓝 1) (fun i => i.fst ∈ B ∧ i.snd ∈ B) fun i => id i.fst ×ˢ id i.snd ⊢ ∀ (ib : Set G), ib ∈ B → ∃ ia, ia ∈ B ∧ ∀ (x : G), x ∈ id ia → x⁻¹ ∈ id ib [PROOFSTEP] intro U U_in [GOAL] case refine'_2 G : Type u inst✝ : Group G B✝ B : GroupFilterBasis G this : TopologicalSpace G := topology B basis : HasBasis (𝓝 1) (fun V => V ∈ B) id basis' : HasBasis (𝓝 1 ×ˢ 𝓝 1) (fun i => i.fst ∈ B ∧ i.snd ∈ B) fun i => id i.fst ×ˢ id i.snd U : Set G U_in : U ∈ B ⊢ ∃ ia, ia ∈ B ∧ ∀ (x : G), x ∈ id ia → x⁻¹ ∈ id U [PROOFSTEP] simpa using inv U_in [GOAL] case refine'_3 G : Type u inst✝ : Group G B✝ B : GroupFilterBasis G this : TopologicalSpace G := topology B basis : HasBasis (𝓝 1) (fun V => V ∈ B) id basis' : HasBasis (𝓝 1 ×ˢ 𝓝 1) (fun i => i.fst ∈ B ∧ i.snd ∈ B) fun i => id i.fst ×ˢ id i.snd ⊢ ∀ (x₀ : G), 𝓝 x₀ = map (fun x => x₀ * x) (𝓝 1) [PROOFSTEP] intro x₀ [GOAL] case refine'_3 G : Type u inst✝ : Group G B✝ B : GroupFilterBasis G this : TopologicalSpace G := topology B basis : HasBasis (𝓝 1) (fun V => V ∈ B) id basis' : HasBasis (𝓝 1 ×ˢ 𝓝 1) (fun i => i.fst ∈ B ∧ i.snd ∈ B) fun i => id i.fst ×ˢ id i.snd x₀ : G ⊢ 𝓝 x₀ = map (fun x => x₀ * x) (𝓝 1) [PROOFSTEP] rw [nhds_eq, nhds_one_eq] [GOAL] case refine'_3 G : Type u inst✝ : Group G B✝ B : GroupFilterBasis G this : TopologicalSpace G := topology B basis : HasBasis (𝓝 1) (fun V => V ∈ B) id basis' : HasBasis (𝓝 1 ×ˢ 𝓝 1) (fun i => i.fst ∈ B ∧ i.snd ∈ B) fun i => id i.fst ×ˢ id i.snd x₀ : G ⊢ N B x₀ = map (fun x => x₀ * x) (FilterBasis.filter toFilterBasis) [PROOFSTEP] rfl [GOAL] case refine'_4 G : Type u inst✝ : Group G B✝ B : GroupFilterBasis G this : TopologicalSpace G := topology B basis : HasBasis (𝓝 1) (fun V => V ∈ B) id basis' : HasBasis (𝓝 1 ×ˢ 𝓝 1) (fun i => i.fst ∈ B ∧ i.snd ∈ B) fun i => id i.fst ×ˢ id i.snd ⊢ ∀ (x₀ : G), Tendsto (fun x => x₀ * x * x₀⁻¹) (𝓝 1) (𝓝 1) [PROOFSTEP] intro x₀ [GOAL] case refine'_4 G : Type u inst✝ : Group G B✝ B : GroupFilterBasis G this : TopologicalSpace G := topology B basis : HasBasis (𝓝 1) (fun V => V ∈ B) id basis' : HasBasis (𝓝 1 ×ˢ 𝓝 1) (fun i => i.fst ∈ B ∧ i.snd ∈ B) fun i => id i.fst ×ˢ id i.snd x₀ : G ⊢ Tendsto (fun x => x₀ * x * x₀⁻¹) (𝓝 1) (𝓝 1) [PROOFSTEP] rw [basis.tendsto_iff basis] [GOAL] case refine'_4 G : Type u inst✝ : Group G B✝ B : GroupFilterBasis G this : TopologicalSpace G := topology B basis : HasBasis (𝓝 1) (fun V => V ∈ B) id basis' : HasBasis (𝓝 1 ×ˢ 𝓝 1) (fun i => i.fst ∈ B ∧ i.snd ∈ B) fun i => id i.fst ×ˢ id i.snd x₀ : G ⊢ ∀ (ib : Set G), ib ∈ B → ∃ ia, ia ∈ B ∧ ∀ (x : G), x ∈ id ia → x₀ * x * x₀⁻¹ ∈ id ib [PROOFSTEP] intro U U_in [GOAL] case refine'_4 G : Type u inst✝ : Group G B✝ B : GroupFilterBasis G this : TopologicalSpace G := topology B basis : HasBasis (𝓝 1) (fun V => V ∈ B) id basis' : HasBasis (𝓝 1 ×ˢ 𝓝 1) (fun i => i.fst ∈ B ∧ i.snd ∈ B) fun i => id i.fst ×ˢ id i.snd x₀ : G U : Set G U_in : U ∈ B ⊢ ∃ ia, ia ∈ B ∧ ∀ (x : G), x ∈ id ia → x₀ * x * x₀⁻¹ ∈ id U [PROOFSTEP] exact conj x₀ U_in [GOAL] R✝ : Type u inst✝¹ : Ring R✝ B✝ : RingFilterBasis R✝ R : Type u inst✝ : Ring R B : RingFilterBasis R ⊢ TopologicalRing R [PROOFSTEP] let B' := B.toAddGroupFilterBasis [GOAL] R✝ : Type u inst✝¹ : Ring R✝ B✝ : RingFilterBasis R✝ R : Type u inst✝ : Ring R B : RingFilterBasis R B' : AddGroupFilterBasis R := toAddGroupFilterBasis ⊢ TopologicalRing R [PROOFSTEP] letI := B'.topology [GOAL] R✝ : Type u inst✝¹ : Ring R✝ B✝ : RingFilterBasis R✝ R : Type u inst✝ : Ring R B : RingFilterBasis R B' : AddGroupFilterBasis R := toAddGroupFilterBasis this : TopologicalSpace R := AddGroupFilterBasis.topology B' ⊢ TopologicalRing R [PROOFSTEP] have basis := B'.nhds_zero_hasBasis [GOAL] R✝ : Type u inst✝¹ : Ring R✝ B✝ : RingFilterBasis R✝ R : Type u inst✝ : Ring R B : RingFilterBasis R B' : AddGroupFilterBasis R := toAddGroupFilterBasis this : TopologicalSpace R := AddGroupFilterBasis.topology B' basis : HasBasis (𝓝 0) (fun V => V ∈ B') id ⊢ TopologicalRing R [PROOFSTEP] have basis' := basis.prod basis [GOAL] R✝ : Type u inst✝¹ : Ring R✝ B✝ : RingFilterBasis R✝ R : Type u inst✝ : Ring R B : RingFilterBasis R B' : AddGroupFilterBasis R := toAddGroupFilterBasis this : TopologicalSpace R := AddGroupFilterBasis.topology B' basis : HasBasis (𝓝 0) (fun V => V ∈ B') id basis' : HasBasis (𝓝 0 ×ˢ 𝓝 0) (fun i => i.fst ∈ B' ∧ i.snd ∈ B') fun i => id i.fst ×ˢ id i.snd ⊢ TopologicalRing R [PROOFSTEP] haveI := B'.isTopologicalAddGroup [GOAL] R✝ : Type u inst✝¹ : Ring R✝ B✝ : RingFilterBasis R✝ R : Type u inst✝ : Ring R B : RingFilterBasis R B' : AddGroupFilterBasis R := toAddGroupFilterBasis this✝ : TopologicalSpace R := AddGroupFilterBasis.topology B' basis : HasBasis (𝓝 0) (fun V => V ∈ B') id basis' : HasBasis (𝓝 0 ×ˢ 𝓝 0) (fun i => i.fst ∈ B' ∧ i.snd ∈ B') fun i => id i.fst ×ˢ id i.snd this : TopologicalAddGroup R ⊢ TopologicalRing R [PROOFSTEP] apply TopologicalRing.of_addGroup_of_nhds_zero [GOAL] case hmul R✝ : Type u inst✝¹ : Ring R✝ B✝ : RingFilterBasis R✝ R : Type u inst✝ : Ring R B : RingFilterBasis R B' : AddGroupFilterBasis R := toAddGroupFilterBasis this✝ : TopologicalSpace R := AddGroupFilterBasis.topology B' basis : HasBasis (𝓝 0) (fun V => V ∈ B') id basis' : HasBasis (𝓝 0 ×ˢ 𝓝 0) (fun i => i.fst ∈ B' ∧ i.snd ∈ B') fun i => id i.fst ×ˢ id i.snd this : TopologicalAddGroup R ⊢ Tendsto (uncurry fun x x_1 => x * x_1) (𝓝 0 ×ˢ 𝓝 0) (𝓝 0) [PROOFSTEP] rw [basis'.tendsto_iff basis] [GOAL] case hmul R✝ : Type u inst✝¹ : Ring R✝ B✝ : RingFilterBasis R✝ R : Type u inst✝ : Ring R B : RingFilterBasis R B' : AddGroupFilterBasis R := toAddGroupFilterBasis this✝ : TopologicalSpace R := AddGroupFilterBasis.topology B' basis : HasBasis (𝓝 0) (fun V => V ∈ B') id basis' : HasBasis (𝓝 0 ×ˢ 𝓝 0) (fun i => i.fst ∈ B' ∧ i.snd ∈ B') fun i => id i.fst ×ˢ id i.snd this : TopologicalAddGroup R ⊢ ∀ (ib : Set R), ib ∈ B' → ∃ ia, (ia.fst ∈ B' ∧ ia.snd ∈ B') ∧ ∀ (x : R × R), x ∈ id ia.fst ×ˢ id ia.snd → uncurry (fun x x_1 => x * x_1) x ∈ id ib [PROOFSTEP] suffices ∀ U ∈ B', ∃ V W, (V ∈ B' ∧ W ∈ B') ∧ ∀ a b, a ∈ V → b ∈ W → a * b ∈ U by simpa [GOAL] R✝ : Type u inst✝¹ : Ring R✝ B✝ : RingFilterBasis R✝ R : Type u inst✝ : Ring R B : RingFilterBasis R B' : AddGroupFilterBasis R := toAddGroupFilterBasis this✝¹ : TopologicalSpace R := AddGroupFilterBasis.topology B' basis : HasBasis (𝓝 0) (fun V => V ∈ B') id basis' : HasBasis (𝓝 0 ×ˢ 𝓝 0) (fun i => i.fst ∈ B' ∧ i.snd ∈ B') fun i => id i.fst ×ˢ id i.snd this✝ : TopologicalAddGroup R this : ∀ (U : Set R), U ∈ B' → ∃ V W, (V ∈ B' ∧ W ∈ B') ∧ ∀ (a b : R), a ∈ V → b ∈ W → a * b ∈ U ⊢ ∀ (ib : Set R), ib ∈ B' → ∃ ia, (ia.fst ∈ B' ∧ ia.snd ∈ B') ∧ ∀ (x : R × R), x ∈ id ia.fst ×ˢ id ia.snd → uncurry (fun x x_1 => x * x_1) x ∈ id ib [PROOFSTEP] simpa [GOAL] case hmul R✝ : Type u inst✝¹ : Ring R✝ B✝ : RingFilterBasis R✝ R : Type u inst✝ : Ring R B : RingFilterBasis R B' : AddGroupFilterBasis R := toAddGroupFilterBasis this✝ : TopologicalSpace R := AddGroupFilterBasis.topology B' basis : HasBasis (𝓝 0) (fun V => V ∈ B') id basis' : HasBasis (𝓝 0 ×ˢ 𝓝 0) (fun i => i.fst ∈ B' ∧ i.snd ∈ B') fun i => id i.fst ×ˢ id i.snd this : TopologicalAddGroup R ⊢ ∀ (U : Set R), U ∈ B' → ∃ V W, (V ∈ B' ∧ W ∈ B') ∧ ∀ (a b : R), a ∈ V → b ∈ W → a * b ∈ U [PROOFSTEP] intro U U_in [GOAL] case hmul R✝ : Type u inst✝¹ : Ring R✝ B✝ : RingFilterBasis R✝ R : Type u inst✝ : Ring R B : RingFilterBasis R B' : AddGroupFilterBasis R := toAddGroupFilterBasis this✝ : TopologicalSpace R := AddGroupFilterBasis.topology B' basis : HasBasis (𝓝 0) (fun V => V ∈ B') id basis' : HasBasis (𝓝 0 ×ˢ 𝓝 0) (fun i => i.fst ∈ B' ∧ i.snd ∈ B') fun i => id i.fst ×ˢ id i.snd this : TopologicalAddGroup R U : Set R U_in : U ∈ B' ⊢ ∃ V W, (V ∈ B' ∧ W ∈ B') ∧ ∀ (a b : R), a ∈ V → b ∈ W → a * b ∈ U [PROOFSTEP] rcases B.mul U_in with ⟨V, V_in, hV⟩ [GOAL] case hmul.intro.intro R✝ : Type u inst✝¹ : Ring R✝ B✝ : RingFilterBasis R✝ R : Type u inst✝ : Ring R B : RingFilterBasis R B' : AddGroupFilterBasis R := toAddGroupFilterBasis this✝ : TopologicalSpace R := AddGroupFilterBasis.topology B' basis : HasBasis (𝓝 0) (fun V => V ∈ B') id basis' : HasBasis (𝓝 0 ×ˢ 𝓝 0) (fun i => i.fst ∈ B' ∧ i.snd ∈ B') fun i => id i.fst ×ˢ id i.snd this : TopologicalAddGroup R U : Set R U_in : U ∈ B' V : Set R V_in : V ∈ B hV : V * V ⊆ U ⊢ ∃ V W, (V ∈ B' ∧ W ∈ B') ∧ ∀ (a b : R), a ∈ V → b ∈ W → a * b ∈ U [PROOFSTEP] refine' ⟨V, V, ⟨V_in, V_in⟩, _⟩ [GOAL] case hmul.intro.intro R✝ : Type u inst✝¹ : Ring R✝ B✝ : RingFilterBasis R✝ R : Type u inst✝ : Ring R B : RingFilterBasis R B' : AddGroupFilterBasis R := toAddGroupFilterBasis this✝ : TopologicalSpace R := AddGroupFilterBasis.topology B' basis : HasBasis (𝓝 0) (fun V => V ∈ B') id basis' : HasBasis (𝓝 0 ×ˢ 𝓝 0) (fun i => i.fst ∈ B' ∧ i.snd ∈ B') fun i => id i.fst ×ˢ id i.snd this : TopologicalAddGroup R U : Set R U_in : U ∈ B' V : Set R V_in : V ∈ B hV : V * V ⊆ U ⊢ ∀ (a b : R), a ∈ V → b ∈ V → a * b ∈ U [PROOFSTEP] intro a b a_in b_in [GOAL] case hmul.intro.intro R✝ : Type u inst✝¹ : Ring R✝ B✝ : RingFilterBasis R✝ R : Type u inst✝ : Ring R B : RingFilterBasis R B' : AddGroupFilterBasis R := toAddGroupFilterBasis this✝ : TopologicalSpace R := AddGroupFilterBasis.topology B' basis : HasBasis (𝓝 0) (fun V => V ∈ B') id basis' : HasBasis (𝓝 0 ×ˢ 𝓝 0) (fun i => i.fst ∈ B' ∧ i.snd ∈ B') fun i => id i.fst ×ˢ id i.snd this : TopologicalAddGroup R U : Set R U_in : U ∈ B' V : Set R V_in : V ∈ B hV : V * V ⊆ U a b : R a_in : a ∈ V b_in : b ∈ V ⊢ a * b ∈ U [PROOFSTEP] exact hV ⟨a, b, a_in, b_in, rfl⟩ [GOAL] case hmul_left R✝ : Type u inst✝¹ : Ring R✝ B✝ : RingFilterBasis R✝ R : Type u inst✝ : Ring R B : RingFilterBasis R B' : AddGroupFilterBasis R := toAddGroupFilterBasis this✝ : TopologicalSpace R := AddGroupFilterBasis.topology B' basis : HasBasis (𝓝 0) (fun V => V ∈ B') id basis' : HasBasis (𝓝 0 ×ˢ 𝓝 0) (fun i => i.fst ∈ B' ∧ i.snd ∈ B') fun i => id i.fst ×ˢ id i.snd this : TopologicalAddGroup R ⊢ ∀ (x₀ : R), Tendsto (fun x => x₀ * x) (𝓝 0) (𝓝 0) [PROOFSTEP] intro x₀ [GOAL] case hmul_left R✝ : Type u inst✝¹ : Ring R✝ B✝ : RingFilterBasis R✝ R : Type u inst✝ : Ring R B : RingFilterBasis R B' : AddGroupFilterBasis R := toAddGroupFilterBasis this✝ : TopologicalSpace R := AddGroupFilterBasis.topology B' basis : HasBasis (𝓝 0) (fun V => V ∈ B') id basis' : HasBasis (𝓝 0 ×ˢ 𝓝 0) (fun i => i.fst ∈ B' ∧ i.snd ∈ B') fun i => id i.fst ×ˢ id i.snd this : TopologicalAddGroup R x₀ : R ⊢ Tendsto (fun x => x₀ * x) (𝓝 0) (𝓝 0) [PROOFSTEP] rw [basis.tendsto_iff basis] [GOAL] case hmul_left R✝ : Type u inst✝¹ : Ring R✝ B✝ : RingFilterBasis R✝ R : Type u inst✝ : Ring R B : RingFilterBasis R B' : AddGroupFilterBasis R := toAddGroupFilterBasis this✝ : TopologicalSpace R := AddGroupFilterBasis.topology B' basis : HasBasis (𝓝 0) (fun V => V ∈ B') id basis' : HasBasis (𝓝 0 ×ˢ 𝓝 0) (fun i => i.fst ∈ B' ∧ i.snd ∈ B') fun i => id i.fst ×ˢ id i.snd this : TopologicalAddGroup R x₀ : R ⊢ ∀ (ib : Set R), ib ∈ B' → ∃ ia, ia ∈ B' ∧ ∀ (x : R), x ∈ id ia → x₀ * x ∈ id ib [PROOFSTEP] intro U [GOAL] case hmul_left R✝ : Type u inst✝¹ : Ring R✝ B✝ : RingFilterBasis R✝ R : Type u inst✝ : Ring R B : RingFilterBasis R B' : AddGroupFilterBasis R := toAddGroupFilterBasis this✝ : TopologicalSpace R := AddGroupFilterBasis.topology B' basis : HasBasis (𝓝 0) (fun V => V ∈ B') id basis' : HasBasis (𝓝 0 ×ˢ 𝓝 0) (fun i => i.fst ∈ B' ∧ i.snd ∈ B') fun i => id i.fst ×ˢ id i.snd this : TopologicalAddGroup R x₀ : R U : Set R ⊢ U ∈ B' → ∃ ia, ia ∈ B' ∧ ∀ (x : R), x ∈ id ia → x₀ * x ∈ id U [PROOFSTEP] simpa using B.mul_left x₀ [GOAL] case hmul_right R✝ : Type u inst✝¹ : Ring R✝ B✝ : RingFilterBasis R✝ R : Type u inst✝ : Ring R B : RingFilterBasis R B' : AddGroupFilterBasis R := toAddGroupFilterBasis this✝ : TopologicalSpace R := AddGroupFilterBasis.topology B' basis : HasBasis (𝓝 0) (fun V => V ∈ B') id basis' : HasBasis (𝓝 0 ×ˢ 𝓝 0) (fun i => i.fst ∈ B' ∧ i.snd ∈ B') fun i => id i.fst ×ˢ id i.snd this : TopologicalAddGroup R ⊢ ∀ (x₀ : R), Tendsto (fun x => x * x₀) (𝓝 0) (𝓝 0) [PROOFSTEP] intro x₀ [GOAL] case hmul_right R✝ : Type u inst✝¹ : Ring R✝ B✝ : RingFilterBasis R✝ R : Type u inst✝ : Ring R B : RingFilterBasis R B' : AddGroupFilterBasis R := toAddGroupFilterBasis this✝ : TopologicalSpace R := AddGroupFilterBasis.topology B' basis : HasBasis (𝓝 0) (fun V => V ∈ B') id basis' : HasBasis (𝓝 0 ×ˢ 𝓝 0) (fun i => i.fst ∈ B' ∧ i.snd ∈ B') fun i => id i.fst ×ˢ id i.snd this : TopologicalAddGroup R x₀ : R ⊢ Tendsto (fun x => x * x₀) (𝓝 0) (𝓝 0) [PROOFSTEP] rw [basis.tendsto_iff basis] [GOAL] case hmul_right R✝ : Type u inst✝¹ : Ring R✝ B✝ : RingFilterBasis R✝ R : Type u inst✝ : Ring R B : RingFilterBasis R B' : AddGroupFilterBasis R := toAddGroupFilterBasis this✝ : TopologicalSpace R := AddGroupFilterBasis.topology B' basis : HasBasis (𝓝 0) (fun V => V ∈ B') id basis' : HasBasis (𝓝 0 ×ˢ 𝓝 0) (fun i => i.fst ∈ B' ∧ i.snd ∈ B') fun i => id i.fst ×ˢ id i.snd this : TopologicalAddGroup R x₀ : R ⊢ ∀ (ib : Set R), ib ∈ B' → ∃ ia, ia ∈ B' ∧ ∀ (x : R), x ∈ id ia → x * x₀ ∈ id ib [PROOFSTEP] intro U [GOAL] case hmul_right R✝ : Type u inst✝¹ : Ring R✝ B✝ : RingFilterBasis R✝ R : Type u inst✝ : Ring R B : RingFilterBasis R B' : AddGroupFilterBasis R := toAddGroupFilterBasis this✝ : TopologicalSpace R := AddGroupFilterBasis.topology B' basis : HasBasis (𝓝 0) (fun V => V ∈ B') id basis' : HasBasis (𝓝 0 ×ˢ 𝓝 0) (fun i => i.fst ∈ B' ∧ i.snd ∈ B') fun i => id i.fst ×ˢ id i.snd this : TopologicalAddGroup R x₀ : R U : Set R ⊢ U ∈ B' → ∃ ia, ia ∈ B' ∧ ∀ (x : R), x ∈ id ia → x * x₀ ∈ id U [PROOFSTEP] simpa using B.mul_right x₀ [GOAL] R : Type u_1 M : Type u_2 inst✝⁴ : CommRing R inst✝³ : TopologicalSpace R inst✝² : AddCommGroup M inst✝¹ : Module R M B : ModuleFilterBasis R M inst✝ : DiscreteTopology R src✝ : AddGroupFilterBasis M := let_fun this := default; this ⊢ ∀ {U : Set M}, U ∈ AddGroupFilterBasis.toFilterBasis.sets → ∃ V, V ∈ 𝓝 0 ∧ ∃ W, W ∈ AddGroupFilterBasis.toFilterBasis.sets ∧ V • W ⊆ U [PROOFSTEP] rintro U (rfl : U ∈ {{(0 : M)}}) [GOAL] R : Type u_1 M : Type u_2 inst✝⁴ : CommRing R inst✝³ : TopologicalSpace R inst✝² : AddCommGroup M inst✝¹ : Module R M B : ModuleFilterBasis R M inst✝ : DiscreteTopology R src✝ : AddGroupFilterBasis M := let_fun this := default; this ⊢ ∃ V, V ∈ 𝓝 0 ∧ ∃ W, W ∈ AddGroupFilterBasis.toFilterBasis.sets ∧ V • W ⊆ {0} [PROOFSTEP] use univ, univ_mem, {0}, rfl [GOAL] case right R : Type u_1 M : Type u_2 inst✝⁴ : CommRing R inst✝³ : TopologicalSpace R inst✝² : AddCommGroup M inst✝¹ : Module R M B : ModuleFilterBasis R M inst✝ : DiscreteTopology R src✝ : AddGroupFilterBasis M := let_fun this := default; this ⊢ univ • {0} ⊆ {0} [PROOFSTEP] rintro a ⟨x, m, -, rfl, rfl⟩ [GOAL] case right.intro.intro.intro.intro R : Type u_1 M : Type u_2 inst✝⁴ : CommRing R inst✝³ : TopologicalSpace R inst✝² : AddCommGroup M inst✝¹ : Module R M B : ModuleFilterBasis R M inst✝ : DiscreteTopology R src✝ : AddGroupFilterBasis M := let_fun this := default; this x : R ⊢ (fun x x_1 => x • x_1) x 0 ∈ {0} [PROOFSTEP] simp only [smul_zero, mem_singleton_iff] [GOAL] R : Type u_1 M : Type u_2 inst✝⁴ : CommRing R inst✝³ : TopologicalSpace R inst✝² : AddCommGroup M inst✝¹ : Module R M B : ModuleFilterBasis R M inst✝ : DiscreteTopology R src✝ : AddGroupFilterBasis M := let_fun this := default; this ⊢ ∀ (x₀ : R) {U : Set M}, U ∈ AddGroupFilterBasis.toFilterBasis.sets → ∃ V, V ∈ AddGroupFilterBasis.toFilterBasis.sets ∧ V ⊆ (fun x => x₀ • x) ⁻¹' U [PROOFSTEP] rintro x₀ U (h : U ∈ {{(0 : M)}}) [GOAL] R : Type u_1 M : Type u_2 inst✝⁴ : CommRing R inst✝³ : TopologicalSpace R inst✝² : AddCommGroup M inst✝¹ : Module R M B : ModuleFilterBasis R M inst✝ : DiscreteTopology R src✝ : AddGroupFilterBasis M := let_fun this := default; this x₀ : R U : Set M h : U ∈ {{0}} ⊢ ∃ V, V ∈ AddGroupFilterBasis.toFilterBasis.sets ∧ V ⊆ (fun x => x₀ • x) ⁻¹' U [PROOFSTEP] rw [mem_singleton_iff] at h [GOAL] R : Type u_1 M : Type u_2 inst✝⁴ : CommRing R inst✝³ : TopologicalSpace R inst✝² : AddCommGroup M inst✝¹ : Module R M B : ModuleFilterBasis R M inst✝ : DiscreteTopology R src✝ : AddGroupFilterBasis M := let_fun this := default; this x₀ : R U : Set M h : U = {0} ⊢ ∃ V, V ∈ AddGroupFilterBasis.toFilterBasis.sets ∧ V ⊆ (fun x => x₀ • x) ⁻¹' U [PROOFSTEP] use{0}, rfl [GOAL] case right R : Type u_1 M : Type u_2 inst✝⁴ : CommRing R inst✝³ : TopologicalSpace R inst✝² : AddCommGroup M inst✝¹ : Module R M B : ModuleFilterBasis R M inst✝ : DiscreteTopology R src✝ : AddGroupFilterBasis M := let_fun this := default; this x₀ : R U : Set M h : U = {0} ⊢ {0} ⊆ (fun x => x₀ • x) ⁻¹' U [PROOFSTEP] simp [h] [GOAL] R : Type u_1 M : Type u_2 inst✝⁴ : CommRing R inst✝³ : TopologicalSpace R inst✝² : AddCommGroup M inst✝¹ : Module R M B : ModuleFilterBasis R M inst✝ : DiscreteTopology R src✝ : AddGroupFilterBasis M := let_fun this := default; this ⊢ ∀ (m₀ : M) {U : Set M}, U ∈ AddGroupFilterBasis.toFilterBasis.sets → ∀ᶠ (x : R) in 𝓝 0, x • m₀ ∈ U [PROOFSTEP] rintro m₀ U (h : U ∈ (0 : Set (Set M))) [GOAL] R : Type u_1 M : Type u_2 inst✝⁴ : CommRing R inst✝³ : TopologicalSpace R inst✝² : AddCommGroup M inst✝¹ : Module R M B : ModuleFilterBasis R M inst✝ : DiscreteTopology R src✝ : AddGroupFilterBasis M := let_fun this := default; this m₀ : M U : Set M h : U ∈ 0 ⊢ ∀ᶠ (x : R) in 𝓝 0, x • m₀ ∈ U [PROOFSTEP] rw [Set.mem_zero] at h [GOAL] R : Type u_1 M : Type u_2 inst✝⁴ : CommRing R inst✝³ : TopologicalSpace R inst✝² : AddCommGroup M inst✝¹ : Module R M B : ModuleFilterBasis R M inst✝ : DiscreteTopology R src✝ : AddGroupFilterBasis M := let_fun this := default; this m₀ : M U : Set M h : U = 0 ⊢ ∀ᶠ (x : R) in 𝓝 0, x • m₀ ∈ U [PROOFSTEP] simp [h, nhds_discrete] [GOAL] R : Type u_1 M : Type u_2 inst✝⁶ : CommRing R inst✝⁵ : TopologicalSpace R inst✝⁴ : AddCommGroup M inst✝³ : Module R M B : ModuleFilterBasis R M ι : Type u_3 inst✝² : TopologicalRing R inst✝¹ : TopologicalSpace M inst✝ : TopologicalAddGroup M p : ι → Prop b : ι → Set M h : HasBasis (𝓝 0) p b hsmul : ∀ {i : ι}, p i → ∃ V, V ∈ 𝓝 0 ∧ ∃ j x, V • b j ⊆ b i hsmul_left : ∀ (x₀ : R) {i : ι}, p i → ∃ j x, b j ⊆ (fun x => x₀ • x) ⁻¹' b i hsmul_right : ∀ (m₀ : M) {i : ι}, p i → ∀ᶠ (x : R) in 𝓝 0, x • m₀ ∈ b i ⊢ ContinuousSMul R M [PROOFSTEP] apply ContinuousSMul.of_nhds_zero [GOAL] case hmul R : Type u_1 M : Type u_2 inst✝⁶ : CommRing R inst✝⁵ : TopologicalSpace R inst✝⁴ : AddCommGroup M inst✝³ : Module R M B : ModuleFilterBasis R M ι : Type u_3 inst✝² : TopologicalRing R inst✝¹ : TopologicalSpace M inst✝ : TopologicalAddGroup M p : ι → Prop b : ι → Set M h : HasBasis (𝓝 0) p b hsmul : ∀ {i : ι}, p i → ∃ V, V ∈ 𝓝 0 ∧ ∃ j x, V • b j ⊆ b i hsmul_left : ∀ (x₀ : R) {i : ι}, p i → ∃ j x, b j ⊆ (fun x => x₀ • x) ⁻¹' b i hsmul_right : ∀ (m₀ : M) {i : ι}, p i → ∀ᶠ (x : R) in 𝓝 0, x • m₀ ∈ b i ⊢ Tendsto (fun p => p.fst • p.snd) (𝓝 0 ×ˢ 𝓝 0) (𝓝 0) [PROOFSTEP] rw [h.tendsto_right_iff] [GOAL] case hmul R : Type u_1 M : Type u_2 inst✝⁶ : CommRing R inst✝⁵ : TopologicalSpace R inst✝⁴ : AddCommGroup M inst✝³ : Module R M B : ModuleFilterBasis R M ι : Type u_3 inst✝² : TopologicalRing R inst✝¹ : TopologicalSpace M inst✝ : TopologicalAddGroup M p : ι → Prop b : ι → Set M h : HasBasis (𝓝 0) p b hsmul : ∀ {i : ι}, p i → ∃ V, V ∈ 𝓝 0 ∧ ∃ j x, V • b j ⊆ b i hsmul_left : ∀ (x₀ : R) {i : ι}, p i → ∃ j x, b j ⊆ (fun x => x₀ • x) ⁻¹' b i hsmul_right : ∀ (m₀ : M) {i : ι}, p i → ∀ᶠ (x : R) in 𝓝 0, x • m₀ ∈ b i ⊢ ∀ (i : ι), p i → ∀ᶠ (x : R × M) in 𝓝 0 ×ˢ 𝓝 0, x.fst • x.snd ∈ b i [PROOFSTEP] intro i hi [GOAL] case hmul R : Type u_1 M : Type u_2 inst✝⁶ : CommRing R inst✝⁵ : TopologicalSpace R inst✝⁴ : AddCommGroup M inst✝³ : Module R M B : ModuleFilterBasis R M ι : Type u_3 inst✝² : TopologicalRing R inst✝¹ : TopologicalSpace M inst✝ : TopologicalAddGroup M p : ι → Prop b : ι → Set M h : HasBasis (𝓝 0) p b hsmul : ∀ {i : ι}, p i → ∃ V, V ∈ 𝓝 0 ∧ ∃ j x, V • b j ⊆ b i hsmul_left : ∀ (x₀ : R) {i : ι}, p i → ∃ j x, b j ⊆ (fun x => x₀ • x) ⁻¹' b i hsmul_right : ∀ (m₀ : M) {i : ι}, p i → ∀ᶠ (x : R) in 𝓝 0, x • m₀ ∈ b i i : ι hi : p i ⊢ ∀ᶠ (x : R × M) in 𝓝 0 ×ˢ 𝓝 0, x.fst • x.snd ∈ b i [PROOFSTEP] rcases hsmul hi with ⟨V, V_in, j, hj, hVj⟩ [GOAL] case hmul.intro.intro.intro.intro R : Type u_1 M : Type u_2 inst✝⁶ : CommRing R inst✝⁵ : TopologicalSpace R inst✝⁴ : AddCommGroup M inst✝³ : Module R M B : ModuleFilterBasis R M ι : Type u_3 inst✝² : TopologicalRing R inst✝¹ : TopologicalSpace M inst✝ : TopologicalAddGroup M p : ι → Prop b : ι → Set M h : HasBasis (𝓝 0) p b hsmul : ∀ {i : ι}, p i → ∃ V, V ∈ 𝓝 0 ∧ ∃ j x, V • b j ⊆ b i hsmul_left : ∀ (x₀ : R) {i : ι}, p i → ∃ j x, b j ⊆ (fun x => x₀ • x) ⁻¹' b i hsmul_right : ∀ (m₀ : M) {i : ι}, p i → ∀ᶠ (x : R) in 𝓝 0, x • m₀ ∈ b i i : ι hi : p i V : Set R V_in : V ∈ 𝓝 0 j : ι hj : p j hVj : V • b j ⊆ b i ⊢ ∀ᶠ (x : R × M) in 𝓝 0 ×ˢ 𝓝 0, x.fst • x.snd ∈ b i [PROOFSTEP] apply mem_of_superset (prod_mem_prod V_in <| h.mem_of_mem hj) [GOAL] case hmul.intro.intro.intro.intro R : Type u_1 M : Type u_2 inst✝⁶ : CommRing R inst✝⁵ : TopologicalSpace R inst✝⁴ : AddCommGroup M inst✝³ : Module R M B : ModuleFilterBasis R M ι : Type u_3 inst✝² : TopologicalRing R inst✝¹ : TopologicalSpace M inst✝ : TopologicalAddGroup M p : ι → Prop b : ι → Set M h : HasBasis (𝓝 0) p b hsmul : ∀ {i : ι}, p i → ∃ V, V ∈ 𝓝 0 ∧ ∃ j x, V • b j ⊆ b i hsmul_left : ∀ (x₀ : R) {i : ι}, p i → ∃ j x, b j ⊆ (fun x => x₀ • x) ⁻¹' b i hsmul_right : ∀ (m₀ : M) {i : ι}, p i → ∀ᶠ (x : R) in 𝓝 0, x • m₀ ∈ b i i : ι hi : p i V : Set R V_in : V ∈ 𝓝 0 j : ι hj : p j hVj : V • b j ⊆ b i ⊢ V ×ˢ b j ⊆ {x | (fun x => x.fst • x.snd ∈ b i) x} [PROOFSTEP] rintro ⟨v, w⟩ ⟨v_in : v ∈ V, w_in : w ∈ b j⟩ [GOAL] case hmul.intro.intro.intro.intro.mk.intro R : Type u_1 M : Type u_2 inst✝⁶ : CommRing R inst✝⁵ : TopologicalSpace R inst✝⁴ : AddCommGroup M inst✝³ : Module R M B : ModuleFilterBasis R M ι : Type u_3 inst✝² : TopologicalRing R inst✝¹ : TopologicalSpace M inst✝ : TopologicalAddGroup M p : ι → Prop b : ι → Set M h : HasBasis (𝓝 0) p b hsmul : ∀ {i : ι}, p i → ∃ V, V ∈ 𝓝 0 ∧ ∃ j x, V • b j ⊆ b i hsmul_left : ∀ (x₀ : R) {i : ι}, p i → ∃ j x, b j ⊆ (fun x => x₀ • x) ⁻¹' b i hsmul_right : ∀ (m₀ : M) {i : ι}, p i → ∀ᶠ (x : R) in 𝓝 0, x • m₀ ∈ b i i : ι hi : p i V : Set R V_in : V ∈ 𝓝 0 j : ι hj : p j hVj : V • b j ⊆ b i v : R w : M v_in : v ∈ V w_in : w ∈ b j ⊢ (v, w) ∈ {x | (fun x => x.fst • x.snd ∈ b i) x} [PROOFSTEP] exact hVj (Set.smul_mem_smul v_in w_in) [GOAL] case hmulleft R : Type u_1 M : Type u_2 inst✝⁶ : CommRing R inst✝⁵ : TopologicalSpace R inst✝⁴ : AddCommGroup M inst✝³ : Module R M B : ModuleFilterBasis R M ι : Type u_3 inst✝² : TopologicalRing R inst✝¹ : TopologicalSpace M inst✝ : TopologicalAddGroup M p : ι → Prop b : ι → Set M h : HasBasis (𝓝 0) p b hsmul : ∀ {i : ι}, p i → ∃ V, V ∈ 𝓝 0 ∧ ∃ j x, V • b j ⊆ b i hsmul_left : ∀ (x₀ : R) {i : ι}, p i → ∃ j x, b j ⊆ (fun x => x₀ • x) ⁻¹' b i hsmul_right : ∀ (m₀ : M) {i : ι}, p i → ∀ᶠ (x : R) in 𝓝 0, x • m₀ ∈ b i ⊢ ∀ (m : M), Tendsto (fun a => a • m) (𝓝 0) (𝓝 0) [PROOFSTEP] intro m₀ [GOAL] case hmulleft R : Type u_1 M : Type u_2 inst✝⁶ : CommRing R inst✝⁵ : TopologicalSpace R inst✝⁴ : AddCommGroup M inst✝³ : Module R M B : ModuleFilterBasis R M ι : Type u_3 inst✝² : TopologicalRing R inst✝¹ : TopologicalSpace M inst✝ : TopologicalAddGroup M p : ι → Prop b : ι → Set M h : HasBasis (𝓝 0) p b hsmul : ∀ {i : ι}, p i → ∃ V, V ∈ 𝓝 0 ∧ ∃ j x, V • b j ⊆ b i hsmul_left : ∀ (x₀ : R) {i : ι}, p i → ∃ j x, b j ⊆ (fun x => x₀ • x) ⁻¹' b i hsmul_right : ∀ (m₀ : M) {i : ι}, p i → ∀ᶠ (x : R) in 𝓝 0, x • m₀ ∈ b i m₀ : M ⊢ Tendsto (fun a => a • m₀) (𝓝 0) (𝓝 0) [PROOFSTEP] rw [h.tendsto_right_iff] [GOAL] case hmulleft R : Type u_1 M : Type u_2 inst✝⁶ : CommRing R inst✝⁵ : TopologicalSpace R inst✝⁴ : AddCommGroup M inst✝³ : Module R M B : ModuleFilterBasis R M ι : Type u_3 inst✝² : TopologicalRing R inst✝¹ : TopologicalSpace M inst✝ : TopologicalAddGroup M p : ι → Prop b : ι → Set M h : HasBasis (𝓝 0) p b hsmul : ∀ {i : ι}, p i → ∃ V, V ∈ 𝓝 0 ∧ ∃ j x, V • b j ⊆ b i hsmul_left : ∀ (x₀ : R) {i : ι}, p i → ∃ j x, b j ⊆ (fun x => x₀ • x) ⁻¹' b i hsmul_right : ∀ (m₀ : M) {i : ι}, p i → ∀ᶠ (x : R) in 𝓝 0, x • m₀ ∈ b i m₀ : M ⊢ ∀ (i : ι), p i → ∀ᶠ (x : R) in 𝓝 0, x • m₀ ∈ b i [PROOFSTEP] intro i hi [GOAL] case hmulleft R : Type u_1 M : Type u_2 inst✝⁶ : CommRing R inst✝⁵ : TopologicalSpace R inst✝⁴ : AddCommGroup M inst✝³ : Module R M B : ModuleFilterBasis R M ι : Type u_3 inst✝² : TopologicalRing R inst✝¹ : TopologicalSpace M inst✝ : TopologicalAddGroup M p : ι → Prop b : ι → Set M h : HasBasis (𝓝 0) p b hsmul : ∀ {i : ι}, p i → ∃ V, V ∈ 𝓝 0 ∧ ∃ j x, V • b j ⊆ b i hsmul_left : ∀ (x₀ : R) {i : ι}, p i → ∃ j x, b j ⊆ (fun x => x₀ • x) ⁻¹' b i hsmul_right : ∀ (m₀ : M) {i : ι}, p i → ∀ᶠ (x : R) in 𝓝 0, x • m₀ ∈ b i m₀ : M i : ι hi : p i ⊢ ∀ᶠ (x : R) in 𝓝 0, x • m₀ ∈ b i [PROOFSTEP] exact hsmul_right m₀ hi [GOAL] case hmulright R : Type u_1 M : Type u_2 inst✝⁶ : CommRing R inst✝⁵ : TopologicalSpace R inst✝⁴ : AddCommGroup M inst✝³ : Module R M B : ModuleFilterBasis R M ι : Type u_3 inst✝² : TopologicalRing R inst✝¹ : TopologicalSpace M inst✝ : TopologicalAddGroup M p : ι → Prop b : ι → Set M h : HasBasis (𝓝 0) p b hsmul : ∀ {i : ι}, p i → ∃ V, V ∈ 𝓝 0 ∧ ∃ j x, V • b j ⊆ b i hsmul_left : ∀ (x₀ : R) {i : ι}, p i → ∃ j x, b j ⊆ (fun x => x₀ • x) ⁻¹' b i hsmul_right : ∀ (m₀ : M) {i : ι}, p i → ∀ᶠ (x : R) in 𝓝 0, x • m₀ ∈ b i ⊢ ∀ (a : R), Tendsto (fun m => a • m) (𝓝 0) (𝓝 0) [PROOFSTEP] intro x₀ [GOAL] case hmulright R : Type u_1 M : Type u_2 inst✝⁶ : CommRing R inst✝⁵ : TopologicalSpace R inst✝⁴ : AddCommGroup M inst✝³ : Module R M B : ModuleFilterBasis R M ι : Type u_3 inst✝² : TopologicalRing R inst✝¹ : TopologicalSpace M inst✝ : TopologicalAddGroup M p : ι → Prop b : ι → Set M h : HasBasis (𝓝 0) p b hsmul : ∀ {i : ι}, p i → ∃ V, V ∈ 𝓝 0 ∧ ∃ j x, V • b j ⊆ b i hsmul_left : ∀ (x₀ : R) {i : ι}, p i → ∃ j x, b j ⊆ (fun x => x₀ • x) ⁻¹' b i hsmul_right : ∀ (m₀ : M) {i : ι}, p i → ∀ᶠ (x : R) in 𝓝 0, x • m₀ ∈ b i x₀ : R ⊢ Tendsto (fun m => x₀ • m) (𝓝 0) (𝓝 0) [PROOFSTEP] rw [h.tendsto_right_iff] [GOAL] case hmulright R : Type u_1 M : Type u_2 inst✝⁶ : CommRing R inst✝⁵ : TopologicalSpace R inst✝⁴ : AddCommGroup M inst✝³ : Module R M B : ModuleFilterBasis R M ι : Type u_3 inst✝² : TopologicalRing R inst✝¹ : TopologicalSpace M inst✝ : TopologicalAddGroup M p : ι → Prop b : ι → Set M h : HasBasis (𝓝 0) p b hsmul : ∀ {i : ι}, p i → ∃ V, V ∈ 𝓝 0 ∧ ∃ j x, V • b j ⊆ b i hsmul_left : ∀ (x₀ : R) {i : ι}, p i → ∃ j x, b j ⊆ (fun x => x₀ • x) ⁻¹' b i hsmul_right : ∀ (m₀ : M) {i : ι}, p i → ∀ᶠ (x : R) in 𝓝 0, x • m₀ ∈ b i x₀ : R ⊢ ∀ (i : ι), p i → ∀ᶠ (x : M) in 𝓝 0, x₀ • x ∈ b i [PROOFSTEP] intro i hi [GOAL] case hmulright R : Type u_1 M : Type u_2 inst✝⁶ : CommRing R inst✝⁵ : TopologicalSpace R inst✝⁴ : AddCommGroup M inst✝³ : Module R M B : ModuleFilterBasis R M ι : Type u_3 inst✝² : TopologicalRing R inst✝¹ : TopologicalSpace M inst✝ : TopologicalAddGroup M p : ι → Prop b : ι → Set M h : HasBasis (𝓝 0) p b hsmul : ∀ {i : ι}, p i → ∃ V, V ∈ 𝓝 0 ∧ ∃ j x, V • b j ⊆ b i hsmul_left : ∀ (x₀ : R) {i : ι}, p i → ∃ j x, b j ⊆ (fun x => x₀ • x) ⁻¹' b i hsmul_right : ∀ (m₀ : M) {i : ι}, p i → ∀ᶠ (x : R) in 𝓝 0, x • m₀ ∈ b i x₀ : R i : ι hi : p i ⊢ ∀ᶠ (x : M) in 𝓝 0, x₀ • x ∈ b i [PROOFSTEP] rcases hsmul_left x₀ hi with ⟨j, hj, hji⟩ [GOAL] case hmulright.intro.intro R : Type u_1 M : Type u_2 inst✝⁶ : CommRing R inst✝⁵ : TopologicalSpace R inst✝⁴ : AddCommGroup M inst✝³ : Module R M B : ModuleFilterBasis R M ι : Type u_3 inst✝² : TopologicalRing R inst✝¹ : TopologicalSpace M inst✝ : TopologicalAddGroup M p : ι → Prop b : ι → Set M h : HasBasis (𝓝 0) p b hsmul : ∀ {i : ι}, p i → ∃ V, V ∈ 𝓝 0 ∧ ∃ j x, V • b j ⊆ b i hsmul_left : ∀ (x₀ : R) {i : ι}, p i → ∃ j x, b j ⊆ (fun x => x₀ • x) ⁻¹' b i hsmul_right : ∀ (m₀ : M) {i : ι}, p i → ∀ᶠ (x : R) in 𝓝 0, x • m₀ ∈ b i x₀ : R i : ι hi : p i j : ι hj : p j hji : b j ⊆ (fun x => x₀ • x) ⁻¹' b i ⊢ ∀ᶠ (x : M) in 𝓝 0, x₀ • x ∈ b i [PROOFSTEP] exact mem_of_superset (h.mem_of_mem hj) hji [GOAL] R : Type u_1 M : Type u_2 inst✝⁴ : CommRing R inst✝³ : TopologicalSpace R inst✝² : AddCommGroup M inst✝¹ : Module R M B : ModuleFilterBasis R M inst✝ : TopologicalRing R ⊢ ContinuousSMul R M [PROOFSTEP] let B' := B.toAddGroupFilterBasis [GOAL] R : Type u_1 M : Type u_2 inst✝⁴ : CommRing R inst✝³ : TopologicalSpace R inst✝² : AddCommGroup M inst✝¹ : Module R M B : ModuleFilterBasis R M inst✝ : TopologicalRing R B' : AddGroupFilterBasis M := B.toAddGroupFilterBasis ⊢ ContinuousSMul R M [PROOFSTEP] let _ := B'.topology [GOAL] R : Type u_1 M : Type u_2 inst✝⁴ : CommRing R inst✝³ : TopologicalSpace R inst✝² : AddCommGroup M inst✝¹ : Module R M B : ModuleFilterBasis R M inst✝ : TopologicalRing R B' : AddGroupFilterBasis M := B.toAddGroupFilterBasis x✝ : TopologicalSpace M := AddGroupFilterBasis.topology B' ⊢ ContinuousSMul R M [PROOFSTEP] have _ := B'.isTopologicalAddGroup [GOAL] R : Type u_1 M : Type u_2 inst✝⁴ : CommRing R inst✝³ : TopologicalSpace R inst✝² : AddCommGroup M inst✝¹ : Module R M B : ModuleFilterBasis R M inst✝ : TopologicalRing R B' : AddGroupFilterBasis M := B.toAddGroupFilterBasis x✝¹ : TopologicalSpace M := AddGroupFilterBasis.topology B' x✝ : TopologicalAddGroup M ⊢ ContinuousSMul R M [PROOFSTEP] exact ContinuousSMul.of_basis_zero B'.nhds_zero_hasBasis (fun {_} => by simpa using B.smul) (by simpa using B.smul_left) B.smul_right [GOAL] R : Type u_1 M : Type u_2 inst✝⁴ : CommRing R inst✝³ : TopologicalSpace R inst✝² : AddCommGroup M inst✝¹ : Module R M B : ModuleFilterBasis R M inst✝ : TopologicalRing R B' : AddGroupFilterBasis M := B.toAddGroupFilterBasis x✝² : TopologicalSpace M := AddGroupFilterBasis.topology B' x✝¹ : TopologicalAddGroup M x✝ : Set M ⊢ x✝ ∈ B' → ∃ V, V ∈ 𝓝 0 ∧ ∃ j x, V • id j ⊆ id x✝ [PROOFSTEP] simpa using B.smul [GOAL] R : Type u_1 M : Type u_2 inst✝⁴ : CommRing R inst✝³ : TopologicalSpace R inst✝² : AddCommGroup M inst✝¹ : Module R M B : ModuleFilterBasis R M inst✝ : TopologicalRing R B' : AddGroupFilterBasis M := B.toAddGroupFilterBasis x✝¹ : TopologicalSpace M := AddGroupFilterBasis.topology B' x✝ : TopologicalAddGroup M ⊢ ∀ (x₀ : R) {i : Set M}, i ∈ B' → ∃ j x, id j ⊆ (fun x => x₀ • x) ⁻¹' id i [PROOFSTEP] simpa using B.smul_left [GOAL] R✝ : Type u_1 M✝ : Type u_2 inst✝⁶ : CommRing R✝ inst✝⁵ : TopologicalSpace R✝ inst✝⁴ : AddCommGroup M✝ inst✝³ : Module R✝ M✝ B : ModuleFilterBasis R✝ M✝ R : Type u_3 M : Type u_4 inst✝² : CommRing R inst✝¹ : AddCommGroup M inst✝ : Module R M BR : RingFilterBasis R BM : AddGroupFilterBasis M smul : ∀ {U : Set M}, U ∈ BM → ∃ V, V ∈ BR ∧ ∃ W, W ∈ BM ∧ V • W ⊆ U smul_left : ∀ (x₀ : R) {U : Set M}, U ∈ BM → ∃ V, V ∈ BM ∧ V ⊆ (fun x => x₀ • x) ⁻¹' U smul_right : ∀ (m₀ : M) {U : Set M}, U ∈ BM → ∃ V, V ∈ BR ∧ V ⊆ (fun x => x • m₀) ⁻¹' U x✝ : TopologicalSpace R := RingFilterBasis.topology BR ⊢ ∀ {U : Set M}, U ∈ AddGroupFilterBasis.toFilterBasis.sets → ∃ V, V ∈ 𝓝 0 ∧ ∃ W, W ∈ AddGroupFilterBasis.toFilterBasis.sets ∧ V • W ⊆ U [PROOFSTEP] intro U U_in [GOAL] R✝ : Type u_1 M✝ : Type u_2 inst✝⁶ : CommRing R✝ inst✝⁵ : TopologicalSpace R✝ inst✝⁴ : AddCommGroup M✝ inst✝³ : Module R✝ M✝ B : ModuleFilterBasis R✝ M✝ R : Type u_3 M : Type u_4 inst✝² : CommRing R inst✝¹ : AddCommGroup M inst✝ : Module R M BR : RingFilterBasis R BM : AddGroupFilterBasis M smul : ∀ {U : Set M}, U ∈ BM → ∃ V, V ∈ BR ∧ ∃ W, W ∈ BM ∧ V • W ⊆ U smul_left : ∀ (x₀ : R) {U : Set M}, U ∈ BM → ∃ V, V ∈ BM ∧ V ⊆ (fun x => x₀ • x) ⁻¹' U smul_right : ∀ (m₀ : M) {U : Set M}, U ∈ BM → ∃ V, V ∈ BR ∧ V ⊆ (fun x => x • m₀) ⁻¹' U x✝ : TopologicalSpace R := RingFilterBasis.topology BR U : Set M U_in : U ∈ AddGroupFilterBasis.toFilterBasis.sets ⊢ ∃ V, V ∈ 𝓝 0 ∧ ∃ W, W ∈ AddGroupFilterBasis.toFilterBasis.sets ∧ V • W ⊆ U [PROOFSTEP] rcases smul U_in with ⟨V, V_in, W, W_in, H⟩ [GOAL] case intro.intro.intro.intro R✝ : Type u_1 M✝ : Type u_2 inst✝⁶ : CommRing R✝ inst✝⁵ : TopologicalSpace R✝ inst✝⁴ : AddCommGroup M✝ inst✝³ : Module R✝ M✝ B : ModuleFilterBasis R✝ M✝ R : Type u_3 M : Type u_4 inst✝² : CommRing R inst✝¹ : AddCommGroup M inst✝ : Module R M BR : RingFilterBasis R BM : AddGroupFilterBasis M smul : ∀ {U : Set M}, U ∈ BM → ∃ V, V ∈ BR ∧ ∃ W, W ∈ BM ∧ V • W ⊆ U smul_left : ∀ (x₀ : R) {U : Set M}, U ∈ BM → ∃ V, V ∈ BM ∧ V ⊆ (fun x => x₀ • x) ⁻¹' U smul_right : ∀ (m₀ : M) {U : Set M}, U ∈ BM → ∃ V, V ∈ BR ∧ V ⊆ (fun x => x • m₀) ⁻¹' U x✝ : TopologicalSpace R := RingFilterBasis.topology BR U : Set M U_in : U ∈ AddGroupFilterBasis.toFilterBasis.sets V : Set R V_in : V ∈ BR W : Set M W_in : W ∈ BM H : V • W ⊆ U ⊢ ∃ V, V ∈ 𝓝 0 ∧ ∃ W, W ∈ AddGroupFilterBasis.toFilterBasis.sets ∧ V • W ⊆ U [PROOFSTEP] exact ⟨V, BR.toAddGroupFilterBasis.mem_nhds_zero V_in, W, W_in, H⟩ [GOAL] R✝ : Type u_1 M✝ : Type u_2 inst✝⁶ : CommRing R✝ inst✝⁵ : TopologicalSpace R✝ inst✝⁴ : AddCommGroup M✝ inst✝³ : Module R✝ M✝ B : ModuleFilterBasis R✝ M✝ R : Type u_3 M : Type u_4 inst✝² : CommRing R inst✝¹ : AddCommGroup M inst✝ : Module R M BR : RingFilterBasis R BM : AddGroupFilterBasis M smul : ∀ {U : Set M}, U ∈ BM → ∃ V, V ∈ BR ∧ ∃ W, W ∈ BM ∧ V • W ⊆ U smul_left : ∀ (x₀ : R) {U : Set M}, U ∈ BM → ∃ V, V ∈ BM ∧ V ⊆ (fun x => x₀ • x) ⁻¹' U smul_right : ∀ (m₀ : M) {U : Set M}, U ∈ BM → ∃ V, V ∈ BR ∧ V ⊆ (fun x => x • m₀) ⁻¹' U x✝ : TopologicalSpace R := RingFilterBasis.topology BR ⊢ ∀ (m₀ : M) {U : Set M}, U ∈ AddGroupFilterBasis.toFilterBasis.sets → ∀ᶠ (x : R) in 𝓝 0, x • m₀ ∈ U [PROOFSTEP] intro m₀ U U_in [GOAL] R✝ : Type u_1 M✝ : Type u_2 inst✝⁶ : CommRing R✝ inst✝⁵ : TopologicalSpace R✝ inst✝⁴ : AddCommGroup M✝ inst✝³ : Module R✝ M✝ B : ModuleFilterBasis R✝ M✝ R : Type u_3 M : Type u_4 inst✝² : CommRing R inst✝¹ : AddCommGroup M inst✝ : Module R M BR : RingFilterBasis R BM : AddGroupFilterBasis M smul : ∀ {U : Set M}, U ∈ BM → ∃ V, V ∈ BR ∧ ∃ W, W ∈ BM ∧ V • W ⊆ U smul_left : ∀ (x₀ : R) {U : Set M}, U ∈ BM → ∃ V, V ∈ BM ∧ V ⊆ (fun x => x₀ • x) ⁻¹' U smul_right : ∀ (m₀ : M) {U : Set M}, U ∈ BM → ∃ V, V ∈ BR ∧ V ⊆ (fun x => x • m₀) ⁻¹' U x✝ : TopologicalSpace R := RingFilterBasis.topology BR m₀ : M U : Set M U_in : U ∈ AddGroupFilterBasis.toFilterBasis.sets ⊢ ∀ᶠ (x : R) in 𝓝 0, x • m₀ ∈ U [PROOFSTEP] rcases smul_right m₀ U_in with ⟨V, V_in, H⟩ [GOAL] case intro.intro R✝ : Type u_1 M✝ : Type u_2 inst✝⁶ : CommRing R✝ inst✝⁵ : TopologicalSpace R✝ inst✝⁴ : AddCommGroup M✝ inst✝³ : Module R✝ M✝ B : ModuleFilterBasis R✝ M✝ R : Type u_3 M : Type u_4 inst✝² : CommRing R inst✝¹ : AddCommGroup M inst✝ : Module R M BR : RingFilterBasis R BM : AddGroupFilterBasis M smul : ∀ {U : Set M}, U ∈ BM → ∃ V, V ∈ BR ∧ ∃ W, W ∈ BM ∧ V • W ⊆ U smul_left : ∀ (x₀ : R) {U : Set M}, U ∈ BM → ∃ V, V ∈ BM ∧ V ⊆ (fun x => x₀ • x) ⁻¹' U smul_right : ∀ (m₀ : M) {U : Set M}, U ∈ BM → ∃ V, V ∈ BR ∧ V ⊆ (fun x => x • m₀) ⁻¹' U x✝ : TopologicalSpace R := RingFilterBasis.topology BR m₀ : M U : Set M U_in : U ∈ AddGroupFilterBasis.toFilterBasis.sets V : Set R V_in : V ∈ BR H : V ⊆ (fun x => x • m₀) ⁻¹' U ⊢ ∀ᶠ (x : R) in 𝓝 0, x • m₀ ∈ U [PROOFSTEP] exact mem_of_superset (BR.toAddGroupFilterBasis.mem_nhds_zero V_in) H
-- broken since the clocks are not supposed to be freely instantiable open import guarded-recursion.prelude renaming (O to zero; S to suc) open Coe module guarded-recursion.clocks (Clk : Type) (▹ : ∀ {a} → Clk → Set a → Set a) (▹′ : ∀ {a} κ → ▹ κ (Set a) → Set a) --▹′ κ A = ▹ κ A (next : ∀ {κ a} {A : Set a} → A → ▹ κ A) (▹′-rule : ∀ {κ a} {A : Set a} → ▹′ κ (next A) ≡ ▹ κ A) -- (▹′-rule : ∀ {a} {A : Set a} → ▹′ ∘ next ≡ ▹_ {A}) (fix : ∀ {κ a} {A : Set a} → (▹ κ A → A) → A) (fix-rule : ∀ {κ a} {A : Set a} {f : ▹ κ A → A} → fix f ≡ f (next (fix f))) (_⊛_ : ∀ {κ a b} {A : Set a} {B : Set b} → ▹ κ (A → B) → ▹ κ A → ▹ κ B) (fix-uniq : ∀ {κ a} {A : Set a} (u : A) (f : ▹ κ A → A) → u ≡ f (next u) → u ≡ fix f) (next⊛next : ∀ {κ a b} {A : Set a} {B : Set b} (f : A → B) (x : A) → next f ⊛ next x ≡ next {κ} (f x)) where roll▹′ : ∀ {κ a} {A : Set a} → ▹ κ A → ▹′ κ (next A) roll▹′ = coe! ▹′-rule un▹′ : ∀ {κ a} {A : Set a} → ▹′ κ (next A) → ▹ κ A un▹′ = coe ▹′-rule ▹Fix : ∀ {a} → Clk → Set a → Set a ▹Fix κ X = (▹ κ X → X) → X ▹Endo : ∀ {a} → Clk → Set a → Set a ▹Endo κ X = ▹ κ X → X μ : ∀ {a} → Fix (Set a) μ F = ∀ {κ} → fix (F ∘ ▹′ κ) un : ∀ {κ a f} → fix {κ} {A = Set a} f → f (next (fix f)) un = coe fix-rule {- unμ : ∀ {κ a} f → μ {a} f → f (▹ κ (μ f)) unμ {κ} {a} f x rewrite sym (▹′-rule {κ} {A = μ f}) = {!un {κ} x!} -} roll : ∀ {κ a f} → f (next (fix f)) → fix {κ} {A = Set a} f roll = coe! fix-rule {- μ-rule : ∀ {κ a} f → μ {a} f ≡ f (▹ κ (μ f)) μ-rule f = {!trans fix-rule (cong f (▹′-rule {A = μ f}))!} -} {- rollμ : ∀ {a} f → (∀ {κ} → f (▹ κ (μ f))) → μ {a} f rollμ f x {κ} = {!roll (x {κ})!} -- rollμ f = subst id (sym (μ-rule f)) -} un₁ : ∀ {κ a b} {A : Set a} {f x} → fix {κ} {A = A → Set b} f x → f (next (fix f)) x un₁ = coe₁ fix-rule roll₁ : ∀ {κ a b} {A : Set a} {f x} → f (next (fix f)) x → fix {κ} {A = A → Set b} f x roll₁ = coe₁! fix-rule un₂ : ∀ {κ a b} {A : Set a} {B : Set b} {c f x y} → fix {κ} {A = A → B → Set c} f x y → f (next (fix f)) x y un₂ = coe₂ fix-rule roll₂ : ∀ {κ a b} {A : Set a} {B : Set b} {c f x y} → f (next (fix f)) x y → fix {κ} {A = A → B → Set c} f x y roll₂ = coe₂! fix-rule map▹ : ∀ {κ a b} {A : Set a} {B : Set b} → (A → B) → ▹ κ A → ▹ κ B map▹ f ▹x = next f ⊛ ▹x _⊛′_ : ∀ {κ a b} {A : Set a} {B : A → Set b} → ▹ κ ((x : A) → B x) → (x : A) → ▹ κ (B x) ▹f ⊛′ x = map▹ (λ f → f x) ▹f module SimpleStream where F : Type → Type → Type F A X = A × X S : Type → Type S A = μ (F A) {- data IsStream (s : S A) : Type where -- cons : ∀ x xs → IsStream xs → IsStream (cons x xs) cons : ∀ x xs → (▹ IsStream) ⊛ next xs → IsStream (cons x xs) cons : ∀ x xs → ▹ (IsStream xs) → IsStream (cons x xs) -} μ₁F' : ∀ {κ a} {A : Set a} → ((A → ▹ κ Type) → A → Type) → (▹ κ (A → Type) → A → Type) μ₁F' F self = F (λ x → (self ⊛ next x)) μ₁F : ∀ {κ a} {A : Set a} → ((A → Type) → A → Type) → (▹ κ (A → Type) → A → Type) μ₁F F self = F (λ x → ▹′ _ (self ⊛ next x)) -- μ₁ : Fix (Endo Type) μ₁ : ∀ {a} {A : Set a} → ((A → Type) → A → Type) → A → Type μ₁ F x = ∀ {κ} → fix (μ₁F {κ} F) x module μId where μid : Type μid = μ id {- μid-rule : μid ≡ (∀ {κ} → ▹ κ μid) μid-rule = {!trans fix-rule (▹′-rule {A = μ id})!} -} {- ω : μid ω = fix (rollμ id) -}
-- | -- Module : Conjure.Conjurable -- Copyright : (c) 2021 Rudy Matela -- License : 3-Clause BSD (see the file LICENSE) -- Maintainer : Rudy Matela <[email protected]> -- -- This module is part of "Conjure". -- -- This defines the 'Conjurable' typeclass -- and utilities involving it. -- -- You are probably better off importing "Conjure". module Conjure.Conjurable ( Reification1 , Reification , Conjurable (..) , conjureType , reifyTiers , reifyEquality , reifyExpress , conjureApplication , conjureVarApplication , conjurePats , conjureHoles , conjureTiersFor , conjureAreEqual , conjureMkEquation , A, B, C, D, E, F , conjureIsDeconstructor , conjureIsDeconstruction , candidateDeconstructionsFrom , conjureIsUnbreakable , conjureReification , conjureReification1 , conjureDynamicEq , cevaluate , ceval , cevl , Name (..) , Express (..) ) where import Test.LeanCheck import Test.LeanCheck.Utils import Test.LeanCheck.Error (errorToFalse) import Conjure.Expr hiding (application) import Conjure.Defn import Test.Speculate.Expr import Data.Functor ((<$>)) import Control.Applicative ((<*>)) import Data.Dynamic import Data.Express import Data.Int -- for instances import Data.Word -- for instances import Data.Ratio -- for instance import Data.Complex -- for instance -- | Single reification of some functions over a type as 'Expr's. -- -- This is a sixtuple, in order: -- -- 1. a hole encoded as an 'Expr'; -- 2. the '==' function encoded as an 'Expr' when available; -- 3. 'tiers' of enumerated test values encoded as 'Expr's when available; -- 4. infinite list of potential variable names; -- 5. boolean indicating whether the type is atomic; -- 6. the 'conjureSize' function encoded as an 'Expr'. type Reification1 = (Expr, Maybe Expr, Maybe [[Expr]], [String], Bool, Expr) -- | A reification over a collection of types. -- -- Represented as a transformation of a list to a list. type Reification = [Reification1] -> [Reification1] -- | A primtive expression (paired with instance reification). type Prim = (Expr, Reification) -- | Provides a primitive value to Conjure. -- To be used on 'Show' instances. -- (cf. 'prim') pr :: (Conjurable a, Show a) => a -> Prim pr x = (val x, conjureType x) -- | Provides a primitive value to Conjure. -- To be used on values that are not 'Show' instances -- such as functions. -- (cf. 'pr') prim :: Conjurable a => String -> a -> Prim prim s x = (value s x, conjureType x) -- | Class of 'Conjurable' types. -- Functions are 'Conjurable' -- if all their arguments are 'Conjurable', 'Listable' and 'Show'able. -- -- For atomic types that are 'Listable', -- instances are defined as: -- -- > instance Conjurable Atomic where -- > conjureTiers = reifyTiers -- -- For atomic types that are both 'Listable' and 'Eq', -- instances are defined as: -- -- > instance Conjurable Atomic where -- > conjureTiers = reifyTiers -- > conjureEquality = reifyEquality -- -- For types with subtypes, -- instances are defined as: -- -- > instance Conjurable Composite where -- > conjureTiers = reifyTiers -- > conjureEquality = reifyEquality -- > conjureSubTypes x = conjureType y -- > . conjureType z -- > . conjureType w -- > where -- > (Composite ... y ... z ... w ...) = x -- -- Above @x@, @y@, @z@ and @w@ are just proxies. -- The @Proxy@ type was avoided for backwards compatibility. -- -- Please see the source code of "Conjure.Conjurable" for more examples. -- -- (cf. 'reifyTiers', 'reifyEquality', 'conjureType') class (Typeable a, Name a) => Conjurable a where conjureArgumentHoles :: a -> [Expr] conjureArgumentHoles _ = [] -- | Returns 'Just' the '==' function encoded as an 'Expr' when available -- or 'Nothing' otherwise. -- -- Use 'reifyEquality' when defining this. conjureEquality :: a -> Maybe Expr conjureEquality _ = Nothing -- | Returns 'Just' 'tiers' of values encoded as 'Expr's when possible -- or 'Nothing' otherwise. -- -- Use 'reifyTiers' when defining this. conjureTiers :: a -> Maybe [[Expr]] conjureTiers _ = Nothing conjureSubTypes :: a -> Reification conjureSubTypes _ = id -- | Returns an if-function encoded as an 'Expr'. conjureIf :: a -> Expr conjureIf = ifFor -- | Returns a top-level case breakdown. conjureCases :: a -> [Expr] conjureCases _ = [] conjureArgumentCases :: a -> [[Expr]] conjureArgumentCases _ = [] -- | Returns the (recursive) size of the given value. conjureSize :: a -> Int conjureSize _ = 0 -- | Returns a function that deeply reencodes an expression when possible. -- ('id' when not available.) -- -- Use 'reifyExpress' when defining this. conjureExpress :: a -> Expr -> Expr conjureEvaluate :: (Expr->Expr) -> Int -> Defn -> Expr -> Maybe a conjureEvaluate = devaluate -- | To be used in the implementation of 'conjureSubTypes'. -- -- > instance ... => Conjurable <Type> where -- > ... -- > conjureSubTypes x = conjureType (field1 x) -- > . conjureType (field2 x) -- > . ... -- > . conjureType (fieldN x) -- > ... conjureType :: Conjurable a => a -> Reification conjureType x ms = if hole x `elem` [h | (h,_,_,_,_,_) <- ms] then ms else conjureSubTypes x $ conjureReification1 x : ms -- | like 'conjureType' but without type repetitions nubConjureType :: Conjurable a => a -> Reification nubConjureType x = nubOn (\(eh,_,_,_,_,_) -> eh) . conjureType x -- The use of nubOn above is O(n^2). -- So long as there is not a huge number of subtypes of a, so we're fine. -- | Conjures a 'Reification1' for a 'Conjurable' type. -- -- This is used in the implementation of 'conjureReification'. conjureReification1 :: Conjurable a => a -> Reification1 conjureReification1 x = (hole x, conjureEquality x, conjureTiers x, names x, null $ conjureCases x, value "conjureSize" (conjureSize -:> x)) -- | Conjures a list of 'Reification1' -- for a 'Conjurable' type, its subtypes and 'Bool'. -- -- This is used in the implementation of -- 'conjureHoles', -- 'conjureMkEquation', -- 'conjureAreEqual', -- 'conjureTiersFor', -- 'conjureIsDeconstructor', -- 'conjureNamesFor', -- 'conjureIsUnbreakable', -- etc. conjureReification :: Conjurable a => a -> [Reification1] conjureReification x = nubConjureType x [conjureReification1 bool] where bool :: Bool bool = error "conjureReification: evaluated proxy boolean value (definitely a bug)" -- | Reifies equality '==' in a 'Conjurable' type instance. -- -- This is to be used -- in the definition of 'conjureEquality' -- of 'Conjurable' typeclass instances: -- -- > instance ... => Conjurable <Type> where -- > ... -- > conjureEquality = reifyEquality -- > ... reifyEquality :: (Eq a, Typeable a) => a -> Maybe Expr reifyEquality = Just . head . reifyEq -- | Reifies equality to be used in a conjurable type. -- -- This is to be used -- in the definition of 'conjureTiers' -- of 'Conjurable' typeclass instances: -- -- > instance ... => Conjurable <Type> where -- > ... -- > conjureTiers = reifyTiers -- > ... reifyTiers :: (Listable a, Show a, Typeable a) => a -> Maybe [[Expr]] reifyTiers = Just . mkExprTiers -- | Reifies the 'expr' function in a 'Conjurable' type instance. -- -- This is to be used -- in the definition of 'conjureExpress' -- of 'Conjurable' typeclass instances. -- -- > instance ... => Conjurable <Type> where -- > ... -- > conjureExpress = reifyExpress -- > ... reifyExpress :: (Express a, Show a) => a -> Expr -> Expr reifyExpress a e = case value "expr" (expr -:> a) $$ e of Nothing -> e -- TODO: consider throwing an error Just e' -> eval e e' -- TODO: consider throwing an error mkExprTiers :: (Listable a, Show a, Typeable a) => a -> [[Expr]] mkExprTiers a = mapT val (tiers -: [[a]]) -- | Computes a list of holes encoded as 'Expr's -- from a 'Conjurable' functional value. -- -- (cf. 'Conjure.Prim.cjHoles') conjureHoles :: Conjurable f => f -> [Expr] conjureHoles f = [eh | (eh,_,Just _,_,_,_) <- conjureReification f] -- | Computes a function that makes an equation between two expressions. conjureMkEquation :: Conjurable f => f -> Expr -> Expr -> Expr conjureMkEquation f = mkEquation [eq | (_,Just eq,_,_,_,_) <- conjureReification f] conjureDynamicEq :: Conjurable f => f -> Dynamic conjureDynamicEq f = case conjureMkEquation f efxs efxs of (Value "==" deq :$ _ :$ _) -> deq _ -> error "conjureDynamicEq: expected an == but found something else. Bug!" where efxs = conjureApplication "f" f -- | Given a 'Conjurable' functional value, -- computes a function that checks whether two 'Expr's are equal -- up to a given number of tests. conjureAreEqual :: Conjurable f => f -> Int -> Expr -> Expr -> Bool conjureAreEqual f maxTests = (===) where (-==-) = conjureMkEquation f e1 === e2 = isTrue $ e1 -==- e2 isTrue = all (errorToFalse . eval False) . gs gs = take maxTests . grounds (conjureTiersFor f) -- | Compute 'tiers' of values encoded as 'Expr's -- of the type of the given 'Expr'. conjureTiersFor :: Conjurable f => f -> Expr -> [[Expr]] conjureTiersFor f e = tf allTiers where allTiers :: [ [[Expr]] ] allTiers = [etiers | (_,_,Just etiers,_,_,_) <- conjureReification f] tf [] = [[e]] -- no tiers found, keep variable tf (etiers:etc) = case etiers of ((e':_):_) | typ e' == typ e -> etiers _ -> tf etc -- | Compute variable names for the given 'Expr' type. conjureNamesFor :: Conjurable f => f -> Expr -> [String] conjureNamesFor f e = head $ [ns | (eh, _, _, ns, _, _) <- conjureReification f, typ e == typ eh] ++ [names (undefined :: Int)] -- use [Int] on lists conjureMostGeneralCanonicalVariation :: Conjurable f => f -> Expr -> Expr conjureMostGeneralCanonicalVariation f = canonicalizeWith (conjureNamesFor f) . fastMostGeneralVariation -- | Checks if an unary function encoded as an 'Expr' is a deconstructor. -- -- (cf. 'conjureIsDeconstruction') conjureIsDeconstructor :: Conjurable f => f -> Int -> Expr -> Bool conjureIsDeconstructor f maxTests e = case as of [] -> False (h:_) -> isDec h where as = [h | h <- hs, isWellTyped (e:$h), typ (e:$h) == typ h] hs = conjureArgumentHoles f isDec h = count is gs >= length gs `div` 2 where gs = take maxTests $ grounds (conjureTiersFor f) h sz = head [sz | (_, _, _, _, _, sz) <- conjureReification f , isWellTyped (sz :$ h)] esz e = eval (0::Int) (sz :$ e) is e' = errorToFalse $ esz (e :$ e') < esz e' -- | Checks if an expression is a deconstruction. -- -- There should be a single 'hole' in the expression. -- -- 1. The result does not increase the size for at least half the time. -- 2. The result decreases in size for at least a third of the time. -- -- (cf. 'conjureIsDeconstructor') conjureIsDeconstruction :: Conjurable f => f -> Int -> Expr -> Bool conjureIsDeconstruction f maxTests ed = length (holes ed) == 1 && typ h == typ ed && count is gs >= length gs `div` 2 && count iz gs >= length gs `div` 3 where gs = take maxTests $ grounds (conjureTiersFor f) ed [h] = holes ed sz = head [sz | (_, _, _, _, _, sz) <- conjureReification f , isWellTyped (sz :$ h)] esz e = eval (0::Int) (sz :$ e) is e = errorToFalse $ esz e <= esz (holeValue e) iz e = errorToFalse $ esz e < esz (holeValue e) holeValue e = fromMaybe err . lookup h . fromMaybe err $ e `match` ed err = error "conjureIsDeconstructor: the impossible happened" -- | Compute candidate deconstructions from an 'Expr'. -- -- This is used in the implementation of -- 'Conjure.Engine.candidateDefnsC' and 'Conjure.Engine.candidateExprs' -- followed by 'conjureIsDeconstruction'. candidateDeconstructionsFrom :: Expr -> [Expr] candidateDeconstructionsFrom e = [ e' | v <- vars e , typ v == typ e , let e' = e //- [(v, holeAsTypeOf v)] , length (holes e') == 1 ] -- | Checks if an 'Expr' is of an unbreakable type. conjureIsUnbreakable :: Conjurable f => f -> Expr -> Bool conjureIsUnbreakable f e = head [is | (h,_,_,_,is,_) <- conjureReification f, typ h == typ e] instance Conjurable () where conjureExpress = reifyExpress conjureEquality = reifyEquality conjureTiers = reifyTiers conjureCases _ = [val ()] instance Conjurable Bool where conjureExpress = reifyExpress conjureEquality = reifyEquality conjureTiers = reifyTiers conjureCases _ = [val False, val True] instance Conjurable Int where conjureExpress = reifyExpress conjureEquality = reifyEquality conjureTiers = reifyTiers conjureSize = abs instance Conjurable Integer where conjureExpress = reifyExpress conjureEquality = reifyEquality conjureTiers = reifyTiers conjureSize = fromIntegral . abs instance Conjurable Char where conjureExpress = reifyExpress conjureEquality = reifyEquality conjureTiers = reifyTiers -- bind equality to the given argument type (==:) :: (a -> a -> Bool) -> a -> (a -> a -> Bool) (==:) = const -- the reconstruction of equality functions for polymorphic types -- such as [a], (a,b), Maybe a, Either a b -- is only needed so we don't impose an Eq restriction on the type context. instance (Conjurable a, Listable a, Express a, Show a) => Conjurable [a] where conjureExpress = reifyExpress conjureSubTypes xs = conjureType (head xs) conjureTiers = reifyTiers conjureSize = length conjureCases xs = [ val ([] -: xs) , value ":" ((:) ->>: xs) :$ hole x :$ hole xs ] where x = head xs conjureEquality xs = from <$> conjureEquality x where x = head xs from e = value "==" (==) where (.==.) = evl e ==: x [] == [] = True (x:xs) == [] = False [] == (y:ys) = False (x:xs) == (y:ys) = x .==. y && xs == ys instance ( Conjurable a, Listable a, Show a, Express a , Conjurable b, Listable b, Show b, Express b ) => Conjurable (a,b) where conjureExpress = reifyExpress conjureTiers = reifyTiers conjureSubTypes xy = conjureType (fst xy) . conjureType (snd xy) conjureCases xy = [value "," ((,) ->>: xy) :$ hole x :$ hole y] where (x,y) = (undefined,undefined) -: xy conjureEquality xy = from <$> conjureEquality x <*> conjureEquality y where (x,y) = xy from e1 e2 = value "==" (==) where (==.) = evl e1 ==: x (.==) = evl e2 ==: y (x1,y1) == (x2,y2) = x1 ==. x2 && y1 .== y2 instance ( Conjurable a, Listable a, Show a, Express a , Conjurable b, Listable b, Show b, Express b , Conjurable c, Listable c, Show c, Express c ) => Conjurable (a,b,c) where conjureExpress = reifyExpress conjureTiers = reifyTiers conjureSubTypes xyz = conjureType x . conjureType y . conjureType z where (x,y,z) = xyz conjureCases xyz = [value ",," ((,,) ->>>: xyz) :$ hole x :$ hole y :$ hole z] where (x,y,z) = (undefined,undefined,undefined) -: xyz conjureEquality xyz = from <$> conjureEquality x <*> conjureEquality y <*> conjureEquality z where (x,y,z) = xyz from e1 e2 e3 = value "==" (==) where (==..) = evl e1 ==: x (.==.) = evl e2 ==: y (..==) = evl e3 ==: z (x1,y1,z1) == (x2,y2,z2) = x1 ==.. x2 && y1 .==. y2 && z1 ..== z2 instance (Conjurable a, Listable a, Show a, Express a) => Conjurable (Maybe a) where conjureExpress = reifyExpress conjureTiers = reifyTiers conjureSubTypes mx = conjureType (fromJust mx) conjureCases mx = [ value "Nothing" (Nothing -: mx) , value "Just" (Just ->: mx) :$ hole x ] where x = Just undefined -: mx conjureEquality mx = from <$> conjureEquality x where x = fromJust mx from e = value "==" (==) where (.==.) = evl e ==: x Nothing == Nothing = True Nothing == (Just _) = False (Just _) == Nothing = False (Just x) == (Just y) = x .==. y instance ( Conjurable a, Listable a, Show a, Express a , Conjurable b, Listable b, Show b, Express b ) => Conjurable (Either a b) where conjureExpress = reifyExpress conjureTiers = reifyTiers conjureSubTypes elr = conjureType l . conjureType r where Left l = elr Right r = elr conjureCases exy = [ value "Left" (Left ->: exy) :$ hole x , value "Right" (Right ->: exy) :$ hole y ] where x = Left undefined -: exy y = Right undefined -: exy conjureEquality elr = from <$> conjureEquality l <*> conjureEquality r where Left l = elr Right r = elr from el er = value "==" (==) where (==.) = evl el ==: l (.==) = evl er ==: r (Left x) == (Left y) = x ==. y (Left _) == (Right _) = False (Right _) == (Left _) = False (Right x) == (Right y) = x .== y instance (Conjurable a, Conjurable b) => Conjurable (a -> b) where conjureArgumentHoles f = hole (argTy f) : conjureArgumentHoles (f undefined) conjureSubTypes f = conjureType (argTy f) . conjureType (resTy f) conjureIf f = conjureIf (f undefined) conjureArgumentCases f = conjureCases (argTy f) : conjureArgumentCases (f undefined) conjureExpress f e | typ e == typeOf (argTy f) = conjureExpress (argTy f) e | otherwise = conjureExpress (f undefined) e conjureEvaluate exprExpr mx defn ef = mf where ce = conjureEvaluate exprExpr mx defn mf = case ce (holeAsTypeOf ef :$ hole x) -: Just (f x) of Nothing -> Nothing Just _ -> Just $ \x -> fromMaybe err . ce $ ef :$ exprExpr (value "" x) f = undefined -: fromJust mf x = argTy f err = error "conjureEvaluate (a->b): BUG! This should never be evaluated as it is protected by the outer case." argTy :: (a -> b) -> a argTy _ = undefined resTy :: (a -> b) -> b resTy _ = undefined -- | Evaluates a 'Defn' into a regular Haskell value -- returning 'Nothing' when there's a type mismatch. -- -- The integer argument indicates the limit of recursive evaluations. cevaluate :: Conjurable f => Int -> Defn -> Maybe f cevaluate mx defn = mr where mr = conjureEvaluate exprExpr mx defn ef' exprExpr = conjureExpress $ fromJust mr (ef':_) = unfoldApp . fst $ head defn -- | Evaluates a 'Defn' into a regular Haskell value -- returning the given default value when there's a type mismatch. -- -- The integer argument indicates the limit of recursive evaluations. ceval :: Conjurable f => Int -> f -> Defn -> f ceval mx z = fromMaybe z . cevaluate mx -- | Evaluates a 'Defn' into a regular Haskell value -- raising an error there's a type mismatch. -- -- The integer argument indicates the limit of recursive evaluations. cevl :: Conjurable f => Int -> Defn -> f cevl mx = ceval mx err where err = error "cevl: type mismatch" -- | Computes a complete application for the given function. -- -- > > conjureApplication "not" not -- > not p :: Bool -- -- > > conjureApplication "+" ((+) :: Int -> Int -> Int) -- > x + y :: Int -- -- (cf. 'conjureVarApplication') conjureApplication :: Conjurable f => String -> f -> Expr conjureApplication = conjureWhatApplication value -- | Computes a complete application for a variable -- of the same type of the given function. -- -- > > conjureVarApplication "not" not -- > not p :: Bool -- -- > > conjureVarApplication "+" ((+) :: Int -> Int -> Int) -- > x + y :: Int -- -- (cf. 'conjureApplication') conjureVarApplication :: Conjurable f => String -> f -> Expr conjureVarApplication = conjureWhatApplication var -- | Used in the implementation of 'conjureApplication' and 'conjureVarApplication'. conjureWhatApplication :: Conjurable f => (String -> f -> Expr) -> String -> f -> Expr conjureWhatApplication what nm f = mostGeneralCanonicalVariation . foldApp $ what nf f : zipWith varAsTypeOf nas (conjureArgumentHoles f) where (nf:nas) = words nm ++ repeat "" -- | Computes tiers of sets of patterns for the given function. -- -- > > conjurePats [zero] "f" (undefined :: Int -> Int) -- > [[[f x :: Int]],[[f 0 :: Int,f x :: Int]]] conjurePats :: Conjurable f => [Expr] -> String -> f -> [[ [Expr] ]] conjurePats es nm f = mapT (map mkApp . prods) $ cs where mkApp = foldApp . (ef:) . unfold . conjureMostGeneralCanonicalVariation f . fold ef = var (head $ words nm) f -- TODO: take the tail into account cs = products $ zipWith mk (conjureArgumentHoles f) (conjureArgumentCases f) mk h [] = mapT (++ [h]) $ setsOf [[e] | e <- es, typ e == typ h] mk h cs = [[[h]], [cs]] tiersFor = conjureTiersFor f prods :: [[a]] -> [[a]] prods = foldr (productWith (:)) [[]] where productWith (?) xs ys = [x ? y | x <- xs, y <- ys] -- -- -- other Conjurable instances -- -- -- instance Conjurable Ordering where conjureExpress = reifyExpress conjureEquality = reifyEquality conjureTiers = reifyTiers instance Conjurable Float where conjureExpress = reifyExpress conjureEquality = reifyEquality conjureTiers = reifyTiers conjureSize = round instance Conjurable Double where conjureExpress = reifyExpress conjureEquality = reifyEquality conjureTiers = reifyTiers conjureSize = round instance Conjurable Int8 where conjureExpress = reifyExpress conjureEquality = reifyEquality conjureTiers = reifyTiers conjureSize = fromIntegral . abs instance Conjurable Int16 where conjureExpress = reifyExpress conjureEquality = reifyEquality conjureTiers = reifyTiers conjureSize = fromIntegral . abs instance Conjurable Int32 where conjureExpress = reifyExpress conjureEquality = reifyEquality conjureTiers = reifyTiers conjureSize = fromIntegral . abs instance Conjurable Int64 where conjureExpress = reifyExpress conjureEquality = reifyEquality conjureTiers = reifyTiers conjureSize = fromIntegral . abs instance Conjurable Word where conjureExpress = reifyExpress conjureEquality = reifyEquality conjureTiers = reifyTiers conjureSize = fromIntegral . abs instance Conjurable Word8 where conjureExpress = reifyExpress conjureEquality = reifyEquality conjureTiers = reifyTiers conjureSize = fromIntegral . abs instance Conjurable Word16 where conjureExpress = reifyExpress conjureEquality = reifyEquality conjureTiers = reifyTiers conjureSize = fromIntegral . abs instance Conjurable Word32 where conjureExpress = reifyExpress conjureEquality = reifyEquality conjureTiers = reifyTiers conjureSize = fromIntegral . abs instance Conjurable Word64 where conjureExpress = reifyExpress conjureEquality = reifyEquality conjureTiers = reifyTiers conjureSize = fromIntegral . abs instance (Integral a, Conjurable a, Listable a, Show a, Eq a, Express a) => Conjurable (Ratio a) where conjureExpress = reifyExpress conjureEquality = reifyEquality conjureTiers = reifyTiers conjureSize q = conjureSize (numerator q) + conjureSize (denominator q) conjureSubTypes q = conjureType (numerator q) conjureCases q = [value "%" ((%) ->>: q) :$ hole n :$ hole d] where n = numerator q d = denominator q instance (RealFloat a, Conjurable a, Listable a, Show a, Eq a, Express a) => Conjurable (Complex a) where conjureExpress = reifyExpress conjureEquality = reifyEquality conjureTiers = reifyTiers conjureSize x = conjureSize (realPart x) + conjureSize (imagPart x) conjureSubTypes x = conjureType (realPart x) -- Conjurable helper types -- instance Conjurable A where conjureExpress = reifyExpress conjureEquality = reifyEquality conjureTiers = reifyTiers conjureSize = fromIntegral . abs instance Conjurable B where conjureExpress = reifyExpress conjureEquality = reifyEquality conjureTiers = reifyTiers conjureSize = fromIntegral . abs instance Conjurable C where conjureExpress = reifyExpress conjureEquality = reifyEquality conjureTiers = reifyTiers conjureSize = fromIntegral . abs instance Conjurable D where conjureExpress = reifyExpress conjureEquality = reifyEquality conjureTiers = reifyTiers conjureSize = fromIntegral . abs instance Conjurable E where conjureExpress = reifyExpress conjureEquality = reifyEquality conjureTiers = reifyTiers conjureSize = fromIntegral . abs instance Conjurable F where conjureExpress = reifyExpress conjureEquality = reifyEquality conjureTiers = reifyTiers conjureSize = fromIntegral . abs -- Conjurable tuples -- instance ( Conjurable a, Listable a, Show a, Express a , Conjurable b, Listable b, Show b, Express b , Conjurable c, Listable c, Show c, Express c , Conjurable d, Listable d, Show d, Express d ) => Conjurable (a,b,c,d) where conjureExpress = reifyExpress conjureTiers = reifyTiers conjureSubTypes xyzw = conjureType x . conjureType y . conjureType z . conjureType w where (x,y,z,w) = xyzw conjureEquality xyzw = from <$> conjureEquality x <*> conjureEquality y <*> conjureEquality z <*> conjureEquality w where (x,y,z,w) = xyzw from e1 e2 e3 e4 = value "==" (==) where (==...) = evl e1 ==: x (.==..) = evl e2 ==: y (..==.) = evl e3 ==: z (...==) = evl e4 ==: w (x1,y1,z1,w1) == (x2,y2,z2,w2) = x1 ==... x2 && y1 .==.. y2 && z1 ..==. z2 && w1 ...== w2 instance ( Conjurable a, Listable a, Show a, Express a , Conjurable b, Listable b, Show b, Express b , Conjurable c, Listable c, Show c, Express c , Conjurable d, Listable d, Show d, Express d , Conjurable e, Listable e, Show e, Express e ) => Conjurable (a,b,c,d,e) where conjureExpress = reifyExpress conjureTiers = reifyTiers conjureSubTypes xyzwv = conjureType x . conjureType y . conjureType z . conjureType w . conjureType v where (x,y,z,w,v) = xyzwv conjureEquality xyzwv = from <$> conjureEquality x <*> conjureEquality y <*> conjureEquality z <*> conjureEquality w <*> conjureEquality v where (x,y,z,w,v) = xyzwv from e1 e2 e3 e4 e5 = value "==" (==) where (==....) = evl e1 ==: x (.==...) = evl e2 ==: y (..==..) = evl e3 ==: z (...==.) = evl e4 ==: w (....==) = evl e5 ==: v (x1,y1,z1,w1,v1) == (x2,y2,z2,w2,v2) = x1 ==.... x2 && y1 .==... y2 && z1 ..==.. z2 && w1 ...==. w2 && v1 ....== v2 instance ( Conjurable a, Listable a, Show a, Express a , Conjurable b, Listable b, Show b, Express b , Conjurable c, Listable c, Show c, Express c , Conjurable d, Listable d, Show d, Express d , Conjurable e, Listable e, Show e, Express e , Conjurable f, Listable f, Show f, Express f ) => Conjurable (a,b,c,d,e,f) where conjureExpress = reifyExpress conjureTiers = reifyTiers conjureSubTypes xyzwvu = conjureType x . conjureType y . conjureType z . conjureType w . conjureType v . conjureType u where (x,y,z,w,v,u) = xyzwvu conjureEquality xyzwvu = from <$> conjureEquality x <*> conjureEquality y <*> conjureEquality z <*> conjureEquality w <*> conjureEquality v <*> conjureEquality u where (x,y,z,w,v,u) = xyzwvu from e1 e2 e3 e4 e5 e6 = value "==" (==) where (==.....) = evl e1 ==: x (.==....) = evl e2 ==: y (..==...) = evl e3 ==: z (...==..) = evl e4 ==: w (....==.) = evl e5 ==: v (.....==) = evl e6 ==: u (x1,y1,z1,w1,v1,u1) == (x2,y2,z2,w2,v2,u2) = x1 ==..... x2 && y1 .==.... y2 && z1 ..==... z2 && w1 ...==.. w2 && v1 ....==. v2 && u1 .....== u2 instance ( Conjurable a, Listable a, Show a, Express a , Conjurable b, Listable b, Show b, Express b , Conjurable c, Listable c, Show c, Express c , Conjurable d, Listable d, Show d, Express d , Conjurable e, Listable e, Show e, Express e , Conjurable f, Listable f, Show f, Express f , Conjurable g, Listable g, Show g, Express g ) => Conjurable (a,b,c,d,e,f,g) where conjureExpress = reifyExpress conjureTiers = reifyTiers conjureSubTypes xyzwvut = conjureType x . conjureType y . conjureType z . conjureType w . conjureType v . conjureType u . conjureType t where (x,y,z,w,v,u,t) = xyzwvut conjureEquality xyzwvut = from <$> conjureEquality x <*> conjureEquality y <*> conjureEquality z <*> conjureEquality w <*> conjureEquality v <*> conjureEquality u <*> conjureEquality t where (x,y,z,w,v,u,t) = xyzwvut from e1 e2 e3 e4 e5 e6 e7 = value "==" (==) where (==......) = evl e1 ==: x (.==.....) = evl e2 ==: y (..==....) = evl e3 ==: z (...==...) = evl e4 ==: w (....==..) = evl e5 ==: v (.....==.) = evl e6 ==: u (......==) = evl e7 ==: t (x1,y1,z1,w1,v1,u1,t1) == (x2,y2,z2,w2,v2,u2,t2) = x1 ==...... x2 && y1 .==..... y2 && z1 ..==.... z2 && w1 ...==... w2 && v1 ....==.. v2 && u1 .....==. u2 && t1 ......== t2 -- TODO: go up to 12-tuples instance Name A instance Name B instance Name C instance Name D instance Name E instance Name F
/- Copyright (c) 2022 Andrew Yang. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Andrew Yang ! This file was ported from Lean 3 source module ring_theory.rees_algebra ! leanprover-community/mathlib commit 70fd9563a21e7b963887c9360bd29b2393e6225a ! Please do not edit these lines, except to modify the commit id ! if you have ported upstream changes. -/ import Mathbin.RingTheory.FiniteType /-! # Rees algebra The Rees algebra of an ideal `I` is the subalgebra `R[It]` of `R[t]` defined as `R[It] = ⨁ₙ Iⁿ tⁿ`. This is used to prove the Artin-Rees lemma, and will potentially enable us to calculate some blowup in the future. ## Main definition - `rees_algebra` : The Rees algebra of an ideal `I`, defined as a subalgebra of `R[X]`. - `adjoin_monomial_eq_rees_algebra` : The Rees algebra is generated by the degree one elements. - `rees_algebra.fg` : The Rees algebra of a f.g. ideal is of finite type. In particular, this implies that the rees algebra over a noetherian ring is still noetherian. -/ universe u v variable {R M : Type u} [CommRing R] [AddCommGroup M] [Module R M] (I : Ideal R) open Polynomial open Polynomial BigOperators /-- The Rees algebra of an ideal `I`, defined as the subalgebra of `R[X]` whose `i`-th coefficient falls in `I ^ i`. -/ def reesAlgebra : Subalgebra R R[X] where carrier := { f | ∀ i, f.coeff i ∈ I ^ i } mul_mem' f g hf hg i := by rw [coeff_mul] apply Ideal.sum_mem rintro ⟨j, k⟩ e rw [← finset.nat.mem_antidiagonal.mp e, pow_add] exact Ideal.mul_mem_mul (hf j) (hg k) one_mem' i := by rw [coeff_one] split_ifs · subst h simp · simp add_mem' f g hf hg i := by rw [coeff_add] exact Ideal.add_mem _ (hf i) (hg i) zero_mem' i := Ideal.zero_mem _ algebraMap_mem' r i := by rw [algebra_map_apply, coeff_C] split_ifs · subst h simp · simp #align rees_algebra reesAlgebra theorem mem_reesAlgebra_iff (f : R[X]) : f ∈ reesAlgebra I ↔ ∀ i, f.coeff i ∈ I ^ i := Iff.rfl #align mem_rees_algebra_iff mem_reesAlgebra_iff theorem mem_reesAlgebra_iff_support (f : R[X]) : f ∈ reesAlgebra I ↔ ∀ i ∈ f.support, f.coeff i ∈ I ^ i := by apply forall_congr' intro a rw [mem_support_iff, Iff.comm, imp_iff_right_iff, Ne.def, ← imp_iff_not_or] exact fun e => e.symm ▸ (I ^ a).zero_mem #align mem_rees_algebra_iff_support mem_reesAlgebra_iff_support theorem reesAlgebra.monomial_mem {I : Ideal R} {i : ℕ} {r : R} : monomial i r ∈ reesAlgebra I ↔ r ∈ I ^ i := by simp (config := { contextual := true }) [mem_reesAlgebra_iff_support, coeff_monomial, ← imp_iff_not_or] #align rees_algebra.monomial_mem reesAlgebra.monomial_mem theorem monomial_mem_adjoin_monomial {I : Ideal R} {n : ℕ} {r : R} (hr : r ∈ I ^ n) : monomial n r ∈ Algebra.adjoin R (Submodule.map (monomial 1 : R →ₗ[R] R[X]) I : Set R[X]) := by induction' n with n hn generalizing r · exact Subalgebra.algebraMap_mem _ _ · rw [pow_succ] at hr apply Submodule.smul_induction_on hr · intro r hr s hs rw [Nat.succ_eq_one_add, smul_eq_mul, ← monomial_mul_monomial] exact Subalgebra.mul_mem _ (Algebra.subset_adjoin (Set.mem_image_of_mem _ hr)) (hn hs) · intro x y hx hy rw [monomial_add] exact Subalgebra.add_mem _ hx hy #align monomial_mem_adjoin_monomial monomial_mem_adjoin_monomial theorem adjoin_monomial_eq_reesAlgebra : Algebra.adjoin R (Submodule.map (monomial 1 : R →ₗ[R] R[X]) I : Set R[X]) = reesAlgebra I := by apply le_antisymm · apply Algebra.adjoin_le _ rintro _ ⟨r, hr, rfl⟩ exact rees_algebra.monomial_mem.mpr (by rwa [pow_one]) · intro p hp rw [p.as_sum_support] apply Subalgebra.sum_mem _ _ rintro i - exact monomial_mem_adjoin_monomial (hp i) #align adjoin_monomial_eq_rees_algebra adjoin_monomial_eq_reesAlgebra variable {I} theorem reesAlgebra.fg (hI : I.Fg) : (reesAlgebra I).Fg := by classical obtain ⟨s, hs⟩ := hI rw [← adjoin_monomial_eq_reesAlgebra, ← hs] use s.image (monomial 1) rw [Finset.coe_image] change _ = Algebra.adjoin R (Submodule.map (monomial 1 : R →ₗ[R] R[X]) (Submodule.span R ↑s) : Set R[X]) rw [Submodule.map_span, Algebra.adjoin_span] #align rees_algebra.fg reesAlgebra.fg instance [IsNoetherianRing R] : Algebra.FiniteType R (reesAlgebra I) := ⟨(reesAlgebra I).fg_top.mpr (reesAlgebra.fg <| IsNoetherian.noetherian I)⟩ instance [IsNoetherianRing R] : IsNoetherianRing (reesAlgebra I) := Algebra.FiniteType.isNoetherianRing R _
Formal statement is: lemma affine_hull_convex_hull [simp]: "affine hull (convex hull S) = affine hull S" Informal statement is: The affine hull of the convex hull of a set $S$ is the affine hull of $S$.
lemma complex_cnj_cnj [simp]: "cnj (cnj z) = z"
module modules_08_b implicit none private public b contains integer function b() b = 5 + kind(.true.) end function end module
namespace deduction_basic class has_Hyp (Form : Type) := (Hyp : Type) [emptyHyp : has_emptyc Hyp] [insertHyp : has_insert Form Hyp] instance singleHyp {Form : Type} [hasHyp : has_Hyp Form] : has_singleton Form hasHyp.Hyp := {singleton := λ φ, hasHyp.insertHyp.insert φ hasHyp.emptyHyp.emptyc} instance lawfulSingleHyp {Form : Type} [hasHyp : has_Hyp Form] : @is_lawful_singleton Form (has_Hyp.Hyp Form) hasHyp.emptyHyp hasHyp.insertHyp deduction_basic.singleHyp := { insert_emptyc_eq := begin assume φ, refl end } class has_derives (Form : Type) extends has_Hyp Form := (derives : Hyp → Form → Prop) (derive_Trans : ∀ {Φ : Hyp} (ψ) {θ : Form}, derives Φ ψ → derives {ψ} θ → derives Φ θ) def der {Form : Type} [Der : has_derives Form] : Form → Form → Prop := λ φ ψ, has_derives.derives {φ} ψ infix `⊢`:60 := der lemma derive_trans {Form : Type} [Der : has_derives Form] : ∀ {φ : Form} (ψ) {θ}, (φ ⊢ ψ) → (ψ ⊢ θ) → (φ ⊢ θ) := begin assume φ, apply Der.derive_Trans, end class has_struct_derives (Form : Type) extends has_derives Form := [memHyp : has_mem Form Hyp] (inInsert : ∀ {φ : Form} {Φ : Hyp}, φ ∈ insert φ Φ) (hyp : ∀ {Φ} {φ}, (φ ∈ Φ) → derives Φ φ) (weak1 : ∀ {Φ} {φ} (ψ), derives Φ φ → derives (insert ψ Φ) φ) lemma derive_refl {Form : Type} [Der : has_struct_derives Form] : ∀ φ : Form, φ ⊢ φ := begin assume φ, apply Der.hyp, apply Der.inInsert, end end deduction_basic
[STATEMENT] lemma image_domain_partition_eq: assumes "f \<in> A \<rightarrow>\<^sub>E B" assumes "p\<^sub>A permutes A" shows "(\<lambda>X. p\<^sub>A ` X) ` ((\<lambda>b. {x \<in> A. f x = b}) ` B) = (\<lambda>b. {x \<in> A. f (inv p\<^sub>A x) = b}) ` B" [PROOF STATE] proof (prove) goal (1 subgoal): 1. (`) p\<^sub>A ` (\<lambda>b. {x \<in> A. f x = b}) ` B = (\<lambda>b. {x \<in> A. f (inv p\<^sub>A x) = b}) ` B [PROOF STEP] proof [PROOF STATE] proof (state) goal (2 subgoals): 1. (`) p\<^sub>A ` (\<lambda>b. {x \<in> A. f x = b}) ` B \<subseteq> (\<lambda>b. {x \<in> A. f (inv p\<^sub>A x) = b}) ` B 2. (\<lambda>b. {x \<in> A. f (inv p\<^sub>A x) = b}) ` B \<subseteq> (`) p\<^sub>A ` (\<lambda>b. {x \<in> A. f x = b}) ` B [PROOF STEP] from \<open>f \<in> A \<rightarrow>\<^sub>E B\<close> [PROOF STATE] proof (chain) picking this: f \<in> A \<rightarrow>\<^sub>E B [PROOF STEP] have "f \<in> A \<rightarrow> B" [PROOF STATE] proof (prove) using this: f \<in> A \<rightarrow>\<^sub>E B goal (1 subgoal): 1. f \<in> A \<rightarrow> B [PROOF STEP] by auto [PROOF STATE] proof (state) this: f \<in> A \<rightarrow> B goal (2 subgoals): 1. (`) p\<^sub>A ` (\<lambda>b. {x \<in> A. f x = b}) ` B \<subseteq> (\<lambda>b. {x \<in> A. f (inv p\<^sub>A x) = b}) ` B 2. (\<lambda>b. {x \<in> A. f (inv p\<^sub>A x) = b}) ` B \<subseteq> (`) p\<^sub>A ` (\<lambda>b. {x \<in> A. f x = b}) ` B [PROOF STEP] note eq = permutes_domain_partition_eq[OF \<open>f \<in> A \<rightarrow> B\<close> \<open>p\<^sub>A permutes A\<close>] [PROOF STATE] proof (state) this: ?b \<in> B \<Longrightarrow> p\<^sub>A ` {x \<in> A. f x = ?b} = {x \<in> A. f (inv p\<^sub>A x) = ?b} goal (2 subgoals): 1. (`) p\<^sub>A ` (\<lambda>b. {x \<in> A. f x = b}) ` B \<subseteq> (\<lambda>b. {x \<in> A. f (inv p\<^sub>A x) = b}) ` B 2. (\<lambda>b. {x \<in> A. f (inv p\<^sub>A x) = b}) ` B \<subseteq> (`) p\<^sub>A ` (\<lambda>b. {x \<in> A. f x = b}) ` B [PROOF STEP] show "(\<lambda>X. p\<^sub>A ` X) ` (\<lambda>b. {x \<in> A. f x = b}) ` B \<subseteq> (\<lambda>b. {x \<in> A. f (inv p\<^sub>A x) = b}) ` B" [PROOF STATE] proof (prove) goal (1 subgoal): 1. (`) p\<^sub>A ` (\<lambda>b. {x \<in> A. f x = b}) ` B \<subseteq> (\<lambda>b. {x \<in> A. f (inv p\<^sub>A x) = b}) ` B [PROOF STEP] proof [PROOF STATE] proof (state) goal (1 subgoal): 1. \<And>x. x \<in> (`) p\<^sub>A ` (\<lambda>b. {x \<in> A. f x = b}) ` B \<Longrightarrow> x \<in> (\<lambda>b. {x \<in> A. f (inv p\<^sub>A x) = b}) ` B [PROOF STEP] fix X [PROOF STATE] proof (state) goal (1 subgoal): 1. \<And>x. x \<in> (`) p\<^sub>A ` (\<lambda>b. {x \<in> A. f x = b}) ` B \<Longrightarrow> x \<in> (\<lambda>b. {x \<in> A. f (inv p\<^sub>A x) = b}) ` B [PROOF STEP] assume "X \<in> (\<lambda>X. p\<^sub>A ` X) ` (\<lambda>b. {x \<in> A. f x = b}) ` B" [PROOF STATE] proof (state) this: X \<in> (`) p\<^sub>A ` (\<lambda>b. {x \<in> A. f x = b}) ` B goal (1 subgoal): 1. \<And>x. x \<in> (`) p\<^sub>A ` (\<lambda>b. {x \<in> A. f x = b}) ` B \<Longrightarrow> x \<in> (\<lambda>b. {x \<in> A. f (inv p\<^sub>A x) = b}) ` B [PROOF STEP] from this [PROOF STATE] proof (chain) picking this: X \<in> (`) p\<^sub>A ` (\<lambda>b. {x \<in> A. f x = b}) ` B [PROOF STEP] obtain b where "b \<in> B" and X_eq: "X = p\<^sub>A ` {x \<in> A. f x = b}" [PROOF STATE] proof (prove) using this: X \<in> (`) p\<^sub>A ` (\<lambda>b. {x \<in> A. f x = b}) ` B goal (1 subgoal): 1. (\<And>b. \<lbrakk>b \<in> B; X = p\<^sub>A ` {x \<in> A. f x = b}\<rbrakk> \<Longrightarrow> thesis) \<Longrightarrow> thesis [PROOF STEP] by auto [PROOF STATE] proof (state) this: b \<in> B X = p\<^sub>A ` {x \<in> A. f x = b} goal (1 subgoal): 1. \<And>x. x \<in> (`) p\<^sub>A ` (\<lambda>b. {x \<in> A. f x = b}) ` B \<Longrightarrow> x \<in> (\<lambda>b. {x \<in> A. f (inv p\<^sub>A x) = b}) ` B [PROOF STEP] from this eq [PROOF STATE] proof (chain) picking this: b \<in> B X = p\<^sub>A ` {x \<in> A. f x = b} ?b \<in> B \<Longrightarrow> p\<^sub>A ` {x \<in> A. f x = ?b} = {x \<in> A. f (inv p\<^sub>A x) = ?b} [PROOF STEP] have "X = {x \<in> A. f (inv p\<^sub>A x) = b}" [PROOF STATE] proof (prove) using this: b \<in> B X = p\<^sub>A ` {x \<in> A. f x = b} ?b \<in> B \<Longrightarrow> p\<^sub>A ` {x \<in> A. f x = ?b} = {x \<in> A. f (inv p\<^sub>A x) = ?b} goal (1 subgoal): 1. X = {x \<in> A. f (inv p\<^sub>A x) = b} [PROOF STEP] by simp [PROOF STATE] proof (state) this: X = {x \<in> A. f (inv p\<^sub>A x) = b} goal (1 subgoal): 1. \<And>x. x \<in> (`) p\<^sub>A ` (\<lambda>b. {x \<in> A. f x = b}) ` B \<Longrightarrow> x \<in> (\<lambda>b. {x \<in> A. f (inv p\<^sub>A x) = b}) ` B [PROOF STEP] from this \<open>b \<in> B\<close> [PROOF STATE] proof (chain) picking this: X = {x \<in> A. f (inv p\<^sub>A x) = b} b \<in> B [PROOF STEP] show "X \<in> (\<lambda>b. {x \<in> A. f (inv p\<^sub>A x) = b}) ` B" [PROOF STATE] proof (prove) using this: X = {x \<in> A. f (inv p\<^sub>A x) = b} b \<in> B goal (1 subgoal): 1. X \<in> (\<lambda>b. {x \<in> A. f (inv p\<^sub>A x) = b}) ` B [PROOF STEP] .. [PROOF STATE] proof (state) this: X \<in> (\<lambda>b. {x \<in> A. f (inv p\<^sub>A x) = b}) ` B goal: No subgoals! [PROOF STEP] qed [PROOF STATE] proof (state) this: (`) p\<^sub>A ` (\<lambda>b. {x \<in> A. f x = b}) ` B \<subseteq> (\<lambda>b. {x \<in> A. f (inv p\<^sub>A x) = b}) ` B goal (1 subgoal): 1. (\<lambda>b. {x \<in> A. f (inv p\<^sub>A x) = b}) ` B \<subseteq> (`) p\<^sub>A ` (\<lambda>b. {x \<in> A. f x = b}) ` B [PROOF STEP] next [PROOF STATE] proof (state) goal (1 subgoal): 1. (\<lambda>b. {x \<in> A. f (inv p\<^sub>A x) = b}) ` B \<subseteq> (`) p\<^sub>A ` (\<lambda>b. {x \<in> A. f x = b}) ` B [PROOF STEP] from \<open>f \<in> A \<rightarrow>\<^sub>E B\<close> [PROOF STATE] proof (chain) picking this: f \<in> A \<rightarrow>\<^sub>E B [PROOF STEP] have "f \<in> A \<rightarrow> B" [PROOF STATE] proof (prove) using this: f \<in> A \<rightarrow>\<^sub>E B goal (1 subgoal): 1. f \<in> A \<rightarrow> B [PROOF STEP] by auto [PROOF STATE] proof (state) this: f \<in> A \<rightarrow> B goal (1 subgoal): 1. (\<lambda>b. {x \<in> A. f (inv p\<^sub>A x) = b}) ` B \<subseteq> (`) p\<^sub>A ` (\<lambda>b. {x \<in> A. f x = b}) ` B [PROOF STEP] note eq = permutes_domain_partition_eq[OF \<open>f \<in> A \<rightarrow> B\<close> \<open>p\<^sub>A permutes A\<close>, symmetric] [PROOF STATE] proof (state) this: ?b \<in> B \<Longrightarrow> {x \<in> A. f (inv p\<^sub>A x) = ?b} = p\<^sub>A ` {x \<in> A. f x = ?b} goal (1 subgoal): 1. (\<lambda>b. {x \<in> A. f (inv p\<^sub>A x) = b}) ` B \<subseteq> (`) p\<^sub>A ` (\<lambda>b. {x \<in> A. f x = b}) ` B [PROOF STEP] show "(\<lambda>b. {x \<in> A. f (inv p\<^sub>A x) = b}) ` B \<subseteq> (\<lambda>X. p\<^sub>A ` X) ` (\<lambda>b. {x \<in> A. f x = b}) ` B" [PROOF STATE] proof (prove) goal (1 subgoal): 1. (\<lambda>b. {x \<in> A. f (inv p\<^sub>A x) = b}) ` B \<subseteq> (`) p\<^sub>A ` (\<lambda>b. {x \<in> A. f x = b}) ` B [PROOF STEP] proof [PROOF STATE] proof (state) goal (1 subgoal): 1. \<And>x. x \<in> (\<lambda>b. {x \<in> A. f (inv p\<^sub>A x) = b}) ` B \<Longrightarrow> x \<in> (`) p\<^sub>A ` (\<lambda>b. {x \<in> A. f x = b}) ` B [PROOF STEP] fix X [PROOF STATE] proof (state) goal (1 subgoal): 1. \<And>x. x \<in> (\<lambda>b. {x \<in> A. f (inv p\<^sub>A x) = b}) ` B \<Longrightarrow> x \<in> (`) p\<^sub>A ` (\<lambda>b. {x \<in> A. f x = b}) ` B [PROOF STEP] assume "X \<in> (\<lambda>b. {x \<in> A. f (inv p\<^sub>A x) = b}) ` B" [PROOF STATE] proof (state) this: X \<in> (\<lambda>b. {x \<in> A. f (inv p\<^sub>A x) = b}) ` B goal (1 subgoal): 1. \<And>x. x \<in> (\<lambda>b. {x \<in> A. f (inv p\<^sub>A x) = b}) ` B \<Longrightarrow> x \<in> (`) p\<^sub>A ` (\<lambda>b. {x \<in> A. f x = b}) ` B [PROOF STEP] from this [PROOF STATE] proof (chain) picking this: X \<in> (\<lambda>b. {x \<in> A. f (inv p\<^sub>A x) = b}) ` B [PROOF STEP] obtain b where "b \<in> B" and X_eq: "X = {x \<in> A. f (inv p\<^sub>A x) = b}" [PROOF STATE] proof (prove) using this: X \<in> (\<lambda>b. {x \<in> A. f (inv p\<^sub>A x) = b}) ` B goal (1 subgoal): 1. (\<And>b. \<lbrakk>b \<in> B; X = {x \<in> A. f (inv p\<^sub>A x) = b}\<rbrakk> \<Longrightarrow> thesis) \<Longrightarrow> thesis [PROOF STEP] by auto [PROOF STATE] proof (state) this: b \<in> B X = {x \<in> A. f (inv p\<^sub>A x) = b} goal (1 subgoal): 1. \<And>x. x \<in> (\<lambda>b. {x \<in> A. f (inv p\<^sub>A x) = b}) ` B \<Longrightarrow> x \<in> (`) p\<^sub>A ` (\<lambda>b. {x \<in> A. f x = b}) ` B [PROOF STEP] from this eq [PROOF STATE] proof (chain) picking this: b \<in> B X = {x \<in> A. f (inv p\<^sub>A x) = b} ?b \<in> B \<Longrightarrow> {x \<in> A. f (inv p\<^sub>A x) = ?b} = p\<^sub>A ` {x \<in> A. f x = ?b} [PROOF STEP] have "X = p\<^sub>A ` {x \<in> A. f x = b}" [PROOF STATE] proof (prove) using this: b \<in> B X = {x \<in> A. f (inv p\<^sub>A x) = b} ?b \<in> B \<Longrightarrow> {x \<in> A. f (inv p\<^sub>A x) = ?b} = p\<^sub>A ` {x \<in> A. f x = ?b} goal (1 subgoal): 1. X = p\<^sub>A ` {x \<in> A. f x = b} [PROOF STEP] by simp [PROOF STATE] proof (state) this: X = p\<^sub>A ` {x \<in> A. f x = b} goal (1 subgoal): 1. \<And>x. x \<in> (\<lambda>b. {x \<in> A. f (inv p\<^sub>A x) = b}) ` B \<Longrightarrow> x \<in> (`) p\<^sub>A ` (\<lambda>b. {x \<in> A. f x = b}) ` B [PROOF STEP] from this \<open>b \<in> B\<close> [PROOF STATE] proof (chain) picking this: X = p\<^sub>A ` {x \<in> A. f x = b} b \<in> B [PROOF STEP] show "X \<in> (\<lambda>X. p\<^sub>A ` X) ` (\<lambda>b. {x \<in> A. f x = b}) ` B" [PROOF STATE] proof (prove) using this: X = p\<^sub>A ` {x \<in> A. f x = b} b \<in> B goal (1 subgoal): 1. X \<in> (`) p\<^sub>A ` (\<lambda>b. {x \<in> A. f x = b}) ` B [PROOF STEP] by auto [PROOF STATE] proof (state) this: X \<in> (`) p\<^sub>A ` (\<lambda>b. {x \<in> A. f x = b}) ` B goal: No subgoals! [PROOF STEP] qed [PROOF STATE] proof (state) this: (\<lambda>b. {x \<in> A. f (inv p\<^sub>A x) = b}) ` B \<subseteq> (`) p\<^sub>A ` (\<lambda>b. {x \<in> A. f x = b}) ` B goal: No subgoals! [PROOF STEP] qed
/- Copyright (c) 2015, 2017 Jeremy Avigad. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Metric spaces. Authors: Jeremy Avigad, Robert Y. Lewis, Johannes Hölzl, Mario Carneiro, Sébastien Gouëzel Many definitions and theorems expected on metric spaces are already introduced on uniform spaces and topological spaces. For example: open and closed sets, compactness, completeness, continuity and uniform continuity -/ import Mathlib.PrePort import Mathlib.Lean3Lib.init.default import Mathlib.topology.metric_space.emetric_space import Mathlib.topology.algebra.ordered import Mathlib.PostPort universes u u_1 l v u_2 namespace Mathlib /-- Construct a uniform structure from a distance function and metric space axioms -/ def uniform_space_of_dist {α : Type u} (dist : α → α → ℝ) (dist_self : ∀ (x : α), dist x x = 0) (dist_comm : ∀ (x y : α), dist x y = dist y x) (dist_triangle : ∀ (x y z : α), dist x z ≤ dist x y + dist y z) : uniform_space α := uniform_space.of_core (uniform_space.core.mk (infi fun (ε : ℝ) => infi fun (H : ε > 0) => filter.principal (set_of fun (p : α × α) => dist (prod.fst p) (prod.snd p) < ε)) sorry sorry sorry) /-- The distance function (given an ambient metric space on `α`), which returns a nonnegative real number `dist x y` given `x y : α`. -/ class has_dist (α : Type u_1) where dist : α → α → ℝ -- the uniform structure and the emetric space structure are embedded in the metric space structure -- to avoid instance diamond issues. See Note [forgetful inheritance]. /-- Metric space Each metric space induces a canonical `uniform_space` and hence a canonical `topological_space`. This is enforced in the type class definition, by extending the `uniform_space` structure. When instantiating a `metric_space` structure, the uniformity fields are not necessary, they will be filled in by default. In the same way, each metric space induces an emetric space structure. It is included in the structure, but filled in by default. -/ class metric_space (α : Type u) extends uniform_space #2, metric_space.to_uniform_space._default #2 #1 #0 α _to_has_dist = id (uniform_space_of_dist dist #0 α _to_has_dist), uniform_space α, has_dist α where dist_self : ∀ (x : α), dist x x = 0 eq_of_dist_eq_zero : ∀ {x y : α}, dist x y = 0 → x = y dist_comm : ∀ (x y : α), dist x y = dist y x dist_triangle : ∀ (x y z : α), dist x z ≤ dist x y + dist y z edist : α → α → ennreal edist_dist : autoParam (∀ (x y : α), edist x y = ennreal.of_real (dist x y)) (Lean.Syntax.ident Lean.SourceInfo.none (String.toSubstring "Mathlib.control_laws_tac") (Lean.Name.mkStr (Lean.Name.mkStr Lean.Name.anonymous "Mathlib") "control_laws_tac") []) to_uniform_space : uniform_space α uniformity_dist : autoParam (uniformity α = infi fun (ε : ℝ) => infi fun (H : ε > 0) => filter.principal (set_of fun (p : α × α) => dist (prod.fst p) (prod.snd p) < ε)) (Lean.Syntax.ident Lean.SourceInfo.none (String.toSubstring "Mathlib.control_laws_tac") (Lean.Name.mkStr (Lean.Name.mkStr Lean.Name.anonymous "Mathlib") "control_laws_tac") []) protected instance metric_space.to_uniform_space' {α : Type u} [metric_space α] : uniform_space α := metric_space.to_uniform_space protected instance metric_space.to_has_edist {α : Type u} [metric_space α] : has_edist α := has_edist.mk metric_space.edist @[simp] theorem dist_self {α : Type u} [metric_space α] (x : α) : dist x x = 0 := metric_space.dist_self x theorem eq_of_dist_eq_zero {α : Type u} [metric_space α] {x : α} {y : α} : dist x y = 0 → x = y := metric_space.eq_of_dist_eq_zero theorem dist_comm {α : Type u} [metric_space α] (x : α) (y : α) : dist x y = dist y x := metric_space.dist_comm x y theorem edist_dist {α : Type u} [metric_space α] (x : α) (y : α) : edist x y = ennreal.of_real (dist x y) := metric_space.edist_dist x y @[simp] theorem dist_eq_zero {α : Type u} [metric_space α] {x : α} {y : α} : dist x y = 0 ↔ x = y := { mp := eq_of_dist_eq_zero, mpr := fun (this : x = y) => this ▸ dist_self x } @[simp] theorem zero_eq_dist {α : Type u} [metric_space α] {x : α} {y : α} : 0 = dist x y ↔ x = y := eq.mpr (id (Eq._oldrec (Eq.refl (0 = dist x y ↔ x = y)) (propext eq_comm))) (eq.mpr (id (Eq._oldrec (Eq.refl (dist x y = 0 ↔ x = y)) (propext dist_eq_zero))) (iff.refl (x = y))) theorem dist_triangle {α : Type u} [metric_space α] (x : α) (y : α) (z : α) : dist x z ≤ dist x y + dist y z := metric_space.dist_triangle x y z theorem dist_triangle_left {α : Type u} [metric_space α] (x : α) (y : α) (z : α) : dist x y ≤ dist z x + dist z y := eq.mpr (id (Eq._oldrec (Eq.refl (dist x y ≤ dist z x + dist z y)) (dist_comm z x))) (dist_triangle x z y) theorem dist_triangle_right {α : Type u} [metric_space α] (x : α) (y : α) (z : α) : dist x y ≤ dist x z + dist y z := eq.mpr (id (Eq._oldrec (Eq.refl (dist x y ≤ dist x z + dist y z)) (dist_comm y z))) (dist_triangle x z y) theorem dist_triangle4 {α : Type u} [metric_space α] (x : α) (y : α) (z : α) (w : α) : dist x w ≤ dist x y + dist y z + dist z w := le_trans (dist_triangle x z w) (add_le_add_right (dist_triangle x y z) (dist z w)) theorem dist_triangle4_left {α : Type u} [metric_space α] (x₁ : α) (y₁ : α) (x₂ : α) (y₂ : α) : dist x₂ y₂ ≤ dist x₁ y₁ + (dist x₁ x₂ + dist y₁ y₂) := sorry theorem dist_triangle4_right {α : Type u} [metric_space α] (x₁ : α) (y₁ : α) (x₂ : α) (y₂ : α) : dist x₁ y₁ ≤ dist x₁ x₂ + dist y₁ y₂ + dist x₂ y₂ := sorry /-- The triangle (polygon) inequality for sequences of points; `finset.Ico` version. -/ theorem dist_le_Ico_sum_dist {α : Type u} [metric_space α] (f : ℕ → α) {m : ℕ} {n : ℕ} (h : m ≤ n) : dist (f m) (f n) ≤ finset.sum (finset.Ico m n) fun (i : ℕ) => dist (f i) (f (i + 1)) := sorry /-- The triangle (polygon) inequality for sequences of points; `finset.range` version. -/ theorem dist_le_range_sum_dist {α : Type u} [metric_space α] (f : ℕ → α) (n : ℕ) : dist (f 0) (f n) ≤ finset.sum (finset.range n) fun (i : ℕ) => dist (f i) (f (i + 1)) := finset.Ico.zero_bot n ▸ dist_le_Ico_sum_dist f (nat.zero_le n) /-- A version of `dist_le_Ico_sum_dist` with each intermediate distance replaced with an upper estimate. -/ theorem dist_le_Ico_sum_of_dist_le {α : Type u} [metric_space α] {f : ℕ → α} {m : ℕ} {n : ℕ} (hmn : m ≤ n) {d : ℕ → ℝ} (hd : ∀ {k : ℕ}, m ≤ k → k < n → dist (f k) (f (k + 1)) ≤ d k) : dist (f m) (f n) ≤ finset.sum (finset.Ico m n) fun (i : ℕ) => d i := sorry /-- A version of `dist_le_range_sum_dist` with each intermediate distance replaced with an upper estimate. -/ theorem dist_le_range_sum_of_dist_le {α : Type u} [metric_space α] {f : ℕ → α} (n : ℕ) {d : ℕ → ℝ} (hd : ∀ {k : ℕ}, k < n → dist (f k) (f (k + 1)) ≤ d k) : dist (f 0) (f n) ≤ finset.sum (finset.range n) fun (i : ℕ) => d i := finset.Ico.zero_bot n ▸ dist_le_Ico_sum_of_dist_le (zero_le n) fun (_x : ℕ) (_x_1 : 0 ≤ _x) => hd theorem swap_dist {α : Type u} [metric_space α] : function.swap dist = dist := funext fun (x : α) => funext fun (y : α) => dist_comm y x theorem abs_dist_sub_le {α : Type u} [metric_space α] (x : α) (y : α) (z : α) : abs (dist x z - dist y z) ≤ dist x y := iff.mpr abs_sub_le_iff { left := iff.mpr sub_le_iff_le_add (dist_triangle x y z), right := iff.mpr sub_le_iff_le_add (dist_triangle_left y z x) } theorem dist_nonneg {α : Type u} [metric_space α] {x : α} {y : α} : 0 ≤ dist x y := sorry @[simp] theorem dist_le_zero {α : Type u} [metric_space α] {x : α} {y : α} : dist x y ≤ 0 ↔ x = y := sorry @[simp] theorem dist_pos {α : Type u} [metric_space α] {x : α} {y : α} : 0 < dist x y ↔ x ≠ y := sorry @[simp] theorem abs_dist {α : Type u} [metric_space α] {a : α} {b : α} : abs (dist a b) = dist a b := abs_of_nonneg dist_nonneg theorem eq_of_forall_dist_le {α : Type u} [metric_space α] {x : α} {y : α} (h : ∀ (ε : ℝ), ε > 0 → dist x y ≤ ε) : x = y := eq_of_dist_eq_zero (eq_of_le_of_forall_le_of_dense dist_nonneg h) /-- Distance as a nonnegative real number. -/ def nndist {α : Type u} [metric_space α] (a : α) (b : α) : nnreal := { val := dist a b, property := dist_nonneg } /--Express `nndist` in terms of `edist`-/ theorem nndist_edist {α : Type u} [metric_space α] (x : α) (y : α) : nndist x y = ennreal.to_nnreal (edist x y) := sorry /--Express `edist` in terms of `nndist`-/ theorem edist_nndist {α : Type u} [metric_space α] (x : α) (y : α) : edist x y = ↑(nndist x y) := sorry @[simp] theorem ennreal_coe_nndist {α : Type u} [metric_space α] (x : α) (y : α) : ↑(nndist x y) = edist x y := Eq.symm (edist_nndist x y) @[simp] theorem edist_lt_coe {α : Type u} [metric_space α] {x : α} {y : α} {c : nnreal} : edist x y < ↑c ↔ nndist x y < c := eq.mpr (id (Eq._oldrec (Eq.refl (edist x y < ↑c ↔ nndist x y < c)) (edist_nndist x y))) (eq.mpr (id (Eq._oldrec (Eq.refl (↑(nndist x y) < ↑c ↔ nndist x y < c)) (propext ennreal.coe_lt_coe))) (iff.refl (nndist x y < c))) @[simp] theorem edist_le_coe {α : Type u} [metric_space α] {x : α} {y : α} {c : nnreal} : edist x y ≤ ↑c ↔ nndist x y ≤ c := eq.mpr (id (Eq._oldrec (Eq.refl (edist x y ≤ ↑c ↔ nndist x y ≤ c)) (edist_nndist x y))) (eq.mpr (id (Eq._oldrec (Eq.refl (↑(nndist x y) ≤ ↑c ↔ nndist x y ≤ c)) (propext ennreal.coe_le_coe))) (iff.refl (nndist x y ≤ c))) /--In a metric space, the extended distance is always finite-/ theorem edist_ne_top {α : Type u} [metric_space α] (x : α) (y : α) : edist x y ≠ ⊤ := eq.mpr (id (Eq._oldrec (Eq.refl (edist x y ≠ ⊤)) (edist_dist x y))) ennreal.coe_ne_top /--In a metric space, the extended distance is always finite-/ theorem edist_lt_top {α : Type u_1} [metric_space α] (x : α) (y : α) : edist x y < ⊤ := iff.mpr ennreal.lt_top_iff_ne_top (edist_ne_top x y) /--`nndist x x` vanishes-/ @[simp] theorem nndist_self {α : Type u} [metric_space α] (a : α) : nndist a a = 0 := iff.mp (nnreal.coe_eq_zero (nndist a a)) (dist_self a) /--Express `dist` in terms of `nndist`-/ theorem dist_nndist {α : Type u} [metric_space α] (x : α) (y : α) : dist x y = ↑(nndist x y) := rfl @[simp] theorem coe_nndist {α : Type u} [metric_space α] (x : α) (y : α) : ↑(nndist x y) = dist x y := Eq.symm (dist_nndist x y) @[simp] theorem dist_lt_coe {α : Type u} [metric_space α] {x : α} {y : α} {c : nnreal} : dist x y < ↑c ↔ nndist x y < c := iff.rfl @[simp] theorem dist_le_coe {α : Type u} [metric_space α] {x : α} {y : α} {c : nnreal} : dist x y ≤ ↑c ↔ nndist x y ≤ c := iff.rfl /--Express `nndist` in terms of `dist`-/ theorem nndist_dist {α : Type u} [metric_space α] (x : α) (y : α) : nndist x y = nnreal.of_real (dist x y) := eq.mpr (id (Eq._oldrec (Eq.refl (nndist x y = nnreal.of_real (dist x y))) (dist_nndist x y))) (eq.mpr (id (Eq._oldrec (Eq.refl (nndist x y = nnreal.of_real ↑(nndist x y))) nnreal.of_real_coe)) (Eq.refl (nndist x y))) /--Deduce the equality of points with the vanishing of the nonnegative distance-/ theorem eq_of_nndist_eq_zero {α : Type u} [metric_space α] {x : α} {y : α} : nndist x y = 0 → x = y := sorry theorem nndist_comm {α : Type u} [metric_space α] (x : α) (y : α) : nndist x y = nndist y x := sorry /--Characterize the equality of points with the vanishing of the nonnegative distance-/ @[simp] theorem nndist_eq_zero {α : Type u} [metric_space α] {x : α} {y : α} : nndist x y = 0 ↔ x = y := sorry @[simp] theorem zero_eq_nndist {α : Type u} [metric_space α] {x : α} {y : α} : 0 = nndist x y ↔ x = y := sorry /--Triangle inequality for the nonnegative distance-/ theorem nndist_triangle {α : Type u} [metric_space α] (x : α) (y : α) (z : α) : nndist x z ≤ nndist x y + nndist y z := dist_triangle x y z theorem nndist_triangle_left {α : Type u} [metric_space α] (x : α) (y : α) (z : α) : nndist x y ≤ nndist z x + nndist z y := dist_triangle_left x y z theorem nndist_triangle_right {α : Type u} [metric_space α] (x : α) (y : α) (z : α) : nndist x y ≤ nndist x z + nndist y z := dist_triangle_right x y z /--Express `dist` in terms of `edist`-/ theorem dist_edist {α : Type u} [metric_space α] (x : α) (y : α) : dist x y = ennreal.to_real (edist x y) := sorry namespace metric /- instantiate metric space as a topology -/ /-- `ball x ε` is the set of all points `y` with `dist y x < ε` -/ def ball {α : Type u} [metric_space α] (x : α) (ε : ℝ) : set α := set_of fun (y : α) => dist y x < ε @[simp] theorem mem_ball {α : Type u} [metric_space α] {x : α} {y : α} {ε : ℝ} : y ∈ ball x ε ↔ dist y x < ε := iff.rfl theorem mem_ball' {α : Type u} [metric_space α] {x : α} {y : α} {ε : ℝ} : y ∈ ball x ε ↔ dist x y < ε := eq.mpr (id (Eq._oldrec (Eq.refl (y ∈ ball x ε ↔ dist x y < ε)) (dist_comm x y))) (iff.refl (y ∈ ball x ε)) @[simp] theorem nonempty_ball {α : Type u} [metric_space α] {x : α} {ε : ℝ} (h : 0 < ε) : set.nonempty (ball x ε) := sorry theorem ball_eq_ball {α : Type u} [metric_space α] (ε : ℝ) (x : α) : uniform_space.ball x (set_of fun (p : α × α) => dist (prod.snd p) (prod.fst p) < ε) = ball x ε := rfl theorem ball_eq_ball' {α : Type u} [metric_space α] (ε : ℝ) (x : α) : uniform_space.ball x (set_of fun (p : α × α) => dist (prod.fst p) (prod.snd p) < ε) = ball x ε := sorry /-- `closed_ball x ε` is the set of all points `y` with `dist y x ≤ ε` -/ def closed_ball {α : Type u} [metric_space α] (x : α) (ε : ℝ) : set α := set_of fun (y : α) => dist y x ≤ ε @[simp] theorem mem_closed_ball {α : Type u} [metric_space α] {x : α} {y : α} {ε : ℝ} : y ∈ closed_ball x ε ↔ dist y x ≤ ε := iff.rfl /-- `sphere x ε` is the set of all points `y` with `dist y x = ε` -/ def sphere {α : Type u} [metric_space α] (x : α) (ε : ℝ) : set α := set_of fun (y : α) => dist y x = ε @[simp] theorem mem_sphere {α : Type u} [metric_space α] {x : α} {y : α} {ε : ℝ} : y ∈ sphere x ε ↔ dist y x = ε := iff.rfl theorem mem_closed_ball' {α : Type u} [metric_space α] {x : α} {y : α} {ε : ℝ} : y ∈ closed_ball x ε ↔ dist x y ≤ ε := eq.mpr (id (Eq._oldrec (Eq.refl (y ∈ closed_ball x ε ↔ dist x y ≤ ε)) (dist_comm x y))) (iff.refl (y ∈ closed_ball x ε)) theorem nonempty_closed_ball {α : Type u} [metric_space α] {x : α} {ε : ℝ} (h : 0 ≤ ε) : set.nonempty (closed_ball x ε) := sorry theorem ball_subset_closed_ball {α : Type u} [metric_space α] {x : α} {ε : ℝ} : ball x ε ⊆ closed_ball x ε := fun (y : α) (hy : dist y x < ε) => le_of_lt hy theorem sphere_subset_closed_ball {α : Type u} [metric_space α] {x : α} {ε : ℝ} : sphere x ε ⊆ closed_ball x ε := fun (y : α) => le_of_eq theorem sphere_disjoint_ball {α : Type u} [metric_space α] {x : α} {ε : ℝ} : disjoint (sphere x ε) (ball x ε) := sorry @[simp] theorem ball_union_sphere {α : Type u} [metric_space α] {x : α} {ε : ℝ} : ball x ε ∪ sphere x ε = closed_ball x ε := set.ext fun (y : α) => iff.symm le_iff_lt_or_eq @[simp] theorem sphere_union_ball {α : Type u} [metric_space α] {x : α} {ε : ℝ} : sphere x ε ∪ ball x ε = closed_ball x ε := eq.mpr (id (Eq._oldrec (Eq.refl (sphere x ε ∪ ball x ε = closed_ball x ε)) (set.union_comm (sphere x ε) (ball x ε)))) (eq.mpr (id (Eq._oldrec (Eq.refl (ball x ε ∪ sphere x ε = closed_ball x ε)) ball_union_sphere)) (Eq.refl (closed_ball x ε))) @[simp] theorem closed_ball_diff_sphere {α : Type u} [metric_space α] {x : α} {ε : ℝ} : closed_ball x ε \ sphere x ε = ball x ε := sorry @[simp] theorem closed_ball_diff_ball {α : Type u} [metric_space α] {x : α} {ε : ℝ} : closed_ball x ε \ ball x ε = sphere x ε := sorry theorem pos_of_mem_ball {α : Type u} [metric_space α] {x : α} {y : α} {ε : ℝ} (hy : y ∈ ball x ε) : 0 < ε := lt_of_le_of_lt dist_nonneg hy theorem mem_ball_self {α : Type u} [metric_space α] {x : α} {ε : ℝ} (h : 0 < ε) : x ∈ ball x ε := (fun (this : dist x x < ε) => this) (eq.mpr (id (Eq._oldrec (Eq.refl (dist x x < ε)) (dist_self x))) h) theorem mem_closed_ball_self {α : Type u} [metric_space α] {x : α} {ε : ℝ} (h : 0 ≤ ε) : x ∈ closed_ball x ε := (fun (this : dist x x ≤ ε) => this) (eq.mpr (id (Eq._oldrec (Eq.refl (dist x x ≤ ε)) (dist_self x))) h) theorem mem_ball_comm {α : Type u} [metric_space α] {x : α} {y : α} {ε : ℝ} : x ∈ ball y ε ↔ y ∈ ball x ε := sorry theorem ball_subset_ball {α : Type u} [metric_space α] {x : α} {ε₁ : ℝ} {ε₂ : ℝ} (h : ε₁ ≤ ε₂) : ball x ε₁ ⊆ ball x ε₂ := fun (y : α) (yx : dist y x < ε₁) => lt_of_lt_of_le yx h theorem closed_ball_subset_closed_ball {α : Type u} [metric_space α] {x : α} {ε₁ : ℝ} {ε₂ : ℝ} (h : ε₁ ≤ ε₂) : closed_ball x ε₁ ⊆ closed_ball x ε₂ := fun (y : α) (yx : dist y x ≤ ε₁) => le_trans yx h theorem ball_disjoint {α : Type u} [metric_space α] {x : α} {y : α} {ε₁ : ℝ} {ε₂ : ℝ} (h : ε₁ + ε₂ ≤ dist x y) : ball x ε₁ ∩ ball y ε₂ = ∅ := sorry theorem ball_disjoint_same {α : Type u} [metric_space α] {x : α} {y : α} {ε : ℝ} (h : ε ≤ dist x y / bit0 1) : ball x ε ∩ ball y ε = ∅ := ball_disjoint (eq.mpr (id (Eq._oldrec (Eq.refl (ε + ε ≤ dist x y)) (Eq.symm (two_mul ε)))) (eq.mpr (id (Eq._oldrec (Eq.refl (bit0 1 * ε ≤ dist x y)) (Eq.symm (propext (le_div_iff' zero_lt_two))))) h)) theorem ball_subset {α : Type u} [metric_space α] {x : α} {y : α} {ε₁ : ℝ} {ε₂ : ℝ} (h : dist x y ≤ ε₂ - ε₁) : ball x ε₁ ⊆ ball y ε₂ := fun (z : α) (zx : z ∈ ball x ε₁) => eq.mpr (id (Eq._oldrec (Eq.refl (z ∈ ball y ε₂)) (Eq.symm (add_sub_cancel'_right ε₁ ε₂)))) (lt_of_le_of_lt (dist_triangle z x y) (add_lt_add_of_lt_of_le zx h)) theorem ball_half_subset {α : Type u} [metric_space α] {x : α} {ε : ℝ} (y : α) (h : y ∈ ball x (ε / bit0 1)) : ball y (ε / bit0 1) ⊆ ball x ε := ball_subset (eq.mpr (id (Eq._oldrec (Eq.refl (dist y x ≤ ε - ε / bit0 1)) (sub_self_div_two ε))) (le_of_lt h)) theorem exists_ball_subset_ball {α : Type u} [metric_space α] {x : α} {y : α} {ε : ℝ} (h : y ∈ ball x ε) : ∃ (ε' : ℝ), ∃ (H : ε' > 0), ball y ε' ⊆ ball x ε := sorry @[simp] theorem ball_eq_empty_iff_nonpos {α : Type u} [metric_space α] {x : α} {ε : ℝ} : ball x ε = ∅ ↔ ε ≤ 0 := iff.trans set.eq_empty_iff_forall_not_mem { mp := fun (h : ∀ (x_1 : α), ¬x_1 ∈ ball x ε) => le_of_not_gt fun (ε0 : ε > 0) => h x (mem_ball_self ε0), mpr := fun (ε0 : ε ≤ 0) (y : α) (h : y ∈ ball x ε) => not_lt_of_le ε0 (pos_of_mem_ball h) } @[simp] theorem closed_ball_eq_empty_iff_neg {α : Type u} [metric_space α] {x : α} {ε : ℝ} : closed_ball x ε = ∅ ↔ ε < 0 := sorry @[simp] theorem ball_zero {α : Type u} [metric_space α] {x : α} : ball x 0 = ∅ := eq.mpr (id (Eq._oldrec (Eq.refl (ball x 0 = ∅)) (propext ball_eq_empty_iff_nonpos))) (le_refl 0) @[simp] theorem closed_ball_zero {α : Type u} [metric_space α] {x : α} : closed_ball x 0 = singleton x := set.ext fun (y : α) => dist_le_zero theorem uniformity_basis_dist {α : Type u} [metric_space α] : filter.has_basis (uniformity α) (fun (ε : ℝ) => 0 < ε) fun (ε : ℝ) => set_of fun (p : α × α) => dist (prod.fst p) (prod.snd p) < ε := sorry /-- Given `f : β → ℝ`, if `f` sends `{i | p i}` to a set of positive numbers accumulating to zero, then `f i`-neighborhoods of the diagonal form a basis of `𝓤 α`. For specific bases see `uniformity_basis_dist`, `uniformity_basis_dist_inv_nat_succ`, and `uniformity_basis_dist_inv_nat_pos`. -/ protected theorem mk_uniformity_basis {α : Type u} [metric_space α] {β : Type u_1} {p : β → Prop} {f : β → ℝ} (hf₀ : ∀ (i : β), p i → 0 < f i) (hf : ∀ {ε : ℝ}, 0 < ε → ∃ (i : β), ∃ (hi : p i), f i ≤ ε) : filter.has_basis (uniformity α) p fun (i : β) => set_of fun (p : α × α) => dist (prod.fst p) (prod.snd p) < f i := sorry theorem uniformity_basis_dist_inv_nat_succ {α : Type u} [metric_space α] : filter.has_basis (uniformity α) (fun (_x : ℕ) => True) fun (n : ℕ) => set_of fun (p : α × α) => dist (prod.fst p) (prod.snd p) < 1 / (↑n + 1) := metric.mk_uniformity_basis (fun (n : ℕ) (_x : True) => div_pos zero_lt_one (nat.cast_add_one_pos n)) fun (ε : ℝ) (ε0 : 0 < ε) => Exists.imp (fun (n : ℕ) (hn : 1 / (↑n + 1) < ε) => Exists.intro trivial (le_of_lt hn)) (exists_nat_one_div_lt ε0) theorem uniformity_basis_dist_inv_nat_pos {α : Type u} [metric_space α] : filter.has_basis (uniformity α) (fun (n : ℕ) => 0 < n) fun (n : ℕ) => set_of fun (p : α × α) => dist (prod.fst p) (prod.snd p) < 1 / ↑n := sorry /-- Given `f : β → ℝ`, if `f` sends `{i | p i}` to a set of positive numbers accumulating to zero, then closed neighborhoods of the diagonal of sizes `{f i | p i}` form a basis of `𝓤 α`. Currently we have only one specific basis `uniformity_basis_dist_le` based on this constructor. More can be easily added if needed in the future. -/ protected theorem mk_uniformity_basis_le {α : Type u} [metric_space α] {β : Type u_1} {p : β → Prop} {f : β → ℝ} (hf₀ : ∀ (x : β), p x → 0 < f x) (hf : ∀ (ε : ℝ), 0 < ε → ∃ (x : β), ∃ (hx : p x), f x ≤ ε) : filter.has_basis (uniformity α) p fun (x : β) => set_of fun (p : α × α) => dist (prod.fst p) (prod.snd p) ≤ f x := sorry /-- Contant size closed neighborhoods of the diagonal form a basis of the uniformity filter. -/ theorem uniformity_basis_dist_le {α : Type u} [metric_space α] : filter.has_basis (uniformity α) (fun (ε : ℝ) => 0 < ε) fun (ε : ℝ) => set_of fun (p : α × α) => dist (prod.fst p) (prod.snd p) ≤ ε := metric.mk_uniformity_basis_le (fun (_x : ℝ) => id) fun (ε : ℝ) (ε₀ : 0 < ε) => Exists.intro ε (Exists.intro ε₀ (le_refl ε)) theorem mem_uniformity_dist {α : Type u} [metric_space α] {s : set (α × α)} : s ∈ uniformity α ↔ ∃ (ε : ℝ), ∃ (H : ε > 0), ∀ {a b : α}, dist a b < ε → (a, b) ∈ s := filter.has_basis.mem_uniformity_iff uniformity_basis_dist /-- A constant size neighborhood of the diagonal is an entourage. -/ theorem dist_mem_uniformity {α : Type u} [metric_space α] {ε : ℝ} (ε0 : 0 < ε) : (set_of fun (p : α × α) => dist (prod.fst p) (prod.snd p) < ε) ∈ uniformity α := iff.mpr mem_uniformity_dist (Exists.intro ε (Exists.intro ε0 fun (a b : α) => id)) theorem uniform_continuous_iff {α : Type u} {β : Type v} [metric_space α] [metric_space β] {f : α → β} : uniform_continuous f ↔ ∀ (ε : ℝ) (H : ε > 0), ∃ (δ : ℝ), ∃ (H : δ > 0), ∀ {a b : α}, dist a b < δ → dist (f a) (f b) < ε := filter.has_basis.uniform_continuous_iff uniformity_basis_dist uniformity_basis_dist theorem uniform_continuous_on_iff {α : Type u} {β : Type v} [metric_space α] [metric_space β] {f : α → β} {s : set α} : uniform_continuous_on f s ↔ ∀ (ε : ℝ) (H : ε > 0), ∃ (δ : ℝ), ∃ (H : δ > 0), ∀ (x y : α), x ∈ s → y ∈ s → dist x y < δ → dist (f x) (f y) < ε := sorry theorem uniform_embedding_iff {α : Type u} {β : Type v} [metric_space α] [metric_space β] {f : α → β} : uniform_embedding f ↔ function.injective f ∧ uniform_continuous f ∧ ∀ (δ : ℝ) (H : δ > 0), ∃ (ε : ℝ), ∃ (H : ε > 0), ∀ {a b : α}, dist (f a) (f b) < ε → dist a b < δ := sorry /-- A map between metric spaces is a uniform embedding if and only if the distance between `f x` and `f y` is controlled in terms of the distance between `x` and `y` and conversely. -/ theorem uniform_embedding_iff' {α : Type u} {β : Type v} [metric_space α] [metric_space β] {f : α → β} : uniform_embedding f ↔ (∀ (ε : ℝ) (H : ε > 0), ∃ (δ : ℝ), ∃ (H : δ > 0), ∀ {a b : α}, dist a b < δ → dist (f a) (f b) < ε) ∧ ∀ (δ : ℝ) (H : δ > 0), ∃ (ε : ℝ), ∃ (H : ε > 0), ∀ {a b : α}, dist (f a) (f b) < ε → dist a b < δ := sorry theorem totally_bounded_iff {α : Type u} [metric_space α] {s : set α} : totally_bounded s ↔ ∀ (ε : ℝ) (H : ε > 0), ∃ (t : set α), set.finite t ∧ s ⊆ set.Union fun (y : α) => set.Union fun (H : y ∈ t) => ball y ε := sorry /-- A metric space space is totally bounded if one can reconstruct up to any ε>0 any element of the space from finitely many data. -/ theorem totally_bounded_of_finite_discretization {α : Type u} [metric_space α] {s : set α} (H : ∀ (ε : ℝ), ε > 0 → ∃ (β : Type u), Exists (∃ (F : ↥s → β), ∀ (x y : ↥s), F x = F y → dist ↑x ↑y < ε)) : totally_bounded s := sorry theorem finite_approx_of_totally_bounded {α : Type u} [metric_space α] {s : set α} (hs : totally_bounded s) (ε : ℝ) (H : ε > 0) : ∃ (t : set α), ∃ (H : t ⊆ s), set.finite t ∧ s ⊆ set.Union fun (y : α) => set.Union fun (H : y ∈ t) => ball y ε := eq.mp (Eq._oldrec (Eq.refl (totally_bounded s)) (propext totally_bounded_iff_subset)) hs (set_of fun (p : α × α) => dist (prod.fst p) (prod.snd p) < ε) (dist_mem_uniformity ε_pos) /-- Expressing locally uniform convergence on a set using `dist`. -/ theorem tendsto_locally_uniformly_on_iff {α : Type u} {β : Type v} [metric_space α] {ι : Type u_1} [topological_space β] {F : ι → β → α} {f : β → α} {p : filter ι} {s : set β} : tendsto_locally_uniformly_on F f p s ↔ ∀ (ε : ℝ) (H : ε > 0) (x : β) (H : x ∈ s), ∃ (t : set β), ∃ (H : t ∈ nhds_within x s), filter.eventually (fun (n : ι) => ∀ (y : β), y ∈ t → dist (f y) (F n y) < ε) p := sorry /-- Expressing uniform convergence on a set using `dist`. -/ theorem tendsto_uniformly_on_iff {α : Type u} {β : Type v} [metric_space α] {ι : Type u_1} {F : ι → β → α} {f : β → α} {p : filter ι} {s : set β} : tendsto_uniformly_on F f p s ↔ ∀ (ε : ℝ), ε > 0 → filter.eventually (fun (n : ι) => ∀ (x : β), x ∈ s → dist (f x) (F n x) < ε) p := sorry /-- Expressing locally uniform convergence using `dist`. -/ theorem tendsto_locally_uniformly_iff {α : Type u} {β : Type v} [metric_space α] {ι : Type u_1} [topological_space β] {F : ι → β → α} {f : β → α} {p : filter ι} : tendsto_locally_uniformly F f p ↔ ∀ (ε : ℝ) (H : ε > 0) (x : β), ∃ (t : set β), ∃ (H : t ∈ nhds x), filter.eventually (fun (n : ι) => ∀ (y : β), y ∈ t → dist (f y) (F n y) < ε) p := sorry /-- Expressing uniform convergence using `dist`. -/ theorem tendsto_uniformly_iff {α : Type u} {β : Type v} [metric_space α] {ι : Type u_1} {F : ι → β → α} {f : β → α} {p : filter ι} : tendsto_uniformly F f p ↔ ∀ (ε : ℝ), ε > 0 → filter.eventually (fun (n : ι) => ∀ (x : β), dist (f x) (F n x) < ε) p := sorry protected theorem cauchy_iff {α : Type u} [metric_space α] {f : filter α} : cauchy f ↔ filter.ne_bot f ∧ ∀ (ε : ℝ) (H : ε > 0), ∃ (t : set α), ∃ (H : t ∈ f), ∀ (x y : α), x ∈ t → y ∈ t → dist x y < ε := filter.has_basis.cauchy_iff uniformity_basis_dist theorem nhds_basis_ball {α : Type u} [metric_space α] {x : α} : filter.has_basis (nhds x) (fun (ε : ℝ) => 0 < ε) (ball x) := nhds_basis_uniformity uniformity_basis_dist theorem mem_nhds_iff {α : Type u} [metric_space α] {x : α} {s : set α} : s ∈ nhds x ↔ ∃ (ε : ℝ), ∃ (H : ε > 0), ball x ε ⊆ s := filter.has_basis.mem_iff nhds_basis_ball theorem eventually_nhds_iff {α : Type u} [metric_space α] {x : α} {p : α → Prop} : filter.eventually (fun (y : α) => p y) (nhds x) ↔ ∃ (ε : ℝ), ∃ (H : ε > 0), ∀ {y : α}, dist y x < ε → p y := mem_nhds_iff theorem eventually_nhds_iff_ball {α : Type u} [metric_space α] {x : α} {p : α → Prop} : filter.eventually (fun (y : α) => p y) (nhds x) ↔ ∃ (ε : ℝ), ∃ (H : ε > 0), ∀ (y : α), y ∈ ball x ε → p y := mem_nhds_iff theorem nhds_basis_closed_ball {α : Type u} [metric_space α] {x : α} : filter.has_basis (nhds x) (fun (ε : ℝ) => 0 < ε) (closed_ball x) := nhds_basis_uniformity uniformity_basis_dist_le theorem nhds_basis_ball_inv_nat_succ {α : Type u} [metric_space α] {x : α} : filter.has_basis (nhds x) (fun (_x : ℕ) => True) fun (n : ℕ) => ball x (1 / (↑n + 1)) := nhds_basis_uniformity uniformity_basis_dist_inv_nat_succ theorem nhds_basis_ball_inv_nat_pos {α : Type u} [metric_space α] {x : α} : filter.has_basis (nhds x) (fun (n : ℕ) => 0 < n) fun (n : ℕ) => ball x (1 / ↑n) := nhds_basis_uniformity uniformity_basis_dist_inv_nat_pos theorem is_open_iff {α : Type u} [metric_space α] {s : set α} : is_open s ↔ ∀ (x : α) (H : x ∈ s), ∃ (ε : ℝ), ∃ (H : ε > 0), ball x ε ⊆ s := sorry theorem is_open_ball {α : Type u} [metric_space α] {x : α} {ε : ℝ} : is_open (ball x ε) := iff.mpr is_open_iff fun (y : α) => exists_ball_subset_ball theorem ball_mem_nhds {α : Type u} [metric_space α] (x : α) {ε : ℝ} (ε0 : 0 < ε) : ball x ε ∈ nhds x := mem_nhds_sets is_open_ball (mem_ball_self ε0) theorem closed_ball_mem_nhds {α : Type u} [metric_space α] (x : α) {ε : ℝ} (ε0 : 0 < ε) : closed_ball x ε ∈ nhds x := filter.mem_sets_of_superset (ball_mem_nhds x ε0) ball_subset_closed_ball theorem nhds_within_basis_ball {α : Type u} [metric_space α] {x : α} {s : set α} : filter.has_basis (nhds_within x s) (fun (ε : ℝ) => 0 < ε) fun (ε : ℝ) => ball x ε ∩ s := nhds_within_has_basis nhds_basis_ball s theorem mem_nhds_within_iff {α : Type u} [metric_space α] {x : α} {s : set α} {t : set α} : s ∈ nhds_within x t ↔ ∃ (ε : ℝ), ∃ (H : ε > 0), ball x ε ∩ t ⊆ s := filter.has_basis.mem_iff nhds_within_basis_ball theorem tendsto_nhds_within_nhds_within {α : Type u} {β : Type v} [metric_space α] {s : set α} [metric_space β] {t : set β} {f : α → β} {a : α} {b : β} : filter.tendsto f (nhds_within a s) (nhds_within b t) ↔ ∀ (ε : ℝ) (H : ε > 0), ∃ (δ : ℝ), ∃ (H : δ > 0), ∀ {x : α}, x ∈ s → dist x a < δ → f x ∈ t ∧ dist (f x) b < ε := sorry theorem tendsto_nhds_within_nhds {α : Type u} {β : Type v} [metric_space α] {s : set α} [metric_space β] {f : α → β} {a : α} {b : β} : filter.tendsto f (nhds_within a s) (nhds b) ↔ ∀ (ε : ℝ) (H : ε > 0), ∃ (δ : ℝ), ∃ (H : δ > 0), ∀ {x : α}, x ∈ s → dist x a < δ → dist (f x) b < ε := sorry theorem tendsto_nhds_nhds {α : Type u} {β : Type v} [metric_space α] [metric_space β] {f : α → β} {a : α} {b : β} : filter.tendsto f (nhds a) (nhds b) ↔ ∀ (ε : ℝ) (H : ε > 0), ∃ (δ : ℝ), ∃ (H : δ > 0), ∀ {x : α}, dist x a < δ → dist (f x) b < ε := filter.has_basis.tendsto_iff nhds_basis_ball nhds_basis_ball theorem continuous_at_iff {α : Type u} {β : Type v} [metric_space α] [metric_space β] {f : α → β} {a : α} : continuous_at f a ↔ ∀ (ε : ℝ) (H : ε > 0), ∃ (δ : ℝ), ∃ (H : δ > 0), ∀ {x : α}, dist x a < δ → dist (f x) (f a) < ε := sorry theorem continuous_within_at_iff {α : Type u} {β : Type v} [metric_space α] [metric_space β] {f : α → β} {a : α} {s : set α} : continuous_within_at f s a ↔ ∀ (ε : ℝ) (H : ε > 0), ∃ (δ : ℝ), ∃ (H : δ > 0), ∀ {x : α}, x ∈ s → dist x a < δ → dist (f x) (f a) < ε := sorry theorem continuous_on_iff {α : Type u} {β : Type v} [metric_space α] [metric_space β] {f : α → β} {s : set α} : continuous_on f s ↔ ∀ (b : α) (H : b ∈ s) (ε : ℝ) (H : ε > 0), ∃ (δ : ℝ), ∃ (H : δ > 0), ∀ (a : α), a ∈ s → dist a b < δ → dist (f a) (f b) < ε := sorry theorem continuous_iff {α : Type u} {β : Type v} [metric_space α] [metric_space β] {f : α → β} : continuous f ↔ ∀ (b : α) (ε : ℝ) (H : ε > 0), ∃ (δ : ℝ), ∃ (H : δ > 0), ∀ (a : α), dist a b < δ → dist (f a) (f b) < ε := iff.trans continuous_iff_continuous_at (forall_congr fun (b : α) => tendsto_nhds_nhds) theorem tendsto_nhds {α : Type u} {β : Type v} [metric_space α] {f : filter β} {u : β → α} {a : α} : filter.tendsto u f (nhds a) ↔ ∀ (ε : ℝ), ε > 0 → filter.eventually (fun (x : β) => dist (u x) a < ε) f := filter.has_basis.tendsto_right_iff nhds_basis_ball theorem continuous_at_iff' {α : Type u} {β : Type v} [metric_space α] [topological_space β] {f : β → α} {b : β} : continuous_at f b ↔ ∀ (ε : ℝ), ε > 0 → filter.eventually (fun (x : β) => dist (f x) (f b) < ε) (nhds b) := sorry theorem continuous_within_at_iff' {α : Type u} {β : Type v} [metric_space α] [topological_space β] {f : β → α} {b : β} {s : set β} : continuous_within_at f s b ↔ ∀ (ε : ℝ), ε > 0 → filter.eventually (fun (x : β) => dist (f x) (f b) < ε) (nhds_within b s) := sorry theorem continuous_on_iff' {α : Type u} {β : Type v} [metric_space α] [topological_space β] {f : β → α} {s : set β} : continuous_on f s ↔ ∀ (b : β), b ∈ s → ∀ (ε : ℝ), ε > 0 → filter.eventually (fun (x : β) => dist (f x) (f b) < ε) (nhds_within b s) := sorry theorem continuous_iff' {α : Type u} {β : Type v} [metric_space α] [topological_space β] {f : β → α} : continuous f ↔ ∀ (a : β) (ε : ℝ), ε > 0 → filter.eventually (fun (x : β) => dist (f x) (f a) < ε) (nhds a) := iff.trans continuous_iff_continuous_at (forall_congr fun (b : β) => tendsto_nhds) theorem tendsto_at_top {α : Type u} {β : Type v} [metric_space α] [Nonempty β] [semilattice_sup β] {u : β → α} {a : α} : filter.tendsto u filter.at_top (nhds a) ↔ ∀ (ε : ℝ), ε > 0 → ∃ (N : β), ∀ (n : β), n ≥ N → dist (u n) a < ε := sorry theorem is_open_singleton_iff {X : Type u_1} [metric_space X] {x : X} : is_open (singleton x) ↔ ∃ (ε : ℝ), ∃ (H : ε > 0), ∀ (y : X), dist y x < ε → y = x := sorry /-- Given a point `x` in a discrete subset `s` of a metric space, there is an open ball centered at `x` and intersecting `s` only at `x`. -/ theorem exists_ball_inter_eq_singleton_of_mem_discrete {α : Type u} [metric_space α] {s : set α} [discrete_topology ↥s] {x : α} (hx : x ∈ s) : ∃ (ε : ℝ), ∃ (H : ε > 0), ball x ε ∩ s = singleton x := filter.has_basis.exists_inter_eq_singleton_of_mem_discrete nhds_basis_ball hx /-- Given a point `x` in a discrete subset `s` of a metric space, there is a closed ball of positive radius centered at `x` and intersecting `s` only at `x`. -/ theorem exists_closed_ball_inter_eq_singleton_of_discrete {α : Type u} [metric_space α] {s : set α} [discrete_topology ↥s] {x : α} (hx : x ∈ s) : ∃ (ε : ℝ), ∃ (H : ε > 0), closed_ball x ε ∩ s = singleton x := filter.has_basis.exists_inter_eq_singleton_of_mem_discrete nhds_basis_closed_ball hx end metric protected instance metric_space.to_separated {α : Type u} [metric_space α] : separated_space α := iff.mpr separated_def fun (x y : α) (h : ∀ (r : set (α × α)), r ∈ uniformity α → (x, y) ∈ r) => eq_of_forall_dist_le fun (ε : ℝ) (ε0 : ε > 0) => le_of_lt (h (set_of fun (p : α × α) => dist (prod.fst p) (prod.snd p) < ε) (metric.dist_mem_uniformity ε0)) /-Instantiate a metric space as an emetric space. Before we can state the instance, we need to show that the uniform structure coming from the edistance and the distance coincide. -/ /-- Expressing the uniformity in terms of `edist` -/ protected theorem metric.uniformity_basis_edist {α : Type u} [metric_space α] : filter.has_basis (uniformity α) (fun (ε : ennreal) => 0 < ε) fun (ε : ennreal) => set_of fun (p : α × α) => edist (prod.fst p) (prod.snd p) < ε := sorry theorem metric.uniformity_edist {α : Type u} [metric_space α] : uniformity α = infi fun (ε : ennreal) => infi fun (H : ε > 0) => filter.principal (set_of fun (p : α × α) => edist (prod.fst p) (prod.snd p) < ε) := filter.has_basis.eq_binfi metric.uniformity_basis_edist /-- A metric space induces an emetric space -/ protected instance metric_space.to_emetric_space {α : Type u} [metric_space α] : emetric_space α := emetric_space.mk sorry sorry sorry sorry metric_space.to_uniform_space /-- Balls defined using the distance or the edistance coincide -/ theorem metric.emetric_ball {α : Type u} [metric_space α] {x : α} {ε : ℝ} : emetric.ball x (ennreal.of_real ε) = metric.ball x ε := sorry /-- Balls defined using the distance or the edistance coincide -/ theorem metric.emetric_ball_nnreal {α : Type u} [metric_space α] {x : α} {ε : nnreal} : emetric.ball x ↑ε = metric.ball x ↑ε := sorry /-- Closed balls defined using the distance or the edistance coincide -/ theorem metric.emetric_closed_ball {α : Type u} [metric_space α] {x : α} {ε : ℝ} (h : 0 ≤ ε) : emetric.closed_ball x (ennreal.of_real ε) = metric.closed_ball x ε := sorry /-- Closed balls defined using the distance or the edistance coincide -/ theorem metric.emetric_closed_ball_nnreal {α : Type u} [metric_space α] {x : α} {ε : nnreal} : emetric.closed_ball x ↑ε = metric.closed_ball x ↑ε := sorry /-- Build a new metric space from an old one where the bundled uniform structure is provably (but typically non-definitionaly) equal to some given uniform structure. See Note [forgetful inheritance]. -/ def metric_space.replace_uniformity {α : Type u_1} [U : uniform_space α] (m : metric_space α) (H : uniformity α = uniformity α) : metric_space α := metric_space.mk dist_self eq_of_dist_eq_zero dist_comm dist_triangle edist U /-- One gets a metric space from an emetric space if the edistance is everywhere finite, by pushing the edistance to reals. We set it up so that the edist and the uniformity are defeq in the metric space and the emetric space. In this definition, the distance is given separately, to be able to prescribe some expression which is not defeq to the push-forward of the edistance to reals. -/ def emetric_space.to_metric_space_of_dist {α : Type u} [e : emetric_space α] (dist : α → α → ℝ) (edist_ne_top : ∀ (x y : α), edist x y ≠ ⊤) (h : ∀ (x y : α), dist x y = ennreal.to_real (edist x y)) : metric_space α := let m : metric_space α := metric_space.mk sorry sorry sorry sorry (fun (x y : α) => edist x y) (uniform_space_of_dist dist sorry sorry sorry); metric_space.replace_uniformity m sorry /-- One gets a metric space from an emetric space if the edistance is everywhere finite, by pushing the edistance to reals. We set it up so that the edist and the uniformity are defeq in the metric space and the emetric space. -/ def emetric_space.to_metric_space {α : Type u} [e : emetric_space α] (h : ∀ (x y : α), edist x y ≠ ⊤) : metric_space α := emetric_space.to_metric_space_of_dist (fun (x y : α) => ennreal.to_real (edist x y)) h sorry /-- A very useful criterion to show that a space is complete is to show that all sequences which satisfy a bound of the form `dist (u n) (u m) < B N` for all `n m ≥ N` are converging. This is often applied for `B N = 2^{-N}`, i.e., with a very fast convergence to `0`, which makes it possible to use arguments of converging series, while this is impossible to do in general for arbitrary Cauchy sequences. -/ theorem metric.complete_of_convergent_controlled_sequences {α : Type u} [metric_space α] (B : ℕ → ℝ) (hB : ∀ (n : ℕ), 0 < B n) (H : ∀ (u : ℕ → α), (∀ (N n m : ℕ), N ≤ n → N ≤ m → dist (u n) (u m) < B N) → ∃ (x : α), filter.tendsto u filter.at_top (nhds x)) : complete_space α := sorry theorem metric.complete_of_cauchy_seq_tendsto {α : Type u} [metric_space α] : (∀ (u : ℕ → α), cauchy_seq u → ∃ (a : α), filter.tendsto u filter.at_top (nhds a)) → complete_space α := emetric.complete_of_cauchy_seq_tendsto /-- Instantiate the reals as a metric space. -/ protected instance real.metric_space : metric_space ℝ := metric_space.mk sorry sorry sorry sorry (fun (x y : ℝ) => ennreal.of_real ((fun (x y : ℝ) => abs (x - y)) x y)) (uniform_space_of_dist (fun (x y : ℝ) => abs (x - y)) sorry sorry sorry) theorem real.dist_eq (x : ℝ) (y : ℝ) : dist x y = abs (x - y) := rfl theorem real.dist_0_eq_abs (x : ℝ) : dist x 0 = abs x := sorry protected instance real.order_topology : order_topology ℝ := sorry theorem closed_ball_Icc {x : ℝ} {r : ℝ} : metric.closed_ball x r = set.Icc (x - r) (x + r) := sorry /-- Special case of the sandwich theorem; see `tendsto_of_tendsto_of_tendsto_of_le_of_le'` for the general case. -/ theorem squeeze_zero' {α : Type u_1} {f : α → ℝ} {g : α → ℝ} {t₀ : filter α} (hf : filter.eventually (fun (t : α) => 0 ≤ f t) t₀) (hft : filter.eventually (fun (t : α) => f t ≤ g t) t₀) (g0 : filter.tendsto g t₀ (nhds 0)) : filter.tendsto f t₀ (nhds 0) := tendsto_of_tendsto_of_tendsto_of_le_of_le' tendsto_const_nhds g0 hf hft /-- Special case of the sandwich theorem; see `tendsto_of_tendsto_of_tendsto_of_le_of_le` and `tendsto_of_tendsto_of_tendsto_of_le_of_le'` for the general case. -/ theorem squeeze_zero {α : Type u_1} {f : α → ℝ} {g : α → ℝ} {t₀ : filter α} (hf : ∀ (t : α), 0 ≤ f t) (hft : ∀ (t : α), f t ≤ g t) (g0 : filter.tendsto g t₀ (nhds 0)) : filter.tendsto f t₀ (nhds 0) := squeeze_zero' (filter.eventually_of_forall hf) (filter.eventually_of_forall hft) g0 theorem metric.uniformity_eq_comap_nhds_zero {α : Type u} [metric_space α] : uniformity α = filter.comap (fun (p : α × α) => dist (prod.fst p) (prod.snd p)) (nhds 0) := sorry theorem cauchy_seq_iff_tendsto_dist_at_top_0 {α : Type u} {β : Type v} [metric_space α] [Nonempty β] [semilattice_sup β] {u : β → α} : cauchy_seq u ↔ filter.tendsto (fun (n : β × β) => dist (u (prod.fst n)) (u (prod.snd n))) filter.at_top (nhds 0) := sorry theorem tendsto_uniformity_iff_dist_tendsto_zero {α : Type u} [metric_space α] {ι : Type u_1} {f : ι → α × α} {p : filter ι} : filter.tendsto f p (uniformity α) ↔ filter.tendsto (fun (x : ι) => dist (prod.fst (f x)) (prod.snd (f x))) p (nhds 0) := sorry theorem filter.tendsto.congr_dist {α : Type u} [metric_space α] {ι : Type u_1} {f₁ : ι → α} {f₂ : ι → α} {p : filter ι} {a : α} (h₁ : filter.tendsto f₁ p (nhds a)) (h : filter.tendsto (fun (x : ι) => dist (f₁ x) (f₂ x)) p (nhds 0)) : filter.tendsto f₂ p (nhds a) := filter.tendsto.congr_uniformity h₁ (iff.mpr tendsto_uniformity_iff_dist_tendsto_zero h) theorem tendsto_of_tendsto_of_dist {α : Type u} [metric_space α] {ι : Type u_1} {f₁ : ι → α} {f₂ : ι → α} {p : filter ι} {a : α} (h₁ : filter.tendsto f₁ p (nhds a)) (h : filter.tendsto (fun (x : ι) => dist (f₁ x) (f₂ x)) p (nhds 0)) : filter.tendsto f₂ p (nhds a) := filter.tendsto.congr_dist theorem tendsto_iff_of_dist {α : Type u} [metric_space α] {ι : Type u_1} {f₁ : ι → α} {f₂ : ι → α} {p : filter ι} {a : α} (h : filter.tendsto (fun (x : ι) => dist (f₁ x) (f₂ x)) p (nhds 0)) : filter.tendsto f₁ p (nhds a) ↔ filter.tendsto f₂ p (nhds a) := uniform.tendsto_congr (iff.mpr tendsto_uniformity_iff_dist_tendsto_zero h) /-- In a metric space, Cauchy sequences are characterized by the fact that, eventually, the distance between its elements is arbitrarily small -/ theorem metric.cauchy_seq_iff {α : Type u} {β : Type v} [metric_space α] [Nonempty β] [semilattice_sup β] {u : β → α} : cauchy_seq u ↔ ∀ (ε : ℝ), ε > 0 → ∃ (N : β), ∀ (m n : β), m ≥ N → n ≥ N → dist (u m) (u n) < ε := filter.has_basis.cauchy_seq_iff metric.uniformity_basis_dist /-- A variation around the metric characterization of Cauchy sequences -/ theorem metric.cauchy_seq_iff' {α : Type u} {β : Type v} [metric_space α] [Nonempty β] [semilattice_sup β] {u : β → α} : cauchy_seq u ↔ ∀ (ε : ℝ), ε > 0 → ∃ (N : β), ∀ (n : β), n ≥ N → dist (u n) (u N) < ε := filter.has_basis.cauchy_seq_iff' metric.uniformity_basis_dist /-- If the distance between `s n` and `s m`, `n, m ≥ N` is bounded above by `b N` and `b` converges to zero, then `s` is a Cauchy sequence. -/ theorem cauchy_seq_of_le_tendsto_0 {α : Type u} {β : Type v} [metric_space α] [Nonempty β] [semilattice_sup β] {s : β → α} (b : β → ℝ) (h : ∀ (n m N : β), N ≤ n → N ≤ m → dist (s n) (s m) ≤ b N) (h₀ : filter.tendsto b filter.at_top (nhds 0)) : cauchy_seq s := sorry /-- A Cauchy sequence on the natural numbers is bounded. -/ theorem cauchy_seq_bdd {α : Type u} [metric_space α] {u : ℕ → α} (hu : cauchy_seq u) : ∃ (R : ℝ), ∃ (H : R > 0), ∀ (m n : ℕ), dist (u m) (u n) < R := sorry /-- Yet another metric characterization of Cauchy sequences on integers. This one is often the most efficient. -/ theorem cauchy_seq_iff_le_tendsto_0 {α : Type u} [metric_space α] {s : ℕ → α} : cauchy_seq s ↔ ∃ (b : ℕ → ℝ), (∀ (n : ℕ), 0 ≤ b n) ∧ (∀ (n m N : ℕ), N ≤ n → N ≤ m → dist (s n) (s m) ≤ b N) ∧ filter.tendsto b filter.at_top (nhds 0) := sorry /-- Metric space structure pulled back by an injective function. Injectivity is necessary to ensure that `dist x y = 0` only if `x = y`. -/ def metric_space.induced {α : Type u_1} {β : Type u_2} (f : α → β) (hf : function.injective f) (m : metric_space β) : metric_space α := metric_space.mk sorry sorry sorry sorry (fun (x y : α) => edist (f x) (f y)) (uniform_space.comap f metric_space.to_uniform_space) protected instance subtype.metric_space {α : Type u_1} {p : α → Prop} [t : metric_space α] : metric_space (Subtype p) := metric_space.induced coe sorry t theorem subtype.dist_eq {α : Type u} [metric_space α] {p : α → Prop} (x : Subtype p) (y : Subtype p) : dist x y = dist ↑x ↑y := rfl protected instance nnreal.metric_space : metric_space nnreal := eq.mpr sorry subtype.metric_space theorem nnreal.dist_eq (a : nnreal) (b : nnreal) : dist a b = abs (↑a - ↑b) := rfl theorem nnreal.nndist_eq (a : nnreal) (b : nnreal) : nndist a b = max (a - b) (b - a) := sorry protected instance prod.metric_space_max {α : Type u} {β : Type v} [metric_space α] [metric_space β] : metric_space (α × β) := metric_space.mk sorry sorry sorry sorry (fun (x y : α × β) => max (edist (prod.fst x) (prod.fst y)) (edist (prod.snd x) (prod.snd y))) prod.uniform_space theorem prod.dist_eq {α : Type u} {β : Type v} [metric_space α] [metric_space β] {x : α × β} {y : α × β} : dist x y = max (dist (prod.fst x) (prod.fst y)) (dist (prod.snd x) (prod.snd y)) := rfl theorem ball_prod_same {α : Type u} {β : Type v} [metric_space α] [metric_space β] (x : α) (y : β) (r : ℝ) : set.prod (metric.ball x r) (metric.ball y r) = metric.ball (x, y) r := sorry theorem closed_ball_prod_same {α : Type u} {β : Type v} [metric_space α] [metric_space β] (x : α) (y : β) (r : ℝ) : set.prod (metric.closed_ball x r) (metric.closed_ball y r) = metric.closed_ball (x, y) r := sorry theorem uniform_continuous_dist {α : Type u} [metric_space α] : uniform_continuous fun (p : α × α) => dist (prod.fst p) (prod.snd p) := sorry theorem uniform_continuous.dist {α : Type u} {β : Type v} [metric_space α] [uniform_space β] {f : β → α} {g : β → α} (hf : uniform_continuous f) (hg : uniform_continuous g) : uniform_continuous fun (b : β) => dist (f b) (g b) := uniform_continuous.comp uniform_continuous_dist (uniform_continuous.prod_mk hf hg) theorem continuous_dist {α : Type u} [metric_space α] : continuous fun (p : α × α) => dist (prod.fst p) (prod.snd p) := uniform_continuous.continuous uniform_continuous_dist theorem continuous.dist {α : Type u} {β : Type v} [metric_space α] [topological_space β] {f : β → α} {g : β → α} (hf : continuous f) (hg : continuous g) : continuous fun (b : β) => dist (f b) (g b) := continuous.comp continuous_dist (continuous.prod_mk hf hg) theorem filter.tendsto.dist {α : Type u} {β : Type v} [metric_space α] {f : β → α} {g : β → α} {x : filter β} {a : α} {b : α} (hf : filter.tendsto f x (nhds a)) (hg : filter.tendsto g x (nhds b)) : filter.tendsto (fun (x : β) => dist (f x) (g x)) x (nhds (dist a b)) := filter.tendsto.comp (continuous.tendsto continuous_dist (a, b)) (filter.tendsto.prod_mk_nhds hf hg) theorem nhds_comap_dist {α : Type u} [metric_space α] (a : α) : filter.comap (fun (a' : α) => dist a' a) (nhds 0) = nhds a := sorry theorem tendsto_iff_dist_tendsto_zero {α : Type u} {β : Type v} [metric_space α] {f : β → α} {x : filter β} {a : α} : filter.tendsto f x (nhds a) ↔ filter.tendsto (fun (b : β) => dist (f b) a) x (nhds 0) := sorry theorem uniform_continuous_nndist {α : Type u} [metric_space α] : uniform_continuous fun (p : α × α) => nndist (prod.fst p) (prod.snd p) := uniform_continuous_subtype_mk uniform_continuous_dist fun (p : α × α) => dist_nonneg theorem uniform_continuous.nndist {α : Type u} {β : Type v} [metric_space α] [uniform_space β] {f : β → α} {g : β → α} (hf : uniform_continuous f) (hg : uniform_continuous g) : uniform_continuous fun (b : β) => nndist (f b) (g b) := uniform_continuous.comp uniform_continuous_nndist (uniform_continuous.prod_mk hf hg) theorem continuous_nndist {α : Type u} [metric_space α] : continuous fun (p : α × α) => nndist (prod.fst p) (prod.snd p) := uniform_continuous.continuous uniform_continuous_nndist theorem continuous.nndist {α : Type u} {β : Type v} [metric_space α] [topological_space β] {f : β → α} {g : β → α} (hf : continuous f) (hg : continuous g) : continuous fun (b : β) => nndist (f b) (g b) := continuous.comp continuous_nndist (continuous.prod_mk hf hg) theorem filter.tendsto.nndist {α : Type u} {β : Type v} [metric_space α] {f : β → α} {g : β → α} {x : filter β} {a : α} {b : α} (hf : filter.tendsto f x (nhds a)) (hg : filter.tendsto g x (nhds b)) : filter.tendsto (fun (x : β) => nndist (f x) (g x)) x (nhds (nndist a b)) := filter.tendsto.comp (continuous.tendsto continuous_nndist (a, b)) (filter.tendsto.prod_mk_nhds hf hg) namespace metric theorem is_closed_ball {α : Type u} [metric_space α] {x : α} {ε : ℝ} : is_closed (closed_ball x ε) := is_closed_le (continuous.dist continuous_id continuous_const) continuous_const theorem is_closed_sphere {α : Type u} [metric_space α] {x : α} {ε : ℝ} : is_closed (sphere x ε) := is_closed_eq (continuous.dist continuous_id continuous_const) continuous_const @[simp] theorem closure_closed_ball {α : Type u} [metric_space α] {x : α} {ε : ℝ} : closure (closed_ball x ε) = closed_ball x ε := is_closed.closure_eq is_closed_ball theorem closure_ball_subset_closed_ball {α : Type u} [metric_space α] {x : α} {ε : ℝ} : closure (ball x ε) ⊆ closed_ball x ε := closure_minimal ball_subset_closed_ball is_closed_ball theorem frontier_ball_subset_sphere {α : Type u} [metric_space α] {x : α} {ε : ℝ} : frontier (ball x ε) ⊆ sphere x ε := frontier_lt_subset_eq (continuous.dist continuous_id continuous_const) continuous_const theorem frontier_closed_ball_subset_sphere {α : Type u} [metric_space α] {x : α} {ε : ℝ} : frontier (closed_ball x ε) ⊆ sphere x ε := frontier_le_subset_eq (continuous.dist continuous_id continuous_const) continuous_const theorem ball_subset_interior_closed_ball {α : Type u} [metric_space α] {x : α} {ε : ℝ} : ball x ε ⊆ interior (closed_ball x ε) := interior_maximal ball_subset_closed_ball is_open_ball /-- ε-characterization of the closure in metric spaces-/ theorem mem_closure_iff {α : Type u} [metric_space α] {s : set α} {a : α} : a ∈ closure s ↔ ∀ (ε : ℝ) (H : ε > 0), ∃ (b : α), ∃ (H : b ∈ s), dist a b < ε := sorry theorem mem_closure_range_iff {β : Type v} {α : Type u} [metric_space α] {e : β → α} {a : α} : a ∈ closure (set.range e) ↔ ∀ (ε : ℝ), ε > 0 → ∃ (k : β), dist a (e k) < ε := sorry theorem mem_closure_range_iff_nat {β : Type v} {α : Type u} [metric_space α] {e : β → α} {a : α} : a ∈ closure (set.range e) ↔ ∀ (n : ℕ), ∃ (k : β), dist a (e k) < 1 / (↑n + 1) := sorry theorem mem_of_closed' {α : Type u} [metric_space α] {s : set α} (hs : is_closed s) {a : α} : a ∈ s ↔ ∀ (ε : ℝ) (H : ε > 0), ∃ (b : α), ∃ (H : b ∈ s), dist a b < ε := sorry end metric /-- A finite product of metric spaces is a metric space, with the sup distance. -/ protected instance metric_space_pi {β : Type v} {π : β → Type u_1} [fintype β] [(b : β) → metric_space (π b)] : metric_space ((b : β) → π b) := emetric_space.to_metric_space_of_dist (fun (f g : (b : β) → π b) => ↑(finset.sup finset.univ fun (b : β) => nndist (f b) (g b))) sorry sorry theorem nndist_pi_def {β : Type v} {π : β → Type u_1} [fintype β] [(b : β) → metric_space (π b)] (f : (b : β) → π b) (g : (b : β) → π b) : nndist f g = finset.sup finset.univ fun (b : β) => nndist (f b) (g b) := subtype.eta (finset.sup finset.univ fun (b : β) => nndist (f b) (g b)) dist_nonneg theorem dist_pi_def {β : Type v} {π : β → Type u_1} [fintype β] [(b : β) → metric_space (π b)] (f : (b : β) → π b) (g : (b : β) → π b) : dist f g = ↑(finset.sup finset.univ fun (b : β) => nndist (f b) (g b)) := rfl @[simp] theorem dist_pi_const {α : Type u} {β : Type v} [metric_space α] [fintype β] [Nonempty β] (a : α) (b : α) : (dist (fun (x : β) => a) fun (_x : β) => b) = dist a b := sorry @[simp] theorem nndist_pi_const {α : Type u} {β : Type v} [metric_space α] [fintype β] [Nonempty β] (a : α) (b : α) : (nndist (fun (x : β) => a) fun (_x : β) => b) = nndist a b := nnreal.eq (dist_pi_const a b) theorem dist_pi_lt_iff {β : Type v} {π : β → Type u_1} [fintype β] [(b : β) → metric_space (π b)] {f : (b : β) → π b} {g : (b : β) → π b} {r : ℝ} (hr : 0 < r) : dist f g < r ↔ ∀ (b : β), dist (f b) (g b) < r := sorry theorem dist_pi_le_iff {β : Type v} {π : β → Type u_1} [fintype β] [(b : β) → metric_space (π b)] {f : (b : β) → π b} {g : (b : β) → π b} {r : ℝ} (hr : 0 ≤ r) : dist f g ≤ r ↔ ∀ (b : β), dist (f b) (g b) ≤ r := sorry theorem nndist_le_pi_nndist {β : Type v} {π : β → Type u_1} [fintype β] [(b : β) → metric_space (π b)] (f : (b : β) → π b) (g : (b : β) → π b) (b : β) : nndist (f b) (g b) ≤ nndist f g := eq.mpr (id (Eq._oldrec (Eq.refl (nndist (f b) (g b) ≤ nndist f g)) (nndist_pi_def f g))) (finset.le_sup (finset.mem_univ b)) theorem dist_le_pi_dist {β : Type v} {π : β → Type u_1} [fintype β] [(b : β) → metric_space (π b)] (f : (b : β) → π b) (g : (b : β) → π b) (b : β) : dist (f b) (g b) ≤ dist f g := sorry /-- An open ball in a product space is a product of open balls. The assumption `0 < r` is necessary for the case of the empty product. -/ theorem ball_pi {β : Type v} {π : β → Type u_1} [fintype β] [(b : β) → metric_space (π b)] (x : (b : β) → π b) {r : ℝ} (hr : 0 < r) : metric.ball x r = set_of fun (y : (b : β) → π b) => ∀ (b : β), y b ∈ metric.ball (x b) r := sorry /-- A closed ball in a product space is a product of closed balls. The assumption `0 ≤ r` is necessary for the case of the empty product. -/ theorem closed_ball_pi {β : Type v} {π : β → Type u_1} [fintype β] [(b : β) → metric_space (π b)] (x : (b : β) → π b) {r : ℝ} (hr : 0 ≤ r) : metric.closed_ball x r = set_of fun (y : (b : β) → π b) => ∀ (b : β), y b ∈ metric.closed_ball (x b) r := sorry /-- Any compact set in a metric space can be covered by finitely many balls of a given positive radius -/ theorem finite_cover_balls_of_compact {α : Type u} [metric_space α] {s : set α} (hs : is_compact s) {e : ℝ} (he : 0 < e) : ∃ (t : set α), ∃ (H : t ⊆ s), set.finite t ∧ s ⊆ set.Union fun (x : α) => set.Union fun (H : x ∈ t) => metric.ball x e := sorry theorem is_compact.finite_cover_balls {α : Type u} [metric_space α] {s : set α} (hs : is_compact s) {e : ℝ} (he : 0 < e) : ∃ (t : set α), ∃ (H : t ⊆ s), set.finite t ∧ s ⊆ set.Union fun (x : α) => set.Union fun (H : x ∈ t) => metric.ball x e := finite_cover_balls_of_compact /-- A metric space is proper if all closed balls are compact. -/ class proper_space (α : Type u) [metric_space α] where compact_ball : ∀ (x : α) (r : ℝ), is_compact (metric.closed_ball x r) theorem tendsto_dist_right_cocompact_at_top {α : Type u} [metric_space α] [proper_space α] (x : α) : filter.tendsto (fun (y : α) => dist y x) (filter.cocompact α) filter.at_top := sorry theorem tendsto_dist_left_cocompact_at_top {α : Type u} [metric_space α] [proper_space α] (x : α) : filter.tendsto (dist x) (filter.cocompact α) filter.at_top := sorry /-- If all closed balls of large enough radius are compact, then the space is proper. Especially useful when the lower bound for the radius is 0. -/ theorem proper_space_of_compact_closed_ball_of_le {α : Type u} [metric_space α] (R : ℝ) (h : ∀ (x : α) (r : ℝ), R ≤ r → is_compact (metric.closed_ball x r)) : proper_space α := sorry /- A compact metric space is proper -/ protected instance proper_of_compact {α : Type u} [metric_space α] [compact_space α] : proper_space α := proper_space.mk fun (x : α) (r : ℝ) => is_closed.compact metric.is_closed_ball /-- A proper space is locally compact -/ protected instance locally_compact_of_proper {α : Type u} [metric_space α] [proper_space α] : locally_compact_space α := locally_compact_of_compact_nhds fun (x : α) => Exists.intro (metric.closed_ball x 1) { left := iff.mpr metric.mem_nhds_iff (Exists.intro 1 (eq.mpr (id (Eq.trans (propext exists_prop) ((fun (a a_1 : Prop) (e_1 : a = a_1) (b b_1 : Prop) (e_2 : b = b_1) => congr (congr_arg And e_1) e_2) (1 > 0) (0 < 1) (propext gt_iff_lt) (metric.ball x 1 ⊆ metric.closed_ball x 1) (metric.ball x 1 ⊆ metric.closed_ball x 1) (Eq.refl (metric.ball x 1 ⊆ metric.closed_ball x 1))))) { left := zero_lt_one, right := metric.ball_subset_closed_ball })), right := proper_space.compact_ball x 1 } /-- A proper space is complete -/ protected instance complete_of_proper {α : Type u} [metric_space α] [proper_space α] : complete_space α := sorry /-- A proper metric space is separable, and therefore second countable. Indeed, any ball is compact, and therefore admits a countable dense subset. Taking a countable union over the balls centered at a fixed point and with integer radius, one obtains a countable set which is dense in the whole space. -/ protected instance second_countable_of_proper {α : Type u} [metric_space α] [proper_space α] : topological_space.second_countable_topology α := emetric.second_countable_of_separable α /-- A finite product of proper spaces is proper. -/ protected instance pi_proper_space {β : Type v} {π : β → Type u_1} [fintype β] [(b : β) → metric_space (π b)] [h : ∀ (b : β), proper_space (π b)] : proper_space ((b : β) → π b) := proper_space_of_compact_closed_ball_of_le 0 fun (x : (b : β) → π b) (r : ℝ) (hr : 0 ≤ r) => eq.mpr (id (Eq._oldrec (Eq.refl (is_compact (metric.closed_ball x r))) (closed_ball_pi x hr))) (compact_pi_infinite fun (b : β) => proper_space.compact_ball (x b) r) namespace metric /-- A metric space is second countable if, for every `ε > 0`, there is a countable set which is `ε`-dense. -/ theorem second_countable_of_almost_dense_set {α : Type u} [metric_space α] (H : ∀ (ε : ℝ) (H : ε > 0), ∃ (s : set α), set.countable s ∧ ∀ (x : α), ∃ (y : α), ∃ (H : y ∈ s), dist x y ≤ ε) : topological_space.second_countable_topology α := sorry /-- A metric space space is second countable if one can reconstruct up to any `ε>0` any element of the space from countably many data. -/ theorem second_countable_of_countable_discretization {α : Type u} [metric_space α] (H : ∀ (ε : ℝ), ε > 0 → ∃ (β : Type u_1), Exists (∃ (F : α → β), ∀ (x y : α), F x = F y → dist x y ≤ ε)) : topological_space.second_countable_topology α := sorry end metric theorem lebesgue_number_lemma_of_metric {α : Type u} [metric_space α] {s : set α} {ι : Sort u_1} {c : ι → set α} (hs : is_compact s) (hc₁ : ∀ (i : ι), is_open (c i)) (hc₂ : s ⊆ set.Union fun (i : ι) => c i) : ∃ (δ : ℝ), ∃ (H : δ > 0), ∀ (x : α), x ∈ s → ∃ (i : ι), metric.ball x δ ⊆ c i := sorry theorem lebesgue_number_lemma_of_metric_sUnion {α : Type u} [metric_space α] {s : set α} {c : set (set α)} (hs : is_compact s) (hc₁ : ∀ (t : set α), t ∈ c → is_open t) (hc₂ : s ⊆ ⋃₀c) : ∃ (δ : ℝ), ∃ (H : δ > 0), ∀ (x : α) (H : x ∈ s), ∃ (t : set α), ∃ (H : t ∈ c), metric.ball x δ ⊆ t := sorry namespace metric /-- Boundedness of a subset of a metric space. We formulate the definition to work even in the empty space. -/ def bounded {α : Type u} [metric_space α] (s : set α) := ∃ (C : ℝ), ∀ (x y : α), x ∈ s → y ∈ s → dist x y ≤ C @[simp] theorem bounded_empty {α : Type u} [metric_space α] : bounded ∅ := sorry theorem bounded_iff_mem_bounded {α : Type u} [metric_space α] {s : set α} : bounded s ↔ ∀ (x : α), x ∈ s → bounded s := sorry /-- Subsets of a bounded set are also bounded -/ theorem bounded.subset {α : Type u} [metric_space α] {s : set α} {t : set α} (incl : s ⊆ t) : bounded t → bounded s := Exists.imp fun (C : ℝ) (hC : ∀ (x y : α), x ∈ t → y ∈ t → dist x y ≤ C) (x y : α) (hx : x ∈ s) (hy : y ∈ s) => hC x y (incl hx) (incl hy) /-- Closed balls are bounded -/ theorem bounded_closed_ball {α : Type u} [metric_space α] {x : α} {r : ℝ} : bounded (closed_ball x r) := sorry /-- Open balls are bounded -/ theorem bounded_ball {α : Type u} [metric_space α] {x : α} {r : ℝ} : bounded (ball x r) := bounded.subset ball_subset_closed_ball bounded_closed_ball /-- Given a point, a bounded subset is included in some ball around this point -/ theorem bounded_iff_subset_ball {α : Type u} [metric_space α] {s : set α} (c : α) : bounded s ↔ ∃ (r : ℝ), s ⊆ closed_ball c r := sorry theorem bounded_closure_of_bounded {α : Type u} [metric_space α] {s : set α} (h : bounded s) : bounded (closure s) := sorry theorem Mathlib.bounded.closure {α : Type u} [metric_space α] {s : set α} (h : bounded s) : bounded (closure s) := bounded_closure_of_bounded /-- The union of two bounded sets is bounded iff each of the sets is bounded -/ @[simp] theorem bounded_union {α : Type u} [metric_space α] {s : set α} {t : set α} : bounded (s ∪ t) ↔ bounded s ∧ bounded t := sorry /-- A finite union of bounded sets is bounded -/ theorem bounded_bUnion {α : Type u} {β : Type v} [metric_space α] {I : set β} {s : β → set α} (H : set.finite I) : bounded (set.Union fun (i : β) => set.Union fun (H : i ∈ I) => s i) ↔ ∀ (i : β), i ∈ I → bounded (s i) := sorry /-- A compact set is bounded -/ -- We cover the compact set by finitely many balls of radius 1, theorem bounded_of_compact {α : Type u} [metric_space α] {s : set α} (h : is_compact s) : bounded s := sorry -- and then argue that a finite union of bounded sets is bounded theorem Mathlib.is_compact.bounded {α : Type u} [metric_space α] {s : set α} (h : is_compact s) : bounded s := bounded_of_compact /-- A finite set is bounded -/ theorem bounded_of_finite {α : Type u} [metric_space α] {s : set α} (h : set.finite s) : bounded s := is_compact.bounded (set.finite.is_compact h) /-- A singleton is bounded -/ theorem bounded_singleton {α : Type u} [metric_space α] {x : α} : bounded (singleton x) := bounded_of_finite (set.finite_singleton x) /-- Characterization of the boundedness of the range of a function -/ theorem bounded_range_iff {α : Type u} {β : Type v} [metric_space α] {f : β → α} : bounded (set.range f) ↔ ∃ (C : ℝ), ∀ (x y : β), dist (f x) (f y) ≤ C := sorry /-- In a compact space, all sets are bounded -/ theorem bounded_of_compact_space {α : Type u} [metric_space α] {s : set α} [compact_space α] : bounded s := bounded.subset (set.subset_univ s) (is_compact.bounded compact_univ) /-- The Heine–Borel theorem: In a proper space, a set is compact if and only if it is closed and bounded -/ theorem compact_iff_closed_bounded {α : Type u} [metric_space α] {s : set α} [proper_space α] : is_compact s ↔ is_closed s ∧ bounded s := sorry /-- The image of a proper space under an expanding onto map is proper. -/ theorem proper_image_of_proper {α : Type u} {β : Type v} [metric_space α] [proper_space α] [metric_space β] (f : α → β) (f_cont : continuous f) (hf : set.range f = set.univ) (C : ℝ) (hC : ∀ (x y : α), dist x y ≤ C * dist (f x) (f y)) : proper_space β := sorry /-- The diameter of a set in a metric space. To get controllable behavior even when the diameter should be infinite, we express it in terms of the emetric.diameter -/ def diam {α : Type u} [metric_space α] (s : set α) : ℝ := ennreal.to_real (emetric.diam s) /-- The diameter of a set is always nonnegative -/ theorem diam_nonneg {α : Type u} [metric_space α] {s : set α} : 0 ≤ diam s := ennreal.to_real_nonneg theorem diam_subsingleton {α : Type u} [metric_space α] {s : set α} (hs : set.subsingleton s) : diam s = 0 := sorry /-- The empty set has zero diameter -/ @[simp] theorem diam_empty {α : Type u} [metric_space α] : diam ∅ = 0 := diam_subsingleton set.subsingleton_empty /-- A singleton has zero diameter -/ @[simp] theorem diam_singleton {α : Type u} [metric_space α] {x : α} : diam (singleton x) = 0 := diam_subsingleton set.subsingleton_singleton -- Does not work as a simp-lemma, since {x, y} reduces to (insert y {x}) theorem diam_pair {α : Type u} [metric_space α] {x : α} {y : α} : diam (insert x (singleton y)) = dist x y := sorry -- Does not work as a simp-lemma, since {x, y, z} reduces to (insert z (insert y {x})) theorem diam_triple {α : Type u} [metric_space α] {x : α} {y : α} {z : α} : diam (insert x (insert y (singleton z))) = max (max (dist x y) (dist x z)) (dist y z) := sorry /-- If the distance between any two points in a set is bounded by some constant `C`, then `ennreal.of_real C` bounds the emetric diameter of this set. -/ theorem ediam_le_of_forall_dist_le {α : Type u} [metric_space α] {s : set α} {C : ℝ} (h : ∀ (x : α), x ∈ s → ∀ (y : α), y ∈ s → dist x y ≤ C) : emetric.diam s ≤ ennreal.of_real C := emetric.diam_le_of_forall_edist_le fun (x : α) (hx : x ∈ s) (y : α) (hy : y ∈ s) => Eq.symm (edist_dist x y) ▸ ennreal.of_real_le_of_real (h x hx y hy) /-- If the distance between any two points in a set is bounded by some non-negative constant, this constant bounds the diameter. -/ theorem diam_le_of_forall_dist_le {α : Type u} [metric_space α] {s : set α} {C : ℝ} (h₀ : 0 ≤ C) (h : ∀ (x : α), x ∈ s → ∀ (y : α), y ∈ s → dist x y ≤ C) : diam s ≤ C := ennreal.to_real_le_of_le_of_real h₀ (ediam_le_of_forall_dist_le h) /-- If the distance between any two points in a nonempty set is bounded by some constant, this constant bounds the diameter. -/ theorem diam_le_of_forall_dist_le_of_nonempty {α : Type u} [metric_space α] {s : set α} (hs : set.nonempty s) {C : ℝ} (h : ∀ (x : α), x ∈ s → ∀ (y : α), y ∈ s → dist x y ≤ C) : diam s ≤ C := sorry /-- The distance between two points in a set is controlled by the diameter of the set. -/ theorem dist_le_diam_of_mem' {α : Type u} [metric_space α] {s : set α} {x : α} {y : α} (h : emetric.diam s ≠ ⊤) (hx : x ∈ s) (hy : y ∈ s) : dist x y ≤ diam s := sorry /-- Characterize the boundedness of a set in terms of the finiteness of its emetric.diameter. -/ theorem bounded_iff_ediam_ne_top {α : Type u} [metric_space α] {s : set α} : bounded s ↔ emetric.diam s ≠ ⊤ := sorry theorem bounded.ediam_ne_top {α : Type u} [metric_space α] {s : set α} (h : bounded s) : emetric.diam s ≠ ⊤ := iff.mp bounded_iff_ediam_ne_top h /-- The distance between two points in a set is controlled by the diameter of the set. -/ theorem dist_le_diam_of_mem {α : Type u} [metric_space α] {s : set α} {x : α} {y : α} (h : bounded s) (hx : x ∈ s) (hy : y ∈ s) : dist x y ≤ diam s := dist_le_diam_of_mem' (bounded.ediam_ne_top h) hx hy /-- An unbounded set has zero diameter. If you would prefer to get the value ∞, use `emetric.diam`. This lemma makes it possible to avoid side conditions in some situations -/ theorem diam_eq_zero_of_unbounded {α : Type u} [metric_space α] {s : set α} (h : ¬bounded s) : diam s = 0 := sorry /-- If `s ⊆ t`, then the diameter of `s` is bounded by that of `t`, provided `t` is bounded. -/ theorem diam_mono {α : Type u} [metric_space α] {s : set α} {t : set α} (h : s ⊆ t) (ht : bounded t) : diam s ≤ diam t := sorry /-- The diameter of a union is controlled by the sum of the diameters, and the distance between any two points in each of the sets. This lemma is true without any side condition, since it is obviously true if `s ∪ t` is unbounded. -/ theorem diam_union {α : Type u} [metric_space α] {s : set α} {x : α} {y : α} {t : set α} (xs : x ∈ s) (yt : y ∈ t) : diam (s ∪ t) ≤ diam s + dist x y + diam t := sorry /-- If two sets intersect, the diameter of the union is bounded by the sum of the diameters. -/ theorem diam_union' {α : Type u} [metric_space α] {s : set α} {t : set α} (h : set.nonempty (s ∩ t)) : diam (s ∪ t) ≤ diam s + diam t := sorry /-- The diameter of a closed ball of radius `r` is at most `2 r`. -/ theorem diam_closed_ball {α : Type u} [metric_space α] {x : α} {r : ℝ} (h : 0 ≤ r) : diam (closed_ball x r) ≤ bit0 1 * r := sorry /-- The diameter of a ball of radius `r` is at most `2 r`. -/ theorem diam_ball {α : Type u} [metric_space α] {x : α} {r : ℝ} (h : 0 ≤ r) : diam (ball x r) ≤ bit0 1 * r := le_trans (diam_mono ball_subset_closed_ball bounded_closed_ball) (diam_closed_ball h)
using EquationEditor const EE = EquationEditor const logger = EE.WebSocketLogger(stderr, Base.CoreLogging.Debug, right_justify = 10) const server, task = serveEE(logger) EE.open_browser("chrome", url = "localhost:8000/interact.html")
lemma fst_quot_of_fract_eq_0_iff [simp]: "fst (quot_of_fract x) = 0 \<longleftrightarrow> x = 0"
/* * Copyright (c) 2016-2021 lymastee, All rights reserved. * Contact: [email protected] * * This file is part of the gslib project. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ #pragma once #ifndef error_e0b666c0_4caa_4710_bb62_0f8a9d0e579e_h #define error_e0b666c0_4caa_4710_bb62_0f8a9d0e579e_h #include <gslib/type.h> __gslib_begin__ struct errinfo { gchar* desc; gchar* file; int line; void* user; }; typedef void* (*error_dump)(void*); gs_export extern void* error_dump_callstack(void*); gs_export extern void _set_error(const gchar* desc, error_dump dump, void* user, const gchar* file, int line); gs_export extern void _set_last_error(const gchar* desc, error_dump dump, void* user, const gchar* file, int line); gs_export extern void pop_error(); gs_export extern errinfo* get_last_error(); gs_export extern void reset_error(); #ifndef swsc_char #define swsc_char(x) _t(x) #endif #ifdef set_error #undef set_error #endif #define set_error(desc, ...) do { \ assert(!desc); \ string str; \ str.format(desc, __VA_ARGS__); \ _set_error(str.c_str(), 0, 0, swsc_char(__FILE__), __LINE__); \ } while(0) #ifdef set_last_error #undef set_last_error #endif #define set_last_error(desc, ...) do { \ assert(!desc); \ string str; \ str.format(desc, _VA_ARGS__); \ _set_last_error(str.c_str(), 0, 0, swsc_char(__FILE__), __LINE__); \ } while(0) //gs_export extern void dumperr_file(void); gs_export extern void trace_hold(const gchar* fmt, ...); gs_export extern void _trace_to_clipboard(); #ifdef _GS_TRACE_TO_CLIPBOARD #define trace(fmt, ...) do { trace_hold(fmt, __VA_ARGS__); } while(0) #define trace_to_clipboard _trace_to_clipboard #elif defined (DEBUG) || defined (_DEBUG) gs_export extern void trace(const gchar* fmt, ...); gs_export extern void trace_all(const gchar* str); #define trace_to_clipboard __noop #else #define trace(fmt, ...) __noop #define trace_all __noop; #define trace_to_clipboard __noop #endif /* beep an alarm */ gs_export extern void sound_alarm(); __gslib_end__ #endif
Formal statement is: lemma prime_natI: "prime p" if "p \<ge> 2" and "\<And>m n. p dvd m * n \<Longrightarrow> p dvd m \<or> p dvd n" for p :: nat Informal statement is: If $p$ is a natural number greater than or equal to 2, and if $p$ divides the product of any two natural numbers, then $p$ divides one of the two numbers, then $p$ is a prime number.
section variable A : Type variable f : A → A variable P : A → Prop variable h : ∀ x, P x → P (f x) -- Show the following: example : ∀ y, P y → P (f(f(y))):= assume y : A, assume py : P y, have hpf : P y → P (f (y)), from h y, have hpff : P (f(y)) → P (f (f(y))), from h (f(y)), hpff (hpf (py)) end section variable U : Type variables A B : U → Prop example : (∀ x, A x ∧ B x) → ∀ x, A x := assume h : (∀ x, A x ∧ B x), assume y, show A y, from and.left (h y) end section variable U : Type variables A B C : U → Prop variable h1 : ∀ x, A x ∨ B x variable h2 : ∀ x, A x → C x variable h3 : ∀ x, B x → C x example : ∀ x, C x := assume y, or.elim (h1 y) (assume ha : A y , (h2 y) ha) (assume hb : B y, (h3 y) hb) end section variable U : Type variables A B : U → Prop example : (∃ x, A x) → ∃ x, A x ∨ B x := assume h, exists.elim h (assume y (h1 : A y), show ∃ x, A x ∨ B x, from exists.intro y (or.inl h1)) end section variable U : Type variables A B C : U → Prop example : (¬ ∃ x, A x) → ∀ x, ¬ A x := sorry example : (∀ x, ¬ A x) → ¬ ∃ x, A x := sorry end
theory deMorgan3 imports Main begin text\<open> Apply style \<close> theorem de_morgan_2 : "((\<not> p \<or> \<not> q) \<longrightarrow> (\<not> (p \<and> q)))" apply (rule impI) apply (rule notI) apply (erule disjE) apply (erule conjE) apply (erule notE) apply assumption apply (erule conjE) apply (erule notE) apply assumption done end
[GOAL] r : ℝ hr : 0 ≤ r ⊢ Real.toNNReal r = { val := r, property := hr } [PROOFSTEP] simp_rw [Real.toNNReal, max_eq_left hr] [GOAL] ⊢ Zero ℝ≥0 [PROOFSTEP] infer_instance [GOAL] ⊢ One ℝ≥0 [PROOFSTEP] infer_instance [GOAL] ⊢ Add ℝ≥0 [PROOFSTEP] infer_instance [GOAL] ⊢ Sub ℝ≥0 [PROOFSTEP] infer_instance [GOAL] ⊢ Mul ℝ≥0 [PROOFSTEP] infer_instance [GOAL] ⊢ Inv ℝ≥0 [PROOFSTEP] infer_instance [GOAL] ⊢ Div ℝ≥0 [PROOFSTEP] infer_instance [GOAL] ⊢ LE ℝ≥0 [PROOFSTEP] infer_instance [GOAL] ⊢ Bot ℝ≥0 [PROOFSTEP] infer_instance [GOAL] ⊢ Inhabited ℝ≥0 [PROOFSTEP] infer_instance [GOAL] ⊢ Nontrivial ℝ≥0 [PROOFSTEP] infer_instance [GOAL] r₁ r₂ : ℝ≥0 h : r₂ ≤ r₁ ⊢ ↑r₂ ≤ ↑r₁ - 0 [PROOFSTEP] simp [show (r₂ : ℝ) ≤ r₁ from h] [GOAL] r : ℝ≥0 ⊢ ↑r = 0 ↔ r = 0 [PROOFSTEP] rw [← NNReal.coe_zero, NNReal.coe_eq] [GOAL] r : ℝ≥0 ⊢ ↑r = 1 ↔ r = 1 [PROOFSTEP] rw [← NNReal.coe_one, NNReal.coe_eq] [GOAL] ⊢ CommSemiring ℝ≥0 [PROOFSTEP] infer_instance [GOAL] A : Type u_1 inst✝¹ : Semiring A inst✝ : Algebra ℝ A r : ℝ≥0 x : (fun x => A) r ⊢ ↑(RingHom.comp (algebraMap ℝ A) toRealHom) r * x = x * ↑(RingHom.comp (algebraMap ℝ A) toRealHom) r [PROOFSTEP] simp [Algebra.commutes] [GOAL] A : Type u_1 inst✝¹ : Semiring A inst✝ : Algebra ℝ A r : ℝ≥0 x : (fun x => A) r ⊢ r • x = ↑(RingHom.comp (algebraMap ℝ A) toRealHom) r * x [PROOFSTEP] simp [← Algebra.smul_def (r : ℝ) x, smul_def] [GOAL] ⊢ Algebra ℝ≥0 ℝ [PROOFSTEP] infer_instance [GOAL] ⊢ DistribMulAction ℝ≥0ˣ ℝ [PROOFSTEP] infer_instance [GOAL] ⊢ MonoidWithZero ℝ≥0 [PROOFSTEP] infer_instance [GOAL] ⊢ CommMonoidWithZero ℝ≥0 [PROOFSTEP] infer_instance [GOAL] ⊢ CommGroupWithZero ℝ≥0 [PROOFSTEP] infer_instance [GOAL] α : Type u_1 s : Finset α f : α → ℝ hf : ∀ (a : α), a ∈ s → 0 ≤ f a ⊢ Real.toNNReal (∑ a in s, f a) = ∑ a in s, Real.toNNReal (f a) [PROOFSTEP] rw [← NNReal.coe_eq, NNReal.coe_sum, Real.coe_toNNReal _ (Finset.sum_nonneg hf)] [GOAL] α : Type u_1 s : Finset α f : α → ℝ hf : ∀ (a : α), a ∈ s → 0 ≤ f a ⊢ ∑ i in s, f i = ∑ a in s, ↑(Real.toNNReal (f a)) [PROOFSTEP] exact Finset.sum_congr rfl fun x hxs => by rw [Real.coe_toNNReal _ (hf x hxs)] [GOAL] α : Type u_1 s : Finset α f : α → ℝ hf : ∀ (a : α), a ∈ s → 0 ≤ f a x : α hxs : x ∈ s ⊢ f x = ↑(Real.toNNReal (f x)) [PROOFSTEP] rw [Real.coe_toNNReal _ (hf x hxs)] [GOAL] α : Type u_1 s : Finset α f : α → ℝ hf : ∀ (a : α), a ∈ s → 0 ≤ f a ⊢ Real.toNNReal (∏ a in s, f a) = ∏ a in s, Real.toNNReal (f a) [PROOFSTEP] rw [← NNReal.coe_eq, NNReal.coe_prod, Real.coe_toNNReal _ (Finset.prod_nonneg hf)] [GOAL] α : Type u_1 s : Finset α f : α → ℝ hf : ∀ (a : α), a ∈ s → 0 ≤ f a ⊢ ∏ i in s, f i = ∏ a in s, ↑(Real.toNNReal (f a)) [PROOFSTEP] exact Finset.prod_congr rfl fun x hxs => by rw [Real.coe_toNNReal _ (hf x hxs)] [GOAL] α : Type u_1 s : Finset α f : α → ℝ hf : ∀ (a : α), a ∈ s → 0 ≤ f a x : α hxs : x ∈ s ⊢ f x = ↑(Real.toNNReal (f x)) [PROOFSTEP] rw [Real.coe_toNNReal _ (hf x hxs)] [GOAL] ⊢ LinearOrder ℝ≥0 [PROOFSTEP] infer_instance [GOAL] n : ℕ ⊢ ↑(Real.toNNReal ↑n) = ↑↑n [PROOFSTEP] simp [Real.coe_toNNReal] [GOAL] ⊢ OrderBot ℝ≥0 [PROOFSTEP] infer_instance [GOAL] ⊢ PartialOrder ℝ≥0 [PROOFSTEP] infer_instance [GOAL] ⊢ CanonicallyLinearOrderedAddMonoid ℝ≥0 [PROOFSTEP] infer_instance [GOAL] ⊢ LinearOrderedAddCommMonoid ℝ≥0 [PROOFSTEP] infer_instance [GOAL] ⊢ DistribLattice ℝ≥0 [PROOFSTEP] infer_instance [GOAL] ⊢ SemilatticeInf ℝ≥0 [PROOFSTEP] infer_instance [GOAL] ⊢ SemilatticeSup ℝ≥0 [PROOFSTEP] infer_instance [GOAL] ⊢ LinearOrderedSemiring ℝ≥0 [PROOFSTEP] infer_instance [GOAL] ⊢ OrderedCommSemiring ℝ≥0 [PROOFSTEP] infer_instance [GOAL] ⊢ LinearOrderedCommMonoid ℝ≥0 [PROOFSTEP] infer_instance [GOAL] ⊢ LinearOrderedCommMonoidWithZero ℝ≥0 [PROOFSTEP] infer_instance [GOAL] ⊢ LinearOrderedCommGroupWithZero ℝ≥0 [PROOFSTEP] infer_instance [GOAL] ⊢ CanonicallyOrderedCommSemiring ℝ≥0 [PROOFSTEP] infer_instance [GOAL] ⊢ DenselyOrdered ℝ≥0 [PROOFSTEP] infer_instance [GOAL] ⊢ NoMaxOrder ℝ≥0 [PROOFSTEP] infer_instance [GOAL] ι : Sort u_1 s : ι → ℝ≥0 ⊢ ↑(⨆ (i : ι), s i) = ⨆ (i : ι), ↑(s i) [PROOFSTEP] rw [iSup, iSup, coe_sSup, ← Set.range_comp] [GOAL] ι : Sort u_1 s : ι → ℝ≥0 ⊢ sSup (Set.range (toReal ∘ fun i => s i)) = sSup (Set.range fun i => ↑(s i)) [PROOFSTEP] rfl [GOAL] ⊢ sInf ∅ = 0 [PROOFSTEP] rw [← NNReal.coe_eq_zero, coe_sInf, Set.image_empty, Real.sInf_empty] [GOAL] ι : Sort u_1 s : ι → ℝ≥0 ⊢ ↑(⨅ (i : ι), s i) = ⨅ (i : ι), ↑(s i) [PROOFSTEP] rw [iInf, iInf, coe_sInf, ← Set.range_comp] [GOAL] ι : Sort u_1 s : ι → ℝ≥0 ⊢ sInf (Set.range (toReal ∘ fun i => s i)) = sInf (Set.range fun i => ↑(s i)) [PROOFSTEP] rfl [GOAL] ι : Sort u_1 ι' : Sort u_2 inst✝¹ : Nonempty ι inst✝ : Nonempty ι' f : ι → ℝ≥0 g : ι' → ℝ≥0 a : ℝ≥0 h : ∀ (i : ι) (j : ι'), a ≤ f i + g j ⊢ a ≤ (⨅ (i : ι), f i) + ⨅ (j : ι'), g j [PROOFSTEP] rw [← NNReal.coe_le_coe, NNReal.coe_add, coe_iInf, coe_iInf] [GOAL] ι : Sort u_1 ι' : Sort u_2 inst✝¹ : Nonempty ι inst✝ : Nonempty ι' f : ι → ℝ≥0 g : ι' → ℝ≥0 a : ℝ≥0 h : ∀ (i : ι) (j : ι'), a ≤ f i + g j ⊢ ↑a ≤ (⨅ (i : ι), ↑(f i)) + ⨅ (i : ι'), ↑(g i) [PROOFSTEP] exact le_ciInf_add_ciInf h [GOAL] ⊢ Archimedean ℝ≥0 [PROOFSTEP] infer_instance -- porting note: TODO: remove? [GOAL] a b : ℝ≥0 h : ↑a < ↑b q : ℚ haq : ↑a < ↑q hqb : ↑q < ↑b this : 0 ≤ ↑q ⊢ a < Real.toNNReal ↑q ∧ Real.toNNReal ↑q < b [PROOFSTEP] simp [Real.coe_toNNReal _ this, NNReal.coe_lt_coe.symm, haq, hqb] [GOAL] α : Type u_1 f : α → ℝ≥0 s : Finset α r : ℝ≥0 ⊢ Finset.sup s f / r = Finset.sup s fun a => f a / r [PROOFSTEP] simp only [div_eq_inv_mul, mul_finset_sup] [GOAL] r : ℝ ⊢ 0 < toNNReal r ↔ 0 < r [PROOFSTEP] simp [← NNReal.coe_lt_coe, lt_irrefl] [GOAL] r : ℝ ⊢ toNNReal r = 0 ↔ r ≤ 0 [PROOFSTEP] simpa [-toNNReal_pos] using not_iff_not.2 (@toNNReal_pos r) [GOAL] r p : ℝ hp : 0 ≤ p ⊢ toNNReal r ≤ toNNReal p ↔ r ≤ p [PROOFSTEP] simp [← NNReal.coe_le_coe, hp] [GOAL] r p : ℝ hr : 0 ≤ r hp : 0 ≤ p ⊢ toNNReal r = toNNReal p ↔ r = p [PROOFSTEP] simp [← NNReal.coe_eq, coe_toNNReal, hr, hp] [GOAL] r p : ℝ hr : 0 ≤ r hp : 0 ≤ p ⊢ ↑(toNNReal (r + p)) = ↑(toNNReal r + toNNReal p) [PROOFSTEP] simp [hr, hp, add_nonneg] [GOAL] r : ℝ≥0 p : ℝ hp : 0 ≤ p ⊢ r ≤ toNNReal p ↔ ↑r ≤ p [PROOFSTEP] rw [← NNReal.coe_le_coe, Real.coe_toNNReal p hp] [GOAL] r : ℝ≥0 p : ℝ hr : 0 < r hp : p < 0 ⊢ r ≤ toNNReal p ↔ ↑r ≤ p [PROOFSTEP] simp only [(hp.trans_le r.coe_nonneg).not_le, toNNReal_eq_zero.2 hp.le, hr.not_le] [GOAL] r : ℝ p : ℝ≥0 ha : 0 ≤ r ⊢ toNNReal r < p ↔ r < ↑p [PROOFSTEP] rw [← NNReal.coe_lt_coe, Real.coe_toNNReal r ha] [GOAL] x : ℝ hx : 0 ≤ x n : ℕ ⊢ toNNReal (x ^ n) = toNNReal x ^ n [PROOFSTEP] rw [← NNReal.coe_eq, NNReal.coe_pow, Real.coe_toNNReal _ (pow_nonneg hx _), Real.coe_toNNReal x hx] [GOAL] p q : ℝ hp : 0 ≤ p ⊢ ↑(toNNReal (p * q)) = ↑(toNNReal p * toNNReal q) [PROOFSTEP] simp [mul_max_of_nonneg, hp] [GOAL] a b c : ℝ≥0 h : a ≠ 0 ⊢ a * b = a * c ↔ b = c [PROOFSTEP] rw [mul_eq_mul_left_iff, or_iff_left h] [GOAL] a b : ℝ≥0 ha : 0 < a hb : b < 1 ⊢ ∃ n, b ^ n < a [PROOFSTEP] simpa only [← coe_pow, NNReal.coe_lt_coe] using exists_pow_lt_of_lt_one (NNReal.coe_pos.2 ha) (NNReal.coe_lt_coe.2 hb) [GOAL] ⊢ OrderedSub ℝ≥0 [PROOFSTEP] infer_instance [GOAL] r p : ℝ≥0 h : r ≠ 0 ⊢ r⁻¹ ≤ p ↔ 1 ≤ r * p [PROOFSTEP] rw [← mul_le_mul_left (pos_iff_ne_zero.2 h), mul_inv_cancel h] [GOAL] r p : ℝ≥0 h : 1 ≤ r * p ⊢ r⁻¹ ≤ p [PROOFSTEP] by_cases r = 0 [GOAL] r p : ℝ≥0 h : 1 ≤ r * p ⊢ r⁻¹ ≤ p [PROOFSTEP] by_cases r = 0 [GOAL] case pos r p : ℝ≥0 h✝ : 1 ≤ r * p h : r = 0 ⊢ r⁻¹ ≤ p [PROOFSTEP] simp [*, inv_le] [GOAL] case neg r p : ℝ≥0 h✝ : 1 ≤ r * p h : ¬r = 0 ⊢ r⁻¹ ≤ p [PROOFSTEP] simp [*, inv_le] [GOAL] r p : ℝ≥0 h : p ≠ 0 ⊢ r ≤ p⁻¹ ↔ r * p ≤ 1 [PROOFSTEP] rw [← mul_le_mul_left (pos_iff_ne_zero.2 h), mul_inv_cancel h, mul_comm] [GOAL] r p : ℝ≥0 h : p ≠ 0 ⊢ r < p⁻¹ ↔ r * p < 1 [PROOFSTEP] rw [← mul_lt_mul_left (pos_iff_ne_zero.2 h), mul_inv_cancel h, mul_comm] [GOAL] a b r : ℝ≥0 hr : r ≠ 0 ⊢ r * a ≤ b ↔ a ≤ r⁻¹ * b [PROOFSTEP] have : 0 < r := lt_of_le_of_ne (zero_le r) hr.symm [GOAL] a b r : ℝ≥0 hr : r ≠ 0 this : 0 < r ⊢ r * a ≤ b ↔ a ≤ r⁻¹ * b [PROOFSTEP] rw [← mul_le_mul_left (inv_pos.mpr this), ← mul_assoc, inv_mul_cancel hr, one_mul] [GOAL] a b c : ℝ≥0 h : a ≤ b * c h0 : c = 0 ⊢ a / c ≤ b [PROOFSTEP] simp [h0] [GOAL] a b r : ℝ≥0 h : a < b / r hr : r = 0 ⊢ False [PROOFSTEP] simp [hr] at h [GOAL] x y : ℝ≥0 h : ∀ (a : ℝ≥0), a < 1 → a * x ≤ y a : ℝ≥0 ha : a < x ⊢ a ≤ y [PROOFSTEP] have hx : x ≠ 0 := pos_iff_ne_zero.1 (lt_of_le_of_lt (zero_le _) ha) [GOAL] x y : ℝ≥0 h : ∀ (a : ℝ≥0), a < 1 → a * x ≤ y a : ℝ≥0 ha : a < x hx : x ≠ 0 ⊢ a ≤ y [PROOFSTEP] have hx' : x⁻¹ ≠ 0 := by rwa [Ne.def, inv_eq_zero] [GOAL] x y : ℝ≥0 h : ∀ (a : ℝ≥0), a < 1 → a * x ≤ y a : ℝ≥0 ha : a < x hx : x ≠ 0 ⊢ x⁻¹ ≠ 0 [PROOFSTEP] rwa [Ne.def, inv_eq_zero] [GOAL] x y : ℝ≥0 h : ∀ (a : ℝ≥0), a < 1 → a * x ≤ y a : ℝ≥0 ha : a < x hx : x ≠ 0 hx' : x⁻¹ ≠ 0 ⊢ a ≤ y [PROOFSTEP] have : a * x⁻¹ < 1 := by rwa [← lt_inv_iff_mul_lt hx', inv_inv] [GOAL] x y : ℝ≥0 h : ∀ (a : ℝ≥0), a < 1 → a * x ≤ y a : ℝ≥0 ha : a < x hx : x ≠ 0 hx' : x⁻¹ ≠ 0 ⊢ a * x⁻¹ < 1 [PROOFSTEP] rwa [← lt_inv_iff_mul_lt hx', inv_inv] [GOAL] x y : ℝ≥0 h : ∀ (a : ℝ≥0), a < 1 → a * x ≤ y a : ℝ≥0 ha : a < x hx : x ≠ 0 hx' : x⁻¹ ≠ 0 this : a * x⁻¹ < 1 ⊢ a ≤ y [PROOFSTEP] have : a * x⁻¹ * x ≤ y := h _ this [GOAL] x y : ℝ≥0 h : ∀ (a : ℝ≥0), a < 1 → a * x ≤ y a : ℝ≥0 ha : a < x hx : x ≠ 0 hx' : x⁻¹ ≠ 0 this✝ : a * x⁻¹ < 1 this : a * x⁻¹ * x ≤ y ⊢ a ≤ y [PROOFSTEP] rwa [mul_assoc, inv_mul_cancel hx, mul_one] at this [GOAL] a b : ℝ≥0 h : a < b ⊢ a / b < 1 [PROOFSTEP] rwa [div_lt_iff, one_mul] [GOAL] a b : ℝ≥0 h : a < b ⊢ b ≠ 0 [PROOFSTEP] exact ne_of_gt (lt_of_le_of_lt (zero_le _) h) [GOAL] x : ℝ ⊢ toNNReal x⁻¹ = (toNNReal x)⁻¹ [PROOFSTEP] cases' le_total 0 x with hx hx [GOAL] case inl x : ℝ hx : 0 ≤ x ⊢ toNNReal x⁻¹ = (toNNReal x)⁻¹ [PROOFSTEP] nth_rw 1 [← Real.coe_toNNReal x hx] [GOAL] case inl x : ℝ hx : 0 ≤ x ⊢ toNNReal (↑(toNNReal x))⁻¹ = (toNNReal x)⁻¹ [PROOFSTEP] rw [← NNReal.coe_inv, Real.toNNReal_coe] [GOAL] case inr x : ℝ hx : x ≤ 0 ⊢ toNNReal x⁻¹ = (toNNReal x)⁻¹ [PROOFSTEP] rw [toNNReal_eq_zero.mpr hx, inv_zero, toNNReal_eq_zero.mpr (inv_nonpos.mpr hx)] [GOAL] x y : ℝ hx : 0 ≤ x ⊢ toNNReal (x / y) = toNNReal x / toNNReal y [PROOFSTEP] rw [div_eq_mul_inv, div_eq_mul_inv, ← Real.toNNReal_inv, ← Real.toNNReal_mul hx] [GOAL] x y : ℝ hy : 0 ≤ y ⊢ toNNReal (x / y) = toNNReal x / toNNReal y [PROOFSTEP] rw [div_eq_inv_mul, div_eq_inv_mul, Real.toNNReal_mul (inv_nonneg.2 hy), Real.toNNReal_inv] [GOAL] x : ℝ≥0 hx : x ≠ 0 ⊢ x⁻¹ < 1 ↔ 1 < x [PROOFSTEP] rw [← one_div, div_lt_iff hx, one_mul] [GOAL] ι : Sort u_1 f : ι → ℝ≥0 s : Set ℝ≥0 hs : ¬BddAbove s ⊢ sSup s = 0 [PROOFSTEP] rw [← bddAbove_coe] at hs [GOAL] ι : Sort u_1 f : ι → ℝ≥0 s : Set ℝ≥0 hs : ¬BddAbove (toReal '' s) ⊢ sSup s = 0 [PROOFSTEP] rw [← NNReal.coe_eq, coe_sSup, NNReal.coe_zero] [GOAL] ι : Sort u_1 f : ι → ℝ≥0 s : Set ℝ≥0 hs : ¬BddAbove (toReal '' s) ⊢ sSup (toReal '' s) = 0 [PROOFSTEP] exact sSup_of_not_bddAbove hs [GOAL] ι : Sort u_1 f✝ : ι → ℝ≥0 inst✝ : IsEmpty ι f : ι → ℝ≥0 ⊢ ⨅ (i : ι), f i = 0 [PROOFSTEP] rw [iInf_of_empty', sInf_empty] [GOAL] ι : Sort u_1 f : ι → ℝ≥0 α : Sort u_2 ⊢ ⨅ (x : α), 0 = 0 [PROOFSTEP] rw [← NNReal.coe_eq, coe_iInf] [GOAL] ι : Sort u_1 f : ι → ℝ≥0 α : Sort u_2 ⊢ ⨅ (i : α), ↑0 = ↑0 [PROOFSTEP] exact Real.ciInf_const_zero [GOAL] ι : Sort u_1 f✝ f : ι → ℝ≥0 a : ℝ≥0 ⊢ iInf f * a = ⨅ (i : ι), f i * a [PROOFSTEP] rw [← NNReal.coe_eq, NNReal.coe_mul, coe_iInf, coe_iInf] [GOAL] ι : Sort u_1 f✝ f : ι → ℝ≥0 a : ℝ≥0 ⊢ (⨅ (i : ι), ↑(f i)) * ↑a = ⨅ (i : ι), ↑(f i * a) [PROOFSTEP] exact Real.iInf_mul_of_nonneg (NNReal.coe_nonneg _) _ [GOAL] ι : Sort u_1 f✝ f : ι → ℝ≥0 a : ℝ≥0 ⊢ a * iInf f = ⨅ (i : ι), a * f i [PROOFSTEP] simpa only [mul_comm] using iInf_mul f a [GOAL] ι : Sort u_1 f✝ f : ι → ℝ≥0 a : ℝ≥0 ⊢ a * ⨆ (i : ι), f i = ⨆ (i : ι), a * f i [PROOFSTEP] rw [← NNReal.coe_eq, NNReal.coe_mul, NNReal.coe_iSup, NNReal.coe_iSup] [GOAL] ι : Sort u_1 f✝ f : ι → ℝ≥0 a : ℝ≥0 ⊢ ↑a * ⨆ (i : ι), ↑(f i) = ⨆ (i : ι), ↑(a * f i) [PROOFSTEP] exact Real.mul_iSup_of_nonneg (NNReal.coe_nonneg _) _ [GOAL] ι : Sort u_1 f✝ f : ι → ℝ≥0 a : ℝ≥0 ⊢ (⨆ (i : ι), f i) * a = ⨆ (i : ι), f i * a [PROOFSTEP] rw [mul_comm, mul_iSup] [GOAL] ι : Sort u_1 f✝ f : ι → ℝ≥0 a : ℝ≥0 ⊢ ⨆ (i : ι), a * f i = ⨆ (i : ι), f i * a [PROOFSTEP] simp_rw [mul_comm] [GOAL] ι : Sort u_1 f✝ f : ι → ℝ≥0 a : ℝ≥0 ⊢ (⨆ (i : ι), f i) / a = ⨆ (i : ι), f i / a [PROOFSTEP] simp only [div_eq_mul_inv, iSup_mul] [GOAL] ι : Sort u_1 f : ι → ℝ≥0 a g : ℝ≥0 h : ι → ℝ≥0 H : ∀ (j : ι), g * h j ≤ a ⊢ g * iSup h ≤ a [PROOFSTEP] rw [mul_iSup] [GOAL] ι : Sort u_1 f : ι → ℝ≥0 a g : ℝ≥0 h : ι → ℝ≥0 H : ∀ (j : ι), g * h j ≤ a ⊢ ⨆ (i : ι), g * h i ≤ a [PROOFSTEP] exact ciSup_le' H [GOAL] ι : Sort u_1 f : ι → ℝ≥0 a : ℝ≥0 g : ι → ℝ≥0 h : ℝ≥0 H : ∀ (i : ι), g i * h ≤ a ⊢ iSup g * h ≤ a [PROOFSTEP] rw [iSup_mul] [GOAL] ι : Sort u_1 f : ι → ℝ≥0 a : ℝ≥0 g : ι → ℝ≥0 h : ℝ≥0 H : ∀ (i : ι), g i * h ≤ a ⊢ ⨆ (i : ι), g i * h ≤ a [PROOFSTEP] exact ciSup_le' H [GOAL] ι : Sort u_1 f : ι → ℝ≥0 inst✝ : Nonempty ι a g : ℝ≥0 h : ι → ℝ≥0 H : ∀ (j : ι), a ≤ g * h j ⊢ a ≤ g * iInf h [PROOFSTEP] rw [mul_iInf] [GOAL] ι : Sort u_1 f : ι → ℝ≥0 inst✝ : Nonempty ι a g : ℝ≥0 h : ι → ℝ≥0 H : ∀ (j : ι), a ≤ g * h j ⊢ a ≤ ⨅ (i : ι), g * h i [PROOFSTEP] exact le_ciInf H [GOAL] ι : Sort u_1 f : ι → ℝ≥0 inst✝ : Nonempty ι a : ℝ≥0 g : ι → ℝ≥0 h : ℝ≥0 H : ∀ (i : ι), a ≤ g i * h ⊢ a ≤ iInf g * h [PROOFSTEP] rw [iInf_mul] [GOAL] ι : Sort u_1 f : ι → ℝ≥0 inst✝ : Nonempty ι a : ℝ≥0 g : ι → ℝ≥0 h : ℝ≥0 H : ∀ (i : ι), a ≤ g i * h ⊢ a ≤ ⨅ (i : ι), g i * h [PROOFSTEP] exact le_ciInf H [GOAL] s : Set ℝ t : Set ℝ≥0 h : OrdConnected s ⊢ OrdConnected (toNNReal '' s) [PROOFSTEP] refine' ⟨ball_image_iff.2 fun x hx => ball_image_iff.2 fun y hy z hz => _⟩ [GOAL] s : Set ℝ t : Set ℝ≥0 h : OrdConnected s x : ℝ hx : x ∈ s y : ℝ hy : y ∈ s z : ℝ≥0 hz : z ∈ Icc (toNNReal x) (toNNReal y) ⊢ z ∈ toNNReal '' s [PROOFSTEP] cases' le_total y 0 with hy₀ hy₀ [GOAL] case inl s : Set ℝ t : Set ℝ≥0 h : OrdConnected s x : ℝ hx : x ∈ s y : ℝ hy : y ∈ s z : ℝ≥0 hz : z ∈ Icc (toNNReal x) (toNNReal y) hy₀ : y ≤ 0 ⊢ z ∈ toNNReal '' s [PROOFSTEP] rw [mem_Icc, Real.toNNReal_of_nonpos hy₀, nonpos_iff_eq_zero] at hz [GOAL] case inl s : Set ℝ t : Set ℝ≥0 h : OrdConnected s x : ℝ hx : x ∈ s y : ℝ hy : y ∈ s z : ℝ≥0 hz : toNNReal x ≤ z ∧ z = 0 hy₀ : y ≤ 0 ⊢ z ∈ toNNReal '' s [PROOFSTEP] exact ⟨y, hy, (toNNReal_of_nonpos hy₀).trans hz.2.symm⟩ [GOAL] case inr s : Set ℝ t : Set ℝ≥0 h : OrdConnected s x : ℝ hx : x ∈ s y : ℝ hy : y ∈ s z : ℝ≥0 hz : z ∈ Icc (toNNReal x) (toNNReal y) hy₀ : 0 ≤ y ⊢ z ∈ toNNReal '' s [PROOFSTEP] lift y to ℝ≥0 using hy₀ [GOAL] case inr.intro s : Set ℝ t : Set ℝ≥0 h : OrdConnected s x : ℝ hx : x ∈ s z y : ℝ≥0 hy : ↑y ∈ s hz : z ∈ Icc (toNNReal x) (toNNReal ↑y) ⊢ z ∈ toNNReal '' s [PROOFSTEP] rw [toNNReal_coe] at hz [GOAL] case inr.intro s : Set ℝ t : Set ℝ≥0 h : OrdConnected s x : ℝ hx : x ∈ s z y : ℝ≥0 hy : ↑y ∈ s hz : z ∈ Icc (toNNReal x) y ⊢ z ∈ toNNReal '' s [PROOFSTEP] exact ⟨z, h.out hx hy ⟨toNNReal_le_iff_le_coe.1 hz.1, hz.2⟩, toNNReal_coe⟩ [GOAL] ⊢ (fun x => { val := |x|, property := (_ : 0 ≤ |x|) }) 0 = 0 [PROOFSTEP] ext [GOAL] case a ⊢ ↑((fun x => { val := |x|, property := (_ : 0 ≤ |x|) }) 0) = ↑0 [PROOFSTEP] simp [GOAL] ⊢ ZeroHom.toFun { toFun := fun x => { val := |x|, property := (_ : 0 ≤ |x|) }, map_zero' := (_ : (fun x => { val := |x|, property := (_ : 0 ≤ |x|) }) 0 = 0) } 1 = 1 [PROOFSTEP] ext [GOAL] case a ⊢ ↑(ZeroHom.toFun { toFun := fun x => { val := |x|, property := (_ : 0 ≤ |x|) }, map_zero' := (_ : (fun x => { val := |x|, property := (_ : 0 ≤ |x|) }) 0 = 0) } 1) = ↑1 [PROOFSTEP] simp [GOAL] x y : ℝ ⊢ ZeroHom.toFun { toFun := fun x => { val := |x|, property := (_ : 0 ≤ |x|) }, map_zero' := (_ : (fun x => { val := |x|, property := (_ : 0 ≤ |x|) }) 0 = 0) } (x * y) = ZeroHom.toFun { toFun := fun x => { val := |x|, property := (_ : 0 ≤ |x|) }, map_zero' := (_ : (fun x => { val := |x|, property := (_ : 0 ≤ |x|) }) 0 = 0) } x * ZeroHom.toFun { toFun := fun x => { val := |x|, property := (_ : 0 ≤ |x|) }, map_zero' := (_ : (fun x => { val := |x|, property := (_ : 0 ≤ |x|) }) 0 = 0) } y [PROOFSTEP] ext [GOAL] case a x y : ℝ ⊢ ↑(ZeroHom.toFun { toFun := fun x => { val := |x|, property := (_ : 0 ≤ |x|) }, map_zero' := (_ : (fun x => { val := |x|, property := (_ : 0 ≤ |x|) }) 0 = 0) } (x * y)) = ↑(ZeroHom.toFun { toFun := fun x => { val := |x|, property := (_ : 0 ≤ |x|) }, map_zero' := (_ : (fun x => { val := |x|, property := (_ : 0 ≤ |x|) }) 0 = 0) } x * ZeroHom.toFun { toFun := fun x => { val := |x|, property := (_ : 0 ≤ |x|) }, map_zero' := (_ : (fun x => { val := |x|, property := (_ : 0 ≤ |x|) }) 0 = 0) } y) [PROOFSTEP] simp [abs_mul] [GOAL] x : ℝ h : 0 ≤ x ⊢ ↑nnabs x = toNNReal x [PROOFSTEP] ext [GOAL] case a x : ℝ h : 0 ≤ x ⊢ ↑(↑nnabs x) = ↑(toNNReal x) [PROOFSTEP] rw [coe_toNNReal x h, coe_nnabs, abs_of_nonneg h] [GOAL] x : ℝ≥0 ⊢ ↑nnabs ↑x = x [PROOFSTEP] simp [GOAL] n : ℤ ⊢ ↑(Int.natAbs n) = ↑nnabs ↑n [PROOFSTEP] ext [GOAL] case a n : ℤ ⊢ ↑↑(Int.natAbs n) = ↑(↑nnabs ↑n) [PROOFSTEP] rw [NNReal.coe_nat_cast, Int.cast_natAbs, Real.coe_nnabs, Int.cast_abs]
From Coqprime Require Import PocklingtonRefl. Local Open Scope positive_scope. Lemma primo76: prime 201471189889-> prime 39488365236169. Proof. intro H. apply (Pocklington_refl (Ell_certif 39488365236169 196 ((201471189889,1)::nil) 0 3584 8 64) ((Proof_certif _ H) :: nil)). native_cast_no_check (refl_equal true). Time Qed.
{-# OPTIONS --rewriting --confluence-check #-} open import Agda.Builtin.Equality open import Agda.Builtin.Equality.Rewrite postulate A : Set a b : A f : A → A rew₁ : f a ≡ b rew₂ : f ≡ λ _ → a {-# REWRITE rew₁ #-} {-# REWRITE rew₂ #-}
# Decision Lens API # # No description provided (generated by Swagger Codegen https://github.com/swagger-api/swagger-codegen) # # OpenAPI spec version: 1.0 # # Generated by: https://github.com/swagger-api/swagger-codegen.git #' RegisterUserRequest Class #' #' @field userRegistrationToken #' @field emailId #' @field landingPage #' @field doNotNotify #' #' @importFrom R6 R6Class #' @importFrom jsonlite fromJSON toJSON #' @export RegisterUserRequest <- R6::R6Class( 'RegisterUserRequest', public = list( `userRegistrationToken` = NULL, `emailId` = NULL, `landingPage` = NULL, `doNotNotify` = NULL, initialize = function(`userRegistrationToken`, `emailId`, `landingPage`, `doNotNotify`){ if (!missing(`userRegistrationToken`)) { stopifnot(is.character(`userRegistrationToken`), length(`userRegistrationToken`) == 1) self$`userRegistrationToken` <- `userRegistrationToken` } if (!missing(`emailId`)) { stopifnot(is.character(`emailId`), length(`emailId`) == 1) self$`emailId` <- `emailId` } if (!missing(`landingPage`)) { stopifnot(is.character(`landingPage`), length(`landingPage`) == 1) self$`landingPage` <- `landingPage` } if (!missing(`doNotNotify`)) { self$`doNotNotify` <- `doNotNotify` } }, toJSON = function() { RegisterUserRequestObject <- list() if (!is.null(self$`userRegistrationToken`)) { RegisterUserRequestObject[['userRegistrationToken']] <- self$`userRegistrationToken` } if (!is.null(self$`emailId`)) { RegisterUserRequestObject[['emailId']] <- self$`emailId` } if (!is.null(self$`landingPage`)) { RegisterUserRequestObject[['landingPage']] <- self$`landingPage` } if (!is.null(self$`doNotNotify`)) { RegisterUserRequestObject[['doNotNotify']] <- self$`doNotNotify` } RegisterUserRequestObject }, fromJSON = function(RegisterUserRequestJson) { RegisterUserRequestObject <- dlensFromJSON(RegisterUserRequestJson) if (!is.null(RegisterUserRequestObject$`userRegistrationToken`)) { self$`userRegistrationToken` <- RegisterUserRequestObject$`userRegistrationToken` } if (!is.null(RegisterUserRequestObject$`emailId`)) { self$`emailId` <- RegisterUserRequestObject$`emailId` } if (!is.null(RegisterUserRequestObject$`landingPage`)) { self$`landingPage` <- RegisterUserRequestObject$`landingPage` } if (!is.null(RegisterUserRequestObject$`doNotNotify`)) { self$`doNotNotify` <- RegisterUserRequestObject$`doNotNotify` } }, toJSONString = function() { sprintf( '{ "userRegistrationToken": %s, "emailId": %s, "landingPage": %s, "doNotNotify": %s }', self$`userRegistrationToken`, self$`emailId`, self$`landingPage`, self$`doNotNotify` ) }, fromJSONString = function(RegisterUserRequestJson) { RegisterUserRequestObject <- dlensFromJSON(RegisterUserRequestJson) self$`userRegistrationToken` <- RegisterUserRequestObject$`userRegistrationToken` self$`emailId` <- RegisterUserRequestObject$`emailId` self$`landingPage` <- RegisterUserRequestObject$`landingPage` self$`doNotNotify` <- RegisterUserRequestObject$`doNotNotify` } ) )
-- An implementation of Olivier Danvy's Type-Directed Partial Evaluation (POPL 1996) -- for STLC with sum types using continuations in form of shift and reset. -- -- The algorithm was originally for a two-level lambda-calculus. -- Our use of Kripke semantics makes the effect of fresh variable generation explicit and formal. open import Library module DanvyShiftReset where data Base : Set where α β : Base -- import Formulas ; open module Form = Formulas Base -- import Derivations; open module Der = Derivations Base open import Formulas Base open import Derivations Base -- -- Shift-reset continutation monad -- record M (A B C : Set) : Set where -- field run : (C → B) → A -- open M -- return : ∀{X A} → A → M X X A -- return x .run k = k x -- _>>=_ : ∀{X Y Z A B} (m : M X Y A) (f : A → M Y Z B) → M X Z B -- (m >>= f) .run k = m .run λ a → f a .run k -- _<$>_ : ∀{X Y A B} (f : A → B) (m : M X Y A) → M X Y B -- (f <$> m) .run k = m .run (k ∘ f) -- shift : ∀{X Y A} (f : (A → Y) → M X Y Y) → M X Y A -- shift f .run k = f k .run id -- shift' : ∀{X Y A} (f : (A → Y) → X) → M X Y A -- shift' f .run k = f k -- reset : ∀{X Y A} (m : M A Y Y) → M X X A -- reset m .run k = k (m .run id) -- Shift-reset continutation monad record M (A B C : Cxt → Set) (Γ : Cxt) : Set where field run : KFun (KFun C B) A Γ open M return : ∀{X A} → □ A →̇ M X X A return x .run τ k = k id≤ (x τ) return' : ∀{X A} → □ A →̇ M X X (□ A) return' x .run τ k = k id≤ λ τ₁ → x (τ₁ • τ) _>>=_ : ∀{X Y Z A B Γ} (m : M X Y A Γ) (f : KFun A (M Y Z B) Γ) → M X Z B Γ (m >>= f) .run σ k = m .run σ λ τ a → f (τ • σ) a .run id≤ λ τ′ → k (τ′ • τ) _<$>_ : ∀{X Y A B} (f : A →̇ B) → M X Y A →̇ M X Y B (f <$> m) .run σ k = m .run σ λ τ → k τ ∘ f -- liftA2 : ∀{X Y A B C} (f : ∀{Γ} → A Γ → B Γ → C Γ) → ∀{Γ} → M X Y A Γ → M X Y B Γ → M X Y C Γ -- liftA2 f ma mb .run σ k = ma .run σ λ τ a → {!mb .run!} K$ : ∀{X Y A B} → KFun A B →̇ KFun (M X Y A) (M X Y B) K$ f τ m .run σ k = m .run σ λ τ′ a → k τ′ (f (τ′ • (σ • τ)) a) shift' : ∀{X Y A Γ} (f : KFun (KFun A Y) X Γ) → M X Y A Γ shift' f .run σ k = f σ k shift : ∀{X Y A Γ} (f : KFun (KFun A Y) (M X Y Y) Γ) → M X Y A Γ shift f .run σ k = f σ k .run id≤ λ τ → id reset' : ∀{Y A} → M A Y Y →̇ A reset' m = m .run id≤ λ τ → id reset : ∀{X Y A} → M A Y Y →̇ M X X A reset m .run σ k = k id≤ (m .run σ λ τ → id) -- We use a continuation monad with answer type Nf. M' : (X : Cxt → Set) (Γ : Cxt) → Set M' X Γ = ∀ {C} → M (Nf' C) (Nf' C) X Γ T⟦_⟧ : (A : Form) (Γ : Cxt) → Set T⟦ Atom P ⟧ = Nf' (Atom P) T⟦ True ⟧ Γ = ⊤ T⟦ False ⟧ Γ = ⊥ T⟦ A ∨ B ⟧ Γ = T⟦ A ⟧ Γ ⊎ T⟦ B ⟧ Γ T⟦ A ∧ B ⟧ Γ = T⟦ A ⟧ Γ × T⟦ B ⟧ Γ T⟦ A ⇒ B ⟧ Γ = ∀{Δ} (τ : Δ ≤ Γ) → T⟦ A ⟧ Δ → M' T⟦ B ⟧ Δ -- Monotonicity of the model is proven by induction on the proposition. -- monT : ∀ A {Γ Δ} (τ : Δ ≤ Γ) → T⟦ A ⟧ Γ → T⟦ A ⟧ Δ monT : ∀ A → Mon T⟦ A ⟧ monT (Atom P) = monNf monT True = _ monT False τ () monT (A ∨ B) τ = map-⊎ (monT A τ) (monT B τ) monT (A ∧ B) τ (a , b) = monT A τ a , monT B τ b monT (A ⇒ B) τ f σ = f (σ • τ) -- Reflection / reification, proven simultaneously by induction on the proposition. -- Reflection is η-expansion (and recursively reflection); mutual reflect : ∀{Γ} A (t : Ne Γ A) → M' T⟦ A ⟧ Γ reflect (Atom P) t = return λ τ → ne (monNe τ t) reflect True t = return _ reflect False t = shift' λ τ k → falseE (monNe τ t) reflect (A ∨ B) t = shift' λ τ k → orE (monNe τ t) (reset' (K$ k (weak id≤) (inj₁ <$> reflect A (hyp top)))) (reset' (K$ k (weak id≤) (inj₂ <$> reflect B (hyp top)))) -- ((inj₂ <$> reflect B (hyp top)) .run λ τ → k (τ • weak id≤)) -- Wrong: -- (reset' (k (weak id≤) <$> (inj₁ <$> reflect A (hyp top)))) -- reflect (A ∧ B) t = do -- a ← reflect A (andE₁ t) -- b ← reflect B (andE₂ t) -- return (a , b) reflect (A ∧ B) t = reflect A (andE₁ t ) >>= λ τ a → reflect B (andE₂ (monNe τ t)) >>= λ τ′ b → return λ τ₁ → monT A (τ₁ • τ′) a , monT B τ₁ b reflect (A ⇒ B) t = return' λ τ a → reflect B (impE (monNe τ t) (reify A a)) reify : ∀{Γ} A (⟦f⟧ : T⟦ A ⟧ Γ) → Nf Γ A reify (Atom P) t = t reify True _ = trueI reify False () reify (A ∨ B) (inj₁ a) = orI₁ (reify A a) reify (A ∨ B) (inj₂ b) = orI₂ (reify B b) reify (A ∧ B) (a , b) = andI (reify A a) (reify B b) reify (A ⇒ B) f = impI $ reset' $ reflect A (hyp top) >>= λ τ a → reify B <$> f (τ • weak id≤) a -- Fundamental theorem -- Extension of T⟦_⟧ to contexts G⟦_⟧ : ∀ (Γ Δ : Cxt) → Set G⟦ ε ⟧ Δ = ⊤ G⟦ Γ ∙ A ⟧ Δ = G⟦ Γ ⟧ Δ × T⟦ A ⟧ Δ -- monG : ∀{Γ Δ Φ} (τ : Φ ≤ Δ) → G⟦ Γ ⟧ Δ → G⟦ Γ ⟧ Φ monG : ∀{Γ} → Mon G⟦ Γ ⟧ monG {ε} τ _ = _ monG {Γ ∙ A} τ (γ , a) = monG τ γ , monT A τ a -- Variable case. fundH : ∀{Γ Δ A} (x : Hyp A Γ) (γ : G⟦ Γ ⟧ Δ) → T⟦ A ⟧ Δ fundH top = proj₂ fundH (pop x) = fundH x ∘ proj₁ -- The fundamental theorem: -- A call-by-value interpreter. fund : ∀{Γ A} (t : Γ ⊢ A) {Δ} (γ : G⟦ Γ ⟧ Δ) → M' T⟦ A ⟧ Δ fund (hyp {A} x) γ = return λ τ → monT A τ (fundH x γ) fund (impI t) γ = return' λ τ a → fund t (monG τ γ , a) fund (impE t u) γ = fund t γ >>= λ τ f → fund u (monG τ γ) >>= λ τ′ a → f τ′ a fund (andI {A} {B} t u) γ = fund t γ >>= λ τ a → fund u (monG τ γ) >>= λ τ′ b → return λ τ₁ → monT A (τ₁ • τ′) a , monT B τ₁ b fund (andE₁ t) γ = proj₁ <$> fund t γ fund (andE₂ t) γ = proj₂ <$> fund t γ fund (orI₁ t) γ = inj₁ <$> fund t γ fund (orI₂ t) γ = inj₂ <$> fund t γ fund (orE t u v) γ = fund t γ >>= λ τ → [ (λ a → fund u (monG τ γ , a)) , (λ b → fund v (monG τ γ , b)) ] fund (falseE t) γ = fund t γ >>= λ τ () fund trueI γ = return _ -- Identity environment ide : ∀ Γ → □ (M' G⟦ Γ ⟧) Γ ide ε τ = return _ ide (Γ ∙ A) τ = ide Γ (τ • weak id≤) >>= λ τ₁ γ → reflect A (monNe (τ₁ • τ) (hyp top)) >>= λ τ₂ a → return λ τ₃ → monG (τ₃ • τ₂) γ , monT A τ₃ a -- Normalization norm : ∀{A Γ} (t : Γ ⊢ A) → Nf Γ A norm {A} {Γ} t = reset' $ ide Γ id≤ >>= λ _ γ → reify A <$> fund t γ idD : (A : Form) → ε ⊢ (A ⇒ A) idD A = impI (hyp top) test : let A = Atom α; B = Atom β in Nf ε (A ∨ B ⇒ A ∨ B) test = norm (idD (Atom α ∨ Atom β)) test2 = norm (idD (Atom α ∨ Atom β ∨ Atom α)) -- Q.E.D. -} -- -} -- -} -- -} -- -} -- -} -- -}
import analysis.normed.group.hom_completion /-! # A controlled exactness lemma for seminormed groups This file contains a proof of Proposition 8.17 of `analytic.pdf`, a technical lemma which controls, in some cases, the norm of the map induced on completions by a normed group hom. -/ noncomputable theory open filter set function normed_add_comm_group uniform_space normed_add_group_hom finset open_locale topological_space big_operators lemma controlled_exactness {M M₁ M₂ : Type*} [seminormed_add_comm_group M] [seminormed_add_comm_group M₁] [seminormed_add_comm_group M₂] {f : normed_add_group_hom M₁ M} {C : ℝ} (hC : 0 < C) {D : ℝ} {g : normed_add_group_hom M M₂} (h : f.surjective_on_with g.ker C) (h' : g.surjective_on_with g.range D) : ∀ ε > 0, f.completion.surjective_on_with g.completion.ker (C + ε) := begin intros ε ε_pos hatm hatm_in, by_cases H : hatm = 0, { use 0, simp only [H, le_refl, norm_zero, eq_self_iff_true, and_self, mul_zero, map_zero], }, set hatf := f.completion, set i := incl g.ker, have norm_j_comp_i : ∀ x, ∥to_compl.comp i x∥ = ∥x∥, { intro x, erw [norm_to_compl, norm_incl] }, have hatm_in : hatm ∈ closure ((to_compl.comp i).range : set $ completion M), by rwa ← normed_add_group_hom.ker_completion h', have : ∀ k : g.ker, ∃ m' : completion M₁, hatf m' = (to_compl.comp i) k ∧ ∥m'∥ ≤ C * ∥k∥, { rintros ⟨k, k_in⟩, rcases h k k_in with ⟨m₁, hm₁, hm₁'⟩, use m₁, erw [f.completion_coe, hm₁, norm_to_compl], exact ⟨rfl, hm₁'⟩ }, exact controlled_closure_range_of_complete norm_j_comp_i hC ε_pos this _ hatm_in end
/- Copyright (c) 2020 Adam Topaz. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Zhangir Azerbayev, Adam Topaz, Eric Wieser -/ import algebra.ring_quot import linear_algebra.tensor_algebra import linear_algebra.alternating import group_theory.perm.sign /-! # Exterior Algebras We construct the exterior algebra of a module `M` over a commutative semiring `R`. ## Notation The exterior algebra of the `R`-module `M` is denoted as `exterior_algebra R M`. It is endowed with the structure of an `R`-algebra. Given a linear morphism `f : M → A` from a module `M` to another `R`-algebra `A`, such that `cond : ∀ m : M, f m * f m = 0`, there is a (unique) lift of `f` to an `R`-algebra morphism, which is denoted `exterior_algebra.lift R f cond`. The canonical linear map `M → exterior_algebra R M` is denoted `exterior_algebra.ι R`. ## Theorems The main theorems proved ensure that `exterior_algebra R M` satisfies the universal property of the exterior algebra. 1. `ι_comp_lift` is fact that the composition of `ι R` with `lift R f cond` agrees with `f`. 2. `lift_unique` ensures the uniqueness of `lift R f cond` with respect to 1. ## Definitions * `ι_multi` is the `alternating_map` corresponding to the wedge product of `ι R m` terms. ## Implementation details The exterior algebra of `M` is constructed as a quotient of the tensor algebra, as follows. 1. We define a relation `exterior_algebra.rel R M` on `tensor_algebra R M`. This is the smallest relation which identifies squares of elements of `M` with `0`. 2. The exterior algebra is the quotient of the tensor algebra by this relation. -/ universes u1 u2 u3 variables (R : Type u1) [comm_semiring R] variables (M : Type u2) [add_comm_monoid M] [module R M] namespace exterior_algebra open tensor_algebra /-- `rel` relates each `ι m * ι m`, for `m : M`, with `0`. The exterior algebra of `M` is defined as the quotient modulo this relation. -/ inductive rel : tensor_algebra R M → tensor_algebra R M → Prop | of (m : M) : rel ((ι R m) * (ι R m)) 0 end exterior_algebra /-- The exterior algebra of an `R`-module `M`. -/ @[derive [inhabited, semiring, algebra R]] def exterior_algebra := ring_quot (exterior_algebra.rel R M) namespace exterior_algebra variables {M} instance {S : Type u3} [comm_ring S] [module S M] : ring (exterior_algebra S M) := ring_quot.ring (exterior_algebra.rel S M) /-- The canonical linear map `M →ₗ[R] exterior_algebra R M`. -/ def ι : M →ₗ[R] exterior_algebra R M := (ring_quot.mk_alg_hom R _).to_linear_map.comp (tensor_algebra.ι R) variables {R} /-- As well as being linear, `ι m` squares to zero -/ @[simp] theorem ι_sq_zero (m : M) : (ι R m) * (ι R m) = 0 := begin erw [←alg_hom.map_mul, ring_quot.mk_alg_hom_rel R (rel.of m), alg_hom.map_zero _], end variables {A : Type*} [semiring A] [algebra R A] @[simp] theorem comp_ι_sq_zero (g : exterior_algebra R M →ₐ[R] A) (m : M) : g (ι R m) * g (ι R m) = 0 := by rw [←alg_hom.map_mul, ι_sq_zero, alg_hom.map_zero] variables (R) /-- Given a linear map `f : M →ₗ[R] A` into an `R`-algebra `A`, which satisfies the condition: `cond : ∀ m : M, f m * f m = 0`, this is the canonical lift of `f` to a morphism of `R`-algebras from `exterior_algebra R M` to `A`. -/ @[simps symm_apply] def lift : {f : M →ₗ[R] A // ∀ m, f m * f m = 0} ≃ (exterior_algebra R M →ₐ[R] A) := { to_fun := λ f, ring_quot.lift_alg_hom R ⟨tensor_algebra.lift R (f : M →ₗ[R] A), λ x y (h : rel R M x y), by { induction h, rw [alg_hom.map_zero, alg_hom.map_mul, tensor_algebra.lift_ι_apply, f.prop] }⟩, inv_fun := λ F, ⟨F.to_linear_map.comp (ι R), λ m, by rw [ linear_map.comp_apply, alg_hom.to_linear_map_apply, comp_ι_sq_zero]⟩, left_inv := λ f, by { ext, simp [ι] }, right_inv := λ F, by { ext, simp [ι] } } @[simp] theorem ι_comp_lift (f : M →ₗ[R] A) (cond : ∀ m, f m * f m = 0) : (lift R ⟨f, cond⟩).to_linear_map.comp (ι R) = f := (subtype.mk_eq_mk.mp $ (lift R).symm_apply_apply ⟨f, cond⟩) @[simp] theorem lift_ι_apply (f : M →ₗ[R] A) (cond : ∀ m, f m * f m = 0) (x) : lift R ⟨f, cond⟩ (ι R x) = f x := (linear_map.ext_iff.mp $ ι_comp_lift R f cond) x @[simp] theorem lift_unique (f : M →ₗ[R] A) (cond : ∀ m, f m * f m = 0) (g : exterior_algebra R M →ₐ[R] A) : g.to_linear_map.comp (ι R) = f ↔ g = lift R ⟨f, cond⟩ := begin convert (lift R).symm_apply_eq, rw lift_symm_apply, simp only, end attribute [irreducible] ι lift -- Marking `exterior_algebra` irreducible makes our `ring` instances inaccessible. -- https://leanprover.zulipchat.com/#narrow/stream/113488-general/topic/algebra.2Esemiring_to_ring.20breaks.20semimodule.20typeclass.20lookup/near/212580241 -- For now, we avoid this by not marking it irreducible. variables {R M} @[simp] theorem lift_comp_ι (g : exterior_algebra R M →ₐ[R] A) : lift R ⟨g.to_linear_map.comp (ι R), comp_ι_sq_zero _⟩ = g := begin convert (lift R).apply_symm_apply g, rw lift_symm_apply, refl, end /-- See note [partially-applied ext lemmas]. -/ @[ext] theorem hom_ext {f g : exterior_algebra R M →ₐ[R] A} (h : f.to_linear_map.comp (ι R) = g.to_linear_map.comp (ι R)) : f = g := begin apply (lift R).symm.injective, rw [lift_symm_apply, lift_symm_apply], simp only [h], end /-- If `C` holds for the `algebra_map` of `r : R` into `exterior_algebra R M`, the `ι` of `x : M`, and is preserved under addition and muliplication, then it holds for all of `exterior_algebra R M`. -/ -- This proof closely follows `tensor_algebra.induction` @[elab_as_eliminator] lemma induction {C : exterior_algebra R M → Prop} (h_grade0 : ∀ r, C (algebra_map R (exterior_algebra R M) r)) (h_grade1 : ∀ x, C (ι R x)) (h_mul : ∀ a b, C a → C b → C (a * b)) (h_add : ∀ a b, C a → C b → C (a + b)) (a : exterior_algebra R M) : C a := begin -- the arguments are enough to construct a subalgebra, and a mapping into it from M let s : subalgebra R (exterior_algebra R M) := { carrier := C, mul_mem' := h_mul, add_mem' := h_add, algebra_map_mem' := h_grade0, }, let of : { f : M →ₗ[R] s // ∀ m, f m * f m = 0 } := ⟨(ι R).cod_restrict s.to_submodule h_grade1, λ m, subtype.eq $ ι_sq_zero m ⟩, -- the mapping through the subalgebra is the identity have of_id : alg_hom.id R (exterior_algebra R M) = s.val.comp (lift R of), { ext, simp [of], }, -- finding a proof is finding an element of the subalgebra convert subtype.prop (lift R of a), exact alg_hom.congr_fun of_id a, end /-- The left-inverse of `algebra_map`. -/ def algebra_map_inv : exterior_algebra R M →ₐ[R] R := exterior_algebra.lift R ⟨(0 : M →ₗ[R] R), λ m, by simp⟩ lemma algebra_map_left_inverse : function.left_inverse algebra_map_inv (algebra_map R $ exterior_algebra R M) := λ x, by simp [algebra_map_inv] /-- The left-inverse of `ι`. As an implementation detail, we implement this using `triv_sq_zero_ext` which has a suitable algebra structure. -/ def ι_inv : exterior_algebra R M →ₗ[R] M := (triv_sq_zero_ext.snd_hom R M).comp (lift R ⟨triv_sq_zero_ext.inr_hom R M, λ m, triv_sq_zero_ext.inr_mul_inr R _ m m⟩).to_linear_map lemma ι_left_inverse : function.left_inverse ι_inv (ι R : M → exterior_algebra R M) := λ x, by simp [ι_inv] @[simp] lemma ι_add_mul_swap (x y : M) : ι R x * ι R y + ι R y * ι R x = 0 := calc _ = ι R (x + y) * ι R (x + y) : by simp [mul_add, add_mul] ... = _ : ι_sq_zero _ lemma ι_mul_prod_list {n : ℕ} (f : fin n → M) (i : fin n) : (ι R $ f i) * (list.of_fn $ λ i, ι R $ f i).prod = 0 := begin induction n with n hn, { exact i.elim0, }, { rw [list.of_fn_succ, list.prod_cons, ←mul_assoc], by_cases h : i = 0, { rw [h, ι_sq_zero, zero_mul], }, { replace hn := congr_arg ((*) $ ι R $ f 0) (hn (λ i, f $ fin.succ i) (i.pred h)), simp only at hn, rw [fin.succ_pred, ←mul_assoc, mul_zero] at hn, refine (eq_zero_iff_eq_zero_of_add_eq_zero _).mp hn, rw [← add_mul, ι_add_mul_swap, zero_mul], } } end variables (R) /-- The product of `n` terms of the form `ι R m` is an alternating map. This is a special case of `multilinear_map.mk_pi_algebra_fin` -/ def ι_multi (n : ℕ) : alternating_map R M (exterior_algebra R M) (fin n) := let F := (multilinear_map.mk_pi_algebra_fin R n (exterior_algebra R M)).comp_linear_map (λ i, ι R) in { map_eq_zero_of_eq' := λ f x y hfxy hxy, begin rw [multilinear_map.comp_linear_map_apply, multilinear_map.mk_pi_algebra_fin_apply], wlog h : x < y := lt_or_gt_of_ne hxy using x y, clear hxy, induction n with n hn generalizing x y, { exact x.elim0, }, { rw [list.of_fn_succ, list.prod_cons], by_cases hx : x = 0, -- one of the repeated terms is on the left { rw hx at hfxy h, rw [hfxy, ←fin.succ_pred y (ne_of_lt h).symm], exact ι_mul_prod_list (f ∘ fin.succ) _, }, -- ignore the left-most term and induct on the remaining ones, decrementing indices { convert mul_zero _, refine hn (λ i, f $ fin.succ i) (x.pred hx) (y.pred (ne_of_lt $ lt_of_le_of_lt x.zero_le h).symm) (fin.pred_lt_pred_iff.mpr h) _, simp only [fin.succ_pred], exact hfxy, } } end, to_fun := F, ..F} variables {R} lemma ι_multi_apply {n : ℕ} (v : fin n → M) : ι_multi R n v = (list.of_fn $ λ i, ι R (v i)).prod := rfl end exterior_algebra namespace tensor_algebra variables {R M} /-- The canonical image of the `tensor_algebra` in the `exterior_algebra`, which maps `tensor_algebra.ι R x` to `exterior_algebra.ι R x`. -/ def to_exterior : tensor_algebra R M →ₐ[R] exterior_algebra R M := tensor_algebra.lift R (exterior_algebra.ι R) @[simp] lemma to_exterior_ι (m : M) : (tensor_algebra.ι R m).to_exterior = exterior_algebra.ι R m := by simp [to_exterior] end tensor_algebra
#md# This animation shows the process of fitting the layout. using CSV using DataFrames using WordCloud df = CSV.File(pkgdir(WordCloud) * "/res/guxiang_frequency.txt", header=false) |> DataFrame; words = df[!, "Column2"] weights = df[!, "Column3"] wc = wordcloud(words, weights, density=0.6) gifdirectory = "animation2" @record gifdirectory overwrite=true generate!(wc, 100, optimiser=WordCloud.Momentum()) println("results are saved in animation2") wc #eval# runexample(:animation2) #md# ![](animation2/animation.gif)
= = Recipients = =
section \<open>Preprocessor and Code-Generator User Interface\<close> theory LLVM_Codegen_Preproc imports "../kernel/LLVM_Codegen" "Monadify" "../../lib/Definition_Utils" "../../lib/Named_Simpsets" keywords "export_llvm" "llvm_deps" :: thy_decl begin subsection \<open>Fixed-Point Unfolding Setup\<close> lemma llc_while_mono[partial_function_mono]: assumes "\<And>x. M_mono (\<lambda>f. b f x)" assumes "\<And>x. M_mono (\<lambda>f. c f x)" shows "M_mono (\<lambda>D. llc_while (b D) (c D) \<sigma>)" using assms unfolding llc_while_def by pf_mono_prover declaration \<open>fn _ => Definition_Utils.declare_extraction_group @{binding LLVM} #> snd\<close> declaration \<open>fn _ => Definition_Utils.declare_extraction_group @{binding LLVM_while} #> snd\<close> declaration \<open> fn _ => Definition_Utils.add_extraction (@{extraction_group LLVM_while},\<^here>) { pattern = Logic.varify_global @{term "llc_while b body"}, gen_thm = @{thm gen_code_thm_llc_while}, gen_tac = K (K no_tac) } \<close> declaration \<open>fn _ => Definition_Utils.add_extraction (@{extraction_group LLVM},\<^here>) { pattern = Logic.varify_global @{term "REC (B::('a \<Rightarrow> 'b llM) \<Rightarrow> 'a \<Rightarrow> 'b llM)"}, gen_thm = @{thm REC_unfold}, gen_tac = Partial_Function.mono_tac } \<close> subsection \<open>Preprocessor\<close> text \<open> The actual code generator expects a set of monomorphic, well-shaped equations. The preprocessor processes user specified equations, monomorphizes them and brings them into the right shape. \<close> named_theorems llvm_code \<open>Isabelle-LLVM code theorems\<close> named_simpset llvm_inline = HOL_ss attribute_setup llvm_inline = \<open> Attrib.add_del (Named_Simpsets.add_attr @{named_simpset llvm_inline}) (Named_Simpsets.del_attr @{named_simpset llvm_inline}) \<close> lemma llvm_inline_bind_laws[llvm_inline]: "bind m return = m" "bind (bind m (\<lambda>x. f x)) g = bind m (\<lambda>x. bind (f x) g)" by auto lemma unit_meta_eq: "x \<equiv> ()" by simp lemma pull_lambda_case: "(case x of (a,b) \<Rightarrow> \<lambda>y. t a b y) = (\<lambda>y. case x of (a,b) \<Rightarrow> t a b y)" apply (rule ext) apply (cases x) by auto ML \<open> structure LLC_Preprocessor = struct open LLC_Lib val cfg_llvm_preproc_timing = Attrib.setup_config_bool @{binding llvm_preproc_timing} (K false) structure Monadify = Gen_Monadify_Cong ( fun mk_return x = @{mk_term "return ?x ::_ llM"} fun mk_bind m f = @{mk_term "bind ?m ?f ::_ llM"} fun dest_return @{mpat "return ?x ::_ llM"} = SOME x | dest_return _ = NONE fun dest_bind @{mpat "bind ?m ?f ::_ llM"} = SOME (m,f) | dest_bind _ = NONE fun dest_monadT (Type (@{type_name M},[T,@{typ unit},@{typ llvm_memory},@{typ err}])) = SOME T | dest_monadT _ = NONE (*val strip_op = K strip_comb*) val bind_return_thm = @{lemma "bind m return = m" by simp} val return_bind_thm = @{lemma "bind (return x) f = f x" by simp} val bind_bind_thm = @{lemma "bind (bind m (\<lambda>x. f x)) g = bind m (\<lambda>x. bind (f x) g)" by simp} ) (********* Normalization of code theorems *) fun cthm_inline ctxt thm = let val ctxt = Named_Simpsets.put @{named_simpset llvm_inline} ctxt in (* TODO: Simplifier.rewrite may introduce beta redexes. Currently we eliminate them right away. Or is it OK to have beta-redexes? *) Conv.fconv_rule (rhs_conv (Simplifier.rewrite ctxt) then_conv Thm.beta_conversion true) thm end val cthm_monadify = Conv.fconv_rule o (rhs_conv o Monadify.monadify_conv) val inline_iteration_limit = Config.int (Config.declare ("inline_iteration_limit", \<^here>) (fn _ => Config.Int ~1)); fun monadify_inline_cthm ctxt thm = let fun rpt 0 thm' = raise THM ("inline_iteration_limit exceeded",~1,[thm,thm']) | rpt n thm = let val thm' = thm |> cthm_monadify ctxt |> cthm_inline ctxt in if Thm.eq_thm_prop (thm,thm') then thm else rpt (n-1) thm' end val it_limit = Config.get ctxt inline_iteration_limit in thm |> cthm_inline ctxt |> rpt it_limit end (* Bring code theorem into parseable format. To be applied after inlining, immediately before parsing. Applies eta-expansion, return-expansion, and converts \<equiv> to =. Finally, it will replace unit-binds by () constants and anonymous bind. May fail on non-well-formed theorems. *) fun cthm_format ctxt thm = let fun normalize_bind1 t = let val (f,args) = strip_comb t val _ = check_valid_head f val args_is_M = fastype_of f |> binder_types |> map (is_llM o body_type) val _ = length args_is_M = length args orelse raise TYPE ("cthm_format: All arguments must be explicit", [fastype_of f], [t]) val args = map2 (fn isM => isM?(normalize o expand_eta_all)) args_is_M args in list_comb (f, args) end and normalize @{mpat "bind ?m ?f"} = let val m = normalize_bind1 m val f = (*ensure_abs f*) expand_eta_all f |> normalize in @{mk_term "bind ?m ?f"} end | normalize (Abs (x,T,t)) = Abs (x,T,normalize t) | normalize (t as @{mpat "return _"}) = t | normalize t = let val t = normalize_bind1 t in @{mk_term "bind ?t (\<lambda>x. return x)"} end fun normalize_eq @{mpat "Trueprop (?a = ?b)"} = let val b = normalize b in @{mk_term "Trueprop (?a = ?b)"} end | normalize_eq @{mpat "?a \<equiv> ?b"} = let val b = normalize b in @{mk_term "?a \<equiv> ?b"} end | normalize_eq t = raise TERM ("format_code_thm: normalize_eq", [t]) fun norm_tac ctxt = ALLGOALS (simp_tac (put_simpset HOL_ss ctxt addsimps @{thms bind_laws})) fun cthm_norm_lambda ctxt thm = let val thm = Local_Defs.unfold ctxt @{thms pull_lambda_case} thm (*fun r thm = case Thm.concl_of thm of @{mpat "Trueprop (_ = (\<lambda>_. _))"} => r (thm RS @{thm fun_cong}) | @{mpat "_ \<equiv> (\<lambda>_. _)"} => r (thm RS @{thm meta_fun_cong}) | _ => thm *) fun r thm = case try (fn () => (thm RS @{thm fun_cong})) () of NONE => thm | SOME thm => r thm in r thm end in thm |> (simplify (put_simpset HOL_ss ctxt addsimps @{thms Monad.bind_laws atomize_eq})) |> cthm_norm_lambda ctxt |> (Conv.fconv_rule (Refine_Util.f_tac_conv ctxt normalize_eq (norm_tac ctxt))) |> (Conv.fconv_rule (Conv.top_sweep_conv (K (Conv.rewr_conv @{thm unit_meta_eq})) ctxt)) end (********* Gathering of code equations *) (* TODO: Use net *) fun dep_prep_code_thm thm = let val c = head_of_eqn_thm thm val _ = check_valid_head c in (c,thm) end fun dep_try_instantiate_code_thm c (l,thm) = let val thy = Thm.theory_of_thm thm in case SOME (Pattern.match thy (l,c) (Vartab.empty,Vartab.empty)) handle Pattern.MATCH => NONE of NONE => NONE | SOME m => SOME (instantiate_uc m thm) end fun dep_find_code_thm pthms c = case get_first (dep_try_instantiate_code_thm c) pthms of SOME eqn => eqn | NONE => raise TERM ("No code equation",[c]) val cmd_name_prefix = Long_Name.qualify (Long_Name.qualifier @{const_name ll_add}) "ll_" val comb_name_prefix = Long_Name.qualify (Long_Name.qualifier @{const_name llc_while}) "llc_" fun dep_is_ll_comb_name name = name = @{const_name bind} orelse name = @{const_name return} orelse String.isPrefix cmd_name_prefix name orelse String.isPrefix comb_name_prefix name fun dep_is_call_const t = case try dest_head t of NONE => false | SOME (name,T) => not (dep_is_ll_comb_name name) (* Not an internal name *) andalso is_llM (body_type T) (* Yields a monadic result *) andalso not (exists (exists_subtype is_llM) (binder_types T)) (* No monadic parameters *) fun calls_of_cthm thm = Term.fold_aterms (fn t => dep_is_call_const t?cons t) (rhs_of_eqn (Thm.prop_of thm)) [] fun default_extractions ctxt = Definition_Utils.get_extraction_group ctxt @{extraction_group LLVM} |> (not (Config.get ctxt llc_compile_while) ? append (Definition_Utils.get_extraction_group ctxt @{extraction_group LLVM_while})) fun gather_code_thms roots lthy = let val thy = Proof_Context.theory_of lthy val pthms = Named_Theorems.get lthy @{named_theorems llvm_code} |> map dep_prep_code_thm |> Refine_Util.subsume_sort fst thy val tim = Config.get lthy cfg_llvm_preproc_timing fun trace msg = if tim then msg () |> tracing else () fun process_root c (ctab, lthy) = let val _ = check_valid_head c val basename = name_of_head c |> Long_Name.base_name in case Termtab.lookup ctab c of SOME _ => (ctab, lthy) | NONE => let val _ = trace (fn () => "Processing " ^ basename) val startt = Time.now () val _ = assert_monomorphic_const c (* Get code theorem and inline it *) val teqn = dep_find_code_thm pthms c |> monadify_inline_cthm lthy (* Extract recursion equations *) val exs = default_extractions lthy val ((teqn,add_eqns,_),lthy) = Definition_Utils.extract_recursion_eqs exs basename teqn lthy val teqns = teqn::add_eqns (* Inline and format again *) val teqns = map (monadify_inline_cthm lthy #> cthm_format lthy) teqns (* Update table *) val ctab = fold Termtab.update_new (map dep_prep_code_thm teqns) ctab (* Find calls *) val calls = map calls_of_cthm teqns |> flat val stopt = Time.now() val _ = trace (fn () => "Done " ^ basename ^ ": " ^ Time.toString (stopt - startt)) (* Recurse *) val (ctab,lthy) = fold process_root calls (ctab,lthy) in (ctab, lthy) end end val (ctab,lthy) = fold process_root roots (Termtab.empty,lthy) val thms = Termtab.dest ctab |> map snd in (thms,lthy) end end \<close> declaration \<open>K (LLC_Preprocessor.Monadify.prepare_add_const_decl @{term "numeral a"})\<close> subsection \<open>Code Generator Driver\<close> text \<open> The driver combines preeprocessing and code generation, and defines the user interface of the code generator, namely the commands @{command export_llvm} and @{command llvm_deps}. \<close> ML \<open> structure LLC_Driver = struct val cfg_llvm_debug = Attrib.setup_config_bool @{binding llvm_debug} (K false) val cfg_llvm_timing = Attrib.setup_config_bool @{binding llvm_timing} (K false) val cfg_llvm_gen_header = Attrib.setup_config_bool @{binding llvm_gen_header} (K true) fun pretty_cthms ctxt cthms = let val ctxt = Config.put Syntax_Trans.eta_contract false ctxt in Pretty.big_list "Code Theorems" (map (Thm.pretty_thm ctxt) cthms) end fun pretty_ftab_entry ctxt (t,n) = Pretty.block [ Syntax.pretty_term ctxt t, Pretty.brk 1, Pretty.str ":: ", Syntax.pretty_typ ctxt (fastype_of t), Pretty.brk 1,Pretty.str "\<rightarrow>",Pretty.brk 1, Pretty.str n ] fun pretty_ftab ctxt ftab = Pretty.big_list "Symbol table:" (map (pretty_ftab_entry ctxt) (Termtab.dest ftab)) fun consts_to_llvm hfname cns tydefs nt_ovr lthy = let val dbg = Config.get lthy cfg_llvm_debug val tim = Config.get lthy cfg_llvm_timing val gen_header = Config.get lthy cfg_llvm_gen_header fun trace s = if dbg then Pretty.string_of (s ()) |> tracing else () fun trtimed msg f x = case (dbg,tim) of (_,true) => timeap_msg msg f x | (true,_) => (trace (fn () => Pretty.str msg); f x) | _ => f x val (cthms,lthy) = trtimed "Gathering code theorems" (LLC_Preprocessor.gather_code_thms (map fst cns)) lthy val _ = trace (fn () => pretty_cthms lthy cthms) fun cmp_symtab cthms = let fun fx (_,NONE) = NONE | fx (cn, SOME csig) = SOME (cn,C_Interface.name_of_sig csig) val fixes = map_filter fx cns val ftab = LLC_Compiler.compute_fun_names fixes cthms in ftab end val ftab = trtimed "Computing symbol table" cmp_symtab cthms val _ = trace (fn () => pretty_ftab lthy ftab) val (tys,eqns) = trtimed "Translating code theorems to IL" (LLC_Compiler.parse_cthms ftab nt_ovr cthms) lthy val _ = trace (fn () => LLC_Intermediate.pretty_llc (tys,eqns)) val _ = trace (fn () => Pretty.str "Writing LLVM") val res = trtimed "Writing LLVM" (LLC_Backend.compile_to_llvm lthy) (tys,eqns) val hdres = if gen_header then let fun mk_hd eqns = let val sigspecs = map_filter snd cns fun dest_sig sg = (C_Interface.name_of_sig sg, sg) val sigtab = Symtab.make (map dest_sig sigspecs) fun match_eqn (eqn as LLC_Intermediate.EQN (_,name,_,_)) = case Symtab.lookup sigtab name of NONE => NONE | SOME sg => SOME (eqn,sg) val eqnsxsigs = map_filter match_eqn eqns val hdres = LLC_HeaderGen.make_header hfname tydefs tys eqnsxsigs in hdres end val hdres = trtimed "Preparing Header" mk_hd eqns in hdres end else NONE in ((cthms,res,hdres), lthy) end local val using_master_directory = File.full_path o Resources.master_directory o Proof_Context.theory_of; fun prepare_path ctxt (s,pos) = let val _ = Position.report pos (Markup.language_path false); val path = Path.explode s; val _ = Position.report pos (Markup.path (Path.implode_symbolic path)); val path = using_master_directory ctxt path in path end fun remove_ext ext p = let val (p',ext') = Path.split_ext p in if ext=ext' then p' else p end fun remove_all_ext p = case Path.split_ext p of (p,"") => p | (p,_) => remove_all_ext p fun prepare_hpath _ NONE = ("HEADER_NAME",NONE) | prepare_hpath ctxt (SOME spos) = let val path = prepare_path ctxt spos |> remove_ext "ll" |> Path.ext "h" val hfname = remove_all_ext (Path.base path) |> Path.implode in (hfname,SOME path) end fun write_out NONE s = writeln s | write_out (SOME path) s = File.write path s (* (* Contains a name (used as name for generated LLVM function) and an optional signature (used for header file generation). Note that this information is redundant, the name in the signature must match the LLVM-name. This redundancy, however, reflects the split of LLVM code generator and Header file generator. *) datatype siginfo = SIGI of string * LLC_HeaderGen.raw_sig option fun sigi_of_sig (rsg as (LLC_HeaderGen.RSIG (_,name,_))) = SIGI (name,SOME rsg) fun sigi_of_name name = SIGI (name,NONE) fun sigi_name (SIGI (name,_)) = name fun sigi_has_sig (SIGI (_,NONE)) = false | sigi_has_sig (SIGI (_,SOME _)) = true fun sigi_the_sig (SIGI (_,SOME sg)) = sg | sigi_the_sig _ = raise Match val parse_sigi = (Parse.short_ident || Parse.string) >> sigi_of_name || xxx, string needs inner parser! *) in fun export_llvm cns tydefs nt_ovr path (hfname,hfpath) lthy = let val lthy = Config.put Syntax_Trans.eta_contract false lthy val ((cthms,llvm_code,hcode),lthy) = consts_to_llvm hfname cns tydefs nt_ovr lthy val _ = write_out path llvm_code val _ = case hcode of SOME c => write_out hfpath c | NONE => () in (cthms,lthy) end val parse_ty_overrides = Scan.repeat1 (Parse.typ --| @{keyword "="} -- Parse.name) val export_llvm_cmd = ( (Args.mode "debug" -- Args.mode "timing" -- Args.mode "no_while" -- Args.mode "no_header" -- Parse_Spec.opt_thm_name ":" -- Scan.repeat1 (Parse.term -- Scan.option (@{keyword "is"} |-- LLC_HeaderGen.parse_raw_sig )) -- Scan.option (@{keyword "defines"} |-- LLC_HeaderGen.parse_raw_tydefs) -- Scan.optional (@{keyword "rewrites"} |-- parse_ty_overrides) [] -- Scan.option ((@{keyword "file"} |-- Parse.position Parse.path)) ) >> (fn (((((((((dbg,timing),nowhile),no_header),bnd),cns),tydefs),nt_ovr),path_spos)) => fn lthy => let local val lthy = (timing?Config.put cfg_llvm_timing true) lthy val lthy = (dbg?Config.put cfg_llvm_debug true) lthy val lthy = (nowhile?Config.put LLC_Lib.llc_compile_while false) lthy val lthy = (no_header?Config.put cfg_llvm_gen_header false) lthy in val cns = map (apfst (Syntax.read_term lthy)) cns val cns = map (apsnd (map_option (LLC_HeaderGen.check_raw_sig lthy))) cns val tydefs = the_default [] (map_option (LLC_HeaderGen.check_raw_tydefs lthy) tydefs) val nt_ovr = map (apfst (Syntax.read_typ lthy)) nt_ovr val path = Option.map (prepare_path lthy) path_spos val hfnpath = prepare_hpath lthy path_spos val (cthms,lthy) = export_llvm cns tydefs nt_ovr path hfnpath lthy end val (_,lthy) = Local_Theory.note (bnd,cthms) lthy in lthy end)) val llvm_deps_cmd = Parse_Spec.opt_thm_name ":" -- Scan.repeat1 Parse.term >> (fn (bnd,cns) => fn lthy => let val cns = map (Syntax.read_term lthy) cns val _ = writeln "Gathering code theorems" val (cthms,lthy) = LLC_Preprocessor.gather_code_thms cns lthy val (_,lthy) = Local_Theory.note (bnd,cthms) lthy val _ = writeln "Done" val _ = pretty_cthms lthy cthms |> Pretty.string_of |> writeln in lthy end ) end val _ = Outer_Syntax.local_theory @{command_keyword export_llvm} "generate LLVM code for constants" export_llvm_cmd val _ = Outer_Syntax.local_theory @{command_keyword llvm_deps} "Print LLVM code theorems for constants" llvm_deps_cmd end \<close> subsection \<open>Setup for Product Type\<close> text \<open>We prepare a setup to compile product types to anonymous 2-element structures\<close> lemma to_val_prod[ll_to_val]: "to_val x = llvm_struct [to_val (fst x), to_val (snd x)]" by (cases x; simp) definition prod_insert_fst :: "('a::llvm_rep \<times> 'b::llvm_rep) \<Rightarrow> 'a \<Rightarrow> _" where [llvm_inline]: "prod_insert_fst p x \<equiv> ll_insert_value p x 0" definition prod_insert_snd :: "('a::llvm_rep \<times> 'b::llvm_rep) \<Rightarrow> 'b \<Rightarrow> _" where [llvm_inline]: "prod_insert_snd p x \<equiv> ll_insert_value p x 1" definition prod_extract_fst :: "('a::llvm_rep \<times> 'b::llvm_rep) \<Rightarrow> 'a llM" where [llvm_inline]: "prod_extract_fst p \<equiv> ll_extract_value p 0" definition prod_extract_snd :: "('a::llvm_rep \<times> 'b::llvm_rep) \<Rightarrow> 'b llM" where [llvm_inline]: "prod_extract_snd p \<equiv> ll_extract_value p 1" definition prod_gep_fst :: "('a::llvm_rep \<times> 'b::llvm_rep) ptr \<Rightarrow> 'a ptr llM" where [llvm_inline]: "prod_gep_fst p \<equiv> ll_gep_struct p 0" definition prod_gep_snd :: "('a::llvm_rep \<times> 'b::llvm_rep) ptr \<Rightarrow> 'b ptr llM" where [llvm_inline]: "prod_gep_snd p \<equiv> ll_gep_struct p 1" lemma prod_ops_simp: "prod_insert_fst = (\<lambda>(_,b) a. return (a,b))" "prod_insert_snd = (\<lambda>(a,_) b. return (a,b))" "prod_extract_fst = (\<lambda>(a,b). return a)" "prod_extract_snd = (\<lambda>(a,b). return b)" unfolding prod_insert_fst_def prod_insert_snd_def ll_insert_value_def prod_extract_fst_def prod_extract_snd_def ll_extract_value_def apply (all \<open>intro ext\<close> ) apply (auto simp: to_val_prod_def from_val_prod_def checked_from_val_def split: prod.splits ) done subsection \<open>Ad-Hoc Regression Tests\<close> experiment begin definition exp :: "64 word \<Rightarrow> 64 word llM" where [llvm_code]: "exp i \<equiv> doM { s \<leftarrow> prod_insert_fst init 1; s \<leftarrow> prod_insert_snd s i; s \<leftarrow> llc_while (\<lambda>s. doM { i \<leftarrow> prod_extract_snd s; ll_icmp_ne i 0 }) (\<lambda>s. doM { c \<leftarrow> prod_extract_fst s; i \<leftarrow> prod_extract_snd s; c \<leftarrow> ll_mul c 2; i \<leftarrow> ll_sub i 1; s \<leftarrow> prod_insert_fst init c; s \<leftarrow> prod_insert_snd s i; return s }) s; prod_extract_fst s }" definition streq :: "8 word ptr \<Rightarrow> 8 word ptr \<Rightarrow> 1 word llM" where [llvm_code]: "streq s\<^sub>1 s\<^sub>2 = doM { x \<leftarrow> ll_load s\<^sub>1; ll_load s\<^sub>2 \<bind> ll_icmp_eq x }" export_llvm streq definition [llvm_code]: "test2 (n::32 word) \<equiv> doM { n \<leftarrow> ll_add n 42; p \<leftarrow> ll_malloc TYPE(16 word) n; p \<leftarrow> ll_ofs_ptr p (5::32 word); ll_store 42 p; r \<leftarrow> ll_load p; return r }" definition [llvm_code]: "add_add (a::_ word) \<equiv> doM { x \<leftarrow> ll_add a a; x \<leftarrow> ll_add x x; return x }" definition [llvm_code]: "add_add_driver (a::32 word) (b::64 word) \<equiv> doM { a \<leftarrow> add_add a; b \<leftarrow> add_add b; a \<leftarrow> ll_zext a TYPE(64 word); b \<leftarrow> ll_add a b; return b }" export_llvm (debug) add_add_driver definition [llvm_code]: "main (argc::32 word) (argv::8 word ptr ptr) \<equiv> doM { r \<leftarrow> test2 argc; r \<leftarrow> ll_zext r TYPE(32 word); return r }" definition [llvm_code]: "main_exp (argc::32 word) (argv::8 word ptr ptr) \<equiv> doM { argc \<leftarrow> ll_zext argc TYPE(64 word); r \<leftarrow> exp argc; r \<leftarrow> ll_trunc r TYPE(32 word); return r }" definition [llvm_code]: "testx (a::64 word) \<equiv> llc_while (\<lambda>a. ll_icmp_ult 0 a) (\<lambda>a. ll_sub a 1) a" export_llvm (debug) testx export_llvm (debug) exp_thms1: exp export_llvm (debug) (no_while) exp_thms2: exp export_llvm (debug) (no_while) exp_thms3: exp thm exp_thms1 thm exp_thms2 thm exp_thms3 export_llvm (debug) foobar: main_exp is main export_llvm (debug) main is main definition [llvm_code]: "test_if_names (n::32 word) \<equiv> doM { tmp \<leftarrow> ll_icmp_eq n 0; a \<leftarrow> llc_if tmp (return null) (doM { x \<leftarrow> ll_malloc TYPE(8 word) n; return x }); p \<leftarrow> ll_ofs_ptr a (1::32 word); ll_store 0x2A p; ll_free a; return () }" export_llvm test_if_names definition fib :: "64 word \<Rightarrow> 64 word llM" where [llvm_code]: "fib n \<equiv> REC (\<lambda>fib n. doM { t\<leftarrow>ll_icmp_ule n 1; llc_if t (return n) (doM { n\<^sub>1 \<leftarrow> ll_sub n 1; a\<leftarrow>fib n\<^sub>1; n\<^sub>2 \<leftarrow> ll_sub n 2; b\<leftarrow>fib n\<^sub>2; c\<leftarrow>ll_add a b; return c })} ) n" export_llvm fib is fib definition triple_sum :: "(64 word \<times> 64 word \<times> 64 word) ptr \<Rightarrow> 64 word llM" where [llvm_code]: "triple_sum abc \<equiv> doM { abc \<leftarrow> ll_load abc; a \<leftarrow> ll_extract_value abc 0; bc::64 word \<times> 64 word \<leftarrow> ll_extract_value abc 1; b \<leftarrow> ll_extract_value bc 0; c \<leftarrow> ll_extract_value bc 1; r \<leftarrow> ll_add a b; r \<leftarrow> ll_add r c; return r }" export_llvm triple_sum is \<open>_ triple_sum(triple*)\<close> defines \<open>typedef struct {int64_t a; struct {int64_t b; int64_t c;};} triple;\<close> end end
Require Import MathClasses.interfaces.abstract_algebra MathClasses.interfaces.functors MathClasses.theory.categories. Section natural_transformations_id_comp. Context `{Category A} `{Category B} `{!Functor (f: A → B) f'} `{!Functor (f: A → B) f'} `{!Functor (g: A → B) g'} `{!Functor (h: A → B) h'} `{!NaturalTransformation (m:f⇛g)} `{!NaturalTransformation (n:g⇛h)}. Global Instance id_transformation: NaturalTransformation (λ a, cat_id: f a ⟶ f a). Proof. intros ???. rewrite left_identity, right_identity; reflexivity. Qed. Global Instance compose_transformation: NaturalTransformation (λ a, n a ◎ m a). Proof. intros ???. rewrite <- associativity, natural, associativity, natural, associativity; reflexivity. Qed. End natural_transformations_id_comp. Record Object A `{Arrows A} `{∀ x y : A, Equiv (x ⟶ y)} `{!CatId A} `{!CatComp A} B `{Arrows B} `{∀ x y : B, Equiv (x ⟶ y)} `{!CatId B} `{!CatComp B} : Type := object { map_obj:> A → B ; Fmap_inst:> Fmap map_obj ; Functor_inst: Functor map_obj _ }. #[global] Existing Instance Fmap_inst. #[global] Existing Instance Functor_inst. Arguments Object _ {Aarrows Aeq Aid Acomp} _ {Barrows Beq Bid Bcomp} : rename. Arguments object {A Aarrows Aeq Aid Acomp B Barrows Beq Bid Bcomp} {Fmap Functor} _ : rename. Arguments map_obj {A Aarrows Aeq Aid Acomp B Barrows Beq Bid Bcomp} _ _ : rename. Record Arrow `{Arrows A} `{∀ x y : A, Equiv (x ⟶ y)} `{!CatId A} `{!CatComp A} `{Arrows B} `{∀ x y : B, Equiv (x ⟶ y)} `{!CatId B} `{!CatComp B} (F G : Object A B) : Type := arrow { eta:> map_obj F ⇛ map_obj G ; NaturalTransformation_inst: NaturalTransformation eta }. #[global] Existing Instance NaturalTransformation_inst. Arguments arrow {A Aarrows Aeq Aid Acomp B Barrows Beq Bid Bcomp F G} _ _ : rename. Arguments eta {A Aarrows Aeq Aid Acomp B Barrows Beq Bid Bcomp F G} _ _ : rename. Section contents. Context `{Category A} `{Category B}. Global Instance: Arrows (Object A B) := Arrow. Section arrow_setoid. Context (F G : Object A B). Global Program Instance e: Equiv (F ⟶ G) := λ m n, ∀ x: A, m x = n x. Instance e_refl: Reflexive e. Proof. intro a; red; reflexivity. Qed. Instance e_sym: Symmetric e. Proof. intros m n Hmn a. red in Hmn. rewrite Hmn. reflexivity. Qed. Instance e_trans: Transitive e. Proof. intros m n o Hmn Hno a. red in Hmn, Hno. rewrite Hmn, Hno. reflexivity. Qed. Instance: Equivalence e := {}. Global Instance: Setoid (F ⟶ G) := {}. End arrow_setoid. Global Instance: CatId (Object A B) := λ _, arrow (λ _, cat_id) _. Global Instance: CatComp (Object A B) := λ _ _ _ m n, arrow (λ a, m a ◎ n a) _. Global Instance: ∀ x y z: Object A B, Proper ((=) ==> (=) ==> (=)) ((◎): (y ⟶ z) → (x ⟶ y) → (x ⟶ z)). Proof. intros ????? Hx ?? Hy a. simpl. rewrite (Hx a), (Hy a). reflexivity. Qed. Instance: ∀ x y: Object A B, LeftIdentity (comp x y y) cat_id. Proof. repeat intro. simpl. apply left_identity. Qed. Instance: ∀ x y: Object A B, RightIdentity (comp x x y) cat_id. Proof. repeat intro. simpl. apply right_identity. Qed. Instance: ArrowsAssociative (Object A B). Proof. repeat intro. simpl. apply associativity. Qed. Global Instance: Category (Object A B) := {}. End contents.
If $s$ is a compact set, then the image of $s$ under the affine map $x \mapsto a + cx$ is also compact.
A set $S$ is complete if and only if it is closed.
lemma of_real_eq_iff [simp]: "of_real x = of_real y \<longleftrightarrow> x = y"
/- Copyright (c) 2022 Jannis Limperg. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Jannis Limperg -/ import Aesop set_option aesop.check.all true -- We used to add local rules to the `default` rule set, but this is doesn't -- work well when the default rule set is disabled. Now we add local rules to -- a separate `local` rule set. example : Unit := by fail_if_success aesop (rule_sets [-default, -builtin]) (options := { terminal := true }) fail_if_success aesop (add safe PUnit.unit) (rule_sets [-default, -builtin, -«local»]) (options := { terminal := true }) aesop (add safe PUnit.unit) (rule_sets [-default, -builtin])
/- Copyright (c) 2020 Joseph Myers. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Joseph Myers, Yury Kudryashov. -/ import Mathlib.PrePort import Mathlib.Lean3Lib.init.default import Mathlib.linear_algebra.affine_space.midpoint import Mathlib.topology.metric_space.isometry import Mathlib.topology.instances.real_vector_space import Mathlib.PostPort universes u_1 u_2 l u_3 u_4 u_5 u_6 namespace Mathlib /-! # Torsors of additive normed group actions. This file defines torsors of additive normed group actions, with a metric space structure. The motivating case is Euclidean affine spaces. -/ /-- A `normed_add_torsor V P` is a torsor of an additive normed group action by a `normed_group V` on points `P`. We bundle the metric space structure and require the distance to be the same as results from the norm (which in fact implies the distance yields a metric space, but bundling just the distance and using an instance for the metric space results in type class problems). -/ class normed_add_torsor (V : outParam (Type u_1)) (P : Type u_2) [outParam (normed_group V)] [metric_space P] extends add_torsor V P where dist_eq_norm' : ∀ (x y : P), dist x y = norm (x -ᵥ y) /-- The distance equals the norm of subtracting two points. In this lemma, it is necessary to have `V` as an explicit argument; otherwise `rw dist_eq_norm_vsub` sometimes doesn't work. -/ theorem dist_eq_norm_vsub (V : Type u_2) {P : Type u_3} [normed_group V] [metric_space P] [normed_add_torsor V P] (x : P) (y : P) : dist x y = norm (x -ᵥ y) := normed_add_torsor.dist_eq_norm' x y /-- A `normed_group` is a `normed_add_torsor` over itself. -/ protected instance normed_group.normed_add_torsor (V : Type u_2) [normed_group V] : normed_add_torsor V V := normed_add_torsor.mk dist_eq_norm @[simp] theorem dist_vadd_cancel_left {V : Type u_2} {P : Type u_3} [normed_group V] [metric_space P] [normed_add_torsor V P] (v : V) (x : P) (y : P) : dist (v +ᵥ x) (v +ᵥ y) = dist x y := sorry @[simp] theorem dist_vadd_cancel_right {V : Type u_2} {P : Type u_3} [normed_group V] [metric_space P] [normed_add_torsor V P] (v₁ : V) (v₂ : V) (x : P) : dist (v₁ +ᵥ x) (v₂ +ᵥ x) = dist v₁ v₂ := sorry @[simp] theorem dist_vadd_left {V : Type u_2} {P : Type u_3} [normed_group V] [metric_space P] [normed_add_torsor V P] (v : V) (x : P) : dist (v +ᵥ x) x = norm v := sorry @[simp] theorem dist_vadd_right {V : Type u_2} {P : Type u_3} [normed_group V] [metric_space P] [normed_add_torsor V P] (v : V) (x : P) : dist x (v +ᵥ x) = norm v := eq.mpr (id (Eq._oldrec (Eq.refl (dist x (v +ᵥ x) = norm v)) (dist_comm x (v +ᵥ x)))) (eq.mpr (id (Eq._oldrec (Eq.refl (dist (v +ᵥ x) x = norm v)) (dist_vadd_left v x))) (Eq.refl (norm v))) @[simp] theorem dist_vsub_cancel_left {V : Type u_2} {P : Type u_3} [normed_group V] [metric_space P] [normed_add_torsor V P] (x : P) (y : P) (z : P) : dist (x -ᵥ y) (x -ᵥ z) = dist y z := sorry @[simp] theorem dist_vsub_cancel_right {V : Type u_2} {P : Type u_3} [normed_group V] [metric_space P] [normed_add_torsor V P] (x : P) (y : P) (z : P) : dist (x -ᵥ z) (y -ᵥ z) = dist x y := eq.mpr (id (Eq._oldrec (Eq.refl (dist (x -ᵥ z) (y -ᵥ z) = dist x y)) (dist_eq_norm (x -ᵥ z) (y -ᵥ z)))) (eq.mpr (id (Eq._oldrec (Eq.refl (norm (x -ᵥ z - (y -ᵥ z)) = dist x y)) (vsub_sub_vsub_cancel_right x y z))) (eq.mpr (id (Eq._oldrec (Eq.refl (norm (x -ᵥ y) = dist x y)) (dist_eq_norm_vsub V x y))) (Eq.refl (norm (x -ᵥ y))))) theorem dist_vadd_vadd_le {V : Type u_2} {P : Type u_3} [normed_group V] [metric_space P] [normed_add_torsor V P] (v : V) (v' : V) (p : P) (p' : P) : dist (v +ᵥ p) (v' +ᵥ p') ≤ dist v v' + dist p p' := sorry theorem dist_vsub_vsub_le {V : Type u_2} {P : Type u_3} [normed_group V] [metric_space P] [normed_add_torsor V P] (p₁ : P) (p₂ : P) (p₃ : P) (p₄ : P) : dist (p₁ -ᵥ p₂) (p₃ -ᵥ p₄) ≤ dist p₁ p₃ + dist p₂ p₄ := sorry theorem nndist_vadd_vadd_le {V : Type u_2} {P : Type u_3} [normed_group V] [metric_space P] [normed_add_torsor V P] (v : V) (v' : V) (p : P) (p' : P) : nndist (v +ᵥ p) (v' +ᵥ p') ≤ nndist v v' + nndist p p' := sorry theorem nndist_vsub_vsub_le {V : Type u_2} {P : Type u_3} [normed_group V] [metric_space P] [normed_add_torsor V P] (p₁ : P) (p₂ : P) (p₃ : P) (p₄ : P) : nndist (p₁ -ᵥ p₂) (p₃ -ᵥ p₄) ≤ nndist p₁ p₃ + nndist p₂ p₄ := sorry theorem edist_vadd_vadd_le {V : Type u_2} {P : Type u_3} [normed_group V] [metric_space P] [normed_add_torsor V P] (v : V) (v' : V) (p : P) (p' : P) : edist (v +ᵥ p) (v' +ᵥ p') ≤ edist v v' + edist p p' := sorry theorem edist_vsub_vsub_le {V : Type u_2} {P : Type u_3} [normed_group V] [metric_space P] [normed_add_torsor V P] (p₁ : P) (p₂ : P) (p₃ : P) (p₄ : P) : edist (p₁ -ᵥ p₂) (p₃ -ᵥ p₄) ≤ edist p₁ p₃ + edist p₂ p₄ := sorry /-- The distance defines a metric space structure on the torsor. This is not an instance because it depends on `V` to define a `metric_space P`. -/ def metric_space_of_normed_group_of_add_torsor (V : Type u_1) (P : Type u_2) [normed_group V] [add_torsor V P] : metric_space P := metric_space.mk sorry sorry sorry sorry (fun (x y : P) => ennreal.of_real ((fun (x y : P) => norm (x -ᵥ y)) x y)) (uniform_space_of_dist (fun (x y : P) => norm (x -ᵥ y)) sorry sorry sorry) namespace isometric /-- The map `v ↦ v +ᵥ p` as an isometric equivalence between `V` and `P`. -/ def vadd_const {V : Type u_2} {P : Type u_3} [normed_group V] [metric_space P] [normed_add_torsor V P] (p : P) : V ≃ᵢ P := mk (equiv.vadd_const p) sorry @[simp] theorem coe_vadd_const {V : Type u_2} {P : Type u_3} [normed_group V] [metric_space P] [normed_add_torsor V P] (p : P) : ⇑(vadd_const p) = fun (v : V) => v +ᵥ p := rfl @[simp] theorem coe_vadd_const_symm {V : Type u_2} {P : Type u_3} [normed_group V] [metric_space P] [normed_add_torsor V P] (p : P) : ⇑(isometric.symm (vadd_const p)) = fun (p' : P) => p' -ᵥ p := rfl @[simp] theorem vadd_const_to_equiv {V : Type u_2} {P : Type u_3} [normed_group V] [metric_space P] [normed_add_torsor V P] (p : P) : to_equiv (vadd_const p) = equiv.vadd_const p := rfl /-- `p' ↦ p -ᵥ p'` as an equivalence. -/ def const_vsub {V : Type u_2} {P : Type u_3} [normed_group V] [metric_space P] [normed_add_torsor V P] (p : P) : P ≃ᵢ V := mk (equiv.const_vsub p) sorry @[simp] theorem coe_const_vsub {V : Type u_2} {P : Type u_3} [normed_group V] [metric_space P] [normed_add_torsor V P] (p : P) : ⇑(const_vsub p) = has_vsub.vsub p := rfl @[simp] theorem coe_const_vsub_symm {V : Type u_2} {P : Type u_3} [normed_group V] [metric_space P] [normed_add_torsor V P] (p : P) : ⇑(isometric.symm (const_vsub p)) = fun (v : V) => -v +ᵥ p := rfl /-- The map `p ↦ v +ᵥ p` as an isometric automorphism of `P`. -/ def const_vadd {V : Type u_2} (P : Type u_3) [normed_group V] [metric_space P] [normed_add_torsor V P] (v : V) : P ≃ᵢ P := mk (equiv.const_vadd P v) sorry @[simp] theorem coe_const_vadd {V : Type u_2} (P : Type u_3) [normed_group V] [metric_space P] [normed_add_torsor V P] (v : V) : ⇑(const_vadd P v) = has_vadd.vadd v := rfl @[simp] theorem const_vadd_zero (V : Type u_2) (P : Type u_3) [normed_group V] [metric_space P] [normed_add_torsor V P] : const_vadd P 0 = isometric.refl P := to_equiv_inj (equiv.const_vadd_zero V P) /-- Point reflection in `x` as an `isometric` homeomorphism. -/ def point_reflection {V : Type u_2} {P : Type u_3} [normed_group V] [metric_space P] [normed_add_torsor V P] (x : P) : P ≃ᵢ P := isometric.trans (const_vsub x) (vadd_const x) theorem point_reflection_apply {V : Type u_2} {P : Type u_3} [normed_group V] [metric_space P] [normed_add_torsor V P] (x : P) (y : P) : coe_fn (point_reflection x) y = x -ᵥ y +ᵥ x := rfl @[simp] theorem point_reflection_to_equiv {V : Type u_2} {P : Type u_3} [normed_group V] [metric_space P] [normed_add_torsor V P] (x : P) : to_equiv (point_reflection x) = equiv.point_reflection x := rfl @[simp] theorem point_reflection_self {V : Type u_2} {P : Type u_3} [normed_group V] [metric_space P] [normed_add_torsor V P] (x : P) : coe_fn (point_reflection x) x = x := equiv.point_reflection_self x theorem point_reflection_involutive {V : Type u_2} {P : Type u_3} [normed_group V] [metric_space P] [normed_add_torsor V P] (x : P) : function.involutive ⇑(point_reflection x) := equiv.point_reflection_involutive x @[simp] theorem point_reflection_symm {V : Type u_2} {P : Type u_3} [normed_group V] [metric_space P] [normed_add_torsor V P] (x : P) : isometric.symm (point_reflection x) = point_reflection x := to_equiv_inj (equiv.point_reflection_symm x) @[simp] theorem dist_point_reflection_fixed {V : Type u_2} {P : Type u_3} [normed_group V] [metric_space P] [normed_add_torsor V P] (x : P) (y : P) : dist (coe_fn (point_reflection x) y) x = dist y x := sorry theorem dist_point_reflection_self' {V : Type u_2} {P : Type u_3} [normed_group V] [metric_space P] [normed_add_torsor V P] (x : P) (y : P) : dist (coe_fn (point_reflection x) y) y = norm (bit0 (x -ᵥ y)) := sorry theorem dist_point_reflection_self {V : Type u_2} {P : Type u_3} [normed_group V] [metric_space P] [normed_add_torsor V P] (𝕜 : Type u_1) [normed_field 𝕜] [normed_space 𝕜 V] (x : P) (y : P) : dist (coe_fn (point_reflection x) y) y = norm (bit0 1) * dist x y := sorry theorem point_reflection_fixed_iff {V : Type u_2} {P : Type u_3} [normed_group V] [metric_space P] [normed_add_torsor V P] (𝕜 : Type u_1) [normed_field 𝕜] [normed_space 𝕜 V] [invertible (bit0 1)] {x : P} {y : P} : coe_fn (point_reflection x) y = y ↔ y = x := affine_equiv.point_reflection_fixed_iff_of_module 𝕜 theorem dist_point_reflection_self_real {V : Type u_2} {P : Type u_3} [normed_group V] [metric_space P] [normed_add_torsor V P] [normed_space ℝ V] (x : P) (y : P) : dist (coe_fn (point_reflection x) y) y = bit0 1 * dist x y := sorry @[simp] theorem point_reflection_midpoint_left {V : Type u_2} {P : Type u_3} [normed_group V] [metric_space P] [normed_add_torsor V P] [normed_space ℝ V] (x : P) (y : P) : coe_fn (point_reflection (midpoint ℝ x y)) x = y := affine_equiv.point_reflection_midpoint_left x y @[simp] theorem point_reflection_midpoint_right {V : Type u_2} {P : Type u_3} [normed_group V] [metric_space P] [normed_add_torsor V P] [normed_space ℝ V] (x : P) (y : P) : coe_fn (point_reflection (midpoint ℝ x y)) y = x := affine_equiv.point_reflection_midpoint_right x y end isometric theorem lipschitz_with.vadd {α : Type u_1} {V : Type u_2} {P : Type u_3} [normed_group V] [metric_space P] [normed_add_torsor V P] [emetric_space α] {f : α → V} {g : α → P} {Kf : nnreal} {Kg : nnreal} (hf : lipschitz_with Kf f) (hg : lipschitz_with Kg g) : lipschitz_with (Kf + Kg) (f +ᵥ g) := fun (x y : α) => trans_rel_left LessEq (le_trans (edist_vadd_vadd_le (f x) (f y) (g x) (g y)) (add_le_add (hf x y) (hg x y))) (Eq.symm (add_mul (↑Kf) (↑Kg) (edist x y))) theorem lipschitz_with.vsub {α : Type u_1} {V : Type u_2} {P : Type u_3} [normed_group V] [metric_space P] [normed_add_torsor V P] [emetric_space α] {f : α → P} {g : α → P} {Kf : nnreal} {Kg : nnreal} (hf : lipschitz_with Kf f) (hg : lipschitz_with Kg g) : lipschitz_with (Kf + Kg) (f -ᵥ g) := fun (x y : α) => trans_rel_left LessEq (le_trans (edist_vsub_vsub_le (f x) (g x) (f y) (g y)) (add_le_add (hf x y) (hg x y))) (Eq.symm (add_mul (↑Kf) (↑Kg) (edist x y))) theorem uniform_continuous_vadd {V : Type u_2} {P : Type u_3} [normed_group V] [metric_space P] [normed_add_torsor V P] : uniform_continuous fun (x : V × P) => prod.fst x +ᵥ prod.snd x := lipschitz_with.uniform_continuous (lipschitz_with.vadd lipschitz_with.prod_fst lipschitz_with.prod_snd) theorem uniform_continuous_vsub {V : Type u_2} {P : Type u_3} [normed_group V] [metric_space P] [normed_add_torsor V P] : uniform_continuous fun (x : P × P) => prod.fst x -ᵥ prod.snd x := lipschitz_with.uniform_continuous (lipschitz_with.vsub lipschitz_with.prod_fst lipschitz_with.prod_snd) theorem continuous_vadd {V : Type u_2} {P : Type u_3} [normed_group V] [metric_space P] [normed_add_torsor V P] : continuous fun (x : V × P) => prod.fst x +ᵥ prod.snd x := uniform_continuous.continuous uniform_continuous_vadd theorem continuous_vsub {V : Type u_2} {P : Type u_3} [normed_group V] [metric_space P] [normed_add_torsor V P] : continuous fun (x : P × P) => prod.fst x -ᵥ prod.snd x := uniform_continuous.continuous uniform_continuous_vsub theorem filter.tendsto.vadd {α : Type u_1} {V : Type u_2} {P : Type u_3} [normed_group V] [metric_space P] [normed_add_torsor V P] {l : filter α} {f : α → V} {g : α → P} {v : V} {p : P} (hf : filter.tendsto f l (nhds v)) (hg : filter.tendsto g l (nhds p)) : filter.tendsto (f +ᵥ g) l (nhds (v +ᵥ p)) := filter.tendsto.comp (continuous.tendsto continuous_vadd (v, p)) (filter.tendsto.prod_mk_nhds hf hg) theorem filter.tendsto.vsub {α : Type u_1} {V : Type u_2} {P : Type u_3} [normed_group V] [metric_space P] [normed_add_torsor V P] {l : filter α} {f : α → P} {g : α → P} {x : P} {y : P} (hf : filter.tendsto f l (nhds x)) (hg : filter.tendsto g l (nhds y)) : filter.tendsto (f -ᵥ g) l (nhds (x -ᵥ y)) := filter.tendsto.comp (continuous.tendsto continuous_vsub (x, y)) (filter.tendsto.prod_mk_nhds hf hg) theorem continuous.vadd {α : Type u_1} {V : Type u_2} {P : Type u_3} [normed_group V] [metric_space P] [normed_add_torsor V P] [topological_space α] {f : α → V} {g : α → P} (hf : continuous f) (hg : continuous g) : continuous (f +ᵥ g) := continuous.comp continuous_vadd (continuous.prod_mk hf hg) theorem continuous.vsub {α : Type u_1} {V : Type u_2} {P : Type u_3} [normed_group V] [metric_space P] [normed_add_torsor V P] [topological_space α] {f : α → P} {g : α → P} (hf : continuous f) (hg : continuous g) : continuous (f -ᵥ g) := continuous.comp continuous_vsub (continuous.prod_mk hf hg) theorem continuous_at.vadd {α : Type u_1} {V : Type u_2} {P : Type u_3} [normed_group V] [metric_space P] [normed_add_torsor V P] [topological_space α] {f : α → V} {g : α → P} {x : α} (hf : continuous_at f x) (hg : continuous_at g x) : continuous_at (f +ᵥ g) x := filter.tendsto.vadd hf hg theorem continuous_at.vsub {α : Type u_1} {V : Type u_2} {P : Type u_3} [normed_group V] [metric_space P] [normed_add_torsor V P] [topological_space α] {f : α → P} {g : α → P} {x : α} (hf : continuous_at f x) (hg : continuous_at g x) : continuous_at (f -ᵥ g) x := filter.tendsto.vsub hf hg theorem continuous_within_at.vadd {α : Type u_1} {V : Type u_2} {P : Type u_3} [normed_group V] [metric_space P] [normed_add_torsor V P] [topological_space α] {f : α → V} {g : α → P} {x : α} {s : set α} (hf : continuous_within_at f s x) (hg : continuous_within_at g s x) : continuous_within_at (f +ᵥ g) s x := filter.tendsto.vadd hf hg theorem continuous_within_at.vsub {α : Type u_1} {V : Type u_2} {P : Type u_3} [normed_group V] [metric_space P] [normed_add_torsor V P] [topological_space α] {f : α → P} {g : α → P} {x : α} {s : set α} (hf : continuous_within_at f s x) (hg : continuous_within_at g s x) : continuous_within_at (f -ᵥ g) s x := filter.tendsto.vsub hf hg /-- The map `g` from `V1` to `V2` corresponding to a map `f` from `P1` to `P2`, at a base point `p`, is an isometry if `f` is one. -/ theorem isometry.vadd_vsub {V : Type u_2} {P : Type u_3} [normed_group V] [metric_space P] [normed_add_torsor V P] {V' : Type u_4} {P' : Type u_5} [normed_group V'] [metric_space P'] [normed_add_torsor V' P'] {f : P → P'} (hf : isometry f) {p : P} {g : V → V'} (hg : ∀ (v : V), g v = f (v +ᵥ p) -ᵥ f p) : isometry g := sorry /-- If `f` is an affine map, then its linear part is continuous iff `f` is continuous. -/ theorem affine_map.continuous_linear_iff {V : Type u_2} {P : Type u_3} [normed_group V] [metric_space P] [normed_add_torsor V P] {V' : Type u_4} {P' : Type u_5} [normed_group V'] [metric_space P'] [normed_add_torsor V' P'] {𝕜 : Type u_6} [normed_field 𝕜] [normed_space 𝕜 V] [normed_space 𝕜 V'] {f : affine_map 𝕜 P P'} : continuous ⇑(affine_map.linear f) ↔ continuous ⇑f := sorry @[simp] theorem dist_center_homothety {V : Type u_2} {P : Type u_3} [normed_group V] [metric_space P] [normed_add_torsor V P] {𝕜 : Type u_6} [normed_field 𝕜] [normed_space 𝕜 V] (p₁ : P) (p₂ : P) (c : 𝕜) : dist p₁ (coe_fn (affine_map.homothety p₁ c) p₂) = norm c * dist p₁ p₂ := sorry @[simp] theorem dist_homothety_center {V : Type u_2} {P : Type u_3} [normed_group V] [metric_space P] [normed_add_torsor V P] {𝕜 : Type u_6} [normed_field 𝕜] [normed_space 𝕜 V] (p₁ : P) (p₂ : P) (c : 𝕜) : dist (coe_fn (affine_map.homothety p₁ c) p₂) p₁ = norm c * dist p₁ p₂ := sorry @[simp] theorem dist_homothety_self {V : Type u_2} {P : Type u_3} [normed_group V] [metric_space P] [normed_add_torsor V P] {𝕜 : Type u_6} [normed_field 𝕜] [normed_space 𝕜 V] (p₁ : P) (p₂ : P) (c : 𝕜) : dist (coe_fn (affine_map.homothety p₁ c) p₂) p₂ = norm (1 - c) * dist p₁ p₂ := sorry @[simp] theorem dist_self_homothety {V : Type u_2} {P : Type u_3} [normed_group V] [metric_space P] [normed_add_torsor V P] {𝕜 : Type u_6} [normed_field 𝕜] [normed_space 𝕜 V] (p₁ : P) (p₂ : P) (c : 𝕜) : dist p₂ (coe_fn (affine_map.homothety p₁ c) p₂) = norm (1 - c) * dist p₁ p₂ := sorry @[simp] theorem dist_left_midpoint {V : Type u_2} {P : Type u_3} [normed_group V] [metric_space P] [normed_add_torsor V P] {𝕜 : Type u_6} [normed_field 𝕜] [normed_space 𝕜 V] [invertible (bit0 1)] (p₁ : P) (p₂ : P) : dist p₁ (midpoint 𝕜 p₁ p₂) = norm (bit0 1)⁻¹ * dist p₁ p₂ := sorry @[simp] theorem dist_midpoint_left {V : Type u_2} {P : Type u_3} [normed_group V] [metric_space P] [normed_add_torsor V P] {𝕜 : Type u_6} [normed_field 𝕜] [normed_space 𝕜 V] [invertible (bit0 1)] (p₁ : P) (p₂ : P) : dist (midpoint 𝕜 p₁ p₂) p₁ = norm (bit0 1)⁻¹ * dist p₁ p₂ := sorry @[simp] theorem dist_midpoint_right {V : Type u_2} {P : Type u_3} [normed_group V] [metric_space P] [normed_add_torsor V P] {𝕜 : Type u_6} [normed_field 𝕜] [normed_space 𝕜 V] [invertible (bit0 1)] (p₁ : P) (p₂ : P) : dist (midpoint 𝕜 p₁ p₂) p₂ = norm (bit0 1)⁻¹ * dist p₁ p₂ := sorry @[simp] theorem dist_right_midpoint {V : Type u_2} {P : Type u_3} [normed_group V] [metric_space P] [normed_add_torsor V P] {𝕜 : Type u_6} [normed_field 𝕜] [normed_space 𝕜 V] [invertible (bit0 1)] (p₁ : P) (p₂ : P) : dist p₂ (midpoint 𝕜 p₁ p₂) = norm (bit0 1)⁻¹ * dist p₁ p₂ := sorry /-- A continuous map between two normed affine spaces is an affine map provided that it sends midpoints to midpoints. -/ def affine_map.of_map_midpoint {V : Type u_2} {P : Type u_3} [normed_group V] [metric_space P] [normed_add_torsor V P] {V' : Type u_4} {P' : Type u_5} [normed_group V'] [metric_space P'] [normed_add_torsor V' P'] [normed_space ℝ V] [normed_space ℝ V'] (f : P → P') (h : ∀ (x y : P), f (midpoint ℝ x y) = midpoint ℝ (f x) (f y)) (hfc : continuous f) : affine_map ℝ P P' := affine_map.mk' f (↑(add_monoid_hom.to_real_linear_map (add_monoid_hom.of_map_midpoint ℝ ℝ (⇑(affine_equiv.symm (affine_equiv.vadd_const ℝ (f (classical.arbitrary P)))) ∘ f ∘ ⇑(affine_equiv.vadd_const ℝ (classical.arbitrary P))) sorry sorry) sorry)) (classical.arbitrary P) sorry end Mathlib
subroutine froutine() implicit none print *, 'in froutine()' end
lemma primitive_part_0 [simp]: "primitive_part 0 = 0"
import tactic data.rat open_locale big_operators open finset theorem sqrt2' : ¬ (∃ m n : ℕ, m ≠ 0 ∧ 2 * m^2 = n ^2) := begin sorry, end theorem sqrt2 : ¬ (∃ m n : ℤ, m ≠ 0 ∧ 2 * m^2 = n ^2) := begin by_contradiction, apply sqrt2', rcases a with ⟨m,n,hm, hmn⟩, use [m.nat_abs, n.nat_abs], split, exact int.nat_abs_ne_zero_of_ne_zero hm, have m1 := int.nat_abs_pow_two m, have n1 := int.nat_abs_pow_two n, rw ←m1 at hmn, rw ←n1 at hmn, norm_cast at hmn, exact hmn, end lemma temp (n : ℤ) : n * n = n^2 := begin ring, end example : ¬ (∃ q : ℚ, 2 = q * q) := begin by_contradiction, cases a with q key, have := rat.eq_iff_mul_eq_mul.mp key, have triv : (2:ℚ).denom = 1, refl, rw triv at this, have triv : (2:ℚ).num = 2, refl, rw triv at this, rw rat.mul_self_denom at this, rw rat.mul_self_num at this, simp only [mul_one, int.coe_nat_zero, int.coe_nat_succ, zero_add, int.coe_nat_mul] at this, rw temp at this, rw temp at this, apply sqrt2, use q.denom, use q.num, split, norm_cast, exact rat.denom_ne_zero q, exact this, -- have : 2 * (↑(q.denom) ^2) = q.num ^2, rw ←temp, end example (p q : rat) : q.denom ≠ 0 := begin exact rat.denom_ne_zero q end example (m : int ) : m ^ 2 = (m.nat_abs)^2 := begin exact (int.nat_abs_pow_two m).symm, end
Goal ((forall (t : Type) (x y : t), True -> x = y)) -> False. Proof. intro HG. let P := lazymatch goal with | [ H : forall t x y, True -> @?P t x y |- _ ] => P end in pose (f := P). unify f (fun (t : Type) (x y : t) => x = y). Abort. Goal True. Proof. let c := lazymatch constr:(fun (T : nat -> Type) (y : nat) (_ : T y) => y) with | fun _ y _ => @?C y => C end in pose (f := c). unify f (fun n : nat => n). Abort. Goal (forall x : nat, x = x -> x = x \/ x = x) -> True. Proof. intro. let P := lazymatch goal with | [ H : forall y, @?P y -> @?P y \/ _ |- _ ] => P end in pose (f := P). unify f (fun x : nat => x = x). Abort. Goal (forall x : nat, x = x -> x = x \/ x = x) -> True. Proof. intro. lazymatch goal with | [ H : forall y, @?P y -> @?Q y \/ _ |- _ ] => idtac end. Abort. Axiom eq : forall {T} (_ : T), Prop. Goal forall _ : (forall t (_ : eq t) (x : t), eq x), Prop. Proof. intro. let P := lazymatch goal with | [ H : forall t _ x, @?P t x |- _ ] => P end in pose (f := P). Abort.
lemmas lipschitz_on_subset = lipschitz_on_mono[OF _ _ order_refl] and lipschitz_on_le = lipschitz_on_mono[OF _ order_refl]
lemma fold_coeffs_pCons_0_0_eq [simp]: "fold_coeffs f (pCons 0 0) = id"
module DeprecationBotTest if VERSION >= v"0.1" print("Hello") else print("World") end end # module
function compute(first::Int, modulo::Int)::Int min_value = max_value = result = first candidate = 0 while candidate ≠ 1 candidate = (min_value + max_value) % modulo if candidate > max_value max_value = candidate elseif candidate < min_value min_value = candidate result += candidate end end return result end
program array_init_test implicit none integer, parameter :: m = 4, n = 5, p = m*n/2 integer :: i, j integer, dimension(m, n) :: a = reshape( [ (i, i = 1, m*n) ], [m, n]) real, dimension(m, n) :: b integer, dimension(p) :: c character(len=10) :: fmt_str print '(A)', '# initialized at declaration' write (fmt_str, '(A, I1, A)') '(', n, 'I3)' do i = 1, size(a, 1) print fmt_str, a(i, :) end do print '(A)', '# initialized in program' b = reshape([ ((1.0/(i*n + j), i = 1, m), j=1, n) ], [m, n]) write (fmt_str, '(A, I1, A)') '(', n, 'F7.3)' do i = 1, size(b, 1) print fmt_str, b(i, :) end do print '(A)', '# transposed and reshaped' c = reshape(transpose(a(2:3, :)), [p]) write (fmt_str, '(A, I2, A)') '(', p, 'I3)' print fmt_str, c(:) end program array_init_test
\subsection{Group action} We have a group \(G\) and a set \(S\). We have a function \(g.s\) which maps onto \(S\) such that: \begin{itemize} \item \(I.s=s\) \item \((gh).s=g(h.s)\) \end{itemize}
section {*FUNCTION\_\_LR\_PARSER\_\_part4*} theory FUNCTION__LR_PARSER__part4 imports FUNCTION__LR_PARSER__part3 begin lemma no_shift_shift_conflicts1: " AF_LR_PARSER_input G F Do S' G' M P k \<Longrightarrow> y \<in> cfgSTD_first G' (k - Suc 0) (\<beta> @ liftB z) \<Longrightarrow> ya \<in> cfgSTD_first G' (k - Suc 0) (\<beta>' @ liftB za) \<Longrightarrow> \<lparr>prod_lhs = A, prod_rhs = \<alpha> @ teB aa # \<beta>\<rparr> \<in> cfg_productions G \<Longrightarrow> \<lparr>prod_lhs = Aa, prod_rhs = \<alpha>' @ teB aa # \<beta>'\<rparr> \<in> cfg_productions G \<Longrightarrow> \<lparr>cfg_item_lhs = A, cfg_item_rhs1 = \<alpha>, cfg_item_rhs2 = teB aa # \<beta>, cfg_item_look_ahead = z\<rparr> \<in> valid_item_set G' k (teB Do # \<delta>) \<Longrightarrow> \<lparr>cfg_item_lhs = Aa, cfg_item_rhs1 = \<alpha>', cfg_item_rhs2 = teB aa # \<beta>', cfg_item_look_ahead = za\<rparr> \<in> valid_item_set G' k (teB Do # \<delta>') \<Longrightarrow> last (F_DFA_GOTO_SEQUENCE M (epda_initial M) (teB Do # \<delta>')) = last (F_DFA_GOTO_SEQUENCE M (epda_initial M) (teB Do # \<delta>)) \<Longrightarrow> (aa # y) \<sqsubseteq> (aa # ya) \<Longrightarrow> y = ya" apply(simp add: prefix_def) apply(clarsimp) apply(rename_tac c)(*strict*) apply(subgoal_tac "valid_cfg G'") apply(rename_tac c)(*strict*) prefer 2 apply(rule F_CFG_AUGMENT__makes_CFG) apply(simp add: F_CFG_AUGMENT__input_def AF_LR_PARSER_input_def) apply(force) apply(rename_tac c)(*strict*) apply(subgoal_tac "valid_dfa M") apply(rename_tac c)(*strict*) prefer 2 apply(rule_tac G="G'" in Theorem6__27_a) apply(rename_tac c)(*strict*) apply(force) apply(rename_tac c)(*strict*) apply(simp add: F_CFG_AUGMENT__input_def AF_LR_PARSER_input_def) apply(force) apply(simp add: F_CFG_AUGMENT__input_def AF_LR_PARSER_input_def) apply(rename_tac c)(*strict*) apply(subgoal_tac "some_step_from_every_configuration M") apply(rename_tac c)(*strict*) prefer 2 apply(rule_tac G="G'" in F_LR_MACHINE_Complete) apply(rename_tac c)(*strict*) apply(force) apply(simp add: F_CFG_AUGMENT__input_def AF_LR_PARSER_input_def) apply(force) apply(rename_tac c)(*strict*) apply(simp add: F_CFG_AUGMENT__input_def AF_LR_PARSER_input_def) apply(rename_tac c)(*strict*) apply(subgoal_tac "every_state_in_some_accessible_configuration M") apply(rename_tac c)(*strict*) prefer 2 apply(rule F_LR_MACHINE_all_Connected) apply(rename_tac c)(*strict*) prefer 2 apply(simp add: F_CFG_AUGMENT__input_def AF_LR_PARSER_input_def) apply(force) apply(rename_tac c)(*strict*) apply(simp add: F_CFG_AUGMENT__input_def AF_LR_PARSER_input_def) apply(simp add: F_CFG_AUGMENT__input_def AF_LR_PARSER_input_def) apply(force) apply(rename_tac c)(*strict*) apply(subgoal_tac "some_step_from_every_configuration M") apply(rename_tac c)(*strict*) prefer 2 apply(rule_tac G="G'" in F_LR_MACHINE_Complete) apply(rename_tac c)(*strict*) apply(blast)+ apply(simp add: F_CFG_AUGMENT__input_def AF_LR_PARSER_input_def) apply(force) apply(rename_tac c)(*strict*) apply(simp add: F_CFG_AUGMENT__input_def AF_LR_PARSER_input_def) apply(rename_tac c)(*strict*) apply(subgoal_tac "valid_parser P") apply(rename_tac c)(*strict*) prefer 2 apply(rule_tac G="G" in AF_LR_PARSER_valid_parser) apply(rename_tac c)(*strict*) apply(simp add: AF_LR_PARSER_input_def) apply(simp add: F_CFG_AUGMENT__input_def AF_LR_PARSER_input_def) apply(force) apply(rename_tac c)(*strict*) apply(force) apply(rename_tac c)(*strict*) apply(force) apply(rename_tac c)(*strict*) apply(force) apply(rename_tac c)(*strict*) apply(force) apply(rename_tac c)(*strict*) apply(simp add: AF_LR_PARSER_input_def) apply(rename_tac c)(*strict*) apply(subgoal_tac "set (teB Do # \<delta>') \<subseteq> two_elements_construct_domain (cfg_nonterminals G') (cfg_events G')") apply(rename_tac c)(*strict*) prefer 2 apply(rule viable_prefix_in_CFG) apply(rename_tac c)(*strict*) apply(simp add: AF_LR_PARSER_input_def) apply(rename_tac c)(*strict*) apply(rule Fact6_12__1) apply(force) apply(rename_tac c)(*strict*) apply(subgoal_tac "set (teB Do # \<delta>) \<subseteq> two_elements_construct_domain (cfg_nonterminals G') (cfg_events G')") apply(rename_tac c)(*strict*) prefer 2 apply(rule viable_prefix_in_CFG) apply(rename_tac c)(*strict*) apply(simp add: AF_LR_PARSER_input_def) apply(rename_tac c)(*strict*) apply(rule Fact6_12__1) apply(force) apply(rename_tac c)(*strict*) apply(subgoal_tac "\<lparr>cfg_item_lhs = A, cfg_item_rhs1 = \<alpha>, cfg_item_rhs2 = teB aa # \<beta>, cfg_item_look_ahead = z\<rparr> \<in> valid_item_set G' k (teB Do # \<delta>')") apply(rename_tac c)(*strict*) prefer 2 apply(subgoal_tac "valid_item_set G' k (teB Do # \<delta>') = (if (teB Do # \<delta>')=[] then (epda_initial M) else last (F_DFA_GOTO_SEQUENCE M (epda_initial M) (teB Do # \<delta>')))") apply(rename_tac c)(*strict*) prefer 2 apply(rule F_LR_MACHINE_all_SOUND) apply(rename_tac c)(*strict*) apply(simp add: AF_LR_PARSER_input_def) apply(rename_tac c)(*strict*) apply(simp add: AF_LR_PARSER_input_def) apply(force) apply(simp add: AF_LR_PARSER_input_def) apply(force) apply(rename_tac c)(*strict*) apply(simp add: AF_LR_PARSER_input_def) apply(rename_tac c)(*strict*) apply(simp add: AF_LR_PARSER_input_def) apply(rename_tac c)(*strict*) prefer 2 apply (metis two_elements_construct_domain_setB) apply(rename_tac c)(*strict*) apply (metis two_elements_construct_domain_setA) apply(rename_tac c)(*strict*) apply(subgoal_tac "valid_item_set G' k (teB Do # \<delta>) = (if (teB Do # \<delta>)=[] then (epda_initial M) else last (F_DFA_GOTO_SEQUENCE M (epda_initial M) (teB Do # \<delta>)))") apply(rename_tac c)(*strict*) prefer 2 apply(rule F_LR_MACHINE_all_SOUND) apply(rename_tac c)(*strict*) apply(simp add: AF_LR_PARSER_input_def) apply(simp add: AF_LR_PARSER_input_def) apply(force) apply(rename_tac c)(*strict*) apply(simp add: AF_LR_PARSER_input_def) apply(rename_tac c)(*strict*) apply(simp add: AF_LR_PARSER_input_def) apply(rename_tac c)(*strict*) apply(simp add: AF_LR_PARSER_input_def) apply(rename_tac c)(*strict*) prefer 2 apply (metis two_elements_construct_domain_setB) apply(rename_tac c)(*strict*) apply (metis two_elements_construct_domain_setA) apply(rename_tac c)(*strict*) apply(force) apply(rename_tac c)(*strict*) apply(thin_tac "last (F_DFA_GOTO_SEQUENCE M (epda_initial M) (teB Do # \<delta>')) = last (F_DFA_GOTO_SEQUENCE M (epda_initial M) (teB Do # \<delta>))") apply(rename_tac c)(*strict*) apply(thin_tac "\<lparr>cfg_item_lhs = A, cfg_item_rhs1 = \<alpha>, cfg_item_rhs2 = teB aa # \<beta>, cfg_item_look_ahead = z\<rparr> \<in> valid_item_set G' k (teB Do # \<delta>)") apply(rename_tac c)(*strict*) apply(thin_tac "set (teB Do # \<delta>) \<subseteq> two_elements_construct_domain (cfg_nonterminals G') (cfg_events G')") apply(subgoal_tac "length y \<le> (k-Suc 0)") apply(rename_tac c)(*strict*) prefer 2 apply(rule cfgSTD_firstk_shorter_than_k) apply(force) apply(rename_tac c)(*strict*) apply(subgoal_tac "length (y@c) \<le> (k-Suc 0)") apply(rename_tac c)(*strict*) prefer 2 apply(rule cfgSTD_firstk_shorter_than_k) apply(force) apply(rename_tac c)(*strict*) apply(case_tac "length y < k - Suc 0") apply(rename_tac c)(*strict*) prefer 2 apply(clarsimp) apply(rename_tac c)(*strict*) apply(subgoal_tac "suffix y z") apply(rename_tac c)(*strict*) prefer 2 apply(rule cfgSTD_first_suffix_is_shorter) apply(rename_tac c)(*strict*) apply(force) apply(rename_tac c)(*strict*) apply(force) apply(rename_tac c)(*strict*) apply(force) apply(rename_tac c)(*strict*) apply(subgoal_tac "length z < k - Suc 0") apply(rename_tac c)(*strict*) prefer 2 apply(simp add: suffix_def) apply(clarsimp) apply(rename_tac c)(*strict*) apply(simp add: valid_item_set_def valid_item_set_n_def) apply(clarsimp) apply(rename_tac c n na d da \<delta> e1 e2 zb \<delta>'a e1a e2a zaa)(*strict*) apply(subgoal_tac "d (Suc 0)= Some (pair (Some \<lparr>prod_lhs=cfg_initial G',prod_rhs=[teB Do,teA (cfg_initial G),teB Do]\<rparr>) \<lparr>cfg_conf=[teB Do,teA (cfg_initial G),teB Do]\<rparr>)") apply(rename_tac c n na d da \<delta> e1 e2 zb \<delta>'a e1a e2a zaa)(*strict*) prefer 2 apply(rule F_CFG_AUGMENT__FirstStep) apply(rename_tac c n na d da \<delta> e1 e2 zb \<delta>'a e1a e2a zaa)(*strict*) apply(simp add: AF_LR_PARSER_input_def) apply(rename_tac c n na d da \<delta> e1 e2 zb \<delta>'a e1a e2a zaa)(*strict*) apply(simp add: AF_LR_PARSER_input_def) apply(rename_tac c n na d da \<delta> e1 e2 zb \<delta>'a e1a e2a zaa)(*strict*) apply(simp add: AF_LR_PARSER_input_def) apply(rename_tac c n na d da \<delta> e1 e2 zb \<delta>'a e1a e2a zaa)(*strict*) apply(simp add: AF_LR_PARSER_input_def) apply(rename_tac c n na d da \<delta> e1 e2 zb \<delta>'a e1a e2a zaa)(*strict*) apply(force) apply(rename_tac c n na d da \<delta> e1 e2 zb \<delta>'a e1a e2a zaa)(*strict*) apply (metis cfgRM_derivations_are_cfg_derivations) apply(rename_tac c n na d da \<delta> e1 e2 zb \<delta>'a e1a e2a zaa)(*strict*) apply(force) apply(rename_tac c n na d da \<delta> e1 e2 zb \<delta>'a e1a e2a zaa)(*strict*) apply(force) apply(rename_tac c n na d da \<delta> e1 e2 zb \<delta>'a e1a e2a zaa)(*strict*) apply(subgoal_tac "da (Suc 0)= Some (pair (Some \<lparr>prod_lhs=cfg_initial G',prod_rhs=[teB Do,teA (cfg_initial G),teB Do]\<rparr>) \<lparr>cfg_conf=[teB Do,teA (cfg_initial G),teB Do]\<rparr>)") apply(rename_tac c n na d da \<delta> e1 e2 zb \<delta>'a e1a e2a zaa)(*strict*) prefer 2 apply(rule F_CFG_AUGMENT__FirstStep) apply(rename_tac c n na d da \<delta> e1 e2 zb \<delta>'a e1a e2a zaa)(*strict*) apply(simp add: AF_LR_PARSER_input_def) apply(rename_tac c n na d da \<delta> e1 e2 zb \<delta>'a e1a e2a zaa)(*strict*) apply(simp add: AF_LR_PARSER_input_def) apply(rename_tac c n na d da \<delta> e1 e2 zb \<delta>'a e1a e2a zaa)(*strict*) apply(simp add: AF_LR_PARSER_input_def) apply(rename_tac c n na d da \<delta> e1 e2 zb \<delta>'a e1a e2a zaa)(*strict*) apply(simp add: AF_LR_PARSER_input_def) apply(rename_tac c n na d da \<delta> e1 e2 zb \<delta>'a e1a e2a zaa)(*strict*) apply(force) apply(rename_tac c n na d da \<delta> e1 e2 zb \<delta>'a e1a e2a zaa)(*strict*) apply (metis cfgRM_derivations_are_cfg_derivations) apply(rename_tac c n na d da \<delta> e1 e2 zb \<delta>'a e1a e2a zaa)(*strict*) apply(force) apply(rename_tac c n na d da \<delta> e1 e2 zb \<delta>'a e1a e2a zaa)(*strict*) apply(force) apply(rename_tac c n na d da \<delta> e1 e2 zb \<delta>'a e1a e2a zaa)(*strict*) apply(subgoal_tac "aa \<noteq> Do") apply(rename_tac c n na d da \<delta> e1 e2 zb \<delta>'a e1a e2a zaa)(*strict*) prefer 2 apply(subgoal_tac "aa \<in> cfg_events G") apply(rename_tac c n na d da \<delta> e1 e2 zb \<delta>'a e1a e2a zaa)(*strict*) apply(subgoal_tac "Do \<notin> cfg_events G") apply(rename_tac c n na d da \<delta> e1 e2 zb \<delta>'a e1a e2a zaa)(*strict*) apply(force) apply(rename_tac c n na d da \<delta> e1 e2 zb \<delta>'a e1a e2a zaa)(*strict*) apply(simp add: AF_LR_PARSER_input_def F_CFG_AUGMENT_def) apply(clarsimp) apply(subgoal_tac "F_FRESH (cfg_events G) \<notin> cfg_events G") apply(rename_tac c n na d da \<delta> e1 e2 zb \<delta>'a e1a e2a zaa)(*strict*) apply(force) apply(rename_tac c n na d da \<delta> e1 e2 zb \<delta>'a e1a e2a zaa)(*strict*) apply(rule F_FRESH_is_fresh) apply(simp add: AF_LR_PARSER_def AF_LR_PARSER_input_def valid_cfg_def) apply(rename_tac c n na d da \<delta> e1 e2 zb \<delta>'a e1a e2a zaa)(*strict*) apply(simp add: AF_LR_PARSER_input_def valid_cfg_def) apply(erule conjE)+ apply(erule_tac x="\<lparr>prod_lhs = A, prod_rhs = \<alpha> @ teB aa # \<beta>\<rparr>" and A="cfg_productions G" in ballE) apply(rename_tac c n na d da \<delta> e1 e2 zb \<delta>'a e1a e2a zaa)(*strict*) prefer 2 apply(force) apply(rename_tac c n na d da \<delta> e1 e2 zb \<delta>'a e1a e2a zaa)(*strict*) apply(clarsimp) apply (metis elemInsetB set_mp_prime) apply(rename_tac c n na d da \<delta> e1 e2 zb \<delta>'a e1a e2a zaa)(*strict*) apply(case_tac n) apply(rename_tac c n na d da \<delta> e1 e2 zb \<delta>'a e1a e2a zaa)(*strict*) apply(clarsimp) apply(rename_tac c na d da \<delta> zb \<delta>'a e1a e2a zaa)(*strict*) apply(case_tac "\<delta>") apply(rename_tac c na d da \<delta> zb \<delta>'a e1a e2a zaa)(*strict*) apply(clarsimp) apply(rename_tac c na d da \<delta>'a e1a e2a zaa)(*strict*) apply(case_tac "\<delta>'a") apply(rename_tac c na d da \<delta>'a e1a e2a zaa)(*strict*) apply(clarsimp) apply(rename_tac c na d da e1a e2a zaa)(*strict*) apply(case_tac "\<delta>'") apply(rename_tac c na d da e1a e2a zaa)(*strict*) apply(clarsimp) apply(rename_tac c na d da e1a e2a zaa a list)(*strict*) apply(clarsimp) apply(rename_tac c na d da e1a e2a zaa list)(*strict*) apply(case_tac list) apply(rename_tac c na d da e1a e2a zaa list)(*strict*) apply(clarsimp) apply(rename_tac c na d da e1a e2a zaa list a lista)(*strict*) apply(clarsimp) apply(rename_tac c na d da \<delta>'a e1a e2a zaa a list)(*strict*) apply(clarsimp) apply(rename_tac c na d da e1a e2a zaa list)(*strict*) apply(case_tac list) apply(rename_tac c na d da e1a e2a zaa list)(*strict*) apply(clarsimp) apply(rename_tac c na d da e1a e2a zaa)(*strict*) apply(case_tac "\<alpha>") apply(rename_tac c na d da e1a e2a zaa)(*strict*) apply(clarsimp) apply(rename_tac c na d da e1a e2a zaa a list)(*strict*) apply(clarsimp) apply(rename_tac c na d da e1a e2a zaa list)(*strict*) apply(case_tac list) apply(rename_tac c na d da e1a e2a zaa list)(*strict*) apply(clarsimp) apply(rename_tac c na d da e1a e2a zaa list a lista)(*strict*) apply(clarsimp) apply(rename_tac c na d da e1a e2a zaa list a lista)(*strict*) apply(clarsimp) apply(rename_tac c na d da e1a e2a zaa lista)(*strict*) apply(case_tac lista) apply(rename_tac c na d da e1a e2a zaa lista)(*strict*) apply(clarsimp) apply(rename_tac c na d da e1a e2a zaa)(*strict*) apply(case_tac "\<alpha>") apply(rename_tac c na d da e1a e2a zaa)(*strict*) apply(clarsimp) apply(rename_tac c na d da e1a e2a zaa a list)(*strict*) apply(clarsimp) apply(rename_tac c na d da e1a e2a zaa lista a list)(*strict*) apply(clarsimp) apply(rename_tac c na d da \<delta> zb \<delta>'a e1a e2a zaa a list)(*strict*) apply(clarsimp) apply(rename_tac c n na d da \<delta> e1 e2 zb \<delta>'a e1a e2a zaa nat)(*strict*) apply(clarsimp) apply(rename_tac c na d da \<delta> e1 e2 zb \<delta>'a e1a e2a zaa nat)(*strict*) apply(case_tac na) apply(rename_tac c na d da \<delta> e1 e2 zb \<delta>'a e1a e2a zaa nat)(*strict*) apply(clarsimp) apply(rename_tac c d da \<delta> e1 e2 zb \<delta>'a zaa nat)(*strict*) apply(case_tac "\<delta>'a") apply(rename_tac c d da \<delta> e1 e2 zb \<delta>'a zaa nat)(*strict*) apply(clarsimp) apply(rename_tac c d da \<delta> e1 e2 zb nat)(*strict*) apply(case_tac "\<delta>") apply(rename_tac c d da \<delta> e1 e2 zb nat)(*strict*) apply(clarsimp) apply(rename_tac c d da e1 e2 zb nat)(*strict*) apply(case_tac "\<delta>'") apply(rename_tac c d da e1 e2 zb nat)(*strict*) apply(clarsimp) apply(rename_tac c d da e1 e2 zb nat a list)(*strict*) apply(clarsimp) apply(rename_tac c d da e1 e2 zb nat list)(*strict*) apply(case_tac list) apply(rename_tac c d da e1 e2 zb nat list)(*strict*) apply(clarsimp) apply(rename_tac c d da e1 e2 zb nat list a lista)(*strict*) apply(clarsimp) apply(rename_tac c d da \<delta> e1 e2 zb nat a list)(*strict*) apply(clarsimp) apply(rename_tac c d da e1 e2 zb nat list)(*strict*) apply(case_tac list) apply(rename_tac c d da e1 e2 zb nat list)(*strict*) apply(clarsimp) apply(rename_tac c d da e1 e2 zb nat)(*strict*) apply(case_tac "\<alpha>'") apply(rename_tac c d da e1 e2 zb nat)(*strict*) apply(clarsimp) apply(rename_tac c d da e1 e2 zb nat a list)(*strict*) apply(clarsimp) apply(rename_tac c d da e1 e2 zb nat list)(*strict*) apply(case_tac list) apply(rename_tac c d da e1 e2 zb nat list)(*strict*) apply(clarsimp) apply(rename_tac c d da e1 e2 zb nat list a lista)(*strict*) apply(clarsimp) apply(rename_tac c d da e1 e2 zb nat list a lista)(*strict*) apply(clarsimp) apply(rename_tac c d da e1 e2 zb nat lista)(*strict*) apply(case_tac lista) apply(rename_tac c d da e1 e2 zb nat lista)(*strict*) apply(clarsimp) apply(rename_tac c d da e1 e2 zb nat)(*strict*) apply(case_tac "\<alpha>'") apply(rename_tac c d da e1 e2 zb nat)(*strict*) apply(clarsimp) apply(rename_tac c d da e1 e2 zb nat a list)(*strict*) apply(clarsimp) apply(rename_tac c d da e1 e2 zb nat lista a list)(*strict*) apply(clarsimp) apply(rename_tac c d da \<delta> e1 e2 zb \<delta>'a zaa nat a list)(*strict*) apply(clarsimp) apply(rename_tac c na d da \<delta> e1 e2 zb \<delta>'a e1a e2a zaa nat nata)(*strict*) apply(clarsimp) apply(rename_tac c d da \<delta> e1 e2 zb \<delta>'a e1a e2a zaa nat nata)(*strict*) apply(subgoal_tac "\<exists>w. set w \<subseteq> two_elements_construct_domain (cfg_nonterminals G) (cfg_events G) \<and> cfg_conf SSc=[teB Do]@w@[teB Do]" for SSc) apply(rename_tac c d da \<delta> e1 e2 zb \<delta>'a e1a e2a zaa nat nata)(*strict*) prefer 2 apply(rule_tac d="d" and i="nat" in F_CFG_AUGMENT__reachableConf_of_certain_form) apply(rename_tac c d da \<delta> e1 e2 zb \<delta>'a e1a e2a zaa nat nata)(*strict*) apply(simp add: F_CFG_AUGMENT__input_def AF_LR_PARSER_input_def) apply(rename_tac c d da \<delta> e1 e2 zb \<delta>'a e1a e2a zaa nat nata)(*strict*) apply(rule cfgSTD.derivation_initialI) apply(rename_tac c d da \<delta> e1 e2 zb \<delta>'a e1a e2a zaa nat nata)(*strict*) apply(rule cfgRM_derivations_are_cfg_derivations) apply(simp add: F_CFG_AUGMENT__input_def AF_LR_PARSER_input_def) apply(rename_tac c d da \<delta> e1 e2 zb \<delta>'a e1a e2a zaa nat nata)(*strict*) apply(simp add: cfg_initial_configurations_def get_configuration_def cfg_configurations_def valid_cfg_def) apply(simp add: F_CFG_AUGMENT__input_def AF_LR_PARSER_input_def) apply(rename_tac c d da \<delta> e1 e2 zb \<delta>'a e1a e2a zaa nat nata)(*strict*) apply(force) apply(rename_tac c d da \<delta> e1 e2 zb \<delta>'a e1a e2a zaa nat nata)(*strict*) apply(subgoal_tac "\<exists>w. set w \<subseteq> two_elements_construct_domain (cfg_nonterminals G) (cfg_events G) \<and> cfg_conf SSc=[teB Do]@w@[teB Do]" for SSc) apply(rename_tac c d da \<delta> e1 e2 zb \<delta>'a e1a e2a zaa nat nata)(*strict*) prefer 2 apply(rule_tac d="da" and i="nata" in F_CFG_AUGMENT__reachableConf_of_certain_form) apply(rename_tac c d da \<delta> e1 e2 zb \<delta>'a e1a e2a zaa nat nata)(*strict*) apply(simp add: F_CFG_AUGMENT__input_def AF_LR_PARSER_input_def) apply(rename_tac c d da \<delta> e1 e2 zb \<delta>'a e1a e2a zaa nat nata)(*strict*) apply(rule cfgSTD.derivation_initialI) apply(rename_tac c d da \<delta> e1 e2 zb \<delta>'a e1a e2a zaa nat nata)(*strict*) apply(rule cfgRM_derivations_are_cfg_derivations) apply(simp add: F_CFG_AUGMENT__input_def AF_LR_PARSER_input_def) apply(rename_tac c d da \<delta> e1 e2 zb \<delta>'a e1a e2a zaa nat nata)(*strict*) apply(simp add: cfg_initial_configurations_def get_configuration_def cfg_configurations_def valid_cfg_def) apply(simp add: F_CFG_AUGMENT__input_def AF_LR_PARSER_input_def) apply(rename_tac c d da \<delta> e1 e2 zb \<delta>'a e1a e2a zaa nat nata)(*strict*) apply(force) apply(rename_tac c d da \<delta> e1 e2 zb \<delta>'a e1a e2a zaa nat nata)(*strict*) apply(clarsimp) apply(rename_tac c d da \<delta> e1 e2 zb \<delta>'a e1a e2a zaa nat nata w wa)(*strict*) apply(case_tac "\<delta>") apply(rename_tac c d da \<delta> e1 e2 zb \<delta>'a e1a e2a zaa nat nata w wa)(*strict*) apply(clarsimp) apply(rename_tac c d da \<delta> e1 e2 zb \<delta>'a e1a e2a zaa nat nata w wa a list)(*strict*) apply(clarsimp) apply(rename_tac c d da e1 e2 zb \<delta>' e1a e2a zaa nat nata w wa list)(*strict*) apply(rename_tac w1) apply(rename_tac c d da e1 e2 zb \<delta>' e1a e2a zaa nat nata w wa w1)(*strict*) apply(case_tac "\<delta>'") apply(rename_tac c d da e1 e2 zb \<delta>' e1a e2a zaa nat nata w wa w1)(*strict*) apply(clarsimp) apply(rename_tac c d da e1 e2 zb \<delta>' e1a e2a zaa nat nata w wa w1 a list)(*strict*) apply(clarsimp) apply(rename_tac c d da e1 e2 zb e1a e2a zaa nat nata w wa w1 list)(*strict*) apply(rename_tac w2) apply(rename_tac c d da e1 e2 zb e1a e2a zaa nat nata w wa w1 w2)(*strict*) apply(case_tac zb) apply(rename_tac c d da e1 e2 zb e1a e2a zaa nat nata w wa w1 w2)(*strict*) apply(clarsimp) apply(rename_tac c d da e1 e2 zb e1a e2a zaa nat nata w wa w1 w2 a list)(*strict*) apply(subgoal_tac "\<exists>w' x'. zb = w' @ [x']") apply(rename_tac c d da e1 e2 zb e1a e2a zaa nat nata w wa w1 w2 a list)(*strict*) prefer 2 apply(rule NonEmptyListHasTailElem) apply(force) apply(rename_tac c d da e1 e2 zb e1a e2a zaa nat nata w wa w1 w2 a list)(*strict*) apply(thin_tac "zb=a#list") apply(clarsimp) apply(rename_tac c d da e1 e2 e1a e2a zaa nat nata wa w1 w2 w')(*strict*) apply(rename_tac w3) apply(rename_tac c d da e1 e2 e1a e2a zaa nat nata wa w1 w2 w3)(*strict*) apply(case_tac zaa) apply(rename_tac c d da e1 e2 e1a e2a zaa nat nata wa w1 w2 w3)(*strict*) apply(clarsimp) apply(rename_tac c d da e1 e2 e1a e2a zaa nat nata wa w1 w2 w3 a list)(*strict*) apply(subgoal_tac "\<exists>w' x'. zaa = w' @ [x']") apply(rename_tac c d da e1 e2 e1a e2a zaa nat nata wa w1 w2 w3 a list)(*strict*) prefer 2 apply(rule NonEmptyListHasTailElem) apply(force) apply(rename_tac c d da e1 e2 e1a e2a zaa nat nata wa w1 w2 w3 a list)(*strict*) apply(thin_tac "zaa=a#list") apply(clarsimp) apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 w')(*strict*) apply(rename_tac w4) apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 w4)(*strict*) apply(simp add: suffix_def) apply(clarsimp) apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 w4 ca)(*strict*) apply(case_tac "k - length w4") apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 w4 ca)(*strict*) apply(clarsimp) apply (metis Nat.add_0_right liftB_reflects_length add_Suc diff_is_0_eq' le_refl less_diff_conv add.commute not_less0 take_all_length) apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 w4 ca natb)(*strict*) apply(clarsimp) apply(subgoal_tac "\<exists>y. z = y@[Do]") apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 w4 ca natb)(*strict*) prefer 2 apply(case_tac "z") apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 w4 ca natb)(*strict*) apply(force) apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 w4 ca natb a list)(*strict*) apply(subgoal_tac "\<exists>w' x'. z = w' @ [x']") apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 w4 ca natb a list)(*strict*) prefer 2 apply(rule NonEmptyListHasTailElem) apply(force) apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 w4 ca natb a list)(*strict*) apply(thin_tac "z=a#list") apply(clarsimp) apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 w4 ca natb w' x')(*strict*) apply(rule liftB_terminal_tail_equals) apply(force) apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 w4 ca natb)(*strict*) apply(clarsimp) apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 w4 ca natb y)(*strict*) apply(subgoal_tac "w4=liftB y") apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 w4 ca natb y)(*strict*) prefer 2 apply(rule liftB_terminal_butlast_equals) apply(force) apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 w4 ca natb y)(*strict*) apply(clarsimp) apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y)(*strict*) apply(thin_tac "liftB y @ [teB Do] = liftB (y @ [Do])") apply(case_tac "k - length w3") apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y)(*strict*) prefer 2 apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y natc)(*strict*) apply(clarsimp) apply(thin_tac "ca @ y @ [Do] \<in> cfgSTD_first G' (k - Suc 0) (\<beta> @ liftB (y @ [Do]))") apply(simp add: cfgSTD_first_def) apply(clarsimp) apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y natc x db e1b n)(*strict*) apply(subgoal_tac "suffix x za") apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y natc x db e1b n)(*strict*) prefer 2 apply(rule liftB_creates_suffix) apply(subgoal_tac "\<exists>d' e. cfgRM.derivation G' d' \<and> maximum_of_domain d' n \<and> d' 0 = Some (pair None \<lparr>cfg_conf=\<beta>' @ liftB za\<rparr>) \<and> d' n = Some (pair e \<lparr>cfg_conf=liftB x\<rparr>)") apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y natc x db e1b n)(*strict*) prefer 2 apply(rule_tac d="db" in cfg_derivation_can_be_translated_to_cfgRM_derivation) apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y natc x db e1b n)(*strict*) apply(simp add: AF_LR_PARSER_input_def) apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y natc x db e1b n)(*strict*) apply(force) apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y natc x db e1b n)(*strict*) apply(simp add: maximum_of_domain_def) apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y natc x db e1b n)(*strict*) apply(force) apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y natc x db e1b n)(*strict*) apply(force) apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y natc x db e1b n)(*strict*) apply (metis setA_liftB) apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y natc x db e1b n)(*strict*) apply(clarsimp) apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y natc x db e1b n d' e)(*strict*) apply(rule_tac d="d'" and i="0" and j="n" in CFGRM_terminals_stay_at_end) apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y natc x db e1b n d' e)(*strict*) apply(force) apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y natc x db e1b n d' e)(*strict*) apply(force) apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y natc x db e1b n d' e)(*strict*) apply (metis setA_liftB) apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y natc x db e1b n d' e)(*strict*) apply(force) apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y natc x db e1b n d' e)(*strict*) apply(force) apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y natc x db e1b n d' e)(*strict*) apply(force) apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y natc x db e1b n)(*strict*) apply(simp add: suffix_def) apply(clarsimp) apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y natc db e1b n cb)(*strict*) apply(case_tac "(k - Suc (length cb))") apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y natc db e1b n cb)(*strict*) apply(clarsimp) apply(subgoal_tac "set cb \<subseteq> cfg_events G") apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y natc db e1b n cb)(*strict*) apply(subgoal_tac "Do \<in> set cb") apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y natc db e1b n cb)(*strict*) apply(subgoal_tac "Do \<notin> set cb") apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y natc db e1b n cb)(*strict*) apply(force) apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y natc db e1b n cb)(*strict*) apply(rule_tac B="cfg_events G" in nset_mp) apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y natc db e1b n cb)(*strict*) apply(force) apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y natc db e1b n cb)(*strict*) apply(simp add: AF_LR_PARSER_input_def two_elements_construct_domain_def) apply(clarsimp) apply(subgoal_tac "F_FRESH (cfg_events G) \<notin> cfg_events G") apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y natc db e1b n cb)(*strict*) apply(force) apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y natc db e1b n cb)(*strict*) apply(rule F_FRESH_is_fresh) apply(simp add: AF_LR_PARSER_def AF_LR_PARSER_input_def valid_cfg_def) apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y natc db e1b n cb)(*strict*) apply(rule_tac A="set(take (k - Suc 0) cb)" in set_mp) apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y natc db e1b n cb)(*strict*) apply(rule List.set_take_subset) apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y natc db e1b n cb)(*strict*) apply(rule_tac t="take (k - Suc 0) cb" and s="ca @ y @ Do # c" in ssubst) apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y natc db e1b n cb)(*strict*) apply(force) apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y natc db e1b n cb)(*strict*) apply(simp (no_asm)) apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y natc db e1b n cb)(*strict*) apply(rule liftB_in_two_elements_construct_domain_to_subset) apply(subgoal_tac "\<exists>v. set v \<subseteq> two_elements_construct_domain (cfg_nonterminals G) (cfg_events G) \<and> (case e1b of None \<Rightarrow> True|Some e' \<Rightarrow> e' \<in> cfg_productions G) \<and> SSc=\<lparr>cfg_conf = v @ liftB za\<rparr>" for SSc) apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y natc db e1b n cb)(*strict*) prefer 2 apply(rule_tac n="n" and d="db" in CFG_preserves_partial_belongs) apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y natc db e1b n cb)(*strict*) apply(simp add: AF_LR_PARSER_input_def) apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y natc db e1b n cb)(*strict*) prefer 2 apply(force) apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y natc db e1b n cb)(*strict*) prefer 2 apply(force) apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y natc db e1b n cb)(*strict*) apply(rule_tac B="set (\<alpha>' @ teB aa # \<beta>')" in subset_trans) apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y natc db e1b n cb)(*strict*) apply(force) apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y natc db e1b n cb)(*strict*) apply(rule SetxBiElem_check_vs_set_two_elements_construct_domain_check) apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y natc db e1b n cb)(*strict*) apply(rule prod_rhs_in_cfg_events) apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y natc db e1b n cb)(*strict*) apply(simp add: AF_LR_PARSER_def AF_LR_PARSER_input_def) apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y natc db e1b n cb)(*strict*) apply(force) apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y natc db e1b n cb)(*strict*) apply(rule prod_rhs_in_nonterms) apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y natc db e1b n cb)(*strict*) apply(simp add: AF_LR_PARSER_def AF_LR_PARSER_input_def) apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y natc db e1b n cb)(*strict*) apply(force) apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y natc db e1b n cb p)(*strict*) apply(simp add: AF_LR_PARSER_input_def F_CFG_AUGMENT_def) apply(clarsimp) apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y natc db e1b n cb)(*strict*) apply(subgoal_tac "F_FRESH (cfg_nonterminals G) \<notin> cfg_nonterminals G") apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y natc db e1b n cb)(*strict*) apply(force) apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y natc db e1b n cb)(*strict*) apply(rule F_FRESH_is_fresh) apply(simp add: AF_LR_PARSER_def AF_LR_PARSER_input_def valid_cfg_def) apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y natc db e1b n cb)(*strict*) apply(force) apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y natc db e1b n cb)(*strict*) apply(erule exE) apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y natc db e1b n cb v)(*strict*) apply(erule conjE)+ apply(subgoal_tac "v=liftB cb") apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y natc db e1b n cb v)(*strict*) apply(force) apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y natc db e1b n cb v)(*strict*) apply(clarsimp) apply(simp add: liftB_commutes_over_concat) apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y natc db e1b n cb natd)(*strict*) apply(clarsimp) apply(subgoal_tac "prefix (ca @ y @ [Do]) cb \<or> prefix cb (ca @ y @ [Do])") apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y natc db e1b n cb natd)(*strict*) prefer 2 apply(rule mutual_prefix_prefix) apply(force) apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y natc db e1b n cb natd)(*strict*) apply(erule disjE) apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y natc db e1b n cb natd)(*strict*) apply(subgoal_tac "set cb \<subseteq> cfg_events G") apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y natc db e1b n cb natd)(*strict*) apply(subgoal_tac "Do \<in> set cb") apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y natc db e1b n cb natd)(*strict*) apply(subgoal_tac "Do \<notin> set cb") apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y natc db e1b n cb natd)(*strict*) apply(force) apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y natc db e1b n cb natd)(*strict*) apply(rule_tac B="cfg_events G" in nset_mp) apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y natc db e1b n cb natd)(*strict*) apply(force) apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y natc db e1b n cb natd)(*strict*) apply(simp add: AF_LR_PARSER_input_def two_elements_construct_domain_def) apply(clarsimp) apply(subgoal_tac "F_FRESH (cfg_events G) \<notin> cfg_events G") apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y natc db e1b n cb natd)(*strict*) apply(force) apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y natc db e1b n cb natd)(*strict*) apply(rule F_FRESH_is_fresh) apply(simp add: AF_LR_PARSER_def AF_LR_PARSER_input_def valid_cfg_def) apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y natc db e1b n cb natd)(*strict*) apply(simp add: prefix_def) apply(force) apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y natc db e1b n cb natd)(*strict*) apply(rule liftB_in_two_elements_construct_domain_to_subset) apply(subgoal_tac "\<exists>v. set v \<subseteq> two_elements_construct_domain (cfg_nonterminals G) (cfg_events G) \<and> (case e1b of None \<Rightarrow> True|Some e' \<Rightarrow> e' \<in> cfg_productions G) \<and> SSc=\<lparr>cfg_conf = v @ liftB za\<rparr>" for SSc) apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y natc db e1b n cb natd)(*strict*) prefer 2 apply(rule_tac n="n" and d="db" in CFG_preserves_partial_belongs) apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y natc db e1b n cb natd)(*strict*) apply(simp add: AF_LR_PARSER_input_def) apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y natc db e1b n cb natd)(*strict*) prefer 2 apply(force) apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y natc db e1b n cb natd)(*strict*) prefer 2 apply(force) apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y natc db e1b n cb natd)(*strict*) apply(rule_tac B="set (\<alpha>' @ teB aa # \<beta>')" in subset_trans) apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y natc db e1b n cb natd)(*strict*) apply(force) apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y natc db e1b n cb natd)(*strict*) apply(rule SetxBiElem_check_vs_set_two_elements_construct_domain_check) apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y natc db e1b n cb natd)(*strict*) apply(rule prod_rhs_in_cfg_events) apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y natc db e1b n cb natd)(*strict*) apply(simp add: AF_LR_PARSER_def AF_LR_PARSER_input_def) apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y natc db e1b n cb natd)(*strict*) apply(force) apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y natc db e1b n cb natd)(*strict*) apply(rule prod_rhs_in_nonterms) apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y natc db e1b n cb natd)(*strict*) apply(simp add: AF_LR_PARSER_def AF_LR_PARSER_input_def) apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y natc db e1b n cb natd)(*strict*) apply(force) apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y natc db e1b n cb natd p)(*strict*) apply(simp add: AF_LR_PARSER_input_def F_CFG_AUGMENT_def) apply(clarsimp) apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y natc db e1b n cb natd)(*strict*) apply(subgoal_tac "F_FRESH (cfg_nonterminals G) \<notin> cfg_nonterminals G") apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y natc db e1b n cb natd)(*strict*) apply(force) apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y natc db e1b n cb natd)(*strict*) apply(rule F_FRESH_is_fresh) apply(simp add: AF_LR_PARSER_def AF_LR_PARSER_input_def valid_cfg_def) apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y natc db e1b n cb natd)(*strict*) apply(force) apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y natc db e1b n cb natd)(*strict*) apply(erule exE) apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y natc db e1b n cb natd v)(*strict*) apply(erule conjE)+ apply(subgoal_tac "v=liftB cb") apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y natc db e1b n cb natd v)(*strict*) apply(force) apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y natc db e1b n cb natd v)(*strict*) apply(clarsimp) apply(simp add: liftB_commutes_over_concat) apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y natc db e1b n cb natd)(*strict*) apply(simp add: prefix_def) apply(clarsimp) apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y natc db e1b n cb natd cc)(*strict*) apply(case_tac cc) apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y natc db e1b n cb natd cc)(*strict*) apply(subgoal_tac "set cb \<subseteq> cfg_events G") apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y natc db e1b n cb natd cc)(*strict*) apply(subgoal_tac "Do \<in> set cb") apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y natc db e1b n cb natd cc)(*strict*) apply(subgoal_tac "Do \<notin> set cb") apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y natc db e1b n cb natd cc)(*strict*) apply(force) apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y natc db e1b n cb natd cc)(*strict*) apply(rule_tac B="cfg_events G" in nset_mp) apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y natc db e1b n cb natd cc)(*strict*) apply(force) apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y natc db e1b n cb natd cc)(*strict*) apply(simp add: AF_LR_PARSER_input_def two_elements_construct_domain_def) apply(clarsimp) apply(rename_tac d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y natc db e1b n natd)(*strict*) apply(subgoal_tac "F_FRESH (cfg_events G) \<notin> cfg_events G") apply(rename_tac d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y natc db e1b n natd)(*strict*) apply(force) apply(rename_tac d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y natc db e1b n natd)(*strict*) apply(rule F_FRESH_is_fresh) apply(simp add: AF_LR_PARSER_def AF_LR_PARSER_input_def valid_cfg_def) apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y natc db e1b n cb natd cc)(*strict*) apply(force) apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y natc db e1b n cb natd cc)(*strict*) apply(rule liftB_in_two_elements_construct_domain_to_subset) apply(subgoal_tac "\<exists>v. set v \<subseteq> two_elements_construct_domain (cfg_nonterminals G) (cfg_events G) \<and> (case e1b of None \<Rightarrow> True|Some e' \<Rightarrow> e' \<in> cfg_productions G) \<and> SSc=\<lparr>cfg_conf = v @ liftB za\<rparr>" for SSc) apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y natc db e1b n cb natd cc)(*strict*) prefer 2 apply(rule_tac n="n" and d="db" in CFG_preserves_partial_belongs) apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y natc db e1b n cb natd cc)(*strict*) apply(simp add: AF_LR_PARSER_input_def) apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y natc db e1b n cb natd cc)(*strict*) prefer 2 apply(force) apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y natc db e1b n cb natd cc)(*strict*) prefer 2 apply(force) apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y natc db e1b n cb natd cc)(*strict*) apply(rule_tac B="set (\<alpha>' @ teB aa # \<beta>')" in subset_trans) apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y natc db e1b n cb natd cc)(*strict*) apply(force) apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y natc db e1b n cb natd cc)(*strict*) apply(rule SetxBiElem_check_vs_set_two_elements_construct_domain_check) apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y natc db e1b n cb natd cc)(*strict*) apply(rule prod_rhs_in_cfg_events) apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y natc db e1b n cb natd cc)(*strict*) apply(simp add: AF_LR_PARSER_def AF_LR_PARSER_input_def) apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y natc db e1b n cb natd cc)(*strict*) apply(force) apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y natc db e1b n cb natd cc)(*strict*) apply(rule prod_rhs_in_nonterms) apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y natc db e1b n cb natd cc)(*strict*) apply(simp add: AF_LR_PARSER_def AF_LR_PARSER_input_def) apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y natc db e1b n cb natd cc)(*strict*) apply(force) apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y natc db e1b n cb natd cc p)(*strict*) apply(simp add: AF_LR_PARSER_input_def F_CFG_AUGMENT_def) apply(clarsimp) apply(rename_tac d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y natc db e1b n natd)(*strict*) apply(subgoal_tac "F_FRESH (cfg_nonterminals G) \<notin> cfg_nonterminals G") apply(rename_tac d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y natc db e1b n natd)(*strict*) apply(force) apply(rename_tac d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y natc db e1b n natd)(*strict*) apply(rule F_FRESH_is_fresh) apply(simp add: AF_LR_PARSER_def AF_LR_PARSER_input_def valid_cfg_def) apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y natc db e1b n cb natd cc)(*strict*) apply(force) apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y natc db e1b n cb natd cc)(*strict*) apply(erule exE) apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y natc db e1b n cb natd cc v)(*strict*) apply(erule conjE)+ apply(subgoal_tac "v=liftB cb") apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y natc db e1b n cb natd cc v)(*strict*) apply(force) apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y natc db e1b n cb natd cc v)(*strict*) apply(clarsimp) apply(rename_tac d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y natc db e1b n natd v)(*strict*) apply(simp add: liftB_commutes_over_concat) apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y natc db e1b n cb natd cc a list)(*strict*) apply(subgoal_tac "\<exists>w' x'. cc = w' @ [x']") apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y natc db e1b n cb natd cc a list)(*strict*) prefer 2 apply(rule NonEmptyListHasTailElem) apply(force) apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y natc db e1b n cb natd cc a list)(*strict*) apply(thin_tac "cc=a#list") apply(clarsimp) apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y natc db e1b n cb natd w')(*strict*) apply(subgoal_tac "take (Suc natd) za = w'@Do#c") apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y natc db e1b n cb natd w')(*strict*) prefer 2 apply(rule sym) apply(rule_tac w="cb" in append_linj) apply(metis concat_asso) apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y natc db e1b n cb natd w')(*strict*) apply(clarsimp) apply(case_tac za) apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y natc db e1b n cb natd w')(*strict*) apply(force) apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y natc db e1b n cb natd w' a list)(*strict*) apply(subgoal_tac "\<exists>w' x'. za = w' @ [x']") apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y natc db e1b n cb natd w' a list)(*strict*) prefer 2 apply(rule NonEmptyListHasTailElem) apply(force) apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y natc db e1b n cb natd w' a list)(*strict*) apply(thin_tac "za=a#list") apply(clarsimp) apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y natc db e1b n cb natd w' w'a x')(*strict*) apply(subgoal_tac "w3=liftB w'a") apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y natc db e1b n cb natd w' w'a x')(*strict*) apply(subgoal_tac "Do=x'") apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y natc db e1b n cb natd w' w'a x')(*strict*) apply(clarsimp) apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 ca natb y natc db e1b n cb natd w' w'a)(*strict*) apply(case_tac c) apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 ca natb y natc db e1b n cb natd w' w'a)(*strict*) apply(force) apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 ca natb y natc db e1b n cb natd w' w'a a list)(*strict*) apply(subgoal_tac "\<exists>w' x'. c = w' @ [x']") apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 ca natb y natc db e1b n cb natd w' w'a a list)(*strict*) prefer 2 apply(rule NonEmptyListHasTailElem) apply(force) apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 ca natb y natc db e1b n cb natd w' w'a a list)(*strict*) apply(thin_tac "c=a#list") apply(clarsimp) apply(rename_tac d da e1 e2 e1a e2a nat nata w1 w2 ca natb y natc db e1b n cb natd w' w'a w'b x')(*strict*) apply(subgoal_tac "teB Do \<in> set (liftB w'a)") apply(rename_tac d da e1 e2 e1a e2a nat nata w1 w2 ca natb y natc db e1b n cb natd w' w'a w'b x')(*strict*) apply(subgoal_tac "teB Do \<notin> set (liftB w'a)") apply(rename_tac d da e1 e2 e1a e2a nat nata w1 w2 ca natb y natc db e1b n cb natd w' w'a w'b x')(*strict*) apply(force) apply(rename_tac d da e1 e2 e1a e2a nat nata w1 w2 ca natb y natc db e1b n cb natd w' w'a w'b x')(*strict*) apply(thin_tac "teB Do \<in> set (liftB w'a)") apply(rule_tac B="two_elements_construct_domain (cfg_nonterminals G) (cfg_events G)" in nset_mp) apply(rename_tac d da e1 e2 e1a e2a nat nata w1 w2 ca natb y natc db e1b n cb natd w' w'a w'b x')(*strict*) apply(force) apply(rename_tac d da e1 e2 e1a e2a nat nata w1 w2 ca natb y natc db e1b n cb natd w' w'a w'b x')(*strict*) apply(simp add: two_elements_construct_domain_def AF_LR_PARSER_input_def) apply(subgoal_tac "F_FRESH (cfg_events G) \<notin> cfg_events G") apply(rename_tac d da e1 e2 e1a e2a nat nata w1 w2 ca natb y natc db e1b n cb natd w' w'a w'b x')(*strict*) apply(force) apply(rename_tac d da e1 e2 e1a e2a nat nata w1 w2 ca natb y natc db e1b n cb natd w' w'a w'b x')(*strict*) apply(rule F_FRESH_is_fresh) apply(simp add: AF_LR_PARSER_def AF_LR_PARSER_input_def valid_cfg_def) apply(rename_tac d da e1 e2 e1a e2a nat nata w1 w2 ca natb y natc db e1b n cb natd w' w'a w'b x')(*strict*) apply(case_tac "Suc natd - length w'a") apply(rename_tac d da e1 e2 e1a e2a nat nata w1 w2 ca natb y natc db e1b n cb natd w' w'a w'b x')(*strict*) apply(clarsimp) apply (metis set_liftB_insert take_reflects_mem) apply(rename_tac d da e1 e2 e1a e2a nat nata w1 w2 ca natb y natc db e1b n cb natd w' w'a w'b x' nate)(*strict*) apply(clarsimp) apply(rename_tac d da e1 e2 e1a e2a nat nata w1 w2 ca natb y natc db e1b n cb natd w' w'b nate)(*strict*) apply (metis head_in_set set_liftB_insert set_append_contra2) apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y natc db e1b n cb natd w' w'a x')(*strict*) apply(rule sym) apply(rule liftB_terminal_tail_equals) apply(force) apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y natc db e1b n cb natd w' w'a x')(*strict*) apply(rule liftB_terminal_butlast_equals) apply(force) apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y)(*strict*) apply(clarsimp) apply(thin_tac "ca @ y @ [Do] \<in> cfgSTD_first G' (k - Suc 0) (\<beta> @ liftB (y @ [Do]))") apply(simp add: cfgSTD_first_def) apply(clarsimp) apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y x db e1b n)(*strict*) apply(subgoal_tac "suffix x za") apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y x db e1b n)(*strict*) prefer 2 apply(rule liftB_creates_suffix) apply(subgoal_tac "\<exists>d' e. cfgRM.derivation G' d' \<and> maximum_of_domain d' n \<and> d' 0 = Some (pair None \<lparr>cfg_conf=\<beta>' @ liftB za\<rparr>) \<and> d' n = Some (pair e \<lparr>cfg_conf=liftB x\<rparr>)") apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y x db e1b n)(*strict*) prefer 2 apply(rule_tac d="db" in cfg_derivation_can_be_translated_to_cfgRM_derivation) apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y x db e1b n)(*strict*) apply(simp add: AF_LR_PARSER_input_def) apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y x db e1b n)(*strict*) apply(force) apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y x db e1b n)(*strict*) apply(simp add: maximum_of_domain_def) apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y x db e1b n)(*strict*) apply(force) apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y x db e1b n)(*strict*) apply(force) apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y x db e1b n)(*strict*) apply (metis setA_liftB) apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y x db e1b n)(*strict*) apply(clarsimp) apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y x db e1b n d' e)(*strict*) apply(rule_tac d="d'" and i="0" and j="n" in CFGRM_terminals_stay_at_end) apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y x db e1b n d' e)(*strict*) apply(force) apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y x db e1b n d' e)(*strict*) apply(force) apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y x db e1b n d' e)(*strict*) apply (metis setA_liftB) apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y x db e1b n d' e)(*strict*) apply(force) apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y x db e1b n d' e)(*strict*) apply(force) apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y x db e1b n d' e)(*strict*) apply(force) apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y x db e1b n)(*strict*) apply(simp add: suffix_def) apply(clarsimp) apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y db e1b n cb)(*strict*) apply(case_tac "(k - Suc (length cb))") apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y db e1b n cb)(*strict*) apply(clarsimp) apply(subgoal_tac "set cb \<subseteq> cfg_events G") apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y db e1b n cb)(*strict*) apply(subgoal_tac "Do \<in> set cb") apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y db e1b n cb)(*strict*) apply(subgoal_tac "Do \<notin> set cb") apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y db e1b n cb)(*strict*) apply(force) apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y db e1b n cb)(*strict*) apply(rule_tac B="cfg_events G" in nset_mp) apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y db e1b n cb)(*strict*) apply(force) apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y db e1b n cb)(*strict*) apply(simp add: AF_LR_PARSER_input_def two_elements_construct_domain_def) apply(clarsimp) apply(subgoal_tac "F_FRESH (cfg_events G) \<notin> cfg_events G") apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y db e1b n cb)(*strict*) apply(force) apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y db e1b n cb)(*strict*) apply(rule F_FRESH_is_fresh) apply(simp add: AF_LR_PARSER_def AF_LR_PARSER_input_def valid_cfg_def) apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y db e1b n cb)(*strict*) apply(rule_tac A="set(take (k - Suc 0) cb)" in set_mp) apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y db e1b n cb)(*strict*) apply(rule List.set_take_subset) apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y db e1b n cb)(*strict*) apply(rule_tac t="take (k - Suc 0) cb" and s="ca @ y @ Do # c" in ssubst) apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y db e1b n cb)(*strict*) apply(force) apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y db e1b n cb)(*strict*) apply(simp (no_asm)) apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y db e1b n cb)(*strict*) apply(rule liftB_in_two_elements_construct_domain_to_subset) apply(subgoal_tac "\<exists>v. set v \<subseteq> two_elements_construct_domain (cfg_nonterminals G) (cfg_events G) \<and> (case e1b of None \<Rightarrow> True|Some e' \<Rightarrow> e' \<in> cfg_productions G) \<and> SSc=\<lparr>cfg_conf = v @ liftB za\<rparr>" for SSc) apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y db e1b n cb)(*strict*) prefer 2 apply(rule_tac n="n" and d="db" in CFG_preserves_partial_belongs) apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y db e1b n cb)(*strict*) apply(simp add: AF_LR_PARSER_input_def) apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y db e1b n cb)(*strict*) prefer 2 apply(force) apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y db e1b n cb)(*strict*) prefer 2 apply(force) apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y db e1b n cb)(*strict*) apply(rule_tac B="set (\<alpha>' @ teB aa # \<beta>')" in subset_trans) apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y db e1b n cb)(*strict*) apply(force) apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y db e1b n cb)(*strict*) apply(rule SetxBiElem_check_vs_set_two_elements_construct_domain_check) apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y db e1b n cb)(*strict*) apply(rule prod_rhs_in_cfg_events) apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y db e1b n cb)(*strict*) apply(simp add: AF_LR_PARSER_def AF_LR_PARSER_input_def) apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y db e1b n cb)(*strict*) apply(force) apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y db e1b n cb)(*strict*) apply(rule prod_rhs_in_nonterms) apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y db e1b n cb)(*strict*) apply(simp add: AF_LR_PARSER_def AF_LR_PARSER_input_def) apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y db e1b n cb)(*strict*) apply(force) apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y db e1b n cb p)(*strict*) apply(simp add: AF_LR_PARSER_input_def F_CFG_AUGMENT_def) apply(clarsimp) apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y db e1b n cb)(*strict*) apply(subgoal_tac "F_FRESH (cfg_nonterminals G) \<notin> cfg_nonterminals G") apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y db e1b n cb)(*strict*) apply(force) apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y db e1b n cb)(*strict*) apply(rule F_FRESH_is_fresh) apply(simp add: AF_LR_PARSER_def AF_LR_PARSER_input_def valid_cfg_def) apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y db e1b n cb)(*strict*) apply(force) apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y db e1b n cb)(*strict*) apply(erule exE) apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y db e1b n cb v)(*strict*) apply(erule conjE)+ apply(subgoal_tac "v=liftB cb") apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y db e1b n cb v)(*strict*) apply(force) apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y db e1b n cb v)(*strict*) apply(clarsimp) apply(simp add: liftB_commutes_over_concat) apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y db e1b n cb natc)(*strict*) apply(clarsimp) apply(subgoal_tac "prefix (ca @ y @ [Do]) cb \<or> prefix cb (ca @ y @ [Do])") apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y db e1b n cb natc)(*strict*) prefer 2 apply(rule mutual_prefix_prefix) apply(force) apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y db e1b n cb natc)(*strict*) apply(erule disjE) apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y db e1b n cb natc)(*strict*) apply(subgoal_tac "set cb \<subseteq> cfg_events G") apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y db e1b n cb natc)(*strict*) apply(subgoal_tac "Do \<in> set cb") apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y db e1b n cb natc)(*strict*) apply(subgoal_tac "Do \<notin> set cb") apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y db e1b n cb natc)(*strict*) apply(force) apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y db e1b n cb natc)(*strict*) apply(rule_tac B="cfg_events G" in nset_mp) apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y db e1b n cb natc)(*strict*) apply(force) apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y db e1b n cb natc)(*strict*) apply(simp add: AF_LR_PARSER_input_def two_elements_construct_domain_def) apply(clarsimp) apply(subgoal_tac "F_FRESH (cfg_events G) \<notin> cfg_events G") apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y db e1b n cb natc)(*strict*) apply(force) apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y db e1b n cb natc)(*strict*) apply(rule F_FRESH_is_fresh) apply(simp add: AF_LR_PARSER_def AF_LR_PARSER_input_def valid_cfg_def) apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y db e1b n cb natc)(*strict*) apply(simp add: prefix_def) apply(force) apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y db e1b n cb natc)(*strict*) apply(rule liftB_in_two_elements_construct_domain_to_subset) apply(subgoal_tac "\<exists>v. set v \<subseteq> two_elements_construct_domain (cfg_nonterminals G) (cfg_events G) \<and> (case e1b of None \<Rightarrow> True|Some e' \<Rightarrow> e' \<in> cfg_productions G) \<and> SSc=\<lparr>cfg_conf = v @ liftB za\<rparr>" for SSc) apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y db e1b n cb natc)(*strict*) prefer 2 apply(rule_tac n="n" and d="db" in CFG_preserves_partial_belongs) apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y db e1b n cb natc)(*strict*) apply(simp add: AF_LR_PARSER_input_def) apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y db e1b n cb natc)(*strict*) prefer 2 apply(force) apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y db e1b n cb natc)(*strict*) prefer 2 apply(force) apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y db e1b n cb natc)(*strict*) apply(rule_tac B="set (\<alpha>' @ teB aa # \<beta>')" in subset_trans) apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y db e1b n cb natc)(*strict*) apply(force) apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y db e1b n cb natc)(*strict*) apply(rule SetxBiElem_check_vs_set_two_elements_construct_domain_check) apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y db e1b n cb natc)(*strict*) apply(rule prod_rhs_in_cfg_events) apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y db e1b n cb natc)(*strict*) apply(simp add: AF_LR_PARSER_def AF_LR_PARSER_input_def) apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y db e1b n cb natc)(*strict*) apply(force) apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y db e1b n cb natc)(*strict*) apply(rule prod_rhs_in_nonterms) apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y db e1b n cb natc)(*strict*) apply(simp add: AF_LR_PARSER_def AF_LR_PARSER_input_def) apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y db e1b n cb natc)(*strict*) apply(force) apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y db e1b n cb natc p)(*strict*) apply(simp add: AF_LR_PARSER_input_def F_CFG_AUGMENT_def) apply(clarsimp) apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y db e1b n cb natc)(*strict*) apply(subgoal_tac "F_FRESH (cfg_nonterminals G) \<notin> cfg_nonterminals G") apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y db e1b n cb natc)(*strict*) apply(force) apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y db e1b n cb natc)(*strict*) apply(rule F_FRESH_is_fresh) apply(simp add: AF_LR_PARSER_def AF_LR_PARSER_input_def valid_cfg_def) apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y db e1b n cb natc)(*strict*) apply(force) apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y db e1b n cb natc)(*strict*) apply(erule exE) apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y db e1b n cb natc v)(*strict*) apply(erule conjE)+ apply(subgoal_tac "v=liftB cb") apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y db e1b n cb natc v)(*strict*) apply(force) apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y db e1b n cb natc v)(*strict*) apply(clarsimp) apply(simp add: liftB_commutes_over_concat) apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y db e1b n cb natc)(*strict*) apply(simp add: prefix_def) apply(clarsimp) apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y db e1b n cb natc cc)(*strict*) apply(case_tac cc) apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y db e1b n cb natc cc)(*strict*) apply(subgoal_tac "set cb \<subseteq> cfg_events G") apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y db e1b n cb natc cc)(*strict*) apply(subgoal_tac "Do \<in> set cb") apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y db e1b n cb natc cc)(*strict*) apply(subgoal_tac "Do \<notin> set cb") apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y db e1b n cb natc cc)(*strict*) apply(force) apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y db e1b n cb natc cc)(*strict*) apply(rule_tac B="cfg_events G" in nset_mp) apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y db e1b n cb natc cc)(*strict*) apply(force) apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y db e1b n cb natc cc)(*strict*) apply(simp add: AF_LR_PARSER_input_def two_elements_construct_domain_def) apply(clarsimp) apply(rename_tac d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y db e1b n natc)(*strict*) apply(subgoal_tac "F_FRESH (cfg_events G) \<notin> cfg_events G") apply(rename_tac d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y db e1b n natc)(*strict*) apply(force) apply(rename_tac d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y db e1b n natc)(*strict*) apply(rule F_FRESH_is_fresh) apply(simp add: AF_LR_PARSER_def AF_LR_PARSER_input_def valid_cfg_def) apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y db e1b n cb natc cc)(*strict*) apply(force) apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y db e1b n cb natc cc)(*strict*) apply(rule liftB_in_two_elements_construct_domain_to_subset) apply(subgoal_tac "\<exists>v. set v \<subseteq> two_elements_construct_domain (cfg_nonterminals G) (cfg_events G) \<and> (case e1b of None \<Rightarrow> True|Some e' \<Rightarrow> e' \<in> cfg_productions G) \<and> SSc=\<lparr>cfg_conf = v @ liftB za\<rparr>" for SSc) apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y db e1b n cb natc cc)(*strict*) prefer 2 apply(rule_tac n="n" and d="db" in CFG_preserves_partial_belongs) apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y db e1b n cb natc cc)(*strict*) apply(simp add: AF_LR_PARSER_input_def) apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y db e1b n cb natc cc)(*strict*) prefer 2 apply(force) apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y db e1b n cb natc cc)(*strict*) prefer 2 apply(force) apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y db e1b n cb natc cc)(*strict*) apply(rule_tac B="set (\<alpha>' @ teB aa # \<beta>')" in subset_trans) apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y db e1b n cb natc cc)(*strict*) apply(force) apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y db e1b n cb natc cc)(*strict*) apply(rule SetxBiElem_check_vs_set_two_elements_construct_domain_check) apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y db e1b n cb natc cc)(*strict*) apply(rule prod_rhs_in_cfg_events) apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y db e1b n cb natc cc)(*strict*) apply(simp add: AF_LR_PARSER_def AF_LR_PARSER_input_def) apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y db e1b n cb natc cc)(*strict*) apply(force) apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y db e1b n cb natc cc)(*strict*) apply(rule prod_rhs_in_nonterms) apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y db e1b n cb natc cc)(*strict*) apply(simp add: AF_LR_PARSER_def AF_LR_PARSER_input_def) apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y db e1b n cb natc cc)(*strict*) apply(force) apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y db e1b n cb natc cc p)(*strict*) apply(simp add: AF_LR_PARSER_input_def F_CFG_AUGMENT_def) apply(clarsimp) apply(rename_tac d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y db e1b n natc)(*strict*) apply(subgoal_tac "F_FRESH (cfg_nonterminals G) \<notin> cfg_nonterminals G") apply(rename_tac d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y db e1b n natc)(*strict*) apply(force) apply(rename_tac d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y db e1b n natc)(*strict*) apply(rule F_FRESH_is_fresh) apply(simp add: AF_LR_PARSER_def AF_LR_PARSER_input_def valid_cfg_def) apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y db e1b n cb natc cc)(*strict*) apply(force) apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y db e1b n cb natc cc)(*strict*) apply(erule exE) apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y db e1b n cb natc cc v)(*strict*) apply(erule conjE)+ apply(subgoal_tac "v=liftB cb") apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y db e1b n cb natc cc v)(*strict*) apply(force) apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y db e1b n cb natc cc v)(*strict*) apply(clarsimp) apply(rename_tac d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y db e1b n natc v)(*strict*) apply(simp add: liftB_commutes_over_concat) apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y db e1b n cb natc cc a list)(*strict*) apply(subgoal_tac "\<exists>w' x'. cc = w' @ [x']") apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y db e1b n cb natc cc a list)(*strict*) prefer 2 apply(rule NonEmptyListHasTailElem) apply(force) apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y db e1b n cb natc cc a list)(*strict*) apply(thin_tac "cc=a#list") apply(clarsimp) apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y db e1b n cb natc w')(*strict*) apply(subgoal_tac "take (Suc natc) za = w'@Do#c") apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y db e1b n cb natc w')(*strict*) prefer 2 apply(rule sym) apply(rule_tac w="cb" in append_linj) apply(metis concat_asso) apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y db e1b n cb natc w')(*strict*) apply(clarsimp) apply(case_tac za) apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y db e1b n cb natc w')(*strict*) apply(force) apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y db e1b n cb natc w' a list)(*strict*) apply(subgoal_tac "\<exists>w' x'. za = w' @ [x']") apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y db e1b n cb natc w' a list)(*strict*) prefer 2 apply(rule NonEmptyListHasTailElem) apply(force) apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y db e1b n cb natc w' a list)(*strict*) apply(thin_tac "za=a#list") apply(clarsimp) apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y db e1b n cb natc w' w'a x')(*strict*) apply(case_tac c) apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y db e1b n cb natc w' w'a x')(*strict*) apply(force) apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y db e1b n cb natc w' w'a x' a list)(*strict*) apply(subgoal_tac "\<exists>w' x'. c = w' @ [x']") apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y db e1b n cb natc w' w'a x' a list)(*strict*) prefer 2 apply(rule NonEmptyListHasTailElem) apply(force) apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y db e1b n cb natc w' w'a x' a list)(*strict*) apply(thin_tac "c=a#list") apply(clarsimp) apply(rename_tac d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y db e1b n cb natc w' w'a x' w'b x'a)(*strict*) apply(subgoal_tac "teB Do \<in> set (liftB w'a)") apply(rename_tac d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y db e1b n cb natc w' w'a x' w'b x'a)(*strict*) apply(subgoal_tac "teB Do \<notin> set (liftB w'a)") apply(rename_tac d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y db e1b n cb natc w' w'a x' w'b x'a)(*strict*) apply(force) apply(rename_tac d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y db e1b n cb natc w' w'a x' w'b x'a)(*strict*) apply(thin_tac "teB Do \<in> set (liftB w'a)") apply(rule_tac B="set(liftB (w'a @ [x']))" in nset_mp) apply(rename_tac d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y db e1b n cb natc w' w'a x' w'b x'a)(*strict*) apply (smt set_liftB_commute set_app_subset) apply(rename_tac d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y db e1b n cb natc w' w'a x' w'b x'a)(*strict*) apply(rule_tac B="set(take k w3)" in nset_mp) apply(rename_tac d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y db e1b n cb natc w' w'a x' w'b x'a)(*strict*) apply(force) apply(rename_tac d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y db e1b n cb natc w' w'a x' w'b x'a)(*strict*) apply(rule_tac B="set w3" in nset_mp) apply(rename_tac d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y db e1b n cb natc w' w'a x' w'b x'a)(*strict*) apply(rule List.set_take_subset) apply(rename_tac d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y db e1b n cb natc w' w'a x' w'b x'a)(*strict*) apply(rule_tac B="two_elements_construct_domain (cfg_nonterminals G) (cfg_events G)" in nset_mp) apply(rename_tac d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y db e1b n cb natc w' w'a x' w'b x'a)(*strict*) apply(force) apply(rename_tac d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y db e1b n cb natc w' w'a x' w'b x'a)(*strict*) apply(simp add: AF_LR_PARSER_input_def F_CFG_AUGMENT_def two_elements_construct_domain_def) apply(clarsimp) apply(subgoal_tac "F_FRESH (cfg_events G) \<notin> cfg_events G") apply(rename_tac d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y db e1b n cb natc w' w'a x' w'b x'a)(*strict*) apply(force) apply(rename_tac d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y db e1b n cb natc w' w'a x' w'b x'a)(*strict*) apply(rule F_FRESH_is_fresh) apply(simp add: AF_LR_PARSER_def AF_LR_PARSER_input_def valid_cfg_def) apply(rename_tac d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y db e1b n cb natc w' w'a x' w'b x'a)(*strict*) apply(case_tac "Suc natc - length w'a") apply(rename_tac d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y db e1b n cb natc w' w'a x' w'b x'a)(*strict*) apply(clarsimp) apply (metis set_liftB_insert take_reflects_mem) apply(rename_tac d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y db e1b n cb natc w' w'a x' w'b x'a natd)(*strict*) apply(clarsimp) apply(rename_tac d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y db e1b n cb natc w' w'b x'a natd)(*strict*) apply (metis head_in_set set_liftB_insert set_append_contra2) done theorem no_shift_shift_conflicts: " AF_LR_PARSER_input G F Do S' G' M P k \<Longrightarrow> (parser_marker P) r1 = Some None \<Longrightarrow> (parser_marker P) r2 = Some None \<Longrightarrow> r1 \<in> parser_rules P \<Longrightarrow> r2 \<in> parser_rules P \<Longrightarrow> rule_lpop r2 \<sqsupseteq> rule_lpop r1 \<or> rule_lpop r1 \<sqsupseteq> rule_lpop r2 \<Longrightarrow> rule_rpop r1 \<sqsubseteq> rule_rpop r2 \<or> rule_rpop r2 \<sqsubseteq> rule_rpop r1 \<Longrightarrow> r1 = r2" apply(case_tac r1) apply(rename_tac rule_lpopa rule_rpopa rule_lpush rule_rpush)(*strict*) apply(subgoal_tac " \<exists>q\<delta> y \<beta> z A \<alpha> a \<delta>. y \<in> (cfgSTD_first G' (k- 1) (\<beta>@(liftB z))) \<and> \<lparr>prod_lhs=A,prod_rhs=\<alpha>@(teB a)#\<beta>\<rparr> \<in> cfg_productions G \<and> q\<delta>=last (F_DFA_GOTO_SEQUENCE M (epda_initial M) (teB Do#\<delta>)) \<and> \<lparr>cfg_item_lhs = A,cfg_item_rhs1 = \<alpha>,cfg_item_rhs2 = (teB a)#\<beta>,cfg_item_look_ahead = z\<rparr> \<in> valid_item_set G' k (teB Do#\<delta>) \<and> rule_lpopa=[q\<delta>] \<and> rule_rpopa=a#y \<and> rule_lpush=[q\<delta>,F_DFA_GOTO M q\<delta> (teB a)] \<and> rule_rpush=y") apply(rename_tac rule_lpopa rule_rpopa rule_lpush rule_rpush)(*strict*) prefer 2 apply(rule_tac S'="S'" and Do="Do" and G'="G'" and G="G" in X6_3_InformationOnRules_shift2) apply(rename_tac rule_lpopa rule_rpopa rule_lpush rule_rpush)(*strict*) apply(simp add: AF_LR_PARSER_input_def) apply(rename_tac rule_lpopa rule_rpopa rule_lpush rule_rpush)(*strict*) apply(simp add: AF_LR_PARSER_input_def) apply(force) apply(simp add: AF_LR_PARSER_input_def) apply(rename_tac rule_lpopa rule_rpopa rule_lpush rule_rpush)(*strict*) apply(simp add: AF_LR_PARSER_input_def) apply(rename_tac rule_lpopa rule_rpopa rule_lpush rule_rpush)(*strict*) apply(simp add: AF_LR_PARSER_input_def) apply(rename_tac rule_lpopa rule_rpopa rule_lpush rule_rpush)(*strict*) apply(simp add: AF_LR_PARSER_input_def) apply(rename_tac rule_lpopa rule_rpopa rule_lpush rule_rpush)(*strict*) apply(force) apply(rename_tac rule_lpopa rule_rpopa rule_lpush rule_rpush)(*strict*) apply(force) apply(rename_tac rule_lpopa rule_rpopa rule_lpush rule_rpush)(*strict*) apply(simp add: AF_LR_PARSER_input_def) apply(rename_tac rule_lpopa rule_rpopa rule_lpush rule_rpush)(*strict*) apply(simp add: AF_LR_PARSER_input_def) apply(rename_tac rule_lpopa rule_rpopa rule_lpush rule_rpush)(*strict*) apply(case_tac r2) apply(rename_tac rule_lpopa rule_rpopa rule_lpush rule_rpush rule_lpopaa rule_rpopaa rule_lpusha rule_rpusha)(*strict*) apply(subgoal_tac " \<exists>q\<delta> y \<beta> z A \<alpha> a \<delta>. y \<in> (cfgSTD_first G' (k- 1) (\<beta>@(liftB z))) \<and> \<lparr>prod_lhs=A,prod_rhs=\<alpha>@(teB a)#\<beta>\<rparr> \<in> cfg_productions G \<and> q\<delta>=last (F_DFA_GOTO_SEQUENCE M (epda_initial M) (teB Do#\<delta>)) \<and> \<lparr>cfg_item_lhs = A,cfg_item_rhs1 = \<alpha>,cfg_item_rhs2 = (teB a)#\<beta>,cfg_item_look_ahead = z\<rparr> \<in> valid_item_set G' k (teB Do#\<delta>) \<and> rule_lpopaa=[q\<delta>] \<and> rule_rpopaa=a#y \<and> rule_lpusha=[q\<delta>,F_DFA_GOTO M q\<delta> (teB a)] \<and> rule_rpusha=y") apply(rename_tac rule_lpopa rule_rpopa rule_lpush rule_rpush rule_lpopaa rule_rpopaa rule_lpusha rule_rpusha)(*strict*) prefer 2 apply(rule_tac S'="S'" and Do="Do" and G'="G'" and G="G" in X6_3_InformationOnRules_shift2) apply(rename_tac rule_lpopa rule_rpopa rule_lpush rule_rpush rule_lpopaa rule_rpopaa rule_lpusha rule_rpusha)(*strict*) apply(simp add: AF_LR_PARSER_input_def) apply(rename_tac rule_lpopa rule_rpopa rule_lpush rule_rpush rule_lpopaa rule_rpopaa rule_lpusha rule_rpusha)(*strict*) apply(simp add: AF_LR_PARSER_input_def) apply(force) apply(simp add: AF_LR_PARSER_input_def) apply(rename_tac rule_lpopa rule_rpopa rule_lpush rule_rpush rule_lpopaa rule_rpopaa rule_lpusha rule_rpusha)(*strict*) apply(simp add: AF_LR_PARSER_input_def) apply(rename_tac rule_lpopa rule_rpopa rule_lpush rule_rpush rule_lpopaa rule_rpopaa rule_lpusha rule_rpusha)(*strict*) apply(simp add: AF_LR_PARSER_input_def) apply(rename_tac rule_lpopa rule_rpopa rule_lpush rule_rpush rule_lpopaa rule_rpopaa rule_lpusha rule_rpusha)(*strict*) apply(simp add: AF_LR_PARSER_input_def) apply(rename_tac rule_lpopa rule_rpopa rule_lpush rule_rpush rule_lpopaa rule_rpopaa rule_lpusha rule_rpusha)(*strict*) apply(force) apply(rename_tac rule_lpopa rule_rpopa rule_lpush rule_rpush rule_lpopaa rule_rpopaa rule_lpusha rule_rpusha)(*strict*) apply(force) apply(rename_tac rule_lpopa rule_rpopa rule_lpush rule_rpush rule_lpopaa rule_rpopaa rule_lpusha rule_rpusha)(*strict*) apply(simp add: AF_LR_PARSER_input_def) apply(rename_tac rule_lpopa rule_rpopa rule_lpush rule_rpush rule_lpopaa rule_rpopaa rule_lpusha rule_rpusha)(*strict*) apply(simp add: AF_LR_PARSER_input_def) apply(rename_tac rule_lpopa rule_rpopa rule_lpush rule_rpush rule_lpopaa rule_rpopaa rule_lpusha rule_rpusha)(*strict*) apply(clarsimp) apply(rename_tac y ya \<beta> \<beta>' z za A \<alpha> a Aa \<alpha>' aa \<delta> \<delta>')(*strict*) apply(subgoal_tac "a=aa") apply(rename_tac y ya \<beta> \<beta>' z za A \<alpha> a Aa \<alpha>' aa \<delta> \<delta>')(*strict*) prefer 2 apply(erule_tac P="(a # y) \<sqsubseteq> (aa # ya)" in disjE) apply(rename_tac y ya \<beta> \<beta>' z za A \<alpha> a Aa \<alpha>' aa \<delta> \<delta>')(*strict*) apply(simp add: prefix_def) apply(rename_tac y ya \<beta> \<beta>' z za A \<alpha> a Aa \<alpha>' aa \<delta> \<delta>')(*strict*) apply(simp add: prefix_def) apply(rename_tac y ya \<beta> \<beta>' z za A \<alpha> a Aa \<alpha>' aa \<delta> \<delta>')(*strict*) apply(clarsimp) apply(rename_tac y ya \<beta> \<beta>' z za A \<alpha> Aa \<alpha>' aa \<delta> \<delta>')(*strict*) apply(subgoal_tac "[last (F_DFA_GOTO_SEQUENCE M (epda_initial M) (teB Do # \<delta>'))] = [last (F_DFA_GOTO_SEQUENCE M (epda_initial M) (teB Do # \<delta>))]") apply(rename_tac y ya \<beta> \<beta>' z za A \<alpha> Aa \<alpha>' aa \<delta> \<delta>')(*strict*) prefer 2 apply(erule_tac P="[last (F_DFA_GOTO_SEQUENCE M (epda_initial M) (teB Do # \<delta>'))] \<sqsupseteq> [last (F_DFA_GOTO_SEQUENCE M (epda_initial M) (teB Do # \<delta>))]" in disjE) apply(rename_tac y ya \<beta> \<beta>' z za A \<alpha> Aa \<alpha>' aa \<delta> \<delta>')(*strict*) apply(simp add: suffix_def) apply(rename_tac y ya \<beta> \<beta>' z za A \<alpha> Aa \<alpha>' aa \<delta> \<delta>')(*strict*) apply(simp add: suffix_def) apply(rename_tac y ya \<beta> \<beta>' z za A \<alpha> Aa \<alpha>' aa \<delta> \<delta>')(*strict*) apply(clarsimp) apply(thin_tac "parser_marker P \<lparr>rule_lpop = [last (F_DFA_GOTO_SEQUENCE M (epda_initial M) (teB Do # \<delta>))], rule_rpop = aa # y, rule_lpush = [last (F_DFA_GOTO_SEQUENCE M (epda_initial M) (teB Do # \<delta>)), F_DFA_GOTO M (last (F_DFA_GOTO_SEQUENCE M (epda_initial M) (teB Do # \<delta>))) (teB aa)], rule_rpush = y\<rparr> = Some None") apply(rename_tac y ya \<beta> \<beta>' z za A \<alpha> Aa \<alpha>' aa \<delta> \<delta>')(*strict*) apply(thin_tac "parser_marker P \<lparr>rule_lpop = [last (F_DFA_GOTO_SEQUENCE M (epda_initial M) (teB Do # \<delta>))], rule_rpop = aa # ya, rule_lpush = [last (F_DFA_GOTO_SEQUENCE M (epda_initial M) (teB Do # \<delta>)), F_DFA_GOTO M (last (F_DFA_GOTO_SEQUENCE M (epda_initial M) (teB Do # \<delta>))) (teB aa)], rule_rpush = ya\<rparr> = Some None") apply(rename_tac y ya \<beta> \<beta>' z za A \<alpha> Aa \<alpha>' aa \<delta> \<delta>')(*strict*) apply(thin_tac "\<lparr>rule_lpop = [last (F_DFA_GOTO_SEQUENCE M (epda_initial M) (teB Do # \<delta>))], rule_rpop = aa # y, rule_lpush = [last (F_DFA_GOTO_SEQUENCE M (epda_initial M) (teB Do # \<delta>)), F_DFA_GOTO M (last (F_DFA_GOTO_SEQUENCE M (epda_initial M) (teB Do # \<delta>))) (teB aa)], rule_rpush = y\<rparr> \<in> parser_rules P") apply(rename_tac y ya \<beta> \<beta>' z za A \<alpha> Aa \<alpha>' aa \<delta> \<delta>')(*strict*) apply(thin_tac "\<lparr>rule_lpop = [last (F_DFA_GOTO_SEQUENCE M (epda_initial M) (teB Do # \<delta>))], rule_rpop = aa # ya, rule_lpush = [last (F_DFA_GOTO_SEQUENCE M (epda_initial M) (teB Do # \<delta>)), F_DFA_GOTO M (last (F_DFA_GOTO_SEQUENCE M (epda_initial M) (teB Do # \<delta>))) (teB aa)], rule_rpush = ya\<rparr> \<in> parser_rules P") apply(rename_tac y ya \<beta> \<beta>' z za A \<alpha> Aa \<alpha>' aa \<delta> \<delta>')(*strict*) apply(thin_tac "[last (F_DFA_GOTO_SEQUENCE M (epda_initial M) (teB Do # \<delta>))] \<sqsupseteq> [last (F_DFA_GOTO_SEQUENCE M (epda_initial M) (teB Do # \<delta>))]") apply(rename_tac y ya \<beta> \<beta>' z za A \<alpha> Aa \<alpha>' aa \<delta> \<delta>')(*strict*) apply(erule disjE) apply(rename_tac y ya \<beta> \<beta>' z za A \<alpha> Aa \<alpha>' aa \<delta> \<delta>')(*strict*) apply(rule no_shift_shift_conflicts1) apply(rename_tac y ya \<beta> \<beta>' z za A \<alpha> Aa \<alpha>' aa \<delta> \<delta>')(*strict*) apply(force) apply(rename_tac y ya \<beta> \<beta>' z za A \<alpha> Aa \<alpha>' aa \<delta> \<delta>')(*strict*) apply(force) apply(rename_tac y ya \<beta> \<beta>' z za A \<alpha> Aa \<alpha>' aa \<delta> \<delta>')(*strict*) apply(force) apply(rename_tac y ya \<beta> \<beta>' z za A \<alpha> Aa \<alpha>' aa \<delta> \<delta>')(*strict*) apply(force) apply(rename_tac y ya \<beta> \<beta>' z za A \<alpha> Aa \<alpha>' aa \<delta> \<delta>')(*strict*) apply(force) apply(rename_tac y ya \<beta> \<beta>' z za A \<alpha> Aa \<alpha>' aa \<delta> \<delta>')(*strict*) apply(force) apply(rename_tac y ya \<beta> \<beta>' z za A \<alpha> Aa \<alpha>' aa \<delta> \<delta>')(*strict*) apply(force) apply(rename_tac y ya \<beta> \<beta>' z za A \<alpha> Aa \<alpha>' aa \<delta> \<delta>')(*strict*) apply(force) apply(rename_tac y ya \<beta> \<beta>' z za A \<alpha> Aa \<alpha>' aa \<delta> \<delta>')(*strict*) apply(force) apply(rename_tac y ya \<beta> \<beta>' z za A \<alpha> Aa \<alpha>' aa \<delta> \<delta>')(*strict*) apply(rule sym) apply(rule no_shift_shift_conflicts1) apply(rename_tac y ya \<beta> \<beta>' z za A \<alpha> Aa \<alpha>' aa \<delta> \<delta>')(*strict*) apply(force) apply(rename_tac y ya \<beta> \<beta>' z za A \<alpha> Aa \<alpha>' aa \<delta> \<delta>')(*strict*) apply(force) apply(rename_tac y ya \<beta> \<beta>' z za A \<alpha> Aa \<alpha>' aa \<delta> \<delta>')(*strict*) apply(force) apply(rename_tac y ya \<beta> \<beta>' z za A \<alpha> Aa \<alpha>' aa \<delta> \<delta>')(*strict*) apply(force) apply(rename_tac y ya \<beta> \<beta>' z za A \<alpha> Aa \<alpha>' aa \<delta> \<delta>')(*strict*) apply(force) apply(rename_tac y ya \<beta> \<beta>' z za A \<alpha> Aa \<alpha>' aa \<delta> \<delta>')(*strict*) apply(force) apply(rename_tac y ya \<beta> \<beta>' z za A \<alpha> Aa \<alpha>' aa \<delta> \<delta>')(*strict*) apply(force) apply(rename_tac y ya \<beta> \<beta>' z za A \<alpha> Aa \<alpha>' aa \<delta> \<delta>')(*strict*) apply(force) apply(rename_tac y ya \<beta> \<beta>' z za A \<alpha> Aa \<alpha>' aa \<delta> \<delta>')(*strict*) apply(force) done lemma no_reduce_reduce_conflicts_hlp: " AF_LR_PARSER_input G F Do S' G' M P k \<Longrightarrow> valid_cfg G' \<Longrightarrow> \<lparr>cfg_item_lhs = A1, cfg_item_rhs1 = w1, cfg_item_rhs2 = [], cfg_item_look_ahead = y1\<rparr> \<in> valid_item_set G' k (teB Do # w) \<Longrightarrow> \<lparr>cfg_item_lhs = A2, cfg_item_rhs1 = w2, cfg_item_rhs2 = [], cfg_item_look_ahead = y2\<rparr> \<in> valid_item_set G' k (teB Do # w) \<Longrightarrow> prefix y1 y2 \<Longrightarrow> y1 = y2" apply(simp add: valid_item_set_def valid_item_set_n_def prefix_def) apply(clarsimp) apply(rename_tac n na c d da \<delta> e1 e2 z \<delta>' e1a e2a za)(*strict*) apply(subgoal_tac "\<exists>e c. d (Suc 0) = Some (pair e c)") apply(rename_tac n na c d da \<delta> e1 e2 z \<delta>' e1a e2a za)(*strict*) prefer 2 apply(rule_tac m="Suc n" in cfgRM.pre_some_position_is_some_position) apply(rename_tac n na c d da \<delta> e1 e2 z \<delta>' e1a e2a za)(*strict*) apply(force) apply(rename_tac n na c d da \<delta> e1 e2 z \<delta>' e1a e2a za)(*strict*) apply(force) apply(rename_tac n na c d da \<delta> e1 e2 z \<delta>' e1a e2a za)(*strict*) apply(force) apply(rename_tac n na c d da \<delta> e1 e2 z \<delta>' e1a e2a za)(*strict*) apply(subgoal_tac "\<exists>e c. da (Suc 0) = Some (pair e c)") apply(rename_tac n na c d da \<delta> e1 e2 z \<delta>' e1a e2a za)(*strict*) prefer 2 apply(rule_tac m="Suc na" in cfgRM.pre_some_position_is_some_position) apply(rename_tac n na c d da \<delta> e1 e2 z \<delta>' e1a e2a za)(*strict*) apply(force) apply(rename_tac n na c d da \<delta> e1 e2 z \<delta>' e1a e2a za)(*strict*) apply(force) apply(rename_tac n na c d da \<delta> e1 e2 z \<delta>' e1a e2a za)(*strict*) apply(force) apply(rename_tac n na c d da \<delta> e1 e2 z \<delta>' e1a e2a za)(*strict*) apply(clarsimp) apply(rename_tac n na c d da \<delta> e1 e2 z \<delta>' e1a e2a za e ea ca cb)(*strict*) apply(subgoal_tac "teB Do \<notin> two_elements_construct_domain (cfg_nonterminals G) (cfg_events G)") apply(rename_tac n na c d da \<delta> e1 e2 z \<delta>' e1a e2a za e ea ca cb)(*strict*) prefer 2 apply(simp add: AF_LR_PARSER_input_def F_CFG_AUGMENT_def two_elements_construct_domain_def) apply(clarsimp) apply(rule conjI) apply(rename_tac n na c d da \<delta> e1 e2 z \<delta>' e1a e2a za e ea ca cb)(*strict*) apply(force) apply(rename_tac n na c d da \<delta> e1 e2 z \<delta>' e1a e2a za e ea ca cb)(*strict*) apply(clarsimp) apply(subgoal_tac "F_FRESH (cfg_events G) \<notin> cfg_events G") apply(rename_tac n na c d da \<delta> e1 e2 z \<delta>' e1a e2a za e ea ca cb)(*strict*) apply(force) apply(rename_tac n na c d da \<delta> e1 e2 z \<delta>' e1a e2a za e ea ca cb)(*strict*) apply(rule F_FRESH_is_fresh) apply(simp add: F_LR_MACHINE_def F_CFG_AUGMENT_def two_elements_construct_domain_def valid_cfg_def) apply(rename_tac n na c d da \<delta> e1 e2 z \<delta>' e1a e2a za e ea ca cb)(*strict*) apply(subgoal_tac "\<exists>w. set w \<subseteq> two_elements_construct_domain (cfg_nonterminals G) (cfg_events G) \<and> cfg_conf ca=[teB Do]@w@[teB Do]") apply(rename_tac n na c d da \<delta> e1 e2 z \<delta>' e1a e2a za e ea ca cb)(*strict*) prefer 2 apply(rule_tac d="d" and i="0" in F_CFG_AUGMENT__reachableConf_of_certain_form) apply(rename_tac n na c d da \<delta> e1 e2 z \<delta>' e1a e2a za e ea ca cb)(*strict*) apply(simp add: F_CFG_AUGMENT__input_def AF_LR_PARSER_input_def) apply(rename_tac n na c d da \<delta> e1 e2 z \<delta>' e1a e2a za e ea ca cb)(*strict*) apply(rule cfgSTD.derivation_initialI) apply(rename_tac n na c d da \<delta> e1 e2 z \<delta>' e1a e2a za e ea ca cb)(*strict*) apply(rule cfgRM_derivations_are_cfg_derivations) apply(simp add: F_CFG_AUGMENT__input_def AF_LR_PARSER_input_def) apply(rename_tac n na c d da \<delta> e1 e2 z \<delta>' e1a e2a za e ea ca cb)(*strict*) apply(simp add: cfg_initial_configurations_def get_configuration_def cfg_configurations_def valid_cfg_def) apply(simp add: F_CFG_AUGMENT__input_def AF_LR_PARSER_input_def) apply(rename_tac n na c d da \<delta> e1 e2 z \<delta>' e1a e2a za e ea ca cb)(*strict*) apply(force) apply(rename_tac n na c d da \<delta> e1 e2 z \<delta>' e1a e2a za e ea ca cb)(*strict*) apply(subgoal_tac "\<exists>w. set w \<subseteq> two_elements_construct_domain (cfg_nonterminals G) (cfg_events G) \<and> cfg_conf cb=[teB Do]@w@[teB Do]") apply(rename_tac n na c d da \<delta> e1 e2 z \<delta>' e1a e2a za e ea ca cb)(*strict*) prefer 2 apply(rule_tac d="da" and i="0" in F_CFG_AUGMENT__reachableConf_of_certain_form) apply(rename_tac n na c d da \<delta> e1 e2 z \<delta>' e1a e2a za e ea ca cb)(*strict*) apply(simp add: F_CFG_AUGMENT__input_def AF_LR_PARSER_input_def) apply(rename_tac n na c d da \<delta> e1 e2 z \<delta>' e1a e2a za e ea ca cb)(*strict*) apply(rule cfgSTD.derivation_initialI) apply(rename_tac n na c d da \<delta> e1 e2 z \<delta>' e1a e2a za e ea ca cb)(*strict*) apply(rule cfgRM_derivations_are_cfg_derivations) apply(simp add: F_CFG_AUGMENT__input_def AF_LR_PARSER_input_def) apply(rename_tac n na c d da \<delta> e1 e2 z \<delta>' e1a e2a za e ea ca cb)(*strict*) apply(simp add: cfg_initial_configurations_def get_configuration_def cfg_configurations_def valid_cfg_def) apply(simp add: F_CFG_AUGMENT__input_def AF_LR_PARSER_input_def) apply(rename_tac n na c d da \<delta> e1 e2 z \<delta>' e1a e2a za e ea ca cb)(*strict*) apply(force) apply(rename_tac n na c d da \<delta> e1 e2 z \<delta>' e1a e2a za e ea ca cb)(*strict*) apply(subgoal_tac "\<exists>w. set w \<subseteq> two_elements_construct_domain (cfg_nonterminals G) (cfg_events G) \<and> cfg_conf \<lparr>cfg_conf = \<delta> @ w1 @ z\<rparr>=[teB Do]@w@[teB Do]") apply(rename_tac n na c d da \<delta> e1 e2 z \<delta>' e1a e2a za e ea ca cb)(*strict*) prefer 2 apply(rule_tac d="d" and i="n" in F_CFG_AUGMENT__reachableConf_of_certain_form) apply(rename_tac n na c d da \<delta> e1 e2 z \<delta>' e1a e2a za e ea ca cb)(*strict*) apply(simp add: F_CFG_AUGMENT__input_def AF_LR_PARSER_input_def) apply(rename_tac n na c d da \<delta> e1 e2 z \<delta>' e1a e2a za e ea ca cb)(*strict*) apply(rule cfgSTD.derivation_initialI) apply(rename_tac n na c d da \<delta> e1 e2 z \<delta>' e1a e2a za e ea ca cb)(*strict*) apply(rule cfgRM_derivations_are_cfg_derivations) apply(simp add: F_CFG_AUGMENT__input_def AF_LR_PARSER_input_def) apply(rename_tac n na c d da \<delta> e1 e2 z \<delta>' e1a e2a za e ea ca cb)(*strict*) apply(simp add: cfg_initial_configurations_def get_configuration_def cfg_configurations_def valid_cfg_def) apply(simp add: F_CFG_AUGMENT__input_def AF_LR_PARSER_input_def) apply(rename_tac n na c d da \<delta> e1 e2 z \<delta>' e1a e2a za e ea ca cb)(*strict*) apply(force) apply(rename_tac n na c d da \<delta> e1 e2 z \<delta>' e1a e2a za e ea ca cb)(*strict*) apply(subgoal_tac "\<exists>w. set w \<subseteq> two_elements_construct_domain (cfg_nonterminals G) (cfg_events G) \<and> cfg_conf \<lparr>cfg_conf = \<delta>' @ w2 @ za\<rparr>=[teB Do]@w@[teB Do]") apply(rename_tac n na c d da \<delta> e1 e2 z \<delta>' e1a e2a za e ea ca cb)(*strict*) prefer 2 apply(rule_tac d="da" and i="na" in F_CFG_AUGMENT__reachableConf_of_certain_form) apply(rename_tac n na c d da \<delta> e1 e2 z \<delta>' e1a e2a za e ea ca cb)(*strict*) apply(simp add: F_CFG_AUGMENT__input_def AF_LR_PARSER_input_def) apply(rename_tac n na c d da \<delta> e1 e2 z \<delta>' e1a e2a za e ea ca cb)(*strict*) apply(rule cfgSTD.derivation_initialI) apply(rename_tac n na c d da \<delta> e1 e2 z \<delta>' e1a e2a za e ea ca cb)(*strict*) apply(rule cfgRM_derivations_are_cfg_derivations) apply(simp add: F_CFG_AUGMENT__input_def AF_LR_PARSER_input_def) apply(rename_tac n na c d da \<delta> e1 e2 z \<delta>' e1a e2a za e ea ca cb)(*strict*) apply(simp add: cfg_initial_configurations_def get_configuration_def cfg_configurations_def valid_cfg_def) apply(simp add: F_CFG_AUGMENT__input_def AF_LR_PARSER_input_def) apply(rename_tac n na c d da \<delta> e1 e2 z \<delta>' e1a e2a za e ea ca cb)(*strict*) apply(force) apply(rename_tac n na c d da \<delta> e1 e2 z \<delta>' e1a e2a za e ea ca cb)(*strict*) apply(clarsimp) apply(rename_tac n na c d da \<delta> e1 e2 z \<delta>' e1a e2a za e ea ca cb wa waa wb wc)(*strict*) apply(case_tac ca) apply(rename_tac n na c d da \<delta> e1 e2 z \<delta>' e1a e2a za e ea ca cb wa waa wb wc cfg_confa)(*strict*) apply(case_tac cb) apply(rename_tac n na c d da \<delta> e1 e2 z \<delta>' e1a e2a za e ea ca cb wa waa wb wc cfg_confa cfg_confaa)(*strict*) apply(clarsimp) apply(rename_tac n na c d da \<delta> e1 e2 z \<delta>' e1a e2a za e ea wa waa wb wc)(*strict*) apply(case_tac n) apply(rename_tac n na c d da \<delta> e1 e2 z \<delta>' e1a e2a za e ea wa waa wb wc)(*strict*) apply(clarsimp) apply(rename_tac na c d da \<delta> e2 z \<delta>' e1a e2a za ea wa wb wc)(*strict*) apply(case_tac "\<delta>") apply(rename_tac na c d da \<delta> e2 z \<delta>' e1a e2a za ea wa wb wc)(*strict*) prefer 2 apply(rename_tac na c d da \<delta> e2 z \<delta>' e1a e2a za ea wa wb wc a list)(*strict*) apply(clarsimp) apply(rename_tac na c d da \<delta> e2 z \<delta>' e1a e2a za ea wa wb wc)(*strict*) apply(clarsimp) apply(rename_tac na c d da e2 \<delta>' e1a e2a za ea wa wb wc)(*strict*) apply(case_tac y1) apply(rename_tac na c d da e2 \<delta>' e1a e2a za ea wa wb wc)(*strict*) prefer 2 apply(rename_tac na c d da e2 \<delta>' e1a e2a za ea wa wb wc a list)(*strict*) apply(clarsimp) apply(rename_tac na c d da e2 \<delta>' e1a e2a za ea wa wb wc)(*strict*) apply(clarsimp) apply(case_tac na) apply(rename_tac na c d da e2 \<delta>' e1a e2a za ea wa wb wc)(*strict*) apply(clarsimp) apply(rename_tac c d da e2 \<delta>' e2a za wb wc)(*strict*) apply(case_tac "\<delta>'") apply(rename_tac c d da e2 \<delta>' e2a za wb wc)(*strict*) prefer 2 apply(rename_tac c d da e2 \<delta>' e2a za wb wc a list)(*strict*) apply(clarsimp) apply(rename_tac c d da e2 \<delta>' e2a za wb wc)(*strict*) apply(clarsimp) apply(rename_tac c d da e2 e2a wc)(*strict*) apply(case_tac c) apply(rename_tac c d da e2 e2a wc)(*strict*) apply(force) apply(rename_tac c d da e2 e2a wc a list)(*strict*) apply(force) apply(rename_tac na c d da e2 \<delta>' e1a e2a za ea wa wb wc nat)(*strict*) apply(clarsimp) apply(rename_tac c d da e2 \<delta>' e1a e2a za ea wa wb wc nat)(*strict*) apply(subgoal_tac "\<exists>w. set w \<subseteq> two_elements_construct_domain (cfg_nonterminals G) (cfg_events G) \<and> cfg_conf \<lparr>cfg_conf = \<delta>' @ teA A2 # za\<rparr>=[teB Do]@w@[teB Do]") apply(rename_tac c d da e2 \<delta>' e1a e2a za ea wa wb wc nat)(*strict*) prefer 2 apply(rule_tac d="da" and i="nat" in F_CFG_AUGMENT__reachableConf_of_certain_form) apply(rename_tac c d da e2 \<delta>' e1a e2a za ea wa wb wc nat)(*strict*) apply(simp add: F_CFG_AUGMENT__input_def AF_LR_PARSER_input_def) apply(rename_tac c d da e2 \<delta>' e1a e2a za ea wa wb wc nat)(*strict*) apply(rule cfgSTD.derivation_initialI) apply(rename_tac c d da e2 \<delta>' e1a e2a za ea wa wb wc nat)(*strict*) apply(rule cfgRM_derivations_are_cfg_derivations) apply(simp add: F_CFG_AUGMENT__input_def AF_LR_PARSER_input_def) apply(rename_tac c d da e2 \<delta>' e1a e2a za ea wa wb wc nat)(*strict*) apply(simp add: cfg_initial_configurations_def get_configuration_def cfg_configurations_def valid_cfg_def) apply(simp add: F_CFG_AUGMENT__input_def AF_LR_PARSER_input_def) apply(rename_tac c d da e2 \<delta>' e1a e2a za ea wa wb wc nat)(*strict*) apply(force) apply(rename_tac c d da e2 \<delta>' e1a e2a za ea wa wb wc nat)(*strict*) apply(subgoal_tac "\<exists>w. set w \<subseteq> two_elements_construct_domain (cfg_nonterminals G) (cfg_events G) \<and> cfg_conf \<lparr>cfg_conf = teB Do # wc @ [teB Do]\<rparr>=[teB Do]@w@[teB Do]") apply(rename_tac c d da e2 \<delta>' e1a e2a za ea wa wb wc nat)(*strict*) prefer 2 apply(rule_tac d="da" and i="Suc nat" in F_CFG_AUGMENT__reachableConf_of_certain_form) apply(rename_tac c d da e2 \<delta>' e1a e2a za ea wa wb wc nat)(*strict*) apply(simp add: F_CFG_AUGMENT__input_def AF_LR_PARSER_input_def) apply(rename_tac c d da e2 \<delta>' e1a e2a za ea wa wb wc nat)(*strict*) apply(rule cfgSTD.derivation_initialI) apply(rename_tac c d da e2 \<delta>' e1a e2a za ea wa wb wc nat)(*strict*) apply(rule cfgRM_derivations_are_cfg_derivations) apply(simp add: F_CFG_AUGMENT__input_def AF_LR_PARSER_input_def) apply(rename_tac c d da e2 \<delta>' e1a e2a za ea wa wb wc nat)(*strict*) apply(simp add: cfg_initial_configurations_def get_configuration_def cfg_configurations_def valid_cfg_def) apply(simp add: F_CFG_AUGMENT__input_def AF_LR_PARSER_input_def) apply(rename_tac c d da e2 \<delta>' e1a e2a za ea wa wb wc nat)(*strict*) apply(force) apply(rename_tac c d da e2 \<delta>' e1a e2a za ea wa wb wc nat)(*strict*) apply(clarsimp) apply(rename_tac c d da e2 \<delta>' e1a e2a za ea wa wb wc nat w)(*strict*) apply(case_tac w2) apply(rename_tac c d da e2 \<delta>' e1a e2a za ea wa wb wc nat w)(*strict*) apply(clarsimp) apply(rename_tac c d da e2 e1a e2a za ea wa wb wc nat w)(*strict*) apply(case_tac za) apply(rename_tac c d da e2 e1a e2a za ea wa wb wc nat w)(*strict*) apply(clarsimp) apply(rename_tac c d da e2 e1a e2a za ea wa wb wc nat w a list)(*strict*) apply(subgoal_tac "\<exists>w' x'. za = w' @ [x']") apply(rename_tac c d da e2 e1a e2a za ea wa wb wc nat w a list)(*strict*) prefer 2 apply(rule NonEmptyListHasTailElem) apply(force) apply(rename_tac c d da e2 e1a e2a za ea wa wb wc nat w a list)(*strict*) apply(thin_tac "za=a#list") apply(clarsimp) apply(rename_tac c d da e2 \<delta>' e1a e2a za ea wa wb wc nat w a list)(*strict*) apply(subgoal_tac "\<exists>w' x'. w2 = w' @ [x']") apply(rename_tac c d da e2 \<delta>' e1a e2a za ea wa wb wc nat w a list)(*strict*) prefer 2 apply(rule NonEmptyListHasTailElem) apply(force) apply(rename_tac c d da e2 \<delta>' e1a e2a za ea wa wb wc nat w a list)(*strict*) apply(thin_tac "w2=a#list") apply(clarsimp) apply(rename_tac c d da e2 \<delta>' e1a e2a za ea wa wb wc nat w w')(*strict*) apply(case_tac "\<delta>'") apply(rename_tac c d da e2 \<delta>' e1a e2a za ea wa wb wc nat w w')(*strict*) apply(clarsimp) apply(rename_tac c d da e2 \<delta>' e1a e2a za ea wa wb wc nat w w' a list)(*strict*) apply(clarsimp) apply(rename_tac c d da e2 e1a e2a za ea wa wc nat w w' list)(*strict*) apply(case_tac za) apply(rename_tac c d da e2 e1a e2a za ea wa wc nat w w' list)(*strict*) apply(clarsimp) apply(rename_tac c d da e2 e1a e2a za ea wa wc nat w w' list a lista)(*strict*) apply(subgoal_tac "\<exists>w' x'. za = w' @ [x']") apply(rename_tac c d da e2 e1a e2a za ea wa wc nat w w' list a lista)(*strict*) prefer 2 apply(rule NonEmptyListHasTailElem) apply(force) apply(rename_tac c d da e2 e1a e2a za ea wa wc nat w w' list a lista)(*strict*) apply(thin_tac "za=a#lista") apply(clarsimp) apply(rename_tac n na c d da \<delta> e1 e2 z \<delta>' e1a e2a za e ea wa waa wb wc nat)(*strict*) apply(clarsimp) apply(rename_tac na c d da \<delta> e1 e2 z \<delta>' e1a e2a za e ea wa waa wb wc nat)(*strict*) apply(case_tac na) apply(rename_tac na c d da \<delta> e1 e2 z \<delta>' e1a e2a za e ea wa waa wb wc nat)(*strict*) apply(clarsimp) apply(rename_tac c d da \<delta> e1 e2 z \<delta>' e2a za e wa wb wc nat)(*strict*) apply(case_tac "\<delta>'") apply(rename_tac c d da \<delta> e1 e2 z \<delta>' e2a za e wa wb wc nat)(*strict*) prefer 2 apply(rename_tac c d da \<delta> e1 e2 z \<delta>' e2a za e wa wb wc nat a list)(*strict*) apply(clarsimp) apply(rename_tac c d da \<delta> e1 e2 z \<delta>' e2a za e wa wb wc nat)(*strict*) apply(clarsimp) apply(rename_tac c d da \<delta> e1 e2 z e2a e w wb wc nat)(*strict*) apply(case_tac c) apply(rename_tac c d da \<delta> e1 e2 z e2a e w wb wc nat)(*strict*) prefer 2 apply(rename_tac c d da \<delta> e1 e2 z e2a e w wb wc nat a list)(*strict*) apply(clarsimp) apply(rename_tac d da \<delta> e1 e2 z e2a e w wb wc nat a list)(*strict*) apply (metis Nil_is_append_conv liftB_reflects_Nil list.simps(3)) apply(rename_tac c d da \<delta> e1 e2 z e2a e w wb wc nat)(*strict*) apply(force) apply(rename_tac na c d da \<delta> e1 e2 z \<delta>' e1a e2a za e ea wa waa wb wc nat nata)(*strict*) apply(clarsimp) apply(rename_tac c d da \<delta> e1 e2 z \<delta>' e1a e2a za e ea wa waa wb wc nat nata)(*strict*) apply(subgoal_tac "\<exists>w. set w \<subseteq> two_elements_construct_domain (cfg_nonterminals G) (cfg_events G) \<and> cfg_conf \<lparr>cfg_conf = \<delta> @ teA A1 # z\<rparr>=[teB Do]@w@[teB Do]") apply(rename_tac c d da \<delta> e1 e2 z \<delta>' e1a e2a za e ea wa waa wb wc nat nata)(*strict*) prefer 2 apply(rule_tac d="d" and i="nat" in F_CFG_AUGMENT__reachableConf_of_certain_form) apply(rename_tac c d da \<delta> e1 e2 z \<delta>' e1a e2a za e ea wa waa wb wc nat nata)(*strict*) apply(simp add: F_CFG_AUGMENT__input_def AF_LR_PARSER_input_def) apply(rename_tac c d da \<delta> e1 e2 z \<delta>' e1a e2a za e ea wa waa wb wc nat nata)(*strict*) apply(rule cfgSTD.derivation_initialI) apply(rename_tac c d da \<delta> e1 e2 z \<delta>' e1a e2a za e ea wa waa wb wc nat nata)(*strict*) apply(rule cfgRM_derivations_are_cfg_derivations) apply(simp add: F_CFG_AUGMENT__input_def AF_LR_PARSER_input_def) apply(rename_tac c d da \<delta> e1 e2 z \<delta>' e1a e2a za e ea wa waa wb wc nat nata)(*strict*) apply(simp add: cfg_initial_configurations_def get_configuration_def cfg_configurations_def valid_cfg_def) apply(simp add: F_CFG_AUGMENT__input_def AF_LR_PARSER_input_def) apply(rename_tac c d da \<delta> e1 e2 z \<delta>' e1a e2a za e ea wa waa wb wc nat nata)(*strict*) apply(force) apply(rename_tac c d da \<delta> e1 e2 z \<delta>' e1a e2a za e ea wa waa wb wc nat nata)(*strict*) apply(subgoal_tac "\<exists>w. set w \<subseteq> two_elements_construct_domain (cfg_nonterminals G) (cfg_events G) \<and> cfg_conf \<lparr>cfg_conf = \<delta>' @ teA A2 # za\<rparr>=[teB Do]@w@[teB Do]") apply(rename_tac c d da \<delta> e1 e2 z \<delta>' e1a e2a za e ea wa waa wb wc nat nata)(*strict*) prefer 2 apply(rule_tac d="da" and i="nata" in F_CFG_AUGMENT__reachableConf_of_certain_form) apply(rename_tac c d da \<delta> e1 e2 z \<delta>' e1a e2a za e ea wa waa wb wc nat nata)(*strict*) apply(simp add: F_CFG_AUGMENT__input_def AF_LR_PARSER_input_def) apply(rename_tac c d da \<delta> e1 e2 z \<delta>' e1a e2a za e ea wa waa wb wc nat nata)(*strict*) apply(rule cfgSTD.derivation_initialI) apply(rename_tac c d da \<delta> e1 e2 z \<delta>' e1a e2a za e ea wa waa wb wc nat nata)(*strict*) apply(rule cfgRM_derivations_are_cfg_derivations) apply(simp add: F_CFG_AUGMENT__input_def AF_LR_PARSER_input_def) apply(rename_tac c d da \<delta> e1 e2 z \<delta>' e1a e2a za e ea wa waa wb wc nat nata)(*strict*) apply(simp add: cfg_initial_configurations_def get_configuration_def cfg_configurations_def valid_cfg_def) apply(simp add: F_CFG_AUGMENT__input_def AF_LR_PARSER_input_def) apply(rename_tac c d da \<delta> e1 e2 z \<delta>' e1a e2a za e ea wa waa wb wc nat nata)(*strict*) apply(force) apply(rename_tac c d da \<delta> e1 e2 z \<delta>' e1a e2a za e ea wa waa wb wc nat nata)(*strict*) apply(clarsimp) apply(rename_tac c d da \<delta> e1 e2 z \<delta>' e1a e2a za e ea wa waa wb wc nat nata wd we)(*strict*) apply(case_tac "\<delta>") apply(rename_tac c d da \<delta> e1 e2 z \<delta>' e1a e2a za e ea wa waa wb wc nat nata wd we)(*strict*) apply(clarsimp) apply(rename_tac c d da \<delta> e1 e2 z \<delta>' e1a e2a za e ea wa waa wb wc nat nata wd we a list)(*strict*) apply(clarsimp) apply(rename_tac c d da e1 e2 z \<delta>' e1a e2a za e ea w wa wb wc nat nata wd we list)(*strict*) apply(case_tac "\<delta>'") apply(rename_tac c d da e1 e2 z \<delta>' e1a e2a za e ea w wa wb wc nat nata wd we list)(*strict*) apply(clarsimp) apply(rename_tac c d da e1 e2 z \<delta>' e1a e2a za e ea w wa wb wc nat nata wd we list a lista)(*strict*) apply(clarsimp) apply(rename_tac c d da e1 e2 z e1a e2a za e ea w wa wb wc nat nata wd we list lista)(*strict*) apply(case_tac "z") apply(rename_tac c d da e1 e2 z e1a e2a za e ea w wa wb wc nat nata wd we list lista)(*strict*) apply(clarsimp) apply(rename_tac c d da e1 e2 z e1a e2a za e ea w wa wb wc nat nata wd we list lista a listb)(*strict*) apply(subgoal_tac "\<exists>w' x'. z = w' @ [x']") apply(rename_tac c d da e1 e2 z e1a e2a za e ea w wa wb wc nat nata wd we list lista a listb)(*strict*) prefer 2 apply(rule NonEmptyListHasTailElem) apply(force) apply(rename_tac c d da e1 e2 z e1a e2a za e ea w wa wb wc nat nata wd we list lista a listb)(*strict*) apply(thin_tac "z=a#listb") apply(clarsimp) apply(rename_tac c d da e1 e2 e1a e2a za e ea w wa wc nat nata we list lista w')(*strict*) apply(case_tac "za") apply(rename_tac c d da e1 e2 e1a e2a za e ea w wa wc nat nata we list lista w')(*strict*) apply(clarsimp) apply(rename_tac c d da e1 e2 e1a e2a za e ea w wa wc nat nata we list lista w' a listb)(*strict*) apply(subgoal_tac "\<exists>w' x'. za = w' @ [x']") apply(rename_tac c d da e1 e2 e1a e2a za e ea w wa wc nat nata we list lista w' a listb)(*strict*) prefer 2 apply(rule NonEmptyListHasTailElem) apply(force) apply(rename_tac c d da e1 e2 e1a e2a za e ea w wa wc nat nata we list lista w' a listb)(*strict*) apply(thin_tac "za=a#listb") apply(clarsimp) apply(rename_tac c d da e1 e2 e1a e2a e ea w wa nat nata list lista w' w'a)(*strict*) apply(case_tac "k-length w'") apply(rename_tac c d da e1 e2 e1a e2a e ea w wa nat nata list lista w' w'a)(*strict*) apply(clarsimp) apply (metis liftB_reflects_length self_append_conv takeShorter take_all take_all_length take_append take_append_prime) apply(rename_tac c d da e1 e2 e1a e2a e ea w wa nat nata list lista w' w'a natb)(*strict*) apply(clarsimp) apply(case_tac y1) apply(rename_tac c d da e1 e2 e1a e2a e ea w wa nat nata list lista w' w'a natb)(*strict*) apply(clarsimp) apply(rename_tac c d da e1 e2 e1a e2a e ea w wa nat nata list lista w' w'a natb a listb)(*strict*) apply(subgoal_tac "\<exists>w' x'. y1 = w' @ [x']") apply(rename_tac c d da e1 e2 e1a e2a e ea w wa nat nata list lista w' w'a natb a listb)(*strict*) prefer 2 apply(rule NonEmptyListHasTailElem) apply(force) apply(rename_tac c d da e1 e2 e1a e2a e ea w wa nat nata list lista w' w'a natb a listb)(*strict*) apply(thin_tac "y1=a#listb") apply(clarsimp) apply(rename_tac c d da e1 e2 e1a e2a e ea w wa nat nata list lista w' w'a natb w'b x')(*strict*) apply(subgoal_tac "x'=Do") apply(rename_tac c d da e1 e2 e1a e2a e ea w wa nat nata list lista w' w'a natb w'b x')(*strict*) prefer 2 apply(rule_tac v="w'" and w="w'b" in liftB_terminal_tail_equals) apply(blast) apply(rename_tac c d da e1 e2 e1a e2a e ea w wa nat nata list lista w' w'a natb w'b x')(*strict*) apply(clarsimp) apply(rename_tac c d da e1 e2 e1a e2a e ea w wa nat nata list lista w' w'a natb w'b)(*strict*) apply(subgoal_tac "w'=liftB w'b") apply(rename_tac c d da e1 e2 e1a e2a e ea w wa nat nata list lista w' w'a natb w'b)(*strict*) prefer 2 apply(rule liftB_terminal_butlast_equals) apply(force) apply(rename_tac c d da e1 e2 e1a e2a e ea w wa nat nata list lista w' w'a natb w'b)(*strict*) apply(clarsimp) apply(rename_tac c d da e1 e2 e1a e2a e ea w wa nat nata list lista w'a natb w'b)(*strict*) apply(case_tac "k - length w'a") apply(rename_tac c d da e1 e2 e1a e2a e ea w wa nat nata list lista w'a natb w'b)(*strict*) apply(clarsimp) apply(subgoal_tac "teB Do \<in> set w'a") apply(rename_tac c d da e1 e2 e1a e2a e ea w wa nat nata list lista w'a natb w'b)(*strict*) apply(subgoal_tac "teB Do \<notin> set w'a") apply(rename_tac c d da e1 e2 e1a e2a e ea w wa nat nata list lista w'a natb w'b)(*strict*) apply(force) apply(rename_tac c d da e1 e2 e1a e2a e ea w wa nat nata list lista w'a natb w'b)(*strict*) apply(force) apply(rename_tac c d da e1 e2 e1a e2a e ea w wa nat nata list lista w'a natb w'b)(*strict*) apply(rule_tac A="set(take k w'a)" in set_mp) apply(rename_tac c d da e1 e2 e1a e2a e ea w wa nat nata list lista w'a natb w'b)(*strict*) apply(rule List.set_take_subset) apply(rename_tac c d da e1 e2 e1a e2a e ea w wa nat nata list lista w'a natb w'b)(*strict*) apply(rule_tac A="set(liftB (w'b @ Do # c))" in set_mp) apply(rename_tac c d da e1 e2 e1a e2a e ea w wa nat nata list lista w'a natb w'b)(*strict*) apply(force) apply(rename_tac c d da e1 e2 e1a e2a e ea w wa nat nata list lista w'a natb w'b)(*strict*) apply (metis liftB_BiElem head_in_set not_in_setBI set_append_contra2) apply(rename_tac c d da e1 e2 e1a e2a e ea w wa nat nata list lista w'a natb w'b natc)(*strict*) apply(clarsimp) apply(case_tac c) apply(rename_tac c d da e1 e2 e1a e2a e ea w wa nat nata list lista w'a natb w'b natc)(*strict*) apply(force) apply(rename_tac c d da e1 e2 e1a e2a e ea w wa nat nata list lista w'a natb w'b natc a listb)(*strict*) apply(subgoal_tac "\<exists>w' x'. c = w' @ [x']") apply(rename_tac c d da e1 e2 e1a e2a e ea w wa nat nata list lista w'a natb w'b natc a listb)(*strict*) prefer 2 apply(rule NonEmptyListHasTailElem) apply(force) apply(rename_tac c d da e1 e2 e1a e2a e ea w wa nat nata list lista w'a natb w'b natc a listb)(*strict*) apply(thin_tac "c=a#listb") apply(clarsimp) apply(rename_tac d da e1 e2 e1a e2a e ea w wa nat nata list lista w'a natb w'b natc w' x')(*strict*) apply(subgoal_tac "x'=Do") apply(rename_tac d da e1 e2 e1a e2a e ea w wa nat nata list lista w'a natb w'b natc w' x')(*strict*) prefer 2 apply(rule_tac v="w'a" and w="w'b@Do#w'" in liftB_terminal_tail_equals) apply(clarsimp) apply(rename_tac d da e1 e2 e1a e2a e ea w wa nat nata list lista w'a natb w'b natc w' x')(*strict*) apply(clarsimp) apply(rename_tac d da e1 e2 e1a e2a e ea w wa nat nata list lista w'a natb w'b natc w')(*strict*) apply(subgoal_tac "w'a=liftB (w'b@Do#w')") apply(rename_tac d da e1 e2 e1a e2a e ea w wa nat nata list lista w'a natb w'b natc w')(*strict*) prefer 2 apply(rule liftB_terminal_butlast_equals) apply(force) apply(rename_tac d da e1 e2 e1a e2a e ea w wa nat nata list lista w'a natb w'b natc w')(*strict*) apply(clarsimp) apply(rename_tac d da e1 e2 e1a e2a e ea w wa nat nata list lista natb w'b natc w')(*strict*) apply(subgoal_tac "teB Do \<in> set (liftB (w'b @ Do # w'))") apply(rename_tac d da e1 e2 e1a e2a e ea w wa nat nata list lista natb w'b natc w')(*strict*) apply(subgoal_tac "teB Do \<notin> set (liftB (w'b @ Do # w'))") apply(rename_tac d da e1 e2 e1a e2a e ea w wa nat nata list lista natb w'b natc w')(*strict*) apply(force) apply(rename_tac d da e1 e2 e1a e2a e ea w wa nat nata list lista natb w'b natc w')(*strict*) apply(force) apply(rename_tac d da e1 e2 e1a e2a e ea w wa nat nata list lista natb w'b natc w')(*strict*) apply (metis liftB_BiElem head_in_set not_in_setBI set_append_contra2) done theorem no_reduce_reduce_conflicts: " AF_LR_PARSER_input G F Do S' G' M P k \<Longrightarrow> conflict_free G G' k \<Longrightarrow> (parser_marker P) r1 = Some (Some \<lparr>prod_lhs = A1, prod_rhs = w1\<rparr>) \<Longrightarrow> (parser_marker P) r2 = Some (Some \<lparr>prod_lhs = A2, prod_rhs = w2\<rparr>) \<Longrightarrow> r1 \<in> parser_rules P \<Longrightarrow> r2 \<in> parser_rules P \<Longrightarrow> rule_lpop r2 \<sqsupseteq> rule_lpop r1 \<or> rule_lpop r1 \<sqsupseteq> rule_lpop r2 \<Longrightarrow> rule_rpop r1 \<sqsubseteq> rule_rpop r2 \<or> rule_rpop r2 \<sqsubseteq> rule_rpop r1 \<Longrightarrow> r1 = r2" apply(case_tac r1) apply(rename_tac rule_lpopa rule_rpopa rule_lpush rule_rpush)(*strict*) apply(subgoal_tac " rule_rpopa=rule_rpush \<and> \<lparr>prod_lhs=A1,prod_rhs=w1\<rparr> \<in> (cfg_productions G) \<and> (\<exists>q\<delta>. rule_lpopa=q\<delta>#F_DFA_GOTO_SEQUENCE M q\<delta> w1 \<and> rule_lpush=q\<delta>#(F_DFA_GOTO_SEQUENCE M q\<delta> [teA A1]) \<and> (\<exists>\<delta>. \<lparr>cfg_item_lhs = A1,cfg_item_rhs1 = w1,cfg_item_rhs2 = [],cfg_item_look_ahead = rule_rpopa\<rparr> \<in> valid_item_set G' k (teB Do#\<delta>@w1) \<and> q\<delta>=last (F_DFA_GOTO_SEQUENCE M (epda_initial M) (teB Do#\<delta>))))") apply(rename_tac rule_lpopa rule_rpopa rule_lpush rule_rpush)(*strict*) prefer 2 apply(rule_tac S'="S'" and Do="Do" and G'="G'" and G="G" in X6_3_InformationOnRules_reduce2) apply(rename_tac rule_lpopa rule_rpopa rule_lpush rule_rpush)(*strict*) apply(simp add: AF_LR_PARSER_input_def) apply(rename_tac rule_lpopa rule_rpopa rule_lpush rule_rpush)(*strict*) apply(simp add: AF_LR_PARSER_input_def) apply(force) apply(rename_tac rule_lpopa rule_rpopa rule_lpush rule_rpush)(*strict*) apply(simp add: AF_LR_PARSER_input_def) apply(simp add: AF_LR_PARSER_input_def) apply(simp add: AF_LR_PARSER_input_def) apply(rename_tac rule_lpopa rule_rpopa rule_lpush rule_rpush)(*strict*) apply(simp add: AF_LR_PARSER_input_def) apply(rename_tac rule_lpopa rule_rpopa rule_lpush rule_rpush)(*strict*) apply(simp add: AF_LR_PARSER_input_def) apply(rename_tac rule_lpopa rule_rpopa rule_lpush rule_rpush)(*strict*) apply(force) apply(rename_tac rule_lpopa rule_rpopa rule_lpush rule_rpush)(*strict*) apply(rename_tac rule_lpopa rule_rpopa rule_lpush rule_rpush)(*strict*) apply(simp add: AF_LR_PARSER_input_def) apply(rename_tac rule_lpopa rule_rpopa rule_lpush rule_rpush)(*strict*) apply(simp add: AF_LR_PARSER_input_def) apply(rename_tac rule_lpopa rule_rpopa rule_lpush rule_rpush)(*strict*) apply(case_tac r2) apply(rename_tac rule_lpopa rule_rpopa rule_lpush rule_rpush rule_lpopaa rule_rpopaa rule_lpusha rule_rpusha)(*strict*) apply(subgoal_tac " rule_rpopaa=rule_rpusha \<and> \<lparr>prod_lhs=A2,prod_rhs=w2\<rparr> \<in> (cfg_productions G) \<and> (\<exists>q\<delta>. rule_lpopaa=q\<delta>#F_DFA_GOTO_SEQUENCE M q\<delta> w2 \<and> rule_lpusha=q\<delta>#(F_DFA_GOTO_SEQUENCE M q\<delta> [teA A2]) \<and> (\<exists>\<delta>. \<lparr>cfg_item_lhs = A2,cfg_item_rhs1 = w2,cfg_item_rhs2 = [],cfg_item_look_ahead = rule_rpopaa\<rparr> \<in> valid_item_set G' k (teB Do#\<delta>@w2) \<and> q\<delta>=last (F_DFA_GOTO_SEQUENCE M (epda_initial M) (teB Do#\<delta>))))") apply(rename_tac rule_lpopa rule_rpopa rule_lpush rule_rpush rule_lpopaa rule_rpopaa rule_lpusha rule_rpusha)(*strict*) prefer 2 apply(rule_tac S'="S'" and Do="Do" and G'="G'" and G="G" in X6_3_InformationOnRules_reduce2) apply(rename_tac rule_lpopa rule_rpopa rule_lpush rule_rpush rule_lpopaa rule_rpopaa rule_lpusha rule_rpusha)(*strict*) apply(simp add: AF_LR_PARSER_input_def) apply(rename_tac rule_lpopa rule_rpopa rule_lpush rule_rpush rule_lpopaa rule_rpopaa rule_lpusha rule_rpusha)(*strict*) apply(simp add: AF_LR_PARSER_input_def) apply(force) apply(rename_tac rule_lpopa rule_rpopa rule_lpush rule_rpush rule_lpopaa rule_rpopaa rule_lpusha rule_rpusha)(*strict*) apply(simp add: AF_LR_PARSER_input_def) apply(rename_tac rule_lpopa rule_rpopa rule_lpush rule_rpush rule_lpopaa rule_rpopaa rule_lpusha rule_rpusha)(*strict*) apply(simp add: AF_LR_PARSER_input_def) apply(rename_tac rule_lpopa rule_rpopa rule_lpush rule_rpush rule_lpopaa rule_rpopaa rule_lpusha rule_rpusha)(*strict*) apply(simp add: AF_LR_PARSER_input_def) apply(simp add: AF_LR_PARSER_input_def) apply(rename_tac rule_lpopa rule_rpopa rule_lpush rule_rpush rule_lpopaa rule_rpopaa rule_lpusha rule_rpusha)(*strict*) apply(force) apply(rename_tac rule_lpopa rule_rpopa rule_lpush rule_rpush rule_lpopaa rule_rpopaa rule_lpusha rule_rpusha)(*strict*) apply(force) apply(rename_tac rule_lpopa rule_rpopa rule_lpush rule_rpush rule_lpopaa rule_rpopaa rule_lpusha rule_rpusha)(*strict*) apply(simp add: AF_LR_PARSER_input_def) apply(rename_tac rule_lpopa rule_rpopa rule_lpush rule_rpush rule_lpopaa rule_rpopaa rule_lpusha rule_rpusha)(*strict*) apply(simp add: AF_LR_PARSER_input_def) apply(rename_tac rule_lpopa rule_rpopa rule_lpush rule_rpush rule_lpopaa rule_rpopaa rule_lpusha rule_rpusha)(*strict*) apply(thin_tac "parser_marker P r1 = Some (Some \<lparr>prod_lhs = A1, prod_rhs = w1\<rparr>)") apply(thin_tac "parser_marker P r2 = Some (Some \<lparr>prod_lhs = A2, prod_rhs = w2\<rparr>)") apply(clarsimp) apply(rename_tac rule_rpush rule_rpusha \<delta> \<delta>')(*strict*) apply(thin_tac "\<lparr>rule_lpop = last (F_DFA_GOTO_SEQUENCE M (epda_initial M) (teB Do # \<delta>)) # F_DFA_GOTO_SEQUENCE M (last (F_DFA_GOTO_SEQUENCE M (epda_initial M) (teB Do # \<delta>))) w1, rule_rpop = rule_rpush, rule_lpush = last (F_DFA_GOTO_SEQUENCE M (epda_initial M) (teB Do # \<delta>)) # F_DFA_GOTO_SEQUENCE M (last (F_DFA_GOTO_SEQUENCE M (epda_initial M) (teB Do # \<delta>))) [teA A1], rule_rpush = rule_rpush\<rparr> \<in> parser_rules P") apply(rename_tac rule_rpush rule_rpusha \<delta> \<delta>')(*strict*) apply(thin_tac "\<lparr>rule_lpop = last (F_DFA_GOTO_SEQUENCE M (epda_initial M) (teB Do # \<delta>')) # F_DFA_GOTO_SEQUENCE M (last (F_DFA_GOTO_SEQUENCE M (epda_initial M) (teB Do # \<delta>'))) w2, rule_rpop = rule_rpusha, rule_lpush = last (F_DFA_GOTO_SEQUENCE M (epda_initial M) (teB Do # \<delta>')) # F_DFA_GOTO_SEQUENCE M (last (F_DFA_GOTO_SEQUENCE M (epda_initial M) (teB Do # \<delta>'))) [teA A2], rule_rpush = rule_rpusha\<rparr> \<in> parser_rules P") apply(rename_tac rule_rpush rule_rpusha \<delta> \<delta>')(*strict*) apply(rename_tac y1 y2 v1 v2) apply(rename_tac y1 y2 v1 v2)(*strict*) apply(subgoal_tac "valid_cfg G'") apply(rename_tac y1 y2 v1 v2)(*strict*) prefer 2 apply(rule F_CFG_AUGMENT__makes_CFG) apply(simp add: F_CFG_AUGMENT__input_def AF_LR_PARSER_input_def) apply(force) apply(rename_tac y1 y2 v1 v2)(*strict*) apply(subgoal_tac "valid_dfa M") apply(rename_tac y1 y2 v1 v2)(*strict*) prefer 2 apply(rule_tac G="G'" in Theorem6__27_a) apply(rename_tac y1 y2 v1 v2)(*strict*) apply(force) apply(simp add: AF_LR_PARSER_input_def) apply(force) apply(rename_tac y1 y2 v1 v2)(*strict*) apply(simp add: F_CFG_AUGMENT__input_def AF_LR_PARSER_input_def) apply(rename_tac y1 y2 v1 v2)(*strict*) apply(subgoal_tac "some_step_from_every_configuration M") apply(rename_tac y1 y2 v1 v2)(*strict*) prefer 2 apply(rule_tac G="G'" in F_LR_MACHINE_Complete) apply(rename_tac y1 y2 v1 v2)(*strict*) apply(force) apply(simp add: AF_LR_PARSER_input_def) apply(force) apply(rename_tac y1 y2 v1 v2)(*strict*) apply(simp add: F_CFG_AUGMENT__input_def AF_LR_PARSER_input_def) apply(rename_tac y1 y2 v1 v2)(*strict*) apply(subgoal_tac "every_state_in_some_accessible_configuration M") apply(rename_tac y1 y2 v1 v2)(*strict*) prefer 2 apply(rule F_LR_MACHINE_all_Connected) apply(rename_tac y1 y2 v1 v2)(*strict*) prefer 2 apply(simp add: F_CFG_AUGMENT__input_def AF_LR_PARSER_input_def) apply(force) apply(simp add: F_CFG_AUGMENT__input_def AF_LR_PARSER_input_def) apply(rename_tac y1 y2 v1 v2)(*strict*) apply(simp add: F_CFG_AUGMENT__input_def AF_LR_PARSER_input_def) apply(rename_tac y1 y2 v1 v2)(*strict*) apply(force) apply(rename_tac y1 y2 v1 v2)(*strict*) apply(subgoal_tac "some_step_from_every_configuration M") apply(rename_tac y1 y2 v1 v2)(*strict*) prefer 2 apply(rule_tac G="G'" in F_LR_MACHINE_Complete) apply(rename_tac y1 y2 v1 v2)(*strict*) apply(force) apply(rename_tac y1 y2 v1 v2)(*strict*) apply(simp add: F_CFG_AUGMENT__input_def AF_LR_PARSER_input_def) apply(force) apply(simp add: AF_LR_PARSER_input_def) apply(rename_tac y1 y2 v1 v2)(*strict*) apply(subgoal_tac "valid_parser P") apply(rename_tac y1 y2 v1 v2)(*strict*) prefer 2 apply(rule_tac G="G" in AF_LR_PARSER_valid_parser) apply(rename_tac y1 y2 v1 v2)(*strict*) apply(simp add: AF_LR_PARSER_input_def) apply(simp add: AF_LR_PARSER_input_def) apply(rename_tac y1 y2 v1 v2)(*strict*) apply(force) apply(rename_tac y1 y2 v1 v2)(*strict*) apply(force) apply(rename_tac y1 y2 v1 v2)(*strict*) apply(force) apply(rename_tac y1 y2 v1 v2)(*strict*) apply(force) apply(rename_tac y1 y2 v1 v2)(*strict*) apply(simp add: AF_LR_PARSER_input_def) apply(simp add: AF_LR_PARSER_input_def) apply(rename_tac y1 y2 v1 v2)(*strict*) apply(subgoal_tac "set (teB Do # v1 @ w1) \<subseteq> two_elements_construct_domain (cfg_nonterminals G') (cfg_events G')") apply(rename_tac y1 y2 v1 v2)(*strict*) prefer 2 apply(rule viable_prefix_in_CFG) apply(rename_tac y1 y2 v1 v2)(*strict*) apply(simp add: AF_LR_PARSER_input_def) apply(rename_tac y1 y2 v1 v2)(*strict*) apply(rule Fact6_12__1) apply(force) apply(rename_tac y1 y2 v1 v2)(*strict*) apply(subgoal_tac "set (teB Do # v2 @ w2) \<subseteq> two_elements_construct_domain (cfg_nonterminals G') (cfg_events G')") apply(rename_tac y1 y2 v1 v2)(*strict*) prefer 2 apply(rule viable_prefix_in_CFG) apply(rename_tac y1 y2 v1 v2)(*strict*) apply(simp add: AF_LR_PARSER_input_def) apply(rename_tac y1 y2 v1 v2)(*strict*) apply(rule Fact6_12__1) apply(force) apply(rename_tac y1 y2 v1 v2)(*strict*) apply(subgoal_tac "valid_item_set G' k (teB Do # v1 @ w1)=valid_item_set G' k (teB Do # v2 @ w2)") apply(rename_tac y1 y2 v1 v2)(*strict*) prefer 2 apply(subgoal_tac "valid_item_set G' k (teB Do # v1 @ w1) = (if (teB Do # v1 @ w1)=[] then (epda_initial M) else last (F_DFA_GOTO_SEQUENCE M (epda_initial M) (teB Do # v1 @ w1)))") apply(rename_tac y1 y2 v1 v2)(*strict*) prefer 2 apply(rule F_LR_MACHINE_all_SOUND) apply(rename_tac y1 y2 v1 v2)(*strict*) apply(simp add: AF_LR_PARSER_input_def) apply(rename_tac y1 y2 v1 v2)(*strict*) apply(simp add: AF_LR_PARSER_input_def) apply(force) apply(rename_tac y1 y2 v1 v2)(*strict*) apply(simp add: AF_LR_PARSER_input_def) apply(rename_tac y1 y2 v1 v2)(*strict*) apply(simp add: AF_LR_PARSER_input_def) apply(simp add: AF_LR_PARSER_input_def) apply(rename_tac y1 y2 v1 v2)(*strict*) prefer 2 apply (metis two_elements_construct_domain_setB) apply(rename_tac y1 y2 v1 v2)(*strict*) apply (metis two_elements_construct_domain_setA) apply(rename_tac y1 y2 v1 v2)(*strict*) apply(subgoal_tac "valid_item_set G' k (teB Do # v2 @ w2) = (if (teB Do # v2 @ w2)=[] then (epda_initial M) else last (F_DFA_GOTO_SEQUENCE M (epda_initial M) (teB Do # v2 @ w2)))") apply(rename_tac y1 y2 v1 v2)(*strict*) prefer 2 apply(rule F_LR_MACHINE_all_SOUND) apply(rename_tac y1 y2 v1 v2)(*strict*) apply(simp add: AF_LR_PARSER_input_def) apply(rename_tac y1 y2 v1 v2)(*strict*) apply(simp add: AF_LR_PARSER_input_def) apply(force) apply(rename_tac y1 y2 v1 v2)(*strict*) apply(simp add: AF_LR_PARSER_input_def) apply(rename_tac y1 y2 v1 v2)(*strict*) apply(simp add: AF_LR_PARSER_input_def) apply(simp add: AF_LR_PARSER_input_def) apply(rename_tac y1 y2 v1 v2)(*strict*) prefer 2 apply (metis two_elements_construct_domain_setB) apply(rename_tac y1 y2 v1 v2)(*strict*) apply (metis two_elements_construct_domain_setA) apply(rename_tac y1 y2 v1 v2)(*strict*) apply(subgoal_tac "valid_item_set G' k (teB Do # v1) = (if (teB Do # v1)=[] then (epda_initial M) else last (F_DFA_GOTO_SEQUENCE M (epda_initial M) (teB Do # v1)))") apply(rename_tac y1 y2 v1 v2)(*strict*) prefer 2 apply(rule F_LR_MACHINE_all_SOUND) apply(rename_tac y1 y2 v1 v2)(*strict*) apply(simp add: AF_LR_PARSER_input_def) apply(rename_tac y1 y2 v1 v2)(*strict*) apply(simp add: AF_LR_PARSER_input_def) apply(force) apply(rename_tac y1 y2 v1 v2)(*strict*) apply(simp add: AF_LR_PARSER_input_def) apply(rename_tac y1 y2 v1 v2)(*strict*) apply(simp add: AF_LR_PARSER_input_def) apply(simp add: AF_LR_PARSER_input_def) apply(rename_tac y1 y2 v1 v2)(*strict*) prefer 2 apply (rule two_elements_construct_domain_setB) apply(rule_tac B="set (teB Do # v1 @ w1)" in subset_trans) apply(rename_tac y1 y2 v1 v2)(*strict*) apply(force) apply(rename_tac y1 y2 v1 v2)(*strict*) apply(force) apply(rename_tac y1 y2 v1 v2)(*strict*) apply (rule two_elements_construct_domain_setA) apply(rule_tac B="set (teB Do # v1 @ w1)" in subset_trans) apply(rename_tac y1 y2 v1 v2)(*strict*) apply(force) apply(rename_tac y1 y2 v1 v2)(*strict*) apply(force) apply(rename_tac y1 y2 v1 v2)(*strict*) apply(subgoal_tac "valid_item_set G' k (teB Do # v2) = (if (teB Do # v2)=[] then (epda_initial M) else last (F_DFA_GOTO_SEQUENCE M (epda_initial M) (teB Do # v2)))") apply(rename_tac y1 y2 v1 v2)(*strict*) prefer 2 apply(rule F_LR_MACHINE_all_SOUND) apply(rename_tac y1 y2 v1 v2)(*strict*) apply(simp add: AF_LR_PARSER_input_def) apply(rename_tac y1 y2 v1 v2)(*strict*) apply(simp add: AF_LR_PARSER_input_def) apply(force) apply(rename_tac y1 y2 v1 v2)(*strict*) apply(simp add: AF_LR_PARSER_input_def) apply(rename_tac y1 y2 v1 v2)(*strict*) apply(simp add: AF_LR_PARSER_input_def) apply(simp add: AF_LR_PARSER_input_def) apply(rename_tac y1 y2 v1 v2)(*strict*) prefer 2 apply (rule two_elements_construct_domain_setB) apply(rule_tac B="set (teB Do # v2 @ w2)" in subset_trans) apply(rename_tac y1 y2 v1 v2)(*strict*) apply(force) apply(rename_tac y1 y2 v1 v2)(*strict*) apply(force) apply(rename_tac y1 y2 v1 v2)(*strict*) apply (rule two_elements_construct_domain_setA) apply(rule_tac B="set (teB Do # v2 @ w2)" in subset_trans) apply(rename_tac y1 y2 v1 v2)(*strict*) apply(force) apply(rename_tac y1 y2 v1 v2)(*strict*) apply(force) apply(rename_tac y1 y2 v1 v2)(*strict*) apply(clarsimp) apply(subgoal_tac "length w2 = length (F_DFA_GOTO_SEQUENCE M (last (F_DFA_GOTO_SEQUENCE M (epda_initial M) (teB Do # v2))) w2)") apply(rename_tac y1 y2 v1 v2)(*strict*) prefer 2 apply(rule F_DFA_GOTO_SEQUENCESound_main1) apply(rename_tac y1 y2 v1 v2)(*strict*) apply(force) apply(rename_tac y1 y2 v1 v2)(*strict*) apply(force) apply(rename_tac y1 y2 v1 v2)(*strict*) apply(force) apply(rename_tac y1 y2 v1 v2)(*strict*) prefer 2 apply(simp add: AF_LR_PARSER_input_def F_LR_MACHINE_def) apply(rename_tac y1 y2 v1 v2)(*strict*) prefer 2 apply(force) apply(rename_tac y1 y2 v1 v2)(*strict*) apply(rule_tac t="last (F_DFA_GOTO_SEQUENCE M (epda_initial M) (teB Do # v2))" and s="valid_item_set G' k (teB Do # v2)" in ssubst) apply(rename_tac y1 y2 v1 v2)(*strict*) apply(force) apply(rename_tac y1 y2 v1 v2)(*strict*) apply(rule LRM_contains_theEqClasses2) apply(rename_tac y1 y2 v1 v2)(*strict*) apply(force) apply(rename_tac y1 y2 v1 v2)(*strict*) apply(simp add: AF_LR_PARSER_input_def) apply(rename_tac y1 y2 v1 v2)(*strict*) apply(force) apply(simp add: AF_LR_PARSER_input_def) apply(force) apply(rename_tac y1 y2 v1 v2)(*strict*) apply(subgoal_tac "length w1 = length (F_DFA_GOTO_SEQUENCE M (last (F_DFA_GOTO_SEQUENCE M (epda_initial M) (teB Do # v1))) w1)") apply(rename_tac y1 y2 v1 v2)(*strict*) prefer 2 apply(rule F_DFA_GOTO_SEQUENCESound_main1) apply(rename_tac y1 y2 v1 v2)(*strict*) apply(force) apply(rename_tac y1 y2 v1 v2)(*strict*) apply(force) apply(rename_tac y1 y2 v1 v2)(*strict*) apply(force) apply(rename_tac y1 y2 v1 v2)(*strict*) prefer 2 apply(simp add: AF_LR_PARSER_input_def F_LR_MACHINE_def) apply(rename_tac y1 y2 v1 v2)(*strict*) prefer 2 apply(force) apply(rename_tac y1 y2 v1 v2)(*strict*) apply(rule_tac t="last (F_DFA_GOTO_SEQUENCE M (epda_initial M) (teB Do # v1))" and s="valid_item_set G' k (teB Do # v1)" in ssubst) apply(rename_tac y1 y2 v1 v2)(*strict*) apply(force) apply(rename_tac y1 y2 v1 v2)(*strict*) apply(rule LRM_contains_theEqClasses2) apply(rename_tac y1 y2 v1 v2)(*strict*) apply(force) apply(rename_tac y1 y2 v1 v2)(*strict*) apply(simp add: AF_LR_PARSER_input_def) apply(rename_tac y1 y2 v1 v2)(*strict*) apply(force) apply(simp add: AF_LR_PARSER_input_def) apply(force) apply(rename_tac y1 y2 v1 v2)(*strict*) apply(subgoal_tac "length (teB Do#v2) = length (F_DFA_GOTO_SEQUENCE M (epda_initial M) (teB Do # v2))") apply(rename_tac y1 y2 v1 v2)(*strict*) prefer 2 apply(rule F_DFA_GOTO_SEQUENCESound_main1) apply(rename_tac y1 y2 v1 v2)(*strict*) apply(force) apply(rename_tac y1 y2 v1 v2)(*strict*) apply(force) apply(rename_tac y1 y2 v1 v2)(*strict*) apply(force) apply(rename_tac y1 y2 v1 v2)(*strict*) prefer 2 apply(simp add: AF_LR_PARSER_input_def F_LR_MACHINE_def) apply(rename_tac y1 y2 v1 v2)(*strict*) prefer 2 apply(force) apply(rename_tac y1 y2 v1 v2)(*strict*) apply(simp add: valid_dfa_def valid_dpda_def valid_pda_def valid_epda_def) apply(rename_tac y1 y2 v1 v2)(*strict*) apply(subgoal_tac "length (teB Do#v1) = length (F_DFA_GOTO_SEQUENCE M (epda_initial M) (teB Do # v1))") apply(rename_tac y1 y2 v1 v2)(*strict*) prefer 2 apply(rule F_DFA_GOTO_SEQUENCESound_main1) apply(rename_tac y1 y2 v1 v2)(*strict*) apply(force) apply(rename_tac y1 y2 v1 v2)(*strict*) apply(force) apply(rename_tac y1 y2 v1 v2)(*strict*) apply(force) apply(rename_tac y1 y2 v1 v2)(*strict*) prefer 2 apply(simp add: AF_LR_PARSER_input_def F_LR_MACHINE_def) apply(rename_tac y1 y2 v1 v2)(*strict*) prefer 2 apply(force) apply(rename_tac y1 y2 v1 v2)(*strict*) apply(simp add: valid_dfa_def valid_dpda_def valid_pda_def valid_epda_def) apply(rename_tac y1 y2 v1 v2)(*strict*) apply(rule_tac t="last (F_DFA_GOTO_SEQUENCE M (epda_initial M) (teB Do # v2 @ w2))" and s="last((last (F_DFA_GOTO_SEQUENCE M (epda_initial M) (teB Do # v2)) # F_DFA_GOTO_SEQUENCE M (last (F_DFA_GOTO_SEQUENCE M (epda_initial M) (teB Do # v2))) w2))" in ssubst) apply(rename_tac y1 y2 v1 v2)(*strict*) apply(clarsimp) apply(case_tac w2) apply(rename_tac y1 y2 v1 v2)(*strict*) apply(force) apply(rename_tac y1 y2 v1 v2 a list)(*strict*) apply(rule conjI) apply(rename_tac y1 y2 v1 v2 a list)(*strict*) apply(force) apply(rename_tac y1 y2 v1 v2 a list)(*strict*) apply(rule impI) apply(subgoal_tac "\<exists>w' x'. w2 = w' @ [x']") apply(rename_tac y1 y2 v1 v2 a list)(*strict*) prefer 2 apply(rule_tac n="length list" in NonEmptyListHasTailElem) apply(force) apply(rename_tac y1 y2 v1 v2 a list)(*strict*) apply(thin_tac "w2=a#list") apply(clarsimp) apply(rename_tac y1 y2 v1 v2 w' x')(*strict*) apply(rule_tac t="teB Do # v2 @ w' @ [x']" and s="(teB Do # v2) @ (w' @ [x'])" in ssubst) apply(rename_tac y1 y2 v1 v2 w' x')(*strict*) apply(force) apply(rename_tac y1 y2 v1 v2 w' x')(*strict*) apply(rule_tac t="F_DFA_GOTO_SEQUENCE M (epda_initial M) ((teB Do # v2) @ (w' @ [x']))" and s="F_DFA_GOTO_SEQUENCE M SSp SSw1 @ (F_DFA_GOTO_SEQUENCE M (last (SSp#(F_DFA_GOTO_SEQUENCE M SSp SSw1))) SSw2)" for SSp SSw1 SSw2 in ssubst) apply(rename_tac y1 y2 v1 v2 w' x')(*strict*) apply(rule F_DFA_GOTO_SEQUENCE_append_split) apply(rename_tac y1 y2 v1 v2 w' x')(*strict*) apply(force) apply(rename_tac y1 y2 v1 v2 w' x')(*strict*) apply(force) apply(rename_tac y1 y2 v1 v2 w' x')(*strict*) apply(force) apply(rename_tac y1 y2 v1 v2 w' x')(*strict*) apply(force) apply(rename_tac y1 y2 v1 v2 w' x')(*strict*) apply(simp add: AF_LR_PARSER_input_def F_LR_MACHINE_def) apply(rename_tac y1 y2 v1 v2 w' x')(*strict*) apply(simp add: AF_LR_PARSER_input_def F_LR_MACHINE_def) apply(rename_tac y1 y2 v1 v2 w' x')(*strict*) apply(clarsimp) apply(rename_tac y1 y2 v1 v2)(*strict*) apply(rule_tac t="last (F_DFA_GOTO_SEQUENCE M (epda_initial M) (teB Do # v1 @ w1))" and s="last((last (F_DFA_GOTO_SEQUENCE M (epda_initial M) (teB Do # v1)) # F_DFA_GOTO_SEQUENCE M (last (F_DFA_GOTO_SEQUENCE M (epda_initial M) (teB Do # v1))) w1))" in ssubst) apply(rename_tac y1 y2 v1 v2)(*strict*) apply(clarsimp) apply(case_tac w1) apply(rename_tac y1 y2 v1 v2)(*strict*) apply(force) apply(rename_tac y1 y2 v1 v2 a list)(*strict*) apply(rule conjI) apply(rename_tac y1 y2 v1 v2 a list)(*strict*) apply(force) apply(rename_tac y1 y2 v1 v2 a list)(*strict*) apply(rule impI) apply(subgoal_tac "\<exists>w' x'. w1 = w' @ [x']") apply(rename_tac y1 y2 v1 v2 a list)(*strict*) prefer 2 apply(rule_tac n="length list" in NonEmptyListHasTailElem) apply(force) apply(rename_tac y1 y2 v1 v2 a list)(*strict*) apply(thin_tac "w1=a#list") apply(clarsimp) apply(rename_tac y1 y2 v1 v2 w' x')(*strict*) apply(rule_tac t="teB Do # v1 @ w' @ [x']" and s="(teB Do # v1) @ (w' @ [x'])" in ssubst) apply(rename_tac y1 y2 v1 v2 w' x')(*strict*) apply(force) apply(rename_tac y1 y2 v1 v2 w' x')(*strict*) apply(rule_tac t="F_DFA_GOTO_SEQUENCE M (epda_initial M) ((teB Do # v1) @ (w' @ [x']))" and s="F_DFA_GOTO_SEQUENCE M SSp SSw1 @ (F_DFA_GOTO_SEQUENCE M (last (SSp#(F_DFA_GOTO_SEQUENCE M SSp SSw1))) SSw2)" for SSp SSw1 SSw2 in ssubst) apply(rename_tac y1 y2 v1 v2 w' x')(*strict*) apply(rule F_DFA_GOTO_SEQUENCE_append_split) apply(rename_tac y1 y2 v1 v2 w' x')(*strict*) apply(force) apply(rename_tac y1 y2 v1 v2 w' x')(*strict*) apply(force) apply(rename_tac y1 y2 v1 v2 w' x')(*strict*) apply(force) apply(rename_tac y1 y2 v1 v2 w' x')(*strict*) apply(force) apply(rename_tac y1 y2 v1 v2 w' x')(*strict*) apply(simp add: AF_LR_PARSER_input_def F_LR_MACHINE_def) apply(rename_tac y1 y2 v1 v2 w' x')(*strict*) apply(simp add: AF_LR_PARSER_input_def F_LR_MACHINE_def) apply(rename_tac y1 y2 v1 v2 w' x')(*strict*) apply(clarsimp) apply(rename_tac y1 y2 v1 v2)(*strict*) apply(rule suffix_last_eq) apply(rename_tac y1 y2 v1 v2)(*strict*) apply(force) apply(rename_tac y1 y2 v1 v2)(*strict*) apply(force) apply(rename_tac y1 y2 v1 v2)(*strict*) apply(force) apply(rename_tac y1 y2 v1 v2)(*strict*) apply(subgoal_tac "y1=y2") apply(rename_tac y1 y2 v1 v2)(*strict*) apply(simp only: conflict_free_def) apply(erule_tac x="(teB Do # v1 @ w1)" in allE) apply(erule impE) apply(rename_tac y1 y2 v1 v2)(*strict*) apply(force) apply(rename_tac y1 y2 v1 v2)(*strict*) apply(erule conjE)+ apply(thin_tac "\<forall>I1 I2. I1 \<in> valid_item_set G' k (teB Do # v1 @ w1) \<and> I2 \<in> valid_item_set G' k (teB Do # v1 @ w1) \<and> item_core I1 \<in> cfg_productions G \<and> item_core I2 \<in> cfg_productions G \<longrightarrow> \<not> item_shift_reduce_conflict G' k I1 I2") apply(rename_tac y1 y2 v1 v2)(*strict*) apply(erule_tac x="\<lparr>cfg_item_lhs = A1, cfg_item_rhs1 = w1, cfg_item_rhs2 = [], cfg_item_look_ahead = y1\<rparr>" in allE) apply(erule_tac x="\<lparr>cfg_item_lhs = A2, cfg_item_rhs1 = w2, cfg_item_rhs2 = [], cfg_item_look_ahead = y2\<rparr>" in allE) apply(erule impE) apply(rename_tac y1 y2 v1 v2)(*strict*) apply(rule conjI) apply(rename_tac y1 y2 v1 v2)(*strict*) apply(force) apply(rename_tac y1 y2 v1 v2)(*strict*) apply(rule conjI) apply(rename_tac y1 y2 v1 v2)(*strict*) apply(force) apply(rename_tac y1 y2 v1 v2)(*strict*) apply(simp add: item_core_def) apply(rename_tac y1 y2 v1 v2)(*strict*) apply(simp add: item_reduce_reduce_conflict_def) apply(subgoal_tac " F_DFA_GOTO_SEQUENCE M (last (F_DFA_GOTO_SEQUENCE M (epda_initial M) (teB Do # v2))) w2 = F_DFA_GOTO_SEQUENCE M (last (F_DFA_GOTO_SEQUENCE M (epda_initial M) (teB Do # v1))) w2 \<and> last (F_DFA_GOTO_SEQUENCE M (epda_initial M) (teB Do # v2)) = last (F_DFA_GOTO_SEQUENCE M (epda_initial M) (teB Do # v1))") apply(rename_tac y1 y2 v1 v2)(*strict*) prefer 2 apply(rule mutual_prefix_equal_suffix) apply(rename_tac y1 y2 v1 v2)(*strict*) apply(force) apply(rename_tac y1 y2 v1 v2)(*strict*) apply(subgoal_tac "valid_item_set G' k (teB Do # v1) = (if (teB Do # v1)=[] then (epda_initial M) else last (F_DFA_GOTO_SEQUENCE M (epda_initial M) (teB Do # v1)))") apply(rename_tac y1 y2 v1 v2)(*strict*) prefer 2 apply(rule F_LR_MACHINE_all_SOUND) apply(rename_tac y1 y2 v1 v2)(*strict*) apply(simp add: AF_LR_PARSER_input_def) apply(rename_tac y1 y2 v1 v2)(*strict*) apply(simp add: AF_LR_PARSER_input_def) apply(force) apply(rename_tac y1 y2 v1 v2)(*strict*) apply(simp add: AF_LR_PARSER_input_def) apply(rename_tac y1 y2 v1 v2)(*strict*) apply(simp add: AF_LR_PARSER_input_def) apply(simp add: AF_LR_PARSER_input_def) apply(rename_tac y1 y2 v1 v2)(*strict*) prefer 2 apply (rule two_elements_construct_domain_setB) apply(rule_tac B="set (teB Do # v1 @ w1)" in subset_trans) apply(rename_tac y1 y2 v1 v2)(*strict*) apply(force) apply(rename_tac y1 y2 v1 v2)(*strict*) apply(force) apply(rename_tac y1 y2 v1 v2)(*strict*) apply (rule two_elements_construct_domain_setA) apply(rule_tac B="set (teB Do # v1 @ w1)" in subset_trans) apply(rename_tac y1 y2 v1 v2)(*strict*) apply(force) apply(rename_tac y1 y2 v1 v2)(*strict*) apply(force) apply(rename_tac y1 y2 v1 v2)(*strict*) apply(subgoal_tac "valid_item_set G' k (teB Do # v2) = (if (teB Do # v2)=[] then (epda_initial M) else last (F_DFA_GOTO_SEQUENCE M (epda_initial M) (teB Do # v2)))") apply(rename_tac y1 y2 v1 v2)(*strict*) prefer 2 apply(rule F_LR_MACHINE_all_SOUND) apply(rename_tac y1 y2 v1 v2)(*strict*) apply(simp add: AF_LR_PARSER_input_def) apply(rename_tac y1 y2 v1 v2)(*strict*) apply(simp add: AF_LR_PARSER_input_def) apply(force) apply(rename_tac y1 y2 v1 v2)(*strict*) apply(simp add: AF_LR_PARSER_input_def) apply(rename_tac y1 y2 v1 v2)(*strict*) apply(simp add: AF_LR_PARSER_input_def) apply(simp add: AF_LR_PARSER_input_def) apply(rename_tac y1 y2 v1 v2)(*strict*) prefer 2 apply (rule two_elements_construct_domain_setB) apply(rule_tac B="set (teB Do # v2 @ w2)" in subset_trans) apply(rename_tac y1 y2 v1 v2)(*strict*) apply(force) apply(rename_tac y1 y2 v1 v2)(*strict*) apply(force) apply(rename_tac y1 y2 v1 v2)(*strict*) apply (rule two_elements_construct_domain_setA) apply(rule_tac B="set (teB Do # v2 @ w2)" in subset_trans) apply(rename_tac y1 y2 v1 v2)(*strict*) apply(force) apply(rename_tac y1 y2 v1 v2)(*strict*) apply(force) apply(rename_tac y1 y2 v1 v2)(*strict*) apply(clarsimp) apply(rename_tac y2 v1 v2)(*strict*) apply(subgoal_tac "length w2 = length (F_DFA_GOTO_SEQUENCE M (last (F_DFA_GOTO_SEQUENCE M (epda_initial M) (teB Do # v2))) w2)") apply(rename_tac y2 v1 v2)(*strict*) prefer 2 apply(rule F_DFA_GOTO_SEQUENCESound_main1) apply(rename_tac y2 v1 v2)(*strict*) apply(force) apply(rename_tac y2 v1 v2)(*strict*) apply(force) apply(rename_tac y2 v1 v2)(*strict*) apply(force) apply(rename_tac y2 v1 v2)(*strict*) prefer 2 apply(simp add: AF_LR_PARSER_input_def F_LR_MACHINE_def) apply(rename_tac y2 v1 v2)(*strict*) prefer 2 apply(force) apply(rename_tac y2 v1 v2)(*strict*) apply(rule_tac t="last (F_DFA_GOTO_SEQUENCE M (epda_initial M) (teB Do # v2))" and s="valid_item_set G' k (teB Do # v2)" in ssubst) apply(rename_tac y2 v1 v2)(*strict*) apply(force) apply(rename_tac y2 v1 v2)(*strict*) apply(rule LRM_contains_theEqClasses2) apply(rename_tac y2 v1 v2)(*strict*) apply(force) apply(simp add: AF_LR_PARSER_input_def) apply(force) apply(rename_tac y2 v1 v2)(*strict*) apply(simp add: AF_LR_PARSER_input_def) apply(rename_tac y2 v1 v2)(*strict*) apply(force) apply(rename_tac y2 v1 v2)(*strict*) apply(subgoal_tac "length w2 = length (F_DFA_GOTO_SEQUENCE M (last (F_DFA_GOTO_SEQUENCE M (epda_initial M) (teB Do # v1))) w2)") apply(rename_tac y2 v1 v2)(*strict*) prefer 2 apply(rule F_DFA_GOTO_SEQUENCESound_main1) apply(rename_tac y2 v1 v2)(*strict*) apply(force) apply(rename_tac y2 v1 v2)(*strict*) apply(force) apply(rename_tac y2 v1 v2)(*strict*) apply(force) apply(rename_tac y2 v1 v2)(*strict*) prefer 2 apply(simp add: AF_LR_PARSER_input_def F_LR_MACHINE_def) apply(rename_tac y2 v1 v2)(*strict*) prefer 2 apply(force) apply(rename_tac y2 v1 v2)(*strict*) apply(rule_tac t="last (F_DFA_GOTO_SEQUENCE M (epda_initial M) (teB Do # v1))" and s="valid_item_set G' k (teB Do # v1)" in ssubst) apply(rename_tac y2 v1 v2)(*strict*) apply(force) apply(rename_tac y2 v1 v2)(*strict*) apply(rule LRM_contains_theEqClasses2) apply(rename_tac y2 v1 v2)(*strict*) apply(force) apply(rename_tac y2 v1 v2)(*strict*) apply(simp add: AF_LR_PARSER_input_def) apply(rename_tac y2 v1 v2)(*strict*) apply(force) apply(simp add: AF_LR_PARSER_input_def) apply(force) apply(rename_tac y2 v1 v2)(*strict*) apply(clarsimp) apply(rename_tac y1 y2 v1 v2)(*strict*) apply(clarsimp) apply(rename_tac y1 y2 v1 v2)(*strict*) apply(subgoal_tac "valid_item_set G' k (teB Do # v1 @ w1) \<in> epda_states M") apply(rename_tac y1 y2 v1 v2)(*strict*) prefer 2 apply(rule LRM_contains_theEqClasses2) apply(rename_tac y1 y2 v1 v2)(*strict*) apply(force) apply(rename_tac y1 y2 v1 v2)(*strict*) apply(simp add: AF_LR_PARSER_input_def) apply(rename_tac y1 y2 v1 v2)(*strict*) apply(force) apply(simp add: AF_LR_PARSER_input_def) apply(force) apply(rename_tac y1 y2 v1 v2)(*strict*) apply(erule_tac P="y1 \<sqsubseteq> y2" in disjE) apply(rename_tac y1 y2 v1 v2)(*strict*) apply(rule no_reduce_reduce_conflicts_hlp) apply(rename_tac y1 y2 v1 v2)(*strict*) apply(force) apply(rename_tac y1 y2 v1 v2)(*strict*) apply(force) apply(rename_tac y1 y2 v1 v2)(*strict*) apply(force) apply(rename_tac y1 y2 v1 v2)(*strict*) apply(force) apply(rename_tac y1 y2 v1 v2)(*strict*) apply(force) apply(rename_tac y1 y2 v1 v2)(*strict*) apply(rule sym) apply(rule no_reduce_reduce_conflicts_hlp) apply(rename_tac y1 y2 v1 v2)(*strict*) apply(force) apply(rename_tac y1 y2 v1 v2)(*strict*) apply(force) apply(rename_tac y1 y2 v1 v2)(*strict*) apply(force) apply(rename_tac y1 y2 v1 v2)(*strict*) apply(force) apply(rename_tac y1 y2 v1 v2)(*strict*) apply(force) done lemma translate_cfgSTD_first_with_single: " AF_LR_PARSER_input G F Do S' G' M P k \<Longrightarrow> y \<in> cfgSTD_first G' (k - Suc 0) w \<Longrightarrow> take k (a # y) \<in> cfgSTD_first G' k (teB a # w)" apply(simp add: cfgSTD_first_def) apply(clarsimp) apply(rename_tac x d e1 n)(*strict*) apply(rule inMap) apply(clarsimp) apply(rule_tac x="a # x" in exI) apply(clarsimp) apply(rule conjI) apply(rename_tac x d e1 n)(*strict*) prefer 2 apply(case_tac k) apply(rename_tac x d e1 n)(*strict*) apply(clarsimp) apply(rename_tac x d e1 n nat)(*strict*) apply(clarsimp) apply(rename_tac x d e1 n)(*strict*) apply(rule_tac x="derivation_map d (\<lambda>v. \<lparr>cfg_conf=(teB a)#(cfg_conf v)\<rparr>)" in exI) apply(rule conjI) apply(rename_tac x d e1 n)(*strict*) apply(rule cfgSTD.derivation_map_preserves_derivation2) apply(rename_tac x d e1 n)(*strict*) apply(force) apply(rename_tac x d e1 n)(*strict*) apply(clarsimp) apply(rename_tac x d e1 n aa e b)(*strict*) apply(simp add: cfgSTD_step_relation_def) apply(clarsimp) apply(rename_tac x d e1 n aa e b l r)(*strict*) apply(rule_tac x="teB a#l" in exI) apply(rule_tac x="r" in exI) apply(clarsimp) apply(rename_tac x d e1 n)(*strict*) apply(rule_tac x="e1" in exI) apply(rule_tac x="n" in exI) apply(simp add: derivation_map_def maximum_of_domain_def) done theorem no_shift_reduce_conflicts: " AF_LR_PARSER_input G F Do S' G' M P k \<Longrightarrow> conflict_free G G' k \<Longrightarrow> (parser_marker P) r1 = Some None \<Longrightarrow> (parser_marker P) r2 = Some (Some \<lparr>prod_lhs = A2, prod_rhs = w2\<rparr>) \<Longrightarrow> r1 \<in> parser_rules P \<Longrightarrow> r2 \<in> parser_rules P \<Longrightarrow> rule_lpop r2 \<sqsupseteq> rule_lpop r1 \<or> rule_lpop r1 \<sqsupseteq> rule_lpop r2 \<Longrightarrow> rule_rpop r1 \<sqsubseteq> rule_rpop r2 \<or> rule_rpop r2 \<sqsubseteq> rule_rpop r1 \<Longrightarrow> r1 = r2" apply(case_tac r1) apply(rename_tac rule_lpopa rule_rpopa rule_lpush rule_rpush)(*strict*) apply(subgoal_tac " \<exists>q\<delta> y \<beta> z A \<alpha> a \<delta>. y \<in> (cfgSTD_first G' (k- 1) (\<beta>@(liftB z))) \<and> \<lparr>prod_lhs=A,prod_rhs=\<alpha>@(teB a)#\<beta>\<rparr> \<in> cfg_productions G \<and> q\<delta>=last (F_DFA_GOTO_SEQUENCE M (epda_initial M) (teB Do#\<delta>)) \<and> \<lparr>cfg_item_lhs = A,cfg_item_rhs1 = \<alpha>,cfg_item_rhs2 = (teB a)#\<beta>,cfg_item_look_ahead = z\<rparr> \<in> valid_item_set G' k (teB Do#\<delta>) \<and> rule_lpopa=[q\<delta>] \<and> rule_rpopa=a#y \<and> rule_lpush=[q\<delta>,F_DFA_GOTO M q\<delta> (teB a)] \<and> rule_rpush=y") apply(rename_tac rule_lpopa rule_rpopa rule_lpush rule_rpush)(*strict*) prefer 2 apply(rule_tac S'="S'" and Do="Do" and G'="G'" and G="G" in X6_3_InformationOnRules_shift2) apply(rename_tac rule_lpopa rule_rpopa rule_lpush rule_rpush)(*strict*) apply(simp add: AF_LR_PARSER_input_def) apply(rename_tac rule_lpopa rule_rpopa rule_lpush rule_rpush)(*strict*) apply(simp add: AF_LR_PARSER_input_def) apply(force) apply(rename_tac rule_lpopa rule_rpopa rule_lpush rule_rpush)(*strict*) apply(simp add: AF_LR_PARSER_input_def) apply(rename_tac rule_lpopa rule_rpopa rule_lpush rule_rpush)(*strict*) apply(simp add: AF_LR_PARSER_input_def) apply(rename_tac rule_lpopa rule_rpopa rule_lpush rule_rpush)(*strict*) apply(simp add: AF_LR_PARSER_input_def) apply(rename_tac rule_lpopa rule_rpopa rule_lpush rule_rpush)(*strict*) apply(simp add: AF_LR_PARSER_input_def) apply(force) apply(rename_tac rule_lpopa rule_rpopa rule_lpush rule_rpush)(*strict*) apply(force) apply(rename_tac rule_lpopa rule_rpopa rule_lpush rule_rpush)(*strict*) apply(simp add: AF_LR_PARSER_input_def) apply(rename_tac rule_lpopa rule_rpopa rule_lpush rule_rpush)(*strict*) apply(simp add: AF_LR_PARSER_input_def) apply(rename_tac rule_lpopa rule_rpopa rule_lpush rule_rpush)(*strict*) apply(case_tac r2) apply(rename_tac rule_lpopa rule_rpopa rule_lpush rule_rpush rule_lpopaa rule_rpopaa rule_lpusha rule_rpusha)(*strict*) apply(subgoal_tac " rule_rpopaa=rule_rpusha \<and> \<lparr>prod_lhs=A2,prod_rhs=w2\<rparr> \<in> (cfg_productions G) \<and> (\<exists>q\<delta>. rule_lpopaa=q\<delta>#F_DFA_GOTO_SEQUENCE M q\<delta> w2 \<and> rule_lpusha=q\<delta>#(F_DFA_GOTO_SEQUENCE M q\<delta> [teA A2]) \<and> (\<exists>\<delta>. \<lparr>cfg_item_lhs = A2,cfg_item_rhs1 = w2,cfg_item_rhs2 = [],cfg_item_look_ahead = rule_rpopaa\<rparr> \<in> valid_item_set G' k (teB Do#\<delta>@w2) \<and> q\<delta>=last (F_DFA_GOTO_SEQUENCE M (epda_initial M) (teB Do#\<delta>))))") apply(rename_tac rule_lpopa rule_rpopa rule_lpush rule_rpush rule_lpopaa rule_rpopaa rule_lpusha rule_rpusha)(*strict*) prefer 2 apply(rule_tac S'="S'" and Do="Do" and G'="G'" and G="G" in X6_3_InformationOnRules_reduce2) apply(rename_tac rule_lpopa rule_rpopa rule_lpush rule_rpush rule_lpopaa rule_rpopaa rule_lpusha rule_rpusha)(*strict*) apply(simp add: AF_LR_PARSER_input_def) apply(rename_tac rule_lpopa rule_rpopa rule_lpush rule_rpush rule_lpopaa rule_rpopaa rule_lpusha rule_rpusha)(*strict*) apply(simp add: AF_LR_PARSER_input_def) apply(force) apply(rename_tac rule_lpopa rule_rpopa rule_lpush rule_rpush rule_lpopaa rule_rpopaa rule_lpusha rule_rpusha)(*strict*) apply(simp add: AF_LR_PARSER_input_def) apply(rename_tac rule_lpopa rule_rpopa rule_lpush rule_rpush rule_lpopaa rule_rpopaa rule_lpusha rule_rpusha)(*strict*) apply(simp add: AF_LR_PARSER_input_def) apply(rename_tac rule_lpopa rule_rpopa rule_lpush rule_rpush rule_lpopaa rule_rpopaa rule_lpusha rule_rpusha)(*strict*) apply(simp add: AF_LR_PARSER_input_def) apply(rename_tac rule_lpopa rule_rpopa rule_lpush rule_rpush rule_lpopaa rule_rpopaa rule_lpusha rule_rpusha)(*strict*) apply(simp add: AF_LR_PARSER_input_def) apply(force) apply(rename_tac rule_lpopa rule_rpopa rule_lpush rule_rpush rule_lpopaa rule_rpopaa rule_lpusha rule_rpusha)(*strict*) apply(force) apply(rename_tac rule_lpopa rule_rpopa rule_lpush rule_rpush rule_lpopaa rule_rpopaa rule_lpusha rule_rpusha)(*strict*) apply(simp add: AF_LR_PARSER_input_def) apply(rename_tac rule_lpopa rule_rpopa rule_lpush rule_rpush rule_lpopaa rule_rpopaa rule_lpusha rule_rpusha)(*strict*) apply(simp add: AF_LR_PARSER_input_def) apply(rename_tac rule_lpopa rule_rpopa rule_lpush rule_rpush rule_lpopaa rule_rpopaa rule_lpusha rule_rpusha)(*strict*) apply(thin_tac "parser_marker P r1 = Some None") apply(thin_tac "parser_marker P r2 = Some (Some \<lparr>prod_lhs = A2, prod_rhs = w2\<rparr>)") apply(clarsimp) apply(rename_tac rule_rpusha y \<beta> z A \<alpha> a \<delta> \<delta>')(*strict*) apply(thin_tac "\<lparr>rule_lpop = [last (F_DFA_GOTO_SEQUENCE M (epda_initial M) (teB Do # \<delta>))], rule_rpop = a # y, rule_lpush = [last (F_DFA_GOTO_SEQUENCE M (epda_initial M) (teB Do # \<delta>)), F_DFA_GOTO M (last (F_DFA_GOTO_SEQUENCE M (epda_initial M) (teB Do # \<delta>))) (teB a)], rule_rpush = y\<rparr> \<in> parser_rules P") apply(rename_tac rule_rpusha y \<beta> z A \<alpha> a \<delta> \<delta>')(*strict*) apply(thin_tac "\<lparr>rule_lpop = last (F_DFA_GOTO_SEQUENCE M (epda_initial M) (teB Do # \<delta>')) # F_DFA_GOTO_SEQUENCE M (last (F_DFA_GOTO_SEQUENCE M (epda_initial M) (teB Do # \<delta>'))) w2, rule_rpop = rule_rpusha, rule_lpush = last (F_DFA_GOTO_SEQUENCE M (epda_initial M) (teB Do # \<delta>')) # F_DFA_GOTO_SEQUENCE M (last (F_DFA_GOTO_SEQUENCE M (epda_initial M) (teB Do # \<delta>'))) [teA A2], rule_rpush = rule_rpusha\<rparr> \<in> parser_rules P") apply(rename_tac rule_rpusha y \<beta> z A \<alpha> a \<delta> \<delta>')(*strict*) apply(rename_tac y1 y \<beta> z A \<alpha> a v1 v2) apply(rename_tac y1 y \<beta> z A \<alpha> a v1 v2)(*strict*) apply(subgoal_tac "valid_cfg G'") apply(rename_tac y1 y \<beta> z A \<alpha> a v1 v2)(*strict*) prefer 2 apply(rule F_CFG_AUGMENT__makes_CFG) apply(simp add: F_CFG_AUGMENT__input_def AF_LR_PARSER_input_def) apply(force) apply(rename_tac y1 y \<beta> z A \<alpha> a v1 v2)(*strict*) apply(subgoal_tac "valid_dfa M") apply(rename_tac y1 y \<beta> z A \<alpha> a v1 v2)(*strict*) prefer 2 apply(rule_tac G="G'" in Theorem6__27_a) apply(rename_tac y1 y \<beta> z A \<alpha> a v1 v2)(*strict*) apply(force) apply(rename_tac y1 y \<beta> z A \<alpha> a v1 v2)(*strict*) apply(simp add: F_CFG_AUGMENT__input_def AF_LR_PARSER_input_def) apply(force) apply(simp add: AF_LR_PARSER_input_def) apply(rename_tac y1 y \<beta> z A \<alpha> a v1 v2)(*strict*) apply(subgoal_tac "some_step_from_every_configuration M") apply(rename_tac y1 y \<beta> z A \<alpha> a v1 v2)(*strict*) prefer 2 apply(rule_tac G="G'" in F_LR_MACHINE_Complete) apply(rename_tac y1 y \<beta> z A \<alpha> a v1 v2)(*strict*) apply(force) apply(rename_tac y1 y \<beta> z A \<alpha> a v1 v2)(*strict*) apply(simp add: F_CFG_AUGMENT__input_def AF_LR_PARSER_input_def) apply(force) apply(simp add: AF_LR_PARSER_input_def) apply(rename_tac y1 y \<beta> z A \<alpha> a v1 v2)(*strict*) apply(subgoal_tac "every_state_in_some_accessible_configuration M") apply(rename_tac y1 y \<beta> z A \<alpha> a v1 v2)(*strict*) prefer 2 apply(rule F_LR_MACHINE_all_Connected) apply(rename_tac y1 y \<beta> z A \<alpha> a v1 v2)(*strict*) prefer 2 apply(simp add: F_CFG_AUGMENT__input_def AF_LR_PARSER_input_def) apply(rename_tac y1 y \<beta> z A \<alpha> a v1 v2)(*strict*) apply(force) apply(simp add: F_CFG_AUGMENT__input_def AF_LR_PARSER_input_def) apply(simp add: AF_LR_PARSER_input_def) apply(force) apply(rename_tac y1 y \<beta> z A \<alpha> a v1 v2)(*strict*) apply(subgoal_tac "some_step_from_every_configuration M") apply(rename_tac y1 y \<beta> z A \<alpha> a v1 v2)(*strict*) prefer 2 apply(rule_tac G="G'" in F_LR_MACHINE_Complete) apply(rename_tac y1 y \<beta> z A \<alpha> a v1 v2)(*strict*) apply(force) apply(rename_tac y1 y \<beta> z A \<alpha> a v1 v2)(*strict*) apply(simp add: F_CFG_AUGMENT__input_def AF_LR_PARSER_input_def) apply(force) apply(simp add: AF_LR_PARSER_input_def) apply(rename_tac y1 y \<beta> z A \<alpha> a v1 v2)(*strict*) apply(subgoal_tac "valid_parser P") apply(rename_tac y1 y \<beta> z A \<alpha> a v1 v2)(*strict*) prefer 2 apply(rule_tac G="G" in AF_LR_PARSER_valid_parser) apply(rename_tac y1 y \<beta> z A \<alpha> a v1 v2)(*strict*) apply(simp add: AF_LR_PARSER_input_def) apply(rename_tac y1 y \<beta> z A \<alpha> a v1 v2)(*strict*) apply(simp add: AF_LR_PARSER_input_def) apply(force) apply(simp add: AF_LR_PARSER_input_def) apply(rename_tac y1 y \<beta> z A \<alpha> a v1 v2)(*strict*) apply(force) apply(rename_tac y1 y \<beta> z A \<alpha> a v1 v2)(*strict*) apply(force) apply(rename_tac y1 y \<beta> z A \<alpha> a v1 v2)(*strict*) apply(force) apply(rename_tac y1 y \<beta> z A \<alpha> a v1 v2)(*strict*) apply(simp add: AF_LR_PARSER_input_def) apply(rename_tac y1 y \<beta> z A \<alpha> a v1 v2)(*strict*) apply(subgoal_tac "set (teB Do # v1) \<subseteq> two_elements_construct_domain (cfg_nonterminals G') (cfg_events G')") apply(rename_tac y1 y \<beta> z A \<alpha> a v1 v2)(*strict*) prefer 2 apply(rule viable_prefix_in_CFG) apply(rename_tac y1 y \<beta> z A \<alpha> a v1 v2)(*strict*) apply(simp add: AF_LR_PARSER_input_def) apply(rename_tac y1 y \<beta> z A \<alpha> a v1 v2)(*strict*) apply(rule Fact6_12__1) apply(force) apply(rename_tac y1 y \<beta> z A \<alpha> a v1 v2)(*strict*) apply(subgoal_tac "set (teB Do # v2 @ w2) \<subseteq> two_elements_construct_domain (cfg_nonterminals G') (cfg_events G')") apply(rename_tac y1 y \<beta> z A \<alpha> a v1 v2)(*strict*) prefer 2 apply(rule viable_prefix_in_CFG) apply(rename_tac y1 y \<beta> z A \<alpha> a v1 v2)(*strict*) apply(simp add: AF_LR_PARSER_input_def) apply(rename_tac y1 y \<beta> z A \<alpha> a v1 v2)(*strict*) apply(rule Fact6_12__1) apply(force) apply(rename_tac y1 y \<beta> z A \<alpha> a v1 v2)(*strict*) apply(subgoal_tac "valid_item_set G' k (teB Do # v1)=valid_item_set G' k (teB Do # v2 @ w2)") apply(rename_tac y1 y \<beta> z A \<alpha> a v1 v2)(*strict*) prefer 2 apply(subgoal_tac "valid_item_set G' k (teB Do # v1) = (if (teB Do # v1)=[] then (epda_initial M) else last (F_DFA_GOTO_SEQUENCE M (epda_initial M) (teB Do # v1)))") apply(rename_tac y1 y \<beta> z A \<alpha> a v1 v2)(*strict*) prefer 2 apply(rule F_LR_MACHINE_all_SOUND) apply(rename_tac y1 y \<beta> z A \<alpha> a v1 v2)(*strict*) apply(simp add: AF_LR_PARSER_input_def) apply(rename_tac y1 y \<beta> z A \<alpha> a v1 v2)(*strict*) apply(rename_tac y1 y \<beta> z A \<alpha> a v1 v2)(*strict*) apply(simp add: AF_LR_PARSER_input_def) apply(force) apply(simp add: AF_LR_PARSER_input_def) apply(simp add: AF_LR_PARSER_input_def) apply(simp add: AF_LR_PARSER_input_def) apply(rename_tac y1 y \<beta> z A \<alpha> a v1 v2)(*strict*) apply(rename_tac y1 y \<beta> z A \<alpha> a v1 v2)(*strict*) prefer 2 apply (metis two_elements_construct_domain_setB) apply(simp add: AF_LR_PARSER_input_def) apply(rename_tac y1 y \<beta> z A \<alpha> a v1 v2)(*strict*) apply (metis two_elements_construct_domain_setA) apply(rename_tac y1 y \<beta> z A \<alpha> a v1 v2)(*strict*) apply(subgoal_tac "valid_item_set G' k (teB Do # v2 @ w2) = (if (teB Do # v2 @ w2)=[] then (epda_initial M) else last (F_DFA_GOTO_SEQUENCE M (epda_initial M) (teB Do # v2 @ w2)))") apply(rename_tac y1 y \<beta> z A \<alpha> a v1 v2)(*strict*) prefer 2 apply(rule F_LR_MACHINE_all_SOUND) apply(rename_tac y1 y \<beta> z A \<alpha> a v1 v2)(*strict*) apply(simp add: AF_LR_PARSER_input_def) apply(rename_tac y1 y \<beta> z A \<alpha> a v1 v2)(*strict*) apply(simp add: AF_LR_PARSER_input_def) apply(force) apply(rename_tac y1 y \<beta> z A \<alpha> a v1 v2)(*strict*) apply(simp add: AF_LR_PARSER_input_def) apply(rename_tac y1 y \<beta> z A \<alpha> a v1 v2)(*strict*) apply(simp add: AF_LR_PARSER_input_def) apply(force) apply(rename_tac y1 y \<beta> z A \<alpha> a v1 v2)(*strict*) prefer 2 apply (metis two_elements_construct_domain_setB) apply(rename_tac y1 y \<beta> z A \<alpha> a v1 v2)(*strict*) apply (metis two_elements_construct_domain_setA) apply(rename_tac y1 y \<beta> z A \<alpha> a v1 v2)(*strict*) apply(subgoal_tac "valid_item_set G' k (teB Do # v2) = (if (teB Do # v2)=[] then (epda_initial M) else last (F_DFA_GOTO_SEQUENCE M (epda_initial M) (teB Do # v2)))") apply(rename_tac y1 y \<beta> z A \<alpha> a v1 v2)(*strict*) prefer 2 apply(rule F_LR_MACHINE_all_SOUND) apply(rename_tac y1 y \<beta> z A \<alpha> a v1 v2)(*strict*) apply(simp add: AF_LR_PARSER_input_def) apply(rename_tac y1 y \<beta> z A \<alpha> a v1 v2)(*strict*) apply(simp add: AF_LR_PARSER_input_def) apply(force) apply(rename_tac y1 y \<beta> z A \<alpha> a v1 v2)(*strict*) apply(simp add: AF_LR_PARSER_input_def) apply(rename_tac y1 y \<beta> z A \<alpha> a v1 v2)(*strict*) apply(simp add: AF_LR_PARSER_input_def) apply(force) apply(rename_tac y1 y \<beta> z A \<alpha> a v1 v2)(*strict*) prefer 2 apply (rule two_elements_construct_domain_setB) apply(rule_tac B="set (teB Do # v2 @ w2)" in subset_trans) apply(rename_tac y1 y \<beta> z A \<alpha> a v1 v2)(*strict*) apply(force) apply(rename_tac y1 y \<beta> z A \<alpha> a v1 v2)(*strict*) apply(force) apply(rename_tac y1 y \<beta> z A \<alpha> a v1 v2)(*strict*) apply (rule two_elements_construct_domain_setA) apply(rule_tac B="set (teB Do # v2 @ w2)" in subset_trans) apply(rename_tac y1 y \<beta> z A \<alpha> a v1 v2)(*strict*) apply(force) apply(rename_tac y1 y \<beta> z A \<alpha> a v1 v2)(*strict*) apply(force) apply(rename_tac y1 y \<beta> z A \<alpha> a v1 v2)(*strict*) apply(clarsimp) apply(subgoal_tac "length w2 = length (F_DFA_GOTO_SEQUENCE M (last (F_DFA_GOTO_SEQUENCE M (epda_initial M) (teB Do # v2))) w2)") apply(rename_tac y1 y \<beta> z A \<alpha> a v1 v2)(*strict*) prefer 2 apply(rule F_DFA_GOTO_SEQUENCESound_main1) apply(rename_tac y1 y \<beta> z A \<alpha> a v1 v2)(*strict*) apply(force) apply(rename_tac y1 y \<beta> z A \<alpha> a v1 v2)(*strict*) apply(force) apply(rename_tac y1 y \<beta> z A \<alpha> a v1 v2)(*strict*) apply(force) apply(rename_tac y1 y \<beta> z A \<alpha> a v1 v2)(*strict*) prefer 2 apply(simp add: AF_LR_PARSER_input_def F_LR_MACHINE_def) apply(rename_tac y1 y \<beta> z A \<alpha> a v1 v2)(*strict*) prefer 2 apply(force) apply(rename_tac y1 y \<beta> z A \<alpha> a v1 v2)(*strict*) apply(rule_tac t="last (F_DFA_GOTO_SEQUENCE M (epda_initial M) (teB Do # v2))" and s="valid_item_set G' k (teB Do # v2)" in ssubst) apply(rename_tac y1 y \<beta> z A \<alpha> a v1 v2)(*strict*) apply(force) apply(rename_tac y1 y \<beta> z A \<alpha> a v1 v2)(*strict*) apply(rule LRM_contains_theEqClasses2) apply(rename_tac y1 y \<beta> z A \<alpha> a v1 v2)(*strict*) apply(force) apply(simp add: AF_LR_PARSER_input_def) apply(force) apply(rename_tac y1 y \<beta> z A \<alpha> a v1 v2)(*strict*) apply(simp add: AF_LR_PARSER_input_def) apply(rename_tac y1 y \<beta> z A \<alpha> a v1 v2)(*strict*) apply(force) apply(rename_tac y1 y \<beta> z A \<alpha> a v1 v2)(*strict*) apply(subgoal_tac "length (teB Do#v2) = length (F_DFA_GOTO_SEQUENCE M (epda_initial M) (teB Do # v2))") apply(rename_tac y1 y \<beta> z A \<alpha> a v1 v2)(*strict*) prefer 2 apply(rule F_DFA_GOTO_SEQUENCESound_main1) apply(rename_tac y1 y \<beta> z A \<alpha> a v1 v2)(*strict*) apply(force) apply(rename_tac y1 y \<beta> z A \<alpha> a v1 v2)(*strict*) apply(force) apply(rename_tac y1 y \<beta> z A \<alpha> a v1 v2)(*strict*) apply(force) apply(rename_tac y1 y \<beta> z A \<alpha> a v1 v2)(*strict*) prefer 2 apply(simp add: AF_LR_PARSER_input_def F_LR_MACHINE_def) apply(rename_tac y1 y \<beta> z A \<alpha> a v1 v2)(*strict*) prefer 2 apply(force) apply(rename_tac y1 y \<beta> z A \<alpha> a v1 v2)(*strict*) apply(simp add: valid_dfa_def valid_dpda_def valid_pda_def valid_epda_def) apply(rename_tac y1 y \<beta> z A \<alpha> a v1 v2)(*strict*) apply(subgoal_tac "length (teB Do#v1) = length (F_DFA_GOTO_SEQUENCE M (epda_initial M) (teB Do # v1))") apply(rename_tac y1 y \<beta> z A \<alpha> a v1 v2)(*strict*) prefer 2 apply(rule F_DFA_GOTO_SEQUENCESound_main1) apply(rename_tac y1 y \<beta> z A \<alpha> a v1 v2)(*strict*) apply(force) apply(rename_tac y1 y \<beta> z A \<alpha> a v1 v2)(*strict*) apply(force) apply(rename_tac y1 y \<beta> z A \<alpha> a v1 v2)(*strict*) apply(force) apply(rename_tac y1 y \<beta> z A \<alpha> a v1 v2)(*strict*) prefer 2 apply(simp add: AF_LR_PARSER_input_def F_LR_MACHINE_def) apply(rename_tac y1 y \<beta> z A \<alpha> a v1 v2)(*strict*) prefer 2 apply(force) apply(rename_tac y1 y \<beta> z A \<alpha> a v1 v2)(*strict*) apply(simp add: valid_dfa_def valid_dpda_def valid_pda_def valid_epda_def) apply(rename_tac y1 y \<beta> z A \<alpha> a v1 v2)(*strict*) apply(rule_tac t="last (F_DFA_GOTO_SEQUENCE M (epda_initial M) (teB Do # v2 @ w2))" and s="last((last (F_DFA_GOTO_SEQUENCE M (epda_initial M) (teB Do # v2)) # F_DFA_GOTO_SEQUENCE M (last (F_DFA_GOTO_SEQUENCE M (epda_initial M) (teB Do # v2))) w2))" in ssubst) apply(rename_tac y1 y \<beta> z A \<alpha> a v1 v2)(*strict*) apply(clarsimp) apply(case_tac w2) apply(rename_tac y1 y \<beta> z A \<alpha> a v1 v2)(*strict*) apply(force) apply(rename_tac y1 y \<beta> z A \<alpha> a v1 v2 aa list)(*strict*) apply(rule conjI) apply(rename_tac y1 y \<beta> z A \<alpha> a v1 v2 aa list)(*strict*) apply(force) apply(rename_tac y1 y \<beta> z A \<alpha> a v1 v2 aa list)(*strict*) apply(rule impI) apply(subgoal_tac "\<exists>w' x'. w2 = w' @ [x']") apply(rename_tac y1 y \<beta> z A \<alpha> a v1 v2 aa list)(*strict*) prefer 2 apply(rule_tac n="length list" in NonEmptyListHasTailElem) apply(force) apply(rename_tac y1 y \<beta> z A \<alpha> a v1 v2 aa list)(*strict*) apply(thin_tac "w2=aa#list") apply(clarsimp) apply(rename_tac y1 y \<beta> z A \<alpha> a v1 v2 w' x')(*strict*) apply(rule_tac t="teB Do # v2 @ w' @ [x']" and s="(teB Do # v2) @ (w' @ [x'])" in ssubst) apply(rename_tac y1 y \<beta> z A \<alpha> a v1 v2 w' x')(*strict*) apply(force) apply(rename_tac y1 y \<beta> z A \<alpha> a v1 v2 w' x')(*strict*) apply(rule_tac t="F_DFA_GOTO_SEQUENCE M (epda_initial M) ((teB Do # v2) @ (w' @ [x']))" and s="F_DFA_GOTO_SEQUENCE M SSp SSw1 @ (F_DFA_GOTO_SEQUENCE M (last (SSp#(F_DFA_GOTO_SEQUENCE M SSp SSw1))) SSw2)" for SSp SSw1 SSw2 in ssubst) apply(rename_tac y1 y \<beta> z A \<alpha> a v1 v2 w' x')(*strict*) apply(rule F_DFA_GOTO_SEQUENCE_append_split) apply(rename_tac y1 y \<beta> z A \<alpha> a v1 v2 w' x')(*strict*) apply(force) apply(rename_tac y1 y \<beta> z A \<alpha> a v1 v2 w' x')(*strict*) apply(force) apply(rename_tac y1 y \<beta> z A \<alpha> a v1 v2 w' x')(*strict*) apply(force) apply(rename_tac y1 y \<beta> z A \<alpha> a v1 v2 w' x')(*strict*) apply(force) apply(rename_tac y1 y \<beta> z A \<alpha> a v1 v2 w' x')(*strict*) apply(simp add: AF_LR_PARSER_input_def F_LR_MACHINE_def) apply(rename_tac y1 y \<beta> z A \<alpha> a v1 v2 w' x')(*strict*) apply(simp add: AF_LR_PARSER_input_def F_LR_MACHINE_def) apply(rename_tac y1 y \<beta> z A \<alpha> a v1 v2 w' x')(*strict*) apply(clarsimp) apply(rename_tac y1 y \<beta> z A \<alpha> a v1 v2)(*strict*) apply(rule_tac t="last (F_DFA_GOTO_SEQUENCE M (epda_initial M) (teB Do # v1))" and s="last([last (F_DFA_GOTO_SEQUENCE M (epda_initial M) (teB Do # v1))])" in ssubst) apply(rename_tac y1 y \<beta> z A \<alpha> a v1 v2)(*strict*) prefer 2 apply(rule sym) apply(rule suffix_last_eq) apply(rename_tac y1 y \<beta> z A \<alpha> a v1 v2)(*strict*) apply(force) apply(rename_tac y1 y \<beta> z A \<alpha> a v1 v2)(*strict*) apply(force) apply(rename_tac y1 y \<beta> z A \<alpha> a v1 v2)(*strict*) apply(force) apply(rename_tac y1 y \<beta> z A \<alpha> a v1 v2)(*strict*) apply(force) apply(rename_tac y1 y \<beta> z A \<alpha> a v1 v2)(*strict*) apply(simp add: conflict_free_def) apply(erule_tac x="(teB Do # v2 @ w2)" in allE) apply(erule impE) apply(rename_tac y1 y \<beta> z A \<alpha> a v1 v2)(*strict*) apply(force) apply(rename_tac y1 y \<beta> z A \<alpha> a v1 v2)(*strict*) apply(erule conjE)+ apply(thin_tac "(\<forall>I1 I2. I1 \<in> valid_item_set G' k (teB Do # v2 @ w2) \<and> I2 \<in> valid_item_set G' k (teB Do # v2 @ w2) \<and> item_core I1 \<in> cfg_productions G \<and> item_core I2 \<in> cfg_productions G \<longrightarrow> \<not> item_reduce_reduce_conflict I1 I2)") apply(rename_tac y1 y \<beta> z A \<alpha> a v1 v2)(*strict*) apply(erule_tac x="\<lparr>cfg_item_lhs = A, cfg_item_rhs1 = \<alpha>, cfg_item_rhs2 = teB a # \<beta>, cfg_item_look_ahead = z\<rparr>" in allE) apply(erule_tac x="\<lparr>cfg_item_lhs = A2, cfg_item_rhs1 = w2, cfg_item_rhs2 = [], cfg_item_look_ahead = y1\<rparr>" in allE) apply(clarsimp) apply(erule impE) apply(rename_tac y1 y \<beta> z A \<alpha> a v1 v2)(*strict*) apply(simp add: item_core_def) apply(rename_tac y1 y \<beta> z A \<alpha> a v1 v2)(*strict*) apply(simp add: item_shift_reduce_conflict_def) defer apply(subgoal_tac "valid_item_set G' k (teB Do # v2 @ w2) \<in> epda_states M") apply(rename_tac y1 y \<beta> z A \<alpha> a v1 v2)(*strict*) prefer 2 apply(rule LRM_contains_theEqClasses2) apply(rename_tac y1 y \<beta> z A \<alpha> a v1 v2)(*strict*) apply(force) apply(simp add: AF_LR_PARSER_input_def) apply(force) apply(rename_tac y1 y \<beta> z A \<alpha> a v1 v2)(*strict*) apply(simp add: AF_LR_PARSER_input_def) apply(rename_tac y1 y \<beta> z A \<alpha> a v1 v2)(*strict*) apply(force) apply(rename_tac y1 y \<beta> z A \<alpha> a v1 v2)(*strict*) apply(subgoal_tac "y1 \<in> cfgSTD_first G' k (teB a # \<beta> @ liftB z)") apply(rename_tac y1 y \<beta> z A \<alpha> a v1 v2)(*strict*) apply(force) apply(rename_tac y1 y \<beta> z A \<alpha> a v1 v2)(*strict*) apply(subgoal_tac "take k (a#y) = y1") apply(rename_tac y1 y \<beta> z A \<alpha> a v1 v2)(*strict*) apply(clarify) apply(rule translate_cfgSTD_first_with_single) apply(rename_tac y1 y \<beta> z A \<alpha> a v1 v2)(*strict*) apply(force) apply(rename_tac y1 y \<beta> z A \<alpha> a v1 v2)(*strict*) apply(force) apply(rename_tac y1 y \<beta> z A \<alpha> a v1 v2)(*strict*) apply(case_tac k) apply(rename_tac y1 y \<beta> z A \<alpha> a v1 v2)(*strict*) apply(clarsimp) apply(subgoal_tac "valid_item G' 0 \<lparr>cfg_item_lhs = A2, cfg_item_rhs1 = w2, cfg_item_rhs2 = [], cfg_item_look_ahead = y1\<rparr>") apply(rename_tac y1 y \<beta> z A \<alpha> a v1 v2)(*strict*) apply(simp add: valid_item_def) apply(rename_tac y1 y \<beta> z A \<alpha> a v1 v2)(*strict*) apply(rule Fact6_12__2) apply(rename_tac y1 y \<beta> z A \<alpha> a v1 v2)(*strict*) apply(force) apply(rename_tac y1 y \<beta> z A \<alpha> a v1 v2)(*strict*) apply(force) apply(rename_tac y1 y \<beta> z A \<alpha> a v1 v2 nat)(*strict*) apply(rule_tac t="k" and s="Suc nat" in ssubst) apply(rename_tac y1 y \<beta> z A \<alpha> a v1 v2 nat)(*strict*) apply(force) apply(rename_tac y1 y \<beta> z A \<alpha> a v1 v2 nat)(*strict*) apply(rule_tac S'="S'" and Do="Do" and G'="G'" and G="G" in no_shift_reduce_conflicts_hlp) apply(rename_tac y1 y \<beta> z A \<alpha> a v1 v2 nat)(*strict*) apply(simp add: F_CFG_AUGMENT__input_def AF_LR_PARSER_input_def) apply(rename_tac y1 y \<beta> z A \<alpha> a v1 v2 nat)(*strict*) apply(force) apply(rename_tac y1 y \<beta> z A \<alpha> a v1 v2 nat)(*strict*) apply(simp add: two_elements_construct_domain_def) apply(rule conjI) apply(rename_tac y1 y \<beta> z A \<alpha> a v1 v2 nat)(*strict*) apply(clarsimp) apply(rename_tac y1 y \<beta> z A \<alpha> a v1 v2 nat)(*strict*) apply(clarsimp) apply(erule_tac P="teB Do \<in> teA ` cfg_nonterminals G'" in disjE) apply(rename_tac y1 y \<beta> z A \<alpha> a v1 v2 nat)(*strict*) apply(clarsimp) apply(rename_tac y1 y \<beta> z A \<alpha> a v1 v2 nat)(*strict*) apply(clarsimp) apply(simp add: AF_LR_PARSER_input_def) apply(clarsimp) apply(subgoal_tac "F_FRESH (cfg_events G) \<notin> cfg_events G") apply(rename_tac y1 y \<beta> z A \<alpha> a v1 v2 nat)(*strict*) apply(force) apply(rename_tac y1 y \<beta> z A \<alpha> a v1 v2 nat)(*strict*) apply(rule F_FRESH_is_fresh) apply(simp add: AF_LR_PARSER_def AF_LR_PARSER_input_def F_LR_PARSER_def) apply(simp add: F_LR_MACHINE_def F_CFG_AUGMENT_def two_elements_construct_domain_def valid_cfg_def) apply(rename_tac y1 y \<beta> z A \<alpha> a v1 v2 nat)(*strict*) apply(simp add: two_elements_construct_domain_def) apply(rule disjI2) apply(clarsimp) apply(rule inMap) apply(clarsimp) apply(simp add: AF_LR_PARSER_input_def valid_cfg_def) apply(clarsimp) apply(erule_tac A="cfg_productions G" and x="\<lparr>prod_lhs = A, prod_rhs = \<alpha> @ teB a # \<beta>\<rparr>" in ballE) apply(rename_tac y1 y \<beta> z A \<alpha> a v1 v2 nat)(*strict*) prefer 2 apply(force) apply(rename_tac y1 y \<beta> z A \<alpha> a v1 v2 nat)(*strict*) apply(clarsimp) apply(simp add: setBConcat) apply(rename_tac y1 y \<beta> z A \<alpha> a v1 v2 nat)(*strict*) apply(force) apply(rename_tac y1 y \<beta> z A \<alpha> a v1 v2 nat)(*strict*) apply(force) apply(rename_tac y1 y \<beta> z A \<alpha> a v1 v2 nat)(*strict*) prefer 3 apply(force) apply(rename_tac y1 y \<beta> z A \<alpha> a v1 v2 nat)(*strict*) prefer 3 apply(force) apply(rename_tac y1 y \<beta> z A \<alpha> a v1 v2 nat)(*strict*) apply(simp add: AF_LR_PARSER_input_def valid_cfg_def) apply(clarsimp) apply(erule_tac x="\<lparr>prod_lhs = A, prod_rhs = \<alpha> @ teB a # \<beta>\<rparr>" and A="cfg_productions G" in ballE) apply(rename_tac y1 y \<beta> z A \<alpha> a v1 v2 nat)(*strict*) prefer 2 apply(force) apply(rename_tac y1 y \<beta> z A \<alpha> a v1 v2 nat)(*strict*) apply(clarsimp) apply(rename_tac y1 y \<beta> z A \<alpha> a v1 v2 nat)(*strict*) apply(simp add: AF_LR_PARSER_input_def valid_cfg_def) apply(clarsimp) apply(erule_tac x="\<lparr>prod_lhs = A2, prod_rhs = w2\<rparr>" and A="cfg_productions G" in ballE) apply(rename_tac y1 y \<beta> z A \<alpha> a v1 v2 nat)(*strict*) prefer 2 apply(force) apply(rename_tac y1 y \<beta> z A \<alpha> a v1 v2 nat)(*strict*) apply(clarsimp) apply(rename_tac y1 y \<beta> z A \<alpha> a v1 v2 nat)(*strict*) apply(force) apply(rename_tac y1 y \<beta> z A \<alpha> a v1 v2 nat)(*strict*) apply(simp add: cfgSTD_first_def) apply(clarsimp) apply(rename_tac y1 y \<beta> z A \<alpha> a v1 v2 nat)(*strict*) apply(clarsimp) apply(rename_tac y1 \<beta> z A \<alpha> a v1 v2 nat w v)(*strict*) apply(thin_tac "(last (F_DFA_GOTO_SEQUENCE M (epda_initial M) (teB Do # v2)) # F_DFA_GOTO_SEQUENCE M (last (F_DFA_GOTO_SEQUENCE M (epda_initial M) (teB Do # v2))) w2) \<sqsupseteq> [last (F_DFA_GOTO_SEQUENCE M (epda_initial M) (teB Do # v1))] \<or> [last (F_DFA_GOTO_SEQUENCE M (epda_initial M) (teB Do # v1))] \<sqsupseteq> (last (F_DFA_GOTO_SEQUENCE M (epda_initial M) (teB Do # v2)) # F_DFA_GOTO_SEQUENCE M (last (F_DFA_GOTO_SEQUENCE M (epda_initial M) (teB Do # v2))) w2)") apply(rename_tac y1 \<beta> z A \<alpha> a v1 v2 nat w v)(*strict*) apply(thin_tac "y1 \<notin> cfgSTD_first G' (Suc nat) (teB a # \<beta> @ liftB z)") apply(thin_tac "\<lparr>prod_lhs = A2, prod_rhs = w2\<rparr> \<in> cfg_productions G") apply(thin_tac "(a # w @ Do # v) \<sqsubseteq> y1 \<or> y1 \<sqsubseteq> (a # w @ Do # v)") apply(subgoal_tac " (\<exists>w. set w \<subseteq> cfg_events G \<and> ((cfg_item_look_ahead SSI = w \<and> length w=Suc nat) \<or> (cfg_item_look_ahead SSI = w@[Do] \<and> length w<Suc nat)))" for SSI) apply(rename_tac y1 \<beta> z A \<alpha> a v1 v2 nat w v)(*strict*) prefer 2 apply(rule_tac I="\<lparr>cfg_item_lhs = A, cfg_item_rhs1 = \<alpha>, cfg_item_rhs2 = teB a # \<beta>, cfg_item_look_ahead = z\<rparr>" in lookaheads_are_kprefixes) apply(rename_tac y1 \<beta> z A \<alpha> a v1 v2 nat w v)(*strict*) apply(simp add: F_CFG_AUGMENT__input_def AF_LR_PARSER_input_def) apply(rename_tac y1 \<beta> z A \<alpha> a v1 v2 nat w v)(*strict*) apply(simp add: F_CFG_AUGMENT__input_def AF_LR_PARSER_input_def) apply(rename_tac y1 \<beta> z A \<alpha> a v1 v2 nat w v)(*strict*) apply(clarsimp) apply(simp add: AF_LR_PARSER_input_def valid_cfg_def) apply(clarsimp) apply(erule_tac x="\<lparr>prod_lhs = A, prod_rhs = \<alpha> @ teB a # \<beta>\<rparr>" and A="cfg_productions G" in ballE) apply(rename_tac y1 \<beta> z A \<alpha> a v1 v2 nat w v)(*strict*) prefer 2 apply(force) apply(rename_tac y1 \<beta> z A \<alpha> a v1 v2 nat w v)(*strict*) apply(clarsimp) apply(rename_tac y1 \<beta> z A \<alpha> a v1 v2 nat w v)(*strict*) apply(simp add: AF_LR_PARSER_input_def valid_cfg_def) apply(rename_tac y1 \<beta> z A \<alpha> a v1 v2 nat w v)(*strict*) apply(clarsimp) apply(rename_tac y1 \<beta> z A \<alpha> a v1 v2 nat w v wa)(*strict*) apply(thin_tac "\<lparr>cfg_item_lhs = A, cfg_item_rhs1 = \<alpha>, cfg_item_rhs2 = teB a # \<beta>, cfg_item_look_ahead = z\<rparr> \<in> valid_item_set G' (Suc nat) (teB Do # v2 @ w2)") apply(rename_tac y1 \<beta> z A \<alpha> a v1 v2 nat w v wa)(*strict*) apply(thin_tac "\<lparr>cfg_item_lhs = A2, cfg_item_rhs1 = w2, cfg_item_rhs2 = [], cfg_item_look_ahead = y1\<rparr> \<in> valid_item_set G' (Suc nat) (teB Do # v2 @ w2)") apply(rename_tac y1 \<beta> z A \<alpha> a v1 v2 nat w v wa)(*strict*) apply(thin_tac "valid_dfa M") apply(thin_tac "every_state_in_some_accessible_configuration M") apply(thin_tac "some_step_from_every_configuration M") apply(thin_tac "valid_parser P") apply(clarsimp) apply(rename_tac \<beta> z A \<alpha> a v1 v2 nat w v wa)(*strict*) apply(thin_tac "valid_item_set G' (Suc nat) (teB Do # v1) = valid_item_set G' (Suc nat) (teB Do # v2 @ w2)") apply(rename_tac \<beta> z A \<alpha> a v1 v2 nat w v wa)(*strict*) apply(thin_tac "teB Do \<in> two_elements_construct_domain (cfg_nonterminals G') (cfg_events G')") apply(thin_tac "set v1 \<subseteq> two_elements_construct_domain (cfg_nonterminals G') (cfg_events G')") apply(thin_tac "set v2 \<subseteq> two_elements_construct_domain (cfg_nonterminals G') (cfg_events G')") apply(thin_tac "set w2 \<subseteq> two_elements_construct_domain (cfg_nonterminals G') (cfg_events G')") apply(simp add: cfgSTD_first_def) apply(rename_tac \<beta> z A \<alpha> a v2 nat w v wa)(*strict*) apply(clarsimp) apply(rename_tac \<beta> z A \<alpha> a v2 nat w v wa x d e1 n)(*strict*) apply(subgoal_tac "suffix x z") apply(rename_tac \<beta> z A \<alpha> a v2 nat w v wa x d e1 n)(*strict*) apply(simp add: suffix_def) apply(clarsimp) apply(rename_tac \<beta> z A \<alpha> a v2 nat w v wa d e1 n c)(*strict*) apply(subgoal_tac "set c \<subseteq> cfg_events G") apply(rename_tac \<beta> z A \<alpha> a v2 nat w v wa d e1 n c)(*strict*) apply(subgoal_tac "strict_prefix w (take nat c) \<or> prefix (take nat c) w") apply(rename_tac \<beta> z A \<alpha> a v2 nat w v wa d e1 n c)(*strict*) apply(erule_tac P="strict_prefix w (take nat c)" in disjE) apply(rename_tac \<beta> z A \<alpha> a v2 nat w v wa d e1 n c)(*strict*) apply(simp add: strict_prefix_def) apply(clarsimp) apply(rename_tac \<beta> z A \<alpha> a v2 nat w v wa d e1 n c ca)(*strict*) apply(case_tac ca) apply(rename_tac \<beta> z A \<alpha> a v2 nat w v wa d e1 n c ca)(*strict*) apply(clarsimp) apply(rename_tac \<beta> z A \<alpha> a v2 nat w v wa d e1 n c ca aa list)(*strict*) apply(clarsimp) apply(rename_tac \<beta> z A \<alpha> a v2 nat w v wa d e1 n c aa list)(*strict*) apply(subgoal_tac "aa=Do") apply(rename_tac \<beta> z A \<alpha> a v2 nat w v wa d e1 n c aa list)(*strict*) apply(clarsimp) apply(rename_tac \<beta> z A \<alpha> a v2 nat w v wa d e1 n c list)(*strict*) apply(subgoal_tac "Do \<in> cfg_events G") apply(rename_tac \<beta> z A \<alpha> a v2 nat w v wa d e1 n c list)(*strict*) apply(subgoal_tac "Do \<notin> cfg_events G") apply(rename_tac \<beta> z A \<alpha> a v2 nat w v wa d e1 n c list)(*strict*) apply(force) apply(rename_tac \<beta> z A \<alpha> a v2 nat w v wa d e1 n c list)(*strict*) apply(simp add: AF_LR_PARSER_input_def F_CFG_AUGMENT_def) apply(clarsimp) apply(subgoal_tac "F_FRESH (cfg_events G) \<notin> cfg_events G") apply(rename_tac \<beta> z A \<alpha> a v2 nat w v wa d e1 n c list)(*strict*) apply(force) apply(rename_tac \<beta> z A \<alpha> a v2 nat w v wa d e1 n c list)(*strict*) apply(rule F_FRESH_is_fresh) apply(simp add: F_LR_MACHINE_def F_CFG_AUGMENT_def two_elements_construct_domain_def valid_cfg_def) apply(rename_tac \<beta> z A \<alpha> a v2 nat w v wa d e1 n c list)(*strict*) apply(rule_tac A="set c" in set_mp) apply(rename_tac \<beta> z A \<alpha> a v2 nat w v wa d e1 n c list)(*strict*) apply(force) apply(rename_tac \<beta> z A \<alpha> a v2 nat w v wa d e1 n c list)(*strict*) apply(rule_tac A="set(take nat c)" in set_mp) apply(rename_tac \<beta> z A \<alpha> a v2 nat w v wa d e1 n c list)(*strict*) apply (metis List.set_take_subset) apply(rename_tac \<beta> z A \<alpha> a v2 nat w v wa d e1 n c list)(*strict*) apply(rule_tac t="take nat c" and s="w@Do#list" in ssubst) apply(rename_tac \<beta> z A \<alpha> a v2 nat w v wa d e1 n c list)(*strict*) apply(force) apply(rename_tac \<beta> z A \<alpha> a v2 nat w v wa d e1 n c list)(*strict*) apply(simp (no_asm)) apply(rename_tac \<beta> z A \<alpha> a v2 nat w v wa d e1 n c aa list)(*strict*) apply(rule_tac t="aa" and s="((w @ aa # list) @ take (nat - length c) z)!(length w)" in ssubst) apply(rename_tac \<beta> z A \<alpha> a v2 nat w v wa d e1 n c aa list)(*strict*) apply (metis Cons_eq_appendI append_eq_appendI nth_append_length) apply(rename_tac \<beta> z A \<alpha> a v2 nat w v wa d e1 n c aa list)(*strict*) apply(rule_tac t="Do" and s="(w @ Do # v)!(length w)" in ssubst) apply(rename_tac \<beta> z A \<alpha> a v2 nat w v wa d e1 n c aa list)(*strict*) apply (metis nth_append_length) apply(rename_tac \<beta> z A \<alpha> a v2 nat w v wa d e1 n c aa list)(*strict*) apply(rule_tac t="(w @ Do # v)" and s="(w @ aa # list) @ take (nat - length c) z" in ssubst) apply(rename_tac \<beta> z A \<alpha> a v2 nat w v wa d e1 n c aa list)(*strict*) apply(force) apply(rename_tac \<beta> z A \<alpha> a v2 nat w v wa d e1 n c aa list)(*strict*) apply(force) apply(rename_tac \<beta> z A \<alpha> a v2 nat w v wa d e1 n c)(*strict*) apply(simp add: prefix_def) apply(clarsimp) apply(rename_tac \<beta> z A \<alpha> a v2 nat v wa d e1 n c ca)(*strict*) apply(erule disjE) apply(rename_tac \<beta> z A \<alpha> a v2 nat v wa d e1 n c ca)(*strict*) apply(clarsimp) apply(rename_tac \<beta> A \<alpha> a v2 nat v wa d e1 n c ca)(*strict*) apply(subgoal_tac "Do \<in> cfg_events G") apply(rename_tac \<beta> A \<alpha> a v2 nat v wa d e1 n c ca)(*strict*) apply(subgoal_tac "Do \<notin> cfg_events G") apply(rename_tac \<beta> A \<alpha> a v2 nat v wa d e1 n c ca)(*strict*) apply(force) apply(rename_tac \<beta> A \<alpha> a v2 nat v wa d e1 n c ca)(*strict*) apply(simp add: AF_LR_PARSER_input_def F_CFG_AUGMENT_def) apply(clarsimp) apply(subgoal_tac "F_FRESH (cfg_events G) \<notin> cfg_events G") apply(rename_tac \<beta> A \<alpha> a v2 nat v wa d e1 n c ca)(*strict*) apply(force) apply(rename_tac \<beta> A \<alpha> a v2 nat v wa d e1 n c ca)(*strict*) apply(rule F_FRESH_is_fresh) apply(simp add: F_LR_MACHINE_def F_CFG_AUGMENT_def two_elements_construct_domain_def valid_cfg_def) apply(rename_tac \<beta> A \<alpha> a v2 nat v wa d e1 n c ca)(*strict*) apply(rule_tac A="set wa" in set_mp) apply(rename_tac \<beta> A \<alpha> a v2 nat v wa d e1 n c ca)(*strict*) apply(force) apply(rename_tac \<beta> A \<alpha> a v2 nat v wa d e1 n c ca)(*strict*) apply(rule_tac A="set(take (nat - length c) wa)" in set_mp) apply(rename_tac \<beta> A \<alpha> a v2 nat v wa d e1 n c ca)(*strict*) apply (metis List.set_take_subset) apply(rename_tac \<beta> A \<alpha> a v2 nat v wa d e1 n c ca)(*strict*) apply(rule_tac t="take (nat - length c) wa" and s="ca@Do#v" in ssubst) apply(rename_tac \<beta> A \<alpha> a v2 nat v wa d e1 n c ca)(*strict*) apply(force) apply(rename_tac \<beta> A \<alpha> a v2 nat v wa d e1 n c ca)(*strict*) apply(simp (no_asm)) apply(rename_tac \<beta> z A \<alpha> a v2 nat v wa d e1 n c ca)(*strict*) apply(clarsimp) apply(rename_tac \<beta> A \<alpha> a v2 nat v wa d e1 n c ca)(*strict*) apply(case_tac v) apply(rename_tac \<beta> A \<alpha> a v2 nat v wa d e1 n c ca)(*strict*) apply(clarsimp) apply(rename_tac \<beta> A \<alpha> a v2 nat wa d e1 n c ca)(*strict*) apply(case_tac "nat - (length c + length wa)") apply(rename_tac \<beta> A \<alpha> a v2 nat wa d e1 n c ca)(*strict*) apply(clarsimp) apply(subgoal_tac "Do \<in> cfg_events G") apply(rename_tac \<beta> A \<alpha> a v2 nat wa d e1 n c ca)(*strict*) apply(subgoal_tac "Do \<notin> cfg_events G") apply(rename_tac \<beta> A \<alpha> a v2 nat wa d e1 n c ca)(*strict*) apply(force) apply(rename_tac \<beta> A \<alpha> a v2 nat wa d e1 n c ca)(*strict*) apply(simp add: AF_LR_PARSER_input_def F_CFG_AUGMENT_def) apply(clarsimp) apply(subgoal_tac "F_FRESH (cfg_events G) \<notin> cfg_events G") apply(rename_tac \<beta> A \<alpha> a v2 nat wa d e1 n c ca)(*strict*) apply(force) apply(rename_tac \<beta> A \<alpha> a v2 nat wa d e1 n c ca)(*strict*) apply(rule F_FRESH_is_fresh) apply(simp add: F_LR_MACHINE_def F_CFG_AUGMENT_def two_elements_construct_domain_def valid_cfg_def) apply(rename_tac \<beta> A \<alpha> a v2 nat wa d e1 n c ca)(*strict*) apply(rule_tac A="set wa" in set_mp) apply(rename_tac \<beta> A \<alpha> a v2 nat wa d e1 n c ca)(*strict*) apply(force) apply(rename_tac \<beta> A \<alpha> a v2 nat wa d e1 n c ca)(*strict*) apply(rule_tac A="set(take (nat - length c) wa)" in set_mp) apply(rename_tac \<beta> A \<alpha> a v2 nat wa d e1 n c ca)(*strict*) apply (metis List.set_take_subset) apply(rename_tac \<beta> A \<alpha> a v2 nat wa d e1 n c ca)(*strict*) apply(rule_tac t="take (nat - length c) wa" and s="ca@[Do]" in ssubst) apply(rename_tac \<beta> A \<alpha> a v2 nat wa d e1 n c ca)(*strict*) apply(force) apply(rename_tac \<beta> A \<alpha> a v2 nat wa d e1 n c ca)(*strict*) apply(simp (no_asm)) apply(rename_tac \<beta> A \<alpha> a v2 nat wa d e1 n c ca nata)(*strict*) apply(clarsimp) apply(rename_tac \<beta> A \<alpha> a v2 nat v wa d e1 n c ca aa list)(*strict*) apply(subgoal_tac "\<exists>w' x'. v = w' @ [x']") apply(rename_tac \<beta> A \<alpha> a v2 nat v wa d e1 n c ca aa list)(*strict*) prefer 2 apply(rule NonEmptyListHasTailElem) apply(force) apply(rename_tac \<beta> A \<alpha> a v2 nat v wa d e1 n c ca aa list)(*strict*) apply(thin_tac "v=aa#list") apply(clarsimp) apply(rename_tac \<beta> A \<alpha> a v2 nat wa d e1 n c ca w' x')(*strict*) apply(case_tac "nat - (length c + length wa)") apply(rename_tac \<beta> A \<alpha> a v2 nat wa d e1 n c ca w' x')(*strict*) apply(clarsimp) apply(subgoal_tac "Do \<in> cfg_events G") apply(rename_tac \<beta> A \<alpha> a v2 nat wa d e1 n c ca w' x')(*strict*) apply(subgoal_tac "Do \<notin> cfg_events G") apply(rename_tac \<beta> A \<alpha> a v2 nat wa d e1 n c ca w' x')(*strict*) apply(force) apply(rename_tac \<beta> A \<alpha> a v2 nat wa d e1 n c ca w' x')(*strict*) apply(simp add: AF_LR_PARSER_input_def F_CFG_AUGMENT_def) apply(clarsimp) apply(subgoal_tac "F_FRESH (cfg_events G) \<notin> cfg_events G") apply(rename_tac \<beta> A \<alpha> a v2 nat wa d e1 n c ca w' x')(*strict*) apply(force) apply(rename_tac \<beta> A \<alpha> a v2 nat wa d e1 n c ca w' x')(*strict*) apply(rule F_FRESH_is_fresh) apply(simp add: F_LR_MACHINE_def F_CFG_AUGMENT_def two_elements_construct_domain_def valid_cfg_def) apply(rename_tac \<beta> A \<alpha> a v2 nat wa d e1 n c ca w' x')(*strict*) apply(rule_tac A="set wa" in set_mp) apply(rename_tac \<beta> A \<alpha> a v2 nat wa d e1 n c ca w' x')(*strict*) apply(force) apply(rename_tac \<beta> A \<alpha> a v2 nat wa d e1 n c ca w' x')(*strict*) apply(rule_tac A="set(take (nat - length c) wa)" in set_mp) apply(rename_tac \<beta> A \<alpha> a v2 nat wa d e1 n c ca w' x')(*strict*) apply (metis List.set_take_subset) apply(rename_tac \<beta> A \<alpha> a v2 nat wa d e1 n c ca w' x')(*strict*) apply(rule_tac t="take (nat - length c) wa" and s="ca @ Do # w' @ [x']" in ssubst) apply(rename_tac \<beta> A \<alpha> a v2 nat wa d e1 n c ca w' x')(*strict*) apply(force) apply(rename_tac \<beta> A \<alpha> a v2 nat wa d e1 n c ca w' x')(*strict*) apply(simp (no_asm)) apply(rename_tac \<beta> A \<alpha> a v2 nat wa d e1 n c ca w' x' nata)(*strict*) apply(clarsimp) apply(rename_tac \<beta> A \<alpha> a v2 nat d e1 n c ca w' nata)(*strict*) apply(simp add: AF_LR_PARSER_input_def F_CFG_AUGMENT_def) apply(clarsimp) apply(subgoal_tac "F_FRESH (cfg_events G) \<notin> cfg_events G") apply(rename_tac \<beta> A \<alpha> a v2 nat d e1 n c ca w' nata)(*strict*) apply(force) apply(rename_tac \<beta> A \<alpha> a v2 nat d e1 n c ca w' nata)(*strict*) apply(rule F_FRESH_is_fresh) apply(simp add: F_LR_MACHINE_def F_CFG_AUGMENT_def two_elements_construct_domain_def valid_cfg_def) apply(rename_tac \<beta> z A \<alpha> a v2 nat w v wa d e1 n c)(*strict*) apply(rule mutual_strict_prefix_prefix) apply(force) apply(rename_tac \<beta> z A \<alpha> a v2 nat w v wa d e1 n c)(*strict*) prefer 2 apply(rename_tac \<beta> z A \<alpha> a v2 nat w v wa x d e1 n)(*strict*) apply(rule liftB_creates_suffix) apply(subgoal_tac "\<exists>d' e. cfgRM.derivation G' d' \<and> maximum_of_domain d' n \<and> d' 0 = Some (pair None \<lparr>cfg_conf=\<beta> @ liftB z\<rparr>) \<and> d' n = Some (pair e \<lparr>cfg_conf=liftB x\<rparr>)") apply(rename_tac \<beta> z A \<alpha> a v2 nat w v wa x d e1 n)(*strict*) prefer 2 apply(rule_tac d="d" in cfg_derivation_can_be_translated_to_cfgRM_derivation) apply(rename_tac \<beta> z A \<alpha> a v2 nat w v wa x d e1 n)(*strict*) apply(simp add: AF_LR_PARSER_input_def) apply(rename_tac \<beta> z A \<alpha> a v2 nat w v wa x d e1 n)(*strict*) apply(force) apply(rename_tac \<beta> z A \<alpha> a v2 nat w v wa x d e1 n)(*strict*) apply(simp add: maximum_of_domain_def) apply(rename_tac \<beta> z A \<alpha> a v2 nat w v wa x d e1 n)(*strict*) apply(force) apply(rename_tac \<beta> z A \<alpha> a v2 nat w v wa x d e1 n)(*strict*) apply(force) apply(rename_tac \<beta> z A \<alpha> a v2 nat w v wa x d e1 n)(*strict*) apply (metis setA_liftB) apply(rename_tac \<beta> z A \<alpha> a v2 nat w v wa x d e1 n)(*strict*) apply(clarsimp) apply(rename_tac \<beta> z A \<alpha> a v2 nat w v wa x d e1 n d' e)(*strict*) apply(rule_tac d="d'" and i="0" and j="n" in CFGRM_terminals_stay_at_end) apply(rename_tac \<beta> z A \<alpha> a v2 nat w v wa x d e1 n d' e)(*strict*) apply(force) apply(rename_tac \<beta> z A \<alpha> a v2 nat w v wa x d e1 n d' e)(*strict*) apply(force) apply(rename_tac \<beta> z A \<alpha> a v2 nat w v wa x d e1 n d' e)(*strict*) apply (metis setA_liftB) apply(rename_tac \<beta> z A \<alpha> a v2 nat w v wa x d e1 n d' e)(*strict*) apply(force) apply(rename_tac \<beta> z A \<alpha> a v2 nat w v wa x d e1 n d' e)(*strict*) apply(force) apply(rename_tac \<beta> z A \<alpha> a v2 nat w v wa x d e1 n d' e)(*strict*) apply(force) apply(rename_tac \<beta> z A \<alpha> a v2 nat w v wa d e1 n c)(*strict*) apply(subgoal_tac "\<exists>v. set v \<subseteq> two_elements_construct_domain (cfg_nonterminals G) (cfg_events G) \<and> (case e1 of None \<Rightarrow> True|Some e' \<Rightarrow> e' \<in> cfg_productions G) \<and> SSc=\<lparr>cfg_conf = v @ liftB z\<rparr>" for SSc) apply(rename_tac \<beta> z A \<alpha> a v2 nat w v wa d e1 n c)(*strict*) prefer 2 apply(rule_tac n="n" and d="d" in CFG_preserves_partial_belongs) apply(rename_tac \<beta> z A \<alpha> a v2 nat w v wa d e1 n c)(*strict*) apply(simp add: AF_LR_PARSER_input_def) apply(rename_tac \<beta> z A \<alpha> a v2 nat w v wa d e1 n c)(*strict*) prefer 2 apply(force) apply(rename_tac \<beta> z A \<alpha> a v2 nat w v wa d e1 n c)(*strict*) prefer 2 apply(force) apply(rename_tac \<beta> z A \<alpha> a v2 nat w v wa d e1 n c)(*strict*) apply(simp add: AF_LR_PARSER_input_def valid_cfg_def) apply(clarsimp) apply(rename_tac \<beta> z A \<alpha> a v2 nat w v wa d e1 n c x)(*strict*) apply(erule_tac x="\<lparr>prod_lhs = A, prod_rhs = \<alpha> @ teB a # \<beta>\<rparr>" and A="cfg_productions G" in ballE) apply(rename_tac \<beta> z A \<alpha> a v2 nat w v wa d e1 n c x)(*strict*) prefer 2 apply(force) apply(rename_tac \<beta> z A \<alpha> a v2 nat w v wa d e1 n c x)(*strict*) apply(clarsimp) apply(simp add: setAConcat setBConcat two_elements_construct_domain_def) apply(clarsimp) apply(case_tac x) apply(rename_tac \<beta> z A \<alpha> a v2 nat w v wa d e1 n c x aa)(*strict*) apply(clarsimp) apply(rename_tac \<beta> z A \<alpha> a v2 nat w v wa d e1 n c aa)(*strict*) apply(rule inMap) apply(clarsimp) apply (metis setA_set_not subsetE) apply(rename_tac \<beta> z A \<alpha> a v2 nat w v wa d e1 n c x b)(*strict*) apply(clarsimp) apply(rename_tac \<beta> z A \<alpha> a v2 nat w v wa d e1 n c b)(*strict*) apply (metis inMap2 set_setB set_mp_prime) apply(rename_tac \<beta> z A \<alpha> a v2 nat w v wa d e1 n c p)(*strict*) apply(simp add: AF_LR_PARSER_def AF_LR_PARSER_input_def) apply(clarsimp) apply(simp add: AF_LR_PARSER_input_def F_CFG_AUGMENT_def) apply(clarsimp) apply(rename_tac \<beta> z A \<alpha> a v2 nat w v wa d e1 n c)(*strict*) apply(subgoal_tac "F_FRESH (cfg_nonterminals G) \<notin> cfg_nonterminals G") apply(rename_tac \<beta> z A \<alpha> a v2 nat w v wa d e1 n c)(*strict*) apply(force) apply(rename_tac \<beta> z A \<alpha> a v2 nat w v wa d e1 n c)(*strict*) apply(rule F_FRESH_is_fresh) apply(simp add: AF_LR_PARSER_def AF_LR_PARSER_input_def valid_cfg_def) apply(rename_tac \<beta> z A \<alpha> a v2 nat w v wa d e1 n c)(*strict*) apply(force) apply(rename_tac \<beta> z A \<alpha> a v2 nat w v wa d e1 n c)(*strict*) apply(erule exE) apply(rename_tac \<beta> z A \<alpha> a v2 nat w v wa d e1 n c va)(*strict*) apply(clarsimp) apply(rename_tac \<beta> z A \<alpha> a v2 nat w v wa d e1 n c va x)(*strict*) apply(simp add: liftB_commutes_over_concat take_liftB) apply(clarsimp) apply(rename_tac \<beta> z A \<alpha> a v2 nat w v wa d e1 n c x)(*strict*) apply(subgoal_tac "teB x \<in> set(liftB c)") apply(rename_tac \<beta> z A \<alpha> a v2 nat w v wa d e1 n c x)(*strict*) prefer 2 apply(rule set_liftB_insert) apply(force) apply(rename_tac \<beta> z A \<alpha> a v2 nat w v wa d e1 n c x)(*strict*) apply(thin_tac "x \<in> set c") apply(subgoal_tac "teB x \<in> two_elements_construct_domain (cfg_nonterminals G) (cfg_events G)") apply(rename_tac \<beta> z A \<alpha> a v2 nat w v wa d e1 n c x)(*strict*) apply(simp add: two_elements_construct_domain_def) apply(erule_tac P="teB x \<in> teA ` cfg_nonterminals G" in disjE) apply(rename_tac \<beta> z A \<alpha> a v2 nat w v wa d e1 n c x)(*strict*) apply(force) apply(rename_tac \<beta> z A \<alpha> a v2 nat w v wa d e1 n c x)(*strict*) apply(clarsimp) apply(rename_tac \<beta> z A \<alpha> a v2 nat w v wa d e1 n c x)(*strict*) apply(force) done theorem Lemma_6_36_ReduceReduce_Conflict_implies_nondeterminism: " AF_LR_PARSER_input G F Do S' G' M P k \<Longrightarrow> conflict_free G G' k \<Longrightarrow> parserS.is_forward_edge_deterministic_accessible P" apply(subgoal_tac "valid_cfg G'") prefer 2 apply(rule F_CFG_AUGMENT__makes_CFG) apply(simp add: F_CFG_AUGMENT__input_def AF_LR_PARSER_input_def) apply(force) apply(simp add: parserS.is_forward_edge_deterministic_accessible_def) apply(clarsimp) apply(rename_tac c c1 c2 e1 e2)(*strict*) apply(rename_tac r1 r2) apply(rename_tac c c1 c2 r1 r2)(*strict*) apply(subgoal_tac "r1 \<in> parser_rules P") apply(rename_tac c c1 c2 r1 r2)(*strict*) prefer 2 apply(simp add: parserS_step_relation_def) apply(rename_tac c c1 c2 r1 r2)(*strict*) apply(subgoal_tac "r2 \<in> parser_rules P") apply(rename_tac c c1 c2 r1 r2)(*strict*) prefer 2 apply(simp add: parserS_step_relation_def) apply(rename_tac c c1 c2 r1 r2)(*strict*) apply(subgoal_tac "(rule_lpop r2 \<sqsupseteq> rule_lpop r1 \<or> rule_lpop r1 \<sqsupseteq> rule_lpop r2) \<and> (rule_rpop r1 \<sqsubseteq> rule_rpop r2 \<or> rule_rpop r2 \<sqsubseteq> rule_rpop r1)") apply(rename_tac c c1 c2 r1 r2)(*strict*) prefer 2 apply(simp add: parserS_step_relation_def) apply(case_tac c1) apply(rename_tac c c1 c2 r1 r2 parserS_conf_stacka parserS_conf_schedulera)(*strict*) apply(case_tac c2) apply(rename_tac c c1 c2 r1 r2 parserS_conf_stacka parserS_conf_schedulera parserS_conf_stackaa parserS_conf_scheduleraa)(*strict*) apply(case_tac c) apply(rename_tac c c1 c2 r1 r2 parserS_conf_stacka parserS_conf_schedulera parserS_conf_stackaa parserS_conf_scheduleraa parserS_conf_stackb parserS_conf_schedulerb)(*strict*) apply(rule context_conjI) apply(rename_tac c c1 c2 r1 r2 parserS_conf_stacka parserS_conf_schedulera parserS_conf_stackaa parserS_conf_scheduleraa parserS_conf_stackb parserS_conf_schedulerb)(*strict*) prefer 2 apply(erule conjE)+ apply(erule exE)+ apply(rename_tac c c1 c2 r1 r2 parserS_conf_stacka parserS_conf_schedulera parserS_conf_stackaa parserS_conf_scheduleraa parserS_conf_stackb parserS_conf_schedulerb x xa xb xc)(*strict*) apply(rule_tac b="xa" and d="xc" in mutual_prefix_prefix) apply(force) apply(rename_tac c c1 c2 r1 r2 parserS_conf_stacka parserS_conf_schedulera parserS_conf_stackaa parserS_conf_scheduleraa parserS_conf_stackb parserS_conf_schedulerb)(*strict*) apply(erule conjE)+ apply(erule exE)+ apply(rename_tac c c1 c2 r1 r2 parserS_conf_stacka parserS_conf_schedulera parserS_conf_stackaa parserS_conf_scheduleraa parserS_conf_stackb parserS_conf_schedulerb x xa xb xc)(*strict*) apply(subgoal_tac "x @ rule_lpop r1 = xb @ rule_lpop r2") apply(rename_tac c c1 c2 r1 r2 parserS_conf_stacka parserS_conf_schedulera parserS_conf_stackaa parserS_conf_scheduleraa parserS_conf_stackb parserS_conf_schedulerb x xa xb xc)(*strict*) prefer 2 apply(force) apply(rename_tac c c1 c2 r1 r2 parserS_conf_stacka parserS_conf_schedulera parserS_conf_stackaa parserS_conf_scheduleraa parserS_conf_stackb parserS_conf_schedulerb x xa xb xc)(*strict*) apply(rule_tac a="xb" in mutual_suffix_suffix) apply(rule sym) apply(force) apply(rename_tac c c1 c2 r1 r2)(*strict*) apply(clarsimp) apply(case_tac "(parser_marker P) r1") apply(rename_tac c c1 c2 r1 r2)(*strict*) apply(subgoal_tac "parser_marker P r1 \<noteq> None") apply(rename_tac c c1 c2 r1 r2)(*strict*) apply(force) apply(rename_tac c c1 c2 r1 r2)(*strict*) apply(rule_tac G="G" in X6_3_InformationOnRules_EffectNotNone) apply(rename_tac c c1 c2 r1 r2)(*strict*) apply(simp add: AF_LR_PARSER_input_def) apply(simp add: AF_LR_PARSER_input_def) apply(force) apply(rename_tac c c1 c2 r1 r2)(*strict*) apply(simp add: AF_LR_PARSER_input_def) apply(rename_tac c c1 c2 r1 r2)(*strict*) apply(simp add: AF_LR_PARSER_input_def) apply(rename_tac c c1 c2 r1 r2)(*strict*) apply(simp add: AF_LR_PARSER_input_def) apply(rename_tac c c1 c2 r1 r2)(*strict*) apply(simp add: AF_LR_PARSER_input_def) apply(rename_tac c c1 c2 r1 r2)(*strict*) apply(simp add: AF_LR_PARSER_input_def) apply(rename_tac c c1 c2 r1 r2)(*strict*) apply(force) apply(rename_tac c c1 c2 r1 r2 a)(*strict*) apply(case_tac "(parser_marker P) r2") apply(rename_tac c c1 c2 r1 r2 a)(*strict*) apply(subgoal_tac "parser_marker P r2 \<noteq> None") apply(rename_tac c c1 c2 r1 r2 a)(*strict*) apply(force) apply(rename_tac c c1 c2 r1 r2 a)(*strict*) apply(rule_tac G="G" in X6_3_InformationOnRules_EffectNotNone) apply(rename_tac c c1 c2 r1 r2 a)(*strict*) apply(simp add: AF_LR_PARSER_input_def) apply(simp add: AF_LR_PARSER_input_def) apply(force) apply(rename_tac c c1 c2 r1 r2 a)(*strict*) apply(simp add: AF_LR_PARSER_input_def) apply(rename_tac c c1 c2 r1 r2 a)(*strict*) apply(simp add: AF_LR_PARSER_input_def) apply(rename_tac c c1 c2 r1 r2 a)(*strict*) apply(simp add: AF_LR_PARSER_input_def) apply(rename_tac c c1 c2 r1 r2 a)(*strict*) apply(simp add: AF_LR_PARSER_input_def) apply(rename_tac c c1 c2 r1 r2 a)(*strict*) apply(simp add: AF_LR_PARSER_input_def) apply(rename_tac c c1 c2 r1 r2 a)(*strict*) apply(force) apply(rename_tac c c1 c2 r1 r2 a aa)(*strict*) apply(case_tac a) apply(rename_tac c c1 c2 r1 r2 a aa)(*strict*) apply(case_tac aa) apply(rename_tac c c1 c2 r1 r2 a aa)(*strict*) apply(rule no_shift_shift_conflicts) apply(rename_tac c c1 c2 r1 r2 a aa)(*strict*) apply(force) apply(rename_tac c c1 c2 r1 r2 a aa)(*strict*) apply(force) apply(rename_tac c c1 c2 r1 r2 a aa)(*strict*) apply(force) apply(rename_tac c c1 c2 r1 r2 a aa)(*strict*) apply(force) apply(rename_tac c c1 c2 r1 r2 a aa)(*strict*) apply(force) apply(rename_tac c c1 c2 r1 r2 a aa)(*strict*) apply(force) apply(rename_tac c c1 c2 r1 r2 a aa)(*strict*) apply(force) apply(rename_tac c c1 c2 r1 r2 a aa ab)(*strict*) apply(case_tac ab) apply(rename_tac c c1 c2 r1 r2 a aa ab prod_lhs prod_rhs)(*strict*) apply(rule no_shift_reduce_conflicts) apply(rename_tac c c1 c2 r1 r2 a aa ab prod_lhs prod_rhs)(*strict*) apply(force) apply(rename_tac c c1 c2 r1 r2 a aa ab prod_lhs prod_rhs)(*strict*) apply(force) apply(rename_tac c c1 c2 r1 r2 a aa ab prod_lhs prod_rhs)(*strict*) apply(force) apply(rename_tac c c1 c2 r1 r2 a aa ab prod_lhs prod_rhs)(*strict*) apply(force) apply(rename_tac c c1 c2 r1 r2 a aa ab prod_lhs prod_rhs)(*strict*) apply(force) apply(rename_tac c c1 c2 r1 r2 a aa ab prod_lhs prod_rhs)(*strict*) apply(force) apply(rename_tac c c1 c2 r1 r2 a aa ab prod_lhs prod_rhs)(*strict*) apply(force) apply(rename_tac c c1 c2 r1 r2 a aa ab prod_lhs prod_rhs)(*strict*) apply(force) apply(rename_tac c c1 c2 r1 r2 a aa ab)(*strict*) apply(case_tac aa) apply(rename_tac c c1 c2 r1 r2 a aa ab)(*strict*) apply(rule sym) apply(case_tac ab) apply(rename_tac c c1 c2 r1 r2 a aa ab prod_lhs prod_rhs)(*strict*) apply(rule no_shift_reduce_conflicts) apply(rename_tac c c1 c2 r1 r2 a aa ab prod_lhs prod_rhs)(*strict*) apply(force) apply(rename_tac c c1 c2 r1 r2 a aa ab prod_lhs prod_rhs)(*strict*) apply(force) apply(rename_tac c c1 c2 r1 r2 a aa ab prod_lhs prod_rhs)(*strict*) apply(force) apply(rename_tac c c1 c2 r1 r2 a aa ab prod_lhs prod_rhs)(*strict*) apply(force) apply(rename_tac c c1 c2 r1 r2 a aa ab prod_lhs prod_rhs)(*strict*) apply(force) apply(rename_tac c c1 c2 r1 r2 a aa ab prod_lhs prod_rhs)(*strict*) apply(force) apply(rename_tac c c1 c2 r1 r2 a aa ab prod_lhs prod_rhs)(*strict*) apply(force) apply(rename_tac c c1 c2 r1 r2 a aa ab prod_lhs prod_rhs)(*strict*) apply(force) apply(rename_tac c c1 c2 r1 r2 a aa ab ac)(*strict*) apply(case_tac ab) apply(rename_tac c c1 c2 r1 r2 a aa ab ac prod_lhs prod_rhs)(*strict*) apply(case_tac ac) apply(rename_tac c c1 c2 r1 r2 a aa ab ac prod_lhs prod_rhs prod_lhsa prod_rhsa)(*strict*) apply(rule no_reduce_reduce_conflicts) apply(rename_tac c c1 c2 r1 r2 a aa ab ac prod_lhs prod_rhs prod_lhsa prod_rhsa)(*strict*) apply(force) apply(rename_tac c c1 c2 r1 r2 a aa ab ac prod_lhs prod_rhs prod_lhsa prod_rhsa)(*strict*) apply(force) apply(rename_tac c c1 c2 r1 r2 a aa ab ac prod_lhs prod_rhs prod_lhsa prod_rhsa)(*strict*) apply(force) apply(rename_tac c c1 c2 r1 r2 a aa ab ac prod_lhs prod_rhs prod_lhsa prod_rhsa)(*strict*) apply(force) apply(rename_tac c c1 c2 r1 r2 a aa ab ac prod_lhs prod_rhs prod_lhsa prod_rhsa)(*strict*) apply(force) apply(rename_tac c c1 c2 r1 r2 a aa ab ac prod_lhs prod_rhs prod_lhsa prod_rhsa)(*strict*) apply(force) apply(rename_tac c c1 c2 r1 r2 a aa ab ac prod_lhs prod_rhs prod_lhsa prod_rhsa)(*strict*) apply(force) apply(rename_tac c c1 c2 r1 r2 a aa ab ac prod_lhs prod_rhs prod_lhsa prod_rhsa)(*strict*) apply(force) done theorem F_LR_PARSER_is_forward_edge_deterministic_accessible: " AF_LR_PARSER_input G F Do S' G' M P k \<Longrightarrow> cfgSTD.Nonblockingness_branching G \<Longrightarrow> cfg_LRk G k \<Longrightarrow> parserS.is_forward_edge_deterministic_accessible P" apply(rule Lemma_6_36_ReduceReduce_Conflict_implies_nondeterminism) apply(force) apply(rule cfg_LRk_implies_conflict_free) apply(simp add: AF_LR_PARSER_input_def F_CFG_AUGMENT__input_def) apply(force) done end
[STATEMENT] lemma repr_boss: assumes A : "\<tau> \<Turnstile> \<delta>(x .boss)" shows "is_represented_in_state in_post_state (x .boss) Person \<tau>" [PROOF STATE] proof (prove) goal (1 subgoal): 1. is_represented_in_state in_post_state (x.boss) Person \<tau> [PROOF STEP] apply(insert A[simplified foundation16] A[THEN dot\<^sub>P\<^sub>e\<^sub>r\<^sub>s\<^sub>o\<^sub>n\<B>\<O>\<S>\<S>_def_mono, simplified foundation16]) [PROOF STATE] proof (prove) goal (1 subgoal): 1. \<lbrakk>(x.boss) \<tau> \<noteq> \<bottom> \<and> (x.boss) \<tau> \<noteq> null; x \<tau> \<noteq> \<bottom> \<and> x \<tau> \<noteq> null\<rbrakk> \<Longrightarrow> is_represented_in_state in_post_state (x.boss) Person \<tau> [PROOF STEP] unfolding is_represented_in_state_def dot\<^sub>P\<^sub>e\<^sub>r\<^sub>s\<^sub>o\<^sub>n\<B>\<O>\<S>\<S>_def eval_extract_def select\<^sub>P\<^sub>e\<^sub>r\<^sub>s\<^sub>o\<^sub>n\<B>\<O>\<S>\<S>_def in_post_state_def [PROOF STATE] proof (prove) goal (1 subgoal): 1. \<lbrakk>(case x \<tau> of \<bottom> \<Rightarrow> invalid \<tau> | \<lfloor>\<bottom>\<rfloor> \<Rightarrow> invalid \<tau> | \<lfloor>\<lfloor>obj\<rfloor>\<rfloor> \<Rightarrow> deref_oid\<^sub>P\<^sub>e\<^sub>r\<^sub>s\<^sub>o\<^sub>n snd (deref_assocs\<^sub>2\<B>\<O>\<S>\<S> snd (select_object Set{} UML_Set.OclIncluding UML_Set.OclANY (deref_oid\<^sub>P\<^sub>e\<^sub>r\<^sub>s\<^sub>o\<^sub>n snd (\<lambda>x _. \<lfloor>\<lfloor>x\<rfloor>\<rfloor>)))) (oid_of obj) \<tau>) \<noteq> \<bottom> \<and> (case x \<tau> of \<bottom> \<Rightarrow> invalid \<tau> | \<lfloor>\<bottom>\<rfloor> \<Rightarrow> invalid \<tau> | \<lfloor>\<lfloor>obj\<rfloor>\<rfloor> \<Rightarrow> deref_oid\<^sub>P\<^sub>e\<^sub>r\<^sub>s\<^sub>o\<^sub>n snd (deref_assocs\<^sub>2\<B>\<O>\<S>\<S> snd (select_object Set{} UML_Set.OclIncluding UML_Set.OclANY (deref_oid\<^sub>P\<^sub>e\<^sub>r\<^sub>s\<^sub>o\<^sub>n snd (\<lambda>x _. \<lfloor>\<lfloor>x\<rfloor>\<rfloor>)))) (oid_of obj) \<tau>) \<noteq> null; x \<tau> \<noteq> \<bottom> \<and> x \<tau> \<noteq> null\<rbrakk> \<Longrightarrow> (case x \<tau> of \<bottom> \<Rightarrow> invalid \<tau> | \<lfloor>\<bottom>\<rfloor> \<Rightarrow> invalid \<tau> | \<lfloor>\<lfloor>obj\<rfloor>\<rfloor> \<Rightarrow> deref_oid\<^sub>P\<^sub>e\<^sub>r\<^sub>s\<^sub>o\<^sub>n snd (deref_assocs\<^sub>2\<B>\<O>\<S>\<S> snd (select_object Set{} UML_Set.OclIncluding UML_Set.OclANY (deref_oid\<^sub>P\<^sub>e\<^sub>r\<^sub>s\<^sub>o\<^sub>n snd (\<lambda>x _. \<lfloor>\<lfloor>x\<rfloor>\<rfloor>)))) (oid_of obj) \<tau>) \<in> (Some \<circ> Person) ` ran (heap (snd \<tau>)) [PROOF STEP] oops
# RUN: julia -e "import Brutus; Brutus.lit(:emit_translated)" --startup-file=no %s 2>&1 | FileCheck %s function labels(N) @label start N += 1 if N < 0 @goto start end return N end ### # 1 ─ nothing::Nothing # 3 2 ┄ %2 = φ (#1 => _2, #3 => %3)::Int64 # │ %3 = Base.add_int(%2, 1)::Int64 # 4 │ %4 = Base.slt_int(%3, 0)::Bool # └── goto #4 if not %4 # 5 3 ─ goto #2 # 7 4 ─ return %3 ### emit(labels, Int64) # CHECK: func nested @"Tuple{typeof(Main.labels), Int64}"(%arg0: !jlir<"typeof(Main.labels)">, %arg1: !jlir.Int64) -> !jlir.Int64 attributes {llvm.emit_c_interface} { # CHECK-NEXT: "jlir.goto"()[^bb1] : () -> () # CHECK-NEXT: ^bb1: // pred: ^bb0 # CHECK-NEXT: "jlir.goto"(%arg1)[^bb2] : (!jlir.Int64) -> () # CHECK-NEXT: ^bb2(%0: !jlir.Int64): // 2 preds: ^bb1, ^bb3 # CHECK-NEXT: %1 = "jlir.constant"() {value = #jlir<"#<intrinsic #2 add_int>">} : () -> !jlir<"typeof(Core.IntrinsicFunction)"> # CHECK-NEXT: %2 = "jlir.constant"() {value = #jlir<"1">} : () -> !jlir.Int64 # CHECK-NEXT: %3 = "jlir.call"(%1, %0, %2) : (!jlir<"typeof(Core.IntrinsicFunction)">, !jlir.Int64, !jlir.Int64) -> !jlir.Int64 # CHECK-NEXT: %4 = "jlir.constant"() {value = #jlir<"#<intrinsic #27 slt_int>">} : () -> !jlir<"typeof(Core.IntrinsicFunction)"> # CHECK-NEXT: %5 = "jlir.constant"() {value = #jlir<"0">} : () -> !jlir.Int64 # CHECK-NEXT: %6 = "jlir.call"(%4, %3, %5) : (!jlir<"typeof(Core.IntrinsicFunction)">, !jlir.Int64, !jlir.Int64) -> !jlir.Bool # CHECK-NEXT: "jlir.gotoifnot"(%6)[^bb4, ^bb3] {operand_segment_sizes = dense<[1, 0, 0]> : vector<3xi32>} : (!jlir.Bool) -> () # CHECK-NEXT: ^bb3: // pred: ^bb2 # CHECK-NEXT: "jlir.goto"(%3)[^bb2] : (!jlir.Int64) -> () # CHECK-NEXT: ^bb4: // pred: ^bb2 # CHECK-NEXT: "jlir.return"(%3) : (!jlir.Int64) -> () # CHECK-NEXT: } # CHECK-NEXT: }
open import Relation.Binary.Core module InsertSort.Impl1.Correctness.Permutation.Alternative {A : Set} (_≤_ : A → A → Set) (tot≤ : Total _≤_) where open import Data.List open import Data.Sum open import Function open import InsertSort.Impl1 _≤_ tot≤ open import List.Permutation.Alternative A renaming (_∼_ to _∼′_) open import List.Permutation.Alternative.Correctness A open import List.Permutation.Base A lemma-insert∼′ : (x : A)(xs : List A) → (x ∷ xs) ∼′ insert x xs lemma-insert∼′ x [] = ∼refl lemma-insert∼′ x (y ∷ ys) with tot≤ x y ... | inj₁ x≤y = ∼refl ... | inj₂ y≤x = ∼trans (∼swap ∼refl) (∼head y (lemma-insert∼′ x ys)) lemma-insertSort∼′ : (xs : List A) → xs ∼′ insertSort xs lemma-insertSort∼′ [] = ∼refl lemma-insertSort∼′ (x ∷ xs) = ∼trans (∼head x (lemma-insertSort∼′ xs)) (lemma-insert∼′ x (insertSort xs)) theorem-insertSort∼ : (xs : List A) → xs ∼ insertSort xs theorem-insertSort∼ = lemma-∼′-∼ ∘ lemma-insertSort∼′
FUNCTION PR_THTA ( tmpc, pres ) C************************************************************************ C* PR_THTA * C* * C* This function computes THTA from TMPC and PRES using Poisson's * C* equation: * C* * C* THTA = TMPK * ( 1000 / PRES ) ** RKAPPA * C* * C* This function also computes STHA from TMPC and PALT, THTV from * C* TVRC and PRES, and THTV from TVRC and PALT. * C* * C* REAL PR_THTA ( TMPC, PRES ) * C* * C* Input parameters: * C* TMPC REAL Temperature in Celsius * C* PRES REAL Pressure in millibars * C* * C* Output parameters: * C* PR_THTA REAL Potential temperature in K * C** * C* Log: * C* P. Kocin/914 1980 Original source code * C* G. Huffman/GSC 8/88 Documentation; check p .le. 0 * C************************************************************************ INCLUDE 'GEMPRM.PRM' INCLUDE 'ERMISS.FNC' C------------------------------------------------------------------------ C* Check for missing values. C IF ( ERMISS ( tmpc ) .or. ERMISS ( pres ) * .or. ( pres .le. 0. ) ) THEN PR_THTA = RMISSD ELSE C C* Change temperature in degrees Celsius to Kelvin. C tmpk = PR_TMCK( tmpc ) C C* Calculate theta. C PR_THTA = tmpk * (1000. / pres) ** RKAPPA END IF C* RETURN END
[STATEMENT] lemma length_cols_mat_to_cols_list [simp]: assumes "j < dim_col A" shows "length [A $$ (i,j) . i <- [0..< dim_row A]] = dim_row A" [PROOF STATE] proof (prove) goal (1 subgoal): 1. length (map (\<lambda>i. A $$ (i, j)) [0..<dim_row A]) = dim_row A [PROOF STEP] using assms [PROOF STATE] proof (prove) using this: j < dim_col A goal (1 subgoal): 1. length (map (\<lambda>i. A $$ (i, j)) [0..<dim_row A]) = dim_row A [PROOF STEP] by simp
------------------------------------------------------------------------------ -- Definition of the gcd of two natural numbers using the Euclid's algorithm ------------------------------------------------------------------------------ {-# OPTIONS --exact-split #-} {-# OPTIONS --no-sized-types #-} {-# OPTIONS --no-universe-polymorphism #-} {-# OPTIONS --without-K #-} module FOTC.Program.GCD.Partial.GCD where open import FOTC.Base open import FOTC.Base.Loop open import FOTC.Data.Nat open import FOTC.Data.Nat.Inequalities ------------------------------------------------------------------------------ -- In GHC ≤ 7.0.4 the gcd is a partial function, i.e. gcd 0 0 = undefined. postulate gcd : D → D → D gcd-eq : ∀ m n → gcd m n ≡ (if (iszero₁ n) then (if (iszero₁ m) then error else m) else (if (iszero₁ m) then n else (if (gt m n) then gcd (m ∸ n) n else gcd m (n ∸ m)))) {-# ATP axiom gcd-eq #-}
module SIMD # A note on Val{} vs. Val(): # # For historic reasoons, SIMD's API accepted compile-time constants as # Val{N} instead of Val(N). The difference is that Val{N} is a type # (Type{Val{N}}), whereas Val(N) is a value (of type Val{N}). This is # against the intent of how Val is designed, and is also much slower # at run time unless functions are either @inline'd or @generated. # # The API has now been cleaned up. To preserve backward compatibility, # passing Val{N} instead of Val(N) is still supported. It might go # away at the next major release. #= # Various boolean types # Idea (from <Gaunard-simd.pdf>): Use Mask{N,T} instead of booleans # with different sizes abstract Boolean <: Integer for sz in (8, 16, 32, 64, 128) Intsz = Symbol(:Int, sz) UIntsz = Symbol(:UInt, sz) Boolsz = Symbol(:Bool, sz) @eval begin immutable $Boolsz <: Boolean int::$UIntsz $Boolsz(b::Bool) = new(ifelse(b, typemax($UIntsz), typemin($UIntsz))) end booltype(::Val($sz)) = $Boolsz inttype(::Val($sz)) = $Intsz uinttype(::Val($sz)) = $UIntsz Base.convert(::Type{Bool}, b::$Boolsz) = b.int != 0 Base.:~(b::$Boolsz) = $Boolsz(~b.int) Base.:!(b::$Boolsz) = ~b Base.:&(b1::$Boolsz, b2::$Boolsz) = $Boolsz(b1.int & b2.int) Base.:|(b1::$Boolsz, b2::$Boolsz) = $Boolsz(b1.int | b2.int) Base.$(:$)(b1::$Boolsz, b2::$Boolsz) = $Boolsz(b1.int $ b2.int) Base.:==(b1::$Boolsz, b2::$Boolsz) = $Boolsz(b1.int == b2.int) Base.:!=(b1::$Boolsz, b2::$Boolsz) = $Boolsz(b1.int != b2.int) Base.:<(b1::$Boolsz, b2::$Boolsz) = $Boolsz(b1.int < b2.int) Base.:<=(b1::$Boolsz, b2::$Boolsz) = $Boolsz(b1.int <= b2.int) Base.:>(b1::$Boolsz, b2::$Boolsz) = $Boolsz(b1.int > b2.int) Base.:>=(b1::$Boolsz, b2::$Boolsz) = $Boolsz(b1.int >= b2.int) end end Base.convert(::Type{Bool}, b::Boolean) = error("impossible") Base.convert{I<:Integer}(::Type{I}, b::Boolean) = I(Bool(b)) Base.convert{B<:Boolean}(::Type{B}, b::Boolean) = B(Bool(b)) Base.convert{B<:Boolean}(::Type{B}, i::Integer) = B(i!=0) booltype{T}(::Type{T}) = booltype(Val(8*sizeof(T))) inttype{T}(::Type{T}) = inttype(Val(8*sizeof(T))) uinttype{T}(::Type{T}) = uinttype(Val(8*sizeof(T))) =# # Array types for SIMD using Base: Slice, ScalarIndex """ ContiguousSubArray{T,N,P,I,L} Like `Base.FastContiguousSubArray` but without requirement for linear indexing (i.e., type parameter `L` can be `false`). # Examples ``` julia> A = view(ones(5, 5), :, [1,3]); julia> A isa Base.FastContiguousSubArray false julia> A isa SIMD.ContiguousSubArray true ``` """ ContiguousSubArray{T,N,P, I<:Union{Tuple{Union{Slice, AbstractUnitRange}, Vararg{Any}}, Tuple{Vararg{ScalarIndex}}}, L} = SubArray{T,N,P,I,L} """ ContiguousArray{T,N} Array types with contiguous first dimension. """ ContiguousArray{T,N} = Union{DenseArray{T,N}, ContiguousSubArray{T,N}} """ FastContiguousArray{T,N} This is the type of arrays that `pointer(A, i)` works. """ FastContiguousArray{T,N} = Union{DenseArray{T,N}, Base.FastContiguousSubArray{T,N}} # https://github.com/eschnett/SIMD.jl/pull/40#discussion_r254131184 # https://github.com/JuliaArrays/MappedArrays.jl/pull/24#issuecomment-460568978 # The Julia SIMD vector type const BoolTypes = Union{Bool} const IntTypes = Union{Int8, Int16, Int32, Int64, Int128} const UIntTypes = Union{UInt8, UInt16, UInt32, UInt64, UInt128} const IntegerTypes = Union{BoolTypes, IntTypes, UIntTypes} const IndexTypes = Union{IntegerTypes, Ptr} const FloatingTypes = Union{Float16, Float32, Float64} const ScalarTypes = Union{IndexTypes, FloatingTypes} const VE = Base.VecElement export Vec struct Vec{N,T<:ScalarTypes} # <: Number elts::NTuple{N,VE{T}} @inline Vec{N,T}(elts::NTuple{N, VE{T}}) where {N,T} = new{N,T}(elts) end function Base.show(io::IO, v::Vec{N,T}) where {N,T} print(io, "<$N x $T>[") join(io, [x.value for x in v.elts], ", ") print(io, "]") end # Type properties Base.eltype(::Type{Vec{N,T}}) where {N,T} = T Base.ndims( ::Type{Vec{N,T}}) where {N,T} = 1 Base.length(::Type{Vec{N,T}}) where {N,T} = N Base.size( ::Type{Vec{N,T}}) where {N,T} = (N,) # TODO: This doesn't follow Base, e.g. `size([], 3) == 1` Base.size(::Type{Vec{N,T}}, n::Integer) where {N,T} = (N,)[n] Base.eltype(V::Vec) = eltype(typeof(V)) Base.ndims( V::Vec) = ndims(typeof(V)) Base.length(V::Vec) = length(typeof(V)) Base.size( V::Vec) = size(typeof(V)) Base.size( V::Vec, n::Integer) = size(typeof(V), n) # Type conversion # Create vectors from scalars or tuples @generated function (::Type{Vec{N,T}})(x::S) where {N,T,S<:ScalarTypes} quote $(Expr(:meta, :inline)) Vec{N,T}(tuple($([:(VE{T}(T(x))) for i in 1:N]...))) end end Vec{N,T}(xs::Tuple{}) where {N,T<:ScalarTypes} = error("illegal argument") @generated function (::Type{Vec{N,T}})(xs::NTuple{N,S}) where {N,T,S<:ScalarTypes} quote $(Expr(:meta, :inline)) Vec{N,T}(tuple($([:(VE{T}(T(xs[$i]))) for i in 1:N]...))) end end Vec(xs::NTuple{N,T}) where {N,T<:ScalarTypes} = Vec{N,T}(xs) # Convert between vectors @inline Base.convert(::Type{Vec{N,T}}, v::Vec{N,T}) where {N,T} = v @inline Base.convert(::Type{Vec{N,R}}, v::Vec{N}) where {N,R} = Vec{N,R}(NTuple{N, R}(v)) @inline Tuple(v::Vec{N}) where {N} = ntuple(i -> v.elts[i].value, Val(N)) @inline NTuple{N, T}(v::Vec{N}) where{N, T} = ntuple(i -> convert(T, v.elts[i].value), Val(N)) @generated function Base.:%(v::Vec{N,T}, ::Type{Vec{N,R}}) where {N,R,T} quote $(Expr(:meta, :inline)) Vec{N,R}(tuple($([:(v.elts[$i].value % R) for i in 1:N]...))) end end # Convert vectors to tuples @generated function Base.convert(::Type{NTuple{N,R}}, v::Vec{N,T}) where {N,R,T} quote $(Expr(:meta, :inline)) tuple($([:(R(v.elts[$i].value)) for i in 1:N]...)) end end @inline Base.convert(::Type{Tuple}, v::Vec{N,T}) where {N,T} = Base.convert(NTuple{N,T}, v) # Promotion rules # Note: Type promotion only works for subtypes of Number # Base.promote_rule{N,T<:ScalarTypes}(::Type{Vec{N,T}}, ::Type{T}) = Vec{N,T} Base.zero(::Type{Vec{N,T}}) where {N,T} = Vec{N,T}(zero(T)) Base.one(::Type{Vec{N,T}}) where {N,T} = Vec{N,T}(one(T)) Base.zero(::Vec{N,T}) where {N,T} = zero(Vec{N,T}) Base.one(::Vec{N,T}) where {N,T} = one(Vec{N,T}) # Floating point formats int_type(::Type{Float16}) = Int16 int_type(::Type{Float32}) = Int32 int_type(::Type{Float64}) = Int64 # int_type(::Type{Float128}) = Int128 # int_type(::Type{Float256}) = Int256 uint_type(::Type{Float16}) = UInt16 uint_type(::Type{Float32}) = UInt32 uint_type(::Type{Float64}) = UInt64 # uint_type(::Type{Float128}) = UInt128 # uint_type(::Type{Float256}) = UInt256 significand_bits(::Type{Float16}) = 10 significand_bits(::Type{Float32}) = 23 significand_bits(::Type{Float64}) = 52 # significand_bits(::Type{Float128}) = 112 # significand_bits(::Type{Float256}) = 136 exponent_bits(::Type{T}) where {T<:FloatingTypes} = 8*sizeof(T) - 1 - significand_bits(T) sign_bits(::Type{T}) where {T<:FloatingTypes} = 1 significand_mask(::Type{T}) where {T<:FloatingTypes} = uint_type(T)(uint_type(T)(1) << significand_bits(T) - 1) exponent_mask(::Type{T}) where {T<:FloatingTypes} = uint_type(T)(uint_type(T)(1) << exponent_bits(T) - 1) << significand_bits(T) sign_mask(::Type{T}) where {T<:FloatingTypes} = uint_type(T)(1) << (significand_bits(T) + exponent_bits(T)) for T in (Float16, Float32, Float64) @assert sizeof(int_type(T)) == sizeof(T) @assert sizeof(uint_type(T)) == sizeof(T) @assert significand_bits(T) + exponent_bits(T) + sign_bits(T) == 8*sizeof(T) @assert significand_mask(T) | exponent_mask(T) | sign_mask(T) == typemax(uint_type(T)) @assert significand_mask(T) ⊻ exponent_mask(T) ⊻ sign_mask(T) == typemax(uint_type(T)) end # Convert Julia types to LLVM types llvmtype(::Type{Bool}) = "i8" # Julia represents Tuple{Bool} as [1 x i8] # llvmtype(::Type{Bool8}) = "i8" # llvmtype(::Type{Bool16}) = "i16" # llvmtype(::Type{Bool32}) = "i32" # llvmtype(::Type{Bool64}) = "i64" # llvmtype(::Type{Bool128}) = "i128" llvmtype(::Type{Int8}) = "i8" llvmtype(::Type{Int16}) = "i16" llvmtype(::Type{Int32}) = "i32" llvmtype(::Type{Int64}) = "i64" llvmtype(::Type{Int128}) = "i128" llvmtype(::Type{<:Ptr}) = llvmtype(Int) llvmtype(::Type{UInt8}) = "i8" llvmtype(::Type{UInt16}) = "i16" llvmtype(::Type{UInt32}) = "i32" llvmtype(::Type{UInt64}) = "i64" llvmtype(::Type{UInt128}) = "i128" llvmtype(::Type{Float16}) = "half" llvmtype(::Type{Float32}) = "float" llvmtype(::Type{Float64}) = "double" # Type-dependent optimization flags # fastflags{T<:IntTypes}(::Type{T}) = "nsw" # fastflags{T<:UIntTypes}(::Type{T}) = "nuw" # fastflags{T<:FloatingTypes}(::Type{T}) = "fast" suffix(N::Integer, ::Type{T}) where {T<:IntegerTypes} = "v$(N)i$(8*sizeof(T))" suffix(N::Integer, ::Type{T}) where {T<:FloatingTypes} = "v$(N)f$(8*sizeof(T))" # Type-dependent LLVM constants function llvmconst(::Type{T}, val) where T T(val) === T(0) && return "zeroinitializer" typ = llvmtype(T) "$typ $val" end function llvmconst(::Type{Bool}, val) Bool(val) === false && return "zeroinitializer" typ = "i1" "$typ $(Int(val))" end function llvmconst(N::Integer, ::Type{T}, val) where T T(val) === T(0) && return "zeroinitializer" typ = llvmtype(T) "<" * join(["$typ $val" for i in 1:N], ", ") * ">" end function llvmconst(N::Integer, ::Type{Bool}, val) Bool(val) === false && return "zeroinitializer" typ = "i1" "<" * join(["$typ $(Int(val))" for i in 1:N], ", ") * ">" end function llvmtypedconst(::Type{T}, val) where T typ = llvmtype(T) T(val) === T(0) && return "$typ zeroinitializer" "$typ $val" end function llvmtypedconst(::Type{Bool}, val) typ = "i1" Bool(val) === false && return "$typ zeroinitializer" "$typ $(Int(val))" end # Type-dependent LLVM intrinsics llvmins(::Val{:+}, N, ::Type{T}) where {T <: IndexTypes} = "add" llvmins(::Val{:-}, N, ::Type{T}) where {T <: IndexTypes} = "sub" llvmins(::Val{:*}, N, ::Type{T}) where {T <: IntegerTypes} = "mul" llvmins(::Val{:div}, N, ::Type{T}) where {T <: IntTypes} = "sdiv" llvmins(::Val{:rem}, N, ::Type{T}) where {T <: IntTypes} = "srem" llvmins(::Val{:div}, N, ::Type{T}) where {T <: UIntTypes} = "udiv" llvmins(::Val{:rem}, N, ::Type{T}) where {T <: UIntTypes} = "urem" llvmins(::Val{:~}, N, ::Type{T}) where {T <: IntegerTypes} = "xor" llvmins(::Val{:&}, N, ::Type{T}) where {T <: IntegerTypes} = "and" llvmins(::Val{:|}, N, ::Type{T}) where {T <: IntegerTypes} = "or" llvmins(::Val{:⊻}, N, ::Type{T}) where {T <: IntegerTypes} = "xor" llvmins(::Val{:<<}, N, ::Type{T}) where {T <: IntegerTypes} = "shl" llvmins(::Val{:>>>}, N, ::Type{T}) where {T <: IntegerTypes} = "lshr" llvmins(::Val{:>>}, N, ::Type{T}) where {T <: UIntTypes} = "lshr" llvmins(::Val{:>>}, N, ::Type{T}) where {T <: IntTypes} = "ashr" llvmins(::Val{:(==)}, N, ::Type{T}) where {T <: IntegerTypes} = "icmp eq" llvmins(::Val{:(!=)}, N, ::Type{T}) where {T <: IntegerTypes} = "icmp ne" llvmins(::Val{:(>)}, N, ::Type{T}) where {T <: IntTypes} = "icmp sgt" llvmins(::Val{:(>=)}, N, ::Type{T}) where {T <: IntTypes} = "icmp sge" llvmins(::Val{:(<)}, N, ::Type{T}) where {T <: IntTypes} = "icmp slt" llvmins(::Val{:(<=)}, N, ::Type{T}) where {T <: IntTypes} = "icmp sle" llvmins(::Val{:(>)}, N, ::Type{T}) where {T <: UIntTypes} = "icmp ugt" llvmins(::Val{:(>=)}, N, ::Type{T}) where {T <: UIntTypes} = "icmp uge" llvmins(::Val{:(<)}, N, ::Type{T}) where {T <: UIntTypes} = "icmp ult" llvmins(::Val{:(<=)}, N, ::Type{T}) where {T <: UIntTypes} = "icmp ule" llvmins(::Val{:vifelse}, N, ::Type{T}) where {T} = "select" llvmins(::Val{:+}, N, ::Type{T}) where {T <: FloatingTypes} = "fadd" llvmins(::Val{:-}, N, ::Type{T}) where {T <: FloatingTypes} = "fsub" llvmins(::Val{:*}, N, ::Type{T}) where {T <: FloatingTypes} = "fmul" llvmins(::Val{:/}, N, ::Type{T}) where {T <: FloatingTypes} = "fdiv" llvmins(::Val{:inv}, N, ::Type{T}) where {T <: FloatingTypes} = "fdiv" llvmins(::Val{:rem}, N, ::Type{T}) where {T <: FloatingTypes} = "frem" llvmins(::Val{:(==)}, N, ::Type{T}) where {T <: FloatingTypes} = "fcmp oeq" llvmins(::Val{:(!=)}, N, ::Type{T}) where {T <: FloatingTypes} = "fcmp une" llvmins(::Val{:(>)}, N, ::Type{T}) where {T <: FloatingTypes} = "fcmp ogt" llvmins(::Val{:(>=)}, N, ::Type{T}) where {T <: FloatingTypes} = "fcmp oge" llvmins(::Val{:(<)}, N, ::Type{T}) where {T <: FloatingTypes} = "fcmp olt" llvmins(::Val{:(<=)}, N, ::Type{T}) where {T <: FloatingTypes} = "fcmp ole" llvmins(::Val{:^}, N, ::Type{T}) where {T <: FloatingTypes} = "@llvm.pow.$(suffix(N,T))" llvmins(::Val{:abs}, N, ::Type{T}) where {T<:FloatingTypes} = "@llvm.fabs.$(suffix(N,T))" llvmins(::Val{:ceil}, N, ::Type{T}) where {T<:FloatingTypes} = "@llvm.ceil.$(suffix(N,T))" llvmins(::Val{:copysign}, N, ::Type{T}) where {T<:FloatingTypes} = "@llvm.copysign.$(suffix(N,T))" llvmins(::Val{:cos}, N, ::Type{T}) where {T<:FloatingTypes} = "@llvm.cos.$(suffix(N,T))" llvmins(::Val{:exp}, N, ::Type{T}) where {T<:FloatingTypes} = "@llvm.exp.$(suffix(N,T))" llvmins(::Val{:exp2}, N, ::Type{T}) where {T<:FloatingTypes} = "@llvm.exp2.$(suffix(N,T))" llvmins(::Val{:floor}, N, ::Type{T}) where {T<:FloatingTypes} = "@llvm.floor.$(suffix(N,T))" llvmins(::Val{:fma}, N, ::Type{T}) where {T<:FloatingTypes} = "@llvm.fma.$(suffix(N,T))" llvmins(::Val{:log}, N, ::Type{T}) where {T<:FloatingTypes} = "@llvm.log.$(suffix(N,T))" llvmins(::Val{:log10}, N, ::Type{T}) where {T<:FloatingTypes} = "@llvm.log10.$(suffix(N,T))" llvmins(::Val{:log2}, N, ::Type{T}) where {T<:FloatingTypes} = "@llvm.log2.$(suffix(N,T))" llvmins(::Val{:max}, N, ::Type{T}) where {T<:FloatingTypes} = "@llvm.maxnum.$(suffix(N,T))" llvmins(::Val{:min}, N, ::Type{T}) where {T<:FloatingTypes} = "@llvm.minnum.$(suffix(N,T))" # llvmins(::Val{:max}, N, ::Type{T}) where {T<:FloatingTypes} = # "@llvm.maximum.$(suffix(N,T))" # llvmins(::Val{:min}, N, ::Type{T}) where {T<:FloatingTypes} = # "@llvm.minimum.$(suffix(N,T))" llvmins(::Val{:muladd}, N, ::Type{T}) where {T<:FloatingTypes} = "@llvm.fmuladd.$(suffix(N,T))" llvmins(::Val{:powi}, N, ::Type{T}) where {T<:FloatingTypes} = "@llvm.powi.$(suffix(N,T))" llvmins(::Val{:round}, N, ::Type{T}) where {T<:FloatingTypes} = "@llvm.rint.$(suffix(N,T))" llvmins(::Val{:sin}, N, ::Type{T}) where {T<:FloatingTypes} = "@llvm.sin.$(suffix(N,T))" llvmins(::Val{:sqrt}, N, ::Type{T}) where {T<:FloatingTypes} = "@llvm.sqrt.$(suffix(N,T))" llvmins(::Val{:trunc}, N, ::Type{T}) where {T<:FloatingTypes} = "@llvm.trunc.$(suffix(N,T))" # Convert between LLVM scalars, vectors, and arrays function scalar2vector(vec, siz, typ, sca) instrs = [] accum(nam, i) = i<0 ? "undef" : i==siz-1 ? nam : "$(nam)_iter$i" for i in 0:siz-1 push!(instrs, "$(accum(vec,i)) = " * "insertelement <$siz x $typ> $(accum(vec,i-1)), " * "$typ $sca, i32 $i") end instrs end function array2vector(vec, siz, typ, arr, tmp="$(arr)_av") instrs = [] accum(nam, i) = i<0 ? "undef" : i==siz-1 ? nam : "$(nam)_iter$i" for i in 0:siz-1 push!(instrs, "$(tmp)_elem$i = extractvalue [$siz x $typ] $arr, $i") push!(instrs, "$(accum(vec,i)) = " * "insertelement <$siz x $typ> $(accum(vec,i-1)), " * "$typ $(tmp)_elem$i, i32 $i") end instrs end function vector2array(arr, siz, typ, vec, tmp="$(vec)_va") instrs = [] accum(nam, i) = i<0 ? "undef" : i==siz-1 ? nam : "$(nam)_iter$i" for i in 0:siz-1 push!(instrs, "$(tmp)_elem$i = extractelement <$siz x $typ> $vec, i32 $i") push!(instrs, "$(accum(arr,i)) = "* "insertvalue [$siz x $typ] $(accum(arr,i-1)), " * "$typ $(tmp)_elem$i, $i") end instrs end # TODO: change argument order function subvector(vec, siz, typ, rvec, rsiz, roff, tmp="$(rvec)_sv") instrs = [] accum(nam, i) = i<0 ? "undef" : i==rsiz-1 ? nam : "$(nam)_iter$i" @assert 0 <= roff @assert roff + rsiz <= siz for i in 0:rsiz-1 push!(instrs, "$(tmp)_elem$i = extractelement <$siz x $typ> $vec, i32 $(roff+i)") push!(instrs, "$(accum(rvec,i)) = " * "insertelement <$rsiz x $typ> $(accum(rvec,i-1)), " * "$typ $(tmp)_elem$i, i32 $i") end instrs end function extendvector(vec, siz, typ, voff, vsiz, val, rvec, tmp="$(rvec)_ev") instrs = [] accum(nam, i) = i<0 ? "undef" : i==siz+vsiz-1 ? nam : "$(nam)_iter$i" rsiz = siz + vsiz for i in 0:siz-1 push!(instrs, "$(tmp)_elem$i = extractelement <$siz x $typ> $vec, i32 $i") push!(instrs, "$(accum(rvec,i)) = " * "insertelement <$rsiz x $typ> $(accum(rvec,i-1)), " * "$typ $(tmp)_elem$i, i32 $i") end for i in siz:siz+vsiz-1 push!(instrs, "$(accum(rvec,i)) = " * "insertelement <$rsiz x $typ> $(accum(rvec,i-1)), $val, i32 $i") end instrs end # Element-wise access import Base.setindex export setindex @generated function setindex(v::Vec{N,T}, x::Number, ::Val{I}) where {N,T,I} @assert isa(I, Integer) 1 <= I <= N || throw(BoundsError()) typ = llvmtype(T) ityp = llvmtype(Int) vtyp = "<$N x $typ>" decls = [] instrs = [] push!(instrs, "%res = insertelement $vtyp %0, $typ %1, $ityp $(I-1)") push!(instrs, "ret $vtyp %res") quote $(Expr(:meta, :inline)) Vec{N,T}(Base.llvmcall($((join(decls, "\n"), join(instrs, "\n"))), NTuple{N,VE{T}}, Tuple{NTuple{N,VE{T}}, T}, v.elts, T(x))) end end @inline function setindex(v::Vec{N,T}, x::Number, ::Type{Val{I}}) where {N,T,I} setindex(v, x, Val(I)) end @generated function setindex(v::Vec{N,T}, x::Number, i::Int) where {N,T} typ = llvmtype(T) ityp = llvmtype(Int) vtyp = "<$N x $typ>" decls = [] instrs = [] push!(instrs, "%res = insertelement $vtyp %0, $typ %2, $ityp %1") push!(instrs, "ret $vtyp %res") quote $(Expr(:meta, :inline)) @boundscheck 1 <= i <= N || throw(BoundsError()) Vec{N,T}(Base.llvmcall($((join(decls, "\n"), join(instrs, "\n"))), NTuple{N,VE{T}}, Tuple{NTuple{N,VE{T}}, Int, T}, v.elts, i-1, T(x))) end end setindex(v::Vec{N,T}, x::Number, i) where {N,T} = setindex(v, x, Int(i)) Base.@propagate_inbounds Base.getindex(v::Vec{N,T}, ::Val{I}) where {N,T,I} = v.elts[I].value Base.@propagate_inbounds Base.getindex(v::Vec{N,T}, ::Type{Val{I}}) where {N,T,I} = Base.getindex(v, Val(I)) Base.@propagate_inbounds Base.getindex(v::Vec{N,T}, i) where {N,T} = v.elts[i].value # Type conversion @generated function Base.reinterpret(::Type{Vec{N,R}}, v1::Vec{N1,T1}) where {N,R,N1,T1} @assert N*sizeof(R) == N1*sizeof(T1) typ1 = llvmtype(T1) vtyp1 = "<$N1 x $typ1>" typr = llvmtype(R) vtypr = "<$N x $typr>" decls = [] instrs = [] push!(instrs, "%res = bitcast $vtyp1 %0 to $vtypr") push!(instrs, "ret $vtypr %res") quote $(Expr(:meta, :inline)) Vec{N,R}(Base.llvmcall($((join(decls, "\n"), join(instrs, "\n"))), NTuple{N,VE{R}}, Tuple{NTuple{N1,VE{T1}}}, v1.elts)) end end # Generic function wrappers # Functions taking one argument @generated function llvmwrap(::Val{Op}, v1::Vec{N,T1}, ::Type{R} = T1) where {Op,N,T1,R} @assert isa(Op, Symbol) typ1 = llvmtype(T1) vtyp1 = "<$N x $typ1>" typr = llvmtype(R) vtypr = "<$N x $typr>" ins = llvmins(Val(Op), N, T1) decls = [] instrs = [] if ins[1] == '@' push!(decls, "declare $vtypr $ins($vtyp1)") push!(instrs, "%res = call $vtypr $ins($vtyp1 %0)") else if Op === :~ @assert T1 <: IntegerTypes otherval = -1 elseif Op === :inv @assert T1 <: FloatingTypes otherval = 1.0 else otherval = 0 end otherarg = llvmconst(N, T1, otherval) push!(instrs, "%res = $ins $vtyp1 $otherarg, %0") end push!(instrs, "ret $vtypr %res") quote $(Expr(:meta, :inline)) Vec{N,R}(Base.llvmcall($((join(decls, "\n"), join(instrs, "\n"))), NTuple{N,VE{R}}, Tuple{NTuple{N,VE{T1}}}, v1.elts)) end end # Functions taking one Bool argument @generated function llvmwrap(::Val{Op}, v1::Vec{N,Bool}, ::Type{Bool} = Bool) where {Op,N} @assert isa(Op, Symbol) btyp = llvmtype(Bool) vbtyp = "<$N x $btyp>" ins = llvmins(Val(Op), N, Bool) decls = [] instrs = [] push!(instrs, "%arg1 = trunc $vbtyp %0 to <$N x i1>") otherarg = llvmconst(N, Bool, true) push!(instrs, "%res = $ins <$N x i1> $otherarg, %arg1") push!(instrs, "%resb = zext <$N x i1> %res to $vbtyp") push!(instrs, "ret $vbtyp %resb") quote $(Expr(:meta, :inline)) Vec{N,Bool}(Base.llvmcall($((join(decls, "\n"), join(instrs, "\n"))), NTuple{N,VE{Bool}}, Tuple{NTuple{N,VE{Bool}}}, v1.elts)) end end # Functions taking two arguments @generated function llvmwrap(::Val{Op}, v1::Vec{N,T1}, v2::Vec{N,T2}, ::Type{R} = T1) where {Op,N,T1,T2,R} @assert isa(Op, Symbol) typ1 = llvmtype(T1) vtyp1 = "<$N x $typ1>" typ2 = llvmtype(T2) vtyp2 = "<$N x $typ2>" typr = llvmtype(R) vtypr = "<$N x $typr>" ins = llvmins(Val(Op), N, T1) decls = [] instrs = [] if ins[1] == '@' push!(decls, "declare $vtypr $ins($vtyp1, $vtyp2)") push!(instrs, "%res = call $vtypr $ins($vtyp1 %0, $vtyp2 %1)") else push!(instrs, "%res = $ins $vtyp1 %0, %1") end push!(instrs, "ret $vtypr %res") quote $(Expr(:meta, :inline)) Vec{N,R}(Base.llvmcall($((join(decls, "\n"), join(instrs, "\n"))), NTuple{N,VE{R}}, Tuple{NTuple{N,VE{T1}}, NTuple{N,VE{T2}}}, v1.elts, v2.elts)) end end # Functions taking two arguments, second argument is a scalar @generated function llvmwrap(::Val{Op}, v1::Vec{N,T1}, s2::ScalarTypes, ::Type{R} = T1) where {Op,N,T1,R} @assert isa(Op, Symbol) typ1 = llvmtype(T1) vtyp1 = "<$N x $typ1>" typ2 = llvmtype(s2) typr = llvmtype(R) vtypr = "<$N x $typr>" ins = llvmins(Val(Op), N, T1) decls = [] instrs = [] if ins[1] == '@' push!(decls, "declare $vtypr $ins($vtyp1, $typ2)") push!(instrs, "%res = call $vtypr $ins($vtyp1 %0, $typ2 %1)") else push!(instrs, "%res = $ins $vtyp1 %0, %1") end push!(instrs, "ret $vtypr %res") quote $(Expr(:meta, :inline)) Vec{N,R}(Base.llvmcall($((join(decls, "\n"), join(instrs, "\n"))), NTuple{N,VE{R}}, Tuple{NTuple{N,VE{T1}}, $s2}, v1.elts, s2)) end end # Functions taking two arguments, returning Bool @generated function llvmwrap(::Val{Op}, v1::Vec{N,T1}, v2::Vec{N,T2}, ::Type{Bool}) where {Op,N,T1,T2} @assert isa(Op, Symbol) btyp = llvmtype(Bool) vbtyp = "<$N x $btyp>" abtyp = "[$N x $btyp]" typ1 = llvmtype(T1) vtyp1 = "<$N x $typ1>" atyp1 = "[$N x $typ1]" typ2 = llvmtype(T2) vtyp2 = "<$N x $typ2>" atyp2 = "[$N x $typ2]" ins = llvmins(Val(Op), N, T1) decls = [] instrs = [] if false && N == 1 append!(instrs, array2vector("%arg1", N, typ1, "%0", "%arg1arr")) append!(instrs, array2vector("%arg2", N, typ2, "%1", "%arg2arr")) push!(instrs, "%cond = $ins $vtyp1 %arg1, %arg2") push!(instrs, "%res = zext <$N x i1> %cond to $vbtyp") append!(instrs, vector2array("%resarr", N, btyp, "%res")) push!(instrs, "ret $abtyp %resarr") else push!(instrs, "%res = $ins $vtyp1 %0, %1") push!(instrs, "%resb = zext <$N x i1> %res to $vbtyp") push!(instrs, "ret $vbtyp %resb") end quote $(Expr(:meta, :inline)) Vec{N,Bool}(Base.llvmcall($((join(decls, "\n"), join(instrs, "\n"))), NTuple{N,VE{Bool}}, Tuple{NTuple{N,VE{T1}}, NTuple{N,VE{T2}}}, v1.elts, v2.elts)) end end # Functions taking a vector and a scalar argument # @generated function llvmwrap{Op,N,T1,T2,R}(::Val{Op}, v1::Vec{N,T1}, # x2::T2, ::Type{R} = T1) # @assert isa(Op, Symbol) # typ1 = llvmtype(T1) # atyp1 = "[$N x $typ1]" # vtyp1 = "<$N x $typ1>" # typ2 = llvmtype(T2) # typr = llvmtype(R) # atypr = "[$N x $typr]" # vtypr = "<$N x $typr>" # ins = llvmins(Val(Op), N, T1) # decls = [] # instrs = [] # append!(instrs, array2vector("%arg1", N, typ1, "%0", "%arg1arr")) # if ins[1] == '@' # push!(decls, "declare $vtypr $ins($vtyp1, $typ2)") # push!(instrs, "%res = call $vtypr $ins($vtyp1 %arg1, $typ2 %1)") # else # push!(instrs, "%res = $ins $vtyp1 %arg1, %1") # end # append!(instrs, vector2array("%resarr", N, typr, "%res")) # push!(instrs, "ret $atypr %resarr") # quote # $(Expr(:meta, :inline)) # Vec{N,R}(Base.llvmcall($((join(decls, "\n"), join(instrs, "\n"))), # NTuple{N,R}, Tuple{NTuple{N,T1}, T2}, v1.elts, x2)) # end # end # Functions taking two Bool arguments, returning Bool @generated function llvmwrap(::Val{Op}, v1::Vec{N,Bool}, v2::Vec{N,Bool}, ::Type{Bool} = Bool) where {Op,N} @assert isa(Op, Symbol) btyp = llvmtype(Bool) vbtyp = "<$N x $btyp>" ins = llvmins(Val(Op), N, Bool) decls = [] instrs = [] push!(instrs, "%arg1 = trunc $vbtyp %0 to <$N x i1>") push!(instrs, "%arg2 = trunc $vbtyp %1 to <$N x i1>") push!(instrs, "%res = $ins <$N x i1> %arg1, %arg2") push!(instrs, "%resb = zext <$N x i1> %res to $vbtyp") push!(instrs, "ret $vbtyp %resb") quote $(Expr(:meta, :inline)) Vec{N,Bool}(Base.llvmcall($((join(decls, "\n"), join(instrs, "\n"))), NTuple{N,VE{Bool}}, Tuple{NTuple{N,VE{Bool}}, NTuple{N,VE{Bool}}}, v1.elts, v2.elts)) end end # Functions taking three arguments @generated function llvmwrap(::Val{Op}, v1::Vec{N,T1}, v2::Vec{N,T2}, v3::Vec{N,T3}, ::Type{R} = T1) where {Op,N,T1,T2,T3,R} @assert isa(Op, Symbol) typ1 = llvmtype(T1) vtyp1 = "<$N x $typ1>" typ2 = llvmtype(T2) vtyp2 = "<$N x $typ2>" typ3 = llvmtype(T3) vtyp3 = "<$N x $typ3>" typr = llvmtype(R) vtypr = "<$N x $typr>" ins = llvmins(Val(Op), N, T1) decls = [] instrs = [] if ins[1] == '@' push!(decls, "declare $vtypr $ins($vtyp1, $vtyp2, $vtyp3)") push!(instrs, "%res = call $vtypr $ins($vtyp1 %0, $vtyp2 %1, $vtyp3 %2)") else push!(instrs, "%res = $ins $vtyp1 %0, %1, %2") end push!(instrs, "ret $vtypr %res") quote $(Expr(:meta, :inline)) Vec{N,R}(Base.llvmcall($((join(decls, "\n"), join(instrs, "\n"))), NTuple{N,VE{R}}, Tuple{NTuple{N,VE{T1}}, NTuple{N,VE{T2}}, NTuple{N,VE{T3}}}, v1.elts, v2.elts, v3.elts)) end end @generated function llvmwrapshift(::Val{Op}, v1::Vec{N,T}, ::Val{I}) where {Op,N,T,I} @assert isa(Op, Symbol) if I >= 0 op = Op i = I else if Op === :>> || Op === :>>> op = :<< else @assert Op === :<< if T <: Unsigned op = :>>> else op = :>> end end i = -I end @assert op in (:<<, :>>, :>>>) @assert i >= 0 typ = llvmtype(T) vtyp = "<$N x $typ>" ins = llvmins(Val(op), N, T) decls = [] instrs = [] nbits = 8*sizeof(T) if (op === :>> && T <: IntTypes) || i < nbits count = llvmconst(N, T, min(nbits-1, i)) push!(instrs, "%res = $ins $vtyp %0, $count") push!(instrs, "ret $vtyp %res") else zero = llvmconst(N, T, 0) push!(instrs, "return $vtyp $zero") end quote $(Expr(:meta, :inline)) Vec{N,T}(Base.llvmcall($((join(decls, "\n"), join(instrs, "\n"))), NTuple{N,VE{T}}, Tuple{NTuple{N,VE{T}}}, v1.elts)) end end @generated function llvmwrapshift(::Val{Op}, v1::Vec{N,T}, x2::Unsigned) where {Op,N,T} @assert isa(Op, Symbol) typ = llvmtype(T) vtyp = "<$N x $typ>" ins = llvmins(Val(Op), N, T) decls = [] instrs = [] append!(instrs, scalar2vector("%count", N, typ, "%1")) nbits = 8*sizeof(T) push!(instrs, "%tmp = $ins $vtyp %0, %count") push!(instrs, "%inbounds = icmp ult $typ %1, $nbits") if Op === :>> && T <: IntTypes nbits1 = llvmconst(N, T, 8*sizeof(T)-1) push!(instrs, "%limit = $ins $vtyp %0, $nbits1") push!(instrs, "%res = select i1 %inbounds, $vtyp %tmp, $vtyp %limit") else zero = llvmconst(N, T, 0) push!(instrs, "%res = select i1 %inbounds, $vtyp %tmp, $vtyp $zero") end push!(instrs, "ret $vtyp %res") quote $(Expr(:meta, :inline)) # Note that this function might be called with out-of-bounds # values for x2, assuming that the results are then ignored Vec{N,T}(Base.llvmcall($((join(decls, "\n"), join(instrs, "\n"))), NTuple{N,VE{T}}, Tuple{NTuple{N,VE{T}}, T}, v1.elts, x2 % T)) end end @generated function llvmwrapshift(::Val{Op}, v1::Vec{N,T}, x2::Integer) where {Op,N,T} if Op === :>> || Op === :>>> NegOp = :<< else @assert Op === :<< if T <: Unsigned NegOp = :>>> else NegOp = :>> end end ValOp = Val(Op) ValNegOp = Val(NegOp) quote $(Expr(:meta, :inline)) ifelse(x2 >= 0, llvmwrapshift($ValOp, v1, unsigned(x2)), llvmwrapshift($ValNegOp, v1, unsigned(-x2))) end end @generated function llvmwrapshift(::Val{Op}, v1::Vec{N,T}, v2::Vec{N,U}) where {Op,N,T,U<:UIntTypes} @assert isa(Op, Symbol) typ = llvmtype(T) vtyp = "<$N x $typ>" ins = llvmins(Val(Op), N, T) decls = [] instrs = [] push!(instrs, "%tmp = $ins $vtyp %0, %1") nbits = llvmconst(N, T, 8*sizeof(T)) push!(instrs, "%inbounds = icmp ult $vtyp %1, $nbits") if Op === :>> && T <: IntTypes nbits1 = llvmconst(N, T, 8*sizeof(T)-1) push!(instrs, "%limit = $ins $vtyp %0, $nbits1") push!(instrs, "%res = select <$N x i1> %inbounds, $vtyp %tmp, $vtyp %limit") else zero = llvmconst(N, T, 0) push!(instrs, "%res = select <$N x i1> %inbounds, $vtyp %tmp, $vtyp $zero") end push!(instrs, "ret $vtyp %res") quote $(Expr(:meta, :inline)) Vec{N,T}(Base.llvmcall($((join(decls, "\n"), join(instrs, "\n"))), NTuple{N,VE{T}}, Tuple{NTuple{N,VE{T}}, NTuple{N,VE{T}}}, v1.elts, (v2 % Vec{N,T}).elts)) end end @generated function llvmwrapshift(::Val{Op}, v1::Vec{N,T}, v2::Vec{N,U}) where {Op,N,T,U<:IntegerTypes} if Op === :>> || Op === :>>> NegOp = :<< else @assert Op === :<< if T <: Unsigned NegOp = :>>> else NegOp = :>> end end ValOp = Val(Op) ValNegOp = Val(NegOp) quote $(Expr(:meta, :inline)) vifelse(v2 >= 0, llvmwrapshift($ValOp, v1, v2 % Vec{N,unsigned(U)}), llvmwrapshift($ValNegOp, v1, -v2 % Vec{N,unsigned(U)})) end end # Conditionals for op in (:(==), :(!=), :(<), :(<=), :(>), :(>=)) @eval begin @inline Base.$op(v1::Vec{N,T}, v2::Vec{N,T}) where {N,T} = llvmwrap(Val($(QuoteNode(op))), v1, v2, Bool) end end @inline function Base.cmp(v1::Vec{N,T}, v2::Vec{N,T}) where {N,T} I = int_type(T) vifelse(isequal(v1, v2), Vec{N,I}(0), vifelse(isless(v1, v2), Vec{N,I}(-1), Vec{N,I}(1))) end @inline function Base.isfinite(v1::Vec{N,T}) where {N,T<:FloatingTypes} U = uint_type(T) em = Vec{N,U}(exponent_mask(T)) iv = reinterpret(Vec{N,U}, v1) iv & em != em end @inline Base.isinf(v1::Vec{N,T}) where {N,T<:FloatingTypes} = abs(v1) == Vec{N,T}(Inf) @inline Base.isnan(v1::Vec{N,T}) where {N,T<:FloatingTypes} = v1 != v1 @inline function Base.issubnormal(v1::Vec{N,T}) where {N,T<:FloatingTypes} U = uint_type(T) em = Vec{N,U}(exponent_mask(T)) sm = Vec{N,U}(significand_mask(T)) iv = reinterpret(Vec{N,U}, v1) (iv & em == Vec{N,U}(0)) & (iv & sm != Vec{N,U}(0)) end @inline function Base.signbit(v1::Vec{N,T}) where {N,T<:FloatingTypes} U = uint_type(T) sm = Vec{N,U}(sign_mask(T)) iv = reinterpret(Vec{N,U}, v1) iv & sm != Vec{N,U}(0) end export vifelse vifelse(c::Bool, x, y) = ifelse(c, x, y) @generated function vifelse(v1::Vec{N,Bool}, v2::Vec{N,T}, v3::Vec{N,T}) where {N,T} btyp = llvmtype(Bool) vbtyp = "<$N x $btyp>" abtyp = "[$N x $btyp]" typ = llvmtype(T) vtyp = "<$N x $typ>" atyp = "[$N x $typ]" decls = [] instrs = [] if false && N == 1 append!(instrs, array2vector("%arg1", N, btyp, "%0", "%arg1arr")) append!(instrs, array2vector("%arg2", N, typ, "%1", "%arg2arr")) append!(instrs, array2vector("%arg3", N, typ, "%2", "%arg3arr")) push!(instrs, "%cond = trunc $vbtyp %arg1 to <$N x i1>") push!(instrs, "%res = select <$N x i1> %cond, $vtyp %arg2, $vtyp %arg3") append!(instrs, vector2array("%resarr", N, typ, "%res")) push!(instrs, "ret $atyp %resarr") else push!(instrs, "%cond = trunc $vbtyp %0 to <$N x i1>") push!(instrs, "%res = select <$N x i1> %cond, $vtyp %1, $vtyp %2") push!(instrs, "ret $vtyp %res") end quote $(Expr(:meta, :inline)) Vec{N,T}(Base.llvmcall($((join(decls, "\n"), join(instrs, "\n"))), NTuple{N,VE{T}}, Tuple{NTuple{N,VE{Bool}}, NTuple{N,VE{T}}, NTuple{N,VE{T}}}, v1.elts, v2.elts, v3.elts)) end end # Integer arithmetic functions for op in (:~, :+, :-) @eval begin @inline Base.$op(v1::Vec{N,T}) where {N,T<:IntegerTypes} = llvmwrap(Val($(QuoteNode(op))), v1) end end @inline Base.:!(v1::Vec{N,Bool}) where {N} = ~v1 @inline function Base.abs(v1::Vec{N,T}) where {N,T<:IntTypes} # s = -Vec{N,T}(signbit(v1)) s = v1 >> Val(8*sizeof(T)) # Note: -v1 == ~v1 + 1 (s ⊻ v1) - s end @inline Base.abs(v1::Vec{N,T}) where {N,T<:UIntTypes} = v1 # TODO: Try T(v1>0) - T(v1<0) # use a shift for v1<0 # evaluate v1>0 as -v1<0 ? @inline Base.sign(v1::Vec{N,T}) where {N,T<:IntTypes} = vifelse(v1 == Vec{N,T}(0), Vec{N,T}(0), vifelse(v1 < Vec{N,T}(0), Vec{N,T}(-1), Vec{N,T}(1))) @inline Base.sign(v1::Vec{N,T}) where {N,T<:UIntTypes} = vifelse(v1 == Vec{N,T}(0), Vec{N,T}(0), Vec{N,T}(1)) @inline Base.signbit(v1::Vec{N,T}) where {N,T<:IntTypes} = v1 < Vec{N,T}(0) @inline Base.signbit(v1::Vec{N,T}) where {N,T<:UIntTypes} = Vec{N,Bool}(false) for op in (:&, :|, :⊻, :+, :-, :*, :div, :rem) @eval begin @inline Base.$op(v1::Vec{N,T}, v2::Vec{N,T}) where {N,T<:IntegerTypes} = llvmwrap(Val($(QuoteNode(op))), v1, v2) end end @inline Base.copysign(v1::Vec{N,T}, v2::Vec{N,T}) where {N,T<:IntTypes} = vifelse(signbit(v2), -abs(v1), abs(v1)) @inline Base.copysign(v1::Vec{N,T}, v2::Vec{N,T}) where {N,T<:UIntTypes} = v1 @inline Base.flipsign(v1::Vec{N,T}, v2::Vec{N,T}) where {N,T<:IntTypes} = vifelse(signbit(v2), -v1, v1) @inline Base.flipsign(v1::Vec{N,T}, v2::Vec{N,T}) where {N,T<:UIntTypes} = v1 @inline Base.max(v1::Vec{N,T}, v2::Vec{N,T}) where {N,T<:IntegerTypes} = vifelse(v1>=v2, v1, v2) @inline Base.min(v1::Vec{N,T}, v2::Vec{N,T}) where {N,T<:IntegerTypes} = vifelse(v1>=v2, v2, v1) @inline function Base.muladd(v1::Vec{N,T}, v2::Vec{N,T}, v3::Vec{N,T}) where {N,T<:IntegerTypes} v1*v2+v3 end # TODO: Handle negative shift counts # use vifelse # ensure vifelse is efficient for op in (:<<, :>>, :>>>) @eval begin @inline Base.$op(v1::Vec{N,T}, ::Val{I}) where {N,T<:IntegerTypes,I} = llvmwrapshift(Val($(QuoteNode(op))), v1, Val(I)) @inline Base.$op(v1::Vec{N,T}, ::Type{Val{I}}) where {N,T<:IntegerTypes,I} = Base.$op(v1, Val(I)) @inline Base.$op(v1::Vec{N,T}, x2::Unsigned) where {N,T<:IntegerTypes} = llvmwrapshift(Val($(QuoteNode(op))), v1, x2) @inline Base.$op(v1::Vec{N,T}, x2::Int) where {N,T<:IntegerTypes} = llvmwrapshift(Val($(QuoteNode(op))), v1, x2) @inline Base.$op(v1::Vec{N,T}, x2::Integer) where {N,T<:IntegerTypes} = llvmwrapshift(Val($(QuoteNode(op))), v1, x2) @inline Base.$op(v1::Vec{N,T}, v2::Vec{N,U}) where {N,T<:IntegerTypes,U<:UIntTypes} = llvmwrapshift(Val($(QuoteNode(op))), v1, v2) @inline Base.$op(v1::Vec{N,T}, v2::Vec{N,U}) where {N,T<:IntegerTypes,U<:IntegerTypes} = llvmwrapshift(Val($(QuoteNode(op))), v1, v2) @inline Base.$op(x1::T, v2::Vec{N,T}) where {N,T<:IntegerTypes} = $op(Vec{N,T}(x1), v2) end end # Floating point arithmetic functions for op in ( :+, :-, :abs, :ceil, :cos, :exp, :exp2, :floor, :inv, :log, :log10, :log2, :round, :sin, :sqrt, :trunc) @eval begin @inline Base.$op(v1::Vec{N,T}) where {N,T<:FloatingTypes} = llvmwrap(Val($(QuoteNode(op))), v1) end end @inline Base.exp10(v1::Vec{N,T}) where {N,T<:FloatingTypes} = Vec{N,T}(10)^v1 @inline Base.sign(v1::Vec{N,T}) where {N,T<:FloatingTypes} = vifelse(v1 == Vec{N,T}(0.0), Vec{N,T}(0.0), copysign(Vec{N,T}(1.0), v1)) for op in (:+, :-, :*, :/, :^, :copysign, :max, :min, :rem) @eval begin @inline Base.$op(v1::Vec{N,T}, v2::Vec{N,T}) where {N,T<:FloatingTypes} = llvmwrap(Val($(QuoteNode(op))), v1, v2) end end # Using `IntegerTypes` here so that this definition "wins" against # `^(::ScalarTypes, v2::Vec)`. @inline Base.:^(v1::Vec{N,T}, x2::IntegerTypes) where {N,T<:FloatingTypes} = llvmwrap(Val(:powi), v1, Int(x2)) @inline Base.:^(v1::Vec{N,T}, x2::Integer) where {N,T<:FloatingTypes} = llvmwrap(Val(:powi), v1, Int(x2)) @inline Base.flipsign(v1::Vec{N,T}, v2::Vec{N,T}) where {N,T<:FloatingTypes} = vifelse(signbit(v2), -v1, v1) # Do what Base does for HWNumber: @inline Base.literal_pow(::typeof(^), x::Vec, ::Val{0}) = one(typeof(x)) @inline Base.literal_pow(::typeof(^), x::Vec, ::Val{1}) = x @inline Base.literal_pow(::typeof(^), x::Vec, ::Val{2}) = x*x @inline Base.literal_pow(::typeof(^), x::Vec, ::Val{3}) = x*x*x for op in (:fma, :muladd) @eval begin @inline function Base.$op(v1::Vec{N,T}, v2::Vec{N,T}, v3::Vec{N,T}) where {N,T<:FloatingTypes} llvmwrap(Val($(QuoteNode(op))), v1, v2, v3) end end end # Type promotion # Promote scalars of all IntegerTypes to vectors of IntegerTypes, leaving the # vector type unchanged for op in ( :(==), :(!=), :(<), :(<=), :(>), :(>=), :&, :|, :⊻, :+, :-, :*, :copysign, :div, :flipsign, :max, :min, :rem) @eval begin @inline Base.$op(s1::Bool, v2::Vec{N,Bool}) where {N} = $op(Vec{N,Bool}(s1), v2) @inline Base.$op(s1::IntegerTypes, v2::Vec{N,T}) where {N,T<:IntegerTypes} = $op(Vec{N,T}(s1), v2) @inline Base.$op(v1::Vec{N,T}, s2::IntegerTypes) where {N,T<:IntegerTypes} = $op(v1, Vec{N,T}(s2)) end end @inline vifelse(c::Vec{N,Bool}, s1::IntegerTypes, v2::Vec{N,T}) where {N,T<:IntegerTypes} = vifelse(c, Vec{N,T}(s1), v2) @inline vifelse(c::Vec{N,Bool}, v1::Vec{N,T}, s2::IntegerTypes) where {N,T<:IntegerTypes} = vifelse(c, v1, Vec{N,T}(s2)) for op in (:muladd,) @eval begin @inline Base.$op(s1::IntegerTypes, v2::Vec{N,T}, v3::Vec{N,T}) where {N,T<:IntegerTypes} = $op(Vec{N,T}(s1), v2, v3) @inline Base.$op(v1::Vec{N,T}, s2::IntegerTypes, v3::Vec{N,T}) where {N,T<:IntegerTypes} = $op(v1, Vec{N,T}(s2), v3) @inline Base.$op(s1::IntegerTypes, s2::IntegerTypes, v3::Vec{N,T}) where {N,T<:IntegerTypes} = $op(Vec{N,T}(s1), Vec{N,T}(s2), v3) @inline Base.$op(v1::Vec{N,T}, v2::Vec{N,T}, s3::IntegerTypes) where {N,T<:IntegerTypes} = $op(v1, v2, Vec{N,T}(s3)) @inline Base.$op(s1::IntegerTypes, v2::Vec{N,T}, s3::IntegerTypes) where {N,T<:IntegerTypes} = $op(Vec{N,T}(s1), v2, Vec{N,T}(s3)) @inline Base.$op(v1::Vec{N,T}, s2::IntegerTypes, s3::IntegerTypes) where {N,T<:IntegerTypes} = $op(v1, Vec{N,T}(s2), Vec{N,T}(s3)) end end # Promote scalars of all ScalarTypes to vectors of FloatingTypes, leaving the # vector type unchanged for op in ( :(==), :(!=), :(<), :(<=), :(>), :(>=), :+, :-, :*, :/, :^, :copysign, :flipsign, :max, :min, :rem) @eval begin @inline Base.$op(s1::ScalarTypes, v2::Vec{N,T}) where {N,T<:FloatingTypes} = $op(Vec{N,T}(s1), v2) @inline Base.$op(v1::Vec{N,T}, s2::ScalarTypes) where {N,T<:FloatingTypes} = $op(v1, Vec{N,T}(s2)) end end @inline vifelse(c::Vec{N,Bool}, s1::ScalarTypes, v2::Vec{N,T}) where {N,T<:FloatingTypes} = vifelse(c, Vec{N,T}(s1), v2) @inline vifelse(c::Vec{N,Bool}, v1::Vec{N,T}, s2::ScalarTypes) where {N,T<:FloatingTypes} = vifelse(c, v1, Vec{N,T}(s2)) for op in (:fma, :muladd) @eval begin @inline Base.$op(s1::ScalarTypes, v2::Vec{N,T}, v3::Vec{N,T}) where {N,T<:FloatingTypes} = $op(Vec{N,T}(s1), v2, v3) @inline Base.$op(v1::Vec{N,T}, s2::ScalarTypes, v3::Vec{N,T}) where {N,T<:FloatingTypes} = $op(v1, Vec{N,T}(s2), v3) @inline Base.$op(s1::ScalarTypes, s2::ScalarTypes, v3::Vec{N,T}) where {N,T<:FloatingTypes} = $op(Vec{N,T}(s1), Vec{N,T}(s2), v3) @inline Base.$op(v1::Vec{N,T}, v2::Vec{N,T}, s3::ScalarTypes) where {N,T<:FloatingTypes} = $op(v1, v2, Vec{N,T}(s3)) @inline Base.$op(s1::ScalarTypes, v2::Vec{N,T}, s3::ScalarTypes) where {N,T<:FloatingTypes} = $op(Vec{N,T}(s1), v2, Vec{N,T}(s3)) @inline Base.$op(v1::Vec{N,T}, s2::ScalarTypes, s3::ScalarTypes) where {N,T<:FloatingTypes} = $op(v1, Vec{N,T}(s2), Vec{N,T}(s3)) end end # Poitner arithmetics between Ptr, IntegerTypes, and vectors of them. for op in (:+, :-) @eval begin @inline Base.$op(v1::Vec{N,<:Ptr}, v2::Vec{N,<:IntegerTypes}) where {N} = llvmwrap(Val($(QuoteNode(op))), v1, v2) @inline Base.$op(v1::Vec{N,<:IntegerTypes}, v2::Vec{N,<:Ptr}) where {N} = llvmwrap(Val($(QuoteNode(op))), v1, v2) @inline Base.$op(s1::P, v2::Vec{N,<:IntegerTypes}) where {N,P<:Ptr} = $op(Vec{N,P}(s1), v2) @inline Base.$op(v1::Vec{N,<:IntegerTypes}, s2::P) where {N,P<:Ptr} = $op(v1, Vec{N,P}(s2)) end end # Reduction operations # TODO: map, mapreduce function getneutral(op::Symbol, ::Type{T}) where T zs = Dict{Symbol,T}() if T <: IntegerTypes zs[:&] = ~T(0) zs[:|] = T(0) end zs[:max] = typemin(T) zs[:min] = typemax(T) zs[:+] = T(0) zs[:*] = T(1) zs[op] end if VERSION >= v"0.7.0-beta2.195" nextpow2(n) = nextpow(2, n) end # We cannot pass in the neutral element via Val{}; if we try, Julia refuses to # inline this function, which is then disastrous for performance @generated function llvmwrapreduce(::Val{Op}, v::Vec{N,T}) where {Op,N,T} @assert isa(Op, Symbol) z = getneutral(Op, T) typ = llvmtype(T) decls = [] instrs = [] n = N nam = "%0" nold,n = n,nextpow2(n) if n > nold namold,nam = nam,"%vec_$n" append!(instrs, extendvector(namold, nold, typ, n, n-nold, llvmtypedconst(T,z), nam)) end while n > 1 nold,n = n, div(n, 2) namold,nam = nam,"%vec_$n" vtyp = "<$n x $typ>" ins = llvmins(Val(Op), n, T) append!(instrs, subvector(namold, nold, typ, "$(nam)_1", n, 0)) append!(instrs, subvector(namold, nold, typ, "$(nam)_2", n, n)) if ins[1] == '@' push!(decls, "declare $vtyp $ins($vtyp, $vtyp)") push!(instrs, "$nam = call $vtyp $ins($vtyp $(nam)_1, $vtyp $(nam)_2)") else push!(instrs, "$nam = $ins $vtyp $(nam)_1, $(nam)_2") end end push!(instrs, "%res = extractelement <$n x $typ> $nam, i32 0") push!(instrs, "ret $typ %res") quote $(Expr(:meta, :inline)) Base.llvmcall($((join(decls, "\n"), join(instrs, "\n"))), T, Tuple{NTuple{N,VE{T}}}, v.elts) end end @inline Base.all(v::Vec{N,T}) where {N,T<:IntegerTypes} = llvmwrapreduce(Val(:&), v) @inline Base.any(v::Vec{N,T}) where {N,T<:IntegerTypes} = llvmwrapreduce(Val(:|), v) @inline Base.maximum(v::Vec{N,T}) where {N,T<:FloatingTypes} = llvmwrapreduce(Val(:max), v) @inline Base.minimum(v::Vec{N,T}) where {N,T<:FloatingTypes} = llvmwrapreduce(Val(:min), v) @inline Base.prod(v::Vec{N,T}) where {N,T} = llvmwrapreduce(Val(:*), v) @inline Base.sum(v::Vec{N,T}) where {N,T} = llvmwrapreduce(Val(:+), v) @generated function Base.reduce(::Val{Op}, v::Vec{N,T}) where {Op,N,T} @assert isa(Op, Symbol) z = getneutral(Op, T) stmts = [] n = N push!(stmts, :($(Symbol(:v,n)) = v)) nold,n = n,nextpow2(n) if n > nold push!(stmts, :($(Symbol(:v,n)) = Vec{$n,T}($(Expr(:tuple, [:($(Symbol(:v,nold)).elts[$i]) for i in 1:nold]..., [z for i in nold+1:n]...))))) end while n > 1 nold,n = n, div(n, 2) push!(stmts, :($(Symbol(:v,n,"lo")) = Vec{$n,T}($(Expr(:tuple, [:($(Symbol(:v,nold)).elts[$i]) for i in 1:n]...,))))) push!(stmts, :($(Symbol(:v,n,"hi")) = Vec{$n,T}($(Expr(:tuple, [:($(Symbol(:v,nold)).elts[$i]) for i in n+1:nold]...))))) push!(stmts, :($(Symbol(:v,n)) = $Op($(Symbol(:v,n,"lo")), $(Symbol(:v,n,"hi"))))) end push!(stmts, :(v1[1])) Expr(:block, Expr(:meta, :inline), stmts...) end @inline function Base.reduce(::Type{Val{Op}}, v::Vec{N,T}) where {Op,N,T} Base.reduce(Val(Op), v) end @inline Base.maximum(v::Vec{N,T}) where {N,T<:IntegerTypes} = reduce(Val(:max), v) @inline Base.minimum(v::Vec{N,T}) where {N,T<:IntegerTypes} = reduce(Val(:min), v) # Load and store functions export valloc function valloc(::Type{T}, N::Int, sz::Int) where T @assert N > 0 @assert sz >= 0 # We use padding to align the address of the first element, and # also to ensure that we can access past the last element up to # the next full vector width padding = N-1 + mod(-sz, N) mem = Vector{T}(undef, sz + padding) addr = Int(pointer(mem)) off = mod(-addr, N * sizeof(T)) @assert mod(off, sizeof(T)) == 0 off = fld(off, sizeof(T)) @assert 0 <= off <= padding res = view(mem, off+1 : off+sz) addr2 = Int(pointer(res)) @assert mod(addr2, N * sizeof(T)) == 0 res end function valloc(f, ::Type{T}, N::Int, sz::Int) where T mem = valloc(T, N, sz) @inbounds for i in 1:sz mem[i] = f(i) end mem end export vload, vloada, vloadnt @generated function vload(::Type{Vec{N,T}}, ptr::Ptr{T}, ::Val{Aligned} = Val(false), ::Val{Nontemporal} = Val(false)) where {N,T,Aligned,Nontemporal} @assert isa(Aligned, Bool) ptyp = llvmtype(Int) typ = llvmtype(T) vtyp = "<$N x $typ>" decls = [] instrs = [] if Aligned align = N * sizeof(T) else align = sizeof(T) # This is overly optimistic end flags = [""] if align > 0 push!(flags, "align $align") end if Nontemporal push!(flags, "!nontemporal !{i32 1}") end if VERSION < v"v0.7.0-DEV" push!(instrs, "%ptr = bitcast $typ* %0 to $vtyp*") else push!(instrs, "%ptr = inttoptr $ptyp %0 to $vtyp*") end push!(instrs, "%res = load $vtyp, $vtyp* %ptr" * join(flags, ", ")) push!(instrs, "ret $vtyp %res") quote $(Expr(:meta, :inline)) Vec{N,T}(Base.llvmcall($((join(decls, "\n"), join(instrs, "\n"))), NTuple{N,VE{T}}, Tuple{Ptr{T}}, ptr)) end end @inline function vload(::Type{Vec{N,T}}, ptr::Ptr{T}, ::Type{Val{Aligned}}, ::Type{Val{Nontemporal}} = Val{false}) where {N,T,Aligned,Nontemporal} vload(Vec{N, T}, ptr, Val(Aligned), Val(Nontemporal)) end @inline vloada(::Type{Vec{N,T}}, ptr::Ptr{T}) where {N,T} = vload(Vec{N,T}, ptr, Val(true)) @inline vloadnt(::Type{Vec{N,T}}, ptr::Ptr{T}) where {N,T} = vload(Vec{N,T}, ptr, Val(true), Val(true)) @inline function vload(::Type{Vec{N,T}}, arr::FastContiguousArray{T,1}, i::Integer, ::Val{Aligned} = Val(false), ::Val{Nontemporal} = Val(false)) where {N,T,Aligned,Nontemporal} #TODO @boundscheck 1 <= i <= length(arr) - (N-1) || throw(BoundsError()) vload(Vec{N,T}, pointer(arr, i), Val(Aligned), Val(Nontemporal)) end @inline function vload(::Type{Vec{N,T}}, arr::FastContiguousArray{T,1}, i::Integer, ::Type{Val{Aligned}},k = Val{false}, ::Type{Val{Nontemporal}} = Val{false}) where {N,T,Aligned,Nontemporal} vload(Vec{N,T}, arr, i, Val(Aligned), Val(Nontemporal)) end @inline function vloada(::Type{Vec{N,T}}, arr::FastContiguousArray{T,1}, i::Integer) where {N,T} vload(Vec{N,T}, arr, i, Val(true)) end @inline function vloadnt(::Type{Vec{N,T}}, arr::Union{Array{T,1},SubArray{T,1}}, i::Integer) where {N,T} vload(Vec{N,T}, arr, i, Val(true), Val(true)) end @inline vload(::Type{Vec{N,T}}, ptr::Ptr{T}, mask::Nothing, ::Val{Aligned} = Val(false)) where {N,T,Aligned} = vload(Vec{N,T}, ptr, Val(Aligned)) @inline vload(::Type{Vec{N,T}}, ptr::Ptr{T}, mask::Nothing, ::Type{Val{Aligned}}) where {N,T,Aligned} = vload(Vec{N,T}, ptr, make, Val(Aligned)) @generated function vload(::Type{Vec{N,T}}, ptr::Ptr{T}, mask::Vec{N,Bool}, ::Val{Aligned} = Val(false)) where {N,T,Aligned} @assert isa(Aligned, Bool) ptyp = llvmtype(Int) typ = llvmtype(T) vtyp = "<$N x $typ>" btyp = llvmtype(Bool) vbtyp = "<$N x $btyp>" decls = [] instrs = [] if Aligned align = N * sizeof(T) else align = sizeof(T) # This is overly optimistic end if VERSION < v"v0.7.0-DEV" push!(instrs, "%ptr = bitcast $typ* %0 to $vtyp*") else push!(instrs, "%ptr = inttoptr $ptyp %0 to $vtyp*") end push!(instrs, "%mask = trunc $vbtyp %1 to <$N x i1>") push!(decls, "declare $vtyp @llvm.masked.load.$(suffix(N,T))($vtyp*, i32, " * "<$N x i1>, $vtyp)") push!(instrs, "%res = call $vtyp @llvm.masked.load.$(suffix(N,T))($vtyp* %ptr, " * "i32 $align, <$N x i1> %mask, $vtyp $(llvmconst(N, T, 0)))") push!(instrs, "ret $vtyp %res") quote $(Expr(:meta, :inline)) Vec{N,T}(Base.llvmcall($((join(decls, "\n"), join(instrs, "\n"))), NTuple{N,VE{T}}, Tuple{Ptr{T}, NTuple{N,VE{Bool}}}, ptr, mask.elts)) end end @inline function vload(::Type{Vec{N,T}}, ptr::Ptr{T}, mask::Vec{N,Bool}, ::Type{Val{Aligned}}) where {N,T,Aligned} vload(Vec{N,T}, ptr, mask, Val(Aligned)) end @inline vloada(::Type{Vec{N,T}}, ptr::Ptr{T}, mask::Union{Vec{N,Bool}, Nothing}) where {N,T} = vload(Vec{N,T}, ptr, mask, Val(true)) @inline function vload(::Type{Vec{N,T}}, arr::FastContiguousArray{T,1}, i::Integer, mask::Union{Vec{N,Bool}, Nothing}, ::Val{Aligned} = Val(false)) where {N,T,Aligned} #TODO @boundscheck 1 <= i <= length(arr) - (N-1) || throw(BoundsError()) vload(Vec{N,T}, pointer(arr, i), mask, Val(Aligned)) end @inline function vload(::Type{Vec{N,T}}, arr::FastContiguousArray{T,1}, i::Integer, mask::Union{Vec{N,Bool}, Nothing}, ::Type{Val{Aligned}}) where {N,T,Aligned} vload(Vec{N,T}, arr, i, mask, Val(Aligned)) end @inline function vloada(::Type{Vec{N,T}}, arr::FastContiguousArray{T,1}, i::Integer, mask::Union{Vec{N,Bool}, Nothing}) where {N,T} vload(Vec{N,T}, arr, i, mask, Val(true)) end export vstore, vstorea, vstorent @generated function vstore(v::Vec{N,T}, ptr::Ptr{T}, ::Val{Aligned} = Val(false), ::Val{Nontemporal} = Val(false)) where {N,T,Aligned,Nontemporal} @assert isa(Aligned, Bool) @assert isa(Nontemporal, Bool) ptyp = llvmtype(Int) typ = llvmtype(T) vtyp = "<$N x $typ>" decls = [] instrs = [] if Aligned align = N * sizeof(T) else align = sizeof(T) # This is overly optimistic end flags = [""] if align > 0 push!(flags, "align $align") end if Nontemporal push!(flags, "!nontemporal !{i32 1}") end if VERSION < v"v0.7.0-DEV" push!(instrs, "%ptr = bitcast $typ* %1 to $vtyp*") else push!(instrs, "%ptr = inttoptr $ptyp %1 to $vtyp*") end push!(instrs, "store $vtyp %0, $vtyp* %ptr" * join(flags, ", ")) push!(instrs, "ret void") quote $(Expr(:meta, :inline)) Base.llvmcall($((join(decls, "\n"), join(instrs, "\n"))), Cvoid, Tuple{NTuple{N,VE{T}}, Ptr{T}}, v.elts, ptr) end end @inline function vstore(v::Vec{N,T}, ptr::Ptr{T}, ::Type{Val{Aligned}}, ::Type{Val{Nontemporal}} = Val{false}) where {N,T,Aligned,Nontemporal} vstore(v, ptr, Val(Aligned), Val(Nontemporal)) end @inline vstorea(v::Vec{N,T}, ptr::Ptr{T}) where {N,T} = vstore(v, ptr, Val{true}) @inline vstorent(v::Vec{N,T}, ptr::Ptr{T}) where {N,T} = vstore(v, ptr, Val{true}, Val{true}) @inline function vstore(v::Vec{N,T}, arr::FastContiguousArray{T,1}, i::Integer, ::Val{Aligned} = Val(false), ::Val{Nontemporal} = Val(false)) where {N,T,Aligned,Nontemporal} @boundscheck 1 <= i <= length(arr) - (N-1) || throw(BoundsError()) vstore(v, pointer(arr, i), Val{Aligned}, Val{Nontemporal}) end @inline function vstore(v::Vec{N,T}, arr::FastContiguousArray{T,1}, i::Integer, ::Type{Val{Aligned}}, ::Type{Val{Nontemporal}} = Val{false}) where {N,T,Aligned,Nontemporal} vstore(v, arr, i, Val(Aligned), Val(Nontemporal)) end @inline function vstorea(v::Vec{N,T}, arr::FastContiguousArray{T,1}, i::Integer) where {N,T} vstore(v, arr, i, Val{true}) end @inline function vstorent(v::Vec{N,T}, arr::FastContiguousArray{T,1}, i::Integer) where {N,T} vstore(v, arr, i, Val{true}, Val{true}) end @inline vstore(v::Vec{N,T}, ptr::Ptr{T}, mask::Nothing, ::Val{Aligned} = Val(false)) where {N,T,Aligned} = vstore(v, ptr, Val{Aligned}) @inline vstore(v::Vec{N,T}, ptr::Ptr{T}, mask::Nothing, ::Type{Val{Aligned}}) where {N,T,Aligned} = vstore(v, ptr, mask, Val(Aligned)) @generated function vstore(v::Vec{N,T}, ptr::Ptr{T}, mask::Vec{N,Bool}, ::Val{Aligned} = Val(false)) where {N,T,Aligned} @assert isa(Aligned, Bool) ptyp = llvmtype(Int) typ = llvmtype(T) vtyp = "<$N x $typ>" btyp = llvmtype(Bool) vbtyp = "<$N x $btyp>" decls = [] instrs = [] if Aligned align = N * sizeof(T) else align = sizeof(T) # This is overly optimistic end if VERSION < v"v0.7.0-DEV" push!(instrs, "%ptr = bitcast $typ* %1 to $vtyp*") else push!(instrs, "%ptr = inttoptr $ptyp %1 to $vtyp*") end push!(instrs, "%mask = trunc $vbtyp %2 to <$N x i1>") push!(decls, "declare void @llvm.masked.store.$(suffix(N,T))($vtyp, $vtyp*, i32, " * "<$N x i1>)") push!(instrs, "call void @llvm.masked.store.$(suffix(N,T))($vtyp %0, $vtyp* %ptr, " * "i32 $align, <$N x i1> %mask)") push!(instrs, "ret void") quote $(Expr(:meta, :inline)) Base.llvmcall($((join(decls, "\n"), join(instrs, "\n"))), Cvoid, Tuple{NTuple{N,VE{T}}, Ptr{T}, NTuple{N,VE{Bool}}}, v.elts, ptr, mask.elts) end end @inline function vstore(v::Vec{N,T}, ptr::Ptr{T}, mask::Vec{N,Bool}, ::Type{Val{Aligned}}) where {N,T,Aligned} vstore(v, ptr, mask, Val(Aligned)) end @inline vstorea(v::Vec{N,T}, ptr::Ptr{T}, mask::Union{Vec{N,Bool}, Nothing}) where {N,T} = vstore(v, ptr, mask, Val{true}) @inline function vstore(v::Vec{N,T}, arr::FastContiguousArray{T,1}, i::Integer, mask::Union{Vec{N,Bool}, Nothing}, ::Val{Aligned} = Val(false), ::Val{Nontemporal} = Val(false)) where {N,T,Aligned,Nontemporal} #TODO @boundscheck 1 <= i <= length(arr) - (N-1) || throw(BoundsError()) vstore(v, pointer(arr, i), mask, Val{Aligned}, Val{Nontemporal}) end @inline function vstore(v::Vec{N,T}, arr::FastContiguousArray{T,1}, i::Integer, mask::Union{Vec{N,Bool}, Nothing}, ::Type{Val{Aligned}}, ::Type{Val{Nontemporal}} = Val{false}) where {N,T,Aligned,Nontemporal} vstore(v, arr, i, mask, Val(Aligned), Val(Nontemporal)) end @inline function vstorea(v::Vec{N,T}, arr::FastContiguousArray{T,1}, i::Integer, mask::Union{Vec{N,Bool}, Nothing}) where {N,T} vstore(v, arr, i, mask, Val{true}) end export vgather, vgathera @inline vgather( ::Type{Vec{N,T}}, ptrs::Vec{N,Ptr{T}}, mask::Nothing, ::Val{Aligned} = Val(false)) where {N,T,Aligned} = vgather(Vec{N,T}, ptrs, Vec(ntuple(_ -> true, N)), Val(Aligned)) @inline vgather( ::Type{Vec{N,T}}, ptrs::Vec{N,Ptr{T}}, mask::Nothing, ::Type{Val{Aligned}}) where {N,T,Aligned} = vgather(Vec{N,T}, ptrs, mask, Val(Aligned)) @generated function vgather( ::Type{Vec{N,T}}, ptrs::Vec{N,Ptr{T}}, mask::Vec{N,Bool}, ::Val{Aligned} = Val(false)) where {N,T,Aligned} @assert isa(Aligned, Bool) ptyp = llvmtype(Int) typ = llvmtype(T) vptyp = "<$N x $typ*>" vtyp = "<$N x $typ>" btyp = llvmtype(Bool) vbtyp = "<$N x $btyp>" decls = [] instrs = [] if Aligned align = N * sizeof(T) else align = sizeof(T) # This is overly optimistic end if VERSION < v"v0.7.0-DEV" push!(instrs, "%ptrs = bitcast <$N x $typ*> %0 to $vptyp") else push!(instrs, "%ptrs = inttoptr <$N x $ptyp> %0 to $vptyp") end push!(instrs, "%mask = trunc $vbtyp %1 to <$N x i1>") push!(decls, "declare $vtyp @llvm.masked.gather.$(suffix(N,T))($vptyp, i32, " * "<$N x i1>, $vtyp)") push!(instrs, "%res = call $vtyp @llvm.masked.gather.$(suffix(N,T))($vptyp %ptrs, " * "i32 $align, <$N x i1> %mask, $vtyp $(llvmconst(N, T, 0)))") push!(instrs, "ret $vtyp %res") quote $(Expr(:meta, :inline)) Vec{N,T}(Base.llvmcall($((join(decls, "\n"), join(instrs, "\n"))), NTuple{N,VE{T}}, Tuple{NTuple{N,VE{Ptr{T}}}, NTuple{N,VE{Bool}}}, ptrs.elts, mask.elts)) end end @inline function vgather( ::Type{Vec{N,T}}, ptrs::Vec{N,Ptr{T}}, mask::Vec{N,Bool}, ::Type{Val{Aligned}}) where {N,T,Aligned} vgather(Vec{N,T}, ptrs, mask, Val(Aligned)) end @inline vgathera(::Type{Vec{N,T}}, ptrs::Vec{N,Ptr{T}}, mask::Union{Vec{N,Bool}, Nothing}) where {N,T} = vgather(Vec{N,T}, ptrs, mask, Val{true}) @inline vgather(arr::FastContiguousArray{T,1}, idx::Vec{N,<:Integer}, mask::Union{Vec{N,Bool}, Nothing} = nothing, ::Val{Aligned} = Val(false)) where {N,T,Aligned} = vgather(Vec{N,T}, pointer(arr) + sizeof(T) * (idx - 1), mask, Val{Aligned}) @inline vgather(arr::FastContiguousArray{T,1}, idx::Vec{N,<:Integer}, mask::Union{Vec{N,Bool}, Nothing}, ::Type{Val{Aligned}}) where {N,T,Aligned} = vgather(arr, idx, mask, Val(Aligned)) @inline vgathera(arr::FastContiguousArray{T,1}, idx::Vec{N,<:Integer}, mask::Union{Vec{N,Bool}, Nothing} = nothing) where {N,T} = vgather(arr, idx, mask, Val{true}) export vscatter, vscattera @inline vscatter( v::Vec{N,T}, ptrs::Vec{N,Ptr{T}}, mask::Nothing, ::Val{Aligned} = Val(false)) where {N,T,Aligned} = vscatter(v, ptrs, Vec(ntuple(_ -> true, N)), Val(Aligned)) @inline vscatter( v::Vec{N,T}, ptrs::Vec{N,Ptr{T}}, mask::Nothing, ::Type{Val{Aligned}}) where {N,T,Aligned} = vscatter(v, ptrs, mask, Val(Aligned)) @generated function vscatter( v::Vec{N,T}, ptrs::Vec{N,Ptr{T}}, mask::Vec{N,Bool}, ::Val{Aligned} = Val(false)) where {N,T,Aligned} @assert isa(Aligned, Bool) ptyp = llvmtype(Int) typ = llvmtype(T) vptyp = "<$N x $typ*>" vtyp = "<$N x $typ>" btyp = llvmtype(Bool) vbtyp = "<$N x $btyp>" decls = [] instrs = [] if Aligned align = N * sizeof(T) else align = sizeof(T) # This is overly optimistic end if VERSION < v"v0.7.0-DEV" push!(instrs, "%ptrs = bitcast <$N x $typ*> %1 to $vptyp") else push!(instrs, "%ptrs = inttoptr <$N x $ptyp> %1 to $vptyp") end push!(instrs, "%mask = trunc $vbtyp %2 to <$N x i1>") push!(decls, "declare void @llvm.masked.scatter.$(suffix(N,T))" * "($vtyp, $vptyp, i32, <$N x i1>)") push!(instrs, "call void @llvm.masked.scatter.$(suffix(N,T))" * "($vtyp %0, $vptyp %ptrs, i32 $align, <$N x i1> %mask)") push!(instrs, "ret void") quote $(Expr(:meta, :inline)) Base.llvmcall($((join(decls, "\n"), join(instrs, "\n"))), Cvoid, Tuple{NTuple{N,VE{T}}, NTuple{N,VE{Ptr{T}}}, NTuple{N,VE{Bool}}}, v.elts, ptrs.elts, mask.elts) end end @inline function vscatter( v::Vec{N,T}, ptrs::Vec{N,Ptr{T}}, mask::Vec{N,Bool}, ::Type{Val{Aligned}}) where {N,T,Aligned} vscatter(v, ptrs, mask, Val(Aligned)) end @inline vscattera(v::Vec{N,T}, ptrs::Vec{N,Ptr{T}}, mask::Union{Vec{N,Bool}, Nothing}) where {N,T} = vscatter(v, ptrs, mask, Val{true}) @inline vscatter(v::Vec{N,T}, arr::FastContiguousArray{T,1}, idx::Vec{N,<:Integer}, mask::Union{Vec{N,Bool}, Nothing} = nothing, ::Val{Aligned} = Val(false)) where {N,T,Aligned} = vscatter(v, pointer(arr) + sizeof(T) * (idx - 1), mask, Val(Aligned)) @inline vscatter(v::Vec{N,T}, arr::FastContiguousArray{T,1}, idx::Vec{N,<:Integer}, mask::Union{Vec{N,Bool}, Nothing}, ::Type{Val{Aligned}}) where {N,T,Aligned} = vscatter(v, arr, idx, mask, Val(Aligned)) @inline vscattera(v::Vec{N,T}, arr::FastContiguousArray{T,1}, idx::Vec{N,<:Integer}, mask::Union{Vec{N,Bool}, Nothing} = nothing) where {N,T} = vscatter(v, arr, idx, mask, Val{true}) # Vector shuffles function shufflevector_instrs(N, T, I, two_operands) typ = llvmtype(T) vtyp2 = vtyp1 = "<$N x $typ>" M = length(I) vtyp3 = "<$M x i32>" vtypr = "<$M x $typ>" mask = "<" * join(map(x->string("i32 ", x), I), ", ") * ">" instrs = [] v2 = two_operands ? "%1" : "undef" push!(instrs, "%res = shufflevector $vtyp1 %0, $vtyp2 $v2, $vtyp3 $mask") push!(instrs, "ret $vtypr %res") return M, [], instrs end export shufflevector @generated function shufflevector(v1::Vec{N,T}, v2::Vec{N,T}, ::Val{I}) where {N,T,I} M, decls, instrs = shufflevector_instrs(N, T, I, true) quote $(Expr(:meta, :inline)) Vec{$M,T}(Base.llvmcall($((join(decls, "\n"), join(instrs, "\n"))), NTuple{$M,VE{T}}, Tuple{NTuple{N,VE{T}}, NTuple{N,VE{T}}}, v1.elts, v2.elts)) end end @inline function shufflevector(v1::Vec{N,T}, v2::Vec{N,T}, ::Type{Val{I}}) where {N,T,I} shufflevector(v1, v2, Val(I)) end @generated function shufflevector(v1::Vec{N,T}, ::Val{I}) where {N,T,I} M, decls, instrs = shufflevector_instrs(N, T, I, false) quote $(Expr(:meta, :inline)) Vec{$M,T}(Base.llvmcall($((join(decls, "\n"), join(instrs, "\n"))), NTuple{$M,VE{T}}, Tuple{NTuple{N,VE{T}}}, v1.elts)) end end @inline function shufflevector(v1::Vec{N,T}, ::Type{Val{I}}) where {N,T,I} shufflevector(v1, Val(I)) end export VecRange """ VecRange{N}(i::Int) Analogous to `UnitRange` but for loading SIMD vector of width `N` at index `i`. # Examples ```jldoctest julia> xs = ones(4); julia> xs[VecRange{4}(1)] # calls `vload(Vec{4,Float64}, xs, 1)` <4 x Float64>[1.0, 1.0, 1.0, 1.0] ``` """ struct VecRange{N} i::Int end @inline Base.length(idx::VecRange{N}) where {N} = N @inline Base.first(idx::VecRange) = idx.i @inline Base.last(idx::VecRange) = idx.i + length(idx) - 1 @inline Base.:+(idx::VecRange{N}, j::Integer) where N = VecRange{N}(idx.i + j) @inline Base.:+(j::Integer, idx::VecRange{N}) where N = VecRange{N}(idx.i + j) @inline Base.:-(idx::VecRange{N}, j::Integer) where N = VecRange{N}(idx.i - j) Base.checkindex(::Type{Bool}, inds::AbstractUnitRange, idx::VecRange) = (first(inds) <= first(idx)) && (last(idx) <= last(inds)) Base.checkindex(::Type{Bool}, inds::AbstractUnitRange, idx::Vec) = all(first(inds) <= idx) && all(idx <= last(inds)) @inline _checkarity(::AbstractArray{<:Any,N}, ::Vararg{<:Any,N}) where {N} = nothing @inline _checkarity(::T, ::Any) where {T <: AbstractArray} = if IndexStyle(T) isa IndexLinear nothing else throw(ArgumentError(""" Array type $T does not support indexing with a single index. Exactly $(ndims(T)) (non-mask) indices have to be specified. """)) end _checkarity(::AbstractArray{<:Any,N}, ::Vararg{<:Any,M}) where {N,M} = throw(ArgumentError(""" $M indices are given to $N-dimensional array. Exactly $N (non-mask) indices have to be specified when using SIMD. """)) # Combined with `_preprocessindices`, helper function `_extractmask` # extracts `mask` in the tail position. As slicing tuple is not # type-stable, we use reverse-of-tail-of-reverse hack to extract # `mask` at the end of `args`. @inline _extractmask(mask::Vec{N,Bool}, R::Vararg{Integer}) where N = (reverse(R), mask) @inline _extractmask(R::Vararg{Integer}) = (reverse(R), nothing) @inline _extractmask(mask::Vec{N,Bool}) where {N} = ((), mask) @inline _extractmask() = ((), nothing) @noinline _extractmask(rargs...) = throw(ArgumentError(""" Using SIMD indexing `array[idx, i2, ..., iN, mask]` for `N`-dimensional array requires `i2` to `iN` to be all integers and `mask` to be optionally a SIMD vector `Vec` of `Bool`s. Given `(i2, ..., iN, mask)` is $(summary(reverse(rargs))) """)) _maskedidx(idx, ::Nothing, ::Any) = idx _maskedidx(idx::Vec, mask::Vec, fst) = vifelse(mask, idx, fst) _maskedidx(idx::VecRange, mask::Vec, fst) = _maskedidx(Vec(ntuple(i -> i - 1 + idx.i, length(mask))), mask, fst) Base.@propagate_inbounds function _preprocessindices(arr, idx, args) I, mask = _extractmask(reverse(args)...) _checkarity(arr, idx, I...) @boundscheck checkbounds(arr, _maskedidx(idx, mask, first(axes(arr, 1))), I...) return I, mask end """ _pointer(arr, i, I) Pointer to the element `arr[i, I...]`. """ Base.@propagate_inbounds _pointer(arr::Array, i, I) = pointer(arr, LinearIndices(arr)[i, I...]) Base.@propagate_inbounds _pointer(arr::Base.FastContiguousSubArray, i, I) = pointer(arr, (i, I...)) Base.@propagate_inbounds _pointer(arr::SubArray, i, I) = pointer(Base.unsafe_view(arr, 1, I...), i) Base.@propagate_inbounds function Base.getindex( arr::ContiguousArray{T}, idx::VecRange{N}, args::Vararg{Union{Integer,Vec{N,Bool}}}) where {N,T} I, mask = _preprocessindices(arr, idx, args) return vload(Vec{N,T}, _pointer(arr, idx.i, I), mask) end Base.@propagate_inbounds function Base.setindex!( arr::ContiguousArray{T}, v::Vec{N,T}, idx::VecRange{N}, args::Vararg{Union{Integer,Vec{N,Bool}}}) where {N,T} I, mask = _preprocessindices(arr, idx, args) vstore(v, _pointer(arr, idx.i, I), mask) return arr end Base.@propagate_inbounds function Base.getindex( arr::ContiguousArray{T}, idx::Vec{N,<:Integer}, args::Vararg{Union{Integer,Vec{N,Bool}}}) where {N,T} I, mask = _preprocessindices(arr, idx, args) ptrs = _pointer(arr, 1, I) - sizeof(T) + sizeof(T) * idx return vgather(Vec{N,T}, ptrs, mask) end Base.@propagate_inbounds function Base.setindex!( arr::ContiguousArray{T}, v::Vec{N,T}, idx::Vec{N,<:Integer}, args::Vararg{Union{Integer,Vec{N,Bool}}}) where {N,T} I, mask = _preprocessindices(arr, idx, args) ptrs = _pointer(arr, 1, I) - sizeof(T) + sizeof(T) * idx vscatter(v, ptrs, mask) return arr end end
namespace hidden constant le : ℕ → ℕ → Prop axiom le.refl {x : ℕ} : le x x axiom le.step {x y : ℕ} : le x y → le x (y + 1) attribute [simp] le.refl le.step attribute [refl] le.refl -- Examples: -- Implicit arguments: example : le 3 3 := le.refl example : le 2 3 := le.step le.refl -- example : le 2 3 := le.step (⊢ le 2 2) example : le 1 3 := le.step (le.step le.refl) -- example : le 1 3 := le.step (⊢ le 1 2) -- example : le 1 3 := le.step (le.step (⊢ le 1 1)) -- Explicit arguments: example : le 3 3 := @le.refl 3 example : le 2 3 := @le.step _ _ le.refl example : le 1 3 := @le.step _ _ (@le.step _ _ le.refl) lemma zero_less_nat (n : ℕ) : le 0 n := begin induction n with n ih, case nat.zero { exact le.refl }, -- ⊢ le 0 0 case nat.succ { -- ih : le 0 n exact le.step ih, -- ⊢ le 0 n.succ }, end #print zero_less_nat -- λ (n : ℕ), -- nat.rec le.refl (λ (n : ℕ) (ih : le 0 n), ih.step) n lemma zero_less_nat₂ (n : ℕ) : le 0 n := begin apply nat.rec, -- and we have 2 goals: -- first: ⊢ le 0 0 { exact le.refl }, -- second: ⊢ ∀ (n : ℕ), le 0 n → le 0 n.succ { exact @le.step 0 }, end #print nat.rec #print nat.rec_on lemma zero_less_nat₃ (n : ℕ) : le 0 n := nat.rec le.refl (@le.step 0) n -- nat.rec le.refl (assume m, sorry) n -- nat.rec (⊢ le 0 0) (⊢ ∀ (n : ℕ), le 0 n → le 0 n.succ) n #print zero_less_nat₃ -- λ (n : ℕ), nat.rec le.refl le.step n lemma zero_less_nat₄ (n : ℕ) : le 0 n := nat.rec le.refl (λ (m : ℕ), @le.step 0 m) n #print zero_less_nat₄ -- λ (n : ℕ), nat.rec le.refl (λ (m : ℕ), le.step) n -- try #1 example (n : ℕ) : n ≠ 0 → le 1 n := begin assume ne_zero : n ≠ 0, -- we in state A rw (ne.def n 0) at ne_zero, by_cases n = 0, apply absurd h ne_zero, -- the same state as state A sorry, end lemma le.branch {a b : ℕ} : le a b → a = b ∨ le a.succ b := begin assume le_a_b : le a b, by_cases (a = b), { left, exact h }, { right, sorry, }, end lemma ex1 (n : ℕ) : n ≠ 0 → le 1 n := begin intro ne_zero, have h : le 0 n := zero_less_nat n, type_check @le.branch 0 n, -- le 0 n → 0 = n ∨ le (0 + 1) n type_check le.branch h, -- 0 = n ∨ le (0 + 1) n have h_cases := le.branch h, cases h_cases with n_eq_zero n_ge_one, { type_check ((ne.def n) 0).mpr, -- we have two options: .mp and .mpr type_check ((ne.def n) 0).mp, -- but we need only .mp have ne_zero' := ((ne.def n) 0).mp ne_zero, exact absurd n_eq_zero.symm ne_zero', }, { exact n_ge_one, }, end #print ex1 -- λ (n : ℕ) (ne_zero : n ≠ 0), -- (zero_less_nat n).branch.dcases_on (λ (n_eq_zero : 0 = n), absurd n_eq_zero.symm ((ne.def n 0).mp ne_zero)) -- (λ (n_ge_one : le 1 n), n_ge_one) lemma ex1₂ (n : ℕ) : n ≠ 0 → le 1 n := begin intro ne_zero, have h_cases := le.branch (zero_less_nat n), have ne_zero' := ((ne.def n) 0).mp ne_zero, type_check h_cases, -- 0 = n ∨ le 1 n apply ( or.elim h_cases (λ (zero_eq_n : 0 = n), absurd zero_eq_n.symm ne_zero') -- λ zero_eq_n, ... also works (λ (x : le 1 n), x) -- ~ identity function (λ x, x) = id ), end lemma ex1₃ (n : ℕ) : n ≠ 0 → le 1 n := begin intro ne_zero, have h_cases : 0 = n ∨ le 1 n := le.branch (zero_less_nat n), have ne_zero' := ((ne.def n) 0).mp ne_zero, apply ( or.elim h_cases (λ h₁, absurd _ ne_zero') (λ h₂, _) -- (λ h₂, h₂) ~ id ), exact h₁.symm, -- first goal exact h₂, -- second goal end lemma ex1₄ (n : ℕ) : n ≠ 0 → le 1 n := begin intro ne_zero, have h_cases : 0 = n ∨ le 1 n := le.branch (zero_less_nat n), have ne_zero' := ((ne.def n) 0).mp ne_zero, apply or.elim, apply h_cases, -- apply (λ h₁, absurd (eq.symm h₁) _), -- exact ne_zero', apply (λ h₁, absurd _ ne_zero), -- ne_zero ~ ne_zero' exact h₁.symm, exact id, end #print ex1₂ #print ex1₃ #print ex1₄ -- short proof -- λ (n : ℕ) (ne_zero : n ≠ 0), -- (zero_less_nat n).branch.elim -- (λ (h₁ : 0 = n), absurd h₁.symm ne_zero) -- id -- Structured proof #1 lemma ex1₅ (n : ℕ) : n ≠ 0 → le 1 n := assume ne_zero : n ≠ 0, have h_cases : 0 = n ∨ le 1 n, from le.branch (zero_less_nat n), h_cases.elim (λ h₁, absurd h₁.symm ne_zero) id -- Structured proof #2 lemma ex1₆ (n : ℕ) : n ≠ 0 → le 1 n := λ ne_zero : n ≠ 0, (zero_less_nat n).branch.elim (λ h₁ : 0 = n, absurd h₁.symm ne_zero) (λ h₂ : le 1 n, h₂) example (n : ℕ) : n ≠ 0 ∧ n ≠ 1 → le 2 n := sorry example (n : ℕ) : ¬(le n 1) → le 2 n := sorry example (n m : ℕ) : ¬(le n m) → le m.succ n := sorry example (n : ℕ) : le n (n+1) := le.step le.refl example (n m : ℕ) : le n (n+m) := sorry example (n : ℕ) : le n (2*n) := begin induction n with n ih, case nat.zero { exact le.refl }, have h₂ := le.step (le.step ih), change le n (2 * n.succ) at h₂, have h₃ : n = 2 * n ∨ le n.succ (2 * n) := le.branch ih, cases h₃ with n_eq_two_n le_nsucc_two_n, { -- 1st way: -- have helper : ∀ m : ℕ, m ≠ 0 → n = m * n → n = 0, from sorry, -- rw (helper 2) _ n_eq_two_n, -- -- rw nat.mul, -- exact le.step le.refl, -- have two_ne_zero : 2 ≠ 0, from dec_trivial, -- exact two_ne_zero, -- 2nd way: -- have helper : ∀ m : ℕ, le 1 m → n = m * n → n = 0, from sorry, -- have n_zero: n = 0 := (helper 2) (le.step le.refl) n_eq_2n, -- rw n_zero, -- exact le.step le.refl, -- 3rd way: rw ←nat.add_one, change le _ (2 * n + 2), rw ←n_eq_two_n, exact le.step le.refl, }, { exact le.step (le.step le_nsucc_two_n), }, end example (n : ℕ) : le (2*n) (3*n) := sorry example (n a b : ℕ) : le a b → le (a*n) (b*n) := sorry example (a b n m : ℕ) : le a b → le m n → le (a*m) (b*n) := sorry lemma not_le_succ_le_succ {m n : ℕ}: le (n + 1) m → le (m + 1) n → false := begin assume h₁ h₂, have helper : ∀ a b, ¬(le a b) ↔ le a.succ b, from sorry, have p1: Prop, sorry, have p2: Prop, sorry, have k : p1 = p2, sorry, type_check (eq.mp k), have h₃ : ¬le n m := (helper n m).mpr h₁, end -- which lemma are simplest for proving without other? lemma not_le_succ_le_succ' {m n : ℕ}: ¬(le (n + 1) m ∧ le (m + 1) n) := λ ⟨h₁, h₂⟩, (@not_le_succ_le_succ m n) h₁ h₂ example (n m : ℕ) : n = m ↔ le n m ∧ le m n := begin apply iff.intro, { assume n_eq_m : n = m, rw n_eq_m, rw and_self, }, { assume h_and : le n m ∧ le m n, -- by_cases (n = m), ~ by_contradiction -- { exact h }, -- exfalso, by_contradiction n_neq_m, have h₁ := le.branch h_and.1, have h₂ := le.branch h_and.2, clear h_and, cases h₁; cases h₂; try { contradiction }, exact absurd h₂.symm n_neq_m, change le (n+1) _ at h₁, change le (m+1) _ at h₂, -- apply (@not_le_succ_le_succ m n) h₁ h₂, exact (@not_le_succ_le_succ' m n) ⟨h₁, h₂⟩, }, end end hidden
theory Extra_no_setVarAny imports HandDryer_no_setVarAny Requirements_no_setVarAny VCTheoryLemmas_no_setVarAny begin theorem extra2: "VC2 extraInv s0 hands_value" apply(simp only: VC2_def extraInv_def dryer_def waiting_def drying_def) by auto theorem extra3: "VC3 extraInv s0 hands_value" apply(simp only: VC3_def extraInv_def dryer_def waiting_def drying_def) by auto theorem extra5: "VC5 extraInv s0 hands_value" apply(simp only: VC5_def extraInv_def dryer_def waiting_def drying_def) apply(auto) proof - assume 1: " toEnvP s0" " \<forall>s1. toEnvP s1 \<and> substate s1 s0 \<longrightarrow> getPstate s1 Ctrl = Suc (Suc (Suc (Suc 0))) \<or> getPstate s1 Ctrl = Suc (Suc (Suc (Suc (Suc 0))))" "env (setVarBool s0 hands ON) ON " " getPstate s0 Ctrl = Suc (Suc (Suc (Suc (Suc 0)))) " " hands_value " " 0 < ltimeEnv s0 Ctrl " " ltimeEnv s0 Ctrl \<le> 10 " "\<forall>s1. toEnvP s1 \<and> substate s1 s0 \<and> Suc (toEnvNum s1 s0) = ltimeEnv s0 Ctrl \<longrightarrow> getVarBool s1 (Suc 0) \<and> getVarBool s1 (Suc (Suc 0)) " " \<forall>s1. toEnvP s1 \<and> substate s1 s0 \<and> Suc (toEnvNum s1 s0) < ltimeEnv s0 Ctrl \<longrightarrow> \<not> getVarBool s1 (Suc 0) \<and> getVarBool s1 (Suc (Suc 0))" with toEnvNum_id have "Suc (toEnvNum s0 s0) = ltimeEnv s0 Ctrl \<or> Suc (toEnvNum s0 s0) <ltimeEnv s0 Ctrl" by auto with 1 substate_refl show "getVarBool s0 (Suc (Suc 0))" by auto qed theorem extra6: "VC6 extraInv s0 hands_value" apply(simp only: VC6_def extraInv_def dryer_def waiting_def drying_def) by auto theorem extra7: "VC7 extraInv s0 hands_value" apply(simp only: VC7_def extraInv_def dryer_def waiting_def drying_def) apply(auto) proof - assume 1: "toEnvP s0 " "\<forall>s1. toEnvP s1 \<and> substate s1 s0 \<longrightarrow> getPstate s1 Ctrl = Suc (Suc (Suc (Suc 0))) \<or> getPstate s1 Ctrl = Suc (Suc (Suc (Suc (Suc 0)))) " " env (setVarBool s0 hands OFF) OFF " "getPstate s0 Ctrl = Suc (Suc (Suc (Suc (Suc 0)))) " "\<not> hands_value " " ltimeEnv s0 Ctrl \<noteq> 10 " "0 < ltimeEnv s0 Ctrl " " ltimeEnv s0 Ctrl \<le> 10 " " \<forall>s1. toEnvP s1 \<and> substate s1 s0 \<and> Suc (toEnvNum s1 s0) = ltimeEnv s0 Ctrl \<longrightarrow> getVarBool s1 (Suc 0) \<and> getVarBool s1 (Suc (Suc 0)) " "\<forall>s1. toEnvP s1 \<and> substate s1 s0 \<and> Suc (toEnvNum s1 s0) < ltimeEnv s0 Ctrl \<longrightarrow> \<not> getVarBool s1 (Suc 0) \<and> getVarBool s1 (Suc (Suc 0))" with toEnvNum_id have "Suc (toEnvNum s0 s0) = ltimeEnv s0 Ctrl \<or> Suc (toEnvNum s0 s0) <ltimeEnv s0 Ctrl" by auto with 1 substate_refl show "getVarBool s0 (Suc (Suc 0))" by auto qed end
/- Copyright (c) 2020 Kenny Lau. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kenny Lau, Ken Lee, Chris Hughes -/ import tactic.ring import algebra.ring.basic import group_theory.group_action.units /-! # Coprime elements of a ring ## Main definitions * `is_coprime x y`: that `x` and `y` are coprime, defined to be the existence of `a` and `b` such that `a * x + b * y = 1`. Note that elements with no common divisors are not necessarily coprime, e.g., the multivariate polynomials `x₁` and `x₂` are not coprime. See also `ring_theory.coprime.lemmas` for further development of coprime elements. -/ open_locale classical universes u v section comm_semiring variables {R : Type u} [comm_semiring R] (x y z : R) /-- The proposition that `x` and `y` are coprime, defined to be the existence of `a` and `b` such that `a * x + b * y = 1`. Note that elements with no common divisors are not necessarily coprime, e.g., the multivariate polynomials `x₁` and `x₂` are not coprime. -/ @[simp] def is_coprime : Prop := ∃ a b, a * x + b * y = 1 variables {x y z} theorem is_coprime.symm (H : is_coprime x y) : is_coprime y x := let ⟨a, b, H⟩ := H in ⟨b, a, by rw [add_comm, H]⟩ theorem is_coprime_comm : is_coprime x y ↔ is_coprime y x := ⟨is_coprime.symm, is_coprime.symm⟩ theorem is_coprime_self : is_coprime x x ↔ is_unit x := ⟨λ ⟨a, b, h⟩, is_unit_of_mul_eq_one x (a + b) $ by rwa [mul_comm, add_mul], λ h, let ⟨b, hb⟩ := is_unit_iff_exists_inv'.1 h in ⟨b, 0, by rwa [zero_mul, add_zero]⟩⟩ theorem is_coprime_zero_left : is_coprime 0 x ↔ is_unit x := ⟨λ ⟨a, b, H⟩, is_unit_of_mul_eq_one x b $ by rwa [mul_zero, zero_add, mul_comm] at H, λ H, let ⟨b, hb⟩ := is_unit_iff_exists_inv'.1 H in ⟨1, b, by rwa [one_mul, zero_add]⟩⟩ theorem is_coprime_zero_right : is_coprime x 0 ↔ is_unit x := is_coprime_comm.trans is_coprime_zero_left lemma not_coprime_zero_zero [nontrivial R] : ¬ is_coprime (0 : R) 0 := mt is_coprime_zero_right.mp not_is_unit_zero /-- If a 2-vector `p` satisfies `is_coprime (p 0) (p 1)`, then `p ≠ 0`. -/ lemma is_coprime.ne_zero [nontrivial R] {p : fin 2 → R} (h : is_coprime (p 0) (p 1)) : p ≠ 0 := by { rintro rfl, exact not_coprime_zero_zero h } theorem is_coprime_one_left : is_coprime 1 x := ⟨1, 0, by rw [one_mul, zero_mul, add_zero]⟩ theorem is_coprime_one_right : is_coprime x 1 := ⟨0, 1, by rw [one_mul, zero_mul, zero_add]⟩ theorem is_coprime.dvd_of_dvd_mul_right (H1 : is_coprime x z) (H2 : x ∣ y * z) : x ∣ y := let ⟨a, b, H⟩ := H1 in by { rw [← mul_one y, ← H, mul_add, ← mul_assoc, mul_left_comm], exact dvd_add (dvd_mul_left _ _) (H2.mul_left _) } theorem is_coprime.dvd_of_dvd_mul_left (H1 : is_coprime x y) (H2 : x ∣ y * z) : x ∣ z := let ⟨a, b, H⟩ := H1 in by { rw [← one_mul z, ← H, add_mul, mul_right_comm, mul_assoc b], exact dvd_add (dvd_mul_left _ _) (H2.mul_left _) } theorem is_coprime.mul_left (H1 : is_coprime x z) (H2 : is_coprime y z) : is_coprime (x * y) z := let ⟨a, b, h1⟩ := H1, ⟨c, d, h2⟩ := H2 in ⟨a * c, a * x * d + b * c * y + b * d * z, calc a * c * (x * y) + (a * x * d + b * c * y + b * d * z) * z = (a * x + b * z) * (c * y + d * z) : by ring ... = 1 : by rw [h1, h2, mul_one]⟩ theorem is_coprime.mul_right (H1 : is_coprime x y) (H2 : is_coprime x z) : is_coprime x (y * z) := by { rw is_coprime_comm at H1 H2 ⊢, exact H1.mul_left H2 } theorem is_coprime.mul_dvd (H : is_coprime x y) (H1 : x ∣ z) (H2 : y ∣ z) : x * y ∣ z := begin obtain ⟨a, b, h⟩ := H, rw [← mul_one z, ← h, mul_add], apply dvd_add, { rw [mul_comm z, mul_assoc], exact (mul_dvd_mul_left _ H2).mul_left _ }, { rw [mul_comm b, ← mul_assoc], exact (mul_dvd_mul_right H1 _).mul_right _ } end theorem is_coprime.of_mul_left_left (H : is_coprime (x * y) z) : is_coprime x z := let ⟨a, b, h⟩ := H in ⟨a * y, b, by rwa [mul_right_comm, mul_assoc]⟩ theorem is_coprime.of_mul_left_right (H : is_coprime (x * y) z) : is_coprime y z := by { rw mul_comm at H, exact H.of_mul_left_left } theorem is_coprime.of_mul_right_left (H : is_coprime x (y * z)) : is_coprime x y := by { rw is_coprime_comm at H ⊢, exact H.of_mul_left_left } theorem is_coprime.of_mul_right_right (H : is_coprime x (y * z)) : is_coprime x z := by { rw mul_comm at H, exact H.of_mul_right_left } theorem is_coprime.mul_left_iff : is_coprime (x * y) z ↔ is_coprime x z ∧ is_coprime y z := ⟨λ H, ⟨H.of_mul_left_left, H.of_mul_left_right⟩, λ ⟨H1, H2⟩, H1.mul_left H2⟩ theorem is_coprime.mul_right_iff : is_coprime x (y * z) ↔ is_coprime x y ∧ is_coprime x z := by rw [is_coprime_comm, is_coprime.mul_left_iff, is_coprime_comm, @is_coprime_comm _ _ z] theorem is_coprime.of_coprime_of_dvd_left (h : is_coprime y z) (hdvd : x ∣ y) : is_coprime x z := begin obtain ⟨d, rfl⟩ := hdvd, exact is_coprime.of_mul_left_left h end theorem is_coprime.of_coprime_of_dvd_right (h : is_coprime z y) (hdvd : x ∣ y) : is_coprime z x := (h.symm.of_coprime_of_dvd_left hdvd).symm theorem is_coprime.is_unit_of_dvd (H : is_coprime x y) (d : x ∣ y) : is_unit x := let ⟨k, hk⟩ := d in is_coprime_self.1 $ is_coprime.of_mul_right_left $ show is_coprime x (x * k), from hk ▸ H theorem is_coprime.is_unit_of_dvd' {a b x : R} (h : is_coprime a b) (ha : x ∣ a) (hb : x ∣ b) : is_unit x := (h.of_coprime_of_dvd_left ha).is_unit_of_dvd hb theorem is_coprime.map (H : is_coprime x y) {S : Type v} [comm_semiring S] (f : R →+* S) : is_coprime (f x) (f y) := let ⟨a, b, h⟩ := H in ⟨f a, f b, by rw [← f.map_mul, ← f.map_mul, ← f.map_add, h, f.map_one]⟩ variables {x y z} lemma is_coprime.of_add_mul_left_left (h : is_coprime (x + y * z) y) : is_coprime x y := let ⟨a, b, H⟩ := h in ⟨a, a * z + b, by simpa only [add_mul, mul_add, add_assoc, add_comm, add_left_comm, mul_assoc, mul_comm, mul_left_comm] using H⟩ lemma is_coprime.of_add_mul_right_left (h : is_coprime (x + z * y) y) : is_coprime x y := by { rw mul_comm at h, exact h.of_add_mul_left_left } lemma is_coprime.of_add_mul_left_right (h : is_coprime x (y + x * z)) : is_coprime x y := by { rw is_coprime_comm at h ⊢, exact h.of_add_mul_left_left } lemma is_coprime.of_add_mul_right_right (h : is_coprime x (y + z * x)) : is_coprime x y := by { rw mul_comm at h, exact h.of_add_mul_left_right } lemma is_coprime.of_mul_add_left_left (h : is_coprime (y * z + x) y) : is_coprime x y := by { rw add_comm at h, exact h.of_add_mul_left_left } lemma is_coprime.of_mul_add_right_left (h : is_coprime (z * y + x) y) : is_coprime x y := by { rw add_comm at h, exact h.of_add_mul_right_left } lemma is_coprime.of_mul_add_left_right (h : is_coprime x (x * z + y)) : is_coprime x y := by { rw add_comm at h, exact h.of_add_mul_left_right } lemma is_coprime.of_mul_add_right_right (h : is_coprime x (z * x + y)) : is_coprime x y := by { rw add_comm at h, exact h.of_add_mul_right_right } end comm_semiring section scalar_tower variables {R G : Type*} [comm_semiring R] [group G] [mul_action G R] [smul_comm_class G R R] [is_scalar_tower G R R] (x : G) (y z : R) lemma is_coprime_group_smul_left : is_coprime (x • y) z ↔ is_coprime y z := ⟨λ ⟨a, b, h⟩, ⟨x • a, b, by rwa [smul_mul_assoc, ←mul_smul_comm]⟩, λ ⟨a, b, h⟩, ⟨x⁻¹ • a, b, by rwa [smul_mul_smul, inv_mul_self, one_smul]⟩⟩ lemma is_coprime_group_smul_right : is_coprime y (x • z) ↔ is_coprime y z := is_coprime_comm.trans $ (is_coprime_group_smul_left x z y).trans is_coprime_comm lemma is_coprime_group_smul : is_coprime (x • y) (x • z) ↔ is_coprime y z := (is_coprime_group_smul_left x y (x • z)).trans (is_coprime_group_smul_right x y z) end scalar_tower section comm_semiring_unit variables {R : Type*} [comm_semiring R] {x : R} (hu : is_unit x) (y z : R) lemma is_coprime_mul_unit_left_left : is_coprime (x * y) z ↔ is_coprime y z := let ⟨u, hu⟩ := hu in hu ▸ is_coprime_group_smul_left u y z lemma is_coprime_mul_unit_left_right : is_coprime y (x * z) ↔ is_coprime y z := let ⟨u, hu⟩ := hu in hu ▸ is_coprime_group_smul_right u y z lemma is_coprime_mul_unit_left : is_coprime (x * y) (x * z) ↔ is_coprime y z := (is_coprime_mul_unit_left_left hu y (x * z)).trans (is_coprime_mul_unit_left_right hu y z) lemma is_coprime_mul_unit_right_left : is_coprime (y * x) z ↔ is_coprime y z := mul_comm x y ▸ is_coprime_mul_unit_left_left hu y z lemma is_coprime_mul_unit_right_right : is_coprime y (z * x) ↔ is_coprime y z := mul_comm x z ▸ is_coprime_mul_unit_left_right hu y z lemma is_coprime_mul_unit_right : is_coprime (y * x) (z * x) ↔ is_coprime y z := (is_coprime_mul_unit_right_left hu y (z * x)).trans (is_coprime_mul_unit_right_right hu y z) end comm_semiring_unit namespace is_coprime section comm_ring variables {R : Type u} [comm_ring R] lemma add_mul_left_left {x y : R} (h : is_coprime x y) (z : R) : is_coprime (x + y * z) y := @of_add_mul_left_left R _ _ _ (-z) $ by simpa only [mul_neg, add_neg_cancel_right] using h lemma add_mul_right_left {x y : R} (h : is_coprime x y) (z : R) : is_coprime (x + z * y) y := by { rw mul_comm, exact h.add_mul_left_left z } lemma add_mul_left_right {x y : R} (h : is_coprime x y) (z : R) : is_coprime x (y + x * z) := by { rw is_coprime_comm, exact h.symm.add_mul_left_left z } lemma add_mul_right_right {x y : R} (h : is_coprime x y) (z : R) : is_coprime x (y + z * x) := by { rw is_coprime_comm, exact h.symm.add_mul_right_left z } lemma mul_add_left_left {x y : R} (h : is_coprime x y) (z : R) : is_coprime (y * z + x) y := by { rw add_comm, exact h.add_mul_left_left z } lemma mul_add_right_left {x y : R} (h : is_coprime x y) (z : R) : is_coprime (z * y + x) y := by { rw add_comm, exact h.add_mul_right_left z } lemma mul_add_left_right {x y : R} (h : is_coprime x y) (z : R) : is_coprime x (x * z + y) := by { rw add_comm, exact h.add_mul_left_right z } lemma mul_add_right_right {x y : R} (h : is_coprime x y) (z : R) : is_coprime x (z * x + y) := by { rw add_comm, exact h.add_mul_right_right z } lemma add_mul_left_left_iff {x y z : R} : is_coprime (x + y * z) y ↔ is_coprime x y := ⟨of_add_mul_left_left, λ h, h.add_mul_left_left z⟩ lemma add_mul_right_left_iff {x y z : R} : is_coprime (x + z * y) y ↔ is_coprime x y := ⟨of_add_mul_right_left, λ h, h.add_mul_right_left z⟩ lemma add_mul_left_right_iff {x y z : R} : is_coprime x (y + x * z) ↔ is_coprime x y := ⟨of_add_mul_left_right, λ h, h.add_mul_left_right z⟩ lemma add_mul_right_right_iff {x y z : R} : is_coprime x (y + z * x) ↔ is_coprime x y := ⟨of_add_mul_right_right, λ h, h.add_mul_right_right z⟩ lemma mul_add_left_left_iff {x y z : R} : is_coprime (y * z + x) y ↔ is_coprime x y := ⟨of_mul_add_left_left, λ h, h.mul_add_left_left z⟩ lemma mul_add_right_left_iff {x y z : R} : is_coprime (z * y + x) y ↔ is_coprime x y := ⟨of_mul_add_right_left, λ h, h.mul_add_right_left z⟩ lemma mul_add_left_right_iff {x y z : R} : is_coprime x (x * z + y) ↔ is_coprime x y := ⟨of_mul_add_left_right, λ h, h.mul_add_left_right z⟩ lemma mul_add_right_right_iff {x y z : R} : is_coprime x (z * x + y) ↔ is_coprime x y := ⟨of_mul_add_right_right, λ h, h.mul_add_right_right z⟩ lemma neg_left {x y : R} (h : is_coprime x y) : is_coprime (-x) y := begin obtain ⟨a, b, h⟩ := h, use [-a, b], rwa neg_mul_neg, end lemma neg_left_iff (x y : R) : is_coprime (-x) y ↔ is_coprime x y := ⟨λ h, neg_neg x ▸ h.neg_left, neg_left⟩ lemma neg_right {x y : R} (h : is_coprime x y) : is_coprime x (-y) := h.symm.neg_left.symm lemma neg_right_iff (x y : R) : is_coprime x (-y) ↔ is_coprime x y := ⟨λ h, neg_neg y ▸ h.neg_right, neg_right⟩ lemma neg_neg {x y : R} (h : is_coprime x y) : is_coprime (-x) (-y) := h.neg_left.neg_right lemma neg_neg_iff (x y : R) : is_coprime (-x) (-y) ↔ is_coprime x y := (neg_left_iff _ _).trans (neg_right_iff _ _) end comm_ring lemma sq_add_sq_ne_zero {R : Type*} [linear_ordered_comm_ring R] {a b : R} (h : is_coprime a b) : a ^ 2 + b ^ 2 ≠ 0 := begin intros h', obtain ⟨ha, hb⟩ := (add_eq_zero_iff' (sq_nonneg a) (sq_nonneg b)).mp h', obtain rfl := pow_eq_zero ha, obtain rfl := pow_eq_zero hb, exact not_coprime_zero_zero h end end is_coprime
open import Prelude module Implicits.Semantics where open import Implicits.Syntax open import Implicits.WellTyped open import Implicits.Semantics.Type public open import Implicits.Semantics.Context public open import Implicits.Semantics.RewriteContext public open import Implicits.Semantics.Term public open import Implicits.Semantics.Preservation public open import SystemF.Everything as F using () module Semantics (_⊢ᵣ_ : ∀ {ν} → ICtx ν → Type ν → Set) (⟦_,_⟧r : ∀ {ν n} {K : Ktx ν n} {a} → (proj₂ K) ⊢ᵣ a → K# K → ∃ λ t → ⟦ proj₁ K ⟧ctx→ F.⊢ t ∈ ⟦ a ⟧tp→) where open TypingRules _⊢ᵣ_ open TermSemantics _⊢ᵣ_ ⟦_,_⟧r public open Preservation _⊢ᵣ_ ⟦_,_⟧r public
lemma countably_compactI: assumes "\<And>C. \<forall>t\<in>C. open t \<Longrightarrow> s \<subseteq> \<Union>C \<Longrightarrow> countable C \<Longrightarrow> (\<exists>C'\<subseteq>C. finite C' \<and> s \<subseteq> \<Union>C')" shows "countably_compact s"
-- Cubo de una diferencia -- ====================== import tactic lemma expand_mult (a b : ℤ) : (b-a)^3 = b^3-3*a*b^2+3*a^2*b-a^3 := by ring_exp
step <- function() { success <- runif(1) > p ## Requires that the "robot" is a variable named "level" level <<- level - 1 + (2 * success) success }
[STATEMENT] lemma abs_non_negative_sum: assumes " abs x + abs y = 0" shows "abs x= 0" and "abs y = 0" [PROOF STATE] proof (prove) goal (1 subgoal): 1. Preliminaries.abs x = 0 &&& Preliminaries.abs y = 0 [PROOF STEP] using abs_def diff_0 abs_non_negative neg_0_le_iff_le add_nonneg_eq_0_iff assms [PROOF STATE] proof (prove) using this: Preliminaries.abs ?x \<equiv> if 0 \<le> ?x then ?x else 0 - ?x (0::?'a) - ?a = - ?a 0 \<le> Preliminaries.abs ?x ((0::?'a) \<le> - ?a) = (?a \<le> (0::?'a)) \<lbrakk>(0::?'a) \<le> ?x; (0::?'a) \<le> ?y\<rbrakk> \<Longrightarrow> (?x + ?y = (0::?'a)) = (?x = (0::?'a) \<and> ?y = (0::?'a)) Preliminaries.abs x + Preliminaries.abs y = 0 goal (1 subgoal): 1. Preliminaries.abs x = 0 &&& Preliminaries.abs y = 0 [PROOF STEP] apply (metis) [PROOF STATE] proof (prove) goal (1 subgoal): 1. Preliminaries.abs y = 0 [PROOF STEP] by (metis abs_non_negative add_nonneg_eq_0_iff assms)
/- Copyright (c) 2020 Markus Himmel. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Markus Himmel ! This file was ported from Lean 3 source module algebra.homology.exact ! leanprover-community/mathlib commit 3feb151caefe53df080ca6ca67a0c6685cfd1b82 ! Please do not edit these lines, except to modify the commit id ! if you have ported upstream changes. -/ import Mathbin.Algebra.Homology.ImageToKernel /-! # Exact sequences In a category with zero morphisms, images, and equalizers we say that `f : A ⟶ B` and `g : B ⟶ C` are exact if `f ≫ g = 0` and the natural map `image f ⟶ kernel g` is an epimorphism. In any preadditive category this is equivalent to the homology at `B` vanishing. However in general it is weaker than other reasonable definitions of exactness, particularly that 1. the inclusion map `image.ι f` is a kernel of `g` or 2. `image f ⟶ kernel g` is an isomorphism or 3. `image_subobject f = kernel_subobject f`. However when the category is abelian, these all become equivalent; these results are found in `category_theory/abelian/exact.lean`. # Main results * Suppose that cokernels exist and that `f` and `g` are exact. If `s` is any kernel fork over `g` and `t` is any cokernel cofork over `f`, then `fork.ι s ≫ cofork.π t = 0`. * Precomposing the first morphism with an epimorphism retains exactness. Postcomposing the second morphism with a monomorphism retains exactness. * If `f` and `g` are exact and `i` is an isomorphism, then `f ≫ i.hom` and `i.inv ≫ g` are also exact. # Future work * Short exact sequences, split exact sequences, the splitting lemma (maybe only for abelian categories?) * Two adjacent maps in a chain complex are exact iff the homology vanishes -/ universe v v₂ u u₂ open CategoryTheory open CategoryTheory.Limits variable {V : Type u} [Category.{v} V] variable [HasImages V] namespace CategoryTheory -- One nice feature of this definition is that we have -- `epi f → exact g h → exact (f ≫ g) h` and `exact f g → mono h → exact f (g ≫ h)`, -- which do not necessarily hold in a non-abelian category with the usual definition of `exact`. /-- Two morphisms `f : A ⟶ B`, `g : B ⟶ C` are called exact if `w : f ≫ g = 0` and the natural map `image_to_kernel f g w : image_subobject f ⟶ kernel_subobject g` is an epimorphism. In any preadditive category, this is equivalent to `w : f ≫ g = 0` and `homology f g w ≅ 0`. In an abelian category, this is equivalent to `image_to_kernel f g w` being an isomorphism, and hence equivalent to the usual definition, `image_subobject f = kernel_subobject g`. -/ structure Exact [HasZeroMorphisms V] [HasKernels V] {A B C : V} (f : A ⟶ B) (g : B ⟶ C) : Prop where w : f ≫ g = 0 Epi : Epi (imageToKernel f g w) #align category_theory.exact CategoryTheory.Exact -- This works as an instance even though `exact` itself is not a class, as long as the goal is -- literally of the form `epi (image_to_kernel f g h.w)` (where `h : exact f g`). If the proof of -- `f ≫ g = 0` looks different, we are out of luck and have to add the instance by hand. attribute [instance] exact.epi attribute [reassoc.1] exact.w section variable [HasZeroObject V] [Preadditive V] [HasKernels V] [HasCokernels V] open ZeroObject /-- In any preadditive category, composable morphisms `f g` are exact iff they compose to zero and the homology vanishes. -/ theorem Preadditive.exact_iff_homology_zero {A B C : V} (f : A ⟶ B) (g : B ⟶ C) : Exact f g ↔ ∃ w : f ≫ g = 0, Nonempty (homology f g w ≅ 0) := ⟨fun h => ⟨h.w, ⟨cokernel.ofEpi _⟩⟩, fun h => by obtain ⟨w, ⟨i⟩⟩ := h exact ⟨w, preadditive.epi_of_cokernel_zero ((cancel_mono i.hom).mp (by ext))⟩⟩ #align category_theory.preadditive.exact_iff_homology_zero CategoryTheory.Preadditive.exact_iff_homology_zero theorem Preadditive.exact_of_iso_of_exact {A₁ B₁ C₁ A₂ B₂ C₂ : V} (f₁ : A₁ ⟶ B₁) (g₁ : B₁ ⟶ C₁) (f₂ : A₂ ⟶ B₂) (g₂ : B₂ ⟶ C₂) (α : Arrow.mk f₁ ≅ Arrow.mk f₂) (β : Arrow.mk g₁ ≅ Arrow.mk g₂) (p : α.Hom.right = β.Hom.left) (h : Exact f₁ g₁) : Exact f₂ g₂ := by rw [preadditive.exact_iff_homology_zero] at h⊢ rcases h with ⟨w₁, ⟨i⟩⟩ suffices w₂ : f₂ ≫ g₂ = 0; exact ⟨w₂, ⟨(homology.mapIso w₁ w₂ α β p).symm.trans i⟩⟩ rw [← cancel_epi α.hom.left, ← cancel_mono β.inv.right, comp_zero, zero_comp, ← w₁] simp only [← arrow.mk_hom f₁, ← arrow.left_hom_inv_right α.hom, ← arrow.mk_hom g₁, ← arrow.left_hom_inv_right β.hom, p] simp only [arrow.mk_hom, is_iso.inv_hom_id_assoc, category.assoc, ← arrow.inv_right, is_iso.iso.inv_hom] #align category_theory.preadditive.exact_of_iso_of_exact CategoryTheory.Preadditive.exact_of_iso_of_exact /-- A reformulation of `preadditive.exact_of_iso_of_exact` that does not involve the arrow category. -/ theorem Preadditive.exact_of_iso_of_exact' {A₁ B₁ C₁ A₂ B₂ C₂ : V} (f₁ : A₁ ⟶ B₁) (g₁ : B₁ ⟶ C₁) (f₂ : A₂ ⟶ B₂) (g₂ : B₂ ⟶ C₂) (α : A₁ ≅ A₂) (β : B₁ ≅ B₂) (γ : C₁ ≅ C₂) (hsq₁ : α.Hom ≫ f₂ = f₁ ≫ β.Hom) (hsq₂ : β.Hom ≫ g₂ = g₁ ≫ γ.Hom) (h : Exact f₁ g₁) : Exact f₂ g₂ := Preadditive.exact_of_iso_of_exact f₁ g₁ f₂ g₂ (Arrow.isoMk α β hsq₁) (Arrow.isoMk β γ hsq₂) rfl h #align category_theory.preadditive.exact_of_iso_of_exact' CategoryTheory.Preadditive.exact_of_iso_of_exact' theorem Preadditive.exact_iff_exact_of_iso {A₁ B₁ C₁ A₂ B₂ C₂ : V} (f₁ : A₁ ⟶ B₁) (g₁ : B₁ ⟶ C₁) (f₂ : A₂ ⟶ B₂) (g₂ : B₂ ⟶ C₂) (α : Arrow.mk f₁ ≅ Arrow.mk f₂) (β : Arrow.mk g₁ ≅ Arrow.mk g₂) (p : α.Hom.right = β.Hom.left) : Exact f₁ g₁ ↔ Exact f₂ g₂ := ⟨Preadditive.exact_of_iso_of_exact _ _ _ _ _ _ p, Preadditive.exact_of_iso_of_exact _ _ _ _ α.symm β.symm (by rw [← cancel_mono α.hom.right] simp only [iso.symm_hom, ← comma.comp_right, α.inv_hom_id] simp only [p, ← comma.comp_left, arrow.id_right, arrow.id_left, iso.inv_hom_id] rfl)⟩ #align category_theory.preadditive.exact_iff_exact_of_iso CategoryTheory.Preadditive.exact_iff_exact_of_iso end section variable [HasZeroMorphisms V] [HasKernels V] theorem comp_eq_zero_of_image_eq_kernel {A B C : V} (f : A ⟶ B) (g : B ⟶ C) (p : imageSubobject f = kernelSubobject g) : f ≫ g = 0 := by rw [← image_subobject_arrow_comp f, category.assoc] convert comp_zero rw [p] simp #align category_theory.comp_eq_zero_of_image_eq_kernel CategoryTheory.comp_eq_zero_of_image_eq_kernel theorem imageToKernel_isIso_of_image_eq_kernel {A B C : V} (f : A ⟶ B) (g : B ⟶ C) (p : imageSubobject f = kernelSubobject g) : IsIso (imageToKernel f g (comp_eq_zero_of_image_eq_kernel f g p)) := by refine' ⟨⟨subobject.of_le _ _ p.ge, _⟩⟩ dsimp [imageToKernel] simp only [subobject.of_le_comp_of_le, subobject.of_le_refl] simp #align category_theory.image_to_kernel_is_iso_of_image_eq_kernel CategoryTheory.imageToKernel_isIso_of_image_eq_kernel -- We'll prove the converse later, when `V` is abelian. theorem exact_of_image_eq_kernel {A B C : V} (f : A ⟶ B) (g : B ⟶ C) (p : imageSubobject f = kernelSubobject g) : Exact f g := { w := comp_eq_zero_of_image_eq_kernel f g p Epi := by haveI := image_to_kernel_is_iso_of_image_eq_kernel f g p infer_instance } #align category_theory.exact_of_image_eq_kernel CategoryTheory.exact_of_image_eq_kernel end variable {A B C D : V} {f : A ⟶ B} {g : B ⟶ C} {h : C ⟶ D} attribute [local instance] epi_comp section variable [HasZeroMorphisms V] [HasEqualizers V] theorem exact_comp_hom_inv_comp (i : B ≅ D) (h : Exact f g) : Exact (f ≫ i.Hom) (i.inv ≫ g) := by refine' ⟨by simp [h.w], _⟩ rw [imageToKernel_comp_hom_inv_comp] haveI := h.epi infer_instance #align category_theory.exact_comp_hom_inv_comp CategoryTheory.exact_comp_hom_inv_comp theorem exact_comp_inv_hom_comp (i : D ≅ B) (h : Exact f g) : Exact (f ≫ i.inv) (i.Hom ≫ g) := exact_comp_hom_inv_comp i.symm h #align category_theory.exact_comp_inv_hom_comp CategoryTheory.exact_comp_inv_hom_comp theorem exact_comp_hom_inv_comp_iff (i : B ≅ D) : Exact (f ≫ i.Hom) (i.inv ≫ g) ↔ Exact f g := ⟨fun h => by simpa using exact_comp_inv_hom_comp i h, exact_comp_hom_inv_comp i⟩ #align category_theory.exact_comp_hom_inv_comp_iff CategoryTheory.exact_comp_hom_inv_comp_iff theorem exact_epi_comp (hgh : Exact g h) [Epi f] : Exact (f ≫ g) h := by refine' ⟨by simp [hgh.w], _⟩ rw [imageToKernel_comp_left] infer_instance #align category_theory.exact_epi_comp CategoryTheory.exact_epi_comp @[simp] theorem exact_iso_comp [IsIso f] : Exact (f ≫ g) h ↔ Exact g h := ⟨fun w => by rw [← is_iso.inv_hom_id_assoc f g] exact exact_epi_comp w, fun w => exact_epi_comp w⟩ #align category_theory.exact_iso_comp CategoryTheory.exact_iso_comp theorem exact_comp_mono (hfg : Exact f g) [Mono h] : Exact f (g ≫ h) := by refine' ⟨by simp [hfg.w_assoc], _⟩ rw [imageToKernel_comp_right f g h hfg.w] infer_instance #align category_theory.exact_comp_mono CategoryTheory.exact_comp_mono /-- The dual of this lemma is only true when `V` is abelian, see `abelian.exact_epi_comp_iff`. -/ theorem exact_comp_mono_iff [Mono h] : Exact f (g ≫ h) ↔ Exact f g := by refine' ⟨fun hfg => ⟨zero_of_comp_mono h (by rw [category.assoc, hfg.1]), _⟩, fun h => exact_comp_mono h⟩ rw [← (iso.eq_comp_inv _).1 (imageToKernel_comp_mono _ _ h hfg.1)] haveI := hfg.2; infer_instance #align category_theory.exact_comp_mono_iff CategoryTheory.exact_comp_mono_iff @[simp] theorem exact_comp_iso [IsIso h] : Exact f (g ≫ h) ↔ Exact f g := exact_comp_mono_iff #align category_theory.exact_comp_iso CategoryTheory.exact_comp_iso theorem exact_kernelSubobject_arrow : Exact (kernelSubobject f).arrow f := by refine' ⟨by simp, _⟩ apply @is_iso.epi_of_iso _ _ _ _ _ _ exact ⟨⟨factor_thru_image_subobject _, by ext simp, by ext simp⟩⟩ #align category_theory.exact_kernel_subobject_arrow CategoryTheory.exact_kernelSubobject_arrow theorem exact_kernel_ι : Exact (kernel.ι f) f := by rw [← kernel_subobject_arrow', exact_iso_comp] exact exact_kernel_subobject_arrow #align category_theory.exact_kernel_ι CategoryTheory.exact_kernel_ι instance (h : Exact f g) : Epi (factorThruKernelSubobject g f h.w) := by rw [← factorThruImageSubobject_comp_imageToKernel] apply epi_comp instance (h : Exact f g) : Epi (kernel.lift g f h.w) := by rw [← factor_thru_kernel_subobject_comp_kernel_subobject_iso] apply epi_comp variable (A) theorem kernelSubobject_arrow_eq_zero_of_exact_zero_left (h : Exact (0 : A ⟶ B) g) : (kernelSubobject g).arrow = 0 := by rw [← cancel_epi (imageToKernel (0 : A ⟶ B) g h.w), ← cancel_epi (factor_thru_image_subobject (0 : A ⟶ B))] simp #align category_theory.kernel_subobject_arrow_eq_zero_of_exact_zero_left CategoryTheory.kernelSubobject_arrow_eq_zero_of_exact_zero_left theorem kernel_ι_eq_zero_of_exact_zero_left (h : Exact (0 : A ⟶ B) g) : kernel.ι g = 0 := by rw [← kernel_subobject_arrow'] simp [kernel_subobject_arrow_eq_zero_of_exact_zero_left A h] #align category_theory.kernel_ι_eq_zero_of_exact_zero_left CategoryTheory.kernel_ι_eq_zero_of_exact_zero_left theorem exact_zero_left_of_mono [HasZeroObject V] [Mono g] : Exact (0 : A ⟶ B) g := ⟨by simp, imageToKernel_epi_of_zero_of_mono _⟩ #align category_theory.exact_zero_left_of_mono CategoryTheory.exact_zero_left_of_mono end section HasCokernels variable [HasZeroMorphisms V] [HasEqualizers V] [HasCokernels V] (f g) @[simp, reassoc.1] theorem kernel_comp_cokernel (h : Exact f g) : kernel.ι g ≫ cokernel.π f = 0 := by rw [← kernel_subobject_arrow', category.assoc] convert comp_zero apply zero_of_epi_comp (imageToKernel f g h.w) _ rw [imageToKernel_arrow_assoc, ← image_subobject_arrow, category.assoc, ← iso.eq_inv_comp] ext simp #align category_theory.kernel_comp_cokernel CategoryTheory.kernel_comp_cokernel theorem comp_eq_zero_of_exact (h : Exact f g) {X Y : V} {ι : X ⟶ B} (hι : ι ≫ g = 0) {π : B ⟶ Y} (hπ : f ≫ π = 0) : ι ≫ π = 0 := by rw [← kernel.lift_ι _ _ hι, ← cokernel.π_desc _ _ hπ, category.assoc, kernel_comp_cokernel_assoc _ _ h, zero_comp, comp_zero] #align category_theory.comp_eq_zero_of_exact CategoryTheory.comp_eq_zero_of_exact @[simp, reassoc.1] theorem fork_ι_comp_cofork_π (h : Exact f g) (s : KernelFork g) (t : CokernelCofork f) : Fork.ι s ≫ Cofork.π t = 0 := comp_eq_zero_of_exact f g h (KernelFork.condition s) (CokernelCofork.condition t) #align category_theory.fork_ι_comp_cofork_π CategoryTheory.fork_ι_comp_cofork_π end HasCokernels section variable [HasZeroObject V] open ZeroObject section variable [HasZeroMorphisms V] [HasKernels V] theorem exact_of_zero {A C : V} (f : A ⟶ 0) (g : 0 ⟶ C) : Exact f g := by obtain rfl : f = 0 := by ext obtain rfl : g = 0 := by ext fconstructor · simp · exact imageToKernel_epi_of_zero_of_mono 0 #align category_theory.exact_of_zero CategoryTheory.exact_of_zero theorem exact_zero_mono {B C : V} (f : B ⟶ C) [Mono f] : Exact (0 : 0 ⟶ B) f := ⟨by simp, inferInstance⟩ #align category_theory.exact_zero_mono CategoryTheory.exact_zero_mono theorem exact_epi_zero {A B : V} (f : A ⟶ B) [Epi f] : Exact f (0 : B ⟶ 0) := ⟨by simp, inferInstance⟩ #align category_theory.exact_epi_zero CategoryTheory.exact_epi_zero end section variable [Preadditive V] theorem mono_iff_exact_zero_left [HasKernels V] {B C : V} (f : B ⟶ C) : Mono f ↔ Exact (0 : 0 ⟶ B) f := ⟨fun h => exact_zero_mono _, fun h => Preadditive.mono_of_kernel_iso_zero ((kernelSubobjectIso f).symm ≪≫ isoZeroOfEpiZero (by simpa using h.epi))⟩ #align category_theory.mono_iff_exact_zero_left CategoryTheory.mono_iff_exact_zero_left theorem epi_iff_exact_zero_right [HasEqualizers V] {A B : V} (f : A ⟶ B) : Epi f ↔ Exact f (0 : B ⟶ 0) := ⟨fun h => exact_epi_zero _, fun h => by have e₁ := h.epi rw [imageToKernel_zero_right] at e₁ have e₂ : epi (((image_subobject f).arrow ≫ inv (kernel_subobject 0).arrow) ≫ (kernel_subobject 0).arrow) := @epi_comp _ _ _ _ _ _ e₁ _ _ rw [category.assoc, is_iso.inv_hom_id, category.comp_id] at e₂ rw [← image_subobject_arrow] at e₂ skip haveI : epi (image.ι f) := epi_of_epi (image_subobject_iso f).Hom (image.ι f) apply epi_of_epi_image⟩ #align category_theory.epi_iff_exact_zero_right CategoryTheory.epi_iff_exact_zero_right end end namespace Functor variable [HasZeroMorphisms V] [HasKernels V] {W : Type u₂} [Category.{v₂} W] variable [HasImages W] [HasZeroMorphisms W] [HasKernels W] /-- A functor reflects exact sequences if any composable pair of morphisms that is mapped to an exact pair is itself exact. -/ class ReflectsExactSequences (F : V ⥤ W) where reflects : ∀ {A B C : V} (f : A ⟶ B) (g : B ⟶ C), Exact (F.map f) (F.map g) → Exact f g #align category_theory.functor.reflects_exact_sequences CategoryTheory.Functor.ReflectsExactSequences theorem exact_of_exact_map (F : V ⥤ W) [ReflectsExactSequences F] {A B C : V} {f : A ⟶ B} {g : B ⟶ C} (hfg : Exact (F.map f) (F.map g)) : Exact f g := ReflectsExactSequences.reflects f g hfg #align category_theory.functor.exact_of_exact_map CategoryTheory.Functor.exact_of_exact_map end Functor end CategoryTheory
lemmas scaleR_sum_left = real_vector.scale_sum_left
Require bedrock2.BasicC64Semantics bedrock2.NotationsCustomEntry. Import BinInt String List.ListNotations. Local Open Scope string_scope. Local Open Scope Z_scope. Local Open Scope list_scope. Require Import coqutil.Macros.ident_to_string. Section chacha20. Import bedrock2.Syntax Syntax.Coercions NotationsCustomEntry. Local Notation "x <<<= n" := (cmd.set (ident_to_string! x) (expr.op bopname.slu (ident_to_string! x) n)) (in custom bedrock_cmd at level 0, x ident, n bigint). Local Notation "x ^= e" := (cmd.set (ident_to_string! x) (expr.op bopname.xor (ident_to_string! x) e)) (in custom bedrock_cmd at level 0, x ident, e custom bedrock_expr). Local Notation "x += e" := (cmd.set (ident_to_string! x) (expr.op bopname.add (ident_to_string! x) e)) (in custom bedrock_cmd at level 0, x ident, e custom bedrock_expr). Definition chacha20_quarter : func := ("chacha20_quarter", (["a";"b";"c";"d"], ["a";"b";"c";"d"], bedrock_func_body:( a += b; d ^= a; d <<<= 16; c += d; b ^= c; b <<<= 12; a += b; d ^= a; d <<<= 8; c += d; b ^= c; b <<<= 7 ))). Local Notation "'xorout' o x" := ( let addr := bedrock_expr:(out+coq:(expr.literal(4*o))) in bedrock_cmd:(store4($addr, load4($addr)^$(expr.var (ident_to_string! x))))) (in custom bedrock_cmd at level 0, o bigint, x ident). Definition chacha20_block : func := (* NOTE: I (REDACTED) don't understand why xorout needs these *) let x0 := "x0" in let x1 := "x1" in let x2 := "x2" in let x3 := "x3" in let x4 := "x4" in let x5 := "x5" in let x6 := "x6" in let x7 := "x7" in let x8 := "x8" in let x9 := "x9" in let x10 := "x10" in let x11 := "x11" in let x12 := "x12" in let x13 := "x13" in let x14 := "x14" in let x15 := "x15" in ("chacha20_block", (["out"; "key"; "nonce"; "countervalue"], [], bedrock_func_body:( x0 = $0x61707865; x1 = $0x3320646e; x2 = $0x79622d32; x3 = $0x6b206574; x4 = load4(key); x5 = load4(key+$4); x6 = load4(key+$8); x7 = load4(key+$12); x8 = load4(key+$16); x9 = load4(key+$20); x10 = load4(key+$24); x11 = load4(key+$28); x12 = countervalue; x13 = load4(nonce); x14 = load4(nonce+$4); x15 = load4(nonce+$8); i = $0; while (i < $10) { i += $1; (x0, x4, x8, x12) = chacha20_quarter( x0, x4, x8, x12); (x1, x5, x9, x13) = chacha20_quarter( x1, x5, x9, x13); (x2, x6, x10, x14) = chacha20_quarter( x2, x6, x10, x14); (x3, x7, x11, x15) = chacha20_quarter( x3, x7, x11, x15); (x0, x5, x10, x15) = chacha20_quarter( x0, x5, x10, x15); (x1, x6, x11, x12) = chacha20_quarter( x1, x6, x11, x12); (x2, x7, x8, x13) = chacha20_quarter( x2, x7, x8, x13); (x3, x4, x9, x1) = chacha20_quarter( x3, x4, x9, x14) }; x0 += $0x61707865; x1 += $0x3320646e; x2 += $0x79622d32; x3 += $0x6b206574; x4 += load4(key); x5 += load4(key+$4); x6 += load4(key+$8); x7 += load4(key+$12); x8 += load4(key+$16); x9 += load4(key+$20); x10 += load4(key+$24); x11 += load4(key+$28); x12 += countervalue; x13 += load4(nonce); x14 += load4(nonce+$4); x15 += load4(nonce+$8); xorout 0 x0; xorout 1 x1; xorout 2 x2; xorout 3 x3; xorout 4 x4; xorout 5 x5; xorout 6 x6; xorout 7 x7; xorout 8 x8; xorout 9 x9; xorout 10 x10; xorout 11 x11; xorout 12 x12; xorout 13 x13; xorout 14 x14; xorout 15 x15 ))). End chacha20. (* Require bedrock2.ToCString. Example chacha20_block_c_string := Eval vm_compute in ToCString.c_module [chacha20_quarter; chacha20_block]. Print chacha20_block_c_string. *)
lemma poly_of_list_impl [code abstract]: "coeffs (poly_of_list as) = strip_while (HOL.eq 0) as"
module Classifiers.QLearning.Prelude ( module Prelude , module Control.Monad.Primitive , module Statistics.Distribution , module Statistics.Distribution.Normal , module System.Random.MWC , module Data.Sequence , module GHC.Float , module Control.Exception , module Data.List , module Data.Vector ) where import Control.Monad.Primitive import Control.Exception (assert) import Data.List (intercalate) import Data.Vector (Vector, (!), (//)) import Data.Sequence (Seq, (<|), (|>)) import Statistics.Distribution import Statistics.Distribution.Normal import System.Random.MWC import GHC.Float import Prelude
lemma norm_cos_sin [simp]: "norm (Complex (cos t) (sin t)) = 1"
export eigmax function eigmax(A::Symmetric{T,<:BandedMatrix{T}}) where T <: Real maximum(KrylovKit.eigsolve(A, issymmetric=true)[1]) end
lemma measure_eq_sum_singleton: "finite S \<Longrightarrow> (\<And>x. x \<in> S \<Longrightarrow> {x} \<in> sets M) \<Longrightarrow> (\<And>x. x \<in> S \<Longrightarrow> emeasure M {x} \<noteq> \<infinity>) \<Longrightarrow> measure M S = (\<Sum>x\<in>S. measure M {x})"
lemma compact_uniformly_equicontinuous: assumes "compact S" and cont: "\<And>x e. \<lbrakk>x \<in> S; 0 < e\<rbrakk> \<Longrightarrow> \<exists>d. 0 < d \<and> (\<forall>f \<in> \<F>. \<forall>x' \<in> S. dist x' x < d \<longrightarrow> dist (f x') (f x) < e)" and "0 < e" obtains d where "0 < d" "\<And>f x x'. \<lbrakk>f \<in> \<F>; x \<in> S; x' \<in> S; dist x' x < d\<rbrakk> \<Longrightarrow> dist (f x') (f x) < e"
Require Import Syntax TypeAlgo. Theorem algo_values_all_effect: forall C v T D G max_rho max_X max_rho' max_X', welltyped_algo G max_rho max_X (e_Thread (t_Value v)) T (EffectIntro D D) C max_rho' max_X' -> forall D', welltyped_algo G max_rho max_X (e_Thread (t_Value v)) T (EffectIntro D' D') C max_rho' max_X'. Proof.
total twoPlusTwoNotFive: 2 + 2 = 5 -> Void twoPlusTwoNotFive Refl impossible
Formal statement is: lemma open_empty [continuous_intros, intro, simp]: "open {}" Informal statement is: The empty set is open.
lemma complex_cnj_minus [simp]: "cnj (- x) = - cnj x"
/- Copyright (c) 2021 Sébastien Gouëzel. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Sébastien Gouëzel -/ import topology.instances.real import order.filter.archimedean /-! # Convergence of subadditive sequences A subadditive sequence `u : ℕ → ℝ` is a sequence satisfying `u (m + n) ≤ u m + u n` for all `m, n`. We define this notion as `subadditive u`, and prove in `subadditive.tendsto_lim` that, if `u n / n` is bounded below, then it converges to a limit (that we denote by `subadditive.lim` for convenience). This result is known as Fekete's lemma in the literature. -/ noncomputable theory open set filter open_locale topological_space /-- A real-valued sequence is subadditive if it satisfies the inequality `u (m + n) ≤ u m + u n` for all `m, n`. -/ def subadditive (u : ℕ → ℝ) : Prop := ∀ m n, u (m + n) ≤ u m + u n namespace subadditive variables {u : ℕ → ℝ} (h : subadditive u) include h /-- The limit of a bounded-below subadditive sequence. The fact that the sequence indeed tends to this limit is given in `subadditive.tendsto_lim` -/ @[irreducible, nolint unused_arguments] protected def lim := Inf ((λ (n : ℕ), u n / n) '' (Ici 1)) lemma lim_le_div (hbdd : bdd_below (range (λ n, u n / n))) {n : ℕ} (hn : n ≠ 0) : h.lim ≤ u n / n := begin rw subadditive.lim, apply cInf_le _ _, { rcases hbdd with ⟨c, hc⟩, exact ⟨c, λ x hx, hc (image_subset_range _ _ hx)⟩ }, { apply mem_image_of_mem, exact zero_lt_iff.2 hn } end lemma apply_mul_add_le (k n r) : u (k * n + r) ≤ k * u n + u r := begin induction k with k IH, { simp only [nat.cast_zero, zero_mul, zero_add] }, calc u ((k+1) * n + r) = u (n + (k * n + r)) : by { congr' 1, ring } ... ≤ u n + u (k * n + r) : h _ _ ... ≤ u n + (k * u n + u r) : add_le_add_left IH _ ... = (k+1 : ℕ) * u n + u r : by simp; ring end lemma eventually_div_lt_of_div_lt {L : ℝ} {n : ℕ} (hn : n ≠ 0) (hL : u n / n < L) : ∀ᶠ p in at_top, u p / p < L := begin have I : ∀ (i : ℕ), 0 < i → (i : ℝ) ≠ 0, { assume i hi, simp only [hi.ne', ne.def, nat.cast_eq_zero, not_false_iff] }, obtain ⟨w, nw, wL⟩ : ∃ w, u n / n < w ∧ w < L := exists_between hL, obtain ⟨x, hx⟩ : ∃ x, ∀ i < n, u i - i * w ≤ x, { obtain ⟨x, hx⟩ : bdd_above (↑(finset.image (λ i, u i - i * w) (finset.range n))) := finset.bdd_above _, refine ⟨x, λ i hi, _⟩, simp only [upper_bounds, mem_image, and_imp, forall_exists_index, mem_set_of_eq, forall_apply_eq_imp_iff₂, finset.mem_range, finset.mem_coe, finset.coe_image] at hx, exact hx _ hi }, have A : ∀ (p : ℕ), u p ≤ p * w + x, { assume p, let s := p / n, let r := p % n, have hp : p = s * n + r, by rw [mul_comm, nat.div_add_mod], calc u p = u (s * n + r) : by rw hp ... ≤ s * u n + u r : h.apply_mul_add_le _ _ _ ... = s * n * (u n / n) + u r : by { field_simp [I _ hn.bot_lt], ring } ... ≤ s * n * w + u r : add_le_add_right (mul_le_mul_of_nonneg_left nw.le (mul_nonneg (nat.cast_nonneg _) (nat.cast_nonneg _))) _ ... = (s * n + r) * w + (u r - r * w) : by ring ... = p * w + (u r - r * w) : by { rw hp, simp only [nat.cast_add, nat.cast_mul] } ... ≤ p * w + x : add_le_add_left (hx _ (nat.mod_lt _ hn.bot_lt)) _ }, have B : ∀ᶠ p in at_top, u p / p ≤ w + x / p, { refine eventually_at_top.2 ⟨1, λ p hp, _⟩, simp only [I p hp, ne.def, not_false_iff] with field_simps, refine div_le_div_of_le_of_nonneg _ (nat.cast_nonneg _), rw mul_comm, exact A _ }, have C : ∀ᶠ (p : ℕ) in at_top, w + x / p < L, { have : tendsto (λ (p : ℕ), w + x / p) at_top (𝓝 (w + 0)) := tendsto_const_nhds.add (tendsto_const_nhds.div_at_top tendsto_coe_nat_at_top_at_top), rw add_zero at this, exact (tendsto_order.1 this).2 _ wL }, filter_upwards [B, C] with _ hp h'p using hp.trans_lt h'p, end /-- Fekete's lemma: a subadditive sequence which is bounded below converges. -/ theorem tendsto_lim (hbdd : bdd_below (range (λ n, u n / n))) : tendsto (λ n, u n / n) at_top (𝓝 h.lim) := begin refine tendsto_order.2 ⟨λ l hl, _, λ L hL, _⟩, { refine eventually_at_top.2 ⟨1, λ n hn, hl.trans_le (h.lim_le_div hbdd ((zero_lt_one.trans_le hn).ne'))⟩ }, { obtain ⟨n, npos, hn⟩ : ∃ (n : ℕ), 0 < n ∧ u n / n < L, { rw subadditive.lim at hL, rcases exists_lt_of_cInf_lt (by simp) hL with ⟨x, hx, xL⟩, rcases (mem_image _ _ _).1 hx with ⟨n, hn, rfl⟩, exact ⟨n, zero_lt_one.trans_le hn, xL⟩ }, exact h.eventually_div_lt_of_div_lt npos.ne' hn } end end subadditive
[STATEMENT] lemma inj_on_Pos [simp]: "inj_on Pos A" and inj_on_Neg [simp]: "inj_on Neg A" [PROOF STATE] proof (prove) goal (1 subgoal): 1. inj_on Pos A &&& inj_on Neg A [PROOF STEP] by(auto simp add: inj_on_def)