Datasets:
AI4M
/

text
stringlengths
0
3.34M
The commander version incorporates a 5 @-@ door hard top cab allowing for the quick and convenient entrance and exit of the driver and all passengers or troops . A large rear compartment enables the storage of both cargo and communications equipment .
-- ------------------------------------------------------------- [ Helpers.idr ] -- Module : Test.Helpers -- Description : Helper functions for writing tests. -- --------------------------------------------------------------------- [ EOH ] module Test.Helpers import public Test.Generic import Data.Vect %access export ||| Like Test.Assertions.assertEqual but with `given` and `expected` swapped. assertEqual' : (Eq a, Show a) => (title : String) -> (expected, given : a) -> IO Bool assertEqual' title expected given = genericTest (Just title) given expected (==) namespace SingleResult summaryLine : Bool -> String summaryLine True = succLine summaryLine False = errLine namespace ManyResults summaryLine : Foldable t => t Bool -> String summaryLine = summaryLine . all id printSummary : Vect n Bool -> IO () printSummary = putStrLn . unlines . ([summaryLine, summary] <*>) . pure testChapter : (label : String) -> (tests : List (IO Bool)) -> IO (Vect (length tests) Bool) testChapter label tests = do putStrLn $ "Testing Chapter " ++ label putStrLn infoLine results <- sequence (fromList tests) printSummary results pure results -- --------------------------------------------------------------------- [ EOF ]
[STATEMENT] lemma tl_prefixes_idx: assumes "i < length p" shows "tl (prefixes p) ! i = take (Suc i) p" [PROOF STATE] proof (prove) goal (1 subgoal): 1. tl (prefixes p) ! i = take (Suc i) p [PROOF STEP] using assms [PROOF STATE] proof (prove) using this: i < length p goal (1 subgoal): 1. tl (prefixes p) ! i = take (Suc i) p [PROOF STEP] by(induct p,auto)
Whether your school term started this June or will still be in August, it’s high time to pick out campus-ready pieces. To level up your standard sleeved-polo-with-trousers look this coming semester, check out this season’s new clothing picks. California-based apparel brand, No Fear, shows you how to keep cool all-school year long. It offers a wide range of apparel and accessories including comfy jackets, fresh-detailed shirt, caps, and even bags. If you’re down for shirts you can wear for all days of the week, No Fear has you covered. With school days potentially welcomed by showers of rain—or if your class rooms are newly equipped with full-blast air-conditioning—bundle up and stay cosy while rocking your casual get-up. Wear the newest jacket releases from No Fear such as the Discipline and Determination hoodies designed with understated neutrals and colour-blocked designs in comfy, nylon material— an edgy touch to your everyday-wear. Mix up your button-down staples with more relaxed collared variant, polo shirts. If you’re on the hunt for easy-to-wear tops that show your personality, a crisp formal shirt won’t cut it. Try on these newest polo shirt drops from No Fear. The Mercury shirt showcases a tasteful striped pattern in classic red-and-black colour way, a perfect match to your fresh white kicks. The True polo shirt is an ideal top to wear for those opting for a minimalist design. A pair of khaki shorts seems to be a great partner if you’re bold enough to wear shorts to school! Let’s face it, after-school hangouts make college life more fun and memorable. Off to a gaming hub or a new food par? Cop yourself a fun and functional cap like these pieces from No Fear. Rep your snapbacks on and off campus on your next field trip adventure! Don’t forget to look and be smart by investing in modern back packs. These waxed canvas backpacks from No Fear are designed with colour block fabric and a clean silhouette. For more No Fear items, visit major department stores or go online at www.nofear.com.ph . Get the latest update on Facebook at www.facebook.com/nofearph and @nofearph for Instagram.
lemma IVT': fixes f :: "'a::linear_continuum_topology \<Rightarrow> 'b::linorder_topology" assumes y: "f a \<le> y" "y \<le> f b" "a \<le> b" and *: "continuous_on {a .. b} f" shows "\<exists>x. a \<le> x \<and> x \<le> b \<and> f x = y"
(* Title: HOL/Auth/n_germanSymIndex_lemma_on_inv__21.thy Author: Yongjian Li and Kaiqiang Duan, State Key Lab of Computer Science, Institute of Software, Chinese Academy of Sciences Copyright 2016 State Key Lab of Computer Science, Institute of Software, Chinese Academy of Sciences *) header{*The n_germanSymIndex Protocol Case Study*} theory n_germanSymIndex_lemma_on_inv__21 imports n_germanSymIndex_base begin section{*All lemmas on causal relation between inv__21 and some rule r*} lemma n_SendInv__part__0Vsinv__21: assumes a1: "(\<exists> i. i\<le>N\<and>r=n_SendInv__part__0 i)" and a2: "(\<exists> p__Inv2. p__Inv2\<le>N\<and>f=inv__21 p__Inv2)" shows "invHoldForRule s f r (invariants N)" (is "?P1 s \<or> ?P2 s \<or> ?P3 s") proof - from a1 obtain i where a1:"i\<le>N\<and>r=n_SendInv__part__0 i" apply fastforce done from a2 obtain p__Inv2 where a2:"p__Inv2\<le>N\<and>f=inv__21 p__Inv2" apply fastforce done have "(i=p__Inv2)\<or>(i~=p__Inv2)" apply (cut_tac a1 a2, auto) done moreover { assume b1: "(i=p__Inv2)" have "?P1 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume b1: "(i~=p__Inv2)" have "?P2 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } ultimately show "invHoldForRule s f r (invariants N)" by satx qed lemma n_SendInv__part__1Vsinv__21: assumes a1: "(\<exists> i. i\<le>N\<and>r=n_SendInv__part__1 i)" and a2: "(\<exists> p__Inv2. p__Inv2\<le>N\<and>f=inv__21 p__Inv2)" shows "invHoldForRule s f r (invariants N)" (is "?P1 s \<or> ?P2 s \<or> ?P3 s") proof - from a1 obtain i where a1:"i\<le>N\<and>r=n_SendInv__part__1 i" apply fastforce done from a2 obtain p__Inv2 where a2:"p__Inv2\<le>N\<and>f=inv__21 p__Inv2" apply fastforce done have "(i=p__Inv2)\<or>(i~=p__Inv2)" apply (cut_tac a1 a2, auto) done moreover { assume b1: "(i=p__Inv2)" have "?P1 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume b1: "(i~=p__Inv2)" have "?P2 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } ultimately show "invHoldForRule s f r (invariants N)" by satx qed lemma n_SendInvAckVsinv__21: assumes a1: "(\<exists> i. i\<le>N\<and>r=n_SendInvAck i)" and a2: "(\<exists> p__Inv2. p__Inv2\<le>N\<and>f=inv__21 p__Inv2)" shows "invHoldForRule s f r (invariants N)" (is "?P1 s \<or> ?P2 s \<or> ?P3 s") proof - from a1 obtain i where a1:"i\<le>N\<and>r=n_SendInvAck i" apply fastforce done from a2 obtain p__Inv2 where a2:"p__Inv2\<le>N\<and>f=inv__21 p__Inv2" apply fastforce done have "(i=p__Inv2)\<or>(i~=p__Inv2)" apply (cut_tac a1 a2, auto) done moreover { assume b1: "(i=p__Inv2)" have "?P1 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume b1: "(i~=p__Inv2)" have "?P2 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } ultimately show "invHoldForRule s f r (invariants N)" by satx qed lemma n_SendGntSVsinv__21: assumes a1: "(\<exists> i. i\<le>N\<and>r=n_SendGntS i)" and a2: "(\<exists> p__Inv2. p__Inv2\<le>N\<and>f=inv__21 p__Inv2)" shows "invHoldForRule s f r (invariants N)" (is "?P1 s \<or> ?P2 s \<or> ?P3 s") proof - from a1 obtain i where a1:"i\<le>N\<and>r=n_SendGntS i" apply fastforce done from a2 obtain p__Inv2 where a2:"p__Inv2\<le>N\<and>f=inv__21 p__Inv2" apply fastforce done have "(i=p__Inv2)\<or>(i~=p__Inv2)" apply (cut_tac a1 a2, auto) done moreover { assume b1: "(i=p__Inv2)" have "?P1 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume b1: "(i~=p__Inv2)" have "?P2 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } ultimately show "invHoldForRule s f r (invariants N)" by satx qed lemma n_SendGntEVsinv__21: assumes a1: "(\<exists> i. i\<le>N\<and>r=n_SendGntE N i)" and a2: "(\<exists> p__Inv2. p__Inv2\<le>N\<and>f=inv__21 p__Inv2)" shows "invHoldForRule s f r (invariants N)" (is "?P1 s \<or> ?P2 s \<or> ?P3 s") proof - from a1 obtain i where a1:"i\<le>N\<and>r=n_SendGntE N i" apply fastforce done from a2 obtain p__Inv2 where a2:"p__Inv2\<le>N\<and>f=inv__21 p__Inv2" apply fastforce done have "(i=p__Inv2)\<or>(i~=p__Inv2)" apply (cut_tac a1 a2, auto) done moreover { assume b1: "(i=p__Inv2)" have "?P3 s" apply (cut_tac a1 a2 b1, simp, rule_tac x="(neg (andForm (eqn (IVar (Ident ''ExGntd'')) (Const false)) (eqn (IVar (Field (Para (Ident ''Cache'') p__Inv2) ''State'')) (Const E))))" in exI, auto) done then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume b1: "(i~=p__Inv2)" have "?P2 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } ultimately show "invHoldForRule s f r (invariants N)" by satx qed lemma n_RecvGntSVsinv__21: assumes a1: "(\<exists> i. i\<le>N\<and>r=n_RecvGntS i)" and a2: "(\<exists> p__Inv2. p__Inv2\<le>N\<and>f=inv__21 p__Inv2)" shows "invHoldForRule s f r (invariants N)" (is "?P1 s \<or> ?P2 s \<or> ?P3 s") proof - from a1 obtain i where a1:"i\<le>N\<and>r=n_RecvGntS i" apply fastforce done from a2 obtain p__Inv2 where a2:"p__Inv2\<le>N\<and>f=inv__21 p__Inv2" apply fastforce done have "(i=p__Inv2)\<or>(i~=p__Inv2)" apply (cut_tac a1 a2, auto) done moreover { assume b1: "(i=p__Inv2)" have "?P1 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume b1: "(i~=p__Inv2)" have "?P2 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } ultimately show "invHoldForRule s f r (invariants N)" by satx qed lemma n_RecvGntEVsinv__21: assumes a1: "(\<exists> i. i\<le>N\<and>r=n_RecvGntE i)" and a2: "(\<exists> p__Inv2. p__Inv2\<le>N\<and>f=inv__21 p__Inv2)" shows "invHoldForRule s f r (invariants N)" (is "?P1 s \<or> ?P2 s \<or> ?P3 s") proof - from a1 obtain i where a1:"i\<le>N\<and>r=n_RecvGntE i" apply fastforce done from a2 obtain p__Inv2 where a2:"p__Inv2\<le>N\<and>f=inv__21 p__Inv2" apply fastforce done have "(i=p__Inv2)\<or>(i~=p__Inv2)" apply (cut_tac a1 a2, auto) done moreover { assume b1: "(i=p__Inv2)" have "?P1 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume b1: "(i~=p__Inv2)" have "?P2 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } ultimately show "invHoldForRule s f r (invariants N)" by satx qed lemma n_SendReqE__part__1Vsinv__21: assumes a1: "\<exists> i. i\<le>N\<and>r=n_SendReqE__part__1 i" and a2: "(\<exists> p__Inv2. p__Inv2\<le>N\<and>f=inv__21 p__Inv2)" shows "invHoldForRule s f r (invariants N)" apply (rule noEffectOnRule, cut_tac a1 a2, auto) done lemma n_StoreVsinv__21: assumes a1: "\<exists> i d. i\<le>N\<and>d\<le>N\<and>r=n_Store i d" and a2: "(\<exists> p__Inv2. p__Inv2\<le>N\<and>f=inv__21 p__Inv2)" shows "invHoldForRule s f r (invariants N)" apply (rule noEffectOnRule, cut_tac a1 a2, auto) done lemma n_RecvInvAckVsinv__21: assumes a1: "\<exists> i. i\<le>N\<and>r=n_RecvInvAck i" and a2: "(\<exists> p__Inv2. p__Inv2\<le>N\<and>f=inv__21 p__Inv2)" shows "invHoldForRule s f r (invariants N)" apply (rule noEffectOnRule, cut_tac a1 a2, auto) done lemma n_RecvReqEVsinv__21: assumes a1: "\<exists> i. i\<le>N\<and>r=n_RecvReqE N i" and a2: "(\<exists> p__Inv2. p__Inv2\<le>N\<and>f=inv__21 p__Inv2)" shows "invHoldForRule s f r (invariants N)" apply (rule noEffectOnRule, cut_tac a1 a2, auto) done lemma n_SendReqE__part__0Vsinv__21: assumes a1: "\<exists> i. i\<le>N\<and>r=n_SendReqE__part__0 i" and a2: "(\<exists> p__Inv2. p__Inv2\<le>N\<and>f=inv__21 p__Inv2)" shows "invHoldForRule s f r (invariants N)" apply (rule noEffectOnRule, cut_tac a1 a2, auto) done lemma n_SendReqSVsinv__21: assumes a1: "\<exists> i. i\<le>N\<and>r=n_SendReqS i" and a2: "(\<exists> p__Inv2. p__Inv2\<le>N\<and>f=inv__21 p__Inv2)" shows "invHoldForRule s f r (invariants N)" apply (rule noEffectOnRule, cut_tac a1 a2, auto) done lemma n_RecvReqSVsinv__21: assumes a1: "\<exists> i. i\<le>N\<and>r=n_RecvReqS N i" and a2: "(\<exists> p__Inv2. p__Inv2\<le>N\<and>f=inv__21 p__Inv2)" shows "invHoldForRule s f r (invariants N)" apply (rule noEffectOnRule, cut_tac a1 a2, auto) done end
[STATEMENT] lemma map_le_fun_upd2: "\<lbrakk> f \<subseteq>\<^sub>m g; x \<notin> dom f \<rbrakk> \<Longrightarrow> f \<subseteq>\<^sub>m g(x := y)" [PROOF STATE] proof (prove) goal (1 subgoal): 1. \<lbrakk>f \<subseteq>\<^sub>m g; x \<notin> dom f\<rbrakk> \<Longrightarrow> f \<subseteq>\<^sub>m g(x := y) [PROOF STEP] by(auto simp add: map_le_def)
/- Copyright (c) 2019 Chris Hughes. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Chris Hughes -/ import set_theory.cardinal /-! # Denumerability of ℚ This file proves that ℚ is infinite, denumerable, and deduces that it has cardinality `omega`. -/ namespace rat open denumerable instance : infinite ℚ := infinite.of_injective (coe : ℕ → ℚ) nat.cast_injective private def denumerable_aux : ℚ ≃ { x : ℤ × ℕ // 0 < x.2 ∧ x.1.nat_abs.coprime x.2 } := { to_fun := λ x, ⟨⟨x.1, x.2⟩, x.3, x.4⟩, inv_fun := λ x, ⟨x.1.1, x.1.2, x.2.1, x.2.2⟩, left_inv := λ ⟨_, _, _, _⟩, rfl, right_inv := λ ⟨⟨_, _⟩, _, _⟩, rfl } /-- **Denumerability of the Rational Numbers** -/ instance : denumerable ℚ := begin let T := { x : ℤ × ℕ // 0 < x.2 ∧ x.1.nat_abs.coprime x.2 }, letI : infinite T := infinite.of_injective _ denumerable_aux.injective, letI : encodable T := encodable.subtype, letI : denumerable T := of_encodable_of_infinite T, exact denumerable.of_equiv T denumerable_aux end end rat namespace cardinal open_locale cardinal lemma mk_rat : #ℚ = ω := mk_denumerable ℚ end cardinal
module Decidable.Equality.Indexed %default total %access public export interface DecEq iTy => DecEqIdx (iTy : Type) (eTy : iTy -> Type) | eTy where decEq : {i,j : iTy} -> (x : eTy i) -> (y : eTy j) -> (prf : i = j) -> Dec (x = y)
Lock in a great price for Lederer's living – rated 9.5 by recent guests! As always words can’t express enough how marvelous our stay was, would love to stay in all the year around! Spacious room, clean, huge comfortable bed, balcony with amazing view. There's a refrigerator, espresso machine and a water heater. Excellent room service. The Staff are very nice. Wonderful stay ,very quit area , in front of river, helpful-smile staff , cleanliness and verity of breakfast. Location and facility were superb. Owner was also friendly. Lederer's living This rating is a reflection of how the property compares to the industry standard when it comes to price, facilities and services available. It's based on a self-evaluation by the property. Use this rating to help choose your stay! One of our best sellers in Kaprun! Lederer’s living is a modern design hotel in the center of Kaprun. The property features a restaurant serving a buffet breakfast and all guests enjoy free admission to the Tauern Spa Kaprun. The ski bus to the Kitzsteinhorn and Schmittenhöhe ski areas stops only 250 feet from Lederer’s living. Ski equipment can be stored and ski passes can be bought on site. After a long day outdoors, guests can relax in the penthouse sauna overlooking Kaprun, in the lounge with a fireplace and on the sun terrace. All apartments and rooms offer panoramic views of the surrounding Alpine landscape from the balcony. An LCD TV with cable channels, espresso machine and seating area are found in all rooms. The private bathroom has a bath or shower and comes with a variety of bathroom amenities. The hotel offers free Wi-Fi and free use of its underground car park. Packed lunches and breakfast in the room can be organized. The Tauern Spa and cross-country ski runs are 5 minutes’ drive from the hotel. Ortsmitte Bus Stop is a minutes’ walk away. This property also has one of the top-rated locations in Kaprun! Guests are happier about it compared to other properties in the area. This property is also rated for the best value in Kaprun! Guests are getting more for their money when compared to other properties in this city. When would you like to stay at Lederer's living? This room offers a balcony with view. The bathroom features a tropical-style shower. Please note that the maximum occupancy of this room is 3 people, 1 extra bed is available on request. This room consists of two bedroom with a large double bed in each and features views of the surrounding Alpine landscape from the balcony. A Nintendo Wii is provided in the room. Please note that the room rate is based on 3 People or 2 adults and 2 children up to 12 years. Please note that extra beds are not possible in this room type, the maximum occupancy is 4 people. This spacious apartment features views of the surrounding Alpine landscape from the spacious balcony. It is fitted with a fully-equipped kitchenette and dining area. There are 2 private bathrooms with a bath or shower. The rate is based on 4 people, maximum occupancy of the room is 6 people on request and at a surcharge. Please note that the final cleaning fee is waived if the apartment is left in a satisfactory condition. Please note that the maximum occupancy of this room is 2 people, extra beds are not possible in this room type. This suite consists of 2 bedrooms with a kingsize double bed in each bedroom. It offers a balcony and a private saune with wellness-shower. Please note that extra beds are not possible in this room type, the maximum occupancy for this room is 4 people. House Rules Lederer's living takes special requests – add in the next step! Lederer&#39;s living accepts these cards and reserves the right to temporarily hold an amount prior to arrival. Lederer's living accepts these cards and reserves the right to temporarily hold an amount prior to arrival. Spotless, beautiful and comfortable design. Friendly staff, amazing breakfast. The best part is the unlimited access to the Tauern Spa in the room price. Great place with very friendly and helpful owners and all stuff. Very comfy rooms and great spa. The terras outside, the location is perfect and the atmosphere in the whole hotel is relaxed and easy. perfectly decorated with an eye to detail.. very good breakfast. Great location. The new ski lift will be completed in December 2019; there will be no more bus rides to Kaprun. Not really dislike, but be aware the underground parking spaces are extremely limited in size, so if you are driving anything like a Land Rover Discovery, you will find it challenging to park. the staff really helpful and kind.. Ski Room with stairs, but tiny detail. Great Breakfast, Great Room, Great Hospitality. Owners and staff were friendly and helpful. Location nearby to Tauren Spa with free entry provided by the accommodation. Central location = a bit of noise from apres ski next door. Very nice, new, cosy hotel. Wonderfull staff! Excellent breakfast.
theory Topological_Spaces imports Category Orders begin locale "open" = fixes "open" :: "'a set set" locale topological_space = "open" + fixes universe :: "'a set" assumes open_empty [simp, intro]: "{} \<in> open" assumes open_UNIV [simp, intro]: "universe \<in> open" assumes open_subsets: "x \<in> open \<Longrightarrow> x \<subseteq> universe" assumes open_Int [intro]: "S \<in> open \<Longrightarrow> T \<in> open \<Longrightarrow> (S \<inter> T) \<in> open " assumes open_Union [intro]: "\<forall>S\<in>K. S \<in> open \<Longrightarrow> (\<Union>K) \<in> open " locale finite_topological_space = topological_space + assumes finite_universe[simp]: "finite universe" locale cover = topological_space + fixes covering :: "'a set set" assumes cover_open[simp, intro]: "covering \<subseteq> open" assumes covers: "\<Union>(covering) = universe" definition "lower S \<equiv> {X. \<exists>Y\<in>S. X \<le> Y}" lemma Sup_is_lower_Sup:"\<Union>S = \<Union>(lower S)" apply (clarsimp simp: lower_def) apply (safe; clarsimp) apply blast apply blast done term lattice locale maximal_cover = cover + assumes antichain: "x \<in> covering \<Longrightarrow> y \<in> covering \<Longrightarrow> \<not> (x \<subset> y) " lemma maximal_in_finite_set: "x \<in> S \<Longrightarrow> P (x :: 'a :: preorder) \<Longrightarrow> finite S \<Longrightarrow> (\<exists>y\<ge>x. y \<in> S \<and> P y \<and> (\<forall>z\<in>S. P z \<longrightarrow> \<not>(z > y)))" apply (induct S arbitrary: x rule:infinite_finite_induct; clarsimp) apply (elim disjE; clarsimp?) apply (metis (no_types, lifting) dual_order.refl less_le_not_le order_trans) by (metis (full_types) dual_order.strict_trans2 less_le_not_le) definition "maximal P x \<equiv> P x \<and> (\<forall>y. P y \<longrightarrow> \<not>(y > x))" context finite_topological_space begin abbreviation (input) "max_cover x \<equiv> maximal_cover open universe x" definition "cover_join X Y = {Z. Z \<in> X \<union> Y \<and> (\<forall>Z'. Z' \<in> X \<union> Y \<longrightarrow> \<not> Z \<subset> Z')} " definition "cover_meet X Y = {Z. Z \<in> lower X \<inter> lower Y \<and> (\<forall>Z'. Z' \<in> lower X \<inter> lower Y \<longrightarrow> \<not> Z \<subset> Z')} " lemma in_cover_is_open: "maximal_cover open universe z \<Longrightarrow> x \<in> z \<Longrightarrow> x \<in> open" by (meson cover.cover_open in_mono maximal_cover_def) lemma spec_set_eq: "X = Y \<Longrightarrow> c \<in> Y \<Longrightarrow> c \<in> X" apply (blast) done lemma cover_meet_is_inf: "max_cover A \<Longrightarrow> max_cover B \<Longrightarrow> x \<in> cover_meet A B \<Longrightarrow> (\<exists>y\<in>A.\<exists>z\<in>B. x = y \<inter> z)" apply (clarsimp simp: cover_meet_def) apply (clarsimp simp: lower_def) by (meson Int_greatest Int_lower1 Int_lower2 order_neq_le_trans) lemma not_psub_iff:"(\<not> x \<subset> y) \<longleftrightarrow> x = y \<or> (\<exists>c. c \<in> x \<and> c \<notin> y)" apply (intro iffI) apply (safe; clarsimp) apply (blast)+ done lemma in_univ_in_inter:"maximal_cover open universe A \<Longrightarrow> maximal_cover open universe B \<Longrightarrow> t \<in> universe \<Longrightarrow> \<exists>U\<in>A. \<exists>V\<in>B. t \<in> U \<inter> V" by (metis (mono_tags, opaque_lifting) Int_iff Union_iff cover.covers maximal_cover.axioms(1)) lemma in_univ_in_inter':"maximal_cover open universe A \<Longrightarrow> maximal_cover open universe B \<Longrightarrow> t \<in> universe \<Longrightarrow> \<forall>U\<in>A. t \<in> U \<longrightarrow> (\<exists>V\<in>B. t \<in> U \<inter> V)" by (metis (mono_tags, opaque_lifting) Int_iff Union_iff cover.covers maximal_cover.axioms(1)) lemma lower_Sup: "lower S = (\<Union>x\<in>S. lower {x})" apply (safe; clarsimp simp: lower_def) by blast lemma finite_lower: "finite S \<Longrightarrow> \<forall>x\<in>S. finite x \<Longrightarrow> finite (lower S)" apply (subst lower_Sup) apply (subst finite_UN; clarsimp) by (clarsimp simp: lower_def) lemma cover_meet_iff: "max_cover a \<Longrightarrow> max_cover b \<Longrightarrow> x \<in> cover_meet a b \<longleftrightarrow> maximal (\<lambda>x. \<exists>U V. U \<in> a \<and> V \<in> b \<and> x \<subseteq> U \<inter> V) x" apply (clarsimp simp: cover_meet_def lower_def) apply (safe; clarsimp?) apply (clarsimp simp: maximal_def) apply (intro conjI) apply (rule_tac x=xa in exI, intro conjI; clarsimp?) apply (rule_tac x=xaa in exI, intro conjI; clarsimp?) apply (meson Int_lower1 inf.cobounded2 inf_greatest order_neq_le_trans) (* apply (clarsimp) apply (metis equalityE insert_subsetI psubset_insert_iff)*) apply (clarsimp simp: maximal_def) apply (blast) apply (clarsimp simp: maximal_def) apply (blast) apply (clarsimp simp: maximal_def) by (metis Int_iff inf.absorb_iff2 inf_assoc psubsetI) find_consts "'a set \<Rightarrow> 'a set set" lemma max_cover_closed: "maximal_cover open universe x \<Longrightarrow> maximal_cover open universe y \<Longrightarrow> \<Union> (cover_meet x y) = universe " apply (safe)[1] apply (clarsimp simp: cover_meet_def lower_def ) apply (subgoal_tac "X=xaa \<inter> xb") apply (meson in_cover_is_open in_mono open_subsets) apply (smt (z3) Int_absorb dual_order.strict_iff_order finite_topological_space.in_cover_is_open finite_topological_space_axioms inf.absorb_iff2 inf.cobounded1 inf.cobounded2 inf_greatest topological_space.open_subsets topological_space_axioms) apply (clarsimp) apply (clarsimp simp: cover_meet_def) apply (frule_tac A=x and B=y in in_univ_in_inter, assumption, assumption) apply (clarsimp) apply (insert maximal_in_finite_set)[1] apply (atomize) apply (erule_tac x="U \<inter> xaa" in allE) apply (erule_tac x="{x. x \<subseteq> universe}" in allE) apply (erule_tac x="\<lambda>v. v \<in> (lower x \<inter> lower y)" in allE) apply (drule mp) apply (clarsimp) apply (meson in_cover_is_open in_mono open_subsets) apply (drule mp) apply (clarsimp simp: lower_def, intro conjI) apply blast apply blast apply (drule mp) apply (clarsimp) (* apply (meson finite_UnionD finite_universe open_Union open_subsets rev_finite_subset) *) apply (clarsimp) apply (rule_tac x=ya in exI; clarsimp) apply (intro conjI) apply (clarsimp) apply (erule_tac x=Z' in allE) apply (clarsimp) apply (metis Sup_is_lower_Sup Union_upper cover.covers maximal_cover.axioms(1) psubsetI) by blast lemma Int_greatest: "xa \<subseteq> U \<and> xa \<subseteq> V \<longleftrightarrow> xa \<subseteq> (U \<inter> V)" by (safe; blast) lemma maximal_iff: " maximal (\<lambda>xa. \<exists>U. U \<in> x \<and> (\<exists>V. V \<in> y \<and> xa \<subseteq> U \<and> xa \<subseteq> V)) z \<longleftrightarrow> (\<exists>U. U \<in> x \<and> (\<exists>V. V \<in> y \<and> z = U \<inter> V)) \<and> (\<forall>z'. (\<exists>U. U \<in> x \<and> (\<exists>V. V \<in> y \<and> z' \<subseteq> U \<inter> V)) \<longrightarrow> \<not> z \<subset> z') " apply (clarsimp simp: maximal_def) apply (intro iffI; clarsimp?) apply (metis dual_order.strict_iff_order inf.cobounded2 inf_greatest inf_sup_ord(1)) by (blast) lemma maximal_iff': "maximal (\<lambda>xa. \<exists>U. U \<in> x \<and> (\<exists>V. V \<in> y \<and> xa \<subseteq> U \<and> xa \<subseteq> V)) = maximal (\<lambda>v. v \<in> lower x \<inter> lower y)" apply (rule ext, safe; clarsimp simp: maximal_def) apply (safe; clarsimp simp: lower_def) apply (blast) apply (blast) apply blast by (smt (verit, del_insts) lower_def mem_Collect_eq) (* Max covers are closed under antichain-meet *) lemma max_cover_closed_meet[simp]:" maximal_cover open universe x \<Longrightarrow> maximal_cover open universe y \<Longrightarrow> maximal_cover open universe (cover_meet x y)" apply (standard; clarsimp?) apply (clarsimp simp: cover_meet_iff maximal_iff) apply (meson in_cover_is_open open_Int) apply (erule (1) max_cover_closed) apply (clarsimp simp: cover_meet_def lower_def) by blast (* Max covers are closed under antichain-join *) lemma max_cover_closed_join[simp]:" maximal_cover open universe x \<Longrightarrow> maximal_cover open universe y \<Longrightarrow> maximal_cover open universe (cover_join x y)" apply (unfold_locales)[1] apply (clarsimp simp: cover_join_def) apply (meson in_cover_is_open) apply (intro set_eqI iffI; clarsimp) apply (clarsimp simp: cover_join_def) apply (meson in_cover_is_open in_mono open_subsets) apply (clarsimp simp: cover_join_def) apply (smt (verit, ccfv_threshold) Int_iff in_univ_in_inter maximal_cover.antichain psubsetD psubset_trans) apply (clarsimp simp: cover_join_def) by blast end end
#pragma once #include <boost/polygon/polygon.hpp> #include <boost/polygon/voronoi.hpp> #include <cslibs_vectormaps/dxf/dxf_map.h> namespace boost { namespace polygon { using PointType = cslibs_vectormaps::dxf::DXFMap::Point; using SegmentType = cslibs_vectormaps::dxf::DXFMap::Vector; template<> struct geometry_concept<PointType> { typedef point_concept type; }; template<> struct point_traits<PointType> { typedef double coordinate_type; static inline coordinate_type get(const PointType &point, orientation_2d orient) { return (orient == HORIZONTAL) ? point.x() : point.y(); } }; template<> struct geometry_concept<SegmentType> { typedef segment_concept type; }; template<> struct segment_traits<SegmentType> { typedef double coordinate_type; typedef PointType point_type; static inline point_type get(const SegmentType &segment, direction_1d dir) { return dir.to_int() ? segment.second : segment.first; } }; } } typedef boost::polygon::voronoi_diagram<double> VoronoiType;
Formal statement is: lemma triangle_contour_integrals_convex_primitive: assumes contf: "continuous_on S f" and S: "a \<in> S" "convex S" and x: "x \<in> S" and zer: "\<And>b c. \<lbrakk>b \<in> S; c \<in> S\<rbrakk> \<Longrightarrow> contour_integral (linepath a b) f + contour_integral (linepath b c) f + contour_integral (linepath c a) f = 0" shows "((\<lambda>x. contour_integral(linepath a x) f) has_field_derivative f x) (at x within S)" Informal statement is: If $f$ is a continuous function on a convex set $S$ and $a \in S$, then the function $g(x) = \int_a^x f(t) dt$ is differentiable at every point $x \in S$ and $g'(x) = f(x)$.
Flattery : " speech to deceive others for our benefit . "
-- Pruebas_de_equivalencia_de_definiciones_de_inversa.lean -- Pruebas de equivalencia de definiciones de inversa -- José A. Alonso Jiménez -- Sevilla, 11 de septiembre de 2021 -- --------------------------------------------------------------------- -- --------------------------------------------------------------------- -- En Lean, está definida la función -- reverse : list α → list α -- tal que (reverse xs) es la lista obtenida invirtiendo el orden de los -- elementos de xs. Por ejemplo, -- reverse [3,2,5,1] = [1,5,2,3] -- Su definición es -- def reverse_core : list α → list α → list α -- | [] r := r -- | (a::l) r := reverse_core l (a::r) -- -- def reverse : list α → list α := -- λ l, reverse_core l [] -- -- Una definición alternativa es -- def inversa : list α → list α -- | [] := [] -- | (x :: xs) := inversa xs ++ [x] -- -- Demostrar que las dos definiciones son equivalentes; es decir, -- reverse xs = inversa xs -- --------------------------------------------------------------------- import data.list.basic open list variable {α : Type*} variable (x : α) variables (xs ys : list α) -- Definición y reglas de simplificación de inversa -- ================================================ def inversa : list α → list α | [] := [] | (x :: xs) := inversa xs ++ [x] @[simp] lemma inversa_nil : inversa ([] : list α) = [] := rfl @[simp] lemma inversa_cons : inversa (x :: xs) = inversa xs ++ [x] := rfl -- Reglas de simplificación de reverse_core -- ======================================== @[simp] lemma reverse_core_nil : reverse_core [] ys = ys := rfl @[simp] lemma reverse_core_cons : reverse_core (x :: xs) ys = reverse_core xs (x :: ys) := rfl -- Lema auxiliar: reverse_core xs ys = (inversa xs) ++ ys -- ====================================================== -- 1ª demostración del lema auxiliar example : reverse_core xs ys = (inversa xs) ++ ys := begin induction xs with a as HI generalizing ys, { calc reverse_core [] ys = ys : reverse_core_nil ys ... = [] ++ ys : (nil_append ys).symm ... = inversa [] ++ ys : congr_arg2 (++) inversa_nil.symm rfl, }, { calc reverse_core (a :: as) ys = reverse_core as (a :: ys) : reverse_core_cons a as ys ... = inversa as ++ (a :: ys) : (HI (a :: ys)) ... = inversa as ++ ([a] ++ ys) : congr_arg2 (++) rfl singleton_append ... = (inversa as ++ [a]) ++ ys : (append_assoc (inversa as) [a] ys).symm ... = inversa (a :: as) ++ ys : congr_arg2 (++) (inversa_cons a as).symm rfl}, end -- 2ª demostración del lema auxiliar example : reverse_core xs ys = (inversa xs) ++ ys := begin induction xs with a as HI generalizing ys, { calc reverse_core [] ys = ys : by rw reverse_core_nil ... = [] ++ ys : by rw nil_append ... = inversa [] ++ ys : by rw inversa_nil }, { calc reverse_core (a :: as) ys = reverse_core as (a :: ys) : by rw reverse_core_cons ... = inversa as ++ (a :: ys) : by rw (HI (a :: ys)) ... = inversa as ++ ([a] ++ ys) : by rw singleton_append ... = (inversa as ++ [a]) ++ ys : by rw append_assoc ... = inversa (a :: as) ++ ys : by rw inversa_cons }, end -- 3ª demostración del lema auxiliar example : reverse_core xs ys = (inversa xs) ++ ys := begin induction xs with a as HI generalizing ys, { calc reverse_core [] ys = ys : rfl ... = [] ++ ys : rfl ... = inversa [] ++ ys : rfl }, { calc reverse_core (a :: as) ys = reverse_core as (a :: ys) : rfl ... = inversa as ++ (a :: ys) : (HI (a :: ys)) ... = inversa as ++ ([a] ++ ys) : rfl ... = (inversa as ++ [a]) ++ ys : by rw append_assoc ... = inversa (a :: as) ++ ys : rfl }, end -- 3ª demostración del lema auxiliar example : reverse_core xs ys = (inversa xs) ++ ys := begin induction xs with a as HI generalizing ys, { calc reverse_core [] ys = ys : by simp ... = [] ++ ys : by simp ... = inversa [] ++ ys : by simp }, { calc reverse_core (a :: as) ys = reverse_core as (a :: ys) : by simp ... = inversa as ++ (a :: ys) : (HI (a :: ys)) ... = inversa as ++ ([a] ++ ys) : by simp ... = (inversa as ++ [a]) ++ ys : by simp ... = inversa (a :: as) ++ ys : by simp }, end -- 4ª demostración del lema auxiliar example : reverse_core xs ys = (inversa xs) ++ ys := begin induction xs with a as HI generalizing ys, { by simp, }, { calc reverse_core (a :: as) ys = reverse_core as (a :: ys) : by simp ... = inversa as ++ (a :: ys) : (HI (a :: ys)) ... = inversa (a :: as) ++ ys : by simp }, end -- 5ª demostración del lema auxiliar example : reverse_core xs ys = (inversa xs) ++ ys := begin induction xs with a as HI generalizing ys, { simp, }, { simp [HI (a :: ys)], }, end -- 6ª demostración del lema auxiliar example : reverse_core xs ys = (inversa xs) ++ ys := by induction xs generalizing ys ; simp [*] -- 7ª demostración del lema auxiliar example : reverse_core xs ys = (inversa xs) ++ ys := begin induction xs with a as HI generalizing ys, { rw reverse_core_nil, rw inversa_nil, rw nil_append, }, { rw reverse_core_cons, rw (HI (a :: ys)), rw inversa_cons, rw append_assoc, rw singleton_append, }, end -- 8ª demostración del lema auxiliar @[simp] lemma inversa_equiv : ∀ xs : list α, ∀ ys, reverse_core xs ys = (inversa xs) ++ ys | [] := by simp | (a :: as) := by simp [inversa_equiv as] -- Demostraciones del lema principal -- ================================= -- 1ª demostración example : reverse xs = inversa xs := calc reverse xs = reverse_core xs [] : rfl ... = inversa xs ++ [] : by rw inversa_equiv ... = inversa xs : by rw append_nil -- 2ª demostración example : reverse xs = inversa xs := by simp [inversa_equiv, reverse] -- 3ª demostración example : reverse xs = inversa xs := by simp [reverse]
Formal statement is: lemma contour_integrable_reversepath_eq: "valid_path g \<Longrightarrow> (f contour_integrable_on (reversepath g) \<longleftrightarrow> f contour_integrable_on g)" Informal statement is: If $g$ is a valid path, then $f$ is contour-integrable along $g$ if and only if $f$ is contour-integrable along the reverse path of $g$.
lemma (in order_topology) order_tendstoD: assumes "(f \<longlongrightarrow> y) F" shows "a < y \<Longrightarrow> eventually (\<lambda>x. a < f x) F" and "y < a \<Longrightarrow> eventually (\<lambda>x. f x < a) F"
Formal statement is: lemma incseqD: "incseq f \<Longrightarrow> i \<le> j \<Longrightarrow> f i \<le> f j" Informal statement is: If $f$ is an increasing sequence, then $f_i \leq f_j$ whenever $i \leq j$.
[STATEMENT] lemma closed_diagonal: "closed {y. \<exists> x::('a::t2_space). y = (x,x)}" [PROOF STATE] proof (prove) goal (1 subgoal): 1. closed {y. \<exists>x. y = (x, x)} [PROOF STEP] proof - [PROOF STATE] proof (state) goal (1 subgoal): 1. closed {y. \<exists>x. y = (x, x)} [PROOF STEP] have "{y. \<exists> x::'a. y = (x,x)} = UNIV - {(x,y) | x y. x \<noteq> y}" [PROOF STATE] proof (prove) goal (1 subgoal): 1. {y. \<exists>x. y = (x, x)} = UNIV - {(x, y) |x y. x \<noteq> y} [PROOF STEP] by auto [PROOF STATE] proof (state) this: {y. \<exists>x. y = (x, x)} = UNIV - {(x, y) |x y. x \<noteq> y} goal (1 subgoal): 1. closed {y. \<exists>x. y = (x, x)} [PROOF STEP] then [PROOF STATE] proof (chain) picking this: {y. \<exists>x. y = (x, x)} = UNIV - {(x, y) |x y. x \<noteq> y} [PROOF STEP] show ?thesis [PROOF STATE] proof (prove) using this: {y. \<exists>x. y = (x, x)} = UNIV - {(x, y) |x y. x \<noteq> y} goal (1 subgoal): 1. closed {y. \<exists>x. y = (x, x)} [PROOF STEP] using open_diagonal_complement closed_Diff [PROOF STATE] proof (prove) using this: {y. \<exists>x. y = (x, x)} = UNIV - {(x, y) |x y. x \<noteq> y} open {(x, y) |x y. x \<noteq> y} \<lbrakk>closed ?S; open ?T\<rbrakk> \<Longrightarrow> closed (?S - ?T) goal (1 subgoal): 1. closed {y. \<exists>x. y = (x, x)} [PROOF STEP] by auto [PROOF STATE] proof (state) this: closed {y. \<exists>x. y = (x, x)} goal: No subgoals! [PROOF STEP] qed
module Replica.App.Format import public Control.ANSI import Control.App import Replica.Option.Global import Replica.App.Log import Replica.App.Replica import Replica.Other.Decorated export ok : State GlobalConfig Global e => App e String ok = do ascii <- map ascii $ get GlobalConfig pure $ if ascii then "OK " else "✅ " export ko : State GlobalConfig Global e => App e String ko = do ascii <- map ascii $ get GlobalConfig pure $ if ascii then "KO " else "❌ " export err : State GlobalConfig Global e => App e String err = do ascii <- map ascii $ get GlobalConfig pure $ if ascii then "ERR" else "⚠️ " export pending : State GlobalConfig Global e => App e String pending = do ascii <- map ascii $ get GlobalConfig pure $ if ascii then "ZzZ" else "💤" export qmark : State GlobalConfig Global e => App e String qmark = do ascii <- map ascii $ get GlobalConfig pure $ if ascii then "?" else "❓" export bold : State GlobalConfig Global e => App e (String -> String) bold = do c <- map colour $ get GlobalConfig pure $ if c then (show . bolden) else id export yellow : State GlobalConfig Global e => App e (String -> String) yellow = do c <- map colour $ get GlobalConfig pure $ if c then (show . colored Yellow) else id export green : State GlobalConfig Global e => App e (String -> String) green = do c <- map colour $ get GlobalConfig pure $ if c then (show . colored Green) else id export red : State GlobalConfig Global e => App e (String -> String) red = do c <- map colour $ get GlobalConfig pure $ if c then (show . colored Red) else id export blue : State GlobalConfig Global e => App e (String -> String) blue = do c <- map colour $ get GlobalConfig pure $ if c then (show . colored BrightBlue) else id
module Numeral.Natural.Relation.Proofs where open import Data open import Functional open import Numeral.Natural open import Numeral.Natural.Relation open import Numeral.Natural.Relation.Order open import Numeral.Natural.Relation.Order.Proofs open import Logic.Propositional open import Logic.Propositional.Theorems import Lvl open import Relator.Equals open import Type private variable n : ℕ Positive-non-zero : Positive(n) ↔ (n ≢ 𝟎) Positive-non-zero {𝟎} = [↔]-intro (apply [≡]-intro) \() Positive-non-zero {𝐒 n} = [↔]-intro (const <>) (const \()) Positive-greater-than-zero : Positive(n) ↔ (n > 𝟎) Positive-greater-than-zero = [↔]-transitivity Positive-non-zero ([↔]-intro [>]-to-[≢] [≢]-to-[<]-of-0ᵣ)
using KeplerTools using ProfileView include(joinpath(@__DIR__, "..", "data", "kerbol_system.jl")) stime1, stime2 = 0., 852. * 6. * 3600. ftime1, ftime2 = 151. * 6. * 3600., 453. * 6. * 3600. startorb = Orbit(kerbin.eqradius + 100000, kerbin) endorb = Orbit(duna.eqradius + 100000, duna) ProfileView.@profview pc = Porkchop(startorb, endorb, stime1, stime2, ftime1, ftime2; npts=100) ProfileView.@profview qpc = fastPorkchop(startorb, endorb, stime1, stime2, ftime1, ftime2; npts=100)
lemma bigger_prime: "\<exists>p. prime p \<and> p > (n::nat)"
[GOAL] α : Type u_1 β : Type u_2 l✝ : Filter α k✝ f g g' : α → β inst✝¹ : TopologicalSpace β inst✝ : CommSemiring β l : Filter α k : α → β z : ℕ ⊢ Tendsto (fun a => k a ^ z * OfNat.ofNat 0 a) l (𝓝 0) [PROOFSTEP] simpa only [Pi.zero_apply, mul_zero] using tendsto_const_nhds [GOAL] α : Type u_1 β : Type u_2 l : Filter α k f g g' : α → β inst✝² : TopologicalSpace β inst✝¹ : CommSemiring β inst✝ : ContinuousAdd β hf : SuperpolynomialDecay l k f hg : SuperpolynomialDecay l k g z : ℕ ⊢ Tendsto (fun a => k a ^ z * (f + g) a) l (𝓝 0) [PROOFSTEP] simpa only [mul_add, add_zero, Pi.add_apply] using (hf z).add (hg z) [GOAL] α : Type u_1 β : Type u_2 l : Filter α k f g g' : α → β inst✝² : TopologicalSpace β inst✝¹ : CommSemiring β inst✝ : ContinuousMul β hf : SuperpolynomialDecay l k f hg : SuperpolynomialDecay l k g z : ℕ ⊢ Tendsto (fun a => k a ^ z * (f * g) a) l (𝓝 0) [PROOFSTEP] simpa only [mul_assoc, one_mul, mul_zero, pow_zero] using (hf z).mul (hg 0) [GOAL] α : Type u_1 β : Type u_2 l : Filter α k f g g' : α → β inst✝² : TopologicalSpace β inst✝¹ : CommSemiring β inst✝ : ContinuousMul β hf : SuperpolynomialDecay l k f c : β z : ℕ ⊢ Tendsto (fun a => k a ^ z * (fun n => f n * c) a) l (𝓝 0) [PROOFSTEP] simpa only [← mul_assoc, zero_mul] using Tendsto.mul_const c (hf z) [GOAL] α : Type u_1 β : Type u_2 l : Filter α k f g g' : α → β inst✝¹ : TopologicalSpace β inst✝ : CommSemiring β hf : SuperpolynomialDecay l k f z : ℕ s : Set β hs : IsOpen s hs0 : 0 ∈ s x : α hx : x ∈ (fun a => k a ^ (z + 1) * f a) ⁻¹' s ⊢ x ∈ (fun a => k a ^ z * (k * f) a) ⁻¹' s [PROOFSTEP] simpa only [Set.mem_preimage, Pi.mul_apply, ← mul_assoc, ← pow_succ'] using hx [GOAL] α : Type u_1 β : Type u_2 l : Filter α k f g g' : α → β inst✝¹ : TopologicalSpace β inst✝ : CommSemiring β hf : SuperpolynomialDecay l k f n : ℕ ⊢ SuperpolynomialDecay l k (k ^ n * f) [PROOFSTEP] induction' n with n hn [GOAL] case zero α : Type u_1 β : Type u_2 l : Filter α k f g g' : α → β inst✝¹ : TopologicalSpace β inst✝ : CommSemiring β hf : SuperpolynomialDecay l k f ⊢ SuperpolynomialDecay l k (k ^ Nat.zero * f) [PROOFSTEP] simpa only [Nat.zero_eq, one_mul, pow_zero] using hf [GOAL] case succ α : Type u_1 β : Type u_2 l : Filter α k f g g' : α → β inst✝¹ : TopologicalSpace β inst✝ : CommSemiring β hf : SuperpolynomialDecay l k f n : ℕ hn : SuperpolynomialDecay l k (k ^ n * f) ⊢ SuperpolynomialDecay l k (k ^ Nat.succ n * f) [PROOFSTEP] simpa only [pow_succ, mul_assoc] using hn.param_mul [GOAL] α : Type u_1 β : Type u_2 l : Filter α k f g g' : α → β inst✝³ : TopologicalSpace β inst✝² : CommSemiring β inst✝¹ : ContinuousAdd β inst✝ : ContinuousMul β hf : SuperpolynomialDecay l k f p✝ p q : β[X] hp : SuperpolynomialDecay l k fun x => eval (k x) p * f x hq : SuperpolynomialDecay l k fun x => eval (k x) q * f x ⊢ SuperpolynomialDecay l k fun x => eval (k x) (p + q) * f x [PROOFSTEP] simpa [add_mul] using hp.add hq [GOAL] α : Type u_1 β : Type u_2 l : Filter α k f g g' : α → β inst✝³ : TopologicalSpace β inst✝² : CommSemiring β inst✝¹ : ContinuousAdd β inst✝ : ContinuousMul β hf : SuperpolynomialDecay l k f p : β[X] n : ℕ c : β ⊢ SuperpolynomialDecay l k fun x => eval (k x) (↑(monomial n) c) * f x [PROOFSTEP] simpa [mul_assoc] using (hf.param_pow_mul n).const_mul c [GOAL] α : Type u_1 β : Type u_2 l : Filter α k f g g' : α → β inst✝² : TopologicalSpace β inst✝¹ : LinearOrderedCommRing β inst✝ : OrderTopology β ⊢ (∀ (n : ℕ), Tendsto (fun a => |k a ^ n * f a|) l (𝓝 0)) ↔ SuperpolynomialDecay l (fun a => |k a|) fun a => |f a| [PROOFSTEP] simp_rw [SuperpolynomialDecay, abs_mul, abs_pow] [GOAL] α : Type u_1 β : Type u_2 l : Filter α k f g g' : α → β inst✝² : TopologicalSpace β inst✝¹ : LinearOrderedCommRing β inst✝ : OrderTopology β hf : SuperpolynomialDecay l k f hfg : abs ∘ g ≤ᶠ[l] abs ∘ f ⊢ SuperpolynomialDecay l k g [PROOFSTEP] rw [superpolynomialDecay_iff_abs_tendsto_zero] at hf ⊢ [GOAL] α : Type u_1 β : Type u_2 l : Filter α k f g g' : α → β inst✝² : TopologicalSpace β inst✝¹ : LinearOrderedCommRing β inst✝ : OrderTopology β hf : ∀ (n : ℕ), Tendsto (fun a => |k a ^ n * f a|) l (𝓝 0) hfg : abs ∘ g ≤ᶠ[l] abs ∘ f ⊢ ∀ (n : ℕ), Tendsto (fun a => |k a ^ n * g a|) l (𝓝 0) [PROOFSTEP] refine' fun z => tendsto_of_tendsto_of_tendsto_of_le_of_le' tendsto_const_nhds (hf z) (eventually_of_forall fun x => abs_nonneg _) (hfg.mono fun x hx => _) [GOAL] α : Type u_1 β : Type u_2 l : Filter α k f g g' : α → β inst✝² : TopologicalSpace β inst✝¹ : LinearOrderedCommRing β inst✝ : OrderTopology β hf : ∀ (n : ℕ), Tendsto (fun a => |k a ^ n * f a|) l (𝓝 0) hfg : abs ∘ g ≤ᶠ[l] abs ∘ f z : ℕ x : α hx : (abs ∘ g) x ≤ (abs ∘ f) x ⊢ |k x ^ z * g x| ≤ |k x ^ z * f x| [PROOFSTEP] calc |k x ^ z * g x| = |k x ^ z| * |g x| := abs_mul (k x ^ z) (g x) _ ≤ |k x ^ z| * |f x| := by gcongr; exact hx _ = |k x ^ z * f x| := (abs_mul (k x ^ z) (f x)).symm [GOAL] α : Type u_1 β : Type u_2 l : Filter α k f g g' : α → β inst✝² : TopologicalSpace β inst✝¹ : LinearOrderedCommRing β inst✝ : OrderTopology β hf : ∀ (n : ℕ), Tendsto (fun a => |k a ^ n * f a|) l (𝓝 0) hfg : abs ∘ g ≤ᶠ[l] abs ∘ f z : ℕ x : α hx : (abs ∘ g) x ≤ (abs ∘ f) x ⊢ |k x ^ z| * |g x| ≤ |k x ^ z| * |f x| [PROOFSTEP] gcongr [GOAL] case h α : Type u_1 β : Type u_2 l : Filter α k f g g' : α → β inst✝² : TopologicalSpace β inst✝¹ : LinearOrderedCommRing β inst✝ : OrderTopology β hf : ∀ (n : ℕ), Tendsto (fun a => |k a ^ n * f a|) l (𝓝 0) hfg : abs ∘ g ≤ᶠ[l] abs ∘ f z : ℕ x : α hx : (abs ∘ g) x ≤ (abs ∘ f) x ⊢ |g x| ≤ |f x| [PROOFSTEP] exact hx [GOAL] α : Type u_1 β : Type u_2 l : Filter α k f g g' : α → β inst✝² : TopologicalSpace β inst✝¹ : Field β inst✝ : ContinuousMul β c : β hc0 : c ≠ 0 h : SuperpolynomialDecay l k fun n => f n * c x : α ⊢ f x * c * c⁻¹ = f x [PROOFSTEP] simp [mul_assoc, mul_inv_cancel hc0] [GOAL] α : Type u_1 β : Type u_2 l : Filter α k f g g' : α → β inst✝² : TopologicalSpace β inst✝¹ : Field β inst✝ : ContinuousMul β c : β hc0 : c ≠ 0 h : SuperpolynomialDecay l k fun n => c * f n x : α ⊢ c⁻¹ * (c * f x) = f x [PROOFSTEP] simp [← mul_assoc, inv_mul_cancel hc0] [GOAL] α : Type u_1 β : Type u_2 l : Filter α k f g g' : α → β inst✝² : TopologicalSpace β inst✝¹ : LinearOrderedField β inst✝ : OrderTopology β hk : Tendsto k l atTop ⊢ SuperpolynomialDecay l k f ↔ ∀ (z : ℕ), IsBoundedUnder (fun x x_1 => x ≤ x_1) l fun a => |k a ^ z * f a| [PROOFSTEP] refine' ⟨fun h z => Tendsto.isBoundedUnder_le (Tendsto.abs (h z)), fun h => (superpolynomialDecay_iff_abs_tendsto_zero l k f).2 fun z => _⟩ [GOAL] α : Type u_1 β : Type u_2 l : Filter α k f g g' : α → β inst✝² : TopologicalSpace β inst✝¹ : LinearOrderedField β inst✝ : OrderTopology β hk : Tendsto k l atTop h : ∀ (z : ℕ), IsBoundedUnder (fun x x_1 => x ≤ x_1) l fun a => |k a ^ z * f a| z : ℕ ⊢ Tendsto (fun a => |k a ^ z * f a|) l (𝓝 0) [PROOFSTEP] obtain ⟨m, hm⟩ := h (z + 1) [GOAL] case intro α : Type u_1 β : Type u_2 l : Filter α k f g g' : α → β inst✝² : TopologicalSpace β inst✝¹ : LinearOrderedField β inst✝ : OrderTopology β hk : Tendsto k l atTop h : ∀ (z : ℕ), IsBoundedUnder (fun x x_1 => x ≤ x_1) l fun a => |k a ^ z * f a| z : ℕ m : β hm : ∀ᶠ (x : β) in Filter.map (fun a => |k a ^ (z + 1) * f a|) l, (fun x x_1 => x ≤ x_1) x m ⊢ Tendsto (fun a => |k a ^ z * f a|) l (𝓝 0) [PROOFSTEP] have h1 : Tendsto (fun _ : α => (0 : β)) l (𝓝 0) := tendsto_const_nhds [GOAL] case intro α : Type u_1 β : Type u_2 l : Filter α k f g g' : α → β inst✝² : TopologicalSpace β inst✝¹ : LinearOrderedField β inst✝ : OrderTopology β hk : Tendsto k l atTop h : ∀ (z : ℕ), IsBoundedUnder (fun x x_1 => x ≤ x_1) l fun a => |k a ^ z * f a| z : ℕ m : β hm : ∀ᶠ (x : β) in Filter.map (fun a => |k a ^ (z + 1) * f a|) l, (fun x x_1 => x ≤ x_1) x m h1 : Tendsto (fun x => 0) l (𝓝 0) ⊢ Tendsto (fun a => |k a ^ z * f a|) l (𝓝 0) [PROOFSTEP] have h2 : Tendsto (fun a : α => |(k a)⁻¹| * m) l (𝓝 0) := zero_mul m ▸ Tendsto.mul_const m ((tendsto_zero_iff_abs_tendsto_zero _).1 hk.inv_tendsto_atTop) [GOAL] case intro α : Type u_1 β : Type u_2 l : Filter α k f g g' : α → β inst✝² : TopologicalSpace β inst✝¹ : LinearOrderedField β inst✝ : OrderTopology β hk : Tendsto k l atTop h : ∀ (z : ℕ), IsBoundedUnder (fun x x_1 => x ≤ x_1) l fun a => |k a ^ z * f a| z : ℕ m : β hm : ∀ᶠ (x : β) in Filter.map (fun a => |k a ^ (z + 1) * f a|) l, (fun x x_1 => x ≤ x_1) x m h1 : Tendsto (fun x => 0) l (𝓝 0) h2 : Tendsto (fun a => |(k a)⁻¹| * m) l (𝓝 0) ⊢ Tendsto (fun a => |k a ^ z * f a|) l (𝓝 0) [PROOFSTEP] refine' tendsto_of_tendsto_of_tendsto_of_le_of_le' h1 h2 (eventually_of_forall fun x => abs_nonneg _) ((eventually_map.1 hm).mp _) [GOAL] case intro α : Type u_1 β : Type u_2 l : Filter α k f g g' : α → β inst✝² : TopologicalSpace β inst✝¹ : LinearOrderedField β inst✝ : OrderTopology β hk : Tendsto k l atTop h : ∀ (z : ℕ), IsBoundedUnder (fun x x_1 => x ≤ x_1) l fun a => |k a ^ z * f a| z : ℕ m : β hm : ∀ᶠ (x : β) in Filter.map (fun a => |k a ^ (z + 1) * f a|) l, (fun x x_1 => x ≤ x_1) x m h1 : Tendsto (fun x => 0) l (𝓝 0) h2 : Tendsto (fun a => |(k a)⁻¹| * m) l (𝓝 0) ⊢ ∀ᶠ (x : α) in l, (fun x x_1 => x ≤ x_1) |k x ^ (z + 1) * f x| m → |k x ^ z * f x| ≤ |(k x)⁻¹| * m [PROOFSTEP] refine' (hk.eventually_ne_atTop 0).mono fun x hk0 hx => _ [GOAL] case intro α : Type u_1 β : Type u_2 l : Filter α k f g g' : α → β inst✝² : TopologicalSpace β inst✝¹ : LinearOrderedField β inst✝ : OrderTopology β hk : Tendsto k l atTop h : ∀ (z : ℕ), IsBoundedUnder (fun x x_1 => x ≤ x_1) l fun a => |k a ^ z * f a| z : ℕ m : β hm : ∀ᶠ (x : β) in Filter.map (fun a => |k a ^ (z + 1) * f a|) l, (fun x x_1 => x ≤ x_1) x m h1 : Tendsto (fun x => 0) l (𝓝 0) h2 : Tendsto (fun a => |(k a)⁻¹| * m) l (𝓝 0) x : α hk0 : k x ≠ 0 hx : (fun x x_1 => x ≤ x_1) |k x ^ (z + 1) * f x| m ⊢ |k x ^ z * f x| ≤ |(k x)⁻¹| * m [PROOFSTEP] refine' Eq.trans_le _ (mul_le_mul_of_nonneg_left hx <| abs_nonneg (k x)⁻¹) [GOAL] case intro α : Type u_1 β : Type u_2 l : Filter α k f g g' : α → β inst✝² : TopologicalSpace β inst✝¹ : LinearOrderedField β inst✝ : OrderTopology β hk : Tendsto k l atTop h : ∀ (z : ℕ), IsBoundedUnder (fun x x_1 => x ≤ x_1) l fun a => |k a ^ z * f a| z : ℕ m : β hm : ∀ᶠ (x : β) in Filter.map (fun a => |k a ^ (z + 1) * f a|) l, (fun x x_1 => x ≤ x_1) x m h1 : Tendsto (fun x => 0) l (𝓝 0) h2 : Tendsto (fun a => |(k a)⁻¹| * m) l (𝓝 0) x : α hk0 : k x ≠ 0 hx : (fun x x_1 => x ≤ x_1) |k x ^ (z + 1) * f x| m ⊢ |k x ^ z * f x| = |(k x)⁻¹| * |k x ^ (z + 1) * f x| [PROOFSTEP] rw [← abs_mul, ← mul_assoc, pow_succ, ← mul_assoc, inv_mul_cancel hk0, one_mul] [GOAL] α : Type u_1 β : Type u_2 l : Filter α k f g g' : α → β inst✝² : TopologicalSpace β inst✝¹ : LinearOrderedField β inst✝ : OrderTopology β hk : Tendsto k l atTop ⊢ SuperpolynomialDecay l k f ↔ ∀ (z : ℤ), Tendsto (fun a => k a ^ z * f a) l (𝓝 0) [PROOFSTEP] refine' ⟨fun h z => _, fun h n => by simpa only [zpow_ofNat] using h (n : ℤ)⟩ [GOAL] α : Type u_1 β : Type u_2 l : Filter α k f g g' : α → β inst✝² : TopologicalSpace β inst✝¹ : LinearOrderedField β inst✝ : OrderTopology β hk : Tendsto k l atTop h : ∀ (z : ℤ), Tendsto (fun a => k a ^ z * f a) l (𝓝 0) n : ℕ ⊢ Tendsto (fun a => k a ^ n * f a) l (𝓝 0) [PROOFSTEP] simpa only [zpow_ofNat] using h (n : ℤ) [GOAL] α : Type u_1 β : Type u_2 l : Filter α k f g g' : α → β inst✝² : TopologicalSpace β inst✝¹ : LinearOrderedField β inst✝ : OrderTopology β hk : Tendsto k l atTop h : SuperpolynomialDecay l k f z : ℤ ⊢ Tendsto (fun a => k a ^ z * f a) l (𝓝 0) [PROOFSTEP] by_cases hz : 0 ≤ z [GOAL] case pos α : Type u_1 β : Type u_2 l : Filter α k f g g' : α → β inst✝² : TopologicalSpace β inst✝¹ : LinearOrderedField β inst✝ : OrderTopology β hk : Tendsto k l atTop h : SuperpolynomialDecay l k f z : ℤ hz : 0 ≤ z ⊢ Tendsto (fun a => k a ^ z * f a) l (𝓝 0) [PROOFSTEP] unfold Tendsto [GOAL] case pos α : Type u_1 β : Type u_2 l : Filter α k f g g' : α → β inst✝² : TopologicalSpace β inst✝¹ : LinearOrderedField β inst✝ : OrderTopology β hk : Tendsto k l atTop h : SuperpolynomialDecay l k f z : ℤ hz : 0 ≤ z ⊢ Filter.map (fun a => k a ^ z * f a) l ≤ 𝓝 0 [PROOFSTEP] lift z to ℕ using hz [GOAL] case pos.intro α : Type u_1 β : Type u_2 l : Filter α k f g g' : α → β inst✝² : TopologicalSpace β inst✝¹ : LinearOrderedField β inst✝ : OrderTopology β hk : Tendsto k l atTop h : SuperpolynomialDecay l k f z : ℕ ⊢ Filter.map (fun a => k a ^ ↑z * f a) l ≤ 𝓝 0 [PROOFSTEP] simpa using h z [GOAL] case neg α : Type u_1 β : Type u_2 l : Filter α k f g g' : α → β inst✝² : TopologicalSpace β inst✝¹ : LinearOrderedField β inst✝ : OrderTopology β hk : Tendsto k l atTop h : SuperpolynomialDecay l k f z : ℤ hz : ¬0 ≤ z ⊢ Tendsto (fun a => k a ^ z * f a) l (𝓝 0) [PROOFSTEP] have : Tendsto (fun a => k a ^ z) l (𝓝 0) := Tendsto.comp (tendsto_zpow_atTop_zero (not_le.1 hz)) hk [GOAL] case neg α : Type u_1 β : Type u_2 l : Filter α k f g g' : α → β inst✝² : TopologicalSpace β inst✝¹ : LinearOrderedField β inst✝ : OrderTopology β hk : Tendsto k l atTop h : SuperpolynomialDecay l k f z : ℤ hz : ¬0 ≤ z this : Tendsto (fun a => k a ^ z) l (𝓝 0) ⊢ Tendsto (fun a => k a ^ z * f a) l (𝓝 0) [PROOFSTEP] have h : Tendsto f l (𝓝 0) := by simpa using h 0 [GOAL] α : Type u_1 β : Type u_2 l : Filter α k f g g' : α → β inst✝² : TopologicalSpace β inst✝¹ : LinearOrderedField β inst✝ : OrderTopology β hk : Tendsto k l atTop h : SuperpolynomialDecay l k f z : ℤ hz : ¬0 ≤ z this : Tendsto (fun a => k a ^ z) l (𝓝 0) ⊢ Tendsto f l (𝓝 0) [PROOFSTEP] simpa using h 0 [GOAL] case neg α : Type u_1 β : Type u_2 l : Filter α k f g g' : α → β inst✝² : TopologicalSpace β inst✝¹ : LinearOrderedField β inst✝ : OrderTopology β hk : Tendsto k l atTop h✝ : SuperpolynomialDecay l k f z : ℤ hz : ¬0 ≤ z this : Tendsto (fun a => k a ^ z) l (𝓝 0) h : Tendsto f l (𝓝 0) ⊢ Tendsto (fun a => k a ^ z * f a) l (𝓝 0) [PROOFSTEP] exact zero_mul (0 : β) ▸ this.mul h [GOAL] α : Type u_1 β : Type u_2 l : Filter α k f g g' : α → β inst✝² : TopologicalSpace β inst✝¹ : LinearOrderedField β inst✝ : OrderTopology β hk : Tendsto k l atTop hf : SuperpolynomialDecay l k f z : ℤ ⊢ SuperpolynomialDecay l k fun a => k a ^ z * f a [PROOFSTEP] rw [superpolynomialDecay_iff_zpow_tendsto_zero _ hk] at hf ⊢ [GOAL] α : Type u_1 β : Type u_2 l : Filter α k f g g' : α → β inst✝² : TopologicalSpace β inst✝¹ : LinearOrderedField β inst✝ : OrderTopology β hk : Tendsto k l atTop hf : ∀ (z : ℤ), Tendsto (fun a => k a ^ z * f a) l (𝓝 0) z : ℤ ⊢ ∀ (z_1 : ℤ), Tendsto (fun a => k a ^ z_1 * (k a ^ z * f a)) l (𝓝 0) [PROOFSTEP] refine' fun z' => (hf <| z' + z).congr' ((hk.eventually_ne_atTop 0).mono fun x hx => _) [GOAL] α : Type u_1 β : Type u_2 l : Filter α k f g g' : α → β inst✝² : TopologicalSpace β inst✝¹ : LinearOrderedField β inst✝ : OrderTopology β hk : Tendsto k l atTop hf : ∀ (z : ℤ), Tendsto (fun a => k a ^ z * f a) l (𝓝 0) z z' : ℤ x : α hx : k x ≠ 0 ⊢ k x ^ (z' + z) * f x = (fun a => k a ^ z' * (k a ^ z * f a)) x [PROOFSTEP] simp [zpow_add₀ hx, mul_assoc, Pi.mul_apply] [GOAL] α : Type u_1 β : Type u_2 l : Filter α k f g g' : α → β inst✝² : TopologicalSpace β inst✝¹ : LinearOrderedField β inst✝ : OrderTopology β hk : Tendsto k l atTop hf : SuperpolynomialDecay l k f ⊢ SuperpolynomialDecay l k (k⁻¹ * f) [PROOFSTEP] simpa using hf.param_zpow_mul hk (-1) [GOAL] α : Type u_1 β : Type u_2 l : Filter α k f g g' : α → β inst✝² : TopologicalSpace β inst✝¹ : LinearOrderedField β inst✝ : OrderTopology β hk : Tendsto k l atTop h : SuperpolynomialDecay l k (k * f) x : α hx : k x ≠ 0 ⊢ (k⁻¹ * (k * f)) x = f x [PROOFSTEP] simp [← mul_assoc, inv_mul_cancel hx] [GOAL] α : Type u_1 β : Type u_2 l : Filter α k f g g' : α → β inst✝² : TopologicalSpace β inst✝¹ : LinearOrderedField β inst✝ : OrderTopology β hk : Tendsto k l atTop ⊢ SuperpolynomialDecay l k (f * k) ↔ SuperpolynomialDecay l k f [PROOFSTEP] simpa [mul_comm k] using superpolynomialDecay_param_mul_iff f hk [GOAL] α : Type u_1 β : Type u_2 l : Filter α k f g g' : α → β inst✝² : TopologicalSpace β inst✝¹ : LinearOrderedField β inst✝ : OrderTopology β hk : Tendsto k l atTop n : ℕ ⊢ SuperpolynomialDecay l k (k ^ n * f) ↔ SuperpolynomialDecay l k f [PROOFSTEP] induction' n with n hn [GOAL] case zero α : Type u_1 β : Type u_2 l : Filter α k f g g' : α → β inst✝² : TopologicalSpace β inst✝¹ : LinearOrderedField β inst✝ : OrderTopology β hk : Tendsto k l atTop ⊢ SuperpolynomialDecay l k (k ^ Nat.zero * f) ↔ SuperpolynomialDecay l k f [PROOFSTEP] simp [GOAL] case succ α : Type u_1 β : Type u_2 l : Filter α k f g g' : α → β inst✝² : TopologicalSpace β inst✝¹ : LinearOrderedField β inst✝ : OrderTopology β hk : Tendsto k l atTop n : ℕ hn : SuperpolynomialDecay l k (k ^ n * f) ↔ SuperpolynomialDecay l k f ⊢ SuperpolynomialDecay l k (k ^ Nat.succ n * f) ↔ SuperpolynomialDecay l k f [PROOFSTEP] simpa [pow_succ, ← mul_comm k, mul_assoc, superpolynomialDecay_param_mul_iff (k ^ n * f) hk] using hn [GOAL] α : Type u_1 β : Type u_2 l : Filter α k f g g' : α → β inst✝² : TopologicalSpace β inst✝¹ : LinearOrderedField β inst✝ : OrderTopology β hk : Tendsto k l atTop n : ℕ ⊢ SuperpolynomialDecay l k (f * k ^ n) ↔ SuperpolynomialDecay l k f [PROOFSTEP] simpa [mul_comm f] using superpolynomialDecay_param_pow_mul_iff f hk n [GOAL] α : Type u_1 β : Type u_2 l : Filter α k f g g' : α → β inst✝ : NormedLinearOrderedField β ⊢ (∀ (n : ℕ), Tendsto (fun a => ‖k a ^ n * f a‖) l (𝓝 0)) ↔ SuperpolynomialDecay l (fun a => ‖k a‖) fun a => ‖f a‖ [PROOFSTEP] simp [SuperpolynomialDecay] [GOAL] α : Type u_1 β : Type u_2 l : Filter α k f g g' : α → β inst✝¹ : NormedLinearOrderedField β inst✝ : OrderTopology β hk : Tendsto k l atTop ⊢ SuperpolynomialDecay l k f ↔ ∀ (z : ℤ), f =O[l] fun a => k a ^ z [PROOFSTEP] refine' (superpolynomialDecay_iff_zpow_tendsto_zero f hk).trans _ [GOAL] α : Type u_1 β : Type u_2 l : Filter α k f g g' : α → β inst✝¹ : NormedLinearOrderedField β inst✝ : OrderTopology β hk : Tendsto k l atTop ⊢ (∀ (z : ℤ), Tendsto (fun a => k a ^ z * f a) l (𝓝 0)) ↔ ∀ (z : ℤ), f =O[l] fun a => k a ^ z [PROOFSTEP] have hk0 : ∀ᶠ x in l, k x ≠ 0 := hk.eventually_ne_atTop 0 [GOAL] α : Type u_1 β : Type u_2 l : Filter α k f g g' : α → β inst✝¹ : NormedLinearOrderedField β inst✝ : OrderTopology β hk : Tendsto k l atTop hk0 : ∀ᶠ (x : α) in l, k x ≠ 0 ⊢ (∀ (z : ℤ), Tendsto (fun a => k a ^ z * f a) l (𝓝 0)) ↔ ∀ (z : ℤ), f =O[l] fun a => k a ^ z [PROOFSTEP] refine' ⟨fun h z => _, fun h z => _⟩ [GOAL] case refine'_1 α : Type u_1 β : Type u_2 l : Filter α k f g g' : α → β inst✝¹ : NormedLinearOrderedField β inst✝ : OrderTopology β hk : Tendsto k l atTop hk0 : ∀ᶠ (x : α) in l, k x ≠ 0 h : ∀ (z : ℤ), Tendsto (fun a => k a ^ z * f a) l (𝓝 0) z : ℤ ⊢ f =O[l] fun a => k a ^ z [PROOFSTEP] refine' isBigO_of_div_tendsto_nhds (hk0.mono fun x hx hxz => absurd (zpow_eq_zero hxz) hx) 0 _ [GOAL] case refine'_1 α : Type u_1 β : Type u_2 l : Filter α k f g g' : α → β inst✝¹ : NormedLinearOrderedField β inst✝ : OrderTopology β hk : Tendsto k l atTop hk0 : ∀ᶠ (x : α) in l, k x ≠ 0 h : ∀ (z : ℤ), Tendsto (fun a => k a ^ z * f a) l (𝓝 0) z : ℤ ⊢ Tendsto (f / fun a => k a ^ z) l (𝓝 0) [PROOFSTEP] have : (fun a : α => k a ^ z)⁻¹ = fun a : α => k a ^ (-z) := funext fun x => by simp [GOAL] α : Type u_1 β : Type u_2 l : Filter α k f g g' : α → β inst✝¹ : NormedLinearOrderedField β inst✝ : OrderTopology β hk : Tendsto k l atTop hk0 : ∀ᶠ (x : α) in l, k x ≠ 0 h : ∀ (z : ℤ), Tendsto (fun a => k a ^ z * f a) l (𝓝 0) z : ℤ x : α ⊢ (fun a => k a ^ z)⁻¹ x = k x ^ (-z) [PROOFSTEP] simp [GOAL] case refine'_1 α : Type u_1 β : Type u_2 l : Filter α k f g g' : α → β inst✝¹ : NormedLinearOrderedField β inst✝ : OrderTopology β hk : Tendsto k l atTop hk0 : ∀ᶠ (x : α) in l, k x ≠ 0 h : ∀ (z : ℤ), Tendsto (fun a => k a ^ z * f a) l (𝓝 0) z : ℤ this : (fun a => k a ^ z)⁻¹ = fun a => k a ^ (-z) ⊢ Tendsto (f / fun a => k a ^ z) l (𝓝 0) [PROOFSTEP] rw [div_eq_mul_inv, mul_comm f, this] [GOAL] case refine'_1 α : Type u_1 β : Type u_2 l : Filter α k f g g' : α → β inst✝¹ : NormedLinearOrderedField β inst✝ : OrderTopology β hk : Tendsto k l atTop hk0 : ∀ᶠ (x : α) in l, k x ≠ 0 h : ∀ (z : ℤ), Tendsto (fun a => k a ^ z * f a) l (𝓝 0) z : ℤ this : (fun a => k a ^ z)⁻¹ = fun a => k a ^ (-z) ⊢ Tendsto ((fun a => k a ^ (-z)) * f) l (𝓝 0) [PROOFSTEP] exact h (-z) [GOAL] case refine'_2 α : Type u_1 β : Type u_2 l : Filter α k f g g' : α → β inst✝¹ : NormedLinearOrderedField β inst✝ : OrderTopology β hk : Tendsto k l atTop hk0 : ∀ᶠ (x : α) in l, k x ≠ 0 h : ∀ (z : ℤ), f =O[l] fun a => k a ^ z z : ℤ ⊢ Tendsto (fun a => k a ^ z * f a) l (𝓝 0) [PROOFSTEP] suffices : (fun a : α => k a ^ z * f a) =O[l] fun a : α => (k a)⁻¹ [GOAL] case refine'_2 α : Type u_1 β : Type u_2 l : Filter α k f g g' : α → β inst✝¹ : NormedLinearOrderedField β inst✝ : OrderTopology β hk : Tendsto k l atTop hk0 : ∀ᶠ (x : α) in l, k x ≠ 0 h : ∀ (z : ℤ), f =O[l] fun a => k a ^ z z : ℤ this : (fun a => k a ^ z * f a) =O[l] fun a => (k a)⁻¹ ⊢ Tendsto (fun a => k a ^ z * f a) l (𝓝 0) case this α : Type u_1 β : Type u_2 l : Filter α k f g g' : α → β inst✝¹ : NormedLinearOrderedField β inst✝ : OrderTopology β hk : Tendsto k l atTop hk0 : ∀ᶠ (x : α) in l, k x ≠ 0 h : ∀ (z : ℤ), f =O[l] fun a => k a ^ z z : ℤ ⊢ (fun a => k a ^ z * f a) =O[l] fun a => (k a)⁻¹ [PROOFSTEP] exact IsBigO.trans_tendsto this hk.inv_tendsto_atTop [GOAL] case this α : Type u_1 β : Type u_2 l : Filter α k f g g' : α → β inst✝¹ : NormedLinearOrderedField β inst✝ : OrderTopology β hk : Tendsto k l atTop hk0 : ∀ᶠ (x : α) in l, k x ≠ 0 h : ∀ (z : ℤ), f =O[l] fun a => k a ^ z z : ℤ ⊢ (fun a => k a ^ z * f a) =O[l] fun a => (k a)⁻¹ [PROOFSTEP] refine' ((isBigO_refl (fun a => k a ^ z) l).mul (h (-(z + 1)))).trans (IsBigO.of_bound 1 <| hk0.mono fun a ha0 => _) [GOAL] case this α : Type u_1 β : Type u_2 l : Filter α k f g g' : α → β inst✝¹ : NormedLinearOrderedField β inst✝ : OrderTopology β hk : Tendsto k l atTop hk0 : ∀ᶠ (x : α) in l, k x ≠ 0 h : ∀ (z : ℤ), f =O[l] fun a => k a ^ z z : ℤ a : α ha0 : k a ≠ 0 ⊢ ‖k a ^ z * k a ^ (-(z + 1))‖ ≤ 1 * ‖(k a)⁻¹‖ [PROOFSTEP] simp only [one_mul, neg_add z 1, zpow_add₀ ha0, ← mul_assoc, zpow_neg, mul_inv_cancel (zpow_ne_zero z ha0), zpow_one] [GOAL] case this α : Type u_1 β : Type u_2 l : Filter α k f g g' : α → β inst✝¹ : NormedLinearOrderedField β inst✝ : OrderTopology β hk : Tendsto k l atTop hk0 : ∀ᶠ (x : α) in l, k x ≠ 0 h : ∀ (z : ℤ), f =O[l] fun a => k a ^ z z : ℤ a : α ha0 : k a ≠ 0 ⊢ ‖(k a)⁻¹‖ ≤ ‖(k a)⁻¹‖ [PROOFSTEP] rfl [GOAL] α : Type u_1 β : Type u_2 l : Filter α k f g g' : α → β inst✝¹ : NormedLinearOrderedField β inst✝ : OrderTopology β hk : Tendsto k l atTop ⊢ SuperpolynomialDecay l k f ↔ ∀ (z : ℤ), f =o[l] fun a => k a ^ z [PROOFSTEP] refine' ⟨fun h z => _, fun h => (superpolynomialDecay_iff_isBigO f hk).2 fun z => (h z).isBigO⟩ [GOAL] α : Type u_1 β : Type u_2 l : Filter α k f g g' : α → β inst✝¹ : NormedLinearOrderedField β inst✝ : OrderTopology β hk : Tendsto k l atTop h : SuperpolynomialDecay l k f z : ℤ ⊢ f =o[l] fun a => k a ^ z [PROOFSTEP] have hk0 : ∀ᶠ x in l, k x ≠ 0 := hk.eventually_ne_atTop 0 [GOAL] α : Type u_1 β : Type u_2 l : Filter α k f g g' : α → β inst✝¹ : NormedLinearOrderedField β inst✝ : OrderTopology β hk : Tendsto k l atTop h : SuperpolynomialDecay l k f z : ℤ hk0 : ∀ᶠ (x : α) in l, k x ≠ 0 ⊢ f =o[l] fun a => k a ^ z [PROOFSTEP] have : (fun _ : α => (1 : β)) =o[l] k := isLittleO_of_tendsto' (hk0.mono fun x hkx hkx' => absurd hkx' hkx) (by simpa using hk.inv_tendsto_atTop) [GOAL] α : Type u_1 β : Type u_2 l : Filter α k f g g' : α → β inst✝¹ : NormedLinearOrderedField β inst✝ : OrderTopology β hk : Tendsto k l atTop h : SuperpolynomialDecay l k f z : ℤ hk0 : ∀ᶠ (x : α) in l, k x ≠ 0 ⊢ Tendsto (fun x => 1 / k x) l (𝓝 0) [PROOFSTEP] simpa using hk.inv_tendsto_atTop [GOAL] α : Type u_1 β : Type u_2 l : Filter α k f g g' : α → β inst✝¹ : NormedLinearOrderedField β inst✝ : OrderTopology β hk : Tendsto k l atTop h : SuperpolynomialDecay l k f z : ℤ hk0 : ∀ᶠ (x : α) in l, k x ≠ 0 this : (fun x => 1) =o[l] k ⊢ f =o[l] fun a => k a ^ z [PROOFSTEP] have : f =o[l] fun x : α => k x * k x ^ (z - 1) := by simpa using this.mul_isBigO ((superpolynomialDecay_iff_isBigO f hk).1 h <| z - 1) [GOAL] α : Type u_1 β : Type u_2 l : Filter α k f g g' : α → β inst✝¹ : NormedLinearOrderedField β inst✝ : OrderTopology β hk : Tendsto k l atTop h : SuperpolynomialDecay l k f z : ℤ hk0 : ∀ᶠ (x : α) in l, k x ≠ 0 this : (fun x => 1) =o[l] k ⊢ f =o[l] fun x => k x * k x ^ (z - 1) [PROOFSTEP] simpa using this.mul_isBigO ((superpolynomialDecay_iff_isBigO f hk).1 h <| z - 1) [GOAL] α : Type u_1 β : Type u_2 l : Filter α k f g g' : α → β inst✝¹ : NormedLinearOrderedField β inst✝ : OrderTopology β hk : Tendsto k l atTop h : SuperpolynomialDecay l k f z : ℤ hk0 : ∀ᶠ (x : α) in l, k x ≠ 0 this✝ : (fun x => 1) =o[l] k this : f =o[l] fun x => k x * k x ^ (z - 1) ⊢ f =o[l] fun a => k a ^ z [PROOFSTEP] refine' this.trans_isBigO (IsBigO.of_bound 1 (hk0.mono fun x hkx => le_of_eq _)) [GOAL] α : Type u_1 β : Type u_2 l : Filter α k f g g' : α → β inst✝¹ : NormedLinearOrderedField β inst✝ : OrderTopology β hk : Tendsto k l atTop h : SuperpolynomialDecay l k f z : ℤ hk0 : ∀ᶠ (x : α) in l, k x ≠ 0 this✝ : (fun x => 1) =o[l] k this : f =o[l] fun x => k x * k x ^ (z - 1) x : α hkx : k x ≠ 0 ⊢ ‖k x * k x ^ (z - 1)‖ = 1 * ‖k x ^ z‖ [PROOFSTEP] rw [one_mul, zpow_sub_one₀ hkx, mul_comm (k x), mul_assoc, inv_mul_cancel hkx, mul_one]
We are constantly suggesting the best meals to eat and the ones to ignore for diabetics as well as suggesting low calorie food options. You can find selected restaurants offering diabetic meals as well as low calorie diet food options. if you are concerned about foods with high sugar or high cholesterol levels. You can also find instructions on picking the right food from the menus while looking for the best restaurants in Mescalero, NM. Very good food at a reasonable price. Service is very good. Atmosphere is classic Southwest. Recommend to anyone passing through. Okay now I have been here. Almost an hour to get Standard Plate lunches. Salsa had energetic flavor, but watery. Prefer Cafe de Suenos if going all the way to Tulie and Chileo's if not leaving Lincoln County. Interesting building......dangerous road. Just off highway 70 about a mile back is this quaint homey restaurant that serves good Mexican food. Service was a bit slow but overall it was a good experience .
(* Title: HOL/Auth/n_germanSimp_lemma_on_inv__49.thy Author: Yongjian Li and Kaiqiang Duan, State Key Lab of Computer Science, Institute of Software, Chinese Academy of Sciences Copyright 2016 State Key Lab of Computer Science, Institute of Software, Chinese Academy of Sciences *) header{*The n_germanSimp Protocol Case Study*} theory n_germanSimp_lemma_on_inv__49 imports n_germanSimp_base begin section{*All lemmas on causal relation between inv__49 and some rule r*} lemma n_RecvReqSVsinv__49: assumes a1: "(\<exists> i. i\<le>N\<and>r=n_RecvReqS N i)" and a2: "(\<exists> p__Inv3 p__Inv4. p__Inv3\<le>N\<and>p__Inv4\<le>N\<and>p__Inv3~=p__Inv4\<and>f=inv__49 p__Inv3 p__Inv4)" shows "invHoldForRule s f r (invariants N)" (is "?P1 s \<or> ?P2 s \<or> ?P3 s") proof - from a1 obtain i where a1:"i\<le>N\<and>r=n_RecvReqS N i" apply fastforce done from a2 obtain p__Inv3 p__Inv4 where a2:"p__Inv3\<le>N\<and>p__Inv4\<le>N\<and>p__Inv3~=p__Inv4\<and>f=inv__49 p__Inv3 p__Inv4" apply fastforce done have "(i=p__Inv4)\<or>(i=p__Inv3)\<or>(i~=p__Inv3\<and>i~=p__Inv4)" apply (cut_tac a1 a2, auto) done moreover { assume b1: "(i=p__Inv4)" have "?P3 s" apply (cut_tac a1 a2 b1, simp, rule_tac x="(neg (andForm (eqn (IVar (Field (Para (Ident ''Chan3'') p__Inv3) ''Cmd'')) (Const InvAck)) (eqn (IVar (Ident ''CurCmd'')) (Const Empty))))" in exI, auto) done then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume b1: "(i=p__Inv3)" have "?P3 s" apply (cut_tac a1 a2 b1, simp, rule_tac x="(neg (andForm (eqn (IVar (Field (Para (Ident ''Chan3'') p__Inv3) ''Cmd'')) (Const InvAck)) (eqn (IVar (Ident ''CurCmd'')) (Const Empty))))" in exI, auto) done then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume b1: "(i~=p__Inv3\<and>i~=p__Inv4)" have "?P3 s" apply (cut_tac a1 a2 b1, simp, rule_tac x="(neg (andForm (eqn (IVar (Field (Para (Ident ''Chan3'') p__Inv3) ''Cmd'')) (Const InvAck)) (eqn (IVar (Ident ''CurCmd'')) (Const Empty))))" in exI, auto) done then have "invHoldForRule s f r (invariants N)" by auto } ultimately show "invHoldForRule s f r (invariants N)" by satx qed lemma n_RecvReqE__part__0Vsinv__49: assumes a1: "(\<exists> i. i\<le>N\<and>r=n_RecvReqE__part__0 N i)" and a2: "(\<exists> p__Inv3 p__Inv4. p__Inv3\<le>N\<and>p__Inv4\<le>N\<and>p__Inv3~=p__Inv4\<and>f=inv__49 p__Inv3 p__Inv4)" shows "invHoldForRule s f r (invariants N)" (is "?P1 s \<or> ?P2 s \<or> ?P3 s") proof - from a1 obtain i where a1:"i\<le>N\<and>r=n_RecvReqE__part__0 N i" apply fastforce done from a2 obtain p__Inv3 p__Inv4 where a2:"p__Inv3\<le>N\<and>p__Inv4\<le>N\<and>p__Inv3~=p__Inv4\<and>f=inv__49 p__Inv3 p__Inv4" apply fastforce done have "(i=p__Inv4)\<or>(i=p__Inv3)\<or>(i~=p__Inv3\<and>i~=p__Inv4)" apply (cut_tac a1 a2, auto) done moreover { assume b1: "(i=p__Inv4)" have "?P1 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume b1: "(i=p__Inv3)" have "?P1 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume b1: "(i~=p__Inv3\<and>i~=p__Inv4)" have "?P1 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } ultimately show "invHoldForRule s f r (invariants N)" by satx qed lemma n_RecvReqE__part__1Vsinv__49: assumes a1: "(\<exists> i. i\<le>N\<and>r=n_RecvReqE__part__1 N i)" and a2: "(\<exists> p__Inv3 p__Inv4. p__Inv3\<le>N\<and>p__Inv4\<le>N\<and>p__Inv3~=p__Inv4\<and>f=inv__49 p__Inv3 p__Inv4)" shows "invHoldForRule s f r (invariants N)" (is "?P1 s \<or> ?P2 s \<or> ?P3 s") proof - from a1 obtain i where a1:"i\<le>N\<and>r=n_RecvReqE__part__1 N i" apply fastforce done from a2 obtain p__Inv3 p__Inv4 where a2:"p__Inv3\<le>N\<and>p__Inv4\<le>N\<and>p__Inv3~=p__Inv4\<and>f=inv__49 p__Inv3 p__Inv4" apply fastforce done have "(i=p__Inv4)\<or>(i=p__Inv3)\<or>(i~=p__Inv3\<and>i~=p__Inv4)" apply (cut_tac a1 a2, auto) done moreover { assume b1: "(i=p__Inv4)" have "?P1 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume b1: "(i=p__Inv3)" have "?P1 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume b1: "(i~=p__Inv3\<and>i~=p__Inv4)" have "?P1 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } ultimately show "invHoldForRule s f r (invariants N)" by satx qed lemma n_SendInvAckVsinv__49: assumes a1: "(\<exists> i. i\<le>N\<and>r=n_SendInvAck i)" and a2: "(\<exists> p__Inv3 p__Inv4. p__Inv3\<le>N\<and>p__Inv4\<le>N\<and>p__Inv3~=p__Inv4\<and>f=inv__49 p__Inv3 p__Inv4)" shows "invHoldForRule s f r (invariants N)" (is "?P1 s \<or> ?P2 s \<or> ?P3 s") proof - from a1 obtain i where a1:"i\<le>N\<and>r=n_SendInvAck i" apply fastforce done from a2 obtain p__Inv3 p__Inv4 where a2:"p__Inv3\<le>N\<and>p__Inv4\<le>N\<and>p__Inv3~=p__Inv4\<and>f=inv__49 p__Inv3 p__Inv4" apply fastforce done have "(i=p__Inv4)\<or>(i=p__Inv3)\<or>(i~=p__Inv3\<and>i~=p__Inv4)" apply (cut_tac a1 a2, auto) done moreover { assume b1: "(i=p__Inv4)" have "?P3 s" apply (cut_tac a1 a2 b1, simp, rule_tac x="(neg (andForm (andForm (eqn (IVar (Ident ''CurCmd'')) (Const ReqS)) (eqn (IVar (Field (Para (Ident ''Chan2'') p__Inv4) ''Cmd'')) (Const Inv))) (eqn (IVar (Field (Para (Ident ''Chan3'') p__Inv3) ''Cmd'')) (Const InvAck))))" in exI, auto) done then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume b1: "(i=p__Inv3)" have "?P3 s" apply (cut_tac a1 a2 b1, simp, rule_tac x="(neg (andForm (andForm (eqn (IVar (Ident ''CurCmd'')) (Const ReqS)) (eqn (IVar (Field (Para (Ident ''Chan2'') p__Inv3) ''Cmd'')) (Const Inv))) (eqn (IVar (Field (Para (Ident ''Chan3'') p__Inv4) ''Cmd'')) (Const InvAck))))" in exI, auto) done then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume b1: "(i~=p__Inv3\<and>i~=p__Inv4)" have "?P2 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } ultimately show "invHoldForRule s f r (invariants N)" by satx qed lemma n_RecvInvAckVsinv__49: assumes a1: "(\<exists> i. i\<le>N\<and>r=n_RecvInvAck i)" and a2: "(\<exists> p__Inv3 p__Inv4. p__Inv3\<le>N\<and>p__Inv4\<le>N\<and>p__Inv3~=p__Inv4\<and>f=inv__49 p__Inv3 p__Inv4)" shows "invHoldForRule s f r (invariants N)" (is "?P1 s \<or> ?P2 s \<or> ?P3 s") proof - from a1 obtain i where a1:"i\<le>N\<and>r=n_RecvInvAck i" apply fastforce done from a2 obtain p__Inv3 p__Inv4 where a2:"p__Inv3\<le>N\<and>p__Inv4\<le>N\<and>p__Inv3~=p__Inv4\<and>f=inv__49 p__Inv3 p__Inv4" apply fastforce done have "(i=p__Inv4)\<or>(i=p__Inv3)\<or>(i~=p__Inv3\<and>i~=p__Inv4)" apply (cut_tac a1 a2, auto) done moreover { assume b1: "(i=p__Inv4)" have "?P1 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume b1: "(i=p__Inv3)" have "?P1 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume b1: "(i~=p__Inv3\<and>i~=p__Inv4)" have "?P2 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } ultimately show "invHoldForRule s f r (invariants N)" by satx qed lemma n_SendGntSVsinv__49: assumes a1: "(\<exists> i. i\<le>N\<and>r=n_SendGntS i)" and a2: "(\<exists> p__Inv3 p__Inv4. p__Inv3\<le>N\<and>p__Inv4\<le>N\<and>p__Inv3~=p__Inv4\<and>f=inv__49 p__Inv3 p__Inv4)" shows "invHoldForRule s f r (invariants N)" (is "?P1 s \<or> ?P2 s \<or> ?P3 s") proof - from a1 obtain i where a1:"i\<le>N\<and>r=n_SendGntS i" apply fastforce done from a2 obtain p__Inv3 p__Inv4 where a2:"p__Inv3\<le>N\<and>p__Inv4\<le>N\<and>p__Inv3~=p__Inv4\<and>f=inv__49 p__Inv3 p__Inv4" apply fastforce done have "(i=p__Inv4)\<or>(i=p__Inv3)\<or>(i~=p__Inv3\<and>i~=p__Inv4)" apply (cut_tac a1 a2, auto) done moreover { assume b1: "(i=p__Inv4)" have "?P1 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume b1: "(i=p__Inv3)" have "?P1 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume b1: "(i~=p__Inv3\<and>i~=p__Inv4)" have "?P1 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } ultimately show "invHoldForRule s f r (invariants N)" by satx qed lemma n_SendGntEVsinv__49: assumes a1: "(\<exists> i. i\<le>N\<and>r=n_SendGntE N i)" and a2: "(\<exists> p__Inv3 p__Inv4. p__Inv3\<le>N\<and>p__Inv4\<le>N\<and>p__Inv3~=p__Inv4\<and>f=inv__49 p__Inv3 p__Inv4)" shows "invHoldForRule s f r (invariants N)" (is "?P1 s \<or> ?P2 s \<or> ?P3 s") proof - from a1 obtain i where a1:"i\<le>N\<and>r=n_SendGntE N i" apply fastforce done from a2 obtain p__Inv3 p__Inv4 where a2:"p__Inv3\<le>N\<and>p__Inv4\<le>N\<and>p__Inv3~=p__Inv4\<and>f=inv__49 p__Inv3 p__Inv4" apply fastforce done have "(i=p__Inv4)\<or>(i=p__Inv3)\<or>(i~=p__Inv3\<and>i~=p__Inv4)" apply (cut_tac a1 a2, auto) done moreover { assume b1: "(i=p__Inv4)" have "?P1 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume b1: "(i=p__Inv3)" have "?P1 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume b1: "(i~=p__Inv3\<and>i~=p__Inv4)" have "?P1 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } ultimately show "invHoldForRule s f r (invariants N)" by satx qed lemma n_StoreVsinv__49: assumes a1: "\<exists> i d. i\<le>N\<and>d\<le>N\<and>r=n_Store i d" and a2: "(\<exists> p__Inv3 p__Inv4. p__Inv3\<le>N\<and>p__Inv4\<le>N\<and>p__Inv3~=p__Inv4\<and>f=inv__49 p__Inv3 p__Inv4)" shows "invHoldForRule s f r (invariants N)" apply (rule noEffectOnRule, cut_tac a1 a2, auto) done lemma n_RecvGntSVsinv__49: assumes a1: "\<exists> i. i\<le>N\<and>r=n_RecvGntS i" and a2: "(\<exists> p__Inv3 p__Inv4. p__Inv3\<le>N\<and>p__Inv4\<le>N\<and>p__Inv3~=p__Inv4\<and>f=inv__49 p__Inv3 p__Inv4)" shows "invHoldForRule s f r (invariants N)" apply (rule noEffectOnRule, cut_tac a1 a2, auto) done lemma n_RecvGntEVsinv__49: assumes a1: "\<exists> i. i\<le>N\<and>r=n_RecvGntE i" and a2: "(\<exists> p__Inv3 p__Inv4. p__Inv3\<le>N\<and>p__Inv4\<le>N\<and>p__Inv3~=p__Inv4\<and>f=inv__49 p__Inv3 p__Inv4)" shows "invHoldForRule s f r (invariants N)" apply (rule noEffectOnRule, cut_tac a1 a2, auto) done lemma n_SendInv__part__0Vsinv__49: assumes a1: "\<exists> i. i\<le>N\<and>r=n_SendInv__part__0 i" and a2: "(\<exists> p__Inv3 p__Inv4. p__Inv3\<le>N\<and>p__Inv4\<le>N\<and>p__Inv3~=p__Inv4\<and>f=inv__49 p__Inv3 p__Inv4)" shows "invHoldForRule s f r (invariants N)" apply (rule noEffectOnRule, cut_tac a1 a2, auto) done lemma n_SendInv__part__1Vsinv__49: assumes a1: "\<exists> i. i\<le>N\<and>r=n_SendInv__part__1 i" and a2: "(\<exists> p__Inv3 p__Inv4. p__Inv3\<le>N\<and>p__Inv4\<le>N\<and>p__Inv3~=p__Inv4\<and>f=inv__49 p__Inv3 p__Inv4)" shows "invHoldForRule s f r (invariants N)" apply (rule noEffectOnRule, cut_tac a1 a2, auto) done end
[STATEMENT] lemma update_kno_dsn_greater_zero: "\<And>rt dip ip dsn hops npre. 1 \<le> dsn \<Longrightarrow> 1 \<le> (sqn (update rt dip (dsn, kno, val, hops, ip, npre)) dip)" [PROOF STATE] proof (prove) goal (1 subgoal): 1. \<And>rt dip ip dsn hops npre. 1 \<le> dsn \<Longrightarrow> 1 \<le> sqn (update rt dip (dsn, kno, val, hops, ip, npre)) dip [PROOF STEP] unfolding update_def [PROOF STATE] proof (prove) goal (1 subgoal): 1. \<And>rt dip ip dsn hops npre. 1 \<le> dsn \<Longrightarrow> 1 \<le> sqn (case rt dip of None \<Rightarrow> rt(dip \<mapsto> (dsn, kno, val, hops, ip, npre)) | Some s \<Rightarrow> if \<pi>\<^sub>2 s < \<pi>\<^sub>2 (dsn, kno, val, hops, ip, npre) then rt(dip \<mapsto> addpre (dsn, kno, val, hops, ip, npre) (\<pi>\<^sub>7 s)) else if \<pi>\<^sub>2 s = \<pi>\<^sub>2 (dsn, kno, val, hops, ip, npre) \<and> (\<pi>\<^sub>5 (dsn, kno, val, hops, ip, npre) < \<pi>\<^sub>5 s \<or> \<pi>\<^sub>4 s = Aodv_Basic.inv) then rt(dip \<mapsto> addpre (dsn, kno, val, hops, ip, npre) (\<pi>\<^sub>7 s)) else if \<pi>\<^sub>3 (dsn, kno, val, hops, ip, npre) = unk then rt(dip \<mapsto> (\<pi>\<^sub>2 s, snd (addpre (dsn, kno, val, hops, ip, npre) (\<pi>\<^sub>7 s)))) else rt(dip \<mapsto> addpre s (\<pi>\<^sub>7 (dsn, kno, val, hops, ip, npre)))) dip [PROOF STEP] by (clarsimp split: option.splits)
(* Title: HOL/MicroJava/DFA/Err.thy Author: Tobias Nipkow Copyright 2000 TUM *) section \<open>The Error Type\<close> theory Err imports Semilat begin datatype 'a err = Err | OK 'a type_synonym 'a ebinop = "'a \<Rightarrow> 'a \<Rightarrow> 'a err" type_synonym 'a esl = "'a set * 'a ord * 'a ebinop" primrec ok_val :: "'a err \<Rightarrow> 'a" where "ok_val (OK x) = x" definition lift :: "('a \<Rightarrow> 'b err) \<Rightarrow> ('a err \<Rightarrow> 'b err)" where "lift f e == case e of Err \<Rightarrow> Err | OK x \<Rightarrow> f x" definition lift2 :: "('a \<Rightarrow> 'b \<Rightarrow> 'c err) \<Rightarrow> 'a err \<Rightarrow> 'b err \<Rightarrow> 'c err" where "lift2 f e1 e2 == case e1 of Err \<Rightarrow> Err | OK x \<Rightarrow> (case e2 of Err \<Rightarrow> Err | OK y \<Rightarrow> f x y)" definition le :: "'a ord \<Rightarrow> 'a err ord" where "le r e1 e2 == case e2 of Err \<Rightarrow> True | OK y \<Rightarrow> (case e1 of Err \<Rightarrow> False | OK x \<Rightarrow> x <=_r y)" definition sup :: "('a \<Rightarrow> 'b \<Rightarrow> 'c) \<Rightarrow> ('a err \<Rightarrow> 'b err \<Rightarrow> 'c err)" where "sup f == lift2(%x y. OK(x +_f y))" definition err :: "'a set \<Rightarrow> 'a err set" where "err A == insert Err {x . ? y:A. x = OK y}" definition esl :: "'a sl \<Rightarrow> 'a esl" where "esl == %(A,r,f). (A,r, %x y. OK(f x y))" definition sl :: "'a esl \<Rightarrow> 'a err sl" where "sl == %(A,r,f). (err A, le r, lift2 f)" abbreviation err_semilat :: "'a esl \<Rightarrow> bool" where "err_semilat L == semilat(Err.sl L)" primrec strict :: "('a \<Rightarrow> 'b err) \<Rightarrow> ('a err \<Rightarrow> 'b err)" where "strict f Err = Err" | "strict f (OK x) = f x" lemma strict_Some [simp]: "(strict f x = OK y) = (\<exists> z. x = OK z \<and> f z = OK y)" by (cases x, auto) lemma not_Err_eq: "(x \<noteq> Err) = (\<exists>a. x = OK a)" by (cases x) auto lemma not_OK_eq: "(\<forall>y. x \<noteq> OK y) = (x = Err)" by (cases x) auto lemma unfold_lesub_err: "e1 <=_(le r) e2 == le r e1 e2" by (simp add: lesub_def) lemma le_err_refl: "!x. x <=_r x \<Longrightarrow> e <=_(Err.le r) e" apply (unfold lesub_def Err.le_def) apply (simp split: err.split) done lemma le_err_trans [rule_format]: "order r \<Longrightarrow> e1 <=_(le r) e2 \<longrightarrow> e2 <=_(le r) e3 \<longrightarrow> e1 <=_(le r) e3" apply (unfold unfold_lesub_err le_def) apply (simp split: err.split) apply (blast intro: order_trans) done lemma le_err_antisym [rule_format]: "order r \<Longrightarrow> e1 <=_(le r) e2 \<longrightarrow> e2 <=_(le r) e1 \<longrightarrow> e1=e2" apply (unfold unfold_lesub_err le_def) apply (simp split: err.split) apply (blast intro: order_antisym) done lemma OK_le_err_OK: "(OK x <=_(le r) OK y) = (x <=_r y)" by (simp add: unfold_lesub_err le_def) lemma order_le_err [iff]: "order(le r) = order r" apply (rule iffI) apply (subst Semilat.order_def) apply (blast dest: order_antisym OK_le_err_OK [THEN iffD2] intro: order_trans OK_le_err_OK [THEN iffD1]) apply (subst Semilat.order_def) apply (blast intro: le_err_refl le_err_trans le_err_antisym dest: order_refl) done lemma le_Err [iff]: "e <=_(le r) Err" by (simp add: unfold_lesub_err le_def) lemma Err_le_conv [iff]: "Err <=_(le r) e = (e = Err)" by (simp add: unfold_lesub_err le_def split: err.split) lemma le_OK_conv [iff]: "e <=_(le r) OK x = (? y. e = OK y & y <=_r x)" by (simp add: unfold_lesub_err le_def split: err.split) lemma OK_le_conv: "OK x <=_(le r) e = (e = Err | (? y. e = OK y & x <=_r y))" by (simp add: unfold_lesub_err le_def split: err.split) lemma top_Err [iff]: "top (le r) Err" by (simp add: top_def) lemma OK_less_conv [rule_format, iff]: "OK x <_(le r) e = (e=Err | (? y. e = OK y & x <_r y))" by (simp add: lesssub_def lesub_def le_def split: err.split) lemma not_Err_less [rule_format, iff]: "~(Err <_(le r) x)" by (simp add: lesssub_def lesub_def le_def split: err.split) lemma semilat_errI [intro]: assumes semilat: "semilat (A, r, f)" shows "semilat(err A, Err.le r, lift2(%x y. OK(f x y)))" using semilat apply (simp only: semilat_Def closed_def plussub_def lesub_def lift2_def Err.le_def err_def) apply (simp split: err.split) done lemma err_semilat_eslI_aux: assumes semilat: "semilat (A, r, f)" shows "err_semilat(esl(A,r,f))" apply (unfold sl_def esl_def) apply (simp add: semilat_errI[OF semilat]) done lemma err_semilat_eslI [intro, simp]: "\<And>L. semilat L \<Longrightarrow> err_semilat(esl L)" by(simp add: err_semilat_eslI_aux split_tupled_all) lemma acc_err [simp, intro!]: "acc r \<Longrightarrow> acc(le r)" apply (unfold acc_def lesub_def le_def lesssub_def) apply (simp add: wf_eq_minimal split: err.split) apply clarify apply (case_tac "Err : Q") apply blast apply (erule_tac x = "{a . OK a : Q}" in allE) apply (case_tac "x") apply fast apply blast done lemma Err_in_err [iff]: "Err : err A" by (simp add: err_def) lemma Ok_in_err [iff]: "(OK x : err A) = (x:A)" by (auto simp add: err_def) subsection \<open>lift\<close> lemma lift_in_errI: "\<lbrakk> e : err S; !x:S. e = OK x \<longrightarrow> f x : err S \<rbrakk> \<Longrightarrow> lift f e : err S" apply (unfold lift_def) apply (simp split: err.split) apply blast done lemma Err_lift2 [simp]: "Err +_(lift2 f) x = Err" by (simp add: lift2_def plussub_def) lemma lift2_Err [simp]: "x +_(lift2 f) Err = Err" by (simp add: lift2_def plussub_def split: err.split) lemma OK_lift2_OK [simp]: "OK x +_(lift2 f) OK y = x +_f y" by (simp add: lift2_def plussub_def split: err.split) subsection \<open>sup\<close> lemma Err_sup_Err [simp]: "Err +_(Err.sup f) x = Err" by (simp add: plussub_def Err.sup_def Err.lift2_def) lemma Err_sup_Err2 [simp]: "x +_(Err.sup f) Err = Err" by (simp add: plussub_def Err.sup_def Err.lift2_def split: err.split) lemma Err_sup_OK [simp]: "OK x +_(Err.sup f) OK y = OK(x +_f y)" by (simp add: plussub_def Err.sup_def Err.lift2_def) lemma Err_sup_eq_OK_conv [iff]: "(Err.sup f ex ey = OK z) = (? x y. ex = OK x & ey = OK y & f x y = z)" apply (unfold Err.sup_def lift2_def plussub_def) apply (rule iffI) apply (simp split: err.split_asm) apply clarify apply simp done lemma Err_sup_eq_Err [iff]: "(Err.sup f ex ey = Err) = (ex=Err | ey=Err)" apply (unfold Err.sup_def lift2_def plussub_def) apply (simp split: err.split) done subsection \<open>semilat (err A) (le r) f\<close> lemma semilat_le_err_Err_plus [simp]: "\<lbrakk> x: err A; semilat(err A, le r, f) \<rbrakk> \<Longrightarrow> Err +_f x = Err" by (blast intro: Semilat.le_iff_plus_unchanged [OF Semilat.intro, THEN iffD1] Semilat.le_iff_plus_unchanged2 [OF Semilat.intro, THEN iffD1]) lemma semilat_le_err_plus_Err [simp]: "\<lbrakk> x: err A; semilat(err A, le r, f) \<rbrakk> \<Longrightarrow> x +_f Err = Err" by (blast intro: Semilat.le_iff_plus_unchanged [OF Semilat.intro, THEN iffD1] Semilat.le_iff_plus_unchanged2 [OF Semilat.intro, THEN iffD1]) lemma semilat_le_err_OK1: "\<lbrakk> x:A; y:A; semilat(err A, le r, f); OK x +_f OK y = OK z \<rbrakk> \<Longrightarrow> x <=_r z" apply (rule OK_le_err_OK [THEN iffD1]) apply (erule subst) apply (simp add: Semilat.ub1 [OF Semilat.intro]) done lemma semilat_le_err_OK2: "\<lbrakk> x:A; y:A; semilat(err A, le r, f); OK x +_f OK y = OK z \<rbrakk> \<Longrightarrow> y <=_r z" apply (rule OK_le_err_OK [THEN iffD1]) apply (erule subst) apply (simp add: Semilat.ub2 [OF Semilat.intro]) done lemma eq_order_le: "\<lbrakk> x=y; order r \<rbrakk> \<Longrightarrow> x <=_r y" apply (unfold Semilat.order_def) apply blast done lemma OK_plus_OK_eq_Err_conv [simp]: assumes "x:A" and "y:A" and "semilat(err A, le r, fe)" shows "((OK x) +_fe (OK y) = Err) = (~(? z:A. x <=_r z & y <=_r z))" proof - have plus_le_conv3: "\<And>A x y z f r. \<lbrakk> semilat (A,r,f); x +_f y <=_r z; x:A; y:A; z:A \<rbrakk> \<Longrightarrow> x <=_r z \<and> y <=_r z" by (rule Semilat.plus_le_conv [OF Semilat.intro, THEN iffD1]) from assms show ?thesis apply (rule_tac iffI) apply clarify apply (drule OK_le_err_OK [THEN iffD2]) apply (drule OK_le_err_OK [THEN iffD2]) apply (drule Semilat.lub [OF Semilat.intro, of _ _ _ "OK x" _ "OK y"]) apply assumption apply assumption apply simp apply simp apply simp apply simp apply (case_tac "(OK x) +_fe (OK y)") apply assumption apply (rename_tac z) apply (subgoal_tac "OK z: err A") apply (drule eq_order_le) apply (erule Semilat.orderI [OF Semilat.intro]) apply (blast dest: plus_le_conv3) apply (erule subst) apply (blast intro: Semilat.closedI [OF Semilat.intro] closedD) done qed subsection \<open>semilat (err (Union AS))\<close> (* FIXME? *) lemma all_bex_swap_ text \<open> If @{term "AS = {}"} the thm collapses to @{prop "order r & closed {Err} f & Err +_f Err = Err"} which may not hold \<close> lemma err_semilat_UnionI: "\<lbrakk> !A:AS. err_semilat(A, r, f); AS ~= {}; !A:AS.!B:AS. A~=B \<longrightarrow> (!a:A.!b:B. ~ a <=_r b & a +_f b = Err) \<rbrakk> \<Longrightarrow> err_semilat (\<Union>AS, r, f)" apply (unfold semilat_def sl_def) apply (simp add: closed_err_Union_lift2I) apply (rule conjI) apply blast apply (simp add: err_def) apply (rule conjI) apply clarify apply (rename_tac A a u B b) apply (case_tac "A = B") apply simp apply simp apply (rule conjI) apply clarify apply (rename_tac A a u B b) apply (case_tac "A = B") apply simp apply simp apply clarify apply (rename_tac A ya yb B yd z C c a b) apply (case_tac "A = B") apply (case_tac "A = C") apply simp apply (rotate_tac -1) apply simp apply (rotate_tac -1) apply (case_tac "B = C") apply simp apply (rotate_tac -1) apply simp done end
Require Import HoTT. Require Import HoTT.Categories.Functor. Require Import GR.bicategories.bicategories. Require Import GR.bicategories.lax_functors. Require Import GR.bicategories.lax_transformations. From GR.groupoid Require Import groupoid_quotient.gquot groupoid_quotient.gquot_functor groupoid_quotient.gquot_principles grpd_bicategory.grpd_bicategory path_groupoid.path_groupoid. From GR.basics Require Import general. Section Counit. Context `{Univalence}. Definition counit_map (X : 1 -Type) : one_types⟦gquot_functor(path_groupoid X),X⟧. Proof. simple refine (gquot_rec X _ _ _ _) ; cbn. - exact idmap. - exact (fun _ _ => idmap). - reflexivity. - reflexivity. Defined. Definition naturality_help₁ {X Y : one_types} (f : X -> Y) {a₁ a₂ : path_groupoid X} (g : path_groupoid X a₁ a₂) : path_over (fun h : gquot (path_groupoid X) => f (counit_map X h) = counit_map Y (gquot_functor_map (ap_functor f) h) ) (gcleq (path_groupoid X) g) idpath idpath. Proof. induction g. apply map_path_over. apply path_to_square. refine (concat_p1 _ @ _ @ (concat_1p _)^). rewrite ge. reflexivity. Qed. Definition naturality_help₂ {X Y : one_types} (f : X -> Y) {a₁ a₂ : path_groupoid X} (g : path_groupoid X a₁ a₂) : path_over (fun h : gquot (path_groupoid X) => counit_map Y (gquot_functor_map (ap_functor f) h) = f (counit_map X h) ) (gcleq (path_groupoid X) g) idpath idpath. Proof. induction g. apply map_path_over. apply path_to_square. refine (concat_p1 _ @ _ @ (concat_1p _)^). rewrite ge. reflexivity. Qed. Definition counit_gq_naturality {X Y : one_types} (f : one_types⟦X,Y⟧) : forall (x : gquot_functor (path_groupoid X)), (f · counit_map X) x = (counit_map Y · gquot_functor_map (ap_functor f)) x. Proof. simple refine (gquot_ind_set _ _ _ _). - reflexivity. - intros ? ? g. exact (naturality_help₁ f g). Defined. Definition counit_gq_naturality_inv {X Y : one_types} (f : one_types⟦X,Y⟧) : forall (x : gquot_functor (path_groupoid X)), (counit_map Y · gquot_functor_map (ap_functor f)) x = (f · counit_map X) x. Proof. simple refine (gquot_ind_set _ _ _ _). - reflexivity. - intros ? ? g. exact (naturality_help₂ f g). Defined. Definition counit_gq_d : PseudoTransformation_d (lax_comp gquot_functor path_groupoid_functor) (lax_id_functor one_types). Proof. make_pseudo_transformation. - exact counit_map. - intros X Y f. exact (path_forall _ _ (counit_gq_naturality f)). - intros X Y f. exact (path_forall _ _ (counit_gq_naturality_inv f)). Defined. Definition counit_gq_d_lax_naturality {X Y : one_types} (f : one_types⟦X,Y⟧) : laxnaturality_of_pd counit_gq_d f = path_forall _ _ (counit_gq_naturality f). Proof. exact idpath. Qed. Definition counit_gq_d_lax_naturality_inv {X Y : one_types} (f : one_types⟦X,Y⟧) : laxnaturality_of_inv_pd counit_gq_d f = path_forall _ _ (counit_gq_naturality_inv f). Proof. exact idpath. Qed. Definition comp_functor_path {X Y : one_types} (f g : one_types⟦X,Y⟧) (p : f ==> g) : lax_comp gquot_functor path_groupoid_functor ₂ p = path_forall _ _ (gquot_functor_map_natural (ap_functor_natural p)). Proof. exact idpath. Qed. Definition comp_functor_Fid (X : one_types) : Fid (lax_comp gquot_functor path_groupoid_functor) X = path_forall _ _ (fun x => (gquot_functor_map_id (path_groupoid X) x) @ gquot_functor_map_natural (path_groupoid_map_id X) x). Proof. rewrite path_forall_pp. reflexivity. Qed. Definition whisker_l_one_types {X Y Z : one_types} (f : one_types⟦Y,Z⟧) {g h : one_types⟦X,Y⟧} (α : g ==> h) : id₂ f * α = path_forall _ _ (fun x => ap f (ap10 α x)). Proof. cbn. f_ap. funext x. apply concat_1p. Qed. Definition whisker_r_one_types {X Y Z : one_types} (f : one_types⟦X,Y⟧) {g h : one_types⟦Y,Z⟧} (α : g ==> h) : α * id₂ f = path_forall _ _ (fun x => ap10 α (f x)). Proof. cbn. f_ap. funext x. apply concat_p1. Qed. Definition one_types_left_unit {X Y : one_types} (f : one_types⟦X,Y⟧) : left_unit f = idpath. Proof. exact idpath. Qed. Definition one_types_right_unit {X Y : one_types} (f : one_types⟦X,Y⟧) : right_unit f = idpath. Proof. exact idpath. Qed. Definition one_types_left_unit_inv {X Y : one_types} (f : one_types⟦X,Y⟧) : left_unit_inv f = idpath. Proof. exact idpath. Qed. Definition one_types_right_unit_inv {X Y : one_types} (f : one_types⟦X,Y⟧) : right_unit_inv f = idpath. Proof. exact idpath. Qed. Definition one_types_assoc {W X Y Z : one_types} (h : one_types⟦Y,Z⟧) (g : one_types⟦X,Y⟧) (f : one_types⟦W,X⟧) : assoc h g f = idpath. Proof. exact idpath. Qed. Definition one_types_assoc_inv {W X Y Z : one_types} (h : one_types⟦Y,Z⟧) (g : one_types⟦X,Y⟧) (f : one_types⟦W,X⟧) : assoc_inv h g f = idpath. Proof. exact idpath. Qed. Definition vcomp_is_concat {X Y : one_types} {f g h : one_types⟦X,Y⟧} (α : f ==> g) (β : g ==> h) : β ∘ α = α @ β. Proof. exact idpath. Qed. Definition one_types_id₂ {X Y : one_types} (f : one_types⟦X,Y⟧) : id₂ f = idpath. Proof. exact idpath. Qed. Definition path_forall_2 {A B : Type} (f g : A -> B) (e₁ e₂ : f == g) : e₁ == e₂ -> path_forall f g e₁ = path_forall f g e₂ := fun He => ap (path_forall f g) (path_forall e₁ e₂ He). Definition counit_gq_is_lax : is_pseudo_transformation_p counit_gq_d. Proof. make_is_pseudo_transformation. - intros X Y f g p. induction p. rewrite !vcomp_is_concat. rewrite (counit_gq_d_lax_naturality f). rewrite (comp_functor_path f). rewrite hcomp_id₂. rewrite one_types_id₂. rewrite concat_1p. rewrite (whisker_l_one_types (counit_gq_d Y)). rewrite <- !path_forall_pp. refine (path_forall_2 _ _ _ _ _). simple refine (gquot_ind_prop _ _ _). intros a. refine (_^ @ (concat_1p _)^). rewrite ap10_path_forall. exact (gquot_rec_beta_gcleq _ _ _ _ _ _ _ _ _ _). - intros X. rewrite hcomp_id₂. rewrite !vcomp_is_concat, one_types_id₂. rewrite concat_1p. rewrite (counit_gq_d_lax_naturality (id₁ X)). rewrite (one_types_left_unit (counit_gq_d X)). rewrite one_types_right_unit_inv. rewrite !concat_1p. rewrite comp_functor_Fid. rewrite (whisker_l_one_types (counit_gq_d X)). refine (path_forall_2 _ _ _ _ _). simple refine (gquot_ind_prop _ _ _). intros a. refine (_ @ ap (ap (counit_gq_d X)) ((ap10_path_forall _ _ _ _)^)) ; cbn. rewrite ge. reflexivity. - intros X Y Z f g. rewrite !vcomp_is_concat. rewrite (whisker_r_one_types (counit_gq_d X)). rewrite (counit_gq_d_lax_naturality (g · f)). rewrite (counit_gq_d_lax_naturality g). rewrite (counit_gq_d_lax_naturality f). rewrite (one_types_assoc _ _ (counit_gq_d X)). rewrite (one_types_assoc_inv _ (counit_gq_d Y) _). rewrite !concat_1p. rewrite (whisker_l_one_types (counit_gq_d Z)). rewrite (whisker_l_one_types (Fmor (lax_id_functor one_types) Y Z g)). rewrite <- !path_forall_pp. refine (path_forall_2 _ _ _ _ _). simple refine (gquot_ind_prop _ _ _). intros a. cbn. rewrite <- path_forall_pp. rewrite !ap10_path_forall. rewrite !concat_1p ; simpl. rewrite ge. reflexivity. - intros X Y f. rewrite (counit_gq_d_lax_naturality f). rewrite (counit_gq_d_lax_naturality_inv f). rewrite vcomp_is_concat. rewrite one_types_id₂. rewrite <- path_forall_pp, <- path_forall_1. refine (path_forall_2 _ _ _ _ _). simple refine (gquot_ind_prop _ _ _). reflexivity. - intros X Y f. rewrite (counit_gq_d_lax_naturality f). rewrite (counit_gq_d_lax_naturality_inv f). rewrite vcomp_is_concat. rewrite one_types_id₂. rewrite <- path_forall_pp, <- path_forall_1. refine (path_forall_2 _ _ _ _ _). simple refine (gquot_ind_prop _ _ _). reflexivity. Qed. Definition counit_gq : PseudoTransformation (lax_comp gquot_functor path_groupoid_functor) (lax_id_functor one_types) := Build_PseudoTransformation counit_gq_d counit_gq_is_lax. End Counit.
theory GabrielaLimonta1 imports "~~/src/HOL/IMP/Hoare_Sound_Complete" "~~/src/HOL/IMP/VCG" begin (* Homework 11.1 *) abbreviation "xx \<equiv> ''x''" abbreviation "yy \<equiv> ''y''" abbreviation "aa \<equiv> ''a''" abbreviation "bb \<equiv> ''b''" definition Cdiff :: com where "Cdiff \<equiv> bb ::= N 0;; WHILE (Less (V bb) (V xx)) DO (yy ::= Plus (V yy) (N -1);; bb ::= Plus (V bb) (N 1))" definition P_Cdiff :: "int \<Rightarrow> int \<Rightarrow> assn" where "P_Cdiff x y \<equiv> \<lambda>s. s xx = x \<and> s yy = y \<and> 0 \<le> x" definition Q_Cdiff :: "int \<Rightarrow> int \<Rightarrow> assn" where "Q_Cdiff x y \<equiv> \<lambda>t. t yy = y - x" definition iCdiff :: "int \<Rightarrow> int \<Rightarrow> assn" where "iCdiff x y \<equiv> \<lambda>s. s xx = x \<and> y = s yy + s bb \<and> s bb \<le> x" definition ACdiff :: "int \<Rightarrow> int \<Rightarrow> acom" where "ACdiff x y \<equiv> (bb ::= N 0) ;; {iCdiff x y} WHILE (Less (V bb) (V xx)) DO (yy ::= Plus (V yy) (N -1);; bb ::= Plus (V bb) (N 1))" lemma strip_ACdiff: "strip (ACdiff x y) = Cdiff" unfolding Cdiff_def P_Cdiff_def Q_Cdiff_def iCdiff_def ACdiff_def by simp lemma Cdiff_correct: "\<turnstile> {P_Cdiff x y} strip (ACdiff x y) {Q_Cdiff x y}" unfolding strip_ACdiff[of x y, symmetric] apply(rule vc_sound') unfolding Cdiff_def P_Cdiff_def Q_Cdiff_def iCdiff_def ACdiff_def by auto end
Now that we’re into our second week of rotational grazing, I’ve take the time to get the Gator, my “grazing-mobile,” prepped for the season. We rotate animals to new paddocks every 3-4 days. I like to have my go-to-supplies on hand so I’m not constantly running back to the barn or the shop for things, and then back again. This season I also spray painted some of the harder to find in the grass items blaze orange in the event I misplace something. I should be ready for just about anything when it comes to fence repair, waterline repair and working with my goats and guardian dogs.
import category_theory.category -- this transitively imports -- category_theory.category -- category_theory.functor -- category_theory.natural_transformation import category_theory.isomorphism import category_theory.groupoid import tactic open category_theory universes v u variables (C : Type u) [category.{v} C] --variables {W X Y Z : C} --variables (f : X ⟶ Y) (g : Y ⟶ X) (h : Y ⟶ X) /-Exercise 1.1.i-/ /-(i) Show that a morphism can have at most one inverse isomorphism-/ lemma at_most_one_inv {X Y : C} (f : X ⟶ Y) (g : Y ⟶ X) [is_iso g]: f ≫ g = 𝟙 X → f = inv g:= begin intro h1, calc f = f ≫ 𝟙 Y : by {rw [category.comp_id]} ... = f ≫ g ≫ inv g : by {rw [is_iso.hom_inv_id]} ... = 𝟙 X ≫ inv g: by {symmetry' at h1, rw [h1, category.assoc]} ... = inv g: by {rw [category.id_comp]} end /-(ii) Consider a morphism f: x ⟶ y. Show that if there exists a pair of morphisms g, h : y ⟶ x so that gf = 𝟙 x and fg = 𝟙 y, then g = h and f is an isomorphism.-/ lemma left_right_inv_eq {X Y : C} (f : X ⟶ Y) (g : Y ⟶ X) (h : Y ⟶ X) : f ≫ g = 𝟙 X ∧ h ≫ f = 𝟙 Y → g = h := begin intro h1, cases h1 with hgx hhy, calc g = 𝟙 Y ≫ g : by {rw [category.id_comp]} ... = h ≫ f ≫ g : by {symmetry' at hhy, rw [hhy, category.assoc]} ... = h ≫ 𝟙 X : by {rw [hgx]} ... = h : by {rw [category.comp_id]} end def left_right_inv_iso {X Y : C} (f : X ⟶ Y) (g : Y ⟶ X) (h : Y ⟶ X) [is_iso g] [is_iso h]: f ≫ g = 𝟙 X ∧ h ≫ f = 𝟙 Y → is_iso f := begin intro h1, cases h1 with hgx hhy, have hg : g = h := -- not proud of this one by {apply left_right_inv_eq, split, exact hgx, exact hhy}, rw hg at hgx, have h2 : f = inv h := by {apply at_most_one_inv, exact hgx}, rw h2, apply is_iso.inv_is_iso, end /-Exercise 1.1.ii-/ /-Let C be a category. Show that the collection of isomorphisms in C defines a subcategory, the maximal groupoid inside C.-/ --To do: -- define objects (all obj of C) -- define morphisms (just isomorphisms of C) -- show that all morphisms have dom/cod? (spoiler: they do, we have all objects) -- identity morphisms (again, they are isomorphisms) -- closure of composite morphisms - probably the only hard part in Lean def identity_is_iso (X : C) : is_iso (𝟙 X) := { inv := 𝟙 X, hom_inv_id' := by rw [category.id_comp], inv_hom_id' := by rw [category.id_comp]} -- need f.hom ≫ g.hom ≫ g.inv ≫ f.inv = 𝟙 X and vice versa def iso_comp_is_iso {X Y Z : C} (f : X ⟶ Y) (g : Y ⟶ Z) [is_iso f] [is_iso g] : is_iso (f ≫ g) := { inv := (inv g ≫ inv f), hom_inv_id' := by rw [← category.assoc, category.assoc f, is_iso.hom_inv_id, category.comp_id, is_iso.hom_inv_id], inv_hom_id' := by rw [← category.assoc, category.assoc (inv g), is_iso.inv_hom_id, category.comp_id, is_iso.inv_hom_id]} def core (C : Type u) : Type u := C --objects are elements of type core C variable (X : core C) #check X --nice -- don't think I need to show that it's a groupoid? instance has_hom : core C := { hom := is_iso } instance core_groupoid : groupoid.{v} (core C) := { hom := /-λ X Y : core C, X ⟶ Y-/sorry, id := by apply identity_is_iso, comp := _, id_comp' := _, comp_id' := _, assoc' := _, inv := _, inv_comp' := _, comp_inv' := _ } --hhhhh /-Exercise 1.1.iii For any category C and any object A ∈ C, show that:-/ /-(i) There is a category A/C whose objects are morphisms f : A ⟶ X with domain A and in which a morphism from f : A ⟶ X to g : A ⟶ Y is a map h : X ⟶ Y such that g = hf.-/ /-instance unop_mono_of_epi {A B : Cᵒᵖ} (f : A ⟶ B) [epi f] : mono f.unop := ⟨λ Z g h eq, has_hom.hom.op_inj ((cancel_epi f).1 (has_hom.hom.unop_inj eq))⟩-/ --goal: /- class category_struct (obj : Type u) extends has_hom.{v} obj : Type (max u (v+1)) := (id : Π X : obj, hom X X) (comp : Π {X Y Z : obj}, (X ⟶ Y) → (Y ⟶ Z) → (X ⟶ Z)) class category (obj : Type u) extends category_struct.{v} obj : Type (max u (v+1)) := (id_comp' : ∀ {X Y : obj} (f : hom X Y), 𝟙 X ≫ f = f . obviously) (comp_id' : ∀ {X Y : obj} (f : hom X Y), f ≫ 𝟙 Y = f . obviously) (assoc' : ∀ {W X Y Z : obj} (f : hom W X) (g : hom X Y) (h : hom Y Z), (f ≫ g) ≫ h = f ≫ (g ≫ h) . obviously)-/ --ugh /-class slice_struct (A : C) (obj : Type v) extends has_slice_hom.{v} obj : Type (max v (v+1)) := (id : Π {X : C}, (A ⟶ X) : obj, hom (A ⟶ X) (A ⟶ X). obviously) (comp : Π {(A ⟶ X) (A ⟶ Y) (A ⟶ Z): AC}, (A ⟶ X) ⟶ (A ⟶ Y))-/ /-class slice (obj : Type u) extends category.{v} obj : Type (max u (v+1)) := (inv : Π {X Y : obj}, (X ⟶ Y) → (Y ⟶ X)) (inv_comp' : ∀ {X Y : obj} (f : X ⟶ Y), comp (inv f) f = id Y . obviously) (comp_inv' : ∀ {X Y : obj} (f : X ⟶ Y), comp f (inv f) = id X . obviously)-/
#pragma once #include <gsl/string_span.h> using zstr = gsl::zstring<>; using czstr = gsl::czstring<>; using zwstr = gsl::wzstring<>; using czwstr = gsl::cwzstring<>;
= = = Science = = =
inductive bin : ℕ → Prop | bin_epsilon : bin 0 | bin_0 : ∀ n, bin n → bin (2 * n) | bin_1 : ∀ n, bin n → bin (2 * n + 1) definition is_expressible_in_binrary_notation := bin example : ∀ n, is_expressible_in_binrary_notation n := begin intro, induction n, apply bin.bin_epsilon, induction n_ih, exact (bin.bin_1 0 bin.bin_epsilon), have pohe : (nat.succ (2 * n_ih_n)) = (2 * n_ih_n + 1), begin rw ← nat.add_one end, rw pohe, exact bin.bin_1 n_ih_n n_ih_a, have fuga: (nat.succ (2 * n_ih_n + 1)) = 2 * (nat.succ n_ih_n), begin calc (nat.succ (2 * n_ih_n + 1)) = 2 * n_ih_n + 1 + 1 : by rw nat.add_one ... = 2 * n_ih_n + (1 + 1) : by rw nat.add_assoc ... = 2 * n_ih_n + 2 : by simp ... = 2 * n_ih_n + 2 * 1 : by simp ... = 2 * (n_ih_n + 1) : by rw nat.left_distrib ... = 2 * (nat.succ n_ih_n) : by rw nat.add_one end, rw fuga, exact bin.bin_0 (nat.succ n_ih_n) n_ih_ih end
(** * Notation1.v ----------------- Defines a more natural monadic notation for the probabilistic computation monad defined in [Comp.v]. *) Set Implicit Arguments. From mathcomp.ssreflect Require Import ssreflect ssrnat seq ssrbool ssrfun fintype choice eqtype . From ProbHash.Computation Require Import Comp. Lemma size_enum_equiv: forall n: nat, size(enum (ordinal n.+1)) = n.+1 -> #|ordinal_finType n.+1| = n.+1. Proof. move=> n H. by rewrite unlock H. Qed. (** Draw a uniformly random integer value from the finite range 0 to n *) Definition random n := (@Rnd (ordinal_finType n.+1) n (size_enum_equiv (size_enum_ord n.+1))). Notation "'ret' v" := (Ret _ v) (at level 75). Notation "[0 ... n ]" := (random n). Notation "{ 0 , 1 } ^ n" := (random (2^n)) (right associativity, at level 77). Notation "{ 0 , 1 }" := (random 1) (right associativity, at level 75). Notation "x <-$ c1 ; c2" := (@Bind _ _ c1 (fun x => c2)) (right associativity, at level 81, c1 at next level). Notation "x <- e1 ; e2" := ((fun x => e2) e1) (right associativity, at level 81, e1 at next level). Notation "'P[' a '===' b ']'" := ((evalDist a) b). Notation "'P[' a ']'" := ((evalDist a) true). Notation "'E[' a ']'" := (expected_value a). Notation " a '|>' b " := (w_a <-$ a; b w_a) (at level 50). Notation " w '>>=' a '<&&>' b " := (fun w => ret (a && b )) (at level 49). Notation " w '>>=' a '<||>' b " := (fun w => ret (a || b )) (at level 49). Definition example := x <- 3; y <-$ [0 ... 3]; ret y.
Formal statement is: lemma homeomorphic_contractible_eq: fixes S :: "'a::real_normed_vector set" and T :: "'b::real_normed_vector set" shows "S homeomorphic T \<Longrightarrow> (contractible S \<longleftrightarrow> contractible T)" Informal statement is: If two topological spaces are homeomorphic, then they are contractible if and only if they are contractible.
(* File: Akra_Bazzi_Real.thy Author: Manuel Eberl <[email protected]> The continuous version of the Akra-Bazzi theorem for functions on the reals. *) section \<open>The continuous Akra-Bazzi theorem\<close> theory Akra_Bazzi_Real imports Complex_Main Akra_Bazzi_Asymptotics begin text \<open> We want to be generic over the integral definition used; we fix some arbitrary notions of integrability and integral and assume just the properties we need. The user can then instantiate the theorems with any desired integral definition. \<close> locale akra_bazzi_integral = fixes integrable :: "(real \<Rightarrow> real) \<Rightarrow> real \<Rightarrow> real \<Rightarrow> bool" and integral :: "(real \<Rightarrow> real) \<Rightarrow> real \<Rightarrow> real \<Rightarrow> real" assumes integrable_const: "c \<ge> 0 \<Longrightarrow> integrable (\<lambda>_. c) a b" and integral_const: "c \<ge> 0 \<Longrightarrow> a \<le> b \<Longrightarrow> integral (\<lambda>_. c) a b = (b - a) * c" and integrable_subinterval: "integrable f a b \<Longrightarrow> a \<le> a' \<Longrightarrow> b' \<le> b \<Longrightarrow> integrable f a' b'" and integral_le: "integrable f a b \<Longrightarrow> integrable g a b \<Longrightarrow> (\<And>x. x \<in> {a..b} \<Longrightarrow> f x \<le> g x) \<Longrightarrow> integral f a b \<le> integral g a b" and integral_combine: "a \<le> c \<Longrightarrow> c \<le> b \<Longrightarrow> integrable f a b \<Longrightarrow> integral f a c + integral f c b = integral f a b" begin lemma integral_nonneg: "a \<le> b \<Longrightarrow> integrable f a b \<Longrightarrow> (\<And>x. x \<in> {a..b} \<Longrightarrow> f x \<ge> 0) \<Longrightarrow> integral f a b \<ge> 0" using integral_le[OF integrable_const[of 0], of f a b] by (simp add: integral_const) end declare sum.cong[fundef_cong] lemma strict_mono_imp_ex1_real: fixes f :: "real \<Rightarrow> real" assumes lim_neg_inf: "LIM x at_bot. f x :> at_top" assumes lim_inf: "(f \<longlongrightarrow> z) at_top" assumes mono: "\<And>a b. a < b \<Longrightarrow> f b < f a" assumes cont: "\<And>x. isCont f x" assumes y_greater_z: "z < y" shows "\<exists>!x. f x = y" proof (rule ex_ex1I) fix a b assume "f a = y" "f b = y" thus "a = b" by (cases rule: linorder_cases[of a b]) (auto dest: mono) next from lim_neg_inf have "eventually (\<lambda>x. y \<le> f x) at_bot" by (subst (asm) filterlim_at_top) simp then obtain l where l: "\<And>x. x \<le> l \<Longrightarrow> y \<le> f x" by (subst (asm) eventually_at_bot_linorder) auto from order_tendstoD(2)[OF lim_inf y_greater_z] obtain u where u: "\<And>x. x \<ge> u \<Longrightarrow> f x < y" by (subst (asm) eventually_at_top_linorder) auto define a where "a = min l u" define b where "b = max l u" have a: "f a \<ge> y" unfolding a_def by (intro l) simp moreover have b: "f b < y" unfolding b_def by (intro u) simp moreover have a_le_b: "a \<le> b" by (simp add: a_def b_def) ultimately have "\<exists>x\<ge>a. x \<le> b \<and> f x = y" using cont by (intro IVT2) auto thus "\<exists>x. f x = y" by blast qed text \<open>The parameter @{term "p"} in the Akra-Bazzi theorem always exists and is unique.\<close> definition akra_bazzi_exponent :: "real list \<Rightarrow> real list \<Rightarrow> real" where "akra_bazzi_exponent as bs \<equiv> (THE p. (\<Sum>i<length as. as!i * bs!i powr p) = 1)" locale akra_bazzi_params = fixes k :: nat and as bs :: "real list" assumes length_as: "length as = k" and length_bs: "length bs = k" and k_not_0: "k \<noteq> 0" and a_ge_0: "a \<in> set as \<Longrightarrow> a \<ge> 0" and b_bounds: "b \<in> set bs \<Longrightarrow> b \<in> {0<..<1}" begin abbreviation p :: real where "p \<equiv> akra_bazzi_exponent as bs" lemma p_def: "p = (THE p. (\<Sum>i<k. as!i * bs!i powr p) = 1)" by (simp add: akra_bazzi_exponent_def length_as) lemma b_pos: "b \<in> set bs \<Longrightarrow> b > 0" and b_less_1: "b \<in> set bs \<Longrightarrow> b < 1" using b_bounds by simp_all lemma as_nonempty [simp]: "as \<noteq> []" and bs_nonempty [simp]: "bs \<noteq> []" using length_as length_bs k_not_0 by auto lemma a_in_as[intro, simp]: "i < k \<Longrightarrow> as ! i \<in> set as" by (rule nth_mem) (simp add: length_as) lemma b_in_bs[intro, simp]: "i < k \<Longrightarrow> bs ! i \<in> set bs" by (rule nth_mem) (simp add: length_bs) end locale akra_bazzi_params_nonzero = fixes k :: nat and as bs :: "real list" assumes length_as: "length as = k" and length_bs: "length bs = k" and a_ge_0: "a \<in> set as \<Longrightarrow> a \<ge> 0" and ex_a_pos: "\<exists>a\<in>set as. a > 0" and b_bounds: "b \<in> set bs \<Longrightarrow> b \<in> {0<..<1}" begin sublocale akra_bazzi_params k as bs by unfold_locales (insert length_as length_bs a_ge_0 ex_a_pos b_bounds, auto) lemma akra_bazzi_p_strict_mono: assumes "x < y" shows "(\<Sum>i<k. as!i * bs!i powr y) < (\<Sum>i<k. as!i * bs!i powr x)" proof (intro sum_strict_mono_ex1 ballI) from ex_a_pos obtain a where "a \<in> set as" "a > 0" by blast then obtain i where "i < k" "as!i > 0" by (force simp: in_set_conv_nth length_as) with b_bounds \<open>x < y\<close> have "as!i * bs!i powr y < as!i * bs!i powr x" by (intro mult_strict_left_mono powr_less_mono') auto with \<open>i < k\<close> show "\<exists>i\<in>{..<k}. as!i * bs!i powr y < as!i * bs!i powr x" by blast next fix i assume "i \<in> {..<k}" with a_ge_0 b_bounds[of "bs!i"] \<open>x < y\<close> show "as!i * bs!i powr y \<le> as!i * bs!i powr x" by (intro mult_left_mono powr_mono') simp_all qed simp_all lemma akra_bazzi_p_mono: assumes "x \<le> y" shows "(\<Sum>i<k. as!i * bs!i powr y) \<le> (\<Sum>i<k. as!i * bs!i powr x)" apply (cases "x < y") using akra_bazzi_p_strict_mono[of x y] assms apply simp_all done lemma akra_bazzi_p_unique: "\<exists>!p. (\<Sum>i<k. as!i * bs!i powr p) = 1" proof (rule strict_mono_imp_ex1_real) from as_nonempty have [simp]: "k > 0" by (auto simp: length_as[symmetric]) have [simp]: "\<And>i. i < k \<Longrightarrow> as!i \<ge> 0" by (rule a_ge_0) simp from ex_a_pos obtain a where "a \<in> set as" "a > 0" by blast then obtain i where i: "i < k" "as!i > 0" by (force simp: in_set_conv_nth length_as) hence "LIM p at_bot. as!i * bs!i powr p :> at_top" using b_bounds i by (intro filterlim_tendsto_pos_mult_at_top[OF tendsto_const] real_powr_at_bot_neg) simp_all moreover have "\<forall>p. as!i*bs!i powr p \<le> (\<Sum>i\<in>{..<k}. as ! i * bs ! i powr p)" proof fix p :: real from a_ge_0 b_bounds have "(\<Sum>i\<in>{..<k}-{i}. as ! i * bs ! i powr p) \<ge> 0" by (intro sum_nonneg mult_nonneg_nonneg) simp_all also have "as!i * bs!i powr p + ... = (\<Sum>i\<in>insert i {..<k}. as ! i * bs ! i powr p)" by (simp add: sum.insert_remove) also from i have "insert i {..<k} = {..<k}" by blast finally show "as!i*bs!i powr p \<le> (\<Sum>i\<in>{..<k}. as ! i * bs ! i powr p)" by simp qed ultimately show "LIM p at_bot. \<Sum>i<k. as ! i * bs ! i powr p :> at_top" by (rule filterlim_at_top_mono[OF _ always_eventually]) next from b_bounds show "((\<lambda>x. \<Sum>i<k. as ! i * bs ! i powr x) \<longlongrightarrow> (\<Sum>i<k. 0)) at_top" by (intro tendsto_sum tendsto_mult_right_zero real_powr_at_top_neg) simp_all next fix x from b_bounds have A: "\<And>i. i < k \<Longrightarrow> bs ! i > 0" by simp show "isCont (\<lambda>x. \<Sum>i<k. as ! i * bs ! i powr x) x" using b_bounds[OF nth_mem] by (intro continuous_intros) (auto dest: A) qed (simp_all add: akra_bazzi_p_strict_mono) lemma p_props: "(\<Sum>i<k. as!i * bs!i powr p) = 1" and p_unique: "(\<Sum>i<k. as!i * bs!i powr p') = 1 \<Longrightarrow> p = p'" proof- from theI'[OF akra_bazzi_p_unique] the1_equality[OF akra_bazzi_p_unique] show "(\<Sum>i<k. as!i * bs!i powr p) = 1" "(\<Sum>i<k. as!i * bs!i powr p') = 1 \<Longrightarrow> p = p'" unfolding p_def by - blast+ qed lemma p_greaterI: "1 < (\<Sum>i<k. as!i * bs!i powr p') \<Longrightarrow> p' < p" by (rule disjE[OF le_less_linear, of p p'], drule akra_bazzi_p_mono, subst (asm) p_props, simp_all) lemma p_lessI: "1 > (\<Sum>i<k. as!i * bs!i powr p') \<Longrightarrow> p' > p" by (rule disjE[OF le_less_linear, of p' p], drule akra_bazzi_p_mono, subst (asm) p_props, simp_all) lemma p_geI: "1 \<le> (\<Sum>i<k. as!i * bs!i powr p') \<Longrightarrow> p' \<le> p" by (rule disjE[OF le_less_linear, of p' p], simp, drule akra_bazzi_p_strict_mono, subst (asm) p_props, simp_all) lemma p_leI: "1 \<ge> (\<Sum>i<k. as!i * bs!i powr p') \<Longrightarrow> p' \<ge> p" by (rule disjE[OF le_less_linear, of p p'], simp, drule akra_bazzi_p_strict_mono, subst (asm) p_props, simp_all) lemma p_boundsI: "(\<Sum>i<k. as!i * bs!i powr x) \<le> 1 \<and> (\<Sum>i<k. as!i * bs!i powr y) \<ge> 1 \<Longrightarrow> p \<in> {y..x}" by (elim conjE, drule p_leI, drule p_geI, simp) lemma p_boundsI': "(\<Sum>i<k. as!i * bs!i powr x) < 1 \<and> (\<Sum>i<k. as!i * bs!i powr y) > 1 \<Longrightarrow> p \<in> {y<..<x}" by (elim conjE, drule p_lessI, drule p_greaterI, simp) lemma p_nonneg: "sum_list as \<ge> 1 \<Longrightarrow> p \<ge> 0" proof (rule p_geI) assume "sum_list as \<ge> 1" also have "... = (\<Sum>i<k. as!i)" by (simp add: sum_list_sum_nth length_as atLeast0LessThan) also { fix i assume "i < k" with b_bounds have "bs!i > 0" by simp hence "as!i * bs!i powr 0 = as!i" by simp } hence "(\<Sum>i<k. as!i) = (\<Sum>i<k. as!i * bs!i powr 0)" by (intro sum.cong) simp_all finally show "1 \<le> (\<Sum>i<k. as ! i * bs ! i powr 0)" . qed end locale akra_bazzi_real_recursion = fixes as bs :: "real list" and hs :: "(real \<Rightarrow> real) list" and k :: nat and x\<^sub>0 x\<^sub>1 hb e p :: real assumes length_as: "length as = k" and length_bs: "length bs = k" and length_hs: "length hs = k" and k_not_0: "k \<noteq> 0" and a_ge_0: "a \<in> set as \<Longrightarrow> a \<ge> 0" and b_bounds: "b \<in> set bs \<Longrightarrow> b \<in> {0<..<1}" (* The recursively-defined function *) and x0_ge_1: "x\<^sub>0 \<ge> 1" and x0_le_x1: "x\<^sub>0 \<le> x\<^sub>1" and x1_ge: "b \<in> set bs \<Longrightarrow> x\<^sub>1 \<ge> 2 * x\<^sub>0 * inverse b" (* Bounds on the variation functions *) and e_pos: "e > 0" and h_bounds: "x \<ge> x\<^sub>1 \<Longrightarrow> h \<in> set hs \<Longrightarrow> \<bar>h x\<bar> \<le> hb * x / ln x powr (1 + e)" (* Asymptotic inequalities *) and asymptotics: "x \<ge> x\<^sub>0 \<Longrightarrow> b \<in> set bs \<Longrightarrow> akra_bazzi_asymptotics b hb e p x" begin sublocale akra_bazzi_params k as bs using length_as length_bs k_not_0 a_ge_0 b_bounds by unfold_locales lemma h_in_hs[intro, simp]: "i < k \<Longrightarrow> hs ! i \<in> set hs" by (rule nth_mem) (simp add: length_hs) lemma x1_gt_1: "x\<^sub>1 > 1" proof- from bs_nonempty obtain b where "b \<in> set bs" by (cases bs) auto from b_pos[OF this] b_less_1[OF this] x0_ge_1 have "1 < 2 * x\<^sub>0 * inverse b" by (simp add: field_simps) also from x1_ge and \<open>b \<in> set bs\<close> have "... \<le> x\<^sub>1" by simp finally show ?thesis . qed lemma x1_ge_1: "x\<^sub>1 \<ge> 1" using x1_gt_1 by simp lemma x1_pos: "x\<^sub>1 > 0" using x1_ge_1 by simp lemma bx_le_x: "x \<ge> 0 \<Longrightarrow> b \<in> set bs \<Longrightarrow> b * x \<le> x" using b_pos[of b] b_less_1[of b] by (intro mult_left_le_one_le) (simp_all) lemma x0_pos: "x\<^sub>0 > 0" using x0_ge_1 by simp lemma assumes "x \<ge> x\<^sub>0" "b \<in> set bs" shows x0_hb_bound0: "hb / ln x powr (1 + e) < b/2" and x0_hb_bound1: "hb / ln x powr (1 + e) < (1 - b) / 2" and x0_hb_bound2: "x*(1 - b - hb / ln x powr (1 + e)) > 1" using asymptotics[OF assms] unfolding akra_bazzi_asymptotic_defs by blast+ lemma step_diff: assumes "i < k" "x \<ge> x\<^sub>1" shows "bs ! i * x + (hs ! i) x + 1 < x" proof- have "bs ! i * x + (hs ! i) x + 1 \<le> bs ! i * x + \<bar>(hs ! i) x\<bar> + 1" by simp also from assms have "\<bar>(hs ! i) x\<bar> \<le> hb * x / ln x powr (1 + e)" by (simp add: h_bounds) also from assms x0_le_x1 have "x*(1 - bs ! i - hb / ln x powr (1 + e)) > 1" by (simp add: x0_hb_bound2) hence "bs ! i * x + hb * x / ln x powr (1 + e) + 1 < x" by (simp add: algebra_simps) finally show ?thesis by simp qed lemma step_le_x: "i < k \<Longrightarrow> x \<ge> x\<^sub>1 \<Longrightarrow> bs ! i * x + (hs ! i) x \<le> x" by (drule (1) step_diff) simp lemma x0_hb_bound0': "\<And>x b. x \<ge> x\<^sub>0 \<Longrightarrow> b \<in> set bs \<Longrightarrow> hb / ln x powr (1 + e) < b" by (drule (1) x0_hb_bound0, erule less_le_trans) (simp add: b_pos) lemma step_pos: assumes "i < k" "x \<ge> x\<^sub>1" shows "bs ! i * x + (hs ! i) x > 0" proof- from assms x0_le_x1 have "hb / ln x powr (1 + e) < bs ! i" by (simp add: x0_hb_bound0') with assms x0_pos x0_le_x1 have "x * 0 < x * (bs ! i - hb / ln x powr (1 + e))" by simp also have "... = bs ! i * x - hb * x / ln x powr (1 + e)" by (simp add: algebra_simps) also from assms have "-hb * x / ln x powr (1 + e) \<le> -\<bar>(hs ! i) x\<bar>" by (simp add: h_bounds) hence "bs ! i * x - hb * x / ln x powr (1 + e) \<le> bs ! i * x + -\<bar>(hs ! i) x\<bar>" by simp also have "-\<bar>(hs ! i) x\<bar> \<le> (hs ! i) x" by simp finally show "bs ! i * x + (hs ! i) x > 0" by simp qed lemma step_nonneg: "i < k \<Longrightarrow> x \<ge> x\<^sub>1 \<Longrightarrow> bs ! i * x + (hs ! i) x \<ge> 0" by (drule (1) step_pos) simp lemma step_nonneg': "i < k \<Longrightarrow> x \<ge> x\<^sub>1 \<Longrightarrow> bs ! i + (hs ! i) x / x \<ge> 0" by (frule (1) step_nonneg, insert x0_pos x0_le_x1) (simp_all add: field_simps) lemma hb_nonneg: "hb \<ge> 0" proof- from k_not_0 and length_hs have "hs \<noteq> []" by auto then obtain h where h: "h \<in> set hs" by (cases hs) auto have "0 \<le> \<bar>h x\<^sub>1\<bar>" by simp also from h have "\<bar>h x\<^sub>1\<bar> \<le> hb * x\<^sub>1 / ln x\<^sub>1 powr (1+e)" by (intro h_bounds) simp_all finally have "0 \<le> hb * x\<^sub>1 / ln x\<^sub>1 powr (1 + e)" . hence "0 \<le> ... * (ln x\<^sub>1 powr (1 + e) / x\<^sub>1)" by (rule mult_nonneg_nonneg) (intro divide_nonneg_nonneg, insert x1_pos, simp_all) also have "... = hb" using x1_gt_1 by (simp add: field_simps) finally show ?thesis . qed lemma x0_hb_bound3: assumes "x \<ge> x\<^sub>1" "i < k" shows "x - (bs ! i * x + (hs ! i) x) \<le> x" proof- have "-(hs ! i) x \<le> \<bar>(hs ! i) x\<bar>" by simp also from assms have "... \<le> hb * x / ln x powr (1 + e)" by (simp add: h_bounds) also have "... = x * (hb / ln x powr (1 + e))" by simp also from assms x0_pos x0_le_x1 have "... < x * bs ! i" by (intro mult_strict_left_mono x0_hb_bound0') simp_all finally show ?thesis by (simp add: algebra_simps) qed lemma x0_hb_bound4: assumes "x \<ge> x\<^sub>1" "i < k" shows "(bs ! i + (hs ! i) x / x) > bs ! i / 2" proof- from assms x0_le_x1 have "hb / ln x powr (1 + e) < bs ! i / 2" by (intro x0_hb_bound0) simp_all with assms x0_pos x0_le_x1 have "(-bs ! i / 2) * x < (-hb / ln x powr (1 + e)) * x" by (intro mult_strict_right_mono) simp_all also from assms x0_pos have "... \<le> -\<bar>(hs ! i) x\<bar>" using h_bounds by simp also have "... \<le> (hs ! i) x" by simp finally show ?thesis using assms x1_pos by (simp add: field_simps) qed lemma x0_hb_bound4': "x \<ge> x\<^sub>1 \<Longrightarrow> i < k \<Longrightarrow> (bs ! i + (hs ! i) x / x) \<ge> bs ! i / 2" by (drule (1) x0_hb_bound4) simp lemma x0_hb_bound5: assumes "x \<ge> x\<^sub>1" "i < k" shows "(bs ! i + (hs ! i) x / x) \<le> bs ! i * 3/2" proof- have "(hs ! i) x \<le> \<bar>(hs ! i) x\<bar>" by simp also from assms have "... \<le> hb * x / ln x powr (1 + e)" by (simp add: h_bounds) also have "... = x * (hb / ln x powr (1 + e))" by simp also from assms x0_pos x0_le_x1 have "... < x * (bs ! i / 2)" by (intro mult_strict_left_mono x0_hb_bound0) simp_all finally show ?thesis using assms x1_pos by (simp add: field_simps) qed lemma x0_hb_bound6: assumes "x \<ge> x\<^sub>1" "i < k" shows "x * ((1 - bs ! i) / 2) \<le> x - (bs ! i * x + (hs ! i) x)" proof- from assms x0_le_x1 have "hb / ln x powr (1 + e) < (1 - bs ! i) / 2" using x0_hb_bound1 by simp with assms x1_pos have "x * ((1 - bs ! i) / 2) \<le> x * (1 - (bs ! i + hb / ln x powr (1 + e)))" by (intro mult_left_mono) (simp_all add: field_simps) also have "... = x - bs ! i * x + -hb * x / ln x powr (1 + e)" by (simp add: algebra_simps) also from h_bounds assms have "-hb * x / ln x powr (1 + e) \<le> -\<bar>(hs ! i) x\<bar>" by (simp add: length_hs) also have "... \<le> -(hs ! i) x" by simp finally show ?thesis by (simp add: algebra_simps) qed lemma x0_hb_bound7: assumes "x \<ge> x\<^sub>1" "i < k" shows "bs!i*x + (hs!i) x > x\<^sub>0" proof- from assms x0_le_x1 have x': "x \<ge> x\<^sub>0" by simp from x1_ge assms have "2 * x\<^sub>0 * inverse (bs!i) \<le> x\<^sub>1" by simp with assms b_pos have "x\<^sub>0 \<le> x\<^sub>1 * (bs!i / 2)" by (simp add: field_simps) also from assms x' have "bs!i/2 < bs!i + (hs!i) x / x" by (intro x0_hb_bound4) also from assms step_nonneg' x' have "x\<^sub>1 * ... \<le> x * ..." by (intro mult_right_mono) (simp_all) also from assms x1_pos have "x * (bs!i + (hs!i) x / x) = bs!i*x + (hs!i) x" by (simp add: field_simps) finally show ?thesis using x1_pos by simp qed lemma x0_hb_bound7': "x \<ge> x\<^sub>1 \<Longrightarrow> i < k \<Longrightarrow> bs!i*x + (hs!i) x > 1" by (rule le_less_trans[OF _ x0_hb_bound7]) (insert x0_le_x1 x0_ge_1, simp_all) lemma x0_hb_bound8: assumes "x \<ge> x\<^sub>1" "i < k" shows "bs!i*x - hb * x / ln x powr (1+e) > x\<^sub>0" proof- from assms have "2 * x\<^sub>0 * inverse (bs!i) \<le> x\<^sub>1" by (intro x1_ge) simp_all with b_pos assms have "x\<^sub>0 \<le> x\<^sub>1 * (bs!i/2)" by (simp add: field_simps) also from assms b_pos have "... \<le> x * (bs!i/2)" by simp also from assms x0_le_x1 have "hb / ln x powr (1+e) < bs!i/2" by (intro x0_hb_bound0) simp_all with assms have "bs!i/2 < bs!i - hb / ln x powr (1+e)" by (simp add: field_simps) also have "x * ... = bs!i*x - hb * x / ln x powr (1+e)" by (simp add: algebra_simps) finally show ?thesis using assms x1_pos by (simp add: field_simps) qed lemma x0_hb_bound8': assumes "x \<ge> x\<^sub>1" "i < k" shows "bs!i*x + hb * x / ln x powr (1+e) > x\<^sub>0" proof- from assms have "x\<^sub>0 < bs!i*x - hb * x / ln x powr (1+e)" by (rule x0_hb_bound8) also from assms hb_nonneg x1_pos have "hb * x / ln x powr (1+e) \<ge> 0" by (intro mult_nonneg_nonneg divide_nonneg_nonneg) simp_all hence "bs!i*x - hb * x / ln x powr (1+e) \<le> bs!i*x + hb * x / ln x powr (1+e)" by simp finally show ?thesis . qed lemma assumes "x \<ge> x\<^sub>0" shows asymptotics1: "i < k \<Longrightarrow> 1 + ln x powr (- e / 2) \<le> (1 - hb * inverse (bs!i) * ln x powr -(1+e)) powr p * (1 + ln (bs!i*x + hb*x/ln x powr (1+e)) powr (-e/2))" and asymptotics2: "i < k \<Longrightarrow> 1 - ln x powr (- e / 2) \<ge> (1 + hb * inverse (bs!i) * ln x powr -(1+e)) powr p * (1 - ln (bs!i*x + hb*x/ln x powr (1+e)) powr (-e/2))" and asymptotics1': "i < k \<Longrightarrow> 1 + ln x powr (- e / 2) \<le> (1 + hb * inverse (bs!i) * ln x powr -(1+e)) powr p * (1 + ln (bs!i*x + hb*x/ln x powr (1+e)) powr (-e/2))" and asymptotics2': "i < k \<Longrightarrow> 1 - ln x powr (- e / 2) \<ge> (1 - hb * inverse (bs!i) * ln x powr -(1+e)) powr p * (1 - ln (bs!i*x + hb*x/ln x powr (1+e)) powr (-e/2))" and asymptotics3: "(1 + ln x powr (- e / 2)) / 2 \<le> 1" and asymptotics4: "(1 - ln x powr (- e / 2)) * 2 \<ge> 1" and asymptotics5: "i < k \<Longrightarrow> ln (bs!i*x - hb*x*ln x powr -(1+e)) powr (-e/2) < 1" apply - using assms asymptotics[of x "bs!i"] unfolding akra_bazzi_asymptotic_defs apply simp_all[4] using assms asymptotics[of x "bs!0"] unfolding akra_bazzi_asymptotic_defs apply simp_all[2] using assms asymptotics[of x "bs!i"] unfolding akra_bazzi_asymptotic_defs apply simp_all done lemma x0_hb_bound9: assumes "x \<ge> x\<^sub>1" "i < k" shows "ln (bs!i*x + (hs!i) x) powr -(e/2) < 1" proof- from b_pos assms have "0 < bs!i/2" by simp also from assms x0_le_x1 have "... < bs!i + (hs!i) x / x" by (intro x0_hb_bound4) simp_all also from assms x1_pos have "x * ... = bs!i*x + (hs!i) x" by (simp add: field_simps) finally have pos: "bs!i*x + (hs!i) x > 0" using assms x1_pos by simp from x0_hb_bound8[OF assms] x0_ge_1 have pos': "bs!i*x - hb * x / ln x powr (1+e) > 1" by simp from assms have "-(hb * x / ln x powr (1+e)) \<le> -\<bar>(hs!i) x\<bar>" by (intro le_imp_neg_le h_bounds) simp_all also have "... \<le> (hs!i) x" by simp finally have "ln (bs!i*x - hb * x / ln x powr (1+e)) \<le> ln (bs!i*x + (hs!i) x)" using assms b_pos x0_pos pos' by (intro ln_mono mult_pos_pos pos) simp_all hence "ln (bs!i*x + (hs!i) x) powr -(e/2) \<le> ln (bs!i*x - hb * x / ln x powr (1+e)) powr -(e/2)" using assms e_pos asymptotics5[of x] pos' by (intro powr_mono2' ln_gt_zero) simp_all also have "... < 1" using asymptotics5[of x i] assms x0_le_x1 by (subst (asm) powr_minus) (simp_all add: field_simps) finally show ?thesis . qed definition akra_bazzi_measure :: "real \<Rightarrow> nat" where "akra_bazzi_measure x = nat \<lceil>x\<rceil>" lemma akra_bazzi_measure_decreases: assumes "x \<ge> x\<^sub>1" "i < k" shows "akra_bazzi_measure (bs!i*x + (hs!i) x) < akra_bazzi_measure x" proof- from step_diff assms have "(bs!i * x + (hs!i) x) + 1 < x" by (simp add: algebra_simps) hence "\<lceil>(bs!i * x + (hs!i) x) + 1\<rceil> \<le> \<lceil>x\<rceil>" by (intro ceiling_mono) simp hence "\<lceil>(bs!i * x + (hs!i) x)\<rceil> < \<lceil>x\<rceil>" by simp with assms x1_pos have "nat \<lceil>(bs!i * x + (hs!i) x)\<rceil> < nat \<lceil>x\<rceil>" by (subst nat_mono_iff) simp_all thus ?thesis unfolding akra_bazzi_measure_def . qed lemma akra_bazzi_induct[consumes 1, case_names base rec]: assumes "x \<ge> x\<^sub>0" assumes base: "\<And>x. x \<ge> x\<^sub>0 \<Longrightarrow> x \<le> x\<^sub>1 \<Longrightarrow> P x" assumes rec: "\<And>x. x > x\<^sub>1 \<Longrightarrow> (\<And>i. i < k \<Longrightarrow> P (bs!i*x + (hs!i) x)) \<Longrightarrow> P x" shows "P x" proof (insert \<open>x \<ge> x\<^sub>0\<close>, induction "akra_bazzi_measure x" arbitrary: x rule: less_induct) case less show ?case proof (cases "x \<le> x\<^sub>1") case True with base and \<open>x \<ge> x\<^sub>0\<close> show ?thesis . next case False hence x: "x > x\<^sub>1" by simp thus ?thesis proof (rule rec) fix i assume i: "i < k" from x0_hb_bound7[OF _ i, of x] x have "bs!i*x + (hs!i) x \<ge> x\<^sub>0" by simp with i x show "P (bs ! i * x + (hs ! i) x)" by (intro less akra_bazzi_measure_decreases) simp_all qed qed qed end locale akra_bazzi_real = akra_bazzi_real_recursion + fixes integrable integral assumes integral: "akra_bazzi_integral integrable integral" fixes f :: "real \<Rightarrow> real" and g :: "real \<Rightarrow> real" and C :: real assumes p_props: "(\<Sum>i<k. as!i * bs!i powr p) = 1" and f_base: "x \<ge> x\<^sub>0 \<Longrightarrow> x \<le> x\<^sub>1 \<Longrightarrow> f x \<ge> 0" and f_rec: "x > x\<^sub>1 \<Longrightarrow> f x = g x + (\<Sum>i<k. as!i * f (bs!i * x + (hs!i) x))" and g_nonneg: "x \<ge> x\<^sub>0 \<Longrightarrow> g x \<ge> 0" and C_bound: "b \<in> set bs \<Longrightarrow> x \<ge> x\<^sub>1 \<Longrightarrow> C*x \<le> b*x - hb*x/ln x powr (1+e)" and g_integrable: "x \<ge> x\<^sub>0 \<Longrightarrow> integrable (\<lambda>u. g u / u powr (p + 1)) x\<^sub>0 x" begin interpretation akra_bazzi_integral integrable integral by (rule integral) lemma akra_bazzi_integrable: "a \<ge> x\<^sub>0 \<Longrightarrow> a \<le> b \<Longrightarrow> integrable (\<lambda>x. g x / x powr (p + 1)) a b" by (rule integrable_subinterval[OF g_integrable, of b]) simp_all definition g_approx :: "nat \<Rightarrow> real \<Rightarrow> real" where "g_approx i x = x powr p * integral (\<lambda>u. g u / u powr (p + 1)) (bs!i * x + (hs!i) x) x" lemma f_nonneg: "x \<ge> x\<^sub>0 \<Longrightarrow> f x \<ge> 0" proof (induction x rule: akra_bazzi_induct) case (base x) with f_base[of x] show ?case by simp next case (rec x) with x0_le_x1 have "g x \<ge> 0" by (intro g_nonneg) simp_all moreover { fix i assume i: "i < k" with rec.IH have "f (bs!i*x + (hs!i) x) \<ge> 0" by simp with i have "as!i * f (bs!i*x + (hs!i) x) \<ge> 0" by (intro mult_nonneg_nonneg[OF a_ge_0]) simp_all } hence "(\<Sum>i<k. as!i * f (bs!i*x + (hs!i) x)) \<ge> 0" by (intro sum_nonneg) blast ultimately show "f x \<ge> 0" using rec.hyps by (subst f_rec) simp_all qed definition f_approx :: "real \<Rightarrow> real" where "f_approx x = x powr p * (1 + integral (\<lambda>u. g u / u powr (p + 1)) x\<^sub>0 x)" lemma f_approx_aux: assumes "x \<ge> x\<^sub>0" shows "1 + integral (\<lambda>u. g u / u powr (p + 1)) x\<^sub>0 x \<ge> 1" proof- from assms have "integral (\<lambda>u. g u / u powr (p + 1)) x\<^sub>0 x \<ge> 0" by (intro integral_nonneg ballI g_nonneg divide_nonneg_nonneg g_integrable) simp_all thus ?thesis by simp qed lemma f_approx_pos: "x \<ge> x\<^sub>0 \<Longrightarrow> f_approx x > 0" unfolding f_approx_def by (intro mult_pos_pos, insert x0_pos, simp, drule f_approx_aux, simp) lemma f_approx_nonneg: "x \<ge> x\<^sub>0 \<Longrightarrow> f_approx x \<ge> 0" using f_approx_pos[of x] by simp lemma f_approx_bounded_below: obtains c where "\<And>x. x \<ge> x\<^sub>0 \<Longrightarrow> x \<le> x\<^sub>1 \<Longrightarrow> f_approx x \<ge> c" "c > 0" proof- { fix x assume x: "x \<ge> x\<^sub>0" "x \<le> x\<^sub>1" with x0_pos have "x powr p \<ge> min (x\<^sub>0 powr p) (x\<^sub>1 powr p)" by (intro powr_lower_bound) simp_all with x have "f_approx x \<ge> min (x\<^sub>0 powr p) (x\<^sub>1 powr p) * 1" unfolding f_approx_def by (intro mult_mono f_approx_aux) simp_all } from this x0_pos x1_pos show ?thesis by (intro that[of "min (x\<^sub>0 powr p) (x\<^sub>1 powr p)"]) auto qed lemma asymptotics_aux: assumes "x \<ge> x\<^sub>1" "i < k" assumes "s \<equiv> (if p \<ge> 0 then 1 else -1)" shows "(bs!i*x - s*hb*x*ln x powr -(1+e)) powr p \<le> (bs!i*x + (hs!i) x) powr p" (is "?thesis1") and "(bs!i*x + (hs!i) x) powr p \<le> (bs!i*x + s*hb*x*ln x powr -(1+e)) powr p" (is "?thesis2") proof- from assms x1_gt_1 have ln_x_pos: "ln x > 0" by simp from assms x1_pos have x_pos: "x > 0" by simp from assms x0_le_x1 have *: "hb / ln x powr (1+e) < bs!i/2" by (intro x0_hb_bound0) simp_all with hb_nonneg ln_x_pos have "(bs!i - hb * ln x powr -(1+e)) > 0" by (subst powr_minus) (simp_all add: field_simps) with * have "0 < x * (bs!i - hb * ln x powr -(1+e))" using x_pos by (subst (asm) powr_minus, intro mult_pos_pos) hence A: "0 < bs!i*x - hb * x * ln x powr -(1+e)" by (simp add: algebra_simps) from assms have "-(hb*x*ln x powr -(1+e)) \<le> -\<bar>(hs!i) x\<bar>" using h_bounds[of x "hs!i"] by (subst neg_le_iff_le, subst powr_minus) (simp add: field_simps) also have "... \<le> (hs!i) x" by simp finally have B: "bs!i*x - hb*x*ln x powr -(1+e) \<le> bs!i*x + (hs!i) x" by simp have "(hs!i) x \<le> \<bar>(hs!i) x\<bar>" by simp also from assms have "... \<le> (hb*x*ln x powr -(1+e))" using h_bounds[of x "hs!i"] by (subst powr_minus) (simp_all add: field_simps) finally have C: "bs!i*x + hb*x*ln x powr -(1+e) \<ge> bs!i*x + (hs!i) x" by simp from A B C show ?thesis1 by (cases "p \<ge> 0") (auto intro: powr_mono2 powr_mono2' simp: assms(3)) from A B C show ?thesis2 by (cases "p \<ge> 0") (auto intro: powr_mono2 powr_mono2' simp: assms(3)) qed lemma asymptotics1': assumes "x \<ge> x\<^sub>1" "i < k" shows "(bs!i*x) powr p * (1 + ln x powr (-e/2)) \<le> (bs!i*x + (hs!i) x) powr p * (1 + ln (bs!i*x + (hs!i) x) powr (-e/2))" proof- from assms x0_le_x1 have x: "x \<ge> x\<^sub>0" by simp from b_pos[of "bs!i"] assms have b_pos: "bs!i > 0" "bs!i \<noteq> 0" by simp_all from b_less_1[of "bs!i"] assms have b_less_1: "bs!i < 1" by simp from x1_gt_1 assms have ln_x_pos: "ln x > 0" by simp have mono: "\<And>a b. a \<le> b \<Longrightarrow> (bs!i*x) powr p * a \<le> (bs!i*x) powr p * b" by (rule mult_left_mono) simp_all define s :: real where [abs_def]: "s = (if p \<ge> 0 then 1 else -1)" have "1 + ln x powr (-e/2) \<le> (1 - s*hb*inverse(bs!i)*ln x powr -(1+e)) powr p * (1 + ln (bs!i*x + hb * x / ln x powr (1+e)) powr (-e/2))" (is "_ \<le> ?A * ?B") using assms x unfolding s_def using asymptotics1[OF x assms(2)] asymptotics1'[OF x assms(2)] by simp also have "(bs!i*x) powr p * ... = (bs!i*x) powr p * ?A * ?B" by simp also from x0_hb_bound0'[OF x, of "bs!i"] hb_nonneg x ln_x_pos assms have "s*hb * ln x powr -(1 + e) < bs ! i" by (subst powr_minus) (simp_all add: field_simps s_def) hence "(bs!i*x) powr p * ?A = (bs!i*x*(1 - s*hb*inverse (bs!i)*ln x powr -(1+e))) powr p" using b_pos assms x x0_pos b_less_1 ln_x_pos by (subst powr_mult[symmetric]) (simp_all add: s_def field_simps) also have "bs!i*x*(1 - s*hb*inverse (bs!i)*ln x powr -(1+e)) = bs!i*x - s*hb*x*ln x powr -(1+e)" using b_pos assms by (simp add: algebra_simps) also have "?B = 1 + ln (bs!i*x + hb*x*ln x powr -(1+e)) powr (-e/2)" by (subst powr_minus) (simp add: field_simps) also { from x assms have "(bs!i*x - s*hb*x*ln x powr -(1+e)) powr p \<le> (bs!i*x + (hs!i) x) powr p" using asymptotics_aux(1)[OF assms(1,2) s_def] by blast moreover { have "(hs!i) x \<le> \<bar>(hs!i) x\<bar>" by simp also from assms have "\<bar>(hs!i) x\<bar> \<le> hb * x / ln x powr (1+e)" by (intro h_bounds) simp_all finally have "(hs ! i) x \<le> hb * x * ln x powr -(1 + e)" by (subst powr_minus) (simp_all add: field_simps) moreover from x hb_nonneg x0_pos have "hb * x * ln x powr -(1+e) \<ge> 0" by (intro mult_nonneg_nonneg) simp_all ultimately have "1 + ln (bs!i*x + hb * x * ln x powr -(1+e)) powr (-e/2) \<le> 1 + ln (bs!i*x + (hs!i) x) powr (-e/2)" using assms x e_pos b_pos x0_pos by (intro add_left_mono powr_mono2' ln_mono ln_gt_zero step_pos x0_hb_bound7' add_pos_nonneg mult_pos_pos) simp_all } ultimately have "(bs!i*x - s*hb*x*ln x powr -(1+e)) powr p * (1 + ln (bs!i*x + hb * x * ln x powr -(1+e)) powr (-e/2)) \<le> (bs!i*x + (hs!i) x) powr p * (1 + ln (bs!i*x + (hs!i) x) powr (-e/2))" by (rule mult_mono) simp_all } finally show ?thesis by (simp_all add: mono) qed lemma asymptotics2': assumes "x \<ge> x\<^sub>1" "i < k" shows "(bs!i*x + (hs!i) x) powr p * (1 - ln (bs!i*x + (hs!i) x) powr (-e/2)) \<le> (bs!i*x) powr p * (1 - ln x powr (-e/2))" proof- define s :: real where "s = (if p \<ge> 0 then 1 else -1)" from assms x0_le_x1 have x: "x \<ge> x\<^sub>0" by simp from assms x1_gt_1 have ln_x_pos: "ln x > 0" by simp from b_pos[of "bs!i"] assms have b_pos: "bs!i > 0" "bs!i \<noteq> 0" by simp_all from b_pos hb_nonneg have pos: "1 + s * hb * (inverse (bs!i) * ln x powr -(1+e)) > 0" using x0_hb_bound0'[OF x, of "bs!i"] b_pos assms ln_x_pos by (subst powr_minus) (simp add: field_simps s_def) have mono: "\<And>a b. a \<le> b \<Longrightarrow> (bs!i*x) powr p * a \<le> (bs!i*x) powr p * b" by (rule mult_left_mono) simp_all let ?A = "(1 + s*hb*inverse(bs!i)*ln x powr -(1+e)) powr p" let ?B = "1 - ln (bs!i*x + (hs!i) x) powr (-e/2)" let ?B' = "1 - ln (bs!i*x + hb * x / ln x powr (1+e)) powr (-e/2)" from assms x have "(bs!i*x + (hs!i) x) powr p \<le> (bs!i*x + s*hb*x*ln x powr -(1+e)) powr p" by (intro asymptotics_aux(2)) (simp_all add: s_def) moreover from x0_hb_bound9[OF assms(1,2)] have "?B \<ge> 0" by (simp add: field_simps) ultimately have "(bs!i*x + (hs!i) x) powr p * ?B \<le> (bs!i*x + s*hb*x*ln x powr -(1+e)) powr p * ?B" by (rule mult_right_mono) also from assms e_pos pos have "?B \<le> ?B'" proof - from x0_hb_bound8'[OF assms(1,2)] x0_hb_bound8[OF assms(1,2)] x0_ge_1 have *: "bs ! i * x + s*hb * x / ln x powr (1 + e) > 1" by (simp add: s_def) moreover from * have "... > 0" by simp moreover from x0_hb_bound7[OF assms(1,2)] x0_ge_1 have "bs ! i * x + (hs ! i) x > 1" by simp moreover { have "(hs!i) x \<le> \<bar>(hs!i) x\<bar>" by simp also from assms x0_le_x1 have "... \<le> hb*x/ln x powr (1+e)" by (intro h_bounds) simp_all finally have "bs!i*x + (hs!i) x \<le> bs!i*x + hb*x/ln x powr (1+e)" by simp } ultimately show "?B \<le> ?B'" using assms e_pos x step_pos by (intro diff_left_mono powr_mono2' ln_mono ln_gt_zero) simp_all qed hence "(bs!i*x + s*hb*x*ln x powr -(1+e)) powr p * ?B \<le> (bs!i*x + s*hb*x*ln x powr -(1+e)) powr p * ?B'" by (intro mult_left_mono) simp_all also have "bs!i*x + s*hb*x*ln x powr -(1+e) = bs!i*x*(1 + s*hb*inverse (bs!i)*ln x powr -(1+e))" using b_pos by (simp_all add: field_simps) also have "... powr p = (bs!i*x) powr p * ?A" using b_pos x x0_pos pos by (intro powr_mult) simp_all also have "(bs!i*x) powr p * ?A * ?B' = (bs!i*x) powr p * (?A * ?B')" by simp also have "?A * ?B' \<le> 1 - ln x powr (-e/2)" using assms x using asymptotics2[OF x assms(2)] asymptotics2'[OF x assms(2)] by (simp add: s_def) finally show ?thesis by (simp_all add: mono) qed lemma Cx_le_step: assumes "i < k" "x \<ge> x\<^sub>1" shows "C*x \<le> bs!i*x + (hs!i) x" proof- from assms have "C*x \<le> bs!i*x - hb*x/ln x powr (1+e)" by (intro C_bound) simp_all also from assms have "-(hb*x/ln x powr (1+e)) \<le> -\<bar>(hs!i) x\<bar>" by (subst neg_le_iff_le, intro h_bounds) simp_all hence "bs!i*x - hb*x/ln x powr (1+e) \<le> bs!i*x + -\<bar>(hs!i) x\<bar>" by simp also have "-\<bar>(hs!i) x\<bar> \<le> (hs!i) x" by simp finally show ?thesis by simp qed end locale akra_bazzi_nat_to_real = akra_bazzi_real_recursion + fixes f :: "nat \<Rightarrow> real" and g :: "real \<Rightarrow> real" assumes f_base: "real x \<ge> x\<^sub>0 \<Longrightarrow> real x \<le> x\<^sub>1 \<Longrightarrow> f x \<ge> 0" and f_rec: "real x > x\<^sub>1 \<Longrightarrow> f x = g (real x) + (\<Sum>i<k. as!i * f (nat \<lfloor>bs!i * x + (hs!i) (real x)\<rfloor>))" and x0_int: "real (nat \<lfloor>x\<^sub>0\<rfloor>) = x\<^sub>0" begin function f' :: "real \<Rightarrow> real" where "x \<le> x\<^sub>1 \<Longrightarrow> f' x = f (nat \<lfloor>x\<rfloor>)" | "x > x\<^sub>1 \<Longrightarrow> f' x = g x + (\<Sum>i<k. as!i * f' (bs!i * x + (hs!i) x))" by (force, simp_all) termination by (relation "Wellfounded.measure akra_bazzi_measure") (simp_all add: akra_bazzi_measure_decreases) lemma f'_base: "x \<ge> x\<^sub>0 \<Longrightarrow> x \<le> x\<^sub>1 \<Longrightarrow> f' x \<ge> 0" apply (subst f'.simps(1), assumption) apply (rule f_base) apply (rule order.trans[of _ "real (nat \<lfloor>x\<^sub>0\<rfloor>)"], simp add: x0_int) apply (subst of_nat_le_iff, intro nat_mono floor_mono, assumption) using x0_pos apply linarith done lemmas f'_rec = f'.simps(2) end locale akra_bazzi_real_lower = akra_bazzi_real + fixes fb2 gb2 c2 :: real assumes f_base2: "x \<ge> x\<^sub>0 \<Longrightarrow> x \<le> x\<^sub>1 \<Longrightarrow> f x \<ge> fb2" and fb2_pos: "fb2 > 0" and g_growth2: "\<forall>x\<ge>x\<^sub>1. \<forall>u\<in>{C*x..x}. c2 * g x \<ge> g u" and c2_pos: "c2 > 0" and g_bounded: "x \<ge> x\<^sub>0 \<Longrightarrow> x \<le> x\<^sub>1 \<Longrightarrow> g x \<le> gb2" begin interpretation akra_bazzi_integral integrable integral by (rule integral) lemma gb2_nonneg: "gb2 \<ge> 0" using g_bounded[of x\<^sub>0] x0_le_x1 x0_pos g_nonneg[of x\<^sub>0] by simp lemma g_growth2': assumes "x \<ge> x\<^sub>1" "i < k" "u \<in> {bs!i*x+(hs!i) x..x}" shows "c2 * g x \<ge> g u" proof- from assms have "C*x \<le> bs!i*x+(hs!i) x" by (intro Cx_le_step) with assms have "u \<in> {C*x..x}" by auto with assms g_growth2 show ?thesis by simp qed lemma g_bounds2: obtains c4 where "\<And>x i. x \<ge> x\<^sub>1 \<Longrightarrow> i < k \<Longrightarrow> g_approx i x \<le> c4 * g x" "c4 > 0" proof- define c4 where "c4 = Max {c2 / min 1 (min ((b/2) powr (p+1)) ((b*3/2) powr (p+1))) |b. b \<in> set bs}" { from bs_nonempty obtain b where b: "b \<in> set bs" by (cases bs) auto let ?m = "min 1 (min ((b/2) powr (p+1)) ((b*3/2) powr (p+1)))" from b b_pos have "?m > 0" unfolding min_def by (auto simp: not_le) with b b_pos c2_pos have "c2 / ?m > 0" by (simp_all add: field_simps) with b have "c4 > 0" unfolding c4_def by (subst Max_gr_iff) (simp, simp, blast) } { fix x i assume i: "i < k" and x: "x \<ge> x\<^sub>1" have powr_negD: "a powr b \<le> 0 \<Longrightarrow> a = 0" for a b :: real unfolding powr_def by (simp split: if_split_asm) let ?m = "min 1 (min ((bs!i/2) powr (p+1)) ((bs!i*3/2) powr (p+1)))" have "min 1 ((bs!i + (hs ! i) x / x) powr (p+1)) \<ge> min 1 (min ((bs!i/2) powr (p+1)) ((bs!i*3/2) powr (p+1)))" apply (insert x i x0_le_x1 x1_pos step_pos b_pos[OF b_in_bs[OF i]], rule min.mono, simp, cases "p + 1 \<ge> 0") apply (rule order.trans[OF min.cobounded1 powr_mono2[OF _ _ x0_hb_bound4']], simp_all add: field_simps) [] apply (rule order.trans[OF min.cobounded2 powr_mono2'[OF _ _ x0_hb_bound5]], simp_all add: field_simps) [] done with i b_pos[of "bs!i"] have "c2 / min 1 ((bs!i + (hs ! i) x / x) powr (p+1)) \<le> c2 / ?m" using c2_pos unfolding min_def by (intro divide_left_mono) (auto intro!: mult_pos_pos dest!: powr_negD) also from i x have "... \<le> c4" unfolding c4_def by (intro Max.coboundedI) auto finally have "c2 / min 1 ((bs!i + (hs ! i) x / x) powr (p+1)) \<le> c4" . } note c4 = this { fix x :: real and i :: nat assume x: "x \<ge> x\<^sub>1" and i: "i < k" from x x1_pos have x_pos: "x > 0" by simp let ?x' = "bs ! i * x + (hs ! i) x" let ?x'' = "bs ! i + (hs ! i) x / x" from x x1_ge_1 i g_growth2' x0_le_x1 c2_pos have c2: "c2 > 0" "\<forall>u\<in>{?x'..x}. g u \<le> c2 * g x" by auto from x0_le_x1 x i have x'_le_x: "?x' \<le> x" by (intro step_le_x) simp_all let ?m = "min (?x' powr (p + 1)) (x powr (p + 1))" define m' where "m' = min 1 (?x'' powr (p + 1))" have [simp]: "bs ! i > 0" by (intro b_pos nth_mem) (simp add: i length_bs) from x0_le_x1 x i have [simp]: "?x' > 0" by (intro step_pos) simp_all { fix u assume u: "u \<ge> ?x'" "u \<le> x" have "?m \<le> u powr (p + 1)" using x u by (intro powr_lower_bound mult_pos_pos) simp_all moreover from c2 and u have "g u \<le> c2 * g x" by simp ultimately have "g u * ?m \<le> c2 * g x * u powr (p + 1)" using c2 x x1_pos x0_le_x1 by (intro mult_mono mult_nonneg_nonneg g_nonneg) auto } hence "integral (\<lambda>u. g u / u powr (p+1)) ?x' x \<le> integral (\<lambda>u. c2 * g x / ?m) ?x' x" using x_pos step_pos[OF i x] x0_hb_bound7[OF x i] c2 x x0_le_x1 by (intro integral_le x'_le_x akra_bazzi_integrable ballI integrable_const) (auto simp: field_simps intro!: mult_nonneg_nonneg g_nonneg) also from x0_pos x x0_le_x1 x'_le_x c2 have "... = (x - ?x') * (c2 * g x / ?m)" by (subst integral_const) (simp_all add: g_nonneg) also from c2 x_pos x x0_le_x1 have "c2 * g x \<ge> 0" by (intro mult_nonneg_nonneg g_nonneg) simp_all with x i x0_le_x1 have "(x - ?x') * (c2 * g x / ?m) \<le> x * (c2 * g x / ?m)" by (intro x0_hb_bound3 mult_right_mono) (simp_all add: field_simps) also have "x powr (p + 1) = x powr (p + 1) * 1" by simp also have "(bs ! i * x + (hs ! i) x) powr (p + 1) = (bs ! i + (hs ! i) x / x) powr (p + 1) * x powr (p + 1)" using x x1_pos step_pos[OF i x] x_pos i x0_le_x1 by (subst powr_mult[symmetric]) (simp add: field_simps, simp, simp add: algebra_simps) also have "... = x powr (p + 1) * (bs ! i + (hs ! i) x / x) powr (p + 1)" by simp also have "min ... (x powr (p + 1) * 1) = x powr (p + 1) * m'" unfolding m'_def using x_pos by (subst min.commute, intro min_mult_left[symmetric]) simp also from x_pos have "x * (c2 * g x / (x powr (p + 1) * m')) = (c2/m') * (g x / x powr p)" by (simp add: field_simps powr_add) also from x i g_nonneg x0_le_x1 x1_pos have "... \<le> c4 * (g x / x powr p)" unfolding m'_def by (intro mult_right_mono c4) (simp_all add: field_simps) finally have "g_approx i x \<le> c4 * g x" unfolding g_approx_def using x_pos by (simp add: field_simps) } thus ?thesis using that \<open>c4 > 0\<close> by blast qed lemma f_approx_bounded_above: obtains c where "\<And>x. x \<ge> x\<^sub>0 \<Longrightarrow> x \<le> x\<^sub>1 \<Longrightarrow> f_approx x \<le> c" "c > 0" proof- let ?m1 = "max (x\<^sub>0 powr p) (x\<^sub>1 powr p)" let ?m2 = "max (x\<^sub>0 powr (-(p+1))) (x\<^sub>1 powr (-(p+1)))" let ?m3 = "gb2 * ?m2" let ?m4 = "1 + (x\<^sub>1 - x\<^sub>0) * ?m3" let ?int = "\<lambda>x. integral (\<lambda>u. g u / u powr (p + 1)) x\<^sub>0 x" { fix x assume x: "x \<ge> x\<^sub>0" "x \<le> x\<^sub>1" with x0_pos have "x powr p \<le> ?m1" "?m1 \<ge> 0" by (intro powr_upper_bound) (simp_all add: max_def) moreover { fix u assume u: "u \<in> {x\<^sub>0..x}" have "g u / u powr (p + 1) = g u * u powr (-(p+1))" by (subst powr_minus) (simp add: field_simps) also from u x x0_pos have "u powr (-(p+1)) \<le> ?m2" by (intro powr_upper_bound) simp_all hence "g u * u powr (-(p+1)) \<le> g u * ?m2" using u g_nonneg x0_pos by (intro mult_left_mono) simp_all also from x u x0_pos have "g u \<le> gb2" by (intro g_bounded) simp_all hence "g u * ?m2 \<le> gb2 * ?m2" by (intro mult_right_mono) (simp_all add: max_def) finally have "g u / u powr (p + 1) \<le> ?m3" . } note A = this { from A x gb2_nonneg have "?int x \<le> integral (\<lambda>_. ?m3) x\<^sub>0 x" by (intro integral_le akra_bazzi_integrable integrable_const mult_nonneg_nonneg) (simp_all add: le_max_iff_disj) also from x gb2_nonneg have "... \<le> (x - x\<^sub>0) * ?m3" by (subst integral_const) (simp_all add: le_max_iff_disj) also from x gb2_nonneg have "... \<le> (x\<^sub>1 - x\<^sub>0) * ?m3" by (intro mult_right_mono mult_nonneg_nonneg) (simp_all add: max_def) finally have "1 + ?int x \<le> ?m4" by simp } moreover from x g_nonneg x0_pos have "?int x \<ge> 0" by (intro integral_nonneg akra_bazzi_integrable) (simp_all add: powr_def field_simps) hence "1 + ?int x \<ge> 0" by simp ultimately have "f_approx x \<le> ?m1 * ?m4" unfolding f_approx_def by (intro mult_mono) hence "f_approx x \<le> max 1 (?m1 * ?m4)" by simp } from that[OF this] show ?thesis by auto qed lemma f_bounded_below: assumes c': "c' > 0" obtains c where "\<And>x. x \<ge> x\<^sub>0 \<Longrightarrow> x \<le> x\<^sub>1 \<Longrightarrow> 2 * (c * f_approx x) \<le> f x" "c \<le> c'" "c > 0" proof- obtain c where c: "\<And>x. x\<^sub>0 \<le> x \<Longrightarrow> x \<le> x\<^sub>1 \<Longrightarrow> f_approx x \<le> c" "c > 0" by (rule f_approx_bounded_above) blast { fix x assume x: "x\<^sub>0 \<le> x" "x \<le> x\<^sub>1" with c have "inverse c * f_approx x \<le> 1" by (simp add: field_simps) moreover from x f_base2 x0_pos have "f x \<ge> fb2" by auto ultimately have "inverse c * f_approx x * fb2 \<le> 1 * f x" using fb2_pos by (intro mult_mono) simp_all hence "inverse c * fb2 * f_approx x \<le> f x" by (simp add: field_simps) moreover have "min c' (inverse c * fb2) * f_approx x \<le> inverse c * fb2 * f_approx x" using f_approx_nonneg x c by (intro mult_right_mono f_approx_nonneg) (simp_all add: field_simps) ultimately have "2 * (min c' (inverse c * fb2) / 2 * f_approx x) \<le> f x" by simp } moreover from c' have "min c' (inverse c * fb2) / 2 \<le> c'" by simp moreover have "min c' (inverse c * fb2) / 2 > 0" using c fb2_pos c' by simp ultimately show ?thesis by (rule that) qed lemma akra_bazzi_lower: obtains c5 where "\<And>x. x \<ge> x\<^sub>0 \<Longrightarrow> f x \<ge> c5 * f_approx x" "c5 > 0" proof- obtain c4 where c4: "\<And>x i. x \<ge> x\<^sub>1 \<Longrightarrow> i < k \<Longrightarrow> g_approx i x \<le> c4 * g x" "c4 > 0" by (rule g_bounds2) blast hence "inverse c4 / 2 > 0" by simp then obtain c5 where c5: "\<And>x. x \<ge> x\<^sub>0 \<Longrightarrow> x \<le> x\<^sub>1 \<Longrightarrow> 2 * (c5 * f_approx x) \<le> f x" "c5 \<le> inverse c4 / 2" "c5 > 0" by (rule f_bounded_below) blast { fix x :: real assume x: "x \<ge> x\<^sub>0" from c5 x have " c5 * 1 * f_approx x \<le> c5 * (1 + ln x powr (- e / 2)) * f_approx x" by (intro mult_right_mono mult_left_mono f_approx_nonneg) simp_all also from x have "c5 * (1 + ln x powr (-e/2)) * f_approx x \<le> f x" proof (induction x rule: akra_bazzi_induct) case (base x) have "1 + ln x powr (-e/2) \<le> 2" using asymptotics3 base by simp hence "(1 + ln x powr (-e/2)) * (c5 * f_approx x) \<le> 2 * (c5 * f_approx x)" using c5 f_approx_nonneg base x0_ge_1 by (intro mult_right_mono mult_nonneg_nonneg) simp_all also from base have "2 * (c5 * f_approx x) \<le> f x" by (intro c5) simp_all finally show ?case by (simp add: algebra_simps) next case (rec x) let ?a = "\<lambda>i. as!i" and ?b = "\<lambda>i. bs!i" and ?h = "\<lambda>i. hs!i" let ?int = "integral (\<lambda>u. g u / u powr (p+1)) x\<^sub>0 x" let ?int1 = "\<lambda>i. integral (\<lambda>u. g u / u powr (p+1)) x\<^sub>0 (?b i*x+?h i x)" let ?int2 = "\<lambda>i. integral (\<lambda>u. g u / u powr (p+1)) (?b i*x+?h i x) x" let ?l = "ln x powr (-e/2)" and ?l' = "\<lambda>i. ln (?b i*x + ?h i x) powr (-e/2)" from rec and x0_le_x1 x0_ge_1 have x: "x \<ge> x\<^sub>0" and x_gt_1: "x > 1" by simp_all with x0_pos have x_pos: "x > 0" and x_nonneg: "x \<ge> 0" by simp_all from c5 c4 have "c5 * c4 \<le> 1/2" by (simp add: field_simps) moreover from asymptotics3 x have "(1 + ?l) \<le> 2" by (simp add: field_simps) ultimately have "(c5*c4)*(1 + ?l) \<le> (1/2) * 2" by (rule mult_mono) simp_all hence "0 \<le> 1 - c5*c4*(1 + ?l)" by simp with g_nonneg[OF x] have "0 \<le> g x * ..." by (intro mult_nonneg_nonneg) simp_all hence "c5 * (1 + ?l) * f_approx x \<le> c5 * (1 + ?l) * f_approx x + g x - c5*c4*(1 + ?l) * g x" by (simp add: algebra_simps) also from x_gt_1 have "... = c5 * x powr p * (1 + ?l) * (1 + ?int - c4*g x/x powr p) + g x" by (simp add: field_simps f_approx_def powr_minus) also have "c5 * x powr p * (1 + ?l) * (1 + ?int - c4*g x/x powr p) = (\<Sum>i<k. (?a i * ?b i powr p) * (c5 * x powr p * (1 + ?l) * (1 + ?int - c4*g x/x powr p)))" by (subst sum_distrib_right[symmetric]) (simp add: p_props) also have "... \<le> (\<Sum>i<k. ?a i * f (?b i*x + ?h i x))" proof (intro sum_mono, clarify) fix i assume i: "i < k" let ?f = "c5 * ?a i * (?b i * x) powr p" from rec.hyps i have "x\<^sub>0 < bs ! i * x + (hs ! i) x" by (intro x0_hb_bound7) simp_all hence "1 + ?int1 i \<ge> 1" by (intro f_approx_aux x0_hb_bound7) simp_all hence int_nonneg: "1 + ?int1 i \<ge> 0" by simp have "(?a i * ?b i powr p) * (c5 * x powr p * (1 + ?l) * (1 + ?int - c4*g x/x powr p)) = ?f * (1 + ?l) * (1 + ?int - c4*g x/x powr p)" (is "?expr = ?A * ?B") using x_pos b_pos[of "bs!i"] i by (subst powr_mult) simp_all also from rec.hyps i have "g_approx i x \<le> c4 * g x" by (intro c4) simp_all hence "c4*g x/x powr p \<ge> ?int2 i" unfolding g_approx_def using x_pos by (simp add: field_simps) hence "?A * ?B \<le> ?A * (1 + (?int - ?int2 i))" using i c5 a_ge_0 by (intro mult_left_mono mult_nonneg_nonneg) simp_all also from rec.hyps i have "x\<^sub>0 < bs ! i * x + (hs ! i) x" by (intro x0_hb_bound7) simp_all hence "?int - ?int2 i = ?int1 i" apply (subst diff_eq_eq, subst eq_commute) apply (intro integral_combine akra_bazzi_integrable) apply (insert rec.hyps step_le_x[OF i, of x], simp_all) done also have "?A * (1 + ?int1 i) = (c5*?a i*(1 + ?int1 i)) * ((?b i*x) powr p * (1 + ?l))" by (simp add: algebra_simps) also have "... \<le> (c5*?a i*(1 + ?int1 i)) * ((?b i*x + ?h i x) powr p * (1 + ?l' i))" using rec.hyps i c5 a_ge_0 int_nonneg by (intro mult_left_mono asymptotics1' mult_nonneg_nonneg) simp_all also have "... = ?a i*(c5*(1 + ?l' i)*f_approx (?b i*x + ?h i x))" by (simp add: algebra_simps f_approx_def) also from i have "... \<le> ?a i * f (?b i*x + ?h i x)" by (intro mult_left_mono a_ge_0 rec.IH) simp_all finally show "?expr \<le> ?a i * f (?b i*x + ?h i x)" . qed also have "... + g x = f x" using f_rec[of x] rec.hyps x0_le_x1 by simp finally show ?case by simp qed finally have "c5 * f_approx x \<le> f x" by simp } from this and c5(3) show ?thesis by (rule that) qed lemma akra_bazzi_bigomega: "f \<in> \<Omega>(\<lambda>x. x powr p * (1 + integral (\<lambda>u. g u / u powr (p + 1)) x\<^sub>0 x))" apply (fold f_approx_def, rule akra_bazzi_lower, erule landau_omega.bigI) apply (subst eventually_at_top_linorder, rule exI[of _ x\<^sub>0]) apply (simp add: f_nonneg f_approx_nonneg) done end locale akra_bazzi_real_upper = akra_bazzi_real + fixes fb1 c1 :: real assumes f_base1: "x \<ge> x\<^sub>0 \<Longrightarrow> x \<le> x\<^sub>1 \<Longrightarrow> f x \<le> fb1" and g_growth1: "\<forall>x\<ge>x\<^sub>1. \<forall>u\<in>{C*x..x}. c1 * g x \<le> g u" and c1_pos: "c1 > 0" begin interpretation akra_bazzi_integral integrable integral by (rule integral) lemma g_growth1': assumes "x \<ge> x\<^sub>1" "i < k" "u \<in> {bs!i*x+(hs!i) x..x}" shows "c1 * g x \<le> g u" proof- from assms have "C*x \<le> bs!i*x+(hs!i) x" by (intro Cx_le_step) with assms have "u \<in> {C*x..x}" by auto with assms g_growth1 show ?thesis by simp qed lemma g_bounds1: obtains c3 where "\<And>x i. x \<ge> x\<^sub>1 \<Longrightarrow> i < k \<Longrightarrow> c3 * g x \<le> g_approx i x" "c3 > 0" proof- define c3 where "c3 = Min {c1*((1-b)/2) / max 1 (max ((b/2) powr (p+1)) ((b*3/2) powr (p+1))) |b. b \<in> set bs}" { fix b assume b: "b \<in> set bs" let ?x = "max 1 (max ((b/2) powr (p+1)) ((b*3/2) powr (p+1)))" have "?x \<ge> 1" by simp hence "?x > 0" by (rule less_le_trans[OF zero_less_one]) with b b_less_1 c1_pos have "c1*((1-b)/2) / ?x > 0" by (intro divide_pos_pos mult_pos_pos) (simp_all add: algebra_simps) } hence "c3 > 0" unfolding c3_def by (subst Min_gr_iff) auto { fix x i assume i: "i < k" and x: "x \<ge> x\<^sub>1" with b_less_1 have b_less_1': "bs ! i < 1" by simp let ?m = "max 1 (max ((bs!i/2) powr (p+1)) ((bs!i*3/2) powr (p+1)))" from i x have "c3 \<le> c1*((1-bs!i)/2) / ?m" unfolding c3_def by (intro Min.coboundedI) auto also have "max 1 ((bs!i + (hs ! i) x / x) powr (p+1)) \<le> max 1 (max ((bs!i/2) powr (p+1)) ((bs!i*3/2) powr (p+1)))" apply (insert x i x0_le_x1 x1_pos step_pos[OF i x] b_pos[OF b_in_bs[OF i]], rule max.mono, simp, cases "p + 1 \<ge> 0") apply (rule order.trans[OF powr_mono2[OF _ _ x0_hb_bound5] max.cobounded2], simp_all add: field_simps) [] apply (rule order.trans[OF powr_mono2'[OF _ _ x0_hb_bound4'] max.cobounded1], simp_all add: field_simps) [] done with b_less_1' c1_pos have "c1*((1-bs!i)/2) / ?m \<le> c1*((1-bs!i)/2) / max 1 ((bs!i + (hs ! i) x / x) powr (p+1))" by (intro divide_left_mono mult_nonneg_nonneg) (simp_all add: algebra_simps) finally have "c3 \<le> c1*((1-bs!i)/2) / max 1 ((bs!i + (hs ! i) x / x) powr (p+1))" . } note c3 = this { fix x :: real and i :: nat assume x: "x \<ge> x\<^sub>1" and i: "i < k" from x x1_pos have x_pos: "x > 0" by simp let ?x' = "bs ! i * x + (hs ! i) x" let ?x'' = "bs ! i + (hs ! i) x / x" from x x1_ge_1 x0_le_x1 i c1_pos g_growth1' have c1: "c1 > 0" "\<forall>u\<in>{?x'..x}. g u \<ge> c1 * g x" by auto define b' where "b' = (1 - bs!i)/2" from x x0_le_x1 i have x'_le_x: "?x' \<le> x" by (intro step_le_x) simp_all let ?m = "max (?x' powr (p + 1)) (x powr (p + 1))" define m' where "m' = max 1 (?x'' powr (p + 1))" have [simp]: "bs ! i > 0" by (intro b_pos nth_mem) (simp add: i length_bs) from x x0_le_x1 i have x'_pos: "?x' > 0" by (intro step_pos) simp_all have m_pos: "?m > 0" unfolding max_def using x_pos step_pos[OF i x] by auto with x x0_le_x1 c1 have c1_g_m_nonneg: "c1 * g x / ?m \<ge> 0" by (intro mult_nonneg_nonneg divide_nonneg_pos g_nonneg) simp_all from x i g_nonneg x0_le_x1 have "c3 * (g x / x powr p) \<le> (c1*b'/m') * (g x / x powr p)" unfolding m'_def b'_def by (intro mult_right_mono c3) (simp_all add: field_simps) also from x_pos have "... = (x * b') * (c1 * g x / (x powr (p + 1) * m'))" by (simp add: field_simps powr_add) also from x i c1_pos x1_pos x0_le_x1 have "... \<le> (x - ?x') * (c1 * g x / (x powr (p + 1) * m'))" unfolding b'_def m'_def by (intro x0_hb_bound6 mult_right_mono mult_nonneg_nonneg divide_nonneg_nonneg g_nonneg) simp_all also have "x powr (p + 1) * m' = max (x powr (p + 1) * (bs ! i + (hs ! i) x / x) powr (p + 1)) (x powr (p + 1) * 1)" unfolding m'_def using x_pos by (subst max.commute, intro max_mult_left) simp also have "(x powr (p + 1) * (bs ! i + (hs ! i) x / x) powr (p + 1)) = (bs ! i + (hs ! i) x / x) powr (p + 1) * x powr (p + 1)" by simp also have "... = (bs ! i * x + (hs ! i) x) powr (p + 1)" using x x1_pos step_pos[OF i x] x_pos i x0_le_x1 x_pos by (subst powr_mult[symmetric]) (simp add: field_simps, simp, simp add: algebra_simps) also have "x powr (p + 1) * 1 = x powr (p + 1)" by simp also have "(x - ?x') * (c1 * g x / ?m) = integral (\<lambda>_. c1 * g x / ?m) ?x' x" using x'_le_x by (subst integral_const[OF c1_g_m_nonneg]) auto also { fix u assume u: "u \<ge> ?x'" "u \<le> x" have "u powr (p + 1) \<le> ?m" using x u x'_pos by (intro powr_upper_bound mult_pos_pos) simp_all moreover from x'_pos u have "u \<ge> 0" by simp moreover from c1 and u have "c1 * g x \<le> g u" by simp ultimately have "c1 * g x * u powr (p + 1) \<le> g u * ?m" using c1 x u x0_hb_bound7[OF x i] by (intro mult_mono g_nonneg) auto with m_pos u step_pos[OF i x] have "c1 * g x / ?m \<le> g u / u powr (p + 1)" by (simp add: field_simps) } hence "integral (\<lambda>_. c1 * g x / ?m) ?x' x \<le> integral (\<lambda>u. g u / u powr (p + 1)) ?x' x" using x0_hb_bound7[OF x i] x'_le_x by (intro integral_le ballI akra_bazzi_integrable integrable_const c1_g_m_nonneg) simp_all finally have "c3 * g x \<le> g_approx i x" using x_pos unfolding g_approx_def by (simp add: field_simps) } thus ?thesis using that \<open>c3 > 0\<close> by blast qed lemma f_bounded_above: assumes c': "c' > 0" obtains c where "\<And>x. x \<ge> x\<^sub>0 \<Longrightarrow> x \<le> x\<^sub>1 \<Longrightarrow> f x \<le> (1/2) * (c * f_approx x)" "c \<ge> c'" "c > 0" proof- obtain c where c: "\<And>x. x\<^sub>0 \<le> x \<Longrightarrow> x \<le> x\<^sub>1 \<Longrightarrow> f_approx x \<ge> c" "c > 0" by (rule f_approx_bounded_below) blast have fb1_nonneg: "fb1 \<ge> 0" using f_base1[of "x\<^sub>0"] f_nonneg[of x\<^sub>0] x0_le_x1 by simp { fix x assume x: "x \<ge> x\<^sub>0" "x \<le> x\<^sub>1" with f_base1 x0_pos have "f x \<le> fb1" by simp moreover from c and x have "f_approx x \<ge> c" by blast ultimately have "f x * c \<le> fb1 * f_approx x" using c fb1_nonneg by (intro mult_mono) simp_all also from f_approx_nonneg x have "... \<le> (fb1 + 1) * f_approx x" by (simp add: algebra_simps) finally have "f x \<le> ((fb1+1) / c) * f_approx x" by (simp add: field_simps c) also have "... \<le> max ((fb1+1) / c) c' * f_approx x" by (intro mult_right_mono) (simp_all add: f_approx_nonneg x) finally have "f x \<le> 1/2 * (max ((fb1+1) / c) c' * 2 * f_approx x)" by simp } moreover have "max ((fb1+1) / c) c' * 2 \<ge> max ((fb1+1) / c) c'" by (subst mult_le_cancel_left1) (insert c', simp) hence "max ((fb1+1) / c) c' * 2 \<ge> c'" by (rule order.trans[OF max.cobounded2]) moreover from fb1_nonneg and c have "(fb1+1) / c > 0" by simp hence "max ((fb1+1) / c) c' * 2 > 0" by simp ultimately show ?thesis by (rule that) qed lemma akra_bazzi_upper: obtains c6 where "\<And>x. x \<ge> x\<^sub>0 \<Longrightarrow> f x \<le> c6 * f_approx x" "c6 > 0" proof- obtain c3 where c3: "\<And>x i. x \<ge> x\<^sub>1 \<Longrightarrow> i < k \<Longrightarrow> c3 * g x \<le> g_approx i x" "c3 > 0" by (rule g_bounds1) blast hence "2 / c3 > 0" by simp then obtain c6 where c6: "\<And>x. x \<ge> x\<^sub>0 \<Longrightarrow> x \<le> x\<^sub>1 \<Longrightarrow> f x \<le> 1/2 * (c6 * f_approx x)" "c6 \<ge> 2 / c3" "c6 > 0" by (rule f_bounded_above) blast { fix x :: real assume x: "x \<ge> x\<^sub>0" hence "f x \<le> c6 * (1 - ln x powr (-e/2)) * f_approx x" proof (induction x rule: akra_bazzi_induct) case (base x) from base have "f x \<le> 1/2 * (c6 * f_approx x)" by (intro c6) simp_all also have "1 - ln x powr (-e/2) \<ge> 1/2" using asymptotics4 base by simp hence "(1 - ln x powr (-e/2)) * (c6 * f_approx x) \<ge> 1/2 * (c6 * f_approx x)" using c6 f_approx_nonneg base x0_ge_1 by (intro mult_right_mono mult_nonneg_nonneg) simp_all finally show ?case by (simp add: algebra_simps) next case (rec x) let ?a = "\<lambda>i. as!i" and ?b = "\<lambda>i. bs!i" and ?h = "\<lambda>i. hs!i" let ?int = "integral (\<lambda>u. g u / u powr (p+1)) x\<^sub>0 x" let ?int1 = "\<lambda>i. integral (\<lambda>u. g u / u powr (p+1)) x\<^sub>0 (?b i*x+?h i x)" let ?int2 = "\<lambda>i. integral (\<lambda>u. g u / u powr (p+1)) (?b i*x+?h i x) x" let ?l = "ln x powr (-e/2)" and ?l' = "\<lambda>i. ln (?b i*x + ?h i x) powr (-e/2)" from rec and x0_le_x1 have x: "x \<ge> x\<^sub>0" by simp with x0_pos have x_pos: "x > 0" and x_nonneg: "x \<ge> 0" by simp_all from c6 c3 have "c6 * c3 \<ge> 2" by (simp add: field_simps) have "f x = (\<Sum>i<k. ?a i * f (?b i*x + ?h i x)) + g x" (is "_ = ?sum + _") using f_rec[of x] rec.hyps x0_le_x1 by simp also have "?sum \<le> (\<Sum>i<k. (?a i*?b i powr p) * (c6*x powr p*(1 - ?l)*(1 + ?int - c3*g x/x powr p)))" (is "_ \<le> ?sum'") proof (rule sum_mono, clarify) fix i assume i: "i < k" from rec.hyps i have "x\<^sub>0 < bs ! i * x + (hs ! i) x" by (intro x0_hb_bound7) simp_all hence "1 + ?int1 i \<ge> 1" by (intro f_approx_aux x0_hb_bound7) simp_all hence int_nonneg: "1 + ?int1 i \<ge> 0" by simp have l_le_1: "ln x powr -(e/2) \<le> 1" using asymptotics3[OF x] by (simp add: field_simps) from i have "f (?b i*x + ?h i x) \<le> c6 * (1 - ?l' i) * f_approx (?b i*x + ?h i x)" by (rule rec.IH) hence "?a i * f (?b i*x + ?h i x) \<le> ?a i * ..." using a_ge_0 i by (intro mult_left_mono) simp_all also have "... = (c6*?a i*(1 + ?int1 i)) * ((?b i*x + ?h i x) powr p * (1 - ?l' i))" unfolding f_approx_def by (simp add: algebra_simps) also from i rec.hyps c6 a_ge_0 have "... \<le> (c6*?a i*(1 + ?int1 i)) * ((?b i*x) powr p * (1 - ?l))" by (intro mult_left_mono asymptotics2' mult_nonneg_nonneg int_nonneg) simp_all also have "... = (1 + ?int1 i) * (c6*?a i*(?b i*x) powr p * (1 - ?l))" by (simp add: algebra_simps) also from rec.hyps i have "x\<^sub>0 < bs ! i * x + (hs ! i) x" by (intro x0_hb_bound7) simp_all hence "?int1 i = ?int - ?int2 i" apply (subst eq_diff_eq) apply (intro integral_combine akra_bazzi_integrable) apply (insert rec.hyps step_le_x[OF i, of x], simp_all) done also from rec.hyps i have "c3 * g x \<le> g_approx i x" by (intro c3) simp_all hence "?int2 i \<ge> c3*g x/x powr p" unfolding g_approx_def using x_pos by (simp add: field_simps) hence "(1 + (?int - ?int2 i)) * (c6*?a i*(?b i*x) powr p * (1 - ?l)) \<le> (1 + ?int - c3*g x/x powr p) * (c6*?a i*(?b i*x) powr p * (1 - ?l))" using i c6 a_ge_0 l_le_1 by (intro mult_right_mono mult_nonneg_nonneg) (simp_all add: field_simps) also have "... = (?a i*?b i powr p) * (c6*x powr p*(1 - ?l) * (1 + ?int - c3*g x/x powr p))" using b_pos[of "bs!i"] x x0_pos i by (subst powr_mult) (simp_all add: algebra_simps) finally show "?a i * f (?b i*x + ?h i x) \<le> ..." . qed hence "?sum + g x \<le> ?sum' + g x" by simp also have "... = c6 * x powr p * (1 - ?l) * (1 + ?int - c3*g x/x powr p) + g x" by (simp add: sum_distrib_right[symmetric] p_props) also have "... = c6 * (1 - ?l) * f_approx x - (c6*c3*(1 - ?l) - 1) * g x" unfolding f_approx_def using x_pos by (simp add: field_simps) also { from c6 c3 have "c6*c3 \<ge> 2" by (simp add: field_simps) moreover have "(1 - ?l) \<ge> 1/2" using asymptotics4[OF x] by simp ultimately have "c6*c3*(1 - ?l) \<ge> 2 * (1/2)" by (intro mult_mono) simp_all with x x_pos have "(c6*c3*(1 - ?l) - 1) * g x \<ge> 0" by (intro mult_nonneg_nonneg g_nonneg) simp_all hence "c6 * (1 - ?l) * f_approx x - (c6*c3*(1 - ?l) - 1) * g x \<le> c6 * (1 - ?l) * f_approx x" by (simp add: algebra_simps) } finally show ?case . qed also from x c6 have "... \<le> c6 * 1 * f_approx x" by (intro mult_left_mono mult_right_mono f_approx_nonneg) simp_all finally have "f x \<le> c6 * f_approx x" by simp } from this and c6(3) show ?thesis by (rule that) qed lemma akra_bazzi_bigo: "f \<in> O(\<lambda>x. x powr p *(1 + integral (\<lambda>u. g u / u powr (p + 1)) x\<^sub>0 x))" apply (fold f_approx_def, rule akra_bazzi_upper, erule landau_o.bigI) apply (subst eventually_at_top_linorder, rule exI[of _ x\<^sub>0]) apply (simp add: f_nonneg f_approx_nonneg) done end end
section \<open>Algebra of Monotonic Boolean Transformers\<close> theory Mono_Bool_Tran_Algebra imports Mono_Bool_Tran begin text\<open> In this section we introduce the {\em algebra of monotonic boolean transformers}. This is a bounded distributive lattice with a monoid operation, a dual operator and an iteration operator. The standard model for this algebra is the set of monotonic boolean transformers introduced in the previous section. \<close> class dual = fixes dual::"'a \<Rightarrow> 'a" ("_ ^ o" [81] 80) class omega = fixes omega::"'a \<Rightarrow> 'a" ("_ ^ \<omega>" [81] 80) class star = fixes star::"'a \<Rightarrow> 'a" ("(_ ^ *)" [81] 80) class dual_star = fixes dual_star::"'a \<Rightarrow> 'a" ("(_ ^ \<otimes>)" [81] 80) class mbt_algebra = monoid_mult + dual + omega + distrib_lattice + order_top + order_bot + star + dual_star + assumes dual_le: "(x \<le> y) = (y ^ o \<le> x ^ o)" and dual_dual [simp]: "(x ^ o) ^ o = x" and dual_comp: "(x * y) ^ o = x ^ o * y ^ o" and dual_one [simp]: "1 ^ o = 1" and top_comp [simp]: "\<top> * x = \<top>" and inf_comp: "(x \<sqinter> y) * z = (x * z) \<sqinter> (y * z)" and le_comp: "x \<le> y \<Longrightarrow> z * x \<le> z * y" and dual_neg: "(x * \<top>) \<sqinter> (x ^ o * \<bottom>) = \<bottom>" and omega_fix: "x ^ \<omega> = (x * (x ^ \<omega>)) \<sqinter> 1" and omega_least: "(x * z) \<sqinter> y \<le> z \<Longrightarrow> (x ^ \<omega>) * y \<le> z" and star_fix: "x ^ * = (x * (x ^ *)) \<sqinter> 1" and star_greatest: "z \<le> (x * z) \<sqinter> y \<Longrightarrow> z \<le> (x ^ *) * y" and dual_star_def: "(x ^ \<otimes>) = (((x ^ o) ^ *) ^ o)" begin lemma le_comp_right: "x \<le> y \<Longrightarrow> x * z \<le> y * z" apply (cut_tac x = x and y = y and z = z in inf_comp) apply (simp add: inf_absorb1) apply (subgoal_tac "x * z \<sqinter> (y * z) \<le> y * z") apply simp by (rule inf_le2) subclass bounded_lattice proof qed end instantiation MonoTran :: (complete_boolean_algebra) mbt_algebra begin lift_definition dual_MonoTran :: "'a MonoTran \<Rightarrow> 'a MonoTran" is dual_fun by (fact mono_dual_fun) lift_definition omega_MonoTran :: "'a MonoTran \<Rightarrow> 'a MonoTran" is omega_fun by (fact mono_omega_fun) lift_definition star_MonoTran :: "'a MonoTran \<Rightarrow> 'a MonoTran" is star_fun by (fact mono_star_fun) definition dual_star_MonoTran :: "'a MonoTran \<Rightarrow> 'a MonoTran" where "(x::('a MonoTran)) ^ \<otimes> = ((x ^ o) ^ *) ^ o" instance proof fix x y :: "'a MonoTran" show "(x \<le> y) = (y ^ o \<le> x ^ o)" apply transfer apply (auto simp add: fun_eq_iff le_fun_def) apply (drule_tac x = "-xa" in spec) apply simp done next fix x :: "'a MonoTran" show "(x ^ o) ^ o = x" apply transfer apply (simp add: fun_eq_iff) done next fix x y :: "'a MonoTran" show "(x * y) ^ o = x ^ o * y ^ o" apply transfer apply (simp add: fun_eq_iff) done next show "(1::'a MonoTran) ^ o = 1" apply transfer apply (simp add: fun_eq_iff) done next fix x :: "'a MonoTran" show "\<top> * x = \<top>" apply transfer apply (simp add: fun_eq_iff) done next fix x y z :: "'a MonoTran" show "(x \<sqinter> y) * z = (x * z) \<sqinter> (y * z)" apply transfer apply (simp add: fun_eq_iff) done next fix x y z :: "'a MonoTran" assume A: "x \<le> y" from A show " z * x \<le> z * y" apply transfer apply (auto simp add: le_fun_def elim: monoE) done next fix x :: "'a MonoTran" show "x * \<top> \<sqinter> (x ^ o * \<bottom>) = \<bottom>" apply transfer apply (simp add: fun_eq_iff) done next fix x :: "'a MonoTran" show "x ^ \<omega> = x * x ^ \<omega> \<sqinter> 1" apply transfer apply (simp add: fun_eq_iff) apply (simp add: omega_fun_def Omega_fun_def) apply (subst lfp_unfold, simp_all add: ac_simps) apply (auto intro!: mono_comp mono_comp_fun) done next fix x y z :: "'a MonoTran" assume A: "x * z \<sqinter> y \<le> z" from A show "x ^ \<omega> * y \<le> z" apply transfer apply (auto simp add: lfp_omega lfp_def) apply (rule Inf_lower) apply (auto simp add: Omega_fun_def ac_simps) done next fix x :: "'a MonoTran" show "x ^ * = x * x ^ * \<sqinter> 1" apply transfer apply (auto simp add: star_fun_def Omega_fun_def) apply (subst gfp_unfold, simp_all add: ac_simps) apply (auto intro!: mono_comp mono_comp_fun) done next fix x y z :: "'a MonoTran" assume A: "z \<le> x * z \<sqinter> y" from A show "z \<le> x ^ * * y" apply transfer apply (auto simp add: gfp_star gfp_def) apply (rule Sup_upper) apply (auto simp add: Omega_fun_def) done next fix x :: "'a MonoTran" show "x ^ \<otimes> = ((x ^ o) ^ *) ^ o" by (simp add: dual_star_MonoTran_def) qed end context mbt_algebra begin lemma dual_top [simp]: "\<top> ^ o = \<bottom>" apply (rule antisym, simp_all) by (subst dual_le, simp) lemma dual_bot [simp]: "\<bottom> ^ o = \<top>" apply (rule antisym, simp_all) by (subst dual_le, simp) lemma dual_inf: "(x \<sqinter> y) ^ o = (x ^ o) \<squnion> (y ^ o)" apply (rule antisym, simp_all, safe) apply (subst dual_le, simp, safe) apply (subst dual_le, simp) apply (subst dual_le, simp) apply (subst dual_le, simp) by (subst dual_le, simp) lemma dual_sup: "(x \<squnion> y) ^ o = (x ^ o) \<sqinter> (y ^ o)" apply (rule antisym, simp_all, safe) apply (subst dual_le, simp) apply (subst dual_le, simp) apply (subst dual_le, simp, safe) apply (subst dual_le, simp) by (subst dual_le, simp) lemma sup_comp: "(x \<squnion> y) * z = (x * z) \<squnion> (y * z)" apply (subgoal_tac "((x ^ o \<sqinter> y ^ o) * z ^ o) ^ o = ((x ^ o * z ^ o) \<sqinter> (y ^ o * z ^ o)) ^ o") apply (simp add: dual_inf dual_comp) by (simp add: inf_comp) lemma dual_eq: "x ^ o = y ^ o \<Longrightarrow> x = y" apply (subgoal_tac "(x ^ o) ^ o = (y ^ o) ^ o") apply (subst (asm) dual_dual) apply (subst (asm) dual_dual) by simp_all lemma dual_neg_top [simp]: "(x ^ o * \<bottom>) \<squnion> (x * \<top>) = \<top>" apply (rule dual_eq) by(simp add: dual_sup dual_comp dual_neg) lemma [simp]: "(x * \<bottom>) * y = x * \<bottom>" by (simp add: mult.assoc) lemma gt_one_comp: "1 \<le> x \<Longrightarrow> y \<le> x * y" by (cut_tac x = 1 and y = x and z = y in le_comp_right, simp_all) theorem omega_comp_fix: "x ^ \<omega> * y = (x * (x ^ \<omega>) * y) \<sqinter> y" apply (subst omega_fix) by (simp add: inf_comp) theorem dual_star_fix: "x^\<otimes> = (x * (x^\<otimes>)) \<squnion> 1" by (metis dual_comp dual_dual dual_inf dual_one dual_star_def star_fix) theorem star_comp_fix: "x ^ * * y = (x * (x ^ *) * y) \<sqinter> y" apply (subst star_fix) by (simp add: inf_comp) theorem dual_star_comp_fix: "x^\<otimes> * y = (x * (x^\<otimes>) * y) \<squnion> y" apply (subst dual_star_fix) by (simp add: sup_comp) theorem dual_star_least: "(x * z) \<squnion> y \<le> z \<Longrightarrow> (x^\<otimes>) * y \<le> z" apply (subst dual_le) apply (simp add: dual_star_def dual_comp) apply (rule star_greatest) apply (subst dual_le) by (simp add: dual_inf dual_comp) lemma omega_one [simp]: "1 ^ \<omega> = \<bottom>" apply (rule antisym, simp_all) by (cut_tac x = "1::'a" and y = 1 and z = \<bottom> in omega_least, simp_all) lemma omega_mono: "x \<le> y \<Longrightarrow> x ^ \<omega> \<le> y ^ \<omega>" apply (cut_tac x = x and y = 1 and z = "y ^ \<omega>" in omega_least, simp_all) apply (subst (2) omega_fix, simp_all) apply (rule_tac y = "x * y ^ \<omega>" in order_trans, simp) by (rule le_comp_right, simp) end sublocale mbt_algebra < conjunctive "inf" "inf" "times" done sublocale mbt_algebra < disjunctive "sup" "sup" "times" done context mbt_algebra begin lemma dual_conjunctive: "x \<in> conjunctive \<Longrightarrow> x ^ o \<in> disjunctive" apply (simp add: conjunctive_def disjunctive_def) apply safe apply (rule dual_eq) by (simp add: dual_comp dual_sup) lemma dual_disjunctive: "x \<in> disjunctive \<Longrightarrow> x ^ o \<in> conjunctive" apply (simp add: conjunctive_def disjunctive_def) apply safe apply (rule dual_eq) by (simp add: dual_comp dual_inf) lemma comp_pres_conj: "x \<in> conjunctive \<Longrightarrow> y \<in> conjunctive \<Longrightarrow> x * y \<in> conjunctive" apply (subst conjunctive_def, safe) by (simp add: mult.assoc conjunctiveD) lemma comp_pres_disj: "x \<in> disjunctive \<Longrightarrow> y \<in> disjunctive \<Longrightarrow> x * y \<in> disjunctive" apply (subst disjunctive_def, safe) by (simp add: mult.assoc disjunctiveD) lemma start_pres_conj: "x \<in> conjunctive \<Longrightarrow> (x ^ *) \<in> conjunctive" apply (subst conjunctive_def, safe) apply (rule antisym, simp_all) apply (metis inf_le1 inf_le2 le_comp) apply (rule star_greatest) apply (subst conjunctiveD, simp) apply (subst star_comp_fix) apply (subst star_comp_fix) by (metis inf.assoc inf_left_commute mult.assoc order_refl) lemma dual_star_pres_disj: "x \<in> disjunctive \<Longrightarrow> x^\<otimes> \<in> disjunctive" apply (simp add: dual_star_def) apply (rule dual_conjunctive) apply (rule start_pres_conj) by (rule dual_disjunctive, simp) subsection\<open>Assertions\<close> text\<open> Usually, in Kleene algebra with tests or in other progrm algebras, tests or assertions or assumptions are defined using an existential quantifier. An element of the algebra is a test if it has a complement with respect to $\bot$ and $1$. In this formalization assertions can be defined much simpler using the dual operator. \<close> definition "assertion = {x . x \<le> 1 \<and> (x * \<top>) \<sqinter> (x ^ o) = x}" lemma assertion_prop: "x \<in> assertion \<Longrightarrow> (x * \<top>) \<sqinter> 1 = x" apply (simp add: assertion_def) apply safe apply (rule antisym) apply simp_all proof - assume [simp]: "x \<le> 1" assume A: "x * \<top> \<sqinter> x ^ o = x" have "x * \<top> \<sqinter> 1 \<le> x * \<top> \<sqinter> x ^ o" apply simp apply (rule_tac y = 1 in order_trans) apply simp apply (subst dual_le) by simp also have "\<dots> = x" by (cut_tac A, simp) finally show "x * \<top> \<sqinter> 1 \<le> x" . next assume A: "x * \<top> \<sqinter> x ^ o = x" have "x = x * \<top> \<sqinter> x ^ o" by (simp add: A) also have "\<dots> \<le> x * \<top>" by simp finally show "x \<le> x * \<top>" . qed lemma dual_assertion_prop: "x \<in> assertion \<Longrightarrow> ((x ^ o) * \<bottom>) \<squnion> 1 = x ^ o" apply (rule dual_eq) by (simp add: dual_sup dual_comp assertion_prop) lemma assertion_disjunctive: "x \<in> assertion \<Longrightarrow> x \<in> disjunctive" apply (simp add: disjunctive_def, safe) apply (drule assertion_prop) proof - assume A: "x * \<top> \<sqinter> 1 = x" fix y z::"'a" have "x * (y \<squnion> z) = (x * \<top> \<sqinter> 1) * (y \<squnion> z)" by (cut_tac A, simp) also have "\<dots> = (x * \<top>) \<sqinter> (y \<squnion> z)" by (simp add: inf_comp) also have "\<dots> = ((x * \<top>) \<sqinter> y) \<squnion> ((x * \<top>) \<sqinter> z)" by (simp add: inf_sup_distrib) also have "\<dots> = (((x * \<top>) \<sqinter> 1) * y) \<squnion> (((x * \<top>) \<sqinter> 1) * z)" by (simp add: inf_comp) also have "\<dots> = x * y \<squnion> x * z" by (cut_tac A, simp) finally show "x * (y \<squnion> z) = x * y \<squnion> x * z" . qed lemma Abs_MonoTran_injective: "mono x \<Longrightarrow> mono y \<Longrightarrow> Abs_MonoTran x = Abs_MonoTran y \<Longrightarrow> x = y" apply (subgoal_tac "Rep_MonoTran (Abs_MonoTran x) = Rep_MonoTran (Abs_MonoTran y)") apply (subst (asm) Abs_MonoTran_inverse, simp) by (subst (asm) Abs_MonoTran_inverse, simp_all) end lemma mbta_MonoTran_disjunctive: "Rep_MonoTran ` disjunctive = Apply.disjunctive" apply (simp add: disjunctive_def Apply.disjunctive_def) apply transfer apply auto proof - fix f :: "'a \<Rightarrow> 'a" and a b assume prem: "\<forall>y. mono y \<longrightarrow> (\<forall>z. mono z \<longrightarrow> f \<circ> y \<squnion> z = (f \<circ> y) \<squnion> (f \<circ> z))" { fix g h :: "'b \<Rightarrow> 'a" assume "mono g" and "mono h" then have "f \<circ> g \<squnion> h = (f \<circ> g) \<squnion> (f \<circ> h)" using prem by blast } note * = this assume "mono f" show "f (a \<squnion> b) = f a \<squnion> f b" (is "?P = ?Q") proof (rule order_antisym) show "?P \<le> ?Q" using * [of "\<lambda>_. a" "\<lambda>_. b"] by (simp add: comp_def fun_eq_iff) next from \<open>mono f\<close> show "?Q \<le> ?P" by (rule Lattices.semilattice_sup_class.mono_sup) qed next fix f :: "'a \<Rightarrow> 'a" assume "\<forall>y z. f (y \<squnion> z) = f y \<squnion> f z" then have *: "\<And>y z. f (y \<squnion> z) = f y \<squnion> f z" by blast show "mono f" proof fix a b :: 'a assume "a \<le> b" then show "f a \<le> f b" unfolding sup.order_iff * [symmetric] by simp qed qed lemma assertion_MonoTran: "assertion = Abs_MonoTran ` assertion_fun" apply (safe) apply (subst assertion_fun_disj_less_one) apply (simp add: image_def) apply (rule_tac x = "Rep_MonoTran x" in bexI) apply (simp add: Rep_MonoTran_inverse) apply safe apply (drule assertion_disjunctive) apply (unfold mbta_MonoTran_disjunctive [THEN sym], simp) apply (simp add: assertion_def less_eq_MonoTran_def one_MonoTran_def Abs_MonoTran_inverse) apply (simp add: assertion_def) by (simp_all add: inf_MonoTran_def less_eq_MonoTran_def times_MonoTran_def dual_MonoTran_def top_MonoTran_def Abs_MonoTran_inverse one_MonoTran_def assertion_fun_dual) context mbt_algebra begin lemma assertion_conjunctive: "x \<in> assertion \<Longrightarrow> x \<in> conjunctive" apply (simp add: conjunctive_def, safe) apply (drule assertion_prop) proof - assume A: "x * \<top> \<sqinter> 1 = x" fix y z::"'a" have "x * (y \<sqinter> z) = (x * \<top> \<sqinter> 1) * (y \<sqinter> z)" by (cut_tac A, simp) also have "\<dots> = (x * \<top>) \<sqinter> (y \<sqinter> z)" by (simp add: inf_comp) also have "\<dots> = ((x * \<top>) \<sqinter> y) \<sqinter> ((x * \<top>) \<sqinter> z)" apply (rule antisym, simp_all, safe) apply (rule_tac y = "y \<sqinter> z" in order_trans) apply (rule inf_le2) apply simp apply (rule_tac y = "y \<sqinter> z" in order_trans) apply (rule inf_le2) apply simp_all apply (simp add: inf_assoc) apply (rule_tac y = " x * \<top> \<sqinter> y" in order_trans) apply (rule inf_le1) apply simp apply (rule_tac y = " x * \<top> \<sqinter> z" in order_trans) apply (rule inf_le2) by simp also have "\<dots> = (((x * \<top>) \<sqinter> 1) * y) \<sqinter> (((x * \<top>) \<sqinter> 1) * z)" by (simp add: inf_comp) also have "\<dots> = (x * y) \<sqinter> (x * z)" by (cut_tac A, simp) finally show "x * (y \<sqinter> z) = (x * y) \<sqinter> (x * z)" . qed lemma dual_assertion_conjunctive: "x \<in> assertion \<Longrightarrow> x ^ o \<in> conjunctive" apply (drule assertion_disjunctive) by (rule dual_disjunctive, simp) lemma dual_assertion_disjunct: "x \<in> assertion \<Longrightarrow> x ^ o \<in> disjunctive" apply (drule assertion_conjunctive) by (rule dual_conjunctive, simp) lemma [simp]: "x \<in> assertion \<Longrightarrow> y \<in> assertion \<Longrightarrow> x \<sqinter> y \<le> x * y" apply (simp add: assertion_def, safe) proof - assume A: "x \<le> 1" assume B: "x * \<top> \<sqinter> x ^ o = x" assume C: "y \<le> 1" assume D: "y * \<top> \<sqinter> y ^ o = y" have "x \<sqinter> y = (x * \<top> \<sqinter> x ^ o) \<sqinter> (y * \<top> \<sqinter> y ^ o)" by (cut_tac B D, simp) also have "\<dots> \<le> (x * \<top>) \<sqinter> (((x^o) * (y * \<top>)) \<sqinter> ((x^o) * (y^o)))" apply (simp, safe) apply (rule_tac y = "x * \<top> \<sqinter> x ^ o" in order_trans) apply (rule inf_le1) apply simp apply (rule_tac y = "y * \<top>" in order_trans) apply (rule_tac y = "y * \<top> \<sqinter> y ^ o" in order_trans) apply (rule inf_le2) apply simp apply (rule gt_one_comp) apply (subst dual_le, simp add: A) apply (rule_tac y = "y ^ o" in order_trans) apply (rule_tac y = "y * \<top> \<sqinter> y ^ o" in order_trans) apply (rule inf_le2) apply simp apply (rule gt_one_comp) by (subst dual_le, simp add: A) also have "... = ((x * \<top>) \<sqinter> (x ^ o)) * ((y * \<top>) \<sqinter> (y ^ o))" apply (cut_tac x = x in dual_assertion_conjunctive) apply (cut_tac A, cut_tac B, simp add: assertion_def) by (simp add: inf_comp conjunctiveD) also have "... = x * y" by (cut_tac B, cut_tac D, simp) finally show "x \<sqinter> y \<le> x * y" . qed lemma [simp]: "x \<in> assertion \<Longrightarrow> x * y \<le> y" by (unfold assertion_def, cut_tac x = x and y = 1 and z = y in le_comp_right, simp_all) lemma [simp]: "x \<in> assertion \<Longrightarrow> y \<in> assertion \<Longrightarrow> x * y \<le> x" apply (subgoal_tac "x * y \<le> (x * \<top>) \<sqinter> (x ^ o)") apply (simp add: assertion_def) apply (simp, safe) apply (rule le_comp, simp) apply (rule_tac y = 1 in order_trans) apply (rule_tac y = y in order_trans) apply simp apply (simp add: assertion_def) by (subst dual_le, simp add: assertion_def) lemma assertion_inf_comp_eq: "x \<in> assertion \<Longrightarrow> y \<in> assertion \<Longrightarrow> x \<sqinter> y = x * y" by (rule antisym, simp_all) lemma one_right_assertion [simp]: "x \<in> assertion \<Longrightarrow> x * 1 = x" apply (drule assertion_prop) proof - assume A: "x * \<top> \<sqinter> 1 = x" have "x * 1 = (x * \<top> \<sqinter> 1) * 1" by (simp add: A) also have "\<dots> = x * \<top> \<sqinter> 1" by (simp add: inf_comp) also have "\<dots> = x" by (simp add: A) finally show ?thesis . qed lemma [simp]: "x \<in> assertion \<Longrightarrow> x \<squnion> 1 = 1" by (rule antisym, simp_all add: assertion_def) lemma [simp]: "x \<in> assertion \<Longrightarrow> 1 \<squnion> x = 1" by (rule antisym, simp_all add: assertion_def) lemma [simp]: "x \<in> assertion \<Longrightarrow> x \<sqinter> 1 = x" by (rule antisym, simp_all add: assertion_def) lemma [simp]: "x \<in> assertion \<Longrightarrow> 1 \<sqinter> x = x" by (rule antisym, simp_all add: assertion_def) lemma [simp]: "x \<in> assertion \<Longrightarrow> x \<le> x * \<top>" by (cut_tac x = 1 and y = \<top> and z = x in le_comp, simp_all) lemma [simp]: "x \<in> assertion \<Longrightarrow> x \<le> 1" by (simp add: assertion_def) definition "neg_assert (x::'a) = (x ^ o * \<bottom>) \<sqinter> 1" lemma sup_uminus[simp]: "x \<in> assertion \<Longrightarrow> x \<squnion> neg_assert x = 1" apply (simp add: neg_assert_def) apply (simp add: sup_inf_distrib) apply (rule antisym, simp_all) apply (unfold assertion_def) apply safe apply (subst dual_le) apply (simp add: dual_sup dual_comp) apply (subst inf_commute) by simp lemma inf_uminus[simp]: "x \<in> assertion \<Longrightarrow> x \<sqinter> neg_assert x = \<bottom>" apply (simp add: neg_assert_def) apply (rule antisym, simp_all) apply (rule_tac y = "x \<sqinter> (x ^ o * \<bottom>)" in order_trans) apply simp apply (rule_tac y = "x ^ o * \<bottom> \<sqinter> 1" in order_trans) apply (rule inf_le2) apply simp apply (rule_tac y = "(x * \<top>) \<sqinter> (x ^ o * \<bottom>)" in order_trans) apply simp apply (rule_tac y = x in order_trans) apply simp_all by (simp add: dual_neg) lemma uminus_assertion[simp]: "x \<in> assertion \<Longrightarrow> neg_assert x \<in> assertion" apply (subst assertion_def) apply (simp add: neg_assert_def) apply (simp add: inf_comp dual_inf dual_comp inf_sup_distrib) apply (subst inf_commute) by (simp add: dual_neg) lemma uminus_uminus [simp]: "x \<in> assertion \<Longrightarrow> neg_assert (neg_assert x) = x" apply (simp add: neg_assert_def) by (simp add: dual_inf dual_comp sup_comp assertion_prop) lemma dual_comp_neg [simp]: "x ^ o * y \<squnion> (neg_assert x) * \<top> = x ^ o * y" apply (simp add: neg_assert_def inf_comp) apply (rule antisym, simp_all) by (rule le_comp, simp) lemma [simp]: "(neg_assert x) ^ o * y \<squnion> x * \<top> = (neg_assert x) ^ o * y" apply (simp add: neg_assert_def inf_comp dual_inf dual_comp sup_comp) by (rule antisym, simp_all) lemma [simp]: " x * \<top> \<squnion> (neg_assert x) ^ o * y= (neg_assert x) ^ o * y" by (simp add: neg_assert_def inf_comp dual_inf dual_comp sup_comp) lemma inf_assertion [simp]: "x \<in> assertion \<Longrightarrow> y \<in> assertion \<Longrightarrow> x \<sqinter> y \<in> assertion" apply (subst assertion_def) apply safe apply (rule_tac y = x in order_trans) apply simp_all apply (simp add: assertion_inf_comp_eq) proof - assume A: "x \<in> assertion" assume B: "y \<in> assertion" have C: "(x * \<top>) \<sqinter> (x ^ o) = x" by (cut_tac A, unfold assertion_def, simp) have D: "(y * \<top>) \<sqinter> (y ^ o) = y" by (cut_tac B, unfold assertion_def, simp) have "x * y = ((x * \<top>) \<sqinter> (x ^ o)) * ((y * \<top>) \<sqinter> (y ^ o))" by (simp add: C D) also have "\<dots> = x * \<top> \<sqinter> ((x ^ o) * ((y * \<top>) \<sqinter> (y ^ o)))" by (simp add: inf_comp) also have "\<dots> = x * \<top> \<sqinter> ((x ^ o) * (y * \<top>)) \<sqinter> ((x ^ o) *(y ^ o))" by (cut_tac A, cut_tac x = x in dual_assertion_conjunctive, simp_all add: conjunctiveD inf_assoc) also have "\<dots> = (((x * \<top>) \<sqinter> (x ^ o)) * (y * \<top>)) \<sqinter> ((x ^ o) *(y ^ o))" by (simp add: inf_comp) also have "\<dots> = (x * y * \<top>) \<sqinter> ((x * y) ^ o)" by (simp add: C mult.assoc dual_comp) finally show "(x * y * \<top>) \<sqinter> ((x * y) ^ o) = x * y" by simp qed lemma comp_assertion [simp]: "x \<in> assertion \<Longrightarrow> y \<in> assertion \<Longrightarrow> x * y \<in> assertion" by (subst assertion_inf_comp_eq [THEN sym], simp_all) lemma sup_assertion [simp]: "x \<in> assertion \<Longrightarrow> y \<in> assertion \<Longrightarrow> x \<squnion> y \<in> assertion" apply (subst assertion_def) apply safe apply (unfold assertion_def) apply simp apply safe proof - assume [simp]: "x \<le> 1" assume [simp]: "y \<le> 1" assume A: "x * \<top> \<sqinter> x ^ o = x" assume B: "y * \<top> \<sqinter> y ^ o = y" have "(y * \<top>) \<sqinter> (x ^ o) \<sqinter> (y ^ o) = (x ^ o) \<sqinter> (y * \<top>) \<sqinter> (y ^ o)" by (simp add: inf_commute) also have "\<dots> = (x ^ o) \<sqinter> ((y * \<top>) \<sqinter> (y ^ o))" by (simp add: inf_assoc) also have "\<dots> = (x ^ o) \<sqinter> y" by (simp add: B) also have "\<dots> = y" apply (rule antisym, simp_all) apply (rule_tac y = 1 in order_trans) apply simp by (subst dual_le, simp) finally have [simp]: "(y * \<top>) \<sqinter> (x ^ o) \<sqinter> (y ^ o) = y" . have "x * \<top> \<sqinter> (x ^ o) \<sqinter> (y ^ o) = x \<sqinter> (y ^ o)" by (simp add: A) also have "\<dots> = x" apply (rule antisym, simp_all) apply (rule_tac y = 1 in order_trans) apply simp by (subst dual_le, simp) finally have [simp]: "x * \<top> \<sqinter> (x ^ o) \<sqinter> (y ^ o) = x" . have "(x \<squnion> y) * \<top> \<sqinter> (x \<squnion> y) ^ o = (x * \<top> \<squnion> y * \<top>) \<sqinter> ((x ^ o) \<sqinter> (y ^ o))" by (simp add: sup_comp dual_sup) also have "\<dots> = x \<squnion> y" by (simp add: inf_sup_distrib inf_assoc [THEN sym]) finally show "(x \<squnion> y) * \<top> \<sqinter> (x \<squnion> y) ^ o = x \<squnion> y" . qed lemma [simp]: "x \<in> assertion \<Longrightarrow> x * x = x" by (simp add: assertion_inf_comp_eq [THEN sym]) lemma [simp]: "x \<in> assertion \<Longrightarrow> (x ^ o) * (x ^ o) = x ^ o" apply (rule dual_eq) by (simp add: dual_comp assertion_inf_comp_eq [THEN sym]) lemma [simp]: "x \<in> assertion \<Longrightarrow> x * (x ^ o) = x" proof - assume A: "x \<in> assertion" have B: "x * \<top> \<sqinter> (x ^ o) = x" by (cut_tac A, unfold assertion_def, simp) have "x * x ^ o = (x * \<top> \<sqinter> (x ^ o)) * x ^ o" by (simp add: B) also have "\<dots> = x * \<top> \<sqinter> (x ^ o)" by (cut_tac A, simp add: inf_comp) also have "\<dots> = x" by (simp add: B) finally show ?thesis . qed lemma [simp]: "x \<in> assertion \<Longrightarrow> (x ^ o) * x = x ^ o" apply (rule dual_eq) by (simp add: dual_comp) lemma [simp]: "\<bottom> \<in> assertion" by (unfold assertion_def, simp) lemma [simp]: "1 \<in> assertion" by (unfold assertion_def, simp) subsection \<open>Weakest precondition of true\<close> definition "wpt x = (x * \<top>) \<sqinter> 1" lemma wpt_is_assertion [simp]: "wpt x \<in> assertion" apply (unfold wpt_def assertion_def, safe) apply simp apply (simp add: inf_comp dual_inf dual_comp inf_sup_distrib) apply (rule antisym) by (simp_all add: dual_neg) lemma wpt_comp: "(wpt x) * x = x" apply (simp add: wpt_def inf_comp) apply (rule antisym, simp_all) by (cut_tac x = 1 and y = \<top> and z = x in le_comp, simp_all) lemma wpt_comp_2: "wpt (x * y) = wpt (x * (wpt y))" by (simp add: wpt_def inf_comp mult.assoc) lemma wpt_assertion [simp]: "x \<in> assertion \<Longrightarrow> wpt x = x" by (simp add: wpt_def assertion_prop) lemma wpt_le_assertion: "x \<in> assertion \<Longrightarrow> x * y = y \<Longrightarrow> wpt y \<le> x" apply (simp add: wpt_def) proof - assume A: "x \<in> assertion" assume B: "x * y = y" have "y * \<top> \<sqinter> 1 = x * (y * \<top>) \<sqinter> 1" by (simp add: B mult.assoc [THEN sym]) also have "\<dots> \<le> x * \<top> \<sqinter> 1" apply simp apply (rule_tac y = "x * (y * \<top>)" in order_trans) apply simp_all by (rule le_comp, simp) also have "\<dots> = x" by (cut_tac A, simp add: assertion_prop) finally show "y * \<top> \<sqinter> 1 \<le> x" . qed lemma wpt_choice: "wpt (x \<sqinter> y) = wpt x \<sqinter> wpt y" apply (simp add: wpt_def inf_comp) proof - have "x * \<top> \<sqinter> 1 \<sqinter> (y * \<top> \<sqinter> 1) = x * \<top> \<sqinter> ((y * \<top> \<sqinter> 1) \<sqinter> 1)" apply (subst inf_assoc) by (simp add: inf_commute) also have "... = x * \<top> \<sqinter> (y * \<top> \<sqinter> 1)" by (subst inf_assoc, simp) also have "... = (x * \<top>) \<sqinter> (y * \<top>) \<sqinter> 1" by (subst inf_assoc, simp) finally show "x * \<top> \<sqinter> (y * \<top>) \<sqinter> 1 = x * \<top> \<sqinter> 1 \<sqinter> (y * \<top> \<sqinter> 1)" by simp qed end context lattice begin lemma [simp]: "x \<le> y \<Longrightarrow> x \<sqinter> y = x" by (simp add: inf_absorb1) end context mbt_algebra begin lemma wpt_dual_assertion_comp: "x \<in> assertion \<Longrightarrow> y \<in> assertion \<Longrightarrow> wpt ((x ^ o) * y) = (neg_assert x) \<squnion> y" apply (simp add: wpt_def neg_assert_def) proof - assume A: "x \<in> assertion" assume B: "y \<in> assertion" have C: "((x ^ o) * \<bottom>) \<squnion> 1 = x ^ o" by (rule dual_assertion_prop, rule A) have "x ^ o * y * \<top> \<sqinter> 1 = (((x ^ o) * \<bottom>) \<squnion> 1) * y * \<top> \<sqinter> 1" by (simp add: C) also have "\<dots> = ((x ^ o) * \<bottom> \<squnion> (y * \<top>)) \<sqinter> 1" by (simp add: sup_comp) also have "\<dots> = (((x ^ o) * \<bottom>) \<sqinter> 1) \<squnion> ((y * \<top>) \<sqinter> 1)" by (simp add: inf_sup_distrib2) also have "\<dots> = (((x ^ o) * \<bottom>) \<sqinter> 1) \<squnion> y" by (cut_tac B, drule assertion_prop, simp) finally show "x ^ o * y * \<top> \<sqinter> 1 = (((x ^ o) * \<bottom>) \<sqinter> 1) \<squnion> y" . qed lemma le_comp_left_right: "x \<le> y \<Longrightarrow> u \<le> v \<Longrightarrow> x * u \<le> y * v" apply (rule_tac y = "x * v" in order_trans) apply (rule le_comp, simp) by (rule le_comp_right, simp) lemma wpt_dual_assertion: "x \<in> assertion \<Longrightarrow> wpt (x ^ o) = 1" apply (simp add: wpt_def) apply (rule antisym) apply simp_all apply (cut_tac x = 1 and y = "x ^ o" and u = 1 and v = \<top> in le_comp_left_right) apply simp_all apply (subst dual_le) by simp lemma assertion_commute: "x \<in> assertion \<Longrightarrow> y \<in> conjunctive \<Longrightarrow> y * x = wpt(y * x) * y" apply (simp add: wpt_def) apply (simp add: inf_comp) apply (drule_tac x = y and y = "x * \<top>" and z = 1 in conjunctiveD) by (simp add: mult.assoc [THEN sym] assertion_prop) lemma wpt_mono: "x \<le> y \<Longrightarrow> wpt x \<le> wpt y" apply (simp add: wpt_def) apply (rule_tac y = "x * \<top>" in order_trans, simp_all) by (rule le_comp_right, simp) lemma "a \<in> conjunctive \<Longrightarrow> x * a \<le> a * y \<Longrightarrow> (x ^ \<omega>) * a \<le> a * (y ^ \<omega>)" apply (rule omega_least) apply (simp add: mult.assoc [THEN sym]) apply (rule_tac y = "a * y * y ^ \<omega> \<sqinter> a" in order_trans) apply (simp) apply (rule_tac y = "x * a * y ^ \<omega>" in order_trans, simp_all) apply (rule le_comp_right, simp) apply (simp add: mult.assoc) apply (subst (2) omega_fix) by (simp add: conjunctiveD) lemma [simp]: "x \<le> 1 \<Longrightarrow> y * x \<le> y" by (cut_tac x = x and y = 1 and z = y in le_comp, simp_all) lemma [simp]: "x \<le> x * \<top>" by (cut_tac x = 1 and y = \<top> and z = x in le_comp, simp_all) lemma [simp]: "x * \<bottom> \<le> x" by (cut_tac x = \<bottom> and y = 1 and z = x in le_comp, simp_all) end subsection\<open>Monotonic Boolean trasformers algebra with post condition statement\<close> definition "post_fun (p::'a::order) q = (if p \<le> q then (\<top>::'b::{order_bot,order_top}) else \<bottom>)" lemma mono_post_fun [simp]: "mono (post_fun (p::_::{order_bot,order_top}))" apply (simp add: post_fun_def mono_def, safe) apply (subgoal_tac "p \<le> y", simp) apply (rule_tac y = x in order_trans) apply simp_all done lemma post_refin [simp]: "mono S \<Longrightarrow> ((S p)::'a::bounded_lattice) \<sqinter> (post_fun p) x \<le> S x" apply (simp add: le_fun_def assert_fun_def post_fun_def, safe) by (rule_tac f = S in monoD, simp_all) class post_mbt_algebra = mbt_algebra + fixes post :: "'a \<Rightarrow> 'a" assumes post_1: "(post x) * x * \<top> = \<top>" and post_2: "y * x * \<top> \<sqinter> (post x) \<le> y" instantiation MonoTran :: (complete_boolean_algebra) post_mbt_algebra begin lift_definition post_MonoTran :: "'a::complete_boolean_algebra MonoTran \<Rightarrow> 'a::complete_boolean_algebra MonoTran" is "\<lambda>x. post_fun (x \<top>)" by (rule mono_post_fun) instance proof fix x :: "'a MonoTran" show "post x * x * \<top> = \<top>" apply transfer apply (simp add: fun_eq_iff) done fix x y :: "'a MonoTran" show "y * x * \<top> \<sqinter> post x \<le> y" apply transfer apply (simp add: le_fun_def) done qed end subsection\<open>Complete monotonic Boolean transformers algebra\<close> class complete_mbt_algebra = post_mbt_algebra + complete_distrib_lattice + assumes Inf_comp: "(Inf X) * z = (INF x \<in> X . (x * z))" instance MonoTran :: (complete_boolean_algebra) complete_mbt_algebra apply intro_classes apply transfer apply (simp add: Inf_comp_fun) done context complete_mbt_algebra begin lemma dual_Inf: "(Inf X) ^ o = (SUP x\<in> X . x ^ o)" apply (rule antisym) apply (subst dual_le, simp) apply (rule Inf_greatest) apply (subst dual_le, simp) apply (rule SUP_upper, simp) apply (rule SUP_least) apply (subst dual_le, simp) by (rule Inf_lower, simp) lemma dual_Sup: "(Sup X) ^ o = (INF x\<in> X . x ^ o)" apply (rule antisym) apply (rule INF_greatest) apply (subst dual_le, simp) apply (rule Sup_upper, simp) apply (subst dual_le, simp) apply (rule Sup_least) apply (subst dual_le, simp) by (rule INF_lower, simp) lemma INF_comp: "(\<Sqinter>(f ` A)) * z = (INF a \<in> A . (f a) * z)" unfolding Inf_comp apply (subgoal_tac "((\<lambda>x::'a. x * z) ` f ` A) = ((\<lambda>a::'b. f a * z) ` A)") by auto lemma dual_INF: "(\<Sqinter>(f ` A)) ^ o = (SUP a \<in> A . (f a) ^ o)" unfolding Inf_comp dual_Inf apply (subgoal_tac "(dual ` f ` A) = ((\<lambda>a::'b. f a ^ o) ` A)") by auto lemma dual_SUP: "(\<Squnion>(f ` A)) ^ o = (INF a \<in> A . (f a) ^ o)" unfolding dual_Sup apply (subgoal_tac "(dual ` f ` A) = ((\<lambda>a::'b. f a ^ o) ` A)") by auto lemma Sup_comp: "(Sup X) * z = (SUP x \<in> X . (x * z))" apply (rule dual_eq) by (simp add: dual_comp dual_Sup dual_SUP INF_comp image_comp) lemma SUP_comp: "(\<Squnion>(f ` A)) * z = (SUP a \<in> A . (f a) * z)" unfolding Sup_comp apply (subgoal_tac "((\<lambda>x::'a. x * z) ` f ` A) = ((\<lambda>a::'b. f a * z) ` A)") by auto lemma Sup_assertion [simp]: "X \<subseteq> assertion \<Longrightarrow> Sup X \<in> assertion" apply (unfold assertion_def) apply safe apply (rule Sup_least) apply blast apply (simp add: Sup_comp dual_Sup Sup_inf) apply (subgoal_tac "((\<lambda>y . y \<sqinter> \<Sqinter>(dual ` X)) ` (\<lambda>x . x * \<top>) ` X) = X") apply simp proof - assume A: "X \<subseteq> {x. x \<le> 1 \<and> x * \<top> \<sqinter> x ^ o = x}" have B [simp]: "!! x . x \<in> X \<Longrightarrow> x * \<top> \<sqinter> (\<Sqinter>(dual ` X)) = x" proof - fix x assume C: "x \<in> X" have "x * \<top> \<sqinter> \<Sqinter>(dual ` X) = x * \<top> \<sqinter> (x ^ o \<sqinter> \<Sqinter>(dual ` X))" apply (subgoal_tac "\<Sqinter>(dual ` X) = (x ^ o \<sqinter> \<Sqinter>(dual ` X))", simp) apply (rule antisym, simp_all) apply (rule Inf_lower, cut_tac C, simp) done also have "\<dots> = x \<sqinter> \<Sqinter>(dual ` X)" by (unfold inf_assoc [THEN sym], cut_tac A, cut_tac C, auto) also have "\<dots> = x" apply (rule antisym, simp_all) apply (rule INF_greatest) apply (cut_tac A C) apply (rule_tac y = 1 in order_trans) apply auto[1] apply (subst dual_le, auto) done finally show "x * \<top> \<sqinter> \<Sqinter>(dual ` X) = x" . qed show "(\<lambda>y. y \<sqinter> \<Sqinter>(dual ` X)) ` (\<lambda>x . x * \<top>) ` X = X" by (simp add: image_comp) qed lemma Sup_range_assertion [simp]: "(!!w . p w \<in> assertion) \<Longrightarrow> Sup (range p) \<in> assertion" by (rule Sup_assertion, auto) lemma Sup_less_assertion [simp]: "(!!w . p w \<in> assertion) \<Longrightarrow> Sup_less p w \<in> assertion" by (unfold Sup_less_def, rule Sup_assertion, auto) theorem omega_lfp: "x ^ \<omega> * y = lfp (\<lambda> z . (x * z) \<sqinter> y)" apply (rule antisym) apply (rule lfp_greatest) apply (drule omega_least, simp) apply (rule lfp_lowerbound) apply (subst (2) omega_fix) by (simp add: inf_comp mult.assoc) end lemma [simp]: "mono (\<lambda> (t::'a::mbt_algebra) . x * t \<sqinter> y)" apply (simp add: mono_def, safe) apply (rule_tac y = "x * xa" in order_trans, simp) by (rule le_comp, simp) class mbt_algebra_fusion = mbt_algebra + assumes fusion: "(\<forall> t . x * t \<sqinter> y \<sqinter> z \<le> u * (t \<sqinter> z) \<sqinter> v) \<Longrightarrow> (x ^ \<omega>) * y \<sqinter> z \<le> (u ^ \<omega>) * v " lemma "class.mbt_algebra_fusion (1::'a::complete_mbt_algebra) ((*)) (\<sqinter>) (\<le>) (<) (\<squnion>) dual dual_star omega star \<bottom> \<top>" apply unfold_locales apply (cut_tac h = "\<lambda> t . t \<sqinter> z" and f = "\<lambda> t . x * t \<sqinter> y" and g = "\<lambda> t . u * t \<sqinter> v" in weak_fusion) apply (rule inf_Disj) apply simp_all apply (simp add: le_fun_def) by (simp add: omega_lfp) context mbt_algebra_fusion begin lemma omega_pres_conj: "x \<in> conjunctive \<Longrightarrow> x ^ \<omega> \<in> conjunctive" apply (subst omega_star, simp) apply (rule comp_pres_conj) apply (rule assertion_conjunctive, simp) by (rule start_pres_conj, simp) end end
using Test using Quon using Yao function yb_fidelity(a1, b1, c1) circ1 = chain(1, Rz(-a1*im), Rx((-b1*im)), Rz(-c1*im)) (a2, b2, c2) = yang_baxter_param(a1, b1, c1) circ2 = chain(1, Rx(-a2*im), Rz((-b2*im)), Rx(-c2*im)) return operator_fidelity(matblock(mat(circ1') * mat(circ2)), I2) end a1 = rand()*π*im b1 = rand()*π*im c1 = rand()*π*im a1, b1, c1 = rand(ComplexF64, 3) a2, b2, c2 = yang_baxter_param(a1, b1, c1) yb_fidelity(a1, b1, c1) @test yb_fidelity(a1, b1, c1) ≈ 1 @test yb_fidelity(a2, b2, c2) ≈ 1 c1 = -a1 a2, b2, c2 = yang_baxter_param(a1, b1, c1) @test yb_fidelity(a1, b1, c1) ≈ 1 @test yb_fidelity(a2, b2, c2) ≈ 1 c1 = π*im - a1 a2, b2, c2 = yang_baxter_param(a1, b1, c1) @test yb_fidelity(a1, b1, c1) ≈ 1 @test yb_fidelity(a2, b2, c2) ≈ 1 @test_throws ErrorException yang_baxter_param(change_direction(pi/3*im), pi/3*im, change_direction(pi/3*im))
We are a German company, offering products like crude and refined oils, meat, natural products, refined products and derivatives, and other products like cement, aluminum, steel etc. Please have a look at our website. At the moment we are in position to buy Frozen Mackerel (Scomber Scombrus) Fish whole in bulk packing. The concerned suppliers are supposed to send best quotes, company profile etc for long term business deal.
6 , but it polymerizes upon condensing . Antimony pentoxide ( Sb
State Before: 𝕜 : Type u_1 𝕝 : Type ?u.89300 E : Type u_2 F : Type ?u.89306 β : Type ?u.89309 inst✝⁷ : OrderedSemiring 𝕜 inst✝⁶ : TopologicalSpace E inst✝⁵ : TopologicalSpace F inst✝⁴ : AddCommGroup E inst✝³ : AddCommGroup F inst✝² : Module 𝕜 E inst✝¹ : Module 𝕜 F inst✝ : ContinuousAdd E s t : Set E hs : StrictConvex 𝕜 s z : E ⊢ StrictConvex 𝕜 ((fun x => x + z) '' s) State After: no goals Tactic: simpa only [add_comm] using hs.add_left z
lemma sets_Sup_measure'2: "sets (Sup_measure' M) = sigma_sets (\<Union>m\<in>M. space m) (\<Union>m\<in>M. sets m)"
{-# OPTIONS --cubical --no-import-sorts --safe #-} module Cubical.HITs.Modulo.FinEquiv where open import Cubical.Foundations.Function open import Cubical.Foundations.Isomorphism open import Cubical.Foundations.Prelude open import Cubical.Data.Fin open import Cubical.Data.Nat open import Cubical.Data.Nat.Order open import Cubical.HITs.Modulo.Base -- For positive `k`, every `Modulo k` can be reduced to its -- residue modulo `k`, given by a value of type `Fin k`. This -- forms an equivalence between `Fin k` and `Modulo k`. module Reduction {k₀ : ℕ} where private k = suc k₀ fembed : Fin k → Modulo k fembed = embed ∘ toℕ ResiduePath : ℕ → Type₀ ResiduePath n = Σ[ f ∈ Fin k ] fembed f ≡ embed n rbase : ∀ n (n<k : n < k) → ResiduePath n rbase n n<k = (n , n<k) , refl rstep : ∀ n → ResiduePath n → ResiduePath (k + n) rstep n (f , p) = f , p ∙ step n rstep≡ : ∀ n (R : ResiduePath n) → PathP (λ i → fembed (fst R) ≡ step n i) (snd R) (snd (rstep n R)) rstep≡ n (f , p) = λ i j → compPath-filler p (step n) i j residuePath : ∀ n → ResiduePath n residuePath = +induction k₀ ResiduePath rbase rstep lemma₁ : ∀ n → rstep n (residuePath n) ≡ residuePath (k + n) lemma₁ = sym ∘ +inductionStep k₀ ResiduePath rbase rstep residueStep₁ : ∀ n → fst (residuePath n) ≡ fst (residuePath (k + n)) residueStep₁ = cong fst ∘ lemma₁ residueStep₂ : ∀ n → PathP (λ i → fembed (residueStep₁ n i) ≡ step n i) ((snd ∘ residuePath) n) ((snd ∘ residuePath) (k + n)) residueStep₂ n i j = hfill (λ ii → λ { (i = i0) → snd (residuePath n) j ; (j = i0) → fembed (residueStep₁ n (i ∧ ii)) ; (i = i1) → snd (lemma₁ n ii) j ; (j = i1) → step n i }) (inS (rstep≡ n (residuePath n) i j)) i1 residue : Modulo k → Fin k residue (embed n) = fst (residuePath n) residue (step n i) = residueStep₁ n i sect : section residue fembed sect (r , r<k) = cong fst (+inductionBase k₀ ResiduePath rbase rstep r r<k) retr : retract residue fembed retr (embed n) = snd (residuePath n) retr (step n i) = residueStep₂ n i Modulo≡Fin : Modulo k ≡ Fin k Modulo≡Fin = isoToPath (iso residue fembed sect retr) open Reduction using (fembed; residue; Modulo≡Fin) public
If $f$ and $g$ are holomorphic functions on a connected open set $S$, and $g$ has a simple zero at $z \in S$, then $f/g$ has a simple pole at $z$ and its residue is $f(z)/g'(z)$.
(* * Copyright 2014, NICTA * * This software may be distributed and modified according to the terms of * the BSD 2-Clause license. Note that NO WARRANTY is provided. * See "LICENSE_BSD2.txt" for details. * * @TAG(NICTA_BSD) *) (* License: BSD, terms see file ./LICENSE *) theory SepFrame imports SepTactic begin class heap_state_type' instance heap_state_type' \<subseteq> type .. consts hst_mem :: "'a::heap_state_type' \<Rightarrow> heap_mem" hst_mem_update :: "(heap_mem \<Rightarrow> heap_mem) \<Rightarrow> 'a::heap_state_type' \<Rightarrow> 'a" hst_htd :: "'a::heap_state_type' \<Rightarrow> heap_typ_desc" hst_htd_update :: "(heap_typ_desc \<Rightarrow> heap_typ_desc) \<Rightarrow> 'a::heap_state_type' \<Rightarrow> 'a" class heap_state_type = heap_state_type' + assumes hst_htd_htd_update [simp]: "hst_htd (hst_htd_update d s) = d (hst_htd s)" assumes hst_mem_mem_update [simp]: "hst_mem (hst_mem_update h s) = h (hst_mem s)" assumes hst_htd_mem_update [simp]: "hst_htd (hst_mem_update h s) = hst_htd s" assumes hst_mem_htd_update [simp]: "hst_mem (hst_htd_update d s) = hst_mem s" translations "s\<lparr> hst_mem := x\<rparr>" <= "CONST hst_mem_update (K_record x) s" "s\<lparr> hst_htd := x\<rparr>" <= "CONST hst_htd_update (K_record x) s" definition lift_hst :: "'a::heap_state_type' \<Rightarrow> heap_state" where "lift_hst s \<equiv> lift_state (hst_mem s,hst_htd s)" definition point_eq_mod :: "('a \<Rightarrow> 'b) \<Rightarrow> ('a \<Rightarrow> 'b) \<Rightarrow> 'a set \<Rightarrow> bool" where "point_eq_mod f g X \<equiv> \<forall>x. x \<notin> X \<longrightarrow> f x = g x" definition exec_fatal :: "('s,'b,'c) com \<Rightarrow> ('s,'b,'c) body \<Rightarrow> 's \<Rightarrow> bool" where "exec_fatal C \<Gamma> s \<equiv> (\<exists>f. \<Gamma> \<turnstile> \<langle>C,Normal s\<rangle> \<Rightarrow> Fault f) \<or> (\<Gamma> \<turnstile> \<langle>C,Normal s\<rangle> \<Rightarrow> Stuck)" definition restrict_htd :: "'s::heap_state_type' \<Rightarrow> s_addr set \<Rightarrow> 's" where "restrict_htd s X \<equiv> s\<lparr> hst_htd := restrict_s (hst_htd s) X \<rparr>" definition restrict_safe_OK :: "'s \<Rightarrow> 's \<Rightarrow> ('s \<Rightarrow> ('s,'c) xstate) \<Rightarrow> s_addr set \<Rightarrow> ('s::heap_state_type','b,'c) com \<Rightarrow> ('s,'b,'c) body \<Rightarrow> bool" where "restrict_safe_OK s t f X C \<Gamma> \<equiv> \<Gamma> \<turnstile> \<langle>C,(Normal (restrict_htd s X))\<rangle> \<Rightarrow> f (restrict_htd t X) \<and> point_eq_mod (lift_state (hst_mem t,hst_htd t)) (lift_state (hst_mem s,hst_htd s)) X" definition restrict_safe :: "'s \<Rightarrow> ('s,'c) xstate \<Rightarrow> ('s::heap_state_type','b,'c) com \<Rightarrow> ('s,'b,'c) body \<Rightarrow> bool" where "restrict_safe s t C \<Gamma> \<equiv> \<forall>X. (case t of Normal t' \<Rightarrow> restrict_safe_OK s t' Normal X C \<Gamma> | Abrupt t' \<Rightarrow> restrict_safe_OK s t' Abrupt X C \<Gamma> | _ \<Rightarrow> False) \<or> exec_fatal C \<Gamma> (restrict_htd s X)" definition mem_safe :: "('s::{heap_state_type',type},'b,'c) com \<Rightarrow> ('s,'b,'c) body \<Rightarrow> bool" where "mem_safe C \<Gamma> \<equiv> \<forall>s t. \<Gamma> \<turnstile> \<langle>C,Normal s\<rangle> \<Rightarrow> t \<longrightarrow> restrict_safe s t C \<Gamma>" definition point_eq_mod_safe :: "'s::{heap_state_type',type} set \<Rightarrow> ('s \<Rightarrow> 's) \<Rightarrow> ('s \<Rightarrow> s_addr \<Rightarrow> 'c) \<Rightarrow> bool" where "point_eq_mod_safe P f g \<equiv> \<forall>s X. restrict_htd s X \<in> P \<longrightarrow> point_eq_mod (g (f s)) (g s) X" definition comm_restrict :: "('s::{heap_state_type',type} \<Rightarrow> 's) \<Rightarrow> 's \<Rightarrow> s_addr set \<Rightarrow> bool" where "comm_restrict f s X \<equiv> f (restrict_htd s X) = restrict_htd (f s) X" definition comm_restrict_safe :: "'s set \<Rightarrow> ('s::{heap_state_type',type} \<Rightarrow> 's) \<Rightarrow> bool" where "comm_restrict_safe P f \<equiv> \<forall>s X. restrict_htd s X \<in> P \<longrightarrow> comm_restrict f s X" definition htd_ind :: "('a::{heap_state_type',type} \<Rightarrow> 'b) \<Rightarrow> bool" where "htd_ind f \<equiv> \<forall>x s. f s = f (hst_htd_update x s)" definition mono_guard :: "'s::{heap_state_type',type} set \<Rightarrow> bool" where "mono_guard P \<equiv> \<forall>s X. restrict_htd s X \<in> P \<longrightarrow> s \<in> P" definition expr_htd_ind :: "'s::{heap_state_type',type} set \<Rightarrow> bool" where "expr_htd_ind P \<equiv> \<forall>d s. s\<lparr> hst_htd := d \<rparr> \<in> P = (s \<in> P)" primrec intra_safe :: "('s::heap_state_type','b,'c) com \<Rightarrow> bool" where "intra_safe Skip = True" | "intra_safe (Basic f) = (comm_restrict_safe UNIV f \<and> point_eq_mod_safe UNIV f (\<lambda>s. lift_state (hst_mem s,hst_htd s)))" | "intra_safe (Spec r) = (\<forall>\<Gamma>. mem_safe (Spec r) (\<Gamma> :: ('s,'b,'c) body))" | "intra_safe (Seq C D) = (intra_safe C \<and> intra_safe D)" | "intra_safe (Cond P C D) = (expr_htd_ind P \<and> intra_safe C \<and> intra_safe D)" | "intra_safe (While P C) = (expr_htd_ind P \<and> intra_safe C)" | "intra_safe (Call p) = True" | "intra_safe (DynCom f) = (htd_ind f \<and> (\<forall>s. intra_safe (f s)))" | "intra_safe (Guard f P C) = (mono_guard P \<and> (case C of Basic g \<Rightarrow> comm_restrict_safe P g \<and> (*point_eq_mod_safe P g hst_mem \<and> *) point_eq_mod_safe P g (\<lambda>s. lift_state (hst_mem s,hst_htd s)) | _ \<Rightarrow> intra_safe C))" | "intra_safe Throw = True" | "intra_safe (Catch C D) = (intra_safe C \<and> intra_safe D)" instance state_ext :: (heap_state_type',type) heap_state_type' .. defs (overloaded) hs_mem_state [simp]: "hst_mem \<equiv> hst_mem \<circ> globals" hs_mem_update_state [simp]: "hst_mem_update \<equiv> globals_update \<circ> hst_mem_update" hs_htd_state[simp]: "hst_htd \<equiv> hst_htd \<circ> globals" hs_htd_update_state [simp]: "hst_htd_update \<equiv> globals_update \<circ> hst_htd_update" instance state_ext :: (heap_state_type,type) heap_state_type apply intro_classes apply auto done primrec intra_deps :: "('s','b,'c) com \<Rightarrow> 'b set" where "intra_deps Skip = {}" | "intra_deps (Basic f) = {}" | "intra_deps (Spec r) = {}" | "intra_deps (Seq C D) = (intra_deps C \<union> intra_deps D)" | "intra_deps (Cond P C D) = (intra_deps C \<union> intra_deps D)" | "intra_deps (While P C) = intra_deps C" | "intra_deps (Call p) = {p}" | "intra_deps (DynCom f) = \<Union>{intra_deps (f s) | s. True}" | "intra_deps (Guard f P C) = intra_deps C" | "intra_deps Throw = {}" | "intra_deps (Catch C D) = (intra_deps C \<union> intra_deps D)" inductive_set proc_deps :: "('s','b,'c) com \<Rightarrow> ('s,'b,'c) body \<Rightarrow> 'b set" for "C" :: "('s','b,'c) com" and "\<Gamma>" :: "('s,'b,'c) body" where "x \<in> intra_deps C \<Longrightarrow> x \<in> proc_deps C \<Gamma>" | "\<lbrakk> x \<in> proc_deps C \<Gamma>; \<Gamma> x = Some D; y \<in> intra_deps D \<rbrakk> \<Longrightarrow> y \<in> proc_deps C \<Gamma>" text {* ---- *} lemma point_eq_mod_refl [simp]: "point_eq_mod f f X" by (simp add: point_eq_mod_def) lemma point_eq_mod_subs: "\<lbrakk> point_eq_mod f g Y; Y \<subseteq> X \<rbrakk> \<Longrightarrow> point_eq_mod f g X" by (force simp: point_eq_mod_def) lemma point_eq_mod_trans: "\<lbrakk> point_eq_mod x y X; point_eq_mod y z X \<rbrakk> \<Longrightarrow> point_eq_mod x z X" by (force simp: point_eq_mod_def) lemma mem_safe_NormalD: "\<lbrakk> \<Gamma> \<turnstile> \<langle>C,Normal s\<rangle> \<Rightarrow> Normal t; mem_safe C \<Gamma>; \<not> exec_fatal C \<Gamma> (restrict_htd s X) \<rbrakk> \<Longrightarrow> (\<Gamma> \<turnstile> \<langle>C,(Normal (restrict_htd s X))\<rangle> \<Rightarrow> Normal (restrict_htd t X) \<and> point_eq_mod (lift_state (hst_mem t,hst_htd t)) (lift_state (hst_mem s,hst_htd s)) X)" by (force simp: mem_safe_def restrict_safe_def restrict_safe_OK_def) lemma mem_safe_AbruptD: "\<lbrakk> \<Gamma> \<turnstile> \<langle>C,Normal s\<rangle> \<Rightarrow> Abrupt t; mem_safe C \<Gamma>; \<not> exec_fatal C \<Gamma> (restrict_htd s X) \<rbrakk> \<Longrightarrow> (\<Gamma> \<turnstile> \<langle>C,(Normal (restrict_htd s X))\<rangle> \<Rightarrow> Abrupt (restrict_htd t X) \<and> point_eq_mod (lift_state (hst_mem t,hst_htd t)) (lift_state (hst_mem s,hst_htd s)) X)" by (force simp: mem_safe_def restrict_safe_def restrict_safe_OK_def) lemma mem_safe_FaultD: "\<lbrakk> \<Gamma> \<turnstile> \<langle>C,Normal s\<rangle> \<Rightarrow> Fault f; mem_safe C \<Gamma> \<rbrakk> \<Longrightarrow> exec_fatal C \<Gamma> (restrict_htd s X)" by (force simp: mem_safe_def restrict_safe_def) lemma mem_safe_StuckD: "\<lbrakk> \<Gamma> \<turnstile> \<langle>C,Normal s\<rangle> \<Rightarrow> Stuck; mem_safe C \<Gamma> \<rbrakk> \<Longrightarrow> exec_fatal C \<Gamma> (restrict_htd s X)" by (force simp: mem_safe_def restrict_safe_def) lemma lift_state_d_restrict [simp]: "lift_state (h,(restrict_s d X)) = lift_state (h,d) |` X" by (auto simp: lift_state_def restrict_map_def restrict_s_def intro!: ext split: s_heap_index.splits) lemma dom_merge_restrict [simp]: "(x ++ y) |` dom y = y" by (force simp: restrict_map_def None_com intro: ext) lemma dom_compl_restrict [simp]: "x |` (UNIV - dom x) = empty" by (force simp: restrict_map_def intro: ext) lemma lift_state_point_eq_mod: "\<lbrakk> point_eq_mod (lift_state (h,d)) (lift_state (h',d')) X \<rbrakk> \<Longrightarrow> lift_state (h,d) |` (UNIV - X) = lift_state (h',d') |` (UNIV - X)" by (auto simp: point_eq_mod_def restrict_map_def intro: ext) lemma htd_'_update_ind [simp]: "htd_ind f \<Longrightarrow> f (hst_htd_update x s) = f s" by (simp add: htd_ind_def) lemma sep_frame': assumes orig_spec: "\<forall>s. \<Gamma> \<turnstile> \<lbrace>s. P (f \<acute>(\<lambda>x. x)) (lift_hst \<acute>(\<lambda>x. x))\<rbrace> C \<lbrace>Q (g s \<acute>(\<lambda>x. x)) (lift_hst \<acute>(\<lambda>x. x))\<rbrace>" and hi_f: "htd_ind f" and hi_g: "htd_ind g" and hi_g': "\<forall>s. htd_ind (g s)" and safe: "mem_safe (C::('s::heap_state_type,'b,'c) com) \<Gamma>" shows "\<forall>s. \<Gamma> \<turnstile> \<lbrace>s. (P (f \<acute>(\<lambda>x. x)) \<and>\<^sup>* R (h \<acute>(\<lambda>x. x))) (lift_hst \<acute>(\<lambda>x. x))\<rbrace> C \<lbrace>(Q (g s \<acute>(\<lambda>x. x)) \<and>\<^sup>* R (h s)) (lift_hst \<acute>(\<lambda>x. x))\<rbrace>" proof (rule, rule hoare_complete, simp only: valid_def, clarify) fix ta x assume ev: "\<Gamma>\<turnstile> \<langle>C,Normal x\<rangle> \<Rightarrow> ta" and pre: "(P (f x) \<and>\<^sup>* R (h x)) (lift_hst x)" then obtain s\<^sub>0 and s\<^sub>1 where pre_P: "P (f x) s\<^sub>0" and pre_R: "R (h x) s\<^sub>1" and disj: "s\<^sub>0 \<bottom> s\<^sub>1" and m: "lift_hst x = s\<^sub>1 ++ s\<^sub>0" by (clarsimp simp: sep_conj_def map_ac_simps) with orig_spec hi_f have nofault: "\<not> exec_fatal C \<Gamma> (restrict_htd x (dom s\<^sub>0))" by (force simp: exec_fatal_def image_def lift_hst_def cvalid_def valid_def restrict_htd_def dest: hoare_sound) show "ta \<in> Normal ` {t. (Q (g x t) \<and>\<^sup>* R (h x)) (lift_hst t)}" proof (cases ta) case (Normal s) moreover with ev safe nofault have ev': "\<Gamma> \<turnstile> \<langle>C,Normal (x\<lparr> hst_htd := (restrict_s (hst_htd x) (dom s\<^sub>0)) \<rparr>)\<rangle> \<Rightarrow> Normal (s\<lparr> hst_htd := (restrict_s (hst_htd s) (dom s\<^sub>0)) \<rparr>)" and "point_eq_mod (lift_state (hst_mem s,hst_htd s)) (lift_state (hst_mem x,hst_htd x)) (dom s\<^sub>0)" by (auto simp: restrict_htd_def dest: mem_safe_NormalD) moreover with m disj have "s\<^sub>1 = lift_hst s |` (UNIV - dom s\<^sub>0)" apply - apply(clarsimp simp: lift_hst_def) apply(subst lift_state_point_eq_mod) apply(drule sym) apply clarsimp apply fast apply(simp add: lift_hst_def lift_state_point_eq_mod map_add_restrict) apply(subst restrict_map_subdom, auto dest: map_disjD) done ultimately show ?thesis using orig_spec hi_f hi_g hi_g' pre_P pre_R m by (force simp: cvalid_def valid_def image_def lift_hst_def map_disj_def intro: sep_conjI dest: hoare_sound) next case (Abrupt s) with ev safe nofault orig_spec pre_P hi_f m show ?thesis by - (simp, drule spec, drule hoare_sound, drule_tac X="dom s\<^sub>0" in mem_safe_AbruptD, assumption+, force simp: valid_def cvalid_def lift_hst_def restrict_htd_def) next case (Fault f) with ev safe nofault show ?thesis by (force dest: mem_safe_FaultD) next case Stuck with ev safe nofault show ?thesis by (force dest: mem_safe_StuckD) qed qed lemma sep_frame: "\<lbrakk> k = (\<lambda>s. (hst_mem s,hst_htd s)); \<forall>s. \<Gamma> \<turnstile> \<lbrace>s. P (f \<acute>(\<lambda>x. x)) (lift_state (k \<acute>(\<lambda>x. x)))\<rbrace> C \<lbrace>Q (g s \<acute>(\<lambda>x. x)) (lift_state (k \<acute>(\<lambda>x. x)))\<rbrace>; htd_ind f; htd_ind g; \<forall>s. htd_ind (g s); mem_safe (C::('s::heap_state_type,'b,'c) com) \<Gamma> \<rbrakk> \<Longrightarrow> \<forall>s. \<Gamma> \<turnstile> \<lbrace>s. (P (f \<acute>(\<lambda>x. x)) \<and>\<^sup>* R (h \<acute>(\<lambda>x. x))) (lift_state (k \<acute>(\<lambda>x. x)))\<rbrace> C \<lbrace>(Q (g s \<acute>(\<lambda>x. x)) \<and>\<^sup>* R (h s)) (lift_state (k \<acute>(\<lambda>x. x)))\<rbrace>" apply(simp only:) apply(fold lift_hst_def) apply(erule (4) sep_frame') done lemma point_eq_mod_safe [simp]: "\<lbrakk> point_eq_mod_safe P f g; restrict_htd s X \<in> P; x \<notin> X \<rbrakk> \<Longrightarrow> g (f s) x = (g s) x" apply (simp add: point_eq_mod_safe_def point_eq_mod_def) apply(case_tac x, force) done lemma comm_restrict_safe [simp]: "\<lbrakk> comm_restrict_safe P f; restrict_htd s X \<in> P \<rbrakk> \<Longrightarrow> restrict_htd (f s ) X = f (restrict_htd s X)" by (simp add: comm_restrict_safe_def comm_restrict_def) lemma mono_guardD: "\<lbrakk> mono_guard P; restrict_htd s X \<in> P \<rbrakk> \<Longrightarrow> s \<in> P" by (unfold mono_guard_def, fast) lemma expr_htd_ind: "expr_htd_ind P \<Longrightarrow> restrict_htd s X \<in> P = (s \<in> P)" by (simp add: expr_htd_ind_def restrict_htd_def) lemma exec_fatal_Seq: "exec_fatal C \<Gamma> s \<Longrightarrow> exec_fatal (C;;D) \<Gamma> s" by (force simp: exec_fatal_def intro: exec.intros) lemma exec_fatal_Seq2: "\<lbrakk> \<Gamma> \<turnstile> \<langle>C,Normal s\<rangle> \<Rightarrow> Normal t; exec_fatal D \<Gamma> t \<rbrakk> \<Longrightarrow> exec_fatal (C;;D) \<Gamma> s" by (force simp: exec_fatal_def intro: exec.intros) lemma exec_fatal_Cond: "exec_fatal (Cond P C D) \<Gamma> s = (if s \<in> P then exec_fatal C \<Gamma> s else exec_fatal D \<Gamma> s)" by (force simp: exec_fatal_def intro: exec.intros elim: exec_Normal_elim_cases) lemma exec_fatal_While: "\<lbrakk> exec_fatal C \<Gamma> s; s \<in> P \<rbrakk> \<Longrightarrow> exec_fatal (While P C) \<Gamma> s" by (force simp: exec_fatal_def intro: exec.intros elim: exec_Normal_elim_cases) lemma exec_fatal_While2: "\<lbrakk> exec_fatal (While P C) \<Gamma> t; \<Gamma> \<turnstile> \<langle>C,Normal s\<rangle> \<Rightarrow> Normal t; s \<in> P \<rbrakk> \<Longrightarrow> exec_fatal (While P C) \<Gamma> s" by (force simp: exec_fatal_def intro: exec.intros elim: exec_Normal_elim_cases) lemma exec_fatal_Call: "\<lbrakk> \<Gamma> p = Some C; exec_fatal C \<Gamma> s \<rbrakk> \<Longrightarrow> exec_fatal (Call p) \<Gamma> s" by (force simp: exec_fatal_def intro: exec.intros) lemma exec_fatal_DynCom: "exec_fatal (f s) \<Gamma> s \<Longrightarrow> exec_fatal (DynCom f) \<Gamma> s" by (force simp: exec_fatal_def intro: exec.intros) lemma exec_fatal_Guard: "exec_fatal (Guard f P C) \<Gamma> s = (s \<in> P \<longrightarrow> exec_fatal C \<Gamma> s)" proof (cases "s \<in> P") case True thus ?thesis by (force simp: exec_fatal_def intro: exec.intros elim: exec_Normal_elim_cases) next case False thus ?thesis by (force simp: exec_fatal_def intro: exec.intros) qed lemma restrict_safe_Guard: assumes restrict: "restrict_safe s t C \<Gamma>" shows "restrict_safe s t (Guard f P C) \<Gamma>" proof (cases t) case (Normal s) with restrict show ?thesis by (force simp: restrict_safe_def restrict_safe_OK_def exec_fatal_Guard intro: exec.intros) next case (Abrupt s) with restrict show ?thesis by (force simp: restrict_safe_def restrict_safe_OK_def exec_fatal_Guard intro: exec.intros) next case (Fault f) with restrict show ?thesis by (force simp: restrict_safe_def exec_fatal_Guard) next case Stuck with restrict show ?thesis by (force simp: restrict_safe_def exec_fatal_Guard) qed lemma restrict_safe_Guard2: "\<lbrakk> s \<notin> P; mono_guard P \<rbrakk> \<Longrightarrow> restrict_safe s (Fault f) (Guard f P C) \<Gamma>" by (force simp: restrict_safe_def exec_fatal_def intro: exec.intros dest: mono_guardD) lemma exec_fatal_Catch: "exec_fatal C \<Gamma> s \<Longrightarrow> exec_fatal (TRY C CATCH D END) \<Gamma> s" by (force simp: exec_fatal_def intro: exec.intros) lemma exec_fatal_Catch2: "\<lbrakk> \<Gamma> \<turnstile> \<langle>C,Normal s\<rangle> \<Rightarrow> Abrupt t; exec_fatal D \<Gamma> t \<rbrakk> \<Longrightarrow> exec_fatal (TRY C CATCH D END) \<Gamma> s" by (force simp: exec_fatal_def intro: exec.intros) lemma intra_safe_restrict [rule_format]: assumes safe_env: "\<And>n C. \<Gamma> n = Some C \<Longrightarrow> intra_safe C" and exec: "\<Gamma> \<turnstile> \<langle>C,s\<rangle> \<Rightarrow> t" shows "\<forall>s'. s = Normal s' \<longrightarrow> intra_safe C \<longrightarrow> restrict_safe s' t C \<Gamma>" using exec proof induct case (Skip s) thus ?case by (force simp: restrict_safe_def restrict_safe_OK_def intro: exec.intros) next case (Guard s' P C t f) show ?case proof (cases "\<exists>g. C = Basic g") case False with Guard show ?thesis by - (clarsimp, split com.splits, auto dest: restrict_safe_Guard) next case True with Guard show ?thesis by (cases t) (force simp: restrict_safe_def restrict_safe_OK_def point_eq_mod_safe_def exec_fatal_Guard intro: exec.intros elim: exec_Normal_elim_cases, (fast elim: exec_Normal_elim_cases)+) qed next case (GuardFault C f P s) thus ?case by (force dest: restrict_safe_Guard2) next case (FaultProp C f) thus ?case by simp next case (Basic f s) thus ?case by (force simp: restrict_safe_def restrict_safe_OK_def point_eq_mod_safe_def intro: exec.intros) next case (Spec r s t) thus ?case apply (clarsimp simp: mem_safe_def) apply (fastforce intro: exec.Spec) done next case (SpecStuck r s) thus ?case apply clarsimp apply (erule_tac x=\<Gamma> in allE) apply (simp add: mem_safe_def) apply (erule allE, erule allE, erule impE, erule exec.SpecStuck) apply assumption done next case (Seq C s sa D ta) show ?case proof (cases sa) case (Normal s') with Seq show ?thesis by (cases ta) (clarsimp simp: restrict_safe_def restrict_safe_OK_def, (drule_tac x=X in spec)+, auto intro: exec.intros point_eq_mod_trans exec_fatal_Seq exec_fatal_Seq2)+ next case (Abrupt s') with Seq show ?thesis by (force simp: restrict_safe_def restrict_safe_OK_def intro: exec.intros dest: exec_fatal_Seq elim: exec_Normal_elim_cases) next case (Fault f) with Seq show ?thesis by (force simp: restrict_safe_def dest: exec_fatal_Seq elim: exec_Normal_elim_cases) next case Stuck with Seq show ?thesis by (force simp: restrict_safe_def dest: exec_fatal_Seq elim: exec_Normal_elim_cases) qed next case (CondTrue s P C t D) thus ?case by (cases t) (auto simp: restrict_safe_def restrict_safe_OK_def exec_fatal_Cond intro: exec.intros dest: expr_htd_ind split: split_if_asm) next case (CondFalse s P C t D) thus ?case by (cases t) (auto simp: restrict_safe_def restrict_safe_OK_def exec_fatal_Cond intro: exec.intros dest: expr_htd_ind split: split_if_asm) next case (WhileTrue P C s s' t) show ?case proof (cases s') case (Normal sa) with WhileTrue show ?thesis by (cases t) (clarsimp simp: restrict_safe_def restrict_safe_OK_def, (drule_tac x=X in spec)+, auto simp: expr_htd_ind intro: exec.intros point_eq_mod_trans exec_fatal_While exec_fatal_While2)+ next case (Abrupt sa) with WhileTrue show ?thesis by (force simp: restrict_safe_def restrict_safe_OK_def expr_htd_ind intro: exec.intros exec_fatal_While elim: exec_Normal_elim_cases) next case (Fault f) with WhileTrue show ?thesis by (force simp: restrict_safe_def expr_htd_ind intro: exec_fatal_While) next case Stuck with WhileTrue show ?thesis by (force simp: restrict_safe_def expr_htd_ind intro: exec_fatal_While) qed next case (WhileFalse P C s) thus ?case by (force simp: restrict_safe_def restrict_safe_OK_def expr_htd_ind intro: exec.intros) next case (Call C p s t) with safe_env show ?case by (cases t) (auto simp: restrict_safe_def restrict_safe_OK_def intro: exec_fatal_Call exec.intros) next case (CallUndefined p s) thus ?case by (force simp: restrict_safe_def exec_fatal_def intro: exec.intros) next case (StuckProp C) thus ?case by simp next case (DynCom f s t) thus ?case by (cases t) (auto simp: restrict_safe_def restrict_safe_OK_def restrict_htd_def intro!: exec.intros exec_fatal_DynCom) next case (Throw s) thus ?case by (force simp: restrict_safe_def restrict_safe_OK_def intro: exec.intros) next case (AbruptProp C s) thus ?case by simp next case (CatchMatch C D s s' t) thus ?case by (cases t) (clarsimp simp: restrict_safe_def, drule_tac x=X in spec, auto simp: restrict_safe_OK_def intro: exec.intros point_eq_mod_trans dest: exec_fatal_Catch exec_fatal_Catch2)+ next case (CatchMiss C s t D) thus ?case by (cases t) (clarsimp simp: restrict_safe_def, drule_tac x=X in spec, auto simp: restrict_safe_OK_def intro: exec.intros dest: exec_fatal_Catch)+ qed lemma intra_mem_safe: "\<lbrakk> \<And>n C. \<Gamma> n = Some C \<Longrightarrow> intra_safe C; intra_safe C \<rbrakk> \<Longrightarrow> mem_safe C \<Gamma>" by (force simp: mem_safe_def intro: intra_safe_restrict) lemma point_eq_mod_safe_triv: "(\<And>s. g (f s) = g s) \<Longrightarrow> point_eq_mod_safe P f g" by (simp add: point_eq_mod_safe_def point_eq_mod_def) lemma comm_restrict_safe_triv: "(\<And>s X. f (s\<lparr> hst_htd := restrict_s (hst_htd s) X \<rparr>) = (f s)\<lparr> hst_htd := restrict_s (hst_htd (f s)) X \<rparr>) \<Longrightarrow> comm_restrict_safe P f" by (force simp: comm_restrict_safe_def comm_restrict_def restrict_htd_def) lemma mono_guard_UNIV [simp]: "mono_guard UNIV" by (force simp: mono_guard_def) lemma mono_guard_triv: "(\<And>s X. s\<lparr> hst_htd := X \<rparr> \<in> g \<Longrightarrow> s \<in> g) \<Longrightarrow> mono_guard g" by (unfold mono_guard_def, unfold restrict_htd_def, fast) lemma mono_guard_triv2: "(\<And>s X. s\<lparr> hst_htd := X \<rparr> \<in> g = ((s::'a::heap_state_type') \<in> g)) \<Longrightarrow> mono_guard g" by (unfold mono_guard_def, unfold restrict_htd_def, fast) lemma dom_restrict_s: "x \<in> dom_s (restrict_s d X) \<Longrightarrow> x \<in> dom_s d \<and> x \<in> X" apply(auto simp: restrict_s_def dom_s_def split: split_if_asm) done lemma mono_guard_ptr_safe: "\<lbrakk> \<And>s. d s = hst_htd (s::'a::heap_state_type); htd_ind p \<rbrakk> \<Longrightarrow> mono_guard {s. ptr_safe (p s) (d s)}" apply (auto simp: mono_guard_def ptr_safe_def restrict_htd_def ) apply(drule (1) subsetD) apply(drule dom_restrict_s) apply simp done lemma point_eq_mod_safe_ptr_safe_update: "\<lbrakk> d = (hst_htd::'a::heap_state_type \<Rightarrow> heap_typ_desc); m = (\<lambda>s. hst_mem_update (heap_update (p s) ((v s)::'b::mem_type)) s); h = hst_mem; k = (\<lambda>s. lift_state (h s,d s)); htd_ind p \<rbrakk> \<Longrightarrow> point_eq_mod_safe {s. ptr_safe (p s) (d s)} m k" apply (auto simp: point_eq_mod_safe_def point_eq_mod_def ptr_safe_def heap_update_def restrict_htd_def lift_state_def intro!: heap_update_nmem_same split: s_heap_index.splits) apply(subgoal_tac "(a,SIndexVal) \<in> s_footprint (p s)") apply(drule (1) subsetD) apply(drule dom_restrict_s, clarsimp) apply(drule intvlD, clarsimp) apply(erule s_footprintI2) done lemma field_ti_s_sub_typ: "field_lookup (export_uinfo (typ_info_t TYPE('b::mem_type))) f 0 = Some (typ_uinfo_t TYPE('a),b) \<Longrightarrow> s_footprint ((Ptr &(p\<rightarrow>f))::'a::mem_type ptr) \<subseteq> s_footprint (p::'b ptr)" apply(drule field_ti_s_sub) apply(simp add: s_footprint_def) done lemma ptr_safe_mono: "\<lbrakk> ptr_safe (p::'a::mem_type ptr) d; field_lookup (typ_info_t TYPE('a)) f 0 = Some (t,n); export_uinfo t = typ_uinfo_t TYPE('b) \<rbrakk> \<Longrightarrow> ptr_safe ((Ptr &(p\<rightarrow>f))::'b::mem_type ptr) d" apply(simp add: ptr_safe_def) apply(drule field_lookup_export_uinfo_Some) apply simp apply(drule field_ti_s_sub_typ) apply(erule (1) subset_trans) done lemma point_eq_mod_safe_ptr_safe_update_fl: "\<lbrakk> d = (hst_htd::'a::heap_state_type \<Rightarrow> heap_typ_desc); m = (\<lambda>s. hst_mem_update (heap_update (Ptr &((p s)\<rightarrow>f)) ((v s)::'b::mem_type)) s); h = hst_mem; k = (\<lambda>s. lift_state (h s,d s)); htd_ind p; field_lookup (typ_info_t TYPE('c)) f 0 = Some (t,n); export_uinfo t = typ_uinfo_t TYPE('b) \<rbrakk> \<Longrightarrow> point_eq_mod_safe {s. ptr_safe ((p::'a \<Rightarrow> 'c::mem_type ptr) s) (d s)} m k" apply(drule (3) point_eq_mod_safe_ptr_safe_update) apply(simp only: htd_ind_def) apply clarify apply(clarsimp simp: point_eq_mod_safe_def) apply(drule_tac x=s in spec) apply(drule_tac x=X in spec) apply(erule impE) apply(erule (2) ptr_safe_mono) apply simp done lemma point_eq_mod_safe_ptr_safe_tag: "\<lbrakk> d = (hst_htd::'a::heap_state_type \<Rightarrow> heap_typ_desc); h = hst_mem; m = (\<lambda>s. hst_htd_update (ptr_retyp (p s)) s); k = (\<lambda>s. lift_state (h s,d s)); htd_ind p \<rbrakk> \<Longrightarrow> point_eq_mod_safe {s. ptr_safe ((p s)::'b::mem_type ptr) (d s)} m k" apply(auto simp: point_eq_mod_safe_def point_eq_mod_def ptr_safe_def) apply(subgoal_tac "(a,b) \<notin> s_footprint (p (restrict_htd s X))") prefer 2 apply clarsimp apply(drule (1) subsetD) apply(clarsimp simp: restrict_htd_def) apply(drule dom_restrict_s, clarsimp) apply(thin_tac "P \<notin> Q" for P Q) apply(auto simp: restrict_htd_def lift_state_def split_def split: s_heap_index.splits split: option.splits) apply(subst (asm) ptr_retyp_d_eq_fst) apply(clarsimp split: split_if_asm) apply(erule notE) apply(drule intvlD, clarsimp) apply(erule s_footprintI2) apply(subst (asm) ptr_retyp_d_eq_fst) apply(clarsimp split: split_if_asm) apply(subst (asm) ptr_retyp_d_eq_snd) apply(clarsimp split: split_if_asm) apply(subst (asm) ptr_retyp_d_eq_snd) apply(clarsimp split: split_if_asm) apply(erule notE) apply(frule intvlD, clarsimp) apply(rule s_footprintI) apply(subst (asm) ptr_retyp_footprint) apply simp apply clarsimp apply(clarsimp simp: list_map_eq split: split_if_asm) apply(subst (asm) unat_of_nat) apply(subst (asm) mod_less) apply(subst len_of_addr_card) apply(erule less_trans) apply simp apply fast apply assumption apply(simp add: ptr_retyp_d_eq_snd) apply(clarsimp split: split_if_asm) apply(simp add: ptr_retyp_footprint) apply(clarsimp simp: list_map_eq split: split_if_asm) apply(erule notE) apply(drule intvlD, clarsimp) apply(rule s_footprintI) apply(subst (asm) unat_of_nat) apply(subst (asm) mod_less) apply(subst len_of_addr_card) apply(erule less_trans) apply simp apply assumption+ apply(simp add: ptr_retyp_d_eq_snd) apply(clarsimp split: split_if_asm) apply(simp add: ptr_retyp_footprint) apply(clarsimp simp: list_map_eq split: split_if_asm) apply(erule notE) apply(drule intvlD, clarsimp) apply(rule s_footprintI) apply(subst (asm) unat_of_nat) apply(subst (asm) mod_less) apply(subst len_of_addr_card) apply(erule less_trans) apply simp apply assumption+ apply(simp add: ptr_retyp_d_eq_snd) apply(clarsimp split: split_if_asm) apply(simp add: ptr_retyp_footprint) apply(clarsimp simp: list_map_eq split: split_if_asm) apply(erule notE) apply(drule intvlD, clarsimp) apply(rule s_footprintI) apply(subst (asm) unat_of_nat) apply(subst (asm) mod_less) apply(subst len_of_addr_card) apply(erule less_trans) apply simp apply assumption+ done lemma comm_restrict_safe_ptr_safe_tag: fixes d::"'a::heap_state_type \<Rightarrow> heap_typ_desc" assumes fun_d: "d = hst_htd" and fun_upd: "m = (\<lambda>s. hst_htd_update (ptr_retyp (p s)) s)" and ind: "htd_ind p" and upd: "\<And>d d' (s::'a). hst_htd_update (d s) (hst_htd_update (d' s) s) = hst_htd_update ((d s) \<circ> (d' s)) s" shows "comm_restrict_safe {s. ptr_safe ((p s)::'b::mem_type ptr) (d s)} m" proof (simp only: comm_restrict_safe_def comm_restrict_def, auto) fix s X assume "ptr_safe (p (restrict_htd s X)) (d (restrict_htd s X))" moreover from ind have p: "p (restrict_htd s X) = p s" by (simp add: restrict_htd_def) ultimately have "ptr_retyp (p s) (restrict_s (hst_htd s) X) = restrict_s (ptr_retyp (p s) (hst_htd s)) X" using fun_d apply - apply(rule ext) apply(auto simp: point_eq_mod_safe_def point_eq_mod_def ptr_safe_def) apply(auto simp: restrict_htd_def ) apply(case_tac "x \<notin> {ptr_val (p s)..+size_of TYPE('b)}") apply(subst ptr_retyp_d) apply clarsimp apply(clarsimp simp: restrict_map_def restrict_s_def) apply(subst ptr_retyp_d) apply clarsimp apply simp apply(subst ptr_retyp_d) apply clarsimp apply simp apply clarsimp apply(subst ptr_retyp_footprint) apply fast apply(clarsimp simp: restrict_map_def restrict_s_def) apply(subst ptr_retyp_footprint) apply fast apply simp apply(subst ptr_retyp_footprint) apply fast apply(rule) apply(subgoal_tac "(x,SIndexVal) \<in> s_footprint (p s)") apply(drule (1) subsetD) apply(clarsimp simp: dom_s_def) apply(drule intvlD, clarsimp) apply(erule s_footprintI2) apply(rule ext) apply(clarsimp simp: map_add_def list_map_eq) apply(subgoal_tac "(x,SIndexTyp y) \<in> s_footprint (p s)") apply(drule (1) subsetD) apply(clarsimp simp: dom_s_def split: split_if_asm) apply(drule intvlD, clarsimp) apply(rule s_footprintI) apply(subst (asm) unat_simps) apply(subst (asm) mod_less) apply(subst len_of_addr_card) apply(erule less_trans) apply simp apply assumption+ done hence "((ptr_retyp (p s) \<circ> (%x _. x) (restrict_s (hst_htd s) X)::heap_typ_desc \<Rightarrow> heap_typ_desc) = (%x _. x) (restrict_s (ptr_retyp (p s) (hst_htd s)) X))" by - (rule ext, simp) moreover from upd have "hst_htd_update (ptr_retyp (p s)) (hst_htd_update ((%x _. x) (restrict_s (hst_htd s) X)) s) = hst_htd_update (((ptr_retyp (p s)) \<circ> ((%x _. x) (restrict_s (hst_htd s) X)))) s" . moreover from upd have "hst_htd_update ((%x _. x) (restrict_s (ptr_retyp (p s) (hst_htd s)) X)) (hst_htd_update (ptr_retyp (p s)) s) = hst_htd_update (((%x _. x) (restrict_s ((ptr_retyp (p s) (hst_htd s))) X)) \<circ> (ptr_retyp (p s))) s" . ultimately show "m (restrict_htd s X) = restrict_htd (m s) X" using fun_d fun_upd upd p by (simp add: restrict_htd_def o_def) qed lemmas intra_sc = hrs_comm comp_def hrs_htd_update_htd_update point_eq_mod_safe_triv comm_restrict_safe_triv mono_guard_triv2 mono_guard_ptr_safe point_eq_mod_safe_ptr_safe_update point_eq_mod_safe_ptr_safe_tag comm_restrict_safe_ptr_safe_tag point_eq_mod_safe_ptr_safe_update_fl declare expr_htd_ind_def [iff] declare htd_ind_def [iff] lemma proc_deps_Skip [simp]: "proc_deps Skip \<Gamma> = {}" by (force elim: proc_deps.induct) lemma proc_deps_Basic [simp]: "proc_deps (Basic f) \<Gamma> = {}" by (force elim: proc_deps.induct) lemma proc_deps_Spec [simp]: "proc_deps (Spec r) \<Gamma> = {}" by (force elim: proc_deps.induct) lemma proc_deps_Seq [simp]: "proc_deps (Seq C D) \<Gamma> = proc_deps C \<Gamma> \<union> proc_deps D \<Gamma>" proof show "proc_deps (C;; D) \<Gamma> \<subseteq> proc_deps C \<Gamma> \<union> proc_deps D \<Gamma>" by - (rule, erule proc_deps.induct, auto intro: proc_deps.intros) next show "proc_deps C \<Gamma> \<union> proc_deps D \<Gamma> \<subseteq> proc_deps (C;; D) \<Gamma>" by auto (erule proc_deps.induct, auto intro: proc_deps.intros)+ qed lemma proc_deps_Cond [simp]: "proc_deps (Cond P C D) \<Gamma> = proc_deps C \<Gamma> \<union> proc_deps D \<Gamma>" proof show "proc_deps (Cond P C D) \<Gamma> \<subseteq> proc_deps C \<Gamma> \<union> proc_deps D \<Gamma>" by - (rule, erule proc_deps.induct, auto intro: proc_deps.intros) next show "proc_deps C \<Gamma> \<union> proc_deps D \<Gamma> \<subseteq> proc_deps (Cond P C D) \<Gamma>" by auto (erule proc_deps.induct, auto intro: proc_deps.intros)+ qed lemma proc_deps_While [simp]: "proc_deps (While P C) \<Gamma> = proc_deps C \<Gamma>" by auto (erule proc_deps.induct, auto intro: proc_deps.intros)+ lemma proc_deps_Guard [simp]: "proc_deps (Guard f P C) \<Gamma> = proc_deps C \<Gamma>" by auto (erule proc_deps.induct, auto intro: proc_deps.intros)+ lemma proc_deps_Throw [simp]: "proc_deps Throw \<Gamma> = {}" by (force elim: proc_deps.induct) lemma proc_deps_Catch [simp]: "proc_deps (Catch C D) \<Gamma> = proc_deps C \<Gamma> \<union> proc_deps D \<Gamma>" proof show "proc_deps (Catch C D) \<Gamma> \<subseteq> proc_deps C \<Gamma> \<union> proc_deps D \<Gamma>" by - (rule, erule proc_deps.induct, auto intro: proc_deps.intros) next show "proc_deps C \<Gamma> \<union> proc_deps D \<Gamma> \<subseteq> proc_deps (Catch C D) \<Gamma>" by auto (erule proc_deps.induct, auto intro: proc_deps.intros)+ qed lemma proc_deps_Call [simp]: "proc_deps (Call p) \<Gamma> = {p} \<union> (case \<Gamma> p of Some C \<Rightarrow> proc_deps C (\<Gamma>(p := None)) | _ \<Rightarrow> {})" (is "?X = ?Y \<union> ?Z") proof show "?X \<subseteq> ?Y \<union> ?Z" by - (rule, erule proc_deps.induct, auto intro: proc_deps.intros, case_tac "xa = p", auto intro: proc_deps.intros split: option.splits) next show "?Y \<union> ?Z \<subseteq> ?X" proof (clarsimp, rule) show "p \<in> ?X" by (force intro: proc_deps.intros) next show "?Z \<subseteq> ?X" by (split option.splits, rule, force intro: proc_deps.intros) (clarify, erule proc_deps.induct, (force intro: proc_deps.intros split: split_if_asm)+) qed qed lemma proc_deps_DynCom [simp]: "proc_deps (DynCom f) \<Gamma> = \<Union>{proc_deps (f s) \<Gamma> | s. True}" by auto (erule proc_deps.induct, force intro: proc_deps.intros, force intro: proc_deps.intros)+ lemma proc_deps_restrict: "proc_deps C \<Gamma> \<subseteq> proc_deps C (\<Gamma>(p := None)) \<union> proc_deps (Call p) \<Gamma>" proof rule fix xa assume mem: "xa \<in> proc_deps C \<Gamma>" hence "\<forall>p. xa \<in> proc_deps C (\<Gamma>(p := None)) \<union> proc_deps (Call p) \<Gamma>" (is "?X") using mem proof induct fix x assume "x \<in> intra_deps C" thus "\<forall>p. x \<in> proc_deps C (\<Gamma>(p := None)) \<union> proc_deps (Call p) \<Gamma>" by (force intro: proc_deps.intros) next fix D x y assume x: "x \<in> proc_deps C \<Gamma>" "x \<in> proc_deps C \<Gamma> \<Longrightarrow> \<forall>p. x \<in> proc_deps C (\<Gamma>(p := None)) \<union> proc_deps (Call p) \<Gamma>" "\<Gamma> x = Some D" "y \<in> intra_deps D" "y \<in> proc_deps C \<Gamma>" show "\<forall>p. y \<in> proc_deps C (\<Gamma>(p := None)) \<union> proc_deps (Call p) \<Gamma>" proof clarify fix p assume y: "y \<notin> proc_deps (Call p) \<Gamma>" show "y \<in> proc_deps C (\<Gamma>(p := None))" proof (cases "x=p") case True with x y show ?thesis by (force intro: proc_deps.intros) next case False with x y show ?thesis by (clarsimp, drule_tac x=p in spec) (auto intro: proc_deps.intros split: option.splits) qed qed qed thus "xa \<in> proc_deps C (\<Gamma>(p := None)) \<union> proc_deps (Call p) \<Gamma>" by simp qed lemma exec_restrict: assumes exec: "\<Gamma>' \<turnstile> \<langle>C,s\<rangle> \<Rightarrow> t" shows "\<And>\<Gamma> X. \<lbrakk> \<Gamma>' = \<Gamma> |` X; proc_deps C \<Gamma> \<subseteq> X \<rbrakk> \<Longrightarrow> \<Gamma> \<turnstile> \<langle>C,s\<rangle> \<Rightarrow> t" using exec proof induct case Skip thus ?case by (fast intro: exec.intros) next case (Guard C f P s' t) thus ?case by (force intro: exec.intros) next case (GuardFault C f P s) thus ?case by (fast intro: exec.intros) next case (FaultProp C f) thus ?case by simp next case (Basic f s) thus ?case by (fast intro: exec.intros) next case (Spec r s t) thus ?case by (fast intro: exec.intros) next case (SpecStuck r s) thus ?case by (fast intro: exec.intros) next case (Seq C D s sa ta) thus ?case by (force intro: exec.intros) next case (CondTrue P C D s t) thus ?case by (force intro: exec.intros) next case (CondFalse P C D s t) thus ?case by (force intro: exec.intros) next case (WhileTrue P C s s' t) thus ?case by (force intro: exec.intros) next case (WhileFalse P C s) thus ?case by (force intro: exec.intros) next case (Call p C s t) thus ?case by - (insert proc_deps_restrict [of C \<Gamma> p], force intro: exec.intros) next case (CallUndefined p s) thus ?case by (force intro: exec.intros) next case (StuckProp C) thus ?case by simp next case (DynCom f s t) thus ?case by (force intro: exec.intros) next case (Throw s) thus ?case by (force intro: exec.intros) next case (AbruptProp C s) thus ?case by simp next case (CatchMatch C D s s' t) thus ?case by (force intro: exec.intros) next case (CatchMiss C D s t) thus ?case by (force intro: exec.intros) qed lemma exec_restrict2: assumes exec: "\<Gamma> \<turnstile> \<langle>C,s\<rangle> \<Rightarrow> t" shows "\<And>X. proc_deps C \<Gamma> \<subseteq> X \<Longrightarrow> \<Gamma> |` X \<turnstile> \<langle>C,s\<rangle> \<Rightarrow> t" using exec proof induct case Skip thus ?case by (fast intro: exec.intros) next case (Guard C f P s' t) thus ?case by (force intro: exec.intros) next case (GuardFault C f P s) thus ?case by (fast intro: exec.intros) next case (FaultProp C f) thus ?case by simp next case (Basic f s) thus ?case by (fast intro: exec.intros) next case (Spec r s t) thus ?case by (fast intro: exec.intros) next case (SpecStuck r s) thus ?case by (fast intro: exec.intros) next case (Seq C D s sa ta) thus ?case by (auto intro: exec.intros) next case (CondTrue P C D s t) thus ?case by (force intro: exec.intros) next case (CondFalse P C D s t) thus ?case by (force intro: exec.intros) next case (WhileTrue P C s s' t) thus ?case by (auto intro: exec.intros) next case (WhileFalse P C s) thus ?case by (force intro: exec.intros) next case (Call p C s t) thus ?case by - (insert proc_deps_restrict [of C \<Gamma> p], auto intro!: exec.intros split: option.splits) next case (CallUndefined p s) thus ?case by (force intro: exec.intros) next case (StuckProp C) thus ?case by simp next case (DynCom f s t) thus ?case by - (rule exec.intros, simp, blast) next case (Throw s) thus ?case by (force intro: exec.intros) next case (AbruptProp C s) thus ?case by simp next case (CatchMatch C D s s' t) thus ?case by (auto intro: exec.intros) next case (CatchMiss C D s t) thus ?case by (force intro: exec.intros) qed lemma exec_restrict_eq: "\<Gamma> |` proc_deps C \<Gamma> \<turnstile> \<langle>C,s\<rangle> \<Rightarrow> t = \<Gamma> \<turnstile> \<langle>C,s\<rangle> \<Rightarrow> t" by (fast intro: exec_restrict exec_restrict2) lemma mem_safe_restrict: "mem_safe C \<Gamma> = mem_safe C (\<Gamma> |` proc_deps C \<Gamma>)" by (auto simp: mem_safe_def restrict_safe_def restrict_safe_OK_def exec_restrict_eq exec_fatal_def split: xstate.splits) end
[STATEMENT] lemma closed_Collect_eq: fixes f g :: "'a::topological_space \<Rightarrow> 'b::t2_space" assumes f: "continuous_on UNIV f" and g: "continuous_on UNIV g" shows "closed {x. f x = g x}" [PROOF STATE] proof (prove) goal (1 subgoal): 1. closed {x. f x = g x} [PROOF STEP] using open_Collect_neq[OF f g] [PROOF STATE] proof (prove) using this: open {x. f x \<noteq> g x} goal (1 subgoal): 1. closed {x. f x = g x} [PROOF STEP] by (simp add: closed_def Collect_neg_eq)
/- Copyright (c) 2022 Scott Morrison. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Scott Morrison -/ import category_theory.limits.shapes.pullbacks import category_theory.limits.shapes.zero_morphisms import category_theory.limits.constructions.binary_products /-! # Limits involving zero objects > THIS FILE IS SYNCHRONIZED WITH MATHLIB4. > Any changes to this file require a corresponding PR to mathlib4. Binary products and coproducts with a zero object always exist, and pullbacks/pushouts over a zero object are products/coproducts. -/ noncomputable theory open category_theory variables {C : Type*} [category C] namespace category_theory.limits variables [has_zero_object C] [has_zero_morphisms C] open_locale zero_object /-- The limit cone for the product with a zero object. -/ def binary_fan_zero_left (X : C) : binary_fan (0 : C) X := binary_fan.mk 0 (𝟙 X) /-- The limit cone for the product with a zero object is limiting. -/ def binary_fan_zero_left_is_limit (X : C) : is_limit (binary_fan_zero_left X) := binary_fan.is_limit_mk (λ s, binary_fan.snd s) (by tidy) (by tidy) (by tidy) instance has_binary_product_zero_left (X : C) : has_binary_product (0 : C) X := has_limit.mk ⟨_, binary_fan_zero_left_is_limit X⟩ /-- A zero object is a left unit for categorical product. -/ def zero_prod_iso (X : C) : (0 : C) ⨯ X ≅ X := limit.iso_limit_cone ⟨_, binary_fan_zero_left_is_limit X⟩ @[simp] lemma zero_prod_iso_hom (X : C) : (zero_prod_iso X).hom = prod.snd := rfl @[simp] lemma zero_prod_iso_inv_snd (X : C) : (zero_prod_iso X).inv ≫ prod.snd = 𝟙 X := by { dsimp [zero_prod_iso, binary_fan_zero_left], simp, } /-- The limit cone for the product with a zero object. -/ def binary_fan_zero_right (X : C) : binary_fan X (0 : C) := binary_fan.mk (𝟙 X) 0 /-- The limit cone for the product with a zero object is limiting. -/ def binary_fan_zero_right_is_limit (X : C) : is_limit (binary_fan_zero_right X) := binary_fan.is_limit_mk (λ s, binary_fan.fst s) (by tidy) (by tidy) (by tidy) instance has_binary_product_zero_right (X : C) : has_binary_product X (0 : C) := has_limit.mk ⟨_, binary_fan_zero_right_is_limit X⟩ /-- A zero object is a right unit for categorical product. -/ def prod_zero_iso (X : C) : X ⨯ (0 : C) ≅ X := limit.iso_limit_cone ⟨_, binary_fan_zero_right_is_limit X⟩ @[simp] lemma prod_zero_iso_hom (X : C) : (prod_zero_iso X).hom = prod.fst := rfl @[simp] lemma prod_zero_iso_iso_inv_snd (X : C) : (prod_zero_iso X).inv ≫ prod.fst = 𝟙 X := by { dsimp [prod_zero_iso, binary_fan_zero_right], simp, } /-- The colimit cocone for the coproduct with a zero object. -/ def binary_cofan_zero_left (X : C) : binary_cofan (0 : C) X := binary_cofan.mk 0 (𝟙 X) /-- The colimit cocone for the coproduct with a zero object is colimiting. -/ def binary_cofan_zero_left_is_colimit (X : C) : is_colimit (binary_cofan_zero_left X) := binary_cofan.is_colimit_mk (λ s, binary_cofan.inr s) (by tidy) (by tidy) (by tidy) instance has_binary_coproduct_zero_left (X : C) : has_binary_coproduct (0 : C) X := has_colimit.mk ⟨_, binary_cofan_zero_left_is_colimit X⟩ /-- A zero object is a left unit for categorical coproduct. -/ def zero_coprod_iso (X : C) : (0 : C) ⨿ X ≅ X := colimit.iso_colimit_cocone ⟨_, binary_cofan_zero_left_is_colimit X⟩ @[simp] lemma inr_zero_coprod_iso_hom (X : C) : coprod.inr ≫ (zero_coprod_iso X).hom = 𝟙 X := by { dsimp [zero_coprod_iso, binary_cofan_zero_left], simp, } @[simp] lemma zero_coprod_iso_inv (X : C) : (zero_coprod_iso X).inv = coprod.inr := rfl /-- The colimit cocone for the coproduct with a zero object. -/ def binary_cofan_zero_right (X : C) : binary_cofan X (0 : C) := binary_cofan.mk (𝟙 X) 0 /-- The colimit cocone for the coproduct with a zero object is colimiting. -/ def binary_cofan_zero_right_is_colimit (X : C) : is_colimit (binary_cofan_zero_right X) := binary_cofan.is_colimit_mk (λ s, binary_cofan.inl s) (by tidy) (by tidy) (by tidy) instance has_binary_coproduct_zero_right (X : C) : has_binary_coproduct X (0 : C) := has_colimit.mk ⟨_, binary_cofan_zero_right_is_colimit X⟩ /-- A zero object is a right unit for categorical coproduct. -/ def coprod_zero_iso (X : C) : X ⨿ (0 : C) ≅ X := colimit.iso_colimit_cocone ⟨_, binary_cofan_zero_right_is_colimit X⟩ @[simp] lemma inr_coprod_zeroiso_hom (X : C) : coprod.inl ≫ (coprod_zero_iso X).hom = 𝟙 X := by { dsimp [coprod_zero_iso, binary_cofan_zero_right], simp, } @[simp] lemma coprod_zero_iso_inv (X : C) : (coprod_zero_iso X).inv = coprod.inl := rfl instance has_pullback_over_zero (X Y : C) [has_binary_product X Y] : has_pullback (0 : X ⟶ 0) (0 : Y ⟶ 0) := has_limit.mk ⟨_, is_pullback_of_is_terminal_is_product _ _ _ _ has_zero_object.zero_is_terminal (prod_is_prod X Y)⟩ /-- The pullback over the zeron object is the product. -/ def pullback_zero_zero_iso (X Y : C) [has_binary_product X Y] : pullback (0 : X ⟶ 0) (0 : Y ⟶ 0) ≅ X ⨯ Y := limit.iso_limit_cone ⟨_, is_pullback_of_is_terminal_is_product _ _ _ _ has_zero_object.zero_is_terminal (prod_is_prod X Y)⟩ @[simp] lemma pullback_zero_zero_iso_inv_fst (X Y : C) [has_binary_product X Y] : (pullback_zero_zero_iso X Y).inv ≫ pullback.fst = prod.fst := by { dsimp [pullback_zero_zero_iso], simp, } @[simp] lemma pullback_zero_zero_iso_inv_snd (X Y : C) [has_binary_product X Y] : (pullback_zero_zero_iso X Y).inv ≫ pullback.snd = prod.snd := by { dsimp [pullback_zero_zero_iso], simp, } @[simp] lemma pullback_zero_zero_iso_hom_fst (X Y : C) [has_binary_product X Y] : (pullback_zero_zero_iso X Y).hom ≫ prod.fst = pullback.fst := by { simp [←iso.eq_inv_comp], } @[simp] lemma pullback_zero_zero_iso_hom_snd (X Y : C) [has_binary_product X Y] : (pullback_zero_zero_iso X Y).hom ≫ prod.snd = pullback.snd := by { simp [←iso.eq_inv_comp], } instance has_pushout_over_zero (X Y : C) [has_binary_coproduct X Y] : has_pushout (0 : 0 ⟶ X) (0 : 0 ⟶ Y) := has_colimit.mk ⟨_, is_pushout_of_is_initial_is_coproduct _ _ _ _ has_zero_object.zero_is_initial (coprod_is_coprod X Y)⟩ /-- The pushout over the zero object is the coproduct. -/ def pushout_zero_zero_iso (X Y : C) [has_binary_coproduct X Y] : pushout (0 : 0 ⟶ X) (0 : 0 ⟶ Y) ≅ X ⨿ Y := colimit.iso_colimit_cocone ⟨_, is_pushout_of_is_initial_is_coproduct _ _ _ _ has_zero_object.zero_is_initial (coprod_is_coprod X Y)⟩ @[simp] lemma inl_pushout_zero_zero_iso_hom (X Y : C) [has_binary_coproduct X Y] : pushout.inl ≫ (pushout_zero_zero_iso X Y).hom = coprod.inl := by { dsimp [pushout_zero_zero_iso], simp, } @[simp] lemma inr_pushout_zero_zero_iso_hom (X Y : C) [has_binary_coproduct X Y] : pushout.inr ≫ (pushout_zero_zero_iso X Y).hom = coprod.inr := by { dsimp [pushout_zero_zero_iso], simp, } @[simp] lemma inl_pushout_zero_zero_iso_inv (X Y : C) [has_binary_coproduct X Y] : coprod.inl ≫ (pushout_zero_zero_iso X Y).inv = pushout.inl := by { simp [iso.comp_inv_eq], } @[simp] lemma inr_pushout_zero_zero_iso_inv (X Y : C) [has_binary_coproduct X Y] : coprod.inr ≫ (pushout_zero_zero_iso X Y).inv = pushout.inr := by { simp [iso.comp_inv_eq], } end category_theory.limits
(* Victor B. F. Gomes, University of Cambridge Martin Kleppmann, University of Cambridge Dominic P. Mulligan, University of Cambridge Alastair R. Beresford, University of Cambridge *) section\<open>Axiomatic network models\<close> text\<open>In this section we develop a formal definition of an \emph{asynchronous unreliable causal broadcast network}. We choose this model because it satisfies the causal delivery requirements of many operation-based CRDTs~\cite{Almeida:2015fc,Baquero:2014ed}. Moreover, it is suitable for use in decentralised settings, as motivated in the introduction, since it does not require waiting for communication with a central server or a quorum of nodes.\<close> theory Network imports Convergence begin subsection\<open>Node histories\<close> text\<open>We model a distributed system as an unbounded number of communicating nodes. We assume nothing about the communication pattern of nodes---we assume only that each node is uniquely identified by a natural number, and that the flow of execution at each node consists of a finite, totally ordered sequence of execution steps (events). We call that sequence of events at node $i$ the \emph{history} of that node. For convenience, we assume that every event or execution step is unique within a node's history.\<close> locale node_histories = fixes history :: "nat \<Rightarrow> 'evt list" assumes histories_distinct [intro!, simp]: "distinct (history i)" lemma (in node_histories) history_finite: shows "finite (set (history i))" by auto definition (in node_histories) history_order :: "'evt \<Rightarrow> nat \<Rightarrow> 'evt \<Rightarrow> bool" ("_/ \<sqsubset>\<^sup>_/ _" [50,1000,50]50) where "x \<sqsubset>\<^sup>i z \<equiv> \<exists>xs ys zs. xs@x#ys@z#zs = history i" lemma (in node_histories) node_total_order_trans: assumes "e1 \<sqsubset>\<^sup>i e2" and "e2 \<sqsubset>\<^sup>i e3" shows "e1 \<sqsubset>\<^sup>i e3" proof - obtain xs1 xs2 ys1 ys2 zs1 zs2 where *: "xs1 @ e1 # ys1 @ e2 # zs1 = history i" "xs2 @ e2 # ys2 @ e3 # zs2 = history i" using history_order_def assms by auto hence "xs1 @ e1 # ys1 = xs2 \<and> zs1 = ys2 @ e3 # zs2" by(rule_tac xs="history i" and ys="[e2]" in pre_suf_eq_distinct_list) auto thus ?thesis by(clarsimp simp: history_order_def) (metis "*"(2) append.assoc append_Cons) qed lemma (in node_histories) local_order_carrier_closed: assumes "e1 \<sqsubset>\<^sup>i e2" shows "{e1,e2} \<subseteq> set (history i)" using assms by (clarsimp simp add: history_order_def) (metis in_set_conv_decomp Un_iff Un_subset_iff insert_subset list.simps(15) set_append set_subset_Cons)+ lemma (in node_histories) node_total_order_irrefl: shows "\<not> (e \<sqsubset>\<^sup>i e)" by(clarsimp simp add: history_order_def) (metis Un_iff histories_distinct distinct_append distinct_set_notin list.set_intros(1) set_append) lemma (in node_histories) node_total_order_antisym: assumes "e1 \<sqsubset>\<^sup>i e2" and "e2 \<sqsubset>\<^sup>i e1" shows "False" using assms node_total_order_irrefl node_total_order_trans by blast lemma (in node_histories) node_order_is_total: assumes "e1 \<in> set (history i)" and "e2 \<in> set (history i)" and "e1 \<noteq> e2" shows "e1 \<sqsubset>\<^sup>i e2 \<or> e2 \<sqsubset>\<^sup>i e1" using assms unfolding history_order_def by(metis list_split_two_elems histories_distinct) definition (in node_histories) prefix_of_node_history :: "'evt list \<Rightarrow> nat \<Rightarrow> bool" (infix "prefix of" 50) where "xs prefix of i \<equiv> \<exists>ys. xs@ys = history i" lemma (in node_histories) carriers_head_lt: assumes "y#ys = history i" shows "\<not>(x \<sqsubset>\<^sup>i y)" using assms apply(clarsimp simp add: history_order_def) apply(rename_tac xs1 ys1 zs1) apply (subgoal_tac "xs1 @ x # ys1 = [] \<and> zs1 = ys") apply clarsimp apply (rule_tac xs="history i" and ys="[y]" in pre_suf_eq_distinct_list) apply auto done lemma (in node_histories) prefix_of_ConsD [dest]: assumes "x # xs prefix of i" shows "[x] prefix of i" using assms by(auto simp: prefix_of_node_history_def) lemma (in node_histories) prefix_of_appendD [dest]: assumes "xs @ ys prefix of i" shows "xs prefix of i" using assms by(auto simp: prefix_of_node_history_def) lemma (in node_histories) prefix_distinct: assumes "xs prefix of i" shows "distinct xs" using assms by(clarsimp simp: prefix_of_node_history_def) (metis histories_distinct distinct_append) lemma (in node_histories) prefix_to_carriers [intro]: assumes "xs prefix of i" shows "set xs \<subseteq> set (history i)" using assms by(clarsimp simp: prefix_of_node_history_def) (metis Un_iff set_append) lemma (in node_histories) prefix_elem_to_carriers: assumes "xs prefix of i" and "x \<in> set xs" shows "x \<in> set (history i)" using assms by(clarsimp simp: prefix_of_node_history_def) (metis Un_iff set_append) lemma (in node_histories) local_order_prefix_closed: assumes "x \<sqsubset>\<^sup>i y" and "xs prefix of i" and "y \<in> set xs" shows "x \<in> set xs" proof - obtain ys where "xs @ ys = history i" using assms prefix_of_node_history_def by blast moreover obtain as bs cs where "as @ x # bs @ y # cs = history i" using assms history_order_def by blast moreover obtain pre suf where *: "xs = pre @ y # suf" using assms split_list by fastforce ultimately have "pre = as @ x # bs \<and> suf @ ys = cs" by (rule_tac xs="history i" and ys="[y]" in pre_suf_eq_distinct_list) auto thus ?thesis using assms * by clarsimp qed lemma (in node_histories) local_order_prefix_closed_last: assumes "x \<sqsubset>\<^sup>i y" and "xs@[y] prefix of i" shows "x \<in> set xs" proof - have "x \<in> set (xs @ [y])" using assms by (force dest: local_order_prefix_closed) thus ?thesis using assms by(force simp add: node_total_order_irrefl prefix_to_carriers) qed lemma (in node_histories) events_before_exist: assumes "x \<in> set (history i)" shows "\<exists>pre. pre @ [x] prefix of i" proof - have "\<exists>idx. idx < length (history i) \<and> (history i) ! idx = x" using assms by(simp add: set_elem_nth) thus ?thesis by(metis append_take_drop_id take_Suc_conv_app_nth prefix_of_node_history_def) qed lemma (in node_histories) events_in_local_order: assumes "pre @ [e2] prefix of i" and "e1 \<in> set pre" shows "e1 \<sqsubset>\<^sup>i e2" using assms split_list unfolding history_order_def prefix_of_node_history_def by fastforce subsection\<open>Asynchronous broadcast networks\<close> text\<open>We define a new locale $\isa{network}$ containing three axioms that define how broadcast and deliver events may interact, with these axioms defining the properties of our network model.\<close> datatype 'msg event = Broadcast 'msg | Deliver 'msg locale network = node_histories history for history :: "nat \<Rightarrow> 'msg event list" + fixes msg_id :: "'msg \<Rightarrow> 'msgid" (* Broadcast/Deliver interaction *) assumes delivery_has_a_cause: "\<lbrakk> Deliver m \<in> set (history i) \<rbrakk> \<Longrightarrow> \<exists>j. Broadcast m \<in> set (history j)" and deliver_locally: "\<lbrakk> Broadcast m \<in> set (history i) \<rbrakk> \<Longrightarrow> Broadcast m \<sqsubset>\<^sup>i Deliver m" and msg_id_unique: "\<lbrakk> Broadcast m1 \<in> set (history i); Broadcast m2 \<in> set (history j); msg_id m1 = msg_id m2 \<rbrakk> \<Longrightarrow> i = j \<and> m1 = m2" text\<open> The axioms can be understood as follows: \begin{description} \item[delivery-has-a-cause:] If some message $\isa{m}$ was delivered at some node, then there exists some node on which $\isa{m}$ was broadcast. With this axiom, we assert that messages are not created ``out of thin air'' by the network itself, and that the only source of messages are the nodes. \item[deliver-locally:] If a node broadcasts some message $\isa{m}$, then the same node must subsequently also deliver $\isa{m}$ to itself. Since $\isa{m}$ does not actually travel over the network, this local delivery is always possible, even if the network is interrupted. Local delivery may seem redundant, since the effect of the delivery could also be implemented by the broadcast event itself; however, it is standard practice in the description of broadcast protocols that the sender of a message also sends it to itself, since this property simplifies the definition of algorithms built on top of the broadcast abstraction \cite{Cachin:2011wt}. \item[msg-id-unique:] We do not assume that the message type $\isacharprime\isa{msg}$ has any particular structure; we only assume the existence of a function $\isa{msg-id} \mathbin{\isacharcolon\isacharcolon} \isacharprime\isa{msg} \mathbin{\isasymRightarrow} \isacharprime\isa{msgid}$ that maps every message to some globally unique identifier of type $\isacharprime\isa{msgid}$. We assert this uniqueness by stating that if $\isa{m1}$ and $\isa{m2}$ are any two messages broadcast by any two nodes, and their $\isa{msg-id}$s are the same, then they were in fact broadcast by the same node and the two messages are identical. In practice, these globally unique IDs can by implemented using unique node identifiers, sequence numbers or timestamps. \end{description} \<close> lemma (in network) broadcast_before_delivery: assumes "Deliver m \<in> set (history i)" shows "\<exists>j. Broadcast m \<sqsubset>\<^sup>j Deliver m" using assms deliver_locally delivery_has_a_cause by blast lemma (in network) broadcasts_unique: assumes "i \<noteq> j" and "Broadcast m \<in> set (history i)" shows "Broadcast m \<notin> set (history j)" using assms msg_id_unique by blast text\<open>Based on the well-known definition by \cite{Lamport:1978jq}, we say that $\isa{m1}\prec\isa{m2}$ if any of the following is true: \begin{enumerate} \item $\isa{m1}$ and $\isa{m2}$ were broadcast by the same node, and $\isa{m1}$ was broadcast before $\isa{m2}$. \item The node that broadcast $\isa{m2}$ had delivered $\isa{m1}$ before it broadcast $\isa{m2}$. \item There exists some operation $\isa{m3}$ such that $\isa{m1} \prec \isa{m3}$ and $\isa{m3} \prec \isa{m2}$. \end{enumerate}\<close> inductive (in network) hb :: "'msg \<Rightarrow> 'msg \<Rightarrow> bool" where hb_broadcast: "\<lbrakk> Broadcast m1 \<sqsubset>\<^sup>i Broadcast m2 \<rbrakk> \<Longrightarrow> hb m1 m2" | hb_deliver: "\<lbrakk> Deliver m1 \<sqsubset>\<^sup>i Broadcast m2 \<rbrakk> \<Longrightarrow> hb m1 m2" | hb_trans: "\<lbrakk> hb m1 m2; hb m2 m3 \<rbrakk> \<Longrightarrow> hb m1 m3" inductive_cases (in network) hb_elim: "hb x y" definition (in network) weak_hb :: "'msg \<Rightarrow> 'msg \<Rightarrow> bool" where "weak_hb m1 m2 \<equiv> hb m1 m2 \<or> m1 = m2" locale causal_network = network + assumes causal_delivery: "Deliver m2 \<in> set (history j) \<Longrightarrow> hb m1 m2 \<Longrightarrow> Deliver m1 \<sqsubset>\<^sup>j Deliver m2" lemma (in causal_network) causal_broadcast: assumes "Deliver m2 \<in> set (history j)" and "Deliver m1 \<sqsubset>\<^sup>i Broadcast m2" shows "Deliver m1 \<sqsubset>\<^sup>j Deliver m2" using assms causal_delivery hb.intros(2) by blast lemma (in network) hb_broadcast_exists1: assumes "hb m1 m2" shows "\<exists>i. Broadcast m1 \<in> set (history i)" using assms apply(induction rule: hb.induct) apply(meson insert_subset node_histories.local_order_carrier_closed node_histories_axioms) apply(meson delivery_has_a_cause insert_subset local_order_carrier_closed) apply simp done lemma (in network) hb_broadcast_exists2: assumes "hb m1 m2" shows "\<exists>i. Broadcast m2 \<in> set (history i)" using assms apply(induction rule: hb.induct) apply(meson insert_subset node_histories.local_order_carrier_closed node_histories_axioms) apply(meson delivery_has_a_cause insert_subset local_order_carrier_closed) apply simp done subsection\<open>Causal networks\<close> lemma (in causal_network) hb_has_a_reason: assumes "hb m1 m2" and "Broadcast m2 \<in> set (history i)" shows "Deliver m1 \<in> set (history i) \<or> Broadcast m1 \<in> set (history i)" using assms apply (induction rule: hb.induct) apply(metis insert_subset local_order_carrier_closed network.broadcasts_unique network_axioms) apply(metis insert_subset local_order_carrier_closed network.broadcasts_unique network_axioms) using hb_trans causal_delivery local_order_carrier_closed apply blast done lemma (in causal_network) hb_cross_node_delivery: assumes "hb m1 m2" and "Broadcast m1 \<in> set (history i)" and "Broadcast m2 \<in> set (history j)" and "i \<noteq> j" shows "Deliver m1 \<in> set (history j)" using assms apply(induction rule: hb.induct) apply(metis broadcasts_unique insert_subset local_order_carrier_closed) apply(metis insert_subset local_order_carrier_closed network.broadcasts_unique network_axioms) using broadcasts_unique hb.intros(3) hb_has_a_reason apply blast done lemma (in causal_network) hb_irrefl: assumes "hb m1 m2" shows "m1 \<noteq> m2" using assms proof(induction rule: hb.induct) case (hb_broadcast m1 i m2) thus ?case using node_total_order_antisym by blast next case (hb_deliver m1 i m2) thus ?case by(meson causal_broadcast insert_subset local_order_carrier_closed node_total_order_irrefl) next case (hb_trans m1 m2 m3) then obtain i j where "Broadcast m3 \<in> set (history i)" "Broadcast m2 \<in> set (history j)" using hb_broadcast_exists2 by blast then show ?case using assms hb_trans by (meson causal_network.causal_delivery causal_network_axioms deliver_locally insert_subset network.hb.intros(3) network_axioms node_histories.local_order_carrier_closed assms hb_trans node_histories_axioms node_total_order_irrefl) qed lemma (in causal_network) hb_broadcast_broadcast_order: assumes "hb m1 m2" and "Broadcast m1 \<in> set (history i)" and "Broadcast m2 \<in> set (history i)" shows "Broadcast m1 \<sqsubset>\<^sup>i Broadcast m2" using assms proof(induction rule: hb.induct) case (hb_broadcast m1 i m2) thus ?case by(metis insertI1 local_order_carrier_closed network.broadcasts_unique network_axioms subsetCE) next case (hb_deliver m1 i m2) thus ?case by(metis broadcasts_unique insert_subset local_order_carrier_closed network.broadcast_before_delivery network_axioms node_total_order_trans) next case (hb_trans m1 m2 m3) then show ?case proof (cases "Broadcast m2 \<in> set (history i)") case True thus ?thesis using hb_trans node_total_order_trans by blast next case False hence "Deliver m2 \<in> set (history i)" "m1 \<noteq> m2" "m2 \<noteq> m3" using hb_has_a_reason hb_trans by auto thus ?thesis by(metis hb_trans event.inject(1) hb.intros(1) hb_irrefl network.hb.intros(3) network_axioms node_order_is_total hb_irrefl) qed qed lemma (in causal_network) hb_antisym: assumes "hb x y" and "hb y x" shows "False" using assms proof(induction rule: hb.induct) fix m1 i m2 assume "hb m2 m1" and "Broadcast m1 \<sqsubset>\<^sup>i Broadcast m2" thus False apply - proof(erule hb_elim) show "\<And>ia. Broadcast m1 \<sqsubset>\<^sup>i Broadcast m2 \<Longrightarrow> Broadcast m2 \<sqsubset>\<^sup>ia Broadcast m1 \<Longrightarrow> False" by(metis broadcasts_unique insert_subset local_order_carrier_closed node_total_order_irrefl node_total_order_trans) next show "\<And>ia. Broadcast m1 \<sqsubset>\<^sup>i Broadcast m2 \<Longrightarrow> Deliver m2 \<sqsubset>\<^sup>ia Broadcast m1 \<Longrightarrow> False" by(metis broadcast_before_delivery broadcasts_unique insert_subset local_order_carrier_closed node_total_order_irrefl node_total_order_trans) next show "\<And>m2a. Broadcast m1 \<sqsubset>\<^sup>i Broadcast m2 \<Longrightarrow> hb m2 m2a \<Longrightarrow> hb m2a m1 \<Longrightarrow> False" using assms(1) assms(2) hb.intros(3) hb_irrefl by blast qed next fix m1 i m2 assume "hb m2 m1" and "Deliver m1 \<sqsubset>\<^sup>i Broadcast m2" thus "False" apply - proof(erule hb_elim) show "\<And>ia. Deliver m1 \<sqsubset>\<^sup>i Broadcast m2 \<Longrightarrow> Broadcast m2 \<sqsubset>\<^sup>ia Broadcast m1 \<Longrightarrow> False" by (metis broadcast_before_delivery broadcasts_unique insert_subset local_order_carrier_closed node_total_order_irrefl node_total_order_trans) next show "\<And>ia. Deliver m1 \<sqsubset>\<^sup>i Broadcast m2 \<Longrightarrow> Deliver m2 \<sqsubset>\<^sup>ia Broadcast m1 \<Longrightarrow> False" by (meson causal_network.causal_delivery causal_network_axioms hb.intros(2) hb.intros(3) insert_subset local_order_carrier_closed node_total_order_irrefl) next show "\<And>m2a. Deliver m1 \<sqsubset>\<^sup>i Broadcast m2 \<Longrightarrow> hb m2 m2a \<Longrightarrow> hb m2a m1 \<Longrightarrow> False" by (meson causal_delivery hb.intros(2) insert_subset local_order_carrier_closed network.hb.intros(3) network_axioms node_total_order_irrefl) qed next fix m1 m2 m3 assume "hb m1 m2" "hb m2 m3" "hb m3 m1" and "(hb m2 m1 \<Longrightarrow> False)" "(hb m3 m2 \<Longrightarrow> False)" thus "False" using hb.intros(3) by blast qed definition (in network) node_deliver_messages :: "'msg event list \<Rightarrow> 'msg list" where "node_deliver_messages cs \<equiv> List.map_filter (\<lambda>e. case e of Deliver m \<Rightarrow> Some m | _ \<Rightarrow> None) cs" lemma (in network) node_deliver_messages_empty [simp]: shows "node_deliver_messages [] = []" by(auto simp add: node_deliver_messages_def List.map_filter_simps) lemma (in network) node_deliver_messages_Cons: shows "node_deliver_messages (x#xs) = (node_deliver_messages [x])@(node_deliver_messages xs)" by(auto simp add: node_deliver_messages_def map_filter_def) lemma (in network) node_deliver_messages_append: shows "node_deliver_messages (xs@ys) = (node_deliver_messages xs)@(node_deliver_messages ys)" by(auto simp add: node_deliver_messages_def map_filter_def) lemma (in network) node_deliver_messages_Broadcast [simp]: shows "node_deliver_messages [Broadcast m] = []" by(clarsimp simp: node_deliver_messages_def map_filter_def) lemma (in network) node_deliver_messages_Deliver [simp]: shows "node_deliver_messages [Deliver m] = [m]" by(clarsimp simp: node_deliver_messages_def map_filter_def) lemma (in network) prefix_msg_in_history: assumes "es prefix of i" and "m \<in> set (node_deliver_messages es)" shows "Deliver m \<in> set (history i)" using assms prefix_to_carriers by(fastforce simp: node_deliver_messages_def map_filter_def split: event.split_asm) lemma (in network) prefix_contains_msg: assumes "es prefix of i" and "m \<in> set (node_deliver_messages es)" shows "Deliver m \<in> set es" using assms by(auto simp: node_deliver_messages_def map_filter_def split: event.split_asm) lemma (in network) node_deliver_messages_distinct: assumes "xs prefix of i" shows "distinct (node_deliver_messages xs)" using assms proof(induction xs rule: rev_induct) case Nil thus ?case by simp next case (snoc x xs) { fix y assume *: "y \<in> set (node_deliver_messages xs)" "y \<in> set (node_deliver_messages [x])" moreover have "distinct (xs @ [x])" using assms snoc prefix_distinct by blast ultimately have "False" using assms apply(case_tac x; clarsimp simp add: map_filter_def node_deliver_messages_def) using * prefix_contains_msg snoc.prems by blast } thus ?case using snoc by(fastforce simp add: node_deliver_messages_append node_deliver_messages_def map_filter_def) qed lemma (in network) drop_last_message: assumes "evts prefix of i" and "node_deliver_messages evts = msgs @ [last_msg]" shows "\<exists>pre. pre prefix of i \<and> node_deliver_messages pre = msgs" proof - have "Deliver last_msg \<in> set evts" using assms network.prefix_contains_msg network_axioms by force then obtain idx where *: "idx < length evts" "evts ! idx = Deliver last_msg" by (meson set_elem_nth) then obtain pre suf where "evts = pre @ (evts ! idx) # suf" using id_take_nth_drop by blast hence **: "evts = pre @ (Deliver last_msg) # suf" using assms * by auto moreover hence "distinct (node_deliver_messages ([Deliver last_msg] @ suf))" by (metis assms(1) assms(2) distinct_singleton node_deliver_messages_Cons node_deliver_messages_Deliver node_deliver_messages_append node_deliver_messages_distinct not_Cons_self2 pre_suf_eq_distinct_list) ultimately have "node_deliver_messages ([Deliver last_msg] @ suf) = [last_msg] @ []" by (metis append_self_conv assms(1) assms(2) node_deliver_messages_Cons node_deliver_messages_Deliver node_deliver_messages_append node_deliver_messages_distinct not_Cons_self2 pre_suf_eq_distinct_list) thus ?thesis using assms * ** by (metis append1_eq_conv append_Cons append_Nil node_deliver_messages_append prefix_of_appendD) qed locale network_with_ops = causal_network history fst for history :: "nat \<Rightarrow> ('msgid \<times> 'op) event list" + fixes interp :: "'op \<Rightarrow> 'state \<rightharpoonup> 'state" and initial_state :: "'state" context network_with_ops begin definition interp_msg :: "'msgid \<times> 'op \<Rightarrow> 'state \<rightharpoonup> 'state" where "interp_msg msg state \<equiv> interp (snd msg) state" sublocale hb: happens_before weak_hb hb interp_msg proof fix x y :: "'msgid \<times> 'op" show "hb x y = (weak_hb x y \<and> \<not> weak_hb y x)" unfolding weak_hb_def using hb_antisym by blast next fix x show "weak_hb x x" using weak_hb_def by blast next fix x y z assume "weak_hb x y" "weak_hb y z" thus "weak_hb x z" using weak_hb_def by (metis network.hb.intros(3) network_axioms) qed end definition (in network_with_ops) apply_operations :: "('msgid \<times> 'op) event list \<rightharpoonup> 'state" where "apply_operations es \<equiv> hb.apply_operations (node_deliver_messages es) initial_state" definition (in network_with_ops) node_deliver_ops :: "('msgid \<times> 'op) event list \<Rightarrow> 'op list" where "node_deliver_ops cs \<equiv> map snd (node_deliver_messages cs)" lemma (in network_with_ops) apply_operations_empty [simp]: shows "apply_operations [] = Some initial_state" by(auto simp add: apply_operations_def) lemma (in network_with_ops) apply_operations_Broadcast [simp]: shows "apply_operations (xs @ [Broadcast m]) = apply_operations xs" by(auto simp add: apply_operations_def node_deliver_messages_def map_filter_def) lemma (in network_with_ops) apply_operations_Deliver [simp]: shows "apply_operations (xs @ [Deliver m]) = (apply_operations xs \<bind> interp_msg m)" by(auto simp add: apply_operations_def node_deliver_messages_def map_filter_def kleisli_def) lemma (in network_with_ops) hb_consistent_technical: assumes "\<And>m n. m < length cs \<Longrightarrow> n < m \<Longrightarrow> cs ! n \<sqsubset>\<^sup>i cs ! m" shows "hb.hb_consistent (node_deliver_messages cs)" using assms proof (induction cs rule: rev_induct) case Nil thus ?case by(simp add: node_deliver_messages_def hb.hb_consistent.intros(1) map_filter_simps(2)) next case (snoc x xs) hence *: "(\<And>m n. m < length xs \<Longrightarrow> n < m \<Longrightarrow> xs ! n \<sqsubset>\<^sup>i xs ! m)" by(-, erule_tac x=m in meta_allE, erule_tac x=n in meta_allE, clarsimp simp add: nth_append) then show ?case proof (cases x) case (Broadcast x1) thus ?thesis using snoc * by (simp add: node_deliver_messages_append) next case (Deliver x2) thus ?thesis using snoc * apply(clarsimp simp add: node_deliver_messages_def map_filter_def map_filter_append) apply (rename_tac m m1 m2) apply (case_tac m; clarsimp) apply(drule set_elem_nth, erule exE, erule conjE) apply(erule_tac x="length xs" in meta_allE) apply(clarsimp simp add: nth_append) by (metis causal_delivery insert_subset node_histories.local_order_carrier_closed node_histories_axioms node_total_order_antisym) qed qed corollary (in network_with_ops) shows "hb.hb_consistent (node_deliver_messages (history i))" by (metis hb_consistent_technical history_order_def less_one linorder_neqE_nat list_nth_split zero_order(3)) lemma (in network_with_ops) hb_consistent_prefix: assumes "xs prefix of i" shows "hb.hb_consistent (node_deliver_messages xs)" using assms proof (clarsimp simp: prefix_of_node_history_def, rule_tac i=i in hb_consistent_technical) fix m n ys assume *: "xs @ ys = history i" "m < length xs" "n < m" consider (a) "xs = []" | (b) "\<exists>c. xs = [c]" | (c) "Suc 0 < length (xs)" by (metis Suc_pred length_Suc_conv length_greater_0_conv zero_less_diff) thus "xs ! n \<sqsubset>\<^sup>i xs ! m" proof (cases) case a thus ?thesis using * by clarsimp next case b thus ?thesis using assms * by clarsimp next case c thus ?thesis using assms * apply clarsimp apply(drule list_nth_split, assumption, clarsimp simp: c) apply (metis append.assoc append.simps(2) history_order_def) done qed qed locale network_with_constrained_ops = network_with_ops + fixes valid_msg :: "'c \<Rightarrow> ('a \<times> 'b) \<Rightarrow> bool" assumes broadcast_only_valid_msgs: "pre @ [Broadcast m] prefix of i \<Longrightarrow> \<exists>state. apply_operations pre = Some state \<and> valid_msg state m" lemma (in network_with_constrained_ops) broadcast_is_valid: assumes "Broadcast m \<in> set (history i)" shows "\<exists>state. valid_msg state m" using assms broadcast_only_valid_msgs events_before_exist by blast lemma (in network_with_constrained_ops) deliver_is_valid: assumes "Deliver m \<in> set (history i)" shows "\<exists>j pre state. pre @ [Broadcast m] prefix of j \<and> apply_operations pre = Some state \<and> valid_msg state m" using assms apply (clarsimp dest!: delivery_has_a_cause) using broadcast_only_valid_msgs events_before_exist apply blast done lemma (in network_with_constrained_ops) deliver_in_prefix_is_valid: assumes "xs prefix of i" and "Deliver m \<in> set xs" shows "\<exists>state. valid_msg state m" by (meson assms network_with_constrained_ops.deliver_is_valid network_with_constrained_ops_axioms prefix_elem_to_carriers) subsection\<open>Dummy network models\<close> interpretation trivial_node_histories: node_histories "\<lambda>m. []" by standard auto interpretation trivial_network: network "\<lambda>m. []" id by standard auto interpretation trivial_causal_network: causal_network "\<lambda>m. []" id by standard auto interpretation trivial_network_with_ops: network_with_ops "\<lambda>m. []" "(\<lambda>x y. Some y)" 0 by standard auto interpretation trivial_network_with_constrained_ops: network_with_constrained_ops "\<lambda>m. []" "(\<lambda>x y. Some y)" 0 "\<lambda>x y. True" by standard (simp add: trivial_node_histories.prefix_of_node_history_def) end
-- Opuesto_de_cero.lean -- Si R es un anillo, entonces -0 = 0. -- José A. Alonso Jiménez <https://jaalonso.github.io> -- Sevilla, 8-septiembre-2022 -- --------------------------------------------------------------------- -- --------------------------------------------------------------------- -- Demostrar que si R es un anillo, entonces -- -0 = 0 -- ---------------------------------------------------------------------- import algebra.ring variables {R : Type*} [ring R] -- 1ª demostración -- =============== example : (-0 : R) = 0 := begin have h : 0 - 0 = (-0 : R) := zero_sub 0, calc (-0 : R) = 0 - 0 : h.symm ... = -(0 - 0) : (neg_sub (0 : R) 0).symm ... = -(-0) : congr_arg (λ x, -x) h ... = 0 : neg_neg 0 end -- 2ª demostración -- =============== example : (-0 : R) = 0 := begin have h : 0 - 0 = (-0 : R) := by rw zero_sub, calc (-0 : R) = 0 - 0 : by rw h ... = -(0 - 0) : by rw neg_sub ... = -(-0) : by {congr; rw h} ... = 0 : by rw neg_neg end -- 3ª demostración -- =============== example : (-0 : R) = 0 := by simpa only [zero_sub, neg_neg] using (neg_sub (0 : R) 0).symm -- 4ª demostración -- =============== example : (-0 : R) = 0 := neg_zero -- 5ª demostración -- =============== example : (-0 : R) = 0 := by simp -- 6ª demostración -- =============== example : (-0 : R) = 0 := begin apply neg_eq_of_add_eq_zero_right, rw add_zero, end -- 7ª demostración -- =============== example : (-0 : R) = 0 := neg_eq_of_add_eq_zero_right (add_zero 0)
(* Title: CoreC++ Author: Daniel Wasserrab Maintainer: Daniel Wasserrab <wasserra at fmi.uni-passau.de> Based on the Jinja theory Common/Decl.thy by David von Oheimb and Tobias Nipkow *) section \<open>CoreC++ types\<close> theory Type imports Auxiliary begin type_synonym cname = string \<comment> \<open>class names\<close> type_synonym mname = string \<comment> \<open>method name\<close> type_synonym vname = string \<comment> \<open>names for local/field variables\<close> definition this :: vname where "this \<equiv> ''this''" \<comment> \<open>types\<close> datatype ty = Void \<comment> \<open>type of statements\<close> | Boolean | Integer | NT \<comment> \<open>null type\<close> | Class cname \<comment> \<open>class type\<close> datatype base \<comment> \<open>superclass\<close> = Repeats cname \<comment> \<open>repeated (nonvirtual) inheritance\<close> | Shares cname \<comment> \<open>shared (virtual) inheritance\<close> primrec getbase :: "base \<Rightarrow> cname" where "getbase (Repeats C) = C" | "getbase (Shares C) = C" primrec isRepBase :: "base \<Rightarrow> bool" where "isRepBase (Repeats C) = True" | "isRepBase (Shares C) = False" primrec isShBase :: "base \<Rightarrow> bool" where "isShBase(Repeats C) = False" | "isShBase(Shares C) = True" definition is_refT :: "ty \<Rightarrow> bool" where "is_refT T \<equiv> T = NT \<or> (\<exists>C. T = Class C)" lemma [iff]: "is_refT(Class C)" by(simp add:is_refT_def) lemma refTE: "\<lbrakk>is_refT T; T = NT \<Longrightarrow> Q; \<And>C. T = Class C \<Longrightarrow> Q \<rbrakk> \<Longrightarrow> Q" by (auto simp add: is_refT_def) lemma not_refTE: "\<lbrakk> \<not>is_refT T; T = Void \<or> T = Boolean \<or> T = Integer \<Longrightarrow> Q \<rbrakk> \<Longrightarrow> Q" by (cases T, auto simp add: is_refT_def) type_synonym env = "vname \<rightharpoonup> ty" end
The Lebesgue measure of an interval is its length.
The Lebesgue measure of an interval is its length.
If $g$ is analytic on $S$ and for all $z \in S$, there exists a $d > 0$ such that for all $w \in B(z, d) - \{a\}$, $g(w) = (w - a)f(w)$, then $f$ is analytic on $S$.
-- Andreas, 2019-10-13, issue 4125 -- Avoid unnecessary normalization in type checker. -- Print to the user what they wrote, not its expanded form. -- {-# OPTIONS -v tc:25 #-} postulate We-do-not-want-to : Set → Set see-this-in-the-output : Set A = We-do-not-want-to see-this-in-the-output postulate P : A → Set test : ∀{a} → P a → P a test p = {!!} -- C-c C-, -- Expected to see -- a : A -- in the context, not the expanded monster of A. -- Testing that the etaExpandVar strategy of the unifier -- does not reduce the context. record ⊤ : Set where data D : ⊤ → Set where c : ∀{x} → D x etaExp : ∀{a} → D record{} → P a etaExp c = {!!} -- C-c C-, -- WAS (2.5.x-2.6.0): -- a : We-do-not-want-to see-this-in-the-output (not in scope) -- EXPECTED -- a : A
/- Copyright (c) 2018 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl -/ import data.multiset.bind /-! # Sections of a multiset > THIS FILE IS SYNCHRONIZED WITH MATHLIB4. > Any changes to this file require a corresponding PR to mathlib4. -/ namespace multiset variables {α : Type*} section sections /-- The sections of a multiset of multisets `s` consists of all those multisets which can be put in bijection with `s`, so each element is an member of the corresponding multiset. -/ def sections (s : multiset (multiset α)) : multiset (multiset α) := multiset.rec_on s {0} (λs _ c, s.bind $ λa, c.map (multiset.cons a)) (assume a₀ a₁ s pi, by simp [map_bind, bind_bind a₀ a₁, cons_swap]) @[simp] lemma sections_zero : sections (0 : multiset (multiset α)) = {0} := rfl @[simp] lemma sections_cons (s : multiset (multiset α)) (m : multiset α) : sections (m ::ₘ s) = m.bind (λa, (sections s).map (multiset.cons a)) := rec_on_cons m s lemma coe_sections : ∀(l : list (list α)), sections ((l.map (λl:list α, (l : multiset α))) : multiset (multiset α)) = ((l.sections.map (λl:list α, (l : multiset α))) : multiset (multiset α)) | [] := rfl | (a :: l) := begin simp, rw [← cons_coe, sections_cons, bind_map_comm, coe_sections l], simp [list.sections, (∘), list.bind] end @[simp] lemma sections_add (s t : multiset (multiset α)) : sections (s + t) = (sections s).bind (λm, (sections t).map ((+) m)) := multiset.induction_on s (by simp) (assume a s ih, by simp [ih, bind_assoc, map_bind, bind_map, -add_comm]) lemma mem_sections {s : multiset (multiset α)} : ∀{a}, a ∈ sections s ↔ s.rel (λs a, a ∈ s) a := multiset.induction_on s (by simp) (assume a s ih a', by simp [ih, rel_cons_left, -exists_and_distrib_left, exists_and_distrib_left.symm, eq_comm]) lemma card_sections {s : multiset (multiset α)} : card (sections s) = prod (s.map card) := multiset.induction_on s (by simp) (by simp {contextual := tt}) lemma prod_map_sum [comm_semiring α] {s : multiset (multiset α)} : prod (s.map sum) = sum ((sections s).map prod) := multiset.induction_on s (by simp) (assume a s ih, by simp [ih, map_bind, sum_map_mul_left, sum_map_mul_right]) end sections end multiset
# DySyn_distance <- function (x, method= "hellinger"){ # # if (method == "ord") { # x_dif <- x[1,]-x[2,] # acum <- 0 # aux <- 0 # for(i in 1:length(x_dif)){ # aux <- x_dif[i]+aux # acum <- acum+aux # } # return(abs(acum)) # } # return(as.numeric(philentropy::distance(x, method = method, p=0.5))) # # } DySyn_distance <- function (x, method= "hellinger"){ if (method == "ord") { x_dif <- x[1,]-x[2,] acum <- 0 aux <- 0 for(i in 1:length(x_dif)){ aux <- x_dif[i]+aux acum <- acum+aux } return(abs(acum)) } if(method == "topsoe"){ re <- 0 for(i in 1:ncol(x)) re <- re + ( x[1,i] * log( (2*x[1,i])/(x[1,i] + x[2,i]) ) + x[2,i]*log( (2*x[2,i])/(x[2,i] + x[1,i]) ) ) return(re) } if(method == "jensen_difference"){ re <- 0 for(i in 1:ncol(x)) re <- re + ( ((x[1,i]*log(x[1,i]) + x[2,i]*log(x[2,i]) )/2) - ((x[1,i] + x[2,i])/2 ) * log((x[1,i] + x[2,i])/2 ) ) return(re) } if(method == "taneja"){ re <- 0 for(i in 1:ncol(x)) re <- re + ( ((x[1,i] + x[2,i])/2) * log( (x[1,i] + x[2,i]) / (2 * sqrt(x[1,i] * x[2,i]) )) ) return(re) } if(method == "hellinger"){ re <- 0 for(i in 1:ncol(x)) re <- re + sqrt((x[1,i] * x[2,i])) return(2*sqrt(1 - re)) } if(method == "prob_symm"){ re <- 0 for(i in 1:ncol(x)) re <- re + ( (x[1,i] - x[2,i] )^2 / (x[1,i] +x[2,i]) ) return(2*re) } stop("measure argument must be a valid option") } getHist <- function(scores, nbins){ breaks <- seq(0,1,length.out = nbins+1) breaks <- c(breaks[-length(breaks)], 1.1) re <- rep((1/(length(breaks)-1)),length(breaks)-1) for(i in 2:length(breaks)){ re[i-1] <- (re[i-1] + length(which(scores >= breaks[i-1] & scores < breaks[i])))/(length(scores)+1) } return(re) } TernarySearch <- function(left, right, f, eps=1e-4){ while(TRUE){ if (abs(left - right) < eps) return((left + right) / 2) leftThird <- left + (right - left) / 3 rightThird <- right - (right - left) / 3 if (f(leftThird) > f(rightThird)) left <- leftThird else right <- rightThird } }
(* Title: HOL/Auth/n_germanSimp_lemma_inv__37_on_rules.thy Author: Yongjian Li and Kaiqiang Duan, State Key Lab of Computer Science, Institute of Software, Chinese Academy of Sciences Copyright 2016 State Key Lab of Computer Science, Institute of Software, Chinese Academy of Sciences *) header{*The n_germanSimp Protocol Case Study*} theory n_germanSimp_lemma_inv__37_on_rules imports n_germanSimp_lemma_on_inv__37 begin section{*All lemmas on causal relation between inv__37*} lemma lemma_inv__37_on_rules: assumes b1: "r \<in> rules N" and b2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__37 p__Inv4)" shows "invHoldForRule s f r (invariants N)" proof - have c1: "(\<exists> i d. i\<le>N\<and>d\<le>N\<and>r=n_Store i d)\<or> (\<exists> i. i\<le>N\<and>r=n_RecvReqS N i)\<or> (\<exists> i. i\<le>N\<and>r=n_RecvReqE__part__0 N i)\<or> (\<exists> i. i\<le>N\<and>r=n_RecvReqE__part__1 N i)\<or> (\<exists> i. i\<le>N\<and>r=n_SendInv__part__0 i)\<or> (\<exists> i. i\<le>N\<and>r=n_SendInv__part__1 i)\<or> (\<exists> i. i\<le>N\<and>r=n_SendInvAck i)\<or> (\<exists> i. i\<le>N\<and>r=n_RecvInvAck i)\<or> (\<exists> i. i\<le>N\<and>r=n_SendGntS i)\<or> (\<exists> i. i\<le>N\<and>r=n_SendGntE N i)\<or> (\<exists> i. i\<le>N\<and>r=n_RecvGntS i)\<or> (\<exists> i. i\<le>N\<and>r=n_RecvGntE i)" apply (cut_tac b1, auto) done moreover { assume d1: "(\<exists> i d. i\<le>N\<and>d\<le>N\<and>r=n_Store i d)" have "invHoldForRule s f r (invariants N)" apply (cut_tac b2 d1, metis n_StoreVsinv__37) done } moreover { assume d1: "(\<exists> i. i\<le>N\<and>r=n_RecvReqS N i)" have "invHoldForRule s f r (invariants N)" apply (cut_tac b2 d1, metis n_RecvReqSVsinv__37) done } moreover { assume d1: "(\<exists> i. i\<le>N\<and>r=n_RecvReqE__part__0 N i)" have "invHoldForRule s f r (invariants N)" apply (cut_tac b2 d1, metis n_RecvReqE__part__0Vsinv__37) done } moreover { assume d1: "(\<exists> i. i\<le>N\<and>r=n_RecvReqE__part__1 N i)" have "invHoldForRule s f r (invariants N)" apply (cut_tac b2 d1, metis n_RecvReqE__part__1Vsinv__37) done } moreover { assume d1: "(\<exists> i. i\<le>N\<and>r=n_SendInv__part__0 i)" have "invHoldForRule s f r (invariants N)" apply (cut_tac b2 d1, metis n_SendInv__part__0Vsinv__37) done } moreover { assume d1: "(\<exists> i. i\<le>N\<and>r=n_SendInv__part__1 i)" have "invHoldForRule s f r (invariants N)" apply (cut_tac b2 d1, metis n_SendInv__part__1Vsinv__37) done } moreover { assume d1: "(\<exists> i. i\<le>N\<and>r=n_SendInvAck i)" have "invHoldForRule s f r (invariants N)" apply (cut_tac b2 d1, metis n_SendInvAckVsinv__37) done } moreover { assume d1: "(\<exists> i. i\<le>N\<and>r=n_RecvInvAck i)" have "invHoldForRule s f r (invariants N)" apply (cut_tac b2 d1, metis n_RecvInvAckVsinv__37) done } moreover { assume d1: "(\<exists> i. i\<le>N\<and>r=n_SendGntS i)" have "invHoldForRule s f r (invariants N)" apply (cut_tac b2 d1, metis n_SendGntSVsinv__37) done } moreover { assume d1: "(\<exists> i. i\<le>N\<and>r=n_SendGntE N i)" have "invHoldForRule s f r (invariants N)" apply (cut_tac b2 d1, metis n_SendGntEVsinv__37) done } moreover { assume d1: "(\<exists> i. i\<le>N\<and>r=n_RecvGntS i)" have "invHoldForRule s f r (invariants N)" apply (cut_tac b2 d1, metis n_RecvGntSVsinv__37) done } moreover { assume d1: "(\<exists> i. i\<le>N\<and>r=n_RecvGntE i)" have "invHoldForRule s f r (invariants N)" apply (cut_tac b2 d1, metis n_RecvGntEVsinv__37) done } ultimately show "invHoldForRule s f r (invariants N)" by satx qed end
(* * Copyright 2014, NICTA * * This software may be distributed and modified according to the terms of * the BSD 2-Clause license. Note that NO WARRANTY is provided. * See "LICENSE_BSD2.txt" for details. * * @TAG(NICTA_BSD) *) section "Enumeration extensions and alternative definition" theory Enumeration imports Main begin abbreviation "enum \<equiv> enum_class.enum" abbreviation "enum_all \<equiv> enum_class.enum_all" abbreviation "enum_ex \<equiv> enum_class.enum_ex" primrec (nonexhaustive) the_index :: "'a list \<Rightarrow> 'a \<Rightarrow> nat" where "the_index (x # xs) y = (if x = y then 0 else Suc (the_index xs y))" lemma the_index_bounded: "x \<in> set xs \<Longrightarrow> the_index xs x < length xs" by (induct xs, clarsimp+) lemma nth_the_index: "x \<in> set xs \<Longrightarrow> xs ! the_index xs x = x" by (induct xs, clarsimp+) lemma distinct_the_index_is_index[simp]: "\<lbrakk> distinct xs ; n < length xs \<rbrakk> \<Longrightarrow> the_index xs (xs ! n) = n" by (meson nth_eq_iff_index_eq nth_mem nth_the_index the_index_bounded) lemma the_index_last_distinct: "distinct xs \<and> xs \<noteq> [] \<Longrightarrow> the_index xs (last xs) = length xs - 1" apply safe apply (subgoal_tac "xs ! (length xs - 1) = last xs") apply (subgoal_tac "xs ! the_index xs (last xs) = last xs") apply (subst nth_eq_iff_index_eq[symmetric]) apply assumption apply (rule the_index_bounded) apply simp_all apply (rule nth_the_index) apply simp apply (induct xs, auto) done context enum begin (* These two are added for historical reasons. *) lemmas enum_surj[simp] = enum_UNIV declare enum_distinct[simp] lemma enum_nonempty[simp]: "(enum :: 'a list) \<noteq> []" using enum_surj by fastforce definition maxBound :: 'a where "maxBound \<equiv> last enum" definition minBound :: 'a where "minBound \<equiv> hd enum" definition toEnum :: "nat \<Rightarrow> 'a" where "toEnum n \<equiv> if n < length (enum :: 'a list) then enum ! n else the None" definition fromEnum :: "'a \<Rightarrow> nat" where "fromEnum x \<equiv> the_index enum x" lemma maxBound_is_length: "fromEnum maxBound = length (enum :: 'a list) - 1" by (simp add: maxBound_def fromEnum_def the_index_last_distinct) lemma maxBound_less_length: "(x \<le> fromEnum maxBound) = (x < length (enum :: 'a list))" unfolding maxBound_is_length by (cases "length enum") auto lemma maxBound_is_bound [simp]: "fromEnum x \<le> fromEnum maxBound" unfolding maxBound_less_length by (fastforce simp: fromEnum_def intro: the_index_bounded) lemma to_from_enum [simp]: fixes x :: 'a shows "toEnum (fromEnum x) = x" proof - have "x \<in> set enum" by simp then show ?thesis by (simp add: toEnum_def fromEnum_def nth_the_index the_index_bounded) qed lemma from_to_enum [simp]: "x \<le> fromEnum maxBound \<Longrightarrow> fromEnum (toEnum x) = x" unfolding maxBound_less_length by (simp add: toEnum_def fromEnum_def) lemma map_enum: fixes x :: 'a shows "map f enum ! fromEnum x = f x" proof - have "fromEnum x \<le> fromEnum (maxBound :: 'a)" by (rule maxBound_is_bound) then have "fromEnum x < length (enum::'a list)" by (simp add: maxBound_less_length) then have "map f enum ! fromEnum x = f (enum ! fromEnum x)" by simp also have "x \<in> set enum" by simp then have "enum ! fromEnum x = x" by (simp add: fromEnum_def nth_the_index) finally show ?thesis . qed definition assocs :: "('a \<Rightarrow> 'b) \<Rightarrow> ('a \<times> 'b) list" where "assocs f \<equiv> map (\<lambda>x. (x, f x)) enum" end (* For historical naming reasons. *) lemmas enum_bool = enum_bool_def lemma fromEnumTrue [simp]: "fromEnum True = 1" by (simp add: fromEnum_def enum_bool) lemma fromEnumFalse [simp]: "fromEnum False = 0" by (simp add: fromEnum_def enum_bool) class enum_alt = fixes enum_alt :: "nat \<Rightarrow> 'a option" class enumeration_alt = enum_alt + assumes enum_alt_one_bound: "enum_alt x = (None :: 'a option) \<Longrightarrow> enum_alt (Suc x) = (None :: 'a option)" assumes enum_alt_surj: "range enum_alt \<union> {None} = UNIV" assumes enum_alt_inj: "(enum_alt x :: 'a option) = enum_alt y \<Longrightarrow> (x = y) \<or> (enum_alt x = (None :: 'a option))" begin lemma enum_alt_inj_2: assumes "enum_alt x = (enum_alt y :: 'a option)" "enum_alt x \<noteq> (None :: 'a option)" shows "x = y" proof - from assms have "(x = y) \<or> (enum_alt x = (None :: 'a option))" by (fastforce intro!: enum_alt_inj) with assms show ?thesis by clarsimp qed lemma enum_alt_surj_2: "\<exists>x. enum_alt x = Some y" proof - have "Some y \<in> range enum_alt \<union> {None}" by (subst enum_alt_surj) simp then have "Some y \<in> range enum_alt" by simp then show ?thesis by auto qed end definition alt_from_ord :: "'a list \<Rightarrow> nat \<Rightarrow> 'a option" where "alt_from_ord L \<equiv> \<lambda>n. if (n < length L) then Some (L ! n) else None" lemma handy_if_lemma: "((if P then Some A else None) = Some B) = (P \<and> (A = B))" by simp class enumeration_both = enum_alt + enum + assumes enum_alt_rel: "enum_alt = alt_from_ord enum" instance enumeration_both < enumeration_alt apply (intro_classes; simp add: enum_alt_rel alt_from_ord_def) apply auto[1] apply (safe; simp)[1] apply (rule rev_image_eqI; simp) apply (rule the_index_bounded; simp) apply (subst nth_the_index; simp) apply (clarsimp simp: handy_if_lemma) apply (subst nth_eq_iff_index_eq[symmetric]; simp) done instantiation bool :: enumeration_both begin definition enum_alt_bool: "enum_alt \<equiv> alt_from_ord [False, True]" instance by (intro_classes, simp add: enum_bool_def enum_alt_bool) end definition toEnumAlt :: "nat \<Rightarrow> ('a :: enum_alt)" where "toEnumAlt n \<equiv> the (enum_alt n)" definition fromEnumAlt :: "('a :: enum_alt) \<Rightarrow> nat" where "fromEnumAlt x \<equiv> THE n. enum_alt n = Some x" definition upto_enum :: "('a :: enumeration_alt) \<Rightarrow> 'a \<Rightarrow> 'a list" ("(1[_.e._])") where "upto_enum n m \<equiv> map toEnumAlt [fromEnumAlt n ..< Suc (fromEnumAlt m)]" lemma fromEnum_alt_red[simp]: "fromEnumAlt = (fromEnum :: ('a :: enumeration_both) \<Rightarrow> nat)" apply (rule ext) apply (simp add: fromEnumAlt_def fromEnum_def enum_alt_rel alt_from_ord_def) apply (rule theI2) apply (rule conjI) apply (clarify, rule nth_the_index, simp) apply (rule the_index_bounded, simp) apply auto done lemma toEnum_alt_red[simp]: "toEnumAlt = (toEnum :: nat \<Rightarrow> 'a :: enumeration_both)" by (rule ext) (simp add: enum_alt_rel alt_from_ord_def toEnum_def toEnumAlt_def) lemma upto_enum_red: "[(n :: ('a :: enumeration_both)) .e. m] = map toEnum [fromEnum n ..< Suc (fromEnum m)]" unfolding upto_enum_def by simp instantiation nat :: enumeration_alt begin definition enum_alt_nat: "enum_alt \<equiv> Some" instance by (intro_classes; simp add: enum_alt_nat UNIV_option_conv) end lemma toEnumAlt_nat[simp]: "toEnumAlt = id" by (rule ext) (simp add: toEnumAlt_def enum_alt_nat) lemma fromEnumAlt_nat[simp]: "fromEnumAlt = id" by (rule ext) (simp add: fromEnumAlt_def enum_alt_nat) lemma upto_enum_nat[simp]: "[n .e. m] = [n ..< Suc m]" by (subst upto_enum_def) simp definition zipE1 :: "'a :: enum_alt \<Rightarrow> 'b list \<Rightarrow> ('a \<times> 'b) list" where "zipE1 x L \<equiv> zip (map toEnumAlt [fromEnumAlt x ..< fromEnumAlt x + length L]) L" definition zipE2 :: "'a :: enum_alt \<Rightarrow> 'a \<Rightarrow> 'b list \<Rightarrow> ('a \<times> 'b) list" where "zipE2 x xn L \<equiv> zip (map (\<lambda>n. toEnumAlt (fromEnumAlt x + (fromEnumAlt xn - fromEnumAlt x) * n)) [0 ..< length L]) L" definition zipE3 :: "'a list \<Rightarrow> 'b :: enum_alt \<Rightarrow> ('a \<times> 'b) list" where "zipE3 L x \<equiv> zip L (map toEnumAlt [fromEnumAlt x ..< fromEnumAlt x + length L])" definition zipE4 :: "'a list \<Rightarrow> 'b :: enum_alt \<Rightarrow> 'b \<Rightarrow> ('a \<times> 'b) list" where "zipE4 L x xn \<equiv> zip L (map (\<lambda>n. toEnumAlt (fromEnumAlt x + (fromEnumAlt xn - fromEnumAlt x) * n)) [0 ..< length L])" lemma to_from_enum_alt[simp]: "toEnumAlt (fromEnumAlt x) = (x :: 'a :: enumeration_alt)" proof - have rl: "\<And>a b. a = Some b \<Longrightarrow> the a = b" by simp show ?thesis unfolding fromEnumAlt_def toEnumAlt_def by (rule rl, rule theI') (metis enum_alt_inj enum_alt_surj_2 not_None_eq) qed lemma upto_enum_triv [simp]: "[x .e. x] = [x]" unfolding upto_enum_def by simp lemma toEnum_eq_to_fromEnum_eq: fixes v :: "'a :: enum" shows "n \<le> fromEnum (maxBound :: 'a) \<Longrightarrow> (toEnum n = v) = (n = fromEnum v)" by auto end
(* Title: HOL/ex/Tarski.thy Author: Florian Kammüller, Cambridge University Computer Laboratory *) section \<open>The Full Theorem of Tarski\<close> theory Tarski imports Main "HOL-Library.FuncSet" begin text \<open> Minimal version of lattice theory plus the full theorem of Tarski: The fixedpoints of a complete lattice themselves form a complete lattice. Illustrates first-class theories, using the Sigma representation of structures. Tidied and converted to Isar by lcp. \<close> record 'a potype = pset :: "'a set" order :: "('a \<times> 'a) set" definition monotone :: "['a \<Rightarrow> 'a, 'a set, ('a \<times> 'a) set] \<Rightarrow> bool" where "monotone f A r \<longleftrightarrow> (\<forall>x\<in>A. \<forall>y\<in>A. (x, y) \<in> r \<longrightarrow> (f x, f y) \<in> r)" definition least :: "['a \<Rightarrow> bool, 'a potype] \<Rightarrow> 'a" where "least P po = (SOME x. x \<in> pset po \<and> P x \<and> (\<forall>y \<in> pset po. P y \<longrightarrow> (x, y) \<in> order po))" definition greatest :: "['a \<Rightarrow> bool, 'a potype] \<Rightarrow> 'a" where "greatest P po = (SOME x. x \<in> pset po \<and> P x \<and> (\<forall>y \<in> pset po. P y \<longrightarrow> (y, x) \<in> order po))" definition lub :: "['a set, 'a potype] \<Rightarrow> 'a" where "lub S po = least (\<lambda>x. \<forall>y\<in>S. (y, x) \<in> order po) po" definition glb :: "['a set, 'a potype] \<Rightarrow> 'a" where "glb S po = greatest (\<lambda>x. \<forall>y\<in>S. (x, y) \<in> order po) po" definition isLub :: "['a set, 'a potype, 'a] \<Rightarrow> bool" where "isLub S po = (\<lambda>L. L \<in> pset po \<and> (\<forall>y\<in>S. (y, L) \<in> order po) \<and> (\<forall>z\<in>pset po. (\<forall>y\<in>S. (y, z) \<in> order po) \<longrightarrow> (L, z) \<in> order po))" definition isGlb :: "['a set, 'a potype, 'a] \<Rightarrow> bool" where "isGlb S po = (\<lambda>G. (G \<in> pset po \<and> (\<forall>y\<in>S. (G, y) \<in> order po) \<and> (\<forall>z \<in> pset po. (\<forall>y\<in>S. (z, y) \<in> order po) \<longrightarrow> (z, G) \<in> order po)))" definition "fix" :: "['a \<Rightarrow> 'a, 'a set] \<Rightarrow> 'a set" where "fix f A = {x. x \<in> A \<and> f x = x}" definition interval :: "[('a \<times> 'a) set, 'a, 'a] \<Rightarrow> 'a set" where "interval r a b = {x. (a, x) \<in> r \<and> (x, b) \<in> r}" definition Bot :: "'a potype \<Rightarrow> 'a" where "Bot po = least (\<lambda>x. True) po" definition Top :: "'a potype \<Rightarrow> 'a" where "Top po = greatest (\<lambda>x. True) po" definition PartialOrder :: "'a potype set" where "PartialOrder = {P. refl_on (pset P) (order P) \<and> antisym (order P) \<and> trans (order P)}" definition CompleteLattice :: "'a potype set" where "CompleteLattice = {cl. cl \<in> PartialOrder \<and> (\<forall>S. S \<subseteq> pset cl \<longrightarrow> (\<exists>L. isLub S cl L)) \<and> (\<forall>S. S \<subseteq> pset cl \<longrightarrow> (\<exists>G. isGlb S cl G))}" definition CLF_set :: "('a potype \<times> ('a \<Rightarrow> 'a)) set" where "CLF_set = (SIGMA cl : CompleteLattice. {f. f \<in> pset cl \<rightarrow> pset cl \<and> monotone f (pset cl) (order cl)})" definition induced :: "['a set, ('a \<times> 'a) set] \<Rightarrow> ('a \<times> 'a) set" where "induced A r = {(a, b). a \<in> A \<and> b \<in> A \<and> (a, b) \<in> r}" definition sublattice :: "('a potype \<times> 'a set) set" where "sublattice = (SIGMA cl : CompleteLattice. {S. S \<subseteq> pset cl \<and> \<lparr>pset = S, order = induced S (order cl)\<rparr> \<in> CompleteLattice})" abbreviation sublat :: "['a set, 'a potype] \<Rightarrow> bool" ("_ <<= _" [51, 50] 50) where "S <<= cl \<equiv> S \<in> sublattice `` {cl}" definition dual :: "'a potype \<Rightarrow> 'a potype" where "dual po = \<lparr>pset = pset po, order = converse (order po)\<rparr>" locale S = fixes cl :: "'a potype" and A :: "'a set" and r :: "('a \<times> 'a) set" defines A_def: "A \<equiv> pset cl" and r_def: "r \<equiv> order cl" locale PO = S + assumes cl_po: "cl \<in> PartialOrder" locale CL = S + assumes cl_co: "cl \<in> CompleteLattice" sublocale CL < po?: PO unfolding A_def r_def using CompleteLattice_def PO.intro cl_co by fastforce locale CLF = S + fixes f :: "'a \<Rightarrow> 'a" and P :: "'a set" assumes f_cl: "(cl, f) \<in> CLF_set" defines P_def: "P \<equiv> fix f A" sublocale CLF < cl?: CL unfolding A_def r_def CL_def using CLF_set_def f_cl by blast locale Tarski = CLF + fixes Y :: "'a set" and intY1 :: "'a set" and v :: "'a" assumes Y_ss: "Y \<subseteq> P" defines intY1_def: "intY1 \<equiv> interval r (lub Y cl) (Top cl)" and v_def: "v \<equiv> glb {x. ((\<lambda>x \<in> intY1. f x) x, x) \<in> induced intY1 r \<and> x \<in> intY1} \<lparr>pset = intY1, order = induced intY1 r\<rparr>" subsection \<open>Partial Order\<close> context PO begin lemma dual: "PO (dual cl)" proof show "dual cl \<in> PartialOrder" using cl_po unfolding PartialOrder_def dual_def by auto qed lemma PO_imp_refl_on [simp]: "refl_on A r" using cl_po by (simp add: PartialOrder_def A_def r_def) lemma PO_imp_sym [simp]: "antisym r" using cl_po by (simp add: PartialOrder_def r_def) lemma PO_imp_trans [simp]: "trans r" using cl_po by (simp add: PartialOrder_def r_def) lemma reflE: "x \<in> A \<Longrightarrow> (x, x) \<in> r" using cl_po by (simp add: PartialOrder_def refl_on_def A_def r_def) lemma antisymE: "\<lbrakk>(a, b) \<in> r; (b, a) \<in> r\<rbrakk> \<Longrightarrow> a = b" using cl_po by (simp add: PartialOrder_def antisym_def r_def) lemma transE: "\<lbrakk>(a, b) \<in> r; (b, c) \<in> r\<rbrakk> \<Longrightarrow> (a, c) \<in> r" using cl_po by (simp add: PartialOrder_def r_def) (unfold trans_def, fast) lemma monotoneE: "\<lbrakk>monotone f A r; x \<in> A; y \<in> A; (x, y) \<in> r\<rbrakk> \<Longrightarrow> (f x, f y) \<in> r" by (simp add: monotone_def) lemma po_subset_po: assumes "S \<subseteq> A" shows "\<lparr>pset = S, order = induced S r\<rparr> \<in> PartialOrder" proof - have "refl_on S (induced S r)" using \<open>S \<subseteq> A\<close> by (auto simp: refl_on_def induced_def intro: reflE) moreover have "antisym (induced S r)" by (auto simp add: antisym_def induced_def intro: antisymE) moreover have "trans (induced S r)" by (auto simp add: trans_def induced_def intro: transE) ultimately show ?thesis by (simp add: PartialOrder_def) qed lemma indE: "\<lbrakk>(x, y) \<in> induced S r; S \<subseteq> A\<rbrakk> \<Longrightarrow> (x, y) \<in> r" by (simp add: induced_def) lemma indI: "\<lbrakk>(x, y) \<in> r; x \<in> S; y \<in> S\<rbrakk> \<Longrightarrow> (x, y) \<in> induced S r" by (simp add: induced_def) end lemma (in CL) CL_imp_ex_isLub: "S \<subseteq> A \<Longrightarrow> \<exists>L. isLub S cl L" using cl_co by (simp add: CompleteLattice_def A_def) declare (in CL) cl_co [simp] lemma isLub_lub: "(\<exists>L. isLub S cl L) \<longleftrightarrow> isLub S cl (lub S cl)" by (simp add: lub_def least_def isLub_def some_eq_ex [symmetric]) lemma isGlb_glb: "(\<exists>G. isGlb S cl G) \<longleftrightarrow> isGlb S cl (glb S cl)" by (simp add: glb_def greatest_def isGlb_def some_eq_ex [symmetric]) lemma isGlb_dual_isLub: "isGlb S cl = isLub S (dual cl)" by (simp add: isLub_def isGlb_def dual_def converse_unfold) lemma isLub_dual_isGlb: "isLub S cl = isGlb S (dual cl)" by (simp add: isLub_def isGlb_def dual_def converse_unfold) lemma (in PO) dualPO: "dual cl \<in> PartialOrder" using cl_po by (simp add: PartialOrder_def dual_def) lemma Rdual: assumes major: "\<And>S. S \<subseteq> A \<Longrightarrow> \<exists>L. isLub S po L" and "S \<subseteq> A" and "A = pset po" shows "\<exists>G. isGlb S po G" proof show "isGlb S po (lub {y \<in> A. \<forall>k\<in>S. (y, k) \<in> order po} po)" using major [of "{y. y \<in> A \<and> (\<forall>k \<in> S. (y, k) \<in> order po)}"] \<open>S \<subseteq> A\<close> \<open>A = pset po\<close> apply (simp add: isLub_lub isGlb_def) apply (auto simp add: isLub_def) done qed lemma lub_dual_glb: "lub S cl = glb S (dual cl)" by (simp add: lub_def glb_def least_def greatest_def dual_def converse_unfold) lemma glb_dual_lub: "glb S cl = lub S (dual cl)" by (simp add: lub_def glb_def least_def greatest_def dual_def converse_unfold) lemma CL_subset_PO: "CompleteLattice \<subseteq> PartialOrder" by (auto simp: PartialOrder_def CompleteLattice_def) lemmas CL_imp_PO = CL_subset_PO [THEN subsetD] context CL begin lemma CO_refl_on: "refl_on A r" by (rule PO_imp_refl_on) lemma CO_antisym: "antisym r" by (rule PO_imp_sym) lemma CO_trans: "trans r" by (rule PO_imp_trans) end lemma CompleteLatticeI: "\<lbrakk>po \<in> PartialOrder; \<forall>S. S \<subseteq> pset po \<longrightarrow> (\<exists>L. isLub S po L); \<forall>S. S \<subseteq> pset po \<longrightarrow> (\<exists>G. isGlb S po G)\<rbrakk> \<Longrightarrow> po \<in> CompleteLattice" unfolding CompleteLattice_def by blast lemma (in CL) CL_dualCL: "dual cl \<in> CompleteLattice" using cl_co apply (simp add: CompleteLattice_def dual_def) apply (simp add: dualPO flip: dual_def isLub_dual_isGlb isGlb_dual_isLub) done context PO begin lemma dualA_iff [simp]: "pset (dual cl) = pset cl" by (simp add: dual_def) lemma dualr_iff [simp]: "(x, y) \<in> (order (dual cl)) \<longleftrightarrow> (y, x) \<in> order cl" by (simp add: dual_def) lemma monotone_dual: "monotone f (pset cl) (order cl) \<Longrightarrow> monotone f (pset (dual cl)) (order(dual cl))" by (simp add: monotone_def) lemma interval_dual: "\<lbrakk>x \<in> A; y \<in> A\<rbrakk> \<Longrightarrow> interval r x y = interval (order(dual cl)) y x" unfolding interval_def dualr_iff by (auto simp flip: r_def) lemma interval_not_empty: "interval r a b \<noteq> {} \<Longrightarrow> (a, b) \<in> r" by (simp add: interval_def) (use transE in blast) lemma interval_imp_mem: "x \<in> interval r a b \<Longrightarrow> (a, x) \<in> r" by (simp add: interval_def) lemma left_in_interval: "\<lbrakk>a \<in> A; b \<in> A; interval r a b \<noteq> {}\<rbrakk> \<Longrightarrow> a \<in> interval r a b" using interval_def interval_not_empty reflE by fastforce lemma right_in_interval: "\<lbrakk>a \<in> A; b \<in> A; interval r a b \<noteq> {}\<rbrakk> \<Longrightarrow> b \<in> interval r a b" by (simp add: A_def PO.dual PO.left_in_interval PO_axioms interval_dual) end subsection \<open>sublattice\<close> lemma (in PO) sublattice_imp_CL: "S <<= cl \<Longrightarrow> \<lparr>pset = S, order = induced S r\<rparr> \<in> CompleteLattice" by (simp add: sublattice_def CompleteLattice_def r_def) lemma (in CL) sublatticeI: "\<lbrakk>S \<subseteq> A; \<lparr>pset = S, order = induced S r\<rparr> \<in> CompleteLattice\<rbrakk> \<Longrightarrow> S <<= cl" by (simp add: sublattice_def A_def r_def) lemma (in CL) dual: "CL (dual cl)" proof show "dual cl \<in> CompleteLattice" using cl_co by (simp add: CompleteLattice_def dualPO flip: isGlb_dual_isLub isLub_dual_isGlb) qed subsection \<open>lub\<close> context CL begin lemma lub_unique: "\<lbrakk>S \<subseteq> A; isLub S cl x; isLub S cl L\<rbrakk> \<Longrightarrow> x = L" by (rule antisymE) (auto simp add: isLub_def r_def) lemma lub_upper: assumes "S \<subseteq> A" "x \<in> S" shows "(x, lub S cl) \<in> r" proof - obtain L where "isLub S cl L" using CL_imp_ex_isLub \<open>S \<subseteq> A\<close> by auto then show ?thesis by (metis assms(2) isLub_def isLub_lub r_def) qed lemma lub_least: assumes "S \<subseteq> A" and L: "L \<in> A" "\<forall>x \<in> S. (x, L) \<in> r" shows "(lub S cl, L) \<in> r" proof - obtain L' where "isLub S cl L'" using CL_imp_ex_isLub \<open>S \<subseteq> A\<close> by auto then show ?thesis by (metis A_def L isLub_def isLub_lub r_def) qed lemma lub_in_lattice: assumes "S \<subseteq> A" shows "lub S cl \<in> A" proof - obtain L where "isLub S cl L" using CL_imp_ex_isLub \<open>S \<subseteq> A\<close> by auto then show ?thesis by (metis A_def isLub_def isLub_lub) qed lemma lubI: assumes A: "S \<subseteq> A" "L \<in> A" and r: "\<forall>x \<in> S. (x, L) \<in> r" and clo: "\<And>z. \<lbrakk>z \<in> A; (\<forall>y \<in> S. (y, z) \<in> r)\<rbrakk> \<Longrightarrow> (L, z) \<in> r" shows "L = lub S cl" proof - obtain L where "isLub S cl L" using CL_imp_ex_isLub assms(1) by auto then show ?thesis by (simp add: antisymE A clo lub_in_lattice lub_least lub_upper r) qed lemma lubIa: "\<lbrakk>S \<subseteq> A; isLub S cl L\<rbrakk> \<Longrightarrow> L = lub S cl" by (meson isLub_lub lub_unique) lemma isLub_in_lattice: "isLub S cl L \<Longrightarrow> L \<in> A" by (simp add: isLub_def A_def) lemma isLub_upper: "\<lbrakk>isLub S cl L; y \<in> S\<rbrakk> \<Longrightarrow> (y, L) \<in> r" by (simp add: isLub_def r_def) lemma isLub_least: "\<lbrakk>isLub S cl L; z \<in> A; \<forall>y \<in> S. (y, z) \<in> r\<rbrakk> \<Longrightarrow> (L, z) \<in> r" by (simp add: isLub_def A_def r_def) lemma isLubI: "\<lbrakk>L \<in> A; \<forall>y \<in> S. (y, L) \<in> r; (\<forall>z \<in> A. (\<forall>y \<in> S. (y, z)\<in>r) \<longrightarrow> (L, z) \<in> r)\<rbrakk> \<Longrightarrow> isLub S cl L" by (simp add: isLub_def A_def r_def) end subsection \<open>glb\<close> context CL begin lemma glb_in_lattice: "S \<subseteq> A \<Longrightarrow> glb S cl \<in> A" by (metis A_def CL.lub_in_lattice dualA_iff glb_dual_lub local.dual) lemma glb_lower: "\<lbrakk>S \<subseteq> A; x \<in> S\<rbrakk> \<Longrightarrow> (glb S cl, x) \<in> r" by (metis A_def CL.lub_upper dualA_iff dualr_iff glb_dual_lub local.dual r_def) end text \<open> Reduce the sublattice property by using substructural properties; abandoned see \<open>Tarski_4.ML\<close>. \<close> context CLF begin declare f_cl [simp] lemma f_in_funcset: "f \<in> A \<rightarrow> A" by (simp add: A_def) lemma monotone_f: "monotone f A r" by (simp add: A_def r_def) lemma CLF_dual: "(dual cl, f) \<in> CLF_set" proof - have "Tarski.monotone f A (order (dual cl))" by (metis (no_types) A_def PO.monotone_dual PO_axioms dualA_iff monotone_f r_def) then show ?thesis by (simp add: A_def CLF_set_def CL_dualCL) qed lemma dual: "CLF (dual cl) f" by (rule CLF.intro) (rule CLF_dual) end subsection \<open>fixed points\<close> lemma fix_subset: "fix f A \<subseteq> A" by (auto simp: fix_def) lemma fix_imp_eq: "x \<in> fix f A \<Longrightarrow> f x = x" by (simp add: fix_def) lemma fixf_subset: "\<lbrakk>A \<subseteq> B; x \<in> fix (\<lambda>y \<in> A. f y) A\<rbrakk> \<Longrightarrow> x \<in> fix f B" by (auto simp: fix_def) subsection \<open>lemmas for Tarski, lub\<close> context CLF begin lemma lubH_le_flubH: assumes "H = {x \<in> A. (x, f x) \<in> r}" shows "(lub H cl, f (lub H cl)) \<in> r" proof (intro lub_least ballI) show "H \<subseteq> A" using assms by auto show "f (lub H cl) \<in> A" using \<open>H \<subseteq> A\<close> f_in_funcset lub_in_lattice by auto show "(x, f (lub H cl)) \<in> r" if "x \<in> H" for x proof - have "(f x, f (lub H cl)) \<in> r" by (meson \<open>H \<subseteq> A\<close> in_mono lub_in_lattice lub_upper monotoneE monotone_f that) moreover have "(x, f x) \<in> r" using assms that by blast ultimately show ?thesis using po.transE by blast qed qed lemma lubH_is_fixp: assumes "H = {x \<in> A. (x, f x) \<in> r}" shows "lub H cl \<in> fix f A" proof - have "(f (lub H cl), lub H cl) \<in> r" proof - have "(lub H cl, f (lub H cl)) \<in> r" using assms lubH_le_flubH by blast then have "(f (lub H cl), f (f (lub H cl))) \<in> r" by (meson PO_imp_refl_on monotoneE monotone_f refl_on_domain) then have "f (lub H cl) \<in> H" by (metis (no_types, lifting) PO_imp_refl_on assms mem_Collect_eq refl_on_domain) then show ?thesis by (simp add: assms lub_upper) qed with assms show ?thesis by (simp add: fix_def antisymE lubH_le_flubH lub_in_lattice) qed lemma fixf_le_lubH: assumes "H = {x \<in> A. (x, f x) \<in> r}" "x \<in> fix f A" shows "(x, lub H cl) \<in> r" proof - have "x \<in> P \<Longrightarrow> x \<in> H" by (simp add: assms P_def fix_imp_eq [of _ f A] reflE fix_subset [of f A, THEN subsetD]) with assms show ?thesis by (metis (no_types, lifting) P_def lub_upper mem_Collect_eq subset_eq) qed subsection \<open>Tarski fixpoint theorem 1, first part\<close> lemma T_thm_1_lub: "lub P cl = lub {x \<in> A. (x, f x) \<in> r} cl" proof - have "lub {x \<in> A. (x, f x) \<in> r} cl = lub (fix f A) cl" proof (rule antisymE) show "(lub {x \<in> A. (x, f x) \<in> r} cl, lub (fix f A) cl) \<in> r" by (simp add: fix_subset lubH_is_fixp lub_upper) have "\<And>a. a \<in> fix f A \<Longrightarrow> a \<in> A" by (meson fix_subset subset_iff) then show "(lub (fix f A) cl, lub {x \<in> A. (x, f x) \<in> r} cl) \<in> r" by (simp add: fix_subset fixf_le_lubH lubH_is_fixp lub_least) qed then show ?thesis using P_def by auto qed lemma glbH_is_fixp: assumes "H = {x \<in> A. (f x, x) \<in> r}" shows "glb H cl \<in> P" \<comment> \<open>Tarski for glb\<close> proof - have "glb H cl \<in> fix f (pset (dual cl))" using assms CLF.lubH_is_fixp [OF dual] PO.dualr_iff PO_axioms by (fastforce simp add: A_def r_def glb_dual_lub) then show ?thesis by (simp add: A_def P_def) qed lemma T_thm_1_glb: "glb P cl = glb {x \<in> A. (f x, x) \<in> r} cl" unfolding glb_dual_lub P_def A_def r_def using CLF.T_thm_1_lub dualA_iff dualr_iff local.dual by force subsection \<open>interval\<close> lemma rel_imp_elem: "(x, y) \<in> r \<Longrightarrow> x \<in> A" using CO_refl_on by (auto simp: refl_on_def) lemma interval_subset: "\<lbrakk>a \<in> A; b \<in> A\<rbrakk> \<Longrightarrow> interval r a b \<subseteq> A" by (simp add: interval_def) (blast intro: rel_imp_elem) lemma intervalI: "\<lbrakk>(a, x) \<in> r; (x, b) \<in> r\<rbrakk> \<Longrightarrow> x \<in> interval r a b" by (simp add: interval_def) lemma interval_lemma1: "\<lbrakk>S \<subseteq> interval r a b; x \<in> S\<rbrakk> \<Longrightarrow> (a, x) \<in> r" unfolding interval_def by fast lemma interval_lemma2: "\<lbrakk>S \<subseteq> interval r a b; x \<in> S\<rbrakk> \<Longrightarrow> (x, b) \<in> r" unfolding interval_def by fast lemma a_less_lub: "\<lbrakk>S \<subseteq> A; S \<noteq> {}; \<forall>x \<in> S. (a,x) \<in> r; \<forall>y \<in> S. (y, L) \<in> r\<rbrakk> \<Longrightarrow> (a, L) \<in> r" by (blast intro: transE) lemma S_intv_cl: "\<lbrakk>a \<in> A; b \<in> A; S \<subseteq> interval r a b\<rbrakk> \<Longrightarrow> S \<subseteq> A" by (simp add: subset_trans [OF _ interval_subset]) lemma L_in_interval: assumes "b \<in> A" and S: "S \<subseteq> interval r a b" "isLub S cl L" "S \<noteq> {}" shows "L \<in> interval r a b" proof (rule intervalI) show "(a, L) \<in> r" by (meson PO_imp_trans all_not_in_conv S interval_lemma1 isLub_upper transD) show "(L, b) \<in> r" using \<open>b \<in> A\<close> assms interval_lemma2 isLub_least by auto qed lemma G_in_interval: assumes "b \<in> A" and S: "S \<subseteq> interval r a b" "isGlb S cl G" "S \<noteq> {}" shows "G \<in> interval r a b" proof - have "a \<in> A" using S(1) \<open>S \<noteq> {}\<close> interval_lemma1 rel_imp_elem by blast with assms show ?thesis by (metis (no_types) A_def CLF.L_in_interval dualA_iff interval_dual isGlb_dual_isLub local.dual) qed lemma intervalPO: "\<lbrakk>a \<in> A; b \<in> A; interval r a b \<noteq> {}\<rbrakk> \<Longrightarrow> \<lparr>pset = interval r a b, order = induced (interval r a b) r\<rparr> \<in> PartialOrder" by (rule po_subset_po) (simp add: interval_subset) lemma intv_CL_lub: assumes "a \<in> A" "b \<in> A" "interval r a b \<noteq> {}" and S: "S \<subseteq> interval r a b" shows "\<exists>L. isLub S \<lparr>pset = interval r a b, order = induced (interval r a b) r\<rparr> L" proof - obtain L where L: "isLub S cl L" by (meson CL_imp_ex_isLub S_intv_cl assms(1) assms(2) assms(4)) show ?thesis unfolding isLub_def potype.simps proof (intro exI impI conjI ballI) let ?L = "(if S = {} then a else L)" show Lin: "?L \<in> interval r a b" using L L_in_interval assms left_in_interval by auto show "(y, ?L) \<in> induced (interval r a b) r" if "y \<in> S" for y proof - have "S \<noteq> {}" using that by blast then show ?thesis using L Lin S indI isLub_upper that by auto qed show "(?L, z) \<in> induced (interval r a b) r" if "z \<in> interval r a b" and "\<forall>y\<in>S. (y, z) \<in> induced (interval r a b) r" for z using that L apply (simp add: isLub_def induced_def interval_imp_mem) by (metis (full_types) A_def Lin \<open>a \<in> A\<close> \<open>b \<in> A\<close> interval_subset r_def subset_eq) qed qed lemmas intv_CL_glb = intv_CL_lub [THEN Rdual] lemma interval_is_sublattice: "\<lbrakk>a \<in> A; b \<in> A; interval r a b \<noteq> {}\<rbrakk> \<Longrightarrow> interval r a b <<= cl" apply (rule sublatticeI) apply (simp add: interval_subset) by (simp add: CompleteLatticeI intervalPO intv_CL_glb intv_CL_lub) lemmas interv_is_compl_latt = interval_is_sublattice [THEN sublattice_imp_CL] subsection \<open>Top and Bottom\<close> lemma Top_dual_Bot: "Top cl = Bot (dual cl)" by (simp add: Top_def Bot_def least_def greatest_def) lemma Bot_dual_Top: "Bot cl = Top (dual cl)" by (simp add: Top_def Bot_def least_def greatest_def) lemma Bot_in_lattice: "Bot cl \<in> A" unfolding Bot_def least_def apply (rule_tac a = "glb A cl" in someI2) using glb_in_lattice glb_lower by (auto simp: A_def r_def) lemma Top_in_lattice: "Top cl \<in> A" using A_def CLF.Bot_in_lattice Top_dual_Bot local.dual by force lemma Top_prop: "x \<in> A \<Longrightarrow> (x, Top cl) \<in> r" unfolding Top_def greatest_def apply (rule_tac a = "lub A cl" in someI2) using lub_in_lattice lub_upper by (auto simp: A_def r_def) lemma Bot_prop: "x \<in> A \<Longrightarrow> (Bot cl, x) \<in> r" using A_def Bot_dual_Top CLF.Top_prop dualA_iff dualr_iff local.dual r_def by fastforce lemma Top_intv_not_empty: "x \<in> A \<Longrightarrow> interval r x (Top cl) \<noteq> {}" using Top_prop intervalI reflE by force lemma Bot_intv_not_empty: "x \<in> A \<Longrightarrow> interval r (Bot cl) x \<noteq> {}" using Bot_dual_Top Bot_prop intervalI reflE by fastforce text \<open>the set of fixed points form a partial order\<close> proposition fixf_po: "\<lparr>pset = P, order = induced P r\<rparr> \<in> PartialOrder" by (simp add: P_def fix_subset po_subset_po) end context Tarski begin lemma Y_subset_A: "Y \<subseteq> A" by (rule subset_trans [OF _ fix_subset]) (rule Y_ss [simplified P_def]) lemma lubY_in_A: "lub Y cl \<in> A" by (rule Y_subset_A [THEN lub_in_lattice]) lemma lubY_le_flubY: "(lub Y cl, f (lub Y cl)) \<in> r" proof (intro lub_least Y_subset_A ballI) show "f (lub Y cl) \<in> A" by (meson Tarski.monotone_def lubY_in_A monotone_f reflE rel_imp_elem) show "(x, f (lub Y cl)) \<in> r" if "x \<in> Y" for x proof have "\<And>A. Y \<subseteq> A \<Longrightarrow> x \<in> A" using that by blast moreover have "(x, lub Y cl) \<in> r" using that by (simp add: Y_subset_A lub_upper) ultimately show "(x, f (lub Y cl)) \<in> r" by (metis (no_types) Tarski.Y_ss Tarski_axioms Y_subset_A fix_imp_eq lubY_in_A monotoneE monotone_f) qed auto qed lemma intY1_subset: "intY1 \<subseteq> A" unfolding intY1_def using Top_in_lattice interval_subset lubY_in_A by auto lemmas intY1_elem = intY1_subset [THEN subsetD] lemma intY1_f_closed: assumes "x \<in> intY1" shows "f x \<in> intY1" proof (simp add: intY1_def interval_def, rule conjI) show "(lub Y cl, f x) \<in> r" using assms intY1_elem interval_imp_mem lubY_in_A unfolding intY1_def using lubY_le_flubY monotoneE monotone_f po.transE by blast then show "(f x, Top cl) \<in> r" by (meson PO_imp_refl_on Top_prop refl_onD2) qed lemma intY1_mono: "monotone (\<lambda> x \<in> intY1. f x) intY1 (induced intY1 r)" apply (auto simp add: monotone_def induced_def intY1_f_closed) apply (blast intro: intY1_elem monotone_f [THEN monotoneE]) done lemma intY1_is_cl: "\<lparr>pset = intY1, order = induced intY1 r\<rparr> \<in> CompleteLattice" unfolding intY1_def by (simp add: Top_in_lattice Top_intv_not_empty interv_is_compl_latt lubY_in_A) lemma v_in_P: "v \<in> P" proof - have "v \<in> fix (restrict f intY1) intY1" unfolding v_def apply (rule CLF.glbH_is_fixp [OF CLF.intro, unfolded CLF_set_def, of "\<lparr>pset = intY1, order = induced intY1 r\<rparr>", simplified]) using intY1_f_closed intY1_is_cl intY1_mono apply blast+ done then show ?thesis unfolding P_def by (meson fixf_subset intY1_subset) qed lemma z_in_interval: "\<lbrakk>z \<in> P; \<forall>y\<in>Y. (y, z) \<in> induced P r\<rbrakk> \<Longrightarrow> z \<in> intY1" unfolding intY1_def P_def by (meson Top_prop Y_subset_A fix_subset in_mono indE intervalI lub_least) lemma tarski_full_lemma: "\<exists>L. isLub Y \<lparr>pset = P, order = induced P r\<rparr> L" proof have "(y, v) \<in> induced P r" if "y \<in> Y" for y proof - have "(y, lub Y cl) \<in> r" by (simp add: Y_subset_A lub_upper that) moreover have "(lub Y cl, v) \<in> r" by (metis (no_types, lifting) CL.glb_in_lattice CL.intro intY1_def intY1_is_cl interval_imp_mem lub_dual_glb mem_Collect_eq select_convs(1) subsetI v_def) ultimately have "(y, v) \<in> r" using po.transE by blast then show ?thesis using Y_ss indI that v_in_P by auto qed moreover have "(v, z) \<in> induced P r" if "z \<in> P" "\<forall>y\<in>Y. (y, z) \<in> induced P r" for z proof (rule indI) have "((\<lambda>x \<in> intY1. f x) z, z) \<in> induced intY1 r" by (metis P_def fix_imp_eq in_mono indI intY1_subset reflE restrict_apply' that z_in_interval) then show "(v, z) \<in> r" by (metis (no_types, lifting) CL.glb_lower CL_def indE intY1_is_cl intY1_subset mem_Collect_eq select_convs(1,2) subsetI that v_def z_in_interval) qed (auto simp: that v_in_P) ultimately show "isLub Y \<lparr>pset = P, order = induced P r\<rparr> v" by (simp add: isLub_def v_in_P) qed end lemma CompleteLatticeI_simp: "\<lbrakk>po \<in> PartialOrder; \<And>S. S \<subseteq> A \<Longrightarrow> \<exists>L. isLub S po L; A = pset po\<rbrakk> \<Longrightarrow> po \<in> CompleteLattice" by (metis CompleteLatticeI Rdual) theorem (in CLF) Tarski_full: "\<lparr>pset = P, order = induced P r\<rparr> \<in> CompleteLattice" proof (intro CompleteLatticeI_simp allI impI) show "\<lparr>pset = P, order = induced P r\<rparr> \<in> PartialOrder" by (simp add: fixf_po) show "\<And>S. S \<subseteq> P \<Longrightarrow> \<exists>L. isLub S \<lparr>pset = P, order = induced P r\<rparr> L" unfolding P_def A_def r_def proof (rule Tarski.tarski_full_lemma [OF Tarski.intro [OF _ Tarski_axioms.intro]]) show "CLF cl f" .. qed qed auto end
#thermo module, meta/package to reference all other subpackages module Thermo include("UniversalConstants.jl") #provides constants include("Compounds.jl") #provides an structure to store and retrieve compound properties end
subset.biomass = function(Q, R, nodes, type="mature.only", fraction11 = 0.2) { out = NULL names(Q) = nodes names(R) = nodes Q[!is.finite(Q)] = 0 R[!is.finite(R)] = 0 if (type =="historic") { tot = fraction11 * (Q["imm.11"] + Q["imm.sm.11"] + Q["CC3to4.11"] + Q["CC5.11"]) + (Q["imm.12"] + Q["imm.sm.12"] + Q["CC3to4.12"] + Q["CC5.12"]) + ( Q["CC3to4.13"] + Q["CC5.13"]) err = sqrt( fraction11^2 * (R["imm.11"]^2 + R["imm.sm.11"]^2 + R["CC3to4.11"]^2 + R["CC5.11"]^2) + R["imm.12"]^2 + R["imm.sm.12"]^2 + R["CC3to4.12"]^2 + R["CC5.12"]^2 + R["CC3to4.13"]^2 + R["CC5.13"]^2 ) } else if (type =="mature.only") { tot = fraction11 * ( Q["CC3to4.11"] + Q["CC5.11"]) + ( Q["CC3to4.12"] + Q["CC5.12"]) + ( Q["CC3to4.13"] + Q["CC5.13"]) err = sqrt( fraction11^2 * ( R["CC3to4.11"]^2 + R["CC5.11"]^2) + R["CC3to4.12"]^2 + R["CC5.12"]^2 + R["CC3to4.13"]^2 + R["CC5.13"]^2 ) } names(tot) = NULL return( c(tot,err) ) }
[STATEMENT] lemma dynmethd_declclass: "\<lbrakk>dynmethd G statC dynC sig = Some m; wf_prog G; is_class G statC \<rbrakk> \<Longrightarrow> methd G (declclass m) sig = Some m" [PROOF STATE] proof (prove) goal (1 subgoal): 1. \<lbrakk>dynmethd G statC dynC sig = Some m; wf_prog G; is_class G statC\<rbrakk> \<Longrightarrow> methd G (declclass m) sig = Some m [PROOF STEP] by (auto dest: dynmethd_declC)
""" This script runs a GRU (Gated Recurrent Unit) neural network and either trains a new model from scratch, or loads a previously trained model, then evaluates that model on the testing set. Usage: - Run this script with `python3 gru.py` to evaluate the trained model on the testing set. - To retrain the model, run this script with the --train_from_scratch command line argument, and optionally specify the following hyperparameters: --use_og_data_only: If set, only trains on the original data without any augmented data. --use_2_classes: If set, uses 2 classes rather than 3 (collapses class 0 and 1 into one class) --n_epochs: Integer representing how many epochs to train the model for --batch_size: Integer representing how large each batch should be --learning_rate: Float representing the desired learning rate --hidden_size: Integer representing the desired dimensions of the hidden layer(s) of the NN --num_layers: Integer representing the number of layers For further explanations of these flags, consult the README or `utils.py`. """ import numpy as np import torch import torch.nn as nn import torch.optim as optim from sklearn.model_selection import train_test_split from tqdm import trange from data_loader import load_data from utils import train_model, evaluate_model, load_data_tensors, parse_command_line_args SAVE_PATH = 'models/gru.pt' class GRU(nn.Module): """ Implementation of a Gated Recurrent Unit neural network. """ def __init__(self, vocab_size, hidden_size, output_size, num_layers): super().__init__() self.num_layers = num_layers self.hidden_size = hidden_size self.emb = nn.Embedding(vocab_size, hidden_size) self.rnn = nn.GRU(hidden_size, hidden_size, num_layers=num_layers, batch_first=False) self.lin = nn.Linear(hidden_size, output_size) self.sigmoid = nn.Sigmoid() def forward(self, input_seq): embeds = self.emb(input_seq) (out, hn_last) = self.rnn(embeds) out = out[0, :, :] scores = self.lin(out) return self.sigmoid(scores) if __name__ == "__main__": args = parse_command_line_args() # If there's an available GPU, let's use it device = torch.device('cuda' if torch.cuda.is_available() else 'cpu') data_train, labels_train, tok_to_ix = load_data_tensors( args.use_og_data_only) if args.retrain: """ Initialize model with the specified hyperparameters and architecture """ hidden_size = args.hidden_size num_layers = 1 if args.num_layers < 0 else args.num_layers vocab_size = len(tok_to_ix) output_size = len(np.unique(labels_train)) model = GRU( hidden_size=hidden_size, num_layers=num_layers, vocab_size=vocab_size, output_size=output_size) model = model.to(device) loss_func = nn.CrossEntropyLoss() optimizer = optim.SGD(model.parameters(), lr=args.learning_rate) model = train_model( model=model, loss_func=loss_func, optimizer=optimizer, data_train=data_train, labels_train=labels_train, n_epochs=args.n_epochs, batch_size=args.batch_size, save_path=SAVE_PATH, device=device) else: """ File was not run with --train_from_scratch, so simply load the model from its saved path """ model = torch.load(SAVE_PATH) """ Whether we're training or just loading the pretrained model, we finish by evaluating the model on the testing set. """ evaluate_model( model=model, tok_to_ix=tok_to_ix, use_og_data_only=args.use_og_data_only, bs=args.batch_size, device=device)
DJ Phantasy is one of the true skool grrrrrrrreats from back in the day, yet how could this series of releases celebrating his 30 Years in Da Biz be anything but phormulaic phrozen-phuturism? "First is a track called Hypocrite with Kanine, which is a techy banger. I have something with grime don ScruFizzer called Bad2DaBone and Sound Killa with my boy Shabba D ... There is a third part planned as well, plus some... stuff I am working on with my bruva Macky Gee. And on top of that SaSaSaS have some releases planned too." Not his fault, though, not at all: it's the surrounding culture that's changed. A question of scenius depletion, not genius decay. Look, he deserves to make a living in perpetuity for having done those tunes. Spot a broken link? - Tell us via the Comments function. Is good.
\documentclass{article} \usepackage{fullpage} \usepackage{amsmath,amsthm,amssymb} \usepackage{url} \usepackage{cite} \usepackage{xcolor,colortbl} \usepackage{graphicx} \usepackage{tikz} \usetikzlibrary{chains,3d} \newcommand{\Exp}{\text{exp}} \begin{document} \hfill \textbf{Vector embeddings of time series data with linear properties} \hfill Ben Black \section{Vector embeddings} Dense data, such as images, video, and audio, is extremely high dimensional in its raw form. For many important tasks, especially information retrieval, it is extremely useful to be able to embed the important parts of the image in a vector of manageable dimension (typically on the order of 100 dimensions). Once the vectors are computed, similar images can be grouped by the similarity of their embeddings. This paper describes a new fast embedding algorithm for audio, but it can be easily generalized to other time series data. \section{Generative vector embeddings} The idea of an embedding is taken from generative models. Take some data $A_1,A_2,A_3,...$, you want an embedding function $f$ and a decoding function $g$ such that $g(f(A_i)) \sim A_i$, where $\sim$ is some approximation relation, and the output of $f$ is smaller than the size of $A$. Then $f(A)$ is the embedding of $A$. In less mathematical terms, $f$ can be seen as a lossy compression function which compresses the data (say, a 600x800 photograph), to an embedding, say a 50 dimensional floating point vector. $g$ is the decompression function which attempts to generate an image based only on the vector. In the deep learning paradigm, it is easy to see how to construct such an $f$ and $g$, given a $\sim$ and a dataset. It is simply to turn the approximation relation to a cost function, make $f$ and $g$ some neural network architecture, and minimize the cost of $g(f(A_i)) \sim A_i$. The biggest problem with this model is coming up with an appropriate approximation relation $\sim$. Humans can easily tell which images are similar and different, yet when pressed, it is clear that this similarity cannot be easily described in terms of color channel magnitudes. For example, two cars, one red and one blue will have very different color channels, but humans would say that the images are quite similar compared to an image of a dog. The deep learning community's solution is adversarial networks. %In an adversarial network, after $g$ has output an image, Intuitively, a generative network can be seen as a counterfitter artist, which cheaply produces images based on incomplete information about the art. The adversarial network is the authority which tries to tell counterfitted art from the real deal. In the end, we hope that the counterfitter gets better and better at producing realistic images in order to fool the authority, while the authority gets better and better and forces the counterfitter to improve even further. More precisely, an adversarial network is a function $c$ which tries to guess whether the image $\bar{A}$ was generated by $g(f(A))$, or if it is in fact the original $A$. This adversarial network is trained separately from the generative network. Thus, the adversarial network $c$ is attempts to optimize these two probabilities $$P[c(g(f(A_i))) = 0]$$ $$P[c(A_i) = 1]$$ It is very important that $f$ and $g$ are fixed when $c$ is training, or this would be trivially solvable. While the generative network ($f$ and $g$) is trained to optimize the value of $$P[c(g(f(A_i))) = 1]$$ While holding $c$ fixed. The adversarial and generative networks are then trained in an alternating sequence, so both the networks can learn from the success of the other. When training is finished, remember the embedding is simply calculated by running $f(A)$, and so it can apply to data outside the original training dataset, although it is not guaranteed to generate a good embedding. %\subsection{Problems} %Using generative vector embeddings which are constructed as described above leads to two major issues which prevent them from being used for many important purposes, including information retrieval. One is that the vectors are not guaranteed to have any substantive algebraic qualities. The other is that these models are not equipped to handle large inputs and outputs. \subsubsection{Similarity of generative embeddings} In the classical generative embeddings described above, the embedding vector is only consumed by a single function, the decoding function $g$. Ideally, though, we want to use this vector for purposes other than applying $g$. In this paper, we will focus on using the vector for information retrieval. One important function for information retrieval is the similarity relation, which takes in two inputs and outputs a number which represents how similar the inputs are to each other. Unfortunately, with the generative networks, there is no guarantee that classical vector similarity calculations, like squared distance or cosine distance accurately represent distance of vectors. This is because even 3 layer neural networks are universal approximators, meaning that if the network is large enough, the network can approximate any function to any degree, even highly discontinuous ones. In reality, of course, neural networks are finite and the weights are trained in a very particular way, so they do have some good properties, but we cannot a-priori say what they are. Of course, many studies have tried to fill in this gap in theory with actual results, and many of them look somewhat promising. The most promising one is the "traveling along a dimension property" (CITE case of this). However, similarity relations is not one of those promising results. This is one reason why we need a new general embedding algorithm for dense data. \subsubsection{Large Data} Generative networks as described above have had significant success with low resolution images and audio, and more limited success with high resolution images. However, we sometimes want to get vectors of much larger data sources, for example, video. Generating more than a handful of frames of even a video would be an astronomically difficult task for a neural network, and would require enormous embeddings, and slow training. This raises the question of why we are trying to generate things in the first place if all we want is a vector. One sort of hacky solution is to average many vectors, for example make a video vector by averaging many image vectors, but averages and other cumulative methods are not likely to be good representations because of the problem with algebraic qualities mentioned above. %Deep neural networks are functions with fixed input and output. Currently, the only well understood way of handling inputs with variable input is with recurrent networks, networks which the output of one iteration feeds into the next. The typical way of handling embeddings with these networks is to feed in the entire dataset one section at a time, and then have the network try to generate the whole dataset back, one step at a time. Unfortunately, with current state of the art (deep LSTMs), this method does not give good results for large numbers of steps (over 50 time steps). At hand here is an even \section{Sparse embeddings for word2vec} One of the major advances in vector embeddings was Thomas Miktov's word2vec algorithm. This algorithm is based on the same ideas as the generative networks described above, but specialized for sequences of sparse data such as words. There are two ideas in word2vec that are critical to this work. First is to compare local context to global content, instead of generating data. Second is to rephrase the prediction problem into terms of individual vectors, instead of dense matrices. First, lets review the basic ideas behind word2vec. The key idea behind word2vec is that the semantic meaning of a word can be described by the frequency of the words in its context. The skip-gram model leverages that by using one word in a context to try to predict other words in its context. In probabilistic terms, this means trying to estimate $$P[w_1 | w_2]$$ Within some specific window. This model is very slow in its original form because of the softmax classification at the end. Recall that the softmax is computed by the following formula $$ \frac{\Exp(W_i x)}{\sum_j \Exp(W_j x)}$$ In terms of the skip-gram model, $x$ would be the word vector embedding, and $W$ would be the output layer. Unfortunately, the output layer of the skip gram model scales in terms of the vocabulary size, so in order to calculate the denominator of the fraction, the algorithm needs $$(\text{vocab size}) * (\text{embedding size})$$ Word2vec eventually solved this problem with negative sampling. The idea is to approximate the denominator by sampling a subset of the output weight vectors, instead of the entire thing. $$ \frac{\Exp(W_i x)}{\sum_{j \in S} \Exp(W_j x)}$$ $S$ is then chosen randomly from the set of words, but not uniformly: more frequent words are chosen more often than less frequent words. These manipulations of the generative equation give rise to a completely new interpretation of what is going on: Positive sample: words $i$ and $j$ are found in the same context. Then compute $W_i O_j$. Negative sample: word $k$ is sampled randomly from the input. Compute $W_i O_k$. Then the negative sample should have a low value as to compared to the positive sample. \section{Dense discriminative embeddings} There has been some past work on discriminative embeddings, rather than predictive embeddings. My work will follow in their footsteps. The most successful version of this is "Look, Learn, Listen" or L$^3$. These models are very powerful in the way that they say what things go where. Unfortunately, attempts to use intra-model learning through spacial reconstructions, etc have fallen far short of supervised learning techniques. \cite{DBLP:journals/corr/NorooziF16} Our goal is to have a better embedding system than them. It is useful to see how these intra-model embeddings work. All of them try to extract high level information by using high level patterns in images. Some try to extract feature position information such as different parts of an animal by artificially creating and solving a jigsaw puzzle. Others look at frames in a video and try to extract position using match mismatch tuples. Others use gray scale to try to predict color. All of them can be termed as missing information problems. Unfortunately, the information these networks extract to solve the missing information problem never seem to be as useful a the information that supervised networks learn to find labels. Meanwhile, other techniques, such as unsupervised learning which assumes no specific structure in the input, such as (CITE: ADVERSARIAL FEATURE LEARNING), do even worse. Instead of hand-engineering a missing information problem, we will train the network to learn the best best possible missing information problem to solve using reinforcement learning, while solving that problem. Another way of describing this problem is scene exploration, with the goal of finding "surprising elements" in the scene. %But all them them try to extract high level featuring using high level patterns. %Our technique is fundamentally different in all of these is that it extracts much lower level features first, and then builds upon them to form high level features. This way, nwe hope that it captures many different aspects of the image relatively well, instead of just capturing enough to solve the contrived high level problem. \section{Algorithm} The algorithm is a neural network trying to approximate a match/mismatch problem. The match case is two local sound vector, the mismatch case is two vectors sampled uniformly from the entire dataset. \begin{tikzpicture}[scale=0.6,mainnode/.style={font=\sffamily\footnotesize\bfseries}] \draw [->] (0,0) -- node[pos=-0.2] {time} (5,0); \foreach \tick in {0,1,2,3,4,5,6,7,8,9} \draw [-] (0.5*\tick,0) -- node[pos=-1.5] {\tick} (0.5*\tick,0.3); \draw [-] (1.5,-1) -- (1.5,-1.5); \draw [-] (3.5,-1) -- (3.5,-1.5); \draw [-] (1.5,-1.5) -- node[anchor=north] {Window} (3.5,-1.5); \end{tikzpicture} The mismatch case has the pair of data drawn uniformly from the entire dataset. Song ID vector \section{Results} To test the qualities of these vectors, they were \cite{DBLP:journals/corr/abs-1712-06651} \bibliography{project_proposal}{} \bibliographystyle{plain} \end{document}
[STATEMENT] lemma rt_fresh_asE [elim]: assumes "rt1 \<approx>\<^bsub>dip\<^esub> rt2" and "\<lbrakk> rt1 \<sqsubseteq>\<^bsub>dip\<^esub> rt2; rt2 \<sqsubseteq>\<^bsub>dip\<^esub> rt1 \<rbrakk> \<Longrightarrow> P rt1 rt2 dip" shows "P rt1 rt2 dip" [PROOF STATE] proof (prove) goal (1 subgoal): 1. P rt1 rt2 dip [PROOF STEP] using assms [PROOF STATE] proof (prove) using this: rt1 \<approx>\<^bsub>dip\<^esub> rt2 \<lbrakk>rt1 \<sqsubseteq>\<^bsub>dip\<^esub> rt2; rt2 \<sqsubseteq>\<^bsub>dip\<^esub> rt1\<rbrakk> \<Longrightarrow> P rt1 rt2 dip goal (1 subgoal): 1. P rt1 rt2 dip [PROOF STEP] unfolding rt_fresh_as_def [PROOF STATE] proof (prove) using this: rt1 \<sqsubseteq>\<^bsub>dip\<^esub> rt2 \<and> rt2 \<sqsubseteq>\<^bsub>dip\<^esub> rt1 \<lbrakk>rt1 \<sqsubseteq>\<^bsub>dip\<^esub> rt2; rt2 \<sqsubseteq>\<^bsub>dip\<^esub> rt1\<rbrakk> \<Longrightarrow> P rt1 rt2 dip goal (1 subgoal): 1. P rt1 rt2 dip [PROOF STEP] by simp
\documentclass{warpdoc} \newlength\lengthfigure % declare a figure width unit \setlength\lengthfigure{0.158\textwidth} % make the figure width unit scale with the textwidth \usepackage{psfrag} % use it to substitute a string in a eps figure \usepackage{subfigure} \usepackage{rotating} \usepackage{pstricks} \usepackage[innercaption]{sidecap} % the cute space-saving side captions \usepackage{scalefnt} \usepackage{amsmath} \usepackage{bm} %%%%%%%%%%%%%=--NEW COMMANDS BEGINS--=%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% \newcommand{\alb}{\vspace{0.2cm}\\} % array line break \newcommand{\mfd}{\displaystyle} \newcommand{\nd}{{n_{\rm d}}} \newcommand{\M}{{\bf M}} \newcommand{\N}{{\bf N}} \newcommand{\B}{{\bf B}} \newcommand{\BI}{\wbar{{\bf B}}} \newcommand{\A}{{\bf A}} \newcommand{\C}{{\bf C}} \newcommand{\T}{{\bf T}} \newcommand{\Dstar}{D^{\!\star}} \newcommand{\Fstar}{F^{\!\star}} \newcommand{\Ustar}{U^{\!\star}} \newcommand{\Sstar}{S^{\!\star}} \newcommand{\Kstar}{K^{\!\star}} \newcommand{\Ystar}{Y^{\!\star}} \newcommand{\co}{,~~} \newcommand{\band}{{\rm Band}} \renewcommand{\fontsizetable}{\footnotesize\scalefont{1.0}} \renewcommand{\fontsizefigure}{\footnotesize} \renewcommand{\vec}[1]{\bm{#1}} \setcounter{tocdepth}{3} \let\citen\cite %%%%%%%%%%%%%=--NEW COMMANDS BEGINS--=%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% \setcounter{tocdepth}{3} %%%%%%%%%%%%%=--NEW COMMANDS ENDS--=%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% \author{ Bernard Parent } \email{ [email protected] } \department{ Dept. of Aerospace Engineering } \institution{ Pusan National University } \title{ Electromagnetic Fields Relaxation Schemes } \date{ March 2018 } %\setlength\nomenclaturelabelwidth{0.13\hsize} % optional, default is 0.03\hsize %\setlength\nomenclaturecolumnsep{0.09\hsize} % optional, default is 0.06\hsize \nomenclature{ \begin{nomenclaturelist}{Roman symbols} \item[$a$] speed of sound \end{nomenclaturelist} } \abstract{ abstract } \begin{document} \pagestyle{headings} \pagenumbering{arabic} \setcounter{page}{1} %% \maketitle \makewarpdoctitle % \makeabstract \tableofcontents % \makenomenclature %% \listoftables %% \listoffigures \sloppy \nocite{misc:1955:douglas} \section{Multigrid} \subsection{Multigrid 2D Constant Coefficients} First, let's derive the delta form on a mesh two times coarser for a 2D system with constant coefficients. Consider the delta form of a scalar diffusion equation with constant conductivity in 2D: % \begin{equation} \sigma(\Delta^n u_{i+1,j} -4 \Delta^n u_{i,j} +\Delta^n u_{i-1,j} +\Delta^n u_{i,j+1} +\Delta^n u_{i,j-1}) = -r_{i,j}^n \label{eqn:mg2Dcc1} \end{equation} % Now consider the same equation evaluated at node $i+1$, $i-1$, $j+1$, $j-1$: % \begin{equation} \sigma(\Delta^n u_{i+2,j} -4 \Delta^n u_{i+1,j} +\Delta^n u_{i,j} +\Delta^n u_{i+1,j+1} +\Delta^n u_{i+1,j-1}) = -r_{i+1,j}^n \label{eqn:mg2Dcc2} \end{equation} % % \begin{equation} \sigma(\Delta^n u_{i,j} -4 \Delta^n u_{i-1,j} +\Delta^n u_{i-2,j} +\Delta^n u_{i-1,j+1} +\Delta^n u_{i-1,j-1}) = -r_{i-1,j}^n \label{eqn:mg2Dcc3} \end{equation} % % \begin{equation} \sigma(\Delta^n u_{i+1,j+1} -4 \Delta^n u_{i,j+1} +\Delta^n u_{i-1,j+1} +\Delta^n u_{i,j+2} +\Delta^n u_{i,j}) = -r_{i,j+1}^n \label{eqn:mg2Dcc4} \end{equation} % % \begin{equation} \sigma(\Delta^n u_{i+1,j-1} -4 \Delta^n u_{i,j-1} +\Delta^n u_{i-1,j-1} +\Delta^n u_{i,j} +\Delta^n u_{i,j-2}) = -r_{i,j-1}^n \label{eqn:mg2Dcc5} \end{equation} % Multiply Eq.\ (\ref{eqn:mg2Dcc1}) by 4 and add to it the latter four equations: % \begin{align} \sigma(& - 12 \Delta^n u_{i,j} + \Delta^n u_{i+2,j} + \Delta^n u_{i-2,j} + \Delta^n u_{i,j+2} + \Delta^n u_{i,j-2} + 2 \Delta^n u_{i+1,j+1} + 2 \Delta^n u_{i-1,j+1}\nonumber\\ &+ 2 \Delta^n u_{i+1,j-1} + 2 \Delta^n u_{i-1,j-1} ) = -4 r_{i,j}^n -r_{i+1,j}^n -r_{i-1,j}^n -r_{i,j+1}^n -r_{i,j-1}^n \label{eqn:mg2Dcc6} \end{align} % Then, can say that: % \begin{equation} \Delta^n u_{i+1,j+1} + \Delta^n u_{i-1,j+1}\\ + \Delta^n u_{i+1,j-1} + \Delta^n u_{i-1,j-1} \approx 4 \Delta^n u_{i,j} \end{equation} % Thus: % \begin{align} \sigma( &- 4 \Delta^n u_{i,j} + \Delta^n u_{i+2,j} + \Delta^n u_{i-2,j} + \Delta^n u_{i,j+2} + \Delta^n u_{i,j-2} )\nonumber\\ &= -4 r_{i,j}^n -r_{i+1,j}^n -r_{i-1,j}^n -r_{i,j+1}^n -r_{i,j-1}^n \label{eqn:mg2Dcc7} \end{align} % \subsection{Multigrid 1D} Here we will derive the delta form on a mesh 2 times coarser for a 1D system with non constant coefficients. % \begin{equation} \sigma_{i+1/2} \Delta^n u_{i+1} - (\sigma_{i+1/2}+\sigma_{i-1/2}) \Delta^n u_{i} +\sigma_{i-1/2}\Delta^n u_{i-1} = -r_{i}^n \label{eqn:mg1D1} \end{equation} % Now consider the same equation evaluated at node $i+1$, $i-1$: % \begin{equation} \sigma_{i+3/2} \Delta^n u_{i+2} - (\sigma_{i+3/2}+\sigma_{i+1/2}) \Delta^n u_{i+1} +\sigma_{i+1/2}\Delta^n u_{i} = -r_{i+1}^n \label{eqn:mg1D2} \end{equation} % % \begin{equation} \sigma_{i-1/2} \Delta^n u_{i} - (\sigma_{i-1/2}+\sigma_{i-3/2}) \Delta^n u_{i-1} +\sigma_{i-3/2}\Delta^n u_{i-2} = -r_{i-1}^n \label{eqn:mg1D3} \end{equation} % Isolate $\Delta^n u_{i+1}$ in Eq.\ (\ref{eqn:mg1D2}) and isolate $\Delta^n u_{i-1}$ in Eq.\ (\ref{eqn:mg1D3}): % \begin{equation} \Delta^n u_{i+1} = \frac{r_{i+1}^n}{\sigma_{i+3/2}+\sigma_{i+1/2}} + \frac{\sigma_{i+3/2}}{\sigma_{i+3/2}+\sigma_{i+1/2}} \Delta^n u_{i+2} + \frac{\sigma_{i+1/2}}{\sigma_{i+3/2}+\sigma_{i+1/2}}\Delta^n u_{i} \label{eqn:mg1D4} \end{equation} % % \begin{equation} \Delta^n u_{i-1} = \frac{r_{i-1}^n}{\sigma_{i-1/2}+\sigma_{i-3/2}} + \frac{\sigma_{i-1/2}}{\sigma_{i-1/2}+\sigma_{i-3/2}} \Delta^n u_{i} + \frac{\sigma_{i-3/2}}{\sigma_{i-1/2}+\sigma_{i-3/2}}\Delta^n u_{i-2} \label{eqn:mg1D5} \end{equation} % Substitute the latter 2 equations in Eq.\ (\ref{eqn:mg1D1}): % \begin{align} \sigma_{i+1/2} \left( \frac{r_{i+1}^n}{\sigma_{i+3/2}+\sigma_{i+1/2}} + \frac{\sigma_{i+3/2}}{\sigma_{i+3/2}+\sigma_{i+1/2}} \Delta^n u_{i+2} + \frac{\sigma_{i+1/2}}{\sigma_{i+3/2}+\sigma_{i+1/2}}\Delta^n u_{i} \right)\nonumber\\ +\sigma_{i-1/2}\left( \frac{r_{i-1}^n}{\sigma_{i-1/2}+\sigma_{i-3/2}} + \frac{\sigma_{i-1/2}}{\sigma_{i-1/2}+\sigma_{i-3/2}} \Delta^n u_{i} + \frac{\sigma_{i-3/2}}{\sigma_{i-1/2}+\sigma_{i-3/2}}\Delta^n u_{i-2}\right)\nonumber\\ - (\sigma_{i+1/2}+\sigma_{i-1/2}) \Delta^n u_{i} = -r_{i}^n \label{eqn:mg1D6} \end{align} % Simplify: % \begin{align} + \frac{\sigma_{i+1/2} \sigma_{i+3/2}}{\sigma_{i+3/2}+\sigma_{i+1/2}} \Delta^n u_{i+2} + \frac{\sigma_{i+1/2}^2}{\sigma_{i+3/2}+\sigma_{i+1/2}}\Delta^n u_{i} \nonumber\\ + \frac{\sigma_{i-1/2}^2}{\sigma_{i-1/2}+\sigma_{i-3/2}} \Delta^n u_{i} + \frac{\sigma_{i-1/2}\sigma_{i-3/2}}{\sigma_{i-1/2}+\sigma_{i-3/2}}\Delta^n u_{i-2}\nonumber\\ - (\sigma_{i+1/2}+\sigma_{i-1/2}) \Delta^n u_{i} = -r_{i}^n - \frac{\sigma_{i+1/2} r_{i+1}^n}{\sigma_{i+3/2}+\sigma_{i+1/2}} - \frac{\sigma_{i-1/2} r_{i-1}^n}{\sigma_{i-1/2}+\sigma_{i-3/2}} \label{eqn:mg1D6} \end{align} % But note that: % \begin{align} \frac{\sigma_{i+1/2}^2}{\sigma_{i+3/2}+\sigma_{i+1/2}} - \sigma_{i+1/2} &= \left(\frac{\sigma_{i+1/2}}{\sigma_{i+3/2}+\sigma_{i+1/2}} -1 \right) \sigma_{i+1/2} \nonumber\\ &= \left(\frac{\sigma_{i+1/2}}{\sigma_{i+3/2}+\sigma_{i+1/2}} -\frac{{\sigma_{i+3/2}+\sigma_{i+1/2}}}{{\sigma_{i+3/2}+\sigma_{i+1/2}}} \right) \sigma_{i+1/2} \nonumber\\ &= \left(\frac{-\sigma_{i+3/2}}{\sigma_{i+3/2}+\sigma_{i+1/2}} \right) \sigma_{i+1/2} \nonumber\\ &= \frac{-\sigma_{i+1/2}\sigma_{i+3/2}}{\sigma_{i+3/2}+\sigma_{i+1/2}} \end{align} % and that: % \begin{align} \frac{\sigma_{i-1/2}^2}{\sigma_{i-3/2}+\sigma_{i-1/2}} - \sigma_{i-1/2} = \frac{-\sigma_{i-1/2}\sigma_{i-3/2}}{\sigma_{i-3/2}+\sigma_{i-1/2}} \end{align} % Substitute the latter two expressions in the former: % \begin{align} + \frac{\sigma_{i+1/2} \sigma_{i+3/2}}{\sigma_{i+3/2}+\sigma_{i+1/2}} \Delta^n u_{i+2} - \left( \frac{\sigma_{i+1/2}\sigma_{i+3/2}}{\sigma_{i+3/2}+\sigma_{i+1/2}} +\frac{\sigma_{i-1/2}\sigma_{i-3/2}}{\sigma_{i-1/2}+\sigma_{i-3/2}}\right)\Delta^n u_{i} + \frac{\sigma_{i-1/2}\sigma_{i-3/2}}{\sigma_{i-1/2}+\sigma_{i-3/2}}\Delta^n u_{i-2}\nonumber\\ = -r_{i}^n - \frac{\sigma_{i+1/2} r_{i+1}^n}{\sigma_{i+3/2}+\sigma_{i+1/2}} - \frac{\sigma_{i-1/2} r_{i-1}^n}{\sigma_{i-1/2}+\sigma_{i-3/2}} \label{eqn:mg1D7} \end{align} % \section{Multigrid Zero-Gradient Boundary} Suppose we have a boundary condition at the boundary node $i$ such that the gradient of $u$ is maintained to zero: % \begin{equation} \Delta^n u_i - \Delta^n u_{i-1} =0 \label{eqn:mgBC1} \end{equation} % Further, note that the delta form at the nearby boundary node $i-1$ can be expressed as: % \begin{equation} \sigma_{i-1/2} \Delta^n u_{i} - (\sigma_{i-1/2}+\sigma_{i-3/2}) \Delta^n u_{i-1} +\sigma_{i-3/2}\Delta^n u_{i-2} = -r_{i-1}^n \label{eqn:mgBC2} \end{equation} % Isolate $\Delta^n u_{i-1}$ in Eq.\ (\ref{eqn:mgBC1}) and substitute in Eq.\ (\ref{eqn:mgBC2}): % \begin{equation} \sigma_{i-1/2} \Delta^n u_{i} - (\sigma_{i-1/2}+\sigma_{i-3/2}) \Delta^n u_{i} +\sigma_{i-3/2}\Delta^n u_{i-2} = -r_{i-1}^n \end{equation} % Simplify: % \begin{equation} - \sigma_{i-3/2} \Delta^n u_{i} +\sigma_{i-3/2}\Delta^n u_{i-2} = -r_{i-1}^n \end{equation} % \section{Multigrid 1D Boundary} Consider the discretization equation at the right boundary node $i,j$: % \begin{equation} a_{i,j} \Delta^n u_{i-1,j} + b_{i,j} \Delta^n u_{i,j} = {\rm RHS}_{i,j} \end{equation} % and the discretization equation at the near boundary node: % \begin{equation} a_{i-1,j} \Delta^n u_{i-2,j} + b_{i-1,j} \Delta^n u_{i-1,j} + c_{i-1,j} \Delta^n u_{i,j} = {\rm RHS}_{i-1,j} \end{equation} % Isolate $\Delta^n u_{i-1,j}$ in the latter and substitute in the former: % \begin{equation} - \frac{a_{i,j} a_{i-1,j}}{b_{i-1,j}} \Delta^n u_{i-2,j} + \left( b_{i,j} - \frac{a_{i,j} c_{i-1,j}}{b_{i-1,j}}\right) \Delta^n u_{i,j} = {\rm RHS}_{i,j} -\frac{a_{i,j} {\rm RHS}_{i-1,j}}{b_{i-1,j}} \end{equation} % Consider the discretization equation at the left boundary node $i,j$: % \begin{equation} b_{i,j} \Delta^n u_{i,j} + c_{i,j} \Delta^n u_{i+1,j} = {\rm RHS}_{i,j} \end{equation} % and the discretization equation at the near boundary node: % \begin{equation} a_{i+1,j} \Delta^n u_{i,j} + b_{i+1,j} \Delta^n u_{i+1,j} + c_{i+1,j} \Delta^n u_{i+2,j} = {\rm RHS}_{i+1,j} \end{equation} % Isolate $\Delta^n u_{i+1,j}$ in the latter and substitute in the former: % \begin{equation} - \frac{c_{i+1,j}c_{i,j}}{b_{i+1,j}} \Delta^n u_{i+2,j} + \left( b_{i,j} - \frac{a_{i+1,j}c_{i,j}}{b_{i+1,j}} \right)\Delta^n u_{i,j} = {\rm RHS}_{i,j} -\frac{c_{i,j} {\rm RHS}_{i+1,j}}{b_{i+1,j}} \end{equation} % \section{Multigrid 2D} Here we will derive the delta form on a mesh 2 times coarser for a 1D system with non constant coefficients. % \begin{align} a_{i,j} \Delta^n u_{i-1,j} + b_{i,j} \Delta^n u_{i,j} + c_{i,j} \Delta^n u_{i+1,j} + d_{i,j} \Delta^n u_{i,j-1} + e_{i,j} \Delta^n u_{i,j+1} = -r_{i,j}^n \label{eqn:mg2D1} \end{align} % Now consider the same equation evaluated at node $i+1$, $i-1$, $j+1$, $j-1$: % \begin{align} a_{i+1,j} \Delta^n u_{i,j} + b_{i+1,j} \Delta^n u_{i+1,j} + c_{i+1,j} \Delta^n u_{i+2,j} + d_{i+1,j} \Delta^n u_{i+1,j-1} + e_{i+1,j} \Delta^n u_{i+1,j+1} = -r_{i+1,j}^n \label{eqn:mg2D2} \end{align} % % \begin{align} a_{i-1,j} \Delta^n u_{i-2,j} + b_{i-1,j} \Delta^n u_{i-1,j} + c_{i-1,j} \Delta^n u_{i,j} + d_{i-1,j} \Delta^n u_{i-1,j-1} + e_{i-1,j} \Delta^n u_{i-1,j+1} = -r_{i-1,j}^n \label{eqn:mg2D3} \end{align} % % \begin{align} a_{i,j+1} \Delta^n u_{i-1,j+1} + b_{i,j+1} \Delta^n u_{i,j+1} + c_{i,j+1} \Delta^n u_{i+1,j+1} + d_{i,j+1} \Delta^n u_{i,j} + e_{i,j+1} \Delta^n u_{i,j+2} = -r_{i,j+1}^n \label{eqn:mg2D4} \end{align} % % \begin{align} a_{i,j-1} \Delta^n u_{i-1,j-1} + b_{i,j-1} \Delta^n u_{i,j-1} + c_{i,j-1} \Delta^n u_{i+1,j-1} + d_{i,j-1} \Delta^n u_{i,j-2} + e_{i,j-1} \Delta^n u_{i,j} = -r_{i,j-1}^n \label{eqn:mg2D5} \end{align} % Rearrange: % \begin{align} \Delta^n u_{i+1,j} =- \frac{a_{i+1,j}}{b_{i+1,j}} \Delta^n u_{i,j} - \frac{c_{i+1,j}}{b_{i+1,j}} \Delta^n u_{i+2,j} - \frac{d_{i+1,j}}{b_{i+1,j}} \Delta^n u_{i+1,j-1} - \frac{e_{i+1,j}}{b_{i+1,j}} \Delta^n u_{i+1,j+1} -\frac{r_{i+1,j}^n}{b_{i+1,j}} \label{eqn:mg2D6} \end{align} % % \begin{align} \Delta^n u_{i-1,j} = - \frac{a_{i-1,j}}{b_{i-1,j}} \Delta^n u_{i-2,j} - \frac{c_{i-1,j}}{b_{i-1,j}} \Delta^n u_{i,j} - \frac{d_{i-1,j}}{b_{i-1,j}} \Delta^n u_{i-1,j-1} - \frac{e_{i-1,j}}{b_{i-1,j}} \Delta^n u_{i-1,j+1} - \frac{r_{i-1,j}^n}{b_{i-1,j}} \label{eqn:mg2D7} \end{align} % % \begin{align} \Delta^n u_{i,j+1} = - \frac{a_{i,j+1}}{b_{i,j+1}} \Delta^n u_{i-1,j+1} - \frac{c_{i,j+1}}{b_{i,j+1}} \Delta^n u_{i+1,j+1} - \frac{d_{i,j+1}}{b_{i,j+1}} \Delta^n u_{i,j} - \frac{e_{i,j+1}}{b_{i,j+1}} \Delta^n u_{i,j+2} - \frac{r_{i,j+1}^n}{b_{i,j+1}} \label{eqn:mg2D8} \end{align} % % \begin{align} \Delta^n u_{i,j-1} = - \frac{a_{i,j-1}}{b_{i,j-1}} \Delta^n u_{i-1,j-1} - \frac{c_{i,j-1}}{b_{i,j-1}} \Delta^n u_{i+1,j-1} - \frac{d_{i,j-1}}{b_{i,j-1}} \Delta^n u_{i,j-2} - \frac{e_{i,j-1}}{b_{i,j-1}} \Delta^n u_{i,j} - \frac{r_{i,j-1}^n}{b_{i,j-1}} \label{eqn:mg2D9} \end{align} % Substitute the latter 4 equations in Eq.\ (\ref{eqn:mg2D10}): % \begin{align} + \left( b_{i,j} - \frac{a_{i,j} c_{i-1,j}}{b_{i-1,j}} - \frac{c_{i,j} a_{i+1,j}}{b_{i+1,j}} - \frac{d_{i,j} e_{i,j-1}}{b_{i,j-1}} - \frac{e_{i,j} d_{i,j+1}}{b_{i,j+1}} \right) \Delta^n u_{i,j} \nonumber\\ - \frac{a_{i,j} a_{i-1,j}}{b_{i-1,j}} \Delta^n u_{i-2,j} - \frac{c_{i,j} c_{i+1,j}}{b_{i+1,j}} \Delta^n u_{i+2,j} - \frac{d_{i,j} d_{i,j-1}}{b_{i,j-1}} \Delta^n u_{i,j-2} - \frac{e_{i,j} e_{i,j+1}}{b_{i,j+1}} \Delta^n u_{i,j+2} \nonumber\\ - \left(\frac{c_{i,j} d_{i+1,j}}{b_{i+1,j}}+\frac{d_{i,j} c_{i,j-1}}{b_{i,j-1}}\right) \Delta^n u_{i+1,j-1} - \left(\frac{c_{i,j} e_{i+1,j}}{b_{i+1,j}}+\frac{e_{i,j} c_{i,j+1}}{b_{i,j+1}} \right)\Delta^n u_{i+1,j+1} \nonumber\\ - \left(\frac{d_{i,j} a_{i,j-1}}{b_{i,j-1}}+\frac{a_{i,j} d_{i-1,j}}{b_{i-1,j}}\right) \Delta^n u_{i-1,j-1} - \left(\frac{e_{i,j} a_{i,j+1}}{b_{i,j+1}}+\frac{a_{i,j} e_{i-1,j}}{b_{i-1,j}}\right) \Delta^n u_{i-1,j+1} \nonumber\\ = -r_{i,j}^n + \frac{a_{i,j} r_{i-1,j}^n}{b_{i-1,j}} + \frac{c_{i,j} r_{i+1,j}^n}{b_{i+1,j}} + \frac{d_{i,j} r_{i,j-1}^n}{b_{i,j-1}} + \frac{e_{i,j} r_{i,j+1}^n}{b_{i,j+1}} \label{eqn:mg2D10} \end{align} % \bibliographystyle{warpdoc} \bibliography{all} \end{document}
(* Title: HOL/Auth/n_german_lemma_inv__15_on_rules.thy Author: Yongjian Li and Kaiqiang Duan, State Key Lab of Computer Science, Institute of Software, Chinese Academy of Sciences Copyright 2016 State Key Lab of Computer Science, Institute of Software, Chinese Academy of Sciences *) header{*The n_german Protocol Case Study*} theory n_german_lemma_inv__15_on_rules imports n_german_lemma_on_inv__15 begin section{*All lemmas on causal relation between inv__15*} lemma lemma_inv__15_on_rules: assumes b1: "r \<in> rules N" and b2: "(\<exists> p__Inv1 p__Inv2. p__Inv1\<le>N\<and>p__Inv2\<le>N\<and>p__Inv1~=p__Inv2\<and>f=inv__15 p__Inv1 p__Inv2)" shows "invHoldForRule s f r (invariants N)" proof - have c1: "(\<exists> i d. i\<le>N\<and>d\<le>N\<and>r=n_Store i d)\<or> (\<exists> i. i\<le>N\<and>r=n_SendReqS i)\<or> (\<exists> i. i\<le>N\<and>r=n_SendReqE__part__0 i)\<or> (\<exists> i. i\<le>N\<and>r=n_SendReqE__part__1 i)\<or> (\<exists> i. i\<le>N\<and>r=n_RecvReqS N i)\<or> (\<exists> i. i\<le>N\<and>r=n_RecvReqE N i)\<or> (\<exists> i. i\<le>N\<and>r=n_SendInv__part__0 i)\<or> (\<exists> i. i\<le>N\<and>r=n_SendInv__part__1 i)\<or> (\<exists> i. i\<le>N\<and>r=n_SendInvAck i)\<or> (\<exists> i. i\<le>N\<and>r=n_RecvInvAck i)\<or> (\<exists> i. i\<le>N\<and>r=n_SendGntS i)\<or> (\<exists> i. i\<le>N\<and>r=n_SendGntE N i)\<or> (\<exists> i. i\<le>N\<and>r=n_RecvGntS i)\<or> (\<exists> i. i\<le>N\<and>r=n_RecvGntE i)" apply (cut_tac b1, auto) done moreover { assume d1: "(\<exists> i d. i\<le>N\<and>d\<le>N\<and>r=n_Store i d)" have "invHoldForRule s f r (invariants N)" apply (cut_tac b2 d1, metis n_StoreVsinv__15) done } moreover { assume d1: "(\<exists> i. i\<le>N\<and>r=n_SendReqS i)" have "invHoldForRule s f r (invariants N)" apply (cut_tac b2 d1, metis n_SendReqSVsinv__15) done } moreover { assume d1: "(\<exists> i. i\<le>N\<and>r=n_SendReqE__part__0 i)" have "invHoldForRule s f r (invariants N)" apply (cut_tac b2 d1, metis n_SendReqE__part__0Vsinv__15) done } moreover { assume d1: "(\<exists> i. i\<le>N\<and>r=n_SendReqE__part__1 i)" have "invHoldForRule s f r (invariants N)" apply (cut_tac b2 d1, metis n_SendReqE__part__1Vsinv__15) done } moreover { assume d1: "(\<exists> i. i\<le>N\<and>r=n_RecvReqS N i)" have "invHoldForRule s f r (invariants N)" apply (cut_tac b2 d1, metis n_RecvReqSVsinv__15) done } moreover { assume d1: "(\<exists> i. i\<le>N\<and>r=n_RecvReqE N i)" have "invHoldForRule s f r (invariants N)" apply (cut_tac b2 d1, metis n_RecvReqEVsinv__15) done } moreover { assume d1: "(\<exists> i. i\<le>N\<and>r=n_SendInv__part__0 i)" have "invHoldForRule s f r (invariants N)" apply (cut_tac b2 d1, metis n_SendInv__part__0Vsinv__15) done } moreover { assume d1: "(\<exists> i. i\<le>N\<and>r=n_SendInv__part__1 i)" have "invHoldForRule s f r (invariants N)" apply (cut_tac b2 d1, metis n_SendInv__part__1Vsinv__15) done } moreover { assume d1: "(\<exists> i. i\<le>N\<and>r=n_SendInvAck i)" have "invHoldForRule s f r (invariants N)" apply (cut_tac b2 d1, metis n_SendInvAckVsinv__15) done } moreover { assume d1: "(\<exists> i. i\<le>N\<and>r=n_RecvInvAck i)" have "invHoldForRule s f r (invariants N)" apply (cut_tac b2 d1, metis n_RecvInvAckVsinv__15) done } moreover { assume d1: "(\<exists> i. i\<le>N\<and>r=n_SendGntS i)" have "invHoldForRule s f r (invariants N)" apply (cut_tac b2 d1, metis n_SendGntSVsinv__15) done } moreover { assume d1: "(\<exists> i. i\<le>N\<and>r=n_SendGntE N i)" have "invHoldForRule s f r (invariants N)" apply (cut_tac b2 d1, metis n_SendGntEVsinv__15) done } moreover { assume d1: "(\<exists> i. i\<le>N\<and>r=n_RecvGntS i)" have "invHoldForRule s f r (invariants N)" apply (cut_tac b2 d1, metis n_RecvGntSVsinv__15) done } moreover { assume d1: "(\<exists> i. i\<le>N\<and>r=n_RecvGntE i)" have "invHoldForRule s f r (invariants N)" apply (cut_tac b2 d1, metis n_RecvGntEVsinv__15) done } ultimately show "invHoldForRule s f r (invariants N)" by satx qed end
function SeqsNew = SimulationFast_ConditionalThinning_ExpHP(SeqsOld, ... para, options) %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % The fast simulation of Hawkes processes with exponential kernels % conditioned on history % % Reference: % Dassios, Angelos, and Hongbiao Zhao. % "Exact simulation of Hawkes process with exponentially decaying intensity." % Electronic Communications in Probability 18.62 (2013): 1-13. % % Provider: % Hongteng Xu @ Georgia Tech % June 13, 2017 % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% SeqsNew = struct('Time', [], ... 'Mark', [], ... 'Start', [], ... 'Stop', [], ... 'Feature', []); tic for n = 1:length(SeqsOld) t=SeqsOld(n).Stop; History = [SeqsOld(n).Time; SeqsOld(n).Mark]; lambdat = Intensity_HP(t, History, para); mt = sum(lambdat); while t<options.Tmax && size(History, 2)<options.Nmax s = random('exp', 1/mt); U = rand; lambda_ts = Intensity_Recurrent_HP(t+s, [], t, lambdat, para); mts = sum(lambda_ts); %fprintf('s=%f, v=%f\n', s, mts/mt); if t+s>options.Tmax || U>mts/mt t = t+s; lambdat = lambda_ts; else u = rand*mts; sumIs = 0; for d=1:length(lambda_ts) sumIs = sumIs + lambda_ts(d); if sumIs >= u break; end end index = d; lambdat = Intensity_Recurrent_HP(t+s, index(1), t, lambdat, para); t = t+s; History = [History,[t;index(1)]]; end mt = sum(lambdat); end SeqsNew(n).Time = History(1,:); SeqsNew(n).Mark = History(2,:); SeqsNew(n).Start = SeqsOld(n).Stop; SeqsNew(n).Stop = options.Tmax; index = find(SeqsOld(n).Stop<=SeqsNew(n).Time & ... SeqsNew(n).Time<=options.Tmax); SeqsNew(n).Time = SeqsNew(n).Time(index); SeqsNew(n).Mark = SeqsNew(n).Mark(index); if mod(n, 10)==0 || n==options.N fprintf('#seq=%d/%d, #event=%d, time=%.2fsec\n', ... n, options.N, length(SeqsNew(n).Mark), toc); end end
<unk> proteins are members of a class of proteins that dictate the stereochemistry of a compound synthesized by other enzymes .
[STATEMENT] lemma to_nat_on_inj[simp]: "countable A \<Longrightarrow> a \<in> A \<Longrightarrow> b \<in> A \<Longrightarrow> to_nat_on A a = to_nat_on A b \<longleftrightarrow> a = b" [PROOF STATE] proof (prove) goal (1 subgoal): 1. \<lbrakk>countable A; a \<in> A; b \<in> A\<rbrakk> \<Longrightarrow> (to_nat_on A a = to_nat_on A b) = (a = b) [PROOF STEP] using inj_on_to_nat_on[of A] [PROOF STATE] proof (prove) using this: countable A \<Longrightarrow> inj_on (to_nat_on A) A goal (1 subgoal): 1. \<lbrakk>countable A; a \<in> A; b \<in> A\<rbrakk> \<Longrightarrow> (to_nat_on A a = to_nat_on A b) = (a = b) [PROOF STEP] by (auto dest: inj_onD)
[STATEMENT] lemma rt_fresh_as_fresherI [intro]: assumes "dip\<in>kD(rt1)" and "dip\<in>kD(rt2)" and "the (rt1 dip) \<sqsubseteq> the (rt2 dip)" and "the (rt2 dip) \<sqsubseteq> the (rt1 dip)" shows "rt1 \<approx>\<^bsub>dip\<^esub> rt2" [PROOF STATE] proof (prove) goal (1 subgoal): 1. rt1 \<approx>\<^bsub>dip\<^esub> rt2 [PROOF STEP] using assms [PROOF STATE] proof (prove) using this: dip \<in> kD rt1 dip \<in> kD rt2 the (rt1 dip) \<sqsubseteq> the (rt2 dip) the (rt2 dip) \<sqsubseteq> the (rt1 dip) goal (1 subgoal): 1. rt1 \<approx>\<^bsub>dip\<^esub> rt2 [PROOF STEP] unfolding rt_fresh_as_def [PROOF STATE] proof (prove) using this: dip \<in> kD rt1 dip \<in> kD rt2 the (rt1 dip) \<sqsubseteq> the (rt2 dip) the (rt2 dip) \<sqsubseteq> the (rt1 dip) goal (1 subgoal): 1. rt1 \<sqsubseteq>\<^bsub>dip\<^esub> rt2 \<and> rt2 \<sqsubseteq>\<^bsub>dip\<^esub> rt1 [PROOF STEP] by (clarsimp dest!: single_rt_fresher)
theory T106 imports Main begin lemma "( (\<forall> x::nat. \<forall> y::nat. meet(x, y) = meet(y, x)) & (\<forall> x::nat. \<forall> y::nat. join(x, y) = join(y, x)) & (\<forall> x::nat. \<forall> y::nat. \<forall> z::nat. meet(x, meet(y, z)) = meet(meet(x, y), z)) & (\<forall> x::nat. \<forall> y::nat. \<forall> z::nat. join(x, join(y, z)) = join(join(x, y), z)) & (\<forall> x::nat. \<forall> y::nat. meet(x, join(x, y)) = x) & (\<forall> x::nat. \<forall> y::nat. join(x, meet(x, y)) = x) & (\<forall> x::nat. \<forall> y::nat. \<forall> z::nat. mult(x, join(y, z)) = join(mult(x, y), mult(x, z))) & (\<forall> x::nat. \<forall> y::nat. \<forall> z::nat. mult(join(x, y), z) = join(mult(x, z), mult(y, z))) & (\<forall> x::nat. \<forall> y::nat. \<forall> z::nat. meet(x, over(join(mult(x, y), z), y)) = x) & (\<forall> x::nat. \<forall> y::nat. \<forall> z::nat. meet(y, undr(x, join(mult(x, y), z))) = y) & (\<forall> x::nat. \<forall> y::nat. \<forall> z::nat. join(mult(over(x, y), y), x) = x) & (\<forall> x::nat. \<forall> y::nat. \<forall> z::nat. join(mult(y, undr(y, x)), x) = x) & (\<forall> x::nat. \<forall> y::nat. \<forall> z::nat. undr(x, join(y, z)) = join(undr(x, y), undr(x, z))) & (\<forall> x::nat. \<forall> y::nat. \<forall> z::nat. undr(meet(x, y), z) = join(undr(x, z), undr(y, z))) & (\<forall> x::nat. \<forall> y::nat. invo(join(x, y)) = meet(invo(x), invo(y))) & (\<forall> x::nat. \<forall> y::nat. invo(meet(x, y)) = join(invo(x), invo(y))) & (\<forall> x::nat. invo(invo(x)) = x) ) \<longrightarrow> (\<forall> x::nat. \<forall> y::nat. \<forall> z::nat. over(join(x, y), z) = join(over(x, z), over(y, z))) " nitpick[card nat=4,timeout=86400] oops end
function [f] = spm_mc_fx_3(x,v,P) % equations of motion for the mountain car problem using basis functions % problem % FORMAT [f] = spm_mc_fx_3(x,v,P) % % x - hidden states % v - exogenous inputs % P.p - parameters for gradient function: G(x(1),P.p) % P.q - parameters for cost or loss-function: C(x(1),P.q) % % returns f = dx/dt = f = [x(2); % G - x(2)*C]*dt; % % where C determines divergence of flow x(2) at any position x(1). %__________________________________________________________________________ % Copyright (C) 2008 Wellcome Trust Centre for Neuroimaging % Karl Friston % $Id: spm_mc_fx_3.m 3333 2009-08-25 16:12:44Z karl $ % gradient (G) %-------------------------------------------------------------------------- G = spm_DEM_basis(x.x(1),v,P.p); % cost function (C) %-------------------------------------------------------------------------- C = spm_DEM_basis(x.x(1),v,P.q); % flow %-------------------------------------------------------------------------- dt = 1/8; f.x = [x.x(2); G - x.x(2)*x.c]*dt; f.c = [-C - x.c]*dt; % true scalar potential gradient (see spm_moutaincar_fx) %-------------------------------------------------------------------------- % if x(1) < 0 % G = 2*x(1) + 1; % else % xx = x(1)^2; % G = (1 + 5*xx)^(-1/2) - 5*xx/(1 + 5*xx)^(3/2) + (x(1)/2)^4; % end
#' Cast functions #' Cast a molten data frame into an array or data frame. #' #' Use \code{acast} or \code{dcast} depending on whether you want #' vector/matrix/array output or data frame output. Data frames can have at #' most two dimensions. #' #' The cast formula has the following format: #' \code{x_variable + x_2 ~ y_variable + y_2 ~ z_variable ~ ... } #' The order of the variables makes a difference. The first varies slowest, #' and the last fastest. There are a couple of special variables: "..." #' represents all other variables not used in the formula and "." represents #' no variable, so you can do \code{formula = var1 ~ .}. #' #' Alternatively, you can supply a list of quoted expressions, in the form #' \code{list(.(x_variable, x_2), .(y_variable, y_2), .(z))}. The advantage #' of this form is that you can cast based on transformations of the #' variables: \code{list(.(a + b), (c = round(c)))}. See the documentation #' for \code{\link[plyr]{.}} for more details and alternative formats. #' #' If the combination of variables you supply does not uniquely identify one #' row in the original data set, you will need to supply an aggregating #' function, \code{fun.aggregate}. This function should take a vector of #' numbers and return a single summary statistic. #' #' @keywords manip #' @param data molten data frame, see \code{\link{melt}}. #' @param formula casting formula, see details for specifics. #' @param fun.aggregate aggregation function needed if variables do not #' identify a single observation for each output cell. Defaults to length #' (with a message) if needed but not specified. #' @param ... further arguments are passed to aggregating function #' @param margins vector of variable names (can include "grand\_col" and #' "grand\_row") to compute margins for, or TRUE to compute all margins . #' Any variables that can not be margined over will be silently dropped. #' @param subset quoted expression used to subset data prior to reshaping, #' e.g. \code{subset = .(variable=="length")}. #' @param fill value with which to fill in structural missings, defaults to #' value from applying \code{fun.aggregate} to 0 length vector #' @param drop should missing combinations dropped or kept? #' @param value.var name of column which stores values, see #' \code{\link{guess_value}} for default strategies to figure this out. #' @seealso \code{\link{melt}}, \url{http://had.co.nz/reshape/} #' @import plyr #' @import stringr #' @examples #' #Air quality example #' names(airquality) <- tolower(names(airquality)) #' aqm <- melt(airquality, id=c("month", "day"), na.rm=TRUE) #' #' acast(aqm, day ~ month ~ variable) #' acast(aqm, month ~ variable, mean) #' acast(aqm, month ~ variable, mean, margins = TRUE) #' dcast(aqm, month ~ variable, mean, margins = c("month", "variable")) #' #' library(plyr) # needed to access . function #' acast(aqm, variable ~ month, mean, subset = .(variable == "ozone")) #' acast(aqm, variable ~ month, mean, subset = .(month == 5)) #' #' #Chick weight example #' names(ChickWeight) <- tolower(names(ChickWeight)) #' chick_m <- melt(ChickWeight, id=2:4, na.rm=TRUE) #' #' dcast(chick_m, time ~ variable, mean) # average effect of time #' dcast(chick_m, diet ~ variable, mean) # average effect of diet #' acast(chick_m, diet ~ time, mean) # average effect of diet & time #' #' # How many chicks at each time? - checking for balance #' acast(chick_m, time ~ diet, length) #' acast(chick_m, chick ~ time, mean) #' acast(chick_m, chick ~ time, mean, subset = .(time < 10 & chick < 20)) #' #' acast(chick_m, time ~ diet, length) #' #' dcast(chick_m, diet + chick ~ time) #' acast(chick_m, diet + chick ~ time) #' acast(chick_m, chick ~ time ~ diet) #' acast(chick_m, diet + chick ~ time, length, margins="diet") #' acast(chick_m, diet + chick ~ time, length, drop = FALSE) #' #' #Tips example #' dcast(melt(tips), sex ~ smoker, mean, subset = .(variable == "total_bill")) #' #' ff_d <- melt(french_fries, id=1:4, na.rm=TRUE) #' acast(ff_d, subject ~ time, length) #' acast(ff_d, subject ~ time, length, fill=0) #' dcast(ff_d, treatment ~ variable, mean, margins = TRUE) #' dcast(ff_d, treatment + subject ~ variable, mean, margins="treatment") #' if (require("lattice")) { #' lattice::xyplot(`1` ~ `2` | variable, dcast(ff_d, ... ~ rep), aspect="iso") #' } #' @name cast NULL cast <- function(data, formula, fun.aggregate = NULL, ..., subset = NULL, fill = NULL, drop = TRUE, value.var = guess_value(data), value_var) { if (!missing(value_var)) { stop("Please use value.var instead of value_var.", call. = FALSE) } if (!(value.var %in% names(data))) { stop("value.var (", value.var, ") not found in input", call. = FALSE) } if (!is.null(subset)) { include <- data.frame(eval.quoted(subset, data)) data <- data[rowSums(include) == ncol(include), ] } formula <- parse_formula(formula, names(data), value.var) value <- data[[value.var]] # Need to branch here depending on whether or not we have strings or # expressions - strings should avoid making copies of the data vars <- lapply(formula, eval.quoted, envir = data, enclos = parent.frame(2)) # Compute labels and id values ids <- lapply(vars, id, drop = drop) # Empty specifications (.) get repeated id is_empty <- vapply(ids, length, integer(1)) == 0 empty <- structure(rep(1, nrow(data)), n = 1L) ids[is_empty] <- rep(list(empty), sum(is_empty)) labels <- mapply(split_labels, vars, ids, MoreArgs = list(drop = drop), SIMPLIFY = FALSE, USE.NAMES = FALSE) labels[is_empty] <- rep(list(data.frame(. = ".")), sum(is_empty)) overall <- id(rev(ids), drop = FALSE) n <- attr(overall, "n") # Aggregate duplicates if (any(duplicated(overall)) || !is.null(fun.aggregate)) { if (is.null(fun.aggregate)) { message("Aggregation function missing: defaulting to length") fun.aggregate <- length } ordered <- vaggregate(.value = value, .group = overall, .fun = fun.aggregate, ..., .default = fill, .n = n) overall <- seq_len(n) } else { # Add in missing values, if necessary if (length(overall) < n) { overall <- match(seq_len(n), overall, nomatch = NA) } else { overall <- order(overall) } ordered <- value[overall] if (!is.null(fill)) { ordered[is.na(ordered)] <- fill } } ns <- vapply(ids, attr, double(1), "n") dim(ordered) <- ns list( data = ordered, labels = labels ) } #' @rdname cast #' @export dcast <- function(data, formula, fun.aggregate = NULL, ..., margins = NULL, subset = NULL, fill=NULL, drop = TRUE, value.var = guess_value(data)) { formula <- parse_formula(formula, names(data), value.var) if (length(formula) > 2) { stop("Dataframes have at most two output dimensions") } if (!is.null(margins)) { data <- add_margins(data, lapply(formula, names), margins) } res <- cast(data, formula, fun.aggregate, ..., subset = subset, fill = fill, drop = drop, value.var = value.var) data <- as.data.frame.matrix(res$data, stringsAsFactors = FALSE) names(data) <- array_names(res$labels[[2]]) stopifnot(nrow(res$labels[[1]]) == nrow(data)) cbind(res$labels[[1]], data) } #' @rdname cast #' @export acast <- function(data, formula, fun.aggregate = NULL, ..., margins = NULL, subset = NULL, fill=NULL, drop = TRUE, value.var = guess_value(data)) { formula <- parse_formula(formula, names(data), value.var) if (!is.null(margins)) { data <- add_margins(data, lapply(formula, names), margins) } res <- cast(data, formula, fun.aggregate, ..., subset = subset, fill = fill, drop = drop, value.var = value.var) dimnames(res$data) <- lapply(res$labels, array_names) res$data } array_names <- function(df) { do.call(paste, c(df, list(sep = "_"))) }
Formal statement is: lemma cauchy_def: "Cauchy S \<longleftrightarrow> (\<forall>e>0. \<exists>N. \<forall>m n. m \<ge> N \<and> n \<ge> N \<longrightarrow> dist (S m) (S n) < e)" Informal statement is: A sequence $S$ is Cauchy if and only if for every $\epsilon > 0$, there exists an $N$ such that for all $m, n \geq N$, we have $|S_m - S_n| < \epsilon$.
## URL used to be: http://www.daviscomicopera.org/ The Davis Comic Opera Company Live Theatre entertained Sacramento Valley audiences from 1973 to 2006, specializing in the Gilbert and Sullivan Opera repertoire, as well as operetta classics. Performances were held at the Veterans Memorial Theatre in Davis. 20060304 01:43:52 nbsp I think they may be merging with Light Opera Theatre of Sacramento, but Im not totally sure about that. Users/KarenaAslanian 20060714 18:05:13 nbsp The Davis Comic Opera Company ceased to exist on June 1, 2006. It is my understanding that Light Opera Theatre of Sacramento is also about ready to close its doors. Users/BevSykes 20080517 18:31:47 nbsp I dont know much about the DCOC, but the Light Opera Theatre of Sacramento just wrapped up G&Ss The Gondoliers and as far as I know, has no plans to close its doors! Users/carter 20080903 21:37:28 nbsp As a member of the board of directors at Light Opera Theatre of Sacramento, Id love to clarify. We are not merging with Davis Comic Opera, though Sean Bianco (once artistic director of Davis Comic Opera) has been our musical director since 2004. Our company is not in fact closing its doors nor does it have any plans to do so. Thanks. Users/kebaad
# Automatic differentiation __Automatic differentiation__ is a method for evaluating the rate of change in the numerical output of a program with respect to the rate of change in its input. The power of the method is the ability of writing a program that computes a differentiable function and having the derivative immediatelly available. We start with an example. Consider the function $$ f(x) = \cos(x)\sin(x) $$ When we want to evaluate the function numerically at a specific $x$, say $x=1$ we can implement a computer program like ~~~ x = 1 f = cos(x)*sin(x) ~~~ or ~~~ def g(x): return cos(x)*sin(x) x = 1 f = g(x) ~~~ Now suppose we need the derivative as well, that is how much $f$ changes when we slightly change $x$. For this example, it is a simple exercise to calculate the derivative symbolically as $$ f'(x) = \cos(x)\cos(x) -\sin(x)\sin(x) = \cos(x)^2 - \sin(x)^2 $$ and code this explicitely as ~~~ x = 1 df_dx = cos(x)*cos(x) - sin(x)*sin(x) ~~~ But could we have calculated the derivative without coding it up explicitely, that is without symbolically evaluating it a priori by hand? For example, can we code just ~~~ x = my.Variable(1) f = my.cos(x)*my.sin(x) df_dx = f.derivative() ~~~ or ~~~ def g(x): return my.cos(x)*my.sin(x) x = my.Variable(1) f = g(x) df_dx = f.derivative() ~~~ to get what we want, perhaps by overloading the appropriate variables, functions and operators? The answer turns out to be yes and it is a quite fascinating subject called __automatic differentiation__. Interestingly, this algorithm, known also as __backpropagation__, is in the core of todays artificial intelligence systems, programs that learn how to program themselves from input and output examples. See https://www.youtube.com/watch?v=aircAruvnKk for an introduction to a particular type of model, known as a __neural network__. To symbolically evaluate the derivative, we use the chain rule. The chain rule dictates that when $$ f(x) = g(h(x)) $$ the derivative is given as $$ f'(x) = g'(h(x)) h'(x) $$ We could implement this program as ~~~ x = 1 h = H(x) g = G(h) f = g ~~~ where we have used capital letters for the functions -- beware that the function and its output is always denoted with the same letter in mathematical notation. To highlight the underlying mechanism of automatic differentiation, we will always assign the output of a function to a variable so we will only think of the rate of change of a variable with respect to another variable, rather than 'derivatives of functions'. To be entirely formal we write ~~~ x = 1 h = H(x) g = G(h) f = identity(g) ~~~ and denote the identity function as $(\cdot)$. This program can be represented also by the following directed computation graph: The derivative is denoted by $$ f'(x) = \frac{df}{dx} $$ As we will later use multiple variables, we will already introduce the partial derivative notation, that is equivalent to the derivative for scalar functions. $$ f'(x) = \frac{\partial f}{\partial x} $$ The chain rule, using the partial derivative notation can be stated as \begin{eqnarray} \frac{\partial f}{\partial x} & = & \frac{\partial h}{\partial x} \frac{\partial g}{\partial h} \frac{\partial f}{\partial g} \\ & = & h'(x) g'(h(x)) \cdot 1 \end{eqnarray} This quantity is actually just a product of numbers, so we could have evaluated this derivative in the following order \begin{eqnarray} \frac{\partial f}{\partial x} & = & \frac{\partial h}{\partial x} \left(\frac{\partial g}{\partial h} \left(\frac{\partial f}{\partial g} \frac{\partial f}{\partial f} \right) \right) \\ & =& \frac{\partial h}{\partial x} \left(\frac{\partial g}{\partial h} \frac{\partial f}{\partial g} \right) \\ & = &\frac{\partial h}{\partial x} \frac{\partial f}{\partial h} \\ & = &\frac{\partial f}{\partial x} \end{eqnarray} where we have included $\partial f/\partial f = 1$ as the boundry case. So, we could imagine calculating the derivative using the following program ~~~ df_df = 1 df_dg = 1 * df_df df_dh = dG(h) * df_dg df_dx = dH(x) * df_dh ~~~ If $g$ and $h$ are elementary functions, their derivatives are known in closed form and can be calculated from their input(s) only. As an example, consider $$ f(x) = \sin(\cos(x)) $$ The derivative is $$ \frac{\partial f}{\partial x} = -\sin(x) \cos(\cos(x)) $$ ~~~ df_df = 1 df_dg = 1 * df_df df_dh = cos(h) * df_dg df_dx = -sin(x) * df_dh ~~~ As $h=\cos(x)$, it can be easily verified that the derivative is calculated correctly. ### Functions of two or more variables When we have functions of two or more variables the notion of a derivative changes slightly. For example, when $$ g(x_1, x_2) $$ we define the partial derivatives \begin{eqnarray} \frac{\partial g}{\partial x_1} & , & \frac{\partial g}{\partial x_2} \end{eqnarray} The collection of partial derivatives can be organized as a vector. This object is known as the __gradient__ and is denoted as \begin{eqnarray} \nabla g(x) \equiv \left(\begin{array}{c} \frac{\partial g}{\partial x_1} \\ \frac{\partial g}{\partial x_2} \end{array} \right) \end{eqnarray} When taking the partial derivative, we assume that all the variables are constant, apart from the one that we are taking the derivative with respect to. For example, $$ g(x_1, x_2) = \cos(x_1)e^{3 x_2} $$ When taking the (partial) derivative with respect to $x_1$, we assume that the second factor is a constant $$ \frac{\partial g}{\partial x_1} = -\sin(x_1) e^{3 x_2} $$ Similarly, when taking the partial derivative with respect to $x_2$, we assume that the first factor is a constant $$ \frac{\partial g}{\partial x_2} = 3 \cos(x_1) e^{3 x_2} $$ The chain rule for multiple variables is in a way similar to the chain rule for single variable functions but with a caveat: the derivatives over all paths between the two variables need to be added. Another example is $$ f(x) = g(h_1(x), h_2(x)) $$ Here, the partial derivative is $$ \frac{\partial g}{\partial x} = \frac{\partial g}{\partial h_1} \frac{\partial h_1}{\partial x} + \frac{\partial g}{\partial h_2} \frac{\partial h_2}{\partial x} $$ The chain rule has a simple form $$ \frac{\partial f}{\partial x} = \frac{\partial f}{\partial g} \frac{\partial g}{\partial x} $$ To see a concrete example of a function of form $f(x) = g(h_1(x), h_2(x)) $, consider $$ f(x) = \sin(x)\cos(x) $$ We define \begin{align} h_1(x) & = c = \cos(x) \\ h_2(x) & = s = \sin(x) \\ g(c,s) & = g = c \times s \\ f & = g(c,s) \end{align} that is equivalent to the following program, written deliberately as a sequence of scalar function evaluations and binary operators only ~~~ x = 1 c = cos(x) s = sin(x) g = c * s f = g ~~~ This program can be represented by the following directed computation graph: The function can be evaluated by traversing the variable nodes of the directed graph from the inputs to the outputs in the topological order. At each variable node, we merely evaluate the incoming function. Topological order guarantees that the inputs for the function are already calculated. It is not obvious, but the derivatives can also be calculated easily. By the chain rule, we have \begin{eqnarray} \frac{\partial f}{\partial x} &=& \frac{\partial f}{\partial g} \frac{\partial g}{\partial c} \frac{\partial c}{\partial x} + \frac{\partial f}{\partial g} \frac{\partial g}{\partial s} \frac{\partial s}{\partial x} \\ &=& 1 \cdot s \cdot (-\sin(x)) + 1 \cdot c \cdot \cos(x) \\ &=& -\sin(x) \cdot \sin(x) + 1 \cdot \cos(x) \cdot \cos(x) \\ \end{eqnarray} The derivative could have been calculated numerically by the following program ~~~ df_dx = 0, df_ds = 0, df_dc = 0, df_dg = 0 df_df = 1 df_dg += df_df // df/dg = 1 df_dc += s * df_dg // dg/dc = s df_ds += c * df_dg // dg/ds = c df_dx += cos(x) * df_ds // ds/dx = cos(x) df_dx += -sin(x) * df_dc // dc/dx = -sin(x) ~~~ Note that the total derivative consists of sums of several terms. Each term is the product of the derivatives along the path leading from $f$ to $x$. In the above example, there are only two paths: - $f,g,c,x$ - $f,g,s,x$ $$ \frac{\partial f}{\partial x} = \frac{\partial f}{\partial g} \frac{\partial g}{\partial c} \frac{\partial c}{\partial x} + \frac{\partial f}{\partial g} \frac{\partial g}{\partial s} \frac{\partial s}{\partial x} $$ It is not obvious in this simple example but the fact that we are propagating backwards makes us save computation by storing the intermediate variables. This program can be represented by the following directed computation graph: Note that during the backward pass, if we traverse variable nodes in the reverse topological order, we only need the derivatives already computed in previous steps and values of variables that are connected to the function node that are computed during the forward pass. As an example, consider $$ \frac{\partial f}{\partial c} = \frac{\partial f}{\partial g} \frac{\partial g}{\partial c} $$ The first term is already available during the backward pass. The second term needs to be programmed by calculating the partial derivative of $g(s,c) = sc$ with respect to $c$. It has a simple form, namely $s$. More importantly, the numerical value is also immediately available, as it is calculated during the forward pass. For each function type, this calculation will be different but is nevertheless straightforward for all basic functions, including the binary arithmetic operators $+,-,\times$ and $\div$. Tutorial introductions to Automatic differentiation Richard D. Neidinger, Introduction to Automatic Differentiation and MATLAB Object-Oriented Programming, SIAM REVIEW, 2010 Society for Industrial and Applied Mathematics, Vol. 52, No. 3, pp. 545–563 Baydin, Atılım Güneş, Barak A. Pearlmutter, Alexey Andreyevich Radul, and Jeffrey Mark Siskind. 2018. “Automatic Differentiation in Machine Learning: a Survey.” Journal of Machine Learning Research (JMLR) https://arxiv.org/pdf/1502.05767.pdf Two related blog posts from Ben Recht: http://www.argmin.net/2016/05/18/mates-of-costate/ http://www.argmin.net/2016/05/31/mechanics-of-lagrangians/ Back-propagation, an introduction, by Sanjeev Arora and Tengyu Ma http://www.offconvex.org/2016/12/20/backprop/ A nice autodifferentiation package for python https://github.com/HIPS/autograd A good tutorial on Backpropagation by Roger Grosse http://www.cs.toronto.edu/~rgrosse/courses/csc321_2017/slides/lec6.pdf http://www.cs.toronto.edu/~rgrosse/courses/csc321_2017/readings/L06%20Backpropagation.pdf ```python from __future__ import absolute_import import autograd.numpy as np import matplotlib.pyplot as plt from autograd import grad ''' Mathematically we can only take gradients of scalar-valued functions, but autograd's grad function also handles numpy's familiar vectorization of scalar functions, which is used in this example. To be precise, grad(fun)(x) always returns the value of a vector-Jacobian product, where the Jacobian of fun is evaluated at x and the the vector is an all-ones vector with the same size as the output of fun. When vectorizing a scalar-valued function over many arguments, the Jacobian of the overall vector-to-vector mapping is diagonal, and so this vector-Jacobian product simply returns the diagonal elements of the Jacobian, which is the gradient of the function at each input value over which the function is vectorized. ''' def tanh(x): return (1.0 - np.exp(-x)) / (1.0 + np.exp(-x)) x = np.linspace(-7, 7, 200) plt.plot(x, tanh(x), x, grad(tanh)(x), # first derivative x, grad(grad(tanh))(x), # second derivative x, grad(grad(grad(tanh)))(x), # third derivative x, grad(grad(grad(grad(tanh))))(x), # fourth derivative x, grad(grad(grad(grad(grad(tanh)))))(x), # fifth derivative x, grad(grad(grad(grad(grad(grad(tanh))))))(x)) # sixth derivative plt.axis('off') plt.savefig("tanh.png") plt.show() ```
Formal statement is: lemma continuous_on_no_limpt: "(\<And>x. \<not> x islimpt S) \<Longrightarrow> continuous_on S f" Informal statement is: If $f$ is a function defined on a set $S$ such that no point of $S$ is a limit point of $S$, then $f$ is continuous on $S$.
Formal statement is: lemma uncountable_cball: fixes a :: "'a::euclidean_space" assumes "r > 0" shows "uncountable (cball a r)" Informal statement is: The open ball of radius $r$ around $a$ is uncountable.
Humphrey Bower, winner of multiple Earphones Awards and the prestigious Audie Award for best narration, is a writer, actor, and director. He earned his BA in English literature from Oxford University and has worked extensively in theater, and television. He was a founding member of the Melbourne collective Whistling in the Theatre and the Perth independent company Last Seen Imagining. He is the artistic director of Night Train Productions.
Require Import UniMath.Foundations.All. Require Import UniMath.MoreFoundations.All. Require Import UniMath.CategoryTheory.Core.Categories. Require Import UniMath.CategoryTheory.Core.Functors. Require Import UniMath.CategoryTheory.Core.NaturalTransformations. Require Import UniMath.CategoryTheory.Core.Isos. Require Import UniMath.CategoryTheory.Monoidal.WhiskeredBifunctors. Require Import UniMath.CategoryTheory.Monoidal.Categories. Require Import UniMath.CategoryTheory.EnrichedCats.Enriched.Enriched. Local Open Scope cat. Local Open Scope moncat. Import MonoidalNotations. Section Opposite. Context {Mon_V : monoidal_cat}. Definition opposite_enriched_precat (A : enriched_precat Mon_V) : enriched_precat (_ ,, monoidal_swapped Mon_V). Proof. use make_enriched_precat. - use make_enriched_precat_data. + exact A. + intros x y. exact (enriched_cat_mor y x). + intro x. simpl. exact (enriched_cat_identity x). + intros x y z. exact (enriched_cat_comp z y x). - split; simpl in a, b; simpl. + refine (_ @ enriched_id_right b a). apply maponpaths_2. unfold monoidal_cat_tensor_mor. unfold functoronmorphisms1. cbn. rewrite whiskerscommutes ; [ apply idpath | ]. apply (pr2 Mon_V). + refine (_ @ enriched_id_left b a). apply maponpaths_2. unfold monoidal_cat_tensor_mor. unfold functoronmorphisms1. cbn. rewrite whiskerscommutes ; [ apply idpath | ]. apply (pr2 Mon_V). - intros a b c d ; cbn. refine (!(id_left _) @ _). etrans. { apply maponpaths_2. exact (!(mon_rassociator_lassociator _ _ _)). } rewrite !assoc'. apply maponpaths. refine (_ @ !(enriched_assoc d c b a) @ _). + apply maponpaths. apply maponpaths_2. unfold monoidal_cat_tensor_mor. unfold functoronmorphisms1. cbn. rewrite whiskerscommutes ; [ apply idpath | ]. apply (pr2 Mon_V). + apply maponpaths_2. unfold monoidal_cat_tensor_mor. unfold functoronmorphisms1. cbn. rewrite whiskerscommutes ; [ apply idpath | ]. apply (pr2 Mon_V). Defined. Definition opposite_enriched_functor {A B : enriched_precat Mon_V} (F : enriched_functor A B) : enriched_functor (opposite_enriched_precat A) (opposite_enriched_precat B). Proof. use make_enriched_functor. - use make_enriched_functor_data. + intro x. exact (F x). + intros x y. exact (enriched_functor_on_morphisms F y x). - intro x. cbn. apply enriched_functor_on_identity. - intros x y z. cbn. refine (enriched_functor_on_comp F z y x @ _). apply maponpaths_2. unfold monoidal_cat_tensor_mor. unfold functoronmorphisms1. cbn. rewrite whiskerscommutes ; [ apply idpath | ]. apply (pr2 Mon_V). Defined. (* note the direction *) Definition opposite_enriched_nat_trans {A B : enriched_precat Mon_V} {F G : enriched_functor A B} (a : enriched_nat_trans F G) : enriched_nat_trans (opposite_enriched_functor G) (opposite_enriched_functor F). Proof. use make_enriched_nat_trans. - intro x. exact (a x). - intros x y. cbn. apply pathsinv0. refine (_ @ enriched_nat_trans_ax a y x @ _). + apply maponpaths. unfold precompose_underlying_morphism, postcompose_underlying_morphism. unfold monoidal_cat_tensor_mor. unfold functoronmorphisms1. cbn. rewrite <- whiskerscommutes ; [ apply idpath | ]. apply (pr2 Mon_V). + apply maponpaths. unfold precompose_underlying_morphism, postcompose_underlying_morphism. unfold monoidal_cat_tensor_mor. unfold functoronmorphisms1. cbn. rewrite <- whiskerscommutes ; [ apply idpath | ]. apply (pr2 Mon_V). Defined. End Opposite.
[GOAL] C : Type u_1 inst✝¹ : Category.{u_2, u_1} C inst✝ : Preadditive C X : SimplicialObject C q n : ℕ hqn : n ≤ q ⊢ HomologicalComplex.Hom.f (P (q + 1)) n = HomologicalComplex.Hom.f (P q) n [PROOFSTEP] rcases n with (_ | n) [GOAL] case zero C : Type u_1 inst✝¹ : Category.{u_2, u_1} C inst✝ : Preadditive C X : SimplicialObject C q : ℕ hqn : Nat.zero ≤ q ⊢ HomologicalComplex.Hom.f (P (q + 1)) Nat.zero = HomologicalComplex.Hom.f (P q) Nat.zero [PROOFSTEP] simp only [Nat.zero_eq, P_f_0_eq] [GOAL] case succ C : Type u_1 inst✝¹ : Category.{u_2, u_1} C inst✝ : Preadditive C X : SimplicialObject C q n : ℕ hqn : Nat.succ n ≤ q ⊢ HomologicalComplex.Hom.f (P (q + 1)) (Nat.succ n) = HomologicalComplex.Hom.f (P q) (Nat.succ n) [PROOFSTEP] simp only [P_succ, add_right_eq_self, comp_add, HomologicalComplex.comp_f, HomologicalComplex.add_f_apply, comp_id] [GOAL] case succ C : Type u_1 inst✝¹ : Category.{u_2, u_1} C inst✝ : Preadditive C X : SimplicialObject C q n : ℕ hqn : Nat.succ n ≤ q ⊢ HomologicalComplex.Hom.f (P q) (Nat.succ n) ≫ HomologicalComplex.Hom.f (Hσ q) (Nat.succ n) = 0 [PROOFSTEP] exact (HigherFacesVanish.of_P q n).comp_Hσ_eq_zero (Nat.succ_le_iff.mp hqn) [GOAL] C : Type u_1 inst✝¹ : Category.{u_2, u_1} C inst✝ : Preadditive C X : SimplicialObject C q n : ℕ hqn : n ≤ q ⊢ HomologicalComplex.Hom.f (Q (q + 1)) n = HomologicalComplex.Hom.f (Q q) n [PROOFSTEP] simp only [Q, HomologicalComplex.sub_f_apply, P_is_eventually_constant hqn] [GOAL] C : Type u_1 inst✝¹ : Category.{?u.41303, u_1} C inst✝ : Preadditive C X : SimplicialObject C n : ℕ ⊢ (fun n => HomologicalComplex.Hom.f (P n) n) (n + 1) ≫ AlternatingFaceMapComplex.objD X n = AlternatingFaceMapComplex.objD X n ≫ (fun n => HomologicalComplex.Hom.f (P n) n) n [PROOFSTEP] simpa only [← P_is_eventually_constant (show n ≤ n by rfl), AlternatingFaceMapComplex.obj_d_eq] using (P (n + 1) : K[X] ⟶ _).comm (n + 1) n [GOAL] C : Type u_1 inst✝¹ : Category.{?u.41303, u_1} C inst✝ : Preadditive C X : SimplicialObject C n : ℕ ⊢ n ≤ n [PROOFSTEP] rfl [GOAL] C : Type u_1 inst✝¹ : Category.{u_2, u_1} C inst✝ : Preadditive C X : SimplicialObject C ⊢ HomologicalComplex.Hom.f QInfty 0 = 0 [PROOFSTEP] dsimp [QInfty] [GOAL] C : Type u_1 inst✝¹ : Category.{u_2, u_1} C inst✝ : Preadditive C X : SimplicialObject C ⊢ 𝟙 (X.obj (op [0])) - 𝟙 (X.obj (op [0])) = 0 [PROOFSTEP] simp only [sub_self] [GOAL] C : Type u_1 inst✝¹ : Category.{u_2, u_1} C inst✝ : Preadditive C X : SimplicialObject C n : ℕ ⊢ HomologicalComplex.Hom.f PInfty n ≫ HomologicalComplex.Hom.f PInfty n = HomologicalComplex.Hom.f PInfty n [PROOFSTEP] simp only [PInfty_f, P_f_idem] [GOAL] C : Type u_1 inst✝¹ : Category.{u_2, u_1} C inst✝ : Preadditive C X : SimplicialObject C ⊢ PInfty ≫ PInfty = PInfty [PROOFSTEP] ext n [GOAL] case h C : Type u_1 inst✝¹ : Category.{u_2, u_1} C inst✝ : Preadditive C X : SimplicialObject C n : ℕ ⊢ HomologicalComplex.Hom.f (PInfty ≫ PInfty) n = HomologicalComplex.Hom.f PInfty n [PROOFSTEP] exact PInfty_f_idem n [GOAL] C : Type u_1 inst✝¹ : Category.{u_2, u_1} C inst✝ : Preadditive C X : SimplicialObject C ⊢ QInfty ≫ QInfty = QInfty [PROOFSTEP] ext n [GOAL] case h C : Type u_1 inst✝¹ : Category.{u_2, u_1} C inst✝ : Preadditive C X : SimplicialObject C n : ℕ ⊢ HomologicalComplex.Hom.f (QInfty ≫ QInfty) n = HomologicalComplex.Hom.f QInfty n [PROOFSTEP] exact QInfty_f_idem n [GOAL] C : Type u_1 inst✝¹ : Category.{u_2, u_1} C inst✝ : Preadditive C X : SimplicialObject C n : ℕ ⊢ HomologicalComplex.Hom.f PInfty n ≫ HomologicalComplex.Hom.f QInfty n = 0 [PROOFSTEP] dsimp only [QInfty] [GOAL] C : Type u_1 inst✝¹ : Category.{u_2, u_1} C inst✝ : Preadditive C X : SimplicialObject C n : ℕ ⊢ HomologicalComplex.Hom.f PInfty n ≫ HomologicalComplex.Hom.f (𝟙 K[X] - PInfty) n = 0 [PROOFSTEP] simp only [HomologicalComplex.sub_f_apply, HomologicalComplex.id_f, comp_sub, comp_id, PInfty_f_idem, sub_self] [GOAL] C : Type u_1 inst✝¹ : Category.{u_2, u_1} C inst✝ : Preadditive C X : SimplicialObject C ⊢ PInfty ≫ QInfty = 0 [PROOFSTEP] ext n [GOAL] case h C : Type u_1 inst✝¹ : Category.{u_2, u_1} C inst✝ : Preadditive C X : SimplicialObject C n : ℕ ⊢ HomologicalComplex.Hom.f (PInfty ≫ QInfty) n = HomologicalComplex.Hom.f 0 n [PROOFSTEP] apply PInfty_f_comp_QInfty_f [GOAL] C : Type u_1 inst✝¹ : Category.{u_2, u_1} C inst✝ : Preadditive C X : SimplicialObject C n : ℕ ⊢ HomologicalComplex.Hom.f QInfty n ≫ HomologicalComplex.Hom.f PInfty n = 0 [PROOFSTEP] dsimp only [QInfty] [GOAL] C : Type u_1 inst✝¹ : Category.{u_2, u_1} C inst✝ : Preadditive C X : SimplicialObject C n : ℕ ⊢ HomologicalComplex.Hom.f (𝟙 K[X] - PInfty) n ≫ HomologicalComplex.Hom.f PInfty n = 0 [PROOFSTEP] simp only [HomologicalComplex.sub_f_apply, HomologicalComplex.id_f, sub_comp, id_comp, PInfty_f_idem, sub_self] [GOAL] C : Type u_1 inst✝¹ : Category.{u_2, u_1} C inst✝ : Preadditive C X : SimplicialObject C ⊢ QInfty ≫ PInfty = 0 [PROOFSTEP] ext n [GOAL] case h C : Type u_1 inst✝¹ : Category.{u_2, u_1} C inst✝ : Preadditive C X : SimplicialObject C n : ℕ ⊢ HomologicalComplex.Hom.f (QInfty ≫ PInfty) n = HomologicalComplex.Hom.f 0 n [PROOFSTEP] apply QInfty_f_comp_PInfty_f [GOAL] C : Type u_1 inst✝¹ : Category.{u_2, u_1} C inst✝ : Preadditive C X : SimplicialObject C ⊢ PInfty + QInfty = 𝟙 K[X] [PROOFSTEP] dsimp only [QInfty] [GOAL] C : Type u_1 inst✝¹ : Category.{u_2, u_1} C inst✝ : Preadditive C X : SimplicialObject C ⊢ PInfty + (𝟙 K[X] - PInfty) = 𝟙 K[X] [PROOFSTEP] simp only [add_sub_cancel'_right] [GOAL] C : Type u_1 inst✝¹ : Category.{?u.354986, u_1} C inst✝ : Preadditive C X✝ X Y : SimplicialObject C f : X ⟶ Y ⊢ (alternatingFaceMapComplex C).map f ≫ (fun x => PInfty) Y = (fun x => PInfty) X ≫ (alternatingFaceMapComplex C).map f [PROOFSTEP] ext n [GOAL] case h C : Type u_1 inst✝¹ : Category.{?u.354986, u_1} C inst✝ : Preadditive C X✝ X Y : SimplicialObject C f : X ⟶ Y n : ℕ ⊢ HomologicalComplex.Hom.f ((alternatingFaceMapComplex C).map f ≫ (fun x => PInfty) Y) n = HomologicalComplex.Hom.f ((fun x => PInfty) X ≫ (alternatingFaceMapComplex C).map f) n [PROOFSTEP] exact PInfty_f_naturality n f [GOAL] C : Type u_1 inst✝⁴ : Category.{u_4, u_1} C inst✝³ : Preadditive C X✝ : SimplicialObject C D : Type u_2 inst✝² : Category.{u_3, u_2} D inst✝¹ : Preadditive D G : C ⥤ D inst✝ : Functor.Additive G X : SimplicialObject C n : ℕ ⊢ HomologicalComplex.Hom.f PInfty n = G.map (HomologicalComplex.Hom.f PInfty n) [PROOFSTEP] simp only [PInfty_f, map_P] [GOAL] C : Type u_1 inst✝¹ : Category.{u_2, u_1} C inst✝ : Preadditive C X : SimplicialObject C Y : Karoubi (SimplicialObject C) n : ℕ ⊢ (HomologicalComplex.Hom.f PInfty n).f = NatTrans.app Y.p (op [n]) ≫ HomologicalComplex.Hom.f PInfty n [PROOFSTEP] let Y₁ := (karoubiFunctorCategoryEmbedding _ _).obj Y [GOAL] C : Type u_1 inst✝¹ : Category.{u_2, u_1} C inst✝ : Preadditive C X : SimplicialObject C Y : Karoubi (SimplicialObject C) n : ℕ Y₁ : SimplexCategoryᵒᵖ ⥤ Karoubi C := (karoubiFunctorCategoryEmbedding SimplexCategoryᵒᵖ C).obj Y ⊢ (HomologicalComplex.Hom.f PInfty n).f = NatTrans.app Y.p (op [n]) ≫ HomologicalComplex.Hom.f PInfty n [PROOFSTEP] let Y₂ := Y.X [GOAL] C : Type u_1 inst✝¹ : Category.{u_2, u_1} C inst✝ : Preadditive C X : SimplicialObject C Y : Karoubi (SimplicialObject C) n : ℕ Y₁ : SimplexCategoryᵒᵖ ⥤ Karoubi C := (karoubiFunctorCategoryEmbedding SimplexCategoryᵒᵖ C).obj Y Y₂ : SimplicialObject C := Y.X ⊢ (HomologicalComplex.Hom.f PInfty n).f = NatTrans.app Y.p (op [n]) ≫ HomologicalComplex.Hom.f PInfty n [PROOFSTEP] let Y₃ := ((whiskering _ _).obj (toKaroubi C)).obj Y.X [GOAL] C : Type u_1 inst✝¹ : Category.{u_2, u_1} C inst✝ : Preadditive C X : SimplicialObject C Y : Karoubi (SimplicialObject C) n : ℕ Y₁ : SimplexCategoryᵒᵖ ⥤ Karoubi C := (karoubiFunctorCategoryEmbedding SimplexCategoryᵒᵖ C).obj Y Y₂ : SimplicialObject C := Y.X Y₃ : SimplicialObject (Karoubi C) := ((whiskering C (Karoubi C)).obj (toKaroubi C)).obj Y.X ⊢ (HomologicalComplex.Hom.f PInfty n).f = NatTrans.app Y.p (op [n]) ≫ HomologicalComplex.Hom.f PInfty n [PROOFSTEP] let Y₄ := (karoubiFunctorCategoryEmbedding _ _).obj ((toKaroubi _).obj Y.X) [GOAL] C : Type u_1 inst✝¹ : Category.{u_2, u_1} C inst✝ : Preadditive C X : SimplicialObject C Y : Karoubi (SimplicialObject C) n : ℕ Y₁ : SimplexCategoryᵒᵖ ⥤ Karoubi C := (karoubiFunctorCategoryEmbedding SimplexCategoryᵒᵖ C).obj Y Y₂ : SimplicialObject C := Y.X Y₃ : SimplicialObject (Karoubi C) := ((whiskering C (Karoubi C)).obj (toKaroubi C)).obj Y.X Y₄ : SimplexCategoryᵒᵖ ⥤ Karoubi C := (karoubiFunctorCategoryEmbedding SimplexCategoryᵒᵖ C).obj ((toKaroubi (SimplexCategoryᵒᵖ ⥤ C)).obj Y.X) ⊢ (HomologicalComplex.Hom.f PInfty n).f = NatTrans.app Y.p (op [n]) ≫ HomologicalComplex.Hom.f PInfty n [PROOFSTEP] let P₁ : K[Y₁] ⟶ _ := PInfty [GOAL] C : Type u_1 inst✝¹ : Category.{u_2, u_1} C inst✝ : Preadditive C X : SimplicialObject C Y : Karoubi (SimplicialObject C) n : ℕ Y₁ : SimplexCategoryᵒᵖ ⥤ Karoubi C := (karoubiFunctorCategoryEmbedding SimplexCategoryᵒᵖ C).obj Y Y₂ : SimplicialObject C := Y.X Y₃ : SimplicialObject (Karoubi C) := ((whiskering C (Karoubi C)).obj (toKaroubi C)).obj Y.X Y₄ : SimplexCategoryᵒᵖ ⥤ Karoubi C := (karoubiFunctorCategoryEmbedding SimplexCategoryᵒᵖ C).obj ((toKaroubi (SimplexCategoryᵒᵖ ⥤ C)).obj Y.X) P₁ : K[Y₁] ⟶ K[Y₁] := PInfty ⊢ (HomologicalComplex.Hom.f PInfty n).f = NatTrans.app Y.p (op [n]) ≫ HomologicalComplex.Hom.f PInfty n [PROOFSTEP] let P₂ : K[Y₂] ⟶ _ := PInfty [GOAL] C : Type u_1 inst✝¹ : Category.{u_2, u_1} C inst✝ : Preadditive C X : SimplicialObject C Y : Karoubi (SimplicialObject C) n : ℕ Y₁ : SimplexCategoryᵒᵖ ⥤ Karoubi C := (karoubiFunctorCategoryEmbedding SimplexCategoryᵒᵖ C).obj Y Y₂ : SimplicialObject C := Y.X Y₃ : SimplicialObject (Karoubi C) := ((whiskering C (Karoubi C)).obj (toKaroubi C)).obj Y.X Y₄ : SimplexCategoryᵒᵖ ⥤ Karoubi C := (karoubiFunctorCategoryEmbedding SimplexCategoryᵒᵖ C).obj ((toKaroubi (SimplexCategoryᵒᵖ ⥤ C)).obj Y.X) P₁ : K[Y₁] ⟶ K[Y₁] := PInfty P₂ : K[Y₂] ⟶ K[Y₂] := PInfty ⊢ (HomologicalComplex.Hom.f PInfty n).f = NatTrans.app Y.p (op [n]) ≫ HomologicalComplex.Hom.f PInfty n [PROOFSTEP] let P₃ : K[Y₃] ⟶ _ := PInfty [GOAL] C : Type u_1 inst✝¹ : Category.{u_2, u_1} C inst✝ : Preadditive C X : SimplicialObject C Y : Karoubi (SimplicialObject C) n : ℕ Y₁ : SimplexCategoryᵒᵖ ⥤ Karoubi C := (karoubiFunctorCategoryEmbedding SimplexCategoryᵒᵖ C).obj Y Y₂ : SimplicialObject C := Y.X Y₃ : SimplicialObject (Karoubi C) := ((whiskering C (Karoubi C)).obj (toKaroubi C)).obj Y.X Y₄ : SimplexCategoryᵒᵖ ⥤ Karoubi C := (karoubiFunctorCategoryEmbedding SimplexCategoryᵒᵖ C).obj ((toKaroubi (SimplexCategoryᵒᵖ ⥤ C)).obj Y.X) P₁ : K[Y₁] ⟶ K[Y₁] := PInfty P₂ : K[Y₂] ⟶ K[Y₂] := PInfty P₃ : K[Y₃] ⟶ K[Y₃] := PInfty ⊢ (HomologicalComplex.Hom.f PInfty n).f = NatTrans.app Y.p (op [n]) ≫ HomologicalComplex.Hom.f PInfty n [PROOFSTEP] let P₄ : K[Y₄] ⟶ _ := PInfty [GOAL] C : Type u_1 inst✝¹ : Category.{u_2, u_1} C inst✝ : Preadditive C X : SimplicialObject C Y : Karoubi (SimplicialObject C) n : ℕ Y₁ : SimplexCategoryᵒᵖ ⥤ Karoubi C := (karoubiFunctorCategoryEmbedding SimplexCategoryᵒᵖ C).obj Y Y₂ : SimplicialObject C := Y.X Y₃ : SimplicialObject (Karoubi C) := ((whiskering C (Karoubi C)).obj (toKaroubi C)).obj Y.X Y₄ : SimplexCategoryᵒᵖ ⥤ Karoubi C := (karoubiFunctorCategoryEmbedding SimplexCategoryᵒᵖ C).obj ((toKaroubi (SimplexCategoryᵒᵖ ⥤ C)).obj Y.X) P₁ : K[Y₁] ⟶ K[Y₁] := PInfty P₂ : K[Y₂] ⟶ K[Y₂] := PInfty P₃ : K[Y₃] ⟶ K[Y₃] := PInfty P₄ : K[Y₄] ⟶ K[Y₄] := PInfty ⊢ (HomologicalComplex.Hom.f PInfty n).f = NatTrans.app Y.p (op [n]) ≫ HomologicalComplex.Hom.f PInfty n [PROOFSTEP] change (P₁.f n).f = Y.p.app (op [n]) ≫ P₂.f n [GOAL] C : Type u_1 inst✝¹ : Category.{u_2, u_1} C inst✝ : Preadditive C X : SimplicialObject C Y : Karoubi (SimplicialObject C) n : ℕ Y₁ : SimplexCategoryᵒᵖ ⥤ Karoubi C := (karoubiFunctorCategoryEmbedding SimplexCategoryᵒᵖ C).obj Y Y₂ : SimplicialObject C := Y.X Y₃ : SimplicialObject (Karoubi C) := ((whiskering C (Karoubi C)).obj (toKaroubi C)).obj Y.X Y₄ : SimplexCategoryᵒᵖ ⥤ Karoubi C := (karoubiFunctorCategoryEmbedding SimplexCategoryᵒᵖ C).obj ((toKaroubi (SimplexCategoryᵒᵖ ⥤ C)).obj Y.X) P₁ : K[Y₁] ⟶ K[Y₁] := PInfty P₂ : K[Y₂] ⟶ K[Y₂] := PInfty P₃ : K[Y₃] ⟶ K[Y₃] := PInfty P₄ : K[Y₄] ⟶ K[Y₄] := PInfty ⊢ (HomologicalComplex.Hom.f P₁ n).f = NatTrans.app Y.p (op [n]) ≫ HomologicalComplex.Hom.f P₂ n [PROOFSTEP] have h₃₂ : (P₃.f n).f = P₂.f n := Karoubi.hom_ext_iff.mp (map_PInfty_f (toKaroubi C) Y₂ n) [GOAL] C : Type u_1 inst✝¹ : Category.{u_2, u_1} C inst✝ : Preadditive C X : SimplicialObject C Y : Karoubi (SimplicialObject C) n : ℕ Y₁ : SimplexCategoryᵒᵖ ⥤ Karoubi C := (karoubiFunctorCategoryEmbedding SimplexCategoryᵒᵖ C).obj Y Y₂ : SimplicialObject C := Y.X Y₃ : SimplicialObject (Karoubi C) := ((whiskering C (Karoubi C)).obj (toKaroubi C)).obj Y.X Y₄ : SimplexCategoryᵒᵖ ⥤ Karoubi C := (karoubiFunctorCategoryEmbedding SimplexCategoryᵒᵖ C).obj ((toKaroubi (SimplexCategoryᵒᵖ ⥤ C)).obj Y.X) P₁ : K[Y₁] ⟶ K[Y₁] := PInfty P₂ : K[Y₂] ⟶ K[Y₂] := PInfty P₃ : K[Y₃] ⟶ K[Y₃] := PInfty P₄ : K[Y₄] ⟶ K[Y₄] := PInfty h₃₂ : (HomologicalComplex.Hom.f P₃ n).f = HomologicalComplex.Hom.f P₂ n ⊢ (HomologicalComplex.Hom.f P₁ n).f = NatTrans.app Y.p (op [n]) ≫ HomologicalComplex.Hom.f P₂ n [PROOFSTEP] have h₄₃ : P₄.f n = P₃.f n := by have h := Functor.congr_obj (toKaroubi_comp_karoubiFunctorCategoryEmbedding _ _) Y₂ simp only [← natTransPInfty_f_app] congr 1 [GOAL] C : Type u_1 inst✝¹ : Category.{u_2, u_1} C inst✝ : Preadditive C X : SimplicialObject C Y : Karoubi (SimplicialObject C) n : ℕ Y₁ : SimplexCategoryᵒᵖ ⥤ Karoubi C := (karoubiFunctorCategoryEmbedding SimplexCategoryᵒᵖ C).obj Y Y₂ : SimplicialObject C := Y.X Y₃ : SimplicialObject (Karoubi C) := ((whiskering C (Karoubi C)).obj (toKaroubi C)).obj Y.X Y₄ : SimplexCategoryᵒᵖ ⥤ Karoubi C := (karoubiFunctorCategoryEmbedding SimplexCategoryᵒᵖ C).obj ((toKaroubi (SimplexCategoryᵒᵖ ⥤ C)).obj Y.X) P₁ : K[Y₁] ⟶ K[Y₁] := PInfty P₂ : K[Y₂] ⟶ K[Y₂] := PInfty P₃ : K[Y₃] ⟶ K[Y₃] := PInfty P₄ : K[Y₄] ⟶ K[Y₄] := PInfty h₃₂ : (HomologicalComplex.Hom.f P₃ n).f = HomologicalComplex.Hom.f P₂ n ⊢ HomologicalComplex.Hom.f P₄ n = HomologicalComplex.Hom.f P₃ n [PROOFSTEP] have h := Functor.congr_obj (toKaroubi_comp_karoubiFunctorCategoryEmbedding _ _) Y₂ [GOAL] C : Type u_1 inst✝¹ : Category.{u_2, u_1} C inst✝ : Preadditive C X : SimplicialObject C Y : Karoubi (SimplicialObject C) n : ℕ Y₁ : SimplexCategoryᵒᵖ ⥤ Karoubi C := (karoubiFunctorCategoryEmbedding SimplexCategoryᵒᵖ C).obj Y Y₂ : SimplicialObject C := Y.X Y₃ : SimplicialObject (Karoubi C) := ((whiskering C (Karoubi C)).obj (toKaroubi C)).obj Y.X Y₄ : SimplexCategoryᵒᵖ ⥤ Karoubi C := (karoubiFunctorCategoryEmbedding SimplexCategoryᵒᵖ C).obj ((toKaroubi (SimplexCategoryᵒᵖ ⥤ C)).obj Y.X) P₁ : K[Y₁] ⟶ K[Y₁] := PInfty P₂ : K[Y₂] ⟶ K[Y₂] := PInfty P₃ : K[Y₃] ⟶ K[Y₃] := PInfty P₄ : K[Y₄] ⟶ K[Y₄] := PInfty h₃₂ : (HomologicalComplex.Hom.f P₃ n).f = HomologicalComplex.Hom.f P₂ n h : (toKaroubi (SimplexCategoryᵒᵖ ⥤ C) ⋙ karoubiFunctorCategoryEmbedding SimplexCategoryᵒᵖ C).obj Y₂ = ((whiskeringRight SimplexCategoryᵒᵖ C (Karoubi C)).obj (toKaroubi C)).obj Y₂ ⊢ HomologicalComplex.Hom.f P₄ n = HomologicalComplex.Hom.f P₃ n [PROOFSTEP] simp only [← natTransPInfty_f_app] [GOAL] C : Type u_1 inst✝¹ : Category.{u_2, u_1} C inst✝ : Preadditive C X : SimplicialObject C Y : Karoubi (SimplicialObject C) n : ℕ Y₁ : SimplexCategoryᵒᵖ ⥤ Karoubi C := (karoubiFunctorCategoryEmbedding SimplexCategoryᵒᵖ C).obj Y Y₂ : SimplicialObject C := Y.X Y₃ : SimplicialObject (Karoubi C) := ((whiskering C (Karoubi C)).obj (toKaroubi C)).obj Y.X Y₄ : SimplexCategoryᵒᵖ ⥤ Karoubi C := (karoubiFunctorCategoryEmbedding SimplexCategoryᵒᵖ C).obj ((toKaroubi (SimplexCategoryᵒᵖ ⥤ C)).obj Y.X) P₁ : K[Y₁] ⟶ K[Y₁] := PInfty P₂ : K[Y₂] ⟶ K[Y₂] := PInfty P₃ : K[Y₃] ⟶ K[Y₃] := PInfty P₄ : K[Y₄] ⟶ K[Y₄] := PInfty h₃₂ : (HomologicalComplex.Hom.f P₃ n).f = HomologicalComplex.Hom.f P₂ n h : (toKaroubi (SimplexCategoryᵒᵖ ⥤ C) ⋙ karoubiFunctorCategoryEmbedding SimplexCategoryᵒᵖ C).obj Y₂ = ((whiskeringRight SimplexCategoryᵒᵖ C (Karoubi C)).obj (toKaroubi C)).obj Y₂ ⊢ NatTrans.app (natTransPInfty_f (Karoubi C) n) ((karoubiFunctorCategoryEmbedding SimplexCategoryᵒᵖ C).obj ((toKaroubi (SimplexCategoryᵒᵖ ⥤ C)).obj Y.X)) = NatTrans.app (natTransPInfty_f (Karoubi C) n) (((whiskering C (Karoubi C)).obj (toKaroubi C)).obj Y.X) [PROOFSTEP] congr 1 [GOAL] C : Type u_1 inst✝¹ : Category.{u_2, u_1} C inst✝ : Preadditive C X : SimplicialObject C Y : Karoubi (SimplicialObject C) n : ℕ Y₁ : SimplexCategoryᵒᵖ ⥤ Karoubi C := (karoubiFunctorCategoryEmbedding SimplexCategoryᵒᵖ C).obj Y Y₂ : SimplicialObject C := Y.X Y₃ : SimplicialObject (Karoubi C) := ((whiskering C (Karoubi C)).obj (toKaroubi C)).obj Y.X Y₄ : SimplexCategoryᵒᵖ ⥤ Karoubi C := (karoubiFunctorCategoryEmbedding SimplexCategoryᵒᵖ C).obj ((toKaroubi (SimplexCategoryᵒᵖ ⥤ C)).obj Y.X) P₁ : K[Y₁] ⟶ K[Y₁] := PInfty P₂ : K[Y₂] ⟶ K[Y₂] := PInfty P₃ : K[Y₃] ⟶ K[Y₃] := PInfty P₄ : K[Y₄] ⟶ K[Y₄] := PInfty h₃₂ : (HomologicalComplex.Hom.f P₃ n).f = HomologicalComplex.Hom.f P₂ n h₄₃ : HomologicalComplex.Hom.f P₄ n = HomologicalComplex.Hom.f P₃ n ⊢ (HomologicalComplex.Hom.f P₁ n).f = NatTrans.app Y.p (op [n]) ≫ HomologicalComplex.Hom.f P₂ n [PROOFSTEP] have h₁₄ := Idempotents.natTrans_eq ((𝟙 (karoubiFunctorCategoryEmbedding SimplexCategoryᵒᵖ C)) ◫ (natTransPInfty_f (Karoubi C) n)) Y [GOAL] C : Type u_1 inst✝¹ : Category.{u_2, u_1} C inst✝ : Preadditive C X : SimplicialObject C Y : Karoubi (SimplicialObject C) n : ℕ Y₁ : SimplexCategoryᵒᵖ ⥤ Karoubi C := (karoubiFunctorCategoryEmbedding SimplexCategoryᵒᵖ C).obj Y Y₂ : SimplicialObject C := Y.X Y₃ : SimplicialObject (Karoubi C) := ((whiskering C (Karoubi C)).obj (toKaroubi C)).obj Y.X Y₄ : SimplexCategoryᵒᵖ ⥤ Karoubi C := (karoubiFunctorCategoryEmbedding SimplexCategoryᵒᵖ C).obj ((toKaroubi (SimplexCategoryᵒᵖ ⥤ C)).obj Y.X) P₁ : K[Y₁] ⟶ K[Y₁] := PInfty P₂ : K[Y₂] ⟶ K[Y₂] := PInfty P₃ : K[Y₃] ⟶ K[Y₃] := PInfty P₄ : K[Y₄] ⟶ K[Y₄] := PInfty h₃₂ : (HomologicalComplex.Hom.f P₃ n).f = HomologicalComplex.Hom.f P₂ n h₄₃ : HomologicalComplex.Hom.f P₄ n = HomologicalComplex.Hom.f P₃ n h₁₄ : NatTrans.app (𝟙 (karoubiFunctorCategoryEmbedding SimplexCategoryᵒᵖ C) ◫ natTransPInfty_f (Karoubi C) n) Y = (karoubiFunctorCategoryEmbedding SimplexCategoryᵒᵖ C ⋙ alternatingFaceMapComplex (Karoubi C) ⋙ HomologicalComplex.eval (Karoubi C) (ComplexShape.down ℕ) n).map (Karoubi.decompId_i Y) ≫ NatTrans.app (𝟙 (karoubiFunctorCategoryEmbedding SimplexCategoryᵒᵖ C) ◫ natTransPInfty_f (Karoubi C) n) (Karoubi.mk Y.X (𝟙 Y.X)) ≫ (karoubiFunctorCategoryEmbedding SimplexCategoryᵒᵖ C ⋙ alternatingFaceMapComplex (Karoubi C) ⋙ HomologicalComplex.eval (Karoubi C) (ComplexShape.down ℕ) n).map (Karoubi.decompId_p Y) ⊢ (HomologicalComplex.Hom.f P₁ n).f = NatTrans.app Y.p (op [n]) ≫ HomologicalComplex.Hom.f P₂ n [PROOFSTEP] dsimp [natTransPInfty_f] at h₁₄ [GOAL] C : Type u_1 inst✝¹ : Category.{u_2, u_1} C inst✝ : Preadditive C X : SimplicialObject C Y : Karoubi (SimplicialObject C) n : ℕ Y₁ : SimplexCategoryᵒᵖ ⥤ Karoubi C := (karoubiFunctorCategoryEmbedding SimplexCategoryᵒᵖ C).obj Y Y₂ : SimplicialObject C := Y.X Y₃ : SimplicialObject (Karoubi C) := ((whiskering C (Karoubi C)).obj (toKaroubi C)).obj Y.X Y₄ : SimplexCategoryᵒᵖ ⥤ Karoubi C := (karoubiFunctorCategoryEmbedding SimplexCategoryᵒᵖ C).obj ((toKaroubi (SimplexCategoryᵒᵖ ⥤ C)).obj Y.X) P₁ : K[Y₁] ⟶ K[Y₁] := PInfty P₂ : K[Y₂] ⟶ K[Y₂] := PInfty P₃ : K[Y₃] ⟶ K[Y₃] := PInfty P₄ : K[Y₄] ⟶ K[Y₄] := PInfty h₃₂ : (HomologicalComplex.Hom.f P₃ n).f = HomologicalComplex.Hom.f P₂ n h₄₃ : HomologicalComplex.Hom.f P₄ n = HomologicalComplex.Hom.f P₃ n h₁₄ : (Karoubi.Hom.mk (NatTrans.app Y.p (op [n])) ≫ HomologicalComplex.Hom.f PInfty n) ≫ Karoubi.Hom.mk (NatTrans.app Y.p (op [n])) = NatTrans.app (KaroubiFunctorCategoryEmbedding.map (Karoubi.decompId_i Y)) (op [n]) ≫ ((Karoubi.Hom.mk (𝟙 (Y.X.obj (op [n]))) ≫ HomologicalComplex.Hom.f PInfty n) ≫ Karoubi.Hom.mk (𝟙 (Y.X.obj (op [n])))) ≫ NatTrans.app (KaroubiFunctorCategoryEmbedding.map (Karoubi.decompId_p Y)) (op [n]) ⊢ (HomologicalComplex.Hom.f P₁ n).f = NatTrans.app Y.p (op [n]) ≫ HomologicalComplex.Hom.f P₂ n [PROOFSTEP] erw [id_comp, id_comp, comp_id, comp_id] at h₁₄ [GOAL] C : Type u_1 inst✝¹ : Category.{u_2, u_1} C inst✝ : Preadditive C X : SimplicialObject C Y : Karoubi (SimplicialObject C) n : ℕ Y₁ : SimplexCategoryᵒᵖ ⥤ Karoubi C := (karoubiFunctorCategoryEmbedding SimplexCategoryᵒᵖ C).obj Y Y₂ : SimplicialObject C := Y.X Y₃ : SimplicialObject (Karoubi C) := ((whiskering C (Karoubi C)).obj (toKaroubi C)).obj Y.X Y₄ : SimplexCategoryᵒᵖ ⥤ Karoubi C := (karoubiFunctorCategoryEmbedding SimplexCategoryᵒᵖ C).obj ((toKaroubi (SimplexCategoryᵒᵖ ⥤ C)).obj Y.X) P₁ : K[Y₁] ⟶ K[Y₁] := PInfty P₂ : K[Y₂] ⟶ K[Y₂] := PInfty P₃ : K[Y₃] ⟶ K[Y₃] := PInfty P₄ : K[Y₄] ⟶ K[Y₄] := PInfty h₃₂ : (HomologicalComplex.Hom.f P₃ n).f = HomologicalComplex.Hom.f P₂ n h₄₃ : HomologicalComplex.Hom.f P₄ n = HomologicalComplex.Hom.f P₃ n h₁₄ : HomologicalComplex.Hom.f PInfty n = NatTrans.app (KaroubiFunctorCategoryEmbedding.map (Karoubi.decompId_i Y)) (op [n]) ≫ HomologicalComplex.Hom.f PInfty n ≫ NatTrans.app (KaroubiFunctorCategoryEmbedding.map (Karoubi.decompId_p Y)) (op [n]) ⊢ (HomologicalComplex.Hom.f P₁ n).f = NatTrans.app Y.p (op [n]) ≫ HomologicalComplex.Hom.f P₂ n [PROOFSTEP] rw [← h₃₂, ← h₄₃, h₁₄] [GOAL] C : Type u_1 inst✝¹ : Category.{u_2, u_1} C inst✝ : Preadditive C X : SimplicialObject C Y : Karoubi (SimplicialObject C) n : ℕ Y₁ : SimplexCategoryᵒᵖ ⥤ Karoubi C := (karoubiFunctorCategoryEmbedding SimplexCategoryᵒᵖ C).obj Y Y₂ : SimplicialObject C := Y.X Y₃ : SimplicialObject (Karoubi C) := ((whiskering C (Karoubi C)).obj (toKaroubi C)).obj Y.X Y₄ : SimplexCategoryᵒᵖ ⥤ Karoubi C := (karoubiFunctorCategoryEmbedding SimplexCategoryᵒᵖ C).obj ((toKaroubi (SimplexCategoryᵒᵖ ⥤ C)).obj Y.X) P₁ : K[Y₁] ⟶ K[Y₁] := PInfty P₂ : K[Y₂] ⟶ K[Y₂] := PInfty P₃ : K[Y₃] ⟶ K[Y₃] := PInfty P₄ : K[Y₄] ⟶ K[Y₄] := PInfty h₃₂ : (HomologicalComplex.Hom.f P₃ n).f = HomologicalComplex.Hom.f P₂ n h₄₃ : HomologicalComplex.Hom.f P₄ n = HomologicalComplex.Hom.f P₃ n h₁₄ : HomologicalComplex.Hom.f PInfty n = NatTrans.app (KaroubiFunctorCategoryEmbedding.map (Karoubi.decompId_i Y)) (op [n]) ≫ HomologicalComplex.Hom.f PInfty n ≫ NatTrans.app (KaroubiFunctorCategoryEmbedding.map (Karoubi.decompId_p Y)) (op [n]) ⊢ (NatTrans.app (KaroubiFunctorCategoryEmbedding.map (Karoubi.decompId_i Y)) (op [n]) ≫ HomologicalComplex.Hom.f PInfty n ≫ NatTrans.app (KaroubiFunctorCategoryEmbedding.map (Karoubi.decompId_p Y)) (op [n])).f = NatTrans.app Y.p (op [n]) ≫ (HomologicalComplex.Hom.f P₄ n).f [PROOFSTEP] simp only [KaroubiFunctorCategoryEmbedding.map_app_f, Karoubi.decompId_p_f, Karoubi.decompId_i_f, Karoubi.comp_f] [GOAL] C : Type u_1 inst✝¹ : Category.{u_2, u_1} C inst✝ : Preadditive C X : SimplicialObject C Y : Karoubi (SimplicialObject C) n : ℕ Y₁ : SimplexCategoryᵒᵖ ⥤ Karoubi C := (karoubiFunctorCategoryEmbedding SimplexCategoryᵒᵖ C).obj Y Y₂ : SimplicialObject C := Y.X Y₃ : SimplicialObject (Karoubi C) := ((whiskering C (Karoubi C)).obj (toKaroubi C)).obj Y.X Y₄ : SimplexCategoryᵒᵖ ⥤ Karoubi C := (karoubiFunctorCategoryEmbedding SimplexCategoryᵒᵖ C).obj ((toKaroubi (SimplexCategoryᵒᵖ ⥤ C)).obj Y.X) P₁ : K[Y₁] ⟶ K[Y₁] := PInfty P₂ : K[Y₂] ⟶ K[Y₂] := PInfty P₃ : K[Y₃] ⟶ K[Y₃] := PInfty P₄ : K[Y₄] ⟶ K[Y₄] := PInfty h₃₂ : (HomologicalComplex.Hom.f P₃ n).f = HomologicalComplex.Hom.f P₂ n h₄₃ : HomologicalComplex.Hom.f P₄ n = HomologicalComplex.Hom.f P₃ n h₁₄ : HomologicalComplex.Hom.f PInfty n = NatTrans.app (KaroubiFunctorCategoryEmbedding.map (Karoubi.decompId_i Y)) (op [n]) ≫ HomologicalComplex.Hom.f PInfty n ≫ NatTrans.app (KaroubiFunctorCategoryEmbedding.map (Karoubi.decompId_p Y)) (op [n]) ⊢ NatTrans.app Y.p (op [n]) ≫ (HomologicalComplex.Hom.f PInfty n).f ≫ NatTrans.app Y.p (op [n]) = NatTrans.app Y.p (op [n]) ≫ (HomologicalComplex.Hom.f PInfty n).f [PROOFSTEP] let π : Y₄ ⟶ Y₄ := (toKaroubi _ ⋙ karoubiFunctorCategoryEmbedding _ _).map Y.p [GOAL] C : Type u_1 inst✝¹ : Category.{u_2, u_1} C inst✝ : Preadditive C X : SimplicialObject C Y : Karoubi (SimplicialObject C) n : ℕ Y₁ : SimplexCategoryᵒᵖ ⥤ Karoubi C := (karoubiFunctorCategoryEmbedding SimplexCategoryᵒᵖ C).obj Y Y₂ : SimplicialObject C := Y.X Y₃ : SimplicialObject (Karoubi C) := ((whiskering C (Karoubi C)).obj (toKaroubi C)).obj Y.X Y₄ : SimplexCategoryᵒᵖ ⥤ Karoubi C := (karoubiFunctorCategoryEmbedding SimplexCategoryᵒᵖ C).obj ((toKaroubi (SimplexCategoryᵒᵖ ⥤ C)).obj Y.X) P₁ : K[Y₁] ⟶ K[Y₁] := PInfty P₂ : K[Y₂] ⟶ K[Y₂] := PInfty P₃ : K[Y₃] ⟶ K[Y₃] := PInfty P₄ : K[Y₄] ⟶ K[Y₄] := PInfty h₃₂ : (HomologicalComplex.Hom.f P₃ n).f = HomologicalComplex.Hom.f P₂ n h₄₃ : HomologicalComplex.Hom.f P₄ n = HomologicalComplex.Hom.f P₃ n h₁₄ : HomologicalComplex.Hom.f PInfty n = NatTrans.app (KaroubiFunctorCategoryEmbedding.map (Karoubi.decompId_i Y)) (op [n]) ≫ HomologicalComplex.Hom.f PInfty n ≫ NatTrans.app (KaroubiFunctorCategoryEmbedding.map (Karoubi.decompId_p Y)) (op [n]) π : Y₄ ⟶ Y₄ := (toKaroubi (SimplexCategoryᵒᵖ ⥤ C) ⋙ karoubiFunctorCategoryEmbedding SimplexCategoryᵒᵖ C).map Y.p ⊢ NatTrans.app Y.p (op [n]) ≫ (HomologicalComplex.Hom.f PInfty n).f ≫ NatTrans.app Y.p (op [n]) = NatTrans.app Y.p (op [n]) ≫ (HomologicalComplex.Hom.f PInfty n).f [PROOFSTEP] have eq := Karoubi.hom_ext_iff.mp (PInfty_f_naturality n π) [GOAL] C : Type u_1 inst✝¹ : Category.{u_2, u_1} C inst✝ : Preadditive C X : SimplicialObject C Y : Karoubi (SimplicialObject C) n : ℕ Y₁ : SimplexCategoryᵒᵖ ⥤ Karoubi C := (karoubiFunctorCategoryEmbedding SimplexCategoryᵒᵖ C).obj Y Y₂ : SimplicialObject C := Y.X Y₃ : SimplicialObject (Karoubi C) := ((whiskering C (Karoubi C)).obj (toKaroubi C)).obj Y.X Y₄ : SimplexCategoryᵒᵖ ⥤ Karoubi C := (karoubiFunctorCategoryEmbedding SimplexCategoryᵒᵖ C).obj ((toKaroubi (SimplexCategoryᵒᵖ ⥤ C)).obj Y.X) P₁ : K[Y₁] ⟶ K[Y₁] := PInfty P₂ : K[Y₂] ⟶ K[Y₂] := PInfty P₃ : K[Y₃] ⟶ K[Y₃] := PInfty P₄ : K[Y₄] ⟶ K[Y₄] := PInfty h₃₂ : (HomologicalComplex.Hom.f P₃ n).f = HomologicalComplex.Hom.f P₂ n h₄₃ : HomologicalComplex.Hom.f P₄ n = HomologicalComplex.Hom.f P₃ n h₁₄ : HomologicalComplex.Hom.f PInfty n = NatTrans.app (KaroubiFunctorCategoryEmbedding.map (Karoubi.decompId_i Y)) (op [n]) ≫ HomologicalComplex.Hom.f PInfty n ≫ NatTrans.app (KaroubiFunctorCategoryEmbedding.map (Karoubi.decompId_p Y)) (op [n]) π : Y₄ ⟶ Y₄ := (toKaroubi (SimplexCategoryᵒᵖ ⥤ C) ⋙ karoubiFunctorCategoryEmbedding SimplexCategoryᵒᵖ C).map Y.p eq : (NatTrans.app π (op [n]) ≫ HomologicalComplex.Hom.f PInfty n).f = (HomologicalComplex.Hom.f PInfty n ≫ NatTrans.app π (op [n])).f ⊢ NatTrans.app Y.p (op [n]) ≫ (HomologicalComplex.Hom.f PInfty n).f ≫ NatTrans.app Y.p (op [n]) = NatTrans.app Y.p (op [n]) ≫ (HomologicalComplex.Hom.f PInfty n).f [PROOFSTEP] simp only [Karoubi.comp_f] at eq [GOAL] C : Type u_1 inst✝¹ : Category.{u_2, u_1} C inst✝ : Preadditive C X : SimplicialObject C Y : Karoubi (SimplicialObject C) n : ℕ Y₁ : SimplexCategoryᵒᵖ ⥤ Karoubi C := (karoubiFunctorCategoryEmbedding SimplexCategoryᵒᵖ C).obj Y Y₂ : SimplicialObject C := Y.X Y₃ : SimplicialObject (Karoubi C) := ((whiskering C (Karoubi C)).obj (toKaroubi C)).obj Y.X Y₄ : SimplexCategoryᵒᵖ ⥤ Karoubi C := (karoubiFunctorCategoryEmbedding SimplexCategoryᵒᵖ C).obj ((toKaroubi (SimplexCategoryᵒᵖ ⥤ C)).obj Y.X) P₁ : K[Y₁] ⟶ K[Y₁] := PInfty P₂ : K[Y₂] ⟶ K[Y₂] := PInfty P₃ : K[Y₃] ⟶ K[Y₃] := PInfty P₄ : K[Y₄] ⟶ K[Y₄] := PInfty h₃₂ : (HomologicalComplex.Hom.f P₃ n).f = HomologicalComplex.Hom.f P₂ n h₄₃ : HomologicalComplex.Hom.f P₄ n = HomologicalComplex.Hom.f P₃ n h₁₄ : HomologicalComplex.Hom.f PInfty n = NatTrans.app (KaroubiFunctorCategoryEmbedding.map (Karoubi.decompId_i Y)) (op [n]) ≫ HomologicalComplex.Hom.f PInfty n ≫ NatTrans.app (KaroubiFunctorCategoryEmbedding.map (Karoubi.decompId_p Y)) (op [n]) π : Y₄ ⟶ Y₄ := (toKaroubi (SimplexCategoryᵒᵖ ⥤ C) ⋙ karoubiFunctorCategoryEmbedding SimplexCategoryᵒᵖ C).map Y.p eq : (NatTrans.app ((toKaroubi (SimplexCategoryᵒᵖ ⥤ C) ⋙ karoubiFunctorCategoryEmbedding SimplexCategoryᵒᵖ C).map Y.p) (op [n])).f ≫ (HomologicalComplex.Hom.f PInfty n).f = (HomologicalComplex.Hom.f PInfty n).f ≫ (NatTrans.app ((toKaroubi (SimplexCategoryᵒᵖ ⥤ C) ⋙ karoubiFunctorCategoryEmbedding SimplexCategoryᵒᵖ C).map Y.p) (op [n])).f ⊢ NatTrans.app Y.p (op [n]) ≫ (HomologicalComplex.Hom.f PInfty n).f ≫ NatTrans.app Y.p (op [n]) = NatTrans.app Y.p (op [n]) ≫ (HomologicalComplex.Hom.f PInfty n).f [PROOFSTEP] dsimp at eq [GOAL] C : Type u_1 inst✝¹ : Category.{u_2, u_1} C inst✝ : Preadditive C X : SimplicialObject C Y : Karoubi (SimplicialObject C) n : ℕ Y₁ : SimplexCategoryᵒᵖ ⥤ Karoubi C := (karoubiFunctorCategoryEmbedding SimplexCategoryᵒᵖ C).obj Y Y₂ : SimplicialObject C := Y.X Y₃ : SimplicialObject (Karoubi C) := ((whiskering C (Karoubi C)).obj (toKaroubi C)).obj Y.X Y₄ : SimplexCategoryᵒᵖ ⥤ Karoubi C := (karoubiFunctorCategoryEmbedding SimplexCategoryᵒᵖ C).obj ((toKaroubi (SimplexCategoryᵒᵖ ⥤ C)).obj Y.X) P₁ : K[Y₁] ⟶ K[Y₁] := PInfty P₂ : K[Y₂] ⟶ K[Y₂] := PInfty P₃ : K[Y₃] ⟶ K[Y₃] := PInfty P₄ : K[Y₄] ⟶ K[Y₄] := PInfty h₃₂ : (HomologicalComplex.Hom.f P₃ n).f = HomologicalComplex.Hom.f P₂ n h₄₃ : HomologicalComplex.Hom.f P₄ n = HomologicalComplex.Hom.f P₃ n h₁₄ : HomologicalComplex.Hom.f PInfty n = NatTrans.app (KaroubiFunctorCategoryEmbedding.map (Karoubi.decompId_i Y)) (op [n]) ≫ HomologicalComplex.Hom.f PInfty n ≫ NatTrans.app (KaroubiFunctorCategoryEmbedding.map (Karoubi.decompId_p Y)) (op [n]) π : Y₄ ⟶ Y₄ := (toKaroubi (SimplexCategoryᵒᵖ ⥤ C) ⋙ karoubiFunctorCategoryEmbedding SimplexCategoryᵒᵖ C).map Y.p eq : NatTrans.app Y.p (op [n]) ≫ (HomologicalComplex.Hom.f PInfty n).f = (HomologicalComplex.Hom.f PInfty n).f ≫ NatTrans.app Y.p (op [n]) ⊢ NatTrans.app Y.p (op [n]) ≫ (HomologicalComplex.Hom.f PInfty n).f ≫ NatTrans.app Y.p (op [n]) = NatTrans.app Y.p (op [n]) ≫ (HomologicalComplex.Hom.f PInfty n).f [PROOFSTEP] rw [← eq, app_idem_assoc Y (op [n])]
#' Utah's Counties #' #' Polygons containing county boundaries from gis.utah.gov. #' #' @format An sf type polygon shapefile "county_poly"
State Before: k : Type u_1 M : Type u_2 N : Type ?u.32115 inst✝³ : OrderedRing k inst✝² : OrderedAddCommGroup M inst✝¹ : Module k M inst✝ : OrderedSMul k M a b : M c : k hc : c < 0 ⊢ c • a < 0 ↔ 0 < a State After: k : Type u_1 M : Type u_2 N : Type ?u.32115 inst✝³ : OrderedRing k inst✝² : OrderedAddCommGroup M inst✝¹ : Module k M inst✝ : OrderedSMul k M a b : M c : k hc : c < 0 ⊢ 0 < -c • a ↔ 0 < a Tactic: rw [← neg_neg c, neg_smul, neg_neg_iff_pos] State Before: k : Type u_1 M : Type u_2 N : Type ?u.32115 inst✝³ : OrderedRing k inst✝² : OrderedAddCommGroup M inst✝¹ : Module k M inst✝ : OrderedSMul k M a b : M c : k hc : c < 0 ⊢ 0 < -c • a ↔ 0 < a State After: no goals Tactic: exact smul_pos_iff_of_pos (neg_pos_of_neg hc)
[STATEMENT] lemma lmap_eq_LCons_conv: "lmap f xs = LCons y ys \<longleftrightarrow> (\<exists>x xs'. xs = LCons x xs' \<and> y = f x \<and> ys = lmap f xs')" [PROOF STATE] proof (prove) goal (1 subgoal): 1. (lmap f xs = LCons y ys) = (\<exists>x xs'. xs = LCons x xs' \<and> y = f x \<and> ys = lmap f xs') [PROOF STEP] by(cases xs)(auto)
context("select") df <- as.data.frame(as.list(setNames(1:26, letters))) tbls <- test_load(df) test_that("two selects equivalent to one", { mf <- memdb_frame(a = 1, b = 1, c = 1, d = 2) out <- mf %>% select(a:c) %>% select(b:c) %>% collect() expect_named(out, c("b", "c")) }) test_that("select operates on mutated vars", { mf <- memdb_frame(x = c(1, 2, 3), y = c(3, 2, 1)) df1 <- mf %>% mutate(x, z = x + y) %>% select(z) %>% collect() df2 <- mf %>% collect() %>% mutate(x, z = x + y) %>% select(z) expect_equal_tbl(df1, df2) }) test_that("select renames variables (#317)", { mf <- memdb_frame(x = 1, y = 2) expect_equal_tbl(mf %>% select(A = x), tibble(A = 1)) }) test_that("rename renames variables", { mf <- memdb_frame(x = 1, y = 2) expect_equal_tbl(mf %>% rename(A = x), tibble(A = 1, y = 2)) }) test_that("can rename multiple vars", { mf <- memdb_frame(a = 1, b = 2) exp <- tibble(c = 1, d = 2) expect_equal_tbl(mf %>% rename(c = a, d = b), exp) expect_equal_tbl(mf %>% group_by(a) %>% rename(c = a, d = b), exp) }) test_that("select preserves grouping vars", { mf <- memdb_frame(a = 1, b = 2) %>% group_by(b) out <- mf %>% select(a) %>% collect() expect_named(out, c("b", "a")) })
Load LFindLoad. From lfind Require Import LFind. From QuickChick Require Import QuickChick. From adtind Require Import goal4. Derive Show for natural. Derive Arbitrary for natural. Instance Dec_Eq_natural : Dec_Eq natural. Proof. dec_eq. Qed. Derive Show for lst. Derive Arbitrary for lst. Instance Dec_Eq_lst : Dec_Eq lst. Proof. dec_eq. Qed. Lemma conj5synthconj6 : forall (lv0 : lst) (lv1 : natural), (@eq natural (len lv0) (lv1)). Admitted. QuickChick conj5synthconj6.
The residue of the Gamma function at $-n$ is $(-1)^n/n!$.
Formal statement is: lemma (in topological_space) at_within_open: "a \<in> S \<Longrightarrow> open S \<Longrightarrow> at a within S = at a" Informal statement is: If $a$ is in an open set $S$, then the filter of neighbourhoods of $a$ within $S$ is the same as the filter of neighbourhoods of $a$.
[STATEMENT] lemma shr_conv [simp]: "shr (ls, (ts, m), ws, is) = m" [PROOF STATE] proof (prove) goal (1 subgoal): 1. shr (ls, (ts, m), ws, is) = m [PROOF STEP] by(simp add: shr_def)
using Test include("heap_sort.jl") @testset "test helpers" begin @testset "max_heapify!" begin input = [16 4 10 14 7 9 3 2 8 1] output = [16 14 10 8 7 9 3 2 4 1] heap = Heap(input) max_heapify!(heap, 2) @test heap.array == output end @testset "build_max_heap" begin input = [16 4 10 14 7 9 3 2 8 1] output = [16 14 10 8 7 9 3 2 4 1] heap = build_max_heap(input) @test heap.array == output input = [4 1 3 2 16 9 10 14 8 7] output = [16 14 10 8 7 9 3 2 4 1] heap = build_max_heap!(input) @test heap.array == output end end
library(tidyverse) #General purpose data wrangling library(rvest) #Parsing of HTML/XML files library(stringr) #String manipulation library(rebus) #Verbose regular expressions library(lubridate) #Eases DateTime manipulation #okay, what are the problems with the scraped angband set? #1)race and class occupy one column #2)experience and turncount are comma formatted character vectors and not numerics #3)comments is character and should just contain the number of comments #4)updated is a character vector but should be POSIXct date load(file = "main_df.RData") #load from the angScrape.r save's output clean_df <- main_df #1)split `race class` clean_df <- separate(clean_df, col = "race class", into = c("race", "class"), sep = " ") #this produces a warning about rows [2577, 3338, 4482] #the origin of these warning is that the dumps are inappropriate (wrong angband variant dumped as angband) remove_rows <- c(2577, 3338, 4482) clean_df <- clean_df[-remove_rows, ] #2)convert experience and turncount into numerics clean_df$experience <- clean_df$experience %>% str_replace_all(pattern = ",", replacement = "") %>% as.numeric() clean_df$turncount <- clean_df$turncount %>% str_replace_all(pattern = ",", replacement = "") %>% as.numeric() #3) turn comments into a numeric #turn empty strings into 0's, because an empty string means no comments clean_df$comments[which(clean_df$comments == "")] <- "0" #replace " comments" and " comment" with "" in that order and then coerce into numeric clean_df$comments <- clean_df$comments %>% str_replace_all(pattern = " comments", replacement = "") %>% str_replace_all(pattern = " comment", replacement = "") %>% as.numeric() #4) coerce updated column into date type. clean_df$updated <- dmy_hm(clean_df$updated) #todo: Look for and remove cheaters (low turn count high exp, e.t.c.) # Look for and remove classes not in the base game (these are probably incorrect dumps) # Look for and remove bad version numbers (version numbers that contain letters e.t.c.) save(clean_df, file = "clean_df.RData")
(* * Copyright 2020, Data61, CSIRO (ABN 41 687 119 230) * * SPDX-License-Identifier: BSD-2-Clause *) (* License: BSD, terms see file ./LICENSE *) theory SepInv imports SepCode begin (* FIXME: temporary hack for compatability - should generalise earlier proofs to avoid all the duplication in here *) definition inv_footprint :: "'a::c_type ptr \<Rightarrow> heap_assert" where "inv_footprint p \<equiv> \<lambda>s. dom s = {(x,y). x \<in> {ptr_val p..+size_of TYPE('a)}} - s_footprint p" text \<open> Like in Separation.thy, these arrows are defined using bsub and esub but have an \emph{input} syntax abbreviation with just sub. See original comment there for justification. \<close> definition sep_map_inv :: "'a::c_type ptr \<Rightarrow> 'a ptr_guard \<Rightarrow> 'a \<Rightarrow> heap_assert" ("_ \<mapsto>\<^sup>i\<^bsub>_\<^esub> _" [56,0,51] 56) where "p \<mapsto>\<^sup>i\<^bsub>g\<^esub> v \<equiv> p \<mapsto>\<^sub>g v \<and>\<^sup>* inv_footprint p" notation (input) sep_map_inv ("_ \<mapsto>\<^sup>i\<^sub>_ _" [56,1000,51] 56) definition sep_map_any_inv :: "'a ::c_type ptr \<Rightarrow> 'a ptr_guard \<Rightarrow> heap_assert" ("_ \<mapsto>\<^sup>i\<^bsub>_\<^esub> -" [56,0] 56) where "p \<mapsto>\<^sup>i\<^bsub>g\<^esub> - \<equiv> p \<mapsto>\<^sub>g - \<and>\<^sup>* inv_footprint p" notation (input) sep_map_any_inv ("_ \<mapsto>\<^sup>i\<^sub>_ -" [56,0] 56) definition sep_map'_inv :: "'a::c_type ptr \<Rightarrow> 'a ptr_guard \<Rightarrow> 'a \<Rightarrow> heap_assert" ("_ \<hookrightarrow>\<^sup>i\<^bsub>_\<^esub> _" [56,0,51] 56) where "p \<hookrightarrow>\<^sup>i\<^bsub>g\<^esub> v \<equiv> p \<hookrightarrow>\<^sub>g v \<and>\<^sup>* inv_footprint p" notation (input) sep_map'_inv ("_ \<hookrightarrow>\<^sup>i\<^sub>_ _" [56,1000,51] 56) definition sep_map'_any_inv :: "'a::c_type ptr \<Rightarrow> 'a ptr_guard \<Rightarrow> heap_assert" ("_ \<hookrightarrow>\<^sup>i\<^bsub>_\<^esub> -" [56,0] 56) where "p \<hookrightarrow>\<^sup>i\<^bsub>g\<^esub> - \<equiv> p \<hookrightarrow>\<^sub>g - \<and>\<^sup>* inv_footprint p" notation (input) sep_map'_any_inv ("_ \<hookrightarrow>\<^sup>i\<^sub>_ -" [56,0] 56) definition tagd_inv :: "'a ptr_guard \<Rightarrow> 'a::c_type ptr \<Rightarrow> heap_assert" (infix "\<turnstile>\<^sub>s\<^sup>i" 100) where "g \<turnstile>\<^sub>s\<^sup>i p \<equiv> g \<turnstile>\<^sub>s p \<and>\<^sup>* inv_footprint p" text \<open>----\<close> lemma sep_map'_g: "(p \<hookrightarrow>\<^sup>i\<^sub>g v) s \<Longrightarrow> g p" unfolding sep_map'_inv_def by (fastforce dest: sep_conjD sep_map'_g_exc) lemma sep_map'_unfold: "(p \<hookrightarrow>\<^sup>i\<^sub>g v) = ((p \<hookrightarrow>\<^sup>i\<^sub>g v) \<and>\<^sup>* sep_true)" by (simp add: sep_map'_inv_def sep_map'_def sep_conj_ac) lemma sep_map'_any_unfold: "(i \<hookrightarrow>\<^sup>i\<^sub>g -) = ((i \<hookrightarrow>\<^sup>i\<^sub>g -) \<and>\<^sup>* sep_true)" apply(rule ext, simp add: sep_map'_any_inv_def sep_map'_any_def sep_conj_ac) apply(rule iffI) apply(subst sep_conj_com) apply(subst sep_conj_assoc)+ apply(erule (1) sep_conj_impl) apply(clarsimp simp: sep_conj_ac) apply(subst (asm) sep_map'_unfold_exc, subst sep_conj_com) apply(subst sep_conj_exists, fast) apply(subst (asm) sep_conj_com) apply(subst (asm) sep_conj_assoc)+ apply(erule (1) sep_conj_impl) apply(subst sep_map'_unfold_exc) apply(subst (asm) sep_conj_exists, fast) done lemma sep_map'_conjE1: "\<lbrakk> (P \<and>\<^sup>* Q) s; \<And>s. P s \<Longrightarrow> (i \<hookrightarrow>\<^sup>i\<^sub>g v) s \<rbrakk> \<Longrightarrow> (i \<hookrightarrow>\<^sup>i\<^sub>g v) s" by (subst sep_map'_unfold, erule sep_conj_impl, simp+) lemma sep_map'_conjE2: "\<lbrakk> (P \<and>\<^sup>* Q) s; \<And>s. Q s \<Longrightarrow> (i \<hookrightarrow>\<^sup>i\<^sub>g v) s \<rbrakk> \<Longrightarrow> (i \<hookrightarrow>\<^sup>i\<^sub>g v) s" by (subst (asm) sep_conj_com, erule sep_map'_conjE1, simp) lemma sep_map'_any_conjE1: "\<lbrakk> (P \<and>\<^sup>* Q) s; \<And>s. P s \<Longrightarrow> (i \<hookrightarrow>\<^sup>i\<^sub>g -) s \<rbrakk> \<Longrightarrow> (i \<hookrightarrow>\<^sup>i\<^sub>g -) s" by (subst sep_map'_any_unfold, erule sep_conj_impl, simp+) lemma sep_map'_any_conjE2: "\<lbrakk> (P \<and>\<^sup>* Q) s; \<And>s. Q s \<Longrightarrow> (i \<hookrightarrow>\<^sup>i\<^sub>g -) s \<rbrakk> \<Longrightarrow> (i \<hookrightarrow>\<^sup>i\<^sub>g -) s" by (subst (asm) sep_conj_com, erule sep_map'_any_conjE1, simp) lemma sep_map_any_old: "(p \<mapsto>\<^sup>i\<^sub>g -) = (\<lambda>s. \<exists>v. (p \<mapsto>\<^sup>i\<^sub>g v) s)" by (simp add: sep_map_inv_def sep_map_any_inv_def sep_map_any_def sep_conj_ac sep_conj_exists) lemma sep_map'_old: "(p \<hookrightarrow>\<^sup>i\<^sub>g v) = ((p \<mapsto>\<^sup>i\<^sub>g v) \<and>\<^sup>* sep_true)" by (simp add: sep_map'_inv_def sep_map_inv_def sep_map'_def sep_conj_ac) lemma sep_map'_any_old: "(p \<hookrightarrow>\<^sup>i\<^sub>g -) = (\<lambda>s. \<exists>v. (p \<hookrightarrow>\<^sup>i\<^sub>g v) s)" by (simp add: sep_map'_inv_def sep_map'_any_inv_def sep_map'_any_def sep_conj_exists) lemma sep_map_sep_map' [simp]: "(p \<mapsto>\<^sup>i\<^sub>g v) s \<Longrightarrow> (p \<hookrightarrow>\<^sup>i\<^sub>g v) s" unfolding sep_map_inv_def sep_map'_inv_def sep_map'_def apply(simp add: sep_conj_ac) apply(subst sep_conj_com) apply(simp add: sep_conj_assoc sep_conj_impl sep_conj_sep_true) done lemmas guardI = sep_map'_g[OF sep_map_sep_map'] lemma sep_map_anyI [simp]: "(p \<mapsto>\<^sup>i\<^sub>g v) s \<Longrightarrow> (p \<mapsto>\<^sup>i\<^sub>g -) s" by (fastforce simp: sep_map_any_inv_def sep_map_inv_def sep_map_any_def sep_conj_ac elim: sep_conj_impl) lemma sep_map_anyD: "(p \<mapsto>\<^sup>i\<^sub>g -) s \<Longrightarrow> \<exists>v. (p \<mapsto>\<^sup>i\<^sub>g v) s" apply(simp add: sep_map_any_def sep_map_any_inv_def sep_map_inv_def sep_conj_ac) apply(subst (asm) sep_conj_com) apply(clarsimp simp: sep_conj_exists sep_conj_ac) done lemma sep_conj_mapD: "((i \<mapsto>\<^sup>i\<^sub>g v) \<and>\<^sup>* P) s \<Longrightarrow> (i \<hookrightarrow>\<^sup>i\<^sub>g v) s \<and> ((i \<mapsto>\<^sup>i\<^sub>g -) \<and>\<^sup>* P) s" by (simp add: sep_conj_impl sep_map'_conjE2 sep_conj_ac) lemma sep_map'_ptr_safe: "(p \<hookrightarrow>\<^sup>i\<^sub>g (v::'a::mem_type)) (lift_state (h,d)) \<Longrightarrow> ptr_safe p d" unfolding sep_map'_inv_def apply(rule sep_map'_ptr_safe_exc) apply(subst sep_map'_unfold_exc) apply(fastforce elim: sep_conj_impl) done lemmas sep_map_ptr_safe = sep_map'_ptr_safe[OF sep_map_sep_map'] lemma sep_map_any_ptr_safe: fixes p::"'a::mem_type ptr" shows "(p \<mapsto>\<^sup>i\<^sub>g -) (lift_state (h, d)) \<Longrightarrow> ptr_safe p d" by (blast dest: sep_map_anyD intro: sep_map_ptr_safe) lemma sep_heap_update': "(g \<turnstile>\<^sub>s\<^sup>i p \<and>\<^sup>* (p \<mapsto>\<^sup>i\<^sub>g v \<longrightarrow>\<^sup>* P)) (lift_state (h,d)) \<Longrightarrow> P (lift_state (heap_update p (v::'a::mem_type) h,d))" apply(rule_tac g=g in sep_heap_update'_exc) apply(unfold tagd_inv_def) apply(subst (asm) sep_conj_assoc)+ apply(erule (1) sep_conj_impl) apply(subst (asm) sep_map_inv_def) apply(simp add: sep_conj_ac) apply(drule sep_conjD, clarsimp) apply(rule sep_implI, clarsimp) apply(drule sep_implD) apply(drule_tac x="s\<^sub>0 ++ s'" in spec) apply(simp add: map_disj_com map_add_disj) apply(clarsimp simp: map_disj_com) apply(erule notE) apply(erule (1) sep_conjI) apply(simp add: map_disj_com) apply(subst map_add_com; simp) done lemma tagd_g: "(g \<turnstile>\<^sub>s\<^sup>i p \<and>\<^sup>* P) s \<Longrightarrow> g p" by (auto simp: tagd_inv_def tagd_def dest!: sep_conjD elim: s_valid_g) lemma tagd_ptr_safe: "(g \<turnstile>\<^sub>s\<^sup>i p \<and>\<^sup>* sep_true) (lift_state (h,d)) \<Longrightarrow> ptr_safe p d" apply(rule tagd_ptr_safe_exc) apply(unfold tagd_inv_def) apply(subst (asm) sep_conj_assoc) apply(erule (1) sep_conj_impl) apply simp done lemma sep_map_tagd: "(p \<mapsto>\<^sup>i\<^sub>g (v::'a::mem_type)) s \<Longrightarrow> (g \<turnstile>\<^sub>s\<^sup>i p) s" apply(unfold sep_map_inv_def tagd_inv_def) apply(erule sep_conj_impl) apply(erule sep_map_tagd_exc) apply assumption done lemma sep_map_any_tagd: "(p \<mapsto>\<^sup>i\<^sub>g -) s \<Longrightarrow> (g \<turnstile>\<^sub>s\<^sup>i (p::'a::mem_type ptr)) s" by (clarsimp dest!: sep_map_anyD, erule sep_map_tagd) lemma sep_heap_update: "\<lbrakk> (p \<mapsto>\<^sup>i\<^sub>g - \<and>\<^sup>* (p \<mapsto>\<^sup>i\<^sub>g v \<longrightarrow>\<^sup>* P)) (lift_state (h,d)) \<rbrakk> \<Longrightarrow> P (lift_state (heap_update p (v::'a::mem_type) h,d))" by (force intro: sep_heap_update' dest: sep_map_anyD sep_map_tagd elim: sep_conj_impl) lemma sep_heap_update_global': "(g \<turnstile>\<^sub>s\<^sup>i p \<and>\<^sup>* R) (lift_state (h,d)) \<Longrightarrow> ((p \<mapsto>\<^sup>i\<^sub>g v) \<and>\<^sup>* R) (lift_state (heap_update p (v::'a::mem_type) h,d))" by (rule sep_heap_update', erule sep_conj_sep_conj_sep_impl_sep_conj) lemma sep_heap_update_global: "(p \<mapsto>\<^sup>i\<^sub>g - \<and>\<^sup>* R) (lift_state (h,d)) \<Longrightarrow> ((p \<mapsto>\<^sup>i\<^sub>g v) \<and>\<^sup>* R) (lift_state (heap_update p (v::'a::mem_type) h,d))" by (fast intro: sep_heap_update_global' sep_conj_impl sep_map_any_tagd) lemma sep_heap_update_global_super_fl_inv: "\<lbrakk> (p \<mapsto>\<^sup>i\<^sub>g u \<and>\<^sup>* R) (lift_state (h,d)); field_lookup (typ_info_t TYPE('b::mem_type)) f 0 = Some (t,n); export_uinfo t = (typ_uinfo_t TYPE('a)) \<rbrakk> \<Longrightarrow> ((p \<mapsto>\<^sup>i\<^sub>g update_ti_t t (to_bytes_p v) u) \<and>\<^sup>* R) (lift_state (heap_update (Ptr &(p\<rightarrow>f)) (v::'a::mem_type) h,d))" apply(unfold sep_map_inv_def) apply(simp only: sep_conj_assoc) apply(erule (2) sep_heap_update_global_super_fl) done lemma sep_map'_inv: "(p \<hookrightarrow>\<^sup>i\<^sub>g v) s \<Longrightarrow> (p \<hookrightarrow>\<^sub>g v) s" apply(unfold sep_map'_inv_def) apply(subst sep_map'_unfold_exc) apply(erule (1) sep_conj_impl, simp) done lemma sep_map'_lift: "(p \<hookrightarrow>\<^sup>i\<^sub>g (v::'a::mem_type)) (lift_state (h,d)) \<Longrightarrow> lift h p = v" apply(drule sep_map'_inv) apply(erule sep_map'_lift_exc) done lemma sep_map_lift: "((p::'a::mem_type ptr) \<mapsto>\<^sup>i\<^sub>g -) (lift_state (h,d)) \<Longrightarrow> (p \<mapsto>\<^sup>i\<^sub>g lift h p) (lift_state (h,d))" apply(frule sep_map_anyD) apply clarsimp apply(frule sep_map_sep_map') apply(drule sep_map'_lift) apply simp done lemma sep_map_lift_wp: "\<lbrakk> \<exists>v. (p \<mapsto>\<^sup>i\<^sub>g v \<and>\<^sup>* (p \<mapsto>\<^sup>i\<^sub>g v \<longrightarrow>\<^sup>* P v)) (lift_state (h,d)) \<rbrakk> \<Longrightarrow> P (lift h (p::'a::mem_type ptr)) (lift_state (h,d))" apply clarsimp apply(subst sep_map'_lift [where g=g and d=d]) apply(subst sep_map'_inv_def) apply(subst sep_map'_def) apply(subst sep_conj_assoc)+ apply(subst sep_conj_com[where P=sep_true]) apply(subst sep_conj_assoc [symmetric]) apply(erule sep_conj_impl) apply(simp add: sep_map_inv_def) apply simp apply(rule_tac P="p \<mapsto>\<^sup>i\<^sub>g v" and Q="P v" in sep_conj_impl_same) apply(unfold sep_map_inv_def) apply(erule (2) sep_conj_impl) done lemma sep_map'_anyI [simp]: "(p \<hookrightarrow>\<^sup>i\<^sub>g v) s \<Longrightarrow> (p \<hookrightarrow>\<^sup>i\<^sub>g -) s" apply(unfold sep_map'_inv_def sep_map'_any_inv_def) apply(erule sep_conj_impl) apply(erule sep_map'_anyI_exc) apply assumption done lemma sep_map'_anyD: "(p \<hookrightarrow>\<^sup>i\<^sub>g -) s \<Longrightarrow> \<exists>v. (p \<hookrightarrow>\<^sup>i\<^sub>g v) s" unfolding sep_map'_inv_def sep_map'_any_inv_def sep_map'_any_def by (clarsimp simp: sep_conj_exists) lemma sep_map'_lift_rev: "\<lbrakk> lift h p = (v::'a::mem_type); (p \<hookrightarrow>\<^sup>i\<^sub>g -) (lift_state (h,d)) \<rbrakk> \<Longrightarrow> (p \<hookrightarrow>\<^sup>i\<^sub>g v) (lift_state (h,d))" by (fastforce dest: sep_map'_anyD simp: sep_map'_lift) lemma sep_map'_any_g: "(p \<hookrightarrow>\<^sup>i\<^sub>g -) s \<Longrightarrow> g p" by (blast dest: sep_map'_anyD intro: sep_map'_g) lemma any_guardI: "(p \<mapsto>\<^sup>i\<^sub>g -) s \<Longrightarrow> g p" by (drule sep_map_anyD) (blast intro: guardI) lemma sep_map_sep_map_any: "(p \<mapsto>\<^sup>i\<^sub>g v) s \<Longrightarrow> (p \<mapsto>\<^sup>i\<^sub>g -) s" by (rule sep_map_anyI) lemma sep_lift_exists: fixes p :: "'a::mem_type ptr" assumes ex: "((\<lambda>s. \<exists>v. (p \<hookrightarrow>\<^sup>i\<^sub>g v) s \<and> P v s) \<and>\<^sup>* Q) (lift_state (h,d))" shows "(P (lift h p) \<and>\<^sup>* Q) (lift_state (h,d))" proof - from ex obtain v where "((\<lambda>s. (p \<hookrightarrow>\<^sup>i\<^sub>g v) s \<and> P v s) \<and>\<^sup>* Q) (lift_state (h,d))" by (subst (asm) sep_conj_exists, clarsimp) thus ?thesis by (force simp: sep_map'_lift sep_conj_ac dest: sep_map'_conjE2 dest!: sep_conj_conj) qed lemma sep_map_dom: "(p \<mapsto>\<^sup>i\<^sub>g (v::'a::c_type)) s \<Longrightarrow> dom s = {(a,b). a \<in> {ptr_val p..+size_of TYPE('a)}}" unfolding sep_map_inv_def by (drule sep_conjD, clarsimp) (auto dest!: sep_map_dom_exc elim: s_footprintD simp: inv_footprint_def) lemma sep_map'_dom: "(p \<hookrightarrow>\<^sup>i\<^sub>g (v::'a::mem_type)) s \<Longrightarrow> (ptr_val p,SIndexVal) \<in> dom s" unfolding sep_map'_inv_def by (drule sep_conjD, clarsimp) (drule sep_map'_dom_exc, clarsimp) lemma sep_map'_inj: "\<lbrakk> (p \<hookrightarrow>\<^sup>i\<^sub>g (v::'a::c_type)) s; (p \<hookrightarrow>\<^sup>i\<^sub>h v') s \<rbrakk> \<Longrightarrow> v=v'" by (drule sep_map'_inv)+ (drule (2) sep_map'_inj_exc) lemma ptr_retyp_sep_cut': fixes p::"'a::mem_type ptr" assumes sc: "(sep_cut' (ptr_val p) (size_of TYPE('a)) \<and>\<^sup>* P) (lift_state (h,d))" and "g p" shows "(g \<turnstile>\<^sub>s\<^sup>i p \<and>\<^sup>* P) (lift_state (h,(ptr_retyp p d)))" proof - from sc obtain s\<^sub>0 and s\<^sub>1 where "s\<^sub>0 \<bottom> s\<^sub>1" and "lift_state (h,d) = s\<^sub>1 ++ s\<^sub>0" and "P s\<^sub>1" and d: "dom s\<^sub>0 = {(a,b). a \<in> {ptr_val p..+size_of TYPE('a)}}" and k: "dom s\<^sub>0 \<subseteq> dom_s d" by (auto dest!: sep_conjD sep_cut'_dom simp: dom_lift_state_dom_s [where h=h,symmetric]) moreover from this have "lift_state (h, ptr_retyp p d) = s\<^sub>1 ++ lift_state (h, ptr_retyp p d) |` (dom s\<^sub>0)" apply - apply(rule ext, rename_tac x) apply(case_tac "x \<in> dom s\<^sub>0") apply(case_tac "x \<in> dom s\<^sub>1") apply(fastforce simp: map_disj_def) apply(subst map_add_com) apply(fastforce simp: map_disj_def) apply(clarsimp simp: map_add_def split: option.splits) apply(case_tac x, clarsimp) apply(clarsimp simp: lift_state_ptr_retyp_d merge_dom2) done moreover have "g p" by fact with d k have "(g \<turnstile>\<^sub>s\<^sup>i p) (lift_state (h, ptr_retyp p d) |` dom s\<^sub>0)" apply(clarsimp simp: lift_state_ptr_retyp_restrict sep_conj_ac tagd_inv_def) apply(rule_tac s\<^sub>0="lift_state (h,d) |` ({(a, b). a \<in> {ptr_val p..+size_of TYPE('a)}} - s_footprint p)" in sep_conjI) apply(fastforce simp: inv_footprint_def) apply(erule_tac h=h in ptr_retyp_tagd_exc) apply(fastforce simp: map_disj_def) apply(subst map_add_comm[of "lift_state (h, ptr_retyp p empty_htd)"]) apply force apply(rule ext) apply(clarsimp simp: map_add_def split: option.splits) by (metis (mono_tags) Diff_iff dom_ptr_retyp_empty_htd non_dom_eval_eq restrict_in_dom restrict_out) ultimately show ?thesis by - (rule_tac s\<^sub>0="(lift_state (h,ptr_retyp p d))|`dom s\<^sub>0" and s\<^sub>1=s\<^sub>1 in sep_conjI, auto simp: map_disj_def) qed lemma ptr_retyp_sep_cut'_wp: "\<lbrakk> (sep_cut' (ptr_val p) (size_of TYPE('a)) \<and>\<^sup>* (g \<turnstile>\<^sub>s\<^sup>i p \<longrightarrow>\<^sup>* P)) (lift_state (h,d)); g (p::'a::mem_type ptr) \<rbrakk> \<Longrightarrow> P (lift_state (h,(ptr_retyp p d)))" by (rule_tac P="g \<turnstile>\<^sub>s\<^sup>i p" and Q=P in sep_conj_impl_same) (simp add: ptr_retyp_sep_cut') lemma tagd_dom: "(g \<turnstile>\<^sub>s\<^sup>i p) s \<Longrightarrow> dom s = {(a,b). a \<in> {ptr_val (p::'a::c_type ptr)..+size_of TYPE('a)}}" unfolding tagd_inv_def by (drule sep_conjD, clarsimp) (auto simp: inv_footprint_def dest!: tagd_dom_exc elim: s_footprintD) lemma tagd_dom_p: "(g \<turnstile>\<^sub>s\<^sup>i p) s \<Longrightarrow> (ptr_val (p::'a::mem_type ptr),SIndexVal) \<in> dom s" by (drule tagd_dom) clarsimp end
[STATEMENT] lemma (in carrier) closedI: "(carrier - s) open \<Longrightarrow> s closed" [PROOF STATE] proof (prove) goal (1 subgoal): 1. carrier - s open \<Longrightarrow> s closed [PROOF STEP] by (auto simp: is_closed_def)
theorem Stone_Weierstrass_polynomial_function: fixes f :: "'a::euclidean_space \<Rightarrow> 'b::euclidean_space" assumes S: "compact S" and f: "continuous_on S f" and e: "0 < e" shows "\<exists>g. polynomial_function g \<and> (\<forall>x \<in> S. norm(f x - g x) < e)"
## -------->> [[file:../../nstandr.src.org::*Universities][Universities:2]] expect_equal(c(" TILBURG UNIVERSTIY " , " VU UNIVERSTITAET " , "LEGALY REPRESENTED BY STAS") |> cockburn_detect_univ() , structure(list(x = c(" TILBURG UNIVERSTIY ", " VU UNIVERSTITAET ", "LEGALY REPRESENTED BY STAS"), x_entity_type = c("univ", "univ", NA)), row.names = c(NA, -3L), class = c("data.table", "data.frame" ))) expect_equal(c(" SUPERVISORS OF THE TILBURG UNIVERSTIY " , " VU UNIVERSTITAET " , "LEGALY REPRESENTED BY STAS") |> cockburn_replace_univ() , c(" TILBURG UNIVERSTIY ", " VU UNIVERSTITAET ", "LEGALY REPRESENTED BY STAS" )) ## --------<< Universities:2 ends here
/- Copyright (c) 2021 Joseph Myers. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Joseph Myers -/ import linear_algebra.ray import linear_algebra.determinant /-! # Orientations of modules This file defines orientations of modules. ## Main definitions * `orientation` is a type synonym for `module.ray` for the case where the module is that of alternating maps from a module to its underlying ring. An orientation may be associated with an alternating map or with a basis. * `module.oriented` is a type class for a choice of orientation of a module that is considered the positive orientation. ## Implementation notes `orientation` is defined for an arbitrary index type, but the main intended use case is when that index type is a `fintype` and there exists a basis of the same cardinality. ## References * https://en.wikipedia.org/wiki/Orientation_(vector_space) -/ noncomputable theory open_locale big_operators section ordered_comm_semiring variables (R : Type*) [strict_ordered_comm_semiring R] variables (M : Type*) [add_comm_monoid M] [module R M] variables {N : Type*} [add_comm_monoid N] [module R N] variables (ι : Type*) /-- An orientation of a module, intended to be used when `ι` is a `fintype` with the same cardinality as a basis. -/ abbreviation orientation := module.ray R (alternating_map R M R ι) /-- A type class fixing an orientation of a module. -/ class module.oriented := (positive_orientation : orientation R M ι) export module.oriented (positive_orientation) variables {R M} /-- An equivalence between modules implies an equivalence between orientations. -/ def orientation.map (e : M ≃ₗ[R] N) : orientation R M ι ≃ orientation R N ι := module.ray.map $ alternating_map.dom_lcongr R R ι R e @[simp] lemma orientation.map_apply (e : M ≃ₗ[R] N) (v : alternating_map R M R ι) (hv : v ≠ 0) : orientation.map ι e (ray_of_ne_zero _ v hv) = ray_of_ne_zero _ (v.comp_linear_map e.symm) (mt (v.comp_linear_equiv_eq_zero_iff e.symm).mp hv) := rfl @[simp] lemma orientation.map_refl : (orientation.map ι $ linear_equiv.refl R M) = equiv.refl _ := by rw [orientation.map, alternating_map.dom_lcongr_refl, module.ray.map_refl] @[simp] lemma orientation.map_symm (e : M ≃ₗ[R] N) : (orientation.map ι e).symm = orientation.map ι e.symm := rfl /-- A module is canonically oriented with respect to an empty index type. -/ @[priority 100] instance is_empty.oriented [nontrivial R] [is_empty ι] : module.oriented R M ι := { positive_orientation := ray_of_ne_zero R (alternating_map.const_linear_equiv_of_is_empty 1) $ alternating_map.const_linear_equiv_of_is_empty.injective.ne (by simp) } @[simp] lemma orientation.map_positive_orientation_of_is_empty [nontrivial R] [is_empty ι] (f : M ≃ₗ[R] N) : orientation.map ι f positive_orientation = positive_orientation := rfl @[simp] lemma orientation.map_of_is_empty [is_empty ι] (x : orientation R M ι) (f : M ≃ₗ[R] M) : orientation.map ι f x = x := begin induction x using module.ray.ind with g hg, rw orientation.map_apply, congr, ext i, rw alternating_map.comp_linear_map_apply, congr, end end ordered_comm_semiring section ordered_comm_ring variables {R : Type*} [strict_ordered_comm_ring R] variables {M N : Type*} [add_comm_group M] [add_comm_group N] [module R M] [module R N] @[simp] protected lemma orientation.map_neg {ι : Type*} (f : M ≃ₗ[R] N) (x : orientation R M ι) : orientation.map ι f (-x) = - orientation.map ι f x := module.ray.map_neg _ x namespace basis variables {ι : Type*} /-- The value of `orientation.map` when the index type has the cardinality of a basis, in terms of `f.det`. -/ lemma map_orientation_eq_det_inv_smul [finite ι] (e : basis ι R M) (x : orientation R M ι) (f : M ≃ₗ[R] M) : orientation.map ι f x = (f.det)⁻¹ • x := begin casesI nonempty_fintype ι, letI := classical.dec_eq ι, induction x using module.ray.ind with g hg, rw [orientation.map_apply, smul_ray_of_ne_zero, ray_eq_iff, units.smul_def, (g.comp_linear_map ↑f.symm).eq_smul_basis_det e, g.eq_smul_basis_det e, alternating_map.comp_linear_map_apply, alternating_map.smul_apply, basis.det_comp, basis.det_self, mul_one, smul_eq_mul, mul_comm, mul_smul, linear_equiv.coe_inv_det], end variables [fintype ι] [decidable_eq ι] /-- The orientation given by a basis. -/ protected def orientation [nontrivial R] (e : basis ι R M) : orientation R M ι := ray_of_ne_zero R _ e.det_ne_zero lemma orientation_map [nontrivial R] (e : basis ι R M) (f : M ≃ₗ[R] N) : (e.map f).orientation = orientation.map ι f e.orientation := by simp_rw [basis.orientation, orientation.map_apply, basis.det_map'] /-- The orientation given by a basis derived using `units_smul`, in terms of the product of those units. -/ lemma orientation_units_smul [nontrivial R] (e : basis ι R M) (w : ι → units R) : (e.units_smul w).orientation = (∏ i, w i)⁻¹ • e.orientation := begin rw [basis.orientation, basis.orientation, smul_ray_of_ne_zero, ray_eq_iff, e.det.eq_smul_basis_det (e.units_smul w), det_units_smul_self, units.smul_def, smul_smul], norm_cast, simp end @[simp] lemma orientation_is_empty [nontrivial R] [is_empty ι] (b : basis ι R M) : b.orientation = positive_orientation := begin congrm ray_of_ne_zero _ _ _, convert b.det_is_empty, end end basis end ordered_comm_ring section linear_ordered_comm_ring variables {R : Type*} [linear_ordered_comm_ring R] variables {M : Type*} [add_comm_group M] [module R M] variables {ι : Type*} namespace orientation /-- A module `M` over a linearly ordered commutative ring has precisely two "orientations" with respect to an empty index type. (Note that these are only orientations of `M` of in the conventional mathematical sense if `M` is zero-dimensional.) -/ lemma eq_or_eq_neg_of_is_empty [nontrivial R] [is_empty ι] (o : orientation R M ι) : o = positive_orientation ∨ o = - positive_orientation := begin induction o using module.ray.ind with x hx, dsimp [positive_orientation], simp only [ray_eq_iff, same_ray_neg_swap], rw same_ray_or_same_ray_neg_iff_not_linear_independent, intros h, let a : R := alternating_map.const_linear_equiv_of_is_empty.symm x, have H : linear_independent R ![a, 1], { convert h.map' ↑alternating_map.const_linear_equiv_of_is_empty.symm (linear_equiv.ker _), ext i, fin_cases i; simp [a] }, rw linear_independent_iff' at H, simpa using H finset.univ ![1, -a] (by simp [fin.sum_univ_succ]) 0 (by simp), end end orientation namespace basis variables [fintype ι] [decidable_eq ι] /-- The orientations given by two bases are equal if and only if the determinant of one basis with respect to the other is positive. -/ lemma orientation_eq_iff_det_pos (e₁ e₂ : basis ι R M) : e₁.orientation = e₂.orientation ↔ 0 < e₁.det e₂ := calc e₁.orientation = e₂.orientation ↔ same_ray R e₁.det e₂.det : ray_eq_iff _ _ ... ↔ same_ray R (e₁.det e₂ • e₂.det) e₂.det : by rw [← e₁.det.eq_smul_basis_det e₂] ... ↔ 0 < e₁.det e₂ : same_ray_smul_left_iff_of_ne e₂.det_ne_zero (e₁.is_unit_det e₂).ne_zero /-- Given a basis, any orientation equals the orientation given by that basis or its negation. -/ lemma orientation_eq_or_eq_neg (e : basis ι R M) (x : orientation R M ι) : x = e.orientation ∨ x = -e.orientation := begin induction x using module.ray.ind with x hx, rw ← x.map_basis_ne_zero_iff e at hx, rwa [basis.orientation, ray_eq_iff, neg_ray_of_ne_zero, ray_eq_iff, x.eq_smul_basis_det e, same_ray_neg_smul_left_iff_of_ne e.det_ne_zero hx, same_ray_smul_left_iff_of_ne e.det_ne_zero hx, lt_or_lt_iff_ne, ne_comm] end /-- Given a basis, an orientation equals the negation of that given by that basis if and only if it does not equal that given by that basis. -/ lemma orientation_ne_iff_eq_neg (e : basis ι R M) (x : orientation R M ι) : x ≠ e.orientation ↔ x = -e.orientation := ⟨λ h, (e.orientation_eq_or_eq_neg x).resolve_left h, λ h, h.symm ▸ (module.ray.ne_neg_self e.orientation).symm⟩ /-- Composing a basis with a linear equiv gives the same orientation if and only if the determinant is positive. -/ lemma orientation_comp_linear_equiv_eq_iff_det_pos (e : basis ι R M) (f : M ≃ₗ[R] M) : (e.map f).orientation = e.orientation ↔ 0 < (f : M →ₗ[R] M).det := by rw [orientation_map, e.map_orientation_eq_det_inv_smul, units_inv_smul, units_smul_eq_self_iff, linear_equiv.coe_det] /-- Composing a basis with a linear equiv gives the negation of that orientation if and only if the determinant is negative. -/ lemma orientation_comp_linear_equiv_eq_neg_iff_det_neg (e : basis ι R M) (f : M ≃ₗ[R] M) : (e.map f).orientation = -e.orientation ↔ (f : M →ₗ[R] M).det < 0 := by rw [orientation_map, e.map_orientation_eq_det_inv_smul, units_inv_smul, units_smul_eq_neg_iff, linear_equiv.coe_det] /-- Negating a single basis vector (represented using `units_smul`) negates the corresponding orientation. -/ @[simp] lemma orientation_neg_single [nontrivial R] (e : basis ι R M) (i : ι) : (e.units_smul (function.update 1 i (-1))).orientation = -e.orientation := begin rw [orientation_units_smul, finset.prod_update_of_mem (finset.mem_univ _)], simp end /-- Given a basis and an orientation, return a basis giving that orientation: either the original basis, or one constructed by negating a single (arbitrary) basis vector. -/ def adjust_to_orientation [nontrivial R] [nonempty ι] (e : basis ι R M) (x : orientation R M ι) : basis ι R M := by haveI := classical.dec_eq (orientation R M ι); exact if e.orientation = x then e else (e.units_smul (function.update 1 (classical.arbitrary ι) (-1))) /-- `adjust_to_orientation` gives a basis with the required orientation. -/ @[simp] lemma orientation_adjust_to_orientation [nontrivial R] [nonempty ι] (e : basis ι R M) (x : orientation R M ι) : (e.adjust_to_orientation x).orientation = x := begin rw adjust_to_orientation, split_ifs with h, { exact h }, { rw [orientation_neg_single, eq_comm, ←orientation_ne_iff_eq_neg, ne_comm], exact h } end /-- Every basis vector from `adjust_to_orientation` is either that from the original basis or its negation. -/ lemma adjust_to_orientation_apply_eq_or_eq_neg [nontrivial R] [nonempty ι] (e : basis ι R M) (x : orientation R M ι) (i : ι) : e.adjust_to_orientation x i = e i ∨ e.adjust_to_orientation x i = -(e i) := begin rw adjust_to_orientation, split_ifs with h, { simp }, { by_cases hi : i = classical.arbitrary ι; simp [units_smul_apply, hi] } end lemma det_adjust_to_orientation [nontrivial R] [nonempty ι] (e : basis ι R M) (x : orientation R M ι) : (e.adjust_to_orientation x).det = e.det ∨ (e.adjust_to_orientation x).det = - e.det := begin dsimp [basis.adjust_to_orientation], split_ifs, { left, refl }, { right, simp [e.det_units_smul, ← units.coe_prod, finset.prod_update_of_mem] } end @[simp] lemma abs_det_adjust_to_orientation [nontrivial R] [nonempty ι] (e : basis ι R M) (x : orientation R M ι) (v : ι → M) : |(e.adjust_to_orientation x).det v| = |e.det v| := begin cases e.det_adjust_to_orientation x with h h; simp [h] end end basis end linear_ordered_comm_ring section linear_ordered_field variables {R : Type*} [linear_ordered_field R] variables {M : Type*} [add_comm_group M] [module R M] variables {ι : Type*} namespace orientation variables [fintype ι] [_i : finite_dimensional R M] open finite_dimensional include _i /-- If the index type has cardinality equal to the finite dimension, any two orientations are equal or negations. -/ lemma eq_or_eq_neg (x₁ x₂ : orientation R M ι) (h : fintype.card ι = finrank R M) : x₁ = x₂ ∨ x₁ = -x₂ := begin have e := (fin_basis R M).reindex (fintype.equiv_fin_of_card_eq h).symm, letI := classical.dec_eq ι, rcases e.orientation_eq_or_eq_neg x₁ with h₁|h₁; rcases e.orientation_eq_or_eq_neg x₂ with h₂|h₂; simp [h₁, h₂] end /-- If the index type has cardinality equal to the finite dimension, an orientation equals the negation of another orientation if and only if they are not equal. -/ lemma ne_iff_eq_neg (x₁ x₂ : orientation R M ι) (h : fintype.card ι = finrank R M) : x₁ ≠ x₂ ↔ x₁ = -x₂ := ⟨λ hn, (eq_or_eq_neg x₁ x₂ h).resolve_left hn, λ he, he.symm ▸ (module.ray.ne_neg_self x₂).symm⟩ /-- The value of `orientation.map` when the index type has cardinality equal to the finite dimension, in terms of `f.det`. -/ lemma map_eq_det_inv_smul (x : orientation R M ι) (f : M ≃ₗ[R] M) (h : fintype.card ι = finrank R M) : orientation.map ι f x = (f.det)⁻¹ • x := begin have e := (fin_basis R M).reindex (fintype.equiv_fin_of_card_eq h).symm, exact e.map_orientation_eq_det_inv_smul x f end omit _i /-- If the index type has cardinality equal to the finite dimension, composing an alternating map with the same linear equiv on each argument gives the same orientation if and only if the determinant is positive. -/ lemma map_eq_iff_det_pos (x : orientation R M ι) (f : M ≃ₗ[R] M) (h : fintype.card ι = finrank R M) : orientation.map ι f x = x ↔ 0 < (f : M →ₗ[R] M).det := begin casesI is_empty_or_nonempty ι, { have H : finrank R M = 0, { refine h.symm.trans _, convert fintype.card_of_is_empty, apply_instance }, simp [linear_map.det_eq_one_of_finrank_eq_zero H] }, have H : 0 < finrank R M, { rw ← h, exact fintype.card_pos }, haveI : finite_dimensional R M := finite_dimensional_of_finrank H, rw [map_eq_det_inv_smul _ _ h, units_inv_smul, units_smul_eq_self_iff, linear_equiv.coe_det] end /-- If the index type has cardinality equal to the finite dimension, composing an alternating map with the same linear equiv on each argument gives the negation of that orientation if and only if the determinant is negative. -/ lemma map_eq_neg_iff_det_neg (x : orientation R M ι) (f : M ≃ₗ[R] M) (h : fintype.card ι = finrank R M) : orientation.map ι f x = -x ↔ (f : M →ₗ[R] M).det < 0 := begin casesI is_empty_or_nonempty ι, { have H : finrank R M = 0, { refine h.symm.trans _, convert fintype.card_of_is_empty, apply_instance }, simp [linear_map.det_eq_one_of_finrank_eq_zero H, module.ray.ne_neg_self x] }, have H : 0 < finrank R M, { rw ← h, exact fintype.card_pos }, haveI : finite_dimensional R M := finite_dimensional_of_finrank H, rw [map_eq_det_inv_smul _ _ h, units_inv_smul, units_smul_eq_neg_iff, linear_equiv.coe_det] end include _i /-- If the index type has cardinality equal to the finite dimension, a basis with the given orientation. -/ def some_basis [nonempty ι] [decidable_eq ι] (x : orientation R M ι) (h : fintype.card ι = finrank R M) : basis ι R M := ((fin_basis R M).reindex (fintype.equiv_fin_of_card_eq h).symm).adjust_to_orientation x /-- `some_basis` gives a basis with the required orientation. -/ @[simp] lemma some_basis_orientation [nonempty ι] [decidable_eq ι] (x : orientation R M ι) (h : fintype.card ι = finrank R M) : (x.some_basis h).orientation = x := basis.orientation_adjust_to_orientation _ _ end orientation end linear_ordered_field