Datasets:
AI4M
/

text
stringlengths
0
3.34M
Formal statement is: lemma reflect_poly_pCons': "p \<noteq> 0 \<Longrightarrow> reflect_poly (pCons c p) = reflect_poly p + monom c (Suc (degree p))" Informal statement is: If $p$ is a nonzero polynomial, then the reflection of $p$ is equal to the reflection of $p$ with a monomial added to the front.
| pc = 0xc003 | a = 0x00 | x = 0x00 | y = 0x00 | sp = 0x01fd | p[NV-BDIZC] = 00110100 | MEM[0x0513] = 0x01 | | pc = 0xc006 | a = 0x00 | x = 0x00 | y = 0x00 | sp = 0x01fd | p[NV-BDIZC] = 00110100 | MEM[0x0513] = 0x02 | | pc = 0xc009 | a = 0x00 | x = 0x00 | y = 0x00 | sp = 0x01fd | p[NV-BDIZC] = 00110100 | MEM[0x0513] = 0x03 | | pc = 0xc00b | a = 0x00 | x = 0x02 | y = 0x00 | sp = 0x01fd | p[NV-BDIZC] = 00110100 | | pc = 0xc00e | a = 0x03 | x = 0x02 | y = 0x00 | sp = 0x01fd | p[NV-BDIZC] = 00110100 | MEM[0x0513] = 0x03 |
-- Conmutatividad_de_la_interseccion.lean -- Conmutatividad de la intersección. -- José A. Alonso Jiménez -- Sevilla, 24 de mayo de 2021 -- --------------------------------------------------------------------- -- --------------------------------------------------------------------- -- Demostrar que -- s ∩ t = t ∩ s -- ---------------------------------------------------------------------- import data.set.basic open set variable {α : Type} variables s t u : set α -- 1ª demostración -- =============== example : s ∩ t = t ∩ s := begin ext x, simp only [mem_inter_eq], split, { intro h, split, { exact h.2, }, { exact h.1, }}, { intro h, split, { exact h.2, }, { exact h.1, }}, end -- 2ª demostración -- =============== example : s ∩ t = t ∩ s := begin ext, simp only [mem_inter_eq], exact ⟨λ h, ⟨h.2, h.1⟩, λ h, ⟨h.2, h.1⟩⟩, end -- 3ª demostración -- =============== example : s ∩ t = t ∩ s := begin ext, exact ⟨λ h, ⟨h.2, h.1⟩, λ h, ⟨h.2, h.1⟩⟩, end -- 4ª demostración -- =============== example : s ∩ t = t ∩ s := begin ext x, simp only [mem_inter_eq], split, { rintros ⟨xs, xt⟩, exact ⟨xt, xs⟩ }, { rintros ⟨xt, xs⟩, exact ⟨xs, xt⟩ }, end -- 5ª demostración -- =============== example : s ∩ t = t ∩ s := begin ext x, exact and.comm, end -- 6ª demostración -- =============== example : s ∩ t = t ∩ s := ext (λ x, and.comm) -- 7ª demostración -- =============== example : s ∩ t = t ∩ s := by ext x; simp [and.comm] -- 8ª demostración -- =============== example : s ∩ t = t ∩ s := inter_comm s t -- 9ª demostración -- =============== example : s ∩ t = t ∩ s := by finish
In the autumn of 2009 , independent producers Timothy Gibbons and Christopher Poole approached Figure 8 Films , a North Carolinian company , with the concept of a reality series about the Brown family . Bill Hayes , the president of Figure 8 Films , said the company agreed to the idea after meeting with the Browns and deciding their lives would make a great story . Camera crews shot footage of the family in mid @-@ 2010 to be used in the first season , ending in May with the marriage of Kody Brown and Robyn Sullivan . The crews continued to film them afterward in case the series was picked up for a second season . Sister Wives was publicly introduced on August 6 , 2010 , at the Television Critics Association summer media tour in Beverly Hills , California . The series ' first episode , an hour long , was broadcast on TLC on September 26 , 2010 , and the first season continued with six half @-@ hour chapters until October 17 , 2010 .
////////////////////////////////////////////////////////////////////////////// // Boost.Assign v2 // // // // Copyright (C) 2003-2004 Thorsten Ottosen // // Copyright (C) 2011 Erwann Rogard // // Use, modification and distribution are subject to the // // Boost Software License, Version 1.0. (See accompanying file // // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) // ////////////////////////////////////////////////////////////////////////////// #ifndef BOOST_ASSIGN_V2_OPTION_MODIFIER_MAPPED_ER_2011_HPP #define BOOST_ASSIGN_V2_OPTION_MODIFIER_MAPPED_ER_2011_HPP #include <boost/assign/v2/support/keyword.hpp> #include <boost/assign/v2/support/pp/ignore.hpp> #include <boost/assign/v2/support/traits/container.hpp> #include <boost/assign/v2/option/modifier/framework.hpp> #include <boost/call_traits.hpp> #include <boost/shared_ptr.hpp> namespace boost{ namespace assign{ namespace v2{ //[syntax_option_mapped namespace modifier_tag{ template<typename Arg> struct mapped{}; }// modifier_tag namespace interpreter_aux{ template<typename Arg> class interpreter_modifier<modifier_tag::mapped<Arg> >/*<-*/ { typedef Arg arg_; // storing a copy of lambda::something has caused pbs, hence ptr typedef boost::shared_ptr<arg_> ptr_; public: interpreter_modifier() : ptr( new arg_() ) {} interpreter_modifier( kwd_ignore_, typename boost::call_traits<arg_>::param_type arg ) : ptr( new arg_( arg ) ) {} //<- #if BOOST_ASSIGN_V2_ENABLE_CPP0X //-> #define BOOST_ASSIGN_V2_arg T&& t #define BOOST_ASSIGN_V2_forward std::forward<T>( t ) //<- #else #define BOOST_ASSIGN_V2_arg T& t #define BOOST_ASSIGN_V2_forward t #endif //-> template<typename C, typename T> void impl(C& cont, BOOST_ASSIGN_V2_arg, data_tag::storage )const { cont[ t/*key*/ ] = (*this->ptr)( cont[ BOOST_ASSIGN_V2_forward ] ); } //<- #undef BOOST_ASSIGN_V2_arg #undef BOOST_ASSIGN_V2_forward //-> private: ptr_ ptr; }/*->*/; }// interpreter_aux BOOST_ASSIGN_V2_OPTION_MODIFIER_KEYWORD(mapped) BOOST_ASSIGN_V2_OPTION_MODIFIER_META_MODIFIER_TAG(mapped, modifier_tag::mapped<Arg>) //] }// v2 }// assign }// boost #endif // BOOST_ASSIGN_V2_OPTION_MODIFIER_MAPPED_ER_2011_HPP
[STATEMENT] lemma ins_list_snoc: "sorted (xs @ [x]) \<Longrightarrow> ins_list x xs = xs @ [x]" [PROOF STATE] proof (prove) goal (1 subgoal): 1. sorted (xs @ [x]) \<Longrightarrow> ins_list x xs = xs @ [x] [PROOF STEP] by(induction xs) (auto simp add: sorted_mid_iff2)
module Flexidisc.OrdList.Disjoint import Flexidisc.Dec.IsYes import Flexidisc.OrdList.Fresh import Flexidisc.OrdList.Label import Flexidisc.OrdList.Nub import Flexidisc.OrdList.Type %default total %access public export ||| A proof that two `OrdList` don't share a key. data Disjoint : (left, right : OrdList k v o) -> Type where ||| The empty `OrdList` is always `Disjoint` from another `OrdList` Nil : Disjoint [] right ||| A key in the first `OrdList` is fresh in the second `OrdList`. (::) : DecEq l => {k : l} -> IsFresh k right -> Disjoint left right -> Disjoint ((k,v) :: left) right %name Disjoint djt, dis, prf freshInMerge : Fresh l left -> Fresh l right -> Fresh l (merge left right) freshInMerge [] freshR = freshR freshInMerge (f :: fresh) [] = f :: fresh freshInMerge (f :: fresh) (g :: prf) {left = ((ll, tl) :: xs)} {right = ((lr, tr) :: hs)} with (ll < lr) | True = f :: freshInMerge fresh (g :: prf) | False = g :: freshInMerge (f :: fresh) prf invertFresh : Disjoint left ((lr, ty)::right) -> Fresh lr left invertFresh [] = [] invertFresh (fresh :: djt) = (\(f :: _) => f . sym) (getProof fresh) :: invertFresh djt disjointSmallerRight : Disjoint left (r::right) -> Disjoint left right disjointSmallerRight [] = [] disjointSmallerRight (fresh :: djt) = tailIsFresh fresh :: disjointSmallerRight djt disjointNub : Disjoint left right -> Nub left -> Nub right -> Nub (merge left right) disjointNub djt [] z = z disjointNub djt (yes :: x) [] = yes :: x disjointNub (fll :: djt) (yes :: x) (prf :: w) {left = ((ll, tl) :: xs)} {right = ((lr, tr) :: hs)} with (ll < lr) | True = freshInMerge yes (getProof fll) :: disjointNub djt x (prf :: w) | False = freshInMerge (invertFresh (fll :: djt)) prf :: disjointNub (disjointSmallerRight (fll :: djt)) (yes :: x) w
/- Copyright (c) 2022 Julian Kuelshammer. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Author : Julian Kuelshammer -/ import solutions.sheet02 /-! Real vector spaces This file defines the concept of a real vector space (as is discussed in the first lecture of Linear Algebra II and proves that ℝ² and Mat₂ are instances of it.) One further ingredient could be useful: calc expr_1 = expr_2 : begin sorry end ... = expr_3 : begin sorry end ... = expr_4 : begin sorry end Fun fact: If you only work with calc, you don't have to switch to tactic mode, i.e. you can leave out the begin ... end rw : rewrite one expression by another using a lemma. apply : Apply a statement to reduce the goal. In ordinary mathematics you would read this as. By this theorem, it suffices to prove the following ... exact : The goal that is to show is exactly the following lemma/theorem. nth_rewrite i _ : If you use rw, it will change the every occurrence of the term. Sometimes you only want to do that on a certain occurrence, that you can use nth_rewrite i to change it on the ith occurrence (starting counting with 0). conv_lhs begin ... end conv_rhs begin ... end : Solve a similar problem to the one before, they allow you to only rewrite the left or the right hand side of an equation. norm_num : Similar to ring, but only calculates explicit expressions (with actual numbers.) -/ /-- `real_vector_space V` is the type of real vector space structures on the type `V`. -/ class real_vector_space (V : Type) extends has_zero V, has_add V, has_neg V, has_scalar ℝ V : Type := (add_assoc : ∀ u v w : V, (u + v) + w = u + (v + w)) (add_comm : ∀ u v : V, u + v = v + u) (add_zero : ∀ v : V, v + 0 = v) (zero_add : ∀ v : V, 0 + v = v) (add_neg : ∀ v : V, v + (-v) = 0) (neg_add : ∀ v : V, (-v) + v = 0) (smul_assoc : ∀ (a b : ℝ) (v : V), (a * b) • v = a • (b • v)) (one_smul : ∀ v : V, (1 : ℝ) • v = v) (add_smul : ∀ (a b : ℝ) (v : V), (a + b) • v = a • v + b • v) (smul_add : ∀ (a : ℝ) (v w : V), a • (v + w) = a • v + a • w) namespace real_vector_space /- We can also add the simp attribute to statements later. -/ attribute [simp] add_assoc add_zero zero_add add_neg neg_add smul_assoc one_smul add_smul smul_add variables {V : Type} [real_vector_space V] {u v w : V} {a b : ℝ} /- Let's first let Lean know that the plane and the 2x2-matrices are real vector spaces. We have proved everything on the previous two sheets, we just have to package it nicely. -/ instance : real_vector_space ℝ² := { zero := has_zero.zero, add := has_add.add, neg := has_neg.neg, smul := has_scalar.smul, add_assoc := plane.add_assoc, add_comm := plane.add_comm, add_zero := plane.add_zero, zero_add := plane.zero_add, add_neg := by tidy, neg_add := by tidy, smul_assoc := plane.smul_assoc, one_smul := plane.one_smul, add_smul := plane.add_smul, smul_add := plane.smul_add, } instance : real_vector_space Mat₂ := { zero := has_zero.zero, add := has_add.add, neg := has_neg.neg, smul := has_scalar.smul, add_assoc := two_matrix.add_assoc, add_comm := two_matrix.add_comm, add_zero := two_matrix.add_zero, zero_add := two_matrix.zero_add, add_neg := by tidy, neg_add := by tidy, smul_assoc := two_matrix.smul_assoc, one_smul := two_matrix.one_smul, add_smul := two_matrix.add_smul, smul_add := two_matrix.smul_add, } /- We continue by proving some well-known properties which hold in (real) vector spaces. -/ lemma zero_unique_right_neutral (h : v + w = v) : w = 0 := calc w = 0 + w : (zero_add w).symm ... = (-v + v) + w : by rw neg_add ... = -v + (v + w) : by rw add_assoc ... = -v + v : by rw h ... = 0 : neg_add v lemma zero_unique_left_neutral (h : w + v = v) : w = 0 := begin rw add_comm at h, exact zero_unique_right_neutral h, end lemma zero_smul_eq_zero_vector (v : V) : (0 : ℝ) • v = 0 := begin apply zero_unique_right_neutral, calc (0 : ℝ) • v + (0 : ℝ) • v = (0 + 0 : ℝ) • v : (add_smul _ _ _).symm ... = (0 : ℝ) • v : by norm_num end lemma neg_unique_right_add_inv (h : v + w = 0) : w = -v := calc w = 0 + w : (zero_add w).symm ... = (-v + v) + w : by rw neg_add ... = -v + (v + w) : by rw add_assoc ... = -v + 0 : by rw h ... = -v : add_zero (-v) lemma neg_unique_left_add_inv (h : w + v = 0) : w = -v := begin rw add_comm at h, exact neg_unique_right_add_inv h, end lemma minus_one_smul_eq_neg : (-1 : ℝ) • v = -v := begin apply neg_unique_right_add_inv, nth_rewrite 0 (one_smul v).symm, rw ← add_smul, norm_num, rw zero_smul_eq_zero_vector end end real_vector_space /- It has been realised that the vector space axioms are not minimal, you can remove some of them and still get the same structure. Here is a minimal list that has been found (which is quite similar to the standard list, only the second axiom seems kind of weird.)-/ class minimal_vector_space_axioms (V : Type) extends has_add V, has_scalar ℝ V : Type := (add_assoc : ∀ u v w : V, (u + v) + w = u + (v + w)) (zero_smul_eq : ∀ v w : V, (0 : ℝ) • v = (0 : ℝ) • w) (one_smul : ∀ v : V, (1 : ℝ) • v = v) (smul_assoc : ∀ (a b : ℝ) (v : V), (a * b) • v = a • (b • v)) (add_smul : ∀ (a b : ℝ) (v : V), (a + b) • v = a • v + b • v) (smul_add : ∀ (a : ℝ) (v w : V), a • (v + w) = a • v + a • w) /- Note that in contrast to the vector space axioms, the axiom about the zero vector is omitted from these minimal vector space axioms. However this means that there is no reason for any vector at all to exist in `V`. So let's prove that the empty set satisfies these axioms. -/ instance : minimal_vector_space_axioms empty := { add := begin intro v, cases v end, smul := begin intros a v, cases v end, add_assoc := begin intros u v w, cases u end, zero_smul_eq := begin intros u v, cases u end, one_smul := begin intro v, cases v end, smul_assoc := begin intros a b v, cases v end, add_smul := begin intros a b v, cases v end, smul_add := begin intros a v w, cases v end, } /- Let's prove that any real_vector_space satisfies the minimal vector space axioms, which is not too difficult, ' there is only one axiom which is already included in the axioms and that is immediately true. -/ def to_minimal_vector_space_axioms (V : Type) [real_vector_space V] : minimal_vector_space_axioms V := { add_assoc := real_vector_space.add_assoc, zero_smul_eq := begin intros v w, rw [real_vector_space.zero_smul_eq_zero_vector, real_vector_space.zero_smul_eq_zero_vector] end, one_smul := real_vector_space.one_smul, smul_assoc := real_vector_space.smul_assoc, add_smul := real_vector_space.add_smul, smul_add := real_vector_space.smul_add } /- In the other direction, the difference seems larger, so let's try to prove some of the axioms which are missing. -/ lemma minimal_vector_space_axioms.add_zero (V : Type) [minimal_vector_space_axioms V] (v w : V) : v + (0 : ℝ) • w = v := begin conv_lhs begin rw ←minimal_vector_space_axioms.one_smul v end, rw [minimal_vector_space_axioms.zero_smul_eq w v, ← minimal_vector_space_axioms.add_smul, add_zero, minimal_vector_space_axioms.one_smul], end lemma minimal_vector_space_axioms.zero_add (V : Type) [minimal_vector_space_axioms V] (v w : V) : (0 : ℝ) • w + v = v := begin conv_lhs begin rw ←minimal_vector_space_axioms.one_smul v end, rw [minimal_vector_space_axioms.zero_smul_eq w v, ← minimal_vector_space_axioms.add_smul, zero_add, minimal_vector_space_axioms.one_smul], end lemma minimal_vector_space_axioms.add_neg (V : Type) [minimal_vector_space_axioms V] (v : V) : v + (-1 : ℝ) • v = (0 : ℝ) • v := begin nth_rewrite 0 ← minimal_vector_space_axioms.one_smul v, rw [← minimal_vector_space_axioms.add_smul, add_right_neg], end lemma minimal_vector_space_axioms.neg_add (V : Type) [minimal_vector_space_axioms V] (v : V) : (-1 : ℝ) • v + v = (0 : ℝ) • v := begin nth_rewrite 1 ← minimal_vector_space_axioms.one_smul v, rw [← minimal_vector_space_axioms.add_smul, add_left_neg], end /- The following is probably the most challenging one. Consider trying to prove it on paper first. -/ lemma minimal_vector_space_axioms.add_comm (V : Type) [minimal_vector_space_axioms V] (v w : V) : v + w = w + v := calc v + w = (0 : ℝ) • v + (v + w) : by rw minimal_vector_space_axioms.zero_add _ _ _ ... = ((-1 : ℝ) • v + v) + (v + w) : by rw minimal_vector_space_axioms.neg_add ... = (((-1 : ℝ) • v + v) + (v + w)) + (0 : ℝ) • w : by rw minimal_vector_space_axioms.add_zero _ _ _ ... = (((-1 : ℝ) • v + v) + (v + w)) + (w + (-1 : ℝ) • w) : by rw minimal_vector_space_axioms.add_neg ... = ((-1 : ℝ) • v + ((v + v) + (w + w))) + (-1 : ℝ) • w : begin simp [minimal_vector_space_axioms.add_assoc], end ... = (-1 : ℝ) • v + (((1 + 1 : ℝ)• v) + ((1 + 1 : ℝ) • w)) + (-1 : ℝ) • w : begin simp [minimal_vector_space_axioms.add_smul, minimal_vector_space_axioms.one_smul] end ... = ((-1 : ℝ) • v + ((1 + 1 : ℝ) • (v + w))) + (-1 : ℝ) • w : by rw minimal_vector_space_axioms.smul_add ... = ((-1 : ℝ) • v + ((v + w) + (v + w))) + (-1 : ℝ) • w : by rw [minimal_vector_space_axioms.add_smul, minimal_vector_space_axioms.one_smul] ... = ((-1 : ℝ) • v + v) + (w + v) + (w + (-1 : ℝ) • w) : by simp [minimal_vector_space_axioms.add_assoc] ... = w + v : begin rw [minimal_vector_space_axioms.neg_add, minimal_vector_space_axioms.add_neg, minimal_vector_space_axioms.zero_add, minimal_vector_space_axioms.add_zero] end /- However if we demand that the set V is nonempty, the axioms are in fact equivalent as we show with the following two results. These are `definitions` as they transport data. Often in a maths lecture we would instead say `proposition` for this, or if one is very careful `definition-proposition`. The definition is marked as `noncomputable` as it relies on choosing an arbitrary element `v` from the nonempty type `V`, for which there might not be an algorithm. -/ noncomputable def to_real_vector_space (V : Type) [minimal_vector_space_axioms V] (h : nonempty V) : real_vector_space V := { zero := begin let v := h.some, exact ((0 : ℝ) • v) end, neg := begin intro v, exact ((-1 : ℝ) • v) end, add_assoc := minimal_vector_space_axioms.add_assoc, add_comm := begin intros u v, exact minimal_vector_space_axioms.add_comm _ _ _, end, add_zero := begin intro v, change v + (0 : ℝ) • h.some = v, exact minimal_vector_space_axioms.add_zero _ _ _, end, zero_add := begin intro v, change (0 : ℝ) • h.some + v = v, exact minimal_vector_space_axioms.zero_add _ _ _, end, add_neg := begin intro v, change v + (-1 : ℝ) • v = (0 : ℝ) • h.some, rw minimal_vector_space_axioms.add_neg, exact minimal_vector_space_axioms.zero_smul_eq _ _ end, neg_add := begin intro v, change (-1 : ℝ) • v + v = (0 : ℝ) • h.some, rw minimal_vector_space_axioms.neg_add, exact minimal_vector_space_axioms.zero_smul_eq _ _ end, smul_assoc := minimal_vector_space_axioms.smul_assoc, one_smul := minimal_vector_space_axioms.one_smul, add_smul := minimal_vector_space_axioms.add_smul, smul_add := minimal_vector_space_axioms.smul_add }
module Main import System import TestRunner import ParsingTest import UML import UML.Reader -- --------------------------------------------------------------------- [ XML ] classTest : Test classTest = parseTestGood classModel "Class Bob {\n + ad : String\n}\n\n Class Alice\n\n Bob --> Alice" seqTest : Test seqTest = parseTestGood sequenceModel "data TCPMsg\n A -> B : (syn : TCPMsg)\n B -> A : (ack : TCPMsg)\n A -> B : (syn : TCPMsg, ack : TCPMsg)\n" depTest : Test depTest = parseTestGood deploymentModel "device server presentation {\n env appserver presentation {\n artifact exe policyAdminUIwar with spec specxml {\n a : \"asas\",\n b : \"asas\"\n }\n }\n properties {\n a : \"sdsd\",\n b : \"asas\"\n }\n}\n\ndevice server policy {\n env appserver policy {\n artifact exe policyServerjar with spec specxml\n properties {\n a : \"sdsd\",\n b : \"asas\"\n }\n }\n}\n\ndevice server product {\n env appserver product {\n artifact exe productServerjar\n }\n env engine rules {\n artifact doc rules\n }\n}\n\ndevice workstation user {\n env os workstation {\n artifact exe productServerUIexe\n }\n}\n\ndevice server documents {\n env os server {\n artifact exe docMngmntSystem\n }\n}\n\ndevice server dbServer {\n env engine dbms {\n artifact doc schemaproduct\n artifact doc schemapolicy\n }\n}\n\ndevice server dirServer {\n env app ldapServer {\n artifact doc GrpUsrheirarchy\n }\n}\n\ndevice server uWriteRating {\n env engine rules {\n artifact doc ratingrules\n artifact doc underwritingrules\n }\n env appserver apps {\n artifact exe underwritingenginejar\n artifact exe ratingenginejar\n }\n}\n\npresentation commsWith policy via http\npolicy commsWith uWriteRating via http\npolicy commsWith dirServer via http\npolicy commsWith dbServer via http\npolicy commsWith documents via http\ndbServer commsWith product via http\nproduct commsWith documents via http\nuser commsWith product via http\n" compTest : Test compTest = parseTestGood componentModel "data Int\ndata String\n\ndata User {\n id : String,\n name : String\n}\n\ndata Item {\n id : String,\n name : String,\n desc : String\n}\n\ndata Order {\n id : String,\n item : Items\n}\n\ncomponent Accounting {\n provides ManageOrders from Orders\n provides ManageCustomers from Customers\n requires ManageInventory from Warehouses\n\n component Customers {\n interface ManageCustomers {\n addCustomer : (c : Customer) -> Bool\n removeCustomer : (c : Customer) -> Bool\n }\n }\n\n component Orders {\n interface ManageOrders {\n createOrder : Int\n addToOrder : (p : Product) -> (orderID : Int) -> Bool\n removeFromOrder : (p : Product) -> (orderID : Int) -> Bool\n }\n requires ManageCustomers from Customers\n requires ManageInventory from Warehouses\n }\n}\n\ncomponent Warehouses {\n provides SearchInventory from Inventory\n provides ManageInventory from Inventory\n\n component Inventory {\n interface SearchInventory {\n createOrder : Int\n addToOrder : (p : Product) -> (orderID : Int) -> Bool\n removeFromOrder : (p : Product) -> (orderID : Int) -> Bool\n }\n interface ManageInventory {\n createOrder : Int\n addToOrder : (p : Product) -> (orderID : Int) -> Bool\n removeFromOrder : (p : Product) -> (orderID : Int) -> Bool\n }\n }\n}\n\ncomponent WebStore {\n provides ProductSearch from SearchEngine\n provides OnlineShopping from ShoppingCart\n provides UserSession from Authentication\n\n requires SearchInventory from Warehouses\n requires ManageOrders from Accounting\n requires ManageCustomers from Accounting\n\n component Authentication {\n interface UserSession {\n createOrder : Int\n addToOrder : (p : Product) -> (orderID : Int) -> Bool\n removeFromOrder : (p : Product) -> (orderID : Int) -> Bool\n }\n requires ManageCustomers from Accounting\n }\n\n component ShoppingCart {\n interface OnlineShopping {\n createOrder : Int\n addToOrder : (p : Product) -> (orderID : Int) -> Bool\n removeFromOrder : (p : Product) -> (orderID : Int) -> Bool\n }\n requires UserSession from Authentication\n requires ManageOrders from Accounting\n }\n\n component SearchEngine {\n interface ProductSearch {\n createOrder : Int\n addToOrder : (p : Product) -> (orderID : Int) -> Bool\n removeFromOrder : (p : Product) -> (orderID : Int) -> Bool\n\n }\n requires SearchInventory from Warehouses\n }\n\n}\n" -- -------------------------------------------------------------------- [ Main ] main : IO () main = do run $ tests (Z) [classTest, seqTest, depTest, compTest] exit 0 -- --------------------------------------------------------------------- [ EOF ]
(* Title: Kuratowski.thy Author: Lars Noschinski, TU München *) theory Kuratowski imports Arc_Walk Digraph_Component Pair_Digraph begin section {* Kuratowski Subgraphs *} text {* We consider the underlying undirected graphs. The underlying undirected graph is represented as a symmetric digraph. *} subsection {* Public definitions *} definition complete_digraph :: "nat \<Rightarrow> 'a pair_pre_digraph \<Rightarrow> bool" ("K\<^bsub>_\<^esub>") where "complete_digraph n G \<equiv> finite (pverts G) \<and> card (pverts G) = n \<and> parcs G = {(u,v). (u,v) \<in> (pverts G \<times> pverts G) \<and> u \<noteq> v}" definition complete_bipartite_digraph :: "nat \<Rightarrow> nat \<Rightarrow> 'a pair_pre_digraph \<Rightarrow> bool" ("K\<^bsub>_,_\<^esub>") where "complete_bipartite_digraph m n G \<equiv> finite (pverts G) \<and> (\<exists>U V. pverts G = U \<union> V \<and> U \<inter> V = {} \<and> card U = m \<and> card V = n \<and> parcs G = U \<times> V \<union> V \<times> U)" lemma pair_graphI_complete: assumes "K\<^bsub>n\<^esub> G" shows "pair_graph G" proof have "finite (pverts G \<times> pverts G)" "parcs G \<subseteq> pverts G \<times> pverts G" using assms by (auto simp: complete_digraph_def) then show "finite (parcs G)" by (rule rev_finite_subset) qed (insert assms, auto simp: complete_digraph_def symmetric_def split: prod.splits intro: symI) lemma pair_graphI_complete_bipartite: assumes "K\<^bsub>m,n\<^esub> G" shows "pair_graph G" using assms by unfold_locales (fastforce simp: complete_bipartite_digraph_def symmetric_def split: prod.splits intro: symI)+ definition planar :: "'a pair_pre_digraph \<Rightarrow> bool" where "planar G \<equiv> \<not>(\<exists>H. subgraph (with_proj H) G \<and> (\<exists>K. subdivision K H \<and> (K\<^bsub>3,3\<^esub> K \<or> K\<^bsub>5\<^esub> K)))" subsection {* Inner vertices of a walk *} context pre_digraph begin definition (in pre_digraph) inner_verts :: "'b awalk \<Rightarrow> 'a list" where "inner_verts p \<equiv> tl (map (tail G) p)" lemma inner_verts_Nil[simp]: "inner_verts [] = []" by (auto simp: inner_verts_def) lemma inner_verts_singleton[simp]: "inner_verts [x] = []" by (auto simp: inner_verts_def) lemma (in wf_digraph) inner_verts_Cons: assumes "awalk u (e # es) v" shows "inner_verts (e # es) = (if es \<noteq> [] then head G e # inner_verts es else [])" using assms by (induct es) (auto simp: inner_verts_def) lemma (in - ) inner_verts_with_proj_def: "pre_digraph.inner_verts (with_proj G) p = tl (map fst p)" unfolding pre_digraph.inner_verts_def by simp lemma inner_verts_conv: "inner_verts p = butlast (tl (awalk_verts u p))" unfolding inner_verts_def awalk_verts_conv by simp lemma (in fin_digraph) set_inner_verts: assumes "apath u p v" shows "set (inner_verts p) = set (awalk_verts u p) - {u,v}" proof (cases "length p < 2") case True with assms show ?thesis by (cases p) (auto simp: inner_verts_conv[of _ u] apath_def) next case False have "awalk_verts u p = u # inner_verts p @ [v]" using assms False length_awalk_verts[of u p] inner_verts_conv[of p u] by (cases "awalk_verts u p") (auto simp: apath_def awalk_conv) then show ?thesis using assms by (auto simp: apath_def) qed lemma in_set_inner_verts_appendI_l: assumes "u \<in> set (inner_verts p)" shows "u \<in> set (inner_verts (p @ q))" using assms by (induct p) (auto simp: inner_verts_def) lemma in_set_inner_verts_appendI_r: assumes "u \<in> set (inner_verts q)" shows "u \<in> set (inner_verts (p @ q))" using assms by (induct p) (auto simp: inner_verts_def dest: list_set_tl) end subsection {* Walks with Restricted Vertices *} definition verts3 :: "('a, 'b) pre_digraph \<Rightarrow> 'a set" where "verts3 G \<equiv> {v \<in> verts G. 2 < in_degree G v}" text {* A path were only the end nodes may be in @{term V} *} (* From this definition, we at least need the following properties: - The end nodes must be distinct (to match graph computed by the C code) - If there is only one connection between u and v, p must be unique This means we cannot replace apath by awalk, without adding at least the following restrictions: - u \<noteq> v - progressing p It might be possible to drop "progressing p" if we talk about trails instead *) definition (in pre_digraph) gen_iapath :: "'a set \<Rightarrow> 'a \<Rightarrow> 'b awalk \<Rightarrow> 'a \<Rightarrow> bool" where "gen_iapath V u p v \<equiv> u \<in> V \<and> v \<in> V \<and> apath u p v \<and> set (inner_verts p) \<inter> V = {} \<and> p \<noteq> []" abbreviation (in pre_digraph) (input) iapath :: "'a \<Rightarrow> 'b awalk \<Rightarrow> 'a \<Rightarrow> bool" where "iapath u p v \<equiv> gen_iapath (verts3 G) u p v" definition gen_contr_graph :: "('a,'b) pre_digraph \<Rightarrow> 'a set \<Rightarrow> 'a pair_pre_digraph" where "gen_contr_graph G V \<equiv> \<lparr> pverts = V, parcs = {(u,v). \<exists>p. pre_digraph.gen_iapath G V u p v} \<rparr>" abbreviation (input) contr_graph :: "'a pair_pre_digraph \<Rightarrow> 'a pair_pre_digraph" where "contr_graph G \<equiv> gen_contr_graph G (verts3 G)" subsection {* Properties of subdivisions *} lemma (in pair_pseudo_graph) verts3_subdivide: assumes "e \<in> parcs G" "w \<notin> pverts G" shows"verts3 (subdivide G e w) = verts3 G" proof - let ?sG = "subdivide G e w" obtain u v where e_conv[simp]: "e = (u,v)" by (cases e) auto from `w \<notin> pverts G` have w_arcs: "(u,w) \<notin> parcs G" "(v,w) \<notin> parcs G" "(w,u) \<notin> parcs G" "(w,v) \<notin> parcs G" by (auto dest: wellformed) have G_arcs: "(u,v) \<in> parcs G" "(v,u) \<in> parcs G" using `e \<in> parcs G` by (auto simp: arcs_symmetric) have "{v \<in> pverts G. 2 < in_degree G v} = {v \<in> pverts G. 2 < in_degree ?sG v}" proof - { fix x assume "x \<in> pverts G" def card_eq \<equiv> "\<lambda>x. in_degree ?sG x = in_degree G x" have "in_arcs ?sG u = (in_arcs G u - {(v,u)}) \<union> {(w,u)}" "in_arcs ?sG v = (in_arcs G v - {(u,v)}) \<union> {(w,v)}" using w_arcs G_arcs by auto then have "card_eq u" "card_eq v" unfolding card_eq_def in_degree_def using w_arcs G_arcs by (simp_all add: card_insert_disjoint finite_in_arcs card_Suc_Diff1 del: card_Diff_insert) moreover have "x \<notin> {u,v} \<Longrightarrow> in_arcs ?sG x = in_arcs G x" using `x \<in> pverts G` `w \<notin> pverts G` by (auto simp: ) then have "x \<notin> {u,v} \<Longrightarrow> card_eq x" by (simp add: in_degree_def card_eq_def) ultimately have "card_eq x" by fast then have "in_degree G x = in_degree ?sG x" unfolding card_eq_def by simp } then show ?thesis by auto qed also have "\<dots> = {v\<in>pverts ?sG. 2 < in_degree ?sG v}" proof - have "in_degree ?sG w \<le> 2" proof - have "in_arcs ?sG w = {(u,w), (v,w)}" using `w \<notin> pverts G` G_arcs(1) by (auto simp: wellformed') then show ?thesis unfolding in_degree_def by (auto simp: card_insert_if) qed then show ?thesis using G_arcs assms by auto qed finally show ?thesis by (simp add: verts3_def) qed lemma sd_path_Nil_iff: "sd_path e w p = [] \<longleftrightarrow> p = []" by (cases "(e,w,p)" rule: sd_path.cases) auto lemma (in pair_pseudo_graph) gen_iapath_sd_path: fixes e :: "'a \<times> 'a" and w :: 'a assumes elems: "e \<in> parcs G" "w \<notin> pverts G" assumes V: "V \<subseteq> pverts G" assumes path: "gen_iapath V u p v" shows "pre_digraph.gen_iapath (subdivide G e w) V u (sd_path e w p) v" proof - obtain x y where e_conv: "e = (x,y)" by (cases e) auto interpret S: pair_pseudo_graph "subdivide G e w" using elems by (auto intro: pair_pseudo_graph_subdivide) from path have "apath u p v" by (auto simp: gen_iapath_def) then have apath_sd: "S.apath u (sd_path e w p) v" and set_ev_sd: "set (S.awalk_verts u (sd_path e w p)) \<subseteq> set (awalk_verts u p) \<union> {w}" using elems by (rule apath_sd_path set_awalk_verts_sd_path)+ have "w \<notin> {u,v}" using elems `apath u p v` by (auto simp: apath_def awalk_hd_in_verts awalk_last_in_verts) have "set (S.inner_verts (sd_path e w p)) = set (S.awalk_verts u (sd_path e w p)) - {u,v}" using apath_sd by (rule S.set_inner_verts) also have "\<dots> \<subseteq> set (awalk_verts u p) \<union> {w} - {u,v}" using set_ev_sd by auto also have "\<dots> = set (inner_verts p) \<union> {w}" using set_inner_verts[OF `apath u p v`] `w \<notin> {u,v}` by blast finally have "set (S.inner_verts (sd_path e w p)) \<inter> V \<subseteq> (set (inner_verts p) \<union> {w}) \<inter> V" using V by blast also have "\<dots> \<subseteq> {}" using path elems V unfolding gen_iapath_def by auto finally show ?thesis using apath_sd elems path by (auto simp: gen_iapath_def S.gen_iapath_def sd_path_Nil_iff) qed lemma (in pair_pseudo_graph) assumes elems: "e \<in> parcs G" "w \<notin> pverts G" assumes V: "V \<subseteq> pverts G" assumes path: "pre_digraph.gen_iapath (subdivide G e w) V u p v" shows gen_iapath_co_path: "gen_iapath V u (co_path e w p) v" (is ?thesis_path) and set_awalk_verts_co_path': "set (awalk_verts u (co_path e w p)) = set (awalk_verts u p) - {w}" (is ?thesis_set) proof - interpret S: pair_pseudo_graph "subdivide G e w" using elems by (rule pair_pseudo_graph_subdivide) have uv: "u \<in> pverts G" "v \<in> pverts G" "S.apath u p v" using V path by (auto simp: S.gen_iapath_def) note co = apath_co_path[OF elems uv] set_awalk_verts_co_path[OF elems uv] show ?thesis_set by (fact co) show ?thesis_path using co path unfolding gen_iapath_def S.gen_iapath_def using elems by (clarsimp simp add: set_inner_verts[of u] S.set_inner_verts[of u]) blast qed subsection {* Pair Graphs *} context pair_pseudo_graph begin lemma gen_iapath_rev_path: "gen_iapath V v (rev_path p) u = gen_iapath V u p v" (is "?L = ?R") proof - { fix u p v assume "gen_iapath V u p v" then have "butlast (tl (awalk_verts v (rev_path p))) = rev (butlast (tl (awalk_verts u p)))" by (auto simp: tl_rev butlast_rev butlast_tl awalk_verts_rev_path gen_iapath_def apath_def) with `gen_iapath V u p v` have "gen_iapath V v (rev_path p) u" by (auto simp: gen_iapath_def apath_def inner_verts_conv[symmetric] awalk_verts_rev_path) } note RL = this show ?thesis by (auto dest: RL intro: RL) qed lemma inner_verts_rev_path: assumes "awalk u p v" shows "inner_verts (rev_path p) = rev (inner_verts p)" by (metis assms butlast_rev butlast_tl awalk_verts_rev_path inner_verts_conv tl_rev) lemma awalk_Cons_deg2_unique: assumes "apath u p v" "p \<noteq> []" assumes "in_degree G u \<le> 2" assumes "apath u1 (e1 # p) v" "apath u2 (e2 # p) v" shows "e1 = e2" proof (cases p) case (Cons e es) show ?thesis proof (rule ccontr) assume "e1 \<noteq> e2" def x \<equiv> "snd e" then have e_unf:"e = (u,x)" using `apath u p v` Cons by (auto simp: apath_simps) then have ei_unf: "e1 = (u1, u)" "e2 = (u2, u)" using Cons assms by (auto simp: apath_simps prod_eqI) with assms `e = (u,x)` `e1 \<noteq> e2` have "u1 \<noteq> u2" "x \<noteq> u1" "x \<noteq> u2" by (auto simp: apath_simps `p = _` hd_in_awalk_verts) moreover have "{(u1, u), (u2, u), (x,u)} \<subseteq> parcs G" using e_unf ei_unf Cons assms by (auto simp: apath_simps intro: arcs_symmetric) then have "finite (in_arcs G u)" and "{(u1, u), (u2, u), (x,u)} \<subseteq> in_arcs G u" by auto then have "card ({(u1, u), (u2, u), (x,u)}) \<le> in_degree G u" unfolding in_degree_def by (rule card_mono) ultimately show "False" using `in_degree G u \<le> 2` by auto qed qed (simp add: `p \<noteq> []`) lemma same_awalk_by_length: assumes walk: "apath u1 p v" "apath u2 q v" "last p = last q" and verts: "set (inner_verts p) \<inter> verts3 G = {}" "set (inner_verts q) \<inter> verts3 G = {}" and len: "length p = length q" shows "p = q" using len walk verts proof (induct p q arbitrary: u1 u2 rule: list_induct2) case (Cons e1 es1 e2 es2) show ?case proof (cases "length es1 = 0") case True then show ?thesis using Cons by simp next case False from Cons have "apath (snd e1) es1 v" "snd e1 \<in> pverts G" by (auto simp: apath_Cons_iff) moreover have "snd e1 \<in> set (inner_verts (e1 # es1))" using False `apath u1 (e1 # es1) v` by (auto simp: apath_def inner_verts_Cons) then have "in_degree G (snd e1) \<le> 2" using Cons(6) `snd e1 \<in> pverts G` by (auto simp: verts3_def) moreover from Cons.prems (4-5) have "set (inner_verts es1) \<inter> verts3 G = {}" "set (inner_verts es2) \<inter> verts3 G = {}" unfolding inner_verts_def by (auto dest!: list_set_tl) with Cons have "es1 = es2" by (intro Cons) (auto simp: apath_Cons_iff split: split_if_asm) moreover then have "apath u2 (e2 # es1) v" using Cons by simp ultimately show ?thesis using False Cons.prems by (auto simp: apath_simps intro: awalk_Cons_deg2_unique) qed qed simp lemma same_awalk_by_same_end: assumes V: "verts3 G \<subseteq> V" "V \<subseteq> pverts G" and walk: "apath u p v" "apath w q v" "last p = last q" "p \<noteq> []" "q \<noteq> []" and tail: "u \<in> V" "w \<in> V" and inner_verts: "set (inner_verts p) \<inter> V = {}" "set (inner_verts q) \<inter> V = {}" shows "p = q" proof (cases "length p" "length q" rule: linorder_cases) { fix u v w p q assume walk: "apath u p v" "apath w q v" "last p = last q" "p \<noteq> []" "q \<noteq> []" and tail: "u \<in> V" "w \<in> V" and inner_verts: "set (inner_verts p) \<inter> V = {}" "set (inner_verts q) \<inter> V = {}" and less: "length p < length q" def q1 \<equiv> "take (length q - length p) q" and q2 \<equiv> "drop (length q - length p) q" with less have "q = q1 @ q2" "length p = length q2" "q1 \<noteq> []" by auto note walk(1) moreover have "apath (awlast w q1) q2 v" using `q = q1 @ q2` walk by (auto simp: apath_append_iff) moreover have "last p = last q2" using walk(3) `q = q1 @ q2` `length p = length q2` by (auto simp: last_append) moreover have "set (inner_verts p) \<inter> verts3 G = {}" "set (inner_verts q2) \<inter> verts3 G = {}" using inner_verts `q = q1 @ q2` V by (auto dest: in_set_inner_verts_appendI_r) ultimately have "p = q2" using `length p = length q2` by (rule same_awalk_by_length) then have "awlast w q1 = u" using walk unfolding `q = q1 @ q2` by (auto simp: apath_def dest: awalk_ends) moreover have "cas w q v" using walk by (auto simp: apath_def) ultimately have "u \<in> set (inner_verts q)" using `q1 \<noteq> []` `p \<noteq> []` `apath w q v` unfolding `q = q1 @ q2` `p = q2` by (auto simp: apath_def inner_verts_conv[of _ w] awalk_verts_conv' last_map butlast_append) with `u \<in> V` inner_verts(2) have "p = q" by auto } note less_rule = this { case less with walk tail inner_verts show ?thesis by (rule less_rule) } { case equal with assms show ?thesis by (intro same_awalk_by_length) auto } { case greater with walk tail inner_verts show ?thesis by (metis less_rule) } qed lemma same_awalk_by_common_arc: assumes V: "verts3 G \<subseteq> V" "V \<subseteq> pverts G" assumes walk: "apath u p v" "apath w q x" assumes iv_not_in_V: "set (inner_verts p) \<inter> V = {}" "set (inner_verts q) \<inter> V = {}" assumes ends_in_V: "{u,v,w,x} \<subseteq> V" assumes arcs: "e \<in> set p" "e \<in> set q" shows "p = q" proof - from arcs obtain p1 p2 where p_decomp: "p = p1 @ e # p2" by (metis in_set_conv_decomp_first) from arcs obtain q1 q2 where q_decomp: "q = q1 @ e # q2" by (metis in_set_conv_decomp_first) { def p1' \<equiv> "p1 @ [e]" and q1' \<equiv> "q1 @ [e]" then have decomp: "p = p1' @ p2" "q = q1' @ q2" and "awlast u p1' = snd e" "awlast w q1' = snd e" using p_decomp q_decomp by (auto simp: awlast_append) then have "apath u p1' (snd e)" "apath w q1' (snd e)" using walk by (auto simp: apath_append_iff) moreover have "last p1' = last q1'" "p1' \<noteq> []" "q1' \<noteq> []" by (auto simp: p1'_def q1'_def) moreover have "u \<in> V" "w \<in> V" "set (inner_verts p1') \<inter> V = {}" "set (inner_verts q1') \<inter> V = {}" using ends_in_V iv_not_in_V unfolding decomp by (auto intro: in_set_inner_verts_appendI_l in_set_inner_verts_appendI_r) ultimately have "p1' = q1'" by (rule same_awalk_by_same_end[OF V]) } moreover { def p2' \<equiv> "rev_path (e # p2)" and q2' \<equiv> "rev_path (e # q2)" then have decomp: "p = p1 @ rev_path p2'" "q = q1 @ rev_path q2'" using p_decomp q_decomp by auto moreover have "awlast u p1 = fst e" "awlast w q1 = fst e" using p_decomp q_decomp walk by (auto simp: apath_def) ultimately have "apath v p2' (fst e)" "apath x q2' (fst e)" using walk by (auto simp: apath_append_iff) moreover have "last p2' = last q2'" "p2' \<noteq> []" "q2' \<noteq> []" by (auto simp: p2'_def q2'_def) moreover have "v \<in> V" "x \<in> V" using ends_in_V by auto moreover have "set (inner_verts (rev_path p2')) \<inter> V = {}" "set (inner_verts (rev_path q2')) \<inter> V = {}" using iv_not_in_V unfolding decomp by (auto intro: in_set_inner_verts_appendI_l in_set_inner_verts_appendI_r) then have "set (inner_verts p2') \<inter> V = {}" "set (inner_verts q2') \<inter> V = {}" using `apath v p2' (fst e)` `apath x q2' (fst e)` by (auto simp: inner_verts_rev_path apath_def) ultimately have "p2' = q2'" by (rule same_awalk_by_same_end[OF V]) } ultimately show "p = q" using p_decomp q_decomp by (auto simp: rev_path_eq) qed lemma same_gen_iapath_by_common_arc: assumes V: "verts3 G \<subseteq> V" "V \<subseteq> pverts G" assumes path: "gen_iapath V u p v" "gen_iapath V w q x" assumes arcs: "e \<in> set p" "e \<in> set q" shows "p = q" proof - from path have awalk: "apath u p v" "apath w q x" and in_V: "set (inner_verts p) \<inter> V = {}" "set (inner_verts q) \<inter> V = {}" "{u,v,w,x} \<subseteq> V" by (auto simp: gen_iapath_def) from V awalk in_V arcs show ?thesis by (rule same_awalk_by_common_arc) qed end subsection {* Slim graphs *} text {* We define the notion of a slim graph. The idea is that for a slim graph @{term G}, @{term G} is a subdivision of @{term "contr_graph G"}. *} context pair_pre_digraph begin definition (in pair_pre_digraph) is_slim :: "'a set \<Rightarrow> bool" where "is_slim V \<equiv> (\<forall>v \<in> pverts G. v \<in> V \<or> in_degree G v \<le> 2 \<and> (\<exists>x p y. gen_iapath V x p y \<and> v \<in> set (awalk_verts x p))) \<and> (\<forall>e \<in> parcs G. \<exists>x p y. gen_iapath V x p y \<and> e \<in> set p) \<and> (\<forall>u v p q. (gen_iapath V u p v \<and> gen_iapath V u q v) \<longrightarrow> p = q) \<and> V \<subseteq> pverts G" definition direct_arc :: "'a \<times> 'a \<Rightarrow> 'a \<times> 'a" where "direct_arc uv \<equiv> SOME e. {fst uv , snd uv} = {fst e, snd e}" definition choose_iapath :: "'a \<Rightarrow> 'a \<Rightarrow> ('a \<times> 'a) awalk" where "choose_iapath u v \<equiv> (let chosen_path = (\<lambda>u v. SOME p. iapath u p v) in if direct_arc (u,v) = (u,v) then chosen_path u v else rev_path (chosen_path v u))" (* XXX: Replace "parcs (contr_graph G)" by its definition *) definition slim_paths :: "('a \<times> ('a \<times> 'a) awalk \<times> 'a) set" where "slim_paths \<equiv> (\<lambda>e. (fst e, choose_iapath (fst e) (snd e), snd e)) ` parcs (contr_graph G)" definition slim_verts :: "'a set" where "slim_verts \<equiv> verts3 G \<union> (\<Union>(u,p,_) \<in> slim_paths. set (awalk_verts u p))" definition slim_arcs :: "'a rel" where "slim_arcs \<equiv> \<Union>(_,p,_) \<in> slim_paths. set p" text {* Computes a slim subgraph for an arbitrary @{term pair_digraph} *} definition slim :: "'a pair_pre_digraph" where "slim \<equiv> \<lparr> pverts = slim_verts, parcs = slim_arcs \<rparr>" end context pair_pseudo_graph begin lemma choose_iapath: assumes "\<exists>p. iapath u p v" shows "iapath u (choose_iapath u v) v" proof (cases "direct_arc (u,v) = (u,v)") def chosen \<equiv> "\<lambda>u v. SOME p. iapath u p v" { case True have "iapath u (chosen u v) v" unfolding chosen_def by (rule someI_ex) (rule assms) then show ?thesis using True by (simp add: choose_iapath_def chosen_def) } { case False from assms obtain p where "iapath u p v" by auto then have "iapath v (rev_path p) u" by (simp add: gen_iapath_rev_path) then have "iapath v (chosen v u) u" unfolding chosen_def by (rule someI) then show ?thesis using False by (simp add: choose_iapath_def chosen_def gen_iapath_rev_path) } qed lemma slim_simps: "pverts slim = slim_verts" "parcs slim = slim_arcs" by (auto simp: slim_def) lemma slim_paths_in_G: assumes "(u,p,v) \<in> slim_paths" shows "iapath u p v" using assms choose_iapath by (fastforce simp: gen_contr_graph_def slim_paths_def) lemma verts_slim_in_G: "pverts slim \<subseteq> pverts G" by (auto simp: slim_simps slim_verts_def verts3_def gen_iapath_def apath_def dest!: slim_paths_in_G elim!: awalkE) lemma verts3_in_slim_G[simp]: assumes "x \<in> verts3 G" shows "x \<in> pverts slim" using assms by (auto simp: slim_simps slim_verts_def) lemma arcs_slim_in_G: "parcs slim \<subseteq> parcs G" by (auto simp: slim_simps slim_arcs_def gen_iapath_def apath_def dest!: slim_paths_in_G elim!: awalkE) lemma slim_paths_in_slimG: assumes "(u,p,v) \<in> slim_paths" shows "pre_digraph.gen_iapath slim (verts3 G) u p v \<and> p \<noteq> []" proof - from assms have arcs: "\<And>e. e \<in> set p \<Longrightarrow> e \<in> parcs slim" by (auto simp: slim_simps slim_arcs_def) moreover from assms have "gen_iapath (verts3 G) u p v" and "p \<noteq> []" using slim_paths_in_G by (auto simp: gen_iapath_def) ultimately show ?thesis by (auto simp: pre_digraph.gen_iapath_def pre_digraph.apath_def pre_digraph.awalk_def inner_verts_with_proj_def) qed lemma direct_arc_swapped: "direct_arc (u,v) = direct_arc (v,u)" by (simp add: direct_arc_def insert_commute) have "\<exists>p::'a \<times> 'a. {u,v} = {fst p, snd p}" by (rule exI[where x="(u,v)"]) auto then have "{u,v} = {fst (f {u,v}), snd (f {u,v})}" unfolding f_def Eps_split by (rule someI_ex) then have "f {u,v} = (u,v) \<or> f {u,v} = (v,u)" by (auto simp: doubleton_eq_iff prod_eq_iff) then show ?thesis by (auto simp: direct_arc_def f_def) qed lemma rev_path_choose_iapath: assumes "u \<noteq> v" shows "rev_path (choose_iapath u v) = choose_iapath v u" using assms direct_arc_chooses[of u v] by (auto simp: choose_iapath_def direct_arc_swapped) lemma pair_pseudo_graph_slim: "pair_pseudo_graph slim" proof show "finite (pverts slim)" using verts_slim_in_G finite_verts by (rule finite_subset) show "finite (parcs slim)" using arcs_slim_in_G finite_arcs by (rule finite_subset) next fix e assume A: "e \<in> parcs slim" then obtain u p v where "(u,p,v) \<in> slim_paths" "e \<in> set p" by (auto simp: slim_simps slim_arcs_def) with A have "iapath u p v" by (auto simp: dest: slim_paths_in_G) with `e \<in> set p` have "fst e \<in> set (awalk_verts u p)" "snd e \<in> set (awalk_verts u p)" by (auto simp: set_awalk_verts gen_iapath_def apath_def) moreover from `_ \<in> slim_paths` have "set (awalk_verts u p) \<subseteq> pverts slim" by (auto simp: slim_simps slim_verts_def) ultimately show "fst e \<in> pverts slim" "snd e \<in> pverts slim" by auto next { fix e assume "e \<in> parcs slim" then obtain u p v where "(u,p,v) \<in> slim_paths" and "e \<in> set p" by (auto simp: slim_simps slim_arcs_def) moreover then have "iapath u p v" and "p \<noteq> []" by (auto dest: slim_paths_in_G) then have "iapath v (rev_path p) u" and "rev_path p \<noteq> []" by (auto simp: gen_iapath_rev_path) then have "(v,u) \<in> parcs (contr_graph G)" by (auto simp: gen_contr_graph_def) moreover from `iapath u p v` have "u \<noteq> v" by (auto simp: gen_iapath_def dest: apath_nonempty_ends) ultimately have "(v, rev_path p, u) \<in> slim_paths" by (auto simp: slim_paths_def rev_path_choose_iapath intro: rev_image_eqI) moreover from `e \<in> set p` have "(snd e, fst e) \<in> set (rev_path p)" by (induct p) auto ultimately have "(snd e, fst e) \<in> parcs slim" by (auto simp: slim_simps slim_arcs_def) } then show "symmetric slim" unfolding symmetric_conv by simp (metis fst_conv snd_conv) qed lemma subgraph_slim: "subgraph slim G" proof (rule subgraphI) interpret H: pair_pseudo_graph "slim" by (rule pair_pseudo_graph_slim) intro_locales show "verts slim \<subseteq> verts G" "arcs slim \<subseteq> arcs G" by (auto simp: verts_slim_in_G arcs_slim_in_G) show "compatible G slim" .. show "wf_digraph slim" "wf_digraph G" by unfold_locales qed lemma giapath_if_slim_giapath: assumes "pre_digraph.gen_iapath slim (verts3 G) u p v" shows "gen_iapath (verts3 G) u p v" using assms verts_slim_in_G arcs_slim_in_G by (auto simp: pre_digraph.gen_iapath_def pre_digraph.apath_def pre_digraph.awalk_def inner_verts_with_proj_def) lemma slim_giapath_if_giapath: assumes "gen_iapath (verts3 G) u p v" shows "\<exists>p. pre_digraph.gen_iapath slim (verts3 G) u p v" (is "\<exists>p. ?P p") proof from assms have choose_arcs: "\<And>e. e \<in> set (choose_iapath u v) \<Longrightarrow> e \<in> parcs slim" by (fastforce simp: slim_simps slim_arcs_def slim_paths_def gen_contr_graph_def) moreover from assms have choose: "iapath u (choose_iapath u v) v" by (intro choose_iapath) (auto simp: gen_iapath_def) ultimately show "?P (choose_iapath u v)" by (auto simp: pre_digraph.gen_iapath_def pre_digraph.apath_def pre_digraph.awalk_def inner_verts_with_proj_def) qed lemma contr_graph_slim_eq: "gen_contr_graph slim (verts3 G) = contr_graph G" using giapath_if_slim_giapath slim_giapath_if_giapath by (fastforce simp: gen_contr_graph_def) lemma verts3_slim_in_verts3: assumes "v \<in> verts3 slim" shows "v \<in> verts3 G" proof - from assms have "2 < in_degree slim v" by (auto simp: verts3_def) also have "\<dots> \<le> in_degree G v" using subgraph_slim by (rule subgraph_in_degree) finally show ?thesis using assms subgraph_slim by (fastforce simp: verts3_def) qed lemma slim_is_slim: "pair_pre_digraph.is_slim slim (verts3 G)" proof (unfold pair_pre_digraph.is_slim_def, safe) interpret S: pair_pseudo_graph slim by (rule pair_pseudo_graph_slim) { fix v assume "v \<in> pverts slim" "v \<notin> verts3 G" then have "in_degree G v \<le> 2" using verts_slim_in_G by (auto simp: verts3_def) then show "in_degree slim v \<le> 2" using subgraph_in_degree[OF subgraph_slim, of v] by fastforce next fix w assume "w \<in> pverts slim" "w \<notin> verts3 G" then obtain u p v where upv: "(u, p, v) \<in> slim_paths" "w \<in> set (awalk_verts u p)" by (auto simp: slim_simps slim_verts_def) moreover then have "S.gen_iapath (verts3 G) u p v" using slim_paths_in_slimG by auto ultimately show "\<exists>x q y. S.gen_iapath (verts3 G) x q y \<and> w \<in> set (awalk_verts x q)" by auto next fix u v assume "(u,v) \<in> parcs slim" then obtain x p y where "(x, p, y) \<in> slim_paths" "(u,v) \<in> set p" by (auto simp: slim_simps slim_arcs_def) then have "S.gen_iapath (verts3 G) x p y \<and> (u,v) \<in> set p" using slim_paths_in_slimG by auto then show "\<exists>x p y. S.gen_iapath (verts3 G) x p y \<and> (u,v) \<in> set p" by blast next fix u v p q assume paths: "S.gen_iapath (verts3 G) u p v" "S.gen_iapath (verts3 G) u q v" have V: "verts3 slim \<subseteq> verts3 G" "verts3 G \<subseteq> pverts slim" by (auto simp: verts3_slim_in_verts3) have "p = [] \<or> q = [] \<Longrightarrow> p = q" using paths by (auto simp: S.gen_iapath_def dest: S.apath_ends) moreover { assume "p \<noteq> []" "q \<noteq> []" { fix u p v assume "p \<noteq> []" and path: "S.gen_iapath (verts3 G) u p v" then obtain e where "e \<in> set p" by (metis last_in_set) then have "e \<in> parcs slim" using path by (auto simp: S.gen_iapath_def S.apath_def) then obtain x r y where "(x,r,y) \<in> slim_paths" "e \<in> set r" by (auto simp: slim_simps slim_arcs_def) then have "S.gen_iapath (verts3 G) x r y" by (metis slim_paths_in_slimG) with `e \<in> set r` `e \<in> set p` path have "p = r" by (auto intro: S.same_gen_iapath_by_common_arc[OF V]) then have "x = u" "y = v" using path `S.gen_iapath (verts3 G) x r y` `p = r` `p \<noteq> []` by (auto simp: S.gen_iapath_def S.apath_def dest: S.awalk_ends) then have "(u,p,v) \<in> slim_paths" using `p = r` `(x,r,y) \<in> slim_paths` by simp } note obt = this from `p \<noteq> []` `q \<noteq> []` paths have "(u,p,v) \<in> slim_paths" "(u,q,v) \<in> slim_paths" by (auto intro: obt) then have "p = q" by (auto simp: slim_paths_def) } ultimately show "p = q" by metis } qed auto lemma assumes p: "gen_iapath (pverts G) u p v" shows gen_iapath_triv_path: "p = [(u,v)]" and gen_iapath_triv_arc: "(u,v) \<in> parcs G" proof - have "set (inner_verts p) = {}" proof - have *: "\<And>A B :: 'a set. \<lbrakk>A \<subseteq> B; A \<inter> B = {}\<rbrakk> \<Longrightarrow> A = {}" by blast have "set (inner_verts p) = set (awalk_verts u p) - {u, v}" using p by (simp add: set_inner_verts gen_iapath_def) also have "\<dots> \<subseteq> pverts G" using p unfolding gen_iapath_def apath_def awalk_conv by auto finally show ?thesis using p by (rule_tac *) (auto simp: gen_iapath_def) qed then have "inner_verts p = []" by simp then show "p = [(u,v)]" using p by (cases p) (auto simp: gen_iapath_def apath_def inner_verts_def split: split_if_asm) then show "(u,v) \<in> parcs G" using p by (auto simp: gen_iapath_def apath_def) qed lemma gen_contr_triv: assumes "is_slim V" "pverts G = V" shows "gen_contr_graph G V = G" proof - let ?gcg = "gen_contr_graph G V" from assms have "pverts ?gcg = pverts G" by (auto simp: gen_contr_graph_def is_slim_def) moreover have "parcs ?gcg = parcs G" proof (rule set_eqI, safe) fix u v assume "(u,v) \<in> parcs ?gcg" then obtain p where "gen_iapath V u p v" by (auto simp: gen_contr_graph_def) then show "(u,v) \<in> parcs G" using gen_iapath_triv_arc `pverts G = V` by auto next fix u v assume "(u,v) \<in> parcs G" with assms obtain x p y where path: "gen_iapath V x p y" "(u,v) \<in> set p" by (auto simp: is_slim_def) with `pverts G = V` have "p = [(x,y)]" by (intro gen_iapath_triv_path) auto then show "(u,v) \<in> parcs ?gcg" using path by (auto simp: gen_contr_graph_def) qed ultimately show "?gcg = G" by auto qed end subsection {* Contraction Preserves Kuratowski-Subgraph-Property *} lemma (in pair_pseudo_graph) in_degree_contr: assumes "v \<in> V" and V: "verts3 G \<subseteq> V" "V \<subseteq> verts G" shows "in_degree (gen_contr_graph G V) v \<le> in_degree G v" proof - have fin: "finite {(u, p). gen_iapath V u p v}" proof - have "{(u, p). gen_iapath V u p v} \<subseteq> (\<lambda>(u,p,_). (u,p)) ` {(u,p,v). apath u p v}" by (force simp: gen_iapath_def) with apaths_finite_triple show ?thesis by (rule finite_surj) qed have io_snd: "inj_on snd {(u,p). gen_iapath V u p v}" by (rule inj_onI) (auto simp: gen_iapath_def apath_def dest: awalk_ends) have io_last: "inj_on last {p. \<exists>u. gen_iapath V u p v}" proof (rule inj_onI, safe) fix u1 u2 p1 p2 assume A: "last p1 = last p2" and B: "gen_iapath V u1 p1 v" "gen_iapath V u2 p2 v" from B have "last p1 \<in> set p1" "last p2 \<in> set p2" by (auto simp: gen_iapath_def) with A have "last p1 \<in> set p1" "last p1 \<in> set p2" by simp_all with V[simplified] B show "p1 = p2" by (rule same_gen_iapath_by_common_arc) qed have "in_degree (gen_contr_graph G V) v = card ((\<lambda>(u,_). (u,v)) ` {(u,p). gen_iapath V u p v})" proof - have "in_arcs (gen_contr_graph G V) v = (\<lambda>(u,_). (u,v)) ` {(u,p). gen_iapath V u p v}" by (auto simp: gen_contr_graph_def) then show ?thesis unfolding in_degree_def by simp qed also have "\<dots> \<le> card {(u,p). gen_iapath V u p v}" using fin by (rule card_image_le) also have "\<dots> = card (snd ` {(u,p). gen_iapath V u p v})" using io_snd by (rule card_image[symmetric]) also have "snd ` {(u,p). gen_iapath V u p v} = {p. \<exists>u. gen_iapath V u p v}" by (auto intro: rev_image_eqI) also have "card \<dots> = card (last ` ...)" using io_last by (rule card_image[symmetric]) also have "\<dots> \<le> in_degree G v" unfolding in_degree_def proof (rule card_mono) show "last ` {p. \<exists>u. gen_iapath V u p v} \<subseteq> in_arcs G v" proof - have "\<And>u p. awalk u p v \<Longrightarrow> p \<noteq> [] \<Longrightarrow> last p \<in> parcs G" by (auto simp: awalk_def) moreover { fix u p assume "awalk u p v" "p \<noteq> []" then have "snd (last p) = v" by (induct p arbitrary: u) (auto simp: awalk_simps) } ultimately show ?thesis unfolding in_arcs_def by (auto simp: gen_iapath_def apath_def) qed qed auto finally show ?thesis . qed lemma (in pair_graph) contracted_no_degree2_simp: assumes subd: "subdivision G H" assumes two_less_deg2: "verts3 G = pverts G" shows "contr_graph H = G" using subd proof (induct rule: subdivision.induct) case base { fix e assume "e \<in> parcs G" then have "gen_iapath (pverts G) (fst e) [(fst e, snd e)] (snd e)" "e \<in> set [(fst e, snd e)]" using no_loops[of "(fst e, snd e)"] by (auto simp: gen_iapath_def apath_simps ) then have "\<exists>u p v. gen_iapath (pverts G) u p v \<and> e \<in> set p" by blast } moreover { fix u p v assume "gen_iapath (pverts G) u p v" from `gen_iapath _ u p v` have "p = [(u,v)]" unfolding gen_iapath_def apath_def by safe (cases p, case_tac [2] list, auto simp: awalk_simps inner_verts_def) } ultimately have "is_slim (verts3 G)" unfolding is_slim_def two_less_deg2 by blast then show ?case by (simp add: gen_contr_triv two_less_deg2) next case (divide e w H) let ?sH = "subdivide H e w" from `subdivision G H` interpret H: pair_graph H by (auto intro: pair_graph_subdivision) from divide(1,2) interpret S: pair_graph ?sH by (rule H.pair_graph_subdivide) obtain u v where e_conv:"e = (u,v)" by (cases e) auto have "contr_graph ?sH = contr_graph H" proof - have V_cond: "verts3 H \<subseteq> pverts H" by (auto simp: verts3_def) have "verts3 H = verts3 ?sH" using divide by (simp add: H.verts3_subdivide) then have v: "pverts (contr_graph ?sH) = pverts (contr_graph H)" by (auto simp: gen_contr_graph_def) moreover then have "parcs (contr_graph ?sH) = parcs (contr_graph H)" unfolding gen_contr_graph_def by (auto dest: H.gen_iapath_co_path[OF divide(1,2) V_cond] H.gen_iapath_sd_path[OF divide(1,2) V_cond]) ultimately show ?thesis by auto qed then show ?case using divide by simp qed lemma verts3_K33: assumes "K\<^bsub>3,3\<^esub> G" shows "verts3 G = verts G" proof - { fix v assume "v \<in> pverts G" from assms obtain U V where cards: "card U = 3" "card V=3" and UV: "U \<inter> V = {}" "pverts G = U \<union> V" "parcs G = U \<times> V \<union> V \<times> U" unfolding complete_bipartite_digraph_def by blast have "2 < in_degree G v" proof (cases "v \<in> U") case True then have "in_arcs G v = V \<times> {v}" using UV by fastforce then show ?thesis using cards by (auto simp: card_cartesian_product in_degree_def) next case False then have "in_arcs G v = U \<times> {v}" using `v \<in> _` UV by fastforce then show ?thesis using cards by (auto simp: card_cartesian_product in_degree_def) qed } then show ?thesis by (auto simp: verts3_def) qed lemma verts3_K5: assumes "K\<^bsub>5\<^esub> G" shows "verts3 G = verts G" proof - interpret pgG: pair_graph G using assms by (rule pair_graphI_complete) { fix v assume "v \<in> pverts G" have "2 < (4 :: nat)" by simp also have "4 = card (pverts G - {v})" using assms `v \<in> pverts G` unfolding complete_digraph_def by auto also have "pverts G - {v} = {u \<in> pverts G. u \<noteq> v}" by auto also have "card \<dots> = card ({u \<in> pverts G. u \<noteq> v} \<times> {v})" (is "_ = card ?A") by auto also have "?A = in_arcs G v" using assms `v \<in> pverts G` unfolding complete_digraph_def by safe auto also have "card \<dots> = in_degree G v" unfolding in_degree_def .. finally have "2 < in_degree G v" . } then show ?thesis unfolding verts3_def by auto qed lemma K33_contractedI: assumes subd: "subdivision G H" assumes k33: "K\<^bsub>3,3\<^esub> G" shows "K\<^bsub>3,3\<^esub> (contr_graph H)" proof - interpret pgG: pair_graph G using k33 by (rule pair_graphI_complete_bipartite) show ?thesis using assms by (auto simp add: pgG.contracted_no_degree2_simp verts3_K33) qed lemma K5_contractedI: assumes subd: "subdivision G H" assumes k5: "K\<^bsub>5\<^esub> G" shows "K\<^bsub>5\<^esub> (contr_graph H)" proof - interpret pgG: pair_graph G using k5 by (rule pair_graphI_complete) show ?thesis using assms by (auto simp add: pgG.contracted_no_degree2_simp verts3_K5) qed subsection {* Final proof *} context pair_pseudo_graph begin lemma gcg_subdivide_eq: assumes mem: "e \<in> parcs G" "w \<notin> pverts G" assumes V: "V \<subseteq> pverts G" shows "gen_contr_graph (subdivide G e w) V = gen_contr_graph G V" proof - interpret sdG: pair_pseudo_graph "subdivide G e w" using mem by (rule pair_pseudo_graph_subdivide) { fix u p v assume "sdG.gen_iapath V u p v" have "gen_iapath V u (co_path e w p) v" using mem V `sdG.gen_iapath V u p v` by (rule gen_iapath_co_path) then have "\<exists>p. gen_iapath V u p v" .. } note A = this moreover { fix u p v assume "gen_iapath V u p v" have "sdG.gen_iapath V u (sd_path e w p) v" using mem V `gen_iapath V u p v` by (rule gen_iapath_sd_path) then have "\<exists>p. sdG.gen_iapath V u p v" .. } note B = this ultimately show ?thesis using assms by (auto simp: gen_contr_graph_def) qed lemma co_path_append: assumes "[last p1, hd p2] \<notin> {[(fst e,w),(w,snd e)], [(snd e,w),(w,fst e)]}" shows "co_path e w (p1 @ p2) = co_path e w p1 @ co_path e w p2" using assms proof (induct p1 rule: co_path_induct) case single then show ?case by (cases p2) auto next case (co e1 e2 es) then show ?case by (cases es) auto next case (corev e1 e2 es) then show ?case by (cases es) auto qed auto lemma exists_co_path_decomp1: assumes mem: "e \<in> parcs G" "w \<notin> pverts G" assumes p: "pre_digraph.apath (subdivide G e w) u p v" "(fst e, w) \<in> set p" "w \<noteq> v" shows "\<exists>p1 p2. p = p1 @ (fst e, w) # (w, snd e) # p2" proof - let ?sdG = "subdivide G e w" interpret sdG: pair_pseudo_graph ?sdG using mem by (rule pair_pseudo_graph_subdivide) obtain p1 p2 z where p_decomp: "p = p1 @ (fst e, w) # (w, z) # p2" "fst e \<noteq> z" "w \<noteq> z" by atomize_elim (rule sdG.apath_succ_decomp[OF p]) then have "(fst e,w) \<in> parcs ?sdG" "(w, z) \<in> parcs ?sdG" using p by (auto simp: sdG.apath_def) with `fst e \<noteq> z` have "z = snd e" using mem by (cases e) (auto simp: wellformed') with p_decomp show ?thesis by fast qed lemma is_slim_if_subdivide: assumes "pair_pre_digraph.is_slim (subdivide G e w) V" assumes mem1: "e \<in> parcs G" "w \<notin> pverts G" and mem2: "w \<notin> V" shows "is_slim V" proof - let ?sdG = "subdivide G e w" interpret sdG: pair_pseudo_graph "subdivide G e w" using mem1 by (rule pair_pseudo_graph_subdivide) obtain u v where "e = (u,v)" by (cases e) auto with mem1 have "u \<in> pverts G" "v \<in> pverts G" by (auto simp: wellformed') with mem1 have "u \<noteq> w" "v \<noteq> w" by auto let ?w_parcs = "{(u,w), (v,w), (w,u), (w, v)}" have sdg_new_parcs: "?w_parcs \<subseteq> parcs ?sdG" using `e = (u,v)` by auto have sdg_no_parcs: "(u,v) \<notin> parcs ?sdG" "(v,u) \<notin> parcs ?sdG" using `e = (u,v)` `u \<noteq> w` `v \<noteq> w` by auto { fix z assume A: "z \<in> pverts G" have "in_degree ?sdG z = in_degree G z" proof - { assume "z \<noteq> u" "z \<noteq> v" then have "in_arcs ?sdG z = in_arcs G z" using `e = (u,v)` mem1 A by auto then have "in_degree ?sdG z = in_degree G z" by (simp add: in_degree_def) } moreover { assume "z = u" then have "in_arcs G z = in_arcs ?sdG z \<union> {(v,u)} - {(w,u)}" using `e = (u,v)` mem1 by (auto simp: intro: arcs_symmetric wellformed') moreover have "card (in_arcs ?sdG z \<union> {(v,u)} - {(w,u)}) = card (in_arcs ?sdG z)" using sdg_new_parcs sdg_no_parcs `z = u` by (auto simp: in_arcs_def) ultimately have "in_degree ?sdG z= in_degree G z" by (simp add: in_degree_def) } moreover { assume "z = v" then have "in_arcs G z = in_arcs ?sdG z \<union> {(u,v)} - {(w,v)}" using `e = (u,v)` mem1 A by (auto simp: wellformed') moreover have "card (in_arcs ?sdG z \<union> {(u,v)} - {(w,v)}) = card (in_arcs ?sdG z)" using sdg_new_parcs sdg_no_parcs `z = v` by (auto simp: in_arcs_def) ultimately have "in_degree ?sdG z= in_degree G z" by (simp add: in_degree_def) } ultimately show ?thesis by metis qed } note in_degree_same = this have V_G: "V \<subseteq> pverts G" "verts3 G \<subseteq> V" proof - have "V \<subseteq> pverts ?sdG" "pverts ?sdG = pverts G \<union> {w}" "verts3 ?sdG \<subseteq> V" "verts3 G \<subseteq> verts3 ?sdG" using `sdG.is_slim V` `e = (u,v)` in_degree_same mem1 unfolding sdG.is_slim_def verts3_def by (fast, simp, fastforce, force) then show "V \<subseteq> pverts G" "verts3 G \<subseteq> V" using `w \<notin> V` by auto qed have pverts: "\<forall>v\<in>pverts G. v \<in> V \<or> in_degree G v \<le> 2 \<and> (\<exists>x p y. gen_iapath V x p y \<and> v \<in> set (awalk_verts x p))" proof - { fix z assume A: "z \<in> pverts G" "z \<notin> V" have "z \<in> pverts ?sdG" using `e = (u,v)` A mem1 by auto then have "in_degree ?sdG z \<le> 2" using `sdG.is_slim V` A by (auto simp: sdG.is_slim_def) with in_degree_same[OF `z \<in> pverts G`] have idg: "in_degree G z \<le> 2" by auto from A have "z \<in> pverts ?sdG" "z \<notin> V" using `e = (u,v)` mem1 by auto then obtain x' q y' where "sdG.gen_iapath V x' q y'" "z \<in> set (sdG.awalk_verts x' q)" using `sdG.is_slim V` unfolding sdG.is_slim_def by metis then have "gen_iapath V x' (co_path e w q) y'" "z \<in> set (awalk_verts x' (co_path e w q))" using A mem1 V_G by (auto simp: set_awalk_verts_co_path' intro: gen_iapath_co_path) with idg have "in_degree G z \<le> 2 \<and> (\<exists>x p y. gen_iapath V x p y \<and> z \<in> set (awalk_verts x p))" by metis } then show ?thesis by auto qed have parcs: "\<forall>e\<in>parcs G. \<exists>x p y. gen_iapath V x p y \<and> e \<in> set p" proof fix e' assume "e' \<in> parcs G" show "\<exists>x p y. gen_iapath V x p y \<and> e' \<in> set p" proof (cases "e' \<in> parcs ?sdG") case True then obtain x p y where "sdG.gen_iapath V x p y" "e' \<in> set p" using `sdG.is_slim V` by (auto simp: sdG.is_slim_def) with `e \<in> parcs G` `w \<notin> pverts G` V_G have "gen_iapath V x (co_path e w p) y" by (auto intro: gen_iapath_co_path) from `e' \<in> parcs G` have "e' \<notin> ?w_parcs" using mem1 by (auto simp: wellformed') with `e' \<in> set p` have "e' \<in> set (co_path e w p)" by (induct p rule: co_path_induct) (force simp: `e = (u,v)`)+ then show "\<exists>x p y. gen_iapath V x p y \<and> e' \<in> set p " using `gen_iapath V x (co_path e w p) y` by fast next assume "e' \<notin> parcs ?sdG" def a \<equiv> "fst e'" and b \<equiv> "snd e'" then have "e' = (a,b)" and ab: "(a,b) = (u,v) \<or> (a,b) = (v,u)" using `e' \<in> parcs G` `e' \<notin> parcs ?sdG` `e = (u,v)` mem1 by auto obtain x p y where "sdG.gen_iapath V x p y" "(a,w) \<in> set p" using `sdG.is_slim V` sdg_new_parcs ab by (auto simp: sdG.is_slim_def) with `e \<in> parcs G` `w \<notin> pverts G` V_G have "gen_iapath V x (co_path e w p) y" by (auto intro: gen_iapath_co_path) have "(a,b) \<in> parcs G" "subdivide G (a,b) w = subdivide G e w" using mem1 `e = (u,v)` `e' = (a,b)` ab by (auto intro: arcs_symmetric simp: subdivide.simps) then have "pre_digraph.apath (subdivide G (a,b) w) x p y" "w \<noteq> y" using mem2 `sdG.gen_iapath V x p y` by (auto simp: sdG.gen_iapath_def) then obtain p1 p2 where "p = p1 @ (a,w) # (w,b) # p2" using exists_co_path_decomp1 `(a,b) \<in> parcs G` `w \<notin> pverts G` `(a,w) \<in> set p` `w \<noteq> y` by atomize_elim auto moreover then have "co_path e w ((a,w) # (w,b) # p2) = (a,b) # co_path e w p2" unfolding `e = (u,v)` using ab by auto ultimately have "(a,b) \<in> set (co_path e w p)" unfolding `e = (u,v)` using ab `u \<noteq> w` `v \<noteq> w` by (induct p rule: co_path_induct) (auto simp: co_path_append) then show ?thesis using `gen_iapath V x (co_path e w p) y` `e' = (a,b)` by fast qed qed have unique: "\<forall>u v p q. (gen_iapath V u p v \<and> gen_iapath V u q v) \<longrightarrow> p = q" proof safe fix x y p q assume A: "gen_iapath V x p y" "gen_iapath V x q y" then have "set p \<subseteq> parcs G" "set q \<subseteq> parcs G" by (auto simp: gen_iapath_def apath_def) then have w_p: "(u,w) \<notin> set p" "(v,w) \<notin> set p" and w_q: "(u,w) \<notin> set q" "(v,w) \<notin> set q" using mem1 by (auto simp: wellformed') from A have "sdG.gen_iapath V x (sd_path e w p) y" "sdG.gen_iapath V x (sd_path e w q) y" using mem1 V_G by (auto intro: gen_iapath_sd_path) then have "sd_path e w p = sd_path e w q" using `sdG.is_slim V` unfolding sdG.is_slim_def by metis then have "co_path e w (sd_path e w p) = co_path e w (sd_path e w q)" by simp then show "p = q" using w_p w_q `e = (u,v)` by (simp add: co_sd_id) qed from pverts parcs V_G unique show ?thesis by (auto simp: is_slim_def) qed lemma subdivision_gen_contr: assumes "is_slim V" shows "subdivision (gen_contr_graph G V) G" using assms pair_pseudo_graph proof (induct "card (pverts G - V)" arbitrary: G) case 0 interpret G: pair_pseudo_graph G by fact from 0 show ?case by (auto intro: subdivision.intros simp: G.gen_contr_triv G.is_slim_def) next case (Suc n) interpret G: pair_pseudo_graph G by fact from `Suc n = card (pverts G - V)` have "pverts G - V \<noteq> {}" by (metis Nat.diff_le_self Suc_n_not_le_n card_Diff_subset_Int diff_Suc_Suc empty_Diff finite.emptyI inf_bot_left) then obtain w where "w \<in> pverts G - V" by auto then obtain x q y where q: "G.gen_iapath V x q y" "w \<in> set (G.awalk_verts x q)" "in_degree G w \<le> 2" using `G.is_slim V` by (auto simp: G.is_slim_def) then have "w \<noteq> x" "w \<noteq> y" "w \<notin> V" using `w \<in> pverts G - V` by (auto simp: G.gen_iapath_def) then obtain e where "e \<in> set q" "snd e = w" using `w \<in> pverts G - V` q unfolding G.gen_iapath_def G.apath_def G.awalk_conv by (auto simp: G.awalk_verts_conv') moreover def u \<equiv> "fst e" ultimately obtain q1 q2 v where q_decomp: "q = q1 @ (u, w) # (w, v) # q2" "u \<noteq> v" "w \<noteq> v" using q `w \<noteq> y` unfolding G.gen_iapath_def by atomize_elim (rule G.apath_succ_decomp, auto) with q have qi_walks: "G.awalk x q1 u" "G.awalk v q2 y" by (auto simp: G.gen_iapath_def G.apath_def G.awalk_Cons_iff) from q q_decomp have uvw_arcs1: "(u,w) \<in> parcs G" "(w,v) \<in> parcs G" by (auto simp: G.gen_iapath_def G.apath_def) then have uvw_arcs2: "(w,u) \<in> parcs G" "(v,w) \<in> parcs G" by (blast intro: G.arcs_symmetric)+ have "u \<noteq> w" "v \<noteq> w" using q_decomp q by (auto simp: G.gen_iapath_def G.apath_append_iff G.apath_simps) have in_arcs: "in_arcs G w = {(u,w), (v,w)}" proof - have "{(u,w), (v,w)} \<subseteq> in_arcs G w" using uvw_arcs1 uvw_arcs2 by (auto simp: ) moreover note `in_degree G w \<le> 2` moreover have "card {(u,w), (v,w)} = 2" using `u \<noteq> v` by auto ultimately show ?thesis by - (rule card_seteq[symmetric], auto simp: in_degree_def) qed have out_arcs: "out_arcs G w \<subseteq> {(w,u), (w,v)}" (is "?L \<subseteq> ?R") proof fix e assume "e \<in> out_arcs G w" then have "(snd e, fst e) \<in> in_arcs G w" by (auto intro: G.arcs_symmetric) then show "e \<in> {(w, u), (w, v)}" using in_arcs by auto qed have "(u,v) \<notin> parcs G" proof assume "(u,v) \<in> parcs G" have "G.gen_iapath V x (q1 @ (u,v) # q2) y" proof - have awalk': "G.awalk x (q1 @ (u,v) # q2) y" using qi_walks `(u,v) \<in> parcs G` by (auto simp: G.awalk_simps) have "G.awalk x q y" using `G.gen_iapath V x q y` by (auto simp: G.gen_iapath_def G.apath_def) have "distinct (G.awalk_verts x (q1 @ (u,v) # q2))" using awalk' `G.gen_iapath V x q y` unfolding q_decomp by (auto simp: G.gen_iapath_def G.apath_def G.awalk_verts_append) moreover have "set (G.inner_verts (q1 @ (u,v) # q2)) \<subseteq> set (G.inner_verts q)" using awalk' `G.awalk x q y` unfolding q_decomp by (auto simp: butlast_append G.inner_verts_conv[of _ x] G.awalk_verts_append intro: in_set_butlast_appendI) then have "set (G.inner_verts (q1 @ (u,v) # q2)) \<inter> V = {}" using `G.gen_iapath V x q y` by (auto simp: G.gen_iapath_def) ultimately show ?thesis using awalk' `G.gen_iapath V x q y` by (simp add: G.gen_iapath_def G.apath_def) qed then have "(q1 @ (u,v) # q2) = q" using `G.gen_iapath V x q y` `G.is_slim V` unfolding G.is_slim_def by metis then show False unfolding q_decomp by simp qed then have "(v,u) \<notin> parcs G" by (auto intro: G.arcs_symmetric) def G' \<equiv> "\<lparr>pverts = pverts G - {w}, parcs = {(u,v), (v,u)} \<union> (parcs G - {(u,w), (w,u), (v,w), (w,v)})\<rparr>" have mem_G': "(u,v) \<in> parcs G'" "w \<notin> pverts G'" by (auto simp: G'_def) interpret pd_G': pair_fin_digraph G' proof fix e assume A: "e \<in> parcs G'" have "e \<in> parcs G \<and> e \<noteq> (u, w) \<and> e \<noteq> (w, u) \<and> e \<noteq> (v, w) \<and> e \<noteq> (w, v) \<Longrightarrow> fst e \<noteq> w" "e \<in> parcs G \<and> e \<noteq> (u, w) \<and> e \<noteq> (w, u) \<and> e \<noteq> (v, w) \<and> e \<noteq> (w, v) \<Longrightarrow> snd e \<noteq> w" using out_arcs in_arcs by auto with A uvw_arcs1 show "fst e \<in> pverts G'" "snd e \<in> pverts G'" using `u \<noteq> w` `v \<noteq> w` by (auto simp: G'_def G.wellformed') next qed (auto simp: G'_def arc_to_ends_def) interpret spd_G': pair_pseudo_graph G' proof (unfold_locales, simp add: symmetric_def) have "sym {(u,v), (v,u)}" "sym (parcs G)" "sym {(u, w), (w, u), (v, w), (w, v)}" using `symmetric G` by (auto simp: symmetric_def sym_def) then have "sym ({(u,v), (v,u)} \<union> (parcs G - {(u,w), (w,u), (v,w), (w,v)}))" by (intro sym_Un) (auto simp: sym_diff) then show "sym (parcs G')" unfolding G'_def by simp qed have card_G': "n = card (pverts G' - V)" proof - have "pverts G - V = insert w (pverts G' - V)" using `w \<in> pverts G - V` by (auto simp: G'_def) then show ?thesis using `Suc n = card (pverts G - V)` mem_G' by simp qed have G_is_sd: "G = subdivide G' (u,v) w" (is "_ = ?sdG'") using `w \<in> pverts G - V` `(u,v) \<notin> parcs G` `(v,u) \<notin> parcs G` uvw_arcs1 uvw_arcs2 by (intro pair_pre_digraph.equality) (auto simp: G'_def) have gcg_sd: "gen_contr_graph (subdivide G' (u,v) w) V = gen_contr_graph G' V" proof - have "V \<subseteq> pverts G" using `G.is_slim V` by (auto simp: G.is_slim_def verts3_def) moreover have "verts3 G' = verts3 G" by (simp only: G_is_sd spd_G'.verts3_subdivide[OF `(u,v) \<in> parcs G'` `w \<notin> pverts G'`]) ultimately have V: "V \<subseteq> pverts G'" using `w \<in> pverts G - V` by (auto simp: G'_def) with mem_G' show ?thesis by (rule spd_G'.gcg_subdivide_eq) qed have is_slim_G': "pd_G'.is_slim V" using `G.is_slim V` mem_G' `w \<notin> V` unfolding G_is_sd by (rule spd_G'.is_slim_if_subdivide) with mem_G' have "subdivision (gen_contr_graph G' V) (subdivide G' (u, v) w)" by (intro Suc card_G' subdivision.intros) auto then show ?case by (simp add: gcg_sd G_is_sd) qed lemma contr_is_subgraph_subdivision: shows "\<exists>H. subgraph (with_proj H) G \<and> subdivision (contr_graph G) H" proof - interpret sG: pair_pseudo_graph slim by (rule pair_pseudo_graph_slim) have "subdivision (gen_contr_graph slim (verts3 G)) slim " by (rule sG.subdivision_gen_contr) (rule slim_is_slim) then show ?thesis unfolding contr_graph_slim_eq by (blast intro: subgraph_slim) qed theorem final_theorem: fixes K :: "'a pair_pre_digraph" assumes subgraph_K: "subgraph K G" assumes spd_K: "pair_pseudo_graph K" assumes kuratowski: "K\<^bsub>3,3\<^esub> (contr_graph K) \<or> K\<^bsub>5\<^esub> (contr_graph K)" shows "\<not>planar G" proof - interpret spd_K: pair_pseudo_graph K by (fact spd_K) obtain H where subgraph_H: "subgraph (with_proj H) K" and subdiv_H:"subdivision (contr_graph K) H" by atomize_elim (rule spd_K.contr_is_subgraph_subdivision) from subdiv_H and kuratowski have "\<exists>K. subdivision K H \<and> (K\<^bsub>3,3\<^esub> K \<or> K\<^bsub>5\<^esub> K)" by blast then show ?thesis using subgraph_H subgraph_K unfolding planar_def by (blast intro: subgraph_trans) qed theorem certificate_characterization: defines "kuratowski \<equiv> \<lambda>G. K\<^bsub>3,3\<^esub> G \<or> K\<^bsub>5\<^esub> G" shows "kuratowski (contr_graph G) \<longleftrightarrow> (\<exists>H. kuratowski H \<and> subdivision H slim \<and> verts3 G = verts3 slim)" (is "?L \<longleftrightarrow> ?R") proof assume ?L interpret S: pair_pseudo_graph slim by (rule pair_pseudo_graph_slim) have "subdivision (contr_graph G) slim" proof - have *: "S.is_slim (verts3 G)" by (rule slim_is_slim) show ?thesis using contr_graph_slim_eq S.subdivision_gen_contr[OF *] by auto qed moreover have "verts3 slim = verts3 G" (is "?l = ?r") proof safe fix v assume "v \<in> ?l" then show "v \<in> ?r" using verts_slim_in_G verts3_slim_in_verts3 by auto next fix v assume "v \<in> ?r" have "v \<in> verts3 (contr_graph G)" proof - have "v \<in> verts (contr_graph G)" using `v \<in> ?r` by (auto simp: verts3_def gen_contr_graph_def) then show ?thesis using `?L` unfolding kuratowski_def by (auto simp: verts3_K33 verts3_K5) qed then have "v \<in> verts3 (gen_contr_graph slim (verts3 G))" unfolding contr_graph_slim_eq . then have "2 < in_degree (gen_contr_graph slim (verts3 G)) v" unfolding verts3_def by auto also have "\<dots> \<le> in_degree slim v" using `v \<in> ?r` verts3_slim_in_verts3 by (auto intro: S.in_degree_contr) finally show "v \<in> verts3 slim" using verts3_in_slim_G `v \<in> ?r` unfolding verts3_def by auto qed ultimately show ?R using `?L` by auto next assume ?R then have "kuratowski (gen_contr_graph slim (verts3 G))" unfolding kuratowski_def by (auto intro: K33_contractedI K5_contractedI) then show ?L unfolding contr_graph_slim_eq . qed definition certify :: "'a pair_pre_digraph \<Rightarrow> bool" where "certify cert \<equiv> let C = contr_graph cert in subgraph cert G \<and> (K\<^bsub>3,3\<^esub> C \<or> K\<^bsub>5\<^esub>C)" theorem certify_complete: assumes "pair_pseudo_graph cert" assumes "subgraph cert G" assumes "\<exists>H. subdivision H cert \<and> (K\<^bsub>3,3\<^esub> H \<or> K\<^bsub>5\<^esub> H)" shows "certify cert" unfolding certify_def using assms by (auto simp: Let_def intro: K33_contractedI K5_contractedI) theorem certify_sound: assumes "pair_pseudo_graph cert" assumes "certify cert" shows" \<not>planar G" using assms by (intro final_theorem) (auto simp: certify_def Let_def) theorem certify_characterization: assumes "pair_pseudo_graph cert" shows "certify cert \<longleftrightarrow> subgraph cert G \<and> verts3 cert = verts3 (pair_pre_digraph.slim cert) \<and>(\<exists>H. (K\<^bsub>3,3\<^esub> H \<or> K\<^bsub>5\<^esub> H) \<and> subdivision H (pair_pre_digraph.slim cert))" (is "?L \<longleftrightarrow> ?R") by (auto simp only: simp_thms certify_def Let_def pair_pseudo_graph.certificate_characterization[OF assms]) end end
# -*- coding: utf-8 -*- """ Created on Fri Apr 13 23:04:11 2018 @author: Marcus """ import numpy as np import time def my_ifft(x): N = len(x) y = np.zeros(N, dtype=np.complex) if (N is 1): return x else: Wn = np.exp(1j * 2 * np.pi / N) W = 1 x_even = x[0::2] x_odd = x[1::2] y_even = my_ifft(x_even) y_odd = my_ifft(x_odd) for m in range(N//2): y[m] = y_even[m] + (W * y_odd[m]) y[m + N//2] = y_even[m] - (W * y_odd[m]) W *= Wn return y def my_ifft_adjusted(x): return my_ifft(x) / len(x) length = 2**14 samples = np.random.normal(0, 1, length) + 1j*np.random.normal(0, 1, length) a0 = time.clock() my_result = my_ifft_adjusted(samples) a1 = time.clock() da = a1 - a0 b0 = time.clock() np_result = np.fft.ifft(samples) b1 = time.clock() db = b1 - b0 print("My IFFT took:", da, "seconds") print("NP IFFT took:", db, "seconds") print("NP IFFT is", da/db, "times faster") print(np.allclose(my_result, np_result))
#include <WebServer/EventLoop.h> #include <WebServer/Acceptor.h> #include <WebServer/Util.h> #include <netinet/in.h> #include <WebServer/InetAddress.h> #include <boost/bind.hpp> #include <errno.h> #include <fcntl.h> using namespace ywl; using namespace ywl::net; Acceptor::Acceptor(EventLoop* loop, const InetAddress& listenAddr) : loop_(loop), acceptFd_(sockets::createNonBlockSocketfd()), acceptChannel_(loop, acceptFd_), listenning_(false), idleFd_(::open("/dev/null", O_RDONLY | O_CLOEXEC)) { assert(idleFd_ >= 0); sockets::SetReuseAddr(acceptFd_, true); sockets::Bind(acceptFd_, listenAddr.getSockAddrInet()); acceptChannel_.setReadCallback( boost::bind(&Acceptor::handleRead, this)); } Acceptor::~Acceptor() { acceptChannel_.disableAll(); acceptChannel_.remove(); ::close(idleFd_); } void Acceptor::listen() { loop_->assertInLoopThread(); listenning_ = true; sockets::Listen(acceptFd_); acceptChannel_.enableReading(); } void Acceptor::handleRead() { loop_->assertInLoopThread(); InetAddress peerAddr(0); struct sockaddr_in addr; bzero(&addr, sizeof addr); // int connfd = sockets::Accept(acceptFd_, &addr); // if (connfd >= 0) { // peerAddr.setSockAddrInet(addr); // if (NewConnectionCallback_) { // NewConnectionCallback_(connfd, peerAddr); // } // else // { // sockets::Close(connfd); // } // } int connfd = -1; while ((connfd = sockets::Accept(acceptFd_, &addr)) >= 0) { if (connfd < 0) break; peerAddr.setSockAddrInet(addr); if (NewConnectionCallback_) { NewConnectionCallback_(connfd, peerAddr); } else { sockets::Close(connfd); } } if (errno == EMFILE) { ::close(idleFd_); idleFd_ = ::accept(acceptFd_, NULL, NULL); ::close(idleFd_); idleFd_ = ::open("/dev/null", O_RDONLY | O_CLOEXEC); } }
MODULE test_module USE global_module, ONLY: i_knd, r_knd, zero IMPLICIT NONE PUBLIC REAL(r_knd), ALLOCATABLE, DIMENSION(:) :: pop CONTAINS SUBROUTINE alloc ( ierr ) !----------------------------------------------------------------------- ! ! Allocate test_module arrays. ! !----------------------------------------------------------------------- ALLOCATE( pop(ng), STAT=ierr ) IF ( ierr /= 0 ) RETURN pop = zero END SUBROUTINE alloc SUBROUTINE dealloc !----------------------------------------------------------------------- ! ! Deallocate test_module arrays. ! !----------------------------------------------------------------------- DEALLOCATE( pop ) END SUBROUTINE dealloc END MODULE test_module
lemma compact_differences: fixes s t :: "'a::real_normed_vector set" assumes "compact s" and "compact t" shows "compact {x - y | x y. x \<in> s \<and> y \<in> t}"
lemma integral_restrict_UNIV: fixes f :: "'a::euclidean_space \<Rightarrow> 'b::euclidean_space" assumes "S \<in> sets lebesgue" shows "integral\<^sup>L lebesgue (\<lambda>x. if x \<in> S then f x else 0) = integral\<^sup>L (lebesgue_on S) f"
[STATEMENT] lemma ordinal_div_greater [simp]: "x < y \<Longrightarrow> x div y = (0::ordinal)" [PROOF STATE] proof (prove) goal (1 subgoal): 1. x < y \<Longrightarrow> x div y = 0 [PROOF STEP] by (rule_tac r=x in ordinal_divI, simp_all)
# Copyright (c) 2021 Microsoft Corporation. Licensed under the MIT license. import torch import numpy as np import base64 import collections from maskrcnn_benchmark.structures.bounding_box import BoxList class LabelLoader(object): def __init__(self, labelmap, extra_fields=(), filter_duplicate_relations=False, ignore_attr=None, ignore_rel=None): self.labelmap = labelmap self.extra_fields = extra_fields self.supported_fields = ["class", "conf", "attributes", 'scores_all', 'boxes_all', 'feature'] self.filter_duplicate_relations = filter_duplicate_relations self.ignore_attr = set(ignore_attr) if ignore_attr != None else set() self.ignore_rel = set(ignore_rel) if ignore_rel != None else set() def __call__(self, annotations, img_size, remove_empty=False, load_fields=None): boxes = [obj["rect"] for obj in annotations] boxes = torch.as_tensor(boxes).reshape(-1, 4) target = BoxList(boxes, img_size, mode="xyxy") if load_fields is None: load_fields = self.extra_fields for field in load_fields: assert field in self.supported_fields, "Unsupported field {}".format(field) if field == "class": classes = self.add_classes(annotations) target.add_field("labels", classes) elif field == "conf": confidences = self.add_confidences(annotations) target.add_field("scores", confidences) elif field == "attributes": attributes = self.add_attributes(annotations) target.add_field("attributes", attributes) elif field == "scores_all": scores_all = self.add_scores_all(annotations) target.add_field("scores_all", scores_all) elif field == "boxes_all": boxes_all = self.add_boxes_all(annotations) target.add_field("boxes_all", boxes_all) elif field == "feature": features = self.add_features(annotations) target.add_field("box_features", features) target = target.clip_to_image(remove_empty=remove_empty) return target def add_classes(self, annotations): class_names = [obj["class"] for obj in annotations] classes = [None] * len(class_names) for i in range(len(class_names)): classes[i] = self.labelmap['class_to_ind'][class_names[i]] return torch.tensor(classes) def add_confidences(self, annotations): confidences = [] for obj in annotations: if "conf" in obj: confidences.append(obj["conf"]) else: confidences.append(1.0) return torch.tensor(confidences) def add_attributes(self, annotations): # the maximal number of attributes per object is 16 attributes = [ [0] * 16 for _ in range(len(annotations))] for i, obj in enumerate(annotations): for j, attr in enumerate(obj["attributes"]): attributes[i][j] = self.labelmap['attribute_to_ind'][attr] return torch.tensor(attributes) def add_features(self, annotations): features = [] for obj in annotations: features.append(np.frombuffer(base64.b64decode(obj['feature']), np.float32)) return torch.tensor(features) def add_scores_all(self, annotations): scores_all = [] for obj in annotations: scores_all.append(np.frombuffer(base64.b64decode(obj['scores_all']), np.float32)) return torch.tensor(scores_all) def add_boxes_all(self, annotations): boxes_all = [] for obj in annotations: boxes_all.append(np.frombuffer(base64.b64decode(obj['boxes_all']), np.float32).reshape(-1, 4)) return torch.tensor(boxes_all) def relation_loader(self, relation_annos, target): if self.filter_duplicate_relations: # Filter out dupes! all_rel_sets = collections.defaultdict(list) for triplet in relation_annos: all_rel_sets[(triplet['subj_id'], triplet['obj_id'])].append(triplet) relation_annos = [np.random.choice(v) for v in all_rel_sets.values()] # get M*M pred_labels relation_triplets = [] relations = torch.zeros([len(target), len(target)], dtype=torch.int64) for i in range(len(relation_annos)): if len(self.ignore_rel)!=0 and relation_annos[i]['class'] in self.ignore_rel: continue subj_id = relation_annos[i]['subj_id'] obj_id = relation_annos[i]['obj_id'] predicate = self.labelmap['relation_to_ind'][relation_annos[i]['class']] relations[subj_id, obj_id] = predicate relation_triplets.append([subj_id, obj_id, predicate]) relation_triplets = torch.tensor(relation_triplets) target.add_field("relation_labels", relation_triplets) target.add_field("pred_labels", relations) return target
Formal statement is: lemma joinable_components_eq: "connected t \<and> t \<subseteq> s \<and> c1 \<in> components s \<and> c2 \<in> components s \<and> c1 \<inter> t \<noteq> {} \<and> c2 \<inter> t \<noteq> {} \<Longrightarrow> c1 = c2" Informal statement is: If $t$ is a connected subset of $s$ and $c_1$ and $c_2$ are components of $s$ that intersect $t$, then $c_1 = c_2$.
(* Copyright (C) 2017 M.A.L. Marques This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/. *) (* type: gga_exc *) (* prefix: gga_xc_th3_params *params; assert(p->params != NULL); params = (gga_xc_th3_params * )(p->params); *) params_a_n := 19: params_a_a := [ 7/6, 8/6, 9/6, 10/6, 17/12, 9/6, 10/6, 11/6, 10/6, 11/6, 12/6, 10/6, 11/6, 12/6, 7/6, 8/6, 9/6, 10/6, 13/12.0 ]: params_a_b := [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0]: params_a_c := [0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 0, 0, 0, 0, 0, 0, 0, 0]: params_a_d := [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0]: $include "th.mpl" f := (rs, z, xt, xs0, xs1) -> f_th(rs, z, xt, xs0, xs1):
""" AbstractLink Abstract type defining maps from R^n -> X. They can be applied by calling `link(x)`. A series of definitions are given in http://web.pdx.edu/~newsomj/mvclass/ho_link.pdf """ abstract type AbstractLink end """ ChainLink(links) Create a composed chain of different links. """ struct ChainLink{Tls} <: AbstractLink links::Tls end (l::ChainLink)(x) = foldl((x, l) -> l(x), l.ls; init=x) """ Link(f) General construction for a link with a function `f`. """ struct Link{F} <: AbstractLink f::F end link(f) = Link(f) link(l::AbstractLink) = l (l::Link)(x) = l.f(x) Base.inv(l::Link) = Link(InverseFunctions.inverse(l.f)) """ BijectiveSimplexLink(link) Wrapper to preprocess the inputs by adding a `0` at the end before passing it to the link `link`. This is a necessary step to work with simplices. For example with the [`SoftMaxLink`](@ref), to obtain a `n`-simplex leading to `n+1` categories for the [`CategoricalLikelihood`](@ref), one needs to pass `n+1` latent GP. However, by wrapping the link into a `BijectiveSimplexLink`, only `n` latent are needed. """ struct BijectiveSimplexLink{L} <: AbstractLink link::L end (l::BijectiveSimplexLink)(f::AbstractVector{<:Real}) = l.link(vcat(f, 0)) # alias const LogLink = Link{typeof(log)} const ExpLink = Link{typeof(exp)} const InvLink = Link{typeof(inv)} const SqrtLink = Link{typeof(sqrt)} const SquareLink = Link{typeof(InverseFunctions.square)} const LogitLink = Link{typeof(logit)} const LogisticLink = Link{typeof(logistic)} const ProbitLink = Link{typeof(norminvcdf)} const NormalCDFLink = Link{typeof(normcdf)} const SoftMaxLink = Link{typeof(softmax)} """ LogLink() `log` link, f:ℝ⁺->ℝ . Its inverse is the [`ExpLink`](@ref). """ LogLink() = Link(log) """ ExpLink() `exp` link, f:ℝ->ℝ⁺. Its inverse is the [`LogLink`](@ref). """ ExpLink() = Link(exp) """ InvLink() `inv` link, f:ℝ/{0}->ℝ/{0}. It is its own inverse. """ InvLink() = Link(inv) """ SqrtLink() `sqrt` link, f:ℝ⁺∪{0}->ℝ⁺∪{0}. Its inverse is the [`SquareLink`](@ref). """ SqrtLink() = Link(sqrt) """ SquareLink() `^2` link, f:ℝ->ℝ⁺∪{0}. Its inverse is the [`SqrtLink`](@ref). """ SquareLink() = Link(InverseFunctions.square) """ LogitLink() `log(x/(1-x))` link, f:[0,1]->ℝ. Its inverse is the [`LogisticLink`](@ref). """ LogitLink() = Link(logit) """ LogisticLink() `1/(1+exp(-x))` link. f:ℝ->[0,1]. Its inverse is the [`LogitLink`](@ref). """ LogisticLink() = Link(logistic) """ ProbitLink() `ϕ⁻¹(y)` link, where `ϕ⁻¹` is the `invcdf` of a `Normal` distribution, f:[0,1]->ℝ. Its inverse is the [`NormalCDFLink`](@ref). """ ProbitLink() = Link(norminvcdf) """ NormalCDFLink() `ϕ(y)` link, where `ϕ` is the `cdf` of a `Normal` distribution, f:ℝ->[0,1]. Its inverse is the [`ProbitLink`](@ref). """ NormalCDFLink() = Link(normcdf) (::ChainLink{<:Tuple{LogLink,NormalCDFLink}})(x) = normlogcdf(x) # Specialisation for log + normal cdf """ SoftMaxLink() `softmax` link, i.e `f(x)ᵢ = exp(xᵢ)/∑ⱼexp(xⱼ)`. f:ℝⁿ->Sⁿ⁻¹, where Sⁿ⁻¹ is an [(n-1)-simplex](https://en.wikipedia.org/wiki/Simplex) It has no defined inverse """ SoftMaxLink() = Link(softmax)
(* *********************************************************************) (* *) (* The Compcert verified compiler *) (* *) (* Xavier Leroy, INRIA Paris-Rocquencourt *) (* *) (* Copyright Institut National de Recherche en Informatique et en *) (* Automatique. All rights reserved. This file is distributed *) (* under the terms of the INRIA Non-Commercial License Agreement. *) (* *) (* *********************************************************************) (** Correctness proof for expression simplification. *) Require Import Coqlib. Require Import Maps. Require Import AST. Require Import Errors. Require Import Integers. Require Import Values. Require Import Memory. Require Import Events. Require Import Smallstep. Require Import Globalenvs. Require Import Ctypes. Require Import Cop. Require Import Csyntax. Require Import Csem. Require Import Cstrategy. Require Import Clight. Require Import SimplExpr. Require Import SimplExprspec. Section PRESERVATION. Variable prog: Csyntax.program. Variable tprog: Clight.program. Hypothesis TRANSL: transl_program prog = OK tprog. Let ge := Csem.globalenv prog. Let tge := Clight.globalenv tprog. (** Invariance properties. *) Lemma comp_env_preserved: Clight.genv_cenv tge = Csem.genv_cenv ge. Proof. monadInv TRANSL. auto. Qed. Lemma symbols_preserved: forall (s: ident), Genv.find_symbol tge s = Genv.find_symbol ge s. Proof. intros. eapply Genv.find_symbol_match. eapply transl_program_spec; eauto. simpl. tauto. Qed. Lemma public_preserved: forall (s: ident), Genv.public_symbol tge s = Genv.public_symbol ge s. Proof. intros. eapply Genv.public_symbol_match. eapply transl_program_spec; eauto. simpl. tauto. Qed. Lemma function_ptr_translated: forall b f, Genv.find_funct_ptr ge b = Some f -> exists tf, Genv.find_funct_ptr tge b = Some tf /\ tr_fundef f tf. Proof. intros. eapply Genv.find_funct_ptr_match. eapply transl_program_spec; eauto. assumption. Qed. Lemma functions_translated: forall v f, Genv.find_funct ge v = Some f -> exists tf, Genv.find_funct tge v = Some tf /\ tr_fundef f tf. Proof. intros. eapply Genv.find_funct_match. eapply transl_program_spec; eauto. assumption. Qed. Lemma varinfo_preserved: forall b, Genv.find_var_info tge b = Genv.find_var_info ge b. Proof. intros. destruct (Genv.find_var_info ge b) as [v|] eqn:V. - exploit Genv.find_var_info_match. eapply transl_program_spec; eauto. eassumption. intros [tv [A B]]. inv B. assumption. - destruct (Genv.find_var_info tge b) as [v'|] eqn:V'; auto. exploit Genv.find_var_info_rev_match. eapply transl_program_spec; eauto. eassumption. simpl. destruct (plt b (Genv.genv_next (Genv.globalenv prog))); try tauto. intros [v [A B]]. inv B. change (Genv.globalenv prog) with (Csem.genv_genv ge) in A. congruence. Qed. Lemma block_is_volatile_preserved: forall b, Genv.block_is_volatile tge b = Genv.block_is_volatile ge b. Proof. intros. unfold Genv.block_is_volatile. rewrite varinfo_preserved. auto. Qed. Lemma type_of_fundef_preserved: forall f tf, tr_fundef f tf -> type_of_fundef tf = Csyntax.type_of_fundef f. Proof. intros. inv H. inv H0; simpl. unfold type_of_function, Csyntax.type_of_function. congruence. auto. Qed. Lemma function_return_preserved: forall f tf, tr_function f tf -> fn_return tf = Csyntax.fn_return f. Proof. intros. inv H; auto. Qed. (** Translation of simple expressions. *) Lemma tr_simple_nil: (forall le dst r sl a tmps, tr_expr le dst r sl a tmps -> dst = For_val \/ dst = For_effects -> simple r = true -> sl = nil) /\(forall le rl sl al tmps, tr_exprlist le rl sl al tmps -> simplelist rl = true -> sl = nil). Proof. assert (A: forall dst a, dst = For_val \/ dst = For_effects -> final dst a = nil). intros. destruct H; subst dst; auto. apply tr_expr_exprlist; intros; simpl in *; try discriminate; auto. rewrite H0; auto. simpl; auto. rewrite H0; auto. simpl; auto. destruct H1; congruence. destruct (andb_prop _ _ H6). inv H1. rewrite H0; eauto. simpl; auto. unfold chunk_for_volatile_type in H9. destruct (type_is_volatile (Csyntax.typeof e1)); simpl in H8; congruence. rewrite H0; auto. simpl; auto. rewrite H0; auto. simpl; auto. destruct (andb_prop _ _ H7). rewrite H0; auto. rewrite H2; auto. simpl; auto. rewrite H0; auto. simpl; auto. destruct (andb_prop _ _ H6). rewrite H0; auto. Qed. Lemma tr_simple_expr_nil: forall le dst r sl a tmps, tr_expr le dst r sl a tmps -> dst = For_val \/ dst = For_effects -> simple r = true -> sl = nil. Proof (proj1 tr_simple_nil). Lemma tr_simple_exprlist_nil: forall le rl sl al tmps, tr_exprlist le rl sl al tmps -> simplelist rl = true -> sl = nil. Proof (proj2 tr_simple_nil). (** Translation of [deref_loc] and [assign_loc] operations. *) Remark deref_loc_translated: forall ty m b ofs t v, Csem.deref_loc ge ty m b ofs t v -> match chunk_for_volatile_type ty with | None => t = E0 /\ Clight.deref_loc ty m b ofs v | Some chunk => volatile_load tge chunk m b ofs t v end. Proof. intros. unfold chunk_for_volatile_type. inv H. (* By_value, not volatile *) rewrite H1. split; auto. eapply deref_loc_value; eauto. (* By_value, volatile *) rewrite H0; rewrite H1. eapply volatile_load_preserved with (ge1 := ge); auto. exact symbols_preserved. exact public_preserved. exact block_is_volatile_preserved. (* By reference *) rewrite H0. destruct (type_is_volatile ty); split; auto; eapply deref_loc_reference; eauto. (* By copy *) rewrite H0. destruct (type_is_volatile ty); split; auto; eapply deref_loc_copy; eauto. Qed. Remark assign_loc_translated: forall ty m b ofs v t m', Csem.assign_loc ge ty m b ofs v t m' -> match chunk_for_volatile_type ty with | None => t = E0 /\ Clight.assign_loc tge ty m b ofs v m' | Some chunk => volatile_store tge chunk m b ofs v t m' end. Proof. intros. unfold chunk_for_volatile_type. inv H. (* By_value, not volatile *) rewrite H1. split; auto. eapply assign_loc_value; eauto. (* By_value, volatile *) rewrite H0; rewrite H1. eapply volatile_store_preserved with (ge1 := ge); auto. exact symbols_preserved. exact public_preserved. exact block_is_volatile_preserved. (* By copy *) rewrite H0. rewrite <- comp_env_preserved in *. destruct (type_is_volatile ty); split; auto; eapply assign_loc_copy; eauto. Qed. (** Evaluation of simple expressions and of their translation *) Lemma tr_simple: forall e m, (forall r v, eval_simple_rvalue ge e m r v -> forall le dst sl a tmps, tr_expr le dst r sl a tmps -> match dst with | For_val => sl = nil /\ Csyntax.typeof r = typeof a /\ eval_expr tge e le m a v | For_effects => sl = nil | For_set sd => exists b, sl = do_set sd b /\ Csyntax.typeof r = typeof b /\ eval_expr tge e le m b v end) /\ (forall l b ofs, eval_simple_lvalue ge e m l b ofs -> forall le sl a tmps, tr_expr le For_val l sl a tmps -> sl = nil /\ Csyntax.typeof l = typeof a /\ eval_lvalue tge e le m a b ofs). Proof. Opaque makeif. intros e m. apply (eval_simple_rvalue_lvalue_ind ge e m); intros until tmps; intros TR; inv TR. (* value *) auto. auto. exists a0; auto. (* rvalof *) inv H7; try congruence. exploit H0; eauto. intros [A [B C]]. subst sl1; simpl. assert (eval_expr tge e le m a v). eapply eval_Elvalue. eauto. rewrite <- B. exploit deref_loc_translated; eauto. unfold chunk_for_volatile_type; rewrite H2. tauto. destruct dst; auto. econstructor. split. simpl; eauto. auto. (* addrof *) exploit H0; eauto. intros [A [B C]]. subst sl1; simpl. assert (eval_expr tge e le m (Eaddrof a1 ty) (Vptr b ofs)). econstructor; eauto. destruct dst; auto. simpl; econstructor; eauto. (* unop *) exploit H0; eauto. intros [A [B C]]. subst sl1; simpl. assert (eval_expr tge e le m (Eunop op a1 ty) v). econstructor; eauto. congruence. destruct dst; auto. simpl; econstructor; eauto. (* binop *) exploit H0; eauto. intros [A [B C]]. exploit H2; eauto. intros [D [E F]]. subst sl1 sl2; simpl. assert (eval_expr tge e le m (Ebinop op a1 a2 ty) v). econstructor; eauto. rewrite comp_env_preserved; congruence. destruct dst; auto. simpl; econstructor; eauto. (* cast *) exploit H0; eauto. intros [A [B C]]. subst sl1; simpl. assert (eval_expr tge e le m (Ecast a1 ty) v). econstructor; eauto. congruence. destruct dst; auto. simpl; econstructor; eauto. (* sizeof *) rewrite <- comp_env_preserved. destruct dst. split; auto. split; auto. constructor. auto. exists (Esizeof ty1 ty). split. auto. split. auto. constructor. (* alignof *) rewrite <- comp_env_preserved. destruct dst. split; auto. split; auto. constructor. auto. exists (Ealignof ty1 ty). split. auto. split. auto. constructor. (* var local *) split; auto. split; auto. apply eval_Evar_local; auto. (* var global *) split; auto. split; auto. apply eval_Evar_global; auto. rewrite symbols_preserved; auto. (* deref *) exploit H0; eauto. intros [A [B C]]. subst sl1. split; auto. split; auto. constructor; auto. (* field struct *) rewrite <- comp_env_preserved in *. exploit H0; eauto. intros [A [B C]]. subst sl1. split; auto. split; auto. rewrite B in H1. eapply eval_Efield_struct; eauto. (* field union *) rewrite <- comp_env_preserved in *. exploit H0; eauto. intros [A [B C]]. subst sl1. split; auto. split; auto. rewrite B in H1. eapply eval_Efield_union; eauto. Qed. Lemma tr_simple_rvalue: forall e m r v, eval_simple_rvalue ge e m r v -> forall le dst sl a tmps, tr_expr le dst r sl a tmps -> match dst with | For_val => sl = nil /\ Csyntax.typeof r = typeof a /\ eval_expr tge e le m a v | For_effects => sl = nil | For_set sd => exists b, sl = do_set sd b /\ Csyntax.typeof r = typeof b /\ eval_expr tge e le m b v end. Proof. intros e m. exact (proj1 (tr_simple e m)). Qed. Lemma tr_simple_lvalue: forall e m l b ofs, eval_simple_lvalue ge e m l b ofs -> forall le sl a tmps, tr_expr le For_val l sl a tmps -> sl = nil /\ Csyntax.typeof l = typeof a /\ eval_lvalue tge e le m a b ofs. Proof. intros e m. exact (proj2 (tr_simple e m)). Qed. Lemma tr_simple_exprlist: forall le rl sl al tmps, tr_exprlist le rl sl al tmps -> forall e m tyl vl, eval_simple_list ge e m rl tyl vl -> sl = nil /\ eval_exprlist tge e le m al tyl vl. Proof. induction 1; intros. inv H. split. auto. constructor. inv H4. exploit tr_simple_rvalue; eauto. intros [A [B C]]. exploit IHtr_exprlist; eauto. intros [D E]. split. subst; auto. econstructor; eauto. congruence. Qed. (** Commutation between the translation of expressions and left contexts. *) Lemma typeof_context: forall k1 k2 C, leftcontext k1 k2 C -> forall e1 e2, Csyntax.typeof e1 = Csyntax.typeof e2 -> Csyntax.typeof (C e1) = Csyntax.typeof (C e2). Proof. induction 1; intros; auto. Qed. Scheme leftcontext_ind2 := Minimality for leftcontext Sort Prop with leftcontextlist_ind2 := Minimality for leftcontextlist Sort Prop. Combined Scheme leftcontext_leftcontextlist_ind from leftcontext_ind2, leftcontextlist_ind2. Lemma tr_expr_leftcontext_rec: ( forall from to C, leftcontext from to C -> forall le e dst sl a tmps, tr_expr le dst (C e) sl a tmps -> exists dst', exists sl1, exists sl2, exists a', exists tmp', tr_expr le dst' e sl1 a' tmp' /\ sl = sl1 ++ sl2 /\ incl tmp' tmps /\ (forall le' e' sl3, tr_expr le' dst' e' sl3 a' tmp' -> (forall id, ~In id tmp' -> le'!id = le!id) -> Csyntax.typeof e' = Csyntax.typeof e -> tr_expr le' dst (C e') (sl3 ++ sl2) a tmps) ) /\ ( forall from C, leftcontextlist from C -> forall le e sl a tmps, tr_exprlist le (C e) sl a tmps -> exists dst', exists sl1, exists sl2, exists a', exists tmp', tr_expr le dst' e sl1 a' tmp' /\ sl = sl1 ++ sl2 /\ incl tmp' tmps /\ (forall le' e' sl3, tr_expr le' dst' e' sl3 a' tmp' -> (forall id, ~In id tmp' -> le'!id = le!id) -> Csyntax.typeof e' = Csyntax.typeof e -> tr_exprlist le' (C e') (sl3 ++ sl2) a tmps) ). Proof. Ltac TR := econstructor; econstructor; econstructor; econstructor; econstructor; split; [eauto | split; [idtac | split]]. Ltac NOTIN := match goal with | [ H1: In ?x ?l, H2: list_disjoint ?l _ |- ~In ?x _ ] => red; intro; elim (H2 x x); auto; fail | [ H1: In ?x ?l, H2: list_disjoint _ ?l |- ~In ?x _ ] => red; intro; elim (H2 x x); auto; fail end. Ltac UNCHANGED := match goal with | [ H: (forall (id: ident), ~In id _ -> ?le' ! id = ?le ! id) |- (forall (id: ident), In id _ -> ?le' ! id = ?le ! id) ] => intros; apply H; NOTIN end. (*generalize compat_dest_change; intro CDC.*) apply leftcontext_leftcontextlist_ind; intros. (* base *) TR. rewrite <- app_nil_end; auto. red; auto. intros. rewrite <- app_nil_end; auto. (* deref *) inv H1. exploit H0; eauto. intros [dst' [sl1' [sl2' [a' [tmp' [P [Q [R S]]]]]]]]. TR. subst sl1; rewrite app_ass; eauto. auto. intros. rewrite <- app_ass. econstructor; eauto. (* field *) inv H1. exploit H0. eauto. intros [dst' [sl1' [sl2' [a' [tmp' [P [Q [R S]]]]]]]]. TR. subst sl1; rewrite app_ass; eauto. auto. intros. rewrite <- app_ass. econstructor; eauto. (* rvalof *) inv H1. exploit H0; eauto. intros [dst' [sl1' [sl2' [a' [tmp' [P [Q [R S]]]]]]]]. TR. subst sl1; rewrite app_ass; eauto. red; eauto. intros. rewrite <- app_ass; econstructor; eauto. exploit typeof_context; eauto. congruence. (* addrof *) inv H1. exploit H0; eauto. intros [dst' [sl1' [sl2' [a' [tmp' [P [Q [R S]]]]]]]]. TR. subst sl1; rewrite app_ass; eauto. auto. intros. rewrite <- app_ass. econstructor; eauto. (* unop *) inv H1. exploit H0; eauto. intros [dst' [sl1' [sl2' [a' [tmp' [P [Q [R S]]]]]]]]. TR. subst sl1; rewrite app_ass; eauto. auto. intros. rewrite <- app_ass. econstructor; eauto. (* binop left *) inv H1. exploit H0; eauto. intros [dst' [sl1' [sl2' [a' [tmp' [P [Q [R S]]]]]]]]. TR. subst sl1. rewrite app_ass. eauto. red; auto. intros. rewrite <- app_ass. econstructor; eauto. eapply tr_expr_invariant; eauto. UNCHANGED. (* binop right *) inv H2. assert (sl1 = nil) by (eapply tr_simple_expr_nil; eauto). subst sl1; simpl. exploit H1; eauto. intros [dst' [sl1' [sl2' [a' [tmp' [P [Q [R S]]]]]]]]. TR. subst sl2. rewrite app_ass. eauto. red; auto. intros. rewrite <- app_ass. change (sl3 ++ sl2') with (nil ++ sl3 ++ sl2'). rewrite app_ass. econstructor; eauto. eapply tr_expr_invariant; eauto. UNCHANGED. (* cast *) inv H1. exploit H0; eauto. intros [dst' [sl1' [sl2' [a' [tmp' [P [Q [R S]]]]]]]]. TR. subst sl1; rewrite app_ass; eauto. auto. intros. rewrite <- app_ass. econstructor; eauto. (* seqand *) inv H1. (* for val *) exploit H0; eauto. intros [dst' [sl1' [sl2' [a' [tmp' [P [Q [R S]]]]]]]]. TR. rewrite Q. rewrite app_ass. eauto. red; auto. intros. rewrite <- app_ass. econstructor. apply S; auto. eapply tr_expr_invariant; eauto. UNCHANGED. auto. auto. auto. auto. (* for effects *) exploit H0; eauto. intros [dst' [sl1' [sl2' [a' [tmp' [P [Q [R S]]]]]]]]. TR. rewrite Q. rewrite app_ass. eauto. red; auto. intros. rewrite <- app_ass. econstructor. apply S; auto. eapply tr_expr_invariant; eauto. UNCHANGED. auto. auto. auto. auto. (* for set *) exploit H0; eauto. intros [dst' [sl1' [sl2' [a' [tmp' [P [Q [R S]]]]]]]]. TR. rewrite Q. rewrite app_ass. eauto. red; auto. intros. rewrite <- app_ass. econstructor. apply S; auto. eapply tr_expr_invariant; eauto. UNCHANGED. auto. auto. auto. auto. (* seqor *) inv H1. (* for val *) exploit H0; eauto. intros [dst' [sl1' [sl2' [a' [tmp' [P [Q [R S]]]]]]]]. TR. rewrite Q. rewrite app_ass. eauto. red; auto. intros. rewrite <- app_ass. econstructor. apply S; auto. eapply tr_expr_invariant; eauto. UNCHANGED. auto. auto. auto. auto. (* for effects *) exploit H0; eauto. intros [dst' [sl1' [sl2' [a' [tmp' [P [Q [R S]]]]]]]]. TR. rewrite Q. rewrite app_ass. eauto. red; auto. intros. rewrite <- app_ass. econstructor. apply S; auto. eapply tr_expr_invariant; eauto. UNCHANGED. auto. auto. auto. auto. (* for set *) exploit H0; eauto. intros [dst' [sl1' [sl2' [a' [tmp' [P [Q [R S]]]]]]]]. TR. rewrite Q. rewrite app_ass. eauto. red; auto. intros. rewrite <- app_ass. econstructor. apply S; auto. eapply tr_expr_invariant; eauto. UNCHANGED. auto. auto. auto. auto. (* condition *) inv H1. (* for val *) exploit H0; eauto. intros [dst' [sl1' [sl2' [a' [tmp' [P [Q [R S]]]]]]]]. TR. rewrite Q. rewrite app_ass. eauto. red; auto. intros. rewrite <- app_ass. econstructor. apply S; auto. eapply tr_expr_invariant; eauto. UNCHANGED. eapply tr_expr_invariant; eauto. UNCHANGED. auto. auto. auto. auto. auto. auto. (* for effects *) exploit H0; eauto. intros [dst' [sl1' [sl2' [a' [tmp' [P [Q [R S]]]]]]]]. TR. rewrite Q. rewrite app_ass. eauto. red; auto. intros. rewrite <- app_ass. eapply tr_condition_effects. apply S; auto. eapply tr_expr_invariant; eauto. UNCHANGED. eapply tr_expr_invariant; eauto. UNCHANGED. auto. auto. auto. auto. auto. (* for set *) exploit H0; eauto. intros [dst' [sl1' [sl2' [a' [tmp' [P [Q [R S]]]]]]]]. TR. rewrite Q. rewrite app_ass. eauto. red; auto. intros. rewrite <- app_ass. eapply tr_condition_set. apply S; auto. eapply tr_expr_invariant; eauto. UNCHANGED. eapply tr_expr_invariant; eauto. UNCHANGED. auto. auto. auto. auto. auto. auto. (* assign left *) inv H1. (* for effects *) exploit H0; eauto. intros [dst' [sl1' [sl2' [a' [tmp' [P [Q [R S]]]]]]]]. TR. subst sl1. rewrite app_ass. eauto. red; auto. intros. rewrite <- app_ass. econstructor. apply S; auto. eapply tr_expr_invariant; eauto. UNCHANGED. auto. auto. auto. (* for val *) exploit H0; eauto. intros [dst' [sl1' [sl2' [a' [tmp' [P [Q [R S]]]]]]]]. TR. subst sl1. rewrite app_ass. eauto. red; auto. intros. rewrite <- app_ass. econstructor. apply S; auto. eapply tr_expr_invariant; eauto. UNCHANGED. auto. auto. auto. auto. auto. auto. eapply typeof_context; eauto. auto. (* assign right *) inv H2. (* for effects *) assert (sl1 = nil) by (eapply tr_simple_expr_nil; eauto). subst sl1; simpl. exploit H1; eauto. intros [dst' [sl1' [sl2' [a' [tmp' [P [Q [R S]]]]]]]]. TR. subst sl2. rewrite app_ass. eauto. red; auto. intros. rewrite <- app_ass. change (sl3 ++ sl2') with (nil ++ (sl3 ++ sl2')). rewrite app_ass. econstructor. eapply tr_expr_invariant; eauto. UNCHANGED. apply S; auto. auto. auto. auto. (* for val *) assert (sl1 = nil) by (eapply tr_simple_expr_nil; eauto). subst sl1; simpl. exploit H1; eauto. intros [dst' [sl1' [sl2' [a' [tmp' [P [Q [R S]]]]]]]]. TR. subst sl2. rewrite app_ass. eauto. red; auto. intros. rewrite <- app_ass. change (sl3 ++ sl2') with (nil ++ (sl3 ++ sl2')). rewrite app_ass. econstructor. eapply tr_expr_invariant; eauto. UNCHANGED. apply S; auto. auto. auto. auto. auto. auto. auto. auto. eapply typeof_context; eauto. (* assignop left *) inv H1. (* for effects *) exploit H0; eauto. intros [dst' [sl1' [sl2' [a' [tmp' [P [Q [R S]]]]]]]]. TR. subst sl1. rewrite app_ass. eauto. red; auto. intros. rewrite <- app_ass. econstructor. apply S; auto. eapply tr_expr_invariant; eauto. UNCHANGED. symmetry; eapply typeof_context; eauto. eauto. auto. auto. auto. auto. auto. auto. (* for val *) exploit H0; eauto. intros [dst' [sl1' [sl2' [a' [tmp' [P [Q [R S]]]]]]]]. TR. subst sl1. rewrite app_ass. eauto. red; auto. intros. rewrite <- app_ass. econstructor. apply S; auto. eapply tr_expr_invariant; eauto. UNCHANGED. eauto. auto. auto. auto. auto. auto. auto. auto. auto. auto. auto. eapply typeof_context; eauto. (* assignop right *) inv H2. (* for effects *) assert (sl1 = nil) by (eapply tr_simple_expr_nil; eauto). subst sl1; simpl. exploit H1; eauto. intros [dst' [sl1' [sl2' [a' [tmp' [P [Q [R S]]]]]]]]. TR. subst sl2. rewrite app_ass. eauto. red; auto. intros. rewrite <- app_ass. change (sl0 ++ sl2') with (nil ++ sl0 ++ sl2'). rewrite app_ass. econstructor. eapply tr_expr_invariant; eauto. UNCHANGED. apply S; auto. auto. eauto. auto. auto. auto. auto. auto. auto. (* for val *) assert (sl1 = nil) by (eapply tr_simple_expr_nil; eauto). subst sl1; simpl. exploit H1; eauto. intros [dst' [sl1' [sl2' [a' [tmp' [P [Q [R S]]]]]]]]. TR. subst sl2. rewrite app_ass. eauto. red; auto. intros. rewrite <- app_ass. change (sl0 ++ sl2') with (nil ++ sl0 ++ sl2'). rewrite app_ass. econstructor. eapply tr_expr_invariant; eauto. UNCHANGED. apply S; auto. eauto. auto. auto. auto. auto. auto. auto. auto. auto. auto. auto. auto. (* postincr *) inv H1. (* for effects *) exploit H0; eauto. intros [dst' [sl1' [sl2' [a' [tmp' [P [Q [R S]]]]]]]]. TR. rewrite Q; rewrite app_ass; eauto. red; auto. intros. rewrite <- app_ass. econstructor; eauto. symmetry; eapply typeof_context; eauto. (* for val *) exploit H0; eauto. intros [dst' [sl1' [sl2' [a' [tmp' [P [Q [R S]]]]]]]]. TR. rewrite Q; rewrite app_ass; eauto. red; auto. intros. rewrite <- app_ass. econstructor; eauto. eapply typeof_context; eauto. (* call left *) inv H1. (* for effects *) exploit H0; eauto. intros [dst' [sl1' [sl2' [a' [tmp' [P [Q [R S]]]]]]]]. TR. rewrite Q; rewrite app_ass; eauto. red; auto. intros. rewrite <- app_ass. econstructor. apply S; auto. eapply tr_exprlist_invariant; eauto. UNCHANGED. auto. auto. auto. (* for val *) exploit H0; eauto. intros [dst' [sl1' [sl2' [a' [tmp' [P [Q [R S]]]]]]]]. TR. rewrite Q; rewrite app_ass; eauto. red; auto. intros. rewrite <- app_ass. econstructor. auto. apply S; auto. eapply tr_exprlist_invariant; eauto. UNCHANGED. auto. auto. auto. auto. (* call right *) inv H2. (* for effects *) assert (sl1 = nil) by (eapply tr_simple_expr_nil; eauto). subst sl1; simpl. exploit H1; eauto. intros [dst' [sl1' [sl2' [a' [tmp' [P [Q [R S]]]]]]]]. TR. rewrite Q; rewrite app_ass; eauto. (*destruct dst'; constructor||contradiction.*) red; auto. intros. rewrite <- app_ass. change (sl3++sl2') with (nil ++ sl3 ++ sl2'). rewrite app_ass. econstructor. eapply tr_expr_invariant; eauto. UNCHANGED. apply S; auto. auto. auto. auto. (* for val *) assert (sl1 = nil) by (eapply tr_simple_expr_nil; eauto). subst sl1; simpl. exploit H1; eauto. intros [dst' [sl1' [sl2' [a' [tmp' [P [Q [R S]]]]]]]]. TR. rewrite Q; rewrite app_ass; eauto. (*destruct dst'; constructor||contradiction.*) red; auto. intros. rewrite <- app_ass. change (sl3++sl2') with (nil ++ sl3 ++ sl2'). rewrite app_ass. econstructor. auto. eapply tr_expr_invariant; eauto. UNCHANGED. apply S; auto. auto. auto. auto. auto. (* builtin *) inv H1. (* for effects *) exploit H0; eauto. intros [dst' [sl1' [sl2' [a' [tmp' [P [Q [R S]]]]]]]]. TR. rewrite Q; rewrite app_ass; eauto. red; auto. intros. rewrite <- app_ass. change (sl3++sl2') with (nil ++ sl3 ++ sl2'). rewrite app_ass. econstructor. apply S; auto. auto. (* for val *) exploit H0; eauto. intros [dst' [sl1' [sl2' [a' [tmp' [P [Q [R S]]]]]]]]. TR. rewrite Q; rewrite app_ass; eauto. red; auto. intros. rewrite <- app_ass. change (sl3++sl2') with (nil ++ sl3 ++ sl2'). rewrite app_ass. econstructor. auto. apply S; auto. auto. auto. (* comma *) inv H1. exploit H0; eauto. intros [dst' [sl1' [sl2' [a' [tmp' [P [Q [R S]]]]]]]]. TR. rewrite Q; rewrite app_ass; eauto. red; auto. intros. rewrite <- app_ass. econstructor. apply S; auto. eapply tr_expr_invariant; eauto. UNCHANGED. auto. auto. auto. (* paren *) inv H1. (* for val *) exploit H0; eauto. intros [dst' [sl1' [sl2' [a' [tmp' [P [Q [R S]]]]]]]]. TR. rewrite Q. eauto. red; auto. intros. econstructor; eauto. (* for effects *) exploit H0; eauto. intros [dst' [sl1' [sl2' [a' [tmp' [P [Q [R S]]]]]]]]. TR. rewrite Q. eauto. auto. intros. econstructor; eauto. (* for set *) exploit H0; eauto. intros [dst' [sl1' [sl2' [a' [tmp' [P [Q [R S]]]]]]]]. TR. rewrite Q. eauto. auto. intros. econstructor; eauto. (* cons left *) inv H1. exploit H0; eauto. intros [dst' [sl1' [sl2' [a' [tmp' [P [Q [R S]]]]]]]]. TR. subst sl1. rewrite app_ass. eauto. red; auto. intros. rewrite <- app_ass. econstructor. apply S; auto. eapply tr_exprlist_invariant; eauto. UNCHANGED. auto. auto. auto. (* cons right *) inv H2. assert (sl1 = nil) by (eapply tr_simple_expr_nil; eauto). subst sl1; simpl. exploit H1; eauto. intros [dst' [sl1' [sl2' [a' [tmp' [P [Q [R S]]]]]]]]. TR. subst sl2. eauto. red; auto. intros. change sl3 with (nil ++ sl3). rewrite app_ass. econstructor. eapply tr_expr_invariant; eauto. UNCHANGED. apply S; auto. auto. auto. auto. Qed. Theorem tr_expr_leftcontext: forall C le r dst sl a tmps, leftcontext RV RV C -> tr_expr le dst (C r) sl a tmps -> exists dst', exists sl1, exists sl2, exists a', exists tmp', tr_expr le dst' r sl1 a' tmp' /\ sl = sl1 ++ sl2 /\ incl tmp' tmps /\ (forall le' r' sl3, tr_expr le' dst' r' sl3 a' tmp' -> (forall id, ~In id tmp' -> le'!id = le!id) -> Csyntax.typeof r' = Csyntax.typeof r -> tr_expr le' dst (C r') (sl3 ++ sl2) a tmps). Proof. intros. eapply (proj1 tr_expr_leftcontext_rec); eauto. Qed. Theorem tr_top_leftcontext: forall e le m dst rtop sl a tmps, tr_top tge e le m dst rtop sl a tmps -> forall r C, rtop = C r -> leftcontext RV RV C -> exists dst', exists sl1, exists sl2, exists a', exists tmp', tr_top tge e le m dst' r sl1 a' tmp' /\ sl = sl1 ++ sl2 /\ incl tmp' tmps /\ (forall le' m' r' sl3, tr_expr le' dst' r' sl3 a' tmp' -> (forall id, ~In id tmp' -> le'!id = le!id) -> Csyntax.typeof r' = Csyntax.typeof r -> tr_top tge e le' m' dst (C r') (sl3 ++ sl2) a tmps). Proof. induction 1; intros. (* val for val *) inv H2; inv H1. exists For_val; econstructor; econstructor; econstructor; econstructor. split. apply tr_top_val_val; eauto. split. instantiate (1 := nil); auto. split. apply incl_refl. intros. rewrite <- app_nil_end. constructor; auto. (* base *) subst r. exploit tr_expr_leftcontext; eauto. intros [dst' [sl1 [sl2 [a' [tmp' [P [Q [R S]]]]]]]]. exists dst'; exists sl1; exists sl2; exists a'; exists tmp'. split. apply tr_top_base; auto. split. auto. split. auto. intros. apply tr_top_base. apply S; auto. Qed. (** Semantics of smart constructors *) Lemma eval_simpl_expr_sound: forall e le m a v, eval_expr tge e le m a v -> match eval_simpl_expr a with Some v' => v' = v | None => True end. Proof. induction 1; simpl; auto. destruct (eval_simpl_expr a); auto. subst. rewrite H0. auto. inv H; simpl; auto. Qed. Lemma static_bool_val_sound: forall v t m b, bool_val v t Mem.empty = Some b -> bool_val v t m = Some b. Proof. intros until b; unfold bool_val. destruct (classify_bool t); destruct v; auto. intros E. unfold Mem.weak_valid_pointer, Mem.valid_pointer, proj_sumbool in E. rewrite ! pred_dec_false in E by (apply Mem.perm_empty). discriminate. Qed. Lemma step_makeif: forall f a s1 s2 k e le m v1 b, eval_expr tge e le m a v1 -> bool_val v1 (typeof a) m = Some b -> star step1 tge (State f (makeif a s1 s2) k e le m) E0 (State f (if b then s1 else s2) k e le m). Proof. intros. functional induction (makeif a s1 s2). - exploit eval_simpl_expr_sound; eauto. rewrite e0. intro EQ; subst v. assert (bool_val v1 (typeof a) m = Some true) by (apply static_bool_val_sound; auto). replace b with true by congruence. constructor. - exploit eval_simpl_expr_sound; eauto. rewrite e0. intro EQ; subst v. assert (bool_val v1 (typeof a) m = Some false) by (apply static_bool_val_sound; auto). replace b with false by congruence. constructor. - apply star_one. eapply step_ifthenelse; eauto. - apply star_one. eapply step_ifthenelse; eauto. Qed. Lemma step_make_set: forall id a ty m b ofs t v e le f k, Csem.deref_loc ge ty m b ofs t v -> eval_lvalue tge e le m a b ofs -> typeof a = ty -> step1 tge (State f (make_set id a) k e le m) t (State f Sskip k e (PTree.set id v le) m). Proof. intros. exploit deref_loc_translated; eauto. rewrite <- H1. unfold make_set. destruct (chunk_for_volatile_type (typeof a)) as [chunk|]. (* volatile case *) intros. change (PTree.set id v le) with (set_opttemp (Some id) v le). econstructor. econstructor. constructor. eauto. simpl. unfold sem_cast. simpl. eauto. constructor. simpl. econstructor; eauto. (* nonvolatile case *) intros [A B]. subst t. constructor. eapply eval_Elvalue; eauto. Qed. Lemma step_make_assign: forall a1 a2 ty m b ofs t v m' v2 e le f k, Csem.assign_loc ge ty m b ofs v t m' -> eval_lvalue tge e le m a1 b ofs -> eval_expr tge e le m a2 v2 -> sem_cast v2 (typeof a2) ty = Some v -> typeof a1 = ty -> step1 tge (State f (make_assign a1 a2) k e le m) t (State f Sskip k e le m'). Proof. intros. exploit assign_loc_translated; eauto. rewrite <- H3. unfold make_assign. destruct (chunk_for_volatile_type (typeof a1)) as [chunk|]. (* volatile case *) intros. change le with (set_opttemp None Vundef le) at 2. econstructor. econstructor. constructor. eauto. simpl. unfold sem_cast. simpl. eauto. econstructor; eauto. rewrite H3; eauto. constructor. simpl. econstructor; eauto. (* nonvolatile case *) intros [A B]. subst t. econstructor; eauto. congruence. Qed. Fixpoint Kseqlist (sl: list statement) (k: cont) := match sl with | nil => k | s :: l => Kseq s (Kseqlist l k) end. Remark Kseqlist_app: forall sl1 sl2 k, Kseqlist (sl1 ++ sl2) k = Kseqlist sl1 (Kseqlist sl2 k). Proof. induction sl1; simpl; congruence. Qed. Lemma push_seq: forall f sl k e le m, star step1 tge (State f (makeseq sl) k e le m) E0 (State f Sskip (Kseqlist sl k) e le m). Proof. intros. unfold makeseq. generalize Sskip. revert sl k. induction sl; simpl; intros. apply star_refl. eapply star_right. apply IHsl. constructor. traceEq. Qed. Lemma step_tr_rvalof: forall ty m b ofs t v e le a sl a' tmp f k, Csem.deref_loc ge ty m b ofs t v -> eval_lvalue tge e le m a b ofs -> tr_rvalof ty a sl a' tmp -> typeof a = ty -> exists le', star step1 tge (State f Sskip (Kseqlist sl k) e le m) t (State f Sskip k e le' m) /\ eval_expr tge e le' m a' v /\ typeof a' = typeof a /\ forall x, ~In x tmp -> le'!x = le!x. Proof. intros. inv H1. (* not volatile *) exploit deref_loc_translated; eauto. unfold chunk_for_volatile_type; rewrite H3. intros [A B]. subst t. exists le; split. apply star_refl. split. eapply eval_Elvalue; eauto. auto. (* volatile *) intros. exists (PTree.set t0 v le); split. simpl. eapply star_two. econstructor. eapply step_make_set; eauto. traceEq. split. constructor. apply PTree.gss. split. auto. intros. apply PTree.gso. congruence. Qed. (** Matching between continuations *) Inductive match_cont : Csem.cont -> cont -> Prop := | match_Kstop: match_cont Csem.Kstop Kstop | match_Kseq: forall s k ts tk, tr_stmt s ts -> match_cont k tk -> match_cont (Csem.Kseq s k) (Kseq ts tk) | match_Kwhile2: forall r s k s' ts tk, tr_if r Sskip Sbreak s' -> tr_stmt s ts -> match_cont k tk -> match_cont (Csem.Kwhile2 r s k) (Kloop1 (Ssequence s' ts) Sskip tk) | match_Kdowhile1: forall r s k s' ts tk, tr_if r Sskip Sbreak s' -> tr_stmt s ts -> match_cont k tk -> match_cont (Csem.Kdowhile1 r s k) (Kloop1 ts s' tk) | match_Kfor3: forall r s3 s k ts3 s' ts tk, tr_if r Sskip Sbreak s' -> tr_stmt s3 ts3 -> tr_stmt s ts -> match_cont k tk -> match_cont (Csem.Kfor3 r s3 s k) (Kloop1 (Ssequence s' ts) ts3 tk) | match_Kfor4: forall r s3 s k ts3 s' ts tk, tr_if r Sskip Sbreak s' -> tr_stmt s3 ts3 -> tr_stmt s ts -> match_cont k tk -> match_cont (Csem.Kfor4 r s3 s k) (Kloop2 (Ssequence s' ts) ts3 tk) | match_Kswitch2: forall k tk, match_cont k tk -> match_cont (Csem.Kswitch2 k) (Kswitch tk) | match_Kcall: forall f e C ty k optid tf le sl tk a dest tmps, tr_function f tf -> leftcontext RV RV C -> (forall v m, tr_top tge e (set_opttemp optid v le) m dest (C (Csyntax.Eval v ty)) sl a tmps) -> match_cont_exp dest a k tk -> match_cont (Csem.Kcall f e C ty k) (Kcall optid tf e le (Kseqlist sl tk)) (* | match_Kcall_some: forall f e C ty k dst tf le sl tk a dest tmps, transl_function f = Errors.OK tf -> leftcontext RV RV C -> (forall v m, tr_top tge e (PTree.set dst v le) m dest (C (C.Eval v ty)) sl a tmps) -> match_cont_exp dest a k tk -> match_cont (Csem.Kcall f e C ty k) (Kcall (Some dst) tf e le (Kseqlist sl tk)) *) with match_cont_exp : destination -> expr -> Csem.cont -> cont -> Prop := | match_Kdo: forall k a tk, match_cont k tk -> match_cont_exp For_effects a (Csem.Kdo k) tk | match_Kifthenelse_1: forall a s1 s2 k ts1 ts2 tk, tr_stmt s1 ts1 -> tr_stmt s2 ts2 -> match_cont k tk -> match_cont_exp For_val a (Csem.Kifthenelse s1 s2 k) (Kseq (Sifthenelse a ts1 ts2) tk) | match_Kwhile1: forall r s k s' a ts tk, tr_if r Sskip Sbreak s' -> tr_stmt s ts -> match_cont k tk -> match_cont_exp For_val a (Csem.Kwhile1 r s k) (Kseq (makeif a Sskip Sbreak) (Kseq ts (Kloop1 (Ssequence s' ts) Sskip tk))) | match_Kdowhile2: forall r s k s' a ts tk, tr_if r Sskip Sbreak s' -> tr_stmt s ts -> match_cont k tk -> match_cont_exp For_val a (Csem.Kdowhile2 r s k) (Kseq (makeif a Sskip Sbreak) (Kloop2 ts s' tk)) | match_Kfor2: forall r s3 s k s' a ts3 ts tk, tr_if r Sskip Sbreak s' -> tr_stmt s3 ts3 -> tr_stmt s ts -> match_cont k tk -> match_cont_exp For_val a (Csem.Kfor2 r s3 s k) (Kseq (makeif a Sskip Sbreak) (Kseq ts (Kloop1 (Ssequence s' ts) ts3 tk))) | match_Kswitch1: forall ls k a tls tk, tr_lblstmts ls tls -> match_cont k tk -> match_cont_exp For_val a (Csem.Kswitch1 ls k) (Kseq (Sswitch a tls) tk) | match_Kreturn: forall k a tk, match_cont k tk -> match_cont_exp For_val a (Csem.Kreturn k) (Kseq (Sreturn (Some a)) tk). Lemma match_cont_call: forall k tk, match_cont k tk -> match_cont (Csem.call_cont k) (call_cont tk). Proof. induction 1; simpl; auto. constructor. econstructor; eauto. Qed. (** Matching between states *) Inductive match_states: Csem.state -> state -> Prop := | match_exprstates: forall f r k e m tf sl tk le dest a tmps, tr_function f tf -> tr_top tge e le m dest r sl a tmps -> match_cont_exp dest a k tk -> match_states (Csem.ExprState f r k e m) (State tf Sskip (Kseqlist sl tk) e le m) | match_regularstates: forall f s k e m tf ts tk le, tr_function f tf -> tr_stmt s ts -> match_cont k tk -> match_states (Csem.State f s k e m) (State tf ts tk e le m) | match_callstates: forall fd args k m tfd tk, tr_fundef fd tfd -> match_cont k tk -> match_states (Csem.Callstate fd args k m) (Callstate tfd args tk m) | match_returnstates: forall res k m tk, match_cont k tk -> match_states (Csem.Returnstate res k m) (Returnstate res tk m) | match_stuckstate: forall S, match_states Csem.Stuckstate S. (** Additional results on translation of statements *) Lemma tr_select_switch: forall n ls tls, tr_lblstmts ls tls -> tr_lblstmts (Csem.select_switch n ls) (select_switch n tls). Proof. assert (DFL: forall ls tls, tr_lblstmts ls tls -> tr_lblstmts (Csem.select_switch_default ls) (select_switch_default tls)). { induction 1; simpl. constructor. destruct c; auto. constructor; auto. } assert (CASE: forall n ls tls, tr_lblstmts ls tls -> match Csem.select_switch_case n ls with | None => select_switch_case n tls = None | Some ls' => exists tls', select_switch_case n tls = Some tls' /\ tr_lblstmts ls' tls' end). { induction 1; simpl; intros. auto. destruct c; auto. destruct (zeq z n); auto. econstructor; split; eauto. constructor; auto. } intros. unfold Csem.select_switch, select_switch. specialize (CASE n ls tls H). destruct (Csem.select_switch_case n ls) as [ls'|]. destruct CASE as [tls' [P Q]]. rewrite P. auto. rewrite CASE. apply DFL; auto. Qed. Lemma tr_seq_of_labeled_statement: forall ls tls, tr_lblstmts ls tls -> tr_stmt (Csem.seq_of_labeled_statement ls) (seq_of_labeled_statement tls). Proof. induction 1; simpl; constructor; auto. Qed. (** Commutation between translation and the "find label" operation. *) Section FIND_LABEL. Variable lbl: label. Definition nolabel (s: statement) : Prop := forall k, find_label lbl s k = None. Fixpoint nolabel_list (sl: list statement) : Prop := match sl with | nil => True | s1 :: sl' => nolabel s1 /\ nolabel_list sl' end. Lemma nolabel_list_app: forall sl2 sl1, nolabel_list sl1 -> nolabel_list sl2 -> nolabel_list (sl1 ++ sl2). Proof. induction sl1; simpl; intros. auto. tauto. Qed. Lemma makeseq_nolabel: forall sl, nolabel_list sl -> nolabel (makeseq sl). Proof. assert (forall sl s, nolabel s -> nolabel_list sl -> nolabel (makeseq_rec s sl)). induction sl; simpl; intros. auto. destruct H0. apply IHsl; auto. red. intros; simpl. rewrite H. apply H0. intros. unfold makeseq. apply H; auto. red. auto. Qed. Lemma makeif_nolabel: forall a s1 s2, nolabel s1 -> nolabel s2 -> nolabel (makeif a s1 s2). Proof. intros. functional induction (makeif a s1 s2); auto. red; simpl; intros. rewrite H; auto. red; simpl; intros. rewrite H; auto. Qed. Lemma make_set_nolabel: forall t a, nolabel (make_set t a). Proof. unfold make_set; intros; red; intros. destruct (chunk_for_volatile_type (typeof a)); auto. Qed. Lemma make_assign_nolabel: forall l r, nolabel (make_assign l r). Proof. unfold make_assign; intros; red; intros. destruct (chunk_for_volatile_type (typeof l)); auto. Qed. Lemma tr_rvalof_nolabel: forall ty a sl a' tmp, tr_rvalof ty a sl a' tmp -> nolabel_list sl. Proof. destruct 1; simpl; intuition. apply make_set_nolabel. Qed. Lemma nolabel_do_set: forall sd a, nolabel_list (do_set sd a). Proof. induction sd; intros; simpl; split; auto; red; auto. Qed. Lemma nolabel_final: forall dst a, nolabel_list (final dst a). Proof. destruct dst; simpl; intros. auto. auto. apply nolabel_do_set. Qed. Ltac NoLabelTac := match goal with | [ |- nolabel_list nil ] => exact I | [ |- nolabel_list (final _ _) ] => apply nolabel_final (*; NoLabelTac*) | [ |- nolabel_list (_ :: _) ] => simpl; split; NoLabelTac | [ |- nolabel_list (_ ++ _) ] => apply nolabel_list_app; NoLabelTac | [ H: _ -> nolabel_list ?x |- nolabel_list ?x ] => apply H; NoLabelTac | [ |- nolabel (makeseq _) ] => apply makeseq_nolabel; NoLabelTac | [ |- nolabel (makeif _ _ _) ] => apply makeif_nolabel; NoLabelTac | [ |- nolabel (make_set _ _) ] => apply make_set_nolabel | [ |- nolabel (make_assign _ _) ] => apply make_assign_nolabel | [ |- nolabel _ ] => red; intros; simpl; auto | [ |- _ /\ _ ] => split; NoLabelTac | _ => auto end. Lemma tr_find_label_expr: (forall le dst r sl a tmps, tr_expr le dst r sl a tmps -> nolabel_list sl) /\(forall le rl sl al tmps, tr_exprlist le rl sl al tmps -> nolabel_list sl). Proof. apply tr_expr_exprlist; intros; NoLabelTac. apply nolabel_do_set. eapply tr_rvalof_nolabel; eauto. apply nolabel_do_set. apply nolabel_do_set. eapply tr_rvalof_nolabel; eauto. eapply tr_rvalof_nolabel; eauto. eapply tr_rvalof_nolabel; eauto. Qed. Lemma tr_find_label_top: forall e le m dst r sl a tmps, tr_top tge e le m dst r sl a tmps -> nolabel_list sl. Proof. induction 1; intros; NoLabelTac. eapply (proj1 tr_find_label_expr); eauto. Qed. Lemma tr_find_label_expression: forall r s a, tr_expression r s a -> forall k, find_label lbl s k = None. Proof. intros. inv H. assert (nolabel (makeseq sl)). apply makeseq_nolabel. eapply tr_find_label_top with (e := empty_env) (le := PTree.empty val) (m := Mem.empty). eauto. apply H. Qed. Lemma tr_find_label_expr_stmt: forall r s, tr_expr_stmt r s -> forall k, find_label lbl s k = None. Proof. intros. inv H. assert (nolabel (makeseq sl)). apply makeseq_nolabel. eapply tr_find_label_top with (e := empty_env) (le := PTree.empty val) (m := Mem.empty). eauto. apply H. Qed. Lemma tr_find_label_if: forall r s, tr_if r Sskip Sbreak s -> forall k, find_label lbl s k = None. Proof. intros. inv H. assert (nolabel (makeseq (sl ++ makeif a Sskip Sbreak :: nil))). apply makeseq_nolabel. apply nolabel_list_app. eapply tr_find_label_top with (e := empty_env) (le := PTree.empty val) (m := Mem.empty). eauto. simpl; split; auto. apply makeif_nolabel. red; simpl; auto. red; simpl; auto. apply H. Qed. Lemma tr_find_label: forall s k ts tk (TR: tr_stmt s ts) (MC: match_cont k tk), match Csem.find_label lbl s k with | None => find_label lbl ts tk = None | Some (s', k') => exists ts', exists tk', find_label lbl ts tk = Some (ts', tk') /\ tr_stmt s' ts' /\ match_cont k' tk' end with tr_find_label_ls: forall s k ts tk (TR: tr_lblstmts s ts) (MC: match_cont k tk), match Csem.find_label_ls lbl s k with | None => find_label_ls lbl ts tk = None | Some (s', k') => exists ts', exists tk', find_label_ls lbl ts tk = Some (ts', tk') /\ tr_stmt s' ts' /\ match_cont k' tk' end. Proof. induction s; intros; inversion TR; subst; clear TR; simpl. auto. eapply tr_find_label_expr_stmt; eauto. (* seq *) exploit (IHs1 (Csem.Kseq s2 k)); eauto. constructor; eauto. destruct (Csem.find_label lbl s1 (Csem.Kseq s2 k)) as [[s' k'] | ]. intros [ts' [tk' [A [B C]]]]. rewrite A. exists ts'; exists tk'; auto. intro EQ. rewrite EQ. eapply IHs2; eauto. (* if *) rename s' into sr. rewrite (tr_find_label_expression _ _ _ H2). exploit (IHs1 k); eauto. destruct (Csem.find_label lbl s1 k) as [[s' k'] | ]. intros [ts' [tk' [A [B C]]]]. rewrite A. exists ts'; exists tk'; intuition. intro EQ. rewrite EQ. eapply IHs2; eauto. (* while *) rename s' into sr. rewrite (tr_find_label_if _ _ H1); auto. exploit (IHs (Kwhile2 e s k)); eauto. econstructor; eauto. destruct (Csem.find_label lbl s (Kwhile2 e s k)) as [[s' k'] | ]. intros [ts' [tk' [A [B C]]]]. rewrite A. exists ts'; exists tk'; intuition. intro EQ. rewrite EQ. auto. (* dowhile *) rename s' into sr. rewrite (tr_find_label_if _ _ H1); auto. exploit (IHs (Kdowhile1 e s k)); eauto. econstructor; eauto. destruct (Csem.find_label lbl s (Kdowhile1 e s k)) as [[s' k'] | ]. intros [ts' [tk' [A [B C]]]]. rewrite A. exists ts'; exists tk'; intuition. intro EQ. rewrite EQ. auto. (* for skip *) rename s' into sr. rewrite (tr_find_label_if _ _ H4); auto. exploit (IHs3 (Csem.Kfor3 e s2 s3 k)); eauto. econstructor; eauto. destruct (Csem.find_label lbl s3 (Csem.Kfor3 e s2 s3 k)) as [[s' k'] | ]. intros [ts' [tk' [A [B C]]]]. rewrite A. exists ts'; exists tk'; intuition. intro EQ. rewrite EQ. exploit (IHs2 (Csem.Kfor4 e s2 s3 k)); eauto. econstructor; eauto. (* for not skip *) rename s' into sr. rewrite (tr_find_label_if _ _ H3); auto. exploit (IHs1 (Csem.Kseq (Csyntax.Sfor Csyntax.Sskip e s2 s3) k)); eauto. econstructor; eauto. econstructor; eauto. destruct (Csem.find_label lbl s1 (Csem.Kseq (Csyntax.Sfor Csyntax.Sskip e s2 s3) k)) as [[s' k'] | ]. intros [ts' [tk' [A [B C]]]]. rewrite A. exists ts'; exists tk'; intuition. intro EQ; rewrite EQ. exploit (IHs3 (Csem.Kfor3 e s2 s3 k)); eauto. econstructor; eauto. destruct (Csem.find_label lbl s3 (Csem.Kfor3 e s2 s3 k)) as [[s'' k''] | ]. intros [ts' [tk' [A [B C]]]]. rewrite A. exists ts'; exists tk'; intuition. intro EQ'. rewrite EQ'. exploit (IHs2 (Csem.Kfor4 e s2 s3 k)); eauto. econstructor; eauto. (* break, continue, return 0 *) auto. auto. auto. (* return 1 *) rewrite (tr_find_label_expression _ _ _ H0). auto. (* switch *) rewrite (tr_find_label_expression _ _ _ H1). apply tr_find_label_ls. auto. constructor; auto. (* labeled stmt *) destruct (ident_eq lbl l). exists ts0; exists tk; auto. apply IHs; auto. (* goto *) auto. induction s; intros; inversion TR; subst; clear TR; simpl. (* nil *) auto. (* case *) exploit (tr_find_label s (Csem.Kseq (Csem.seq_of_labeled_statement s0) k)); eauto. econstructor; eauto. apply tr_seq_of_labeled_statement; eauto. destruct (Csem.find_label lbl s (Csem.Kseq (Csem.seq_of_labeled_statement s0) k)) as [[s' k'] | ]. intros [ts' [tk' [A [B C]]]]. rewrite A. exists ts'; exists tk'; auto. intro EQ. rewrite EQ. eapply IHs; eauto. Qed. End FIND_LABEL. (** Anti-stuttering measure *) (** There are some stuttering steps in the translation: - The execution of [Sdo a] where [a] is side-effect free, which is three transitions in the source: << Sdo a, k ---> a, Kdo k ---> rval v, Kdo k ---> Sskip, k >> but the translation, which is [Sskip], makes no transitions. - The reduction [Ecomma (Eval v) r2 --> r2]. - The reduction [Eparen (Eval v) --> Eval v] in a [For_effects] context. The following measure decreases for these stuttering steps. *) Fixpoint esize (a: Csyntax.expr) : nat := match a with | Csyntax.Eloc _ _ _ => 1%nat | Csyntax.Evar _ _ => 1%nat | Csyntax.Ederef r1 _ => S(esize r1) | Csyntax.Efield l1 _ _ => S(esize l1) | Csyntax.Eval _ _ => O | Csyntax.Evalof l1 _ => S(esize l1) | Csyntax.Eaddrof l1 _ => S(esize l1) | Csyntax.Eunop _ r1 _ => S(esize r1) | Csyntax.Ebinop _ r1 r2 _ => S(esize r1 + esize r2)%nat | Csyntax.Ecast r1 _ => S(esize r1) | Csyntax.Eseqand r1 _ _ => S(esize r1) | Csyntax.Eseqor r1 _ _ => S(esize r1) | Csyntax.Econdition r1 _ _ _ => S(esize r1) | Csyntax.Esizeof _ _ => 1%nat | Csyntax.Ealignof _ _ => 1%nat | Csyntax.Eassign l1 r2 _ => S(esize l1 + esize r2)%nat | Csyntax.Eassignop _ l1 r2 _ _ => S(esize l1 + esize r2)%nat | Csyntax.Epostincr _ l1 _ => S(esize l1) | Csyntax.Ecomma r1 r2 _ => S(esize r1 + esize r2)%nat | Csyntax.Ecall r1 rl2 _ => S(esize r1 + esizelist rl2)%nat | Csyntax.Ebuiltin ef _ rl _ => S(esizelist rl)%nat | Csyntax.Eparen r1 _ _ => S(esize r1) end with esizelist (el: Csyntax.exprlist) : nat := match el with | Csyntax.Enil => O | Csyntax.Econs r1 rl2 => (esize r1 + esizelist rl2)%nat end. Definition measure (st: Csem.state) : nat := match st with | Csem.ExprState _ r _ _ _ => (esize r + 1)%nat | Csem.State _ Csyntax.Sskip _ _ _ => 0%nat | Csem.State _ (Csyntax.Sdo r) _ _ _ => (esize r + 2)%nat | Csem.State _ (Csyntax.Sifthenelse r _ _) _ _ _ => (esize r + 2)%nat | _ => 0%nat end. Lemma leftcontext_size: forall from to C, leftcontext from to C -> forall e1 e2, (esize e1 < esize e2)%nat -> (esize (C e1) < esize (C e2))%nat with leftcontextlist_size: forall from C, leftcontextlist from C -> forall e1 e2, (esize e1 < esize e2)%nat -> (esizelist (C e1) < esizelist (C e2))%nat. Proof. induction 1; intros; simpl; auto with arith. exploit leftcontextlist_size; eauto. auto with arith. exploit leftcontextlist_size; eauto. auto with arith. induction 1; intros; simpl; auto with arith. exploit leftcontext_size; eauto. auto with arith. Qed. (** Forward simulation for expressions. *) Lemma tr_val_gen: forall le dst v ty a tmp, typeof a = ty -> (forall tge e le' m, (forall id, In id tmp -> le'!id = le!id) -> eval_expr tge e le' m a v) -> tr_expr le dst (Csyntax.Eval v ty) (final dst a) a tmp. Proof. intros. destruct dst; simpl; econstructor; auto. Qed. Lemma estep_simulation: forall S1 t S2, Cstrategy.estep ge S1 t S2 -> forall S1' (MS: match_states S1 S1'), exists S2', (plus step1 tge S1' t S2' \/ (star step1 tge S1' t S2' /\ measure S2 < measure S1)%nat) /\ match_states S2 S2'. Proof. induction 1; intros; inv MS. (* expr *) assert (tr_expr le dest r sl a tmps). inv H9. contradiction. auto. exploit tr_simple_rvalue; eauto. destruct dest. (* for val *) intros [SL1 [TY1 EV1]]. subst sl. econstructor; split. right; split. apply star_refl. destruct r; simpl; (contradiction || omega). econstructor; eauto. instantiate (1 := tmps). apply tr_top_val_val; auto. (* for effects *) intros SL1. subst sl. econstructor; split. right; split. apply star_refl. destruct r; simpl; (contradiction || omega). econstructor; eauto. instantiate (1 := tmps). apply tr_top_base. constructor. (* for set *) inv H10. (* rval volatile *) exploit tr_top_leftcontext; eauto. clear H11. intros [dst' [sl1 [sl2 [a' [tmp' [P [Q [R S]]]]]]]]. inv P. inv H2. inv H7; try congruence. exploit tr_simple_lvalue; eauto. intros [SL [TY EV]]. subst sl0; simpl. econstructor; split. left. eapply plus_two. constructor. eapply step_make_set; eauto. traceEq. econstructor; eauto. change (final dst' (Etempvar t0 (Csyntax.typeof l)) ++ sl2) with (nil ++ (final dst' (Etempvar t0 (Csyntax.typeof l)) ++ sl2)). apply S. apply tr_val_gen. auto. intros. constructor. rewrite H5; auto. apply PTree.gss. intros. apply PTree.gso. red; intros; subst; elim H5; auto. auto. (* seqand true *) exploit tr_top_leftcontext; eauto. clear H9. intros [dst' [sl1 [sl2 [a' [tmp' [P [Q [R S]]]]]]]]. inv P. inv H2. (* for val *) exploit tr_simple_rvalue; eauto. intros [SL [TY EV]]. subst sl0; simpl Kseqlist. econstructor; split. left. eapply plus_left. constructor. eapply star_trans. apply step_makeif with (b := true) (v1 := v); auto. congruence. apply push_seq. reflexivity. reflexivity. rewrite <- Kseqlist_app. eapply match_exprstates; eauto. apply S. apply tr_paren_val with (a1 := a2); auto. apply tr_expr_monotone with tmp2; eauto. auto. auto. (* for effects *) exploit tr_simple_rvalue; eauto. intros [SL [TY EV]]. subst sl0; simpl Kseqlist. econstructor; split. left. eapply plus_left. constructor. eapply star_trans. apply step_makeif with (b := true) (v1 := v); auto. congruence. apply push_seq. reflexivity. reflexivity. rewrite <- Kseqlist_app. eapply match_exprstates; eauto. apply S. apply tr_paren_effects with (a1 := a2); auto. apply tr_expr_monotone with tmp2; eauto. auto. auto. (* for set *) exploit tr_simple_rvalue; eauto. intros [SL [TY EV]]. subst sl0; simpl Kseqlist. econstructor; split. left. eapply plus_left. constructor. eapply star_trans. apply step_makeif with (b := true) (v1 := v); auto. congruence. apply push_seq. reflexivity. reflexivity. rewrite <- Kseqlist_app. eapply match_exprstates; eauto. apply S. apply tr_paren_set with (a1 := a2) (t := sd_temp sd); auto. apply tr_expr_monotone with tmp2; eauto. auto. auto. (* seqand false *) exploit tr_top_leftcontext; eauto. clear H9. intros [dst' [sl1 [sl2 [a' [tmp' [P [Q [R S]]]]]]]]. inv P. inv H2. (* for val *) exploit tr_simple_rvalue; eauto. intros [SL [TY EV]]. subst sl0; simpl Kseqlist. econstructor; split. left. eapply plus_left. constructor. eapply star_trans. apply step_makeif with (b := false) (v1 := v); auto. congruence. apply star_one. constructor. constructor. reflexivity. reflexivity. eapply match_exprstates; eauto. change sl2 with (nil ++ sl2). apply S. econstructor; eauto. intros. constructor. rewrite H2. apply PTree.gss. auto. intros. apply PTree.gso. congruence. auto. (* for effects *) exploit tr_simple_rvalue; eauto. intros [SL [TY EV]]. subst sl0; simpl Kseqlist. econstructor; split. left. eapply plus_left. constructor. apply step_makeif with (b := false) (v1 := v); auto. congruence. reflexivity. eapply match_exprstates; eauto. change sl2 with (nil ++ sl2). apply S. econstructor; eauto. auto. auto. (* for set *) exploit tr_simple_rvalue; eauto. intros [SL [TY EV]]. subst sl0; simpl Kseqlist. econstructor; split. left. eapply plus_left. constructor. eapply star_trans. apply step_makeif with (b := false) (v1 := v); auto. congruence. apply push_seq. reflexivity. reflexivity. rewrite <- Kseqlist_app. eapply match_exprstates; eauto. apply S. econstructor; eauto. intros. constructor. auto. auto. (* seqor true *) exploit tr_top_leftcontext; eauto. clear H9. intros [dst' [sl1 [sl2 [a' [tmp' [P [Q [R S]]]]]]]]. inv P. inv H2. (* for val *) exploit tr_simple_rvalue; eauto. intros [SL [TY EV]]. subst sl0; simpl Kseqlist. econstructor; split. left. eapply plus_left. constructor. eapply star_trans. apply step_makeif with (b := true) (v1 := v); auto. congruence. apply star_one. constructor. constructor. reflexivity. reflexivity. eapply match_exprstates; eauto. change sl2 with (nil ++ sl2). apply S. econstructor; eauto. intros. constructor. rewrite H2. apply PTree.gss. auto. intros. apply PTree.gso. congruence. auto. (* for effects *) exploit tr_simple_rvalue; eauto. intros [SL [TY EV]]. subst sl0; simpl Kseqlist. econstructor; split. left. eapply plus_left. constructor. apply step_makeif with (b := true) (v1 := v); auto. congruence. reflexivity. eapply match_exprstates; eauto. change sl2 with (nil ++ sl2). apply S. econstructor; eauto. auto. auto. (* for set *) exploit tr_simple_rvalue; eauto. intros [SL [TY EV]]. subst sl0; simpl Kseqlist. econstructor; split. left. eapply plus_left. constructor. eapply star_trans. apply step_makeif with (b := true) (v1 := v); auto. congruence. apply push_seq. reflexivity. reflexivity. rewrite <- Kseqlist_app. eapply match_exprstates; eauto. apply S. econstructor; eauto. intros. constructor. auto. auto. (* seqand false *) exploit tr_top_leftcontext; eauto. clear H9. intros [dst' [sl1 [sl2 [a' [tmp' [P [Q [R S]]]]]]]]. inv P. inv H2. (* for val *) exploit tr_simple_rvalue; eauto. intros [SL [TY EV]]. subst sl0; simpl Kseqlist. econstructor; split. left. eapply plus_left. constructor. eapply star_trans. apply step_makeif with (b := false) (v1 := v); auto. congruence. apply push_seq. reflexivity. reflexivity. rewrite <- Kseqlist_app. eapply match_exprstates; eauto. apply S. apply tr_paren_val with (a1 := a2); auto. apply tr_expr_monotone with tmp2; eauto. auto. auto. (* for effects *) exploit tr_simple_rvalue; eauto. intros [SL [TY EV]]. subst sl0; simpl Kseqlist. econstructor; split. left. eapply plus_left. constructor. eapply star_trans. apply step_makeif with (b := false) (v1 := v); auto. congruence. apply push_seq. reflexivity. reflexivity. rewrite <- Kseqlist_app. eapply match_exprstates; eauto. apply S. apply tr_paren_effects with (a1 := a2); auto. apply tr_expr_monotone with tmp2; eauto. auto. auto. (* for set *) exploit tr_simple_rvalue; eauto. intros [SL [TY EV]]. subst sl0; simpl Kseqlist. econstructor; split. left. eapply plus_left. constructor. eapply star_trans. apply step_makeif with (b := false) (v1 := v); auto. congruence. apply push_seq. reflexivity. reflexivity. rewrite <- Kseqlist_app. eapply match_exprstates; eauto. apply S. apply tr_paren_set with (a1 := a2) (t := sd_temp sd); auto. apply tr_expr_monotone with tmp2; eauto. auto. auto. (* condition *) exploit tr_top_leftcontext; eauto. clear H9. intros [dst' [sl1 [sl2 [a' [tmp' [P [Q [R S]]]]]]]]. inv P. inv H2. (* for value *) exploit tr_simple_rvalue; eauto. intros [SL [TY EV]]. subst sl0; simpl Kseqlist. destruct b. econstructor; split. left. eapply plus_left. constructor. eapply star_trans. apply step_makeif with (b := true) (v1 := v); auto. congruence. apply push_seq. reflexivity. reflexivity. rewrite <- Kseqlist_app. eapply match_exprstates; eauto. apply S. econstructor; eauto. apply tr_expr_monotone with tmp2; eauto. auto. auto. econstructor; split. left. eapply plus_left. constructor. eapply star_trans. apply step_makeif with (b := false) (v1 := v); auto. congruence. apply push_seq. reflexivity. reflexivity. rewrite <- Kseqlist_app. eapply match_exprstates; eauto. apply S. econstructor; eauto. apply tr_expr_monotone with tmp3; eauto. auto. auto. (* for effects *) exploit tr_simple_rvalue; eauto. intros [SL [TY EV]]. subst sl0; simpl Kseqlist. destruct b. econstructor; split. left. eapply plus_left. constructor. eapply star_trans. apply step_makeif with (b := true) (v1 := v); auto. congruence. apply push_seq. reflexivity. traceEq. rewrite <- Kseqlist_app. econstructor. eauto. apply S. econstructor; eauto. apply tr_expr_monotone with tmp2; eauto. econstructor; eauto. auto. auto. econstructor; split. left. eapply plus_left. constructor. eapply star_trans. apply step_makeif with (b := false) (v1 := v); auto. congruence. apply push_seq. reflexivity. traceEq. rewrite <- Kseqlist_app. econstructor. eauto. apply S. econstructor; eauto. apply tr_expr_monotone with tmp3; eauto. econstructor; eauto. auto. auto. (* for set *) exploit tr_simple_rvalue; eauto. intros [SL [TY EV]]. subst sl0; simpl Kseqlist. destruct b. econstructor; split. left. eapply plus_left. constructor. eapply star_trans. apply step_makeif with (b := true) (v1 := v); auto. congruence. apply push_seq. reflexivity. traceEq. rewrite <- Kseqlist_app. econstructor. eauto. apply S. econstructor; eauto. apply tr_expr_monotone with tmp2; eauto. econstructor; eauto. auto. auto. econstructor; split. left. eapply plus_left. constructor. eapply star_trans. apply step_makeif with (b := false) (v1 := v); auto. congruence. apply push_seq. reflexivity. traceEq. rewrite <- Kseqlist_app. econstructor. eauto. apply S. econstructor; eauto. apply tr_expr_monotone with tmp3; eauto. econstructor; eauto. auto. auto. (* assign *) exploit tr_top_leftcontext; eauto. clear H12. intros [dst' [sl1 [sl2 [a' [tmp' [P [Q [R S]]]]]]]]. inv P. inv H4. (* for effects *) exploit tr_simple_rvalue; eauto. intros [SL2 [TY2 EV2]]. exploit tr_simple_lvalue; eauto. intros [SL1 [TY1 EV1]]. subst; simpl Kseqlist. econstructor; split. left. eapply plus_left. constructor. apply star_one. eapply step_make_assign; eauto. rewrite <- TY2; eauto. traceEq. econstructor. auto. change sl2 with (nil ++ sl2). apply S. constructor. auto. auto. auto. (* for value *) exploit tr_simple_rvalue; eauto. intros [SL2 [TY2 EV2]]. exploit tr_simple_lvalue. eauto. eapply tr_expr_invariant with (le' := PTree.set t0 v le). eauto. intros. apply PTree.gso. intuition congruence. intros [SL1 [TY1 EV1]]. subst; simpl Kseqlist. econstructor; split. left. eapply plus_left. constructor. eapply star_left. constructor. eauto. eapply star_left. constructor. apply star_one. eapply step_make_assign; eauto. constructor. apply PTree.gss. reflexivity. reflexivity. traceEq. econstructor. auto. apply S. apply tr_val_gen. auto. intros. econstructor; eauto. constructor. rewrite H4; auto. apply PTree.gss. intros. apply PTree.gso. intuition congruence. auto. auto. (* assignop *) exploit tr_top_leftcontext; eauto. clear H15. intros [dst' [sl1 [sl2 [a' [tmp' [P [Q [R S]]]]]]]]. inv P. inv H6. (* for effects *) exploit tr_simple_lvalue; eauto. intros [SL1 [TY1 EV1]]. exploit step_tr_rvalof; eauto. intros [le' [EXEC [EV3 [TY3 INV]]]]. exploit tr_simple_lvalue. eauto. eapply tr_expr_invariant with (le := le) (le' := le'). eauto. intros. apply INV. NOTIN. intros [? [? EV1']]. exploit tr_simple_rvalue. eauto. eapply tr_expr_invariant with (le := le) (le' := le'). eauto. intros. apply INV. NOTIN. simpl. intros [SL2 [TY2 EV2]]. subst; simpl Kseqlist. econstructor; split. left. eapply star_plus_trans. rewrite app_ass. rewrite Kseqlist_app. eexact EXEC. eapply plus_two. simpl. econstructor. eapply step_make_assign; eauto. econstructor. eexact EV3. eexact EV2. rewrite TY3; rewrite <- TY1; rewrite <- TY2; rewrite comp_env_preserved; auto. reflexivity. traceEq. econstructor. auto. change sl2 with (nil ++ sl2). apply S. constructor. auto. auto. auto. (* for value *) exploit tr_simple_lvalue; eauto. intros [SL1 [TY1 EV1]]. exploit step_tr_rvalof; eauto. intros [le' [EXEC [EV3 [TY3 INV]]]]. exploit tr_simple_lvalue. eauto. eapply tr_expr_invariant with (le := le) (le' := le'). eauto. intros. apply INV. NOTIN. intros [? [? EV1']]. exploit tr_simple_rvalue. eauto. eapply tr_expr_invariant with (le := le) (le' := le'). eauto. intros. apply INV. NOTIN. simpl. intros [SL2 [TY2 EV2]]. exploit tr_simple_lvalue. eauto. eapply tr_expr_invariant with (le := le) (le' := PTree.set t v3 le'). eauto. intros. rewrite PTree.gso. apply INV. NOTIN. intuition congruence. intros [? [? EV1'']]. subst; simpl Kseqlist. econstructor; split. left. rewrite app_ass. rewrite Kseqlist_app. eapply star_plus_trans. eexact EXEC. simpl. eapply plus_four. econstructor. econstructor. econstructor. eexact EV3. eexact EV2. rewrite TY3; rewrite <- TY1; rewrite <- TY2; rewrite comp_env_preserved; eauto. econstructor. eapply step_make_assign; eauto. constructor. apply PTree.gss. reflexivity. traceEq. econstructor. auto. apply S. apply tr_val_gen. auto. intros. econstructor; eauto. constructor. rewrite H10; auto. apply PTree.gss. intros. rewrite PTree.gso. apply INV. red; intros; elim H10; auto. intuition congruence. auto. auto. (* assignop stuck *) exploit tr_top_leftcontext; eauto. clear H12. intros [dst' [sl1 [sl2 [a' [tmp' [P [Q [R S]]]]]]]]. inv P. inv H4. (* for effects *) exploit tr_simple_lvalue; eauto. intros [SL1 [TY1 EV1]]. exploit tr_simple_rvalue; eauto. intros [SL2 [TY2 EV2]]. exploit step_tr_rvalof; eauto. intros [le' [EXEC [EV3 [TY3 INV]]]]. subst; simpl Kseqlist. econstructor; split. right; split. rewrite app_ass. rewrite Kseqlist_app. eexact EXEC. simpl. omega. constructor. (* for value *) exploit tr_simple_lvalue; eauto. intros [SL1 [TY1 EV1]]. exploit tr_simple_rvalue; eauto. intros [SL2 [TY2 EV2]]. exploit step_tr_rvalof; eauto. intros [le' [EXEC [EV3 [TY3 INV]]]]. subst; simpl Kseqlist. econstructor; split. right; split. rewrite app_ass. rewrite Kseqlist_app. eexact EXEC. simpl. omega. constructor. (* postincr *) exploit tr_top_leftcontext; eauto. clear H14. intros [dst' [sl1 [sl2 [a' [tmp' [P [Q [R S]]]]]]]]. inv P. inv H5. (* for effects *) exploit tr_simple_lvalue; eauto. intros [SL1 [TY1 EV1]]. exploit step_tr_rvalof; eauto. intros [le' [EXEC [EV3 [TY3 INV]]]]. exploit tr_simple_lvalue. eauto. eapply tr_expr_invariant with (le := le) (le' := le'). eauto. intros. apply INV. NOTIN. intros [? [? EV1']]. subst; simpl Kseqlist. econstructor; split. left. rewrite app_ass; rewrite Kseqlist_app. eapply star_plus_trans. eexact EXEC. eapply plus_two. simpl. constructor. eapply step_make_assign; eauto. unfold transl_incrdecr. destruct id; simpl in H2. econstructor. eauto. constructor. rewrite TY3; rewrite <- TY1; rewrite comp_env_preserved. simpl; eauto. econstructor. eauto. constructor. rewrite TY3; rewrite <- TY1; rewrite comp_env_preserved. simpl; eauto. destruct id; auto. reflexivity. traceEq. econstructor. auto. change sl2 with (nil ++ sl2). apply S. constructor. auto. auto. auto. (* for value *) exploit tr_simple_lvalue; eauto. intros [SL1 [TY1 EV1]]. exploit tr_simple_lvalue. eauto. eapply tr_expr_invariant with (le' := PTree.set t v1 le). eauto. intros. apply PTree.gso. intuition congruence. intros [SL2 [TY2 EV2]]. subst; simpl Kseqlist. econstructor; split. left. eapply plus_four. constructor. eapply step_make_set; eauto. constructor. eapply step_make_assign; eauto. unfold transl_incrdecr. destruct id; simpl in H2. econstructor. constructor. apply PTree.gss. constructor. rewrite comp_env_preserved; simpl; eauto. econstructor. constructor. apply PTree.gss. constructor. rewrite comp_env_preserved; simpl; eauto. destruct id; auto. traceEq. econstructor. auto. apply S. apply tr_val_gen. auto. intros. econstructor; eauto. rewrite H5; auto. apply PTree.gss. intros. apply PTree.gso. intuition congruence. auto. auto. (* postincr stuck *) exploit tr_top_leftcontext; eauto. clear H11. intros [dst' [sl1 [sl2 [a' [tmp' [P [Q [R S]]]]]]]]. inv P. inv H3. (* for effects *) exploit tr_simple_lvalue; eauto. intros [SL1 [TY1 EV1]]. exploit step_tr_rvalof; eauto. intros [le' [EXEC [EV3 [TY3 INV]]]]. subst. simpl Kseqlist. econstructor; split. right; split. rewrite app_ass; rewrite Kseqlist_app. eexact EXEC. simpl; omega. constructor. (* for value *) exploit tr_simple_lvalue; eauto. intros [SL1 [TY1 EV1]]. subst. simpl Kseqlist. econstructor; split. left. eapply plus_two. constructor. eapply step_make_set; eauto. traceEq. constructor. (* comma *) exploit tr_top_leftcontext; eauto. clear H9. intros [dst' [sl1 [sl2 [a' [tmp' [P [Q [R S]]]]]]]]. inv P. inv H1. exploit tr_simple_rvalue; eauto. simpl; intro SL1. subst sl0; simpl Kseqlist. econstructor; split. right; split. apply star_refl. simpl. apply plus_lt_compat_r. apply (leftcontext_size _ _ _ H). simpl. omega. econstructor; eauto. apply S. eapply tr_expr_monotone; eauto. auto. auto. (* paren *) exploit tr_top_leftcontext; eauto. clear H9. intros [dst' [sl1 [sl2 [a' [tmp' [P [Q [R S]]]]]]]]. inv P. inv H2. (* for value *) exploit tr_simple_rvalue; eauto. intros [b [SL1 [TY1 EV1]]]. subst sl1; simpl Kseqlist. econstructor; split. left. eapply plus_left. constructor. apply star_one. econstructor. econstructor; eauto. rewrite <- TY1; eauto. traceEq. econstructor; eauto. change sl2 with (final For_val (Etempvar t (Csyntax.typeof r)) ++ sl2). apply S. constructor. auto. intros. constructor. rewrite H2; auto. apply PTree.gss. intros. apply PTree.gso. intuition congruence. auto. (* for effects *) econstructor; split. right; split. apply star_refl. simpl. apply plus_lt_compat_r. apply (leftcontext_size _ _ _ H). simpl. omega. econstructor; eauto. exploit tr_simple_rvalue; eauto. simpl. intros A. subst sl1. apply S. constructor; auto. auto. auto. (* for set *) exploit tr_simple_rvalue; eauto. simpl. intros [b [SL1 [TY1 EV1]]]. subst sl1. simpl Kseqlist. econstructor; split. left. eapply plus_left. constructor. apply star_one. econstructor. econstructor; eauto. rewrite <- TY1; eauto. traceEq. econstructor; eauto. apply S. constructor; auto. intros. constructor. rewrite H2. apply PTree.gss. auto. intros. apply PTree.gso. congruence. auto. (* call *) exploit tr_top_leftcontext; eauto. clear H12. intros [dst' [sl1 [sl2 [a' [tmp' [P [Q [R S]]]]]]]]. inv P. inv H5. (* for effects *) exploit tr_simple_rvalue; eauto. intros [SL1 [TY1 EV1]]. exploit tr_simple_exprlist; eauto. intros [SL2 EV2]. subst. simpl Kseqlist. exploit functions_translated; eauto. intros [tfd [J K]]. econstructor; split. left. eapply plus_left. constructor. apply star_one. econstructor; eauto. rewrite <- TY1; eauto. exploit type_of_fundef_preserved; eauto. congruence. traceEq. constructor; auto. econstructor; eauto. intros. change sl2 with (nil ++ sl2). apply S. constructor. auto. auto. (* for value *) exploit tr_simple_rvalue; eauto. intros [SL1 [TY1 EV1]]. exploit tr_simple_exprlist; eauto. intros [SL2 EV2]. subst. simpl Kseqlist. exploit functions_translated; eauto. intros [tfd [J K]]. econstructor; split. left. eapply plus_left. constructor. apply star_one. econstructor; eauto. rewrite <- TY1; eauto. exploit type_of_fundef_preserved; eauto. congruence. traceEq. constructor; auto. econstructor; eauto. intros. apply S. destruct dst'; constructor. auto. intros. constructor. rewrite H5; auto. apply PTree.gss. auto. intros. constructor. rewrite H5; auto. apply PTree.gss. intros. apply PTree.gso. intuition congruence. auto. (* builtin *) exploit tr_top_leftcontext; eauto. clear H9. intros [dst' [sl1 [sl2 [a' [tmp' [P [Q [R S]]]]]]]]. inv P. inv H2. (* for effects *) exploit tr_simple_exprlist; eauto. intros [SL EV]. subst. simpl Kseqlist. econstructor; split. left. eapply plus_left. constructor. apply star_one. econstructor; eauto. eapply external_call_symbols_preserved; eauto. exact symbols_preserved. exact public_preserved. exact varinfo_preserved. traceEq. econstructor; eauto. change sl2 with (nil ++ sl2). apply S. constructor. simpl; auto. auto. (* for value *) exploit tr_simple_exprlist; eauto. intros [SL EV]. subst. simpl Kseqlist. econstructor; split. left. eapply plus_left. constructor. apply star_one. econstructor; eauto. eapply external_call_symbols_preserved; eauto. exact symbols_preserved. exact public_preserved. exact varinfo_preserved. traceEq. econstructor; eauto. change sl2 with (nil ++ sl2). apply S. apply tr_val_gen. auto. intros. constructor. rewrite H2; auto. simpl. apply PTree.gss. intros; simpl. apply PTree.gso. intuition congruence. auto. Qed. (** Forward simulation for statements. *) Lemma tr_top_val_for_val_inv: forall e le m v ty sl a tmps, tr_top tge e le m For_val (Csyntax.Eval v ty) sl a tmps -> sl = nil /\ typeof a = ty /\ eval_expr tge e le m a v. Proof. intros. inv H. auto. inv H0. auto. Qed. Lemma alloc_variables_preserved: forall e m params e' m', Csem.alloc_variables ge e m params e' m' -> alloc_variables tge e m params e' m'. Proof. induction 1; econstructor; eauto. rewrite comp_env_preserved; auto. Qed. Lemma bind_parameters_preserved: forall e m params args m', Csem.bind_parameters ge e m params args m' -> bind_parameters tge e m params args m'. Proof. induction 1; econstructor; eauto. inv H0. - eapply assign_loc_value; eauto. - inv H4. eapply assign_loc_value; eauto. - rewrite <- comp_env_preserved in *. eapply assign_loc_copy; eauto. Qed. Lemma blocks_of_env_preserved: forall e, blocks_of_env tge e = Csem.blocks_of_env ge e. Proof. intros; unfold blocks_of_env, Csem.blocks_of_env. unfold block_of_binding, Csem.block_of_binding. rewrite comp_env_preserved. auto. Qed. Lemma sstep_simulation: forall S1 t S2, Csem.sstep ge S1 t S2 -> forall S1' (MS: match_states S1 S1'), exists S2', (plus step1 tge S1' t S2' \/ (star step1 tge S1' t S2' /\ measure S2 < measure S1)%nat) /\ match_states S2 S2'. Proof. induction 1; intros; inv MS. (* do 1 *) inv H6. inv H0. econstructor; split. right; split. apply push_seq. simpl. omega. econstructor; eauto. constructor. auto. (* do 2 *) inv H7. inv H6. inv H. econstructor; split. right; split. apply star_refl. simpl. omega. econstructor; eauto. constructor. (* seq *) inv H6. econstructor; split. left. apply plus_one. constructor. econstructor; eauto. constructor; auto. (* skip seq *) inv H6; inv H7. econstructor; split. left. apply plus_one; constructor. econstructor; eauto. (* continue seq *) inv H6; inv H7. econstructor; split. left. apply plus_one; constructor. econstructor; eauto. constructor. (* break seq *) inv H6; inv H7. econstructor; split. left. apply plus_one; constructor. econstructor; eauto. constructor. (* ifthenelse *) inv H6. inv H2. econstructor; split. left. eapply plus_left. constructor. apply push_seq. traceEq. econstructor; eauto. econstructor; eauto. (* ifthenelse *) inv H8. exploit tr_top_val_for_val_inv; eauto. intros [A [B C]]. subst. econstructor; split. left. eapply plus_two. constructor. apply step_ifthenelse with (v1 := v) (b := b); auto. traceEq. destruct b; econstructor; eauto. (* while *) inv H6. inv H1. econstructor; split. left. eapply plus_left. constructor. eapply star_left. constructor. apply push_seq. reflexivity. traceEq. rewrite Kseqlist_app. econstructor; eauto. simpl. econstructor; eauto. econstructor; eauto. (* while false *) inv H8. exploit tr_top_val_for_val_inv; eauto. intros [A [B C]]. subst. econstructor; split. left. simpl. eapply plus_left. constructor. eapply star_trans. apply step_makeif with (v1 := v) (b := false); auto. eapply star_two. constructor. apply step_break_loop1. reflexivity. reflexivity. traceEq. constructor; auto. constructor. (* while true *) inv H8. exploit tr_top_val_for_val_inv; eauto. intros [A [B C]]. subst. econstructor; split. left. simpl. eapply plus_left. constructor. eapply star_right. apply step_makeif with (v1 := v) (b := true); auto. constructor. reflexivity. traceEq. constructor; auto. constructor; auto. (* skip-or-continue while *) assert (ts = Sskip \/ ts = Scontinue). destruct H; subst s0; inv H7; auto. inv H8. econstructor; split. left. eapply plus_two. apply step_skip_or_continue_loop1; auto. apply step_skip_loop2. traceEq. constructor; auto. constructor; auto. (* break while *) inv H6. inv H7. econstructor; split. left. apply plus_one. apply step_break_loop1. constructor; auto. constructor. (* dowhile *) inv H6. econstructor; split. left. apply plus_one. apply step_loop. constructor; auto. constructor; auto. (* skip_or_continue dowhile *) assert (ts = Sskip \/ ts = Scontinue). destruct H; subst s0; inv H7; auto. inv H8. inv H4. econstructor; split. left. eapply plus_left. apply step_skip_or_continue_loop1. auto. apply push_seq. traceEq. rewrite Kseqlist_app. econstructor; eauto. simpl. econstructor; auto. econstructor; eauto. (* dowhile false *) inv H8. exploit tr_top_val_for_val_inv; eauto. intros [A [B C]]. subst. econstructor; split. left. simpl. eapply plus_left. constructor. eapply star_right. apply step_makeif with (v1 := v) (b := false); auto. constructor. reflexivity. traceEq. constructor; auto. constructor. (* dowhile true *) inv H8. exploit tr_top_val_for_val_inv; eauto. intros [A [B C]]. subst. econstructor; split. left. simpl. eapply plus_left. constructor. eapply star_right. apply step_makeif with (v1 := v) (b := true); auto. constructor. reflexivity. traceEq. constructor; auto. constructor; auto. (* break dowhile *) inv H6. inv H7. econstructor; split. left. apply plus_one. apply step_break_loop1. constructor; auto. constructor. (* for start *) inv H7. congruence. econstructor; split. left; apply plus_one. constructor. econstructor; eauto. constructor; auto. econstructor; eauto. (* for *) inv H6; try congruence. inv H2. econstructor; split. left. eapply plus_left. apply step_loop. eapply star_left. constructor. apply push_seq. reflexivity. traceEq. rewrite Kseqlist_app. econstructor; eauto. simpl. constructor; auto. econstructor; eauto. (* for false *) inv H8. exploit tr_top_val_for_val_inv; eauto. intros [A [B C]]. subst. econstructor; split. left. simpl. eapply plus_left. constructor. eapply star_trans. apply step_makeif with (v1 := v) (b := false); auto. eapply star_two. constructor. apply step_break_loop1. reflexivity. reflexivity. traceEq. constructor; auto. constructor. (* for true *) inv H8. exploit tr_top_val_for_val_inv; eauto. intros [A [B C]]. subst. econstructor; split. left. simpl. eapply plus_left. constructor. eapply star_right. apply step_makeif with (v1 := v) (b := true); auto. constructor. reflexivity. traceEq. constructor; auto. constructor; auto. (* skip_or_continue for3 *) assert (ts = Sskip \/ ts = Scontinue). destruct H; subst x; inv H7; auto. inv H8. econstructor; split. left. apply plus_one. apply step_skip_or_continue_loop1. auto. econstructor; eauto. econstructor; auto. (* break for3 *) inv H6. inv H7. econstructor; split. left. apply plus_one. apply step_break_loop1. econstructor; eauto. constructor. (* skip for4 *) inv H6. inv H7. econstructor; split. left. apply plus_one. constructor. econstructor; eauto. constructor; auto. (* return none *) inv H7. econstructor; split. left. apply plus_one. econstructor; eauto. rewrite blocks_of_env_preserved; eauto. constructor. apply match_cont_call; auto. (* return some 1 *) inv H6. inv H0. econstructor; split. left; eapply plus_left. constructor. apply push_seq. traceEq. econstructor; eauto. constructor. auto. (* return some 2 *) inv H9. exploit tr_top_val_for_val_inv; eauto. intros [A [B C]]. subst. econstructor; split. left. eapply plus_two. constructor. econstructor. eauto. erewrite function_return_preserved; eauto. rewrite blocks_of_env_preserved; eauto. eauto. traceEq. constructor. apply match_cont_call; auto. (* skip return *) inv H8. assert (is_call_cont tk). inv H9; simpl in *; auto. econstructor; split. left. apply plus_one. apply step_skip_call; eauto. rewrite blocks_of_env_preserved; eauto. constructor. auto. (* switch *) inv H6. inv H1. econstructor; split. left; eapply plus_left. constructor. apply push_seq. traceEq. econstructor; eauto. constructor; auto. (* expr switch *) inv H8. exploit tr_top_val_for_val_inv; eauto. intros [A [B C]]. subst. econstructor; split. left; eapply plus_two. constructor. econstructor; eauto. traceEq. econstructor; eauto. apply tr_seq_of_labeled_statement. apply tr_select_switch. auto. constructor; auto. (* skip-or-break switch *) assert (ts = Sskip \/ ts = Sbreak). destruct H; subst x; inv H7; auto. inv H8. econstructor; split. left; apply plus_one. apply step_skip_break_switch. auto. constructor; auto. constructor. (* continue switch *) inv H6. inv H7. econstructor; split. left; apply plus_one. apply step_continue_switch. constructor; auto. constructor. (* label *) inv H6. econstructor; split. left; apply plus_one. constructor. constructor; auto. (* goto *) inv H7. inversion H6; subst. exploit tr_find_label. eauto. apply match_cont_call. eauto. instantiate (1 := lbl). rewrite H. intros [ts' [tk' [P [Q R]]]]. econstructor; split. left. apply plus_one. econstructor; eauto. econstructor; eauto. (* internal function *) inv H7. inversion H3; subst. econstructor; split. left; apply plus_one. eapply step_internal_function. econstructor. rewrite H6; rewrite H7; auto. rewrite H6; rewrite H7. eapply alloc_variables_preserved; eauto. rewrite H6. eapply bind_parameters_preserved; eauto. eauto. constructor; auto. (* external function *) inv H5. econstructor; split. left; apply plus_one. econstructor; eauto. eapply external_call_symbols_preserved; eauto. exact symbols_preserved. exact public_preserved. exact varinfo_preserved. constructor; auto. (* return *) inv H3. econstructor; split. left; apply plus_one. constructor. econstructor; eauto. Qed. (** Semantic preservation *) Theorem simulation: forall S1 t S2, Cstrategy.step ge S1 t S2 -> forall S1' (MS: match_states S1 S1'), exists S2', (plus step1 tge S1' t S2' \/ (star step1 tge S1' t S2' /\ measure S2 < measure S1)%nat) /\ match_states S2 S2'. Proof. intros S1 t S2 STEP. destruct STEP. apply estep_simulation; auto. apply sstep_simulation; auto. Qed. Lemma transl_initial_states: forall S, Csem.initial_state prog S -> exists S', Clight.initial_state tprog S' /\ match_states S S'. Proof. intros. inv H. generalize TRANSL; intros TR; monadInv TR. rewrite H4. exploit transl_program_spec; eauto. intros MP. exploit function_ptr_translated; eauto. intros [tf [FIND TR]]. econstructor; split. econstructor. exploit Genv.init_mem_match; eauto. change (Genv.globalenv tprog) with (genv_genv tge). rewrite symbols_preserved. rewrite <- H4; simpl; eauto. eexact FIND. rewrite <- H3. apply type_of_fundef_preserved. auto. constructor. auto. constructor. Qed. Lemma transl_final_states: forall S S' r, match_states S S' -> Csem.final_state S r -> Clight.final_state S' r. Proof. intros. inv H0. inv H. inv H4. constructor. Qed. Theorem transl_program_correct: forward_simulation (Cstrategy.semantics prog) (Clight.semantics1 tprog). Proof. eapply forward_simulation_star_wf with (order := ltof _ measure). eexact public_preserved. eexact transl_initial_states. eexact transl_final_states. apply well_founded_ltof. exact simulation. Qed. End PRESERVATION.
import csv import numpy as np import plotly.figure_factory as ff import streamlit as st @st.cache def read_data(delimiter=","): # Read data from csv file data = [] with open("data.csv") as csvfile: reader = csv.DictReader(csvfile, delimiter=delimiter) data = list(reader) return data def create_random_array(): return list(np.random.rand(25)) # Add some description to page st.set_page_config(layout="wide") st.title('Demo to load data from CSV and visualize using streamlit') def create_plotly_graph(_data, description): fig = ff.create_distplot( [_data], [description], bin_size=[5] ) return fig def create_plot(data, key, description): # Create graph with plotly, seaborn, matplotlob... _data = [float(data[key]) for data in read_data()] fig = create_plotly_graph(_data, description) # Plot! st.plotly_chart(fig, use_container_width=True) # Create a graph with st.form("create_graph"): st.write("Create graph") # Every form must have a submit button. submitted = st.form_submit_button("Submit") if submitted: create_plot(read_data(), 'age', 'Age') # Using some numpy math stuff with st.form("get_random_data"): st.write("Get random data") # Every form must have a submit button. submitted = st.form_submit_button("Submit") if submitted: fig = create_plotly_graph(create_random_array(), 'Random numbers') st.plotly_chart(fig, use_container_width=True) # Create a nice looking table from the raw data with st.form("get_data"): st.write("Get data table") # Every form must have a submit button. submitted = st.form_submit_button("Submit") if submitted: st.table(read_data())
[STATEMENT] lemma stack_xlift_Cons_tuple [simp]: "stack_xlift n ((from, to, C, handler, depth) # xt) = (from, to, C, handler, depth + n) # stack_xlift n xt" [PROOF STATE] proof (prove) goal (1 subgoal): 1. stack_xlift n ((from, to, C, handler, depth) # xt) = (from, to, C, handler, depth + n) # stack_xlift n xt [PROOF STEP] by(simp add: stack_xlift_def)
(* Title: HOL/Auth/n_flash_lemma_on_inv__17.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_flash Protocol Case Study*} theory n_flash_lemma_on_inv__17 imports n_flash_base begin section{*All lemmas on causal relation between inv__17 and some rule r*} lemma n_PI_Remote_GetVsinv__17: assumes a1: "(\<exists> src. src\<le>N\<and>r=n_PI_Remote_Get src)" and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__17 p__Inv4)" shows "invHoldForRule s f r (invariants N)" (is "?P1 s \<or> ?P2 s \<or> ?P3 s") proof - from a1 obtain src where a1:"src\<le>N\<and>r=n_PI_Remote_Get src" apply fastforce done from a2 obtain p__Inv4 where a2:"p__Inv4\<le>N\<and>f=inv__17 p__Inv4" apply fastforce done have "(src=p__Inv4)\<or>(src~=p__Inv4)" apply (cut_tac a1 a2, auto) done moreover { assume b1: "(src=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: "(src~=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_PI_Remote_GetXVsinv__17: assumes a1: "(\<exists> src. src\<le>N\<and>r=n_PI_Remote_GetX src)" and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__17 p__Inv4)" shows "invHoldForRule s f r (invariants N)" (is "?P1 s \<or> ?P2 s \<or> ?P3 s") proof - from a1 obtain src where a1:"src\<le>N\<and>r=n_PI_Remote_GetX src" apply fastforce done from a2 obtain p__Inv4 where a2:"p__Inv4\<le>N\<and>f=inv__17 p__Inv4" apply fastforce done have "(src=p__Inv4)\<or>(src~=p__Inv4)" apply (cut_tac a1 a2, auto) done moreover { assume b1: "(src=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: "(src~=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_NI_NakVsinv__17: assumes a1: "(\<exists> dst. dst\<le>N\<and>r=n_NI_Nak dst)" and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__17 p__Inv4)" shows "invHoldForRule s f r (invariants N)" (is "?P1 s \<or> ?P2 s \<or> ?P3 s") proof - from a1 obtain dst where a1:"dst\<le>N\<and>r=n_NI_Nak dst" apply fastforce done from a2 obtain p__Inv4 where a2:"p__Inv4\<le>N\<and>f=inv__17 p__Inv4" apply fastforce done have "(dst=p__Inv4)\<or>(dst~=p__Inv4)" apply (cut_tac a1 a2, auto) done moreover { assume b1: "(dst=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: "(dst~=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_NI_Local_Get_Nak__part__0Vsinv__17: assumes a1: "(\<exists> src. src\<le>N\<and>r=n_NI_Local_Get_Nak__part__0 src)" and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__17 p__Inv4)" shows "invHoldForRule s f r (invariants N)" (is "?P1 s \<or> ?P2 s \<or> ?P3 s") proof - from a1 obtain src where a1:"src\<le>N\<and>r=n_NI_Local_Get_Nak__part__0 src" apply fastforce done from a2 obtain p__Inv4 where a2:"p__Inv4\<le>N\<and>f=inv__17 p__Inv4" apply fastforce done have "(src=p__Inv4)\<or>(src~=p__Inv4)" apply (cut_tac a1 a2, auto) done moreover { assume b1: "(src=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: "(src~=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_NI_Local_Get_Nak__part__1Vsinv__17: assumes a1: "(\<exists> src. src\<le>N\<and>r=n_NI_Local_Get_Nak__part__1 src)" and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__17 p__Inv4)" shows "invHoldForRule s f r (invariants N)" (is "?P1 s \<or> ?P2 s \<or> ?P3 s") proof - from a1 obtain src where a1:"src\<le>N\<and>r=n_NI_Local_Get_Nak__part__1 src" apply fastforce done from a2 obtain p__Inv4 where a2:"p__Inv4\<le>N\<and>f=inv__17 p__Inv4" apply fastforce done have "(src=p__Inv4)\<or>(src~=p__Inv4)" apply (cut_tac a1 a2, auto) done moreover { assume b1: "(src=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: "(src~=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_NI_Local_Get_Nak__part__2Vsinv__17: assumes a1: "(\<exists> src. src\<le>N\<and>r=n_NI_Local_Get_Nak__part__2 src)" and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__17 p__Inv4)" shows "invHoldForRule s f r (invariants N)" (is "?P1 s \<or> ?P2 s \<or> ?P3 s") proof - from a1 obtain src where a1:"src\<le>N\<and>r=n_NI_Local_Get_Nak__part__2 src" apply fastforce done from a2 obtain p__Inv4 where a2:"p__Inv4\<le>N\<and>f=inv__17 p__Inv4" apply fastforce done have "(src=p__Inv4)\<or>(src~=p__Inv4)" apply (cut_tac a1 a2, auto) done moreover { assume b1: "(src=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: "(src~=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_NI_Local_Get_Get__part__0Vsinv__17: assumes a1: "(\<exists> src. src\<le>N\<and>r=n_NI_Local_Get_Get__part__0 src)" and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__17 p__Inv4)" shows "invHoldForRule s f r (invariants N)" (is "?P1 s \<or> ?P2 s \<or> ?P3 s") proof - from a1 obtain src where a1:"src\<le>N\<and>r=n_NI_Local_Get_Get__part__0 src" apply fastforce done from a2 obtain p__Inv4 where a2:"p__Inv4\<le>N\<and>f=inv__17 p__Inv4" apply fastforce done have "(src=p__Inv4)\<or>(src~=p__Inv4)" apply (cut_tac a1 a2, auto) done moreover { assume b1: "(src=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: "(src~=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_NI_Local_Get_Get__part__1Vsinv__17: assumes a1: "(\<exists> src. src\<le>N\<and>r=n_NI_Local_Get_Get__part__1 src)" and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__17 p__Inv4)" shows "invHoldForRule s f r (invariants N)" (is "?P1 s \<or> ?P2 s \<or> ?P3 s") proof - from a1 obtain src where a1:"src\<le>N\<and>r=n_NI_Local_Get_Get__part__1 src" apply fastforce done from a2 obtain p__Inv4 where a2:"p__Inv4\<le>N\<and>f=inv__17 p__Inv4" apply fastforce done have "(src=p__Inv4)\<or>(src~=p__Inv4)" apply (cut_tac a1 a2, auto) done moreover { assume b1: "(src=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: "(src~=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_NI_Local_Get_Put_HeadVsinv__17: assumes a1: "(\<exists> src. src\<le>N\<and>r=n_NI_Local_Get_Put_Head N src)" and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__17 p__Inv4)" shows "invHoldForRule s f r (invariants N)" (is "?P1 s \<or> ?P2 s \<or> ?P3 s") proof - from a1 obtain src where a1:"src\<le>N\<and>r=n_NI_Local_Get_Put_Head N src" apply fastforce done from a2 obtain p__Inv4 where a2:"p__Inv4\<le>N\<and>f=inv__17 p__Inv4" apply fastforce done have "(src=p__Inv4)\<or>(src~=p__Inv4)" apply (cut_tac a1 a2, auto) done moreover { assume b1: "(src=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: "(src~=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_NI_Local_Get_PutVsinv__17: assumes a1: "(\<exists> src. src\<le>N\<and>r=n_NI_Local_Get_Put src)" and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__17 p__Inv4)" shows "invHoldForRule s f r (invariants N)" (is "?P1 s \<or> ?P2 s \<or> ?P3 s") proof - from a1 obtain src where a1:"src\<le>N\<and>r=n_NI_Local_Get_Put src" apply fastforce done from a2 obtain p__Inv4 where a2:"p__Inv4\<le>N\<and>f=inv__17 p__Inv4" apply fastforce done have "(src=p__Inv4)\<or>(src~=p__Inv4)" apply (cut_tac a1 a2, auto) done moreover { assume b1: "(src=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: "(src~=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_NI_Local_Get_Put_DirtyVsinv__17: assumes a1: "(\<exists> src. src\<le>N\<and>r=n_NI_Local_Get_Put_Dirty src)" and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__17 p__Inv4)" shows "invHoldForRule s f r (invariants N)" (is "?P1 s \<or> ?P2 s \<or> ?P3 s") proof - from a1 obtain src where a1:"src\<le>N\<and>r=n_NI_Local_Get_Put_Dirty src" apply fastforce done from a2 obtain p__Inv4 where a2:"p__Inv4\<le>N\<and>f=inv__17 p__Inv4" apply fastforce done have "(src=p__Inv4)\<or>(src~=p__Inv4)" apply (cut_tac a1 a2, auto) done moreover { assume b1: "(src=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: "(src~=p__Inv4)" have "?P3 s" apply (cut_tac a1 a2 b1, simp, rule_tac x="(neg (andForm (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''Local'')) (Const true)) (eqn (IVar (Field (Para (Field (Ident ''Sta'') ''UniMsg'') p__Inv4) ''Cmd'')) (Const UNI_PutX))))" 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_NI_Remote_Get_NakVsinv__17: assumes a1: "(\<exists> src dst. src\<le>N\<and>dst\<le>N\<and>src~=dst\<and>r=n_NI_Remote_Get_Nak src dst)" and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__17 p__Inv4)" shows "invHoldForRule s f r (invariants N)" (is "?P1 s \<or> ?P2 s \<or> ?P3 s") proof - from a1 obtain src dst where a1:"src\<le>N\<and>dst\<le>N\<and>src~=dst\<and>r=n_NI_Remote_Get_Nak src dst" apply fastforce done from a2 obtain p__Inv4 where a2:"p__Inv4\<le>N\<and>f=inv__17 p__Inv4" apply fastforce done have "(src=p__Inv4\<and>dst~=p__Inv4)\<or>(src~=p__Inv4\<and>dst=p__Inv4)\<or>(src~=p__Inv4\<and>dst~=p__Inv4)" apply (cut_tac a1 a2, auto) done moreover { assume b1: "(src=p__Inv4\<and>dst~=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: "(src~=p__Inv4\<and>dst=p__Inv4)" have "?P2 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume b1: "(src~=p__Inv4\<and>dst~=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_NI_Remote_Get_PutVsinv__17: assumes a1: "(\<exists> src dst. src\<le>N\<and>dst\<le>N\<and>src~=dst\<and>r=n_NI_Remote_Get_Put src dst)" and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__17 p__Inv4)" shows "invHoldForRule s f r (invariants N)" (is "?P1 s \<or> ?P2 s \<or> ?P3 s") proof - from a1 obtain src dst where a1:"src\<le>N\<and>dst\<le>N\<and>src~=dst\<and>r=n_NI_Remote_Get_Put src dst" apply fastforce done from a2 obtain p__Inv4 where a2:"p__Inv4\<le>N\<and>f=inv__17 p__Inv4" apply fastforce done have "(src=p__Inv4\<and>dst~=p__Inv4)\<or>(src~=p__Inv4\<and>dst=p__Inv4)\<or>(src~=p__Inv4\<and>dst~=p__Inv4)" apply (cut_tac a1 a2, auto) done moreover { assume b1: "(src=p__Inv4\<and>dst~=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: "(src~=p__Inv4\<and>dst=p__Inv4)" have "?P2 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume b1: "(src~=p__Inv4\<and>dst~=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_NI_Local_GetX_Nak__part__0Vsinv__17: assumes a1: "(\<exists> src. src\<le>N\<and>r=n_NI_Local_GetX_Nak__part__0 src)" and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__17 p__Inv4)" shows "invHoldForRule s f r (invariants N)" (is "?P1 s \<or> ?P2 s \<or> ?P3 s") proof - from a1 obtain src where a1:"src\<le>N\<and>r=n_NI_Local_GetX_Nak__part__0 src" apply fastforce done from a2 obtain p__Inv4 where a2:"p__Inv4\<le>N\<and>f=inv__17 p__Inv4" apply fastforce done have "(src=p__Inv4)\<or>(src~=p__Inv4)" apply (cut_tac a1 a2, auto) done moreover { assume b1: "(src=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: "(src~=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_NI_Local_GetX_Nak__part__1Vsinv__17: assumes a1: "(\<exists> src. src\<le>N\<and>r=n_NI_Local_GetX_Nak__part__1 src)" and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__17 p__Inv4)" shows "invHoldForRule s f r (invariants N)" (is "?P1 s \<or> ?P2 s \<or> ?P3 s") proof - from a1 obtain src where a1:"src\<le>N\<and>r=n_NI_Local_GetX_Nak__part__1 src" apply fastforce done from a2 obtain p__Inv4 where a2:"p__Inv4\<le>N\<and>f=inv__17 p__Inv4" apply fastforce done have "(src=p__Inv4)\<or>(src~=p__Inv4)" apply (cut_tac a1 a2, auto) done moreover { assume b1: "(src=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: "(src~=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_NI_Local_GetX_Nak__part__2Vsinv__17: assumes a1: "(\<exists> src. src\<le>N\<and>r=n_NI_Local_GetX_Nak__part__2 src)" and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__17 p__Inv4)" shows "invHoldForRule s f r (invariants N)" (is "?P1 s \<or> ?P2 s \<or> ?P3 s") proof - from a1 obtain src where a1:"src\<le>N\<and>r=n_NI_Local_GetX_Nak__part__2 src" apply fastforce done from a2 obtain p__Inv4 where a2:"p__Inv4\<le>N\<and>f=inv__17 p__Inv4" apply fastforce done have "(src=p__Inv4)\<or>(src~=p__Inv4)" apply (cut_tac a1 a2, auto) done moreover { assume b1: "(src=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: "(src~=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_NI_Local_GetX_GetX__part__0Vsinv__17: assumes a1: "(\<exists> src. src\<le>N\<and>r=n_NI_Local_GetX_GetX__part__0 src)" and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__17 p__Inv4)" shows "invHoldForRule s f r (invariants N)" (is "?P1 s \<or> ?P2 s \<or> ?P3 s") proof - from a1 obtain src where a1:"src\<le>N\<and>r=n_NI_Local_GetX_GetX__part__0 src" apply fastforce done from a2 obtain p__Inv4 where a2:"p__Inv4\<le>N\<and>f=inv__17 p__Inv4" apply fastforce done have "(src=p__Inv4)\<or>(src~=p__Inv4)" apply (cut_tac a1 a2, auto) done moreover { assume b1: "(src=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: "(src~=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_NI_Local_GetX_GetX__part__1Vsinv__17: assumes a1: "(\<exists> src. src\<le>N\<and>r=n_NI_Local_GetX_GetX__part__1 src)" and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__17 p__Inv4)" shows "invHoldForRule s f r (invariants N)" (is "?P1 s \<or> ?P2 s \<or> ?P3 s") proof - from a1 obtain src where a1:"src\<le>N\<and>r=n_NI_Local_GetX_GetX__part__1 src" apply fastforce done from a2 obtain p__Inv4 where a2:"p__Inv4\<le>N\<and>f=inv__17 p__Inv4" apply fastforce done have "(src=p__Inv4)\<or>(src~=p__Inv4)" apply (cut_tac a1 a2, auto) done moreover { assume b1: "(src=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: "(src~=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_NI_Local_GetX_PutX_1Vsinv__17: assumes a1: "(\<exists> src. src\<le>N\<and>r=n_NI_Local_GetX_PutX_1 N src)" and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__17 p__Inv4)" shows "invHoldForRule s f r (invariants N)" (is "?P1 s \<or> ?P2 s \<or> ?P3 s") proof - from a1 obtain src where a1:"src\<le>N\<and>r=n_NI_Local_GetX_PutX_1 N src" apply fastforce done from a2 obtain p__Inv4 where a2:"p__Inv4\<le>N\<and>f=inv__17 p__Inv4" apply fastforce done have "(src=p__Inv4)\<or>(src~=p__Inv4)" apply (cut_tac a1 a2, auto) done moreover { assume b1: "(src=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: "(src~=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_NI_Local_GetX_PutX_2Vsinv__17: assumes a1: "(\<exists> src. src\<le>N\<and>r=n_NI_Local_GetX_PutX_2 N src)" and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__17 p__Inv4)" shows "invHoldForRule s f r (invariants N)" (is "?P1 s \<or> ?P2 s \<or> ?P3 s") proof - from a1 obtain src where a1:"src\<le>N\<and>r=n_NI_Local_GetX_PutX_2 N src" apply fastforce done from a2 obtain p__Inv4 where a2:"p__Inv4\<le>N\<and>f=inv__17 p__Inv4" apply fastforce done have "(src=p__Inv4)\<or>(src~=p__Inv4)" apply (cut_tac a1 a2, auto) done moreover { assume b1: "(src=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: "(src~=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_NI_Local_GetX_PutX_3Vsinv__17: assumes a1: "(\<exists> src. src\<le>N\<and>r=n_NI_Local_GetX_PutX_3 N src)" and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__17 p__Inv4)" shows "invHoldForRule s f r (invariants N)" (is "?P1 s \<or> ?P2 s \<or> ?P3 s") proof - from a1 obtain src where a1:"src\<le>N\<and>r=n_NI_Local_GetX_PutX_3 N src" apply fastforce done from a2 obtain p__Inv4 where a2:"p__Inv4\<le>N\<and>f=inv__17 p__Inv4" apply fastforce done have "(src=p__Inv4)\<or>(src~=p__Inv4)" apply (cut_tac a1 a2, auto) done moreover { assume b1: "(src=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: "(src~=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_NI_Local_GetX_PutX_4Vsinv__17: assumes a1: "(\<exists> src. src\<le>N\<and>r=n_NI_Local_GetX_PutX_4 N src)" and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__17 p__Inv4)" shows "invHoldForRule s f r (invariants N)" (is "?P1 s \<or> ?P2 s \<or> ?P3 s") proof - from a1 obtain src where a1:"src\<le>N\<and>r=n_NI_Local_GetX_PutX_4 N src" apply fastforce done from a2 obtain p__Inv4 where a2:"p__Inv4\<le>N\<and>f=inv__17 p__Inv4" apply fastforce done have "(src=p__Inv4)\<or>(src~=p__Inv4)" apply (cut_tac a1 a2, auto) done moreover { assume b1: "(src=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: "(src~=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_NI_Local_GetX_PutX_5Vsinv__17: assumes a1: "(\<exists> src. src\<le>N\<and>r=n_NI_Local_GetX_PutX_5 N src)" and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__17 p__Inv4)" shows "invHoldForRule s f r (invariants N)" (is "?P1 s \<or> ?P2 s \<or> ?P3 s") proof - from a1 obtain src where a1:"src\<le>N\<and>r=n_NI_Local_GetX_PutX_5 N src" apply fastforce done from a2 obtain p__Inv4 where a2:"p__Inv4\<le>N\<and>f=inv__17 p__Inv4" apply fastforce done have "(src=p__Inv4)\<or>(src~=p__Inv4)" apply (cut_tac a1 a2, auto) done moreover { assume b1: "(src=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: "(src~=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_NI_Local_GetX_PutX_6Vsinv__17: assumes a1: "(\<exists> src. src\<le>N\<and>r=n_NI_Local_GetX_PutX_6 N src)" and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__17 p__Inv4)" shows "invHoldForRule s f r (invariants N)" (is "?P1 s \<or> ?P2 s \<or> ?P3 s") proof - from a1 obtain src where a1:"src\<le>N\<and>r=n_NI_Local_GetX_PutX_6 N src" apply fastforce done from a2 obtain p__Inv4 where a2:"p__Inv4\<le>N\<and>f=inv__17 p__Inv4" apply fastforce done have "(src=p__Inv4)\<or>(src~=p__Inv4)" apply (cut_tac a1 a2, auto) done moreover { assume b1: "(src=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: "(src~=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_NI_Local_GetX_PutX_7__part__0Vsinv__17: assumes a1: "(\<exists> src. src\<le>N\<and>r=n_NI_Local_GetX_PutX_7__part__0 N src)" and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__17 p__Inv4)" shows "invHoldForRule s f r (invariants N)" (is "?P1 s \<or> ?P2 s \<or> ?P3 s") proof - from a1 obtain src where a1:"src\<le>N\<and>r=n_NI_Local_GetX_PutX_7__part__0 N src" apply fastforce done from a2 obtain p__Inv4 where a2:"p__Inv4\<le>N\<and>f=inv__17 p__Inv4" apply fastforce done have "(src=p__Inv4)\<or>(src~=p__Inv4)" apply (cut_tac a1 a2, auto) done moreover { assume b1: "(src=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: "(src~=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_NI_Local_GetX_PutX_7__part__1Vsinv__17: assumes a1: "(\<exists> src. src\<le>N\<and>r=n_NI_Local_GetX_PutX_7__part__1 N src)" and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__17 p__Inv4)" shows "invHoldForRule s f r (invariants N)" (is "?P1 s \<or> ?P2 s \<or> ?P3 s") proof - from a1 obtain src where a1:"src\<le>N\<and>r=n_NI_Local_GetX_PutX_7__part__1 N src" apply fastforce done from a2 obtain p__Inv4 where a2:"p__Inv4\<le>N\<and>f=inv__17 p__Inv4" apply fastforce done have "(src=p__Inv4)\<or>(src~=p__Inv4)" apply (cut_tac a1 a2, auto) done moreover { assume b1: "(src=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: "(src~=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_NI_Local_GetX_PutX_7_NODE_Get__part__0Vsinv__17: assumes a1: "(\<exists> src. src\<le>N\<and>r=n_NI_Local_GetX_PutX_7_NODE_Get__part__0 N src)" and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__17 p__Inv4)" shows "invHoldForRule s f r (invariants N)" (is "?P1 s \<or> ?P2 s \<or> ?P3 s") proof - from a1 obtain src where a1:"src\<le>N\<and>r=n_NI_Local_GetX_PutX_7_NODE_Get__part__0 N src" apply fastforce done from a2 obtain p__Inv4 where a2:"p__Inv4\<le>N\<and>f=inv__17 p__Inv4" apply fastforce done have "(src=p__Inv4)\<or>(src~=p__Inv4)" apply (cut_tac a1 a2, auto) done moreover { assume b1: "(src=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: "(src~=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_NI_Local_GetX_PutX_7_NODE_Get__part__1Vsinv__17: assumes a1: "(\<exists> src. src\<le>N\<and>r=n_NI_Local_GetX_PutX_7_NODE_Get__part__1 N src)" and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__17 p__Inv4)" shows "invHoldForRule s f r (invariants N)" (is "?P1 s \<or> ?P2 s \<or> ?P3 s") proof - from a1 obtain src where a1:"src\<le>N\<and>r=n_NI_Local_GetX_PutX_7_NODE_Get__part__1 N src" apply fastforce done from a2 obtain p__Inv4 where a2:"p__Inv4\<le>N\<and>f=inv__17 p__Inv4" apply fastforce done have "(src=p__Inv4)\<or>(src~=p__Inv4)" apply (cut_tac a1 a2, auto) done moreover { assume b1: "(src=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: "(src~=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_NI_Local_GetX_PutX_8_HomeVsinv__17: assumes a1: "(\<exists> src. src\<le>N\<and>r=n_NI_Local_GetX_PutX_8_Home N src)" and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__17 p__Inv4)" shows "invHoldForRule s f r (invariants N)" (is "?P1 s \<or> ?P2 s \<or> ?P3 s") proof - from a1 obtain src where a1:"src\<le>N\<and>r=n_NI_Local_GetX_PutX_8_Home N src" apply fastforce done from a2 obtain p__Inv4 where a2:"p__Inv4\<le>N\<and>f=inv__17 p__Inv4" apply fastforce done have "(src=p__Inv4)\<or>(src~=p__Inv4)" apply (cut_tac a1 a2, auto) done moreover { assume b1: "(src=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: "(src~=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_NI_Local_GetX_PutX_8_Home_NODE_GetVsinv__17: assumes a1: "(\<exists> src. src\<le>N\<and>r=n_NI_Local_GetX_PutX_8_Home_NODE_Get N src)" and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__17 p__Inv4)" shows "invHoldForRule s f r (invariants N)" (is "?P1 s \<or> ?P2 s \<or> ?P3 s") proof - from a1 obtain src where a1:"src\<le>N\<and>r=n_NI_Local_GetX_PutX_8_Home_NODE_Get N src" apply fastforce done from a2 obtain p__Inv4 where a2:"p__Inv4\<le>N\<and>f=inv__17 p__Inv4" apply fastforce done have "(src=p__Inv4)\<or>(src~=p__Inv4)" apply (cut_tac a1 a2, auto) done moreover { assume b1: "(src=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: "(src~=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_NI_Local_GetX_PutX_8Vsinv__17: assumes a1: "(\<exists> src pp. src\<le>N\<and>pp\<le>N\<and>src~=pp\<and>r=n_NI_Local_GetX_PutX_8 N src pp)" and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__17 p__Inv4)" shows "invHoldForRule s f r (invariants N)" (is "?P1 s \<or> ?P2 s \<or> ?P3 s") proof - from a1 obtain src pp where a1:"src\<le>N\<and>pp\<le>N\<and>src~=pp\<and>r=n_NI_Local_GetX_PutX_8 N src pp" apply fastforce done from a2 obtain p__Inv4 where a2:"p__Inv4\<le>N\<and>f=inv__17 p__Inv4" apply fastforce done have "(src=p__Inv4\<and>pp~=p__Inv4)\<or>(src~=p__Inv4\<and>pp=p__Inv4)\<or>(src~=p__Inv4\<and>pp~=p__Inv4)" apply (cut_tac a1 a2, auto) done moreover { assume b1: "(src=p__Inv4\<and>pp~=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: "(src~=p__Inv4\<and>pp=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: "(src~=p__Inv4\<and>pp~=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_NI_Local_GetX_PutX_8_NODE_GetVsinv__17: assumes a1: "(\<exists> src pp. src\<le>N\<and>pp\<le>N\<and>src~=pp\<and>r=n_NI_Local_GetX_PutX_8_NODE_Get N src pp)" and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__17 p__Inv4)" shows "invHoldForRule s f r (invariants N)" (is "?P1 s \<or> ?P2 s \<or> ?P3 s") proof - from a1 obtain src pp where a1:"src\<le>N\<and>pp\<le>N\<and>src~=pp\<and>r=n_NI_Local_GetX_PutX_8_NODE_Get N src pp" apply fastforce done from a2 obtain p__Inv4 where a2:"p__Inv4\<le>N\<and>f=inv__17 p__Inv4" apply fastforce done have "(src=p__Inv4\<and>pp~=p__Inv4)\<or>(src~=p__Inv4\<and>pp=p__Inv4)\<or>(src~=p__Inv4\<and>pp~=p__Inv4)" apply (cut_tac a1 a2, auto) done moreover { assume b1: "(src=p__Inv4\<and>pp~=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: "(src~=p__Inv4\<and>pp=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: "(src~=p__Inv4\<and>pp~=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_NI_Local_GetX_PutX_9__part__0Vsinv__17: assumes a1: "(\<exists> src. src\<le>N\<and>r=n_NI_Local_GetX_PutX_9__part__0 N src)" and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__17 p__Inv4)" shows "invHoldForRule s f r (invariants N)" (is "?P1 s \<or> ?P2 s \<or> ?P3 s") proof - from a1 obtain src where a1:"src\<le>N\<and>r=n_NI_Local_GetX_PutX_9__part__0 N src" apply fastforce done from a2 obtain p__Inv4 where a2:"p__Inv4\<le>N\<and>f=inv__17 p__Inv4" apply fastforce done have "(src=p__Inv4)\<or>(src~=p__Inv4)" apply (cut_tac a1 a2, auto) done moreover { assume b1: "(src=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: "(src~=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_NI_Local_GetX_PutX_9__part__1Vsinv__17: assumes a1: "(\<exists> src. src\<le>N\<and>r=n_NI_Local_GetX_PutX_9__part__1 N src)" and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__17 p__Inv4)" shows "invHoldForRule s f r (invariants N)" (is "?P1 s \<or> ?P2 s \<or> ?P3 s") proof - from a1 obtain src where a1:"src\<le>N\<and>r=n_NI_Local_GetX_PutX_9__part__1 N src" apply fastforce done from a2 obtain p__Inv4 where a2:"p__Inv4\<le>N\<and>f=inv__17 p__Inv4" apply fastforce done have "(src=p__Inv4)\<or>(src~=p__Inv4)" apply (cut_tac a1 a2, auto) done moreover { assume b1: "(src=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: "(src~=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_NI_Local_GetX_PutX_10_HomeVsinv__17: assumes a1: "(\<exists> src. src\<le>N\<and>r=n_NI_Local_GetX_PutX_10_Home N src)" and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__17 p__Inv4)" shows "invHoldForRule s f r (invariants N)" (is "?P1 s \<or> ?P2 s \<or> ?P3 s") proof - from a1 obtain src where a1:"src\<le>N\<and>r=n_NI_Local_GetX_PutX_10_Home N src" apply fastforce done from a2 obtain p__Inv4 where a2:"p__Inv4\<le>N\<and>f=inv__17 p__Inv4" apply fastforce done have "(src=p__Inv4)\<or>(src~=p__Inv4)" apply (cut_tac a1 a2, auto) done moreover { assume b1: "(src=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: "(src~=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_NI_Local_GetX_PutX_10Vsinv__17: assumes a1: "(\<exists> src pp. src\<le>N\<and>pp\<le>N\<and>src~=pp\<and>r=n_NI_Local_GetX_PutX_10 N src pp)" and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__17 p__Inv4)" shows "invHoldForRule s f r (invariants N)" (is "?P1 s \<or> ?P2 s \<or> ?P3 s") proof - from a1 obtain src pp where a1:"src\<le>N\<and>pp\<le>N\<and>src~=pp\<and>r=n_NI_Local_GetX_PutX_10 N src pp" apply fastforce done from a2 obtain p__Inv4 where a2:"p__Inv4\<le>N\<and>f=inv__17 p__Inv4" apply fastforce done have "(src=p__Inv4\<and>pp~=p__Inv4)\<or>(src~=p__Inv4\<and>pp=p__Inv4)\<or>(src~=p__Inv4\<and>pp~=p__Inv4)" apply (cut_tac a1 a2, auto) done moreover { assume b1: "(src=p__Inv4\<and>pp~=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: "(src~=p__Inv4\<and>pp=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: "(src~=p__Inv4\<and>pp~=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_NI_Local_GetX_PutX_11Vsinv__17: assumes a1: "(\<exists> src. src\<le>N\<and>r=n_NI_Local_GetX_PutX_11 N src)" and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__17 p__Inv4)" shows "invHoldForRule s f r (invariants N)" (is "?P1 s \<or> ?P2 s \<or> ?P3 s") proof - from a1 obtain src where a1:"src\<le>N\<and>r=n_NI_Local_GetX_PutX_11 N src" apply fastforce done from a2 obtain p__Inv4 where a2:"p__Inv4\<le>N\<and>f=inv__17 p__Inv4" apply fastforce done have "(src=p__Inv4)\<or>(src~=p__Inv4)" apply (cut_tac a1 a2, auto) done moreover { assume b1: "(src=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: "(src~=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_NI_Remote_GetX_NakVsinv__17: assumes a1: "(\<exists> src dst. src\<le>N\<and>dst\<le>N\<and>src~=dst\<and>r=n_NI_Remote_GetX_Nak src dst)" and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__17 p__Inv4)" shows "invHoldForRule s f r (invariants N)" (is "?P1 s \<or> ?P2 s \<or> ?P3 s") proof - from a1 obtain src dst where a1:"src\<le>N\<and>dst\<le>N\<and>src~=dst\<and>r=n_NI_Remote_GetX_Nak src dst" apply fastforce done from a2 obtain p__Inv4 where a2:"p__Inv4\<le>N\<and>f=inv__17 p__Inv4" apply fastforce done have "(src=p__Inv4\<and>dst~=p__Inv4)\<or>(src~=p__Inv4\<and>dst=p__Inv4)\<or>(src~=p__Inv4\<and>dst~=p__Inv4)" apply (cut_tac a1 a2, auto) done moreover { assume b1: "(src=p__Inv4\<and>dst~=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: "(src~=p__Inv4\<and>dst=p__Inv4)" have "?P2 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume b1: "(src~=p__Inv4\<and>dst~=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_NI_Remote_GetX_PutXVsinv__17: assumes a1: "(\<exists> src dst. src\<le>N\<and>dst\<le>N\<and>src~=dst\<and>r=n_NI_Remote_GetX_PutX src dst)" and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__17 p__Inv4)" shows "invHoldForRule s f r (invariants N)" (is "?P1 s \<or> ?P2 s \<or> ?P3 s") proof - from a1 obtain src dst where a1:"src\<le>N\<and>dst\<le>N\<and>src~=dst\<and>r=n_NI_Remote_GetX_PutX src dst" apply fastforce done from a2 obtain p__Inv4 where a2:"p__Inv4\<le>N\<and>f=inv__17 p__Inv4" apply fastforce done have "(src=p__Inv4\<and>dst~=p__Inv4)\<or>(src~=p__Inv4\<and>dst=p__Inv4)\<or>(src~=p__Inv4\<and>dst~=p__Inv4)" apply (cut_tac a1 a2, auto) done moreover { assume b1: "(src=p__Inv4\<and>dst~=p__Inv4)" have "?P3 s" apply (cut_tac a1 a2 b1, simp, rule_tac x="(neg (andForm (eqn (IVar (Field (Para (Field (Ident ''Sta'') ''Proc'') dst) ''CacheState'')) (Const CACHE_E)) (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''Dirty'')) (Const false))))" in exI, auto) done then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume b1: "(src~=p__Inv4\<and>dst=p__Inv4)" have "?P2 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume b1: "(src~=p__Inv4\<and>dst~=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_NI_Remote_PutVsinv__17: assumes a1: "(\<exists> dst. dst\<le>N\<and>r=n_NI_Remote_Put dst)" and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__17 p__Inv4)" shows "invHoldForRule s f r (invariants N)" (is "?P1 s \<or> ?P2 s \<or> ?P3 s") proof - from a1 obtain dst where a1:"dst\<le>N\<and>r=n_NI_Remote_Put dst" apply fastforce done from a2 obtain p__Inv4 where a2:"p__Inv4\<le>N\<and>f=inv__17 p__Inv4" apply fastforce done have "(dst=p__Inv4)\<or>(dst~=p__Inv4)" apply (cut_tac a1 a2, auto) done moreover { assume b1: "(dst=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: "(dst~=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_NI_Remote_PutXVsinv__17: assumes a1: "(\<exists> dst. dst\<le>N\<and>r=n_NI_Remote_PutX dst)" and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__17 p__Inv4)" shows "invHoldForRule s f r (invariants N)" (is "?P1 s \<or> ?P2 s \<or> ?P3 s") proof - from a1 obtain dst where a1:"dst\<le>N\<and>r=n_NI_Remote_PutX dst" apply fastforce done from a2 obtain p__Inv4 where a2:"p__Inv4\<le>N\<and>f=inv__17 p__Inv4" apply fastforce done have "(dst=p__Inv4)\<or>(dst~=p__Inv4)" apply (cut_tac a1 a2, auto) done moreover { assume b1: "(dst=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: "(dst~=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_PI_Local_GetX_PutX_HeadVld__part__0Vsinv__17: assumes a1: "(r=n_PI_Local_GetX_PutX_HeadVld__part__0 N )" and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__17 p__Inv4)" shows "invHoldForRule s f r (invariants N)" (is "?P1 s \<or> ?P2 s \<or> ?P3 s") proof - from a2 obtain p__Inv4 where a2:"p__Inv4\<le>N\<and>f=inv__17 p__Inv4" apply fastforce done have "?P1 s" proof(cut_tac a1 a2 , auto) qed then show "invHoldForRule s f r (invariants N)" by auto qed lemma n_PI_Local_GetX_PutX_HeadVld__part__1Vsinv__17: assumes a1: "(r=n_PI_Local_GetX_PutX_HeadVld__part__1 N )" and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__17 p__Inv4)" shows "invHoldForRule s f r (invariants N)" (is "?P1 s \<or> ?P2 s \<or> ?P3 s") proof - from a2 obtain p__Inv4 where a2:"p__Inv4\<le>N\<and>f=inv__17 p__Inv4" apply fastforce done have "?P1 s" proof(cut_tac a1 a2 , auto) qed then show "invHoldForRule s f r (invariants N)" by auto qed lemma n_PI_Local_GetX_PutX__part__0Vsinv__17: assumes a1: "(r=n_PI_Local_GetX_PutX__part__0 )" and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__17 p__Inv4)" shows "invHoldForRule s f r (invariants N)" (is "?P1 s \<or> ?P2 s \<or> ?P3 s") proof - from a2 obtain p__Inv4 where a2:"p__Inv4\<le>N\<and>f=inv__17 p__Inv4" apply fastforce done have "?P1 s" proof(cut_tac a1 a2 , auto) qed then show "invHoldForRule s f r (invariants N)" by auto qed lemma n_PI_Local_GetX_PutX__part__1Vsinv__17: assumes a1: "(r=n_PI_Local_GetX_PutX__part__1 )" and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__17 p__Inv4)" shows "invHoldForRule s f r (invariants N)" (is "?P1 s \<or> ?P2 s \<or> ?P3 s") proof - from a2 obtain p__Inv4 where a2:"p__Inv4\<le>N\<and>f=inv__17 p__Inv4" apply fastforce done have "?P1 s" proof(cut_tac a1 a2 , auto) qed then show "invHoldForRule s f r (invariants N)" by auto qed lemma n_PI_Local_PutXVsinv__17: assumes a1: "(r=n_PI_Local_PutX )" and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__17 p__Inv4)" shows "invHoldForRule s f r (invariants N)" (is "?P1 s \<or> ?P2 s \<or> ?P3 s") proof - from a2 obtain p__Inv4 where a2:"p__Inv4\<le>N\<and>f=inv__17 p__Inv4" apply fastforce done have "((formEval (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''Pending'')) (Const true)) s))\<or>((formEval (neg (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''Pending'')) (Const true))) s))" by auto moreover { assume c1: "((formEval (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''Pending'')) (Const true)) s))" have "?P3 s" apply (cut_tac a1 a2 c1, simp, rule_tac x="(neg (andForm (eqn (IVar (Field (Field (Ident ''Sta'') ''HomeProc'') ''CacheState'')) (Const CACHE_E)) (eqn (IVar (Field (Para (Field (Ident ''Sta'') ''UniMsg'') p__Inv4) ''Cmd'')) (Const UNI_PutX))))" in exI, auto) done then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume c1: "((formEval (neg (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''Pending'')) (Const true))) s))" have "?P3 s" apply (cut_tac a1 a2 c1, simp, rule_tac x="(neg (andForm (eqn (IVar (Field (Field (Ident ''Sta'') ''HomeProc'') ''CacheState'')) (Const CACHE_E)) (eqn (IVar (Field (Para (Field (Ident ''Sta'') ''UniMsg'') p__Inv4) ''Cmd'')) (Const UNI_PutX))))" 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_NI_Local_PutVsinv__17: assumes a1: "(r=n_NI_Local_Put )" and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__17 p__Inv4)" shows "invHoldForRule s f r (invariants N)" (is "?P1 s \<or> ?P2 s \<or> ?P3 s") proof - from a2 obtain p__Inv4 where a2:"p__Inv4\<le>N\<and>f=inv__17 p__Inv4" apply fastforce done have "?P3 s" apply (cut_tac a1 a2 , simp, rule_tac x="(neg (andForm (eqn (IVar (Field (Para (Field (Ident ''Sta'') ''UniMsg'') p__Inv4) ''Cmd'')) (Const UNI_PutX)) (eqn (IVar (Field (Field (Ident ''Sta'') ''HomeUniMsg'') ''Cmd'')) (Const UNI_Put))))" in exI, auto) done then show "invHoldForRule s f r (invariants N)" by auto qed lemma n_NI_WbVsinv__17: assumes a1: "(r=n_NI_Wb )" and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__17 p__Inv4)" shows "invHoldForRule s f r (invariants N)" (is "?P1 s \<or> ?P2 s \<or> ?P3 s") proof - from a2 obtain p__Inv4 where a2:"p__Inv4\<le>N\<and>f=inv__17 p__Inv4" apply fastforce done have "?P3 s" apply (cut_tac a1 a2 , simp, rule_tac x="(neg (andForm (eqn (IVar (Field (Para (Field (Ident ''Sta'') ''UniMsg'') p__Inv4) ''Cmd'')) (Const UNI_PutX)) (eqn (IVar (Field (Field (Ident ''Sta'') ''WbMsg'') ''Cmd'')) (Const WB_Wb))))" in exI, auto) done then show "invHoldForRule s f r (invariants N)" by auto qed lemma n_NI_ShWbVsinv__17: assumes a1: "(r=n_NI_ShWb N )" and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__17 p__Inv4)" shows "invHoldForRule s f r (invariants N)" (is "?P1 s \<or> ?P2 s \<or> ?P3 s") proof - from a2 obtain p__Inv4 where a2:"p__Inv4\<le>N\<and>f=inv__17 p__Inv4" apply fastforce done have "?P3 s" apply (cut_tac a1 a2 , simp, rule_tac x="(neg (andForm (eqn (IVar (Field (Para (Field (Ident ''Sta'') ''UniMsg'') p__Inv4) ''Cmd'')) (Const UNI_PutX)) (eqn (IVar (Field (Field (Ident ''Sta'') ''ShWbMsg'') ''Cmd'')) (Const SHWB_ShWb))))" in exI, auto) done then show "invHoldForRule s f r (invariants N)" by auto qed lemma n_NI_Remote_GetX_PutX_HomeVsinv__17: assumes a1: "\<exists> dst. dst\<le>N\<and>r=n_NI_Remote_GetX_PutX_Home dst" and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__17 p__Inv4)" shows "invHoldForRule s f r (invariants N)" apply (rule noEffectOnRule, cut_tac a1 a2, auto) done lemma n_StoreVsinv__17: assumes a1: "\<exists> src data. src\<le>N\<and>data\<le>N\<and>r=n_Store src data" and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__17 p__Inv4)" shows "invHoldForRule s f r (invariants N)" apply (rule noEffectOnRule, cut_tac a1 a2, auto) done lemma n_NI_InvAck_3Vsinv__17: assumes a1: "\<exists> src. src\<le>N\<and>r=n_NI_InvAck_3 N src" and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__17 p__Inv4)" shows "invHoldForRule s f r (invariants N)" apply (rule noEffectOnRule, cut_tac a1 a2, auto) done lemma n_NI_InvAck_1Vsinv__17: assumes a1: "\<exists> src. src\<le>N\<and>r=n_NI_InvAck_1 N src" and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__17 p__Inv4)" shows "invHoldForRule s f r (invariants N)" apply (rule noEffectOnRule, cut_tac a1 a2, auto) done lemma n_PI_Local_GetX_GetX__part__1Vsinv__17: assumes a1: "r=n_PI_Local_GetX_GetX__part__1 " and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__17 p__Inv4)" shows "invHoldForRule s f r (invariants N)" apply (rule noEffectOnRule, cut_tac a1 a2, auto) done lemma n_PI_Local_GetX_GetX__part__0Vsinv__17: assumes a1: "r=n_PI_Local_GetX_GetX__part__0 " and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__17 p__Inv4)" shows "invHoldForRule s f r (invariants N)" apply (rule noEffectOnRule, cut_tac a1 a2, auto) done lemma n_PI_Remote_ReplaceVsinv__17: assumes a1: "\<exists> src. src\<le>N\<and>r=n_PI_Remote_Replace src" and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__17 p__Inv4)" shows "invHoldForRule s f r (invariants N)" apply (rule noEffectOnRule, cut_tac a1 a2, auto) done lemma n_Store_HomeVsinv__17: assumes a1: "\<exists> data. data\<le>N\<and>r=n_Store_Home data" and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__17 p__Inv4)" shows "invHoldForRule s f r (invariants N)" apply (rule noEffectOnRule, cut_tac a1 a2, auto) done lemma n_PI_Local_ReplaceVsinv__17: assumes a1: "r=n_PI_Local_Replace " and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__17 p__Inv4)" shows "invHoldForRule s f r (invariants N)" apply (rule noEffectOnRule, cut_tac a1 a2, auto) done lemma n_NI_InvAck_existsVsinv__17: assumes a1: "\<exists> src pp. src\<le>N\<and>pp\<le>N\<and>src~=pp\<and>r=n_NI_InvAck_exists src pp" and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__17 p__Inv4)" shows "invHoldForRule s f r (invariants N)" apply (rule noEffectOnRule, cut_tac a1 a2, auto) done lemma n_PI_Remote_PutXVsinv__17: assumes a1: "\<exists> dst. dst\<le>N\<and>r=n_PI_Remote_PutX dst" and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__17 p__Inv4)" shows "invHoldForRule s f r (invariants N)" apply (rule noEffectOnRule, cut_tac a1 a2, auto) done lemma n_NI_Remote_Get_Put_HomeVsinv__17: assumes a1: "\<exists> dst. dst\<le>N\<and>r=n_NI_Remote_Get_Put_Home dst" and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__17 p__Inv4)" shows "invHoldForRule s f r (invariants N)" apply (rule noEffectOnRule, cut_tac a1 a2, auto) done lemma n_NI_InvVsinv__17: assumes a1: "\<exists> dst. dst\<le>N\<and>r=n_NI_Inv dst" and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__17 p__Inv4)" shows "invHoldForRule s f r (invariants N)" apply (rule noEffectOnRule, cut_tac a1 a2, auto) done lemma n_PI_Local_Get_PutVsinv__17: assumes a1: "r=n_PI_Local_Get_Put " and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__17 p__Inv4)" shows "invHoldForRule s f r (invariants N)" apply (rule noEffectOnRule, cut_tac a1 a2, auto) done lemma n_NI_ReplaceVsinv__17: assumes a1: "\<exists> src. src\<le>N\<and>r=n_NI_Replace src" and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__17 p__Inv4)" shows "invHoldForRule s f r (invariants N)" apply (rule noEffectOnRule, cut_tac a1 a2, auto) done lemma n_NI_Remote_GetX_Nak_HomeVsinv__17: assumes a1: "\<exists> dst. dst\<le>N\<and>r=n_NI_Remote_GetX_Nak_Home dst" and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__17 p__Inv4)" shows "invHoldForRule s f r (invariants N)" apply (rule noEffectOnRule, cut_tac a1 a2, auto) done lemma n_NI_Local_PutXAcksDoneVsinv__17: assumes a1: "r=n_NI_Local_PutXAcksDone " and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__17 p__Inv4)" shows "invHoldForRule s f r (invariants N)" apply (rule noEffectOnRule, cut_tac a1 a2, auto) done lemma n_NI_Remote_Get_Nak_HomeVsinv__17: assumes a1: "\<exists> dst. dst\<le>N\<and>r=n_NI_Remote_Get_Nak_Home dst" and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__17 p__Inv4)" shows "invHoldForRule s f r (invariants N)" apply (rule noEffectOnRule, cut_tac a1 a2, auto) done lemma n_NI_InvAck_exists_HomeVsinv__17: assumes a1: "\<exists> src. src\<le>N\<and>r=n_NI_InvAck_exists_Home src" and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__17 p__Inv4)" shows "invHoldForRule s f r (invariants N)" apply (rule noEffectOnRule, cut_tac a1 a2, auto) done lemma n_NI_Replace_HomeVsinv__17: assumes a1: "r=n_NI_Replace_Home " and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__17 p__Inv4)" shows "invHoldForRule s f r (invariants N)" apply (rule noEffectOnRule, cut_tac a1 a2, auto) done lemma n_NI_Nak_ClearVsinv__17: assumes a1: "r=n_NI_Nak_Clear " and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__17 p__Inv4)" shows "invHoldForRule s f r (invariants N)" apply (rule noEffectOnRule, cut_tac a1 a2, auto) done lemma n_PI_Local_Get_GetVsinv__17: assumes a1: "r=n_PI_Local_Get_Get " and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__17 p__Inv4)" shows "invHoldForRule s f r (invariants N)" apply (rule noEffectOnRule, cut_tac a1 a2, auto) done lemma n_NI_Nak_HomeVsinv__17: assumes a1: "r=n_NI_Nak_Home " and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__17 p__Inv4)" shows "invHoldForRule s f r (invariants N)" apply (rule noEffectOnRule, cut_tac a1 a2, auto) done lemma n_NI_InvAck_2Vsinv__17: assumes a1: "\<exists> src. src\<le>N\<and>r=n_NI_InvAck_2 N src" and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__17 p__Inv4)" shows "invHoldForRule s f r (invariants N)" apply (rule noEffectOnRule, cut_tac a1 a2, auto) done lemma n_NI_FAckVsinv__17: assumes a1: "r=n_NI_FAck " and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__17 p__Inv4)" shows "invHoldForRule s f r (invariants N)" apply (rule noEffectOnRule, cut_tac a1 a2, auto) done end
||| Interface implementations for lazy values. ||| This module should be imported when automatically ||| deriving interface implementations of data types ||| containing `Lazy` fields. module Data.Lazy %default total public export Eq a => Eq (Lazy a) where x == y = x == y public export Ord a => Ord (Lazy a) where compare x y = compare x y public export Semigroup a => Semigroup (Lazy a) where x <+> y = x <+> y public export Monoid a => Monoid (Lazy a) where neutral = neutral public export Show a => Show (Lazy a) where showPrec p a = showPrec p a public export Num a => Num (Lazy a) where a + b = a + b a * b = a * b fromInteger n = fromInteger n public export Neg a => Neg (Lazy a) where negate a = negate a a - b = a - b public export Abs a => Abs (Lazy a) where abs a = abs a public export Fractional a => Fractional (Lazy a) where a / b = a / b recip a = recip a public export Integral a => Integral (Lazy a) where a `mod` b = a `mod` b a `div` b = a `div` b
C * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * C * * C * copyright (c) 2011 by UCAR * C * * C * University Corporation for Atmospheric Research * C * * C * all rights reserved * C * * C * FFTPACK version 5.1 * C * * C * A Fortran Package of Fast Fourier * C * * C * Subroutines and Example Programs * C * * C * by * C * * C * Paul Swarztrauber and Dick Valent * C * * C * of * C * * C * the National Center for Atmospheric Research * C * * C * Boulder, Colorado (80307) U.S.A. * C * * C * which is sponsored by * C * * C * the National Science Foundation * C * * C * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * C SUBROUTINE RFFTMB (LOT, JUMP, N, INC, R, LENR, WSAVE, LENSAV, 1 WORK, LENWRK, IER) INTEGER LOT, JUMP, N, INC, LENR, LENSAV, LENWRK, IER REAL R(LENR), WSAVE(LENSAV) ,WORK(LENWRK) LOGICAL XERCON C IER = 0 C IF (LENR .LT. (LOT-1)*JUMP + INC*(N-1) + 1) THEN IER = 1 CALL XERFFT ('RFFTMB ', 6) ELSEIF (LENSAV .LT. N + INT(LOG(REAL(N))/LOG(2.)) +4) THEN IER = 2 CALL XERFFT ('RFFTMB ', 8) ELSEIF (LENWRK .LT. LOT*N) THEN IER = 3 CALL XERFFT ('RFFTMB ', 10) ELSEIF (.NOT. XERCON(INC,JUMP,N,LOT)) THEN IER = 4 CALL XERFFT ('RFFTMB ', -1) ENDIF C IF (N .EQ. 1) RETURN C CALL MRFTB1 (LOT,JUMP,N,INC,R,WORK,WSAVE,WSAVE(N+1)) RETURN END
{-# OPTIONS --cubical #-} module Type.Cubical where import Lvl open import Type open import Agda.Primitive public using (SSet) open import Agda.Primitive.Cubical public using () renaming (I to Interval) -- _ : SSet(Lvl.𝟎). Inhabitants can be seen as points on a closed unit interval. module Interval where open Agda.Primitive.Cubical public using ( Partial ; -- _ : ∀{ℓ} → Interval → Type{ℓ} → SSet(ℓ) PartialP -- _ : ∀{ℓ} → (i : Interval) → (.(Is-𝟏 i) → Type{ℓ}) → SSet(ℓ) ) renaming ( i0 to 𝟎 ; -- _ : Interval. 0 (the initial point) in the interval. i1 to 𝟏 ; -- _ : Interval. 1 (the terminal point) in the interval. primIMin to min ; -- _ : Interval → Interval → Interval. Chooses the point nearest 𝟎. Also called: _∧_ (from lattice structure). primIMax to max ; -- _ : Interval → Interval → Interval. Chooses the point nearest 𝟏. Also called: _∨_ (from lattice structure). primINeg to flip ; -- _ : Interval → Interval. Flips a point in the interval around the point of symmetry (the middle). Essentially (p ↦ 𝟏 − p). IsOne to Is-𝟏 ; -- _ : Interval → SSet(Lvl.𝟎). The predicate stating that a point is 𝟏. itIsOne to 𝟏-is-𝟏 ; -- _ : Is-𝟏(𝟏). Proof of 𝟏 being 𝟏. primComp to comp ; -- _ : ∀{ℓ : Interval → Lvl.Level} → (P : (i : Interval) → Type{ℓ(i)}) → ∀{i : Interval} → ((j : Interval) → .(Is-𝟏 i) → P(j)) → (P(𝟎) → P(𝟏)) primHComp to hComp ; -- _ : ∀{ℓ}{A : Type{ℓ}}{i : Interval} → (Interval → .(Is-𝟏 i) → A) → (A → A) primTransp to transp -- _ : ∀{ℓ : Interval → Lvl.Level}(A : (i : Interval) → Type{ℓ(i)}) → Interval → A(𝟎)→ A(𝟏). ) -- The distance to the nearest boundary. nearBound : Interval → Interval nearBound x = min x (flip x) -- The distance to the furthest boundary. farBound : Interval → Interval farBound x = max x (flip x) -- Proof of maximum of 𝟏 being 𝟏. maxₗ-is-𝟏 : ∀{x y} → Is-𝟏(x) → Is-𝟏(max x y) maxₗ-is-𝟏 {x}{y} = Agda.Primitive.Cubical.IsOne1 x y -- Proof of maximum of 𝟏 being 𝟏. maxᵣ-is-𝟏 : ∀{x y} → Is-𝟏(y) → Is-𝟏(max x y) maxᵣ-is-𝟏 {x}{y} = Agda.Primitive.Cubical.IsOne2 x y -- The predicate stating that a point is 𝟎. Is-𝟎 : Interval → SSet(Lvl.𝟎) Is-𝟎 i = Is-𝟏(flip i) -- Proof of 𝟎 being 𝟎. 𝟎-is-𝟎 : Is-𝟎(𝟎) 𝟎-is-𝟎 = 𝟏-is-𝟏 -- Proof of minimum of 𝟎 being 𝟎. minₗ-is-𝟎 : ∀{x y} → Is-𝟎(x) → Is-𝟎(min x y) minₗ-is-𝟎 {x}{y} = maxₗ-is-𝟏 {flip x} {flip y} -- Proof of minimum of 𝟎 being 𝟎. minᵣ-is-𝟎 : ∀{x y} → Is-𝟎(y) → Is-𝟎(min x y) minᵣ-is-𝟎 {x}{y} = maxᵣ-is-𝟏 {flip x} {flip y}
[STATEMENT] lemma split_szip_all[no_atp]: "(\<forall> x. P x) \<longleftrightarrow> (\<forall> y z. P (y ||| z))" [PROOF STATE] proof (prove) goal (1 subgoal): 1. (\<forall>x. P x) = (\<forall>y z. P (y ||| z)) [PROOF STEP] by (fastforce iff: split_szip)
(* The value setup for paper confidentiality *) theory Paper_Value_Setup imports Paper_Intro begin (* The observed values: *) consts PID :: paperID subsection\<open>Preliminaries\<close> declare updates_commute_paper[simp] (* two papers equal everywhere but w.r.t. their content: *) fun eqButC :: "paper \<Rightarrow> paper \<Rightarrow> bool" where "eqButC (Paper name info ct reviews dis decs ) (Paper name1 info1 ct1 reviews1 dis1 decs1) = (name = name1 \<and> info = info1 \<and> reviews = reviews1 \<and> dis = dis1 \<and> decs = decs1)" lemma eqButC: "eqButC pap pap1 = (titlePaper pap = titlePaper pap1 \<and> abstractPaper pap = abstractPaper pap1 \<and> reviewsPaper pap = reviewsPaper pap1 \<and> disPaper pap = disPaper pap1 \<and> decsPaper pap = decsPaper pap1)" by(cases pap, cases pap1, auto) lemma eqButC_eq[simp,intro!]: "eqButC pap pap" by(cases pap) auto lemma eqButC_sym: assumes "eqButC pap pap1" shows "eqButC pap1 pap" apply(cases pap, cases pap1) using assms by auto lemma eqButC_trans: assumes "eqButC pap pap1" and "eqButC pap1 pap2" shows "eqButC pap pap2" apply(cases pap, cases pap1, cases pap2) using assms by auto (* Auxiliary notion: two functions are equal everywhere but on the NIC (content) of the value corresponding to PID *) definition eeqButPID where "eeqButPID paps paps1 \<equiv> \<forall> pid. if pid = PID then eqButC (paps pid) (paps1 pid) else paps pid = paps1 pid" lemma eeqButPID_eeq[simp,intro!]: "eeqButPID s s" unfolding eeqButPID_def by auto lemma eeqButPID_sym: assumes "eeqButPID s s1" shows "eeqButPID s1 s" using assms eqButC_sym unfolding eeqButPID_def by auto lemma eeqButPID_trans: assumes "eeqButPID s s1" and "eeqButPID s1 s2" shows "eeqButPID s s2" using assms eqButC_trans unfolding eeqButPID_def by simp blast lemma eeqButPID_imp: "eeqButPID paps paps1 \<Longrightarrow> eqButC (paps PID) (paps1 PID)" "\<lbrakk>eeqButPID paps paps1; pid \<noteq> PID\<rbrakk> \<Longrightarrow> paps pid = paps1 pid" unfolding eeqButPID_def by auto lemma eeqButPID_cong: assumes "eeqButPID paps paps1" and "pid = PID \<Longrightarrow> eqButC uu uu1" and "pid \<noteq> PID \<Longrightarrow> uu = uu1" shows "eeqButPID (paps (pid := uu)) (paps1(pid := uu1))" using assms unfolding eeqButPID_def by auto lemma eeqButPID_RDD: "eeqButPID paps paps1 \<Longrightarrow> titlePaper (paps PID) = titlePaper (paps1 PID) \<and> abstractPaper (paps PID) = abstractPaper (paps1 PID) \<and> reviewsPaper (paps PID) = reviewsPaper (paps1 PID) \<and> disPaper (paps PID) = disPaper (paps1 PID) \<and> decsPaper (paps PID) = decsPaper (paps1 PID)" using eeqButPID_def unfolding eqButC by auto (* The notion of two states being equal everywhere but on the content of the paper associated to a given PID *) definition eqButPID :: "state \<Rightarrow> state \<Rightarrow> bool" where "eqButPID s s1 \<equiv> confIDs s = confIDs s1 \<and> conf s = conf s1 \<and> userIDs s = userIDs s1 \<and> pass s = pass s1 \<and> user s = user s1 \<and> roles s = roles s1 \<and> paperIDs s = paperIDs s1 \<and> eeqButPID (paper s) (paper s1) \<and> pref s = pref s1 \<and> voronkov s = voronkov s1 \<and> news s = news s1 \<and> phase s = phase s1" lemma eqButPID_eq[simp,intro!]: "eqButPID s s" unfolding eqButPID_def by auto lemma eqButPID_sym: assumes "eqButPID s s1" shows "eqButPID s1 s" using assms eeqButPID_sym unfolding eqButPID_def by auto lemma eqButPID_trans: assumes "eqButPID s s1" and "eqButPID s1 s2" shows "eqButPID s s2" using assms eeqButPID_trans unfolding eqButPID_def by auto (* Implications from eqButPID, including w.r.t. auxiliary operations: *) lemma eqButPID_imp: "eqButPID s s1 \<Longrightarrow> confIDs s = confIDs s1 \<and> conf s = conf s1 \<and> userIDs s = userIDs s1 \<and> pass s = pass s1 \<and> user s = user s1 \<and> roles s = roles s1 \<and> paperIDs s = paperIDs s1 \<and> eeqButPID (paper s) (paper s1) \<and> pref s = pref s1 \<and> voronkov s = voronkov s1 \<and> news s = news s1 \<and> phase s = phase s1 \<and> getAllPaperIDs s = getAllPaperIDs s1 \<and> isRev s cid uid pid = isRev s1 cid uid pid \<and> getReviewIndex s cid uid pid = getReviewIndex s1 cid uid pid \<and> getRevRole s cid uid pid = getRevRole s1 cid uid pid " unfolding eqButPID_def getAllPaperIDs_def unfolding isRev_def getReviewIndex_def getRevRole_def by auto lemma eqButPID_imp1: "eqButPID s s1 \<Longrightarrow> eqButC (paper s pid) (paper s1 pid)" "eqButPID s s1 \<Longrightarrow> pid \<noteq> PID \<or> PID \<noteq> pid \<Longrightarrow> paper s pid = paper s1 pid \<and> getNthReview s pid n = getNthReview s1 pid n" unfolding eqButPID_def getNthReview_def eeqButPID_def apply auto by (metis eqButC_eq) lemma eqButPID_imp2: assumes "eqButPID s s1" and "pid \<noteq> PID \<or> PID \<noteq> pid" shows "getReviewersReviews s cid pid = getReviewersReviews s1 cid pid" proof- have "(\<lambda>uID. if isRev s cid uID pid then [(uID, getNthReview s pid (getReviewIndex s cid uID pid))] else []) = (\<lambda>uID. if isRev s1 cid uID pid then [(uID, getNthReview s1 pid (getReviewIndex s1 cid uID pid))] else [])" apply(rule ext) using assms by (auto simp: eqButPID_imp eqButPID_imp1) thus ?thesis unfolding getReviewersReviews_def using assms by (simp add: eqButPID_imp) qed lemma eqButPID_RDD: "eqButPID s s1 \<Longrightarrow> titlePaper (paper s PID) = titlePaper (paper s1 PID) \<and> abstractPaper (paper s PID) = abstractPaper (paper s1 PID) \<and> reviewsPaper (paper s PID) = reviewsPaper (paper s1 PID) \<and> disPaper (paper s PID) = disPaper (paper s1 PID) \<and> decsPaper (paper s PID) = decsPaper (paper s1 PID)" using eqButPID_imp eeqButPID_RDD by auto lemma eqButPID_cong[simp, intro]: "\<And> uu1 uu2. eqButPID s s1 \<Longrightarrow> uu1 = uu2 \<Longrightarrow> eqButPID (s \<lparr>confIDs := uu1\<rparr>) (s1 \<lparr>confIDs := uu2\<rparr>)" "\<And> uu1 uu2. eqButPID s s1 \<Longrightarrow> uu1 = uu2 \<Longrightarrow> eqButPID (s \<lparr>conf := uu1\<rparr>) (s1 \<lparr>conf := uu2\<rparr>)" "\<And> uu1 uu2. eqButPID s s1 \<Longrightarrow> uu1 = uu2 \<Longrightarrow> eqButPID (s \<lparr>userIDs := uu1\<rparr>) (s1 \<lparr>userIDs := uu2\<rparr>)" "\<And> uu1 uu2. eqButPID s s1 \<Longrightarrow> uu1 = uu2 \<Longrightarrow> eqButPID (s \<lparr>pass := uu1\<rparr>) (s1 \<lparr>pass := uu2\<rparr>)" "\<And> uu1 uu2. eqButPID s s1 \<Longrightarrow> uu1 = uu2 \<Longrightarrow> eqButPID (s \<lparr>user := uu1\<rparr>) (s1 \<lparr>user := uu2\<rparr>)" "\<And> uu1 uu2. eqButPID s s1 \<Longrightarrow> uu1 = uu2 \<Longrightarrow> eqButPID (s \<lparr>roles := uu1\<rparr>) (s1 \<lparr>roles := uu2\<rparr>)" "\<And> uu1 uu2. eqButPID s s1 \<Longrightarrow> uu1 = uu2 \<Longrightarrow> eqButPID (s \<lparr>paperIDs := uu1\<rparr>) (s1 \<lparr>paperIDs := uu2\<rparr>)" "\<And> uu1 uu2. eqButPID s s1 \<Longrightarrow> eeqButPID uu1 uu2 \<Longrightarrow> eqButPID (s \<lparr>paper := uu1\<rparr>) (s1 \<lparr>paper := uu2\<rparr>)" "\<And> uu1 uu2. eqButPID s s1 \<Longrightarrow> uu1 = uu2 \<Longrightarrow> eqButPID (s \<lparr>pref := uu1\<rparr>) (s1 \<lparr>pref := uu2\<rparr>)" "\<And> uu1 uu2. eqButPID s s1 \<Longrightarrow> uu1 = uu2 \<Longrightarrow> eqButPID (s \<lparr>voronkov := uu1\<rparr>) (s1 \<lparr>voronkov := uu2\<rparr>)" "\<And> uu1 uu2. eqButPID s s1 \<Longrightarrow> uu1 = uu2 \<Longrightarrow> eqButPID (s \<lparr>news := uu1\<rparr>) (s1 \<lparr>news := uu2\<rparr>)" "\<And> uu1 uu2. eqButPID s s1 \<Longrightarrow> uu1 = uu2 \<Longrightarrow> eqButPID (s \<lparr>phase := uu1\<rparr>) (s1 \<lparr>phase := uu2\<rparr>)" unfolding eqButPID_def by auto lemma eqButPID_Paper: assumes s's1': "eqButPID s s1" and "paper s pid = Paper title abstract pc reviews dis decs" and "paper s1 pid = Paper title1 abstract1 pc1 reviews1 dis1 decs1" shows "title = title1 \<and> abstract = abstract1 \<and> reviews = reviews1 \<and> dis = dis1 \<and> decs = decs1" using assms unfolding eqButPID_def apply (auto simp: eqButC eeqButPID_def) by (metis titlePaper.simps abstractPaper.simps reviewsPaper.simps disPaper.simps decsPaper.simps)+ definition "NOSIMP a \<equiv> a" lemma [cong]: "NOSIMP a = NOSIMP a" by simp lemma eqButPID_paper: assumes "eqButPID s s1" shows "paper s = (paper s1)(PID := Paper (titlePaper (paper s1 PID)) (abstractPaper (paper s1 PID)) (contentPaper (NOSIMP (paper s PID))) (reviewsPaper (paper s1 PID)) (disPaper (paper s1 PID)) (decsPaper (paper s1 PID)) )" apply (rule sym) using assms unfolding NOSIMP_def eqButPID_def eeqButPID_def apply (intro ext) apply simp apply (cases "paper s1 PID", simp_all) apply (cases "paper s PID", simp_all) done (* lemmas eqButPID_simps = eqButPID_simps1 eqButPID_simps2 eqButPID_paper *) lemmas eqButPID_simps = eqButPID_imp eqButPID_paper subsection\<open>Value Setup\<close> type_synonym "value" = pcontent fun \<phi> :: "(state,act,out) trans \<Rightarrow> bool" where "\<phi> (Trans _ (Uact (uPaperC cid uid p pid ct)) ou _) = (pid = PID \<and> ou = outOK)" | "\<phi> _ = False" lemma \<phi>_def2: "\<phi> (Trans s a ou s') = (\<exists>cid uid p ct. a = Uact (uPaperC cid uid p PID ct) \<and> ou = outOK)" proof (cases a) case (Uact x2) then show ?thesis by (cases x2; auto) qed auto fun f :: "(state,act,out) trans \<Rightarrow> value" where "f (Trans _ (Uact (uPaperC cid uid p pid ct)) _ _) = ct" lemma Uact_uPaperC_step_eqButPID: assumes a: "a = Uact (uPaperC cid uid p PID ct)" and "step s a = (ou,s')" shows "eqButPID s s'" using assms unfolding eqButPID_def eeqButPID_def by (auto simp: u_defs) lemma \<phi>_step_eqButPID: assumes \<phi>: "\<phi> (Trans s a ou s')" and s: "step s a = (ou,s')" shows "eqButPID s s'" using \<phi> Uact_uPaperC_step_eqButPID[OF _ s] unfolding \<phi>_def2 by blast (* major *) lemma eqButPID_step: assumes s's1': "eqButPID s s1" and step: "step s a = (ou,s')" and step1: "step s1 a = (ou1,s1')" shows "eqButPID s' s1'" proof - note eqs = eqButPID_imp[OF s's1'] note eqs' = eqButPID_imp1[OF s's1'] note simps[simp] = c_defs u_defs uu_defs r_defs l_defs Paper_dest_conv eqButPID_def eeqButPID_def eqButC note * = step step1 eqs eqs' then show ?thesis proof (cases a) case (Cact x1) then show ?thesis using * by (cases x1; auto) next case (Uact x2) then show ?thesis using * by (cases x2; auto) next case (UUact x3) then show ?thesis using * by (cases x3; auto) qed auto qed lemma eqButPID_step_\<phi>_imp: assumes s's1': "eqButPID s s1" and step: "step s a = (ou,s')" and step1: "step s1 a = (ou1,s1')" and \<phi>: "\<phi> (Trans s a ou s')" shows "\<phi> (Trans s1 a ou1 s1')" using assms unfolding \<phi>_def2 by (auto simp add: u_defs eqButPID_imp) lemma eqButPID_step_\<phi>: assumes s's1': "eqButPID s s1" and step: "step s a = (ou,s')" and step1: "step s1 a = (ou1,s1')" shows "\<phi> (Trans s a ou s') = \<phi> (Trans s1 a ou1 s1')" by (metis eqButPID_step_\<phi>_imp eqButPID_sym assms) end
/- Copyright (c) 2018 Chris Hughes. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Chris Hughes -/ import data.nat.modeq import tactic.ring /-! # Congruences modulo an integer This file defines the equivalence relation `a ≡ b [ZMOD n]` on the integers, similarly to how `data.nat.modeq` defines them for the natural numbers. The notation is short for `n.modeq a b`, which is defined to be `a % n = b % n` for integers `a b n`. ## Tags modeq, congruence, mod, MOD, modulo, integers -/ namespace int /-- `a ≡ b [ZMOD n]` when `a % n = b % n`. -/ @[derive decidable] def modeq (n a b : ℤ) := a % n = b % n notation a ` ≡ `:50 b ` [ZMOD `:50 n `]`:0 := modeq n a b variables {m n a b c d : ℤ} namespace modeq @[refl] protected theorem refl (a : ℤ) : a ≡ a [ZMOD n] := @rfl _ _ protected theorem rfl : a ≡ a [ZMOD n] := modeq.refl _ @[symm] protected theorem symm : a ≡ b [ZMOD n] → b ≡ a [ZMOD n] := eq.symm @[trans] protected theorem trans : a ≡ b [ZMOD n] → b ≡ c [ZMOD n] → a ≡ c [ZMOD n] := eq.trans end modeq lemma coe_nat_modeq_iff {a b n : ℕ} : a ≡ b [ZMOD n] ↔ a ≡ b [MOD n] := by unfold modeq nat.modeq; rw ← int.coe_nat_eq_coe_nat_iff; simp [coe_nat_mod] theorem modeq_zero_iff_dvd : a ≡ 0 [ZMOD n] ↔ n ∣ a := by rw [modeq, zero_mod, dvd_iff_mod_eq_zero] lemma _root_.has_dvd.dvd.modeq_zero_int (h : n ∣ a) : a ≡ 0 [ZMOD n] := modeq_zero_iff_dvd.2 h lemma _root_.has_dvd.dvd.zero_modeq_int (h : n ∣ a) : 0 ≡ a [ZMOD n] := h.modeq_zero_int.symm theorem modeq_iff_dvd : a ≡ b [ZMOD n] ↔ n ∣ b - a := by rw [modeq, eq_comm]; simp [mod_eq_mod_iff_mod_sub_eq_zero, dvd_iff_mod_eq_zero, -euclidean_domain.mod_eq_zero] theorem modeq.dvd : a ≡ b [ZMOD n] → n ∣ b - a := modeq_iff_dvd.1 theorem modeq_of_dvd : n ∣ b - a → a ≡ b [ZMOD n] := modeq_iff_dvd.2 theorem mod_modeq (a n) : a % n ≡ a [ZMOD n] := mod_mod _ _ namespace modeq protected theorem modeq_of_dvd (d : m ∣ n) (h : a ≡ b [ZMOD n]) : a ≡ b [ZMOD m] := modeq_iff_dvd.2 $ d.trans h.dvd protected theorem mul_left' (hc : 0 ≤ c) (h : a ≡ b [ZMOD n]) : c * a ≡ c * b [ZMOD (c * n)] := or.cases_on hc.lt_or_eq (λ hc, by unfold modeq; simp [mul_mod_mul_of_pos hc, (show _ = _, from h)] ) (λ hc, by simp [hc.symm]) protected theorem mul_right' (hc : 0 ≤ c) (h : a ≡ b [ZMOD n]) : a * c ≡ b * c [ZMOD (n * c)] := by rw [mul_comm a, mul_comm b, mul_comm n]; exact h.mul_left' hc protected theorem add (h₁ : a ≡ b [ZMOD n]) (h₂ : c ≡ d [ZMOD n]) : a + c ≡ b + d [ZMOD n] := modeq_iff_dvd.2 $ by { convert dvd_add h₁.dvd h₂.dvd, ring } protected theorem add_left (c : ℤ) (h : a ≡ b [ZMOD n]) : c + a ≡ c + b [ZMOD n] := modeq.rfl.add h protected theorem add_right (c : ℤ) (h : a ≡ b [ZMOD n]) : a + c ≡ b + c [ZMOD n] := h.add modeq.rfl protected theorem add_left_cancel (h₁ : a ≡ b [ZMOD n]) (h₂ : a + c ≡ b + d [ZMOD n]) : c ≡ d [ZMOD n] := have d - c = b + d - (a + c) - (b - a) := by ring, modeq_iff_dvd.2 $ by { rw [this], exact dvd_sub h₂.dvd h₁.dvd } protected theorem add_left_cancel' (c : ℤ) (h : c + a ≡ c + b [ZMOD n]) : a ≡ b [ZMOD n] := modeq.rfl.add_left_cancel h protected theorem add_right_cancel (h₁ : c ≡ d [ZMOD n]) (h₂ : a + c ≡ b + d [ZMOD n]) : a ≡ b [ZMOD n] := by { rw [add_comm a, add_comm b] at h₂, exact h₁.add_left_cancel h₂ } protected theorem add_right_cancel' (c : ℤ) (h : a + c ≡ b + c [ZMOD n]) : a ≡ b [ZMOD n] := modeq.rfl.add_right_cancel h protected theorem neg (h : a ≡ b [ZMOD n]) : -a ≡ -b [ZMOD n] := h.add_left_cancel (by simp_rw [←sub_eq_add_neg, sub_self]) protected theorem sub (h₁ : a ≡ b [ZMOD n]) (h₂ : c ≡ d [ZMOD n]) : a - c ≡ b - d [ZMOD n] := by { rw [sub_eq_add_neg, sub_eq_add_neg], exact h₁.add h₂.neg } protected theorem sub_left (c : ℤ) (h : a ≡ b [ZMOD n]) : c - a ≡ c - b [ZMOD n] := modeq.rfl.sub h protected theorem sub_right (c : ℤ) (h : a ≡ b [ZMOD n]) : a - c ≡ b - c [ZMOD n] := h.sub modeq.rfl protected theorem mul_left (c : ℤ) (h : a ≡ b [ZMOD n]) : c * a ≡ c * b [ZMOD n] := or.cases_on (le_total 0 c) (λ hc, (h.mul_left' hc).modeq_of_dvd (dvd_mul_left _ _) ) (λ hc, by rw [← neg_neg c, ← neg_mul_eq_neg_mul, ← neg_mul_eq_neg_mul _ b]; exact ((h.mul_left' $ neg_nonneg.2 hc).modeq_of_dvd (dvd_mul_left _ _)).neg) protected theorem mul_right (c : ℤ) (h : a ≡ b [ZMOD n]) : a * c ≡ b * c [ZMOD n] := by { rw [mul_comm a, mul_comm b], exact h.mul_left c } protected theorem mul (h₁ : a ≡ b [ZMOD n]) (h₂ : c ≡ d [ZMOD n]) : a * c ≡ b * d [ZMOD n] := (h₂.mul_left _).trans (h₁.mul_right _) protected theorem pow (m : ℕ) (h : a ≡ b [ZMOD n]) : a ^ m ≡ b ^ m [ZMOD n] := begin induction m with d hd, {refl}, rw [pow_succ, pow_succ], exact h.mul hd, end theorem of_modeq_mul_left (m : ℤ) (h : a ≡ b [ZMOD m * n]) : a ≡ b [ZMOD n] := by rw [modeq_iff_dvd] at *; exact (dvd_mul_left n m).trans h theorem of_modeq_mul_right (m : ℤ) : a ≡ b [ZMOD n * m] → a ≡ b [ZMOD n] := mul_comm m n ▸ of_modeq_mul_left _ end modeq theorem modeq_one : a ≡ b [ZMOD 1] := modeq_of_dvd (one_dvd _) lemma modeq_sub (a b : ℤ) : a ≡ b [ZMOD a - b] := (modeq_of_dvd dvd_rfl).symm lemma modeq_and_modeq_iff_modeq_mul {a b m n : ℤ} (hmn : m.nat_abs.coprime n.nat_abs) : a ≡ b [ZMOD m] ∧ a ≡ b [ZMOD n] ↔ (a ≡ b [ZMOD m * n]) := ⟨λ h, begin rw [modeq_iff_dvd, modeq_iff_dvd] at h, rw [modeq_iff_dvd, ← nat_abs_dvd, ← dvd_nat_abs, coe_nat_dvd, nat_abs_mul], refine hmn.mul_dvd_of_dvd_of_dvd _ _; rw [← coe_nat_dvd, nat_abs_dvd, dvd_nat_abs]; tauto end, λ h, ⟨h.of_modeq_mul_right _, h.of_modeq_mul_left _⟩⟩ lemma gcd_a_modeq (a b : ℕ) : (a : ℤ) * nat.gcd_a a b ≡ nat.gcd a b [ZMOD b] := by { rw [← add_zero ((a : ℤ) * _), nat.gcd_eq_gcd_ab], exact (dvd_mul_right _ _).zero_modeq_int.add_left _ } theorem modeq_add_fac {a b n : ℤ} (c : ℤ) (ha : a ≡ b [ZMOD n]) : a + n*c ≡ b [ZMOD n] := calc a + n*c ≡ b + n*c [ZMOD n] : ha.add_right _ ... ≡ b + 0 [ZMOD n] : (dvd_mul_right _ _).modeq_zero_int.add_left _ ... ≡ b [ZMOD n] : by rw add_zero lemma mod_coprime {a b : ℕ} (hab : nat.coprime a b) : ∃ y : ℤ, a * y ≡ 1 [ZMOD b] := ⟨ nat.gcd_a a b, have hgcd : nat.gcd a b = 1, from nat.coprime.gcd_eq_one hab, calc ↑a * nat.gcd_a a b ≡ ↑a * nat.gcd_a a b + ↑b * nat.gcd_b a b [ZMOD ↑b] : modeq.symm $ modeq_add_fac _ $ modeq.refl _ ... ≡ 1 [ZMOD ↑b] : by rw [← nat.gcd_eq_gcd_ab, hgcd]; reflexivity ⟩ lemma exists_unique_equiv (a : ℤ) {b : ℤ} (hb : 0 < b) : ∃ z : ℤ, 0 ≤ z ∧ z < b ∧ z ≡ a [ZMOD b] := ⟨ a % b, mod_nonneg _ (ne_of_gt hb), have a % b < |b|, from mod_lt _ (ne_of_gt hb), by rwa abs_of_pos hb at this, by simp [modeq] ⟩ lemma exists_unique_equiv_nat (a : ℤ) {b : ℤ} (hb : 0 < b) : ∃ z : ℕ, ↑z < b ∧ ↑z ≡ a [ZMOD b] := let ⟨z, hz1, hz2, hz3⟩ := exists_unique_equiv a hb in ⟨z.nat_abs, by split; rw [←of_nat_eq_coe, of_nat_nat_abs_eq_of_nonneg hz1]; assumption⟩ @[simp] lemma mod_mul_right_mod (a b c : ℤ) : a % (b * c) % b = a % b := (mod_modeq _ _).of_modeq_mul_right _ @[simp] lemma mod_mul_left_mod (a b c : ℤ) : a % (b * c) % c = a % c := (mod_modeq _ _).of_modeq_mul_left _ end int
State Before: M : Type u_1 inst✝ : Semigroup M a : Stream' M i : ℕ ⊢ Stream'.nth a i ∈ FP a State After: case zero M : Type u_1 inst✝ : Semigroup M a✝ a : Stream' M ⊢ Stream'.nth a Nat.zero ∈ FP a case succ M : Type u_1 inst✝ : Semigroup M a✝ : Stream' M i : ℕ ih : ∀ (a : Stream' M), Stream'.nth a i ∈ FP a a : Stream' M ⊢ Stream'.nth a (Nat.succ i) ∈ FP a Tactic: induction' i with i ih generalizing a State Before: case zero M : Type u_1 inst✝ : Semigroup M a✝ a : Stream' M ⊢ Stream'.nth a Nat.zero ∈ FP a State After: no goals Tactic: apply FP.head State Before: case succ M : Type u_1 inst✝ : Semigroup M a✝ : Stream' M i : ℕ ih : ∀ (a : Stream' M), Stream'.nth a i ∈ FP a a : Stream' M ⊢ Stream'.nth a (Nat.succ i) ∈ FP a State After: case succ.h M : Type u_1 inst✝ : Semigroup M a✝ : Stream' M i : ℕ ih : ∀ (a : Stream' M), Stream'.nth a i ∈ FP a a : Stream' M ⊢ FP (Stream'.tail a) (Stream'.nth a (Nat.succ i)) Tactic: apply FP.tail State Before: case succ.h M : Type u_1 inst✝ : Semigroup M a✝ : Stream' M i : ℕ ih : ∀ (a : Stream' M), Stream'.nth a i ∈ FP a a : Stream' M ⊢ FP (Stream'.tail a) (Stream'.nth a (Nat.succ i)) State After: no goals Tactic: apply ih
State Before: ι : Type ?u.476599 α : Type u β : Type v γ : Type w δ : Type x l₁ l₂ : List α a : α as : List α b : β bs : List β ⊢ zipLeft as [] = map (fun a => (a, none)) as State After: no goals Tactic: cases as <;> rfl
State Before: α : Type u_2 E : Type u_1 F : Type ?u.367774 m0 : MeasurableSpace α inst✝⁵ : NormedAddCommGroup E inst✝⁴ : NormedSpace ℝ E inst✝³ : CompleteSpace E inst✝² : NormedAddCommGroup F inst✝¹ : NormedSpace ℝ F inst✝ : CompleteSpace F μ : MeasureTheory.Measure α s : Set E t : Set α f : α → E g : E → ℝ C : ℝ hs : Convex ℝ s hsc : IsClosed s h0 : ↑↑μ t ≠ 0 ht : ↑↑μ t ≠ ⊤ hfs : ∀ᵐ (x : α) ∂Measure.restrict μ t, f x ∈ s hfi : IntegrableOn f t ⊢ (⨍ (x : α) in t, f x ∂μ) ∈ s State After: α : Type u_2 E : Type u_1 F : Type ?u.367774 m0 : MeasurableSpace α inst✝⁵ : NormedAddCommGroup E inst✝⁴ : NormedSpace ℝ E inst✝³ : CompleteSpace E inst✝² : NormedAddCommGroup F inst✝¹ : NormedSpace ℝ F inst✝ : CompleteSpace F μ : MeasureTheory.Measure α s : Set E t : Set α f : α → E g : E → ℝ C : ℝ hs : Convex ℝ s hsc : IsClosed s h0 : ↑↑μ t ≠ 0 ht : ↑↑μ t ≠ ⊤ hfs : ∀ᵐ (x : α) ∂Measure.restrict μ t, f x ∈ s hfi : IntegrableOn f t this : Fact (↑↑μ t < ⊤) ⊢ (⨍ (x : α) in t, f x ∂μ) ∈ s Tactic: haveI : Fact (μ t < ∞) := ⟨ht.lt_top⟩ State Before: α : Type u_2 E : Type u_1 F : Type ?u.367774 m0 : MeasurableSpace α inst✝⁵ : NormedAddCommGroup E inst✝⁴ : NormedSpace ℝ E inst✝³ : CompleteSpace E inst✝² : NormedAddCommGroup F inst✝¹ : NormedSpace ℝ F inst✝ : CompleteSpace F μ : MeasureTheory.Measure α s : Set E t : Set α f : α → E g : E → ℝ C : ℝ hs : Convex ℝ s hsc : IsClosed s h0 : ↑↑μ t ≠ 0 ht : ↑↑μ t ≠ ⊤ hfs : ∀ᵐ (x : α) ∂Measure.restrict μ t, f x ∈ s hfi : IntegrableOn f t this : Fact (↑↑μ t < ⊤) ⊢ (⨍ (x : α) in t, f x ∂μ) ∈ s State After: α : Type u_2 E : Type u_1 F : Type ?u.367774 m0 : MeasurableSpace α inst✝⁵ : NormedAddCommGroup E inst✝⁴ : NormedSpace ℝ E inst✝³ : CompleteSpace E inst✝² : NormedAddCommGroup F inst✝¹ : NormedSpace ℝ F inst✝ : CompleteSpace F μ : MeasureTheory.Measure α s : Set E t : Set α f : α → E g : E → ℝ C : ℝ hs : Convex ℝ s hsc : IsClosed s h0 : ↑↑μ t ≠ 0 ht : ↑↑μ t ≠ ⊤ hfs : ∀ᵐ (x : α) ∂Measure.restrict μ t, f x ∈ s hfi : IntegrableOn f t this : Fact (↑↑μ t < ⊤) ⊢ Measure.restrict μ t ≠ 0 Tactic: refine' hs.average_mem hsc _ hfs hfi State Before: α : Type u_2 E : Type u_1 F : Type ?u.367774 m0 : MeasurableSpace α inst✝⁵ : NormedAddCommGroup E inst✝⁴ : NormedSpace ℝ E inst✝³ : CompleteSpace E inst✝² : NormedAddCommGroup F inst✝¹ : NormedSpace ℝ F inst✝ : CompleteSpace F μ : MeasureTheory.Measure α s : Set E t : Set α f : α → E g : E → ℝ C : ℝ hs : Convex ℝ s hsc : IsClosed s h0 : ↑↑μ t ≠ 0 ht : ↑↑μ t ≠ ⊤ hfs : ∀ᵐ (x : α) ∂Measure.restrict μ t, f x ∈ s hfi : IntegrableOn f t this : Fact (↑↑μ t < ⊤) ⊢ Measure.restrict μ t ≠ 0 State After: no goals Tactic: rwa [Ne.def, restrict_eq_zero]
#redirect City UCD Student Liaison Commission
function compute(obj::DOPComputer, arg0::AbsoluteDate, arg1::List) return jcall(obj, "compute", DOP, (AbsoluteDate, List), arg0, arg1) end function create(::Type{DOPComputer}, arg0::OneAxisEllipsoid, arg1::GeodeticPoint) return jcall(DOPComputer, "create", DOPComputer, (OneAxisEllipsoid, GeodeticPoint), arg0, arg1) end function get_elevation_mask(obj::DOPComputer) return jcall(obj, "getElevationMask", ElevationMask, ()) end function get_min_elevation(obj::DOPComputer) return jcall(obj, "getMinElevation", jdouble, ()) end function with_elevation_mask(obj::DOPComputer, arg0::ElevationMask) return jcall(obj, "withElevationMask", DOPComputer, (ElevationMask,), arg0) end function with_min_elevation(obj::DOPComputer, arg0::jdouble) return jcall(obj, "withMinElevation", DOPComputer, (jdouble,), arg0) end
\section{Linear Support Vector Classifier} \label{section:svc} Given $n$ training points, where each input $x_i$ has $m$ attributes, i.e., is of dimensionality $m$, and is in one of two classes $y_i=\pm1$, i.e., our training data is of the form: \begin{equation} \{(x_i,y_i), x_i\in\Re^m, y_i=\pm1, i=1, \dots, n\} \label{eq:svc_data} \end{equation} For simplicity we first assume that data are (not fully) linearly separable in the input space $x$, meaning that we can draw a line separating the two classes when $m=2$, a plane for $m=3$ and, more in general, a hyperplane for an arbitrary $m$. Support vectors are the examples closest to the separating hyperplane and the aim of support vector machines is to orientate this hyperplane in such a way as to be as far as possible from the closest members of both classes, i.e., we need to maximize this margin. This hyperplane is represented by the equation $w^T x + b=0$. So, we need to find $w$ and $b$ so that our training data can be described by: \begin{equation} \label{eq:svc_consts} \begin{aligned} & w^T x_i + b \geq +1 - \xi_i, \forall y_i=+1 \\ & w^T x_i + b \leq -1 + \xi_i, \forall y_i=-1 \\ & \xi_i \geq 0 \ \forall_i \end{aligned} \end{equation} where the positive slack variables $\xi_i$ are introduced to allow misclassified points. In this way data points on the incorrect side of the margin boundary will have a penalty that increases with the distance from it. These two equations can be combined into: \begin{equation} \label{eq:svc_const} \begin{aligned} & y_i (w^T x_i + b) \geq 1 - \xi_i \ \forall_i \\ & \xi_i\geq 0 \ \forall_i \end{aligned} \end{equation} The margin is equal to $\displaystyle \frac{1}{\| w \|}$ and maximizing it subject to the constraint in~\eqref{eq:svc_const} while as we are trying to reduce the number of misclassifications is equivalent to finding: \begin{equation} \label{eq:svc_obj} \begin{aligned} \min_{w,b,\xi} \quad & \| w \| + C \sum_{i=1}^n \xi_i \\ \text{subject to} \quad & y_i (w^T x_i + b) \geq 1 - \xi_i \ \forall_i \\ & \xi_i \geq 0 \ \forall_i \end{aligned} \end{equation} Minimizing $\| w \|$ is equivalent to minimizing $\displaystyle \frac{1}{2} \| w \|^2$, but in this form we will deal with a 1-strongly convex regularization term that has more desirable convergence properties. So we need to find: \begin{equation} \label{eq:quad_svc_obj} \begin{aligned} \min_{w,b,\xi} \quad & \frac{1}{2} \| w \|^2 + C \sum_{i=1}^n \xi_i \\ \text{subject to} \quad & y_i (w^T x_i + b) \geq 1 - \xi_i \ \forall_i \\ & \xi_i \geq 0 \ \forall_i \end{aligned} \end{equation} where the parameter $C$ controls the trade-off between the slack variable penalty and the size of the margin. \begin{figure}[h!] \centering \includegraphics[scale=0.6]{img/linear_dual_l1_svc_hyperplane} \caption{Linear SVC hyperplane} \label{fig:linear_dual_l1_svc_hyperplane} \end{figure} \pagebreak \subsection{Hinge loss} The \emph{hinge} loss is defined as: \begin{equation} \label{eq:hinge_loss1} \mathcal{L}_1 = \max(0, 1 - y (w^T x + b)) \end{equation} or, equivalently: \begin{equation} \label{eq:hinge_loss2} \mathcal{L}_1 = \begin{cases} 0 & \text{if} \ y (w^T x + b) \geq 1 \\ 1 - y (w^T x + b) & \text{otherwise} \\ \end{cases} \end{equation} and it is a nondifferentiable convex function due to its nonsmoothness in 1, but has a subgradient that is given by: \begin{equation} \label{eq:hinge_loss_der} \partial_w \mathcal{L}_1= \begin{cases} -y x & \text{if} \ y (w^T x + b) < 1 \\ 0 & \text{otherwise} \\ \end{cases} \end{equation} \subsubsection{Primal formulation} The general primal unconstrained formulation takes the form: \begin{equation} \label{eq:primal_svm} \min_{w,b} \frac{1}{2} \| w \|^2 + C \sum_{i=1}^n \mathcal{L}(w,b;x_i,y_i) \end{equation} where $\displaystyle \frac{1}{2} \| w \|^2$ is the \emph{regularization term} and $\mathcal{L}(w,b;x_i,y_i)$ is the \emph{loss function} associated with the observation $(x_i,y_i)$~\cite{piccialli2018nonlinear}. The quadratic optimization problem~\eqref{eq:quad_svc_obj} can be equivalently formulated as: \begin{equation} \label{eq:primal_l1_svc} \min_{w,b} \frac{1}{2} \| w \|^2 + C \sum_{i=1}^n \max(0, 1 - y_i (w^T x_i + b)) \end{equation} where we make use of the \emph{hinge} loss~\eqref{eq:hinge_loss1} or~\eqref{eq:hinge_loss2}. The above formulation penalizes slacks $\xi$ linearly and is called $\mathcal{L}_1$-SVC. \begin{figure}[h!] \centering \includegraphics[scale=0.4]{img/l1_svc_loss} \caption{Hinge loss with different optimization steps} \label{fig:l1_svc_loss} \end{figure} To simplify the notation and so also the design of the algorithms, the simplest approach to learn the bias term $b$ is that of including that into the \emph{regularization term}; so we can rewrite~\eqref{eq:primal_svm} as follows: \begin{equation} \label{eq:reg_bias_primal_svm1} \min_{w,b} \frac{1}{2} (\| w \|^2 + b^2) + C \sum_{i=1}^n \mathcal{L}(w,b;x_i,y_i) \end{equation} or, equivalently, by augmenting the weight vector $w$ with the bias term $b$ and each instance $x_i$ with an additional dimension, i.e., with constant value equal to 1: \begin{equation} \label{eq:reg_bias_primal_svm2} \begin{aligned} \min_{w} \quad & \frac{1}{2} \| \hat{w} \|^2 + C \sum_{i=1}^n \mathcal{L}(\hat{w};\hat{x}_i,y_i) \\ \text{where} \quad & \hat{w}^T = [w^T, b] \\ & \hat{x}_i^T = [x_i^T, 1] \end{aligned} \end{equation} with the advantages of having convex properties of the objective function useful for convergence analysis and the possibility to directly apply algorithms designed for models without the bias term. In the specific case of the $\mathcal{L}_1$-SVC the objective~\eqref{eq:primal_l1_svc} become: \begin{equation} \label{eq:reg_bias_primal_l1_svc} \min_{w,b} \frac{1}{2} (\| w \|^2 + b^2) + C \sum_{i=1}^n \max(0, 1 - y_i (w^T x_i + b)) \end{equation} Note that in terms of numerical optimization the formulation~\eqref{eq:primal_l1_svc} is not equivalent to~\eqref{eq:reg_bias_primal_l1_svc} since in the first one the bias term $b$ does not contribute to the \emph{regularization term}, so the SVM formulation is based on an unregularized bias term $b$, as highlighted by the \emph{statistical learning theory}. But, in machine learning sense, numerical experiments in~\cite{hsu2002simple} show that the accuracy does not vary much when the bias term $b$ is embedded into the weight vector $w$. \subsubsection{Wolfe dual formulation} To reformulate the~\eqref{eq:quad_svc_obj} as a \emph{Wolfe dual}, we need to allocate the Lagrange multipliers $\alpha_i, \mu_i \geq 0 \ \forall_i$: \begin{equation} \label{eq:svc_wolfe_dual} \max_{\alpha,\mu} \min_{w,b,\xi} \mathcal{W}(w,b,\xi,\alpha,\mu) = \frac{1}{2} \| w \|^2 + C \sum_{i=1}^n \xi_i-\sum_{i=1}^n \alpha_i(y_i(w^T x_i + b)-1+\xi_i)-\sum_{i=1}^n\mu_i\xi_i \end{equation} We wish to find the $w$, $b$ and $\xi_i$ which minimizes, and the $\alpha$ and $\mu$ which maximizes $\mathcal{W}$, provided $\alpha_i\geq 0, \mu_i \geq 0 \ \forall_i$. We can do this by differentiating $\mathcal{W}$ wrt $w$ and $b$ and setting the derivatives to 0: \begin{equation} \label{eq:svc_wolfe_der_w} \frac{\partial \mathcal{W}}{\partial w}=w-\sum_{i=1}^n \alpha_i y_i x_i \Rightarrow w=\sum_{i=1}^n \alpha_i y_i x_i \end{equation} \begin{equation} \label{eq:svc_wolfe_der_b} \frac{\partial \mathcal{W}}{\partial b}=-\sum_{i=1}^n \alpha_i y_i\Rightarrow\sum_{i=1}^n \alpha_i y_i=0 \end{equation} \begin{equation} \label{eq:svc_wolfe_der_xi} \frac{\partial \mathcal{W}}{\partial\xi_i}=0\Rightarrow C=\alpha_i+\mu_i \end{equation} Substituting~\eqref{eq:svc_wolfe_der_w} and~\eqref{eq:svc_wolfe_der_b} into~\eqref{eq:svc_wolfe_dual} together with $\mu_i\geq 0 \ \forall_i$, which implies that $\alpha\leq C$, gives a new formulation being dependent on $\alpha$. We therefore need to find: \begin{equation} \label{eq:svc_max_wolfe_dual} \begin{aligned} \max_{\alpha} \mathcal{W}(\alpha) &= \sum_{i=1}^n \alpha_i - \frac{1}{2}\sum_{i,j}\alpha_i\alpha_j y_i y_j \langle x_i, x_j \rangle \\ &= \sum_{i=1}^n \alpha_i - \frac{1}{2}\sum_{i,j}\alpha_i Q_{ij}\alpha_j \ \text{where} \ Q_{ij} = y_i y_j \langle x_i, x_j \rangle \\ &= \sum_{i=1}^n \alpha_i - \frac{1}{2}\alpha^T Q\alpha \ \text{subject to} \ 0\leq\alpha_i\leq C \ \forall_i, \sum_{i=1}^n \alpha_i y_i=0 \end{aligned} \end{equation} or, equivalently: \begin{equation} \label{eq:svc_min_wolfe_dual} \begin{aligned} \min_{\alpha} \quad & \frac{1}{2}\alpha^T Q\alpha+q^T\alpha \\ \text{subject to} \quad & 0\leq\alpha_i\leq C \ \forall_i \\ & y^T\alpha=0 \end{aligned} \end{equation} where $q^T = [1, \dots, 1]$. By solving~\eqref{eq:svc_min_wolfe_dual} we will know $\alpha$ and, from~\eqref{eq:svc_wolfe_der_w}, we will get $w$, so we need to calculate $b$. We know that any data point satisfying~\eqref{eq:svc_wolfe_der_b} which is a support vector $x_s$ will have the form: \begin{equation} \label{eq:svc_sv_const1} y_s(w^T x_s + b)=1 \end{equation} and, by substituting in~\eqref{eq:svc_wolfe_der_w}, we get: \begin{equation} \label{eq:svc_sv_const2} y_s\big(\sum_{m\in S}\alpha_m y_m \langle x_m, x_s \rangle +b\big)=1 \end{equation} where $s$ denotes the set of indices of the support vectors and is determined by finding the indices $i$ where $\alpha_i>0$, i.e., nonzero Lagrange multipliers. Multiplying through by $y_s$ and then using $y_s^2=1$ from~\eqref{eq:svc_consts}: \begin{equation} \label{eq:svc_sv_squared_const2} y_s^2\big(\sum_{m\in S}\alpha_m y_m \langle x_m, x_s \rangle +b\big)=y_s \end{equation} \begin{equation} \label{eq:svc_b} b=y_s-\sum_{m\in S}\alpha_m y_m \langle x_m, x_s \rangle \end{equation} Instead of using an arbitrary support vector $x_s$, it is better to take an average over all of the support vectors in $S$: \begin{equation} \label{eq:svc_b_avg} b=\frac{1}{N_s}\sum_{s\in S} y_s-\sum_{m\in S}\alpha_m y_m \langle x_m, x_s \rangle \end{equation} We now have the variables $w$ and $b$ that define our separating hyperplane's optimal orientation and hence our support vector machine. Each new point $x'$ is classified by evaluating: \begin{equation} \label{eq:svc_pred} y'=\operatorname{sign}\big(\sum_{i=1}^n\alpha_i y_i\langle x_i, x' \rangle+b\big) \end{equation} From~\eqref{eq:svc_min_wolfe_dual} we can notice that the equality constraint $y^T \alpha = 0$ arises form the stationarity condition $\partial_{{b}} \mathcal{W}=0$. So, again, for simplicity, we can again consider the bias term $b$ embedded into the weight vector. We report below the box-constrained dual formulation~\cite{hsu2002simple} that arises from the primal~\eqref{eq:reg_bias_primal_svm1} or~\eqref{eq:reg_bias_primal_svm2} where the bias term $b$ is embedded into the weight vector $w$: \begin{equation} \label{eq:svc_min_bcqp_wolf_dual} \begin{aligned} \min_{\alpha} \quad & \frac{1}{2} \alpha^T (Q + yy^T)\alpha+q^T\alpha \\ \text{subject to} \quad & 0\leq\alpha_i\leq C \ \forall_i \end{aligned} \end{equation} \subsubsection{Lagrangian dual formulation} In order to relax the constraints in the \emph{Wolfe dual} formulation~\eqref{eq:svc_min_wolfe_dual} we define the problem as a \emph{Lagrangian dual} relaxation by embedding them into objective function, so we need to allocate the Lagrange multipliers $\mu$ and $\lambda_+, \lambda_- \geq 0$: \begin{equation} \label{eq:l1_svc_lagrangian_dual} \begin{aligned} \max_{\mu,\lambda_+,\lambda_-} \min_{\alpha} \mathcal{L}(\alpha,\mu,\lambda_+,\lambda_-) &= \frac{1}{2} \alpha^T Q\alpha+q^T\alpha + \mu^T (y^T \alpha) + \lambda_+^T (ub - \alpha) - \lambda_-^T \alpha \\ &= \frac{1}{2} \alpha^T Q\alpha + (q + \mu y^T + \lambda_+ - \lambda_-)^T \alpha + \lambda_+^T ub \\ \text{subject to} \quad & \,\, \lambda_+, \lambda_- \geq 0 \end{aligned} \end{equation} where the upper bound $ub^T = [C, \dots, C]$. Taking the derivative of the Lagrangian $\mathcal{L}$ wrt $\alpha$ and settings it to 0 gives: \begin{equation} \label{eq:svc_lagrangian_der_a} \frac{\partial \mathcal{L}}{\partial \alpha}=0\Rightarrow Q \alpha + (q + \mu y^T + \lambda_+ - \lambda_-) = 0 \end{equation} With $\alpha$ optimal solution of the linear system: \begin{equation} \label{eq:l1_svc_lagrangian_sol} Q \alpha = - (q + \mu y^T + \lambda_+ - \lambda_-) \end{equation} the gradients wrt $\mu$, $\lambda_+$ and $\lambda_-$ are: \begin{equation} \label{eq:svc_lagrangian_der_mu} \frac{\partial \mathcal{L}}{\partial \mu}=-y \alpha \end{equation} \begin{equation} \label{eq:svc_lagrangian_der_lp} \frac{\partial \mathcal{L}}{\partial \lambda_+}=\alpha - ub \end{equation} \begin{equation} \label{eq:svc_lagrangian_der_lm} \frac{\partial \mathcal{L}}{\partial \lambda_-}=-\alpha \end{equation} From~\eqref{eq:svc_min_wolfe_dual} we can notice that the equality constraint $y^T \alpha = 0$ arises form the stationarity condition $\partial_{{b}} \mathcal{W}=0$. So, again, for simplicity, we can again consider the bias term $b$ embedded into the weight vector. In this way the dimensionality of~\eqref{eq:l1_svc_lagrangian_dual} is reduced by removing the multipliers $\mu$ which was allocated to control the equality constraint $y^T \alpha=0$, so we will end up solving exactly the problem~\eqref{eq:svc_min_bcqp_wolf_dual}. \begin{equation} \label{eq:l1_svc_bcqp_lagrangian_dual} \begin{aligned} \max_{\lambda_+,\lambda_-} \min_{\alpha} \mathcal{L}(\alpha,\lambda_+,\lambda_-) &= \frac{1}{2} \alpha^T (Q + yy^T)\alpha+q^T\alpha + \lambda_+^T (ub - \alpha) - \lambda_-^T \alpha \\ &= \frac{1}{2} \alpha^T (Q + yy^T)\alpha + (q + \lambda_+ - \lambda_-)^T \alpha + \lambda_+^T ub \\ \text{subject to} \quad & \,\, \lambda_+, \lambda_- \geq 0 \end{aligned} \end{equation} where, again, the upper bound $ub^T = [C, \dots, C]$. Now, taking the derivative of the Lagrangian $\mathcal{L}$ wrt $\alpha$ and settings it to 0 gives: \begin{equation} \label{eq:l1_svc_bcqp_lagrangian_der_a} \frac{\partial \mathcal{L}}{\partial \alpha}=0\Rightarrow (Q + yy^T) \alpha + (q + \lambda_+ - \lambda_-) = 0 \end{equation} With $\alpha$ optimal solution of the linear system: \begin{equation} \label{eq:l1_svc_bcqp_lagrangian_sol} (Q + yy^T) \alpha = - (q + \lambda_+ - \lambda_-) \end{equation} the gradients wrt $\lambda_+$ and $\lambda_-$ are: \begin{equation} \label{eq:l1_svc_bcqp_lagrangian_der_lp} \frac{\partial \mathcal{L}}{\partial \lambda_+}=\alpha - ub \end{equation} \begin{equation} \label{eq:l1_svc_bcqp_lagrangian_der_lm} \frac{\partial \mathcal{L}}{\partial \lambda_-}=-\alpha \end{equation} \bigskip Note that since the Hessian matrix $Q$ of the $\mathcal{L}_1$-SVC is not strictly positive definite, i.e., the Lagrangian function is not strictly convex since it will be linear along the eigenvectors correspondent to the null eigenvalues and so it will be unbounded below, the Lagrangian dual relaxation, i.e.,~\ref{eq:l1_svc_lagrangian_sol} and~\ref{eq:l1_svc_bcqp_lagrangian_sol}, will be nondifferentiable, so it will have infinite solutions and for each of them it will have a different subgradient. In order to compute an approximation of the gradient, we will choose $\alpha$ in such a way as the one that minimizes the 2-norm since it is good almost like the gradient: \begin{equation} \label{eq:svc_lagrangian_krylov_sol} \min_{\alpha_n \in K_n(Q, b)} \| Q \alpha_n - b \| \end{equation} Since we are dealing with a symmetric system we will choose a well-known Krylov method that performs the Lanczos iterate, i.e., symmetric Arnoldi iterate, called \emph{minres}, i.e., symmetric \emph{gmres}, to compute the vector $\alpha_n$ that minimizes the norm of the residual $r_n = Q \alpha_n - b$ among all vectors in $K_n(Q, b) = span(b, Qb, Q^2b, \dots, Q^{n-1}b)$. \bigskip Since the linear algebra methods in the ML context are crucial and also in order to deal with a per-iteration cost equals to the other algorithms described later to provide a coherent comparison of all at the end, we will solve it with a primal-dual optimization method and we modify its definition by adding a strictly convex augmentation term, i.e., a penalty term, in order to improve the actual convergence of the algorithms. So, if we consider a general quadratic optimization problem subject to linear constraints, i.e., equality and inequality constraints, defined as: \begin{equation} \begin{aligned} \min_{\alpha} \quad & \frac{1}{2} \alpha^T Q \alpha + q^T \alpha \\ \textrm{subject to} \quad & A \alpha = b \\ & G \alpha \leq h \\ & lb \leq \alpha \leq ub \end{aligned} \end{equation} or, equivalently: \begin{equation} \begin{aligned} \min_{\alpha} \quad & \frac{1}{2} \alpha^T Q \alpha + q^T \alpha \\ \textrm{subject to} \quad & A \alpha = b \\ & \hat{G} \alpha \leq \hat{h} \end{aligned} \end{equation} where $\hat{G} = \begin{bmatrix} G \\ -I \\ I \end{bmatrix}$ and $\hat{h} = \begin{bmatrix} h & -lb & ub \end{bmatrix}$; we give the following \emph{augmented Lagrangian dual}: \begin{equation} \label{eq:svc_gen_aug_lagrangian_dual} \begin{aligned} \max_{\mu,\lambda} \min_{\alpha} \quad & \frac{1}{2} \alpha^T Q \alpha + q^T \alpha + \mu^T (A \alpha - b) + \lambda^T (\hat{G} \alpha - \hat{h}) + \frac{\rho}{2} \| A \alpha - b \|^2 + \frac{\rho}{2} \| \hat{G} \alpha - \hat{h} \|^2 \\ \text{subject to} \quad & \lambda \geq 0 \end{aligned} \end{equation} with $\rho > 0$. \bigskip According to this definition, we change the formulation~\ref{eq:l1_svc_lagrangian_dual} as: \begin{equation} \label{eq:l1_svc_aug_lagrangian_dual} \begin{aligned} \max_{\mu,\lambda} \min_{\alpha} \mathcal{L}(\alpha,\mu,\lambda) &= \frac{1}{2} \alpha^T Q\alpha+q^T\alpha + \mu^T (y^T \alpha) + \lambda^T (\hat{G} \alpha - \hat{h}) + \frac{\rho}{2} \| y^T \alpha \|^2 + \frac{\rho}{2} \| \hat{G} \alpha - \hat{h} \|^2 \\ \text{subject to} \quad & \,\, \lambda \geq 0 \end{aligned} \end{equation} and the formulation~\ref{eq:l1_svc_bcqp_lagrangian_dual} as: \begin{equation} \label{eq:l1_svc_bcqp_aug_lagrangian_dual} \begin{aligned} \max_{\lambda} \min_{\alpha} \mathcal{L}(\alpha,\lambda) &= \frac{1}{2} \alpha^T (Q + yy^T) \alpha + q^T \alpha + \lambda^T (\hat{G} \alpha - \hat{h}) + \frac{\rho}{2} \| \hat{G} \alpha - \hat{h} \|^2 \\ \text{subject to} \quad & \,\, \lambda \geq 0 \end{aligned} \end{equation} where $\hat{G} = \begin{bmatrix} -I \\ I \end{bmatrix}$ and $\hat{h} = \begin{bmatrix} -lb & ub \end{bmatrix}$ with $lb^T = [0, \dots, 0]$, $ub^T = [C, \dots, C]$ and $\rho > 0$. \pagebreak \subsection{Squared hinge loss} The \emph{squared hinge} loss is defined as: \begin{equation} \label{eq:squared_hinge_loss2} \mathcal{L}_2 = \max(0, 1 - y (w^T x + b))^2 \end{equation} or, equivalently: \begin{equation} \label{eq:squared_hinge_loss1} \mathcal{L}_2 = \begin{cases} 0 & \text{if} \ y (w^T x + b) \geq 1 \\ (1 - y (w^T x + b))^2 & \text{otherwise} \\ \end{cases} \end{equation} It is a strictly convex function and its gradient is given by: \begin{equation} \label{eq:squared_hinge_loss_der} \nabla_w \mathcal{L}_2= \begin{cases} - 2 \max(0, 1 - y (w^T x + b)) y x & \text{if} \ y (w^T x + b) < 1 \\ 0 & \text{otherwise} \\ \end{cases} \end{equation} \subsubsection{Primal formulation} Since smoothed versions of objective functions may be preferred for optimization, we can reformulate~\eqref{eq:primal_l1_svc} as: \begin{equation} \label{eq:primal_l2_svc} \min_{w,b} \frac{1}{2} \| w \|^2 + C \sum_{i=1}^n \max(0, 1 - y_i (w^T x_i + b))^2 \end{equation} where we make use of the \emph{squared hinge} loss that quadratically penalized slacks $\xi$ and is called $\mathcal{L}_2$-SVC. The $\mathcal{L}_2$-SVC objective~\eqref{eq:primal_l2_svc} can be rewritten in form~\eqref{eq:reg_bias_primal_svm1} or~\eqref{eq:reg_bias_primal_svm2} as: \begin{equation} \label{eq:reg_bias_primal_l2_svc} \min_{w,b} \frac{1}{2} (\| w \|^2 + b^2) + C \sum_{i=1}^n \max(0, 1 - y_i (w^T x_i + b))^2 \end{equation} \begin{figure}[h!] \centering \includegraphics[scale=0.4]{img/l2_svc_loss} \caption{Squared hinge loss with different optimization steps} \label{fig:l2_svc_loss} \end{figure} \subsubsection{Wolfe dual formulation} As done for the $\mathcal{L}_1$-SVC we can derive the \emph{Wolfe dual} formulation of the $\mathcal{L}_2$-SVC by obtaining: \begin{equation} \label{eq:wolfe_dual_l2_svc} \begin{aligned} \min_{\alpha} \quad & \frac{1}{2}\alpha^T (Q + D)\alpha+q^T\alpha \\ \text{subject to} \quad & \alpha_i\geq 0 \ \forall_i \\ & y^T\alpha=0 \end{aligned} \end{equation} or, alternatively, with the regularized bias term by obtaining: \begin{equation} \label{eq:reg_bias_wolfe_dual_l2_svc} \begin{aligned} \min_{\alpha} \quad & \frac{1}{2}\alpha^T (Q + yy^T + D) \alpha + q^T \alpha \\ \text{subject to} \quad & \alpha_i \geq 0 \ \forall_i \end{aligned} \end{equation} where the diagonal matrix $\displaystyle D_{ii} = \frac{1}{2C} \ \forall_i$. \subsubsection{Lagrangian dual formulation} In order to relax the constraints in the $\mathcal{L}_2$-SVC \emph{Wolfe dual} formulation~\eqref{eq:wolfe_dual_l2_svc} we define the problem as a \emph{Lagrangian dual} relaxation by embedding them into objective function, so we need to allocate the Lagrange multipliers $\mu$ and $\lambda \geq 0$: \begin{equation} \label{eq:l2_svc_lagrangian_dual} \begin{aligned} \max_{\mu,\lambda} \min_{\alpha} \mathcal{L}(\alpha,\mu,\lambda) &= \frac{1}{2} \alpha^T (Q+D)\alpha+q^T\alpha + \mu^T (y^T \alpha) - \lambda^T \alpha \\ &= \frac{1}{2} \alpha^T (Q+D)\alpha + (q + \mu y^T - \lambda)^T \alpha \\ \text{subject to} \quad & \,\, \lambda \geq 0 \end{aligned} \end{equation} Taking the derivative of the Lagrangian $\mathcal{L}$ wrt $\alpha$ and settings it to 0 gives: \begin{equation} \label{eq:l2_svc_lagrangian_der_a} \frac{\partial \mathcal{L}}{\partial \alpha}=0\Rightarrow (Q+D) \alpha + (q + \mu y^T - \lambda) = 0 \end{equation} With $\alpha$ optimal solution of the linear system: \begin{equation} \label{eq:l2_svc_lagrangian_sol} (Q+D) \alpha = - (q + \mu y^T - \lambda) \end{equation} the gradients wrt $\mu$ and $\lambda$ are: \begin{equation} \label{eq:l2_svc_lagrangian_der_mu} \frac{\partial \mathcal{L}}{\partial \mu}=-y \alpha \end{equation} \begin{equation} \label{eq:l2_svc_lagrangian_der_lambda} \frac{\partial \mathcal{L}}{\partial \lambda}=-\alpha \end{equation} From~\eqref{eq:svc_min_wolfe_dual} we can notice that the equality constraint $y^T \alpha = 0$ arises form the stationarity condition $\partial_{{b}} \mathcal{W}=0$. So, again, for simplicity, we can again consider the bias term $b$ embedded into the weight vector. In this way the dimensionality of~\eqref{eq:l2_svc_lagrangian_dual} is reduced by removing the multipliers $\mu$ which was allocated to control the equality constraint $y^T \alpha=0$, so we will end up solving exactly the problem~\eqref{eq:reg_bias_wolfe_dual_l2_svc}. \begin{equation} \label{eq:l2_svc_lb_lagrangian_dual} \begin{aligned} \max_{\lambda} \min_{\alpha} \mathcal{L}(\alpha,\lambda) &= \frac{1}{2} \alpha^T (Q + yy^T + D) \alpha+q^T\alpha - \lambda^T \alpha \\ &= \frac{1}{2} \alpha^T (Q + yy^T + D) \alpha + (q - \lambda)^T \alpha \\ \text{subject to} \quad & \,\, \lambda \geq 0 \end{aligned} \end{equation} Now, taking the derivative of the Lagrangian $\mathcal{L}$ wrt $\alpha$ and settings it to 0 gives: \begin{equation} \label{eq:l2_svc_lb_lagrangian_der_a} \frac{\partial \mathcal{L}}{\partial \alpha}=0\Rightarrow (Q + yy^T + D) \alpha + (q - \lambda) = 0 \end{equation} With $\alpha$ optimal solution of the linear system: \begin{equation} \label{eq:l2_svc_lb_lagrangian_sol} (Q + yy^T + D) \alpha = - (q - \lambda) \end{equation} the gradient wrt $\lambda$ is: \begin{equation} \label{eq:l2_svc_lb_lagrangian_der_l} \frac{\partial \mathcal{L}}{\partial \lambda}=-\alpha \end{equation} \bigskip Note that since the Hessian matrix $Q$ of the $\mathcal{L}_2$-SVC is symmetric and strictly positive definite, we can find the unique solution of the Lagrangian dual relaxation, i.e.,~\ref{eq:l2_svc_lagrangian_sol} and~\ref{eq:l2_svc_lb_lagrangian_sol}, by solving the system with the Cholesky factorization. \bigskip Since the linear algebra methods in the ML context are crucial and also in order to deal with a per-iteration cost equals to the other algorithms described later to provide a coherent comparison of all at the end, we will solve it with a primal-dual optimization method and we modify its definition by adding a strictly convex augmentation term, i.e., a penalty term, in order to improve the actual convergence of the algorithms. So, if we consider a general quadratic optimization problem subject to linear constraints, i.e., equality and inequality constraints, defined as: \begin{equation} \begin{aligned} \min_{\alpha} \quad & \frac{1}{2} \alpha^T Q \alpha + q^T \alpha \\ \textrm{subject to} \quad & A \alpha = b \\ & G \alpha \leq h \\ & lb \leq \alpha \leq ub \end{aligned} \end{equation} or, equivalently: \begin{equation} \begin{aligned} \min_{\alpha} \quad & \frac{1}{2} \alpha^T Q \alpha + q^T \alpha \\ \textrm{subject to} \quad & A \alpha = b \\ & \hat{G} \alpha \leq \hat{h} \end{aligned} \end{equation} where $\hat{G} = \begin{bmatrix} G \\ -I \\ I \end{bmatrix}$ and $\hat{h} = \begin{bmatrix} h & -lb & ub \end{bmatrix}$; we give the following \emph{augmented Lagrangian dual}: \begin{equation} \label{eq:l2_svc_gen_aug_lagrangian_dual} \begin{aligned} \max_{\mu,\lambda} \min_{\alpha} \quad & \frac{1}{2} \alpha^T Q \alpha + q^T \alpha + \mu^T (A \alpha - b) + \lambda^T (\hat{G} \alpha - \hat{h}) + \frac{\rho}{2} \| A \alpha - b \|^2 + \frac{\rho}{2} \| \hat{G} \alpha - \hat{h} \|^2 \\ \text{subject to} \quad & \lambda \geq 0 \end{aligned} \end{equation} with $\rho > 0$. \bigskip According to this definition, we change the formulation~\ref{eq:l2_svc_lagrangian_dual} as: \begin{equation} \label{eq:l2_svc_aug_lagrangian_dual} \begin{aligned} \max_{\mu,\lambda} \min_{\alpha} \mathcal{L}(\alpha,\mu,\lambda) &= \frac{1}{2} \alpha^T (Q + D) \alpha+q^T\alpha + \mu^T (y^T \alpha) + \lambda^T (\hat{G} \alpha - \hat{h}) + \frac{\rho}{2} \| y^T \alpha \|^2 + \frac{\rho}{2} \| \hat{G} \alpha - \hat{h} \|^2 \\ \text{subject to} \quad & \,\, \lambda \geq 0 \end{aligned} \end{equation} and the formulation~\ref{eq:l2_svc_lb_lagrangian_dual} as: \begin{equation} \label{eq:l2_svc_lb_aug_lagrangian_dual} \begin{aligned} \max_{\lambda} \min_{\alpha} \mathcal{L}(\alpha,\lambda) &= \frac{1}{2} \alpha^T (Q + yy^T + D) \alpha + q^T \alpha + \lambda^T (\hat{G} \alpha - \hat{h}) + \frac{\rho}{2} \| \hat{G} \alpha - \hat{h} \|^2 \\ \text{subject to} \quad & \,\, \lambda \geq 0 \end{aligned} \end{equation} where $\hat{G} = \begin{bmatrix} -I \end{bmatrix}$ and $\hat{h} = \begin{bmatrix} -lb \end{bmatrix}$ with $lb^T = [0, \dots, 0]$ and $\rho > 0$.
""" Cyberdyne Systems Series 800 Model 101 Infiltration Unit - Terminator T800. Logic for the CSM101 T800 infiltration unit. Provides access to visual cortex and Heads-Up-Display (HUD) analysis. * TerminatorVision: The T800 Visual cortex. * HeadUpDisplay: The HUD analysis. """ import cv2 # OpenCV module. import numpy as np from playsound import playsound import time from threading import Thread class TerminatorVision: """ CSM 101 Terminator T800 Visual Input. Receive and process data from Terminator's visual cortext. Input is received and processed asynchronously for improved performance. Throws exceptions if errors occur. """ def __init__(self, feed: int, shape: tuple): """ Construct Terminator visual input feed. """ self.feed: int = feed self.shape = tuple(int(x) for x in shape) # Open camera. self.cam = cv2.VideoCapture(self.feed) if not self.cam.isOpened(): raise Exception(f"Accessing camera #{self.feed} error.") # Work out processing metrics from sample video feed frame. (self.ret, self.frame) = self.cam.read() if not self.ret: raise Exception( f"Reading initial frame from camera #{self.feed} error.") # Create empty channel to merge with red channel. self.ZEROS = np.zeros(self.frame[:, :, 2].shape, dtype="uint8") # Capture the first image to ensure we have one before thread starts. self.__capture() # Start background thread to read camera asynchronously (better performance). self.stopping = False Thread(target=self.__update, args=(), daemon = True).start() def __update(self): """ Update with the latest camera image. Runs in the background on a separate thread for additional performance. """ while not self.stopping and self.ret: self.__capture() self.cam.release() def __capture(self): """ Capture and process a frame from visual input feed. """ (camRet, camFrame) = self.cam.read() if camRet: camFrame = cv2.merge([self.ZEROS, self.ZEROS, camFrame[:, :, 2]]) if camFrame.shape[:2] != self.shape[:2]: camFrame = self.__resize(camFrame) (self.ret, self.frame) = (camRet, camFrame) def __resize(self, image): """ Resize (and letterbox) the image to the required dimensions. """ (reqH, reqW) = self.shape[:2] (imgH, imgW) = image.shape[:2] ratio = reqW / float(imgW) dim = (reqW, int(imgH * ratio)) # Resize the image resized = cv2.resize(image, dim) (imgH, imgW) = resized.shape[:2] # Letterbox the image y = (imgH - reqH) / 2 return resized[int(y):int(y+reqH), 0:reqW] def read(self): """ Return the last processed image from visual input feed. """ if not self.ret: raise Exception(f"Unable to read frame from camera {self.feed}") else: return self.frame def release(self): """ Release the visual cortex camera as part of a shutdown process. """ self.stopping = True def __del__(self): """ Destroy the T800 vision object and release the camera. """ self.release() class HeadsUpDisplay: """ CSM 101 Terminator T800 Heads-Up Display (HUD). Receive and process HUD analysis data from T800 Neural Net Processor. """ def __init__(self, feed: str, sound: str): """ Construct T800 HUD Feed. """ self.feed = feed self.sound = sound self.hud = cv2.VideoCapture(feed) if not self.hud.isOpened(): raise Exception(f"Accessing HUD analysis feed {self.feed} error.") self.FPS = self.hud.get(cv2.CAP_PROP_FPS) self.frameNumber = 0 # Next frame number of HUD. self.baseNanos = None # Base time for relative time calculations (None => set when read) self.timeMillis = 0 # Relative time of last frame read. def read(self): """ Return correct frame of analysis from HUD. Will return the current frame of analysis or the next frame of analysis. Will skip ahead to keep analysis feed in-sync. Returns: A frame of analysis to match the current time. """ if self.baseNanos is None: playsound(self.sound, block=False) # Base for working out relative time in milliseconds. self.baseNanos = time.time_ns() # Handle delays to keep video & sound in step. # Time relative to beginning of loop. self.timeMillis = (time.time_ns() - self.baseNanos) // 1000000 # Calc frame required from relative time and FPS. frameRequired = self.timeMillis * self.FPS // 1000 # Skip to sync any lag. if self.frameNumber < frameRequired: self.__skip(frameRequired) if self.frameNumber == frameRequired: # Read HUD frame if we are ready for it. (self.ret, self.frame) = self.hud.read() if self.ret: self.frameNumber += 1 elif self.frameNumber == 0 and not self.ret: raise Exception( f"Failed to read initial frame {self.frameNumber} from {self.src}.") else: # If not read frame 1+, loop and try again. self.__loop() self.read() return self.frame def __skip(self, frameRequired): """ Skip frames to catch up on lag. """ print(f"@{self.timeMillis}: skip {self.frameNumber} to {frameRequired}") if not self.hud.set(cv2.CAP_PROP_POS_FRAMES, frameRequired): raise Exception( f"Failed to skip from {self.frameNumber} to {frameRequired}.") self.frameNumber = frameRequired def __loop(self): """ Loop the HUD feed. """ self.frameNumber = 0 if not self.hud.set(cv2.CAP_PROP_POS_FRAMES, self.frameNumber): raise Exception(f"Failed to loop to {self.frameNumber}.") self.baseNanos = None # Force read to restart time. self.timeMillis = 0 def get_time(self): """ Return relative time in ms since start of HUD feed. """ return self.timeMillis def get_shape(self): """ Return shape (width, height) of HUD frames. """ return (int(self.hud.get(cv2.CAP_PROP_FRAME_HEIGHT)), int(self.hud.get(cv2.CAP_PROP_FRAME_WIDTH))) def release(self): """ Release the HUD analysis feed as part of a shutdown process. """ self.stopping = True def __del__(self): """ Destroy the T800 HUD object and release the analysis feed. """ self.release()
module Collections.Util.Erased ||| A data type which wraps an erased value, so that it can be returned by a function for use in ||| another erased context. public export data Erased : (0 t : Type) -> Type where MkErased : (0 x : t) -> Erased t
-- ---------------------------------------------------------------------- -- The Agda Descriptor Library -- -- (Open) Descriptors -- ---------------------------------------------------------------------- module Data.Desc where open import Data.List using (List; []; _∷_) open import Data.List.Relation.Unary.All using (All; []; _∷_) open import Data.List.Relation.Unary.Any using (here; there) open import Data.List.Membership.Propositional using (_∈_) open import Data.Product using (Σ; _,_) open import Data.Var using (_-Scoped[_]; Var; get; zero; suc; tabulate) open import Data.Unit.Polymorphic using (⊤; tt) open import Level using (Level; 0ℓ; _⊔_) open import Relation.Unary using (IUniversal; _⇒_) private variable A : Set 1ℓ : Level 1ℓ = Level.suc 0ℓ -- ---------------------------------------------------------------------- -- Definition -- -- An open description is a open dependent type theory. -- Our theoretic model is described by: -- -- Metatheoretic terms: -- -- Agda sets A, B ∷= ... -- Agda values x, y ∷= ... -- -- Open object terms: -- -- kinds κ ∷= Set | Π A κ -- types T ∷= a | T x | Π A T | T ⟶ T -- -- A descriptor is a set of well-kinded constructor types. data Kind : Set₁ where `Set₀ : Kind `Π : (A : Set) → (A → Kind) → Kind private variable κ κ′ : Kind Γ : List Kind B : A → Kind infixr 6 _⟶_ data Type : Kind -Scoped[ 1ℓ ] where `_ : ∀[ Var κ ⇒ Type κ ] _·_ : Type (`Π A B) Γ → (a : A) → Type (B a) Γ `Π : (A : Set) → (A → Type `Set₀ Γ) → Type `Set₀ Γ _⟶_ : Type `Set₀ Γ → Type `Set₀ Γ → Type `Set₀ Γ mutual data Pos : Type κ Γ → Set where `_ : ∀ (x : Var κ Γ) -- ---------------- → Pos (` x) _·_ : ∀ {T : Type (`Π A B) Γ} → Pos T → (a : A) -- ------------------------ → Pos (T · a) `Π : (A : Set) {T : A → Type `Set₀ Γ} → ((a : A) → Pos (T a)) -- -------------------------------- → Pos (`Π A T) _⟶_ : ∀ {T T′ : Type `Set₀ Γ} → Neg T → Pos T′ -- -------------------------- → Pos (T ⟶ T′) data Neg : Type κ Γ → Set where _·_ : ∀ {T : Type (`Π A B) Γ} → Neg T → (a : A) -- ------------------------ → Neg (T · a) `Π : (A : Set) {T : A → Type `Set₀ Γ} → ((a : A) → Neg (T a)) -- -------------------------------- → Neg (`Π A T) _⟶_ : ∀ {T T′ : Type `Set₀ Γ} → Pos T → Neg T′ -- -------------------------- → Neg (T ⟶ T′) data StrictPos : Type κ Γ → Set where `_ : ∀ (x : Var κ Γ) -- ---------------- → StrictPos (` x) _·_ : ∀ {T : Type (`Π A B) Γ} → StrictPos T → (a : A) -- ------------------------ → StrictPos (T · a) `Π : (A : Set) {T : A → Type `Set₀ Γ} → ((a : A) → StrictPos (T a)) -- -------------------------------- → StrictPos (`Π A T) data Con : Type κ Γ → Set where `_ : ∀ (x : Var κ Γ) -- ---------------- → Con (` x) _·_ : ∀ {T : Type (`Π A B) Γ} → Con T → (a : A) -- ------------------------ → Con (T · a) `Π : (A : Set) {T : A → Type `Set₀ Γ} → ((a : A) → Con (T a)) -- -------------------------------- → Con (`Π A T) _⟶_ : ∀ {T T′ : Type `Set₀ Γ} → StrictPos T → Con T′ -- -------------------------- → Con (T ⟶ T′) data Constr : Kind -Scoped[ 1ℓ ] where ! : {T : Type κ Γ} → Con T → Constr κ Γ ++⇒C : ∀{T : Type κ Γ} → StrictPos T → Con T ++⇒C (` x) = ` x ++⇒C (P · a) = ++⇒C P · a ++⇒C (`Π A P) = `Π A (λ a → ++⇒C (P a)) Desc : List Kind → Set₁ Desc Γ = List (Constr `Set₀ Γ) -- ---------------------------------------------------------------------- -- Interpretation lift⟦_⟧ᴷ : Kind → (ℓ : Level) → Set (Level.suc ℓ) lift⟦ `Set₀ ⟧ᴷ ℓ = Set ℓ lift⟦ `Π A κ ⟧ᴷ ℓ = (a : A) → lift⟦ κ a ⟧ᴷ ℓ -- Lifting of lift⟦_⟧ᴷ to a context lift⟪_⟫ᴷ : List Kind → (ℓ : Level) → Set (Level.suc ℓ) lift⟪ Γ ⟫ᴷ ℓ = All (λ κ → lift⟦ κ ⟧ᴷ ℓ) Γ ⟦_⟧ᴷ : Kind → Set₁ ⟦ `Set₀ ⟧ᴷ = Set ⟦ `Π A κ ⟧ᴷ = (a : A) → ⟦ κ a ⟧ᴷ ⟪_⟫ᴷ : List Kind → Set₁ ⟪ Γ ⟫ᴷ = All ⟦_⟧ᴷ Γ -- ---------------------------------------------------------------------- -- Fixpoint -- -- To define the fixed point, we're looking for a fixpoint of the form: -- μ : Desc Γ → ⟪ Γ ⟫ᴷ -- -- To consider the interpretation of constructors and type formers, -- we first describe the terms formed by constructors and -- positive types: -- -- constructor terms c ∷= Constrᵢ | c · a | c · p private variable C : Constr `Set₀ Γ D : Desc Γ data Term : Constr `Set₀ Γ -Scoped[ 1ℓ ] where `Constr : ∀[ Var C ⇒ Term C ] _·_ : ∀ {A} {T : A → Type `Set₀ Γ} {C : (a : A) → Con (T a)} → Term (! (`Π A C)) D → (a : A) → Term (! (C a)) D _•_ : ∀ {T T′ : Type `Set₀ Γ} {P : StrictPos T} {C : Con T′} → Term (! (P ⟶ C)) D → Term (! (++⇒C P)) D → Term (! C) D μᵏ : Constr κ Γ → Desc Γ → lift⟦ κ ⟧ᴷ 1ℓ μᵏ {κ = `Set₀} C D = Term C D μᵏ {κ = `Π _ _} (! C) D = λ a → μᵏ (! (C · a)) D μᴰ : Desc Γ → lift⟪ Γ ⟫ᴷ 1ℓ μᴰ D = tabulate λ x → μᵏ (! (` x)) D -- ---------------------------------------------------------------------- -- Examples ℕᴰ : Desc (`Set₀ ∷ []) ℕᴰ = ! (` zero) ∷ ! ((` zero) ⟶ (` zero)) ∷ [] `ℕ : Set₁ `ℕ = get zero (μᴰ ℕᴰ) pattern `zero = `Constr zero pattern `suc n = `Constr (suc zero) • n _ : `ℕ _ = `suc (`suc `zero)
[GOAL] α : Type u_1 inst✝² : CanonicallyLinearOrderedSemifield α inst✝¹ : Sub α inst✝ : OrderedSub α a b c : α ⊢ (a - b) / c = a / c - b / c [PROOFSTEP] simp_rw [div_eq_mul_inv, tsub_mul]
We manage to collect kids school books of various kinds and conditions. If a book is in no shape to sell but is festooned with character, it is kept in the archives. If a book is pristine but so awesome it couldn't possibly be let go, it is kept in the archives. The first book we'll look at is Magic Letters, a psychedelic romp through diverse style changes, watercolour, paper cut-out, clay illustration, etc. On a radically different note, Let's Learn To Spell is a staid grammar book, replete with exercises on constructing sentences and all that. Why we feature it here is for the arcane quality of it's symbols and the obvious connection between spelling words and casting spells (magic letters!). Also, some kid went to town on it and learned to spell. This is a small fragment of our collection. Stay tuned for more thematic uploads. We are thrilled to have the gorgeous silkscreened prints of Todd Stewart aka bree,ree framed and on our walls for the month of March.
So after everything the New England Patriots have been threw with Randy Moss, its clear it was true love after all. Well at least on Randy’s part. While being interviewed he said he loves New England and wants to play for them again.
# ...................................................................................... # ......................... Cvičení 8. Výběrové charakteristiky......................... # ..................................... Michal Béreš.................................... # ...................................................................................... # Nezobrazuje-li se vám text korektně, nastavte File \ Reopen with Encoding... na UTF-8 # Pro zobrazení obsahu skriptu použijte CTRL+SHIFT+O # Pro spouštění příkazů v jednotlivých řádcích použijte CTRL+ENTER # Další vybraná spojitá rozdělení #### # * $\chi^2$ - Chí-kvadrát rozdělení (Pearsnovo rozdělení) #### # - Použítí: při odhadu směrodatné odchylky (za použití výběrové) # - Má jediný parametr - počet stupňů volnosti # - $\frac{S^2}{\sigma^2}(n-1) \sim \chi^2_{n-1}$ # - $S$ je výběrová směrodatná odchylka n = 5 # počet stupňů volnosti x = seq(from = 0, to = 30, by = 0.01) # osa x fx = dchisq(x = x, df = n) # hustota pravděpodobnosti chí-kvad. rozdělení plot(x, fx, type='l') Fx = pchisq(q = x, df = n) # distrib. fce. chí-kvad. rozdělení plot(x, Fx, type='l') # * $t$ - Studentovo rozdělení #### # - Použití: při odhadu střední hodnoty bez přesné znalosti rozptylu (pouze výběrového # rozptylu) # - $\frac{\bar X - \mu}{S}\sqrt{n} \sim t_{n-1} $ # - $\bar X$ je výběrový průměr # - $S$ je výběrová směrodatná odchylka # - s rostoucím počtem stupňů volnosti konverguje k normovanému normálnímu rozdělení n = 5 # počet stupňů volnosti x = seq(from = -3, to = 3, by = 0.01) # osa x fx = dt(x = x, df = n) # hustota pravděpodobnosti studentova rozdělení plot(x, fx, type='l') fnorm = dnorm(x, mean=0, sd=1) # hodnoty norm. normálního roz. lines(x, fnorm, col="red") # do posledního grafu Fx = pt(q = x, df = n) # hustota pravděpodobnosti studentova rozdělení plot(x, Fx, type='l') Fnorm = pnorm(x, mean=0, sd=1) # hodnoty norm. normálního roz. lines(x, Fnorm, col="red") # do posledního grafu # * $F$ - Fisher-Snedecorovo rozdělení #### # - Používá se k testování schody rozptylů # - $\frac{S_1^2/\sigma_1^2}{S_2^2/\sigma_2^2} \sim F_{n_1 - 1, n_2 - 1}$ n = 5 # počet stupňů volnosti výběr. 1 m = 6 # počet stupňů volnosti výběr. 2 x = seq(from = 0, to = 10, by = 0.01) # osa x fx = df(x = x, df1 = n, df2 = m) # hustota pravděpodobnosti chí-kvad. rozdělení plot(x, fx, type='l') Fx = pf(q = x, df1 = n, df2 = m) # hustota pravděpodobnosti chí-kvad. rozdělení plot(x, Fx, type='l') # Jak se chová průměr hodnot z normálního rozdělení? #### # Funkce **rnorm(n, mean, sd)** generuje **n** hodnot z normálního rozdělení se střední # hodnotou **mean** a směrodatnou odchylkou **sd**. vel_nah_vyberu = 30 mu = 10 sigma = 3 nah_vyber = rnorm(n=vel_nah_vyberu, mean=mu, sd=sigma) nah_vyber mean(nah_vyber) sd(nah_vyber) # ** Náhodná veličina: průměr hodnot #### poc_vyberu = 1000 prumery = numeric(poc_vyberu) # numeric vyrobi vektor 0 smer_odchylky = numeric(poc_vyberu) for(i in 1:poc_vyberu){ nah_vyber = rnorm(n=vel_nah_vyberu,mean=mu,sd=sigma) prumery[i] = mean(nah_vyber) smer_odchylky[i] = sd(nah_vyber) } hist(prumery) qqnorm(prumery) qqline(prumery) mean(prumery) sd(prumery) sigma/sqrt(vel_nah_vyberu) # Jak se chová průměr hodnot z uniformního rozdělení? #### # Fukce **runif(n, min, max)** generuje **n** hodnot z uniformního rozdělení # U(**min,max**). vel_nah_vyberu = 30 a = 1 b = 7 nah_vyber=runif(n=vel_nah_vyberu, min=a, max=b) #nah_vyber hist(nah_vyber) qqnorm(nah_vyber) qqline(nah_vyber) mu = (a+b)/2 mu mean(nah_vyber) sigma = sqrt((b-a)^2/12) sigma sd(nah_vyber) # ** Náhodná veličina: průměr hodnot #### poc_vyberu = 1000 prumery = numeric(poc_vyberu) smer_odchylky = numeric(poc_vyberu) for(i in 1:poc_vyberu){ nah_vyber = runif(n=vel_nah_vyberu, min=a, max=b) prumery[i] = mean(nah_vyber) smer_odchylky[i] = sd(nah_vyber) } hist(prumery) qqnorm(prumery) qqline(prumery) mean(prumery) sd(prumery) sigma/sqrt(vel_nah_vyberu) # Příklady #### # * Příklad 1. #### # Zatížení letadla s 64 místy nemá překročit 6 000 kg. Jaká je pravděpodobnost, že při # plném obsazení bude tato hodnota překročena, má-li hmotnost cestujícího střední # hodnotu 90 kg a směrodatnou odchylku 10 kg? # X...hmotnost 64 cestujících # X ~ N(64*90; 64*100) # P(X > 6000) = 1 - F(6000) 1 - pnorm(q=6000, mean=64*90, sd=sqrt(64*100)) # * Příklad 2. #### # Zásilka obsahuje 300 výrobků určitého typu. Je známo, že pravděpodobnost zhotovení # vadného výrobku tohoto typu je 0,04. # ** a) #### # Odhadněte pravděpodobnost, že absolutní odchylka podílu vadných výrobků v zásilce od # pravděpodobnosti vyrobení vadného výrobku bude menší než 1 %. # X = (p − π)/sqrt(π*(1 − π))*sqrt(n) ∼ N(0, 1) # P(-0.01/sqrt(π*(1 − π))*sqrt(n) < X < 0.01/sqrt(π*(1 − π))*sqrt(n)) pi = 0.04 n = 300 bound = 0.01/sqrt(pi*(1-pi))*sqrt(n) pnorm(q=bound, mean=0, sd=1) - pnorm(q=-bound, mean=0, sd=1) # ** b) #### # Jak se změní výsledek, jestliže zásilka bude obsahovat 3 000 výrobků? n = 3000 bound = 0.01/sqrt(pi*(1-pi))*sqrt(n) pnorm(q=bound, mean=0, sd=1) - pnorm(q=-bound, mean=0, sd=1) # * Příklad 3. #### # Cestující pravidelně jezdí do zaměstnání a zpět MHD. Je známo, že doba čekání na # příjezd MHD se pohybuje v mezích od 0 do 3 minut. Jaká je pravděpodobnost, že celková # doba čekání zaměstnance na příjezd MHD během 23 pracovních dnů bude kratší než 80 # minut? # Y...doba i-tého čekání na MHD # y ~ R(0; 3) # X...celková doba čekání během 23 dnů (cesta tam a zpět ⇒ 46 čekání) # X ~ N(46*EY; 46*DY) # P(X < 80) a = 0 b = 3 n = 46 EY = (a+b)/2 DY = (b-a)^2/12 pnorm(q=80, mean=n*EY, sd=sqrt(n*DY)) # * Příklad 4. #### # Předpokládejme, že průměrná spotřeba elektrické energie domácností v určitém městě v # lednu je 120 kWh a směrodatná odchylka spotřeby je 100 kWh. Určete pravděpodobnost, že # průměrná spotřeba 100 náhodně vybraných domácností bude větší než 140 kWh. # Xi...spotřeba i-té domácnosti # X...průměrná spotřeba 100 domácností # X ~ N(EXi;Dxi/n) # P(X > 140) EXi = 120 DXi = 100^2 n = 100 1 - pnorm(q=140, mean=EXi, sd=sqrt(DXi/n)) # * Příklad 5. #### # Společnost Acme Battery Company vyvinula nový typ baterie mobilních telefonů. V # průměru vydrží baterie 60 minut na jedno nabití. Směrodatná odchylka této doby je 4 # minuty. Předpokládejme, že výrobní oddělení po 6 měsících spustí test kontroly # kvality. Provedli dva náhodné výběry o rozsahu 10 baterií a v obou zjistili # směrodatnou odchylku výdrže baterií větší než 6 minut. S jakou pravděpodobností takový # výsledek mohli očekávat? # X = (n − 1)S^2/σ^2 # X ∼ χ_n-1 # P(S > 6) = P(X > ...) n = 10 S_obs = 6 sigma = 4 X_obs = (n - 1)*S_obs^2/sigma^2 P_jedno_mereni = 1 - pchisq(q=X_obs, df=n-1) P_jedno_mereni P_jedno_mereni^2 # * Příklad 6. #### # Z úmrtnostních tabulek vyplývá pravděpodobnost 0,99, že se 35 - letý muž dožije # dalšího roku. Roční pojistné této věkové skupiny činí 2 000 Kč, v případě úmrtí # pojišťovna vyplatí 100 000 Kč. Jaká je pravděpodobnost, že zisk z 500 pojištěných mužů # ve věku 35 let bude alespoň 500 000 Kč? (Řešte dvěma způsoby - pomocí binomického # rozdělení a pomoci aproximace binomického rozdělení rozdělením normálním.) # X...počet mužů z 500, kteří se nedožijí dalšího roku # X ~ Bi(500; 0.01) # Z = 500 · 2 000 − X · 100 000 # P(Z ≥ 500 000) = P(X ≤ 5) pbinom(5, size=500, prob=0.01) # X ~ Bi(500; 0.01) ~ N(500*0.01; 500*0.01*(1-0.01)) # P(X ≤ 5) ~ P(X < 5.5) (oprava na spojitost) pnorm(5.5, mean=500*0.01, sd=sqrt(500*0.01*(1-0.01))) # * Příklad 7. #### # Předpokládejme, že v populaci má přibližně 60 % mladých mužů vyšší než doporučenou # hladinu cholesterolu v séru. S jakou pravděpodobností bude mít v náhodném výběru 200 # mladých mužů více než 120 z nich vyšší než doporučenou hladinu cholesterolu v séru? # X...počet mladých mužů z 200 s vyšší než doporučenou hladinou cholesterolu v séru # X ∼ Bi(200; 0.6) # P(X > 120) = 1 - P(X ≤ 120) 1 - pbinom(120, size=200, prob=0.6) # X ~ N(200*0.6; 200*0.6(1-0.6)), tj. X ≈ N(120; 48) # 1 - P(X ≤ 120) ~ 1 - P(X < 120.5) (oprava na spojitost) 1 - pnorm(120.5, mean=200*0.6, sd=sqrt(200*0.6*(1-0.6)))
Formal statement is: lemma bounded_any_center: "bounded S \<longleftrightarrow> (\<exists>e. \<forall>y\<in>S. dist a y \<le> e)" Informal statement is: A set $S$ is bounded if and only if there exists a real number $e$ such that for all $y \in S$, we have $|y - a| \leq e$.
/* filter/rmedian.c * * Copyright (C) 2018 Patrick Alken * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 3 of the License, or (at * your option) any later version. * * This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ /* * This module contains routines related to the recursive median filter. The * algorithm is based on this paper, * * [1] S-J Ko, Y. H. Lee, and A. T. Fam, Efficient Implementation of One-Dimensional * Recursive Median Filters, IEEE Transactions on Circuits and Systems, Vol 37, * No 11, 1990. */ #include <config.h> #include <stdlib.h> #include <math.h> #include <gsl/gsl_math.h> #include <gsl/gsl_vector.h> #include <gsl/gsl_filter.h> #include <gsl/gsl_errno.h> #include <gsl/gsl_statistics.h> #include <gsl/gsl_movstat.h> typedef struct { const gsl_movstat_accum * minmax_acc; /* minimum/maximum accumulator */ void *minmax_state; /* minimum/maximum accumulator workspace */ } rmedian_state_t; static size_t rmedian_size(const size_t n); static int rmedian_init(const size_t n, void * vstate); static int rmedian_insert(const double x, void * vstate); static int rmedian_delete(void * vstate); static int rmedian_get(void * params, double * result, const void * vstate); static const gsl_movstat_accum rmedian_accum_type; gsl_filter_rmedian_workspace * gsl_filter_rmedian_alloc(const size_t K) { gsl_filter_rmedian_workspace *w; size_t state_size; w = calloc(1, sizeof(gsl_filter_rmedian_workspace)); if (w == 0) { GSL_ERROR_NULL ("failed to allocate space for workspace", GSL_ENOMEM); } w->H = K / 2; w->K = 2*w->H + 1; w->minmaxacc = gsl_movstat_accum_minmax; w->window = malloc(w->K * sizeof(double)); if (w->window == NULL) { gsl_filter_rmedian_free(w); GSL_ERROR_NULL ("failed to allocate space for window", GSL_ENOMEM); } state_size = rmedian_size(w->H + 1); w->state = malloc(state_size); if (w->state == NULL) { gsl_filter_rmedian_free(w); GSL_ERROR_NULL ("failed to allocate space for min/max state", GSL_ENOMEM); } w->movstat_workspace_p = gsl_movstat_alloc_with_size(state_size, 0, w->H); if (!w->movstat_workspace_p) { gsl_filter_rmedian_free(w); GSL_ERROR_NULL ("failed to allocate space for movstat workspace", GSL_ENOMEM); } return w; } void gsl_filter_rmedian_free(gsl_filter_rmedian_workspace * w) { if (w->state) free(w->state); if (w->window) free(w->window); if (w->movstat_workspace_p) gsl_movstat_free(w->movstat_workspace_p); free(w); } /* gsl_filter_rmedian() Recursive median filter Inputs: endtype - end point handling x - input vector y - output vector w - workspace */ int gsl_filter_rmedian(const gsl_filter_end_t endtype, const gsl_vector * x, gsl_vector * y, gsl_filter_rmedian_workspace * w) { if (x->size != y->size) { GSL_ERROR("input and output vectors must have same length", GSL_EBADLEN); } else { int status = GSL_SUCCESS; const size_t n = x->size; const int H = (int) w->H; double yprev; int wsize; /* find median of first window to initialize filter */ wsize = gsl_movstat_fill(endtype, x, 0, H, H, w->window); yprev = gsl_stats_median(w->window, 1, wsize); gsl_vector_set(y, 0, yprev); if (x->size > 1) { gsl_vector_const_view xv = gsl_vector_const_subvector(x, 1, n - 1); gsl_vector_view yv = gsl_vector_subvector(y, 1, n - 1); /* apply recursive median filter to x[2:end] */ status = gsl_movstat_apply_accum(endtype, &xv.vector, &rmedian_accum_type, (void *) &yprev, &yv.vector, NULL, w->movstat_workspace_p); } return status; } } static size_t rmedian_size(const size_t n) { size_t size = 0; const gsl_movstat_accum * acc = gsl_movstat_accum_minmax; size += sizeof(rmedian_state_t); size += (acc->size)(n); return size; } static int rmedian_init(const size_t n, void * vstate) { rmedian_state_t * state = (rmedian_state_t *) vstate; state->minmax_acc = gsl_movstat_accum_minmax; state->minmax_state = (void *) ((unsigned char *) vstate + sizeof(rmedian_state_t)); (state->minmax_acc->init)(n, state->minmax_state); return GSL_SUCCESS; } static int rmedian_insert(const double x, void * vstate) { rmedian_state_t * state = (rmedian_state_t *) vstate; return (state->minmax_acc->insert)(x, state->minmax_state); } static int rmedian_delete(void * vstate) { rmedian_state_t * state = (rmedian_state_t *) vstate; return (state->minmax_acc->delete_oldest)(state->minmax_state); } static int rmedian_get(void * params, double * result, const void * vstate) { const rmedian_state_t * state = (const rmedian_state_t *) vstate; double *yprev = (double *) params; /* previous filter output */ double y; /* new filter output */ double xminmax[2]; /* get minimum/maximum values of {x_i,...,x_{i+H}} */ (state->minmax_acc->get)(NULL, xminmax, state->minmax_state); /* y = median [ yprev, xmin, xmax ] */ if (*yprev <= xminmax[0]) y = xminmax[0]; else if (*yprev <= xminmax[1]) y = *yprev; else y = xminmax[1]; *result = y; *yprev = y; return GSL_SUCCESS; } static const gsl_movstat_accum rmedian_accum_type = { rmedian_size, rmedian_init, rmedian_insert, rmedian_delete, rmedian_get };
import os import tqdm import torch import numpy as np import torch.nn as nn from lib.helpers.save_helper import get_checkpoint_state from lib.helpers.save_helper import load_checkpoint from lib.helpers.save_helper import save_checkpoint from lib.losses.centernet_loss import compute_centernet3d_loss class Trainer(object): def __init__(self, cfg, model, optimizer, train_loader, test_loader, lr_scheduler, warmup_lr_scheduler, logger, log_dir): self.cfg = cfg self.model = model self.optimizer = optimizer self.train_loader = train_loader self.test_loader = test_loader self.lr_scheduler = lr_scheduler self.warmup_lr_scheduler = warmup_lr_scheduler self.logger = logger self.epoch = 0 self.device = torch.device("cuda:0" if torch.cuda.is_available() else "cpu") self.log_dir = log_dir # loading pretrain/resume model if cfg.get('pretrain_model'): assert os.path.exists(cfg['pretrain_model']) load_checkpoint(model=self.model, optimizer=None, filename=cfg['pretrain_model'], map_location=self.device, logger=self.logger) if cfg.get('resume_model', None): assert os.path.exists(cfg['resume_model']) self.epoch = load_checkpoint(model=self.model.to(self.device), optimizer=self.optimizer, filename=cfg['resume_model'], map_location=self.device, logger=self.logger) self.lr_scheduler.last_epoch = self.epoch - 1 if isinstance(cfg['gpu_ids'], int): self.gpu_ids = [cfg['gpu_ids']] else: self.gpu_ids = list(map(int, cfg['gpu_ids'].split(","))) self.model = torch.nn.DataParallel(model, device_ids=self.gpu_ids).to(self.device) def train(self): start_epoch = self.epoch progress_bar = tqdm.tqdm(range(start_epoch, self.cfg['max_epoch']), dynamic_ncols=True, leave=True, desc='epochs') for epoch in range(start_epoch, self.cfg['max_epoch']): # reset random seed # ref: https://github.com/pytorch/pytorch/issues/5059 np.random.seed(np.random.get_state()[1][0] + epoch) self.logger.info("epoch: {}".format(epoch)) # train one epoch self.train_one_epoch() self.epoch += 1 # update learning rate if self.warmup_lr_scheduler is not None and epoch < 5: self.warmup_lr_scheduler.step() else: self.lr_scheduler.step() # save trained model if (self.epoch % self.cfg['save_frequency']) == 0: os.makedirs(os.path.join(self.log_dir, 'checkpoints'), exist_ok=True) ckpt_name = os.path.join(self.log_dir, 'checkpoints', 'checkpoint_epoch_%d' % self.epoch) save_checkpoint(get_checkpoint_state(self.model, self.optimizer, self.epoch), ckpt_name) progress_bar.update() return None def train_one_epoch(self): self.model.train() loss_items = {} progress_bar = tqdm.tqdm(total=len(self.train_loader), leave=(self.epoch+1 == self.cfg['max_epoch']), desc='iters') for batch_idx, (inputs, targets, _) in enumerate(self.train_loader): inputs = inputs.to(self.device) for key in targets.keys(): targets[key] = targets[key].to(self.device) # train one batch self.optimizer.zero_grad() outputs = self.model(inputs, targets) total_loss, stats_batch = compute_centernet3d_loss(outputs, targets) total_loss.backward() self.optimizer.step() self.update_loss_item(loss_items, stats_batch) progress_bar.update() progress_bar.close() self.print_loss_items(loss_items) def update_loss_item(self, loss_items, stats_batch): # cache loss item of this batch if not loss_items: for idx, key in enumerate(stats_batch.keys()): loss_items[key] = 0.0 for idx, key in enumerate(stats_batch.keys()): loss_items[key] += stats_batch[key] def print_loss_items(self, loss_items): print(end="\n") num_batch = len(self.train_loader) for key, value in loss_items.items(): self.logger.info("{} loss: {}, ".format(key, value / num_batch)) print(end="\n")
8 * .Machine$sizeof.long # e.g. 32 # or object.size(0L) # e.g. 32 bytes
Require Import Coq.PArith.BinPos. Require Import Coq.Lists.List. Import ListNotations. Module natmap. Section __. Context {V: Type}. (* TODO if there are trailing None's map extensionality doesn't hold, can we fix that? *) Definition natmap := list (option V). Definition head(m: natmap): option V := match m with | nil => None | o :: _ => o end. Definition tail: natmap -> natmap := @List.tail (option V). Fixpoint skip(n: nat)(m: natmap): natmap := match n with | O => m | S n' => tail (skip n' m) end. Definition get(m: natmap)(n: nat): option V := head (skip n m). (* m2 overrides m1. Simplifies best if m2 is concrete *) Fixpoint merge(m1 m2: natmap): natmap := match m2 with | nil => m1 | cons h t => cons (match h with | Some v => Some v | None => head m1 end) (merge (tail m1) t) end. Fixpoint singleton(k: nat)(v: V): natmap := match k with | O => Some v :: nil | S n => None :: singleton n v end. Definition put(m: natmap)(k: nat)(v: V): natmap := merge m (singleton k v). Definition putmany: natmap -> list (nat * V) -> natmap := List.fold_right (fun '(k, v) res => put res k v). End __. End natmap. Arguments natmap.natmap: clear implicits. Notation natmap := natmap.natmap. Definition forcetype(o: option Type): Type := match o with | Some T => T | None => unit end. Inductive hnatmap: natmap Type -> Type := | HNil: hnatmap nil | HCons{OV: option Type}{T: natmap Type}(v: forcetype OV)(t: hnatmap T): hnatmap (cons OV T). Module hnatmap. Definition head{T: natmap Type}(m: hnatmap T): forcetype (natmap.head T) := match m with | HNil => tt | HCons v _ => v end. Definition tail{T: natmap Type}(m: hnatmap T): hnatmap (tail T) := match m with | HNil => HNil | HCons _ t => t end. Fixpoint skip(n: nat){T: natmap Type}(m: hnatmap T): hnatmap (natmap.skip n T) := match n with | 0 => m | S n' => tail (skip n' m) end. Definition get{T: natmap Type}(m: hnatmap T)(n: nat): forcetype (natmap.get T n) := head (skip n m). (* m2 overrides m1 *) Fixpoint merge{T1 T2: natmap Type}(m1: hnatmap T1)(m2: hnatmap T2): hnatmap (natmap.merge T1 T2). refine (match m2 with | HNil => m1 | @HCons OV T2Tail v t => @HCons (match OV with | Some V => Some V | None => natmap.head T1 end) (natmap.merge (natmap.tail T1) T2Tail) _ (merge _ _ (tail m1) t) end). destruct OV as [V|]. - exact v. - exact (head m1). Defined. Fixpoint singleton{V: Type}(k: nat)(v: V){struct k}: hnatmap (natmap.singleton k V) := match k with | 0 => @HCons (Some V) [] v HNil | S n => @HCons None (natmap.singleton n V) tt (singleton n v) end. Definition put{T: natmap Type}(m: hnatmap T)(k: nat){V: Type}(v: V): hnatmap (natmap.put T k V) := merge m (singleton k v). End hnatmap. Module HnatmapNotations. Declare Scope hnatmap_scope. Notation "m [ k := v ]" := (hnatmap.put m k v) (at level 8, left associativity, format "m [ k := v ]") : hnatmap_scope. Notation "m [ k ]" := (hnatmap.get m k) (at level 8, left associativity, format "m [ k ]") : hnatmap_scope. (* this notation overrides the notation for applying a function m to the singleton list containing k, but that's so rare that it's fine *) End HnatmapNotations.
/* * Copyright 2020 Robert Bosch GmbH * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * * SPDX-License-Identifier: Apache-2.0 */ /** * \file cloe/utility/command.cpp * \see cloe/utility/command.hpp */ #include <cloe/utility/command.hpp> #include <cstdlib> // for getenv #include <string> // for string #include <boost/filesystem/path.hpp> // for path #include <boost/process/search_path.hpp> // for search_path namespace cloe { namespace { /** * Return the first suitable shell found, taking the SHELL environment variable * into account as a last resort. * * It might seem intuitive to take SHELL into account first, but this could * quickly lead to errors if the user starting Cloe makes use of an alternative * shell. */ boost::filesystem::path shell_executable() { for (auto shell : {"bash", "dash", "sh", "zsh"}) { auto result = boost::process::search_path(shell); if (!result.empty()) { return result; } } if (std::getenv("SHELL") != nullptr) { auto result = boost::process::search_path(std::getenv("SHELL")); if (!result.empty()) { return result; } } return boost::filesystem::path{}; } } // namespace std::string Command::command() const { std::string s = executable_.native(); for (const auto& a : args_) { s += " " + a; } return s; } void Command::from_conf(const Conf& c) { command_.clear(); Confable::from_conf(c); if (!command_.empty()) { executable_ = shell_executable(); if (executable_.empty()) { c.throw_error("cannot find suitable shell to execute command"); } args_.clear(); args_.emplace_back("-c"); args_.emplace_back(command_); } } } // namespace cloe
\subsection{Forms on real functions} A form takes two vectors and produces a scalar. \subsubsection{Integration as a form} We can use integration to get a bilinear form. \(\int f(x) g(x) dx\) If we instead want a sesquilinear form we can instead use: \(\int \bar {f(x)} g(x) dx\)
Address(Chateau Lane) is a residential street in South Davis. Intersecting Streets Emerald Bay Drive Emerald Bay Drive again
# OpenFace API tests. # # Copyright 2015-2016 Carnegie Mellon University # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. import cv2 import os import numpy as np np.set_printoptions(precision=2) import scipy import scipy.spatial import openface openfaceDir = os.path.dirname(os.path.dirname(os.path.realpath(__file__))) modelDir = os.path.join(openfaceDir, 'models') dlibModelDir = os.path.join(modelDir, 'dlib') openfaceModelDir = os.path.join(modelDir, 'openface') exampleImages = os.path.join(openfaceDir, 'images', 'examples') lfwSubset = os.path.join(openfaceDir, 'data', 'lfw-subset') dlibFacePredictor = os.path.join(dlibModelDir, "shape_predictor_68_face_landmarks.dat") model = os.path.join(openfaceModelDir, 'nn4.small2.v1.t7') imgDim = 96 align = openface.AlignDlib(dlibFacePredictor) net = openface.TorchNeuralNet(model, imgDim=imgDim) def test_pipeline(): imgPath = os.path.join(exampleImages, 'lennon-1.jpg') bgrImg = cv2.imread(imgPath) if bgrImg is None: raise Exception("Unable to load image: {}".format(imgPath)) rgbImg = cv2.cvtColor(bgrImg, cv2.COLOR_BGR2RGB) # assert np.isclose(norm(rgbImg), 11.1355) bb = align.getLargestFaceBoundingBox(rgbImg) assert bb.left() == 341 assert bb.right() == 1006 assert bb.top() == 193 assert bb.bottom() == 859 alignedFace = align.align(imgDim, rgbImg, bb, landmarkIndices=openface.AlignDlib.OUTER_EYES_AND_NOSE) # assert np.isclose(norm(alignedFace), 7.61577) rep = net.forward(alignedFace) cosDist = scipy.spatial.distance.cosine(rep, np.ones(128)) print(cosDist) assert np.isclose(cosDist, 0.938840385931)
(* Title: HOL/Auth/n_germanSymIndex_lemma_inv__4_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_germanSymIndex Protocol Case Study*} theory n_germanSymIndex_lemma_inv__4_on_rules imports n_germanSymIndex_lemma_on_inv__4 begin section{*All lemmas on causal relation between inv__4*} lemma lemma_inv__4_on_rules: assumes b1: "r \<in> rules N" and b2: "(\<exists> p__Inv2. p__Inv2\<le>N\<and>f=inv__4 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__4) 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__4) 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__4) 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__4) 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__4) 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__4) 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__4) 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__4) 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__4) 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__4) 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__4) 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__4) 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__4) 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__4) done } ultimately show "invHoldForRule s f r (invariants N)" by satx qed end
(* Title: HOL/Auth/n_flash_lemma_on_inv__4.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_flash Protocol Case Study*} theory n_flash_lemma_on_inv__4 imports n_flash_base begin section{*All lemmas on causal relation between inv__4 and some rule r*} lemma n_PI_Remote_GetVsinv__4: assumes a1: "(\<exists> src. src\<le>N\<and>r=n_PI_Remote_Get src)" and a2: "(\<exists> p__Inv3 p__Inv4. p__Inv3\<le>N\<and>p__Inv4\<le>N\<and>p__Inv3~=p__Inv4\<and>f=inv__4 p__Inv3 p__Inv4)" shows "invHoldForRule s f r (invariants N)" (is "?P1 s \<or> ?P2 s \<or> ?P3 s") proof - from a1 obtain src where a1:"src\<le>N\<and>r=n_PI_Remote_Get src" 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__4 p__Inv3 p__Inv4" apply fastforce done have "(src=p__Inv4)\<or>(src=p__Inv3)\<or>(src~=p__Inv3\<and>src~=p__Inv4)" apply (cut_tac a1 a2, auto) done moreover { assume b1: "(src=p__Inv4)" have "?P2 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume b1: "(src=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: "(src~=p__Inv3\<and>src~=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_PI_Remote_GetXVsinv__4: assumes a1: "(\<exists> src. src\<le>N\<and>r=n_PI_Remote_GetX src)" and a2: "(\<exists> p__Inv3 p__Inv4. p__Inv3\<le>N\<and>p__Inv4\<le>N\<and>p__Inv3~=p__Inv4\<and>f=inv__4 p__Inv3 p__Inv4)" shows "invHoldForRule s f r (invariants N)" (is "?P1 s \<or> ?P2 s \<or> ?P3 s") proof - from a1 obtain src where a1:"src\<le>N\<and>r=n_PI_Remote_GetX src" 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__4 p__Inv3 p__Inv4" apply fastforce done have "(src=p__Inv4)\<or>(src=p__Inv3)\<or>(src~=p__Inv3\<and>src~=p__Inv4)" apply (cut_tac a1 a2, auto) done moreover { assume b1: "(src=p__Inv4)" have "?P2 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume b1: "(src=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: "(src~=p__Inv3\<and>src~=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_PI_Remote_PutXVsinv__4: assumes a1: "(\<exists> dst. dst\<le>N\<and>r=n_PI_Remote_PutX dst)" and a2: "(\<exists> p__Inv3 p__Inv4. p__Inv3\<le>N\<and>p__Inv4\<le>N\<and>p__Inv3~=p__Inv4\<and>f=inv__4 p__Inv3 p__Inv4)" shows "invHoldForRule s f r (invariants N)" (is "?P1 s \<or> ?P2 s \<or> ?P3 s") proof - from a1 obtain dst where a1:"dst\<le>N\<and>r=n_PI_Remote_PutX dst" 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__4 p__Inv3 p__Inv4" apply fastforce done have "(dst=p__Inv4)\<or>(dst=p__Inv3)\<or>(dst~=p__Inv3\<and>dst~=p__Inv4)" apply (cut_tac a1 a2, auto) done moreover { assume b1: "(dst=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: "(dst=p__Inv3)" have "?P2 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume b1: "(dst~=p__Inv3\<and>dst~=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_PI_Remote_ReplaceVsinv__4: assumes a1: "(\<exists> src. src\<le>N\<and>r=n_PI_Remote_Replace src)" and a2: "(\<exists> p__Inv3 p__Inv4. p__Inv3\<le>N\<and>p__Inv4\<le>N\<and>p__Inv3~=p__Inv4\<and>f=inv__4 p__Inv3 p__Inv4)" shows "invHoldForRule s f r (invariants N)" (is "?P1 s \<or> ?P2 s \<or> ?P3 s") proof - from a1 obtain src where a1:"src\<le>N\<and>r=n_PI_Remote_Replace src" 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__4 p__Inv3 p__Inv4" apply fastforce done have "(src=p__Inv4)\<or>(src=p__Inv3)\<or>(src~=p__Inv3\<and>src~=p__Inv4)" apply (cut_tac a1 a2, auto) done moreover { assume b1: "(src=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: "(src=p__Inv3)" have "?P2 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume b1: "(src~=p__Inv3\<and>src~=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_NI_NakVsinv__4: assumes a1: "(\<exists> dst. dst\<le>N\<and>r=n_NI_Nak dst)" and a2: "(\<exists> p__Inv3 p__Inv4. p__Inv3\<le>N\<and>p__Inv4\<le>N\<and>p__Inv3~=p__Inv4\<and>f=inv__4 p__Inv3 p__Inv4)" shows "invHoldForRule s f r (invariants N)" (is "?P1 s \<or> ?P2 s \<or> ?P3 s") proof - from a1 obtain dst where a1:"dst\<le>N\<and>r=n_NI_Nak dst" 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__4 p__Inv3 p__Inv4" apply fastforce done have "(dst=p__Inv4)\<or>(dst=p__Inv3)\<or>(dst~=p__Inv3\<and>dst~=p__Inv4)" apply (cut_tac a1 a2, auto) done moreover { assume b1: "(dst=p__Inv4)" have "?P2 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume b1: "(dst=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: "(dst~=p__Inv3\<and>dst~=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_NI_Local_Get_Nak__part__0Vsinv__4: assumes a1: "(\<exists> src. src\<le>N\<and>r=n_NI_Local_Get_Nak__part__0 src)" and a2: "(\<exists> p__Inv3 p__Inv4. p__Inv3\<le>N\<and>p__Inv4\<le>N\<and>p__Inv3~=p__Inv4\<and>f=inv__4 p__Inv3 p__Inv4)" shows "invHoldForRule s f r (invariants N)" (is "?P1 s \<or> ?P2 s \<or> ?P3 s") proof - from a1 obtain src where a1:"src\<le>N\<and>r=n_NI_Local_Get_Nak__part__0 src" 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__4 p__Inv3 p__Inv4" apply fastforce done have "(src=p__Inv4)\<or>(src=p__Inv3)\<or>(src~=p__Inv3\<and>src~=p__Inv4)" apply (cut_tac a1 a2, auto) done moreover { assume b1: "(src=p__Inv4)" have "?P2 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume b1: "(src=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: "(src~=p__Inv3\<and>src~=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_NI_Local_Get_Nak__part__1Vsinv__4: assumes a1: "(\<exists> src. src\<le>N\<and>r=n_NI_Local_Get_Nak__part__1 src)" and a2: "(\<exists> p__Inv3 p__Inv4. p__Inv3\<le>N\<and>p__Inv4\<le>N\<and>p__Inv3~=p__Inv4\<and>f=inv__4 p__Inv3 p__Inv4)" shows "invHoldForRule s f r (invariants N)" (is "?P1 s \<or> ?P2 s \<or> ?P3 s") proof - from a1 obtain src where a1:"src\<le>N\<and>r=n_NI_Local_Get_Nak__part__1 src" 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__4 p__Inv3 p__Inv4" apply fastforce done have "(src=p__Inv4)\<or>(src=p__Inv3)\<or>(src~=p__Inv3\<and>src~=p__Inv4)" apply (cut_tac a1 a2, auto) done moreover { assume b1: "(src=p__Inv4)" have "?P2 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume b1: "(src=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: "(src~=p__Inv3\<and>src~=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_NI_Local_Get_Nak__part__2Vsinv__4: assumes a1: "(\<exists> src. src\<le>N\<and>r=n_NI_Local_Get_Nak__part__2 src)" and a2: "(\<exists> p__Inv3 p__Inv4. p__Inv3\<le>N\<and>p__Inv4\<le>N\<and>p__Inv3~=p__Inv4\<and>f=inv__4 p__Inv3 p__Inv4)" shows "invHoldForRule s f r (invariants N)" (is "?P1 s \<or> ?P2 s \<or> ?P3 s") proof - from a1 obtain src where a1:"src\<le>N\<and>r=n_NI_Local_Get_Nak__part__2 src" 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__4 p__Inv3 p__Inv4" apply fastforce done have "(src=p__Inv4)\<or>(src=p__Inv3)\<or>(src~=p__Inv3\<and>src~=p__Inv4)" apply (cut_tac a1 a2, auto) done moreover { assume b1: "(src=p__Inv4)" have "?P2 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume b1: "(src=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: "(src~=p__Inv3\<and>src~=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_NI_Local_Get_Get__part__0Vsinv__4: assumes a1: "(\<exists> src. src\<le>N\<and>r=n_NI_Local_Get_Get__part__0 src)" and a2: "(\<exists> p__Inv3 p__Inv4. p__Inv3\<le>N\<and>p__Inv4\<le>N\<and>p__Inv3~=p__Inv4\<and>f=inv__4 p__Inv3 p__Inv4)" shows "invHoldForRule s f r (invariants N)" (is "?P1 s \<or> ?P2 s \<or> ?P3 s") proof - from a1 obtain src where a1:"src\<le>N\<and>r=n_NI_Local_Get_Get__part__0 src" 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__4 p__Inv3 p__Inv4" apply fastforce done have "(src=p__Inv4)\<or>(src=p__Inv3)\<or>(src~=p__Inv3\<and>src~=p__Inv4)" apply (cut_tac a1 a2, auto) done moreover { assume b1: "(src=p__Inv4)" have "?P2 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume b1: "(src=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: "(src~=p__Inv3\<and>src~=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_NI_Local_Get_Get__part__1Vsinv__4: assumes a1: "(\<exists> src. src\<le>N\<and>r=n_NI_Local_Get_Get__part__1 src)" and a2: "(\<exists> p__Inv3 p__Inv4. p__Inv3\<le>N\<and>p__Inv4\<le>N\<and>p__Inv3~=p__Inv4\<and>f=inv__4 p__Inv3 p__Inv4)" shows "invHoldForRule s f r (invariants N)" (is "?P1 s \<or> ?P2 s \<or> ?P3 s") proof - from a1 obtain src where a1:"src\<le>N\<and>r=n_NI_Local_Get_Get__part__1 src" 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__4 p__Inv3 p__Inv4" apply fastforce done have "(src=p__Inv4)\<or>(src=p__Inv3)\<or>(src~=p__Inv3\<and>src~=p__Inv4)" apply (cut_tac a1 a2, auto) done moreover { assume b1: "(src=p__Inv4)" have "?P2 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume b1: "(src=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: "(src~=p__Inv3\<and>src~=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_NI_Local_Get_Put_HeadVsinv__4: assumes a1: "(\<exists> src. src\<le>N\<and>r=n_NI_Local_Get_Put_Head N src)" and a2: "(\<exists> p__Inv3 p__Inv4. p__Inv3\<le>N\<and>p__Inv4\<le>N\<and>p__Inv3~=p__Inv4\<and>f=inv__4 p__Inv3 p__Inv4)" shows "invHoldForRule s f r (invariants N)" (is "?P1 s \<or> ?P2 s \<or> ?P3 s") proof - from a1 obtain src where a1:"src\<le>N\<and>r=n_NI_Local_Get_Put_Head N src" 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__4 p__Inv3 p__Inv4" apply fastforce done have "(src=p__Inv4)\<or>(src=p__Inv3)\<or>(src~=p__Inv3\<and>src~=p__Inv4)" apply (cut_tac a1 a2, auto) done moreover { assume b1: "(src=p__Inv4)" have "?P2 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume b1: "(src=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: "(src~=p__Inv3\<and>src~=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_NI_Local_Get_PutVsinv__4: assumes a1: "(\<exists> src. src\<le>N\<and>r=n_NI_Local_Get_Put src)" and a2: "(\<exists> p__Inv3 p__Inv4. p__Inv3\<le>N\<and>p__Inv4\<le>N\<and>p__Inv3~=p__Inv4\<and>f=inv__4 p__Inv3 p__Inv4)" shows "invHoldForRule s f r (invariants N)" (is "?P1 s \<or> ?P2 s \<or> ?P3 s") proof - from a1 obtain src where a1:"src\<le>N\<and>r=n_NI_Local_Get_Put src" 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__4 p__Inv3 p__Inv4" apply fastforce done have "(src=p__Inv4)\<or>(src=p__Inv3)\<or>(src~=p__Inv3\<and>src~=p__Inv4)" apply (cut_tac a1 a2, auto) done moreover { assume b1: "(src=p__Inv4)" have "?P2 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume b1: "(src=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: "(src~=p__Inv3\<and>src~=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_NI_Local_Get_Put_DirtyVsinv__4: assumes a1: "(\<exists> src. src\<le>N\<and>r=n_NI_Local_Get_Put_Dirty src)" and a2: "(\<exists> p__Inv3 p__Inv4. p__Inv3\<le>N\<and>p__Inv4\<le>N\<and>p__Inv3~=p__Inv4\<and>f=inv__4 p__Inv3 p__Inv4)" shows "invHoldForRule s f r (invariants N)" (is "?P1 s \<or> ?P2 s \<or> ?P3 s") proof - from a1 obtain src where a1:"src\<le>N\<and>r=n_NI_Local_Get_Put_Dirty src" 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__4 p__Inv3 p__Inv4" apply fastforce done have "(src=p__Inv4)\<or>(src=p__Inv3)\<or>(src~=p__Inv3\<and>src~=p__Inv4)" apply (cut_tac a1 a2, auto) done moreover { assume b1: "(src=p__Inv4)" have "?P2 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume b1: "(src=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: "(src~=p__Inv3\<and>src~=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_NI_Remote_Get_NakVsinv__4: assumes a1: "(\<exists> src dst. src\<le>N\<and>dst\<le>N\<and>src~=dst\<and>r=n_NI_Remote_Get_Nak src dst)" and a2: "(\<exists> p__Inv3 p__Inv4. p__Inv3\<le>N\<and>p__Inv4\<le>N\<and>p__Inv3~=p__Inv4\<and>f=inv__4 p__Inv3 p__Inv4)" shows "invHoldForRule s f r (invariants N)" (is "?P1 s \<or> ?P2 s \<or> ?P3 s") proof - from a1 obtain src dst where a1:"src\<le>N\<and>dst\<le>N\<and>src~=dst\<and>r=n_NI_Remote_Get_Nak src dst" 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__4 p__Inv3 p__Inv4" apply fastforce done have "(src=p__Inv4\<and>dst=p__Inv3)\<or>(src=p__Inv3\<and>dst=p__Inv4)\<or>(src=p__Inv4\<and>dst~=p__Inv3\<and>dst~=p__Inv4)\<or>(src~=p__Inv3\<and>src~=p__Inv4\<and>dst=p__Inv4)\<or>(src=p__Inv3\<and>dst~=p__Inv3\<and>dst~=p__Inv4)\<or>(src~=p__Inv3\<and>src~=p__Inv4\<and>dst=p__Inv3)\<or>(src~=p__Inv3\<and>src~=p__Inv4\<and>dst~=p__Inv3\<and>dst~=p__Inv4)" apply (cut_tac a1 a2, auto) done moreover { assume b1: "(src=p__Inv4\<and>dst=p__Inv3)" have "?P2 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume b1: "(src=p__Inv3\<and>dst=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: "(src=p__Inv4\<and>dst~=p__Inv3\<and>dst~=p__Inv4)" have "?P2 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume b1: "(src~=p__Inv3\<and>src~=p__Inv4\<and>dst=p__Inv4)" have "?P2 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume b1: "(src=p__Inv3\<and>dst~=p__Inv3\<and>dst~=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: "(src~=p__Inv3\<and>src~=p__Inv4\<and>dst=p__Inv3)" have "?P2 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume b1: "(src~=p__Inv3\<and>src~=p__Inv4\<and>dst~=p__Inv3\<and>dst~=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_NI_Remote_Get_PutVsinv__4: assumes a1: "(\<exists> src dst. src\<le>N\<and>dst\<le>N\<and>src~=dst\<and>r=n_NI_Remote_Get_Put src dst)" and a2: "(\<exists> p__Inv3 p__Inv4. p__Inv3\<le>N\<and>p__Inv4\<le>N\<and>p__Inv3~=p__Inv4\<and>f=inv__4 p__Inv3 p__Inv4)" shows "invHoldForRule s f r (invariants N)" (is "?P1 s \<or> ?P2 s \<or> ?P3 s") proof - from a1 obtain src dst where a1:"src\<le>N\<and>dst\<le>N\<and>src~=dst\<and>r=n_NI_Remote_Get_Put src dst" 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__4 p__Inv3 p__Inv4" apply fastforce done have "(src=p__Inv4\<and>dst=p__Inv3)\<or>(src=p__Inv3\<and>dst=p__Inv4)\<or>(src=p__Inv4\<and>dst~=p__Inv3\<and>dst~=p__Inv4)\<or>(src~=p__Inv3\<and>src~=p__Inv4\<and>dst=p__Inv4)\<or>(src=p__Inv3\<and>dst~=p__Inv3\<and>dst~=p__Inv4)\<or>(src~=p__Inv3\<and>src~=p__Inv4\<and>dst=p__Inv3)\<or>(src~=p__Inv3\<and>src~=p__Inv4\<and>dst~=p__Inv3\<and>dst~=p__Inv4)" apply (cut_tac a1 a2, auto) done moreover { assume b1: "(src=p__Inv4\<and>dst=p__Inv3)" have "?P2 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume b1: "(src=p__Inv3\<and>dst=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: "(src=p__Inv4\<and>dst~=p__Inv3\<and>dst~=p__Inv4)" have "?P2 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume b1: "(src~=p__Inv3\<and>src~=p__Inv4\<and>dst=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: "(src=p__Inv3\<and>dst~=p__Inv3\<and>dst~=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: "(src~=p__Inv3\<and>src~=p__Inv4\<and>dst=p__Inv3)" have "?P2 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume b1: "(src~=p__Inv3\<and>src~=p__Inv4\<and>dst~=p__Inv3\<and>dst~=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_NI_Remote_Get_Put_HomeVsinv__4: assumes a1: "(\<exists> dst. dst\<le>N\<and>r=n_NI_Remote_Get_Put_Home dst)" and a2: "(\<exists> p__Inv3 p__Inv4. p__Inv3\<le>N\<and>p__Inv4\<le>N\<and>p__Inv3~=p__Inv4\<and>f=inv__4 p__Inv3 p__Inv4)" shows "invHoldForRule s f r (invariants N)" (is "?P1 s \<or> ?P2 s \<or> ?P3 s") proof - from a1 obtain dst where a1:"dst\<le>N\<and>r=n_NI_Remote_Get_Put_Home dst" 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__4 p__Inv3 p__Inv4" apply fastforce done have "(dst=p__Inv4)\<or>(dst=p__Inv3)\<or>(dst~=p__Inv3\<and>dst~=p__Inv4)" apply (cut_tac a1 a2, auto) done moreover { assume b1: "(dst=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: "(dst=p__Inv3)" have "?P2 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume b1: "(dst~=p__Inv3\<and>dst~=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_NI_Local_GetX_Nak__part__0Vsinv__4: assumes a1: "(\<exists> src. src\<le>N\<and>r=n_NI_Local_GetX_Nak__part__0 src)" and a2: "(\<exists> p__Inv3 p__Inv4. p__Inv3\<le>N\<and>p__Inv4\<le>N\<and>p__Inv3~=p__Inv4\<and>f=inv__4 p__Inv3 p__Inv4)" shows "invHoldForRule s f r (invariants N)" (is "?P1 s \<or> ?P2 s \<or> ?P3 s") proof - from a1 obtain src where a1:"src\<le>N\<and>r=n_NI_Local_GetX_Nak__part__0 src" 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__4 p__Inv3 p__Inv4" apply fastforce done have "(src=p__Inv4)\<or>(src=p__Inv3)\<or>(src~=p__Inv3\<and>src~=p__Inv4)" apply (cut_tac a1 a2, auto) done moreover { assume b1: "(src=p__Inv4)" have "?P2 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume b1: "(src=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: "(src~=p__Inv3\<and>src~=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_NI_Local_GetX_Nak__part__1Vsinv__4: assumes a1: "(\<exists> src. src\<le>N\<and>r=n_NI_Local_GetX_Nak__part__1 src)" and a2: "(\<exists> p__Inv3 p__Inv4. p__Inv3\<le>N\<and>p__Inv4\<le>N\<and>p__Inv3~=p__Inv4\<and>f=inv__4 p__Inv3 p__Inv4)" shows "invHoldForRule s f r (invariants N)" (is "?P1 s \<or> ?P2 s \<or> ?P3 s") proof - from a1 obtain src where a1:"src\<le>N\<and>r=n_NI_Local_GetX_Nak__part__1 src" 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__4 p__Inv3 p__Inv4" apply fastforce done have "(src=p__Inv4)\<or>(src=p__Inv3)\<or>(src~=p__Inv3\<and>src~=p__Inv4)" apply (cut_tac a1 a2, auto) done moreover { assume b1: "(src=p__Inv4)" have "?P2 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume b1: "(src=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: "(src~=p__Inv3\<and>src~=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_NI_Local_GetX_Nak__part__2Vsinv__4: assumes a1: "(\<exists> src. src\<le>N\<and>r=n_NI_Local_GetX_Nak__part__2 src)" and a2: "(\<exists> p__Inv3 p__Inv4. p__Inv3\<le>N\<and>p__Inv4\<le>N\<and>p__Inv3~=p__Inv4\<and>f=inv__4 p__Inv3 p__Inv4)" shows "invHoldForRule s f r (invariants N)" (is "?P1 s \<or> ?P2 s \<or> ?P3 s") proof - from a1 obtain src where a1:"src\<le>N\<and>r=n_NI_Local_GetX_Nak__part__2 src" 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__4 p__Inv3 p__Inv4" apply fastforce done have "(src=p__Inv4)\<or>(src=p__Inv3)\<or>(src~=p__Inv3\<and>src~=p__Inv4)" apply (cut_tac a1 a2, auto) done moreover { assume b1: "(src=p__Inv4)" have "?P2 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume b1: "(src=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: "(src~=p__Inv3\<and>src~=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_NI_Local_GetX_GetX__part__0Vsinv__4: assumes a1: "(\<exists> src. src\<le>N\<and>r=n_NI_Local_GetX_GetX__part__0 src)" and a2: "(\<exists> p__Inv3 p__Inv4. p__Inv3\<le>N\<and>p__Inv4\<le>N\<and>p__Inv3~=p__Inv4\<and>f=inv__4 p__Inv3 p__Inv4)" shows "invHoldForRule s f r (invariants N)" (is "?P1 s \<or> ?P2 s \<or> ?P3 s") proof - from a1 obtain src where a1:"src\<le>N\<and>r=n_NI_Local_GetX_GetX__part__0 src" 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__4 p__Inv3 p__Inv4" apply fastforce done have "(src=p__Inv4)\<or>(src=p__Inv3)\<or>(src~=p__Inv3\<and>src~=p__Inv4)" apply (cut_tac a1 a2, auto) done moreover { assume b1: "(src=p__Inv4)" have "?P2 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume b1: "(src=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: "(src~=p__Inv3\<and>src~=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_NI_Local_GetX_GetX__part__1Vsinv__4: assumes a1: "(\<exists> src. src\<le>N\<and>r=n_NI_Local_GetX_GetX__part__1 src)" and a2: "(\<exists> p__Inv3 p__Inv4. p__Inv3\<le>N\<and>p__Inv4\<le>N\<and>p__Inv3~=p__Inv4\<and>f=inv__4 p__Inv3 p__Inv4)" shows "invHoldForRule s f r (invariants N)" (is "?P1 s \<or> ?P2 s \<or> ?P3 s") proof - from a1 obtain src where a1:"src\<le>N\<and>r=n_NI_Local_GetX_GetX__part__1 src" 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__4 p__Inv3 p__Inv4" apply fastforce done have "(src=p__Inv4)\<or>(src=p__Inv3)\<or>(src~=p__Inv3\<and>src~=p__Inv4)" apply (cut_tac a1 a2, auto) done moreover { assume b1: "(src=p__Inv4)" have "?P2 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume b1: "(src=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: "(src~=p__Inv3\<and>src~=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_NI_Local_GetX_PutX_1Vsinv__4: assumes a1: "(\<exists> src. src\<le>N\<and>r=n_NI_Local_GetX_PutX_1 N src)" and a2: "(\<exists> p__Inv3 p__Inv4. p__Inv3\<le>N\<and>p__Inv4\<le>N\<and>p__Inv3~=p__Inv4\<and>f=inv__4 p__Inv3 p__Inv4)" shows "invHoldForRule s f r (invariants N)" (is "?P1 s \<or> ?P2 s \<or> ?P3 s") proof - from a1 obtain src where a1:"src\<le>N\<and>r=n_NI_Local_GetX_PutX_1 N src" 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__4 p__Inv3 p__Inv4" apply fastforce done have "(src=p__Inv4)\<or>(src=p__Inv3)\<or>(src~=p__Inv3\<and>src~=p__Inv4)" apply (cut_tac a1 a2, auto) done moreover { assume b1: "(src=p__Inv4)" have "?P2 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume b1: "(src=p__Inv3)" have "?P3 s" apply (cut_tac a1 a2 b1, simp, rule_tac x="(neg (andForm (eqn (IVar (Field (Para (Field (Ident ''Sta'') ''Proc'') p__Inv4) ''CacheState'')) (Const CACHE_E)) (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''Dirty'')) (Const false))))" in exI, auto) done then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume b1: "(src~=p__Inv3\<and>src~=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_NI_Local_GetX_PutX_2Vsinv__4: assumes a1: "(\<exists> src. src\<le>N\<and>r=n_NI_Local_GetX_PutX_2 N src)" and a2: "(\<exists> p__Inv3 p__Inv4. p__Inv3\<le>N\<and>p__Inv4\<le>N\<and>p__Inv3~=p__Inv4\<and>f=inv__4 p__Inv3 p__Inv4)" shows "invHoldForRule s f r (invariants N)" (is "?P1 s \<or> ?P2 s \<or> ?P3 s") proof - from a1 obtain src where a1:"src\<le>N\<and>r=n_NI_Local_GetX_PutX_2 N src" 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__4 p__Inv3 p__Inv4" apply fastforce done have "(src=p__Inv4)\<or>(src=p__Inv3)\<or>(src~=p__Inv3\<and>src~=p__Inv4)" apply (cut_tac a1 a2, auto) done moreover { assume b1: "(src=p__Inv4)" have "?P2 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume b1: "(src=p__Inv3)" have "?P3 s" apply (cut_tac a1 a2 b1, simp, rule_tac x="(neg (andForm (eqn (IVar (Field (Para (Field (Ident ''Sta'') ''Proc'') p__Inv4) ''CacheState'')) (Const CACHE_E)) (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''Dirty'')) (Const false))))" in exI, auto) done then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume b1: "(src~=p__Inv3\<and>src~=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_NI_Local_GetX_PutX_3Vsinv__4: assumes a1: "(\<exists> src. src\<le>N\<and>r=n_NI_Local_GetX_PutX_3 N src)" and a2: "(\<exists> p__Inv3 p__Inv4. p__Inv3\<le>N\<and>p__Inv4\<le>N\<and>p__Inv3~=p__Inv4\<and>f=inv__4 p__Inv3 p__Inv4)" shows "invHoldForRule s f r (invariants N)" (is "?P1 s \<or> ?P2 s \<or> ?P3 s") proof - from a1 obtain src where a1:"src\<le>N\<and>r=n_NI_Local_GetX_PutX_3 N src" 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__4 p__Inv3 p__Inv4" apply fastforce done have "(src=p__Inv4)\<or>(src=p__Inv3)\<or>(src~=p__Inv3\<and>src~=p__Inv4)" apply (cut_tac a1 a2, auto) done moreover { assume b1: "(src=p__Inv4)" have "?P2 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume b1: "(src=p__Inv3)" have "?P3 s" apply (cut_tac a1 a2 b1, simp, rule_tac x="(neg (andForm (eqn (IVar (Field (Para (Field (Ident ''Sta'') ''Proc'') p__Inv4) ''CacheState'')) (Const CACHE_E)) (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''Dirty'')) (Const false))))" in exI, auto) done then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume b1: "(src~=p__Inv3\<and>src~=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_NI_Local_GetX_PutX_4Vsinv__4: assumes a1: "(\<exists> src. src\<le>N\<and>r=n_NI_Local_GetX_PutX_4 N src)" and a2: "(\<exists> p__Inv3 p__Inv4. p__Inv3\<le>N\<and>p__Inv4\<le>N\<and>p__Inv3~=p__Inv4\<and>f=inv__4 p__Inv3 p__Inv4)" shows "invHoldForRule s f r (invariants N)" (is "?P1 s \<or> ?P2 s \<or> ?P3 s") proof - from a1 obtain src where a1:"src\<le>N\<and>r=n_NI_Local_GetX_PutX_4 N src" 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__4 p__Inv3 p__Inv4" apply fastforce done have "(src=p__Inv4)\<or>(src=p__Inv3)\<or>(src~=p__Inv3\<and>src~=p__Inv4)" apply (cut_tac a1 a2, auto) done moreover { assume b1: "(src=p__Inv4)" have "?P2 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume b1: "(src=p__Inv3)" have "?P3 s" apply (cut_tac a1 a2 b1, simp, rule_tac x="(neg (andForm (eqn (IVar (Field (Para (Field (Ident ''Sta'') ''Proc'') p__Inv4) ''CacheState'')) (Const CACHE_E)) (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''Dirty'')) (Const false))))" in exI, auto) done then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume b1: "(src~=p__Inv3\<and>src~=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_NI_Local_GetX_PutX_5Vsinv__4: assumes a1: "(\<exists> src. src\<le>N\<and>r=n_NI_Local_GetX_PutX_5 N src)" and a2: "(\<exists> p__Inv3 p__Inv4. p__Inv3\<le>N\<and>p__Inv4\<le>N\<and>p__Inv3~=p__Inv4\<and>f=inv__4 p__Inv3 p__Inv4)" shows "invHoldForRule s f r (invariants N)" (is "?P1 s \<or> ?P2 s \<or> ?P3 s") proof - from a1 obtain src where a1:"src\<le>N\<and>r=n_NI_Local_GetX_PutX_5 N src" 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__4 p__Inv3 p__Inv4" apply fastforce done have "(src=p__Inv4)\<or>(src=p__Inv3)\<or>(src~=p__Inv3\<and>src~=p__Inv4)" apply (cut_tac a1 a2, auto) done moreover { assume b1: "(src=p__Inv4)" have "?P2 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume b1: "(src=p__Inv3)" have "?P3 s" apply (cut_tac a1 a2 b1, simp, rule_tac x="(neg (andForm (eqn (IVar (Field (Para (Field (Ident ''Sta'') ''Proc'') p__Inv4) ''CacheState'')) (Const CACHE_E)) (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''Dirty'')) (Const false))))" in exI, auto) done then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume b1: "(src~=p__Inv3\<and>src~=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_NI_Local_GetX_PutX_6Vsinv__4: assumes a1: "(\<exists> src. src\<le>N\<and>r=n_NI_Local_GetX_PutX_6 N src)" and a2: "(\<exists> p__Inv3 p__Inv4. p__Inv3\<le>N\<and>p__Inv4\<le>N\<and>p__Inv3~=p__Inv4\<and>f=inv__4 p__Inv3 p__Inv4)" shows "invHoldForRule s f r (invariants N)" (is "?P1 s \<or> ?P2 s \<or> ?P3 s") proof - from a1 obtain src where a1:"src\<le>N\<and>r=n_NI_Local_GetX_PutX_6 N src" 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__4 p__Inv3 p__Inv4" apply fastforce done have "(src=p__Inv4)\<or>(src=p__Inv3)\<or>(src~=p__Inv3\<and>src~=p__Inv4)" apply (cut_tac a1 a2, auto) done moreover { assume b1: "(src=p__Inv4)" have "?P2 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume b1: "(src=p__Inv3)" have "?P3 s" apply (cut_tac a1 a2 b1, simp, rule_tac x="(neg (andForm (eqn (IVar (Field (Para (Field (Ident ''Sta'') ''Proc'') p__Inv4) ''CacheState'')) (Const CACHE_E)) (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''Dirty'')) (Const false))))" in exI, auto) done then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume b1: "(src~=p__Inv3\<and>src~=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_NI_Local_GetX_PutX_7__part__0Vsinv__4: assumes a1: "(\<exists> src. src\<le>N\<and>r=n_NI_Local_GetX_PutX_7__part__0 N src)" and a2: "(\<exists> p__Inv3 p__Inv4. p__Inv3\<le>N\<and>p__Inv4\<le>N\<and>p__Inv3~=p__Inv4\<and>f=inv__4 p__Inv3 p__Inv4)" shows "invHoldForRule s f r (invariants N)" (is "?P1 s \<or> ?P2 s \<or> ?P3 s") proof - from a1 obtain src where a1:"src\<le>N\<and>r=n_NI_Local_GetX_PutX_7__part__0 N src" 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__4 p__Inv3 p__Inv4" apply fastforce done have "(src=p__Inv4)\<or>(src=p__Inv3)\<or>(src~=p__Inv3\<and>src~=p__Inv4)" apply (cut_tac a1 a2, auto) done moreover { assume b1: "(src=p__Inv4)" have "?P2 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume b1: "(src=p__Inv3)" have "?P3 s" apply (cut_tac a1 a2 b1, simp, rule_tac x="(neg (andForm (eqn (IVar (Field (Para (Field (Ident ''Sta'') ''Proc'') p__Inv4) ''CacheState'')) (Const CACHE_E)) (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''Dirty'')) (Const false))))" in exI, auto) done then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume b1: "(src~=p__Inv3\<and>src~=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_NI_Local_GetX_PutX_7__part__1Vsinv__4: assumes a1: "(\<exists> src. src\<le>N\<and>r=n_NI_Local_GetX_PutX_7__part__1 N src)" and a2: "(\<exists> p__Inv3 p__Inv4. p__Inv3\<le>N\<and>p__Inv4\<le>N\<and>p__Inv3~=p__Inv4\<and>f=inv__4 p__Inv3 p__Inv4)" shows "invHoldForRule s f r (invariants N)" (is "?P1 s \<or> ?P2 s \<or> ?P3 s") proof - from a1 obtain src where a1:"src\<le>N\<and>r=n_NI_Local_GetX_PutX_7__part__1 N src" 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__4 p__Inv3 p__Inv4" apply fastforce done have "(src=p__Inv4)\<or>(src=p__Inv3)\<or>(src~=p__Inv3\<and>src~=p__Inv4)" apply (cut_tac a1 a2, auto) done moreover { assume b1: "(src=p__Inv4)" have "?P2 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume b1: "(src=p__Inv3)" have "?P3 s" apply (cut_tac a1 a2 b1, simp, rule_tac x="(neg (andForm (eqn (IVar (Field (Para (Field (Ident ''Sta'') ''Proc'') p__Inv4) ''CacheState'')) (Const CACHE_E)) (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''Dirty'')) (Const false))))" in exI, auto) done then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume b1: "(src~=p__Inv3\<and>src~=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_NI_Local_GetX_PutX_7_NODE_Get__part__0Vsinv__4: assumes a1: "(\<exists> src. src\<le>N\<and>r=n_NI_Local_GetX_PutX_7_NODE_Get__part__0 N src)" and a2: "(\<exists> p__Inv3 p__Inv4. p__Inv3\<le>N\<and>p__Inv4\<le>N\<and>p__Inv3~=p__Inv4\<and>f=inv__4 p__Inv3 p__Inv4)" shows "invHoldForRule s f r (invariants N)" (is "?P1 s \<or> ?P2 s \<or> ?P3 s") proof - from a1 obtain src where a1:"src\<le>N\<and>r=n_NI_Local_GetX_PutX_7_NODE_Get__part__0 N src" 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__4 p__Inv3 p__Inv4" apply fastforce done have "(src=p__Inv4)\<or>(src=p__Inv3)\<or>(src~=p__Inv3\<and>src~=p__Inv4)" apply (cut_tac a1 a2, auto) done moreover { assume b1: "(src=p__Inv4)" have "?P2 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume b1: "(src=p__Inv3)" have "?P3 s" apply (cut_tac a1 a2 b1, simp, rule_tac x="(neg (andForm (eqn (IVar (Field (Para (Field (Ident ''Sta'') ''Proc'') p__Inv4) ''CacheState'')) (Const CACHE_E)) (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''Dirty'')) (Const false))))" in exI, auto) done then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume b1: "(src~=p__Inv3\<and>src~=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_NI_Local_GetX_PutX_7_NODE_Get__part__1Vsinv__4: assumes a1: "(\<exists> src. src\<le>N\<and>r=n_NI_Local_GetX_PutX_7_NODE_Get__part__1 N src)" and a2: "(\<exists> p__Inv3 p__Inv4. p__Inv3\<le>N\<and>p__Inv4\<le>N\<and>p__Inv3~=p__Inv4\<and>f=inv__4 p__Inv3 p__Inv4)" shows "invHoldForRule s f r (invariants N)" (is "?P1 s \<or> ?P2 s \<or> ?P3 s") proof - from a1 obtain src where a1:"src\<le>N\<and>r=n_NI_Local_GetX_PutX_7_NODE_Get__part__1 N src" 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__4 p__Inv3 p__Inv4" apply fastforce done have "(src=p__Inv4)\<or>(src=p__Inv3)\<or>(src~=p__Inv3\<and>src~=p__Inv4)" apply (cut_tac a1 a2, auto) done moreover { assume b1: "(src=p__Inv4)" have "?P2 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume b1: "(src=p__Inv3)" have "?P3 s" apply (cut_tac a1 a2 b1, simp, rule_tac x="(neg (andForm (eqn (IVar (Field (Para (Field (Ident ''Sta'') ''Proc'') p__Inv4) ''CacheState'')) (Const CACHE_E)) (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''Dirty'')) (Const false))))" in exI, auto) done then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume b1: "(src~=p__Inv3\<and>src~=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_NI_Local_GetX_PutX_8_HomeVsinv__4: assumes a1: "(\<exists> src. src\<le>N\<and>r=n_NI_Local_GetX_PutX_8_Home N src)" and a2: "(\<exists> p__Inv3 p__Inv4. p__Inv3\<le>N\<and>p__Inv4\<le>N\<and>p__Inv3~=p__Inv4\<and>f=inv__4 p__Inv3 p__Inv4)" shows "invHoldForRule s f r (invariants N)" (is "?P1 s \<or> ?P2 s \<or> ?P3 s") proof - from a1 obtain src where a1:"src\<le>N\<and>r=n_NI_Local_GetX_PutX_8_Home N src" 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__4 p__Inv3 p__Inv4" apply fastforce done have "(src=p__Inv4)\<or>(src=p__Inv3)\<or>(src~=p__Inv3\<and>src~=p__Inv4)" apply (cut_tac a1 a2, auto) done moreover { assume b1: "(src=p__Inv4)" have "?P2 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume b1: "(src=p__Inv3)" have "?P3 s" apply (cut_tac a1 a2 b1, simp, rule_tac x="(neg (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''HomeShrSet'')) (Const true)))" in exI, auto) done then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume b1: "(src~=p__Inv3\<and>src~=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_NI_Local_GetX_PutX_8_Home_NODE_GetVsinv__4: assumes a1: "(\<exists> src. src\<le>N\<and>r=n_NI_Local_GetX_PutX_8_Home_NODE_Get N src)" and a2: "(\<exists> p__Inv3 p__Inv4. p__Inv3\<le>N\<and>p__Inv4\<le>N\<and>p__Inv3~=p__Inv4\<and>f=inv__4 p__Inv3 p__Inv4)" shows "invHoldForRule s f r (invariants N)" (is "?P1 s \<or> ?P2 s \<or> ?P3 s") proof - from a1 obtain src where a1:"src\<le>N\<and>r=n_NI_Local_GetX_PutX_8_Home_NODE_Get N src" 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__4 p__Inv3 p__Inv4" apply fastforce done have "(src=p__Inv4)\<or>(src=p__Inv3)\<or>(src~=p__Inv3\<and>src~=p__Inv4)" apply (cut_tac a1 a2, auto) done moreover { assume b1: "(src=p__Inv4)" have "?P2 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume b1: "(src=p__Inv3)" have "?P3 s" apply (cut_tac a1 a2 b1, simp, rule_tac x="(neg (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''HomeShrSet'')) (Const true)))" in exI, auto) done then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume b1: "(src~=p__Inv3\<and>src~=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_NI_Local_GetX_PutX_8Vsinv__4: assumes a1: "(\<exists> src pp. src\<le>N\<and>pp\<le>N\<and>src~=pp\<and>r=n_NI_Local_GetX_PutX_8 N src pp)" and a2: "(\<exists> p__Inv3 p__Inv4. p__Inv3\<le>N\<and>p__Inv4\<le>N\<and>p__Inv3~=p__Inv4\<and>f=inv__4 p__Inv3 p__Inv4)" shows "invHoldForRule s f r (invariants N)" (is "?P1 s \<or> ?P2 s \<or> ?P3 s") proof - from a1 obtain src pp where a1:"src\<le>N\<and>pp\<le>N\<and>src~=pp\<and>r=n_NI_Local_GetX_PutX_8 N src pp" 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__4 p__Inv3 p__Inv4" apply fastforce done have "(src=p__Inv4\<and>pp=p__Inv3)\<or>(src=p__Inv3\<and>pp=p__Inv4)\<or>(src=p__Inv4\<and>pp~=p__Inv3\<and>pp~=p__Inv4)\<or>(src~=p__Inv3\<and>src~=p__Inv4\<and>pp=p__Inv4)\<or>(src=p__Inv3\<and>pp~=p__Inv3\<and>pp~=p__Inv4)\<or>(src~=p__Inv3\<and>src~=p__Inv4\<and>pp=p__Inv3)\<or>(src~=p__Inv3\<and>src~=p__Inv4\<and>pp~=p__Inv3\<and>pp~=p__Inv4)" apply (cut_tac a1 a2, auto) done moreover { assume b1: "(src=p__Inv4\<and>pp=p__Inv3)" have "?P2 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume b1: "(src=p__Inv3\<and>pp=p__Inv4)" have "?P3 s" apply (cut_tac a1 a2 b1, simp, rule_tac x="(neg (andForm (eqn (IVar (Field (Para (Field (Ident ''Sta'') ''Proc'') p__Inv4) ''CacheState'')) (Const CACHE_E)) (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''Dirty'')) (Const false))))" in exI, auto) done then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume b1: "(src=p__Inv4\<and>pp~=p__Inv3\<and>pp~=p__Inv4)" have "?P2 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume b1: "(src~=p__Inv3\<and>src~=p__Inv4\<and>pp=p__Inv4)" have "?P2 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume b1: "(src=p__Inv3\<and>pp~=p__Inv3\<and>pp~=p__Inv4)" have "?P3 s" apply (cut_tac a1 a2 b1, simp, rule_tac x="(neg (andForm (eqn (IVar (Field (Para (Field (Ident ''Sta'') ''Proc'') p__Inv4) ''CacheState'')) (Const CACHE_E)) (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''Dirty'')) (Const false))))" in exI, auto) done then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume b1: "(src~=p__Inv3\<and>src~=p__Inv4\<and>pp=p__Inv3)" have "?P2 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume b1: "(src~=p__Inv3\<and>src~=p__Inv4\<and>pp~=p__Inv3\<and>pp~=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_NI_Local_GetX_PutX_8_NODE_GetVsinv__4: assumes a1: "(\<exists> src pp. src\<le>N\<and>pp\<le>N\<and>src~=pp\<and>r=n_NI_Local_GetX_PutX_8_NODE_Get N src pp)" and a2: "(\<exists> p__Inv3 p__Inv4. p__Inv3\<le>N\<and>p__Inv4\<le>N\<and>p__Inv3~=p__Inv4\<and>f=inv__4 p__Inv3 p__Inv4)" shows "invHoldForRule s f r (invariants N)" (is "?P1 s \<or> ?P2 s \<or> ?P3 s") proof - from a1 obtain src pp where a1:"src\<le>N\<and>pp\<le>N\<and>src~=pp\<and>r=n_NI_Local_GetX_PutX_8_NODE_Get N src pp" 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__4 p__Inv3 p__Inv4" apply fastforce done have "(src=p__Inv4\<and>pp=p__Inv3)\<or>(src=p__Inv3\<and>pp=p__Inv4)\<or>(src=p__Inv4\<and>pp~=p__Inv3\<and>pp~=p__Inv4)\<or>(src~=p__Inv3\<and>src~=p__Inv4\<and>pp=p__Inv4)\<or>(src=p__Inv3\<and>pp~=p__Inv3\<and>pp~=p__Inv4)\<or>(src~=p__Inv3\<and>src~=p__Inv4\<and>pp=p__Inv3)\<or>(src~=p__Inv3\<and>src~=p__Inv4\<and>pp~=p__Inv3\<and>pp~=p__Inv4)" apply (cut_tac a1 a2, auto) done moreover { assume b1: "(src=p__Inv4\<and>pp=p__Inv3)" have "?P2 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume b1: "(src=p__Inv3\<and>pp=p__Inv4)" have "?P3 s" apply (cut_tac a1 a2 b1, simp, rule_tac x="(neg (andForm (eqn (IVar (Field (Para (Field (Ident ''Sta'') ''Proc'') p__Inv4) ''CacheState'')) (Const CACHE_E)) (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''Dirty'')) (Const false))))" in exI, auto) done then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume b1: "(src=p__Inv4\<and>pp~=p__Inv3\<and>pp~=p__Inv4)" have "?P2 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume b1: "(src~=p__Inv3\<and>src~=p__Inv4\<and>pp=p__Inv4)" have "?P2 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume b1: "(src=p__Inv3\<and>pp~=p__Inv3\<and>pp~=p__Inv4)" have "?P3 s" apply (cut_tac a1 a2 b1, simp, rule_tac x="(neg (andForm (eqn (IVar (Field (Para (Field (Ident ''Sta'') ''Proc'') p__Inv4) ''CacheState'')) (Const CACHE_E)) (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''Dirty'')) (Const false))))" in exI, auto) done then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume b1: "(src~=p__Inv3\<and>src~=p__Inv4\<and>pp=p__Inv3)" have "?P2 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume b1: "(src~=p__Inv3\<and>src~=p__Inv4\<and>pp~=p__Inv3\<and>pp~=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_NI_Local_GetX_PutX_9__part__0Vsinv__4: assumes a1: "(\<exists> src. src\<le>N\<and>r=n_NI_Local_GetX_PutX_9__part__0 N src)" and a2: "(\<exists> p__Inv3 p__Inv4. p__Inv3\<le>N\<and>p__Inv4\<le>N\<and>p__Inv3~=p__Inv4\<and>f=inv__4 p__Inv3 p__Inv4)" shows "invHoldForRule s f r (invariants N)" (is "?P1 s \<or> ?P2 s \<or> ?P3 s") proof - from a1 obtain src where a1:"src\<le>N\<and>r=n_NI_Local_GetX_PutX_9__part__0 N src" 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__4 p__Inv3 p__Inv4" apply fastforce done have "(src=p__Inv4)\<or>(src=p__Inv3)\<or>(src~=p__Inv3\<and>src~=p__Inv4)" apply (cut_tac a1 a2, auto) done moreover { assume b1: "(src=p__Inv4)" have "?P2 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume b1: "(src=p__Inv3)" have "?P3 s" apply (cut_tac a1 a2 b1, simp, rule_tac x="(neg (andForm (eqn (IVar (Field (Para (Field (Ident ''Sta'') ''Proc'') p__Inv4) ''CacheState'')) (Const CACHE_E)) (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''Dirty'')) (Const false))))" in exI, auto) done then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume b1: "(src~=p__Inv3\<and>src~=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_NI_Local_GetX_PutX_9__part__1Vsinv__4: assumes a1: "(\<exists> src. src\<le>N\<and>r=n_NI_Local_GetX_PutX_9__part__1 N src)" and a2: "(\<exists> p__Inv3 p__Inv4. p__Inv3\<le>N\<and>p__Inv4\<le>N\<and>p__Inv3~=p__Inv4\<and>f=inv__4 p__Inv3 p__Inv4)" shows "invHoldForRule s f r (invariants N)" (is "?P1 s \<or> ?P2 s \<or> ?P3 s") proof - from a1 obtain src where a1:"src\<le>N\<and>r=n_NI_Local_GetX_PutX_9__part__1 N src" 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__4 p__Inv3 p__Inv4" apply fastforce done have "(src=p__Inv4)\<or>(src=p__Inv3)\<or>(src~=p__Inv3\<and>src~=p__Inv4)" apply (cut_tac a1 a2, auto) done moreover { assume b1: "(src=p__Inv4)" have "?P2 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume b1: "(src=p__Inv3)" have "?P3 s" apply (cut_tac a1 a2 b1, simp, rule_tac x="(neg (andForm (eqn (IVar (Field (Para (Field (Ident ''Sta'') ''Proc'') p__Inv4) ''CacheState'')) (Const CACHE_E)) (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''Dirty'')) (Const false))))" in exI, auto) done then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume b1: "(src~=p__Inv3\<and>src~=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_NI_Local_GetX_PutX_10_HomeVsinv__4: assumes a1: "(\<exists> src. src\<le>N\<and>r=n_NI_Local_GetX_PutX_10_Home N src)" and a2: "(\<exists> p__Inv3 p__Inv4. p__Inv3\<le>N\<and>p__Inv4\<le>N\<and>p__Inv3~=p__Inv4\<and>f=inv__4 p__Inv3 p__Inv4)" shows "invHoldForRule s f r (invariants N)" (is "?P1 s \<or> ?P2 s \<or> ?P3 s") proof - from a1 obtain src where a1:"src\<le>N\<and>r=n_NI_Local_GetX_PutX_10_Home N src" 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__4 p__Inv3 p__Inv4" apply fastforce done have "(src=p__Inv4)\<or>(src=p__Inv3)\<or>(src~=p__Inv3\<and>src~=p__Inv4)" apply (cut_tac a1 a2, auto) done moreover { assume b1: "(src=p__Inv4)" have "?P2 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume b1: "(src=p__Inv3)" have "?P3 s" apply (cut_tac a1 a2 b1, simp, rule_tac x="(neg (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''HomeShrSet'')) (Const true)))" in exI, auto) done then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume b1: "(src~=p__Inv3\<and>src~=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_NI_Local_GetX_PutX_10Vsinv__4: assumes a1: "(\<exists> src pp. src\<le>N\<and>pp\<le>N\<and>src~=pp\<and>r=n_NI_Local_GetX_PutX_10 N src pp)" and a2: "(\<exists> p__Inv3 p__Inv4. p__Inv3\<le>N\<and>p__Inv4\<le>N\<and>p__Inv3~=p__Inv4\<and>f=inv__4 p__Inv3 p__Inv4)" shows "invHoldForRule s f r (invariants N)" (is "?P1 s \<or> ?P2 s \<or> ?P3 s") proof - from a1 obtain src pp where a1:"src\<le>N\<and>pp\<le>N\<and>src~=pp\<and>r=n_NI_Local_GetX_PutX_10 N src pp" 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__4 p__Inv3 p__Inv4" apply fastforce done have "(src=p__Inv4\<and>pp=p__Inv3)\<or>(src=p__Inv3\<and>pp=p__Inv4)\<or>(src=p__Inv4\<and>pp~=p__Inv3\<and>pp~=p__Inv4)\<or>(src~=p__Inv3\<and>src~=p__Inv4\<and>pp=p__Inv4)\<or>(src=p__Inv3\<and>pp~=p__Inv3\<and>pp~=p__Inv4)\<or>(src~=p__Inv3\<and>src~=p__Inv4\<and>pp=p__Inv3)\<or>(src~=p__Inv3\<and>src~=p__Inv4\<and>pp~=p__Inv3\<and>pp~=p__Inv4)" apply (cut_tac a1 a2, auto) done moreover { assume b1: "(src=p__Inv4\<and>pp=p__Inv3)" have "?P2 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume b1: "(src=p__Inv3\<and>pp=p__Inv4)" have "?P3 s" apply (cut_tac a1 a2 b1, simp, rule_tac x="(neg (andForm (eqn (IVar (Field (Para (Field (Ident ''Sta'') ''Proc'') p__Inv4) ''CacheState'')) (Const CACHE_E)) (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''Dirty'')) (Const false))))" in exI, auto) done then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume b1: "(src=p__Inv4\<and>pp~=p__Inv3\<and>pp~=p__Inv4)" have "?P2 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume b1: "(src~=p__Inv3\<and>src~=p__Inv4\<and>pp=p__Inv4)" have "?P2 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume b1: "(src=p__Inv3\<and>pp~=p__Inv3\<and>pp~=p__Inv4)" have "?P3 s" apply (cut_tac a1 a2 b1, simp, rule_tac x="(neg (andForm (eqn (IVar (Field (Para (Field (Ident ''Sta'') ''Proc'') p__Inv4) ''CacheState'')) (Const CACHE_E)) (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''Dirty'')) (Const false))))" in exI, auto) done then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume b1: "(src~=p__Inv3\<and>src~=p__Inv4\<and>pp=p__Inv3)" have "?P2 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume b1: "(src~=p__Inv3\<and>src~=p__Inv4\<and>pp~=p__Inv3\<and>pp~=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_NI_Local_GetX_PutX_11Vsinv__4: assumes a1: "(\<exists> src. src\<le>N\<and>r=n_NI_Local_GetX_PutX_11 N src)" and a2: "(\<exists> p__Inv3 p__Inv4. p__Inv3\<le>N\<and>p__Inv4\<le>N\<and>p__Inv3~=p__Inv4\<and>f=inv__4 p__Inv3 p__Inv4)" shows "invHoldForRule s f r (invariants N)" (is "?P1 s \<or> ?P2 s \<or> ?P3 s") proof - from a1 obtain src where a1:"src\<le>N\<and>r=n_NI_Local_GetX_PutX_11 N src" 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__4 p__Inv3 p__Inv4" apply fastforce done have "(src=p__Inv4)\<or>(src=p__Inv3)\<or>(src~=p__Inv3\<and>src~=p__Inv4)" apply (cut_tac a1 a2, auto) done moreover { assume b1: "(src=p__Inv4)" have "?P2 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume b1: "(src=p__Inv3)" have "?P3 s" apply (cut_tac a1 a2 b1, simp, rule_tac x="(neg (andForm (eqn (IVar (Field (Para (Field (Ident ''Sta'') ''Proc'') p__Inv4) ''CacheState'')) (Const CACHE_E)) (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''Local'')) (Const true))))" in exI, auto) done then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume b1: "(src~=p__Inv3\<and>src~=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_NI_Remote_GetX_NakVsinv__4: assumes a1: "(\<exists> src dst. src\<le>N\<and>dst\<le>N\<and>src~=dst\<and>r=n_NI_Remote_GetX_Nak src dst)" and a2: "(\<exists> p__Inv3 p__Inv4. p__Inv3\<le>N\<and>p__Inv4\<le>N\<and>p__Inv3~=p__Inv4\<and>f=inv__4 p__Inv3 p__Inv4)" shows "invHoldForRule s f r (invariants N)" (is "?P1 s \<or> ?P2 s \<or> ?P3 s") proof - from a1 obtain src dst where a1:"src\<le>N\<and>dst\<le>N\<and>src~=dst\<and>r=n_NI_Remote_GetX_Nak src dst" 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__4 p__Inv3 p__Inv4" apply fastforce done have "(src=p__Inv4\<and>dst=p__Inv3)\<or>(src=p__Inv3\<and>dst=p__Inv4)\<or>(src=p__Inv4\<and>dst~=p__Inv3\<and>dst~=p__Inv4)\<or>(src~=p__Inv3\<and>src~=p__Inv4\<and>dst=p__Inv4)\<or>(src=p__Inv3\<and>dst~=p__Inv3\<and>dst~=p__Inv4)\<or>(src~=p__Inv3\<and>src~=p__Inv4\<and>dst=p__Inv3)\<or>(src~=p__Inv3\<and>src~=p__Inv4\<and>dst~=p__Inv3\<and>dst~=p__Inv4)" apply (cut_tac a1 a2, auto) done moreover { assume b1: "(src=p__Inv4\<and>dst=p__Inv3)" have "?P2 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume b1: "(src=p__Inv3\<and>dst=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: "(src=p__Inv4\<and>dst~=p__Inv3\<and>dst~=p__Inv4)" have "?P2 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume b1: "(src~=p__Inv3\<and>src~=p__Inv4\<and>dst=p__Inv4)" have "?P2 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume b1: "(src=p__Inv3\<and>dst~=p__Inv3\<and>dst~=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: "(src~=p__Inv3\<and>src~=p__Inv4\<and>dst=p__Inv3)" have "?P2 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume b1: "(src~=p__Inv3\<and>src~=p__Inv4\<and>dst~=p__Inv3\<and>dst~=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_NI_Remote_GetX_PutXVsinv__4: assumes a1: "(\<exists> src dst. src\<le>N\<and>dst\<le>N\<and>src~=dst\<and>r=n_NI_Remote_GetX_PutX src dst)" and a2: "(\<exists> p__Inv3 p__Inv4. p__Inv3\<le>N\<and>p__Inv4\<le>N\<and>p__Inv3~=p__Inv4\<and>f=inv__4 p__Inv3 p__Inv4)" shows "invHoldForRule s f r (invariants N)" (is "?P1 s \<or> ?P2 s \<or> ?P3 s") proof - from a1 obtain src dst where a1:"src\<le>N\<and>dst\<le>N\<and>src~=dst\<and>r=n_NI_Remote_GetX_PutX src dst" 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__4 p__Inv3 p__Inv4" apply fastforce done have "(src=p__Inv4\<and>dst=p__Inv3)\<or>(src=p__Inv3\<and>dst=p__Inv4)\<or>(src=p__Inv4\<and>dst~=p__Inv3\<and>dst~=p__Inv4)\<or>(src~=p__Inv3\<and>src~=p__Inv4\<and>dst=p__Inv4)\<or>(src=p__Inv3\<and>dst~=p__Inv3\<and>dst~=p__Inv4)\<or>(src~=p__Inv3\<and>src~=p__Inv4\<and>dst=p__Inv3)\<or>(src~=p__Inv3\<and>src~=p__Inv4\<and>dst~=p__Inv3\<and>dst~=p__Inv4)" apply (cut_tac a1 a2, auto) done moreover { assume b1: "(src=p__Inv4\<and>dst=p__Inv3)" have "?P2 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume b1: "(src=p__Inv3\<and>dst=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: "(src=p__Inv4\<and>dst~=p__Inv3\<and>dst~=p__Inv4)" have "?P2 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume b1: "(src~=p__Inv3\<and>src~=p__Inv4\<and>dst=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: "(src=p__Inv3\<and>dst~=p__Inv3\<and>dst~=p__Inv4)" have "?P3 s" apply (cut_tac a1 a2 b1, simp, rule_tac x="(neg (andForm (eqn (IVar (Field (Para (Field (Ident ''Sta'') ''Proc'') p__Inv4) ''CacheState'')) (Const CACHE_E)) (eqn (IVar (Field (Para (Field (Ident ''Sta'') ''Proc'') dst) ''CacheState'')) (Const CACHE_E))))" in exI, auto) done then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume b1: "(src~=p__Inv3\<and>src~=p__Inv4\<and>dst=p__Inv3)" have "?P2 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume b1: "(src~=p__Inv3\<and>src~=p__Inv4\<and>dst~=p__Inv3\<and>dst~=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_NI_Remote_GetX_PutX_HomeVsinv__4: assumes a1: "(\<exists> dst. dst\<le>N\<and>r=n_NI_Remote_GetX_PutX_Home dst)" and a2: "(\<exists> p__Inv3 p__Inv4. p__Inv3\<le>N\<and>p__Inv4\<le>N\<and>p__Inv3~=p__Inv4\<and>f=inv__4 p__Inv3 p__Inv4)" shows "invHoldForRule s f r (invariants N)" (is "?P1 s \<or> ?P2 s \<or> ?P3 s") proof - from a1 obtain dst where a1:"dst\<le>N\<and>r=n_NI_Remote_GetX_PutX_Home dst" 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__4 p__Inv3 p__Inv4" apply fastforce done have "(dst=p__Inv4)\<or>(dst=p__Inv3)\<or>(dst~=p__Inv3\<and>dst~=p__Inv4)" apply (cut_tac a1 a2, auto) done moreover { assume b1: "(dst=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: "(dst=p__Inv3)" have "?P2 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume b1: "(dst~=p__Inv3\<and>dst~=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_NI_Remote_PutVsinv__4: assumes a1: "(\<exists> dst. dst\<le>N\<and>r=n_NI_Remote_Put dst)" and a2: "(\<exists> p__Inv3 p__Inv4. p__Inv3\<le>N\<and>p__Inv4\<le>N\<and>p__Inv3~=p__Inv4\<and>f=inv__4 p__Inv3 p__Inv4)" shows "invHoldForRule s f r (invariants N)" (is "?P1 s \<or> ?P2 s \<or> ?P3 s") proof - from a1 obtain dst where a1:"dst\<le>N\<and>r=n_NI_Remote_Put dst" 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__4 p__Inv3 p__Inv4" apply fastforce done have "(dst=p__Inv4)\<or>(dst=p__Inv3)\<or>(dst~=p__Inv3\<and>dst~=p__Inv4)" apply (cut_tac a1 a2, auto) done moreover { assume b1: "(dst=p__Inv4)" have "((formEval (eqn (IVar (Field (Para (Field (Ident ''Sta'') ''Proc'') p__Inv4) ''InvMarked'')) (Const true)) s))\<or>((formEval (neg (eqn (IVar (Field (Para (Field (Ident ''Sta'') ''Proc'') p__Inv4) ''InvMarked'')) (Const true))) s))" by auto moreover { assume c1: "((formEval (eqn (IVar (Field (Para (Field (Ident ''Sta'') ''Proc'') p__Inv4) ''InvMarked'')) (Const true)) s))" have "?P1 s" proof(cut_tac a1 a2 b1 c1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume c1: "((formEval (neg (eqn (IVar (Field (Para (Field (Ident ''Sta'') ''Proc'') p__Inv4) ''InvMarked'')) (Const true))) s))" have "?P1 s" proof(cut_tac a1 a2 b1 c1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } ultimately have "invHoldForRule s f r (invariants N)" by satx } moreover { assume b1: "(dst=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: "(dst~=p__Inv3\<and>dst~=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_NI_Remote_PutXVsinv__4: assumes a1: "(\<exists> dst. dst\<le>N\<and>r=n_NI_Remote_PutX dst)" and a2: "(\<exists> p__Inv3 p__Inv4. p__Inv3\<le>N\<and>p__Inv4\<le>N\<and>p__Inv3~=p__Inv4\<and>f=inv__4 p__Inv3 p__Inv4)" shows "invHoldForRule s f r (invariants N)" (is "?P1 s \<or> ?P2 s \<or> ?P3 s") proof - from a1 obtain dst where a1:"dst\<le>N\<and>r=n_NI_Remote_PutX dst" 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__4 p__Inv3 p__Inv4" apply fastforce done have "(dst=p__Inv4)\<or>(dst=p__Inv3)\<or>(dst~=p__Inv3\<and>dst~=p__Inv4)" apply (cut_tac a1 a2, auto) done moreover { assume b1: "(dst=p__Inv4)" have "?P3 s" apply (cut_tac a1 a2 b1, simp, rule_tac x="(neg (andForm (eqn (IVar (Field (Para (Field (Ident ''Sta'') ''UniMsg'') p__Inv3) ''Cmd'')) (Const UNI_PutX)) (eqn (IVar (Field (Para (Field (Ident ''Sta'') ''UniMsg'') p__Inv4) ''Cmd'')) (Const UNI_PutX))))" in exI, auto) done then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume b1: "(dst=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: "(dst~=p__Inv3\<and>dst~=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_NI_InvVsinv__4: assumes a1: "(\<exists> dst. dst\<le>N\<and>r=n_NI_Inv dst)" and a2: "(\<exists> p__Inv3 p__Inv4. p__Inv3\<le>N\<and>p__Inv4\<le>N\<and>p__Inv3~=p__Inv4\<and>f=inv__4 p__Inv3 p__Inv4)" shows "invHoldForRule s f r (invariants N)" (is "?P1 s \<or> ?P2 s \<or> ?P3 s") proof - from a1 obtain dst where a1:"dst\<le>N\<and>r=n_NI_Inv dst" 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__4 p__Inv3 p__Inv4" apply fastforce done have "(dst=p__Inv4)\<or>(dst=p__Inv3)\<or>(dst~=p__Inv3\<and>dst~=p__Inv4)" apply (cut_tac a1 a2, auto) done moreover { assume b1: "(dst=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: "(dst=p__Inv3)" have "?P2 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume b1: "(dst~=p__Inv3\<and>dst~=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_PI_Local_GetX_PutX__part__0Vsinv__4: assumes a1: "r=n_PI_Local_GetX_PutX__part__0 " and a2: "(\<exists> p__Inv3 p__Inv4. p__Inv3\<le>N\<and>p__Inv4\<le>N\<and>p__Inv3~=p__Inv4\<and>f=inv__4 p__Inv3 p__Inv4)" shows "invHoldForRule s f r (invariants N)" apply (rule noEffectOnRule, cut_tac a1 a2, auto) done lemma n_NI_WbVsinv__4: assumes a1: "r=n_NI_Wb " and a2: "(\<exists> p__Inv3 p__Inv4. p__Inv3\<le>N\<and>p__Inv4\<le>N\<and>p__Inv3~=p__Inv4\<and>f=inv__4 p__Inv3 p__Inv4)" shows "invHoldForRule s f r (invariants N)" apply (rule noEffectOnRule, cut_tac a1 a2, auto) done lemma n_StoreVsinv__4: assumes a1: "\<exists> src data. src\<le>N\<and>data\<le>N\<and>r=n_Store src data" and a2: "(\<exists> p__Inv3 p__Inv4. p__Inv3\<le>N\<and>p__Inv4\<le>N\<and>p__Inv3~=p__Inv4\<and>f=inv__4 p__Inv3 p__Inv4)" shows "invHoldForRule s f r (invariants N)" apply (rule noEffectOnRule, cut_tac a1 a2, auto) done lemma n_NI_InvAck_3Vsinv__4: assumes a1: "\<exists> src. src\<le>N\<and>r=n_NI_InvAck_3 N src" and a2: "(\<exists> p__Inv3 p__Inv4. p__Inv3\<le>N\<and>p__Inv4\<le>N\<and>p__Inv3~=p__Inv4\<and>f=inv__4 p__Inv3 p__Inv4)" shows "invHoldForRule s f r (invariants N)" apply (rule noEffectOnRule, cut_tac a1 a2, auto) done lemma n_NI_InvAck_1Vsinv__4: assumes a1: "\<exists> src. src\<le>N\<and>r=n_NI_InvAck_1 N src" and a2: "(\<exists> p__Inv3 p__Inv4. p__Inv3\<le>N\<and>p__Inv4\<le>N\<and>p__Inv3~=p__Inv4\<and>f=inv__4 p__Inv3 p__Inv4)" shows "invHoldForRule s f r (invariants N)" apply (rule noEffectOnRule, cut_tac a1 a2, auto) done lemma n_PI_Local_GetX_GetX__part__1Vsinv__4: assumes a1: "r=n_PI_Local_GetX_GetX__part__1 " and a2: "(\<exists> p__Inv3 p__Inv4. p__Inv3\<le>N\<and>p__Inv4\<le>N\<and>p__Inv3~=p__Inv4\<and>f=inv__4 p__Inv3 p__Inv4)" shows "invHoldForRule s f r (invariants N)" apply (rule noEffectOnRule, cut_tac a1 a2, auto) done lemma n_PI_Local_GetX_GetX__part__0Vsinv__4: assumes a1: "r=n_PI_Local_GetX_GetX__part__0 " and a2: "(\<exists> p__Inv3 p__Inv4. p__Inv3\<le>N\<and>p__Inv4\<le>N\<and>p__Inv3~=p__Inv4\<and>f=inv__4 p__Inv3 p__Inv4)" shows "invHoldForRule s f r (invariants N)" apply (rule noEffectOnRule, cut_tac a1 a2, auto) done lemma n_Store_HomeVsinv__4: assumes a1: "\<exists> data. data\<le>N\<and>r=n_Store_Home data" and a2: "(\<exists> p__Inv3 p__Inv4. p__Inv3\<le>N\<and>p__Inv4\<le>N\<and>p__Inv3~=p__Inv4\<and>f=inv__4 p__Inv3 p__Inv4)" shows "invHoldForRule s f r (invariants N)" apply (rule noEffectOnRule, cut_tac a1 a2, auto) done lemma n_PI_Local_ReplaceVsinv__4: assumes a1: "r=n_PI_Local_Replace " and a2: "(\<exists> p__Inv3 p__Inv4. p__Inv3\<le>N\<and>p__Inv4\<le>N\<and>p__Inv3~=p__Inv4\<and>f=inv__4 p__Inv3 p__Inv4)" shows "invHoldForRule s f r (invariants N)" apply (rule noEffectOnRule, cut_tac a1 a2, auto) done lemma n_NI_InvAck_existsVsinv__4: assumes a1: "\<exists> src pp. src\<le>N\<and>pp\<le>N\<and>src~=pp\<and>r=n_NI_InvAck_exists src pp" and a2: "(\<exists> p__Inv3 p__Inv4. p__Inv3\<le>N\<and>p__Inv4\<le>N\<and>p__Inv3~=p__Inv4\<and>f=inv__4 p__Inv3 p__Inv4)" shows "invHoldForRule s f r (invariants N)" apply (rule noEffectOnRule, cut_tac a1 a2, auto) done lemma n_PI_Local_PutXVsinv__4: assumes a1: "r=n_PI_Local_PutX " and a2: "(\<exists> p__Inv3 p__Inv4. p__Inv3\<le>N\<and>p__Inv4\<le>N\<and>p__Inv3~=p__Inv4\<and>f=inv__4 p__Inv3 p__Inv4)" shows "invHoldForRule s f r (invariants N)" apply (rule noEffectOnRule, cut_tac a1 a2, auto) done lemma n_PI_Local_Get_PutVsinv__4: assumes a1: "r=n_PI_Local_Get_Put " and a2: "(\<exists> p__Inv3 p__Inv4. p__Inv3\<le>N\<and>p__Inv4\<le>N\<and>p__Inv3~=p__Inv4\<and>f=inv__4 p__Inv3 p__Inv4)" shows "invHoldForRule s f r (invariants N)" apply (rule noEffectOnRule, cut_tac a1 a2, auto) done lemma n_NI_ShWbVsinv__4: assumes a1: "r=n_NI_ShWb N " and a2: "(\<exists> p__Inv3 p__Inv4. p__Inv3\<le>N\<and>p__Inv4\<le>N\<and>p__Inv3~=p__Inv4\<and>f=inv__4 p__Inv3 p__Inv4)" shows "invHoldForRule s f r (invariants N)" apply (rule noEffectOnRule, cut_tac a1 a2, auto) done lemma n_PI_Local_GetX_PutX_HeadVld__part__0Vsinv__4: assumes a1: "r=n_PI_Local_GetX_PutX_HeadVld__part__0 N " and a2: "(\<exists> p__Inv3 p__Inv4. p__Inv3\<le>N\<and>p__Inv4\<le>N\<and>p__Inv3~=p__Inv4\<and>f=inv__4 p__Inv3 p__Inv4)" shows "invHoldForRule s f r (invariants N)" apply (rule noEffectOnRule, cut_tac a1 a2, auto) done lemma n_NI_ReplaceVsinv__4: assumes a1: "\<exists> src. src\<le>N\<and>r=n_NI_Replace src" and a2: "(\<exists> p__Inv3 p__Inv4. p__Inv3\<le>N\<and>p__Inv4\<le>N\<and>p__Inv3~=p__Inv4\<and>f=inv__4 p__Inv3 p__Inv4)" shows "invHoldForRule s f r (invariants N)" apply (rule noEffectOnRule, cut_tac a1 a2, auto) done lemma n_NI_Remote_GetX_Nak_HomeVsinv__4: assumes a1: "\<exists> dst. dst\<le>N\<and>r=n_NI_Remote_GetX_Nak_Home dst" and a2: "(\<exists> p__Inv3 p__Inv4. p__Inv3\<le>N\<and>p__Inv4\<le>N\<and>p__Inv3~=p__Inv4\<and>f=inv__4 p__Inv3 p__Inv4)" shows "invHoldForRule s f r (invariants N)" apply (rule noEffectOnRule, cut_tac a1 a2, auto) done lemma n_NI_Local_PutXAcksDoneVsinv__4: assumes a1: "r=n_NI_Local_PutXAcksDone " and a2: "(\<exists> p__Inv3 p__Inv4. p__Inv3\<le>N\<and>p__Inv4\<le>N\<and>p__Inv3~=p__Inv4\<and>f=inv__4 p__Inv3 p__Inv4)" shows "invHoldForRule s f r (invariants N)" apply (rule noEffectOnRule, cut_tac a1 a2, auto) done lemma n_PI_Local_GetX_PutX__part__1Vsinv__4: assumes a1: "r=n_PI_Local_GetX_PutX__part__1 " and a2: "(\<exists> p__Inv3 p__Inv4. p__Inv3\<le>N\<and>p__Inv4\<le>N\<and>p__Inv3~=p__Inv4\<and>f=inv__4 p__Inv3 p__Inv4)" shows "invHoldForRule s f r (invariants N)" apply (rule noEffectOnRule, cut_tac a1 a2, auto) done lemma n_NI_Remote_Get_Nak_HomeVsinv__4: assumes a1: "\<exists> dst. dst\<le>N\<and>r=n_NI_Remote_Get_Nak_Home dst" and a2: "(\<exists> p__Inv3 p__Inv4. p__Inv3\<le>N\<and>p__Inv4\<le>N\<and>p__Inv3~=p__Inv4\<and>f=inv__4 p__Inv3 p__Inv4)" shows "invHoldForRule s f r (invariants N)" apply (rule noEffectOnRule, cut_tac a1 a2, auto) done lemma n_NI_InvAck_exists_HomeVsinv__4: assumes a1: "\<exists> src. src\<le>N\<and>r=n_NI_InvAck_exists_Home src" and a2: "(\<exists> p__Inv3 p__Inv4. p__Inv3\<le>N\<and>p__Inv4\<le>N\<and>p__Inv3~=p__Inv4\<and>f=inv__4 p__Inv3 p__Inv4)" shows "invHoldForRule s f r (invariants N)" apply (rule noEffectOnRule, cut_tac a1 a2, auto) done lemma n_NI_Replace_HomeVsinv__4: assumes a1: "r=n_NI_Replace_Home " and a2: "(\<exists> p__Inv3 p__Inv4. p__Inv3\<le>N\<and>p__Inv4\<le>N\<and>p__Inv3~=p__Inv4\<and>f=inv__4 p__Inv3 p__Inv4)" shows "invHoldForRule s f r (invariants N)" apply (rule noEffectOnRule, cut_tac a1 a2, auto) done lemma n_NI_Local_PutVsinv__4: assumes a1: "r=n_NI_Local_Put " and a2: "(\<exists> p__Inv3 p__Inv4. p__Inv3\<le>N\<and>p__Inv4\<le>N\<and>p__Inv3~=p__Inv4\<and>f=inv__4 p__Inv3 p__Inv4)" shows "invHoldForRule s f r (invariants N)" apply (rule noEffectOnRule, cut_tac a1 a2, auto) done lemma n_NI_Nak_ClearVsinv__4: assumes a1: "r=n_NI_Nak_Clear " and a2: "(\<exists> p__Inv3 p__Inv4. p__Inv3\<le>N\<and>p__Inv4\<le>N\<and>p__Inv3~=p__Inv4\<and>f=inv__4 p__Inv3 p__Inv4)" shows "invHoldForRule s f r (invariants N)" apply (rule noEffectOnRule, cut_tac a1 a2, auto) done lemma n_PI_Local_Get_GetVsinv__4: assumes a1: "r=n_PI_Local_Get_Get " and a2: "(\<exists> p__Inv3 p__Inv4. p__Inv3\<le>N\<and>p__Inv4\<le>N\<and>p__Inv3~=p__Inv4\<and>f=inv__4 p__Inv3 p__Inv4)" shows "invHoldForRule s f r (invariants N)" apply (rule noEffectOnRule, cut_tac a1 a2, auto) done lemma n_NI_Nak_HomeVsinv__4: assumes a1: "r=n_NI_Nak_Home " and a2: "(\<exists> p__Inv3 p__Inv4. p__Inv3\<le>N\<and>p__Inv4\<le>N\<and>p__Inv3~=p__Inv4\<and>f=inv__4 p__Inv3 p__Inv4)" shows "invHoldForRule s f r (invariants N)" apply (rule noEffectOnRule, cut_tac a1 a2, auto) done lemma n_NI_InvAck_2Vsinv__4: assumes a1: "\<exists> src. src\<le>N\<and>r=n_NI_InvAck_2 N src" and a2: "(\<exists> p__Inv3 p__Inv4. p__Inv3\<le>N\<and>p__Inv4\<le>N\<and>p__Inv3~=p__Inv4\<and>f=inv__4 p__Inv3 p__Inv4)" shows "invHoldForRule s f r (invariants N)" apply (rule noEffectOnRule, cut_tac a1 a2, auto) done lemma n_PI_Local_GetX_PutX_HeadVld__part__1Vsinv__4: assumes a1: "r=n_PI_Local_GetX_PutX_HeadVld__part__1 N " and a2: "(\<exists> p__Inv3 p__Inv4. p__Inv3\<le>N\<and>p__Inv4\<le>N\<and>p__Inv3~=p__Inv4\<and>f=inv__4 p__Inv3 p__Inv4)" shows "invHoldForRule s f r (invariants N)" apply (rule noEffectOnRule, cut_tac a1 a2, auto) done lemma n_NI_FAckVsinv__4: assumes a1: "r=n_NI_FAck " and a2: "(\<exists> p__Inv3 p__Inv4. p__Inv3\<le>N\<and>p__Inv4\<le>N\<and>p__Inv3~=p__Inv4\<and>f=inv__4 p__Inv3 p__Inv4)" shows "invHoldForRule s f r (invariants N)" apply (rule noEffectOnRule, cut_tac a1 a2, auto) done end
/- Copyright (c) 2017 Scott Morrison. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Stephen Morgan, Scott Morrison -/ import category_theory.types import category_theory.equivalence universes v₁ v₂ u₁ u₂ -- morphism levels before object levels. See note [category_theory universes]. open opposite variables {C : Type u₁} section quiver variables [quiver.{v₁} C] lemma quiver.hom.op_inj {X Y : C} : function.injective (quiver.hom.op : (X ⟶ Y) → (op Y ⟶ op X)) := λ _ _ H, congr_arg quiver.hom.unop H lemma quiver.hom.unop_inj {X Y : Cᵒᵖ} : function.injective (quiver.hom.unop : (X ⟶ Y) → (unop Y ⟶ unop X)) := λ _ _ H, congr_arg quiver.hom.op H @[simp] lemma quiver.hom.unop_op {X Y : C} {f : X ⟶ Y} : f.op.unop = f := rfl @[simp] lemma quiver.hom.op_unop {X Y : Cᵒᵖ} {f : X ⟶ Y} : f.unop.op = f := rfl end quiver namespace category_theory variables [category.{v₁} C] /-- The opposite category. See https://stacks.math.columbia.edu/tag/001M. -/ instance category.opposite : category.{v₁} Cᵒᵖ := { comp := λ _ _ _ f g, (g.unop ≫ f.unop).op, id := λ X, (𝟙 (unop X)).op } @[simp] lemma op_comp {X Y Z : C} {f : X ⟶ Y} {g : Y ⟶ Z} : (f ≫ g).op = g.op ≫ f.op := rfl @[simp] lemma op_id {X : C} : (𝟙 X).op = 𝟙 (op X) := rfl @[simp] lemma unop_comp {X Y Z : Cᵒᵖ} {f : X ⟶ Y} {g : Y ⟶ Z} : (f ≫ g).unop = g.unop ≫ f.unop := rfl @[simp] lemma unop_id {X : Cᵒᵖ} : (𝟙 X).unop = 𝟙 (unop X) := rfl @[simp] lemma unop_id_op {X : C} : (𝟙 (op X)).unop = 𝟙 X := rfl @[simp] lemma op_id_unop {X : Cᵒᵖ} : (𝟙 (unop X)).op = 𝟙 X := rfl section variables (C) /-- The functor from the double-opposite of a category to the underlying category. -/ @[simps] def op_op : (Cᵒᵖ)ᵒᵖ ⥤ C := { obj := λ X, unop (unop X), map := λ X Y f, f.unop.unop } /-- The functor from a category to its double-opposite. -/ @[simps] def unop_unop : C ⥤ Cᵒᵖᵒᵖ := { obj := λ X, op (op X), map := λ X Y f, f.op.op } /-- The double opposite category is equivalent to the original. -/ @[simps] def op_op_equivalence : Cᵒᵖᵒᵖ ≌ C := { functor := op_op C, inverse := unop_unop C, unit_iso := iso.refl (𝟭 Cᵒᵖᵒᵖ), counit_iso := iso.refl (unop_unop C ⋙ op_op C) } end /-- If `f.op` is an isomorphism `f` must be too. (This cannot be an instance as it would immediately loop!) -/ lemma is_iso_of_op {X Y : C} (f : X ⟶ Y) [is_iso f.op] : is_iso f := ⟨⟨(inv (f.op)).unop, ⟨quiver.hom.op_inj (by simp), quiver.hom.op_inj (by simp)⟩⟩⟩ namespace functor section variables {D : Type u₂} [category.{v₂} D] variables {C D} /-- The opposite of a functor, i.e. considering a functor `F : C ⥤ D` as a functor `Cᵒᵖ ⥤ Dᵒᵖ`. In informal mathematics no distinction is made between these. -/ @[simps] protected def op (F : C ⥤ D) : Cᵒᵖ ⥤ Dᵒᵖ := { obj := λ X, op (F.obj (unop X)), map := λ X Y f, (F.map f.unop).op } /-- Given a functor `F : Cᵒᵖ ⥤ Dᵒᵖ` we can take the "unopposite" functor `F : C ⥤ D`. In informal mathematics no distinction is made between these. -/ @[simps] protected def unop (F : Cᵒᵖ ⥤ Dᵒᵖ) : C ⥤ D := { obj := λ X, unop (F.obj (op X)), map := λ X Y f, (F.map f.op).unop } /-- The isomorphism between `F.op.unop` and `F`. -/ def op_unop_iso (F : C ⥤ D) : F.op.unop ≅ F := nat_iso.of_components (λ X, iso.refl _) (by tidy) /-- The isomorphism between `F.unop.op` and `F`. -/ def unop_op_iso (F : Cᵒᵖ ⥤ Dᵒᵖ) : F.unop.op ≅ F := nat_iso.of_components (λ X, iso.refl _) (by tidy) variables (C D) /-- Taking the opposite of a functor is functorial. -/ @[simps] def op_hom : (C ⥤ D)ᵒᵖ ⥤ (Cᵒᵖ ⥤ Dᵒᵖ) := { obj := λ F, (unop F).op, map := λ F G α, { app := λ X, (α.unop.app (unop X)).op, naturality' := λ X Y f, quiver.hom.unop_inj (α.unop.naturality f.unop).symm } } /-- Take the "unopposite" of a functor is functorial. -/ @[simps] def op_inv : (Cᵒᵖ ⥤ Dᵒᵖ) ⥤ (C ⥤ D)ᵒᵖ := { obj := λ F, op F.unop, map := λ F G α, quiver.hom.op { app := λ X, (α.app (op X)).unop, naturality' := λ X Y f, quiver.hom.op_inj $ (α.naturality f.op).symm } } -- TODO show these form an equivalence variables {C D} /-- Another variant of the opposite of functor, turning a functor `C ⥤ Dᵒᵖ` into a functor `Cᵒᵖ ⥤ D`. In informal mathematics no distinction is made. -/ @[simps] protected def left_op (F : C ⥤ Dᵒᵖ) : Cᵒᵖ ⥤ D := { obj := λ X, unop (F.obj (unop X)), map := λ X Y f, (F.map f.unop).unop } /-- Another variant of the opposite of functor, turning a functor `Cᵒᵖ ⥤ D` into a functor `C ⥤ Dᵒᵖ`. In informal mathematics no distinction is made. -/ @[simps] protected def right_op (F : Cᵒᵖ ⥤ D) : C ⥤ Dᵒᵖ := { obj := λ X, op (F.obj (op X)), map := λ X Y f, (F.map f.op).op } -- TODO show these form an equivalence instance {F : C ⥤ D} [full F] : full F.op := { preimage := λ X Y f, (F.preimage f.unop).op } instance {F : C ⥤ D} [faithful F] : faithful F.op := { map_injective' := λ X Y f g h, quiver.hom.unop_inj $ by simpa using map_injective F (quiver.hom.op_inj h) } /-- If F is faithful then the right_op of F is also faithful. -/ instance right_op_faithful {F : Cᵒᵖ ⥤ D} [faithful F] : faithful F.right_op := { map_injective' := λ X Y f g h, quiver.hom.op_inj (map_injective F (quiver.hom.op_inj h)) } /-- If F is faithful then the left_op of F is also faithful. -/ instance left_op_faithful {F : C ⥤ Dᵒᵖ} [faithful F] : faithful F.left_op := { map_injective' := λ X Y f g h, quiver.hom.unop_inj (map_injective F (quiver.hom.unop_inj h)) } end end functor namespace nat_trans variables {D : Type u₂} [category.{v₂} D] section variables {F G : C ⥤ D} local attribute [semireducible] quiver.opposite /-- The opposite of a natural transformation. -/ @[simps] protected def op (α : F ⟶ G) : G.op ⟶ F.op := { app := λ X, (α.app (unop X)).op, naturality' := begin tidy, erw α.naturality, refl, end } @[simp] lemma op_id (F : C ⥤ D) : nat_trans.op (𝟙 F) = 𝟙 (F.op) := rfl /-- The "unopposite" of a natural transformation. -/ @[simps] protected def unop {F G : Cᵒᵖ ⥤ Dᵒᵖ} (α : F ⟶ G) : G.unop ⟶ F.unop := { app := λ X, (α.app (op X)).unop, naturality' := begin tidy, erw α.naturality, refl, end } @[simp] lemma unop_id (F : Cᵒᵖ ⥤ Dᵒᵖ) : nat_trans.unop (𝟙 F) = 𝟙 (F.unop) := rfl /-- Given a natural transformation `α : F.op ⟶ G.op`, we can take the "unopposite" of each component obtaining a natural transformation `G ⟶ F`. -/ @[simps] protected def remove_op (α : F.op ⟶ G.op) : G ⟶ F := { app := λ X, (α.app (op X)).unop, naturality' := begin intros X Y f, have := congr_arg quiver.hom.op (α.naturality f.op), dsimp at this, erw this, refl, end } @[simp] lemma remove_op_id (F : C ⥤ D) : nat_trans.remove_op (𝟙 F.op) = 𝟙 F := rfl end section variables {F G : C ⥤ Dᵒᵖ} local attribute [semireducible] quiver.opposite /-- Given a natural transformation `α : F ⟶ G`, for `F G : C ⥤ Dᵒᵖ`, taking `unop` of each component gives a natural transformation `G.left_op ⟶ F.left_op`. -/ @[simps] protected def left_op (α : F ⟶ G) : G.left_op ⟶ F.left_op := { app := λ X, (α.app (unop X)).unop, naturality' := begin tidy, erw α.naturality, refl, end } /-- Given a natural transformation `α : F.left_op ⟶ G.left_op`, for `F G : C ⥤ Dᵒᵖ`, taking `op` of each component gives a natural transformation `G ⟶ F`. -/ @[simps] protected def remove_left_op (α : F.left_op ⟶ G.left_op) : G ⟶ F := { app := λ X, (α.app (op X)).op, naturality' := begin intros X Y f, have := congr_arg quiver.hom.op (α.naturality f.op), dsimp at this, erw this end } end end nat_trans namespace iso variables {X Y : C} /-- The opposite isomorphism. -/ @[simps] protected def op (α : X ≅ Y) : op Y ≅ op X := { hom := α.hom.op, inv := α.inv.op, hom_inv_id' := quiver.hom.unop_inj α.inv_hom_id, inv_hom_id' := quiver.hom.unop_inj α.hom_inv_id } end iso namespace nat_iso variables {D : Type u₂} [category.{v₂} D] variables {F G : C ⥤ D} /-- The natural isomorphism between opposite functors `G.op ≅ F.op` induced by a natural isomorphism between the original functors `F ≅ G`. -/ @[simps] protected def op (α : F ≅ G) : G.op ≅ F.op := { hom := nat_trans.op α.hom, inv := nat_trans.op α.inv, hom_inv_id' := begin ext, dsimp, rw ←op_comp, rw α.inv_hom_id_app, refl, end, inv_hom_id' := begin ext, dsimp, rw ←op_comp, rw α.hom_inv_id_app, refl, end } /-- The natural isomorphism between functors `G ≅ F` induced by a natural isomorphism between the opposite functors `F.op ≅ G.op`. -/ @[simps] protected def remove_op (α : F.op ≅ G.op) : G ≅ F := { hom := nat_trans.remove_op α.hom, inv := nat_trans.remove_op α.inv, hom_inv_id' := begin ext, dsimp, rw ←unop_comp, rw α.inv_hom_id_app, refl, end, inv_hom_id' := begin ext, dsimp, rw ←unop_comp, rw α.hom_inv_id_app, refl, end } /-- The natural isomorphism between functors `G.unop ≅ F.unop` induced by a natural isomorphism between the original functors `F ≅ G`. -/ @[simps] protected def unop {F G : Cᵒᵖ ⥤ Dᵒᵖ} (α : F ≅ G) : G.unop ≅ F.unop := { hom := nat_trans.unop α.hom, inv := nat_trans.unop α.inv, hom_inv_id' := begin ext, dsimp, rw ←unop_comp, rw α.inv_hom_id_app, refl, end, inv_hom_id' := begin ext, dsimp, rw ←unop_comp, rw α.hom_inv_id_app, refl, end } end nat_iso namespace equivalence variables {D : Type u₂} [category.{v₂} D] /-- An equivalence between categories gives an equivalence between the opposite categories. -/ @[simps] def op (e : C ≌ D) : Cᵒᵖ ≌ Dᵒᵖ := { functor := e.functor.op, inverse := e.inverse.op, unit_iso := (nat_iso.op e.unit_iso).symm, counit_iso := (nat_iso.op e.counit_iso).symm, functor_unit_iso_comp' := λ X, by { apply quiver.hom.unop_inj, dsimp, simp, }, } /-- An equivalence between opposite categories gives an equivalence between the original categories. -/ @[simps] def unop (e : Cᵒᵖ ≌ Dᵒᵖ) : C ≌ D := { functor := e.functor.unop, inverse := e.inverse.unop, unit_iso := (nat_iso.unop e.unit_iso).symm, counit_iso := (nat_iso.unop e.counit_iso).symm, functor_unit_iso_comp' := λ X, by { apply quiver.hom.op_inj, dsimp, simp, }, } end equivalence /-- The equivalence between arrows of the form `A ⟶ B` and `B.unop ⟶ A.unop`. Useful for building adjunctions. Note that this (definitionally) gives variants ``` def op_equiv' (A : C) (B : Cᵒᵖ) : (opposite.op A ⟶ B) ≃ (B.unop ⟶ A) := op_equiv _ _ def op_equiv'' (A : Cᵒᵖ) (B : C) : (A ⟶ opposite.op B) ≃ (B ⟶ A.unop) := op_equiv _ _ def op_equiv''' (A B : C) : (opposite.op A ⟶ opposite.op B) ≃ (B ⟶ A) := op_equiv _ _ ``` -/ @[simps] def op_equiv (A B : Cᵒᵖ) : (A ⟶ B) ≃ (B.unop ⟶ A.unop) := { to_fun := λ f, f.unop, inv_fun := λ g, g.op, left_inv := λ _, rfl, right_inv := λ _, rfl } instance subsingleton_of_unop (A B : Cᵒᵖ) [subsingleton (unop B ⟶ unop A)] : subsingleton (A ⟶ B) := (op_equiv A B).subsingleton instance decidable_eq_of_unop (A B : Cᵒᵖ) [decidable_eq (unop B ⟶ unop A)] : decidable_eq (A ⟶ B) := (op_equiv A B).decidable_eq universes v variables {α : Type v} [preorder α] /-- Construct a morphism in the opposite of a preorder category from an inequality. -/ def op_hom_of_le {U V : αᵒᵖ} (h : unop V ≤ unop U) : U ⟶ V := quiver.hom.op (hom_of_le h) lemma le_of_op_hom {U V : αᵒᵖ} (h : U ⟶ V) : unop V ≤ unop U := le_of_hom (h.unop) end category_theory
Jamie is alone, left in the care of his cold, harsh uncle. On the wall of his uncle’s study hangs a long, silvery horn. Uncle claims it came from a narwhale. Jamie is sure that it is something different, something much more rare. And he is determined to find out. Are you ever going to record COLD FIRE and SHATTERGLASS?
A fantastic festival, inspirational artistes and performers helped to create a series of ads that translated the energy, creativity and freedom of the Darwin Festival. Far and away the most popular and well received campaign the festival ‘had ever had’. It was a fabulous project to be a part of Storm Cell were thrilled to be a part of the hype. Nicky Bomba’s Bustamento must also get a mention, with ‘Livin’ the Dream’ the theme tune of the Darwin Festival, and a fantastic live band.
[STATEMENT] lemma delta_neg_sol: "delta_neg = dual (F (dual delta_pos, undual delta_neg))" [PROOF STATE] proof (prove) goal (1 subgoal): 1. delta_neg = dual (F (dual delta_pos, undual delta_neg)) [PROOF STEP] by (metis (no_types, lifting) case_prod_unfold delta_neg_def delta_pos_def fst_conv lfp_unfold sym_lr_def sym_lr_mono)
[STATEMENT] lemma maddux_21: "x \<le> 1 ; x" [PROOF STATE] proof (prove) goal (1 subgoal): 1. x \<le> 1 ; x [PROOF STEP] by (metis mult_isor mult_onel top_greatest)
subroutine evspline(xget,x,nx,ilinx,f,ict,fval,ier) C C use mkspline to set up spline coefficients... C C evaluate a 1d cubic Spline interpolant -- this is C2 C C this subroutine calls two subroutines: C herm1x -- find cell containing (xget) C fvspline -- evaluate interpolant function and (optionally) derivatives C C input arguments: C ================ C integer nx ! grid size real xget ! target of this interpolation real x(nx) ! ordered x grid integer ilinx ! ilinx=1 => assume x evenly spaced C real f(0:1,nx) ! function data C C f(0,i) = f @ x(i) C f(1,i) = d2f/dx2 @ x(i) C C (these are spline coefficients selected for continuous 2- C diffentiability, see mkspline.for) C integer ict(3) ! code specifying output desired C C ict(1)=1 -- return f (0, don't) C ict(2)=1 -- return df/dx (0, don't) C ict(3)=1 -- return d2f/dx2 (0, don't) c c set ict(1)=3 to get d3f/dx3 (only) C C output arguments: C ================= C real fval(*) ! output data integer ier ! error code =0 ==> no error C C fval(1) receives the first output (depends on ict(...) spec) C fval(2) receives the second output (depends on ict(...) spec) C fval(3) receives the third output (depends on ict(...) spec) C C examples: C on input ict = [1,1,1] C on output fval= [f,df/dx,d2f/dx2] C C on input ict = [1,0,0] C on output fval= [f] ... elements 2 -- 3 never referenced. C C on input ict = [0,0,1] C on output fval= [d2f/dx2] ... elements 2 -- 3 never referenced. C C ier -- completion code: 0 means OK C------------------- C local: C integer i(1) ! cell indices C C normalized displacement from x(i) grid point. C xparam=0 @x(i) xparam=1 @x(i+1) C real xparam(1) C C cell dimensions and C inverse cell dimensions hxi = 1/(x(i+1)-x(i)) C real hx(1) real hxi(1) C C 0 .le. xparam .le. 1 C C ** the interface is very similar to herm2ev.for; can use herm2xy ** C--------------------------------------------------------------------- C i(1)=0 C call herm1x(xget,x,nx,ilinx,i(1),xparam(1),hx(1),hxi(1),ier) if(ier.ne.0) return c call fvspline(ict,1,1,fval,i,xparam,hx,hxi,f,nx) C return end C--------------------------------------------------------------------- C evaluate C1 cubic Hermite function interpolation -- 2d fcn C --vectorized-- dmc 10 Feb 1999 C subroutine fvspline(ict,ivec,ivecd, > fval,ii,xparam,hx,hxi,fin,nx) C C use mkspline to set up spline coefficients... C integer ict(3) ! requested output control integer ivec ! vector length integer ivecd ! vector dimension (1st dim of fval) C integer ii(ivec) ! target cells (i) real xparam(ivec) ! normalized displacements from (i) corners C real hx(ivec) ! grid spacing, and real hxi(ivec) ! inverse grid spacing 1/(x(i+1)-x(i)) C real fin(0:1,nx) ! interpolant data (cf "evspline") C real fval(ivecd,*) ! output returned C C for detailed description of fin, ict and fval see subroutine C evspline comments. Note ict is not vectorized; the same output C is expected to be returned for all input vector data points. C C note that the index inputs ii and parameter inputs C xparam,hx,hxi, are vectorized, and the C output array fval has a vector ** 1st dimension ** whose C size must be given as a separate argument C C to use this routine in scalar mode, pass in ivec=ivecd=1 C C--------------- C Spline evaluation consists of a "mixing" of the interpolant C data using the linear functionals xparam, xpi = 1-xparam, C xparam**3-xparam, xpi**3-xpi ... C and their derivatives as needed. C integer v C real sum real sixth C data sixth/0.166666666666666667/ C C--------------- C ...in x direction C iadr=0 C if(ict(1).le.2) then C C normal call C if(ict(1).eq.1) then C C get desired values: C iadr = iadr + 1 do v=1,ivec i=ii(v) C xp=xparam(v) xpi=1.0-xp xp2=xp*xp xpi2=xpi*xpi C cx=xp*(xp2-1.0) cxi=xpi*(xpi2-1.0) hx2=hx(v)*hx(v) C C function value: C sum=xpi*fin(0,i) +xp*fin(0,i+1) sum=sum+sixth*hx2*(cxi*fin(1,i) +cx*fin(1,i+1)) C fval(v,iadr)=sum enddo endif C if(ict(2).eq.1) then C C df/dx: C iadr=iadr+1 do v=1,ivec i=ii(v) C xp=xparam(v) xpi=1.0-xp xp2=xp*xp xpi2=xpi*xpi C cxd=3.0*xp2-1.0 cxdi=-3.0*xpi2+1.0 sum=hxi(v)*(fin(0,i+1)-fin(0,i)) sum=sum+sixth*hx(v)*(cxdi*fin(1,i) +cxd*fin(1,i+1)) C fval(v,iadr)=sum enddo endif C if(ict(3).eq.1) then C C d2f/dx2: C iadr=iadr+1 do v=1,ivec i=ii(v) C xp=xparam(v) xpi=1.0-xp C sum=xpi*fin(1,i) +xp*fin(1,i+1) fval(v,iadr)=sum enddo endif C else C C return fxxx = d3f/dx3 C iadr=1 do v=1,ivec i=ii(v) fval(v,iadr)=hxi(v)*(fin(1,i+1)-fin(1,i)) enddo C endif C return end
||| http://okmij.org/ftp/Computation/free-monad.html module Freer %default total %access public export ||| Argh, has the same totality problems as free monad! data FFree : (Type -> Type) -> Type -> Type where FPure : a -> FFree g a FImpure : g x -> (x -> FFree g a) -> FFree g a fmap : (a -> b) -> FFree g a -> FFree g b fmap f (FPure x) = FPure (f x) fmap f (FImpure u q) = FImpure u (fmap f . q) Functor (FFree g) where map f (FPure x) = FPure (f x) map f (FImpure u q) = FImpure u (map f . q) Applicative (FFree g) where pure = FPure (FPure f) <*> x = map f x (FImpure u q) <*> x = FImpure u ((<*> x) . q) infixr 5 >=> (>=>) : Monad m => (a -> m b) -> (b -> m c) -> (a -> m c) f >=> g = (>>= g) . f Monad (FFree g) where (FPure x) >>= f = f x (FImpure u f') >>= f = FImpure u (f' >=> f)
The sign of a real number is the same as the sign of its image under the embedding of the reals into any real normed algebra.
lemma closure_approachable: fixes S :: "'a::metric_space set" shows "x \<in> closure S \<longleftrightarrow> (\<forall>e>0. \<exists>y\<in>S. dist y x < e)"
(* Title: HOL/Auth/n_germanSymIndex_lemma_inv__39_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_germanSymIndex Protocol Case Study*} theory n_germanSymIndex_lemma_inv__39_on_rules imports n_germanSymIndex_lemma_on_inv__39 begin section{*All lemmas on causal relation between inv__39*} lemma lemma_inv__39_on_rules: assumes b1: "r \<in> rules N" and b2: "(\<exists> p__Inv0 p__Inv2. p__Inv0\<le>N\<and>p__Inv2\<le>N\<and>p__Inv0~=p__Inv2\<and>f=inv__39 p__Inv0 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__39) 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__39) 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__39) 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__39) 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__39) 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__39) 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__39) 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__39) 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__39) 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__39) 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__39) 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__39) 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__39) 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__39) done } ultimately show "invHoldForRule s f r (invariants N)" by satx qed end
% floatwrite() - Write data matrix to float file. % % Usage: >> floatwrite(data,filename, 'format') % % Inputs: % data - write matrix data to specified file as four-byte floating point numbers. % filename - name of the file % 'format' - The option FORMAT argument specifies the storage format as % defined by fopen. Default format is 'native'. % 'transp|normal' - save the data transposed (.dat files) or not. % % Author: Sigurd Enghoff, CNL / Salk Institute, La Jolla, 7/1998 % % See also: floatread(), fopen() % Copyright (C) Sigurd Enghoff, CNL / Salk Institute, La Jolla, 7/1998 % % This program is free software; you can redistribute it and/or modify % it under the terms of the GNU General Public License as published by % the Free Software Foundation; either version 2 of the License, or % (at your option) any later version. % % This program is distributed in the hope that it will be useful, % but WITHOUT ANY WARRANTY; without even the implied warranty of % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the % GNU General Public License for more details. % % You should have received a copy of the GNU General Public License % along with this program; if not, write to the Free Software % Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA % 07-08-99 FORMAT argument added -se % 02-08-00 new version included in toolbox -sm % 01-25-02 reformated help & license, added links -ad function A = floatwrite(A, fname, fform, transp) if ~exist('fform') fform = 'native'; end if nargin < 4 transp = 'normal'; end; if strcmpi(transp,'normal') if strcmpi(class(A), 'mmo') A = changefile(A, fname); return; elseif strcmpi(class(A), 'memmapdata') % check file to overwrite % ----------------------- [fpath1 fname1 ext1] = fileparts(fname); [fpath2 fname2 ext2] = fileparts(A.data.Filename); if isempty(fpath1), fpath1 = pwd; end; fname1 = fullfile(fpath1, [fname1 ext1]); fname2 = fullfile(fpath2, [fname2 ext2]); if ~isempty(findstr(fname1, fname2)) disp('Warning: raw data already saved in memory mapped file (no need to resave it)'); return; end; fid = fopen(fname,'wb',fform); if fid == -1, error('Cannot write output file, check permission and space'); end; if size(A,3) > 1 for ind = 1:size(A,3) tmpdata = A(:,:,ind); fwrite(fid,tmpdata,'float'); end; else blocks = [ 1:round(size(A,2)/10):size(A,2)]; if blocks(end) ~= size(A,2), blocks = [blocks size(A,2)]; end; for ind = 1:length(blocks)-1 tmpdata = A(:, blocks(ind):blocks(ind+1)); fwrite(fid,tmpdata,'float'); end; end; else fid = fopen(fname,'wb',fform); if fid == -1, error('Cannot write output file, check permission and space'); end; fwrite(fid,A,'float'); end; else % save transposed for ind = 1:size(A,1) fwrite(fid,A(ind,:),'float'); end; end; fclose(fid);
(* Title: HOL/Auth/n_mutualExSimp_lemma_inv__2_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_mutualExSimp Protocol Case Study*} theory n_mutualExSimp_lemma_inv__2_on_rules imports n_mutualExSimp_lemma_on_inv__2 begin section{*All lemmas on causal relation between inv__2*} lemma lemma_inv__2_on_rules: assumes b1: "r \<in> rules N" and b2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__2 p__Inv4)" shows "invHoldForRule s f r (invariants N)" proof - have c1: "(\<exists> i. i\<le>N\<and>r=n_Crit i)\<or> (\<exists> i. i\<le>N\<and>r=n_Exit i)\<or> (\<exists> i. i\<le>N\<and>r=n_Idle i)" apply (cut_tac b1, auto) done moreover { assume d1: "(\<exists> i. i\<le>N\<and>r=n_Crit i)" have "invHoldForRule s f r (invariants N)" apply (cut_tac b2 d1, metis n_CritVsinv__2) done } moreover { assume d1: "(\<exists> i. i\<le>N\<and>r=n_Exit i)" have "invHoldForRule s f r (invariants N)" apply (cut_tac b2 d1, metis n_ExitVsinv__2) done } moreover { assume d1: "(\<exists> i. i\<le>N\<and>r=n_Idle i)" have "invHoldForRule s f r (invariants N)" apply (cut_tac b2 d1, metis n_IdleVsinv__2) done } ultimately show "invHoldForRule s f r (invariants N)" by satx qed end
1 -- @@stderr -- dtrace: invalid probe specifier fight:: probe description ::fight: does not match any probes
Formal statement is: lemma has_field_der_id: "((\<lambda>x. x\<^sup>2/2) has_field_derivative x) (at x)" Informal statement is: The function $f(x) = x^2/2$ has derivative $f'(x) = x$.
c c c ################################################### c ## COPYRIGHT (C) 1995 by Jay William Ponder ## c ## All Rights Reserved ## c ################################################### c c ############################################################### c ## ## c ## subroutine kpolar -- assign polarizability parameters ## c ## ## c ############################################################### c c c "kpolar" assigns atomic dipole polarizabilities to the atoms c within the structure and processes any new or changed values c c subroutine kpolar implicit none include 'sizes.i' include 'atoms.i' include 'inform.i' include 'iounit.i' include 'keys.i' include 'kpolr.i' include 'mpole.i' include 'polar.i' include 'polpot.i' include 'potent.i' include 'usolve.i' integer i,j,k integer npg,next integer pg(maxval) real*8 pol,thl real*8 sixth logical header character*20 keyword character*120 record character*120 string c c c process keywords containing polarizability parameters c header = .true. do i = 1, nkey next = 1 record = keyline(i) call gettext (record,keyword,next) call upcase (keyword) if (keyword(1:9) .eq. 'POLARIZE ') then k = 0 pol = 0.0d0 thl = -1.0d0 do j = 1, maxval pg(j) = 0 end do call getnumb (record,k,next) string = record(next:120) read (string,*,err=10,end=10) pol,thl,(pg(j),j=1,maxval) 10 continue if (k .gt. 0) then if (header .and. .not.silent) then header = .false. write (iout,20) 20 format (/,' Additional Atomic Dipole', & ' Polarizability Parameters :', & //,5x,'Atom Type',11x,'Alpha',8x, & 'Damp',5x,'Group Atom Types'/) end if if (k .le. maxtyp) then polr(k) = pol athl(k) = thl do j = 1, maxval pgrp(j,k) = pg(j) if (pg(j) .eq. 0) then npg = j - 1 goto 30 end if end do 30 continue if (.not. silent) then write (iout,40) k,pol,thl,(pg(j),j=1,npg) 40 format (4x,i6,10x,f10.3,2x,f10.3,7x,20i5) end if else write (iout,50) 50 format (/,' KPOLAR -- Too many Dipole', & ' Polarizability Parameters') abort = .true. end if end if end if end do c c find and store the atomic dipole polarizability parameters c do i = 1, n polarity(i) = polr(type(i)) thole(i) = athl(type(i)) end do c c process keywords containing atom specific polarizabilities c header = .true. do i = 1, nkey next = 1 record = keyline(i) call gettext (record,keyword,next) call upcase (keyword) if (keyword(1:9) .eq. 'POLARIZE ') then k = 0 pol = 0.0d0 thl = 0.0d0 call getnumb (record,k,next) if (k.lt.0 .and. k.ge.-n) then k = -k string = record(next:120) read (string,*,err=60,end=60) pol,thl 60 continue if (header) then header = .false. write (iout,70) 70 format (/,' Additional Dipole Polarizabilities', & ' for Specific Atoms :', & //,6x,'Atom',15x,'Alpha',8x,'Damp',/) end if if (.not. silent) then write (iout,80) k,pol,thl 80 format (4x,i6,10x,f10.3,2x,f10.3) end if polarity(k) = pol thole(k) = thl end if end if end do c c remove zero and undefined polarizable sites from the list c npole = 0 npolar = 0 do i = 1, n if (polsiz(i).ne.0 .or. polarity(i).ne.0.0d0) then npole = npole + 1 ipole(npole) = i pollist(i) = npole zaxis(npole) = zaxis(i) xaxis(npole) = xaxis(i) yaxis(npole) = yaxis(i) polaxe(npole) = polaxe(i) do k = 1, maxpole pole(k,npole) = pole(k,i) end do if (polarity(i) .ne. 0.0d0) npolar = npolar + 1 polarity(npole) = polarity(i) thole(npole) = thole(i) end if end do c c set the values used in the scaling of the polarizability c sixth = 1.0d0 / 6.0d0 do i = 1, npole if (thole(i) .eq. 0.0d0) then pdamp(i) = 0.0d0 else pdamp(i) = polarity(i)**sixth end if end do c c assign polarization group connectivity of each atom c call polargrp c c test multipoles at chiral sites and invert if necessary c call chkpole c c turn off polarizable multipole potential if it is not used c if (npole .eq. 0) use_mpole = .false. if (npolar .eq. 0) use_polar = .false. c c perform dynamic allocation of some pointer arrays c if (use_polar) then if (associated(mindex)) deallocate (mindex) if (associated(minv)) deallocate (minv) allocate (mindex(npole)) allocate (minv(3*maxulst*npole)) end if return end c c c ################################################################ c ## ## c ## subroutine polargrp -- polarization group connectivity ## c ## ## c ################################################################ c c c "polargrp" generates members of the polarization group of c each atom and separate lists of the 1-2, 1-3 and 1-4 group c connectivities c c subroutine polargrp implicit none include 'sizes.i' include 'atoms.i' include 'couple.i' include 'inform.i' include 'iounit.i' include 'kpolr.i' include 'mpole.i' include 'polgrp.i' integer maxlist,maxkeep parameter (maxkeep=100) parameter (maxlist=1000) integer i,j,k integer it,jt integer jj,kk integer start,stop integer nlist,nkeep integer keep(maxkeep) integer list(maxlist) integer, allocatable :: mask(:) logical done c c c find the directly connected group members for each atom c do i = 1, n np11(i) = 1 ip11(1,i) = i it = type(i) do j = 1, n12(i) jj = i12(j,i) jt = type(jj) do k = 1, maxval kk = pgrp(k,it) if (kk .eq. 0) goto 20 if (pgrp(k,it) .eq. jt) then np11(i) = np11(i) + 1 if (np11(i) .le. maxp11) then ip11(np11(i),i) = jj else write (iout,10) 10 format (/,' POLARGRP -- Too many Atoms', & ' in Polarization Group') abort = .true. goto 30 end if end if end do 20 continue end do end do 30 continue c c perform dynamic allocation of some local arrays c allocate (mask(n)) c c find any other group members for each atom in turn c do i = 1, n mask(i) = 0 end do do i = 1, n done = .false. start = 1 stop = np11(i) do j = start, stop jj = ip11(j,i) if (jj .lt. i) then done = .true. np11(i) = np11(jj) do k = 1, np11(i) ip11(k,i) = ip11(k,jj) end do else mask(jj) = i end if end do do while (.not. done) done = .true. do j = start, stop jj = ip11(j,i) do k = 1, np11(jj) kk = ip11(k,jj) if (mask(kk) .ne. i) then np11(i) = np11(i) + 1 if (np11(i) .le. maxp11) then ip11(np11(i),i) = kk else write (iout,40) 40 format (/,' POLARGRP -- Too many Atoms', & ' in Polarization Group') abort = .true. goto 50 end if mask(kk) = i end if end do end do if (np11(i) .ne. stop) then done = .false. start = stop + 1 stop = np11(i) end if end do call sort (np11(i),ip11(1,i)) end do 50 continue c c loop over atoms finding all the 1-2 group relationships c do i = 1, n mask(i) = 0 end do do i = 1, n do j = 1, np11(i) jj = ip11(j,i) mask(jj) = i end do nkeep = 0 do j = 1, np11(i) jj = ip11(j,i) do k = 1, n12(jj) kk = i12(k,jj) if (mask(kk) .ne. i) then nkeep = nkeep + 1 keep(nkeep) = kk end if end do end do nlist = 0 do j = 1, nkeep jj = keep(j) do k = 1, np11(jj) kk = ip11(k,jj) nlist = nlist + 1 list(nlist) = kk end do end do call sort8 (nlist,list) if (nlist .le. maxp12) then np12(i) = nlist do j = 1, nlist ip12(j,i) = list(j) end do else write (iout,60) 60 format (/,' POLARGRP -- Too many Atoms', & ' in 1-2 Polarization Group') abort = .true. goto 70 end if end do 70 continue c c loop over atoms finding all the 1-3 group relationships c do i = 1, n mask(i) = 0 end do do i = 1, n do j = 1, np11(i) jj = ip11(j,i) mask(jj) = i end do do j = 1, np12(i) jj = ip12(j,i) mask(jj) = i end do nlist = 0 do j = 1, np12(i) jj = ip12(j,i) do k = 1, np12(jj) kk = ip12(k,jj) if (mask(kk) .ne. i) then nlist = nlist + 1 list(nlist) = kk end if end do end do call sort8 (nlist,list) if (nlist .le. maxp13) then np13(i) = nlist do j = 1, nlist ip13(j,i) = list(j) end do else write (iout,80) 80 format (/,' POLARGRP -- Too many Atoms', & ' in 1-3 Polarization Group') abort = .true. goto 90 end if end do 90 continue c c loop over atoms finding all the 1-4 group relationships c do i = 1, n mask(i) = 0 end do do i = 1, n do j = 1, np11(i) jj = ip11(j,i) mask(jj) = i end do do j = 1, np12(i) jj = ip12(j,i) mask(jj) = i end do do j = 1, np13(i) jj = ip13(j,i) mask(jj) = i end do nlist = 0 do j = 1, np13(i) jj = ip13(j,i) do k = 1, np12(jj) kk = ip12(k,jj) if (mask(kk) .ne. i) then nlist = nlist + 1 list(nlist) = kk end if end do end do call sort8 (nlist,list) if (nlist .le. maxp14) then np14(i) = nlist do j = 1, nlist ip14(j,i) = list(j) end do else write (iout,100) 100 format (/,' POLARGRP -- Too many Atoms', & ' in 1-4 Polarization Group') abort = .true. goto 110 end if end do 110 continue c c perform deallocation of some local arrays c deallocate (mask) return end
theory proof_delete imports proof_insert begin subsection \<open>locale implementation\<close> locale llrb_op = fixes pre_invl::"('a::linorder) llrb \<Rightarrow>'a llrb \<Rightarrow>'a \<Rightarrow> 'a llrb \<Rightarrow> 'a llrb" and pre_invr::"'a llrb \<Rightarrow> 'a \<Rightarrow> 'a llrb \<Rightarrow>'a llrb \<Rightarrow> 'a llrb" and pre_invsplit::"'a llrb \<Rightarrow>'a \<Rightarrow> 'a llrb \<Rightarrow> 'a llrb" begin fun del'::"'a::linorder \<Rightarrow> 'a llrb \<Rightarrow> 'a llrb" where "del' x Leaf = Leaf"| "del' x (Node l (a, _) r) = (case cmp x a of LT \<Rightarrow> pre_invl (del' x l) l a r| GT \<Rightarrow> pre_invr l a r (del' x r)| EQ \<Rightarrow> pre_invsplit l a r)" fun ins' :: "'a::linorder \<Rightarrow> 'a llrb \<Rightarrow> 'a llrb" where "ins' x Leaf = R Leaf x Leaf" | "ins' x (B l a r) = (case cmp x a of LT \<Rightarrow> pre_invl (ins' x l) l a r | GT \<Rightarrow> pre_invr l a r (ins' x r) | EQ \<Rightarrow> B l a r)" | "ins' x (R l a r) = (case cmp x a of LT \<Rightarrow> R (ins x l) a r | GT \<Rightarrow> R l a (ins x r) | EQ \<Rightarrow> R l a r)" end locale llrb_delete begin definition pre_invl'::"('a::linorder) llrb \<Rightarrow>'a llrb \<Rightarrow> 'a \<Rightarrow> 'a llrb \<Rightarrow> 'a llrb " where "pre_invl' l' l a r = ( if l \<noteq> Leaf \<and> color l = Black then baldL l' a r else rightredR l' a r)" definition pre_invr'::"('a ::linorder) llrb \<Rightarrow>'a \<Rightarrow> 'a llrb \<Rightarrow>'a llrb \<Rightarrow> 'a llrb " where "pre_invr' l a r r' = ( if r \<noteq> Leaf \<and> color r = Black then baldR l a r' else R l a r')" definition pre_invsplit'::" 'a llrb \<Rightarrow>'a \<Rightarrow> 'a llrb \<Rightarrow> 'a llrb" where "pre_invsplit' l a r = (if r = Leaf then l else (let (a', r') = split_min r in if color r = Black then baldR l a' r' else rightredR l a' r'))" interpretation llrb_op pre_invl' pre_invr' pre_invsplit' done term "del'" thm "del'.simps" definition delete' :: "'a::linorder \<Rightarrow> 'a llrb \<Rightarrow> 'a llrb" where "delete' x t = paint Black (del' x t)" lemma locdel_eq_del:"del' x t = del x t" apply(induct t) apply simp apply(case_tac "x2") apply (simp only: del'.simps del.simps) by (simp add: pre_invl'_def pre_invr'_def pre_invsplit'_def) end locale llrb_insert begin fun baliL' :: "('a ::linorder) llrb \<Rightarrow>'a llrb \<Rightarrow> 'a \<Rightarrow> 'a llrb \<Rightarrow> 'a llrb" where "baliL' (R t1 a (R t2 b t3)) _ c t4 = R (B t1 a t2) b (rightredB t3 c t4)" | "baliL' (R (R t1 a t2) b t3) _ c t4 = R (B t1 a t2) b (rightredB t3 c t4)" | "baliL' t1 _ a t2 = rightredB t1 a t2" fun baliR' :: "('a ::linorder) llrb \<Rightarrow> 'a \<Rightarrow> 'a llrb \<Rightarrow> 'a llrb \<Rightarrow>'a llrb" where "baliR' t1 a _ (R t2 b (R t3 c t4)) = R (rightredB t1 a t2) b (B t3 c t4)" | "baliR' t1 a _ (R (R t2 b t3) c t4) = R (B t1 a t2) b (rightredB t3 c t4)" | "baliR' t1 a _ t2 = rightredB t1 a t2" interpretation llrb_op baliL' baliR' done term "ins'" thm "ins'.simps" lemma baliL'_eq_baliL:"baliL' l' l a r = baliL l' a r" apply(case_tac "l'") apply simp+ apply(case_tac "x22") apply(case_tac "b") defer apply simp apply (case_tac"x21") apply (case_tac"x23") apply simp+ apply(case_tac"x22a") apply(case_tac"ba") defer apply simp+ apply(case_tac"x22a") apply(case_tac"ba") apply (case_tac"x23") apply simp+ apply(case_tac"x22b") apply(case_tac"bb") apply simp+ apply (case_tac"x23") apply simp+ apply(case_tac"x22b") apply(case_tac"bb") apply simp+ done lemma baliR'_eq_baliR:"baliR' l a r r' = baliR l a r'" apply(case_tac "r'") apply simp+ apply(case_tac "x22") apply(case_tac "b") defer apply simp apply (case_tac"x21") apply (case_tac"x23") apply simp+ apply(case_tac"x22a") apply(case_tac"ba") defer apply simp+ apply(case_tac"x22a") apply(case_tac"ba") apply (case_tac"x23") apply simp+ apply(case_tac"x22b") apply(case_tac"bb") apply simp+ apply (case_tac"x23") apply simp+ apply(case_tac"x22b") apply(case_tac"bb") apply simp+ done lemma locins_eq_ins:"ins' x t = ins x t" apply(induct t) apply simp apply(case_tac "x2") apply(case_tac "b") apply (simp only: ins'.simps ins.simps) by (metis ins'.simps(2) ins.simps(2) baliL'_eq_baliL baliR'_eq_baliR) end subsection \<open>proof of bst_delete\<close> lemma colorbr: "(B l a r = R l a r) \<Longrightarrow> false" by simp lemma bst_rightredR: "inorder (rightredR l a r) = inorder l @ a # inorder r" by(cases "(l, a, r)" rule: rightredR.cases) auto lemma bst_baldL: "inorder(baldL l a r) = inorder l @ a # inorder r" by(cases "(l,a,r)" rule: baldL.cases) (auto simp: bst_baliR bst_paint bst_rightredR bst_rightredB) lemma bst_baldR: "inorder(baldR l a r) = inorder l @ a # inorder r" by(cases "(l,a,r)" rule: baldR.cases) (auto simp: bst_baliL bst_paint bst_rightredR) lemma bst_split_min: "split_min t = (x,t') \<Longrightarrow> t \<noteq> Leaf \<Longrightarrow> x # inorder t' = inorder t" by(induction t arbitrary: t' rule: split_min.induct) (auto simp: sorted_lems bst_baldL bst_rightredR split: prod.splits if_splits) lemma bst_del: "sorted(inorder t) \<Longrightarrow> inorder(del x t) = del_list x (inorder t)" apply(induction t) apply(auto simp: del_list_simps bst_rightredR bst_split_min split: prod.splits) apply (simp add: bst_baldR) apply (smt (verit, ccfv_SIG) inorder.simps(1) bst_rightredR bst_baldL) apply (simp add: bst_split_min bst_baldR) apply (smt (verit, best) bst_rightredR bst_baldL) by(smt (verit, best) bst_rightredR bst_baldL) theorem bst_delete: "sorted(inorder t) \<Longrightarrow> inorder(delete x t) = del_list x (inorder t)" by(auto simp: delete_def bst_del bst_paint) subsection \<open>proof of invh_delete\<close> lemma bheight_false: " (bheight r - Suc 0 = bheight r \<and> r \<noteq> Leaf \<and> color r = Black) = False" by(cases r rule: search_tree2_cases) auto lemma neq_LeafD: "t \<noteq> Leaf \<Longrightarrow> \<exists>l x c r. t = Node l (x,c) r" by(cases t rule: search_tree2_cases) auto lemma bheight_paint_Red: "color t = Black \<Longrightarrow> bheight (paint Red t) = bheight t - 1" by (cases t) auto lemma invh_rightredR: "\<lbrakk> invh l; invh r; bheight l = bheight r \<rbrakk> \<Longrightarrow> invh (rightredR l a r) \<and> bheight (rightredR l a r) = bheight r" apply (induct l a r rule: rightredR.induct) apply (smt (verit) rightredR.simps(1) Suc_eq_plus1 bheight.simps(2) bheight_paint_Red diff_Suc_1 color.simps(2) invh.simps(2) paint.simps(2)) by simp+ lemma invh_baldL: "\<lbrakk> invh l; invh r; bheight l + 1 = bheight r; invc r \<rbrakk> \<Longrightarrow> invh (baldL l a r) \<and> bheight (baldL l a r) = bheight r" by(induct l a r rule: baldL.induct) (auto simp: invh_baliR invh_paint bheight_baliR bheight_paint_Red invh_rightredR invh_bheight_rightredB) lemma invh_baldR: "\<lbrakk> invh l; invh r; bheight l = bheight r + 1; invc l \<rbrakk> \<Longrightarrow> invh (baldR l a r) \<and> bheight (baldR l a r) = bheight l" by(induct l a r rule: baldR.induct) (auto simp: invh_baliL invh_paint bheight_baliL bheight_paint_Red) lemma invh_split_min: "\<lbrakk>split_min t = (x,t'); t \<noteq> Leaf; invh t; invc t \<rbrakk> \<Longrightarrow> invh t' \<and> (color t = Red \<longrightarrow> bheight t' = bheight t) \<and>(color t = Black \<longrightarrow> bheight t' = bheight t - 1)" apply(induction t arbitrary: x t' rule: split_min.induct) apply(auto split: if_splits prod.splits) apply(auto dest!: neq_LeafD) by(auto simp: invh_baldR invh_baldL invh_baliR invh_rightredR) lemma invh_del_f1: "bheight l = bheight r \<Longrightarrow> invh l \<Longrightarrow> invh r \<Longrightarrow> invc l \<Longrightarrow> invc r \<Longrightarrow> color r = Black \<Longrightarrow> x < a \<Longrightarrow> invh (del x l) \<Longrightarrow> color l = Black \<Longrightarrow> bheight (del x l) = bheight r - Suc 0 \<Longrightarrow> invh (let l' = del x l in if l \<noteq> \<langle>\<rangle> then baldL l' a r else rightredR l' a r)" apply(case_tac "l= Leaf") apply auto apply (simp add: invh_rightredR) by(metis Suc_eq_plus1 Suc_pred bheight_false diff_0_eq_0 invh_baldL not_gr_zero) lemma invh_del_f2: "bheight l = bheight r \<Longrightarrow> invh l \<Longrightarrow> invh r \<Longrightarrow> invc l \<Longrightarrow> invc r \<Longrightarrow> color r = Black \<Longrightarrow> x < a \<Longrightarrow> invh (del x l) \<Longrightarrow> bheight r - Suc 0 = bheight r \<Longrightarrow> bheight (del x l) = bheight r \<Longrightarrow> invh (let l' = del x l in if l \<noteq> \<langle>\<rangle> \<and> color l = Black then baldL l' a r else rightredR l' a r)" apply(case_tac "l= Leaf") apply auto apply (simp add: invh_rightredR) by (metis (mono_tags, lifting) bheight_false invh_rightredR) lemma invh_del_f3: "bheight l = bheight r \<Longrightarrow> invh l \<Longrightarrow> invh r \<Longrightarrow> invc l \<Longrightarrow> invc r \<Longrightarrow> color r = Black \<Longrightarrow> x < a \<Longrightarrow> invh (del x l) \<Longrightarrow> color l = Black \<Longrightarrow> bheight (del x l) = bheight r - Suc 0 \<Longrightarrow> bheight (let l' = del x l in if l \<noteq> \<langle>\<rangle> then baldL l' a r else rightredR l' a r) = bheight r" apply(case_tac "l= Leaf") apply auto apply (simp add: invh_rightredR) by(metis Suc_eq_plus1 Suc_pred bheight_false diff_less_Suc gr_implies_not_zero gr_zeroI less_SucE invh_baldL) lemma invh_del_f4: "bheight l = bheight r \<Longrightarrow> invh l \<Longrightarrow> invh r \<Longrightarrow> invc l \<Longrightarrow> invc r \<Longrightarrow> color r = Black \<Longrightarrow> x < a \<Longrightarrow>invh (del x l) \<Longrightarrow> bheight r - Suc 0 = bheight r \<Longrightarrow> bheight (del x l) = bheight r \<Longrightarrow> bheight (let l' = del x l in if l \<noteq> \<langle>\<rangle> \<and> color l = Black then baldL l' a r else rightredR l' a r) = bheight r" apply(case_tac "l= Leaf") apply auto apply (simp add: invh_rightredR) by(metis (mono_tags, lifting) bheight_false invh_rightredR) lemma invh_del_f5: "bheight l = bheight r \<Longrightarrow> invh l \<Longrightarrow> invh r \<Longrightarrow> invc l \<Longrightarrow> invc r \<Longrightarrow> color r = Black \<Longrightarrow> a < x \<Longrightarrow> invh (del x r) \<Longrightarrow> bheight (del x r) = bheight r - Suc 0 \<Longrightarrow> invh (let r' = del x r in if r \<noteq> \<langle>\<rangle> then baldR l a r' else R l a r')" apply(case_tac "r= Leaf") apply auto by(metis Suc_eq_plus1 Suc_pred bheight_false diff_0_eq_0 invh_baldR not_gr_zero) lemma invh_del_f6: "bheight l = bheight r \<Longrightarrow> invh l \<Longrightarrow> invh r \<Longrightarrow> invc l \<Longrightarrow> invc r \<Longrightarrow> color r = Black \<Longrightarrow> a < x \<Longrightarrow> invh (del x r) \<Longrightarrow> bheight (del x r) = bheight r - Suc 0 \<Longrightarrow> bheight (let r' = del x r in if r \<noteq> \<langle>\<rangle> then baldR l a r' else R l a r') = bheight r" apply(case_tac "r= Leaf") apply auto by(metis Suc_eq_plus1 Suc_pred bheight_false diff_0_eq_0 invh_baldR not_gr_zero) lemma invh_del_f7: "bheight l = bheight r \<Longrightarrow> invh l \<Longrightarrow> invh r \<Longrightarrow> invc l \<Longrightarrow> invc r \<Longrightarrow> color l = Red \<Longrightarrow> a < x \<Longrightarrow> invh (del x r) \<Longrightarrow> bheight r - Suc 0 = bheight r \<Longrightarrow> bheight (del x r) = bheight r \<Longrightarrow> invh (let r' = del x r in if r \<noteq> \<langle>\<rangle> \<and> color r = Black then baldR l a r' else R l a r')" apply(case_tac "r= Leaf") apply auto using bheight_false by fastforce lemma invh_del_f8: "bheight l = bheight r \<Longrightarrow> invh l \<Longrightarrow> invh r \<Longrightarrow> invc l \<Longrightarrow> invc r \<Longrightarrow> color l = Red \<Longrightarrow> a < x \<Longrightarrow> invh (del x r) \<Longrightarrow> bheight r - Suc 0 = bheight r \<Longrightarrow> bheight (del x r) = bheight r \<Longrightarrow> bheight (let r' = del x r in if r \<noteq> \<langle>\<rangle> \<and> color r = Black then baldR l a r' else R l a r') = bheight r" apply(case_tac "r= Leaf") apply auto using bheight_false by fastforce lemma invh_del: "\<lbrakk>invh t; invc t\<rbrakk> \<Longrightarrow> invh (del x t) \<and> (color t = Red \<longrightarrow> bheight (del x t) = bheight t) \<and> (color t = Black \<longrightarrow> bheight (del x t) = bheight t - 1)" apply(induction x t rule: del.induct) apply(auto simp: invh_baldR invh_baldL invc2I invh_rightredR dest!: invh_split_min dest: neq_LeafD split!: prod.splits if_splits) by(auto simp: invh_del_f1 invh_del_f2 invh_del_f3 invh_del_f4 invh_del_f5 invh_del_f6 invh_del_f7 invh_del_f8) theorem invh_delete: "llrb t \<Longrightarrow> invh (delete x t)" by (simp add: delete_def invh_del invh_paint llrb_def) subsection \<open>proof of invc_delete\<close> lemma color_rightredR:"color (rightredR l a r) = Red" apply (induct l a r rule: rightredR.induct) by auto lemma invc2_rightredR:"invc l \<Longrightarrow> invc r \<Longrightarrow> invc2 (rightredR l a r)" apply (induct l a r rule: rightredR.induct) by auto lemma invc_rightredR:"invc l \<Longrightarrow> invc r \<Longrightarrow> color r = Black \<Longrightarrow> color l = Black \<Longrightarrow> invc (rightredR l a r)" apply (induct l a r rule: rightredR.induct) by auto lemma invc_baliR: "\<lbrakk>invc l; invc2 r\<rbrakk> \<Longrightarrow> invc (baliR l a r)" apply (induct l a r rule: baliR.induct) by(auto simp: invc_rightredB color_rightredB) lemma invc_baliL: "\<lbrakk>invc2 l; invc r\<rbrakk> \<Longrightarrow> invc (baliL l a r)" apply (induct l a r rule: baliL.induct) by(auto simp: invc_rightredB color_rightredB) lemma inv_baliR: "\<lbrakk> invh l; invh r; invc l; invc2 r; bheight l = bheight r \<rbrakk> \<Longrightarrow> invc (baliR l a r) \<and> invh (baliR l a r) \<and> bheight (baliR l a r) = Suc (bheight l)" apply (induct l a r rule: baliR.induct) apply (auto simp: color_rightredB invc_rightredB bheight_rightredB invh_rightredB) done lemma inv_baliL: "\<lbrakk> invh l; invh r; invc2 l; invc r; bheight l = bheight r \<rbrakk> \<Longrightarrow> invc (baliL l a r) \<and> invh (baliL l a r) \<and> bheight (baliL l a r) = Suc (bheight l)" apply (induct l a r rule: baliL.induct) apply (auto simp: color_rightredB invc_rightredB bheight_rightredB invh_rightredB) done lemma invc_baldR: "\<lbrakk> invh l; invh r; bheight l = bheight r + 1; invc l; invc2 r \<rbrakk> \<Longrightarrow> invc2 (baldR l a r) \<and> (color l = Black \<longrightarrow> invc (baldR l a r))" apply (induct l a r rule: baldR.induct) by(auto simp: inv_baliL invh_paint bheight_paint_Red paint2 invc2I) lemma invc_baldL: "\<lbrakk> invh l; invh r; bheight l + 1 = bheight r; invc2 l; invc r \<rbrakk> \<Longrightarrow> invc2 (baldL l a r) \<and> (color r = Black \<longrightarrow> invc (baldL l a r))" apply (induct l a r rule: baldL.induct) apply(auto simp: inv_baliR invh_paint bheight_paint_Red paint2 invc2I invc2_rightredR invc_rightredR) by (simp add: invc2I invc2_rightredR invc_rightredB invc_baliR paint2)+ lemma invc_baldL1: "\<lbrakk>invc2 l; invc r; color r = Black\<rbrakk> \<Longrightarrow> invc (baldL l a r)" apply(induct l a r rule: baldL.induct) by(auto simp: invc_baliR invc_rightredR) lemma invc2_baldL: "\<lbrakk> invc2 l; invc r \<rbrakk> \<Longrightarrow> invc2 (baldL l a r)" apply (induct l a r rule: baldL.induct) apply(auto simp: invc_baliR invc2I invc2_rightredR) by (simp add: invc2I invc2_rightredR invc_rightredB invc_baliR paint2)+ lemma invc_baldR1: "\<lbrakk>invc l; invc2 r; color l = Black\<rbrakk> \<Longrightarrow> invc (baldR l a r)" by(induct l a r rule: baldR.induct) (simp_all add: invc_baliL) lemma invc2_baldR: "\<lbrakk> invc l; invc2 r \<rbrakk> \<Longrightarrow>invc2 (baldR l a r)" by(induct l a r rule: baldR.induct) (auto simp: invc_baliL paint2 invc2I) lemma invc_split_min: "\<lbrakk> split_min t = (x,t'); t \<noteq> Leaf; invh t; invc t \<rbrakk> \<Longrightarrow> (color t = Red \<longrightarrow> invc t') \<and> (color t = Black \<longrightarrow> invc2 t')" apply(induction t arbitrary: x t' rule: split_min.induct) apply(auto split: if_splits prod.splits) apply(auto dest!: neq_LeafD) by(auto simp: invc_baldR invc_baldL invc2I invc2_rightredR invc_baldL1) lemma invc_del_f1: "bheight l = bheight r \<Longrightarrow> invh l \<Longrightarrow> invh r \<Longrightarrow> invc l \<Longrightarrow> invc r \<Longrightarrow> color r = Black \<Longrightarrow> x < a \<Longrightarrow> color l = Black \<Longrightarrow> invc2 (del x l) \<Longrightarrow> invc2 (let l' = del x l in if l \<noteq> \<langle>\<rangle> then baldL l' a r else rightredR l' a r)" apply(case_tac "l = Leaf") apply auto apply (simp add: invc2_rightredR) by(simp add: invc2_baldL) lemma invc_del_f2: "bheight l = bheight r \<Longrightarrow> invh l \<Longrightarrow> invh r \<Longrightarrow> invc l \<Longrightarrow> invc r \<Longrightarrow> color r = Black \<Longrightarrow> x < a \<Longrightarrow> invc (del x l) \<Longrightarrow> invc2 (let l' = del x l in if l \<noteq> \<langle>\<rangle> \<and> color l = Black then baldL l' a r else rightredR l' a r)" apply(case_tac "l = Leaf") apply auto apply (simp add: invc2_rightredR) by (smt (verit, best) invc2I invc2_rightredR invc_del_f1) lemma invc_del_f3: "invc2 (del x r) \<Longrightarrow> bheight l = bheight r \<Longrightarrow> invh l \<Longrightarrow> invh r \<Longrightarrow> invc l \<Longrightarrow> invc r \<Longrightarrow> color r = Black \<Longrightarrow> a < x \<Longrightarrow> invc2 (let r' = del x r in if r \<noteq> \<langle>\<rangle> then baldR l a r' else R l a r')" apply(case_tac "r = Leaf") apply auto by(metis color.simps(2) add_diff_cancel_right' bheight.elims invh_del invc_baldR) lemma invc_del_f4: "bheight l = bheight r \<Longrightarrow> invh l \<Longrightarrow> invh r \<Longrightarrow> invc l \<Longrightarrow> invc r \<Longrightarrow> color l = Red \<Longrightarrow> a < x \<Longrightarrow> invc (del x r) \<Longrightarrow> invc2 (let r' = del x r in if r \<noteq> \<langle>\<rangle> \<and> color r = Black then baldR l a r' else R l a r')" apply(case_tac "r = Leaf") apply auto by(metis (full_types) color.distinct(1) invc.simps(2) invc2I invc2_baldR paint.simps(2)) lemma invc_del_f5: "invc2 (del x l) \<Longrightarrow> bheight l = bheight r \<Longrightarrow> invh l \<Longrightarrow> invh r \<Longrightarrow> invc l \<Longrightarrow> invc r \<Longrightarrow> color l = Black \<Longrightarrow> color r = Black \<Longrightarrow> x < a \<Longrightarrow> invc (let l' = del x l in if l \<noteq> \<langle>\<rangle> then baldL l' a r else rightredR l' a r)" apply(case_tac "l = Leaf") apply auto apply (simp add: invc_rightredR) using invc_baldL1 by fastforce lemma invc_del_f6: "invc2 (del x r) \<Longrightarrow> bheight l = bheight r \<Longrightarrow> invh l \<Longrightarrow> invh r \<Longrightarrow> invc l \<Longrightarrow> invc r \<Longrightarrow> color l = Black \<Longrightarrow> color r = Black \<Longrightarrow> a < x \<Longrightarrow> invc (let r' = del x r in if r \<noteq> \<langle>\<rangle> then baldR l a r' else R l a r')" apply(case_tac "r = Leaf") apply auto by(meson invc_baldR1) lemma invc_del: "\<lbrakk> invh t; invc t \<rbrakk> \<Longrightarrow> (color t = Red \<longrightarrow> invc (del x t)) \<and> (color t = Black \<longrightarrow> invc2 (del x t))" apply(induction x t rule: del.induct) apply(auto simp: invc_baldR invc2_baldR invc_baldR1 invc_baldL invc2_baldL invc_baldL1 invc2I invc2_rightredR dest!: invc_split_min dest: neq_LeafD split!: prod.splits if_splits) by(auto simp: invc_del_f1 invc_del_f2 invc_del_f3 invc_del_f4 invc_del_f5 invc_del_f6) theorem invc_delete: "llrb t \<Longrightarrow> invc (delete x t)" by(simp add: delete_def invc_del llrb_def) subsection \<open>proof of delete\<close> theorem llrb_delete: "llrb t \<Longrightarrow> llrb (delete x t)" by(metis color_paint_Black delete_def invc_delete invh_delete llrb_def) end
{-# OPTIONS --without-K --safe #-} open import Relation.Binary using (Rel) module Algebra.Structures.Field {a ℓ} {A : Set a} (_≈_ : Rel A ℓ) where open import Algebra.Linear.Core open import Relation.Nullary using (¬_) open import Algebra.Structures _≈_ open import Algebra.FunctionProperties _≈_ open import Level using (_⊔_) record NonZero (0# : A) : Set (a ⊔ ℓ) where field value : A non-zero : ¬ (value ≈ 0#) MultiplicativeInverse : ∀ (0# : A) -> Set (a ⊔ ℓ) MultiplicativeInverse 0# = NonZero 0# → NonZero 0# record IsField (_+_ _*_ : Op₂ A) (0# 1# : A) (-_ : Op₁ A) (_⁻¹ : MultiplicativeInverse 0#) : Set (a ⊔ ℓ) where field isCommutativeRing : IsCommutativeRing _+_ _*_ -_ 0# 1# _⁻¹-involutive : ∀ (x : NonZero 0#) → NonZero.value ((x ⁻¹) ⁻¹) ≈ NonZero.value x _⁻¹-inverse : ∀ (x : NonZero 0#) → ((NonZero.value x) * (NonZero.value (x ⁻¹))) ≈ 1# 0#-not-1# : ¬ (0# ≈ 1#) open IsCommutativeRing isCommutativeRing public open import Algebra.Properties.Ring (record { isRing = isRing }) public
Formal statement is: lemma (in topological_space) eventually_nhds: "eventually P (nhds a) \<longleftrightarrow> (\<exists>S. open S \<and> a \<in> S \<and> (\<forall>x\<in>S. P x))" Informal statement is: A predicate $P$ holds eventually in the neighborhood filter of $a$ if and only if there exists an open set $S$ containing $a$ such that $P$ holds for all $x \in S$.
[GOAL] 𝕜✝ : Type u_1 𝕜 : Type u_2 inst✝ : NonUnitalSeminormedRing 𝕜 a✝ b✝ : 𝕜 hx : a✝ ∈ ball 0 1 hy : b✝ ∈ ball 0 1 ⊢ a✝ * b✝ ∈ ball 0 1 [PROOFSTEP] rw [mem_ball_zero_iff] at * [GOAL] 𝕜✝ : Type u_1 𝕜 : Type u_2 inst✝ : NonUnitalSeminormedRing 𝕜 a✝ b✝ : 𝕜 hx : ‖a✝‖ < 1 hy : ‖b✝‖ < 1 ⊢ ‖a✝ * b✝‖ < 1 [PROOFSTEP] exact (norm_mul_le _ _).trans_lt (mul_lt_one_of_nonneg_of_lt_one_left (norm_nonneg _) hx hy.le) [GOAL] 𝕜✝ : Type u_1 𝕜 : Type u_2 inst✝ : NonUnitalSeminormedRing 𝕜 a✝ b✝ : 𝕜 hx : a✝ ∈ closedBall 0 1 hy : b✝ ∈ closedBall 0 1 ⊢ a✝ * b✝ ∈ closedBall 0 1 [PROOFSTEP] rw [mem_closedBall_zero_iff] at * [GOAL] 𝕜✝ : Type u_1 𝕜 : Type u_2 inst✝ : NonUnitalSeminormedRing 𝕜 a✝ b✝ : 𝕜 hx : ‖a✝‖ ≤ 1 hy : ‖b✝‖ ≤ 1 ⊢ ‖a✝ * b✝‖ ≤ 1 [PROOFSTEP] exact (norm_mul_le _ _).trans (mul_le_one hx (norm_nonneg _) hy) [GOAL] 𝕜✝ : Type u_1 𝕜 : Type u_2 inst✝ : NormedDivisionRing 𝕜 a✝ b✝ : 𝕜 hx : a✝ ∈ sphere 0 1 hy : b✝ ∈ sphere 0 1 ⊢ a✝ * b✝ ∈ sphere 0 1 [PROOFSTEP] rw [mem_sphere_zero_iff_norm] at * [GOAL] 𝕜✝ : Type u_1 𝕜 : Type u_2 inst✝ : NormedDivisionRing 𝕜 a✝ b✝ : 𝕜 hx : ‖a✝‖ = 1 hy : ‖b✝‖ = 1 ⊢ ‖a✝ * b✝‖ = 1 [PROOFSTEP] simp [*] [GOAL] 𝕜 : Type u_1 inst✝ : NormedDivisionRing 𝕜 x : ↑(sphere 0 1) ⊢ ‖(↑x)⁻¹‖ = 1 [PROOFSTEP] rw [norm_inv, mem_sphere_zero_iff_norm.1 x.coe_prop, inv_one] [GOAL] 𝕜 : Type u_1 inst✝ : NormedDivisionRing 𝕜 x y : ↑(sphere 0 1) ⊢ ‖↑x / ↑y‖ = 1 [PROOFSTEP] rw [norm_div, mem_sphere_zero_iff_norm.1 x.coe_prop, mem_sphere_zero_iff_norm.1 y.coe_prop, div_one] [GOAL] 𝕜 : Type u_1 inst✝ : NormedDivisionRing 𝕜 x : ↑(sphere 0 1) n : ℤ ⊢ ↑x ^ n ∈ sphere 0 1 [PROOFSTEP] rw [mem_sphere_zero_iff_norm, norm_zpow, mem_sphere_zero_iff_norm.1 x.coe_prop, one_zpow] [GOAL] 𝕜 : Type u_1 inst✝ : NormedDivisionRing 𝕜 x y : ↑(sphere 0 1) h : ↑(unitSphereToUnits 𝕜) x = ↑(unitSphereToUnits 𝕜) y ⊢ ↑x = ↑y [PROOFSTEP] convert congr_arg Units.val h
LoadData <- function() { # Select the directory path_dir <- "files/input/" path_GPS_dir <- paste0(path_dir, "GPS_Dataset/GPS_dataset_individual_level/") # Load the data data <- read_dta(paste0(path_GPS_dir, "individual_new.dta")) %>% setDT(.) world_area <- fread(file = paste0(path_dir, "world_area.txt"), sep = ",") indicators <- fread(file = paste0(path_dir, "world_bank_GDP_2010USdollars.csv"), na = "..") timeWomenSuff <- fread(file = paste0(path_dir, "womens_suffrage_date.csv"), na.strings = "-") %>% setDT(.) WEF <- fread(paste0(path_dir, "WEF_Global_Gender_Gap_Index.txt"), sep = "\t") ratioLabor <- fread(file = paste0(path_dir, "ratio_labor_MF.csv"), skip = 4) UNindex <- fread(file = paste0(path_dir, "Gender_Inequality_Index_UN_2015.csv"), na = "..") return(list(data = data, world_area = world_area, indicators = indicators, timeWomenSuff = timeWomenSuff, WEF = WEF, ratioLabor = ratioLabor, UNindex = UNindex)) }
[GOAL] f : ℝ → ℝ x a c d : ℝ l : Filter ℝ hl : l ≤ 𝓝[{x}ᶜ] x hf : Tendsto (fun y => (f y - d) / (y - x)) l (𝓝 a) h' : Tendsto (fun y => y + c * (y - x) ^ 2) l l ⊢ Tendsto (fun y => (f (y + c * (y - x) ^ 2) - d) / (y - x)) l (𝓝 a) [PROOFSTEP] have L : Tendsto (fun y => (y + c * (y - x) ^ 2 - x) / (y - x)) l (𝓝 1) := by have : Tendsto (fun y => 1 + c * (y - x)) l (𝓝 (1 + c * (x - x))) := by apply Tendsto.mono_left _ (hl.trans nhdsWithin_le_nhds) exact ((tendsto_id.sub_const x).const_mul c).const_add 1 simp only [_root_.sub_self, add_zero, mul_zero] at this apply Tendsto.congr' (Eventually.filter_mono hl _) this filter_upwards [self_mem_nhdsWithin] with y hy field_simp [sub_ne_zero.2 hy] ring [GOAL] f : ℝ → ℝ x a c d : ℝ l : Filter ℝ hl : l ≤ 𝓝[{x}ᶜ] x hf : Tendsto (fun y => (f y - d) / (y - x)) l (𝓝 a) h' : Tendsto (fun y => y + c * (y - x) ^ 2) l l ⊢ Tendsto (fun y => (y + c * (y - x) ^ 2 - x) / (y - x)) l (𝓝 1) [PROOFSTEP] have : Tendsto (fun y => 1 + c * (y - x)) l (𝓝 (1 + c * (x - x))) := by apply Tendsto.mono_left _ (hl.trans nhdsWithin_le_nhds) exact ((tendsto_id.sub_const x).const_mul c).const_add 1 [GOAL] f : ℝ → ℝ x a c d : ℝ l : Filter ℝ hl : l ≤ 𝓝[{x}ᶜ] x hf : Tendsto (fun y => (f y - d) / (y - x)) l (𝓝 a) h' : Tendsto (fun y => y + c * (y - x) ^ 2) l l ⊢ Tendsto (fun y => 1 + c * (y - x)) l (𝓝 (1 + c * (x - x))) [PROOFSTEP] apply Tendsto.mono_left _ (hl.trans nhdsWithin_le_nhds) [GOAL] f : ℝ → ℝ x a c d : ℝ l : Filter ℝ hl : l ≤ 𝓝[{x}ᶜ] x hf : Tendsto (fun y => (f y - d) / (y - x)) l (𝓝 a) h' : Tendsto (fun y => y + c * (y - x) ^ 2) l l ⊢ Tendsto (fun y => 1 + c * (y - x)) (𝓝 x) (𝓝 (1 + c * (x - x))) [PROOFSTEP] exact ((tendsto_id.sub_const x).const_mul c).const_add 1 [GOAL] f : ℝ → ℝ x a c d : ℝ l : Filter ℝ hl : l ≤ 𝓝[{x}ᶜ] x hf : Tendsto (fun y => (f y - d) / (y - x)) l (𝓝 a) h' : Tendsto (fun y => y + c * (y - x) ^ 2) l l this : Tendsto (fun y => 1 + c * (y - x)) l (𝓝 (1 + c * (x - x))) ⊢ Tendsto (fun y => (y + c * (y - x) ^ 2 - x) / (y - x)) l (𝓝 1) [PROOFSTEP] simp only [_root_.sub_self, add_zero, mul_zero] at this [GOAL] f : ℝ → ℝ x a c d : ℝ l : Filter ℝ hl : l ≤ 𝓝[{x}ᶜ] x hf : Tendsto (fun y => (f y - d) / (y - x)) l (𝓝 a) h' : Tendsto (fun y => y + c * (y - x) ^ 2) l l this : Tendsto (fun y => 1 + c * (y - x)) l (𝓝 1) ⊢ Tendsto (fun y => (y + c * (y - x) ^ 2 - x) / (y - x)) l (𝓝 1) [PROOFSTEP] apply Tendsto.congr' (Eventually.filter_mono hl _) this [GOAL] f : ℝ → ℝ x a c d : ℝ l : Filter ℝ hl : l ≤ 𝓝[{x}ᶜ] x hf : Tendsto (fun y => (f y - d) / (y - x)) l (𝓝 a) h' : Tendsto (fun y => y + c * (y - x) ^ 2) l l this : Tendsto (fun y => 1 + c * (y - x)) l (𝓝 1) ⊢ ∀ᶠ (x_1 : ℝ) in 𝓝[{x}ᶜ] x, 1 + c * (x_1 - x) = (x_1 + c * (x_1 - x) ^ 2 - x) / (x_1 - x) [PROOFSTEP] filter_upwards [self_mem_nhdsWithin] with y hy [GOAL] case h f : ℝ → ℝ x a c d : ℝ l : Filter ℝ hl : l ≤ 𝓝[{x}ᶜ] x hf : Tendsto (fun y => (f y - d) / (y - x)) l (𝓝 a) h' : Tendsto (fun y => y + c * (y - x) ^ 2) l l this : Tendsto (fun y => 1 + c * (y - x)) l (𝓝 1) y : ℝ hy : y ∈ {x}ᶜ ⊢ 1 + c * (y - x) = (y + c * (y - x) ^ 2 - x) / (y - x) [PROOFSTEP] field_simp [sub_ne_zero.2 hy] [GOAL] case h f : ℝ → ℝ x a c d : ℝ l : Filter ℝ hl : l ≤ 𝓝[{x}ᶜ] x hf : Tendsto (fun y => (f y - d) / (y - x)) l (𝓝 a) h' : Tendsto (fun y => y + c * (y - x) ^ 2) l l this : Tendsto (fun y => 1 + c * (y - x)) l (𝓝 1) y : ℝ hy : y ∈ {x}ᶜ ⊢ (1 + c * (y - x)) * (y - x) = y + c * (y - x) ^ 2 - x [PROOFSTEP] ring [GOAL] f : ℝ → ℝ x a c d : ℝ l : Filter ℝ hl : l ≤ 𝓝[{x}ᶜ] x hf : Tendsto (fun y => (f y - d) / (y - x)) l (𝓝 a) h' : Tendsto (fun y => y + c * (y - x) ^ 2) l l L : Tendsto (fun y => (y + c * (y - x) ^ 2 - x) / (y - x)) l (𝓝 1) ⊢ Tendsto (fun y => (f (y + c * (y - x) ^ 2) - d) / (y - x)) l (𝓝 a) [PROOFSTEP] have Z := (hf.comp h').mul L [GOAL] f : ℝ → ℝ x a c d : ℝ l : Filter ℝ hl : l ≤ 𝓝[{x}ᶜ] x hf : Tendsto (fun y => (f y - d) / (y - x)) l (𝓝 a) h' : Tendsto (fun y => y + c * (y - x) ^ 2) l l L : Tendsto (fun y => (y + c * (y - x) ^ 2 - x) / (y - x)) l (𝓝 1) Z : Tendsto (fun x_1 => ((fun y => (f y - d) / (y - x)) ∘ fun y => y + c * (y - x) ^ 2) x_1 * ((x_1 + c * (x_1 - x) ^ 2 - x) / (x_1 - x))) l (𝓝 (a * 1)) ⊢ Tendsto (fun y => (f (y + c * (y - x) ^ 2) - d) / (y - x)) l (𝓝 a) [PROOFSTEP] rw [mul_one] at Z [GOAL] f : ℝ → ℝ x a c d : ℝ l : Filter ℝ hl : l ≤ 𝓝[{x}ᶜ] x hf : Tendsto (fun y => (f y - d) / (y - x)) l (𝓝 a) h' : Tendsto (fun y => y + c * (y - x) ^ 2) l l L : Tendsto (fun y => (y + c * (y - x) ^ 2 - x) / (y - x)) l (𝓝 1) Z : Tendsto (fun x_1 => ((fun y => (f y - d) / (y - x)) ∘ fun y => y + c * (y - x) ^ 2) x_1 * ((x_1 + c * (x_1 - x) ^ 2 - x) / (x_1 - x))) l (𝓝 a) ⊢ Tendsto (fun y => (f (y + c * (y - x) ^ 2) - d) / (y - x)) l (𝓝 a) [PROOFSTEP] apply Tendsto.congr' _ Z [GOAL] f : ℝ → ℝ x a c d : ℝ l : Filter ℝ hl : l ≤ 𝓝[{x}ᶜ] x hf : Tendsto (fun y => (f y - d) / (y - x)) l (𝓝 a) h' : Tendsto (fun y => y + c * (y - x) ^ 2) l l L : Tendsto (fun y => (y + c * (y - x) ^ 2 - x) / (y - x)) l (𝓝 1) Z : Tendsto (fun x_1 => ((fun y => (f y - d) / (y - x)) ∘ fun y => y + c * (y - x) ^ 2) x_1 * ((x_1 + c * (x_1 - x) ^ 2 - x) / (x_1 - x))) l (𝓝 a) ⊢ (fun x_1 => ((fun y => (f y - d) / (y - x)) ∘ fun y => y + c * (y - x) ^ 2) x_1 * ((x_1 + c * (x_1 - x) ^ 2 - x) / (x_1 - x))) =ᶠ[l] fun y => (f (y + c * (y - x) ^ 2) - d) / (y - x) [PROOFSTEP] have : ∀ᶠ y in l, y + c * (y - x) ^ 2 ≠ x := by apply Tendsto.mono_right h' hl self_mem_nhdsWithin [GOAL] f : ℝ → ℝ x a c d : ℝ l : Filter ℝ hl : l ≤ 𝓝[{x}ᶜ] x hf : Tendsto (fun y => (f y - d) / (y - x)) l (𝓝 a) h' : Tendsto (fun y => y + c * (y - x) ^ 2) l l L : Tendsto (fun y => (y + c * (y - x) ^ 2 - x) / (y - x)) l (𝓝 1) Z : Tendsto (fun x_1 => ((fun y => (f y - d) / (y - x)) ∘ fun y => y + c * (y - x) ^ 2) x_1 * ((x_1 + c * (x_1 - x) ^ 2 - x) / (x_1 - x))) l (𝓝 a) ⊢ ∀ᶠ (y : ℝ) in l, y + c * (y - x) ^ 2 ≠ x [PROOFSTEP] apply Tendsto.mono_right h' hl self_mem_nhdsWithin [GOAL] f : ℝ → ℝ x a c d : ℝ l : Filter ℝ hl : l ≤ 𝓝[{x}ᶜ] x hf : Tendsto (fun y => (f y - d) / (y - x)) l (𝓝 a) h' : Tendsto (fun y => y + c * (y - x) ^ 2) l l L : Tendsto (fun y => (y + c * (y - x) ^ 2 - x) / (y - x)) l (𝓝 1) Z : Tendsto (fun x_1 => ((fun y => (f y - d) / (y - x)) ∘ fun y => y + c * (y - x) ^ 2) x_1 * ((x_1 + c * (x_1 - x) ^ 2 - x) / (x_1 - x))) l (𝓝 a) this : ∀ᶠ (y : ℝ) in l, y + c * (y - x) ^ 2 ≠ x ⊢ (fun x_1 => ((fun y => (f y - d) / (y - x)) ∘ fun y => y + c * (y - x) ^ 2) x_1 * ((x_1 + c * (x_1 - x) ^ 2 - x) / (x_1 - x))) =ᶠ[l] fun y => (f (y + c * (y - x) ^ 2) - d) / (y - x) [PROOFSTEP] filter_upwards [this] with y hy [GOAL] case h f : ℝ → ℝ x a c d : ℝ l : Filter ℝ hl : l ≤ 𝓝[{x}ᶜ] x hf : Tendsto (fun y => (f y - d) / (y - x)) l (𝓝 a) h' : Tendsto (fun y => y + c * (y - x) ^ 2) l l L : Tendsto (fun y => (y + c * (y - x) ^ 2 - x) / (y - x)) l (𝓝 1) Z : Tendsto (fun x_1 => ((fun y => (f y - d) / (y - x)) ∘ fun y => y + c * (y - x) ^ 2) x_1 * ((x_1 + c * (x_1 - x) ^ 2 - x) / (x_1 - x))) l (𝓝 a) this : ∀ᶠ (y : ℝ) in l, y + c * (y - x) ^ 2 ≠ x y : ℝ hy : y + c * (y - x) ^ 2 ≠ x ⊢ ((fun y => (f y - d) / (y - x)) ∘ fun y => y + c * (y - x) ^ 2) y * ((y + c * (y - x) ^ 2 - x) / (y - x)) = (f (y + c * (y - x) ^ 2) - d) / (y - x) [PROOFSTEP] field_simp [sub_ne_zero.2 hy] [GOAL] f : StieltjesFunction ⊢ ∀ᵐ (x : ℝ), HasDerivAt (↑f) (ENNReal.toReal (rnDeriv (StieltjesFunction.measure f) volume x)) x [PROOFSTEP] filter_upwards [VitaliFamily.ae_tendsto_rnDeriv (vitaliFamily (volume : Measure ℝ) 1) f.measure, rnDeriv_lt_top f.measure volume, f.countable_leftLim_ne.ae_not_mem volume] with x hx h'x h''x [GOAL] case h f : StieltjesFunction x : ℝ hx : Tendsto (fun a => ↑↑(StieltjesFunction.measure f) a / ↑↑volume a) (VitaliFamily.filterAt (vitaliFamily volume 1) x) (𝓝 (rnDeriv (StieltjesFunction.measure f) volume x)) h'x : rnDeriv (StieltjesFunction.measure f) volume x < ⊤ h''x : ¬leftLim (↑f) x ≠ ↑f x ⊢ HasDerivAt (↑f) (ENNReal.toReal (rnDeriv (StieltjesFunction.measure f) volume x)) x [PROOFSTEP] have L1 : Tendsto (fun y => (f y - f x) / (y - x)) (𝓝[>] x) (𝓝 (rnDeriv f.measure volume x).toReal) := by apply Tendsto.congr' _ ((ENNReal.tendsto_toReal h'x.ne).comp (hx.comp (Real.tendsto_Icc_vitaliFamily_right x))) filter_upwards [self_mem_nhdsWithin] rintro y (hxy : x < y) simp only [comp_apply, StieltjesFunction.measure_Icc, Real.volume_Icc, Classical.not_not.1 h''x] rw [← ENNReal.ofReal_div_of_pos (sub_pos.2 hxy), ENNReal.toReal_ofReal] exact div_nonneg (sub_nonneg.2 (f.mono hxy.le)) (sub_pos.2 hxy).le [GOAL] f : StieltjesFunction x : ℝ hx : Tendsto (fun a => ↑↑(StieltjesFunction.measure f) a / ↑↑volume a) (VitaliFamily.filterAt (vitaliFamily volume 1) x) (𝓝 (rnDeriv (StieltjesFunction.measure f) volume x)) h'x : rnDeriv (StieltjesFunction.measure f) volume x < ⊤ h''x : ¬leftLim (↑f) x ≠ ↑f x ⊢ Tendsto (fun y => (↑f y - ↑f x) / (y - x)) (𝓝[Ioi x] x) (𝓝 (ENNReal.toReal (rnDeriv (StieltjesFunction.measure f) volume x))) [PROOFSTEP] apply Tendsto.congr' _ ((ENNReal.tendsto_toReal h'x.ne).comp (hx.comp (Real.tendsto_Icc_vitaliFamily_right x))) [GOAL] f : StieltjesFunction x : ℝ hx : Tendsto (fun a => ↑↑(StieltjesFunction.measure f) a / ↑↑volume a) (VitaliFamily.filterAt (vitaliFamily volume 1) x) (𝓝 (rnDeriv (StieltjesFunction.measure f) volume x)) h'x : rnDeriv (StieltjesFunction.measure f) volume x < ⊤ h''x : ¬leftLim (↑f) x ≠ ↑f x ⊢ (ENNReal.toReal ∘ (fun a => ↑↑(StieltjesFunction.measure f) a / ↑↑volume a) ∘ fun y => Icc x y) =ᶠ[𝓝[Ioi x] x] fun y => (↑f y - ↑f x) / (y - x) [PROOFSTEP] filter_upwards [self_mem_nhdsWithin] [GOAL] case h f : StieltjesFunction x : ℝ hx : Tendsto (fun a => ↑↑(StieltjesFunction.measure f) a / ↑↑volume a) (VitaliFamily.filterAt (vitaliFamily volume 1) x) (𝓝 (rnDeriv (StieltjesFunction.measure f) volume x)) h'x : rnDeriv (StieltjesFunction.measure f) volume x < ⊤ h''x : ¬leftLim (↑f) x ≠ ↑f x ⊢ ∀ (a : ℝ), a ∈ Ioi x → (ENNReal.toReal ∘ (fun a => ↑↑(StieltjesFunction.measure f) a / ↑↑volume a) ∘ fun y => Icc x y) a = (↑f a - ↑f x) / (a - x) [PROOFSTEP] rintro y (hxy : x < y) [GOAL] case h f : StieltjesFunction x : ℝ hx : Tendsto (fun a => ↑↑(StieltjesFunction.measure f) a / ↑↑volume a) (VitaliFamily.filterAt (vitaliFamily volume 1) x) (𝓝 (rnDeriv (StieltjesFunction.measure f) volume x)) h'x : rnDeriv (StieltjesFunction.measure f) volume x < ⊤ h''x : ¬leftLim (↑f) x ≠ ↑f x y : ℝ hxy : x < y ⊢ (ENNReal.toReal ∘ (fun a => ↑↑(StieltjesFunction.measure f) a / ↑↑volume a) ∘ fun y => Icc x y) y = (↑f y - ↑f x) / (y - x) [PROOFSTEP] simp only [comp_apply, StieltjesFunction.measure_Icc, Real.volume_Icc, Classical.not_not.1 h''x] [GOAL] case h f : StieltjesFunction x : ℝ hx : Tendsto (fun a => ↑↑(StieltjesFunction.measure f) a / ↑↑volume a) (VitaliFamily.filterAt (vitaliFamily volume 1) x) (𝓝 (rnDeriv (StieltjesFunction.measure f) volume x)) h'x : rnDeriv (StieltjesFunction.measure f) volume x < ⊤ h''x : ¬leftLim (↑f) x ≠ ↑f x y : ℝ hxy : x < y ⊢ ENNReal.toReal (ENNReal.ofReal (↑f y - ↑f x) / ENNReal.ofReal (y - x)) = (↑f y - ↑f x) / (y - x) [PROOFSTEP] rw [← ENNReal.ofReal_div_of_pos (sub_pos.2 hxy), ENNReal.toReal_ofReal] [GOAL] case h f : StieltjesFunction x : ℝ hx : Tendsto (fun a => ↑↑(StieltjesFunction.measure f) a / ↑↑volume a) (VitaliFamily.filterAt (vitaliFamily volume 1) x) (𝓝 (rnDeriv (StieltjesFunction.measure f) volume x)) h'x : rnDeriv (StieltjesFunction.measure f) volume x < ⊤ h''x : ¬leftLim (↑f) x ≠ ↑f x y : ℝ hxy : x < y ⊢ 0 ≤ (↑f y - ↑f x) / (y - x) [PROOFSTEP] exact div_nonneg (sub_nonneg.2 (f.mono hxy.le)) (sub_pos.2 hxy).le [GOAL] case h f : StieltjesFunction x : ℝ hx : Tendsto (fun a => ↑↑(StieltjesFunction.measure f) a / ↑↑volume a) (VitaliFamily.filterAt (vitaliFamily volume 1) x) (𝓝 (rnDeriv (StieltjesFunction.measure f) volume x)) h'x : rnDeriv (StieltjesFunction.measure f) volume x < ⊤ h''x : ¬leftLim (↑f) x ≠ ↑f x L1 : Tendsto (fun y => (↑f y - ↑f x) / (y - x)) (𝓝[Ioi x] x) (𝓝 (ENNReal.toReal (rnDeriv (StieltjesFunction.measure f) volume x))) ⊢ HasDerivAt (↑f) (ENNReal.toReal (rnDeriv (StieltjesFunction.measure f) volume x)) x [PROOFSTEP] have L2 : Tendsto (fun y => (leftLim f y - f x) / (y - x)) (𝓝[<] x) (𝓝 (rnDeriv f.measure volume x).toReal) := by apply Tendsto.congr' _ ((ENNReal.tendsto_toReal h'x.ne).comp (hx.comp (Real.tendsto_Icc_vitaliFamily_left x))) filter_upwards [self_mem_nhdsWithin] rintro y (hxy : y < x) simp only [comp_apply, StieltjesFunction.measure_Icc, Real.volume_Icc] rw [← ENNReal.ofReal_div_of_pos (sub_pos.2 hxy), ENNReal.toReal_ofReal, ← neg_neg (y - x), div_neg, neg_div', neg_sub, neg_sub] exact div_nonneg (sub_nonneg.2 (f.mono.leftLim_le hxy.le)) (sub_pos.2 hxy).le [GOAL] f : StieltjesFunction x : ℝ hx : Tendsto (fun a => ↑↑(StieltjesFunction.measure f) a / ↑↑volume a) (VitaliFamily.filterAt (vitaliFamily volume 1) x) (𝓝 (rnDeriv (StieltjesFunction.measure f) volume x)) h'x : rnDeriv (StieltjesFunction.measure f) volume x < ⊤ h''x : ¬leftLim (↑f) x ≠ ↑f x L1 : Tendsto (fun y => (↑f y - ↑f x) / (y - x)) (𝓝[Ioi x] x) (𝓝 (ENNReal.toReal (rnDeriv (StieltjesFunction.measure f) volume x))) ⊢ Tendsto (fun y => (leftLim (↑f) y - ↑f x) / (y - x)) (𝓝[Iio x] x) (𝓝 (ENNReal.toReal (rnDeriv (StieltjesFunction.measure f) volume x))) [PROOFSTEP] apply Tendsto.congr' _ ((ENNReal.tendsto_toReal h'x.ne).comp (hx.comp (Real.tendsto_Icc_vitaliFamily_left x))) [GOAL] f : StieltjesFunction x : ℝ hx : Tendsto (fun a => ↑↑(StieltjesFunction.measure f) a / ↑↑volume a) (VitaliFamily.filterAt (vitaliFamily volume 1) x) (𝓝 (rnDeriv (StieltjesFunction.measure f) volume x)) h'x : rnDeriv (StieltjesFunction.measure f) volume x < ⊤ h''x : ¬leftLim (↑f) x ≠ ↑f x L1 : Tendsto (fun y => (↑f y - ↑f x) / (y - x)) (𝓝[Ioi x] x) (𝓝 (ENNReal.toReal (rnDeriv (StieltjesFunction.measure f) volume x))) ⊢ (ENNReal.toReal ∘ (fun a => ↑↑(StieltjesFunction.measure f) a / ↑↑volume a) ∘ fun y => Icc y x) =ᶠ[𝓝[Iio x] x] fun y => (leftLim (↑f) y - ↑f x) / (y - x) [PROOFSTEP] filter_upwards [self_mem_nhdsWithin] [GOAL] case h f : StieltjesFunction x : ℝ hx : Tendsto (fun a => ↑↑(StieltjesFunction.measure f) a / ↑↑volume a) (VitaliFamily.filterAt (vitaliFamily volume 1) x) (𝓝 (rnDeriv (StieltjesFunction.measure f) volume x)) h'x : rnDeriv (StieltjesFunction.measure f) volume x < ⊤ h''x : ¬leftLim (↑f) x ≠ ↑f x L1 : Tendsto (fun y => (↑f y - ↑f x) / (y - x)) (𝓝[Ioi x] x) (𝓝 (ENNReal.toReal (rnDeriv (StieltjesFunction.measure f) volume x))) ⊢ ∀ (a : ℝ), a ∈ Iio x → (ENNReal.toReal ∘ (fun a => ↑↑(StieltjesFunction.measure f) a / ↑↑volume a) ∘ fun y => Icc y x) a = (leftLim (↑f) a - ↑f x) / (a - x) [PROOFSTEP] rintro y (hxy : y < x) [GOAL] case h f : StieltjesFunction x : ℝ hx : Tendsto (fun a => ↑↑(StieltjesFunction.measure f) a / ↑↑volume a) (VitaliFamily.filterAt (vitaliFamily volume 1) x) (𝓝 (rnDeriv (StieltjesFunction.measure f) volume x)) h'x : rnDeriv (StieltjesFunction.measure f) volume x < ⊤ h''x : ¬leftLim (↑f) x ≠ ↑f x L1 : Tendsto (fun y => (↑f y - ↑f x) / (y - x)) (𝓝[Ioi x] x) (𝓝 (ENNReal.toReal (rnDeriv (StieltjesFunction.measure f) volume x))) y : ℝ hxy : y < x ⊢ (ENNReal.toReal ∘ (fun a => ↑↑(StieltjesFunction.measure f) a / ↑↑volume a) ∘ fun y => Icc y x) y = (leftLim (↑f) y - ↑f x) / (y - x) [PROOFSTEP] simp only [comp_apply, StieltjesFunction.measure_Icc, Real.volume_Icc] [GOAL] case h f : StieltjesFunction x : ℝ hx : Tendsto (fun a => ↑↑(StieltjesFunction.measure f) a / ↑↑volume a) (VitaliFamily.filterAt (vitaliFamily volume 1) x) (𝓝 (rnDeriv (StieltjesFunction.measure f) volume x)) h'x : rnDeriv (StieltjesFunction.measure f) volume x < ⊤ h''x : ¬leftLim (↑f) x ≠ ↑f x L1 : Tendsto (fun y => (↑f y - ↑f x) / (y - x)) (𝓝[Ioi x] x) (𝓝 (ENNReal.toReal (rnDeriv (StieltjesFunction.measure f) volume x))) y : ℝ hxy : y < x ⊢ ENNReal.toReal (ENNReal.ofReal (↑f x - leftLim (↑f) y) / ENNReal.ofReal (x - y)) = (leftLim (↑f) y - ↑f x) / (y - x) [PROOFSTEP] rw [← ENNReal.ofReal_div_of_pos (sub_pos.2 hxy), ENNReal.toReal_ofReal, ← neg_neg (y - x), div_neg, neg_div', neg_sub, neg_sub] [GOAL] case h f : StieltjesFunction x : ℝ hx : Tendsto (fun a => ↑↑(StieltjesFunction.measure f) a / ↑↑volume a) (VitaliFamily.filterAt (vitaliFamily volume 1) x) (𝓝 (rnDeriv (StieltjesFunction.measure f) volume x)) h'x : rnDeriv (StieltjesFunction.measure f) volume x < ⊤ h''x : ¬leftLim (↑f) x ≠ ↑f x L1 : Tendsto (fun y => (↑f y - ↑f x) / (y - x)) (𝓝[Ioi x] x) (𝓝 (ENNReal.toReal (rnDeriv (StieltjesFunction.measure f) volume x))) y : ℝ hxy : y < x ⊢ 0 ≤ (↑f x - leftLim (↑f) y) / (x - y) [PROOFSTEP] exact div_nonneg (sub_nonneg.2 (f.mono.leftLim_le hxy.le)) (sub_pos.2 hxy).le [GOAL] case h f : StieltjesFunction x : ℝ hx : Tendsto (fun a => ↑↑(StieltjesFunction.measure f) a / ↑↑volume a) (VitaliFamily.filterAt (vitaliFamily volume 1) x) (𝓝 (rnDeriv (StieltjesFunction.measure f) volume x)) h'x : rnDeriv (StieltjesFunction.measure f) volume x < ⊤ h''x : ¬leftLim (↑f) x ≠ ↑f x L1 : Tendsto (fun y => (↑f y - ↑f x) / (y - x)) (𝓝[Ioi x] x) (𝓝 (ENNReal.toReal (rnDeriv (StieltjesFunction.measure f) volume x))) L2 : Tendsto (fun y => (leftLim (↑f) y - ↑f x) / (y - x)) (𝓝[Iio x] x) (𝓝 (ENNReal.toReal (rnDeriv (StieltjesFunction.measure f) volume x))) ⊢ HasDerivAt (↑f) (ENNReal.toReal (rnDeriv (StieltjesFunction.measure f) volume x)) x [PROOFSTEP] have L3 : Tendsto (fun y => (leftLim f (y + 1 * (y - x) ^ 2) - f x) / (y - x)) (𝓝[<] x) (𝓝 (rnDeriv f.measure volume x).toReal) := by apply tendsto_apply_add_mul_sq_div_sub (nhds_left'_le_nhds_ne x) L2 apply tendsto_nhdsWithin_of_tendsto_nhds_of_eventually_within · apply Tendsto.mono_left _ nhdsWithin_le_nhds have : Tendsto (fun y : ℝ => y + ↑1 * (y - x) ^ 2) (𝓝 x) (𝓝 (x + ↑1 * (x - x) ^ 2)) := tendsto_id.add (((tendsto_id.sub_const x).pow 2).const_mul ↑1) simpa using this · have : Ioo (x - 1) x ∈ 𝓝[<] x := by apply Ioo_mem_nhdsWithin_Iio; exact ⟨by linarith, le_refl _⟩ filter_upwards [this] rintro y ⟨hy : x - 1 < y, h'y : y < x⟩ rw [mem_Iio] norm_num; nlinarith -- Deduce the correct limit on the left, by sandwiching. [GOAL] f : StieltjesFunction x : ℝ hx : Tendsto (fun a => ↑↑(StieltjesFunction.measure f) a / ↑↑volume a) (VitaliFamily.filterAt (vitaliFamily volume 1) x) (𝓝 (rnDeriv (StieltjesFunction.measure f) volume x)) h'x : rnDeriv (StieltjesFunction.measure f) volume x < ⊤ h''x : ¬leftLim (↑f) x ≠ ↑f x L1 : Tendsto (fun y => (↑f y - ↑f x) / (y - x)) (𝓝[Ioi x] x) (𝓝 (ENNReal.toReal (rnDeriv (StieltjesFunction.measure f) volume x))) L2 : Tendsto (fun y => (leftLim (↑f) y - ↑f x) / (y - x)) (𝓝[Iio x] x) (𝓝 (ENNReal.toReal (rnDeriv (StieltjesFunction.measure f) volume x))) ⊢ Tendsto (fun y => (leftLim (↑f) (y + ↑1 * (y - x) ^ 2) - ↑f x) / (y - x)) (𝓝[Iio x] x) (𝓝 (ENNReal.toReal (rnDeriv (StieltjesFunction.measure f) volume x))) [PROOFSTEP] apply tendsto_apply_add_mul_sq_div_sub (nhds_left'_le_nhds_ne x) L2 [GOAL] f : StieltjesFunction x : ℝ hx : Tendsto (fun a => ↑↑(StieltjesFunction.measure f) a / ↑↑volume a) (VitaliFamily.filterAt (vitaliFamily volume 1) x) (𝓝 (rnDeriv (StieltjesFunction.measure f) volume x)) h'x : rnDeriv (StieltjesFunction.measure f) volume x < ⊤ h''x : ¬leftLim (↑f) x ≠ ↑f x L1 : Tendsto (fun y => (↑f y - ↑f x) / (y - x)) (𝓝[Ioi x] x) (𝓝 (ENNReal.toReal (rnDeriv (StieltjesFunction.measure f) volume x))) L2 : Tendsto (fun y => (leftLim (↑f) y - ↑f x) / (y - x)) (𝓝[Iio x] x) (𝓝 (ENNReal.toReal (rnDeriv (StieltjesFunction.measure f) volume x))) ⊢ Tendsto (fun y => y + ↑1 * (y - x) ^ 2) (𝓝[Iio x] x) (𝓝[Iio x] x) [PROOFSTEP] apply tendsto_nhdsWithin_of_tendsto_nhds_of_eventually_within [GOAL] case h1 f : StieltjesFunction x : ℝ hx : Tendsto (fun a => ↑↑(StieltjesFunction.measure f) a / ↑↑volume a) (VitaliFamily.filterAt (vitaliFamily volume 1) x) (𝓝 (rnDeriv (StieltjesFunction.measure f) volume x)) h'x : rnDeriv (StieltjesFunction.measure f) volume x < ⊤ h''x : ¬leftLim (↑f) x ≠ ↑f x L1 : Tendsto (fun y => (↑f y - ↑f x) / (y - x)) (𝓝[Ioi x] x) (𝓝 (ENNReal.toReal (rnDeriv (StieltjesFunction.measure f) volume x))) L2 : Tendsto (fun y => (leftLim (↑f) y - ↑f x) / (y - x)) (𝓝[Iio x] x) (𝓝 (ENNReal.toReal (rnDeriv (StieltjesFunction.measure f) volume x))) ⊢ Tendsto (fun y => y + ↑1 * (y - x) ^ 2) (𝓝[Iio x] x) (𝓝 x) [PROOFSTEP] apply Tendsto.mono_left _ nhdsWithin_le_nhds [GOAL] f : StieltjesFunction x : ℝ hx : Tendsto (fun a => ↑↑(StieltjesFunction.measure f) a / ↑↑volume a) (VitaliFamily.filterAt (vitaliFamily volume 1) x) (𝓝 (rnDeriv (StieltjesFunction.measure f) volume x)) h'x : rnDeriv (StieltjesFunction.measure f) volume x < ⊤ h''x : ¬leftLim (↑f) x ≠ ↑f x L1 : Tendsto (fun y => (↑f y - ↑f x) / (y - x)) (𝓝[Ioi x] x) (𝓝 (ENNReal.toReal (rnDeriv (StieltjesFunction.measure f) volume x))) L2 : Tendsto (fun y => (leftLim (↑f) y - ↑f x) / (y - x)) (𝓝[Iio x] x) (𝓝 (ENNReal.toReal (rnDeriv (StieltjesFunction.measure f) volume x))) ⊢ Tendsto (fun y => y + ↑1 * (y - x) ^ 2) (𝓝 x) (𝓝 x) [PROOFSTEP] have : Tendsto (fun y : ℝ => y + ↑1 * (y - x) ^ 2) (𝓝 x) (𝓝 (x + ↑1 * (x - x) ^ 2)) := tendsto_id.add (((tendsto_id.sub_const x).pow 2).const_mul ↑1) [GOAL] f : StieltjesFunction x : ℝ hx : Tendsto (fun a => ↑↑(StieltjesFunction.measure f) a / ↑↑volume a) (VitaliFamily.filterAt (vitaliFamily volume 1) x) (𝓝 (rnDeriv (StieltjesFunction.measure f) volume x)) h'x : rnDeriv (StieltjesFunction.measure f) volume x < ⊤ h''x : ¬leftLim (↑f) x ≠ ↑f x L1 : Tendsto (fun y => (↑f y - ↑f x) / (y - x)) (𝓝[Ioi x] x) (𝓝 (ENNReal.toReal (rnDeriv (StieltjesFunction.measure f) volume x))) L2 : Tendsto (fun y => (leftLim (↑f) y - ↑f x) / (y - x)) (𝓝[Iio x] x) (𝓝 (ENNReal.toReal (rnDeriv (StieltjesFunction.measure f) volume x))) this : Tendsto (fun y => y + 1 * (y - x) ^ 2) (𝓝 x) (𝓝 (x + 1 * (x - x) ^ 2)) ⊢ Tendsto (fun y => y + ↑1 * (y - x) ^ 2) (𝓝 x) (𝓝 x) [PROOFSTEP] simpa using this [GOAL] case h2 f : StieltjesFunction x : ℝ hx : Tendsto (fun a => ↑↑(StieltjesFunction.measure f) a / ↑↑volume a) (VitaliFamily.filterAt (vitaliFamily volume 1) x) (𝓝 (rnDeriv (StieltjesFunction.measure f) volume x)) h'x : rnDeriv (StieltjesFunction.measure f) volume x < ⊤ h''x : ¬leftLim (↑f) x ≠ ↑f x L1 : Tendsto (fun y => (↑f y - ↑f x) / (y - x)) (𝓝[Ioi x] x) (𝓝 (ENNReal.toReal (rnDeriv (StieltjesFunction.measure f) volume x))) L2 : Tendsto (fun y => (leftLim (↑f) y - ↑f x) / (y - x)) (𝓝[Iio x] x) (𝓝 (ENNReal.toReal (rnDeriv (StieltjesFunction.measure f) volume x))) ⊢ ∀ᶠ (x_1 : ℝ) in 𝓝[Iio x] x, x_1 + ↑1 * (x_1 - x) ^ 2 ∈ Iio x [PROOFSTEP] have : Ioo (x - 1) x ∈ 𝓝[<] x := by apply Ioo_mem_nhdsWithin_Iio; exact ⟨by linarith, le_refl _⟩ [GOAL] f : StieltjesFunction x : ℝ hx : Tendsto (fun a => ↑↑(StieltjesFunction.measure f) a / ↑↑volume a) (VitaliFamily.filterAt (vitaliFamily volume 1) x) (𝓝 (rnDeriv (StieltjesFunction.measure f) volume x)) h'x : rnDeriv (StieltjesFunction.measure f) volume x < ⊤ h''x : ¬leftLim (↑f) x ≠ ↑f x L1 : Tendsto (fun y => (↑f y - ↑f x) / (y - x)) (𝓝[Ioi x] x) (𝓝 (ENNReal.toReal (rnDeriv (StieltjesFunction.measure f) volume x))) L2 : Tendsto (fun y => (leftLim (↑f) y - ↑f x) / (y - x)) (𝓝[Iio x] x) (𝓝 (ENNReal.toReal (rnDeriv (StieltjesFunction.measure f) volume x))) ⊢ Ioo (x - 1) x ∈ 𝓝[Iio x] x [PROOFSTEP] apply Ioo_mem_nhdsWithin_Iio [GOAL] case H f : StieltjesFunction x : ℝ hx : Tendsto (fun a => ↑↑(StieltjesFunction.measure f) a / ↑↑volume a) (VitaliFamily.filterAt (vitaliFamily volume 1) x) (𝓝 (rnDeriv (StieltjesFunction.measure f) volume x)) h'x : rnDeriv (StieltjesFunction.measure f) volume x < ⊤ h''x : ¬leftLim (↑f) x ≠ ↑f x L1 : Tendsto (fun y => (↑f y - ↑f x) / (y - x)) (𝓝[Ioi x] x) (𝓝 (ENNReal.toReal (rnDeriv (StieltjesFunction.measure f) volume x))) L2 : Tendsto (fun y => (leftLim (↑f) y - ↑f x) / (y - x)) (𝓝[Iio x] x) (𝓝 (ENNReal.toReal (rnDeriv (StieltjesFunction.measure f) volume x))) ⊢ x ∈ Ioc (x - 1) x [PROOFSTEP] exact ⟨by linarith, le_refl _⟩ [GOAL] f : StieltjesFunction x : ℝ hx : Tendsto (fun a => ↑↑(StieltjesFunction.measure f) a / ↑↑volume a) (VitaliFamily.filterAt (vitaliFamily volume 1) x) (𝓝 (rnDeriv (StieltjesFunction.measure f) volume x)) h'x : rnDeriv (StieltjesFunction.measure f) volume x < ⊤ h''x : ¬leftLim (↑f) x ≠ ↑f x L1 : Tendsto (fun y => (↑f y - ↑f x) / (y - x)) (𝓝[Ioi x] x) (𝓝 (ENNReal.toReal (rnDeriv (StieltjesFunction.measure f) volume x))) L2 : Tendsto (fun y => (leftLim (↑f) y - ↑f x) / (y - x)) (𝓝[Iio x] x) (𝓝 (ENNReal.toReal (rnDeriv (StieltjesFunction.measure f) volume x))) ⊢ x - 1 < x [PROOFSTEP] linarith [GOAL] case h2 f : StieltjesFunction x : ℝ hx : Tendsto (fun a => ↑↑(StieltjesFunction.measure f) a / ↑↑volume a) (VitaliFamily.filterAt (vitaliFamily volume 1) x) (𝓝 (rnDeriv (StieltjesFunction.measure f) volume x)) h'x : rnDeriv (StieltjesFunction.measure f) volume x < ⊤ h''x : ¬leftLim (↑f) x ≠ ↑f x L1 : Tendsto (fun y => (↑f y - ↑f x) / (y - x)) (𝓝[Ioi x] x) (𝓝 (ENNReal.toReal (rnDeriv (StieltjesFunction.measure f) volume x))) L2 : Tendsto (fun y => (leftLim (↑f) y - ↑f x) / (y - x)) (𝓝[Iio x] x) (𝓝 (ENNReal.toReal (rnDeriv (StieltjesFunction.measure f) volume x))) this : Ioo (x - 1) x ∈ 𝓝[Iio x] x ⊢ ∀ᶠ (x_1 : ℝ) in 𝓝[Iio x] x, x_1 + ↑1 * (x_1 - x) ^ 2 ∈ Iio x [PROOFSTEP] filter_upwards [this] [GOAL] case h f : StieltjesFunction x : ℝ hx : Tendsto (fun a => ↑↑(StieltjesFunction.measure f) a / ↑↑volume a) (VitaliFamily.filterAt (vitaliFamily volume 1) x) (𝓝 (rnDeriv (StieltjesFunction.measure f) volume x)) h'x : rnDeriv (StieltjesFunction.measure f) volume x < ⊤ h''x : ¬leftLim (↑f) x ≠ ↑f x L1 : Tendsto (fun y => (↑f y - ↑f x) / (y - x)) (𝓝[Ioi x] x) (𝓝 (ENNReal.toReal (rnDeriv (StieltjesFunction.measure f) volume x))) L2 : Tendsto (fun y => (leftLim (↑f) y - ↑f x) / (y - x)) (𝓝[Iio x] x) (𝓝 (ENNReal.toReal (rnDeriv (StieltjesFunction.measure f) volume x))) this : Ioo (x - 1) x ∈ 𝓝[Iio x] x ⊢ ∀ (a : ℝ), a ∈ Ioo (x - 1) x → a + ↑1 * (a - x) ^ 2 ∈ Iio x [PROOFSTEP] rintro y ⟨hy : x - 1 < y, h'y : y < x⟩ [GOAL] case h.intro f : StieltjesFunction x : ℝ hx : Tendsto (fun a => ↑↑(StieltjesFunction.measure f) a / ↑↑volume a) (VitaliFamily.filterAt (vitaliFamily volume 1) x) (𝓝 (rnDeriv (StieltjesFunction.measure f) volume x)) h'x : rnDeriv (StieltjesFunction.measure f) volume x < ⊤ h''x : ¬leftLim (↑f) x ≠ ↑f x L1 : Tendsto (fun y => (↑f y - ↑f x) / (y - x)) (𝓝[Ioi x] x) (𝓝 (ENNReal.toReal (rnDeriv (StieltjesFunction.measure f) volume x))) L2 : Tendsto (fun y => (leftLim (↑f) y - ↑f x) / (y - x)) (𝓝[Iio x] x) (𝓝 (ENNReal.toReal (rnDeriv (StieltjesFunction.measure f) volume x))) this : Ioo (x - 1) x ∈ 𝓝[Iio x] x y : ℝ hy : x - 1 < y h'y : y < x ⊢ y + ↑1 * (y - x) ^ 2 ∈ Iio x [PROOFSTEP] rw [mem_Iio] [GOAL] case h.intro f : StieltjesFunction x : ℝ hx : Tendsto (fun a => ↑↑(StieltjesFunction.measure f) a / ↑↑volume a) (VitaliFamily.filterAt (vitaliFamily volume 1) x) (𝓝 (rnDeriv (StieltjesFunction.measure f) volume x)) h'x : rnDeriv (StieltjesFunction.measure f) volume x < ⊤ h''x : ¬leftLim (↑f) x ≠ ↑f x L1 : Tendsto (fun y => (↑f y - ↑f x) / (y - x)) (𝓝[Ioi x] x) (𝓝 (ENNReal.toReal (rnDeriv (StieltjesFunction.measure f) volume x))) L2 : Tendsto (fun y => (leftLim (↑f) y - ↑f x) / (y - x)) (𝓝[Iio x] x) (𝓝 (ENNReal.toReal (rnDeriv (StieltjesFunction.measure f) volume x))) this : Ioo (x - 1) x ∈ 𝓝[Iio x] x y : ℝ hy : x - 1 < y h'y : y < x ⊢ y + ↑1 * (y - x) ^ 2 < x [PROOFSTEP] norm_num [GOAL] case h.intro f : StieltjesFunction x : ℝ hx : Tendsto (fun a => ↑↑(StieltjesFunction.measure f) a / ↑↑volume a) (VitaliFamily.filterAt (vitaliFamily volume 1) x) (𝓝 (rnDeriv (StieltjesFunction.measure f) volume x)) h'x : rnDeriv (StieltjesFunction.measure f) volume x < ⊤ h''x : ¬leftLim (↑f) x ≠ ↑f x L1 : Tendsto (fun y => (↑f y - ↑f x) / (y - x)) (𝓝[Ioi x] x) (𝓝 (ENNReal.toReal (rnDeriv (StieltjesFunction.measure f) volume x))) L2 : Tendsto (fun y => (leftLim (↑f) y - ↑f x) / (y - x)) (𝓝[Iio x] x) (𝓝 (ENNReal.toReal (rnDeriv (StieltjesFunction.measure f) volume x))) this : Ioo (x - 1) x ∈ 𝓝[Iio x] x y : ℝ hy : x - 1 < y h'y : y < x ⊢ y + (y - x) ^ 2 < x [PROOFSTEP] nlinarith -- Deduce the correct limit on the left, by sandwiching. [GOAL] case h f : StieltjesFunction x : ℝ hx : Tendsto (fun a => ↑↑(StieltjesFunction.measure f) a / ↑↑volume a) (VitaliFamily.filterAt (vitaliFamily volume 1) x) (𝓝 (rnDeriv (StieltjesFunction.measure f) volume x)) h'x : rnDeriv (StieltjesFunction.measure f) volume x < ⊤ h''x : ¬leftLim (↑f) x ≠ ↑f x L1 : Tendsto (fun y => (↑f y - ↑f x) / (y - x)) (𝓝[Ioi x] x) (𝓝 (ENNReal.toReal (rnDeriv (StieltjesFunction.measure f) volume x))) L2 : Tendsto (fun y => (leftLim (↑f) y - ↑f x) / (y - x)) (𝓝[Iio x] x) (𝓝 (ENNReal.toReal (rnDeriv (StieltjesFunction.measure f) volume x))) L3 : Tendsto (fun y => (leftLim (↑f) (y + ↑1 * (y - x) ^ 2) - ↑f x) / (y - x)) (𝓝[Iio x] x) (𝓝 (ENNReal.toReal (rnDeriv (StieltjesFunction.measure f) volume x))) ⊢ HasDerivAt (↑f) (ENNReal.toReal (rnDeriv (StieltjesFunction.measure f) volume x)) x [PROOFSTEP] have L4 : Tendsto (fun y => (f y - f x) / (y - x)) (𝓝[<] x) (𝓝 (rnDeriv f.measure volume x).toReal) := by apply tendsto_of_tendsto_of_tendsto_of_le_of_le' L3 L2 · filter_upwards [self_mem_nhdsWithin] rintro y (hy : y < x) refine' div_le_div_of_nonpos_of_le (by linarith) ((sub_le_sub_iff_right _).2 _) apply f.mono.le_leftLim have : ↑0 < (x - y) ^ 2 := sq_pos_of_pos (sub_pos.2 hy) norm_num; linarith · filter_upwards [self_mem_nhdsWithin] rintro y (hy : y < x) refine' div_le_div_of_nonpos_of_le (by linarith) _ simpa only [sub_le_sub_iff_right] using f.mono.leftLim_le (le_refl y) -- prove the result by splitting into left and right limits. [GOAL] f : StieltjesFunction x : ℝ hx : Tendsto (fun a => ↑↑(StieltjesFunction.measure f) a / ↑↑volume a) (VitaliFamily.filterAt (vitaliFamily volume 1) x) (𝓝 (rnDeriv (StieltjesFunction.measure f) volume x)) h'x : rnDeriv (StieltjesFunction.measure f) volume x < ⊤ h''x : ¬leftLim (↑f) x ≠ ↑f x L1 : Tendsto (fun y => (↑f y - ↑f x) / (y - x)) (𝓝[Ioi x] x) (𝓝 (ENNReal.toReal (rnDeriv (StieltjesFunction.measure f) volume x))) L2 : Tendsto (fun y => (leftLim (↑f) y - ↑f x) / (y - x)) (𝓝[Iio x] x) (𝓝 (ENNReal.toReal (rnDeriv (StieltjesFunction.measure f) volume x))) L3 : Tendsto (fun y => (leftLim (↑f) (y + ↑1 * (y - x) ^ 2) - ↑f x) / (y - x)) (𝓝[Iio x] x) (𝓝 (ENNReal.toReal (rnDeriv (StieltjesFunction.measure f) volume x))) ⊢ Tendsto (fun y => (↑f y - ↑f x) / (y - x)) (𝓝[Iio x] x) (𝓝 (ENNReal.toReal (rnDeriv (StieltjesFunction.measure f) volume x))) [PROOFSTEP] apply tendsto_of_tendsto_of_tendsto_of_le_of_le' L3 L2 [GOAL] case hgf f : StieltjesFunction x : ℝ hx : Tendsto (fun a => ↑↑(StieltjesFunction.measure f) a / ↑↑volume a) (VitaliFamily.filterAt (vitaliFamily volume 1) x) (𝓝 (rnDeriv (StieltjesFunction.measure f) volume x)) h'x : rnDeriv (StieltjesFunction.measure f) volume x < ⊤ h''x : ¬leftLim (↑f) x ≠ ↑f x L1 : Tendsto (fun y => (↑f y - ↑f x) / (y - x)) (𝓝[Ioi x] x) (𝓝 (ENNReal.toReal (rnDeriv (StieltjesFunction.measure f) volume x))) L2 : Tendsto (fun y => (leftLim (↑f) y - ↑f x) / (y - x)) (𝓝[Iio x] x) (𝓝 (ENNReal.toReal (rnDeriv (StieltjesFunction.measure f) volume x))) L3 : Tendsto (fun y => (leftLim (↑f) (y + ↑1 * (y - x) ^ 2) - ↑f x) / (y - x)) (𝓝[Iio x] x) (𝓝 (ENNReal.toReal (rnDeriv (StieltjesFunction.measure f) volume x))) ⊢ ∀ᶠ (b : ℝ) in 𝓝[Iio x] x, (leftLim (↑f) (b + ↑1 * (b - x) ^ 2) - ↑f x) / (b - x) ≤ (↑f b - ↑f x) / (b - x) [PROOFSTEP] filter_upwards [self_mem_nhdsWithin] [GOAL] case h f : StieltjesFunction x : ℝ hx : Tendsto (fun a => ↑↑(StieltjesFunction.measure f) a / ↑↑volume a) (VitaliFamily.filterAt (vitaliFamily volume 1) x) (𝓝 (rnDeriv (StieltjesFunction.measure f) volume x)) h'x : rnDeriv (StieltjesFunction.measure f) volume x < ⊤ h''x : ¬leftLim (↑f) x ≠ ↑f x L1 : Tendsto (fun y => (↑f y - ↑f x) / (y - x)) (𝓝[Ioi x] x) (𝓝 (ENNReal.toReal (rnDeriv (StieltjesFunction.measure f) volume x))) L2 : Tendsto (fun y => (leftLim (↑f) y - ↑f x) / (y - x)) (𝓝[Iio x] x) (𝓝 (ENNReal.toReal (rnDeriv (StieltjesFunction.measure f) volume x))) L3 : Tendsto (fun y => (leftLim (↑f) (y + ↑1 * (y - x) ^ 2) - ↑f x) / (y - x)) (𝓝[Iio x] x) (𝓝 (ENNReal.toReal (rnDeriv (StieltjesFunction.measure f) volume x))) ⊢ ∀ (a : ℝ), a ∈ Iio x → (leftLim (↑f) (a + ↑1 * (a - x) ^ 2) - ↑f x) / (a - x) ≤ (↑f a - ↑f x) / (a - x) [PROOFSTEP] rintro y (hy : y < x) [GOAL] case h f : StieltjesFunction x : ℝ hx : Tendsto (fun a => ↑↑(StieltjesFunction.measure f) a / ↑↑volume a) (VitaliFamily.filterAt (vitaliFamily volume 1) x) (𝓝 (rnDeriv (StieltjesFunction.measure f) volume x)) h'x : rnDeriv (StieltjesFunction.measure f) volume x < ⊤ h''x : ¬leftLim (↑f) x ≠ ↑f x L1 : Tendsto (fun y => (↑f y - ↑f x) / (y - x)) (𝓝[Ioi x] x) (𝓝 (ENNReal.toReal (rnDeriv (StieltjesFunction.measure f) volume x))) L2 : Tendsto (fun y => (leftLim (↑f) y - ↑f x) / (y - x)) (𝓝[Iio x] x) (𝓝 (ENNReal.toReal (rnDeriv (StieltjesFunction.measure f) volume x))) L3 : Tendsto (fun y => (leftLim (↑f) (y + ↑1 * (y - x) ^ 2) - ↑f x) / (y - x)) (𝓝[Iio x] x) (𝓝 (ENNReal.toReal (rnDeriv (StieltjesFunction.measure f) volume x))) y : ℝ hy : y < x ⊢ (leftLim (↑f) (y + ↑1 * (y - x) ^ 2) - ↑f x) / (y - x) ≤ (↑f y - ↑f x) / (y - x) [PROOFSTEP] refine' div_le_div_of_nonpos_of_le (by linarith) ((sub_le_sub_iff_right _).2 _) [GOAL] f : StieltjesFunction x : ℝ hx : Tendsto (fun a => ↑↑(StieltjesFunction.measure f) a / ↑↑volume a) (VitaliFamily.filterAt (vitaliFamily volume 1) x) (𝓝 (rnDeriv (StieltjesFunction.measure f) volume x)) h'x : rnDeriv (StieltjesFunction.measure f) volume x < ⊤ h''x : ¬leftLim (↑f) x ≠ ↑f x L1 : Tendsto (fun y => (↑f y - ↑f x) / (y - x)) (𝓝[Ioi x] x) (𝓝 (ENNReal.toReal (rnDeriv (StieltjesFunction.measure f) volume x))) L2 : Tendsto (fun y => (leftLim (↑f) y - ↑f x) / (y - x)) (𝓝[Iio x] x) (𝓝 (ENNReal.toReal (rnDeriv (StieltjesFunction.measure f) volume x))) L3 : Tendsto (fun y => (leftLim (↑f) (y + ↑1 * (y - x) ^ 2) - ↑f x) / (y - x)) (𝓝[Iio x] x) (𝓝 (ENNReal.toReal (rnDeriv (StieltjesFunction.measure f) volume x))) y : ℝ hy : y < x ⊢ y - x ≤ 0 [PROOFSTEP] linarith [GOAL] case h f : StieltjesFunction x : ℝ hx : Tendsto (fun a => ↑↑(StieltjesFunction.measure f) a / ↑↑volume a) (VitaliFamily.filterAt (vitaliFamily volume 1) x) (𝓝 (rnDeriv (StieltjesFunction.measure f) volume x)) h'x : rnDeriv (StieltjesFunction.measure f) volume x < ⊤ h''x : ¬leftLim (↑f) x ≠ ↑f x L1 : Tendsto (fun y => (↑f y - ↑f x) / (y - x)) (𝓝[Ioi x] x) (𝓝 (ENNReal.toReal (rnDeriv (StieltjesFunction.measure f) volume x))) L2 : Tendsto (fun y => (leftLim (↑f) y - ↑f x) / (y - x)) (𝓝[Iio x] x) (𝓝 (ENNReal.toReal (rnDeriv (StieltjesFunction.measure f) volume x))) L3 : Tendsto (fun y => (leftLim (↑f) (y + ↑1 * (y - x) ^ 2) - ↑f x) / (y - x)) (𝓝[Iio x] x) (𝓝 (ENNReal.toReal (rnDeriv (StieltjesFunction.measure f) volume x))) y : ℝ hy : y < x ⊢ ↑f y ≤ leftLim (↑f) (y + ↑1 * (y - x) ^ 2) [PROOFSTEP] apply f.mono.le_leftLim [GOAL] case h f : StieltjesFunction x : ℝ hx : Tendsto (fun a => ↑↑(StieltjesFunction.measure f) a / ↑↑volume a) (VitaliFamily.filterAt (vitaliFamily volume 1) x) (𝓝 (rnDeriv (StieltjesFunction.measure f) volume x)) h'x : rnDeriv (StieltjesFunction.measure f) volume x < ⊤ h''x : ¬leftLim (↑f) x ≠ ↑f x L1 : Tendsto (fun y => (↑f y - ↑f x) / (y - x)) (𝓝[Ioi x] x) (𝓝 (ENNReal.toReal (rnDeriv (StieltjesFunction.measure f) volume x))) L2 : Tendsto (fun y => (leftLim (↑f) y - ↑f x) / (y - x)) (𝓝[Iio x] x) (𝓝 (ENNReal.toReal (rnDeriv (StieltjesFunction.measure f) volume x))) L3 : Tendsto (fun y => (leftLim (↑f) (y + ↑1 * (y - x) ^ 2) - ↑f x) / (y - x)) (𝓝[Iio x] x) (𝓝 (ENNReal.toReal (rnDeriv (StieltjesFunction.measure f) volume x))) y : ℝ hy : y < x ⊢ y < y + ↑1 * (y - x) ^ 2 [PROOFSTEP] have : ↑0 < (x - y) ^ 2 := sq_pos_of_pos (sub_pos.2 hy) [GOAL] case h f : StieltjesFunction x : ℝ hx : Tendsto (fun a => ↑↑(StieltjesFunction.measure f) a / ↑↑volume a) (VitaliFamily.filterAt (vitaliFamily volume 1) x) (𝓝 (rnDeriv (StieltjesFunction.measure f) volume x)) h'x : rnDeriv (StieltjesFunction.measure f) volume x < ⊤ h''x : ¬leftLim (↑f) x ≠ ↑f x L1 : Tendsto (fun y => (↑f y - ↑f x) / (y - x)) (𝓝[Ioi x] x) (𝓝 (ENNReal.toReal (rnDeriv (StieltjesFunction.measure f) volume x))) L2 : Tendsto (fun y => (leftLim (↑f) y - ↑f x) / (y - x)) (𝓝[Iio x] x) (𝓝 (ENNReal.toReal (rnDeriv (StieltjesFunction.measure f) volume x))) L3 : Tendsto (fun y => (leftLim (↑f) (y + ↑1 * (y - x) ^ 2) - ↑f x) / (y - x)) (𝓝[Iio x] x) (𝓝 (ENNReal.toReal (rnDeriv (StieltjesFunction.measure f) volume x))) y : ℝ hy : y < x this : 0 < (x - y) ^ 2 ⊢ y < y + ↑1 * (y - x) ^ 2 [PROOFSTEP] norm_num [GOAL] case h f : StieltjesFunction x : ℝ hx : Tendsto (fun a => ↑↑(StieltjesFunction.measure f) a / ↑↑volume a) (VitaliFamily.filterAt (vitaliFamily volume 1) x) (𝓝 (rnDeriv (StieltjesFunction.measure f) volume x)) h'x : rnDeriv (StieltjesFunction.measure f) volume x < ⊤ h''x : ¬leftLim (↑f) x ≠ ↑f x L1 : Tendsto (fun y => (↑f y - ↑f x) / (y - x)) (𝓝[Ioi x] x) (𝓝 (ENNReal.toReal (rnDeriv (StieltjesFunction.measure f) volume x))) L2 : Tendsto (fun y => (leftLim (↑f) y - ↑f x) / (y - x)) (𝓝[Iio x] x) (𝓝 (ENNReal.toReal (rnDeriv (StieltjesFunction.measure f) volume x))) L3 : Tendsto (fun y => (leftLim (↑f) (y + ↑1 * (y - x) ^ 2) - ↑f x) / (y - x)) (𝓝[Iio x] x) (𝓝 (ENNReal.toReal (rnDeriv (StieltjesFunction.measure f) volume x))) y : ℝ hy : y < x this : 0 < (x - y) ^ 2 ⊢ 0 < (y - x) ^ 2 [PROOFSTEP] linarith [GOAL] case hfh f : StieltjesFunction x : ℝ hx : Tendsto (fun a => ↑↑(StieltjesFunction.measure f) a / ↑↑volume a) (VitaliFamily.filterAt (vitaliFamily volume 1) x) (𝓝 (rnDeriv (StieltjesFunction.measure f) volume x)) h'x : rnDeriv (StieltjesFunction.measure f) volume x < ⊤ h''x : ¬leftLim (↑f) x ≠ ↑f x L1 : Tendsto (fun y => (↑f y - ↑f x) / (y - x)) (𝓝[Ioi x] x) (𝓝 (ENNReal.toReal (rnDeriv (StieltjesFunction.measure f) volume x))) L2 : Tendsto (fun y => (leftLim (↑f) y - ↑f x) / (y - x)) (𝓝[Iio x] x) (𝓝 (ENNReal.toReal (rnDeriv (StieltjesFunction.measure f) volume x))) L3 : Tendsto (fun y => (leftLim (↑f) (y + ↑1 * (y - x) ^ 2) - ↑f x) / (y - x)) (𝓝[Iio x] x) (𝓝 (ENNReal.toReal (rnDeriv (StieltjesFunction.measure f) volume x))) ⊢ ∀ᶠ (b : ℝ) in 𝓝[Iio x] x, (↑f b - ↑f x) / (b - x) ≤ (leftLim (↑f) b - ↑f x) / (b - x) [PROOFSTEP] filter_upwards [self_mem_nhdsWithin] [GOAL] case h f : StieltjesFunction x : ℝ hx : Tendsto (fun a => ↑↑(StieltjesFunction.measure f) a / ↑↑volume a) (VitaliFamily.filterAt (vitaliFamily volume 1) x) (𝓝 (rnDeriv (StieltjesFunction.measure f) volume x)) h'x : rnDeriv (StieltjesFunction.measure f) volume x < ⊤ h''x : ¬leftLim (↑f) x ≠ ↑f x L1 : Tendsto (fun y => (↑f y - ↑f x) / (y - x)) (𝓝[Ioi x] x) (𝓝 (ENNReal.toReal (rnDeriv (StieltjesFunction.measure f) volume x))) L2 : Tendsto (fun y => (leftLim (↑f) y - ↑f x) / (y - x)) (𝓝[Iio x] x) (𝓝 (ENNReal.toReal (rnDeriv (StieltjesFunction.measure f) volume x))) L3 : Tendsto (fun y => (leftLim (↑f) (y + ↑1 * (y - x) ^ 2) - ↑f x) / (y - x)) (𝓝[Iio x] x) (𝓝 (ENNReal.toReal (rnDeriv (StieltjesFunction.measure f) volume x))) ⊢ ∀ (a : ℝ), a ∈ Iio x → (↑f a - ↑f x) / (a - x) ≤ (leftLim (↑f) a - ↑f x) / (a - x) [PROOFSTEP] rintro y (hy : y < x) [GOAL] case h f : StieltjesFunction x : ℝ hx : Tendsto (fun a => ↑↑(StieltjesFunction.measure f) a / ↑↑volume a) (VitaliFamily.filterAt (vitaliFamily volume 1) x) (𝓝 (rnDeriv (StieltjesFunction.measure f) volume x)) h'x : rnDeriv (StieltjesFunction.measure f) volume x < ⊤ h''x : ¬leftLim (↑f) x ≠ ↑f x L1 : Tendsto (fun y => (↑f y - ↑f x) / (y - x)) (𝓝[Ioi x] x) (𝓝 (ENNReal.toReal (rnDeriv (StieltjesFunction.measure f) volume x))) L2 : Tendsto (fun y => (leftLim (↑f) y - ↑f x) / (y - x)) (𝓝[Iio x] x) (𝓝 (ENNReal.toReal (rnDeriv (StieltjesFunction.measure f) volume x))) L3 : Tendsto (fun y => (leftLim (↑f) (y + ↑1 * (y - x) ^ 2) - ↑f x) / (y - x)) (𝓝[Iio x] x) (𝓝 (ENNReal.toReal (rnDeriv (StieltjesFunction.measure f) volume x))) y : ℝ hy : y < x ⊢ (↑f y - ↑f x) / (y - x) ≤ (leftLim (↑f) y - ↑f x) / (y - x) [PROOFSTEP] refine' div_le_div_of_nonpos_of_le (by linarith) _ [GOAL] f : StieltjesFunction x : ℝ hx : Tendsto (fun a => ↑↑(StieltjesFunction.measure f) a / ↑↑volume a) (VitaliFamily.filterAt (vitaliFamily volume 1) x) (𝓝 (rnDeriv (StieltjesFunction.measure f) volume x)) h'x : rnDeriv (StieltjesFunction.measure f) volume x < ⊤ h''x : ¬leftLim (↑f) x ≠ ↑f x L1 : Tendsto (fun y => (↑f y - ↑f x) / (y - x)) (𝓝[Ioi x] x) (𝓝 (ENNReal.toReal (rnDeriv (StieltjesFunction.measure f) volume x))) L2 : Tendsto (fun y => (leftLim (↑f) y - ↑f x) / (y - x)) (𝓝[Iio x] x) (𝓝 (ENNReal.toReal (rnDeriv (StieltjesFunction.measure f) volume x))) L3 : Tendsto (fun y => (leftLim (↑f) (y + ↑1 * (y - x) ^ 2) - ↑f x) / (y - x)) (𝓝[Iio x] x) (𝓝 (ENNReal.toReal (rnDeriv (StieltjesFunction.measure f) volume x))) y : ℝ hy : y < x ⊢ y - x ≤ 0 [PROOFSTEP] linarith [GOAL] case h f : StieltjesFunction x : ℝ hx : Tendsto (fun a => ↑↑(StieltjesFunction.measure f) a / ↑↑volume a) (VitaliFamily.filterAt (vitaliFamily volume 1) x) (𝓝 (rnDeriv (StieltjesFunction.measure f) volume x)) h'x : rnDeriv (StieltjesFunction.measure f) volume x < ⊤ h''x : ¬leftLim (↑f) x ≠ ↑f x L1 : Tendsto (fun y => (↑f y - ↑f x) / (y - x)) (𝓝[Ioi x] x) (𝓝 (ENNReal.toReal (rnDeriv (StieltjesFunction.measure f) volume x))) L2 : Tendsto (fun y => (leftLim (↑f) y - ↑f x) / (y - x)) (𝓝[Iio x] x) (𝓝 (ENNReal.toReal (rnDeriv (StieltjesFunction.measure f) volume x))) L3 : Tendsto (fun y => (leftLim (↑f) (y + ↑1 * (y - x) ^ 2) - ↑f x) / (y - x)) (𝓝[Iio x] x) (𝓝 (ENNReal.toReal (rnDeriv (StieltjesFunction.measure f) volume x))) y : ℝ hy : y < x ⊢ leftLim (↑f) y - ↑f x ≤ ↑f y - ↑f x [PROOFSTEP] simpa only [sub_le_sub_iff_right] using f.mono.leftLim_le (le_refl y) -- prove the result by splitting into left and right limits. [GOAL] case h f : StieltjesFunction x : ℝ hx : Tendsto (fun a => ↑↑(StieltjesFunction.measure f) a / ↑↑volume a) (VitaliFamily.filterAt (vitaliFamily volume 1) x) (𝓝 (rnDeriv (StieltjesFunction.measure f) volume x)) h'x : rnDeriv (StieltjesFunction.measure f) volume x < ⊤ h''x : ¬leftLim (↑f) x ≠ ↑f x L1 : Tendsto (fun y => (↑f y - ↑f x) / (y - x)) (𝓝[Ioi x] x) (𝓝 (ENNReal.toReal (rnDeriv (StieltjesFunction.measure f) volume x))) L2 : Tendsto (fun y => (leftLim (↑f) y - ↑f x) / (y - x)) (𝓝[Iio x] x) (𝓝 (ENNReal.toReal (rnDeriv (StieltjesFunction.measure f) volume x))) L3 : Tendsto (fun y => (leftLim (↑f) (y + ↑1 * (y - x) ^ 2) - ↑f x) / (y - x)) (𝓝[Iio x] x) (𝓝 (ENNReal.toReal (rnDeriv (StieltjesFunction.measure f) volume x))) L4 : Tendsto (fun y => (↑f y - ↑f x) / (y - x)) (𝓝[Iio x] x) (𝓝 (ENNReal.toReal (rnDeriv (StieltjesFunction.measure f) volume x))) ⊢ HasDerivAt (↑f) (ENNReal.toReal (rnDeriv (StieltjesFunction.measure f) volume x)) x [PROOFSTEP] rw [hasDerivAt_iff_tendsto_slope, slope_fun_def_field, ← nhds_left'_sup_nhds_right', tendsto_sup] [GOAL] case h f : StieltjesFunction x : ℝ hx : Tendsto (fun a => ↑↑(StieltjesFunction.measure f) a / ↑↑volume a) (VitaliFamily.filterAt (vitaliFamily volume 1) x) (𝓝 (rnDeriv (StieltjesFunction.measure f) volume x)) h'x : rnDeriv (StieltjesFunction.measure f) volume x < ⊤ h''x : ¬leftLim (↑f) x ≠ ↑f x L1 : Tendsto (fun y => (↑f y - ↑f x) / (y - x)) (𝓝[Ioi x] x) (𝓝 (ENNReal.toReal (rnDeriv (StieltjesFunction.measure f) volume x))) L2 : Tendsto (fun y => (leftLim (↑f) y - ↑f x) / (y - x)) (𝓝[Iio x] x) (𝓝 (ENNReal.toReal (rnDeriv (StieltjesFunction.measure f) volume x))) L3 : Tendsto (fun y => (leftLim (↑f) (y + ↑1 * (y - x) ^ 2) - ↑f x) / (y - x)) (𝓝[Iio x] x) (𝓝 (ENNReal.toReal (rnDeriv (StieltjesFunction.measure f) volume x))) L4 : Tendsto (fun y => (↑f y - ↑f x) / (y - x)) (𝓝[Iio x] x) (𝓝 (ENNReal.toReal (rnDeriv (StieltjesFunction.measure f) volume x))) ⊢ Tendsto (fun b => (↑f b - ↑f x) / (b - x)) (𝓝[Iio x] x) (𝓝 (ENNReal.toReal (rnDeriv (StieltjesFunction.measure f) volume x))) ∧ Tendsto (fun b => (↑f b - ↑f x) / (b - x)) (𝓝[Ioi x] x) (𝓝 (ENNReal.toReal (rnDeriv (StieltjesFunction.measure f) volume x))) [PROOFSTEP] exact ⟨L4, L1⟩ [GOAL] f : ℝ → ℝ hf : Monotone f ⊢ ∀ᵐ (x : ℝ), HasDerivAt f (ENNReal.toReal (rnDeriv (StieltjesFunction.measure (stieltjesFunction hf)) volume x)) x [PROOFSTEP] filter_upwards [hf.stieltjesFunction.ae_hasDerivAt, hf.countable_not_continuousAt.ae_not_mem volume] with x hx h'x [GOAL] case h f : ℝ → ℝ hf : Monotone f x : ℝ hx : HasDerivAt (↑(stieltjesFunction hf)) (ENNReal.toReal (rnDeriv (StieltjesFunction.measure (stieltjesFunction hf)) volume x)) x h'x : ¬¬ContinuousAt f x ⊢ HasDerivAt f (ENNReal.toReal (rnDeriv (StieltjesFunction.measure (stieltjesFunction hf)) volume x)) x [PROOFSTEP] have A : hf.stieltjesFunction x = f x := by rw [Classical.not_not, hf.continuousAt_iff_leftLim_eq_rightLim] at h'x apply le_antisymm _ (hf.le_rightLim (le_refl _)) rw [← h'x] exact hf.leftLim_le (le_refl _) [GOAL] f : ℝ → ℝ hf : Monotone f x : ℝ hx : HasDerivAt (↑(stieltjesFunction hf)) (ENNReal.toReal (rnDeriv (StieltjesFunction.measure (stieltjesFunction hf)) volume x)) x h'x : ¬¬ContinuousAt f x ⊢ ↑(stieltjesFunction hf) x = f x [PROOFSTEP] rw [Classical.not_not, hf.continuousAt_iff_leftLim_eq_rightLim] at h'x [GOAL] f : ℝ → ℝ hf : Monotone f x : ℝ hx : HasDerivAt (↑(stieltjesFunction hf)) (ENNReal.toReal (rnDeriv (StieltjesFunction.measure (stieltjesFunction hf)) volume x)) x h'x : leftLim f x = rightLim f x ⊢ ↑(stieltjesFunction hf) x = f x [PROOFSTEP] apply le_antisymm _ (hf.le_rightLim (le_refl _)) [GOAL] f : ℝ → ℝ hf : Monotone f x : ℝ hx : HasDerivAt (↑(stieltjesFunction hf)) (ENNReal.toReal (rnDeriv (StieltjesFunction.measure (stieltjesFunction hf)) volume x)) x h'x : leftLim f x = rightLim f x ⊢ rightLim f x ≤ f x [PROOFSTEP] rw [← h'x] [GOAL] f : ℝ → ℝ hf : Monotone f x : ℝ hx : HasDerivAt (↑(stieltjesFunction hf)) (ENNReal.toReal (rnDeriv (StieltjesFunction.measure (stieltjesFunction hf)) volume x)) x h'x : leftLim f x = rightLim f x ⊢ leftLim f x ≤ f x [PROOFSTEP] exact hf.leftLim_le (le_refl _) [GOAL] case h f : ℝ → ℝ hf : Monotone f x : ℝ hx : HasDerivAt (↑(stieltjesFunction hf)) (ENNReal.toReal (rnDeriv (StieltjesFunction.measure (stieltjesFunction hf)) volume x)) x h'x : ¬¬ContinuousAt f x A : ↑(stieltjesFunction hf) x = f x ⊢ HasDerivAt f (ENNReal.toReal (rnDeriv (StieltjesFunction.measure (stieltjesFunction hf)) volume x)) x [PROOFSTEP] rw [hasDerivAt_iff_tendsto_slope, (nhds_left'_sup_nhds_right' x).symm, tendsto_sup, slope_fun_def_field, A] at hx [GOAL] case h f : ℝ → ℝ hf : Monotone f x : ℝ hx : Tendsto (fun b => (↑(stieltjesFunction hf) b - f x) / (b - x)) (𝓝[Iio x] x) (𝓝 (ENNReal.toReal (rnDeriv (StieltjesFunction.measure (stieltjesFunction hf)) volume x))) ∧ Tendsto (fun b => (↑(stieltjesFunction hf) b - f x) / (b - x)) (𝓝[Ioi x] x) (𝓝 (ENNReal.toReal (rnDeriv (StieltjesFunction.measure (stieltjesFunction hf)) volume x))) h'x : ¬¬ContinuousAt f x A : ↑(stieltjesFunction hf) x = f x ⊢ HasDerivAt f (ENNReal.toReal (rnDeriv (StieltjesFunction.measure (stieltjesFunction hf)) volume x)) x [PROOFSTEP] have L1 : Tendsto (fun y => (f y - f x) / (y - x)) (𝓝[>] x) (𝓝 (rnDeriv hf.stieltjesFunction.measure volume x).toReal) := by -- limit of a helper function, with a small shift compared to `g` have : Tendsto (fun y => (hf.stieltjesFunction (y + -1 * (y - x) ^ 2) - f x) / (y - x)) (𝓝[>] x) (𝓝 (rnDeriv hf.stieltjesFunction.measure volume x).toReal) := by apply tendsto_apply_add_mul_sq_div_sub (nhds_right'_le_nhds_ne x) hx.2 apply tendsto_nhdsWithin_of_tendsto_nhds_of_eventually_within · apply Tendsto.mono_left _ nhdsWithin_le_nhds have : Tendsto (fun y : ℝ => y + -↑1 * (y - x) ^ 2) (𝓝 x) (𝓝 (x + -↑1 * (x - x) ^ 2)) := tendsto_id.add (((tendsto_id.sub_const x).pow 2).const_mul (-1)) simpa using this · have : Ioo x (x + 1) ∈ 𝓝[>] x := by apply Ioo_mem_nhdsWithin_Ioi; exact ⟨le_refl _, by linarith⟩ filter_upwards [this] rintro y ⟨hy : x < y, h'y : y < x + 1⟩ rw [mem_Ioi] norm_num; nlinarith -- apply the sandwiching argument, with the helper function and `g` apply tendsto_of_tendsto_of_tendsto_of_le_of_le' this hx.2 · filter_upwards [self_mem_nhdsWithin] rintro y (hy : x < y) have : ↑0 < (y - x) ^ 2 := sq_pos_of_pos (sub_pos.2 hy) apply div_le_div_of_le_of_nonneg _ (sub_pos.2 hy).le exact (sub_le_sub_iff_right _).2 (hf.rightLim_le (by norm_num; linarith)) · filter_upwards [self_mem_nhdsWithin] rintro y (hy : x < y) apply div_le_div_of_le_of_nonneg _ (sub_pos.2 hy).le exact (sub_le_sub_iff_right _).2 (hf.le_rightLim (le_refl y)) -- prove differentiability on the left, by sandwiching with values of `g` [GOAL] f : ℝ → ℝ hf : Monotone f x : ℝ hx : Tendsto (fun b => (↑(stieltjesFunction hf) b - f x) / (b - x)) (𝓝[Iio x] x) (𝓝 (ENNReal.toReal (rnDeriv (StieltjesFunction.measure (stieltjesFunction hf)) volume x))) ∧ Tendsto (fun b => (↑(stieltjesFunction hf) b - f x) / (b - x)) (𝓝[Ioi x] x) (𝓝 (ENNReal.toReal (rnDeriv (StieltjesFunction.measure (stieltjesFunction hf)) volume x))) h'x : ¬¬ContinuousAt f x A : ↑(stieltjesFunction hf) x = f x ⊢ Tendsto (fun y => (f y - f x) / (y - x)) (𝓝[Ioi x] x) (𝓝 (ENNReal.toReal (rnDeriv (StieltjesFunction.measure (stieltjesFunction hf)) volume x))) [PROOFSTEP] have : Tendsto (fun y => (hf.stieltjesFunction (y + -1 * (y - x) ^ 2) - f x) / (y - x)) (𝓝[>] x) (𝓝 (rnDeriv hf.stieltjesFunction.measure volume x).toReal) := by apply tendsto_apply_add_mul_sq_div_sub (nhds_right'_le_nhds_ne x) hx.2 apply tendsto_nhdsWithin_of_tendsto_nhds_of_eventually_within · apply Tendsto.mono_left _ nhdsWithin_le_nhds have : Tendsto (fun y : ℝ => y + -↑1 * (y - x) ^ 2) (𝓝 x) (𝓝 (x + -↑1 * (x - x) ^ 2)) := tendsto_id.add (((tendsto_id.sub_const x).pow 2).const_mul (-1)) simpa using this · have : Ioo x (x + 1) ∈ 𝓝[>] x := by apply Ioo_mem_nhdsWithin_Ioi; exact ⟨le_refl _, by linarith⟩ filter_upwards [this] rintro y ⟨hy : x < y, h'y : y < x + 1⟩ rw [mem_Ioi] norm_num; nlinarith -- apply the sandwiching argument, with the helper function and `g` [GOAL] f : ℝ → ℝ hf : Monotone f x : ℝ hx : Tendsto (fun b => (↑(stieltjesFunction hf) b - f x) / (b - x)) (𝓝[Iio x] x) (𝓝 (ENNReal.toReal (rnDeriv (StieltjesFunction.measure (stieltjesFunction hf)) volume x))) ∧ Tendsto (fun b => (↑(stieltjesFunction hf) b - f x) / (b - x)) (𝓝[Ioi x] x) (𝓝 (ENNReal.toReal (rnDeriv (StieltjesFunction.measure (stieltjesFunction hf)) volume x))) h'x : ¬¬ContinuousAt f x A : ↑(stieltjesFunction hf) x = f x ⊢ Tendsto (fun y => (↑(stieltjesFunction hf) (y + -↑1 * (y - x) ^ 2) - f x) / (y - x)) (𝓝[Ioi x] x) (𝓝 (ENNReal.toReal (rnDeriv (StieltjesFunction.measure (stieltjesFunction hf)) volume x))) [PROOFSTEP] apply tendsto_apply_add_mul_sq_div_sub (nhds_right'_le_nhds_ne x) hx.2 [GOAL] f : ℝ → ℝ hf : Monotone f x : ℝ hx : Tendsto (fun b => (↑(stieltjesFunction hf) b - f x) / (b - x)) (𝓝[Iio x] x) (𝓝 (ENNReal.toReal (rnDeriv (StieltjesFunction.measure (stieltjesFunction hf)) volume x))) ∧ Tendsto (fun b => (↑(stieltjesFunction hf) b - f x) / (b - x)) (𝓝[Ioi x] x) (𝓝 (ENNReal.toReal (rnDeriv (StieltjesFunction.measure (stieltjesFunction hf)) volume x))) h'x : ¬¬ContinuousAt f x A : ↑(stieltjesFunction hf) x = f x ⊢ Tendsto (fun y => y + -↑1 * (y - x) ^ 2) (𝓝[Ioi x] x) (𝓝[Ioi x] x) [PROOFSTEP] apply tendsto_nhdsWithin_of_tendsto_nhds_of_eventually_within [GOAL] case h1 f : ℝ → ℝ hf : Monotone f x : ℝ hx : Tendsto (fun b => (↑(stieltjesFunction hf) b - f x) / (b - x)) (𝓝[Iio x] x) (𝓝 (ENNReal.toReal (rnDeriv (StieltjesFunction.measure (stieltjesFunction hf)) volume x))) ∧ Tendsto (fun b => (↑(stieltjesFunction hf) b - f x) / (b - x)) (𝓝[Ioi x] x) (𝓝 (ENNReal.toReal (rnDeriv (StieltjesFunction.measure (stieltjesFunction hf)) volume x))) h'x : ¬¬ContinuousAt f x A : ↑(stieltjesFunction hf) x = f x ⊢ Tendsto (fun y => y + -↑1 * (y - x) ^ 2) (𝓝[Ioi x] x) (𝓝 x) [PROOFSTEP] apply Tendsto.mono_left _ nhdsWithin_le_nhds [GOAL] f : ℝ → ℝ hf : Monotone f x : ℝ hx : Tendsto (fun b => (↑(stieltjesFunction hf) b - f x) / (b - x)) (𝓝[Iio x] x) (𝓝 (ENNReal.toReal (rnDeriv (StieltjesFunction.measure (stieltjesFunction hf)) volume x))) ∧ Tendsto (fun b => (↑(stieltjesFunction hf) b - f x) / (b - x)) (𝓝[Ioi x] x) (𝓝 (ENNReal.toReal (rnDeriv (StieltjesFunction.measure (stieltjesFunction hf)) volume x))) h'x : ¬¬ContinuousAt f x A : ↑(stieltjesFunction hf) x = f x ⊢ Tendsto (fun y => y + -↑1 * (y - x) ^ 2) (𝓝 x) (𝓝 x) [PROOFSTEP] have : Tendsto (fun y : ℝ => y + -↑1 * (y - x) ^ 2) (𝓝 x) (𝓝 (x + -↑1 * (x - x) ^ 2)) := tendsto_id.add (((tendsto_id.sub_const x).pow 2).const_mul (-1)) [GOAL] f : ℝ → ℝ hf : Monotone f x : ℝ hx : Tendsto (fun b => (↑(stieltjesFunction hf) b - f x) / (b - x)) (𝓝[Iio x] x) (𝓝 (ENNReal.toReal (rnDeriv (StieltjesFunction.measure (stieltjesFunction hf)) volume x))) ∧ Tendsto (fun b => (↑(stieltjesFunction hf) b - f x) / (b - x)) (𝓝[Ioi x] x) (𝓝 (ENNReal.toReal (rnDeriv (StieltjesFunction.measure (stieltjesFunction hf)) volume x))) h'x : ¬¬ContinuousAt f x A : ↑(stieltjesFunction hf) x = f x this : Tendsto (fun y => y + -1 * (y - x) ^ 2) (𝓝 x) (𝓝 (x + -1 * (x - x) ^ 2)) ⊢ Tendsto (fun y => y + -↑1 * (y - x) ^ 2) (𝓝 x) (𝓝 x) [PROOFSTEP] simpa using this [GOAL] case h2 f : ℝ → ℝ hf : Monotone f x : ℝ hx : Tendsto (fun b => (↑(stieltjesFunction hf) b - f x) / (b - x)) (𝓝[Iio x] x) (𝓝 (ENNReal.toReal (rnDeriv (StieltjesFunction.measure (stieltjesFunction hf)) volume x))) ∧ Tendsto (fun b => (↑(stieltjesFunction hf) b - f x) / (b - x)) (𝓝[Ioi x] x) (𝓝 (ENNReal.toReal (rnDeriv (StieltjesFunction.measure (stieltjesFunction hf)) volume x))) h'x : ¬¬ContinuousAt f x A : ↑(stieltjesFunction hf) x = f x ⊢ ∀ᶠ (x_1 : ℝ) in 𝓝[Ioi x] x, x_1 + -↑1 * (x_1 - x) ^ 2 ∈ Ioi x [PROOFSTEP] have : Ioo x (x + 1) ∈ 𝓝[>] x := by apply Ioo_mem_nhdsWithin_Ioi; exact ⟨le_refl _, by linarith⟩ [GOAL] f : ℝ → ℝ hf : Monotone f x : ℝ hx : Tendsto (fun b => (↑(stieltjesFunction hf) b - f x) / (b - x)) (𝓝[Iio x] x) (𝓝 (ENNReal.toReal (rnDeriv (StieltjesFunction.measure (stieltjesFunction hf)) volume x))) ∧ Tendsto (fun b => (↑(stieltjesFunction hf) b - f x) / (b - x)) (𝓝[Ioi x] x) (𝓝 (ENNReal.toReal (rnDeriv (StieltjesFunction.measure (stieltjesFunction hf)) volume x))) h'x : ¬¬ContinuousAt f x A : ↑(stieltjesFunction hf) x = f x ⊢ Ioo x (x + 1) ∈ 𝓝[Ioi x] x [PROOFSTEP] apply Ioo_mem_nhdsWithin_Ioi [GOAL] case H f : ℝ → ℝ hf : Monotone f x : ℝ hx : Tendsto (fun b => (↑(stieltjesFunction hf) b - f x) / (b - x)) (𝓝[Iio x] x) (𝓝 (ENNReal.toReal (rnDeriv (StieltjesFunction.measure (stieltjesFunction hf)) volume x))) ∧ Tendsto (fun b => (↑(stieltjesFunction hf) b - f x) / (b - x)) (𝓝[Ioi x] x) (𝓝 (ENNReal.toReal (rnDeriv (StieltjesFunction.measure (stieltjesFunction hf)) volume x))) h'x : ¬¬ContinuousAt f x A : ↑(stieltjesFunction hf) x = f x ⊢ x ∈ Ico x (x + 1) [PROOFSTEP] exact ⟨le_refl _, by linarith⟩ [GOAL] f : ℝ → ℝ hf : Monotone f x : ℝ hx : Tendsto (fun b => (↑(stieltjesFunction hf) b - f x) / (b - x)) (𝓝[Iio x] x) (𝓝 (ENNReal.toReal (rnDeriv (StieltjesFunction.measure (stieltjesFunction hf)) volume x))) ∧ Tendsto (fun b => (↑(stieltjesFunction hf) b - f x) / (b - x)) (𝓝[Ioi x] x) (𝓝 (ENNReal.toReal (rnDeriv (StieltjesFunction.measure (stieltjesFunction hf)) volume x))) h'x : ¬¬ContinuousAt f x A : ↑(stieltjesFunction hf) x = f x ⊢ x < x + 1 [PROOFSTEP] linarith [GOAL] case h2 f : ℝ → ℝ hf : Monotone f x : ℝ hx : Tendsto (fun b => (↑(stieltjesFunction hf) b - f x) / (b - x)) (𝓝[Iio x] x) (𝓝 (ENNReal.toReal (rnDeriv (StieltjesFunction.measure (stieltjesFunction hf)) volume x))) ∧ Tendsto (fun b => (↑(stieltjesFunction hf) b - f x) / (b - x)) (𝓝[Ioi x] x) (𝓝 (ENNReal.toReal (rnDeriv (StieltjesFunction.measure (stieltjesFunction hf)) volume x))) h'x : ¬¬ContinuousAt f x A : ↑(stieltjesFunction hf) x = f x this : Ioo x (x + 1) ∈ 𝓝[Ioi x] x ⊢ ∀ᶠ (x_1 : ℝ) in 𝓝[Ioi x] x, x_1 + -↑1 * (x_1 - x) ^ 2 ∈ Ioi x [PROOFSTEP] filter_upwards [this] [GOAL] case h f : ℝ → ℝ hf : Monotone f x : ℝ hx : Tendsto (fun b => (↑(stieltjesFunction hf) b - f x) / (b - x)) (𝓝[Iio x] x) (𝓝 (ENNReal.toReal (rnDeriv (StieltjesFunction.measure (stieltjesFunction hf)) volume x))) ∧ Tendsto (fun b => (↑(stieltjesFunction hf) b - f x) / (b - x)) (𝓝[Ioi x] x) (𝓝 (ENNReal.toReal (rnDeriv (StieltjesFunction.measure (stieltjesFunction hf)) volume x))) h'x : ¬¬ContinuousAt f x A : ↑(stieltjesFunction hf) x = f x this : Ioo x (x + 1) ∈ 𝓝[Ioi x] x ⊢ ∀ (a : ℝ), a ∈ Ioo x (x + 1) → a + -↑1 * (a - x) ^ 2 ∈ Ioi x [PROOFSTEP] rintro y ⟨hy : x < y, h'y : y < x + 1⟩ [GOAL] case h.intro f : ℝ → ℝ hf : Monotone f x : ℝ hx : Tendsto (fun b => (↑(stieltjesFunction hf) b - f x) / (b - x)) (𝓝[Iio x] x) (𝓝 (ENNReal.toReal (rnDeriv (StieltjesFunction.measure (stieltjesFunction hf)) volume x))) ∧ Tendsto (fun b => (↑(stieltjesFunction hf) b - f x) / (b - x)) (𝓝[Ioi x] x) (𝓝 (ENNReal.toReal (rnDeriv (StieltjesFunction.measure (stieltjesFunction hf)) volume x))) h'x : ¬¬ContinuousAt f x A : ↑(stieltjesFunction hf) x = f x this : Ioo x (x + 1) ∈ 𝓝[Ioi x] x y : ℝ hy : x < y h'y : y < x + 1 ⊢ y + -↑1 * (y - x) ^ 2 ∈ Ioi x [PROOFSTEP] rw [mem_Ioi] [GOAL] case h.intro f : ℝ → ℝ hf : Monotone f x : ℝ hx : Tendsto (fun b => (↑(stieltjesFunction hf) b - f x) / (b - x)) (𝓝[Iio x] x) (𝓝 (ENNReal.toReal (rnDeriv (StieltjesFunction.measure (stieltjesFunction hf)) volume x))) ∧ Tendsto (fun b => (↑(stieltjesFunction hf) b - f x) / (b - x)) (𝓝[Ioi x] x) (𝓝 (ENNReal.toReal (rnDeriv (StieltjesFunction.measure (stieltjesFunction hf)) volume x))) h'x : ¬¬ContinuousAt f x A : ↑(stieltjesFunction hf) x = f x this : Ioo x (x + 1) ∈ 𝓝[Ioi x] x y : ℝ hy : x < y h'y : y < x + 1 ⊢ x < y + -↑1 * (y - x) ^ 2 [PROOFSTEP] norm_num [GOAL] case h.intro f : ℝ → ℝ hf : Monotone f x : ℝ hx : Tendsto (fun b => (↑(stieltjesFunction hf) b - f x) / (b - x)) (𝓝[Iio x] x) (𝓝 (ENNReal.toReal (rnDeriv (StieltjesFunction.measure (stieltjesFunction hf)) volume x))) ∧ Tendsto (fun b => (↑(stieltjesFunction hf) b - f x) / (b - x)) (𝓝[Ioi x] x) (𝓝 (ENNReal.toReal (rnDeriv (StieltjesFunction.measure (stieltjesFunction hf)) volume x))) h'x : ¬¬ContinuousAt f x A : ↑(stieltjesFunction hf) x = f x this : Ioo x (x + 1) ∈ 𝓝[Ioi x] x y : ℝ hy : x < y h'y : y < x + 1 ⊢ x + (y - x) ^ 2 < y [PROOFSTEP] nlinarith -- apply the sandwiching argument, with the helper function and `g` [GOAL] f : ℝ → ℝ hf : Monotone f x : ℝ hx : Tendsto (fun b => (↑(stieltjesFunction hf) b - f x) / (b - x)) (𝓝[Iio x] x) (𝓝 (ENNReal.toReal (rnDeriv (StieltjesFunction.measure (stieltjesFunction hf)) volume x))) ∧ Tendsto (fun b => (↑(stieltjesFunction hf) b - f x) / (b - x)) (𝓝[Ioi x] x) (𝓝 (ENNReal.toReal (rnDeriv (StieltjesFunction.measure (stieltjesFunction hf)) volume x))) h'x : ¬¬ContinuousAt f x A : ↑(stieltjesFunction hf) x = f x this : Tendsto (fun y => (↑(stieltjesFunction hf) (y + -↑1 * (y - x) ^ 2) - f x) / (y - x)) (𝓝[Ioi x] x) (𝓝 (ENNReal.toReal (rnDeriv (StieltjesFunction.measure (stieltjesFunction hf)) volume x))) ⊢ Tendsto (fun y => (f y - f x) / (y - x)) (𝓝[Ioi x] x) (𝓝 (ENNReal.toReal (rnDeriv (StieltjesFunction.measure (stieltjesFunction hf)) volume x))) [PROOFSTEP] apply tendsto_of_tendsto_of_tendsto_of_le_of_le' this hx.2 [GOAL] case hgf f : ℝ → ℝ hf : Monotone f x : ℝ hx : Tendsto (fun b => (↑(stieltjesFunction hf) b - f x) / (b - x)) (𝓝[Iio x] x) (𝓝 (ENNReal.toReal (rnDeriv (StieltjesFunction.measure (stieltjesFunction hf)) volume x))) ∧ Tendsto (fun b => (↑(stieltjesFunction hf) b - f x) / (b - x)) (𝓝[Ioi x] x) (𝓝 (ENNReal.toReal (rnDeriv (StieltjesFunction.measure (stieltjesFunction hf)) volume x))) h'x : ¬¬ContinuousAt f x A : ↑(stieltjesFunction hf) x = f x this : Tendsto (fun y => (↑(stieltjesFunction hf) (y + -↑1 * (y - x) ^ 2) - f x) / (y - x)) (𝓝[Ioi x] x) (𝓝 (ENNReal.toReal (rnDeriv (StieltjesFunction.measure (stieltjesFunction hf)) volume x))) ⊢ ∀ᶠ (b : ℝ) in 𝓝[Ioi x] x, (↑(stieltjesFunction hf) (b + -↑1 * (b - x) ^ 2) - f x) / (b - x) ≤ (f b - f x) / (b - x) [PROOFSTEP] filter_upwards [self_mem_nhdsWithin] [GOAL] case h f : ℝ → ℝ hf : Monotone f x : ℝ hx : Tendsto (fun b => (↑(stieltjesFunction hf) b - f x) / (b - x)) (𝓝[Iio x] x) (𝓝 (ENNReal.toReal (rnDeriv (StieltjesFunction.measure (stieltjesFunction hf)) volume x))) ∧ Tendsto (fun b => (↑(stieltjesFunction hf) b - f x) / (b - x)) (𝓝[Ioi x] x) (𝓝 (ENNReal.toReal (rnDeriv (StieltjesFunction.measure (stieltjesFunction hf)) volume x))) h'x : ¬¬ContinuousAt f x A : ↑(stieltjesFunction hf) x = f x this : Tendsto (fun y => (↑(stieltjesFunction hf) (y + -↑1 * (y - x) ^ 2) - f x) / (y - x)) (𝓝[Ioi x] x) (𝓝 (ENNReal.toReal (rnDeriv (StieltjesFunction.measure (stieltjesFunction hf)) volume x))) ⊢ ∀ (a : ℝ), a ∈ Ioi x → (↑(stieltjesFunction hf) (a + -↑1 * (a - x) ^ 2) - f x) / (a - x) ≤ (f a - f x) / (a - x) [PROOFSTEP] rintro y (hy : x < y) [GOAL] case h f : ℝ → ℝ hf : Monotone f x : ℝ hx : Tendsto (fun b => (↑(stieltjesFunction hf) b - f x) / (b - x)) (𝓝[Iio x] x) (𝓝 (ENNReal.toReal (rnDeriv (StieltjesFunction.measure (stieltjesFunction hf)) volume x))) ∧ Tendsto (fun b => (↑(stieltjesFunction hf) b - f x) / (b - x)) (𝓝[Ioi x] x) (𝓝 (ENNReal.toReal (rnDeriv (StieltjesFunction.measure (stieltjesFunction hf)) volume x))) h'x : ¬¬ContinuousAt f x A : ↑(stieltjesFunction hf) x = f x this : Tendsto (fun y => (↑(stieltjesFunction hf) (y + -↑1 * (y - x) ^ 2) - f x) / (y - x)) (𝓝[Ioi x] x) (𝓝 (ENNReal.toReal (rnDeriv (StieltjesFunction.measure (stieltjesFunction hf)) volume x))) y : ℝ hy : x < y ⊢ (↑(stieltjesFunction hf) (y + -↑1 * (y - x) ^ 2) - f x) / (y - x) ≤ (f y - f x) / (y - x) [PROOFSTEP] have : ↑0 < (y - x) ^ 2 := sq_pos_of_pos (sub_pos.2 hy) [GOAL] case h f : ℝ → ℝ hf : Monotone f x : ℝ hx : Tendsto (fun b => (↑(stieltjesFunction hf) b - f x) / (b - x)) (𝓝[Iio x] x) (𝓝 (ENNReal.toReal (rnDeriv (StieltjesFunction.measure (stieltjesFunction hf)) volume x))) ∧ Tendsto (fun b => (↑(stieltjesFunction hf) b - f x) / (b - x)) (𝓝[Ioi x] x) (𝓝 (ENNReal.toReal (rnDeriv (StieltjesFunction.measure (stieltjesFunction hf)) volume x))) h'x : ¬¬ContinuousAt f x A : ↑(stieltjesFunction hf) x = f x this✝ : Tendsto (fun y => (↑(stieltjesFunction hf) (y + -↑1 * (y - x) ^ 2) - f x) / (y - x)) (𝓝[Ioi x] x) (𝓝 (ENNReal.toReal (rnDeriv (StieltjesFunction.measure (stieltjesFunction hf)) volume x))) y : ℝ hy : x < y this : 0 < (y - x) ^ 2 ⊢ (↑(stieltjesFunction hf) (y + -↑1 * (y - x) ^ 2) - f x) / (y - x) ≤ (f y - f x) / (y - x) [PROOFSTEP] apply div_le_div_of_le_of_nonneg _ (sub_pos.2 hy).le [GOAL] f : ℝ → ℝ hf : Monotone f x : ℝ hx : Tendsto (fun b => (↑(stieltjesFunction hf) b - f x) / (b - x)) (𝓝[Iio x] x) (𝓝 (ENNReal.toReal (rnDeriv (StieltjesFunction.measure (stieltjesFunction hf)) volume x))) ∧ Tendsto (fun b => (↑(stieltjesFunction hf) b - f x) / (b - x)) (𝓝[Ioi x] x) (𝓝 (ENNReal.toReal (rnDeriv (StieltjesFunction.measure (stieltjesFunction hf)) volume x))) h'x : ¬¬ContinuousAt f x A : ↑(stieltjesFunction hf) x = f x this✝ : Tendsto (fun y => (↑(stieltjesFunction hf) (y + -↑1 * (y - x) ^ 2) - f x) / (y - x)) (𝓝[Ioi x] x) (𝓝 (ENNReal.toReal (rnDeriv (StieltjesFunction.measure (stieltjesFunction hf)) volume x))) y : ℝ hy : x < y this : 0 < (y - x) ^ 2 ⊢ ↑(stieltjesFunction hf) (y + -↑1 * (y - x) ^ 2) - f x ≤ f y - f x [PROOFSTEP] exact (sub_le_sub_iff_right _).2 (hf.rightLim_le (by norm_num; linarith)) [GOAL] f : ℝ → ℝ hf : Monotone f x : ℝ hx : Tendsto (fun b => (↑(stieltjesFunction hf) b - f x) / (b - x)) (𝓝[Iio x] x) (𝓝 (ENNReal.toReal (rnDeriv (StieltjesFunction.measure (stieltjesFunction hf)) volume x))) ∧ Tendsto (fun b => (↑(stieltjesFunction hf) b - f x) / (b - x)) (𝓝[Ioi x] x) (𝓝 (ENNReal.toReal (rnDeriv (StieltjesFunction.measure (stieltjesFunction hf)) volume x))) h'x : ¬¬ContinuousAt f x A : ↑(stieltjesFunction hf) x = f x this✝ : Tendsto (fun y => (↑(stieltjesFunction hf) (y + -↑1 * (y - x) ^ 2) - f x) / (y - x)) (𝓝[Ioi x] x) (𝓝 (ENNReal.toReal (rnDeriv (StieltjesFunction.measure (stieltjesFunction hf)) volume x))) y : ℝ hy : x < y this : 0 < (y - x) ^ 2 ⊢ y + -↑1 * (y - x) ^ 2 < y [PROOFSTEP] norm_num [GOAL] f : ℝ → ℝ hf : Monotone f x : ℝ hx : Tendsto (fun b => (↑(stieltjesFunction hf) b - f x) / (b - x)) (𝓝[Iio x] x) (𝓝 (ENNReal.toReal (rnDeriv (StieltjesFunction.measure (stieltjesFunction hf)) volume x))) ∧ Tendsto (fun b => (↑(stieltjesFunction hf) b - f x) / (b - x)) (𝓝[Ioi x] x) (𝓝 (ENNReal.toReal (rnDeriv (StieltjesFunction.measure (stieltjesFunction hf)) volume x))) h'x : ¬¬ContinuousAt f x A : ↑(stieltjesFunction hf) x = f x this✝ : Tendsto (fun y => (↑(stieltjesFunction hf) (y + -↑1 * (y - x) ^ 2) - f x) / (y - x)) (𝓝[Ioi x] x) (𝓝 (ENNReal.toReal (rnDeriv (StieltjesFunction.measure (stieltjesFunction hf)) volume x))) y : ℝ hy : x < y this : 0 < (y - x) ^ 2 ⊢ 0 < (y - x) ^ 2 [PROOFSTEP] linarith [GOAL] case hfh f : ℝ → ℝ hf : Monotone f x : ℝ hx : Tendsto (fun b => (↑(stieltjesFunction hf) b - f x) / (b - x)) (𝓝[Iio x] x) (𝓝 (ENNReal.toReal (rnDeriv (StieltjesFunction.measure (stieltjesFunction hf)) volume x))) ∧ Tendsto (fun b => (↑(stieltjesFunction hf) b - f x) / (b - x)) (𝓝[Ioi x] x) (𝓝 (ENNReal.toReal (rnDeriv (StieltjesFunction.measure (stieltjesFunction hf)) volume x))) h'x : ¬¬ContinuousAt f x A : ↑(stieltjesFunction hf) x = f x this : Tendsto (fun y => (↑(stieltjesFunction hf) (y + -↑1 * (y - x) ^ 2) - f x) / (y - x)) (𝓝[Ioi x] x) (𝓝 (ENNReal.toReal (rnDeriv (StieltjesFunction.measure (stieltjesFunction hf)) volume x))) ⊢ ∀ᶠ (b : ℝ) in 𝓝[Ioi x] x, (f b - f x) / (b - x) ≤ (↑(stieltjesFunction hf) b - f x) / (b - x) [PROOFSTEP] filter_upwards [self_mem_nhdsWithin] [GOAL] case h f : ℝ → ℝ hf : Monotone f x : ℝ hx : Tendsto (fun b => (↑(stieltjesFunction hf) b - f x) / (b - x)) (𝓝[Iio x] x) (𝓝 (ENNReal.toReal (rnDeriv (StieltjesFunction.measure (stieltjesFunction hf)) volume x))) ∧ Tendsto (fun b => (↑(stieltjesFunction hf) b - f x) / (b - x)) (𝓝[Ioi x] x) (𝓝 (ENNReal.toReal (rnDeriv (StieltjesFunction.measure (stieltjesFunction hf)) volume x))) h'x : ¬¬ContinuousAt f x A : ↑(stieltjesFunction hf) x = f x this : Tendsto (fun y => (↑(stieltjesFunction hf) (y + -↑1 * (y - x) ^ 2) - f x) / (y - x)) (𝓝[Ioi x] x) (𝓝 (ENNReal.toReal (rnDeriv (StieltjesFunction.measure (stieltjesFunction hf)) volume x))) ⊢ ∀ (a : ℝ), a ∈ Ioi x → (f a - f x) / (a - x) ≤ (↑(stieltjesFunction hf) a - f x) / (a - x) [PROOFSTEP] rintro y (hy : x < y) [GOAL] case h f : ℝ → ℝ hf : Monotone f x : ℝ hx : Tendsto (fun b => (↑(stieltjesFunction hf) b - f x) / (b - x)) (𝓝[Iio x] x) (𝓝 (ENNReal.toReal (rnDeriv (StieltjesFunction.measure (stieltjesFunction hf)) volume x))) ∧ Tendsto (fun b => (↑(stieltjesFunction hf) b - f x) / (b - x)) (𝓝[Ioi x] x) (𝓝 (ENNReal.toReal (rnDeriv (StieltjesFunction.measure (stieltjesFunction hf)) volume x))) h'x : ¬¬ContinuousAt f x A : ↑(stieltjesFunction hf) x = f x this : Tendsto (fun y => (↑(stieltjesFunction hf) (y + -↑1 * (y - x) ^ 2) - f x) / (y - x)) (𝓝[Ioi x] x) (𝓝 (ENNReal.toReal (rnDeriv (StieltjesFunction.measure (stieltjesFunction hf)) volume x))) y : ℝ hy : x < y ⊢ (f y - f x) / (y - x) ≤ (↑(stieltjesFunction hf) y - f x) / (y - x) [PROOFSTEP] apply div_le_div_of_le_of_nonneg _ (sub_pos.2 hy).le [GOAL] f : ℝ → ℝ hf : Monotone f x : ℝ hx : Tendsto (fun b => (↑(stieltjesFunction hf) b - f x) / (b - x)) (𝓝[Iio x] x) (𝓝 (ENNReal.toReal (rnDeriv (StieltjesFunction.measure (stieltjesFunction hf)) volume x))) ∧ Tendsto (fun b => (↑(stieltjesFunction hf) b - f x) / (b - x)) (𝓝[Ioi x] x) (𝓝 (ENNReal.toReal (rnDeriv (StieltjesFunction.measure (stieltjesFunction hf)) volume x))) h'x : ¬¬ContinuousAt f x A : ↑(stieltjesFunction hf) x = f x this : Tendsto (fun y => (↑(stieltjesFunction hf) (y + -↑1 * (y - x) ^ 2) - f x) / (y - x)) (𝓝[Ioi x] x) (𝓝 (ENNReal.toReal (rnDeriv (StieltjesFunction.measure (stieltjesFunction hf)) volume x))) y : ℝ hy : x < y ⊢ f y - f x ≤ ↑(stieltjesFunction hf) y - f x [PROOFSTEP] exact (sub_le_sub_iff_right _).2 (hf.le_rightLim (le_refl y)) -- prove differentiability on the left, by sandwiching with values of `g` [GOAL] case h f : ℝ → ℝ hf : Monotone f x : ℝ hx : Tendsto (fun b => (↑(stieltjesFunction hf) b - f x) / (b - x)) (𝓝[Iio x] x) (𝓝 (ENNReal.toReal (rnDeriv (StieltjesFunction.measure (stieltjesFunction hf)) volume x))) ∧ Tendsto (fun b => (↑(stieltjesFunction hf) b - f x) / (b - x)) (𝓝[Ioi x] x) (𝓝 (ENNReal.toReal (rnDeriv (StieltjesFunction.measure (stieltjesFunction hf)) volume x))) h'x : ¬¬ContinuousAt f x A : ↑(stieltjesFunction hf) x = f x L1 : Tendsto (fun y => (f y - f x) / (y - x)) (𝓝[Ioi x] x) (𝓝 (ENNReal.toReal (rnDeriv (StieltjesFunction.measure (stieltjesFunction hf)) volume x))) ⊢ HasDerivAt f (ENNReal.toReal (rnDeriv (StieltjesFunction.measure (stieltjesFunction hf)) volume x)) x [PROOFSTEP] have L2 : Tendsto (fun y => (f y - f x) / (y - x)) (𝓝[<] x) (𝓝 (rnDeriv hf.stieltjesFunction.measure volume x).toReal) := by -- limit of a helper function, with a small shift compared to `g` have : Tendsto (fun y => (hf.stieltjesFunction (y + -1 * (y - x) ^ 2) - f x) / (y - x)) (𝓝[<] x) (𝓝 (rnDeriv hf.stieltjesFunction.measure volume x).toReal) := by apply tendsto_apply_add_mul_sq_div_sub (nhds_left'_le_nhds_ne x) hx.1 apply tendsto_nhdsWithin_of_tendsto_nhds_of_eventually_within · apply Tendsto.mono_left _ nhdsWithin_le_nhds have : Tendsto (fun y : ℝ => y + -↑1 * (y - x) ^ 2) (𝓝 x) (𝓝 (x + -↑1 * (x - x) ^ 2)) := tendsto_id.add (((tendsto_id.sub_const x).pow 2).const_mul (-1)) simpa using this · have : Ioo (x - 1) x ∈ 𝓝[<] x := by apply Ioo_mem_nhdsWithin_Iio; exact ⟨by linarith, le_refl _⟩ filter_upwards [this] rintro y ⟨hy : x - 1 < y, h'y : y < x⟩ rw [mem_Iio] norm_num; nlinarith -- apply the sandwiching argument, with `g` and the helper function apply tendsto_of_tendsto_of_tendsto_of_le_of_le' hx.1 this · filter_upwards [self_mem_nhdsWithin] rintro y (hy : y < x) apply div_le_div_of_nonpos_of_le (sub_neg.2 hy).le exact (sub_le_sub_iff_right _).2 (hf.le_rightLim (le_refl _)) · filter_upwards [self_mem_nhdsWithin] rintro y (hy : y < x) have : ↑0 < (y - x) ^ 2 := sq_pos_of_neg (sub_neg.2 hy) apply div_le_div_of_nonpos_of_le (sub_neg.2 hy).le exact (sub_le_sub_iff_right _).2 (hf.rightLim_le (by norm_num; linarith)) -- conclude global differentiability [GOAL] f : ℝ → ℝ hf : Monotone f x : ℝ hx : Tendsto (fun b => (↑(stieltjesFunction hf) b - f x) / (b - x)) (𝓝[Iio x] x) (𝓝 (ENNReal.toReal (rnDeriv (StieltjesFunction.measure (stieltjesFunction hf)) volume x))) ∧ Tendsto (fun b => (↑(stieltjesFunction hf) b - f x) / (b - x)) (𝓝[Ioi x] x) (𝓝 (ENNReal.toReal (rnDeriv (StieltjesFunction.measure (stieltjesFunction hf)) volume x))) h'x : ¬¬ContinuousAt f x A : ↑(stieltjesFunction hf) x = f x L1 : Tendsto (fun y => (f y - f x) / (y - x)) (𝓝[Ioi x] x) (𝓝 (ENNReal.toReal (rnDeriv (StieltjesFunction.measure (stieltjesFunction hf)) volume x))) ⊢ Tendsto (fun y => (f y - f x) / (y - x)) (𝓝[Iio x] x) (𝓝 (ENNReal.toReal (rnDeriv (StieltjesFunction.measure (stieltjesFunction hf)) volume x))) [PROOFSTEP] have : Tendsto (fun y => (hf.stieltjesFunction (y + -1 * (y - x) ^ 2) - f x) / (y - x)) (𝓝[<] x) (𝓝 (rnDeriv hf.stieltjesFunction.measure volume x).toReal) := by apply tendsto_apply_add_mul_sq_div_sub (nhds_left'_le_nhds_ne x) hx.1 apply tendsto_nhdsWithin_of_tendsto_nhds_of_eventually_within · apply Tendsto.mono_left _ nhdsWithin_le_nhds have : Tendsto (fun y : ℝ => y + -↑1 * (y - x) ^ 2) (𝓝 x) (𝓝 (x + -↑1 * (x - x) ^ 2)) := tendsto_id.add (((tendsto_id.sub_const x).pow 2).const_mul (-1)) simpa using this · have : Ioo (x - 1) x ∈ 𝓝[<] x := by apply Ioo_mem_nhdsWithin_Iio; exact ⟨by linarith, le_refl _⟩ filter_upwards [this] rintro y ⟨hy : x - 1 < y, h'y : y < x⟩ rw [mem_Iio] norm_num; nlinarith -- apply the sandwiching argument, with `g` and the helper function [GOAL] f : ℝ → ℝ hf : Monotone f x : ℝ hx : Tendsto (fun b => (↑(stieltjesFunction hf) b - f x) / (b - x)) (𝓝[Iio x] x) (𝓝 (ENNReal.toReal (rnDeriv (StieltjesFunction.measure (stieltjesFunction hf)) volume x))) ∧ Tendsto (fun b => (↑(stieltjesFunction hf) b - f x) / (b - x)) (𝓝[Ioi x] x) (𝓝 (ENNReal.toReal (rnDeriv (StieltjesFunction.measure (stieltjesFunction hf)) volume x))) h'x : ¬¬ContinuousAt f x A : ↑(stieltjesFunction hf) x = f x L1 : Tendsto (fun y => (f y - f x) / (y - x)) (𝓝[Ioi x] x) (𝓝 (ENNReal.toReal (rnDeriv (StieltjesFunction.measure (stieltjesFunction hf)) volume x))) ⊢ Tendsto (fun y => (↑(stieltjesFunction hf) (y + -↑1 * (y - x) ^ 2) - f x) / (y - x)) (𝓝[Iio x] x) (𝓝 (ENNReal.toReal (rnDeriv (StieltjesFunction.measure (stieltjesFunction hf)) volume x))) [PROOFSTEP] apply tendsto_apply_add_mul_sq_div_sub (nhds_left'_le_nhds_ne x) hx.1 [GOAL] f : ℝ → ℝ hf : Monotone f x : ℝ hx : Tendsto (fun b => (↑(stieltjesFunction hf) b - f x) / (b - x)) (𝓝[Iio x] x) (𝓝 (ENNReal.toReal (rnDeriv (StieltjesFunction.measure (stieltjesFunction hf)) volume x))) ∧ Tendsto (fun b => (↑(stieltjesFunction hf) b - f x) / (b - x)) (𝓝[Ioi x] x) (𝓝 (ENNReal.toReal (rnDeriv (StieltjesFunction.measure (stieltjesFunction hf)) volume x))) h'x : ¬¬ContinuousAt f x A : ↑(stieltjesFunction hf) x = f x L1 : Tendsto (fun y => (f y - f x) / (y - x)) (𝓝[Ioi x] x) (𝓝 (ENNReal.toReal (rnDeriv (StieltjesFunction.measure (stieltjesFunction hf)) volume x))) ⊢ Tendsto (fun y => y + -↑1 * (y - x) ^ 2) (𝓝[Iio x] x) (𝓝[Iio x] x) [PROOFSTEP] apply tendsto_nhdsWithin_of_tendsto_nhds_of_eventually_within [GOAL] case h1 f : ℝ → ℝ hf : Monotone f x : ℝ hx : Tendsto (fun b => (↑(stieltjesFunction hf) b - f x) / (b - x)) (𝓝[Iio x] x) (𝓝 (ENNReal.toReal (rnDeriv (StieltjesFunction.measure (stieltjesFunction hf)) volume x))) ∧ Tendsto (fun b => (↑(stieltjesFunction hf) b - f x) / (b - x)) (𝓝[Ioi x] x) (𝓝 (ENNReal.toReal (rnDeriv (StieltjesFunction.measure (stieltjesFunction hf)) volume x))) h'x : ¬¬ContinuousAt f x A : ↑(stieltjesFunction hf) x = f x L1 : Tendsto (fun y => (f y - f x) / (y - x)) (𝓝[Ioi x] x) (𝓝 (ENNReal.toReal (rnDeriv (StieltjesFunction.measure (stieltjesFunction hf)) volume x))) ⊢ Tendsto (fun y => y + -↑1 * (y - x) ^ 2) (𝓝[Iio x] x) (𝓝 x) [PROOFSTEP] apply Tendsto.mono_left _ nhdsWithin_le_nhds [GOAL] f : ℝ → ℝ hf : Monotone f x : ℝ hx : Tendsto (fun b => (↑(stieltjesFunction hf) b - f x) / (b - x)) (𝓝[Iio x] x) (𝓝 (ENNReal.toReal (rnDeriv (StieltjesFunction.measure (stieltjesFunction hf)) volume x))) ∧ Tendsto (fun b => (↑(stieltjesFunction hf) b - f x) / (b - x)) (𝓝[Ioi x] x) (𝓝 (ENNReal.toReal (rnDeriv (StieltjesFunction.measure (stieltjesFunction hf)) volume x))) h'x : ¬¬ContinuousAt f x A : ↑(stieltjesFunction hf) x = f x L1 : Tendsto (fun y => (f y - f x) / (y - x)) (𝓝[Ioi x] x) (𝓝 (ENNReal.toReal (rnDeriv (StieltjesFunction.measure (stieltjesFunction hf)) volume x))) ⊢ Tendsto (fun y => y + -↑1 * (y - x) ^ 2) (𝓝 x) (𝓝 x) [PROOFSTEP] have : Tendsto (fun y : ℝ => y + -↑1 * (y - x) ^ 2) (𝓝 x) (𝓝 (x + -↑1 * (x - x) ^ 2)) := tendsto_id.add (((tendsto_id.sub_const x).pow 2).const_mul (-1)) [GOAL] f : ℝ → ℝ hf : Monotone f x : ℝ hx : Tendsto (fun b => (↑(stieltjesFunction hf) b - f x) / (b - x)) (𝓝[Iio x] x) (𝓝 (ENNReal.toReal (rnDeriv (StieltjesFunction.measure (stieltjesFunction hf)) volume x))) ∧ Tendsto (fun b => (↑(stieltjesFunction hf) b - f x) / (b - x)) (𝓝[Ioi x] x) (𝓝 (ENNReal.toReal (rnDeriv (StieltjesFunction.measure (stieltjesFunction hf)) volume x))) h'x : ¬¬ContinuousAt f x A : ↑(stieltjesFunction hf) x = f x L1 : Tendsto (fun y => (f y - f x) / (y - x)) (𝓝[Ioi x] x) (𝓝 (ENNReal.toReal (rnDeriv (StieltjesFunction.measure (stieltjesFunction hf)) volume x))) this : Tendsto (fun y => y + -1 * (y - x) ^ 2) (𝓝 x) (𝓝 (x + -1 * (x - x) ^ 2)) ⊢ Tendsto (fun y => y + -↑1 * (y - x) ^ 2) (𝓝 x) (𝓝 x) [PROOFSTEP] simpa using this [GOAL] case h2 f : ℝ → ℝ hf : Monotone f x : ℝ hx : Tendsto (fun b => (↑(stieltjesFunction hf) b - f x) / (b - x)) (𝓝[Iio x] x) (𝓝 (ENNReal.toReal (rnDeriv (StieltjesFunction.measure (stieltjesFunction hf)) volume x))) ∧ Tendsto (fun b => (↑(stieltjesFunction hf) b - f x) / (b - x)) (𝓝[Ioi x] x) (𝓝 (ENNReal.toReal (rnDeriv (StieltjesFunction.measure (stieltjesFunction hf)) volume x))) h'x : ¬¬ContinuousAt f x A : ↑(stieltjesFunction hf) x = f x L1 : Tendsto (fun y => (f y - f x) / (y - x)) (𝓝[Ioi x] x) (𝓝 (ENNReal.toReal (rnDeriv (StieltjesFunction.measure (stieltjesFunction hf)) volume x))) ⊢ ∀ᶠ (x_1 : ℝ) in 𝓝[Iio x] x, x_1 + -↑1 * (x_1 - x) ^ 2 ∈ Iio x [PROOFSTEP] have : Ioo (x - 1) x ∈ 𝓝[<] x := by apply Ioo_mem_nhdsWithin_Iio; exact ⟨by linarith, le_refl _⟩ [GOAL] f : ℝ → ℝ hf : Monotone f x : ℝ hx : Tendsto (fun b => (↑(stieltjesFunction hf) b - f x) / (b - x)) (𝓝[Iio x] x) (𝓝 (ENNReal.toReal (rnDeriv (StieltjesFunction.measure (stieltjesFunction hf)) volume x))) ∧ Tendsto (fun b => (↑(stieltjesFunction hf) b - f x) / (b - x)) (𝓝[Ioi x] x) (𝓝 (ENNReal.toReal (rnDeriv (StieltjesFunction.measure (stieltjesFunction hf)) volume x))) h'x : ¬¬ContinuousAt f x A : ↑(stieltjesFunction hf) x = f x L1 : Tendsto (fun y => (f y - f x) / (y - x)) (𝓝[Ioi x] x) (𝓝 (ENNReal.toReal (rnDeriv (StieltjesFunction.measure (stieltjesFunction hf)) volume x))) ⊢ Ioo (x - 1) x ∈ 𝓝[Iio x] x [PROOFSTEP] apply Ioo_mem_nhdsWithin_Iio [GOAL] case H f : ℝ → ℝ hf : Monotone f x : ℝ hx : Tendsto (fun b => (↑(stieltjesFunction hf) b - f x) / (b - x)) (𝓝[Iio x] x) (𝓝 (ENNReal.toReal (rnDeriv (StieltjesFunction.measure (stieltjesFunction hf)) volume x))) ∧ Tendsto (fun b => (↑(stieltjesFunction hf) b - f x) / (b - x)) (𝓝[Ioi x] x) (𝓝 (ENNReal.toReal (rnDeriv (StieltjesFunction.measure (stieltjesFunction hf)) volume x))) h'x : ¬¬ContinuousAt f x A : ↑(stieltjesFunction hf) x = f x L1 : Tendsto (fun y => (f y - f x) / (y - x)) (𝓝[Ioi x] x) (𝓝 (ENNReal.toReal (rnDeriv (StieltjesFunction.measure (stieltjesFunction hf)) volume x))) ⊢ x ∈ Ioc (x - 1) x [PROOFSTEP] exact ⟨by linarith, le_refl _⟩ [GOAL] f : ℝ → ℝ hf : Monotone f x : ℝ hx : Tendsto (fun b => (↑(stieltjesFunction hf) b - f x) / (b - x)) (𝓝[Iio x] x) (𝓝 (ENNReal.toReal (rnDeriv (StieltjesFunction.measure (stieltjesFunction hf)) volume x))) ∧ Tendsto (fun b => (↑(stieltjesFunction hf) b - f x) / (b - x)) (𝓝[Ioi x] x) (𝓝 (ENNReal.toReal (rnDeriv (StieltjesFunction.measure (stieltjesFunction hf)) volume x))) h'x : ¬¬ContinuousAt f x A : ↑(stieltjesFunction hf) x = f x L1 : Tendsto (fun y => (f y - f x) / (y - x)) (𝓝[Ioi x] x) (𝓝 (ENNReal.toReal (rnDeriv (StieltjesFunction.measure (stieltjesFunction hf)) volume x))) ⊢ x - 1 < x [PROOFSTEP] linarith [GOAL] case h2 f : ℝ → ℝ hf : Monotone f x : ℝ hx : Tendsto (fun b => (↑(stieltjesFunction hf) b - f x) / (b - x)) (𝓝[Iio x] x) (𝓝 (ENNReal.toReal (rnDeriv (StieltjesFunction.measure (stieltjesFunction hf)) volume x))) ∧ Tendsto (fun b => (↑(stieltjesFunction hf) b - f x) / (b - x)) (𝓝[Ioi x] x) (𝓝 (ENNReal.toReal (rnDeriv (StieltjesFunction.measure (stieltjesFunction hf)) volume x))) h'x : ¬¬ContinuousAt f x A : ↑(stieltjesFunction hf) x = f x L1 : Tendsto (fun y => (f y - f x) / (y - x)) (𝓝[Ioi x] x) (𝓝 (ENNReal.toReal (rnDeriv (StieltjesFunction.measure (stieltjesFunction hf)) volume x))) this : Ioo (x - 1) x ∈ 𝓝[Iio x] x ⊢ ∀ᶠ (x_1 : ℝ) in 𝓝[Iio x] x, x_1 + -↑1 * (x_1 - x) ^ 2 ∈ Iio x [PROOFSTEP] filter_upwards [this] [GOAL] case h f : ℝ → ℝ hf : Monotone f x : ℝ hx : Tendsto (fun b => (↑(stieltjesFunction hf) b - f x) / (b - x)) (𝓝[Iio x] x) (𝓝 (ENNReal.toReal (rnDeriv (StieltjesFunction.measure (stieltjesFunction hf)) volume x))) ∧ Tendsto (fun b => (↑(stieltjesFunction hf) b - f x) / (b - x)) (𝓝[Ioi x] x) (𝓝 (ENNReal.toReal (rnDeriv (StieltjesFunction.measure (stieltjesFunction hf)) volume x))) h'x : ¬¬ContinuousAt f x A : ↑(stieltjesFunction hf) x = f x L1 : Tendsto (fun y => (f y - f x) / (y - x)) (𝓝[Ioi x] x) (𝓝 (ENNReal.toReal (rnDeriv (StieltjesFunction.measure (stieltjesFunction hf)) volume x))) this : Ioo (x - 1) x ∈ 𝓝[Iio x] x ⊢ ∀ (a : ℝ), a ∈ Ioo (x - 1) x → a + -↑1 * (a - x) ^ 2 ∈ Iio x [PROOFSTEP] rintro y ⟨hy : x - 1 < y, h'y : y < x⟩ [GOAL] case h.intro f : ℝ → ℝ hf : Monotone f x : ℝ hx : Tendsto (fun b => (↑(stieltjesFunction hf) b - f x) / (b - x)) (𝓝[Iio x] x) (𝓝 (ENNReal.toReal (rnDeriv (StieltjesFunction.measure (stieltjesFunction hf)) volume x))) ∧ Tendsto (fun b => (↑(stieltjesFunction hf) b - f x) / (b - x)) (𝓝[Ioi x] x) (𝓝 (ENNReal.toReal (rnDeriv (StieltjesFunction.measure (stieltjesFunction hf)) volume x))) h'x : ¬¬ContinuousAt f x A : ↑(stieltjesFunction hf) x = f x L1 : Tendsto (fun y => (f y - f x) / (y - x)) (𝓝[Ioi x] x) (𝓝 (ENNReal.toReal (rnDeriv (StieltjesFunction.measure (stieltjesFunction hf)) volume x))) this : Ioo (x - 1) x ∈ 𝓝[Iio x] x y : ℝ hy : x - 1 < y h'y : y < x ⊢ y + -↑1 * (y - x) ^ 2 ∈ Iio x [PROOFSTEP] rw [mem_Iio] [GOAL] case h.intro f : ℝ → ℝ hf : Monotone f x : ℝ hx : Tendsto (fun b => (↑(stieltjesFunction hf) b - f x) / (b - x)) (𝓝[Iio x] x) (𝓝 (ENNReal.toReal (rnDeriv (StieltjesFunction.measure (stieltjesFunction hf)) volume x))) ∧ Tendsto (fun b => (↑(stieltjesFunction hf) b - f x) / (b - x)) (𝓝[Ioi x] x) (𝓝 (ENNReal.toReal (rnDeriv (StieltjesFunction.measure (stieltjesFunction hf)) volume x))) h'x : ¬¬ContinuousAt f x A : ↑(stieltjesFunction hf) x = f x L1 : Tendsto (fun y => (f y - f x) / (y - x)) (𝓝[Ioi x] x) (𝓝 (ENNReal.toReal (rnDeriv (StieltjesFunction.measure (stieltjesFunction hf)) volume x))) this : Ioo (x - 1) x ∈ 𝓝[Iio x] x y : ℝ hy : x - 1 < y h'y : y < x ⊢ y + -↑1 * (y - x) ^ 2 < x [PROOFSTEP] norm_num [GOAL] case h.intro f : ℝ → ℝ hf : Monotone f x : ℝ hx : Tendsto (fun b => (↑(stieltjesFunction hf) b - f x) / (b - x)) (𝓝[Iio x] x) (𝓝 (ENNReal.toReal (rnDeriv (StieltjesFunction.measure (stieltjesFunction hf)) volume x))) ∧ Tendsto (fun b => (↑(stieltjesFunction hf) b - f x) / (b - x)) (𝓝[Ioi x] x) (𝓝 (ENNReal.toReal (rnDeriv (StieltjesFunction.measure (stieltjesFunction hf)) volume x))) h'x : ¬¬ContinuousAt f x A : ↑(stieltjesFunction hf) x = f x L1 : Tendsto (fun y => (f y - f x) / (y - x)) (𝓝[Ioi x] x) (𝓝 (ENNReal.toReal (rnDeriv (StieltjesFunction.measure (stieltjesFunction hf)) volume x))) this : Ioo (x - 1) x ∈ 𝓝[Iio x] x y : ℝ hy : x - 1 < y h'y : y < x ⊢ y < x + (y - x) ^ 2 [PROOFSTEP] nlinarith -- apply the sandwiching argument, with `g` and the helper function [GOAL] f : ℝ → ℝ hf : Monotone f x : ℝ hx : Tendsto (fun b => (↑(stieltjesFunction hf) b - f x) / (b - x)) (𝓝[Iio x] x) (𝓝 (ENNReal.toReal (rnDeriv (StieltjesFunction.measure (stieltjesFunction hf)) volume x))) ∧ Tendsto (fun b => (↑(stieltjesFunction hf) b - f x) / (b - x)) (𝓝[Ioi x] x) (𝓝 (ENNReal.toReal (rnDeriv (StieltjesFunction.measure (stieltjesFunction hf)) volume x))) h'x : ¬¬ContinuousAt f x A : ↑(stieltjesFunction hf) x = f x L1 : Tendsto (fun y => (f y - f x) / (y - x)) (𝓝[Ioi x] x) (𝓝 (ENNReal.toReal (rnDeriv (StieltjesFunction.measure (stieltjesFunction hf)) volume x))) this : Tendsto (fun y => (↑(stieltjesFunction hf) (y + -↑1 * (y - x) ^ 2) - f x) / (y - x)) (𝓝[Iio x] x) (𝓝 (ENNReal.toReal (rnDeriv (StieltjesFunction.measure (stieltjesFunction hf)) volume x))) ⊢ Tendsto (fun y => (f y - f x) / (y - x)) (𝓝[Iio x] x) (𝓝 (ENNReal.toReal (rnDeriv (StieltjesFunction.measure (stieltjesFunction hf)) volume x))) [PROOFSTEP] apply tendsto_of_tendsto_of_tendsto_of_le_of_le' hx.1 this [GOAL] case hgf f : ℝ → ℝ hf : Monotone f x : ℝ hx : Tendsto (fun b => (↑(stieltjesFunction hf) b - f x) / (b - x)) (𝓝[Iio x] x) (𝓝 (ENNReal.toReal (rnDeriv (StieltjesFunction.measure (stieltjesFunction hf)) volume x))) ∧ Tendsto (fun b => (↑(stieltjesFunction hf) b - f x) / (b - x)) (𝓝[Ioi x] x) (𝓝 (ENNReal.toReal (rnDeriv (StieltjesFunction.measure (stieltjesFunction hf)) volume x))) h'x : ¬¬ContinuousAt f x A : ↑(stieltjesFunction hf) x = f x L1 : Tendsto (fun y => (f y - f x) / (y - x)) (𝓝[Ioi x] x) (𝓝 (ENNReal.toReal (rnDeriv (StieltjesFunction.measure (stieltjesFunction hf)) volume x))) this : Tendsto (fun y => (↑(stieltjesFunction hf) (y + -↑1 * (y - x) ^ 2) - f x) / (y - x)) (𝓝[Iio x] x) (𝓝 (ENNReal.toReal (rnDeriv (StieltjesFunction.measure (stieltjesFunction hf)) volume x))) ⊢ ∀ᶠ (b : ℝ) in 𝓝[Iio x] x, (↑(stieltjesFunction hf) b - f x) / (b - x) ≤ (f b - f x) / (b - x) [PROOFSTEP] filter_upwards [self_mem_nhdsWithin] [GOAL] case h f : ℝ → ℝ hf : Monotone f x : ℝ hx : Tendsto (fun b => (↑(stieltjesFunction hf) b - f x) / (b - x)) (𝓝[Iio x] x) (𝓝 (ENNReal.toReal (rnDeriv (StieltjesFunction.measure (stieltjesFunction hf)) volume x))) ∧ Tendsto (fun b => (↑(stieltjesFunction hf) b - f x) / (b - x)) (𝓝[Ioi x] x) (𝓝 (ENNReal.toReal (rnDeriv (StieltjesFunction.measure (stieltjesFunction hf)) volume x))) h'x : ¬¬ContinuousAt f x A : ↑(stieltjesFunction hf) x = f x L1 : Tendsto (fun y => (f y - f x) / (y - x)) (𝓝[Ioi x] x) (𝓝 (ENNReal.toReal (rnDeriv (StieltjesFunction.measure (stieltjesFunction hf)) volume x))) this : Tendsto (fun y => (↑(stieltjesFunction hf) (y + -↑1 * (y - x) ^ 2) - f x) / (y - x)) (𝓝[Iio x] x) (𝓝 (ENNReal.toReal (rnDeriv (StieltjesFunction.measure (stieltjesFunction hf)) volume x))) ⊢ ∀ (a : ℝ), a ∈ Iio x → (↑(stieltjesFunction hf) a - f x) / (a - x) ≤ (f a - f x) / (a - x) [PROOFSTEP] rintro y (hy : y < x) [GOAL] case h f : ℝ → ℝ hf : Monotone f x : ℝ hx : Tendsto (fun b => (↑(stieltjesFunction hf) b - f x) / (b - x)) (𝓝[Iio x] x) (𝓝 (ENNReal.toReal (rnDeriv (StieltjesFunction.measure (stieltjesFunction hf)) volume x))) ∧ Tendsto (fun b => (↑(stieltjesFunction hf) b - f x) / (b - x)) (𝓝[Ioi x] x) (𝓝 (ENNReal.toReal (rnDeriv (StieltjesFunction.measure (stieltjesFunction hf)) volume x))) h'x : ¬¬ContinuousAt f x A : ↑(stieltjesFunction hf) x = f x L1 : Tendsto (fun y => (f y - f x) / (y - x)) (𝓝[Ioi x] x) (𝓝 (ENNReal.toReal (rnDeriv (StieltjesFunction.measure (stieltjesFunction hf)) volume x))) this : Tendsto (fun y => (↑(stieltjesFunction hf) (y + -↑1 * (y - x) ^ 2) - f x) / (y - x)) (𝓝[Iio x] x) (𝓝 (ENNReal.toReal (rnDeriv (StieltjesFunction.measure (stieltjesFunction hf)) volume x))) y : ℝ hy : y < x ⊢ (↑(stieltjesFunction hf) y - f x) / (y - x) ≤ (f y - f x) / (y - x) [PROOFSTEP] apply div_le_div_of_nonpos_of_le (sub_neg.2 hy).le [GOAL] case h f : ℝ → ℝ hf : Monotone f x : ℝ hx : Tendsto (fun b => (↑(stieltjesFunction hf) b - f x) / (b - x)) (𝓝[Iio x] x) (𝓝 (ENNReal.toReal (rnDeriv (StieltjesFunction.measure (stieltjesFunction hf)) volume x))) ∧ Tendsto (fun b => (↑(stieltjesFunction hf) b - f x) / (b - x)) (𝓝[Ioi x] x) (𝓝 (ENNReal.toReal (rnDeriv (StieltjesFunction.measure (stieltjesFunction hf)) volume x))) h'x : ¬¬ContinuousAt f x A : ↑(stieltjesFunction hf) x = f x L1 : Tendsto (fun y => (f y - f x) / (y - x)) (𝓝[Ioi x] x) (𝓝 (ENNReal.toReal (rnDeriv (StieltjesFunction.measure (stieltjesFunction hf)) volume x))) this : Tendsto (fun y => (↑(stieltjesFunction hf) (y + -↑1 * (y - x) ^ 2) - f x) / (y - x)) (𝓝[Iio x] x) (𝓝 (ENNReal.toReal (rnDeriv (StieltjesFunction.measure (stieltjesFunction hf)) volume x))) y : ℝ hy : y < x ⊢ f y - f x ≤ ↑(stieltjesFunction hf) y - f x [PROOFSTEP] exact (sub_le_sub_iff_right _).2 (hf.le_rightLim (le_refl _)) [GOAL] case hfh f : ℝ → ℝ hf : Monotone f x : ℝ hx : Tendsto (fun b => (↑(stieltjesFunction hf) b - f x) / (b - x)) (𝓝[Iio x] x) (𝓝 (ENNReal.toReal (rnDeriv (StieltjesFunction.measure (stieltjesFunction hf)) volume x))) ∧ Tendsto (fun b => (↑(stieltjesFunction hf) b - f x) / (b - x)) (𝓝[Ioi x] x) (𝓝 (ENNReal.toReal (rnDeriv (StieltjesFunction.measure (stieltjesFunction hf)) volume x))) h'x : ¬¬ContinuousAt f x A : ↑(stieltjesFunction hf) x = f x L1 : Tendsto (fun y => (f y - f x) / (y - x)) (𝓝[Ioi x] x) (𝓝 (ENNReal.toReal (rnDeriv (StieltjesFunction.measure (stieltjesFunction hf)) volume x))) this : Tendsto (fun y => (↑(stieltjesFunction hf) (y + -↑1 * (y - x) ^ 2) - f x) / (y - x)) (𝓝[Iio x] x) (𝓝 (ENNReal.toReal (rnDeriv (StieltjesFunction.measure (stieltjesFunction hf)) volume x))) ⊢ ∀ᶠ (b : ℝ) in 𝓝[Iio x] x, (f b - f x) / (b - x) ≤ (↑(stieltjesFunction hf) (b + -↑1 * (b - x) ^ 2) - f x) / (b - x) [PROOFSTEP] filter_upwards [self_mem_nhdsWithin] [GOAL] case h f : ℝ → ℝ hf : Monotone f x : ℝ hx : Tendsto (fun b => (↑(stieltjesFunction hf) b - f x) / (b - x)) (𝓝[Iio x] x) (𝓝 (ENNReal.toReal (rnDeriv (StieltjesFunction.measure (stieltjesFunction hf)) volume x))) ∧ Tendsto (fun b => (↑(stieltjesFunction hf) b - f x) / (b - x)) (𝓝[Ioi x] x) (𝓝 (ENNReal.toReal (rnDeriv (StieltjesFunction.measure (stieltjesFunction hf)) volume x))) h'x : ¬¬ContinuousAt f x A : ↑(stieltjesFunction hf) x = f x L1 : Tendsto (fun y => (f y - f x) / (y - x)) (𝓝[Ioi x] x) (𝓝 (ENNReal.toReal (rnDeriv (StieltjesFunction.measure (stieltjesFunction hf)) volume x))) this : Tendsto (fun y => (↑(stieltjesFunction hf) (y + -↑1 * (y - x) ^ 2) - f x) / (y - x)) (𝓝[Iio x] x) (𝓝 (ENNReal.toReal (rnDeriv (StieltjesFunction.measure (stieltjesFunction hf)) volume x))) ⊢ ∀ (a : ℝ), a ∈ Iio x → (f a - f x) / (a - x) ≤ (↑(stieltjesFunction hf) (a + -↑1 * (a - x) ^ 2) - f x) / (a - x) [PROOFSTEP] rintro y (hy : y < x) [GOAL] case h f : ℝ → ℝ hf : Monotone f x : ℝ hx : Tendsto (fun b => (↑(stieltjesFunction hf) b - f x) / (b - x)) (𝓝[Iio x] x) (𝓝 (ENNReal.toReal (rnDeriv (StieltjesFunction.measure (stieltjesFunction hf)) volume x))) ∧ Tendsto (fun b => (↑(stieltjesFunction hf) b - f x) / (b - x)) (𝓝[Ioi x] x) (𝓝 (ENNReal.toReal (rnDeriv (StieltjesFunction.measure (stieltjesFunction hf)) volume x))) h'x : ¬¬ContinuousAt f x A : ↑(stieltjesFunction hf) x = f x L1 : Tendsto (fun y => (f y - f x) / (y - x)) (𝓝[Ioi x] x) (𝓝 (ENNReal.toReal (rnDeriv (StieltjesFunction.measure (stieltjesFunction hf)) volume x))) this : Tendsto (fun y => (↑(stieltjesFunction hf) (y + -↑1 * (y - x) ^ 2) - f x) / (y - x)) (𝓝[Iio x] x) (𝓝 (ENNReal.toReal (rnDeriv (StieltjesFunction.measure (stieltjesFunction hf)) volume x))) y : ℝ hy : y < x ⊢ (f y - f x) / (y - x) ≤ (↑(stieltjesFunction hf) (y + -↑1 * (y - x) ^ 2) - f x) / (y - x) [PROOFSTEP] have : ↑0 < (y - x) ^ 2 := sq_pos_of_neg (sub_neg.2 hy) [GOAL] case h f : ℝ → ℝ hf : Monotone f x : ℝ hx : Tendsto (fun b => (↑(stieltjesFunction hf) b - f x) / (b - x)) (𝓝[Iio x] x) (𝓝 (ENNReal.toReal (rnDeriv (StieltjesFunction.measure (stieltjesFunction hf)) volume x))) ∧ Tendsto (fun b => (↑(stieltjesFunction hf) b - f x) / (b - x)) (𝓝[Ioi x] x) (𝓝 (ENNReal.toReal (rnDeriv (StieltjesFunction.measure (stieltjesFunction hf)) volume x))) h'x : ¬¬ContinuousAt f x A : ↑(stieltjesFunction hf) x = f x L1 : Tendsto (fun y => (f y - f x) / (y - x)) (𝓝[Ioi x] x) (𝓝 (ENNReal.toReal (rnDeriv (StieltjesFunction.measure (stieltjesFunction hf)) volume x))) this✝ : Tendsto (fun y => (↑(stieltjesFunction hf) (y + -↑1 * (y - x) ^ 2) - f x) / (y - x)) (𝓝[Iio x] x) (𝓝 (ENNReal.toReal (rnDeriv (StieltjesFunction.measure (stieltjesFunction hf)) volume x))) y : ℝ hy : y < x this : 0 < (y - x) ^ 2 ⊢ (f y - f x) / (y - x) ≤ (↑(stieltjesFunction hf) (y + -↑1 * (y - x) ^ 2) - f x) / (y - x) [PROOFSTEP] apply div_le_div_of_nonpos_of_le (sub_neg.2 hy).le [GOAL] case h f : ℝ → ℝ hf : Monotone f x : ℝ hx : Tendsto (fun b => (↑(stieltjesFunction hf) b - f x) / (b - x)) (𝓝[Iio x] x) (𝓝 (ENNReal.toReal (rnDeriv (StieltjesFunction.measure (stieltjesFunction hf)) volume x))) ∧ Tendsto (fun b => (↑(stieltjesFunction hf) b - f x) / (b - x)) (𝓝[Ioi x] x) (𝓝 (ENNReal.toReal (rnDeriv (StieltjesFunction.measure (stieltjesFunction hf)) volume x))) h'x : ¬¬ContinuousAt f x A : ↑(stieltjesFunction hf) x = f x L1 : Tendsto (fun y => (f y - f x) / (y - x)) (𝓝[Ioi x] x) (𝓝 (ENNReal.toReal (rnDeriv (StieltjesFunction.measure (stieltjesFunction hf)) volume x))) this✝ : Tendsto (fun y => (↑(stieltjesFunction hf) (y + -↑1 * (y - x) ^ 2) - f x) / (y - x)) (𝓝[Iio x] x) (𝓝 (ENNReal.toReal (rnDeriv (StieltjesFunction.measure (stieltjesFunction hf)) volume x))) y : ℝ hy : y < x this : 0 < (y - x) ^ 2 ⊢ ↑(stieltjesFunction hf) (y + -↑1 * (y - x) ^ 2) - f x ≤ f y - f x [PROOFSTEP] exact (sub_le_sub_iff_right _).2 (hf.rightLim_le (by norm_num; linarith)) -- conclude global differentiability [GOAL] f : ℝ → ℝ hf : Monotone f x : ℝ hx : Tendsto (fun b => (↑(stieltjesFunction hf) b - f x) / (b - x)) (𝓝[Iio x] x) (𝓝 (ENNReal.toReal (rnDeriv (StieltjesFunction.measure (stieltjesFunction hf)) volume x))) ∧ Tendsto (fun b => (↑(stieltjesFunction hf) b - f x) / (b - x)) (𝓝[Ioi x] x) (𝓝 (ENNReal.toReal (rnDeriv (StieltjesFunction.measure (stieltjesFunction hf)) volume x))) h'x : ¬¬ContinuousAt f x A : ↑(stieltjesFunction hf) x = f x L1 : Tendsto (fun y => (f y - f x) / (y - x)) (𝓝[Ioi x] x) (𝓝 (ENNReal.toReal (rnDeriv (StieltjesFunction.measure (stieltjesFunction hf)) volume x))) this✝ : Tendsto (fun y => (↑(stieltjesFunction hf) (y + -↑1 * (y - x) ^ 2) - f x) / (y - x)) (𝓝[Iio x] x) (𝓝 (ENNReal.toReal (rnDeriv (StieltjesFunction.measure (stieltjesFunction hf)) volume x))) y : ℝ hy : y < x this : 0 < (y - x) ^ 2 ⊢ y + -↑1 * (y - x) ^ 2 < y [PROOFSTEP] norm_num [GOAL] f : ℝ → ℝ hf : Monotone f x : ℝ hx : Tendsto (fun b => (↑(stieltjesFunction hf) b - f x) / (b - x)) (𝓝[Iio x] x) (𝓝 (ENNReal.toReal (rnDeriv (StieltjesFunction.measure (stieltjesFunction hf)) volume x))) ∧ Tendsto (fun b => (↑(stieltjesFunction hf) b - f x) / (b - x)) (𝓝[Ioi x] x) (𝓝 (ENNReal.toReal (rnDeriv (StieltjesFunction.measure (stieltjesFunction hf)) volume x))) h'x : ¬¬ContinuousAt f x A : ↑(stieltjesFunction hf) x = f x L1 : Tendsto (fun y => (f y - f x) / (y - x)) (𝓝[Ioi x] x) (𝓝 (ENNReal.toReal (rnDeriv (StieltjesFunction.measure (stieltjesFunction hf)) volume x))) this✝ : Tendsto (fun y => (↑(stieltjesFunction hf) (y + -↑1 * (y - x) ^ 2) - f x) / (y - x)) (𝓝[Iio x] x) (𝓝 (ENNReal.toReal (rnDeriv (StieltjesFunction.measure (stieltjesFunction hf)) volume x))) y : ℝ hy : y < x this : 0 < (y - x) ^ 2 ⊢ 0 < (y - x) ^ 2 [PROOFSTEP] linarith [GOAL] case h f : ℝ → ℝ hf : Monotone f x : ℝ hx : Tendsto (fun b => (↑(stieltjesFunction hf) b - f x) / (b - x)) (𝓝[Iio x] x) (𝓝 (ENNReal.toReal (rnDeriv (StieltjesFunction.measure (stieltjesFunction hf)) volume x))) ∧ Tendsto (fun b => (↑(stieltjesFunction hf) b - f x) / (b - x)) (𝓝[Ioi x] x) (𝓝 (ENNReal.toReal (rnDeriv (StieltjesFunction.measure (stieltjesFunction hf)) volume x))) h'x : ¬¬ContinuousAt f x A : ↑(stieltjesFunction hf) x = f x L1 : Tendsto (fun y => (f y - f x) / (y - x)) (𝓝[Ioi x] x) (𝓝 (ENNReal.toReal (rnDeriv (StieltjesFunction.measure (stieltjesFunction hf)) volume x))) L2 : Tendsto (fun y => (f y - f x) / (y - x)) (𝓝[Iio x] x) (𝓝 (ENNReal.toReal (rnDeriv (StieltjesFunction.measure (stieltjesFunction hf)) volume x))) ⊢ HasDerivAt f (ENNReal.toReal (rnDeriv (StieltjesFunction.measure (stieltjesFunction hf)) volume x)) x [PROOFSTEP] rw [hasDerivAt_iff_tendsto_slope, slope_fun_def_field, (nhds_left'_sup_nhds_right' x).symm, tendsto_sup] [GOAL] case h f : ℝ → ℝ hf : Monotone f x : ℝ hx : Tendsto (fun b => (↑(stieltjesFunction hf) b - f x) / (b - x)) (𝓝[Iio x] x) (𝓝 (ENNReal.toReal (rnDeriv (StieltjesFunction.measure (stieltjesFunction hf)) volume x))) ∧ Tendsto (fun b => (↑(stieltjesFunction hf) b - f x) / (b - x)) (𝓝[Ioi x] x) (𝓝 (ENNReal.toReal (rnDeriv (StieltjesFunction.measure (stieltjesFunction hf)) volume x))) h'x : ¬¬ContinuousAt f x A : ↑(stieltjesFunction hf) x = f x L1 : Tendsto (fun y => (f y - f x) / (y - x)) (𝓝[Ioi x] x) (𝓝 (ENNReal.toReal (rnDeriv (StieltjesFunction.measure (stieltjesFunction hf)) volume x))) L2 : Tendsto (fun y => (f y - f x) / (y - x)) (𝓝[Iio x] x) (𝓝 (ENNReal.toReal (rnDeriv (StieltjesFunction.measure (stieltjesFunction hf)) volume x))) ⊢ Tendsto (fun b => (f b - f x) / (b - x)) (𝓝[Iio x] x) (𝓝 (ENNReal.toReal (rnDeriv (StieltjesFunction.measure (stieltjesFunction hf)) volume x))) ∧ Tendsto (fun b => (f b - f x) / (b - x)) (𝓝[Ioi x] x) (𝓝 (ENNReal.toReal (rnDeriv (StieltjesFunction.measure (stieltjesFunction hf)) volume x))) [PROOFSTEP] exact ⟨L2, L1⟩ [GOAL] f : ℝ → ℝ hf : Monotone f ⊢ ∀ᵐ (x : ℝ), DifferentiableAt ℝ f x [PROOFSTEP] filter_upwards [hf.ae_hasDerivAt] with x hx using hx.differentiableAt [GOAL] f : ℝ → ℝ s : Set ℝ hf : MonotoneOn f s ⊢ ∀ᵐ (x : ℝ), x ∈ s → DifferentiableWithinAt ℝ f s x [PROOFSTEP] apply ae_of_mem_of_ae_of_mem_inter_Ioo [GOAL] case h f : ℝ → ℝ s : Set ℝ hf : MonotoneOn f s ⊢ ∀ (a b : ℝ), a ∈ s → b ∈ s → a < b → ∀ᵐ (x : ℝ), x ∈ s ∩ Ioo a b → DifferentiableWithinAt ℝ f s x [PROOFSTEP] intro a b as bs _ [GOAL] case h f : ℝ → ℝ s : Set ℝ hf : MonotoneOn f s a b : ℝ as : a ∈ s bs : b ∈ s a✝ : a < b ⊢ ∀ᵐ (x : ℝ), x ∈ s ∩ Ioo a b → DifferentiableWithinAt ℝ f s x [PROOFSTEP] obtain ⟨g, hg, gf⟩ : ∃ g : ℝ → ℝ, Monotone g ∧ EqOn f g (s ∩ Icc a b) := (hf.mono (inter_subset_left s (Icc a b))).exists_monotone_extension (hf.map_bddBelow (inter_subset_left _ _) ⟨a, fun x hx => hx.2.1, as⟩) (hf.map_bddAbove (inter_subset_left _ _) ⟨b, fun x hx => hx.2.2, bs⟩) [GOAL] case h.intro.intro f : ℝ → ℝ s : Set ℝ hf : MonotoneOn f s a b : ℝ as : a ∈ s bs : b ∈ s a✝ : a < b g : ℝ → ℝ hg : Monotone g gf : EqOn f g (s ∩ Icc a b) ⊢ ∀ᵐ (x : ℝ), x ∈ s ∩ Ioo a b → DifferentiableWithinAt ℝ f s x [PROOFSTEP] filter_upwards [hg.ae_differentiableAt] with x hx [GOAL] case h f : ℝ → ℝ s : Set ℝ hf : MonotoneOn f s a b : ℝ as : a ∈ s bs : b ∈ s a✝ : a < b g : ℝ → ℝ hg : Monotone g gf : EqOn f g (s ∩ Icc a b) x : ℝ hx : DifferentiableAt ℝ g x ⊢ x ∈ s ∩ Ioo a b → DifferentiableWithinAt ℝ f s x [PROOFSTEP] intro h'x [GOAL] case h f : ℝ → ℝ s : Set ℝ hf : MonotoneOn f s a b : ℝ as : a ∈ s bs : b ∈ s a✝ : a < b g : ℝ → ℝ hg : Monotone g gf : EqOn f g (s ∩ Icc a b) x : ℝ hx : DifferentiableAt ℝ g x h'x : x ∈ s ∩ Ioo a b ⊢ DifferentiableWithinAt ℝ f s x [PROOFSTEP] apply hx.differentiableWithinAt.congr_of_eventuallyEq _ (gf ⟨h'x.1, h'x.2.1.le, h'x.2.2.le⟩) [GOAL] f : ℝ → ℝ s : Set ℝ hf : MonotoneOn f s a b : ℝ as : a ∈ s bs : b ∈ s a✝ : a < b g : ℝ → ℝ hg : Monotone g gf : EqOn f g (s ∩ Icc a b) x : ℝ hx : DifferentiableAt ℝ g x h'x : x ∈ s ∩ Ioo a b ⊢ f =ᶠ[𝓝[s] x] g [PROOFSTEP] have : Ioo a b ∈ 𝓝[s] x := nhdsWithin_le_nhds (Ioo_mem_nhds h'x.2.1 h'x.2.2) [GOAL] f : ℝ → ℝ s : Set ℝ hf : MonotoneOn f s a b : ℝ as : a ∈ s bs : b ∈ s a✝ : a < b g : ℝ → ℝ hg : Monotone g gf : EqOn f g (s ∩ Icc a b) x : ℝ hx : DifferentiableAt ℝ g x h'x : x ∈ s ∩ Ioo a b this : Ioo a b ∈ 𝓝[s] x ⊢ f =ᶠ[𝓝[s] x] g [PROOFSTEP] filter_upwards [self_mem_nhdsWithin, this] with y hy h'y [GOAL] case h f : ℝ → ℝ s : Set ℝ hf : MonotoneOn f s a b : ℝ as : a ∈ s bs : b ∈ s a✝ : a < b g : ℝ → ℝ hg : Monotone g gf : EqOn f g (s ∩ Icc a b) x : ℝ hx : DifferentiableAt ℝ g x h'x : x ∈ s ∩ Ioo a b this : Ioo a b ∈ 𝓝[s] x y : ℝ hy : y ∈ s h'y : y ∈ Ioo a b ⊢ f y = g y [PROOFSTEP] exact gf ⟨hy, h'y.1.le, h'y.2.le⟩ [GOAL] f : ℝ → ℝ s : Set ℝ hf : MonotoneOn f s hs : MeasurableSet s ⊢ ∀ᵐ (x : ℝ) ∂Measure.restrict volume s, DifferentiableWithinAt ℝ f s x [PROOFSTEP] rw [ae_restrict_iff' hs] [GOAL] f : ℝ → ℝ s : Set ℝ hf : MonotoneOn f s hs : MeasurableSet s ⊢ ∀ᵐ (x : ℝ), x ∈ s → DifferentiableWithinAt ℝ f s x [PROOFSTEP] exact hf.ae_differentiableWithinAt_of_mem
(** * LogRel.NormalForms: definition of normal and neutral forms, and properties. *) From LogRel.AutoSubst Require Import core unscoped Ast Extra. From LogRel Require Import Utils BasicAst Context. (** ** Weak-head normal forms and neutrals. *) Inductive whnf : term -> Type := | whnf_tSort {s} : whnf (tSort s) | whnf_tProd {A B} : whnf (tProd A B) | whnf_tLambda {A t} : whnf (tLambda A t) | whnf_tNat : whnf tNat | whnf_tZero : whnf tZero | whnf_tSucc {n} : whnf (tSucc n) | whnf_tEmpty : whnf tEmpty | whnf_whne {n} : whne n -> whnf n with whne : term -> Type := | whne_tRel {v} : whne (tRel v) | whne_tApp {n t} : whne n -> whne (tApp n t) | whne_tNatElim {P hz hs n} : whne n -> whne (tNatElim P hz hs n) | whne_tEmptyElim {P e} : whne e -> whne (tEmptyElim P e). #[global] Hint Constructors whne whnf : gen_typing. Ltac inv_whne := repeat lazymatch goal with | H : whne _ |- _ => try solve [inversion H] ; block H end; unblock. Lemma neSort s : whne (tSort s) -> False. Proof. inversion 1. Qed. Lemma nePi A B : whne (tProd A B) -> False. Proof. inversion 1. Qed. Lemma neLambda A t : whne (tLambda A t) -> False. Proof. inversion 1. Qed. #[global] Hint Resolve neSort nePi neLambda : gen_typing. (** ** Restricted classes of normal forms *) Inductive isType : term -> Type := | UnivType {s} : isType (tSort s) | ProdType { A B} : isType (tProd A B) | NatType : isType tNat | EmptyType : isType tEmpty | NeType {A} : whne A -> isType A. Inductive isPosType : term -> Type := | UnivPos {s} : isPosType (tSort s) | NatPos : isPosType tNat | EmptyPos : isPosType tEmpty | NePos {A} : whne A -> isPosType A. Inductive isFun : term -> Type := | LamFun {A t} : isFun (tLambda A t) | NeFun {f} : whne f -> isFun f. Definition isPosType_isType t (i : isPosType t) : isType t := match i with | UnivPos => UnivType | NatPos => NatType | EmptyPos => EmptyType | NePos ne => NeType ne end. Coercion isPosType_isType : isPosType >-> isType. Definition isType_whnf t (i : isType t) : whnf t := match i with | UnivType => whnf_tSort | ProdType => whnf_tProd | NatType => whnf_tNat | EmptyType => whnf_tEmpty | NeType ne => whnf_whne ne end. Coercion isType_whnf : isType >-> whnf. Definition isFun_whnf t (i : isFun t) : whnf t := match i with | LamFun => whnf_tLambda | NeFun ne => whnf_whne ne end. Coercion isFun_whnf : isFun >-> whnf. #[global] Hint Resolve isPosType_isType isType_whnf isFun_whnf : gen_typing.
using MPFR_wrap const atol = BigFloat("1e-100000") const prec = 333_000 const π_MPFR = BigFloat(π, prec) function brent_salamin() old_prec = precision(BigFloat) setprecision(BigFloat, prec) a_prev, b_prev = big(1.0), 1 / sqrt(big(2.0)) s_prev, π_prev = big(1.0) / 2, big(4.0) π_next = BigFloat() k, p2 = 1, big(2) while true a_next = (a_prev + b_prev) / 2 b_next = sqrt(a_prev * b_prev) c_next = (a_next - b_next) * (a_next + b_next) s_next = s_prev - p2 * c_next π_next = 2a_next^2 / s_next #println("$k -> $pn") δπ = π_next - π_prev abs(δπ) ≤ atol && break a_prev, b_prev, s_prev, π_prev = a_next, b_next, s_next, π_next k += 1 p2 *= 2 end setprecision(BigFloat, old_prec) @assert isapprox(π_next, π_MPFR, atol=atol) (k, π_next) end function inplace_brent_salamin() a_prev = BigFloat(1, precision=prec) b_prev = BigFloat(2, precision=prec) rec_sqrt!(b_prev, b_prev) s_prev = BigFloat(0.5, precision=prec) π_prev = BigFloat(4, precision=prec) a_next = BigFloat(precision=prec) b_next = BigFloat(precision=prec) c_next = BigFloat(precision=prec) s_next = BigFloat(precision=prec) π_next = BigFloat(precision=prec) δπ = BigFloat(precision=prec) k = Int32(1) while true add!(a_next, a_prev, b_prev) div_2!(a_next, a_next, Int32(1)) mul!(b_next, a_prev, b_prev) sqrt!(b_next, b_next) sub!(c_next, a_prev, a_next) sqr!(c_next, c_next) mul_2!(c_next, c_next, k) sub!(s_next, s_prev, c_next) sqr!(π_next, a_next) mul_2!(π_next, π_next, Int32(1)) div!(π_next, π_next, s_next) sub!(δπ, π_next, π_prev) abs(δπ) ≤ atol && break a_prev, a_next = a_next, a_prev b_prev, b_next = b_next, b_prev s_prev, s_next = s_next, s_prev π_prev, π_next = π_next, π_prev k += Int32(1) end @assert isapprox(π_next, π_MPFR, atol=atol) (k, π_next) end function inplace_borwein_cubic() a_prev = BigFloat(1, precision=prec) div!(a_prev, a_prev, Int32(3)) s_prev = BigFloat(3, precision=prec) sqrt!(s_prev, s_prev) sub!(s_prev, s_prev, Int32(1)) div_2!(s_prev, s_prev, Int32(1)) r_next = BigFloat(precision=prec) s_next = BigFloat(precision=prec) rsq_next = BigFloat(precision=prec) a_next = BigFloat(precision=prec) tmp = BigFloat(precision=prec) π_prev = BigFloat(0, precision=prec) π_next = BigFloat(precision=prec) δπ = BigFloat(precision=prec) k = Int32(0) while true pow!(r_next, s_prev, Int32(3)) sub!(r_next, Int32(1), r_next) cbrt!(r_next, r_next) mul_2!(r_next, r_next, Int32(1)) add!(r_next, r_next, Int32(1)) div!(r_next, Int32(3), r_next) sub!(s_next, r_next, Int32(1)) div_2!(s_next, s_next, Int32(1)) sqr!(rsq_next, r_next) sub!(tmp, rsq_next, Int32(1)) mul!(tmp, tmp, Int32(3)^k) mul!(a_next, rsq_next, a_prev) sub!(a_next, a_next, tmp) div!(π_next, Int32(1), a_next) sub!(δπ, π_next, π_prev) abs(δπ) ≤ atol && break a_prev, a_next = a_next, a_prev s_prev, s_next = s_next, s_prev π_prev, π_next = π_next, π_prev k += Int32(1) end @assert isapprox(π_next, π_MPFR, atol=atol) (k, π_next) end
State Before: ι : Type ?u.498342 β : Type u α : Type v γ : Type w s✝ s₁ s₂ : Finset α a : α f g : α → β inst✝² : CommMonoid β inst✝¹ : DecidableEq α inst✝ : CommMonoid α m : List α s : Finset α hs : toFinset m ⊆ s ⊢ prod m = ∏ i in s, i ^ count i m State After: ι : Type ?u.498342 β : Type u α : Type v γ : Type w s✝ s₁ s₂ : Finset α a : α f g : α → β inst✝² : CommMonoid β inst✝¹ : DecidableEq α inst✝ : CommMonoid α m : List α s : Finset α hs : toFinset m ⊆ s ⊢ ∏ m_1 in toFinset m, m_1 ^ count m_1 m = ∏ i in s, i ^ count i m Tactic: rw [prod_list_count] State Before: ι : Type ?u.498342 β : Type u α : Type v γ : Type w s✝ s₁ s₂ : Finset α a : α f g : α → β inst✝² : CommMonoid β inst✝¹ : DecidableEq α inst✝ : CommMonoid α m : List α s : Finset α hs : toFinset m ⊆ s ⊢ ∏ m_1 in toFinset m, m_1 ^ count m_1 m = ∏ i in s, i ^ count i m State After: ι : Type ?u.498342 β : Type u α : Type v γ : Type w s✝ s₁ s₂ : Finset α a : α f g : α → β inst✝² : CommMonoid β inst✝¹ : DecidableEq α inst✝ : CommMonoid α m : List α s : Finset α hs : toFinset m ⊆ s x : α x✝ : x ∈ s hx : ¬x ∈ toFinset m ⊢ x ^ count x m = 1 Tactic: refine' prod_subset hs fun x _ hx => _ State Before: ι : Type ?u.498342 β : Type u α : Type v γ : Type w s✝ s₁ s₂ : Finset α a : α f g : α → β inst✝² : CommMonoid β inst✝¹ : DecidableEq α inst✝ : CommMonoid α m : List α s : Finset α hs : toFinset m ⊆ s x : α x✝ : x ∈ s hx : ¬x ∈ toFinset m ⊢ x ^ count x m = 1 State After: ι : Type ?u.498342 β : Type u α : Type v γ : Type w s✝ s₁ s₂ : Finset α a : α f g : α → β inst✝² : CommMonoid β inst✝¹ : DecidableEq α inst✝ : CommMonoid α m : List α s : Finset α hs : toFinset m ⊆ s x : α x✝ : x ∈ s hx : ¬x ∈ m ⊢ x ^ count x m = 1 Tactic: rw [mem_toFinset] at hx State Before: ι : Type ?u.498342 β : Type u α : Type v γ : Type w s✝ s₁ s₂ : Finset α a : α f g : α → β inst✝² : CommMonoid β inst✝¹ : DecidableEq α inst✝ : CommMonoid α m : List α s : Finset α hs : toFinset m ⊆ s x : α x✝ : x ∈ s hx : ¬x ∈ m ⊢ x ^ count x m = 1 State After: no goals Tactic: rw [count_eq_zero_of_not_mem hx, pow_zero]
(* Title: Psi-calculi Author/Maintainer: Jesper Bengtson ([email protected]), 2012 *) theory Bisim_Struct_Cong imports Bisim_Pres Sim_Struct_Cong Structural_Congruence begin context env begin lemma bisimParComm: fixes \<Psi> :: 'b and P :: "('a, 'b, 'c) psi" and Q :: "('a, 'b, 'c) psi" shows "\<Psi> \<rhd> P \<parallel> Q \<sim> Q \<parallel> P" proof - let ?X = "{((\<Psi>::'b), \<lparr>\<nu>*xvec\<rparr>((P::('a, 'b, 'c) psi) \<parallel> Q), \<lparr>\<nu>*xvec\<rparr>(Q \<parallel> P)) | xvec \<Psi> P Q. xvec \<sharp>* \<Psi>}" have "eqvt ?X" by(force simp add: eqvt_def pt_fresh_star_bij[OF pt_name_inst, OF at_name_inst] eqvts) have "(\<Psi>, P \<parallel> Q, Q \<parallel> P) \<in> ?X" apply auto by(rule_tac x="[]" in exI) auto thus ?thesis proof(coinduct rule: bisimWeakCoinduct) case(cStatEq \<Psi> PQ QP) from `(\<Psi>, PQ, QP) \<in> ?X` obtain xvec P Q where PFrQ: "PQ = \<lparr>\<nu>*xvec\<rparr>(P \<parallel> Q)" and QFrP: "QP = \<lparr>\<nu>*xvec\<rparr>(Q \<parallel> P)" and "xvec \<sharp>* \<Psi>" by auto obtain A\<^sub>P \<Psi>\<^sub>P where FrP: "extractFrame P = \<langle>A\<^sub>P, \<Psi>\<^sub>P\<rangle>" and "A\<^sub>P \<sharp>* \<Psi>" and "A\<^sub>P \<sharp>* Q" by(rule_tac C="(\<Psi>, Q)" in freshFrame) auto obtain A\<^sub>Q \<Psi>\<^sub>Q where FrQ: "extractFrame Q = \<langle>A\<^sub>Q, \<Psi>\<^sub>Q\<rangle>" and "A\<^sub>Q \<sharp>* \<Psi>" and "A\<^sub>Q \<sharp>* A\<^sub>P" and "A\<^sub>Q \<sharp>* \<Psi>\<^sub>P" by(rule_tac C="(\<Psi>, A\<^sub>P, \<Psi>\<^sub>P)" in freshFrame) auto from FrQ `A\<^sub>Q \<sharp>* A\<^sub>P` `A\<^sub>P \<sharp>* Q` have "A\<^sub>P \<sharp>* \<Psi>\<^sub>Q" by(force dest: extractFrameFreshChain) have "\<langle>(xvec@A\<^sub>P@A\<^sub>Q), \<Psi> \<otimes> \<Psi>\<^sub>P \<otimes> \<Psi>\<^sub>Q\<rangle> \<simeq>\<^sub>F \<langle>(xvec@A\<^sub>Q@A\<^sub>P), \<Psi> \<otimes> \<Psi>\<^sub>Q \<otimes> \<Psi>\<^sub>P\<rangle>" by(simp add: frameChainAppend) (metis frameResChainPres frameResChainComm frameNilStatEq compositionSym Associativity Commutativity FrameStatEqTrans) with FrP FrQ PFrQ QFrP `A\<^sub>P \<sharp>* \<Psi>\<^sub>Q` `A\<^sub>Q \<sharp>* \<Psi>\<^sub>P` `A\<^sub>Q \<sharp>* A\<^sub>P` `xvec \<sharp>* \<Psi>` `A\<^sub>P \<sharp>* \<Psi>` `A\<^sub>Q \<sharp>* \<Psi>` show ?case by(auto simp add: frameChainAppend) next case(cSim \<Psi> PQ QP) from `(\<Psi>, PQ, QP) \<in> ?X` obtain xvec P Q where PFrQ: "PQ = \<lparr>\<nu>*xvec\<rparr>(P \<parallel> Q)" and QFrP: "QP = \<lparr>\<nu>*xvec\<rparr>(Q \<parallel> P)" and "xvec \<sharp>* \<Psi>" by auto moreover have "\<Psi> \<rhd> \<lparr>\<nu>*xvec\<rparr>(P \<parallel> Q) \<leadsto>[?X] \<lparr>\<nu>*xvec\<rparr>(Q \<parallel> P)" proof - have "\<Psi> \<rhd> P \<parallel> Q \<leadsto>[?X] Q \<parallel> P" proof - note `eqvt ?X` moreover have "\<And>\<Psi> P Q. (\<Psi>, P \<parallel> Q, Q \<parallel> P) \<in> ?X" apply auto by(rule_tac x="[]" in exI) auto moreover have "\<And>\<Psi> P Q xvec. \<lbrakk>(\<Psi>, P, Q) \<in> ?X; xvec \<sharp>* \<Psi>\<rbrakk> \<Longrightarrow> (\<Psi>, \<lparr>\<nu>*xvec\<rparr>P, \<lparr>\<nu>*xvec\<rparr>Q) \<in> ?X" apply(induct xvec, auto) by(rule_tac x="xvec@xveca" in exI) (auto simp add: resChainAppend) ultimately show ?thesis by(rule simParComm) qed moreover note `eqvt ?X` `xvec \<sharp>* \<Psi>` moreover have "\<And>\<Psi> P Q x. \<lbrakk>(\<Psi>, P, Q) \<in> ?X; x \<sharp> \<Psi>\<rbrakk> \<Longrightarrow> (\<Psi>, \<lparr>\<nu>x\<rparr>P, \<lparr>\<nu>x\<rparr>Q) \<in> ?X" apply auto by(rule_tac x="x#xvec" in exI) auto ultimately show ?thesis by(rule resChainPres) qed ultimately show ?case by simp next case(cExt \<Psi> PQ QP \<Psi>') from `(\<Psi>, PQ, QP) \<in> ?X` obtain xvec P Q where PFrQ: "PQ = \<lparr>\<nu>*xvec\<rparr>(P \<parallel> Q)" and QFrP: "QP = \<lparr>\<nu>*xvec\<rparr>(Q \<parallel> P)" and "xvec \<sharp>* \<Psi>" by auto obtain p where "(p \<bullet> xvec) \<sharp>* \<Psi>" and "(p \<bullet> xvec) \<sharp>* P" and "(p \<bullet> xvec) \<sharp>* Q" and "(p \<bullet> xvec) \<sharp>* \<Psi>'" and S: "(set p) \<subseteq> (set xvec) \<times> (set(p \<bullet> xvec))" and "distinctPerm p" by(rule_tac c="(\<Psi>, P, Q, \<Psi>')" in name_list_avoiding) auto from `(p \<bullet> xvec) \<sharp>* P` `(p \<bullet> xvec) \<sharp>* Q` S have "\<lparr>\<nu>*xvec\<rparr>(P \<parallel> Q) = \<lparr>\<nu>*(p \<bullet> xvec)\<rparr>(p \<bullet> (P \<parallel> Q))" by(subst resChainAlpha) auto hence PQAlpha: "\<lparr>\<nu>*xvec\<rparr>(P \<parallel> Q) = \<lparr>\<nu>*(p \<bullet> xvec)\<rparr>((p \<bullet> P) \<parallel> (p \<bullet> Q))" by(simp add: eqvts) from `(p \<bullet> xvec) \<sharp>* P` `(p \<bullet> xvec) \<sharp>* Q` S have "\<lparr>\<nu>*xvec\<rparr>(Q \<parallel> P) = \<lparr>\<nu>*(p \<bullet> xvec)\<rparr>(p \<bullet> (Q \<parallel> P))" by(subst resChainAlpha) auto hence QPAlpha: "\<lparr>\<nu>*xvec\<rparr>(Q \<parallel> P) = \<lparr>\<nu>*(p \<bullet> xvec)\<rparr>((p \<bullet> Q) \<parallel> (p \<bullet> P))" by(simp add: eqvts) from `(p \<bullet> xvec) \<sharp>* \<Psi>` `(p \<bullet> xvec) \<sharp>* \<Psi>'` have "(\<Psi> \<otimes> \<Psi>', \<lparr>\<nu>*(p \<bullet> xvec)\<rparr>((p \<bullet> P) \<parallel> (p \<bullet> Q)), \<lparr>\<nu>*(p \<bullet> xvec)\<rparr>((p \<bullet> Q) \<parallel> (p \<bullet> P))) \<in> ?X" by auto with PFrQ QFrP PQAlpha QPAlpha show ?case by simp next case(cSym \<Psi> PR QR) thus ?case by blast qed qed lemma bisimResComm: fixes x :: name and \<Psi> :: 'b and y :: name and P :: "('a, 'b, 'c) psi" shows "\<Psi> \<rhd> \<lparr>\<nu>x\<rparr>(\<lparr>\<nu>y\<rparr>P) \<sim> \<lparr>\<nu>y\<rparr>(\<lparr>\<nu>x\<rparr>P)" proof(cases "x=y") case True thus ?thesis by(blast intro: bisimReflexive) next case False { fix x::name and y::name and P::"('a, 'b, 'c) psi" assume "x \<sharp> \<Psi>" and "y \<sharp> \<Psi>" let ?X = "{((\<Psi>::'b), \<lparr>\<nu>x\<rparr>(\<lparr>\<nu>y\<rparr>(P::('a, 'b, 'c) psi)), \<lparr>\<nu>y\<rparr>(\<lparr>\<nu>x\<rparr>P)) | \<Psi> x y P. x \<sharp> \<Psi> \<and> y \<sharp> \<Psi>}" from `x \<sharp> \<Psi>` `y \<sharp> \<Psi>` have "(\<Psi>, \<lparr>\<nu>x\<rparr>(\<lparr>\<nu>y\<rparr>P), \<lparr>\<nu>y\<rparr>(\<lparr>\<nu>x\<rparr>P)) \<in> ?X" by auto hence "\<Psi> \<rhd> \<lparr>\<nu>x\<rparr>(\<lparr>\<nu>y\<rparr>P) \<sim> \<lparr>\<nu>y\<rparr>(\<lparr>\<nu>x\<rparr>P)" proof(coinduct rule: bisimCoinduct) case(cStatEq \<Psi> xyP yxP) from `(\<Psi>, xyP, yxP) \<in> ?X` obtain x y P where "x \<sharp> \<Psi>" and "y \<sharp> \<Psi>" and "xyP = \<lparr>\<nu>x\<rparr>(\<lparr>\<nu>y\<rparr>P)" and "yxP = \<lparr>\<nu>y\<rparr>(\<lparr>\<nu>x\<rparr>P)" by auto moreover obtain A\<^sub>P \<Psi>\<^sub>P where "extractFrame P = \<langle>A\<^sub>P, \<Psi>\<^sub>P\<rangle>" and "A\<^sub>P \<sharp>* \<Psi>" and "x \<sharp> A\<^sub>P" and "y \<sharp> A\<^sub>P" by(rule_tac C="(x, y, \<Psi>)" in freshFrame) auto ultimately show ?case by(force intro: frameResComm FrameStatEqTrans) next case(cSim \<Psi> xyP yxP) from `(\<Psi>, xyP, yxP) \<in> ?X` obtain x y P where "x \<sharp> \<Psi>" and "y \<sharp> \<Psi>" and "xyP = \<lparr>\<nu>x\<rparr>(\<lparr>\<nu>y\<rparr>P)" and "yxP = \<lparr>\<nu>y\<rparr>(\<lparr>\<nu>x\<rparr>P)" by auto note `x \<sharp> \<Psi>` `y \<sharp> \<Psi>` moreover have "eqvt ?X" by(force simp add: eqvt_def pt_fresh_bij[OF pt_name_inst, OF at_name_inst]) hence "eqvt(?X \<union> bisim)" by auto moreover have "\<And>\<Psi> P. (\<Psi>, P, P) \<in> ?X \<union> bisim" by(blast intro: bisimReflexive) moreover have "\<And>\<Psi> x y P. \<lbrakk>x \<sharp> \<Psi>; y \<sharp> \<Psi>\<rbrakk> \<Longrightarrow> (\<Psi>, \<lparr>\<nu>x\<rparr>(\<lparr>\<nu>y\<rparr>P), \<lparr>\<nu>y\<rparr>(\<lparr>\<nu>x\<rparr>P)) \<in> ?X \<union> bisim" by auto ultimately have "\<Psi> \<rhd> \<lparr>\<nu>x\<rparr>(\<lparr>\<nu>y\<rparr>P) \<leadsto>[(?X \<union> bisim)] \<lparr>\<nu>y\<rparr>(\<lparr>\<nu>x\<rparr>P)" by(rule resComm) with `xyP = \<lparr>\<nu>x\<rparr>(\<lparr>\<nu>y\<rparr>P)` `yxP = \<lparr>\<nu>y\<rparr>(\<lparr>\<nu>x\<rparr>P)` show ?case by simp next case(cExt \<Psi> xyP yxP \<Psi>') from `(\<Psi>, xyP, yxP) \<in> ?X` obtain x y P where "x \<sharp> \<Psi>" and "y \<sharp> \<Psi>" and xyPeq: "xyP = \<lparr>\<nu>x\<rparr>(\<lparr>\<nu>y\<rparr>P)" and yxPeq: "yxP = \<lparr>\<nu>y\<rparr>(\<lparr>\<nu>x\<rparr>P)" by auto show ?case proof(case_tac "x=y") assume "x = y" with xyPeq yxPeq show ?case by(blast intro: bisimReflexive) next assume "x \<noteq> y" obtain x' where "x' \<sharp> \<Psi>" and "x' \<sharp> \<Psi>'" and "x' \<noteq> x" and "x' \<noteq> y" and "x' \<sharp> P" by(generate_fresh "name") (auto simp add: fresh_prod) obtain y' where "y' \<sharp> \<Psi>" and "y' \<sharp> \<Psi>'" and "y' \<noteq> x" and "x' \<noteq> y'" and "y' \<noteq> y" and "y' \<sharp> P" by(generate_fresh "name") (auto simp add: fresh_prod) with xyPeq `y' \<sharp> P` `x' \<sharp> P` `x \<noteq> y` `x' \<noteq> y` `y' \<noteq> x` have "\<lparr>\<nu>x\<rparr>(\<lparr>\<nu>y\<rparr>P) = \<lparr>\<nu>x'\<rparr>(\<lparr>\<nu>y'\<rparr>([(x, x')] \<bullet> [(y, y')] \<bullet> P))" apply(subst alphaRes[of x']) apply(simp add: abs_fresh) by(subst alphaRes[of y' _ y]) (auto simp add: eqvts calc_atm) moreover with yxPeq `y' \<sharp> P` `x' \<sharp> P` `x \<noteq> y` `x' \<noteq> y` `y' \<noteq> x` `x' \<noteq> y'` have "\<lparr>\<nu>y\<rparr>(\<lparr>\<nu>x\<rparr>P) = \<lparr>\<nu>y'\<rparr>(\<lparr>\<nu>x'\<rparr>([(y, y')] \<bullet> [(x, x')] \<bullet> P))" apply(subst alphaRes[of y']) apply(simp add: abs_fresh) by(subst alphaRes[of x' _ x]) (auto simp add: eqvts calc_atm) with `x \<noteq> y` `x' \<noteq> y` `y' \<noteq> y` `x' \<noteq> x` `y' \<noteq> x` `x' \<noteq> y'` have "\<lparr>\<nu>y\<rparr>(\<lparr>\<nu>x\<rparr>P) = \<lparr>\<nu>y'\<rparr>(\<lparr>\<nu>x'\<rparr>([(x, x')] \<bullet> [(y, y')] \<bullet> P))" by(subst perm_compose) (simp add: calc_atm) moreover from `x' \<sharp> \<Psi>` `x' \<sharp> \<Psi>'` `y' \<sharp> \<Psi>` `y' \<sharp> \<Psi>'` have "(\<Psi> \<otimes> \<Psi>', \<lparr>\<nu>x'\<rparr>(\<lparr>\<nu>y'\<rparr>([(x, x')] \<bullet> [(y, y')] \<bullet> P)), \<lparr>\<nu>y'\<rparr>(\<lparr>\<nu>x'\<rparr>([(x, x')] \<bullet> [(y, y')] \<bullet> P))) \<in> ?X" by auto ultimately show ?case using xyPeq yxPeq by simp qed next case(cSym \<Psi> xyP yxP) thus ?case by auto qed } moreover obtain x'::name where "x' \<sharp> \<Psi>" and "x' \<sharp> P" and "x' \<noteq> x" and "x' \<noteq> y" by(generate_fresh "name") auto moreover obtain y'::name where "y' \<sharp> \<Psi>" and "y' \<sharp> P" and "y' \<noteq> x" and "y' \<noteq> y" and "y' \<noteq> x'" by(generate_fresh "name") auto ultimately have "\<Psi> \<rhd> \<lparr>\<nu>x'\<rparr>(\<lparr>\<nu>y'\<rparr>([(y, y'), (x, x')] \<bullet> P)) \<sim> \<lparr>\<nu>y'\<rparr>(\<lparr>\<nu>x'\<rparr>([(y, y'), (x, x')] \<bullet> P))" by auto thus ?thesis using `x' \<sharp> P` `x' \<noteq> x` `x' \<noteq> y` `y' \<sharp> P` `y' \<noteq> x` `y' \<noteq> y` `y' \<noteq> x'` `x \<noteq> y` apply(subst alphaRes[where x=x and y=x' and P=P], auto) apply(subst alphaRes[where x=y and y=y' and P=P], auto) apply(subst alphaRes[where x=x and y=x' and P="\<lparr>\<nu>y'\<rparr>([(y, y')] \<bullet> P)"], auto simp add: abs_fresh fresh_left) apply(subst alphaRes[where x=y and y=y' and P="\<lparr>\<nu>x'\<rparr>([(x, x')] \<bullet> P)"], auto simp add: abs_fresh fresh_left) by(subst perm_compose) (simp add: eqvts calc_atm) qed lemma bisimResComm': fixes x :: name and \<Psi> :: 'b and xvec :: "name list" and P :: "('a, 'b, 'c) psi" assumes "x \<sharp> \<Psi>" and "xvec \<sharp>* \<Psi>" shows "\<Psi> \<rhd> \<lparr>\<nu>x\<rparr>(\<lparr>\<nu>*xvec\<rparr>P) \<sim> \<lparr>\<nu>*xvec\<rparr>(\<lparr>\<nu>x\<rparr>P)" using assms by(induct xvec) (auto intro: bisimResComm bisimReflexive bisimResPres bisimTransitive) lemma bisimScopeExt: fixes x :: name and \<Psi> :: 'b and P :: "('a, 'b, 'c) psi" and Q :: "('a, 'b, 'c) psi" assumes "x \<sharp> P" shows "\<Psi> \<rhd> \<lparr>\<nu>x\<rparr>(P \<parallel> Q) \<sim> P \<parallel> \<lparr>\<nu>x\<rparr>Q" proof - { fix x::name and Q :: "('a, 'b, 'c) psi" assume "x \<sharp> \<Psi>" and "x \<sharp> P" let ?X1 = "{((\<Psi>::'b), \<lparr>\<nu>*xvec\<rparr>(\<lparr>\<nu>x\<rparr>((P::('a, 'b, 'c) psi) \<parallel> Q)), \<lparr>\<nu>*xvec\<rparr>(P \<parallel> \<lparr>\<nu>x\<rparr>Q)) | \<Psi> xvec x P Q. x \<sharp> \<Psi> \<and> x \<sharp> P \<and> xvec \<sharp>* \<Psi>}" let ?X2 = "{((\<Psi>::'b), \<lparr>\<nu>*xvec\<rparr>((P::('a, 'b, 'c) psi) \<parallel> \<lparr>\<nu>x\<rparr>Q), \<lparr>\<nu>*xvec\<rparr>(\<lparr>\<nu>x\<rparr>(P \<parallel> Q))) | \<Psi> xvec x P Q. x \<sharp> \<Psi> \<and> x \<sharp> P \<and> xvec \<sharp>* \<Psi>}" let ?X = "?X1 \<union> ?X2" from `x \<sharp> \<Psi>` `x \<sharp> P` have "(\<Psi>, \<lparr>\<nu>x\<rparr>(P \<parallel> Q), P \<parallel> \<lparr>\<nu>x\<rparr>Q) \<in> ?X" by(auto, rule_tac x="[]" in exI) (auto simp add: fresh_list_nil) moreover have "eqvt ?X" by(rule eqvtUnion) (fastforce simp add: eqvt_def eqvts pt_fresh_star_bij[OF pt_name_inst, OF at_name_inst] pt_fresh_bij[OF pt_name_inst, OF at_name_inst])+ ultimately have "\<Psi> \<rhd> \<lparr>\<nu>x\<rparr>(P \<parallel> Q) \<sim> P \<parallel> \<lparr>\<nu>x\<rparr>Q" proof(coinduct rule: transitiveCoinduct) case(cStatEq \<Psi> R T) show ?case proof(case_tac "(\<Psi>, R, T) \<in> ?X1") assume "(\<Psi>, R, T) \<in> ?X1" then obtain xvec x P Q where "R = \<lparr>\<nu>*xvec\<rparr>(\<lparr>\<nu>x\<rparr>(P \<parallel> Q))" and "T = \<lparr>\<nu>*xvec\<rparr>(P \<parallel> \<lparr>\<nu>x\<rparr>Q)" and "xvec \<sharp>* \<Psi>" and "x \<sharp> P" and "x \<sharp> \<Psi>" by auto moreover obtain A\<^sub>P \<Psi>\<^sub>P where FrP: "extractFrame P = \<langle>A\<^sub>P, \<Psi>\<^sub>P\<rangle>" and "A\<^sub>P \<sharp>* \<Psi>" and "x \<sharp> A\<^sub>P" and "A\<^sub>P \<sharp>* Q" by(rule_tac C="(\<Psi>, x, Q)" in freshFrame) auto moreover obtain A\<^sub>Q \<Psi>\<^sub>Q where FrQ: "extractFrame Q = \<langle>A\<^sub>Q, \<Psi>\<^sub>Q\<rangle>" and "A\<^sub>Q \<sharp>* \<Psi>" and "x \<sharp> A\<^sub>Q" and "A\<^sub>Q \<sharp>* A\<^sub>P" and "A\<^sub>Q \<sharp>* \<Psi>\<^sub>P" by(rule_tac C="(\<Psi>, x, A\<^sub>P, \<Psi>\<^sub>P)" in freshFrame) auto moreover from FrQ `A\<^sub>P \<sharp>* Q` `A\<^sub>Q \<sharp>* A\<^sub>P` have "A\<^sub>P \<sharp>* \<Psi>\<^sub>Q" by(drule_tac extractFrameFreshChain) auto moreover from `x \<sharp> P` `x \<sharp> A\<^sub>P` FrP have "x \<sharp> \<Psi>\<^sub>P" by(drule_tac extractFrameFresh) auto ultimately show ?case by(force simp add: frameChainAppend intro: frameResComm' FrameStatEqTrans frameResChainPres) next assume "(\<Psi>, R, T) \<notin> ?X1" with `(\<Psi>, R, T) \<in> ?X` have "(\<Psi>, R, T) \<in> ?X2" by blast then obtain xvec x P Q where "T = \<lparr>\<nu>*xvec\<rparr>(\<lparr>\<nu>x\<rparr>(P \<parallel> Q))" and "R = \<lparr>\<nu>*xvec\<rparr>(P \<parallel> \<lparr>\<nu>x\<rparr>Q)" and "xvec \<sharp>* \<Psi>" and "x \<sharp> P" and "x \<sharp> \<Psi>" by auto moreover obtain A\<^sub>P \<Psi>\<^sub>P where FrP: "extractFrame P = \<langle>A\<^sub>P, \<Psi>\<^sub>P\<rangle>" and "A\<^sub>P \<sharp>* \<Psi>" and "x \<sharp> A\<^sub>P" and "A\<^sub>P \<sharp>* Q" by(rule_tac C="(\<Psi>, x, Q)" in freshFrame) auto moreover obtain A\<^sub>Q \<Psi>\<^sub>Q where FrQ: "extractFrame Q = \<langle>A\<^sub>Q, \<Psi>\<^sub>Q\<rangle>" and "A\<^sub>Q \<sharp>* \<Psi>" and "x \<sharp> A\<^sub>Q" and "A\<^sub>Q \<sharp>* A\<^sub>P" and "A\<^sub>Q \<sharp>* \<Psi>\<^sub>P" by(rule_tac C="(\<Psi>, x, A\<^sub>P, \<Psi>\<^sub>P)" in freshFrame) auto moreover from FrQ `A\<^sub>P \<sharp>* Q` `A\<^sub>Q \<sharp>* A\<^sub>P` have "A\<^sub>P \<sharp>* \<Psi>\<^sub>Q" by(drule_tac extractFrameFreshChain) auto moreover from `x \<sharp> P` `x \<sharp> A\<^sub>P` FrP have "x \<sharp> \<Psi>\<^sub>P" by(drule_tac extractFrameFresh) auto ultimately show ?case apply auto by(force simp add: frameChainAppend intro: frameResComm' FrameStatEqTrans frameResChainPres FrameStatEqSym) qed next case(cSim \<Psi> R T) let ?Y = "{(\<Psi>, P, Q) | \<Psi> P P' Q' Q. \<Psi> \<rhd> P \<sim> P' \<and> ((\<Psi>, P', Q') \<in> ?X \<or> \<Psi> \<rhd> P' \<sim> Q') \<and> \<Psi> \<rhd> Q' \<sim> Q}" from `eqvt ?X` have "eqvt ?Y" by blast have C1: "\<And>\<Psi> R T y. \<lbrakk>(\<Psi>, R, T) \<in> ?Y; (y::name) \<sharp> \<Psi>\<rbrakk> \<Longrightarrow> (\<Psi>, \<lparr>\<nu>y\<rparr>R, \<lparr>\<nu>y\<rparr>T) \<in> ?Y" proof - fix \<Psi> R T y assume "(\<Psi>, R, T) \<in> ?Y" then obtain R' T' where "\<Psi> \<rhd> R \<sim> R'" and "(\<Psi>, R', T') \<in> (?X \<union> bisim)" and "\<Psi> \<rhd> T' \<sim> T" by fastforce assume "(y::name) \<sharp> \<Psi>" show "(\<Psi>, \<lparr>\<nu>y\<rparr>R, \<lparr>\<nu>y\<rparr>T) \<in> ?Y" proof(case_tac "(\<Psi>, R', T') \<in> ?X") assume "(\<Psi>, R', T') \<in> ?X" show ?thesis proof(case_tac "(\<Psi>, R', T') \<in> ?X1") assume "(\<Psi>, R', T') \<in> ?X1" then obtain xvec x P Q where R'eq: "R' = \<lparr>\<nu>*xvec\<rparr>(\<lparr>\<nu>x\<rparr>(P \<parallel> Q))" and T'eq: "T' = \<lparr>\<nu>*xvec\<rparr>(P \<parallel> \<lparr>\<nu>x\<rparr>Q)" and "xvec \<sharp>* \<Psi>" and "x \<sharp> P" and "x \<sharp> \<Psi>" by auto from `\<Psi> \<rhd> R \<sim> R'` `y \<sharp> \<Psi>` have "\<Psi> \<rhd> \<lparr>\<nu>y\<rparr>R \<sim> \<lparr>\<nu>y\<rparr>R'" by(rule bisimResPres) moreover from `xvec \<sharp>* \<Psi>` `y \<sharp> \<Psi>` `x \<sharp> P` `x \<sharp> \<Psi>` have "(\<Psi>, \<lparr>\<nu>*(y#xvec)\<rparr>\<lparr>\<nu>x\<rparr>(P \<parallel> Q), \<lparr>\<nu>*(y#xvec)\<rparr>(P \<parallel> \<lparr>\<nu>x\<rparr>Q)) \<in> ?X1" by(force simp del: resChain.simps) with R'eq T'eq have "(\<Psi>, \<lparr>\<nu>y\<rparr>R', \<lparr>\<nu>y\<rparr>T') \<in> ?X \<union> bisim" by simp moreover from `\<Psi> \<rhd> T' \<sim> T` `y \<sharp> \<Psi>` have "\<Psi> \<rhd> \<lparr>\<nu>y\<rparr>T' \<sim> \<lparr>\<nu>y\<rparr>T" by(rule bisimResPres) ultimately show ?thesis by blast next assume "(\<Psi>, R', T') \<notin> ?X1" with `(\<Psi>, R', T') \<in> ?X` have "(\<Psi>, R', T') \<in> ?X2" by blast then obtain xvec x P Q where T'eq: "T' = \<lparr>\<nu>*xvec\<rparr>(\<lparr>\<nu>x\<rparr>(P \<parallel> Q))" and R'eq: "R' = \<lparr>\<nu>*xvec\<rparr>(P \<parallel> \<lparr>\<nu>x\<rparr>Q)" and "xvec \<sharp>* \<Psi>" and "x \<sharp> P" and "x \<sharp> \<Psi>" by auto from `\<Psi> \<rhd> R \<sim> R'` `y \<sharp> \<Psi>` have "\<Psi> \<rhd> \<lparr>\<nu>y\<rparr>R \<sim> \<lparr>\<nu>y\<rparr>R'" by(rule bisimResPres) moreover from `xvec \<sharp>* \<Psi>` `y \<sharp> \<Psi>` `x \<sharp> P` `x \<sharp> \<Psi>` have "(\<Psi>, \<lparr>\<nu>*(y#xvec)\<rparr>(P \<parallel> \<lparr>\<nu>x\<rparr>Q), \<lparr>\<nu>*(y#xvec)\<rparr>(\<lparr>\<nu>x\<rparr>(P \<parallel> Q))) \<in> ?X2" by(force simp del: resChain.simps) with R'eq T'eq have "(\<Psi>, \<lparr>\<nu>y\<rparr>R', \<lparr>\<nu>y\<rparr>T') \<in> ?X \<union> bisim" by simp moreover from `\<Psi> \<rhd> T' \<sim> T` `y \<sharp> \<Psi>` have "\<Psi> \<rhd> \<lparr>\<nu>y\<rparr>T' \<sim> \<lparr>\<nu>y\<rparr>T" by(rule bisimResPres) ultimately show ?thesis by blast qed next assume "(\<Psi>, R', T') \<notin> ?X" with `(\<Psi>, R', T') \<in> ?X \<union> bisim` have "\<Psi> \<rhd> R' \<sim> T'" by blast with `\<Psi> \<rhd> R \<sim> R'` `\<Psi> \<rhd> T' \<sim> T` `y \<sharp> \<Psi>` show ?thesis by(blast dest: bisimResPres) qed qed show ?case proof(case_tac "(\<Psi>, R, T) \<in> ?X1") assume "(\<Psi>, R, T) \<in> ?X1" then obtain xvec x P Q where Req: "R = \<lparr>\<nu>*xvec\<rparr>(\<lparr>\<nu>x\<rparr>(P \<parallel> Q))" and Teq: "T = \<lparr>\<nu>*xvec\<rparr>(P \<parallel> \<lparr>\<nu>x\<rparr>Q)" and "xvec \<sharp>* \<Psi>" and "x \<sharp> P" and "x \<sharp> \<Psi>" by auto have "\<Psi> \<rhd> \<lparr>\<nu>*xvec\<rparr>(\<lparr>\<nu>x\<rparr>(P \<parallel> Q)) \<leadsto>[?Y] \<lparr>\<nu>*xvec\<rparr>(P \<parallel> \<lparr>\<nu>x\<rparr>Q)" proof - have "\<Psi> \<rhd> \<lparr>\<nu>x\<rparr>(P \<parallel> Q) \<leadsto>[?Y] P \<parallel> \<lparr>\<nu>x\<rparr>Q" proof - note `x \<sharp> P` `x \<sharp> \<Psi>` `eqvt ?Y` moreover have "\<And>\<Psi> P. (\<Psi>, P, P) \<in> ?Y" by(blast intro: bisimReflexive) moreover have "\<And>x \<Psi> P Q xvec. \<lbrakk>x \<sharp> \<Psi>; x \<sharp> P; xvec \<sharp>* \<Psi>\<rbrakk> \<Longrightarrow> (\<Psi>, \<lparr>\<nu>x\<rparr>(\<lparr>\<nu>*xvec\<rparr>(P \<parallel> Q)), \<lparr>\<nu>*xvec\<rparr>(P \<parallel> \<lparr>\<nu>x\<rparr>Q)) \<in> ?Y" proof - fix x \<Psi> P Q xvec assume "(x::name) \<sharp> (\<Psi>::'b)" and "x \<sharp> (P::('a, 'b, 'c) psi)" and "(xvec::name list) \<sharp>* \<Psi>" from `x \<sharp> \<Psi>` `xvec \<sharp>* \<Psi>` have "\<Psi> \<rhd> \<lparr>\<nu>x\<rparr>(\<lparr>\<nu>*xvec\<rparr>(P \<parallel> Q)) \<sim> \<lparr>\<nu>*xvec\<rparr>(\<lparr>\<nu>x\<rparr>(P \<parallel> Q))" by(rule bisimResComm') moreover from `xvec \<sharp>* \<Psi>` `x \<sharp> \<Psi>` `x \<sharp> P` have "(\<Psi>, \<lparr>\<nu>*xvec\<rparr>(\<lparr>\<nu>x\<rparr>(P \<parallel> Q)), \<lparr>\<nu>*xvec\<rparr>(P \<parallel> \<lparr>\<nu>x\<rparr>Q)) \<in> ?X \<union> bisim" by blast ultimately show "(\<Psi>, \<lparr>\<nu>x\<rparr>(\<lparr>\<nu>*xvec\<rparr>(P \<parallel> Q)), \<lparr>\<nu>*xvec\<rparr>(P \<parallel> \<lparr>\<nu>x\<rparr>Q)) \<in> ?Y" by(blast intro: bisimReflexive) qed moreover have "\<And>\<Psi> xvec P x. \<lbrakk>x \<sharp> \<Psi>; xvec \<sharp>* \<Psi>\<rbrakk> \<Longrightarrow> (\<Psi>, \<lparr>\<nu>x\<rparr>(\<lparr>\<nu>*xvec\<rparr>P), \<lparr>\<nu>*xvec\<rparr>(\<lparr>\<nu>x\<rparr>P)) \<in> ?Y" by(blast intro: bisimResComm' bisimReflexive) ultimately show ?thesis by(rule scopeExtLeft) qed thus ?thesis using `eqvt ?Y` `xvec \<sharp>* \<Psi>` C1 by(rule resChainPres) qed with Req Teq show ?case by simp next assume "(\<Psi>, R, T) \<notin> ?X1" with `(\<Psi>, R, T) \<in> ?X` have "(\<Psi>, R, T) \<in> ?X2" by blast then obtain xvec x P Q where Teq: "T = \<lparr>\<nu>*xvec\<rparr>(\<lparr>\<nu>x\<rparr>(P \<parallel> Q))" and Req: "R = \<lparr>\<nu>*xvec\<rparr>(P \<parallel> \<lparr>\<nu>x\<rparr>Q)" and "xvec \<sharp>* \<Psi>" and "x \<sharp> P" and "x \<sharp> \<Psi>" by auto have "\<Psi> \<rhd> \<lparr>\<nu>*xvec\<rparr>(P \<parallel> \<lparr>\<nu>x\<rparr>Q) \<leadsto>[?Y] \<lparr>\<nu>*xvec\<rparr>(\<lparr>\<nu>x\<rparr>(P \<parallel> Q))" proof - have "\<Psi> \<rhd> P \<parallel> \<lparr>\<nu>x\<rparr>Q \<leadsto>[?Y] \<lparr>\<nu>x\<rparr>(P \<parallel> Q)" proof - note `x \<sharp> P` `x \<sharp> \<Psi>` `eqvt ?Y` moreover have "\<And>\<Psi> P. (\<Psi>, P, P) \<in> ?Y" by(blast intro: bisimReflexive) moreover have "\<And>x \<Psi> P Q xvec. \<lbrakk>x \<sharp> \<Psi>; x \<sharp> P; xvec \<sharp>* \<Psi>\<rbrakk> \<Longrightarrow> (\<Psi>, \<lparr>\<nu>*xvec\<rparr>(P \<parallel> \<lparr>\<nu>x\<rparr>Q), \<lparr>\<nu>x\<rparr>(\<lparr>\<nu>*xvec\<rparr>(P \<parallel> Q))) \<in> ?Y" proof - fix x \<Psi> P Q xvec assume "(x::name) \<sharp> (\<Psi>::'b)" and "x \<sharp> (P::('a, 'b, 'c) psi)" and "(xvec::name list) \<sharp>* \<Psi>" from `xvec \<sharp>* \<Psi>` `x \<sharp> \<Psi>` `x \<sharp> P` have "(\<Psi>, \<lparr>\<nu>*xvec\<rparr>(P \<parallel> \<lparr>\<nu>x\<rparr>Q), \<lparr>\<nu>*xvec\<rparr>(\<lparr>\<nu>x\<rparr>(P \<parallel> Q))) \<in> ?X \<union> bisim" by blast moreover from `x \<sharp> \<Psi>` `xvec \<sharp>* \<Psi>` have "\<Psi> \<rhd> \<lparr>\<nu>*xvec\<rparr>(\<lparr>\<nu>x\<rparr>(P \<parallel> Q)) \<sim> \<lparr>\<nu>x\<rparr>(\<lparr>\<nu>*xvec\<rparr>(P \<parallel> Q))" by(blast intro: bisimResComm' bisimE) ultimately show "(\<Psi>, \<lparr>\<nu>*xvec\<rparr>(P \<parallel> \<lparr>\<nu>x\<rparr>Q), \<lparr>\<nu>x\<rparr>(\<lparr>\<nu>*xvec\<rparr>(P \<parallel> Q))) \<in> ?Y" by(blast intro: bisimReflexive) qed ultimately show ?thesis by(rule scopeExtRight) qed thus ?thesis using `eqvt ?Y` `xvec \<sharp>* \<Psi>` C1 by(rule resChainPres) qed with Req Teq show ?case by simp qed next case(cExt \<Psi> R T \<Psi>') show ?case proof(case_tac "(\<Psi>, R, T) \<in> ?X1") assume "(\<Psi>, R, T) \<in> ?X1" then obtain xvec x P Q where Req: "R = \<lparr>\<nu>*xvec\<rparr>(\<lparr>\<nu>x\<rparr>(P \<parallel> Q))" and Teq: "T = \<lparr>\<nu>*xvec\<rparr>(P \<parallel> \<lparr>\<nu>x\<rparr>Q)" and "xvec \<sharp>* \<Psi>" and "x \<sharp> P" and "x \<sharp> \<Psi>" by auto obtain y::name where "y \<sharp> P" and "y \<sharp> Q" and "y \<sharp> xvec" and "y \<sharp> \<Psi>" and "y \<sharp> \<Psi>'" by(generate_fresh "name", auto simp add: fresh_prod) obtain p where "(p \<bullet> xvec) \<sharp>* \<Psi>" and "(p \<bullet> xvec) \<sharp>* P" and "(p \<bullet> xvec) \<sharp>* Q" and "(p \<bullet> xvec) \<sharp>* \<Psi>'" and "x \<sharp> (p \<bullet> xvec)" and "y \<sharp> (p \<bullet> xvec)" and S: "(set p) \<subseteq> (set xvec) \<times> (set(p \<bullet> xvec))" and "distinctPerm p" by(rule_tac c="(\<Psi>, P, Q, x, y, \<Psi>')" in name_list_avoiding) auto from `y \<sharp> P` have "(p \<bullet> y) \<sharp> (p \<bullet> P)" by(simp add: pt_fresh_bij[OF pt_name_inst, OF at_name_inst]) with S `y \<sharp> xvec` `y \<sharp> (p \<bullet> xvec)` have "y \<sharp> (p \<bullet> P)" by simp with `(p \<bullet> xvec) \<sharp>* \<Psi>` `y \<sharp> \<Psi>` `(p \<bullet> xvec) \<sharp>* \<Psi>'` `y \<sharp> \<Psi>'` have "(\<Psi> \<otimes> \<Psi>', \<lparr>\<nu>*(p \<bullet> xvec)\<rparr>(\<lparr>\<nu>y\<rparr>((p \<bullet> P) \<parallel> (p \<bullet> [(x, y)] \<bullet> Q))), \<lparr>\<nu>*(p \<bullet> xvec)\<rparr>((p \<bullet> P) \<parallel> (\<lparr>\<nu>y\<rparr>(p \<bullet> [(x, y)] \<bullet> Q)))) \<in> ?X" by auto moreover from Req `(p \<bullet> xvec) \<sharp>* P` `(p \<bullet> xvec) \<sharp>* Q` `y \<sharp> xvec` `y \<sharp> (p \<bullet> xvec)` `x \<sharp> (p \<bullet> xvec)` `y \<sharp> P` `y \<sharp> Q` `x \<sharp> P` S have "R = \<lparr>\<nu>*(p \<bullet> xvec)\<rparr>(\<lparr>\<nu>y\<rparr>((p \<bullet> P) \<parallel> (p \<bullet> [(x, y)] \<bullet> Q)))" apply(erule_tac rev_mp) apply(subst alphaRes[of y]) apply(clarsimp simp add: eqvts) apply(subst resChainAlpha[of p]) by(auto simp add: eqvts) moreover from Teq `(p \<bullet> xvec) \<sharp>* P` `(p \<bullet> xvec) \<sharp>* Q` `y \<sharp> xvec` `y \<sharp> (p \<bullet> xvec)` `x \<sharp> (p \<bullet> xvec)` `y \<sharp> P` `y \<sharp> Q` `x \<sharp> P` S have "T = \<lparr>\<nu>*(p \<bullet> xvec)\<rparr>((p \<bullet> P) \<parallel> \<lparr>\<nu>y\<rparr>(p \<bullet> [(x, y)] \<bullet> Q))" apply(erule_tac rev_mp) apply(subst alphaRes[of y]) apply(clarsimp simp add: eqvts) apply(subst resChainAlpha[of p]) by(auto simp add: eqvts) ultimately show ?case by blast next assume "(\<Psi>, R, T) \<notin> ?X1" with `(\<Psi>, R, T) \<in> ?X` have "(\<Psi>, R, T) \<in> ?X2" by blast then obtain xvec x P Q where Teq: "T = \<lparr>\<nu>*xvec\<rparr>(\<lparr>\<nu>x\<rparr>(P \<parallel> Q))" and Req: "R = \<lparr>\<nu>*xvec\<rparr>(P \<parallel> \<lparr>\<nu>x\<rparr>Q)" and "xvec \<sharp>* \<Psi>" and "x \<sharp> P" and "x \<sharp> \<Psi>" by auto obtain y::name where "y \<sharp> P" and "y \<sharp> Q" and "y \<sharp> xvec" and "y \<sharp> \<Psi>" and "y \<sharp> \<Psi>'" by(generate_fresh "name", auto simp add: fresh_prod) obtain p where "(p \<bullet> xvec) \<sharp>* \<Psi>" and "(p \<bullet> xvec) \<sharp>* P" and "(p \<bullet> xvec) \<sharp>* Q" and "(p \<bullet> xvec) \<sharp>* \<Psi>'" and "x \<sharp> (p \<bullet> xvec)" and "y \<sharp> (p \<bullet> xvec)" and S: "(set p) \<subseteq> (set xvec) \<times> (set(p \<bullet> xvec))" and "distinctPerm p" by(rule_tac c="(\<Psi>, P, Q, x, y, \<Psi>')" in name_list_avoiding) auto from `y \<sharp> P` have "(p \<bullet> y) \<sharp> (p \<bullet> P)" by(simp add: pt_fresh_bij[OF pt_name_inst, OF at_name_inst]) with S `y \<sharp> xvec` `y \<sharp> (p \<bullet> xvec)` have "y \<sharp> (p \<bullet> P)" by simp with `(p \<bullet> xvec) \<sharp>* \<Psi>` `y \<sharp> \<Psi>` `(p \<bullet> xvec) \<sharp>* \<Psi>'` `y \<sharp> \<Psi>'` have "(\<Psi> \<otimes> \<Psi>', \<lparr>\<nu>*(p \<bullet> xvec)\<rparr>((p \<bullet> P) \<parallel> \<lparr>\<nu>y\<rparr>(p \<bullet> [(x, y)] \<bullet> Q)), \<lparr>\<nu>*(p \<bullet> xvec)\<rparr>(\<lparr>\<nu>y\<rparr>((p \<bullet> P) \<parallel> (p \<bullet> [(x, y)] \<bullet> Q)))) \<in> ?X2" by auto moreover from Teq `(p \<bullet> xvec) \<sharp>* P` `(p \<bullet> xvec) \<sharp>* Q` `y \<sharp> xvec` `y \<sharp> (p \<bullet> xvec)` `x \<sharp> (p \<bullet> xvec)` `y \<sharp> P` `y \<sharp> Q` `x \<sharp> P` S have "T = \<lparr>\<nu>*(p \<bullet> xvec)\<rparr>(\<lparr>\<nu>y\<rparr>((p \<bullet> P) \<parallel> (p \<bullet> [(x, y)] \<bullet> Q)))" apply(erule_tac rev_mp) apply(subst alphaRes[of y]) apply(clarsimp simp add: eqvts) apply(subst resChainAlpha[of p]) by(auto simp add: eqvts) moreover from Req `(p \<bullet> xvec) \<sharp>* P` `(p \<bullet> xvec) \<sharp>* Q` `y \<sharp> xvec` `y \<sharp> (p \<bullet> xvec)` `x \<sharp> (p \<bullet> xvec)` `y \<sharp> P` `y \<sharp> Q` `x \<sharp> P` S have "R = \<lparr>\<nu>*(p \<bullet> xvec)\<rparr>((p \<bullet> P) \<parallel> \<lparr>\<nu>y\<rparr>(p \<bullet> [(x, y)] \<bullet> Q))" apply(erule_tac rev_mp) apply(subst alphaRes[of y]) apply(clarsimp simp add: eqvts) apply(subst resChainAlpha[of p]) by(auto simp add: eqvts) ultimately show ?case by blast qed next case(cSym \<Psi> P Q) thus ?case by(blast dest: bisimE) qed } moreover obtain y::name where "y \<sharp> \<Psi>" and "y \<sharp> P" "y \<sharp> Q" by(generate_fresh "name") auto ultimately have "\<Psi> \<rhd> \<lparr>\<nu>y\<rparr>(P \<parallel> ([(x, y)] \<bullet> Q)) \<sim> P \<parallel> \<lparr>\<nu>y\<rparr>([(x, y)] \<bullet> Q)" by auto thus ?thesis using assms `y \<sharp> P` `y \<sharp> Q` apply(subst alphaRes[where x=x and y=y and P=Q], auto) by(subst alphaRes[where x=x and y=y and P="P \<parallel> Q"]) auto qed lemma bisimScopeExtChain: fixes xvec :: "name list" and \<Psi> :: 'b and P :: "('a, 'b, 'c) psi" and Q :: "('a, 'b, 'c) psi" assumes "xvec \<sharp>* \<Psi>" and "xvec \<sharp>* P" shows "\<Psi> \<rhd> \<lparr>\<nu>*xvec\<rparr>(P \<parallel> Q) \<sim> P \<parallel> (\<lparr>\<nu>*xvec\<rparr>Q)" using assms by(induct xvec) (auto intro: bisimScopeExt bisimReflexive bisimTransitive bisimResPres) lemma bisimParAssoc: fixes \<Psi> :: 'b and P :: "('a, 'b, 'c) psi" and Q :: "('a, 'b, 'c) psi" and R :: "('a, 'b, 'c) psi" shows "\<Psi> \<rhd> (P \<parallel> Q) \<parallel> R \<sim> P \<parallel> (Q \<parallel> R)" proof - let ?X = "{(\<Psi>, \<lparr>\<nu>*xvec\<rparr>((P \<parallel> Q) \<parallel> R), \<lparr>\<nu>*xvec\<rparr>(P \<parallel> (Q \<parallel> R))) | \<Psi> xvec P Q R. xvec \<sharp>* \<Psi>}" let ?Y = "{(\<Psi>, P, Q) | \<Psi> P P' Q' Q. \<Psi> \<rhd> P \<sim> P' \<and> (\<Psi>, P', Q') \<in> ?X \<and> \<Psi> \<rhd> Q' \<sim> Q}" have "(\<Psi>, (P \<parallel> Q) \<parallel> R, P \<parallel> (Q \<parallel> R)) \<in> ?X" by(auto, rule_tac x="[]" in exI) auto moreover have "eqvt ?X" by(force simp add: eqvt_def simp add: pt_fresh_star_bij[OF pt_name_inst, OF at_name_inst] eqvts) ultimately show ?thesis proof(coinduct rule: weakTransitiveCoinduct') case(cStatEq \<Psi> PQR PQR') from `(\<Psi>, PQR, PQR') \<in> ?X` obtain xvec P Q R where "xvec \<sharp>* \<Psi>" and "PQR = \<lparr>\<nu>*xvec\<rparr>((P \<parallel> Q) \<parallel> R)" and "PQR' = \<lparr>\<nu>*xvec\<rparr>(P \<parallel> (Q \<parallel> R))" by auto moreover obtain A\<^sub>P \<Psi>\<^sub>P where FrP: "extractFrame P = \<langle>A\<^sub>P, \<Psi>\<^sub>P\<rangle>" and "A\<^sub>P \<sharp>* \<Psi>" and "A\<^sub>P \<sharp>* Q" and "A\<^sub>P \<sharp>* R" by(rule_tac C="(\<Psi>, Q, R)" in freshFrame) auto moreover obtain A\<^sub>Q \<Psi>\<^sub>Q where FrQ: "extractFrame Q = \<langle>A\<^sub>Q, \<Psi>\<^sub>Q\<rangle>" and "A\<^sub>Q \<sharp>* \<Psi>" and "A\<^sub>Q \<sharp>* A\<^sub>P" and "A\<^sub>Q \<sharp>* \<Psi>\<^sub>P" and "A\<^sub>Q \<sharp>* R" by(rule_tac C="(\<Psi>, A\<^sub>P, \<Psi>\<^sub>P, R)" in freshFrame) auto moreover obtain A\<^sub>R \<Psi>\<^sub>R where FrR: "extractFrame R = \<langle>A\<^sub>R, \<Psi>\<^sub>R\<rangle>" and "A\<^sub>R \<sharp>* \<Psi>" and "A\<^sub>R \<sharp>* A\<^sub>P" and "A\<^sub>R \<sharp>* \<Psi>\<^sub>P" and "A\<^sub>R \<sharp>* A\<^sub>Q" and "A\<^sub>R \<sharp>* \<Psi>\<^sub>Q" by(rule_tac C="(\<Psi>, A\<^sub>P, \<Psi>\<^sub>P, A\<^sub>Q, \<Psi>\<^sub>Q)" in freshFrame) auto moreover from FrQ `A\<^sub>P \<sharp>* Q` `A\<^sub>Q \<sharp>* A\<^sub>P` have "A\<^sub>P \<sharp>* \<Psi>\<^sub>Q" by(drule_tac extractFrameFreshChain) auto moreover from FrR `A\<^sub>P \<sharp>* R` `A\<^sub>R \<sharp>* A\<^sub>P` have "A\<^sub>P \<sharp>* \<Psi>\<^sub>R" by(drule_tac extractFrameFreshChain) auto moreover from FrR `A\<^sub>Q \<sharp>* R` `A\<^sub>R \<sharp>* A\<^sub>Q` have "A\<^sub>Q \<sharp>* \<Psi>\<^sub>R" by(drule_tac extractFrameFreshChain) auto ultimately show ?case using freshCompChain by auto (metis frameChainAppend compositionSym Associativity frameNilStatEq frameResChainPres) next case(cSim \<Psi> T S) from `(\<Psi>, T, S) \<in> ?X` obtain xvec P Q R where "xvec \<sharp>* \<Psi>" and TEq: "T = \<lparr>\<nu>*xvec\<rparr>((P \<parallel> Q) \<parallel> R)" and SEq: "S = \<lparr>\<nu>*xvec\<rparr>(P \<parallel> (Q \<parallel> R))" by auto from `eqvt ?X`have "eqvt ?Y" by blast have C1: "\<And>\<Psi> T S yvec. \<lbrakk>(\<Psi>, T, S) \<in> ?Y; yvec \<sharp>* \<Psi>\<rbrakk> \<Longrightarrow> (\<Psi>, \<lparr>\<nu>*yvec\<rparr>T, \<lparr>\<nu>*yvec\<rparr>S) \<in> ?Y" proof - fix \<Psi> T S yvec assume "(\<Psi>, T, S) \<in> ?Y" then obtain T' S' where "\<Psi> \<rhd> T \<sim> T'" and "(\<Psi>, T', S') \<in> ?X" and "\<Psi> \<rhd> S' \<sim> S" by fastforce assume "(yvec::name list) \<sharp>* \<Psi>" from `(\<Psi>, T', S') \<in> ?X` obtain xvec P Q R where T'eq: "T' = \<lparr>\<nu>*xvec\<rparr>((P \<parallel> Q) \<parallel> R)" and S'eq: "S' = \<lparr>\<nu>*xvec\<rparr>(P \<parallel> (Q \<parallel> R))" and "xvec \<sharp>* \<Psi>" by auto from `\<Psi> \<rhd> T \<sim> T'` `yvec \<sharp>* \<Psi>` have "\<Psi> \<rhd> \<lparr>\<nu>*yvec\<rparr>T \<sim> \<lparr>\<nu>*yvec\<rparr>T'" by(rule bisimResChainPres) moreover from `xvec \<sharp>* \<Psi>` `yvec \<sharp>* \<Psi>` have "(\<Psi>, \<lparr>\<nu>*(yvec@xvec)\<rparr>((P \<parallel> Q) \<parallel> R), \<lparr>\<nu>*(yvec@xvec)\<rparr>(P \<parallel> (Q \<parallel> R))) \<in> ?X" by force with T'eq S'eq have "(\<Psi>, \<lparr>\<nu>*yvec\<rparr>T', \<lparr>\<nu>*yvec\<rparr>S') \<in> ?X" by(simp add: resChainAppend) moreover from `\<Psi> \<rhd> S' \<sim> S` `yvec \<sharp>* \<Psi>` have "\<Psi> \<rhd> \<lparr>\<nu>*yvec\<rparr>S' \<sim> \<lparr>\<nu>*yvec\<rparr>S" by(rule bisimResChainPres) ultimately show "(\<Psi>, \<lparr>\<nu>*yvec\<rparr>T, \<lparr>\<nu>*yvec\<rparr>S) \<in> ?Y" by blast qed have C2: "\<And>\<Psi> T S y. \<lbrakk>(\<Psi>, T, S) \<in> ?Y; y \<sharp> \<Psi>\<rbrakk> \<Longrightarrow> (\<Psi>, \<lparr>\<nu>y\<rparr>T, \<lparr>\<nu>y\<rparr>S) \<in> ?Y" by(drule_tac yvec="[y]" in C1) auto have "\<Psi> \<rhd> \<lparr>\<nu>*xvec\<rparr>((P \<parallel> Q) \<parallel> R) \<leadsto>[?Y] \<lparr>\<nu>*xvec\<rparr>(P \<parallel> (Q \<parallel> R))" proof - have "\<Psi> \<rhd> (P \<parallel> Q) \<parallel> R \<leadsto>[?Y] P \<parallel> (Q \<parallel> R)" proof - note `eqvt ?Y` moreover have "\<And>\<Psi> P Q R. (\<Psi>, (P \<parallel> Q) \<parallel> R, P \<parallel> (Q \<parallel> R)) \<in> ?Y" proof - fix \<Psi> P Q R have "(\<Psi>::'b, ((P::('a, 'b, 'c) psi) \<parallel> Q) \<parallel> R, P \<parallel> (Q \<parallel> R)) \<in> ?X" by(auto, rule_tac x="[]" in exI) auto thus "(\<Psi>, (P \<parallel> Q) \<parallel> R, P \<parallel> (Q \<parallel> R)) \<in> ?Y" by(blast intro: bisimReflexive) qed moreover have "\<And>xvec \<Psi> P Q R. \<lbrakk>xvec \<sharp>* \<Psi>; xvec \<sharp>* P\<rbrakk> \<Longrightarrow> (\<Psi>, \<lparr>\<nu>*xvec\<rparr>((P \<parallel> Q) \<parallel> R), P \<parallel> (\<lparr>\<nu>*xvec\<rparr>(Q \<parallel> R))) \<in> ?Y" proof - fix xvec \<Psi> P Q R assume "(xvec::name list) \<sharp>* (\<Psi>::'b)" and "xvec \<sharp>* (P::('a, 'b, 'c) psi)" from `xvec \<sharp>* \<Psi>` have "(\<Psi>, \<lparr>\<nu>*xvec\<rparr>((P \<parallel> Q) \<parallel> R), \<lparr>\<nu>*xvec\<rparr>(P \<parallel> (Q \<parallel> R))) \<in> ?X" by blast moreover from `xvec \<sharp>* \<Psi>` `xvec \<sharp>* P` have "\<Psi> \<rhd> \<lparr>\<nu>*xvec\<rparr>(P \<parallel> (Q \<parallel> R)) \<sim> P \<parallel> (\<lparr>\<nu>*xvec\<rparr>(Q \<parallel> R))" by(rule bisimScopeExtChain) ultimately show "(\<Psi>, \<lparr>\<nu>*xvec\<rparr>((P \<parallel> Q) \<parallel> R), P \<parallel> (\<lparr>\<nu>*xvec\<rparr>(Q \<parallel> R))) \<in> ?Y" by(blast intro: bisimReflexive) qed moreover have "\<And>xvec \<Psi> P Q R. \<lbrakk>xvec \<sharp>* \<Psi>; xvec \<sharp>* R\<rbrakk> \<Longrightarrow> (\<Psi>, (\<lparr>\<nu>*xvec\<rparr>(P \<parallel> Q)) \<parallel> R, \<lparr>\<nu>*xvec\<rparr>(P \<parallel> (Q \<parallel> R))) \<in> ?Y" proof - fix xvec \<Psi> P Q R assume "(xvec::name list) \<sharp>* (\<Psi>::'b)" and "xvec \<sharp>* (R::('a, 'b, 'c) psi)" have "\<Psi> \<rhd> (\<lparr>\<nu>*xvec\<rparr>(P \<parallel> Q)) \<parallel> R \<sim> R \<parallel> (\<lparr>\<nu>*xvec\<rparr>(P \<parallel> Q))" by(rule bisimParComm) moreover from `xvec \<sharp>* \<Psi>` `xvec \<sharp>* R` have "\<Psi> \<rhd> \<lparr>\<nu>*xvec\<rparr>(R \<parallel> (P \<parallel> Q)) \<sim> R \<parallel> (\<lparr>\<nu>*xvec\<rparr>(P \<parallel> Q))" by(rule bisimScopeExtChain) hence "\<Psi> \<rhd> R \<parallel> (\<lparr>\<nu>*xvec\<rparr>(P \<parallel> Q)) \<sim> \<lparr>\<nu>*xvec\<rparr>(R \<parallel> (P \<parallel> Q))" by(rule bisimE) moreover from `xvec \<sharp>* \<Psi>` have "\<Psi> \<rhd> \<lparr>\<nu>*xvec\<rparr>(R \<parallel> (P \<parallel> Q)) \<sim> \<lparr>\<nu>*xvec\<rparr>((P \<parallel> Q) \<parallel> R)" by(metis bisimResChainPres bisimParComm) moreover from `xvec \<sharp>* \<Psi>` have "(\<Psi>, \<lparr>\<nu>*xvec\<rparr>((P \<parallel> Q) \<parallel> R), \<lparr>\<nu>*xvec\<rparr>(P \<parallel> (Q \<parallel> R))) \<in> ?X" by blast ultimately show "(\<Psi>, (\<lparr>\<nu>*xvec\<rparr>(P \<parallel> Q)) \<parallel> R, \<lparr>\<nu>*xvec\<rparr>(P \<parallel> (Q \<parallel> R))) \<in> ?Y" by(blast dest: bisimTransitive intro: bisimReflexive) qed ultimately show ?thesis using C1 by(rule parAssocLeft) qed thus ?thesis using `eqvt ?Y` `xvec \<sharp>* \<Psi>` C2 by(rule resChainPres) qed with TEq SEq show ?case by simp next case(cExt \<Psi> T S \<Psi>') from `(\<Psi>, T, S) \<in> ?X` obtain xvec P Q R where "xvec \<sharp>* \<Psi>" and TEq: "T = \<lparr>\<nu>*xvec\<rparr>((P \<parallel> Q) \<parallel> R)" and SEq: "S = \<lparr>\<nu>*xvec\<rparr>(P \<parallel> (Q \<parallel> R))" by auto obtain p where "(p \<bullet> xvec) \<sharp>* \<Psi>" and "(p \<bullet> xvec) \<sharp>* P" and "(p \<bullet> xvec) \<sharp>* Q" and "(p \<bullet> xvec) \<sharp>* R" and "(p \<bullet> xvec) \<sharp>* \<Psi>'" and S: "(set p) \<subseteq> (set xvec) \<times> (set(p \<bullet> xvec))" and "distinctPerm p" by(rule_tac c="(\<Psi>, P, Q, R, \<Psi>')" in name_list_avoiding) auto from `(p \<bullet> xvec) \<sharp>* \<Psi>` `(p \<bullet> xvec) \<sharp>* \<Psi>'` have "(\<Psi> \<otimes> \<Psi>', \<lparr>\<nu>*(p \<bullet> xvec)\<rparr>(((p \<bullet> P) \<parallel> (p \<bullet> Q)) \<parallel> (p \<bullet> R)), \<lparr>\<nu>*(p \<bullet> xvec)\<rparr>((p \<bullet> P) \<parallel> ((p \<bullet> Q) \<parallel> (p \<bullet> R)))) \<in> ?X" by auto moreover from TEq `(p \<bullet> xvec) \<sharp>* P` `(p \<bullet> xvec) \<sharp>* Q` `(p \<bullet> xvec) \<sharp>* R` S have "T = \<lparr>\<nu>*(p \<bullet> xvec)\<rparr>(((p \<bullet> P) \<parallel> (p \<bullet> Q)) \<parallel> (p \<bullet> R))" apply auto by(subst resChainAlpha[of p]) auto moreover from SEq `(p \<bullet> xvec) \<sharp>* P` `(p \<bullet> xvec) \<sharp>* Q` `(p \<bullet> xvec) \<sharp>* R` S have "S = \<lparr>\<nu>*(p \<bullet> xvec)\<rparr>((p \<bullet> P) \<parallel> ((p \<bullet> Q) \<parallel> (p \<bullet> R)))" apply auto by(subst resChainAlpha[of p]) auto ultimately show ?case by simp next case(cSym \<Psi> T S) from `(\<Psi>, T, S) \<in> ?X` obtain xvec P Q R where "xvec \<sharp>* \<Psi>" and TEq: "T = \<lparr>\<nu>*xvec\<rparr>((P \<parallel> Q) \<parallel> R)" and SEq: "\<lparr>\<nu>*xvec\<rparr>(P \<parallel> (Q \<parallel> R)) = S" by auto from `xvec \<sharp>* \<Psi>` have "\<Psi> \<rhd> \<lparr>\<nu>*xvec\<rparr>(P \<parallel> (Q \<parallel> R)) \<sim> \<lparr>\<nu>*xvec\<rparr>((R \<parallel> Q) \<parallel> P)" by(metis bisimParComm bisimParPres bisimTransitive bisimResChainPres) moreover from `xvec \<sharp>* \<Psi>` have "(\<Psi>, \<lparr>\<nu>*xvec\<rparr>((R \<parallel> Q) \<parallel> P), \<lparr>\<nu>*xvec\<rparr>(R \<parallel> (Q \<parallel> P))) \<in> ?X" by blast moreover from `xvec \<sharp>* \<Psi>` have "\<Psi> \<rhd> \<lparr>\<nu>*xvec\<rparr>(R \<parallel> (Q \<parallel> P)) \<sim> \<lparr>\<nu>*xvec\<rparr>((P \<parallel> Q) \<parallel> R)" by(metis bisimParComm bisimParPres bisimTransitive bisimResChainPres) ultimately show ?case using TEq SEq by(blast dest: bisimTransitive) qed qed lemma bisimParNil: fixes P :: "('a, 'b, 'c) psi" shows "\<Psi> \<rhd> P \<parallel> \<zero> \<sim> P" proof - let ?X1 = "{(\<Psi>, P \<parallel> \<zero>, P) | \<Psi> P. True}" let ?X2 = "{(\<Psi>, P, P \<parallel> \<zero>) | \<Psi> P. True}" let ?X = "?X1 \<union> ?X2" have "eqvt ?X" by(auto simp add: eqvt_def) have "(\<Psi>, P \<parallel> \<zero>, P) \<in> ?X" by simp thus ?thesis proof(coinduct rule: bisimWeakCoinduct) case(cStatEq \<Psi> Q R) show ?case proof(case_tac "(\<Psi>, Q, R) \<in> ?X1") assume "(\<Psi>, Q, R) \<in> ?X1" then obtain P where "Q = P \<parallel> \<zero>" and "R = P" by auto moreover obtain A\<^sub>P \<Psi>\<^sub>P where "extractFrame P = \<langle>A\<^sub>P, \<Psi>\<^sub>P\<rangle>" and "A\<^sub>P \<sharp>* \<Psi>" by(rule freshFrame) ultimately show ?case apply auto by(metis frameResChainPres frameNilStatEq Identity Associativity AssertionStatEqTrans Commutativity) next assume "(\<Psi>, Q, R) \<notin> ?X1" with `(\<Psi>, Q, R) \<in> ?X` have "(\<Psi>, Q, R) \<in> ?X2" by blast then obtain P where "Q = P" and "R = P \<parallel> \<zero>" by auto moreover obtain A\<^sub>P \<Psi>\<^sub>P where "extractFrame P = \<langle>A\<^sub>P, \<Psi>\<^sub>P\<rangle>" and "A\<^sub>P \<sharp>* \<Psi>" by(rule freshFrame) ultimately show ?case apply auto by(metis frameResChainPres frameNilStatEq Identity Associativity AssertionStatEqTrans AssertionStatEqSym Commutativity) qed next case(cSim \<Psi> Q R) thus ?case using `eqvt ?X` by(auto intro: parNilLeft parNilRight) next case(cExt \<Psi> Q R \<Psi>') thus ?case by auto next case(cSym \<Psi> Q R) thus ?case by auto qed qed lemma bisimResNil: fixes x :: name and \<Psi> :: 'b shows "\<Psi> \<rhd> \<lparr>\<nu>x\<rparr>\<zero> \<sim> \<zero>" proof - { fix x::name assume "x \<sharp> \<Psi>" have "\<Psi> \<rhd> \<lparr>\<nu>x\<rparr>\<zero> \<sim> \<zero>" proof - let ?X1 = "{(\<Psi>, \<lparr>\<nu>x\<rparr>\<zero>, \<zero>) | \<Psi> x. x \<sharp> \<Psi>}" let ?X2 = "{(\<Psi>, \<zero>, \<lparr>\<nu>x\<rparr>\<zero>) | \<Psi> x. x \<sharp> \<Psi>}" let ?X = "?X1 \<union> ?X2" from `x \<sharp> \<Psi>` have "(\<Psi>, \<lparr>\<nu>x\<rparr>\<zero>, \<zero>) \<in> ?X" by auto thus ?thesis proof(coinduct rule: bisimWeakCoinduct) case(cStatEq \<Psi> P Q) thus ?case using freshComp by(force intro: frameResFresh FrameStatEqSym) next case(cSim \<Psi> P Q) thus ?case by(force intro: resNilLeft resNilRight) next case(cExt \<Psi> P Q \<Psi>') obtain y where "y \<sharp> \<Psi>" and "y \<sharp> \<Psi>'" and "y \<noteq> x" by(generate_fresh "name") (auto simp add: fresh_prod) show ?case proof(case_tac "(\<Psi>, P, Q) \<in> ?X1") assume "(\<Psi>, P, Q) \<in> ?X1" then obtain x where "P = \<lparr>\<nu>x\<rparr>\<zero>" and "Q = \<zero>" by auto moreover have "\<lparr>\<nu>x\<rparr>\<zero> = \<lparr>\<nu>y\<rparr> \<zero>" by(subst alphaRes) auto ultimately show ?case using `y \<sharp> \<Psi>` `y \<sharp> \<Psi>'` by auto next assume "(\<Psi>, P, Q) \<notin> ?X1" with `(\<Psi>, P, Q) \<in> ?X` have "(\<Psi>, P, Q) \<in> ?X2" by auto then obtain x where "Q = \<lparr>\<nu>x\<rparr>\<zero>" and "P = \<zero>" by auto moreover have "\<lparr>\<nu>x\<rparr>\<zero> = \<lparr>\<nu>y\<rparr> \<zero>" by(subst alphaRes) auto ultimately show ?case using `y \<sharp> \<Psi>` `y \<sharp> \<Psi>'` by auto qed next case(cSym \<Psi> P Q) thus ?case by auto qed qed } moreover obtain y::name where "y \<sharp> \<Psi>" by(generate_fresh "name") auto ultimately have "\<Psi> \<rhd> \<lparr>\<nu>y\<rparr>\<zero> \<sim> \<zero>" by auto thus ?thesis by(subst alphaRes[where x=x and y=y]) auto qed lemma bisimOutputPushRes: fixes x :: name and \<Psi> :: 'b and M :: 'a and N :: 'a and P :: "('a, 'b, 'c) psi" assumes "x \<sharp> M" and "x \<sharp> N" shows "\<Psi> \<rhd> \<lparr>\<nu>x\<rparr>(M\<langle>N\<rangle>.P) \<sim> M\<langle>N\<rangle>.\<lparr>\<nu>x\<rparr>P" proof - { fix x::name and P::"('a, 'b, 'c) psi" assume "x \<sharp> \<Psi>" and "x \<sharp> M" and "x \<sharp> N" let ?X1 = "{(\<Psi>, \<lparr>\<nu>x\<rparr>(M\<langle>N\<rangle>.P), M\<langle>N\<rangle>.\<lparr>\<nu>x\<rparr>P) | \<Psi> x M N P. x \<sharp> \<Psi> \<and> x \<sharp> M \<and> x \<sharp> N}" let ?X2 = "{(\<Psi>, M\<langle>N\<rangle>.\<lparr>\<nu>x\<rparr>P, \<lparr>\<nu>x\<rparr>(M\<langle>N\<rangle>.P)) | \<Psi> x M N P. x \<sharp> \<Psi> \<and> x \<sharp> M \<and> x \<sharp> N}" let ?X = "?X1 \<union> ?X2" have "eqvt ?X" by(rule_tac eqvtUnion) (force simp add: eqvt_def pt_fresh_bij[OF pt_name_inst, OF at_name_inst] eqvts)+ from `x \<sharp> \<Psi>` `x \<sharp> M` `x \<sharp> N` have "(\<Psi>, \<lparr>\<nu>x\<rparr>(M\<langle>N\<rangle>.P), M\<langle>N\<rangle>.\<lparr>\<nu>x\<rparr>P) \<in> ?X" by auto hence "\<Psi> \<rhd> \<lparr>\<nu>x\<rparr>(M\<langle>N\<rangle>.P) \<sim> M\<langle>N\<rangle>.\<lparr>\<nu>x\<rparr>P" proof(coinduct rule: bisimCoinduct) case(cStatEq \<Psi> Q R) thus ?case using freshComp by(force intro: frameResFresh FrameStatEqSym) next case(cSim \<Psi> Q R) thus ?case using `eqvt ?X` by(fastforce intro: outputPushResLeft outputPushResRight bisimReflexive) next case(cExt \<Psi> Q R \<Psi>') show ?case proof(case_tac "(\<Psi>, Q, R) \<in> ?X1") assume "(\<Psi>, Q, R) \<in> ?X1" then obtain x M N P where Qeq: "Q = \<lparr>\<nu>x\<rparr>(M\<langle>N\<rangle>.P)" and Req: "R = M\<langle>N\<rangle>.\<lparr>\<nu>x\<rparr>P" and "x \<sharp> \<Psi>" and "x \<sharp> M" and "x \<sharp> N" by auto obtain y::name where "y \<sharp> \<Psi>" and "y \<sharp> \<Psi>'" and "y \<sharp> M" and "y \<sharp> N" and "y \<sharp> P" by(generate_fresh "name") (auto simp add: fresh_prod) moreover hence "(\<Psi> \<otimes> \<Psi>', \<lparr>\<nu>y\<rparr>(M\<langle>N\<rangle>.([(x, y)] \<bullet> P)), M\<langle>N\<rangle>.\<lparr>\<nu>y\<rparr>([(x, y)] \<bullet> P)) \<in> ?X" by auto moreover from Qeq `x \<sharp> M` `y \<sharp> M` `x \<sharp> N` `y \<sharp> N` `y \<sharp> P` have "Q = \<lparr>\<nu>y\<rparr>(M\<langle>N\<rangle>.([(x, y)] \<bullet> P))" apply auto by(subst alphaRes[of y]) (auto simp add: eqvts) moreover from Req `y \<sharp> P` have "R = M\<langle>N\<rangle>.\<lparr>\<nu>y\<rparr>([(x, y)] \<bullet> P)" apply auto by(subst alphaRes[of y]) (auto simp add: eqvts) ultimately show ?case by blast next assume "(\<Psi>, Q, R) \<notin> ?X1" with `(\<Psi>, Q, R) \<in> ?X` have "(\<Psi>, Q, R) \<in> ?X2" by blast then obtain x M N P where Req: "R = \<lparr>\<nu>x\<rparr>(M\<langle>N\<rangle>.P)" and Qeq: "Q = M\<langle>N\<rangle>.\<lparr>\<nu>x\<rparr>P" and "x \<sharp> \<Psi>" and "x \<sharp> M" and "x \<sharp> N" by auto obtain y::name where "y \<sharp> \<Psi>" and "y \<sharp> \<Psi>'" and "y \<sharp> M" and "y \<sharp> N" and "y \<sharp> P" by(generate_fresh "name") (auto simp add: fresh_prod) moreover hence "(\<Psi> \<otimes> \<Psi>', \<lparr>\<nu>y\<rparr>(M\<langle>N\<rangle>.([(x, y)] \<bullet> P)), M\<langle>N\<rangle>.\<lparr>\<nu>y\<rparr>([(x, y)] \<bullet> P)) \<in> ?X" by auto moreover from Req `x \<sharp> M` `y \<sharp> M` `x \<sharp> N` `y \<sharp> N` `y \<sharp> P` have "R = \<lparr>\<nu>y\<rparr>(M\<langle>N\<rangle>.([(x, y)] \<bullet> P))" apply auto by(subst alphaRes[of y]) (auto simp add: eqvts) moreover from Qeq `y \<sharp> P` have "Q = M\<langle>N\<rangle>.\<lparr>\<nu>y\<rparr>([(x, y)] \<bullet> P)" apply auto by(subst alphaRes[of y]) (auto simp add: eqvts) ultimately show ?case by blast qed next case(cSym \<Psi> R Q) thus ?case by blast qed } moreover obtain y::name where "y \<sharp> \<Psi>" and "y \<sharp> M" and "y \<sharp> N" "y \<sharp> P" by(generate_fresh "name") auto ultimately have "\<Psi> \<rhd> \<lparr>\<nu>y\<rparr>(M\<langle>N\<rangle>.([(x, y)] \<bullet> P)) \<sim> M\<langle>N\<rangle>.\<lparr>\<nu>y\<rparr>([(x, y)] \<bullet> P)" by auto thus ?thesis using assms `y \<sharp> P` `y \<sharp> M` `y \<sharp> N` apply(subst alphaRes[where x=x and y=y and P=P], auto) by(subst alphaRes[where x=x and y=y and P="M\<langle>N\<rangle>.P"]) auto qed lemma bisimInputPushRes: fixes x :: name and \<Psi> :: 'b and M :: 'a and xvec :: "name list" and N :: 'a and P :: "('a, 'b, 'c) psi" assumes "x \<sharp> M" and "x \<sharp> xvec" and "x \<sharp> N" shows "\<Psi> \<rhd> \<lparr>\<nu>x\<rparr>(M\<lparr>\<lambda>*xvec N\<rparr>.P) \<sim> M\<lparr>\<lambda>*xvec N\<rparr>.\<lparr>\<nu>x\<rparr>P" proof - { fix x::name and P::"('a, 'b, 'c) psi" assume "x \<sharp> \<Psi>" and "x \<sharp> M" and "x \<sharp> N" and "x \<sharp> xvec" let ?X1 = "{(\<Psi>, \<lparr>\<nu>x\<rparr>(M\<lparr>\<lambda>*xvec N\<rparr>.P), M\<lparr>\<lambda>*xvec N\<rparr>.\<lparr>\<nu>x\<rparr>P) | \<Psi> x M xvec N P. x \<sharp> \<Psi> \<and> x \<sharp> M \<and> x \<sharp> xvec \<and> x \<sharp> N}" let ?X2 = "{(\<Psi>, M\<lparr>\<lambda>*xvec N\<rparr>.\<lparr>\<nu>x\<rparr>P, \<lparr>\<nu>x\<rparr>(M\<lparr>\<lambda>*xvec N\<rparr>.P)) | \<Psi> x M xvec N P. x \<sharp> \<Psi> \<and> x \<sharp> M \<and> x \<sharp> xvec \<and> x \<sharp> N}" let ?X = "?X1 \<union> ?X2" have "eqvt ?X" by(rule_tac eqvtUnion) (force simp add: eqvt_def pt_fresh_bij[OF pt_name_inst, OF at_name_inst] eqvts)+ from `x \<sharp> \<Psi>` `x \<sharp> M` `x \<sharp> xvec` `x \<sharp> N` have "(\<Psi>, \<lparr>\<nu>x\<rparr>(M\<lparr>\<lambda>*xvec N\<rparr>.P), M\<lparr>\<lambda>*xvec N\<rparr>.\<lparr>\<nu>x\<rparr>P) \<in> ?X" by blast hence "\<Psi> \<rhd> \<lparr>\<nu>x\<rparr>(M\<lparr>\<lambda>*xvec N\<rparr>.P) \<sim> M\<lparr>\<lambda>*xvec N\<rparr>.\<lparr>\<nu>x\<rparr>P" proof(coinduct rule: bisimCoinduct) case(cStatEq \<Psi> Q R) thus ?case using freshComp by(force intro: frameResFresh FrameStatEqSym) next case(cSim \<Psi> Q R) thus ?case using `eqvt ?X` by(fastforce intro: inputPushResLeft inputPushResRight bisimReflexive) next case(cExt \<Psi> Q R \<Psi>') show ?case proof(case_tac "(\<Psi>, Q, R) \<in> ?X1") assume "(\<Psi>, Q, R) \<in> ?X1" then obtain x M xvec N P where Qeq: "Q = \<lparr>\<nu>x\<rparr>(M\<lparr>\<lambda>*xvec N\<rparr>.P)" and Req: "R = M\<lparr>\<lambda>*xvec N\<rparr>.\<lparr>\<nu>x\<rparr>P" and "x \<sharp> \<Psi>" and "x \<sharp> M" and "x \<sharp> xvec" and "x \<sharp> N" by auto obtain y::name where "y \<sharp> \<Psi>" and "y \<sharp> \<Psi>'" and "y \<sharp> M" and "y \<sharp> N" and "y \<sharp> P" and "y \<sharp> xvec" by(generate_fresh "name") (auto simp add: fresh_prod) moreover hence "(\<Psi> \<otimes> \<Psi>', \<lparr>\<nu>y\<rparr>(M\<lparr>\<lambda>*xvec N\<rparr>.([(x, y)] \<bullet> P)), M\<lparr>\<lambda>*xvec N\<rparr>.\<lparr>\<nu>y\<rparr>([(x, y)] \<bullet> P)) \<in> ?X" by fastforce moreover from Qeq `x \<sharp> M` `y \<sharp> M` `x \<sharp> xvec` `y \<sharp> xvec` `x \<sharp> N` `y \<sharp> N` `y \<sharp> P` have "Q = \<lparr>\<nu>y\<rparr>(M\<lparr>\<lambda>*xvec N\<rparr>.([(x, y)] \<bullet> P))" apply auto by(subst alphaRes[of y]) (auto simp add: eqvts inputChainFresh) moreover from Req `y \<sharp> P` have "R = M\<lparr>\<lambda>*xvec N \<rparr>.\<lparr>\<nu>y\<rparr>([(x, y)] \<bullet> P)" apply auto by(subst alphaRes[of y]) (auto simp add: eqvts) ultimately show ?case by blast next assume "(\<Psi>, Q, R) \<notin> ?X1" with `(\<Psi>, Q, R) \<in> ?X` have "(\<Psi>, Q, R) \<in> ?X2" by blast then obtain x M xvec N P where Req: "R = \<lparr>\<nu>x\<rparr>(M\<lparr>\<lambda>*xvec N\<rparr>.P)" and Qeq: "Q = M\<lparr>\<lambda>*xvec N\<rparr>.\<lparr>\<nu>x\<rparr>P" and "x \<sharp> \<Psi>" and "x \<sharp> M" and "x \<sharp> xvec" and "x \<sharp> N" by auto obtain y::name where "y \<sharp> \<Psi>" and "y \<sharp> \<Psi>'" and "y \<sharp> M" and "y \<sharp> N" and "y \<sharp> P" and "y \<sharp> xvec" by(generate_fresh "name") (auto simp add: fresh_prod) moreover hence "(\<Psi> \<otimes> \<Psi>', \<lparr>\<nu>y\<rparr>(M\<lparr>\<lambda>*xvec N\<rparr>.([(x, y)] \<bullet> P)), M\<lparr>\<lambda>*xvec N\<rparr>.\<lparr>\<nu>y\<rparr>([(x, y)] \<bullet> P)) \<in> ?X" by fastforce moreover from Req `x \<sharp> M` `y \<sharp> M` `x \<sharp> xvec` `y \<sharp> xvec` `x \<sharp> N` `y \<sharp> N` `y \<sharp> P` have "R = \<lparr>\<nu>y\<rparr>(M\<lparr>\<lambda>*xvec N\<rparr>.([(x, y)] \<bullet> P))" apply auto by(subst alphaRes[of y]) (auto simp add: eqvts inputChainFresh) moreover from Qeq `y \<sharp> P` have "Q = M\<lparr>\<lambda>*xvec N \<rparr>.\<lparr>\<nu>y\<rparr>([(x, y)] \<bullet> P)" apply auto by(subst alphaRes[of y]) (auto simp add: eqvts) ultimately show ?case by blast qed next case(cSym \<Psi> R Q) thus ?case by blast qed } moreover obtain y::name where "y \<sharp> \<Psi>" and "y \<sharp> M" and "y \<sharp> N" and "y \<sharp> P" and "y \<sharp> xvec" by(generate_fresh "name") auto ultimately have "\<Psi> \<rhd> \<lparr>\<nu>y\<rparr>(M\<lparr>\<lambda>*xvec N\<rparr>.([(x, y)] \<bullet> P)) \<sim> M\<lparr>\<lambda>*xvec N\<rparr>.\<lparr>\<nu>y\<rparr>([(x, y)] \<bullet> P)" by auto thus ?thesis using assms `y \<sharp> P` `y \<sharp> M` `y \<sharp> N` `y \<sharp> xvec` apply(subst alphaRes[where x=x and y=y and P=P], auto) by(subst alphaRes[where x=x and y=y and P="M\<lparr>\<lambda>*xvec N\<rparr>.P"]) (auto simp add: inputChainFresh eqvts) qed lemma bisimCasePushRes: fixes x :: name and \<Psi> :: 'b and Cs :: "('c \<times> ('a, 'b, 'c) psi) list" assumes "x \<sharp> (map fst Cs)" shows "\<Psi> \<rhd> \<lparr>\<nu>x\<rparr>(Cases Cs) \<sim> Cases(map (\<lambda>(\<phi>, P). (\<phi>, \<lparr>\<nu>x\<rparr>P)) Cs)" proof - { fix x::name and Cs::"('c \<times> ('a, 'b, 'c) psi) list" assume "x \<sharp> \<Psi>" and "x \<sharp> (map fst Cs)" let ?X1 = "{(\<Psi>, \<lparr>\<nu>x\<rparr>(Cases Cs), Cases(map (\<lambda>(\<phi>, P). (\<phi>, \<lparr>\<nu>x\<rparr>P)) Cs)) | \<Psi> x Cs. x \<sharp> \<Psi> \<and> x \<sharp> (map fst Cs)}" let ?X2 = "{(\<Psi>, Cases(map (\<lambda>(\<phi>, P). (\<phi>, \<lparr>\<nu>x\<rparr>P)) Cs), \<lparr>\<nu>x\<rparr>(Cases Cs)) | \<Psi> x Cs. x \<sharp> \<Psi> \<and> x \<sharp> (map fst Cs)}" let ?X = "?X1 \<union> ?X2" have "eqvt ?X" apply(rule_tac eqvtUnion) apply(auto simp add: eqvt_def eqvts) apply(rule_tac x="p \<bullet> x" in exI) apply(rule_tac x="p \<bullet> Cs" in exI) apply(perm_extend_simp) apply(auto simp add: eqvts) apply(simp add: pt_fresh_bij[OF pt_name_inst, OF at_name_inst]) apply(drule_tac pi=p in pt_fresh_bij1[OF pt_name_inst, OF at_name_inst]) apply(drule_tac pi=p in pt_fresh_bij1[OF pt_name_inst, OF at_name_inst]) apply(simp add: eqvts) apply(perm_extend_simp) apply(simp add: eqvts) apply(rule_tac x="p \<bullet> x" in exI) apply(rule_tac x="p \<bullet> Cs" in exI) apply auto apply(perm_extend_simp) apply(simp add: pt_fresh_bij[OF pt_name_inst, OF at_name_inst]) apply(drule_tac pi=p in pt_fresh_bij1[OF pt_name_inst, OF at_name_inst]) apply(drule_tac pi=p in pt_fresh_bij1[OF pt_name_inst, OF at_name_inst]) apply(simp add: eqvts) apply(perm_extend_simp) by(simp add: eqvts) from `x \<sharp> \<Psi>` `x \<sharp> map fst Cs` have "(\<Psi>, \<lparr>\<nu>x\<rparr>(Cases Cs), Cases(map (\<lambda>(\<phi>, P). (\<phi>, \<lparr>\<nu>x\<rparr>P)) Cs)) \<in> ?X" by auto hence "\<Psi> \<rhd> \<lparr>\<nu>x\<rparr>(Cases Cs) \<sim> Cases(map (\<lambda>(\<phi>, P). (\<phi>, \<lparr>\<nu>x\<rparr>P)) Cs)" proof(coinduct rule: bisimCoinduct) case(cStatEq \<Psi> Q R) thus ?case using freshComp by(force intro: frameResFresh FrameStatEqSym) next case(cSim \<Psi> Q R) thus ?case using `eqvt ?X` by(fastforce intro: casePushResLeft casePushResRight bisimReflexive) next case(cExt \<Psi> Q R \<Psi>') show ?case proof(case_tac "(\<Psi>, Q, R) \<in> ?X1") assume "(\<Psi>, Q, R) \<in> ?X1" then obtain x Cs where Qeq: "Q = \<lparr>\<nu>x\<rparr>(Cases Cs)" and Req: "R = Cases(map (\<lambda>(\<phi>, P). (\<phi>, \<lparr>\<nu>x\<rparr>P)) Cs)" and "x \<sharp> \<Psi>" and "x \<sharp> (map fst Cs)" by blast obtain y::name where "y \<sharp> \<Psi>" and "y \<sharp> \<Psi>'" and "y \<sharp> Cs" by(generate_fresh "name") (auto simp add: fresh_prod) from `y \<sharp> Cs` `x \<sharp> (map fst Cs)` have "y \<sharp> map fst ([(x, y)] \<bullet> Cs)" by(induct Cs) (auto simp add: fresh_list_cons fresh_list_nil) moreover with `y \<sharp> \<Psi>` `y \<sharp> \<Psi>'` have "(\<Psi> \<otimes> \<Psi>', \<lparr>\<nu>y\<rparr>(Cases ([(x, y)] \<bullet> Cs)), Cases(map (\<lambda>(\<phi>, P). (\<phi>, \<lparr>\<nu>y\<rparr>P)) ([(x, y)] \<bullet> Cs))) \<in> ?X" by auto moreover from Qeq `y \<sharp> Cs` have "Q = \<lparr>\<nu>y\<rparr>(Cases([(x, y)] \<bullet> Cs))" apply auto by(subst alphaRes[of y]) (auto simp add: eqvts) moreover from Req `y \<sharp> Cs` `x \<sharp> (map fst Cs)` have "R = Cases(map (\<lambda>(\<phi>, P). (\<phi>, \<lparr>\<nu>y\<rparr>P)) ([(x, y)] \<bullet> Cs))" by(induct Cs arbitrary: R) (auto simp add: fresh_list_cons fresh_prod alphaRes) ultimately show ?case by blast next assume "(\<Psi>, Q, R) \<notin> ?X1" with `(\<Psi>, Q, R) \<in> ?X` have "(\<Psi>, Q, R) \<in> ?X2" by blast then obtain x Cs where Req: "R = \<lparr>\<nu>x\<rparr>(Cases Cs)" and Qeq: "Q = Cases(map (\<lambda>(\<phi>, P). (\<phi>, \<lparr>\<nu>x\<rparr>P)) Cs)" and "x \<sharp> \<Psi>" and "x \<sharp> (map fst Cs)" by blast obtain y::name where "y \<sharp> \<Psi>" and "y \<sharp> \<Psi>'" and "y \<sharp> Cs" by(generate_fresh "name") (auto simp add: fresh_prod) from `y \<sharp> Cs` `x \<sharp> (map fst Cs)` have "y \<sharp> map fst ([(x, y)] \<bullet> Cs)" by(induct Cs) (auto simp add: fresh_list_cons fresh_list_nil) moreover with `y \<sharp> \<Psi>` `y \<sharp> \<Psi>'` have "(\<Psi> \<otimes> \<Psi>', \<lparr>\<nu>y\<rparr>(Cases ([(x, y)] \<bullet> Cs)), Cases(map (\<lambda>(\<phi>, P). (\<phi>, \<lparr>\<nu>y\<rparr>P)) ([(x, y)] \<bullet> Cs))) \<in> ?X" by auto moreover from Req `y \<sharp> Cs` have "R = \<lparr>\<nu>y\<rparr>(Cases([(x, y)] \<bullet> Cs))" apply auto by(subst alphaRes[of y]) (auto simp add: eqvts) moreover from Qeq `y \<sharp> Cs` `x \<sharp> (map fst Cs)` have "Q = Cases(map (\<lambda>(\<phi>, P). (\<phi>, \<lparr>\<nu>y\<rparr>P)) ([(x, y)] \<bullet> Cs))" by(induct Cs arbitrary: Q) (auto simp add: fresh_list_cons fresh_prod alphaRes) ultimately show ?case by blast qed next case(cSym \<Psi> R Q) thus ?case by blast qed } moreover obtain y::name where "y \<sharp> \<Psi>" and "y \<sharp> Cs" by(generate_fresh "name") auto moreover from `x \<sharp> map fst Cs` have "y \<sharp> map fst([(x, y)] \<bullet> Cs)" by(induct Cs) (auto simp add: fresh_left calc_atm) ultimately have "\<Psi> \<rhd> \<lparr>\<nu>y\<rparr>(Cases ([(x, y)] \<bullet> Cs)) \<sim> Cases(map (\<lambda>(\<phi>, P). (\<phi>, \<lparr>\<nu>y\<rparr>P)) ([(x, y)] \<bullet> Cs))" by auto moreover from `y \<sharp> Cs` have "\<lparr>\<nu>y\<rparr>(Cases ([(x, y)] \<bullet> Cs)) = \<lparr>\<nu>x\<rparr>(Cases Cs)" by(simp add: alphaRes eqvts) moreover from `x \<sharp> map fst Cs` `y \<sharp> Cs` have "Cases(map (\<lambda>(\<phi>, P). (\<phi>, \<lparr>\<nu>y\<rparr>P)) ([(x, y)] \<bullet> Cs)) = Cases(map (\<lambda>(\<phi>, P). (\<phi>, \<lparr>\<nu>x\<rparr>P)) Cs)" by(induct Cs) (auto simp add: alphaRes) ultimately show ?thesis by auto qed lemma bangExt: fixes \<Psi> :: 'b and P :: "('a, 'b, 'c) psi" assumes "guarded P" shows "\<Psi> \<rhd> !P \<sim> P \<parallel> !P" proof - let ?X = "{(\<Psi>, !P, P \<parallel> !P) | \<Psi> P. guarded P} \<union> {(\<Psi>, P \<parallel> !P, !P) | \<Psi> P. guarded P}" from `guarded P` have "(\<Psi>, !P, P \<parallel> !P) \<in> ?X" by auto thus ?thesis proof(coinduct rule: bisimCoinduct) case(cStatEq \<Psi> Q R) from `(\<Psi>, Q, R) \<in> ?X` obtain P where Eq: "(Q = !P \<and> R = P \<parallel> !P) \<or> (Q = P \<parallel> !P \<and> R = !P)" and "guarded P" by auto obtain A\<^sub>P \<Psi>\<^sub>P where FrP: "extractFrame P = \<langle>A\<^sub>P, \<Psi>\<^sub>P\<rangle>" and "A\<^sub>P \<sharp>* \<Psi>" by(rule freshFrame) from FrP `guarded P` have "\<Psi>\<^sub>P \<simeq> SBottom'" by(blast dest: guardedStatEq) from `\<Psi>\<^sub>P \<simeq> SBottom'` have "\<Psi> \<otimes> SBottom' \<simeq> \<Psi> \<otimes> \<Psi>\<^sub>P \<otimes> SBottom'" by(metis Identity Composition AssertionStatEqTrans Commutativity AssertionStatEqSym) hence "\<langle>A\<^sub>P, \<Psi> \<otimes> SBottom'\<rangle> \<simeq>\<^sub>F \<langle>A\<^sub>P, \<Psi> \<otimes> \<Psi>\<^sub>P \<otimes> SBottom'\<rangle>" by(force intro: frameResChainPres) moreover from `A\<^sub>P \<sharp>* \<Psi>` have "\<langle>\<epsilon>, \<Psi> \<otimes> SBottom'\<rangle> \<simeq>\<^sub>F \<langle>A\<^sub>P, \<Psi> \<otimes> SBottom'\<rangle>" by(rule_tac FrameStatEqSym) (fastforce intro: frameResFreshChain) ultimately show ?case using Eq `A\<^sub>P \<sharp>* \<Psi>` FrP by auto (blast dest: FrameStatEqTrans FrameStatEqSym)+ next case(cSim \<Psi> Q R) thus ?case by(auto intro: bangExtLeft bangExtRight bisimReflexive) next case(cExt \<Psi> Q R) thus ?case by auto next case(cSym \<Psi> Q R) thus ?case by auto qed qed lemma bisimParPresSym: fixes \<Psi> :: 'b and P :: "('a, 'b, 'c) psi" and Q :: "('a, 'b, 'c) psi" and R :: "('a, 'b, 'c) psi" assumes "\<Psi> \<rhd> P \<sim> Q" shows "\<Psi> \<rhd> R \<parallel> P \<sim> R \<parallel> Q" using assms by(metis bisimParComm bisimParPres bisimTransitive) lemma bisimScopeExtSym: fixes x :: name and Q :: "('a, 'b, 'c) psi" and P :: "('a, 'b, 'c) psi" assumes "x \<sharp> \<Psi>" and "x \<sharp> Q" shows "\<Psi> \<rhd> \<lparr>\<nu>x\<rparr>(P \<parallel> Q) \<sim> (\<lparr>\<nu>x\<rparr>P) \<parallel> Q" using assms by(metis bisimScopeExt bisimTransitive bisimParComm bisimSymmetric bisimResPres) lemma bisimScopeExtChainSym: fixes xvec :: "name list" and Q :: "('a, 'b, 'c) psi" and P :: "('a, 'b, 'c) psi" assumes "xvec \<sharp>* \<Psi>" and "xvec \<sharp>* Q" shows "\<Psi> \<rhd> \<lparr>\<nu>*xvec\<rparr>(P \<parallel> Q) \<sim> (\<lparr>\<nu>*xvec\<rparr>P) \<parallel> Q" using assms by(induct xvec) (auto intro: bisimScopeExtSym bisimReflexive bisimTransitive bisimResPres) lemma bisimParPresAuxSym: fixes \<Psi> :: 'b and P :: "('a, 'b, 'c) psi" and Q :: "('a, 'b, 'c) psi" and R :: "('a, 'b, 'c) psi" assumes "\<Psi> \<otimes> \<Psi>\<^sub>R \<rhd> P \<sim> Q" and "extractFrame R = \<langle>A\<^sub>R, \<Psi>\<^sub>R\<rangle>" and "A\<^sub>R \<sharp>* \<Psi>" and "A\<^sub>R \<sharp>* P" and "A\<^sub>R \<sharp>* Q" shows "\<Psi> \<rhd> R \<parallel> P \<sim> R \<parallel> Q" using assms by(metis bisimParComm bisimParPresAux bisimTransitive) lemma bangDerivative: fixes \<Psi> :: 'b and P :: "('a, 'b, 'c) psi" and \<alpha> :: "'a action" and P' :: "('a, 'b, 'c) psi" assumes "\<Psi> \<rhd> !P \<longmapsto>\<alpha> \<prec> P'" and "\<Psi> \<rhd> P \<sim> Q" and "bn \<alpha> \<sharp>* \<Psi>" and "bn \<alpha> \<sharp>* P" and "bn \<alpha> \<sharp>* Q" and "bn \<alpha> \<sharp>* subject \<alpha>" and "guarded Q" obtains Q' R T where "\<Psi> \<rhd> !Q \<longmapsto>\<alpha> \<prec> Q'" and "\<Psi> \<rhd> P' \<sim> R \<parallel> !P" and "\<Psi> \<rhd> Q' \<sim> T \<parallel> !Q" and "\<Psi> \<rhd> R \<sim> T" and "((supp R)::name set) \<subseteq> supp P'" and "((supp T)::name set) \<subseteq> supp Q'" proof - from `\<Psi> \<rhd> !P \<longmapsto>\<alpha> \<prec> P'` have "guarded P" apply - by(ind_cases "\<Psi> \<rhd> !P \<longmapsto>\<alpha> \<prec> P'") (auto simp add: psi.inject) assume "\<And>Q' R T. \<lbrakk>\<Psi> \<rhd> !Q \<longmapsto>\<alpha> \<prec> Q'; \<Psi> \<rhd> P' \<sim> R \<parallel> !P; \<Psi> \<rhd> Q' \<sim> T \<parallel> !Q; \<Psi> \<rhd> R \<sim> T; ((supp R)::name set) \<subseteq> supp P'; ((supp T)::name set) \<subseteq> supp Q'\<rbrakk> \<Longrightarrow> thesis" moreover from `\<Psi> \<rhd> !P \<longmapsto>\<alpha> \<prec> P'` `bn \<alpha> \<sharp>* subject \<alpha>` `bn \<alpha> \<sharp>* \<Psi>` `bn \<alpha> \<sharp>* P` `bn \<alpha> \<sharp>* Q` `\<Psi> \<rhd> P \<sim> Q` `guarded Q` have "\<exists>Q' T R . \<Psi> \<rhd> !Q \<longmapsto>\<alpha> \<prec> Q' \<and> \<Psi> \<rhd> P' \<sim> R \<parallel> !P \<and> \<Psi> \<rhd> Q' \<sim> T \<parallel> !Q \<and> \<Psi> \<rhd> R \<sim> T \<and> ((supp R)::name set) \<subseteq> supp P' \<and> ((supp T)::name set) \<subseteq> supp Q'" proof(nominal_induct avoiding: Q rule: bangInduct') case(cAlpha \<alpha> P' p Q) then obtain Q' T R where QTrans: "\<Psi> \<rhd> !Q \<longmapsto>\<alpha> \<prec> Q'" and "\<Psi> \<rhd> P' \<sim> R \<parallel> (P \<parallel> !P)" and "\<Psi> \<rhd> Q' \<sim> T \<parallel> !Q" and "\<Psi> \<rhd> R \<sim> T" and suppR: "((supp R)::name set) \<subseteq> supp P'" and suppT: "((supp T)::name set) \<subseteq> supp Q'" by blast from QTrans have "distinct(bn \<alpha>)" by(rule boundOutputDistinct) have S: "set p \<subseteq> set(bn \<alpha>) \<times> set(bn(p \<bullet> \<alpha>))" by fact from QTrans `bn(p \<bullet> \<alpha>) \<sharp>* Q` `bn(p \<bullet> \<alpha>) \<sharp>* \<alpha>` `bn \<alpha> \<sharp>* subject \<alpha>` `distinct(bn \<alpha>)` have "bn(p \<bullet> \<alpha>) \<sharp>* Q'" by(drule_tac freeFreshChainDerivative) simp+ with QTrans `bn(p \<bullet> \<alpha>) \<sharp>* \<alpha>` S `bn \<alpha> \<sharp>* subject \<alpha>` have "\<Psi> \<rhd> !Q \<longmapsto>(p \<bullet> \<alpha>) \<prec> (p \<bullet> Q')" by(force simp add: residualAlpha) moreover from `\<Psi> \<rhd> P' \<sim> R \<parallel> (P \<parallel> !P)` have "(p \<bullet> \<Psi>) \<rhd> (p \<bullet> P') \<sim> (p \<bullet> (R \<parallel> (P \<parallel> !P)))" by(rule bisimClosed) with `bn \<alpha> \<sharp>* \<Psi>` `bn \<alpha> \<sharp>* P` `bn(p \<bullet> \<alpha>) \<sharp>* \<Psi>` `bn(p \<bullet> \<alpha>) \<sharp>* P` S have "\<Psi> \<rhd> (p \<bullet> P') \<sim> (p \<bullet> R) \<parallel> (P \<parallel> !P)" by(simp add: eqvts) moreover from `\<Psi> \<rhd> Q' \<sim> T \<parallel> !Q` have "(p \<bullet> \<Psi>) \<rhd> (p \<bullet> Q') \<sim> (p \<bullet> (T \<parallel> !Q))" by(rule bisimClosed) with `bn \<alpha> \<sharp>* \<Psi>` `bn \<alpha> \<sharp>* Q` `bn(p \<bullet> \<alpha>) \<sharp>* \<Psi>` `bn(p \<bullet> \<alpha>) \<sharp>* Q` S have "\<Psi> \<rhd> (p \<bullet> Q') \<sim> (p \<bullet> T) \<parallel> !Q" by(simp add: eqvts) moreover from `\<Psi> \<rhd> R \<sim> T` have "(p \<bullet> \<Psi>) \<rhd> (p \<bullet> R) \<sim> (p \<bullet> T)" by(rule bisimClosed) with `bn \<alpha> \<sharp>* \<Psi>` `bn(p \<bullet> \<alpha>) \<sharp>* \<Psi>` S have "\<Psi> \<rhd> (p \<bullet> R) \<sim> (p \<bullet> T)" by(simp add: eqvts) moreover from suppR have "((supp(p \<bullet> R))::name set) \<subseteq> supp(p \<bullet> P')" apply(erule_tac rev_mp) by(subst subsetClosed[of p, symmetric]) (simp add: eqvts) moreover from suppT have "((supp(p \<bullet> T))::name set) \<subseteq> supp(p \<bullet> Q')" apply(erule_tac rev_mp) by(subst subsetClosed[of p, symmetric]) (simp add: eqvts) ultimately show ?case by blast next case(cPar1 \<alpha> P' Q) from `\<Psi> \<rhd> P \<sim> Q` `\<Psi> \<rhd> P \<longmapsto>\<alpha> \<prec> P'` `bn \<alpha> \<sharp>* \<Psi>` `bn \<alpha> \<sharp>* Q` obtain Q' where QTrans: "\<Psi> \<rhd> Q \<longmapsto>\<alpha> \<prec> Q'" and "\<Psi> \<rhd> P' \<sim> Q'" by(blast dest: bisimE simE) from QTrans have "\<Psi> \<otimes> SBottom' \<rhd> Q \<longmapsto>\<alpha> \<prec> Q'" by(metis statEqTransition Identity AssertionStatEqSym) hence "\<Psi> \<rhd> Q \<parallel> !Q \<longmapsto>\<alpha> \<prec> (Q' \<parallel> !Q)" using `bn \<alpha> \<sharp>* Q` by(rule_tac Par1) (assumption | simp)+ hence "\<Psi> \<rhd> !Q \<longmapsto>\<alpha> \<prec> (Q' \<parallel> !Q)" using `guarded Q` by(rule Bang) moreover from `guarded P` have "\<Psi> \<rhd> P' \<parallel> !P \<sim> P' \<parallel> (P \<parallel> !P)" by(metis bangExt bisimParPresSym) moreover have "\<Psi> \<rhd> Q' \<parallel> !Q \<sim> Q' \<parallel> !Q" by(rule bisimReflexive) ultimately show ?case using `\<Psi> \<rhd> P' \<sim> Q'` by(force simp add: psi.supp) next case(cPar2 \<alpha> P' Q) then obtain Q' T R where QTrans: "\<Psi> \<rhd> !Q \<longmapsto>\<alpha> \<prec> Q'" and "\<Psi> \<rhd> P' \<sim> R \<parallel> !P" and "\<Psi> \<rhd> Q' \<sim> T \<parallel> !Q" and "\<Psi> \<rhd> R \<sim> T" and suppR: "((supp R)::name set) \<subseteq> supp P'" and suppT: "((supp T)::name set) \<subseteq> supp Q'" by blast note QTrans from `\<Psi> \<rhd> P' \<sim> R \<parallel> !P` have "\<Psi> \<rhd> P \<parallel> P' \<sim> R \<parallel> (P \<parallel> !P)" by(metis bisimParPresSym bisimParComm bisimTransitive bisimParAssoc) with QTrans show ?case using `\<Psi> \<rhd> Q' \<sim> T \<parallel> !Q` `\<Psi> \<rhd> R \<sim> T` suppR suppT by(force simp add: psi.supp) next case(cComm1 M N P' K xvec P'' Q) from `\<Psi> \<rhd> P \<sim> Q` have "\<Psi> \<rhd> Q \<leadsto>[bisim] P" by(metis bisimE) with `\<Psi> \<rhd> P \<longmapsto>M\<lparr>N\<rparr> \<prec> P'` obtain Q' where QTrans: "\<Psi> \<rhd> Q \<longmapsto>M\<lparr>N\<rparr> \<prec> Q'" and "\<Psi> \<rhd> Q' \<sim> P'" by(force dest: simE) from QTrans have "\<Psi> \<otimes> SBottom' \<rhd> Q \<longmapsto>M\<lparr>N\<rparr> \<prec> Q'" by(metis statEqTransition Identity AssertionStatEqSym) moreover obtain A\<^sub>Q \<Psi>\<^sub>Q where FrQ: "extractFrame Q = \<langle>A\<^sub>Q, \<Psi>\<^sub>Q\<rangle>" and "A\<^sub>Q \<sharp>* \<Psi>" and "A\<^sub>Q \<sharp>* Q" and "A\<^sub>Q \<sharp>* M" by(rule_tac C="(\<Psi>, Q, M)" in freshFrame) auto note FrQ moreover from FrQ `guarded Q` have "\<Psi>\<^sub>Q \<simeq> SBottom'" by(blast dest: guardedStatEq) from `\<Psi> \<rhd> !P \<longmapsto>K\<lparr>\<nu>*xvec\<rparr>\<langle>N\<rangle> \<prec> P''` `xvec \<sharp>* K` `\<Psi> \<rhd> P \<sim> Q` `xvec \<sharp>* \<Psi>` `xvec \<sharp>* P` `xvec \<sharp>* Q` `guarded Q` obtain Q'' T R where QTrans': "\<Psi> \<rhd> !Q \<longmapsto>K\<lparr>\<nu>*xvec\<rparr>\<langle>N\<rangle> \<prec> Q''" and "\<Psi> \<rhd> P'' \<sim> R \<parallel> !P" and "\<Psi> \<rhd> Q'' \<sim> T \<parallel> !Q" and "\<Psi> \<rhd> R \<sim> T" and suppR: "((supp R)::name set) \<subseteq> supp P''" and suppT: "((supp T)::name set) \<subseteq> supp Q''" using cComm1 by fastforce from QTrans' `\<Psi>\<^sub>Q \<simeq> SBottom'` have "\<Psi> \<otimes> \<Psi>\<^sub>Q \<rhd> !Q \<longmapsto>K\<lparr>\<nu>*xvec\<rparr>\<langle>N\<rangle> \<prec> Q''" by(metis statEqTransition Identity compositionSym AssertionStatEqSym) moreover from `\<Psi> \<turnstile> M \<leftrightarrow> K` `\<Psi>\<^sub>Q \<simeq> SBottom'` have "\<Psi> \<otimes> \<Psi>\<^sub>Q \<otimes> SBottom' \<turnstile> M \<leftrightarrow> K" by(metis statEqEnt Identity compositionSym AssertionStatEqSym) ultimately have "\<Psi> \<rhd> Q \<parallel> !Q \<longmapsto>\<tau> \<prec> (\<lparr>\<nu>*xvec\<rparr>(Q' \<parallel> Q''))" using `A\<^sub>Q \<sharp>* \<Psi>` `A\<^sub>Q \<sharp>* Q` `A\<^sub>Q \<sharp>* M` `xvec \<sharp>* Q` by(rule_tac Comm1) (assumption | simp)+ hence "\<Psi> \<rhd> !Q \<longmapsto>\<tau> \<prec> (\<lparr>\<nu>*xvec\<rparr>(Q' \<parallel> Q''))" using `guarded Q` by(rule Bang) moreover from `\<Psi> \<rhd> P'' \<sim> R \<parallel> !P` `guarded P` `xvec \<sharp>* \<Psi>` have "\<Psi> \<rhd> \<lparr>\<nu>*xvec\<rparr>(P' \<parallel> P'') \<sim> \<lparr>\<nu>*xvec\<rparr>((P' \<parallel> R) \<parallel> (P \<parallel> !P))" by(metis bisimParPresSym bangExt bisimTransitive bisimParAssoc bisimSymmetric bisimResChainPres) with `xvec \<sharp>* \<Psi>` `xvec \<sharp>* P` have "\<Psi> \<rhd> \<lparr>\<nu>*xvec\<rparr>(P' \<parallel> P'') \<sim> (\<lparr>\<nu>*xvec\<rparr>(P' \<parallel> R)) \<parallel> (P \<parallel> !P)" by(metis bisimScopeExtChainSym bisimTransitive psiFreshVec) moreover from `\<Psi> \<rhd> Q'' \<sim> T \<parallel> !Q` `xvec \<sharp>* \<Psi>` `xvec \<sharp>* Q` have "\<Psi> \<rhd> \<lparr>\<nu>*xvec\<rparr>(Q' \<parallel> Q'') \<sim> (\<lparr>\<nu>*xvec\<rparr>(Q' \<parallel> T)) \<parallel> !Q" by(metis bisimParPresSym bisimTransitive bisimParAssoc bisimSymmetric bisimResChainPres bisimScopeExtChainSym psiFreshVec) moreover from `\<Psi> \<rhd> R \<sim> T` `\<Psi> \<rhd> Q' \<sim> P'` `xvec \<sharp>* \<Psi>` have "\<Psi> \<rhd> \<lparr>\<nu>*xvec\<rparr>(P' \<parallel> R) \<sim> \<lparr>\<nu>*xvec\<rparr>(Q' \<parallel> T)" by(metis bisimParPresSym bisimTransitive bisimResChainPres bisimParComm bisimE(4)) moreover from suppR have "((supp(\<lparr>\<nu>*xvec\<rparr>(P' \<parallel> R)))::name set) \<subseteq> supp((\<lparr>\<nu>*xvec\<rparr>(P' \<parallel> P'')))" by(auto simp add: psi.supp resChainSupp) moreover from suppT have "((supp(\<lparr>\<nu>*xvec\<rparr>(Q' \<parallel> T)))::name set) \<subseteq> supp((\<lparr>\<nu>*xvec\<rparr>(Q' \<parallel> Q'')))" by(auto simp add: psi.supp resChainSupp) ultimately show ?case by blast next case(cComm2 M xvec N P' K P'' Q) from `\<Psi> \<rhd> P \<sim> Q` `\<Psi> \<rhd> P \<longmapsto>M\<lparr>\<nu>*xvec\<rparr>\<langle>N\<rangle> \<prec> P'` `xvec \<sharp>* \<Psi>` `xvec \<sharp>* Q` obtain Q' where QTrans: "\<Psi> \<rhd> Q \<longmapsto>M\<lparr>\<nu>*xvec\<rparr>\<langle>N\<rangle> \<prec> Q'" and "\<Psi> \<rhd> P' \<sim> Q'" by(metis bisimE simE bn.simps) from QTrans have "\<Psi> \<otimes> SBottom' \<rhd> Q \<longmapsto>M\<lparr>\<nu>*xvec\<rparr>\<langle>N\<rangle> \<prec> Q'" by(metis statEqTransition Identity AssertionStatEqSym) moreover obtain A\<^sub>Q \<Psi>\<^sub>Q where FrQ: "extractFrame Q = \<langle>A\<^sub>Q, \<Psi>\<^sub>Q\<rangle>" and "A\<^sub>Q \<sharp>* \<Psi>" and "A\<^sub>Q \<sharp>* Q" and "A\<^sub>Q \<sharp>* M" by(rule_tac C="(\<Psi>, Q, M)" in freshFrame) auto note FrQ moreover from FrQ `guarded Q` have "\<Psi>\<^sub>Q \<simeq> SBottom'" by(blast dest: guardedStatEq) from `\<Psi> \<rhd> !P \<longmapsto>K\<lparr>N\<rparr> \<prec> P''` `\<Psi> \<rhd> P \<sim> Q` `guarded Q` obtain Q'' T R where QTrans': "\<Psi> \<rhd> !Q \<longmapsto>K\<lparr>N\<rparr> \<prec> Q''" and "\<Psi> \<rhd> P'' \<sim> R \<parallel> !P" and "\<Psi> \<rhd> Q'' \<sim> T \<parallel> !Q" and "\<Psi> \<rhd> R \<sim> T" and suppR: "((supp R)::name set) \<subseteq> supp P''" and suppT: "((supp T)::name set) \<subseteq> supp Q''" using cComm2 by fastforce from QTrans' `\<Psi>\<^sub>Q \<simeq> SBottom'` have "\<Psi> \<otimes> \<Psi>\<^sub>Q \<rhd> !Q \<longmapsto>K\<lparr>N\<rparr> \<prec> Q''" by(metis statEqTransition Identity compositionSym AssertionStatEqSym) moreover from `\<Psi> \<turnstile> M \<leftrightarrow> K` `\<Psi>\<^sub>Q \<simeq> SBottom'` have "\<Psi> \<otimes> \<Psi>\<^sub>Q \<otimes> SBottom' \<turnstile> M \<leftrightarrow> K" by(metis statEqEnt Identity compositionSym AssertionStatEqSym) ultimately have "\<Psi> \<rhd> Q \<parallel> !Q \<longmapsto>\<tau> \<prec> (\<lparr>\<nu>*xvec\<rparr>(Q' \<parallel> Q''))" using `A\<^sub>Q \<sharp>* \<Psi>` `A\<^sub>Q \<sharp>* Q` `A\<^sub>Q \<sharp>* M` `xvec \<sharp>* Q` by(rule_tac Comm2) (assumption | simp)+ hence "\<Psi> \<rhd> !Q \<longmapsto>\<tau> \<prec> (\<lparr>\<nu>*xvec\<rparr>(Q' \<parallel> Q''))" using `guarded Q` by(rule Bang) moreover from `\<Psi> \<rhd> P'' \<sim> R \<parallel> !P` `guarded P` `xvec \<sharp>* \<Psi>` have "\<Psi> \<rhd> \<lparr>\<nu>*xvec\<rparr>(P' \<parallel> P'') \<sim> \<lparr>\<nu>*xvec\<rparr>((P' \<parallel> R) \<parallel> (P \<parallel> !P))" by(metis bisimParPresSym bangExt bisimTransitive bisimParAssoc bisimSymmetric bisimResChainPres) with `xvec \<sharp>* \<Psi>` `xvec \<sharp>* P` have "\<Psi> \<rhd> \<lparr>\<nu>*xvec\<rparr>(P' \<parallel> P'') \<sim> (\<lparr>\<nu>*xvec\<rparr>(P' \<parallel> R)) \<parallel> (P \<parallel> !P)" by(metis bisimScopeExtChainSym bisimTransitive psiFreshVec) moreover from `\<Psi> \<rhd> Q'' \<sim> T \<parallel> !Q` `xvec \<sharp>* \<Psi>` `xvec \<sharp>* Q` have "\<Psi> \<rhd> \<lparr>\<nu>*xvec\<rparr>(Q' \<parallel> Q'') \<sim> (\<lparr>\<nu>*xvec\<rparr>(Q' \<parallel> T)) \<parallel> !Q" by(metis bisimParPresSym bisimTransitive bisimParAssoc bisimSymmetric bisimResChainPres bisimScopeExtChainSym psiFreshVec) moreover from `\<Psi> \<rhd> R \<sim> T` `\<Psi> \<rhd> P' \<sim> Q'` `xvec \<sharp>* \<Psi>` have "\<Psi> \<rhd> \<lparr>\<nu>*xvec\<rparr>(P' \<parallel> R) \<sim> \<lparr>\<nu>*xvec\<rparr>(Q' \<parallel> T)" by(metis bisimParPresSym bisimTransitive bisimResChainPres bisimParComm) moreover from suppR have "((supp(\<lparr>\<nu>*xvec\<rparr>(P' \<parallel> R)))::name set) \<subseteq> supp((\<lparr>\<nu>*xvec\<rparr>(P' \<parallel> P'')))" by(auto simp add: psi.supp resChainSupp) moreover from suppT have "((supp(\<lparr>\<nu>*xvec\<rparr>(Q' \<parallel> T)))::name set) \<subseteq> supp((\<lparr>\<nu>*xvec\<rparr>(Q' \<parallel> Q'')))" by(auto simp add: psi.supp resChainSupp) ultimately show ?case by blast next case(cBang \<alpha> P' Q) then obtain Q' T R where QTrans: "\<Psi> \<rhd> !Q \<longmapsto>\<alpha> \<prec> Q'" and "\<Psi> \<rhd> P' \<sim> R \<parallel> (P \<parallel> !P)" and "\<Psi> \<rhd> Q' \<sim> T \<parallel> !Q" and "\<Psi> \<rhd> R \<sim> T" and suppR: "((supp R)::name set) \<subseteq> supp P'" and suppT: "((supp T)::name set) \<subseteq> supp Q'" by blast from `\<Psi> \<rhd> P' \<sim> R \<parallel> (P \<parallel> !P)` `guarded P` have "\<Psi> \<rhd> P' \<sim> R \<parallel> !P" by(metis bangExt bisimParPresSym bisimTransitive bisimSymmetric) with QTrans show ?case using `\<Psi> \<rhd> Q' \<sim> T \<parallel> !Q` `\<Psi> \<rhd> R \<sim> T` suppR suppT by blast qed ultimately show ?thesis by blast qed lemma structCongBisim: fixes P :: "('a, 'b, 'c) psi" and Q :: "('a, 'b, 'c) psi" assumes "P \<equiv>\<^sub>s Q" shows "P \<sim> Q" using assms by(induct rule: structCong.induct) (auto intro: bisimReflexive bisimSymmetric bisimTransitive bisimParComm bisimParAssoc bisimParNil bisimResNil bisimResComm bisimScopeExt bisimCasePushRes bisimInputPushRes bisimOutputPushRes bangExt) lemma bisimBangPres: fixes \<Psi> :: 'b and P :: "('a, 'b, 'c) psi" and Q :: "('a, 'b, 'c) psi" assumes "\<Psi> \<rhd> P \<sim> Q" and "guarded P" and "guarded Q" shows "\<Psi> \<rhd> !P \<sim> !Q" proof - let ?X = "{(\<Psi>, R \<parallel> !P, R \<parallel> !Q) | \<Psi> P Q R. \<Psi> \<rhd> P \<sim> Q \<and> guarded P \<and> guarded Q}" let ?Y = "{(\<Psi>, P, Q) | \<Psi> P P' Q' Q. \<Psi> \<rhd> P \<sim> P' \<and> (\<Psi>, P', Q') \<in> ?X \<and> \<Psi> \<rhd> Q' \<sim> Q}" from assms have "(\<Psi>, \<zero> \<parallel> !P, \<zero> \<parallel> !Q) \<in> ?X" by(blast intro: bisimReflexive) moreover have "eqvt ?X" apply(auto simp add: eqvt_def) apply(drule_tac p=p in bisimClosed) by fastforce ultimately have "\<Psi> \<rhd> \<zero> \<parallel> !P \<sim> \<zero> \<parallel> !Q" proof(coinduct rule: weakTransitiveCoinduct) case(cStatEq \<Psi> P Q) thus ?case by auto next case(cSim \<Psi> RP RQ) from `(\<Psi>, RP, RQ) \<in> ?X` obtain P Q R where "\<Psi> \<rhd> P \<sim> Q" and "guarded P" and "guarded Q" and "RP = R \<parallel> !P" and "RQ = R \<parallel> !Q" by auto note `\<Psi> \<rhd> P \<sim> Q` moreover from `eqvt ?X` have "eqvt ?Y" by blast moreover note `guarded P` `guarded Q` bisimE(2) bisimE(3) bisimE(4) statEqBisim bisimClosed bisimParAssoc[THEN bisimSymmetric] bisimParPres bisimParPresAuxSym bisimResChainPres bisimScopeExtChainSym bisimTransitive moreover have "\<And>\<Psi> P Q R T. \<lbrakk>\<Psi> \<rhd> P \<sim> Q; (\<Psi>, Q, R) \<in> ?Y; \<Psi> \<rhd> R \<sim> T\<rbrakk> \<Longrightarrow> (\<Psi>, P, T) \<in> ?Y" by auto (metis bisimTransitive) moreover have "\<And>\<Psi> P Q R. \<lbrakk>\<Psi> \<rhd> P \<sim> Q; guarded P; guarded Q\<rbrakk> \<Longrightarrow> (\<Psi>, R \<parallel> !P, R \<parallel> !Q) \<in> ?Y" by(blast intro: bisimReflexive) moreover have "\<And>\<Psi> P \<alpha> P' Q. \<lbrakk>\<Psi> \<rhd> !P \<longmapsto>\<alpha> \<prec> P'; \<Psi> \<rhd> P \<sim> Q; bn \<alpha> \<sharp>* \<Psi>; bn \<alpha> \<sharp>* P; bn \<alpha> \<sharp>* Q; guarded Q; bn \<alpha> \<sharp>* subject \<alpha>\<rbrakk> \<Longrightarrow> \<exists>Q' R T. \<Psi> \<rhd> !Q \<longmapsto>\<alpha> \<prec> Q' \<and> \<Psi> \<rhd> P' \<sim> R \<parallel> !P \<and> \<Psi> \<rhd> Q' \<sim> T \<parallel> !Q \<and> \<Psi> \<rhd> R \<sim> T \<and> ((supp R)::name set) \<subseteq> supp P' \<and> ((supp T)::name set) \<subseteq> supp Q'" by(blast elim: bangDerivative) ultimately have "\<Psi> \<rhd> R \<parallel> !P \<leadsto>[?Y] R \<parallel> !Q" by(rule bangPres) with `RP = R \<parallel> !P` `RQ = R \<parallel> !Q` show ?case by blast next case(cExt \<Psi> RP RQ \<Psi>') thus ?case by(blast dest: bisimE) next case(cSym \<Psi> RP RQ) thus ?case by(blast dest: bisimE) qed thus ?thesis by(metis bisimTransitive bisimParNil bisimSymmetric bisimParComm) qed end end
/- Copyright (c) 2017 Scott Morrison. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Tim Baumann, Stephen Morgan, Scott Morrison, Floris van Doorn -/ import Mathlib.PrePort import Mathlib.Lean3Lib.init.default import Mathlib.category_theory.functor import Mathlib.PostPort universes v u l u₂ v₂ namespace Mathlib /-! # Isomorphisms This file defines isomorphisms between objects of a category. ## Main definitions - `structure iso` : a bundled isomorphism between two objects of a category; - `class is_iso` : an unbundled version of `iso`; note that `is_iso f` is usually *not* a `Prop`, because it holds the inverse morphism; - `as_iso` : convert from `is_iso` to `iso`; - `of_iso` : convert from `iso` to `is_iso`; - standard operations on isomorphisms (composition, inverse etc) ## Notations - `X ≅ Y` : same as `iso X Y`; - `α ≪≫ β` : composition of two isomorphisms; it is called `iso.trans` ## Tags category, category theory, isomorphism -/ namespace category_theory /-- An isomorphism (a.k.a. an invertible morphism) between two objects of a category. The inverse morphism is bundled. See also `category_theory.core` for the category with the same objects and isomorphisms playing the role of morphisms. See https://stacks.math.columbia.edu/tag/0017. -/ structure iso {C : Type u} [category C] (X : C) (Y : C) where hom : X ⟶ Y inv : Y ⟶ X hom_inv_id' : autoParam (hom ≫ inv = 𝟙) (Lean.Syntax.ident Lean.SourceInfo.none (String.toSubstring "Mathlib.obviously") (Lean.Name.mkStr (Lean.Name.mkStr Lean.Name.anonymous "Mathlib") "obviously") []) inv_hom_id' : autoParam (inv ≫ hom = 𝟙) (Lean.Syntax.ident Lean.SourceInfo.none (String.toSubstring "Mathlib.obviously") (Lean.Name.mkStr (Lean.Name.mkStr Lean.Name.anonymous "Mathlib") "obviously") []) @[simp] theorem iso.hom_inv_id {C : Type u} [category C] {X : C} {Y : C} (c : iso X Y) : iso.hom c ≫ iso.inv c = 𝟙 := sorry @[simp] theorem iso.inv_hom_id {C : Type u} [category C] {X : C} {Y : C} (c : iso X Y) : iso.inv c ≫ iso.hom c = 𝟙 := sorry @[simp] theorem iso.hom_inv_id_assoc {C : Type u} [category C] {X : C} {Y : C} (c : iso X Y) {X' : C} (f' : X ⟶ X') : iso.hom c ≫ iso.inv c ≫ f' = f' := sorry infixr:10 " ≅ " => Mathlib.category_theory.iso namespace iso theorem ext {C : Type u} [category C] {X : C} {Y : C} {α : X ≅ Y} {β : X ≅ Y} (w : hom α = hom β) : α = β := sorry /-- Inverse isomorphism. -/ def symm {C : Type u} [category C] {X : C} {Y : C} (I : X ≅ Y) : Y ≅ X := mk (inv I) (hom I) @[simp] theorem symm_hom {C : Type u} [category C] {X : C} {Y : C} (α : X ≅ Y) : hom (symm α) = inv α := rfl @[simp] theorem symm_inv {C : Type u} [category C] {X : C} {Y : C} (α : X ≅ Y) : inv (symm α) = hom α := rfl @[simp] theorem symm_mk {C : Type u} [category C] {X : C} {Y : C} (hom : X ⟶ Y) (inv : Y ⟶ X) (hom_inv_id : hom ≫ inv = 𝟙) (inv_hom_id : inv ≫ hom = 𝟙) : symm (mk hom inv) = mk inv hom := rfl @[simp] theorem symm_symm_eq {C : Type u} [category C] {X : C} {Y : C} (α : X ≅ Y) : symm (symm α) = α := sorry @[simp] theorem symm_eq_iff {C : Type u} [category C] {X : C} {Y : C} {α : X ≅ Y} {β : X ≅ Y} : symm α = symm β ↔ α = β := { mp := fun (h : symm α = symm β) => symm_symm_eq α ▸ symm_symm_eq β ▸ congr_arg symm h, mpr := congr_arg symm } /-- Identity isomorphism. -/ @[simp] theorem refl_inv {C : Type u} [category C] (X : C) : inv (refl X) = 𝟙 := Eq.refl (inv (refl X)) protected instance inhabited {C : Type u} [category C] {X : C} : Inhabited (X ≅ X) := { default := refl X } @[simp] theorem refl_symm {C : Type u} [category C] (X : C) : symm (refl X) = refl X := rfl /-- Composition of two isomorphisms -/ def trans {C : Type u} [category C] {X : C} {Y : C} {Z : C} (α : X ≅ Y) (β : Y ≅ Z) : X ≅ Z := mk (hom α ≫ hom β) (inv β ≫ inv α) infixr:80 " ≪≫ " => Mathlib.category_theory.iso.trans @[simp] theorem trans_mk {C : Type u} [category C] {X : C} {Y : C} {Z : C} (hom : X ⟶ Y) (inv : Y ⟶ X) (hom_inv_id : hom ≫ inv = 𝟙) (inv_hom_id : inv ≫ hom = 𝟙) (hom' : Y ⟶ Z) (inv' : Z ⟶ Y) (hom_inv_id' : hom' ≫ inv' = 𝟙) (inv_hom_id' : inv' ≫ hom' = 𝟙) (hom_inv_id'' : (hom ≫ hom') ≫ inv' ≫ inv = 𝟙) (inv_hom_id'' : (inv' ≫ inv) ≫ hom ≫ hom' = 𝟙) : mk hom inv ≪≫ mk hom' inv' = mk (hom ≫ hom') (inv' ≫ inv) := rfl @[simp] theorem trans_symm {C : Type u} [category C] {X : C} {Y : C} {Z : C} (α : X ≅ Y) (β : Y ≅ Z) : symm (α ≪≫ β) = symm β ≪≫ symm α := rfl @[simp] theorem trans_assoc {C : Type u} [category C] {X : C} {Y : C} {Z : C} {Z' : C} (α : X ≅ Y) (β : Y ≅ Z) (γ : Z ≅ Z') : (α ≪≫ β) ≪≫ γ = α ≪≫ β ≪≫ γ := sorry @[simp] theorem refl_trans {C : Type u} [category C] {X : C} {Y : C} (α : X ≅ Y) : refl X ≪≫ α = α := ext (category.id_comp (hom α)) @[simp] theorem trans_refl {C : Type u} [category C] {X : C} {Y : C} (α : X ≅ Y) : α ≪≫ refl Y = α := ext (category.comp_id (hom α)) @[simp] theorem symm_self_id {C : Type u} [category C] {X : C} {Y : C} (α : X ≅ Y) : symm α ≪≫ α = refl Y := ext (inv_hom_id α) @[simp] theorem self_symm_id {C : Type u} [category C] {X : C} {Y : C} (α : X ≅ Y) : α ≪≫ symm α = refl X := ext (hom_inv_id α) @[simp] theorem symm_self_id_assoc {C : Type u} [category C] {X : C} {Y : C} {Z : C} (α : X ≅ Y) (β : Y ≅ Z) : symm α ≪≫ α ≪≫ β = β := eq.mpr (id (Eq._oldrec (Eq.refl (symm α ≪≫ α ≪≫ β = β)) (Eq.symm (trans_assoc (symm α) α β)))) (eq.mpr (id (Eq._oldrec (Eq.refl ((symm α ≪≫ α) ≪≫ β = β)) (symm_self_id α))) (eq.mpr (id (Eq._oldrec (Eq.refl (refl Y ≪≫ β = β)) (refl_trans β))) (Eq.refl β))) @[simp] theorem self_symm_id_assoc {C : Type u} [category C] {X : C} {Y : C} {Z : C} (α : X ≅ Y) (β : X ≅ Z) : α ≪≫ symm α ≪≫ β = β := eq.mpr (id (Eq._oldrec (Eq.refl (α ≪≫ symm α ≪≫ β = β)) (Eq.symm (trans_assoc α (symm α) β)))) (eq.mpr (id (Eq._oldrec (Eq.refl ((α ≪≫ symm α) ≪≫ β = β)) (self_symm_id α))) (eq.mpr (id (Eq._oldrec (Eq.refl (refl X ≪≫ β = β)) (refl_trans β))) (Eq.refl β))) theorem inv_comp_eq {C : Type u} [category C] {X : C} {Y : C} {Z : C} (α : X ≅ Y) {f : X ⟶ Z} {g : Y ⟶ Z} : inv α ≫ f = g ↔ f = hom α ≫ g := sorry theorem eq_inv_comp {C : Type u} [category C] {X : C} {Y : C} {Z : C} (α : X ≅ Y) {f : X ⟶ Z} {g : Y ⟶ Z} : g = inv α ≫ f ↔ hom α ≫ g = f := iff.symm (inv_comp_eq (symm α)) theorem comp_inv_eq {C : Type u} [category C] {X : C} {Y : C} {Z : C} (α : X ≅ Y) {f : Z ⟶ Y} {g : Z ⟶ X} : f ≫ inv α = g ↔ f = g ≫ hom α := sorry theorem eq_comp_inv {C : Type u} [category C] {X : C} {Y : C} {Z : C} (α : X ≅ Y) {f : Z ⟶ Y} {g : Z ⟶ X} : g = f ≫ inv α ↔ g ≫ hom α = f := iff.symm (comp_inv_eq (symm α)) theorem inv_eq_inv {C : Type u} [category C] {X : C} {Y : C} (f : X ≅ Y) (g : X ≅ Y) : inv f = inv g ↔ hom f = hom g := sorry theorem hom_comp_eq_id {C : Type u} [category C] {X : C} {Y : C} (α : X ≅ Y) {f : Y ⟶ X} : hom α ≫ f = 𝟙 ↔ f = inv α := eq.mpr (id (Eq._oldrec (Eq.refl (hom α ≫ f = 𝟙 ↔ f = inv α)) (Eq.symm (propext (eq_inv_comp α))))) (eq.mpr (id (Eq._oldrec (Eq.refl (f = inv α ≫ 𝟙 ↔ f = inv α)) (category.comp_id (inv α)))) (iff.refl (f = inv α))) theorem comp_hom_eq_id {C : Type u} [category C] {X : C} {Y : C} (α : X ≅ Y) {f : Y ⟶ X} : f ≫ hom α = 𝟙 ↔ f = inv α := eq.mpr (id (Eq._oldrec (Eq.refl (f ≫ hom α = 𝟙 ↔ f = inv α)) (Eq.symm (propext (eq_comp_inv α))))) (eq.mpr (id (Eq._oldrec (Eq.refl (f = 𝟙 ≫ inv α ↔ f = inv α)) (category.id_comp (inv α)))) (iff.refl (f = inv α))) theorem hom_eq_inv {C : Type u} [category C] {X : C} {Y : C} (α : X ≅ Y) (β : Y ≅ X) : hom α = inv β ↔ hom β = inv α := eq.mpr (id (Eq._oldrec (Eq.refl (hom α = inv β ↔ hom β = inv α)) (propext (inv_eq_inv (symm α) β)))) (eq.mpr (id (Eq._oldrec (Eq.refl (hom (symm α) = hom β ↔ hom β = inv α)) (propext eq_comm))) (iff.refl (hom β = hom (symm α)))) end iso /-- `is_iso` typeclass expressing that a morphism is invertible. This contains the data of the inverse, but is a subsingleton type. -/ class is_iso {C : Type u} [category C] {X : C} {Y : C} (f : X ⟶ Y) where inv : Y ⟶ X hom_inv_id' : autoParam (f ≫ inv = 𝟙) (Lean.Syntax.ident Lean.SourceInfo.none (String.toSubstring "Mathlib.obviously") (Lean.Name.mkStr (Lean.Name.mkStr Lean.Name.anonymous "Mathlib") "obviously") []) inv_hom_id' : autoParam (inv ≫ f = 𝟙) (Lean.Syntax.ident Lean.SourceInfo.none (String.toSubstring "Mathlib.obviously") (Lean.Name.mkStr (Lean.Name.mkStr Lean.Name.anonymous "Mathlib") "obviously") []) /-- Reinterpret a morphism `f` with an `is_iso f` instance as an `iso`. -/ def as_iso {C : Type u} [category C] {X : C} {Y : C} (f : X ⟶ Y) [h : is_iso f] : X ≅ Y := iso.mk f (inv f) @[simp] theorem as_iso_hom {C : Type u} [category C] {X : C} {Y : C} (f : X ⟶ Y) [is_iso f] : iso.hom (as_iso f) = f := rfl @[simp] theorem as_iso_inv {C : Type u} [category C] {X : C} {Y : C} (f : X ⟶ Y) [is_iso f] : iso.inv (as_iso f) = inv f := rfl namespace is_iso @[simp] theorem hom_inv_id {C : Type u} [category C] {X : C} {Y : C} (f : X ⟶ Y) [is_iso f] : f ≫ inv f = 𝟙 := hom_inv_id' @[simp] theorem inv_hom_id {C : Type u} [category C] {X : C} {Y : C} (f : X ⟶ Y) [is_iso f] : inv f ≫ f = 𝟙 := inv_hom_id' @[simp] theorem hom_inv_id_assoc {C : Type u} [category C] {X : C} {Y : C} {Z : C} (f : X ⟶ Y) [is_iso f] (g : X ⟶ Z) : f ≫ inv f ≫ g = g := iso.hom_inv_id_assoc (as_iso f) g @[simp] theorem inv_hom_id_assoc {C : Type u} [category C] {X : C} {Y : C} {Z : C} (f : X ⟶ Y) [is_iso f] (g : Y ⟶ Z) : inv f ≫ f ≫ g = g := iso.inv_hom_id_assoc (as_iso f) g protected instance id {C : Type u} [category C] (X : C) : is_iso 𝟙 := mk 𝟙 protected instance of_iso {C : Type u} [category C] {X : C} {Y : C} (f : X ≅ Y) : is_iso (iso.hom f) := mk (iso.inv f) protected instance of_iso_inv {C : Type u} [category C] {X : C} {Y : C} (f : X ≅ Y) : is_iso (iso.inv f) := is_iso.of_iso (iso.symm f) protected instance inv_is_iso {C : Type u} [category C] {X : C} {Y : C} {f : X ⟶ Y} [is_iso f] : is_iso (inv f) := is_iso.of_iso_inv (as_iso f) protected instance comp_is_iso {C : Type u} [category C] {X : C} {Y : C} {Z : C} {f : X ⟶ Y} {h : Y ⟶ Z} [is_iso f] [is_iso h] : is_iso (f ≫ h) := is_iso.of_iso (as_iso f ≪≫ as_iso h) @[simp] theorem inv_id {C : Type u} [category C] {X : C} : inv 𝟙 = 𝟙 := rfl @[simp] theorem inv_comp {C : Type u} [category C] {X : C} {Y : C} {Z : C} {f : X ⟶ Y} {h : Y ⟶ Z} [is_iso f] [is_iso h] : inv (f ≫ h) = inv h ≫ inv f := rfl @[simp] theorem inv_inv {C : Type u} [category C] {X : C} {Y : C} {f : X ⟶ Y} [is_iso f] : inv (inv f) = f := rfl @[simp] theorem iso.inv_inv {C : Type u} [category C] {X : C} {Y : C} (f : X ≅ Y) : inv (iso.inv f) = iso.hom f := rfl @[simp] theorem iso.inv_hom {C : Type u} [category C] {X : C} {Y : C} (f : X ≅ Y) : inv (iso.hom f) = iso.inv f := rfl @[simp] theorem inv_comp_eq {C : Type u} [category C] {X : C} {Y : C} {Z : C} (α : X ⟶ Y) [is_iso α] {f : X ⟶ Z} {g : Y ⟶ Z} : inv α ≫ f = g ↔ f = α ≫ g := iso.inv_comp_eq (as_iso α) @[simp] theorem eq_inv_comp {C : Type u} [category C] {X : C} {Y : C} {Z : C} (α : X ⟶ Y) [is_iso α] {f : X ⟶ Z} {g : Y ⟶ Z} : g = inv α ≫ f ↔ α ≫ g = f := iso.eq_inv_comp (as_iso α) @[simp] theorem comp_inv_eq {C : Type u} [category C] {X : C} {Y : C} {Z : C} (α : X ⟶ Y) [is_iso α] {f : Z ⟶ Y} {g : Z ⟶ X} : f ≫ inv α = g ↔ f = g ≫ α := iso.comp_inv_eq (as_iso α) @[simp] theorem eq_comp_inv {C : Type u} [category C] {X : C} {Y : C} {Z : C} (α : X ⟶ Y) [is_iso α] {f : Z ⟶ Y} {g : Z ⟶ X} : g = f ≫ inv α ↔ g ≫ α = f := iso.eq_comp_inv (as_iso α) protected instance epi_of_iso {C : Type u} [category C] {X : C} {Y : C} (f : X ⟶ Y) [is_iso f] : epi f := epi.mk fun (Z : C) (g h : Y ⟶ Z) (w : f ≫ g = f ≫ h) => eq.mpr (id (Eq._oldrec (Eq.refl (g = h)) (Eq.symm (inv_hom_id_assoc f g)))) (eq.mpr (id (Eq._oldrec (Eq.refl (inv f ≫ f ≫ g = h)) w)) (eq.mpr (id (Eq._oldrec (Eq.refl (inv f ≫ f ≫ h = h)) (inv_hom_id_assoc f h))) (Eq.refl h))) protected instance mono_of_iso {C : Type u} [category C] {X : C} {Y : C} (f : X ⟶ Y) [is_iso f] : mono f := mono.mk fun (Z : C) (g h : Z ⟶ X) (w : g ≫ f = h ≫ f) => eq.mpr (id (Eq._oldrec (Eq.refl (g = h)) (Eq.symm (category.comp_id g)))) (eq.mpr (id (Eq._oldrec (Eq.refl (g ≫ 𝟙 = h)) (Eq.symm (category.comp_id h)))) (eq.mpr (id (Eq._oldrec (Eq.refl (g ≫ 𝟙 = h ≫ 𝟙)) (Eq.symm (hom_inv_id f)))) (eq.mpr (id (Eq._oldrec (Eq.refl (g ≫ f ≫ inv f = h ≫ f ≫ inv f)) (Eq.symm (category.assoc g f (inv f))))) (eq.mpr (id (Eq._oldrec (Eq.refl ((g ≫ f) ≫ inv f = h ≫ f ≫ inv f)) w)) (eq.mpr (id (Eq._oldrec (Eq.refl ((h ≫ f) ≫ inv f = h ≫ f ≫ inv f)) (Eq.symm (category.assoc h f (inv f))))) (Eq.refl ((h ≫ f) ≫ inv f))))))) end is_iso theorem eq_of_inv_eq_inv {C : Type u} [category C] {X : C} {Y : C} {f : X ⟶ Y} {g : X ⟶ Y} [is_iso f] [is_iso g] (p : inv f = inv g) : f = g := sorry protected instance is_iso.subsingleton {C : Type u} [category C] {X : C} {Y : C} (f : X ⟶ Y) : subsingleton (is_iso f) := sorry theorem is_iso.inv_eq_inv {C : Type u} [category C] {X : C} {Y : C} {f : X ⟶ Y} {g : X ⟶ Y} [is_iso f] [is_iso g] : inv f = inv g ↔ f = g := iso.inv_eq_inv (as_iso f) (as_iso g) theorem hom_comp_eq_id {C : Type u} [category C] {X : C} {Y : C} (g : X ⟶ Y) [is_iso g] {f : Y ⟶ X} : g ≫ f = 𝟙 ↔ f = inv g := iso.hom_comp_eq_id (as_iso g) theorem comp_hom_eq_id {C : Type u} [category C] {X : C} {Y : C} (g : X ⟶ Y) [is_iso g] {f : Y ⟶ X} : f ≫ g = 𝟙 ↔ f = inv g := iso.comp_hom_eq_id (as_iso g) namespace iso /-! All these cancellation lemmas can be solved by `simp [cancel_mono]` (or `simp [cancel_epi]`), but with the current design `cancel_mono` is not a good `simp` lemma, because it generates a typeclass search. When we can see syntactically that a morphism is a `mono` or an `epi` because it came from an isomorphism, it's fine to do the cancellation via `simp`. In the longer term, it might be worth exploring making `mono` and `epi` structures, rather than typeclasses, with coercions back to `X ⟶ Y`. Presumably we could write `X ↪ Y` and `X ↠ Y`. -/ @[simp] theorem cancel_iso_hom_left {C : Type u} [category C] {X : C} {Y : C} {Z : C} (f : X ≅ Y) (g : Y ⟶ Z) (g' : Y ⟶ Z) : hom f ≫ g = hom f ≫ g' ↔ g = g' := sorry @[simp] theorem cancel_iso_inv_left {C : Type u} [category C] {X : C} {Y : C} {Z : C} (f : Y ≅ X) (g : Y ⟶ Z) (g' : Y ⟶ Z) : inv f ≫ g = inv f ≫ g' ↔ g = g' := sorry @[simp] theorem cancel_iso_hom_right {C : Type u} [category C] {X : C} {Y : C} {Z : C} (f : X ⟶ Y) (f' : X ⟶ Y) (g : Y ≅ Z) : f ≫ hom g = f' ≫ hom g ↔ f = f' := sorry @[simp] theorem cancel_iso_inv_right {C : Type u} [category C] {X : C} {Y : C} {Z : C} (f : X ⟶ Y) (f' : X ⟶ Y) (g : Z ≅ Y) : f ≫ inv g = f' ≫ inv g ↔ f = f' := sorry /- Unfortunately cancelling an isomorphism from the right of a chain of compositions is awkward. We would need separate lemmas for each chain length (worse: for each pair of chain lengths). We provide two more lemmas, for case of three morphisms, because this actually comes up in practice, but then stop. -/ @[simp] theorem cancel_iso_hom_right_assoc {C : Type u} [category C] {W : C} {X : C} {X' : C} {Y : C} {Z : C} (f : W ⟶ X) (g : X ⟶ Y) (f' : W ⟶ X') (g' : X' ⟶ Y) (h : Y ≅ Z) : f ≫ g ≫ hom h = f' ≫ g' ≫ hom h ↔ f ≫ g = f' ≫ g' := sorry @[simp] theorem cancel_iso_inv_right_assoc {C : Type u} [category C] {W : C} {X : C} {X' : C} {Y : C} {Z : C} (f : W ⟶ X) (g : X ⟶ Y) (f' : W ⟶ X') (g' : X' ⟶ Y) (h : Z ≅ Y) : f ≫ g ≫ inv h = f' ≫ g' ≫ inv h ↔ f ≫ g = f' ≫ g' := sorry end iso namespace functor /-- A functor `F : C ⥤ D` sends isomorphisms `i : X ≅ Y` to isomorphisms `F.obj X ≅ F.obj Y` -/ def map_iso {C : Type u} [category C] {D : Type u₂} [category D] (F : C ⥤ D) {X : C} {Y : C} (i : X ≅ Y) : obj F X ≅ obj F Y := iso.mk (map F (iso.hom i)) (map F (iso.inv i)) @[simp] theorem map_iso_hom {C : Type u} [category C] {D : Type u₂} [category D] (F : C ⥤ D) {X : C} {Y : C} (i : X ≅ Y) : iso.hom (map_iso F i) = map F (iso.hom i) := rfl @[simp] theorem map_iso_inv {C : Type u} [category C] {D : Type u₂} [category D] (F : C ⥤ D) {X : C} {Y : C} (i : X ≅ Y) : iso.inv (map_iso F i) = map F (iso.inv i) := rfl @[simp] theorem map_iso_symm {C : Type u} [category C] {D : Type u₂} [category D] (F : C ⥤ D) {X : C} {Y : C} (i : X ≅ Y) : map_iso F (iso.symm i) = iso.symm (map_iso F i) := rfl @[simp] theorem map_iso_trans {C : Type u} [category C] {D : Type u₂} [category D] (F : C ⥤ D) {X : C} {Y : C} {Z : C} (i : X ≅ Y) (j : Y ≅ Z) : map_iso F (i ≪≫ j) = map_iso F i ≪≫ map_iso F j := iso.ext (map_comp F (iso.hom i) (iso.hom j)) @[simp] theorem map_iso_refl {C : Type u} [category C] {D : Type u₂} [category D] (F : C ⥤ D) (X : C) : map_iso F (iso.refl X) = iso.refl (obj F X) := iso.ext (map_id F X) protected instance map_is_iso {C : Type u} [category C] {X : C} {Y : C} {D : Type u₂} [category D] (F : C ⥤ D) (f : X ⟶ Y) [is_iso f] : is_iso (map F f) := is_iso.of_iso (map_iso F (as_iso f)) @[simp] theorem map_inv {C : Type u} [category C] {D : Type u₂} [category D] (F : C ⥤ D) {X : C} {Y : C} (f : X ⟶ Y) [is_iso f] : map F (inv f) = inv (map F f) := rfl theorem map_hom_inv {C : Type u} [category C] {D : Type u₂} [category D] (F : C ⥤ D) {X : C} {Y : C} (f : X ⟶ Y) [is_iso f] : map F f ≫ map F (inv f) = 𝟙 := sorry theorem map_inv_hom {C : Type u} [category C] {D : Type u₂} [category D] (F : C ⥤ D) {X : C} {Y : C} (f : X ⟶ Y) [is_iso f] : map F (inv f) ≫ map F f = 𝟙 := sorry
# Niyi Solomon Adebayo # -*- coding: utf-8 -*- import numpy as np from velocity import Velocity #################################### # Lab09: code to continuously edit # #################################### TASK = 3 # Update this value in the beginning of each task! # Pre-defined dictionaries # Dictionary for holding positions positions = {'current_marker': -1, 'current_us': -1, 'current_enc': -1, 'current_cam': -1, 'current_moving_avg_us': -1, 'current_complementary': -1, 'current_kalman': -1} # A Velocity class object for holding and updating velocities velocities = Velocity({'us': 0, 'enc': 0, 'cam': 0, 'moving_avg_us': 0, 'complementary': 0, 'kalman': 0}) ############################################ # Task 2: Implement moving average filter # ############################################ my_list =[] def moving_average(pos): global my_list # Fill in the function. limit = 10 my_list.append(pos) # i = 0 print('my_list ----------------> ', my_list) if len(my_list) > limit: # my_list[limit:-1] values = my_list[-limit:] # returns 5 last elements moving_average = sum(values)/int(limit) # i += 1 # print('my_list ----------------> ', my_list) else: values = my_list print('MOVING AVERAGE ELSEE VALUE: ', np.mean(values)) moving_average = sum(values) / int(limit) print(' moving_average----->', moving_average) return moving_average ############################################ # Task 3: Implement complementary filter # ############################################ encoder_value_dict = {} complemetary_est_value_dict = {} def complementary(us_pos, enc_pos): ''' posN=α⋅usN+β⋅(posN−1+Δenc). ''' global complemetary_est_value_dict, encoder_value_dict # Fill in the function enc_position = 'value' complemetary_est_value = 'value' usN = us_pos if 'enc_position' in encoder_value_dict: # first time it check if in dict...else it appends delta_encoders = encoder_value_dict['enc_position'] - enc_pos ## takes diff between current value and past value else: delta_encoders = 0 encoder_value_dict['enc_position'] = enc_pos if 'complemetary_est_value' in complemetary_est_value_dict: posN_minus_1 = complemetary_est_value_dict['complemetary_est_value'] else: posN_minus_1 = 1800 # 1800mm posN = (0.05 * usN) + 0.95 * (posN_minus_1 + delta_encoders) ## weighted average complemetary_est_value_dict['complemetary_est_value'] = posN return posN '''if one of the sensor is returning a constant value for e.g the ultrasonic sensor is return a constant value... for example when it is blocked i.e "(posN_minus_1 + delta_encoders) = a constant value". then, we will have a situation where the weigted average does not work as espected bcoz the weights are supposed to be shared according the formular, so it negate the prupose for complementary filter and it will hence add only the weights will be to the estimate of param1 '(0.05 * usN)' ...then "posN" starts accumulating errors we're trying to solve by implementing complemetary filter ''' # A class for performing operations with Gaussians class Gaussian: def __init__(self, mu, sigma): # Initializes a Gaussian with given mu and sigma values self.mu = mu self.sigma = sigma ################################################# # Task 4.2: Implement addition of two Gaussians # ################################################# def __add__(self, other): # Fill in the function. return Gaussian(0, 0) ####################################################### # Task 4.3: Implement multiplication of two Gaussians # ####################################################### def __mul__(self, other): # Fill in the function return Gaussian(0, 0) # A Kalman filter class class Kalman: def __init__(self, initial_gaussian): # Initializes a Kalman filter with the initial state given as an input self.filtered_result = initial_gaussian ######################################## # Task 4.2: Implement the predict step # ######################################## def predict(self, measurement): # Fill in the function return ####################################### # Task 4.3: Implement the update step # ####################################### def update(self, measurement): # Fill in the function return # Global variables for holding the encoder difference and camera Gaussians # and the Kalman class object for use in other files # DO NOT CHANGE THE NAMES OF THESE VARIABLES! camera_gaussian = None encoder_diff_gaussian = None kalman_filter = Kalman(None) #################################### # Lab09: code to continuously edit # #################################### def on_ultrasonic_measurement(us_pos): # Write code here that will perform actions # whenever the robot calculates a new ultrasonic-based location estimate moving_average_variable_holder = moving_average(us_pos) ### ----------------------------<<<<<<<<<<<< CODE ADDED BY NIYI velocities.update_velocity_for_sensor(moving_average_variable_holder, 'moving_avg_us') positions['current_moving_avg_us'] = moving_average_variable_holder # Update the velocity calculated based on ultrasonic measurements velocities.update_velocity_for_sensor(us_pos, 'us') return def on_encoder_measurement(enc_pos): # Write code here that will perform actions # whenever the robot calculates a new encoders-based location estimate current_ultra_sonic_pos = positions['current_us'] complementary_value = complementary(current_ultra_sonic_pos, enc_pos) velocities.update_velocity_for_sensor(complementary_value, 'complementary') positions[ 'current_complementary'] = complementary_value # Update the velocity calculated based on encoder measurements velocities.update_velocity_for_sensor(enc_pos, 'enc') return def on_camera_measurement(cam_pos): # Write code here that will perform actions # whenever the robot calculates a new camera-based location estimate # Update the velocity calculated based on ultrasonic measurements velocities.update_velocity_for_sensor(cam_pos, 'cam') return
This exterior room has large entrances and spaces. It consists of 2 separate beds of 1.05x2m and bathroom fully equipped and adapted. With all the services and amenities you might need. Room for one or two people.
function BOBYQAOptimizer(arg0::jint) return BOBYQAOptimizer((jint,), arg0) end function BOBYQAOptimizer(arg0::jint, arg1::jdouble, arg2::jdouble) return BOBYQAOptimizer((jint, jdouble, jdouble), arg0, arg1, arg2) end function compute_objective_value(obj::MultivariateOptimizer, arg0::Vector{jdouble}) return jcall(obj, "computeObjectiveValue", jdouble, (Vector{jdouble},), arg0) end function get_convergence_checker(obj::BaseOptimizer) return jcall(obj, "getConvergenceChecker", ConvergenceChecker, ()) end function get_evaluations(obj::BaseOptimizer) return jcall(obj, "getEvaluations", jint, ()) end function get_goal_type(obj::MultivariateOptimizer) return jcall(obj, "getGoalType", GoalType, ()) end function get_iterations(obj::BaseOptimizer) return jcall(obj, "getIterations", jint, ()) end function get_lower_bound(obj::BaseMultivariateOptimizer) return jcall(obj, "getLowerBound", Vector{jdouble}, ()) end function get_max_evaluations(obj::BaseOptimizer) return jcall(obj, "getMaxEvaluations", jint, ()) end function get_max_iterations(obj::BaseOptimizer) return jcall(obj, "getMaxIterations", jint, ()) end function get_start_point(obj::BaseMultivariateOptimizer) return jcall(obj, "getStartPoint", Vector{jdouble}, ()) end function get_upper_bound(obj::BaseMultivariateOptimizer) return jcall(obj, "getUpperBound", Vector{jdouble}, ()) end function optimize(obj::BaseOptimizer) return jcall(obj, "optimize", Object, ()) end function optimize(obj::MultivariateOptimizer, arg0::Vector{OptimizationData}) return jcall(obj, "optimize", PointValuePair, (Vector{OptimizationData},), arg0) end
module TypeListToFunction %default total TypeListFun : List Type -> Type TypeListFun [] = Unit TypeListFun (x::xs) = x -> TypeListFun xs typeListFun : (ts : List Type) -> TypeListFun ts typeListFun [] = () typeListFun (_::xs) = \_ => typeListFun xs
George Johnstone Stoney introduced the term electron in 1891 . John Stewart Bell was the originator of Bell 's Theorem and a paper concerning the discovery of the Bell @-@ <unk> @-@ Adler anomaly and was nominated for a Nobel prize . Notable mathematicians include Sir William Rowan Hamilton , famous for work in classical mechanics and the invention of quaternions . Francis Ysidro Edgeworth 's contribution of the Edgeworth Box remains influential in neo @-@ classical microeconomic theory to this day ; while Richard Cantillon inspired Adam Smith , among others . John B. Cosgrave was a specialist in number theory and discovered a 2000 @-@ digit prime number in 1999 and a record composite Fermat number in 2003 . John Lighton Synge made progress in different fields of science , including mechanics and geometrical methods in general relativity . He had mathematician John Nash as one of his students .
[STATEMENT] lemma elem_permutation_of_set_empty_iff: "finite A \<Longrightarrow> xs \<in> permutations_of_set A \<Longrightarrow> xs = [] \<longleftrightarrow> A = {}" [PROOF STATE] proof (prove) goal (1 subgoal): 1. \<lbrakk>finite A; xs \<in> permutations_of_set A\<rbrakk> \<Longrightarrow> (xs = []) = (A = {}) [PROOF STEP] using permutations_of_setD(1) [PROOF STATE] proof (prove) using this: ?xs \<in> permutations_of_set ?A \<Longrightarrow> set ?xs = ?A goal (1 subgoal): 1. \<lbrakk>finite A; xs \<in> permutations_of_set A\<rbrakk> \<Longrightarrow> (xs = []) = (A = {}) [PROOF STEP] by fastforce
%% ============================Notation============================ %% % X_sub_super % q_ToFrom % p_ofWhat_expressedInWhatFrame %% =============================Setup============================== %% clear; close all; clc; addpath('utils'); tic dataDir = '../datasets'; % fileName = 'dataset3'; % fileName = 'dataset3_fresh_10noisy'; % fileName = 'dataset3_fresh_10lessnoisy'; % fileName = 'dataset3_fresh_20lessnoisy'; % fileName = 'dataset3_fresh_40lessnoisy'; % fileName = 'dataset3_fresh_60lessnoisy'; % fileName = 'dataset3_fresh_80lessnoisy'; % fileName = 'dataset3_fresh_100lessnoisy'; % fileName = 'dataset3_fresh_500lessnoisy'; % fileName = '2011_09_26_drive_0035_sync_KLT'; % fileName = '2011_09_26_drive_0005_sync_KLT'; % fileName = '2011_09_30_drive_0020_sync_KLT'; % fileName = '2011_09_26_drive_0027_sync_KLT'; % fileName = '2011_09_30_drive_0020_sync_KLT'; kStart = 2; kEnd = 900; % Good KITTI runs % fileName = '2011_09_26_drive_0001_sync_KLT'; kStart = 2; kEnd = 98; fileName = '2011_09_26_drive_0036_sync_KLT'; kStart = 2; kEnd = 239; % fileName = '2011_09_26_drive_0051_sync_KLT'; kStart = 2; kEnd = 114; % fileName = '2011_09_26_drive_0095_sync_KLT'; kStart = 2; kEnd = 139; load(sprintf('%s/%s.mat',dataDir,fileName)); % r_i_vk_i = p_vi_i; %Dataset window bounds % kStart = 2; kEnd = 177; % kStart = 1215; kEnd = 1715; %Set constant numLandmarks = size(y_k_j,3); %Set up the camera parameters camera.c_u = cu; % Principal point [u pixels] camera.c_v = cv; % Principal point [v pixels] camera.f_u = fu; % Focal length [u pixels] camera.f_v = fv; % Focal length [v pixels] camera.b = b; % Stereo baseline [m] camera.q_CI = rotMatToQuat(C_c_v); % 4x1 IMU-to-Camera rotation quaternion camera.p_C_I = rho_v_c_v; % 3x1 Camera position in IMU frame %Set up the noise parameters y_var = 11^2 * ones(1,4); % pixel coord var noiseParams.u_var_prime = y_var(1)/camera.f_u^2; noiseParams.v_var_prime = y_var(2)/camera.f_v^2; w_var = 4e-2 * ones(1,3); % rot vel var v_var = 4e-2 * ones(1,3); % lin vel var dbg_var = 1e-6 * ones(1,3); % gyro bias change var dbv_var = 1e-6 * ones(1,3); % vel bias change var noiseParams.Q_imu = diag([w_var, dbg_var, v_var, dbv_var]); q_var_init = 1e-6 * ones(1,3); % init rot var p_var_init = 1e-6 * ones(1,3); % init pos var bg_var_init = 1e-6 * ones(1,3); % init gyro bias var bv_var_init = 1e-6 * ones(1,3); % init vel bias var noiseParams.initialIMUCovar = diag([q_var_init, bg_var_init, bv_var_init, p_var_init]); % MSCKF parameters msckfParams.minTrackLength = 10; % Set to inf to dead-reckon only msckfParams.maxTrackLength = Inf; % Set to inf to wait for features to go out of view msckfParams.maxGNCostNorm = 1e-2; % Set to inf to allow any triangulation, no matter how bad msckfParams.minRCOND = 1e-12; msckfParams.doNullSpaceTrick = true; msckfParams.doQRdecomp = true; % IMU state for plotting etc. Structures indexed in a cell array imuStates = cell(1,numel(t)); prunedStates = {}; % imuStates{k}.q_IG 4x1 Global to IMU rotation quaternion % imuStates{k}.p_I_G 3x1 IMU Position in the Global frame % imuStates{k}.b_g 3x1 Gyro bias % imuStates{k}.b_v 3x1 Velocity bias % imuStates{k}.covar 12x12 IMU state covariance % We don't really need these outside of msckfState, do we? % camState = cell(1,numel(t)); % camStates{k}.q_CG 4x1 Global to camera rotation quaternion % camStates{k}.p_C_G 3x1 Camera Position in the Global frame % camStates{k}.trackedFeatureIds 1xM List of feature ids that are currently being tracked from that camera state %msckfState.imuState %msckfState.imuCovar %msckfState.camCovar %msckfState.imuCamCovar %msckfState.camStates % Measurements as structures all indexed in a cell array dT = [0, diff(t)]; measurements = cell(1,numel(t)); % groundTruthStates = cell(1,numel(t)); % groundTruthMap = rho_i_pj_i; % Important: Because we're idealizing our pixel measurements and the % idealized measurements could legitimately be -1, replace our invalid % measurement flag with NaN y_k_j(y_k_j == -1) = NaN; for state_k = kStart:kEnd measurements{state_k}.dT = dT(state_k); % sampling times measurements{state_k}.y = squeeze(y_k_j(1:2,state_k,:)); % left camera only measurements{state_k}.omega = w_vk_vk_i(:,state_k); % ang vel measurements{state_k}.v = v_vk_vk_i(:,state_k); % lin vel %Idealize measurements validMeas = ~isnan(measurements{state_k}.y(1,:)); measurements{state_k}.y(1,validMeas) = (measurements{state_k}.y(1,validMeas) - camera.c_u)/camera.f_u; measurements{state_k}.y(2,validMeas) = (measurements{state_k}.y(2,validMeas) - camera.c_v)/camera.f_v; %Ground Truth q_IG = rotMatToQuat(axisAngleToRotMat(theta_vk_i(:,state_k))); p_I_G = r_i_vk_i(:,state_k); groundTruthStates{state_k}.imuState.q_IG = q_IG; groundTruthStates{state_k}.imuState.p_I_G = p_I_G; % Compute camera pose from current IMU pose C_IG = quatToRotMat(q_IG); q_CG = quatLeftComp(camera.q_CI) * q_IG; p_C_G = p_I_G + C_IG' * camera.p_C_I; groundTruthStates{state_k}.camState.q_CG = q_CG; groundTruthStates{state_k}.camState.p_C_G = p_C_G; end %Struct used to keep track of features featureTracks = {}; trackedFeatureIds = []; % featureTracks = {track1, track2, ...} % track.featureId % track.observations %% ==========================Initial State======================== %% %Use ground truth for first state and initialize feature tracks with %feature observations %Use ground truth for the first state firstImuState.q_IG = rotMatToQuat(axisAngleToRotMat(theta_vk_i(:,kStart))); firstImuState.p_I_G = r_i_vk_i(:,kStart); % firstImuState.q_IG = [0;0;0;1]; % firstImuState.q_IG = rotMatToQuat(rotx(90)); % firstImuState.p_I_G = [0;0;0]; [msckfState, featureTracks, trackedFeatureIds] = initializeMSCKF(firstImuState, measurements{kStart}, camera, kStart, noiseParams); imuStates = updateStateHistory(imuStates, msckfState, camera, kStart); msckfState_imuOnly{kStart} = msckfState; %% ============================MAIN LOOP========================== %% numFeatureTracksResidualized = 0; map = []; for state_k = kStart:(kEnd-1) fprintf('state_k = %4d\n', state_k); %% ==========================STATE PROPAGATION======================== %% %Propagate state and covariance msckfState = propagateMsckfStateAndCovar(msckfState, measurements{state_k}, noiseParams); msckfState_imuOnly{state_k+1} = propagateMsckfStateAndCovar(msckfState_imuOnly{state_k}, measurements{state_k}, noiseParams); %Add camera pose to msckfState msckfState = augmentState(msckfState, camera, state_k+1); %% ==========================FEATURE TRACKING======================== %% % Add observations to the feature tracks, or initialize a new one % If an observation is -1, add the track to featureTracksToResidualize featureTracksToResidualize = {}; for featureId = 1:numLandmarks %IMPORTANT: state_k + 1 not state_k meas_k = measurements{state_k+1}.y(:, featureId); outOfView = isnan(meas_k(1,1)); if ismember(featureId, trackedFeatureIds) if ~outOfView %Append observation and append id to cam states featureTracks{trackedFeatureIds == featureId}.observations(:, end+1) = meas_k; %Add observation to current camera msckfState.camStates{end}.trackedFeatureIds(end+1) = featureId; end track = featureTracks{trackedFeatureIds == featureId}; if outOfView ... || size(track.observations, 2) >= msckfParams.maxTrackLength ... || state_k+1 == kEnd %Feature is not in view, remove from the tracked features [msckfState, camStates, camStateIndices] = removeTrackedFeature(msckfState, featureId); %Add the track, with all of its camStates, to the %residualized list if length(camStates) >= msckfParams.minTrackLength track.camStates = camStates; track.camStateIndices = camStateIndices; featureTracksToResidualize{end+1} = track; end %Remove the track featureTracks = featureTracks(trackedFeatureIds ~= featureId); trackedFeatureIds(trackedFeatureIds == featureId) = []; end elseif ~outOfView && state_k+1 < kEnd % && ~ismember(featureId, trackedFeatureIds) %Track new feature track.featureId = featureId; track.observations = meas_k; featureTracks{end+1} = track; trackedFeatureIds(end+1) = featureId; %Add observation to current camera msckfState.camStates{end}.trackedFeatureIds(end+1) = featureId; end end %% ==========================FEATURE RESIDUAL CORRECTIONS======================== %% if ~isempty(featureTracksToResidualize) H_o = []; r_o = []; R_o = []; for f_i = 1:length(featureTracksToResidualize) track = featureTracksToResidualize{f_i}; %Estimate feature 3D location through Gauss Newton inverse depth %optimization [p_f_G, Jcost, RCOND] = calcGNPosEst(track.camStates, track.observations, noiseParams); % Uncomment to use ground truth map instead % p_f_G = groundTruthMap(:, track.featureId); Jcost = 0; RCOND = 1; % p_f_C = triangulate(squeeze(y_k_j(:, track.camStates{1}.state_k, track.featureId)), camera); Jcost = 0; RCOND = 1; nObs = size(track.observations,2); JcostNorm = Jcost / nObs^2; fprintf('Jcost = %f | JcostNorm = %f | RCOND = %f\n',... Jcost, JcostNorm,RCOND); if JcostNorm > msckfParams.maxGNCostNorm ... || RCOND < msckfParams.minRCOND % || norm(p_f_G) > 50 break; else map(:,end+1) = p_f_G; numFeatureTracksResidualized = numFeatureTracksResidualized + 1; fprintf('Using new feature track with %d observations. Total track count = %d.\n',... nObs, numFeatureTracksResidualized); end %Calculate residual and Hoj [r_j] = calcResidual(p_f_G, track.camStates, track.observations); R_j = diag(repmat([noiseParams.u_var_prime, noiseParams.v_var_prime], [1, numel(r_j)/2])); [H_o_j, A_j, H_x_j] = calcHoj(p_f_G, msckfState, track.camStateIndices); % Stacked residuals and friends if msckfParams.doNullSpaceTrick H_o = [H_o; H_o_j]; if ~isempty(A_j) r_o_j = A_j' * r_j; r_o = [r_o ; r_o_j]; R_o_j = A_j' * R_j * A_j; R_o(end+1 : end+size(R_o_j,1), end+1 : end+size(R_o_j,2)) = R_o_j; end else H_o = [H_o; H_x_j]; r_o = [r_o; r_j]; R_o(end+1 : end+size(R_j,1), end+1 : end+size(R_j,2)) = R_j; end end if ~isempty(r_o) % Put residuals into their final update-worthy form if msckfParams.doQRdecomp [T_H, Q_1] = calcTH(H_o); r_n = Q_1' * r_o; R_n = Q_1' * R_o * Q_1; else T_H = H_o; r_n = r_o; R_n = R_o; end % Build MSCKF covariance matrix P = [msckfState.imuCovar, msckfState.imuCamCovar; msckfState.imuCamCovar', msckfState.camCovar]; % Calculate Kalman gain K = (P*T_H') / ( T_H*P*T_H' + R_n ); % == (P*T_H') * inv( T_H*P*T_H' + R_n ) % State correction deltaX = K * r_n; msckfState = updateState(msckfState, deltaX); % Covariance correction tempMat = (eye(12 + 6*size(msckfState.camStates,2)) - K*T_H); % tempMat = (eye(12 + 6*size(msckfState.camStates,2)) - K*H_o); P_corrected = tempMat * P * tempMat' + K * R_n * K'; msckfState.imuCovar = P_corrected(1:12,1:12); msckfState.camCovar = P_corrected(13:end,13:end); msckfState.imuCamCovar = P_corrected(1:12, 13:end); % figure(1); clf; imagesc(deltaX); axis equal; axis ij; colorbar; % drawnow; end end %% ==========================STATE HISTORY======================== %% imuStates = updateStateHistory(imuStates, msckfState, camera, state_k+1); %% ==========================STATE PRUNING======================== %% %Remove any camera states with no tracked features [msckfState, deletedCamStates] = pruneStates(msckfState); if ~isempty(deletedCamStates) prunedStates(end+1:end+length(deletedCamStates)) = deletedCamStates; end % if max(max(msckfState.imuCovar(1:12,1:12))) > 1 % disp('omgbroken'); % end plot_traj; % figure(1); imagesc(msckfState.imuCovar(1:12,1:12)); axis equal; axis ij; colorbar; % drawnow; end %for state_K = ... toc %% ==========================PLOT ERRORS======================== %% kNum = length(prunedStates); p_C_G_est = NaN(3, kNum); p_I_G_imu = NaN(3, kNum); p_C_G_imu = NaN(3, kNum); p_C_G_GT = NaN(3, kNum); theta_CG_err = NaN(3,kNum); theta_CG_err_imu = NaN(3,kNum); err_sigma = NaN(6,kNum); % cam state is ordered as [rot, trans] err_sigma_imu = NaN(6,kNum); % tPlot = NaN(1, kNum); % for k = 1:kNum state_k = prunedStates{k}.state_k; p_C_G_GT(:,k) = groundTruthStates{state_k}.camState.p_C_G; p_C_G_est(:,k) = prunedStates{k}.p_C_G; q_CG_est = prunedStates{k}.q_CG; theta_CG_err(:,k) = crossMatToVec( eye(3) ... - quatToRotMat(q_CG_est) ... * ( C_c_v * axisAngleToRotMat(theta_vk_i(:,kStart+k-1)) )' ); err_sigma(:,k) = prunedStates{k}.sigma; imusig = sqrt(diag(msckfState_imuOnly{state_k}.imuCovar)); err_sigma_imu(:,k) = imusig([1:3,10:12]); p_I_G_imu(:,k) = msckfState_imuOnly{state_k}.imuState.p_I_G; C_CG_est_imu = C_CI * quatToRotMat(msckfState_imuOnly{state_k}.imuState.q_IG); theta_CG_err_imu(:,k) = crossMatToVec( eye(3) ... - C_CG_est_imu ... * ( C_CI * axisAngleToRotMat(theta_vk_i(:,kStart+k-1)) )' ); tPlot(k) = t(state_k); end % p_I_G_GT = p_vi_i(:,kStart:kEnd); p_I_G_GT = r_i_vk_i(:,kStart:kEnd); p_C_G_GT = p_I_G_GT + repmat(rho_v_c_v,[1,size(p_I_G_GT,2)]); p_C_G_imu = p_I_G_imu + repmat(rho_v_c_v,[1,size(p_I_G_imu,2)]); rotLim = [-0.5 0.5]; transLim = [-0.5 0.5]; % Save estimates msckf_trans_err = p_C_G_est - p_C_G_GT; msckf_rot_err = theta_CG_err; imu_trans_err = p_C_G_imu - p_C_G_GT; imu_rot_err = theta_CG_err_imu; save(sprintf('../KITTI Trials/msckf_%s', fileName)); armse_trans_msckf = mean(sqrt(sum(msckf_trans_err.^2, 1)/3)); armse_rot_msckf = mean(sqrt(sum(msckf_rot_err.^2, 1)/3)); final_trans_err_msckf = norm(msckf_trans_err(:,end)); armse_trans_imu = mean(sqrt(sum(imu_trans_err.^2, 1)/3)); armse_rot_imu = mean(sqrt(sum(imu_rot_err.^2, 1)/3)); final_trans_err_imu = norm(imu_trans_err(:,end)); fprintf('Trans ARMSE: IMU %f, MSCKF %f\n',armse_trans_imu, armse_trans_msckf); fprintf('Rot ARMSE: IMU %f, MSCKF %f\n',armse_rot_imu, armse_rot_msckf); fprintf('Final Trans Err: IMU %f, MSCKF %f\n',final_trans_err_imu, final_trans_err_msckf); % Translation Errors figure subplot(3,1,1) plot(tPlot, p_C_G_est(1,:) - p_C_G_GT(1,:), 'LineWidth', 2) hold on plot(tPlot, 3*err_sigma(4,:), '--r') plot(tPlot, -3*err_sigma(4,:), '--r') % ylim(transLim) xlim([tPlot(1) tPlot(end)]) title('Translational Error') ylabel('\delta r_x') subplot(3,1,2) plot(tPlot, p_C_G_est(2,:) - p_C_G_GT(2,:), 'LineWidth', 2) hold on plot(tPlot, 3*err_sigma(5,:), '--r') plot(tPlot, -3*err_sigma(5,:), '--r') % ylim(transLim) xlim([tPlot(1) tPlot(end)]) ylabel('\delta r_y') subplot(3,1,3) plot(tPlot, p_C_G_est(3,:) - p_C_G_GT(3,:), 'LineWidth', 2) hold on plot(tPlot, 3*err_sigma(6,:), '--r') plot(tPlot, -3*err_sigma(6,:), '--r') % ylim(transLim) xlim([tPlot(1) tPlot(end)]) ylabel('\delta r_z') xlabel('t_k') % Rotation Errors figure subplot(3,1,1) plot(tPlot, theta_CG_err(1,:), 'LineWidth', 2) hold on plot(tPlot, 3*err_sigma(1,:), '--r') plot(tPlot, -3*err_sigma(1,:), '--r') ylim(rotLim) xlim([tPlot(1) tPlot(end)]) title('Rotational Error') ylabel('\delta \theta_x') subplot(3,1,2) plot(tPlot, theta_CG_err(2,:), 'LineWidth', 2) hold on plot(tPlot, 3*err_sigma(2,:), '--r') plot(tPlot, -3*err_sigma(2,:), '--r') ylim(rotLim) xlim([tPlot(1) tPlot(end)]) ylabel('\delta \theta_y') subplot(3,1,3) plot(tPlot, theta_CG_err(3,:), 'LineWidth', 2) hold on plot(tPlot, 3*err_sigma(3,:), '--r') plot(tPlot, -3*err_sigma(3,:), '--r') ylim(rotLim) xlim([tPlot(1) tPlot(end)]) ylabel('\delta \theta_z') xlabel('t_k')
The summary for the Fiscal Year 2019 Funding for Ebey's Landing National Historical Reserve grant is detailed below. This summary states who is eligible for the grant, how much grant money will be awarded, current and past deadlines, Catalog of Federal Domestic Assistance (CFDA) numbers, and a sampling of similar government grants. Verify the accuracy of the data FederalGrants.com provides by visiting the webpage noted in the Link to Full Announcement section or by contacting the appropriate person listed as the Grant Announcement Contact. If any section is incomplete, please visit the website for the National Park Service, which is the U.S. government agency offering this grant.
A sports day will commence at the club grounds from 1.45pm. Proceedings will get under way with a fancy dress parade followed by football, hurling, camogie and athletic competitions. There will also be other sideshows, teas and refreshments on the day. Players past and present, members and parishioners are invited to this celebration.
Steve Jerome – engineer – 1984 release
import ActivationFunction import Numeric.LinearAlgebra main = do let x = (1><2) [1.0, 0.5] :: Matrix R y = forward x print y forward x = let w1 = (2><3) [0.1, 0.3, 0.5, 0.2, 0.4, 0.6] :: Matrix R w2 = (3><2) [0.1, 0.4, 0.2, 0.5, 0.3, 0.6] :: Matrix R w3 = (2><2) [0.1, 0.3, 0.2, 0.4] :: Matrix R b1 = (1><3) [0.1, 0.2, 0.3] :: Matrix R b2 = (1><2) [0.1, 0.2] :: Matrix R b3 = (1><2) [0.1, 0,2] :: Matrix R a1 = (x <> w1) + b1 z1 = sigmoid a1 a2 = (z1 <> w2) + b2 z2 = sigmoid a2 a3 = (z2 <> w3) + b3 in id a3
Require Import CertiGraph.lib.Ensembles_ext. Require Import Coq.Lists.List. Require Import VST.msl.seplog. Require Import VST.msl.log_normalize. Require Import CertiGraph.lib.Coqlib. Require Import CertiGraph.lib.EquivDec_ext. Require Import CertiGraph.msl_ext.log_normalize. Require Import CertiGraph.msl_ext.iter_sepcon. Require Import CertiGraph.msl_ext.seplog. Require Import CertiGraph.graph.graph_model. Require Import CertiGraph.graph.path_lemmas. Require Import CertiGraph.graph.reachable_computable. Require Import CertiGraph.graph.reachable_ind. Require Import CertiGraph.graph.subgraph2. Require Import CertiGraph.graph.graph_gen. Require Export CertiGraph.graph.BiGraph. Require Export CertiGraph.graph.MathGraph. Require Export CertiGraph.graph.FiniteGraph. Require Import CertiGraph.msl_application.Graph. Require Import Coq.Logic.Classical. Import OconNotation. Local Open Scope logic. Inductive LR := | L | R. Class pPointwiseGraph_Graph_Bi: Type := { addr: Type; null: addr; SGBA: PointwiseGraphBasicAssum addr (addr * LR) }. Existing Instance SGBA. Definition is_null_SGBA {pSGGB: pPointwiseGraph_Graph_Bi} : DecidablePred addr := (existT (fun P => forall a, {P a} + {~ P a}) (fun x => x = null) (fun x => SGBA_VE x null)). Class sPointwiseGraph_Graph_Bi {pSGG_Bi: pPointwiseGraph_Graph_Bi} (DV DE: Type): Type := { pred: Type; SGP: PointwiseGraphPred addr (addr * LR) (DV * addr * addr) unit pred; SGA: PointwiseGraphAssum SGP; SGAvs: PointwiseGraphAssum_vs SGP; SGAvn: PointwiseGraphAssum_vn SGP null }. Existing Instances SGP SGA SGAvs. Section GRAPH_BI. (********************************************************* Pure Facts Part *********************************************************) Context {pSGG_Bi: pPointwiseGraph_Graph_Bi}. Context {DV DE DG: Type}. Class BiMaFin (g: PreGraph addr (addr * LR)) := { bi: BiGraph g (fun x => (x, L)) (fun x => (x, R)); ma: MathGraph g is_null_SGBA; fin: FiniteGraph g }. Class BiMaFin' (g: PreGraph addr (addr * LR)) := { bi': BiGraph g (fun x => (x, L)) (fun x => (x, R)); ma': MathGraph' g is_null_SGBA; fin': FiniteGraph g }. Definition Graph := (GeneralGraph addr (addr * LR) DV DE DG (fun g => BiMaFin (pg_lg g))). Definition Graph' := (GeneralGraph addr (addr * LR) DV DE DG (fun g => BiMaFin' (pg_lg g))). Definition LGraph := (LabeledGraph addr (addr * LR) DV DE DG). Definition SGraph := (PointwiseGraph addr (addr * LR) (DV * addr * addr) unit). Instance SGC_Bi: PointwiseGraphConstructor addr (addr * LR) DV DE DG (DV * addr * addr) unit. Proof. refine (Build_PointwiseGraphConstructor _ _ _ _ _ _ _ SGBA _ _). + exact (fun G v => (vlabel G v, dst (pg_lg G) (v, L), dst (pg_lg G) (v, R))). + exact (fun _ _ => tt). Defined. Instance L_SGC_Bi: Local_PointwiseGraphConstructor addr (addr * LR) DV DE DG (DV * addr * addr) unit. Proof. refine (Build_Local_PointwiseGraphConstructor _ _ _ _ _ _ _ SGBA SGC_Bi (fun G v => evalid (pg_lg G) (v, L) /\ evalid (pg_lg G) (v, R) /\ src (pg_lg G) (v, L) = v /\ src (pg_lg G) (v, R) = v) _ (fun _ _ => True) _). + intros. simpl. destruct H as [? [? [? ?]]], H0 as [? [? [? ?]]]. f_equal; [f_equal |]; auto. + intros; simpl. auto. Defined. Global Existing Instances SGC_Bi L_SGC_Bi. Definition Graph_LGraph (G: Graph): LGraph := lg_gg G. Definition Graph'_LGraph (G: Graph'): LGraph := lg_gg G. Definition LGraph_SGraph (G: LGraph): SGraph := Graph_PointwiseGraph G. Local Coercion Graph_LGraph: Graph >-> LGraph. Local Coercion Graph'_LGraph: Graph' >-> LGraph. Local Coercion LGraph_SGraph: LGraph >-> SGraph. Local Identity Coercion Graph_GeneralGraph: Graph >-> GeneralGraph. Local Identity Coercion Graph'_GeneralGraph: Graph' >-> GeneralGraph. Local Identity Coercion LGraph_LabeledGraph: LGraph >-> LabeledGraph. Local Identity Coercion SGraph_PointwiseGraph: SGraph >-> PointwiseGraph. Local Coercion pg_lg: LabeledGraph >-> PreGraph. Instance biGraph (G: Graph): BiGraph G (fun x => (x, L)) (fun x => (x, R)) := @bi G (@sound_gg _ _ _ _ _ _ _ _ G). Instance biGraph' (G: Graph'): BiGraph G (fun x => (x, L)) (fun x => (x, R)) := @bi' G (@sound_gg _ _ _ _ _ _ _ _ G). Instance maGraph(G: Graph): MathGraph G is_null_SGBA := @ma G (@sound_gg _ _ _ _ _ _ _ _ G). Instance maGraph'(G: Graph'): MathGraph' G is_null_SGBA := @ma' G (@sound_gg _ _ _ _ _ _ _ _ G). Instance finGraph (G: Graph): FiniteGraph G := @fin G (@sound_gg _ _ _ _ _ _ _ _ G). Instance finGraph' (G: Graph'): FiniteGraph G := @fin' G (@sound_gg _ _ _ _ _ _ _ _ G). Instance RGF (G: Graph): ReachableFiniteGraph G. apply Build_ReachableFiniteGraph. intros. apply finite_reachable_computable with (is_null := is_null_SGBA) in H. + destruct H as [l [? ?]]. exists l; auto. + apply maGraph. + apply (LocalFiniteGraph_FiniteGraph G), finGraph. + apply (FiniteGraph_EnumCovered G), finGraph. Defined. Definition Graph_vgen (G: Graph) (x: addr) (d: DV) : Graph := generalgraph_vgen G x d (sound_gg G). Definition Graph_egen (G: Graph) (e: addr * LR) (d: DE) : Graph := generalgraph_egen G e d (sound_gg G). Definition empty_BiGraph: BiGraph (empty_pregraph (fun e => fst e) (fun e => null)) (fun x => (x, L)) (fun x => (x, R)). constructor. + intros ? []. + intros ? ? []. Defined. Definition empty_MathGraph: MathGraph (empty_pregraph (fun e => fst e) (fun e => null)) is_null_SGBA. apply (Build_MathGraph _ is_null_SGBA). + intros ? []. + intros ? []. Defined. Definition empty_MathGraph': MathGraph' (empty_pregraph (fun e => fst e) (fun e => null)) is_null_SGBA. apply (Build_MathGraph' _ is_null_SGBA). + intros ? []. + intros ? []. Defined. Definition empty_FiniteGraph: FiniteGraph (empty_pregraph (fun e => fst e) (fun e => null)). constructor. + exists nil. split; [constructor | intros]. simpl. unfold Ensembles.In; reflexivity. + exists nil. split; [constructor | intros]. simpl. unfold Ensembles.In; reflexivity. Defined. Definition empty_sound: BiMaFin (empty_pregraph (fun e => fst e) (fun e => null)) := Build_BiMaFin _ empty_BiGraph empty_MathGraph empty_FiniteGraph. Definition empty_sound': BiMaFin' (empty_pregraph (fun e => fst e) (fun e => null)) := Build_BiMaFin' _ empty_BiGraph empty_MathGraph' empty_FiniteGraph. Definition empty_Graph (default_v: DV) (default_e: DE) (default_g : DG) : Graph := Build_GeneralGraph _ _ _ _ (empty_labeledgraph (fun e => fst e) (fun e => null) default_v default_e default_g) empty_sound. Definition empty_Graph' (default_v: DV) (default_e: DE) (default_g : DG) : Graph' := Build_GeneralGraph _ _ _ _ (empty_labeledgraph (fun e => fst e) (fun e => null) default_v default_e default_g) empty_sound'. Definition is_BiMaFin (g: LGraph): Prop := exists X: BiMaFin (pg_lg g), True. Definition is_BiMaFin' (g: LGraph): Prop := exists X: BiMaFin' (pg_lg g), True. Definition is_guarded_BiMaFin (PV: addr -> Prop) (PE: addr * LR -> Prop) (g: LGraph): Prop := is_BiMaFin (gpredicate_sub_labeledgraph PV PE g). Definition is_guarded_BiMaFin' (PV: addr -> Prop) (PE: addr * LR -> Prop) (g: LGraph): Prop := is_BiMaFin' (gpredicate_sub_labeledgraph PV PE g). Definition left_right_sound: forall (g: Graph) (x: addr) lr, vvalid g x -> src g (x, lr) = x. Proof. intros. destruct lr. + apply (@left_sound _ _ _ _ _ _ g (biGraph _) x); auto. + apply (@right_sound _ _ _ _ _ _ g (biGraph _) x); auto. Qed. Definition left_right_sound0: forall (g: Graph) (x: addr) lr, evalid g (x, lr) -> src g (x, lr) = x. Proof. intros. destruct lr. + destruct (@valid_graph _ _ _ _ g _ (maGraph _) (x, L) H) as [? _]. pose proof (@only_two_edges _ _ _ _ g _ _ (biGraph _) _ (x, L) H0). simpl in H1. destruct H1 as [? _]. specialize (H1 (conj eq_refl H)). destruct H1; inversion H1. rewrite <- ! H3; auto. + destruct (@valid_graph _ _ _ _ g _ (maGraph _) (x, R) H) as [? _]. pose proof (@only_two_edges _ _ _ _ g _ _ (biGraph _) _ (x, R) H0). simpl in H1. destruct H1 as [? _]. specialize (H1 (conj eq_refl H)). destruct H1; inversion H1. rewrite <- ! H3; auto. Qed. Definition left_right_sound': forall (g: Graph') (x: addr) lr, vvalid g x -> src g (x, lr) = x. Proof. intros. destruct lr. + apply (@left_sound _ _ _ _ _ _ g (biGraph' _) x); auto. + apply (@right_sound _ _ _ _ _ _ g (biGraph' _) x); auto. Qed. Definition left_right_sound0': forall (g: Graph') (x: addr) lr, evalid g (x, lr) -> src g (x, lr) = x. Proof. intros. destruct lr. + pose proof @valid_graph' _ _ _ _ g _ (maGraph' _) (x, L) H. pose proof (@only_two_edges _ _ _ _ g _ _ (biGraph' _) _ (x, L) H0). simpl in H1. destruct H1 as [? _]. specialize (H1 (conj eq_refl H)). destruct H1; inversion H1. rewrite <- ! H3; auto. + pose proof @valid_graph' _ _ _ _ g _ (maGraph' _) (x, R) H. pose proof (@only_two_edges _ _ _ _ g _ _ (biGraph' _) _ (x, R) H0). simpl in H1. destruct H1 as [? _]. specialize (H1 (conj eq_refl H)). destruct H1; inversion H1. rewrite <- ! H3; auto. Qed. Lemma weak_valid_vvalid_dec: forall (g : Graph) (x: addr), weak_valid g x -> Decidable (vvalid g x). Proof. intros. apply null_or_valid in H. destruct H; [right | left]; auto. pose proof valid_not_null g x; tauto. Qed. Hint Resolve weak_valid_vvalid_dec : GraphDec. Lemma invalid_null: forall (g: Graph), ~ vvalid g null. Proof. intros. pose proof @valid_not_null _ _ _ _ g _ (maGraph g) null. cbv beta delta [is_null_SGBA] in H; simpl in H. tauto. Qed. Lemma vvalid_vguard: forall (g: Graph) x, vvalid g x -> vguard g x. Proof. intros. pose proof biGraph g. simpl. split; [| split; [| split]]. + apply left_valid with (x0 := x) in H0; auto. + apply right_valid with (x0 := x) in H0; auto. + pose proof (proj2 (only_two_edges x (x, L) H)). specialize (H1 (or_introl eq_refl)). tauto. + pose proof (proj2 (only_two_edges x (x, R) H)). specialize (H1 (or_intror eq_refl)). tauto. Qed. Lemma vvalid_vguard': forall (g: Graph') x, vvalid g x -> vguard g x. Proof. intros. pose proof biGraph' g. simpl. split; [| split; [| split]]. + apply left_valid with (x0 := x) in H0; auto. + apply right_valid with (x0 := x) in H0; auto. + pose proof (proj2 (only_two_edges x (x, L) H)). specialize (H1 (or_introl eq_refl)). tauto. + pose proof (proj2 (only_two_edges x (x, R) H)). specialize (H1 (or_intror eq_refl)). tauto. Qed. Definition Graph_gen_left_null (G : Graph) (x : addr) : Graph. Proof. refine (generalgraph_gen_dst G (x, L) null _). assert (weak_valid G null) by (left; reflexivity). refine (Build_BiMaFin _ (gen_dst_preserve_bi G (x, L) null _) (gen_dst_preserve_math G (x, L) null ma H) (gen_dst_preserve_finite G (x, L) null (finGraph G))). Defined. Definition Graph_gen_right_null (G : Graph) (x : addr) : Graph. Proof. refine (generalgraph_gen_dst G (x, R) null _). assert (weak_valid G null) by (left; reflexivity). refine (Build_BiMaFin _ (gen_dst_preserve_bi G (x, R) null _) (gen_dst_preserve_math G (x, R) null ma H) (gen_dst_preserve_finite G (x, R) null (finGraph G))). Defined. Ltac s_rewrite p := let H := fresh "H" in pose proof p as H; simpl in H; rewrite H; clear H. Lemma Graph_vgen_vgamma: forall (G: Graph) (x: addr) (d d': DV) l r, vgamma G x = (d, l, r) -> vgamma (Graph_vgen G x d') x = (d', l, r). Proof. intros. simpl in H |- *. inversion H; subst. f_equal. f_equal. unfold update_vlabel. destruct_eq_dec x x; [| congruence]. auto. Qed. (* Lemma Graph_gen_spatial_spec: forall (G: Graph) (x: addr) (d d': DV) l r, vgamma G x = (d, l, r) -> (Graph_gen G x d') -=- (spatialgraph_vgen G x (d', l, r)). Proof. intros. split; [reflexivity | split; [| auto]]. simpl in *; intros. simpl in *; unfold update_vlabel. destruct_eq_dec x v; subst. + inversion H; subst; f_equal; f_equal. + auto. Qed. (* TODO: This lemma is not true. They are not even structural identical. But we should change the definition of validly identical or some how fix this. *) Lemma Graph_gen_left_null_spatial_spec: forall (G: Graph) (x: addr) (d : DV) l r, vgamma G x = (d, l, r) -> (Graph_gen_left_null G x) -=- (spatialgraph_vgen G x (d, null, r)). Proof. intros. split; [|split; [| auto]]. + split; [|split; [|split]]; intros; simpl; intuition. unfold Graph_gen_left_null in H0. simpl in H0. unfold spatialgraph_vgen in H1. simpl in H1. + intros. simpl. unfold Graph_gen_left_null. unfold generalgraph_gen_dst. simpl. unfold update_dst. destruct_eq_dec (x, L) (v, L). - destruct_eq_dec (x, L) (v, R). inversion H3. inversion H2. destruct_eq_dec v v. 2: exfalso; auto. simpl in H. inversion H; subst; auto. - destruct_eq_dec (x, L) (v, R). inversion H3. destruct_eq_dec x v. * subst. exfalso; auto. * auto. Qed. *) Lemma weak_valid_si: forall (g1 g2: Graph) n, g1 ~=~ g2 -> (weak_valid g1 n <-> weak_valid g2 n). Proof. intros. unfold weak_valid. destruct H as [? _]. rewrite H. reflexivity. Qed. Lemma gamma_step: forall (g : Graph) x (d: DV) (l r: addr), vvalid g x -> vgamma g x = (d, l, r) -> forall y, step g x y <-> y = l \/ y = r. Proof. intros. simpl in H0; inversion H0; subst. rewrite step_spec; split; intros. + destruct H1 as [e [? [? ?]]]. pose proof (only_two_edges x e H). cbv beta in H4. pose proof (proj1 H4 (conj H2 H1)). destruct H5; subst e; auto. + destruct H1. - exists (x, L). s_rewrite (left_sound g); auto. apply (left_valid g) in H. auto. - exists (x, R). s_rewrite (right_sound g); auto. apply (right_valid g) in H. auto. Qed. Lemma gamma_left_weak_valid: forall (g : Graph) x d l r, vvalid g x -> vgamma g x = (d, l, r) -> weak_valid g l. Proof. intros. simpl in H0. inversion H0. pose proof valid_graph g (x, L). spec H1; [pose proof (left_valid g); auto |]. tauto. Qed. Hint Resolve gamma_left_weak_valid : GraphDec. Lemma gamma_right_weak_valid: forall (g : Graph) x d l r, vvalid g x -> vgamma g x = (d, l, r) -> weak_valid g r. Proof. intros. simpl in H0. inversion H0. pose proof valid_graph g (x, R). spec H1; [pose proof (right_valid g); auto |]. tauto. Qed. Hint Resolve gamma_right_weak_valid : GraphDec. Lemma gamma_step_list: forall (g : Graph) x d l r, vvalid g x -> vgamma g x = (d, l, r) -> step_list g x (l :: r :: nil). Proof. intros. unfold step_list. intros y. rewrite gamma_step by eauto. simpl. pose proof (@eq_sym _ l y). pose proof (@eq_sym _ r y). pose proof (@eq_sym _ y l). pose proof (@eq_sym _ y r). tauto. Qed. Lemma gamma_step_list': forall (g : Graph) x d l r, vvalid g x -> vgamma g x = (d, l, r) -> step_list g x (r :: l :: nil). Proof. intros. unfold step_list. intros y. rewrite gamma_step by eauto. simpl. pose proof (@eq_sym _ l y). pose proof (@eq_sym _ r y). pose proof (@eq_sym _ y l). pose proof (@eq_sym _ y r). tauto. Qed. Lemma Graph_reachable_dec: forall (G: Graph) x, Decidable (vvalid G x) -> forall y, Decidable (reachable G x y). Proof. intros. apply reachable_decidable with (is_null := is_null_SGBA); auto. + apply maGraph. + apply LocalFiniteGraph_FiniteGraph, finGraph. + apply FiniteGraph_EnumCovered, finGraph. Qed. Hint Resolve Graph_reachable_dec : GraphDec. Lemma Graph_reachable_by_dec: forall (G: Graph) x (P: NodePred addr), Decidable (vvalid G x) -> ReachDecidable G x P. Proof. intros. intro y. apply reachable_by_decidable with (is_null := is_null_SGBA); auto. + apply maGraph. + apply LocalFiniteGraph_FiniteGraph, finGraph. + apply FiniteGraph_EnumCovered, finGraph. Qed. (* Lemma Graph_partialgraph_vi_spec: forall (G G': Graph) (P P': addr -> Prop), (predicate_partialgraph G P) ~=~ (predicate_partialgraph G' P') -> (forall v, vvalid G v -> P v -> vvalid G' v -> P' v -> vlabel G v = vlabel G' v) -> (predicate_partial_spatialgraph G P) -=- (predicate_partial_spatialgraph G' P'). Proof. intros. split; [auto |]. split; [| intros; simpl; auto]. simpl; unfold predicate_vvalid. intros. f_equal; [f_equal |]. + apply H0; tauto. + destruct H as [_ [_ [_ ?]]]. generalize (left_sound G v); intro. generalize (left_sound G' v); intro. apply H; simpl; unfold predicate_weak_evalid. - destruct H1. apply (left_valid G) in H1. change (pg_lg G) with (G: PGraph). rewrite H3. auto. - destruct H2. apply (left_valid G') in H2. change (pg_lg G') with (G': PGraph). rewrite H4. auto. + destruct H as [_ [_ [_ ?]]]. generalize (right_sound G v); intro. generalize (right_sound G' v); intro. apply H; simpl; unfold predicate_weak_evalid. - destruct H1. apply (right_valid G) in H1. change (pg_lg G) with (G: PGraph). rewrite H3. auto. - destruct H2. apply (right_valid G') in H2. change (pg_lg G') with (G': PGraph). rewrite H4. auto. Qed. *) Lemma gamma_left_reachable_included: forall (g: Graph) x d l r, vvalid g x -> vgamma g x = (d, l, r) -> Included (reachable g l) (reachable g x). Proof. intros. intro y; intros. apply edge_reachable_by with l; auto. split; auto. split. + apply reachable_head_valid in H1; auto. + rewrite (gamma_step _ _ _ _ _ H H0). auto. Qed. Lemma gamma_right_reachable_included: forall (g: Graph) x d l r, vvalid g x -> vgamma g x = (d, l, r) -> Included (reachable g r) (reachable g x). Proof. intros. intro y; intros. apply edge_reachable_by with r; auto. split; auto. split. + apply reachable_head_valid in H1; auto. + rewrite (gamma_step _ _ _ _ _ H H0). auto. Qed. Lemma Prop_join_reachable_left: forall (g: Graph) x d l r, vvalid g x -> vgamma g x = (d, l, r) -> Prop_join (reachable g l) (Intersection _ (reachable g x) (Complement addr (reachable g l))) (reachable g x). Proof. intros. apply Ensemble_join_Intersection_Complement. - eapply gamma_left_reachable_included; eauto. - intros. apply gamma_left_weak_valid in H0; [| auto]. apply decidable_prop_decidable, Graph_reachable_dec, weak_valid_vvalid_dec; auto. Qed. Lemma Prop_join_reachable_right: forall (g: Graph) x d l r, vvalid g x -> vgamma g x = (d, l, r) -> Prop_join (reachable g r) (Intersection _ (reachable g x) (Complement addr (reachable g r))) (reachable g x). Proof. intros. apply Ensemble_join_Intersection_Complement. - eapply gamma_right_reachable_included; eauto. - intros. apply gamma_right_weak_valid in H0; [| auto]. apply decidable_prop_decidable, Graph_reachable_dec, weak_valid_vvalid_dec; auto. Qed. Lemma dst_L_eq: forall (g1 g2: Graph) x, vvalid g1 x -> g1 ~=~ g2 -> dst g1 (x, L) = dst g2 (x, L). Proof. intros. destruct H0 as [? [? [? ?]]]. assert (vvalid g2 x) by (clear - H H0; firstorder). apply H3. + eapply left_valid in H; [| apply biGraph]. auto. + eapply left_valid in H4; [| apply biGraph]. auto. Qed. Lemma dst_R_eq: forall (g1 g2: Graph) x, vvalid g1 x -> g1 ~=~ g2 -> dst g1 (x, R) = dst g2 (x, R). Proof. intros. destruct H0 as [? [? [? ?]]]. assert (vvalid g2 x) by (clear - H H0; firstorder). apply H3. + eapply right_valid in H; [| apply biGraph]. auto. + eapply right_valid in H4; [| apply biGraph]. auto. Qed. Instance BiMaFin_Normal: NormalGeneralGraph (fun g: LGraph => BiMaFin g). Proof. constructor. + intros. destruct X as [?H ?H ?H]. apply (bi_graph_si _ _ (proj1 H)) in H0. apply (math_graph_si _ _ (proj1 H)) in H1. apply (finite_graph_si _ _ (proj1 H)) in H2. constructor; auto. + intros. destruct X as [?H ?H ?H]. destruct X0 as [?H ?H ?H]. constructor. - eapply bi_graph_join; eauto. - eapply math_graph_join; eauto. - eapply finite_graph_join; eauto. Qed. Instance BiMaFin'_Normal: NormalGeneralGraph (fun g: LGraph => BiMaFin' g). Proof. constructor. + intros. destruct X as [?H ?H ?H]. apply (bi_graph_si _ _ (proj1 H)) in H0. apply (math_graph_si' _ _ (proj1 H)) in H1. apply (finite_graph_si _ _ (proj1 H)) in H2. constructor; auto. + intros. destruct X as [?H ?H ?H]. destruct X0 as [?H ?H ?H]. constructor. - eapply bi_graph_join'; eauto. - eapply math_graph_join'; eauto. - eapply finite_graph_join; eauto. Qed. Lemma Graph_is_BiMaFin: forall (g: Graph), is_BiMaFin g. Proof. intros. destruct g. exists sound_gg; auto. Qed. Lemma Graph'_is_BiMaFin': forall (g: Graph'), is_BiMaFin' g. Proof. intros. destruct g. exists sound_gg; auto. Qed. Lemma single_vertex_guarded_BiMaFin: forall (x0: addr) dv de dg, is_guarded_BiMaFin (fun v : addr => x0 <> v) (fun _ : addr * LR => ~ False) (single_vertex_labeledgraph x0 dv de dg). Proof. intros. constructor; auto. simpl. constructor. + constructor; simpl; intros. - congruence. - rewrite Intersection_spec in H; destruct H; congruence. + constructor; simpl; intros. - rewrite Intersection_spec in H; destruct H; tauto. - rewrite Intersection_spec in H; destruct H; congruence. + constructor; exists nil; repeat constructor. - inversion H. - inversion H. - simpl; intros. unfold Ensembles.In in H; rewrite Intersection_spec in H; destruct H; congruence. - inversion H. - inversion H. - simpl; intros. unfold Ensembles.In in H; rewrite Intersection_spec in H; destruct H; congruence. Qed. Lemma single_vertex_guarded_BiMaFin': forall (x0: addr) dv de dg, is_guarded_BiMaFin' (fun v : addr => x0 <> v) (fun _ : addr * LR => ~ False) (single_vertex_labeledgraph x0 dv de dg). Proof. intros. constructor; auto. simpl. constructor. + constructor; simpl; intros. - congruence. - rewrite Intersection_spec in H; destruct H; congruence. + constructor; simpl; intros. - rewrite Intersection_spec in H; destruct H; tauto. - rewrite Intersection_spec in H; destruct H; congruence. + constructor; exists nil; repeat constructor. - inversion H. - inversion H. - simpl; intros. unfold Ensembles.In in H; rewrite Intersection_spec in H; destruct H; congruence. - inversion H. - inversion H. - simpl; intros. unfold Ensembles.In in H; rewrite Intersection_spec in H; destruct H; congruence. Qed. Lemma is_BiMaFin_si: forall (g1 g2: LGraph), g1 ~=~ g2 -> is_BiMaFin g1 -> is_BiMaFin g2. Proof. intros. destruct H0 as [[?H ?H ?H] _]. apply (bi_graph_si _ _ H) in H0. apply (math_graph_si _ _ H) in H1. apply (finite_graph_si _ _ H) in H2. constructor; constructor; auto. Qed. Lemma is_BiMaFin_si': forall (g1 g2: LGraph), g1 ~=~ g2 -> is_BiMaFin' g1 -> is_BiMaFin' g2. Proof. intros. destruct H0 as [[?H ?H ?H] _]. apply (bi_graph_si _ _ H) in H0. apply (math_graph_si' _ _ H) in H1. apply (finite_graph_si _ _ H) in H2. constructor; constructor; auto. Qed. Lemma is_guarded_BiMaFin_labeledgraph_add_edge: forall (g: LGraph) PV PE PE' e s d data_e, ~ evalid g e -> Same_set PE' (Intersection _ PE (fun e0 => e0 <> e)) -> is_guarded_BiMaFin PV PE g -> is_guarded_BiMaFin PV PE' (labeledgraph_add_edge g e s d data_e). Proof. unfold is_guarded_BiMaFin. intros. eapply is_BiMaFin_si; [| eassumption]. simpl. rewrite Same_set_spec in H0. split; [| split; [| split]]. + intros; simpl; reflexivity. + intros; simpl. specialize (H0 e0). rewrite !Intersection_spec in *. unfold addValidFunc. rewrite H0. destruct_eq_dec e0 e; [subst |]; try tauto. + simpl; intros. unfold updateEdgeFunc. destruct_eq_dec e e0; auto; subst. specialize (H0 e0). rewrite Intersection_spec in *. destruct H3. tauto. + simpl; intros. unfold updateEdgeFunc. destruct_eq_dec e e0; auto; subst. specialize (H0 e0). rewrite Intersection_spec in *. destruct H3. tauto. Qed. Lemma is_guarded_BiMaFin'_labeledgraph_add_edge: forall (g: LGraph) PV PE PE' e s d data_e, ~ evalid g e -> Same_set PE' (Intersection _ PE (fun e0 => e0 <> e)) -> is_guarded_BiMaFin' PV PE g -> is_guarded_BiMaFin' PV PE' (labeledgraph_add_edge g e s d data_e). Proof. unfold is_guarded_BiMaFin'. intros. eapply is_BiMaFin_si'; [| eassumption]. simpl. rewrite Same_set_spec in H0. split; [| split; [| split]]. + intros; simpl; reflexivity. + intros; simpl. specialize (H0 e0). rewrite !Intersection_spec in *. unfold addValidFunc. rewrite H0. destruct_eq_dec e0 e; [subst |]; try tauto. + simpl; intros. unfold updateEdgeFunc. destruct_eq_dec e e0; auto; subst. specialize (H0 e0). rewrite Intersection_spec in *. destruct H3. tauto. + simpl; intros. unfold updateEdgeFunc. destruct_eq_dec e e0; auto; subst. specialize (H0 e0). rewrite Intersection_spec in *. destruct H3. tauto. Qed. (********************************************************* Spatial Facts Part *********************************************************) Context {sSGG_Bi: sPointwiseGraph_Graph_Bi DV DE}. Lemma va_reachable_dag_unfold: forall (g: Graph) x d l r, vvalid g x -> vgamma g x = (d, l, r) -> reachable_dag_vertices_at x g = vertex_at x (d, l, r) * reachable_through_dag_vertices_at (l :: r :: nil) g. Proof. intros. apply va_reachable_dag_unfold; auto. eapply gamma_step_list; eauto. Qed. Lemma va_reachable_dag_update_unfold: forall (g: Graph) x d l r v, vvalid g x -> vgamma g x = (d, l, r) -> reachable_dag_vertices_at x (Graph_vgen g x v) = vertex_at x (v, l, r) * reachable_through_dag_vertices_at (l :: r :: nil) g. Proof. intros. apply va_reachable_dag_update_unfold; auto. + eapply gamma_step_list; eauto. + eapply Graph_vgen_vgamma; eauto. + unfold Included, Ensembles.In; intros. apply vvalid_vguard. apply reachable_through_set_foot_valid in H1; auto. + unfold Included, Ensembles.In; intros. apply vvalid_vguard. apply reachable_through_set_foot_valid in H1; auto. Qed. Lemma va_reachable_root_stable_ramify: forall (g: Graph) (x: addr) (gx: DV * addr * addr), vgamma g x = gx -> vvalid g x -> @derives pred _ (reachable_vertices_at x g) (vertex_at x gx * (vertex_at x gx -* reachable_vertices_at x g)). Proof. intros; apply va_reachable_root_stable_ramify; auto. Qed. Lemma va_reachable_root_update_ramify: forall (g: Graph) (x: addr) (lx: DV) (gx gx': DV * addr * addr), vvalid g x -> vgamma g x = gx -> vgamma (Graph_vgen g x lx) x = gx' -> @derives pred _ (reachable_vertices_at x g) (vertex_at x gx * (vertex_at x gx' -* reachable_vertices_at x (Graph_vgen g x lx))). Proof. intros. apply va_reachable_root_update_ramify; auto. + unfold Included, Ensembles.In; intros. apply vvalid_vguard. rewrite Intersection_spec in H2. destruct H2 as [? _]. apply reachable_foot_valid in H2; auto. + unfold Included, Ensembles.In; intros. apply vvalid_vguard. rewrite Intersection_spec in H2. destruct H2 as [? _]. apply reachable_foot_valid in H2; auto. Qed. Lemma va_reachable_internal_stable_ramify: forall (g: Graph) (x y: addr) (gy: DV * addr * addr), vvalid g y -> vgamma g y = gy -> reachable g x y -> @derives pred _ (reachable_vertices_at x g) (vertex_at y gy * (vertex_at y gy -* reachable_vertices_at x g)). Proof. intros. apply va_reachable_internal_stable_ramify; auto. Qed. (* TODO: maybe as a general lemma for normal_general_graph Lemma is_guarded_BiMaFin_si: forall (g1 g2: LGraph), *) Lemma is_BiMaFin_LGraph_Graph: forall (g: LGraph) (P: LGraph -> pred), is_BiMaFin g -> P g |-- EX g: Graph, P g. Proof. intros. destruct H as [X _]. apply (exp_right (Build_GeneralGraph _ _ _ BiMaFin g X)). simpl. auto. Qed. Lemma va_labeledgraph_add_edge_eq: forall (g: LGraph) es e s d data, ~ evalid g e -> is_guarded_BiMaFin (fun x => s <> x) (fun e => ~ In e es) g -> let g' := labeledgraph_add_edge g e s d data in @vertices_at _ _ _ _ _ _ SGP _ (Intersection _ (vvalid g) (fun x => s <> x)) (Graph_PointwiseGraph g) = @vertices_at _ _ _ _ _ _ SGP _ (Intersection _ (vvalid g') (fun x => s <> x)) (Graph_PointwiseGraph g'). Proof. intros. apply va_labeledgraph_add_edge_eq; auto. + unfold Included, Ensembles.In. intros x0 ?. destruct H0 as [X _]. pose (g0 := Build_GeneralGraph _ _ _ (fun g => BiMaFin (pg_lg g)) _ X: Graph). assert (vvalid g0 x0) by auto. apply vvalid_vguard in H0. simpl in H0 |- *. rewrite !Intersection_spec in H0. tauto. + unfold Included, Ensembles.In. intros x0 ?. destruct H0 as [X _]. pose (g0 := Build_GeneralGraph _ _ _ (fun g => BiMaFin (pg_lg g)) _ X: Graph). assert (vvalid g0 x0) by auto. apply vvalid_vguard in H0. simpl in H0 |- *. rewrite !Intersection_spec in H0. unfold addValidFunc, updateEdgeFunc. split; [| split]; [tauto | tauto |]. destruct_eq_dec e (x0, L); subst; [tauto |]. destruct_eq_dec e (x0, R); subst; [tauto |]. tauto. Qed. Lemma va_labeledgraph_add_edge_eq': forall (g: LGraph) es e s d data, ~ evalid g e -> is_guarded_BiMaFin' (fun x => s <> x) (fun e => ~ In e es) g -> let g' := labeledgraph_add_edge g e s d data in @vertices_at _ _ _ _ _ _ SGP _ (Intersection _ (vvalid g) (fun x => s <> x)) (Graph_PointwiseGraph g) = @vertices_at _ _ _ _ _ _ SGP _ (Intersection _ (vvalid g') (fun x => s <> x)) (Graph_PointwiseGraph g'). Proof. intros. apply Graph.va_labeledgraph_add_edge_eq; auto. + unfold Included, Ensembles.In. intros x0 ?. destruct H0 as [X _]. pose (g0 := Build_GeneralGraph _ _ _ (fun g => BiMaFin' (pg_lg g)) _ X: Graph'). assert (vvalid g0 x0) by auto. apply vvalid_vguard' in H0. simpl in H0 |- *. rewrite !Intersection_spec in H0. tauto. + unfold Included, Ensembles.In. intros x0 ?. destruct H0 as [X _]. pose (g0 := Build_GeneralGraph _ _ _ (fun g => BiMaFin' (pg_lg g)) _ X: Graph'). assert (vvalid g0 x0) by auto. apply vvalid_vguard' in H0. simpl in H0 |- *. rewrite !Intersection_spec in H0. unfold addValidFunc, updateEdgeFunc. split; [| split]; [tauto | tauto |]. destruct_eq_dec e (x0, L); subst; [tauto |]. destruct_eq_dec e (x0, R); subst; [tauto |]. tauto. Qed. Lemma va_labeledgraph_egen_eq: forall (g: LGraph) e data P, @vertices_at _ _ _ _ _ _ SGP _ P (Graph_PointwiseGraph g) = @vertices_at _ _ _ _ _ _ SGP _ P (Graph_PointwiseGraph (labeledgraph_egen g e data)). Proof. intros. apply vertices_at_vertices_identical. rewrite vertices_identical_spec; intros. simpl; auto. Qed. (********************************************************* Spatial Facts (with Strong Assumption) Part *********************************************************) Context {SGSA: PointwiseGraphStrongAssum SGP}. Notation graph x g := (@reachable_vertices_at _ _ _ _ _ _ _ _ (_) _ (@SGP pSGG_Bi DV DE sSGG_Bi) _ x g). Lemma bi_graph_unfold: forall (g: Graph) x d l r, vvalid g x -> vgamma g x = (d, l, r) -> graph x g = vertex_at x (d, l, r) ⊗ graph l g ⊗ graph r g. Proof. intros. rewrite graph_unfold with (S := (l :: r :: nil)); auto. + change (Graph_PointwiseGraph g) with (LGraph_SGraph g). rewrite H0. simpl. rewrite ocon_emp. rewrite <- ocon_assoc. auto. + apply RGF. + intros. apply weak_valid_vvalid_dec. simpl in H1. destruct H1; [|destruct H1]; [subst x0 ..|exfalso; auto]. - apply (gamma_left_weak_valid _ x d l r); auto. - apply (gamma_right_weak_valid _ x d l r); auto. + apply (gamma_step_list _ _ d l r); auto. Qed. Lemma bi_graph_precise_left: forall (g: Graph) x l, vvalid g x -> dst g (x, L) = l -> precise (graph l g). Proof. intros. apply precise_graph. 1: apply RGF. apply weak_valid_vvalid_dec. pose proof (left_valid g x H). simpl in H1. destruct (@valid_graph _ _ _ _ g _ (maGraph g) (x, L) H1). rewrite H0 in H3. apply H3. Qed. Lemma bi_graph_precise_right: forall (g: Graph) x r, vvalid g x -> dst g (x, R) = r -> precise (graph r g). Proof. intros. apply precise_graph. 1: apply RGF. apply weak_valid_vvalid_dec. pose proof (right_valid g x H). simpl in H1. destruct (@valid_graph _ _ _ _ g _ (maGraph g) (x, R) H1). rewrite H0 in H3. apply H3. Qed. Lemma reachable_through_set_unreachable: forall (g: Graph) (S1 S2: list addr) (v: addr), reachable_through_set (predicate_partialgraph g (Intersection addr (vvalid g) (Complement addr (reachable_through_set g S1)))) S2 v -> Complement addr (reachable_through_set g S1) v. Proof. intros. hnf in H. destruct H as [s [? ?]]. unfold Complement. unfold Ensembles.In . rewrite <- reachable_by_eq_partialgraph_reachable in H0. apply reachable_by_foot_prop in H0. rewrite Intersection_spec in H0. destruct H0. unfold Complement, Ensembles.In in H1. auto. Qed. Lemma unreachable_partialgraph_si_vertices_identical: forall (g g': Graph) (S1 S1' S2: list addr), (predicate_partial_labeledgraph g (Complement addr (reachable_through_set g S1))) ~=~ (predicate_partial_labeledgraph g' (Complement addr (reachable_through_set g' S1')))%LabeledGraph -> vertices_identical2 (reachable_through_set (predicate_partialgraph g (Intersection addr (vvalid g) (Complement addr (reachable_through_set g S1)))) S2) (reachable_through_set (predicate_partialgraph g' (Intersection addr (vvalid g') (Complement addr (reachable_through_set g' S1')))) S2) (Graph_PointwiseGraph g) (Graph_PointwiseGraph g'). Proof. intros. apply GSG_PartialGraphPreserve2. - unfold Included, Ensembles.In. intros. apply vvalid_vguard. apply reachable_through_set_foot_valid in H0. destruct H0; auto. - unfold Included, Ensembles.In. intros. apply vvalid_vguard. apply reachable_through_set_foot_valid in H0. destruct H0; auto. - unfold Included, Ensembles.In. intros. apply reachable_through_set_foot_valid in H0. destruct H0; auto. - unfold Included, Ensembles.In. intros. apply reachable_through_set_foot_valid in H0. destruct H0; auto. - assert ((predicate_partialgraph g (Intersection addr (vvalid g) (Complement addr (reachable_through_set g S1)))) ~=~ (predicate_partialgraph g' (Intersection addr (vvalid g') (Complement addr (reachable_through_set g' S1'))))). { destruct H as [[? [? [? ?]]] _]. hnf. simpl in *. unfold predicate_vvalid in *. unfold predicate_weak_evalid in *. split; [|split; [|split]]; intros; rewrite !Intersection_spec in *. - clear -H. specialize (H v). intuition. - clear H2. specialize (H0 e). specialize (H1 e). intuition. + rewrite <- H2 in *. specialize (H (src g e)). intuition. + rewrite H2 in *. specialize (H (src g' e)). intuition. - apply H1; intuition. - apply H2; intuition. } rewrite <- H0. destruct H as [[? [? [? ?]]] [? ?]]. hnf. unfold structurally_identical. simpl in *. unfold predicate_vvalid in *. unfold predicate_weak_evalid in *. split; [split; [|split; [|split]] |split]; intros. + clear -H H0. intuition. * apply reachable_through_set_unreachable in H3. specialize (H v). intuition. * rewrite H0 in H3. apply reachable_through_set_unreachable in H3. specialize (H v). intuition. + clear -H1 H2 H0. specialize (H1 e). specialize (H2 e). intuition. * apply reachable_through_set_unreachable in H5. apply H1 in H5. intuition. * pose proof H5. apply reachable_through_set_unreachable in H5. specialize (H3 H5). specialize (H1 H5). specialize (H3 H1). rewrite <- H3. auto. * rewrite H0 in H5. apply reachable_through_set_unreachable in H5. specialize (H3 H5). intuition. * pose proof H5. rewrite H0 in H5. apply reachable_through_set_unreachable in H5. specialize (H3 H5). destruct H3. specialize (H1 H3 H6). assert (src g e = src g' e) by (apply H1; auto). rewrite H7. auto. + destruct H6, H7. rewrite H0 in H9. apply reachable_through_set_unreachable in H8. apply reachable_through_set_unreachable in H9. apply H2; auto. + destruct H6, H7. rewrite H0 in H9. apply reachable_through_set_unreachable in H8. apply reachable_through_set_unreachable in H9. apply H3; auto. + destruct H6, H7. rewrite H0 in H9. apply reachable_through_set_unreachable in H8. apply reachable_through_set_unreachable in H9. apply H4; auto. + destruct H6, H7. rewrite H0 in H9. apply reachable_through_set_unreachable in H8. apply reachable_through_set_unreachable in H9. apply H5; auto. Qed. Lemma subgraph_update: forall (g g': Graph) (S1 S1' S2: list addr), (forall x : addr, In x (S1 ++ S2) -> Decidable (vvalid g x)) -> (forall x : addr, In x (S1' ++ S2) -> Decidable (vvalid g' x)) -> (predicate_partial_labeledgraph g (Complement addr (reachable_through_set g S1))) ~=~ (predicate_partial_labeledgraph g' (Complement addr (reachable_through_set g' S1')))%LabeledGraph -> @derives pred _ (graphs S1 g ⊗ graphs S2 g) (graphs S1 g * (graphs S1' g' -* graphs S1' g' ⊗ graphs S2 g')). Proof. intros. apply subgraph_update; auto. + apply RGF. + apply RGF. + apply unreachable_partialgraph_si_vertices_identical; auto. + apply Included_trans with (vvalid g). - hnf; intros. apply reachable_through_set_foot_valid in H0. destruct H0; auto. - intro v; apply vvalid_vguard. + apply Included_trans with (vvalid g'). - hnf; intros. apply reachable_through_set_foot_valid in H0. destruct H0; auto. - intro v; apply vvalid_vguard. Qed. End GRAPH_BI.
/- Copyright (c) 2019 Seul Baek. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Seul Baek ! This file was ported from Lean 3 source module data.list.func ! leanprover-community/mathlib commit d11893b411025250c8e61ff2f12ccbd7ee35ab15 ! Please do not edit these lines, except to modify the commit id ! if you have ported upstream changes. -/ import Mathbin.Data.Nat.Order.Basic /-! # Lists as Functions > THIS FILE IS SYNCHRONIZED WITH MATHLIB4. > Any changes to this file require a corresponding PR to mathlib4. Definitions for using lists as finite representations of finitely-supported functions with domain ℕ. These include pointwise operations on lists, as well as get and set operations. ## Notations An index notation is introduced in this file for setting a particular element of a list. With `as` as a list `m` as an index, and `a` as a new element, the notation is `as {m ↦ a}`. So, for example `[1, 3, 5] {1 ↦ 9}` would result in `[1, 9, 5]` This notation is in the locale `list.func`. -/ open List universe u v w variable {α : Type u} {β : Type v} {γ : Type w} namespace List namespace Func variable {a : α} variable {as as1 as2 as3 : List α} #print List.Func.neg /- /-- Elementwise negation of a list -/ def neg [Neg α] (as : List α) := as.map fun a => -a #align list.func.neg List.Func.neg -/ variable [Inhabited α] [Inhabited β] #print List.Func.set /- /-- Update element of a list by index. If the index is out of range, extend the list with default elements -/ @[simp] def set (a : α) : List α → ℕ → List α | _ :: as, 0 => a :: as | [], 0 => [a] | h :: as, k + 1 => h :: Set as k | [], k + 1 => default :: Set ([] : List α) k #align list.func.set List.Func.set -/ -- mathport name: list.func.set scoped notation as " {" m " ↦ " a "}" => List.Func.set a as m #print List.Func.get /- /-- Get element of a list by index. If the index is out of range, return the default element -/ @[simp] def get : ℕ → List α → α | _, [] => default | 0, a :: as => a | n + 1, a :: as => get n as #align list.func.get List.Func.get -/ #print List.Func.Equiv /- /-- Pointwise equality of lists. If lists are different lengths, compare with the default element. -/ def Equiv (as1 as2 : List α) : Prop := ∀ m : Nat, get m as1 = get m as2 #align list.func.equiv List.Func.Equiv -/ #print List.Func.pointwise /- /-- Pointwise operations on lists. If lists are different lengths, use the default element. -/ @[simp] def pointwise (f : α → β → γ) : List α → List β → List γ | [], [] => [] | [], b :: bs => map (f default) (b :: bs) | a :: as, [] => map (fun x => f x default) (a :: as) | a :: as, b :: bs => f a b :: pointwise as bs #align list.func.pointwise List.Func.pointwise -/ #print List.Func.add /- /-- Pointwise addition on lists. If lists are different lengths, use zero. -/ def add {α : Type u} [Zero α] [Add α] : List α → List α → List α := @pointwise α α α ⟨0⟩ ⟨0⟩ (· + ·) #align list.func.add List.Func.add -/ #print List.Func.sub /- /-- Pointwise subtraction on lists. If lists are different lengths, use zero. -/ def sub {α : Type u} [Zero α] [Sub α] : List α → List α → List α := @pointwise α α α ⟨0⟩ ⟨0⟩ (@Sub.sub α _) #align list.func.sub List.Func.sub -/ /- warning: list.func.length_set -> List.Func.length_set is a dubious translation: lean 3 declaration is forall {α : Type.{u1}} {a : α} [_inst_1 : Inhabited.{succ u1} α] {m : Nat} {as : List.{u1} α}, Eq.{1} Nat (List.length.{u1} α (List.Func.set.{u1} α _inst_1 a as m)) (LinearOrder.max.{0} Nat Nat.linearOrder (List.length.{u1} α as) (HAdd.hAdd.{0, 0, 0} Nat Nat Nat (instHAdd.{0} Nat Nat.hasAdd) m (OfNat.ofNat.{0} Nat 1 (OfNat.mk.{0} Nat 1 (One.one.{0} Nat Nat.hasOne))))) but is expected to have type forall {α : Type.{u1}} {a : α} [_inst_1 : Inhabited.{succ u1} α] {m : Nat} {as : List.{u1} α}, Eq.{1} Nat (List.length.{u1} α (List.Func.set.{u1} α _inst_1 a as m)) (Max.max.{0} Nat Nat.instMaxNat (List.length.{u1} α as) (HAdd.hAdd.{0, 0, 0} Nat Nat Nat (instHAdd.{0} Nat instAddNat) m (OfNat.ofNat.{0} Nat 1 (instOfNatNat 1)))) Case conversion may be inaccurate. Consider using '#align list.func.length_set List.Func.length_setₓ'. -/ -- set theorem length_set : ∀ {m : ℕ} {as : List α}, as {m ↦ a}.length = max as.length (m + 1) | 0, [] => rfl | 0, a :: as => by rw [max_eq_left] rfl simp [Nat.le_add_right] | m + 1, [] => by simp only [Set, Nat.zero_max, length, @length_set m] | m + 1, a :: as => by simp only [Set, Nat.max_succ_succ, length, @length_set m] #align list.func.length_set List.Func.length_set #print List.Func.get_nil /- @[simp] theorem get_nil {k : ℕ} : (get k [] : α) = default := by cases k <;> rfl #align list.func.get_nil List.Func.get_nil -/ #print List.Func.get_eq_default_of_le /- theorem get_eq_default_of_le : ∀ (k : ℕ) {as : List α}, as.length ≤ k → get k as = default | 0, [], h1 => rfl | 0, a :: as, h1 => by cases h1 | k + 1, [], h1 => rfl | k + 1, a :: as, h1 => by apply get_eq_default_of_le k rw [← Nat.succ_le_succ_iff]; apply h1 #align list.func.get_eq_default_of_le List.Func.get_eq_default_of_le -/ #print List.Func.get_set /- @[simp] theorem get_set {a : α} : ∀ {k : ℕ} {as : List α}, get k (as {k ↦ a}) = a | 0, as => by cases as <;> rfl | k + 1, as => by cases as <;> simp [get_set] #align list.func.get_set List.Func.get_set -/ /- warning: list.func.eq_get_of_mem clashes with [anonymous] -> [anonymous] warning: list.func.eq_get_of_mem -> [anonymous] is a dubious translation: lean 3 declaration is forall {α : Type.{u}} [_inst_1 : Inhabited.{succ u} α] {a : α} {as : List.{u} α}, (Membership.Mem.{u, u} α (List.{u} α) (List.hasMem.{u} α) a as) -> (Exists.{1} Nat (fun (n : Nat) => α -> (Eq.{succ u} α a (List.Func.get.{u} α _inst_1 n as)))) but is expected to have type forall {α : Type.{u}} {_inst_1 : Type.{v}}, (Nat -> α -> _inst_1) -> Nat -> (List.{u} α) -> (List.{v} _inst_1) Case conversion may be inaccurate. Consider using '#align list.func.eq_get_of_mem [anonymous]ₓ'. -/ theorem [anonymous] {a : α} : ∀ {as : List α}, a ∈ as → ∃ n : Nat, ∀ d : α, a = get n as | [], h => by cases h | b :: as, h => by rw [mem_cons_iff] at h; cases h · exists 0 intro d apply h · cases' eq_get_of_mem h with n h2 exists n + 1 apply h2 #align list.func.eq_get_of_mem [anonymous] #print List.Func.mem_get_of_le /- theorem mem_get_of_le : ∀ {n : ℕ} {as : List α}, n < as.length → get n as ∈ as | _, [], h1 => by cases h1 | 0, a :: as, _ => Or.inl rfl | n + 1, a :: as, h1 => by apply Or.inr; unfold get apply mem_get_of_le apply Nat.lt_of_succ_lt_succ h1 #align list.func.mem_get_of_le List.Func.mem_get_of_le -/ #print List.Func.mem_get_of_ne_zero /- theorem mem_get_of_ne_zero : ∀ {n : ℕ} {as : List α}, get n as ≠ default → get n as ∈ as | _, [], h1 => by exfalso; apply h1; rw [get_nil] | 0, a :: as, h1 => Or.inl rfl | n + 1, a :: as, h1 => by unfold get apply Or.inr (mem_get_of_ne_zero _) apply h1 #align list.func.mem_get_of_ne_zero List.Func.mem_get_of_ne_zero -/ #print List.Func.get_set_eq_of_ne /- theorem get_set_eq_of_ne {a : α} : ∀ {as : List α} (k : ℕ) (m : ℕ), m ≠ k → get m (as {k ↦ a}) = get m as | as, 0, m, h1 => by cases m contradiction cases as <;> simp only [Set, get, get_nil] | as, k + 1, m, h1 => by cases as <;> cases m simp only [Set, get] · have h3 : get m (nil {k ↦ a}) = default := by rw [get_set_eq_of_ne k m, get_nil] intro hc apply h1 simp [hc] apply h3 simp only [Set, get] · apply get_set_eq_of_ne k m intro hc apply h1 simp [hc] #align list.func.get_set_eq_of_ne List.Func.get_set_eq_of_ne -/ #print List.Func.get_map /- theorem get_map {f : α → β} : ∀ {n : ℕ} {as : List α}, n < as.length → get n (as.map f) = f (get n as) | _, [], h => by cases h | 0, a :: as, h => rfl | n + 1, a :: as, h1 => by have h2 : n < length as := by rw [← Nat.succ_le_iff, ← Nat.lt_succ_iff] apply h1 apply get_map h2 #align list.func.get_map List.Func.get_map -/ #print List.Func.get_map' /- theorem get_map' {f : α → β} {n : ℕ} {as : List α} : f default = default → get n (as.map f) = f (get n as) := by intro h1; by_cases h2 : n < as.length · apply get_map h2 · rw [not_lt] at h2 rw [get_eq_default_of_le _ h2, get_eq_default_of_le, h1] rw [length_map] apply h2 #align list.func.get_map' List.Func.get_map' -/ #print List.Func.forall_val_of_forall_mem /- theorem forall_val_of_forall_mem {as : List α} {p : α → Prop} : p default → (∀ x ∈ as, p x) → ∀ n, p (get n as) := by intro h1 h2 n by_cases h3 : n < as.length · apply h2 _ (mem_get_of_le h3) · rw [not_lt] at h3 rw [get_eq_default_of_le _ h3] apply h1 #align list.func.forall_val_of_forall_mem List.Func.forall_val_of_forall_mem -/ #print List.Func.equiv_refl /- -- equiv theorem equiv_refl : Equiv as as := fun k => rfl #align list.func.equiv_refl List.Func.equiv_refl -/ #print List.Func.equiv_symm /- theorem equiv_symm : Equiv as1 as2 → Equiv as2 as1 := fun h1 k => (h1 k).symm #align list.func.equiv_symm List.Func.equiv_symm -/ #print List.Func.equiv_trans /- theorem equiv_trans : Equiv as1 as2 → Equiv as2 as3 → Equiv as1 as3 := fun h1 h2 k => Eq.trans (h1 k) (h2 k) #align list.func.equiv_trans List.Func.equiv_trans -/ #print List.Func.equiv_of_eq /- theorem equiv_of_eq : as1 = as2 → Equiv as1 as2 := by intro h1; rw [h1]; apply equiv_refl #align list.func.equiv_of_eq List.Func.equiv_of_eq -/ #print List.Func.eq_of_equiv /- theorem eq_of_equiv : ∀ {as1 as2 : List α}, as1.length = as2.length → Equiv as1 as2 → as1 = as2 | [], [], h1, h2 => rfl | _ :: _, [], h1, h2 => by cases h1 | [], _ :: _, h1, h2 => by cases h1 | a1 :: as1, a2 :: as2, h1, h2 => by congr · apply h2 0 have h3 : as1.length = as2.length := by simpa [add_left_inj, add_comm, length] using h1 apply eq_of_equiv h3 intro m apply h2 (m + 1) #align list.func.eq_of_equiv List.Func.eq_of_equiv -/ end Func -- We want to drop the `inhabited` instances for a moment, -- so we close and open the namespace namespace Func /- warning: list.func.get_neg -> List.Func.get_neg is a dubious translation: lean 3 declaration is forall {α : Type.{u1}} [_inst_1 : AddGroup.{u1} α] {k : Nat} {as : List.{u1} α}, Eq.{succ u1} α (List.Func.get.{u1} α (Inhabited.mk.{succ u1} α (OfNat.ofNat.{u1} α 0 (OfNat.mk.{u1} α 0 (Zero.zero.{u1} α (AddZeroClass.toHasZero.{u1} α (AddMonoid.toAddZeroClass.{u1} α (SubNegMonoid.toAddMonoid.{u1} α (AddGroup.toSubNegMonoid.{u1} α _inst_1)))))))) k (List.Func.neg.{u1} α (SubNegMonoid.toHasNeg.{u1} α (AddGroup.toSubNegMonoid.{u1} α _inst_1)) as)) (Neg.neg.{u1} α (SubNegMonoid.toHasNeg.{u1} α (AddGroup.toSubNegMonoid.{u1} α _inst_1)) (List.Func.get.{u1} α (Inhabited.mk.{succ u1} α (OfNat.ofNat.{u1} α 0 (OfNat.mk.{u1} α 0 (Zero.zero.{u1} α (AddZeroClass.toHasZero.{u1} α (AddMonoid.toAddZeroClass.{u1} α (SubNegMonoid.toAddMonoid.{u1} α (AddGroup.toSubNegMonoid.{u1} α _inst_1)))))))) k as)) but is expected to have type forall {α : Type.{u1}} [_inst_1 : AddGroup.{u1} α] {k : Nat} {as : List.{u1} α}, Eq.{succ u1} α (List.Func.get.{u1} α (Inhabited.mk.{succ u1} α (OfNat.ofNat.{u1} α 0 (Zero.toOfNat0.{u1} α (NegZeroClass.toZero.{u1} α (SubNegZeroMonoid.toNegZeroClass.{u1} α (SubtractionMonoid.toSubNegZeroMonoid.{u1} α (AddGroup.toSubtractionMonoid.{u1} α _inst_1))))))) k (List.Func.neg.{u1} α (NegZeroClass.toNeg.{u1} α (SubNegZeroMonoid.toNegZeroClass.{u1} α (SubtractionMonoid.toSubNegZeroMonoid.{u1} α (AddGroup.toSubtractionMonoid.{u1} α _inst_1)))) as)) (Neg.neg.{u1} α (NegZeroClass.toNeg.{u1} α (SubNegZeroMonoid.toNegZeroClass.{u1} α (SubtractionMonoid.toSubNegZeroMonoid.{u1} α (AddGroup.toSubtractionMonoid.{u1} α _inst_1)))) (List.Func.get.{u1} α (Inhabited.mk.{succ u1} α (OfNat.ofNat.{u1} α 0 (Zero.toOfNat0.{u1} α (NegZeroClass.toZero.{u1} α (SubNegZeroMonoid.toNegZeroClass.{u1} α (SubtractionMonoid.toSubNegZeroMonoid.{u1} α (AddGroup.toSubtractionMonoid.{u1} α _inst_1))))))) k as)) Case conversion may be inaccurate. Consider using '#align list.func.get_neg List.Func.get_negₓ'. -/ -- neg @[simp] theorem get_neg [AddGroup α] {k : ℕ} {as : List α} : @get α ⟨0⟩ k (neg as) = -@get α ⟨0⟩ k as := by unfold neg rw [@get_map' α α ⟨0⟩] apply neg_zero #align list.func.get_neg List.Func.get_neg #print List.Func.length_neg /- @[simp] theorem length_neg [Neg α] (as : List α) : (neg as).length = as.length := by simp only [neg, length_map] #align list.func.length_neg List.Func.length_neg -/ variable [Inhabited α] [Inhabited β] #print List.Func.nil_pointwise /- -- pointwise theorem nil_pointwise {f : α → β → γ} : ∀ bs : List β, pointwise f [] bs = bs.map (f default) | [] => rfl | b :: bs => by simp only [nil_pointwise bs, pointwise, eq_self_iff_true, and_self_iff, map] #align list.func.nil_pointwise List.Func.nil_pointwise -/ #print List.Func.pointwise_nil /- theorem pointwise_nil {f : α → β → γ} : ∀ as : List α, pointwise f as [] = as.map fun a => f a default | [] => rfl | a :: as => by simp only [pointwise_nil as, pointwise, eq_self_iff_true, and_self_iff, List.map] #align list.func.pointwise_nil List.Func.pointwise_nil -/ #print List.Func.get_pointwise /- theorem get_pointwise [Inhabited γ] {f : α → β → γ} (h1 : f default default = default) : ∀ (k : Nat) (as : List α) (bs : List β), get k (pointwise f as bs) = f (get k as) (get k bs) | k, [], [] => by simp only [h1, get_nil, pointwise, get] | 0, [], b :: bs => by simp only [get_pointwise, get_nil, pointwise, get, Nat.zero_eq, map] | k + 1, [], b :: bs => by have : get k (map (f default) bs) = f default (get k bs) := by simpa [nil_pointwise, get_nil] using get_pointwise k [] bs simpa [get, get_nil, pointwise, map] | 0, a :: as, [] => by simp only [get_pointwise, get_nil, pointwise, get, Nat.zero_eq, map] | k + 1, a :: as, [] => by simpa [get, get_nil, pointwise, map, pointwise_nil, get_nil] using get_pointwise k as [] | 0, a :: as, b :: bs => by simp only [pointwise, get] | k + 1, a :: as, b :: bs => by simp only [pointwise, get, get_pointwise k] #align list.func.get_pointwise List.Func.get_pointwise -/ /- warning: list.func.length_pointwise -> List.Func.length_pointwise is a dubious translation: lean 3 declaration is forall {α : Type.{u1}} {β : Type.{u2}} {γ : Type.{u3}} [_inst_1 : Inhabited.{succ u1} α] [_inst_2 : Inhabited.{succ u2} β] {f : α -> β -> γ} {as : List.{u1} α} {bs : List.{u2} β}, Eq.{1} Nat (List.length.{u3} γ (List.Func.pointwise.{u1, u2, u3} α β γ _inst_1 _inst_2 f as bs)) (LinearOrder.max.{0} Nat Nat.linearOrder (List.length.{u1} α as) (List.length.{u2} β bs)) but is expected to have type forall {α : Type.{u1}} {β : Type.{u2}} {γ : Type.{u3}} [_inst_1 : Inhabited.{succ u1} α] [_inst_2 : Inhabited.{succ u2} β] {f : α -> β -> γ} {as : List.{u1} α} {bs : List.{u2} β}, Eq.{1} Nat (List.length.{u3} γ (List.Func.pointwise.{u1, u2, u3} α β γ _inst_1 _inst_2 f as bs)) (Max.max.{0} Nat Nat.instMaxNat (List.length.{u1} α as) (List.length.{u2} β bs)) Case conversion may be inaccurate. Consider using '#align list.func.length_pointwise List.Func.length_pointwiseₓ'. -/ theorem length_pointwise {f : α → β → γ} : ∀ {as : List α} {bs : List β}, (pointwise f as bs).length = max as.length bs.length | [], [] => rfl | [], b :: bs => by simp only [pointwise, length, length_map, max_eq_right (Nat.zero_le (length bs + 1))] | a :: as, [] => by simp only [pointwise, length, length_map, max_eq_left (Nat.zero_le (length as + 1))] | a :: as, b :: bs => by simp only [pointwise, length, Nat.max_succ_succ, @length_pointwise as bs] #align list.func.length_pointwise List.Func.length_pointwise end Func namespace Func /- warning: list.func.get_add -> List.Func.get_add is a dubious translation: lean 3 declaration is forall {α : Type.{u1}} [_inst_1 : AddMonoid.{u1} α] {k : Nat} {xs : List.{u1} α} {ys : List.{u1} α}, Eq.{succ u1} α (List.Func.get.{u1} α (Inhabited.mk.{succ u1} α (OfNat.ofNat.{u1} α 0 (OfNat.mk.{u1} α 0 (Zero.zero.{u1} α (AddZeroClass.toHasZero.{u1} α (AddMonoid.toAddZeroClass.{u1} α _inst_1)))))) k (List.Func.add.{u1} α (AddZeroClass.toHasZero.{u1} α (AddMonoid.toAddZeroClass.{u1} α _inst_1)) (AddZeroClass.toHasAdd.{u1} α (AddMonoid.toAddZeroClass.{u1} α _inst_1)) xs ys)) (HAdd.hAdd.{u1, u1, u1} α α α (instHAdd.{u1} α (AddZeroClass.toHasAdd.{u1} α (AddMonoid.toAddZeroClass.{u1} α _inst_1))) (List.Func.get.{u1} α (Inhabited.mk.{succ u1} α (OfNat.ofNat.{u1} α 0 (OfNat.mk.{u1} α 0 (Zero.zero.{u1} α (AddZeroClass.toHasZero.{u1} α (AddMonoid.toAddZeroClass.{u1} α _inst_1)))))) k xs) (List.Func.get.{u1} α (Inhabited.mk.{succ u1} α (OfNat.ofNat.{u1} α 0 (OfNat.mk.{u1} α 0 (Zero.zero.{u1} α (AddZeroClass.toHasZero.{u1} α (AddMonoid.toAddZeroClass.{u1} α _inst_1)))))) k ys)) but is expected to have type forall {α : Type.{u1}} [_inst_1 : AddMonoid.{u1} α] {k : Nat} {xs : List.{u1} α} {ys : List.{u1} α}, Eq.{succ u1} α (List.Func.get.{u1} α (Inhabited.mk.{succ u1} α (OfNat.ofNat.{u1} α 0 (Zero.toOfNat0.{u1} α (AddMonoid.toZero.{u1} α _inst_1)))) k (List.Func.add.{u1} α (AddMonoid.toZero.{u1} α _inst_1) (AddZeroClass.toAdd.{u1} α (AddMonoid.toAddZeroClass.{u1} α _inst_1)) xs ys)) (HAdd.hAdd.{u1, u1, u1} α α α (instHAdd.{u1} α (AddZeroClass.toAdd.{u1} α (AddMonoid.toAddZeroClass.{u1} α _inst_1))) (List.Func.get.{u1} α (Inhabited.mk.{succ u1} α (OfNat.ofNat.{u1} α 0 (Zero.toOfNat0.{u1} α (AddMonoid.toZero.{u1} α _inst_1)))) k xs) (List.Func.get.{u1} α (Inhabited.mk.{succ u1} α (OfNat.ofNat.{u1} α 0 (Zero.toOfNat0.{u1} α (AddMonoid.toZero.{u1} α _inst_1)))) k ys)) Case conversion may be inaccurate. Consider using '#align list.func.get_add List.Func.get_addₓ'. -/ -- add @[simp] theorem get_add {α : Type u} [AddMonoid α] {k : ℕ} {xs ys : List α} : @get α ⟨0⟩ k (add xs ys) = @get α ⟨0⟩ k xs + @get α ⟨0⟩ k ys := by apply get_pointwise apply zero_add #align list.func.get_add List.Func.get_add /- warning: list.func.length_add -> List.Func.length_add is a dubious translation: lean 3 declaration is forall {α : Type.{u1}} [_inst_1 : Zero.{u1} α] [_inst_2 : Add.{u1} α] {xs : List.{u1} α} {ys : List.{u1} α}, Eq.{1} Nat (List.length.{u1} α (List.Func.add.{u1} α _inst_1 _inst_2 xs ys)) (LinearOrder.max.{0} Nat Nat.linearOrder (List.length.{u1} α xs) (List.length.{u1} α ys)) but is expected to have type forall {α : Type.{u1}} [_inst_1 : Zero.{u1} α] [_inst_2 : Add.{u1} α] {xs : List.{u1} α} {ys : List.{u1} α}, Eq.{1} Nat (List.length.{u1} α (List.Func.add.{u1} α _inst_1 _inst_2 xs ys)) (Max.max.{0} Nat Nat.instMaxNat (List.length.{u1} α xs) (List.length.{u1} α ys)) Case conversion may be inaccurate. Consider using '#align list.func.length_add List.Func.length_addₓ'. -/ @[simp] theorem length_add {α : Type u} [Zero α] [Add α] {xs ys : List α} : (add xs ys).length = max xs.length ys.length := @length_pointwise α α α ⟨0⟩ ⟨0⟩ _ _ _ #align list.func.length_add List.Func.length_add /- warning: list.func.nil_add -> List.Func.nil_add is a dubious translation: lean 3 declaration is forall {α : Type.{u1}} [_inst_1 : AddMonoid.{u1} α] (as : List.{u1} α), Eq.{succ u1} (List.{u1} α) (List.Func.add.{u1} α (AddZeroClass.toHasZero.{u1} α (AddMonoid.toAddZeroClass.{u1} α _inst_1)) (AddZeroClass.toHasAdd.{u1} α (AddMonoid.toAddZeroClass.{u1} α _inst_1)) (List.nil.{u1} α) as) as but is expected to have type forall {α : Type.{u1}} [_inst_1 : AddMonoid.{u1} α] (as : List.{u1} α), Eq.{succ u1} (List.{u1} α) (List.Func.add.{u1} α (AddMonoid.toZero.{u1} α _inst_1) (AddZeroClass.toAdd.{u1} α (AddMonoid.toAddZeroClass.{u1} α _inst_1)) (List.nil.{u1} α) as) as Case conversion may be inaccurate. Consider using '#align list.func.nil_add List.Func.nil_addₓ'. -/ @[simp] theorem nil_add {α : Type u} [AddMonoid α] (as : List α) : add [] as = as := by rw [add, @nil_pointwise α α α ⟨0⟩ ⟨0⟩] apply Eq.trans _ (map_id as) congr with x rw [zero_add, id] #align list.func.nil_add List.Func.nil_add /- warning: list.func.add_nil -> List.Func.add_nil is a dubious translation: lean 3 declaration is forall {α : Type.{u1}} [_inst_1 : AddMonoid.{u1} α] (as : List.{u1} α), Eq.{succ u1} (List.{u1} α) (List.Func.add.{u1} α (AddZeroClass.toHasZero.{u1} α (AddMonoid.toAddZeroClass.{u1} α _inst_1)) (AddZeroClass.toHasAdd.{u1} α (AddMonoid.toAddZeroClass.{u1} α _inst_1)) as (List.nil.{u1} α)) as but is expected to have type forall {α : Type.{u1}} [_inst_1 : AddMonoid.{u1} α] (as : List.{u1} α), Eq.{succ u1} (List.{u1} α) (List.Func.add.{u1} α (AddMonoid.toZero.{u1} α _inst_1) (AddZeroClass.toAdd.{u1} α (AddMonoid.toAddZeroClass.{u1} α _inst_1)) as (List.nil.{u1} α)) as Case conversion may be inaccurate. Consider using '#align list.func.add_nil List.Func.add_nilₓ'. -/ @[simp] theorem add_nil {α : Type u} [AddMonoid α] (as : List α) : add as [] = as := by rw [add, @pointwise_nil α α α ⟨0⟩ ⟨0⟩] apply Eq.trans _ (map_id as) congr with x rw [add_zero, id] #align list.func.add_nil List.Func.add_nil /- warning: list.func.map_add_map -> List.Func.map_add_map is a dubious translation: lean 3 declaration is forall {α : Type.{u1}} [_inst_1 : AddMonoid.{u1} α] (f : α -> α) (g : α -> α) {as : List.{u1} α}, Eq.{succ u1} (List.{u1} α) (List.Func.add.{u1} α (AddZeroClass.toHasZero.{u1} α (AddMonoid.toAddZeroClass.{u1} α _inst_1)) (AddZeroClass.toHasAdd.{u1} α (AddMonoid.toAddZeroClass.{u1} α _inst_1)) (List.map.{u1, u1} α α f as) (List.map.{u1, u1} α α g as)) (List.map.{u1, u1} α α (fun (x : α) => HAdd.hAdd.{u1, u1, u1} α α α (instHAdd.{u1} α (AddZeroClass.toHasAdd.{u1} α (AddMonoid.toAddZeroClass.{u1} α _inst_1))) (f x) (g x)) as) but is expected to have type forall {α : Type.{u1}} [_inst_1 : AddMonoid.{u1} α] (f : α -> α) (g : α -> α) {as : List.{u1} α}, Eq.{succ u1} (List.{u1} α) (List.Func.add.{u1} α (AddMonoid.toZero.{u1} α _inst_1) (AddZeroClass.toAdd.{u1} α (AddMonoid.toAddZeroClass.{u1} α _inst_1)) (List.map.{u1, u1} α α f as) (List.map.{u1, u1} α α g as)) (List.map.{u1, u1} α α (fun (x : α) => HAdd.hAdd.{u1, u1, u1} α α α (instHAdd.{u1} α (AddZeroClass.toAdd.{u1} α (AddMonoid.toAddZeroClass.{u1} α _inst_1))) (f x) (g x)) as) Case conversion may be inaccurate. Consider using '#align list.func.map_add_map List.Func.map_add_mapₓ'. -/ theorem map_add_map {α : Type u} [AddMonoid α] (f g : α → α) {as : List α} : add (as.map f) (as.map g) = as.map fun x => f x + g x := by apply @eq_of_equiv _ (⟨0⟩ : Inhabited α) · rw [length_map, length_add, max_eq_left, length_map] apply le_of_eq rw [length_map, length_map] intro m rw [get_add] by_cases h : m < length as · repeat' rw [@get_map α α ⟨0⟩ ⟨0⟩ _ _ _ h] rw [not_lt] at h repeat' rw [get_eq_default_of_le m] <;> try rw [length_map]; apply h apply zero_add #align list.func.map_add_map List.Func.map_add_map /- warning: list.func.get_sub -> List.Func.get_sub is a dubious translation: lean 3 declaration is forall {α : Type.{u1}} [_inst_1 : AddGroup.{u1} α] {k : Nat} {xs : List.{u1} α} {ys : List.{u1} α}, Eq.{succ u1} α (List.Func.get.{u1} α (Inhabited.mk.{succ u1} α (OfNat.ofNat.{u1} α 0 (OfNat.mk.{u1} α 0 (Zero.zero.{u1} α (AddZeroClass.toHasZero.{u1} α (AddMonoid.toAddZeroClass.{u1} α (SubNegMonoid.toAddMonoid.{u1} α (AddGroup.toSubNegMonoid.{u1} α _inst_1)))))))) k (List.Func.sub.{u1} α (AddZeroClass.toHasZero.{u1} α (AddMonoid.toAddZeroClass.{u1} α (SubNegMonoid.toAddMonoid.{u1} α (AddGroup.toSubNegMonoid.{u1} α _inst_1)))) (SubNegMonoid.toHasSub.{u1} α (AddGroup.toSubNegMonoid.{u1} α _inst_1)) xs ys)) (HSub.hSub.{u1, u1, u1} α α α (instHSub.{u1} α (SubNegMonoid.toHasSub.{u1} α (AddGroup.toSubNegMonoid.{u1} α _inst_1))) (List.Func.get.{u1} α (Inhabited.mk.{succ u1} α (OfNat.ofNat.{u1} α 0 (OfNat.mk.{u1} α 0 (Zero.zero.{u1} α (AddZeroClass.toHasZero.{u1} α (AddMonoid.toAddZeroClass.{u1} α (SubNegMonoid.toAddMonoid.{u1} α (AddGroup.toSubNegMonoid.{u1} α _inst_1)))))))) k xs) (List.Func.get.{u1} α (Inhabited.mk.{succ u1} α (OfNat.ofNat.{u1} α 0 (OfNat.mk.{u1} α 0 (Zero.zero.{u1} α (AddZeroClass.toHasZero.{u1} α (AddMonoid.toAddZeroClass.{u1} α (SubNegMonoid.toAddMonoid.{u1} α (AddGroup.toSubNegMonoid.{u1} α _inst_1)))))))) k ys)) but is expected to have type forall {α : Type.{u1}} [_inst_1 : AddGroup.{u1} α] {k : Nat} {xs : List.{u1} α} {ys : List.{u1} α}, Eq.{succ u1} α (List.Func.get.{u1} α (Inhabited.mk.{succ u1} α (OfNat.ofNat.{u1} α 0 (Zero.toOfNat0.{u1} α (NegZeroClass.toZero.{u1} α (SubNegZeroMonoid.toNegZeroClass.{u1} α (SubtractionMonoid.toSubNegZeroMonoid.{u1} α (AddGroup.toSubtractionMonoid.{u1} α _inst_1))))))) k (List.Func.sub.{u1} α (NegZeroClass.toZero.{u1} α (SubNegZeroMonoid.toNegZeroClass.{u1} α (SubtractionMonoid.toSubNegZeroMonoid.{u1} α (AddGroup.toSubtractionMonoid.{u1} α _inst_1)))) (SubNegMonoid.toSub.{u1} α (AddGroup.toSubNegMonoid.{u1} α _inst_1)) xs ys)) (HSub.hSub.{u1, u1, u1} α α α (instHSub.{u1} α (SubNegMonoid.toSub.{u1} α (AddGroup.toSubNegMonoid.{u1} α _inst_1))) (List.Func.get.{u1} α (Inhabited.mk.{succ u1} α (OfNat.ofNat.{u1} α 0 (Zero.toOfNat0.{u1} α (NegZeroClass.toZero.{u1} α (SubNegZeroMonoid.toNegZeroClass.{u1} α (SubtractionMonoid.toSubNegZeroMonoid.{u1} α (AddGroup.toSubtractionMonoid.{u1} α _inst_1))))))) k xs) (List.Func.get.{u1} α (Inhabited.mk.{succ u1} α (OfNat.ofNat.{u1} α 0 (Zero.toOfNat0.{u1} α (NegZeroClass.toZero.{u1} α (SubNegZeroMonoid.toNegZeroClass.{u1} α (SubtractionMonoid.toSubNegZeroMonoid.{u1} α (AddGroup.toSubtractionMonoid.{u1} α _inst_1))))))) k ys)) Case conversion may be inaccurate. Consider using '#align list.func.get_sub List.Func.get_subₓ'. -/ -- sub @[simp] theorem get_sub {α : Type u} [AddGroup α] {k : ℕ} {xs ys : List α} : @get α ⟨0⟩ k (sub xs ys) = @get α ⟨0⟩ k xs - @get α ⟨0⟩ k ys := by apply get_pointwise apply sub_zero #align list.func.get_sub List.Func.get_sub /- warning: list.func.length_sub -> List.Func.length_sub is a dubious translation: lean 3 declaration is forall {α : Type.{u1}} [_inst_1 : Zero.{u1} α] [_inst_2 : Sub.{u1} α] {xs : List.{u1} α} {ys : List.{u1} α}, Eq.{1} Nat (List.length.{u1} α (List.Func.sub.{u1} α _inst_1 _inst_2 xs ys)) (LinearOrder.max.{0} Nat Nat.linearOrder (List.length.{u1} α xs) (List.length.{u1} α ys)) but is expected to have type forall {α : Type.{u1}} [_inst_1 : Zero.{u1} α] [_inst_2 : Sub.{u1} α] {xs : List.{u1} α} {ys : List.{u1} α}, Eq.{1} Nat (List.length.{u1} α (List.Func.sub.{u1} α _inst_1 _inst_2 xs ys)) (Max.max.{0} Nat Nat.instMaxNat (List.length.{u1} α xs) (List.length.{u1} α ys)) Case conversion may be inaccurate. Consider using '#align list.func.length_sub List.Func.length_subₓ'. -/ @[simp] theorem length_sub [Zero α] [Sub α] {xs ys : List α} : (sub xs ys).length = max xs.length ys.length := @length_pointwise α α α ⟨0⟩ ⟨0⟩ _ _ _ #align list.func.length_sub List.Func.length_sub /- warning: list.func.nil_sub -> List.Func.nil_sub is a dubious translation: lean 3 declaration is forall {α : Type.{u1}} [_inst_1 : AddGroup.{u1} α] (as : List.{u1} α), Eq.{succ u1} (List.{u1} α) (List.Func.sub.{u1} α (AddZeroClass.toHasZero.{u1} α (AddMonoid.toAddZeroClass.{u1} α (SubNegMonoid.toAddMonoid.{u1} α (AddGroup.toSubNegMonoid.{u1} α _inst_1)))) (SubNegMonoid.toHasSub.{u1} α (AddGroup.toSubNegMonoid.{u1} α _inst_1)) (List.nil.{u1} α) as) (List.Func.neg.{u1} α (SubNegMonoid.toHasNeg.{u1} α (AddGroup.toSubNegMonoid.{u1} α _inst_1)) as) but is expected to have type forall {α : Type.{u1}} [_inst_1 : AddGroup.{u1} α] (as : List.{u1} α), Eq.{succ u1} (List.{u1} α) (List.Func.sub.{u1} α (NegZeroClass.toZero.{u1} α (SubNegZeroMonoid.toNegZeroClass.{u1} α (SubtractionMonoid.toSubNegZeroMonoid.{u1} α (AddGroup.toSubtractionMonoid.{u1} α _inst_1)))) (SubNegMonoid.toSub.{u1} α (AddGroup.toSubNegMonoid.{u1} α _inst_1)) (List.nil.{u1} α) as) (List.Func.neg.{u1} α (NegZeroClass.toNeg.{u1} α (SubNegZeroMonoid.toNegZeroClass.{u1} α (SubtractionMonoid.toSubNegZeroMonoid.{u1} α (AddGroup.toSubtractionMonoid.{u1} α _inst_1)))) as) Case conversion may be inaccurate. Consider using '#align list.func.nil_sub List.Func.nil_subₓ'. -/ @[simp] theorem nil_sub {α : Type _} [AddGroup α] (as : List α) : sub [] as = neg as := by rw [sub, nil_pointwise] congr with x rw [zero_sub] #align list.func.nil_sub List.Func.nil_sub /- warning: list.func.sub_nil -> List.Func.sub_nil is a dubious translation: lean 3 declaration is forall {α : Type.{u1}} [_inst_1 : AddGroup.{u1} α] (as : List.{u1} α), Eq.{succ u1} (List.{u1} α) (List.Func.sub.{u1} α (AddZeroClass.toHasZero.{u1} α (AddMonoid.toAddZeroClass.{u1} α (SubNegMonoid.toAddMonoid.{u1} α (AddGroup.toSubNegMonoid.{u1} α _inst_1)))) (SubNegMonoid.toHasSub.{u1} α (AddGroup.toSubNegMonoid.{u1} α _inst_1)) as (List.nil.{u1} α)) as but is expected to have type forall {α : Type.{u1}} [_inst_1 : AddGroup.{u1} α] (as : List.{u1} α), Eq.{succ u1} (List.{u1} α) (List.Func.sub.{u1} α (NegZeroClass.toZero.{u1} α (SubNegZeroMonoid.toNegZeroClass.{u1} α (SubtractionMonoid.toSubNegZeroMonoid.{u1} α (AddGroup.toSubtractionMonoid.{u1} α _inst_1)))) (SubNegMonoid.toSub.{u1} α (AddGroup.toSubNegMonoid.{u1} α _inst_1)) as (List.nil.{u1} α)) as Case conversion may be inaccurate. Consider using '#align list.func.sub_nil List.Func.sub_nilₓ'. -/ @[simp] theorem sub_nil {α : Type _} [AddGroup α] (as : List α) : sub as [] = as := by rw [sub, pointwise_nil] apply Eq.trans _ (map_id as) congr with x rw [sub_zero, id] #align list.func.sub_nil List.Func.sub_nil end Func end List
[STATEMENT] lemma iIN_icard: "icard [n\<dots>,d] = enat (Suc d)" [PROOF STATE] proof (prove) goal (1 subgoal): 1. icard [n\<dots>,d] = enat (Suc d) [PROOF STEP] by (simp add: icard_finite iT_finite iT_card)
(* Author: David Sanan Maintainer: David Sanan, sanan at ntu edu sg License: LGPL *) (* Title: XVCGCon.thy Author: David Sanan, NTU Copyright (C) 2015-2016 David Sanan Some rights reserved, NTU This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA *) theory XVcgCon imports VcgCon begin text {* We introduce a syntactic variant of the let-expression so that we can safely unfold it during verification condition generation. With the new theorem attribute @{text "vcg_simp"} we can declare equalities to be used by the verification condition generator, while simplifying assertions. *} syntax "_Let'" :: "[letbinds, basicblock] => basicblock" ("(LET (_)/ IN (_))" 23) translations "_Let' (_binds b bs) e" == "_Let' b (_Let' bs e)" "_Let' (_bind x a) e" == "CONST Let' a (%x. e)" lemma Let'_unfold [vcg_simp]: "Let' x f = f x" by (simp add: Let'_def Let_def) lemma Let'_split_conv [vcg_simp]: "(Let' x (\<lambda>p. (case_prod (f p) (g p)))) = (Let' x (\<lambda>p. (f p) (fst (g p)) (snd (g p))))" by (simp add: split_def) end
clear; close all; clc; %% % Plot settings markerSize=10; markerSize2=10; fontSize=15; faceAlpha1=0.3; faceAlpha2=0.5; cMap=gjet(4); %% Control parameters % Path names defaultFolder = fileparts(fileparts(mfilename('fullpath'))); savePath=fullfile(defaultFolder,'data','temp'); % Defining file names febioFebFileNamePart='tempModel'; febioFebFileName=fullfile(savePath,[febioFebFileNamePart,'.feb']); %FEB file name febioLogFileName=[febioFebFileNamePart,'.txt']; %FEBio log file name febioLogFileName_disp=[febioFebFileNamePart,'_disp_out.txt']; %Log file name for exporting displacement febioLogFileName_force=[febioFebFileNamePart,'_force_out.txt']; %Log file name for exporting force febioLogFileName_sed=[febioFebFileNamePart,'_stress_out.txt']; %Log file name for exporting strain energy density tireWidth = 120; tireRadius = 150; tireThickness = 8; threadHeight = 8; tireBulge=tireWidth/8; pointSpacing = 8; tireCircumference = 2*pi.*tireRadius; numFeatures = 20; groveWidth = 8; distKeep=75; %Distance after which model is cropped, empty = full model displacementVert=0.8*tireThickness; displacementHor=-tireRadius/20; contactInitialOffset=0.1; %Material parameter set c1=1e-3; %Shear-modulus-like parameter m1=2; %Material parameter setting degree of non-linearity k_factor=100; %Bulk modulus factor k=c1*k_factor; %Bulk modulus % FEA control settings numTimeSteps=20; %Number of time steps desired max_refs=40; %Max reforms max_ups=0; %Set to zero to use full-Newton iterations opt_iter=25; %Optimum number of iterations max_retries=5; %Maximum number of retires dtmin=(1/numTimeSteps)/100; %Minimum time step size dtmax=1/numTimeSteps; %Maximum time step size runMode='external';%'internal'; min_residual=1e-20; %Contact parameters contactPenalty=5; laugon=0; minaug=1; maxaug=10; fric_coeff=0.5; %% tireHalfWidth=tireWidth/2; featureHeight = (tireCircumference-(numFeatures*groveWidth))./numFeatures; featureWidth = tireHalfWidth-2*groveWidth; % Coordinates of 1x1 square v=[-1 -1 0;... 1 -1 0;... 1 1 0;... -1 1 0]/2; % Deformation gradient tensor for shear f=eye(3,3); f(1,2)=1; %Create boundary coordinates V1=v; %Copy square V1(:,1)=V1(:,1).*tireCircumference+tireCircumference/2; %Stretch to create circumference V1(:,2)=V1(:,2).*tireHalfWidth+tireHalfWidth/2; %Stretch to get desired width V1=evenlySpaceCurve(V1,pointSpacing,'linear',1,1:1:size(v,1)); %Evenly sample V1=(f*V1')'; %Shear %Create thread feature Vf=v; %Copy square Vf(:,1)=Vf(:,1).*featureHeight; %Stretch to create circumference Vf(:,2)=Vf(:,2).*(featureWidth+groveWidth/2)+tireHalfWidth/2-groveWidth/4; %Stretch to get desired width Vf=evenlySpaceCurve(Vf,pointSpacing,'linear',1,1:1:size(v,1)); %Evenly sample Vf(:,1)=Vf(:,1)+featureHeight/2+groveWidth/2; VF=cell(1,numFeatures); for q=1:1:numFeatures Vff=Vf; Vff(:,1)=Vf(:,1)+(q-1).*(featureHeight+groveWidth); %Shift VF{q}=(f*Vff')'; %Shear and store end %% %Defining 4 regions regionSpec{1}={V1(:,[1 2])}; for q=1:1:numFeatures regionSpec{1}{q+1}=VF{q}(:,[1 2]); end for q=1:1:numFeatures regionSpec{q+1}{1}=VF{q}(:,[1 2]); end [Ft,Vt,Ct]=multiRegionTriMesh2D(regionSpec,pointSpacing,0,0); Vt(:,3)=0; Fb=fliplr(Ft); Vb=Vt; Vb(:,2)=-Vb(:,2); Cb=Ct; Cb(Cb>1)=Cb(Cb>1)-1+max(Ct); [F,V,C]=joinElementSets({Ft,Fb},{Vt,Vb},{Ct,Cb}); [F,V]=mergeVertices(F,V); %% cFigure; hold on; plotV(V1,'r.-','MarkerSize',markerSize); plotV(VF,'b.-','MarkerSize',markerSize); gpatch(F,V,C); axisGeom(gca,fontSize); view(2); colormap spectral; icolorbar; gdrawnow; %% cMax=max(C); numVert=size(V,1); F2=F(C>1,:); C2=C(C>1,:)+cMax; Eb1=patchBoundary(F2); Eb2=Eb1+numVert; F=[F(C==1,:);F2+numVert]; V=[V;V]; C=[C(C==1,:);C2+max(C(:))]; %% % if tireBulge>eps(0) w=tireWidth; h=tireBulge; r=h/2+(w^2/(8*h)); a=atan((w/2)./(r-h)); TH = (V(:,2)./tireHalfWidth)*a; R = r.*ones(size(V,1),1); R(numVert+1:end)=R(numVert+1:end)+threadHeight; Z = V(:,1); [V(:,1),V(:,2),V(:,3)] = pol2cart(TH,R,Z); V=V(:,[3 2 1]); V(:,3)=V(:,3)-r+h; else V(numVert+1:end,3)=V(numVert+1:end,3)+threadHeight; end %% cFigure; hold on; plotV(V1,'r.-','MarkerSize',markerSize); plotV(VF,'b.-','MarkerSize',markerSize); gpatch(F,V,C); axisGeom(gca,fontSize); view(2); colormap spectral; icolorbar; gdrawnow; %% TH = V(:,1)./tireRadius; R = tireRadius+V(:,3); Z = V(:,2); [V(:,1),V(:,2),V(:,3)] = pol2cart(TH,R,Z); V=V(:,[1 3 2]); F=fliplr(F); [Eb1,V1]=patchCleanUnused(Eb1,V); [Eb2,V2]=patchCleanUnused(Eb2,V); [F,V,~,indFix]=mergeVertices(F,V); numSteps=ceil(threadHeight./pointSpacing)+1; %Create quadrilateral faces X=linspacen(V1(:,1),V2(:,1),numSteps); Y=linspacen(V1(:,2),V2(:,2),numSteps); Z=linspacen(V1(:,3),V2(:,3),numSteps); Vn=[X(:) Y(:) Z(:)]; %Vertex set Fn=repmat([fliplr(Eb1) Eb2],numSteps-1,1); q=repmat(0:(numSteps-2),size(Eb1,1),1); q=q(:); Q=[q q q+1 q+1]*size(V1,1); Fn=Fn+Q; [Fn,Vn]=quad2tri(Fn,Vn,'a'); %% [F,V]=patchCleanUnused(F,V); C(C>1)=2; %Switch to use 2 for all thread profile parts [F_out,V_out,C_out]=joinElementSets({F,Fn},{V,Vn},{C,max(C(:))+1*ones(size(Fn,1),1)}); [F_out,V_out]=patchCleanUnused(F_out,V_out); [F_out,V_out]=mergeVertices(F_out,V_out); Eb_out=patchBoundary(F_out); %% cFigure; hold on; gpatch(F_out,V_out,C_out); % patchNormPlot(Fq,Vq); axisGeom(gca,fontSize); camlight headlight; colormap spectral; icolorbar; gdrawnow; %% % Create inner cylinder inputStructCyl.cylRadius=tireRadius-tireThickness; inputStructCyl.numRadial=ceil((2*pi*inputStructCyl.cylRadius)/pointSpacing); inputStructCyl.cylHeight=tireWidth; numheight=ceil(tireWidth./pointSpacing); numheight=numheight+iseven(numheight); %Force uneven inputStructCyl.numHeight=numheight; inputStructCyl.meshType='tri'; %% % Derive patch data for a cylinder [F_in,V_in]=patchcylinder(inputStructCyl); V_in=V_in(:,[1 3 2]); Eb_in=patchBoundary(F_in); C_in=(max(C_out)+1)*ones(size(F_in,1),1); %% inputStructGroup.outputType='label'; G_out=tesgroup(Eb_out,inputStructGroup); G_in=tesgroup(Eb_in,inputStructGroup); yMean_out=nan(2,1); yMean_in=nan(2,1); for q=1:1:2 ind_out=Eb_out(G_out==q,:); yMean_out(q)=mean(V_out(ind_out(:),2)); ind_in=Eb_in(G_in==q,:); yMean_in(q)=mean(V_in(ind_in(:),2)); end [~,ind1_out]=min(yMean_out); [~,ind2_out]=max(yMean_out); indCurve1_out=edgeListToCurve(Eb_out(G_out==ind1_out,:)); indCurve1_out=indCurve1_out(1:end-1); indCurve2_out=edgeListToCurve(Eb_out(G_out==ind2_out,:)); indCurve2_out=indCurve2_out(1:end-1); [~,ind1_in]=min(yMean_in); [~,ind2_in]=max(yMean_in); indCurve1_in=edgeListToCurve(Eb_in(G_in==ind1_in,:)); indCurve1_in=indCurve1_in(1:end-1); indCurve2_in=edgeListToCurve(Eb_in(G_in==ind2_in,:)); indCurve2_in=indCurve2_in(1:end-1); [Fs1,Vs1]=regionTriMesh2D({V_out(indCurve1_out,[1 3]),V_in(indCurve1_in,[1 3])},pointSpacing,0); Vs1(:,3)=-tireWidth/2; Vs1=Vs1(:,[1 3 2]); Cs1=(max(C_in)+1)*ones(size(Fs1,1),1); [Fs2,Vs2]=regionTriMesh2D({V_out(indCurve2_out,[1 3]),V_in(indCurve2_in,[1 3])},pointSpacing,0); Vs2(:,3)=tireWidth/2; Vs2=Vs2(:,[1 3 2]); Fs2=fliplr(Fs2); Cs2=(max(Cs1)+1)*ones(size(Fs2,1),1); %% [FT,VT,CT]=joinElementSets({F_out,F_in,Fs1,Fs2},{V_out,V_in,Vs1,Vs2},{C_out,C_in,Cs1,Cs2}); [FT,VT]=patchCleanUnused(FT,VT); [FT,VT]=mergeVertices(FT,VT); %% cFigure; hold on; gpatch(FT,VT,CT,'none'); patchNormPlot(FT,VT); axisGeom(gca,fontSize); camlight headlight; colormap spectral; icolorbar; gdrawnow; %% V_regions=getInnerPoint(FT,VT); %Define region points V_holes=[]; %Define hole points [regionTetVolumes]=tetVolMeanEst(FT,VT); %Volume estimate for regular tets stringOpt='-pq1.2AaY'; %Options for tetgen %% % Mesh using TetGen %Create tetgen input structure inputStruct.stringOpt=stringOpt; %Tetgen options inputStruct.Faces=FT; %Boundary faces inputStruct.Nodes=VT; %Nodes of boundary inputStruct.faceBoundaryMarker=CT; inputStruct.regionPoints=V_regions; %Interior points for regions inputStruct.holePoints=V_holes; %Interior points for holes inputStruct.regionA=regionTetVolumes; %Desired tetrahedral volume for each region % Mesh model using tetrahedral elements using tetGen [meshOutput]=runTetGen(inputStruct); %Run tetGen %% % Access mesh output structure E=meshOutput.elements; %The elements V=meshOutput.nodes; %The vertices or nodes Fb=meshOutput.facesBoundary; %The boundary faces Cb=meshOutput.boundaryMarker; %The boundary markers %% % Visualization hf=cFigure; subplot(1,2,1); hold on; title('Input boundaries','FontSize',fontSize); hp(1)=gpatch(Fb,V,Cb,'k',faceAlpha1); hp(2)=plotV(V_regions,'r.','MarkerSize',markerSize); legend(hp,{'Input mesh','Interior point(s)'},'Location','NorthWestOutside'); axisGeom(gca,fontSize); camlight headlight; colormap(cMap); icolorbar; hs=subplot(1,2,2); hold on; title('Tetrahedral mesh','FontSize',fontSize); % Visualizing using |meshView| optionStruct.hFig=[hf,hs]; meshView(meshOutput,optionStruct); axisGeom(gca,fontSize); gdrawnow; %% if ~isempty(distKeep) Fb_full=Fb; V_full=V; [Fb_full,V_full]=patchCleanUnused(Fb_full,V_full); VE=patchCentre(E,V); logicKeepElements = VE(:,3) <= (min(VE(:,3))+distKeep); E=E(logicKeepElements,:); indKeepNodes=unique(E); logicKeep_Fb=all(ismember(Fb,indKeepNodes),2); Fb=Fb(logicKeep_Fb,:); Cb=Cb(logicKeep_Fb,:); logicKeep_F=all(ismember(F,indKeepNodes),2); F=F(logicKeep_F,:); [E,V,indFix]=patchCleanUnused(E,V); Fb=indFix(Fb); F=indFix(F); meshOutput.nodes=V; meshOutput.facesBoundary=Fb; meshOutput.boundaryMarker=Cb; meshOutput.faces=F; meshOutput.elements=E; meshOutput.elementMaterialID=ones(size(E,1),1); else Fb_full=Fb; V_full=V; end %% hf=cFigure; subplot(1,2,1); hold on; title('Input boundaries','FontSize',fontSize); hp(1)=gpatch(Fb,V,Cb,'k',faceAlpha1); hp(2)=plotV(V_regions,'r.','MarkerSize',markerSize); legend(hp,{'Input mesh','Interior point(s)'},'Location','NorthWestOutside'); axisGeom(gca,fontSize); camlight headlight; colormap(cMap); icolorbar; hs=subplot(1,2,2); hold on; title('Tetrahedral mesh','FontSize',fontSize); % Visualizing using |meshView| optionStruct.hFig=[hf,hs]; meshView(meshOutput,optionStruct); axisGeom(gca,fontSize); gdrawnow; %% plateDim=[2*tireRadius tireWidth]; plateEl=ceil(plateDim./pointSpacing); [Eg,Vg]=quadPlate(plateDim,plateEl); Vg(:,3)=Vg(:,3)+min(VT(:,3))-contactInitialOffset; center_of_mass=mean(Vg,1); %% Joining node sets Eg=Eg+size(V,1); %Fixed element indices V=[V;Vg;]; %Combined node sets %% cFigure; hold on; hp(1)=gpatch(Fb,V,Cb,'k',faceAlpha1); hp(2)=gpatch(Eg,V,'kw','k',faceAlpha1); % legend(hp,{'Input mesh','Interior point(s)'},'Location','NorthWestOutside'); axisGeom(gca,fontSize); camlight headlight; colormap(cMap); icolorbar; gdrawnow; %% Define contact surfaces % The rigid master surface of the sphere F_contact_secondary=Eg; % The deformable slave surface of the slab logicContactSurf1=Cb==2; F_contact_primary=fliplr(Fb(logicContactSurf1,:)); % Plotting surface models cFigure; hold on; title('Contact sets and normal directions','FontSize',fontSize); gpatch(Fb,V,'kw','none',faceAlpha2); hl(1)=gpatch(F_contact_secondary,V,'g','k',1); patchNormPlot(F_contact_secondary,V); hl(2)=gpatch(F_contact_primary,V,'b','k',1); patchNormPlot(F_contact_primary,V); legend(hl,{'Secondary','Primary'}); axisGeom(gca,fontSize); camlight headlight; drawnow; %% Define boundary conditions %Supported nodes bcSupportList=unique(Fb(Cb==4,:)); %% % Visualize BC's hf=cFigure; title('Boundary conditions model','FontSize',fontSize); xlabel('X','FontSize',fontSize); ylabel('Y','FontSize',fontSize); zlabel('Z','FontSize',fontSize); hold on; gpatch(Fb,V,'w','none',faceAlpha2); hl2(1)=gpatch(Eg,V,'gw','k',1); hl2(2)=plotV(V(bcSupportList,:),'k.','MarkerSize',markerSize); legend(hl2,{'Rigid body plate','BC support'}); axisGeom(gca,fontSize); camlight headlight; drawnow; %% Defining the FEBio input structure % See also |febioStructTemplate| and |febioStruct2xml| and the FEBio user % manual. %Get a template with default settings [febio_spec]=febioStructTemplate; %febio_spec version febio_spec.ATTR.version='3.0'; %Module section febio_spec.Module.ATTR.type='solid'; %Create control structure for use by all steps febio_spec.Control.analysis='STATIC'; stepStruct.Control.time_steps=numTimeSteps; stepStruct.Control.step_size=1/numTimeSteps; stepStruct.Control.solver.max_refs=max_refs; stepStruct.Control.solver.max_ups=max_ups; stepStruct.Control.solver.symmetric_stiffness=0; febio_spec.Control.solver.min_residual=min_residual; stepStruct.Control.time_stepper.dtmin=dtmin; stepStruct.Control.time_stepper.dtmax=dtmax; stepStruct.Control.time_stepper.max_retries=max_retries; stepStruct.Control.time_stepper.opt_iter=opt_iter; %Add template based default settings to proposed control section [stepStruct.Control]=structComplete(stepStruct.Control,febio_spec.Control,1); %Complement provided with default if missing %Remove control field (part of template) since step specific control sections are used febio_spec=rmfield(febio_spec,'Control'); febio_spec.Step.step{1}.Control=stepStruct.Control; febio_spec.Step.step{1}.ATTR.id=1; febio_spec.Step.step{2}.Control=stepStruct.Control; febio_spec.Step.step{2}.ATTR.id=2; %Material section materialName1='Material1'; febio_spec.Material.material{1}.ATTR.name=materialName1; febio_spec.Material.material{1}.ATTR.type='Ogden'; febio_spec.Material.material{1}.ATTR.id=1; febio_spec.Material.material{1}.c1=c1; febio_spec.Material.material{1}.m1=m1; febio_spec.Material.material{1}.c2=c1; febio_spec.Material.material{1}.m2=-m1; febio_spec.Material.material{1}.k=k; materialName2='Material2'; febio_spec.Material.material{2}.ATTR.name=materialName2; febio_spec.Material.material{2}.ATTR.type='rigid body'; febio_spec.Material.material{2}.ATTR.id=2; febio_spec.Material.material{2}.density=1; febio_spec.Material.material{2}.center_of_mass=center_of_mass; %Mesh section % -> Nodes febio_spec.Mesh.Nodes{1}.ATTR.name='nodeSet_all'; %The node set name febio_spec.Mesh.Nodes{1}.node.ATTR.id=(1:size(V,1))'; %The node id's febio_spec.Mesh.Nodes{1}.node.VAL=V; %The nodel coordinates % -> Elements partName1='Part1'; febio_spec.Mesh.Elements{1}.ATTR.name=partName1; %Name of this part febio_spec.Mesh.Elements{1}.ATTR.type='tet4'; %Element type febio_spec.Mesh.Elements{1}.elem.ATTR.id=(1:1:size(E,1))'; %Element id's febio_spec.Mesh.Elements{1}.elem.VAL=E; %The element matrix partName2='Part2'; febio_spec.Mesh.Elements{2}.ATTR.name=partName2; %Name of this part febio_spec.Mesh.Elements{2}.ATTR.type='quad4'; %Element type febio_spec.Mesh.Elements{2}.elem.ATTR.id=size(E,1)+(1:1:size(Eg,1))'; %Element id's febio_spec.Mesh.Elements{2}.elem.VAL=Eg; %The element matrix % -> NodeSets nodeSetName1='bcSupportList'; febio_spec.Mesh.NodeSet{1}.ATTR.name=nodeSetName1; febio_spec.Mesh.NodeSet{1}.node.ATTR.id=bcSupportList(:); %MeshDomains section febio_spec.MeshDomains.SolidDomain.ATTR.name=partName1; febio_spec.MeshDomains.SolidDomain.ATTR.mat=materialName1; febio_spec.MeshDomains.ShellDomain.ATTR.name=partName2; febio_spec.MeshDomains.ShellDomain.ATTR.mat=materialName2; % -> Surfaces surfaceName1='contactSurface1'; febio_spec.Mesh.Surface{1}.ATTR.name=surfaceName1; febio_spec.Mesh.Surface{1}.quad4.ATTR.id=(1:1:size(F_contact_secondary,1))'; febio_spec.Mesh.Surface{1}.quad4.VAL=F_contact_secondary; surfaceName2='contactSurface2'; febio_spec.Mesh.Surface{2}.ATTR.name=surfaceName2; febio_spec.Mesh.Surface{2}.tri3.ATTR.id=(1:1:size(F_contact_primary,1))'; febio_spec.Mesh.Surface{2}.tri3.VAL=F_contact_primary; % -> Surface pairs febio_spec.Mesh.SurfacePair{1}.ATTR.name='Contact1'; febio_spec.Mesh.SurfacePair{1}.primary=surfaceName2; febio_spec.Mesh.SurfacePair{1}.secondary=surfaceName1; %Boundary condition section % -> Fix boundary conditions febio_spec.Boundary.bc{1}.ATTR.type='fix'; febio_spec.Boundary.bc{1}.ATTR.node_set=nodeSetName1; febio_spec.Boundary.bc{1}.dofs='x,y,z'; %Rigid section % -> Prescribed rigid body boundary conditions febio_spec.Step.step{1}.Rigid.rigid_constraint{1}.ATTR.name='RigidFix_1'; febio_spec.Step.step{1}.Rigid.rigid_constraint{1}.ATTR.type='fix'; febio_spec.Step.step{1}.Rigid.rigid_constraint{1}.rb=2; febio_spec.Step.step{1}.Rigid.rigid_constraint{1}.dofs='Rx,Ry'; febio_spec.Step.step{1}.Rigid.rigid_constraint{2}.ATTR.name='RigidPrescribe'; febio_spec.Step.step{1}.Rigid.rigid_constraint{2}.ATTR.type='prescribe'; febio_spec.Step.step{1}.Rigid.rigid_constraint{2}.rb=2; febio_spec.Step.step{1}.Rigid.rigid_constraint{2}.dof='Rz'; febio_spec.Step.step{1}.Rigid.rigid_constraint{2}.value.ATTR.lc=1; febio_spec.Step.step{1}.Rigid.rigid_constraint{2}.value.VAL=(displacementVert+contactInitialOffset); febio_spec.Step.step{1}.Rigid.rigid_constraint{2}.relative=0; febio_spec.Step.step{2}.Rigid.rigid_constraint{1}.ATTR.name='RigidFix_1'; febio_spec.Step.step{2}.Rigid.rigid_constraint{1}.ATTR.type='fix'; febio_spec.Step.step{2}.Rigid.rigid_constraint{1}.rb=2; febio_spec.Step.step{2}.Rigid.rigid_constraint{1}.dofs='Ry,Rz,Ru,Rv,Rw'; febio_spec.Step.step{2}.Rigid.rigid_constraint{2}.ATTR.name='RigidPrescribe'; febio_spec.Step.step{2}.Rigid.rigid_constraint{2}.ATTR.type='prescribe'; febio_spec.Step.step{2}.Rigid.rigid_constraint{2}.rb=2; febio_spec.Step.step{2}.Rigid.rigid_constraint{2}.dof='Rx'; febio_spec.Step.step{2}.Rigid.rigid_constraint{2}.value.ATTR.lc=2; febio_spec.Step.step{2}.Rigid.rigid_constraint{2}.value.VAL=displacementHor; % febio_spec.Step.step{2}.Rigid.rigid_constraint{2}.relative=1; %Contact section febio_spec.Contact.contact{1}.ATTR.type='sliding-elastic'; febio_spec.Contact.contact{1}.ATTR.surface_pair=febio_spec.Mesh.SurfacePair{1}.ATTR.name; febio_spec.Contact.contact{1}.two_pass=0; febio_spec.Contact.contact{1}.laugon=laugon; febio_spec.Contact.contact{1}.tolerance=0.2; febio_spec.Contact.contact{1}.gaptol=0; febio_spec.Contact.contact{1}.minaug=minaug; febio_spec.Contact.contact{1}.maxaug=maxaug; febio_spec.Contact.contact{1}.search_tol=0.01; febio_spec.Contact.contact{1}.search_radius=0.1*sqrt(sum((max(V,[],1)-min(V,[],1)).^2,2)); febio_spec.Contact.contact{1}.symmetric_stiffness=0; febio_spec.Contact.contact{1}.auto_penalty=1; febio_spec.Contact.contact{1}.penalty=contactPenalty; febio_spec.Contact.contact{1}.fric_coeff=fric_coeff; %LoadData section % -> load_controller febio_spec.LoadData.load_controller{1}.ATTR.id=1; febio_spec.LoadData.load_controller{1}.ATTR.type='loadcurve'; febio_spec.LoadData.load_controller{1}.interpolate='LINEAR'; febio_spec.LoadData.load_controller{1}.points.point.VAL=[0 0; 1 1; 2 1]; febio_spec.LoadData.load_controller{2}.ATTR.id=2; febio_spec.LoadData.load_controller{2}.ATTR.type='loadcurve'; febio_spec.LoadData.load_controller{2}.interpolate='LINEAR'; febio_spec.LoadData.load_controller{2}.points.point.VAL=[0 0; 1 0; 2 1]; %Output section % -> log file febio_spec.Output.logfile.ATTR.file=febioLogFileName; febio_spec.Output.logfile.node_data{1}.ATTR.file=febioLogFileName_disp; febio_spec.Output.logfile.node_data{1}.ATTR.data='ux;uy;uz'; febio_spec.Output.logfile.node_data{1}.ATTR.delim=','; febio_spec.Output.logfile.node_data{1}.VAL=1:size(V,1); febio_spec.Output.logfile.node_data{2}.ATTR.file=febioLogFileName_force; febio_spec.Output.logfile.node_data{2}.ATTR.data='Rx;Ry;Rz'; febio_spec.Output.logfile.node_data{2}.ATTR.delim=','; febio_spec.Output.logfile.node_data{2}.VAL=1:size(V,1); febio_spec.Output.logfile.element_data{1}.ATTR.file=febioLogFileName_sed; febio_spec.Output.logfile.element_data{1}.ATTR.data='sed'; febio_spec.Output.logfile.element_data{1}.ATTR.delim=','; febio_spec.Output.logfile.element_data{1}.VAL=1:size(E,1); %% Quick viewing of the FEBio input file structure % The |febView| function can be used to view the xml structure in a MATLAB % figure window. %% % |febView(febio_spec); %Viewing the febio file| %% Exporting the FEBio input file % Exporting the febio_spec structure to an FEBio input file is done using % the |febioStruct2xml| function. febioStruct2xml(febio_spec,febioFebFileName); %Exporting to file and domNode %% Running the FEBio analysis % To run the analysis defined by the created FEBio input file the % |runMonitorFEBio| function is used. The input for this function is a % structure defining job settings e.g. the FEBio input file name. The % optional output runFlag informs the user if the analysis was run % succesfully. febioAnalysis.run_filename=febioFebFileName; %The input file name febioAnalysis.run_logname=febioLogFileName; %The name for the log file febioAnalysis.disp_on=1; %Display information on the command window febioAnalysis.runMode=runMode; [runFlag]=runMonitorFEBio(febioAnalysis);%START FEBio NOW!!!!!!!! %% Import FEBio results if runFlag==1 %i.e. a succesful run %% % Importing nodal displacements from a log file dataStruct=importFEBio_logfile(fullfile(savePath,febioLogFileName_disp),1,1); %Access data N_disp_mat=dataStruct.data; %Displacement timeVec=dataStruct.time; %Time %Create deformed coordinate set V_DEF=N_disp_mat+repmat(V,[1 1 size(N_disp_mat,3)]); %% % Importing element stress from a log file dataStruct=importFEBio_logfile(fullfile(savePath,febioLogFileName_sed),1,1); %Access data E_sed_mat=dataStruct.data; E_sed_mat(isnan(E_sed_mat))=0; %% % Plotting the simulated results using |anim8| to visualize and animate % deformations [CV]=faceToVertexMeasure(E,V,E_sed_mat(:,:,end)); % Create basic view and store graphics handle to initiate animation hf=cFigure; %Open figure gtitle([febioFebFileNamePart,': Press play to animate']); title('Strain energy density','Interpreter','Latex') gpatch(Fb_full,V_full,'w','none',0.25); hp=gpatch(Fb,V_DEF(:,:,end),CV,'none',1); %Add graphics object to animate % hp.Marker='.'; % hp.MarkerSize=markerSize2; hp.FaceColor='interp'; hp2=gpatch(Eg,V_DEF(:,:,end),'w','none',0.5); %Add graphics object to animate Ebb=patchBoundaryLabelEdges(Fb,V,Cb); hp3=gpatch(Ebb,V_DEF(:,:,end),'none','k',1,3); hp4=gpatch(patchBoundary(Eg),V_DEF(:,:,end),'none','kw',1,3); axisGeom(gca,fontSize); colormap(spectral(250)); colorbar; caxis([0 0.25*max(E_sed_mat(:))]); axis(axisLim(V_DEF,V_full)); %Set axis limits statically camlight headlight; % Set up animation features animStruct.Time=timeVec; %The time vector for qt=1:1:size(N_disp_mat,3) %Loop over time increments [CV]=faceToVertexMeasure(E,V,E_sed_mat(:,:,qt)); %Set entries in animation structure animStruct.Handles{qt}=[hp hp hp2 hp3 hp4]; %Handles of objects to animate animStruct.Props{qt}={'Vertices','CData','Vertices','Vertices','Vertices'}; %Properties of objects to animate animStruct.Set{qt}={V_DEF(:,:,qt),CV,V_DEF(:,:,qt),V_DEF(:,:,qt),V_DEF(:,:,qt)}; %Property values for to set in order to animate end anim8(hf,animStruct); %Initiate animation feature drawnow; end %% % % <<gibbVerySmall.gif>> % % _*GIBBON*_ % <www.gibboncode.org> % % _Kevin Mattheus Moerman_, <[email protected]> %% % _*GIBBON footer text*_ % % License: <https://github.com/gibbonCode/GIBBON/blob/master/LICENSE> % % GIBBON: The Geometry and Image-based Bioengineering add-On. A toolbox for % image segmentation, image-based modeling, meshing, and finite element % analysis. % % Copyright (C) 2006-2022 Kevin Mattheus Moerman and the GIBBON contributors % % This program is free software: you can redistribute it and/or modify % it under the terms of the GNU General Public License as published by % the Free Software Foundation, either version 3 of the License, or % (at your option) any later version. % % This program is distributed in the hope that it will be useful, % but WITHOUT ANY WARRANTY; without even the implied warranty of % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the % GNU General Public License for more details. % % You should have received a copy of the GNU General Public License % along with this program. If not, see <http://www.gnu.org/licenses/>.
/* Copyright (C) 2021 Quaternion Risk Management Ltd All rights reserved. This file is part of ORE, a free-software/open-source library for transparent pricing and risk analysis - http://opensourcerisk.org ORE is free software: you can redistribute it and/or modify it under the terms of the Modified BSD License. You should have received a copy of the license along with this program. The license is also available online at <http://opensourcerisk.org> This program is distributed on the basis that it will form a useful contribution to risk analytics and model standardisation, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the license for more details. */ #include <ored/portfolio/builders/capflooredaverageonindexedcouponleg.hpp> #include <ored/utilities/log.hpp> #include <qle/cashflows/blackovernightindexedcouponpricer.hpp> #include <boost/make_shared.hpp> namespace ore { namespace data { boost::shared_ptr<FloatingRateCouponPricer> CapFlooredAverageONIndexedCouponLegEngineBuilder::engineImpl(const Currency& ccy) { // Check if we already have a pricer for this ccy const string& ccyCode = ccy.code(); if (engines_.find(ccyCode) == engines_.end()) { Handle<YieldTermStructure> yts = market_->discountCurve(ccyCode, configuration(MarketContext::pricing)); QL_REQUIRE(!yts.empty(), "engineFactory error: yield term structure not found for currency " << ccyCode); Handle<OptionletVolatilityStructure> ovs = market_->capFloorVol(ccyCode, configuration(MarketContext::pricing)); boost::shared_ptr<FloatingRateCouponPricer> pricer = boost::make_shared<QuantExt::BlackAverageONIndexedCouponPricer>(ovs); engines_[ccyCode] = pricer; } // Return the cached pricer return engines_[ccyCode]; } } // namespace data } // namespace ore
State Before: α : Type u_1 β : Type u_2 γ : Type ?u.218890 ι : Type ?u.218893 M : Type u_3 M' : Type ?u.218899 N : Type ?u.218902 P : Type ?u.218905 G : Type ?u.218908 H : Type ?u.218911 R : Type ?u.218914 S : Type ?u.218917 inst✝¹ : Zero M inst✝ : Zero N f : α ↪ β v : α →₀ M a : β h : ¬a ∈ Set.range ↑f ⊢ ↑(embDomain f v) a = 0 State After: no goals Tactic: classical refine' dif_neg (mt (fun h => _) h) rcases Finset.mem_map.1 h with ⟨a, _h, rfl⟩ exact Set.mem_range_self a State Before: α : Type u_1 β : Type u_2 γ : Type ?u.218890 ι : Type ?u.218893 M : Type u_3 M' : Type ?u.218899 N : Type ?u.218902 P : Type ?u.218905 G : Type ?u.218908 H : Type ?u.218911 R : Type ?u.218914 S : Type ?u.218917 inst✝¹ : Zero M inst✝ : Zero N f : α ↪ β v : α →₀ M a : β h : ¬a ∈ Set.range ↑f ⊢ ↑(embDomain f v) a = 0 State After: α : Type u_1 β : Type u_2 γ : Type ?u.218890 ι : Type ?u.218893 M : Type u_3 M' : Type ?u.218899 N : Type ?u.218902 P : Type ?u.218905 G : Type ?u.218908 H : Type ?u.218911 R : Type ?u.218914 S : Type ?u.218917 inst✝¹ : Zero M inst✝ : Zero N f : α ↪ β v : α →₀ M a : β h✝ : ¬a ∈ Set.range ↑f h : a ∈ map f v.support ⊢ a ∈ Set.range ↑f Tactic: refine' dif_neg (mt (fun h => _) h) State Before: α : Type u_1 β : Type u_2 γ : Type ?u.218890 ι : Type ?u.218893 M : Type u_3 M' : Type ?u.218899 N : Type ?u.218902 P : Type ?u.218905 G : Type ?u.218908 H : Type ?u.218911 R : Type ?u.218914 S : Type ?u.218917 inst✝¹ : Zero M inst✝ : Zero N f : α ↪ β v : α →₀ M a : β h✝ : ¬a ∈ Set.range ↑f h : a ∈ map f v.support ⊢ a ∈ Set.range ↑f State After: case intro.intro α : Type u_1 β : Type u_2 γ : Type ?u.218890 ι : Type ?u.218893 M : Type u_3 M' : Type ?u.218899 N : Type ?u.218902 P : Type ?u.218905 G : Type ?u.218908 H : Type ?u.218911 R : Type ?u.218914 S : Type ?u.218917 inst✝¹ : Zero M inst✝ : Zero N f : α ↪ β v : α →₀ M a : α _h : a ∈ v.support h✝ : ¬↑f a ∈ Set.range ↑f h : ↑f a ∈ map f v.support ⊢ ↑f a ∈ Set.range ↑f Tactic: rcases Finset.mem_map.1 h with ⟨a, _h, rfl⟩ State Before: case intro.intro α : Type u_1 β : Type u_2 γ : Type ?u.218890 ι : Type ?u.218893 M : Type u_3 M' : Type ?u.218899 N : Type ?u.218902 P : Type ?u.218905 G : Type ?u.218908 H : Type ?u.218911 R : Type ?u.218914 S : Type ?u.218917 inst✝¹ : Zero M inst✝ : Zero N f : α ↪ β v : α →₀ M a : α _h : a ∈ v.support h✝ : ¬↑f a ∈ Set.range ↑f h : ↑f a ∈ map f v.support ⊢ ↑f a ∈ Set.range ↑f State After: no goals Tactic: exact Set.mem_range_self a
##real-time plot from pyqtgraph.Qt import QtGui, QtCore import pyqtgraph as pg import numpy as np import collections class Graph(): def setup(self): #provide all parameters as floats with at least one decimal point self.frequency = 250.0 self.sample_interval = 1/self.frequency #converting to milliseconds for timer.start() function self.timer_interval = self.sample_interval*1000 self.time_window = 10 self.buffer_size = int(self.time_window/self.sample_interval) self.data_buffer = collections.deque([0.0]*self.buffer_size,self.buffer_size) self.x = np.linspace(0.0,self.time_window,self.buffer_size) self.y = np.zeros(self.buffer_size, dtype=np.float) #PyQtGraph settings self.app = QtGui.QApplication([]) self.plt = pg.plot(title='Real Time Open BCI data') self.plt.showGrid(x=True, y=True) self.plt.setLabel('left','amplitude','uV') self.plt.setLabel('bottom','time','s') self.curve = self.plt.plot(self.x,self.y,pen=(255,0,0)) #QTimer self.timer = QtCore.QTimer() self.timer.timeout.connect(self.update_plot) self.timer.start(self.timer_interval) def __init__(self): with open('data-trial.txt','r') as f: self.data = f.readlines() self.data = [x.strip() for x in self.data] self.i = 0 def get_data(self): sample = self.data[self.i].split(' ')[5] self.i = self.i + 1 return sample def update_plot(self): self.data_buffer.append(self.get_data()) self.y[:] = self.data_buffer self.curve.setData(self.x,self.y) self.app.processEvents() def run(self): self.app.exec_() if __name__ == '__main__': g = Graph() g.setup() g.run()
{-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE TupleSections #-} {-# LANGUAGE ScopedTypeVariables #-} module Day13 where import Control.Lens import Control.Lens.TH import qualified Data.ByteString as BS import Data.Attoparsec.ByteString (Parser, (<?>)) import qualified Data.Attoparsec.ByteString as DAB import qualified Data.Attoparsec.ByteString.Char8 as DABC8 import Data.Attoparsec.ByteString.Char8 (decimal, inClass, digit, endOfLine, char, anyChar, letter_ascii, notChar) import Data.Map.Strict (Map) import qualified Data.Map.Strict as Map import qualified Data.List as DL import qualified Data.List.Split as DLS import Debug.Trace import Control.Arrow import Data.Array.IArray (Array) import qualified Data.Array.IArray as IA import Data.Set (Set) import qualified Data.Set as Set import Data.Either (isRight) import Data.Maybe (isJust, mapMaybe, catMaybes) import Data.Bool (bool) import Data.Vector (Vector, (!)) import qualified Data.Vector as Vec import Data.Function (on) import Control.Monad.State.Strict (State) import qualified Control.Monad.State.Strict as State import qualified Control.Monad as CM import qualified Control.Foldl as L import Data.Complex import Data.Functor import Data.Bifunctor (bimap) -- Each input is the id of a bus line. Nothing means that the line, whatever its -- id was, is out of service. type Input = Maybe BusId newtype BusId = BusId { getBusId :: Integer } deriving Show -- Parases an unsigned decimal number parseBusId :: Parser BusId parseBusId = (BusId <$> decimal) <?> "BusId" newtype Timestamp = Timestamp { getTimestamp :: Integer } deriving Show parseTimestamp :: Parser Timestamp parseTimestamp = (Timestamp <$> decimal) <?> "Timestamp" -- Solve part 1 -- -- forall n m : int, -- -- start + n = bus_id * m -- -- n is the waiting time for the m-th departure of `bus_id`. This can be -- rearranged as: -- -- (1) n = bus_id * m - start -- -- `start` can be rewriten in terms of `bus_id`: -- -- start = bus_id * q + r -- -- where -- -- q = start / bus_id -- r = start % bus_id -- -- with -- -- r < bus_id -- -- replacing in (1) -- -- n = bus_id * (m - q) - r -- -- So the smallest positive n happens when (m - q) == 1 and is thus equal to -- -- n_min = bus_id - r -- -- Returns Norhing in case there are no bus lines. solver :: Timestamp -> [Input] -> Maybe Integer solver start input = do -- Find the bus line with the earliest departure time. (busId, departureTime) <- L.fold ( L.minimumBy (compare `on` snd) ) $ (id &&& mapper) <$> catMaybes input pure (getBusId busId * departureTime) where -- Compute the earliest departure time after `start` for a bus line. mapper :: BusId -> Integer mapper bid = getBusId bid - ( getTimestamp start `mod` getBusId bid ) -- Write equations for part 2 -- -- For each bus_id, n_i is the departure time for the m_i-th departure -- -- n_1 = bus_id_1 * m_1 -- n_2 = bus_id_2 * m_2 -- ... -- n_i = bus_id_i * m_i -- -- Those departure times have to be consecutive so: -- -- n_2 = n_1 + (ord_2 - ord_1) -- ... -- n_(i+1) = n_i + (ord_(i+1) - ord_i) -- -- where ord_i is the order of the bus_id on the list. With ord_(i+1) > ord_i. -- -- Applying this constrain we get: -- -- n_1 = bus_id_1 * m_1 -- n_1 + (ord_2 - ord_1) = bus_id_2 * m_2 -- n_2 + (ord_3 - ord_2) = bus_id_3 * m_3 -- ... -- n_i + (ord_(i+1) - ord_i) = bus_id_(i+1) * m_(i+1) -- -- Leaving only n_1 we get: -- -- n_1 = bus_id_1 * m_1 -- n_1 + (ord_2 - ord_1) = bus_id_2 * m_2 -- (n_1 + (ord_2 - ord_1)) + (ord_3 - ord_2) = bus_id_3 * m_3 -- ... -- -- The last equation becomes -- -- n_1 + (ord_3 - ord_1) = bus_id_3 * m_3 -- -- So all the equations become -- -- n_1 = bus_id_1 * m_1 -- n_1 + (ord_2 - ord_1) = bus_id_2 * m_2 -- n_1 + (ord_3 - ord_1) = bus_id_3 * m_3 -- ... -- n_1 + (ord_i - ord_1) = bus_id_i * m_i -- -- Next I rewrite them like: -- -- n_1 - bus_id_1 * m_1 = 0 -- n_1 + (ord_2 - ord_1) - bus_id_2 * m_2 = 0 -- ... -- n_1 + (ord_i - ord_1) - bus_id_i * m_i = 0 -- -- Finally I replace n_1 in all the equations -- -- bus_id_1 * m_1 + (ord_i - ord_1) - bus_id_i * m_i = 0 -- -- This equations can be stored using a 4-tuple -- -- (bus_id_1, bus_id_i, (ord_i - ord_1), ord_i) -- -- This functions just creates those 4-tuples to be further processed. solver' input = case catMaybes (zipWith (\x -> fmap (x,)) [1..] input) of ( (ord1, busId1) : rest) -> (busId1, busId1, 0, ord1) : fmap mapper rest where mapper (ordi, busIdi) = (busId1, busIdi, ordi - ord1, ordi) -- Sample input -- -- 939 -- 7,13,x,x,59,x,31,19 -- -- The x's represent lines that are out of service. parseInput :: Parser (Timestamp, [Input]) parseInput = ( (,) <$> (parseTimestamp <* endOfLine) <*> (DAB.choice [ Just <$> parseBusId , char 'x' $> Nothing ] `DAB.sepBy1'` char ',') ) <* endOfLine runSolution :: FilePath -> IO () runSolution filePath = do putStrLn "**Day 13**" contents <- BS.readFile filePath let parseResult = DAB.parseOnly parseInput contents case parseResult of Left err -> putStrLn $ "Error :" ++ err Right (start, input) -> do putStrLn "Part 1" print $ solver start input putStrLn "\nPart 2" mapM_ (putStrLn . printEq) $ solver' input where -- Prints an equation to be solved. printEq (flid, bid, delta, ordi) = show (getBusId flid) ++ " * x[1] - " ++ show (getBusId bid) ++ " * x[" ++ show ordi ++ "] + " ++ show delta -- Wrong -- 1258 -- Part 1: -- Answer = Just 410