Datasets:
AI4M
/

text
stringlengths
0
3.34M
% Copyright 2011 Zdenek Kalal % % This file is part of TLD. % % TLD 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. % % TLD 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 TLD. If not, see <http://www.gnu.org/licenses/>. function source = tldInitFirstFrame(tld,source,min_win) % load the first frame into memory source.im0 = img_get(source,source.idx(1)); % set the initial bounding box: % - from file if source.camera == 0 && exist([source.input '/init.txt'],'file') bb = dlmread([source.input '/init.txt']); source.bb = bb(:); % check if isempty(source.bb) || min(bb_size(source.bb)) < min_win exit('Error: bounding box is incorrectly defined or too small'); end % - by mouse else source.bb = bb_click(tld,source.im0.input); % check if isempty(source.bb) || min(bb_size(source.bb)) < min_win source = []; end end
Intertoto Cup 2 :
#'@title calcSpeedUnitConversion #' #'@description Convert speed in knots to m/s. #' #'@param shipSpeed Ship speed (vector of numericals, knots) #' #'@return speed (vector of numericals, m/s) #' #'@examples #'calcSpeedUnitConversion(seq(10,15,1)) #' #'@export calcSpeedUnitConversion<- function(shipSpeed){ speed<- shipSpeed*0.5144 return(speed) }
(* This Isabelle theory is produced using the TIP tool offered at the following website: https://github.com/tip-org/tools This file was originally provided as part of TIP benchmark at the following website: https://github.com/tip-org/benchmarks Yutaka Nagashima at CIIRC, CTU changed the TIP output theory file slightly to make it compatible with Isabelle2017. \:w Some proofs were added by Yutaka Nagashima.*) theory TIP_sort_nat_HSort2IsSort imports "../../Test_Base" begin datatype 'a list = nil2 | cons2 "'a" "'a list" datatype Nat = Z | S "Nat" datatype Heap = Node "Heap" "Nat" "Heap" | Nil fun le :: "Nat => Nat => bool" where "le (Z) y = True" | "le (S z) (Z) = False" | "le (S z) (S x2) = le z x2" fun insert :: "Nat => Nat list => Nat list" where "insert x (nil2) = cons2 x (nil2)" | "insert x (cons2 z xs) = (if le x z then cons2 x (cons2 z xs) else cons2 z (insert x xs))" fun isort :: "Nat list => Nat list" where "isort (nil2) = nil2" | "isort (cons2 y xs) = insert y (isort xs)" fun hmerge :: "Heap => Heap => Heap" where "hmerge (Node z x2 x3) (Node x4 x5 x6) = (if le x2 x5 then Node (hmerge x3 (Node x4 x5 x6)) x2 z else Node (hmerge (Node z x2 x3) x6) x5 x4)" | "hmerge (Node z x2 x3) (Nil) = Node z x2 x3" | "hmerge (Nil) y = y" (*fun did not finish the proof*) function toList :: "Heap => Nat list" where "toList (Node q y r) = cons2 y (toList (hmerge q r))" | "toList (Nil) = nil2" by pat_completeness auto fun hinsert :: "Nat => Heap => Heap" where "hinsert x y = hmerge (Node Nil x Nil) y" fun toHeap2 :: "Nat list => Heap" where "toHeap2 (nil2) = Nil" | "toHeap2 (cons2 y xs) = hinsert y (toHeap2 xs)" fun hsort2 :: "Nat list => Nat list" where "hsort2 x = toList (toHeap2 x)" theorem property0 : "((hsort2 xs) = (isort xs))" oops end
// Copyright (c) 2014-2017 Jae-jun Kang // See the file LICENSE for details. #ifndef X2BOOST_SINGLE_THREADED_FLOW_HPP_ #define X2BOOST_SINGLE_THREADED_FLOW_HPP_ #ifndef X2BOOST_PRE_HPP_ #include "x2boost/pre.hpp" #endif #include <boost/bind.hpp> #include <boost/thread.hpp> #include "x2boost/flows/event_based_flow.hpp" namespace x2boost { template<class Q = synchronized_event_queue> class X2BOOST_API single_threaded_flow : public event_based_flow<Q> { public: single_threaded_flow() : thread_(NULL) {} virtual ~single_threaded_flow() {} virtual void startup() { boost::mutex::scoped_lock lock(flow::mutex_); if (thread_) { return; } this->setup(); flow::case_stack_.setup(boost::enable_shared_from_this<flow>::shared_from_this()); thread_ = new boost::thread(boost::bind(&event_based_flow<Q>::run, this)); } virtual void shutdown() { boost::mutex::scoped_lock lock(flow::mutex_); if (!thread_) { return; } // enqueue flow_stop event_based_flow<Q>::queue_.close(); thread_->join(); delete thread_; thread_ = NULL; flow::case_stack_.teardown(boost::enable_shared_from_this<flow>::shared_from_this()); this->teardown(); } protected: boost::thread* thread_; }; } #endif // X2BOOST_SINGLE_THREADED_FLOW_HPP_
If $f$ and $g$ are holomorphic functions on a domain $D$ except at a point $z \in D$, then the residue of $f - g$ at $z$ is equal to the residue of $f$ at $z$ minus the residue of $g$ at $z$.
(* (C) Copyright Andreas Viktor Hess, DTU, 2018-2020 All Rights Reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: - Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. - Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. - Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *) (* Title: Stateful_Typing.thy Author: Andreas Viktor Hess, DTU *) section \<open>Extending the Typing Result to Stateful Constraints\<close> text \<open>\label{sec:Stateful-Typing}\<close> theory Stateful_Typing imports Typing_Result Stateful_Strands begin text \<open>Locale setup\<close> locale stateful_typed_model = typed_model arity public Ana \<Gamma> for arity::"'fun \<Rightarrow> nat" and public::"'fun \<Rightarrow> bool" and Ana::"('fun,'var) term \<Rightarrow> (('fun,'var) term list \<times> ('fun,'var) term list)" and \<Gamma>::"('fun,'var) term \<Rightarrow> ('fun,'atom::finite) term_type" + fixes Pair::"'fun" assumes Pair_arity: "arity Pair = 2" and Ana_subst': "\<And>f T \<delta> K M. Ana (Fun f T) = (K,M) \<Longrightarrow> Ana (Fun f T \<cdot> \<delta>) = (K \<cdot>\<^sub>l\<^sub>i\<^sub>s\<^sub>t \<delta>,M \<cdot>\<^sub>l\<^sub>i\<^sub>s\<^sub>t \<delta>)" begin lemma Ana_invar_subst'[simp]: "Ana_invar_subst \<S>" using Ana_subst' unfolding Ana_invar_subst_def by force definition pair where "pair d \<equiv> case d of (t,t') \<Rightarrow> Fun Pair [t,t']" fun tr\<^sub>p\<^sub>a\<^sub>i\<^sub>r\<^sub>s:: "(('fun,'var) term \<times> ('fun,'var) term) list \<Rightarrow> ('fun,'var) dbstatelist \<Rightarrow> (('fun,'var) term \<times> ('fun,'var) term) list list" where "tr\<^sub>p\<^sub>a\<^sub>i\<^sub>r\<^sub>s [] D = [[]]" | "tr\<^sub>p\<^sub>a\<^sub>i\<^sub>r\<^sub>s ((s,t)#F) D = concat (map (\<lambda>d. map ((#) (pair (s,t), pair d)) (tr\<^sub>p\<^sub>a\<^sub>i\<^sub>r\<^sub>s F D)) D)" text \<open> A translation/reduction \<open>tr\<close> from stateful constraints to (lists of) "non-stateful" constraints. The output represents a finite disjunction of constraints whose models constitute exactly the models of the input constraint. The typing result for "non-stateful" constraints is later lifted to the stateful setting through this reduction procedure. \<close> fun tr::"('fun,'var) stateful_strand \<Rightarrow> ('fun,'var) dbstatelist \<Rightarrow> ('fun,'var) strand list" where "tr [] D = [[]]" | "tr (send\<langle>t\<rangle>#A) D = map ((#) (send\<langle>t\<rangle>\<^sub>s\<^sub>t)) (tr A D)" | "tr (receive\<langle>t\<rangle>#A) D = map ((#) (receive\<langle>t\<rangle>\<^sub>s\<^sub>t)) (tr A D)" | "tr (\<langle>ac: t \<doteq> t'\<rangle>#A) D = map ((#) (\<langle>ac: t \<doteq> t'\<rangle>\<^sub>s\<^sub>t)) (tr A D)" | "tr (insert\<langle>t,s\<rangle>#A) D = tr A (List.insert (t,s) D)" | "tr (delete\<langle>t,s\<rangle>#A) D = concat (map (\<lambda>Di. map (\<lambda>B. (map (\<lambda>d. \<langle>check: (pair (t,s)) \<doteq> (pair d)\<rangle>\<^sub>s\<^sub>t) Di)@ (map (\<lambda>d. \<forall>[]\<langle>\<or>\<noteq>: [(pair (t,s), pair d)]\<rangle>\<^sub>s\<^sub>t) [d\<leftarrow>D. d \<notin> set Di])@B) (tr A [d\<leftarrow>D. d \<notin> set Di])) (subseqs D))" | "tr (\<langle>ac: t \<in> s\<rangle>#A) D = concat (map (\<lambda>B. map (\<lambda>d. \<langle>ac: (pair (t,s)) \<doteq> (pair d)\<rangle>\<^sub>s\<^sub>t#B) D) (tr A D))" | "tr (\<forall>X\<langle>\<or>\<noteq>: F \<or>\<notin>: F'\<rangle>#A) D = map ((@) (map (\<lambda>G. \<forall>X\<langle>\<or>\<noteq>: (F@G)\<rangle>\<^sub>s\<^sub>t) (tr\<^sub>p\<^sub>a\<^sub>i\<^sub>r\<^sub>s F' D))) (tr A D)" text \<open>Type-flaw resistance of stateful constraint steps\<close> fun tfr\<^sub>s\<^sub>s\<^sub>t\<^sub>p where "tfr\<^sub>s\<^sub>s\<^sub>t\<^sub>p (Equality _ t t') = ((\<exists>\<delta>. Unifier \<delta> t t') \<longrightarrow> \<Gamma> t = \<Gamma> t')" | "tfr\<^sub>s\<^sub>s\<^sub>t\<^sub>p (NegChecks X F F') = ( (F' = [] \<and> (\<forall>x \<in> fv\<^sub>p\<^sub>a\<^sub>i\<^sub>r\<^sub>s F-set X. \<exists>a. \<Gamma> (Var x) = TAtom a)) \<or> (\<forall>f T. Fun f T \<in> subterms\<^sub>s\<^sub>e\<^sub>t (trms\<^sub>p\<^sub>a\<^sub>i\<^sub>r\<^sub>s F \<union> pair ` set F') \<longrightarrow> T = [] \<or> (\<exists>s \<in> set T. s \<notin> Var ` set X)))" | "tfr\<^sub>s\<^sub>s\<^sub>t\<^sub>p _ = True" text \<open>Type-flaw resistance of stateful constraints\<close> definition tfr\<^sub>s\<^sub>s\<^sub>t where "tfr\<^sub>s\<^sub>s\<^sub>t S \<equiv> tfr\<^sub>s\<^sub>e\<^sub>t (trms\<^sub>s\<^sub>s\<^sub>t S \<union> pair ` setops\<^sub>s\<^sub>s\<^sub>t S) \<and> list_all tfr\<^sub>s\<^sub>s\<^sub>t\<^sub>p S" subsection \<open>Small Lemmata\<close> lemma pair_in_pair_image_iff: "pair (s,t) \<in> pair ` P \<longleftrightarrow> (s,t) \<in> P" unfolding pair_def by fast lemma subst_apply_pairs_pair_image_subst: "pair ` set (F \<cdot>\<^sub>p\<^sub>a\<^sub>i\<^sub>r\<^sub>s \<theta>) = pair ` set F \<cdot>\<^sub>s\<^sub>e\<^sub>t \<theta>" unfolding subst_apply_pairs_def pair_def by (induct F) auto lemma Ana_subst_subterms_cases: fixes \<theta>::"('fun,'var) subst" assumes t: "t \<in> subterms\<^sub>s\<^sub>e\<^sub>t (M \<cdot>\<^sub>s\<^sub>e\<^sub>t \<theta>)" and s: "s \<in> set (snd (Ana t))" shows "(\<exists>u \<in> subterms\<^sub>s\<^sub>e\<^sub>t M. t = u \<cdot> \<theta> \<and> s \<in> set (snd (Ana u)) \<cdot>\<^sub>s\<^sub>e\<^sub>t \<theta>) \<or> (\<exists>x \<in> fv\<^sub>s\<^sub>e\<^sub>t M. t \<sqsubseteq> \<theta> x)" proof (cases "t \<in> subterms\<^sub>s\<^sub>e\<^sub>t M \<cdot>\<^sub>s\<^sub>e\<^sub>t \<theta>") case True then obtain u where u: "u \<in> subterms\<^sub>s\<^sub>e\<^sub>t M" "t = u \<cdot> \<theta>" by moura show ?thesis proof (cases u) case (Var x) hence "x \<in> fv\<^sub>s\<^sub>e\<^sub>t M" using fv_subset_subterms[OF u(1)] by simp thus ?thesis using u(2) Var by fastforce next case (Fun f T) hence "set (snd (Ana t)) = set (snd (Ana u)) \<cdot>\<^sub>s\<^sub>e\<^sub>t \<theta>" using Ana_subst'[of f T _ _ \<theta>] u(2) by (cases "Ana u") auto thus ?thesis using s u by blast qed qed (use s t subterms\<^sub>s\<^sub>e\<^sub>t_subst in blast) lemma tfr\<^sub>s\<^sub>s\<^sub>t\<^sub>p_alt_def: "list_all tfr\<^sub>s\<^sub>s\<^sub>t\<^sub>p S = ((\<forall>ac t t'. Equality ac t t' \<in> set S \<and> (\<exists>\<delta>. Unifier \<delta> t t') \<longrightarrow> \<Gamma> t = \<Gamma> t') \<and> (\<forall>X F F'. NegChecks X F F' \<in> set S \<longrightarrow> ( (F' = [] \<and> (\<forall>x \<in> fv\<^sub>p\<^sub>a\<^sub>i\<^sub>r\<^sub>s F-set X. \<exists>a. \<Gamma> (Var x) = TAtom a)) \<or> (\<forall>f T. Fun f T \<in> subterms\<^sub>s\<^sub>e\<^sub>t (trms\<^sub>p\<^sub>a\<^sub>i\<^sub>r\<^sub>s F \<union> pair ` set F') \<longrightarrow> T = [] \<or> (\<exists>s \<in> set T. s \<notin> Var ` set X)))))" (is "?P S = ?Q S") proof show "?P S \<Longrightarrow> ?Q S" proof (induction S) case (Cons x S) thus ?case by (cases x) auto qed simp show "?Q S \<Longrightarrow> ?P S" proof (induction S) case (Cons x S) thus ?case by (cases x) auto qed simp qed lemma fun_pair_eq[dest]: "pair d = pair d' \<Longrightarrow> d = d'" proof - obtain t s t' s' where "d = (t,s)" "d' = (t',s')" by moura thus "pair d = pair d' \<Longrightarrow> d = d'" unfolding pair_def by simp qed lemma fun_pair_subst: "pair d \<cdot> \<delta> = pair (d \<cdot>\<^sub>p \<delta>)" using surj_pair[of d] unfolding pair_def by force lemma fun_pair_subst_set: "pair ` M \<cdot>\<^sub>s\<^sub>e\<^sub>t \<delta> = pair ` (M \<cdot>\<^sub>p\<^sub>s\<^sub>e\<^sub>t \<delta>)" proof show "pair ` M \<cdot>\<^sub>s\<^sub>e\<^sub>t \<delta> \<subseteq> pair ` (M \<cdot>\<^sub>p\<^sub>s\<^sub>e\<^sub>t \<delta>)" using fun_pair_subst[of _ \<delta>] by fastforce show "pair ` (M \<cdot>\<^sub>p\<^sub>s\<^sub>e\<^sub>t \<delta>) \<subseteq> pair ` M \<cdot>\<^sub>s\<^sub>e\<^sub>t \<delta>" proof fix t assume t: "t \<in> pair ` (M \<cdot>\<^sub>p\<^sub>s\<^sub>e\<^sub>t \<delta>)" then obtain p where p: "p \<in> M" "t = pair (p \<cdot>\<^sub>p \<delta>)" by blast thus "t \<in> pair ` M \<cdot>\<^sub>s\<^sub>e\<^sub>t \<delta>" using fun_pair_subst[of p \<delta>] by force qed qed lemma fun_pair_eq_subst: "pair d \<cdot> \<delta> = pair d' \<cdot> \<theta> \<longleftrightarrow> d \<cdot>\<^sub>p \<delta> = d' \<cdot>\<^sub>p \<theta>" by (metis fun_pair_subst fun_pair_eq[of "d \<cdot>\<^sub>p \<delta>" "d' \<cdot>\<^sub>p \<theta>"]) lemma setops\<^sub>s\<^sub>s\<^sub>t_pair_image_cons[simp]: "pair ` setops\<^sub>s\<^sub>s\<^sub>t (x#S) = pair ` setops\<^sub>s\<^sub>s\<^sub>t\<^sub>p x \<union> pair ` setops\<^sub>s\<^sub>s\<^sub>t S" "pair ` setops\<^sub>s\<^sub>s\<^sub>t (send\<langle>t\<rangle>#S) = pair ` setops\<^sub>s\<^sub>s\<^sub>t S" "pair ` setops\<^sub>s\<^sub>s\<^sub>t (receive\<langle>t\<rangle>#S) = pair ` setops\<^sub>s\<^sub>s\<^sub>t S" "pair ` setops\<^sub>s\<^sub>s\<^sub>t (\<langle>ac: t \<doteq> t'\<rangle>#S) = pair ` setops\<^sub>s\<^sub>s\<^sub>t S" "pair ` setops\<^sub>s\<^sub>s\<^sub>t (insert\<langle>t,s\<rangle>#S) = {pair (t,s)} \<union> pair ` setops\<^sub>s\<^sub>s\<^sub>t S" "pair ` setops\<^sub>s\<^sub>s\<^sub>t (delete\<langle>t,s\<rangle>#S) = {pair (t,s)} \<union> pair ` setops\<^sub>s\<^sub>s\<^sub>t S" "pair ` setops\<^sub>s\<^sub>s\<^sub>t (\<langle>ac: t \<in> s\<rangle>#S) = {pair (t,s)} \<union> pair ` setops\<^sub>s\<^sub>s\<^sub>t S" "pair ` setops\<^sub>s\<^sub>s\<^sub>t (\<forall>X\<langle>\<or>\<noteq>: F \<or>\<notin>: G\<rangle>#S) = pair ` set G \<union> pair ` setops\<^sub>s\<^sub>s\<^sub>t S" unfolding setops\<^sub>s\<^sub>s\<^sub>t_def by auto lemma setops\<^sub>s\<^sub>s\<^sub>t_pair_image_subst_cons[simp]: "pair ` setops\<^sub>s\<^sub>s\<^sub>t (x#S \<cdot>\<^sub>s\<^sub>s\<^sub>t \<theta>) = pair ` setops\<^sub>s\<^sub>s\<^sub>t\<^sub>p (x \<cdot>\<^sub>s\<^sub>s\<^sub>t\<^sub>p \<theta>) \<union> pair ` setops\<^sub>s\<^sub>s\<^sub>t (S \<cdot>\<^sub>s\<^sub>s\<^sub>t \<theta>)" "pair ` setops\<^sub>s\<^sub>s\<^sub>t (send\<langle>t\<rangle>#S \<cdot>\<^sub>s\<^sub>s\<^sub>t \<theta>) = pair ` setops\<^sub>s\<^sub>s\<^sub>t (S \<cdot>\<^sub>s\<^sub>s\<^sub>t \<theta>)" "pair ` setops\<^sub>s\<^sub>s\<^sub>t (receive\<langle>t\<rangle>#S \<cdot>\<^sub>s\<^sub>s\<^sub>t \<theta>) = pair ` setops\<^sub>s\<^sub>s\<^sub>t (S \<cdot>\<^sub>s\<^sub>s\<^sub>t \<theta>)" "pair ` setops\<^sub>s\<^sub>s\<^sub>t (\<langle>ac: t \<doteq> t'\<rangle>#S \<cdot>\<^sub>s\<^sub>s\<^sub>t \<theta>) = pair ` setops\<^sub>s\<^sub>s\<^sub>t (S \<cdot>\<^sub>s\<^sub>s\<^sub>t \<theta>)" "pair ` setops\<^sub>s\<^sub>s\<^sub>t (insert\<langle>t,s\<rangle>#S \<cdot>\<^sub>s\<^sub>s\<^sub>t \<theta>) = {pair (t,s) \<cdot> \<theta>} \<union> pair ` setops\<^sub>s\<^sub>s\<^sub>t (S \<cdot>\<^sub>s\<^sub>s\<^sub>t \<theta>)" "pair ` setops\<^sub>s\<^sub>s\<^sub>t (delete\<langle>t,s\<rangle>#S \<cdot>\<^sub>s\<^sub>s\<^sub>t \<theta>) = {pair (t,s) \<cdot> \<theta>} \<union> pair ` setops\<^sub>s\<^sub>s\<^sub>t (S \<cdot>\<^sub>s\<^sub>s\<^sub>t \<theta>)" "pair ` setops\<^sub>s\<^sub>s\<^sub>t (\<langle>ac: t \<in> s\<rangle>#S \<cdot>\<^sub>s\<^sub>s\<^sub>t \<theta>) = {pair (t,s) \<cdot> \<theta>} \<union> pair ` setops\<^sub>s\<^sub>s\<^sub>t (S \<cdot>\<^sub>s\<^sub>s\<^sub>t \<theta>)" "pair ` setops\<^sub>s\<^sub>s\<^sub>t (\<forall>X\<langle>\<or>\<noteq>: F \<or>\<notin>: G\<rangle>#S \<cdot>\<^sub>s\<^sub>s\<^sub>t \<theta>) = pair ` set (G \<cdot>\<^sub>p\<^sub>a\<^sub>i\<^sub>r\<^sub>s rm_vars (set X) \<theta>) \<union> pair ` setops\<^sub>s\<^sub>s\<^sub>t (S \<cdot>\<^sub>s\<^sub>s\<^sub>t \<theta>)" using subst_sst_cons[of _ S \<theta>] unfolding setops\<^sub>s\<^sub>s\<^sub>t_def pair_def by auto lemma setops\<^sub>s\<^sub>s\<^sub>t_are_pairs: "t \<in> pair ` setops\<^sub>s\<^sub>s\<^sub>t A \<Longrightarrow> \<exists>s s'. t = pair (s,s')" proof (induction A) case (Cons a A) thus ?case by (cases a) (auto simp add: setops\<^sub>s\<^sub>s\<^sub>t_def) qed (simp add: setops\<^sub>s\<^sub>s\<^sub>t_def) lemma fun_pair_wf\<^sub>t\<^sub>r\<^sub>m: "wf\<^sub>t\<^sub>r\<^sub>m t \<Longrightarrow> wf\<^sub>t\<^sub>r\<^sub>m t' \<Longrightarrow> wf\<^sub>t\<^sub>r\<^sub>m (pair (t,t'))" using Pair_arity unfolding wf\<^sub>t\<^sub>r\<^sub>m_def pair_def by auto lemma wf\<^sub>t\<^sub>r\<^sub>m\<^sub>s_pairs: "wf\<^sub>t\<^sub>r\<^sub>m\<^sub>s (trms\<^sub>p\<^sub>a\<^sub>i\<^sub>r\<^sub>s F) \<Longrightarrow> wf\<^sub>t\<^sub>r\<^sub>m\<^sub>s (pair ` set F)" using fun_pair_wf\<^sub>t\<^sub>r\<^sub>m by blast lemma tfr\<^sub>s\<^sub>s\<^sub>t_Nil[simp]: "tfr\<^sub>s\<^sub>s\<^sub>t []" by (simp add: tfr\<^sub>s\<^sub>s\<^sub>t_def setops\<^sub>s\<^sub>s\<^sub>t_def) lemma tfr\<^sub>s\<^sub>s\<^sub>t_append: "tfr\<^sub>s\<^sub>s\<^sub>t (A@B) \<Longrightarrow> tfr\<^sub>s\<^sub>s\<^sub>t A" proof - assume assms: "tfr\<^sub>s\<^sub>s\<^sub>t (A@B)" let ?M = "trms\<^sub>s\<^sub>s\<^sub>t A \<union> pair ` setops\<^sub>s\<^sub>s\<^sub>t A" let ?N = "trms\<^sub>s\<^sub>s\<^sub>t (A@B) \<union> pair ` setops\<^sub>s\<^sub>s\<^sub>t (A@B)" let ?P = "\<lambda>t t'. \<forall>x \<in> fv t \<union> fv t'. \<exists>a. \<Gamma> (Var x) = Var a" let ?Q = "\<lambda>X t t'. X = [] \<or> (\<forall>x \<in> (fv t \<union> fv t')-set X. \<exists>a. \<Gamma> (Var x) = Var a)" have *: "SMP ?M - Var`\<V> \<subseteq> SMP ?N - Var`\<V>" "?M \<subseteq> ?N" using SMP_mono[of ?M ?N] setops\<^sub>s\<^sub>s\<^sub>t_append[of A B] by auto { fix s t assume **: "tfr\<^sub>s\<^sub>e\<^sub>t ?N" "s \<in> SMP ?M - Var`\<V>" "t \<in> SMP ?M - Var`\<V>" "(\<exists>\<delta>. Unifier \<delta> s t)" hence "s \<in> SMP ?N - Var`\<V>" "t \<in> SMP ?N - Var`\<V>" using * by auto hence "\<Gamma> s = \<Gamma> t" using **(1,4) unfolding tfr\<^sub>s\<^sub>e\<^sub>t_def by blast } moreover have "\<forall>t \<in> ?N. wf\<^sub>t\<^sub>r\<^sub>m t \<Longrightarrow> \<forall>t \<in> ?M. wf\<^sub>t\<^sub>r\<^sub>m t" using * by blast ultimately have "tfr\<^sub>s\<^sub>e\<^sub>t ?N \<Longrightarrow> tfr\<^sub>s\<^sub>e\<^sub>t ?M" unfolding tfr\<^sub>s\<^sub>e\<^sub>t_def by blast hence "tfr\<^sub>s\<^sub>e\<^sub>t ?M" using assms unfolding tfr\<^sub>s\<^sub>s\<^sub>t_def by metis thus "tfr\<^sub>s\<^sub>s\<^sub>t A" using assms unfolding tfr\<^sub>s\<^sub>s\<^sub>t_def by simp qed lemma tfr\<^sub>s\<^sub>s\<^sub>t_append': "tfr\<^sub>s\<^sub>s\<^sub>t (A@B) \<Longrightarrow> tfr\<^sub>s\<^sub>s\<^sub>t B" proof - assume assms: "tfr\<^sub>s\<^sub>s\<^sub>t (A@B)" let ?M = "trms\<^sub>s\<^sub>s\<^sub>t B \<union> pair ` setops\<^sub>s\<^sub>s\<^sub>t B" let ?N = "trms\<^sub>s\<^sub>s\<^sub>t (A@B) \<union> pair ` setops\<^sub>s\<^sub>s\<^sub>t (A@B)" let ?P = "\<lambda>t t'. \<forall>x \<in> fv t \<union> fv t'. \<exists>a. \<Gamma> (Var x) = Var a" let ?Q = "\<lambda>X t t'. X = [] \<or> (\<forall>x \<in> (fv t \<union> fv t')-set X. \<exists>a. \<Gamma> (Var x) = Var a)" have *: "SMP ?M - Var`\<V> \<subseteq> SMP ?N - Var`\<V>" "?M \<subseteq> ?N" using SMP_mono[of ?M ?N] setops\<^sub>s\<^sub>s\<^sub>t_append[of A B] by auto { fix s t assume **: "tfr\<^sub>s\<^sub>e\<^sub>t ?N" "s \<in> SMP ?M - Var`\<V>" "t \<in> SMP ?M - Var`\<V>" "(\<exists>\<delta>. Unifier \<delta> s t)" hence "s \<in> SMP ?N - Var`\<V>" "t \<in> SMP ?N - Var`\<V>" using * by auto hence "\<Gamma> s = \<Gamma> t" using **(1,4) unfolding tfr\<^sub>s\<^sub>e\<^sub>t_def by blast } moreover have "\<forall>t \<in> ?N. wf\<^sub>t\<^sub>r\<^sub>m t \<Longrightarrow> \<forall>t \<in> ?M. wf\<^sub>t\<^sub>r\<^sub>m t" using * by blast ultimately have "tfr\<^sub>s\<^sub>e\<^sub>t ?N \<Longrightarrow> tfr\<^sub>s\<^sub>e\<^sub>t ?M" unfolding tfr\<^sub>s\<^sub>e\<^sub>t_def by blast hence "tfr\<^sub>s\<^sub>e\<^sub>t ?M" using assms unfolding tfr\<^sub>s\<^sub>s\<^sub>t_def by metis thus "tfr\<^sub>s\<^sub>s\<^sub>t B" using assms unfolding tfr\<^sub>s\<^sub>s\<^sub>t_def by simp qed lemma tfr\<^sub>s\<^sub>s\<^sub>t_cons: "tfr\<^sub>s\<^sub>s\<^sub>t (a#A) \<Longrightarrow> tfr\<^sub>s\<^sub>s\<^sub>t A" using tfr\<^sub>s\<^sub>s\<^sub>t_append'[of "[a]" A] by simp lemma tfr\<^sub>s\<^sub>s\<^sub>t\<^sub>p_subst: assumes s: "tfr\<^sub>s\<^sub>s\<^sub>t\<^sub>p s" and \<theta>: "wt\<^sub>s\<^sub>u\<^sub>b\<^sub>s\<^sub>t \<theta>" "wf\<^sub>t\<^sub>r\<^sub>m\<^sub>s (subst_range \<theta>)" "set (bvars\<^sub>s\<^sub>s\<^sub>t\<^sub>p s) \<inter> range_vars \<theta> = {}" shows "tfr\<^sub>s\<^sub>s\<^sub>t\<^sub>p (s \<cdot>\<^sub>s\<^sub>s\<^sub>t\<^sub>p \<theta>)" proof (cases s) case (Equality a t t') thus ?thesis proof (cases "\<exists>\<delta>. Unifier \<delta> (t \<cdot> \<theta>) (t' \<cdot> \<theta>)") case True hence "\<exists>\<delta>. Unifier \<delta> t t'" by (metis subst_subst_compose[of _ \<theta>]) moreover have "\<Gamma> t = \<Gamma> (t \<cdot> \<theta>)" "\<Gamma> t' = \<Gamma> (t' \<cdot> \<theta>)" by (metis wt_subst_trm''[OF assms(2)])+ ultimately have "\<Gamma> (t \<cdot> \<theta>) = \<Gamma> (t' \<cdot> \<theta>)" using s Equality by simp thus ?thesis using Equality True by simp qed simp next case (NegChecks X F G) let ?P = "\<lambda>F G. G = [] \<and> (\<forall>x \<in> fv\<^sub>p\<^sub>a\<^sub>i\<^sub>r\<^sub>s F-set X. \<exists>a. \<Gamma> (Var x) = TAtom a)" let ?Q = "\<lambda>F G. \<forall>f T. Fun f T \<in> subterms\<^sub>s\<^sub>e\<^sub>t (trms\<^sub>p\<^sub>a\<^sub>i\<^sub>r\<^sub>s F \<union> pair ` set G) \<longrightarrow> T = [] \<or> (\<exists>s \<in> set T. s \<notin> Var ` set X)" let ?\<theta> = "rm_vars (set X) \<theta>" have "?P F G \<or> ?Q F G" using NegChecks assms(1) by simp hence "?P (F \<cdot>\<^sub>p\<^sub>a\<^sub>i\<^sub>r\<^sub>s ?\<theta>) (G \<cdot>\<^sub>p\<^sub>a\<^sub>i\<^sub>r\<^sub>s ?\<theta>) \<or> ?Q (F \<cdot>\<^sub>p\<^sub>a\<^sub>i\<^sub>r\<^sub>s ?\<theta>) (G \<cdot>\<^sub>p\<^sub>a\<^sub>i\<^sub>r\<^sub>s ?\<theta>)" proof assume *: "?P F G" have "G \<cdot>\<^sub>p\<^sub>a\<^sub>i\<^sub>r\<^sub>s ?\<theta> = []" using * by simp moreover have "\<exists>a. \<Gamma> (Var x) = TAtom a" when x: "x \<in> fv\<^sub>p\<^sub>a\<^sub>i\<^sub>r\<^sub>s (F \<cdot>\<^sub>p\<^sub>a\<^sub>i\<^sub>r\<^sub>s ?\<theta>) - set X" for x proof - obtain t t' where t: "(t,t') \<in> set (F \<cdot>\<^sub>p\<^sub>a\<^sub>i\<^sub>r\<^sub>s ?\<theta>)" "x \<in> fv t \<union> fv t' - set X" using x(1) by auto then obtain u u' where u: "(u,u') \<in> set F" "u \<cdot> ?\<theta> = t" "u' \<cdot> ?\<theta> = t'" unfolding subst_apply_pairs_def by auto obtain y where y: "y \<in> fv u \<union> fv u' - set X" "x \<in> fv (?\<theta> y)" using t(2) u(2,3) rm_vars_fv_obtain by fast hence a: "\<exists>a. \<Gamma> (Var y) = TAtom a" using u * by auto have a': "\<Gamma> (Var y) = \<Gamma> (?\<theta> y)" using wt_subst_trm''[OF wt_subst_rm_vars[OF \<theta>(1), of "set X"], of "Var y"] by simp have "(\<exists>z. ?\<theta> y = Var z) \<or> (\<exists>c. ?\<theta> y = Fun c [])" proof (cases "?\<theta> y \<in> subst_range \<theta>") case True thus ?thesis using a a' \<theta>(2) const_type_inv_wf by (cases "?\<theta> y") fastforce+ qed fastforce hence "?\<theta> y = Var x" using y(2) by fastforce hence "\<Gamma> (Var x) = \<Gamma> (Var y)" using a' by simp thus ?thesis using a by presburger qed ultimately show ?thesis by simp next assume *: "?Q F G" have **: "set X \<inter> range_vars ?\<theta> = {}" using \<theta>(3) NegChecks rm_vars_img_fv_subset[of "set X" \<theta>] by auto have "?Q (F \<cdot>\<^sub>p\<^sub>a\<^sub>i\<^sub>r\<^sub>s ?\<theta>) (G \<cdot>\<^sub>p\<^sub>a\<^sub>i\<^sub>r\<^sub>s ?\<theta>)" using ineq_subterm_inj_cond_subst[OF ** *] trms\<^sub>p\<^sub>a\<^sub>i\<^sub>r\<^sub>s_subst[of F "rm_vars (set X) \<theta>"] subst_apply_pairs_pair_image_subst[of G "rm_vars (set X) \<theta>"] by (metis (no_types, lifting) image_Un) thus ?thesis by simp qed thus ?thesis using NegChecks by simp qed simp_all lemma tfr\<^sub>s\<^sub>s\<^sub>t\<^sub>p_all_wt_subst_apply: assumes S: "list_all tfr\<^sub>s\<^sub>s\<^sub>t\<^sub>p S" and \<theta>: "wt\<^sub>s\<^sub>u\<^sub>b\<^sub>s\<^sub>t \<theta>" "wf\<^sub>t\<^sub>r\<^sub>m\<^sub>s (subst_range \<theta>)" "bvars\<^sub>s\<^sub>s\<^sub>t S \<inter> range_vars \<theta> = {}" shows "list_all tfr\<^sub>s\<^sub>s\<^sub>t\<^sub>p (S \<cdot>\<^sub>s\<^sub>s\<^sub>t \<theta>)" proof - have "set (bvars\<^sub>s\<^sub>s\<^sub>t\<^sub>p s) \<inter> range_vars \<theta> = {}" when "s \<in> set S" for s using that \<theta>(3) unfolding bvars\<^sub>s\<^sub>s\<^sub>t_def range_vars_alt_def by fastforce thus ?thesis using tfr\<^sub>s\<^sub>s\<^sub>t\<^sub>p_subst[OF _ \<theta>(1,2)] S unfolding list_all_iff by (auto simp add: subst_apply_stateful_strand_def) qed lemma tr\<^sub>p\<^sub>a\<^sub>i\<^sub>r\<^sub>s_empty_case: assumes "tr\<^sub>p\<^sub>a\<^sub>i\<^sub>r\<^sub>s F D = []" shows "D = []" "F \<noteq> []" proof - show "F \<noteq> []" using assms by (auto intro: ccontr) have "tr\<^sub>p\<^sub>a\<^sub>i\<^sub>r\<^sub>s F (a#A) \<noteq> []" for a A by (induct F "a#A" rule: tr\<^sub>p\<^sub>a\<^sub>i\<^sub>r\<^sub>s.induct) fastforce+ thus "D = []" using assms by (cases D) simp_all qed lemma tr\<^sub>p\<^sub>a\<^sub>i\<^sub>r\<^sub>s_elem_length_eq: assumes "G \<in> set (tr\<^sub>p\<^sub>a\<^sub>i\<^sub>r\<^sub>s F D)" shows "length G = length F" using assms by (induct F D arbitrary: G rule: tr\<^sub>p\<^sub>a\<^sub>i\<^sub>r\<^sub>s.induct) auto lemma tr\<^sub>p\<^sub>a\<^sub>i\<^sub>r\<^sub>s_index: assumes "G \<in> set (tr\<^sub>p\<^sub>a\<^sub>i\<^sub>r\<^sub>s F D)" "i < length F" shows "\<exists>d \<in> set D. G ! i = (pair (F ! i), pair d)" using assms proof (induction F D arbitrary: i G rule: tr\<^sub>p\<^sub>a\<^sub>i\<^sub>r\<^sub>s.induct) case (2 s t F D) obtain d G' where G: "d \<in> set D" "G' \<in> set (tr\<^sub>p\<^sub>a\<^sub>i\<^sub>r\<^sub>s F D)" "G = (pair (s,t), pair d)#G'" using "2.prems"(1) by moura show ?case using "2.IH"[OF G(1,2)] "2.prems"(2) G(1,3) by (cases i) auto qed simp lemma tr\<^sub>p\<^sub>a\<^sub>i\<^sub>r\<^sub>s_cons: assumes "G \<in> set (tr\<^sub>p\<^sub>a\<^sub>i\<^sub>r\<^sub>s F D)" "d \<in> set D" shows "(pair (s,t), pair d)#G \<in> set (tr\<^sub>p\<^sub>a\<^sub>i\<^sub>r\<^sub>s ((s,t)#F) D)" using assms by auto lemma tr\<^sub>p\<^sub>a\<^sub>i\<^sub>r\<^sub>s_has_pair_lists: assumes "G \<in> set (tr\<^sub>p\<^sub>a\<^sub>i\<^sub>r\<^sub>s F D)" "g \<in> set G" shows "\<exists>f \<in> set F. \<exists>d \<in> set D. g = (pair f, pair d)" using assms proof (induction F D arbitrary: G rule: tr\<^sub>p\<^sub>a\<^sub>i\<^sub>r\<^sub>s.induct) case (2 s t F D) obtain d G' where G: "d \<in> set D" "G' \<in> set (tr\<^sub>p\<^sub>a\<^sub>i\<^sub>r\<^sub>s F D)" "G = (pair (s,t), pair d)#G'" using "2.prems"(1) by moura show ?case using "2.IH"[OF G(1,2)] "2.prems"(2) G(1,3) by (cases "g \<in> set G'") auto qed simp lemma tr\<^sub>p\<^sub>a\<^sub>i\<^sub>r\<^sub>s_is_pair_lists: assumes "f \<in> set F" "d \<in> set D" shows "\<exists>G \<in> set (tr\<^sub>p\<^sub>a\<^sub>i\<^sub>r\<^sub>s F D). (pair f, pair d) \<in> set G" (is "?P F D f d") proof - have "\<forall>f \<in> set F. \<forall>d \<in> set D. ?P F D f d" proof (induction F D rule: tr\<^sub>p\<^sub>a\<^sub>i\<^sub>r\<^sub>s.induct) case (2 s t F D) hence IH: "\<forall>f \<in> set F. \<forall>d \<in> set D. ?P F D f d" by metis moreover have "\<forall>d \<in> set D. ?P ((s,t)#F) D (s,t) d" proof fix d assume d: "d \<in> set D" then obtain G where G: "G \<in> set (tr\<^sub>p\<^sub>a\<^sub>i\<^sub>r\<^sub>s F D)" using tr\<^sub>p\<^sub>a\<^sub>i\<^sub>r\<^sub>s_empty_case(1) by force hence "(pair (s, t), pair d)#G \<in> set (tr\<^sub>p\<^sub>a\<^sub>i\<^sub>r\<^sub>s ((s,t)#F) D)" using d by auto thus "?P ((s,t)#F) D (s,t) d" using d G by auto qed ultimately show ?case by fastforce qed simp thus ?thesis by (metis assms) qed lemma tr\<^sub>p\<^sub>a\<^sub>i\<^sub>r\<^sub>s_db_append_subset: "set (tr\<^sub>p\<^sub>a\<^sub>i\<^sub>r\<^sub>s F D) \<subseteq> set (tr\<^sub>p\<^sub>a\<^sub>i\<^sub>r\<^sub>s F (D@E))" (is ?A) "set (tr\<^sub>p\<^sub>a\<^sub>i\<^sub>r\<^sub>s F E) \<subseteq> set (tr\<^sub>p\<^sub>a\<^sub>i\<^sub>r\<^sub>s F (D@E))" (is ?B) proof - show ?A proof (induction F D rule: tr\<^sub>p\<^sub>a\<^sub>i\<^sub>r\<^sub>s.induct) case (2 s t F D) show ?case proof fix G assume "G \<in> set (tr\<^sub>p\<^sub>a\<^sub>i\<^sub>r\<^sub>s ((s,t)#F) D)" then obtain d G' where G': "d \<in> set D" "G' \<in> set (tr\<^sub>p\<^sub>a\<^sub>i\<^sub>r\<^sub>s F D)" "G = (pair (s,t), pair d)#G'" by moura have "d \<in> set (D@E)" "G' \<in> set (tr\<^sub>p\<^sub>a\<^sub>i\<^sub>r\<^sub>s F (D@E))" using "2.IH"[OF G'(1)] G'(1,2) by auto thus "G \<in> set (tr\<^sub>p\<^sub>a\<^sub>i\<^sub>r\<^sub>s ((s,t)#F) (D@E))" using G'(3) by auto qed qed simp show ?B proof (induction F E rule: tr\<^sub>p\<^sub>a\<^sub>i\<^sub>r\<^sub>s.induct) case (2 s t F E) show ?case proof fix G assume "G \<in> set (tr\<^sub>p\<^sub>a\<^sub>i\<^sub>r\<^sub>s ((s,t)#F) E)" then obtain d G' where G': "d \<in> set E" "G' \<in> set (tr\<^sub>p\<^sub>a\<^sub>i\<^sub>r\<^sub>s F E)" "G = (pair (s,t), pair d)#G'" by moura have "d \<in> set (D@E)" "G' \<in> set (tr\<^sub>p\<^sub>a\<^sub>i\<^sub>r\<^sub>s F (D@E))" using "2.IH"[OF G'(1)] G'(1,2) by auto thus "G \<in> set (tr\<^sub>p\<^sub>a\<^sub>i\<^sub>r\<^sub>s ((s,t)#F) (D@E))" using G'(3) by auto qed qed simp qed lemma tr\<^sub>p\<^sub>a\<^sub>i\<^sub>r\<^sub>s_trms_subset: "G \<in> set (tr\<^sub>p\<^sub>a\<^sub>i\<^sub>r\<^sub>s F D) \<Longrightarrow> trms\<^sub>p\<^sub>a\<^sub>i\<^sub>r\<^sub>s G \<subseteq> pair ` set F \<union> pair ` set D" proof (induction F D arbitrary: G rule: tr\<^sub>p\<^sub>a\<^sub>i\<^sub>r\<^sub>s.induct) case (2 s t F D G) obtain d G' where G: "d \<in> set D" "G' \<in> set (tr\<^sub>p\<^sub>a\<^sub>i\<^sub>r\<^sub>s F D)" "G = (pair (s,t), pair d)#G'" using "2.prems"(1) by moura show ?case using "2.IH"[OF G(1,2)] G(1,3) by auto qed simp lemma tr\<^sub>p\<^sub>a\<^sub>i\<^sub>r\<^sub>s_trms_subset': "\<Union>(trms\<^sub>p\<^sub>a\<^sub>i\<^sub>r\<^sub>s ` set (tr\<^sub>p\<^sub>a\<^sub>i\<^sub>r\<^sub>s F D)) \<subseteq> pair ` set F \<union> pair ` set D" using tr\<^sub>p\<^sub>a\<^sub>i\<^sub>r\<^sub>s_trms_subset by blast lemma tr_trms_subset: "A' \<in> set (tr A D) \<Longrightarrow> trms\<^sub>s\<^sub>t A' \<subseteq> trms\<^sub>s\<^sub>s\<^sub>t A \<union> pair ` setops\<^sub>s\<^sub>s\<^sub>t A \<union> pair ` set D" proof (induction A D arbitrary: A' rule: tr.induct) case 1 thus ?case by simp next case (2 t A D) then obtain A'' where A'': "A' = send\<langle>t\<rangle>\<^sub>s\<^sub>t#A''" "A'' \<in> set (tr A D)" by moura hence "trms\<^sub>s\<^sub>t A'' \<subseteq> trms\<^sub>s\<^sub>s\<^sub>t A \<union> pair ` setops\<^sub>s\<^sub>s\<^sub>t A \<union> pair ` set D" by (metis "2.IH") thus ?case using A'' by (auto simp add: setops\<^sub>s\<^sub>s\<^sub>t_def) next case (3 t A D) then obtain A'' where A'': "A' = receive\<langle>t\<rangle>\<^sub>s\<^sub>t#A''" "A'' \<in> set (tr A D)" by moura hence "trms\<^sub>s\<^sub>t A'' \<subseteq> trms\<^sub>s\<^sub>s\<^sub>t A \<union> pair ` setops\<^sub>s\<^sub>s\<^sub>t A \<union> pair ` set D" by (metis "3.IH") thus ?case using A'' by (auto simp add: setops\<^sub>s\<^sub>s\<^sub>t_def) next case (4 ac t t' A D) then obtain A'' where A'': "A' = \<langle>ac: t \<doteq> t'\<rangle>\<^sub>s\<^sub>t#A''" "A'' \<in> set (tr A D)" by moura hence "trms\<^sub>s\<^sub>t A'' \<subseteq> trms\<^sub>s\<^sub>s\<^sub>t A \<union> pair ` setops\<^sub>s\<^sub>s\<^sub>t A \<union> pair ` set D" by (metis "4.IH") thus ?case using A'' by (auto simp add: setops\<^sub>s\<^sub>s\<^sub>t_def) next case (5 t s A D) hence "A' \<in> set (tr A (List.insert (t,s) D))" by simp hence "trms\<^sub>s\<^sub>t A' \<subseteq> trms\<^sub>s\<^sub>s\<^sub>t A \<union> pair ` setops\<^sub>s\<^sub>s\<^sub>t A \<union> pair ` set (List.insert (t, s) D)" by (metis "5.IH") thus ?case by (auto simp add: setops\<^sub>s\<^sub>s\<^sub>t_def) next case (6 t s A D) from 6 obtain Di A'' B C where A'': "Di \<in> set (subseqs D)" "A'' \<in> set (tr A [d\<leftarrow>D. d \<notin> set Di])" "A' = (B@C)@A''" "B = map (\<lambda>d. \<langle>check: (pair (t,s)) \<doteq> (pair d)\<rangle>\<^sub>s\<^sub>t) Di" "C = map (\<lambda>d. Inequality [] [(pair (t,s) , pair d)]) [d\<leftarrow>D. d \<notin> set Di]" by moura hence "trms\<^sub>s\<^sub>t A'' \<subseteq> trms\<^sub>s\<^sub>s\<^sub>t A \<union> pair ` setops\<^sub>s\<^sub>s\<^sub>t A \<union> pair ` set [d\<leftarrow>D. d \<notin> set Di]" by (metis "6.IH") hence "trms\<^sub>s\<^sub>t A'' \<subseteq> trms\<^sub>s\<^sub>s\<^sub>t (Delete t s#A) \<union> pair ` setops\<^sub>s\<^sub>s\<^sub>t (Delete t s#A) \<union> pair ` set D" by (auto simp add: setops\<^sub>s\<^sub>s\<^sub>t_def) moreover have "trms\<^sub>s\<^sub>t (B@C) \<subseteq> insert (pair (t,s)) (pair ` set D)" using A''(4,5) subseqs_set_subset[OF A''(1)] by auto moreover have "pair (t,s) \<in> pair ` setops\<^sub>s\<^sub>s\<^sub>t (Delete t s#A)" by (simp add: setops\<^sub>s\<^sub>s\<^sub>t_def) ultimately show ?case using A''(3) trms\<^sub>s\<^sub>t_append[of "B@C" A'] by auto next case (7 ac t s A D) from 7 obtain d A'' where A'': "d \<in> set D" "A'' \<in> set (tr A D)" "A' = \<langle>ac: (pair (t,s)) \<doteq> (pair d)\<rangle>\<^sub>s\<^sub>t#A''" by moura hence "trms\<^sub>s\<^sub>t A'' \<subseteq> trms\<^sub>s\<^sub>s\<^sub>t A \<union> pair ` setops\<^sub>s\<^sub>s\<^sub>t A \<union> pair ` set D" by (metis "7.IH") moreover have "trms\<^sub>s\<^sub>t A' = {pair (t,s), pair d} \<union> trms\<^sub>s\<^sub>t A''" using A''(1,3) by auto ultimately show ?case using A''(1) by (auto simp add: setops\<^sub>s\<^sub>s\<^sub>t_def) next case (8 X F F' A D) from 8 obtain A'' where A'': "A'' \<in> set (tr A D)" "A' = (map (\<lambda>G. \<forall>X\<langle>\<or>\<noteq>: (F@G)\<rangle>\<^sub>s\<^sub>t) (tr\<^sub>p\<^sub>a\<^sub>i\<^sub>r\<^sub>s F' D))@A''" by moura define B where "B \<equiv> \<Union>(trms\<^sub>p\<^sub>a\<^sub>i\<^sub>r\<^sub>s ` set (tr\<^sub>p\<^sub>a\<^sub>i\<^sub>r\<^sub>s F' D))" have "trms\<^sub>s\<^sub>t A'' \<subseteq> trms\<^sub>s\<^sub>s\<^sub>t A \<union> pair ` setops\<^sub>s\<^sub>s\<^sub>t A \<union> pair ` set D" by (metis A''(1) "8.IH") hence "trms\<^sub>s\<^sub>t A' \<subseteq> B \<union> trms\<^sub>p\<^sub>a\<^sub>i\<^sub>r\<^sub>s F \<union> trms\<^sub>s\<^sub>s\<^sub>t A \<union> pair ` setops\<^sub>s\<^sub>s\<^sub>t A \<union> pair ` set D" using A'' B_def by auto moreover have "B \<subseteq> pair ` set F' \<union> pair ` set D" using tr\<^sub>p\<^sub>a\<^sub>i\<^sub>r\<^sub>s_trms_subset'[of F' D] B_def by simp moreover have "pair ` setops\<^sub>s\<^sub>s\<^sub>t (\<forall>X\<langle>\<or>\<noteq>: F \<or>\<notin>: F'\<rangle>#A) = pair ` set F' \<union> pair ` setops\<^sub>s\<^sub>s\<^sub>t A" by (auto simp add: setops\<^sub>s\<^sub>s\<^sub>t_def) ultimately show ?case by auto qed lemma tr\<^sub>p\<^sub>a\<^sub>i\<^sub>r\<^sub>s_vars_subset: "G \<in> set (tr\<^sub>p\<^sub>a\<^sub>i\<^sub>r\<^sub>s F D) \<Longrightarrow> fv\<^sub>p\<^sub>a\<^sub>i\<^sub>r\<^sub>s G \<subseteq> fv\<^sub>p\<^sub>a\<^sub>i\<^sub>r\<^sub>s F \<union> fv\<^sub>p\<^sub>a\<^sub>i\<^sub>r\<^sub>s D" proof (induction F D arbitrary: G rule: tr\<^sub>p\<^sub>a\<^sub>i\<^sub>r\<^sub>s.induct) case (2 s t F D G) obtain d G' where G: "d \<in> set D" "G' \<in> set (tr\<^sub>p\<^sub>a\<^sub>i\<^sub>r\<^sub>s F D)" "G = (pair (s,t), pair d)#G'" using "2.prems"(1) by moura show ?case using "2.IH"[OF G(1,2)] G(1,3) unfolding pair_def by auto qed simp lemma tr\<^sub>p\<^sub>a\<^sub>i\<^sub>r\<^sub>s_vars_subset': "\<Union>(fv\<^sub>p\<^sub>a\<^sub>i\<^sub>r\<^sub>s ` set (tr\<^sub>p\<^sub>a\<^sub>i\<^sub>r\<^sub>s F D)) \<subseteq> fv\<^sub>p\<^sub>a\<^sub>i\<^sub>r\<^sub>s F \<union> fv\<^sub>p\<^sub>a\<^sub>i\<^sub>r\<^sub>s D" using tr\<^sub>p\<^sub>a\<^sub>i\<^sub>r\<^sub>s_vars_subset[of _ F D] by blast lemma tr_vars_subset: assumes "A' \<in> set (tr A D)" shows "fv\<^sub>s\<^sub>t A' \<subseteq> fv\<^sub>s\<^sub>s\<^sub>t A \<union> (\<Union>(t,t') \<in> set D. fv t \<union> fv t')" (is ?P) and "bvars\<^sub>s\<^sub>t A' \<subseteq> bvars\<^sub>s\<^sub>s\<^sub>t A" (is ?Q) proof - show ?P using assms proof (induction A arbitrary: A' D rule: strand_sem_stateful_induct) case (ConsIn A' D ac t s A) then obtain A'' d where *: "d \<in> set D" "A' = \<langle>ac: (pair (t,s)) \<doteq> (pair d)\<rangle>\<^sub>s\<^sub>t#A''" "A'' \<in> set (tr A D)" by moura hence "fv\<^sub>s\<^sub>t A'' \<subseteq> fv\<^sub>s\<^sub>s\<^sub>t A \<union> (\<Union>(t,t')\<in>set D. fv t \<union> fv t')" by (metis ConsIn.IH) thus ?case using * unfolding pair_def by auto next case (ConsDel A' D t s A) define Dfv where "Dfv \<equiv> \<lambda>D::('fun,'var) dbstatelist. (\<Union>(t,t')\<in>set D. fv t \<union> fv t')" define fltD where "fltD \<equiv> \<lambda>Di. filter (\<lambda>d. d \<notin> set Di) D" define constr where "constr \<equiv> \<lambda>Di. (map (\<lambda>d. \<langle>check: (pair (t,s)) \<doteq> (pair d)\<rangle>\<^sub>s\<^sub>t) Di)@ (map (\<lambda>d. \<forall>[]\<langle>\<or>\<noteq>: [(pair (t,s), pair d)]\<rangle>\<^sub>s\<^sub>t) (fltD Di))" from ConsDel obtain A'' Di where *: "Di \<in> set (subseqs D)" "A' = (constr Di)@A''" "A'' \<in> set (tr A (fltD Di))" unfolding constr_def fltD_def by moura hence "fv\<^sub>s\<^sub>t A'' \<subseteq> fv\<^sub>s\<^sub>s\<^sub>t A \<union> Dfv (fltD Di)" unfolding Dfv_def constr_def fltD_def by (metis ConsDel.IH) moreover have "Dfv (fltD Di) \<subseteq> Dfv D" unfolding Dfv_def constr_def fltD_def by auto moreover have "Dfv Di \<subseteq> Dfv D" using subseqs_set_subset(1)[OF *(1)] unfolding Dfv_def constr_def fltD_def by fast moreover have "fv\<^sub>s\<^sub>t (constr Di) \<subseteq> fv t \<union> fv s \<union> (Dfv Di \<union> Dfv (fltD Di))" unfolding Dfv_def constr_def fltD_def pair_def by auto moreover have "fv\<^sub>s\<^sub>s\<^sub>t (Delete t s#A) = fv t \<union> fv s \<union> fv\<^sub>s\<^sub>s\<^sub>t A" by auto moreover have "fv\<^sub>s\<^sub>t A' = fv\<^sub>s\<^sub>t (constr Di) \<union> fv\<^sub>s\<^sub>t A''" using * by force ultimately have "fv\<^sub>s\<^sub>t A' \<subseteq> fv\<^sub>s\<^sub>s\<^sub>t (Delete t s#A) \<union> Dfv D" by auto thus ?case unfolding Dfv_def fltD_def constr_def by simp next case (ConsNegChecks A' D X F F' A) then obtain A'' where A'': "A'' \<in> set (tr A D)" "A' = (map (\<lambda>G. \<forall>X\<langle>\<or>\<noteq>: (F@G)\<rangle>\<^sub>s\<^sub>t) (tr\<^sub>p\<^sub>a\<^sub>i\<^sub>r\<^sub>s F' D))@A''" by moura define B where "B \<equiv> \<Union>(fv\<^sub>p\<^sub>a\<^sub>i\<^sub>r\<^sub>s ` set (tr\<^sub>p\<^sub>a\<^sub>i\<^sub>r\<^sub>s F' D))" have 1: "fv\<^sub>s\<^sub>t (map (\<lambda>G. \<forall>X\<langle>\<or>\<noteq>: (F@G)\<rangle>\<^sub>s\<^sub>t) (tr\<^sub>p\<^sub>a\<^sub>i\<^sub>r\<^sub>s F' D)) \<subseteq> (B \<union> fv\<^sub>p\<^sub>a\<^sub>i\<^sub>r\<^sub>s F) - set X" unfolding B_def by auto have 2: "B \<subseteq> fv\<^sub>p\<^sub>a\<^sub>i\<^sub>r\<^sub>s F' \<union> fv\<^sub>p\<^sub>a\<^sub>i\<^sub>r\<^sub>s D" using tr\<^sub>p\<^sub>a\<^sub>i\<^sub>r\<^sub>s_vars_subset'[of F' D] unfolding B_def by simp have "fv\<^sub>s\<^sub>t A' \<subseteq> ((fv\<^sub>p\<^sub>a\<^sub>i\<^sub>r\<^sub>s F' \<union> fv\<^sub>p\<^sub>a\<^sub>i\<^sub>r\<^sub>s D \<union> fv\<^sub>p\<^sub>a\<^sub>i\<^sub>r\<^sub>s F) - set X) \<union> fv\<^sub>s\<^sub>t A''" using 1 2 A''(2) by fastforce thus ?case using ConsNegChecks.IH[OF A''(1)] by auto qed fastforce+ show ?Q using assms by (induct A arbitrary: A' D rule: strand_sem_stateful_induct) fastforce+ qed lemma tr_vars_disj: assumes "A' \<in> set (tr A D)" "\<forall>(t,t') \<in> set D. (fv t \<union> fv t') \<inter> bvars\<^sub>s\<^sub>s\<^sub>t A = {}" and "fv\<^sub>s\<^sub>s\<^sub>t A \<inter> bvars\<^sub>s\<^sub>s\<^sub>t A = {}" shows "fv\<^sub>s\<^sub>t A' \<inter> bvars\<^sub>s\<^sub>t A' = {}" using assms tr_vars_subset by fast lemma wf_fun_pair_ineqs_map: assumes "wf\<^sub>s\<^sub>t X A" shows "wf\<^sub>s\<^sub>t X (map (\<lambda>d. \<forall>Y\<langle>\<or>\<noteq>: [(pair (t, s), pair d)]\<rangle>\<^sub>s\<^sub>t) D@A)" using assms by (induct D) auto lemma wf_fun_pair_negchecks_map: assumes "wf\<^sub>s\<^sub>t X A" shows "wf\<^sub>s\<^sub>t X (map (\<lambda>G. \<forall>Y\<langle>\<or>\<noteq>: (F@G)\<rangle>\<^sub>s\<^sub>t) M@A)" using assms by (induct M) auto lemma wf_fun_pair_eqs_ineqs_map: fixes A::"('fun,'var) strand" assumes "wf\<^sub>s\<^sub>t X A" "Di \<in> set (subseqs D)" "\<forall>(t,t') \<in> set D. fv t \<union> fv t' \<subseteq> X" shows "wf\<^sub>s\<^sub>t X ((map (\<lambda>d. \<langle>check: (pair (t,s)) \<doteq> (pair d)\<rangle>\<^sub>s\<^sub>t) Di)@ (map (\<lambda>d. \<forall>[]\<langle>\<or>\<noteq>: [(pair (t,s), pair d)]\<rangle>\<^sub>s\<^sub>t) [d\<leftarrow>D. d \<notin> set Di])@A)" proof - let ?c1 = "map (\<lambda>d. \<langle>check: (pair (t,s)) \<doteq> (pair d)\<rangle>\<^sub>s\<^sub>t) Di" let ?c2 = "map (\<lambda>d. \<forall>[]\<langle>\<or>\<noteq>: [(pair (t,s), pair d)]\<rangle>\<^sub>s\<^sub>t) [d\<leftarrow>D. d \<notin> set Di]" have 1: "wf\<^sub>s\<^sub>t X (?c2@A)" using wf_fun_pair_ineqs_map[OF assms(1)] by simp have 2: "\<forall>(t,t') \<in> set Di. fv t \<union> fv t' \<subseteq> X" using assms(2,3) by (meson contra_subsetD subseqs_set_subset(1)) have "wf\<^sub>s\<^sub>t X (?c1@B)" when "wf\<^sub>s\<^sub>t X B" for B::"('fun,'var) strand" using 2 that by (induct Di) auto thus ?thesis using 1 by simp qed lemma trms\<^sub>s\<^sub>s\<^sub>t_wt_subst_ex: assumes \<theta>: "wt\<^sub>s\<^sub>u\<^sub>b\<^sub>s\<^sub>t \<theta>" "wf\<^sub>t\<^sub>r\<^sub>m\<^sub>s (subst_range \<theta>)" and t: "t \<in> trms\<^sub>s\<^sub>s\<^sub>t (S \<cdot>\<^sub>s\<^sub>s\<^sub>t \<theta>)" shows "\<exists>s \<delta>. s \<in> trms\<^sub>s\<^sub>s\<^sub>t S \<and> wt\<^sub>s\<^sub>u\<^sub>b\<^sub>s\<^sub>t \<delta> \<and> wf\<^sub>t\<^sub>r\<^sub>m\<^sub>s (subst_range \<delta>) \<and> t = s \<cdot> \<delta>" using t proof (induction S) case (Cons s S) thus ?case proof (cases "t \<in> trms\<^sub>s\<^sub>s\<^sub>t (S \<cdot>\<^sub>s\<^sub>s\<^sub>t \<theta>)") case False hence "t \<in> trms\<^sub>s\<^sub>s\<^sub>t\<^sub>p (s \<cdot>\<^sub>s\<^sub>s\<^sub>t\<^sub>p \<theta>)" using Cons.prems trms\<^sub>s\<^sub>s\<^sub>t_subst_cons[of s S \<theta>] by auto then obtain u where u: "u \<in> trms\<^sub>s\<^sub>s\<^sub>t\<^sub>p s" "t = u \<cdot> rm_vars (set (bvars\<^sub>s\<^sub>s\<^sub>t\<^sub>p s)) \<theta>" using trms\<^sub>s\<^sub>s\<^sub>t\<^sub>p_subst'' by blast thus ?thesis using trms\<^sub>s\<^sub>s\<^sub>t_subst_cons[of s S \<theta>] wt_subst_rm_vars[OF \<theta>(1), of "set (bvars\<^sub>s\<^sub>s\<^sub>t\<^sub>p s)"] wf_trms_subst_rm_vars'[OF \<theta>(2), of "set (bvars\<^sub>s\<^sub>s\<^sub>t\<^sub>p s)"] by fastforce qed auto qed simp lemma setops\<^sub>s\<^sub>s\<^sub>t_wt_subst_ex: assumes \<theta>: "wt\<^sub>s\<^sub>u\<^sub>b\<^sub>s\<^sub>t \<theta>" "wf\<^sub>t\<^sub>r\<^sub>m\<^sub>s (subst_range \<theta>)" and t: "t \<in> pair ` setops\<^sub>s\<^sub>s\<^sub>t (S \<cdot>\<^sub>s\<^sub>s\<^sub>t \<theta>)" shows "\<exists>s \<delta>. s \<in> pair ` setops\<^sub>s\<^sub>s\<^sub>t S \<and> wt\<^sub>s\<^sub>u\<^sub>b\<^sub>s\<^sub>t \<delta> \<and> wf\<^sub>t\<^sub>r\<^sub>m\<^sub>s (subst_range \<delta>) \<and> t = s \<cdot> \<delta>" using t proof (induction S) case (Cons x S) thus ?case proof (cases x) case (Insert t' s) hence "t = pair (t',s) \<cdot> \<theta> \<or> t \<in> pair ` setops\<^sub>s\<^sub>s\<^sub>t (S \<cdot>\<^sub>s\<^sub>s\<^sub>t \<theta>)" using Cons.prems subst_sst_cons[of _ S \<theta>] unfolding pair_def by (force simp add: setops\<^sub>s\<^sub>s\<^sub>t_def) thus ?thesis using Insert Cons.IH \<theta> by (cases "t = pair (t', s) \<cdot> \<theta>") (fastforce, auto) next case (Delete t' s) hence "t = pair (t',s) \<cdot> \<theta> \<or> t \<in> pair ` setops\<^sub>s\<^sub>s\<^sub>t (S \<cdot>\<^sub>s\<^sub>s\<^sub>t \<theta>)" using Cons.prems subst_sst_cons[of _ S \<theta>] unfolding pair_def by (force simp add: setops\<^sub>s\<^sub>s\<^sub>t_def) thus ?thesis using Delete Cons.IH \<theta> by (cases "t = pair (t', s) \<cdot> \<theta>") (fastforce, auto) next case (InSet ac t' s) hence "t = pair (t',s) \<cdot> \<theta> \<or> t \<in> pair ` setops\<^sub>s\<^sub>s\<^sub>t (S \<cdot>\<^sub>s\<^sub>s\<^sub>t \<theta>)" using Cons.prems subst_sst_cons[of _ S \<theta>] unfolding pair_def by (force simp add: setops\<^sub>s\<^sub>s\<^sub>t_def) thus ?thesis using InSet Cons.IH \<theta> by (cases "t = pair (t', s) \<cdot> \<theta>") (fastforce, auto) next case (NegChecks X F F') hence "t \<in> pair ` set (F' \<cdot>\<^sub>p\<^sub>a\<^sub>i\<^sub>r\<^sub>s rm_vars (set X) \<theta>) \<or> t \<in> pair ` setops\<^sub>s\<^sub>s\<^sub>t (S \<cdot>\<^sub>s\<^sub>s\<^sub>t \<theta>)" using Cons.prems subst_sst_cons[of _ S \<theta>] unfolding pair_def by (force simp add: setops\<^sub>s\<^sub>s\<^sub>t_def) thus ?thesis proof assume "t \<in> pair ` set (F' \<cdot>\<^sub>p\<^sub>a\<^sub>i\<^sub>r\<^sub>s rm_vars (set X) \<theta>)" then obtain s where s: "t = s \<cdot> rm_vars (set X) \<theta>" "s \<in> pair ` set F'" using subst_apply_pairs_pair_image_subst[of F' "rm_vars (set X) \<theta>"] by auto thus ?thesis using NegChecks setops\<^sub>s\<^sub>s\<^sub>t_pair_image_cons(8)[of X F F' S] wt_subst_rm_vars[OF \<theta>(1), of "set X"] wf_trms_subst_rm_vars'[OF \<theta>(2), of "set X"] by fast qed (use Cons.IH in auto) qed (auto simp add: setops\<^sub>s\<^sub>s\<^sub>t_def subst_sst_cons[of _ S \<theta>]) qed (simp add: setops\<^sub>s\<^sub>s\<^sub>t_def) lemma setops\<^sub>s\<^sub>s\<^sub>t_wf\<^sub>t\<^sub>r\<^sub>m\<^sub>s: "wf\<^sub>t\<^sub>r\<^sub>m\<^sub>s (trms\<^sub>s\<^sub>s\<^sub>t A) \<Longrightarrow> wf\<^sub>t\<^sub>r\<^sub>m\<^sub>s (pair ` setops\<^sub>s\<^sub>s\<^sub>t A)" "wf\<^sub>t\<^sub>r\<^sub>m\<^sub>s (trms\<^sub>s\<^sub>s\<^sub>t A) \<Longrightarrow> wf\<^sub>t\<^sub>r\<^sub>m\<^sub>s (trms\<^sub>s\<^sub>s\<^sub>t A \<union> pair ` setops\<^sub>s\<^sub>s\<^sub>t A)" proof - show "wf\<^sub>t\<^sub>r\<^sub>m\<^sub>s (trms\<^sub>s\<^sub>s\<^sub>t A) \<Longrightarrow> wf\<^sub>t\<^sub>r\<^sub>m\<^sub>s (pair ` setops\<^sub>s\<^sub>s\<^sub>t A)" proof (induction A) case (Cons a A) hence 0: "wf\<^sub>t\<^sub>r\<^sub>m\<^sub>s (trms\<^sub>s\<^sub>s\<^sub>t\<^sub>p a)" "wf\<^sub>t\<^sub>r\<^sub>m\<^sub>s (pair ` setops\<^sub>s\<^sub>s\<^sub>t A)" by auto thus ?case proof (cases a) case (NegChecks X F F') hence "wf\<^sub>t\<^sub>r\<^sub>m\<^sub>s (trms\<^sub>p\<^sub>a\<^sub>i\<^sub>r\<^sub>s F')" using 0 by simp thus ?thesis using NegChecks wf\<^sub>t\<^sub>r\<^sub>m\<^sub>s_pairs[of F'] 0 by (auto simp add: setops\<^sub>s\<^sub>s\<^sub>t_def) qed (auto simp add: setops\<^sub>s\<^sub>s\<^sub>t_def dest: fun_pair_wf\<^sub>t\<^sub>r\<^sub>m) qed (auto simp add: setops\<^sub>s\<^sub>s\<^sub>t_def) thus "wf\<^sub>t\<^sub>r\<^sub>m\<^sub>s (trms\<^sub>s\<^sub>s\<^sub>t A) \<Longrightarrow> wf\<^sub>t\<^sub>r\<^sub>m\<^sub>s (trms\<^sub>s\<^sub>s\<^sub>t A \<union> pair ` setops\<^sub>s\<^sub>s\<^sub>t A)" by fast qed lemma SMP_MP_split: assumes "t \<in> SMP M" and M: "\<forall>m \<in> M. is_Fun m" shows "(\<exists>\<delta>. wt\<^sub>s\<^sub>u\<^sub>b\<^sub>s\<^sub>t \<delta> \<and> wf\<^sub>t\<^sub>r\<^sub>m\<^sub>s (subst_range \<delta>) \<and> t \<in> M \<cdot>\<^sub>s\<^sub>e\<^sub>t \<delta>) \<or> t \<in> SMP ((subterms\<^sub>s\<^sub>e\<^sub>t M \<union> \<Union>((set \<circ> fst \<circ> Ana) ` M)) - M)" (is "?P t \<or> ?Q t") using assms(1) proof (induction t rule: SMP.induct) case (MP t) have "wt\<^sub>s\<^sub>u\<^sub>b\<^sub>s\<^sub>t Var" "wf\<^sub>t\<^sub>r\<^sub>m\<^sub>s (subst_range Var)" "M \<cdot>\<^sub>s\<^sub>e\<^sub>t Var = M" by simp_all thus ?case using MP by metis next case (Subterm t t') show ?case using Subterm.IH proof assume "?P t" then obtain s \<delta> where s: "s \<in> M" "t = s \<cdot> \<delta>" and \<delta>: "wt\<^sub>s\<^sub>u\<^sub>b\<^sub>s\<^sub>t \<delta>" "wf\<^sub>t\<^sub>r\<^sub>m\<^sub>s (subst_range \<delta>)" by moura then obtain f T where fT: "s = Fun f T" using M by fast have "(\<exists>s'. s' \<sqsubseteq> s \<and> t' = s' \<cdot> \<delta>) \<or> (\<exists>x \<in> fv s. t' \<sqsubset> \<delta> x)" using subterm_subst_unfold[OF Subterm.hyps(2)[unfolded s(2)]] by blast thus ?thesis proof assume "\<exists>s'. s' \<sqsubseteq> s \<and> t' = s' \<cdot> \<delta>" then obtain s' where s': "s' \<sqsubseteq> s" "t' = s' \<cdot> \<delta>" by moura show ?thesis proof (cases "s' \<in> M") case True thus ?thesis using s' \<delta> by blast next case False hence "s' \<in> (subterms\<^sub>s\<^sub>e\<^sub>t M \<union> \<Union>((set \<circ> fst \<circ> Ana) ` M)) - M" using s'(1) s(1) by force thus ?thesis using SMP.Substitution[OF SMP.MP[of s'] \<delta>] s' by presburger qed next assume "\<exists>x \<in> fv s. t' \<sqsubset> \<delta> x" then obtain x where x: "x \<in> fv s" "t' \<sqsubset> \<delta> x" by moura have "Var x \<notin> M" using M by blast hence "Var x \<in> (subterms\<^sub>s\<^sub>e\<^sub>t M \<union> \<Union>((set \<circ> fst \<circ> Ana) ` M)) - M" using s(1) var_is_subterm[OF x(1)] by blast hence "\<delta> x \<in> SMP ((subterms\<^sub>s\<^sub>e\<^sub>t M \<union> \<Union>((set \<circ> fst \<circ> Ana) ` M)) - M)" using SMP.Substitution[OF SMP.MP[of "Var x"] \<delta>] by auto thus ?thesis using SMP.Subterm x(2) by presburger qed qed (metis SMP.Subterm[OF _ Subterm.hyps(2)]) next case (Substitution t \<delta>) show ?case using Substitution.IH proof assume "?P t" then obtain \<theta> where "wt\<^sub>s\<^sub>u\<^sub>b\<^sub>s\<^sub>t \<theta>" "wf\<^sub>t\<^sub>r\<^sub>m\<^sub>s (subst_range \<theta>)" "t \<in> M \<cdot>\<^sub>s\<^sub>e\<^sub>t \<theta>" by moura hence "wt\<^sub>s\<^sub>u\<^sub>b\<^sub>s\<^sub>t (\<theta> \<circ>\<^sub>s \<delta>)" "wf\<^sub>t\<^sub>r\<^sub>m\<^sub>s (subst_range (\<theta> \<circ>\<^sub>s \<delta>))" "t \<cdot> \<delta> \<in> M \<cdot>\<^sub>s\<^sub>e\<^sub>t (\<theta> \<circ>\<^sub>s \<delta>)" using wt_subst_compose[of \<theta>, OF _ Substitution.hyps(2)] wf_trm_subst_compose[of \<theta> _ \<delta>, OF _ wf_trm_subst_rangeD[OF Substitution.hyps(3)]] wf_trm_subst_range_iff by (argo, blast, auto) thus ?thesis by blast next assume "?Q t" thus ?thesis using SMP.Substitution[OF _ Substitution.hyps(2,3)] by meson qed next case (Ana t K T k) show ?case using Ana.IH proof assume "?P t" then obtain \<theta> where \<theta>: "wt\<^sub>s\<^sub>u\<^sub>b\<^sub>s\<^sub>t \<theta>" "wf\<^sub>t\<^sub>r\<^sub>m\<^sub>s (subst_range \<theta>)" "t \<in> M \<cdot>\<^sub>s\<^sub>e\<^sub>t \<theta>" by moura then obtain s where s: "s \<in> M" "t = s \<cdot> \<theta>" by auto then obtain f S where fT: "s = Fun f S" using M by (cases s) auto obtain K' T' where s_Ana: "Ana s = (K', T')" by (metis surj_pair) hence "set K = set K' \<cdot>\<^sub>s\<^sub>e\<^sub>t \<theta>" "set T = set T' \<cdot>\<^sub>s\<^sub>e\<^sub>t \<theta>" using Ana_subst'[of f S K' T'] fT Ana.hyps(2) s(2) by auto then obtain k' where k': "k' \<in> set K'" "k = k' \<cdot> \<theta>" using Ana.hyps(3) by fast show ?thesis proof (cases "k' \<in> M") case True thus ?thesis using k' \<theta>(1,2) by blast next case False hence "k' \<in> (subterms\<^sub>s\<^sub>e\<^sub>t M \<union> \<Union>((set \<circ> fst \<circ> Ana) ` M)) - M" using k'(1) s_Ana s(1) by force thus ?thesis using SMP.Substitution[OF SMP.MP[of k'] \<theta>(1,2)] k'(2) by presburger qed next assume "?Q t" thus ?thesis using SMP.Ana[OF _ Ana.hyps(2,3)] by meson qed qed lemma setops_subterm_trms: assumes t: "t \<in> pair ` setops\<^sub>s\<^sub>s\<^sub>t S" and s: "s \<sqsubset> t" shows "s \<in> subterms\<^sub>s\<^sub>e\<^sub>t (trms\<^sub>s\<^sub>s\<^sub>t S)" proof - obtain u u' where u: "pair (u,u') \<in> pair ` setops\<^sub>s\<^sub>s\<^sub>t S" "t = pair (u,u')" using t setops\<^sub>s\<^sub>s\<^sub>t_are_pairs[of _ S] by blast hence "s \<sqsubseteq> u \<or> s \<sqsubseteq> u'" using s unfolding pair_def by auto thus ?thesis using u setops\<^sub>s\<^sub>s\<^sub>t_member_iff[of u u' S] unfolding trms\<^sub>s\<^sub>s\<^sub>t_def by force qed lemma setops_subterms_cases: assumes t: "t \<in> subterms\<^sub>s\<^sub>e\<^sub>t (pair ` setops\<^sub>s\<^sub>s\<^sub>t S)" shows "t \<in> subterms\<^sub>s\<^sub>e\<^sub>t (trms\<^sub>s\<^sub>s\<^sub>t S) \<or> t \<in> pair ` setops\<^sub>s\<^sub>s\<^sub>t S" proof - obtain s s' where s: "pair (s,s') \<in> pair ` setops\<^sub>s\<^sub>s\<^sub>t S" "t \<sqsubseteq> pair (s,s')" using t setops\<^sub>s\<^sub>s\<^sub>t_are_pairs[of _ S] by blast hence "t \<in> pair ` setops\<^sub>s\<^sub>s\<^sub>t S \<or> t \<sqsubseteq> s \<or> t \<sqsubseteq> s'" unfolding pair_def by auto thus ?thesis using s setops\<^sub>s\<^sub>s\<^sub>t_member_iff[of s s' S] unfolding trms\<^sub>s\<^sub>s\<^sub>t_def by force qed lemma setops_SMP_cases: assumes "t \<in> SMP (pair ` setops\<^sub>s\<^sub>s\<^sub>t S)" and "\<forall>p. Ana (pair p) = ([], [])" shows "(\<exists>\<delta>. wt\<^sub>s\<^sub>u\<^sub>b\<^sub>s\<^sub>t \<delta> \<and> wf\<^sub>t\<^sub>r\<^sub>m\<^sub>s (subst_range \<delta>) \<and> t \<in> pair ` setops\<^sub>s\<^sub>s\<^sub>t S \<cdot>\<^sub>s\<^sub>e\<^sub>t \<delta>) \<or> t \<in> SMP (trms\<^sub>s\<^sub>s\<^sub>t S)" proof - have 0: "\<Union>((set \<circ> fst \<circ> Ana) ` pair ` setops\<^sub>s\<^sub>s\<^sub>t S) = {}" proof (induction S) case (Cons x S) thus ?case using assms(2) by (cases x) (auto simp add: setops\<^sub>s\<^sub>s\<^sub>t_def) qed (simp add: setops\<^sub>s\<^sub>s\<^sub>t_def) have 1: "\<forall>m \<in> pair ` setops\<^sub>s\<^sub>s\<^sub>t S. is_Fun m" proof (induction S) case (Cons x S) thus ?case unfolding pair_def by (cases x) (auto simp add: assms(2) setops\<^sub>s\<^sub>s\<^sub>t_def) qed (simp add: setops\<^sub>s\<^sub>s\<^sub>t_def) have 2: "subterms\<^sub>s\<^sub>e\<^sub>t (pair ` setops\<^sub>s\<^sub>s\<^sub>t S) \<union> \<Union>((set \<circ> fst \<circ> Ana) ` (pair ` setops\<^sub>s\<^sub>s\<^sub>t S)) - pair ` setops\<^sub>s\<^sub>s\<^sub>t S \<subseteq> subterms\<^sub>s\<^sub>e\<^sub>t (trms\<^sub>s\<^sub>s\<^sub>t S)" using 0 setops_subterms_cases by fast show ?thesis using SMP_MP_split[OF assms(1) 1] SMP_mono[OF 2] SMP_subterms_eq[of "trms\<^sub>s\<^sub>s\<^sub>t S"] by blast qed lemma tfr_setops_if_tfr_trms: assumes "Pair \<notin> \<Union>(funs_term ` SMP (trms\<^sub>s\<^sub>s\<^sub>t S))" and "\<forall>p. Ana (pair p) = ([], [])" and "\<forall>s \<in> pair ` setops\<^sub>s\<^sub>s\<^sub>t S. \<forall>t \<in> pair ` setops\<^sub>s\<^sub>s\<^sub>t S. (\<exists>\<delta>. Unifier \<delta> s t) \<longrightarrow> \<Gamma> s = \<Gamma> t" and "\<forall>s \<in> pair ` setops\<^sub>s\<^sub>s\<^sub>t S. \<forall>t \<in> pair ` setops\<^sub>s\<^sub>s\<^sub>t S. (\<exists>\<sigma> \<theta> \<rho>. wt\<^sub>s\<^sub>u\<^sub>b\<^sub>s\<^sub>t \<sigma> \<and> wt\<^sub>s\<^sub>u\<^sub>b\<^sub>s\<^sub>t \<theta> \<and> wf\<^sub>t\<^sub>r\<^sub>m\<^sub>s (subst_range \<sigma>) \<and> wf\<^sub>t\<^sub>r\<^sub>m\<^sub>s (subst_range \<theta>) \<and> Unifier \<rho> (s \<cdot> \<sigma>) (t \<cdot> \<theta>)) \<longrightarrow> (\<exists>\<delta>. Unifier \<delta> s t)" and tfr: "tfr\<^sub>s\<^sub>e\<^sub>t (trms\<^sub>s\<^sub>s\<^sub>t S)" shows "tfr\<^sub>s\<^sub>e\<^sub>t (trms\<^sub>s\<^sub>s\<^sub>t S \<union> pair ` setops\<^sub>s\<^sub>s\<^sub>t S)" proof - have 0: "t \<in> SMP (trms\<^sub>s\<^sub>s\<^sub>t S) - range Var \<or> t \<in> SMP (pair ` setops\<^sub>s\<^sub>s\<^sub>t S) - range Var" when "t \<in> SMP (trms\<^sub>s\<^sub>s\<^sub>t S \<union> pair ` setops\<^sub>s\<^sub>s\<^sub>t S) - range Var" for t using that SMP_union by blast have 1: "s \<in> SMP (trms\<^sub>s\<^sub>s\<^sub>t S) - range Var" when st: "s \<in> SMP (pair ` setops\<^sub>s\<^sub>s\<^sub>t S) - range Var" "t \<in> SMP (trms\<^sub>s\<^sub>s\<^sub>t S) - range Var" "\<exists>\<delta>. Unifier \<delta> s t" for s t proof - have "(\<exists>\<delta>. s \<in> pair ` setops\<^sub>s\<^sub>s\<^sub>t S \<cdot>\<^sub>s\<^sub>e\<^sub>t \<delta>) \<or> s \<in> SMP (trms\<^sub>s\<^sub>s\<^sub>t S) - range Var" using st setops_SMP_cases[of s S] assms(2) by blast moreover { fix \<delta> assume \<delta>: "s \<in> pair ` setops\<^sub>s\<^sub>s\<^sub>t S \<cdot>\<^sub>s\<^sub>e\<^sub>t \<delta>" then obtain s' where s': "s' \<in> pair ` setops\<^sub>s\<^sub>s\<^sub>t S" "s = s' \<cdot> \<delta>" by blast then obtain u u' where u: "s' = Fun Pair [u,u']" using setops\<^sub>s\<^sub>s\<^sub>t_are_pairs[of s'] unfolding pair_def by fast hence *: "s = Fun Pair [u \<cdot> \<delta>, u' \<cdot> \<delta>]" using \<delta> s' by simp obtain f T where fT: "t = Fun f T" using st(2) by (cases t) auto hence "f \<noteq> Pair" using st(2) assms(1) by auto hence False using st(3) * fT s' u by fast } ultimately show ?thesis by meson qed have 2: "\<Gamma> s = \<Gamma> t" when "s \<in> SMP (trms\<^sub>s\<^sub>s\<^sub>t S) - range Var" "t \<in> SMP (trms\<^sub>s\<^sub>s\<^sub>t S) - range Var" "\<exists>\<delta>. Unifier \<delta> s t" for s t using that tfr unfolding tfr\<^sub>s\<^sub>e\<^sub>t_def by blast have 3: "\<Gamma> s = \<Gamma> t" when st: "s \<in> SMP (pair ` setops\<^sub>s\<^sub>s\<^sub>t S) - range Var" "t \<in> SMP (pair ` setops\<^sub>s\<^sub>s\<^sub>t S) - range Var" "\<exists>\<delta>. Unifier \<delta> s t" for s t proof - let ?P = "\<lambda>s \<delta>. wt\<^sub>s\<^sub>u\<^sub>b\<^sub>s\<^sub>t \<delta> \<and> wf\<^sub>t\<^sub>r\<^sub>m\<^sub>s (subst_range \<delta>) \<and> s \<in> pair ` setops\<^sub>s\<^sub>s\<^sub>t S \<cdot>\<^sub>s\<^sub>e\<^sub>t \<delta>" have "(\<exists>\<delta>. ?P s \<delta>) \<or> s \<in> SMP (trms\<^sub>s\<^sub>s\<^sub>t S) - range Var" "(\<exists>\<delta>. ?P t \<delta>) \<or> t \<in> SMP (trms\<^sub>s\<^sub>s\<^sub>t S) - range Var" using setops_SMP_cases[of _ S] assms(2) st(1,2) by auto hence "(\<exists>\<delta> \<delta>'. ?P s \<delta> \<and> ?P t \<delta>') \<or> \<Gamma> s = \<Gamma> t" by (metis 1 2 st) moreover { fix \<delta> \<delta>' assume *: "?P s \<delta>" "?P t \<delta>'" then obtain s' t' where **: "s' \<in> pair ` setops\<^sub>s\<^sub>s\<^sub>t S" "t' \<in> pair ` setops\<^sub>s\<^sub>s\<^sub>t S" "s = s' \<cdot> \<delta>" "t = t' \<cdot> \<delta>'" by blast hence "\<exists>\<theta>. Unifier \<theta> s' t'" using st(3) assms(4) * by blast hence "\<Gamma> s' = \<Gamma> t'" using assms(3) ** by blast hence "\<Gamma> s = \<Gamma> t" using * **(3,4) wt_subst_trm''[of \<delta> s'] wt_subst_trm''[of \<delta>' t'] by argo } ultimately show ?thesis by blast qed show ?thesis using 0 1 2 3 unfolding tfr\<^sub>s\<^sub>e\<^sub>t_def by metis qed subsection \<open>The Typing Result for Stateful Constraints\<close> context begin private lemma tr_wf': assumes "\<forall>(t,t') \<in> set D. (fv t \<union> fv t') \<inter> bvars\<^sub>s\<^sub>s\<^sub>t A = {}" and "\<forall>(t,t') \<in> set D. fv t \<union> fv t' \<subseteq> X" and "wf'\<^sub>s\<^sub>s\<^sub>t X A" "fv\<^sub>s\<^sub>s\<^sub>t A \<inter> bvars\<^sub>s\<^sub>s\<^sub>t A = {}" and "A' \<in> set (tr A D)" shows "wf\<^sub>s\<^sub>t X A'" proof - define P where "P = (\<lambda>(D::('fun,'var) dbstatelist) (A::('fun,'var) stateful_strand). (\<forall>(t,t') \<in> set D. (fv t \<union> fv t') \<inter> bvars\<^sub>s\<^sub>s\<^sub>t A = {}) \<and> fv\<^sub>s\<^sub>s\<^sub>t A \<inter> bvars\<^sub>s\<^sub>s\<^sub>t A = {})" have "P D A" using assms(1,4) by (simp add: P_def) with assms(5,3,2) show ?thesis proof (induction A arbitrary: A' D X rule: wf'\<^sub>s\<^sub>s\<^sub>t.induct) case 1 thus ?case by simp next case (2 X t A A') then obtain A'' where A'': "A' = receive\<langle>t\<rangle>\<^sub>s\<^sub>t#A''" "A'' \<in> set (tr A D)" "fv t \<subseteq> X" by moura have *: "wf'\<^sub>s\<^sub>s\<^sub>t X A" "\<forall>(s,s') \<in> set D. fv s \<union> fv s' \<subseteq> X" "P D A" using 2(1,2,3,4) apply (force, force) using 2(5) unfolding P_def by force show ?case using "2.IH"[OF A''(2) *] A''(1,3) by simp next case (3 X t A A') then obtain A'' where A'': "A' = send\<langle>t\<rangle>\<^sub>s\<^sub>t#A''" "A'' \<in> set (tr A D)" by moura have *: "wf'\<^sub>s\<^sub>s\<^sub>t (X \<union> fv t) A" "\<forall>(s,s') \<in> set D. fv s \<union> fv s' \<subseteq> X \<union> fv t" "P D A" using 3(1,2,3,4) apply (force, force) using 3(5) unfolding P_def by force show ?case using "3.IH"[OF A''(2) *] A''(1) by simp next case (4 X t t' A A') then obtain A'' where A'': "A' = \<langle>assign: t \<doteq> t'\<rangle>\<^sub>s\<^sub>t#A''" "A'' \<in> set (tr A D)" "fv t' \<subseteq> X" by moura have *: "wf'\<^sub>s\<^sub>s\<^sub>t (X \<union> fv t) A" "\<forall>(s,s') \<in> set D. fv s \<union> fv s' \<subseteq> X \<union> fv t" "P D A" using 4(1,2,3,4) apply (force, force) using 4(5) unfolding P_def by force show ?case using "4.IH"[OF A''(2) *] A''(1,3) by simp next case (5 X t t' A A') then obtain A'' where A'': "A' = \<langle>check: t \<doteq> t'\<rangle>\<^sub>s\<^sub>t#A''" "A'' \<in> set (tr A D)" by moura have *: "wf'\<^sub>s\<^sub>s\<^sub>t X A" "P D A" using 5(3) apply force using 5(5) unfolding P_def by force show ?case using "5.IH"[OF A''(2) *(1) 5(4) *(2)] A''(1) by simp next case (6 X t s A A') hence A': "A' \<in> set (tr A (List.insert (t,s) D))" "fv t \<subseteq> X" "fv s \<subseteq> X" by auto have *: "wf'\<^sub>s\<^sub>s\<^sub>t X A" "\<forall>(s,s') \<in> set (List.insert (t,s) D). fv s \<union> fv s' \<subseteq> X" using 6 by auto have **: "P (List.insert (t,s) D) A" using 6(5) unfolding P_def by force show ?case using "6.IH"[OF A'(1) * **] A'(2,3) by simp next case (7 X t s A A') let ?constr = "\<lambda>Di. (map (\<lambda>d. \<langle>check: (pair (t,s)) \<doteq> (pair d)\<rangle>\<^sub>s\<^sub>t) Di)@ (map (\<lambda>d. \<forall>[]\<langle>\<or>\<noteq>: [(pair (t,s), pair d)]\<rangle>\<^sub>s\<^sub>t) [d\<leftarrow>D. d \<notin> set Di])" from 7 obtain Di A'' where A'': "A' = ?constr Di@A''" "A'' \<in> set (tr A [d\<leftarrow>D. d \<notin> set Di])" "Di \<in> set (subseqs D)" by moura have *: "wf'\<^sub>s\<^sub>s\<^sub>t X A" "\<forall>(t',s') \<in> set [d\<leftarrow>D. d \<notin> set Di]. fv t' \<union> fv s' \<subseteq> X" using 7 by auto have **: "P [d\<leftarrow>D. d \<notin> set Di] A" using 7 unfolding P_def by force have ***: "\<forall>(t, t') \<in> set D. fv t \<union> fv t' \<subseteq> X" using 7 by auto show ?case using "7.IH"[OF A''(2) * **] A''(1) wf_fun_pair_eqs_ineqs_map[OF _ A''(3) ***] by simp next case (8 X t s A A') then obtain d A'' where A'': "A' = \<langle>assign: (pair (t,s)) \<doteq> (pair d)\<rangle>\<^sub>s\<^sub>t#A''" "A'' \<in> set (tr A D)" "d \<in> set D" by moura have *: "wf'\<^sub>s\<^sub>s\<^sub>t (X \<union> fv t \<union> fv s) A" "\<forall>(t',s')\<in>set D. fv t' \<union> fv s' \<subseteq> X \<union> fv t \<union> fv s" "P D A" using 8(1,2,3,4) apply (force, force) using 8(5) unfolding P_def by force have **: "fv (pair d) \<subseteq> X" using A''(3) "8.prems"(3) unfolding pair_def by fastforce have ***: "fv (pair (t,s)) = fv s \<union> fv t" unfolding pair_def by auto show ?case using "8.IH"[OF A''(2) *] A''(1) ** *** unfolding pair_def by (simp add: Un_assoc) next case (9 X t s A A') then obtain d A'' where A'': "A' = \<langle>check: (pair (t,s)) \<doteq> (pair d)\<rangle>\<^sub>s\<^sub>t#A''" "A'' \<in> set (tr A D)" "d \<in> set D" by moura have *: "wf'\<^sub>s\<^sub>s\<^sub>t X A""P D A" using 9(3) apply force using 9(5) unfolding P_def by force have **: "fv (pair d) \<subseteq> X" using A''(3) "9.prems"(3) unfolding pair_def by fastforce have ***: "fv (pair (t,s)) = fv s \<union> fv t" unfolding pair_def by auto show ?case using "9.IH"[OF A''(2) *(1) 9(4) *(2)] A''(1) ** *** by (simp add: Un_assoc) next case (10 X Y F F' A A') from 10 obtain A'' where A'': "A' = (map (\<lambda>G. \<forall>Y\<langle>\<or>\<noteq>: (F@G)\<rangle>\<^sub>s\<^sub>t) (tr\<^sub>p\<^sub>a\<^sub>i\<^sub>r\<^sub>s F' D))@A''" "A'' \<in> set (tr A D)" by moura have *: "wf'\<^sub>s\<^sub>s\<^sub>t X A" "\<forall>(t',s') \<in> set D. fv t' \<union> fv s' \<subseteq> X" using 10 by auto have "bvars\<^sub>s\<^sub>s\<^sub>t A \<subseteq> bvars\<^sub>s\<^sub>s\<^sub>t (\<forall>Y\<langle>\<or>\<noteq>: F \<or>\<notin>: F'\<rangle>#A)" "fv\<^sub>s\<^sub>s\<^sub>t A \<subseteq> fv\<^sub>s\<^sub>s\<^sub>t (\<forall>Y\<langle>\<or>\<noteq>: F \<or>\<notin>: F'\<rangle>#A)" by auto hence **: "P D A" using 10 unfolding P_def by blast show ?case using "10.IH"[OF A''(2) * **] A''(1) wf_fun_pair_negchecks_map by simp qed qed private lemma tr_wf\<^sub>t\<^sub>r\<^sub>m\<^sub>s: assumes "A' \<in> set (tr A [])" "wf\<^sub>t\<^sub>r\<^sub>m\<^sub>s (trms\<^sub>s\<^sub>s\<^sub>t A)" shows "wf\<^sub>t\<^sub>r\<^sub>m\<^sub>s (trms\<^sub>s\<^sub>t A')" using tr_trms_subset[OF assms(1)] setops\<^sub>s\<^sub>s\<^sub>t_wf\<^sub>t\<^sub>r\<^sub>m\<^sub>s(2)[OF assms(2)] by auto lemma tr_wf: assumes "A' \<in> set (tr A [])" and "wf\<^sub>s\<^sub>s\<^sub>t A" and "wf\<^sub>t\<^sub>r\<^sub>m\<^sub>s (trms\<^sub>s\<^sub>s\<^sub>t A)" shows "wf\<^sub>s\<^sub>t {} A'" and "wf\<^sub>t\<^sub>r\<^sub>m\<^sub>s (trms\<^sub>s\<^sub>t A')" and "fv\<^sub>s\<^sub>t A' \<inter> bvars\<^sub>s\<^sub>t A' = {}" using tr_wf'[OF _ _ _ _ assms(1)] tr_wf\<^sub>t\<^sub>r\<^sub>m\<^sub>s[OF assms(1,3)] tr_vars_disj[OF assms(1)] assms(2) by fastforce+ private lemma tr_tfr\<^sub>s\<^sub>s\<^sub>t\<^sub>p: assumes "A' \<in> set (tr A D)" "list_all tfr\<^sub>s\<^sub>s\<^sub>t\<^sub>p A" and "fv\<^sub>s\<^sub>s\<^sub>t A \<inter> bvars\<^sub>s\<^sub>s\<^sub>t A = {}" (is "?P0 A D") and "\<forall>(t,s) \<in> set D. (fv t \<union> fv s) \<inter> bvars\<^sub>s\<^sub>s\<^sub>t A = {}" (is "?P1 A D") and "\<forall>t \<in> pair ` setops\<^sub>s\<^sub>s\<^sub>t A \<union> pair ` set D. \<forall>t' \<in> pair ` setops\<^sub>s\<^sub>s\<^sub>t A \<union> pair ` set D. (\<exists>\<delta>. Unifier \<delta> t t') \<longrightarrow> \<Gamma> t = \<Gamma> t'" (is "?P3 A D") shows "list_all tfr\<^sub>s\<^sub>t\<^sub>p A'" proof - have sublmm: "list_all tfr\<^sub>s\<^sub>s\<^sub>t\<^sub>p A" "?P0 A D" "?P1 A D" "?P3 A D" when p: "list_all tfr\<^sub>s\<^sub>s\<^sub>t\<^sub>p (a#A)" "?P0 (a#A) D" "?P1 (a#A) D" "?P3 (a#A) D" for a A D using p(1) apply (simp add: tfr\<^sub>s\<^sub>s\<^sub>t_def) using p(2) fv\<^sub>s\<^sub>s\<^sub>t_cons_subset bvars\<^sub>s\<^sub>s\<^sub>t_cons_subset apply fast using p(3) bvars\<^sub>s\<^sub>s\<^sub>t_cons_subset apply fast using p(4) setops\<^sub>s\<^sub>s\<^sub>t_cons_subset by fast show ?thesis using assms proof (induction A D arbitrary: A' rule: tr.induct) case 1 thus ?case by simp next case (2 t A D) note prems = "2.prems" note IH = "2.IH" from prems(1) obtain A'' where A'': "A' = send\<langle>t\<rangle>\<^sub>s\<^sub>t#A''" "A'' \<in> set (tr A D)" by moura have "list_all tfr\<^sub>s\<^sub>t\<^sub>p A''" using IH[OF A''(2)] prems(5) sublmm[OF prems(2,3,4,5)] by meson thus ?case using A''(1) by simp next case (3 t A D) note prems = "3.prems" note IH = "3.IH" from prems(1) obtain A'' where A'': "A' = receive\<langle>t\<rangle>\<^sub>s\<^sub>t#A''" "A'' \<in> set (tr A D)" by moura have "list_all tfr\<^sub>s\<^sub>t\<^sub>p A''" using IH[OF A''(2)] prems(5) sublmm[OF prems(2,3,4,5)] by meson thus ?case using A''(1) by simp next case (4 ac t t' A D) note prems = "4.prems" note IH = "4.IH" from prems(1) obtain A'' where A'': "A' = \<langle>ac: t \<doteq> t'\<rangle>\<^sub>s\<^sub>t#A''" "A'' \<in> set (tr A D)" by moura have "list_all tfr\<^sub>s\<^sub>t\<^sub>p A''" using IH[OF A''(2)] prems(5) sublmm[OF prems(2,3,4,5)] by meson moreover have "(\<exists>\<delta>. Unifier \<delta> t t') \<Longrightarrow> \<Gamma> t = \<Gamma> t'" using prems(2) by (simp add: tfr\<^sub>s\<^sub>s\<^sub>t_def) ultimately show ?case using A''(1) by auto next case (5 t s A D) note prems = "5.prems" note IH = "5.IH" from prems(1) have A': "A' \<in> set (tr A (List.insert (t,s) D))" by simp have 1: "list_all tfr\<^sub>s\<^sub>s\<^sub>t\<^sub>p A" using sublmm[OF prems(2,3,4,5)] by simp have "pair ` setops\<^sub>s\<^sub>s\<^sub>t (Insert t s#A) \<union> pair`set D = pair ` setops\<^sub>s\<^sub>s\<^sub>t A \<union> pair`set (List.insert (t,s) D)" by (simp add: setops\<^sub>s\<^sub>s\<^sub>t_def) hence 3: "?P3 A (List.insert (t,s) D)" using prems(5) by metis moreover have "?P1 A (List.insert (t, s) D)" using prems(3,4) bvars\<^sub>s\<^sub>s\<^sub>t_cons_subset[of A] by auto ultimately have "list_all tfr\<^sub>s\<^sub>t\<^sub>p A'" using IH[OF A' sublmm(1,2)[OF prems(2,3,4,5)] _ 3] by metis thus ?case using A'(1) by auto next case (6 t s A D) note prems = "6.prems" note IH = "6.IH" define constr where constr: "constr \<equiv> (\<lambda>Di. (map (\<lambda>d. \<langle>check: (pair (t,s)) \<doteq> (pair d)\<rangle>\<^sub>s\<^sub>t) Di)@ (map (\<lambda>d. \<forall>[]\<langle>\<or>\<noteq>: [(pair (t,s), pair d)]\<rangle>\<^sub>s\<^sub>t) [d\<leftarrow>D. d \<notin> set Di]))" from prems(1) obtain Di A'' where A'': "A' = constr Di@A''" "A'' \<in> set (tr A [d\<leftarrow>D. d \<notin> set Di])" "Di \<in> set (subseqs D)" unfolding constr by auto define Q1 where "Q1 \<equiv> (\<lambda>(F::(('fun,'var) term \<times> ('fun,'var) term) list) X. \<forall>x \<in> (fv\<^sub>p\<^sub>a\<^sub>i\<^sub>r\<^sub>s F) - set X. \<exists>a. \<Gamma> (Var x) = TAtom a)" define Q2 where "Q2 \<equiv> (\<lambda>(F::(('fun,'var) term \<times> ('fun,'var) term) list) X. \<forall>f T. Fun f T \<in> subterms\<^sub>s\<^sub>e\<^sub>t (trms\<^sub>p\<^sub>a\<^sub>i\<^sub>r\<^sub>s F) \<longrightarrow> T = [] \<or> (\<exists>s \<in> set T. s \<notin> Var ` set X))" have "set [d\<leftarrow>D. d \<notin> set Di] \<subseteq> set D" "pair ` setops\<^sub>s\<^sub>s\<^sub>t A \<union> pair ` set [d\<leftarrow>D. d \<notin> set Di] \<subseteq> pair ` setops\<^sub>s\<^sub>s\<^sub>t (Delete t s#A) \<union> pair ` set D" by (auto simp add: setops\<^sub>s\<^sub>s\<^sub>t_def) hence *: "?P3 A [d\<leftarrow>D. d \<notin> set Di]" using prems(5) by blast have **: "?P1 A [d\<leftarrow>D. d \<notin> set Di]" using prems(4,5) by auto have 1: "list_all tfr\<^sub>s\<^sub>t\<^sub>p A''" using IH[OF A''(3,2) sublmm(1,2)[OF prems(2,3,4,5)] ** *] by metis have 2: "\<langle>ac: u \<doteq> u'\<rangle>\<^sub>s\<^sub>t \<in> set A'' \<or> (\<exists>d \<in> set Di. u = pair (t,s) \<and> u' = pair d)" when "\<langle>ac: u \<doteq> u'\<rangle>\<^sub>s\<^sub>t \<in> set A'" for ac u u' using that A''(1) unfolding constr by force have 3: "Inequality X U \<in> set A' \<Longrightarrow> Inequality X U \<in> set A'' \<or> (\<exists>d \<in> set [d\<leftarrow>D. d \<notin> set Di]. U = [(pair (t,s), pair d)] \<and> Q2 [(pair (t,s), pair d)] X)" for X U using A''(1) unfolding Q2_def constr by force have 4: "\<forall>d\<in>set D. (\<exists>\<delta>. Unifier \<delta> (pair (t,s)) (pair d)) \<longrightarrow> \<Gamma> (pair (t,s)) = \<Gamma> (pair d)" using prems(5) by (simp add: setops\<^sub>s\<^sub>s\<^sub>t_def) { fix ac u u' assume a: "\<langle>ac: u \<doteq> u'\<rangle>\<^sub>s\<^sub>t \<in> set A'" "\<exists>\<delta>. Unifier \<delta> u u'" hence "\<langle>ac: u \<doteq> u'\<rangle>\<^sub>s\<^sub>t \<in> set A'' \<or> (\<exists>d \<in> set Di. u = pair (t,s) \<and> u' = pair d)" using 2 by metis hence "\<Gamma> u = \<Gamma> u'" using 1(1) 4 subseqs_set_subset[OF A''(3)] a(2) tfr\<^sub>s\<^sub>t\<^sub>p_list_all_alt_def[of A''] by blast } moreover { fix u U assume "\<forall>U\<langle>\<or>\<noteq>: u\<rangle>\<^sub>s\<^sub>t \<in> set A'" hence "\<forall>U\<langle>\<or>\<noteq>: u\<rangle>\<^sub>s\<^sub>t \<in> set A'' \<or> (\<exists>d \<in> set [d\<leftarrow>D. d \<notin> set Di]. u = [(pair (t,s), pair d)] \<and> Q2 u U)" using 3 by metis hence "Q1 u U \<or> Q2 u U" using 1 4 subseqs_set_subset[OF A''(3)] tfr\<^sub>s\<^sub>t\<^sub>p_list_all_alt_def[of A''] unfolding Q1_def Q2_def by blast } ultimately show ?case using tfr\<^sub>s\<^sub>t\<^sub>p_list_all_alt_def[of A'] unfolding Q1_def Q2_def by blast next case (7 ac t s A D) note prems = "7.prems" note IH = "7.IH" from prems(1) obtain d A'' where A'': "A' = \<langle>ac: (pair (t,s)) \<doteq> (pair d)\<rangle>\<^sub>s\<^sub>t#A''" "A'' \<in> set (tr A D)" "d \<in> set D" by moura have "list_all tfr\<^sub>s\<^sub>t\<^sub>p A''" using IH[OF A''(2) sublmm(1,2,3)[OF prems(2,3,4,5)] sublmm(4)[OF prems(2,3,4,5)]] by metis moreover have "(\<exists>\<delta>. Unifier \<delta> (pair (t,s)) (pair d)) \<Longrightarrow> \<Gamma> (pair (t,s)) = \<Gamma> (pair d)" using prems(2,5) A''(3) unfolding tfr\<^sub>s\<^sub>s\<^sub>t_def by (simp add: setops\<^sub>s\<^sub>s\<^sub>t_def) ultimately show ?case using A''(1) by fastforce next case (8 X F F' A D) note prems = "8.prems" note IH = "8.IH" define constr where "constr = (map (\<lambda>G. \<forall>X\<langle>\<or>\<noteq>: (F@G)\<rangle>\<^sub>s\<^sub>t) (tr\<^sub>p\<^sub>a\<^sub>i\<^sub>r\<^sub>s F' D))" define Q1 where "Q1 \<equiv> (\<lambda>(F::(('fun,'var) term \<times> ('fun,'var) term) list) X. \<forall>x \<in> (fv\<^sub>p\<^sub>a\<^sub>i\<^sub>r\<^sub>s F) - set X. \<exists>a. \<Gamma> (Var x) = TAtom a)" define Q2 where "Q2 \<equiv> (\<lambda>(M::('fun,'var) terms) X. \<forall>f T. Fun f T \<in> subterms\<^sub>s\<^sub>e\<^sub>t M \<longrightarrow> T = [] \<or> (\<exists>s \<in> set T. s \<notin> Var ` set X))" have Q2_subset: "Q2 M' X" when "M' \<subseteq> M" "Q2 M X" for X M M' using that unfolding Q2_def by auto have Q2_supset: "Q2 (M \<union> M') X" when "Q2 M X" "Q2 M' X" for X M M' using that unfolding Q2_def by auto from prems(1) obtain A'' where A'': "A' = constr@A''" "A'' \<in> set (tr A D)" using constr_def by moura have 0: "F' = [] \<Longrightarrow> constr = [\<forall>X\<langle>\<or>\<noteq>: F\<rangle>\<^sub>s\<^sub>t]" unfolding constr_def by simp have 1: "list_all tfr\<^sub>s\<^sub>t\<^sub>p A''" using IH[OF A''(2) sublmm(1,2,3)[OF prems(2,3,4,5)] sublmm(4)[OF prems(2,3,4,5)]] by metis have 2: "(F' = [] \<and> Q1 F X) \<or> Q2 (trms\<^sub>p\<^sub>a\<^sub>i\<^sub>r\<^sub>s F \<union> pair ` set F') X" using prems(2) unfolding Q1_def Q2_def by simp have 3: "list_all tfr\<^sub>s\<^sub>t\<^sub>p constr" when "F' = []" "Q1 F X" using that 0 2 tfr\<^sub>s\<^sub>t\<^sub>p_list_all_alt_def[of constr] unfolding Q1_def by auto { fix c assume "c \<in> set constr" hence "\<exists>G \<in> set (tr\<^sub>p\<^sub>a\<^sub>i\<^sub>r\<^sub>s F' D). c = \<forall>X\<langle>\<or>\<noteq>: (F@G)\<rangle>\<^sub>s\<^sub>t" unfolding constr_def by force } moreover { fix G assume G: "G \<in> set (tr\<^sub>p\<^sub>a\<^sub>i\<^sub>r\<^sub>s F' D)" and c: "\<forall>X\<langle>\<or>\<noteq>: (F@G)\<rangle>\<^sub>s\<^sub>t \<in> set constr" and e: "Q2 (trms\<^sub>p\<^sub>a\<^sub>i\<^sub>r\<^sub>s F \<union> pair ` set F') X" have d_Q2: "Q2 (pair ` set D) X" unfolding Q2_def proof (intro allI impI) fix f T assume "Fun f T \<in> subterms\<^sub>s\<^sub>e\<^sub>t (pair ` set D)" then obtain d where d: "d \<in> set D" "Fun f T \<in> subterms (pair d)" by auto hence "fv (pair d) \<inter> set X = {}" using prems(4) unfolding pair_def by force thus "T = [] \<or> (\<exists>s \<in> set T. s \<notin> Var ` set X)" by (metis fv_disj_Fun_subterm_param_cases d(2)) qed have "trms\<^sub>p\<^sub>a\<^sub>i\<^sub>r\<^sub>s (F@G) \<subseteq> trms\<^sub>p\<^sub>a\<^sub>i\<^sub>r\<^sub>s F \<union> pair ` set F' \<union> pair ` set D" using tr\<^sub>p\<^sub>a\<^sub>i\<^sub>r\<^sub>s_trms_subset[OF G] by auto hence "Q2 (trms\<^sub>p\<^sub>a\<^sub>i\<^sub>r\<^sub>s (F@G)) X" using Q2_subset[OF _ Q2_supset[OF e d_Q2]] by metis hence "tfr\<^sub>s\<^sub>t\<^sub>p (\<forall>X\<langle>\<or>\<noteq>: (F@G)\<rangle>\<^sub>s\<^sub>t)" by (metis Q2_def tfr\<^sub>s\<^sub>t\<^sub>p.simps(2)) } ultimately have 4: "list_all tfr\<^sub>s\<^sub>t\<^sub>p constr" when "Q2 (trms\<^sub>p\<^sub>a\<^sub>i\<^sub>r\<^sub>s F \<union> pair ` set F') X" using that Ball_set by blast have 5: "list_all tfr\<^sub>s\<^sub>t\<^sub>p constr" using 2 3 4 by metis show ?case using 1 5 A''(1) by simp qed qed lemma tr_tfr: assumes "A' \<in> set (tr A [])" and "tfr\<^sub>s\<^sub>s\<^sub>t A" and "fv\<^sub>s\<^sub>s\<^sub>t A \<inter> bvars\<^sub>s\<^sub>s\<^sub>t A = {}" shows "tfr\<^sub>s\<^sub>t A'" proof - have *: "trms\<^sub>s\<^sub>t A' \<subseteq> trms\<^sub>s\<^sub>s\<^sub>t A \<union> pair ` setops\<^sub>s\<^sub>s\<^sub>t A" using tr_trms_subset[OF assms(1)] by simp hence "SMP (trms\<^sub>s\<^sub>t A') \<subseteq> SMP (trms\<^sub>s\<^sub>s\<^sub>t A \<union> pair ` setops\<^sub>s\<^sub>s\<^sub>t A)" using SMP_mono by simp moreover have "tfr\<^sub>s\<^sub>e\<^sub>t (trms\<^sub>s\<^sub>s\<^sub>t A \<union> pair ` setops\<^sub>s\<^sub>s\<^sub>t A)" using assms(2) unfolding tfr\<^sub>s\<^sub>s\<^sub>t_def by fast ultimately have 1: "tfr\<^sub>s\<^sub>e\<^sub>t (trms\<^sub>s\<^sub>t A')" by (metis tfr_subset(2)[OF _ *]) have **: "list_all tfr\<^sub>s\<^sub>s\<^sub>t\<^sub>p A" using assms(2) unfolding tfr\<^sub>s\<^sub>s\<^sub>t_def by fast have "pair ` setops\<^sub>s\<^sub>s\<^sub>t A \<subseteq> SMP (trms\<^sub>s\<^sub>s\<^sub>t A \<union> pair ` setops\<^sub>s\<^sub>s\<^sub>t A) - Var`\<V>" using setops\<^sub>s\<^sub>s\<^sub>t_are_pairs unfolding pair_def by auto hence ***: "\<forall>t \<in> pair`setops\<^sub>s\<^sub>s\<^sub>t A. \<forall>t' \<in> pair`setops\<^sub>s\<^sub>s\<^sub>t A. (\<exists>\<delta>. Unifier \<delta> t t') \<longrightarrow> \<Gamma> t = \<Gamma> t'" using assms(2) unfolding tfr\<^sub>s\<^sub>s\<^sub>t_def tfr\<^sub>s\<^sub>e\<^sub>t_def by blast have 2: "list_all tfr\<^sub>s\<^sub>t\<^sub>p A'" using tr_tfr\<^sub>s\<^sub>s\<^sub>t\<^sub>p[OF assms(1) ** assms(3)] *** unfolding pair_def by fastforce show ?thesis by (metis 1 2 tfr\<^sub>s\<^sub>t_def) qed private lemma fun_pair_ineqs: assumes "d \<cdot>\<^sub>p \<delta> \<cdot>\<^sub>p \<theta> \<noteq> d' \<cdot>\<^sub>p \<I>" shows "pair d \<cdot> \<delta> \<cdot> \<theta> \<noteq> pair d' \<cdot> \<I>" proof - have "d \<cdot>\<^sub>p (\<delta> \<circ>\<^sub>s \<theta>) \<noteq> d' \<cdot>\<^sub>p \<I>" using assms subst_pair_compose by metis hence "pair d \<cdot> (\<delta> \<circ>\<^sub>s \<theta>) \<noteq> pair d' \<cdot> \<I>" using fun_pair_eq_subst by metis thus ?thesis by simp qed private lemma tr_Delete_constr_iff_aux1: assumes "\<forall>d \<in> set Di. (t,s) \<cdot>\<^sub>p \<I> = d \<cdot>\<^sub>p \<I>" and "\<forall>d \<in> set D - set Di. (t,s) \<cdot>\<^sub>p \<I> \<noteq> d \<cdot>\<^sub>p \<I>" shows "\<lbrakk>M; (map (\<lambda>d. \<langle>check: (pair (t,s)) \<doteq> (pair d)\<rangle>\<^sub>s\<^sub>t) Di)@ (map (\<lambda>d. \<forall>[]\<langle>\<or>\<noteq>: [(pair (t,s), pair d)]\<rangle>\<^sub>s\<^sub>t) [d\<leftarrow>D. d \<notin> set Di])\<rbrakk>\<^sub>d \<I>" proof - from assms(2) have "\<lbrakk>M; map (\<lambda>d. \<forall>[]\<langle>\<or>\<noteq>: [(pair (t,s), pair d)]\<rangle>\<^sub>s\<^sub>t) [d\<leftarrow>D. d \<notin> set Di]\<rbrakk>\<^sub>d \<I>" proof (induction D) case (Cons d D) hence IH: "\<lbrakk>M; map (\<lambda>d. \<forall>[]\<langle>\<or>\<noteq>: [(pair (t,s), pair d)]\<rangle>\<^sub>s\<^sub>t) [d\<leftarrow>D . d \<notin> set Di]\<rbrakk>\<^sub>d \<I>" by auto thus ?case proof (cases "d \<in> set Di") case False hence "(t,s) \<cdot>\<^sub>p \<I> \<noteq> d \<cdot>\<^sub>p \<I>" using Cons by simp hence "pair (t,s) \<cdot> \<I> \<noteq> pair d \<cdot> \<I>" using fun_pair_eq_subst by metis moreover have "\<And>t (\<delta>::('fun,'var) subst). subst_domain \<delta> = {} \<Longrightarrow> t \<cdot> \<delta> = t" by auto ultimately have "\<forall>\<delta>. subst_domain \<delta> = {} \<longrightarrow> pair (t,s) \<cdot> \<delta> \<cdot> \<I> \<noteq> pair d \<cdot> \<delta> \<cdot> \<I>" by metis thus ?thesis using IH by (simp add: ineq_model_def) qed simp qed simp moreover { fix B assume "\<lbrakk>M; B\<rbrakk>\<^sub>d \<I>" with assms(1) have "\<lbrakk>M; (map (\<lambda>d. \<langle>check: (pair (t,s)) \<doteq> (pair d)\<rangle>\<^sub>s\<^sub>t) Di)@B\<rbrakk>\<^sub>d \<I>" unfolding pair_def by (induction Di) auto } ultimately show ?thesis by metis qed private lemma tr_Delete_constr_iff_aux2: assumes "ground M" and "\<lbrakk>M; (map (\<lambda>d. \<langle>check: (pair (t,s)) \<doteq> (pair d)\<rangle>\<^sub>s\<^sub>t) Di)@ (map (\<lambda>d. \<forall>[]\<langle>\<or>\<noteq>: [(pair (t,s), pair d)]\<rangle>\<^sub>s\<^sub>t) [d\<leftarrow>D. d \<notin> set Di])\<rbrakk>\<^sub>d \<I>" shows "(\<forall>d \<in> set Di. (t,s) \<cdot>\<^sub>p \<I> = d \<cdot>\<^sub>p \<I>) \<and> (\<forall>d \<in> set D - set Di. (t,s) \<cdot>\<^sub>p \<I> \<noteq> d \<cdot>\<^sub>p \<I>)" proof - let ?c1 = "map (\<lambda>d. \<langle>check: (pair (t,s)) \<doteq> (pair d)\<rangle>\<^sub>s\<^sub>t) Di" let ?c2 = "map (\<lambda>d. \<forall>[]\<langle>\<or>\<noteq>: [(pair (t,s), pair d)]\<rangle>\<^sub>s\<^sub>t) [d\<leftarrow>D. d \<notin> set Di]" have "M \<cdot>\<^sub>s\<^sub>e\<^sub>t \<I> = M" using assms(1) subst_all_ground_ident by metis moreover have "ik\<^sub>s\<^sub>t ?c1 = {}" by auto ultimately have *: "\<lbrakk>M; map (\<lambda>d. \<langle>check: (pair (t,s)) \<doteq> (pair d)\<rangle>\<^sub>s\<^sub>t) Di\<rbrakk>\<^sub>d \<I>" "\<lbrakk>M; map (\<lambda>d. \<forall>[]\<langle>\<or>\<noteq>: [(pair (t,s), pair d)]\<rangle>\<^sub>s\<^sub>t) [d\<leftarrow>D. d \<notin> set Di]\<rbrakk>\<^sub>d \<I>" using strand_sem_split(3,4)[of M ?c1 ?c2 \<I>] assms(2) by auto from *(1) have 1: "\<forall>d \<in> set Di. (t,s) \<cdot>\<^sub>p \<I> = d \<cdot>\<^sub>p \<I>" unfolding pair_def by (induct Di) auto from *(2) have 2: "\<forall>d \<in> set D - set Di. (t,s) \<cdot>\<^sub>p \<I> \<noteq> d \<cdot>\<^sub>p \<I>" proof (induction D arbitrary: Di) case (Cons d D) thus ?case proof (cases "d \<in> set Di") case False hence IH: "\<forall>d \<in> set D - set Di. (t,s) \<cdot>\<^sub>p \<I> \<noteq> d \<cdot>\<^sub>p \<I>" using Cons by force have "\<And>t (\<delta>::('fun,'var) subst). subst_domain \<delta> = {} \<and> ground (subst_range \<delta>) \<longleftrightarrow> \<delta> = Var" by auto moreover have "ineq_model \<I> [] [((pair (t,s)), (pair d))]" using False Cons.prems by simp ultimately have "pair (t,s) \<cdot> \<I> \<noteq> pair d \<cdot> \<I>" by (simp add: ineq_model_def) thus ?thesis using IH unfolding pair_def by force qed simp qed simp show ?thesis by (metis 1 2) qed private lemma tr_Delete_constr_iff: fixes \<I>::"('fun,'var) subst" assumes "ground M" shows "set Di \<cdot>\<^sub>p\<^sub>s\<^sub>e\<^sub>t \<I> \<subseteq> {(t,s) \<cdot>\<^sub>p \<I>} \<and> (t,s) \<cdot>\<^sub>p \<I> \<notin> (set D - set Di) \<cdot>\<^sub>p\<^sub>s\<^sub>e\<^sub>t \<I> \<longleftrightarrow> \<lbrakk>M; (map (\<lambda>d. \<langle>check: (pair (t,s)) \<doteq> (pair d)\<rangle>\<^sub>s\<^sub>t) Di)@ (map (\<lambda>d. \<forall>[]\<langle>\<or>\<noteq>: [(pair (t,s), pair d)]\<rangle>\<^sub>s\<^sub>t) [d\<leftarrow>D. d \<notin> set Di])\<rbrakk>\<^sub>d \<I>" proof - let ?constr = "(map (\<lambda>d. \<langle>check: (pair (t,s)) \<doteq> (pair d)\<rangle>\<^sub>s\<^sub>t) Di)@ (map (\<lambda>d. \<forall>[]\<langle>\<or>\<noteq>: [(pair (t,s), pair d)]\<rangle>\<^sub>s\<^sub>t) [d\<leftarrow>D. d \<notin> set Di])" { assume "set Di \<cdot>\<^sub>p\<^sub>s\<^sub>e\<^sub>t \<I> \<subseteq> {(t,s) \<cdot>\<^sub>p \<I>}" "(t,s) \<cdot>\<^sub>p \<I> \<notin> (set D - set Di) \<cdot>\<^sub>p\<^sub>s\<^sub>e\<^sub>t \<I>" hence "\<forall>d \<in> set Di. (t,s) \<cdot>\<^sub>p \<I> = d \<cdot>\<^sub>p \<I>" "\<forall>d \<in> set D - set Di. (t,s) \<cdot>\<^sub>p \<I> \<noteq> d \<cdot>\<^sub>p \<I>" by auto hence "\<lbrakk>M; ?constr\<rbrakk>\<^sub>d \<I>" using tr_Delete_constr_iff_aux1 by simp } moreover { assume "\<lbrakk>M; ?constr\<rbrakk>\<^sub>d \<I>" hence "\<forall>d \<in> set Di. (t,s) \<cdot>\<^sub>p \<I> = d \<cdot>\<^sub>p \<I>" "\<forall>d \<in> set D - set Di. (t,s) \<cdot>\<^sub>p \<I> \<noteq> d \<cdot>\<^sub>p \<I>" using assms tr_Delete_constr_iff_aux2 by auto hence "set Di \<cdot>\<^sub>p\<^sub>s\<^sub>e\<^sub>t \<I> \<subseteq> {(t,s) \<cdot>\<^sub>p \<I>} \<and> (t,s) \<cdot>\<^sub>p \<I> \<notin> (set D - set Di) \<cdot>\<^sub>p\<^sub>s\<^sub>e\<^sub>t \<I>" by force } ultimately show ?thesis by metis qed private lemma tr_NotInSet_constr_iff: fixes \<I>::"('fun,'var) subst" assumes "\<forall>(t,t') \<in> set D. (fv t \<union> fv t') \<inter> set X = {}" shows "(\<forall>\<delta>. subst_domain \<delta> = set X \<and> ground (subst_range \<delta>) \<longrightarrow> (t,s) \<cdot>\<^sub>p \<delta> \<cdot>\<^sub>p \<I> \<notin> set D \<cdot>\<^sub>p\<^sub>s\<^sub>e\<^sub>t \<I>) \<longleftrightarrow> \<lbrakk>M; map (\<lambda>d. \<forall>X\<langle>\<or>\<noteq>: [(pair (t,s), pair d)]\<rangle>\<^sub>s\<^sub>t) D\<rbrakk>\<^sub>d \<I>" proof - { assume "\<forall>\<delta>. subst_domain \<delta> = set X \<and> ground (subst_range \<delta>) \<longrightarrow> (t,s) \<cdot>\<^sub>p \<delta> \<cdot>\<^sub>p \<I> \<notin> set D \<cdot>\<^sub>p\<^sub>s\<^sub>e\<^sub>t \<I>" with assms have "\<lbrakk>M; map (\<lambda>d. \<forall>X\<langle>\<or>\<noteq>: [(pair (t,s), pair d)]\<rangle>\<^sub>s\<^sub>t) D\<rbrakk>\<^sub>d \<I>" proof (induction D) case (Cons d D) obtain t' s' where d: "d = (t',s')" by moura have "\<lbrakk>M; map (\<lambda>d. \<forall>X\<langle>\<or>\<noteq>: [(pair (t,s), pair d)]\<rangle>\<^sub>s\<^sub>t) D\<rbrakk>\<^sub>d \<I>" "map (\<lambda>d. \<forall>X\<langle>\<or>\<noteq>: [(pair (t,s), pair d)]\<rangle>\<^sub>s\<^sub>t) (d#D) = \<forall>X\<langle>\<or>\<noteq>: [(pair (t,s), pair d)]\<rangle>\<^sub>s\<^sub>t#map (\<lambda>d. \<forall>X\<langle>\<or>\<noteq>: [(pair (t,s), pair d)]\<rangle>\<^sub>s\<^sub>t) D" using Cons by auto moreover have "\<forall>\<delta>. subst_domain \<delta> = set X \<and> ground (subst_range \<delta>) \<longrightarrow> pair (t, s) \<cdot> \<delta> \<cdot> \<I> \<noteq> pair d \<cdot> \<I>" using fun_pair_ineqs[of \<I> _ "(t,s)" \<I> d] Cons.prems(2) by auto moreover have "(fv t' \<union> fv s') \<inter> set X = {}" using Cons.prems(1) d by auto hence "\<forall>\<delta>. subst_domain \<delta> = set X \<longrightarrow> pair d \<cdot> \<delta> = pair d" using d unfolding pair_def by auto ultimately show ?case by (simp add: ineq_model_def) qed simp } moreover { fix \<delta>::"('fun,'var) subst" assume "\<lbrakk>M; map (\<lambda>d. \<forall>X\<langle>\<or>\<noteq>: [(pair (t,s), pair d)]\<rangle>\<^sub>s\<^sub>t) D\<rbrakk>\<^sub>d \<I>" and \<delta>: "subst_domain \<delta> = set X" "ground (subst_range \<delta>)" with assms have "(t,s) \<cdot>\<^sub>p \<delta> \<cdot>\<^sub>p \<I> \<notin> set D \<cdot>\<^sub>p\<^sub>s\<^sub>e\<^sub>t \<I>" proof (induction D) case (Cons d D) obtain t' s' where d: "d = (t',s')" by moura have "(t,s) \<cdot>\<^sub>p \<delta> \<cdot>\<^sub>p \<I> \<notin> set D \<cdot>\<^sub>p\<^sub>s\<^sub>e\<^sub>t \<I>" "pair (t,s) \<cdot> \<delta> \<cdot> \<I> \<noteq> pair d \<cdot> \<delta> \<cdot> \<I>" using Cons d by (auto simp add: ineq_model_def simp del: subst_range.simps) moreover have "pair d \<cdot> \<delta> = pair d" using Cons.prems(1) fun_pair_subst[of d \<delta>] d \<delta>(1) unfolding pair_def by auto ultimately show ?case unfolding pair_def by force qed simp } ultimately show ?thesis by metis qed lemma tr_NegChecks_constr_iff: "(\<forall>G\<in>set L. ineq_model \<I> X (F@G)) \<longleftrightarrow> \<lbrakk>M; map (\<lambda>G. \<forall>X\<langle>\<or>\<noteq>: (F@G)\<rangle>\<^sub>s\<^sub>t) L\<rbrakk>\<^sub>d \<I>" (is ?A) "negchecks_model \<I> D X F F' \<longleftrightarrow> \<lbrakk>M; D; [\<forall>X\<langle>\<or>\<noteq>: F \<or>\<notin>: F'\<rangle>]\<rbrakk>\<^sub>s \<I>" (is ?B) proof - show ?A by (induct L) auto show ?B by simp qed lemma tr\<^sub>p\<^sub>a\<^sub>i\<^sub>r\<^sub>s_sem_equiv: fixes \<I>::"('fun,'var) subst" assumes "\<forall>(t,t') \<in> set D. (fv t \<union> fv t') \<inter> set X = {}" shows "negchecks_model \<I> (set D \<cdot>\<^sub>p\<^sub>s\<^sub>e\<^sub>t \<I>) X F F' \<longleftrightarrow> (\<forall>G \<in> set (tr\<^sub>p\<^sub>a\<^sub>i\<^sub>r\<^sub>s F' D). ineq_model \<I> X (F@G))" proof - define P where "P \<equiv> \<lambda>\<delta>::('fun,'var) subst. subst_domain \<delta> = set X \<and> ground (subst_range \<delta>)" define Ineq where "Ineq \<equiv> \<lambda>(\<delta>::('fun,'var) subst) F. list_ex (\<lambda>f. fst f \<cdot> \<delta> \<circ>\<^sub>s \<I> \<noteq> snd f \<cdot> \<delta> \<circ>\<^sub>s \<I>) F" define Ineq' where "Ineq' \<equiv> \<lambda>(\<delta>::('fun,'var) subst) F. list_ex (\<lambda>f. fst f \<cdot> \<delta> \<circ>\<^sub>s \<I> \<noteq> snd f \<cdot> \<I>) F" define Notin where "Notin \<equiv> \<lambda>(\<delta>::('fun,'var) subst) D F'. list_ex (\<lambda>f. f \<cdot>\<^sub>p \<delta> \<circ>\<^sub>s \<I> \<notin> set D \<cdot>\<^sub>p\<^sub>s\<^sub>e\<^sub>t \<I>) F'" have sublmm: "((s,t) \<cdot>\<^sub>p \<delta> \<circ>\<^sub>s \<I> \<notin> set D \<cdot>\<^sub>p\<^sub>s\<^sub>e\<^sub>t \<I>) \<longleftrightarrow> (list_all (\<lambda>d. Ineq' \<delta> [(pair (s,t),pair d)]) D)" for s t \<delta> D unfolding pair_def by (induct D) (auto simp add: Ineq'_def) have "Notin \<delta> D F' \<longleftrightarrow> (\<forall>G \<in> set (tr\<^sub>p\<^sub>a\<^sub>i\<^sub>r\<^sub>s F' D). Ineq' \<delta> G)" (is "?A \<longleftrightarrow> ?B") when "P \<delta>" for \<delta> proof show "?A \<Longrightarrow> ?B" proof (induction F' D rule: tr\<^sub>p\<^sub>a\<^sub>i\<^sub>r\<^sub>s.induct) case (2 s t F' D) show ?case proof (cases "Notin \<delta> D F'") case False hence "(s,t) \<cdot>\<^sub>p \<delta> \<circ>\<^sub>s \<I> \<notin> set D \<cdot>\<^sub>p\<^sub>s\<^sub>e\<^sub>t \<I>" using "2.prems" by (auto simp add: Notin_def) hence "pair (s,t) \<cdot> \<delta> \<circ>\<^sub>s \<I> \<noteq> pair d \<cdot> \<I>" when "d \<in> set D" for d using that sublmm Ball_set[of D "\<lambda>d. Ineq' \<delta> [(pair (s,t), pair d)]"] by (simp add: Ineq'_def) moreover have "\<exists>d \<in> set D. \<exists>G'. G = (pair (s,t), pair d)#G'" when "G \<in> set (tr\<^sub>p\<^sub>a\<^sub>i\<^sub>r\<^sub>s ((s,t)#F') D)" for G using that tr\<^sub>p\<^sub>a\<^sub>i\<^sub>r\<^sub>s_index[OF that, of 0] by force ultimately show ?thesis by (simp add: Ineq'_def) qed (auto dest: "2.IH" simp add: Ineq'_def) qed (simp add: Notin_def) have "\<not>?A \<Longrightarrow> \<not>?B" proof (induction F' D rule: tr\<^sub>p\<^sub>a\<^sub>i\<^sub>r\<^sub>s.induct) case (2 s t F' D) then obtain G where G: "G \<in> set (tr\<^sub>p\<^sub>a\<^sub>i\<^sub>r\<^sub>s F' D)" "\<not>Ineq' \<delta> G" by (auto simp add: Notin_def) obtain d where d: "d \<in> set D" "pair (s,t) \<cdot> \<delta> \<circ>\<^sub>s \<I> = pair d \<cdot> \<I>" using "2.prems" unfolding pair_def by (auto simp add: Notin_def) thus ?case using G(2) tr\<^sub>p\<^sub>a\<^sub>i\<^sub>r\<^sub>s_cons[OF G(1) d(1)] by (auto simp add: Ineq'_def) qed (simp add: Ineq'_def) thus "?B \<Longrightarrow> ?A" by metis qed hence *: "(\<forall>\<delta>. P \<delta> \<longrightarrow> Ineq \<delta> F \<or> Notin \<delta> D F') \<longleftrightarrow> (\<forall>G \<in> set (tr\<^sub>p\<^sub>a\<^sub>i\<^sub>r\<^sub>s F' D). \<forall>\<delta>. P \<delta> \<longrightarrow> Ineq \<delta> F \<or> Ineq' \<delta> G)" by auto have "snd g \<cdot> \<delta> = snd g" when "G \<in> set (tr\<^sub>p\<^sub>a\<^sub>i\<^sub>r\<^sub>s F' D)" "g \<in> set G" "P \<delta>" for \<delta> g G using assms that(3) tr\<^sub>p\<^sub>a\<^sub>i\<^sub>r\<^sub>s_has_pair_lists[OF that(1,2)] unfolding pair_def by (fastforce simp add: P_def) hence **: "Ineq' \<delta> G = Ineq \<delta> G" when "G \<in> set (tr\<^sub>p\<^sub>a\<^sub>i\<^sub>r\<^sub>s F' D)" "P \<delta>" for \<delta> G using Bex_set[of G "\<lambda>f. fst f \<cdot> \<delta> \<circ>\<^sub>s \<I> \<noteq> snd f \<cdot> \<I>"] Bex_set[of G "\<lambda>f. fst f \<cdot> \<delta> \<circ>\<^sub>s \<I> \<noteq> snd f \<cdot> \<delta> \<circ>\<^sub>s \<I>"] that by (simp add: Ineq_def Ineq'_def) show ?thesis using * ** by (simp add: Ineq_def Ineq'_def Notin_def P_def negchecks_model_def ineq_model_def) qed lemma tr_sem_equiv': assumes "\<forall>(t,t') \<in> set D. (fv t \<union> fv t') \<inter> bvars\<^sub>s\<^sub>s\<^sub>t A = {}" and "fv\<^sub>s\<^sub>s\<^sub>t A \<inter> bvars\<^sub>s\<^sub>s\<^sub>t A = {}" and "ground M" and \<I>: "interpretation\<^sub>s\<^sub>u\<^sub>b\<^sub>s\<^sub>t \<I>" shows "\<lbrakk>M; set D \<cdot>\<^sub>p\<^sub>s\<^sub>e\<^sub>t \<I>; A\<rbrakk>\<^sub>s \<I> \<longleftrightarrow> (\<exists>A' \<in> set (tr A D). \<lbrakk>M; A'\<rbrakk>\<^sub>d \<I>)" (is "?P \<longleftrightarrow> ?Q") proof have \<I>_grounds: "\<And>t. fv (t \<cdot> \<I>) = {}" by (rule interpretation_grounds[OF \<I>]) have "\<exists>A' \<in> set (tr A D). \<lbrakk>M; A'\<rbrakk>\<^sub>d \<I>" when ?P using that assms(1,2,3) proof (induction A arbitrary: D rule: strand_sem_stateful_induct) case (ConsRcv M D t A) have "\<lbrakk>insert (t \<cdot> \<I>) M; set D \<cdot>\<^sub>p\<^sub>s\<^sub>e\<^sub>t \<I>; A\<rbrakk>\<^sub>s \<I>" "\<forall>(t,t') \<in> set D. (fv t \<union> fv t') \<inter> bvars\<^sub>s\<^sub>s\<^sub>t A = {}" "fv\<^sub>s\<^sub>s\<^sub>t A \<inter> bvars\<^sub>s\<^sub>s\<^sub>t A = {}" "ground (insert (t \<cdot> \<I>) M)" using \<I> ConsRcv.prems unfolding fv\<^sub>s\<^sub>s\<^sub>t_def bvars\<^sub>s\<^sub>s\<^sub>t_def by force+ then obtain A' where A': "A' \<in> set (tr A D)" "\<lbrakk>insert (t \<cdot> \<I>) M; A'\<rbrakk>\<^sub>d \<I>" by (metis ConsRcv.IH) thus ?case by auto next case (ConsSnd M D t A) have "\<lbrakk>M; set D \<cdot>\<^sub>p\<^sub>s\<^sub>e\<^sub>t \<I>; A\<rbrakk>\<^sub>s \<I>" "\<forall>(t,t') \<in> set D. (fv t \<union> fv t') \<inter> bvars\<^sub>s\<^sub>s\<^sub>t A = {}" "fv\<^sub>s\<^sub>s\<^sub>t A \<inter> bvars\<^sub>s\<^sub>s\<^sub>t A = {}" "ground M" and *: "M \<turnstile> t \<cdot> \<I>" using \<I> ConsSnd.prems unfolding fv\<^sub>s\<^sub>s\<^sub>t_def bvars\<^sub>s\<^sub>s\<^sub>t_def by force+ then obtain A' where A': "A' \<in> set (tr A D)" "\<lbrakk>M; A'\<rbrakk>\<^sub>d \<I>" by (metis ConsSnd.IH) thus ?case using * by auto next case (ConsEq M D ac t t' A) have "\<lbrakk>M; set D \<cdot>\<^sub>p\<^sub>s\<^sub>e\<^sub>t \<I>; A\<rbrakk>\<^sub>s \<I>" "\<forall>(t,t') \<in> set D. (fv t \<union> fv t') \<inter> bvars\<^sub>s\<^sub>s\<^sub>t A = {}" "fv\<^sub>s\<^sub>s\<^sub>t A \<inter> bvars\<^sub>s\<^sub>s\<^sub>t A = {}" "ground M" and *: "t \<cdot> \<I> = t' \<cdot> \<I>" using \<I> ConsEq.prems unfolding fv\<^sub>s\<^sub>s\<^sub>t_def bvars\<^sub>s\<^sub>s\<^sub>t_def by force+ then obtain A' where A': "A' \<in> set (tr A D)" "\<lbrakk>M; A'\<rbrakk>\<^sub>d \<I>" by (metis ConsEq.IH) thus ?case using * by auto next case (ConsIns M D t s A) have "\<lbrakk>M; set (List.insert (t,s) D) \<cdot>\<^sub>p\<^sub>s\<^sub>e\<^sub>t \<I>; A\<rbrakk>\<^sub>s \<I>" "\<forall>(t,t') \<in> set (List.insert (t,s) D). (fv t \<union> fv t') \<inter> bvars\<^sub>s\<^sub>s\<^sub>t A = {}" "fv\<^sub>s\<^sub>s\<^sub>t A \<inter> bvars\<^sub>s\<^sub>s\<^sub>t A = {}" "ground M" using ConsIns.prems unfolding fv\<^sub>s\<^sub>s\<^sub>t_def bvars\<^sub>s\<^sub>s\<^sub>t_def by force+ then obtain A' where A': "A' \<in> set (tr A (List.insert (t,s) D))" "\<lbrakk>M; A'\<rbrakk>\<^sub>d \<I>" by (metis ConsIns.IH) thus ?case by auto next case (ConsDel M D t s A) have *: "\<lbrakk>M; (set D \<cdot>\<^sub>p\<^sub>s\<^sub>e\<^sub>t \<I>) - {(t,s) \<cdot>\<^sub>p \<I>}; A\<rbrakk>\<^sub>s \<I>" "\<forall>(t,t')\<in>set D. (fv t \<union> fv t') \<inter> bvars\<^sub>s\<^sub>s\<^sub>t A = {}" "fv\<^sub>s\<^sub>s\<^sub>t A \<inter> bvars\<^sub>s\<^sub>s\<^sub>t A = {}" "ground M" using ConsDel.prems unfolding fv\<^sub>s\<^sub>s\<^sub>t_def bvars\<^sub>s\<^sub>s\<^sub>t_def by force+ then obtain Di where Di: "Di \<subseteq> set D" "Di \<cdot>\<^sub>p\<^sub>s\<^sub>e\<^sub>t \<I> \<subseteq> {(t,s) \<cdot>\<^sub>p \<I>}" "(t,s) \<cdot>\<^sub>p \<I> \<notin> (set D - Di) \<cdot>\<^sub>p\<^sub>s\<^sub>e\<^sub>t \<I>" using subset_subst_pairs_diff_exists'[of "set D"] by moura hence **: "(set D \<cdot>\<^sub>p\<^sub>s\<^sub>e\<^sub>t \<I>) - {(t,s) \<cdot>\<^sub>p \<I>} = (set D - Di) \<cdot>\<^sub>p\<^sub>s\<^sub>e\<^sub>t \<I>" by blast obtain Di' where Di': "set Di' = Di" "Di' \<in> set (subseqs D)" using subset_sublist_exists[OF Di(1)] by moura hence ***: "(set D \<cdot>\<^sub>p\<^sub>s\<^sub>e\<^sub>t \<I>) - {(t,s) \<cdot>\<^sub>p \<I>} = (set [d\<leftarrow>D. d \<notin> set Di'] \<cdot>\<^sub>p\<^sub>s\<^sub>e\<^sub>t \<I>)" using Di ** by auto define constr where "constr \<equiv> map (\<lambda>d. \<langle>check: (pair (t,s)) \<doteq> (pair d)\<rangle>\<^sub>s\<^sub>t) Di'@ map (\<lambda>d. \<forall>[]\<langle>\<or>\<noteq>: [(pair (t,s), pair d)]\<rangle>\<^sub>s\<^sub>t) [d\<leftarrow>D. d \<notin> set Di']" have ****: "\<forall>(t,t')\<in>set [d\<leftarrow>D. d \<notin> set Di']. (fv t \<union> fv t') \<inter> bvars\<^sub>s\<^sub>s\<^sub>t A = {}" using *(2) Di(1) Di'(1) subseqs_set_subset[OF Di'(2)] by simp have "set D - Di = set [d\<leftarrow>D. d \<notin> set Di']" using Di Di' by auto hence *****: "\<lbrakk>M; set [d\<leftarrow>D. d \<notin> set Di'] \<cdot>\<^sub>p\<^sub>s\<^sub>e\<^sub>t \<I>; A\<rbrakk>\<^sub>s \<I>" using *(1) ** by metis obtain A' where A': "A' \<in> set (tr A [d\<leftarrow>D. d \<notin> set Di'])" "\<lbrakk>M; A'\<rbrakk>\<^sub>d \<I>" using ConsDel.IH[OF ***** **** *(3,4)] by moura hence constr_sat: "\<lbrakk>M; constr\<rbrakk>\<^sub>d \<I>" using Di Di' *(1) *** tr_Delete_constr_iff[OF *(4), of \<I> Di' t s D] unfolding constr_def by auto have "constr@A' \<in> set (tr (Delete t s#A) D)" using A'(1) Di' unfolding constr_def by auto moreover have "ik\<^sub>s\<^sub>t constr = {}" unfolding constr_def by auto hence "\<lbrakk>M \<cdot>\<^sub>s\<^sub>e\<^sub>t \<I>; constr\<rbrakk>\<^sub>d \<I>" "\<lbrakk>M \<union> (ik\<^sub>s\<^sub>t constr \<cdot>\<^sub>s\<^sub>e\<^sub>t \<I>); A'\<rbrakk>\<^sub>d \<I>" using constr_sat A'(2) subst_all_ground_ident[OF *(4)] by simp_all ultimately show ?case using strand_sem_append(2)[of _ _ \<I>] subst_all_ground_ident[OF *(4), of \<I>] by metis next case (ConsIn M D ac t s A) have "\<lbrakk>M; set D \<cdot>\<^sub>p\<^sub>s\<^sub>e\<^sub>t \<I>; A\<rbrakk>\<^sub>s \<I>" "\<forall>(t,t') \<in> set D. (fv t \<union> fv t') \<inter> bvars\<^sub>s\<^sub>s\<^sub>t A = {}" "fv\<^sub>s\<^sub>s\<^sub>t A \<inter> bvars\<^sub>s\<^sub>s\<^sub>t A = {}" "ground M" and *: "(t,s) \<cdot>\<^sub>p \<I> \<in> set D \<cdot>\<^sub>p\<^sub>s\<^sub>e\<^sub>t \<I>" using \<I> ConsIn.prems unfolding fv\<^sub>s\<^sub>s\<^sub>t_def bvars\<^sub>s\<^sub>s\<^sub>t_def by force+ then obtain A' where A': "A' \<in> set (tr A D)" "\<lbrakk>M; A'\<rbrakk>\<^sub>d \<I>" by (metis ConsIn.IH) moreover obtain d where "d \<in> set D" "pair (t,s) \<cdot> \<I> = pair d \<cdot> \<I>" using * unfolding pair_def by auto ultimately show ?case using * by auto next case (ConsNegChecks M D X F F' A) let ?ineqs = "(map (\<lambda>G. \<forall>X\<langle>\<or>\<noteq>: (F@G)\<rangle>\<^sub>s\<^sub>t) (tr\<^sub>p\<^sub>a\<^sub>i\<^sub>r\<^sub>s F' D))" have 1: "\<lbrakk>M; set D \<cdot>\<^sub>p\<^sub>s\<^sub>e\<^sub>t \<I>; A\<rbrakk>\<^sub>s \<I>" "ground M" using ConsNegChecks by auto have 2: "\<forall>(t,t') \<in> set D. (fv t \<union> fv t') \<inter> bvars\<^sub>s\<^sub>s\<^sub>t A = {}" "fv\<^sub>s\<^sub>s\<^sub>t A \<inter> bvars\<^sub>s\<^sub>s\<^sub>t A = {}" using ConsNegChecks.prems(2,3) \<I> unfolding fv\<^sub>s\<^sub>s\<^sub>t_def bvars\<^sub>s\<^sub>s\<^sub>t_def by fastforce+ have 3: "negchecks_model \<I> (set D \<cdot>\<^sub>p\<^sub>s\<^sub>e\<^sub>t \<I>) X F F'" using ConsNegChecks.prems(1) by simp from 1 2 obtain A' where A': "A' \<in> set (tr A D)" "\<lbrakk>M; A'\<rbrakk>\<^sub>d \<I>" by (metis ConsNegChecks.IH) have 4: "\<forall>(t,t') \<in> set D. (fv t \<union> fv t') \<inter> set X = {}" using ConsNegChecks.prems(2) unfolding bvars\<^sub>s\<^sub>s\<^sub>t_def by auto have "\<lbrakk>M; ?ineqs\<rbrakk>\<^sub>d \<I>" using 3 tr\<^sub>p\<^sub>a\<^sub>i\<^sub>r\<^sub>s_sem_equiv[OF 4] tr_NegChecks_constr_iff by metis moreover have "ik\<^sub>s\<^sub>t ?ineqs = {}" by auto moreover have "M \<cdot>\<^sub>s\<^sub>e\<^sub>t \<I> = M" using 1(2) \<I> by (simp add: subst_all_ground_ident) ultimately show ?case using strand_sem_append(2)[of M ?ineqs \<I> A'] A' by force qed simp thus "?P \<Longrightarrow> ?Q" by metis have "(\<exists>A' \<in> set (tr A D). \<lbrakk>M; A'\<rbrakk>\<^sub>d \<I>) \<Longrightarrow> ?P" using assms(1,2,3) proof (induction A arbitrary: D rule: strand_sem_stateful_induct) case (ConsRcv M D t A) have "\<exists>A' \<in> set (tr A D). \<lbrakk>insert (t \<cdot> \<I>) M; A'\<rbrakk>\<^sub>d \<I>" "\<forall>(t,t') \<in> set D. (fv t \<union> fv t') \<inter> bvars\<^sub>s\<^sub>s\<^sub>t A = {}" "fv\<^sub>s\<^sub>s\<^sub>t A \<inter> bvars\<^sub>s\<^sub>s\<^sub>t A = {}" "ground (insert (t \<cdot> \<I>) M)" using \<I> ConsRcv.prems unfolding fv\<^sub>s\<^sub>s\<^sub>t_def bvars\<^sub>s\<^sub>s\<^sub>t_def by force+ hence "\<lbrakk>insert (t \<cdot> \<I>) M; set D \<cdot>\<^sub>p\<^sub>s\<^sub>e\<^sub>t \<I>; A\<rbrakk>\<^sub>s \<I>" by (metis ConsRcv.IH) thus ?case by auto next case (ConsSnd M D t A) have "\<exists>A' \<in> set (tr A D). \<lbrakk>M; A'\<rbrakk>\<^sub>d \<I>" "\<forall>(t,t') \<in> set D. (fv t \<union> fv t') \<inter> bvars\<^sub>s\<^sub>s\<^sub>t A = {}" "fv\<^sub>s\<^sub>s\<^sub>t A \<inter> bvars\<^sub>s\<^sub>s\<^sub>t A = {}" "ground M" and *: "M \<turnstile> t \<cdot> \<I>" using \<I> ConsSnd.prems unfolding fv\<^sub>s\<^sub>s\<^sub>t_def bvars\<^sub>s\<^sub>s\<^sub>t_def by force+ hence "\<lbrakk>M; set D \<cdot>\<^sub>p\<^sub>s\<^sub>e\<^sub>t \<I>; A\<rbrakk>\<^sub>s \<I>" by (metis ConsSnd.IH) thus ?case using * by auto next case (ConsEq M D ac t t' A) have "\<exists>A' \<in> set (tr A D). \<lbrakk>M; A'\<rbrakk>\<^sub>d \<I>" "\<forall>(t,t') \<in> set D. (fv t \<union> fv t') \<inter> bvars\<^sub>s\<^sub>s\<^sub>t A = {}" "fv\<^sub>s\<^sub>s\<^sub>t A \<inter> bvars\<^sub>s\<^sub>s\<^sub>t A = {}" "ground M" and *: "t \<cdot> \<I> = t' \<cdot> \<I>" using \<I> ConsEq.prems unfolding fv\<^sub>s\<^sub>s\<^sub>t_def bvars\<^sub>s\<^sub>s\<^sub>t_def by force+ hence "\<lbrakk>M; set D \<cdot>\<^sub>p\<^sub>s\<^sub>e\<^sub>t \<I>; A\<rbrakk>\<^sub>s \<I>" by (metis ConsEq.IH) thus ?case using * by auto next case (ConsIns M D t s A) hence "\<exists>A' \<in> set (tr A (List.insert (t,s) D)). \<lbrakk>M; A'\<rbrakk>\<^sub>d \<I>" "\<forall>(t,t') \<in> set (List.insert (t,s) D). (fv t \<union> fv t') \<inter> bvars\<^sub>s\<^sub>s\<^sub>t A = {}" "fv\<^sub>s\<^sub>s\<^sub>t A \<inter> bvars\<^sub>s\<^sub>s\<^sub>t A = {}" "ground M" unfolding fv\<^sub>s\<^sub>s\<^sub>t_def bvars\<^sub>s\<^sub>s\<^sub>t_def by auto+ hence "\<lbrakk>M; set (List.insert (t,s) D) \<cdot>\<^sub>p\<^sub>s\<^sub>e\<^sub>t \<I>; A\<rbrakk>\<^sub>s \<I>" by (metis ConsIns.IH) thus ?case by auto next case (ConsDel M D t s A) define constr where "constr \<equiv> \<lambda>Di. map (\<lambda>d. \<langle>check: (pair (t,s)) \<doteq> (pair d)\<rangle>\<^sub>s\<^sub>t) Di@ map (\<lambda>d. \<forall>[]\<langle>\<or>\<noteq>: [(pair (t,s), pair d)]\<rangle>\<^sub>s\<^sub>t) [d\<leftarrow>D. d \<notin> set Di]" let ?flt = "\<lambda>Di. filter (\<lambda>d. d \<notin> set Di) D" have "\<exists>Di \<in> set (subseqs D). \<exists>B' \<in> set (tr A (?flt Di)). B = constr Di@B'" when "B \<in> set (tr (delete\<langle>t,s\<rangle>#A) D)" for B using that unfolding constr_def by auto then obtain A' Di where A': "constr Di@A' \<in> set (tr (Delete t s#A) D)" "A' \<in> set (tr A (?flt Di))" "Di \<in> set (subseqs D)" "\<lbrakk>M; constr Di@A'\<rbrakk>\<^sub>d \<I>" using ConsDel.prems(1) by blast have 1: "\<forall>(t,t')\<in>set (?flt Di). (fv t \<union> fv t') \<inter> bvars\<^sub>s\<^sub>s\<^sub>t A = {}" using ConsDel.prems(2) by auto have 2: "fv\<^sub>s\<^sub>s\<^sub>t A \<inter> bvars\<^sub>s\<^sub>s\<^sub>t A = {}" using ConsDel.prems(3) by force+ have "ik\<^sub>s\<^sub>t (constr Di) = {}" unfolding constr_def by auto hence 3: "\<lbrakk>M; A'\<rbrakk>\<^sub>d \<I>" using subst_all_ground_ident[OF ConsDel.prems(4)] A'(4) strand_sem_split(4)[of M "constr Di" A' \<I>] by simp have IH: "\<lbrakk>M; set (?flt Di) \<cdot>\<^sub>p\<^sub>s\<^sub>e\<^sub>t \<I>; A\<rbrakk>\<^sub>s \<I>" by (metis ConsDel.IH[OF _ 1 2 ConsDel.prems(4)] 3 A'(2)) have "\<lbrakk>M; constr Di\<rbrakk>\<^sub>d \<I>" using subst_all_ground_ident[OF ConsDel.prems(4)] strand_sem_split(3) A'(4) by metis hence *: "set Di \<cdot>\<^sub>p\<^sub>s\<^sub>e\<^sub>t \<I> \<subseteq> {(t,s) \<cdot>\<^sub>p \<I>}" "(t,s) \<cdot>\<^sub>p \<I> \<notin> (set D - set Di) \<cdot>\<^sub>p\<^sub>s\<^sub>e\<^sub>t \<I>" using tr_Delete_constr_iff[OF ConsDel.prems(4), of \<I> Di t s D] unfolding constr_def by auto have 4: "set (?flt Di) \<cdot>\<^sub>p\<^sub>s\<^sub>e\<^sub>t \<I> = (set D \<cdot>\<^sub>p\<^sub>s\<^sub>e\<^sub>t \<I>) - {((t,s) \<cdot>\<^sub>p \<I>)}" proof show "set (?flt Di) \<cdot>\<^sub>p\<^sub>s\<^sub>e\<^sub>t \<I> \<subseteq> (set D \<cdot>\<^sub>p\<^sub>s\<^sub>e\<^sub>t \<I>) - {((t,s) \<cdot>\<^sub>p \<I>)}" proof fix u u' assume u: "(u,u') \<in> set (?flt Di) \<cdot>\<^sub>p\<^sub>s\<^sub>e\<^sub>t \<I>" then obtain v v' where v: "(v,v') \<in> set D - set Di" "(v,v') \<cdot>\<^sub>p \<I> = (u,u')" by auto hence "(u,u') \<noteq> (t,s) \<cdot>\<^sub>p \<I>" using * by force thus "(u,u') \<in> (set D \<cdot>\<^sub>p\<^sub>s\<^sub>e\<^sub>t \<I>) - {((t,s) \<cdot>\<^sub>p \<I>)}" using u v * subseqs_set_subset[OF A'(3)] by auto qed show "(set D \<cdot>\<^sub>p\<^sub>s\<^sub>e\<^sub>t \<I>) - {((t,s) \<cdot>\<^sub>p \<I>)} \<subseteq> set (?flt Di) \<cdot>\<^sub>p\<^sub>s\<^sub>e\<^sub>t \<I>" using * subseqs_set_subset[OF A'(3)] by force qed show ?case using 4 IH by simp next case (ConsIn M D ac t s A) have "\<exists>A' \<in> set (tr A D). \<lbrakk>M; A'\<rbrakk>\<^sub>d \<I>" "\<forall>(t,t') \<in> set D. (fv t \<union> fv t') \<inter> bvars\<^sub>s\<^sub>s\<^sub>t A = {}" "fv\<^sub>s\<^sub>s\<^sub>t A \<inter> bvars\<^sub>s\<^sub>s\<^sub>t A = {}" "ground M" and *: "(t,s) \<cdot>\<^sub>p \<I> \<in> set D \<cdot>\<^sub>p\<^sub>s\<^sub>e\<^sub>t \<I>" using ConsIn.prems(1,2,3,4) apply (fastforce, fastforce, fastforce, fastforce) using ConsIn.prems(1) tr.simps(7)[of ac t s A D] unfolding pair_def by fastforce hence "\<lbrakk>M; set D \<cdot>\<^sub>p\<^sub>s\<^sub>e\<^sub>t \<I>; A\<rbrakk>\<^sub>s \<I>" by (metis ConsIn.IH) moreover obtain d where "d \<in> set D" "pair (t,s) \<cdot> \<I> = pair d \<cdot> \<I>" using * unfolding pair_def by auto ultimately show ?case using * by auto next case (ConsNegChecks M D X F F' A) let ?ineqs = "(map (\<lambda>G. \<forall>X\<langle>\<or>\<noteq>: (F@G)\<rangle>\<^sub>s\<^sub>t) (tr\<^sub>p\<^sub>a\<^sub>i\<^sub>r\<^sub>s F' D))" obtain B where B: "?ineqs@B \<in> set (tr (NegChecks X F F'#A) D)" "\<lbrakk>M; ?ineqs@B\<rbrakk>\<^sub>d \<I>" "B \<in> set (tr A D)" using ConsNegChecks.prems(1) by moura moreover have "M \<cdot>\<^sub>s\<^sub>e\<^sub>t \<I> = M" using ConsNegChecks.prems(4) \<I> by (simp add: subst_all_ground_ident) moreover have "ik\<^sub>s\<^sub>t ?ineqs = {}" by auto ultimately have "\<lbrakk>M; B\<rbrakk>\<^sub>d \<I>" using strand_sem_split(4)[of M ?ineqs B \<I>] by simp moreover have "\<forall>(t,t')\<in>set D. (fv t \<union> fv t') \<inter> bvars\<^sub>s\<^sub>s\<^sub>t A = {}" "fv\<^sub>s\<^sub>s\<^sub>t A \<inter> bvars\<^sub>s\<^sub>s\<^sub>t A = {}" using ConsNegChecks.prems(2,3) unfolding fv\<^sub>s\<^sub>s\<^sub>t_def bvars\<^sub>s\<^sub>s\<^sub>t_def by force+ ultimately have "\<lbrakk>M; set D \<cdot>\<^sub>p\<^sub>s\<^sub>e\<^sub>t \<I>; A\<rbrakk>\<^sub>s \<I>" by (metis ConsNegChecks.IH B(3) ConsNegChecks.prems(4)) moreover have "\<forall>(t, t')\<in>set D. (fv t \<union> fv t') \<inter> set X = {}" using ConsNegChecks.prems(2) unfolding bvars\<^sub>s\<^sub>s\<^sub>t_def by force ultimately show ?case using tr\<^sub>p\<^sub>a\<^sub>i\<^sub>r\<^sub>s_sem_equiv tr_NegChecks_constr_iff B(2) strand_sem_split(3)[of M ?ineqs B \<I>] \<open>M \<cdot>\<^sub>s\<^sub>e\<^sub>t \<I> = M\<close> by simp qed simp thus "?Q \<Longrightarrow> ?P" by metis qed lemma tr_sem_equiv: assumes "fv\<^sub>s\<^sub>s\<^sub>t A \<inter> bvars\<^sub>s\<^sub>s\<^sub>t A = {}" and "interpretation\<^sub>s\<^sub>u\<^sub>b\<^sub>s\<^sub>t \<I>" shows "\<I> \<Turnstile>\<^sub>s A \<longleftrightarrow> (\<exists>A' \<in> set (tr A []). (\<I> \<Turnstile> \<langle>A'\<rangle>))" using tr_sem_equiv'[OF _ assms(1) _ assms(2), of "[]" "{}"] unfolding constr_sem_d_def by auto theorem stateful_typing_result: assumes "wf\<^sub>s\<^sub>s\<^sub>t \<A>" and "tfr\<^sub>s\<^sub>s\<^sub>t \<A>" and "wf\<^sub>t\<^sub>r\<^sub>m\<^sub>s (trms\<^sub>s\<^sub>s\<^sub>t \<A>)" and "interpretation\<^sub>s\<^sub>u\<^sub>b\<^sub>s\<^sub>t \<I>" and "\<I> \<Turnstile>\<^sub>s \<A>" obtains \<I>\<^sub>\<tau> where "interpretation\<^sub>s\<^sub>u\<^sub>b\<^sub>s\<^sub>t \<I>\<^sub>\<tau>" and "\<I>\<^sub>\<tau> \<Turnstile>\<^sub>s \<A>" and "wt\<^sub>s\<^sub>u\<^sub>b\<^sub>s\<^sub>t \<I>\<^sub>\<tau>" and "wf\<^sub>t\<^sub>r\<^sub>m\<^sub>s (subst_range \<I>\<^sub>\<tau>)" proof - obtain \<A>' where \<A>': "\<A>' \<in> set (tr \<A> [])" "\<I> \<Turnstile> \<langle>\<A>'\<rangle>" using tr_sem_equiv[of \<A>] assms(1,4,5) by auto have *: "wf\<^sub>s\<^sub>t {} \<A>'" "fv\<^sub>s\<^sub>t \<A>' \<inter> bvars\<^sub>s\<^sub>t \<A>' = {}" "tfr\<^sub>s\<^sub>t \<A>'" "wf\<^sub>t\<^sub>r\<^sub>m\<^sub>s (trms\<^sub>s\<^sub>t \<A>')" using tr_wf[OF \<A>'(1) assms(1,3)] tr_tfr[OF \<A>'(1) assms(2)] assms(1) by metis+ obtain \<I>\<^sub>\<tau> where \<I>\<^sub>\<tau>: "interpretation\<^sub>s\<^sub>u\<^sub>b\<^sub>s\<^sub>t \<I>\<^sub>\<tau>" "\<lbrakk>{}; \<A>'\<rbrakk>\<^sub>d \<I>\<^sub>\<tau>" "wt\<^sub>s\<^sub>u\<^sub>b\<^sub>s\<^sub>t \<I>\<^sub>\<tau>" "wf\<^sub>t\<^sub>r\<^sub>m\<^sub>s (subst_range \<I>\<^sub>\<tau>)" using wt_attack_if_tfr_attack_d * Ana_invar_subst' assms(4) \<A>'(2) unfolding constr_sem_d_def by moura thus ?thesis using that tr_sem_equiv[of \<A>] assms(1,3) \<A>'(1) unfolding constr_sem_d_def by auto qed end end subsection \<open>Proving type-flaw resistance automatically\<close> definition pair' where "pair' pair_fun d \<equiv> case d of (t,t') \<Rightarrow> Fun pair_fun [t,t']" fun comp_tfr\<^sub>s\<^sub>s\<^sub>t\<^sub>p where "comp_tfr\<^sub>s\<^sub>s\<^sub>t\<^sub>p \<Gamma> pair_fun (\<langle>_: t \<doteq> t'\<rangle>) = (mgu t t' \<noteq> None \<longrightarrow> \<Gamma> t = \<Gamma> t')" | "comp_tfr\<^sub>s\<^sub>s\<^sub>t\<^sub>p \<Gamma> pair_fun (\<forall>X\<langle>\<or>\<noteq>: F \<or>\<notin>: F'\<rangle>) = ( (F' = [] \<and> (\<forall>x \<in> fv\<^sub>p\<^sub>a\<^sub>i\<^sub>r\<^sub>s F - set X. is_Var (\<Gamma> (Var x)))) \<or> (\<forall>u \<in> subterms\<^sub>s\<^sub>e\<^sub>t (trms\<^sub>p\<^sub>a\<^sub>i\<^sub>r\<^sub>s F \<union> pair' pair_fun ` set F'). is_Fun u \<longrightarrow> (args u = [] \<or> (\<exists>s \<in> set (args u). s \<notin> Var ` set X))))" | "comp_tfr\<^sub>s\<^sub>s\<^sub>t\<^sub>p _ _ _ = True" definition comp_tfr\<^sub>s\<^sub>s\<^sub>t where "comp_tfr\<^sub>s\<^sub>s\<^sub>t arity Ana \<Gamma> pair_fun M S \<equiv> list_all (comp_tfr\<^sub>s\<^sub>s\<^sub>t\<^sub>p \<Gamma> pair_fun) S \<and> list_all (wf\<^sub>t\<^sub>r\<^sub>m' arity) (trms_list\<^sub>s\<^sub>s\<^sub>t S) \<and> has_all_wt_instances_of \<Gamma> (trms\<^sub>s\<^sub>s\<^sub>t S \<union> pair' pair_fun ` setops\<^sub>s\<^sub>s\<^sub>t S) (set M) \<and> comp_tfr\<^sub>s\<^sub>e\<^sub>t arity Ana \<Gamma> M" locale stateful_typed_model' = stateful_typed_model arity public Ana \<Gamma> Pair for arity::"'fun \<Rightarrow> nat" and public::"'fun \<Rightarrow> bool" and Ana::"('fun,(('fun,'atom::finite) term_type \<times> nat)) term \<Rightarrow> (('fun,(('fun,'atom) term_type \<times> nat)) term list \<times> ('fun,(('fun,'atom) term_type \<times> nat)) term list)" and \<Gamma>::"('fun,(('fun,'atom) term_type \<times> nat)) term \<Rightarrow> ('fun,'atom) term_type" and Pair::"'fun" + assumes \<Gamma>_Var_fst': "\<And>\<tau> n m. \<Gamma> (Var (\<tau>,n)) = \<Gamma> (Var (\<tau>,m))" and Ana_const': "\<And>c T. arity c = 0 \<Longrightarrow> Ana (Fun c T) = ([], [])" begin sublocale typed_model' by (unfold_locales, rule \<Gamma>_Var_fst', metis Ana_const', metis Ana_subst') lemma pair_code: "pair d = pair' Pair d" by (simp add: pair_def pair'_def) lemma tfr\<^sub>s\<^sub>s\<^sub>t\<^sub>p_is_comp_tfr\<^sub>s\<^sub>s\<^sub>t\<^sub>p: "tfr\<^sub>s\<^sub>s\<^sub>t\<^sub>p a = comp_tfr\<^sub>s\<^sub>s\<^sub>t\<^sub>p \<Gamma> Pair a" proof (cases a) case (Equality ac t t') thus ?thesis using mgu_always_unifies[of t _ t'] mgu_gives_MGU[of t t'] by auto next case (NegChecks X F F') thus ?thesis using tfr\<^sub>s\<^sub>s\<^sub>t\<^sub>p.simps(2)[of X F F'] comp_tfr\<^sub>s\<^sub>s\<^sub>t\<^sub>p.simps(2)[of \<Gamma> Pair X F F'] Fun_range_case(2)[of "subterms\<^sub>s\<^sub>e\<^sub>t (trms\<^sub>p\<^sub>a\<^sub>i\<^sub>r\<^sub>s F \<union> pair ` set F')"] unfolding is_Var_def pair_code[symmetric] by auto qed auto lemma tfr\<^sub>s\<^sub>s\<^sub>t_if_comp_tfr\<^sub>s\<^sub>s\<^sub>t: assumes "comp_tfr\<^sub>s\<^sub>s\<^sub>t arity Ana \<Gamma> Pair M S" shows "tfr\<^sub>s\<^sub>s\<^sub>t S" unfolding tfr\<^sub>s\<^sub>s\<^sub>t_def proof have comp_tfr\<^sub>s\<^sub>e\<^sub>t_M: "comp_tfr\<^sub>s\<^sub>e\<^sub>t arity Ana \<Gamma> M" using assms unfolding comp_tfr\<^sub>s\<^sub>s\<^sub>t_def by blast have wf\<^sub>t\<^sub>r\<^sub>m\<^sub>s_M: "wf\<^sub>t\<^sub>r\<^sub>m\<^sub>s (set M)" and wf\<^sub>t\<^sub>r\<^sub>m\<^sub>s_S: "wf\<^sub>t\<^sub>r\<^sub>m\<^sub>s (trms\<^sub>s\<^sub>s\<^sub>t S \<union> pair ` setops\<^sub>s\<^sub>s\<^sub>t S)" and S_trms_instance_M: "has_all_wt_instances_of \<Gamma> (trms\<^sub>s\<^sub>s\<^sub>t S \<union> pair ` setops\<^sub>s\<^sub>s\<^sub>t S) (set M)" using assms setops\<^sub>s\<^sub>s\<^sub>t_wf\<^sub>t\<^sub>r\<^sub>m\<^sub>s(2)[of S] trms_list\<^sub>s\<^sub>s\<^sub>t_is_trms\<^sub>s\<^sub>s\<^sub>t[of S] unfolding comp_tfr\<^sub>s\<^sub>s\<^sub>t_def comp_tfr\<^sub>s\<^sub>e\<^sub>t_def list_all_iff pair_code[symmetric] wf\<^sub>t\<^sub>r\<^sub>m_code[symmetric] finite_SMP_representation_def by (meson, meson, blast, meson) show "tfr\<^sub>s\<^sub>e\<^sub>t (trms\<^sub>s\<^sub>s\<^sub>t S \<union> pair ` setops\<^sub>s\<^sub>s\<^sub>t S)" using tfr_subset(3)[OF tfr\<^sub>s\<^sub>e\<^sub>t_if_comp_tfr\<^sub>s\<^sub>e\<^sub>t[OF comp_tfr\<^sub>s\<^sub>e\<^sub>t_M] SMP_SMP_subset] SMP_I'[OF wf\<^sub>t\<^sub>r\<^sub>m\<^sub>s_S wf\<^sub>t\<^sub>r\<^sub>m\<^sub>s_M S_trms_instance_M] by blast have "list_all (comp_tfr\<^sub>s\<^sub>s\<^sub>t\<^sub>p \<Gamma> Pair) S" by (metis assms comp_tfr\<^sub>s\<^sub>s\<^sub>t_def) thus "list_all tfr\<^sub>s\<^sub>s\<^sub>t\<^sub>p S" by (induct S) (simp_all add: tfr\<^sub>s\<^sub>s\<^sub>t\<^sub>p_is_comp_tfr\<^sub>s\<^sub>s\<^sub>t\<^sub>p) qed lemma tfr\<^sub>s\<^sub>s\<^sub>t_if_comp_tfr\<^sub>s\<^sub>s\<^sub>t': assumes "comp_tfr\<^sub>s\<^sub>s\<^sub>t arity Ana \<Gamma> Pair (SMP0 Ana \<Gamma> (trms_list\<^sub>s\<^sub>s\<^sub>t S@map pair (setops_list\<^sub>s\<^sub>s\<^sub>t S))) S" shows "tfr\<^sub>s\<^sub>s\<^sub>t S" by (rule tfr\<^sub>s\<^sub>s\<^sub>t_if_comp_tfr\<^sub>s\<^sub>s\<^sub>t[OF assms]) end end
library(ggplot2) alldata = read.csv('graphs/results.csv') strgrapher <- function(exclude, ty, wl, title) { ftab = subset(subset(subset(alldata, data.type == ty), workload == wl), number.of.elements != exclude) tags=ftab$data.structure sizes=ftab$str.number.of.elements optimes=ftab$mean.time.per.operation.ns btab = data.frame(Size=sizes, Data.Structure=tags, ns.Per.Op=optimes) # print(btab) png(filename=paste('graphs/', paste(ty,wl,sep='_'), '.png', sep=''), width=600, height=600) posns <- c("16K", "1M", "16M") ggplot(btab, aes(fill=Data.Structure,y=ns.Per.Op, x=Size)) + scale_x_discrete(limits=posns) + geom_bar(position="dodge", stat="identity") + labs(title=title, x="Number of Elements", y="ns Per Operation") } intgrapher <- function(size, ty1, ty2, wl, title) { ftab1 = subset(subset(subset(alldata, number.of.elements == size), data.type == ty1), workload == wl) ftab2 = subset(subset(subset(alldata, number.of.elements == size), data.type == ty2), workload == wl) png(filename=paste('graphs/', paste(ty1,ty2,wl,size,sep='_'), '.png', sep=''), width=600, height=600) tags = c(rep('dense', length(ftab1$mean.time.per.operation.ns)), rep('sparse', length(ftab1$mean.time.per.operation.ns))) btab = data.frame(Data.Structure=rep(ftab1$data.structure, 2), ns.Per.Operation=c(ftab1$mean.time.per.operation.ns, ftab2$mean.time.per.operation.ns), workload=tags) ggplot(btab, aes(fill=workload, y=ns.Per.Operation, x=Data.Structure)) + geom_bar(position="dodge", stat="identity") + labs(title=title, x="Data Structure", y="ns Per Operation") } intgrapher(16384, 'dense_u64', 'sparse_u64', 'lookup_hit', 'Lookups for elements in the set with integer keys, 16K elements') intgrapher(16777216, 'dense_u64', 'sparse_u64', 'lookup_hit', 'Lookups for elements in the set with integer keys, 16M elements') intgrapher(268435456, 'dense_u64', 'sparse_u64', 'lookup_hit', 'Lookups for elements in the set with integer keys, 256M elements') intgrapher(16384, 'dense_u64', 'sparse_u64', 'lookup_miss', 'Lookups for elements not in the set with integer keys, 16K elements') intgrapher(16777216, 'dense_u64', 'sparse_u64', 'lookup_miss', 'Lookups for elements not in the set with integer keys, 16M elements') intgrapher(268435456, 'dense_u64', 'sparse_u64', 'lookup_miss', 'Lookups for elements not in the set with integer keys, 256M elements') intgrapher(16384, 'dense_u64', 'sparse_u64', 'insert_remove', 'Insert/Remove pairs with integer keys, 16K elements') intgrapher(16777216, 'dense_u64', 'sparse_u64', 'insert_remove', 'Insert/Remove pairs with integer keys, 16M elements') intgrapher(268435456, 'dense_u64', 'sparse_u64', 'insert_remove', 'Insert/Remove pairs with integer keys, 256M elements') strgrapher(67108864,'String', 'lookup_hit', 'Lookups in the set, UTF-8 Strings of mean length 10') strgrapher(67108864,'String', 'lookup_miss', 'Lookups not in the set, UTF-8 Strings of mean length 10') strgrapher(67108864,'String', 'insert_remove', 'Insert/Remove Pairs, UTF-8 Strings of mean length 10')
From iris.algebra Require Import numbers excl auth list gset gmap agree csum. From iris.bi.lib Require Import fractional. From iris.proofmode Require Import proofmode. From iris.base_logic.lib Require Export invariants proph_map saved_prop. From iris.program_logic Require Export atomic. From iris.heap_lang.lib Require Import arith diverge. From iris.heap_lang Require Import proofmode notation par. From iris_examples.logatom.herlihy_wing_queue Require Import spec. From iris.prelude Require Import options. (** * Some array-related notations ******************************************) Notation "new_array: sz" := (AllocN sz%E NONEV) (at level 80) : expr_scope. Notation "e1 <[[ e2 ]]>" := (BinOp OffsetOp e1%E e2%E) (at level 8) : expr_scope. (** * Implementation of the queue operations ********************************) (** new_queue(sz){ let ar := new_array sz None in let back := ref 0 in let p := new_proph () in {sz, ar, back, p} } *) Definition new_queue : val := λ: "sz", let: "ar" := new_array: "sz" in let: "back" := ref #0 in (* First free cell. *) let: "p" := NewProph in ("sz", "ar", "back", "p"). (** enqueue(q : queue, x : item){ let i : int := FAA(q.back, 1) in if(i < q.size){ q.items[i] := x } else { while true; } } *) Definition enqueue : val := λ: "q" "x", let: "q_size" := Fst (Fst (Fst "q")) in let: "q_ar" := Snd (Fst (Fst "q")) in let: "q_back" := Snd (Fst "q") in (* Get the next free index. *) let: "i" := FAA "q_back" #1 in (* Check not full, and actually insert. *) if: "i" < "q_size" then "q_ar"<[["i"]]> <- SOME "x" ;; Skip else diverge #(). (** dequeue(q : queue){ let range = min(!q.back, q.size) in let rec dequeue_aux(i) = if i = 0 { dequeue(q) } else { let j = range - i in let x = ! q.ar[j] in if x == null { dequeue_aux(i-1) } else { if resolve (CAS q.ar[j] x null) q.p (j, x) { v } else { dequeue_aux(i-1) } } } in dequeue_aux(range) } *) Definition dequeue_aux : val := rec: "loop" "dequeue" "q" "range" "i" := if: "i" = #0 then "dequeue" "q" else let: "q_ar" := Snd (Fst (Fst "q")) in let: "q_p" := Snd "q" in let: "j" := "range" - "i" in let: "x" := ! "q_ar"<[["j"]]> in match: "x" with NONE => "loop" "dequeue" "q" "range" ("i" - #1) | SOME "v" => let: "c" := Resolve (CmpXchg ("q_ar"<[["j"]]>) "x" NONE) "q_p" "j" in if: Snd "c" then "v" else "loop" "dequeue" "q" "range" ("i" - #1) end. Definition dequeue : val := rec: "dequeue" "q" := let: "q_size" := Fst (Fst (Fst "q")) in let: "q_back" := Snd (Fst "q") in let: "range" := minimum !"q_back" "q_size" in dequeue_aux "dequeue" "q" "range" "range". (** * Definition of the cameras we need for queues **************************) Definition prod4R A B C D E := prodR (prodR (prodR (prodR A B) C) D) E. Definition oneshotUR := optionUR $ csumR (exclR unitR) (agreeR unitR). Definition shot : oneshotUR := Some $ Cinr $ to_agree (). Definition not_shot : oneshotUR := Some $ Cinl $ Excl (). Definition per_slot := prod4R (* Unique token for the index. *) (optionUR $ exclR unitR) (* The location stored at our index, which always remains the same. *) (optionUR $ agreeR locO) (* Possible unique name for the index, only if being helped. *) (optionUR $ exclR gnameO) (* One shot witnessing the transition from pending to helped. *) oneshotUR (* One shot witnessing the physical writing of the value in the slot. *) oneshotUR. Definition eltsUR := authR $ optionUR $ exclR $ listO locO. Definition contUR := csumR (exclR unitR) (agreeR (prodO natO natO)). Definition slotUR := authR $ gmapUR nat per_slot. Definition backUR := authR max_natUR. Class hwqG Σ := HwqG { hwq_arG :> inG Σ eltsUR; (** Logical contents of the queue. *) hwq_contG :> inG Σ contUR; (** One-shot for contradiction states. *) hwq_slotG :> inG Σ slotUR; (** State data for used array slots. *) hwq_back :> inG Σ backUR; (** Used to show that back only increases. *) }. Definition hwqΣ : gFunctors := #[GFunctor eltsUR; GFunctor contUR; GFunctor slotUR; GFunctor backUR]. Global Instance subG_hwqΣ {Σ} : subG hwqΣ Σ → hwqG Σ. Proof. solve_inG. Qed. (** * The specifiaction... **************************************************) Section herlihy_wing_queue. Context `{!heapGS Σ, !savedPropG Σ, !hwqG Σ}. Context (N : namespace). Notation iProp := (iProp Σ). Implicit Types γe γc γs : gname. Implicit Types sz : nat. Implicit Types ℓ_ar ℓ_back : loc. Implicit Types p : proph_id. Implicit Types v : val. Implicit Types pvs : list nat. (** Operations for the CMRA representing the logical contents of the queue. *) Lemma new_elts l : ⊢ |==> ∃ γe, own γe (● Excl' l) ∗ own γe (◯ Excl' l). Proof. iMod (own_alloc (● Excl' l ⋅ ◯ Excl' l)) as (γe) "[H● H◯]". - by apply auth_both_valid_discrete. - iModIntro. iExists γe. iFrame. Qed. Lemma sync_elts γe (l1 l2 : list loc) : own γe (● Excl' l1) -∗ own γe (◯ Excl' l2) -∗ ⌜l1 = l2⌝. Proof. iIntros "H● H◯". iCombine "H●" "H◯" as "H". iDestruct (own_valid with "H") as "H". by iDestruct "H" as %[H%Excl_included%leibniz_equiv _]%auth_both_valid_discrete. Qed. Lemma update_elts γe (l1 l2 l : list loc) : own γe (● Excl' l1) -∗ own γe (◯ Excl' l2) ==∗ own γe (● Excl' l) ∗ own γe (◯ Excl' l). Proof. iIntros "H● H◯". iCombine "H●" "H◯" as "H". rewrite -own_op. iApply (own_update with "H"). by apply auth_update, option_local_update, exclusive_local_update. Qed. (* Fragmental part, made available during atomic updates. *) Definition hwq_cont γe (elts : list loc) : iProp := own γe (◯ Excl' elts). Lemma hwq_cont_exclusive γe elts1 elts2 : hwq_cont γe elts1 -∗ hwq_cont γe elts2 -∗ False. Proof. iIntros "H1 H2". by iDestruct (own_valid_2 with "H1 H2") as %?%auth_frag_op_valid_1. Qed. (** Operations for the CMRA used to show that back only increases. *) Definition back_value γb n := own γb (● MaxNat n). Definition back_lower_bound γb n := own γb (◯ MaxNat n). Lemma new_back : ⊢ |==> ∃ γb, back_value γb 0. Proof. iMod (own_alloc (● MaxNat 0)) as (γb) "H●". - by rewrite auth_auth_valid. - by iExists γb. Qed. Lemma back_incr γb n : back_value γb n ==∗ back_value γb (S n). Proof. iIntros "H●". iMod (own_update with "H●") as "[$ _]"; last done. apply auth_update_alloc, (max_nat_local_update _ _ (MaxNat (S n))). simpl. lia. Qed. Lemma back_snapshot γb n : back_value γb n ==∗ back_value γb n ∗ back_lower_bound γb n. Proof. iIntros "H●". rewrite -own_op. iApply (own_update with "H●"). by apply auth_update_alloc, max_nat_local_update. Qed. Lemma back_le γb n1 n2 : back_value γb n1 -∗ back_lower_bound γb n2 -∗ ⌜n2 ≤ n1⌝. Proof. iIntros "H1 H2". iCombine "H1 H2" as "H". iDestruct (own_valid with "H") as %Hvalid. iPureIntro. apply auth_both_valid_discrete in Hvalid as [H1%max_nat_included _]. done. Qed. (* Stores a lower bound on the [i2] part of any contradiction that has arised or may arise in the future. *) Definition i2_lower_bound γi n := back_value γi n. (* Witness that the [i2] part of any (future or not) contradicton is greater than [n]. *) Definition no_contra_wit γi n := back_lower_bound γi n. Lemma i2_lower_bound_update γi n m : n ≤ m → i2_lower_bound γi n ==∗ i2_lower_bound γi m. Proof. iIntros (H) "H●". iMod (own_update with "H●") as "[$ _]"; last done. apply auth_update_alloc, (max_nat_local_update _ _ (MaxNat m)). simpl. lia. Qed. Lemma i2_lower_bound_snapshot γi n : i2_lower_bound γi n ==∗ i2_lower_bound γi n ∗ no_contra_wit γi n. Proof. iIntros "H●". rewrite -own_op. iApply (own_update with "H●"). by apply auth_update_alloc, max_nat_local_update. Qed. (** Operations for the one-shot CMRA used for contradiction states. *) (** Element for "no contradiction yet". *) Definition no_contra γc := own γc (Cinl (Excl ())). (** Element witnessing a contradiction [(i1, i2)]. *) Definition contra γc (i1 i2 : nat) := own γc (Cinr (to_agree (i1, i2))). Lemma new_no_contra : ⊢ |==> ∃ γc, no_contra γc. Proof. by apply own_alloc. Qed. Lemma to_contra i1 i2 γc : no_contra γc ==∗ contra γc i1 i2. Proof. apply own_update. by apply cmra_update_exclusive. Qed. Lemma contra_not_no_contra i1 i2 γc : no_contra γc -∗ contra γc i1 i2 -∗ False. Proof. iIntros "HnoC HC". iDestruct (own_valid_2 with "HnoC HC") as %[]. Qed. Lemma contra_agree i1 i2 i1' i2' γc : contra γc i1 i2 -∗ contra γc i1' i2' -∗ ⌜i1' = i1 ∧ i2' = i2⌝. Proof. iIntros "HC HC'". iDestruct (own_valid_2 with "HC HC'") as %H. iPureIntro. apply to_agree_op_inv_L in H. by inversion H. Qed. Global Instance contra_persistent γc i1 i2 : Persistent (contra γc i1 i2). Proof. apply own_core_persistent. by rewrite /CoreId. Qed. (** Operations for the state data. *) Inductive state := (** Help was requested (element not committed). *) | Pend : gname → state (** Help has been provided (element committed). *) | Help : gname → state (** The enqueue operation known it has been committed. *) | Done : state. Instance state_inhabited : Inhabited state. Proof. constructor. refine Done. Qed. (** Data associated to each slot. The four components are: - the location that is being written in the slot, - a possible name for a stored proposition containing the postcondition of the atomic update of the enqueue happening for the slot (used only in case of helping), - state of the slot, - [true] if a value was physically written in the slot. *) Definition slot_data : Type := loc * state * bool. Implicit Types slots : gmap nat slot_data. Definition update_slot i f slots := match slots !! i with | Some d => <[i := f d]> (delete i slots) | None => slots end. Definition val_of (data : slot_data) : loc := match data with (l, _, _) => l end. Definition state_of (data : slot_data) : state := match data with (_, s, _) => s end. Definition name_of (data : slot_data) : option gname := match state_of data with Pend γ => Some γ | Help γ => Some γ | _ => None end. Definition was_written (data : slot_data) : bool := match data with (_, _, b) => b end. Definition was_committed (data : slot_data) : bool := match state_of data with Pend _ => false | _ => true end. Definition set_written (data : slot_data) : slot_data := match data with (l, s, _) => (l, s, true) end. Definition set_written_and_done (data : slot_data) : slot_data := match data with (l, _, _) => (l, Done, true) end. Definition to_helped (γ : gname) (data : slot_data) : slot_data := match data with (l, _, w) => (l, Help γ, w) end. Definition to_done (data : slot_data) : slot_data := match data with (l, _, w) => (l, Done, w) end. Definition physical_value (data : slot_data) : val := match data with (l, _, w) => if w then SOMEV #l else NONEV end. Lemma val_of_set_written d : val_of (set_written d) = val_of d. Proof. by destruct d as [[l s] w]. Qed. Lemma was_written_set_written d : was_written (set_written d) = true. Proof. by destruct d as [[l s] w]. Qed. Lemma state_of_set_written d : state_of (set_written d) = state_of d. Proof. by destruct d as [[l s] w]. Qed. Definition of_slot_data (data : slot_data) : per_slot := match data with | (l, s, w) => let name := match s with Pend γ => Excl' γ | Help γ => Excl' γ | Done => None end in let comm := if was_committed data then shot else not_shot in let wr := if w then shot else not_shot in (Excl' (), Some (to_agree l), name, comm, wr) end. Lemma of_slot_data_valid d : ✓ of_slot_data d. Proof. by destruct d as [[l []] []]. Qed. (* The (unique) token for slot [i]. *) Definition slot_token γs i := own γs (◯ {[i := (Excl' (), None, None, None, None)]} : slotUR). (* A witness that the location enqueued in slot [i] is [l]. *) Definition slot_val_wit γs i l := own γs (◯ {[i := (None, Some (to_agree l), None, None, None)]} : slotUR). (* A witness that the element inserted at slot [i] has been committed. *) Definition slot_committed_wit γs i := own γs (◯ {[i := (None, None, None, shot, None)]} : slotUR). Definition slot_name_tok γs i γ := own γs (◯ {[i := (None, None, Excl' γ, None, None)]} : slotUR). (* A witness that the element inserted at slot [i] has been written. *) Definition slot_written_wit γs i := own γs (◯ {[i := (None, None, None, None, shot)]} : slotUR). (* A token proving that the enqueue in slot [i] has not been commited. *) Definition slot_pending_tok γs i := own γs (◯ {[i := (None, None, None, not_shot, None)]} : slotUR). (* A token proving that no value has been written in slot [i]. *) Definition slot_writing_tok γs i := own γs (◯ {[i := (None, None, None, None, not_shot)]} : slotUR). (* Initial slot data, with not allocated slots. *) Lemma new_slots : ⊢ |==> ∃ γs, own γs (● ∅). Proof. iMod (own_alloc (● ∅ ⋅ ◯ ∅)) as (γs) "[H● _]". - by apply auth_both_valid_discrete. - iModIntro. iExists γs. iFrame. Qed. (* Allocate a new slot with data [d] at the fresh index [i]. *) Lemma alloc_slot γs slots (i : nat) (d : slot_data) : slots !! i = None → own γs (● (of_slot_data <$> slots) : slotUR) ==∗ own γs (● (of_slot_data <$> (<[i := d]> slots)) : slotUR) ∗ own γs (◯ {[i := of_slot_data d]} : slotUR). Proof. iIntros (Hi) "H". rewrite -own_op fmap_insert. iApply (own_update with "H"). apply auth_update_alloc. apply alloc_singleton_local_update. - by rewrite lookup_fmap Hi. - apply of_slot_data_valid. Qed. Lemma alloc_done_slot γs slots i l : slots !! i = None → own γs (● (of_slot_data <$> slots) : slotUR) ==∗ own γs (● (of_slot_data <$> (<[i := (l, Done, false)]> slots)) : slotUR) ∗ slot_token γs i ∗ slot_val_wit γs i l ∗ slot_committed_wit γs i ∗ slot_writing_tok γs i. Proof. iIntros (Hi) "H". iMod (alloc_slot _ _ _ _ Hi with "H") as "[$ Hi]". repeat rewrite -own_op. repeat rewrite -auth_frag_op. repeat rewrite -insert_op. repeat rewrite left_id. by rewrite insert_empty. Qed. Lemma alloc_pend_slot γs slots i l γ : slots !! i = None → own γs (● (of_slot_data <$> slots) : slotUR) ==∗ own γs (● (of_slot_data <$> (<[i := (l, Pend γ, false)]> slots)) : slotUR) ∗ slot_token γs i ∗ slot_val_wit γs i l ∗ slot_pending_tok γs i ∗ slot_name_tok γs i γ ∗ slot_writing_tok γs i. Proof. iIntros (Hi) "H". iMod (alloc_slot _ _ _ _ Hi with "H") as "[$ Hi]". repeat rewrite -own_op. repeat rewrite -auth_frag_op. repeat rewrite -insert_op. repeat rewrite left_id. by rewrite insert_empty. Qed. Lemma use_val_wit γs slots i l : own γs (● (of_slot_data <$> slots) : slotUR) -∗ slot_val_wit γs i l -∗ ⌜val_of <$> slots !! i = Some l⌝. Proof. iIntros "H● Hwit". iDestruct (own_valid_2 with "H● Hwit") as %H. iPureIntro. apply auth_both_valid_discrete in H as [H%singleton_included_l _]. destruct H as [ps (H1 & H2%option_included)]. rewrite lookup_fmap in H1. destruct (slots !! i) as [d|]; last by inversion H1. simpl in H1. inversion_clear H1. (* Ltac is a steaming pile of ***, so we cannot use [rename select] here. It infers the type of the [≡] too early and then fails to match the term. *) match goal with H: of_slot_data d ≡ ps |- _ => rename H into H1 end. destruct H2 as [H2|[a [b (H21 & H22 & H23)]]]; first done. simplify_eq. simpl. destruct b as [[[[b1 b2] b3] b4] b5]. destruct d as [[dl ds] dw]. destruct H1 as [[[[_ H1] _] _] _]; simpl in H1. simpl. f_equal. destruct H23 as [H2|H2]. - destruct H2 as [[[[_ H2] _] _] _]; simpl in H2. assert (Some (to_agree l) ≡ Some (to_agree dl)) as H by by transitivity b2. apply Some_equiv_inj, to_agree_inj in H. done. - apply prod_included in H2 as [H2 _]; simpl in H2. apply prod_included in H2 as [H2 _]; simpl in H2. apply prod_included in H2 as [H2 _]; simpl in H2. apply prod_included in H2 as [_ H2]; simpl in H2. assert (Some (to_agree l) ≼ Some (to_agree dl)) as H by set_solver. apply option_included in H. destruct H as [H|[a [b (H11 & H12 & H13)]]]; first done. simplify_eq. destruct H13 as [H|H]. + by apply to_agree_inj in H. + by apply to_agree_included in H. Qed. Lemma use_name_tok γs slots i γ : own γs (● (of_slot_data <$> slots) : slotUR) -∗ slot_name_tok γs i γ -∗ ⌜name_of <$> slots !! i = Some (Some γ)⌝. Proof. iIntros "H● Hwit". iDestruct (own_valid_2 with "H● Hwit") as %H. iPureIntro. apply auth_both_valid_discrete in H as [H%singleton_included_l _]. destruct H as [ps (H1 & H2%option_included)]. rewrite lookup_fmap in H1. destruct (slots !! i) as [d|]; last by inversion H1. simpl in H1. inversion_clear H1. (* Ltac is a steaming pile of ***, so we cannot use [rename select] here. It infers the type of the [≡] too early and then fails to match the term. *) match goal with H: of_slot_data d ≡ ps |- _ => rename H into H1 end. destruct H2 as [H2|[a [b (H21 & H22 & H23)]]]; first done. simplify_eq. simpl. destruct b as [[[[b1 b2] b3] b4] b5]. destruct d as [[dl ds] dw]. destruct H1 as [[[[_ _] H1] _] _]; simpl in H1. simpl. f_equal. destruct H23 as [H2|H2]. - destruct H2 as [[[[_ _] H2] _] _]; simpl in H2. destruct ds as [γ'|γ'|]; rewrite /name_of /=; try f_equal. + assert (Excl' γ ≡ Excl' γ') as H by by transitivity b3. inversion H as [x y HH|]. by inversion HH. + assert (Excl' γ ≡ Excl' γ') as H by by transitivity b3. inversion H as [x y HH|]. by inversion HH. + assert (Excl' γ ≡ None) as H by by transitivity b3. inversion H. - apply prod_included in H2 as [H2 _]; simpl in H2. apply prod_included in H2 as [H2 _]; simpl in H2. apply prod_included in H2 as [_ H2]; simpl in H2. destruct ds as [γ'|γ'|]; rewrite /name_of /=; try f_equal. + assert (Excl' γ ≼ Excl' γ') as H by set_solver. by apply Excl_included in H. + assert (Excl' γ ≼ Excl' γ') as H by set_solver. by apply Excl_included in H. + assert (Excl' γ ≼ None) as H by set_solver. exfalso. apply option_included in H as [H|H]; first done. destruct H as [a [b (H11 & H12 & H13)]]. by simplify_eq. Qed. Lemma shot_not_equiv_not_shot : shot ≢ not_shot. Proof. intros H. rewrite /shot /not_shot in H. inversion H as [x y HAbsurd|]. inversion HAbsurd. Qed. Lemma shot_not_equiv_not_shot' e : shot ≢ not_shot ⋅ e. Proof. intros H. rewrite /shot /not_shot in H. destruct e as [e|]; first destruct e. - rewrite -Some_op -Cinl_op in H. inversion H as [x y Habsurd|]; inversion Habsurd. - rewrite -Some_op in H. compute in H. inversion H as [x y HAbsurd|]. inversion HAbsurd. - inversion H as [x y HAbsurd|]. inversion HAbsurd. - inversion H as [x y HAbsurd|]. inversion HAbsurd. Qed. Lemma shot_not_included_not_shot : ¬ shot ≼ not_shot. Proof. intros H. rewrite /shot /not_shot in H. apply option_included in H. destruct H as [H|H]; first done. destruct H as [a [b (H1 & H2 & [H3|H3])]]. - simplify_eq. by inversion H3. - simplify_eq. apply csum_included in H3. destruct H3 as [H3|H3]; first done. destruct H3 as [H3|H3]. + destruct H3 as [a [b (H1 & H2 & H3)]]. by inversion H1. + destruct H3 as [a [b (H1 & H2 & H3)]]. by inversion H1. Qed. Lemma use_committed_wit γs slots i : own γs (● (of_slot_data <$> slots) : slotUR) -∗ slot_committed_wit γs i -∗ ⌜was_committed <$> slots !! i = Some true⌝. Proof. iIntros "H● Hwit". iDestruct (own_valid_2 with "H● Hwit") as %H. iPureIntro. apply auth_both_valid_discrete in H as [H%singleton_included_l _]. destruct H as [ps (H1 & H2%option_included)]. rewrite lookup_fmap in H1. destruct (slots !! i) as [d|]; last by inversion H1. simpl in H1. inversion_clear H1. (* Ltac is a steaming pile of ***, so we cannot use [rename select] here. It infers the type of the [≡] too early and then fails to match the term. *) match goal with H: of_slot_data d ≡ ps |- _ => rename H into H1 end. destruct H2 as [H2|[a [b (H21 & H22 & H23)]]]; first done. simplify_eq. simpl. destruct b as [[[[b1 b2] b3] b4] b5]. destruct d as [[dl ds] dw]. destruct H1 as [[[[_ _] _] H1]]; simpl in H1. f_equal. destruct (was_committed (dl, ds, dw)); first done. exfalso. destruct H23 as [H2|H2]. - destruct H2 as [[[[_ _] _] H2] _]; simpl in H2. apply shot_not_equiv_not_shot. set_solver. - apply prod_included in H2 as [H2 _]; simpl in H2. apply prod_included in H2 as [_ H2]; simpl in H2. apply shot_not_included_not_shot. set_solver. Qed. Lemma use_written_wit γs slots i : own γs (● (of_slot_data <$> slots) : slotUR) -∗ slot_written_wit γs i -∗ ⌜was_written <$> slots !! i = Some true⌝. Proof. iIntros "H● Hwit". iDestruct (own_valid_2 with "H● Hwit") as %H. iPureIntro. apply auth_both_valid_discrete in H as [H%singleton_included_l _]. destruct H as [ps (H1 & H2%option_included)]. rewrite lookup_fmap in H1. destruct (slots !! i) as [d|]; last by inversion H1. simpl in H1. inversion_clear H1. (* Ltac is a steaming pile of ***, so we cannot use [rename select] here. It infers the type of the [≡] too early and then fails to match the term. *) match goal with H: of_slot_data d ≡ ps |- _ => rename H into H1 end. destruct H2 as [H2|[a [b (H21 & H22 & H23)]]]; first done. simplify_eq. simpl. destruct b as [[[[b1 b2] b3] b4] b5]. destruct d as [[dl ds] dw]. destruct H1 as [[[[_ _] _] _] H1]; simpl in H1. f_equal. destruct dw; first done. exfalso. destruct H23 as [H2|H2]. - destruct H2 as [[[[_ _] _] _] H2]; simpl in H2. exfalso. apply shot_not_equiv_not_shot. set_solver. - apply prod_included in H2 as [_ H2]; simpl in H2. exfalso. apply shot_not_included_not_shot. set_solver. Qed. Lemma use_writing_tok γs i slots : own γs (● (of_slot_data <$> slots) : slotUR) -∗ slot_writing_tok γs i ==∗ own γs (● (of_slot_data <$> update_slot i set_written slots) : slotUR) ∗ slot_written_wit γs i. Proof. iIntros "Hs● Htok". iCombine "Hs● Htok" as "H". rewrite -own_op. iDestruct (own_valid with "H") as %Hvalid. iApply (own_update with "H"). apply auth_both_valid_discrete in Hvalid as [H1 H2]. apply singleton_included_l in H1 as [e (H1_1 & H1_2)]. rewrite lookup_fmap in H1_1. destruct (slots !! i) as [[[l s] w]|] eqn:Hi; last by inversion H1_1. apply Some_equiv_inj in H1_1. assert (w = false) as ->. { destruct w; [ exfalso | done ]. apply Some_included in H1_2 as [H1_2|H1_2]. - assert ((None, None, None, None, not_shot) ≡ of_slot_data (l, s, true)) as Hequiv by by transitivity e. destruct Hequiv as [[[[_ _] _] _] Hequiv]; simpl in Hequiv. by apply shot_not_equiv_not_shot. - destruct H1_2 as [f H1_2]. assert ((None, None, None, None, not_shot) ⋅ f ≡ of_slot_data (l, s, true)) as Hequiv by by transitivity e. destruct Hequiv as [[[[_ _] _] _] Hequiv]; simpl in Hequiv. by eapply shot_not_equiv_not_shot'. } rewrite /update_slot Hi insert_delete_insert fmap_insert. apply auth_update. eapply (singleton_local_update _ i). { by rewrite lookup_fmap Hi. } rewrite /set_written. apply prod_local_update; first done. simpl. by apply option_local_update, exclusive_local_update. Qed. Lemma writing_tok_not_written γs slots i : own γs (● (of_slot_data <$> slots) : slotUR) -∗ slot_writing_tok γs i -∗ ⌜was_written <$> slots !! i = Some false⌝. Proof. iIntros "Hs● Htok". iCombine "Hs● Htok" as "H". iDestruct (own_valid with "H") as %Hvalid%auth_both_valid_discrete. iPureIntro. destruct Hvalid as [H1 H2]. apply singleton_included_l in H1 as [e (H1_1 & H1_2)]. rewrite lookup_fmap in H1_1. destruct (slots !! i) as [[[l s] w]|]; last by inversion H1_1. apply Some_equiv_inj in H1_1. simpl. f_equal. destruct w; last done. exfalso. apply Some_included in H1_2 as [H1_2|H1_2]. - assert ((None, None, None, None, not_shot) ≡ of_slot_data (l, s, true)) as Hequiv by by transitivity e. destruct Hequiv as [[[[_ _] _] _] Hequiv]; simpl in Hequiv. by apply shot_not_equiv_not_shot. - destruct H1_2 as [f H1_2]. assert ((None, None, None, None, not_shot) ⋅ f ≡ of_slot_data (l, s, true)) as Hequiv by by transitivity e. destruct Hequiv as [[[[_ _] _] _] Hequiv]; simpl in Hequiv. by eapply shot_not_equiv_not_shot'. Qed. Lemma None_op {A : cmra} : (None : optionUR A) ⋅ None = None. Proof. done. Qed. Lemma use_pending_tok γs i γ slots : state_of <$> slots !! i = Some (Pend γ) → own γs (● (of_slot_data <$> slots) : slotUR) -∗ slot_pending_tok γs i ==∗ own γs (● (of_slot_data <$> update_slot i (to_helped γ) slots) : slotUR) ∗ slot_committed_wit γs i. Proof. iIntros (Hlookup) "Hs● Htok". iCombine "Hs● Htok" as "H". rewrite -own_op. iDestruct (own_valid with "H") as %Hvalid. iApply (own_update with "H"). apply auth_both_valid_discrete in Hvalid as [H1 H2]. apply singleton_included_l in H1 as [e (H1_1 & H1_2)]. rewrite lookup_fmap in H1_1. destruct (slots !! i) as [[[l s] w]|] eqn:Hi; last by inversion H1_1. simpl in Hlookup. inversion Hlookup; subst s. rewrite /update_slot Hi insert_delete_insert fmap_insert. apply auth_update. repeat rewrite pair_op. eapply (singleton_local_update _ i). { by rewrite lookup_fmap Hi. } rewrite /to_helped. repeat rewrite None_op. repeat apply prod_local_update; try done. by apply option_local_update, exclusive_local_update. Qed. Lemma slot_token_exclusive γs i : slot_token γs i -∗ slot_token γs i -∗ False. Proof. iIntros "H1 H2". iCombine "H1 H2" as "H". iDestruct (own_valid with "H") as %H. iPureIntro. move:H =>/auth_frag_valid H. apply singleton_valid in H. by repeat apply pair_valid in H as [H _]; simpl in H. Qed. Lemma helped_to_done_aux γs i γ slots : state_of <$> slots !! i = Some (Help γ) → own γs (● (of_slot_data <$> slots) : slotUR) -∗ slot_name_tok γs i γ ==∗ own γs (● (of_slot_data <$> update_slot i to_done slots) : slotUR) ∗ own γs (◯ {[i := (None, None, None, None, None)]} : slotUR). Proof. iIntros (H) "H1 H2". iCombine "H1 H2" as "H". iDestruct (own_valid with "H") as %Hvalid. rewrite -own_op. iApply (own_update with "H"). apply auth_update. rewrite /update_slot. destruct (slots !! i) as [d|] eqn:Hd; last by inversion H. rewrite insert_delete_insert fmap_insert. eapply singleton_local_update. { by rewrite lookup_fmap Hd /=. } destruct d as [[dl ds] dw]. inversion H; subst ds; simpl. repeat apply prod_local_update; try done. simpl. apply delete_option_local_update. apply _. Qed. Lemma helped_to_done γs i γ slots : state_of <$> slots !! i = Some (Help γ) → own γs (● (of_slot_data <$> slots) : slotUR) -∗ slot_name_tok γs i γ ==∗ own γs (● (of_slot_data <$> update_slot i to_done slots) : slotUR). Proof. iIntros (H) "H1 H2". by iMod (helped_to_done_aux with "H1 H2") as "[H _]". Qed. Lemma val_wit_from_auth γs i l slots : val_of <$> slots !! i = Some l → own γs (● (of_slot_data <$> slots) : slotUR) ==∗ own γs (● (of_slot_data <$> slots) : slotUR) ∗ slot_val_wit γs i l. Proof. iIntros (H) "H". rewrite -own_op. iApply (own_update with "H"). apply auth_update_dfrac_alloc; first apply _. assert (∃ d, slots !! i = Some d) as [d Hlookup]. { destruct (slots !! i) as [d|]; inversion H. by exists d. } apply singleton_included_l. rewrite lookup_fmap. rewrite Hlookup /=. exists (of_slot_data d). split; first done. apply Some_included. right. destruct d as [[dl ds] dw]. simpl. repeat (apply prod_included; split; simpl); try by (apply option_included; left). apply option_included; right. exists (to_agree l), (to_agree dl). repeat (split; first done). left. rewrite Hlookup /= in H. by inversion H. Qed. (** * Prophecy abstractions *************************************************) Fixpoint proph_data sz (deq : gset nat) (rs : list (val * val)) : list nat := match rs with | (PairV _ #true , LitV (LitInt i)) :: rs => if decide (0 ≤ i < sz)%Z then let i := Z.to_nat i in if decide (i ∈ deq) then [] else i :: proph_data sz ({[i]} ∪ deq) rs else [] | (PairV _ #false, LitV (LitInt i)) :: rs => if decide (0 ≤ i < sz)%Z then proph_data sz deq rs else [] | _ => [] end. (* Wrapper for the Iris [proph] proposition, using our data abstraction. *) Definition hwq_proph p sz deq pvs := (∃ rs, proph p rs ∗ ⌜pvs = proph_data sz deq rs⌝)%I. Lemma proph_data_deq sz deq rs : ∀ i, i ∈ deq → i ∉ proph_data sz deq rs. Proof. revert deq. induction rs as [|[b k] rs IH]; intros deq i Hi. - apply not_elem_of_nil. - destruct b as [| |b1 b2| |]; simpl; try by apply not_elem_of_nil. destruct b2 as [lit| | | |]; simpl; try by apply not_elem_of_nil. destruct lit as [|b| | | |]; simpl; try by apply not_elem_of_nil. destruct b. + destruct k as [lit | | | |]; simpl; try by apply not_elem_of_nil. destruct lit as [n| | | | |]; simpl; try by apply not_elem_of_nil. destruct (decide (0 ≤ n < sz)%Z); last by apply not_elem_of_nil. destruct (decide (Z.to_nat n ∈ deq)); first by apply not_elem_of_nil. apply not_elem_of_cons. split; first by set_solver. apply IH. set_solver. + destruct k as [lit | | | |]; simpl; try by apply not_elem_of_nil. destruct lit as [n| | | | |]; simpl; try by apply not_elem_of_nil. destruct (decide (0 ≤ n < sz)%Z); last by apply not_elem_of_nil. apply IH. done. Qed. Lemma proph_data_sz sz deq rs : ∀ i, i ∈ proph_data sz deq rs → i < sz. Proof. revert deq. induction rs as [|[b k] rs IH]; intros deq i Hi. - set_solver. - destruct b as [| |b1 b2| |]; simpl; try by set_solver. destruct b2 as [lit| | | |]; simpl; try by set_solver. destruct lit as [|b| | | |]; simpl; try by set_solver. destruct b. + destruct k as [lit | | | |]; simpl; try by set_solver. destruct lit as [n| | | | |]; simpl; try by set_solver. simpl in Hi. destruct (decide (0 ≤ n < sz)%Z) as [Hn|Hn]; last by set_solver. destruct (decide (Z.to_nat n ∈ deq)) as [H|H]; first by set_solver. apply elem_of_cons in Hi. destruct Hi as [->|Hi]. * apply Nat2Z.inj_lt. destruct Hn as [Hn1 Hn2]. by rewrite Z2Nat.id. * by apply (IH _ _ Hi). + destruct k as [lit | | | |]; simpl; try by set_solver. destruct lit as [n| | | | |]; simpl; try by set_solver. simpl in Hi. destruct (decide (0 ≤ n < sz)%Z); last by set_solver. apply (IH _ _ Hi). Qed. Lemma proph_data_NoDup sz deq rs : NoDup (proph_data sz deq rs ++ elements deq). Proof. revert deq. induction rs as [|[b k] rs IH]; intros deq. - apply NoDup_elements. - destruct b as [| |b1 b2| |]; simpl; try by apply NoDup_elements. destruct b2 as [lit| | | |]; simpl; try by apply NoDup_elements. destruct lit as [|b| | | |]; simpl; try by apply NoDup_elements. destruct b. + destruct k as [lit| | | |]; simpl; try by apply NoDup_elements. destruct lit as [n| | | | |]; simpl; try by apply NoDup_elements. destruct (decide (0 ≤ n < sz)%Z) as [Hn|Hn]; last by apply NoDup_elements. destruct (decide (Z.to_nat n ∈ deq)) as [Hn_in_deq|Hn_not_in_deq]; first by apply NoDup_elements. specialize (IH ({[Z.to_nat n]} ∪ deq)) as H1. assert (Z.to_nat n ∉ proph_data sz ({[Z.to_nat n]} ∪ deq) rs) as H2. { apply proph_data_deq. by set_solver. } apply NoDup_app in H1 as (H1_1 & H1_2 & H1_3). apply NoDup_app. repeat split_and. * by apply NoDup_cons. * intros i Hi. apply elem_of_cons in Hi as [Hi|Hi]; first by set_solver. intros H_elements%elem_of_elements. eapply (proph_data_deq sz ({[Z.to_nat n]} ∪ deq) rs i); by set_solver. * by apply NoDup_elements. + destruct k as [lit| | | |]; simpl; try by apply NoDup_elements. destruct lit as [n| | | | |]; simpl; try by apply NoDup_elements. destruct (decide (0 ≤ n < sz)%Z); [ by apply IH | by apply NoDup_elements ]. Qed. Definition block : Type := nat * list nat. Definition blocks : Type := list block. (* A block is valid if it follows the structure described above. *) Definition block_valid slots (b : block) := slots !! b.1 = None ∧ ∀ i, i ∈ b.2 → was_committed <$> (slots !! i) = Some false. Fixpoint glue_blocks (b : block) (i : nat) (bs : blocks) : blocks := match bs with | [] => [b] | (j, pends) :: bs => if decide (i = j) then (b.1, b.2 ++ i :: pends) :: bs else b :: glue_blocks (j, pends) i bs end. Fixpoint flatten_blocks bs : list nat := match bs with | [] => [] | (i, pends) :: bs => i :: pends ++ flatten_blocks bs end. Lemma blocks_elem1 b blocks : b ∈ blocks → b.1 ∈ flatten_blocks blocks. Proof. intros H. induction blocks as [|b' blocks IH]; first by inversion H. destruct (decide (b' = b)) as [->|Hb_not_b']. - destruct b as [b_u b_ps]. by apply elem_of_list_here. - destruct b' as [b'_u b'_bs]. simpl. apply elem_of_list_further. apply elem_of_app; right. apply IH. apply elem_of_cons in H as [H|H]; last done. by rewrite H in Hb_not_b'. Qed. Lemma blocks_elem2 b blocks : b ∈ blocks → ∀ i, i ∈ b.2 → i ∈ flatten_blocks blocks. Proof. intros H. induction blocks as [|b' blocks IH]; first by inversion H. destruct (decide (b' = b)) as [->|Hb_not_b']. - destruct b as [b_u b_ps]. intros i Hi. simpl in *. apply elem_of_list_further. apply elem_of_app. by left. - destruct b' as [b'_u b'_bs]. simpl. intros i Hi. apply elem_of_list_further. apply elem_of_app; right. apply IH; last done. apply elem_of_cons in H as [H|H]; last done. by rewrite H in Hb_not_b'. Qed. Lemma glue_blocks_valid slots i b_unused b_pendings blocks l γ : slots !! i = None → b_unused ≠ i → NoDup (b_unused :: b_pendings ++ flatten_blocks blocks) → (∀ b : block, b ∈ (b_unused, b_pendings) :: blocks → block_valid slots b) → ∀ b, b ∈ glue_blocks (b_unused, b_pendings) i blocks → block_valid (<[i:=(l, Pend γ, false)]> slots) b. Proof using Type*. intros Hi. revert b_unused b_pendings. induction blocks as [|[b_u b_ps] blocks IH]; intros b_unused b_pendings Hb_unused_not_i HND Hblocks_valid [b_u' b_ps'] Hb. - apply Hblocks_valid in Hb as Hvalid. apply elem_of_list_singleton in Hb. simplify_eq. destruct Hvalid as (Hvalid1 & Hvalid2). split. + by rewrite lookup_insert_ne. + simpl in *. intros k Hk. specialize (Hvalid2 _ Hk) as Hvalid_k. destruct (decide (k = i)) as [->|Hk_not_i]. * by rewrite lookup_insert. * by rewrite lookup_insert_ne. - simpl in Hb. destruct (decide (i = b_u)) as [->|Hi_not_b_u]. + apply elem_of_cons in Hb as [Hb|Hb]. * simplify_eq. assert ((b_unused, b_pendings) ∈ (b_unused, b_pendings) :: (b_u, b_ps) :: blocks) as Hvalid%Hblocks_valid by set_solver. destruct Hvalid as (Hvalid1 & Hvalid2). assert ((b_u, b_ps) ∈ (b_unused, b_pendings) :: (b_u, b_ps) :: blocks) as Hvalid'%Hblocks_valid by set_solver. destruct Hvalid' as (Hvalid1' & Hvalid2'). split; simpl. ** by rewrite lookup_insert_ne. ** intros k Hk. apply elem_of_app in Hk as [Hk|Hk]. *** assert (k ≠ b_u) as HNEq2. { apply NoDup_cons in HND as (_ & HND). apply NoDup_app in HND as (_ & HND & _). apply HND in Hk. simpl in Hk. by apply not_elem_of_cons in Hk as (Hk & _). } rewrite lookup_insert_ne; last done. by apply Hvalid2. *** apply elem_of_cons in Hk as [->|Hk]; first by rewrite lookup_insert. assert (b_u ≠ k) as HNEq2. { apply NoDup_cons in HND as (_ & HND). apply NoDup_app in HND as (_ & _ & HND). simpl in HND. apply NoDup_cons in HND as (HND & _). apply not_elem_of_app in HND as (HND & _). intros ->. apply HND, Hk. } rewrite lookup_insert_ne; last done. by apply Hvalid2'. * assert ((b_u', b_ps') ∈ (b_unused, b_pendings) :: (b_u, b_ps) :: blocks) as Hvalid%Hblocks_valid by set_solver. destruct Hvalid as (Hvalid1 & Hvalid2). rewrite /block_valid. assert (b_u ≠ b_u') as HNeq1. { apply NoDup_cons in HND as (_ & HND). apply NoDup_app in HND as (_ & _ & HND). simpl in HND. apply NoDup_cons in HND as (HND & _). intros <-. apply not_elem_of_app in HND as (_ & HND). apply HND. by apply blocks_elem1 in Hb. } rewrite lookup_insert_ne; last done. split; first done. intros k Hk. simpl in Hk. assert (b_u ≠ k) as HNeq2. { apply NoDup_cons in HND as (_ & HND). apply NoDup_app in HND as (_ & _ & HND). simpl in HND. apply NoDup_cons in HND as (HND & _). intros <-. apply not_elem_of_app in HND as (_ & HND). apply HND. by eapply blocks_elem2 in Hb. } rewrite lookup_insert_ne; last done. by apply Hvalid2. + apply elem_of_cons in Hb as [Hb|Hb]. * simplify_eq. assert ((b_unused, b_pendings) ∈ (b_unused, b_pendings) :: (b_u, b_ps) :: blocks) as Hvalid%Hblocks_valid by set_solver. destruct Hvalid as (Hvalid1 & Hvalid2). split. ** by rewrite lookup_insert_ne. ** intros k Hk. simpl in *. assert (k ≠ i) as HNEq. { intros ->. apply Hvalid2 in Hk. rewrite Hi in Hk. by inversion Hk. } rewrite lookup_insert_ne; last done. by apply Hvalid2. * eapply IH; last done; first done. { apply NoDup_cons in HND as (_ & HND). by apply NoDup_app in HND as (_ & _ & HND). } intros b' Hb'. assert (b' ∈ (b_unused, b_pendings) :: (b_u, b_ps) :: blocks) as Hb'_valid%Hblocks_valid by set_solver. done. Qed. (* Contradiction status: either there is a contradiction going on with the given indices, or there is no contradiction. In the latter case the prophecy has well-formed pending blocks as a suffix. *) Inductive cont_status := | WithCont : nat → nat → cont_status | NoCont : blocks → cont_status. Global Instance cont_status_inhabited : Inhabited cont_status. Proof. constructor. refine (NoCont []). Qed. Lemma initial_block_valid b pvs : b ∈ map (λ i : nat, (i, [])) pvs → block_valid ∅ b. Proof. intros H. induction pvs as [|i pvs IH]. - by inversion H. - simpl in H. apply elem_of_cons in H as [->|H]. + split; first by apply lookup_empty. intros k Hk. by inversion Hk. + apply IH, H. Qed. Lemma flatten_blocks_initial pvs : pvs = flatten_blocks (map (λ i : nat, (i, [])) pvs). Proof. induction pvs as [|i pvs IH]; first done. simpl. f_equal. by apply IH. Qed. Lemma flatten_blocks_glue b bs i : flatten_blocks (b :: bs) = flatten_blocks (glue_blocks b i bs). Proof. revert b. induction bs as [|[b_u' b_ps'] bs IH]; intros [b_u b_ps]; first done. simpl. destruct (decide (i = b_u')) as [->|HNEq]; simpl. - by rewrite -app_assoc. - by rewrite -IH. Qed. Lemma flatten_blocks_mem1 blocks : ∀b, b ∈ blocks → b.1 ∈ flatten_blocks blocks. Proof. intros b Hb. induction blocks as [|[i ps] bs IH]; first by inversion Hb. apply elem_of_cons in Hb as [->|Hb]; first by apply elem_of_list_here. simpl. apply elem_of_list_further. apply elem_of_app. right. by apply IH. Qed. Lemma flatten_blocks_mem2 blocks : ∀b, b ∈ blocks → ∀i, i ∈ b.2 → i ∈ flatten_blocks blocks. Proof. intros b Hb. induction blocks as [|[i ps] bs IH]; first by inversion Hb. intros k Hk. apply elem_of_cons in Hb as [->|Hb]; simpl. - apply elem_of_list_further. apply elem_of_app. by left. - apply elem_of_list_further. apply elem_of_app. right. by apply IH. Qed. (** * Some definitions and lemmas about array content manipulation **********) Definition array_get slots (deqs : gset nat) i := match slots !! i with | None => NONEV | Some d => if decide (i ∈ deqs) then NONEV else physical_value d end. Fixpoint array_content n slots deqs := match n with | 0 => [] | S n => array_content n slots deqs ++ [array_get slots deqs n] end. Lemma length_array_content sz slots deqs : length (array_content sz slots deqs) = sz. Proof. induction sz as [|sz IH]; first done. by rewrite /= app_length plus_comm /= IH. Qed. Lemma array_content_lookup sz slots deqs i : i < sz → array_content sz slots deqs !! i = Some (array_get slots deqs i). Proof. intros H. induction sz as [|sz IH]; first lia. destruct (decide (i = sz)) as [->|Hi_not_sz]; simpl. - rewrite lookup_app_r length_array_content; last done. by rewrite Nat.sub_diag /=. - rewrite lookup_app_l; first (apply IH; by lia). rewrite length_array_content. lia. Qed. Lemma array_content_empty sz : array_content sz ∅ ∅ = replicate sz NONEV. Proof. induction sz as [|sz IH]; first done. rewrite replicate_S_end /= IH. done. Qed. Lemma array_content_NONEV sz i d slots deqs : physical_value d = NONEV → slots !! i = None → i ∉ deqs → array_content sz (<[i:=d]> slots) deqs = array_content sz slots deqs. Proof. intros H1 H2 H3. induction sz as [|sz IH]; first done. rewrite /= /array_get. destruct (decide (i = sz)) as [->|Hi_not_sz]. - rewrite lookup_insert H2 decide_False; last done. by rewrite IH H1. - rewrite lookup_insert_ne; last done. by rewrite IH. Qed. Lemma array_content_is_Some sz i slots deqs : i < sz → is_Some (array_content sz slots deqs !! i). Proof. intros H. apply lookup_lt_is_Some. by rewrite length_array_content. Qed. Lemma array_content_ext sz slots1 slots2 deqs : (∀ i, i < sz → array_get slots1 deqs i = array_get slots2 deqs i) → array_content sz slots1 deqs = array_content sz slots2 deqs. Proof. induction sz as [|sz IH]; intros H; first done. simpl. rewrite H; last by lia. f_equal. apply IH. intros i Hi. apply H. by lia. Qed. Lemma array_content_more_deqs sz slots deqs i : sz ≤ i → array_content sz slots ({[i]} ∪ deqs) = array_content sz slots deqs. Proof. intros H. induction sz as [|sz IH]; first done. rewrite /= IH; last by lia. f_equal. rewrite /array_get. destruct (slots !! sz) as [d|]; last done. destruct (decide (sz ∈ deqs)) as [Helem|Hnot_elem]. - rewrite decide_True; [ done | by set_solver ]. - rewrite decide_False; [ done | .. ]. apply not_elem_of_union. split; last done. apply not_elem_of_singleton. by lia. Qed. Lemma array_content_update_slot_ge sz slots deqs f i : sz ≤ i → array_content sz slots deqs = array_content sz (update_slot i f slots) deqs. Proof. intros H. induction sz as [|sz IH]; first done. rewrite /= IH; last by lia. f_equal. rewrite /array_get /update_slot. destruct (slots !! i) as [d|]; last done. rewrite insert_delete_insert. rewrite lookup_insert_ne; [ done | by lia ]. Qed. Lemma array_content_dequeue sz i slots deqs : i < sz → i ∉ deqs → array_content sz slots ({[i]} ∪ deqs) = <[i:=NONEV]> (array_content sz slots deqs). Proof using Type*. revert i. induction sz as [|sz IH]; intros i H1 H2; first done. destruct (decide (sz = i)) as [->|Hsz_not_i]; simpl. - assert (i = length (array_content i slots deqs) + 0) as HEq. { rewrite length_array_content. by lia. } rewrite [X in <[X:=_]> _]HEq. rewrite (insert_app_r (array_content i slots deqs) _ 0 NONEV). rewrite /= /array_get. destruct (slots !! i) as [d|]. + rewrite decide_True; last by set_solver. f_equal. rewrite array_content_more_deqs; [ done | by lia ]. + f_equal. rewrite array_content_more_deqs; [ done | by lia ]. - rewrite insert_app_l; last (rewrite length_array_content; by lia). rewrite IH; [ .. | by lia | done ]. f_equal. rewrite /array_get. destruct (slots !! sz) as [d|]; last done. destruct (decide (sz ∈ deqs)) as [H|H]. * rewrite decide_True; [ done | by set_solver ]. * rewrite decide_False; [ done | by set_solver ]. Qed. Lemma array_content_set_written sz i (l : loc) slots deqs : i < sz → val_of <$> slots !! i = Some l → ¬ i ∈ deqs → <[i:=InjRV #l]> (array_content sz slots deqs) = array_content sz (update_slot i set_written slots) deqs. Proof using Type*. revert i. induction sz as [|sz IH]; intros i H1 H2 H3; first done. destruct (decide (sz = i)) as [->|Hsz_not_i]; simpl. - assert (i = length (array_content i slots deqs) + 0) as HEq. { rewrite length_array_content. by lia. } rewrite [X in <[X:=_]> _]HEq. rewrite (insert_app_r (array_content i slots deqs) _ 0). erewrite array_content_update_slot_ge; [ f_equal | by lia ]. rewrite /= /array_get /update_slot. destruct (slots !! i) as [d|]. + rewrite lookup_insert decide_False; last done. destruct d as [[ld sd] wd]. inversion H2; subst ld. done. + inversion H2. - rewrite insert_app_l; last (rewrite length_array_content; by lia). rewrite IH; [ .. | by lia | done | done ]. f_equal. rewrite /array_get /update_slot. destruct (slots !! i) as [d|]; last done. by rewrite insert_delete_insert lookup_insert_ne. Qed. (* FIXME similar to previous lemma. Share stuff? *) Lemma array_content_set_written_and_done sz i (l : loc) slots deqs : i < sz → val_of <$> slots !! i = Some l → ¬ i ∈ deqs → <[i:=InjRV #l]> (array_content sz slots deqs) = array_content sz (update_slot i set_written_and_done slots) deqs. Proof. revert i. induction sz as [|sz IH]; intros i H1 H2 H3; first done. destruct (decide (sz = i)) as [->|Hsz_not_i]; simpl. - assert (i = length (array_content i slots deqs) + 0) as HEq. { rewrite length_array_content. by lia. } rewrite [X in <[X:=_]> _]HEq. rewrite (insert_app_r (array_content i slots deqs) _ 0). erewrite array_content_update_slot_ge; [ f_equal | by lia ]. rewrite /= /array_get /update_slot. destruct (slots !! i) as [d|]. + rewrite lookup_insert decide_False; last done. destruct d as [[ld sd] wd]. inversion H2; subst ld. done. + inversion H2. - rewrite insert_app_l; last (rewrite length_array_content; by lia). rewrite IH; [ .. | by lia | done | done ]. f_equal. rewrite /array_get /update_slot. destruct (slots !! i) as [d|]; last done. by rewrite insert_delete_insert lookup_insert_ne. Qed. Lemma update_slot_lookup i f slots : update_slot i f slots !! i = f <$> slots !! i. Proof. rewrite /update_slot. destruct (slots !! i) as [d|] eqn:HEq; last done. by rewrite lookup_insert. Qed. Lemma update_slot_lookup_ne i k f slots : i ≠ k → update_slot i f slots !! k = slots !! k. Proof. intros H. rewrite /update_slot. destruct (slots !! i) as [d|] eqn:HEq; last done. rewrite lookup_insert_ne; last done. by rewrite lookup_delete_ne. Qed. Lemma update_slot_update_slot i f g slots : update_slot i f (update_slot i g slots) = update_slot i (f ∘ g) slots. Proof. rewrite /update_slot. destruct (slots !! i) as [d|] eqn:HEq. - rewrite lookup_insert. repeat rewrite insert_delete_insert. rewrite insert_insert. done. - rewrite HEq. done. Qed. Definition get_value slots (deqs : gset nat) i : loc := match slots !! i with | None => inhabitant | Some d => val_of d end. Definition map_get_value_not_in_pref i d pref slots deqs : was_written d = false → i ∉ pref → map (get_value (<[i:=d]> slots) deqs) pref = map (get_value slots deqs) pref. Proof. intros Hd. induction pref as [|k pref IH]; intros Hi; first done. rewrite /= IH; last by set_solver. f_equal. rewrite /get_value. rewrite lookup_insert_ne; first done. set_solver. Qed. (** * Definition of the main ************************************************) (** Atomic update for the insertion of [l], with post-condition [Q]. *) Definition enqueue_AU γe l Q := (AU << ∀ ls : list loc, hwq_cont γe ls >> @ ⊤ ∖ ↑N, ∅ << hwq_cont γe (ls ++ [l]), COMM Q >>)%I. (* When a contradiction is going on, we have [cont = WithCont i1 i2] where: - [i1] is the index reserved by the enqueue operation the initiated the contradiction, - [i2] is the first index in the prophecy that was not yet reserved for an enqueue operation (when the contradiction was initiated). *) Definition per_slot_own γe γs i d := (slot_val_wit γs i (val_of d) ∗ (if was_written d then slot_written_wit γs i else True) ∗ match state_of d with | Pend γ => slot_pending_tok γs i ∗ ∃ Q, saved_prop_own γ Q ∗ enqueue_AU γe (val_of d) Q | Help γ => slot_committed_wit γs i ∗ ∃ Q, saved_prop_own γ Q ∗ ▷ Q | Done => slot_committed_wit γs i ∗ slot_token γs i end)%I. Definition inv_hwq sz γb γi γe γc γs ℓ_ar ℓ_back p : iProp := (∃ (back : nat) (** Physical value of [q.back]. *) (pvs : list nat) (** Full contents of the prophecy. *) (pref : list nat) (** Commit prefix of the prophecy *) (rest : list loc) (** Logical queue after commit prefix. *) (cont : cont_status) (** Contradiction or prophecy suffix. *) (slots : gmap nat slot_data) (** Per-slot data for used indices. *) (deqs : gset nat), (** Dequeued indices. *) (** Physical data. *) ℓ_back ↦ #back ∗ ℓ_ar ↦∗ (array_content sz slots deqs) ∗ (** Logical contents of the queue and prophecy contents. *) back_value γb back ∗ i2_lower_bound γi (match cont with WithCont _ i2 => i2 | NoCont _ => back `min` sz end) ∗ own γe (● (Excl' (map (get_value slots deqs) pref ++ rest))) ∗ own γs (● (of_slot_data <$> slots : gmap nat per_slot)) ∗ hwq_proph p sz deqs pvs ∗ (** Per-slot ownership. *) ([∗ map] i ↦ d ∈ slots, per_slot_own γe γs i d) ∗ (** Contradiction status. *) match cont with NoCont _ => no_contra γc | WithCont i1 i2 => contra γc i1 i2 end ∗ (** Tying the logical and physical data and some other pure stuff. *) ⌜(∀ i, (i < back `min` sz) ↔ is_Some (slots !! i)) ∧ (∀ i, (was_committed <$> slots !! i = Some false → was_written <$> slots !! i = Some false) ∧ (was_written <$> slots !! i = Some false → i ∉ deqs)) ∧ (∀ i, i ∈ pref → was_committed <$> slots !! i = Some true ∧ i ∉ deqs ∧ match cont with WithCont i1 _ => i ≠ i1 | _ => True end) ∧ (∀ i, i ∈ deqs → was_written <$> slots !! i = Some true ∧ was_committed <$> slots !! i = Some true ∧ array_get slots deqs i = NONEV) ∧ (NoDup (pvs ++ elements deqs) ∧ ∀ i, i ∈ pvs → i < sz) ∧ match cont with | NoCont bs => (∀ b, b ∈ bs → block_valid slots b) ∧ (bs ≠ [] → rest = []) ∧ pvs = pref ++ flatten_blocks bs | WithCont i1 i2 => (i1 < i2 < sz ∧ i1 < back) ∧ was_committed <$> slots !! i1 = Some true ∧ was_written <$> slots !! i1 = Some true ∧ ¬ i1 ∈ deqs ∧ array_get slots deqs i1 ≠ NONEV ∧ pref ++ [i2] `prefix_of` pvs end⌝)%I. Definition is_hwq sz γe v : iProp := (∃ γb γi γc γs ℓ_ar ℓ_back p, ⌜v = (#sz, #ℓ_ar, #ℓ_back, #p)%V⌝ ∗ inv N (inv_hwq sz γb γi γe γc γs ℓ_ar ℓ_back p))%I. (** * Some useful instances *************************************************) Instance blocks_match_persistent (bs : blocks) γc i1 : Persistent (match bs with | [] => True | (i2, _) :: _ => contra γc i1 i2 end)%I. Proof. destruct bs as [|[i2 _] _]; apply _. Qed. Instance cont_match_persistent cont γc : Persistent (match cont with | NoCont _ => True | WithCont i1 i2 => contra γc i1 i2 end)%I. Proof. destruct cont as [i1 i2|_]; apply _. Qed. Instance contra_timeless cont γc : Timeless (match cont with | NoCont _ => no_contra γc | WithCont i1 i2 => contra γc i1 i2 end). Proof. destruct cont as [i1 i2|_]; apply _. Qed. (** * Some important lemmas for the specification of [enqueue] **************) Definition get_values (slots : gmap nat slot_data) (p : list nat) := fold_right (λ i acc, match val_of <$> slots !! i with | None => acc | Some l => l :: acc end) [] p. Definition get_values_not_in n ps d s : n ∉ ps → get_values (<[n:=d]> s) ps = get_values s ps. Proof. intros H. induction ps as [|p ps IH]; first done. simpl. assert (n ≠ p) as Hn_not_p by set_solver. rewrite lookup_insert_ne; last done. rewrite IH; first done. set_solver. Qed. Definition helped (p : list nat) (i : nat) d := match state_of d with | Pend γ => if decide (i ∈ p) then Some (val_of d, Help γ, was_written d) else Some d | _ => Some d end. Lemma is_Some_helped (p : list nat) i d : is_Some (helped p i d). Proof. rewrite /helped. destruct (state_of d); try by eexists. destruct (decide (i ∈ p)); by eexists. Qed. Lemma map_imap_helped_nil slots : map_imap (helped []) slots = slots. Proof. apply map_eq. intros i. rewrite map_lookup_imap. destruct (slots !! i) as [d|] eqn:HEq. - rewrite /helped /= HEq. by destruct (state_of d). - by rewrite /= HEq. Qed. Lemma annoying_lemma_1 slots deqs pref i l b_pendings : (∀ k, k ∈ pref → was_committed <$> slots !! k = Some true ∧ k ∉ deqs) → NoDup (pref ++ i :: b_pendings) → map (get_value (map_imap (helped b_pendings) (<[i:=(l, Done, false)]> slots)) deqs) pref = map (get_value slots deqs) pref. Proof. intros Hpref HND. induction pref as [|pref_hd pref IH]; first done. assert (NoDup (pref ++ i :: b_pendings)) as HND_IH. { simpl in HND. apply NoDup_cons in HND as [_ HND]. done. } assert (∀ k, k ∈ pref → was_committed <$> slots !! k = Some true ∧ k ∉ deqs) as Hpref_IH. { intros k Hk. by apply Hpref, elem_of_list_further, Hk. } rewrite /= IH; try done. clear IH HND_IH Hpref_IH. f_equal. assert (i ≠ pref_hd) as Hi_not_pref_hd. { simpl in HND. apply NoDup_cons in HND as (HND & _). apply not_elem_of_app in HND as (_ & HND). by apply not_elem_of_cons in HND as (HND & _). } rewrite /get_value map_lookup_imap lookup_insert_ne; last done. destruct (slots !! pref_hd) as [[[lp sp] wp]|]; last done. destruct sp; try done. rewrite /= /helped /=. rewrite decide_False; first done. simpl in HND. apply NoDup_cons in HND as (HND & _). apply not_elem_of_app in HND as (_ & HND). by apply not_elem_of_cons in HND as (_ & HND). Qed. Lemma annoying_lemma_2 slots deqs pref i l b_pendings : block_valid slots (i, b_pendings) → NoDup (pref ++ i :: b_pendings) → map (get_value (map_imap (helped b_pendings) (<[i:=(l, Done, false)]> slots)) deqs) b_pendings = get_values (<[i:=(l, Done, false)]> slots) b_pendings. Proof. intros (Hvalid_1 & Hvalid_2) HND. induction b_pendings as [|p ps IH]; first done. simpl in *. assert (i ≠ p) as Hi_not_p. { intros ->. apply NoDup_app in HND as (_ & _ & HND). apply NoDup_cons in HND as (HND & _). by set_solver +HND. } rewrite lookup_insert_ne; last done. assert (p ∈ p :: ps) as Hcomm%Hvalid_2 by set_solver. destruct (slots !! p) as [[[lp sp] wp]|] eqn:Hslots_p; [ f_equal | by inversion Hcomm ]. - rewrite /= map_imap_insert /helped /= /get_value. rewrite lookup_insert_ne; last done. rewrite map_lookup_imap Hslots_p /=. destruct sp; try done. rewrite decide_True; [ done | by set_solver ]. - rewrite -IH; first last; try done. { apply NoDup_app in HND as (HND1 & HND2 & HND3). apply NoDup_app. split; first done. split. - intros e He. apply HND2 in He. apply not_elem_of_cons. split; by set_solver +He. - apply NoDup_cons in HND3 as (HND3_1 & HND3_2). apply NoDup_cons. split; first by set_solver +HND3_1. apply NoDup_cons in HND3_2 as (HND3_2_1 & HND3_2_2). done. } { intros k Hk. by apply Hvalid_2, elem_of_list_further, Hk. } apply map_ext_in. intros k Hk. rewrite /get_value map_lookup_imap map_lookup_imap. assert (i ≠ k) as Hi_not_k. { intros ->. apply NoDup_app in HND as (_ & _ & HND). apply NoDup_cons in HND as (HND & _). apply not_elem_of_cons in HND as (_ & HND). by apply HND, elem_of_list_In, Hk. } rewrite lookup_insert_ne; last done. assert (k ∈ p :: ps) as Hk_p_ps by by apply elem_of_list_further, elem_of_list_In. specialize (Hvalid_2 _ Hk_p_ps) as Hcomm_k. destruct (slots !! k) as [[[lk sk] wk]|]; last by inversion Hcomm_k. destruct sk; try done. rewrite /= /helped /=. rewrite decide_True; last done. rewrite decide_True; [ done | by apply elem_of_list_In ]. Qed. Lemma big_lemma γe γs (ls : list loc) slots (p : list nat) : NoDup p → (∀ i, i ∈ p → was_committed <$> slots !! i = Some false) → own γs (● (of_slot_data <$> slots) : slotUR) -∗ ([∗ map] i ↦ d ∈ slots, per_slot_own γe γs i d) -∗ own γe (● (Excl' ls)) ={⊤ ∖ ↑N}=∗ own γs (● (of_slot_data <$> map_imap (helped p) slots) : slotUR) ∗ ([∗ map] i ↦ d ∈ map_imap (helped p) slots, per_slot_own γe γs i d) ∗ own γe (● (Excl' (ls ++ get_values slots p))). Proof. revert p. iIntros (p). iInduction p as [|n ps] "IH" forall (slots ls); iIntros (HNoDup H) "Hs● Hbig He●". - iModIntro. rewrite /= -app_nil_end map_imap_helped_nil. iFrame. - assert (∀ i : nat, i ∈ ps → was_committed <$> slots !! i = Some false) as H1. { intros i Hi. apply H. apply elem_of_list_further, Hi. } assert (was_committed <$> slots !! n = Some false) as H2. { apply H. apply elem_of_list_here. } assert (∃ ln γn wn, slots !! n = Some (ln, Pend γn, wn)) as Hn. { destruct (slots !! n) as [[[ln sn] wn]|]; last by inversion H2. (destruct sn as [γn|γn|]; last by inversion H2); by exists ln, γn, wn. } apply NoDup_cons in HNoDup. destruct HNoDup as [Hn_not_in_ps HNoDup]. destruct Hn as [l [γ [w Hn]]]. assert (slots = <[n:=(l, Pend γ, w)]> (delete n slots)) as Hs. { by rewrite insert_delete_insert insert_id. } rewrite [in ([∗ map] _ ↦ _ ∈ slots, _)%I]Hs. iDestruct (big_sepM_insert with "Hbig") as "[Hbig_n Hbig]"; first by apply lookup_delete. iDestruct "Hbig_n" as "[Hval_wit_n [Hwritten_n [Hpending_tok_n H]]]". iDestruct "H" as (Q) "[Hsaved AU]". iMod "AU" as (elts_AU) "[He◯ [_ Hclose]]". iDestruct (sync_elts with "He● He◯") as %<-. iMod (update_elts _ _ _ (ls ++ [l]) with "He● He◯") as "[He● He◯]". iMod ("Hclose" with "[$He◯]") as "HPost". iMod (use_pending_tok with "Hs● Hpending_tok_n") as "[Hs● Hcommitted_wit_n]"; first by rewrite Hn. iCombine "Hsaved HPost" as "Hn". iDestruct (big_sepM_insert _ (delete n slots) n (l, Help γ, w) with "[Hn Hval_wit_n Hwritten_n Hcommitted_wit_n Hbig]") as "Hbig"; first by apply lookup_delete. { iClear "IH". iFrame "Hbig". rewrite /per_slot_own /=. iFrame. iExists Q. iDestruct "Hn" as "[$ HPost]". iNext. done. } rewrite insert_delete_insert /update_slot Hn insert_delete_insert. assert (∀ i : nat, i ∈ ps → was_committed <$> <[n:=(l, Help γ, w)]> slots !! i = Some false) as HHH. { intros i Hi. rewrite lookup_insert_ne; [ by apply H1 | by set_solver ]. } iMod ("IH" $! (<[n:=(l, Help γ, w)]> slots) (ls ++ [l]) HNoDup HHH with "Hs● Hbig He●") as "[Hs● [Hbig He●]]"; iClear "IH". assert (map_imap (helped ps) (<[n:=(l, Help γ, w)]> slots) = map_imap (helped (n :: ps)) slots) as ->. { apply map_eq. intros i. destruct (decide (i = n)) as [->|Hi_not_n]. - rewrite map_lookup_imap map_lookup_imap /= lookup_insert Hn /=. rewrite /helped /=. rewrite decide_True; first done. set_solver. - rewrite map_lookup_imap map_lookup_imap /= lookup_insert_ne; last done. destruct (slots !! i) as [[[li si] wi]|]; last done. simpl. rewrite /helped /=. destruct si; try done. destruct (decide (i ∈ n :: ps)). + rewrite decide_True; first done. set_solver. + rewrite decide_False; first done. set_solver. } iModIntro. iFrame. by rewrite /= Hn -app_assoc /= get_values_not_in. Qed. Lemma array_contents_cases γs slots deqs i li : own γs (● (of_slot_data <$> slots) : slotUR) -∗ slot_val_wit γs i li -∗ ⌜array_get slots deqs i = SOMEV #li ∨ array_get slots deqs i = NONEV⌝. Proof. iIntros "Hs● Hval_wit_i". iDestruct (use_val_wit with "Hs● Hval_wit_i") as %Hslots_i. destruct (slots !! i) as [d|] eqn:HEq; last by inversion Hslots_i. destruct d as [[li' si] wi]. inversion Hslots_i as [H]; subst li'. rewrite /array_get HEq. simpl. iPureIntro. destruct (decide (i ∈ deqs)); first by right. destruct wi; by [ left | right ]. Qed. (** * Specification of the queue operations *********************************) Lemma new_queue_spec sz : 0 < sz → {{{ True }}} new_queue #sz {{{ v γ, RET v; is_hwq sz γ v ∗ hwq_cont γ [] }}}. Proof. iIntros (Hsz Φ) "_ HΦ". wp_lam. (** Allocate [q.ar], [q.back] and [q.p]. *) wp_apply wp_allocN; [ lia | done | ]. iIntros (ℓa) "[Hℓa _]". wp_alloc ℓb as "Hℓb". wp_pures. wp_apply wp_new_proph; [ done | ]. iIntros (rs p) "Hp". wp_pures. (* Allocate the remaining ghost state. *) iMod new_back as (γb) "Hb●". iMod new_back as (γi) "Hi●". (* FIXME not about back. *) iMod (new_elts []) as (γe) "[He● He◯]". iMod new_no_contra as (γc) "HC". iMod new_slots as (γs) "Hs●". (* Allocate the invariant. *) iMod (inv_alloc N _ (inv_hwq sz γb γi γe γc γs ℓa ℓb p) with "[Hℓa Hℓb Hp Hb● Hi● He● HC Hs●]") as "#InvN". { pose (pvs := proph_data sz ∅ rs). pose (cont := NoCont (map (λ i, (i, [])) pvs)). iNext. iExists 0, pvs, [], [], cont, ∅, ∅. rewrite array_content_empty Nat2Z.id fmap_empty /=. iFrame. iSplitL. { iExists rs. by iFrame. } repeat (iSplit; first done). iPureIntro. repeat split_and; try done. - intros i. split; intros Hi; [ by lia | by inversion Hi]. - intros e He. set_solver. - apply proph_data_NoDup. - intros i. apply proph_data_sz. - intros b. apply initial_block_valid. - simpl. apply flatten_blocks_initial. } (* Wrap things up. *) iModIntro. iApply "HΦ". iFrame. iExists γb, γi, γc, γs, ℓa, ℓb, p. by iSplit. Qed. Lemma enqueue_spec sz γe (q : val) (l : loc) : is_hwq sz γe q -∗ <<< ∀ (ls : list loc), hwq_cont γe ls >>> enqueue q #l @ ↑N <<< hwq_cont γe (ls ++ [l]), RET #() >>>. Proof. iIntros "Hq" (Φ) "AU". iDestruct "Hq" as (γb γi γc γs ℓ_ar ℓ_back p ->) "#Inv". rewrite /enqueue. wp_pures. wp_bind (FAA _ _)%E. (* Open the invariant to perform the increment. *) iInv "Inv" as (back pvs pref rest cont slots deqs) "HInv". iDestruct "HInv" as "[Hℓ_back [Hℓ_ar [Hb● [Hi● [He● [Hs● HInv]]]]]]". iDestruct "HInv" as "[Hproph [Hbig [Hcont >Hpures]]]". iDestruct "Hpures" as %(Hslots & Hstate & Hpref & Hdeqs & Hpvs_OK & Hcont). destruct Hpvs_OK as (Hpvs_ND & Hpvs_sz). wp_faa. assert (back + 1 = S back)%Z as -> by lia. iMod (back_incr with "Hb●") as "Hb●". iAssert (i2_lower_bound γi match cont with | WithCont _ i2 => i2 | NoCont _ => back `min` sz end -∗ |==> i2_lower_bound γi match cont with | WithCont _ i2 => i2 | NoCont _ => (S back) `min` sz end)%I as "Hup". { destruct cont as [i1 i2|bs]; iIntros "Hi●"; first done. iMod (i2_lower_bound_update with "Hi●") as "$"; [ lia | done ]. } iMod ("Hup" with "Hi●") as "Hi● {Hup}". (* We first handle the case where there is no more space in the queue. *) destruct (decide (back < sz)%Z) as [Hback_sz|Hback_sz]; last first. { iModIntro. iClear "AU". iSplitL. - iNext. iExists (S back), pvs, pref, rest, cont, slots, deqs. assert (S back `min` sz = back `min` sz) as -> by lia. iFrame. iPureIntro. repeat split_and; try done. destruct cont as [i1 i2|bs]; last done. destruct Hcont as ((H1 & H2) & H3 & H4). by repeat (split; first lia). - wp_pures. rewrite (bool_decide_false _ Hback_sz). wp_smart_apply wp_diverge. } (* We now have a reserved slot [i], which is still free. *) pose (i := back). pose (elts := map (get_value slots deqs) pref ++ rest). assert (slots !! back = None) as Hi_free. { destruct (Hslots i) as [H1 H2]. rewrite min_l in H1; last by lia. assert (¬ is_Some (slots !! back)). { intro H. apply H2 in H. lia. } apply eq_None_not_Some. eauto. } (* Useful fact: our index was not yet dequeued. *) assert (i ∉ deqs) as Hi_not_in_deq. { intros H. apply Hdeqs in H as (H & _). rewrite Hi_free in H. inversion H. } (* We then handle the case where there is a contradiction going on. *) destruct cont as [i1 i2|bs]. { (* We access the atomic update and commit the element. *) iMod "AU" as (elts_AU) "[He◯ [_ Hclose]]". iDestruct (sync_elts with "He● He◯") as %<-. iMod (update_elts _ _ _ (elts ++ [l]) with "He● He◯") as "[He● He◯]". iMod ("Hclose" with "[$He◯]") as "HΦ". (* We allocate the new slot. *) iMod (alloc_done_slot γs slots i l Hi_free with "Hs●") as "[Hs [Htok_i [#val_wit_i [#commit_wit_i Hwriting_tok_i]]]]". (* We also remember that we had contradiciton states. *) iDestruct "Hcont" as "#cont_wit". (* And we can close the invariant. *) iModIntro. iSplitR "HΦ Hwriting_tok_i". { iNext. iExists (S back), pvs, pref, (rest ++ [l]), (WithCont i1 i2). iExists (<[i := (l, Done, false)]> slots), deqs. rewrite fmap_insert /= array_content_NONEV; try done. iFrame. iFrame. iSplitL "He●". { rewrite /elts app_assoc map_get_value_not_in_pref; try done. intros Hi%Hpref. rewrite Hi_free in Hi. destruct Hi; done. } iSplitL "Hbig Htok_i". { iApply big_sepM_insert. + apply eq_None_not_Some. intros H. apply Hslots in H. lia. + iFrame "Hbig". repeat (iSplit; first done). done. } iFrame "cont_wit". destruct Hcont as (((HC1 & HC2) & HC3) & HC4 & HC5 & HC6 & HC7 & HC8). iPureIntro. repeat split_and; try done; try by lia. - intros k. destruct sz as [|sz]; first by lia. split; intros Hk. + destruct (decide (k = i)) as [->|k_not_i]. * rewrite lookup_insert. by eexists. * rewrite lookup_insert_ne; last done. apply Hslots. by lia. + destruct (decide (k = i)) as [->|k_not_i]. * destruct sz; by lia. * rewrite lookup_insert_ne in Hk; last done. apply Hslots in Hk. by lia. - intros k. destruct (decide (k = i)) as [->|k_not_i]. + by rewrite lookup_insert. + rewrite lookup_insert_ne; last done. apply Hstate. - intros k Hk. destruct (decide (k = i)) as [->|HNeq]. + split; first by rewrite lookup_insert. split; first done. intros ->. apply Hpref in Hk as (_ & _ & H). done. + rewrite lookup_insert_ne; last done. apply Hpref, Hk. - intros k Hk. destruct (decide (k = i)) as [->|Hk_not_i]. + by rewrite lookup_insert. + rewrite /array_get. rewrite lookup_insert_ne; last done. apply Hdeqs in Hk as (H1 & H2 & H3). repeat (split; first done). rewrite /array_get in H3. destruct (slots !! k) as [[[dl ds] dw]|]; last done. done. - destruct (decide (i1 = i)) as [->|Hi1_not_i]. + by rewrite lookup_insert. + by rewrite lookup_insert_ne. - rewrite /array_get lookup_insert_ne; first done. lia. - rewrite /array_get lookup_insert_ne; last by lia. destruct (slots !! i1) as [[[li1 si1] wi2]|]; last by inversion HC4. rewrite decide_False; last done. inversion HC5; subst wi2. done. } (* Let's clean up the context a bit. *) clear Hslots Hstate Hpref Hdeqs Hcont Hi_not_in_deq Hi_free Hpvs_ND Hpvs_sz. clear elts pvs pref rest slots deqs. subst i. rename back into i. (* We can now move to the store. *) wp_pures. rewrite (bool_decide_true _ Hback_sz). wp_pures. wp_bind (_ <- _)%E. (* We open the invariant again for the store. *) iInv "Inv" as (back pvs pref rest cont slots deqs) "HInv". iDestruct "HInv" as "[Hℓ_back [Hℓ_ar [Hb● [Hi● [He● [>Hs● HInv]]]]]]". iDestruct "HInv" as "[Hproph [Hbig [>Hcont >Hpures]]]". iDestruct "Hpures" as %(Hslots & Hstate & Hpref & Hdeqs & Hpvs_OK & Hcont). destruct Hpvs_OK as (Hpvs_ND & Hpvs_sz). (* Using witnesses, we show that our value and state have not changed. *) iDestruct (use_val_wit with "Hs● val_wit_i") as %Hval_wit_i. iDestruct (use_committed_wit with "Hs● commit_wit_i") as %Hval_commit_i. iDestruct (writing_tok_not_written with "Hs● Hwriting_tok_i") as %Hnot_written_i. (* We also show that the same contradiction ist still going on. *) destruct cont as [i1' i2'|bs]; last first. { by iDestruct (contra_not_no_contra with "Hcont cont_wit") as %Absurd. } iDestruct (contra_agree with "cont_wit Hcont") as %[-> ->]. destruct Hcont as (((HC1 & HC2) & HC3) & HC4 & HC5 & HC6 & HC7 & HC8). (* Our slot is mapped. *) assert (is_Some (slots !! i)) as Hslots_i. { destruct (slots !! i) as [d|]; first by exists d. inversion Hval_wit_i. } (* Our index is in the array. *) assert (i < back `min` sz) as Hi_le_back by by apply Hslots. (* An we perform the store. *) wp_apply (wp_store_offset _ _ ℓ_ar i (array_content sz slots deqs) with "Hℓ_ar"). { apply array_content_is_Some. by lia. } iIntros "Hℓ_ar". (* We perform some updates. *) iMod (use_writing_tok with "Hs● Hwriting_tok_i") as "[Hs● #written_wit_i]". iModIntro. iSplitR "HΦ"; last by wp_pures. iNext. (* It remains to re-establish the invariant. *) pose (new_slots := update_slot i set_written slots). iExists back, pvs, pref, rest, (WithCont i1 i2), new_slots, deqs. subst new_slots. iFrame. iSplitL "Hℓ_ar". { rewrite array_content_set_written; [ by iFrame | by lia | done | by apply Hstate ]. } iSplitL "He●". { erewrite map_ext; first by iFrame. rewrite /get_value. intros k. destruct (decide (k = i)) as [->|Hk_not_i]. - rewrite update_slot_lookup. destruct Hslots_i as [d Hslots_i]. destruct d as [[ld sd] wd]. rewrite Hslots_i in Hnot_written_i. inversion Hnot_written_i; subst wd. rewrite Hslots_i /=. done. - rewrite update_slot_lookup_ne; last done. done. } iSplitL "Hbig". { rewrite /update_slot. destruct (slots !! i) as [d|] eqn:HEq; last done. iApply big_sepM_insert; first by rewrite lookup_delete. assert (slots = <[i:=d]> (delete i slots)) as HEq_slots. { rewrite insert_delete_insert. by rewrite insert_id. } rewrite [X in ([∗ map] _ ↦ _ ∈ X, _)%I] HEq_slots. iDestruct (big_sepM_insert with "Hbig") as "[[H1 [H2 H3]] $]"; first by rewrite lookup_delete. rewrite /per_slot_own val_of_set_written state_of_set_written. iFrame. by rewrite was_written_set_written. } iPureIntro. destruct Hslots_i as [[[li si] wi] Hslots_i]. repeat split_and; try done. - intros k. destruct (decide (k = i)) as [->|k_not_i]. + rewrite update_slot_lookup. split; intros H; last done. rewrite Hslots_i. by eexists. + rewrite update_slot_lookup_ne; last done. by apply Hslots. - intros k. destruct (decide (k = i)) as [->|k_not_i]. + rewrite update_slot_lookup Hslots_i /=. split; intros H. * exfalso. rewrite Hslots_i in Hval_commit_i. destruct si as [γ|γ|]; try by inversion Hval_commit_i. * by inversion H. + rewrite update_slot_lookup_ne; last done. apply Hstate. - intros k Hk. destruct (decide (k = i)) as [->|Hk_not_i]. + rewrite update_slot_lookup Hslots_i /=. repeat split. * rewrite Hslots_i in Hval_commit_i. destruct si; try by inversion Hval_commit_i. * intros Hi%Hdeqs. destruct Hi as [H _]. rewrite Hnot_written_i in H. inversion H. * by apply Hpref in Hk as (_ & _ & H). + rewrite update_slot_lookup_ne; last done. apply Hpref, Hk. - intros k Hk. destruct (decide (k = i)) as [->|Hk_not_i]. + rewrite update_slot_lookup Hslots_i /update_slot /=. rewrite Hslots_i /= insert_delete_insert /array_get lookup_insert. rewrite decide_True; last done. repeat split; try done. destruct si; try done. rewrite Hslots_i in Hval_commit_i. done. + rewrite /array_get update_slot_lookup_ne; last done. apply Hdeqs in Hk. rewrite /array_get in Hk. done. - destruct (decide (i1 = i)) as [->|Hi1_not_i]. + rewrite update_slot_lookup Hslots_i /=. rewrite Hslots_i in HC4. by inversion HC4. + by rewrite update_slot_lookup_ne. - destruct (decide (i1 = i)) as [->|Hi1_not_i]. + rewrite /array_get update_slot_lookup Hslots_i /=. destruct (decide (i ∈ deqs)) as [H|H]; last done. exfalso. apply Hdeqs in H as (H1 & H2 & H3). rewrite Hnot_written_i in H1. inversion H1. + by rewrite /array_get update_slot_lookup_ne. - destruct (decide (i1 = i)) as [->|Hi1_not_i]. + rewrite /array_get update_slot_lookup Hslots_i /=. rewrite Hslots_i in HC5. inversion HC5; subst wi. by rewrite decide_False. + rewrite /array_get update_slot_lookup_ne; last done. destruct (slots !! i1) as [[[li1 si1] wi1]|]; last by inversion HC4. rewrite decide_False; last done. inversion HC5; subst wi1. done. } (* There is no [Contra1]/[Contra2], first assume the prophecy is trivial. *) destruct bs as [|b blocks]. { (* We access the atomic update and commit the element. *) iMod "AU" as (elts_AU) "[He◯ [_ Hclose]]". iDestruct (sync_elts with "He● He◯") as %<-. iMod (update_elts _ _ _ (elts ++ [l]) with "He● He◯") as "[He● He◯]". iMod ("Hclose" with "[$He◯]") as "HΦ". (* We allocate the new slot. *) iMod (alloc_done_slot γs slots i l Hi_free with "Hs●") as "[Hs [Htok_i [#val_wit_i [#commit_wit_i Hwriting_tok_i]]]]". (* And we can close the invariant. *) iModIntro. iSplitR "HΦ Hwriting_tok_i". { iNext. iExists (S back), pvs, pref, (rest ++ [l]), (NoCont []). iExists (<[i := (l, Done, false)]> slots), deqs. rewrite array_content_NONEV //. iFrame. iFrame. iSplitL "He●". { rewrite /elts app_assoc map_get_value_not_in_pref; try done. intros Hi%Hpref. rewrite Hi_free in Hi. destruct Hi; done. } iSplitL "Hbig Htok_i". { iApply big_sepM_insert. + apply eq_None_not_Some. intros H. apply Hslots in H. lia. + iFrame "Hbig". repeat (iSplit; first done). done. } destruct Hcont as (HC1 & HC2 & HC3). iPureIntro. repeat split_and; try done; try by lia. - intros k. destruct sz as [|sz]; first by lia. split; intros Hk. + destruct (decide (k = i)) as [->|k_not_i]. * rewrite lookup_insert. by eexists. * rewrite lookup_insert_ne; last done. apply Hslots. by lia. + destruct (decide (k = i)) as [->|k_not_i]. * destruct sz; by lia. * rewrite lookup_insert_ne in Hk; last done. apply Hslots in Hk. by lia. - intros k. destruct (decide (k = i)) as [->|k_not_i]. + by rewrite lookup_insert. + rewrite lookup_insert_ne; last done. apply Hstate. - intros k Hk. destruct (decide (k = i)) as [->|Hk_not_i]. + by rewrite lookup_insert. + rewrite lookup_insert_ne; last done. apply Hpref, Hk. - intros k Hk. destruct (decide (k = i)) as [->|Hk_not_i]. + by rewrite lookup_insert. + rewrite /array_get. rewrite lookup_insert_ne; last done. apply Hdeqs in Hk as (H1 & H2 & H3). repeat (split; first done). rewrite /array_get in H3. destruct (slots !! k) as [[[dl ds] dw]|]; last done. done. - intros b Hb. by inversion Hb. } (* Let's clean up the context a bit. *) clear Hslots Hstate Hpref Hdeqs Hcont Hi_not_in_deq Hi_free Hpvs_ND Hpvs_sz. clear pvs pref rest slots deqs elts. subst i. rename back into i. (* We can now move to the store. *) wp_pures. rewrite (bool_decide_true _ Hback_sz). wp_pures. wp_bind (_ <- _)%E. (* We open the invariant again for the store. *) iInv "Inv" as (back pvs pref rest cont slots deqs) "HInv". iDestruct "HInv" as "[Hℓ_back [Hℓ_ar [Hb● [Hi● [He● [>Hs● HInv]]]]]]". iDestruct "HInv" as "[Hproph [Hbig [>Hcont >Hpures]]]". iDestruct "Hpures" as %(Hslots & Hstate & Hpref & Hdeqs & Hpvs_OK & Hcont). destruct Hpvs_OK as (Hpvs_ND & Hpvs_sz). (* Using witnesses, we show that our value and state have not changed. *) iDestruct (use_val_wit with "Hs● val_wit_i") as %Hval_wit_i. iDestruct (use_committed_wit with "Hs● commit_wit_i") as %Hval_commit_i. iDestruct (writing_tok_not_written with "Hs● Hwriting_tok_i") as %Hnot_written_i. (* Our slot is mapped. *) assert (is_Some (slots !! i)) as Hslots_i. { destruct (slots !! i) as [d|]; first by exists d. inversion Hval_wit_i. } (* Our index is in the array. *) assert (i < back `min` sz) as Hi_le_back by by apply Hslots. (* An we perform the store. *) wp_apply (wp_store_offset _ _ ℓ_ar i (array_content sz slots deqs) with "Hℓ_ar"). { apply array_content_is_Some. by lia. } iIntros "Hℓ_ar". (* We perform some updates. *) iMod (use_writing_tok with "Hs● Hwriting_tok_i") as "[Hs● #written_wit_i]". iModIntro. iSplitR "HΦ"; last by wp_pures. iNext. (* It remains to re-establish the invariant. *) pose (new_slots := update_slot i set_written slots). iExists back, pvs, pref, rest, cont, new_slots, deqs. subst new_slots. iFrame. iSplitL "Hℓ_ar". { rewrite array_content_set_written; [ by iFrame | by lia | done | by apply Hstate ]. } iSplitL "He●". { erewrite map_ext; first by iFrame. rewrite /get_value. intros k. destruct (decide (k = i)) as [->|Hk_not_i]. - rewrite update_slot_lookup. destruct Hslots_i as [d Hslots_i]. destruct d as [[ld sd] wd]. rewrite Hslots_i in Hnot_written_i. inversion Hnot_written_i; subst wd. rewrite Hslots_i /=. done. - rewrite update_slot_lookup_ne; last done. done. } iSplitL "Hbig". { rewrite /update_slot. destruct (slots !! i) as [d|] eqn:HEq; last done. iApply big_sepM_insert; first by rewrite lookup_delete. assert (slots = <[i:=d]> (delete i slots)) as HEq_slots. { rewrite insert_delete_insert. by rewrite insert_id. } rewrite [X in ([∗ map] _ ↦ _ ∈ X, _)%I] HEq_slots. iDestruct (big_sepM_insert with "Hbig") as "[[H1 [H2 H3]] $]"; first by rewrite lookup_delete. rewrite /per_slot_own val_of_set_written state_of_set_written. iFrame. by rewrite was_written_set_written. } iPureIntro. destruct Hslots_i as [[[li si] wi] Hslots_i]. repeat split_and; try done. - intros k. destruct (decide (k = i)) as [->|k_not_i]. + rewrite update_slot_lookup. split; intros H; last done. rewrite Hslots_i. by eexists. + rewrite update_slot_lookup_ne; last done. by apply Hslots. - intros k. destruct (decide (k = i)) as [->|k_not_i]. + rewrite update_slot_lookup Hslots_i /=. split; intros H. * exfalso. rewrite Hslots_i in Hval_commit_i. destruct si as [γ|γ|]; try by inversion Hval_commit_i. * by inversion H. + rewrite update_slot_lookup_ne; last done. apply Hstate. - intros k Hk. destruct (decide (k = i)) as [->|Hk_not_i]. + rewrite update_slot_lookup Hslots_i /=. repeat split. * rewrite Hslots_i in Hval_commit_i. destruct si; try by inversion Hval_commit_i. * by intros Hi%Hpref. * by apply Hpref in Hk as (_ & _ & H). + rewrite update_slot_lookup_ne; last done. apply Hpref, Hk. - intros k Hk. destruct (decide (k = i)) as [->|Hk_not_i]. + rewrite update_slot_lookup Hslots_i /update_slot /=. rewrite Hslots_i /= insert_delete_insert /array_get lookup_insert. rewrite decide_True; last done. repeat split; try done. destruct si; try done. rewrite Hslots_i in Hval_commit_i. done. + rewrite /array_get update_slot_lookup_ne; last done. apply Hdeqs in Hk. rewrite /array_get in Hk. done. - destruct cont as [i1 i2|bs]. + destruct Hcont as (HC1 & HC2 & HC3 & HC4 & HC5 & HC6). split; first done. destruct (decide (i1 = i)) as [->|Hi1_not_i]. * rewrite /array_get update_slot_lookup Hslots_i /=. repeat split_and; try done. ** rewrite Hslots_i in Hval_commit_i. destruct si; try done. ** rewrite decide_False; first done. apply Hstate. done. * rewrite /array_get update_slot_lookup_ne; last done. rewrite /array_get in HC3. done. + destruct Hcont as (HC1 & HC2 & HC3). repeat split_and; try done. intros b Hb. apply HC1 in Hb as (Hb1 & Hb2). split. * destruct (decide (b.1 = i)) as [Hb1_is_i|Hb1_not_i]. ** rewrite -Hb1_is_i in Hslots_i. by rewrite Hslots_i in Hb1. ** rewrite /update_slot Hslots_i insert_delete_insert. by rewrite lookup_insert_ne. * intros k Hk. destruct (decide (k = i)) as [Hk_is_i|Hk_not_i]. ** rewrite /update_slot Hslots_i insert_delete_insert. subst k. rewrite lookup_insert /=. rewrite Hslots_i in Hval_commit_i. destruct (was_committed (li, si, true)) eqn:H; last done. exfalso. apply Hb2 in Hk. rewrite Hslots_i in Hk. inversion Hk. destruct si; try done. ** rewrite /update_slot Hslots_i insert_delete_insert. rewrite lookup_insert_ne; last done. apply Hb2, Hk. } (* There is no [Contra1]/[Contra2], and the prophecy is non-trivial. *) destruct Hcont as (Hblocks & Hrest & Hpvs). assert (rest = []) as -> by by apply Hrest. rewrite -app_nil_end in elts. rewrite -app_nil_end. destruct b as [b_unused b_pendings]. (* We compare our index with the unused element of the prophecy. *) destruct (decide (b_unused = i)) as [->|b_unused_not_i]. + (* We are the non-committed element of the prophecy: commit the block. *) (* We allocate the new slot. *) iMod (alloc_done_slot γs slots i l Hi_free with "Hs●") as "[Hs● [Htok_i [#val_wit_i [#commit_wit_i Hwriting_tok_i]]]]". (* We then commit at our index. *) iMod "AU" as (elts_AU) "[He◯ [_ Hclose]]". iDestruct (sync_elts with "He● He◯") as %<-. iMod (update_elts _ _ _ (elts ++ [l]) with "He● He◯") as "[He● He◯]". iMod ("Hclose" with "[$He◯]") as "HΦ". (* Our prophecy block must be valid. *) assert (block_valid slots (i, b_pendings)) as Hb_valid by apply Hblocks, elem_of_list_here. rewrite /block_valid /= in Hb_valid. destruct Hb_valid as [Hb_valid1 Hb_valid2]. (* We also need to commit for all indices in in [p_pendings] *) assert (NoDup (i :: b_pendings)) as Hblock_ND. { apply NoDup_app in Hpvs_ND as (H & _ & _). subst pvs. apply NoDup_app in H as (_ & _ & H). simpl in H. rewrite app_comm_cons in H. by apply NoDup_app in H as (H & _ & _). } apply NoDup_cons in Hblock_ND as (Hi & HNoDup). iAssert (per_slot_own γe γs i (l, Done, false)) with "[Htok_i]" as "Hi". { rewrite /per_slot_own /=. eauto with iFrame. } iDestruct (big_sepM_insert (per_slot_own γe γs) slots i (l, Done, false) with "[Hi Hbig]") as "Hbig"; [ done | by iFrame | .. ]. iMod (big_lemma _ _ _ _ b_pendings HNoDup with "Hs● Hbig He●") as "[Hs● [Hbig He●]]". { intros k Hk. destruct (decide (k = i)) as [->|Hk_not_i]. + exfalso. apply Hi, Hk. + rewrite lookup_insert_ne; last done. apply Hb_valid2, Hk. } (* And then we can close the invariant. *) iModIntro. iSplitR "HΦ Hwriting_tok_i". { pose (new_pref := pref ++ i :: b_pendings). pose (new_slots := map_imap (helped b_pendings) (<[i:=(l, Done, false)]> slots)). iNext. iExists (S back), pvs, new_pref, [], (NoCont blocks), new_slots, deqs. iFrame. iSplitL "Hℓ_ar". { assert (array_content sz slots deqs = array_content sz new_slots deqs) as ->; last done. apply array_content_ext. intros k Hk. rewrite /new_slots /array_get. rewrite map_lookup_imap. destruct (decide (k = i)) as [->|Hk_not_i]. - by rewrite lookup_insert Hb_valid1 /helped /= decide_False. - rewrite lookup_insert_ne; last done. destruct (slots !! k) as [[[dl ds] dw]|]; last done. rewrite /helped /=. destruct ds as [dγ|dγ|]. + destruct dw; try done; by destruct (decide (k ∈ b_pendings)). + by destruct dw. + by destruct dw. } iSplitL "He●". { rewrite -app_nil_end /new_pref /elts map_app map_cons. rewrite [in get_value new_slots deqs i]/get_value. rewrite [in new_slots !! i]/new_slots. rewrite map_lookup_imap lookup_insert /= -app_assoc cons_middle. assert (NoDup (pref ++ i :: b_pendings)) as HND. { apply NoDup_app in Hpvs_ND as (HND & _ & _). rewrite cons_middle app_assoc. rewrite Hpvs /= in HND. rewrite cons_middle in HND. rewrite app_assoc app_assoc in HND. by apply NoDup_app in HND as (HND & _ & _). } rewrite annoying_lemma_1 //; last first. { intros k Hk. by apply Hpref in Hk as (H1 & H2 & _). } assert (map (get_value new_slots deqs) b_pendings = get_values (<[i:=(l, Done, false)]> slots) b_pendings) as ->. - rewrite /new_slots. by eapply annoying_lemma_2. - done. } iPureIntro. repeat split_and; try done. - intros k. rewrite /new_slots map_lookup_imap. split; intros Hk. + destruct (decide (k = i)) as [->|Hk_not_i]. * rewrite lookup_insert /helped /=. by eexists. * rewrite lookup_insert_ne; last done. assert (is_Some (slots !! k)) as [d ->] by (apply Hslots; lia). by apply is_Some_helped. + destruct (decide (k = i)) as [->|Hk_not_i]; first by lia. rewrite lookup_insert_ne in Hk; last done. assert (k < back `min` sz) as H; last by lia. apply Hslots. destruct (slots !! k) as [d|]; first by exists d. by inversion Hk. - intros k. rewrite /new_slots map_lookup_imap. destruct (decide (k = i)) as [->|Hk_not_i]; first by rewrite lookup_insert /helped /=. rewrite lookup_insert_ne; last done. split; intros Hk. + destruct (slots !! k) as [d|] eqn:HEq; last done. assert (was_committed <$> Some d ≫= helped b_pendings k = was_committed <$> Some d) as HEq1. { destruct d as [[dl []] dw]; simpl; simpl in Hk; by rewrite Hk. } rewrite HEq1 -HEq in Hk. apply Hstate in Hk. rewrite HEq in Hk. assert (was_written <$> Some d ≫= helped b_pendings k = was_written <$> Some d) as HEq2. { destruct d as [[dl []] []]; simpl; simpl in Hk; try by inversion Hk. rewrite /helped /=. destruct (decide (k ∈ b_pendings)); done. } rewrite HEq2. by inversion Hk. + destruct (slots !! k) as [d|] eqn:HEq; last done. assert (was_written <$> Some d ≫= helped b_pendings k = was_written <$> Some d) as HEq1. { by destruct d as [[dl []] dw]; rewrite /helped; destruct (decide (k ∈ b_pendings)). } rewrite HEq1 -HEq in Hk. apply Hstate in Hk. done. - intros k Hk. subst new_pref new_slots. apply elem_of_app in Hk as [Hk|Hk]. { apply Hpref in Hk as (H1 & H2). split; last done. rewrite map_imap_insert /=. destruct (decide (k = i)) as [->|Hk_not_i]. - by rewrite lookup_insert. - rewrite lookup_insert_ne; last done. rewrite map_lookup_imap. destruct (slots !! k) as [[[dl ds] dw]|]; last by inversion H1. rewrite /= /helped. destruct ds as [dγ|dγ|]; try done. } apply elem_of_cons in Hk as [Hk|Hk]. { subst k. split; last done. by rewrite map_imap_insert /= lookup_insert. } apply Hb_valid2 in Hk as Hb_valid2_k. split. + rewrite map_lookup_imap. destruct (decide (k = i)) as [->|Hk_not_i]. * by rewrite lookup_insert /=. * rewrite lookup_insert_ne; last done. destruct (slots !! k) as [[[kl ks] kw]|]; last by inversion Hb_valid2_k. rewrite /= /helped. destruct ks; try done. by rewrite /= decide_True. + apply Hstate in Hb_valid2_k. apply Hstate in Hb_valid2_k. done. - intros k Hk. subst new_slots. rewrite /array_get map_lookup_imap. assert (k ≠ i) as Hk_not_i. { intros ->. apply Hi_not_in_deq, Hk. } rewrite lookup_insert_ne; last done. apply Hdeqs in Hk as (H1 & H2 & H3). destruct (slots !! k) as [[[lk sk] wk]|] eqn:HEq; last by inversion H1. inversion H1; subst wk. rewrite /=. repeat split_and; try by destruct sk. destruct sk; try done; simpl. + rewrite decide_True; first done. rewrite /array_get HEq in H3. simpl in H3. destruct (decide (k ∈ deqs)); first done. by inversion H3. + rewrite decide_True; first done. rewrite /array_get HEq in H3. simpl in H3. destruct (decide (k ∈ deqs)); first done. by inversion H3. - intros b Hk. subst new_slots. rewrite map_imap_insert /=. assert (b ∈ (i, b_pendings) :: blocks) as H by set_solver +Hk. assert (NoDup (i :: b_pendings ++ flatten_blocks blocks)) as HND. { subst pvs. apply NoDup_app in Hpvs_ND as (HND & _ & _). apply NoDup_app in HND as (_ & _ & HND). done. } apply flatten_blocks_mem1 in Hk as Hk1. apply Hblocks in H as (H1 & H2). split. + assert (b.1 ≠ i) as Hb1_not_i. { intros HEq. apply NoDup_cons in HND as [HND1 HND2]. apply HND1. rewrite -HEq. apply elem_of_app. by right. } rewrite lookup_insert_ne; last done. by rewrite map_lookup_imap H1. + intros j Hj. assert (j ≠ i) as Hj_not_i. { intros HEq. apply NoDup_cons in HND as [HND1 HND2]. apply HND1. rewrite -HEq. apply elem_of_app. right. apply (flatten_blocks_mem2 _ _ Hk _ Hj). } rewrite lookup_insert_ne; last done. rewrite map_lookup_imap. apply H2 in Hj as Hcomm. destruct (slots !! j) as [[[lj sj] wj]|]; last by inversion Hj. rewrite /= /helped. destruct sj; try done. simpl. assert (j ∉ b_pendings); last by rewrite decide_False. intros Hj_contra. apply NoDup_cons in HND as [_ HND]. apply NoDup_app in HND. destruct HND as (HND1 & HND2 & HND3). apply (HND2 _ Hj_contra). apply (flatten_blocks_mem2 _ _ Hk _ Hj). - by rewrite Hpvs /= /new_pref app_comm_cons app_assoc. } clear Hslots Hstate Hpref Hdeqs Hpvs Hrest Hblocks Hi_free Hi_not_in_deq. clear Hpvs_ND Hpvs_sz Hb_valid1 Hb_valid2 HNoDup Hi elts pvs pref slots deqs. clear blocks b_pendings. subst i. rename back into i. wp_pures. rewrite bool_decide_true; last done. wp_pures. wp_bind (_ <- _)%E. (* We open the invariant again for the store. *) iInv "Inv" as (back pvs pref rest cont slots deqs) "HInv". iDestruct "HInv" as "[Hℓ_back [Hℓ_ar [Hb● [Hi● [He● [>Hs● HInv]]]]]]". iDestruct "HInv" as "[Hproph [Hbig [>Hcont >Hpures]]]". iDestruct "Hpures" as %(Hslots & Hstate & Hpref & Hdeqs & Hpvs_OK & Hcont). destruct Hpvs_OK as (Hpvs_ND & Hpvs_sz). (* Using witnesses, we show that our value and state have not changed. *) iDestruct (use_val_wit with "Hs● val_wit_i") as %Hval_wit_i. iDestruct (use_committed_wit with "Hs● commit_wit_i") as %Hval_commit_i. iDestruct (writing_tok_not_written with "Hs● Hwriting_tok_i") as %Hnot_written_i. (* Our slot is mapped. *) assert (is_Some (slots !! i)) as Hslots_i. { destruct (slots !! i) as [d|]; first by exists d. inversion Hval_wit_i. } (* Our index is in the array. *) assert (i < back `min` sz) as Hi_le_back by by apply Hslots. (* An we perform the store. *) wp_apply (wp_store_offset _ _ ℓ_ar i (array_content sz slots deqs) with "Hℓ_ar"). { apply array_content_is_Some. by lia. } iIntros "Hℓ_ar". (* We perform some updates. *) iMod (use_writing_tok with "Hs● Hwriting_tok_i") as "[Hs● #written_wit_i]". iModIntro. iSplitR "HΦ"; last by wp_pures. iNext. (* It remains to re-establish the invariant. *) { pose (new_slots := update_slot i set_written slots). iExists back, pvs, pref, rest, cont, new_slots, deqs. subst new_slots. iFrame. iSplitL "Hℓ_ar". { rewrite array_content_set_written; [ by iFrame | by lia | done | by apply Hstate ]. } iSplitL "He●". { erewrite map_ext; first by iFrame. rewrite /get_value. intros k. destruct (decide (k = i)) as [->|Hk_not_i]. - rewrite update_slot_lookup. destruct Hslots_i as [d Hslots_i]. destruct d as [[ld sd] wd]. rewrite Hslots_i in Hnot_written_i. inversion Hnot_written_i; subst wd. rewrite Hslots_i /=. done. - rewrite update_slot_lookup_ne; last done. done. } iSplitL "Hbig". { rewrite /update_slot. destruct (slots !! i) as [d|] eqn:HEq; last done. iApply big_sepM_insert; first by rewrite lookup_delete. assert (slots = <[i:=d]> (delete i slots)) as HEq_slots. { rewrite insert_delete_insert. by rewrite insert_id. } rewrite [X in ([∗ map] _ ↦ _ ∈ X, _)%I] HEq_slots. iDestruct (big_sepM_insert with "Hbig") as "[[H1 [H2 H3]] $]"; first by rewrite lookup_delete. rewrite /per_slot_own val_of_set_written state_of_set_written. iFrame. by rewrite was_written_set_written. } iPureIntro. repeat split_and; try done. - intros k. destruct (decide (k = i)) as [->|Hk_not_i]. + rewrite update_slot_lookup. split; intros Hk; last by lia. by apply fmap_is_Some. + rewrite update_slot_lookup_ne; last done. apply Hslots. - intros k. destruct (decide (k = i)) as [->|Hk_not_i]. + rewrite update_slot_lookup. split; intros Hk; exfalso. * destruct (slots !! i) as [[[li si] wi]|]; last by inversion Hk. inversion_clear Hnot_written_i. destruct si; inversion Hk. inversion Hval_commit_i. * destruct (slots !! i) as [[[li si] wi]|]; by inversion Hk. + rewrite update_slot_lookup_ne; last done. by apply Hstate. - intros k Hk. destruct (decide (k = i)) as [->|Hk_not_i]. + rewrite update_slot_lookup /=. split. * destruct (slots !! i) as [[[li si] wi]|]; first done. by inversion Hval_wit_i. * apply Hpref, Hk. + rewrite update_slot_lookup_ne; last done. by apply Hpref. - intros k Hk. assert (k ≠ i) as Hk_not_i. { intros ->. apply Hdeqs in Hk as (H1 & H2 & H3). apply Hstate in Hnot_written_i. rewrite /array_get in H3. destruct Hslots_i as [[[li si] wi] Hslots_i]. rewrite Hslots_i decide_False in H3; last done. rewrite Hslots_i in H1. inversion H1; subst wi. inversion H3. } rewrite /array_get update_slot_lookup_ne; last done. apply Hdeqs in Hk. rewrite /array_get in Hk. done. - destruct cont as [i1 i2|bs]. + destruct Hcont as (HC1 & HC2 & HC3 & HC4 & HC5 & HC6). split; first done. repeat split_and; try done. * destruct (decide (i1 = i)) as [->|Hi1_not_i]. ** rewrite update_slot_lookup. destruct (slots !! i) as [[[li si] wi]|]; first done. by inversion Hval_wit_i. ** by rewrite update_slot_lookup_ne. * destruct (decide (i1 = i)) as [->|Hi1_not_i]. ** rewrite /array_get update_slot_lookup. destruct (slots !! i) as [[[li si] wi]|] eqn:HEq; try done. ** by rewrite /array_get update_slot_lookup_ne. * destruct (decide (i1 = i)) as [->|Hi1_not_i]. ** rewrite /array_get update_slot_lookup. destruct (slots !! i) as [[[li si] wi]|] eqn:HEq; try done. inversion HC3; subst wi. done. ** rewrite /array_get update_slot_lookup_ne; last done. destruct (slots !! i1) as [[[li1 si1] wi1]|] eqn:HEq; try done. rewrite decide_False; last done. inversion HC3; subst wi1. done. + destruct Hcont as (HC1 & HC2 & HC3). repeat split_and; try done. destruct Hslots_i as [[[li si] wi] Hslots_i]. intros b Hb. apply HC1 in Hb as (Hb1 & Hb2). split. * destruct (decide (b.1 = i)) as [Hb1_is_i|Hb1_not_i]. ** rewrite -Hb1_is_i in Hslots_i. rewrite Hb1 in Hslots_i. by inversion Hslots_i. ** by rewrite /update_slot Hslots_i insert_delete_insert lookup_insert_ne. * intros k Hk. destruct (decide (k = i)) as [Hk_is_i|Hk_not_i]. ** rewrite /update_slot Hslots_i insert_delete_insert. subst k. rewrite lookup_insert /=. rewrite Hslots_i in Hval_commit_i. destruct (was_committed (li, si, true)) eqn:H; last done. exfalso. apply Hb2 in Hk. rewrite Hslots_i in Hk. inversion Hk. destruct si; try done. ** rewrite /update_slot Hslots_i insert_delete_insert. rewrite lookup_insert_ne; last done. apply Hb2, Hk. } + (* We are not the first non-done element, we will give away our AU. *) iMod (saved_prop_alloc (Φ #())) as (γs_i) "#Hγs_i". iMod (alloc_pend_slot γs slots i l γs_i Hi_free with "Hs●") as "[Hs● [Htok_i [#val_wit_i [Hpend_tok_i [Hname_tok_i Hwriting_tok_i]]]]]". (* We close the invariant, storing our AU. *) iModIntro. iSplitR "Htok_i Hname_tok_i Hwriting_tok_i". { pose (new_bs := glue_blocks (b_unused, b_pendings) i blocks). pose (new_slots := <[i:=(l, Pend γs_i, false)]> slots). iNext. iExists (S back), pvs, pref, [], (NoCont new_bs), new_slots, deqs. rewrite -app_nil_end. iFrame. iSplitL "Hℓ_ar". { assert (array_content sz slots deqs = array_content sz new_slots deqs) as ->; last done. apply array_content_ext. intros k Hk. rewrite /new_slots /array_get. destruct (decide (k = i)) as [->|Hk_not_i]. - by rewrite Hi_free lookup_insert decide_False. - rewrite lookup_insert_ne; last done. destruct (slots !! k) as [d|]; last done. destruct d as [[dl ds] dw]. rewrite /helped /=. destruct ds as [dγ|dγ|]; destruct dw; try done. } iSplitL "He●". { erewrite map_ext_in; first done. subst new_slots. intros k Hk%elem_of_list_In. rewrite /get_value. assert (k ≠ i); last by rewrite lookup_insert_ne. intros ->. apply Hpref in Hk as (H1 & H2). rewrite Hi_free in H1. inversion H1. } iSplitL "Hbig Hpend_tok_i AU". { iApply big_sepM_insert; first done. iFrame. iSplit; first done. iExists (Φ #()). iFrame. done. } iPureIntro. subst new_slots. repeat split_and; try done. - intros k. destruct sz as [|sz]; first by lia. split; intros Hk. + destruct (decide (k = i)) as [->|k_not_i]. * rewrite lookup_insert. by eexists. * rewrite lookup_insert_ne; last done. apply Hslots. by lia. + destruct (decide (k = i)) as [->|k_not_i]. * destruct sz; by lia. * rewrite lookup_insert_ne in Hk; last done. apply Hslots in Hk. by lia. - intros k. destruct (decide (k = i)) as [->|Hk_not_i]. + by rewrite lookup_insert. + rewrite lookup_insert_ne; last done. apply Hstate. - intros k Hk. rewrite lookup_insert_ne; first by apply Hpref, Hk. intros HEq. subst k. apply Hpref in Hk as [H _]. rewrite Hi_free in H. inversion H. - intros k Hk. rewrite /array_get lookup_insert_ne. + apply Hdeqs in Hk. by rewrite /array_get in Hk. + intros <-. apply Hdeqs in Hk as [Hk _]. rewrite Hi_free in Hk. done. - intros b Hb. subst new_bs. rewrite Hpvs in Hpvs_ND. apply NoDup_app in Hpvs_ND as (HND & _ & _). apply NoDup_app in HND as (_ & _ & HND). simpl in HND. by eapply glue_blocks_valid. - subst pvs new_bs. f_equal. apply flatten_blocks_glue. } clear Hslots Hstate Hpref Hdeqs Hblocks Hrest Hpvs Hi_free Hi_not_in_deq. clear Hpvs_ND Hpvs_sz b_unused b_unused_not_i elts blocks pvs pref slots. clear deqs b_pendings. subst i. rename back into i. wp_pures. rewrite bool_decide_true; last done. wp_pures. wp_bind (_ <- _)%E. (* We open the invariant again for the store. *) iInv "Inv" as (back pvs pref rest cont slots deqs) "HInv". iDestruct "HInv" as "[Hℓ_back [Hℓ_ar [Hb● [Hi● [He● [>Hs● HInv]]]]]]". iDestruct "HInv" as "[Hproph [Hbig [>Hcont >Hpures]]]". iDestruct "Hpures" as %(Hslots & Hstate & Hpref & Hdeqs & Hpvs_OK & Hcont). destruct Hpvs_OK as (Hpvs_ND & Hpvs_sz). (* Using witnesses, we show that our value and state have not changed. *) iDestruct (use_val_wit with "Hs● val_wit_i") as %Hval_wit_i. iDestruct (writing_tok_not_written with "Hs● Hwriting_tok_i") as %Hnot_written_i. (* Our slot is mapped. *) assert (is_Some (slots !! i)) as Hslots_i. { destruct (slots !! i) as [d|]; first by exists d. inversion Hval_wit_i. } (* Our index is in the array. *) assert (i < back `min` sz) as Hi_le_back by by apply Hslots. (* An we perform the store. *) wp_apply (wp_store_offset _ _ ℓ_ar i (array_content sz slots deqs) with "Hℓ_ar"). { apply array_content_is_Some. by lia. } iIntros "Hℓ_ar". (* We now look at the state of our cell. *) destruct Hslots_i as [[[l' s] w] Hi]. rewrite Hi in Hval_wit_i. simpl in Hval_wit_i. inversion Hval_wit_i; subst l'. destruct s as [γs_i'|γs_i'|]. - (* We are still in the pending state: contradiction. *) (* We need to run our atomic update ourselves, we recover it. *) rewrite -[in X in ([∗ map] _ ↦ _ ∈ X, _)%I](insert_id _ _ _ Hi). rewrite -insert_delete_insert. iDestruct (big_sepM_insert with "Hbig") as "[Hbig_i Hbig]"; first by apply lookup_delete. iDestruct "Hbig_i" as "[_ [_ [Hcommit_tok_i HAU]]]". iDestruct "HAU" as (Q) "[Hsaved AU]". (* We use the name token to show that γs_i and γs_i' are equal. *) iDestruct (use_name_tok with "Hs● Hname_tok_i") as %Hname_tok_i. assert (γs_i' = γs_i) as Hγs_i; last subst γs_i'. { rewrite Hi /= in Hname_tok_i. by inversion Hname_tok_i. } iDestruct (saved_prop_agree with "Hγs_i Hsaved") as "HQ_is_Φ". (* We run our atomic update ourself. *) pose (elts := map (get_value slots deqs) pref ++ rest). iMod "AU" as (elts_AU) "[He◯ [_ Hclose]]". iDestruct (sync_elts with "He● He◯") as %<-. iMod (update_elts _ _ _ (elts ++ [l]) with "He● He◯") as "[He● He◯]". iMod ("Hclose" with "[$He◯]") as "HΦ". iMod (use_writing_tok with "Hs● Hwriting_tok_i") as "[Hs● #written_wit_i]". iMod (use_pending_tok with "Hs● Hcommit_tok_i") as "[Hs● #commit_wit_i]". { by rewrite update_slot_lookup Hi /=. } iMod (helped_to_done with "Hs● Hname_tok_i") as "Hs●". { by rewrite update_slot_lookup update_slot_lookup Hi. } (* We now act according ot the contradiction status. *) destruct cont as [i1 i2|bs]. * (* A contradiction has arised from somewhere else, we keep it. *) iModIntro. iSplitR "HQ_is_Φ HΦ". { iNext. iExists back, pvs, pref, (rest ++ [l]), (WithCont i1 i2). iExists (update_slot i set_written_and_done slots), deqs. subst elts. rewrite app_assoc. iFrame. iSplitL "Hℓ_ar". { rewrite array_content_set_written_and_done; [ by iFrame | by lia | by rewrite Hi | by apply Hstate ]. } iSplitL "He●". { erewrite map_ext_in; first done. intros k Hk%elem_of_list_In. rewrite /get_value /update_slot Hi insert_delete_insert. destruct (decide (k = i)) as [->|Hk_not_i]. - by rewrite lookup_insert Hi. - by rewrite lookup_insert_ne. } iSplitL "Hs●". { repeat rewrite update_slot_update_slot. by rewrite /update_slot Hi. } iSplitL. { rewrite /update_slot Hi. iApply big_sepM_insert; first by rewrite lookup_delete. iFrame "Hbig". rewrite /per_slot_own /=. iFrame. iSplit; first done. iSplit; done. } iPureIntro. destruct Hcont as (((HC1 & HC2) & HC3) & HC4 & HC5 & HC6 & HC7 & HC8). repeat split_and; try lia; try done. - intros k. destruct (decide (i = k)) as [->|Hk_not_i]. + rewrite update_slot_lookup Hi. split; [ by eexists | lia ]. + rewrite update_slot_lookup_ne; last done. apply Hslots. - intros k. split; intros Hk. + assert (k ≠ i) as Hk_not_i. { intros ->. by rewrite update_slot_lookup Hi in Hk. } rewrite update_slot_lookup_ne; last done. rewrite update_slot_lookup_ne in Hk; last done. by apply Hstate. + assert (k ≠ i) as Hk_not_i. { intros ->. by rewrite update_slot_lookup Hi in Hk. } rewrite update_slot_lookup_ne in Hk; last done. by apply Hstate. - intros k Hk. destruct (decide (k = i)) as [->|Hk_not_i]. + rewrite update_slot_lookup Hi /=. split; [ done | by apply Hpref, Hk ]. + rewrite update_slot_lookup_ne; last done. apply Hpref, Hk. - intros k Hk. assert (k ≠ i) as Hk_not_i. { intros ->. apply Hdeqs in Hk as (H1 & H2 & H3). apply Hstate in Hnot_written_i. rewrite /array_get in H3. rewrite Hi decide_False in H3; last done. rewrite Hi in H1. inversion H1; subst w. inversion H3. } rewrite /array_get update_slot_lookup_ne; last done. apply Hdeqs in Hk. rewrite /array_get in Hk. done. - destruct (decide (i1 = i)) as [->|Hi1_not_i]. + by rewrite update_slot_lookup Hi. + by rewrite update_slot_lookup_ne. - destruct (decide (i1 = i)) as [->|Hi1_not_i]. + by rewrite update_slot_lookup Hi /=. + rewrite update_slot_lookup_ne; last done. destruct (slots !! i1) as [[[li1 si1] wi1]|]; last by inversion HC4. inversion HC5; subst wi1. done. - destruct (decide (i1 = i)) as [->|Hi1_not_i]. + by rewrite /array_get update_slot_lookup Hi /= decide_False. + rewrite /array_get update_slot_lookup_ne; last done. destruct (slots !! i1) as [[[li1 si1] wi1]|]; last by inversion HC4. rewrite decide_False; last done. inversion HC5; subst wi1. done. } wp_pures. iRewrite "HQ_is_Φ". done. * (* No contradiction yet, make it ours if the prophecy is non-trivial. *) iAssert (match bs with | [] => i2_lower_bound γi (back `min` sz) | _ => no_contra γc ∗ i2_lower_bound γi (back `min` sz) end -∗ |==> match bs with | [] => True | (i2, _) :: _ => contra γc i i2 end ∗ match bs with | [] => i2_lower_bound γi (back `min` sz) | (i2, _) :: _ => i2_lower_bound γi i2 end)%I as "Hup". { destruct bs as [|[i2 ps] bs]; first (iIntros "Hi●"; by iFrame). iIntros "[Hcont Hi●]". iMod (to_contra i i2 with "Hcont") as "$". iMod (i2_lower_bound_update _ _ i2 with "Hi●") as "$"; last done. assert (block_valid slots (i2, ps)) as [Hvalid _]. { destruct Hcont as (Hblocks & _ & _). apply Hblocks, elem_of_list_here. } assert (¬ (i2 < back `min` sz)) as H%not_lt; last by lia. eapply iffRLn. - apply Hslots. - intros H. rewrite Hvalid in H. by inversion H. } iAssert (match bs with | [] => i2_lower_bound γi (back `min` sz) | _ => no_contra γc ∗ i2_lower_bound γi (back `min` sz) end ∗ match bs with | [] => no_contra γc | _ => True end)%I with "[Hcont Hi●]" as "[HNC_triv HNC_non_triv]". { destruct bs; by iFrame. } iMod ("Hup" with "HNC_triv") as "[#HC_triv Hi●]". (* We can now close the invariant. *) iModIntro. iSplitR "HQ_is_Φ HΦ". { pose (new_slots := update_slot i set_written_and_done slots). pose (cont := match bs with [] => NoCont [] | (i2, _) :: _ => WithCont i i2 end). iNext. iExists back, pvs, pref, (rest ++ [l]), cont, new_slots, deqs. subst new_slots elts cont. rewrite app_assoc. iFrame. iSplitL "Hℓ_ar". { rewrite array_content_set_written_and_done; [ by iFrame | by lia | by rewrite Hi | by apply Hstate ]. } iSplitL "Hi●". { destruct bs as [|[b_u b_ps] bs]; by iFrame. } iSplitL "He●". { erewrite map_ext_in; first done. intros k Hk%elem_of_list_In. rewrite /get_value /update_slot Hi insert_delete_insert. destruct (decide (k = i)) as [->|Hk_not_i]. - by rewrite lookup_insert Hi. - by rewrite lookup_insert_ne. } iSplitL "Hs●". { repeat rewrite update_slot_update_slot. by rewrite /update_slot Hi. } iSplitR "HNC_non_triv". { rewrite /update_slot Hi. iApply big_sepM_insert; first by rewrite lookup_delete. iFrame "Hbig". rewrite /per_slot_own /=. iFrame. iSplit; first done. iSplit; done. } iSplitL "HNC_non_triv"; first by destruct bs as [|[i2 ps] bs]. iPureIntro. repeat split_and. - intros k. destruct (decide (i = k)) as [->|Hk_not_i]. + rewrite update_slot_lookup Hi. split; [ by eexists | lia ]. + rewrite update_slot_lookup_ne; last done. apply Hslots. - intros k. split; intros Hk. + assert (k ≠ i) as Hk_not_i. { intros ->. by rewrite update_slot_lookup Hi in Hk. } rewrite update_slot_lookup_ne; last done. rewrite update_slot_lookup_ne in Hk; last done. by apply Hstate. + assert (k ≠ i) as Hk_not_i. { intros ->. by rewrite update_slot_lookup Hi in Hk. } rewrite update_slot_lookup_ne in Hk; last done. by apply Hstate. - intros k Hk. apply Hpref in Hk as (H1 & H2 & _). repeat split; try done. + destruct (decide (k = i)) as [->|Hk_not_i]. * by rewrite update_slot_lookup Hi. * by rewrite update_slot_lookup_ne. + destruct bs as [|[b_u b_ps] bs]; first done. intros ->. rewrite Hi in H1. by inversion H1. - intros k Hk. assert (k ≠ i) as Hk_not_i. { intros ->. apply Hdeqs in Hk as (H1 & H2 & H3). apply Hstate in Hnot_written_i. rewrite /array_get in H3. rewrite Hi decide_False in H3; last done. rewrite Hi in H1. inversion H1; subst w. inversion H3. } rewrite /array_get update_slot_lookup_ne; last done. apply Hdeqs in Hk. rewrite /array_get in Hk. done. - done. - done. - destruct Hcont as (HC1 & HC2 & HC3). destruct bs as [|[i2 ps] bs]. + repeat split_and; try done. intros. by set_solver. + repeat split_and; try lia. * assert (i < back `min` sz) as Hi_lt by (apply Hslots; by eexists). assert (block_valid slots (i2, ps)) as Hvalid by apply HC1, elem_of_list_here. assert (slots !! i2 = None) as Hi2_None by by destruct Hvalid as (H & _). assert (¬ i2 < back `min` sz) as Hi2_ge; last by lia. intros H%Hslots. rewrite Hi2_None in H. by inversion H. * apply Hpvs_sz. subst pvs. apply elem_of_app. right. simpl. by apply elem_of_list_here. * by rewrite update_slot_lookup Hi /=. * by rewrite update_slot_lookup Hi /=. * by apply Hstate. * rewrite /array_get update_slot_lookup Hi /=. rewrite decide_False; first done. apply Hstate. done. * rewrite HC3 /=. exists (ps ++ flatten_blocks bs). by rewrite cons_middle app_assoc. } wp_pures. iRewrite "HQ_is_Φ". done. - (* We have moved to the helped state. *) assert (slots = <[i := (l, Help γs_i', w)]> (delete i slots)) as Hslots_i by by rewrite insert_delete_insert insert_id. rewrite [X in ([∗ map] _ ↦ _ ∈ X, _)%I]Hslots_i. (* We recover our postcondition. *) iDestruct (big_sepM_insert with "Hbig") as "[Hbig_i Hbig]"; first by apply lookup_delete. iDestruct "Hbig_i" as "[_ [_ [Hcommit_wit_i Hpost]]]". iDestruct "Hpost" as (Q) "[Hsaved Hpost]". (* We use the name token to show that γs_i and γs_i' are equal. *) iDestruct (use_name_tok with "Hs● Hname_tok_i") as %Hname_tok_i. assert (γs_i' = γs_i) as Hγs_i; last subst γs_i'. { rewrite Hi /= in Hname_tok_i. by inversion Hname_tok_i. } iDestruct (saved_prop_agree with "Hγs_i Hsaved") as "HQ_is_Φ". (* We need to move from helped to done. *) iMod (helped_to_done with "Hs● Hname_tok_i") as "Hs●". { by rewrite Hi. } (* We perform some updates. *) iMod (use_writing_tok with "Hs● Hwriting_tok_i") as "[Hs● #written_wit_i]". iModIntro. iSplitR "HQ_is_Φ Hpost". { pose (new_slots := update_slot i set_written_and_done slots). iNext. iExists back, pvs, pref, rest, cont, new_slots, deqs. subst new_slots. iFrame. iSplitL "Hℓ_ar". { rewrite array_content_set_written_and_done; [ by iFrame | by lia | by rewrite Hi | by apply Hstate ]. } iSplitL "He●". { erewrite map_ext_in; first done. intros k Hk%elem_of_list_In. rewrite /get_value /update_slot Hi insert_delete_insert. destruct (decide (k = i)) as [->|Hk_not_i]. - by rewrite lookup_insert Hi. - by rewrite lookup_insert_ne. } iSplitL "Hs●". { repeat rewrite update_slot_update_slot. by rewrite /update_slot Hi. } iSplitL. { rewrite /update_slot Hi. iApply big_sepM_insert; first by rewrite lookup_delete. iFrame "Hbig". rewrite /per_slot_own /=. iFrame. iSplit; done. } iPureIntro. repeat split_and; try done. - intros k. destruct (decide (i = k)) as [->|Hk_not_i]. + rewrite update_slot_lookup Hi. split; [ by eexists | lia ]. + rewrite update_slot_lookup_ne; last done. apply Hslots. - intros k. split; intros Hk. + assert (k ≠ i) as Hk_not_i. { intros ->. by rewrite update_slot_lookup Hi in Hk. } rewrite update_slot_lookup_ne; last done. rewrite update_slot_lookup_ne in Hk; last done. by apply Hstate. + assert (k ≠ i) as Hk_not_i. { intros ->. by rewrite update_slot_lookup Hi in Hk. } rewrite update_slot_lookup_ne in Hk; last done. by apply Hstate. - intros k Hk. destruct (decide (k = i)) as [->|Hk_not_i]. + rewrite update_slot_lookup Hi. split; first done. apply Hpref, Hk. + rewrite update_slot_lookup_ne; last done. apply Hpref, Hk. - intros k Hk. assert (k ≠ i) as Hk_not_i. { intros ->. apply Hdeqs in Hk as (H1 & H2 & H3). apply Hstate in Hnot_written_i. rewrite /array_get in H3. rewrite Hi decide_False in H3; last done. rewrite Hi in H1. inversion H1; subst w. inversion H3. } rewrite /array_get update_slot_lookup_ne; last done. apply Hdeqs in Hk. rewrite /array_get in Hk. done. - destruct cont as [i1 i2|bs]. + destruct Hcont as (HC1 & HC2 & HC3 & HC4 & HC5 & HC6). split; first done. repeat split_and; try done. * destruct (decide (i1 = i)) as [->|Hi1_not_i]. ** by rewrite update_slot_lookup Hi. ** by rewrite update_slot_lookup_ne. * destruct (decide (i1 = i)) as [->|Hi1_not_i]. ** by rewrite /array_get update_slot_lookup Hi /=. ** rewrite /array_get update_slot_lookup_ne; last done. rewrite /array_get in HC3. done. * destruct (decide (i1 = i)) as [->|Hi1_not_i]. ** by rewrite /array_get update_slot_lookup Hi decide_False. ** rewrite /array_get update_slot_lookup_ne; last done. rewrite /array_get in HC3. done. + destruct Hcont as (HC1 & HC2 & HC3). repeat split_and; try done. intros b Hb. apply HC1 in Hb as (H1 & H2). split. ** assert (b.1 ≠ i) as Hb1_not_i. { intros H. rewrite H in H1. by rewrite Hi in H1. } by rewrite update_slot_lookup_ne. ** intros k Hk. assert (k ≠ i) as Hb1_not_i. { intros H. subst k. apply H2 in Hk. rewrite Hi in Hk. by inversion Hk. } rewrite update_slot_lookup_ne; last done. by apply H2. } wp_pures. iRewrite "HQ_is_Φ". done. - (* We are in the done state: contradiction. *) iDestruct (big_sepM_lookup _ _ i with "Hbig") as "[_ [_ H]]"; first done; simpl. iDestruct "H" as "[_ Htok_i']". by iDestruct (slot_token_exclusive with "Htok_i Htok_i'") as "H". Qed. Lemma dequeue_spec sz γe (q : val) : is_hwq sz γe q -∗ <<< ∀ (ls : list loc), hwq_cont γe ls >>> dequeue q @ ↑N <<< ∃ (l : loc) ls', ⌜ls = l :: ls'⌝ ∗ hwq_cont γe ls', RET #l >>>. Proof. iIntros "Hq" (Φ) "AU". iLöb as "IH". iDestruct "Hq" as (γb γi γc γs ℓ_ar ℓ_back p ->) "#Inv". wp_lam. wp_pures. wp_bind (! _)%E. (* We need to open the invariant to read [q.back]. *) iInv "Inv" as (back pvs pref rest cont slots deqs) "HInv". iDestruct "HInv" as "[Hℓ_back [Hℓ_ar [>Hb● [Hi● [He● [Hs● HInv]]]]]]". iDestruct "HInv" as "[Hproph [Hbig [>Hcont Hpures]]]". wp_load. (* If there is a contradiction, remember that. *) iAssert (match cont with | NoCont _ => True | WithCont i1 i2 => contra γc i1 i2 end)%I with "[Hcont]" as "#Hinit_cont". { destruct cont as [i1 i2|bs]; [ by iDestruct "Hcont" as "#C" | done ]. } (* We remember the current back value. *) iMod (back_snapshot with "Hb●") as "[Hb● Hback_snap]". iMod (i2_lower_bound_snapshot with "Hi●") as "[Hi● Hi2_lower_bound]". (* We close the invariant again. *) iModIntro. iSplitR "AU Hback_snap Hi2_lower_bound". { iNext. repeat iExists _. eauto with iFrame. } clear pref rest slots deqs pvs. (* The range is the min between [q.back - 1] and [q.size - 1]. *) wp_bind (minimum _ _)%E. wp_apply minimum_spec_nat. wp_pures. (* We now prove the inner loop part by induction in the index. *) assert (back `min` sz ≤ back `min` sz) as Hn by done. assert (match cont with | NoCont _ => True | WithCont i1 _ => back `min` sz - back `min` sz ≤ i1 end) as Hcont_i1 by (destruct cont as [i1 _|_]; lia). revert Hn Hcont_i1. generalize (back `min` sz) at 1 4 7 as n. intros n Hn Hcont_i1. iInduction n as [|n] "IH_loop" forall (Hn Hcont_i1). (* The bas case is trivial. *) { wp_lam. wp_pures. iApply "IH"; last done. iExists _, _, _, _, _, _, _. iSplitR; done. } (* Now the induction case: we need to open the invariant for the load. *) wp_lam. wp_pures. wp_bind (! _)%E. iInv "Inv" as (back' pvs pref rest cont' slots deqs) "HInv". iDestruct "HInv" as "[Hℓ_back [Hℓ_ar [>Hb● [Hi● [He● [Hs● HInv]]]]]]". iDestruct "HInv" as "[Hproph [Hbig [Hcont >Hpures]]]". iDestruct "Hpures" as %(Hslots & Hstate & Hpref & Hdeqs & Hpvs_OK & Hcont). destruct Hpvs_OK as (Hpvs_ND & Hpvs_sz). (* We use our snapshot to show that back is smaller that back'. *) iDestruct (back_le with "Hb● Hback_snap") as %Hback. (* We define the loop index as [i]. *) pose (i := (back `min` sz) - S n). assert ((back `min` sz)%nat - S n = i)%Z as -> by by rewrite Nat2Z.inj_sub. (* We can now load. *) wp_apply (wp_load_offset _ _ ℓ_ar _ i _ (array_get slots deqs i) with "Hℓ_ar"); [ apply array_content_lookup; lia | ]. iIntros "Hℓa". (* If there was an initial contradiction, it is still here. *) iAssert ⌜match cont with | NoCont _ => True | WithCont i1 i2 => cont' = cont ∧ (back `min` sz - S n ≤ i1) end⌝%I as %Hinitial_cont. { destruct cont as [i1 i2|bs]; destruct cont' as [i1' i2'|bs']; try done. - iDestruct (contra_agree with "Hinit_cont Hcont") as %[-> ->]. iPureIntro. split; first done. destruct Hcont as (((H1 & H2) & H3) & _). lia. - by iDestruct (contra_not_no_contra with "Hcont Hinit_cont") as "False". } (* We then reason by cas on the physical contents of slot [i]. *) destruct (decide (array_get slots deqs i = NONEV)) as [Hi_NULL|Hi_not_NULL]. { rewrite Hi_NULL. iModIntro. iSplitR "AU Hback_snap Hi2_lower_bound". { iNext. repeat iExists _. iFrame. iSplit; done. } wp_pures. assert (S n - 1 = n)%Z as -> by lia. iApply ("IH_loop" with "[] [] AU Hback_snap"). - iPureIntro. lia. - iPureIntro. destruct cont as [i1 i2|bs]; last done. destruct Hinitial_cont as [-> Hi1]. destruct Hcont as (HC1 & HC2 & HC3 & HC4 & HC5 & HC6). apply le_lt_or_eq in Hcont_i1 as [H|H]; rewrite -/i in H; first by lia. exfalso. subst i1. assert (is_Some (slots !! i)) as [d Hslots_i] by (apply Hslots; lia). destruct d as [[li si] wi]. rewrite /array_get Hslots_i /= in Hi_NULL. rewrite /array_get Hslots_i in HC3. rewrite decide_False in Hi_NULL; last done. inversion HC3; subst wi. by inversion Hi_NULL. - by iFrame. } (* We know that a non-null value [li] at index [i], we get a witness. *) assert (is_Some (slots !! i)) as [[[li si] wi] Hslots_i]. { rewrite /array_get in Hi_not_NULL. destruct (slots !! i) as [d|]; last done. by eexists. } assert (array_get slots deqs i = SOMEV #li) as ->. { rewrite /array_get Hslots_i /=. rewrite /array_get Hslots_i in Hi_not_NULL. revert Hi_not_NULL. destruct (decide (i ∈ deqs)); intros H; first done. by destruct wi. } iMod (val_wit_from_auth γs i li with "Hs●") as "[Hs● #Hval_wit_i]"; first by rewrite Hslots_i. (* Close the invariant and clean up the context. *) iModIntro. iSplitR "AU Hback_snap Hi2_lower_bound". { iNext. repeat iExists _. iFrame. iSplit; done. } clear Hslots Hstate Hpref Hdeqs Hcont Hinitial_cont Hback back' Hpvs_ND. clear Hpvs_sz pvs pref rest cont' Hslots_i si wi Hi_not_NULL slots deqs. (* Finally, the interesting where the cell was non-NULL on the load. *) wp_pures. wp_bind (Resolve _ _ _)%E. iInv "Inv" as (back' pvs pref rest cont' slots deqs) "HInv". iDestruct "HInv" as "[Hℓ_back [Hℓ_ar [>Hb● [>Hi● [He● [>Hs● HInv]]]]]]". iDestruct "HInv" as "[>Hproph [Hbig [>Hcont >Hpures]]]". iDestruct "Hpures" as %(Hslots & Hstate & Hpref & Hdeqs & Hpvs_OK & Hcont). destruct Hpvs_OK as (Hpvs_ND & Hpvs_sz). (* If there was an initial contradiction, it is still here. *) iAssert ⌜match cont with | NoCont _ => True | WithCont i1 i2 => cont' = cont ∧ back `min` sz - S n ≤ i1 end⌝%I as %Hinitial_cont. { destruct cont as [i1 i2|bs]; destruct cont' as [i1' i2'|bs']; try done. - iDestruct (contra_agree with "Hinit_cont Hcont") as %[-> ->]. iPureIntro. split; first done. destruct Hcont as (((H1 & H2) & H3) & _). done. - by iDestruct (contra_not_no_contra with "Hcont Hinit_cont") as "False". } (* We resolve. *) iDestruct "Hproph" as (rs) "[Hp Hpvs]". iDestruct "Hpvs" as %Hpvs. wp_apply (wp_resolve with "Hp"); first done. (* We reason by case on the success of the CAS. *) iDestruct (array_contents_cases γs slots deqs with "Hs● Hval_wit_i") as %[Hi|Hi]. * (* The CmpXchg succeeded. *) iClear "IH_loop IH". assert (array_content sz slots deqs !! i = Some (SOMEV #li)). { rewrite array_content_lookup; last by lia. by rewrite Hi. } wp_apply (wp_cmpxchg_suc_offset with "Hℓ_ar"); [ done | done | by right | ]. iIntros "Hℓ_ar" (rs' ->) "Hp". (* Note that [i] is used (otherwise the CmpXchg would have failed). *) iDestruct (use_val_wit with "Hs● Hval_wit_i") as %Hval_wit_i. iDestruct (back_le with "Hi● Hi2_lower_bound") as %Hi2. assert (is_Some (slots !! i)) as [[[dl ds] dw] Hslots_i]. { destruct (slots !! i) as [d|]; [ by exists d | by inversion Hval_wit_i ]. } assert (dl = li) as Hdl_li; last subst dl. { rewrite Hslots_i in Hval_wit_i. by inversion Hval_wit_i. } (* We now reason by case on whether the enqueue at [i] was committed. *) destruct (was_committed (li, ds, dw)) eqn:Hcommitted. { (* We first consider the case where it was committed. *) (* If [i] has been dequeued alread: contradiction. *) assert (i ∉ deqs) as Hi_not_deq. { intros Hi_deq. specialize (Hdeqs i Hi_deq) as (H1 & H2 & H3). rewrite Hslots_i /= in H1. inversion H1; subst dw. rewrite /array_get Hslots_i in Hi. rewrite decide_True in Hi; last done. inversion Hi. } (* We clean up the prophecy. *) rewrite /= decide_True in Hpvs; last lia. rewrite Nat2Z.id in Hpvs. rewrite decide_False in Hpvs; last done. (* We then show that the commit prefix cannot be empty. *) destruct pref as [|i' new_pref]. { exfalso. destruct cont as [i1 i2|_]. - destruct Hinitial_cont as [-> Hi1]. destruct Hcont as (((HC1 & HC2) & HC3) & HC4 & HC5 & HC6 & HC7 & HC8). rewrite Hpvs /= in HC8. destruct HC8 as [junk HEq]. inversion HEq as [[HEq1 HEq2]]. lia. - destruct cont' as [i1' i2'|bs]. + destruct Hcont as (((HC1 & HC2) & HC3) & HC4 & HC5 & HC6 & HC7 & HC8). rewrite Hpvs /= in HC8. destruct HC8 as [junk HEq]. inversion HEq as [[HEq1 HEq2]]. assert (back < i2'); last by lia. lia. + destruct Hcont as (HC1 & HC2 & HC3). rewrite Hpvs /= in HC3. destruct bs as [|[b_u b_ps] bs]; first by inversion HC3. simpl in HC3. inversion HC3 as [[HEq1 HEq2]]. assert (block_valid slots (b_u, b_ps)) as [Hvalid _] by apply HC1, elem_of_list_here. rewrite /= -HEq1 Hslots_i in Hvalid. inversion Hvalid. } assert (i' = i) as ->. { destruct cont' as [i1' i2'|bs]. - destruct Hcont as (_ & _ & _ & _ & _ & HC). rewrite Hpvs in HC. destruct HC as [junk HC]. by inversion HC. - destruct Hcont as (_ & _ & HC). rewrite Hpvs in HC. by inversion HC. } (* We commit. *) pose (new_elts := map (get_value slots ({[i]} ∪ deqs)) new_pref ++ rest). pose (new_pvs := proph_data sz ({[i]} ∪ deqs) rs'). iMod "AU" as (elts_AU) "[He◯ [_ Hclose]]". iDestruct (sync_elts with "He● He◯") as %<-. iMod (update_elts _ _ _ new_elts with "He● He◯") as "[He● He◯]". iMod ("Hclose" $! li new_elts with "[$He◯]") as "HΦ". { iPureIntro. rewrite /new_elts /=. by rewrite /get_value Hslots_i. } iModIntro. iSplitR "HΦ Hback_snap". { pose (new_deqs := {[i]} ∪ deqs). iNext. iExists back', new_pvs, new_pref, rest, cont', slots, new_deqs. subst new_deqs. iFrame. iSplitL "Hℓ_ar". { rewrite array_content_dequeue; [ done | by lia | done ]. } iSplitL "Hp". { iExists rs'. by iFrame "Hp". } iPureIntro. repeat split_and; try done. - intros k. split; intros Hk; first by apply Hstate. intros Hk_in_deqs. apply elem_of_union in Hk_in_deqs. destruct Hk_in_deqs as [Hk_is_i|Hk_in_deqs]. + apply elem_of_singleton_1 in Hk_is_i. subst k. rewrite /array_get Hslots_i decide_False in Hi; last done. rewrite /physical_value in Hi. rewrite Hslots_i in Hk. inversion Hk; subst dw. inversion Hi. + apply Hdeqs in Hk_in_deqs as (HContra & _). rewrite HContra in Hk. inversion Hk. - intros k Hk. assert (k ∈ i :: new_pref) as HH%Hpref by set_solver +Hk. destruct HH as (H1 & H2 & H3). repeat split; try done. apply not_elem_of_union. split; last done. apply not_elem_of_singleton. intros ->. destruct cont' as [i1' i2'|bs]. + destruct Hcont as (HC1 & HC2 & HC3 & HC4 & HC5 & [junk HC6]). rewrite HC6 in Hpvs_ND. apply NoDup_app in Hpvs_ND as (HND & _ & _). apply NoDup_app in HND as (HND & _ & _). apply NoDup_app in HND as (HND & _ & _). apply NoDup_cons in HND as (HND & _). apply HND, Hk. + destruct Hcont as (HC1 & HC2 & HC3). rewrite HC3 in Hpvs_ND. apply NoDup_app in Hpvs_ND as (HND & _ & _). apply NoDup_app in HND as (HND & _ & _). apply NoDup_cons in HND as (HND & _). apply HND, Hk. - intros k Hk. apply elem_of_union in Hk as [Hk%elem_of_singleton_1|Hk]. + subst k. rewrite Hslots_i /=. assert (dw = true) as ->. { rewrite /array_get Hslots_i decide_False in Hi; last done. rewrite /physical_value in Hi. destruct dw; first done. by inversion Hi. } repeat split_and; [ done | by f_equal | .. ]. rewrite /array_get Hslots_i decide_True; [ done | by set_solver ]. + destruct (Hdeqs k Hk) as (H1 & H2 & H3). repeat split_and; try done. rewrite /array_get. destruct (slots !! k) as [[[lk sk] wk]|]; last done. rewrite decide_True; first done. by set_solver +Hk. - by apply proph_data_NoDup. - intros k Hk. by eapply (proph_data_sz sz _ _ _ Hk). - destruct cont' as [i1' i2'|bs]. + destruct Hcont as (((HC1 & HC2) & HC3) & HC4 & HC5 & HC6 & HC7 & HC8). assert (i1' ≠ i) as Hi1'_not_i. { intros ->. assert (i ∈ i :: new_pref) as Hpref_i%Hpref by set_solver. by destruct Hpref_i as (_ & _ & Hpref_i). } repeat split_and; try done. * apply not_elem_of_union. split; last done. by apply not_elem_of_singleton. * rewrite /array_get. destruct (slots !! i1') as [di1'|]; last by inversion HC2. destruct di1' as [[li1' si1'] wi1']. rewrite decide_False; last by set_solver. inversion HC5; subst wi1'. done. * rewrite Hpvs /= in HC8. rewrite /new_pvs. by eapply prefix_cons_inv_2. + destruct Hcont as (HC1 & HC2 & HC3). repeat split_and; try done. rewrite Hpvs /= in HC3. by inversion HC3. } wp_pures. done. } (* If the enqueue at index [i] was not committed: contradiction. *) exfalso. assert (was_committed <$> slots !! i = Some false) as Hcom_i. { rewrite Hslots_i. simpl. by f_equal. } apply Hstate in Hcom_i. rewrite Hslots_i in Hcom_i. inversion Hcom_i; subst dw. rewrite /array_get Hslots_i /= in Hi. destruct (decide (i ∈ deqs)); by inversion Hi. * (* The CmpXchg failed, we continue looping. *) assert (array_content sz slots deqs !! i = Some NONEV) as Hcont_i. { rewrite array_content_lookup; last by lia. by rewrite Hi. } wp_apply (wp_cmpxchg_fail_offset _ _ _ _ _ _ (array_get slots deqs i) with "Hℓ_ar"); [ by rewrite Hi | by rewrite Hi | by right | ]. iIntros "Hℓa" (rs' ->) "Hp". (* We can close the invariant. *) iModIntro. iSplitR "AU Hback_snap Hi2_lower_bound". { iNext. iExists _, _, _, _, cont', _, _. iFrame. iSplit; last done. iExists rs'. rewrite Hpvs /= decide_True; last by lia. by iFrame. } (* And conclude using the loop induction hypothesis. *) wp_pures. assert (S n - 1 = n)%Z as -> by lia. iClear "Hval_wit_i". iApply ("IH_loop" with "[] [] AU Hback_snap"). - iPureIntro. lia. - iPureIntro. destruct cont as [i1 i2|bs]; last done. apply le_lt_or_eq in Hcont_i1. destruct Hcont_i1 as [Hi1|Hi1]; first lia. exfalso. destruct Hinitial_cont as [-> Hinitial_cont]. destruct Hcont as (HC1 & HC2 & HC3 & HC4 & HC5 & HC6 & HC7). assert (is_Some (slots !! i1)) as Hslots_i1. { apply Hslots. lia. } destruct Hslots_i1 as [[[li1 si1] wi1] Hslots_i1]. rewrite /array_get Hslots_i1 decide_False in HC5; last done. simpl in HC5. destruct wi1; last done. clear HC5. rewrite array_content_lookup in Hcont_i; last by lia. rewrite /array_get in Hcont_i. subst i i1. rewrite Hslots_i1 in Hcont_i. rewrite decide_False in Hcont_i; last done. inversion Hcont_i. - by iFrame. Qed. End herlihy_wing_queue. (** * Instantiation of the specification ***********************************) Definition atomic_cinc `{!heapGS Σ, !savedPropG Σ, !hwqG Σ} : spec.atomic_hwq Σ := {| spec.new_queue_spec := new_queue_spec; spec.enqueue_spec := enqueue_spec; spec.dequeue_spec := dequeue_spec; spec.hwq_content_exclusive := hwq_cont_exclusive |}. Typeclasses Opaque hwq_content is_hwq.
function a = transpose(a) %TRANSPOSE Implements a.' for gradients % % c = a.' % % written 10/16/98 S.M. Rump % modified 11/03/03 S.M. Rump improved performance % modified 04/04/04 S.M. Rump set round to nearest for safety % modified 04/06/05 S.M. Rump rounding unchanged % [m n] = size(a.x); a.x = a.x.'; if m*n~=1 index = reshape( 1:(m*n) , m , n )'; a.dx = a.dx( index , : ); end
(* Title: JinjaThreads/Framework/FWLocking.thy Author: Andreas Lochbihler *) header {* \isaheader{Semantics of the thread actions for locking} *} theory FWLocking imports FWLock begin definition redT_updLs :: "('l,'t) locks \<Rightarrow> 't \<Rightarrow> 'l lock_actions \<Rightarrow> ('l,'t) locks" where "redT_updLs ls t las \<equiv> (\<lambda>(l, la). upd_locks l t la) \<circ>$ (($ls, las$))" lemma redT_updLs_iff [simp]: "redT_updLs ls t las $ l = upd_locks (ls $ l) t (las $ l)" by(simp add: redT_updLs_def) lemma upd_locks_empty_conv [simp]: "(\<lambda>(l, las). upd_locks l t las) \<circ>$ ($ls, K$ []$) = ls" by(auto intro: finfun_ext) lemma redT_updLs_Some_thread_idD: "\<lbrakk> has_lock (redT_updLs ls t las $ l) t'; t \<noteq> t' \<rbrakk> \<Longrightarrow> has_lock (ls $ l) t'" by(auto simp add: redT_updLs_def intro: has_lock_upd_locks_implies_has_lock) definition acquire_all :: "('l, 't) locks \<Rightarrow> 't \<Rightarrow> ('l \<Rightarrow>f nat) \<Rightarrow> ('l, 't) locks" where "acquire_all ls t ln \<equiv> (\<lambda>(l, la). acquire_locks l t la) \<circ>$ (($ls, ln$))" lemma acquire_all_iff [simp]: "acquire_all ls t ln $ l = acquire_locks (ls $ l) t (ln $ l)" by(simp add: acquire_all_def) definition lock_ok_las :: "('l,'t) locks \<Rightarrow> 't \<Rightarrow> 'l lock_actions \<Rightarrow> bool" where "lock_ok_las ls t las \<equiv> \<forall>l. lock_actions_ok (ls $ l) t (las $ l)" lemma lock_ok_lasI [intro]: "(\<And>l. lock_actions_ok (ls $ l) t (las $ l)) \<Longrightarrow> lock_ok_las ls t las" by(simp add: lock_ok_las_def) lemma lock_ok_lasE: "\<lbrakk> lock_ok_las ls t las; (\<And>l. lock_actions_ok (ls $ l) t (las $ l)) \<Longrightarrow> Q \<rbrakk> \<Longrightarrow> Q" by(simp add: lock_ok_las_def) lemma lock_ok_lasD: "lock_ok_las ls t las \<Longrightarrow> lock_actions_ok (ls $ l) t (las $ l)" by(simp add: lock_ok_las_def) lemma lock_ok_las_code [code]: "lock_ok_las ls t las = finfun_All ((\<lambda>(l, la). lock_actions_ok l t la) \<circ>$ ($ls, las$))" by(simp add: lock_ok_las_def finfun_All_All o_def) lemma lock_ok_las_may_lock: "\<lbrakk> lock_ok_las ls t las; Lock \<in> set (las $ l) \<rbrakk> \<Longrightarrow> may_lock (ls $ l) t" by(erule lock_ok_lasE)(rule lock_actions_ok_Lock_may_lock) lemma redT_updLs_may_lock [simp]: "lock_ok_las ls t las \<Longrightarrow> may_lock (redT_updLs ls t las $ l) t = may_lock (ls $ l) t" by(auto dest!: lock_ok_lasD[where l=l]) lemma redT_updLs_has_locks [simp]: "\<lbrakk> lock_ok_las ls t' las; t \<noteq> t' \<rbrakk> \<Longrightarrow> has_locks (redT_updLs ls t' las $ l) t = has_locks (ls $ l) t" by(auto dest!: lock_ok_lasD[where l=l]) definition may_acquire_all :: "('l, 't) locks \<Rightarrow> 't \<Rightarrow> ('l \<Rightarrow>f nat) \<Rightarrow> bool" where "may_acquire_all ls t ln \<equiv> \<forall>l. ln $ l > 0 \<longrightarrow> may_lock (ls $ l) t" lemma may_acquire_allE: "\<lbrakk> may_acquire_all ls t ln; \<forall>l. ln $ l > 0 \<longrightarrow> may_lock (ls $ l) t \<Longrightarrow> P \<rbrakk> \<Longrightarrow> P" by(auto simp add: may_acquire_all_def) lemma may_acquire_allD [dest]: "\<lbrakk> may_acquire_all ls t ln; ln $ l > 0 \<rbrakk> \<Longrightarrow> may_lock (ls $ l) t" by(auto simp add: may_acquire_all_def) lemma may_acquire_all_has_locks_acquire_locks [simp]: "\<lbrakk> may_acquire_all ls t ln; t \<noteq> t' \<rbrakk> \<Longrightarrow> has_locks (acquire_locks (ls $ l) t (ln $ l)) t' = has_locks (ls $ l) t'" by(cases "ln $ l > 0")(auto dest: may_acquire_allD) lemma may_acquire_all_code [code]: "may_acquire_all ls t ln \<longleftrightarrow> finfun_All ((\<lambda>(lock, n). n > 0 \<longrightarrow> may_lock lock t) \<circ>$ ($ls, ln$))" by(auto simp add: may_acquire_all_def finfun_All_All o_def) definition collect_locks :: "'l lock_actions \<Rightarrow> 'l set" where "collect_locks las = {l. Lock \<in> set (las $ l)}" lemma collect_locksI: "Lock \<in> set (las $ l) \<Longrightarrow> l \<in> collect_locks las" by(simp add: collect_locks_def) lemma collect_locksE: "\<lbrakk> l \<in> collect_locks las; Lock \<in> set (las $ l) \<Longrightarrow> P \<rbrakk> \<Longrightarrow> P" by(simp add: collect_locks_def) lemma collect_locksD: "l \<in> collect_locks las \<Longrightarrow> Lock \<in> set (las $ l)" by(simp add: collect_locks_def) fun must_acquire_lock :: "lock_action list \<Rightarrow> bool" where "must_acquire_lock [] = False" | "must_acquire_lock (Lock # las) = True" | "must_acquire_lock (Unlock # las) = False" | "must_acquire_lock (_ # las) = must_acquire_lock las" lemma must_acquire_lock_append: "must_acquire_lock (xs @ ys) \<longleftrightarrow> (if Lock \<in> set xs \<or> Unlock \<in> set xs then must_acquire_lock xs else must_acquire_lock ys)" proof(induct xs) case Nil thus ?case by simp next case (Cons L Ls) thus ?case by (cases L, simp_all) qed lemma must_acquire_lock_contains_lock: "must_acquire_lock las \<Longrightarrow> Lock \<in> set las" proof(induct las) case (Cons l las) thus ?case by(cases l) auto qed simp lemma must_acquire_lock_conv: "must_acquire_lock las = (case (filter (\<lambda>L. L = Lock \<or> L = Unlock) las) of [] \<Rightarrow> False | L # Ls \<Rightarrow> L = Lock)" proof(induct las) case Nil thus ?case by simp next case (Cons LA LAS) thus ?case by(cases LA, auto split: list.split_asm) qed definition collect_locks' :: "'l lock_actions \<Rightarrow> 'l set" where "collect_locks' las \<equiv> {l. must_acquire_lock (las $ l)}" lemma collect_locks'I: "must_acquire_lock (las $ l) \<Longrightarrow> l \<in> collect_locks' las" by(simp add: collect_locks'_def) lemma collect_locks'E: "\<lbrakk> l \<in> collect_locks' las; must_acquire_lock (las $ l) \<Longrightarrow> P \<rbrakk> \<Longrightarrow> P" by(simp add: collect_locks'_def) lemma collect_locks'_subset_collect_locks: "collect_locks' las \<subseteq> collect_locks las" by(auto simp add: collect_locks'_def collect_locks_def intro: must_acquire_lock_contains_lock) definition lock_ok_las' :: "('l,'t) locks \<Rightarrow> 't \<Rightarrow> 'l lock_actions \<Rightarrow> bool" where "lock_ok_las' ls t las \<equiv> \<forall>l. lock_actions_ok' (ls $ l) t (las $ l)" lemma lock_ok_las'I: "(\<And>l. lock_actions_ok' (ls $ l) t (las $ l)) \<Longrightarrow> lock_ok_las' ls t las" by(simp add: lock_ok_las'_def) lemma lock_ok_las'D: "lock_ok_las' ls t las \<Longrightarrow> lock_actions_ok' (ls $ l) t (las $ l)" by(simp add: lock_ok_las'_def) lemma not_lock_ok_las'_conv: "\<not> lock_ok_las' ls t las \<longleftrightarrow> (\<exists>l. \<not> lock_actions_ok' (ls $ l) t (las $ l))" by(simp add: lock_ok_las'_def) lemma lock_ok_las'_code: "lock_ok_las' ls t las = finfun_All ((\<lambda>(l, la). lock_actions_ok' l t la) \<circ>$ ($ls, las$))" by(simp add: lock_ok_las'_def finfun_All_All o_def) lemma lock_ok_las'_collect_locks'_may_lock: assumes lot': "lock_ok_las' ls t las" and mayl: "\<forall>l \<in> collect_locks' las. may_lock (ls $ l) t" and l: "l \<in> collect_locks las" shows "may_lock (ls $ l) t" proof(cases "l \<in> collect_locks' las") case True thus ?thesis using mayl by auto next case False hence nmal: "\<not> must_acquire_lock (las $ l)" by(auto intro: collect_locks'I) from l have locklasl: "Lock \<in> set (las $ l)" by(rule collect_locksD) then obtain ys zs where las: "las $ l = ys @ Lock # zs" and notin: "Lock \<notin> set ys" by(auto dest: split_list_first) from lot' have "lock_actions_ok' (ls $ l) t (las $ l)" by(auto simp add: lock_ok_las'_def) thus ?thesis proof(induct rule: lock_actions_ok'E) case ok with locklasl show ?thesis by -(rule lock_actions_ok_Lock_may_lock) next case (Lock YS ZS) note LAS = `las $ l = YS @ Lock # ZS` note lao = `lock_actions_ok (ls $ l) t YS` note nml = `\<not> may_lock (upd_locks (ls $ l) t YS) t` from LAS las nmal notin have "Unlock \<in> set YS" by -(erule contrapos_np, auto simp add: must_acquire_lock_append append_eq_append_conv2 append_eq_Cons_conv) then obtain ys' zs' where YS: "YS = ys' @ Unlock # zs'" and unlock: "Unlock \<notin> set ys'" by(auto dest: split_list_first) from YS las LAS lao have lao': "lock_actions_ok (ls $ l) t (ys' @ [Unlock])" by(auto) hence "has_lock (upd_locks (ls $ l) t ys') t" by simp hence "may_lock (upd_locks (ls $ l) t ys') t" by(rule has_lock_may_lock) moreover from lao' have "lock_actions_ok (ls $ l) t ys'" by simp ultimately show ?thesis by simp qed qed lemma lock_actions_ok'_must_acquire_lock_lock_actions_ok: "\<lbrakk> lock_actions_ok' l t Ls; must_acquire_lock Ls \<longrightarrow> may_lock l t\<rbrakk> \<Longrightarrow> lock_actions_ok l t Ls" proof(induct l t Ls rule: lock_actions_ok.induct) case 1 thus ?case by simp next case (2 l t L LS) thus ?case proof(cases "L = Lock \<or> L = Unlock") case True with 2 show ?thesis by(auto simp add: lock_actions_ok'_iff Cons_eq_append_conv intro: has_lock_may_lock) qed(cases L, auto) qed lemma lock_ok_las'_collect_locks_lock_ok_las: assumes lol': "lock_ok_las' ls t las" and clml: "\<And>l. l \<in> collect_locks las \<Longrightarrow> may_lock (ls $ l) t" shows "lock_ok_las ls t las" proof(rule lock_ok_lasI) fix l from lol' have "lock_actions_ok' (ls $ l) t (las $ l)" by(rule lock_ok_las'D) thus "lock_actions_ok (ls $ l) t (las $ l)" proof(rule lock_actions_ok'_must_acquire_lock_lock_actions_ok[OF _ impI]) assume mal: "must_acquire_lock (las $ l)" thus "may_lock (ls $ l) t" by(auto intro!: clml collect_locksI elim: must_acquire_lock_contains_lock ) qed qed lemma lock_ok_las'_into_lock_on_las: "\<lbrakk>lock_ok_las' ls t las; \<And>l. l \<in> collect_locks' las \<Longrightarrow> may_lock (ls $ l) t\<rbrakk> \<Longrightarrow> lock_ok_las ls t las" by (metis lock_ok_las'_collect_locks'_may_lock lock_ok_las'_collect_locks_lock_ok_las) end
# Copyright (c) 2018-2021, Carnegie Mellon University # See LICENSE for details _printattr := x->When((x=[] and TYPE(x)="string") or (x<>[] and IsString(x)), Print("\"", x, "\""), Print(x)); attrTakeA := (to, from) -> When(IsRec(to) and IsBound(to.takeAobj), to.takeAobj(from), to); Class(AttrMixin, rec( a := rec(), setA := meth(arg) local self, i, a, f, val; a := rec(); self := arg[1]; for i in [2..Length(arg)] do if IsVarMap(arg[i]) then f := NameOf(arg[i][1]); val := Eval(arg[i][2]); a.(f) := val; elif IsList(arg[i]) and Length(arg[i]) in [0,2] then if Length(arg[i])>0 then [f, val] := arg[i]; a.(f) := val; fi; else return Error("arg[i] must be a list or varmap"); fi; od; return CopyFields(self, rec(a:=a)); end, withA := meth(arg) local self, res, set; self := arg[1]; set := self.setA; res := ApplyFunc(set, arg); res.a := CopyFields(self.a, res.a); return res; end, hasA := (self, attr) >> Cond(IsBound(self.a.(attr)), true, false), # getA(<attr>, <def> = false) - returns attribute value. # Optional <def> parameter is value to return when attribute is not found. getA := (arg) >> let( self := arg[1], attr := arg[2], def := When(Length(arg)>2, arg[3], false), Cond(IsBound(self.a.(attr)), self.a.(attr), def)), printA := self >> let(flds := UserRecFields(self.a), Cond(flds=[], Print(""), Print(".setA(", DoForAllButLast(flds, x->Print(x, " => ", _printattr(self.a.(x)), ", ")), Last(flds), " => ", _printattr(self.a.(Last(flds))), ")"))), takeA := meth(self, a) self.a := CopyFields(a); return self; end, appendA := meth(self, a) self.a := CopyFields(self.a, a); return self; end, takeAobj := meth(self, obj) self.a := CopyFields(obj.a); return self; end, appendAobj := meth(self, obj) self.a := CopyFields(self.a, obj.a); return self; end, attrs := ~.takeAobj, # testA( attr, v = true ) returns true if object has attribute <attr> with value equal to <v> testA := (arg) >> let( self := arg[1], attr := arg[2], v := When(IsBound(arg[3]), arg[3], true), self.hasA(attr) and self.getA(attr) = v), dropA := meth(arg) local obj, d, s; obj := ShallowCopy(arg[1]); d := Drop(arg, 1); if Length(arg)=1 then Unbind(obj.a); elif ForAll(d, IsString) then obj.a := ShallowCopy(obj.a); for s in d do Unbind(obj.a.(s)); od; else Error("Usage: dropA([ <attr_name_string>[, <attr_name_string>[, ...]] ])"); fi; return obj; end, # listA() returns list of attribute names and values in [[name, value],...] form. listA := (self) >> List(Sort(UserRecFields(self.a)), e -> [e, self.a.(e)]), ));
[STATEMENT] lemma vCons_carrier_vec[simp]: "vCons a v \<in> carrier_vec (Suc n) \<longleftrightarrow> v \<in> carrier_vec n" [PROOF STATE] proof (prove) goal (1 subgoal): 1. (vCons a v \<in> carrier_vec (Suc n)) = (v \<in> carrier_vec n) [PROOF STEP] by (auto dest!: carrier_vecD intro: carrier_vecI)
State Before: α : Type u_2 β : Type u_1 γ : Type u_3 δ : Type ?u.362154 inst✝⁴ : AddCommMonoid α inst✝³ : TopologicalSpace α inst✝² : T2Space α f g : β → α a a₁ a₂ : α inst✝¹ : Encodable γ inst✝ : CompleteLattice β m : β → α m0 : m ⊥ = 0 s : γ → β ⊢ (∑' (i : ℕ), m (⨆ (b : γ) (_ : b ∈ decode₂ γ i), s b)) = ∑' (b : γ), m (s b) State After: α : Type u_2 β : Type u_1 γ : Type u_3 δ : Type ?u.362154 inst✝⁴ : AddCommMonoid α inst✝³ : TopologicalSpace α inst✝² : T2Space α f g : β → α a a₁ a₂ : α inst✝¹ : Encodable γ inst✝ : CompleteLattice β m : β → α m0 : m ⊥ = 0 s : γ → β H : ∀ (n : ℕ), m (⨆ (b : γ) (_ : b ∈ decode₂ γ n), s b) ≠ 0 → Option.isSome (decode₂ γ n) = true ⊢ (∑' (i : ℕ), m (⨆ (b : γ) (_ : b ∈ decode₂ γ i), s b)) = ∑' (b : γ), m (s b) Tactic: have H : ∀ n, m (⨆ b ∈ decode₂ γ n, s b) ≠ 0 → (decode₂ γ n).isSome :=by intro n h generalize decode₂ γ n = foo at * cases' foo with b . refine' (h <| by simp [m0]).elim . exact rfl State Before: α : Type u_2 β : Type u_1 γ : Type u_3 δ : Type ?u.362154 inst✝⁴ : AddCommMonoid α inst✝³ : TopologicalSpace α inst✝² : T2Space α f g : β → α a a₁ a₂ : α inst✝¹ : Encodable γ inst✝ : CompleteLattice β m : β → α m0 : m ⊥ = 0 s : γ → β H : ∀ (n : ℕ), m (⨆ (b : γ) (_ : b ∈ decode₂ γ n), s b) ≠ 0 → Option.isSome (decode₂ γ n) = true ⊢ (∑' (i : ℕ), m (⨆ (b : γ) (_ : b ∈ decode₂ γ i), s b)) = ∑' (b : γ), m (s b) State After: α : Type u_2 β : Type u_1 γ : Type u_3 δ : Type ?u.362154 inst✝⁴ : AddCommMonoid α inst✝³ : TopologicalSpace α inst✝² : T2Space α f g : β → α a a₁ a₂ : α inst✝¹ : Encodable γ inst✝ : CompleteLattice β m : β → α m0 : m ⊥ = 0 s : γ → β H : ∀ (n : ℕ), m (⨆ (b : γ) (_ : b ∈ decode₂ γ n), s b) ≠ 0 → Option.isSome (decode₂ γ n) = true ⊢ (∑' (b : γ), m (s b)) = ∑' (i : ℕ), m (⨆ (b : γ) (_ : b ∈ decode₂ γ i), s b) Tactic: symm State Before: α : Type u_2 β : Type u_1 γ : Type u_3 δ : Type ?u.362154 inst✝⁴ : AddCommMonoid α inst✝³ : TopologicalSpace α inst✝² : T2Space α f g : β → α a a₁ a₂ : α inst✝¹ : Encodable γ inst✝ : CompleteLattice β m : β → α m0 : m ⊥ = 0 s : γ → β H : ∀ (n : ℕ), m (⨆ (b : γ) (_ : b ∈ decode₂ γ n), s b) ≠ 0 → Option.isSome (decode₂ γ n) = true ⊢ (∑' (b : γ), m (s b)) = ∑' (i : ℕ), m (⨆ (b : γ) (_ : b ∈ decode₂ γ i), s b) State After: case refine'_1 α : Type u_2 β : Type u_1 γ : Type u_3 δ : Type ?u.362154 inst✝⁴ : AddCommMonoid α inst✝³ : TopologicalSpace α inst✝² : T2Space α f g : β → α a a₁ a₂ : α inst✝¹ : Encodable γ inst✝ : CompleteLattice β m : β → α m0 : m ⊥ = 0 s : γ → β H : ∀ (n : ℕ), m (⨆ (b : γ) (_ : b ∈ decode₂ γ n), s b) ≠ 0 → Option.isSome (decode₂ γ n) = true ⊢ ∀ ⦃x y : ↑(support fun i => m (⨆ (b : γ) (_ : b ∈ decode₂ γ i), s b))⦄, (fun a => Option.get (decode₂ γ ↑a) (_ : Option.isSome (decode₂ γ ↑a) = true)) x = (fun a => Option.get (decode₂ γ ↑a) (_ : Option.isSome (decode₂ γ ↑a) = true)) y → ↑x = ↑y case refine'_2 α : Type u_2 β : Type u_1 γ : Type u_3 δ : Type ?u.362154 inst✝⁴ : AddCommMonoid α inst✝³ : TopologicalSpace α inst✝² : T2Space α f g : β → α a a₁ a₂ : α inst✝¹ : Encodable γ inst✝ : CompleteLattice β m : β → α m0 : m ⊥ = 0 s : γ → β H : ∀ (n : ℕ), m (⨆ (b : γ) (_ : b ∈ decode₂ γ n), s b) ≠ 0 → Option.isSome (decode₂ γ n) = true ⊢ (support fun b => m (s b)) ⊆ Set.range fun a => Option.get (decode₂ γ ↑a) (_ : Option.isSome (decode₂ γ ↑a) = true) case refine'_3 α : Type u_2 β : Type u_1 γ : Type u_3 δ : Type ?u.362154 inst✝⁴ : AddCommMonoid α inst✝³ : TopologicalSpace α inst✝² : T2Space α f g : β → α a a₁ a₂ : α inst✝¹ : Encodable γ inst✝ : CompleteLattice β m : β → α m0 : m ⊥ = 0 s : γ → β H : ∀ (n : ℕ), m (⨆ (b : γ) (_ : b ∈ decode₂ γ n), s b) ≠ 0 → Option.isSome (decode₂ γ n) = true ⊢ ∀ (x : ↑(support fun i => m (⨆ (b : γ) (_ : b ∈ decode₂ γ i), s b))), m (s ((fun a => Option.get (decode₂ γ ↑a) (_ : Option.isSome (decode₂ γ ↑a) = true)) x)) = m (⨆ (b : γ) (_ : b ∈ decode₂ γ ↑x), s b) Tactic: refine' tsum_eq_tsum_of_ne_zero_bij (fun a => Option.get _ (H a.1 a.2)) _ _ _ State Before: α : Type u_2 β : Type u_1 γ : Type u_3 δ : Type ?u.362154 inst✝⁴ : AddCommMonoid α inst✝³ : TopologicalSpace α inst✝² : T2Space α f g : β → α a a₁ a₂ : α inst✝¹ : Encodable γ inst✝ : CompleteLattice β m : β → α m0 : m ⊥ = 0 s : γ → β ⊢ ∀ (n : ℕ), m (⨆ (b : γ) (_ : b ∈ decode₂ γ n), s b) ≠ 0 → Option.isSome (decode₂ γ n) = true State After: α : Type u_2 β : Type u_1 γ : Type u_3 δ : Type ?u.362154 inst✝⁴ : AddCommMonoid α inst✝³ : TopologicalSpace α inst✝² : T2Space α f g : β → α a a₁ a₂ : α inst✝¹ : Encodable γ inst✝ : CompleteLattice β m : β → α m0 : m ⊥ = 0 s : γ → β n : ℕ h : m (⨆ (b : γ) (_ : b ∈ decode₂ γ n), s b) ≠ 0 ⊢ Option.isSome (decode₂ γ n) = true Tactic: intro n h State Before: α : Type u_2 β : Type u_1 γ : Type u_3 δ : Type ?u.362154 inst✝⁴ : AddCommMonoid α inst✝³ : TopologicalSpace α inst✝² : T2Space α f g : β → α a a₁ a₂ : α inst✝¹ : Encodable γ inst✝ : CompleteLattice β m : β → α m0 : m ⊥ = 0 s : γ → β n : ℕ h : m (⨆ (b : γ) (_ : b ∈ decode₂ γ n), s b) ≠ 0 ⊢ Option.isSome (decode₂ γ n) = true State After: α : Type u_2 β : Type u_1 γ : Type u_3 δ : Type ?u.362154 inst✝⁴ : AddCommMonoid α inst✝³ : TopologicalSpace α inst✝² : T2Space α f g : β → α a a₁ a₂ : α inst✝¹ : Encodable γ inst✝ : CompleteLattice β m : β → α m0 : m ⊥ = 0 s : γ → β n : ℕ foo : Option γ h : m (⨆ (b : γ) (_ : b ∈ foo), s b) ≠ 0 ⊢ Option.isSome foo = true Tactic: generalize decode₂ γ n = foo at * State Before: α : Type u_2 β : Type u_1 γ : Type u_3 δ : Type ?u.362154 inst✝⁴ : AddCommMonoid α inst✝³ : TopologicalSpace α inst✝² : T2Space α f g : β → α a a₁ a₂ : α inst✝¹ : Encodable γ inst✝ : CompleteLattice β m : β → α m0 : m ⊥ = 0 s : γ → β n : ℕ foo : Option γ h : m (⨆ (b : γ) (_ : b ∈ foo), s b) ≠ 0 ⊢ Option.isSome foo = true State After: case none α : Type u_2 β : Type u_1 γ : Type u_3 δ : Type ?u.362154 inst✝⁴ : AddCommMonoid α inst✝³ : TopologicalSpace α inst✝² : T2Space α f g : β → α a a₁ a₂ : α inst✝¹ : Encodable γ inst✝ : CompleteLattice β m : β → α m0 : m ⊥ = 0 s : γ → β n : ℕ h : m (⨆ (b : γ) (_ : b ∈ none), s b) ≠ 0 ⊢ Option.isSome none = true case some α : Type u_2 β : Type u_1 γ : Type u_3 δ : Type ?u.362154 inst✝⁴ : AddCommMonoid α inst✝³ : TopologicalSpace α inst✝² : T2Space α f g : β → α a a₁ a₂ : α inst✝¹ : Encodable γ inst✝ : CompleteLattice β m : β → α m0 : m ⊥ = 0 s : γ → β n : ℕ b : γ h : m (⨆ (b_1 : γ) (_ : b_1 ∈ some b), s b_1) ≠ 0 ⊢ Option.isSome (some b) = true Tactic: cases' foo with b State Before: case none α : Type u_2 β : Type u_1 γ : Type u_3 δ : Type ?u.362154 inst✝⁴ : AddCommMonoid α inst✝³ : TopologicalSpace α inst✝² : T2Space α f g : β → α a a₁ a₂ : α inst✝¹ : Encodable γ inst✝ : CompleteLattice β m : β → α m0 : m ⊥ = 0 s : γ → β n : ℕ h : m (⨆ (b : γ) (_ : b ∈ none), s b) ≠ 0 ⊢ Option.isSome none = true case some α : Type u_2 β : Type u_1 γ : Type u_3 δ : Type ?u.362154 inst✝⁴ : AddCommMonoid α inst✝³ : TopologicalSpace α inst✝² : T2Space α f g : β → α a a₁ a₂ : α inst✝¹ : Encodable γ inst✝ : CompleteLattice β m : β → α m0 : m ⊥ = 0 s : γ → β n : ℕ b : γ h : m (⨆ (b_1 : γ) (_ : b_1 ∈ some b), s b_1) ≠ 0 ⊢ Option.isSome (some b) = true State After: case some α : Type u_2 β : Type u_1 γ : Type u_3 δ : Type ?u.362154 inst✝⁴ : AddCommMonoid α inst✝³ : TopologicalSpace α inst✝² : T2Space α f g : β → α a a₁ a₂ : α inst✝¹ : Encodable γ inst✝ : CompleteLattice β m : β → α m0 : m ⊥ = 0 s : γ → β n : ℕ b : γ h : m (⨆ (b_1 : γ) (_ : b_1 ∈ some b), s b_1) ≠ 0 ⊢ Option.isSome (some b) = true Tactic: . refine' (h <| by simp [m0]).elim State Before: case some α : Type u_2 β : Type u_1 γ : Type u_3 δ : Type ?u.362154 inst✝⁴ : AddCommMonoid α inst✝³ : TopologicalSpace α inst✝² : T2Space α f g : β → α a a₁ a₂ : α inst✝¹ : Encodable γ inst✝ : CompleteLattice β m : β → α m0 : m ⊥ = 0 s : γ → β n : ℕ b : γ h : m (⨆ (b_1 : γ) (_ : b_1 ∈ some b), s b_1) ≠ 0 ⊢ Option.isSome (some b) = true State After: no goals Tactic: . exact rfl State Before: case none α : Type u_2 β : Type u_1 γ : Type u_3 δ : Type ?u.362154 inst✝⁴ : AddCommMonoid α inst✝³ : TopologicalSpace α inst✝² : T2Space α f g : β → α a a₁ a₂ : α inst✝¹ : Encodable γ inst✝ : CompleteLattice β m : β → α m0 : m ⊥ = 0 s : γ → β n : ℕ h : m (⨆ (b : γ) (_ : b ∈ none), s b) ≠ 0 ⊢ Option.isSome none = true State After: no goals Tactic: refine' (h <| by simp [m0]).elim State Before: α : Type u_2 β : Type u_1 γ : Type u_3 δ : Type ?u.362154 inst✝⁴ : AddCommMonoid α inst✝³ : TopologicalSpace α inst✝² : T2Space α f g : β → α a a₁ a₂ : α inst✝¹ : Encodable γ inst✝ : CompleteLattice β m : β → α m0 : m ⊥ = 0 s : γ → β n : ℕ h : m (⨆ (b : γ) (_ : b ∈ none), s b) ≠ 0 ⊢ m (⨆ (b : γ) (_ : b ∈ none), s b) = 0 State After: no goals Tactic: simp [m0] State Before: case some α : Type u_2 β : Type u_1 γ : Type u_3 δ : Type ?u.362154 inst✝⁴ : AddCommMonoid α inst✝³ : TopologicalSpace α inst✝² : T2Space α f g : β → α a a₁ a₂ : α inst✝¹ : Encodable γ inst✝ : CompleteLattice β m : β → α m0 : m ⊥ = 0 s : γ → β n : ℕ b : γ h : m (⨆ (b_1 : γ) (_ : b_1 ∈ some b), s b_1) ≠ 0 ⊢ Option.isSome (some b) = true State After: no goals Tactic: exact rfl State Before: case refine'_1 α : Type u_2 β : Type u_1 γ : Type u_3 δ : Type ?u.362154 inst✝⁴ : AddCommMonoid α inst✝³ : TopologicalSpace α inst✝² : T2Space α f g : β → α a a₁ a₂ : α inst✝¹ : Encodable γ inst✝ : CompleteLattice β m : β → α m0 : m ⊥ = 0 s : γ → β H : ∀ (n : ℕ), m (⨆ (b : γ) (_ : b ∈ decode₂ γ n), s b) ≠ 0 → Option.isSome (decode₂ γ n) = true ⊢ ∀ ⦃x y : ↑(support fun i => m (⨆ (b : γ) (_ : b ∈ decode₂ γ i), s b))⦄, (fun a => Option.get (decode₂ γ ↑a) (_ : Option.isSome (decode₂ γ ↑a) = true)) x = (fun a => Option.get (decode₂ γ ↑a) (_ : Option.isSome (decode₂ γ ↑a) = true)) y → ↑x = ↑y State After: case refine'_1 α : Type u_2 β : Type u_1 γ : Type u_3 δ : Type ?u.362154 inst✝⁴ : AddCommMonoid α inst✝³ : TopologicalSpace α inst✝² : T2Space α f g : β → α a a₁ a₂ : α inst✝¹ : Encodable γ inst✝ : CompleteLattice β m : β → α m0 : m ⊥ = 0 s : γ → β H : ∀ (n : ℕ), m (⨆ (b : γ) (_ : b ∈ decode₂ γ n), s b) ≠ 0 → Option.isSome (decode₂ γ n) = true ⊢ ∀ ⦃x y : ↑(support fun i => m (⨆ (b : γ) (_ : b ∈ decode₂ γ i), s b))⦄, Option.get (decode₂ γ ↑x) (_ : Option.isSome (decode₂ γ ↑x) = true) = Option.get (decode₂ γ ↑y) (_ : Option.isSome (decode₂ γ ↑y) = true) → ↑x = ↑y Tactic: dsimp only [] State Before: case refine'_1 α : Type u_2 β : Type u_1 γ : Type u_3 δ : Type ?u.362154 inst✝⁴ : AddCommMonoid α inst✝³ : TopologicalSpace α inst✝² : T2Space α f g : β → α a a₁ a₂ : α inst✝¹ : Encodable γ inst✝ : CompleteLattice β m : β → α m0 : m ⊥ = 0 s : γ → β H : ∀ (n : ℕ), m (⨆ (b : γ) (_ : b ∈ decode₂ γ n), s b) ≠ 0 → Option.isSome (decode₂ γ n) = true ⊢ ∀ ⦃x y : ↑(support fun i => m (⨆ (b : γ) (_ : b ∈ decode₂ γ i), s b))⦄, Option.get (decode₂ γ ↑x) (_ : Option.isSome (decode₂ γ ↑x) = true) = Option.get (decode₂ γ ↑y) (_ : Option.isSome (decode₂ γ ↑y) = true) → ↑x = ↑y State After: case refine'_1.mk.mk α : Type u_2 β : Type u_1 γ : Type u_3 δ : Type ?u.362154 inst✝⁴ : AddCommMonoid α inst✝³ : TopologicalSpace α inst✝² : T2Space α f g : β → α a a₁ a₂ : α inst✝¹ : Encodable γ inst✝ : CompleteLattice β m✝ : β → α m0 : m✝ ⊥ = 0 s : γ → β H : ∀ (n : ℕ), m✝ (⨆ (b : γ) (_ : b ∈ decode₂ γ n), s b) ≠ 0 → Option.isSome (decode₂ γ n) = true m : ℕ hm : m ∈ support fun i => m✝ (⨆ (b : γ) (_ : b ∈ decode₂ γ i), s b) n : ℕ hn : n ∈ support fun i => m✝ (⨆ (b : γ) (_ : b ∈ decode₂ γ i), s b) e : Option.get (decode₂ γ ↑{ val := m, property := hm }) (_ : Option.isSome (decode₂ γ ↑{ val := m, property := hm }) = true) = Option.get (decode₂ γ ↑{ val := n, property := hn }) (_ : Option.isSome (decode₂ γ ↑{ val := n, property := hn }) = true) ⊢ ↑{ val := m, property := hm } = ↑{ val := n, property := hn } Tactic: rintro ⟨m, hm⟩ ⟨n, hn⟩ e State Before: case refine'_1.mk.mk α : Type u_2 β : Type u_1 γ : Type u_3 δ : Type ?u.362154 inst✝⁴ : AddCommMonoid α inst✝³ : TopologicalSpace α inst✝² : T2Space α f g : β → α a a₁ a₂ : α inst✝¹ : Encodable γ inst✝ : CompleteLattice β m✝ : β → α m0 : m✝ ⊥ = 0 s : γ → β H : ∀ (n : ℕ), m✝ (⨆ (b : γ) (_ : b ∈ decode₂ γ n), s b) ≠ 0 → Option.isSome (decode₂ γ n) = true m : ℕ hm : m ∈ support fun i => m✝ (⨆ (b : γ) (_ : b ∈ decode₂ γ i), s b) n : ℕ hn : n ∈ support fun i => m✝ (⨆ (b : γ) (_ : b ∈ decode₂ γ i), s b) e : Option.get (decode₂ γ ↑{ val := m, property := hm }) (_ : Option.isSome (decode₂ γ ↑{ val := m, property := hm }) = true) = Option.get (decode₂ γ ↑{ val := n, property := hn }) (_ : Option.isSome (decode₂ γ ↑{ val := n, property := hn }) = true) ⊢ ↑{ val := m, property := hm } = ↑{ val := n, property := hn } State After: case refine'_1.mk.mk α : Type u_2 β : Type u_1 γ : Type u_3 δ : Type ?u.362154 inst✝⁴ : AddCommMonoid α inst✝³ : TopologicalSpace α inst✝² : T2Space α f g : β → α a a₁ a₂ : α inst✝¹ : Encodable γ inst✝ : CompleteLattice β m✝ : β → α m0 : m✝ ⊥ = 0 s : γ → β H : ∀ (n : ℕ), m✝ (⨆ (b : γ) (_ : b ∈ decode₂ γ n), s b) ≠ 0 → Option.isSome (decode₂ γ n) = true m : ℕ hm : m ∈ support fun i => m✝ (⨆ (b : γ) (_ : b ∈ decode₂ γ i), s b) n : ℕ hn : n ∈ support fun i => m✝ (⨆ (b : γ) (_ : b ∈ decode₂ γ i), s b) e : Option.get (decode₂ γ ↑{ val := m, property := hm }) (_ : Option.isSome (decode₂ γ ↑{ val := m, property := hm }) = true) = Option.get (decode₂ γ ↑{ val := n, property := hn }) (_ : Option.isSome (decode₂ γ ↑{ val := n, property := hn }) = true) this : encode (Option.get (decode₂ γ n) (_ : Option.isSome (decode₂ γ n) = true)) = n ⊢ ↑{ val := m, property := hm } = ↑{ val := n, property := hn } Tactic: have := mem_decode₂.1 (Option.get_mem (H n hn)) State Before: case refine'_1.mk.mk α : Type u_2 β : Type u_1 γ : Type u_3 δ : Type ?u.362154 inst✝⁴ : AddCommMonoid α inst✝³ : TopologicalSpace α inst✝² : T2Space α f g : β → α a a₁ a₂ : α inst✝¹ : Encodable γ inst✝ : CompleteLattice β m✝ : β → α m0 : m✝ ⊥ = 0 s : γ → β H : ∀ (n : ℕ), m✝ (⨆ (b : γ) (_ : b ∈ decode₂ γ n), s b) ≠ 0 → Option.isSome (decode₂ γ n) = true m : ℕ hm : m ∈ support fun i => m✝ (⨆ (b : γ) (_ : b ∈ decode₂ γ i), s b) n : ℕ hn : n ∈ support fun i => m✝ (⨆ (b : γ) (_ : b ∈ decode₂ γ i), s b) e : Option.get (decode₂ γ ↑{ val := m, property := hm }) (_ : Option.isSome (decode₂ γ ↑{ val := m, property := hm }) = true) = Option.get (decode₂ γ ↑{ val := n, property := hn }) (_ : Option.isSome (decode₂ γ ↑{ val := n, property := hn }) = true) this : encode (Option.get (decode₂ γ n) (_ : Option.isSome (decode₂ γ n) = true)) = n ⊢ ↑{ val := m, property := hm } = ↑{ val := n, property := hn } State After: no goals Tactic: rwa [← e, mem_decode₂.1 (Option.get_mem (H m hm))] at this State Before: case refine'_2 α : Type u_2 β : Type u_1 γ : Type u_3 δ : Type ?u.362154 inst✝⁴ : AddCommMonoid α inst✝³ : TopologicalSpace α inst✝² : T2Space α f g : β → α a a₁ a₂ : α inst✝¹ : Encodable γ inst✝ : CompleteLattice β m : β → α m0 : m ⊥ = 0 s : γ → β H : ∀ (n : ℕ), m (⨆ (b : γ) (_ : b ∈ decode₂ γ n), s b) ≠ 0 → Option.isSome (decode₂ γ n) = true ⊢ (support fun b => m (s b)) ⊆ Set.range fun a => Option.get (decode₂ γ ↑a) (_ : Option.isSome (decode₂ γ ↑a) = true) State After: case refine'_2 α : Type u_2 β : Type u_1 γ : Type u_3 δ : Type ?u.362154 inst✝⁴ : AddCommMonoid α inst✝³ : TopologicalSpace α inst✝² : T2Space α f g : β → α a a₁ a₂ : α inst✝¹ : Encodable γ inst✝ : CompleteLattice β m : β → α m0 : m ⊥ = 0 s : γ → β H : ∀ (n : ℕ), m (⨆ (b : γ) (_ : b ∈ decode₂ γ n), s b) ≠ 0 → Option.isSome (decode₂ γ n) = true b : γ h : b ∈ support fun b => m (s b) ⊢ b ∈ Set.range fun a => Option.get (decode₂ γ ↑a) (_ : Option.isSome (decode₂ γ ↑a) = true) Tactic: intro b h State Before: case refine'_2 α : Type u_2 β : Type u_1 γ : Type u_3 δ : Type ?u.362154 inst✝⁴ : AddCommMonoid α inst✝³ : TopologicalSpace α inst✝² : T2Space α f g : β → α a a₁ a₂ : α inst✝¹ : Encodable γ inst✝ : CompleteLattice β m : β → α m0 : m ⊥ = 0 s : γ → β H : ∀ (n : ℕ), m (⨆ (b : γ) (_ : b ∈ decode₂ γ n), s b) ≠ 0 → Option.isSome (decode₂ γ n) = true b : γ h : b ∈ support fun b => m (s b) ⊢ b ∈ Set.range fun a => Option.get (decode₂ γ ↑a) (_ : Option.isSome (decode₂ γ ↑a) = true) State After: case refine'_2.refine'_1 α : Type u_2 β : Type u_1 γ : Type u_3 δ : Type ?u.362154 inst✝⁴ : AddCommMonoid α inst✝³ : TopologicalSpace α inst✝² : T2Space α f g : β → α a a₁ a₂ : α inst✝¹ : Encodable γ inst✝ : CompleteLattice β m : β → α m0 : m ⊥ = 0 s : γ → β H : ∀ (n : ℕ), m (⨆ (b : γ) (_ : b ∈ decode₂ γ n), s b) ≠ 0 → Option.isSome (decode₂ γ n) = true b : γ h : b ∈ support fun b => m (s b) ⊢ encode b ∈ support fun i => m (⨆ (b : γ) (_ : b ∈ decode₂ γ i), s b) case refine'_2.refine'_2 α : Type u_2 β : Type u_1 γ : Type u_3 δ : Type ?u.362154 inst✝⁴ : AddCommMonoid α inst✝³ : TopologicalSpace α inst✝² : T2Space α f g : β → α a a₁ a₂ : α inst✝¹ : Encodable γ inst✝ : CompleteLattice β m : β → α m0 : m ⊥ = 0 s : γ → β H : ∀ (n : ℕ), m (⨆ (b : γ) (_ : b ∈ decode₂ γ n), s b) ≠ 0 → Option.isSome (decode₂ γ n) = true b : γ h : b ∈ support fun b => m (s b) ⊢ (fun a => Option.get (decode₂ γ ↑a) (_ : Option.isSome (decode₂ γ ↑a) = true)) { val := encode b, property := ?refine'_2.refine'_1 } = b Tactic: refine' ⟨⟨encode b, _⟩, _⟩ State Before: case refine'_2.refine'_1 α : Type u_2 β : Type u_1 γ : Type u_3 δ : Type ?u.362154 inst✝⁴ : AddCommMonoid α inst✝³ : TopologicalSpace α inst✝² : T2Space α f g : β → α a a₁ a₂ : α inst✝¹ : Encodable γ inst✝ : CompleteLattice β m : β → α m0 : m ⊥ = 0 s : γ → β H : ∀ (n : ℕ), m (⨆ (b : γ) (_ : b ∈ decode₂ γ n), s b) ≠ 0 → Option.isSome (decode₂ γ n) = true b : γ h : b ∈ support fun b => m (s b) ⊢ encode b ∈ support fun i => m (⨆ (b : γ) (_ : b ∈ decode₂ γ i), s b) State After: case refine'_2.refine'_1 α : Type u_2 β : Type u_1 γ : Type u_3 δ : Type ?u.362154 inst✝⁴ : AddCommMonoid α inst✝³ : TopologicalSpace α inst✝² : T2Space α f g : β → α a a₁ a₂ : α inst✝¹ : Encodable γ inst✝ : CompleteLattice β m : β → α m0 : m ⊥ = 0 s : γ → β H : ∀ (n : ℕ), m (⨆ (b : γ) (_ : b ∈ decode₂ γ n), s b) ≠ 0 → Option.isSome (decode₂ γ n) = true b : γ h : m (s b) ≠ 0 ⊢ m (⨆ (b_1 : γ) (_ : b_1 ∈ some b), s b_1) ≠ 0 Tactic: simp only [mem_support, encodek₂] at h⊢ State Before: case refine'_2.refine'_1 α : Type u_2 β : Type u_1 γ : Type u_3 δ : Type ?u.362154 inst✝⁴ : AddCommMonoid α inst✝³ : TopologicalSpace α inst✝² : T2Space α f g : β → α a a₁ a₂ : α inst✝¹ : Encodable γ inst✝ : CompleteLattice β m : β → α m0 : m ⊥ = 0 s : γ → β H : ∀ (n : ℕ), m (⨆ (b : γ) (_ : b ∈ decode₂ γ n), s b) ≠ 0 → Option.isSome (decode₂ γ n) = true b : γ h : m (s b) ≠ 0 ⊢ m (⨆ (b_1 : γ) (_ : b_1 ∈ some b), s b_1) ≠ 0 State After: case h.e'_2.h.e'_1 α : Type u_2 β : Type u_1 γ : Type u_3 δ : Type ?u.362154 inst✝⁴ : AddCommMonoid α inst✝³ : TopologicalSpace α inst✝² : T2Space α f g : β → α a a₁ a₂ : α inst✝¹ : Encodable γ inst✝ : CompleteLattice β m : β → α m0 : m ⊥ = 0 s : γ → β H : ∀ (n : ℕ), m (⨆ (b : γ) (_ : b ∈ decode₂ γ n), s b) ≠ 0 → Option.isSome (decode₂ γ n) = true b : γ h : m (s b) ≠ 0 ⊢ (⨆ (b_1 : γ) (_ : b_1 ∈ some b), s b_1) = s b Tactic: convert h State Before: case h.e'_2.h.e'_1 α : Type u_2 β : Type u_1 γ : Type u_3 δ : Type ?u.362154 inst✝⁴ : AddCommMonoid α inst✝³ : TopologicalSpace α inst✝² : T2Space α f g : β → α a a₁ a₂ : α inst✝¹ : Encodable γ inst✝ : CompleteLattice β m : β → α m0 : m ⊥ = 0 s : γ → β H : ∀ (n : ℕ), m (⨆ (b : γ) (_ : b ∈ decode₂ γ n), s b) ≠ 0 → Option.isSome (decode₂ γ n) = true b : γ h : m (s b) ≠ 0 ⊢ (⨆ (b_1 : γ) (_ : b_1 ∈ some b), s b_1) = s b State After: no goals Tactic: simp [Set.ext_iff, encodek₂] State Before: case refine'_2.refine'_2 α : Type u_2 β : Type u_1 γ : Type u_3 δ : Type ?u.362154 inst✝⁴ : AddCommMonoid α inst✝³ : TopologicalSpace α inst✝² : T2Space α f g : β → α a a₁ a₂ : α inst✝¹ : Encodable γ inst✝ : CompleteLattice β m : β → α m0 : m ⊥ = 0 s : γ → β H : ∀ (n : ℕ), m (⨆ (b : γ) (_ : b ∈ decode₂ γ n), s b) ≠ 0 → Option.isSome (decode₂ γ n) = true b : γ h : b ∈ support fun b => m (s b) ⊢ (fun a => Option.get (decode₂ γ ↑a) (_ : Option.isSome (decode₂ γ ↑a) = true)) { val := encode b, property := (_ : encode b ∈ support fun i => m (⨆ (b : γ) (_ : b ∈ decode₂ γ i), s b)) } = b State After: no goals Tactic: exact Option.get_of_mem _ (encodek₂ _) State Before: case refine'_3 α : Type u_2 β : Type u_1 γ : Type u_3 δ : Type ?u.362154 inst✝⁴ : AddCommMonoid α inst✝³ : TopologicalSpace α inst✝² : T2Space α f g : β → α a a₁ a₂ : α inst✝¹ : Encodable γ inst✝ : CompleteLattice β m : β → α m0 : m ⊥ = 0 s : γ → β H : ∀ (n : ℕ), m (⨆ (b : γ) (_ : b ∈ decode₂ γ n), s b) ≠ 0 → Option.isSome (decode₂ γ n) = true ⊢ ∀ (x : ↑(support fun i => m (⨆ (b : γ) (_ : b ∈ decode₂ γ i), s b))), m (s ((fun a => Option.get (decode₂ γ ↑a) (_ : Option.isSome (decode₂ γ ↑a) = true)) x)) = m (⨆ (b : γ) (_ : b ∈ decode₂ γ ↑x), s b) State After: case refine'_3.mk α : Type u_2 β : Type u_1 γ : Type u_3 δ : Type ?u.362154 inst✝⁴ : AddCommMonoid α inst✝³ : TopologicalSpace α inst✝² : T2Space α f g : β → α a a₁ a₂ : α inst✝¹ : Encodable γ inst✝ : CompleteLattice β m : β → α m0 : m ⊥ = 0 s : γ → β H : ∀ (n : ℕ), m (⨆ (b : γ) (_ : b ∈ decode₂ γ n), s b) ≠ 0 → Option.isSome (decode₂ γ n) = true n : ℕ h : n ∈ support fun i => m (⨆ (b : γ) (_ : b ∈ decode₂ γ i), s b) ⊢ m (s ((fun a => Option.get (decode₂ γ ↑a) (_ : Option.isSome (decode₂ γ ↑a) = true)) { val := n, property := h })) = m (⨆ (b : γ) (_ : b ∈ decode₂ γ ↑{ val := n, property := h }), s b) Tactic: rintro ⟨n, h⟩ State Before: case refine'_3.mk α : Type u_2 β : Type u_1 γ : Type u_3 δ : Type ?u.362154 inst✝⁴ : AddCommMonoid α inst✝³ : TopologicalSpace α inst✝² : T2Space α f g : β → α a a₁ a₂ : α inst✝¹ : Encodable γ inst✝ : CompleteLattice β m : β → α m0 : m ⊥ = 0 s : γ → β H : ∀ (n : ℕ), m (⨆ (b : γ) (_ : b ∈ decode₂ γ n), s b) ≠ 0 → Option.isSome (decode₂ γ n) = true n : ℕ h : n ∈ support fun i => m (⨆ (b : γ) (_ : b ∈ decode₂ γ i), s b) ⊢ m (s ((fun a => Option.get (decode₂ γ ↑a) (_ : Option.isSome (decode₂ γ ↑a) = true)) { val := n, property := h })) = m (⨆ (b : γ) (_ : b ∈ decode₂ γ ↑{ val := n, property := h }), s b) State After: case refine'_3.mk α : Type u_2 β : Type u_1 γ : Type u_3 δ : Type ?u.362154 inst✝⁴ : AddCommMonoid α inst✝³ : TopologicalSpace α inst✝² : T2Space α f g : β → α a a₁ a₂ : α inst✝¹ : Encodable γ inst✝ : CompleteLattice β m : β → α m0 : m ⊥ = 0 s : γ → β H : ∀ (n : ℕ), m (⨆ (b : γ) (_ : b ∈ decode₂ γ n), s b) ≠ 0 → Option.isSome (decode₂ γ n) = true n : ℕ h : n ∈ support fun i => m (⨆ (b : γ) (_ : b ∈ decode₂ γ i), s b) ⊢ m (s (Option.get (decode₂ γ n) (_ : Option.isSome (decode₂ γ n) = true))) = m (⨆ (b : γ) (_ : b ∈ decode₂ γ n), s b) Tactic: dsimp only [Subtype.coe_mk] State Before: case refine'_3.mk α : Type u_2 β : Type u_1 γ : Type u_3 δ : Type ?u.362154 inst✝⁴ : AddCommMonoid α inst✝³ : TopologicalSpace α inst✝² : T2Space α f g : β → α a a₁ a₂ : α inst✝¹ : Encodable γ inst✝ : CompleteLattice β m : β → α m0 : m ⊥ = 0 s : γ → β H : ∀ (n : ℕ), m (⨆ (b : γ) (_ : b ∈ decode₂ γ n), s b) ≠ 0 → Option.isSome (decode₂ γ n) = true n : ℕ h : n ∈ support fun i => m (⨆ (b : γ) (_ : b ∈ decode₂ γ i), s b) ⊢ m (s (Option.get (decode₂ γ n) (_ : Option.isSome (decode₂ γ n) = true))) = m (⨆ (b : γ) (_ : b ∈ decode₂ γ n), s b) State After: α : Type u_2 β : Type u_1 γ : Type u_3 δ : Type ?u.362154 inst✝⁴ : AddCommMonoid α inst✝³ : TopologicalSpace α inst✝² : T2Space α f g : β → α a a₁ a₂ : α inst✝¹ : Encodable γ inst✝ : CompleteLattice β m : β → α m0 : m ⊥ = 0 s : γ → β H : ∀ (n : ℕ), m (⨆ (b : γ) (_ : b ∈ decode₂ γ n), s b) ≠ 0 → Option.isSome (decode₂ γ n) = true n : ℕ h : n ∈ support fun i => m (⨆ (b : γ) (_ : b ∈ decode₂ γ i), s b) ⊢ m (s (Option.get (decode₂ γ n) (_ : Option.isSome (decode₂ γ n) = true))) = ?m.371147 α : Type u_2 β : Type u_1 γ : Type u_3 δ : Type ?u.362154 inst✝⁴ : AddCommMonoid α inst✝³ : TopologicalSpace α inst✝² : T2Space α f g : β → α a a₁ a₂ : α inst✝¹ : Encodable γ inst✝ : CompleteLattice β m : β → α m0 : m ⊥ = 0 s : γ → β H : ∀ (n : ℕ), m (⨆ (b : γ) (_ : b ∈ decode₂ γ n), s b) ≠ 0 → Option.isSome (decode₂ γ n) = true n : ℕ h : n ∈ support fun i => m (⨆ (b : γ) (_ : b ∈ decode₂ γ i), s b) ⊢ ?m.371147 = m (⨆ (b : γ) (_ : b ∈ decode₂ γ n), s b) α : Type u_2 β : Type u_1 γ : Type u_3 δ : Type ?u.362154 inst✝⁴ : AddCommMonoid α inst✝³ : TopologicalSpace α inst✝² : T2Space α f g : β → α a a₁ a₂ : α inst✝¹ : Encodable γ inst✝ : CompleteLattice β m : β → α m0 : m ⊥ = 0 s : γ → β H : ∀ (n : ℕ), m (⨆ (b : γ) (_ : b ∈ decode₂ γ n), s b) ≠ 0 → Option.isSome (decode₂ γ n) = true n : ℕ h : n ∈ support fun i => m (⨆ (b : γ) (_ : b ∈ decode₂ γ i), s b) ⊢ α Tactic: trans State Before: α : Type u_2 β : Type u_1 γ : Type u_3 δ : Type ?u.362154 inst✝⁴ : AddCommMonoid α inst✝³ : TopologicalSpace α inst✝² : T2Space α f g : β → α a a₁ a₂ : α inst✝¹ : Encodable γ inst✝ : CompleteLattice β m : β → α m0 : m ⊥ = 0 s : γ → β H : ∀ (n : ℕ), m (⨆ (b : γ) (_ : b ∈ decode₂ γ n), s b) ≠ 0 → Option.isSome (decode₂ γ n) = true n : ℕ h : n ∈ support fun i => m (⨆ (b : γ) (_ : b ∈ decode₂ γ i), s b) ⊢ m (s (Option.get (decode₂ γ n) (_ : Option.isSome (decode₂ γ n) = true))) = ?m.371147 α : Type u_2 β : Type u_1 γ : Type u_3 δ : Type ?u.362154 inst✝⁴ : AddCommMonoid α inst✝³ : TopologicalSpace α inst✝² : T2Space α f g : β → α a a₁ a₂ : α inst✝¹ : Encodable γ inst✝ : CompleteLattice β m : β → α m0 : m ⊥ = 0 s : γ → β H : ∀ (n : ℕ), m (⨆ (b : γ) (_ : b ∈ decode₂ γ n), s b) ≠ 0 → Option.isSome (decode₂ γ n) = true n : ℕ h : n ∈ support fun i => m (⨆ (b : γ) (_ : b ∈ decode₂ γ i), s b) ⊢ ?m.371147 = m (⨆ (b : γ) (_ : b ∈ decode₂ γ n), s b) α : Type u_2 β : Type u_1 γ : Type u_3 δ : Type ?u.362154 inst✝⁴ : AddCommMonoid α inst✝³ : TopologicalSpace α inst✝² : T2Space α f g : β → α a a₁ a₂ : α inst✝¹ : Encodable γ inst✝ : CompleteLattice β m : β → α m0 : m ⊥ = 0 s : γ → β H : ∀ (n : ℕ), m (⨆ (b : γ) (_ : b ∈ decode₂ γ n), s b) ≠ 0 → Option.isSome (decode₂ γ n) = true n : ℕ h : n ∈ support fun i => m (⨆ (b : γ) (_ : b ∈ decode₂ γ i), s b) ⊢ α State After: α : Type u_2 β : Type u_1 γ : Type u_3 δ : Type ?u.362154 inst✝⁴ : AddCommMonoid α inst✝³ : TopologicalSpace α inst✝² : T2Space α f g : β → α a a₁ a₂ : α inst✝¹ : Encodable γ inst✝ : CompleteLattice β m : β → α m0 : m ⊥ = 0 s : γ → β H : ∀ (n : ℕ), m (⨆ (b : γ) (_ : b ∈ decode₂ γ n), s b) ≠ 0 → Option.isSome (decode₂ γ n) = true n : ℕ h : n ∈ support fun i => m (⨆ (b : γ) (_ : b ∈ decode₂ γ i), s b) ⊢ ?m.371147 = m (⨆ (b : γ) (_ : b ∈ decode₂ γ n), s b) α : Type u_2 β : Type u_1 γ : Type u_3 δ : Type ?u.362154 inst✝⁴ : AddCommMonoid α inst✝³ : TopologicalSpace α inst✝² : T2Space α f g : β → α a a₁ a₂ : α inst✝¹ : Encodable γ inst✝ : CompleteLattice β m : β → α m0 : m ⊥ = 0 s : γ → β H : ∀ (n : ℕ), m (⨆ (b : γ) (_ : b ∈ decode₂ γ n), s b) ≠ 0 → Option.isSome (decode₂ γ n) = true n : ℕ h : n ∈ support fun i => m (⨆ (b : γ) (_ : b ∈ decode₂ γ i), s b) ⊢ m (s (Option.get (decode₂ γ n) (_ : Option.isSome (decode₂ γ n) = true))) = ?m.371147 α : Type u_2 β : Type u_1 γ : Type u_3 δ : Type ?u.362154 inst✝⁴ : AddCommMonoid α inst✝³ : TopologicalSpace α inst✝² : T2Space α f g : β → α a a₁ a₂ : α inst✝¹ : Encodable γ inst✝ : CompleteLattice β m : β → α m0 : m ⊥ = 0 s : γ → β H : ∀ (n : ℕ), m (⨆ (b : γ) (_ : b ∈ decode₂ γ n), s b) ≠ 0 → Option.isSome (decode₂ γ n) = true n : ℕ h : n ∈ support fun i => m (⨆ (b : γ) (_ : b ∈ decode₂ γ i), s b) ⊢ α Tactic: swap State Before: α : Type u_2 β : Type u_1 γ : Type u_3 δ : Type ?u.362154 inst✝⁴ : AddCommMonoid α inst✝³ : TopologicalSpace α inst✝² : T2Space α f g : β → α a a₁ a₂ : α inst✝¹ : Encodable γ inst✝ : CompleteLattice β m : β → α m0 : m ⊥ = 0 s : γ → β H : ∀ (n : ℕ), m (⨆ (b : γ) (_ : b ∈ decode₂ γ n), s b) ≠ 0 → Option.isSome (decode₂ γ n) = true n : ℕ h : n ∈ support fun i => m (⨆ (b : γ) (_ : b ∈ decode₂ γ i), s b) ⊢ ?m.371147 = m (⨆ (b : γ) (_ : b ∈ decode₂ γ n), s b) α : Type u_2 β : Type u_1 γ : Type u_3 δ : Type ?u.362154 inst✝⁴ : AddCommMonoid α inst✝³ : TopologicalSpace α inst✝² : T2Space α f g : β → α a a₁ a₂ : α inst✝¹ : Encodable γ inst✝ : CompleteLattice β m : β → α m0 : m ⊥ = 0 s : γ → β H : ∀ (n : ℕ), m (⨆ (b : γ) (_ : b ∈ decode₂ γ n), s b) ≠ 0 → Option.isSome (decode₂ γ n) = true n : ℕ h : n ∈ support fun i => m (⨆ (b : γ) (_ : b ∈ decode₂ γ i), s b) ⊢ m (s (Option.get (decode₂ γ n) (_ : Option.isSome (decode₂ γ n) = true))) = ?m.371147 α : Type u_2 β : Type u_1 γ : Type u_3 δ : Type ?u.362154 inst✝⁴ : AddCommMonoid α inst✝³ : TopologicalSpace α inst✝² : T2Space α f g : β → α a a₁ a₂ : α inst✝¹ : Encodable γ inst✝ : CompleteLattice β m : β → α m0 : m ⊥ = 0 s : γ → β H : ∀ (n : ℕ), m (⨆ (b : γ) (_ : b ∈ decode₂ γ n), s b) ≠ 0 → Option.isSome (decode₂ γ n) = true n : ℕ h : n ∈ support fun i => m (⨆ (b : γ) (_ : b ∈ decode₂ γ i), s b) ⊢ α State After: α : Type u_2 β : Type u_1 γ : Type u_3 δ : Type ?u.362154 inst✝⁴ : AddCommMonoid α inst✝³ : TopologicalSpace α inst✝² : T2Space α f g : β → α a a₁ a₂ : α inst✝¹ : Encodable γ inst✝ : CompleteLattice β m : β → α m0 : m ⊥ = 0 s : γ → β H : ∀ (n : ℕ), m (⨆ (b : γ) (_ : b ∈ decode₂ γ n), s b) ≠ 0 → Option.isSome (decode₂ γ n) = true n : ℕ h : n ∈ support fun i => m (⨆ (b : γ) (_ : b ∈ decode₂ γ i), s b) ⊢ m (s (Option.get (decode₂ γ n) (_ : Option.isSome (decode₂ γ n) = true))) = m (⨆ (b : γ) (_ : b ∈ some (Option.get (decode₂ γ n) (_ : Option.isSome (decode₂ γ n) = true))), s b) Tactic: rw [show decode₂ γ n = _ from Option.get_mem (H n h)] State Before: α : Type u_2 β : Type u_1 γ : Type u_3 δ : Type ?u.362154 inst✝⁴ : AddCommMonoid α inst✝³ : TopologicalSpace α inst✝² : T2Space α f g : β → α a a₁ a₂ : α inst✝¹ : Encodable γ inst✝ : CompleteLattice β m : β → α m0 : m ⊥ = 0 s : γ → β H : ∀ (n : ℕ), m (⨆ (b : γ) (_ : b ∈ decode₂ γ n), s b) ≠ 0 → Option.isSome (decode₂ γ n) = true n : ℕ h : n ∈ support fun i => m (⨆ (b : γ) (_ : b ∈ decode₂ γ i), s b) ⊢ m (s (Option.get (decode₂ γ n) (_ : Option.isSome (decode₂ γ n) = true))) = m (⨆ (b : γ) (_ : b ∈ some (Option.get (decode₂ γ n) (_ : Option.isSome (decode₂ γ n) = true))), s b) State After: case e_a α : Type u_2 β : Type u_1 γ : Type u_3 δ : Type ?u.362154 inst✝⁴ : AddCommMonoid α inst✝³ : TopologicalSpace α inst✝² : T2Space α f g : β → α a a₁ a₂ : α inst✝¹ : Encodable γ inst✝ : CompleteLattice β m : β → α m0 : m ⊥ = 0 s : γ → β H : ∀ (n : ℕ), m (⨆ (b : γ) (_ : b ∈ decode₂ γ n), s b) ≠ 0 → Option.isSome (decode₂ γ n) = true n : ℕ h : n ∈ support fun i => m (⨆ (b : γ) (_ : b ∈ decode₂ γ i), s b) ⊢ s (Option.get (decode₂ γ n) (_ : Option.isSome (decode₂ γ n) = true)) = ⨆ (b : γ) (_ : b ∈ some (Option.get (decode₂ γ n) (_ : Option.isSome (decode₂ γ n) = true))), s b Tactic: congr State Before: case e_a α : Type u_2 β : Type u_1 γ : Type u_3 δ : Type ?u.362154 inst✝⁴ : AddCommMonoid α inst✝³ : TopologicalSpace α inst✝² : T2Space α f g : β → α a a₁ a₂ : α inst✝¹ : Encodable γ inst✝ : CompleteLattice β m : β → α m0 : m ⊥ = 0 s : γ → β H : ∀ (n : ℕ), m (⨆ (b : γ) (_ : b ∈ decode₂ γ n), s b) ≠ 0 → Option.isSome (decode₂ γ n) = true n : ℕ h : n ∈ support fun i => m (⨆ (b : γ) (_ : b ∈ decode₂ γ i), s b) ⊢ s (Option.get (decode₂ γ n) (_ : Option.isSome (decode₂ γ n) = true)) = ⨆ (b : γ) (_ : b ∈ some (Option.get (decode₂ γ n) (_ : Option.isSome (decode₂ γ n) = true))), s b State After: no goals Tactic: simp [ext_iff, -Option.some_get]
-- {-# OPTIONS -v tc.size:100 #-} module SizedTypesMergeSort where open import Common.Size open import Common.Prelude using (Bool; true; false; if_then_else_) open import Common.Product module Old where -- sized lists data List (A : Set) : {_ : Size} -> Set where [] : {size : Size} -> List A {↑ size} _::_ : {size : Size} -> A -> List A {size} -> List A {↑ size} -- CPS split (non-size increasing) split : {A : Set}{i : Size} -> List A {i} -> {C : Set} -> (List A {i} -> List A {i} -> C) -> C split [] k = k [] [] split (x :: xs) k = split xs (\ l r -> k (x :: r) l) module Sort (A : Set) (compare : A -> A -> {B : Set} -> B -> B -> B) where -- Andreas, 4 Sep 2008 -- the size indices i and j should not be necessary here -- but without them, the termination checker does not recognise that -- the pattern x :: xs is equal to the term x :: xs -- I suspect that _::_ {∞} x xs is not equal to itself since ∞ is a term -- not a constructor or variable merge : {i j : Size} -> List A {i} -> List A {j} -> List A merge [] ys = ys merge xs [] = xs merge (x :: xs) (y :: ys) = compare x y (x :: merge xs (y :: ys)) (y :: merge (x :: xs) ys) sort : {i : Size} -> List A {i} -> List A sort [] = [] sort (x :: []) = x :: [] sort (x :: (y :: xs)) = split xs (\ l r -> merge (sort (x :: l)) (sort (y :: r))) module New where -- sized lists data List A {i} : Set where [] : List A _::_ : {i' : Size< i} → A → List A {i'} → List A module CPS where -- CPS split (non-size increasing) split : ∀ {A i} → List A {i} → {C : Set} → (List A {i} → List A {i} → C) → C split [] k = k [] [] split (x :: xs) k = split xs (\ l r → k (x :: r) l) module Sort (A : Set) (compare : A → A → {B : Set} → B → B → B) where merge : List A → List A → List A merge [] ys = ys merge xs [] = xs merge (x :: xs) (y :: ys) = compare x y (x :: merge xs (y :: ys)) (y :: merge (x :: xs) ys) sort : {i : Size} → List A {i} → List A sort [] = [] sort (x :: []) = x :: [] sort (x :: (y :: xs)) = split xs (\ l r → merge (sort (x :: l)) (sort (y :: r))) module Direct where split : ∀ {A i} → List A {i} → List A {i} × List A {i} split [] = [] , [] split (x :: xs) = let l , r = split xs in (x :: r) , l module Sort (A : Set) (_≤_ : A → A → Bool) where merge : List A → List A → List A merge [] ys = ys merge xs [] = xs merge (x :: xs) (y :: ys) = if x ≤ y then (x :: merge xs (y :: ys)) else (y :: merge (x :: xs) ys) sort : {i : Size} → List A {i} → List A sort [] = [] sort (x :: []) = x :: [] sort (x :: (y :: xs)) = let l , r = split xs in merge (sort (x :: l)) (sort (y :: r))
\section{System's Perspective} \subsection{Design} To develop our version of MiniTwit, we have chosen to use the programming language Go. We are using a toolkit called Gorilla that includes a number of different packages, that each help with different things regarding web development. We use the library called GORM to interact with our PostgreSQL database instead of writing our own SQL queries. We use Prometheus to monitor our application - and Grafana to give us a dashboard with the Prometheus data. To log things like error messages, we use the ELK stack. \subsection{Architecture} \subsubsection{Components and connectors} Our system is containerized using docker and deployed with DigitalOcean, which enables the user to access and use the application. Our API and app are connected to the database container. We use Caddy as our reverse proxy. Caddy receives traffic and redirects it to either the API, app, Grafana, or Kibana, using the same ports for all four services. \begin{figure}[H] \centering \includegraphics[scale=0.40]{images/C&C_diagram.png} \caption{Diagram showing an overview of our components and connectors.} \label{fig:CCDiagram} \end{figure} \subsubsection{Module Viewpoints} \subsubsection*{Packages} The system consists of three packages: \textit{src}, \textit{CircleCI} and \textit{Docker}. The packages and their dependencies are visualized in figure \ref{fig:packages}. The \textit{src} package contains the system logic relevant to user actions in the app and API. The app handles user inputs from the MiniTwit website, whereas the API handles HTTP requests through exposed endpoints. \textit{src} also contains the monitoring and the controller packages. The \textit{monitoring} package contains two things. First and foremost, the monitoring infrastructure is set up with the Prometheus package. The Prometheus Promauto functionality is used to define what metrics to track. We chose it because it sets up an easily extendable code structure. Secondly, the function MiddlewareMetrics starts a timer and measures CPU usage before serving the http request it is handling. After having served the HTTP request it increments the request count and records the duration of the HTTP request. The \textit{controller} simply defines the structs for the database, to connect to the database, query a users ID from a username and hash passwords. \newline For a full overview of the entire \textit{src} package, see appendix \ref{appendix:CCDiagram} The \textit{Docker} package is not tied to MiniTwit functionality. Its purpose is to contain the instructions for initialization of our different Docker containers when we deploy the system. This means that it contains a variety of file types. Naturally, it contains the .Dockerfile for the app and API. Furthermore, it contains .yml files with launch settings for our monitoring tools. The \textit{/grafana} directory also includes .json files that define the UI for its dashboard. \newline These files are run at every system initialization, building the containers, based on the data carried in the package. Finally, the \textit{CircleCI} package contains the functionality for CI/CD. It is linked to our GitHub repository, meaning that every time we merge a pull request into the MiniTwit repository's main branch, the setup in the \textit{Docker} package is run. \begin{figure}[H] \centering \includegraphics[scale=0.60]{images/packages.png} \caption{This diagram shows the outermost layer of the Minitwit packages and their dependencies.} \label{fig:packages} \end{figure} \subsubsection*{Src} The overview of our \textit{src} package is seen in figure \ref{fig:src} which visualizes the dependencies of our \textit{API} and \textit{App}. \begin{figure}[H] \centering \includegraphics[scale=0.75]{images/src.png} \caption{The diagram shows the dependencies between the API and app in the \textit{src} package.} \label{fig:src} \end{figure} \newpage \subsubsection*{Class overview of App} Our App consists of the following: \begin{itemize} \item Main.go $\rightarrow$ our back-end functionality of the application \item Front-end, consisting of 4 HTML files \begin{itemize} \item Layout.html \item login.html \item register.html \item timeline.html \end{itemize} \item a single CSS file responsible for the UI-design of our front-end \end{itemize} Our app exposes HTTP-endpoints for the following use cases: \begin{itemize} \item \texttt{/} $\rightarrow$ If user logged in, loading personal timeline, if not logged in, redirecting to \texttt{/public} \vspace{0.5em} \item \texttt{/favicon.ico} $\rightarrow$ prevents the app from thinking favicon.ico is a user \vspace{0.5em} \item \texttt{/public} $\rightarrow$ loads the public timeline \vspace{0.5em} \item \texttt{/add\_message} $\rightarrow$ posting message on the web service \vspace{0.5em} \item \texttt{/login} $\rightarrow$ login opportunity for users \vspace{0.5em} \item \texttt{/register} $\rightarrow$ registration opportunity for users \vspace{0.5em} \item \texttt{/logout} $\rightarrow$ opportunity to log out of the web service \vspace{0.5em} \item \texttt{/\{username\}} $\rightarrow$ load the timeline of the given user \vspace{0.5em} \item \texttt{/\{username\}/follow} $\rightarrow$ logged in user wanting to follow user called \texttt{\{username\}} \vspace{0.5em} \item \texttt{/\{username\}/unfollow} $\rightarrow$ logged in user wanting to unfollow user called\\ \texttt{\{username\}} \end{itemize} In order to display data in the front-end, we make use of the struct \texttt{TimelineData}, which acts as a container for the data fetched from the database. The struct \texttt{SessionData} is used to keep track of the data associated with the current session in the application. In other words, this is the struct whose field, \texttt{Flashes}, is injected into the frontend, such that nothing is directly exposed to the front-end. This hides the back-end functionality, improving security of the site as well as keeping the code less coupled, such that changes in one part do not break others. To load the data on the frontend, we use the Go package \textit{Go/Template} which allows for Go code to be loaded directly in the HTML without the need for any JavaScript. \newpage \subsubsection*{Class overview of API} The API makes use of HTTP requests by exposing HTTP-endpoints in order for the internal logic to handle the HTTP requests. Every endpoint has been kept according to the initial Python application. Our API has exposed endpoints for the following HTTP requests: \begin{itemize} \item Registering users (POST) /api/register - if success, returns HTTP response code 204. If failing, returns HTTP response 400. \item Following a user (POST / GET) /api/follws/\{username\} - the method is checking if already followed (GET) and following / unfollowing (POST) - if success, returns HTTP response code 204. If failing, returns HTTP response 404. \item Latest message (GET) /api/latest - returns the ID of the latest message from the application. \item Messages per user (GET) /api/msgs/\{username\} - if success, returns HTTP response code 204. If failing, returns HTTP response 405. \item Messages (feed) (GET) /api/msgs - if success, returns HTTP response code 204. If failing, returns HTTP response 405. \end{itemize} The API is meant to be run within a simulator environment, which acts as if the API is being accessed by real users. In our case, the API has failed quite a lot (around 90-95\%), which is due to downtime of our database (4 days). We are suspecting that a lot of the users were registered during these days and therefore we had a lot of errors. The errors arising from \textit{user does not exist} has also caused the problem that it camouflaged any downstream errors. Due to the fact that it does not follow good DevOps principles to just register users (by using the "username" property in some endpoints and therefore allowing null-values in the database, which is not a maintainable solution) when they did not exist, we were unable to find a way of resolving this in a proper manner. \newpage \subsubsection{Deployment} The deployment diagram below (see figure \ref{fig:deployment_diagram}) visualizes the dependencies between software containers, stored in Docker containers, and the physical hardware that runs it. The system is run on a virtual machine hosted by DigitalOcean. The virtual machine runs Ubuntu 20.04 LTS and the OS runs the system in a Docker daemon that contains individual Docker containers and Docker networks. \newline The two Docker networks are separated into logical units. The first unit is the main-network, which contains the system logic, monitoring tools, and the database. The second network container, elk-network, contains the tools used to create logs. As the ELK setup does not need to communicate with any of the applications, it does not need to be in the same network. It works by Filebeat reading directly from the system directory that contains the logs from Docker containers, which is mounted as a Docker volume. \begin{figure}[H] \centering \includegraphics[scale=0.37]{images/deployment_diagram.png} \caption{The deployment diagram highlights how the software elements are mapped to the hardware that it is hosted on.} \label{fig:deployment_diagram} \end{figure} \newpage \subsection{Dependencies} \begin{itemize} \item Go 1.18.x \vspace{0.5em} \item DigitalOcean: Our hosting service. \vspace{0.5em} \item Docker: Service for containerizing software. \vspace{0.5em} \item Docker Compose: Tool that gives instructions to Docker on what images to initialize when deploying the system. \vspace{0.5em} \item CircleCI: A platform for continuous integration and deployment. \vspace{0.5em} \item PostgreSQL: The relational database system \vspace{0.5em} \item Gorilla/mux: A http request router and dispatcher which we use for matching incoming request to their respective handlers. \vspace{0.5em} \item GORM: Go library used for creation of relational database schema and migration, as well as providing CRUD operations. \vspace{0.5em} \item Prometheus: Our monitoring software. \vspace{0.5em} \item Grafana: An analytics and visualization tool which is hooked up to Prometheus. \vspace{0.5em} \item ELK: A Docker Image providing the following services: \vspace{0.5em} \begin{itemize} \item Elasticsearch: used for its index log data. \vspace{0.5em} \item Filebeat: Collects logging data and forwards it to Elasticsearch. \vspace{0.5em} \item Kibana: Visualization and navigation tool for the data stored in Elasticsearch. \vspace{0.5em} \end{itemize} \item Caddy: Proxy and web server service. We use it for reverse proxying. \vspace{0.5em} \item Watchtower: A service for checking updates for Docker images and updating Docker containers. \end{itemize} \subsection{Important interactions of subsystems} We use Docker Compose to run multiple Docker containers for our system, such as MiniTwit, ELK, Prometheus, etc. For automating the process of updating images, we use Watchtower. For logging we have set up our Docker Compose file to create containers for the three ELK images; Elasticsearch, Filebeat, and Kibana. Filebeat is the container that observes and ships data to Elasticsearch. Kibana then receives the data from Elasticsearch and visualizes it. When new features are pushed to the GitHub repository's main branch, CircleCI triggers and re-deploys the system. We monitor our application with Prometheus, which collects metrics by scraping from a selection of HTTP endpoints. These metrics are then stored on the Prometheus server, and can be exported or visualized with Grafana. \subsection{Current state of our system} %Describe the current state of your systems, for example using results of static analysis and quality assessment systems SecureGo notified that the .md5 hashing algorithm is weak. Our system still uses it, as it is a requirement for Gravatar URLs. At the end of development, we have judged our system according to our chosen metrics, described in section \ref{CI/CD}. \begin{itemize} \item Maintainability - The code base has been left in a maintainable state. It is easy to navigate and understand. The packages divide the system in logical units. \item Testability - We did not manage to implement unit testing in time. However, we do static analysis on all branches and also build and deploy for each pull request to main. \item Portability - The portability of the system is difficult to estimate without unit or integration testing. Again, the static analysis and clean conventions combat this somewhat, though we are not completely satisfied yet. \item Reusability - We have managed to make our code reusable and avoiding redundant code. An example is our controller, which has methods used by both our API and app. \item Technical debt - During the course of developing and maintaining Minitwit, we tried to minimize our accrued technical debt. The most mention-worthy debt, is that our Docker swarm is stopping our monitoring and logging from working. As such, the production branch, at the date of delivery, is not using swarm, to prioritize monitoring. \end{itemize} \subsection{License compatibility} Our MiniTwit application is licensed under the AGPLv3 license. After running the tool \textit{\href{https://github.com/uw-labs/lichen}{lichen}} on our code, we found no license violations. AGPLv3 is the most copy-left license that we know of, meaning that almost all other FOSS licenses are compatible with it.
Formal statement is: lemma LIM_at_top_divide: fixes f g :: "'a \<Rightarrow> real" assumes f: "(f \<longlongrightarrow> a) F" "0 < a" and g: "(g \<longlongrightarrow> 0) F" "eventually (\<lambda>x. 0 < g x) F" shows "LIM x F. f x / g x :> at_top" Informal statement is: If $f(x) \to a > 0$ and $g(x) \to 0$ with $g(x) > 0$ for all sufficiently large $x$, then $f(x)/g(x) \to \infty$.
-- @@stderr -- dtrace: failed to compile script test/unittest/actions/printf/err.D_SYNTAX.pct_flags.d: [D_SYNTAX] line 19: format conversion #1 cannot be combined with other format flags: %%
theory AlgebraicStructure imports Main "HOL-Library.Monad_Syntax" "HOL-Library.State_Monad" HOL.Real "~~/src/HOL/ex/Sqrt" begin section \<open>monoid\<close> class monoid = fixes mult :: "'a \<Rightarrow> 'a \<Rightarrow> 'a" (infixl "\<otimes>" 70) fixes neutral :: 'a ("\<one>") assumes assoc : "(x \<otimes> y) \<otimes> z = x \<otimes> (y \<otimes> z)" and neutr : "x \<otimes> \<one> = x" and neutl : "\<one> \<otimes> x = x" begin lemma "(w \<otimes> x) \<otimes> (y \<otimes> z) = w \<otimes> x \<otimes> y \<otimes> z" using assoc by auto end instantiation int :: monoid begin definition mult_int_def : "x \<otimes> y = (x :: int) + y" definition neutral_int_def : "\<one> = (0::int)" instance apply standard using neutral_int_def mult_int_def by auto end value "(1::int) \<otimes> 2" instantiation nat :: monoid begin definition mult_nat_def : "x \<otimes> y = (x :: nat) + y" definition neutral_nat_def : "\<one> = (0::nat)" instance apply standard using neutral_nat_def mult_nat_def by auto end value "(1::nat) \<otimes> 2" instantiation bool :: monoid begin definition mult_bool_def : "x \<otimes> y = ((x::bool) \<and> y)" definition neutral_bool_def : "\<one> = True" instance apply standard using mult_bool_def neutral_bool_def by auto end value "True \<otimes> True" value "True \<otimes> False" value "False \<otimes> False" instantiation list :: (type) monoid begin definition mult_list_def : "(x :: 'a list) \<otimes> y = x @ y" definition neutral_list_def : "\<one> = []" instance apply standard using neutral_list_def mult_list_def by auto end value "[1::nat,2,3] \<otimes> [4,5,6]" value "''abcde'' \<otimes> ''fghij''" instantiation set :: (type) monoid begin definition mult_set_def : "(x :: 'a set) \<otimes> y = x \<union> y" definition neutral_set_def : "\<one> = {}" instance apply standard using mult_set_def neutral_set_def by auto end value "{1::int,2,3} \<otimes> {3,4,5,6}" interpretation setintersect : monoid "(\<inter>)" UNIV unfolding class.monoid_def by auto instantiation prod :: (monoid, monoid) monoid begin definition mult_prod_def : "x \<otimes> y = (fst x \<otimes> fst y, snd x \<otimes> snd y)" definition neutral_prod_def : "\<one> = (\<one>,\<one>)" instance apply standard using mult_prod_def neutral_prod_def neutr neutl apply (simp add: assoc) apply (simp add: mult_prod_def neutr neutral_prod_def) by (simp add: mult_prod_def neutl neutral_prod_def) end value "(''aaaa'',{1::int,2,3}) \<otimes> (''cccc'',{4,5,6})" value "(''aaa'',''bbb'',''ccc'') \<otimes> (''ddd'',''eee'',''fff'') \<otimes> (''ggg'',''hhh'',''iii'')" value "(''aa'',{1::int},1::nat) \<otimes> (''cc'',{2},2) \<otimes> (''ee'',{3},3)" value "(''aaa'', 20::int, False,{1::int}) \<otimes> (''ddd'', 30::int, False,{2})" value "foldl (\<otimes>) \<one> [''aa'',''bb'',''cc'']" value "foldl (\<otimes>) \<one> [1::int,2,3,4,5]" value "foldl (\<otimes>) \<one> [(''aa'',{1::int},1::nat),(''bb'',{2},2),(''cc'',{3},3),(''dd'',{4},4)]" value "foldl (\<otimes>) \<one> [(1::int,''bb''),(2,''dd''),(3,''ff'')]" (* count the elements and their sum in a list *) value "foldl (\<otimes>) \<one> (map (\<lambda>x. (1::int,x)) [1::int,2,3,4,5])" (* count the elements and their sum in a list *) value "foldl (\<otimes>) \<one> (map (\<lambda>x. (1::int,x)) [''aa'',''bb'',''cc'',''dd''])" interpretation fun_monoid: monoid comp id unfolding class.monoid_def by auto section \<open>monad\<close> subsection \<open>motivation example\<close> definition eval :: int where "eval \<equiv> let x = 1; y = x + 5; z = x + y; z = z * 2 in z div 2" (* definition bind_option :: "'a option \<Rightarrow> ('a \<Rightarrow> 'b option) \<Rightarrow> 'b option" where "bind_option a f \<equiv> (case a of Some x \<Rightarrow> f x | None \<Rightarrow> None)" adhoc_overloading Monad_Syntax.bind bind_option *) subsection \<open>option monad\<close> thm Option.bind.simps definition returno :: "'a \<Rightarrow> 'a option" where "returno a = Some a" definition add :: "int option \<Rightarrow> int option \<Rightarrow> int option" where "add x y \<equiv> do { mx \<leftarrow> x; my \<leftarrow> y; returno (mx + my) }" thm add_def value "add (Some 2) None" value "add (Some 3) (Some 5)" definition adds :: "int option \<Rightarrow> int option" where "adds x \<equiv> do { a \<leftarrow> x; b \<leftarrow> add (Some a) (Some 1); c \<leftarrow> add (Some b) (Some 2); d \<leftarrow> add (Some c) (Some 3); returno d }" thm adds_def value "adds (Some 2)" definition safe_div :: "int option \<Rightarrow> int option \<Rightarrow> int option" where "safe_div x y \<equiv> do { mx \<leftarrow> x; my \<leftarrow> y; if my \<noteq> 0 then returno (mx div my) else None }" thm safe_div_def value "safe_div (Some 5) (Some 0)" value "safe_div (Some 6) (Some 2)" value "safe_div (Some 5) None" value "safe_div None (Some 5)" definition comps :: "int option \<Rightarrow> int option" where "comps x \<equiv> do { a \<leftarrow> add x (Some (-3)); b \<leftarrow> safe_div (Some 6) (Some a); c \<leftarrow> add (Some b) (Some (-6)); d \<leftarrow> safe_div (Some 15) (Some c); returno d }" value "comps (Some 3)" value "comps (Some 4)" value "comps (Some 5)" subsection \<open>list monad\<close> context begin definition returnl :: "'a \<Rightarrow> 'a list" where "returnl a \<equiv> [a]" definition "sqr_even l \<equiv> do { x \<leftarrow> l; if x mod 2 = 0 then returnl (x * x) else returnl x }" thm sqr_even_def value "sqr_even [1..10]" definition "list_double l \<equiv> do { x \<leftarrow> l; [x,2*x] }" thm list_double_def value "list_double [1..5]" definition "prod1 xs ys \<equiv> do { x \<leftarrow> xs; y \<leftarrow> ys; returnl (x, y) }" thm prod1_def value "prod1 [a,b,c] [e,f,g]" definition "prod2 xs ys \<equiv> concat (map (\<lambda>x. concat (map (\<lambda>y. [(x,y)]) ys)) xs)" lemma "prod1 xs ys = prod2 xs ys" unfolding prod1_def List.bind_def prod2_def returnl_def by simp definition list2 :: "string list \<Rightarrow> (nat \<times> string) list" where "list2 ss \<equiv> do { x \<leftarrow> ss; let y = x@''#''; let z = y@''@''; returnl (length x,z@z) }" thm list2_def value "list2 [''aaa'',''bb'',''cccc'']" thm List.bind_def (* double vlen(double * v) { double d = 0.0; int n; for (n = 0; n < 3; ++n) d += v[n] * v[n]; return sqrt(d); } *) definition vlen :: "real list \<Rightarrow> real" where "vlen l \<equiv> foldl plus 0.0 ((l \<bind> (\<lambda>x. [x * x]))\<bind> (\<lambda>x. [x + 1]))" definition vlen2 :: "real list \<Rightarrow> real" where "vlen2 l \<equiv> foldl plus 0.0 (do { x \<leftarrow> l; let y = x * x; returnl (y + 1) })" thm vlen_def thm vlen2_def value "vlen [1,2,3,5]" value "vlen2 [1,2,3,5]" definition list3 :: "real list \<Rightarrow> real list" where "list3 l \<equiv> ((l \<bind> (\<lambda>x. [x * x]))\<bind> (\<lambda>x. [x + 100]))\<bind> (\<lambda>x. [x + 1000])" definition list32 :: "real list \<Rightarrow> real list" where "list32 l \<equiv> do { x \<leftarrow> l; let y = x * x; let z = y + 100; returnl (z + 1000) }" thm list3_def thm list32_def value "list3 [1,2,3,5]" value "list32 [1,2,3,5]" end subsection \<open>set monad\<close> definition returns :: "'a \<Rightarrow> 'a set" where "returns a = {a}" definition set1 :: "int set \<Rightarrow> (int \<times> string) set" where "set1 s \<equiv> do { x \<leftarrow> s; if x mod 2 = 0 then returns (3 * x, ''aaa'') else returns (0,'''') }" value "set1 {0..10}" definition set2 :: "int set \<Rightarrow> (int \<times> string) set" where "set2 s \<equiv> (s \<bind> (\<lambda>x. if x mod 2 = 0 then {(3 * x, ''aaa'')} else {(0,'''')})) \<bind> (\<lambda>(x,y). {(x+1,y@''__'')})" definition set22 :: "int set \<Rightarrow> (int \<times> string) set" where "set22 s \<equiv> do { x \<leftarrow> s; if x mod 2 = 0 then do { let (x,y) = (3 * x, ''aaa''); returns (x+1,y@''__'') } else do { let (x,y) = (0,''''); returns (x+1,y@''__'') } }" thm set2_def thm set22_def value "set2 {0..10}" value "set22 {0..10}" definition set3 :: "int set \<Rightarrow> (int \<times> string) set" where "set3 s \<equiv> (s \<bind> (\<lambda>x. {(x*2,''*2'')})) \<bind> (\<lambda>(x,y). {(x+1,y@''__'')})" definition set32 :: "int set \<Rightarrow> (int \<times> string) set" where "set32 s \<equiv> do { x \<leftarrow> s; (x,y) \<leftarrow> {(x*2,''*2'')}; returns (x+1,y@''__'') }" value "set3 {0..10}" value "set32 {0..10}" subsection \<open>state monad\<close> lemma "Pair a = (\<lambda>s. (a,s))" by auto type_synonym 'v stack = "'v list" definition pop :: "('v stack,'v option) state" where "pop \<equiv> State (\<lambda>s. case s of [] \<Rightarrow> (None, []) | (x#xs) \<Rightarrow> (Some x,xs))" definition push :: "'v \<Rightarrow> ('v stack,'v option) state" where "push v \<equiv> State (\<lambda>s. case s of [] \<Rightarrow> (None, [v]) | (x#xs) \<Rightarrow> (None,v#x#xs))" primrec pushn :: "'v list \<Rightarrow> ('v stack, 'v option) state" where "pushn [] = State_Monad.return None" | "pushn (x#xs) = do { push x; pushn xs }" primrec popn :: "nat \<Rightarrow> ('v stack,('v option) list) state" where "popn 0 = State_Monad.return []" | "popn (Suc n) = do { a \<leftarrow> pop; as \<leftarrow> popn n; State_Monad.return (a#as) }" value "run_state (pushn [1::int,2,3,4,5]) []" value "run_state (pushn [1::int,2,3,4,5]) [0,0,0]" value "run_state (popn 5) [0::int,1,2,3,4,5,6]" value "run_state (do { pushn [1::int,2,3,4,5]; popn 4 }) []" thm foldl.simps definition stackops :: "(int stack,int option) state" where "stackops \<equiv> do { State_Monad.return (0::int); push (1::int); push 2; push 3; push 4; State_Monad.return None }" thm stackops_def value "run_state stackops []" definition swap :: "'a list \<Rightarrow> nat \<Rightarrow> nat \<Rightarrow> 'a list" where "swap l i j \<equiv> (let temp = l!i in (l[i := l!j])[j := temp])" value "swap [0::nat,1,2,3,4] 0 4" fun insert :: "('a::linorder) list \<Rightarrow> nat \<Rightarrow> (('a::linorder) list,('a::linorder) list) state" where "insert l i = (if i \<noteq> 0 \<and> l!i < l!(i-1) then do { let l1 = swap l (i-1) i; insert l1 (i - 1) } else do { State_Monad.return l })" value "run_state (insert [3::int,2,8,4,3] 1) []" function isort :: "('a::linorder) list \<Rightarrow> nat \<Rightarrow> (('a::linorder) list,('a::linorder) list) state" where "isort l i = (if i < length l then do { l' \<leftarrow> insert l i; isort l' (i + 1) } else do { State_Monad.return l })" by auto termination apply (relation "measure (\<lambda>(l,i). length l - i)") apply auto sorry thm isort.simps value "(run_state (isort ([1::int,0,2,8,4,3,6,2]) 1) [])" subsection \<open>I/O monad\<close> type_synonym Name = "string" type_synonym IOStreams = "Name \<Rightarrow> string" type_synonym IOState = "(IOStreams,string) state" definition "nl \<equiv> CHR 0x0A" definition newIO :: "Name \<Rightarrow> IOState" where "newIO x \<equiv> State (\<lambda>s. (''OK'', s(x := ([]::string))))" definition putChar :: "Name \<Rightarrow> char \<Rightarrow> IOState" where "putChar x c \<equiv> State (\<lambda>s. ([c],s(x := s x @ [c])))" definition putStr :: "Name \<Rightarrow> string \<Rightarrow> IOState" where "putStr x c \<equiv> State (\<lambda>s. (c, s(x := s x @ c)))" definition putStrLn :: "Name \<Rightarrow> string \<Rightarrow> IOState" where "putStrLn x c \<equiv> putStr x (c@[nl])" definition getChar :: "Name \<Rightarrow> IOState" where "getChar x \<equiv> State ( \<lambda>s. case s x of [] \<Rightarrow> ([],s) | (y#xs) \<Rightarrow> ([y],s(x := xs)))" primrec getline :: "string \<Rightarrow> (string \<times> string)" where "getline [] = ([],[])" | "getline (x#xs) = (let (a,b) = getline xs in if x = nl then ([],xs) else (x#a,b))" definition getLine :: "Name \<Rightarrow> IOState" where "getLine x = State ( \<lambda>s. let str = s x; (a,b) = getline str in (a, s(x := b)))" definition init :: "IOStreams" where "init = (\<lambda>x. [])" definition printIO :: "Name \<Rightarrow> IOState \<Rightarrow> (string \<times> string)" where "printIO x sm \<equiv> (fst (run_state sm init), (snd (run_state sm init)) x)" value "printIO ''io1'' (do { newIO ''io1''; putStrLn ''io1'' (''aaa''); putStrLn ''io1'' (''bbb''); putStrLn ''io1'' (''ccc''); putChar ''io1'' (CHR ''d''); x \<leftarrow> getChar ''io1''; State_Monad.return x })" value "printIO ''io2'' (do { newIO ''io1''; putStrLn ''io1'' (''aaa''); putStrLn ''io1'' (''bbb''); putStrLn ''io1'' (''ccc''); putChar ''io1'' (CHR ''d''); x \<leftarrow> getChar ''io1''; newIO ''io2''; putStrLn ''io2'' (x); putStrLn ''io2'' (''fff''); putStrLn ''io2'' (''ggg''); getLine ''io2''; getLine ''io2''; y \<leftarrow> getLine ''io2''; State_Monad.return y })" value "printIO ''io2'' (do { newIO ''io1''; putStrLn ''io1'' (''aaa''); putStrLn ''io1'' (''bbb''); putStrLn ''io1'' (''ccc''); putChar ''io1'' (CHR ''d''); getChar ''io1''; newIO ''io2''; putStrLn ''io2'' (''eee''); putStrLn ''io2'' (''fff''); putStrLn ''io2'' (''ggg''); x \<leftarrow> getLine ''io2''; State_Monad.return x })" section \<open>functor\<close> typedecl ('a, 'b, 'c, 'd) F consts map_F :: "('a \<Rightarrow> 'a') \<Rightarrow> ('b' \<Rightarrow> 'b) \<Rightarrow> ('c \<Rightarrow> 'c') \<Rightarrow> ('a, 'b, 'c, 'd) F \<Rightarrow> ('a', 'b', 'c', 'd') F" functor map_F sorry typedecl 'a T consts map_t :: "('a \<Rightarrow> 'a') \<Rightarrow> 'a T \<Rightarrow> 'a' T" functor map_t sorry primrec maplist2 :: "('a \<Rightarrow> 'b) \<Rightarrow> 'a list \<Rightarrow> 'b list" where "maplist2 f [] = []" | "maplist2 f (x # xs) = f x # maplist2 f xs" functor maplist2 proof fix f g x show "(maplist2 f \<circ> maplist2 g) x = maplist2 (f \<circ> g) x" apply(induct x) using maplist2.simps by auto next { fix x have "(maplist2 id) x = id x" apply(induct x) using maplist2.simps by auto } then show "maplist2 id = id" by blast qed thm AlgebraicStructure.list.comp thm list.comp (* functor map (* map function on list is a functor *) by auto (* Duplicate fact declaration "AlgebraicStructure.list.comp" vs. "AlgebraicStructure.list.comp" *) *) primrec mapsome :: "('a \<Rightarrow> 'b) \<Rightarrow> 'a option \<Rightarrow> 'b option" where "mapsome f None = None" | "mapsome f (Some a) = Some (f a)" functor mapsome proof fix f g x show "(mapsome f \<circ> mapsome g) x = mapsome (f \<circ> g) x" apply(induct x) using mapsome.simps by auto next show "mapsome id = id" using mapsome.simps by (metis eq_id_iff not_None_eq) qed datatype 'a tree = Leaf 'a | Node "'a tree" "'a tree" primrec maptree :: "('a \<Rightarrow> 'b) \<Rightarrow> 'a tree \<Rightarrow> 'b tree" where "maptree f (Leaf a) = Leaf (f a)" | "maptree f (Node l r) = Node (maptree f l) (maptree f r)" lemma lmmt1: "(maptree f \<circ> maptree g) x = (maptree (f \<circ> g)) x" apply(induct x) using maplist2.simps by auto lemma lmmt2: "(maptree id) x = id x" apply(induct x) using maptree.simps by auto functor maptree proof fix f::"'b \<Rightarrow> 'c" fix g::"'a \<Rightarrow> 'b" fix x::"'a tree" show "(maptree f \<circ> maptree g) x = maptree (f \<circ> g) x" using lmmt1 by simp next show "maptree id = id" using lmmt2 by blast qed (* locale Functor = fixes fmap :: "('a \<Rightarrow> 'b) \<Rightarrow> 'a T \<Rightarrow> 'b T" assumes "fmap f \<circ> fmap g = fmap (f \<circ> g)" *) end
lemma LIM_eq: "f \<midarrow>a\<rightarrow> L = (\<forall>r>0. \<exists>s>0. \<forall>x. x \<noteq> a \<and> norm (x - a) < s \<longrightarrow> norm (f x - L) < r)" for a :: "'a::real_normed_vector" and L :: "'b::real_normed_vector"
(* Title: HOL/HOLCF/IOA/Storage/Correctness.thy Author: Olaf Müller *) section \<open>Correctness Proof\<close> theory Correctness imports IOA.SimCorrectness Spec Impl begin default_sort type definition sim_relation :: "((nat * bool) * (nat set * bool)) set" where "sim_relation = {qua. let c = fst qua; a = snd qua ; k = fst c; b = snd c; used = fst a; c = snd a in (\<forall>l\<in>used. l < k) \<and> b=c}" declare split_paired_Ex [simp del] (* Idea: instead of impl_con_lemma do not rewrite impl_ioa, but derive simple lemmas asig_of impl_ioa = impl_sig, trans_of impl_ioa = impl_trans Idea: ?ex. move .. should be generally replaced by a step via a subst tac if desired, as this can be done globally *) lemma issimulation: "is_simulation sim_relation impl_ioa spec_ioa" apply (simp (no_asm) add: is_simulation_def) apply (rule conjI) txt \<open>start states\<close> apply (auto)[1] apply (rule_tac x = " ({},False) " in exI) apply (simp add: sim_relation_def starts_of_def spec_ioa_def impl_ioa_def) txt \<open>main-part\<close> apply (rule allI)+ apply (rule imp_conj_lemma) apply (rename_tac k b used c k' b' a) apply (induct_tac "a") apply (simp_all (no_asm) add: sim_relation_def impl_ioa_def impl_trans_def trans_of_def) apply auto txt \<open>NEW\<close> apply (rule_tac x = "(used,True)" in exI) apply simp apply (rule transition_is_ex) apply (simp (no_asm) add: spec_ioa_def spec_trans_def trans_of_def) txt \<open>LOC\<close> apply (rule_tac x = " (used Un {k},False) " in exI) apply (simp add: less_SucI) apply (rule transition_is_ex) apply (simp (no_asm) add: spec_ioa_def spec_trans_def trans_of_def) apply fast txt \<open>FREE\<close> apply (rename_tac nat, rule_tac x = " (used - {nat},c) " in exI) apply simp apply (rule transition_is_ex) apply (simp (no_asm) add: spec_ioa_def spec_trans_def trans_of_def) done lemma implementation: "impl_ioa =<| spec_ioa" apply (unfold ioa_implements_def) apply (rule conjI) apply (simp (no_asm) add: impl_sig_def spec_sig_def impl_ioa_def spec_ioa_def asig_outputs_def asig_of_def asig_inputs_def) apply (rule trace_inclusion_for_simulations) apply (simp (no_asm) add: impl_sig_def spec_sig_def impl_ioa_def spec_ioa_def externals_def asig_outputs_def asig_of_def asig_inputs_def) apply (rule issimulation) done end
-- ----------------------------------------------------------- [ GLangPlus.idr ] -- Module : GLangPlus.idr -- Copyright : (c) Jan de Muijnck-Hughes -- License : see LICENSE -- --------------------------------------------------------------------- [ EOH ] ||| A alternate version of the GRL with added structural semantics. module GRL.Lang.GLangPlus import public GRL.Common import public GRL.IR import public GRL.Model import public GRL.Builder import public GRL.Pretty %access public export -- ------------------------------------------------------------- [ Type System ] ||| Specify valid impacts between elements. data ValidImpacts : GElemTy -> GElemTy -> Type where GIS : ValidImpacts GOALty SOFTty SIG : ValidImpacts SOFTty GOALty TIG : ValidImpacts TASKty GOALty TIS : ValidImpacts TASKty SOFTty RIG : ValidImpacts RESty GOALty RIS : ValidImpacts RESty GOALty ||| Specify valid decomopositions. data ValidDecomp : GElemTy -> GElemTy -> Type where GHS : ValidDecomp GOALty SOFTty THT : ValidDecomp TASKty TASKty ||| New structural types. data GLangPTy = E GElemTy | L | S ||| The GLang Language with improved structural semantics. data GLang : GLangPTy -> GTy -> Type where ||| Make a Goal node. MkGoal : String -> Maybe SValue -> GLang (E GOALty) ELEM ||| Make a Soft Goal node. MkSoft : String -> Maybe SValue -> GLang (E SOFTty) ELEM ||| Make a Task node. MkTask : String -> Maybe SValue -> GLang (E TASKty) ELEM ||| Make a resource node. MkRes : String -> Maybe SValue -> GLang (E RESty) ELEM ||| Declare an impact relation. MkImpact : CValue -> GLang (E xty) ELEM -> GLang (E yty) ELEM -> {auto prf : ValidImpacts xty yty} -> GLang L INTENT ||| And decomposition relation. MkAnd : GLang (E xty) ELEM -> GLang (E yty) ELEM -> {auto prf : ValidDecomp xty yty} -> GLang S STRUCT -- ----------------------------------------------------------- [ Pretty Syntax ] syntax [a] "~~>" [b] "|" [c] = MkImpact c a b syntax [a] "&=" [b] = MkAnd a b -- ----------------------------------------------------------- [ Type Synonyms ] GOAL : Type GOAL = GLang (E GOALty) ELEM SOFT : Type SOFT = GLang (E SOFTty) ELEM TASK : Type TASK = GLang (E TASKty) ELEM RES : Type RES = GLang (E RESty) ELEM IMPACT : Type IMPACT = GLang L INTENT AND : Type AND = GLang S STRUCT -- --------------------------------------------------------------------- [ GRL ] implementation GRL (\x => GLang ty x) where mkElem (MkGoal s e) = Elem GOALty s e mkElem (MkSoft s e) = Elem SOFTty s e mkElem (MkTask s e) = Elem TASKty s e mkElem (MkRes s e) = Elem RESty s e mkIntent (MkImpact c a b) = ILink IMPACTSty c (mkElem a) (mkElem b) mkStruct (MkAnd a b) = SLink ANDty (mkElem a) [(mkElem b)] -- --------------------------------------------------------------------- [ EOF ]
[STATEMENT] lemma bliftM_strict1[simp]: "bliftM f\<cdot>\<bottom> = \<bottom>" [PROOF STATE] proof (prove) goal (1 subgoal): 1. bliftM f\<cdot>\<bottom> = \<bottom> [PROOF STEP] by (simp add: bliftM_def)
/// /// Copyright (c) 2009-2014 Nous Xiong (348944179 at qq dot com) /// /// Distributed under 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) /// /// See https://github.com/nousxiong/gce for latest version. /// #ifndef GCE_ACTOR_DETAIL_MAILBOX_HPP #define GCE_ACTOR_DETAIL_MAILBOX_HPP #include <gce/actor/config.hpp> #include <gce/actor/response.hpp> #include <gce/actor/detail/request.hpp> #include <gce/actor/message.hpp> #include <gce/actor/detail/mailbox_fwd.hpp> #include <boost/variant/variant.hpp> #include <vector> #include <deque> #include <list> #include <map> namespace gce { namespace detail { class mailbox { typedef std::pair<recv_t, message> recv_pair_t; typedef std::pair<response_t, message> res_msg_pair_t; typedef std::map<sid_t, res_msg_pair_t> res_msg_list_t; public: explicit mailbox(std::size_t); ~mailbox(); void clear(); public: bool pop(recv_t&, message&, match_list_t const&); bool pop(response_t&, message&); bool pop(aid_t, request_t&); void push(aid_t, message const&); void push(exit_t, message const&); void push(request_t, message const&); bool push(response_t, message const&); private: void add_match_msg(recv_t const&, aid_t sender, message const&); bool fetch_match_msg(match_t, recv_t&, message&); private: typedef std::list<recv_pair_t> recv_queue_t; typedef recv_queue_t::iterator recv_itr; recv_queue_t recv_que_; typedef std::list<recv_itr> match_queue_t; typedef match_queue_t::iterator match_itr; std::vector<match_queue_t> cache_match_list_; typedef std::map<match_t, match_queue_t> match_queue_list_t; match_queue_list_t match_queue_list_; res_msg_list_t res_msg_list_; typedef std::deque<request_t> req_queue_t; typedef std::map<aid_t, req_queue_t> wait_reply_list_t; wait_reply_list_t wait_reply_list_; typedef std::map<aid_t, match_itr> exit_list_t; typedef std::map<svcid_t, std::pair<aid_t, match_itr> > svc_exit_list_t; exit_list_t exit_list_; svc_exit_list_t svc_exit_list_; req_queue_t dummy_; match_queue_t dummy2_; }; } } #endif /// GCE_ACTOR_DETAIL_MAILBOX_HPP
-- Module : Itea -- Description : -- Copyright : (c) Simon Nielsen Knights 2018 -- License : MIT -- Maintainer : [email protected] -- Stability : unstable -- Portability : portable ||| Itea top-level module exporting the most commonly used modules module Itea import public Itea.Javascript.Types import public Itea.Html import public Itea.Html.Attributes import public Itea.Html.Events import public Itea.Utils import public Itea.Program import public Control.Monad.Trans import public Control.Monad.Reader
program average ![-3-]@copyright wikipedia, modified @alpaca-tc. http://en.wikipedia.org/wiki/Fortran ![-4-] Read in some numbers and take the average ![-5-] As written, if there are no data points, an average of zero is returned ![-6-] While this may not be desired behavior, it keeps this example simple implicit none real, dimension(:), allocatable :: points integer :: number_of_points real :: average_points=0., positive_average=0., negative_average=0. write (*,*) "Input number of points to average:" read (*,*) number_of_points allocate (points(number_of_points)) write (*,*) "Enter the points to average:" read (*,*) points ![-22-] Take the average by summing points and dividing by number_of_points if (number_of_points > 0) average_points = sum(points) / number_of_points ![-25-] Now form average over positive and negative points only if (count(points > 0.) > 0) then positive_average = sum(points, points > 0.) / count(points > 0.) end if if (count(points < 0.) > 0) then negative_average = sum(points, points < 0.) / count(points < 0.) end if deallocate (points) ![-34-] Print result to terminal ![-36-] Print result to terminal write (*,'(a,g12.4)') 'Average = ', average_points write (*,'(a,g12.4)') 'Average of positive points = ', positive_average write (*,'(a,g12.4)') 'Average of negative points = ', negative_average end program average
/- Copyright (c) 2015 Microsoft Corporation. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Leonardo de Moura, Mario Carneiro ! This file was ported from Lean 3 source module logic.equiv.basic ! leanprover-community/mathlib commit d2d8742b0c21426362a9dacebc6005db895ca963 ! Please do not edit these lines, except to modify the commit id ! if you have ported upstream changes. -/ import Mathbin.Logic.Equiv.Defs import Mathbin.Data.Option.Basic import Mathbin.Data.Prod.Basic import Mathbin.Data.Sigma.Basic import Mathbin.Data.Subtype import Mathbin.Data.Sum.Basic import Mathbin.Logic.Function.Conjugate /-! # Equivalence between types > THIS FILE IS SYNCHRONIZED WITH MATHLIB4. > Any changes to this file require a corresponding PR to mathlib4. In this file we continue the work on equivalences begun in `logic/equiv/defs.lean`, defining * canonical isomorphisms between various types: e.g., - `equiv.sum_equiv_sigma_bool` is the canonical equivalence between the sum of two types `α ⊕ β` and the sigma-type `Σ b : bool, cond b α β`; - `equiv.prod_sum_distrib : α × (β ⊕ γ) ≃ (α × β) ⊕ (α × γ)` shows that type product and type sum satisfy the distributive law up to a canonical equivalence; * operations on equivalences: e.g., - `equiv.prod_congr ea eb : α₁ × β₁ ≃ α₂ × β₂`: combine two equivalences `ea : α₁ ≃ α₂` and `eb : β₁ ≃ β₂` using `prod.map`. More definitions of this kind can be found in other files. E.g., `data/equiv/transfer_instance` does it for many algebraic type classes like `group`, `module`, etc. ## Tags equivalence, congruence, bijective map -/ open Function universe u v w z variable {α : Sort u} {β : Sort v} {γ : Sort w} namespace Equiv #print Equiv.pprodEquivProd /- /-- `pprod α β` is equivalent to `α × β` -/ @[simps apply symm_apply] def pprodEquivProd {α β : Type _} : PProd α β ≃ α × β where toFun x := (x.1, x.2) invFun x := ⟨x.1, x.2⟩ left_inv := fun ⟨x, y⟩ => rfl right_inv := fun ⟨x, y⟩ => rfl #align equiv.pprod_equiv_prod Equiv.pprodEquivProd -/ #print Equiv.pprodCongr /- /-- Product of two equivalences, in terms of `pprod`. If `α ≃ β` and `γ ≃ δ`, then `pprod α γ ≃ pprod β δ`. -/ @[congr, simps apply] def pprodCongr {δ : Sort z} (e₁ : α ≃ β) (e₂ : γ ≃ δ) : PProd α γ ≃ PProd β δ where toFun x := ⟨e₁ x.1, e₂ x.2⟩ invFun x := ⟨e₁.symm x.1, e₂.symm x.2⟩ left_inv := fun ⟨x, y⟩ => by simp right_inv := fun ⟨x, y⟩ => by simp #align equiv.pprod_congr Equiv.pprodCongr -/ /- warning: equiv.pprod_prod -> Equiv.pprodProd is a dubious translation: lean 3 declaration is forall {α₁ : Sort.{u1}} {β₁ : Sort.{u2}} {α₂ : Type.{u3}} {β₂ : Type.{u4}}, (Equiv.{u1, succ u3} α₁ α₂) -> (Equiv.{u2, succ u4} β₁ β₂) -> (Equiv.{max 1 u1 u2, max (succ u3) (succ u4)} (PProd.{u1, u2} α₁ β₁) (Prod.{u3, u4} α₂ β₂)) but is expected to have type forall {α₁ : Sort.{u1}} {β₁ : Type.{u2}} {α₂ : Sort.{u3}} {β₂ : Type.{u4}}, (Equiv.{u1, succ u2} α₁ β₁) -> (Equiv.{u3, succ u4} α₂ β₂) -> (Equiv.{max (max 1 u3) u1, max (succ u4) (succ u2)} (PProd.{u1, u3} α₁ α₂) (Prod.{u2, u4} β₁ β₂)) Case conversion may be inaccurate. Consider using '#align equiv.pprod_prod Equiv.pprodProdₓ'. -/ /-- Combine two equivalences using `pprod` in the domain and `prod` in the codomain. -/ @[simps apply symm_apply] def pprodProd {α₁ β₁ : Sort _} {α₂ β₂ : Type _} (ea : α₁ ≃ α₂) (eb : β₁ ≃ β₂) : PProd α₁ β₁ ≃ α₂ × β₂ := (ea.pprodCongr eb).trans pprodEquivProd #align equiv.pprod_prod Equiv.pprodProd /- warning: equiv.prod_pprod -> Equiv.prodPProd is a dubious translation: lean 3 declaration is forall {α₁ : Type.{u1}} {β₁ : Type.{u2}} {α₂ : Sort.{u3}} {β₂ : Sort.{u4}}, (Equiv.{succ u1, u3} α₁ α₂) -> (Equiv.{succ u2, u4} β₁ β₂) -> (Equiv.{max (succ u1) (succ u2), max 1 u3 u4} (Prod.{u1, u2} α₁ β₁) (PProd.{u3, u4} α₂ β₂)) but is expected to have type forall {α₁ : Type.{u1}} {β₁ : Sort.{u2}} {α₂ : Type.{u3}} {β₂ : Sort.{u4}}, (Equiv.{succ u1, u2} α₁ β₁) -> (Equiv.{succ u3, u4} α₂ β₂) -> (Equiv.{max (succ u3) (succ u1), max (max 1 u4) u2} (Prod.{u1, u3} α₁ α₂) (PProd.{u2, u4} β₁ β₂)) Case conversion may be inaccurate. Consider using '#align equiv.prod_pprod Equiv.prodPProdₓ'. -/ /-- Combine two equivalences using `pprod` in the codomain and `prod` in the domain. -/ @[simps apply symm_apply] def prodPProd {α₁ β₁ : Type _} {α₂ β₂ : Sort _} (ea : α₁ ≃ α₂) (eb : β₁ ≃ β₂) : α₁ × β₁ ≃ PProd α₂ β₂ := (ea.symm.pprodProd eb.symm).symm #align equiv.prod_pprod Equiv.prodPProd #print Equiv.pprodEquivProdPLift /- /-- `pprod α β` is equivalent to `plift α × plift β` -/ @[simps apply symm_apply] def pprodEquivProdPLift {α β : Sort _} : PProd α β ≃ PLift α × PLift β := Equiv.plift.symm.pprodProd Equiv.plift.symm #align equiv.pprod_equiv_prod_plift Equiv.pprodEquivProdPLift -/ /- warning: equiv.prod_congr -> Equiv.prodCongr is a dubious translation: lean 3 declaration is forall {α₁ : Type.{u1}} {β₁ : Type.{u2}} {α₂ : Type.{u3}} {β₂ : Type.{u4}}, (Equiv.{succ u1, succ u3} α₁ α₂) -> (Equiv.{succ u2, succ u4} β₁ β₂) -> (Equiv.{max (succ u1) (succ u2), max (succ u3) (succ u4)} (Prod.{u1, u2} α₁ β₁) (Prod.{u3, u4} α₂ β₂)) but is expected to have type forall {α₁ : Type.{u1}} {β₁ : Type.{u2}} {α₂ : Type.{u3}} {β₂ : Type.{u4}}, (Equiv.{succ u1, succ u2} α₁ β₁) -> (Equiv.{succ u3, succ u4} α₂ β₂) -> (Equiv.{max (succ u3) (succ u1), max (succ u4) (succ u2)} (Prod.{u1, u3} α₁ α₂) (Prod.{u2, u4} β₁ β₂)) Case conversion may be inaccurate. Consider using '#align equiv.prod_congr Equiv.prodCongrₓ'. -/ /-- Product of two equivalences. If `α₁ ≃ α₂` and `β₁ ≃ β₂`, then `α₁ × β₁ ≃ α₂ × β₂`. This is `prod.map` as an equivalence. -/ @[congr, simps (config := { fullyApplied := false }) apply] def prodCongr {α₁ β₁ α₂ β₂ : Type _} (e₁ : α₁ ≃ α₂) (e₂ : β₁ ≃ β₂) : α₁ × β₁ ≃ α₂ × β₂ := ⟨Prod.map e₁ e₂, Prod.map e₁.symm e₂.symm, fun ⟨a, b⟩ => by simp, fun ⟨a, b⟩ => by simp⟩ #align equiv.prod_congr Equiv.prodCongr /- warning: equiv.prod_congr_symm -> Equiv.prodCongr_symm is a dubious translation: lean 3 declaration is forall {α₁ : Type.{u1}} {β₁ : Type.{u2}} {α₂ : Type.{u3}} {β₂ : Type.{u4}} (e₁ : Equiv.{succ u1, succ u3} α₁ α₂) (e₂ : Equiv.{succ u2, succ u4} β₁ β₂), Eq.{max 1 (max (max (succ u3) (succ u4)) (succ u1) (succ u2)) (max (succ u1) (succ u2)) (succ u3) (succ u4)} (Equiv.{max (succ u3) (succ u4), max (succ u1) (succ u2)} (Prod.{u3, u4} α₂ β₂) (Prod.{u1, u2} α₁ β₁)) (Equiv.symm.{max (succ u1) (succ u2), max (succ u3) (succ u4)} (Prod.{u1, u2} α₁ β₁) (Prod.{u3, u4} α₂ β₂) (Equiv.prodCongr.{u1, u2, u3, u4} α₁ β₁ α₂ β₂ e₁ e₂)) (Equiv.prodCongr.{u3, u4, u1, u2} α₂ β₂ α₁ β₁ (Equiv.symm.{succ u1, succ u3} α₁ α₂ e₁) (Equiv.symm.{succ u2, succ u4} β₁ β₂ e₂)) but is expected to have type forall {α₁ : Type.{u4}} {β₁ : Type.{u3}} {α₂ : Type.{u2}} {β₂ : Type.{u1}} (e₁ : Equiv.{succ u4, succ u3} α₁ β₁) (e₂ : Equiv.{succ u2, succ u1} α₂ β₂), Eq.{max (max (max (succ u1) (succ u2)) (succ u3)) (succ u4)} (Equiv.{max (succ u1) (succ u3), max (succ u2) (succ u4)} (Prod.{u3, u1} β₁ β₂) (Prod.{u4, u2} α₁ α₂)) (Equiv.symm.{max (succ u2) (succ u4), max (succ u1) (succ u3)} (Prod.{u4, u2} α₁ α₂) (Prod.{u3, u1} β₁ β₂) (Equiv.prodCongr.{u4, u3, u2, u1} α₁ β₁ α₂ β₂ e₁ e₂)) (Equiv.prodCongr.{u3, u4, u1, u2} β₁ α₁ β₂ α₂ (Equiv.symm.{succ u4, succ u3} α₁ β₁ e₁) (Equiv.symm.{succ u2, succ u1} α₂ β₂ e₂)) Case conversion may be inaccurate. Consider using '#align equiv.prod_congr_symm Equiv.prodCongr_symmₓ'. -/ @[simp] theorem prodCongr_symm {α₁ β₁ α₂ β₂ : Type _} (e₁ : α₁ ≃ α₂) (e₂ : β₁ ≃ β₂) : (prodCongr e₁ e₂).symm = prodCongr e₁.symm e₂.symm := rfl #align equiv.prod_congr_symm Equiv.prodCongr_symm #print Equiv.prodComm /- /-- Type product is commutative up to an equivalence: `α × β ≃ β × α`. This is `prod.swap` as an equivalence.-/ def prodComm (α β : Type _) : α × β ≃ β × α := ⟨Prod.swap, Prod.swap, Prod.swap_swap, Prod.swap_swap⟩ #align equiv.prod_comm Equiv.prodComm -/ /- warning: equiv.coe_prod_comm -> Equiv.coe_prodComm is a dubious translation: lean 3 declaration is forall (α : Type.{u1}) (β : Type.{u2}), Eq.{max (max (succ u1) (succ u2)) (succ u2) (succ u1)} ((Prod.{u1, u2} α β) -> (Prod.{u2, u1} β α)) (coeFn.{max 1 (max (max (succ u1) (succ u2)) (succ u2) (succ u1)) (max (succ u2) (succ u1)) (succ u1) (succ u2), max (max (succ u1) (succ u2)) (succ u2) (succ u1)} (Equiv.{max (succ u1) (succ u2), max (succ u2) (succ u1)} (Prod.{u1, u2} α β) (Prod.{u2, u1} β α)) (fun (_x : Equiv.{max (succ u1) (succ u2), max (succ u2) (succ u1)} (Prod.{u1, u2} α β) (Prod.{u2, u1} β α)) => (Prod.{u1, u2} α β) -> (Prod.{u2, u1} β α)) (Equiv.hasCoeToFun.{max (succ u1) (succ u2), max (succ u2) (succ u1)} (Prod.{u1, u2} α β) (Prod.{u2, u1} β α)) (Equiv.prodComm.{u1, u2} α β)) (Prod.swap.{u1, u2} α β) but is expected to have type forall (α : Type.{u2}) (β : Type.{u1}), Eq.{max (succ u1) (succ u2)} (forall (ᾰ : Prod.{u2, u1} α β), (fun ([email protected]._hyg.808 : Prod.{u2, u1} α β) => Prod.{u1, u2} β α) ᾰ) (FunLike.coe.{max (succ u1) (succ u2), max (succ u1) (succ u2), max (succ u1) (succ u2)} (Equiv.{max (succ u1) (succ u2), max (succ u2) (succ u1)} (Prod.{u2, u1} α β) (Prod.{u1, u2} β α)) (Prod.{u2, u1} α β) (fun (_x : Prod.{u2, u1} α β) => (fun ([email protected]._hyg.808 : Prod.{u2, u1} α β) => Prod.{u1, u2} β α) _x) (Equiv.instFunLikeEquiv.{max (succ u1) (succ u2), max (succ u1) (succ u2)} (Prod.{u2, u1} α β) (Prod.{u1, u2} β α)) (Equiv.prodComm.{u2, u1} α β)) (Prod.swap.{u2, u1} α β) Case conversion may be inaccurate. Consider using '#align equiv.coe_prod_comm Equiv.coe_prodCommₓ'. -/ @[simp] theorem coe_prodComm (α β : Type _) : ⇑(prodComm α β) = Prod.swap := rfl #align equiv.coe_prod_comm Equiv.coe_prodComm /- warning: equiv.prod_comm_apply -> Equiv.prodComm_apply is a dubious translation: lean 3 declaration is forall {α : Type.{u1}} {β : Type.{u2}} (x : Prod.{u1, u2} α β), Eq.{max (succ u2) (succ u1)} (Prod.{u2, u1} β α) (coeFn.{max 1 (max (max (succ u1) (succ u2)) (succ u2) (succ u1)) (max (succ u2) (succ u1)) (succ u1) (succ u2), max (max (succ u1) (succ u2)) (succ u2) (succ u1)} (Equiv.{max (succ u1) (succ u2), max (succ u2) (succ u1)} (Prod.{u1, u2} α β) (Prod.{u2, u1} β α)) (fun (_x : Equiv.{max (succ u1) (succ u2), max (succ u2) (succ u1)} (Prod.{u1, u2} α β) (Prod.{u2, u1} β α)) => (Prod.{u1, u2} α β) -> (Prod.{u2, u1} β α)) (Equiv.hasCoeToFun.{max (succ u1) (succ u2), max (succ u2) (succ u1)} (Prod.{u1, u2} α β) (Prod.{u2, u1} β α)) (Equiv.prodComm.{u1, u2} α β) x) (Prod.swap.{u1, u2} α β x) but is expected to have type forall {α : Type.{u2}} {β : Type.{u1}} (x : Prod.{u2, u1} α β), Eq.{max (succ u1) (succ u2)} ((fun ([email protected]._hyg.808 : Prod.{u2, u1} α β) => Prod.{u1, u2} β α) x) (FunLike.coe.{max (succ u1) (succ u2), max (succ u1) (succ u2), max (succ u1) (succ u2)} (Equiv.{max (succ u1) (succ u2), max (succ u2) (succ u1)} (Prod.{u2, u1} α β) (Prod.{u1, u2} β α)) (Prod.{u2, u1} α β) (fun (_x : Prod.{u2, u1} α β) => (fun ([email protected]._hyg.808 : Prod.{u2, u1} α β) => Prod.{u1, u2} β α) _x) (Equiv.instFunLikeEquiv.{max (succ u1) (succ u2), max (succ u1) (succ u2)} (Prod.{u2, u1} α β) (Prod.{u1, u2} β α)) (Equiv.prodComm.{u2, u1} α β) x) (Prod.swap.{u2, u1} α β x) Case conversion may be inaccurate. Consider using '#align equiv.prod_comm_apply Equiv.prodComm_applyₓ'. -/ @[simp] theorem prodComm_apply {α β : Type _} (x : α × β) : prodComm α β x = x.symm := rfl #align equiv.prod_comm_apply Equiv.prodComm_apply /- warning: equiv.prod_comm_symm -> Equiv.prodComm_symm is a dubious translation: lean 3 declaration is forall (α : Type.{u1}) (β : Type.{u2}), Eq.{max 1 (max (max (succ u2) (succ u1)) (succ u1) (succ u2)) (max (succ u1) (succ u2)) (succ u2) (succ u1)} (Equiv.{max (succ u2) (succ u1), max (succ u1) (succ u2)} (Prod.{u2, u1} β α) (Prod.{u1, u2} α β)) (Equiv.symm.{max (succ u1) (succ u2), max (succ u2) (succ u1)} (Prod.{u1, u2} α β) (Prod.{u2, u1} β α) (Equiv.prodComm.{u1, u2} α β)) (Equiv.prodComm.{u2, u1} β α) but is expected to have type forall (α : Type.{u2}) (β : Type.{u1}), Eq.{max (succ u1) (succ u2)} (Equiv.{max (succ u1) (succ u2), max (succ u1) (succ u2)} (Prod.{u1, u2} β α) (Prod.{u2, u1} α β)) (Equiv.symm.{max (succ u1) (succ u2), max (succ u1) (succ u2)} (Prod.{u2, u1} α β) (Prod.{u1, u2} β α) (Equiv.prodComm.{u2, u1} α β)) (Equiv.prodComm.{u1, u2} β α) Case conversion may be inaccurate. Consider using '#align equiv.prod_comm_symm Equiv.prodComm_symmₓ'. -/ @[simp] theorem prodComm_symm (α β) : (prodComm α β).symm = prodComm β α := rfl #align equiv.prod_comm_symm Equiv.prodComm_symm #print Equiv.prodAssoc /- /-- Type product is associative up to an equivalence. -/ @[simps] def prodAssoc (α β γ : Sort _) : (α × β) × γ ≃ α × β × γ := ⟨fun p => (p.1.1, p.1.2, p.2), fun p => ((p.1, p.2.1), p.2.2), fun ⟨⟨a, b⟩, c⟩ => rfl, fun ⟨a, ⟨b, c⟩⟩ => rfl⟩ #align equiv.prod_assoc Equiv.prodAssoc -/ #print Equiv.curry /- /-- Functions on `α × β` are equivalent to functions `α → β → γ`. -/ @[simps (config := { fullyApplied := false })] def curry (α β γ : Type _) : (α × β → γ) ≃ (α → β → γ) where toFun := curry invFun := uncurry left_inv := uncurry_curry right_inv := curry_uncurry #align equiv.curry Equiv.curry -/ section /- warning: equiv.prod_punit -> Equiv.prodPUnit is a dubious translation: lean 3 declaration is forall (α : Type.{u2}), Equiv.{max (succ u2) (succ u1), succ u2} (Prod.{u2, u1} α PUnit.{succ u1}) α but is expected to have type forall (α : Type.{u1}), Equiv.{max (succ u2) (succ u1), succ u1} (Prod.{u1, u2} α PUnit.{succ u2}) α Case conversion may be inaccurate. Consider using '#align equiv.prod_punit Equiv.prodPUnitₓ'. -/ /-- `punit` is a right identity for type product up to an equivalence. -/ @[simps] def prodPUnit (α : Type _) : α × PUnit.{u + 1} ≃ α := ⟨fun p => p.1, fun a => (a, PUnit.unit), fun ⟨_, PUnit.unit⟩ => rfl, fun a => rfl⟩ #align equiv.prod_punit Equiv.prodPUnit /- warning: equiv.punit_prod -> Equiv.punitProd is a dubious translation: lean 3 declaration is forall (α : Type.{u2}), Equiv.{max (succ u1) (succ u2), succ u2} (Prod.{u1, u2} PUnit.{succ u1} α) α but is expected to have type forall (α : Type.{u1}), Equiv.{max (succ u1) (succ u2), succ u1} (Prod.{u2, u1} PUnit.{succ u2} α) α Case conversion may be inaccurate. Consider using '#align equiv.punit_prod Equiv.punitProdₓ'. -/ /-- `punit` is a left identity for type product up to an equivalence. -/ @[simps] def punitProd (α : Type _) : PUnit.{u + 1} × α ≃ α := calc PUnit × α ≃ α × PUnit := prodComm _ _ _ ≃ α := prodPUnit _ #align equiv.punit_prod Equiv.punitProd /- warning: equiv.prod_unique -> Equiv.prodUnique is a dubious translation: lean 3 declaration is forall (α : Type.{u_1}) (β : Type.{u_2}) [_inst_1 : Unique.{succ u_2} β], Equiv.{max (succ u_1) (succ u_2), succ u_1} (Prod.{u_1, u_2} α β) α but is expected to have type forall (α : Type.{u_1}) (β : Type.{u_2}) [_inst_1 : Unique.{succ u_2} β], Equiv.{max (succ u_2) (succ u_1), succ u_1} (Prod.{u_1, u_2} α β) α Case conversion may be inaccurate. Consider using '#align equiv.prod_unique Equiv.prodUniqueₓ'. -/ /-- Any `unique` type is a right identity for type product up to equivalence. -/ def prodUnique (α β : Type _) [Unique β] : α × β ≃ α := ((Equiv.refl α).prodCongr <| equivPUnit β).trans <| prodPUnit α #align equiv.prod_unique Equiv.prodUnique /- warning: equiv.coe_prod_unique -> Equiv.coe_prodUnique is a dubious translation: lean 3 declaration is forall {α : Type.{u_1}} {β : Type.{u_2}} [_inst_1 : Unique.{succ u_2} β], Eq.{max (succ u_1) (succ u_2)} ((Prod.{u_1, u_2} α β) -> α) (coeFn.{max 1 (succ u_1) (succ u_2), max (succ u_1) (succ u_2)} (Equiv.{max (succ u_1) (succ u_2), succ u_1} (Prod.{u_1, u_2} α β) α) (fun (_x : Equiv.{max (succ u_1) (succ u_2), succ u_1} (Prod.{u_1, u_2} α β) α) => (Prod.{u_1, u_2} α β) -> α) (Equiv.hasCoeToFun.{max (succ u_1) (succ u_2), succ u_1} (Prod.{u_1, u_2} α β) α) (Equiv.prodUnique.{u_1, u_2, u_3} α β _inst_1)) (Prod.fst.{u_1, u_2} α β) but is expected to have type forall {α : Type.{u_1}} {β : Type.{u_2}} [_inst_1 : Unique.{succ u_1} α], Eq.{max (succ u_1) (succ u_2)} (forall (ᾰ : Prod.{u_2, u_1} β α), (fun ([email protected]._hyg.808 : Prod.{u_2, u_1} β α) => β) ᾰ) (FunLike.coe.{max (succ u_1) (succ u_2), max (succ u_1) (succ u_2), succ u_2} (Equiv.{max (succ u_1) (succ u_2), succ u_2} (Prod.{u_2, u_1} β α) β) (Prod.{u_2, u_1} β α) (fun (_x : Prod.{u_2, u_1} β α) => (fun ([email protected]._hyg.808 : Prod.{u_2, u_1} β α) => β) _x) (Equiv.instFunLikeEquiv.{max (succ u_1) (succ u_2), succ u_2} (Prod.{u_2, u_1} β α) β) (Equiv.prodUnique.{u_2, u_1} β α _inst_1)) (Prod.fst.{u_2, u_1} β α) Case conversion may be inaccurate. Consider using '#align equiv.coe_prod_unique Equiv.coe_prodUniqueₓ'. -/ @[simp] theorem coe_prodUnique {α β : Type _} [Unique β] : ⇑(prodUnique α β) = Prod.fst := rfl #align equiv.coe_prod_unique Equiv.coe_prodUnique /- warning: equiv.prod_unique_apply -> Equiv.prodUnique_apply is a dubious translation: lean 3 declaration is forall {α : Type.{u_1}} {β : Type.{u_2}} [_inst_1 : Unique.{succ u_2} β] (x : Prod.{u_1, u_2} α β), Eq.{succ u_1} α (coeFn.{max 1 (succ u_1) (succ u_2), max (succ u_1) (succ u_2)} (Equiv.{max (succ u_1) (succ u_2), succ u_1} (Prod.{u_1, u_2} α β) α) (fun (_x : Equiv.{max (succ u_1) (succ u_2), succ u_1} (Prod.{u_1, u_2} α β) α) => (Prod.{u_1, u_2} α β) -> α) (Equiv.hasCoeToFun.{max (succ u_1) (succ u_2), succ u_1} (Prod.{u_1, u_2} α β) α) (Equiv.prodUnique.{u_1, u_2, u_3} α β _inst_1) x) (Prod.fst.{u_1, u_2} α β x) but is expected to have type forall {α : Type.{u_1}} {β : Type.{u_2}} [_inst_1 : Unique.{succ u_1} α] (x : Prod.{u_2, u_1} β α), Eq.{succ u_2} ((fun ([email protected]._hyg.808 : Prod.{u_2, u_1} β α) => β) x) (FunLike.coe.{max (succ u_1) (succ u_2), max (succ u_1) (succ u_2), succ u_2} (Equiv.{max (succ u_1) (succ u_2), succ u_2} (Prod.{u_2, u_1} β α) β) (Prod.{u_2, u_1} β α) (fun (_x : Prod.{u_2, u_1} β α) => (fun ([email protected]._hyg.808 : Prod.{u_2, u_1} β α) => β) _x) (Equiv.instFunLikeEquiv.{max (succ u_1) (succ u_2), succ u_2} (Prod.{u_2, u_1} β α) β) (Equiv.prodUnique.{u_2, u_1} β α _inst_1) x) (Prod.fst.{u_2, u_1} β α x) Case conversion may be inaccurate. Consider using '#align equiv.prod_unique_apply Equiv.prodUnique_applyₓ'. -/ theorem prodUnique_apply {α β : Type _} [Unique β] (x : α × β) : prodUnique α β x = x.1 := rfl #align equiv.prod_unique_apply Equiv.prodUnique_apply /- warning: equiv.prod_unique_symm_apply -> Equiv.prodUnique_symm_apply is a dubious translation: lean 3 declaration is forall {α : Type.{u_1}} {β : Type.{u_2}} [_inst_1 : Unique.{succ u_2} β] (x : α), Eq.{max (succ u_1) (succ u_2)} (Prod.{u_1, u_2} α β) (coeFn.{max 1 (succ u_1) (succ u_2), max (succ u_1) (succ u_2)} (Equiv.{succ u_1, max (succ u_1) (succ u_2)} α (Prod.{u_1, u_2} α β)) (fun (_x : Equiv.{succ u_1, max (succ u_1) (succ u_2)} α (Prod.{u_1, u_2} α β)) => α -> (Prod.{u_1, u_2} α β)) (Equiv.hasCoeToFun.{succ u_1, max (succ u_1) (succ u_2)} α (Prod.{u_1, u_2} α β)) (Equiv.symm.{max (succ u_1) (succ u_2), succ u_1} (Prod.{u_1, u_2} α β) α (Equiv.prodUnique.{u_1, u_2, u_3} α β _inst_1)) x) (Prod.mk.{u_1, u_2} α β x (Inhabited.default.{succ u_2} β (Unique.inhabited.{succ u_2} β _inst_1))) but is expected to have type forall {α : Type.{u_1}} {β : Type.{u_2}} [_inst_1 : Unique.{succ u_1} α] (x : β), Eq.{max (succ u_1) (succ u_2)} ((fun ([email protected]._hyg.808 : β) => Prod.{u_2, u_1} β α) x) (FunLike.coe.{max (succ u_1) (succ u_2), succ u_2, max (succ u_1) (succ u_2)} (Equiv.{succ u_2, max (succ u_1) (succ u_2)} β (Prod.{u_2, u_1} β α)) β (fun (_x : β) => (fun ([email protected]._hyg.808 : β) => Prod.{u_2, u_1} β α) _x) (Equiv.instFunLikeEquiv.{succ u_2, max (succ u_1) (succ u_2)} β (Prod.{u_2, u_1} β α)) (Equiv.symm.{max (succ u_1) (succ u_2), succ u_2} (Prod.{u_2, u_1} β α) β (Equiv.prodUnique.{u_2, u_1} β α _inst_1)) x) (Prod.mk.{u_2, u_1} β α x (Inhabited.default.{succ u_1} α (Unique.instInhabited.{succ u_1} α _inst_1))) Case conversion may be inaccurate. Consider using '#align equiv.prod_unique_symm_apply Equiv.prodUnique_symm_applyₓ'. -/ @[simp] theorem prodUnique_symm_apply {α β : Type _} [Unique β] (x : α) : (prodUnique α β).symm x = (x, default) := rfl #align equiv.prod_unique_symm_apply Equiv.prodUnique_symm_apply /- warning: equiv.unique_prod -> Equiv.uniqueProd is a dubious translation: lean 3 declaration is forall (α : Type.{u_1}) (β : Type.{u_2}) [_inst_1 : Unique.{succ u_2} β], Equiv.{max (succ u_2) (succ u_1), succ u_1} (Prod.{u_2, u_1} β α) α but is expected to have type forall (α : Type.{u_1}) (β : Type.{u_2}) [_inst_1 : Unique.{succ u_2} β], Equiv.{max (succ u_1) (succ u_2), succ u_1} (Prod.{u_2, u_1} β α) α Case conversion may be inaccurate. Consider using '#align equiv.unique_prod Equiv.uniqueProdₓ'. -/ /-- Any `unique` type is a left identity for type product up to equivalence. -/ def uniqueProd (α β : Type _) [Unique β] : β × α ≃ α := ((equivPUnit β).prodCongr <| Equiv.refl α).trans <| punitProd α #align equiv.unique_prod Equiv.uniqueProd /- warning: equiv.coe_unique_prod -> Equiv.coe_uniqueProd is a dubious translation: lean 3 declaration is forall {α : Type.{u_1}} {β : Type.{u_2}} [_inst_1 : Unique.{succ u_2} β], Eq.{max (succ u_2) (succ u_1)} ((Prod.{u_2, u_1} β α) -> α) (coeFn.{max 1 (succ u_2) (succ u_1), max (succ u_2) (succ u_1)} (Equiv.{max (succ u_2) (succ u_1), succ u_1} (Prod.{u_2, u_1} β α) α) (fun (_x : Equiv.{max (succ u_2) (succ u_1), succ u_1} (Prod.{u_2, u_1} β α) α) => (Prod.{u_2, u_1} β α) -> α) (Equiv.hasCoeToFun.{max (succ u_2) (succ u_1), succ u_1} (Prod.{u_2, u_1} β α) α) (Equiv.uniqueProd.{u_1, u_2, u_3} α β _inst_1)) (Prod.snd.{u_2, u_1} β α) but is expected to have type forall {α : Type.{u_1}} {β : Type.{u_2}} [_inst_1 : Unique.{succ u_1} α], Eq.{max (succ u_2) (succ u_1)} (forall (ᾰ : Prod.{u_1, u_2} α β), (fun ([email protected]._hyg.808 : Prod.{u_1, u_2} α β) => β) ᾰ) (FunLike.coe.{max (succ u_2) (succ u_1), max (succ u_2) (succ u_1), succ u_2} (Equiv.{max (succ u_2) (succ u_1), succ u_2} (Prod.{u_1, u_2} α β) β) (Prod.{u_1, u_2} α β) (fun (_x : Prod.{u_1, u_2} α β) => (fun ([email protected]._hyg.808 : Prod.{u_1, u_2} α β) => β) _x) (Equiv.instFunLikeEquiv.{max (succ u_2) (succ u_1), succ u_2} (Prod.{u_1, u_2} α β) β) (Equiv.uniqueProd.{u_2, u_1} β α _inst_1)) (Prod.snd.{u_1, u_2} α β) Case conversion may be inaccurate. Consider using '#align equiv.coe_unique_prod Equiv.coe_uniqueProdₓ'. -/ @[simp] theorem coe_uniqueProd {α β : Type _} [Unique β] : ⇑(uniqueProd α β) = Prod.snd := rfl #align equiv.coe_unique_prod Equiv.coe_uniqueProd /- warning: equiv.unique_prod_apply -> Equiv.uniqueProd_apply is a dubious translation: lean 3 declaration is forall {α : Type.{u_1}} {β : Type.{u_2}} [_inst_1 : Unique.{succ u_2} β] (x : Prod.{u_2, u_1} β α), Eq.{succ u_1} α (coeFn.{max 1 (succ u_2) (succ u_1), max (succ u_2) (succ u_1)} (Equiv.{max (succ u_2) (succ u_1), succ u_1} (Prod.{u_2, u_1} β α) α) (fun (_x : Equiv.{max (succ u_2) (succ u_1), succ u_1} (Prod.{u_2, u_1} β α) α) => (Prod.{u_2, u_1} β α) -> α) (Equiv.hasCoeToFun.{max (succ u_2) (succ u_1), succ u_1} (Prod.{u_2, u_1} β α) α) (Equiv.uniqueProd.{u_1, u_2, u_3} α β _inst_1) x) (Prod.snd.{u_2, u_1} β α x) but is expected to have type forall {α : Type.{u_1}} {β : Type.{u_2}} [_inst_1 : Unique.{succ u_1} α] (x : Prod.{u_1, u_2} α β), Eq.{succ u_2} ((fun ([email protected]._hyg.808 : Prod.{u_1, u_2} α β) => β) x) (FunLike.coe.{max (succ u_2) (succ u_1), max (succ u_2) (succ u_1), succ u_2} (Equiv.{max (succ u_2) (succ u_1), succ u_2} (Prod.{u_1, u_2} α β) β) (Prod.{u_1, u_2} α β) (fun (_x : Prod.{u_1, u_2} α β) => (fun ([email protected]._hyg.808 : Prod.{u_1, u_2} α β) => β) _x) (Equiv.instFunLikeEquiv.{max (succ u_2) (succ u_1), succ u_2} (Prod.{u_1, u_2} α β) β) (Equiv.uniqueProd.{u_2, u_1} β α _inst_1) x) (Prod.snd.{u_1, u_2} α β x) Case conversion may be inaccurate. Consider using '#align equiv.unique_prod_apply Equiv.uniqueProd_applyₓ'. -/ theorem uniqueProd_apply {α β : Type _} [Unique β] (x : β × α) : uniqueProd α β x = x.2 := rfl #align equiv.unique_prod_apply Equiv.uniqueProd_apply /- warning: equiv.unique_prod_symm_apply -> Equiv.uniqueProd_symm_apply is a dubious translation: lean 3 declaration is forall {α : Type.{u_1}} {β : Type.{u_2}} [_inst_1 : Unique.{succ u_2} β] (x : α), Eq.{max (succ u_2) (succ u_1)} (Prod.{u_2, u_1} β α) (coeFn.{max 1 (succ u_2) (succ u_1), max (succ u_2) (succ u_1)} (Equiv.{succ u_1, max (succ u_2) (succ u_1)} α (Prod.{u_2, u_1} β α)) (fun (_x : Equiv.{succ u_1, max (succ u_2) (succ u_1)} α (Prod.{u_2, u_1} β α)) => α -> (Prod.{u_2, u_1} β α)) (Equiv.hasCoeToFun.{succ u_1, max (succ u_2) (succ u_1)} α (Prod.{u_2, u_1} β α)) (Equiv.symm.{max (succ u_2) (succ u_1), succ u_1} (Prod.{u_2, u_1} β α) α (Equiv.uniqueProd.{u_1, u_2, u_3} α β _inst_1)) x) (Prod.mk.{u_2, u_1} β α (Inhabited.default.{succ u_2} β (Unique.inhabited.{succ u_2} β _inst_1)) x) but is expected to have type forall {α : Type.{u_1}} {β : Type.{u_2}} [_inst_1 : Unique.{succ u_1} α] (x : β), Eq.{max (succ u_1) (succ u_2)} ((fun ([email protected]._hyg.808 : β) => Prod.{u_1, u_2} α β) x) (FunLike.coe.{max (succ u_1) (succ u_2), succ u_2, max (succ u_1) (succ u_2)} (Equiv.{succ u_2, max (succ u_1) (succ u_2)} β (Prod.{u_1, u_2} α β)) β (fun (_x : β) => (fun ([email protected]._hyg.808 : β) => Prod.{u_1, u_2} α β) _x) (Equiv.instFunLikeEquiv.{succ u_2, max (succ u_1) (succ u_2)} β (Prod.{u_1, u_2} α β)) (Equiv.symm.{max (succ u_1) (succ u_2), succ u_2} (Prod.{u_1, u_2} α β) β (Equiv.uniqueProd.{u_2, u_1} β α _inst_1)) x) (Prod.mk.{u_1, u_2} α β (Inhabited.default.{succ u_1} α (Unique.instInhabited.{succ u_1} α _inst_1)) x) Case conversion may be inaccurate. Consider using '#align equiv.unique_prod_symm_apply Equiv.uniqueProd_symm_applyₓ'. -/ @[simp] theorem uniqueProd_symm_apply {α β : Type _} [Unique β] (x : α) : (uniqueProd α β).symm x = (default, x) := rfl #align equiv.unique_prod_symm_apply Equiv.uniqueProd_symm_apply #print Equiv.prodEmpty /- /-- `empty` type is a right absorbing element for type product up to an equivalence. -/ def prodEmpty (α : Type _) : α × Empty ≃ Empty := equivEmpty _ #align equiv.prod_empty Equiv.prodEmpty -/ #print Equiv.emptyProd /- /-- `empty` type is a left absorbing element for type product up to an equivalence. -/ def emptyProd (α : Type _) : Empty × α ≃ Empty := equivEmpty _ #align equiv.empty_prod Equiv.emptyProd -/ #print Equiv.prodPEmpty /- /-- `pempty` type is a right absorbing element for type product up to an equivalence. -/ def prodPEmpty (α : Type _) : α × PEmpty ≃ PEmpty := equivPEmpty _ #align equiv.prod_pempty Equiv.prodPEmpty -/ #print Equiv.pemptyProd /- /-- `pempty` type is a left absorbing element for type product up to an equivalence. -/ def pemptyProd (α : Type _) : PEmpty × α ≃ PEmpty := equivPEmpty _ #align equiv.pempty_prod Equiv.pemptyProd -/ end section open Sum #print Equiv.psumEquivSum /- /-- `psum` is equivalent to `sum`. -/ def psumEquivSum (α β : Type _) : PSum α β ≃ Sum α β where toFun s := PSum.casesOn s inl inr invFun := Sum.elim PSum.inl PSum.inr left_inv s := by cases s <;> rfl right_inv s := by cases s <;> rfl #align equiv.psum_equiv_sum Equiv.psumEquivSum -/ /- warning: equiv.sum_congr -> Equiv.sumCongr is a dubious translation: lean 3 declaration is forall {α₁ : Type.{u1}} {β₁ : Type.{u2}} {α₂ : Type.{u3}} {β₂ : Type.{u4}}, (Equiv.{succ u1, succ u3} α₁ α₂) -> (Equiv.{succ u2, succ u4} β₁ β₂) -> (Equiv.{max (succ u1) (succ u2), max (succ u3) (succ u4)} (Sum.{u1, u2} α₁ β₁) (Sum.{u3, u4} α₂ β₂)) but is expected to have type forall {α₁ : Type.{u1}} {β₁ : Type.{u2}} {α₂ : Type.{u3}} {β₂ : Type.{u4}}, (Equiv.{succ u1, succ u2} α₁ β₁) -> (Equiv.{succ u3, succ u4} α₂ β₂) -> (Equiv.{max (succ u3) (succ u1), max (succ u4) (succ u2)} (Sum.{u1, u3} α₁ α₂) (Sum.{u2, u4} β₁ β₂)) Case conversion may be inaccurate. Consider using '#align equiv.sum_congr Equiv.sumCongrₓ'. -/ /-- If `α ≃ α'` and `β ≃ β'`, then `α ⊕ β ≃ α' ⊕ β'`. This is `sum.map` as an equivalence. -/ @[simps apply] def sumCongr {α₁ β₁ α₂ β₂ : Type _} (ea : α₁ ≃ α₂) (eb : β₁ ≃ β₂) : Sum α₁ β₁ ≃ Sum α₂ β₂ := ⟨Sum.map ea eb, Sum.map ea.symm eb.symm, fun x => by simp, fun x => by simp⟩ #align equiv.sum_congr Equiv.sumCongr #print Equiv.psumCongr /- /-- If `α ≃ α'` and `β ≃ β'`, then `psum α β ≃ psum α' β'`. -/ def psumCongr {δ : Sort z} (e₁ : α ≃ β) (e₂ : γ ≃ δ) : PSum α γ ≃ PSum β δ where toFun x := PSum.casesOn x (PSum.inl ∘ e₁) (PSum.inr ∘ e₂) invFun x := PSum.casesOn x (PSum.inl ∘ e₁.symm) (PSum.inr ∘ e₂.symm) left_inv := by rintro (x | x) <;> simp right_inv := by rintro (x | x) <;> simp #align equiv.psum_congr Equiv.psumCongr -/ /- warning: equiv.psum_sum -> Equiv.psumSum is a dubious translation: lean 3 declaration is forall {α₁ : Sort.{u1}} {β₁ : Sort.{u2}} {α₂ : Type.{u3}} {β₂ : Type.{u4}}, (Equiv.{u1, succ u3} α₁ α₂) -> (Equiv.{u2, succ u4} β₁ β₂) -> (Equiv.{max 1 u1 u2, max (succ u3) (succ u4)} (PSum.{u1, u2} α₁ β₁) (Sum.{u3, u4} α₂ β₂)) but is expected to have type forall {α₁ : Sort.{u1}} {β₁ : Type.{u2}} {α₂ : Sort.{u3}} {β₂ : Type.{u4}}, (Equiv.{u1, succ u2} α₁ β₁) -> (Equiv.{u3, succ u4} α₂ β₂) -> (Equiv.{max (max 1 u3) u1, max (succ u4) (succ u2)} (PSum.{u1, u3} α₁ α₂) (Sum.{u2, u4} β₁ β₂)) Case conversion may be inaccurate. Consider using '#align equiv.psum_sum Equiv.psumSumₓ'. -/ /-- Combine two `equiv`s using `psum` in the domain and `sum` in the codomain. -/ def psumSum {α₁ β₁ : Sort _} {α₂ β₂ : Type _} (ea : α₁ ≃ α₂) (eb : β₁ ≃ β₂) : PSum α₁ β₁ ≃ Sum α₂ β₂ := (ea.psumCongr eb).trans (psumEquivSum _ _) #align equiv.psum_sum Equiv.psumSum /- warning: equiv.sum_psum -> Equiv.sumPSum is a dubious translation: lean 3 declaration is forall {α₁ : Type.{u1}} {β₁ : Type.{u2}} {α₂ : Sort.{u3}} {β₂ : Sort.{u4}}, (Equiv.{succ u1, u3} α₁ α₂) -> (Equiv.{succ u2, u4} β₁ β₂) -> (Equiv.{max (succ u1) (succ u2), max 1 u3 u4} (Sum.{u1, u2} α₁ β₁) (PSum.{u3, u4} α₂ β₂)) but is expected to have type forall {α₁ : Type.{u1}} {β₁ : Sort.{u2}} {α₂ : Type.{u3}} {β₂ : Sort.{u4}}, (Equiv.{succ u1, u2} α₁ β₁) -> (Equiv.{succ u3, u4} α₂ β₂) -> (Equiv.{max (succ u3) (succ u1), max (max 1 u4) u2} (Sum.{u1, u3} α₁ α₂) (PSum.{u2, u4} β₁ β₂)) Case conversion may be inaccurate. Consider using '#align equiv.sum_psum Equiv.sumPSumₓ'. -/ /-- Combine two `equiv`s using `sum` in the domain and `psum` in the codomain. -/ def sumPSum {α₁ β₁ : Type _} {α₂ β₂ : Sort _} (ea : α₁ ≃ α₂) (eb : β₁ ≃ β₂) : Sum α₁ β₁ ≃ PSum α₂ β₂ := (ea.symm.psumSum eb.symm).symm #align equiv.sum_psum Equiv.sumPSum /- warning: equiv.sum_congr_trans -> Equiv.sumCongr_trans is a dubious translation: lean 3 declaration is forall {α₁ : Type.{u1}} {α₂ : Type.{u2}} {β₁ : Type.{u3}} {β₂ : Type.{u4}} {γ₁ : Type.{u5}} {γ₂ : Type.{u6}} (e : Equiv.{succ u1, succ u3} α₁ β₁) (f : Equiv.{succ u2, succ u4} α₂ β₂) (g : Equiv.{succ u3, succ u5} β₁ γ₁) (h : Equiv.{succ u4, succ u6} β₂ γ₂), Eq.{max 1 (max (max (succ u1) (succ u2)) (succ u5) (succ u6)) (max (succ u5) (succ u6)) (succ u1) (succ u2)} (Equiv.{max (succ u1) (succ u2), max (succ u5) (succ u6)} (Sum.{u1, u2} α₁ α₂) (Sum.{u5, u6} γ₁ γ₂)) (Equiv.trans.{max (succ u1) (succ u2), max (succ u3) (succ u4), max (succ u5) (succ u6)} (Sum.{u1, u2} α₁ α₂) (Sum.{u3, u4} β₁ β₂) (Sum.{u5, u6} γ₁ γ₂) (Equiv.sumCongr.{u1, u2, u3, u4} α₁ α₂ β₁ β₂ e f) (Equiv.sumCongr.{u3, u4, u5, u6} β₁ β₂ γ₁ γ₂ g h)) (Equiv.sumCongr.{u1, u2, u5, u6} α₁ α₂ γ₁ γ₂ (Equiv.trans.{succ u1, succ u3, succ u5} α₁ β₁ γ₁ e g) (Equiv.trans.{succ u2, succ u4, succ u6} α₂ β₂ γ₂ f h)) but is expected to have type forall {α₁ : Type.{u6}} {α₂ : Type.{u5}} {β₁ : Type.{u4}} {β₂ : Type.{u3}} {γ₁ : Type.{u2}} {γ₂ : Type.{u1}} (e : Equiv.{succ u6, succ u5} α₁ α₂) (f : Equiv.{succ u4, succ u3} β₁ β₂) (g : Equiv.{succ u5, succ u2} α₂ γ₁) (h : Equiv.{succ u3, succ u1} β₂ γ₂), Eq.{max (max (max (succ u4) (succ u6)) (succ u1)) (succ u2)} (Equiv.{max (succ u4) (succ u6), max (succ u1) (succ u2)} (Sum.{u6, u4} α₁ β₁) (Sum.{u2, u1} γ₁ γ₂)) (Equiv.trans.{max (succ u4) (succ u6), max (succ u3) (succ u5), max (succ u1) (succ u2)} (Sum.{u6, u4} α₁ β₁) (Sum.{u5, u3} α₂ β₂) (Sum.{u2, u1} γ₁ γ₂) (Equiv.sumCongr.{u6, u5, u4, u3} α₁ α₂ β₁ β₂ e f) (Equiv.sumCongr.{u5, u2, u3, u1} α₂ γ₁ β₂ γ₂ g h)) (Equiv.sumCongr.{u6, u2, u4, u1} α₁ γ₁ β₁ γ₂ (Equiv.trans.{succ u6, succ u5, succ u2} α₁ α₂ γ₁ e g) (Equiv.trans.{succ u4, succ u3, succ u1} β₁ β₂ γ₂ f h)) Case conversion may be inaccurate. Consider using '#align equiv.sum_congr_trans Equiv.sumCongr_transₓ'. -/ @[simp] theorem sumCongr_trans {α₁ α₂ β₁ β₂ γ₁ γ₂ : Sort _} (e : α₁ ≃ β₁) (f : α₂ ≃ β₂) (g : β₁ ≃ γ₁) (h : β₂ ≃ γ₂) : (Equiv.sumCongr e f).trans (Equiv.sumCongr g h) = Equiv.sumCongr (e.trans g) (f.trans h) := by ext i cases i <;> rfl #align equiv.sum_congr_trans Equiv.sumCongr_trans /- warning: equiv.sum_congr_symm -> Equiv.sumCongr_symm is a dubious translation: lean 3 declaration is forall {α : Type.{u1}} {β : Type.{u2}} {γ : Type.{u3}} {δ : Type.{u4}} (e : Equiv.{succ u1, succ u2} α β) (f : Equiv.{succ u3, succ u4} γ δ), Eq.{max 1 (max (max (succ u2) (succ u4)) (succ u1) (succ u3)) (max (succ u1) (succ u3)) (succ u2) (succ u4)} (Equiv.{max (succ u2) (succ u4), max (succ u1) (succ u3)} (Sum.{u2, u4} β δ) (Sum.{u1, u3} α γ)) (Equiv.symm.{max (succ u1) (succ u3), max (succ u2) (succ u4)} (Sum.{u1, u3} α γ) (Sum.{u2, u4} β δ) (Equiv.sumCongr.{u1, u3, u2, u4} α γ β δ e f)) (Equiv.sumCongr.{u2, u4, u1, u3} β δ α γ (Equiv.symm.{succ u1, succ u2} α β e) (Equiv.symm.{succ u3, succ u4} γ δ f)) but is expected to have type forall {α : Type.{u4}} {β : Type.{u3}} {γ : Type.{u2}} {δ : Type.{u1}} (e : Equiv.{succ u4, succ u3} α β) (f : Equiv.{succ u2, succ u1} γ δ), Eq.{max (max (max (succ u1) (succ u2)) (succ u3)) (succ u4)} (Equiv.{max (succ u1) (succ u3), max (succ u2) (succ u4)} (Sum.{u3, u1} β δ) (Sum.{u4, u2} α γ)) (Equiv.symm.{max (succ u2) (succ u4), max (succ u1) (succ u3)} (Sum.{u4, u2} α γ) (Sum.{u3, u1} β δ) (Equiv.sumCongr.{u4, u3, u2, u1} α β γ δ e f)) (Equiv.sumCongr.{u3, u4, u1, u2} β α δ γ (Equiv.symm.{succ u4, succ u3} α β e) (Equiv.symm.{succ u2, succ u1} γ δ f)) Case conversion may be inaccurate. Consider using '#align equiv.sum_congr_symm Equiv.sumCongr_symmₓ'. -/ @[simp] theorem sumCongr_symm {α β γ δ : Sort _} (e : α ≃ β) (f : γ ≃ δ) : (Equiv.sumCongr e f).symm = Equiv.sumCongr e.symm f.symm := rfl #align equiv.sum_congr_symm Equiv.sumCongr_symm /- warning: equiv.sum_congr_refl -> Equiv.sumCongr_refl is a dubious translation: lean 3 declaration is forall {α : Type.{u1}} {β : Type.{u2}}, Eq.{max 1 (succ u1) (succ u2)} (Equiv.{max (succ u1) (succ u2), max (succ u1) (succ u2)} (Sum.{u1, u2} α β) (Sum.{u1, u2} α β)) (Equiv.sumCongr.{u1, u2, u1, u2} α β α β (Equiv.refl.{succ u1} α) (Equiv.refl.{succ u2} β)) (Equiv.refl.{max (succ u1) (succ u2)} (Sum.{u1, u2} α β)) but is expected to have type forall {α : Type.{u2}} {β : Type.{u1}}, Eq.{max (succ u1) (succ u2)} (Equiv.{max (succ u1) (succ u2), max (succ u1) (succ u2)} (Sum.{u2, u1} α β) (Sum.{u2, u1} α β)) (Equiv.sumCongr.{u2, u2, u1, u1} α α β β (Equiv.refl.{succ u2} α) (Equiv.refl.{succ u1} β)) (Equiv.refl.{max (succ u1) (succ u2)} (Sum.{u2, u1} α β)) Case conversion may be inaccurate. Consider using '#align equiv.sum_congr_refl Equiv.sumCongr_reflₓ'. -/ @[simp] theorem sumCongr_refl {α β : Sort _} : Equiv.sumCongr (Equiv.refl α) (Equiv.refl β) = Equiv.refl (Sum α β) := by ext i cases i <;> rfl #align equiv.sum_congr_refl Equiv.sumCongr_refl namespace Perm #print Equiv.Perm.sumCongr /- /-- Combine a permutation of `α` and of `β` into a permutation of `α ⊕ β`. -/ @[reducible] def sumCongr {α β : Type _} (ea : Equiv.Perm α) (eb : Equiv.Perm β) : Equiv.Perm (Sum α β) := Equiv.sumCongr ea eb #align equiv.perm.sum_congr Equiv.Perm.sumCongr -/ /- warning: equiv.perm.sum_congr_apply -> Equiv.Perm.sumCongr_apply is a dubious translation: lean 3 declaration is forall {α : Type.{u1}} {β : Type.{u2}} (ea : Equiv.Perm.{succ u1} α) (eb : Equiv.Perm.{succ u2} β) (x : Sum.{u1, u2} α β), Eq.{max (succ u1) (succ u2)} (Sum.{u1, u2} α β) (coeFn.{max 1 (succ u1) (succ u2), max (succ u1) (succ u2)} (Equiv.Perm.{max (succ u1) (succ u2)} (Sum.{u1, u2} α β)) (fun (_x : Equiv.{max (succ u1) (succ u2), max (succ u1) (succ u2)} (Sum.{u1, u2} α β) (Sum.{u1, u2} α β)) => (Sum.{u1, u2} α β) -> (Sum.{u1, u2} α β)) (Equiv.hasCoeToFun.{max (succ u1) (succ u2), max (succ u1) (succ u2)} (Sum.{u1, u2} α β) (Sum.{u1, u2} α β)) (Equiv.Perm.sumCongr.{u1, u2} α β ea eb) x) (Sum.map.{u1, u2, u1, u2} α α β β (coeFn.{succ u1, succ u1} (Equiv.Perm.{succ u1} α) (fun (_x : Equiv.{succ u1, succ u1} α α) => α -> α) (Equiv.hasCoeToFun.{succ u1, succ u1} α α) ea) (coeFn.{succ u2, succ u2} (Equiv.Perm.{succ u2} β) (fun (_x : Equiv.{succ u2, succ u2} β β) => β -> β) (Equiv.hasCoeToFun.{succ u2, succ u2} β β) eb) x) but is expected to have type forall {α : Type.{u2}} {β : Type.{u1}} (ea : Equiv.Perm.{succ u2} α) (eb : Equiv.Perm.{succ u1} β) (x : Sum.{u2, u1} α β), Eq.{max (succ u1) (succ u2)} ((fun ([email protected]._hyg.808 : Sum.{u2, u1} α β) => Sum.{u2, u1} α β) x) (FunLike.coe.{max (succ u1) (succ u2), max (succ u1) (succ u2), max (succ u1) (succ u2)} (Equiv.Perm.{max (succ u1) (succ u2)} (Sum.{u2, u1} α β)) (Sum.{u2, u1} α β) (fun (_x : Sum.{u2, u1} α β) => (fun ([email protected]._hyg.808 : Sum.{u2, u1} α β) => Sum.{u2, u1} α β) _x) (Equiv.instFunLikeEquiv.{max (succ u1) (succ u2), max (succ u1) (succ u2)} (Sum.{u2, u1} α β) (Sum.{u2, u1} α β)) (Equiv.Perm.sumCongr.{u2, u1} α β ea eb) x) (Sum.map.{u2, u1, u2, u1} α α β β (FunLike.coe.{succ u2, succ u2, succ u2} (Equiv.Perm.{succ u2} α) α (fun (_x : α) => (fun ([email protected]._hyg.808 : α) => α) _x) (Equiv.instFunLikeEquiv.{succ u2, succ u2} α α) ea) (FunLike.coe.{succ u1, succ u1, succ u1} (Equiv.Perm.{succ u1} β) β (fun (_x : β) => (fun ([email protected]._hyg.808 : β) => β) _x) (Equiv.instFunLikeEquiv.{succ u1, succ u1} β β) eb) x) Case conversion may be inaccurate. Consider using '#align equiv.perm.sum_congr_apply Equiv.Perm.sumCongr_applyₓ'. -/ @[simp] theorem sumCongr_apply {α β : Type _} (ea : Equiv.Perm α) (eb : Equiv.Perm β) (x : Sum α β) : sumCongr ea eb x = Sum.map (⇑ea) (⇑eb) x := Equiv.sumCongr_apply ea eb x #align equiv.perm.sum_congr_apply Equiv.Perm.sumCongr_apply /- warning: equiv.perm.sum_congr_trans -> Equiv.Perm.sumCongr_trans is a dubious translation: lean 3 declaration is forall {α : Type.{u1}} {β : Type.{u2}} (e : Equiv.Perm.{succ u1} α) (f : Equiv.Perm.{succ u2} β) (g : Equiv.Perm.{succ u1} α) (h : Equiv.Perm.{succ u2} β), Eq.{max 1 (succ u1) (succ u2)} (Equiv.{max (succ u1) (succ u2), max (succ u1) (succ u2)} (Sum.{u1, u2} α β) (Sum.{u1, u2} α β)) (Equiv.trans.{max (succ u1) (succ u2), max (succ u1) (succ u2), max (succ u1) (succ u2)} (Sum.{u1, u2} α β) (Sum.{u1, u2} α β) (Sum.{u1, u2} α β) (Equiv.Perm.sumCongr.{u1, u2} α β e f) (Equiv.Perm.sumCongr.{u1, u2} α β g h)) (Equiv.Perm.sumCongr.{u1, u2} α β (Equiv.trans.{succ u1, succ u1, succ u1} α α α e g) (Equiv.trans.{succ u2, succ u2, succ u2} β β β f h)) but is expected to have type forall {α : Type.{u2}} {β : Type.{u1}} (e : Equiv.Perm.{succ u2} α) (f : Equiv.Perm.{succ u1} β) (g : Equiv.Perm.{succ u2} α) (h : Equiv.Perm.{succ u1} β), Eq.{max (succ u1) (succ u2)} (Equiv.{max (succ u1) (succ u2), max (succ u1) (succ u2)} (Sum.{u2, u1} α β) (Sum.{u2, u1} α β)) (Equiv.trans.{max (succ u1) (succ u2), max (succ u1) (succ u2), max (succ u1) (succ u2)} (Sum.{u2, u1} α β) (Sum.{u2, u1} α β) (Sum.{u2, u1} α β) (Equiv.Perm.sumCongr.{u2, u1} α β e f) (Equiv.Perm.sumCongr.{u2, u1} α β g h)) (Equiv.Perm.sumCongr.{u2, u1} α β (Equiv.trans.{succ u2, succ u2, succ u2} α α α e g) (Equiv.trans.{succ u1, succ u1, succ u1} β β β f h)) Case conversion may be inaccurate. Consider using '#align equiv.perm.sum_congr_trans Equiv.Perm.sumCongr_transₓ'. -/ @[simp] theorem sumCongr_trans {α β : Sort _} (e : Equiv.Perm α) (f : Equiv.Perm β) (g : Equiv.Perm α) (h : Equiv.Perm β) : (sumCongr e f).trans (sumCongr g h) = sumCongr (e.trans g) (f.trans h) := Equiv.sumCongr_trans e f g h #align equiv.perm.sum_congr_trans Equiv.Perm.sumCongr_trans /- warning: equiv.perm.sum_congr_symm -> Equiv.Perm.sumCongr_symm is a dubious translation: lean 3 declaration is forall {α : Type.{u1}} {β : Type.{u2}} (e : Equiv.Perm.{succ u1} α) (f : Equiv.Perm.{succ u2} β), Eq.{max 1 (succ u1) (succ u2)} (Equiv.{max (succ u1) (succ u2), max (succ u1) (succ u2)} (Sum.{u1, u2} α β) (Sum.{u1, u2} α β)) (Equiv.symm.{max (succ u1) (succ u2), max (succ u1) (succ u2)} (Sum.{u1, u2} α β) (Sum.{u1, u2} α β) (Equiv.Perm.sumCongr.{u1, u2} α β e f)) (Equiv.Perm.sumCongr.{u1, u2} α β (Equiv.symm.{succ u1, succ u1} α α e) (Equiv.symm.{succ u2, succ u2} β β f)) but is expected to have type forall {α : Type.{u2}} {β : Type.{u1}} (e : Equiv.Perm.{succ u2} α) (f : Equiv.Perm.{succ u1} β), Eq.{max (succ u1) (succ u2)} (Equiv.{max (succ u1) (succ u2), max (succ u1) (succ u2)} (Sum.{u2, u1} α β) (Sum.{u2, u1} α β)) (Equiv.symm.{max (succ u1) (succ u2), max (succ u1) (succ u2)} (Sum.{u2, u1} α β) (Sum.{u2, u1} α β) (Equiv.Perm.sumCongr.{u2, u1} α β e f)) (Equiv.Perm.sumCongr.{u2, u1} α β (Equiv.symm.{succ u2, succ u2} α α e) (Equiv.symm.{succ u1, succ u1} β β f)) Case conversion may be inaccurate. Consider using '#align equiv.perm.sum_congr_symm Equiv.Perm.sumCongr_symmₓ'. -/ @[simp] theorem sumCongr_symm {α β : Sort _} (e : Equiv.Perm α) (f : Equiv.Perm β) : (sumCongr e f).symm = sumCongr e.symm f.symm := Equiv.sumCongr_symm e f #align equiv.perm.sum_congr_symm Equiv.Perm.sumCongr_symm /- warning: equiv.perm.sum_congr_refl -> Equiv.Perm.sumCongr_refl is a dubious translation: lean 3 declaration is forall {α : Type.{u1}} {β : Type.{u2}}, Eq.{max 1 (succ u1) (succ u2)} (Equiv.Perm.{max (succ u1) (succ u2)} (Sum.{u1, u2} α β)) (Equiv.Perm.sumCongr.{u1, u2} α β (Equiv.refl.{succ u1} α) (Equiv.refl.{succ u2} β)) (Equiv.refl.{max (succ u1) (succ u2)} (Sum.{u1, u2} α β)) but is expected to have type forall {α : Type.{u2}} {β : Type.{u1}}, Eq.{max (succ u1) (succ u2)} (Equiv.Perm.{max (succ u1) (succ u2)} (Sum.{u2, u1} α β)) (Equiv.Perm.sumCongr.{u2, u1} α β (Equiv.refl.{succ u2} α) (Equiv.refl.{succ u1} β)) (Equiv.refl.{max (succ u1) (succ u2)} (Sum.{u2, u1} α β)) Case conversion may be inaccurate. Consider using '#align equiv.perm.sum_congr_refl Equiv.Perm.sumCongr_reflₓ'. -/ @[simp] theorem sumCongr_refl {α β : Sort _} : sumCongr (Equiv.refl α) (Equiv.refl β) = Equiv.refl (Sum α β) := Equiv.sumCongr_refl #align equiv.perm.sum_congr_refl Equiv.Perm.sumCongr_refl end Perm #print Equiv.boolEquivPUnitSumPUnit /- /-- `bool` is equivalent the sum of two `punit`s. -/ def boolEquivPUnitSumPUnit : Bool ≃ Sum PUnit.{u + 1} PUnit.{v + 1} := ⟨fun b => cond b (inr PUnit.unit) (inl PUnit.unit), Sum.elim (fun _ => false) fun _ => true, fun b => by cases b <;> rfl, fun s => by rcases s with (⟨⟨⟩⟩ | ⟨⟨⟩⟩) <;> rfl⟩ #align equiv.bool_equiv_punit_sum_punit Equiv.boolEquivPUnitSumPUnit -/ #print Equiv.sumComm /- /-- Sum of types is commutative up to an equivalence. This is `sum.swap` as an equivalence. -/ @[simps (config := { fullyApplied := false }) apply] def sumComm (α β : Type _) : Sum α β ≃ Sum β α := ⟨Sum.swap, Sum.swap, Sum.swap_swap, Sum.swap_swap⟩ #align equiv.sum_comm Equiv.sumComm -/ /- warning: equiv.sum_comm_symm -> Equiv.sumComm_symm is a dubious translation: lean 3 declaration is forall (α : Type.{u1}) (β : Type.{u2}), Eq.{max 1 (max (max (succ u2) (succ u1)) (succ u1) (succ u2)) (max (succ u1) (succ u2)) (succ u2) (succ u1)} (Equiv.{max (succ u2) (succ u1), max (succ u1) (succ u2)} (Sum.{u2, u1} β α) (Sum.{u1, u2} α β)) (Equiv.symm.{max (succ u1) (succ u2), max (succ u2) (succ u1)} (Sum.{u1, u2} α β) (Sum.{u2, u1} β α) (Equiv.sumComm.{u1, u2} α β)) (Equiv.sumComm.{u2, u1} β α) but is expected to have type forall (α : Type.{u2}) (β : Type.{u1}), Eq.{max (succ u1) (succ u2)} (Equiv.{max (succ u1) (succ u2), max (succ u1) (succ u2)} (Sum.{u1, u2} β α) (Sum.{u2, u1} α β)) (Equiv.symm.{max (succ u1) (succ u2), max (succ u1) (succ u2)} (Sum.{u2, u1} α β) (Sum.{u1, u2} β α) (Equiv.sumComm.{u2, u1} α β)) (Equiv.sumComm.{u1, u2} β α) Case conversion may be inaccurate. Consider using '#align equiv.sum_comm_symm Equiv.sumComm_symmₓ'. -/ @[simp] theorem sumComm_symm (α β) : (sumComm α β).symm = sumComm β α := rfl #align equiv.sum_comm_symm Equiv.sumComm_symm #print Equiv.sumAssoc /- /-- Sum of types is associative up to an equivalence. -/ def sumAssoc (α β γ : Type _) : Sum (Sum α β) γ ≃ Sum α (Sum β γ) := ⟨Sum.elim (Sum.elim Sum.inl (Sum.inr ∘ Sum.inl)) (Sum.inr ∘ Sum.inr), Sum.elim (Sum.inl ∘ Sum.inl) <| Sum.elim (Sum.inl ∘ Sum.inr) Sum.inr, by rintro (⟨_ | _⟩ | _) <;> rfl, by rintro (_ | ⟨_ | _⟩) <;> rfl⟩ #align equiv.sum_assoc Equiv.sumAssoc -/ /- warning: equiv.sum_assoc_apply_inl_inl -> Equiv.sumAssoc_apply_inl_inl is a dubious translation: lean 3 declaration is forall {α : Type.{u1}} {β : Type.{u2}} {γ : Type.{u3}} (a : α), Eq.{max (succ u1) (succ (max u2 u3))} (Sum.{u1, max u2 u3} α (Sum.{u2, u3} β γ)) (coeFn.{max 1 (max (max (succ (max u1 u2)) (succ u3)) (succ u1) (succ (max u2 u3))) (max (succ u1) (succ (max u2 u3))) (succ (max u1 u2)) (succ u3), max (max (succ (max u1 u2)) (succ u3)) (succ u1) (succ (max u2 u3))} (Equiv.{max (succ (max u1 u2)) (succ u3), max (succ u1) (succ (max u2 u3))} (Sum.{max u1 u2, u3} (Sum.{u1, u2} α β) γ) (Sum.{u1, max u2 u3} α (Sum.{u2, u3} β γ))) (fun (_x : Equiv.{max (succ (max u1 u2)) (succ u3), max (succ u1) (succ (max u2 u3))} (Sum.{max u1 u2, u3} (Sum.{u1, u2} α β) γ) (Sum.{u1, max u2 u3} α (Sum.{u2, u3} β γ))) => (Sum.{max u1 u2, u3} (Sum.{u1, u2} α β) γ) -> (Sum.{u1, max u2 u3} α (Sum.{u2, u3} β γ))) (Equiv.hasCoeToFun.{max (succ (max u1 u2)) (succ u3), max (succ u1) (succ (max u2 u3))} (Sum.{max u1 u2, u3} (Sum.{u1, u2} α β) γ) (Sum.{u1, max u2 u3} α (Sum.{u2, u3} β γ))) (Equiv.sumAssoc.{u1, u2, u3} α β γ) (Sum.inl.{max u1 u2, u3} (Sum.{u1, u2} α β) γ (Sum.inl.{u1, u2} α β a))) (Sum.inl.{u1, max u2 u3} α (Sum.{u2, u3} β γ) a) but is expected to have type forall {α : Type.{u3}} {β : Type.{u2}} {γ : Type.{u1}} (a : α), Eq.{max (max (succ u1) (succ u2)) (succ u3)} ((fun ([email protected]._hyg.808 : Sum.{max u2 u3, u1} (Sum.{u3, u2} α β) γ) => Sum.{u3, max u1 u2} α (Sum.{u2, u1} β γ)) (Sum.inl.{max u2 u3, u1} (Sum.{u3, u2} α β) γ (Sum.inl.{u3, u2} α β a))) (FunLike.coe.{max (max (succ u1) (succ u2)) (succ u3), max (max (succ u1) (succ u2)) (succ u3), max (max (succ u1) (succ u2)) (succ u3)} (Equiv.{max (succ u1) (succ (max u2 u3)), max (succ (max u1 u2)) (succ u3)} (Sum.{max u2 u3, u1} (Sum.{u3, u2} α β) γ) (Sum.{u3, max u1 u2} α (Sum.{u2, u1} β γ))) (Sum.{max u2 u3, u1} (Sum.{u3, u2} α β) γ) (fun (_x : Sum.{max u2 u3, u1} (Sum.{u3, u2} α β) γ) => (fun ([email protected]._hyg.808 : Sum.{max u2 u3, u1} (Sum.{u3, u2} α β) γ) => Sum.{u3, max u1 u2} α (Sum.{u2, u1} β γ)) _x) (Equiv.instFunLikeEquiv.{max (max (succ u1) (succ u2)) (succ u3), max (max (succ u1) (succ u2)) (succ u3)} (Sum.{max u2 u3, u1} (Sum.{u3, u2} α β) γ) (Sum.{u3, max u1 u2} α (Sum.{u2, u1} β γ))) (Equiv.sumAssoc.{u3, u2, u1} α β γ) (Sum.inl.{max u2 u3, u1} (Sum.{u3, u2} α β) γ (Sum.inl.{u3, u2} α β a))) (Sum.inl.{u3, max u1 u2} α (Sum.{u2, u1} β γ) a) Case conversion may be inaccurate. Consider using '#align equiv.sum_assoc_apply_inl_inl Equiv.sumAssoc_apply_inl_inlₓ'. -/ @[simp] theorem sumAssoc_apply_inl_inl {α β γ} (a) : sumAssoc α β γ (inl (inl a)) = inl a := rfl #align equiv.sum_assoc_apply_inl_inl Equiv.sumAssoc_apply_inl_inl /- warning: equiv.sum_assoc_apply_inl_inr -> Equiv.sumAssoc_apply_inl_inr is a dubious translation: lean 3 declaration is forall {α : Type.{u1}} {β : Type.{u2}} {γ : Type.{u3}} (b : β), Eq.{max (succ u1) (succ (max u2 u3))} (Sum.{u1, max u2 u3} α (Sum.{u2, u3} β γ)) (coeFn.{max 1 (max (max (succ (max u1 u2)) (succ u3)) (succ u1) (succ (max u2 u3))) (max (succ u1) (succ (max u2 u3))) (succ (max u1 u2)) (succ u3), max (max (succ (max u1 u2)) (succ u3)) (succ u1) (succ (max u2 u3))} (Equiv.{max (succ (max u1 u2)) (succ u3), max (succ u1) (succ (max u2 u3))} (Sum.{max u1 u2, u3} (Sum.{u1, u2} α β) γ) (Sum.{u1, max u2 u3} α (Sum.{u2, u3} β γ))) (fun (_x : Equiv.{max (succ (max u1 u2)) (succ u3), max (succ u1) (succ (max u2 u3))} (Sum.{max u1 u2, u3} (Sum.{u1, u2} α β) γ) (Sum.{u1, max u2 u3} α (Sum.{u2, u3} β γ))) => (Sum.{max u1 u2, u3} (Sum.{u1, u2} α β) γ) -> (Sum.{u1, max u2 u3} α (Sum.{u2, u3} β γ))) (Equiv.hasCoeToFun.{max (succ (max u1 u2)) (succ u3), max (succ u1) (succ (max u2 u3))} (Sum.{max u1 u2, u3} (Sum.{u1, u2} α β) γ) (Sum.{u1, max u2 u3} α (Sum.{u2, u3} β γ))) (Equiv.sumAssoc.{u1, u2, u3} α β γ) (Sum.inl.{max u1 u2, u3} (Sum.{u1, u2} α β) γ (Sum.inr.{u1, u2} α β b))) (Sum.inr.{u1, max u2 u3} α (Sum.{u2, u3} β γ) (Sum.inl.{u2, u3} β γ b)) but is expected to have type forall {α : Type.{u3}} {β : Type.{u2}} {γ : Type.{u1}} (b : β), Eq.{max (max (succ u1) (succ u2)) (succ u3)} ((fun ([email protected]._hyg.808 : Sum.{max u2 u3, u1} (Sum.{u3, u2} α β) γ) => Sum.{u3, max u1 u2} α (Sum.{u2, u1} β γ)) (Sum.inl.{max u2 u3, u1} (Sum.{u3, u2} α β) γ (Sum.inr.{u3, u2} α β b))) (FunLike.coe.{max (max (succ u1) (succ u2)) (succ u3), max (max (succ u1) (succ u2)) (succ u3), max (max (succ u1) (succ u2)) (succ u3)} (Equiv.{max (succ u1) (succ (max u2 u3)), max (succ (max u1 u2)) (succ u3)} (Sum.{max u2 u3, u1} (Sum.{u3, u2} α β) γ) (Sum.{u3, max u1 u2} α (Sum.{u2, u1} β γ))) (Sum.{max u2 u3, u1} (Sum.{u3, u2} α β) γ) (fun (_x : Sum.{max u2 u3, u1} (Sum.{u3, u2} α β) γ) => (fun ([email protected]._hyg.808 : Sum.{max u2 u3, u1} (Sum.{u3, u2} α β) γ) => Sum.{u3, max u1 u2} α (Sum.{u2, u1} β γ)) _x) (Equiv.instFunLikeEquiv.{max (max (succ u1) (succ u2)) (succ u3), max (max (succ u1) (succ u2)) (succ u3)} (Sum.{max u2 u3, u1} (Sum.{u3, u2} α β) γ) (Sum.{u3, max u1 u2} α (Sum.{u2, u1} β γ))) (Equiv.sumAssoc.{u3, u2, u1} α β γ) (Sum.inl.{max u2 u3, u1} (Sum.{u3, u2} α β) γ (Sum.inr.{u3, u2} α β b))) (Sum.inr.{u3, max u1 u2} α (Sum.{u2, u1} β γ) (Sum.inl.{u2, u1} β γ b)) Case conversion may be inaccurate. Consider using '#align equiv.sum_assoc_apply_inl_inr Equiv.sumAssoc_apply_inl_inrₓ'. -/ @[simp] theorem sumAssoc_apply_inl_inr {α β γ} (b) : sumAssoc α β γ (inl (inr b)) = inr (inl b) := rfl #align equiv.sum_assoc_apply_inl_inr Equiv.sumAssoc_apply_inl_inr /- warning: equiv.sum_assoc_apply_inr -> Equiv.sumAssoc_apply_inr is a dubious translation: lean 3 declaration is forall {α : Type.{u1}} {β : Type.{u2}} {γ : Type.{u3}} (c : γ), Eq.{max (succ u1) (succ (max u2 u3))} (Sum.{u1, max u2 u3} α (Sum.{u2, u3} β γ)) (coeFn.{max 1 (max (max (succ (max u1 u2)) (succ u3)) (succ u1) (succ (max u2 u3))) (max (succ u1) (succ (max u2 u3))) (succ (max u1 u2)) (succ u3), max (max (succ (max u1 u2)) (succ u3)) (succ u1) (succ (max u2 u3))} (Equiv.{max (succ (max u1 u2)) (succ u3), max (succ u1) (succ (max u2 u3))} (Sum.{max u1 u2, u3} (Sum.{u1, u2} α β) γ) (Sum.{u1, max u2 u3} α (Sum.{u2, u3} β γ))) (fun (_x : Equiv.{max (succ (max u1 u2)) (succ u3), max (succ u1) (succ (max u2 u3))} (Sum.{max u1 u2, u3} (Sum.{u1, u2} α β) γ) (Sum.{u1, max u2 u3} α (Sum.{u2, u3} β γ))) => (Sum.{max u1 u2, u3} (Sum.{u1, u2} α β) γ) -> (Sum.{u1, max u2 u3} α (Sum.{u2, u3} β γ))) (Equiv.hasCoeToFun.{max (succ (max u1 u2)) (succ u3), max (succ u1) (succ (max u2 u3))} (Sum.{max u1 u2, u3} (Sum.{u1, u2} α β) γ) (Sum.{u1, max u2 u3} α (Sum.{u2, u3} β γ))) (Equiv.sumAssoc.{u1, u2, u3} α β γ) (Sum.inr.{max u1 u2, u3} (Sum.{u1, u2} α β) γ c)) (Sum.inr.{u1, max u2 u3} α (Sum.{u2, u3} β γ) (Sum.inr.{u2, u3} β γ c)) but is expected to have type forall {α : Type.{u3}} {β : Type.{u2}} {γ : Type.{u1}} (c : γ), Eq.{max (max (succ u1) (succ u2)) (succ u3)} ((fun ([email protected]._hyg.808 : Sum.{max u2 u3, u1} (Sum.{u3, u2} α β) γ) => Sum.{u3, max u1 u2} α (Sum.{u2, u1} β γ)) (Sum.inr.{max u2 u3, u1} (Sum.{u3, u2} α β) γ c)) (FunLike.coe.{max (max (succ u1) (succ u2)) (succ u3), max (max (succ u1) (succ u2)) (succ u3), max (max (succ u1) (succ u2)) (succ u3)} (Equiv.{max (succ u1) (succ (max u2 u3)), max (succ (max u1 u2)) (succ u3)} (Sum.{max u2 u3, u1} (Sum.{u3, u2} α β) γ) (Sum.{u3, max u1 u2} α (Sum.{u2, u1} β γ))) (Sum.{max u2 u3, u1} (Sum.{u3, u2} α β) γ) (fun (_x : Sum.{max u2 u3, u1} (Sum.{u3, u2} α β) γ) => (fun ([email protected]._hyg.808 : Sum.{max u2 u3, u1} (Sum.{u3, u2} α β) γ) => Sum.{u3, max u1 u2} α (Sum.{u2, u1} β γ)) _x) (Equiv.instFunLikeEquiv.{max (max (succ u1) (succ u2)) (succ u3), max (max (succ u1) (succ u2)) (succ u3)} (Sum.{max u2 u3, u1} (Sum.{u3, u2} α β) γ) (Sum.{u3, max u1 u2} α (Sum.{u2, u1} β γ))) (Equiv.sumAssoc.{u3, u2, u1} α β γ) (Sum.inr.{max u2 u3, u1} (Sum.{u3, u2} α β) γ c)) (Sum.inr.{u3, max u1 u2} α (Sum.{u2, u1} β γ) (Sum.inr.{u2, u1} β γ c)) Case conversion may be inaccurate. Consider using '#align equiv.sum_assoc_apply_inr Equiv.sumAssoc_apply_inrₓ'. -/ @[simp] theorem sumAssoc_apply_inr {α β γ} (c) : sumAssoc α β γ (inr c) = inr (inr c) := rfl #align equiv.sum_assoc_apply_inr Equiv.sumAssoc_apply_inr /- warning: equiv.sum_assoc_symm_apply_inl -> Equiv.sumAssoc_symm_apply_inl is a dubious translation: lean 3 declaration is forall {α : Type.{u1}} {β : Type.{u2}} {γ : Type.{u3}} (a : α), Eq.{max (succ (max u1 u2)) (succ u3)} (Sum.{max u1 u2, u3} (Sum.{u1, u2} α β) γ) (coeFn.{max 1 (max (max (succ u1) (succ (max u2 u3))) (succ (max u1 u2)) (succ u3)) (max (succ (max u1 u2)) (succ u3)) (succ u1) (succ (max u2 u3)), max (max (succ u1) (succ (max u2 u3))) (succ (max u1 u2)) (succ u3)} (Equiv.{max (succ u1) (succ (max u2 u3)), max (succ (max u1 u2)) (succ u3)} (Sum.{u1, max u2 u3} α (Sum.{u2, u3} β γ)) (Sum.{max u1 u2, u3} (Sum.{u1, u2} α β) γ)) (fun (_x : Equiv.{max (succ u1) (succ (max u2 u3)), max (succ (max u1 u2)) (succ u3)} (Sum.{u1, max u2 u3} α (Sum.{u2, u3} β γ)) (Sum.{max u1 u2, u3} (Sum.{u1, u2} α β) γ)) => (Sum.{u1, max u2 u3} α (Sum.{u2, u3} β γ)) -> (Sum.{max u1 u2, u3} (Sum.{u1, u2} α β) γ)) (Equiv.hasCoeToFun.{max (succ u1) (succ (max u2 u3)), max (succ (max u1 u2)) (succ u3)} (Sum.{u1, max u2 u3} α (Sum.{u2, u3} β γ)) (Sum.{max u1 u2, u3} (Sum.{u1, u2} α β) γ)) (Equiv.symm.{max (succ (max u1 u2)) (succ u3), max (succ u1) (succ (max u2 u3))} (Sum.{max u1 u2, u3} (Sum.{u1, u2} α β) γ) (Sum.{u1, max u2 u3} α (Sum.{u2, u3} β γ)) (Equiv.sumAssoc.{u1, u2, u3} α β γ)) (Sum.inl.{u1, max u2 u3} α (Sum.{u2, u3} β γ) a)) (Sum.inl.{max u1 u2, u3} (Sum.{u1, u2} α β) γ (Sum.inl.{u1, u2} α β a)) but is expected to have type forall {α : Type.{u3}} {β : Type.{u2}} {γ : Type.{u1}} (a : α), Eq.{max (max (succ u1) (succ u2)) (succ u3)} ((fun ([email protected]._hyg.808 : Sum.{u3, max u1 u2} α (Sum.{u2, u1} β γ)) => Sum.{max u2 u3, u1} (Sum.{u3, u2} α β) γ) (Sum.inl.{u3, max u1 u2} α (Sum.{u2, u1} β γ) a)) (FunLike.coe.{max (max (succ u1) (succ u2)) (succ u3), max (max (succ u1) (succ u2)) (succ u3), max (max (succ u1) (succ u2)) (succ u3)} (Equiv.{max (max (succ u1) (succ u2)) (succ u3), max (max (succ u1) (succ u2)) (succ u3)} (Sum.{u3, max u1 u2} α (Sum.{u2, u1} β γ)) (Sum.{max u2 u3, u1} (Sum.{u3, u2} α β) γ)) (Sum.{u3, max u1 u2} α (Sum.{u2, u1} β γ)) (fun (_x : Sum.{u3, max u1 u2} α (Sum.{u2, u1} β γ)) => (fun ([email protected]._hyg.808 : Sum.{u3, max u1 u2} α (Sum.{u2, u1} β γ)) => Sum.{max u2 u3, u1} (Sum.{u3, u2} α β) γ) _x) (Equiv.instFunLikeEquiv.{max (max (succ u1) (succ u2)) (succ u3), max (max (succ u1) (succ u2)) (succ u3)} (Sum.{u3, max u1 u2} α (Sum.{u2, u1} β γ)) (Sum.{max u2 u3, u1} (Sum.{u3, u2} α β) γ)) (Equiv.symm.{max (max (succ u1) (succ u2)) (succ u3), max (max (succ u1) (succ u2)) (succ u3)} (Sum.{max u2 u3, u1} (Sum.{u3, u2} α β) γ) (Sum.{u3, max u1 u2} α (Sum.{u2, u1} β γ)) (Equiv.sumAssoc.{u3, u2, u1} α β γ)) (Sum.inl.{u3, max u1 u2} α (Sum.{u2, u1} β γ) a)) (Sum.inl.{max u2 u3, u1} (Sum.{u3, u2} α β) γ (Sum.inl.{u3, u2} α β a)) Case conversion may be inaccurate. Consider using '#align equiv.sum_assoc_symm_apply_inl Equiv.sumAssoc_symm_apply_inlₓ'. -/ @[simp] theorem sumAssoc_symm_apply_inl {α β γ} (a) : (sumAssoc α β γ).symm (inl a) = inl (inl a) := rfl #align equiv.sum_assoc_symm_apply_inl Equiv.sumAssoc_symm_apply_inl /- warning: equiv.sum_assoc_symm_apply_inr_inl -> Equiv.sumAssoc_symm_apply_inr_inl is a dubious translation: lean 3 declaration is forall {α : Type.{u1}} {β : Type.{u2}} {γ : Type.{u3}} (b : β), Eq.{max (succ (max u1 u2)) (succ u3)} (Sum.{max u1 u2, u3} (Sum.{u1, u2} α β) γ) (coeFn.{max 1 (max (max (succ u1) (succ (max u2 u3))) (succ (max u1 u2)) (succ u3)) (max (succ (max u1 u2)) (succ u3)) (succ u1) (succ (max u2 u3)), max (max (succ u1) (succ (max u2 u3))) (succ (max u1 u2)) (succ u3)} (Equiv.{max (succ u1) (succ (max u2 u3)), max (succ (max u1 u2)) (succ u3)} (Sum.{u1, max u2 u3} α (Sum.{u2, u3} β γ)) (Sum.{max u1 u2, u3} (Sum.{u1, u2} α β) γ)) (fun (_x : Equiv.{max (succ u1) (succ (max u2 u3)), max (succ (max u1 u2)) (succ u3)} (Sum.{u1, max u2 u3} α (Sum.{u2, u3} β γ)) (Sum.{max u1 u2, u3} (Sum.{u1, u2} α β) γ)) => (Sum.{u1, max u2 u3} α (Sum.{u2, u3} β γ)) -> (Sum.{max u1 u2, u3} (Sum.{u1, u2} α β) γ)) (Equiv.hasCoeToFun.{max (succ u1) (succ (max u2 u3)), max (succ (max u1 u2)) (succ u3)} (Sum.{u1, max u2 u3} α (Sum.{u2, u3} β γ)) (Sum.{max u1 u2, u3} (Sum.{u1, u2} α β) γ)) (Equiv.symm.{max (succ (max u1 u2)) (succ u3), max (succ u1) (succ (max u2 u3))} (Sum.{max u1 u2, u3} (Sum.{u1, u2} α β) γ) (Sum.{u1, max u2 u3} α (Sum.{u2, u3} β γ)) (Equiv.sumAssoc.{u1, u2, u3} α β γ)) (Sum.inr.{u1, max u2 u3} α (Sum.{u2, u3} β γ) (Sum.inl.{u2, u3} β γ b))) (Sum.inl.{max u1 u2, u3} (Sum.{u1, u2} α β) γ (Sum.inr.{u1, u2} α β b)) but is expected to have type forall {α : Type.{u3}} {β : Type.{u2}} {γ : Type.{u1}} (b : β), Eq.{max (max (succ u1) (succ u2)) (succ u3)} ((fun ([email protected]._hyg.808 : Sum.{u3, max u1 u2} α (Sum.{u2, u1} β γ)) => Sum.{max u2 u3, u1} (Sum.{u3, u2} α β) γ) (Sum.inr.{u3, max u1 u2} α (Sum.{u2, u1} β γ) (Sum.inl.{u2, u1} β γ b))) (FunLike.coe.{max (max (succ u1) (succ u2)) (succ u3), max (max (succ u1) (succ u2)) (succ u3), max (max (succ u1) (succ u2)) (succ u3)} (Equiv.{max (max (succ u1) (succ u2)) (succ u3), max (max (succ u1) (succ u2)) (succ u3)} (Sum.{u3, max u1 u2} α (Sum.{u2, u1} β γ)) (Sum.{max u2 u3, u1} (Sum.{u3, u2} α β) γ)) (Sum.{u3, max u1 u2} α (Sum.{u2, u1} β γ)) (fun (_x : Sum.{u3, max u1 u2} α (Sum.{u2, u1} β γ)) => (fun ([email protected]._hyg.808 : Sum.{u3, max u1 u2} α (Sum.{u2, u1} β γ)) => Sum.{max u2 u3, u1} (Sum.{u3, u2} α β) γ) _x) (Equiv.instFunLikeEquiv.{max (max (succ u1) (succ u2)) (succ u3), max (max (succ u1) (succ u2)) (succ u3)} (Sum.{u3, max u1 u2} α (Sum.{u2, u1} β γ)) (Sum.{max u2 u3, u1} (Sum.{u3, u2} α β) γ)) (Equiv.symm.{max (max (succ u1) (succ u2)) (succ u3), max (max (succ u1) (succ u2)) (succ u3)} (Sum.{max u2 u3, u1} (Sum.{u3, u2} α β) γ) (Sum.{u3, max u1 u2} α (Sum.{u2, u1} β γ)) (Equiv.sumAssoc.{u3, u2, u1} α β γ)) (Sum.inr.{u3, max u1 u2} α (Sum.{u2, u1} β γ) (Sum.inl.{u2, u1} β γ b))) (Sum.inl.{max u2 u3, u1} (Sum.{u3, u2} α β) γ (Sum.inr.{u3, u2} α β b)) Case conversion may be inaccurate. Consider using '#align equiv.sum_assoc_symm_apply_inr_inl Equiv.sumAssoc_symm_apply_inr_inlₓ'. -/ @[simp] theorem sumAssoc_symm_apply_inr_inl {α β γ} (b) : (sumAssoc α β γ).symm (inr (inl b)) = inl (inr b) := rfl #align equiv.sum_assoc_symm_apply_inr_inl Equiv.sumAssoc_symm_apply_inr_inl /- warning: equiv.sum_assoc_symm_apply_inr_inr -> Equiv.sumAssoc_symm_apply_inr_inr is a dubious translation: lean 3 declaration is forall {α : Type.{u1}} {β : Type.{u2}} {γ : Type.{u3}} (c : γ), Eq.{max (succ (max u1 u2)) (succ u3)} (Sum.{max u1 u2, u3} (Sum.{u1, u2} α β) γ) (coeFn.{max 1 (max (max (succ u1) (succ (max u2 u3))) (succ (max u1 u2)) (succ u3)) (max (succ (max u1 u2)) (succ u3)) (succ u1) (succ (max u2 u3)), max (max (succ u1) (succ (max u2 u3))) (succ (max u1 u2)) (succ u3)} (Equiv.{max (succ u1) (succ (max u2 u3)), max (succ (max u1 u2)) (succ u3)} (Sum.{u1, max u2 u3} α (Sum.{u2, u3} β γ)) (Sum.{max u1 u2, u3} (Sum.{u1, u2} α β) γ)) (fun (_x : Equiv.{max (succ u1) (succ (max u2 u3)), max (succ (max u1 u2)) (succ u3)} (Sum.{u1, max u2 u3} α (Sum.{u2, u3} β γ)) (Sum.{max u1 u2, u3} (Sum.{u1, u2} α β) γ)) => (Sum.{u1, max u2 u3} α (Sum.{u2, u3} β γ)) -> (Sum.{max u1 u2, u3} (Sum.{u1, u2} α β) γ)) (Equiv.hasCoeToFun.{max (succ u1) (succ (max u2 u3)), max (succ (max u1 u2)) (succ u3)} (Sum.{u1, max u2 u3} α (Sum.{u2, u3} β γ)) (Sum.{max u1 u2, u3} (Sum.{u1, u2} α β) γ)) (Equiv.symm.{max (succ (max u1 u2)) (succ u3), max (succ u1) (succ (max u2 u3))} (Sum.{max u1 u2, u3} (Sum.{u1, u2} α β) γ) (Sum.{u1, max u2 u3} α (Sum.{u2, u3} β γ)) (Equiv.sumAssoc.{u1, u2, u3} α β γ)) (Sum.inr.{u1, max u2 u3} α (Sum.{u2, u3} β γ) (Sum.inr.{u2, u3} β γ c))) (Sum.inr.{max u1 u2, u3} (Sum.{u1, u2} α β) γ c) but is expected to have type forall {α : Type.{u3}} {β : Type.{u2}} {γ : Type.{u1}} (c : γ), Eq.{max (max (succ u1) (succ u2)) (succ u3)} ((fun ([email protected]._hyg.808 : Sum.{u3, max u1 u2} α (Sum.{u2, u1} β γ)) => Sum.{max u2 u3, u1} (Sum.{u3, u2} α β) γ) (Sum.inr.{u3, max u1 u2} α (Sum.{u2, u1} β γ) (Sum.inr.{u2, u1} β γ c))) (FunLike.coe.{max (max (succ u1) (succ u2)) (succ u3), max (max (succ u1) (succ u2)) (succ u3), max (max (succ u1) (succ u2)) (succ u3)} (Equiv.{max (max (succ u1) (succ u2)) (succ u3), max (max (succ u1) (succ u2)) (succ u3)} (Sum.{u3, max u1 u2} α (Sum.{u2, u1} β γ)) (Sum.{max u2 u3, u1} (Sum.{u3, u2} α β) γ)) (Sum.{u3, max u1 u2} α (Sum.{u2, u1} β γ)) (fun (_x : Sum.{u3, max u1 u2} α (Sum.{u2, u1} β γ)) => (fun ([email protected]._hyg.808 : Sum.{u3, max u1 u2} α (Sum.{u2, u1} β γ)) => Sum.{max u2 u3, u1} (Sum.{u3, u2} α β) γ) _x) (Equiv.instFunLikeEquiv.{max (max (succ u1) (succ u2)) (succ u3), max (max (succ u1) (succ u2)) (succ u3)} (Sum.{u3, max u1 u2} α (Sum.{u2, u1} β γ)) (Sum.{max u2 u3, u1} (Sum.{u3, u2} α β) γ)) (Equiv.symm.{max (max (succ u1) (succ u2)) (succ u3), max (max (succ u1) (succ u2)) (succ u3)} (Sum.{max u2 u3, u1} (Sum.{u3, u2} α β) γ) (Sum.{u3, max u1 u2} α (Sum.{u2, u1} β γ)) (Equiv.sumAssoc.{u3, u2, u1} α β γ)) (Sum.inr.{u3, max u1 u2} α (Sum.{u2, u1} β γ) (Sum.inr.{u2, u1} β γ c))) (Sum.inr.{max u2 u3, u1} (Sum.{u3, u2} α β) γ c) Case conversion may be inaccurate. Consider using '#align equiv.sum_assoc_symm_apply_inr_inr Equiv.sumAssoc_symm_apply_inr_inrₓ'. -/ @[simp] theorem sumAssoc_symm_apply_inr_inr {α β γ} (c) : (sumAssoc α β γ).symm (inr (inr c)) = inr c := rfl #align equiv.sum_assoc_symm_apply_inr_inr Equiv.sumAssoc_symm_apply_inr_inr #print Equiv.sumEmpty /- /-- Sum with `empty` is equivalent to the original type. -/ @[simps symm_apply] def sumEmpty (α β : Type _) [IsEmpty β] : Sum α β ≃ α := ⟨Sum.elim id isEmptyElim, inl, fun s => by rcases s with (_ | x) rfl exact isEmptyElim x, fun a => rfl⟩ #align equiv.sum_empty Equiv.sumEmpty -/ /- warning: equiv.sum_empty_apply_inl -> Equiv.sumEmpty_apply_inl is a dubious translation: lean 3 declaration is forall {α : Type.{u1}} {β : Type.{u2}} [_inst_1 : IsEmpty.{succ u2} β] (a : α), Eq.{succ u1} α (coeFn.{max 1 (succ u1) (succ u2), max (succ u1) (succ u2)} (Equiv.{max (succ u1) (succ u2), succ u1} (Sum.{u1, u2} α β) α) (fun (_x : Equiv.{max (succ u1) (succ u2), succ u1} (Sum.{u1, u2} α β) α) => (Sum.{u1, u2} α β) -> α) (Equiv.hasCoeToFun.{max (succ u1) (succ u2), succ u1} (Sum.{u1, u2} α β) α) (Equiv.sumEmpty.{u1, u2} α β _inst_1) (Sum.inl.{u1, u2} α β a)) a but is expected to have type forall {α : Type.{u2}} {β : Type.{u1}} [_inst_1 : IsEmpty.{succ u2} α] (a : β), Eq.{succ u1} ((fun ([email protected]._hyg.808 : Sum.{u1, u2} β α) => β) (Sum.inl.{u1, u2} β α a)) (FunLike.coe.{max (succ u2) (succ u1), max (succ u2) (succ u1), succ u1} (Equiv.{max (succ u2) (succ u1), succ u1} (Sum.{u1, u2} β α) β) (Sum.{u1, u2} β α) (fun (_x : Sum.{u1, u2} β α) => (fun ([email protected]._hyg.808 : Sum.{u1, u2} β α) => β) _x) (Equiv.instFunLikeEquiv.{max (succ u2) (succ u1), succ u1} (Sum.{u1, u2} β α) β) (Equiv.sumEmpty.{u1, u2} β α _inst_1) (Sum.inl.{u1, u2} β α a)) a Case conversion may be inaccurate. Consider using '#align equiv.sum_empty_apply_inl Equiv.sumEmpty_apply_inlₓ'. -/ @[simp] theorem sumEmpty_apply_inl {α β : Type _} [IsEmpty β] (a : α) : sumEmpty α β (Sum.inl a) = a := rfl #align equiv.sum_empty_apply_inl Equiv.sumEmpty_apply_inl #print Equiv.emptySum /- /-- The sum of `empty` with any `Sort*` is equivalent to the right summand. -/ @[simps symm_apply] def emptySum (α β : Type _) [IsEmpty α] : Sum α β ≃ β := (sumComm _ _).trans <| sumEmpty _ _ #align equiv.empty_sum Equiv.emptySum -/ /- warning: equiv.empty_sum_apply_inr -> Equiv.emptySum_apply_inr is a dubious translation: lean 3 declaration is forall {α : Type.{u1}} {β : Type.{u2}} [_inst_1 : IsEmpty.{succ u1} α] (b : β), Eq.{succ u2} β (coeFn.{max 1 (succ u1) (succ u2), max (succ u1) (succ u2)} (Equiv.{max (succ u1) (succ u2), succ u2} (Sum.{u1, u2} α β) β) (fun (_x : Equiv.{max (succ u1) (succ u2), succ u2} (Sum.{u1, u2} α β) β) => (Sum.{u1, u2} α β) -> β) (Equiv.hasCoeToFun.{max (succ u1) (succ u2), succ u2} (Sum.{u1, u2} α β) β) (Equiv.emptySum.{u1, u2} α β _inst_1) (Sum.inr.{u1, u2} α β b)) b but is expected to have type forall {α : Type.{u2}} {β : Type.{u1}} [_inst_1 : IsEmpty.{succ u2} α] (b : β), Eq.{succ u1} ((fun ([email protected]._hyg.808 : Sum.{u2, u1} α β) => β) (Sum.inr.{u2, u1} α β b)) (FunLike.coe.{max (succ u1) (succ u2), max (succ u1) (succ u2), succ u1} (Equiv.{max (succ u1) (succ u2), succ u1} (Sum.{u2, u1} α β) β) (Sum.{u2, u1} α β) (fun (_x : Sum.{u2, u1} α β) => (fun ([email protected]._hyg.808 : Sum.{u2, u1} α β) => β) _x) (Equiv.instFunLikeEquiv.{max (succ u1) (succ u2), succ u1} (Sum.{u2, u1} α β) β) (Equiv.emptySum.{u2, u1} α β _inst_1) (Sum.inr.{u2, u1} α β b)) b Case conversion may be inaccurate. Consider using '#align equiv.empty_sum_apply_inr Equiv.emptySum_apply_inrₓ'. -/ @[simp] theorem emptySum_apply_inr {α β : Type _} [IsEmpty α] (b : β) : emptySum α β (Sum.inr b) = b := rfl #align equiv.empty_sum_apply_inr Equiv.emptySum_apply_inr /- warning: equiv.option_equiv_sum_punit -> Equiv.optionEquivSumPUnit is a dubious translation: lean 3 declaration is forall (α : Type.{u2}), Equiv.{succ u2, max (succ u2) (succ u1)} (Option.{u2} α) (Sum.{u2, u1} α PUnit.{succ u1}) but is expected to have type forall (α : Type.{u1}), Equiv.{succ u1, max (succ u2) (succ u1)} (Option.{u1} α) (Sum.{u1, u2} α PUnit.{succ u2}) Case conversion may be inaccurate. Consider using '#align equiv.option_equiv_sum_punit Equiv.optionEquivSumPUnitₓ'. -/ /-- `option α` is equivalent to `α ⊕ punit` -/ def optionEquivSumPUnit (α : Type _) : Option α ≃ Sum α PUnit.{u + 1} := ⟨fun o => o.elim (inr PUnit.unit) inl, fun s => s.elim some fun _ => none, fun o => by cases o <;> rfl, fun s => by rcases s with (_ | ⟨⟨⟩⟩) <;> rfl⟩ #align equiv.option_equiv_sum_punit Equiv.optionEquivSumPUnit /- warning: equiv.option_equiv_sum_punit_none -> Equiv.optionEquivSumPUnit_none is a dubious translation: lean 3 declaration is forall {α : Type.{u1}}, Eq.{max (succ u1) (succ u2)} (Sum.{u1, u2} α PUnit.{succ u2}) (coeFn.{max 1 (succ u1) (succ u2), max (succ u1) (succ u2)} (Equiv.{succ u1, max (succ u1) (succ u2)} (Option.{u1} α) (Sum.{u1, u2} α PUnit.{succ u2})) (fun (_x : Equiv.{succ u1, max (succ u1) (succ u2)} (Option.{u1} α) (Sum.{u1, u2} α PUnit.{succ u2})) => (Option.{u1} α) -> (Sum.{u1, u2} α PUnit.{succ u2})) (Equiv.hasCoeToFun.{succ u1, max (succ u1) (succ u2)} (Option.{u1} α) (Sum.{u1, u2} α PUnit.{succ u2})) (Equiv.optionEquivSumPUnit.{u2, u1} α) (Option.none.{u1} α)) (Sum.inr.{u1, u2} α PUnit.{succ u2} PUnit.unit.{succ u2}) but is expected to have type forall {α : Type.{u2}}, Eq.{max (succ u1) (succ u2)} ((fun ([email protected]._hyg.808 : Option.{u2} α) => Sum.{u2, u1} α PUnit.{succ u1}) (Option.none.{u2} α)) (FunLike.coe.{max (succ u1) (succ u2), succ u2, max (succ u1) (succ u2)} (Equiv.{succ u2, max (succ u1) (succ u2)} (Option.{u2} α) (Sum.{u2, u1} α PUnit.{succ u1})) (Option.{u2} α) (fun (_x : Option.{u2} α) => (fun ([email protected]._hyg.808 : Option.{u2} α) => Sum.{u2, u1} α PUnit.{succ u1}) _x) (Equiv.instFunLikeEquiv.{succ u2, max (succ u1) (succ u2)} (Option.{u2} α) (Sum.{u2, u1} α PUnit.{succ u1})) (Equiv.optionEquivSumPUnit.{u2, u1} α) (Option.none.{u2} α)) (Sum.inr.{u2, u1} α PUnit.{succ u1} PUnit.unit.{succ u1}) Case conversion may be inaccurate. Consider using '#align equiv.option_equiv_sum_punit_none Equiv.optionEquivSumPUnit_noneₓ'. -/ @[simp] theorem optionEquivSumPUnit_none {α} : optionEquivSumPUnit α none = Sum.inr PUnit.unit := rfl #align equiv.option_equiv_sum_punit_none Equiv.optionEquivSumPUnit_none /- warning: equiv.option_equiv_sum_punit_some -> Equiv.optionEquivSumPUnit_some is a dubious translation: lean 3 declaration is forall {α : Type.{u1}} (a : α), Eq.{max (succ u1) (succ u2)} (Sum.{u1, u2} α PUnit.{succ u2}) (coeFn.{max 1 (succ u1) (succ u2), max (succ u1) (succ u2)} (Equiv.{succ u1, max (succ u1) (succ u2)} (Option.{u1} α) (Sum.{u1, u2} α PUnit.{succ u2})) (fun (_x : Equiv.{succ u1, max (succ u1) (succ u2)} (Option.{u1} α) (Sum.{u1, u2} α PUnit.{succ u2})) => (Option.{u1} α) -> (Sum.{u1, u2} α PUnit.{succ u2})) (Equiv.hasCoeToFun.{succ u1, max (succ u1) (succ u2)} (Option.{u1} α) (Sum.{u1, u2} α PUnit.{succ u2})) (Equiv.optionEquivSumPUnit.{u2, u1} α) (Option.some.{u1} α a)) (Sum.inl.{u1, u2} α PUnit.{succ u2} a) but is expected to have type forall {α : Type.{u2}} (a : α), Eq.{max (succ u1) (succ u2)} ((fun ([email protected]._hyg.808 : Option.{u2} α) => Sum.{u2, u1} α PUnit.{succ u1}) (Option.some.{u2} α a)) (FunLike.coe.{max (succ u1) (succ u2), succ u2, max (succ u1) (succ u2)} (Equiv.{succ u2, max (succ u1) (succ u2)} (Option.{u2} α) (Sum.{u2, u1} α PUnit.{succ u1})) (Option.{u2} α) (fun (_x : Option.{u2} α) => (fun ([email protected]._hyg.808 : Option.{u2} α) => Sum.{u2, u1} α PUnit.{succ u1}) _x) (Equiv.instFunLikeEquiv.{succ u2, max (succ u1) (succ u2)} (Option.{u2} α) (Sum.{u2, u1} α PUnit.{succ u1})) (Equiv.optionEquivSumPUnit.{u2, u1} α) (Option.some.{u2} α a)) (Sum.inl.{u2, u1} α PUnit.{succ u1} a) Case conversion may be inaccurate. Consider using '#align equiv.option_equiv_sum_punit_some Equiv.optionEquivSumPUnit_someₓ'. -/ @[simp] theorem optionEquivSumPUnit_some {α} (a) : optionEquivSumPUnit α (some a) = Sum.inl a := rfl #align equiv.option_equiv_sum_punit_some Equiv.optionEquivSumPUnit_some /- warning: equiv.option_equiv_sum_punit_coe -> Equiv.optionEquivSumPUnit_coe is a dubious translation: lean 3 declaration is forall {α : Type.{u1}} (a : α), Eq.{max (succ u1) (succ u2)} (Sum.{u1, u2} α PUnit.{succ u2}) (coeFn.{max 1 (succ u1) (succ u2), max (succ u1) (succ u2)} (Equiv.{succ u1, max (succ u1) (succ u2)} (Option.{u1} α) (Sum.{u1, u2} α PUnit.{succ u2})) (fun (_x : Equiv.{succ u1, max (succ u1) (succ u2)} (Option.{u1} α) (Sum.{u1, u2} α PUnit.{succ u2})) => (Option.{u1} α) -> (Sum.{u1, u2} α PUnit.{succ u2})) (Equiv.hasCoeToFun.{succ u1, max (succ u1) (succ u2)} (Option.{u1} α) (Sum.{u1, u2} α PUnit.{succ u2})) (Equiv.optionEquivSumPUnit.{u2, u1} α) ((fun (a : Type.{u1}) (b : Type.{u1}) [self : HasLiftT.{succ u1, succ u1} a b] => self.0) α (Option.{u1} α) (HasLiftT.mk.{succ u1, succ u1} α (Option.{u1} α) (CoeTCₓ.coe.{succ u1, succ u1} α (Option.{u1} α) (coeOption.{u1} α))) a)) (Sum.inl.{u1, u2} α PUnit.{succ u2} a) but is expected to have type forall {α : Type.{u2}} (a : α), Eq.{max (succ u1) (succ u2)} ((fun ([email protected]._hyg.808 : Option.{u2} α) => Sum.{u2, u1} α PUnit.{succ u1}) (Option.some.{u2} α a)) (FunLike.coe.{max (succ u1) (succ u2), succ u2, max (succ u1) (succ u2)} (Equiv.{succ u2, max (succ u1) (succ u2)} (Option.{u2} α) (Sum.{u2, u1} α PUnit.{succ u1})) (Option.{u2} α) (fun (_x : Option.{u2} α) => (fun ([email protected]._hyg.808 : Option.{u2} α) => Sum.{u2, u1} α PUnit.{succ u1}) _x) (Equiv.instFunLikeEquiv.{succ u2, max (succ u1) (succ u2)} (Option.{u2} α) (Sum.{u2, u1} α PUnit.{succ u1})) (Equiv.optionEquivSumPUnit.{u2, u1} α) (Option.some.{u2} α a)) (Sum.inl.{u2, u1} α PUnit.{succ u1} a) Case conversion may be inaccurate. Consider using '#align equiv.option_equiv_sum_punit_coe Equiv.optionEquivSumPUnit_coeₓ'. -/ @[simp] theorem optionEquivSumPUnit_coe {α} (a : α) : optionEquivSumPUnit α a = Sum.inl a := rfl #align equiv.option_equiv_sum_punit_coe Equiv.optionEquivSumPUnit_coe /- warning: equiv.option_equiv_sum_punit_symm_inl -> Equiv.optionEquivSumPUnit_symm_inl is a dubious translation: lean 3 declaration is forall {α : Type.{u1}} (a : α), Eq.{succ u1} (Option.{u1} α) (coeFn.{max 1 (succ u1) (succ u2), max (succ u1) (succ u2)} (Equiv.{max (succ u1) (succ u2), succ u1} (Sum.{u1, u2} α PUnit.{succ u2}) (Option.{u1} α)) (fun (_x : Equiv.{max (succ u1) (succ u2), succ u1} (Sum.{u1, u2} α PUnit.{succ u2}) (Option.{u1} α)) => (Sum.{u1, u2} α PUnit.{succ u2}) -> (Option.{u1} α)) (Equiv.hasCoeToFun.{max (succ u1) (succ u2), succ u1} (Sum.{u1, u2} α PUnit.{succ u2}) (Option.{u1} α)) (Equiv.symm.{succ u1, max (succ u1) (succ u2)} (Option.{u1} α) (Sum.{u1, u2} α PUnit.{succ u2}) (Equiv.optionEquivSumPUnit.{u2, u1} α)) (Sum.inl.{u1, u2} α PUnit.{succ u2} a)) ((fun (a : Type.{u1}) (b : Type.{u1}) [self : HasLiftT.{succ u1, succ u1} a b] => self.0) α (Option.{u1} α) (HasLiftT.mk.{succ u1, succ u1} α (Option.{u1} α) (CoeTCₓ.coe.{succ u1, succ u1} α (Option.{u1} α) (coeOption.{u1} α))) a) but is expected to have type forall {α : Type.{u2}} (a : α), Eq.{succ u2} ((fun ([email protected]._hyg.808 : Sum.{u2, u1} α PUnit.{succ u1}) => Option.{u2} α) (Sum.inl.{u2, u1} α PUnit.{succ u1} a)) (FunLike.coe.{max (succ u1) (succ u2), max (succ u1) (succ u2), succ u2} (Equiv.{max (succ u1) (succ u2), succ u2} (Sum.{u2, u1} α PUnit.{succ u1}) (Option.{u2} α)) (Sum.{u2, u1} α PUnit.{succ u1}) (fun (_x : Sum.{u2, u1} α PUnit.{succ u1}) => (fun ([email protected]._hyg.808 : Sum.{u2, u1} α PUnit.{succ u1}) => Option.{u2} α) _x) (Equiv.instFunLikeEquiv.{max (succ u1) (succ u2), succ u2} (Sum.{u2, u1} α PUnit.{succ u1}) (Option.{u2} α)) (Equiv.symm.{succ u2, max (succ u1) (succ u2)} (Option.{u2} α) (Sum.{u2, u1} α PUnit.{succ u1}) (Equiv.optionEquivSumPUnit.{u2, u1} α)) (Sum.inl.{u2, u1} α PUnit.{succ u1} a)) (Option.some.{u2} α a) Case conversion may be inaccurate. Consider using '#align equiv.option_equiv_sum_punit_symm_inl Equiv.optionEquivSumPUnit_symm_inlₓ'. -/ @[simp] theorem optionEquivSumPUnit_symm_inl {α} (a) : (optionEquivSumPUnit α).symm (Sum.inl a) = a := rfl #align equiv.option_equiv_sum_punit_symm_inl Equiv.optionEquivSumPUnit_symm_inl /- warning: equiv.option_equiv_sum_punit_symm_inr -> Equiv.optionEquivSumPUnit_symm_inr is a dubious translation: lean 3 declaration is forall {α : Type.{u1}} (a : PUnit.{succ u2}), Eq.{succ u1} (Option.{u1} α) (coeFn.{max 1 (succ u1) (succ u2), max (succ u1) (succ u2)} (Equiv.{max (succ u1) (succ u2), succ u1} (Sum.{u1, u2} α PUnit.{succ u2}) (Option.{u1} α)) (fun (_x : Equiv.{max (succ u1) (succ u2), succ u1} (Sum.{u1, u2} α PUnit.{succ u2}) (Option.{u1} α)) => (Sum.{u1, u2} α PUnit.{succ u2}) -> (Option.{u1} α)) (Equiv.hasCoeToFun.{max (succ u1) (succ u2), succ u1} (Sum.{u1, u2} α PUnit.{succ u2}) (Option.{u1} α)) (Equiv.symm.{succ u1, max (succ u1) (succ u2)} (Option.{u1} α) (Sum.{u1, u2} α PUnit.{succ u2}) (Equiv.optionEquivSumPUnit.{u2, u1} α)) (Sum.inr.{u1, u2} α PUnit.{succ u2} a)) (Option.none.{u1} α) but is expected to have type forall {α : Type.{u2}} (a : PUnit.{succ u1}), Eq.{succ u2} ((fun ([email protected]._hyg.808 : Sum.{u2, u1} α PUnit.{succ u1}) => Option.{u2} α) (Sum.inr.{u2, u1} α PUnit.{succ u1} a)) (FunLike.coe.{max (succ u1) (succ u2), max (succ u1) (succ u2), succ u2} (Equiv.{max (succ u1) (succ u2), succ u2} (Sum.{u2, u1} α PUnit.{succ u1}) (Option.{u2} α)) (Sum.{u2, u1} α PUnit.{succ u1}) (fun (_x : Sum.{u2, u1} α PUnit.{succ u1}) => (fun ([email protected]._hyg.808 : Sum.{u2, u1} α PUnit.{succ u1}) => Option.{u2} α) _x) (Equiv.instFunLikeEquiv.{max (succ u1) (succ u2), succ u2} (Sum.{u2, u1} α PUnit.{succ u1}) (Option.{u2} α)) (Equiv.symm.{succ u2, max (succ u1) (succ u2)} (Option.{u2} α) (Sum.{u2, u1} α PUnit.{succ u1}) (Equiv.optionEquivSumPUnit.{u2, u1} α)) (Sum.inr.{u2, u1} α PUnit.{succ u1} a)) (Option.none.{u2} α) Case conversion may be inaccurate. Consider using '#align equiv.option_equiv_sum_punit_symm_inr Equiv.optionEquivSumPUnit_symm_inrₓ'. -/ @[simp] theorem optionEquivSumPUnit_symm_inr {α} (a) : (optionEquivSumPUnit α).symm (Sum.inr a) = none := rfl #align equiv.option_equiv_sum_punit_symm_inr Equiv.optionEquivSumPUnit_symm_inr #print Equiv.optionIsSomeEquiv /- /-- The set of `x : option α` such that `is_some x` is equivalent to `α`. -/ @[simps] def optionIsSomeEquiv (α : Type _) : { x : Option α // x.isSome } ≃ α where toFun o := Option.get o.2 invFun x := ⟨some x, by decide⟩ left_inv o := Subtype.eq <| Option.some_get _ right_inv x := Option.get_some _ _ #align equiv.option_is_some_equiv Equiv.optionIsSomeEquiv -/ #print Equiv.piOptionEquivProd /- /-- The product over `option α` of `β a` is the binary product of the product over `α` of `β (some α)` and `β none` -/ @[simps] def piOptionEquivProd {α : Type _} {β : Option α → Type _} : (∀ a : Option α, β a) ≃ β none × ∀ a : α, β (some a) where toFun f := (f none, fun a => f (some a)) invFun x a := Option.casesOn a x.fst x.snd left_inv f := funext fun a => by cases a <;> rfl right_inv x := by simp #align equiv.pi_option_equiv_prod Equiv.piOptionEquivProd -/ #print Equiv.sumEquivSigmaBool /- /-- `α ⊕ β` is equivalent to a `sigma`-type over `bool`. Note that this definition assumes `α` and `β` to be types from the same universe, so it cannot by used directly to transfer theorems about sigma types to theorems about sum types. In many cases one can use `ulift` to work around this difficulty. -/ def sumEquivSigmaBool (α β : Type u) : Sum α β ≃ Σb : Bool, cond b α β := ⟨fun s => s.elim (fun x => ⟨true, x⟩) fun x => ⟨false, x⟩, fun s => match s with | ⟨tt, a⟩ => inl a | ⟨ff, b⟩ => inr b, fun s => by cases s <;> rfl, fun s => by rcases s with ⟨_ | _, _⟩ <;> rfl⟩ #align equiv.sum_equiv_sigma_bool Equiv.sumEquivSigmaBool -/ #print Equiv.sigmaFiberEquiv /- -- See also `equiv.sigma_preimage_equiv`. /-- `sigma_fiber_equiv f` for `f : α → β` is the natural equivalence between the type of all fibres of `f` and the total space `α`. -/ @[simps] def sigmaFiberEquiv {α β : Type _} (f : α → β) : (Σy : β, { x // f x = y }) ≃ α := ⟨fun x => ↑x.2, fun x => ⟨f x, x, rfl⟩, fun ⟨y, x, rfl⟩ => rfl, fun x => rfl⟩ #align equiv.sigma_fiber_equiv Equiv.sigmaFiberEquiv -/ end section SumCompl #print Equiv.sumCompl /- /-- For any predicate `p` on `α`, the sum of the two subtypes `{a // p a}` and its complement `{a // ¬ p a}` is naturally equivalent to `α`. See `subtype_or_equiv` for sum types over subtypes `{x // p x}` and `{x // q x}` that are not necessarily `is_compl p q`. -/ def sumCompl {α : Type _} (p : α → Prop) [DecidablePred p] : Sum { a // p a } { a // ¬p a } ≃ α where toFun := Sum.elim coe coe invFun a := if h : p a then Sum.inl ⟨a, h⟩ else Sum.inr ⟨a, h⟩ left_inv := by rintro (⟨x, hx⟩ | ⟨x, hx⟩) <;> dsimp <;> [rw [dif_pos], rw [dif_neg]] right_inv a := by dsimp split_ifs <;> rfl #align equiv.sum_compl Equiv.sumCompl -/ #print Equiv.sumCompl_apply_inl /- @[simp] theorem sumCompl_apply_inl {α : Type _} (p : α → Prop) [DecidablePred p] (x : { a // p a }) : sumCompl p (Sum.inl x) = x := rfl #align equiv.sum_compl_apply_inl Equiv.sumCompl_apply_inl -/ #print Equiv.sumCompl_apply_inr /- @[simp] theorem sumCompl_apply_inr {α : Type _} (p : α → Prop) [DecidablePred p] (x : { a // ¬p a }) : sumCompl p (Sum.inr x) = x := rfl #align equiv.sum_compl_apply_inr Equiv.sumCompl_apply_inr -/ #print Equiv.sumCompl_apply_symm_of_pos /- @[simp] theorem sumCompl_apply_symm_of_pos {α : Type _} (p : α → Prop) [DecidablePred p] (a : α) (h : p a) : (sumCompl p).symm a = Sum.inl ⟨a, h⟩ := dif_pos h #align equiv.sum_compl_apply_symm_of_pos Equiv.sumCompl_apply_symm_of_pos -/ #print Equiv.sumCompl_apply_symm_of_neg /- @[simp] theorem sumCompl_apply_symm_of_neg {α : Type _} (p : α → Prop) [DecidablePred p] (a : α) (h : ¬p a) : (sumCompl p).symm a = Sum.inr ⟨a, h⟩ := dif_neg h #align equiv.sum_compl_apply_symm_of_neg Equiv.sumCompl_apply_symm_of_neg -/ #print Equiv.subtypeCongr /- /-- Combines an `equiv` between two subtypes with an `equiv` between their complements to form a permutation. -/ def subtypeCongr {α : Type _} {p q : α → Prop} [DecidablePred p] [DecidablePred q] (e : { x // p x } ≃ { x // q x }) (f : { x // ¬p x } ≃ { x // ¬q x }) : Perm α := (sumCompl p).symm.trans ((sumCongr e f).trans (sumCompl q)) #align equiv.subtype_congr Equiv.subtypeCongr -/ open Equiv variable {ε : Type _} {p : ε → Prop} [DecidablePred p] variable (ep ep' : Perm { a // p a }) (en en' : Perm { a // ¬p a }) #print Equiv.Perm.subtypeCongr /- /-- Combining permutations on `ε` that permute only inside or outside the subtype split induced by `p : ε → Prop` constructs a permutation on `ε`. -/ def Perm.subtypeCongr : Equiv.Perm ε := permCongr (sumCompl p) (sumCongr ep en) #align equiv.perm.subtype_congr Equiv.Perm.subtypeCongr -/ #print Equiv.Perm.subtypeCongr.apply /- theorem Perm.subtypeCongr.apply (a : ε) : ep.subtypeCongr en a = if h : p a then ep ⟨a, h⟩ else en ⟨a, h⟩ := by by_cases h : p a <;> simp [perm.subtype_congr, h] #align equiv.perm.subtype_congr.apply Equiv.Perm.subtypeCongr.apply -/ #print Equiv.Perm.subtypeCongr.left_apply /- @[simp] theorem Perm.subtypeCongr.left_apply {a : ε} (h : p a) : ep.subtypeCongr en a = ep ⟨a, h⟩ := by simp [perm.subtype_congr.apply, h] #align equiv.perm.subtype_congr.left_apply Equiv.Perm.subtypeCongr.left_apply -/ #print Equiv.Perm.subtypeCongr.left_apply_subtype /- @[simp] theorem Perm.subtypeCongr.left_apply_subtype (a : { a // p a }) : ep.subtypeCongr en a = ep a := by convert perm.subtype_congr.left_apply _ _ a.property simp #align equiv.perm.subtype_congr.left_apply_subtype Equiv.Perm.subtypeCongr.left_apply_subtype -/ #print Equiv.Perm.subtypeCongr.right_apply /- @[simp] theorem Perm.subtypeCongr.right_apply {a : ε} (h : ¬p a) : ep.subtypeCongr en a = en ⟨a, h⟩ := by simp [perm.subtype_congr.apply, h] #align equiv.perm.subtype_congr.right_apply Equiv.Perm.subtypeCongr.right_apply -/ #print Equiv.Perm.subtypeCongr.right_apply_subtype /- @[simp] theorem Perm.subtypeCongr.right_apply_subtype (a : { a // ¬p a }) : ep.subtypeCongr en a = en a := by convert perm.subtype_congr.right_apply _ _ a.property simp #align equiv.perm.subtype_congr.right_apply_subtype Equiv.Perm.subtypeCongr.right_apply_subtype -/ #print Equiv.Perm.subtypeCongr.refl /- @[simp] theorem Perm.subtypeCongr.refl : Perm.subtypeCongr (Equiv.refl { a // p a }) (Equiv.refl { a // ¬p a }) = Equiv.refl ε := by ext x by_cases h : p x <;> simp [h] #align equiv.perm.subtype_congr.refl Equiv.Perm.subtypeCongr.refl -/ #print Equiv.Perm.subtypeCongr.symm /- @[simp] theorem Perm.subtypeCongr.symm : (ep.subtypeCongr en).symm = Perm.subtypeCongr ep.symm en.symm := by ext x by_cases h : p x · have : p (ep.symm ⟨x, h⟩) := Subtype.property _ simp [perm.subtype_congr.apply, h, symm_apply_eq, this] · have : ¬p (en.symm ⟨x, h⟩) := Subtype.property (en.symm _) simp [perm.subtype_congr.apply, h, symm_apply_eq, this] #align equiv.perm.subtype_congr.symm Equiv.Perm.subtypeCongr.symm -/ #print Equiv.Perm.subtypeCongr.trans /- @[simp] theorem Perm.subtypeCongr.trans : (ep.subtypeCongr en).trans (ep'.subtypeCongr en') = Perm.subtypeCongr (ep.trans ep') (en.trans en') := by ext x by_cases h : p x · have : p (ep ⟨x, h⟩) := Subtype.property _ simp [perm.subtype_congr.apply, h, this] · have : ¬p (en ⟨x, h⟩) := Subtype.property (en _) simp [perm.subtype_congr.apply, h, symm_apply_eq, this] #align equiv.perm.subtype_congr.trans Equiv.Perm.subtypeCongr.trans -/ end SumCompl section SubtypePreimage variable (p : α → Prop) [DecidablePred p] (x₀ : { a // p a } → β) #print Equiv.subtypePreimage /- /-- For a fixed function `x₀ : {a // p a} → β` defined on a subtype of `α`, the subtype of functions `x : α → β` that agree with `x₀` on the subtype `{a // p a}` is naturally equivalent to the type of functions `{a // ¬ p a} → β`. -/ @[simps] def subtypePreimage : { x : α → β // x ∘ coe = x₀ } ≃ ({ a // ¬p a } → β) where toFun (x : { x : α → β // x ∘ coe = x₀ }) a := (x : α → β) a invFun x := ⟨fun a => if h : p a then x₀ ⟨a, h⟩ else x ⟨a, h⟩, funext fun ⟨a, h⟩ => dif_pos h⟩ left_inv := fun ⟨x, hx⟩ => Subtype.val_injective <| funext fun a => by dsimp split_ifs <;> [rw [← hx], skip] <;> rfl right_inv x := funext fun ⟨a, h⟩ => show dite (p a) _ _ = _ by dsimp rw [dif_neg h] #align equiv.subtype_preimage Equiv.subtypePreimage -/ /- warning: equiv.subtype_preimage_symm_apply_coe_pos -> Equiv.subtypePreimage_symm_apply_coe_pos is a dubious translation: lean 3 declaration is forall {α : Sort.{u1}} {β : Sort.{u2}} (p : α -> Prop) [_inst_1 : DecidablePred.{u1} α p] (x₀ : (Subtype.{u1} α (fun (a : α) => p a)) -> β) (x : (Subtype.{u1} α (fun (a : α) => Not (p a))) -> β) (a : α) (h : p a), Eq.{u2} β ((fun (a : Sort.{max 1 (imax u1 u2)}) (b : Sort.{imax u1 u2}) [self : HasLiftT.{max 1 (imax u1 u2), imax u1 u2} a b] => self.0) (Subtype.{imax u1 u2} (α -> β) (fun (x : α -> β) => Eq.{imax (max 1 u1) u2} ((Subtype.{u1} α (fun (a : α) => p a)) -> β) (Function.comp.{max 1 u1, u1, u2} (Subtype.{u1} α (fun (a : α) => p a)) α β x ((fun (a : Sort.{max 1 u1}) (b : Sort.{u1}) [self : HasLiftT.{max 1 u1, u1} a b] => self.0) (Subtype.{u1} α (fun (a : α) => p a)) α (HasLiftT.mk.{max 1 u1, u1} (Subtype.{u1} α (fun (a : α) => p a)) α (CoeTCₓ.coe.{max 1 u1, u1} (Subtype.{u1} α (fun (a : α) => p a)) α (coeBase.{max 1 u1, u1} (Subtype.{u1} α (fun (a : α) => p a)) α (coeSubtype.{u1} α (fun (a : α) => p a))))))) x₀)) (α -> β) (HasLiftT.mk.{max 1 (imax u1 u2), imax u1 u2} (Subtype.{imax u1 u2} (α -> β) (fun (x : α -> β) => Eq.{imax (max 1 u1) u2} ((Subtype.{u1} α (fun (a : α) => p a)) -> β) (Function.comp.{max 1 u1, u1, u2} (Subtype.{u1} α (fun (a : α) => p a)) α β x ((fun (a : Sort.{max 1 u1}) (b : Sort.{u1}) [self : HasLiftT.{max 1 u1, u1} a b] => self.0) (Subtype.{u1} α (fun (a : α) => p a)) α (HasLiftT.mk.{max 1 u1, u1} (Subtype.{u1} α (fun (a : α) => p a)) α (CoeTCₓ.coe.{max 1 u1, u1} (Subtype.{u1} α (fun (a : α) => p a)) α (coeBase.{max 1 u1, u1} (Subtype.{u1} α (fun (a : α) => p a)) α (coeSubtype.{u1} α (fun (a : α) => p a))))))) x₀)) (α -> β) (CoeTCₓ.coe.{max 1 (imax u1 u2), imax u1 u2} (Subtype.{imax u1 u2} (α -> β) (fun (x : α -> β) => Eq.{imax (max 1 u1) u2} ((Subtype.{u1} α (fun (a : α) => p a)) -> β) (Function.comp.{max 1 u1, u1, u2} (Subtype.{u1} α (fun (a : α) => p a)) α β x ((fun (a : Sort.{max 1 u1}) (b : Sort.{u1}) [self : HasLiftT.{max 1 u1, u1} a b] => self.0) (Subtype.{u1} α (fun (a : α) => p a)) α (HasLiftT.mk.{max 1 u1, u1} (Subtype.{u1} α (fun (a : α) => p a)) α (CoeTCₓ.coe.{max 1 u1, u1} (Subtype.{u1} α (fun (a : α) => p a)) α (coeBase.{max 1 u1, u1} (Subtype.{u1} α (fun (a : α) => p a)) α (coeSubtype.{u1} α (fun (a : α) => p a))))))) x₀)) (α -> β) (coeBase.{max 1 (imax u1 u2), imax u1 u2} (Subtype.{imax u1 u2} (α -> β) (fun (x : α -> β) => Eq.{imax (max 1 u1) u2} ((Subtype.{u1} α (fun (a : α) => p a)) -> β) (Function.comp.{max 1 u1, u1, u2} (Subtype.{u1} α (fun (a : α) => p a)) α β x ((fun (a : Sort.{max 1 u1}) (b : Sort.{u1}) [self : HasLiftT.{max 1 u1, u1} a b] => self.0) (Subtype.{u1} α (fun (a : α) => p a)) α (HasLiftT.mk.{max 1 u1, u1} (Subtype.{u1} α (fun (a : α) => p a)) α (CoeTCₓ.coe.{max 1 u1, u1} (Subtype.{u1} α (fun (a : α) => p a)) α (coeBase.{max 1 u1, u1} (Subtype.{u1} α (fun (a : α) => p a)) α (coeSubtype.{u1} α (fun (a : α) => p a))))))) x₀)) (α -> β) (coeSubtype.{imax u1 u2} (α -> β) (fun (x : α -> β) => Eq.{imax (max 1 u1) u2} ((Subtype.{u1} α (fun (a : α) => p a)) -> β) (Function.comp.{max 1 u1, u1, u2} (Subtype.{u1} α (fun (a : α) => p a)) α β x ((fun (a : Sort.{max 1 u1}) (b : Sort.{u1}) [self : HasLiftT.{max 1 u1, u1} a b] => self.0) (Subtype.{u1} α (fun (a : α) => p a)) α (HasLiftT.mk.{max 1 u1, u1} (Subtype.{u1} α (fun (a : α) => p a)) α (CoeTCₓ.coe.{max 1 u1, u1} (Subtype.{u1} α (fun (a : α) => p a)) α (coeBase.{max 1 u1, u1} (Subtype.{u1} α (fun (a : α) => p a)) α (coeSubtype.{u1} α (fun (a : α) => p a))))))) x₀))))) (coeFn.{max 1 (max (imax (max 1 u1) u2) 1 (imax u1 u2)) (imax (max 1 (imax u1 u2)) (max 1 u1) u2), max (imax (max 1 u1) u2) 1 (imax u1 u2)} (Equiv.{imax (max 1 u1) u2, max 1 (imax u1 u2)} ((Subtype.{u1} α (fun (a : α) => Not (p a))) -> β) (Subtype.{imax u1 u2} (α -> β) (fun (x : α -> β) => Eq.{imax (max 1 u1) u2} ((Subtype.{u1} α (fun (a : α) => p a)) -> β) (Function.comp.{max 1 u1, u1, u2} (Subtype.{u1} α (fun (a : α) => p a)) α β x ((fun (a : Sort.{max 1 u1}) (b : Sort.{u1}) [self : HasLiftT.{max 1 u1, u1} a b] => self.0) (Subtype.{u1} α (fun (a : α) => p a)) α (HasLiftT.mk.{max 1 u1, u1} (Subtype.{u1} α (fun (a : α) => p a)) α (CoeTCₓ.coe.{max 1 u1, u1} (Subtype.{u1} α (fun (a : α) => p a)) α (coeBase.{max 1 u1, u1} (Subtype.{u1} α (fun (a : α) => p a)) α (coeSubtype.{u1} α (fun (a : α) => p a))))))) x₀))) (fun (_x : Equiv.{imax (max 1 u1) u2, max 1 (imax u1 u2)} ((Subtype.{u1} α (fun (a : α) => Not (p a))) -> β) (Subtype.{imax u1 u2} (α -> β) (fun (x : α -> β) => Eq.{imax (max 1 u1) u2} ((Subtype.{u1} α (fun (a : α) => p a)) -> β) (Function.comp.{max 1 u1, u1, u2} (Subtype.{u1} α (fun (a : α) => p a)) α β x ((fun (a : Sort.{max 1 u1}) (b : Sort.{u1}) [self : HasLiftT.{max 1 u1, u1} a b] => self.0) (Subtype.{u1} α (fun (a : α) => p a)) α (HasLiftT.mk.{max 1 u1, u1} (Subtype.{u1} α (fun (a : α) => p a)) α (CoeTCₓ.coe.{max 1 u1, u1} (Subtype.{u1} α (fun (a : α) => p a)) α (coeBase.{max 1 u1, u1} (Subtype.{u1} α (fun (a : α) => p a)) α (coeSubtype.{u1} α (fun (a : α) => p a))))))) x₀))) => ((Subtype.{u1} α (fun (a : α) => Not (p a))) -> β) -> (Subtype.{imax u1 u2} (α -> β) (fun (x : α -> β) => Eq.{imax (max 1 u1) u2} ((Subtype.{u1} α (fun (a : α) => p a)) -> β) (Function.comp.{max 1 u1, u1, u2} (Subtype.{u1} α (fun (a : α) => p a)) α β x ((fun (a : Sort.{max 1 u1}) (b : Sort.{u1}) [self : HasLiftT.{max 1 u1, u1} a b] => self.0) (Subtype.{u1} α (fun (a : α) => p a)) α (HasLiftT.mk.{max 1 u1, u1} (Subtype.{u1} α (fun (a : α) => p a)) α (CoeTCₓ.coe.{max 1 u1, u1} (Subtype.{u1} α (fun (a : α) => p a)) α (coeBase.{max 1 u1, u1} (Subtype.{u1} α (fun (a : α) => p a)) α (coeSubtype.{u1} α (fun (a : α) => p a))))))) x₀))) (Equiv.hasCoeToFun.{imax (max 1 u1) u2, max 1 (imax u1 u2)} ((Subtype.{u1} α (fun (a : α) => Not (p a))) -> β) (Subtype.{imax u1 u2} (α -> β) (fun (x : α -> β) => Eq.{imax (max 1 u1) u2} ((Subtype.{u1} α (fun (a : α) => p a)) -> β) (Function.comp.{max 1 u1, u1, u2} (Subtype.{u1} α (fun (a : α) => p a)) α β x ((fun (a : Sort.{max 1 u1}) (b : Sort.{u1}) [self : HasLiftT.{max 1 u1, u1} a b] => self.0) (Subtype.{u1} α (fun (a : α) => p a)) α (HasLiftT.mk.{max 1 u1, u1} (Subtype.{u1} α (fun (a : α) => p a)) α (CoeTCₓ.coe.{max 1 u1, u1} (Subtype.{u1} α (fun (a : α) => p a)) α (coeBase.{max 1 u1, u1} (Subtype.{u1} α (fun (a : α) => p a)) α (coeSubtype.{u1} α (fun (a : α) => p a))))))) x₀))) (Equiv.symm.{max 1 (imax u1 u2), imax (max 1 u1) u2} (Subtype.{imax u1 u2} (α -> β) (fun (x : α -> β) => Eq.{imax (max 1 u1) u2} ((Subtype.{u1} α (fun (a : α) => p a)) -> β) (Function.comp.{max 1 u1, u1, u2} (Subtype.{u1} α (fun (a : α) => p a)) α β x ((fun (a : Sort.{max 1 u1}) (b : Sort.{u1}) [self : HasLiftT.{max 1 u1, u1} a b] => self.0) (Subtype.{u1} α (fun (a : α) => p a)) α (HasLiftT.mk.{max 1 u1, u1} (Subtype.{u1} α (fun (a : α) => p a)) α (CoeTCₓ.coe.{max 1 u1, u1} (Subtype.{u1} α (fun (a : α) => p a)) α (coeBase.{max 1 u1, u1} (Subtype.{u1} α (fun (a : α) => p a)) α (coeSubtype.{u1} α (fun (a : α) => p a))))))) x₀)) ((Subtype.{u1} α (fun (a : α) => Not (p a))) -> β) (Equiv.subtypePreimage.{u1, u2} α β p (fun (a : α) => _inst_1 a) x₀)) x) a) (x₀ (Subtype.mk.{u1} α (fun (a : α) => p a) a h)) but is expected to have type forall {α : Sort.{u2}} {β : Sort.{u1}} (p : α -> Prop) [_inst_1 : DecidablePred.{u2} α p] (x₀ : (Subtype.{u2} α (fun (a : α) => p a)) -> β) (x : (Subtype.{u2} α (fun (a : α) => Not (p a))) -> β) (a : α) (h : p a), Eq.{u1} β (Subtype.val.{imax u2 u1} (α -> β) (fun (x : α -> β) => Eq.{imax (max 1 u2) u1} ((Subtype.{u2} α (fun (a : α) => p a)) -> β) (Function.comp.{max 1 u2, u2, u1} (Subtype.{u2} α (fun (a : α) => p a)) α β x (Subtype.val.{u2} α (fun (a : α) => p a))) x₀) (FunLike.coe.{max (max 1 (imax u2 u1)) (imax (max 1 u2) u1), imax (max 1 u2) u1, max 1 (imax u2 u1)} (Equiv.{imax (max 1 u2) u1, max 1 (imax u2 u1)} ((Subtype.{u2} α (fun (a : α) => Not (p a))) -> β) (Subtype.{imax u2 u1} (α -> β) (fun (x : α -> β) => Eq.{imax (max 1 u2) u1} ((Subtype.{u2} α (fun (a : α) => p a)) -> β) (Function.comp.{max 1 u2, u2, u1} (Subtype.{u2} α (fun (a : α) => p a)) α β x (Subtype.val.{u2} α (fun (a : α) => p a))) x₀))) ((Subtype.{u2} α (fun (a : α) => Not (p a))) -> β) (fun (_x : (Subtype.{u2} α (fun (a : α) => Not (p a))) -> β) => (fun ([email protected]._hyg.808 : (Subtype.{u2} α (fun (a : α) => Not (p a))) -> β) => Subtype.{imax u2 u1} (α -> β) (fun (x : α -> β) => Eq.{imax (max 1 u2) u1} ((Subtype.{u2} α (fun (a : α) => p a)) -> β) (Function.comp.{max 1 u2, u2, u1} (Subtype.{u2} α (fun (a : α) => p a)) α β x (Subtype.val.{u2} α (fun (a : α) => p a))) x₀)) _x) (Equiv.instFunLikeEquiv.{imax (max 1 u2) u1, max 1 (imax u2 u1)} ((Subtype.{u2} α (fun (a : α) => Not (p a))) -> β) (Subtype.{imax u2 u1} (α -> β) (fun (x : α -> β) => Eq.{imax (max 1 u2) u1} ((Subtype.{u2} α (fun (a : α) => p a)) -> β) (Function.comp.{max 1 u2, u2, u1} (Subtype.{u2} α (fun (a : α) => p a)) α β x (Subtype.val.{u2} α (fun (a : α) => p a))) x₀))) (Equiv.symm.{max 1 (imax u2 u1), imax (max 1 u2) u1} (Subtype.{imax u2 u1} (α -> β) (fun (x : α -> β) => Eq.{imax (max 1 u2) u1} ((Subtype.{u2} α (fun (a : α) => p a)) -> β) (Function.comp.{max 1 u2, u2, u1} (Subtype.{u2} α (fun (a : α) => p a)) α β x (Subtype.val.{u2} α (fun (a : α) => p a))) x₀)) ((Subtype.{u2} α (fun (a : α) => Not (p a))) -> β) (Equiv.subtypePreimage.{u2, u1} α β p (fun (a : α) => _inst_1 a) x₀)) x) a) (x₀ (Subtype.mk.{u2} α (fun (a : α) => p a) a h)) Case conversion may be inaccurate. Consider using '#align equiv.subtype_preimage_symm_apply_coe_pos Equiv.subtypePreimage_symm_apply_coe_posₓ'. -/ theorem subtypePreimage_symm_apply_coe_pos (x : { a // ¬p a } → β) (a : α) (h : p a) : ((subtypePreimage p x₀).symm x : α → β) a = x₀ ⟨a, h⟩ := dif_pos h #align equiv.subtype_preimage_symm_apply_coe_pos Equiv.subtypePreimage_symm_apply_coe_pos /- warning: equiv.subtype_preimage_symm_apply_coe_neg -> Equiv.subtypePreimage_symm_apply_coe_neg is a dubious translation: lean 3 declaration is forall {α : Sort.{u1}} {β : Sort.{u2}} (p : α -> Prop) [_inst_1 : DecidablePred.{u1} α p] (x₀ : (Subtype.{u1} α (fun (a : α) => p a)) -> β) (x : (Subtype.{u1} α (fun (a : α) => Not (p a))) -> β) (a : α) (h : Not (p a)), Eq.{u2} β ((fun (a : Sort.{max 1 (imax u1 u2)}) (b : Sort.{imax u1 u2}) [self : HasLiftT.{max 1 (imax u1 u2), imax u1 u2} a b] => self.0) (Subtype.{imax u1 u2} (α -> β) (fun (x : α -> β) => Eq.{imax (max 1 u1) u2} ((Subtype.{u1} α (fun (a : α) => p a)) -> β) (Function.comp.{max 1 u1, u1, u2} (Subtype.{u1} α (fun (a : α) => p a)) α β x ((fun (a : Sort.{max 1 u1}) (b : Sort.{u1}) [self : HasLiftT.{max 1 u1, u1} a b] => self.0) (Subtype.{u1} α (fun (a : α) => p a)) α (HasLiftT.mk.{max 1 u1, u1} (Subtype.{u1} α (fun (a : α) => p a)) α (CoeTCₓ.coe.{max 1 u1, u1} (Subtype.{u1} α (fun (a : α) => p a)) α (coeBase.{max 1 u1, u1} (Subtype.{u1} α (fun (a : α) => p a)) α (coeSubtype.{u1} α (fun (a : α) => p a))))))) x₀)) (α -> β) (HasLiftT.mk.{max 1 (imax u1 u2), imax u1 u2} (Subtype.{imax u1 u2} (α -> β) (fun (x : α -> β) => Eq.{imax (max 1 u1) u2} ((Subtype.{u1} α (fun (a : α) => p a)) -> β) (Function.comp.{max 1 u1, u1, u2} (Subtype.{u1} α (fun (a : α) => p a)) α β x ((fun (a : Sort.{max 1 u1}) (b : Sort.{u1}) [self : HasLiftT.{max 1 u1, u1} a b] => self.0) (Subtype.{u1} α (fun (a : α) => p a)) α (HasLiftT.mk.{max 1 u1, u1} (Subtype.{u1} α (fun (a : α) => p a)) α (CoeTCₓ.coe.{max 1 u1, u1} (Subtype.{u1} α (fun (a : α) => p a)) α (coeBase.{max 1 u1, u1} (Subtype.{u1} α (fun (a : α) => p a)) α (coeSubtype.{u1} α (fun (a : α) => p a))))))) x₀)) (α -> β) (CoeTCₓ.coe.{max 1 (imax u1 u2), imax u1 u2} (Subtype.{imax u1 u2} (α -> β) (fun (x : α -> β) => Eq.{imax (max 1 u1) u2} ((Subtype.{u1} α (fun (a : α) => p a)) -> β) (Function.comp.{max 1 u1, u1, u2} (Subtype.{u1} α (fun (a : α) => p a)) α β x ((fun (a : Sort.{max 1 u1}) (b : Sort.{u1}) [self : HasLiftT.{max 1 u1, u1} a b] => self.0) (Subtype.{u1} α (fun (a : α) => p a)) α (HasLiftT.mk.{max 1 u1, u1} (Subtype.{u1} α (fun (a : α) => p a)) α (CoeTCₓ.coe.{max 1 u1, u1} (Subtype.{u1} α (fun (a : α) => p a)) α (coeBase.{max 1 u1, u1} (Subtype.{u1} α (fun (a : α) => p a)) α (coeSubtype.{u1} α (fun (a : α) => p a))))))) x₀)) (α -> β) (coeBase.{max 1 (imax u1 u2), imax u1 u2} (Subtype.{imax u1 u2} (α -> β) (fun (x : α -> β) => Eq.{imax (max 1 u1) u2} ((Subtype.{u1} α (fun (a : α) => p a)) -> β) (Function.comp.{max 1 u1, u1, u2} (Subtype.{u1} α (fun (a : α) => p a)) α β x ((fun (a : Sort.{max 1 u1}) (b : Sort.{u1}) [self : HasLiftT.{max 1 u1, u1} a b] => self.0) (Subtype.{u1} α (fun (a : α) => p a)) α (HasLiftT.mk.{max 1 u1, u1} (Subtype.{u1} α (fun (a : α) => p a)) α (CoeTCₓ.coe.{max 1 u1, u1} (Subtype.{u1} α (fun (a : α) => p a)) α (coeBase.{max 1 u1, u1} (Subtype.{u1} α (fun (a : α) => p a)) α (coeSubtype.{u1} α (fun (a : α) => p a))))))) x₀)) (α -> β) (coeSubtype.{imax u1 u2} (α -> β) (fun (x : α -> β) => Eq.{imax (max 1 u1) u2} ((Subtype.{u1} α (fun (a : α) => p a)) -> β) (Function.comp.{max 1 u1, u1, u2} (Subtype.{u1} α (fun (a : α) => p a)) α β x ((fun (a : Sort.{max 1 u1}) (b : Sort.{u1}) [self : HasLiftT.{max 1 u1, u1} a b] => self.0) (Subtype.{u1} α (fun (a : α) => p a)) α (HasLiftT.mk.{max 1 u1, u1} (Subtype.{u1} α (fun (a : α) => p a)) α (CoeTCₓ.coe.{max 1 u1, u1} (Subtype.{u1} α (fun (a : α) => p a)) α (coeBase.{max 1 u1, u1} (Subtype.{u1} α (fun (a : α) => p a)) α (coeSubtype.{u1} α (fun (a : α) => p a))))))) x₀))))) (coeFn.{max 1 (max (imax (max 1 u1) u2) 1 (imax u1 u2)) (imax (max 1 (imax u1 u2)) (max 1 u1) u2), max (imax (max 1 u1) u2) 1 (imax u1 u2)} (Equiv.{imax (max 1 u1) u2, max 1 (imax u1 u2)} ((Subtype.{u1} α (fun (a : α) => Not (p a))) -> β) (Subtype.{imax u1 u2} (α -> β) (fun (x : α -> β) => Eq.{imax (max 1 u1) u2} ((Subtype.{u1} α (fun (a : α) => p a)) -> β) (Function.comp.{max 1 u1, u1, u2} (Subtype.{u1} α (fun (a : α) => p a)) α β x ((fun (a : Sort.{max 1 u1}) (b : Sort.{u1}) [self : HasLiftT.{max 1 u1, u1} a b] => self.0) (Subtype.{u1} α (fun (a : α) => p a)) α (HasLiftT.mk.{max 1 u1, u1} (Subtype.{u1} α (fun (a : α) => p a)) α (CoeTCₓ.coe.{max 1 u1, u1} (Subtype.{u1} α (fun (a : α) => p a)) α (coeBase.{max 1 u1, u1} (Subtype.{u1} α (fun (a : α) => p a)) α (coeSubtype.{u1} α (fun (a : α) => p a))))))) x₀))) (fun (_x : Equiv.{imax (max 1 u1) u2, max 1 (imax u1 u2)} ((Subtype.{u1} α (fun (a : α) => Not (p a))) -> β) (Subtype.{imax u1 u2} (α -> β) (fun (x : α -> β) => Eq.{imax (max 1 u1) u2} ((Subtype.{u1} α (fun (a : α) => p a)) -> β) (Function.comp.{max 1 u1, u1, u2} (Subtype.{u1} α (fun (a : α) => p a)) α β x ((fun (a : Sort.{max 1 u1}) (b : Sort.{u1}) [self : HasLiftT.{max 1 u1, u1} a b] => self.0) (Subtype.{u1} α (fun (a : α) => p a)) α (HasLiftT.mk.{max 1 u1, u1} (Subtype.{u1} α (fun (a : α) => p a)) α (CoeTCₓ.coe.{max 1 u1, u1} (Subtype.{u1} α (fun (a : α) => p a)) α (coeBase.{max 1 u1, u1} (Subtype.{u1} α (fun (a : α) => p a)) α (coeSubtype.{u1} α (fun (a : α) => p a))))))) x₀))) => ((Subtype.{u1} α (fun (a : α) => Not (p a))) -> β) -> (Subtype.{imax u1 u2} (α -> β) (fun (x : α -> β) => Eq.{imax (max 1 u1) u2} ((Subtype.{u1} α (fun (a : α) => p a)) -> β) (Function.comp.{max 1 u1, u1, u2} (Subtype.{u1} α (fun (a : α) => p a)) α β x ((fun (a : Sort.{max 1 u1}) (b : Sort.{u1}) [self : HasLiftT.{max 1 u1, u1} a b] => self.0) (Subtype.{u1} α (fun (a : α) => p a)) α (HasLiftT.mk.{max 1 u1, u1} (Subtype.{u1} α (fun (a : α) => p a)) α (CoeTCₓ.coe.{max 1 u1, u1} (Subtype.{u1} α (fun (a : α) => p a)) α (coeBase.{max 1 u1, u1} (Subtype.{u1} α (fun (a : α) => p a)) α (coeSubtype.{u1} α (fun (a : α) => p a))))))) x₀))) (Equiv.hasCoeToFun.{imax (max 1 u1) u2, max 1 (imax u1 u2)} ((Subtype.{u1} α (fun (a : α) => Not (p a))) -> β) (Subtype.{imax u1 u2} (α -> β) (fun (x : α -> β) => Eq.{imax (max 1 u1) u2} ((Subtype.{u1} α (fun (a : α) => p a)) -> β) (Function.comp.{max 1 u1, u1, u2} (Subtype.{u1} α (fun (a : α) => p a)) α β x ((fun (a : Sort.{max 1 u1}) (b : Sort.{u1}) [self : HasLiftT.{max 1 u1, u1} a b] => self.0) (Subtype.{u1} α (fun (a : α) => p a)) α (HasLiftT.mk.{max 1 u1, u1} (Subtype.{u1} α (fun (a : α) => p a)) α (CoeTCₓ.coe.{max 1 u1, u1} (Subtype.{u1} α (fun (a : α) => p a)) α (coeBase.{max 1 u1, u1} (Subtype.{u1} α (fun (a : α) => p a)) α (coeSubtype.{u1} α (fun (a : α) => p a))))))) x₀))) (Equiv.symm.{max 1 (imax u1 u2), imax (max 1 u1) u2} (Subtype.{imax u1 u2} (α -> β) (fun (x : α -> β) => Eq.{imax (max 1 u1) u2} ((Subtype.{u1} α (fun (a : α) => p a)) -> β) (Function.comp.{max 1 u1, u1, u2} (Subtype.{u1} α (fun (a : α) => p a)) α β x ((fun (a : Sort.{max 1 u1}) (b : Sort.{u1}) [self : HasLiftT.{max 1 u1, u1} a b] => self.0) (Subtype.{u1} α (fun (a : α) => p a)) α (HasLiftT.mk.{max 1 u1, u1} (Subtype.{u1} α (fun (a : α) => p a)) α (CoeTCₓ.coe.{max 1 u1, u1} (Subtype.{u1} α (fun (a : α) => p a)) α (coeBase.{max 1 u1, u1} (Subtype.{u1} α (fun (a : α) => p a)) α (coeSubtype.{u1} α (fun (a : α) => p a))))))) x₀)) ((Subtype.{u1} α (fun (a : α) => Not (p a))) -> β) (Equiv.subtypePreimage.{u1, u2} α β p (fun (a : α) => _inst_1 a) x₀)) x) a) (x (Subtype.mk.{u1} α (fun (a : α) => Not (p a)) a h)) but is expected to have type forall {α : Sort.{u2}} {β : Sort.{u1}} (p : α -> Prop) [_inst_1 : DecidablePred.{u2} α p] (x₀ : (Subtype.{u2} α (fun (a : α) => p a)) -> β) (x : (Subtype.{u2} α (fun (a : α) => Not (p a))) -> β) (a : α) (h : Not (p a)), Eq.{u1} β (Subtype.val.{imax u2 u1} (α -> β) (fun (x : α -> β) => Eq.{imax (max 1 u2) u1} ((Subtype.{u2} α (fun (a : α) => p a)) -> β) (Function.comp.{max 1 u2, u2, u1} (Subtype.{u2} α (fun (a : α) => p a)) α β x (Subtype.val.{u2} α (fun (a : α) => p a))) x₀) (FunLike.coe.{max (max 1 (imax u2 u1)) (imax (max 1 u2) u1), imax (max 1 u2) u1, max 1 (imax u2 u1)} (Equiv.{imax (max 1 u2) u1, max 1 (imax u2 u1)} ((Subtype.{u2} α (fun (a : α) => Not (p a))) -> β) (Subtype.{imax u2 u1} (α -> β) (fun (x : α -> β) => Eq.{imax (max 1 u2) u1} ((Subtype.{u2} α (fun (a : α) => p a)) -> β) (Function.comp.{max 1 u2, u2, u1} (Subtype.{u2} α (fun (a : α) => p a)) α β x (Subtype.val.{u2} α (fun (a : α) => p a))) x₀))) ((Subtype.{u2} α (fun (a : α) => Not (p a))) -> β) (fun (_x : (Subtype.{u2} α (fun (a : α) => Not (p a))) -> β) => (fun ([email protected]._hyg.808 : (Subtype.{u2} α (fun (a : α) => Not (p a))) -> β) => Subtype.{imax u2 u1} (α -> β) (fun (x : α -> β) => Eq.{imax (max 1 u2) u1} ((Subtype.{u2} α (fun (a : α) => p a)) -> β) (Function.comp.{max 1 u2, u2, u1} (Subtype.{u2} α (fun (a : α) => p a)) α β x (Subtype.val.{u2} α (fun (a : α) => p a))) x₀)) _x) (Equiv.instFunLikeEquiv.{imax (max 1 u2) u1, max 1 (imax u2 u1)} ((Subtype.{u2} α (fun (a : α) => Not (p a))) -> β) (Subtype.{imax u2 u1} (α -> β) (fun (x : α -> β) => Eq.{imax (max 1 u2) u1} ((Subtype.{u2} α (fun (a : α) => p a)) -> β) (Function.comp.{max 1 u2, u2, u1} (Subtype.{u2} α (fun (a : α) => p a)) α β x (Subtype.val.{u2} α (fun (a : α) => p a))) x₀))) (Equiv.symm.{max 1 (imax u2 u1), imax (max 1 u2) u1} (Subtype.{imax u2 u1} (α -> β) (fun (x : α -> β) => Eq.{imax (max 1 u2) u1} ((Subtype.{u2} α (fun (a : α) => p a)) -> β) (Function.comp.{max 1 u2, u2, u1} (Subtype.{u2} α (fun (a : α) => p a)) α β x (Subtype.val.{u2} α (fun (a : α) => p a))) x₀)) ((Subtype.{u2} α (fun (a : α) => Not (p a))) -> β) (Equiv.subtypePreimage.{u2, u1} α β p (fun (a : α) => _inst_1 a) x₀)) x) a) (x (Subtype.mk.{u2} α (fun (a : α) => Not (p a)) a h)) Case conversion may be inaccurate. Consider using '#align equiv.subtype_preimage_symm_apply_coe_neg Equiv.subtypePreimage_symm_apply_coe_negₓ'. -/ theorem subtypePreimage_symm_apply_coe_neg (x : { a // ¬p a } → β) (a : α) (h : ¬p a) : ((subtypePreimage p x₀).symm x : α → β) a = x ⟨a, h⟩ := dif_neg h #align equiv.subtype_preimage_symm_apply_coe_neg Equiv.subtypePreimage_symm_apply_coe_neg end SubtypePreimage section #print Equiv.piCongrRight /- /-- A family of equivalences `Π a, β₁ a ≃ β₂ a` generates an equivalence between `Π a, β₁ a` and `Π a, β₂ a`. -/ def piCongrRight {α} {β₁ β₂ : α → Sort _} (F : ∀ a, β₁ a ≃ β₂ a) : (∀ a, β₁ a) ≃ ∀ a, β₂ a := ⟨fun H a => F a (H a), fun H a => (F a).symm (H a), fun H => funext <| by simp, fun H => funext <| by simp⟩ #align equiv.Pi_congr_right Equiv.piCongrRight -/ #print Equiv.piComm /- /-- Given `φ : α → β → Sort*`, we have an equivalence between `Π a b, φ a b` and `Π b a, φ a b`. This is `function.swap` as an `equiv`. -/ @[simps apply] def piComm {α β} (φ : α → β → Sort _) : (∀ a b, φ a b) ≃ ∀ b a, φ a b := ⟨swap, swap, fun x => rfl, fun y => rfl⟩ #align equiv.Pi_comm Equiv.piComm -/ /- warning: equiv.Pi_comm_symm -> Equiv.piComm_symm is a dubious translation: lean 3 declaration is forall {α : Sort.{u1}} {β : Sort.{u2}} {φ : α -> β -> Sort.{u3}}, Eq.{max 1 (imax (imax u2 u1 u3) u1 u2 u3) (imax (imax u1 u2 u3) u2 u1 u3)} (Equiv.{imax u2 u1 u3, imax u1 u2 u3} (forall (b : β) (a : α), φ a b) (forall (a : α) (b : β), φ a b)) (Equiv.symm.{imax u1 u2 u3, imax u2 u1 u3} (forall (a : α) (b : β), φ a b) (forall (b : β) (a : α), φ a b) (Equiv.piComm.{u1, u2, u3} α β φ)) (Equiv.piComm.{u2, u1, u3} β α (Function.swap.{u1, u2, succ u3} α β (fun (ᾰ : α) (ᾰ : β) => Sort.{u3}) φ)) but is expected to have type forall {α : Sort.{u3}} {β : Sort.{u2}} {φ : α -> β -> Sort.{u1}}, Eq.{max (max 1 (imax u3 u2 u1)) (imax u2 u3 u1)} (Equiv.{imax u2 u3 u1, imax u3 u2 u1} (forall (b : β) (a : α), φ a b) (forall (a : α) (b : β), φ a b)) (Equiv.symm.{imax u3 u2 u1, imax u2 u3 u1} (forall (a : α) (b : β), φ a b) (forall (b : β) (a : α), φ a b) (Equiv.piComm.{u3, u2, u1} α β φ)) (Equiv.piComm.{u2, u3, u1} β α (Function.swap.{u3, u2, succ u1} α β (fun (ᾰ : α) (ᾰ : β) => Sort.{u1}) φ)) Case conversion may be inaccurate. Consider using '#align equiv.Pi_comm_symm Equiv.piComm_symmₓ'. -/ @[simp] theorem piComm_symm {α β} {φ : α → β → Sort _} : (piComm φ).symm = (piComm <| swap φ) := rfl #align equiv.Pi_comm_symm Equiv.piComm_symm #print Equiv.piCurry /- /-- Dependent `curry` equivalence: the type of dependent functions on `Σ i, β i` is equivalent to the type of dependent functions of two arguments (i.e., functions to the space of functions). This is `sigma.curry` and `sigma.uncurry` together as an equiv. -/ def piCurry {α} {β : α → Sort _} (γ : ∀ a, β a → Sort _) : (∀ x : Σi, β i, γ x.1 x.2) ≃ ∀ a b, γ a b where toFun := Sigma.curry invFun := Sigma.uncurry left_inv := Sigma.uncurry_curry right_inv := Sigma.curry_uncurry #align equiv.Pi_curry Equiv.piCurry -/ end section ProdCongr variable {α₁ β₁ β₂ : Type _} (e : α₁ → β₁ ≃ β₂) #print Equiv.prodCongrLeft /- /-- A family of equivalences `Π (a : α₁), β₁ ≃ β₂` generates an equivalence between `β₁ × α₁` and `β₂ × α₁`. -/ def prodCongrLeft : β₁ × α₁ ≃ β₂ × α₁ where toFun ab := ⟨e ab.2 ab.1, ab.2⟩ invFun ab := ⟨(e ab.2).symm ab.1, ab.2⟩ left_inv := by rintro ⟨a, b⟩ simp right_inv := by rintro ⟨a, b⟩ simp #align equiv.prod_congr_left Equiv.prodCongrLeft -/ /- warning: equiv.prod_congr_left_apply -> Equiv.prodCongrLeft_apply is a dubious translation: lean 3 declaration is forall {α₁ : Type.{u1}} {β₁ : Type.{u2}} {β₂ : Type.{u3}} (e : α₁ -> (Equiv.{succ u2, succ u3} β₁ β₂)) (b : β₁) (a : α₁), Eq.{max (succ u3) (succ u1)} (Prod.{u3, u1} β₂ α₁) (coeFn.{max 1 (max (max (succ u2) (succ u1)) (succ u3) (succ u1)) (max (succ u3) (succ u1)) (succ u2) (succ u1), max (max (succ u2) (succ u1)) (succ u3) (succ u1)} (Equiv.{max (succ u2) (succ u1), max (succ u3) (succ u1)} (Prod.{u2, u1} β₁ α₁) (Prod.{u3, u1} β₂ α₁)) (fun (_x : Equiv.{max (succ u2) (succ u1), max (succ u3) (succ u1)} (Prod.{u2, u1} β₁ α₁) (Prod.{u3, u1} β₂ α₁)) => (Prod.{u2, u1} β₁ α₁) -> (Prod.{u3, u1} β₂ α₁)) (Equiv.hasCoeToFun.{max (succ u2) (succ u1), max (succ u3) (succ u1)} (Prod.{u2, u1} β₁ α₁) (Prod.{u3, u1} β₂ α₁)) (Equiv.prodCongrLeft.{u1, u2, u3} α₁ β₁ β₂ e) (Prod.mk.{u2, u1} β₁ α₁ b a)) (Prod.mk.{u3, u1} β₂ α₁ (coeFn.{max 1 (max (succ u2) (succ u3)) (succ u3) (succ u2), max (succ u2) (succ u3)} (Equiv.{succ u2, succ u3} β₁ β₂) (fun (_x : Equiv.{succ u2, succ u3} β₁ β₂) => β₁ -> β₂) (Equiv.hasCoeToFun.{succ u2, succ u3} β₁ β₂) (e a) b) a) but is expected to have type forall {α₁ : Type.{u2}} {β₁ : Type.{u1}} {β₂ : Type.{u3}} (e : α₁ -> (Equiv.{succ u1, succ u3} β₁ β₂)) (b : β₁) (a : α₁), Eq.{max (succ u3) (succ u2)} ((fun ([email protected]._hyg.808 : Prod.{u1, u2} β₁ α₁) => Prod.{u3, u2} β₂ α₁) (Prod.mk.{u1, u2} β₁ α₁ b a)) (FunLike.coe.{max (max (succ u3) (succ u1)) (succ u2), max (succ u1) (succ u2), max (succ u3) (succ u2)} (Equiv.{max (succ u2) (succ u1), max (succ u2) (succ u3)} (Prod.{u1, u2} β₁ α₁) (Prod.{u3, u2} β₂ α₁)) (Prod.{u1, u2} β₁ α₁) (fun (_x : Prod.{u1, u2} β₁ α₁) => (fun ([email protected]._hyg.808 : Prod.{u1, u2} β₁ α₁) => Prod.{u3, u2} β₂ α₁) _x) (Equiv.instFunLikeEquiv.{max (succ u1) (succ u2), max (succ u3) (succ u2)} (Prod.{u1, u2} β₁ α₁) (Prod.{u3, u2} β₂ α₁)) (Equiv.prodCongrLeft.{u2, u1, u3} α₁ β₁ β₂ e) (Prod.mk.{u1, u2} β₁ α₁ b a)) (Prod.mk.{u3, u2} ((fun ([email protected]._hyg.808 : β₁) => β₂) b) α₁ (FunLike.coe.{max (succ u3) (succ u1), succ u1, succ u3} (Equiv.{succ u1, succ u3} β₁ β₂) β₁ (fun (_x : β₁) => (fun ([email protected]._hyg.808 : β₁) => β₂) _x) (Equiv.instFunLikeEquiv.{succ u1, succ u3} β₁ β₂) (e a) b) a) Case conversion may be inaccurate. Consider using '#align equiv.prod_congr_left_apply Equiv.prodCongrLeft_applyₓ'. -/ @[simp] theorem prodCongrLeft_apply (b : β₁) (a : α₁) : prodCongrLeft e (b, a) = (e a b, a) := rfl #align equiv.prod_congr_left_apply Equiv.prodCongrLeft_apply /- warning: equiv.prod_congr_refl_right -> Equiv.prodCongr_refl_right is a dubious translation: lean 3 declaration is forall {α₁ : Type.{u1}} {β₁ : Type.{u2}} {β₂ : Type.{u3}} (e : Equiv.{succ u2, succ u3} β₁ β₂), Eq.{max 1 (max (max (succ u2) (succ u1)) (succ u3) (succ u1)) (max (succ u3) (succ u1)) (succ u2) (succ u1)} (Equiv.{max (succ u2) (succ u1), max (succ u3) (succ u1)} (Prod.{u2, u1} β₁ α₁) (Prod.{u3, u1} β₂ α₁)) (Equiv.prodCongr.{u2, u1, u3, u1} β₁ α₁ β₂ α₁ e (Equiv.refl.{succ u1} α₁)) (Equiv.prodCongrLeft.{u1, u2, u3} α₁ β₁ β₂ (fun (_x : α₁) => e)) but is expected to have type forall {α₁ : Type.{u1}} {β₁ : Type.{u3}} {β₂ : Type.{u2}} (e : Equiv.{succ u3, succ u2} β₁ β₂), Eq.{max (max (succ u1) (succ u2)) (succ u3)} (Equiv.{max (succ u1) (succ u3), max (succ u1) (succ u2)} (Prod.{u3, u1} β₁ α₁) (Prod.{u2, u1} β₂ α₁)) (Equiv.prodCongr.{u3, u2, u1, u1} β₁ β₂ α₁ α₁ e (Equiv.refl.{succ u1} α₁)) (Equiv.prodCongrLeft.{u1, u3, u2} α₁ β₁ β₂ (fun (_x : α₁) => e)) Case conversion may be inaccurate. Consider using '#align equiv.prod_congr_refl_right Equiv.prodCongr_refl_rightₓ'. -/ theorem prodCongr_refl_right (e : β₁ ≃ β₂) : prodCongr e (Equiv.refl α₁) = prodCongrLeft fun _ => e := by ext ⟨a, b⟩ : 1 simp #align equiv.prod_congr_refl_right Equiv.prodCongr_refl_right #print Equiv.prodCongrRight /- /-- A family of equivalences `Π (a : α₁), β₁ ≃ β₂` generates an equivalence between `α₁ × β₁` and `α₁ × β₂`. -/ def prodCongrRight : α₁ × β₁ ≃ α₁ × β₂ where toFun ab := ⟨ab.1, e ab.1 ab.2⟩ invFun ab := ⟨ab.1, (e ab.1).symm ab.2⟩ left_inv := by rintro ⟨a, b⟩ simp right_inv := by rintro ⟨a, b⟩ simp #align equiv.prod_congr_right Equiv.prodCongrRight -/ /- warning: equiv.prod_congr_right_apply -> Equiv.prodCongrRight_apply is a dubious translation: lean 3 declaration is forall {α₁ : Type.{u1}} {β₁ : Type.{u2}} {β₂ : Type.{u3}} (e : α₁ -> (Equiv.{succ u2, succ u3} β₁ β₂)) (a : α₁) (b : β₁), Eq.{max (succ u1) (succ u3)} (Prod.{u1, u3} α₁ β₂) (coeFn.{max 1 (max (max (succ u1) (succ u2)) (succ u1) (succ u3)) (max (succ u1) (succ u3)) (succ u1) (succ u2), max (max (succ u1) (succ u2)) (succ u1) (succ u3)} (Equiv.{max (succ u1) (succ u2), max (succ u1) (succ u3)} (Prod.{u1, u2} α₁ β₁) (Prod.{u1, u3} α₁ β₂)) (fun (_x : Equiv.{max (succ u1) (succ u2), max (succ u1) (succ u3)} (Prod.{u1, u2} α₁ β₁) (Prod.{u1, u3} α₁ β₂)) => (Prod.{u1, u2} α₁ β₁) -> (Prod.{u1, u3} α₁ β₂)) (Equiv.hasCoeToFun.{max (succ u1) (succ u2), max (succ u1) (succ u3)} (Prod.{u1, u2} α₁ β₁) (Prod.{u1, u3} α₁ β₂)) (Equiv.prodCongrRight.{u1, u2, u3} α₁ β₁ β₂ e) (Prod.mk.{u1, u2} α₁ β₁ a b)) (Prod.mk.{u1, u3} α₁ β₂ a (coeFn.{max 1 (max (succ u2) (succ u3)) (succ u3) (succ u2), max (succ u2) (succ u3)} (Equiv.{succ u2, succ u3} β₁ β₂) (fun (_x : Equiv.{succ u2, succ u3} β₁ β₂) => β₁ -> β₂) (Equiv.hasCoeToFun.{succ u2, succ u3} β₁ β₂) (e a) b)) but is expected to have type forall {α₁ : Type.{u2}} {β₁ : Type.{u1}} {β₂ : Type.{u3}} (e : α₁ -> (Equiv.{succ u1, succ u3} β₁ β₂)) (a : α₁) (b : β₁), Eq.{max (succ u3) (succ u2)} ((fun ([email protected]._hyg.808 : Prod.{u2, u1} α₁ β₁) => Prod.{u2, u3} α₁ β₂) (Prod.mk.{u2, u1} α₁ β₁ a b)) (FunLike.coe.{max (max (succ u3) (succ u1)) (succ u2), max (succ u1) (succ u2), max (succ u3) (succ u2)} (Equiv.{max (succ u1) (succ u2), max (succ u3) (succ u2)} (Prod.{u2, u1} α₁ β₁) (Prod.{u2, u3} α₁ β₂)) (Prod.{u2, u1} α₁ β₁) (fun (_x : Prod.{u2, u1} α₁ β₁) => (fun ([email protected]._hyg.808 : Prod.{u2, u1} α₁ β₁) => Prod.{u2, u3} α₁ β₂) _x) (Equiv.instFunLikeEquiv.{max (succ u1) (succ u2), max (succ u3) (succ u2)} (Prod.{u2, u1} α₁ β₁) (Prod.{u2, u3} α₁ β₂)) (Equiv.prodCongrRight.{u2, u1, u3} α₁ β₁ β₂ e) (Prod.mk.{u2, u1} α₁ β₁ a b)) (Prod.mk.{u2, u3} α₁ ((fun ([email protected]._hyg.808 : β₁) => β₂) b) a (FunLike.coe.{max (succ u3) (succ u1), succ u1, succ u3} (Equiv.{succ u1, succ u3} β₁ β₂) β₁ (fun (_x : β₁) => (fun ([email protected]._hyg.808 : β₁) => β₂) _x) (Equiv.instFunLikeEquiv.{succ u1, succ u3} β₁ β₂) (e a) b)) Case conversion may be inaccurate. Consider using '#align equiv.prod_congr_right_apply Equiv.prodCongrRight_applyₓ'. -/ @[simp] theorem prodCongrRight_apply (a : α₁) (b : β₁) : prodCongrRight e (a, b) = (a, e a b) := rfl #align equiv.prod_congr_right_apply Equiv.prodCongrRight_apply /- warning: equiv.prod_congr_refl_left -> Equiv.prodCongr_refl_left is a dubious translation: lean 3 declaration is forall {α₁ : Type.{u1}} {β₁ : Type.{u2}} {β₂ : Type.{u3}} (e : Equiv.{succ u2, succ u3} β₁ β₂), Eq.{max 1 (max (max (succ u1) (succ u2)) (succ u1) (succ u3)) (max (succ u1) (succ u3)) (succ u1) (succ u2)} (Equiv.{max (succ u1) (succ u2), max (succ u1) (succ u3)} (Prod.{u1, u2} α₁ β₁) (Prod.{u1, u3} α₁ β₂)) (Equiv.prodCongr.{u1, u2, u1, u3} α₁ β₁ α₁ β₂ (Equiv.refl.{succ u1} α₁) e) (Equiv.prodCongrRight.{u1, u2, u3} α₁ β₁ β₂ (fun (_x : α₁) => e)) but is expected to have type forall {α₁ : Type.{u1}} {β₁ : Type.{u3}} {β₂ : Type.{u2}} (e : Equiv.{succ u3, succ u2} β₁ β₂), Eq.{max (max (succ u2) (succ u3)) (succ u1)} (Equiv.{max (succ u3) (succ u1), max (succ u2) (succ u1)} (Prod.{u1, u3} α₁ β₁) (Prod.{u1, u2} α₁ β₂)) (Equiv.prodCongr.{u1, u1, u3, u2} α₁ α₁ β₁ β₂ (Equiv.refl.{succ u1} α₁) e) (Equiv.prodCongrRight.{u1, u3, u2} α₁ β₁ β₂ (fun (_x : α₁) => e)) Case conversion may be inaccurate. Consider using '#align equiv.prod_congr_refl_left Equiv.prodCongr_refl_leftₓ'. -/ theorem prodCongr_refl_left (e : β₁ ≃ β₂) : prodCongr (Equiv.refl α₁) e = prodCongrRight fun _ => e := by ext ⟨a, b⟩ : 1 simp #align equiv.prod_congr_refl_left Equiv.prodCongr_refl_left #print Equiv.prodCongrLeft_trans_prodComm /- @[simp] theorem prodCongrLeft_trans_prodComm : (prodCongrLeft e).trans (prodComm _ _) = (prodComm _ _).trans (prodCongrRight e) := by ext ⟨a, b⟩ : 1 simp #align equiv.prod_congr_left_trans_prod_comm Equiv.prodCongrLeft_trans_prodComm -/ #print Equiv.prodCongrRight_trans_prodComm /- @[simp] theorem prodCongrRight_trans_prodComm : (prodCongrRight e).trans (prodComm _ _) = (prodComm _ _).trans (prodCongrLeft e) := by ext ⟨a, b⟩ : 1 simp #align equiv.prod_congr_right_trans_prod_comm Equiv.prodCongrRight_trans_prodComm -/ #print Equiv.sigmaCongrRight_sigmaEquivProd /- theorem sigmaCongrRight_sigmaEquivProd : (sigmaCongrRight e).trans (sigmaEquivProd α₁ β₂) = (sigmaEquivProd α₁ β₁).trans (prodCongrRight e) := by ext ⟨a, b⟩ : 1 simp #align equiv.sigma_congr_right_sigma_equiv_prod Equiv.sigmaCongrRight_sigmaEquivProd -/ /- warning: equiv.sigma_equiv_prod_sigma_congr_right -> Equiv.sigmaEquivProd_sigmaCongrRight is a dubious translation: lean 3 declaration is forall {α₁ : Type.{u1}} {β₁ : Type.{u2}} {β₂ : Type.{u3}} (e : α₁ -> (Equiv.{succ u2, succ u3} β₁ β₂)), Eq.{max 1 (max (max (succ u1) (succ u2)) (succ u1) (succ u3)) (max (succ u1) (succ u3)) (succ u1) (succ u2)} (Equiv.{max (succ u1) (succ u2), max (succ u1) (succ u3)} (Prod.{u1, u2} α₁ β₁) (Sigma.{u1, u3} α₁ (fun (a : α₁) => β₂))) (Equiv.trans.{max (succ u1) (succ u2), max (succ u1) (succ u2), max (succ u1) (succ u3)} (Prod.{u1, u2} α₁ β₁) (Sigma.{u1, u2} α₁ (fun (_x : α₁) => β₁)) (Sigma.{u1, u3} α₁ (fun (a : α₁) => β₂)) (Equiv.symm.{max (succ u1) (succ u2), max (succ u1) (succ u2)} (Sigma.{u1, u2} α₁ (fun (_x : α₁) => β₁)) (Prod.{u1, u2} α₁ β₁) (Equiv.sigmaEquivProd.{u1, u2} α₁ β₁)) (Equiv.sigmaCongrRight.{u1, u2, u3} α₁ (fun (_x : α₁) => β₁) (fun (ᾰ : α₁) => β₂) e)) (Equiv.trans.{max (succ u1) (succ u2), max (succ u1) (succ u3), max (succ u1) (succ u3)} (Prod.{u1, u2} α₁ β₁) (Prod.{u1, u3} α₁ β₂) (Sigma.{u1, u3} α₁ (fun (a : α₁) => β₂)) (Equiv.prodCongrRight.{u1, u2, u3} α₁ β₁ β₂ e) (Equiv.symm.{max (succ u1) (succ u3), max (succ u1) (succ u3)} (Sigma.{u1, u3} α₁ (fun (_x : α₁) => β₂)) (Prod.{u1, u3} α₁ β₂) (Equiv.sigmaEquivProd.{u1, u3} α₁ β₂))) but is expected to have type forall {α₁ : Type.{u2}} {β₁ : Type.{u3}} {β₂ : Type.{u1}} (e : α₁ -> (Equiv.{succ u3, succ u1} β₁ β₂)), Eq.{max (max (succ u3) (succ u2)) (succ u1)} (Equiv.{max (succ u3) (succ u2), max (succ u2) (succ u1)} (Prod.{u2, u3} α₁ β₁) (Sigma.{u2, u1} α₁ (fun (a : α₁) => β₂))) (Equiv.trans.{max (succ u3) (succ u2), max (succ u3) (succ u2), max (succ u2) (succ u1)} (Prod.{u2, u3} α₁ β₁) (Sigma.{u2, u3} α₁ (fun (_x : α₁) => β₁)) (Sigma.{u2, u1} α₁ (fun (a : α₁) => β₂)) (Equiv.symm.{max (succ u3) (succ u2), max (succ u3) (succ u2)} (Sigma.{u2, u3} α₁ (fun (_x : α₁) => β₁)) (Prod.{u2, u3} α₁ β₁) (Equiv.sigmaEquivProd.{u2, u3} α₁ β₁)) (Equiv.sigmaCongrRight.{u2, u3, u1} α₁ (fun (_x : α₁) => β₁) (fun (ᾰ : α₁) => β₂) e)) (Equiv.trans.{max (succ u3) (succ u2), max (succ u2) (succ u1), max (succ u2) (succ u1)} (Prod.{u2, u3} α₁ β₁) (Prod.{u2, u1} α₁ β₂) (Sigma.{u2, u1} α₁ (fun (a : α₁) => β₂)) (Equiv.prodCongrRight.{u2, u3, u1} α₁ β₁ β₂ e) (Equiv.symm.{max (succ u2) (succ u1), max (succ u2) (succ u1)} (Sigma.{u2, u1} α₁ (fun (_x : α₁) => β₂)) (Prod.{u2, u1} α₁ β₂) (Equiv.sigmaEquivProd.{u2, u1} α₁ β₂))) Case conversion may be inaccurate. Consider using '#align equiv.sigma_equiv_prod_sigma_congr_right Equiv.sigmaEquivProd_sigmaCongrRightₓ'. -/ theorem sigmaEquivProd_sigmaCongrRight : (sigmaEquivProd α₁ β₁).symm.trans (sigmaCongrRight e) = (prodCongrRight e).trans (sigmaEquivProd α₁ β₂).symm := by ext ⟨a, b⟩ : 1 simp #align equiv.sigma_equiv_prod_sigma_congr_right Equiv.sigmaEquivProd_sigmaCongrRight /- warning: equiv.of_fiber_equiv -> Equiv.ofFiberEquiv is a dubious translation: lean 3 declaration is forall {α : Type.{u1}} {β : Type.{u2}} {γ : Type.{u3}} {f : α -> γ} {g : β -> γ}, (forall (c : γ), Equiv.{succ u1, succ u2} (Subtype.{succ u1} α (fun (a : α) => Eq.{succ u3} γ (f a) c)) (Subtype.{succ u2} β (fun (b : β) => Eq.{succ u3} γ (g b) c))) -> (Equiv.{succ u1, succ u2} α β) but is expected to have type forall {α : Type.{u1}} {β : Type.{u2}} {γ : Type.{u3}} {f : α -> β} {g : γ -> β}, (forall (c : β), Equiv.{succ u1, succ u3} (Subtype.{succ u1} α (fun (a : α) => Eq.{succ u2} β (f a) c)) (Subtype.{succ u3} γ (fun (b : γ) => Eq.{succ u2} β (g b) c))) -> (Equiv.{succ u1, succ u3} α γ) Case conversion may be inaccurate. Consider using '#align equiv.of_fiber_equiv Equiv.ofFiberEquivₓ'. -/ -- See also `equiv.of_preimage_equiv`. /-- A family of equivalences between fibers gives an equivalence between domains. -/ @[simps] def ofFiberEquiv {α β γ : Type _} {f : α → γ} {g : β → γ} (e : ∀ c, { a // f a = c } ≃ { b // g b = c }) : α ≃ β := (sigmaFiberEquiv f).symm.trans <| (Equiv.sigmaCongrRight e).trans (sigmaFiberEquiv g) #align equiv.of_fiber_equiv Equiv.ofFiberEquiv /- warning: equiv.of_fiber_equiv_map -> Equiv.ofFiberEquiv_map is a dubious translation: lean 3 declaration is forall {α : Type.{u1}} {β : Type.{u2}} {γ : Type.{u3}} {f : α -> γ} {g : β -> γ} (e : forall (c : γ), Equiv.{succ u1, succ u2} (Subtype.{succ u1} α (fun (a : α) => Eq.{succ u3} γ (f a) c)) (Subtype.{succ u2} β (fun (b : β) => Eq.{succ u3} γ (g b) c))) (a : α), Eq.{succ u3} γ (g (coeFn.{max 1 (max (succ u1) (succ u2)) (succ u2) (succ u1), max (succ u1) (succ u2)} (Equiv.{succ u1, succ u2} α β) (fun (_x : Equiv.{succ u1, succ u2} α β) => α -> β) (Equiv.hasCoeToFun.{succ u1, succ u2} α β) (Equiv.ofFiberEquiv.{u1, u2, u3} α β γ (fun (a : α) => f a) (fun (b : β) => g b) e) a)) (f a) but is expected to have type forall {α : Type.{u3}} {β : Type.{u2}} {γ : Type.{u1}} {f : α -> γ} {g : β -> γ} (e : forall (c : γ), Equiv.{succ u3, succ u2} (Subtype.{succ u3} α (fun (a : α) => Eq.{succ u1} γ (f a) c)) (Subtype.{succ u2} β (fun (b : β) => Eq.{succ u1} γ (g b) c))) (a : α), Eq.{succ u1} γ (g (FunLike.coe.{max (succ u2) (succ u3), succ u3, succ u2} (Equiv.{succ u3, succ u2} α β) α (fun (_x : α) => (fun ([email protected]._hyg.808 : α) => β) _x) (Equiv.instFunLikeEquiv.{succ u3, succ u2} α β) (Equiv.ofFiberEquiv.{u3, u1, u2} α γ β (fun (a : α) => f a) (fun (b : β) => g b) e) a)) (f a) Case conversion may be inaccurate. Consider using '#align equiv.of_fiber_equiv_map Equiv.ofFiberEquiv_mapₓ'. -/ theorem ofFiberEquiv_map {α β γ} {f : α → γ} {g : β → γ} (e : ∀ c, { a // f a = c } ≃ { b // g b = c }) (a : α) : g (ofFiberEquiv e a) = f a := (_ : { b // g b = _ }).Prop #align equiv.of_fiber_equiv_map Equiv.ofFiberEquiv_map /- warning: equiv.prod_shear -> Equiv.prodShear is a dubious translation: lean 3 declaration is forall {α₁ : Type.{u1}} {β₁ : Type.{u2}} {α₂ : Type.{u3}} {β₂ : Type.{u4}}, (Equiv.{succ u1, succ u3} α₁ α₂) -> (α₁ -> (Equiv.{succ u2, succ u4} β₁ β₂)) -> (Equiv.{max (succ u1) (succ u2), max (succ u3) (succ u4)} (Prod.{u1, u2} α₁ β₁) (Prod.{u3, u4} α₂ β₂)) but is expected to have type forall {α₁ : Type.{u1}} {β₁ : Type.{u2}} {α₂ : Type.{u3}} {β₂ : Type.{u4}}, (Equiv.{succ u1, succ u4} α₁ β₂) -> (α₁ -> (Equiv.{succ u2, succ u3} β₁ α₂)) -> (Equiv.{max (succ u2) (succ u1), max (succ u3) (succ u4)} (Prod.{u1, u2} α₁ β₁) (Prod.{u4, u3} β₂ α₂)) Case conversion may be inaccurate. Consider using '#align equiv.prod_shear Equiv.prodShearₓ'. -/ /-- A variation on `equiv.prod_congr` where the equivalence in the second component can depend on the first component. A typical example is a shear mapping, explaining the name of this declaration. -/ @[simps (config := { fullyApplied := false })] def prodShear {α₁ β₁ α₂ β₂ : Type _} (e₁ : α₁ ≃ α₂) (e₂ : α₁ → β₁ ≃ β₂) : α₁ × β₁ ≃ α₂ × β₂ where toFun := fun x : α₁ × β₁ => (e₁ x.1, e₂ x.1 x.2) invFun := fun y : α₂ × β₂ => (e₁.symm y.1, (e₂ <| e₁.symm y.1).symm y.2) left_inv := by rintro ⟨x₁, y₁⟩ simp only [symm_apply_apply] right_inv := by rintro ⟨x₁, y₁⟩ simp only [apply_symm_apply] #align equiv.prod_shear Equiv.prodShear end ProdCongr namespace Perm variable {α₁ β₁ β₂ : Type _} [DecidableEq α₁] (a : α₁) (e : Perm β₁) #print Equiv.Perm.prodExtendRight /- /-- `prod_extend_right a e` extends `e : perm β` to `perm (α × β)` by sending `(a, b)` to `(a, e b)` and keeping the other `(a', b)` fixed. -/ def prodExtendRight : Perm (α₁ × β₁) where toFun ab := if ab.fst = a then (a, e ab.snd) else ab invFun ab := if ab.fst = a then (a, e.symm ab.snd) else ab left_inv := by rintro ⟨k', x⟩ dsimp only split_ifs with h <;> simp [h] right_inv := by rintro ⟨k', x⟩ dsimp only split_ifs with h <;> simp [h] #align equiv.perm.prod_extend_right Equiv.Perm.prodExtendRight -/ #print Equiv.Perm.prodExtendRight_apply_eq /- @[simp] theorem prodExtendRight_apply_eq (b : β₁) : prodExtendRight a e (a, b) = (a, e b) := if_pos rfl #align equiv.perm.prod_extend_right_apply_eq Equiv.Perm.prodExtendRight_apply_eq -/ /- warning: equiv.perm.prod_extend_right_apply_ne -> Equiv.Perm.prodExtendRight_apply_ne is a dubious translation: lean 3 declaration is forall {α₁ : Type.{u1}} {β₁ : Type.{u2}} [_inst_1 : DecidableEq.{succ u1} α₁] (e : Equiv.Perm.{succ u2} β₁) {a : α₁} {a' : α₁}, (Ne.{succ u1} α₁ a' a) -> (forall (b : β₁), Eq.{max (succ u1) (succ u2)} (Prod.{u1, u2} α₁ β₁) (coeFn.{max 1 (succ u1) (succ u2), max (succ u1) (succ u2)} (Equiv.Perm.{max (succ u1) (succ u2)} (Prod.{u1, u2} α₁ β₁)) (fun (_x : Equiv.{max (succ u1) (succ u2), max (succ u1) (succ u2)} (Prod.{u1, u2} α₁ β₁) (Prod.{u1, u2} α₁ β₁)) => (Prod.{u1, u2} α₁ β₁) -> (Prod.{u1, u2} α₁ β₁)) (Equiv.hasCoeToFun.{max (succ u1) (succ u2), max (succ u1) (succ u2)} (Prod.{u1, u2} α₁ β₁) (Prod.{u1, u2} α₁ β₁)) (Equiv.Perm.prodExtendRight.{u1, u2} α₁ β₁ (fun (a : α₁) (b : α₁) => _inst_1 a b) a e) (Prod.mk.{u1, u2} α₁ β₁ a' b)) (Prod.mk.{u1, u2} α₁ β₁ a' b)) but is expected to have type forall {α₁ : Type.{u2}} {β₁ : Type.{u1}} [_inst_1 : DecidableEq.{succ u2} α₁] (e : Equiv.Perm.{succ u1} β₁) {a : α₁} {a' : α₁}, (Ne.{succ u2} α₁ a' a) -> (forall (b : β₁), Eq.{max (succ u1) (succ u2)} ((fun ([email protected]._hyg.808 : Prod.{u2, u1} α₁ β₁) => Prod.{u2, u1} α₁ β₁) (Prod.mk.{u2, u1} α₁ β₁ a' b)) (FunLike.coe.{max (succ u1) (succ u2), max (succ u1) (succ u2), max (succ u1) (succ u2)} (Equiv.Perm.{max (succ u1) (succ u2)} (Prod.{u2, u1} α₁ β₁)) (Prod.{u2, u1} α₁ β₁) (fun (_x : Prod.{u2, u1} α₁ β₁) => (fun ([email protected]._hyg.808 : Prod.{u2, u1} α₁ β₁) => Prod.{u2, u1} α₁ β₁) _x) (Equiv.instFunLikeEquiv.{max (succ u1) (succ u2), max (succ u1) (succ u2)} (Prod.{u2, u1} α₁ β₁) (Prod.{u2, u1} α₁ β₁)) (Equiv.Perm.prodExtendRight.{u2, u1} α₁ β₁ (fun (a : α₁) (b : α₁) => _inst_1 a b) a e) (Prod.mk.{u2, u1} α₁ β₁ a' b)) (Prod.mk.{u2, u1} α₁ β₁ a' b)) Case conversion may be inaccurate. Consider using '#align equiv.perm.prod_extend_right_apply_ne Equiv.Perm.prodExtendRight_apply_neₓ'. -/ theorem prodExtendRight_apply_ne {a a' : α₁} (h : a' ≠ a) (b : β₁) : prodExtendRight a e (a', b) = (a', b) := if_neg h #align equiv.perm.prod_extend_right_apply_ne Equiv.Perm.prodExtendRight_apply_ne #print Equiv.Perm.eq_of_prodExtendRight_ne /- theorem eq_of_prodExtendRight_ne {e : Perm β₁} {a a' : α₁} {b : β₁} (h : prodExtendRight a e (a', b) ≠ (a', b)) : a' = a := by contrapose! h exact prod_extend_right_apply_ne _ h _ #align equiv.perm.eq_of_prod_extend_right_ne Equiv.Perm.eq_of_prodExtendRight_ne -/ /- warning: equiv.perm.fst_prod_extend_right -> Equiv.Perm.fst_prodExtendRight is a dubious translation: lean 3 declaration is forall {α₁ : Type.{u1}} {β₁ : Type.{u2}} [_inst_1 : DecidableEq.{succ u1} α₁] (a : α₁) (e : Equiv.Perm.{succ u2} β₁) (ab : Prod.{u1, u2} α₁ β₁), Eq.{succ u1} α₁ (Prod.fst.{u1, u2} α₁ β₁ (coeFn.{max 1 (succ u1) (succ u2), max (succ u1) (succ u2)} (Equiv.Perm.{max (succ u1) (succ u2)} (Prod.{u1, u2} α₁ β₁)) (fun (_x : Equiv.{max (succ u1) (succ u2), max (succ u1) (succ u2)} (Prod.{u1, u2} α₁ β₁) (Prod.{u1, u2} α₁ β₁)) => (Prod.{u1, u2} α₁ β₁) -> (Prod.{u1, u2} α₁ β₁)) (Equiv.hasCoeToFun.{max (succ u1) (succ u2), max (succ u1) (succ u2)} (Prod.{u1, u2} α₁ β₁) (Prod.{u1, u2} α₁ β₁)) (Equiv.Perm.prodExtendRight.{u1, u2} α₁ β₁ (fun (a : α₁) (b : α₁) => _inst_1 a b) a e) ab)) (Prod.fst.{u1, u2} α₁ β₁ ab) but is expected to have type forall {α₁ : Type.{u2}} {β₁ : Type.{u1}} [_inst_1 : DecidableEq.{succ u2} α₁] (a : α₁) (e : Equiv.Perm.{succ u1} β₁) (ab : Prod.{u2, u1} α₁ β₁), Eq.{succ u2} α₁ (Prod.fst.{u2, u1} α₁ β₁ (FunLike.coe.{max (succ u1) (succ u2), max (succ u1) (succ u2), max (succ u1) (succ u2)} (Equiv.Perm.{max (succ u1) (succ u2)} (Prod.{u2, u1} α₁ β₁)) (Prod.{u2, u1} α₁ β₁) (fun (_x : Prod.{u2, u1} α₁ β₁) => (fun ([email protected]._hyg.808 : Prod.{u2, u1} α₁ β₁) => Prod.{u2, u1} α₁ β₁) _x) (Equiv.instFunLikeEquiv.{max (succ u1) (succ u2), max (succ u1) (succ u2)} (Prod.{u2, u1} α₁ β₁) (Prod.{u2, u1} α₁ β₁)) (Equiv.Perm.prodExtendRight.{u2, u1} α₁ β₁ (fun (a : α₁) (b : α₁) => _inst_1 a b) a e) ab)) (Prod.fst.{u2, u1} α₁ β₁ ab) Case conversion may be inaccurate. Consider using '#align equiv.perm.fst_prod_extend_right Equiv.Perm.fst_prodExtendRightₓ'. -/ @[simp] theorem fst_prodExtendRight (ab : α₁ × β₁) : (prodExtendRight a e ab).fst = ab.fst := by rw [prod_extend_right, [anonymous]] split_ifs with h · rw [h] · rfl #align equiv.perm.fst_prod_extend_right Equiv.Perm.fst_prodExtendRight end Perm section #print Equiv.arrowProdEquivProdArrow /- /-- The type of functions to a product `α × β` is equivalent to the type of pairs of functions `γ → α` and `γ → β`. -/ def arrowProdEquivProdArrow (α β γ : Type _) : (γ → α × β) ≃ (γ → α) × (γ → β) := ⟨fun f => (fun c => (f c).1, fun c => (f c).2), fun p c => (p.1 c, p.2 c), fun f => funext fun c => Prod.mk.eta, fun p => by cases p rfl⟩ #align equiv.arrow_prod_equiv_prod_arrow Equiv.arrowProdEquivProdArrow -/ open Sum #print Equiv.sumArrowEquivProdArrow /- /-- The type of functions on a sum type `α ⊕ β` is equivalent to the type of pairs of functions on `α` and on `β`. -/ def sumArrowEquivProdArrow (α β γ : Type _) : (Sum α β → γ) ≃ (α → γ) × (β → γ) := ⟨fun f => (f ∘ inl, f ∘ inr), fun p => Sum.elim p.1 p.2, fun f => by ext ⟨⟩ <;> rfl, fun p => by cases p rfl⟩ #align equiv.sum_arrow_equiv_prod_arrow Equiv.sumArrowEquivProdArrow -/ /- warning: equiv.sum_arrow_equiv_prod_arrow_apply_fst -> Equiv.sumArrowEquivProdArrow_apply_fst is a dubious translation: lean 3 declaration is forall {α : Type.{u1}} {β : Type.{u2}} {γ : Type.{u3}} (f : (Sum.{u1, u2} α β) -> γ) (a : α), Eq.{succ u3} γ (Prod.fst.{max u1 u3, max u2 u3} (α -> γ) (β -> γ) (coeFn.{max 1 (max (max (max (succ u1) (succ u2)) (succ u3)) (succ (max u1 u3)) (succ (max u2 u3))) (max (succ (max u1 u3)) (succ (max u2 u3))) (max (succ u1) (succ u2)) (succ u3), max (max (max (succ u1) (succ u2)) (succ u3)) (succ (max u1 u3)) (succ (max u2 u3))} (Equiv.{max (max (succ u1) (succ u2)) (succ u3), max (succ (max u1 u3)) (succ (max u2 u3))} ((Sum.{u1, u2} α β) -> γ) (Prod.{max u1 u3, max u2 u3} (α -> γ) (β -> γ))) (fun (_x : Equiv.{max (max (succ u1) (succ u2)) (succ u3), max (succ (max u1 u3)) (succ (max u2 u3))} ((Sum.{u1, u2} α β) -> γ) (Prod.{max u1 u3, max u2 u3} (α -> γ) (β -> γ))) => ((Sum.{u1, u2} α β) -> γ) -> (Prod.{max u1 u3, max u2 u3} (α -> γ) (β -> γ))) (Equiv.hasCoeToFun.{max (max (succ u1) (succ u2)) (succ u3), max (succ (max u1 u3)) (succ (max u2 u3))} ((Sum.{u1, u2} α β) -> γ) (Prod.{max u1 u3, max u2 u3} (α -> γ) (β -> γ))) (Equiv.sumArrowEquivProdArrow.{u1, u2, u3} α β γ) f) a) (f (Sum.inl.{u1, u2} α β a)) but is expected to have type forall {α : Type.{u3}} {β : Type.{u2}} {γ : Type.{u1}} (f : (Sum.{u3, u2} α β) -> γ) (a : α), Eq.{succ u1} γ (Prod.fst.{max u3 u1, max u2 u1} (α -> γ) (β -> γ) (FunLike.coe.{max (max (succ u2) (succ u3)) (succ u1), max (max (succ u2) (succ u3)) (succ u1), max (max (succ u2) (succ u3)) (succ u1)} (Equiv.{max (max (succ u3) (succ u2)) (succ u1), max (succ (max u2 u1)) (succ (max u3 u1))} ((Sum.{u3, u2} α β) -> γ) (Prod.{max u3 u1, max u2 u1} (α -> γ) (β -> γ))) ((Sum.{u3, u2} α β) -> γ) (fun (_x : (Sum.{u3, u2} α β) -> γ) => (fun ([email protected]._hyg.808 : (Sum.{u3, u2} α β) -> γ) => Prod.{max u3 u1, max u2 u1} (α -> γ) (β -> γ)) _x) (Equiv.instFunLikeEquiv.{max (max (succ u2) (succ u3)) (succ u1), max (max (succ u2) (succ u3)) (succ u1)} ((Sum.{u3, u2} α β) -> γ) (Prod.{max u3 u1, max u2 u1} (α -> γ) (β -> γ))) (Equiv.sumArrowEquivProdArrow.{u3, u2, u1} α β γ) f) a) (f (Sum.inl.{u3, u2} α β a)) Case conversion may be inaccurate. Consider using '#align equiv.sum_arrow_equiv_prod_arrow_apply_fst Equiv.sumArrowEquivProdArrow_apply_fstₓ'. -/ @[simp] theorem sumArrowEquivProdArrow_apply_fst {α β γ} (f : Sum α β → γ) (a : α) : (sumArrowEquivProdArrow α β γ f).1 a = f (inl a) := rfl #align equiv.sum_arrow_equiv_prod_arrow_apply_fst Equiv.sumArrowEquivProdArrow_apply_fst /- warning: equiv.sum_arrow_equiv_prod_arrow_apply_snd -> Equiv.sumArrowEquivProdArrow_apply_snd is a dubious translation: lean 3 declaration is forall {α : Type.{u1}} {β : Type.{u2}} {γ : Type.{u3}} (f : (Sum.{u1, u2} α β) -> γ) (b : β), Eq.{succ u3} γ (Prod.snd.{max u1 u3, max u2 u3} (α -> γ) (β -> γ) (coeFn.{max 1 (max (max (max (succ u1) (succ u2)) (succ u3)) (succ (max u1 u3)) (succ (max u2 u3))) (max (succ (max u1 u3)) (succ (max u2 u3))) (max (succ u1) (succ u2)) (succ u3), max (max (max (succ u1) (succ u2)) (succ u3)) (succ (max u1 u3)) (succ (max u2 u3))} (Equiv.{max (max (succ u1) (succ u2)) (succ u3), max (succ (max u1 u3)) (succ (max u2 u3))} ((Sum.{u1, u2} α β) -> γ) (Prod.{max u1 u3, max u2 u3} (α -> γ) (β -> γ))) (fun (_x : Equiv.{max (max (succ u1) (succ u2)) (succ u3), max (succ (max u1 u3)) (succ (max u2 u3))} ((Sum.{u1, u2} α β) -> γ) (Prod.{max u1 u3, max u2 u3} (α -> γ) (β -> γ))) => ((Sum.{u1, u2} α β) -> γ) -> (Prod.{max u1 u3, max u2 u3} (α -> γ) (β -> γ))) (Equiv.hasCoeToFun.{max (max (succ u1) (succ u2)) (succ u3), max (succ (max u1 u3)) (succ (max u2 u3))} ((Sum.{u1, u2} α β) -> γ) (Prod.{max u1 u3, max u2 u3} (α -> γ) (β -> γ))) (Equiv.sumArrowEquivProdArrow.{u1, u2, u3} α β γ) f) b) (f (Sum.inr.{u1, u2} α β b)) but is expected to have type forall {α : Type.{u3}} {β : Type.{u2}} {γ : Type.{u1}} (f : (Sum.{u3, u2} α β) -> γ) (b : β), Eq.{succ u1} γ (Prod.snd.{max u3 u1, max u2 u1} (α -> γ) (β -> γ) (FunLike.coe.{max (max (succ u2) (succ u3)) (succ u1), max (max (succ u2) (succ u3)) (succ u1), max (max (succ u2) (succ u3)) (succ u1)} (Equiv.{max (max (succ u3) (succ u2)) (succ u1), max (succ (max u2 u1)) (succ (max u3 u1))} ((Sum.{u3, u2} α β) -> γ) (Prod.{max u3 u1, max u2 u1} (α -> γ) (β -> γ))) ((Sum.{u3, u2} α β) -> γ) (fun (_x : (Sum.{u3, u2} α β) -> γ) => (fun ([email protected]._hyg.808 : (Sum.{u3, u2} α β) -> γ) => Prod.{max u3 u1, max u2 u1} (α -> γ) (β -> γ)) _x) (Equiv.instFunLikeEquiv.{max (max (succ u2) (succ u3)) (succ u1), max (max (succ u2) (succ u3)) (succ u1)} ((Sum.{u3, u2} α β) -> γ) (Prod.{max u3 u1, max u2 u1} (α -> γ) (β -> γ))) (Equiv.sumArrowEquivProdArrow.{u3, u2, u1} α β γ) f) b) (f (Sum.inr.{u3, u2} α β b)) Case conversion may be inaccurate. Consider using '#align equiv.sum_arrow_equiv_prod_arrow_apply_snd Equiv.sumArrowEquivProdArrow_apply_sndₓ'. -/ @[simp] theorem sumArrowEquivProdArrow_apply_snd {α β γ} (f : Sum α β → γ) (b : β) : (sumArrowEquivProdArrow α β γ f).2 b = f (inr b) := rfl #align equiv.sum_arrow_equiv_prod_arrow_apply_snd Equiv.sumArrowEquivProdArrow_apply_snd /- warning: equiv.sum_arrow_equiv_prod_arrow_symm_apply_inl -> Equiv.sumArrowEquivProdArrow_symm_apply_inl is a dubious translation: lean 3 declaration is forall {α : Type.{u1}} {β : Type.{u2}} {γ : Type.{u3}} (f : α -> γ) (g : β -> γ) (a : α), Eq.{succ u3} γ (coeFn.{max 1 (max (max (succ (max u1 u3)) (succ (max u2 u3))) (max (succ u1) (succ u2)) (succ u3)) (max (max (succ u1) (succ u2)) (succ u3)) (succ (max u1 u3)) (succ (max u2 u3)), max (max (succ (max u1 u3)) (succ (max u2 u3))) (max (succ u1) (succ u2)) (succ u3)} (Equiv.{max (succ (max u1 u3)) (succ (max u2 u3)), max (max (succ u1) (succ u2)) (succ u3)} (Prod.{max u1 u3, max u2 u3} (α -> γ) (β -> γ)) ((Sum.{u1, u2} α β) -> γ)) (fun (_x : Equiv.{max (succ (max u1 u3)) (succ (max u2 u3)), max (max (succ u1) (succ u2)) (succ u3)} (Prod.{max u1 u3, max u2 u3} (α -> γ) (β -> γ)) ((Sum.{u1, u2} α β) -> γ)) => (Prod.{max u1 u3, max u2 u3} (α -> γ) (β -> γ)) -> (Sum.{u1, u2} α β) -> γ) (Equiv.hasCoeToFun.{max (succ (max u1 u3)) (succ (max u2 u3)), max (max (succ u1) (succ u2)) (succ u3)} (Prod.{max u1 u3, max u2 u3} (α -> γ) (β -> γ)) ((Sum.{u1, u2} α β) -> γ)) (Equiv.symm.{max (max (succ u1) (succ u2)) (succ u3), max (succ (max u1 u3)) (succ (max u2 u3))} ((Sum.{u1, u2} α β) -> γ) (Prod.{max u1 u3, max u2 u3} (α -> γ) (β -> γ)) (Equiv.sumArrowEquivProdArrow.{u1, u2, u3} α β γ)) (Prod.mk.{max u1 u3, max u2 u3} (α -> γ) (β -> γ) f g) (Sum.inl.{u1, u2} α β a)) (f a) but is expected to have type forall {α : Type.{u3}} {β : Type.{u2}} {γ : Type.{u1}} (f : α -> β) (g : γ -> β) (a : α), Eq.{succ u2} β (FunLike.coe.{max (max (succ u2) (succ u1)) (succ u3), max (max (succ u2) (succ u1)) (succ u3), max (max (succ u2) (succ u1)) (succ u3)} (Equiv.{max (max (succ u2) (succ u1)) (succ u3), max (max (succ u2) (succ u1)) (succ u3)} (Prod.{max u3 u2, max u1 u2} (α -> β) (γ -> β)) ((Sum.{u3, u1} α γ) -> β)) (Prod.{max u3 u2, max u1 u2} (α -> β) (γ -> β)) (fun (_x : Prod.{max u3 u2, max u1 u2} (α -> β) (γ -> β)) => (fun ([email protected]._hyg.808 : Prod.{max u3 u2, max u1 u2} (α -> β) (γ -> β)) => (Sum.{u3, u1} α γ) -> β) _x) (Equiv.instFunLikeEquiv.{max (max (succ u2) (succ u1)) (succ u3), max (max (succ u2) (succ u1)) (succ u3)} (Prod.{max u3 u2, max u1 u2} (α -> β) (γ -> β)) ((Sum.{u3, u1} α γ) -> β)) (Equiv.symm.{max (max (succ u2) (succ u1)) (succ u3), max (max (succ u2) (succ u1)) (succ u3)} ((Sum.{u3, u1} α γ) -> β) (Prod.{max u3 u2, max u1 u2} (α -> β) (γ -> β)) (Equiv.sumArrowEquivProdArrow.{u3, u1, u2} α γ β)) (Prod.mk.{max u2 u3, max u2 u1} (α -> β) (γ -> β) f g) (Sum.inl.{u3, u1} α γ a)) (f a) Case conversion may be inaccurate. Consider using '#align equiv.sum_arrow_equiv_prod_arrow_symm_apply_inl Equiv.sumArrowEquivProdArrow_symm_apply_inlₓ'. -/ @[simp] theorem sumArrowEquivProdArrow_symm_apply_inl {α β γ} (f : α → γ) (g : β → γ) (a : α) : ((sumArrowEquivProdArrow α β γ).symm (f, g)) (inl a) = f a := rfl #align equiv.sum_arrow_equiv_prod_arrow_symm_apply_inl Equiv.sumArrowEquivProdArrow_symm_apply_inl /- warning: equiv.sum_arrow_equiv_prod_arrow_symm_apply_inr -> Equiv.sumArrowEquivProdArrow_symm_apply_inr is a dubious translation: lean 3 declaration is forall {α : Type.{u1}} {β : Type.{u2}} {γ : Type.{u3}} (f : α -> γ) (g : β -> γ) (b : β), Eq.{succ u3} γ (coeFn.{max 1 (max (max (succ (max u1 u3)) (succ (max u2 u3))) (max (succ u1) (succ u2)) (succ u3)) (max (max (succ u1) (succ u2)) (succ u3)) (succ (max u1 u3)) (succ (max u2 u3)), max (max (succ (max u1 u3)) (succ (max u2 u3))) (max (succ u1) (succ u2)) (succ u3)} (Equiv.{max (succ (max u1 u3)) (succ (max u2 u3)), max (max (succ u1) (succ u2)) (succ u3)} (Prod.{max u1 u3, max u2 u3} (α -> γ) (β -> γ)) ((Sum.{u1, u2} α β) -> γ)) (fun (_x : Equiv.{max (succ (max u1 u3)) (succ (max u2 u3)), max (max (succ u1) (succ u2)) (succ u3)} (Prod.{max u1 u3, max u2 u3} (α -> γ) (β -> γ)) ((Sum.{u1, u2} α β) -> γ)) => (Prod.{max u1 u3, max u2 u3} (α -> γ) (β -> γ)) -> (Sum.{u1, u2} α β) -> γ) (Equiv.hasCoeToFun.{max (succ (max u1 u3)) (succ (max u2 u3)), max (max (succ u1) (succ u2)) (succ u3)} (Prod.{max u1 u3, max u2 u3} (α -> γ) (β -> γ)) ((Sum.{u1, u2} α β) -> γ)) (Equiv.symm.{max (max (succ u1) (succ u2)) (succ u3), max (succ (max u1 u3)) (succ (max u2 u3))} ((Sum.{u1, u2} α β) -> γ) (Prod.{max u1 u3, max u2 u3} (α -> γ) (β -> γ)) (Equiv.sumArrowEquivProdArrow.{u1, u2, u3} α β γ)) (Prod.mk.{max u1 u3, max u2 u3} (α -> γ) (β -> γ) f g) (Sum.inr.{u1, u2} α β b)) (g b) but is expected to have type forall {α : Type.{u3}} {β : Type.{u2}} {γ : Type.{u1}} (f : α -> β) (g : γ -> β) (b : γ), Eq.{succ u2} β (FunLike.coe.{max (max (succ u2) (succ u1)) (succ u3), max (max (succ u2) (succ u1)) (succ u3), max (max (succ u2) (succ u1)) (succ u3)} (Equiv.{max (max (succ u2) (succ u1)) (succ u3), max (max (succ u2) (succ u1)) (succ u3)} (Prod.{max u3 u2, max u1 u2} (α -> β) (γ -> β)) ((Sum.{u3, u1} α γ) -> β)) (Prod.{max u3 u2, max u1 u2} (α -> β) (γ -> β)) (fun (_x : Prod.{max u3 u2, max u1 u2} (α -> β) (γ -> β)) => (fun ([email protected]._hyg.808 : Prod.{max u3 u2, max u1 u2} (α -> β) (γ -> β)) => (Sum.{u3, u1} α γ) -> β) _x) (Equiv.instFunLikeEquiv.{max (max (succ u2) (succ u1)) (succ u3), max (max (succ u2) (succ u1)) (succ u3)} (Prod.{max u3 u2, max u1 u2} (α -> β) (γ -> β)) ((Sum.{u3, u1} α γ) -> β)) (Equiv.symm.{max (max (succ u2) (succ u1)) (succ u3), max (max (succ u2) (succ u1)) (succ u3)} ((Sum.{u3, u1} α γ) -> β) (Prod.{max u3 u2, max u1 u2} (α -> β) (γ -> β)) (Equiv.sumArrowEquivProdArrow.{u3, u1, u2} α γ β)) (Prod.mk.{max u2 u3, max u2 u1} (α -> β) (γ -> β) f g) (Sum.inr.{u3, u1} α γ b)) (g b) Case conversion may be inaccurate. Consider using '#align equiv.sum_arrow_equiv_prod_arrow_symm_apply_inr Equiv.sumArrowEquivProdArrow_symm_apply_inrₓ'. -/ @[simp] theorem sumArrowEquivProdArrow_symm_apply_inr {α β γ} (f : α → γ) (g : β → γ) (b : β) : ((sumArrowEquivProdArrow α β γ).symm (f, g)) (inr b) = g b := rfl #align equiv.sum_arrow_equiv_prod_arrow_symm_apply_inr Equiv.sumArrowEquivProdArrow_symm_apply_inr #print Equiv.sumProdDistrib /- /-- Type product is right distributive with respect to type sum up to an equivalence. -/ def sumProdDistrib (α β γ : Sort _) : Sum α β × γ ≃ Sum (α × γ) (β × γ) := ⟨fun p => p.1.map (fun x => (x, p.2)) fun x => (x, p.2), fun s => s.elim (Prod.map inl id) (Prod.map inr id), by rintro ⟨_ | _, _⟩ <;> rfl, by rintro (⟨_, _⟩ | ⟨_, _⟩) <;> rfl⟩ #align equiv.sum_prod_distrib Equiv.sumProdDistrib -/ /- warning: equiv.sum_prod_distrib_apply_left -> Equiv.sumProdDistrib_apply_left is a dubious translation: lean 3 declaration is forall {α : Type.{u1}} {β : Type.{u2}} {γ : Type.{u3}} (a : α) (c : γ), Eq.{max (succ (max u1 u3)) (succ (max u2 u3))} (Sum.{max u1 u3, max u2 u3} (Prod.{u1, u3} α γ) (Prod.{u2, u3} β γ)) (coeFn.{max 1 (max (max (succ (max u1 u2)) (succ u3)) (succ (max u1 u3)) (succ (max u2 u3))) (max (succ (max u1 u3)) (succ (max u2 u3))) (succ (max u1 u2)) (succ u3), max (max (succ (max u1 u2)) (succ u3)) (succ (max u1 u3)) (succ (max u2 u3))} (Equiv.{max (succ (max u1 u2)) (succ u3), max (succ (max u1 u3)) (succ (max u2 u3))} (Prod.{max u1 u2, u3} (Sum.{u1, u2} α β) γ) (Sum.{max u1 u3, max u2 u3} (Prod.{u1, u3} α γ) (Prod.{u2, u3} β γ))) (fun (_x : Equiv.{max (succ (max u1 u2)) (succ u3), max (succ (max u1 u3)) (succ (max u2 u3))} (Prod.{max u1 u2, u3} (Sum.{u1, u2} α β) γ) (Sum.{max u1 u3, max u2 u3} (Prod.{u1, u3} α γ) (Prod.{u2, u3} β γ))) => (Prod.{max u1 u2, u3} (Sum.{u1, u2} α β) γ) -> (Sum.{max u1 u3, max u2 u3} (Prod.{u1, u3} α γ) (Prod.{u2, u3} β γ))) (Equiv.hasCoeToFun.{max (succ (max u1 u2)) (succ u3), max (succ (max u1 u3)) (succ (max u2 u3))} (Prod.{max u1 u2, u3} (Sum.{u1, u2} α β) γ) (Sum.{max u1 u3, max u2 u3} (Prod.{u1, u3} α γ) (Prod.{u2, u3} β γ))) (Equiv.sumProdDistrib.{u1, u2, u3} α β γ) (Prod.mk.{max u1 u2, u3} (Sum.{u1, u2} α β) γ (Sum.inl.{u1, u2} α β a) c)) (Sum.inl.{max u1 u3, max u2 u3} (Prod.{u1, u3} α γ) (Prod.{u2, u3} β γ) (Prod.mk.{u1, u3} α γ a c)) but is expected to have type forall {α : Type.{u3}} {β : Type.{u2}} {γ : Type.{u1}} (a : α) (c : β), Eq.{max (max (succ u2) (succ u1)) (succ u3)} ((fun ([email protected]._hyg.808 : Prod.{max u1 u3, u2} (Sum.{u3, u1} α γ) β) => Sum.{max u2 u3, max u2 u1} (Prod.{u3, u2} α β) (Prod.{u1, u2} γ β)) (Prod.mk.{max u1 u3, u2} (Sum.{u3, u1} α γ) β (Sum.inl.{u3, u1} α γ a) c)) (FunLike.coe.{max (max (succ u2) (succ u1)) (succ u3), max (max (succ u2) (succ u1)) (succ u3), max (max (succ u2) (succ u1)) (succ u3)} (Equiv.{max (succ u2) (succ (max u1 u3)), max (succ (max u2 u1)) (succ (max u2 u3))} (Prod.{max u1 u3, u2} (Sum.{u3, u1} α γ) β) (Sum.{max u2 u3, max u2 u1} (Prod.{u3, u2} α β) (Prod.{u1, u2} γ β))) (Prod.{max u1 u3, u2} (Sum.{u3, u1} α γ) β) (fun (_x : Prod.{max u1 u3, u2} (Sum.{u3, u1} α γ) β) => (fun ([email protected]._hyg.808 : Prod.{max u1 u3, u2} (Sum.{u3, u1} α γ) β) => Sum.{max u2 u3, max u2 u1} (Prod.{u3, u2} α β) (Prod.{u1, u2} γ β)) _x) (Equiv.instFunLikeEquiv.{max (max (succ u2) (succ u1)) (succ u3), max (max (succ u2) (succ u1)) (succ u3)} (Prod.{max u1 u3, u2} (Sum.{u3, u1} α γ) β) (Sum.{max u2 u3, max u2 u1} (Prod.{u3, u2} α β) (Prod.{u1, u2} γ β))) (Equiv.sumProdDistrib.{u3, u1, u2} α γ β) (Prod.mk.{max u1 u3, u2} (Sum.{u3, u1} α γ) β (Sum.inl.{u3, u1} α γ a) c)) (Sum.inl.{max u2 u3, max u2 u1} (Prod.{u3, u2} α β) (Prod.{u1, u2} γ β) (Prod.mk.{u3, u2} α β a c)) Case conversion may be inaccurate. Consider using '#align equiv.sum_prod_distrib_apply_left Equiv.sumProdDistrib_apply_leftₓ'. -/ @[simp] theorem sumProdDistrib_apply_left {α β γ} (a : α) (c : γ) : sumProdDistrib α β γ (Sum.inl a, c) = Sum.inl (a, c) := rfl #align equiv.sum_prod_distrib_apply_left Equiv.sumProdDistrib_apply_left /- warning: equiv.sum_prod_distrib_apply_right -> Equiv.sumProdDistrib_apply_right is a dubious translation: lean 3 declaration is forall {α : Type.{u1}} {β : Type.{u2}} {γ : Type.{u3}} (b : β) (c : γ), Eq.{max (succ (max u1 u3)) (succ (max u2 u3))} (Sum.{max u1 u3, max u2 u3} (Prod.{u1, u3} α γ) (Prod.{u2, u3} β γ)) (coeFn.{max 1 (max (max (succ (max u1 u2)) (succ u3)) (succ (max u1 u3)) (succ (max u2 u3))) (max (succ (max u1 u3)) (succ (max u2 u3))) (succ (max u1 u2)) (succ u3), max (max (succ (max u1 u2)) (succ u3)) (succ (max u1 u3)) (succ (max u2 u3))} (Equiv.{max (succ (max u1 u2)) (succ u3), max (succ (max u1 u3)) (succ (max u2 u3))} (Prod.{max u1 u2, u3} (Sum.{u1, u2} α β) γ) (Sum.{max u1 u3, max u2 u3} (Prod.{u1, u3} α γ) (Prod.{u2, u3} β γ))) (fun (_x : Equiv.{max (succ (max u1 u2)) (succ u3), max (succ (max u1 u3)) (succ (max u2 u3))} (Prod.{max u1 u2, u3} (Sum.{u1, u2} α β) γ) (Sum.{max u1 u3, max u2 u3} (Prod.{u1, u3} α γ) (Prod.{u2, u3} β γ))) => (Prod.{max u1 u2, u3} (Sum.{u1, u2} α β) γ) -> (Sum.{max u1 u3, max u2 u3} (Prod.{u1, u3} α γ) (Prod.{u2, u3} β γ))) (Equiv.hasCoeToFun.{max (succ (max u1 u2)) (succ u3), max (succ (max u1 u3)) (succ (max u2 u3))} (Prod.{max u1 u2, u3} (Sum.{u1, u2} α β) γ) (Sum.{max u1 u3, max u2 u3} (Prod.{u1, u3} α γ) (Prod.{u2, u3} β γ))) (Equiv.sumProdDistrib.{u1, u2, u3} α β γ) (Prod.mk.{max u1 u2, u3} (Sum.{u1, u2} α β) γ (Sum.inr.{u1, u2} α β b) c)) (Sum.inr.{max u1 u3, max u2 u3} (Prod.{u1, u3} α γ) (Prod.{u2, u3} β γ) (Prod.mk.{u2, u3} β γ b c)) but is expected to have type forall {α : Type.{u3}} {β : Type.{u2}} {γ : Type.{u1}} (b : α) (c : β), Eq.{max (max (succ u2) (succ u3)) (succ u1)} ((fun ([email protected]._hyg.808 : Prod.{max u3 u1, u2} (Sum.{u1, u3} γ α) β) => Sum.{max u2 u1, max u2 u3} (Prod.{u1, u2} γ β) (Prod.{u3, u2} α β)) (Prod.mk.{max u3 u1, u2} (Sum.{u1, u3} γ α) β (Sum.inr.{u1, u3} γ α b) c)) (FunLike.coe.{max (max (succ u2) (succ u3)) (succ u1), max (max (succ u2) (succ u3)) (succ u1), max (max (succ u2) (succ u3)) (succ u1)} (Equiv.{max (succ u2) (succ (max u3 u1)), max (succ (max u2 u3)) (succ (max u2 u1))} (Prod.{max u3 u1, u2} (Sum.{u1, u3} γ α) β) (Sum.{max u2 u1, max u2 u3} (Prod.{u1, u2} γ β) (Prod.{u3, u2} α β))) (Prod.{max u3 u1, u2} (Sum.{u1, u3} γ α) β) (fun (_x : Prod.{max u3 u1, u2} (Sum.{u1, u3} γ α) β) => (fun ([email protected]._hyg.808 : Prod.{max u3 u1, u2} (Sum.{u1, u3} γ α) β) => Sum.{max u2 u1, max u2 u3} (Prod.{u1, u2} γ β) (Prod.{u3, u2} α β)) _x) (Equiv.instFunLikeEquiv.{max (max (succ u2) (succ u3)) (succ u1), max (max (succ u2) (succ u3)) (succ u1)} (Prod.{max u3 u1, u2} (Sum.{u1, u3} γ α) β) (Sum.{max u2 u1, max u2 u3} (Prod.{u1, u2} γ β) (Prod.{u3, u2} α β))) (Equiv.sumProdDistrib.{u1, u3, u2} γ α β) (Prod.mk.{max u3 u1, u2} (Sum.{u1, u3} γ α) β (Sum.inr.{u1, u3} γ α b) c)) (Sum.inr.{max u2 u1, max u2 u3} (Prod.{u1, u2} γ β) (Prod.{u3, u2} α β) (Prod.mk.{u3, u2} α β b c)) Case conversion may be inaccurate. Consider using '#align equiv.sum_prod_distrib_apply_right Equiv.sumProdDistrib_apply_rightₓ'. -/ @[simp] theorem sumProdDistrib_apply_right {α β γ} (b : β) (c : γ) : sumProdDistrib α β γ (Sum.inr b, c) = Sum.inr (b, c) := rfl #align equiv.sum_prod_distrib_apply_right Equiv.sumProdDistrib_apply_right /- warning: equiv.sum_prod_distrib_symm_apply_left -> Equiv.sumProdDistrib_symm_apply_left is a dubious translation: lean 3 declaration is forall {α : Type.{u1}} {β : Type.{u2}} {γ : Type.{u3}} (a : Prod.{u1, u3} α γ), Eq.{max (succ (max u1 u2)) (succ u3)} (Prod.{max u1 u2, u3} (Sum.{u1, u2} α β) γ) (coeFn.{max 1 (max (max (succ (max u1 u3)) (succ (max u2 u3))) (succ (max u1 u2)) (succ u3)) (max (succ (max u1 u2)) (succ u3)) (succ (max u1 u3)) (succ (max u2 u3)), max (max (succ (max u1 u3)) (succ (max u2 u3))) (succ (max u1 u2)) (succ u3)} (Equiv.{max (succ (max u1 u3)) (succ (max u2 u3)), max (succ (max u1 u2)) (succ u3)} (Sum.{max u1 u3, max u2 u3} (Prod.{u1, u3} α γ) (Prod.{u2, u3} β γ)) (Prod.{max u1 u2, u3} (Sum.{u1, u2} α β) γ)) (fun (_x : Equiv.{max (succ (max u1 u3)) (succ (max u2 u3)), max (succ (max u1 u2)) (succ u3)} (Sum.{max u1 u3, max u2 u3} (Prod.{u1, u3} α γ) (Prod.{u2, u3} β γ)) (Prod.{max u1 u2, u3} (Sum.{u1, u2} α β) γ)) => (Sum.{max u1 u3, max u2 u3} (Prod.{u1, u3} α γ) (Prod.{u2, u3} β γ)) -> (Prod.{max u1 u2, u3} (Sum.{u1, u2} α β) γ)) (Equiv.hasCoeToFun.{max (succ (max u1 u3)) (succ (max u2 u3)), max (succ (max u1 u2)) (succ u3)} (Sum.{max u1 u3, max u2 u3} (Prod.{u1, u3} α γ) (Prod.{u2, u3} β γ)) (Prod.{max u1 u2, u3} (Sum.{u1, u2} α β) γ)) (Equiv.symm.{max (succ (max u1 u2)) (succ u3), max (succ (max u1 u3)) (succ (max u2 u3))} (Prod.{max u1 u2, u3} (Sum.{u1, u2} α β) γ) (Sum.{max u1 u3, max u2 u3} (Prod.{u1, u3} α γ) (Prod.{u2, u3} β γ)) (Equiv.sumProdDistrib.{u1, u2, u3} α β γ)) (Sum.inl.{max u1 u3, max u2 u3} (Prod.{u1, u3} α γ) (Prod.{u2, u3} β γ) a)) (Prod.mk.{max u1 u2, u3} (Sum.{u1, u2} α β) γ (Sum.inl.{u1, u2} α β (Prod.fst.{u1, u3} α γ a)) (Prod.snd.{u1, u3} α γ a)) but is expected to have type forall {α : Type.{u3}} {β : Type.{u2}} {γ : Type.{u1}} (a : Prod.{u3, u2} α β), Eq.{max (max (succ u2) (succ u3)) (succ u1)} ((fun ([email protected]._hyg.808 : Sum.{max u2 u3, max u2 u1} (Prod.{u3, u2} α β) (Prod.{u1, u2} γ β)) => Prod.{max u1 u3, u2} (Sum.{u3, u1} α γ) β) (Sum.inl.{max u2 u3, max u2 u1} (Prod.{u3, u2} α β) (Prod.{u1, u2} γ β) a)) (FunLike.coe.{max (max (succ u2) (succ u3)) (succ u1), max (max (succ u2) (succ u3)) (succ u1), max (max (succ u2) (succ u3)) (succ u1)} (Equiv.{max (max (succ u2) (succ u3)) (succ u1), max (max (succ u2) (succ u3)) (succ u1)} (Sum.{max u2 u3, max u2 u1} (Prod.{u3, u2} α β) (Prod.{u1, u2} γ β)) (Prod.{max u1 u3, u2} (Sum.{u3, u1} α γ) β)) (Sum.{max u2 u3, max u2 u1} (Prod.{u3, u2} α β) (Prod.{u1, u2} γ β)) (fun (_x : Sum.{max u2 u3, max u2 u1} (Prod.{u3, u2} α β) (Prod.{u1, u2} γ β)) => (fun ([email protected]._hyg.808 : Sum.{max u2 u3, max u2 u1} (Prod.{u3, u2} α β) (Prod.{u1, u2} γ β)) => Prod.{max u1 u3, u2} (Sum.{u3, u1} α γ) β) _x) (Equiv.instFunLikeEquiv.{max (max (succ u2) (succ u3)) (succ u1), max (max (succ u2) (succ u3)) (succ u1)} (Sum.{max u2 u3, max u2 u1} (Prod.{u3, u2} α β) (Prod.{u1, u2} γ β)) (Prod.{max u1 u3, u2} (Sum.{u3, u1} α γ) β)) (Equiv.symm.{max (max (succ u2) (succ u3)) (succ u1), max (max (succ u2) (succ u3)) (succ u1)} (Prod.{max u1 u3, u2} (Sum.{u3, u1} α γ) β) (Sum.{max u2 u3, max u2 u1} (Prod.{u3, u2} α β) (Prod.{u1, u2} γ β)) (Equiv.sumProdDistrib.{u3, u1, u2} α γ β)) (Sum.inl.{max u2 u3, max u2 u1} (Prod.{u3, u2} α β) (Prod.{u1, u2} γ β) a)) (Prod.mk.{max u1 u3, u2} (Sum.{u3, u1} α γ) β (Sum.inl.{u3, u1} α γ (Prod.fst.{u3, u2} α β a)) (Prod.snd.{u3, u2} α β a)) Case conversion may be inaccurate. Consider using '#align equiv.sum_prod_distrib_symm_apply_left Equiv.sumProdDistrib_symm_apply_leftₓ'. -/ @[simp] theorem sumProdDistrib_symm_apply_left {α β γ} (a : α × γ) : (sumProdDistrib α β γ).symm (inl a) = (inl a.1, a.2) := rfl #align equiv.sum_prod_distrib_symm_apply_left Equiv.sumProdDistrib_symm_apply_left /- warning: equiv.sum_prod_distrib_symm_apply_right -> Equiv.sumProdDistrib_symm_apply_right is a dubious translation: lean 3 declaration is forall {α : Type.{u1}} {β : Type.{u2}} {γ : Type.{u3}} (b : Prod.{u2, u3} β γ), Eq.{max (succ (max u1 u2)) (succ u3)} (Prod.{max u1 u2, u3} (Sum.{u1, u2} α β) γ) (coeFn.{max 1 (max (max (succ (max u1 u3)) (succ (max u2 u3))) (succ (max u1 u2)) (succ u3)) (max (succ (max u1 u2)) (succ u3)) (succ (max u1 u3)) (succ (max u2 u3)), max (max (succ (max u1 u3)) (succ (max u2 u3))) (succ (max u1 u2)) (succ u3)} (Equiv.{max (succ (max u1 u3)) (succ (max u2 u3)), max (succ (max u1 u2)) (succ u3)} (Sum.{max u1 u3, max u2 u3} (Prod.{u1, u3} α γ) (Prod.{u2, u3} β γ)) (Prod.{max u1 u2, u3} (Sum.{u1, u2} α β) γ)) (fun (_x : Equiv.{max (succ (max u1 u3)) (succ (max u2 u3)), max (succ (max u1 u2)) (succ u3)} (Sum.{max u1 u3, max u2 u3} (Prod.{u1, u3} α γ) (Prod.{u2, u3} β γ)) (Prod.{max u1 u2, u3} (Sum.{u1, u2} α β) γ)) => (Sum.{max u1 u3, max u2 u3} (Prod.{u1, u3} α γ) (Prod.{u2, u3} β γ)) -> (Prod.{max u1 u2, u3} (Sum.{u1, u2} α β) γ)) (Equiv.hasCoeToFun.{max (succ (max u1 u3)) (succ (max u2 u3)), max (succ (max u1 u2)) (succ u3)} (Sum.{max u1 u3, max u2 u3} (Prod.{u1, u3} α γ) (Prod.{u2, u3} β γ)) (Prod.{max u1 u2, u3} (Sum.{u1, u2} α β) γ)) (Equiv.symm.{max (succ (max u1 u2)) (succ u3), max (succ (max u1 u3)) (succ (max u2 u3))} (Prod.{max u1 u2, u3} (Sum.{u1, u2} α β) γ) (Sum.{max u1 u3, max u2 u3} (Prod.{u1, u3} α γ) (Prod.{u2, u3} β γ)) (Equiv.sumProdDistrib.{u1, u2, u3} α β γ)) (Sum.inr.{max u1 u3, max u2 u3} (Prod.{u1, u3} α γ) (Prod.{u2, u3} β γ) b)) (Prod.mk.{max u1 u2, u3} (Sum.{u1, u2} α β) γ (Sum.inr.{u1, u2} α β (Prod.fst.{u2, u3} β γ b)) (Prod.snd.{u2, u3} β γ b)) but is expected to have type forall {α : Type.{u3}} {β : Type.{u2}} {γ : Type.{u1}} (b : Prod.{u3, u2} α β), Eq.{max (max (succ u2) (succ u3)) (succ u1)} ((fun ([email protected]._hyg.808 : Sum.{max u2 u1, max u2 u3} (Prod.{u1, u2} γ β) (Prod.{u3, u2} α β)) => Prod.{max u3 u1, u2} (Sum.{u1, u3} γ α) β) (Sum.inr.{max u2 u1, max u2 u3} (Prod.{u1, u2} γ β) (Prod.{u3, u2} α β) b)) (FunLike.coe.{max (max (succ u2) (succ u3)) (succ u1), max (max (succ u2) (succ u3)) (succ u1), max (max (succ u2) (succ u3)) (succ u1)} (Equiv.{max (max (succ u2) (succ u3)) (succ u1), max (max (succ u2) (succ u3)) (succ u1)} (Sum.{max u2 u1, max u2 u3} (Prod.{u1, u2} γ β) (Prod.{u3, u2} α β)) (Prod.{max u3 u1, u2} (Sum.{u1, u3} γ α) β)) (Sum.{max u2 u1, max u2 u3} (Prod.{u1, u2} γ β) (Prod.{u3, u2} α β)) (fun (_x : Sum.{max u2 u1, max u2 u3} (Prod.{u1, u2} γ β) (Prod.{u3, u2} α β)) => (fun ([email protected]._hyg.808 : Sum.{max u2 u1, max u2 u3} (Prod.{u1, u2} γ β) (Prod.{u3, u2} α β)) => Prod.{max u3 u1, u2} (Sum.{u1, u3} γ α) β) _x) (Equiv.instFunLikeEquiv.{max (max (succ u2) (succ u3)) (succ u1), max (max (succ u2) (succ u3)) (succ u1)} (Sum.{max u2 u1, max u2 u3} (Prod.{u1, u2} γ β) (Prod.{u3, u2} α β)) (Prod.{max u3 u1, u2} (Sum.{u1, u3} γ α) β)) (Equiv.symm.{max (max (succ u2) (succ u3)) (succ u1), max (max (succ u2) (succ u3)) (succ u1)} (Prod.{max u3 u1, u2} (Sum.{u1, u3} γ α) β) (Sum.{max u2 u1, max u2 u3} (Prod.{u1, u2} γ β) (Prod.{u3, u2} α β)) (Equiv.sumProdDistrib.{u1, u3, u2} γ α β)) (Sum.inr.{max u2 u1, max u2 u3} (Prod.{u1, u2} γ β) (Prod.{u3, u2} α β) b)) (Prod.mk.{max u3 u1, u2} (Sum.{u1, u3} γ α) β (Sum.inr.{u1, u3} γ α (Prod.fst.{u3, u2} α β b)) (Prod.snd.{u3, u2} α β b)) Case conversion may be inaccurate. Consider using '#align equiv.sum_prod_distrib_symm_apply_right Equiv.sumProdDistrib_symm_apply_rightₓ'. -/ @[simp] theorem sumProdDistrib_symm_apply_right {α β γ} (b : β × γ) : (sumProdDistrib α β γ).symm (inr b) = (inr b.1, b.2) := rfl #align equiv.sum_prod_distrib_symm_apply_right Equiv.sumProdDistrib_symm_apply_right #print Equiv.prodSumDistrib /- /-- Type product is left distributive with respect to type sum up to an equivalence. -/ def prodSumDistrib (α β γ : Sort _) : α × Sum β γ ≃ Sum (α × β) (α × γ) := calc α × Sum β γ ≃ Sum β γ × α := prodComm _ _ _ ≃ Sum (β × α) (γ × α) := (sumProdDistrib _ _ _) _ ≃ Sum (α × β) (α × γ) := sumCongr (prodComm _ _) (prodComm _ _) #align equiv.prod_sum_distrib Equiv.prodSumDistrib -/ /- warning: equiv.prod_sum_distrib_apply_left -> Equiv.prodSumDistrib_apply_left is a dubious translation: lean 3 declaration is forall {α : Type.{u1}} {β : Type.{u2}} {γ : Type.{u3}} (a : α) (b : β), Eq.{max (succ (max u1 u2)) (succ (max u1 u3))} (Sum.{max u1 u2, max u1 u3} (Prod.{u1, u2} α β) (Prod.{u1, u3} α γ)) (coeFn.{max 1 (max (max (succ u1) (succ (max u2 u3))) (succ (max u1 u2)) (succ (max u1 u3))) (max (succ (max u1 u2)) (succ (max u1 u3))) (succ u1) (succ (max u2 u3)), max (max (succ u1) (succ (max u2 u3))) (succ (max u1 u2)) (succ (max u1 u3))} (Equiv.{max (succ u1) (succ (max u2 u3)), max (succ (max u1 u2)) (succ (max u1 u3))} (Prod.{u1, max u2 u3} α (Sum.{u2, u3} β γ)) (Sum.{max u1 u2, max u1 u3} (Prod.{u1, u2} α β) (Prod.{u1, u3} α γ))) (fun (_x : Equiv.{max (succ u1) (succ (max u2 u3)), max (succ (max u1 u2)) (succ (max u1 u3))} (Prod.{u1, max u2 u3} α (Sum.{u2, u3} β γ)) (Sum.{max u1 u2, max u1 u3} (Prod.{u1, u2} α β) (Prod.{u1, u3} α γ))) => (Prod.{u1, max u2 u3} α (Sum.{u2, u3} β γ)) -> (Sum.{max u1 u2, max u1 u3} (Prod.{u1, u2} α β) (Prod.{u1, u3} α γ))) (Equiv.hasCoeToFun.{max (succ u1) (succ (max u2 u3)), max (succ (max u1 u2)) (succ (max u1 u3))} (Prod.{u1, max u2 u3} α (Sum.{u2, u3} β γ)) (Sum.{max u1 u2, max u1 u3} (Prod.{u1, u2} α β) (Prod.{u1, u3} α γ))) (Equiv.prodSumDistrib.{u1, u2, u3} α β γ) (Prod.mk.{u1, max u2 u3} α (Sum.{u2, u3} β γ) a (Sum.inl.{u2, u3} β γ b))) (Sum.inl.{max u1 u2, max u1 u3} (Prod.{u1, u2} α β) (Prod.{u1, u3} α γ) (Prod.mk.{u1, u2} α β a b)) but is expected to have type forall {α : Type.{u3}} {β : Type.{u2}} {γ : Type.{u1}} (a : α) (b : β), Eq.{max (max (succ u1) (succ u2)) (succ u3)} ((fun ([email protected]._hyg.808 : Prod.{u3, max u1 u2} α (Sum.{u2, u1} β γ)) => Sum.{max u2 u3, max u1 u3} (Prod.{u3, u2} α β) (Prod.{u3, u1} α γ)) (Prod.mk.{u3, max u1 u2} α (Sum.{u2, u1} β γ) a (Sum.inl.{u2, u1} β γ b))) (FunLike.coe.{max (max (succ u1) (succ u2)) (succ u3), max (max (succ u1) (succ u2)) (succ u3), max (max (succ u1) (succ u2)) (succ u3)} (Equiv.{max (succ (max u1 u2)) (succ u3), max (succ (max u1 u3)) (succ (max u2 u3))} (Prod.{u3, max u1 u2} α (Sum.{u2, u1} β γ)) (Sum.{max u2 u3, max u1 u3} (Prod.{u3, u2} α β) (Prod.{u3, u1} α γ))) (Prod.{u3, max u1 u2} α (Sum.{u2, u1} β γ)) (fun (_x : Prod.{u3, max u1 u2} α (Sum.{u2, u1} β γ)) => (fun ([email protected]._hyg.808 : Prod.{u3, max u1 u2} α (Sum.{u2, u1} β γ)) => Sum.{max u2 u3, max u1 u3} (Prod.{u3, u2} α β) (Prod.{u3, u1} α γ)) _x) (Equiv.instFunLikeEquiv.{max (max (succ u1) (succ u2)) (succ u3), max (max (succ u1) (succ u2)) (succ u3)} (Prod.{u3, max u1 u2} α (Sum.{u2, u1} β γ)) (Sum.{max u2 u3, max u1 u3} (Prod.{u3, u2} α β) (Prod.{u3, u1} α γ))) (Equiv.prodSumDistrib.{u3, u2, u1} α β γ) (Prod.mk.{u3, max u1 u2} α (Sum.{u2, u1} β γ) a (Sum.inl.{u2, u1} β γ b))) (Sum.inl.{max u2 u3, max u1 u3} (Prod.{u3, u2} α β) (Prod.{u3, u1} α γ) (Prod.mk.{u3, u2} α β a b)) Case conversion may be inaccurate. Consider using '#align equiv.prod_sum_distrib_apply_left Equiv.prodSumDistrib_apply_leftₓ'. -/ @[simp] theorem prodSumDistrib_apply_left {α β γ} (a : α) (b : β) : prodSumDistrib α β γ (a, Sum.inl b) = Sum.inl (a, b) := rfl #align equiv.prod_sum_distrib_apply_left Equiv.prodSumDistrib_apply_left /- warning: equiv.prod_sum_distrib_apply_right -> Equiv.prodSumDistrib_apply_right is a dubious translation: lean 3 declaration is forall {α : Type.{u1}} {β : Type.{u2}} {γ : Type.{u3}} (a : α) (c : γ), Eq.{max (succ (max u1 u2)) (succ (max u1 u3))} (Sum.{max u1 u2, max u1 u3} (Prod.{u1, u2} α β) (Prod.{u1, u3} α γ)) (coeFn.{max 1 (max (max (succ u1) (succ (max u2 u3))) (succ (max u1 u2)) (succ (max u1 u3))) (max (succ (max u1 u2)) (succ (max u1 u3))) (succ u1) (succ (max u2 u3)), max (max (succ u1) (succ (max u2 u3))) (succ (max u1 u2)) (succ (max u1 u3))} (Equiv.{max (succ u1) (succ (max u2 u3)), max (succ (max u1 u2)) (succ (max u1 u3))} (Prod.{u1, max u2 u3} α (Sum.{u2, u3} β γ)) (Sum.{max u1 u2, max u1 u3} (Prod.{u1, u2} α β) (Prod.{u1, u3} α γ))) (fun (_x : Equiv.{max (succ u1) (succ (max u2 u3)), max (succ (max u1 u2)) (succ (max u1 u3))} (Prod.{u1, max u2 u3} α (Sum.{u2, u3} β γ)) (Sum.{max u1 u2, max u1 u3} (Prod.{u1, u2} α β) (Prod.{u1, u3} α γ))) => (Prod.{u1, max u2 u3} α (Sum.{u2, u3} β γ)) -> (Sum.{max u1 u2, max u1 u3} (Prod.{u1, u2} α β) (Prod.{u1, u3} α γ))) (Equiv.hasCoeToFun.{max (succ u1) (succ (max u2 u3)), max (succ (max u1 u2)) (succ (max u1 u3))} (Prod.{u1, max u2 u3} α (Sum.{u2, u3} β γ)) (Sum.{max u1 u2, max u1 u3} (Prod.{u1, u2} α β) (Prod.{u1, u3} α γ))) (Equiv.prodSumDistrib.{u1, u2, u3} α β γ) (Prod.mk.{u1, max u2 u3} α (Sum.{u2, u3} β γ) a (Sum.inr.{u2, u3} β γ c))) (Sum.inr.{max u1 u2, max u1 u3} (Prod.{u1, u2} α β) (Prod.{u1, u3} α γ) (Prod.mk.{u1, u3} α γ a c)) but is expected to have type forall {α : Type.{u3}} {β : Type.{u2}} {γ : Type.{u1}} (a : α) (c : β), Eq.{max (max (succ u2) (succ u1)) (succ u3)} ((fun ([email protected]._hyg.808 : Prod.{u3, max u2 u1} α (Sum.{u1, u2} γ β)) => Sum.{max u1 u3, max u2 u3} (Prod.{u3, u1} α γ) (Prod.{u3, u2} α β)) (Prod.mk.{u3, max u2 u1} α (Sum.{u1, u2} γ β) a (Sum.inr.{u1, u2} γ β c))) (FunLike.coe.{max (max (succ u2) (succ u1)) (succ u3), max (max (succ u2) (succ u1)) (succ u3), max (max (succ u2) (succ u1)) (succ u3)} (Equiv.{max (succ (max u2 u1)) (succ u3), max (succ (max u2 u3)) (succ (max u1 u3))} (Prod.{u3, max u2 u1} α (Sum.{u1, u2} γ β)) (Sum.{max u1 u3, max u2 u3} (Prod.{u3, u1} α γ) (Prod.{u3, u2} α β))) (Prod.{u3, max u2 u1} α (Sum.{u1, u2} γ β)) (fun (_x : Prod.{u3, max u2 u1} α (Sum.{u1, u2} γ β)) => (fun ([email protected]._hyg.808 : Prod.{u3, max u2 u1} α (Sum.{u1, u2} γ β)) => Sum.{max u1 u3, max u2 u3} (Prod.{u3, u1} α γ) (Prod.{u3, u2} α β)) _x) (Equiv.instFunLikeEquiv.{max (max (succ u2) (succ u1)) (succ u3), max (max (succ u2) (succ u1)) (succ u3)} (Prod.{u3, max u2 u1} α (Sum.{u1, u2} γ β)) (Sum.{max u1 u3, max u2 u3} (Prod.{u3, u1} α γ) (Prod.{u3, u2} α β))) (Equiv.prodSumDistrib.{u3, u1, u2} α γ β) (Prod.mk.{u3, max u2 u1} α (Sum.{u1, u2} γ β) a (Sum.inr.{u1, u2} γ β c))) (Sum.inr.{max u1 u3, max u2 u3} (Prod.{u3, u1} α γ) (Prod.{u3, u2} α β) (Prod.mk.{u3, u2} α β a c)) Case conversion may be inaccurate. Consider using '#align equiv.prod_sum_distrib_apply_right Equiv.prodSumDistrib_apply_rightₓ'. -/ @[simp] theorem prodSumDistrib_apply_right {α β γ} (a : α) (c : γ) : prodSumDistrib α β γ (a, Sum.inr c) = Sum.inr (a, c) := rfl #align equiv.prod_sum_distrib_apply_right Equiv.prodSumDistrib_apply_right /- warning: equiv.prod_sum_distrib_symm_apply_left -> Equiv.prodSumDistrib_symm_apply_left is a dubious translation: lean 3 declaration is forall {α : Type.{u1}} {β : Type.{u2}} {γ : Type.{u3}} (a : Prod.{u1, u2} α β), Eq.{max (succ u1) (succ (max u2 u3))} (Prod.{u1, max u2 u3} α (Sum.{u2, u3} β γ)) (coeFn.{max 1 (max (max (succ (max u1 u2)) (succ (max u1 u3))) (succ u1) (succ (max u2 u3))) (max (succ u1) (succ (max u2 u3))) (succ (max u1 u2)) (succ (max u1 u3)), max (max (succ (max u1 u2)) (succ (max u1 u3))) (succ u1) (succ (max u2 u3))} (Equiv.{max (succ (max u1 u2)) (succ (max u1 u3)), max (succ u1) (succ (max u2 u3))} (Sum.{max u1 u2, max u1 u3} (Prod.{u1, u2} α β) (Prod.{u1, u3} α γ)) (Prod.{u1, max u2 u3} α (Sum.{u2, u3} β γ))) (fun (_x : Equiv.{max (succ (max u1 u2)) (succ (max u1 u3)), max (succ u1) (succ (max u2 u3))} (Sum.{max u1 u2, max u1 u3} (Prod.{u1, u2} α β) (Prod.{u1, u3} α γ)) (Prod.{u1, max u2 u3} α (Sum.{u2, u3} β γ))) => (Sum.{max u1 u2, max u1 u3} (Prod.{u1, u2} α β) (Prod.{u1, u3} α γ)) -> (Prod.{u1, max u2 u3} α (Sum.{u2, u3} β γ))) (Equiv.hasCoeToFun.{max (succ (max u1 u2)) (succ (max u1 u3)), max (succ u1) (succ (max u2 u3))} (Sum.{max u1 u2, max u1 u3} (Prod.{u1, u2} α β) (Prod.{u1, u3} α γ)) (Prod.{u1, max u2 u3} α (Sum.{u2, u3} β γ))) (Equiv.symm.{max (succ u1) (succ (max u2 u3)), max (succ (max u1 u2)) (succ (max u1 u3))} (Prod.{u1, max u2 u3} α (Sum.{u2, u3} β γ)) (Sum.{max u1 u2, max u1 u3} (Prod.{u1, u2} α β) (Prod.{u1, u3} α γ)) (Equiv.prodSumDistrib.{u1, u2, u3} α β γ)) (Sum.inl.{max u1 u2, max u1 u3} (Prod.{u1, u2} α β) (Prod.{u1, u3} α γ) a)) (Prod.mk.{u1, max u2 u3} α (Sum.{u2, u3} β γ) (Prod.fst.{u1, u2} α β a) (Sum.inl.{u2, u3} β γ (Prod.snd.{u1, u2} α β a))) but is expected to have type forall {α : Type.{u3}} {β : Type.{u2}} {γ : Type.{u1}} (a : Prod.{u3, u2} α β), Eq.{max (max (succ u2) (succ u3)) (succ u1)} ((fun ([email protected]._hyg.808 : Sum.{max u2 u3, max u1 u3} (Prod.{u3, u2} α β) (Prod.{u3, u1} α γ)) => Prod.{u3, max u1 u2} α (Sum.{u2, u1} β γ)) (Sum.inl.{max u2 u3, max u3 u1} (Prod.{u3, u2} α β) (Prod.{u3, u1} α γ) a)) (FunLike.coe.{max (max (succ u2) (succ u3)) (succ u1), max (max (succ u2) (succ u3)) (succ u1), max (max (succ u2) (succ u3)) (succ u1)} (Equiv.{max (max (succ u2) (succ u3)) (succ u1), max (max (succ u2) (succ u3)) (succ u1)} (Sum.{max u2 u3, max u1 u3} (Prod.{u3, u2} α β) (Prod.{u3, u1} α γ)) (Prod.{u3, max u1 u2} α (Sum.{u2, u1} β γ))) (Sum.{max u2 u3, max u1 u3} (Prod.{u3, u2} α β) (Prod.{u3, u1} α γ)) (fun (_x : Sum.{max u2 u3, max u1 u3} (Prod.{u3, u2} α β) (Prod.{u3, u1} α γ)) => (fun ([email protected]._hyg.808 : Sum.{max u2 u3, max u1 u3} (Prod.{u3, u2} α β) (Prod.{u3, u1} α γ)) => Prod.{u3, max u1 u2} α (Sum.{u2, u1} β γ)) _x) (Equiv.instFunLikeEquiv.{max (max (succ u2) (succ u3)) (succ u1), max (max (succ u2) (succ u3)) (succ u1)} (Sum.{max u2 u3, max u1 u3} (Prod.{u3, u2} α β) (Prod.{u3, u1} α γ)) (Prod.{u3, max u1 u2} α (Sum.{u2, u1} β γ))) (Equiv.symm.{max (max (succ u2) (succ u3)) (succ u1), max (max (succ u2) (succ u3)) (succ u1)} (Prod.{u3, max u1 u2} α (Sum.{u2, u1} β γ)) (Sum.{max u2 u3, max u1 u3} (Prod.{u3, u2} α β) (Prod.{u3, u1} α γ)) (Equiv.prodSumDistrib.{u3, u2, u1} α β γ)) (Sum.inl.{max u2 u3, max u3 u1} (Prod.{u3, u2} α β) (Prod.{u3, u1} α γ) a)) (Prod.mk.{u3, max u1 u2} α (Sum.{u2, u1} β γ) (Prod.fst.{u3, u2} α β a) (Sum.inl.{u2, u1} β γ (Prod.snd.{u3, u2} α β a))) Case conversion may be inaccurate. Consider using '#align equiv.prod_sum_distrib_symm_apply_left Equiv.prodSumDistrib_symm_apply_leftₓ'. -/ @[simp] theorem prodSumDistrib_symm_apply_left {α β γ} (a : α × β) : (prodSumDistrib α β γ).symm (inl a) = (a.1, inl a.2) := rfl #align equiv.prod_sum_distrib_symm_apply_left Equiv.prodSumDistrib_symm_apply_left /- warning: equiv.prod_sum_distrib_symm_apply_right -> Equiv.prodSumDistrib_symm_apply_right is a dubious translation: lean 3 declaration is forall {α : Type.{u1}} {β : Type.{u2}} {γ : Type.{u3}} (a : Prod.{u1, u3} α γ), Eq.{max (succ u1) (succ (max u2 u3))} (Prod.{u1, max u2 u3} α (Sum.{u2, u3} β γ)) (coeFn.{max 1 (max (max (succ (max u1 u2)) (succ (max u1 u3))) (succ u1) (succ (max u2 u3))) (max (succ u1) (succ (max u2 u3))) (succ (max u1 u2)) (succ (max u1 u3)), max (max (succ (max u1 u2)) (succ (max u1 u3))) (succ u1) (succ (max u2 u3))} (Equiv.{max (succ (max u1 u2)) (succ (max u1 u3)), max (succ u1) (succ (max u2 u3))} (Sum.{max u1 u2, max u1 u3} (Prod.{u1, u2} α β) (Prod.{u1, u3} α γ)) (Prod.{u1, max u2 u3} α (Sum.{u2, u3} β γ))) (fun (_x : Equiv.{max (succ (max u1 u2)) (succ (max u1 u3)), max (succ u1) (succ (max u2 u3))} (Sum.{max u1 u2, max u1 u3} (Prod.{u1, u2} α β) (Prod.{u1, u3} α γ)) (Prod.{u1, max u2 u3} α (Sum.{u2, u3} β γ))) => (Sum.{max u1 u2, max u1 u3} (Prod.{u1, u2} α β) (Prod.{u1, u3} α γ)) -> (Prod.{u1, max u2 u3} α (Sum.{u2, u3} β γ))) (Equiv.hasCoeToFun.{max (succ (max u1 u2)) (succ (max u1 u3)), max (succ u1) (succ (max u2 u3))} (Sum.{max u1 u2, max u1 u3} (Prod.{u1, u2} α β) (Prod.{u1, u3} α γ)) (Prod.{u1, max u2 u3} α (Sum.{u2, u3} β γ))) (Equiv.symm.{max (succ u1) (succ (max u2 u3)), max (succ (max u1 u2)) (succ (max u1 u3))} (Prod.{u1, max u2 u3} α (Sum.{u2, u3} β γ)) (Sum.{max u1 u2, max u1 u3} (Prod.{u1, u2} α β) (Prod.{u1, u3} α γ)) (Equiv.prodSumDistrib.{u1, u2, u3} α β γ)) (Sum.inr.{max u1 u2, max u1 u3} (Prod.{u1, u2} α β) (Prod.{u1, u3} α γ) a)) (Prod.mk.{u1, max u2 u3} α (Sum.{u2, u3} β γ) (Prod.fst.{u1, u3} α γ a) (Sum.inr.{u2, u3} β γ (Prod.snd.{u1, u3} α γ a))) but is expected to have type forall {α : Type.{u3}} {β : Type.{u2}} {γ : Type.{u1}} (a : Prod.{u3, u2} α β), Eq.{max (max (succ u2) (succ u3)) (succ u1)} ((fun ([email protected]._hyg.808 : Sum.{max u1 u3, max u2 u3} (Prod.{u3, u1} α γ) (Prod.{u3, u2} α β)) => Prod.{u3, max u2 u1} α (Sum.{u1, u2} γ β)) (Sum.inr.{max u3 u1, max u2 u3} (Prod.{u3, u1} α γ) (Prod.{u3, u2} α β) a)) (FunLike.coe.{max (max (succ u2) (succ u3)) (succ u1), max (max (succ u2) (succ u3)) (succ u1), max (max (succ u2) (succ u3)) (succ u1)} (Equiv.{max (max (succ u2) (succ u3)) (succ u1), max (max (succ u2) (succ u3)) (succ u1)} (Sum.{max u1 u3, max u2 u3} (Prod.{u3, u1} α γ) (Prod.{u3, u2} α β)) (Prod.{u3, max u2 u1} α (Sum.{u1, u2} γ β))) (Sum.{max u1 u3, max u2 u3} (Prod.{u3, u1} α γ) (Prod.{u3, u2} α β)) (fun (_x : Sum.{max u1 u3, max u2 u3} (Prod.{u3, u1} α γ) (Prod.{u3, u2} α β)) => (fun ([email protected]._hyg.808 : Sum.{max u1 u3, max u2 u3} (Prod.{u3, u1} α γ) (Prod.{u3, u2} α β)) => Prod.{u3, max u2 u1} α (Sum.{u1, u2} γ β)) _x) (Equiv.instFunLikeEquiv.{max (max (succ u2) (succ u3)) (succ u1), max (max (succ u2) (succ u3)) (succ u1)} (Sum.{max u1 u3, max u2 u3} (Prod.{u3, u1} α γ) (Prod.{u3, u2} α β)) (Prod.{u3, max u2 u1} α (Sum.{u1, u2} γ β))) (Equiv.symm.{max (max (succ u2) (succ u3)) (succ u1), max (max (succ u2) (succ u3)) (succ u1)} (Prod.{u3, max u2 u1} α (Sum.{u1, u2} γ β)) (Sum.{max u1 u3, max u2 u3} (Prod.{u3, u1} α γ) (Prod.{u3, u2} α β)) (Equiv.prodSumDistrib.{u3, u1, u2} α γ β)) (Sum.inr.{max u3 u1, max u2 u3} (Prod.{u3, u1} α γ) (Prod.{u3, u2} α β) a)) (Prod.mk.{u3, max u2 u1} α (Sum.{u1, u2} γ β) (Prod.fst.{u3, u2} α β a) (Sum.inr.{u1, u2} γ β (Prod.snd.{u3, u2} α β a))) Case conversion may be inaccurate. Consider using '#align equiv.prod_sum_distrib_symm_apply_right Equiv.prodSumDistrib_symm_apply_rightₓ'. -/ @[simp] theorem prodSumDistrib_symm_apply_right {α β γ} (a : α × γ) : (prodSumDistrib α β γ).symm (inr a) = (a.1, inr a.2) := rfl #align equiv.prod_sum_distrib_symm_apply_right Equiv.prodSumDistrib_symm_apply_right #print Equiv.sigmaSumDistrib /- /-- An indexed sum of disjoint sums of types is equivalent to the sum of the indexed sums. -/ @[simps] def sigmaSumDistrib {ι : Type _} (α β : ι → Type _) : (Σi, Sum (α i) (β i)) ≃ Sum (Σi, α i) (Σi, β i) := ⟨fun p => p.2.map (Sigma.mk p.1) (Sigma.mk p.1), Sum.elim (Sigma.map id fun _ => Sum.inl) (Sigma.map id fun _ => Sum.inr), fun p => by rcases p with ⟨i, a | b⟩ <;> rfl, fun p => by rcases p with (⟨i, a⟩ | ⟨i, b⟩) <;> rfl⟩ #align equiv.sigma_sum_distrib Equiv.sigmaSumDistrib -/ #print Equiv.sigmaProdDistrib /- /-- The product of an indexed sum of types (formally, a `sigma`-type `Σ i, α i`) by a type `β` is equivalent to the sum of products `Σ i, (α i × β)`. -/ def sigmaProdDistrib {ι : Type _} (α : ι → Type _) (β : Type _) : (Σi, α i) × β ≃ Σi, α i × β := ⟨fun p => ⟨p.1.1, (p.1.2, p.2)⟩, fun p => (⟨p.1, p.2.1⟩, p.2.2), fun p => by rcases p with ⟨⟨_, _⟩, _⟩ rfl, fun p => by rcases p with ⟨_, ⟨_, _⟩⟩ rfl⟩ #align equiv.sigma_prod_distrib Equiv.sigmaProdDistrib -/ #print Equiv.sigmaNatSucc /- /-- An equivalence that separates out the 0th fiber of `(Σ (n : ℕ), f n)`. -/ def sigmaNatSucc (f : ℕ → Type u) : (Σn, f n) ≃ Sum (f 0) (Σn, f (n + 1)) := ⟨fun x => @Sigma.casesOn ℕ f (fun _ => Sum (f 0) (Σn, f (n + 1))) x fun n => @Nat.casesOn (fun i => f i → Sum (f 0) (Σn : ℕ, f (n + 1))) n (fun x : f 0 => Sum.inl x) fun (n : ℕ) (x : f n.succ) => Sum.inr ⟨n, x⟩, Sum.elim (Sigma.mk 0) (Sigma.map Nat.succ fun _ => id), by rintro ⟨n | n, x⟩ <;> rfl, by rintro (x | ⟨n, x⟩) <;> rfl⟩ #align equiv.sigma_nat_succ Equiv.sigmaNatSucc -/ #print Equiv.boolProdEquivSum /- /-- The product `bool × α` is equivalent to `α ⊕ α`. -/ @[simps] def boolProdEquivSum (α : Type u) : Bool × α ≃ Sum α α where toFun p := cond p.1 (inr p.2) (inl p.2) invFun := Sum.elim (Prod.mk false) (Prod.mk true) left_inv := by rintro ⟨_ | _, _⟩ <;> rfl right_inv := by rintro (_ | _) <;> rfl #align equiv.bool_prod_equiv_sum Equiv.boolProdEquivSum -/ #print Equiv.boolArrowEquivProd /- /-- The function type `bool → α` is equivalent to `α × α`. -/ @[simps] def boolArrowEquivProd (α : Type u) : (Bool → α) ≃ α × α where toFun f := (f true, f false) invFun p b := cond b p.1 p.2 left_inv f := funext <| Bool.forall_bool.2 ⟨rfl, rfl⟩ right_inv := fun ⟨x, y⟩ => rfl #align equiv.bool_arrow_equiv_prod Equiv.boolArrowEquivProd -/ end section open Sum Nat #print Equiv.natEquivNatSumPUnit /- /-- The set of natural numbers is equivalent to `ℕ ⊕ punit`. -/ def natEquivNatSumPUnit : ℕ ≃ Sum ℕ PUnit.{u + 1} where toFun n := Nat.casesOn n (inr PUnit.unit) inl invFun := Sum.elim Nat.succ fun _ => 0 left_inv n := by cases n <;> rfl right_inv := by rintro (_ | _ | _) <;> rfl #align equiv.nat_equiv_nat_sum_punit Equiv.natEquivNatSumPUnit -/ #print Equiv.natSumPUnitEquivNat /- /-- `ℕ ⊕ punit` is equivalent to `ℕ`. -/ def natSumPUnitEquivNat : Sum ℕ PUnit.{u + 1} ≃ ℕ := natEquivNatSumPUnit.symm #align equiv.nat_sum_punit_equiv_nat Equiv.natSumPUnitEquivNat -/ #print Equiv.intEquivNatSumNat /- /-- The type of integer numbers is equivalent to `ℕ ⊕ ℕ`. -/ def intEquivNatSumNat : ℤ ≃ Sum ℕ ℕ where toFun z := Int.casesOn z inl inr invFun := Sum.elim coe Int.negSucc left_inv := by rintro (m | n) <;> rfl right_inv := by rintro (m | n) <;> rfl #align equiv.int_equiv_nat_sum_nat Equiv.intEquivNatSumNat -/ end #print Equiv.listEquivOfEquiv /- /-- An equivalence between `α` and `β` generates an equivalence between `list α` and `list β`. -/ def listEquivOfEquiv {α β : Type _} (e : α ≃ β) : List α ≃ List β where toFun := List.map e invFun := List.map e.symm left_inv l := by rw [List.map_map, e.symm_comp_self, List.map_id] right_inv l := by rw [List.map_map, e.self_comp_symm, List.map_id] #align equiv.list_equiv_of_equiv Equiv.listEquivOfEquiv -/ #print Equiv.uniqueCongr /- /-- If `α` is equivalent to `β`, then `unique α` is equivalent to `unique β`. -/ def uniqueCongr (e : α ≃ β) : Unique α ≃ Unique β where toFun h := @Equiv.unique _ _ h e.symm invFun h := @Equiv.unique _ _ h e left_inv _ := Subsingleton.elim _ _ right_inv _ := Subsingleton.elim _ _ #align equiv.unique_congr Equiv.uniqueCongr -/ /- warning: equiv.is_empty_congr -> Equiv.isEmpty_congr is a dubious translation: lean 3 declaration is forall {α : Sort.{u1}} {β : Sort.{u2}}, (Equiv.{u1, u2} α β) -> (Iff (IsEmpty.{u1} α) (IsEmpty.{u2} β)) but is expected to have type forall {α : Sort.{u2}} {β : Sort.{u1}}, (Equiv.{u2, u1} α β) -> (Iff (IsEmpty.{u2} α) (IsEmpty.{u1} β)) Case conversion may be inaccurate. Consider using '#align equiv.is_empty_congr Equiv.isEmpty_congrₓ'. -/ /-- If `α` is equivalent to `β`, then `is_empty α` is equivalent to `is_empty β`. -/ theorem isEmpty_congr (e : α ≃ β) : IsEmpty α ↔ IsEmpty β := ⟨fun h => @Function.isEmpty _ _ h e.symm, fun h => @Function.isEmpty _ _ h e⟩ #align equiv.is_empty_congr Equiv.isEmpty_congr /- warning: equiv.is_empty -> Equiv.isEmpty is a dubious translation: lean 3 declaration is forall {α : Sort.{u1}} {β : Sort.{u2}}, (Equiv.{u1, u2} α β) -> (forall [_inst_1 : IsEmpty.{u2} β], IsEmpty.{u1} α) but is expected to have type forall {α : Sort.{u2}} {β : Sort.{u1}}, (Equiv.{u2, u1} α β) -> (forall [_inst_1 : IsEmpty.{u1} β], IsEmpty.{u2} α) Case conversion may be inaccurate. Consider using '#align equiv.is_empty Equiv.isEmptyₓ'. -/ protected theorem isEmpty (e : α ≃ β) [IsEmpty β] : IsEmpty α := e.isEmpty_congr.mpr ‹_› #align equiv.is_empty Equiv.isEmpty section open Subtype #print Equiv.subtypeEquiv /- /-- If `α` is equivalent to `β` and the predicates `p : α → Prop` and `q : β → Prop` are equivalent at corresponding points, then `{a // p a}` is equivalent to `{b // q b}`. For the statement where `α = β`, that is, `e : perm α`, see `perm.subtype_perm`. -/ def subtypeEquiv {p : α → Prop} {q : β → Prop} (e : α ≃ β) (h : ∀ a, p a ↔ q (e a)) : { a : α // p a } ≃ { b : β // q b } where toFun a := ⟨e a, (h _).mp a.Prop⟩ invFun b := ⟨e.symm b, (h _).mpr ((e.apply_symm_apply b).symm ▸ b.Prop)⟩ left_inv a := Subtype.ext <| by simp right_inv b := Subtype.ext <| by simp #align equiv.subtype_equiv Equiv.subtypeEquiv -/ #print Equiv.subtypeEquiv_refl /- @[simp] theorem subtypeEquiv_refl {p : α → Prop} (h : ∀ a, p a ↔ p (Equiv.refl _ a) := fun a => Iff.rfl) : (Equiv.refl α).subtypeEquiv h = Equiv.refl { a : α // p a } := by ext rfl #align equiv.subtype_equiv_refl Equiv.subtypeEquiv_refl -/ /- warning: equiv.subtype_equiv_symm -> Equiv.subtypeEquiv_symm is a dubious translation: lean 3 declaration is forall {α : Sort.{u1}} {β : Sort.{u2}} {p : α -> Prop} {q : β -> Prop} (e : Equiv.{u1, u2} α β) (h : forall (a : α), Iff (p a) (q (coeFn.{max 1 (imax u1 u2) (imax u2 u1), imax u1 u2} (Equiv.{u1, u2} α β) (fun (_x : Equiv.{u1, u2} α β) => α -> β) (Equiv.hasCoeToFun.{u1, u2} α β) e a))), Eq.{max 1 (max (max 1 u2) 1 u1) (max 1 u1) 1 u2} (Equiv.{max 1 u2, max 1 u1} (Subtype.{u2} β (fun (b : β) => q b)) (Subtype.{u1} α (fun (a : α) => p a))) (Equiv.symm.{max 1 u1, max 1 u2} (Subtype.{u1} α (fun (a : α) => p a)) (Subtype.{u2} β (fun (b : β) => q b)) (Equiv.subtypeEquiv.{u1, u2} α β (fun (a : α) => p a) q e h)) (Equiv.subtypeEquiv.{u2, u1} β α (fun (b : β) => q b) (fun (a : α) => p a) (Equiv.symm.{u1, u2} α β e) (fun (a : β) => Eq.mpr.{0} (Iff (q a) (p (coeFn.{max 1 (imax u2 u1) (imax u1 u2), imax u2 u1} (Equiv.{u2, u1} β α) (fun (_x : Equiv.{u2, u1} β α) => β -> α) (Equiv.hasCoeToFun.{u2, u1} β α) (Equiv.symm.{u1, u2} α β e) a))) (Iff (q (coeFn.{max 1 (imax u1 u2) (imax u2 u1), imax u1 u2} (Equiv.{u1, u2} α β) (fun (_x : Equiv.{u1, u2} α β) => α -> β) (Equiv.hasCoeToFun.{u1, u2} α β) e (coeFn.{max 1 (imax u2 u1) (imax u1 u2), imax u2 u1} (Equiv.{u2, u1} β α) (fun (_x : Equiv.{u2, u1} β α) => β -> α) (Equiv.hasCoeToFun.{u2, u1} β α) (Equiv.symm.{u1, u2} α β e) a))) (p (coeFn.{max 1 (imax u2 u1) (imax u1 u2), imax u2 u1} (Equiv.{u2, u1} β α) (fun (_x : Equiv.{u2, u1} β α) => β -> α) (Equiv.hasCoeToFun.{u2, u1} β α) (Equiv.symm.{u1, u2} α β e) a))) ((fun (a : Prop) (a_1 : Prop) (e_1 : Eq.{1} Prop a a_1) (b : Prop) (b_1 : Prop) (e_2 : Eq.{1} Prop b b_1) => congr.{1, 1} Prop Prop (Iff a) (Iff a_1) b b_1 (congr_arg.{1, 1} Prop (Prop -> Prop) a a_1 Iff e_1) e_2) (q a) (q (coeFn.{max 1 (imax u1 u2) (imax u2 u1), imax u1 u2} (Equiv.{u1, u2} α β) (fun (_x : Equiv.{u1, u2} α β) => α -> β) (Equiv.hasCoeToFun.{u1, u2} α β) e (coeFn.{max 1 (imax u2 u1) (imax u1 u2), imax u2 u1} (Equiv.{u2, u1} β α) (fun (_x : Equiv.{u2, u1} β α) => β -> α) (Equiv.hasCoeToFun.{u2, u1} β α) (Equiv.symm.{u1, u2} α β e) a))) ((fun (ᾰ : β) (ᾰ_1 : β) (e_1 : Eq.{u2} β ᾰ ᾰ_1) => congr_arg.{u2, 1} β Prop ᾰ ᾰ_1 q e_1) a (coeFn.{max 1 (imax u1 u2) (imax u2 u1), imax u1 u2} (Equiv.{u1, u2} α β) (fun (_x : Equiv.{u1, u2} α β) => α -> β) (Equiv.hasCoeToFun.{u1, u2} α β) e (coeFn.{max 1 (imax u2 u1) (imax u1 u2), imax u2 u1} (Equiv.{u2, u1} β α) (fun (_x : Equiv.{u2, u1} β α) => β -> α) (Equiv.hasCoeToFun.{u2, u1} β α) (Equiv.symm.{u1, u2} α β e) a)) (Eq.symm.{u2} β (coeFn.{max 1 (imax u1 u2) (imax u2 u1), imax u1 u2} (Equiv.{u1, u2} α β) (fun (_x : Equiv.{u1, u2} α β) => α -> β) (Equiv.hasCoeToFun.{u1, u2} α β) e (coeFn.{max 1 (imax u2 u1) (imax u1 u2), imax u2 u1} (Equiv.{u2, u1} β α) (fun (_x : Equiv.{u2, u1} β α) => β -> α) (Equiv.hasCoeToFun.{u2, u1} β α) (Equiv.symm.{u1, u2} α β e) a)) a (Equiv.apply_symm_apply.{u1, u2} α β e a))) (p (coeFn.{max 1 (imax u2 u1) (imax u1 u2), imax u2 u1} (Equiv.{u2, u1} β α) (fun (_x : Equiv.{u2, u1} β α) => β -> α) (Equiv.hasCoeToFun.{u2, u1} β α) (Equiv.symm.{u1, u2} α β e) a)) (p (coeFn.{max 1 (imax u2 u1) (imax u1 u2), imax u2 u1} (Equiv.{u2, u1} β α) (fun (_x : Equiv.{u2, u1} β α) => β -> α) (Equiv.hasCoeToFun.{u2, u1} β α) (Equiv.symm.{u1, u2} α β e) a)) (rfl.{1} Prop (p (coeFn.{max 1 (imax u2 u1) (imax u1 u2), imax u2 u1} (Equiv.{u2, u1} β α) (fun (_x : Equiv.{u2, u1} β α) => β -> α) (Equiv.hasCoeToFun.{u2, u1} β α) (Equiv.symm.{u1, u2} α β e) a)))) (Iff.symm (p (coeFn.{max 1 (imax u2 u1) (imax u1 u2), imax u2 u1} (Equiv.{u2, u1} β α) (fun (_x : Equiv.{u2, u1} β α) => β -> α) (Equiv.hasCoeToFun.{u2, u1} β α) (Equiv.symm.{u1, u2} α β e) a)) (q (coeFn.{max 1 (imax u1 u2) (imax u2 u1), imax u1 u2} (Equiv.{u1, u2} α β) (fun (_x : Equiv.{u1, u2} α β) => α -> β) (Equiv.hasCoeToFun.{u1, u2} α β) e (coeFn.{max 1 (imax u2 u1) (imax u1 u2), imax u2 u1} (Equiv.{u2, u1} β α) (fun (_x : Equiv.{u2, u1} β α) => β -> α) (Equiv.hasCoeToFun.{u2, u1} β α) (Equiv.symm.{u1, u2} α β e) a))) (h (coeFn.{max 1 (imax u2 u1) (imax u1 u2), imax u2 u1} (Equiv.{u2, u1} β α) (fun (_x : Equiv.{u2, u1} β α) => β -> α) (Equiv.hasCoeToFun.{u2, u1} β α) (Equiv.symm.{u1, u2} α β e) a))))) but is expected to have type forall {α : Sort.{u2}} {β : Sort.{u1}} {p : α -> Prop} {q : β -> Prop} (e : Equiv.{u2, u1} α β) (h : forall (a : α), Iff (p a) (q (FunLike.coe.{max (max 1 u2) u1, u2, u1} (Equiv.{u2, u1} α β) α (fun (_x : α) => (fun ([email protected]._hyg.808 : α) => β) _x) (Equiv.instFunLikeEquiv.{u2, u1} α β) e a))), Eq.{max (max 1 u2) u1} (Equiv.{max 1 u1, max 1 u2} (Subtype.{u1} β (fun (b : β) => q b)) (Subtype.{u2} α (fun (a : α) => p a))) (Equiv.symm.{max 1 u2, max 1 u1} (Subtype.{u2} α (fun (a : α) => p a)) (Subtype.{u1} β (fun (b : β) => q b)) (Equiv.subtypeEquiv.{u2, u1} α β (fun (a : α) => p a) q e h)) (Equiv.subtypeEquiv.{u1, u2} β α (fun (b : β) => q b) (fun (a : α) => p a) (Equiv.symm.{u2, u1} α β e) (fun (a : β) => Eq.mpr.{0} (Iff (q a) (p (FunLike.coe.{max (max 1 u1) u2, u1, u2} (Equiv.{u1, u2} β α) β (fun (_x : β) => (fun ([email protected]._hyg.808 : β) => α) _x) (Equiv.instFunLikeEquiv.{u1, u2} β α) (Equiv.symm.{u2, u1} α β e) a))) (Iff (q (FunLike.coe.{max (max 1 u2) u1, u2, u1} (Equiv.{u2, u1} α β) α (fun (_x : α) => (fun ([email protected]._hyg.808 : α) => β) _x) (Equiv.instFunLikeEquiv.{u2, u1} α β) e (FunLike.coe.{max (max 1 u2) u1, u1, u2} (Equiv.{u1, u2} β α) β (fun (_x : β) => (fun ([email protected]._hyg.808 : β) => α) _x) (Equiv.instFunLikeEquiv.{u1, u2} β α) (Equiv.symm.{u2, u1} α β e) a))) (p (FunLike.coe.{max (max 1 u2) u1, u1, u2} (Equiv.{u1, u2} β α) β (fun (_x : β) => (fun ([email protected]._hyg.808 : β) => α) _x) (Equiv.instFunLikeEquiv.{u1, u2} β α) (Equiv.symm.{u2, u1} α β e) a))) (eq_of_heq.{1} Prop (Iff (q a) (p (FunLike.coe.{max (max 1 u1) u2, u1, u2} (Equiv.{u1, u2} β α) β (fun (a : β) => (fun ([email protected]._hyg.808 : β) => α) a) (Equiv.instFunLikeEquiv.{u1, u2} β α) (Equiv.symm.{u2, u1} α β e) a))) (Iff (q (FunLike.coe.{max (max 1 u2) u1, u2, u1} (Equiv.{u2, u1} α β) α (fun (a : α) => (fun ([email protected]._hyg.808 : α) => β) a) (Equiv.instFunLikeEquiv.{u2, u1} α β) e (FunLike.coe.{max (max 1 u2) u1, u1, u2} (Equiv.{u1, u2} β α) β (fun (a : β) => (fun ([email protected]._hyg.808 : β) => α) a) (Equiv.instFunLikeEquiv.{u1, u2} β α) (Equiv.symm.{u2, u1} α β e) a))) (p (FunLike.coe.{max (max 1 u2) u1, u1, u2} (Equiv.{u1, u2} β α) β (fun (a : β) => (fun ([email protected]._hyg.808 : β) => α) a) (Equiv.instFunLikeEquiv.{u1, u2} β α) (Equiv.symm.{u2, u1} α β e) a))) ((fun (a : Prop) (a' : Prop) (e'_1 : Eq.{1} Prop a a') (b : Prop) => Eq.casesOn.{0, 1} Prop a (fun ([email protected]._hyg.170 : Prop) (x : Eq.{1} Prop a [email protected]._hyg.170) => (Eq.{1} Prop a' [email protected]._hyg.170) -> (HEq.{0} (Eq.{1} Prop a a') e'_1 (Eq.{1} Prop a [email protected]._hyg.170) x) -> (HEq.{1} Prop (Iff a b) Prop (Iff a' b))) a' e'_1 (fun ([email protected]._hyg.9722 : Eq.{1} Prop a' a) => Eq.ndrec.{0, 1} Prop a (fun (a'[email protected]._hyg.9719 : Prop) => forall ([email protected]._hyg.9720 : Eq.{1} Prop a a'[email protected]._hyg.9719), (HEq.{0} (Eq.{1} Prop a a'[email protected]._hyg.9719) [email protected]._hyg.9720 (Eq.{1} Prop a a) (Eq.refl.{1} Prop a)) -> (HEq.{1} Prop (Iff a b) Prop (Iff a'[email protected]._hyg.9719 b))) (fun ([email protected]._hyg.9720 : Eq.{1} Prop a a) ([email protected]._hyg.9723 : HEq.{0} (Eq.{1} Prop a a) [email protected]._hyg.9720 (Eq.{1} Prop a a) (Eq.refl.{1} Prop a)) => Eq.ndrec.{0, 0} (Eq.{1} Prop a a) (Eq.refl.{1} Prop a) (fun ([email protected]._hyg.9720 : Eq.{1} Prop a a) => HEq.{1} Prop (Iff a b) Prop (Iff a b)) (HEq.refl.{1} Prop (Iff a b)) [email protected]._hyg.9720 (Eq.symm.{0} (Eq.{1} Prop a a) [email protected]._hyg.9720 (Eq.refl.{1} Prop a) (eq_of_heq.{0} (Eq.{1} Prop a a) [email protected]._hyg.9720 (Eq.refl.{1} Prop a) [email protected]._hyg.9723))) a' (Eq.symm.{1} Prop a' a [email protected]._hyg.9722) e'_1) (Eq.refl.{1} Prop a') (HEq.refl.{0} (Eq.{1} Prop a a') e'_1)) (q a) (q (FunLike.coe.{max (max 1 u2) u1, u2, u1} (Equiv.{u2, u1} α β) α (fun (a : α) => (fun ([email protected]._hyg.808 : α) => β) a) (Equiv.instFunLikeEquiv.{u2, u1} α β) e (FunLike.coe.{max (max 1 u2) u1, u1, u2} (Equiv.{u1, u2} β α) β (fun (a : β) => (fun ([email protected]._hyg.808 : β) => α) a) (Equiv.instFunLikeEquiv.{u1, u2} β α) (Equiv.symm.{u2, u1} α β e) a))) (eq_of_heq.{1} Prop (q a) (q (FunLike.coe.{max (max 1 u2) u1, u2, u1} (Equiv.{u2, u1} α β) α (fun (a : α) => (fun ([email protected]._hyg.808 : α) => β) a) (Equiv.instFunLikeEquiv.{u2, u1} α β) e (FunLike.coe.{max (max 1 u2) u1, u1, u2} (Equiv.{u1, u2} β α) β (fun (a : β) => (fun ([email protected]._hyg.808 : β) => α) a) (Equiv.instFunLikeEquiv.{u1, u2} β α) (Equiv.symm.{u2, u1} α β e) a))) ((fun ([email protected]._hyg.9668 : β) (a'[email protected]._hyg.9668 : β) (e'_1 : Eq.{u1} β [email protected]._hyg.9668 a'[email protected]._hyg.9668) => Eq.casesOn.{0, u1} β [email protected]._hyg.9668 (fun ([email protected]._hyg.170 : β) (x : Eq.{u1} β [email protected]._hyg.9668 [email protected]._hyg.170) => (Eq.{u1} β a'[email protected]._hyg.9668 [email protected]._hyg.170) -> (HEq.{0} (Eq.{u1} β [email protected]._hyg.9668 a'[email protected]._hyg.9668) e'_1 (Eq.{u1} β [email protected]._hyg.9668 [email protected]._hyg.170) x) -> (HEq.{1} Prop (q [email protected]._hyg.9668) Prop (q a'[email protected]._hyg.9668))) a'[email protected]._hyg.9668 e'_1 (fun ([email protected]._hyg.9730 : Eq.{u1} β a'[email protected]._hyg.9668 [email protected]._hyg.9668) => Eq.ndrec.{0, u1} β [email protected]._hyg.9668 (fun (a'[email protected]._hyg.9668.9728 : β) => forall ([email protected]._hyg.9729 : Eq.{u1} β [email protected]._hyg.9668 a'[email protected]._hyg.9668.9728), (HEq.{0} (Eq.{u1} β [email protected]._hyg.9668 a'[email protected]._hyg.9668.9728) [email protected]._hyg.9729 (Eq.{u1} β [email protected]._hyg.9668 [email protected]._hyg.9668) (Eq.refl.{u1} β [email protected]._hyg.9668)) -> (HEq.{1} Prop (q [email protected]._hyg.9668) Prop (q a'[email protected]._hyg.9668.9728))) (fun ([email protected]._hyg.9729 : Eq.{u1} β [email protected]._hyg.9668 [email protected]._hyg.9668) ([email protected]._hyg.9731 : HEq.{0} (Eq.{u1} β [email protected]._hyg.9668 [email protected]._hyg.9668) [email protected]._hyg.9729 (Eq.{u1} β [email protected]._hyg.9668 [email protected]._hyg.9668) (Eq.refl.{u1} β [email protected]._hyg.9668)) => Eq.ndrec.{0, 0} (Eq.{u1} β [email protected]._hyg.9668 [email protected]._hyg.9668) (Eq.refl.{u1} β [email protected]._hyg.9668) (fun ([email protected]._hyg.9729 : Eq.{u1} β [email protected]._hyg.9668 [email protected]._hyg.9668) => HEq.{1} Prop (q [email protected]._hyg.9668) Prop (q [email protected]._hyg.9668)) (HEq.refl.{1} Prop (q [email protected]._hyg.9668)) [email protected]._hyg.9729 (Eq.symm.{0} (Eq.{u1} β [email protected]._hyg.9668 [email protected]._hyg.9668) [email protected]._hyg.9729 (Eq.refl.{u1} β [email protected]._hyg.9668) (eq_of_heq.{0} (Eq.{u1} β [email protected]._hyg.9668 [email protected]._hyg.9668) [email protected]._hyg.9729 (Eq.refl.{u1} β [email protected]._hyg.9668) [email protected]._hyg.9731))) a'[email protected]._hyg.9668 (Eq.symm.{u1} β a'[email protected]._hyg.9668 [email protected]._hyg.9668 [email protected]._hyg.9730) e'_1) (Eq.refl.{u1} β a'[email protected]._hyg.9668) (HEq.refl.{0} (Eq.{u1} β [email protected]._hyg.9668 a'[email protected]._hyg.9668) e'_1)) a (FunLike.coe.{max (max 1 u2) u1, u2, u1} (Equiv.{u2, u1} α β) α (fun (a : α) => (fun ([email protected]._hyg.808 : α) => β) a) (Equiv.instFunLikeEquiv.{u2, u1} α β) e (FunLike.coe.{max (max 1 u2) u1, u1, u2} (Equiv.{u1, u2} β α) β (fun (a : β) => (fun ([email protected]._hyg.808 : β) => α) a) (Equiv.instFunLikeEquiv.{u1, u2} β α) (Equiv.symm.{u2, u1} α β e) a)) (Eq.symm.{u1} ((fun ([email protected]._hyg.808 : α) => β) (FunLike.coe.{max (max 1 u2) u1, u1, u2} (Equiv.{u1, u2} β α) β (fun (a : β) => (fun ([email protected]._hyg.808 : β) => α) a) (Equiv.instFunLikeEquiv.{u1, u2} β α) (Equiv.symm.{u2, u1} α β e) a)) (FunLike.coe.{max (max 1 u2) u1, u2, u1} (Equiv.{u2, u1} α β) α (fun (a : α) => (fun ([email protected]._hyg.808 : α) => β) a) (Equiv.instFunLikeEquiv.{u2, u1} α β) e (FunLike.coe.{max (max 1 u2) u1, u1, u2} (Equiv.{u1, u2} β α) β (fun (a : β) => (fun ([email protected]._hyg.808 : β) => α) a) (Equiv.instFunLikeEquiv.{u1, u2} β α) (Equiv.symm.{u2, u1} α β e) a)) a (Equiv.apply_symm_apply.{u2, u1} α β e a)))) (p (FunLike.coe.{max (max 1 u1) u2, u1, u2} (Equiv.{u1, u2} β α) β (fun (_x : β) => (fun ([email protected]._hyg.808 : β) => α) _x) (Equiv.instFunLikeEquiv.{u1, u2} β α) (Equiv.symm.{u2, u1} α β e) a)))) (Iff.symm (p (FunLike.coe.{max (max 1 u2) u1, u1, u2} (Equiv.{u1, u2} β α) β (fun (_x : β) => (fun ([email protected]._hyg.808 : β) => α) _x) (Equiv.instFunLikeEquiv.{u1, u2} β α) (Equiv.symm.{u2, u1} α β e) a)) (q (FunLike.coe.{max (max 1 u2) u1, u2, u1} (Equiv.{u2, u1} α β) α (fun (_x : α) => (fun ([email protected]._hyg.808 : α) => β) _x) (Equiv.instFunLikeEquiv.{u2, u1} α β) e (FunLike.coe.{max (max 1 u2) u1, u1, u2} (Equiv.{u1, u2} β α) β (fun (_x : β) => (fun ([email protected]._hyg.808 : β) => α) _x) (Equiv.instFunLikeEquiv.{u1, u2} β α) (Equiv.symm.{u2, u1} α β e) a))) (h (FunLike.coe.{max (max 1 u2) u1, u1, u2} (Equiv.{u1, u2} β α) β (fun (_x : β) => (fun ([email protected]._hyg.808 : β) => α) _x) (Equiv.instFunLikeEquiv.{u1, u2} β α) (Equiv.symm.{u2, u1} α β e) a))))) Case conversion may be inaccurate. Consider using '#align equiv.subtype_equiv_symm Equiv.subtypeEquiv_symmₓ'. -/ @[simp] theorem subtypeEquiv_symm {p : α → Prop} {q : β → Prop} (e : α ≃ β) (h : ∀ a : α, p a ↔ q (e a)) : (e.subtypeEquiv h).symm = e.symm.subtypeEquiv fun a => by convert(h <| e.symm a).symm exact (e.apply_symm_apply a).symm := rfl #align equiv.subtype_equiv_symm Equiv.subtypeEquiv_symm /- warning: equiv.subtype_equiv_trans -> Equiv.subtypeEquiv_trans is a dubious translation: lean 3 declaration is forall {α : Sort.{u1}} {β : Sort.{u2}} {γ : Sort.{u3}} {p : α -> Prop} {q : β -> Prop} {r : γ -> Prop} (e : Equiv.{u1, u2} α β) (f : Equiv.{u2, u3} β γ) (h : forall (a : α), Iff (p a) (q (coeFn.{max 1 (imax u1 u2) (imax u2 u1), imax u1 u2} (Equiv.{u1, u2} α β) (fun (_x : Equiv.{u1, u2} α β) => α -> β) (Equiv.hasCoeToFun.{u1, u2} α β) e a))) (h' : forall (b : β), Iff (q b) (r (coeFn.{max 1 (imax u2 u3) (imax u3 u2), imax u2 u3} (Equiv.{u2, u3} β γ) (fun (_x : Equiv.{u2, u3} β γ) => β -> γ) (Equiv.hasCoeToFun.{u2, u3} β γ) f b))), Eq.{max 1 (max (max 1 u1) 1 u3) (max 1 u3) 1 u1} (Equiv.{max 1 u1, max 1 u3} (Subtype.{u1} α (fun (a : α) => p a)) (Subtype.{u3} γ (fun (b : γ) => r b))) (Equiv.trans.{max 1 u1, max 1 u2, max 1 u3} (Subtype.{u1} α (fun (a : α) => p a)) (Subtype.{u2} β (fun (b : β) => q b)) (Subtype.{u3} γ (fun (b : γ) => r b)) (Equiv.subtypeEquiv.{u1, u2} α β (fun (a : α) => p a) q e h) (Equiv.subtypeEquiv.{u2, u3} β γ (fun (b : β) => q b) r f h')) (Equiv.subtypeEquiv.{u1, u3} α γ (fun (a : α) => p a) (fun (b : γ) => r b) (Equiv.trans.{u1, u2, u3} α β γ e f) (fun (a : α) => Iff.trans (p a) (q (coeFn.{max 1 (imax u1 u2) (imax u2 u1), imax u1 u2} (Equiv.{u1, u2} α β) (fun (_x : Equiv.{u1, u2} α β) => α -> β) (Equiv.hasCoeToFun.{u1, u2} α β) e a)) (r (coeFn.{max 1 (imax u1 u3) (imax u3 u1), imax u1 u3} (Equiv.{u1, u3} α γ) (fun (_x : Equiv.{u1, u3} α γ) => α -> γ) (Equiv.hasCoeToFun.{u1, u3} α γ) (Equiv.trans.{u1, u2, u3} α β γ e f) a)) (h a) (h' (coeFn.{max 1 (imax u1 u2) (imax u2 u1), imax u1 u2} (Equiv.{u1, u2} α β) (fun (_x : Equiv.{u1, u2} α β) => α -> β) (Equiv.hasCoeToFun.{u1, u2} α β) e a)))) but is expected to have type forall {α : Sort.{u3}} {β : Sort.{u2}} {γ : Sort.{u1}} {p : α -> Prop} {q : β -> Prop} {r : γ -> Prop} (e : Equiv.{u3, u2} α β) (f : Equiv.{u2, u1} β γ) (h : forall (a : α), Iff (p a) (q (FunLike.coe.{max (max 1 u3) u2, u3, u2} (Equiv.{u3, u2} α β) α (fun (_x : α) => (fun ([email protected]._hyg.808 : α) => β) _x) (Equiv.instFunLikeEquiv.{u3, u2} α β) e a))) (h' : forall (b : β), Iff (q b) (r (FunLike.coe.{max (max 1 u2) u1, u2, u1} (Equiv.{u2, u1} β γ) β (fun (_x : β) => (fun ([email protected]._hyg.808 : β) => γ) _x) (Equiv.instFunLikeEquiv.{u2, u1} β γ) f b))), Eq.{max (max 1 u3) u1} (Equiv.{max 1 u3, max 1 u1} (Subtype.{u3} α (fun (a : α) => p a)) (Subtype.{u1} γ (fun (b : γ) => r b))) (Equiv.trans.{max 1 u3, max 1 u2, max 1 u1} (Subtype.{u3} α (fun (a : α) => p a)) (Subtype.{u2} β (fun (b : β) => q b)) (Subtype.{u1} γ (fun (b : γ) => r b)) (Equiv.subtypeEquiv.{u3, u2} α β (fun (a : α) => p a) q e h) (Equiv.subtypeEquiv.{u2, u1} β γ (fun (b : β) => q b) r f h')) (Equiv.subtypeEquiv.{u3, u1} α γ (fun (a : α) => p a) r (Equiv.trans.{u3, u2, u1} α β γ e f) (fun (a : α) => Iff.trans (p a) (q (FunLike.coe.{max (max 1 u3) u2, u3, u2} (Equiv.{u3, u2} α β) α (fun (_x : α) => (fun ([email protected]._hyg.808 : α) => β) _x) (Equiv.instFunLikeEquiv.{u3, u2} α β) e a)) (r (FunLike.coe.{max (max 1 u3) u1, u3, u1} (Equiv.{u3, u1} α γ) α (fun (_x : α) => (fun ([email protected]._hyg.808 : α) => γ) _x) (Equiv.instFunLikeEquiv.{u3, u1} α γ) (Equiv.trans.{u3, u2, u1} α β γ e f) a)) (h a) (h' (FunLike.coe.{max (max 1 u3) u2, u3, u2} (Equiv.{u3, u2} α β) α (fun (_x : α) => (fun ([email protected]._hyg.808 : α) => β) _x) (Equiv.instFunLikeEquiv.{u3, u2} α β) e a)))) Case conversion may be inaccurate. Consider using '#align equiv.subtype_equiv_trans Equiv.subtypeEquiv_transₓ'. -/ @[simp] theorem subtypeEquiv_trans {p : α → Prop} {q : β → Prop} {r : γ → Prop} (e : α ≃ β) (f : β ≃ γ) (h : ∀ a : α, p a ↔ q (e a)) (h' : ∀ b : β, q b ↔ r (f b)) : (e.subtypeEquiv h).trans (f.subtypeEquiv h') = (e.trans f).subtypeEquiv fun a => (h a).trans (h' <| e a) := rfl #align equiv.subtype_equiv_trans Equiv.subtypeEquiv_trans /- warning: equiv.subtype_equiv_apply -> Equiv.subtypeEquiv_apply is a dubious translation: lean 3 declaration is forall {α : Sort.{u1}} {β : Sort.{u2}} {p : α -> Prop} {q : β -> Prop} (e : Equiv.{u1, u2} α β) (h : forall (a : α), Iff (p a) (q (coeFn.{max 1 (imax u1 u2) (imax u2 u1), imax u1 u2} (Equiv.{u1, u2} α β) (fun (_x : Equiv.{u1, u2} α β) => α -> β) (Equiv.hasCoeToFun.{u1, u2} α β) e a))) (x : Subtype.{u1} α (fun (x : α) => p x)), Eq.{max 1 u2} (Subtype.{u2} β (fun (b : β) => q b)) (coeFn.{max 1 (max (max 1 u1) 1 u2) (max 1 u2) 1 u1, max (max 1 u1) 1 u2} (Equiv.{max 1 u1, max 1 u2} (Subtype.{u1} α (fun (a : α) => (fun (a : α) => p a) a)) (Subtype.{u2} β (fun (b : β) => q b))) (fun (_x : Equiv.{max 1 u1, max 1 u2} (Subtype.{u1} α (fun (a : α) => (fun (a : α) => p a) a)) (Subtype.{u2} β (fun (b : β) => q b))) => (Subtype.{u1} α (fun (a : α) => (fun (a : α) => p a) a)) -> (Subtype.{u2} β (fun (b : β) => q b))) (Equiv.hasCoeToFun.{max 1 u1, max 1 u2} (Subtype.{u1} α (fun (a : α) => (fun (a : α) => p a) a)) (Subtype.{u2} β (fun (b : β) => q b))) (Equiv.subtypeEquiv.{u1, u2} α β (fun (a : α) => p a) q e h) x) (Subtype.mk.{u2} β (fun (b : β) => q b) (coeFn.{max 1 (imax u1 u2) (imax u2 u1), imax u1 u2} (Equiv.{u1, u2} α β) (fun (_x : Equiv.{u1, u2} α β) => α -> β) (Equiv.hasCoeToFun.{u1, u2} α β) e ((fun (a : Sort.{max 1 u1}) (b : Sort.{u1}) [self : HasLiftT.{max 1 u1, u1} a b] => self.0) (Subtype.{u1} α (fun (x : α) => p x)) α (HasLiftT.mk.{max 1 u1, u1} (Subtype.{u1} α (fun (x : α) => p x)) α (CoeTCₓ.coe.{max 1 u1, u1} (Subtype.{u1} α (fun (x : α) => p x)) α (coeBase.{max 1 u1, u1} (Subtype.{u1} α (fun (x : α) => p x)) α (coeSubtype.{u1} α (fun (x : α) => p x))))) x)) (Iff.mp (p ((fun (a : Sort.{max 1 u1}) (b : Sort.{u1}) [self : HasLiftT.{max 1 u1, u1} a b] => self.0) (Subtype.{u1} α (fun (x : α) => p x)) α (HasLiftT.mk.{max 1 u1, u1} (Subtype.{u1} α (fun (x : α) => p x)) α (CoeTCₓ.coe.{max 1 u1, u1} (Subtype.{u1} α (fun (x : α) => p x)) α (coeBase.{max 1 u1, u1} (Subtype.{u1} α (fun (x : α) => p x)) α (coeSubtype.{u1} α (fun (x : α) => p x))))) x)) (q (coeFn.{max 1 (imax u1 u2) (imax u2 u1), imax u1 u2} (Equiv.{u1, u2} α β) (fun (_x : Equiv.{u1, u2} α β) => α -> β) (Equiv.hasCoeToFun.{u1, u2} α β) e ((fun (a : Sort.{max 1 u1}) (b : Sort.{u1}) [self : HasLiftT.{max 1 u1, u1} a b] => self.0) (Subtype.{u1} α (fun (x : α) => p x)) α (HasLiftT.mk.{max 1 u1, u1} (Subtype.{u1} α (fun (x : α) => p x)) α (CoeTCₓ.coe.{max 1 u1, u1} (Subtype.{u1} α (fun (x : α) => p x)) α (coeBase.{max 1 u1, u1} (Subtype.{u1} α (fun (x : α) => p x)) α (coeSubtype.{u1} α (fun (x : α) => p x))))) x))) (h ((fun (a : Sort.{max 1 u1}) (b : Sort.{u1}) [self : HasLiftT.{max 1 u1, u1} a b] => self.0) (Subtype.{u1} α (fun (x : α) => p x)) α (HasLiftT.mk.{max 1 u1, u1} (Subtype.{u1} α (fun (x : α) => p x)) α (CoeTCₓ.coe.{max 1 u1, u1} (Subtype.{u1} α (fun (x : α) => p x)) α (coeBase.{max 1 u1, u1} (Subtype.{u1} α (fun (x : α) => p x)) α (coeSubtype.{u1} α (fun (x : α) => p x))))) x)) (Subtype.property.{u1} α (fun (x : α) => p x) x))) but is expected to have type forall {α : Sort.{u2}} {β : Sort.{u1}} {p : α -> Prop} {q : β -> Prop} (e : Equiv.{u2, u1} α β) (h : forall (a : α), Iff (p a) (q (FunLike.coe.{max (max 1 u2) u1, u2, u1} (Equiv.{u2, u1} α β) α (fun (_x : α) => (fun ([email protected]._hyg.808 : α) => β) _x) (Equiv.instFunLikeEquiv.{u2, u1} α β) e a))) (x : Subtype.{u2} α (fun (x : α) => p x)), Eq.{max 1 u1} ((fun ([email protected]._hyg.808 : Subtype.{u2} α (fun (a : α) => p a)) => Subtype.{u1} β (fun (b : β) => q b)) x) (FunLike.coe.{max (max 1 u2) u1, max 1 u2, max 1 u1} (Equiv.{max 1 u2, max 1 u1} (Subtype.{u2} α (fun (a : α) => p a)) (Subtype.{u1} β (fun (b : β) => q b))) (Subtype.{u2} α (fun (a : α) => p a)) (fun (_x : Subtype.{u2} α (fun (a : α) => p a)) => (fun ([email protected]._hyg.808 : Subtype.{u2} α (fun (a : α) => p a)) => Subtype.{u1} β (fun (b : β) => q b)) _x) (Equiv.instFunLikeEquiv.{max 1 u2, max 1 u1} (Subtype.{u2} α (fun (a : α) => p a)) (Subtype.{u1} β (fun (b : β) => q b))) (Equiv.subtypeEquiv.{u2, u1} α β (fun (a : α) => p a) q e h) x) (Subtype.mk.{u1} β (fun (b : β) => q b) (FunLike.coe.{max (max 1 u2) u1, u2, u1} (Equiv.{u2, u1} α β) α (fun (_x : α) => (fun ([email protected]._hyg.808 : α) => β) _x) (Equiv.instFunLikeEquiv.{u2, u1} α β) e (Subtype.val.{u2} α (fun (x : α) => p x) x)) (Iff.mp (p (Subtype.val.{u2} α (fun (x : α) => p x) x)) (q (FunLike.coe.{max (max 1 u2) u1, u2, u1} (Equiv.{u2, u1} α β) α (fun (_x : α) => (fun ([email protected]._hyg.808 : α) => β) _x) (Equiv.instFunLikeEquiv.{u2, u1} α β) e (Subtype.val.{u2} α (fun (x : α) => p x) x))) (h (Subtype.val.{u2} α (fun (x : α) => p x) x)) (Subtype.property.{u2} α (fun (x : α) => p x) x))) Case conversion may be inaccurate. Consider using '#align equiv.subtype_equiv_apply Equiv.subtypeEquiv_applyₓ'. -/ @[simp] theorem subtypeEquiv_apply {p : α → Prop} {q : β → Prop} (e : α ≃ β) (h : ∀ a : α, p a ↔ q (e a)) (x : { x // p x }) : e.subtypeEquiv h x = ⟨e x, (h _).1 x.2⟩ := rfl #align equiv.subtype_equiv_apply Equiv.subtypeEquiv_apply #print Equiv.subtypeEquivRight /- /-- If two predicates `p` and `q` are pointwise equivalent, then `{x // p x}` is equivalent to `{x // q x}`. -/ @[simps] def subtypeEquivRight {p q : α → Prop} (e : ∀ x, p x ↔ q x) : { x // p x } ≃ { x // q x } := subtypeEquiv (Equiv.refl _) e #align equiv.subtype_equiv_right Equiv.subtypeEquivRight -/ /- warning: equiv.subtype_equiv_of_subtype -> Equiv.subtypeEquivOfSubtype is a dubious translation: lean 3 declaration is forall {α : Sort.{u1}} {β : Sort.{u2}} {p : β -> Prop} (e : Equiv.{u1, u2} α β), Equiv.{max 1 u1, max 1 u2} (Subtype.{u1} α (fun (a : α) => p (coeFn.{max 1 (imax u1 u2) (imax u2 u1), imax u1 u2} (Equiv.{u1, u2} α β) (fun (_x : Equiv.{u1, u2} α β) => α -> β) (Equiv.hasCoeToFun.{u1, u2} α β) e a))) (Subtype.{u2} β (fun (b : β) => p b)) but is expected to have type forall {α : Sort.{u1}} {β : Sort.{u2}} {p : α -> Prop} (e : Equiv.{u2, u1} β α), Equiv.{max 1 u2, max 1 u1} (Subtype.{u2} β (fun (a : β) => p (FunLike.coe.{max (max 1 u1) u2, u2, u1} (Equiv.{u2, u1} β α) β (fun (_x : β) => (fun ([email protected]._hyg.808 : β) => α) _x) (Equiv.instFunLikeEquiv.{u2, u1} β α) e a))) (Subtype.{u1} α (fun (b : α) => p b)) Case conversion may be inaccurate. Consider using '#align equiv.subtype_equiv_of_subtype Equiv.subtypeEquivOfSubtypeₓ'. -/ /-- If `α ≃ β`, then for any predicate `p : β → Prop` the subtype `{a // p (e a)}` is equivalent to the subtype `{b // p b}`. -/ def subtypeEquivOfSubtype {p : β → Prop} (e : α ≃ β) : { a : α // p (e a) } ≃ { b : β // p b } := subtypeEquiv e <| by simp #align equiv.subtype_equiv_of_subtype Equiv.subtypeEquivOfSubtype #print Equiv.subtypeEquivOfSubtype' /- /-- If `α ≃ β`, then for any predicate `p : α → Prop` the subtype `{a // p a}` is equivalent to the subtype `{b // p (e.symm b)}`. This version is used by `equiv_rw`. -/ def subtypeEquivOfSubtype' {p : α → Prop} (e : α ≃ β) : { a : α // p a } ≃ { b : β // p (e.symm b) } := e.symm.subtypeEquivOfSubtype.symm #align equiv.subtype_equiv_of_subtype' Equiv.subtypeEquivOfSubtype' -/ #print Equiv.subtypeEquivProp /- /-- If two predicates are equal, then the corresponding subtypes are equivalent. -/ def subtypeEquivProp {α : Sort _} {p q : α → Prop} (h : p = q) : Subtype p ≃ Subtype q := subtypeEquiv (Equiv.refl α) fun a => h ▸ Iff.rfl #align equiv.subtype_equiv_prop Equiv.subtypeEquivProp -/ #print Equiv.subtypeSubtypeEquivSubtypeExists /- /-- A subtype of a subtype is equivalent to the subtype of elements satisfying both predicates. This version allows the “inner” predicate to depend on `h : p a`. -/ @[simps] def subtypeSubtypeEquivSubtypeExists {α : Sort u} (p : α → Prop) (q : Subtype p → Prop) : Subtype q ≃ { a : α // ∃ h : p a, q ⟨a, h⟩ } := ⟨fun a => ⟨a, a.1.2, by rcases a with ⟨⟨a, hap⟩, haq⟩ exact haq⟩, fun a => ⟨⟨a, a.2.fst⟩, a.2.snd⟩, fun ⟨⟨a, ha⟩, h⟩ => rfl, fun ⟨a, h₁, h₂⟩ => rfl⟩ #align equiv.subtype_subtype_equiv_subtype_exists Equiv.subtypeSubtypeEquivSubtypeExists -/ /- warning: equiv.subtype_subtype_equiv_subtype_inter -> Equiv.subtypeSubtypeEquivSubtypeInter is a dubious translation: lean 3 declaration is forall {α : Sort.{u1}} (p : α -> Prop) (q : α -> Prop), Equiv.{max 1 u1, max 1 u1} (Subtype.{max 1 u1} (Subtype.{u1} α p) (fun (x : Subtype.{u1} α p) => q (Subtype.val.{u1} α p x))) (Subtype.{u1} α (fun (x : α) => And (p x) (q x))) but is expected to have type forall {α : Type.{u1}} (p : α -> Prop) (q : α -> Prop), Equiv.{succ u1, succ u1} (Subtype.{succ u1} (Subtype.{succ u1} α p) (fun (x : Subtype.{succ u1} α p) => q (Subtype.val.{succ u1} α p x))) (Subtype.{succ u1} α (fun (x : α) => And (p x) (q x))) Case conversion may be inaccurate. Consider using '#align equiv.subtype_subtype_equiv_subtype_inter Equiv.subtypeSubtypeEquivSubtypeInterₓ'. -/ /-- A subtype of a subtype is equivalent to the subtype of elements satisfying both predicates. -/ @[simps] def subtypeSubtypeEquivSubtypeInter {α : Sort u} (p q : α → Prop) : { x : Subtype p // q x.1 } ≃ Subtype fun x => p x ∧ q x := (subtypeSubtypeEquivSubtypeExists p _).trans <| subtypeEquivRight fun x => exists_prop #align equiv.subtype_subtype_equiv_subtype_inter Equiv.subtypeSubtypeEquivSubtypeInter #print Equiv.subtypeSubtypeEquivSubtype /- /-- If the outer subtype has more restrictive predicate than the inner one, then we can drop the latter. -/ @[simps] def subtypeSubtypeEquivSubtype {α : Type u} {p q : α → Prop} (h : ∀ {x}, q x → p x) : { x : Subtype p // q x.1 } ≃ Subtype q := (subtypeSubtypeEquivSubtypeInter p _).trans <| subtypeEquivRight fun x => and_iff_right_of_imp h #align equiv.subtype_subtype_equiv_subtype Equiv.subtypeSubtypeEquivSubtype -/ #print Equiv.subtypeUnivEquiv /- /-- If a proposition holds for all elements, then the subtype is equivalent to the original type. -/ @[simps apply symm_apply] def subtypeUnivEquiv {α : Type u} {p : α → Prop} (h : ∀ x, p x) : Subtype p ≃ α := ⟨fun x => x, fun x => ⟨x, h x⟩, fun x => Subtype.eq rfl, fun x => rfl⟩ #align equiv.subtype_univ_equiv Equiv.subtypeUnivEquiv -/ /- warning: equiv.subtype_sigma_equiv -> Equiv.subtypeSigmaEquiv is a dubious translation: lean 3 declaration is forall {α : Type.{u1}} (p : α -> Type.{u2}) (q : α -> Prop), Equiv.{max 1 (succ u1) (succ u2), max (succ u1) (succ u2)} (Subtype.{max (succ u1) (succ u2)} (Sigma.{u1, u2} α p) (fun (y : Sigma.{u1, u2} α p) => q (Sigma.fst.{u1, u2} α p y))) (Sigma.{u1, u2} (Subtype.{succ u1} α q) (fun (x : Subtype.{succ u1} α q) => p (Subtype.val.{succ u1} α q x))) but is expected to have type forall {α : Type.{u2}} (p : α -> Type.{u1}) (q : α -> Prop), Equiv.{max 1 (succ u1) (succ u2), max (succ u1) (succ u2)} (Subtype.{max (succ u1) (succ u2)} (Sigma.{u2, u1} α p) (fun (y : Sigma.{u2, u1} α p) => q (Sigma.fst.{u2, u1} α p y))) (Sigma.{u2, u1} (Subtype.{succ u2} α q) (fun (x : Subtype.{succ u2} α q) => p (Subtype.val.{succ u2} α q x))) Case conversion may be inaccurate. Consider using '#align equiv.subtype_sigma_equiv Equiv.subtypeSigmaEquivₓ'. -/ /-- A subtype of a sigma-type is a sigma-type over a subtype. -/ def subtypeSigmaEquiv {α : Type u} (p : α → Type v) (q : α → Prop) : { y : Sigma p // q y.1 } ≃ Σx : Subtype q, p x.1 := ⟨fun x => ⟨⟨x.1.1, x.2⟩, x.1.2⟩, fun x => ⟨⟨x.1.1, x.2⟩, x.1.2⟩, fun ⟨⟨x, h⟩, y⟩ => rfl, fun ⟨⟨x, y⟩, h⟩ => rfl⟩ #align equiv.subtype_sigma_equiv Equiv.subtypeSigmaEquiv /- warning: equiv.sigma_subtype_equiv_of_subset -> Equiv.sigmaSubtypeEquivOfSubset is a dubious translation: lean 3 declaration is forall {α : Type.{u1}} (p : α -> Type.{u2}) (q : α -> Prop), (forall (x : α), (p x) -> (q x)) -> (Equiv.{max (succ u1) (succ u2), max (succ u1) (succ u2)} (Sigma.{u1, u2} (Subtype.{succ u1} α q) (fun (x : Subtype.{succ u1} α q) => p ((fun (a : Type.{u1}) (b : Type.{u1}) [self : HasLiftT.{succ u1, succ u1} a b] => self.0) (Subtype.{succ u1} α q) α (HasLiftT.mk.{succ u1, succ u1} (Subtype.{succ u1} α q) α (CoeTCₓ.coe.{succ u1, succ u1} (Subtype.{succ u1} α q) α (coeBase.{succ u1, succ u1} (Subtype.{succ u1} α q) α (coeSubtype.{succ u1} α (fun (x : α) => q x))))) x))) (Sigma.{u1, u2} α (fun (x : α) => p x))) but is expected to have type forall {α : Type.{u2}} (p : α -> Type.{u1}) (q : α -> Prop), (forall (x : α), (p x) -> (q x)) -> (Equiv.{max (succ u1) (succ u2), max (succ u1) (succ u2)} (Sigma.{u2, u1} (Subtype.{succ u2} α q) (fun (x : Subtype.{succ u2} α q) => p (Subtype.val.{succ u2} α q x))) (Sigma.{u2, u1} α (fun (x : α) => p x))) Case conversion may be inaccurate. Consider using '#align equiv.sigma_subtype_equiv_of_subset Equiv.sigmaSubtypeEquivOfSubsetₓ'. -/ /-- A sigma type over a subtype is equivalent to the sigma set over the original type, if the fiber is empty outside of the subset -/ def sigmaSubtypeEquivOfSubset {α : Type u} (p : α → Type v) (q : α → Prop) (h : ∀ x, p x → q x) : (Σx : Subtype q, p x) ≃ Σx : α, p x := (subtypeSigmaEquiv p q).symm.trans <| subtypeUnivEquiv fun x => h x.1 x.2 #align equiv.sigma_subtype_equiv_of_subset Equiv.sigmaSubtypeEquivOfSubset #print Equiv.sigmaSubtypeFiberEquiv /- /-- If a predicate `p : β → Prop` is true on the range of a map `f : α → β`, then `Σ y : {y // p y}, {x // f x = y}` is equivalent to `α`. -/ def sigmaSubtypeFiberEquiv {α : Type u} {β : Type v} (f : α → β) (p : β → Prop) (h : ∀ x, p (f x)) : (Σy : Subtype p, { x : α // f x = y }) ≃ α := calc _ ≃ Σy : β, { x : α // f x = y } := sigmaSubtypeEquivOfSubset _ p fun y ⟨x, h'⟩ => h' ▸ h x _ ≃ α := sigmaFiberEquiv f #align equiv.sigma_subtype_fiber_equiv Equiv.sigmaSubtypeFiberEquiv -/ #print Equiv.sigmaSubtypeFiberEquivSubtype /- /-- If for each `x` we have `p x ↔ q (f x)`, then `Σ y : {y // q y}, f ⁻¹' {y}` is equivalent to `{x // p x}`. -/ def sigmaSubtypeFiberEquivSubtype {α : Type u} {β : Type v} (f : α → β) {p : α → Prop} {q : β → Prop} (h : ∀ x, p x ↔ q (f x)) : (Σy : Subtype q, { x : α // f x = y }) ≃ Subtype p := calc (Σy : Subtype q, { x : α // f x = y }) ≃ Σy : Subtype q, { x : Subtype p // Subtype.mk (f x) ((h x).1 x.2) = y } := by apply sigma_congr_right intro y symm refine' (subtype_subtype_equiv_subtype_exists _ _).trans (subtype_equiv_right _) intro x exact ⟨fun ⟨hp, h'⟩ => congr_arg Subtype.val h', fun h' => ⟨(h x).2 (h'.symm ▸ y.2), Subtype.eq h'⟩⟩ _ ≃ Subtype p := sigmaFiberEquiv fun x : Subtype p => (⟨f x, (h x).1 x.property⟩ : Subtype q) #align equiv.sigma_subtype_fiber_equiv_subtype Equiv.sigmaSubtypeFiberEquivSubtype -/ /- warning: equiv.sigma_option_equiv_of_some -> Equiv.sigmaOptionEquivOfSome is a dubious translation: lean 3 declaration is forall {α : Type.{u1}} (p : (Option.{u1} α) -> Type.{u2}), ((p (Option.none.{u1} α)) -> False) -> (Equiv.{max (succ u1) (succ u2), max (succ u1) (succ u2)} (Sigma.{u1, u2} (Option.{u1} α) (fun (x : Option.{u1} α) => p x)) (Sigma.{u1, u2} α (fun (x : α) => p (Option.some.{u1} α x)))) but is expected to have type forall {α : Type.{u2}} (p : (Option.{u2} α) -> Type.{u1}), ((p (Option.none.{u2} α)) -> False) -> (Equiv.{max (succ u1) (succ u2), max (succ u1) (succ u2)} (Sigma.{u2, u1} (Option.{u2} α) (fun (x : Option.{u2} α) => p x)) (Sigma.{u2, u1} α (fun (x : α) => p (Option.some.{u2} α x)))) Case conversion may be inaccurate. Consider using '#align equiv.sigma_option_equiv_of_some Equiv.sigmaOptionEquivOfSomeₓ'. -/ /-- A sigma type over an `option` is equivalent to the sigma set over the original type, if the fiber is empty at none. -/ def sigmaOptionEquivOfSome {α : Type u} (p : Option α → Type v) (h : p none → False) : (Σx : Option α, p x) ≃ Σx : α, p (some x) := haveI h' : ∀ x, p x → x.isSome := by intro x cases x · intro n exfalso exact h n · intro s exact rfl (sigma_subtype_equiv_of_subset _ _ h').symm.trans (sigma_congr_left' (option_is_some_equiv α)) #align equiv.sigma_option_equiv_of_some Equiv.sigmaOptionEquivOfSome #print Equiv.piEquivSubtypeSigma /- /-- The `pi`-type `Π i, π i` is equivalent to the type of sections `f : ι → Σ i, π i` of the `sigma` type such that for all `i` we have `(f i).fst = i`. -/ def piEquivSubtypeSigma (ι : Type _) (π : ι → Type _) : (∀ i, π i) ≃ { f : ι → Σi, π i // ∀ i, (f i).1 = i } := ⟨fun f => ⟨fun i => ⟨i, f i⟩, fun i => rfl⟩, fun f i => by rw [← f.2 i]; exact (f.1 i).2, fun f => funext fun i => rfl, fun ⟨f, hf⟩ => Subtype.eq <| funext fun i => Sigma.eq (hf i).symm <| eq_of_hEq <| rec_heq_of_heq _ <| rec_heq_of_heq _ <| HEq.refl _⟩ #align equiv.pi_equiv_subtype_sigma Equiv.piEquivSubtypeSigma -/ /- warning: equiv.subtype_pi_equiv_pi -> Equiv.subtypePiEquivPi is a dubious translation: lean 3 declaration is forall {α : Sort.{u1}} {β : α -> Sort.{u2}} {p : forall (a : α), (β a) -> Prop}, Equiv.{max 1 (imax u1 u2), max u1 1 u2} (Subtype.{imax u1 u2} (forall (a : α), β a) (fun (f : forall (a : α), β a) => forall (a : α), p a (f a))) (forall (a : α), Subtype.{u2} (β a) (fun (b : β a) => p a b)) but is expected to have type forall {α : Sort.{u2}} {β : α -> Sort.{u1}} {p : forall (a : α), (β a) -> Prop}, Equiv.{max 1 (imax u2 u1), max (max 1 u1) u2} (Subtype.{imax u2 u1} (forall (a : α), β a) (fun (f : forall (a : α), β a) => forall (a : α), p a (f a))) (forall (a : α), Subtype.{u1} (β a) (fun (b : β a) => p a b)) Case conversion may be inaccurate. Consider using '#align equiv.subtype_pi_equiv_pi Equiv.subtypePiEquivPiₓ'. -/ /-- The set of functions `f : Π a, β a` such that for all `a` we have `p a (f a)` is equivalent to the set of functions `Π a, {b : β a // p a b}`. -/ def subtypePiEquivPi {α : Sort u} {β : α → Sort v} {p : ∀ a, β a → Prop} : { f : ∀ a, β a // ∀ a, p a (f a) } ≃ ∀ a, { b : β a // p a b } := ⟨fun f a => ⟨f.1 a, f.2 a⟩, fun f => ⟨fun a => (f a).1, fun a => (f a).2⟩, by rintro ⟨f, h⟩ rfl, by rintro f funext a exact Subtype.ext_val rfl⟩ #align equiv.subtype_pi_equiv_pi Equiv.subtypePiEquivPi #print Equiv.subtypeProdEquivProd /- /-- A subtype of a product defined by componentwise conditions is equivalent to a product of subtypes. -/ def subtypeProdEquivProd {α : Type u} {β : Type v} {p : α → Prop} {q : β → Prop} : { c : α × β // p c.1 ∧ q c.2 } ≃ { a // p a } × { b // q b } := ⟨fun x => ⟨⟨x.1.1, x.2.1⟩, ⟨x.1.2, x.2.2⟩⟩, fun x => ⟨⟨x.1.1, x.2.1⟩, ⟨x.1.2, x.2.2⟩⟩, fun ⟨⟨_, _⟩, ⟨_, _⟩⟩ => rfl, fun ⟨⟨_, _⟩, ⟨_, _⟩⟩ => rfl⟩ #align equiv.subtype_prod_equiv_prod Equiv.subtypeProdEquivProd -/ #print Equiv.subtypeProdEquivSigmaSubtype /- /-- A subtype of a `prod` is equivalent to a sigma type whose fibers are subtypes. -/ def subtypeProdEquivSigmaSubtype {α β : Type _} (p : α → β → Prop) : { x : α × β // p x.1 x.2 } ≃ Σa, { b : β // p a b } where toFun x := ⟨x.1.1, x.1.2, x.Prop⟩ invFun x := ⟨⟨x.1, x.2⟩, x.2.Prop⟩ left_inv x := by ext <;> rfl right_inv := fun ⟨a, b, pab⟩ => rfl #align equiv.subtype_prod_equiv_sigma_subtype Equiv.subtypeProdEquivSigmaSubtype -/ #print Equiv.piEquivPiSubtypeProd /- /-- The type `Π (i : α), β i` can be split as a product by separating the indices in `α` depending on whether they satisfy a predicate `p` or not. -/ @[simps] def piEquivPiSubtypeProd {α : Type _} (p : α → Prop) (β : α → Type _) [DecidablePred p] : (∀ i : α, β i) ≃ (∀ i : { x // p x }, β i) × ∀ i : { x // ¬p x }, β i where toFun f := (fun x => f x, fun x => f x) invFun f x := if h : p x then f.1 ⟨x, h⟩ else f.2 ⟨x, h⟩ right_inv := by rintro ⟨f, g⟩ ext1 <;> · ext y rcases y with ⟨⟩ simp only [y_property, dif_pos, dif_neg, not_false_iff, Subtype.coe_mk] rfl left_inv f := by ext x by_cases h : p x <;> · simp only [h, dif_neg, dif_pos, not_false_iff] rfl #align equiv.pi_equiv_pi_subtype_prod Equiv.piEquivPiSubtypeProd -/ #print Equiv.piSplitAt /- /-- A product of types can be split as the binary product of one of the types and the product of all the remaining types. -/ @[simps] def piSplitAt {α : Type _} [DecidableEq α] (i : α) (β : α → Type _) : (∀ j, β j) ≃ β i × ∀ j : { j // j ≠ i }, β j where toFun f := ⟨f i, fun j => f j⟩ invFun f j := if h : j = i then h.symm.rec f.1 else f.2 ⟨j, h⟩ right_inv f := by ext exacts[dif_pos rfl, (dif_neg x.2).trans (by cases x <;> rfl)] left_inv f := by ext dsimp only split_ifs · subst h · rfl #align equiv.pi_split_at Equiv.piSplitAt -/ #print Equiv.funSplitAt /- /-- A product of copies of a type can be split as the binary product of one copy and the product of all the remaining copies. -/ @[simps] def funSplitAt {α : Type _} [DecidableEq α] (i : α) (β : Type _) : (α → β) ≃ β × ({ j // j ≠ i } → β) := piSplitAt i _ #align equiv.fun_split_at Equiv.funSplitAt -/ end section SubtypeEquivCodomain variable {X : Type _} {Y : Type _} [DecidableEq X] {x : X} /- warning: equiv.subtype_equiv_codomain -> Equiv.subtypeEquivCodomain is a dubious translation: lean 3 declaration is forall {X : Type.{u1}} {Y : Type.{u2}} [_inst_1 : DecidableEq.{succ u1} X] {x : X} (f : (Subtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x)) -> Y), Equiv.{max 1 (succ u1) (succ u2), succ u2} (Subtype.{max (succ u1) (succ u2)} (X -> Y) (fun (g : X -> Y) => Eq.{max (succ u1) (succ u2)} ((Subtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x)) -> Y) (Function.comp.{succ u1, succ u1, succ u2} (Subtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x)) X Y g ((fun (a : Type.{u1}) (b : Type.{u1}) [self : HasLiftT.{succ u1, succ u1} a b] => self.0) (Subtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x)) X (HasLiftT.mk.{succ u1, succ u1} (Subtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x)) X (CoeTCₓ.coe.{succ u1, succ u1} (Subtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x)) X (coeBase.{succ u1, succ u1} (Subtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x)) X (coeSubtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x))))))) f)) Y but is expected to have type forall {X : Sort.{u1}} [Y : DecidableEq.{u1} X] {_inst_1 : X} {x : Sort.{u2}} (f : (Subtype.{u1} X (fun (x' : X) => Ne.{u1} X x' _inst_1)) -> x), Equiv.{max 1 (imax u1 u2), u2} (Subtype.{imax u1 u2} (X -> x) (fun (g : X -> x) => Eq.{imax (max 1 u1) u2} ((Subtype.{u1} X (fun (x' : X) => Ne.{u1} X x' _inst_1)) -> x) (Function.comp.{max 1 u1, u1, u2} (Subtype.{u1} X (fun (x' : X) => Ne.{u1} X x' _inst_1)) X x g (Subtype.val.{u1} X (fun (x' : X) => Ne.{u1} X x' _inst_1))) f)) x Case conversion may be inaccurate. Consider using '#align equiv.subtype_equiv_codomain Equiv.subtypeEquivCodomainₓ'. -/ /-- The type of all functions `X → Y` with prescribed values for all `x' ≠ x` is equivalent to the codomain `Y`. -/ def subtypeEquivCodomain (f : { x' // x' ≠ x } → Y) : { g : X → Y // g ∘ coe = f } ≃ Y := (subtypePreimage _ f).trans <| @funUnique { x' // ¬x' ≠ x } _ <| show Unique { x' // ¬x' ≠ x } from @Equiv.unique _ _ (show Unique { x' // x' = x } from { default := ⟨x, rfl⟩ uniq := fun ⟨x', h⟩ => Subtype.val_injective h }) (subtypeEquivRight fun a => Classical.not_not) #align equiv.subtype_equiv_codomain Equiv.subtypeEquivCodomain /- warning: equiv.coe_subtype_equiv_codomain -> Equiv.coe_subtypeEquivCodomain is a dubious translation: lean 3 declaration is forall {X : Type.{u1}} {Y : Type.{u2}} [_inst_1 : DecidableEq.{succ u1} X] {x : X} (f : (Subtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x)) -> Y), Eq.{max (max 1 (succ u1) (succ u2)) (succ u2)} ((fun (_x : Equiv.{max 1 (succ u1) (succ u2), succ u2} (Subtype.{max (succ u1) (succ u2)} (X -> Y) (fun (g : X -> Y) => Eq.{max (succ u1) (succ u2)} ((Subtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x)) -> Y) (Function.comp.{succ u1, succ u1, succ u2} (Subtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x)) X Y g ((fun (a : Type.{u1}) (b : Type.{u1}) [self : HasLiftT.{succ u1, succ u1} a b] => self.0) (Subtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x)) X (HasLiftT.mk.{succ u1, succ u1} (Subtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x)) X (CoeTCₓ.coe.{succ u1, succ u1} (Subtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x)) X (coeBase.{succ u1, succ u1} (Subtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x)) X (coeSubtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x))))))) f)) Y) => (Subtype.{max (succ u1) (succ u2)} (X -> Y) (fun (g : X -> Y) => Eq.{max (succ u1) (succ u2)} ((Subtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x)) -> Y) (Function.comp.{succ u1, succ u1, succ u2} (Subtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x)) X Y g ((fun (a : Type.{u1}) (b : Type.{u1}) [self : HasLiftT.{succ u1, succ u1} a b] => self.0) (Subtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x)) X (HasLiftT.mk.{succ u1, succ u1} (Subtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x)) X (CoeTCₓ.coe.{succ u1, succ u1} (Subtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x)) X (coeBase.{succ u1, succ u1} (Subtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x)) X (coeSubtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x))))))) f)) -> Y) (Equiv.subtypeEquivCodomain.{u1, u2} X Y (fun (a : X) (b : X) => _inst_1 a b) x f)) (coeFn.{max 1 (max (max 1 (succ u1) (succ u2)) (succ u2)) (succ u2) 1 (succ u1) (succ u2), max (max 1 (succ u1) (succ u2)) (succ u2)} (Equiv.{max 1 (succ u1) (succ u2), succ u2} (Subtype.{max (succ u1) (succ u2)} (X -> Y) (fun (g : X -> Y) => Eq.{max (succ u1) (succ u2)} ((Subtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x)) -> Y) (Function.comp.{succ u1, succ u1, succ u2} (Subtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x)) X Y g ((fun (a : Type.{u1}) (b : Type.{u1}) [self : HasLiftT.{succ u1, succ u1} a b] => self.0) (Subtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x)) X (HasLiftT.mk.{succ u1, succ u1} (Subtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x)) X (CoeTCₓ.coe.{succ u1, succ u1} (Subtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x)) X (coeBase.{succ u1, succ u1} (Subtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x)) X (coeSubtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x))))))) f)) Y) (fun (_x : Equiv.{max 1 (succ u1) (succ u2), succ u2} (Subtype.{max (succ u1) (succ u2)} (X -> Y) (fun (g : X -> Y) => Eq.{max (succ u1) (succ u2)} ((Subtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x)) -> Y) (Function.comp.{succ u1, succ u1, succ u2} (Subtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x)) X Y g ((fun (a : Type.{u1}) (b : Type.{u1}) [self : HasLiftT.{succ u1, succ u1} a b] => self.0) (Subtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x)) X (HasLiftT.mk.{succ u1, succ u1} (Subtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x)) X (CoeTCₓ.coe.{succ u1, succ u1} (Subtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x)) X (coeBase.{succ u1, succ u1} (Subtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x)) X (coeSubtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x))))))) f)) Y) => (Subtype.{max (succ u1) (succ u2)} (X -> Y) (fun (g : X -> Y) => Eq.{max (succ u1) (succ u2)} ((Subtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x)) -> Y) (Function.comp.{succ u1, succ u1, succ u2} (Subtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x)) X Y g ((fun (a : Type.{u1}) (b : Type.{u1}) [self : HasLiftT.{succ u1, succ u1} a b] => self.0) (Subtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x)) X (HasLiftT.mk.{succ u1, succ u1} (Subtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x)) X (CoeTCₓ.coe.{succ u1, succ u1} (Subtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x)) X (coeBase.{succ u1, succ u1} (Subtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x)) X (coeSubtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x))))))) f)) -> Y) (Equiv.hasCoeToFun.{max 1 (succ u1) (succ u2), succ u2} (Subtype.{max (succ u1) (succ u2)} (X -> Y) (fun (g : X -> Y) => Eq.{max (succ u1) (succ u2)} ((Subtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x)) -> Y) (Function.comp.{succ u1, succ u1, succ u2} (Subtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x)) X Y g ((fun (a : Type.{u1}) (b : Type.{u1}) [self : HasLiftT.{succ u1, succ u1} a b] => self.0) (Subtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x)) X (HasLiftT.mk.{succ u1, succ u1} (Subtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x)) X (CoeTCₓ.coe.{succ u1, succ u1} (Subtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x)) X (coeBase.{succ u1, succ u1} (Subtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x)) X (coeSubtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x))))))) f)) Y) (Equiv.subtypeEquivCodomain.{u1, u2} X Y (fun (a : X) (b : X) => _inst_1 a b) x f)) (fun (g : Subtype.{max (succ u1) (succ u2)} (X -> Y) (fun (g : X -> Y) => Eq.{max (succ u1) (succ u2)} ((Subtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x)) -> Y) (Function.comp.{succ u1, succ u1, succ u2} (Subtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x)) X Y g ((fun (a : Type.{u1}) (b : Type.{u1}) [self : HasLiftT.{succ u1, succ u1} a b] => self.0) (Subtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x)) X (HasLiftT.mk.{succ u1, succ u1} (Subtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x)) X (CoeTCₓ.coe.{succ u1, succ u1} (Subtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x)) X (coeBase.{succ u1, succ u1} (Subtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x)) X (coeSubtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x))))))) f)) => (fun (a : Sort.{max 1 (succ u1) (succ u2)}) (b : Sort.{max (succ u1) (succ u2)}) [self : HasLiftT.{max 1 (succ u1) (succ u2), max (succ u1) (succ u2)} a b] => self.0) (Subtype.{max (succ u1) (succ u2)} (X -> Y) (fun (g : X -> Y) => Eq.{max (succ u1) (succ u2)} ((Subtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x)) -> Y) (Function.comp.{succ u1, succ u1, succ u2} (Subtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x)) X Y g ((fun (a : Type.{u1}) (b : Type.{u1}) [self : HasLiftT.{succ u1, succ u1} a b] => self.0) (Subtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x)) X (HasLiftT.mk.{succ u1, succ u1} (Subtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x)) X (CoeTCₓ.coe.{succ u1, succ u1} (Subtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x)) X (coeBase.{succ u1, succ u1} (Subtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x)) X (coeSubtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x))))))) f)) (X -> Y) (HasLiftT.mk.{max 1 (succ u1) (succ u2), max (succ u1) (succ u2)} (Subtype.{max (succ u1) (succ u2)} (X -> Y) (fun (g : X -> Y) => Eq.{max (succ u1) (succ u2)} ((Subtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x)) -> Y) (Function.comp.{succ u1, succ u1, succ u2} (Subtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x)) X Y g ((fun (a : Type.{u1}) (b : Type.{u1}) [self : HasLiftT.{succ u1, succ u1} a b] => self.0) (Subtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x)) X (HasLiftT.mk.{succ u1, succ u1} (Subtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x)) X (CoeTCₓ.coe.{succ u1, succ u1} (Subtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x)) X (coeBase.{succ u1, succ u1} (Subtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x)) X (coeSubtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x))))))) f)) (X -> Y) (CoeTCₓ.coe.{max 1 (succ u1) (succ u2), max (succ u1) (succ u2)} (Subtype.{max (succ u1) (succ u2)} (X -> Y) (fun (g : X -> Y) => Eq.{max (succ u1) (succ u2)} ((Subtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x)) -> Y) (Function.comp.{succ u1, succ u1, succ u2} (Subtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x)) X Y g ((fun (a : Type.{u1}) (b : Type.{u1}) [self : HasLiftT.{succ u1, succ u1} a b] => self.0) (Subtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x)) X (HasLiftT.mk.{succ u1, succ u1} (Subtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x)) X (CoeTCₓ.coe.{succ u1, succ u1} (Subtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x)) X (coeBase.{succ u1, succ u1} (Subtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x)) X (coeSubtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x))))))) f)) (X -> Y) (coeBase.{max 1 (succ u1) (succ u2), max (succ u1) (succ u2)} (Subtype.{max (succ u1) (succ u2)} (X -> Y) (fun (g : X -> Y) => Eq.{max (succ u1) (succ u2)} ((Subtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x)) -> Y) (Function.comp.{succ u1, succ u1, succ u2} (Subtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x)) X Y g ((fun (a : Type.{u1}) (b : Type.{u1}) [self : HasLiftT.{succ u1, succ u1} a b] => self.0) (Subtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x)) X (HasLiftT.mk.{succ u1, succ u1} (Subtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x)) X (CoeTCₓ.coe.{succ u1, succ u1} (Subtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x)) X (coeBase.{succ u1, succ u1} (Subtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x)) X (coeSubtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x))))))) f)) (X -> Y) (coeSubtype.{max (succ u1) (succ u2)} (X -> Y) (fun (g : X -> Y) => Eq.{max (succ u1) (succ u2)} ((Subtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x)) -> Y) (Function.comp.{succ u1, succ u1, succ u2} (Subtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x)) X Y g ((fun (a : Type.{u1}) (b : Type.{u1}) [self : HasLiftT.{succ u1, succ u1} a b] => self.0) (Subtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x)) X (HasLiftT.mk.{succ u1, succ u1} (Subtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x)) X (CoeTCₓ.coe.{succ u1, succ u1} (Subtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x)) X (coeBase.{succ u1, succ u1} (Subtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x)) X (coeSubtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x))))))) f))))) g x) but is expected to have type forall {X : Sort.{u1}} [Y : DecidableEq.{u1} X] {_inst_1 : X} {x : Sort.{u2}} (f : (Subtype.{u1} X (fun (x' : X) => Ne.{u1} X x' _inst_1)) -> x), Eq.{imax (max 1 (imax u1 u2)) u2} (forall (a : Subtype.{imax u1 u2} (X -> x) (fun (g : X -> x) => Eq.{imax (max 1 u1) u2} ((Subtype.{u1} X (fun (x' : X) => Ne.{u1} X x' _inst_1)) -> x) (Function.comp.{max 1 u1, u1, u2} (Subtype.{u1} X (fun (x' : X) => Ne.{u1} X x' _inst_1)) X x g (Subtype.val.{u1} X (fun (x' : X) => Ne.{u1} X x' _inst_1))) f)), (fun ([email protected]._hyg.808 : Subtype.{imax u1 u2} (X -> x) (fun (g : X -> x) => Eq.{imax (max 1 u1) u2} ((Subtype.{u1} X (fun (x' : X) => Ne.{u1} X x' _inst_1)) -> x) (Function.comp.{max 1 u1, u1, u2} (Subtype.{u1} X (fun (x' : X) => Ne.{u1} X x' _inst_1)) X x g (Subtype.val.{u1} X (fun (x' : X) => Ne.{u1} X x' _inst_1))) f)) => x) a) (FunLike.coe.{max (max 1 u2) (imax u1 u2), max 1 (imax u1 u2), u2} (Equiv.{max 1 (imax u1 u2), u2} (Subtype.{imax u1 u2} (X -> x) (fun (g : X -> x) => Eq.{imax (max 1 u1) u2} ((Subtype.{u1} X (fun (x' : X) => Ne.{u1} X x' _inst_1)) -> x) (Function.comp.{max 1 u1, u1, u2} (Subtype.{u1} X (fun (x' : X) => Ne.{u1} X x' _inst_1)) X x g (Subtype.val.{u1} X (fun (x' : X) => Ne.{u1} X x' _inst_1))) f)) x) (Subtype.{imax u1 u2} (X -> x) (fun (g : X -> x) => Eq.{imax (max 1 u1) u2} ((Subtype.{u1} X (fun (x' : X) => Ne.{u1} X x' _inst_1)) -> x) (Function.comp.{max 1 u1, u1, u2} (Subtype.{u1} X (fun (x' : X) => Ne.{u1} X x' _inst_1)) X x g (Subtype.val.{u1} X (fun (x' : X) => Ne.{u1} X x' _inst_1))) f)) (fun (_x : Subtype.{imax u1 u2} (X -> x) (fun (g : X -> x) => Eq.{imax (max 1 u1) u2} ((Subtype.{u1} X (fun (x' : X) => Ne.{u1} X x' _inst_1)) -> x) (Function.comp.{max 1 u1, u1, u2} (Subtype.{u1} X (fun (x' : X) => Ne.{u1} X x' _inst_1)) X x g (Subtype.val.{u1} X (fun (x' : X) => Ne.{u1} X x' _inst_1))) f)) => (fun ([email protected]._hyg.808 : Subtype.{imax u1 u2} (X -> x) (fun (g : X -> x) => Eq.{imax (max 1 u1) u2} ((Subtype.{u1} X (fun (x' : X) => Ne.{u1} X x' _inst_1)) -> x) (Function.comp.{max 1 u1, u1, u2} (Subtype.{u1} X (fun (x' : X) => Ne.{u1} X x' _inst_1)) X x g (Subtype.val.{u1} X (fun (x' : X) => Ne.{u1} X x' _inst_1))) f)) => x) _x) (Equiv.instFunLikeEquiv.{max 1 (imax u1 u2), u2} (Subtype.{imax u1 u2} (X -> x) (fun (g : X -> x) => Eq.{imax (max 1 u1) u2} ((Subtype.{u1} X (fun (x' : X) => Ne.{u1} X x' _inst_1)) -> x) (Function.comp.{max 1 u1, u1, u2} (Subtype.{u1} X (fun (x' : X) => Ne.{u1} X x' _inst_1)) X x g (Subtype.val.{u1} X (fun (x' : X) => Ne.{u1} X x' _inst_1))) f)) x) (Equiv.subtypeEquivCodomain.{u1, u2} X (fun (a : X) (b : X) => Y a b) _inst_1 x f)) (fun (g : Subtype.{imax u1 u2} (X -> x) (fun (g : X -> x) => Eq.{imax (max 1 u1) u2} ((Subtype.{u1} X (fun (x' : X) => Ne.{u1} X x' _inst_1)) -> x) (Function.comp.{max 1 u1, u1, u2} (Subtype.{u1} X (fun (x' : X) => Ne.{u1} X x' _inst_1)) X x g (Subtype.val.{u1} X (fun (x' : X) => Ne.{u1} X x' _inst_1))) f)) => Subtype.val.{imax u1 u2} (X -> x) (fun (g : X -> x) => Eq.{imax (max 1 u1) u2} ((Subtype.{u1} X (fun (x' : X) => Ne.{u1} X x' _inst_1)) -> x) (Function.comp.{max 1 u1, u1, u2} (Subtype.{u1} X (fun (x' : X) => Ne.{u1} X x' _inst_1)) X x g (Subtype.val.{u1} X (fun (x' : X) => Ne.{u1} X x' _inst_1))) f) g _inst_1) Case conversion may be inaccurate. Consider using '#align equiv.coe_subtype_equiv_codomain Equiv.coe_subtypeEquivCodomainₓ'. -/ @[simp] theorem coe_subtypeEquivCodomain (f : { x' // x' ≠ x } → Y) : (subtypeEquivCodomain f : { g : X → Y // g ∘ coe = f } → Y) = fun g => (g : X → Y) x := rfl #align equiv.coe_subtype_equiv_codomain Equiv.coe_subtypeEquivCodomain /- warning: equiv.subtype_equiv_codomain_apply -> Equiv.subtypeEquivCodomain_apply is a dubious translation: lean 3 declaration is forall {X : Type.{u1}} {Y : Type.{u2}} [_inst_1 : DecidableEq.{succ u1} X] {x : X} (f : (Subtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x)) -> Y) (g : Subtype.{max (succ u1) (succ u2)} (X -> Y) (fun (g : X -> Y) => Eq.{max (succ u1) (succ u2)} ((Subtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x)) -> Y) (Function.comp.{succ u1, succ u1, succ u2} (Subtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x)) X Y g ((fun (a : Type.{u1}) (b : Type.{u1}) [self : HasLiftT.{succ u1, succ u1} a b] => self.0) (Subtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x)) X (HasLiftT.mk.{succ u1, succ u1} (Subtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x)) X (CoeTCₓ.coe.{succ u1, succ u1} (Subtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x)) X (coeBase.{succ u1, succ u1} (Subtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x)) X (coeSubtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x))))))) f)), Eq.{succ u2} Y (coeFn.{max 1 (max (max 1 (succ u1) (succ u2)) (succ u2)) (succ u2) 1 (succ u1) (succ u2), max (max 1 (succ u1) (succ u2)) (succ u2)} (Equiv.{max 1 (succ u1) (succ u2), succ u2} (Subtype.{max (succ u1) (succ u2)} (X -> Y) (fun (g : X -> Y) => Eq.{max (succ u1) (succ u2)} ((Subtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x)) -> Y) (Function.comp.{succ u1, succ u1, succ u2} (Subtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x)) X Y g ((fun (a : Type.{u1}) (b : Type.{u1}) [self : HasLiftT.{succ u1, succ u1} a b] => self.0) (Subtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x)) X (HasLiftT.mk.{succ u1, succ u1} (Subtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x)) X (CoeTCₓ.coe.{succ u1, succ u1} (Subtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x)) X (coeBase.{succ u1, succ u1} (Subtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x)) X (coeSubtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x))))))) f)) Y) (fun (_x : Equiv.{max 1 (succ u1) (succ u2), succ u2} (Subtype.{max (succ u1) (succ u2)} (X -> Y) (fun (g : X -> Y) => Eq.{max (succ u1) (succ u2)} ((Subtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x)) -> Y) (Function.comp.{succ u1, succ u1, succ u2} (Subtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x)) X Y g ((fun (a : Type.{u1}) (b : Type.{u1}) [self : HasLiftT.{succ u1, succ u1} a b] => self.0) (Subtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x)) X (HasLiftT.mk.{succ u1, succ u1} (Subtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x)) X (CoeTCₓ.coe.{succ u1, succ u1} (Subtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x)) X (coeBase.{succ u1, succ u1} (Subtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x)) X (coeSubtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x))))))) f)) Y) => (Subtype.{max (succ u1) (succ u2)} (X -> Y) (fun (g : X -> Y) => Eq.{max (succ u1) (succ u2)} ((Subtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x)) -> Y) (Function.comp.{succ u1, succ u1, succ u2} (Subtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x)) X Y g ((fun (a : Type.{u1}) (b : Type.{u1}) [self : HasLiftT.{succ u1, succ u1} a b] => self.0) (Subtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x)) X (HasLiftT.mk.{succ u1, succ u1} (Subtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x)) X (CoeTCₓ.coe.{succ u1, succ u1} (Subtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x)) X (coeBase.{succ u1, succ u1} (Subtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x)) X (coeSubtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x))))))) f)) -> Y) (Equiv.hasCoeToFun.{max 1 (succ u1) (succ u2), succ u2} (Subtype.{max (succ u1) (succ u2)} (X -> Y) (fun (g : X -> Y) => Eq.{max (succ u1) (succ u2)} ((Subtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x)) -> Y) (Function.comp.{succ u1, succ u1, succ u2} (Subtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x)) X Y g ((fun (a : Type.{u1}) (b : Type.{u1}) [self : HasLiftT.{succ u1, succ u1} a b] => self.0) (Subtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x)) X (HasLiftT.mk.{succ u1, succ u1} (Subtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x)) X (CoeTCₓ.coe.{succ u1, succ u1} (Subtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x)) X (coeBase.{succ u1, succ u1} (Subtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x)) X (coeSubtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x))))))) f)) Y) (Equiv.subtypeEquivCodomain.{u1, u2} X Y (fun (a : X) (b : X) => _inst_1 a b) x f) g) ((fun (a : Sort.{max 1 (succ u1) (succ u2)}) (b : Sort.{max (succ u1) (succ u2)}) [self : HasLiftT.{max 1 (succ u1) (succ u2), max (succ u1) (succ u2)} a b] => self.0) (Subtype.{max (succ u1) (succ u2)} (X -> Y) (fun (g : X -> Y) => Eq.{max (succ u1) (succ u2)} ((Subtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x)) -> Y) (Function.comp.{succ u1, succ u1, succ u2} (Subtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x)) X Y g ((fun (a : Type.{u1}) (b : Type.{u1}) [self : HasLiftT.{succ u1, succ u1} a b] => self.0) (Subtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x)) X (HasLiftT.mk.{succ u1, succ u1} (Subtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x)) X (CoeTCₓ.coe.{succ u1, succ u1} (Subtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x)) X (coeBase.{succ u1, succ u1} (Subtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x)) X (coeSubtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x))))))) f)) (X -> Y) (HasLiftT.mk.{max 1 (succ u1) (succ u2), max (succ u1) (succ u2)} (Subtype.{max (succ u1) (succ u2)} (X -> Y) (fun (g : X -> Y) => Eq.{max (succ u1) (succ u2)} ((Subtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x)) -> Y) (Function.comp.{succ u1, succ u1, succ u2} (Subtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x)) X Y g ((fun (a : Type.{u1}) (b : Type.{u1}) [self : HasLiftT.{succ u1, succ u1} a b] => self.0) (Subtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x)) X (HasLiftT.mk.{succ u1, succ u1} (Subtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x)) X (CoeTCₓ.coe.{succ u1, succ u1} (Subtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x)) X (coeBase.{succ u1, succ u1} (Subtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x)) X (coeSubtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x))))))) f)) (X -> Y) (CoeTCₓ.coe.{max 1 (succ u1) (succ u2), max (succ u1) (succ u2)} (Subtype.{max (succ u1) (succ u2)} (X -> Y) (fun (g : X -> Y) => Eq.{max (succ u1) (succ u2)} ((Subtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x)) -> Y) (Function.comp.{succ u1, succ u1, succ u2} (Subtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x)) X Y g ((fun (a : Type.{u1}) (b : Type.{u1}) [self : HasLiftT.{succ u1, succ u1} a b] => self.0) (Subtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x)) X (HasLiftT.mk.{succ u1, succ u1} (Subtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x)) X (CoeTCₓ.coe.{succ u1, succ u1} (Subtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x)) X (coeBase.{succ u1, succ u1} (Subtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x)) X (coeSubtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x))))))) f)) (X -> Y) (coeBase.{max 1 (succ u1) (succ u2), max (succ u1) (succ u2)} (Subtype.{max (succ u1) (succ u2)} (X -> Y) (fun (g : X -> Y) => Eq.{max (succ u1) (succ u2)} ((Subtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x)) -> Y) (Function.comp.{succ u1, succ u1, succ u2} (Subtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x)) X Y g ((fun (a : Type.{u1}) (b : Type.{u1}) [self : HasLiftT.{succ u1, succ u1} a b] => self.0) (Subtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x)) X (HasLiftT.mk.{succ u1, succ u1} (Subtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x)) X (CoeTCₓ.coe.{succ u1, succ u1} (Subtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x)) X (coeBase.{succ u1, succ u1} (Subtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x)) X (coeSubtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x))))))) f)) (X -> Y) (coeSubtype.{max (succ u1) (succ u2)} (X -> Y) (fun (g : X -> Y) => Eq.{max (succ u1) (succ u2)} ((Subtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x)) -> Y) (Function.comp.{succ u1, succ u1, succ u2} (Subtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x)) X Y g ((fun (a : Type.{u1}) (b : Type.{u1}) [self : HasLiftT.{succ u1, succ u1} a b] => self.0) (Subtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x)) X (HasLiftT.mk.{succ u1, succ u1} (Subtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x)) X (CoeTCₓ.coe.{succ u1, succ u1} (Subtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x)) X (coeBase.{succ u1, succ u1} (Subtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x)) X (coeSubtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x))))))) f))))) g x) but is expected to have type forall {X : Sort.{u1}} [Y : DecidableEq.{u1} X] {_inst_1 : X} {x : Sort.{u2}} (f : (Subtype.{u1} X (fun (x' : X) => Ne.{u1} X x' _inst_1)) -> x) (g : Subtype.{imax u1 u2} (X -> x) (fun (g : X -> x) => Eq.{imax (max 1 u1) u2} ((Subtype.{u1} X (fun (x' : X) => Ne.{u1} X x' _inst_1)) -> x) (Function.comp.{max 1 u1, u1, u2} (Subtype.{u1} X (fun (x' : X) => Ne.{u1} X x' _inst_1)) X x g (Subtype.val.{u1} X (fun (x' : X) => Ne.{u1} X x' _inst_1))) f)), Eq.{u2} ((fun ([email protected]._hyg.808 : Subtype.{imax u1 u2} (X -> x) (fun (g : X -> x) => Eq.{imax (max 1 u1) u2} ((Subtype.{u1} X (fun (x' : X) => Ne.{u1} X x' _inst_1)) -> x) (Function.comp.{max 1 u1, u1, u2} (Subtype.{u1} X (fun (x' : X) => Ne.{u1} X x' _inst_1)) X x g (Subtype.val.{u1} X (fun (x' : X) => Ne.{u1} X x' _inst_1))) f)) => x) g) (FunLike.coe.{max (max 1 u2) (imax u1 u2), max 1 (imax u1 u2), u2} (Equiv.{max 1 (imax u1 u2), u2} (Subtype.{imax u1 u2} (X -> x) (fun (g : X -> x) => Eq.{imax (max 1 u1) u2} ((Subtype.{u1} X (fun (x' : X) => Ne.{u1} X x' _inst_1)) -> x) (Function.comp.{max 1 u1, u1, u2} (Subtype.{u1} X (fun (x' : X) => Ne.{u1} X x' _inst_1)) X x g (Subtype.val.{u1} X (fun (x' : X) => Ne.{u1} X x' _inst_1))) f)) x) (Subtype.{imax u1 u2} (X -> x) (fun (g : X -> x) => Eq.{imax (max 1 u1) u2} ((Subtype.{u1} X (fun (x' : X) => Ne.{u1} X x' _inst_1)) -> x) (Function.comp.{max 1 u1, u1, u2} (Subtype.{u1} X (fun (x' : X) => Ne.{u1} X x' _inst_1)) X x g (Subtype.val.{u1} X (fun (x' : X) => Ne.{u1} X x' _inst_1))) f)) (fun (_x : Subtype.{imax u1 u2} (X -> x) (fun (g : X -> x) => Eq.{imax (max 1 u1) u2} ((Subtype.{u1} X (fun (x' : X) => Ne.{u1} X x' _inst_1)) -> x) (Function.comp.{max 1 u1, u1, u2} (Subtype.{u1} X (fun (x' : X) => Ne.{u1} X x' _inst_1)) X x g (Subtype.val.{u1} X (fun (x' : X) => Ne.{u1} X x' _inst_1))) f)) => (fun ([email protected]._hyg.808 : Subtype.{imax u1 u2} (X -> x) (fun (g : X -> x) => Eq.{imax (max 1 u1) u2} ((Subtype.{u1} X (fun (x' : X) => Ne.{u1} X x' _inst_1)) -> x) (Function.comp.{max 1 u1, u1, u2} (Subtype.{u1} X (fun (x' : X) => Ne.{u1} X x' _inst_1)) X x g (Subtype.val.{u1} X (fun (x' : X) => Ne.{u1} X x' _inst_1))) f)) => x) _x) (Equiv.instFunLikeEquiv.{max 1 (imax u1 u2), u2} (Subtype.{imax u1 u2} (X -> x) (fun (g : X -> x) => Eq.{imax (max 1 u1) u2} ((Subtype.{u1} X (fun (x' : X) => Ne.{u1} X x' _inst_1)) -> x) (Function.comp.{max 1 u1, u1, u2} (Subtype.{u1} X (fun (x' : X) => Ne.{u1} X x' _inst_1)) X x g (Subtype.val.{u1} X (fun (x' : X) => Ne.{u1} X x' _inst_1))) f)) x) (Equiv.subtypeEquivCodomain.{u1, u2} X (fun (a : X) (b : X) => Y a b) _inst_1 x f) g) (Subtype.val.{imax u1 u2} (X -> x) (fun (g : X -> x) => Eq.{imax (max 1 u1) u2} ((Subtype.{u1} X (fun (x' : X) => Ne.{u1} X x' _inst_1)) -> x) (Function.comp.{max 1 u1, u1, u2} (Subtype.{u1} X (fun (x' : X) => Ne.{u1} X x' _inst_1)) X x g (Subtype.val.{u1} X (fun (x' : X) => Ne.{u1} X x' _inst_1))) f) g _inst_1) Case conversion may be inaccurate. Consider using '#align equiv.subtype_equiv_codomain_apply Equiv.subtypeEquivCodomain_applyₓ'. -/ @[simp] theorem subtypeEquivCodomain_apply (f : { x' // x' ≠ x } → Y) (g : { g : X → Y // g ∘ coe = f }) : subtypeEquivCodomain f g = (g : X → Y) x := rfl #align equiv.subtype_equiv_codomain_apply Equiv.subtypeEquivCodomain_apply /- warning: equiv.coe_subtype_equiv_codomain_symm -> Equiv.coe_subtypeEquivCodomain_symm is a dubious translation: lean 3 declaration is forall {X : Type.{u1}} {Y : Type.{u2}} [_inst_1 : DecidableEq.{succ u1} X] {x : X} (f : (Subtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x)) -> Y), Eq.{max (succ u2) 1 (succ u1) (succ u2)} ((fun (_x : Equiv.{succ u2, max 1 (succ u1) (succ u2)} Y (Subtype.{max (succ u1) (succ u2)} (X -> Y) (fun (g : X -> Y) => Eq.{max (succ u1) (succ u2)} ((Subtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x)) -> Y) (Function.comp.{succ u1, succ u1, succ u2} (Subtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x)) X Y g ((fun (a : Type.{u1}) (b : Type.{u1}) [self : HasLiftT.{succ u1, succ u1} a b] => self.0) (Subtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x)) X (HasLiftT.mk.{succ u1, succ u1} (Subtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x)) X (CoeTCₓ.coe.{succ u1, succ u1} (Subtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x)) X (coeBase.{succ u1, succ u1} (Subtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x)) X (coeSubtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x))))))) f))) => Y -> (Subtype.{max (succ u1) (succ u2)} (X -> Y) (fun (g : X -> Y) => Eq.{max (succ u1) (succ u2)} ((Subtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x)) -> Y) (Function.comp.{succ u1, succ u1, succ u2} (Subtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x)) X Y g ((fun (a : Type.{u1}) (b : Type.{u1}) [self : HasLiftT.{succ u1, succ u1} a b] => self.0) (Subtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x)) X (HasLiftT.mk.{succ u1, succ u1} (Subtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x)) X (CoeTCₓ.coe.{succ u1, succ u1} (Subtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x)) X (coeBase.{succ u1, succ u1} (Subtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x)) X (coeSubtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x))))))) f))) (Equiv.symm.{max 1 (succ u1) (succ u2), succ u2} (Subtype.{max (succ u1) (succ u2)} (X -> Y) (fun (g : X -> Y) => Eq.{max (succ u1) (succ u2)} ((Subtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x)) -> Y) (Function.comp.{succ u1, succ u1, succ u2} (Subtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x)) X Y g ((fun (a : Type.{u1}) (b : Type.{u1}) [self : HasLiftT.{succ u1, succ u1} a b] => self.0) (Subtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x)) X (HasLiftT.mk.{succ u1, succ u1} (Subtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x)) X (CoeTCₓ.coe.{succ u1, succ u1} (Subtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x)) X (coeBase.{succ u1, succ u1} (Subtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x)) X (coeSubtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x))))))) f)) Y (Equiv.subtypeEquivCodomain.{u1, u2} X Y (fun (a : X) (b : X) => _inst_1 a b) x f))) (coeFn.{max 1 (max (succ u2) 1 (succ u1) (succ u2)) (max 1 (succ u1) (succ u2)) (succ u2), max (succ u2) 1 (succ u1) (succ u2)} (Equiv.{succ u2, max 1 (succ u1) (succ u2)} Y (Subtype.{max (succ u1) (succ u2)} (X -> Y) (fun (g : X -> Y) => Eq.{max (succ u1) (succ u2)} ((Subtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x)) -> Y) (Function.comp.{succ u1, succ u1, succ u2} (Subtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x)) X Y g ((fun (a : Type.{u1}) (b : Type.{u1}) [self : HasLiftT.{succ u1, succ u1} a b] => self.0) (Subtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x)) X (HasLiftT.mk.{succ u1, succ u1} (Subtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x)) X (CoeTCₓ.coe.{succ u1, succ u1} (Subtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x)) X (coeBase.{succ u1, succ u1} (Subtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x)) X (coeSubtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x))))))) f))) (fun (_x : Equiv.{succ u2, max 1 (succ u1) (succ u2)} Y (Subtype.{max (succ u1) (succ u2)} (X -> Y) (fun (g : X -> Y) => Eq.{max (succ u1) (succ u2)} ((Subtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x)) -> Y) (Function.comp.{succ u1, succ u1, succ u2} (Subtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x)) X Y g ((fun (a : Type.{u1}) (b : Type.{u1}) [self : HasLiftT.{succ u1, succ u1} a b] => self.0) (Subtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x)) X (HasLiftT.mk.{succ u1, succ u1} (Subtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x)) X (CoeTCₓ.coe.{succ u1, succ u1} (Subtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x)) X (coeBase.{succ u1, succ u1} (Subtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x)) X (coeSubtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x))))))) f))) => Y -> (Subtype.{max (succ u1) (succ u2)} (X -> Y) (fun (g : X -> Y) => Eq.{max (succ u1) (succ u2)} ((Subtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x)) -> Y) (Function.comp.{succ u1, succ u1, succ u2} (Subtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x)) X Y g ((fun (a : Type.{u1}) (b : Type.{u1}) [self : HasLiftT.{succ u1, succ u1} a b] => self.0) (Subtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x)) X (HasLiftT.mk.{succ u1, succ u1} (Subtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x)) X (CoeTCₓ.coe.{succ u1, succ u1} (Subtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x)) X (coeBase.{succ u1, succ u1} (Subtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x)) X (coeSubtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x))))))) f))) (Equiv.hasCoeToFun.{succ u2, max 1 (succ u1) (succ u2)} Y (Subtype.{max (succ u1) (succ u2)} (X -> Y) (fun (g : X -> Y) => Eq.{max (succ u1) (succ u2)} ((Subtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x)) -> Y) (Function.comp.{succ u1, succ u1, succ u2} (Subtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x)) X Y g ((fun (a : Type.{u1}) (b : Type.{u1}) [self : HasLiftT.{succ u1, succ u1} a b] => self.0) (Subtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x)) X (HasLiftT.mk.{succ u1, succ u1} (Subtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x)) X (CoeTCₓ.coe.{succ u1, succ u1} (Subtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x)) X (coeBase.{succ u1, succ u1} (Subtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x)) X (coeSubtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x))))))) f))) (Equiv.symm.{max 1 (succ u1) (succ u2), succ u2} (Subtype.{max (succ u1) (succ u2)} (X -> Y) (fun (g : X -> Y) => Eq.{max (succ u1) (succ u2)} ((Subtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x)) -> Y) (Function.comp.{succ u1, succ u1, succ u2} (Subtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x)) X Y g ((fun (a : Type.{u1}) (b : Type.{u1}) [self : HasLiftT.{succ u1, succ u1} a b] => self.0) (Subtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x)) X (HasLiftT.mk.{succ u1, succ u1} (Subtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x)) X (CoeTCₓ.coe.{succ u1, succ u1} (Subtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x)) X (coeBase.{succ u1, succ u1} (Subtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x)) X (coeSubtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x))))))) f)) Y (Equiv.subtypeEquivCodomain.{u1, u2} X Y (fun (a : X) (b : X) => _inst_1 a b) x f))) (fun (y : Y) => Subtype.mk.{max (succ u1) (succ u2)} (X -> Y) (fun (g : X -> Y) => Eq.{max (succ u1) (succ u2)} ((Subtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x)) -> Y) (Function.comp.{succ u1, succ u1, succ u2} (Subtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x)) X Y g ((fun (a : Type.{u1}) (b : Type.{u1}) [self : HasLiftT.{succ u1, succ u1} a b] => self.0) (Subtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x)) X (HasLiftT.mk.{succ u1, succ u1} (Subtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x)) X (CoeTCₓ.coe.{succ u1, succ u1} (Subtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x)) X (coeBase.{succ u1, succ u1} (Subtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x)) X (coeSubtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x))))))) f) (fun (x' : X) => dite.{succ u2} Y (Ne.{succ u1} X x' x) (Ne.decidable.{succ u1} X (fun (a : X) (b : X) => _inst_1 a b) x' x) (fun (h : Ne.{succ u1} X x' x) => f (Subtype.mk.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x) x' h)) (fun (h : Not (Ne.{succ u1} X x' x)) => y)) (funext.{succ u1, succ u2} (Subtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x)) (fun (x : Subtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x)) => Y) (Function.comp.{succ u1, succ u1, succ u2} (Subtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x)) X Y (fun (x' : X) => dite.{succ u2} Y (Ne.{succ u1} X x' x) (Ne.decidable.{succ u1} X (fun (a : X) (b : X) => _inst_1 a b) x' x) (fun (h : Ne.{succ u1} X x' x) => f (Subtype.mk.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x) x' h)) (fun (h : Not (Ne.{succ u1} X x' x)) => y)) ((fun (a : Type.{u1}) (b : Type.{u1}) [self : HasLiftT.{succ u1, succ u1} a b] => self.0) (Subtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x)) X (HasLiftT.mk.{succ u1, succ u1} (Subtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x)) X (CoeTCₓ.coe.{succ u1, succ u1} (Subtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x)) X (coeBase.{succ u1, succ u1} (Subtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x)) X (coeSubtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x))))))) f (fun (x' : Subtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x)) => id.{0} (Eq.{succ u2} Y (Function.comp.{succ u1, succ u1, succ u2} (Subtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x)) X Y (fun (x' : X) => dite.{succ u2} Y (Ne.{succ u1} X x' x) (Ne.decidable.{succ u1} X (fun (a : X) (b : X) => _inst_1 a b) x' x) (fun (h : Ne.{succ u1} X x' x) => f (Subtype.mk.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x) x' h)) (fun (h : Not (Ne.{succ u1} X x' x)) => y)) ((fun (a : Type.{u1}) (b : Type.{u1}) [self : HasLiftT.{succ u1, succ u1} a b] => self.0) (Subtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x)) X (HasLiftT.mk.{succ u1, succ u1} (Subtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x)) X (CoeTCₓ.coe.{succ u1, succ u1} (Subtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x)) X (coeBase.{succ u1, succ u1} (Subtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x)) X (coeSubtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x)))))) x') (f x')) (Eq.mpr.{0} (Eq.{succ u2} Y (dite.{succ u2} Y (Not (Eq.{succ u1} X ((fun (a : Type.{u1}) (b : Type.{u1}) [self : HasLiftT.{succ u1, succ u1} a b] => self.0) (Subtype.{succ u1} X (fun (x' : X) => Not (Eq.{succ u1} X x' x))) X (HasLiftT.mk.{succ u1, succ u1} (Subtype.{succ u1} X (fun (x' : X) => Not (Eq.{succ u1} X x' x))) X (CoeTCₓ.coe.{succ u1, succ u1} (Subtype.{succ u1} X (fun (x' : X) => Not (Eq.{succ u1} X x' x))) X (coeBase.{succ u1, succ u1} (Subtype.{succ u1} X (fun (x' : X) => Not (Eq.{succ u1} X x' x))) X (coeSubtype.{succ u1} X (fun (x' : X) => Not (Eq.{succ u1} X x' x)))))) x') x)) (Ne.decidable.{succ u1} X _inst_1 ((fun (a : Type.{u1}) (b : Type.{u1}) [self : HasLiftT.{succ u1, succ u1} a b] => self.0) (Subtype.{succ u1} X (fun (x' : X) => Not (Eq.{succ u1} X x' x))) X (HasLiftT.mk.{succ u1, succ u1} (Subtype.{succ u1} X (fun (x' : X) => Not (Eq.{succ u1} X x' x))) X (CoeTCₓ.coe.{succ u1, succ u1} (Subtype.{succ u1} X (fun (x' : X) => Not (Eq.{succ u1} X x' x))) X (coeBase.{succ u1, succ u1} (Subtype.{succ u1} X (fun (x' : X) => Not (Eq.{succ u1} X x' x))) X (coeSubtype.{succ u1} X (fun (x' : X) => Not (Eq.{succ u1} X x' x)))))) x') x) (fun (h : Not (Eq.{succ u1} X ((fun (a : Type.{u1}) (b : Type.{u1}) [self : HasLiftT.{succ u1, succ u1} a b] => self.0) (Subtype.{succ u1} X (fun (x' : X) => Not (Eq.{succ u1} X x' x))) X (HasLiftT.mk.{succ u1, succ u1} (Subtype.{succ u1} X (fun (x' : X) => Not (Eq.{succ u1} X x' x))) X (CoeTCₓ.coe.{succ u1, succ u1} (Subtype.{succ u1} X (fun (x' : X) => Not (Eq.{succ u1} X x' x))) X (coeBase.{succ u1, succ u1} (Subtype.{succ u1} X (fun (x' : X) => Not (Eq.{succ u1} X x' x))) X (coeSubtype.{succ u1} X (fun (x' : X) => Not (Eq.{succ u1} X x' x)))))) x') x)) => f (Subtype.mk.{succ u1} X (fun (x' : X) => Not (Eq.{succ u1} X x' x)) ((fun (a : Type.{u1}) (b : Type.{u1}) [self : HasLiftT.{succ u1, succ u1} a b] => self.0) (Subtype.{succ u1} X (fun (x' : X) => Not (Eq.{succ u1} X x' x))) X (HasLiftT.mk.{succ u1, succ u1} (Subtype.{succ u1} X (fun (x' : X) => Not (Eq.{succ u1} X x' x))) X (CoeTCₓ.coe.{succ u1, succ u1} (Subtype.{succ u1} X (fun (x' : X) => Not (Eq.{succ u1} X x' x))) X (coeBase.{succ u1, succ u1} (Subtype.{succ u1} X (fun (x' : X) => Not (Eq.{succ u1} X x' x))) X (coeSubtype.{succ u1} X (fun (x' : X) => Not (Eq.{succ u1} X x' x)))))) x') h)) (fun (h : Not (Not (Eq.{succ u1} X ((fun (a : Type.{u1}) (b : Type.{u1}) [self : HasLiftT.{succ u1, succ u1} a b] => self.0) (Subtype.{succ u1} X (fun (x' : X) => Not (Eq.{succ u1} X x' x))) X (HasLiftT.mk.{succ u1, succ u1} (Subtype.{succ u1} X (fun (x' : X) => Not (Eq.{succ u1} X x' x))) X (CoeTCₓ.coe.{succ u1, succ u1} (Subtype.{succ u1} X (fun (x' : X) => Not (Eq.{succ u1} X x' x))) X (coeBase.{succ u1, succ u1} (Subtype.{succ u1} X (fun (x' : X) => Not (Eq.{succ u1} X x' x))) X (coeSubtype.{succ u1} X (fun (x' : X) => Not (Eq.{succ u1} X x' x)))))) x') x))) => y)) (f x')) (Eq.{succ u2} Y (f (Subtype.mk.{succ u1} X (fun (x' : X) => Not (Eq.{succ u1} X x' x)) ((fun (a : Type.{u1}) (b : Type.{u1}) [self : HasLiftT.{succ u1, succ u1} a b] => self.0) (Subtype.{succ u1} X (fun (x' : X) => Not (Eq.{succ u1} X x' x))) X (HasLiftT.mk.{succ u1, succ u1} (Subtype.{succ u1} X (fun (x' : X) => Not (Eq.{succ u1} X x' x))) X (CoeTCₓ.coe.{succ u1, succ u1} (Subtype.{succ u1} X (fun (x' : X) => Not (Eq.{succ u1} X x' x))) X (coeBase.{succ u1, succ u1} (Subtype.{succ u1} X (fun (x' : X) => Not (Eq.{succ u1} X x' x))) X (coeSubtype.{succ u1} X (fun (x' : X) => Not (Eq.{succ u1} X x' x)))))) x') (Subtype.property.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x) x'))) (f x')) (id_tag Tactic.IdTag.rw (Eq.{1} Prop (Eq.{succ u2} Y (dite.{succ u2} Y (Not (Eq.{succ u1} X ((fun (a : Type.{u1}) (b : Type.{u1}) [self : HasLiftT.{succ u1, succ u1} a b] => self.0) (Subtype.{succ u1} X (fun (x' : X) => Not (Eq.{succ u1} X x' x))) X (HasLiftT.mk.{succ u1, succ u1} (Subtype.{succ u1} X (fun (x' : X) => Not (Eq.{succ u1} X x' x))) X (CoeTCₓ.coe.{succ u1, succ u1} (Subtype.{succ u1} X (fun (x' : X) => Not (Eq.{succ u1} X x' x))) X (coeBase.{succ u1, succ u1} (Subtype.{succ u1} X (fun (x' : X) => Not (Eq.{succ u1} X x' x))) X (coeSubtype.{succ u1} X (fun (x' : X) => Not (Eq.{succ u1} X x' x)))))) x') x)) (Ne.decidable.{succ u1} X _inst_1 ((fun (a : Type.{u1}) (b : Type.{u1}) [self : HasLiftT.{succ u1, succ u1} a b] => self.0) (Subtype.{succ u1} X (fun (x' : X) => Not (Eq.{succ u1} X x' x))) X (HasLiftT.mk.{succ u1, succ u1} (Subtype.{succ u1} X (fun (x' : X) => Not (Eq.{succ u1} X x' x))) X (CoeTCₓ.coe.{succ u1, succ u1} (Subtype.{succ u1} X (fun (x' : X) => Not (Eq.{succ u1} X x' x))) X (coeBase.{succ u1, succ u1} (Subtype.{succ u1} X (fun (x' : X) => Not (Eq.{succ u1} X x' x))) X (coeSubtype.{succ u1} X (fun (x' : X) => Not (Eq.{succ u1} X x' x)))))) x') x) (fun (h : Not (Eq.{succ u1} X ((fun (a : Type.{u1}) (b : Type.{u1}) [self : HasLiftT.{succ u1, succ u1} a b] => self.0) (Subtype.{succ u1} X (fun (x' : X) => Not (Eq.{succ u1} X x' x))) X (HasLiftT.mk.{succ u1, succ u1} (Subtype.{succ u1} X (fun (x' : X) => Not (Eq.{succ u1} X x' x))) X (CoeTCₓ.coe.{succ u1, succ u1} (Subtype.{succ u1} X (fun (x' : X) => Not (Eq.{succ u1} X x' x))) X (coeBase.{succ u1, succ u1} (Subtype.{succ u1} X (fun (x' : X) => Not (Eq.{succ u1} X x' x))) X (coeSubtype.{succ u1} X (fun (x' : X) => Not (Eq.{succ u1} X x' x)))))) x') x)) => f (Subtype.mk.{succ u1} X (fun (x' : X) => Not (Eq.{succ u1} X x' x)) ((fun (a : Type.{u1}) (b : Type.{u1}) [self : HasLiftT.{succ u1, succ u1} a b] => self.0) (Subtype.{succ u1} X (fun (x' : X) => Not (Eq.{succ u1} X x' x))) X (HasLiftT.mk.{succ u1, succ u1} (Subtype.{succ u1} X (fun (x' : X) => Not (Eq.{succ u1} X x' x))) X (CoeTCₓ.coe.{succ u1, succ u1} (Subtype.{succ u1} X (fun (x' : X) => Not (Eq.{succ u1} X x' x))) X (coeBase.{succ u1, succ u1} (Subtype.{succ u1} X (fun (x' : X) => Not (Eq.{succ u1} X x' x))) X (coeSubtype.{succ u1} X (fun (x' : X) => Not (Eq.{succ u1} X x' x)))))) x') h)) (fun (h : Not (Not (Eq.{succ u1} X ((fun (a : Type.{u1}) (b : Type.{u1}) [self : HasLiftT.{succ u1, succ u1} a b] => self.0) (Subtype.{succ u1} X (fun (x' : X) => Not (Eq.{succ u1} X x' x))) X (HasLiftT.mk.{succ u1, succ u1} (Subtype.{succ u1} X (fun (x' : X) => Not (Eq.{succ u1} X x' x))) X (CoeTCₓ.coe.{succ u1, succ u1} (Subtype.{succ u1} X (fun (x' : X) => Not (Eq.{succ u1} X x' x))) X (coeBase.{succ u1, succ u1} (Subtype.{succ u1} X (fun (x' : X) => Not (Eq.{succ u1} X x' x))) X (coeSubtype.{succ u1} X (fun (x' : X) => Not (Eq.{succ u1} X x' x)))))) x') x))) => y)) (f x')) (Eq.{succ u2} Y (f (Subtype.mk.{succ u1} X (fun (x' : X) => Not (Eq.{succ u1} X x' x)) ((fun (a : Type.{u1}) (b : Type.{u1}) [self : HasLiftT.{succ u1, succ u1} a b] => self.0) (Subtype.{succ u1} X (fun (x' : X) => Not (Eq.{succ u1} X x' x))) X (HasLiftT.mk.{succ u1, succ u1} (Subtype.{succ u1} X (fun (x' : X) => Not (Eq.{succ u1} X x' x))) X (CoeTCₓ.coe.{succ u1, succ u1} (Subtype.{succ u1} X (fun (x' : X) => Not (Eq.{succ u1} X x' x))) X (coeBase.{succ u1, succ u1} (Subtype.{succ u1} X (fun (x' : X) => Not (Eq.{succ u1} X x' x))) X (coeSubtype.{succ u1} X (fun (x' : X) => Not (Eq.{succ u1} X x' x)))))) x') (Subtype.property.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x) x'))) (f x'))) (Eq.ndrec.{0, succ u2} Y (dite.{succ u2} Y (Ne.{succ u1} X (Subtype.val.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x) x') x) (Ne.decidable.{succ u1} X (fun (a : X) (b : X) => _inst_1 a b) (Subtype.val.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x) x') x) (fun (h : Not (Eq.{succ u1} X ((fun (a : Type.{u1}) (b : Type.{u1}) [self : HasLiftT.{succ u1, succ u1} a b] => self.0) (Subtype.{succ u1} X (fun (x' : X) => Not (Eq.{succ u1} X x' x))) X (HasLiftT.mk.{succ u1, succ u1} (Subtype.{succ u1} X (fun (x' : X) => Not (Eq.{succ u1} X x' x))) X (CoeTCₓ.coe.{succ u1, succ u1} (Subtype.{succ u1} X (fun (x' : X) => Not (Eq.{succ u1} X x' x))) X (coeBase.{succ u1, succ u1} (Subtype.{succ u1} X (fun (x' : X) => Not (Eq.{succ u1} X x' x))) X (coeSubtype.{succ u1} X (fun (x' : X) => Not (Eq.{succ u1} X x' x)))))) x') x)) => f (Subtype.mk.{succ u1} X (fun (x' : X) => Not (Eq.{succ u1} X x' x)) ((fun (a : Type.{u1}) (b : Type.{u1}) [self : HasLiftT.{succ u1, succ u1} a b] => self.0) (Subtype.{succ u1} X (fun (x' : X) => Not (Eq.{succ u1} X x' x))) X (HasLiftT.mk.{succ u1, succ u1} (Subtype.{succ u1} X (fun (x' : X) => Not (Eq.{succ u1} X x' x))) X (CoeTCₓ.coe.{succ u1, succ u1} (Subtype.{succ u1} X (fun (x' : X) => Not (Eq.{succ u1} X x' x))) X (coeBase.{succ u1, succ u1} (Subtype.{succ u1} X (fun (x' : X) => Not (Eq.{succ u1} X x' x))) X (coeSubtype.{succ u1} X (fun (x' : X) => Not (Eq.{succ u1} X x' x)))))) x') h)) (fun (h : Not (Not (Eq.{succ u1} X ((fun (a : Type.{u1}) (b : Type.{u1}) [self : HasLiftT.{succ u1, succ u1} a b] => self.0) (Subtype.{succ u1} X (fun (x' : X) => Not (Eq.{succ u1} X x' x))) X (HasLiftT.mk.{succ u1, succ u1} (Subtype.{succ u1} X (fun (x' : X) => Not (Eq.{succ u1} X x' x))) X (CoeTCₓ.coe.{succ u1, succ u1} (Subtype.{succ u1} X (fun (x' : X) => Not (Eq.{succ u1} X x' x))) X (coeBase.{succ u1, succ u1} (Subtype.{succ u1} X (fun (x' : X) => Not (Eq.{succ u1} X x' x))) X (coeSubtype.{succ u1} X (fun (x' : X) => Not (Eq.{succ u1} X x' x)))))) x') x))) => y)) (fun (_a : Y) => Eq.{1} Prop (Eq.{succ u2} Y (dite.{succ u2} Y (Not (Eq.{succ u1} X ((fun (a : Type.{u1}) (b : Type.{u1}) [self : HasLiftT.{succ u1, succ u1} a b] => self.0) (Subtype.{succ u1} X (fun (x' : X) => Not (Eq.{succ u1} X x' x))) X (HasLiftT.mk.{succ u1, succ u1} (Subtype.{succ u1} X (fun (x' : X) => Not (Eq.{succ u1} X x' x))) X (CoeTCₓ.coe.{succ u1, succ u1} (Subtype.{succ u1} X (fun (x' : X) => Not (Eq.{succ u1} X x' x))) X (coeBase.{succ u1, succ u1} (Subtype.{succ u1} X (fun (x' : X) => Not (Eq.{succ u1} X x' x))) X (coeSubtype.{succ u1} X (fun (x' : X) => Not (Eq.{succ u1} X x' x)))))) x') x)) (Ne.decidable.{succ u1} X _inst_1 ((fun (a : Type.{u1}) (b : Type.{u1}) [self : HasLiftT.{succ u1, succ u1} a b] => self.0) (Subtype.{succ u1} X (fun (x' : X) => Not (Eq.{succ u1} X x' x))) X (HasLiftT.mk.{succ u1, succ u1} (Subtype.{succ u1} X (fun (x' : X) => Not (Eq.{succ u1} X x' x))) X (CoeTCₓ.coe.{succ u1, succ u1} (Subtype.{succ u1} X (fun (x' : X) => Not (Eq.{succ u1} X x' x))) X (coeBase.{succ u1, succ u1} (Subtype.{succ u1} X (fun (x' : X) => Not (Eq.{succ u1} X x' x))) X (coeSubtype.{succ u1} X (fun (x' : X) => Not (Eq.{succ u1} X x' x)))))) x') x) (fun (h : Not (Eq.{succ u1} X ((fun (a : Type.{u1}) (b : Type.{u1}) [self : HasLiftT.{succ u1, succ u1} a b] => self.0) (Subtype.{succ u1} X (fun (x' : X) => Not (Eq.{succ u1} X x' x))) X (HasLiftT.mk.{succ u1, succ u1} (Subtype.{succ u1} X (fun (x' : X) => Not (Eq.{succ u1} X x' x))) X (CoeTCₓ.coe.{succ u1, succ u1} (Subtype.{succ u1} X (fun (x' : X) => Not (Eq.{succ u1} X x' x))) X (coeBase.{succ u1, succ u1} (Subtype.{succ u1} X (fun (x' : X) => Not (Eq.{succ u1} X x' x))) X (coeSubtype.{succ u1} X (fun (x' : X) => Not (Eq.{succ u1} X x' x)))))) x') x)) => f (Subtype.mk.{succ u1} X (fun (x' : X) => Not (Eq.{succ u1} X x' x)) ((fun (a : Type.{u1}) (b : Type.{u1}) [self : HasLiftT.{succ u1, succ u1} a b] => self.0) (Subtype.{succ u1} X (fun (x' : X) => Not (Eq.{succ u1} X x' x))) X (HasLiftT.mk.{succ u1, succ u1} (Subtype.{succ u1} X (fun (x' : X) => Not (Eq.{succ u1} X x' x))) X (CoeTCₓ.coe.{succ u1, succ u1} (Subtype.{succ u1} X (fun (x' : X) => Not (Eq.{succ u1} X x' x))) X (coeBase.{succ u1, succ u1} (Subtype.{succ u1} X (fun (x' : X) => Not (Eq.{succ u1} X x' x))) X (coeSubtype.{succ u1} X (fun (x' : X) => Not (Eq.{succ u1} X x' x)))))) x') h)) (fun (h : Not (Not (Eq.{succ u1} X ((fun (a : Type.{u1}) (b : Type.{u1}) [self : HasLiftT.{succ u1, succ u1} a b] => self.0) (Subtype.{succ u1} X (fun (x' : X) => Not (Eq.{succ u1} X x' x))) X (HasLiftT.mk.{succ u1, succ u1} (Subtype.{succ u1} X (fun (x' : X) => Not (Eq.{succ u1} X x' x))) X (CoeTCₓ.coe.{succ u1, succ u1} (Subtype.{succ u1} X (fun (x' : X) => Not (Eq.{succ u1} X x' x))) X (coeBase.{succ u1, succ u1} (Subtype.{succ u1} X (fun (x' : X) => Not (Eq.{succ u1} X x' x))) X (coeSubtype.{succ u1} X (fun (x' : X) => Not (Eq.{succ u1} X x' x)))))) x') x))) => y)) (f x')) (Eq.{succ u2} Y _a (f x'))) (rfl.{1} Prop (Eq.{succ u2} Y (dite.{succ u2} Y (Not (Eq.{succ u1} X ((fun (a : Type.{u1}) (b : Type.{u1}) [self : HasLiftT.{succ u1, succ u1} a b] => self.0) (Subtype.{succ u1} X (fun (x' : X) => Not (Eq.{succ u1} X x' x))) X (HasLiftT.mk.{succ u1, succ u1} (Subtype.{succ u1} X (fun (x' : X) => Not (Eq.{succ u1} X x' x))) X (CoeTCₓ.coe.{succ u1, succ u1} (Subtype.{succ u1} X (fun (x' : X) => Not (Eq.{succ u1} X x' x))) X (coeBase.{succ u1, succ u1} (Subtype.{succ u1} X (fun (x' : X) => Not (Eq.{succ u1} X x' x))) X (coeSubtype.{succ u1} X (fun (x' : X) => Not (Eq.{succ u1} X x' x)))))) x') x)) (Ne.decidable.{succ u1} X _inst_1 ((fun (a : Type.{u1}) (b : Type.{u1}) [self : HasLiftT.{succ u1, succ u1} a b] => self.0) (Subtype.{succ u1} X (fun (x' : X) => Not (Eq.{succ u1} X x' x))) X (HasLiftT.mk.{succ u1, succ u1} (Subtype.{succ u1} X (fun (x' : X) => Not (Eq.{succ u1} X x' x))) X (CoeTCₓ.coe.{succ u1, succ u1} (Subtype.{succ u1} X (fun (x' : X) => Not (Eq.{succ u1} X x' x))) X (coeBase.{succ u1, succ u1} (Subtype.{succ u1} X (fun (x' : X) => Not (Eq.{succ u1} X x' x))) X (coeSubtype.{succ u1} X (fun (x' : X) => Not (Eq.{succ u1} X x' x)))))) x') x) (fun (h : Not (Eq.{succ u1} X ((fun (a : Type.{u1}) (b : Type.{u1}) [self : HasLiftT.{succ u1, succ u1} a b] => self.0) (Subtype.{succ u1} X (fun (x' : X) => Not (Eq.{succ u1} X x' x))) X (HasLiftT.mk.{succ u1, succ u1} (Subtype.{succ u1} X (fun (x' : X) => Not (Eq.{succ u1} X x' x))) X (CoeTCₓ.coe.{succ u1, succ u1} (Subtype.{succ u1} X (fun (x' : X) => Not (Eq.{succ u1} X x' x))) X (coeBase.{succ u1, succ u1} (Subtype.{succ u1} X (fun (x' : X) => Not (Eq.{succ u1} X x' x))) X (coeSubtype.{succ u1} X (fun (x' : X) => Not (Eq.{succ u1} X x' x)))))) x') x)) => f (Subtype.mk.{succ u1} X (fun (x' : X) => Not (Eq.{succ u1} X x' x)) ((fun (a : Type.{u1}) (b : Type.{u1}) [self : HasLiftT.{succ u1, succ u1} a b] => self.0) (Subtype.{succ u1} X (fun (x' : X) => Not (Eq.{succ u1} X x' x))) X (HasLiftT.mk.{succ u1, succ u1} (Subtype.{succ u1} X (fun (x' : X) => Not (Eq.{succ u1} X x' x))) X (CoeTCₓ.coe.{succ u1, succ u1} (Subtype.{succ u1} X (fun (x' : X) => Not (Eq.{succ u1} X x' x))) X (coeBase.{succ u1, succ u1} (Subtype.{succ u1} X (fun (x' : X) => Not (Eq.{succ u1} X x' x))) X (coeSubtype.{succ u1} X (fun (x' : X) => Not (Eq.{succ u1} X x' x)))))) x') h)) (fun (h : Not (Not (Eq.{succ u1} X ((fun (a : Type.{u1}) (b : Type.{u1}) [self : HasLiftT.{succ u1, succ u1} a b] => self.0) (Subtype.{succ u1} X (fun (x' : X) => Not (Eq.{succ u1} X x' x))) X (HasLiftT.mk.{succ u1, succ u1} (Subtype.{succ u1} X (fun (x' : X) => Not (Eq.{succ u1} X x' x))) X (CoeTCₓ.coe.{succ u1, succ u1} (Subtype.{succ u1} X (fun (x' : X) => Not (Eq.{succ u1} X x' x))) X (coeBase.{succ u1, succ u1} (Subtype.{succ u1} X (fun (x' : X) => Not (Eq.{succ u1} X x' x))) X (coeSubtype.{succ u1} X (fun (x' : X) => Not (Eq.{succ u1} X x' x)))))) x') x))) => y)) (f x'))) (f (Subtype.mk.{succ u1} X (fun (x' : X) => Not (Eq.{succ u1} X x' x)) ((fun (a : Type.{u1}) (b : Type.{u1}) [self : HasLiftT.{succ u1, succ u1} a b] => self.0) (Subtype.{succ u1} X (fun (x' : X) => Not (Eq.{succ u1} X x' x))) X (HasLiftT.mk.{succ u1, succ u1} (Subtype.{succ u1} X (fun (x' : X) => Not (Eq.{succ u1} X x' x))) X (CoeTCₓ.coe.{succ u1, succ u1} (Subtype.{succ u1} X (fun (x' : X) => Not (Eq.{succ u1} X x' x))) X (coeBase.{succ u1, succ u1} (Subtype.{succ u1} X (fun (x' : X) => Not (Eq.{succ u1} X x' x))) X (coeSubtype.{succ u1} X (fun (x' : X) => Not (Eq.{succ u1} X x' x)))))) x') (Subtype.property.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x) x'))) (dif_pos.{succ u2} (Ne.{succ u1} X (Subtype.val.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x) x') x) (Ne.decidable.{succ u1} X (fun (a : X) (b : X) => _inst_1 a b) (Subtype.val.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x) x') x) (Subtype.property.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x) x') Y (fun (h : Not (Eq.{succ u1} X ((fun (a : Type.{u1}) (b : Type.{u1}) [self : HasLiftT.{succ u1, succ u1} a b] => self.0) (Subtype.{succ u1} X (fun (x' : X) => Not (Eq.{succ u1} X x' x))) X (HasLiftT.mk.{succ u1, succ u1} (Subtype.{succ u1} X (fun (x' : X) => Not (Eq.{succ u1} X x' x))) X (CoeTCₓ.coe.{succ u1, succ u1} (Subtype.{succ u1} X (fun (x' : X) => Not (Eq.{succ u1} X x' x))) X (coeBase.{succ u1, succ u1} (Subtype.{succ u1} X (fun (x' : X) => Not (Eq.{succ u1} X x' x))) X (coeSubtype.{succ u1} X (fun (x' : X) => Not (Eq.{succ u1} X x' x)))))) x') x)) => f (Subtype.mk.{succ u1} X (fun (x' : X) => Not (Eq.{succ u1} X x' x)) ((fun (a : Type.{u1}) (b : Type.{u1}) [self : HasLiftT.{succ u1, succ u1} a b] => self.0) (Subtype.{succ u1} X (fun (x' : X) => Not (Eq.{succ u1} X x' x))) X (HasLiftT.mk.{succ u1, succ u1} (Subtype.{succ u1} X (fun (x' : X) => Not (Eq.{succ u1} X x' x))) X (CoeTCₓ.coe.{succ u1, succ u1} (Subtype.{succ u1} X (fun (x' : X) => Not (Eq.{succ u1} X x' x))) X (coeBase.{succ u1, succ u1} (Subtype.{succ u1} X (fun (x' : X) => Not (Eq.{succ u1} X x' x))) X (coeSubtype.{succ u1} X (fun (x' : X) => Not (Eq.{succ u1} X x' x)))))) x') h)) (fun (h : Not (Not (Eq.{succ u1} X ((fun (a : Type.{u1}) (b : Type.{u1}) [self : HasLiftT.{succ u1, succ u1} a b] => self.0) (Subtype.{succ u1} X (fun (x' : X) => Not (Eq.{succ u1} X x' x))) X (HasLiftT.mk.{succ u1, succ u1} (Subtype.{succ u1} X (fun (x' : X) => Not (Eq.{succ u1} X x' x))) X (CoeTCₓ.coe.{succ u1, succ u1} (Subtype.{succ u1} X (fun (x' : X) => Not (Eq.{succ u1} X x' x))) X (coeBase.{succ u1, succ u1} (Subtype.{succ u1} X (fun (x' : X) => Not (Eq.{succ u1} X x' x))) X (coeSubtype.{succ u1} X (fun (x' : X) => Not (Eq.{succ u1} X x' x)))))) x') x))) => y)))) (Eq.mpr.{0} (Eq.{succ u2} Y (f (Subtype.mk.{succ u1} X (fun (x' : X) => Not (Eq.{succ u1} X x' x)) ((fun (a : Type.{u1}) (b : Type.{u1}) [self : HasLiftT.{succ u1, succ u1} a b] => self.0) (Subtype.{succ u1} X (fun (x' : X) => Not (Eq.{succ u1} X x' x))) X (HasLiftT.mk.{succ u1, succ u1} (Subtype.{succ u1} X (fun (x' : X) => Not (Eq.{succ u1} X x' x))) X (CoeTCₓ.coe.{succ u1, succ u1} (Subtype.{succ u1} X (fun (x' : X) => Not (Eq.{succ u1} X x' x))) X (coeBase.{succ u1, succ u1} (Subtype.{succ u1} X (fun (x' : X) => Not (Eq.{succ u1} X x' x))) X (coeSubtype.{succ u1} X (fun (x' : X) => Not (Eq.{succ u1} X x' x)))))) x') (Subtype.property.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x) x'))) (f x')) (Eq.{succ u2} Y (f x') (f x')) (id_tag Tactic.IdTag.rw (Eq.{1} Prop (Eq.{succ u2} Y (f (Subtype.mk.{succ u1} X (fun (x' : X) => Not (Eq.{succ u1} X x' x)) ((fun (a : Type.{u1}) (b : Type.{u1}) [self : HasLiftT.{succ u1, succ u1} a b] => self.0) (Subtype.{succ u1} X (fun (x' : X) => Not (Eq.{succ u1} X x' x))) X (HasLiftT.mk.{succ u1, succ u1} (Subtype.{succ u1} X (fun (x' : X) => Not (Eq.{succ u1} X x' x))) X (CoeTCₓ.coe.{succ u1, succ u1} (Subtype.{succ u1} X (fun (x' : X) => Not (Eq.{succ u1} X x' x))) X (coeBase.{succ u1, succ u1} (Subtype.{succ u1} X (fun (x' : X) => Not (Eq.{succ u1} X x' x))) X (coeSubtype.{succ u1} X (fun (x' : X) => Not (Eq.{succ u1} X x' x)))))) x') (Subtype.property.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x) x'))) (f x')) (Eq.{succ u2} Y (f x') (f x'))) (Eq.ndrec.{0, succ u1} (Subtype.{succ u1} X (fun (x' : X) => Not (Eq.{succ u1} X x' x))) (Subtype.mk.{succ u1} X (fun (x' : X) => Not (Eq.{succ u1} X x' x)) ((fun (a : Type.{u1}) (b : Type.{u1}) [self : HasLiftT.{succ u1, succ u1} a b] => self.0) (Subtype.{succ u1} X (fun (a : X) => Not (Eq.{succ u1} X a x))) X (HasLiftT.mk.{succ u1, succ u1} (Subtype.{succ u1} X (fun (a : X) => Not (Eq.{succ u1} X a x))) X (CoeTCₓ.coe.{succ u1, succ u1} (Subtype.{succ u1} X (fun (a : X) => Not (Eq.{succ u1} X a x))) X (coeBase.{succ u1, succ u1} (Subtype.{succ u1} X (fun (a : X) => Not (Eq.{succ u1} X a x))) X (coeSubtype.{succ u1} X (fun (a : X) => Not (Eq.{succ u1} X a x)))))) x') (Subtype.property.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x) x')) (fun (_a : Subtype.{succ u1} X (fun (x' : X) => Not (Eq.{succ u1} X x' x))) => Eq.{1} Prop (Eq.{succ u2} Y (f (Subtype.mk.{succ u1} X (fun (x' : X) => Not (Eq.{succ u1} X x' x)) ((fun (a : Type.{u1}) (b : Type.{u1}) [self : HasLiftT.{succ u1, succ u1} a b] => self.0) (Subtype.{succ u1} X (fun (x' : X) => Not (Eq.{succ u1} X x' x))) X (HasLiftT.mk.{succ u1, succ u1} (Subtype.{succ u1} X (fun (x' : X) => Not (Eq.{succ u1} X x' x))) X (CoeTCₓ.coe.{succ u1, succ u1} (Subtype.{succ u1} X (fun (x' : X) => Not (Eq.{succ u1} X x' x))) X (coeBase.{succ u1, succ u1} (Subtype.{succ u1} X (fun (x' : X) => Not (Eq.{succ u1} X x' x))) X (coeSubtype.{succ u1} X (fun (x' : X) => Not (Eq.{succ u1} X x' x)))))) x') (Subtype.property.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x) x'))) (f x')) (Eq.{succ u2} Y (f _a) (f x'))) (rfl.{1} Prop (Eq.{succ u2} Y (f (Subtype.mk.{succ u1} X (fun (x' : X) => Not (Eq.{succ u1} X x' x)) ((fun (a : Type.{u1}) (b : Type.{u1}) [self : HasLiftT.{succ u1, succ u1} a b] => self.0) (Subtype.{succ u1} X (fun (x' : X) => Not (Eq.{succ u1} X x' x))) X (HasLiftT.mk.{succ u1, succ u1} (Subtype.{succ u1} X (fun (x' : X) => Not (Eq.{succ u1} X x' x))) X (CoeTCₓ.coe.{succ u1, succ u1} (Subtype.{succ u1} X (fun (x' : X) => Not (Eq.{succ u1} X x' x))) X (coeBase.{succ u1, succ u1} (Subtype.{succ u1} X (fun (x' : X) => Not (Eq.{succ u1} X x' x))) X (coeSubtype.{succ u1} X (fun (x' : X) => Not (Eq.{succ u1} X x' x)))))) x') (Subtype.property.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x) x'))) (f x'))) x' (Subtype.coe_eta.{succ u1} X (fun (x' : X) => Not (Eq.{succ u1} X x' x)) x' (Subtype.property.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x) x')))) (rfl.{succ u2} Y (f x'))))))) but is expected to have type forall {X : Sort.{u1}} [Y : DecidableEq.{u1} X] {_inst_1 : X} {x : Sort.{u2}} (f : (Subtype.{u1} X (fun (x' : X) => Ne.{u1} X x' _inst_1)) -> x), Eq.{max (max 1 u2) (imax u1 u2)} (forall (a : x), (fun ([email protected]._hyg.808 : x) => Subtype.{imax u1 u2} (X -> x) (fun (g : X -> x) => Eq.{imax (max 1 u1) u2} ((Subtype.{u1} X (fun (x' : X) => Ne.{u1} X x' _inst_1)) -> x) (Function.comp.{max 1 u1, u1, u2} (Subtype.{u1} X (fun (x' : X) => Ne.{u1} X x' _inst_1)) X x g (Subtype.val.{u1} X (fun (x' : X) => Ne.{u1} X x' _inst_1))) f)) a) (FunLike.coe.{max (max 1 u2) (imax u1 u2), u2, max 1 (imax u1 u2)} (Equiv.{u2, max 1 (imax u1 u2)} x (Subtype.{imax u1 u2} (X -> x) (fun (g : X -> x) => Eq.{imax (max 1 u1) u2} ((Subtype.{u1} X (fun (x' : X) => Ne.{u1} X x' _inst_1)) -> x) (Function.comp.{max 1 u1, u1, u2} (Subtype.{u1} X (fun (x' : X) => Ne.{u1} X x' _inst_1)) X x g (Subtype.val.{u1} X (fun (x' : X) => Ne.{u1} X x' _inst_1))) f))) x (fun (_x : x) => (fun ([email protected]._hyg.808 : x) => Subtype.{imax u1 u2} (X -> x) (fun (g : X -> x) => Eq.{imax (max 1 u1) u2} ((Subtype.{u1} X (fun (x' : X) => Ne.{u1} X x' _inst_1)) -> x) (Function.comp.{max 1 u1, u1, u2} (Subtype.{u1} X (fun (x' : X) => Ne.{u1} X x' _inst_1)) X x g (Subtype.val.{u1} X (fun (x' : X) => Ne.{u1} X x' _inst_1))) f)) _x) (Equiv.instFunLikeEquiv.{u2, max 1 (imax u1 u2)} x (Subtype.{imax u1 u2} (X -> x) (fun (g : X -> x) => Eq.{imax (max 1 u1) u2} ((Subtype.{u1} X (fun (x' : X) => Ne.{u1} X x' _inst_1)) -> x) (Function.comp.{max 1 u1, u1, u2} (Subtype.{u1} X (fun (x' : X) => Ne.{u1} X x' _inst_1)) X x g (Subtype.val.{u1} X (fun (x' : X) => Ne.{u1} X x' _inst_1))) f))) (Equiv.symm.{max 1 (imax u1 u2), u2} (Subtype.{imax u1 u2} (X -> x) (fun (g : X -> x) => Eq.{imax (max 1 u1) u2} ((Subtype.{u1} X (fun (x' : X) => Ne.{u1} X x' _inst_1)) -> x) (Function.comp.{max 1 u1, u1, u2} (Subtype.{u1} X (fun (x' : X) => Ne.{u1} X x' _inst_1)) X x g (Subtype.val.{u1} X (fun (x' : X) => Ne.{u1} X x' _inst_1))) f)) x (Equiv.subtypeEquivCodomain.{u1, u2} X (fun (a : X) (b : X) => Y a b) _inst_1 x f))) (fun (y : x) => Subtype.mk.{imax u1 u2} (X -> x) (fun (g : X -> x) => Eq.{imax (max 1 u1) u2} ((Subtype.{u1} X (fun (x' : X) => Ne.{u1} X x' _inst_1)) -> x) (Function.comp.{max 1 u1, u1, u2} (Subtype.{u1} X (fun (x' : X) => Ne.{u1} X x' _inst_1)) X x g (Subtype.val.{u1} X (fun (x' : X) => Ne.{u1} X x' _inst_1))) f) (fun (x' : X) => dite.{u2} x (Ne.{u1} X x' _inst_1) (instDecidableNot (Eq.{u1} X x' _inst_1) (Y x' _inst_1)) (fun (h : Ne.{u1} X x' _inst_1) => f (Subtype.mk.{u1} X (fun (x' : X) => Ne.{u1} X x' _inst_1) x' h)) (fun (h : Not (Ne.{u1} X x' _inst_1)) => y)) (funext.{max 1 u1, u2} (Subtype.{u1} X (fun (x' : X) => Ne.{u1} X x' _inst_1)) (fun (x_1 : Subtype.{u1} X (fun (x' : X) => Ne.{u1} X x' _inst_1)) => x) (Function.comp.{max 1 u1, u1, u2} (Subtype.{u1} X (fun (x' : X) => Ne.{u1} X x' _inst_1)) X x (fun (x' : X) => dite.{u2} x (Ne.{u1} X x' _inst_1) (instDecidableNot (Eq.{u1} X x' _inst_1) (Y x' _inst_1)) (fun (h : Ne.{u1} X x' _inst_1) => f (Subtype.mk.{u1} X (fun (x' : X) => Ne.{u1} X x' _inst_1) x' h)) (fun (h : Not (Ne.{u1} X x' _inst_1)) => y)) (Subtype.val.{u1} X (fun (x' : X) => Ne.{u1} X x' _inst_1))) f (fun (x' : Subtype.{u1} X (fun (x' : X) => Ne.{u1} X x' _inst_1)) => Eq.mpr.{0} (Eq.{u2} x (Function.comp.{max 1 u1, u1, u2} (Subtype.{u1} X (fun (x' : X) => Ne.{u1} X x' _inst_1)) X x (fun (x' : X) => dite.{u2} x (Ne.{u1} X x' _inst_1) (instDecidableNot (Eq.{u1} X x' _inst_1) (Y x' _inst_1)) (fun (h : Ne.{u1} X x' _inst_1) => f (Subtype.mk.{u1} X (fun (x' : X) => Ne.{u1} X x' _inst_1) x' h)) (fun (h : Not (Ne.{u1} X x' _inst_1)) => y)) (Subtype.val.{u1} X (fun (x' : X) => Ne.{u1} X x' _inst_1)) x') (f x')) ((Eq.{u1} X (Subtype.val.{u1} X (fun (x' : X) => Not (Eq.{u1} X x' _inst_1)) x') _inst_1) -> (Eq.{u2} x y (f x'))) (id.{0} (Eq.{1} Prop (Eq.{u2} x (Function.comp.{max 1 u1, u1, u2} (Subtype.{u1} X (fun (x' : X) => Ne.{u1} X x' _inst_1)) X x (fun (x' : X) => dite.{u2} x (Ne.{u1} X x' _inst_1) (instDecidableNot (Eq.{u1} X x' _inst_1) (Y x' _inst_1)) (fun (h : Ne.{u1} X x' _inst_1) => f (Subtype.mk.{u1} X (fun (x' : X) => Ne.{u1} X x' _inst_1) x' h)) (fun (h : Not (Ne.{u1} X x' _inst_1)) => y)) (Subtype.val.{u1} X (fun (x' : X) => Ne.{u1} X x' _inst_1)) x') (f x')) ((Eq.{u1} X (Subtype.val.{u1} X (fun (x' : X) => Not (Eq.{u1} X x' _inst_1)) x') _inst_1) -> (Eq.{u2} x y (f x')))) (Eq.trans.{1} Prop (Eq.{u2} x (Function.comp.{max 1 u1, u1, u2} (Subtype.{u1} X (fun (x' : X) => Not (Eq.{u1} X x' _inst_1))) X x (fun (x_1 : X) => dite.{u2} x (Not (Eq.{u1} X x_1 _inst_1)) (instDecidableNot (Eq.{u1} X x_1 _inst_1) (Y x_1 _inst_1)) (fun (h : Not (Eq.{u1} X x_1 _inst_1)) => f (Subtype.mk.{u1} X (fun (x' : X) => Ne.{u1} X x' _inst_1) x_1 h)) (fun (h : Not (Not (Eq.{u1} X x_1 _inst_1))) => y)) (Subtype.val.{u1} X (fun (x' : X) => Not (Eq.{u1} X x' _inst_1))) x') (f x')) (Eq.{u2} x (dite.{u2} x (Eq.{u1} X (Subtype.val.{u1} X (fun (x' : X) => Not (Eq.{u1} X x' _inst_1)) x') _inst_1) (Y (Subtype.val.{u1} X (fun (x' : X) => Not (Eq.{u1} X x' _inst_1)) x') _inst_1) (fun (h : Eq.{u1} X (Subtype.val.{u1} X (fun (x' : X) => Not (Eq.{u1} X x' _inst_1)) x') _inst_1) => y) (fun (h : Not (Eq.{u1} X (Subtype.val.{u1} X (fun (x' : X) => Not (Eq.{u1} X x' _inst_1)) x') _inst_1)) => f x')) (f x')) ((Eq.{u1} X (Subtype.val.{u1} X (fun (x' : X) => Not (Eq.{u1} X x' _inst_1)) x') _inst_1) -> (Eq.{u2} x y (f x'))) (congrFun.{u2, 1} x (fun ([email protected]._hyg.170 : x) => Prop) (Eq.{u2} x (Function.comp.{max 1 u1, u1, u2} (Subtype.{u1} X (fun (x' : X) => Not (Eq.{u1} X x' _inst_1))) X x (fun (x_1 : X) => dite.{u2} x (Not (Eq.{u1} X x_1 _inst_1)) (instDecidableNot (Eq.{u1} X x_1 _inst_1) (Y x_1 _inst_1)) (fun (h : Not (Eq.{u1} X x_1 _inst_1)) => f (Subtype.mk.{u1} X (fun (x' : X) => Ne.{u1} X x' _inst_1) x_1 h)) (fun (h : Not (Not (Eq.{u1} X x_1 _inst_1))) => y)) (Subtype.val.{u1} X (fun (x' : X) => Not (Eq.{u1} X x' _inst_1))) x')) (Eq.{u2} x (dite.{u2} x (Eq.{u1} X (Subtype.val.{u1} X (fun (x' : X) => Not (Eq.{u1} X x' _inst_1)) x') _inst_1) (Y (Subtype.val.{u1} X (fun (x' : X) => Not (Eq.{u1} X x' _inst_1)) x') _inst_1) (fun (h : Eq.{u1} X (Subtype.val.{u1} X (fun (x' : X) => Not (Eq.{u1} X x' _inst_1)) x') _inst_1) => y) (fun (h : Not (Eq.{u1} X (Subtype.val.{u1} X (fun (x' : X) => Not (Eq.{u1} X x' _inst_1)) x') _inst_1)) => f x'))) (congrArg.{u2, max 1 u2} x (x -> Prop) (Function.comp.{max 1 u1, u1, u2} (Subtype.{u1} X (fun (x' : X) => Not (Eq.{u1} X x' _inst_1))) X x (fun (x_1 : X) => dite.{u2} x (Not (Eq.{u1} X x_1 _inst_1)) (instDecidableNot (Eq.{u1} X x_1 _inst_1) (Y x_1 _inst_1)) (fun (h : Not (Eq.{u1} X x_1 _inst_1)) => f (Subtype.mk.{u1} X (fun (x' : X) => Ne.{u1} X x' _inst_1) x_1 h)) (fun (h : Not (Not (Eq.{u1} X x_1 _inst_1))) => y)) (Subtype.val.{u1} X (fun (x' : X) => Not (Eq.{u1} X x' _inst_1))) x') (dite.{u2} x (Eq.{u1} X (Subtype.val.{u1} X (fun (x' : X) => Not (Eq.{u1} X x' _inst_1)) x') _inst_1) (Y (Subtype.val.{u1} X (fun (x' : X) => Not (Eq.{u1} X x' _inst_1)) x') _inst_1) (fun (h : Eq.{u1} X (Subtype.val.{u1} X (fun (x' : X) => Not (Eq.{u1} X x' _inst_1)) x') _inst_1) => y) (fun (h : Not (Eq.{u1} X (Subtype.val.{u1} X (fun (x' : X) => Not (Eq.{u1} X x' _inst_1)) x') _inst_1)) => f x')) (Eq.{u2} x) (Eq.trans.{u2} x (Function.comp.{max 1 u1, u1, u2} (Subtype.{u1} X (fun (x' : X) => Not (Eq.{u1} X x' _inst_1))) X x (fun (x_1 : X) => dite.{u2} x (Not (Eq.{u1} X x_1 _inst_1)) (instDecidableNot (Eq.{u1} X x_1 _inst_1) (Y x_1 _inst_1)) (fun (h : Not (Eq.{u1} X x_1 _inst_1)) => f (Subtype.mk.{u1} X (fun (x' : X) => Ne.{u1} X x' _inst_1) x_1 h)) (fun (h : Not (Not (Eq.{u1} X x_1 _inst_1))) => y)) (Subtype.val.{u1} X (fun (x' : X) => Not (Eq.{u1} X x' _inst_1))) x') (Function.comp.{max 1 u1, u1, u2} (Subtype.{u1} X (fun (x' : X) => Not (Eq.{u1} X x' _inst_1))) X x (fun (x_1 : X) => dite.{u2} x (Eq.{u1} X x_1 _inst_1) (Y x_1 _inst_1) (fun (h : Eq.{u1} X x_1 _inst_1) => y) (fun (h : Not (Eq.{u1} X x_1 _inst_1)) => f (Subtype.mk.{u1} X (fun (x' : X) => Ne.{u1} X x' _inst_1) x_1 h))) (Subtype.val.{u1} X (fun (x' : X) => Not (Eq.{u1} X x' _inst_1))) x') (dite.{u2} x (Eq.{u1} X (Subtype.val.{u1} X (fun (x' : X) => Not (Eq.{u1} X x' _inst_1)) x') _inst_1) (Y (Subtype.val.{u1} X (fun (x' : X) => Not (Eq.{u1} X x' _inst_1)) x') _inst_1) (fun (h : Eq.{u1} X (Subtype.val.{u1} X (fun (x' : X) => Not (Eq.{u1} X x' _inst_1)) x') _inst_1) => y) (fun (h : Not (Eq.{u1} X (Subtype.val.{u1} X (fun (x' : X) => Not (Eq.{u1} X x' _inst_1)) x') _inst_1)) => f x')) (congrFun.{max 1 u1, u2} (Subtype.{u1} X (fun (x' : X) => Not (Eq.{u1} X x' _inst_1))) (fun ([email protected]._hyg.25 : Subtype.{u1} X (fun (x' : X) => Not (Eq.{u1} X x' _inst_1))) => x) (Function.comp.{max 1 u1, u1, u2} (Subtype.{u1} X (fun (x' : X) => Not (Eq.{u1} X x' _inst_1))) X x (fun (x_1 : X) => dite.{u2} x (Not (Eq.{u1} X x_1 _inst_1)) (instDecidableNot (Eq.{u1} X x_1 _inst_1) (Y x_1 _inst_1)) (fun (h : Not (Eq.{u1} X x_1 _inst_1)) => f (Subtype.mk.{u1} X (fun (x' : X) => Ne.{u1} X x' _inst_1) x_1 h)) (fun (h : Not (Not (Eq.{u1} X x_1 _inst_1))) => y)) (Subtype.val.{u1} X (fun (x' : X) => Not (Eq.{u1} X x' _inst_1)))) (Function.comp.{max 1 u1, u1, u2} (Subtype.{u1} X (fun (x' : X) => Not (Eq.{u1} X x' _inst_1))) X x (fun (x_1 : X) => dite.{u2} x (Eq.{u1} X x_1 _inst_1) (Y x_1 _inst_1) (fun (h : Eq.{u1} X x_1 _inst_1) => y) (fun (h : Not (Eq.{u1} X x_1 _inst_1)) => f (Subtype.mk.{u1} X (fun (x' : X) => Ne.{u1} X x' _inst_1) x_1 h))) (Subtype.val.{u1} X (fun (x' : X) => Not (Eq.{u1} X x' _inst_1)))) (congrFun.{imax (max 1 u1) u1, imax (max 1 u1) u2} ((Subtype.{u1} X (fun (x' : X) => Not (Eq.{u1} X x' _inst_1))) -> X) (fun (g : (Subtype.{u1} X (fun (x' : X) => Not (Eq.{u1} X x' _inst_1))) -> X) => (Subtype.{u1} X (fun (x' : X) => Not (Eq.{u1} X x' _inst_1))) -> x) (Function.comp.{max 1 u1, u1, u2} (Subtype.{u1} X (fun (x' : X) => Not (Eq.{u1} X x' _inst_1))) X x (fun (x_1 : X) => dite.{u2} x (Not (Eq.{u1} X x_1 _inst_1)) (instDecidableNot (Eq.{u1} X x_1 _inst_1) (Y x_1 _inst_1)) (fun (h : Not (Eq.{u1} X x_1 _inst_1)) => f (Subtype.mk.{u1} X (fun (x' : X) => Ne.{u1} X x' _inst_1) x_1 h)) (fun (h : Not (Not (Eq.{u1} X x_1 _inst_1))) => y))) (Function.comp.{max 1 u1, u1, u2} (Subtype.{u1} X (fun (x' : X) => Not (Eq.{u1} X x' _inst_1))) X x (fun (x_1 : X) => dite.{u2} x (Eq.{u1} X x_1 _inst_1) (Y x_1 _inst_1) (fun (h : Eq.{u1} X x_1 _inst_1) => y) (fun (h : Not (Eq.{u1} X x_1 _inst_1)) => f (Subtype.mk.{u1} X (fun (x' : X) => Ne.{u1} X x' _inst_1) x_1 h)))) (congrArg.{imax u1 u2, imax (imax (max 1 u1) u1) (max 1 u1) u2} (X -> x) (((Subtype.{u1} X (fun (x' : X) => Not (Eq.{u1} X x' _inst_1))) -> X) -> (Subtype.{u1} X (fun (x' : X) => Not (Eq.{u1} X x' _inst_1))) -> x) (fun (x_1 : X) => dite.{u2} x (Not (Eq.{u1} X x_1 _inst_1)) (instDecidableNot (Eq.{u1} X x_1 _inst_1) (Y x_1 _inst_1)) (fun (h : Not (Eq.{u1} X x_1 _inst_1)) => f (Subtype.mk.{u1} X (fun (x' : X) => Ne.{u1} X x' _inst_1) x_1 h)) (fun (h : Not (Not (Eq.{u1} X x_1 _inst_1))) => y)) (fun (x_1 : X) => dite.{u2} x (Eq.{u1} X x_1 _inst_1) (Y x_1 _inst_1) (fun (h : Eq.{u1} X x_1 _inst_1) => y) (fun (h : Not (Eq.{u1} X x_1 _inst_1)) => f (Subtype.mk.{u1} X (fun (x' : X) => Ne.{u1} X x' _inst_1) x_1 h))) (Function.comp.{max 1 u1, u1, u2} (Subtype.{u1} X (fun (x' : X) => Not (Eq.{u1} X x' _inst_1))) X x) (funext.{u1, u2} X (fun (x_1 : X) => x) (fun (x_1 : X) => dite.{u2} x (Not (Eq.{u1} X x_1 _inst_1)) (instDecidableNot (Eq.{u1} X x_1 _inst_1) (Y x_1 _inst_1)) (fun (h : Not (Eq.{u1} X x_1 _inst_1)) => f (Subtype.mk.{u1} X (fun (x' : X) => Ne.{u1} X x' _inst_1) x_1 h)) (fun (h : Not (Not (Eq.{u1} X x_1 _inst_1))) => y)) (fun (x_1 : X) => dite.{u2} x (Eq.{u1} X x_1 _inst_1) (Y x_1 _inst_1) (fun (h : Eq.{u1} X x_1 _inst_1) => y) (fun (h : Not (Eq.{u1} X x_1 _inst_1)) => f (Subtype.mk.{u1} X (fun (x' : X) => Ne.{u1} X x' _inst_1) x_1 h))) (fun (x' : X) => dite_not.{u2} x (Eq.{u1} X x' _inst_1) (Y x' _inst_1) (fun (h : Not (Eq.{u1} X x' _inst_1)) => f (Subtype.mk.{u1} X (fun (x' : X) => Ne.{u1} X x' _inst_1) x' h)) (fun (h : Not (Not (Eq.{u1} X x' _inst_1))) => y)))) (Subtype.val.{u1} X (fun (x' : X) => Not (Eq.{u1} X x' _inst_1)))) x') (dite_congr.{u2} (Eq.{u1} X (Subtype.val.{u1} X (fun (x' : X) => Not (Eq.{u1} X x' _inst_1)) x') _inst_1) (Eq.{u1} X (Subtype.val.{u1} X (fun (x' : X) => Not (Eq.{u1} X x' _inst_1)) x') _inst_1) x (Y (Subtype.val.{u1} X (fun (x' : X) => Not (Eq.{u1} X x' _inst_1)) x') _inst_1) (Y (Subtype.val.{u1} X (fun (x' : X) => Not (Eq.{u1} X x' _inst_1)) x') _inst_1) (fun (h : Eq.{u1} X (Subtype.val.{u1} X (fun (x' : X) => Not (Eq.{u1} X x' _inst_1)) x') _inst_1) => y) (fun (h : Eq.{u1} X (Subtype.val.{u1} X (fun (x' : X) => Not (Eq.{u1} X x' _inst_1)) x') _inst_1) => y) (fun (h : Not (Eq.{u1} X (Subtype.val.{u1} X (fun (x' : X) => Not (Eq.{u1} X x' _inst_1)) x') _inst_1)) => f (Subtype.mk.{u1} X (fun (x' : X) => Ne.{u1} X x' _inst_1) (Subtype.val.{u1} X (fun (x' : X) => Not (Eq.{u1} X x' _inst_1)) x') h)) (fun (h : Not (Eq.{u1} X (Subtype.val.{u1} X (fun (x' : X) => Not (Eq.{u1} X x' _inst_1)) x') _inst_1)) => f x') (Eq.refl.{1} Prop (Eq.{u1} X (Subtype.val.{u1} X (fun (x' : X) => Not (Eq.{u1} X x' _inst_1)) x') _inst_1)) (fun (h : Eq.{u1} X (Subtype.val.{u1} X (fun (x' : X) => Not (Eq.{u1} X x' _inst_1)) x') _inst_1) => Eq.refl.{u2} x y) (fun (h : Not (Eq.{u1} X (Subtype.val.{u1} X (fun (x' : X) => Not (Eq.{u1} X x' _inst_1)) x') _inst_1)) => congrArg.{max 1 u1, u2} (Subtype.{u1} X (fun (x' : X) => Ne.{u1} X x' _inst_1)) x (Subtype.mk.{u1} X (fun (x' : X) => Ne.{u1} X x' _inst_1) (Subtype.val.{u1} X (fun (a : X) => Ne.{u1} X a _inst_1) x') (Eq.mpr_not (Eq.{u1} X (Subtype.val.{u1} X (fun (x' : X) => Not (Eq.{u1} X x' _inst_1)) x') _inst_1) (Eq.{u1} X (Subtype.val.{u1} X (fun (x' : X) => Not (Eq.{u1} X x' _inst_1)) x') _inst_1) (Eq.refl.{1} Prop (Eq.{u1} X (Subtype.val.{u1} X (fun (x' : X) => Not (Eq.{u1} X x' _inst_1)) x') _inst_1)) h)) x' f (Subtype.coe_eta.{u1} X (fun (x' : X) => Ne.{u1} X x' _inst_1) x' (Eq.mpr_not (Eq.{u1} X (Subtype.val.{u1} X (fun (x' : X) => Not (Eq.{u1} X x' _inst_1)) x') _inst_1) (Eq.{u1} X (Subtype.val.{u1} X (fun (x' : X) => Not (Eq.{u1} X x' _inst_1)) x') _inst_1) (Eq.refl.{1} Prop (Eq.{u1} X (Subtype.val.{u1} X (fun (x' : X) => Not (Eq.{u1} X x' _inst_1)) x') _inst_1)) h)))))) (f x')) (Mathlib.Logic.Equiv.Basic._auxLemma.3.{u2} x (Eq.{u1} X (Subtype.val.{u1} X (fun (x' : X) => Not (Eq.{u1} X x' _inst_1)) x') _inst_1) (Y (Subtype.val.{u1} X (fun (x' : X) => Not (Eq.{u1} X x' _inst_1)) x') _inst_1) y (f x')))) (fun (w : Eq.{u1} X (Subtype.val.{u1} X (fun (x' : X) => Not (Eq.{u1} X x' _inst_1)) x') _inst_1) => False.elim.{0} (Eq.{u2} x y (f x')) (Subtype.property.{u1} X (fun (x' : X) => Ne.{u1} X x' _inst_1) x' w))))) Case conversion may be inaccurate. Consider using '#align equiv.coe_subtype_equiv_codomain_symm Equiv.coe_subtypeEquivCodomain_symmₓ'. -/ theorem coe_subtypeEquivCodomain_symm (f : { x' // x' ≠ x } → Y) : ((subtypeEquivCodomain f).symm : Y → { g : X → Y // g ∘ coe = f }) = fun y => ⟨fun x' => if h : x' ≠ x then f ⟨x', h⟩ else y, by funext x' dsimp erw [dif_pos x'.2, Subtype.coe_eta]⟩ := rfl #align equiv.coe_subtype_equiv_codomain_symm Equiv.coe_subtypeEquivCodomain_symm /- warning: equiv.subtype_equiv_codomain_symm_apply -> Equiv.subtypeEquivCodomain_symm_apply is a dubious translation: lean 3 declaration is forall {X : Type.{u1}} {Y : Type.{u2}} [_inst_1 : DecidableEq.{succ u1} X] {x : X} (f : (Subtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x)) -> Y) (y : Y) (x' : X), Eq.{succ u2} Y ((fun (a : Sort.{max 1 (succ u1) (succ u2)}) (b : Sort.{max (succ u1) (succ u2)}) [self : HasLiftT.{max 1 (succ u1) (succ u2), max (succ u1) (succ u2)} a b] => self.0) (Subtype.{max (succ u1) (succ u2)} (X -> Y) (fun (g : X -> Y) => Eq.{max (succ u1) (succ u2)} ((Subtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x)) -> Y) (Function.comp.{succ u1, succ u1, succ u2} (Subtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x)) X Y g ((fun (a : Type.{u1}) (b : Type.{u1}) [self : HasLiftT.{succ u1, succ u1} a b] => self.0) (Subtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x)) X (HasLiftT.mk.{succ u1, succ u1} (Subtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x)) X (CoeTCₓ.coe.{succ u1, succ u1} (Subtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x)) X (coeBase.{succ u1, succ u1} (Subtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x)) X (coeSubtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x))))))) f)) (X -> Y) (HasLiftT.mk.{max 1 (succ u1) (succ u2), max (succ u1) (succ u2)} (Subtype.{max (succ u1) (succ u2)} (X -> Y) (fun (g : X -> Y) => Eq.{max (succ u1) (succ u2)} ((Subtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x)) -> Y) (Function.comp.{succ u1, succ u1, succ u2} (Subtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x)) X Y g ((fun (a : Type.{u1}) (b : Type.{u1}) [self : HasLiftT.{succ u1, succ u1} a b] => self.0) (Subtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x)) X (HasLiftT.mk.{succ u1, succ u1} (Subtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x)) X (CoeTCₓ.coe.{succ u1, succ u1} (Subtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x)) X (coeBase.{succ u1, succ u1} (Subtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x)) X (coeSubtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x))))))) f)) (X -> Y) (CoeTCₓ.coe.{max 1 (succ u1) (succ u2), max (succ u1) (succ u2)} (Subtype.{max (succ u1) (succ u2)} (X -> Y) (fun (g : X -> Y) => Eq.{max (succ u1) (succ u2)} ((Subtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x)) -> Y) (Function.comp.{succ u1, succ u1, succ u2} (Subtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x)) X Y g ((fun (a : Type.{u1}) (b : Type.{u1}) [self : HasLiftT.{succ u1, succ u1} a b] => self.0) (Subtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x)) X (HasLiftT.mk.{succ u1, succ u1} (Subtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x)) X (CoeTCₓ.coe.{succ u1, succ u1} (Subtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x)) X (coeBase.{succ u1, succ u1} (Subtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x)) X (coeSubtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x))))))) f)) (X -> Y) (coeBase.{max 1 (succ u1) (succ u2), max (succ u1) (succ u2)} (Subtype.{max (succ u1) (succ u2)} (X -> Y) (fun (g : X -> Y) => Eq.{max (succ u1) (succ u2)} ((Subtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x)) -> Y) (Function.comp.{succ u1, succ u1, succ u2} (Subtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x)) X Y g ((fun (a : Type.{u1}) (b : Type.{u1}) [self : HasLiftT.{succ u1, succ u1} a b] => self.0) (Subtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x)) X (HasLiftT.mk.{succ u1, succ u1} (Subtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x)) X (CoeTCₓ.coe.{succ u1, succ u1} (Subtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x)) X (coeBase.{succ u1, succ u1} (Subtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x)) X (coeSubtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x))))))) f)) (X -> Y) (coeSubtype.{max (succ u1) (succ u2)} (X -> Y) (fun (g : X -> Y) => Eq.{max (succ u1) (succ u2)} ((Subtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x)) -> Y) (Function.comp.{succ u1, succ u1, succ u2} (Subtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x)) X Y g ((fun (a : Type.{u1}) (b : Type.{u1}) [self : HasLiftT.{succ u1, succ u1} a b] => self.0) (Subtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x)) X (HasLiftT.mk.{succ u1, succ u1} (Subtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x)) X (CoeTCₓ.coe.{succ u1, succ u1} (Subtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x)) X (coeBase.{succ u1, succ u1} (Subtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x)) X (coeSubtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x))))))) f))))) (coeFn.{max 1 (max (succ u2) 1 (succ u1) (succ u2)) (max 1 (succ u1) (succ u2)) (succ u2), max (succ u2) 1 (succ u1) (succ u2)} (Equiv.{succ u2, max 1 (succ u1) (succ u2)} Y (Subtype.{max (succ u1) (succ u2)} (X -> Y) (fun (g : X -> Y) => Eq.{max (succ u1) (succ u2)} ((Subtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x)) -> Y) (Function.comp.{succ u1, succ u1, succ u2} (Subtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x)) X Y g ((fun (a : Type.{u1}) (b : Type.{u1}) [self : HasLiftT.{succ u1, succ u1} a b] => self.0) (Subtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x)) X (HasLiftT.mk.{succ u1, succ u1} (Subtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x)) X (CoeTCₓ.coe.{succ u1, succ u1} (Subtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x)) X (coeBase.{succ u1, succ u1} (Subtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x)) X (coeSubtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x))))))) f))) (fun (_x : Equiv.{succ u2, max 1 (succ u1) (succ u2)} Y (Subtype.{max (succ u1) (succ u2)} (X -> Y) (fun (g : X -> Y) => Eq.{max (succ u1) (succ u2)} ((Subtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x)) -> Y) (Function.comp.{succ u1, succ u1, succ u2} (Subtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x)) X Y g ((fun (a : Type.{u1}) (b : Type.{u1}) [self : HasLiftT.{succ u1, succ u1} a b] => self.0) (Subtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x)) X (HasLiftT.mk.{succ u1, succ u1} (Subtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x)) X (CoeTCₓ.coe.{succ u1, succ u1} (Subtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x)) X (coeBase.{succ u1, succ u1} (Subtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x)) X (coeSubtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x))))))) f))) => Y -> (Subtype.{max (succ u1) (succ u2)} (X -> Y) (fun (g : X -> Y) => Eq.{max (succ u1) (succ u2)} ((Subtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x)) -> Y) (Function.comp.{succ u1, succ u1, succ u2} (Subtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x)) X Y g ((fun (a : Type.{u1}) (b : Type.{u1}) [self : HasLiftT.{succ u1, succ u1} a b] => self.0) (Subtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x)) X (HasLiftT.mk.{succ u1, succ u1} (Subtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x)) X (CoeTCₓ.coe.{succ u1, succ u1} (Subtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x)) X (coeBase.{succ u1, succ u1} (Subtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x)) X (coeSubtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x))))))) f))) (Equiv.hasCoeToFun.{succ u2, max 1 (succ u1) (succ u2)} Y (Subtype.{max (succ u1) (succ u2)} (X -> Y) (fun (g : X -> Y) => Eq.{max (succ u1) (succ u2)} ((Subtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x)) -> Y) (Function.comp.{succ u1, succ u1, succ u2} (Subtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x)) X Y g ((fun (a : Type.{u1}) (b : Type.{u1}) [self : HasLiftT.{succ u1, succ u1} a b] => self.0) (Subtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x)) X (HasLiftT.mk.{succ u1, succ u1} (Subtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x)) X (CoeTCₓ.coe.{succ u1, succ u1} (Subtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x)) X (coeBase.{succ u1, succ u1} (Subtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x)) X (coeSubtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x))))))) f))) (Equiv.symm.{max 1 (succ u1) (succ u2), succ u2} (Subtype.{max (succ u1) (succ u2)} (X -> Y) (fun (g : X -> Y) => Eq.{max (succ u1) (succ u2)} ((Subtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x)) -> Y) (Function.comp.{succ u1, succ u1, succ u2} (Subtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x)) X Y g ((fun (a : Type.{u1}) (b : Type.{u1}) [self : HasLiftT.{succ u1, succ u1} a b] => self.0) (Subtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x)) X (HasLiftT.mk.{succ u1, succ u1} (Subtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x)) X (CoeTCₓ.coe.{succ u1, succ u1} (Subtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x)) X (coeBase.{succ u1, succ u1} (Subtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x)) X (coeSubtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x))))))) f)) Y (Equiv.subtypeEquivCodomain.{u1, u2} X Y (fun (a : X) (b : X) => _inst_1 a b) x f)) y) x') (dite.{succ u2} Y (Ne.{succ u1} X x' x) (Ne.decidable.{succ u1} X (fun (a : X) (b : X) => _inst_1 a b) x' x) (fun (h : Ne.{succ u1} X x' x) => f (Subtype.mk.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x) x' h)) (fun (h : Not (Ne.{succ u1} X x' x)) => y)) but is expected to have type forall {X : Sort.{u1}} [Y : DecidableEq.{u1} X] {_inst_1 : X} {x : Sort.{u2}} (f : (Subtype.{u1} X (fun (x' : X) => Ne.{u1} X x' _inst_1)) -> x) (y : x) (x' : X), Eq.{u2} x (Subtype.val.{imax u1 u2} (X -> x) (fun (g : X -> x) => Eq.{imax (max 1 u1) u2} ((Subtype.{u1} X (fun (x' : X) => Ne.{u1} X x' _inst_1)) -> x) (Function.comp.{max 1 u1, u1, u2} (Subtype.{u1} X (fun (x' : X) => Ne.{u1} X x' _inst_1)) X x g (Subtype.val.{u1} X (fun (x' : X) => Ne.{u1} X x' _inst_1))) f) (FunLike.coe.{max (max 1 u2) (imax u1 u2), u2, max 1 (imax u1 u2)} (Equiv.{u2, max 1 (imax u1 u2)} x (Subtype.{imax u1 u2} (X -> x) (fun (g : X -> x) => Eq.{imax (max 1 u1) u2} ((Subtype.{u1} X (fun (x' : X) => Ne.{u1} X x' _inst_1)) -> x) (Function.comp.{max 1 u1, u1, u2} (Subtype.{u1} X (fun (x' : X) => Ne.{u1} X x' _inst_1)) X x g (Subtype.val.{u1} X (fun (x' : X) => Ne.{u1} X x' _inst_1))) f))) x (fun (_x : x) => (fun ([email protected]._hyg.808 : x) => Subtype.{imax u1 u2} (X -> x) (fun (g : X -> x) => Eq.{imax (max 1 u1) u2} ((Subtype.{u1} X (fun (x' : X) => Ne.{u1} X x' _inst_1)) -> x) (Function.comp.{max 1 u1, u1, u2} (Subtype.{u1} X (fun (x' : X) => Ne.{u1} X x' _inst_1)) X x g (Subtype.val.{u1} X (fun (x' : X) => Ne.{u1} X x' _inst_1))) f)) _x) (Equiv.instFunLikeEquiv.{u2, max 1 (imax u1 u2)} x (Subtype.{imax u1 u2} (X -> x) (fun (g : X -> x) => Eq.{imax (max 1 u1) u2} ((Subtype.{u1} X (fun (x' : X) => Ne.{u1} X x' _inst_1)) -> x) (Function.comp.{max 1 u1, u1, u2} (Subtype.{u1} X (fun (x' : X) => Ne.{u1} X x' _inst_1)) X x g (Subtype.val.{u1} X (fun (x' : X) => Ne.{u1} X x' _inst_1))) f))) (Equiv.symm.{max 1 (imax u1 u2), u2} (Subtype.{imax u1 u2} (X -> x) (fun (g : X -> x) => Eq.{imax (max 1 u1) u2} ((Subtype.{u1} X (fun (x' : X) => Ne.{u1} X x' _inst_1)) -> x) (Function.comp.{max 1 u1, u1, u2} (Subtype.{u1} X (fun (x' : X) => Ne.{u1} X x' _inst_1)) X x g (Subtype.val.{u1} X (fun (x' : X) => Ne.{u1} X x' _inst_1))) f)) x (Equiv.subtypeEquivCodomain.{u1, u2} X (fun (a : X) (b : X) => Y a b) _inst_1 x f)) y) x') (dite.{u2} x (Ne.{u1} X x' _inst_1) (instDecidableNot (Eq.{u1} X x' _inst_1) (Y x' _inst_1)) (fun (h : Ne.{u1} X x' _inst_1) => f (Subtype.mk.{u1} X (fun (x' : X) => Ne.{u1} X x' _inst_1) x' h)) (fun (h : Not (Ne.{u1} X x' _inst_1)) => y)) Case conversion may be inaccurate. Consider using '#align equiv.subtype_equiv_codomain_symm_apply Equiv.subtypeEquivCodomain_symm_applyₓ'. -/ @[simp] theorem subtypeEquivCodomain_symm_apply (f : { x' // x' ≠ x } → Y) (y : Y) (x' : X) : ((subtypeEquivCodomain f).symm y : X → Y) x' = if h : x' ≠ x then f ⟨x', h⟩ else y := rfl #align equiv.subtype_equiv_codomain_symm_apply Equiv.subtypeEquivCodomain_symm_apply /- warning: equiv.subtype_equiv_codomain_symm_apply_eq -> Equiv.subtypeEquivCodomain_symm_apply_eq is a dubious translation: lean 3 declaration is forall {X : Type.{u1}} {Y : Type.{u2}} [_inst_1 : DecidableEq.{succ u1} X] {x : X} (f : (Subtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x)) -> Y) (y : Y), Eq.{succ u2} Y ((fun (a : Sort.{max 1 (succ u1) (succ u2)}) (b : Sort.{max (succ u1) (succ u2)}) [self : HasLiftT.{max 1 (succ u1) (succ u2), max (succ u1) (succ u2)} a b] => self.0) (Subtype.{max (succ u1) (succ u2)} (X -> Y) (fun (g : X -> Y) => Eq.{max (succ u1) (succ u2)} ((Subtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x)) -> Y) (Function.comp.{succ u1, succ u1, succ u2} (Subtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x)) X Y g ((fun (a : Type.{u1}) (b : Type.{u1}) [self : HasLiftT.{succ u1, succ u1} a b] => self.0) (Subtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x)) X (HasLiftT.mk.{succ u1, succ u1} (Subtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x)) X (CoeTCₓ.coe.{succ u1, succ u1} (Subtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x)) X (coeBase.{succ u1, succ u1} (Subtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x)) X (coeSubtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x))))))) f)) (X -> Y) (HasLiftT.mk.{max 1 (succ u1) (succ u2), max (succ u1) (succ u2)} (Subtype.{max (succ u1) (succ u2)} (X -> Y) (fun (g : X -> Y) => Eq.{max (succ u1) (succ u2)} ((Subtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x)) -> Y) (Function.comp.{succ u1, succ u1, succ u2} (Subtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x)) X Y g ((fun (a : Type.{u1}) (b : Type.{u1}) [self : HasLiftT.{succ u1, succ u1} a b] => self.0) (Subtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x)) X (HasLiftT.mk.{succ u1, succ u1} (Subtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x)) X (CoeTCₓ.coe.{succ u1, succ u1} (Subtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x)) X (coeBase.{succ u1, succ u1} (Subtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x)) X (coeSubtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x))))))) f)) (X -> Y) (CoeTCₓ.coe.{max 1 (succ u1) (succ u2), max (succ u1) (succ u2)} (Subtype.{max (succ u1) (succ u2)} (X -> Y) (fun (g : X -> Y) => Eq.{max (succ u1) (succ u2)} ((Subtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x)) -> Y) (Function.comp.{succ u1, succ u1, succ u2} (Subtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x)) X Y g ((fun (a : Type.{u1}) (b : Type.{u1}) [self : HasLiftT.{succ u1, succ u1} a b] => self.0) (Subtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x)) X (HasLiftT.mk.{succ u1, succ u1} (Subtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x)) X (CoeTCₓ.coe.{succ u1, succ u1} (Subtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x)) X (coeBase.{succ u1, succ u1} (Subtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x)) X (coeSubtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x))))))) f)) (X -> Y) (coeBase.{max 1 (succ u1) (succ u2), max (succ u1) (succ u2)} (Subtype.{max (succ u1) (succ u2)} (X -> Y) (fun (g : X -> Y) => Eq.{max (succ u1) (succ u2)} ((Subtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x)) -> Y) (Function.comp.{succ u1, succ u1, succ u2} (Subtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x)) X Y g ((fun (a : Type.{u1}) (b : Type.{u1}) [self : HasLiftT.{succ u1, succ u1} a b] => self.0) (Subtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x)) X (HasLiftT.mk.{succ u1, succ u1} (Subtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x)) X (CoeTCₓ.coe.{succ u1, succ u1} (Subtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x)) X (coeBase.{succ u1, succ u1} (Subtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x)) X (coeSubtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x))))))) f)) (X -> Y) (coeSubtype.{max (succ u1) (succ u2)} (X -> Y) (fun (g : X -> Y) => Eq.{max (succ u1) (succ u2)} ((Subtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x)) -> Y) (Function.comp.{succ u1, succ u1, succ u2} (Subtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x)) X Y g ((fun (a : Type.{u1}) (b : Type.{u1}) [self : HasLiftT.{succ u1, succ u1} a b] => self.0) (Subtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x)) X (HasLiftT.mk.{succ u1, succ u1} (Subtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x)) X (CoeTCₓ.coe.{succ u1, succ u1} (Subtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x)) X (coeBase.{succ u1, succ u1} (Subtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x)) X (coeSubtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x))))))) f))))) (coeFn.{max 1 (max (succ u2) 1 (succ u1) (succ u2)) (max 1 (succ u1) (succ u2)) (succ u2), max (succ u2) 1 (succ u1) (succ u2)} (Equiv.{succ u2, max 1 (succ u1) (succ u2)} Y (Subtype.{max (succ u1) (succ u2)} (X -> Y) (fun (g : X -> Y) => Eq.{max (succ u1) (succ u2)} ((Subtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x)) -> Y) (Function.comp.{succ u1, succ u1, succ u2} (Subtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x)) X Y g ((fun (a : Type.{u1}) (b : Type.{u1}) [self : HasLiftT.{succ u1, succ u1} a b] => self.0) (Subtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x)) X (HasLiftT.mk.{succ u1, succ u1} (Subtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x)) X (CoeTCₓ.coe.{succ u1, succ u1} (Subtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x)) X (coeBase.{succ u1, succ u1} (Subtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x)) X (coeSubtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x))))))) f))) (fun (_x : Equiv.{succ u2, max 1 (succ u1) (succ u2)} Y (Subtype.{max (succ u1) (succ u2)} (X -> Y) (fun (g : X -> Y) => Eq.{max (succ u1) (succ u2)} ((Subtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x)) -> Y) (Function.comp.{succ u1, succ u1, succ u2} (Subtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x)) X Y g ((fun (a : Type.{u1}) (b : Type.{u1}) [self : HasLiftT.{succ u1, succ u1} a b] => self.0) (Subtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x)) X (HasLiftT.mk.{succ u1, succ u1} (Subtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x)) X (CoeTCₓ.coe.{succ u1, succ u1} (Subtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x)) X (coeBase.{succ u1, succ u1} (Subtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x)) X (coeSubtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x))))))) f))) => Y -> (Subtype.{max (succ u1) (succ u2)} (X -> Y) (fun (g : X -> Y) => Eq.{max (succ u1) (succ u2)} ((Subtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x)) -> Y) (Function.comp.{succ u1, succ u1, succ u2} (Subtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x)) X Y g ((fun (a : Type.{u1}) (b : Type.{u1}) [self : HasLiftT.{succ u1, succ u1} a b] => self.0) (Subtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x)) X (HasLiftT.mk.{succ u1, succ u1} (Subtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x)) X (CoeTCₓ.coe.{succ u1, succ u1} (Subtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x)) X (coeBase.{succ u1, succ u1} (Subtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x)) X (coeSubtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x))))))) f))) (Equiv.hasCoeToFun.{succ u2, max 1 (succ u1) (succ u2)} Y (Subtype.{max (succ u1) (succ u2)} (X -> Y) (fun (g : X -> Y) => Eq.{max (succ u1) (succ u2)} ((Subtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x)) -> Y) (Function.comp.{succ u1, succ u1, succ u2} (Subtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x)) X Y g ((fun (a : Type.{u1}) (b : Type.{u1}) [self : HasLiftT.{succ u1, succ u1} a b] => self.0) (Subtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x)) X (HasLiftT.mk.{succ u1, succ u1} (Subtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x)) X (CoeTCₓ.coe.{succ u1, succ u1} (Subtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x)) X (coeBase.{succ u1, succ u1} (Subtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x)) X (coeSubtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x))))))) f))) (Equiv.symm.{max 1 (succ u1) (succ u2), succ u2} (Subtype.{max (succ u1) (succ u2)} (X -> Y) (fun (g : X -> Y) => Eq.{max (succ u1) (succ u2)} ((Subtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x)) -> Y) (Function.comp.{succ u1, succ u1, succ u2} (Subtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x)) X Y g ((fun (a : Type.{u1}) (b : Type.{u1}) [self : HasLiftT.{succ u1, succ u1} a b] => self.0) (Subtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x)) X (HasLiftT.mk.{succ u1, succ u1} (Subtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x)) X (CoeTCₓ.coe.{succ u1, succ u1} (Subtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x)) X (coeBase.{succ u1, succ u1} (Subtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x)) X (coeSubtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x))))))) f)) Y (Equiv.subtypeEquivCodomain.{u1, u2} X Y (fun (a : X) (b : X) => _inst_1 a b) x f)) y) x) y but is expected to have type forall {X : Sort.{u1}} [Y : DecidableEq.{u1} X] {_inst_1 : X} {x : Sort.{u2}} (f : (Subtype.{u1} X (fun (x' : X) => Ne.{u1} X x' _inst_1)) -> x) (y : x), Eq.{u2} x (Subtype.val.{imax u1 u2} (X -> x) (fun (g : X -> x) => Eq.{imax (max 1 u1) u2} ((Subtype.{u1} X (fun (x' : X) => Ne.{u1} X x' _inst_1)) -> x) (Function.comp.{max 1 u1, u1, u2} (Subtype.{u1} X (fun (x' : X) => Ne.{u1} X x' _inst_1)) X x g (Subtype.val.{u1} X (fun (x' : X) => Ne.{u1} X x' _inst_1))) f) (FunLike.coe.{max (max 1 u2) (imax u1 u2), u2, max 1 (imax u1 u2)} (Equiv.{u2, max 1 (imax u1 u2)} x (Subtype.{imax u1 u2} (X -> x) (fun (g : X -> x) => Eq.{imax (max 1 u1) u2} ((Subtype.{u1} X (fun (x' : X) => Ne.{u1} X x' _inst_1)) -> x) (Function.comp.{max 1 u1, u1, u2} (Subtype.{u1} X (fun (x' : X) => Ne.{u1} X x' _inst_1)) X x g (Subtype.val.{u1} X (fun (x' : X) => Ne.{u1} X x' _inst_1))) f))) x (fun (_x : x) => (fun ([email protected]._hyg.808 : x) => Subtype.{imax u1 u2} (X -> x) (fun (g : X -> x) => Eq.{imax (max 1 u1) u2} ((Subtype.{u1} X (fun (x' : X) => Ne.{u1} X x' _inst_1)) -> x) (Function.comp.{max 1 u1, u1, u2} (Subtype.{u1} X (fun (x' : X) => Ne.{u1} X x' _inst_1)) X x g (Subtype.val.{u1} X (fun (x' : X) => Ne.{u1} X x' _inst_1))) f)) _x) (Equiv.instFunLikeEquiv.{u2, max 1 (imax u1 u2)} x (Subtype.{imax u1 u2} (X -> x) (fun (g : X -> x) => Eq.{imax (max 1 u1) u2} ((Subtype.{u1} X (fun (x' : X) => Ne.{u1} X x' _inst_1)) -> x) (Function.comp.{max 1 u1, u1, u2} (Subtype.{u1} X (fun (x' : X) => Ne.{u1} X x' _inst_1)) X x g (Subtype.val.{u1} X (fun (x' : X) => Ne.{u1} X x' _inst_1))) f))) (Equiv.symm.{max 1 (imax u1 u2), u2} (Subtype.{imax u1 u2} (X -> x) (fun (g : X -> x) => Eq.{imax (max 1 u1) u2} ((Subtype.{u1} X (fun (x' : X) => Ne.{u1} X x' _inst_1)) -> x) (Function.comp.{max 1 u1, u1, u2} (Subtype.{u1} X (fun (x' : X) => Ne.{u1} X x' _inst_1)) X x g (Subtype.val.{u1} X (fun (x' : X) => Ne.{u1} X x' _inst_1))) f)) x (Equiv.subtypeEquivCodomain.{u1, u2} X (fun (a : X) (b : X) => Y a b) _inst_1 x f)) y) _inst_1) y Case conversion may be inaccurate. Consider using '#align equiv.subtype_equiv_codomain_symm_apply_eq Equiv.subtypeEquivCodomain_symm_apply_eqₓ'. -/ @[simp] theorem subtypeEquivCodomain_symm_apply_eq (f : { x' // x' ≠ x } → Y) (y : Y) : ((subtypeEquivCodomain f).symm y : X → Y) x = y := dif_neg (Classical.not_not.mpr rfl) #align equiv.subtype_equiv_codomain_symm_apply_eq Equiv.subtypeEquivCodomain_symm_apply_eq /- warning: equiv.subtype_equiv_codomain_symm_apply_ne -> Equiv.subtypeEquivCodomain_symm_apply_ne is a dubious translation: lean 3 declaration is forall {X : Type.{u1}} {Y : Type.{u2}} [_inst_1 : DecidableEq.{succ u1} X] {x : X} (f : (Subtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x)) -> Y) (y : Y) (x' : X) (h : Ne.{succ u1} X x' x), Eq.{succ u2} Y ((fun (a : Sort.{max 1 (succ u1) (succ u2)}) (b : Sort.{max (succ u1) (succ u2)}) [self : HasLiftT.{max 1 (succ u1) (succ u2), max (succ u1) (succ u2)} a b] => self.0) (Subtype.{max (succ u1) (succ u2)} (X -> Y) (fun (g : X -> Y) => Eq.{max (succ u1) (succ u2)} ((Subtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x)) -> Y) (Function.comp.{succ u1, succ u1, succ u2} (Subtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x)) X Y g ((fun (a : Type.{u1}) (b : Type.{u1}) [self : HasLiftT.{succ u1, succ u1} a b] => self.0) (Subtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x)) X (HasLiftT.mk.{succ u1, succ u1} (Subtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x)) X (CoeTCₓ.coe.{succ u1, succ u1} (Subtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x)) X (coeBase.{succ u1, succ u1} (Subtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x)) X (coeSubtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x))))))) f)) (X -> Y) (HasLiftT.mk.{max 1 (succ u1) (succ u2), max (succ u1) (succ u2)} (Subtype.{max (succ u1) (succ u2)} (X -> Y) (fun (g : X -> Y) => Eq.{max (succ u1) (succ u2)} ((Subtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x)) -> Y) (Function.comp.{succ u1, succ u1, succ u2} (Subtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x)) X Y g ((fun (a : Type.{u1}) (b : Type.{u1}) [self : HasLiftT.{succ u1, succ u1} a b] => self.0) (Subtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x)) X (HasLiftT.mk.{succ u1, succ u1} (Subtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x)) X (CoeTCₓ.coe.{succ u1, succ u1} (Subtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x)) X (coeBase.{succ u1, succ u1} (Subtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x)) X (coeSubtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x))))))) f)) (X -> Y) (CoeTCₓ.coe.{max 1 (succ u1) (succ u2), max (succ u1) (succ u2)} (Subtype.{max (succ u1) (succ u2)} (X -> Y) (fun (g : X -> Y) => Eq.{max (succ u1) (succ u2)} ((Subtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x)) -> Y) (Function.comp.{succ u1, succ u1, succ u2} (Subtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x)) X Y g ((fun (a : Type.{u1}) (b : Type.{u1}) [self : HasLiftT.{succ u1, succ u1} a b] => self.0) (Subtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x)) X (HasLiftT.mk.{succ u1, succ u1} (Subtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x)) X (CoeTCₓ.coe.{succ u1, succ u1} (Subtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x)) X (coeBase.{succ u1, succ u1} (Subtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x)) X (coeSubtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x))))))) f)) (X -> Y) (coeBase.{max 1 (succ u1) (succ u2), max (succ u1) (succ u2)} (Subtype.{max (succ u1) (succ u2)} (X -> Y) (fun (g : X -> Y) => Eq.{max (succ u1) (succ u2)} ((Subtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x)) -> Y) (Function.comp.{succ u1, succ u1, succ u2} (Subtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x)) X Y g ((fun (a : Type.{u1}) (b : Type.{u1}) [self : HasLiftT.{succ u1, succ u1} a b] => self.0) (Subtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x)) X (HasLiftT.mk.{succ u1, succ u1} (Subtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x)) X (CoeTCₓ.coe.{succ u1, succ u1} (Subtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x)) X (coeBase.{succ u1, succ u1} (Subtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x)) X (coeSubtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x))))))) f)) (X -> Y) (coeSubtype.{max (succ u1) (succ u2)} (X -> Y) (fun (g : X -> Y) => Eq.{max (succ u1) (succ u2)} ((Subtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x)) -> Y) (Function.comp.{succ u1, succ u1, succ u2} (Subtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x)) X Y g ((fun (a : Type.{u1}) (b : Type.{u1}) [self : HasLiftT.{succ u1, succ u1} a b] => self.0) (Subtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x)) X (HasLiftT.mk.{succ u1, succ u1} (Subtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x)) X (CoeTCₓ.coe.{succ u1, succ u1} (Subtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x)) X (coeBase.{succ u1, succ u1} (Subtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x)) X (coeSubtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x))))))) f))))) (coeFn.{max 1 (max (succ u2) 1 (succ u1) (succ u2)) (max 1 (succ u1) (succ u2)) (succ u2), max (succ u2) 1 (succ u1) (succ u2)} (Equiv.{succ u2, max 1 (succ u1) (succ u2)} Y (Subtype.{max (succ u1) (succ u2)} (X -> Y) (fun (g : X -> Y) => Eq.{max (succ u1) (succ u2)} ((Subtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x)) -> Y) (Function.comp.{succ u1, succ u1, succ u2} (Subtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x)) X Y g ((fun (a : Type.{u1}) (b : Type.{u1}) [self : HasLiftT.{succ u1, succ u1} a b] => self.0) (Subtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x)) X (HasLiftT.mk.{succ u1, succ u1} (Subtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x)) X (CoeTCₓ.coe.{succ u1, succ u1} (Subtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x)) X (coeBase.{succ u1, succ u1} (Subtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x)) X (coeSubtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x))))))) f))) (fun (_x : Equiv.{succ u2, max 1 (succ u1) (succ u2)} Y (Subtype.{max (succ u1) (succ u2)} (X -> Y) (fun (g : X -> Y) => Eq.{max (succ u1) (succ u2)} ((Subtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x)) -> Y) (Function.comp.{succ u1, succ u1, succ u2} (Subtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x)) X Y g ((fun (a : Type.{u1}) (b : Type.{u1}) [self : HasLiftT.{succ u1, succ u1} a b] => self.0) (Subtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x)) X (HasLiftT.mk.{succ u1, succ u1} (Subtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x)) X (CoeTCₓ.coe.{succ u1, succ u1} (Subtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x)) X (coeBase.{succ u1, succ u1} (Subtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x)) X (coeSubtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x))))))) f))) => Y -> (Subtype.{max (succ u1) (succ u2)} (X -> Y) (fun (g : X -> Y) => Eq.{max (succ u1) (succ u2)} ((Subtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x)) -> Y) (Function.comp.{succ u1, succ u1, succ u2} (Subtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x)) X Y g ((fun (a : Type.{u1}) (b : Type.{u1}) [self : HasLiftT.{succ u1, succ u1} a b] => self.0) (Subtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x)) X (HasLiftT.mk.{succ u1, succ u1} (Subtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x)) X (CoeTCₓ.coe.{succ u1, succ u1} (Subtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x)) X (coeBase.{succ u1, succ u1} (Subtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x)) X (coeSubtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x))))))) f))) (Equiv.hasCoeToFun.{succ u2, max 1 (succ u1) (succ u2)} Y (Subtype.{max (succ u1) (succ u2)} (X -> Y) (fun (g : X -> Y) => Eq.{max (succ u1) (succ u2)} ((Subtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x)) -> Y) (Function.comp.{succ u1, succ u1, succ u2} (Subtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x)) X Y g ((fun (a : Type.{u1}) (b : Type.{u1}) [self : HasLiftT.{succ u1, succ u1} a b] => self.0) (Subtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x)) X (HasLiftT.mk.{succ u1, succ u1} (Subtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x)) X (CoeTCₓ.coe.{succ u1, succ u1} (Subtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x)) X (coeBase.{succ u1, succ u1} (Subtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x)) X (coeSubtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x))))))) f))) (Equiv.symm.{max 1 (succ u1) (succ u2), succ u2} (Subtype.{max (succ u1) (succ u2)} (X -> Y) (fun (g : X -> Y) => Eq.{max (succ u1) (succ u2)} ((Subtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x)) -> Y) (Function.comp.{succ u1, succ u1, succ u2} (Subtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x)) X Y g ((fun (a : Type.{u1}) (b : Type.{u1}) [self : HasLiftT.{succ u1, succ u1} a b] => self.0) (Subtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x)) X (HasLiftT.mk.{succ u1, succ u1} (Subtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x)) X (CoeTCₓ.coe.{succ u1, succ u1} (Subtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x)) X (coeBase.{succ u1, succ u1} (Subtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x)) X (coeSubtype.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x))))))) f)) Y (Equiv.subtypeEquivCodomain.{u1, u2} X Y (fun (a : X) (b : X) => _inst_1 a b) x f)) y) x') (f (Subtype.mk.{succ u1} X (fun (x' : X) => Ne.{succ u1} X x' x) x' h)) but is expected to have type forall {X : Sort.{u1}} [Y : DecidableEq.{u1} X] {_inst_1 : X} {x : Sort.{u2}} (f : (Subtype.{u1} X (fun (x' : X) => Ne.{u1} X x' _inst_1)) -> x) (y : x) (x' : X) (h : Ne.{u1} X x' _inst_1), Eq.{u2} x (Subtype.val.{imax u1 u2} (X -> x) (fun (g : X -> x) => Eq.{imax (max 1 u1) u2} ((Subtype.{u1} X (fun (x' : X) => Ne.{u1} X x' _inst_1)) -> x) (Function.comp.{max 1 u1, u1, u2} (Subtype.{u1} X (fun (x' : X) => Ne.{u1} X x' _inst_1)) X x g (Subtype.val.{u1} X (fun (x' : X) => Ne.{u1} X x' _inst_1))) f) (FunLike.coe.{max (max 1 u2) (imax u1 u2), u2, max 1 (imax u1 u2)} (Equiv.{u2, max 1 (imax u1 u2)} x (Subtype.{imax u1 u2} (X -> x) (fun (g : X -> x) => Eq.{imax (max 1 u1) u2} ((Subtype.{u1} X (fun (x' : X) => Ne.{u1} X x' _inst_1)) -> x) (Function.comp.{max 1 u1, u1, u2} (Subtype.{u1} X (fun (x' : X) => Ne.{u1} X x' _inst_1)) X x g (Subtype.val.{u1} X (fun (x' : X) => Ne.{u1} X x' _inst_1))) f))) x (fun (_x : x) => (fun ([email protected]._hyg.808 : x) => Subtype.{imax u1 u2} (X -> x) (fun (g : X -> x) => Eq.{imax (max 1 u1) u2} ((Subtype.{u1} X (fun (x' : X) => Ne.{u1} X x' _inst_1)) -> x) (Function.comp.{max 1 u1, u1, u2} (Subtype.{u1} X (fun (x' : X) => Ne.{u1} X x' _inst_1)) X x g (Subtype.val.{u1} X (fun (x' : X) => Ne.{u1} X x' _inst_1))) f)) _x) (Equiv.instFunLikeEquiv.{u2, max 1 (imax u1 u2)} x (Subtype.{imax u1 u2} (X -> x) (fun (g : X -> x) => Eq.{imax (max 1 u1) u2} ((Subtype.{u1} X (fun (x' : X) => Ne.{u1} X x' _inst_1)) -> x) (Function.comp.{max 1 u1, u1, u2} (Subtype.{u1} X (fun (x' : X) => Ne.{u1} X x' _inst_1)) X x g (Subtype.val.{u1} X (fun (x' : X) => Ne.{u1} X x' _inst_1))) f))) (Equiv.symm.{max 1 (imax u1 u2), u2} (Subtype.{imax u1 u2} (X -> x) (fun (g : X -> x) => Eq.{imax (max 1 u1) u2} ((Subtype.{u1} X (fun (x' : X) => Ne.{u1} X x' _inst_1)) -> x) (Function.comp.{max 1 u1, u1, u2} (Subtype.{u1} X (fun (x' : X) => Ne.{u1} X x' _inst_1)) X x g (Subtype.val.{u1} X (fun (x' : X) => Ne.{u1} X x' _inst_1))) f)) x (Equiv.subtypeEquivCodomain.{u1, u2} X (fun (a : X) (b : X) => Y a b) _inst_1 x f)) y) x') (f (Subtype.mk.{u1} X (fun (x' : X) => Ne.{u1} X x' _inst_1) x' h)) Case conversion may be inaccurate. Consider using '#align equiv.subtype_equiv_codomain_symm_apply_ne Equiv.subtypeEquivCodomain_symm_apply_neₓ'. -/ theorem subtypeEquivCodomain_symm_apply_ne (f : { x' // x' ≠ x } → Y) (y : Y) (x' : X) (h : x' ≠ x) : ((subtypeEquivCodomain f).symm y : X → Y) x' = f ⟨x', h⟩ := dif_pos h #align equiv.subtype_equiv_codomain_symm_apply_ne Equiv.subtypeEquivCodomain_symm_apply_ne end SubtypeEquivCodomain #print Equiv.ofBijective /- /-- If `f` is a bijective function, then its domain is equivalent to its codomain. -/ @[simps apply] noncomputable def ofBijective (f : α → β) (hf : Bijective f) : α ≃ β where toFun := f invFun := Function.surjInv hf.Surjective left_inv := Function.leftInverse_surjInv hf right_inv := Function.rightInverse_surjInv _ #align equiv.of_bijective Equiv.ofBijective -/ /- warning: equiv.of_bijective_apply_symm_apply -> Equiv.ofBijective_apply_symm_apply is a dubious translation: lean 3 declaration is forall {α : Sort.{u1}} {β : Sort.{u2}} (f : α -> β) (hf : Function.Bijective.{u1, u2} α β f) (x : β), Eq.{u2} β (f (coeFn.{max 1 (imax u2 u1) (imax u1 u2), imax u2 u1} (Equiv.{u2, u1} β α) (fun (_x : Equiv.{u2, u1} β α) => β -> α) (Equiv.hasCoeToFun.{u2, u1} β α) (Equiv.symm.{u1, u2} α β (Equiv.ofBijective.{u1, u2} α β f hf)) x)) x but is expected to have type forall {α : Sort.{u2}} {β : Sort.{u1}} (f : α -> β) (hf : Function.Bijective.{u2, u1} α β f) (x : β), Eq.{u1} β (f (FunLike.coe.{max (max 1 u2) u1, u1, u2} (Equiv.{u1, u2} β α) β (fun (_x : β) => (fun ([email protected]._hyg.808 : β) => α) _x) (Equiv.instFunLikeEquiv.{u1, u2} β α) (Equiv.symm.{u2, u1} α β (Equiv.ofBijective.{u2, u1} α β f hf)) x)) x Case conversion may be inaccurate. Consider using '#align equiv.of_bijective_apply_symm_apply Equiv.ofBijective_apply_symm_applyₓ'. -/ theorem ofBijective_apply_symm_apply (f : α → β) (hf : Bijective f) (x : β) : f ((ofBijective f hf).symm x) = x := (ofBijective f hf).apply_symm_apply x #align equiv.of_bijective_apply_symm_apply Equiv.ofBijective_apply_symm_apply /- warning: equiv.of_bijective_symm_apply_apply -> Equiv.ofBijective_symm_apply_apply is a dubious translation: lean 3 declaration is forall {α : Sort.{u1}} {β : Sort.{u2}} (f : α -> β) (hf : Function.Bijective.{u1, u2} α β f) (x : α), Eq.{u1} α (coeFn.{max 1 (imax u2 u1) (imax u1 u2), imax u2 u1} (Equiv.{u2, u1} β α) (fun (_x : Equiv.{u2, u1} β α) => β -> α) (Equiv.hasCoeToFun.{u2, u1} β α) (Equiv.symm.{u1, u2} α β (Equiv.ofBijective.{u1, u2} α β f hf)) (f x)) x but is expected to have type forall {α : Sort.{u2}} {β : Sort.{u1}} (f : α -> β) (hf : Function.Bijective.{u2, u1} α β f) (x : α), Eq.{u2} ((fun ([email protected]._hyg.808 : β) => α) (f x)) (FunLike.coe.{max (max 1 u2) u1, u1, u2} (Equiv.{u1, u2} β α) β (fun (_x : β) => (fun ([email protected]._hyg.808 : β) => α) _x) (Equiv.instFunLikeEquiv.{u1, u2} β α) (Equiv.symm.{u2, u1} α β (Equiv.ofBijective.{u2, u1} α β f hf)) (f x)) x Case conversion may be inaccurate. Consider using '#align equiv.of_bijective_symm_apply_apply Equiv.ofBijective_symm_apply_applyₓ'. -/ @[simp] theorem ofBijective_symm_apply_apply (f : α → β) (hf : Bijective f) (x : α) : (ofBijective f hf).symm (f x) = x := (ofBijective f hf).symm_apply_apply x #align equiv.of_bijective_symm_apply_apply Equiv.ofBijective_symm_apply_apply instance : CanLift (α → β) (α ≃ β) coeFn Bijective where prf f hf := ⟨ofBijective f hf, rfl⟩ section variable {α' β' : Type _} (e : Perm α') {p : β' → Prop} [DecidablePred p] (f : α' ≃ Subtype p) #print Equiv.Perm.extendDomain /- /-- Extend the domain of `e : equiv.perm α` to one that is over `β` via `f : α → subtype p`, where `p : β → Prop`, permuting only the `b : β` that satisfy `p b`. This can be used to extend the domain across a function `f : α → β`, keeping everything outside of `set.range f` fixed. For this use-case `equiv` given by `f` can be constructed by `equiv.of_left_inverse'` or `equiv.of_left_inverse` when there is a known inverse, or `equiv.of_injective` in the general case.`. -/ def Perm.extendDomain : Perm β' := (permCongr f e).subtypeCongr (Equiv.refl _) #align equiv.perm.extend_domain Equiv.Perm.extendDomain -/ #print Equiv.Perm.extendDomain_apply_image /- @[simp] theorem Perm.extendDomain_apply_image (a : α') : e.extendDomain f (f a) = f (e a) := by simp [perm.extend_domain] #align equiv.perm.extend_domain_apply_image Equiv.Perm.extendDomain_apply_image -/ #print Equiv.Perm.extendDomain_apply_subtype /- theorem Perm.extendDomain_apply_subtype {b : β'} (h : p b) : e.extendDomain f b = f (e (f.symm ⟨b, h⟩)) := by simp [perm.extend_domain, h] #align equiv.perm.extend_domain_apply_subtype Equiv.Perm.extendDomain_apply_subtype -/ #print Equiv.Perm.extendDomain_apply_not_subtype /- theorem Perm.extendDomain_apply_not_subtype {b : β'} (h : ¬p b) : e.extendDomain f b = b := by simp [perm.extend_domain, h] #align equiv.perm.extend_domain_apply_not_subtype Equiv.Perm.extendDomain_apply_not_subtype -/ #print Equiv.Perm.extendDomain_refl /- @[simp] theorem Perm.extendDomain_refl : Perm.extendDomain (Equiv.refl _) f = Equiv.refl _ := by simp [perm.extend_domain] #align equiv.perm.extend_domain_refl Equiv.Perm.extendDomain_refl -/ #print Equiv.Perm.extendDomain_symm /- @[simp] theorem Perm.extendDomain_symm : (e.extendDomain f).symm = Perm.extendDomain e.symm f := rfl #align equiv.perm.extend_domain_symm Equiv.Perm.extendDomain_symm -/ /- warning: equiv.perm.extend_domain_trans -> Equiv.Perm.extendDomain_trans is a dubious translation: lean 3 declaration is forall {α' : Type.{u1}} {β' : Type.{u2}} {p : β' -> Prop} [_inst_1 : DecidablePred.{succ u2} β' p] (f : Equiv.{succ u1, succ u2} α' (Subtype.{succ u2} β' p)) (e : Equiv.Perm.{succ u1} α') (e' : Equiv.Perm.{succ u1} α'), Eq.{succ u2} (Equiv.{succ u2, succ u2} β' β') (Equiv.trans.{succ u2, succ u2, succ u2} β' β' β' (Equiv.Perm.extendDomain.{u1, u2} α' β' e p (fun (a : β') => _inst_1 a) f) (Equiv.Perm.extendDomain.{u1, u2} α' β' e' p (fun (a : β') => _inst_1 a) f)) (Equiv.Perm.extendDomain.{u1, u2} α' β' (Equiv.trans.{succ u1, succ u1, succ u1} α' α' α' e e') p (fun (a : β') => _inst_1 a) f) but is expected to have type forall {α' : Type.{u2}} {β' : Type.{u1}} {p : β' -> Prop} [_inst_1 : DecidablePred.{succ u1} β' p] (f : Equiv.{succ u2, succ u1} α' (Subtype.{succ u1} β' p)) (e : Equiv.Perm.{succ u2} α') (e' : Equiv.Perm.{succ u2} α'), Eq.{succ u1} (Equiv.{succ u1, succ u1} β' β') (Equiv.trans.{succ u1, succ u1, succ u1} β' β' β' (Equiv.Perm.extendDomain.{u2, u1} α' β' e p (fun (a : β') => _inst_1 a) f) (Equiv.Perm.extendDomain.{u2, u1} α' β' e' p (fun (a : β') => _inst_1 a) f)) (Equiv.Perm.extendDomain.{u2, u1} α' β' (Equiv.trans.{succ u2, succ u2, succ u2} α' α' α' e e') p (fun (a : β') => _inst_1 a) f) Case conversion may be inaccurate. Consider using '#align equiv.perm.extend_domain_trans Equiv.Perm.extendDomain_transₓ'. -/ theorem Perm.extendDomain_trans (e e' : Perm α') : (e.extendDomain f).trans (e'.extendDomain f) = Perm.extendDomain (e.trans e') f := by simp [perm.extend_domain, perm_congr_trans] #align equiv.perm.extend_domain_trans Equiv.Perm.extendDomain_trans end #print Equiv.subtypeQuotientEquivQuotientSubtype /- /-- Subtype of the quotient is equivalent to the quotient of the subtype. Let `α` be a setoid with equivalence relation `~`. Let `p₂` be a predicate on the quotient type `α/~`, and `p₁` be the lift of this predicate to `α`: `p₁ a ↔ p₂ ⟦a⟧`. Let `~₂` be the restriction of `~` to `{x // p₁ x}`. Then `{x // p₂ x}` is equivalent to the quotient of `{x // p₁ x}` by `~₂`. -/ def subtypeQuotientEquivQuotientSubtype (p₁ : α → Prop) [s₁ : Setoid α] [s₂ : Setoid (Subtype p₁)] (p₂ : Quotient s₁ → Prop) (hp₂ : ∀ a, p₁ a ↔ p₂ ⟦a⟧) (h : ∀ x y : Subtype p₁, @Setoid.r _ s₂ x y ↔ (x : α) ≈ y) : { x // p₂ x } ≃ Quotient s₂ where toFun a := Quotient.hrecOn a.1 (fun a h => ⟦⟨a, (hp₂ _).2 h⟩⟧) (fun a b hab => hfunext (by rw [Quotient.sound hab]) fun h₁ h₂ _ => hEq_of_eq (Quotient.sound ((h _ _).2 hab))) a.2 invFun a := Quotient.liftOn a (fun a => (⟨⟦a.1⟧, (hp₂ _).1 a.2⟩ : { x // p₂ x })) fun a b hab => Subtype.ext_val (Quotient.sound ((h _ _).1 hab)) left_inv := fun ⟨a, ha⟩ => Quotient.inductionOn a (fun a ha => rfl) ha right_inv a := Quotient.inductionOn a fun ⟨a, ha⟩ => rfl #align equiv.subtype_quotient_equiv_quotient_subtype Equiv.subtypeQuotientEquivQuotientSubtype -/ #print Equiv.subtypeQuotientEquivQuotientSubtype_mk /- @[simp] theorem subtypeQuotientEquivQuotientSubtype_mk (p₁ : α → Prop) [s₁ : Setoid α] [s₂ : Setoid (Subtype p₁)] (p₂ : Quotient s₁ → Prop) (hp₂ : ∀ a, p₁ a ↔ p₂ ⟦a⟧) (h : ∀ x y : Subtype p₁, @Setoid.r _ s₂ x y ↔ (x : α) ≈ y) (x hx) : subtypeQuotientEquivQuotientSubtype p₁ p₂ hp₂ h ⟨⟦x⟧, hx⟩ = ⟦⟨x, (hp₂ _).2 hx⟩⟧ := rfl #align equiv.subtype_quotient_equiv_quotient_subtype_mk Equiv.subtypeQuotientEquivQuotientSubtype_mk -/ #print Equiv.subtypeQuotientEquivQuotientSubtype_symm_mk /- @[simp] theorem subtypeQuotientEquivQuotientSubtype_symm_mk (p₁ : α → Prop) [s₁ : Setoid α] [s₂ : Setoid (Subtype p₁)] (p₂ : Quotient s₁ → Prop) (hp₂ : ∀ a, p₁ a ↔ p₂ ⟦a⟧) (h : ∀ x y : Subtype p₁, @Setoid.r _ s₂ x y ↔ (x : α) ≈ y) (x) : (subtypeQuotientEquivQuotientSubtype p₁ p₂ hp₂ h).symm ⟦x⟧ = ⟨⟦x⟧, (hp₂ _).1 x.Prop⟩ := rfl #align equiv.subtype_quotient_equiv_quotient_subtype_symm_mk Equiv.subtypeQuotientEquivQuotientSubtype_symm_mk -/ section Swap variable [DecidableEq α] #print Equiv.swapCore /- /-- A helper function for `equiv.swap`. -/ def swapCore (a b r : α) : α := if r = a then b else if r = b then a else r #align equiv.swap_core Equiv.swapCore -/ #print Equiv.swapCore_self /- theorem swapCore_self (r a : α) : swapCore a a r = r := by unfold swap_core split_ifs <;> cc #align equiv.swap_core_self Equiv.swapCore_self -/ #print Equiv.swapCore_swapCore /- theorem swapCore_swapCore (r a b : α) : swapCore a b (swapCore a b r) = r := by unfold swap_core split_ifs <;> cc #align equiv.swap_core_swap_core Equiv.swapCore_swapCore -/ #print Equiv.swapCore_comm /- theorem swapCore_comm (r a b : α) : swapCore a b r = swapCore b a r := by unfold swap_core split_ifs <;> cc #align equiv.swap_core_comm Equiv.swapCore_comm -/ #print Equiv.swap /- /-- `swap a b` is the permutation that swaps `a` and `b` and leaves other values as is. -/ def swap (a b : α) : Perm α := ⟨swapCore a b, swapCore a b, fun r => swapCore_swapCore r a b, fun r => swapCore_swapCore r a b⟩ #align equiv.swap Equiv.swap -/ #print Equiv.swap_self /- @[simp] theorem swap_self (a : α) : swap a a = Equiv.refl _ := ext fun r => swapCore_self r a #align equiv.swap_self Equiv.swap_self -/ #print Equiv.swap_comm /- theorem swap_comm (a b : α) : swap a b = swap b a := ext fun r => swapCore_comm r _ _ #align equiv.swap_comm Equiv.swap_comm -/ #print Equiv.swap_apply_def /- theorem swap_apply_def (a b x : α) : swap a b x = if x = a then b else if x = b then a else x := rfl #align equiv.swap_apply_def Equiv.swap_apply_def -/ #print Equiv.swap_apply_left /- @[simp] theorem swap_apply_left (a b : α) : swap a b a = b := if_pos rfl #align equiv.swap_apply_left Equiv.swap_apply_left -/ #print Equiv.swap_apply_right /- @[simp] theorem swap_apply_right (a b : α) : swap a b b = a := by by_cases h : b = a <;> simp [swap_apply_def, h] #align equiv.swap_apply_right Equiv.swap_apply_right -/ #print Equiv.swap_apply_of_ne_of_ne /- theorem swap_apply_of_ne_of_ne {a b x : α} : x ≠ a → x ≠ b → swap a b x = x := by simp (config := { contextual := true }) [swap_apply_def] #align equiv.swap_apply_of_ne_of_ne Equiv.swap_apply_of_ne_of_ne -/ #print Equiv.swap_swap /- @[simp] theorem swap_swap (a b : α) : (swap a b).trans (swap a b) = Equiv.refl _ := ext fun x => swapCore_swapCore _ _ _ #align equiv.swap_swap Equiv.swap_swap -/ #print Equiv.symm_swap /- @[simp] theorem symm_swap (a b : α) : (swap a b).symm = swap a b := rfl #align equiv.symm_swap Equiv.symm_swap -/ #print Equiv.swap_eq_refl_iff /- @[simp] theorem swap_eq_refl_iff {x y : α} : swap x y = Equiv.refl _ ↔ x = y := by refine' ⟨fun h => (Equiv.refl _).Injective _, fun h => h ▸ swap_self _⟩ rw [← h, swap_apply_left, h, refl_apply] #align equiv.swap_eq_refl_iff Equiv.swap_eq_refl_iff -/ #print Equiv.swap_comp_apply /- theorem swap_comp_apply {a b x : α} (π : Perm α) : π.trans (swap a b) x = if π x = a then b else if π x = b then a else π x := by cases π rfl #align equiv.swap_comp_apply Equiv.swap_comp_apply -/ #print Equiv.swap_eq_update /- theorem swap_eq_update (i j : α) : (Equiv.swap i j : α → α) = update (update id j i) i j := funext fun x => by rw [update_apply _ i j, update_apply _ j i, Equiv.swap_apply_def, id.def] #align equiv.swap_eq_update Equiv.swap_eq_update -/ /- warning: equiv.comp_swap_eq_update -> Equiv.comp_swap_eq_update is a dubious translation: lean 3 declaration is forall {α : Sort.{u1}} {β : Sort.{u2}} [_inst_1 : DecidableEq.{u1} α] (i : α) (j : α) (f : α -> β), Eq.{imax u1 u2} (α -> β) (Function.comp.{u1, u1, u2} α α β f (coeFn.{max 1 u1, u1} (Equiv.Perm.{u1} α) (fun (_x : Equiv.{u1, u1} α α) => α -> α) (Equiv.hasCoeToFun.{u1, u1} α α) (Equiv.swap.{u1} α (fun (a : α) (b : α) => _inst_1 a b) i j))) (Function.update.{u1, u2} α (fun (ᾰ : α) => β) (fun (a : α) (b : α) => _inst_1 a b) (Function.update.{u1, u2} α (fun (a : α) => β) (fun (a : α) (b : α) => _inst_1 a b) f j (f i)) i (f j)) but is expected to have type forall {α : Sort.{u1}} [β : DecidableEq.{u1} α] {_inst_1 : Sort.{u2}} (i : α) (j : α) (f : α -> _inst_1), Eq.{imax u1 u2} (α -> _inst_1) (Function.comp.{u1, u1, u2} α α _inst_1 f (FunLike.coe.{max 1 u1, u1, u1} (Equiv.Perm.{u1} α) α (fun (_x : α) => (fun ([email protected]._hyg.808 : α) => α) _x) (Equiv.instFunLikeEquiv.{u1, u1} α α) (Equiv.swap.{u1} α (fun (a : α) (b : α) => β a b) i j))) (Function.update.{u1, u2} α (fun (ᾰ : α) => _inst_1) (fun (a : α) (b : α) => β a b) (Function.update.{u1, u2} α (fun (a : α) => _inst_1) (fun (a : α) (b : α) => β a b) f j (f i)) i (f j)) Case conversion may be inaccurate. Consider using '#align equiv.comp_swap_eq_update Equiv.comp_swap_eq_updateₓ'. -/ theorem comp_swap_eq_update (i j : α) (f : α → β) : f ∘ Equiv.swap i j = update (update f j (f i)) i (f j) := by rw [swap_eq_update, comp_update, comp_update, comp.right_id] #align equiv.comp_swap_eq_update Equiv.comp_swap_eq_update /- warning: equiv.symm_trans_swap_trans -> Equiv.symm_trans_swap_trans is a dubious translation: lean 3 declaration is forall {α : Sort.{u1}} {β : Sort.{u2}} [_inst_1 : DecidableEq.{u1} α] [_inst_2 : DecidableEq.{u2} β] (a : α) (b : α) (e : Equiv.{u1, u2} α β), Eq.{max 1 u2} (Equiv.{u2, u2} β β) (Equiv.trans.{u2, u1, u2} β α β (Equiv.trans.{u2, u1, u1} β α α (Equiv.symm.{u1, u2} α β e) (Equiv.swap.{u1} α (fun (a : α) (b : α) => _inst_1 a b) a b)) e) (Equiv.swap.{u2} β (fun (a : β) (b : β) => _inst_2 a b) (coeFn.{max 1 (imax u1 u2) (imax u2 u1), imax u1 u2} (Equiv.{u1, u2} α β) (fun (_x : Equiv.{u1, u2} α β) => α -> β) (Equiv.hasCoeToFun.{u1, u2} α β) e a) (coeFn.{max 1 (imax u1 u2) (imax u2 u1), imax u1 u2} (Equiv.{u1, u2} α β) (fun (_x : Equiv.{u1, u2} α β) => α -> β) (Equiv.hasCoeToFun.{u1, u2} α β) e b)) but is expected to have type forall {α : Sort.{u1}} [β : DecidableEq.{u1} α] {_inst_1 : Sort.{u2}} [_inst_2 : DecidableEq.{u2} _inst_1] (a : α) (b : α) (e : Equiv.{u1, u2} α _inst_1), Eq.{max 1 u2} (Equiv.{u2, u2} _inst_1 _inst_1) (Equiv.trans.{u2, u1, u2} _inst_1 α _inst_1 (Equiv.trans.{u2, u1, u1} _inst_1 α α (Equiv.symm.{u1, u2} α _inst_1 e) (Equiv.swap.{u1} α (fun (a : α) (b : α) => β a b) a b)) e) (Equiv.swap.{u2} ((fun ([email protected]._hyg.808 : α) => _inst_1) a) (fun (a : _inst_1) (b : _inst_1) => _inst_2 a b) (FunLike.coe.{max (max 1 u1) u2, u1, u2} (Equiv.{u1, u2} α _inst_1) α (fun (_x : α) => (fun ([email protected]._hyg.808 : α) => _inst_1) _x) (Equiv.instFunLikeEquiv.{u1, u2} α _inst_1) e a) (FunLike.coe.{max (max 1 u1) u2, u1, u2} (Equiv.{u1, u2} α _inst_1) α (fun (_x : α) => (fun ([email protected]._hyg.808 : α) => _inst_1) _x) (Equiv.instFunLikeEquiv.{u1, u2} α _inst_1) e b)) Case conversion may be inaccurate. Consider using '#align equiv.symm_trans_swap_trans Equiv.symm_trans_swap_transₓ'. -/ @[simp] theorem symm_trans_swap_trans [DecidableEq β] (a b : α) (e : α ≃ β) : (e.symm.trans (swap a b)).trans e = swap (e a) (e b) := Equiv.ext fun x => by have : ∀ a, e.symm x = a ↔ x = e a := fun a => by rw [@eq_comm _ (e.symm x)] constructor <;> intros <;> simp_all simp [swap_apply_def, this] split_ifs <;> simp #align equiv.symm_trans_swap_trans Equiv.symm_trans_swap_trans /- warning: equiv.trans_swap_trans_symm -> Equiv.trans_swap_trans_symm is a dubious translation: lean 3 declaration is forall {α : Sort.{u1}} {β : Sort.{u2}} [_inst_1 : DecidableEq.{u1} α] [_inst_2 : DecidableEq.{u2} β] (a : β) (b : β) (e : Equiv.{u1, u2} α β), Eq.{max 1 u1} (Equiv.{u1, u1} α α) (Equiv.trans.{u1, u2, u1} α β α (Equiv.trans.{u1, u2, u2} α β β e (Equiv.swap.{u2} β (fun (a : β) (b : β) => _inst_2 a b) a b)) (Equiv.symm.{u1, u2} α β e)) (Equiv.swap.{u1} α (fun (a : α) (b : α) => _inst_1 a b) (coeFn.{max 1 (imax u2 u1) (imax u1 u2), imax u2 u1} (Equiv.{u2, u1} β α) (fun (_x : Equiv.{u2, u1} β α) => β -> α) (Equiv.hasCoeToFun.{u2, u1} β α) (Equiv.symm.{u1, u2} α β e) a) (coeFn.{max 1 (imax u2 u1) (imax u1 u2), imax u2 u1} (Equiv.{u2, u1} β α) (fun (_x : Equiv.{u2, u1} β α) => β -> α) (Equiv.hasCoeToFun.{u2, u1} β α) (Equiv.symm.{u1, u2} α β e) b)) but is expected to have type forall {α : Sort.{u1}} [β : DecidableEq.{u1} α] {_inst_1 : Sort.{u2}} [_inst_2 : DecidableEq.{u2} _inst_1] (a : _inst_1) (b : _inst_1) (e : Equiv.{u1, u2} α _inst_1), Eq.{max 1 u1} (Equiv.{u1, u1} α α) (Equiv.trans.{u1, u2, u1} α _inst_1 α (Equiv.trans.{u1, u2, u2} α _inst_1 _inst_1 e (Equiv.swap.{u2} _inst_1 (fun (a : _inst_1) (b : _inst_1) => _inst_2 a b) a b)) (Equiv.symm.{u1, u2} α _inst_1 e)) (Equiv.swap.{u1} ((fun ([email protected]._hyg.808 : _inst_1) => α) a) (fun (a : α) (b : α) => β a b) (FunLike.coe.{max (max 1 u1) u2, u2, u1} (Equiv.{u2, u1} _inst_1 α) _inst_1 (fun (_x : _inst_1) => (fun ([email protected]._hyg.808 : _inst_1) => α) _x) (Equiv.instFunLikeEquiv.{u2, u1} _inst_1 α) (Equiv.symm.{u1, u2} α _inst_1 e) a) (FunLike.coe.{max (max 1 u1) u2, u2, u1} (Equiv.{u2, u1} _inst_1 α) _inst_1 (fun (_x : _inst_1) => (fun ([email protected]._hyg.808 : _inst_1) => α) _x) (Equiv.instFunLikeEquiv.{u2, u1} _inst_1 α) (Equiv.symm.{u1, u2} α _inst_1 e) b)) Case conversion may be inaccurate. Consider using '#align equiv.trans_swap_trans_symm Equiv.trans_swap_trans_symmₓ'. -/ @[simp] theorem trans_swap_trans_symm [DecidableEq β] (a b : β) (e : α ≃ β) : (e.trans (swap a b)).trans e.symm = swap (e.symm a) (e.symm b) := symm_trans_swap_trans a b e.symm #align equiv.trans_swap_trans_symm Equiv.trans_swap_trans_symm #print Equiv.swap_apply_self /- @[simp] theorem swap_apply_self (i j a : α) : swap i j (swap i j a) = a := by rw [← Equiv.trans_apply, Equiv.swap_swap, Equiv.refl_apply] #align equiv.swap_apply_self Equiv.swap_apply_self -/ /- warning: equiv.apply_swap_eq_self -> Equiv.apply_swap_eq_self is a dubious translation: lean 3 declaration is forall {α : Sort.{u1}} {β : Sort.{u2}} [_inst_1 : DecidableEq.{u1} α] {v : α -> β} {i : α} {j : α}, (Eq.{u2} β (v i) (v j)) -> (forall (k : α), Eq.{u2} β (v (coeFn.{max 1 u1, u1} (Equiv.Perm.{u1} α) (fun (_x : Equiv.{u1, u1} α α) => α -> α) (Equiv.hasCoeToFun.{u1, u1} α α) (Equiv.swap.{u1} α (fun (a : α) (b : α) => _inst_1 a b) i j) k)) (v k)) but is expected to have type forall {α : Sort.{u1}} [β : DecidableEq.{u1} α] {_inst_1 : Sort.{u2}} {v : α -> _inst_1} {i : α} {j : α}, (Eq.{u2} _inst_1 (v i) (v j)) -> (forall (k : α), Eq.{u2} _inst_1 (v (FunLike.coe.{max 1 u1, u1, u1} (Equiv.Perm.{u1} α) α (fun (_x : α) => (fun ([email protected]._hyg.808 : α) => α) _x) (Equiv.instFunLikeEquiv.{u1, u1} α α) (Equiv.swap.{u1} α (fun (a : α) (b : α) => β a b) i j) k)) (v k)) Case conversion may be inaccurate. Consider using '#align equiv.apply_swap_eq_self Equiv.apply_swap_eq_selfₓ'. -/ /-- A function is invariant to a swap if it is equal at both elements -/ theorem apply_swap_eq_self {v : α → β} {i j : α} (hv : v i = v j) (k : α) : v (swap i j k) = v k := by by_cases hi : k = i; · rw [hi, swap_apply_left, hv] by_cases hj : k = j; · rw [hj, swap_apply_right, hv] rw [swap_apply_of_ne_of_ne hi hj] #align equiv.apply_swap_eq_self Equiv.apply_swap_eq_self #print Equiv.swap_apply_eq_iff /- theorem swap_apply_eq_iff {x y z w : α} : swap x y z = w ↔ z = swap x y w := by rw [apply_eq_iff_eq_symm_apply, symm_swap] #align equiv.swap_apply_eq_iff Equiv.swap_apply_eq_iff -/ #print Equiv.swap_apply_ne_self_iff /- theorem swap_apply_ne_self_iff {a b x : α} : swap a b x ≠ x ↔ a ≠ b ∧ (x = a ∨ x = b) := by by_cases hab : a = b · simp [hab] by_cases hax : x = a · simp [hax, eq_comm] by_cases hbx : x = b · simp [hbx] simp [hab, hax, hbx, swap_apply_of_ne_of_ne] #align equiv.swap_apply_ne_self_iff Equiv.swap_apply_ne_self_iff -/ namespace Perm /- warning: equiv.perm.sum_congr_swap_refl -> Equiv.Perm.sumCongr_swap_refl is a dubious translation: lean 3 declaration is forall {α : Type.{u1}} {β : Type.{u2}} [_inst_2 : DecidableEq.{succ u1} α] [_inst_3 : DecidableEq.{succ u2} β] (i : α) (j : α), Eq.{max 1 (succ u1) (succ u2)} (Equiv.Perm.{max (succ u1) (succ u2)} (Sum.{u1, u2} α β)) (Equiv.Perm.sumCongr.{u1, u2} α β (Equiv.swap.{succ u1} α (fun (a : α) (b : α) => _inst_2 a b) i j) (Equiv.refl.{succ u2} β)) (Equiv.swap.{max (succ u1) (succ u2)} (Sum.{u1, u2} α β) (fun (a : Sum.{u1, u2} α β) (b : Sum.{u1, u2} α β) => Sum.decidableEq.{u1, u2} α (fun (a : α) (b : α) => _inst_2 a b) β (fun (a : β) (b : β) => _inst_3 a b) a b) (Sum.inl.{u1, u2} α β i) (Sum.inl.{u1, u2} α β j)) but is expected to have type forall {α : Type.{u2}} {β : Type.{u1}} [_inst_2 : DecidableEq.{succ u2} α] [_inst_3 : DecidableEq.{succ u1} β] (i : α) (j : α), Eq.{max (succ u1) (succ u2)} (Equiv.Perm.{max (succ u1) (succ u2)} (Sum.{u2, u1} α β)) (Equiv.Perm.sumCongr.{u2, u1} α β (Equiv.swap.{succ u2} α (fun (a : α) (b : α) => _inst_2 a b) i j) (Equiv.refl.{succ u1} β)) (Equiv.swap.{max (succ u1) (succ u2)} (Sum.{u2, u1} α β) (fun (a : Sum.{u2, u1} α β) (b : Sum.{u2, u1} α β) => Sum.instDecidableEqSum.{u2, u1} α β (fun (a : α) (b : α) => _inst_2 a b) (fun (a : β) (b : β) => _inst_3 a b) a b) (Sum.inl.{u2, u1} α β i) (Sum.inl.{u2, u1} α β j)) Case conversion may be inaccurate. Consider using '#align equiv.perm.sum_congr_swap_refl Equiv.Perm.sumCongr_swap_reflₓ'. -/ @[simp] theorem sumCongr_swap_refl {α β : Sort _} [DecidableEq α] [DecidableEq β] (i j : α) : Equiv.Perm.sumCongr (Equiv.swap i j) (Equiv.refl β) = Equiv.swap (Sum.inl i) (Sum.inl j) := by ext x cases x · simp [Sum.map, swap_apply_def] split_ifs <;> rfl · simp [Sum.map, swap_apply_of_ne_of_ne] #align equiv.perm.sum_congr_swap_refl Equiv.Perm.sumCongr_swap_refl /- warning: equiv.perm.sum_congr_refl_swap -> Equiv.Perm.sumCongr_refl_swap is a dubious translation: lean 3 declaration is forall {α : Type.{u1}} {β : Type.{u2}} [_inst_2 : DecidableEq.{succ u1} α] [_inst_3 : DecidableEq.{succ u2} β] (i : β) (j : β), Eq.{max 1 (succ u1) (succ u2)} (Equiv.Perm.{max (succ u1) (succ u2)} (Sum.{u1, u2} α β)) (Equiv.Perm.sumCongr.{u1, u2} α β (Equiv.refl.{succ u1} α) (Equiv.swap.{succ u2} β (fun (a : β) (b : β) => _inst_3 a b) i j)) (Equiv.swap.{max (succ u1) (succ u2)} (Sum.{u1, u2} α β) (fun (a : Sum.{u1, u2} α β) (b : Sum.{u1, u2} α β) => Sum.decidableEq.{u1, u2} α (fun (a : α) (b : α) => _inst_2 a b) β (fun (a : β) (b : β) => _inst_3 a b) a b) (Sum.inr.{u1, u2} α β i) (Sum.inr.{u1, u2} α β j)) but is expected to have type forall {α : Type.{u2}} {β : Type.{u1}} [_inst_2 : DecidableEq.{succ u2} α] [_inst_3 : DecidableEq.{succ u1} β] (i : β) (j : β), Eq.{max (succ u1) (succ u2)} (Equiv.Perm.{max (succ u1) (succ u2)} (Sum.{u2, u1} α β)) (Equiv.Perm.sumCongr.{u2, u1} α β (Equiv.refl.{succ u2} α) (Equiv.swap.{succ u1} β (fun (a : β) (b : β) => _inst_3 a b) i j)) (Equiv.swap.{max (succ u1) (succ u2)} (Sum.{u2, u1} α β) (fun (a : Sum.{u2, u1} α β) (b : Sum.{u2, u1} α β) => Sum.instDecidableEqSum.{u2, u1} α β (fun (a : α) (b : α) => _inst_2 a b) (fun (a : β) (b : β) => _inst_3 a b) a b) (Sum.inr.{u2, u1} α β i) (Sum.inr.{u2, u1} α β j)) Case conversion may be inaccurate. Consider using '#align equiv.perm.sum_congr_refl_swap Equiv.Perm.sumCongr_refl_swapₓ'. -/ @[simp] theorem sumCongr_refl_swap {α β : Sort _} [DecidableEq α] [DecidableEq β] (i j : β) : Equiv.Perm.sumCongr (Equiv.refl α) (Equiv.swap i j) = Equiv.swap (Sum.inr i) (Sum.inr j) := by ext x cases x · simp [Sum.map, swap_apply_of_ne_of_ne] · simp [Sum.map, swap_apply_def] split_ifs <;> rfl #align equiv.perm.sum_congr_refl_swap Equiv.Perm.sumCongr_refl_swap end Perm /- warning: equiv.set_value -> Equiv.setValue is a dubious translation: lean 3 declaration is forall {α : Sort.{u1}} {β : Sort.{u2}} [_inst_1 : DecidableEq.{u1} α], (Equiv.{u1, u2} α β) -> α -> β -> (Equiv.{u1, u2} α β) but is expected to have type forall {α : Sort.{u1}} [β : DecidableEq.{u1} α] {_inst_1 : Sort.{u2}}, (Equiv.{u1, u2} α _inst_1) -> α -> _inst_1 -> (Equiv.{u1, u2} α _inst_1) Case conversion may be inaccurate. Consider using '#align equiv.set_value Equiv.setValueₓ'. -/ /-- Augment an equivalence with a prescribed mapping `f a = b` -/ def setValue (f : α ≃ β) (a : α) (b : β) : α ≃ β := (swap a (f.symm b)).trans f #align equiv.set_value Equiv.setValue /- warning: equiv.set_value_eq -> Equiv.setValue_eq is a dubious translation: lean 3 declaration is forall {α : Sort.{u1}} {β : Sort.{u2}} [_inst_1 : DecidableEq.{u1} α] (f : Equiv.{u1, u2} α β) (a : α) (b : β), Eq.{u2} β (coeFn.{max 1 (imax u1 u2) (imax u2 u1), imax u1 u2} (Equiv.{u1, u2} α β) (fun (_x : Equiv.{u1, u2} α β) => α -> β) (Equiv.hasCoeToFun.{u1, u2} α β) (Equiv.setValue.{u1, u2} α β (fun (a : α) (b : α) => _inst_1 a b) f a b) a) b but is expected to have type forall {α : Sort.{u1}} [β : DecidableEq.{u1} α] {_inst_1 : Sort.{u2}} (f : Equiv.{u1, u2} α _inst_1) (a : α) (b : _inst_1), Eq.{u2} ((fun ([email protected]._hyg.808 : α) => _inst_1) a) (FunLike.coe.{max (max 1 u1) u2, u1, u2} (Equiv.{u1, u2} α _inst_1) α (fun (_x : α) => (fun ([email protected]._hyg.808 : α) => _inst_1) _x) (Equiv.instFunLikeEquiv.{u1, u2} α _inst_1) (Equiv.setValue.{u1, u2} α (fun (a : α) (b : α) => β a b) _inst_1 f a b) a) b Case conversion may be inaccurate. Consider using '#align equiv.set_value_eq Equiv.setValue_eqₓ'. -/ @[simp] theorem setValue_eq (f : α ≃ β) (a : α) (b : β) : setValue f a b a = b := by dsimp [set_value] simp [swap_apply_left] #align equiv.set_value_eq Equiv.setValue_eq end Swap end Equiv namespace Function.Involutive #print Function.Involutive.toPerm /- /-- Convert an involutive function `f` to a permutation with `to_fun = inv_fun = f`. -/ def toPerm (f : α → α) (h : Involutive f) : Equiv.Perm α := ⟨f, f, h.LeftInverse, h.RightInverse⟩ #align function.involutive.to_perm Function.Involutive.toPerm -/ #print Function.Involutive.coe_toPerm /- @[simp] theorem coe_toPerm {f : α → α} (h : Involutive f) : (h.toPerm f : α → α) = f := rfl #align function.involutive.coe_to_perm Function.Involutive.coe_toPerm -/ #print Function.Involutive.toPerm_symm /- @[simp] theorem toPerm_symm {f : α → α} (h : Involutive f) : (h.toPerm f).symm = h.toPerm f := rfl #align function.involutive.to_perm_symm Function.Involutive.toPerm_symm -/ #print Function.Involutive.toPerm_involutive /- theorem toPerm_involutive {f : α → α} (h : Involutive f) : Involutive (h.toPerm f) := h #align function.involutive.to_perm_involutive Function.Involutive.toPerm_involutive -/ end Function.Involutive #print PLift.eq_up_iff_down_eq /- theorem PLift.eq_up_iff_down_eq {x : PLift α} {y : α} : x = PLift.up y ↔ x.down = y := Equiv.plift.eq_symm_apply #align plift.eq_up_iff_down_eq PLift.eq_up_iff_down_eq -/ /- warning: function.injective.map_swap -> Function.Injective.map_swap is a dubious translation: lean 3 declaration is forall {α : Sort.{u1}} {β : Sort.{u2}} [_inst_1 : DecidableEq.{u1} α] [_inst_2 : DecidableEq.{u2} β] {f : α -> β}, (Function.Injective.{u1, u2} α β f) -> (forall (x : α) (y : α) (z : α), Eq.{u2} β (f (coeFn.{max 1 u1, u1} (Equiv.Perm.{u1} α) (fun (_x : Equiv.{u1, u1} α α) => α -> α) (Equiv.hasCoeToFun.{u1, u1} α α) (Equiv.swap.{u1} α (fun (a : α) (b : α) => _inst_1 a b) x y) z)) (coeFn.{max 1 u2, u2} (Equiv.Perm.{u2} β) (fun (_x : Equiv.{u2, u2} β β) => β -> β) (Equiv.hasCoeToFun.{u2, u2} β β) (Equiv.swap.{u2} β (fun (a : β) (b : β) => _inst_2 a b) (f x) (f y)) (f z))) but is expected to have type forall {α : Sort.{u2}} {β : Sort.{u1}} [_inst_1 : DecidableEq.{u2} α] [_inst_2 : DecidableEq.{u1} β] {f : α -> β}, (Function.Injective.{u2, u1} α β f) -> (forall (x : α) (y : α) (z : α), Eq.{u1} β (f (FunLike.coe.{max 1 u2, u2, u2} (Equiv.Perm.{u2} α) α (fun (_x : α) => (fun ([email protected]._hyg.808 : α) => α) _x) (Equiv.instFunLikeEquiv.{u2, u2} α α) (Equiv.swap.{u2} α (fun (a : α) (b : α) => _inst_1 a b) x y) z)) (FunLike.coe.{max 1 u1, u1, u1} (Equiv.Perm.{u1} β) β (fun (_x : β) => (fun ([email protected]._hyg.808 : β) => β) _x) (Equiv.instFunLikeEquiv.{u1, u1} β β) (Equiv.swap.{u1} β (fun (a : β) (b : β) => _inst_2 a b) (f x) (f y)) (f z))) Case conversion may be inaccurate. Consider using '#align function.injective.map_swap Function.Injective.map_swapₓ'. -/ theorem Function.Injective.map_swap {α β : Sort _} [DecidableEq α] [DecidableEq β] {f : α → β} (hf : Function.Injective f) (x y z : α) : f (Equiv.swap x y z) = Equiv.swap (f x) (f y) (f z) := by conv_rhs => rw [Equiv.swap_apply_def] split_ifs with h₁ h₂ · rw [hf h₁, Equiv.swap_apply_left] · rw [hf h₂, Equiv.swap_apply_right] · rw [Equiv.swap_apply_of_ne_of_ne (mt (congr_arg f) h₁) (mt (congr_arg f) h₂)] #align function.injective.map_swap Function.Injective.map_swap namespace Equiv section variable (P : α → Sort w) (e : α ≃ β) #print Equiv.piCongrLeft' /- /-- Transport dependent functions through an equivalence of the base space. -/ @[simps] def piCongrLeft' : (∀ a, P a) ≃ ∀ b, P (e.symm b) where toFun f x := f (e.symm x) invFun f x := by rw [← e.symm_apply_apply x]; exact f (e x) left_inv f := funext fun x => eq_of_hEq ((eq_rec_hEq _ _).trans (by dsimp rw [e.symm_apply_apply])) right_inv f := funext fun x => eq_of_hEq ((eq_rec_hEq _ _).trans (by rw [e.apply_symm_apply])) #align equiv.Pi_congr_left' Equiv.piCongrLeft' -/ end section variable (P : β → Sort w) (e : α ≃ β) /- warning: equiv.Pi_congr_left -> Equiv.piCongrLeft is a dubious translation: lean 3 declaration is forall {α : Sort.{u1}} {β : Sort.{u2}} (P : β -> Sort.{u3}) (e : Equiv.{u1, u2} α β), Equiv.{imax u1 u3, imax u2 u3} (forall (a : α), P (coeFn.{max 1 (imax u1 u2) (imax u2 u1), imax u1 u2} (Equiv.{u1, u2} α β) (fun (_x : Equiv.{u1, u2} α β) => α -> β) (Equiv.hasCoeToFun.{u1, u2} α β) e a)) (forall (b : β), P b) but is expected to have type forall {α : Sort.{u2}} {β : Sort.{u3}} (P : α -> Sort.{u1}) (e : Equiv.{u3, u2} β α), Equiv.{imax u3 u1, imax u2 u1} (forall (a : β), P (FunLike.coe.{max (max 1 u2) u3, u3, u2} (Equiv.{u3, u2} β α) β (fun (_x : β) => (fun ([email protected]._hyg.808 : β) => α) _x) (Equiv.instFunLikeEquiv.{u3, u2} β α) e a)) (forall (b : α), P b) Case conversion may be inaccurate. Consider using '#align equiv.Pi_congr_left Equiv.piCongrLeftₓ'. -/ /-- Transporting dependent functions through an equivalence of the base, expressed as a "simplification". -/ def piCongrLeft : (∀ a, P (e a)) ≃ ∀ b, P b := (piCongrLeft' P e.symm).symm #align equiv.Pi_congr_left Equiv.piCongrLeft end section variable {W : α → Sort w} {Z : β → Sort z} (h₁ : α ≃ β) (h₂ : ∀ a : α, W a ≃ Z (h₁ a)) /- warning: equiv.Pi_congr -> Equiv.piCongr is a dubious translation: lean 3 declaration is forall {α : Sort.{u1}} {β : Sort.{u2}} {W : α -> Sort.{u3}} {Z : β -> Sort.{u4}} (h₁ : Equiv.{u1, u2} α β), (forall (a : α), Equiv.{u3, u4} (W a) (Z (coeFn.{max 1 (imax u1 u2) (imax u2 u1), imax u1 u2} (Equiv.{u1, u2} α β) (fun (_x : Equiv.{u1, u2} α β) => α -> β) (Equiv.hasCoeToFun.{u1, u2} α β) h₁ a))) -> (Equiv.{imax u1 u3, imax u2 u4} (forall (a : α), W a) (forall (b : β), Z b)) but is expected to have type forall {α : Sort.{u3}} {β : Sort.{u4}} {W : α -> Sort.{u1}} {Z : β -> Sort.{u2}} (h₁ : Equiv.{u3, u4} α β), (forall (a : α), Equiv.{u1, u2} (W a) (Z (FunLike.coe.{max (max 1 u3) u4, u3, u4} (Equiv.{u3, u4} α β) α (fun (_x : α) => (fun ([email protected]._hyg.808 : α) => β) _x) (Equiv.instFunLikeEquiv.{u3, u4} α β) h₁ a))) -> (Equiv.{imax u3 u1, imax u4 u2} (forall (a : α), W a) (forall (b : β), Z b)) Case conversion may be inaccurate. Consider using '#align equiv.Pi_congr Equiv.piCongrₓ'. -/ /-- Transport dependent functions through an equivalence of the base spaces and a family of equivalences of the matching fibers. -/ def piCongr : (∀ a, W a) ≃ ∀ b, Z b := (Equiv.piCongrRight h₂).trans (Equiv.piCongrLeft _ h₁) #align equiv.Pi_congr Equiv.piCongr #print Equiv.coe_piCongr_symm /- @[simp] theorem coe_piCongr_symm : ((h₁.piCongr h₂).symm : (∀ b, Z b) → ∀ a, W a) = fun f a => (h₂ a).symm (f (h₁ a)) := rfl #align equiv.coe_Pi_congr_symm Equiv.coe_piCongr_symm -/ /- warning: equiv.Pi_congr_symm_apply -> Equiv.piCongr_symm_apply is a dubious translation: lean 3 declaration is forall {α : Sort.{u1}} {β : Sort.{u2}} {W : α -> Sort.{u3}} {Z : β -> Sort.{u4}} (h₁ : Equiv.{u1, u2} α β) (h₂ : forall (a : α), Equiv.{u3, u4} (W a) (Z (coeFn.{max 1 (imax u1 u2) (imax u2 u1), imax u1 u2} (Equiv.{u1, u2} α β) (fun (_x : Equiv.{u1, u2} α β) => α -> β) (Equiv.hasCoeToFun.{u1, u2} α β) h₁ a))) (f : forall (b : β), Z b), Eq.{imax u1 u3} (forall (a : α), W a) (coeFn.{max 1 (imax (imax u2 u4) u1 u3) (imax (imax u1 u3) u2 u4), imax (imax u2 u4) u1 u3} (Equiv.{imax u2 u4, imax u1 u3} (forall (b : β), Z b) (forall (a : α), W a)) (fun (_x : Equiv.{imax u2 u4, imax u1 u3} (forall (b : β), Z b) (forall (a : α), W a)) => (forall (b : β), Z b) -> (forall (a : α), W a)) (Equiv.hasCoeToFun.{imax u2 u4, imax u1 u3} (forall (b : β), Z b) (forall (a : α), W a)) (Equiv.symm.{imax u1 u3, imax u2 u4} (forall (a : α), W a) (forall (b : β), Z b) (Equiv.piCongr.{u1, u2, u3, u4} α β (fun (a : α) => W a) Z h₁ h₂)) f) (fun (a : α) => coeFn.{max 1 (imax u4 u3) (imax u3 u4), imax u4 u3} (Equiv.{u4, u3} (Z (coeFn.{max 1 (imax u1 u2) (imax u2 u1), imax u1 u2} (Equiv.{u1, u2} α β) (fun (_x : Equiv.{u1, u2} α β) => α -> β) (Equiv.hasCoeToFun.{u1, u2} α β) h₁ a)) (W a)) (fun (_x : Equiv.{u4, u3} (Z (coeFn.{max 1 (imax u1 u2) (imax u2 u1), imax u1 u2} (Equiv.{u1, u2} α β) (fun (_x : Equiv.{u1, u2} α β) => α -> β) (Equiv.hasCoeToFun.{u1, u2} α β) h₁ a)) (W a)) => (Z (coeFn.{max 1 (imax u1 u2) (imax u2 u1), imax u1 u2} (Equiv.{u1, u2} α β) (fun (_x : Equiv.{u1, u2} α β) => α -> β) (Equiv.hasCoeToFun.{u1, u2} α β) h₁ a)) -> (W a)) (Equiv.hasCoeToFun.{u4, u3} (Z (coeFn.{max 1 (imax u1 u2) (imax u2 u1), imax u1 u2} (Equiv.{u1, u2} α β) (fun (_x : Equiv.{u1, u2} α β) => α -> β) (Equiv.hasCoeToFun.{u1, u2} α β) h₁ a)) (W a)) (Equiv.symm.{u3, u4} (W a) (Z (coeFn.{max 1 (imax u1 u2) (imax u2 u1), imax u1 u2} (Equiv.{u1, u2} α β) (fun (_x : Equiv.{u1, u2} α β) => α -> β) (Equiv.hasCoeToFun.{u1, u2} α β) h₁ a)) (h₂ a)) (f (coeFn.{max 1 (imax u1 u2) (imax u2 u1), imax u1 u2} (Equiv.{u1, u2} α β) (fun (_x : Equiv.{u1, u2} α β) => α -> β) (Equiv.hasCoeToFun.{u1, u2} α β) h₁ a))) but is expected to have type forall {α : Sort.{u2}} {β : Sort.{u1}} {W : α -> Sort.{u3}} {Z : β -> Sort.{u4}} (h₁ : Equiv.{u2, u1} α β) (h₂ : forall (a : α), Equiv.{u3, u4} (W a) (Z (FunLike.coe.{max (max 1 u2) u1, u2, u1} (Equiv.{u2, u1} α β) α (fun (_x : α) => (fun ([email protected]._hyg.808 : α) => β) _x) (Equiv.instFunLikeEquiv.{u2, u1} α β) h₁ a))) (f : forall (b : β), Z b), Eq.{imax u2 u3} ((fun ([email protected]._hyg.808 : forall (b : β), Z b) => forall (a : α), W a) f) (FunLike.coe.{max (max 1 (imax u2 u3)) (imax u1 u4), imax u1 u4, imax u2 u3} (Equiv.{imax u1 u4, imax u2 u3} (forall (b : β), Z b) (forall (a : α), W a)) (forall (b : β), Z b) (fun (_x : forall (b : β), Z b) => (fun ([email protected]._hyg.808 : forall (b : β), Z b) => forall (a : α), W a) _x) (Equiv.instFunLikeEquiv.{imax u1 u4, imax u2 u3} (forall (b : β), Z b) (forall (a : α), W a)) (Equiv.symm.{imax u2 u3, imax u1 u4} (forall (a : α), W a) (forall (b : β), Z b) (Equiv.piCongr.{u3, u4, u2, u1} α β (fun (a : α) => W a) Z h₁ h₂)) f) (fun (a : α) => FunLike.coe.{max (max 1 u3) u4, u4, u3} (Equiv.{u4, u3} (Z (FunLike.coe.{max (max 1 u2) u1, u2, u1} (Equiv.{u2, u1} α β) α (fun (a : α) => (fun ([email protected]._hyg.808 : α) => β) a) (Equiv.instFunLikeEquiv.{u2, u1} α β) h₁ a)) (W a)) (Z (FunLike.coe.{max (max 1 u2) u1, u2, u1} (Equiv.{u2, u1} α β) α (fun (a : α) => (fun ([email protected]._hyg.808 : α) => β) a) (Equiv.instFunLikeEquiv.{u2, u1} α β) h₁ a)) (fun (_x : Z (FunLike.coe.{max (max 1 u2) u1, u2, u1} (Equiv.{u2, u1} α β) α (fun (a : α) => (fun ([email protected]._hyg.808 : α) => β) a) (Equiv.instFunLikeEquiv.{u2, u1} α β) h₁ a)) => (fun ([email protected]._hyg.808 : Z (FunLike.coe.{max (max 1 u2) u1, u2, u1} (Equiv.{u2, u1} α β) α (fun (a : α) => (fun ([email protected]._hyg.808 : α) => β) a) (Equiv.instFunLikeEquiv.{u2, u1} α β) h₁ a)) => W a) _x) (Equiv.instFunLikeEquiv.{u4, u3} (Z (FunLike.coe.{max (max 1 u2) u1, u2, u1} (Equiv.{u2, u1} α β) α (fun (_x : α) => (fun ([email protected]._hyg.808 : α) => β) _x) (Equiv.instFunLikeEquiv.{u2, u1} α β) h₁ a)) (W a)) (Equiv.symm.{u3, u4} (W a) (Z (FunLike.coe.{max (max 1 u2) u1, u2, u1} (Equiv.{u2, u1} α β) α (fun (_x : α) => (fun ([email protected]._hyg.808 : α) => β) _x) (Equiv.instFunLikeEquiv.{u2, u1} α β) h₁ a)) (h₂ a)) (f (FunLike.coe.{max (max 1 u2) u1, u2, u1} (Equiv.{u2, u1} α β) α (fun (_x : α) => (fun ([email protected]._hyg.808 : α) => β) _x) (Equiv.instFunLikeEquiv.{u2, u1} α β) h₁ a))) Case conversion may be inaccurate. Consider using '#align equiv.Pi_congr_symm_apply Equiv.piCongr_symm_applyₓ'. -/ theorem piCongr_symm_apply (f : ∀ b, Z b) : (h₁.piCongr h₂).symm f = fun a => (h₂ a).symm (f (h₁ a)) := rfl #align equiv.Pi_congr_symm_apply Equiv.piCongr_symm_apply /- warning: equiv.Pi_congr_apply_apply -> Equiv.piCongr_apply_apply is a dubious translation: lean 3 declaration is forall {α : Sort.{u1}} {β : Sort.{u2}} {W : α -> Sort.{u3}} {Z : β -> Sort.{u4}} (h₁ : Equiv.{u1, u2} α β) (h₂ : forall (a : α), Equiv.{u3, u4} (W a) (Z (coeFn.{max 1 (imax u1 u2) (imax u2 u1), imax u1 u2} (Equiv.{u1, u2} α β) (fun (_x : Equiv.{u1, u2} α β) => α -> β) (Equiv.hasCoeToFun.{u1, u2} α β) h₁ a))) (f : forall (a : α), W a) (a : α), Eq.{u4} (Z (coeFn.{max 1 (imax u1 u2) (imax u2 u1), imax u1 u2} (Equiv.{u1, u2} α β) (fun (_x : Equiv.{u1, u2} α β) => α -> β) (Equiv.hasCoeToFun.{u1, u2} α β) h₁ a)) (coeFn.{max 1 (imax (imax u1 u3) u2 u4) (imax (imax u2 u4) u1 u3), imax (imax u1 u3) u2 u4} (Equiv.{imax u1 u3, imax u2 u4} (forall (a : α), (fun (a : α) => W a) a) (forall (b : β), Z b)) (fun (_x : Equiv.{imax u1 u3, imax u2 u4} (forall (a : α), (fun (a : α) => W a) a) (forall (b : β), Z b)) => (forall (a : α), (fun (a : α) => W a) a) -> (forall (b : β), Z b)) (Equiv.hasCoeToFun.{imax u1 u3, imax u2 u4} (forall (a : α), (fun (a : α) => W a) a) (forall (b : β), Z b)) (Equiv.piCongr.{u1, u2, u3, u4} α β (fun (a : α) => W a) Z h₁ h₂) f (coeFn.{max 1 (imax u1 u2) (imax u2 u1), imax u1 u2} (Equiv.{u1, u2} α β) (fun (_x : Equiv.{u1, u2} α β) => α -> β) (Equiv.hasCoeToFun.{u1, u2} α β) h₁ a)) (coeFn.{max 1 (imax u3 u4) (imax u4 u3), imax u3 u4} (Equiv.{u3, u4} (W a) (Z (coeFn.{max 1 (imax u1 u2) (imax u2 u1), imax u1 u2} (Equiv.{u1, u2} α β) (fun (_x : Equiv.{u1, u2} α β) => α -> β) (Equiv.hasCoeToFun.{u1, u2} α β) h₁ a))) (fun (_x : Equiv.{u3, u4} (W a) (Z (coeFn.{max 1 (imax u1 u2) (imax u2 u1), imax u1 u2} (Equiv.{u1, u2} α β) (fun (_x : Equiv.{u1, u2} α β) => α -> β) (Equiv.hasCoeToFun.{u1, u2} α β) h₁ a))) => (W a) -> (Z (coeFn.{max 1 (imax u1 u2) (imax u2 u1), imax u1 u2} (Equiv.{u1, u2} α β) (fun (_x : Equiv.{u1, u2} α β) => α -> β) (Equiv.hasCoeToFun.{u1, u2} α β) h₁ a))) (Equiv.hasCoeToFun.{u3, u4} (W a) (Z (coeFn.{max 1 (imax u1 u2) (imax u2 u1), imax u1 u2} (Equiv.{u1, u2} α β) (fun (_x : Equiv.{u1, u2} α β) => α -> β) (Equiv.hasCoeToFun.{u1, u2} α β) h₁ a))) (h₂ a) (f a)) but is expected to have type forall {α : Sort.{u2}} {β : Sort.{u1}} {W : α -> Sort.{u3}} {Z : β -> Sort.{u4}} (h₁ : Equiv.{u2, u1} α β) (h₂ : forall (a : α), Equiv.{u3, u4} (W a) (Z (FunLike.coe.{max (max 1 u2) u1, u2, u1} (Equiv.{u2, u1} α β) α (fun (_x : α) => (fun ([email protected]._hyg.808 : α) => β) _x) (Equiv.instFunLikeEquiv.{u2, u1} α β) h₁ a))) (f : forall (a : α), W a) (a : α), Eq.{u4} (Z (FunLike.coe.{max (max 1 u2) u1, u2, u1} (Equiv.{u2, u1} α β) α (fun (_x : α) => (fun ([email protected]._hyg.808 : α) => β) _x) (Equiv.instFunLikeEquiv.{u2, u1} α β) h₁ a)) (FunLike.coe.{max (max 1 (imax u2 u3)) (imax u1 u4), imax u2 u3, imax u1 u4} (Equiv.{imax u2 u3, imax u1 u4} (forall (a : α), W a) (forall (b : β), Z b)) (forall (a : α), W a) (fun (_x : forall (a : α), W a) => (fun ([email protected]._hyg.808 : forall (a : α), W a) => forall (b : β), Z b) _x) (Equiv.instFunLikeEquiv.{imax u2 u3, imax u1 u4} (forall (a : α), W a) (forall (b : β), Z b)) (Equiv.piCongr.{u3, u4, u2, u1} α β (fun (a : α) => W a) Z h₁ h₂) f (FunLike.coe.{max (max 1 u2) u1, u2, u1} (Equiv.{u2, u1} α β) α (fun (_x : α) => (fun ([email protected]._hyg.808 : α) => β) _x) (Equiv.instFunLikeEquiv.{u2, u1} α β) h₁ a)) (FunLike.coe.{max (max 1 u3) u4, u3, u4} (Equiv.{u3, u4} (W a) (Z (FunLike.coe.{max (max 1 u2) u1, u2, u1} (Equiv.{u2, u1} α β) α (fun (a : α) => (fun ([email protected]._hyg.808 : α) => β) a) (Equiv.instFunLikeEquiv.{u2, u1} α β) h₁ a))) (W a) (fun (_x : W a) => (fun ([email protected]._hyg.808 : W a) => Z (FunLike.coe.{max (max 1 u2) u1, u2, u1} (Equiv.{u2, u1} α β) α (fun (a : α) => (fun ([email protected]._hyg.808 : α) => β) a) (Equiv.instFunLikeEquiv.{u2, u1} α β) h₁ a)) _x) (Equiv.instFunLikeEquiv.{u3, u4} (W a) (Z (FunLike.coe.{max (max 1 u2) u1, u2, u1} (Equiv.{u2, u1} α β) α (fun (_x : α) => (fun ([email protected]._hyg.808 : α) => β) _x) (Equiv.instFunLikeEquiv.{u2, u1} α β) h₁ a))) (h₂ a) (f a)) Case conversion may be inaccurate. Consider using '#align equiv.Pi_congr_apply_apply Equiv.piCongr_apply_applyₓ'. -/ @[simp] theorem piCongr_apply_apply (f : ∀ a, W a) (a : α) : h₁.piCongr h₂ f (h₁ a) = h₂ a (f a) := by change cast _ ((h₂ (h₁.symm (h₁ a))) (f (h₁.symm (h₁ a)))) = (h₂ a) (f a) generalize_proofs hZa revert hZa rw [h₁.symm_apply_apply a] simp #align equiv.Pi_congr_apply_apply Equiv.piCongr_apply_apply end section variable {W : α → Sort w} {Z : β → Sort z} (h₁ : α ≃ β) (h₂ : ∀ b : β, W (h₁.symm b) ≃ Z b) /- warning: equiv.Pi_congr' -> Equiv.piCongr' is a dubious translation: lean 3 declaration is forall {α : Sort.{u1}} {β : Sort.{u2}} {W : α -> Sort.{u3}} {Z : β -> Sort.{u4}} (h₁ : Equiv.{u1, u2} α β), (forall (b : β), Equiv.{u3, u4} (W (coeFn.{max 1 (imax u2 u1) (imax u1 u2), imax u2 u1} (Equiv.{u2, u1} β α) (fun (_x : Equiv.{u2, u1} β α) => β -> α) (Equiv.hasCoeToFun.{u2, u1} β α) (Equiv.symm.{u1, u2} α β h₁) b)) (Z b)) -> (Equiv.{imax u1 u3, imax u2 u4} (forall (a : α), W a) (forall (b : β), Z b)) but is expected to have type forall {α : Sort.{u3}} {β : Sort.{u4}} {W : α -> Sort.{u1}} {Z : β -> Sort.{u2}} (h₁ : Equiv.{u3, u4} α β), (forall (b : β), Equiv.{u1, u2} (W (FunLike.coe.{max (max 1 u3) u4, u4, u3} (Equiv.{u4, u3} β α) β (fun (_x : β) => (fun ([email protected]._hyg.808 : β) => α) _x) (Equiv.instFunLikeEquiv.{u4, u3} β α) (Equiv.symm.{u3, u4} α β h₁) b)) (Z b)) -> (Equiv.{imax u3 u1, imax u4 u2} (forall (a : α), W a) (forall (b : β), Z b)) Case conversion may be inaccurate. Consider using '#align equiv.Pi_congr' Equiv.piCongr'ₓ'. -/ /-- Transport dependent functions through an equivalence of the base spaces and a family of equivalences of the matching fibres. -/ def piCongr' : (∀ a, W a) ≃ ∀ b, Z b := (piCongr h₁.symm fun b => (h₂ b).symm).symm #align equiv.Pi_congr' Equiv.piCongr' /- warning: equiv.coe_Pi_congr' -> Equiv.coe_piCongr' is a dubious translation: lean 3 declaration is forall {α : Sort.{u1}} {β : Sort.{u2}} {W : α -> Sort.{u3}} {Z : β -> Sort.{u4}} (h₁ : Equiv.{u1, u2} α β) (h₂ : forall (b : β), Equiv.{u3, u4} (W (coeFn.{max 1 (imax u2 u1) (imax u1 u2), imax u2 u1} (Equiv.{u2, u1} β α) (fun (_x : Equiv.{u2, u1} β α) => β -> α) (Equiv.hasCoeToFun.{u2, u1} β α) (Equiv.symm.{u1, u2} α β h₁) b)) (Z b)), Eq.{imax (imax u1 u3) u2 u4} ((fun (_x : Equiv.{imax u1 u3, imax u2 u4} (forall (a : α), W a) (forall (b : β), (fun (b : β) => Z b) b)) => (forall (a : α), W a) -> (forall (b : β), (fun (b : β) => Z b) b)) (Equiv.piCongr'.{u1, u2, u3, u4} α β W (fun (b : β) => Z b) h₁ h₂)) (coeFn.{max 1 (imax (imax u1 u3) u2 u4) (imax (imax u2 u4) u1 u3), imax (imax u1 u3) u2 u4} (Equiv.{imax u1 u3, imax u2 u4} (forall (a : α), W a) (forall (b : β), (fun (b : β) => Z b) b)) (fun (_x : Equiv.{imax u1 u3, imax u2 u4} (forall (a : α), W a) (forall (b : β), (fun (b : β) => Z b) b)) => (forall (a : α), W a) -> (forall (b : β), (fun (b : β) => Z b) b)) (Equiv.hasCoeToFun.{imax u1 u3, imax u2 u4} (forall (a : α), W a) (forall (b : β), (fun (b : β) => Z b) b)) (Equiv.piCongr'.{u1, u2, u3, u4} α β W (fun (b : β) => Z b) h₁ h₂)) (fun (f : forall (a : α), W a) (b : β) => coeFn.{max 1 (imax u3 u4) (imax u4 u3), imax u3 u4} (Equiv.{u3, u4} (W (coeFn.{max 1 (imax u2 u1) (imax u1 u2), imax u2 u1} (Equiv.{u2, u1} β α) (fun (_x : Equiv.{u2, u1} β α) => β -> α) (Equiv.hasCoeToFun.{u2, u1} β α) (Equiv.symm.{u1, u2} α β h₁) b)) (Z b)) (fun (_x : Equiv.{u3, u4} (W (coeFn.{max 1 (imax u2 u1) (imax u1 u2), imax u2 u1} (Equiv.{u2, u1} β α) (fun (_x : Equiv.{u2, u1} β α) => β -> α) (Equiv.hasCoeToFun.{u2, u1} β α) (Equiv.symm.{u1, u2} α β h₁) b)) (Z b)) => (W (coeFn.{max 1 (imax u2 u1) (imax u1 u2), imax u2 u1} (Equiv.{u2, u1} β α) (fun (_x : Equiv.{u2, u1} β α) => β -> α) (Equiv.hasCoeToFun.{u2, u1} β α) (Equiv.symm.{u1, u2} α β h₁) b)) -> (Z b)) (Equiv.hasCoeToFun.{u3, u4} (W (coeFn.{max 1 (imax u2 u1) (imax u1 u2), imax u2 u1} (Equiv.{u2, u1} β α) (fun (_x : Equiv.{u2, u1} β α) => β -> α) (Equiv.hasCoeToFun.{u2, u1} β α) (Equiv.symm.{u1, u2} α β h₁) b)) (Z b)) (h₂ b) (f (coeFn.{max 1 (imax u2 u1) (imax u1 u2), imax u2 u1} (Equiv.{u2, u1} β α) (fun (_x : Equiv.{u2, u1} β α) => β -> α) (Equiv.hasCoeToFun.{u2, u1} β α) (Equiv.symm.{u1, u2} α β h₁) b))) but is expected to have type forall {α : Sort.{u2}} {β : Sort.{u1}} {W : α -> Sort.{u3}} {Z : β -> Sort.{u4}} (h₁ : Equiv.{u2, u1} α β) (h₂ : forall (b : β), Equiv.{u3, u4} (W (FunLike.coe.{max (max 1 u2) u1, u1, u2} (Equiv.{u1, u2} β α) β (fun (_x : β) => (fun ([email protected]._hyg.808 : β) => α) _x) (Equiv.instFunLikeEquiv.{u1, u2} β α) (Equiv.symm.{u2, u1} α β h₁) b)) (Z b)), Eq.{imax (imax u2 u3) u1 u4} (forall (a : forall (a : α), W a), (fun ([email protected]._hyg.808 : forall (a : α), W a) => forall (b : β), Z b) a) (FunLike.coe.{max (max 1 (imax u2 u3)) (imax u1 u4), imax u2 u3, imax u1 u4} (Equiv.{imax u2 u3, imax u1 u4} (forall (a : α), W a) (forall (b : β), Z b)) (forall (a : α), W a) (fun (_x : forall (a : α), W a) => (fun ([email protected]._hyg.808 : forall (a : α), W a) => forall (b : β), Z b) _x) (Equiv.instFunLikeEquiv.{imax u2 u3, imax u1 u4} (forall (a : α), W a) (forall (b : β), Z b)) (Equiv.piCongr'.{u3, u4, u2, u1} α β W (fun (b : β) => Z b) h₁ h₂)) (fun (f : forall (a : α), W a) (b : β) => FunLike.coe.{max (max 1 u3) u4, u3, u4} (Equiv.{u3, u4} (W (FunLike.coe.{max (max 1 u2) u1, u1, u2} (Equiv.{u1, u2} β α) β (fun (a : β) => (fun ([email protected]._hyg.808 : β) => α) a) (Equiv.instFunLikeEquiv.{u1, u2} β α) (Equiv.symm.{u2, u1} α β h₁) b)) (Z b)) (W (FunLike.coe.{max (max 1 u2) u1, u1, u2} (Equiv.{u1, u2} β α) β (fun (a : β) => (fun ([email protected]._hyg.808 : β) => α) a) (Equiv.instFunLikeEquiv.{u1, u2} β α) (Equiv.symm.{u2, u1} α β h₁) b)) (fun (_x : W (FunLike.coe.{max (max 1 u2) u1, u1, u2} (Equiv.{u1, u2} β α) β (fun (a : β) => (fun ([email protected]._hyg.808 : β) => α) a) (Equiv.instFunLikeEquiv.{u1, u2} β α) (Equiv.symm.{u2, u1} α β h₁) b)) => (fun ([email protected]._hyg.808 : W (FunLike.coe.{max (max 1 u2) u1, u1, u2} (Equiv.{u1, u2} β α) β (fun (a : β) => (fun ([email protected]._hyg.808 : β) => α) a) (Equiv.instFunLikeEquiv.{u1, u2} β α) (Equiv.symm.{u2, u1} α β h₁) b)) => Z b) _x) (Equiv.instFunLikeEquiv.{u3, u4} (W (FunLike.coe.{max (max 1 u2) u1, u1, u2} (Equiv.{u1, u2} β α) β (fun (_x : β) => (fun ([email protected]._hyg.808 : β) => α) _x) (Equiv.instFunLikeEquiv.{u1, u2} β α) (Equiv.symm.{u2, u1} α β h₁) b)) (Z b)) (h₂ b) (f (FunLike.coe.{max (max 1 u2) u1, u1, u2} (Equiv.{u1, u2} β α) β (fun (_x : β) => (fun ([email protected]._hyg.808 : β) => α) _x) (Equiv.instFunLikeEquiv.{u1, u2} β α) (Equiv.symm.{u2, u1} α β h₁) b))) Case conversion may be inaccurate. Consider using '#align equiv.coe_Pi_congr' Equiv.coe_piCongr'ₓ'. -/ @[simp] theorem coe_piCongr' : (h₁.piCongr' h₂ : (∀ a, W a) → ∀ b, Z b) = fun f b => h₂ b <| f <| h₁.symm b := rfl #align equiv.coe_Pi_congr' Equiv.coe_piCongr' #print Equiv.piCongr'_apply /- theorem piCongr'_apply (f : ∀ a, W a) : h₁.piCongr' h₂ f = fun b => h₂ b <| f <| h₁.symm b := rfl #align equiv.Pi_congr'_apply Equiv.piCongr'_apply -/ /- warning: equiv.Pi_congr'_symm_apply_symm_apply -> Equiv.piCongr'_symm_apply_symm_apply is a dubious translation: lean 3 declaration is forall {α : Sort.{u1}} {β : Sort.{u2}} {W : α -> Sort.{u3}} {Z : β -> Sort.{u4}} (h₁ : Equiv.{u1, u2} α β) (h₂ : forall (b : β), Equiv.{u3, u4} (W (coeFn.{max 1 (imax u2 u1) (imax u1 u2), imax u2 u1} (Equiv.{u2, u1} β α) (fun (_x : Equiv.{u2, u1} β α) => β -> α) (Equiv.hasCoeToFun.{u2, u1} β α) (Equiv.symm.{u1, u2} α β h₁) b)) (Z b)) (f : forall (b : β), Z b) (b : β), Eq.{u3} (W (coeFn.{max 1 (imax u2 u1) (imax u1 u2), imax u2 u1} (Equiv.{u2, u1} β α) (fun (_x : Equiv.{u2, u1} β α) => β -> α) (Equiv.hasCoeToFun.{u2, u1} β α) (Equiv.symm.{u1, u2} α β h₁) b)) (coeFn.{max 1 (imax (imax u2 u4) u1 u3) (imax (imax u1 u3) u2 u4), imax (imax u2 u4) u1 u3} (Equiv.{imax u2 u4, imax u1 u3} (forall (b : β), Z b) (forall (a : α), W a)) (fun (_x : Equiv.{imax u2 u4, imax u1 u3} (forall (b : β), Z b) (forall (a : α), W a)) => (forall (b : β), Z b) -> (forall (a : α), W a)) (Equiv.hasCoeToFun.{imax u2 u4, imax u1 u3} (forall (b : β), Z b) (forall (a : α), W a)) (Equiv.symm.{imax u1 u3, imax u2 u4} (forall (a : α), W a) (forall (b : β), Z b) (Equiv.piCongr'.{u1, u2, u3, u4} α β W (fun (b : β) => Z b) h₁ h₂)) f (coeFn.{max 1 (imax u2 u1) (imax u1 u2), imax u2 u1} (Equiv.{u2, u1} β α) (fun (_x : Equiv.{u2, u1} β α) => β -> α) (Equiv.hasCoeToFun.{u2, u1} β α) (Equiv.symm.{u1, u2} α β h₁) b)) (coeFn.{max 1 (imax u4 u3) (imax u3 u4), imax u4 u3} (Equiv.{u4, u3} (Z b) (W (coeFn.{max 1 (imax u2 u1) (imax u1 u2), imax u2 u1} (Equiv.{u2, u1} β α) (fun (_x : Equiv.{u2, u1} β α) => β -> α) (Equiv.hasCoeToFun.{u2, u1} β α) (Equiv.symm.{u1, u2} α β h₁) b))) (fun (_x : Equiv.{u4, u3} (Z b) (W (coeFn.{max 1 (imax u2 u1) (imax u1 u2), imax u2 u1} (Equiv.{u2, u1} β α) (fun (_x : Equiv.{u2, u1} β α) => β -> α) (Equiv.hasCoeToFun.{u2, u1} β α) (Equiv.symm.{u1, u2} α β h₁) b))) => (Z b) -> (W (coeFn.{max 1 (imax u2 u1) (imax u1 u2), imax u2 u1} (Equiv.{u2, u1} β α) (fun (_x : Equiv.{u2, u1} β α) => β -> α) (Equiv.hasCoeToFun.{u2, u1} β α) (Equiv.symm.{u1, u2} α β h₁) b))) (Equiv.hasCoeToFun.{u4, u3} (Z b) (W (coeFn.{max 1 (imax u2 u1) (imax u1 u2), imax u2 u1} (Equiv.{u2, u1} β α) (fun (_x : Equiv.{u2, u1} β α) => β -> α) (Equiv.hasCoeToFun.{u2, u1} β α) (Equiv.symm.{u1, u2} α β h₁) b))) (Equiv.symm.{u3, u4} (W (coeFn.{max 1 (imax u2 u1) (imax u1 u2), imax u2 u1} (Equiv.{u2, u1} β α) (fun (_x : Equiv.{u2, u1} β α) => β -> α) (Equiv.hasCoeToFun.{u2, u1} β α) (Equiv.symm.{u1, u2} α β h₁) b)) (Z b) (h₂ b)) (f b)) but is expected to have type forall {α : Sort.{u2}} {β : Sort.{u1}} {W : α -> Sort.{u3}} {Z : β -> Sort.{u4}} (h₁ : Equiv.{u2, u1} α β) (h₂ : forall (b : β), Equiv.{u3, u4} (W (FunLike.coe.{max (max 1 u2) u1, u1, u2} (Equiv.{u1, u2} β α) β (fun (_x : β) => (fun ([email protected]._hyg.808 : β) => α) _x) (Equiv.instFunLikeEquiv.{u1, u2} β α) (Equiv.symm.{u2, u1} α β h₁) b)) (Z b)) (f : forall (b : β), Z b) (b : β), Eq.{u3} (W (FunLike.coe.{max (max 1 u2) u1, u1, u2} (Equiv.{u1, u2} β α) β (fun (_x : β) => (fun ([email protected]._hyg.808 : β) => α) _x) (Equiv.instFunLikeEquiv.{u1, u2} β α) (Equiv.symm.{u2, u1} α β h₁) b)) (FunLike.coe.{max (max 1 (imax u2 u3)) (imax u1 u4), imax u1 u4, imax u2 u3} (Equiv.{imax u1 u4, imax u2 u3} (forall (b : β), Z b) (forall (a : α), W a)) (forall (b : β), Z b) (fun (_x : forall (b : β), Z b) => (fun ([email protected]._hyg.808 : forall (b : β), Z b) => forall (a : α), W a) _x) (Equiv.instFunLikeEquiv.{imax u1 u4, imax u2 u3} (forall (b : β), Z b) (forall (a : α), W a)) (Equiv.symm.{imax u2 u3, imax u1 u4} (forall (a : α), W a) (forall (b : β), Z b) (Equiv.piCongr'.{u3, u4, u2, u1} α β W (fun (b : β) => Z b) h₁ h₂)) f (FunLike.coe.{max (max 1 u2) u1, u1, u2} (Equiv.{u1, u2} β α) β (fun (_x : β) => (fun ([email protected]._hyg.808 : β) => α) _x) (Equiv.instFunLikeEquiv.{u1, u2} β α) (Equiv.symm.{u2, u1} α β h₁) b)) (FunLike.coe.{max (max 1 u3) u4, u4, u3} (Equiv.{u4, u3} (Z b) (W (FunLike.coe.{max (max 1 u2) u1, u1, u2} (Equiv.{u1, u2} β α) β (fun (a : β) => (fun ([email protected]._hyg.808 : β) => α) a) (Equiv.instFunLikeEquiv.{u1, u2} β α) (Equiv.symm.{u2, u1} α β h₁) b))) (Z b) (fun (_x : Z b) => (fun ([email protected]._hyg.808 : Z b) => W (FunLike.coe.{max (max 1 u2) u1, u1, u2} (Equiv.{u1, u2} β α) β (fun (a : β) => (fun ([email protected]._hyg.808 : β) => α) a) (Equiv.instFunLikeEquiv.{u1, u2} β α) (Equiv.symm.{u2, u1} α β h₁) b)) _x) (Equiv.instFunLikeEquiv.{u4, u3} (Z b) (W (FunLike.coe.{max (max 1 u2) u1, u1, u2} (Equiv.{u1, u2} β α) β (fun (_x : β) => (fun ([email protected]._hyg.808 : β) => α) _x) (Equiv.instFunLikeEquiv.{u1, u2} β α) (Equiv.symm.{u2, u1} α β h₁) b))) (Equiv.symm.{u3, u4} (W (FunLike.coe.{max (max 1 u2) u1, u1, u2} (Equiv.{u1, u2} β α) β (fun (_x : β) => (fun ([email protected]._hyg.808 : β) => α) _x) (Equiv.instFunLikeEquiv.{u1, u2} β α) (Equiv.symm.{u2, u1} α β h₁) b)) (Z b) (h₂ b)) (f b)) Case conversion may be inaccurate. Consider using '#align equiv.Pi_congr'_symm_apply_symm_apply Equiv.piCongr'_symm_apply_symm_applyₓ'. -/ @[simp] theorem piCongr'_symm_apply_symm_apply (f : ∀ b, Z b) (b : β) : (h₁.piCongr' h₂).symm f (h₁.symm b) = (h₂ b).symm (f b) := by change cast _ ((h₂ (h₁ (h₁.symm b))).symm (f (h₁ (h₁.symm b)))) = (h₂ b).symm (f b) generalize_proofs hWb revert hWb generalize hb : h₁ (h₁.symm b) = b' rw [h₁.apply_symm_apply b] at hb subst hb simp #align equiv.Pi_congr'_symm_apply_symm_apply Equiv.piCongr'_symm_apply_symm_apply end section BinaryOp variable {α₁ β₁ : Type _} (e : α₁ ≃ β₁) (f : α₁ → α₁ → α₁) /- warning: equiv.semiconj_conj -> Equiv.semiconj_conj is a dubious translation: lean 3 declaration is forall {α₁ : Type.{u1}} {β₁ : Type.{u2}} (e : Equiv.{succ u1, succ u2} α₁ β₁) (f : α₁ -> α₁), Function.Semiconj.{u1, u2} α₁ β₁ (coeFn.{max 1 (max (succ u1) (succ u2)) (succ u2) (succ u1), max (succ u1) (succ u2)} (Equiv.{succ u1, succ u2} α₁ β₁) (fun (_x : Equiv.{succ u1, succ u2} α₁ β₁) => α₁ -> β₁) (Equiv.hasCoeToFun.{succ u1, succ u2} α₁ β₁) e) f (coeFn.{max 1 (max (succ u1) (succ u2)) (succ u2) (succ u1), max (succ u1) (succ u2)} (Equiv.{succ u1, succ u2} (α₁ -> α₁) (β₁ -> β₁)) (fun (_x : Equiv.{succ u1, succ u2} (α₁ -> α₁) (β₁ -> β₁)) => (α₁ -> α₁) -> β₁ -> β₁) (Equiv.hasCoeToFun.{succ u1, succ u2} (α₁ -> α₁) (β₁ -> β₁)) (Equiv.conj.{succ u1, succ u2} α₁ β₁ e) f) but is expected to have type forall {α₁ : Type.{u2}} {β₁ : Type.{u1}} (e : Equiv.{succ u2, succ u1} α₁ β₁) (f : α₁ -> α₁), Function.Semiconj.{u2, u1} α₁ β₁ (FunLike.coe.{max (succ u1) (succ u2), succ u2, succ u1} (Equiv.{succ u2, succ u1} α₁ β₁) α₁ (fun (_x : α₁) => (fun ([email protected]._hyg.808 : α₁) => β₁) _x) (Equiv.instFunLikeEquiv.{succ u2, succ u1} α₁ β₁) e) f (FunLike.coe.{max (succ u1) (succ u2), succ u2, succ u1} (Equiv.{succ u2, succ u1} (α₁ -> α₁) (β₁ -> β₁)) (α₁ -> α₁) (fun (_x : α₁ -> α₁) => (fun ([email protected]._hyg.808 : α₁ -> α₁) => β₁ -> β₁) _x) (Equiv.instFunLikeEquiv.{succ u2, succ u1} (α₁ -> α₁) (β₁ -> β₁)) (Equiv.conj.{succ u2, succ u1} α₁ β₁ e) f) Case conversion may be inaccurate. Consider using '#align equiv.semiconj_conj Equiv.semiconj_conjₓ'. -/ theorem semiconj_conj (f : α₁ → α₁) : Semiconj e f (e.conj f) := fun x => by simp #align equiv.semiconj_conj Equiv.semiconj_conj /- warning: equiv.semiconj₂_conj -> Equiv.semiconj₂_conj is a dubious translation: lean 3 declaration is forall {α₁ : Type.{u1}} {β₁ : Type.{u2}} (e : Equiv.{succ u1, succ u2} α₁ β₁) (f : α₁ -> α₁ -> α₁), Function.Semiconj₂.{u1, u2} α₁ β₁ (coeFn.{max 1 (max (succ u1) (succ u2)) (succ u2) (succ u1), max (succ u1) (succ u2)} (Equiv.{succ u1, succ u2} α₁ β₁) (fun (_x : Equiv.{succ u1, succ u2} α₁ β₁) => α₁ -> β₁) (Equiv.hasCoeToFun.{succ u1, succ u2} α₁ β₁) e) f (coeFn.{max 1 (max (succ u1) (succ u2)) (succ u2) (succ u1), max (succ u1) (succ u2)} (Equiv.{succ u1, succ u2} (α₁ -> α₁ -> α₁) (β₁ -> β₁ -> β₁)) (fun (_x : Equiv.{succ u1, succ u2} (α₁ -> α₁ -> α₁) (β₁ -> β₁ -> β₁)) => (α₁ -> α₁ -> α₁) -> β₁ -> β₁ -> β₁) (Equiv.hasCoeToFun.{succ u1, succ u2} (α₁ -> α₁ -> α₁) (β₁ -> β₁ -> β₁)) (Equiv.arrowCongr.{succ u1, succ u1, succ u2, succ u2} α₁ (α₁ -> α₁) β₁ (β₁ -> β₁) e (Equiv.conj.{succ u1, succ u2} α₁ β₁ e)) f) but is expected to have type forall {α₁ : Type.{u2}} {β₁ : Type.{u1}} (e : Equiv.{succ u2, succ u1} α₁ β₁) (f : α₁ -> α₁ -> α₁), Function.Semiconj₂.{u2, u1} α₁ β₁ (FunLike.coe.{max (succ u1) (succ u2), succ u2, succ u1} (Equiv.{succ u2, succ u1} α₁ β₁) α₁ (fun (_x : α₁) => (fun ([email protected]._hyg.808 : α₁) => β₁) _x) (Equiv.instFunLikeEquiv.{succ u2, succ u1} α₁ β₁) e) f (FunLike.coe.{max (succ u1) (succ u2), succ u2, succ u1} (Equiv.{succ u2, succ u1} (α₁ -> α₁ -> α₁) (β₁ -> β₁ -> β₁)) (α₁ -> α₁ -> α₁) (fun (_x : α₁ -> α₁ -> α₁) => (fun ([email protected]._hyg.808 : α₁ -> α₁ -> α₁) => β₁ -> β₁ -> β₁) _x) (Equiv.instFunLikeEquiv.{succ u2, succ u1} (α₁ -> α₁ -> α₁) (β₁ -> β₁ -> β₁)) (Equiv.arrowCongr.{succ u2, succ u2, succ u1, succ u1} α₁ (α₁ -> α₁) β₁ (β₁ -> β₁) e (Equiv.conj.{succ u2, succ u1} α₁ β₁ e)) f) Case conversion may be inaccurate. Consider using '#align equiv.semiconj₂_conj Equiv.semiconj₂_conjₓ'. -/ theorem semiconj₂_conj : Semiconj₂ e f (e.arrowCongr e.conj f) := fun x y => by simp #align equiv.semiconj₂_conj Equiv.semiconj₂_conj instance [IsAssociative α₁ f] : IsAssociative β₁ (e.arrowCongr (e.arrowCongr e) f) := (e.semiconj₂_conj f).isAssociative_right e.Surjective instance [IsIdempotent α₁ f] : IsIdempotent β₁ (e.arrowCongr (e.arrowCongr e) f) := (e.semiconj₂_conj f).isIdempotent_right e.Surjective instance [IsLeftCancel α₁ f] : IsLeftCancel β₁ (e.arrowCongr (e.arrowCongr e) f) := ⟨e.Surjective.forall₃.2 fun x y z => by simpa using @IsLeftCancel.left_cancel _ f _ x y z⟩ instance [IsRightCancel α₁ f] : IsRightCancel β₁ (e.arrowCongr (e.arrowCongr e) f) := ⟨e.Surjective.forall₃.2 fun x y z => by simpa using @IsRightCancel.right_cancel _ f _ x y z⟩ end BinaryOp end Equiv /- warning: function.injective.swap_apply -> Function.Injective.swap_apply is a dubious translation: lean 3 declaration is forall {α : Sort.{u1}} {β : Sort.{u2}} [_inst_1 : DecidableEq.{u1} α] [_inst_2 : DecidableEq.{u2} β] {f : α -> β}, (Function.Injective.{u1, u2} α β f) -> (forall (x : α) (y : α) (z : α), Eq.{u2} β (coeFn.{max 1 u2, u2} (Equiv.Perm.{u2} β) (fun (_x : Equiv.{u2, u2} β β) => β -> β) (Equiv.hasCoeToFun.{u2, u2} β β) (Equiv.swap.{u2} β (fun (a : β) (b : β) => _inst_2 a b) (f x) (f y)) (f z)) (f (coeFn.{max 1 u1, u1} (Equiv.Perm.{u1} α) (fun (_x : Equiv.{u1, u1} α α) => α -> α) (Equiv.hasCoeToFun.{u1, u1} α α) (Equiv.swap.{u1} α (fun (a : α) (b : α) => _inst_1 a b) x y) z))) but is expected to have type forall {α : Sort.{u2}} {β : Sort.{u1}} [_inst_1 : DecidableEq.{u2} α] [_inst_2 : DecidableEq.{u1} β] {f : α -> β}, (Function.Injective.{u2, u1} α β f) -> (forall (x : α) (y : α) (z : α), Eq.{u1} ((fun ([email protected]._hyg.808 : β) => β) (f z)) (FunLike.coe.{max 1 u1, u1, u1} (Equiv.Perm.{u1} β) β (fun (_x : β) => (fun ([email protected]._hyg.808 : β) => β) _x) (Equiv.instFunLikeEquiv.{u1, u1} β β) (Equiv.swap.{u1} β (fun (a : β) (b : β) => _inst_2 a b) (f x) (f y)) (f z)) (f (FunLike.coe.{max 1 u2, u2, u2} (Equiv.Perm.{u2} α) α (fun (_x : α) => (fun ([email protected]._hyg.808 : α) => α) _x) (Equiv.instFunLikeEquiv.{u2, u2} α α) (Equiv.swap.{u2} α (fun (a : α) (b : α) => _inst_1 a b) x y) z))) Case conversion may be inaccurate. Consider using '#align function.injective.swap_apply Function.Injective.swap_applyₓ'. -/ theorem Function.Injective.swap_apply [DecidableEq α] [DecidableEq β] {f : α → β} (hf : Function.Injective f) (x y z : α) : Equiv.swap (f x) (f y) (f z) = f (Equiv.swap x y z) := by by_cases hx : z = x; · simp [hx] by_cases hy : z = y; · simp [hy] rw [Equiv.swap_apply_of_ne_of_ne hx hy, Equiv.swap_apply_of_ne_of_ne (hf.ne hx) (hf.ne hy)] #align function.injective.swap_apply Function.Injective.swap_apply /- warning: function.injective.swap_comp -> Function.Injective.swap_comp is a dubious translation: lean 3 declaration is forall {α : Sort.{u1}} {β : Sort.{u2}} [_inst_1 : DecidableEq.{u1} α] [_inst_2 : DecidableEq.{u2} β] {f : α -> β}, (Function.Injective.{u1, u2} α β f) -> (forall (x : α) (y : α), Eq.{imax u1 u2} (α -> β) (Function.comp.{u1, u2, u2} α β β (coeFn.{max 1 u2, u2} (Equiv.Perm.{u2} β) (fun (_x : Equiv.{u2, u2} β β) => β -> β) (Equiv.hasCoeToFun.{u2, u2} β β) (Equiv.swap.{u2} β (fun (a : β) (b : β) => _inst_2 a b) (f x) (f y))) f) (Function.comp.{u1, u1, u2} α α β f (coeFn.{max 1 u1, u1} (Equiv.Perm.{u1} α) (fun (_x : Equiv.{u1, u1} α α) => α -> α) (Equiv.hasCoeToFun.{u1, u1} α α) (Equiv.swap.{u1} α (fun (a : α) (b : α) => _inst_1 a b) x y)))) but is expected to have type forall {α : Sort.{u2}} {β : Sort.{u1}} [_inst_1 : DecidableEq.{u2} α] [_inst_2 : DecidableEq.{u1} β] {f : α -> β}, (Function.Injective.{u2, u1} α β f) -> (forall (x : α) (y : α), Eq.{imax u2 u1} (α -> β) (Function.comp.{u2, u1, u1} α β β (FunLike.coe.{max 1 u1, u1, u1} (Equiv.Perm.{u1} β) β (fun (_x : β) => (fun ([email protected]._hyg.808 : β) => β) _x) (Equiv.instFunLikeEquiv.{u1, u1} β β) (Equiv.swap.{u1} β (fun (a : β) (b : β) => _inst_2 a b) (f x) (f y))) f) (Function.comp.{u2, u2, u1} α α β f (FunLike.coe.{max 1 u2, u2, u2} (Equiv.Perm.{u2} α) α (fun (_x : α) => (fun ([email protected]._hyg.808 : α) => α) _x) (Equiv.instFunLikeEquiv.{u2, u2} α α) (Equiv.swap.{u2} α (fun (a : α) (b : α) => _inst_1 a b) x y)))) Case conversion may be inaccurate. Consider using '#align function.injective.swap_comp Function.Injective.swap_compₓ'. -/ theorem Function.Injective.swap_comp [DecidableEq α] [DecidableEq β] {f : α → β} (hf : Function.Injective f) (x y : α) : Equiv.swap (f x) (f y) ∘ f = f ∘ Equiv.swap x y := funext fun z => hf.swap_apply _ _ _ #align function.injective.swap_comp Function.Injective.swap_comp #print subsingletonProdSelfEquiv /- /-- If `α` is a subsingleton, then it is equivalent to `α × α`. -/ def subsingletonProdSelfEquiv {α : Type _} [Subsingleton α] : α × α ≃ α where toFun p := p.1 invFun a := (a, a) left_inv p := Subsingleton.elim _ _ right_inv p := Subsingleton.elim _ _ #align subsingleton_prod_self_equiv subsingletonProdSelfEquiv -/ #print equivOfSubsingletonOfSubsingleton /- /-- To give an equivalence between two subsingleton types, it is sufficient to give any two functions between them. -/ def equivOfSubsingletonOfSubsingleton [Subsingleton α] [Subsingleton β] (f : α → β) (g : β → α) : α ≃ β where toFun := f invFun := g left_inv _ := Subsingleton.elim _ _ right_inv _ := Subsingleton.elim _ _ #align equiv_of_subsingleton_of_subsingleton equivOfSubsingletonOfSubsingleton -/ /- warning: equiv.punit_of_nonempty_of_subsingleton -> Equiv.punitOfNonemptyOfSubsingleton is a dubious translation: lean 3 declaration is forall {α : Sort.{u2}} [h : Nonempty.{u2} α] [_inst_1 : Subsingleton.{u2} α], Equiv.{u2, u1} α PUnit.{u1} but is expected to have type forall {α : Sort.{u1}} [h : Nonempty.{u1} α] [_inst_1 : Subsingleton.{u1} α], Equiv.{u1, u2} α PUnit.{u2} Case conversion may be inaccurate. Consider using '#align equiv.punit_of_nonempty_of_subsingleton Equiv.punitOfNonemptyOfSubsingletonₓ'. -/ /-- A nonempty subsingleton type is (noncomputably) equivalent to `punit`. -/ noncomputable def Equiv.punitOfNonemptyOfSubsingleton {α : Sort _} [h : Nonempty α] [Subsingleton α] : α ≃ PUnit.{v} := equivOfSubsingletonOfSubsingleton (fun _ => PUnit.unit) fun _ => h.some #align equiv.punit_of_nonempty_of_subsingleton Equiv.punitOfNonemptyOfSubsingleton #print uniqueUniqueEquiv /- /-- `unique (unique α)` is equivalent to `unique α`. -/ def uniqueUniqueEquiv : Unique (Unique α) ≃ Unique α := equivOfSubsingletonOfSubsingleton (fun h => h.default) fun h => { default := h uniq := fun _ => Subsingleton.elim _ _ } #align unique_unique_equiv uniqueUniqueEquiv -/ namespace Function /- warning: function.update_comp_equiv -> Function.update_comp_equiv is a dubious translation: lean 3 declaration is forall {α : Sort.{u1}} {β : Sort.{u2}} {α' : Sort.{u3}} [_inst_1 : DecidableEq.{u3} α'] [_inst_2 : DecidableEq.{u1} α] (f : α -> β) (g : Equiv.{u3, u1} α' α) (a : α) (v : β), Eq.{imax u3 u2} (α' -> β) (Function.comp.{u3, u1, u2} α' α β (Function.update.{u1, u2} α (fun (ᾰ : α) => β) (fun (a : α) (b : α) => _inst_2 a b) f a v) (coeFn.{max 1 (imax u3 u1) (imax u1 u3), imax u3 u1} (Equiv.{u3, u1} α' α) (fun (_x : Equiv.{u3, u1} α' α) => α' -> α) (Equiv.hasCoeToFun.{u3, u1} α' α) g)) (Function.update.{u3, u2} α' (fun (ᾰ : α') => β) (fun (a : α') (b : α') => _inst_1 a b) (Function.comp.{u3, u1, u2} α' α β f (coeFn.{max 1 (imax u3 u1) (imax u1 u3), imax u3 u1} (Equiv.{u3, u1} α' α) (fun (_x : Equiv.{u3, u1} α' α) => α' -> α) (Equiv.hasCoeToFun.{u3, u1} α' α) g)) (coeFn.{max 1 (imax u1 u3) (imax u3 u1), imax u1 u3} (Equiv.{u1, u3} α α') (fun (_x : Equiv.{u1, u3} α α') => α -> α') (Equiv.hasCoeToFun.{u1, u3} α α') (Equiv.symm.{u3, u1} α' α g) a) v) but is expected to have type forall {α : Sort.{u3}} {β : Sort.{u2}} {α' : Sort.{u1}} [_inst_1 : DecidableEq.{u3} α] [_inst_2 : DecidableEq.{u2} β] (f : β -> α') (g : Equiv.{u3, u2} α β) (a : β) (v : α'), Eq.{imax u3 u1} (α -> α') (Function.comp.{u3, u2, u1} α β α' (Function.update.{u2, u1} β (fun (ᾰ : β) => α') (fun (a : β) (b : β) => _inst_2 a b) f a v) (FunLike.coe.{max (max 1 u3) u2, u3, u2} (Equiv.{u3, u2} α β) α (fun (_x : α) => (fun ([email protected]._hyg.808 : α) => β) _x) (Equiv.instFunLikeEquiv.{u3, u2} α β) g)) (Function.update.{u3, u1} α (fun (ᾰ : α) => α') (fun (a : α) (b : α) => _inst_1 a b) (Function.comp.{u3, u2, u1} α β α' f (FunLike.coe.{max (max 1 u3) u2, u3, u2} (Equiv.{u3, u2} α β) α (fun (_x : α) => (fun ([email protected]._hyg.808 : α) => β) _x) (Equiv.instFunLikeEquiv.{u3, u2} α β) g)) (FunLike.coe.{max (max 1 u3) u2, u2, u3} (Equiv.{u2, u3} β α) β (fun (_x : β) => (fun ([email protected]._hyg.808 : β) => α) _x) (Equiv.instFunLikeEquiv.{u2, u3} β α) (Equiv.symm.{u3, u2} α β g) a) v) Case conversion may be inaccurate. Consider using '#align function.update_comp_equiv Function.update_comp_equivₓ'. -/ theorem update_comp_equiv {α β α' : Sort _} [DecidableEq α'] [DecidableEq α] (f : α → β) (g : α' ≃ α) (a : α) (v : β) : update f a v ∘ g = update (f ∘ g) (g.symm a) v := by rw [← update_comp_eq_of_injective _ g.injective, g.apply_symm_apply] #align function.update_comp_equiv Function.update_comp_equiv /- warning: function.update_apply_equiv_apply -> Function.update_apply_equiv_apply is a dubious translation: lean 3 declaration is forall {α : Sort.{u1}} {β : Sort.{u2}} {α' : Sort.{u3}} [_inst_1 : DecidableEq.{u3} α'] [_inst_2 : DecidableEq.{u1} α] (f : α -> β) (g : Equiv.{u3, u1} α' α) (a : α) (v : β) (a' : α'), Eq.{u2} β (Function.update.{u1, u2} α (fun (ᾰ : α) => β) (fun (a : α) (b : α) => _inst_2 a b) f a v (coeFn.{max 1 (imax u3 u1) (imax u1 u3), imax u3 u1} (Equiv.{u3, u1} α' α) (fun (_x : Equiv.{u3, u1} α' α) => α' -> α) (Equiv.hasCoeToFun.{u3, u1} α' α) g a')) (Function.update.{u3, u2} α' (fun (ᾰ : α') => β) (fun (a : α') (b : α') => _inst_1 a b) (Function.comp.{u3, u1, u2} α' α β f (coeFn.{max 1 (imax u3 u1) (imax u1 u3), imax u3 u1} (Equiv.{u3, u1} α' α) (fun (_x : Equiv.{u3, u1} α' α) => α' -> α) (Equiv.hasCoeToFun.{u3, u1} α' α) g)) (coeFn.{max 1 (imax u1 u3) (imax u3 u1), imax u1 u3} (Equiv.{u1, u3} α α') (fun (_x : Equiv.{u1, u3} α α') => α -> α') (Equiv.hasCoeToFun.{u1, u3} α α') (Equiv.symm.{u3, u1} α' α g) a) v a') but is expected to have type forall {α : Sort.{u3}} {β : Sort.{u2}} {α' : Sort.{u1}} [_inst_1 : DecidableEq.{u3} α] [_inst_2 : DecidableEq.{u2} β] (f : β -> α') (g : Equiv.{u3, u2} α β) (a : β) (v : α') (a' : α), Eq.{u1} α' (Function.update.{u2, u1} β (fun (ᾰ : β) => α') (fun (a : β) (b : β) => _inst_2 a b) f a v (FunLike.coe.{max (max 1 u3) u2, u3, u2} (Equiv.{u3, u2} α β) α (fun (_x : α) => (fun ([email protected]._hyg.808 : α) => β) _x) (Equiv.instFunLikeEquiv.{u3, u2} α β) g a')) (Function.update.{u3, u1} α (fun (ᾰ : α) => α') (fun (a : α) (b : α) => _inst_1 a b) (Function.comp.{u3, u2, u1} α β α' f (FunLike.coe.{max (max 1 u3) u2, u3, u2} (Equiv.{u3, u2} α β) α (fun (_x : α) => (fun ([email protected]._hyg.808 : α) => β) _x) (Equiv.instFunLikeEquiv.{u3, u2} α β) g)) (FunLike.coe.{max (max 1 u3) u2, u2, u3} (Equiv.{u2, u3} β α) β (fun (_x : β) => (fun ([email protected]._hyg.808 : β) => α) _x) (Equiv.instFunLikeEquiv.{u2, u3} β α) (Equiv.symm.{u3, u2} α β g) a) v a') Case conversion may be inaccurate. Consider using '#align function.update_apply_equiv_apply Function.update_apply_equiv_applyₓ'. -/ theorem update_apply_equiv_apply {α β α' : Sort _} [DecidableEq α'] [DecidableEq α] (f : α → β) (g : α' ≃ α) (a : α) (v : β) (a' : α') : update f a v (g a') = update (f ∘ g) (g.symm a) v a' := congr_fun (update_comp_equiv f g a v) a' #align function.update_apply_equiv_apply Function.update_apply_equiv_apply /- warning: function.Pi_congr_left'_update -> Function.piCongrLeft'_update is a dubious translation: lean 3 declaration is forall {α : Sort.{u1}} {β : Sort.{u2}} [_inst_1 : DecidableEq.{u1} α] [_inst_2 : DecidableEq.{u2} β] (P : α -> Sort.{u3}) (e : Equiv.{u1, u2} α β) (f : forall (a : α), P a) (b : β) (x : P (coeFn.{max 1 (imax u2 u1) (imax u1 u2), imax u2 u1} (Equiv.{u2, u1} β α) (fun (_x : Equiv.{u2, u1} β α) => β -> α) (Equiv.hasCoeToFun.{u2, u1} β α) (Equiv.symm.{u1, u2} α β e) b)), Eq.{imax u2 u3} (forall (b : β), P (coeFn.{max 1 (imax u2 u1) (imax u1 u2), imax u2 u1} (Equiv.{u2, u1} β α) (fun (_x : Equiv.{u2, u1} β α) => β -> α) (Equiv.hasCoeToFun.{u2, u1} β α) (Equiv.symm.{u1, u2} α β e) b)) (coeFn.{max 1 (imax (imax u1 u3) u2 u3) (imax (imax u2 u3) u1 u3), imax (imax u1 u3) u2 u3} (Equiv.{imax u1 u3, imax u2 u3} (forall (a : α), P a) (forall (b : β), P (coeFn.{max 1 (imax u2 u1) (imax u1 u2), imax u2 u1} (Equiv.{u2, u1} β α) (fun (_x : Equiv.{u2, u1} β α) => β -> α) (Equiv.hasCoeToFun.{u2, u1} β α) (Equiv.symm.{u1, u2} α β e) b))) (fun (_x : Equiv.{imax u1 u3, imax u2 u3} (forall (a : α), P a) (forall (b : β), P (coeFn.{max 1 (imax u2 u1) (imax u1 u2), imax u2 u1} (Equiv.{u2, u1} β α) (fun (_x : Equiv.{u2, u1} β α) => β -> α) (Equiv.hasCoeToFun.{u2, u1} β α) (Equiv.symm.{u1, u2} α β e) b))) => (forall (a : α), P a) -> (forall (b : β), P (coeFn.{max 1 (imax u2 u1) (imax u1 u2), imax u2 u1} (Equiv.{u2, u1} β α) (fun (_x : Equiv.{u2, u1} β α) => β -> α) (Equiv.hasCoeToFun.{u2, u1} β α) (Equiv.symm.{u1, u2} α β e) b))) (Equiv.hasCoeToFun.{imax u1 u3, imax u2 u3} (forall (a : α), P a) (forall (b : β), P (coeFn.{max 1 (imax u2 u1) (imax u1 u2), imax u2 u1} (Equiv.{u2, u1} β α) (fun (_x : Equiv.{u2, u1} β α) => β -> α) (Equiv.hasCoeToFun.{u2, u1} β α) (Equiv.symm.{u1, u2} α β e) b))) (Equiv.piCongrLeft'.{u1, u2, u3} α β P e) (Function.update.{u1, u3} α (fun (a : α) => P a) (fun (a : α) (b : α) => _inst_1 a b) f (coeFn.{max 1 (imax u2 u1) (imax u1 u2), imax u2 u1} (Equiv.{u2, u1} β α) (fun (_x : Equiv.{u2, u1} β α) => β -> α) (Equiv.hasCoeToFun.{u2, u1} β α) (Equiv.symm.{u1, u2} α β e) b) x)) (Function.update.{u2, u3} β (fun (b : β) => P (coeFn.{max 1 (imax u2 u1) (imax u1 u2), imax u2 u1} (Equiv.{u2, u1} β α) (fun (_x : Equiv.{u2, u1} β α) => β -> α) (Equiv.hasCoeToFun.{u2, u1} β α) (Equiv.symm.{u1, u2} α β e) b)) (fun (a : β) (b : β) => _inst_2 a b) (coeFn.{max 1 (imax (imax u1 u3) u2 u3) (imax (imax u2 u3) u1 u3), imax (imax u1 u3) u2 u3} (Equiv.{imax u1 u3, imax u2 u3} (forall (a : α), P a) (forall (b : β), P (coeFn.{max 1 (imax u2 u1) (imax u1 u2), imax u2 u1} (Equiv.{u2, u1} β α) (fun (_x : Equiv.{u2, u1} β α) => β -> α) (Equiv.hasCoeToFun.{u2, u1} β α) (Equiv.symm.{u1, u2} α β e) b))) (fun (_x : Equiv.{imax u1 u3, imax u2 u3} (forall (a : α), P a) (forall (b : β), P (coeFn.{max 1 (imax u2 u1) (imax u1 u2), imax u2 u1} (Equiv.{u2, u1} β α) (fun (_x : Equiv.{u2, u1} β α) => β -> α) (Equiv.hasCoeToFun.{u2, u1} β α) (Equiv.symm.{u1, u2} α β e) b))) => (forall (a : α), P a) -> (forall (b : β), P (coeFn.{max 1 (imax u2 u1) (imax u1 u2), imax u2 u1} (Equiv.{u2, u1} β α) (fun (_x : Equiv.{u2, u1} β α) => β -> α) (Equiv.hasCoeToFun.{u2, u1} β α) (Equiv.symm.{u1, u2} α β e) b))) (Equiv.hasCoeToFun.{imax u1 u3, imax u2 u3} (forall (a : α), P a) (forall (b : β), P (coeFn.{max 1 (imax u2 u1) (imax u1 u2), imax u2 u1} (Equiv.{u2, u1} β α) (fun (_x : Equiv.{u2, u1} β α) => β -> α) (Equiv.hasCoeToFun.{u2, u1} β α) (Equiv.symm.{u1, u2} α β e) b))) (Equiv.piCongrLeft'.{u1, u2, u3} α β P e) f) b x) but is expected to have type forall {α : Sort.{u3}} {β : Sort.{u2}} [_inst_1 : DecidableEq.{u3} α] [_inst_2 : DecidableEq.{u2} β] (P : α -> Sort.{u1}) (e : Equiv.{u3, u2} α β) (f : forall (a : α), P a) (b : β) (x : P (FunLike.coe.{max (max 1 u3) u2, u2, u3} (Equiv.{u2, u3} β α) β (fun (_x : β) => (fun ([email protected]._hyg.808 : β) => α) _x) (Equiv.instFunLikeEquiv.{u2, u3} β α) (Equiv.symm.{u3, u2} α β e) b)), Eq.{imax u2 u1} ((fun ([email protected]._hyg.808 : forall (a : α), P a) => forall (b : β), P (FunLike.coe.{max (max 1 u3) u2, u2, u3} (Equiv.{u2, u3} β α) β (fun (a : β) => (fun ([email protected]._hyg.808 : β) => α) a) (Equiv.instFunLikeEquiv.{u2, u3} β α) (Equiv.symm.{u3, u2} α β e) b)) (Function.update.{u3, u1} α (fun (a : α) => P a) (fun (a : α) (b : α) => _inst_1 a b) f (FunLike.coe.{max (max 1 u3) u2, u2, u3} (Equiv.{u2, u3} β α) β (fun (a : β) => (fun ([email protected]._hyg.808 : β) => α) a) (Equiv.instFunLikeEquiv.{u2, u3} β α) (Equiv.symm.{u3, u2} α β e) b) x)) (FunLike.coe.{max (max 1 (imax u3 u1)) (imax u2 u1), imax u3 u1, imax u2 u1} (Equiv.{imax u3 u1, imax u2 u1} (forall (a : α), P a) (forall (b : β), P (FunLike.coe.{max (max 1 u3) u2, u2, u3} (Equiv.{u2, u3} β α) β (fun (a : β) => (fun ([email protected]._hyg.808 : β) => α) a) (Equiv.instFunLikeEquiv.{u2, u3} β α) (Equiv.symm.{u3, u2} α β e) b))) (forall (a : α), P a) (fun (_x : forall (a : α), P a) => (fun ([email protected]._hyg.808 : forall (a : α), P a) => forall (b : β), P (FunLike.coe.{max (max 1 u3) u2, u2, u3} (Equiv.{u2, u3} β α) β (fun (a : β) => (fun ([email protected]._hyg.808 : β) => α) a) (Equiv.instFunLikeEquiv.{u2, u3} β α) (Equiv.symm.{u3, u2} α β e) b)) _x) (Equiv.instFunLikeEquiv.{imax u3 u1, imax u2 u1} (forall (a : α), P a) (forall (b : β), P (FunLike.coe.{max (max 1 u3) u2, u2, u3} (Equiv.{u2, u3} β α) β (fun (_x : β) => (fun ([email protected]._hyg.808 : β) => α) _x) (Equiv.instFunLikeEquiv.{u2, u3} β α) (Equiv.symm.{u3, u2} α β e) b))) (Equiv.piCongrLeft'.{u3, u2, u1} α β P e) (Function.update.{u3, u1} α (fun (a : α) => P a) (fun (a : α) (b : α) => _inst_1 a b) f (FunLike.coe.{max (max 1 u3) u2, u2, u3} (Equiv.{u2, u3} β α) β (fun (_x : β) => (fun ([email protected]._hyg.808 : β) => α) _x) (Equiv.instFunLikeEquiv.{u2, u3} β α) (Equiv.symm.{u3, u2} α β e) b) x)) (Function.update.{u2, u1} β (fun (b : β) => P (FunLike.coe.{max (max 1 u3) u2, u2, u3} (Equiv.{u2, u3} β α) β (fun (_x : β) => (fun ([email protected]._hyg.808 : β) => α) _x) (Equiv.instFunLikeEquiv.{u2, u3} β α) (Equiv.symm.{u3, u2} α β e) b)) (fun (a : β) (b : β) => _inst_2 a b) (FunLike.coe.{max (max 1 (imax u3 u1)) (imax u2 u1), imax u3 u1, imax u2 u1} (Equiv.{imax u3 u1, imax u2 u1} (forall (a : α), P a) (forall (b : β), P (FunLike.coe.{max (max 1 u3) u2, u2, u3} (Equiv.{u2, u3} β α) β (fun (a : β) => (fun ([email protected]._hyg.808 : β) => α) a) (Equiv.instFunLikeEquiv.{u2, u3} β α) (Equiv.symm.{u3, u2} α β e) b))) (forall (a : α), P a) (fun (_x : forall (a : α), P a) => (fun ([email protected]._hyg.808 : forall (a : α), P a) => forall (b : β), P (FunLike.coe.{max (max 1 u3) u2, u2, u3} (Equiv.{u2, u3} β α) β (fun (a : β) => (fun ([email protected]._hyg.808 : β) => α) a) (Equiv.instFunLikeEquiv.{u2, u3} β α) (Equiv.symm.{u3, u2} α β e) b)) _x) (Equiv.instFunLikeEquiv.{imax u3 u1, imax u2 u1} (forall (a : α), P a) (forall (b : β), P (FunLike.coe.{max (max 1 u3) u2, u2, u3} (Equiv.{u2, u3} β α) β (fun (_x : β) => (fun ([email protected]._hyg.808 : β) => α) _x) (Equiv.instFunLikeEquiv.{u2, u3} β α) (Equiv.symm.{u3, u2} α β e) b))) (Equiv.piCongrLeft'.{u3, u2, u1} α β P e) f) b x) Case conversion may be inaccurate. Consider using '#align function.Pi_congr_left'_update Function.piCongrLeft'_updateₓ'. -/ theorem piCongrLeft'_update [DecidableEq α] [DecidableEq β] (P : α → Sort _) (e : α ≃ β) (f : ∀ a, P a) (b : β) (x : P (e.symm b)) : e.piCongrLeft' P (update f (e.symm b) x) = update (e.piCongrLeft' P f) b x := by ext b' rcases eq_or_ne b' b with (rfl | h) · simp · simp [h] #align function.Pi_congr_left'_update Function.piCongrLeft'_update /- warning: function.Pi_congr_left'_symm_update -> Function.piCongrLeft'_symm_update is a dubious translation: lean 3 declaration is forall {α : Sort.{u1}} {β : Sort.{u2}} [_inst_1 : DecidableEq.{u1} α] [_inst_2 : DecidableEq.{u2} β] (P : α -> Sort.{u3}) (e : Equiv.{u1, u2} α β) (f : forall (b : β), P (coeFn.{max 1 (imax u2 u1) (imax u1 u2), imax u2 u1} (Equiv.{u2, u1} β α) (fun (_x : Equiv.{u2, u1} β α) => β -> α) (Equiv.hasCoeToFun.{u2, u1} β α) (Equiv.symm.{u1, u2} α β e) b)) (b : β) (x : P (coeFn.{max 1 (imax u2 u1) (imax u1 u2), imax u2 u1} (Equiv.{u2, u1} β α) (fun (_x : Equiv.{u2, u1} β α) => β -> α) (Equiv.hasCoeToFun.{u2, u1} β α) (Equiv.symm.{u1, u2} α β e) b)), Eq.{imax u1 u3} (forall (a : α), P a) (coeFn.{max 1 (imax (imax u2 u3) u1 u3) (imax (imax u1 u3) u2 u3), imax (imax u2 u3) u1 u3} (Equiv.{imax u2 u3, imax u1 u3} (forall (b : β), P (coeFn.{max 1 (imax u2 u1) (imax u1 u2), imax u2 u1} (Equiv.{u2, u1} β α) (fun (_x : Equiv.{u2, u1} β α) => β -> α) (Equiv.hasCoeToFun.{u2, u1} β α) (Equiv.symm.{u1, u2} α β e) b)) (forall (a : α), P a)) (fun (_x : Equiv.{imax u2 u3, imax u1 u3} (forall (b : β), P (coeFn.{max 1 (imax u2 u1) (imax u1 u2), imax u2 u1} (Equiv.{u2, u1} β α) (fun (_x : Equiv.{u2, u1} β α) => β -> α) (Equiv.hasCoeToFun.{u2, u1} β α) (Equiv.symm.{u1, u2} α β e) b)) (forall (a : α), P a)) => (forall (b : β), P (coeFn.{max 1 (imax u2 u1) (imax u1 u2), imax u2 u1} (Equiv.{u2, u1} β α) (fun (_x : Equiv.{u2, u1} β α) => β -> α) (Equiv.hasCoeToFun.{u2, u1} β α) (Equiv.symm.{u1, u2} α β e) b)) -> (forall (a : α), P a)) (Equiv.hasCoeToFun.{imax u2 u3, imax u1 u3} (forall (b : β), P (coeFn.{max 1 (imax u2 u1) (imax u1 u2), imax u2 u1} (Equiv.{u2, u1} β α) (fun (_x : Equiv.{u2, u1} β α) => β -> α) (Equiv.hasCoeToFun.{u2, u1} β α) (Equiv.symm.{u1, u2} α β e) b)) (forall (a : α), P a)) (Equiv.symm.{imax u1 u3, imax u2 u3} (forall (a : α), P a) (forall (b : β), P (coeFn.{max 1 (imax u2 u1) (imax u1 u2), imax u2 u1} (Equiv.{u2, u1} β α) (fun (_x : Equiv.{u2, u1} β α) => β -> α) (Equiv.hasCoeToFun.{u2, u1} β α) (Equiv.symm.{u1, u2} α β e) b)) (Equiv.piCongrLeft'.{u1, u2, u3} α β P e)) (Function.update.{u2, u3} β (fun (b : β) => P (coeFn.{max 1 (imax u2 u1) (imax u1 u2), imax u2 u1} (Equiv.{u2, u1} β α) (fun (_x : Equiv.{u2, u1} β α) => β -> α) (Equiv.hasCoeToFun.{u2, u1} β α) (Equiv.symm.{u1, u2} α β e) b)) (fun (a : β) (b : β) => _inst_2 a b) f b x)) (Function.update.{u1, u3} α (fun (a : α) => P a) (fun (a : α) (b : α) => _inst_1 a b) (coeFn.{max 1 (imax (imax u2 u3) u1 u3) (imax (imax u1 u3) u2 u3), imax (imax u2 u3) u1 u3} (Equiv.{imax u2 u3, imax u1 u3} (forall (b : β), P (coeFn.{max 1 (imax u2 u1) (imax u1 u2), imax u2 u1} (Equiv.{u2, u1} β α) (fun (_x : Equiv.{u2, u1} β α) => β -> α) (Equiv.hasCoeToFun.{u2, u1} β α) (Equiv.symm.{u1, u2} α β e) b)) (forall (a : α), P a)) (fun (_x : Equiv.{imax u2 u3, imax u1 u3} (forall (b : β), P (coeFn.{max 1 (imax u2 u1) (imax u1 u2), imax u2 u1} (Equiv.{u2, u1} β α) (fun (_x : Equiv.{u2, u1} β α) => β -> α) (Equiv.hasCoeToFun.{u2, u1} β α) (Equiv.symm.{u1, u2} α β e) b)) (forall (a : α), P a)) => (forall (b : β), P (coeFn.{max 1 (imax u2 u1) (imax u1 u2), imax u2 u1} (Equiv.{u2, u1} β α) (fun (_x : Equiv.{u2, u1} β α) => β -> α) (Equiv.hasCoeToFun.{u2, u1} β α) (Equiv.symm.{u1, u2} α β e) b)) -> (forall (a : α), P a)) (Equiv.hasCoeToFun.{imax u2 u3, imax u1 u3} (forall (b : β), P (coeFn.{max 1 (imax u2 u1) (imax u1 u2), imax u2 u1} (Equiv.{u2, u1} β α) (fun (_x : Equiv.{u2, u1} β α) => β -> α) (Equiv.hasCoeToFun.{u2, u1} β α) (Equiv.symm.{u1, u2} α β e) b)) (forall (a : α), P a)) (Equiv.symm.{imax u1 u3, imax u2 u3} (forall (a : α), P a) (forall (b : β), P (coeFn.{max 1 (imax u2 u1) (imax u1 u2), imax u2 u1} (Equiv.{u2, u1} β α) (fun (_x : Equiv.{u2, u1} β α) => β -> α) (Equiv.hasCoeToFun.{u2, u1} β α) (Equiv.symm.{u1, u2} α β e) b)) (Equiv.piCongrLeft'.{u1, u2, u3} α β P e)) f) (coeFn.{max 1 (imax u2 u1) (imax u1 u2), imax u2 u1} (Equiv.{u2, u1} β α) (fun (_x : Equiv.{u2, u1} β α) => β -> α) (Equiv.hasCoeToFun.{u2, u1} β α) (Equiv.symm.{u1, u2} α β e) b) x) but is expected to have type forall {α : Sort.{u3}} {β : Sort.{u2}} [_inst_1 : DecidableEq.{u3} α] [_inst_2 : DecidableEq.{u2} β] (P : α -> Sort.{u1}) (e : Equiv.{u3, u2} α β) (f : forall (b : β), P (FunLike.coe.{max (max 1 u3) u2, u2, u3} (Equiv.{u2, u3} β α) β (fun (_x : β) => (fun ([email protected]._hyg.808 : β) => α) _x) (Equiv.instFunLikeEquiv.{u2, u3} β α) (Equiv.symm.{u3, u2} α β e) b)) (b : β) (x : P (FunLike.coe.{max (max 1 u3) u2, u2, u3} (Equiv.{u2, u3} β α) β (fun (_x : β) => (fun ([email protected]._hyg.808 : β) => α) _x) (Equiv.instFunLikeEquiv.{u2, u3} β α) (Equiv.symm.{u3, u2} α β e) b)), Eq.{imax u3 u1} ((fun ([email protected]._hyg.808 : forall (b : β), P (FunLike.coe.{max (max 1 u3) u2, u2, u3} (Equiv.{u2, u3} β α) β (fun (a : β) => (fun ([email protected]._hyg.808 : β) => α) a) (Equiv.instFunLikeEquiv.{u2, u3} β α) (Equiv.symm.{u3, u2} α β e) b)) => forall (a : α), P a) (Function.update.{u2, u1} β (fun (b : β) => P (FunLike.coe.{max (max 1 u3) u2, u2, u3} (Equiv.{u2, u3} β α) β (fun (a : β) => (fun ([email protected]._hyg.808 : β) => α) a) (Equiv.instFunLikeEquiv.{u2, u3} β α) (Equiv.symm.{u3, u2} α β e) b)) (fun (a : β) (b : β) => _inst_2 a b) f b x)) (FunLike.coe.{max (max 1 (imax u3 u1)) (imax u2 u1), imax u2 u1, imax u3 u1} (Equiv.{imax u2 u1, imax u3 u1} (forall (b : β), P (FunLike.coe.{max (max 1 u3) u2, u2, u3} (Equiv.{u2, u3} β α) β (fun (a : β) => (fun ([email protected]._hyg.808 : β) => α) a) (Equiv.instFunLikeEquiv.{u2, u3} β α) (Equiv.symm.{u3, u2} α β e) b)) (forall (a : α), P a)) (forall (b : β), P (FunLike.coe.{max (max 1 u3) u2, u2, u3} (Equiv.{u2, u3} β α) β (fun (a : β) => (fun ([email protected]._hyg.808 : β) => α) a) (Equiv.instFunLikeEquiv.{u2, u3} β α) (Equiv.symm.{u3, u2} α β e) b)) (fun (_x : forall (b : β), P (FunLike.coe.{max (max 1 u3) u2, u2, u3} (Equiv.{u2, u3} β α) β (fun (a : β) => (fun ([email protected]._hyg.808 : β) => α) a) (Equiv.instFunLikeEquiv.{u2, u3} β α) (Equiv.symm.{u3, u2} α β e) b)) => (fun ([email protected]._hyg.808 : forall (b : β), P (FunLike.coe.{max (max 1 u3) u2, u2, u3} (Equiv.{u2, u3} β α) β (fun (a : β) => (fun ([email protected]._hyg.808 : β) => α) a) (Equiv.instFunLikeEquiv.{u2, u3} β α) (Equiv.symm.{u3, u2} α β e) b)) => forall (a : α), P a) _x) (Equiv.instFunLikeEquiv.{imax u2 u1, imax u3 u1} (forall (b : β), P (FunLike.coe.{max (max 1 u3) u2, u2, u3} (Equiv.{u2, u3} β α) β (fun (_x : β) => (fun ([email protected]._hyg.808 : β) => α) _x) (Equiv.instFunLikeEquiv.{u2, u3} β α) (Equiv.symm.{u3, u2} α β e) b)) (forall (a : α), P a)) (Equiv.symm.{imax u3 u1, imax u2 u1} (forall (a : α), P a) (forall (b : β), P (FunLike.coe.{max (max 1 u3) u2, u2, u3} (Equiv.{u2, u3} β α) β (fun (_x : β) => (fun ([email protected]._hyg.808 : β) => α) _x) (Equiv.instFunLikeEquiv.{u2, u3} β α) (Equiv.symm.{u3, u2} α β e) b)) (Equiv.piCongrLeft'.{u3, u2, u1} α β P e)) (Function.update.{u2, u1} β (fun (b : β) => P (FunLike.coe.{max (max 1 u3) u2, u2, u3} (Equiv.{u2, u3} β α) β (fun (_x : β) => (fun ([email protected]._hyg.808 : β) => α) _x) (Equiv.instFunLikeEquiv.{u2, u3} β α) (Equiv.symm.{u3, u2} α β e) b)) (fun (a : β) (b : β) => _inst_2 a b) f b x)) (Function.update.{u3, u1} α (fun (a : α) => P a) (fun (a : α) (b : α) => _inst_1 a b) (FunLike.coe.{max (max 1 (imax u3 u1)) (imax u2 u1), imax u2 u1, imax u3 u1} (Equiv.{imax u2 u1, imax u3 u1} (forall (b : β), P (FunLike.coe.{max (max 1 u3) u2, u2, u3} (Equiv.{u2, u3} β α) β (fun (a : β) => (fun ([email protected]._hyg.808 : β) => α) a) (Equiv.instFunLikeEquiv.{u2, u3} β α) (Equiv.symm.{u3, u2} α β e) b)) (forall (a : α), P a)) (forall (b : β), P (FunLike.coe.{max (max 1 u3) u2, u2, u3} (Equiv.{u2, u3} β α) β (fun (a : β) => (fun ([email protected]._hyg.808 : β) => α) a) (Equiv.instFunLikeEquiv.{u2, u3} β α) (Equiv.symm.{u3, u2} α β e) b)) (fun (_x : forall (b : β), P (FunLike.coe.{max (max 1 u3) u2, u2, u3} (Equiv.{u2, u3} β α) β (fun (a : β) => (fun ([email protected]._hyg.808 : β) => α) a) (Equiv.instFunLikeEquiv.{u2, u3} β α) (Equiv.symm.{u3, u2} α β e) b)) => (fun ([email protected]._hyg.808 : forall (b : β), P (FunLike.coe.{max (max 1 u3) u2, u2, u3} (Equiv.{u2, u3} β α) β (fun (a : β) => (fun ([email protected]._hyg.808 : β) => α) a) (Equiv.instFunLikeEquiv.{u2, u3} β α) (Equiv.symm.{u3, u2} α β e) b)) => forall (a : α), P a) _x) (Equiv.instFunLikeEquiv.{imax u2 u1, imax u3 u1} (forall (b : β), P (FunLike.coe.{max (max 1 u3) u2, u2, u3} (Equiv.{u2, u3} β α) β (fun (_x : β) => (fun ([email protected]._hyg.808 : β) => α) _x) (Equiv.instFunLikeEquiv.{u2, u3} β α) (Equiv.symm.{u3, u2} α β e) b)) (forall (a : α), P a)) (Equiv.symm.{imax u3 u1, imax u2 u1} (forall (a : α), P a) (forall (b : β), P (FunLike.coe.{max (max 1 u3) u2, u2, u3} (Equiv.{u2, u3} β α) β (fun (_x : β) => (fun ([email protected]._hyg.808 : β) => α) _x) (Equiv.instFunLikeEquiv.{u2, u3} β α) (Equiv.symm.{u3, u2} α β e) b)) (Equiv.piCongrLeft'.{u3, u2, u1} α β P e)) f) (FunLike.coe.{max (max 1 u3) u2, u2, u3} (Equiv.{u2, u3} β α) β (fun (_x : β) => (fun ([email protected]._hyg.808 : β) => α) _x) (Equiv.instFunLikeEquiv.{u2, u3} β α) (Equiv.symm.{u3, u2} α β e) b) x) Case conversion may be inaccurate. Consider using '#align function.Pi_congr_left'_symm_update Function.piCongrLeft'_symm_updateₓ'. -/ theorem piCongrLeft'_symm_update [DecidableEq α] [DecidableEq β] (P : α → Sort _) (e : α ≃ β) (f : ∀ b, P (e.symm b)) (b : β) (x : P (e.symm b)) : (e.piCongrLeft' P).symm (update f b x) = update ((e.piCongrLeft' P).symm f) (e.symm b) x := by simp [(e.Pi_congr_left' P).symm_apply_eq, Pi_congr_left'_update] #align function.Pi_congr_left'_symm_update Function.piCongrLeft'_symm_update end Function
Formal statement is: lemma complex_derivative_transform_within_open: "\<lbrakk>f holomorphic_on s; g holomorphic_on s; open s; z \<in> s; \<And>w. w \<in> s \<Longrightarrow> f w = g w\<rbrakk> \<Longrightarrow> deriv f z = deriv g z" Informal statement is: If $f$ and $g$ are holomorphic functions on an open set $S$ and $f(x) = g(x)$ for all $x \in S$, then $f'(x) = g'(x)$ for all $x \in S$.
/* Copyright (C) 2007, 2008 Eric Ehlers This file is part of QuantLib, a free-software/open-source library for financial quantitative analysts and developers - http://quantlib.org/ QuantLib is free software: you can redistribute it and/or modify it under the terms of the QuantLib license. You should have received a copy of the license along with this program; if not, please email <[email protected]>. The license is also available online at <http://quantlib.org/license.shtml>. 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 license for more details. */ //This suppression seems no longer to be necessary?... //#include <boost/config.hpp> //#if defined BOOST_MSVC //#pragma warning(disable : 4267) //#endif #include <qlo/serialization/register/serialization_oh.hpp> #include <oh/valueobject.hpp> #include <oh/valueobjects/vo_group.hpp> #include <oh/valueobjects/vo_range.hpp> #include <boost/serialization/shared_ptr.hpp> #include <boost/serialization/variant.hpp> #include <boost/serialization/vector.hpp> /* Register ObjectHandler classes with boost serialization framework ("BSF" below). - At present four classes are registered, this value 4 is hard-coded into gensrc script gensrc/addins/serialization.py so if you add new classes here you also need to change the script. gensrc uses the value to keep track of the IDs which the BSF assigns to each addin class. - Here we explicitly register boost::shared_ptr<ObjectHandler::ValueObject> std::vector<boost::shared_ptr<ObjectHandler::ValueObject> > This isn't strictly necessary because if we neglect to register these classes then the BSF will do so automatically on our behalf the first time we attempt to serialize them. We register them explicitly in order to retain control over all ID numbers assigned by the BSF to our classes. */ namespace QuantLibAddin { void register_oh(boost::archive::xml_oarchive &ar) { // class ID 0 in the boost serialization framework ar.register_type<boost::shared_ptr<ObjectHandler::ValueObject> >(); // class ID 1 in the boost serialization framework ar.register_type<std::vector<boost::shared_ptr<ObjectHandler::ValueObject> > >(); // class ID 2 in the boost serialization framework ar.register_type<ObjectHandler::ValueObjects::ohGroup>(); // class ID 3 in the boost serialization framework ar.register_type<ObjectHandler::ValueObjects::ohRange>(); } void register_oh(boost::archive::xml_iarchive &ar) { // class ID 0 in the boost serialization framework ar.register_type<boost::shared_ptr<ObjectHandler::ValueObject> >(); // class ID 1 in the boost serialization framework ar.register_type<std::vector<boost::shared_ptr<ObjectHandler::ValueObject> > >(); // class ID 2 in the boost serialization framework ar.register_type<ObjectHandler::ValueObjects::ohGroup>(); // class ID 3 in the boost serialization framework ar.register_type<ObjectHandler::ValueObjects::ohRange>(); } }
import scanpy as sc from os import listdir from os.path import join import anndata import scanpy as sc import numpy as np import pandas as pd from os.path import exists # Read Morse et all def get_budinger(): print('budinger') path_budinger = '../data/budinger/budinger_input_scvi_scanpy_norm.h5ad' print(exists(path_budinger), path_budinger) assert exists(path_budinger) budinger = sc.read_h5ad(path_budinger) budinger.obs['cell.type'] = budinger.obs['Cluster'].str[2:] budinger.obs['study'] = 'budinger' budinger.layers["counts"] = budinger.raw.X.copy() budinger.obs['patient.id'] = budinger.obs['Sample Name'] budinger.obs['disease.status'] = 'covid' # MP scoring score_marker_genes_ipf(budinger) return budinger def get_adams(): print('adams') path_adams = '../data/adams/adams_input_scvi_Macrophage_scanpy_norm.h5ad' print(exists(path_adams), path_adams) assert exists(path_adams) adams = sc.read_h5ad(path_adams) adams.layers["counts"] = adams.raw.X.copy() adams.obs['study'] = 'adams' adams.obs['patient.id'] = adams.obs['Subject_Identity'] adams.obs['disease.status'] = adams.obs['Disease_Identity'] # MP scoring score_marker_genes_ipf(adams) return adams def get_morse(): # MORSE print('morse') rootdir = '../data/morse/by_patient_scanpy_norm_mac' ad_all = [] for f in listdir(rootdir): next_path_morse = join(rootdir, f) print(exists(next_path_morse), next_path_morse) assert exists(next_path_morse) ad_next = sc.read_h5ad(next_path_morse) # print(f) if ad_next.shape[0] == 0: # print(f, 'empty') continue ad_next.var_names_make_unique(); ad_next.raw.var.index = ad_next.var.index # del ad_next.raw ad_all.append(ad_next) morse = anndata.concat(ad_all) morse.obs['cell.type'] = morse.obs['cell.type'].str[2:] morse.obs['study'] = 'morse' morse.var = ad_all[0].var.copy() morse.layers["counts"] = morse.raw.X.copy() morse.obs['disease.status'] = np.where(morse.obs['sample.id'].str.contains('IPF'), 'IPF', 'control') # MP scoring score_marker_genes_ipf(morse) return morse def get_bal(): print('bal') # BAL path_bal = '../data/bal/bal.h5ad' path_bal_feats = '../data/bal/bal_feature_names.tsv.gz' print(exists(path_bal), path_bal) print(exists(path_bal_feats), path_bal) assert exists(path_bal) assert exists(path_bal_feats) bal = sc.read_h5ad(path_bal) bal_df = pd.read_csv(path_bal_feats, compression='gzip', sep='\t') bal.obs['patient.id'] = bal.obs['patient'] bal.var['ensembl'] = bal.var.index bal.var['symbol'] = bal.var.index.map(bal_df.set_index('ensID')['feature'].to_dict()) # print(sum(pd.isnull(bal.var['symbol']))) bal = bal[:,~pd.isnull(bal.var['symbol'])] bal.var.index = np.array(bal.var['symbol']) bal.var_names_make_unique() # print(bal.var.index.value_counts()) bal.raw = bal.copy() bal.layers["counts"] = bal.raw.X.copy() bal.obs['study'] = 'BAL' bal.obs['disease.status'] = 'BAL (NA)' bal.obs['cell.type'] = bal.obs['Celltype_2'] # QC for BAL and only MPs bal = bal[bal.obs['percent.mt'] < 10,:] bal = bal[bal.obs['nCount_RNA'] > 1000,:] bal = bal[bal.obs['nFeature_RNA'] > 1000,:] bal = bal[bal.obs['Celltype_2'].str.contains('Macrophages'),:] sc.pp.normalize_per_cell(bal, counts_per_cell_after=1e6); sc.pp.log1p(bal); # remove unnecessary keys for k in list(bal.obsm): if k != 'RNA_MNN_40_UMAP': del bal.obsm[k] for k in list(bal.obs): if 'res' in k and not 'RNA_mnn_40' in k: del bal.obs[k] print('adding annotation from bal mdm...') # add annotation for bal_mdm bal_mdm = sc.read_h5ad('../data/bal/bal_mdm.h5ad') bal.obs['mdm.type'] = bal.obs.index.map(bal_mdm.obs.Cluster.to_dict()) # MP scoring print('scoring genes...') score_marker_genes_ipf(bal) return bal def get_concatenated_dataset(N=1000): # Read Morse et all file by file # ADAMS adams = get_adams() morse = get_morse() bal = get_bal() budinger = get_budinger() #HVGs sc.pp.highly_variable_genes(adams, n_top_genes=4000) sc.pp.highly_variable_genes(morse, n_top_genes=4000) sc.pp.highly_variable_genes(bal, n_top_genes=4000) sc.pp.highly_variable_genes(budinger, n_top_genes=4000) a = set(adams.var[adams.var['highly_variable']].index) b = set(morse.var[morse.var['highly_variable']].index) c = set(bal.var[bal.var['highly_variable']].index) d = set(budinger.var[budinger.var['highly_variable']].index) hvg = set(a).union(b).union(c).union(d) print(adams.layers['counts'].max()) print(morse.layers['counts'].max()) print(bal.layers['counts'].max()) print(budinger.layers['counts'].max()) print('morse+adams') adata = morse.concatenate(adams) print('(morse+adams) + bal') adata = adata.concatenate(bal) print('(morse+adams+bal) + budinger') adata = adata.concatenate(budinger) adata.var['highly_variable'] = adata.var.index.isin(hvg) print(adata.var['highly_variable'].value_counts()) adata.obs['disease.status'] = adata.obs['disease.status'].str.replace('Control', 'control') adata.obs['cell.type'] = np.where(adata.obs['cell.type'].str.contains('nan'), adata.obs['Subclass_Cell_Identity'], adata.obs['cell.type']) if not 'cell.type' in adata.obs: adata.obs['cell.type'] = adata.obs['Subclass_Cell_Identity'] return adata def get_marker_genes_ipf(): marker_genes = {} marker_genes['MP.markers'] = {"TREM2", "CD9", "SPP1", "GPNMB", "LGALS3", "LGALS1", "FABP4", "FABP5", "ACP5", "PSAP", "FTH1", "LIPA", "CTSD", "CTSB", "CSTB", "CTSL", "APOE", "APOC1", "CD63", "LPL"} marker_genes['MP.others'] = {"FTL1", "CTSC", "HEXA", "HEXB", "MMP12", "MERTK", "TYROBP", "MFGE8", "DOCK1", "ADGRB1", "IL7R"} marker_genes['MP.SPP1'] = {"SPP1"} marker_genes['MP.SPP2'] = {"SPP2"} marker_genes['MP.all'] = {g for k in marker_genes for g in marker_genes[k]} return marker_genes def score_marker_genes_ipf(adata): marker_genes = get_marker_genes_ipf() for k in marker_genes: marker_genes[k] = marker_genes[k].intersection(set(adata.var.symbol)) for k in ['MP.markers', 'MP.others', 'MP.all']: print('scoring', k, len(marker_genes[k])) next_marker_genes = marker_genes[k]; sc.tl.score_genes(adata, list(next_marker_genes), use_raw=False, score_name=k + ".score"); def subset_anndata(adata, N=15000): import random ad = adata if N is not None: adata_sel = adata[adata.obs.index.isin(set(random.sample(list(adata.obs.index), N))) | (adata.obs['study'].isin({'BAL', 'morse'})),:] # adata_sel = adata[(adata.obs['study'].isin({'BAL', 'morse'})),:] ad = adata_sel print(ad.shape) # print(ad.obs['patient.id'].value_counts()) print(ad.obs['study'].value_counts()) return ad def cartesian(arrays, out=None): """ Generate a cartesian product of input arrays. Based on discussion from here https://stackoverflow.com/questions/1208118/using-numpy-to-build-an-array-of-all-combinations-of-two-arrays Parameters ---------- arrays : list of array-like 1-D arrays to form the cartesian product of. out : ndarray Array to place the cartesian product in. Returns ------- out : ndarray 2-D array of shape (M, len(arrays)) containing cartesian products formed of input arrays. Examples -------- >>> cartesian(([1, 2, 3], [4, 5], [6, 7])) array([[1, 4, 6], [1, 4, 7], [1, 5, 6], [1, 5, 7], [2, 4, 6], [2, 4, 7], [2, 5, 6], [2, 5, 7], [3, 4, 6], [3, 4, 7], [3, 5, 6], [3, 5, 7]]) """ arrays = [np.asarray(x) for x in arrays] dtype = arrays[0].dtype n = np.prod([x.size for x in arrays]) if out is None: out = np.zeros([n, len(arrays)], dtype=dtype) m = int(n / arrays[0].size) out[:,0] = np.repeat(arrays[0], m) if arrays[1:]: cartesian(arrays[1:], out=out[0:m, 1:]) for j in range(1, arrays[0].size): out[j*m:(j+1)*m, 1:] = out[0:m, 1:] return out
#pragma once #include "Type/peColor.h" #include "Type\peBitmask.h" #include "peCoreDefs.h" #include <glm/detail/type_vec2.hpp> #undef max #include <gsl.h> #include <random> #pragma warning(push) #pragma warning(disable : 4251) /* * Everything in here is taking more or less one-to-one from 'Physically based * rendering' (Pharr, Humphreys, 2010) */ namespace pe { struct Sample; class peCoordSys; //! \brief Represents a color spectrum. We will use RGB with floating-point //! precision here using Spectrum_t = RGB_32BitFloat; //! \brief Types of BRDFs and BTDFs enum class BxDFType { Reflection = 1 << 0, Transmission = 1 << 1, Diffuse = 1 << 2, Glossy = 1 << 3, Specular = 1 << 4, AllTypes = Diffuse | Glossy | Specular, AllReflection = Reflection | AllTypes, AllTransmission = Transmission | AllTypes, All = AllReflection | AllTransmission }; template <> struct EnableEnumBitmask<BxDFType> : std::true_type {}; //! \brief BRDF or BTDF base class class PE_CORE_API peBxDF { public: virtual ~peBxDF() = default; explicit peBxDF(BxDFType type); bool HasFlags(BxDFType flags) const; auto Type() const { return _type; } //! \brief Evaluate this BxDF for the given outgoing and incoming vectors //! \param wo Outgoing vector //! \param wi Incoming vector //! \returns Value of the distribution function for the two vectors virtual Spectrum_t Eval(const glm::vec3 &wo, const glm::vec3 &wi) const = 0; //! \brief Sampling function for BxDF distributions that utilize delta //! distributions. Here, the incident direction wi cannot //! be known to the user, hence the BxDF computes it //! \param wo Outgoing vector //! \param wi Incoming vector, will be computed by the BxDF //! \param rnd1 First uniform random variable //! \param rnd2 Second uniform random variable //! \param pdf Probability density function for this BxDF and the given pair //! of vectors \returns Value of the distribution function for the two vectors virtual Spectrum_t Sample_f(const glm::vec3 &wo, glm::vec3 &wi, const float rnd1, const float rnd2, float &pdf) const; //! \brief Computes the hemishperical-directional reflectance, which is the //! total reflection in the given direction due to constant illumination over //! the hemisphere. Not every BxDF will be able to compute this in closed //! form, so they will use something like a monte carlo algorithm to compute //! it, hence the <paramref name="samples"/> member //! \param wo Outgoing vector //! \param samples Samples //! \returns Hemispherical reflection around <paramref name="wo"/> virtual Spectrum_t rho(const glm::vec3 &wo, const gsl::span<glm::vec2> &samples) const; //! \brief Computes the hemispherical-hemispherical reflectance, which is the //! fraction of incident light reflected by the surface when the incident //! light is the same from all directions. Not every BxDF will be able to //! compute this in closed form, so they will use something like a monte carlo //! algorithm to compute it //! \param samples1 First set of samples for monte carlo method //! \param samples2 Second set of samples for monte carlo method //! \returns Direction-independent reflectance virtual Spectrum_t rho(const gsl::span<glm::vec2> &samples1, const gsl::span<glm::vec2> &samples2) const; //! \brief Returns the probability density function for the given pairs of //! vectors \param wo Outgoing vector in shading space \param wi Incoming //! vector in shading space \returns PDF virtual float Pdf(const glm::vec3 &wo, const glm::vec3 &wi) const; private: const BxDFType _type; }; #pragma region Fresnel //! \brief Helper class to encapsulate fresnel reflectance struct PE_CORE_API peFresnel { virtual ~peFresnel() {} virtual Spectrum_t Eval(float cosi) const = 0; }; //! \brief Fresnel reflectance for a conductor class PE_CORE_API peFresnelConductor : public peFresnel { public: //! \brief Initializes this FresnelConductor structure with the given index of //! refraction and absorption //! \param eta Index of refraction of conductor //! \param k Absorption index of conductor peFresnelConductor(const Spectrum_t &eta, const Spectrum_t &k); Spectrum_t Eval(float cosi) const override; private: const Spectrum_t _eta; const Spectrum_t _k; }; //! \brief Fresnel reflectance for dielectric material class PE_CORE_API peFresnelDielectric : public peFresnel { public: //! \brief Initializes this FresnelDielectric structure with the given //! incident and transmitted medium indices of refraction //! \param etaIncident Index of refraction for incident material //! \param etaTransmitted Index of refraction for transmitted material peFresnelDielectric(float etaIncident, float etaTransmitted); Spectrum_t Eval(float cosi) const override; private: const float _etaIndicent, _etaTransmitted; }; #pragma endregion //! \brief BRDF for specular reflection class PE_CORE_API peSpecularReflection : public peBxDF { public: peSpecularReflection(const Spectrum_t &spectrum, const peFresnel &fresnel); Spectrum_t Eval(const glm::vec3 &wo, const glm::vec3 &wi) const override; Spectrum_t Sample_f(const glm::vec3 &wo, glm::vec3 &wi, const float rnd1, const float rnd2, float &pdf) const override; private: const Spectrum_t _color; const peFresnel &_fresnel; }; //! \brief Lambertian diffuse reflection class PE_CORE_API peLambert : public peBxDF { public: explicit peLambert(const Spectrum_t &color); Spectrum_t Eval(const glm::vec3 &wo, const glm::vec3 &wi) const override; Spectrum_t rho(const glm::vec3 &wo, const gsl::span<glm::vec2> &samples) const override; Spectrum_t rho(const gsl::span<glm::vec2> &samples1, const gsl::span<glm::vec2> &samples2) const override; private: const Spectrum_t _color; }; //! \brief Random values for BSDF sampling struct PE_CORE_API BSDFSample { BSDFSample() = default; BSDFSample(const glm::vec2 &dir, float component); template <typename Rnd> explicit BSDFSample(Rnd &rng) { std::uniform_real_distribution<float> dist{0.f, 1.f}; dir = {dist(rng), dist(rng)}; component = dist(rng); } glm::vec2 dir; float component; }; //! \brief Bidirectional scattering distribution function. Determines surface //! properties of an object class PE_CORE_API BSDF { public: BSDF(); BSDF(const BSDF &other); BSDF(BSDF &&other) noexcept; BSDF &operator=(const BSDF &); BSDF &operator=(BSDF &&) noexcept; void Add(peBxDF const *bxdf); uint32_t NumBxDFs() const; uint32_t NumBxDFsWithFlags(BxDFType flags) const; //! \brief Evaluate the BSDF for the given set of incoming and outgoing //! vectors \param outgoingWorld Outgoing vector in world space \param //! incomingWorld Incoming vector in world space \param shadingCoordSys //! Shading coordinate system \param flags Types of BxDFs to sample \param //! geometricNormal The normal of the actual geometry for the evaluated point //! \returns Evaluated spectrum Spectrum_t Eval(const glm::vec3 &outgoingWorld, const glm::vec3 &incomingWorld, const peCoordSys &shadingCoordSys, const glm::vec3 &geometricNormal, BxDFType flags) const; //! \brief Sample this BSDF by evaluating a random BxDF Spectrum_t Sample_f(const glm::vec3 &wo, glm::vec3 &wi, const peCoordSys &shadingCoordSys, const glm::vec3 &geometryNormal, const BSDFSample &sample, float &pdf, BxDFType flags, BxDFType &sampledType) const; //! \brief Sums up the hemispherical-hemispherical reflectance values of //! all assigned BxDFs \param rnd Random number generator for monte carlo //! method \param flags Types of BxDFs to sample \param sqrtSamples //! Sampling parameter for monte carlo \returns Summed reflectance Spectrum_t rho(std::default_random_engine &rnd, BxDFType flags = BxDFType::All, uint32_t sqrtSamples = 6) const; //! \brief Sums up the hemispherical-directional reflectance values of all //! assigned BxDFs \param wo Outgoing direction \param rnd Random number //! generator for monte carlo method \param flags Types of BxDFs to sample //! \param sqrtSamples Sampling parameter for monte carlo //! \returns Summed reflectance Spectrum_t rho(const glm::vec3 &wo, std::default_random_engine &rnd, BxDFType flags = BxDFType::All, uint32_t sqrtSamples = 6) const; //! \brief Probability density function of this BSDF for the given pair of //! vectors \param wo Outgoing vector in world space \param wi Incoming vector //! in world space float Pdf(const glm::vec3 &wo, const glm::vec3 &wi, const peCoordSys &shadingCoordSys, BxDFType flags = BxDFType::All) const; private: constexpr static size_t MaxBxDF = 8; uint32_t _numBxdfs; std::array<peBxDF const *, MaxBxDF> _bxdfs; }; #pragma region HelperFunctions //! \brief Computes fresnel reflectance for dielectric materials //! \param cosIncident Cosine of angle of incident direction //! \param cosTransmitted Cosine of angle of transmitted direction //! \param etaIncident Index of refraction for incident medium //! \param etaTransmitted Index of refraction for transmitted medium //! \returns Fresnel reflectance Spectrum_t PE_CORE_API FresnelDielectric(float cosIncident, float cosTransmitted, const Spectrum_t &etaIncident, const Spectrum_t &etaTransmitted); //! \brief Computes the fresnel reflectance for a conducting material //! \param cosIndicent Cosine of the angle of incident direction //! \param eta Index of refraction of the conductor //! \param k Absorption coefficient //! \returns Fresnel reflectance Spectrum_t PE_CORE_API FresnelConductor(float cosIndicent, const Spectrum_t &eta, const Spectrum_t &k); //! \brief Helper to evaluate fresnel shading for dieletric materials //! \param cosIncident Cosine of angle of incident direction //! \param etaIncident Index of refraction of incident medium //! \param etaTransmitted Index of refraction of transmitted medium //! \returns Fresnel reflectance Spectrum_t PE_CORE_API EvalFresnelDielectric(float cosIncident, float etaIncident, float etaTransmitted); #pragma endregion } // namespace pe #pragma warning(pop)
I have a spectra water maker. I am trying to change end fittings on my cklarckpump. But I can't get I lose, the outer ring that holds the end fitting. Should come off with a strap wrech. If not, put the edge of a piece of hardwood in the notch and give a few whacks to loosen. Cylinder Disassembly (Do not disassemble the cylinder unless there is a problem) Hold the base of the S.S compression fittings and loosen the nuts to remove the J-tube. Loosen the base fitting first. Use the spanner or a strap wrench, oil filter wrench, or a nonmetal punch in the groove to loosen the aluminum cylinder ring then remove the ring and plastic end cap." Looks like a cracked cap from over tightening. Where are you located? I tried it all, it is not coming lose. I try heating it a litel, tips from spectra tech. But that did knot worked. At this moment I put it all together and it works but it leaks. Just know we are at Maderia, and we are soon going to the Canaries, there we hope to find someone how can rebuild the and give the pump some service. I've replaced customers clark pump cylinders but never the end cap only unless it was on a membrane housing.. Maybee Tellie could ship one out to you. That end cap is toast and the ring has to come off or you'll have to replace the whole cylinder. This may sound brutal but get a large enough Monkey wrench. Preferably clamp the Clark pump in a vise. It will slightly scar the ring but the Monkey wrench will give you the best leverage. Do not apply great pressure to the wrench. If it does not come loose then apply pressure to the wrench and sharply whack the long end of the wrench with a hammer multiple times to shock the ring loose. If all this fails you can try to weld the crack by heating a screw driver with a torch and melting the crack to seal it. This is best performed with the SS fitting removed and may mean you'll need a tap to re-thread the end cap. I've never met a ring that wouldn't come loose but if you're truly the first you may need to just order a new cylinder kit and replace the whole thing. I don't have a monkey wrench in that size, I don't think  that would work either, maybe if you are in a proper workshop. I would try to weld it if we can't find some one who can do services to the pump when we are on Canaries island's. I would not weld with it in place, you might damage other components. Maybe just try something like JB Weld on the crack for now. Its a lot easier to work on a Clark pump on a work bench. Removing and getting on a bench will actually save you time and give you better leverage. Will the ring on the opposite end turn? Don't mean to be a smart azz, But righty tighty...lefty lucy? I have not tried the opposite ring, that side is fine, and I will leave it that way. Next step is to find a works shop hear in Funshal and try to get inside to work on it, if not here it bee Canaries in a week or so.
function [costPatchCand, uvBiasCand] = ... sc_patch_cost(trgPatch, srcPatch, modelPlane, uvPlaneIDData, ... trgPos, srcTform, srcPosMap, bdPos, optS) numUvPix = size(srcPatch, 3); costPatchCand = zeros(numUvPix, 4, 'single'); % Patch cost - appearance [costApp, uvBiasCand] = sc_patch_cost_app(trgPatch, srcPatch, optS); % Patch cost - planar guidance srcPos = srcTform(:,7:8); costPlane = sc_patch_cost_plane(modelPlane.mLogLPlaneProb, uvPlaneIDData, trgPos, srcPos); if(optS.useCoherence) % Patch cost - coherence costCoherence = sc_patch_cost_coherence(trgPos, srcPosMap, srcTform, optS); end % Patch cost - directional guidance costDirect = sc_patch_cost_direct(uvPlaneIDData, trgPos, srcPos, modelPlane, optS); % Patch cost - proximity cost costProx = sc_patch_cost_prox(srcPos, trgPos, bdPos, optS); % costReg = double(uvPixUpdateSrc == 1); % Weighted sum of the appearance cost and guidance cost costPatchCand(:,1) = costApp; costPatchCand(:,2) = optS.lambdaPlane * costPlane; if(optS.useCoherence) costPatchCand(:,3) = optS.lambdaCoherence * costCoherence; end costPatchCand(:,4) = optS.lambdaDirect * costDirect; costPatchCand(:,5) = optS.lambdaProx * costProx; % costPatchCand(3,:) = optS.lambdaReg * costReg; % [To-Do] Adaptive weighting for patch cost % costPatchCand(2:5,:) = (iLvl/optS.numPyrLvl)*costPatchCand(2:5,:); end function [costApp, uvBias] = sc_patch_cost_app(trgPatch, srcPatch, optS) % SC_PATCH_COST_APP % % Compute the weighted sum of the absolute difference between % cost between source and target patches % Input: % - trgPatch: target patch % - srcPatch: source patch % - optS: parameter % Output: % - costApp: appearance cost % - uvBias bias for the closet neighbor % ========================================================================= % Apply bias correction % ========================================================================= uvBias = []; if(optS.useBiasCorrection) % Mean of source and target patch meanTrgPatch = mean(trgPatch, 1); meanSrcPatch = mean(srcPatch, 1); % Compute bias and clamp it to inteval [optS.minBias, optS.maxBias] uvBias = meanTrgPatch - meanSrcPatch; uvBias = sc_clamp(uvBias, optS.minBias, optS.maxBias); % Update the UV map for bias % uvBias = reshape(biasPatch, 3, numUvValidPix); % Apply the bias correction to source patch srcPatch = bsxfun(@plus, srcPatch, uvBias); end % ========================================================================= % Compute weighted distance % ========================================================================= % Compute distance patchDist = trgPatch - srcPatch; % Sum of absolute distance if(strcmp(optS.costType, 'L1')) patchDist = abs(patchDist); elseif(strcmp(optS.costType, 'L2')) patchDist = patchDist.^2; end % Apply weights patchDist = bsxfun(@times, patchDist, optS.wPatch); costApp = squeeze(sum(sum(patchDist, 1),2)); end function cost = sc_patch_cost_coherence(trgPos, srcPosMap, srcTform, opt) % SC_PATCH_COST_COHERENCE: spatial coherence cost % % Input % - trgPos: target patch positions [numPix] x [2] % - srcPosMap: source patch map [imgH] x [imgW] x [2] % - srcPos: source patch positions [numPix] x [2] % - srcTfmG: source patch geometric transformation [numPix] x [9] % - opt: parameters % Output: % - cost: spatio-temporal coherence cost numPix = size(trgPos,1); [imgH, imgW, ~] = size(srcPosMap); % initialize coherence cost cost = zeros(numPix, 1, 'single'); % ========================================================================= % Compute spatial coherence cost % ========================================================================= for i = 1:4 % source patch position prediction v = opt.propDir(i,:); srcPosP = sc_trans_tform(srcTform, v); srcPosP = srcPosP(:,7:8); % source patch positions of neighboring target patches trgPosN = bsxfun(@plus, trgPos, v); trgIndN = uint32(sub2ind([imgH, imgW], trgPosN(:,2), trgPosN(:,1))); srcPosN = sc_uvMat_from_uvMap(srcPosMap, trgIndN); validSrc = (srcPosN(:,1) ~= 0); % add cost if the differences are high diff = zeros(numPix, 1, 'single'); diff(validSrc) = sum(abs(srcPosP(validSrc,:) - srcPosN(validSrc,:)), 2) > 1; cost = cost + diff; end % cost = opt.lambdaCoherence*cost; end function costPlane = sc_patch_cost_plane(mLogLPlaneProb, uvPlaneIDData, trgPixSub, srcPixSub) % SC_PATCH_COST_PLANE % % Compute planar costs (See Eqn 11 in the paper) [imgH, imgW, numPlane] = size(mLogLPlaneProb); srcPixSub = round(srcPixSub); uvPlaneIDData = double(uvPlaneIDData); trgPixIndCur = sub2ind([imgH, imgW, numPlane], trgPixSub(:,2), trgPixSub(:,1), uvPlaneIDData); srcPixIndCur = sub2ind([imgH, imgW, numPlane], srcPixSub(:,2), srcPixSub(:,1), uvPlaneIDData); costPlane = mLogLPlaneProb(trgPixIndCur) + mLogLPlaneProb(srcPixIndCur); end function costProx = sc_patch_cost_prox(srcPos, trgPos, uvDtBdPixPos, optS) % SC_PATCH_COST_PROX % Encourage to sample patches near to the target patch d = srcPos - trgPos; d = sqrt(sum(d.^2,2)); d = d/optS.imgSize; uvDtBdPixPos = uvDtBdPixPos/optS.imgSize; % costProx = max(0, d - optS.proxThres); % Shrinkage thresholding costProx = max(0, d - uvDtBdPixPos - optS.proxThres); % costProx = max(0, d - optS.proxThres); end function costDirect = sc_patch_cost_direct(uvPlaneIDData, trgPos, srcPos, modelPlane, optS) % SC_PATCH_COST_DIRECT % % Compute the directional cost (See Eqn 13 in the paper) % % Input % - % Output % - numUvPix = size(trgPos, 1); costDirect = optS.lambdaDirect*ones(numUvPix, 2, 'single'); for indPlane = 1: modelPlane.numPlane % Retrieve the uv pixels that have the current plane label uvPlaneIndCur = uvPlaneIDData == indPlane; numPlanePixCur = sum(uvPlaneIndCur); if(indPlane == modelPlane.numPlane) costDirect(uvPlaneIndCur, :) = optS.imgSize*optS.directThres; else % The rectifying transformation for the plane rectMat = modelPlane.rectMat{indPlane}; h7 = rectMat(3,1); h8 = rectMat(3,2); if(numPlanePixCur~=0) trgPosCur = trgPos(uvPlaneIndCur, :) - 1; srcPosCur = srcPos(uvPlaneIndCur, :) - 1; for iTheta = 1:2 rotMat = modelPlane.rotMat{indPlane, iTheta}; rotRecMat = rotMat; rotRecMat(3,1) = h7; rotRecMat(3,2) = h8; rotRecMat = rotRecMat'; trgPosCurRect = cat(2, trgPosCur, ones(numPlanePixCur,1))*rotRecMat; trgPosCurRect = bsxfun(@rdivide, trgPosCurRect, trgPosCurRect(:,3)); % Source patch center position in the rectified domain srcPosCurRect = cat(2, srcPosCur, ones(numPlanePixCur,1))*rotRecMat; srcPosCurRect = bsxfun(@rdivide, srcPosCurRect, srcPosCurRect(:,3)); costDirect(uvPlaneIndCur, iTheta) = abs(srcPosCurRect(:,2) - trgPosCurRect(:,2)); end end end end costDirect = min(costDirect, [], 2); costDirect = min(costDirect/optS.imgSize, optS.directThres); end
State Before: 𝕜 : Type u_1 E : Type u_2 F : Type ?u.270732 β : Type ?u.270735 inst✝⁴ : LinearOrderedField 𝕜 inst✝³ : AddCommGroup E inst✝² : AddCommGroup F inst✝¹ : Module 𝕜 E inst✝ : Module 𝕜 F s : Set E h_conv : Convex 𝕜 s p q : 𝕜 hp : 0 ≤ p hq : 0 ≤ q ⊢ p • s + q • s ⊆ (p + q) • s State After: case intro.intro.intro.intro.intro.intro.intro.intro 𝕜 : Type u_1 E : Type u_2 F : Type ?u.270732 β : Type ?u.270735 inst✝⁴ : LinearOrderedField 𝕜 inst✝³ : AddCommGroup E inst✝² : AddCommGroup F inst✝¹ : Module 𝕜 E inst✝ : Module 𝕜 F s : Set E h_conv : Convex 𝕜 s p q : 𝕜 hp : 0 ≤ p hq : 0 ≤ q v₁ : E h₁ : v₁ ∈ s v₂ : E h₂ : v₂ ∈ s ⊢ (fun x x_1 => x + x_1) ((fun x => p • x) v₁) ((fun x => q • x) v₂) ∈ (p + q) • s Tactic: rintro _ ⟨_, _, ⟨v₁, h₁, rfl⟩, ⟨v₂, h₂, rfl⟩, rfl⟩ State Before: case intro.intro.intro.intro.intro.intro.intro.intro 𝕜 : Type u_1 E : Type u_2 F : Type ?u.270732 β : Type ?u.270735 inst✝⁴ : LinearOrderedField 𝕜 inst✝³ : AddCommGroup E inst✝² : AddCommGroup F inst✝¹ : Module 𝕜 E inst✝ : Module 𝕜 F s : Set E h_conv : Convex 𝕜 s p q : 𝕜 hp : 0 ≤ p hq : 0 ≤ q v₁ : E h₁ : v₁ ∈ s v₂ : E h₂ : v₂ ∈ s ⊢ (fun x x_1 => x + x_1) ((fun x => p • x) v₁) ((fun x => q • x) v₂) ∈ (p + q) • s State After: no goals Tactic: exact h_conv.exists_mem_add_smul_eq h₁ h₂ hp hq
| pc = 0xc002 | a = 0x95 | x = 0x00 | y = 0x00 | sp = 0x01fd | p[NV-BDIZC] = 10110100 | | pc = 0xc004 | a = 0x95 | x = 0x00 | y = 0x00 | sp = 0x01fd | p[NV-BDIZC] = 10110100 | MEM[0x0015] = 0x95 | | pc = 0xc006 | a = 0x95 | x = 0x00 | y = 0x00 | sp = 0x01fd | p[NV-BDIZC] = 00110111 | MEM[0x0015] = 0x95 | | pc = 0xc008 | a = 0x03 | x = 0x00 | y = 0x00 | sp = 0x01fd | p[NV-BDIZC] = 00110101 | | pc = 0xc00a | a = 0x03 | x = 0x00 | y = 0x00 | sp = 0x01fd | p[NV-BDIZC] = 00110100 | MEM[0x0015] = 0x95 | | pc = 0xc00c | a = 0x03 | x = 0x00 | y = 0x00 | sp = 0x01fd | p[NV-BDIZC] = 00110100 | MEM[0x0016] = 0x03 | | pc = 0xc00e | a = 0x95 | x = 0x00 | y = 0x00 | sp = 0x01fd | p[NV-BDIZC] = 10110100 | | pc = 0xc010 | a = 0x95 | x = 0x00 | y = 0x00 | sp = 0x01fd | p[NV-BDIZC] = 10110101 | MEM[0x0016] = 0x03 |
Require Import FinProof.ProgrammingWith. Require Import UMLang.UrsusLib. Require Import UMLang.LocalClassGenerator.ClassGenerator. Require Import UrsusTVM.Cpp.tvmTypes. Require Import Project.CommonTypes. (*Поля контракта*) Inductive IBlankFields := | IBlank_ι_botch0 | IBlank_ι_botch1 . Inductive VarInitFields := | VarInit_ι_botch0 | VarInit_ι_botch1 . Local Open Scope xlist_scope. Local Open Scope record. Local Open Scope program_scope. Local Open Scope glist_scope. Opaque address. Definition IBlankL : list Type := [ address : Type; address : Type]. GeneratePruvendoRecord IBlankL IBlankFields. Opaque IBlankLRecord. Definition VarInitL: list Type := [ (address : Type); (address : Type) ]. GeneratePruvendoRecord VarInitL VarInitFields. Opaque VarInitLRecord.
[GOAL] ι : Sort u_1 α : Type u_2 β : Type u_3 γ : Type u_4 inst✝¹ : MeasurableSpace α inst✝ : MeasurableSpace β f : ι → α → β μ : Measure α p : α → (ι → β) → Prop hf : ∀ (i : ι), AEMeasurable (f i) x : α hx : x ∈ aeSeqSet hf p i : ι ⊢ aeSeqSet hf p ⊆ {x | ∀ (i : ι), f i x = AEMeasurable.mk (f i) (_ : AEMeasurable (f i)) x} [PROOFSTEP] rw [aeSeqSet, ← compl_compl {x | ∀ i, f i x = (hf i).mk (f i) x}, Set.compl_subset_compl] [GOAL] ι : Sort u_1 α : Type u_2 β : Type u_3 γ : Type u_4 inst✝¹ : MeasurableSpace α inst✝ : MeasurableSpace β f : ι → α → β μ : Measure α p : α → (ι → β) → Prop hf : ∀ (i : ι), AEMeasurable (f i) x : α hx : x ∈ aeSeqSet hf p i : ι ⊢ {x | ∀ (i : ι), f i x = AEMeasurable.mk (f i) (_ : AEMeasurable (f i)) x}ᶜ ⊆ toMeasurable μ {x | (∀ (i : ι), f i x = AEMeasurable.mk (f i) (_ : AEMeasurable (f i)) x) ∧ p x fun n => f n x}ᶜ [PROOFSTEP] refine' Set.Subset.trans (Set.compl_subset_compl.mpr fun x h => _) (subset_toMeasurable _ _) [GOAL] ι : Sort u_1 α : Type u_2 β : Type u_3 γ : Type u_4 inst✝¹ : MeasurableSpace α inst✝ : MeasurableSpace β f : ι → α → β μ : Measure α p : α → (ι → β) → Prop hf : ∀ (i : ι), AEMeasurable (f i) x✝ : α hx : x✝ ∈ aeSeqSet hf p i : ι x : α h : x ∈ {x | (∀ (i : ι), f i x = AEMeasurable.mk (f i) (_ : AEMeasurable (f i)) x) ∧ p x fun n => f n x} ⊢ x ∈ {x | ∀ (i : ι), f i x = AEMeasurable.mk (f i) (_ : AEMeasurable (f i)) x} [PROOFSTEP] exact h.1 [GOAL] ι : Sort u_1 α : Type u_2 β : Type u_3 γ : Type u_4 inst✝¹ : MeasurableSpace α inst✝ : MeasurableSpace β f : ι → α → β μ : Measure α p : α → (ι → β) → Prop hf : ∀ (i : ι), AEMeasurable (f i) x : α hx : x ∈ aeSeqSet hf p i : ι ⊢ aeSeq hf p i x = AEMeasurable.mk (f i) (_ : AEMeasurable (f i)) x [PROOFSTEP] simp only [aeSeq, hx, if_true] [GOAL] ι : Sort u_1 α : Type u_2 β : Type u_3 γ : Type u_4 inst✝¹ : MeasurableSpace α inst✝ : MeasurableSpace β f : ι → α → β μ : Measure α p : α → (ι → β) → Prop hf : ∀ (i : ι), AEMeasurable (f i) x : α hx : x ∈ aeSeqSet hf p i : ι ⊢ aeSeq hf p i x = f i x [PROOFSTEP] simp only [aeSeq_eq_mk_of_mem_aeSeqSet hf hx i, mk_eq_fun_of_mem_aeSeqSet hf hx i] [GOAL] ι : Sort u_1 α : Type u_2 β : Type u_3 γ : Type u_4 inst✝¹ : MeasurableSpace α inst✝ : MeasurableSpace β f : ι → α → β μ : Measure α p : α → (ι → β) → Prop hf : ∀ (i : ι), AEMeasurable (f i) x : α hx : x ∈ aeSeqSet hf p ⊢ p x fun n => aeSeq hf p n x [PROOFSTEP] simp only [aeSeq, hx, if_true] [GOAL] ι : Sort u_1 α : Type u_2 β : Type u_3 γ : Type u_4 inst✝¹ : MeasurableSpace α inst✝ : MeasurableSpace β f : ι → α → β μ : Measure α p : α → (ι → β) → Prop hf : ∀ (i : ι), AEMeasurable (f i) x : α hx : x ∈ aeSeqSet hf p ⊢ p x fun n => AEMeasurable.mk (f n) (_ : AEMeasurable (f n)) x [PROOFSTEP] rw [funext fun n => mk_eq_fun_of_mem_aeSeqSet hf hx n] [GOAL] ι : Sort u_1 α : Type u_2 β : Type u_3 γ : Type u_4 inst✝¹ : MeasurableSpace α inst✝ : MeasurableSpace β f : ι → α → β μ : Measure α p : α → (ι → β) → Prop hf : ∀ (i : ι), AEMeasurable (f i) x : α hx : x ∈ aeSeqSet hf p ⊢ p x fun n => f n x [PROOFSTEP] have h_ss : aeSeqSet hf p ⊆ {x | p x fun n => f n x} := by rw [← compl_compl {x | p x fun n => f n x}, aeSeqSet, Set.compl_subset_compl] refine' Set.Subset.trans (Set.compl_subset_compl.mpr _) (subset_toMeasurable _ _) exact fun x hx => hx.2 [GOAL] ι : Sort u_1 α : Type u_2 β : Type u_3 γ : Type u_4 inst✝¹ : MeasurableSpace α inst✝ : MeasurableSpace β f : ι → α → β μ : Measure α p : α → (ι → β) → Prop hf : ∀ (i : ι), AEMeasurable (f i) x : α hx : x ∈ aeSeqSet hf p ⊢ aeSeqSet hf p ⊆ {x | p x fun n => f n x} [PROOFSTEP] rw [← compl_compl {x | p x fun n => f n x}, aeSeqSet, Set.compl_subset_compl] [GOAL] ι : Sort u_1 α : Type u_2 β : Type u_3 γ : Type u_4 inst✝¹ : MeasurableSpace α inst✝ : MeasurableSpace β f : ι → α → β μ : Measure α p : α → (ι → β) → Prop hf : ∀ (i : ι), AEMeasurable (f i) x : α hx : x ∈ aeSeqSet hf p ⊢ {x | p x fun n => f n x}ᶜ ⊆ toMeasurable μ {x | (∀ (i : ι), f i x = AEMeasurable.mk (f i) (_ : AEMeasurable (f i)) x) ∧ p x fun n => f n x}ᶜ [PROOFSTEP] refine' Set.Subset.trans (Set.compl_subset_compl.mpr _) (subset_toMeasurable _ _) [GOAL] ι : Sort u_1 α : Type u_2 β : Type u_3 γ : Type u_4 inst✝¹ : MeasurableSpace α inst✝ : MeasurableSpace β f : ι → α → β μ : Measure α p : α → (ι → β) → Prop hf : ∀ (i : ι), AEMeasurable (f i) x : α hx : x ∈ aeSeqSet hf p ⊢ {x | (∀ (i : ι), f i x = AEMeasurable.mk (f i) (_ : AEMeasurable (f i)) x) ∧ p x fun n => f n x} ⊆ {x | p x fun n => f n x} [PROOFSTEP] exact fun x hx => hx.2 [GOAL] ι : Sort u_1 α : Type u_2 β : Type u_3 γ : Type u_4 inst✝¹ : MeasurableSpace α inst✝ : MeasurableSpace β f : ι → α → β μ : Measure α p : α → (ι → β) → Prop hf : ∀ (i : ι), AEMeasurable (f i) x : α hx : x ∈ aeSeqSet hf p h_ss : aeSeqSet hf p ⊆ {x | p x fun n => f n x} ⊢ p x fun n => f n x [PROOFSTEP] have hx' := Set.mem_of_subset_of_mem h_ss hx [GOAL] ι : Sort u_1 α : Type u_2 β : Type u_3 γ : Type u_4 inst✝¹ : MeasurableSpace α inst✝ : MeasurableSpace β f : ι → α → β μ : Measure α p : α → (ι → β) → Prop hf : ∀ (i : ι), AEMeasurable (f i) x : α hx : x ∈ aeSeqSet hf p h_ss : aeSeqSet hf p ⊆ {x | p x fun n => f n x} hx' : x ∈ {x | p x fun n => f n x} ⊢ p x fun n => f n x [PROOFSTEP] exact hx' [GOAL] ι : Sort u_1 α : Type u_2 β : Type u_3 γ : Type u_4 inst✝¹ : MeasurableSpace α inst✝ : MeasurableSpace β f : ι → α → β μ : Measure α p : α → (ι → β) → Prop hf : ∀ (i : ι), AEMeasurable (f i) x : α hx : x ∈ aeSeqSet hf p ⊢ p x fun n => f n x [PROOFSTEP] have h_eq : (fun n => f n x) = fun n => aeSeq hf p n x := funext fun n => (aeSeq_eq_fun_of_mem_aeSeqSet hf hx n).symm [GOAL] ι : Sort u_1 α : Type u_2 β : Type u_3 γ : Type u_4 inst✝¹ : MeasurableSpace α inst✝ : MeasurableSpace β f : ι → α → β μ : Measure α p : α → (ι → β) → Prop hf : ∀ (i : ι), AEMeasurable (f i) x : α hx : x ∈ aeSeqSet hf p h_eq : (fun n => f n x) = fun n => aeSeq hf p n x ⊢ p x fun n => f n x [PROOFSTEP] rw [h_eq] [GOAL] ι : Sort u_1 α : Type u_2 β : Type u_3 γ : Type u_4 inst✝¹ : MeasurableSpace α inst✝ : MeasurableSpace β f : ι → α → β μ : Measure α p : α → (ι → β) → Prop hf : ∀ (i : ι), AEMeasurable (f i) x : α hx : x ∈ aeSeqSet hf p h_eq : (fun n => f n x) = fun n => aeSeq hf p n x ⊢ p x fun n => aeSeq hf p n x [PROOFSTEP] exact prop_of_mem_aeSeqSet hf hx [GOAL] ι : Sort u_1 α : Type u_2 β : Type u_3 γ : Type u_4 inst✝² : MeasurableSpace α inst✝¹ : MeasurableSpace β f : ι → α → β μ : Measure α p : α → (ι → β) → Prop inst✝ : Countable ι hf : ∀ (i : ι), AEMeasurable (f i) hp : ∀ᵐ (x : α) ∂μ, p x fun n => f n x ⊢ ↑↑μ (aeSeqSet hf p)ᶜ = 0 [PROOFSTEP] rw [aeSeqSet, compl_compl, measure_toMeasurable] [GOAL] ι : Sort u_1 α : Type u_2 β : Type u_3 γ : Type u_4 inst✝² : MeasurableSpace α inst✝¹ : MeasurableSpace β f : ι → α → β μ : Measure α p : α → (ι → β) → Prop inst✝ : Countable ι hf : ∀ (i : ι), AEMeasurable (f i) hp : ∀ᵐ (x : α) ∂μ, p x fun n => f n x ⊢ ↑↑μ {x | (∀ (i : ι), f i x = AEMeasurable.mk (f i) (_ : AEMeasurable (f i)) x) ∧ p x fun n => f n x}ᶜ = 0 [PROOFSTEP] have hf_eq := fun i => (hf i).ae_eq_mk [GOAL] ι : Sort u_1 α : Type u_2 β : Type u_3 γ : Type u_4 inst✝² : MeasurableSpace α inst✝¹ : MeasurableSpace β f : ι → α → β μ : Measure α p : α → (ι → β) → Prop inst✝ : Countable ι hf : ∀ (i : ι), AEMeasurable (f i) hp : ∀ᵐ (x : α) ∂μ, p x fun n => f n x hf_eq : ∀ (i : ι), f i =ᵐ[μ] AEMeasurable.mk (f i) (_ : AEMeasurable (f i)) ⊢ ↑↑μ {x | (∀ (i : ι), f i x = AEMeasurable.mk (f i) (_ : AEMeasurable (f i)) x) ∧ p x fun n => f n x}ᶜ = 0 [PROOFSTEP] simp_rw [Filter.EventuallyEq, ← ae_all_iff] at hf_eq [GOAL] ι : Sort u_1 α : Type u_2 β : Type u_3 γ : Type u_4 inst✝² : MeasurableSpace α inst✝¹ : MeasurableSpace β f : ι → α → β μ : Measure α p : α → (ι → β) → Prop inst✝ : Countable ι hf : ∀ (i : ι), AEMeasurable (f i) hp : ∀ᵐ (x : α) ∂μ, p x fun n => f n x hf_eq : ∀ᵐ (a : α) ∂μ, ∀ (i : ι), f i a = AEMeasurable.mk (f i) (_ : AEMeasurable (f i)) a ⊢ ↑↑μ {x | (∀ (i : ι), f i x = AEMeasurable.mk (f i) (_ : AEMeasurable (f i)) x) ∧ p x fun n => f n x}ᶜ = 0 [PROOFSTEP] exact Filter.Eventually.and hf_eq hp [GOAL] ι : Sort u_1 α : Type u_2 β : Type u_3 γ : Type u_4 inst✝² : MeasurableSpace α inst✝¹ : MeasurableSpace β f : ι → α → β μ : Measure α p : α → (ι → β) → Prop inst✝ : Countable ι hf : ∀ (i : ι), AEMeasurable (f i) hp : ∀ᵐ (x : α) ∂μ, p x fun n => f n x x : α hx : x ∈ aeSeqSet hf p i : ι ⊢ aeSeq hf p i x = AEMeasurable.mk (f i) (_ : AEMeasurable (f i)) x [PROOFSTEP] simp only [aeSeq, hx, if_true] [GOAL] ι : Sort u_1 α : Type u_2 β : Type u_3 γ : Type u_4 inst✝³ : MeasurableSpace α inst✝² : MeasurableSpace β f : ι → α → β μ : Measure α p : α → (ι → β) → Prop inst✝¹ : CompleteLattice β inst✝ : Countable ι hf : ∀ (i : ι), AEMeasurable (f i) hp : ∀ᵐ (x : α) ∂μ, p x fun n => f n x ⊢ ⨆ (n : ι), aeSeq hf p n =ᵐ[μ] ⨆ (n : ι), f n [PROOFSTEP] simp_rw [Filter.EventuallyEq, ae_iff, iSup_apply] [GOAL] ι : Sort u_1 α : Type u_2 β : Type u_3 γ : Type u_4 inst✝³ : MeasurableSpace α inst✝² : MeasurableSpace β f : ι → α → β μ : Measure α p : α → (ι → β) → Prop inst✝¹ : CompleteLattice β inst✝ : Countable ι hf : ∀ (i : ι), AEMeasurable (f i) hp : ∀ᵐ (x : α) ∂μ, p x fun n => f n x ⊢ ↑↑μ {a | ¬⨆ (i : ι), aeSeq hf p i a = ⨆ (i : ι), f i a} = 0 [PROOFSTEP] have h_ss : aeSeqSet hf p ⊆ {a : α | ⨆ i : ι, aeSeq hf p i a = ⨆ i : ι, f i a} := by intro x hx congr exact funext fun i => aeSeq_eq_fun_of_mem_aeSeqSet hf hx i [GOAL] ι : Sort u_1 α : Type u_2 β : Type u_3 γ : Type u_4 inst✝³ : MeasurableSpace α inst✝² : MeasurableSpace β f : ι → α → β μ : Measure α p : α → (ι → β) → Prop inst✝¹ : CompleteLattice β inst✝ : Countable ι hf : ∀ (i : ι), AEMeasurable (f i) hp : ∀ᵐ (x : α) ∂μ, p x fun n => f n x ⊢ aeSeqSet hf p ⊆ {a | ⨆ (i : ι), aeSeq hf p i a = ⨆ (i : ι), f i a} [PROOFSTEP] intro x hx [GOAL] ι : Sort u_1 α : Type u_2 β : Type u_3 γ : Type u_4 inst✝³ : MeasurableSpace α inst✝² : MeasurableSpace β f : ι → α → β μ : Measure α p : α → (ι → β) → Prop inst✝¹ : CompleteLattice β inst✝ : Countable ι hf : ∀ (i : ι), AEMeasurable (f i) hp : ∀ᵐ (x : α) ∂μ, p x fun n => f n x x : α hx : x ∈ aeSeqSet hf p ⊢ x ∈ {a | ⨆ (i : ι), aeSeq hf p i a = ⨆ (i : ι), f i a} [PROOFSTEP] congr [GOAL] case e_s ι : Sort u_1 α : Type u_2 β : Type u_3 γ : Type u_4 inst✝³ : MeasurableSpace α inst✝² : MeasurableSpace β f : ι → α → β μ : Measure α p : α → (ι → β) → Prop inst✝¹ : CompleteLattice β inst✝ : Countable ι hf : ∀ (i : ι), AEMeasurable (f i) hp : ∀ᵐ (x : α) ∂μ, p x fun n => f n x x : α hx : x ∈ aeSeqSet hf p ⊢ (fun i => aeSeq hf p i x) = fun i => f i x [PROOFSTEP] exact funext fun i => aeSeq_eq_fun_of_mem_aeSeqSet hf hx i [GOAL] ι : Sort u_1 α : Type u_2 β : Type u_3 γ : Type u_4 inst✝³ : MeasurableSpace α inst✝² : MeasurableSpace β f : ι → α → β μ : Measure α p : α → (ι → β) → Prop inst✝¹ : CompleteLattice β inst✝ : Countable ι hf : ∀ (i : ι), AEMeasurable (f i) hp : ∀ᵐ (x : α) ∂μ, p x fun n => f n x h_ss : aeSeqSet hf p ⊆ {a | ⨆ (i : ι), aeSeq hf p i a = ⨆ (i : ι), f i a} ⊢ ↑↑μ {a | ¬⨆ (i : ι), aeSeq hf p i a = ⨆ (i : ι), f i a} = 0 [PROOFSTEP] exact measure_mono_null (Set.compl_subset_compl.mpr h_ss) (measure_compl_aeSeqSet_eq_zero hf hp)
# R36 DERIVATION **We know the following from our geometry:** ``` 1. R0u = R06 * R6g * Rgu 2. R03 = R03 * R36 3. R6g = I 4. R0u = rotz(yaw) * roty(pitch) * rotx(roll) 5. Rgu = rotz(pi) * roty(-pi/2) ``` **For any matrix recall the following properties:** ``` 1. R = I * R = R * I 2. (A * B) * C = A * (B * C) 3. if A = B then A * C = B * C and vice versa 4. if A = B then C * A = C * C and vice versa 5. R * R.inverse() = R.inverse() * R = I ``` **Note that for rotation matrices** ``` R.inverse() = R.T Therefore: R.T * R = R * R.T = I ``` **From the discussion above, you can do the following:** - _Subsitution_ - - `R0u = (R03 * R36) * I * Rgu` - _Multiply both sides by `Rgu.inverse() = Rgu.T` at the right_ - - `R0u * Rgu.T = R03 * R36 ` - _Multiply both sides by `R03.inverse() = R03.T` at the left_ - - `R03.T * R0u * Rgu.T = R36 ` **We conclude then that:** ``` R36 = R03.T * R0u * Rgu.T R36 = R03.T * R0g where: R0u = rotz(yaw) * roty(pitch) * rotx(roll) Rgu = rotz(pi) * roty(-pi/2) ``` ` ```python from sympy import symbols, cos, sin, pi, simplify, trigsimp, expand_trig, pprint, sqrt, atan2 from sympy.matrices import Matrix def rotx(q): sq, cq = sin(q), cos(q) r = Matrix([ [1., 0., 0.], [0., cq,-sq], [0., sq, cq] ]) return r def roty(q): sq, cq = sin(q), cos(q) r = Matrix([ [ cq, 0., sq], [ 0., 1., 0.], [-sq, 0., cq] ]) return r def rotz(q): sq, cq = sin(q), cos(q) r = Matrix([ [cq,-sq, 0.], [sq, cq, 0.], [0., 0., 1.] ]) return r ``` ```python q1, q2, q3, q4, q5, q6= symbols('q1:7') R03 = Matrix([ [sin(q2 + q3)*cos(q1), cos(q1)*cos(q2 + q3), -sin(q1)], [sin(q1)*sin(q2 + q3), sin(q1)*cos(q2 + q3), cos(q1)], [ cos(q2 + q3), -sin(q2 + q3), 0]]) R03T = R03.T pprint(R03T) ``` ⎡sin(q₂ + q₃)⋅cos(q₁) sin(q₁)⋅sin(q₂ + q₃) cos(q₂ + q₃) ⎤ ⎢ ⎥ ⎢cos(q₁)⋅cos(q₂ + q₃) sin(q₁)⋅cos(q₂ + q₃) -sin(q₂ + q₃)⎥ ⎢ ⎥ ⎣ -sin(q₁) cos(q₁) 0 ⎦ ```python R36 = Matrix([[-sin(q4)*sin(q6) + cos(q4)*cos(q5)*cos(q6), -sin(q4)*cos(q6) - sin(q6)*cos(q4)*cos(q5), -sin(q5)*cos(q4)], [ sin(q5)*cos(q6), -sin(q5)*sin(q6), cos(q5)], [-sin(q4)*cos(q5)*cos(q6) - sin(q6)*cos(q4), sin(q4)*sin(q6)*cos(q5) - cos(q4)*cos(q6), sin(q4)*sin(q5)]]) ``` ```python alpha, beta, gamma = symbols('alpha beta gamma', real = True) R0u = rotz(alpha) * roty(beta) * rotx(gamma) pprint(R0u) ``` ⎡1.0⋅cos(α)⋅cos(β) -1.0⋅sin(α)⋅cos(γ) + sin(β)⋅sin(γ)⋅cos(α) 1.0⋅sin(α)⋅sin( ⎢ ⎢1.0⋅sin(α)⋅cos(β) sin(α)⋅sin(β)⋅sin(γ) + 1.0⋅cos(α)⋅cos(γ) sin(α)⋅sin(β)⋅c ⎢ ⎣ -1.0⋅sin(β) 1.0⋅sin(γ)⋅cos(β) 1.0⋅ γ) + sin(β)⋅cos(α)⋅cos(γ)⎤ ⎥ os(γ) - 1.0⋅sin(γ)⋅cos(α)⎥ ⎥ cos(β)⋅cos(γ) ⎦ ```python RugT = (rotz(pi) * roty(-pi/2)).T pprint(RugT) ``` ⎡0 0 1.0⎤ ⎢ ⎥ ⎢0 -1.0 0 ⎥ ⎢ ⎥ ⎣1 0 0 ⎦ ```python R36 = R03T * R0u * RugT pprint(R36) ``` ⎡(1.0⋅sin(α)⋅sin(γ) + sin(β)⋅cos(α)⋅cos(γ))⋅sin(q₂ + q₃)⋅cos(q₁) + (sin(α)⋅sin ⎢ ⎢(1.0⋅sin(α)⋅sin(γ) + sin(β)⋅cos(α)⋅cos(γ))⋅cos(q₁)⋅cos(q₂ + q₃) + (sin(α)⋅sin ⎢ ⎣ -(1.0⋅sin(α)⋅sin(γ) + sin(β)⋅cos(α)⋅cos(γ))⋅sin( (β)⋅cos(γ) - 1.0⋅sin(γ)⋅cos(α))⋅sin(q₁)⋅sin(q₂ + q₃) + 1.0⋅cos(β)⋅cos(γ)⋅cos(q (β)⋅cos(γ) - 1.0⋅sin(γ)⋅cos(α))⋅sin(q₁)⋅cos(q₂ + q₃) - 1.0⋅sin(q₂ + q₃)⋅cos(β) q₁) + (sin(α)⋅sin(β)⋅cos(γ) - 1.0⋅sin(γ)⋅cos(α))⋅cos(q₁) ₂ + q₃) -1.0⋅(-1.0⋅sin(α)⋅cos(γ) + sin(β)⋅sin(γ)⋅cos(α))⋅sin(q₂ + q₃)⋅cos(q₁) ⋅cos(γ) -1.0⋅(-1.0⋅sin(α)⋅cos(γ) + sin(β)⋅sin(γ)⋅cos(α))⋅cos(q₁)⋅cos(q₂ + q₃) 1.0⋅(-1.0⋅sin(α)⋅cos(γ) + sin(β)⋅sin(γ) - 1.0⋅(sin(α)⋅sin(β)⋅sin(γ) + 1.0⋅cos(α)⋅cos(γ))⋅sin(q₁)⋅sin(q₂ + q₃) - 1.0⋅s - 1.0⋅(sin(α)⋅sin(β)⋅sin(γ) + 1.0⋅cos(α)⋅cos(γ))⋅sin(q₁)⋅cos(q₂ + q₃) + 1.0⋅s ⋅cos(α))⋅sin(q₁) - 1.0⋅(sin(α)⋅sin(β)⋅sin(γ) + 1.0⋅cos(α)⋅cos(γ))⋅cos(q₁) in(γ)⋅cos(β)⋅cos(q₂ + q₃) 1.0⋅sin(α)⋅sin(q₁)⋅sin(q₂ + q₃)⋅cos(β) - 1.0⋅sin(β) in(γ)⋅sin(q₂ + q₃)⋅cos(β) 1.0⋅sin(α)⋅sin(q₁)⋅cos(β)⋅cos(q₂ + q₃) + 1.0⋅sin(β) 1.0⋅sin(α)⋅cos(β)⋅cos(q₁) ⋅cos(q₂ + q₃) + 1.0⋅sin(q₂ + q₃)⋅cos(α)⋅cos(β)⋅cos(q₁)⎤ ⎥ ⋅sin(q₂ + q₃) + 1.0⋅cos(α)⋅cos(β)⋅cos(q₁)⋅cos(q₂ + q₃)⎥ ⎥ - 1.0⋅sin(q₁)⋅cos(α)⋅cos(β) ⎦ ```python q1, q2, q3, q4, q5, q6= symbols('q1:7') R03 = Matrix([ [sin(q2 + q3)*cos(q1), cos(q1)*cos(q2 + q3), -sin(q1)], [sin(q1)*sin(q2 + q3), sin(q1)*cos(q2 + q3), cos(q1)], [ cos(q2 + q3), -sin(q2 + q3), 0]]) R03T = R03.T alpha, beta, gamma = symbols('alpha beta gamma') R0u = rotz(alpha) * roty(beta) * rotx(gamma) RugT = (rotz(pi) * roty(-pi/2)).T R36 = R03T * R0u * RugT roll, pitch, yaw = 0.366, -0.078, 2.561 variables = { q1: 1.01249, q2: -0.2758, q3: -0.11568, alpha: yaw, beta: pitch, gamma: roll } R0g = R0u * Rug R36eval = R36.evalf(subs = variables) pprint(R36eval) print(get_spherical_ik(R36eval)) ``` ⎡ 0.724598074610823 -0.686235503719083 0.0635489079820028⎤ ⎢ ⎥ ⎢ 0.684428504026748 0.727345057020894 0.0502671950976013⎥ ⎢ ⎥ ⎣-0.0807171180481332 0.00707117123884714 0.996711967115533 ⎦ (0.756897144385541, 0.0808050247662215, 0.00709437915922838) ```python print(simplify(R03I) == R03.T) print(Rug == Rug.T) ``` True True ```python R03 = Matrix([ [sin(q2 + q3)*cos(q1), cos(q1)*cos(q2 + q3), -sin(q1)], [sin(q1)*sin(q2 + q3), sin(q1)*cos(q2 + q3), cos(q1)], [ cos(q2 + q3), -sin(q2 + q3), 0]]) roll, pitch, yaw = 0.366, -0.078, 2.561 R0u = rotz(yaw)* roty(pitch) * rotx(roll) Rug = (rotz(pi) * roty(-pi/2)).T R0u.evalf(subs = {alpha: yaw, beta: pitch, gamma: roll}) R36eval2 = R36.evalf(subs = {q1: 1.01249, q2: -0.2758, q3: -0.11568}) pprint(R36eval2) ``` ⎡ 0.724598074610823 -0.686235503719083 0.0635489079820028⎤ ⎢ ⎥ ⎢ 0.684428504026748 0.727345057020894 0.0502671950976012⎥ ⎢ ⎥ ⎣-0.0807171180481332 0.00707117123884723 0.996711967115533 ⎦ ```python def ik(R): r12, r13 = R[0,1], R[0,2] r21, r22, r23 = R[1,0], R[1,1], R[1,2] r32, r33 = R[2,1], R[2,2] q5 = atan2(sqrt(r13**2 + r33**2), r23) q4 = atan2(r33, -r13) q6 = atan2(-r22, r21) return q4.evalf(), q5.evalf(), q6.evalf() print(ik(R36eval)) print(R36eval) ``` (1.63446868902482, 1.52050793847535, -0.815787839019348) Matrix([[0.724598074610823, -0.686235503719083, 0.0635489079820028], [0.684428504026748, 0.727345057020894, 0.0502671950976013], [-0.0807171180481332, 0.00707117123884714, 0.996711967115533]]) ```python R0g = rotz(yaw) * roty(pitch) * rotx(roll) * Rug print(R0g) ``` Matrix([[0.257143295038827, 0.488872082559650, -0.833595473062544], [0.259329420712765, 0.796053601157403, 0.546851822377060], [0.930927267496960, -0.356795110642117, 0.0779209320563015]]) ```python R03T_eval =R03T.evalf(subs = { q1: 1.01249, q2: -0.2758, q3: -0.11568}) pprint(R03T_eval) pprint(R03T) ``` ⎡-0.202129925357168 -0.323618808899201 0.924345368248129⎤ ⎢ ⎥ ⎢0.489672387232293 0.783986806638987 0.381556863649747⎥ ⎢ ⎥ ⎣-0.848153551226034 0.529750463466212 0 ⎦ ⎡sin(q₂ + q₃)⋅cos(q₁) sin(q₁)⋅sin(q₂ + q₃) cos(q₂ + q₃) ⎤ ⎢ ⎥ ⎢cos(q₁)⋅cos(q₂ + q₃) sin(q₁)⋅cos(q₂ + q₃) -sin(q₂ + q₃)⎥ ⎢ ⎥ ⎣ -sin(q₁) cos(q₁) 0 ⎦ ```python ```
If $z$ is a complex number with norm $1$, then there exists a real number $t$ such that $0 \leq t < 2\pi$ and $z = \cos(t) + i \sin(t)$.
[STATEMENT] lemma has_derivative_imp_has_field_derivative: "(f has_derivative D) F \<Longrightarrow> (\<And>x. x * D' = D x) \<Longrightarrow> (f has_field_derivative D') F" [PROOF STATE] proof (prove) goal (1 subgoal): 1. \<lbrakk>(f has_derivative D) F; \<And>x. x * D' = D x\<rbrakk> \<Longrightarrow> (f has_field_derivative D') F [PROOF STEP] unfolding has_field_derivative_def [PROOF STATE] proof (prove) goal (1 subgoal): 1. \<lbrakk>(f has_derivative D) F; \<And>x. x * D' = D x\<rbrakk> \<Longrightarrow> (f has_derivative (*) D') F [PROOF STEP] by (rule has_derivative_eq_rhs[of f D]) (simp_all add: fun_eq_iff mult.commute)
!! R526 allocatable-stmt ! - F2008 addition ! - allocatable component can be of recursive type ! program recursive_type TYPE NODE ! Define a "recursive" type INTEGER :: value = 0 TYPE(NODE), POINTER :: next_node => NULL() END TYPE NODE type(NODE) :: recursive_t allocatable :: recursive_t end program
lemma pairwise_orthogonal_imp_finite: fixes S :: "'a::euclidean_space set" assumes "pairwise orthogonal S" shows "finite S"
[STATEMENT] lemma inL2': "F, G, H, \<Gamma> \<Rightarrow> \<Delta> \<down> n \<Longrightarrow> G, H, F, \<Gamma> \<Rightarrow> \<Delta> \<down> n" [PROOF STATE] proof (prove) goal (1 subgoal): 1. F, G, H, \<Gamma> \<Rightarrow> \<Delta> \<down> n \<Longrightarrow> G, H, F, \<Gamma> \<Rightarrow> \<Delta> \<down> n [PROOF STEP] by(simp add: add_mset_commute)
Spring Songs with Music ; Blackie , 1923
function [C,T]=hungarian(A) % HUNGARIAN - Solve the assignment problem using the Hungarian method. % % Usage: >> [C,T]=hungarian(A) % % Inputs: % A - a square (correlation/distance/cost) matrix. % C - the optimal assignment (closest row/col pairs) % T - the total (minimized) cost of the optimal assignment. % % Author: Niclas Borlin, 1996 % Adapted from the FORTRAN IV code in Carpaneto and Toth, "Algorithm 548: % Solution of the assignment problem [H]", ACM Transactions on % Mathematical Software, 6(1):104-111, 1980. % % v1.0 96-06-14. Niclas Borlin, [email protected]. % Department of Computing Science, Ume University, % Sweden. % % NOTE: A substantial effort was put into this code. If you use it for a % publication or otherwise, please include an acknowledgement and notify % me by email. /Niclas [m,n]=size(A); if (m~=n) error('HUNGARIAN: Cost matrix must be square!'); end % Save original cost matrix. orig=A; % Reduce matrix. A=hminired(A); % Do an initial assignment. [A,C,U]=hminiass(A); % Repeat while we have unassigned rows. while (U(n+1)) % Start with no path, no unchecked zeros, and no unexplored rows. LR=zeros(1,n); LC=zeros(1,n); CH=zeros(1,n); RH=[zeros(1,n) -1]; % No labelled columns. SLC=[]; % Start path in first unassigned row. r=U(n+1); % Mark row with end-of-path label. LR(r)=-1; % Insert row first in labelled row set. SLR=r; % Repeat until we manage to find an assignable zero. while (1) % If there are free zeros in row r if (A(r,n+1)~=0) % ...get column of first free zero. l=-A(r,n+1); % If there are more free zeros in row r and row r in not % yet marked as unexplored.. if (A(r,l)~=0 && RH(r)==0) % Insert row r first in unexplored list. RH(r)=RH(n+1); RH(n+1)=r; % Mark in which column the next unexplored zero in this row % is. CH(r)=-A(r,l); end else % If all rows are explored.. if (RH(n+1)<=0) % Reduce matrix. [A,CH,RH]=hmreduce(A,CH,RH,LC,LR,SLC,SLR); end % Re-start with first unexplored row. r=RH(n+1); % Get column of next free zero in row r. l=CH(r); % Advance "column of next free zero". CH(r)=-A(r,l); % If this zero is last in the list.. if (A(r,l)==0) % ...remove row r from unexplored list. RH(n+1)=RH(r); RH(r)=0; end end % While the column l is labelled, i.e. in path. while (LC(l)~=0) % If row r is explored.. if (RH(r)==0) % If all rows are explored.. if (RH(n+1)<=0) % Reduce cost matrix. [A,CH,RH]=hmreduce(A,CH,RH,LC,LR,SLC,SLR); end % Re-start with first unexplored row. r=RH(n+1); end % Get column of next free zero in row r. l=CH(r); % Advance "column of next free zero". CH(r)=-A(r,l); % If this zero is last in list.. if(A(r,l)==0) % ...remove row r from unexplored list. RH(n+1)=RH(r); RH(r)=0; end end % If the column found is unassigned.. if (C(l)==0) % Flip all zeros along the path in LR,LC. [A,C,U]=hmflip(A,C,LC,LR,U,l,r); % ...and exit to continue with next unassigned row. break; else % ...else add zero to path. % Label column l with row r. LC(l)=r; % Add l to the set of labelled columns. SLC=[SLC l]; % Continue with the row assigned to column l. r=C(l); % Label row r with column l. LR(r)=l; % Add r to the set of labelled rows. SLR=[SLR r]; end end end % Calculate the total cost. T=sum(orig(logical(sparse(C,1:size(orig,2),1)))); function A=hminired(A) %HMINIRED Initial reduction of cost matrix for the Hungarian method. % %B=assredin(A) %A - the unreduced cost matris. %B - the reduced cost matrix with linked zeros in each row. % v1.0 96-06-13. Niclas Borlin, [email protected]. [m,n]=size(A); % Subtract column-minimum values from each column. colMin=min(A); A=A-colMin(ones(n,1),:); % Subtract row-minimum values from each row. rowMin=min(A')'; A=A-rowMin(:,ones(1,n)); % Get positions of all zeros. [i,j]=find(A==0); % Extend A to give room for row zero list header column. A(1,n+1)=0; for k=1:n % Get all column in this row. cols=j(k==i)'; % Insert pointers in matrix. A(k,[n+1 cols])=[-cols 0]; end function [A,C,U]=hminiass(A) %HMINIASS Initial assignment of the Hungarian method. % %[B,C,U]=hminiass(A) %A - the reduced cost matrix. %B - the reduced cost matrix, with assigned zeros removed from lists. %C - a vector. C(J)=I means row I is assigned to column J, % i.e. there is an assigned zero in position I,J. %U - a vector with a linked list of unassigned rows. % v1.0 96-06-14. Niclas Borlin, [email protected]. [n,np1]=size(A); % Initialize return vectors. C=zeros(1,n); U=zeros(1,n+1); % Initialize last/next zero "pointers". LZ=zeros(1,n); NZ=zeros(1,n); for i=1:n % Set j to first unassigned zero in row i. lj=n+1; j=-A(i,lj); % Repeat until we have no more zeros (j==0) or we find a zero % in an unassigned column (c(j)==0). while (C(j)~=0) % Advance lj and j in zero list. lj=j; j=-A(i,lj); % Stop if we hit end of list. if (j==0) break; end end if (j~=0) % We found a zero in an unassigned column. % Assign row i to column j. C(j)=i; % Remove A(i,j) from unassigned zero list. A(i,lj)=A(i,j); % Update next/last unassigned zero pointers. NZ(i)=-A(i,j); LZ(i)=lj; % Indicate A(i,j) is an assigned zero. A(i,j)=0; else % We found no zero in an unassigned column. % Check all zeros in this row. lj=n+1; j=-A(i,lj); % Check all zeros in this row for a suitable zero in another row. while (j~=0) % Check the in the row assigned to this column. r=C(j); % Pick up last/next pointers. lm=LZ(r); m=NZ(r); % Check all unchecked zeros in free list of this row. while (m~=0) % Stop if we find an unassigned column. if (C(m)==0) break; end % Advance one step in list. lm=m; m=-A(r,lm); end if (m==0) % We failed on row r. Continue with next zero on row i. lj=j; j=-A(i,lj); else % We found a zero in an unassigned column. % Replace zero at (r,m) in unassigned list with zero at (r,j) A(r,lm)=-j; A(r,j)=A(r,m); % Update last/next pointers in row r. NZ(r)=-A(r,m); LZ(r)=j; % Mark A(r,m) as an assigned zero in the matrix . . . A(r,m)=0; % ...and in the assignment vector. C(m)=r; % Remove A(i,j) from unassigned list. A(i,lj)=A(i,j); % Update last/next pointers in row r. NZ(i)=-A(i,j); LZ(i)=lj; % Mark A(r,m) as an assigned zero in the matrix . . . A(i,j)=0; % ...and in the assignment vector. C(j)=i; % Stop search. break; end end end end % Create vector with list of unassigned rows. % Mark all rows have assignment. r=zeros(1,n); rows=C(C~=0); r(rows)=rows; empty=find(r==0); % Create vector with linked list of unassigned rows. U=zeros(1,n+1); U([n+1 empty])=[empty 0]; function [A,C,U]=hmflip(A,C,LC,LR,U,l,r) %HMFLIP Flip assignment state of all zeros along a path. % %[A,C,U]=hmflip(A,C,LC,LR,U,l,r) %Input: %A - the cost matrix. %C - the assignment vector. %LC - the column label vector. %LR - the row label vector. %U - the %r,l - position of last zero in path. %Output: %A - updated cost matrix. %C - updated assignment vector. %U - updated unassigned row list vector. % v1.0 96-06-14. Niclas Borlin, [email protected]. n=size(A,1); while (1) % Move assignment in column l to row r. C(l)=r; % Find zero to be removed from zero list.. % Find zero before this. m=find(A(r,:)==-l); % Link past this zero. A(r,m)=A(r,l); A(r,l)=0; % If this was the first zero of the path.. if (LR(r)<0) % remove row from unassigned row list and return. U(n+1)=U(r); U(r)=0; return; else % Move back in this row along the path and get column of next zero. l=LR(r); % Insert zero at (r,l) first in zero list. A(r,l)=A(r,n+1); A(r,n+1)=-l; % Continue back along the column to get row of next zero in path. r=LC(l); end end function [A,CH,RH]=hmreduce(A,CH,RH,LC,LR,SLC,SLR) %HMREDUCE Reduce parts of cost matrix in the Hungerian method. % %[A,CH,RH]=hmreduce(A,CH,RH,LC,LR,SLC,SLR) %Input: %A - Cost matrix. %CH - vector of column of 'next zeros' in each row. %RH - vector with list of unexplored rows. %LC - column labels. %RC - row labels. %SLC - set of column labels. %SLR - set of row labels. % %Output: %A - Reduced cost matrix. %CH - Updated vector of 'next zeros' in each row. %RH - Updated vector of unexplored rows. % v1.0 96-06-14. Niclas Borlin, [email protected]. n=size(A,1); % Find which rows are covered, i.e. unlabelled. coveredRows=LR==0; % Find which columns are covered, i.e. labelled. coveredCols=LC~=0; r=find(~coveredRows); c=find(~coveredCols); % Get minimum of uncovered elements. m=min(min(A(r,c))); % Subtract minimum from all uncovered elements. A(r,c)=A(r,c)-m; % Check all uncovered columns.. for j=c % ...and uncovered rows in path order.. for i=SLR % If this is a (new) zero.. if (A(i,j)==0) % If the row is not in unexplored list.. if (RH(i)==0) % ...insert it first in unexplored list. RH(i)=RH(n+1); RH(n+1)=i; % Mark this zero as "next free" in this row. CH(i)=j; end % Find last unassigned zero on row I. row=A(i,:); colsInList=-row(row<0); if (length(colsInList)==0) % No zeros in the list. l=n+1; else l=colsInList(row(colsInList)==0); end % Append this zero to end of list. A(i,l)=-j; end end end % Add minimum to all doubly covered elements. r=find(coveredRows); c=find(coveredCols); % Take care of the zeros we will remove. [i,j]=find(A(r,c)<=0); i=r(i); j=c(j); for k=1:length(i) % Find zero before this in this row. lj=find(A(i(k),:)==-j(k)); % Link past it. A(i(k),lj)=A(i(k),j(k)); % Mark it as assigned. A(i(k),j(k))=0; end A(r,c)=A(r,c)+m;
(* This program 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 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 Lesser General Public *) (* License along with this program; if not, write to the Free *) (* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *) (* 02110-1301 USA *) Require Export angles_vecteurs. Set Implicit Arguments. Unset Strict Implicit. (* Le plan est orienté et on utilise le cercle trigonométrique*) Definition repere_orthonormal_direct (O I J : PO) := image_angle pisurdeux = cons_AV (vec O I) (vec O J) /\ scalaire (vec O I) (vec O I) = 1 /\ scalaire (vec O J) (vec O J) = 1. Parameter cos : R -> R. Parameter sin : R -> R. Parameter Cos : AV -> R. Parameter Sin : AV -> R. (* cosinus et sinus d'un angle (ou d'un réel) sont obtenus par projections du point image du cercle trigonométrique sur les axes de coordonnées*) Axiom def_cos : forall (A B C : PO) (x : R), distance A B = 1 -> distance A C = 1 -> image_angle x = cons_AV (vec A B) (vec A C) -> cos x = scalaire (vec A B) (vec A C). Axiom def_sin : forall (A B C D : PO) (x : R), distance A B = 1 -> distance A C = 1 -> image_angle x = cons_AV (vec A B) (vec A C) -> repere_orthonormal_direct A B D -> sin x = scalaire (vec A C) (vec A D). Axiom def_Cos : forall A B C : PO, distance A B = 1 -> distance A C = 1 -> Cos (cons_AV (vec A B) (vec A C)) = scalaire (vec A B) (vec A C). Axiom def_Sin : forall A B C D : PO, distance A B = 1 -> distance A C = 1 -> repere_orthonormal_direct A B D -> Sin (cons_AV (vec A B) (vec A C)) = scalaire (vec A C) (vec A D). Lemma ROND_RON : forall O I J : PO, repere_orthonormal_direct O I J -> repere_orthonormal O I J. unfold repere_orthonormal_direct, repere_orthonormal in |- *; intros. elim H; intros H0 H1; try clear H; try exact H1. split; [ auto with geo | try assumption ]. Qed. Hint Resolve ROND_RON: geo. Definition repere_orthonormal_indirect (O I J : PO) := image_angle pisurdeux = cons_AV (vec O J) (vec O I) /\ scalaire (vec O I) (vec O I) = 1 /\ scalaire (vec O J) (vec O J) = 1. Lemma ROND_RONI : forall O I J : PO, repere_orthonormal_direct O I J -> repere_orthonormal_indirect O J I. unfold repere_orthonormal_indirect, repere_orthonormal_direct in |- *. intros O I J H; try assumption. elim H; intros H0 H1; try clear H; try exact H1. elim H1; intros H H2; try clear H1; try exact H2. split; [ auto | split; [ auto | try assumption ] ]. Qed. Lemma ROND_new : forall O I J K : PO, repere_orthonormal_direct O I J -> vec O K = mult_PP (-1) (vec O I) -> repere_orthonormal_direct O J K. unfold repere_orthonormal_indirect, repere_orthonormal_direct in |- *. intros O I J K H H0; try assumption. elim H; intros H1 H2; elim H2; intros H3 H4; try clear H2 H; try exact H4. cut (scalaire (vec O K) (vec O K) = 1); intros. split; [ auto | split; [ auto | try assumption ] ]. replace pisurdeux with (- pisurdeux + pi). cut (image_angle (- pisurdeux) = cons_AV (vec O J) (vec O I)); intros. cut (image_angle pi = cons_AV (vec O I) (vec O K)); intros. rewrite add_mes_compatible. rewrite H5; rewrite H2; rewrite Chasles; auto with geo. replace (vec O K) with (vec I O). rewrite <- angle_plat; auto with geo. rewrite H0. unfold vec in |- *; RingPP. apply mes_oppx; auto with geo. unfold pi in |- *; ring. rewrite H0. Simplscal; rewrite H3; ring. Qed. Lemma existence_ROND_AB : forall A B : PO, distance A B = 1 -> exists C : PO, repere_orthonormal_direct A B C. intros. elim existence_representant_angle with (A := A) (B := B) (C := A) (x := pisurdeux); [ intros C H0; elim H0; intros H1 H2; try clear H0; try exact H2 | auto ]. exists C; unfold repere_orthonormal_direct in |- *. split; [ try assumption | idtac ]. split; auto with geo. Qed. Lemma cos_deux_mes : forall x y : R, image_angle x = image_angle y -> cos x = cos y. intros. elim existence_AB_unitaire; intros A H1; elim H1; intros B H0; try clear H1. elim existence_representant_angle with (A := A) (B := B) (C := A) (x := x); [ intros C H1; elim H1; intros; try clear H1 | auto ]. rewrite (def_cos (A:=A) (B:=B) (C:=C) (x:=x)); auto. rewrite (def_cos (A:=A) (B:=B) (C:=C) (x:=y)); auto. rewrite <- H3; auto. Qed. Lemma cos_paire : forall x : R, cos (- x) = cos x. intros. elim existence_AB_unitaire; intros A H; elim H; intros B H0; try clear H; try exact H0. elim existence_representant_angle with (A := A) (B := B) (C := A) (x := x); [ intros C H; elim H; intros H1 H2; try clear H; try exact H2 | auto ]. rewrite (def_cos (A:=A) (B:=B) (C:=C) (x:=x)); auto. cut (image_angle (- x) = cons_AV (vec A C) (vec A B)); intros. rewrite (def_cos (A:=A) (B:=C) (C:=B) (x:=- x)); auto. rewrite scalaire_sym; auto. apply mes_oppx; auto with geo. Qed. Lemma cos_periodique : forall x : R, cos (x + deuxpi) = cos x. intros. elim existence_AB_unitaire; intros A H; elim H; intros B H0; try clear H; try exact H0. elim existence_representant_angle with (A := A) (B := B) (C := A) (x := x); [ intros C H; elim H; intros H1 H2; try clear H; try exact H2 | auto ]. rewrite (def_cos (A:=A) (B:=B) (C:=C) (x:=x)); auto. cut (image_angle (x + deuxpi) = cons_AV (vec A B) (vec A C)); intros. rewrite (def_cos (A:=A) (B:=B) (C:=C) (x:=x + deuxpi)); auto. apply mesure_mod_deuxpi; auto with geo. Qed. Lemma sin_deux_mes : forall x y : R, image_angle x = image_angle y -> sin x = sin y. intros. elim existence_AB_unitaire; intros A H1; elim H1; clear H1; intros B H0. elim existence_ROND_AB with (A := A) (B := B); [ intros D H10 | auto ]. elim existence_representant_angle with (A := A) (B := B) (C := A) (x := x); [ intros C H1; elim H1; intros; try clear H1 | auto ]. rewrite (def_sin (A:=A) (B:=B) (C:=C) (D:=D) (x:=x)); auto. rewrite (def_sin (A:=A) (B:=B) (C:=C) (D:=D) (x:=y)); auto. rewrite <- H3; auto. Qed. Lemma sin_periodique : forall x : R, sin (x + deuxpi) = sin x. intros. elim existence_AB_unitaire; intros A H; elim H; intros B H0; try clear H; try exact H0. elim existence_ROND_AB with (A := A) (B := B); [ intros D H10 | auto ]. elim existence_representant_angle with (A := A) (B := B) (C := A) (x := x); [ intros C H; elim H; intros H1 H2; try clear H; try exact H2 | auto ]. rewrite (def_sin (A:=A) (B:=B) (C:=C) (D:=D) (x:=x)); auto. cut (image_angle (x + deuxpi) = cons_AV (vec A B) (vec A C)); intros. rewrite (def_sin (A:=A) (B:=B) (C:=C) (D:=D) (x:=x + deuxpi)); auto. apply mesure_mod_deuxpi; auto with geo. Qed. Lemma sin_cos_pisurdeux_moins_x : forall x : R, sin x = cos (pisurdeux + - x). intros. elim existence_AB_unitaire; intros A H; elim H; intros B H0; try clear H; try exact H0. elim existence_representant_angle with (A := A) (B := B) (C := A) (x := x); [ intros C H; elim H; intros H1 H2; try clear H; try exact H2 | auto ]. elim existence_ROND_AB with (A := A) (B := B); [ intros D H; try exact H | auto ]. rewrite (def_sin (A:=A) (B:=B) (C:=C) (D:=D) (x:=x)); auto. cut (image_angle (- x) = cons_AV (vec A C) (vec A B)); intros. replace (pisurdeux + - x) with (- x + pisurdeux); try ring. elim H; intros. elim H5; intros H6 H7; try clear H5; try exact H7. rewrite (def_cos (A:=A) (B:=C) (C:=D) (x:=- x + pisurdeux)); auto with geo. rewrite add_mes_compatible. rewrite H3; rewrite H4; rewrite Chasles; auto with geo. apply mes_oppx; auto with geo. Qed. Lemma cos_sin_pisurdeux_moins_x : forall x : R, cos x = sin (pisurdeux + - x). intros. rewrite sin_cos_pisurdeux_moins_x. replace (pisurdeux + - (pisurdeux + - x)) with x; try ring. Qed. Lemma cos_zero : cos 0 = 1. elim existence_AB_unitaire; intros A H; elim H; intros B H0; try clear H; try exact H0. rewrite (def_cos (A:=A) (B:=B) (C:=B) (x:=0)); auto with geo. rewrite <- angle_nul; auto with geo. Qed. Lemma sin_zero : sin 0 = 0. elim existence_AB_unitaire; intros A H; elim H; intros B H0; try clear H; try exact H0. elim existence_ROND_AB with (A := A) (B := B); [ intros D H | auto ]. elim H; intros. rewrite (def_sin (A:=A) (B:=B) (C:=B) (D:=D) (x:=0)); auto with geo. rewrite <- angle_nul; auto with geo. Qed. Lemma cos_pisurdeux : cos pisurdeux = 0. elim existence_AB_unitaire; intros A H; elim H; intros B H0; try clear H; try exact H0. elim existence_ROND_AB with (A := A) (B := B); [ intros D H | auto ]. elim H; intros. elim H2; intros H3 H4; try clear H2; try exact H4. rewrite (def_cos (A:=A) (B:=B) (C:=D) (x:=pisurdeux)); auto with geo. Qed. Lemma sin_pisurdeux : sin pisurdeux = 1. elim existence_AB_unitaire; intros A H; elim H; intros B H0; try clear H; try exact H0. elim existence_ROND_AB with (A := A) (B := B); [ intros D H | auto ]. elim H; intros. elim H2; intros H3 H4; try clear H2; try exact H4. rewrite (def_sin (A:=A) (B:=B) (C:=D) (D:=D) (x:=pisurdeux)); auto with geo. Qed. Lemma cos_pi : cos pi = -1. elim existence_AB_unitaire; intros A H; elim H; intros B H0; try clear H; try exact H0. elim existence_representant_mult_vecteur with (A := A) (B := A) (C := B) (k := -1); intros D H1. cut (scalaire (vec A D) (vec A D) = 1); intros. rewrite (def_cos (A:=A) (B:=B) (C:=D) (x:=pi)); auto with geo. rewrite H1. Simplscal; rewrite carre_scalaire_distance; rewrite H0; ring. replace (vec A D) with (vec B A). rewrite <- angle_plat; auto with geo. rewrite H1. Ringvec. rewrite H1. Simplscal; rewrite carre_scalaire_distance; rewrite H0; ring. Qed. Lemma sin_pi : sin pi = 0. elim existence_AB_unitaire; intros A H; elim H; intros B H0; try clear H; try exact H0. elim existence_ROND_AB with (A := A) (B := B); [ intros D H | auto ]. elim H; intros. elim H2; intros H4 H5; try clear H2; try exact H4. elim existence_representant_mult_vecteur with (A := A) (B := A) (C := B) (k := -1); intros E H3. rewrite (def_sin (A:=A) (B:=B) (C:=E) (D:=D) (x:=pi)); auto. rewrite H3. cut (scalaire (vec A B) (vec A D) = 0); auto with geo; intros. Simplscal; rewrite H2; ring. cut (scalaire (vec A E) (vec A E) = 1); auto with geo; intros. rewrite H3. Simplscal; rewrite H4; ring. replace (vec A E) with (vec B A). rewrite <- angle_plat; auto with geo. rewrite H3. Ringvec. Qed. Lemma coordonnees_cos_sin : forall (x : R) (O I J M : PO), repere_orthonormal_direct O I J -> image_angle x = cons_AV (vec O I) (vec O M) -> distance O M = 1 -> vec O M = add_PP (mult_PP (cos x) (vec O I)) (mult_PP (sin x) (vec O J)) :>PP. intros. elim H; intros. elim H3; intros H4 H5; try clear H3; try exact H5. rewrite (def_sin (A:=O) (B:=I) (C:=M) (D:=J) (x:=x)); auto with geo. rewrite (def_cos (A:=O) (B:=I) (C:=M) (x:=x)); auto with geo. pattern (vec O M) at 1 in |- *. rewrite (coordonnees_scalaire_base (O:=O) (I:=I) (J:=J) M); auto with geo. rewrite scalaire_sym; auto. Qed. Lemma calcul_cos_sin : forall (x a b : R) (O I J M : PO), repere_orthonormal_direct O I J -> image_angle x = cons_AV (vec O I) (vec O M) -> distance O M = 1 -> vec O M = add_PP (mult_PP a (vec O I)) (mult_PP b (vec O J)) :>PP -> a = cos x /\ b = sin x. intros. apply unicite_coordonnees with (2 := H2); auto with geo. apply coordonnees_cos_sin; auto. Qed. Lemma trigo_Pythagore : forall x : R, Rsqr (cos x) + Rsqr (sin x) = 1. unfold Rsqr in |- *; intros. elim existence_AB_unitaire; intros A H; elim H; intros B H0; try clear H; try exact H0. elim existence_representant_angle with (A := A) (B := B) (C := A) (x := x); [ intros C H; elim H; intros H1 H2; try clear H; try exact H2 | auto ]. elim existence_ROND_AB with (A := A) (B := B); [ intros D H | auto ]. elim H; intros. cut (vec A C = add_PP (mult_PP (cos x) (vec A B)) (mult_PP (sin x) (vec A D))); intros. replace 1 with (scalaire (vec A C) (vec A C)); auto with geo. rewrite H5. Simplscal. elim H4; intros H6 H7; try clear H4; try exact H7. rewrite H7; rewrite H6. rewrite (pisurdeux_scalaire_nul (A:=A) (B:=B) (C:=D)); auto. rewrite scalaire_sym. rewrite (pisurdeux_scalaire_nul (A:=A) (B:=B) (C:=D)); auto. ring. apply coordonnees_cos_sin; auto. Qed. Lemma pisurdeux_plus_x : forall x : R, cos (pisurdeux + x) = - sin x /\ sin (pisurdeux + x) = cos x. intros. elim existence_AB_unitaire; intros A H; elim H; intros B H0; try clear H; try exact H0. elim existence_ROND_AB with (A := A) (B := B); [ intros D H10 | auto ]. elim existence_representant_angle with (A := A) (B := B) (C := A) (x := pisurdeux + x); [ intros C H; elim H; intros H1 H2; try clear H; try exact H2 | auto ]. elim H10; intros. elim H3; intros H6 H7; try clear H3; try exact H7. elim existence_representant_mult_vecteur with (A := A) (B := A) (C := B) (k := -1); intros E H4. cut (image_angle x = cons_AV (vec A D) (vec A C)); intros. generalize (coordonnees_cos_sin (x:=pisurdeux + x) (O:=A) (I:=B) (J:=D) (M:=C)); intros. generalize (coordonnees_cos_sin (x:=x) (O:=A) (I:=D) (J:=E) (M:=C)); intros. cut (vec A C = add_PP (mult_PP (- sin x) (vec A B)) (mult_PP (cos x) (vec A D))); intros. apply unicite_coordonnees with (3 := H9); auto with geo. rewrite H8; auto. rewrite H4. unfold vec in |- *; RingPP. apply ROND_new with B; auto. replace x with (- pisurdeux + (pisurdeux + x)); try ring. replace (cons_AV (vec A D) (vec A C)) with (plus (cons_AV (vec A D) (vec A B)) (cons_AV (vec A B) (vec A C))). replace (cons_AV (vec A D) (vec A B)) with (image_angle (- pisurdeux)). rewrite <- H2. apply add_mes_compatible. apply mes_oppx; auto with geo. apply Chasles; auto with geo. Qed. Lemma sin_impaire : forall x : R, sin (- x) = - sin x. intros. elim pisurdeux_plus_x with (x := - x); intros H H0; try clear pisurdeux_plus_x; try exact H. replace (sin (- x)) with (-1 * - sin (- x)). rewrite <- H. replace (- x + pisurdeux) with (pisurdeux + - x). rewrite <- sin_cos_pisurdeux_moins_x. ring. ring. ring. Qed. Lemma pi_moins_x : forall x : R, cos (pi + - x) = - cos x /\ sin (pi + - x) = sin x. intros. unfold pi in |- *. replace (pisurdeux + pisurdeux + - x) with (pisurdeux + (pisurdeux + - x)). elim pisurdeux_plus_x with (x := pisurdeux + - x); intros H H0; try clear pisurdeux_plus_x; try exact H0. rewrite H0; rewrite H. split; [ try assumption | idtac ]. rewrite cos_sin_pisurdeux_moins_x; auto. rewrite sin_cos_pisurdeux_moins_x; auto. ring. Qed. Lemma pi_plus_x : forall x : R, cos (pi + x) = - cos x /\ sin (pi + x) = - sin x. intros. elim pi_moins_x with (x := - x); intros H H0; try clear pi_moins_x; try exact H0. replace (pi + x) with (pi + - - x). rewrite H0; rewrite H. split; [ try assumption | idtac ]. rewrite cos_paire; auto. rewrite sin_impaire; auto. ring. Qed. Theorem cos_diff : forall a b : R, cos (a + - b) = cos a * cos b + sin a * sin b. intros. elim existence_AB_unitaire; intros A H; elim H; intros B H0; try clear H; try exact H0. elim existence_ROND_AB with (A := A) (B := B); [ intros D H10 | auto ]. elim existence_representant_angle with (A := A) (B := B) (C := A) (x := a); [ intros C H; elim H; intros H1 H2; try clear H; try exact H2 | auto ]. elim existence_representant_angle with (A := A) (B := B) (C := A) (x := b); [ intros E H; elim H; intros H3 H4; try clear H; try exact H4 | auto ]. generalize (coordonnees_cos_sin (x:=a) (O:=A) (I:=B) (J:=D) (M:=C)); intros H. generalize (coordonnees_cos_sin (x:=b) (O:=A) (I:=B) (J:=D) (M:=E)); intros. replace (cos a * cos b + sin a * sin b) with (scalaire (vec A C) (vec A E)). cut (image_angle (a + - b) = cons_AV (vec A E) (vec A C)); intros. rewrite (def_cos (A:=A) (B:=E) (C:=C) (x:=a + - b)); auto. rewrite scalaire_sym; auto. replace (cons_AV (vec A E) (vec A C)) with (plus (cons_AV (vec A E) (vec A B)) (cons_AV (vec A B) (vec A C))). replace (cons_AV (vec A E) (vec A B)) with (image_angle (- b)). rewrite <- H2. replace (a + - b) with (- b + a). apply add_mes_compatible. ring. apply mes_oppx; auto with geo. apply Chasles; auto with geo. rewrite H5; auto. rewrite H; auto. Simplscal. elim H10; intros. elim H7; intros H8 H9; try clear H7; try exact H9. cut (scalaire (vec A B) (vec A D) = 0); auto with geo; intros. rewrite H9; rewrite H8; rewrite H7. rewrite scalaire_sym; rewrite H7. ring. Qed. Lemma cos_som : forall a b : R, cos (a + b) = cos a * cos b + - (sin a * sin b). intros. replace (a + b) with (a + - - b). rewrite (cos_diff a (- b)). rewrite cos_paire. rewrite sin_impaire. ring. ring. Qed. Lemma sin_som : forall a b : R, sin (a + b) = sin a * cos b + sin b * cos a. intros. replace (sin (a + b)) with (cos (pisurdeux + - (a + b))). replace (pisurdeux + - (a + b)) with (pisurdeux + - a + - b). rewrite cos_diff. rewrite <- sin_cos_pisurdeux_moins_x. rewrite <- cos_sin_pisurdeux_moins_x. ring. ring. rewrite <- sin_cos_pisurdeux_moins_x; auto. Qed. Lemma sin_diff : forall a b : R, sin (a + - b) = sin a * cos b + - (sin b * cos a). intros. rewrite sin_som. rewrite cos_paire. rewrite sin_impaire. ring. Qed. Lemma duplication_cos : forall a : R, cos (2 * a) = 2 * Rsqr (cos a) + -1. intros. repeat rewrite double. rewrite cos_som. rewrite <- (trigo_Pythagore a). unfold Rsqr; ring. Qed. Lemma duplication_cos2 : forall a : R, cos (2 * a) = 1 + - (2 * Rsqr (sin a)). intros. repeat rewrite double. rewrite cos_som. rewrite <- (trigo_Pythagore a). unfold Rsqr; ring. Qed. Lemma duplication_sin : forall a : R, sin (2 * a) = 2 * (sin a * cos a). intros. repeat rewrite double. rewrite sin_som; auto. Qed. Lemma coordonnees_polaires_cartesiennes : forall (x y a r : R) (O I J M : PO), repere_orthonormal_direct O I J -> O <> M -> r = distance O M -> image_angle a = cons_AV (vec O I) (vec O M) -> vec O M = add_PP (mult_PP x (vec O I)) (mult_PP y (vec O J)) :>PP -> x = r * cos a /\ y = r * sin a. intros. apply unicite_coordonnees with (2 := H3); auto with geo. elim existence_representant_unitaire with (A := O) (B := M); [ intros C H4; try clear existence_unitaire; try exact H4 | auto ]. rewrite (distance_vecteur (A:=O) (B:=M)); auto. rewrite <- H4. rewrite (coordonnees_cos_sin (x:=a) (O:=O) (I:=I) (J:=J) (M:=C)); auto. rewrite <- H1. unfold vec in |- *; RingPP. rewrite H2. rewrite H4. inversion H. elim H6; intros H7 H8; try clear H6; try exact H7. rewrite angles_representants_unitaires; auto with geo. replace (representant_unitaire (vec O I)) with (vec O I); auto with geo. elim def_representant_unitaire2 with (A := O) (B := M) (C := C); [ intros; elim H6; intros H7 H8; try clear H6 def_representant_unitaire2; auto with geo | auto | auto ]. Qed. Lemma trivial_cos_Cos : forall (A B C : PO) (x : R), distance A B = 1 -> distance A C = 1 -> image_angle x = cons_AV (vec A B) (vec A C) -> cos x = Cos (cons_AV (vec A B) (vec A C)). intros. rewrite (def_cos (A:=A) (B:=B) (C:=C) (x:=x)); auto. rewrite (def_Cos (A:=A) (B:=B) (C:=C)); auto. Qed. Lemma egalite_cos_Cos : forall (A B C : PO) (x : R), A <> B -> A <> C -> image_angle x = cons_AV (vec A B) (vec A C) -> cos x = Cos (cons_AV (vec A B) (vec A C)). intros. elim existence_representant_unitaire with (A := A) (B := B); [ intros B' H2; try clear existence_representant_unitaire; try exact H2 | auto ]. elim existence_representant_unitaire with (A := A) (B := C); [ intros C' H3; try clear existence_representant_unitaire; try exact H3 | auto ]. rewrite (trivial_cos_Cos (A:=A) (B:=B') (C:=C') (x:=x)); auto. rewrite H2; rewrite H3; auto. rewrite angles_representants_unitaires; auto. elim def_representant_unitaire2 with (A := A) (B := B) (C := B'); auto; intros. elim H5; auto with geo. elim def_representant_unitaire2 with (A := A) (B := C) (C := C'); auto; intros. elim H5; auto with geo. rewrite H2; rewrite H3; rewrite H1; rewrite angles_representants_unitaires; auto with geo. Qed. Lemma trivial_sin_Sin : forall (A B C D : PO) (x : R), distance A B = 1 -> distance A C = 1 -> image_angle x = cons_AV (vec A B) (vec A C) -> repere_orthonormal_direct A B D -> sin x = Sin (cons_AV (vec A B) (vec A C)). intros. rewrite (def_sin (A:=A) (B:=B) (C:=C) (D:=D) (x:=x)); auto. rewrite (def_Sin (A:=A) (B:=B) (C:=C) (D:=D)); auto. Qed. Lemma egalite_sin_Sin : forall (A B C : PO) (x : R), A <> B -> A <> C -> image_angle x = cons_AV (vec A B) (vec A C) -> sin x = Sin (cons_AV (vec A B) (vec A C)). intros. elim existence_representant_unitaire with (A := A) (B := B); [ intros B' H2; try clear existence_representant_unitaire; try exact H2 | auto ]. elim existence_ROND_AB with (A := A) (B := B'); [ intros D H10 | auto ]. elim existence_representant_unitaire with (A := A) (B := C); [ intros C' H3; try clear existence_representant_unitaire; try exact H3 | auto ]. rewrite (trivial_sin_Sin (A:=A) (B:=B') (C:=C') (D:=D) (x:=x)); auto. rewrite H2; rewrite H3; auto. rewrite angles_representants_unitaires; auto. elim def_representant_unitaire2 with (A := A) (B := B) (C := B'); auto; intros. elim H5; auto with geo. elim def_representant_unitaire2 with (A := A) (B := C) (C := C'); auto; intros. elim H5; auto with geo. rewrite H2; rewrite H3; rewrite H1; rewrite angles_representants_unitaires; auto. elim def_representant_unitaire2 with (A := A) (B := B) (C := B'); auto with geo; intros. elim H4; auto with geo. Qed. Lemma coordonnees_Cos_Sin : forall O I J M : PO, repere_orthonormal_direct O I J -> distance O M = 1 -> vec O M = add_PP (mult_PP (Cos (cons_AV (vec O I) (vec O M))) (vec O I)) (mult_PP (Sin (cons_AV (vec O I) (vec O M))) (vec O J)) :>PP. intros. elim H; intros. elim H2; intros H4 H5; try clear H2. mesure O I O M. rewrite H2. rewrite <- (trivial_sin_Sin (A:=O) (B:=I) (C:=M) (D:=J) (x:=x)); auto with geo. rewrite <- (trivial_cos_Cos (A:=O) (B:=I) (C:=M) (x:=x)); auto with geo. apply coordonnees_cos_sin; auto. Qed. Lemma calcul_Cos_Sin : forall (a b : R) (O I J M : PO), repere_orthonormal_direct O I J -> distance O M = 1 -> vec O M = add_PP (mult_PP a (vec O I)) (mult_PP b (vec O J)) :>PP -> a = Cos (cons_AV (vec O I) (vec O M)) /\ b = Sin (cons_AV (vec O I) (vec O M)). intros. elim H; intros. elim H3; intros H4 H5; try clear H3. mesure O I O M. rewrite H3. rewrite <- (trivial_sin_Sin (A:=O) (B:=I) (C:=M) (D:=J) (x:=x)); auto with geo. rewrite <- (trivial_cos_Cos (A:=O) (B:=I) (C:=M) (x:=x)); auto with geo. apply (calcul_cos_sin (x:=x) (a:=a) (b:=b) (O:=O) (I:=I) (J:=J) (M:=M)); auto. Qed. Axiom egalite_angle_trigo : forall x y : R, sin x = sin y -> cos x = cos y -> image_angle x = image_angle y. Hint Resolve egalite_angle_trigo: geo.
Formal statement is: lemma cohomotopically_trivial_retraction_null_gen: assumes P: "\<And>f. \<lbrakk>continuous_on t f; f ` t \<subseteq> U; Q f\<rbrakk> \<Longrightarrow> P(f \<circ> h)" and Q: "\<And>f. \<lbrakk>continuous_on s f; f ` s \<subseteq> U; P f\<rbrakk> \<Longrightarrow> Q(f \<circ> k)" and Qeq: "\<And>h k. (\<And>x. x \<in> t \<Longrightarrow> h x = k x) \<Longrightarrow> Q h = Q k" and hom: "\<And>f g. \<lbrakk>continuous_on s f; f ` s \<subseteq> U; P f\<rbrakk> \<Longrightarrow> \<exists>c. homotopic_with_canon P s U f (\<lambda>x. c)" and contf: "continuous_on t f" and imf: "f ` t \<subseteq> U" and Qf: "Q f" obtains c where "homotopic_with_canon Q t U f (\<lambda>x. c)" Informal statement is: If $f$ is a continuous map from a topological space $X$ to a topological space $Y$, and if $Y$ is compact, then $f$ is uniformly continuous.
State Before: α : Type u a : α inst✝³ : Group α inst✝² : DecidableEq α inst✝¹ : Fintype α inst✝ : IsCyclic α n : ℕ hn0 : 0 < n g : α hg : ∀ (x : α), x ∈ zpowers g x : α hx : x ∈ filter (fun a => a ^ n = 1) univ m : ℕ hm : (fun x x_1 => x ^ x_1) g m = x ⊢ (fun x x_1 => x ^ x_1) (g ^ (Fintype.card α / Nat.gcd n (Fintype.card α))) ↑(m / (Fintype.card α / Nat.gcd n (Fintype.card α))) = x State After: α : Type u a : α inst✝³ : Group α inst✝² : DecidableEq α inst✝¹ : Fintype α inst✝ : IsCyclic α n : ℕ hn0 : 0 < n g : α hg : ∀ (x : α), x ∈ zpowers g x : α hx : x ∈ filter (fun a => a ^ n = 1) univ m : ℕ hm : g ^ m = x ⊢ (fun x x_1 => x ^ x_1) (g ^ (Fintype.card α / Nat.gcd n (Fintype.card α))) ↑(m / (Fintype.card α / Nat.gcd n (Fintype.card α))) = x Tactic: dsimp at hm State Before: α : Type u a : α inst✝³ : Group α inst✝² : DecidableEq α inst✝¹ : Fintype α inst✝ : IsCyclic α n : ℕ hn0 : 0 < n g : α hg : ∀ (x : α), x ∈ zpowers g x : α hx : x ∈ filter (fun a => a ^ n = 1) univ m : ℕ hm : g ^ m = x ⊢ (fun x x_1 => x ^ x_1) (g ^ (Fintype.card α / Nat.gcd n (Fintype.card α))) ↑(m / (Fintype.card α / Nat.gcd n (Fintype.card α))) = x State After: α : Type u a : α inst✝³ : Group α inst✝² : DecidableEq α inst✝¹ : Fintype α inst✝ : IsCyclic α n : ℕ hn0 : 0 < n g : α hg : ∀ (x : α), x ∈ zpowers g x : α hx : x ∈ filter (fun a => a ^ n = 1) univ m : ℕ hm : g ^ m = x hgmn : g ^ (m * Nat.gcd n (Fintype.card α)) = 1 ⊢ (fun x x_1 => x ^ x_1) (g ^ (Fintype.card α / Nat.gcd n (Fintype.card α))) ↑(m / (Fintype.card α / Nat.gcd n (Fintype.card α))) = x Tactic: have hgmn : g ^ (m * Nat.gcd n (Fintype.card α)) = 1 := by rw [pow_mul, hm, ← pow_gcd_card_eq_one_iff]; exact (mem_filter.1 hx).2 State Before: α : Type u a : α inst✝³ : Group α inst✝² : DecidableEq α inst✝¹ : Fintype α inst✝ : IsCyclic α n : ℕ hn0 : 0 < n g : α hg : ∀ (x : α), x ∈ zpowers g x : α hx : x ∈ filter (fun a => a ^ n = 1) univ m : ℕ hm : g ^ m = x hgmn : g ^ (m * Nat.gcd n (Fintype.card α)) = 1 ⊢ (fun x x_1 => x ^ x_1) (g ^ (Fintype.card α / Nat.gcd n (Fintype.card α))) ↑(m / (Fintype.card α / Nat.gcd n (Fintype.card α))) = x State After: α : Type u a : α inst✝³ : Group α inst✝² : DecidableEq α inst✝¹ : Fintype α inst✝ : IsCyclic α n : ℕ hn0 : 0 < n g : α hg : ∀ (x : α), x ∈ zpowers g x : α hx : x ∈ filter (fun a => a ^ n = 1) univ m : ℕ hm : g ^ m = x hgmn : g ^ (m * Nat.gcd n (Fintype.card α)) = 1 ⊢ (g ^ (Fintype.card α / Nat.gcd n (Fintype.card α))) ^ ↑(m / (Fintype.card α / Nat.gcd n (Fintype.card α))) = x Tactic: dsimp only State Before: α : Type u a : α inst✝³ : Group α inst✝² : DecidableEq α inst✝¹ : Fintype α inst✝ : IsCyclic α n : ℕ hn0 : 0 < n g : α hg : ∀ (x : α), x ∈ zpowers g x : α hx : x ∈ filter (fun a => a ^ n = 1) univ m : ℕ hm : g ^ m = x hgmn : g ^ (m * Nat.gcd n (Fintype.card α)) = 1 ⊢ (g ^ (Fintype.card α / Nat.gcd n (Fintype.card α))) ^ ↑(m / (Fintype.card α / Nat.gcd n (Fintype.card α))) = x State After: α : Type u a : α inst✝³ : Group α inst✝² : DecidableEq α inst✝¹ : Fintype α inst✝ : IsCyclic α n : ℕ hn0 : 0 < n g : α hg : ∀ (x : α), x ∈ zpowers g x : α hx : x ∈ filter (fun a => a ^ n = 1) univ m : ℕ hm : g ^ m = x hgmn : g ^ (m * Nat.gcd n (Fintype.card α)) = 1 ⊢ Fintype.card α / Nat.gcd n (Fintype.card α) ∣ m Tactic: rw [zpow_ofNat, ← pow_mul, Nat.mul_div_cancel_left', hm] State Before: α : Type u a : α inst✝³ : Group α inst✝² : DecidableEq α inst✝¹ : Fintype α inst✝ : IsCyclic α n : ℕ hn0 : 0 < n g : α hg : ∀ (x : α), x ∈ zpowers g x : α hx : x ∈ filter (fun a => a ^ n = 1) univ m : ℕ hm : g ^ m = x hgmn : g ^ (m * Nat.gcd n (Fintype.card α)) = 1 ⊢ Fintype.card α / Nat.gcd n (Fintype.card α) ∣ m State After: α : Type u a : α inst✝³ : Group α inst✝² : DecidableEq α inst✝¹ : Fintype α inst✝ : IsCyclic α n : ℕ hn0 : 0 < n g : α hg : ∀ (x : α), x ∈ zpowers g x : α hx : x ∈ filter (fun a => a ^ n = 1) univ m : ℕ hm : g ^ m = x hgmn : g ^ (m * Nat.gcd n (Fintype.card α)) = 1 ⊢ Fintype.card α / Nat.gcd n (Fintype.card α) * Nat.gcd n (Fintype.card α) ∣ m * Nat.gcd n (Fintype.card α) Tactic: refine' Nat.dvd_of_mul_dvd_mul_right (gcd_pos_of_pos_left (Fintype.card α) hn0) _ State Before: α : Type u a : α inst✝³ : Group α inst✝² : DecidableEq α inst✝¹ : Fintype α inst✝ : IsCyclic α n : ℕ hn0 : 0 < n g : α hg : ∀ (x : α), x ∈ zpowers g x : α hx : x ∈ filter (fun a => a ^ n = 1) univ m : ℕ hm : g ^ m = x hgmn : g ^ (m * Nat.gcd n (Fintype.card α)) = 1 ⊢ Fintype.card α / Nat.gcd n (Fintype.card α) * Nat.gcd n (Fintype.card α) ∣ m * Nat.gcd n (Fintype.card α) State After: α : Type u a : α inst✝³ : Group α inst✝² : DecidableEq α inst✝¹ : Fintype α inst✝ : IsCyclic α n : ℕ hn0 : 0 < n g : α hg : ∀ (x : α), x ∈ zpowers g x : α hx : x ∈ filter (fun a => a ^ n = 1) univ m : ℕ hm : g ^ m = x hgmn : g ^ (m * Nat.gcd n (Fintype.card α)) = 1 ⊢ orderOf g ∣ m * Nat.gcd n (Fintype.card α) Tactic: conv_lhs => rw [Nat.div_mul_cancel (Nat.gcd_dvd_right _ _), ← orderOf_eq_card_of_forall_mem_zpowers hg] State Before: α : Type u a : α inst✝³ : Group α inst✝² : DecidableEq α inst✝¹ : Fintype α inst✝ : IsCyclic α n : ℕ hn0 : 0 < n g : α hg : ∀ (x : α), x ∈ zpowers g x : α hx : x ∈ filter (fun a => a ^ n = 1) univ m : ℕ hm : g ^ m = x hgmn : g ^ (m * Nat.gcd n (Fintype.card α)) = 1 ⊢ orderOf g ∣ m * Nat.gcd n (Fintype.card α) State After: no goals Tactic: exact orderOf_dvd_of_pow_eq_one hgmn State Before: α : Type u a : α inst✝³ : Group α inst✝² : DecidableEq α inst✝¹ : Fintype α inst✝ : IsCyclic α n : ℕ hn0 : 0 < n g : α hg : ∀ (x : α), x ∈ zpowers g x : α hx : x ∈ filter (fun a => a ^ n = 1) univ m : ℕ hm : g ^ m = x ⊢ g ^ (m * Nat.gcd n (Fintype.card α)) = 1 State After: α : Type u a : α inst✝³ : Group α inst✝² : DecidableEq α inst✝¹ : Fintype α inst✝ : IsCyclic α n : ℕ hn0 : 0 < n g : α hg : ∀ (x : α), x ∈ zpowers g x : α hx : x ∈ filter (fun a => a ^ n = 1) univ m : ℕ hm : g ^ m = x ⊢ x ^ n = 1 Tactic: rw [pow_mul, hm, ← pow_gcd_card_eq_one_iff] State Before: α : Type u a : α inst✝³ : Group α inst✝² : DecidableEq α inst✝¹ : Fintype α inst✝ : IsCyclic α n : ℕ hn0 : 0 < n g : α hg : ∀ (x : α), x ∈ zpowers g x : α hx : x ∈ filter (fun a => a ^ n = 1) univ m : ℕ hm : g ^ m = x ⊢ x ^ n = 1 State After: no goals Tactic: exact (mem_filter.1 hx).2 State Before: α : Type u a : α inst✝³ : Group α inst✝² : DecidableEq α inst✝¹ : Fintype α inst✝ : IsCyclic α n : ℕ hn0 : 0 < n g : α hg : ∀ (x : α), x ∈ zpowers g ⊢ card (Set.toFinset ↑(zpowers (g ^ (Fintype.card α / Nat.gcd n (Fintype.card α))))) ≤ n State After: α : Type u a : α inst✝³ : Group α inst✝² : DecidableEq α inst✝¹ : Fintype α inst✝ : IsCyclic α n : ℕ hn0 : 0 < n g : α hg : ∀ (x : α), x ∈ zpowers g m : ℕ hm : Fintype.card α = Nat.gcd n (Fintype.card α) * m ⊢ card (Set.toFinset ↑(zpowers (g ^ (Fintype.card α / Nat.gcd n (Fintype.card α))))) ≤ n Tactic: let ⟨m, hm⟩ := Nat.gcd_dvd_right n (Fintype.card α) State Before: α : Type u a : α inst✝³ : Group α inst✝² : DecidableEq α inst✝¹ : Fintype α inst✝ : IsCyclic α n : ℕ hn0 : 0 < n g : α hg : ∀ (x : α), x ∈ zpowers g m : ℕ hm : Fintype.card α = Nat.gcd n (Fintype.card α) * m ⊢ card (Set.toFinset ↑(zpowers (g ^ (Fintype.card α / Nat.gcd n (Fintype.card α))))) ≤ n State After: α : Type u a : α inst✝³ : Group α inst✝² : DecidableEq α inst✝¹ : Fintype α inst✝ : IsCyclic α n : ℕ hn0 : 0 < n g : α hg : ∀ (x : α), x ∈ zpowers g m : ℕ hm : Fintype.card α = Nat.gcd n (Fintype.card α) * m hm0 : 0 < m ⊢ card (Set.toFinset ↑(zpowers (g ^ (Fintype.card α / Nat.gcd n (Fintype.card α))))) ≤ n Tactic: have hm0 : 0 < m := Nat.pos_of_ne_zero fun hm0 => by rw [hm0, MulZeroClass.mul_zero, Fintype.card_eq_zero_iff] at hm exact hm.elim' 1 State Before: α : Type u a : α inst✝³ : Group α inst✝² : DecidableEq α inst✝¹ : Fintype α inst✝ : IsCyclic α n : ℕ hn0 : 0 < n g : α hg : ∀ (x : α), x ∈ zpowers g m : ℕ hm : Fintype.card α = Nat.gcd n (Fintype.card α) * m hm0 : 0 < m ⊢ card (Set.toFinset ↑(zpowers (g ^ (Fintype.card α / Nat.gcd n (Fintype.card α))))) ≤ n State After: α : Type u a : α inst✝³ : Group α inst✝² : DecidableEq α inst✝¹ : Fintype α inst✝ : IsCyclic α n : ℕ hn0 : 0 < n g : α hg : ∀ (x : α), x ∈ zpowers g m : ℕ hm : Fintype.card α = Nat.gcd n (Fintype.card α) * m hm0 : 0 < m ⊢ Fintype.card { x // x ∈ zpowers (g ^ (Fintype.card α / Nat.gcd n (Fintype.card α))) } ≤ n Tactic: simp only [Set.toFinset_card, SetLike.coe_sort_coe] State Before: α : Type u a : α inst✝³ : Group α inst✝² : DecidableEq α inst✝¹ : Fintype α inst✝ : IsCyclic α n : ℕ hn0 : 0 < n g : α hg : ∀ (x : α), x ∈ zpowers g m : ℕ hm : Fintype.card α = Nat.gcd n (Fintype.card α) * m hm0 : 0 < m ⊢ Fintype.card { x // x ∈ zpowers (g ^ (Fintype.card α / Nat.gcd n (Fintype.card α))) } ≤ n State After: α : Type u a : α inst✝³ : Group α inst✝² : DecidableEq α inst✝¹ : Fintype α inst✝ : IsCyclic α n : ℕ hn0 : 0 < n g : α hg : ∀ (x : α), x ∈ zpowers g m : ℕ hm : Fintype.card α = Nat.gcd n (Fintype.card α) * m hm0 : 0 < m ⊢ Fintype.card α / Nat.gcd (Fintype.card α) (Fintype.card α / Nat.gcd n (Fintype.card α)) ≤ n Tactic: rw [← orderOf_eq_card_zpowers, orderOf_pow g, orderOf_eq_card_of_forall_mem_zpowers hg] State Before: α : Type u a : α inst✝³ : Group α inst✝² : DecidableEq α inst✝¹ : Fintype α inst✝ : IsCyclic α n : ℕ hn0 : 0 < n g : α hg : ∀ (x : α), x ∈ zpowers g m : ℕ hm : Fintype.card α = Nat.gcd n (Fintype.card α) * m hm0 : 0 < m ⊢ Fintype.card α / Nat.gcd (Fintype.card α) (Fintype.card α / Nat.gcd n (Fintype.card α)) ≤ n State After: α : Type u a : α inst✝³ : Group α inst✝² : DecidableEq α inst✝¹ : Fintype α inst✝ : IsCyclic α n : ℕ hn0 : 0 < n g : α hg : ∀ (x : α), x ∈ zpowers g m : ℕ hm : Fintype.card α = Nat.gcd n (Fintype.card α) * m hm0 : 0 < m ⊢ Fintype.card α / Nat.gcd (Nat.gcd n (Fintype.card α) * m) (Fintype.card α / Nat.gcd n (Fintype.card α)) ≤ n Tactic: nth_rw 2 [hm] State Before: α : Type u a : α inst✝³ : Group α inst✝² : DecidableEq α inst✝¹ : Fintype α inst✝ : IsCyclic α n : ℕ hn0 : 0 < n g : α hg : ∀ (x : α), x ∈ zpowers g m : ℕ hm : Fintype.card α = Nat.gcd n (Fintype.card α) * m hm0 : 0 < m ⊢ Fintype.card α / Nat.gcd (Nat.gcd n (Fintype.card α) * m) (Fintype.card α / Nat.gcd n (Fintype.card α)) ≤ n State After: α : Type u a : α inst✝³ : Group α inst✝² : DecidableEq α inst✝¹ : Fintype α inst✝ : IsCyclic α n : ℕ hn0 : 0 < n g : α hg : ∀ (x : α), x ∈ zpowers g m : ℕ hm : Fintype.card α = Nat.gcd n (Fintype.card α) * m hm0 : 0 < m ⊢ Fintype.card α / Nat.gcd (Nat.gcd n (Fintype.card α) * m) (Nat.gcd n (Fintype.card α) * m / Nat.gcd n (Fintype.card α)) ≤ n Tactic: nth_rw 3 [hm] State Before: α : Type u a : α inst✝³ : Group α inst✝² : DecidableEq α inst✝¹ : Fintype α inst✝ : IsCyclic α n : ℕ hn0 : 0 < n g : α hg : ∀ (x : α), x ∈ zpowers g m : ℕ hm : Fintype.card α = Nat.gcd n (Fintype.card α) * m hm0 : 0 < m ⊢ Fintype.card α / Nat.gcd (Nat.gcd n (Fintype.card α) * m) (Nat.gcd n (Fintype.card α) * m / Nat.gcd n (Fintype.card α)) ≤ n State After: α : Type u a : α inst✝³ : Group α inst✝² : DecidableEq α inst✝¹ : Fintype α inst✝ : IsCyclic α n : ℕ hn0 : 0 < n g : α hg : ∀ (x : α), x ∈ zpowers g m : ℕ hm : Fintype.card α = Nat.gcd n (Fintype.card α) * m hm0 : 0 < m ⊢ Nat.gcd n (Fintype.card α) ≤ n Tactic: rw [Nat.mul_div_cancel_left _ (gcd_pos_of_pos_left _ hn0), gcd_mul_left_left, hm, Nat.mul_div_cancel _ hm0] State Before: α : Type u a : α inst✝³ : Group α inst✝² : DecidableEq α inst✝¹ : Fintype α inst✝ : IsCyclic α n : ℕ hn0 : 0 < n g : α hg : ∀ (x : α), x ∈ zpowers g m : ℕ hm : Fintype.card α = Nat.gcd n (Fintype.card α) * m hm0 : 0 < m ⊢ Nat.gcd n (Fintype.card α) ≤ n State After: no goals Tactic: exact le_of_dvd hn0 (Nat.gcd_dvd_left _ _) State Before: α : Type u a : α inst✝³ : Group α inst✝² : DecidableEq α inst✝¹ : Fintype α inst✝ : IsCyclic α n : ℕ hn0 : 0 < n g : α hg : ∀ (x : α), x ∈ zpowers g m : ℕ hm : Fintype.card α = Nat.gcd n (Fintype.card α) * m hm0 : m = 0 ⊢ False State After: α : Type u a : α inst✝³ : Group α inst✝² : DecidableEq α inst✝¹ : Fintype α inst✝ : IsCyclic α n : ℕ hn0 : 0 < n g : α hg : ∀ (x : α), x ∈ zpowers g m : ℕ hm : IsEmpty α hm0 : m = 0 ⊢ False Tactic: rw [hm0, MulZeroClass.mul_zero, Fintype.card_eq_zero_iff] at hm State Before: α : Type u a : α inst✝³ : Group α inst✝² : DecidableEq α inst✝¹ : Fintype α inst✝ : IsCyclic α n : ℕ hn0 : 0 < n g : α hg : ∀ (x : α), x ∈ zpowers g m : ℕ hm : IsEmpty α hm0 : m = 0 ⊢ False State After: no goals Tactic: exact hm.elim' 1
// Licensed to the Apache Software Foundation (ASF) under one // or more contributor license agreements. See the NOTICE file // distributed with this work for additional information // regarding copyright ownership. The ASF licenses this file // to you 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. #include "kudu/tablet/diskrowset.h" #include <algorithm> #include <map> #include <ostream> #include <vector> #include <boost/optional/optional.hpp> #include <gflags/gflags.h> #include <glog/logging.h> #include <glog/stl_logging.h> #include "kudu/cfile/bloomfile.h" #include "kudu/cfile/cfile_util.h" #include "kudu/cfile/cfile_writer.h" #include "kudu/common/generic_iterators.h" #include "kudu/common/iterator.h" #include "kudu/common/rowblock.h" #include "kudu/common/schema.h" #include "kudu/common/timestamp.h" #include "kudu/common/types.h" #include "kudu/fs/block_manager.h" #include "kudu/fs/fs_manager.h" #include "kudu/gutil/gscoped_ptr.h" #include "kudu/gutil/port.h" #include "kudu/tablet/cfile_set.h" #include "kudu/tablet/compaction.h" #include "kudu/tablet/delta_compaction.h" #include "kudu/tablet/delta_stats.h" #include "kudu/tablet/delta_store.h" #include "kudu/tablet/deltafile.h" #include "kudu/tablet/metadata.pb.h" #include "kudu/tablet/multi_column_writer.h" #include "kudu/tablet/mutation.h" #include "kudu/tablet/mvcc.h" #include "kudu/util/compression/compression.pb.h" #include "kudu/util/debug/trace_event.h" #include "kudu/util/flag_tags.h" #include "kudu/util/locks.h" #include "kudu/util/logging.h" #include "kudu/util/monotime.h" #include "kudu/util/scoped_cleanup.h" #include "kudu/util/slice.h" #include "kudu/util/status.h" DEFINE_int32(tablet_delta_store_minor_compact_max, 1000, "How many delta stores are required before forcing a minor delta compaction " "(Advanced option)"); TAG_FLAG(tablet_delta_store_minor_compact_max, experimental); DEFINE_double(tablet_delta_store_major_compact_min_ratio, 0.1f, "Minimum ratio of sizeof(deltas) to sizeof(base data) before a major compaction " "can run (Advanced option)"); TAG_FLAG(tablet_delta_store_major_compact_min_ratio, experimental); DEFINE_int32(default_composite_key_index_block_size_bytes, 4096, "Block size used for composite key indexes."); TAG_FLAG(default_composite_key_index_block_size_bytes, experimental); DEFINE_bool(rowset_metadata_store_keys, false, "Whether to store the min/max encoded keys in the rowset " "metadata. If false, keys will be read from the data blocks."); TAG_FLAG(rowset_metadata_store_keys, experimental); namespace kudu { class Mutex; namespace consensus { class OpId; } namespace tablet { using cfile::BloomFileWriter; using fs::BlockManager; using fs::BlockCreationTransaction; using fs::CreateBlockOptions; using fs::WritableBlock; using log::LogAnchorRegistry; using std::shared_ptr; using std::string; using std::unique_ptr; using std::vector; const char *DiskRowSet::kMinKeyMetaEntryName = "min_key"; const char *DiskRowSet::kMaxKeyMetaEntryName = "max_key"; DiskRowSetWriter::DiskRowSetWriter(RowSetMetadata* rowset_metadata, const Schema* schema, BloomFilterSizing bloom_sizing) : rowset_metadata_(rowset_metadata), schema_(schema), bloom_sizing_(bloom_sizing), finished_(false), written_count_(0) { CHECK(schema->has_column_ids()); } Status DiskRowSetWriter::Open() { TRACE_EVENT0("tablet", "DiskRowSetWriter::Open"); FsManager* fs = rowset_metadata_->fs_manager(); const string& tablet_id = rowset_metadata_->tablet_metadata()->tablet_id(); col_writer_.reset(new MultiColumnWriter(fs, schema_, tablet_id)); RETURN_NOT_OK(col_writer_->Open()); // Open bloom filter. RETURN_NOT_OK(InitBloomFileWriter()); if (schema_->num_key_columns() > 1) { // Open ad-hoc index writer RETURN_NOT_OK(InitAdHocIndexWriter()); } return Status::OK(); } Status DiskRowSetWriter::InitBloomFileWriter() { TRACE_EVENT0("tablet", "DiskRowSetWriter::InitBloomFileWriter"); unique_ptr<WritableBlock> block; FsManager* fs = rowset_metadata_->fs_manager(); const string& tablet_id = rowset_metadata_->tablet_metadata()->tablet_id(); RETURN_NOT_OK_PREPEND(fs->CreateNewBlock(CreateBlockOptions({ tablet_id }), &block), "Couldn't allocate a block for bloom filter"); rowset_metadata_->set_bloom_block(block->id()); bloom_writer_.reset(new cfile::BloomFileWriter(std::move(block), bloom_sizing_)); RETURN_NOT_OK(bloom_writer_->Start()); return Status::OK(); } Status DiskRowSetWriter::InitAdHocIndexWriter() { TRACE_EVENT0("tablet", "DiskRowSetWriter::InitAdHocIndexWriter"); unique_ptr<WritableBlock> block; FsManager* fs = rowset_metadata_->fs_manager(); const string& tablet_id = rowset_metadata_->tablet_metadata()->tablet_id(); RETURN_NOT_OK_PREPEND(fs->CreateNewBlock(CreateBlockOptions({ tablet_id }), &block), "Couldn't allocate a block for compoound index"); rowset_metadata_->set_adhoc_index_block(block->id()); cfile::WriterOptions opts; // Index the composite key by value opts.write_validx = true; // no need to index positions opts.write_posidx = false; opts.storage_attributes.encoding = PREFIX_ENCODING; opts.storage_attributes.compression = LZ4; opts.storage_attributes.cfile_block_size = FLAGS_default_composite_key_index_block_size_bytes; // Create the CFile writer for the ad-hoc index. ad_hoc_index_writer_.reset(new cfile::CFileWriter( std::move(opts), GetTypeInfo(BINARY), false, std::move(block))); return ad_hoc_index_writer_->Start(); } Status DiskRowSetWriter::AppendBlock(const RowBlock &block) { DCHECK_EQ(block.schema().num_columns(), schema_->num_columns()); CHECK(!finished_); // If this is the very first block, encode the first key and save it as metadata // in the index column. if (written_count_ == 0) { Slice enc_key = schema_->EncodeComparableKey(block.row(0), &last_encoded_key_); key_index_writer()->AddMetadataPair(DiskRowSet::kMinKeyMetaEntryName, enc_key); if (FLAGS_rowset_metadata_store_keys) { rowset_metadata_->set_min_encoded_key(enc_key.ToString()); } last_encoded_key_.clear(); } // Write the batch to each of the columns RETURN_NOT_OK(col_writer_->AppendBlock(block)); #ifndef NDEBUG faststring prev_key; #endif // Write the batch to the bloom and optionally the ad-hoc index for (size_t i = 0; i < block.nrows(); i++) { #ifndef NDEBUG prev_key.assign_copy(last_encoded_key_.data(), last_encoded_key_.size()); #endif // TODO: performance might be better if we actually batch this - // encode a bunch of key slices, then pass them all in one go. RowBlockRow row = block.row(i); // Insert the encoded key into the bloom. Slice enc_key = schema_->EncodeComparableKey(row, &last_encoded_key_); RETURN_NOT_OK(bloom_writer_->AppendKeys(&enc_key, 1)); // Write the batch to the ad hoc index if we're using one if (ad_hoc_index_writer_ != nullptr) { RETURN_NOT_OK(ad_hoc_index_writer_->AppendEntries(&enc_key, 1)); } #ifndef NDEBUG CHECK(prev_key.size() == 0 || Slice(prev_key).compare(enc_key) < 0) << KUDU_REDACT(enc_key.ToDebugString()) << " appended to file not > previous key " << KUDU_REDACT(Slice(prev_key).ToDebugString()); #endif } written_count_ += block.nrows(); return Status::OK(); } Status DiskRowSetWriter::Finish() { TRACE_EVENT0("tablet", "DiskRowSetWriter::Finish"); BlockManager* bm = rowset_metadata_->fs_manager()->block_manager(); unique_ptr<BlockCreationTransaction> transaction = bm->NewCreationTransaction(); RETURN_NOT_OK(FinishAndReleaseBlocks(transaction.get())); return transaction->CommitCreatedBlocks(); } Status DiskRowSetWriter::FinishAndReleaseBlocks(BlockCreationTransaction* transaction) { TRACE_EVENT0("tablet", "DiskRowSetWriter::FinishAndReleaseBlocks"); CHECK(!finished_); if (written_count_ == 0) { finished_ = true; return Status::Aborted("no data written"); } // Save the last encoded (max) key Slice last_enc_slice(last_encoded_key_); std::string first_encoded_key = key_index_writer()->GetMetaValueOrDie(DiskRowSet::kMinKeyMetaEntryName); Slice first_enc_slice(first_encoded_key); CHECK_LE(first_enc_slice.compare(last_enc_slice), 0) << "First Key not <= Last key: first_key=" << KUDU_REDACT(first_enc_slice.ToDebugString()) << " last_key=" << KUDU_REDACT(last_enc_slice.ToDebugString()); key_index_writer()->AddMetadataPair(DiskRowSet::kMaxKeyMetaEntryName, last_enc_slice); if (FLAGS_rowset_metadata_store_keys) { rowset_metadata_->set_max_encoded_key(last_enc_slice.ToString()); } // Finish writing the columns themselves. RETURN_NOT_OK(col_writer_->FinishAndReleaseBlocks(transaction)); // Put the column data blocks in the metadata. std::map<ColumnId, BlockId> flushed_blocks; col_writer_->GetFlushedBlocksByColumnId(&flushed_blocks); rowset_metadata_->SetColumnDataBlocks(flushed_blocks); if (ad_hoc_index_writer_ != nullptr) { Status s = ad_hoc_index_writer_->FinishAndReleaseBlock(transaction); if (!s.ok()) { LOG(WARNING) << "Unable to Finish ad hoc index writer: " << s.ToString(); return s; } } // Finish bloom. Status s = bloom_writer_->FinishAndReleaseBlock(transaction); if (!s.ok()) { LOG(WARNING) << "Unable to Finish bloom filter writer: " << s.ToString(); return s; } finished_ = true; return Status::OK(); } cfile::CFileWriter *DiskRowSetWriter::key_index_writer() { return ad_hoc_index_writer_ ? ad_hoc_index_writer_.get() : col_writer_->writer_for_col_idx(0); } size_t DiskRowSetWriter::written_size() const { size_t size = 0; if (col_writer_) { size += col_writer_->written_size(); } if (bloom_writer_) { size += bloom_writer_->written_size(); } if (ad_hoc_index_writer_) { size += ad_hoc_index_writer_->written_size(); } return size; } DiskRowSetWriter::~DiskRowSetWriter() { } RollingDiskRowSetWriter::RollingDiskRowSetWriter( TabletMetadata* tablet_metadata, const Schema& schema, BloomFilterSizing bloom_sizing, size_t target_rowset_size) : state_(kInitialized), tablet_metadata_(DCHECK_NOTNULL(tablet_metadata)), schema_(schema), bloom_sizing_(bloom_sizing), target_rowset_size_(target_rowset_size), row_idx_in_cur_drs_(0), can_roll_(false), written_count_(0), written_size_(0) { BlockManager* bm = tablet_metadata->fs_manager()->block_manager(); block_transaction_ = bm->NewCreationTransaction(); CHECK(schema.has_column_ids()); } Status RollingDiskRowSetWriter::Open() { TRACE_EVENT0("tablet", "RollingDiskRowSetWriter::Open"); CHECK_EQ(state_, kInitialized); RETURN_NOT_OK(RollWriter()); state_ = kStarted; return Status::OK(); } Status RollingDiskRowSetWriter::RollWriter() { TRACE_EVENT0("tablet", "RollingDiskRowSetWriter::RollWriter"); // Close current writer if it is open RETURN_NOT_OK(FinishCurrentWriter()); RETURN_NOT_OK(tablet_metadata_->CreateRowSet(&cur_drs_metadata_)); cur_writer_.reset(new DiskRowSetWriter(cur_drs_metadata_.get(), &schema_, bloom_sizing_)); RETURN_NOT_OK(cur_writer_->Open()); FsManager* fs = tablet_metadata_->fs_manager(); unique_ptr<WritableBlock> undo_data_block; unique_ptr<WritableBlock> redo_data_block; RETURN_NOT_OK(fs->CreateNewBlock(CreateBlockOptions({ tablet_metadata_->tablet_id() }), &undo_data_block)); RETURN_NOT_OK(fs->CreateNewBlock(CreateBlockOptions({ tablet_metadata_->tablet_id() }), &redo_data_block)); cur_undo_ds_block_id_ = undo_data_block->id(); cur_redo_ds_block_id_ = redo_data_block->id(); cur_undo_writer_.reset(new DeltaFileWriter(std::move(undo_data_block))); cur_redo_writer_.reset(new DeltaFileWriter(std::move(redo_data_block))); cur_undo_delta_stats.reset(new DeltaStats()); cur_redo_delta_stats.reset(new DeltaStats()); row_idx_in_cur_drs_ = 0; can_roll_ = false; RETURN_NOT_OK(cur_undo_writer_->Start()); return cur_redo_writer_->Start(); } Status RollingDiskRowSetWriter::RollIfNecessary() { DCHECK_EQ(state_, kStarted); if (can_roll_ && cur_writer_->written_size() > target_rowset_size_) { RETURN_NOT_OK(RollWriter()); } return Status::OK(); } Status RollingDiskRowSetWriter::AppendBlock(const RowBlock &block) { DCHECK_EQ(state_, kStarted); RETURN_NOT_OK(cur_writer_->AppendBlock(block)); written_count_ += block.nrows(); row_idx_in_cur_drs_ += block.nrows(); can_roll_ = true; return Status::OK(); } Status RollingDiskRowSetWriter::AppendUndoDeltas(rowid_t row_idx_in_block, Mutation* undo_delta_head, rowid_t* row_idx) { return AppendDeltas<UNDO>(row_idx_in_block, undo_delta_head, row_idx, cur_undo_writer_.get(), cur_undo_delta_stats.get()); } Status RollingDiskRowSetWriter::AppendRedoDeltas(rowid_t row_idx_in_block, Mutation* redo_delta_head, rowid_t* row_idx) { return AppendDeltas<REDO>(row_idx_in_block, redo_delta_head, row_idx, cur_redo_writer_.get(), cur_redo_delta_stats.get()); } template<DeltaType Type> Status RollingDiskRowSetWriter::AppendDeltas(rowid_t row_idx_in_block, Mutation* delta_head, rowid_t* row_idx, DeltaFileWriter* writer, DeltaStats* delta_stats) { can_roll_ = false; *row_idx = row_idx_in_cur_drs_ + row_idx_in_block; for (const Mutation *mut = delta_head; mut != nullptr; mut = mut->next()) { DeltaKey undo_key(*row_idx, mut->timestamp()); RETURN_NOT_OK(writer->AppendDelta<Type>(undo_key, mut->changelist())); delta_stats->UpdateStats(mut->timestamp(), mut->changelist()); } return Status::OK(); } Status RollingDiskRowSetWriter::FinishCurrentWriter() { TRACE_EVENT0("tablet", "RollingDiskRowSetWriter::FinishCurrentWriter"); if (!cur_writer_) { return Status::OK(); } CHECK_EQ(state_, kStarted); Status writer_status = cur_writer_->FinishAndReleaseBlocks(block_transaction_.get()); // If no rows were written (e.g. due to an empty flush or a compaction with all rows // deleted), FinishAndReleaseBlocks(...) returns Aborted. In that case, we don't // generate a RowSetMetadata. if (writer_status.IsAborted()) { CHECK_EQ(cur_writer_->written_count(), 0); } else { RETURN_NOT_OK(writer_status); CHECK_GT(cur_writer_->written_count(), 0); cur_undo_writer_->WriteDeltaStats(*cur_undo_delta_stats); cur_redo_writer_->WriteDeltaStats(*cur_redo_delta_stats); // Commit the UNDO block. Status::Aborted() indicates that there // were no UNDOs written. Status s = cur_undo_writer_->FinishAndReleaseBlock(block_transaction_.get()); if (!s.IsAborted()) { RETURN_NOT_OK(s); cur_drs_metadata_->CommitUndoDeltaDataBlock(cur_undo_ds_block_id_); } else { DCHECK_EQ(cur_undo_delta_stats->min_timestamp(), Timestamp::kMax); } // Same for the REDO block. s = cur_redo_writer_->FinishAndReleaseBlock(block_transaction_.get()); if (!s.IsAborted()) { RETURN_NOT_OK(s); cur_drs_metadata_->CommitRedoDeltaDataBlock(0, cur_redo_ds_block_id_); } else { DCHECK_EQ(cur_redo_delta_stats->min_timestamp(), Timestamp::kMax); } written_size_ += cur_writer_->written_size(); written_drs_metas_.push_back(cur_drs_metadata_); } cur_writer_.reset(nullptr); cur_undo_writer_.reset(nullptr); cur_redo_writer_.reset(nullptr); cur_drs_metadata_.reset(); return Status::OK(); } Status RollingDiskRowSetWriter::Finish() { TRACE_EVENT0("tablet", "RollingDiskRowSetWriter::Finish"); DCHECK_EQ(state_, kStarted); RETURN_NOT_OK(FinishCurrentWriter()); RETURN_NOT_OK(block_transaction_->CommitCreatedBlocks()); state_ = kFinished; return Status::OK(); } void RollingDiskRowSetWriter::GetWrittenRowSetMetadata(RowSetMetadataVector* metas) const { CHECK_EQ(state_, kFinished); metas->assign(written_drs_metas_.begin(), written_drs_metas_.end()); } RollingDiskRowSetWriter::~RollingDiskRowSetWriter() { } //////////////////////////////////////////////////////////// // Reader //////////////////////////////////////////////////////////// Status DiskRowSet::Open(const shared_ptr<RowSetMetadata>& rowset_metadata, log::LogAnchorRegistry* log_anchor_registry, const TabletMemTrackers& mem_trackers, shared_ptr<DiskRowSet> *rowset) { shared_ptr<DiskRowSet> rs(new DiskRowSet(rowset_metadata, log_anchor_registry, mem_trackers)); RETURN_NOT_OK(rs->Open()); rowset->swap(rs); return Status::OK(); } DiskRowSet::DiskRowSet(shared_ptr<RowSetMetadata> rowset_metadata, LogAnchorRegistry* log_anchor_registry, TabletMemTrackers mem_trackers) : rowset_metadata_(std::move(rowset_metadata)), open_(false), log_anchor_registry_(log_anchor_registry), mem_trackers_(std::move(mem_trackers)), num_rows_(-1), has_been_compacted_(false) {} Status DiskRowSet::Open() { TRACE_EVENT0("tablet", "DiskRowSet::Open"); RETURN_NOT_OK(CFileSet::Open(rowset_metadata_, mem_trackers_.tablet_tracker, &base_data_)); RETURN_NOT_OK(DeltaTracker::Open(rowset_metadata_, log_anchor_registry_, mem_trackers_, &delta_tracker_)); open_ = true; return Status::OK(); } Status DiskRowSet::FlushDeltas() { TRACE_EVENT0("tablet", "DiskRowSet::FlushDeltas"); return delta_tracker_->Flush(DeltaTracker::FLUSH_METADATA); } Status DiskRowSet::MinorCompactDeltaStores() { TRACE_EVENT0("tablet", "DiskRowSet::MinorCompactDeltaStores"); return delta_tracker_->Compact(); } Status DiskRowSet::MajorCompactDeltaStores(HistoryGcOpts history_gc_opts) { vector<ColumnId> col_ids; delta_tracker_->GetColumnIdsWithUpdates(&col_ids); if (col_ids.empty()) { VLOG_WITH_PREFIX(2) << "There are no column ids with updates"; return Status::OK(); } return MajorCompactDeltaStoresWithColumnIds(col_ids, std::move(history_gc_opts)); } Status DiskRowSet::MajorCompactDeltaStoresWithColumnIds(const vector<ColumnId>& col_ids, HistoryGcOpts history_gc_opts) { LOG_WITH_PREFIX(INFO) << "Major compacting REDO delta stores (cols: " << col_ids << ")"; TRACE_EVENT0("tablet", "DiskRowSet::MajorCompactDeltaStoresWithColumnIds"); std::lock_guard<Mutex> l(*delta_tracker()->compact_flush_lock()); RETURN_NOT_OK(delta_tracker()->CheckWritableUnlocked()); // TODO(todd): do we need to lock schema or anything here? gscoped_ptr<MajorDeltaCompaction> compaction; RETURN_NOT_OK(NewMajorDeltaCompaction(col_ids, std::move(history_gc_opts), &compaction)); RETURN_NOT_OK(compaction->Compact()); // Before updating anything, create a copy of the rowset metadata so we can // revert changes in case of error. RowSetDataPB original_pb; rowset_metadata_->ToProtobuf(&original_pb); auto revert_metadata_update = MakeScopedCleanup([&] { LOG_WITH_PREFIX(WARNING) << "Error during major delta compaction! Rolling back rowset metadata"; rowset_metadata_->LoadFromPB(original_pb); }); // Prepare the changes to the metadata. RowSetMetadataUpdate update; compaction->CreateMetadataUpdate(&update); vector<BlockId> removed_blocks; rowset_metadata_->CommitUpdate(update, &removed_blocks); // Now that the metadata has been updated, open a new cfile set with the // appropriate blocks to match the update. shared_ptr<CFileSet> new_base; RETURN_NOT_OK(CFileSet::Open(rowset_metadata_, mem_trackers_.tablet_tracker, &new_base)); { // Update the delta tracker and the base data with the changes. std::lock_guard<rw_spinlock> lock(component_lock_); RETURN_NOT_OK(compaction->UpdateDeltaTracker(delta_tracker_.get())); base_data_.swap(new_base); } // Now that we've successfully compacted, add the removed blocks to the // orphaned blocks list and cancel cleanup. rowset_metadata_->AddOrphanedBlocks(removed_blocks); revert_metadata_update.cancel(); // Even if we don't successfully flush we don't have consistency problems in // the case of major delta compaction -- we are not adding additional // mutations that werent already present. return rowset_metadata_->Flush(); } Status DiskRowSet::NewMajorDeltaCompaction(const vector<ColumnId>& col_ids, HistoryGcOpts history_gc_opts, gscoped_ptr<MajorDeltaCompaction>* out) const { DCHECK(open_); shared_lock<rw_spinlock> l(component_lock_); const Schema* schema = &rowset_metadata_->tablet_schema(); vector<shared_ptr<DeltaStore> > included_stores; unique_ptr<DeltaIterator> delta_iter; RETURN_NOT_OK(delta_tracker_->NewDeltaFileIterator( schema, MvccSnapshot::CreateSnapshotIncludingAllTransactions(), REDO, &included_stores, &delta_iter)); out->reset(new MajorDeltaCompaction(rowset_metadata_->fs_manager(), *schema, base_data_.get(), std::move(delta_iter), std::move(included_stores), col_ids, std::move(history_gc_opts), rowset_metadata_->tablet_metadata()->tablet_id())); return Status::OK(); } Status DiskRowSet::NewRowIterator(const Schema *projection, const MvccSnapshot &mvcc_snap, OrderMode /*order*/, gscoped_ptr<RowwiseIterator>* out) const { DCHECK(open_); shared_lock<rw_spinlock> l(component_lock_); shared_ptr<CFileSet::Iterator> base_iter(base_data_->NewIterator(projection)); gscoped_ptr<ColumnwiseIterator> col_iter; RETURN_NOT_OK(delta_tracker_->WrapIterator(base_iter, mvcc_snap, &col_iter)); out->reset(new MaterializingIterator( shared_ptr<ColumnwiseIterator>(col_iter.release()))); return Status::OK(); } Status DiskRowSet::NewCompactionInput(const Schema* projection, const MvccSnapshot &snap, gscoped_ptr<CompactionInput>* out) const { return CompactionInput::Create(*this, projection, snap, out); } Status DiskRowSet::MutateRow(Timestamp timestamp, const RowSetKeyProbe &probe, const RowChangeList &update, const consensus::OpId& op_id, ProbeStats* stats, OperationResultPB* result) { DCHECK(open_); #ifndef NDEBUG rowid_t num_rows; RETURN_NOT_OK(CountRows(&num_rows)); #endif shared_lock<rw_spinlock> l(component_lock_); boost::optional<rowid_t> row_idx; RETURN_NOT_OK(base_data_->FindRow(probe, &row_idx, stats)); if (PREDICT_FALSE(row_idx == boost::none)) { return Status::NotFound("row not found"); } #ifndef NDEBUG CHECK_LT(*row_idx, num_rows); #endif // It's possible that the row key exists in this DiskRowSet, but it has // in fact been Deleted already. Check with the delta tracker to be sure. bool deleted; RETURN_NOT_OK(delta_tracker_->CheckRowDeleted(*row_idx, &deleted, stats)); if (deleted) { return Status::NotFound("row not found"); } RETURN_NOT_OK(delta_tracker_->Update(timestamp, *row_idx, update, op_id, result)); return Status::OK(); } Status DiskRowSet::CheckRowPresent(const RowSetKeyProbe &probe, bool* present, ProbeStats* stats) const { DCHECK(open_); #ifndef NDEBUG rowid_t num_rows; RETURN_NOT_OK(CountRows(&num_rows)); #endif shared_lock<rw_spinlock> l(component_lock_); rowid_t row_idx; RETURN_NOT_OK(base_data_->CheckRowPresent(probe, present, &row_idx, stats)); if (!*present) { // If it wasn't in the base data, then it's definitely not in the rowset. return Status::OK(); } #ifndef NDEBUG CHECK_LT(row_idx, num_rows); #endif // Otherwise it might be in the base data but deleted. bool deleted = false; RETURN_NOT_OK(delta_tracker_->CheckRowDeleted(row_idx, &deleted, stats)); *present = !deleted; return Status::OK(); } Status DiskRowSet::CountRows(rowid_t *count) const { DCHECK(open_); rowid_t num_rows = num_rows_.load(); if (PREDICT_TRUE(num_rows != -1)) { *count = num_rows; } else { shared_lock<rw_spinlock> l(component_lock_); RETURN_NOT_OK(base_data_->CountRows(count)); num_rows_.store(*count); } return Status::OK(); } Status DiskRowSet::GetBounds(std::string* min_encoded_key, std::string* max_encoded_key) const { DCHECK(open_); shared_lock<rw_spinlock> l(component_lock_); return base_data_->GetBounds(min_encoded_key, max_encoded_key); } void DiskRowSet::GetDiskRowSetSpaceUsage(DiskRowSetSpace* drss) const { DCHECK(open_); shared_lock<rw_spinlock> l(component_lock_); drss->base_data_size = base_data_->OnDiskDataSize(); drss->bloom_size = base_data_->BloomFileOnDiskSize(); drss->ad_hoc_index_size = base_data_->AdhocIndexOnDiskSize(); drss->redo_deltas_size = delta_tracker_->RedoDeltaOnDiskSize(); drss->undo_deltas_size = delta_tracker_->UndoDeltaOnDiskSize(); } uint64_t DiskRowSet::OnDiskSize() const { DiskRowSetSpace drss; GetDiskRowSetSpaceUsage(&drss); return drss.CFileSetOnDiskSize() + drss.redo_deltas_size + drss.undo_deltas_size; } uint64_t DiskRowSet::OnDiskBaseDataSize() const { DiskRowSetSpace drss; GetDiskRowSetSpaceUsage(&drss); return drss.base_data_size; } uint64_t DiskRowSet::OnDiskBaseDataSizeWithRedos() const { DiskRowSetSpace drss; GetDiskRowSetSpaceUsage(&drss); return drss.base_data_size + drss.redo_deltas_size; } size_t DiskRowSet::DeltaMemStoreSize() const { DCHECK(open_); return delta_tracker_->DeltaMemStoreSize(); } bool DiskRowSet::DeltaMemStoreEmpty() const { DCHECK(open_); return delta_tracker_->DeltaMemStoreEmpty(); } int64_t DiskRowSet::MinUnflushedLogIndex() const { DCHECK(open_); return delta_tracker_->MinUnflushedLogIndex(); } size_t DiskRowSet::CountDeltaStores() const { DCHECK(open_); return delta_tracker_->CountRedoDeltaStores(); } // In this implementation, the returned improvement score is 0 if there aren't any redo files to // compact or if the base data is empty. After this, with a max score of 1: // - Major compactions: the score will be the result of sizeof(deltas)/sizeof(base data), unless // it is smaller than tablet_delta_store_major_compact_min_ratio or if the // delta files are only composed of deletes, in which case the score is // brought down to zero. // - Minor compactions: the score will be zero if there's only 1 redo file, else it will be the // result of redo_files_count/tablet_delta_store_minor_compact_max. The // latter is meant to be high since minor compactions don't give us much, so // we only consider it a gain if it gets rid of many tiny files. double DiskRowSet::DeltaStoresCompactionPerfImprovementScore(DeltaCompactionType type) const { DCHECK(open_); double perf_improv = 0; size_t store_count = CountDeltaStores(); if (store_count == 0) { return perf_improv; } if (type == RowSet::MAJOR_DELTA_COMPACTION) { vector<ColumnId> col_ids_with_updates; delta_tracker_->GetColumnIdsWithUpdates(&col_ids_with_updates); // If we have files but no updates, we don't want to major compact. if (!col_ids_with_updates.empty()) { DiskRowSetSpace drss; GetDiskRowSetSpaceUsage(&drss); double ratio = static_cast<double>(drss.redo_deltas_size) / drss.base_data_size; if (ratio >= FLAGS_tablet_delta_store_major_compact_min_ratio) { perf_improv = ratio; } } } else if (type == RowSet::MINOR_DELTA_COMPACTION) { if (store_count > 1) { perf_improv = static_cast<double>(store_count) / FLAGS_tablet_delta_store_minor_compact_max; } } else { LOG_WITH_PREFIX(FATAL) << "Unknown delta compaction type " << type; } return std::min(1.0, perf_improv); } Status DiskRowSet::EstimateBytesInPotentiallyAncientUndoDeltas(Timestamp ancient_history_mark, int64_t* bytes) { return delta_tracker_->EstimateBytesInPotentiallyAncientUndoDeltas(ancient_history_mark, bytes); } Status DiskRowSet::InitUndoDeltas(Timestamp ancient_history_mark, MonoTime deadline, int64_t* delta_blocks_initialized, int64_t* bytes_in_ancient_undos) { TRACE_EVENT0("tablet", "DiskRowSet::InitUndoDeltas"); return delta_tracker_->InitUndoDeltas(ancient_history_mark, deadline, delta_blocks_initialized, bytes_in_ancient_undos); } Status DiskRowSet::DeleteAncientUndoDeltas(Timestamp ancient_history_mark, int64_t* blocks_deleted, int64_t* bytes_deleted) { TRACE_EVENT0("tablet", "DiskRowSet::DeleteAncientUndoDeltas"); return delta_tracker_->DeleteAncientUndoDeltas(ancient_history_mark, blocks_deleted, bytes_deleted); } Status DiskRowSet::DebugDump(vector<string> *lines) { // Using CompactionInput to dump our data is an easy way of seeing all the // rows and deltas. gscoped_ptr<CompactionInput> input; RETURN_NOT_OK(NewCompactionInput(&rowset_metadata_->tablet_schema(), MvccSnapshot::CreateSnapshotIncludingAllTransactions(), &input)); return DebugDumpCompactionInput(input.get(), lines); } } // namespace tablet } // namespace kudu
lemma fact_cancel: fixes c :: "'a::real_field" shows "of_nat (Suc n) * c / (fact (Suc n)) = c / (fact n)"
###### Weight vector ##### abstract type AbstractWeights{S<:Real, T<:Real, V<:AbstractVector{T}} <: AbstractVector{T} end """ @weights name Generates a new generic weight type with specified `name`, which subtypes `AbstractWeights` and stores the `values` (`V<:RealVector`) and `sum` (`S<:Real`). """ macro weights(name) return quote mutable struct $name{S<:Real, T<:Real, V<:AbstractVector{T}} <: AbstractWeights{S, T, V} values::V sum::S end $(esc(name))(vs) = $(esc(name))(vs, sum(vs)) end end eltype(wv::AbstractWeights) = eltype(wv.values) length(wv::AbstractWeights) = length(wv.values) values(wv::AbstractWeights) = wv.values sum(wv::AbstractWeights) = wv.sum isempty(wv::AbstractWeights) = isempty(wv.values) Base.getindex(wv::AbstractWeights, i) = getindex(wv.values, i) Base.size(wv::AbstractWeights) = size(wv.values) @propagate_inbounds function Base.setindex!(wv::AbstractWeights, v::Real, i::Int) s = v - wv[i] wv.values[i] = v wv.sum += s v end """ varcorrection(n::Integer, corrected=false) Compute a bias correction factor for calculating `var`, `std` and `cov` with `n` observations. Returns ``\\frac{1}{n - 1}`` when `corrected=true` (i.e. [Bessel's correction](https://en.wikipedia.org/wiki/Bessel's_correction)), otherwise returns ``\\frac{1}{n}`` (i.e. no correction). """ @inline varcorrection(n::Integer, corrected::Bool=false) = 1 / (n - Int(corrected)) @weights Weights @doc """ Weights(vs, wsum=sum(vs)) Construct a `Weights` vector with weight values `vs`. A precomputed sum may be provided as `wsum`. The `Weights` type describes a generic weights vector which does not support all operations possible for [`FrequencyWeights`](@ref), [`AnalyticWeights`](@ref) and [`ProbabilityWeights`](@ref). """ Weights """ weights(vs) Construct a `Weights` vector from array `vs`. See the documentation for [`Weights`](@ref) for more details. """ weights(vs::RealVector) = Weights(vs) weights(vs::RealArray) = Weights(vec(vs)) """ varcorrection(w::Weights, corrected=false) Returns ``\\frac{1}{\\sum w}`` when `corrected=false` and throws an `ArgumentError` if `corrected=true`. """ @inline function varcorrection(w::Weights, corrected::Bool=false) corrected && throw(ArgumentError("Weights type does not support bias correction: " * "use FrequencyWeights, AnalyticWeights or ProbabilityWeights if applicable.")) 1 / w.sum end @weights AnalyticWeights @doc """ AnalyticWeights(vs, wsum=sum(vs)) Construct an `AnalyticWeights` vector with weight values `vs`. A precomputed sum may be provided as `wsum`. Analytic weights describe a non-random relative importance (usually between 0 and 1) for each observation. These weights may also be referred to as reliability weights, precision weights or inverse variance weights. These are typically used when the observations being weighted are aggregate values (e.g., averages) with differing variances. """ AnalyticWeights """ aweights(vs) Construct an `AnalyticWeights` vector from array `vs`. See the documentation for [`AnalyticWeights`](@ref) for more details. """ aweights(vs::RealVector) = AnalyticWeights(vs) aweights(vs::RealArray) = AnalyticWeights(vec(vs)) """ varcorrection(w::AnalyticWeights, corrected=false) * `corrected=true`: ``\\frac{1}{\\sum w - \\sum {w^2} / \\sum w}`` * `corrected=false`: ``\\frac{1}{\\sum w}`` """ @inline function varcorrection(w::AnalyticWeights, corrected::Bool=false) s = w.sum if corrected sum_sn = sum(x -> (x / s) ^ 2, w) 1 / (s * (1 - sum_sn)) else 1 / s end end @weights FrequencyWeights @doc """ FrequencyWeights(vs, wsum=sum(vs)) Construct a `FrequencyWeights` vector with weight values `vs`. A precomputed sum may be provided as `wsum`. Frequency weights describe the number of times (or frequency) each observation was observed. These weights may also be referred to as case weights or repeat weights. """ FrequencyWeights """ fweights(vs) Construct a `FrequencyWeights` vector from a given array. See the documentation for [`FrequencyWeights`](@ref) for more details. """ fweights(vs::RealVector) = FrequencyWeights(vs) fweights(vs::RealArray) = FrequencyWeights(vec(vs)) """ varcorrection(w::FrequencyWeights, corrected=false) * `corrected=true`: ``\\frac{1}{\\sum{w} - 1}`` * `corrected=false`: ``\\frac{1}{\\sum w}`` """ @inline function varcorrection(w::FrequencyWeights, corrected::Bool=false) s = w.sum if corrected 1 / (s - 1) else 1 / s end end @weights ProbabilityWeights @doc """ ProbabilityWeights(vs, wsum=sum(vs)) Construct a `ProbabilityWeights` vector with weight values `vs`. A precomputed sum may be provided as `wsum`. Probability weights represent the inverse of the sampling probability for each observation, providing a correction mechanism for under- or over-sampling certain population groups. These weights may also be referred to as sampling weights. """ ProbabilityWeights """ pweights(vs) Construct a `ProbabilityWeights` vector from a given array. See the documentation for [`ProbabilityWeights`](@ref) for more details. """ pweights(vs::RealVector) = ProbabilityWeights(vs) pweights(vs::RealArray) = ProbabilityWeights(vec(vs)) """ varcorrection(w::ProbabilityWeights, corrected=false) * `corrected=true`: ``\\frac{n}{(n - 1) \\sum w}`` where ``n`` equals `count(!iszero, w)` * `corrected=false`: ``\\frac{1}{\\sum w}`` """ @inline function varcorrection(w::ProbabilityWeights, corrected::Bool=false) s = w.sum if corrected n = count(!iszero, w) n / (s * (n - 1)) else 1 / s end end ##### Equality tests ##### for w in (AnalyticWeights, FrequencyWeights, ProbabilityWeights, Weights) @eval begin Base.isequal(x::$w, y::$w) = isequal(x.sum, y.sum) && isequal(x.values, y.values) Base.:(==)(x::$w, y::$w) = (x.sum == y.sum) && (x.values == y.values) end end Base.isequal(x::AbstractWeights, y::AbstractWeights) = false Base.:(==)(x::AbstractWeights, y::AbstractWeights) = false ##### Weighted sum ##### ## weighted sum over vectors """ wsum(v, w::AbstractVector, [dim]) Compute the weighted sum of an array `v` with weights `w`, optionally over the dimension `dim`. """ wsum(v::AbstractVector, w::AbstractVector) = dot(v, w) wsum(v::AbstractArray, w::AbstractVector) = dot(vec(v), w) # Note: the methods for BitArray and SparseMatrixCSC are to avoid ambiguities Base.sum(v::BitArray, w::AbstractWeights) = wsum(v, values(w)) Base.sum(v::SparseArrays.SparseMatrixCSC, w::AbstractWeights) = wsum(v, values(w)) Base.sum(v::AbstractArray, w::AbstractWeights) = dot(v, values(w)) ## wsum along dimension # # Brief explanation of the algorithm: # ------------------------------------ # # 1. _wsum! provides the core implementation, which assumes that # the dimensions of all input arguments are consistent, and no # dimension checking is performed therein. # # wsum and wsum! perform argument checking and call _wsum! # internally. # # 2. _wsum! adopt a Cartesian based implementation for general # sub types of AbstractArray. Particularly, a faster routine # that keeps a local accumulator will be used when dim = 1. # # The internal function that implements this is _wsum_general! # # 3. _wsum! is specialized for following cases: # (a) A is a vector: we invoke the vector version wsum above. # The internal function that implements this is _wsum1! # # (b) A is a dense matrix with eltype <: BlasReal: we call gemv! # The internal function that implements this is _wsum2_blas! # # (c) A is a contiguous array with eltype <: BlasReal: # dim == 1: treat A like a matrix of size (d1, d2 x ... x dN) # dim == N: treat A like a matrix of size (d1 x ... x d(N-1), dN) # otherwise: decompose A into multiple pages, and apply _wsum2! # for each # # (d) A is a general dense array with eltype <: BlasReal: # dim <= 2: delegate to (a) and (b) # otherwise, decompose A into multiple pages # function _wsum1!(R::AbstractArray, A::AbstractVector, w::AbstractVector, init::Bool) r = wsum(A, w) if init R[1] = r else R[1] += r end return R end function _wsum2_blas!(R::StridedVector{T}, A::StridedMatrix{T}, w::StridedVector{T}, dim::Int, init::Bool) where T<:BlasReal beta = ifelse(init, zero(T), one(T)) trans = dim == 1 ? 'T' : 'N' BLAS.gemv!(trans, one(T), A, w, beta, R) return R end function _wsumN!(R::StridedArray{T}, A::StridedArray{T,N}, w::StridedVector{T}, dim::Int, init::Bool) where {T<:BlasReal,N} if dim == 1 m = size(A, 1) n = div(length(A), m) _wsum2_blas!(view(R,:), reshape(A, (m, n)), w, 1, init) elseif dim == N n = size(A, N) m = div(length(A), n) _wsum2_blas!(view(R,:), reshape(A, (m, n)), w, 2, init) else # 1 < dim < N m = 1 for i = 1:dim-1; m *= size(A, i); end n = size(A, dim) k = 1 for i = dim+1:N; k *= size(A, i); end Av = reshape(A, (m, n, k)) Rv = reshape(R, (m, k)) for i = 1:k _wsum2_blas!(view(Rv,:,i), view(Av,:,:,i), w, 2, init) end end return R end function _wsumN!(R::StridedArray{T}, A::DenseArray{T,N}, w::StridedVector{T}, dim::Int, init::Bool) where {T<:BlasReal,N} @assert N >= 3 if dim <= 2 m = size(A, 1) n = size(A, 2) npages = 1 for i = 3:N npages *= size(A, i) end rlen = ifelse(dim == 1, n, m) Rv = reshape(R, (rlen, npages)) for i = 1:npages _wsum2_blas!(view(Rv,:,i), view(A,:,:,i), w, dim, init) end else _wsum_general!(R, identity, A, w, dim, init) end return R end # General Cartesian-based weighted sum across dimensions @generated function _wsum_general!(R::AbstractArray{RT}, f::supertype(typeof(abs)), A::AbstractArray{T,N}, w::AbstractVector{WT}, dim::Int, init::Bool) where {T,RT,WT,N} quote init && fill!(R, zero(RT)) wi = zero(WT) if dim == 1 @nextract $N sizeR d->size(R,d) sizA1 = size(A, 1) @nloops $N i d->(d>1 ? (1:size(A,d)) : (1:1)) d->(j_d = sizeR_d==1 ? 1 : i_d) begin @inbounds r = (@nref $N R j) for i_1 = 1:sizA1 @inbounds r += f(@nref $N A i) * w[i_1] end @inbounds (@nref $N R j) = r end else @nloops $N i A d->(if d == dim wi = w[i_d] j_d = 1 else j_d = i_d end) @inbounds (@nref $N R j) += f(@nref $N A i) * wi end return R end end @generated function _wsum_centralize!(R::AbstractArray{RT}, f::supertype(typeof(abs)), A::AbstractArray{T,N}, w::AbstractVector{WT}, means, dim::Int, init::Bool) where {T,RT,WT,N} quote init && fill!(R, zero(RT)) wi = zero(WT) if dim == 1 @nextract $N sizeR d->size(R,d) sizA1 = size(A, 1) @nloops $N i d->(d>1 ? (1:size(A,d)) : (1:1)) d->(j_d = sizeR_d==1 ? 1 : i_d) begin @inbounds r = (@nref $N R j) @inbounds m = (@nref $N means j) for i_1 = 1:sizA1 @inbounds r += f((@nref $N A i) - m) * w[i_1] end @inbounds (@nref $N R j) = r end else @nloops $N i A d->(if d == dim wi = w[i_d] j_d = 1 else j_d = i_d end) @inbounds (@nref $N R j) += f((@nref $N A i) - (@nref $N means j)) * wi end return R end end # N = 1 _wsum!(R::StridedArray{T}, A::DenseArray{T,1}, w::StridedVector{T}, dim::Int, init::Bool) where {T<:BlasReal} = _wsum1!(R, A, w, init) # N = 2 _wsum!(R::StridedArray{T}, A::DenseArray{T,2}, w::StridedVector{T}, dim::Int, init::Bool) where {T<:BlasReal} = (_wsum2_blas!(view(R,:), A, w, dim, init); R) # N >= 3 _wsum!(R::StridedArray{T}, A::DenseArray{T,N}, w::StridedVector{T}, dim::Int, init::Bool) where {T<:BlasReal,N} = _wsumN!(R, A, w, dim, init) _wsum!(R::AbstractArray, A::AbstractArray, w::AbstractVector, dim::Int, init::Bool) = _wsum_general!(R, identity, A, w, dim, init) ## wsum! and wsum wsumtype(::Type{T}, ::Type{W}) where {T,W} = typeof(zero(T) * zero(W) + zero(T) * zero(W)) wsumtype(::Type{T}, ::Type{T}) where {T<:BlasReal} = T """ wsum!(R, A, w, dim; init=true) Compute the weighted sum of `A` with weights `w` over the dimension `dim` and store the result in `R`. If `init=false`, the sum is added to `R` rather than starting from zero. """ function wsum!(R::AbstractArray, A::AbstractArray{T,N}, w::AbstractVector, dim::Int; init::Bool=true) where {T,N} 1 <= dim <= N || error("dim should be within [1, $N]") ndims(R) <= N || error("ndims(R) should not exceed $N") length(w) == size(A,dim) || throw(DimensionMismatch("Inconsistent array dimension.")) # TODO: more careful examination of R's size _wsum!(R, A, w, dim, init) end function wsum(A::AbstractArray{T}, w::AbstractVector{W}, dim::Int) where {T<:Number,W<:Real} length(w) == size(A,dim) || throw(DimensionMismatch("Inconsistent array dimension.")) _wsum!(similar(A, wsumtype(T,W), Base.reduced_indices(axes(A), dim)), A, w, dim, true) end # extended sum! and wsum Base.sum!(R::AbstractArray, A::AbstractArray, w::AbstractWeights{<:Real}, dim::Int; init::Bool=true) = wsum!(R, A, values(w), dim; init=init) Base.sum(A::AbstractArray{<:Number}, w::AbstractWeights{<:Real}, dim::Int) = wsum(A, values(w), dim) ###### Weighted means ##### """ wmean(v, w::AbstractVector) Compute the weighted mean of an array `v` with weights `w`. """ function wmean(v::AbstractArray{<:Number}, w::AbstractVector) Base.depwarn("wmean is deprecated, use mean(v, weights(w)) instead.", :wmean) mean(v, weights(w)) end """ mean(A::AbstractArray, w::AbstractWeights[, dim::Int]) Compute the weighted mean of array `A` with weight vector `w` (of type `AbstractWeights`). If `dim` is provided, compute the weighted mean along dimension `dim`. # Examples ```julia w = rand(n) mean(x, weights(w)) ``` """ mean(A::AbstractArray, w::AbstractWeights) = sum(A, w) / sum(w) """ mean(R::AbstractArray, , A::AbstractArray, w::AbstractWeights[, dim::Int]) Compute the weighted mean of array `A` with weight vector `w` (of type `AbstractWeights`) along dimension `dim`, and write results to `R`. """ mean!(R::AbstractArray, A::AbstractArray, w::AbstractWeights, dim::Int) = rmul!(Base.sum!(R, A, w, dim), inv(sum(w))) wmeantype(::Type{T}, ::Type{W}) where {T,W} = typeof((zero(T)*zero(W) + zero(T)*zero(W)) / one(W)) wmeantype(::Type{T}, ::Type{T}) where {T<:BlasReal} = T mean(A::AbstractArray{T}, w::AbstractWeights{W}, dim::Int) where {T<:Number,W<:Real} = mean!(similar(A, wmeantype(T, W), Base.reduced_indices(axes(A), dim)), A, w, dim) ###### Weighted median ##### function median(v::AbstractArray, w::AbstractWeights) throw(MethodError(median, (v, w))) end """ median(v::RealVector, w::AbstractWeights) Compute the weighted median of `x`, using weights given by a weight vector `w` (of type `AbstractWeights`). The weight and data vectors must have the same length. The weighted median ``x_k`` is the element of `x` that satisfies ``\\sum_{x_i < x_k} w_i \\le \\frac{1}{2} \\sum_{j} w_j`` and ``\\sum_{x_i > x_k} w_i \\le \\frac{1}{2} \\sum_{j} w_j``. If a weight has value zero, then its associated data point is ignored. If none of the weights are positive, an error is thrown. `NaN` is returned if `x` contains any `NaN` values. An error is raised if `w` contains any `NaN` values. """ function median(v::RealVector, w::AbstractWeights{<:Real}) isempty(v) && error("median of an empty array is undefined") if length(v) != length(w) error("data and weight vectors must be the same size") end @inbounds for x in w.values isnan(x) && error("weight vector cannot contain NaN entries") end @inbounds for x in v isnan(x) && return x end mask = w.values .!= 0 if !any(mask) error("all weights are zero") end if all(w.values .<= 0) error("no positive weights found") end v = v[mask] wt = w[mask] midpoint = w.sum / 2 maxval, maxind = findmax(wt) if maxval > midpoint v[maxind] else permute = sortperm(v) cumulative_weight = zero(eltype(wt)) i = 0 for (_i, p) in enumerate(permute) i = _i if cumulative_weight == midpoint i += 1 break elseif cumulative_weight > midpoint cumulative_weight -= wt[p] break end cumulative_weight += wt[p] end if cumulative_weight == midpoint middle(v[permute[i-2]], v[permute[i-1]]) else middle(v[permute[i-1]]) end end end """ wmedian(v, w) Compute the weighted median of an array `v` with weights `w`, given as either a vector or an `AbstractWeights` vector. """ wmedian(v::RealVector, w::RealVector) = median(v, weights(w)) wmedian(v::RealVector, w::AbstractWeights{<:Real}) = median(v, w) ###### Weighted quantile ##### """ quantile(v, w::AbstractWeights, p) Compute the weighted quantiles of a vector `v` at a specified set of probability values `p`, using weights given by a weight vector `w` (of type `AbstractWeights`). Weights must not be negative. The weights and data vectors must have the same length. With [`FrequencyWeights`](@ref), the function returns the same result as `quantile` for a vector with repeated values. With non `FrequencyWeights`, denote ``N`` the length of the vector, ``w`` the vector of weights, ``h = p (\\sum_{i<= N}w_i - w_1) + w_1`` the cumulative weight corresponding to the probability ``p`` and ``S_k = \\sum_{i<=k}w_i`` the cumulative weight for each observation, define ``v_{k+1}`` the smallest element of `v` such that ``S_{k+1}`` is strictly superior to ``h``. The weighted ``p`` quantile is given by ``v_k + \\gamma (v_{k+1} -v_k)`` with ``\\gamma = (h - S_k)/(S_{k+1}-S_k)``. In particular, when `w` is a vector of ones, the function returns the same result as `quantile`. """ function quantile(v::RealVector{V}, w::AbstractWeights{W}, p::RealVector) where {V,W<:Real} # checks isempty(v) && error("quantile of an empty array is undefined") isempty(p) && throw(ArgumentError("empty quantile array")) w.sum == 0 && error("weight vector cannot sum to zero") length(v) == length(w) || error("data and weight vectors must be the same size, got $(length(v)) and $(length(w))") for x in w.values isnan(x) && error("weight vector cannot contain NaN entries") x < 0 && error("weight vector cannot contain negative entries") end # remove zeros weights and sort wsum = sum(w) nz = .!iszero.(w) vw = sort!(collect(zip(view(v, nz), view(w, nz)))) N = length(vw) # prepare percentiles ppermute = sortperm(p) p = p[ppermute] p = bound_quantiles(p) # prepare out vector out = Vector{typeof(zero(V)/1)}(undef, length(p)) fill!(out, vw[end][1]) # start looping on quantiles Sk, Skold = zero(W), zero(W) vk, vkold = zero(V), zero(V) k = 0 for i in 1:length(p) if isa(w, FrequencyWeights) h = p[i] * (wsum - 1) + 1 else h = p[i] * (wsum - vw[1][2]) + vw[1][2] end while Sk <= h k += 1 if k > N # out was initialized with maximum v return out end Skold, vkold = Sk, vk vk, wk = vw[k] Sk += wk end if isa(w, FrequencyWeights) out[ppermute[i]] = vkold + min(h - Skold, 1) * (vk - vkold) else out[ppermute[i]] = vkold + (h - Skold) / (Sk - Skold) * (vk - vkold) end end return out end # similarly to statistics.jl in Base function bound_quantiles(qs::AbstractVector{T}) where T<:Real epsilon = 100 * eps() if (any(qs .< -epsilon) || any(qs .> 1+epsilon)) throw(ArgumentError("quantiles out of [0,1] range")) end T[min(one(T), max(zero(T), q)) for q = qs] end quantile(v::RealVector, w::AbstractWeights{<:Real}, p::Number) = quantile(v, w, [p])[1] """ wquantile(v, w, p) Compute the `p`th quantile(s) of `v` with weights `w`, given as either a vector or an `AbstractWeights` vector. """ wquantile(v::RealVector, w::AbstractWeights{<:Real}, p::RealVector) = quantile(v, w, p) wquantile(v::RealVector, w::AbstractWeights{<:Real}, p::Number) = quantile(v, w, [p])[1] wquantile(v::RealVector, w::RealVector, p::RealVector) = quantile(v, weights(w), p) wquantile(v::RealVector, w::RealVector, p::Number) = quantile(v, weights(w), [p])[1]
/- Copyright (c) 2022 Kexing Ying. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kexing Ying -/ import measure_theory.function.convergence_in_measure import measure_theory.function.l1_space /-! # Uniform integrability This file contains the definitions for uniform integrability (both in the measure theory sense as well as the probability theory sense). This file also contains the Vitali convergence theorem which estabishes a relation between uniform integrability, convergence in measure and Lp convergence. Uniform integrability plays a vital role in the theory of martingales most notably is used to fomulate the martingale convergence theorem. ## Main definitions * `measure_theory.unif_integrable`: uniform integrability in the measure theory sense. In particular, a sequence of functions `f` is uniformly integrable if for all `ε > 0`, there exists some `δ > 0` such that for all sets `s` of smaller measure than `δ`, the Lp-norm of `f i` restricted `s` is smaller than `ε` for all `i`. * `measure_theory.uniform_integrable`: uniform integrability in the probability theory sense. In particular, a sequence of measurable functions `f` is uniformly integrable in the probability theory sense if it is uniformly integrable in the measure theory sense and has uniformly bounded Lp-norm. # Main results * `measure_theory.unif_integrable_fintype`: a finite sequence of Lp functions is uniformly integrable. * `measure_theory.tendsto_Lp_of_tendsto_ae`: a sequence of Lp functions which is uniformly integrable converges in Lp if they converge almost everywhere. * `measure_theory.tendsto_in_measure_iff_tendsto_Lp`: Vitali convergence theorem: a sequence of Lp functions converges in Lp if and only if it is uniformly integrable and converges in measure. ## Tags uniform integrable, uniformly absolutely continuous integral, Vitali convergence theorem -/ noncomputable theory open_locale classical measure_theory nnreal ennreal topology big_operators namespace measure_theory open set filter topological_space variables {α β ι : Type*} {m : measurable_space α} {μ : measure α} [normed_add_comm_group β] /-- Uniform integrability in the measure theory sense. A sequence of functions `f` is said to be uniformly integrable if for all `ε > 0`, there exists some `δ > 0` such that for all sets `s` with measure less than `δ`, the Lp-norm of `f i` restricted on `s` is less than `ε`. Uniform integrablility is also known as uniformly absolutely continuous integrals. -/ def unif_integrable {m : measurable_space α} (f : ι → α → β) (p : ℝ≥0∞) (μ : measure α) : Prop := ∀ ⦃ε : ℝ⦄ (hε : 0 < ε), ∃ (δ : ℝ) (hδ : 0 < δ), ∀ i s, measurable_set s → μ s ≤ ennreal.of_real δ → snorm (s.indicator (f i)) p μ ≤ ennreal.of_real ε /-- In probability theory, a family of measurable functions is uniformly integrable if it is uniformly integrable in the measure theory sense and is uniformly bounded. -/ def uniform_integrable {m : measurable_space α} (f : ι → α → β) (p : ℝ≥0∞) (μ : measure α) : Prop := (∀ i, ae_strongly_measurable (f i) μ) ∧ unif_integrable f p μ ∧ ∃ C : ℝ≥0, ∀ i, snorm (f i) p μ ≤ C namespace uniform_integrable protected lemma ae_strongly_measurable {f : ι → α → β} {p : ℝ≥0∞} (hf : uniform_integrable f p μ) (i : ι) : ae_strongly_measurable (f i) μ := hf.1 i protected lemma unif_integrable {f : ι → α → β} {p : ℝ≥0∞} (hf : uniform_integrable f p μ) : unif_integrable f p μ := hf.2.1 protected lemma mem_ℒp {f : ι → α → β} {p : ℝ≥0∞} (hf : uniform_integrable f p μ) (i : ι) : mem_ℒp (f i) p μ := ⟨hf.1 i, let ⟨_, _, hC⟩ := hf.2 in lt_of_le_of_lt (hC i) ennreal.coe_lt_top⟩ end uniform_integrable section unif_integrable /-! ### `unif_integrable` This section deals with uniform integrability in the measure theory sense. -/ namespace unif_integrable variables {f g : ι → α → β} {p : ℝ≥0∞} protected lemma add (hf : unif_integrable f p μ) (hg : unif_integrable g p μ) (hp : 1 ≤ p) (hf_meas : ∀ i, ae_strongly_measurable (f i) μ) (hg_meas : ∀ i, ae_strongly_measurable (g i) μ) : unif_integrable (f + g) p μ := begin intros ε hε, have hε2 : 0 < ε / 2 := half_pos hε, obtain ⟨δ₁, hδ₁_pos, hfδ₁⟩ := hf hε2, obtain ⟨δ₂, hδ₂_pos, hgδ₂⟩ := hg hε2, refine ⟨min δ₁ δ₂, lt_min hδ₁_pos hδ₂_pos, λ i s hs hμs, _⟩, simp_rw [pi.add_apply, indicator_add'], refine (snorm_add_le ((hf_meas i).indicator hs) ((hg_meas i).indicator hs) hp).trans _, have hε_halves : ennreal.of_real ε = ennreal.of_real (ε / 2) + ennreal.of_real (ε / 2), by rw [← ennreal.of_real_add hε2.le hε2.le, add_halves], rw hε_halves, exact add_le_add (hfδ₁ i s hs (hμs.trans (ennreal.of_real_le_of_real (min_le_left _ _)))) (hgδ₂ i s hs (hμs.trans (ennreal.of_real_le_of_real (min_le_right _ _)))), end protected lemma neg (hf : unif_integrable f p μ) : unif_integrable (-f) p μ := by { simp_rw [unif_integrable, pi.neg_apply, indicator_neg', snorm_neg], exact hf, } protected lemma sub (hf : unif_integrable f p μ) (hg : unif_integrable g p μ) (hp : 1 ≤ p) (hf_meas : ∀ i, ae_strongly_measurable (f i) μ) (hg_meas : ∀ i, ae_strongly_measurable (g i) μ) : unif_integrable (f - g) p μ := by { rw sub_eq_add_neg, exact hf.add hg.neg hp hf_meas (λ i, (hg_meas i).neg), } protected lemma ae_eq (hf : unif_integrable f p μ) (hfg : ∀ n, f n =ᵐ[μ] g n) : unif_integrable g p μ := begin intros ε hε, obtain ⟨δ, hδ_pos, hfδ⟩ := hf hε, refine ⟨δ, hδ_pos, λ n s hs hμs, (le_of_eq $ snorm_congr_ae _).trans (hfδ n s hs hμs)⟩, filter_upwards [hfg n] with x hx, simp_rw [indicator_apply, hx], end end unif_integrable lemma unif_integrable_zero_meas [measurable_space α] {p : ℝ≥0∞} {f : ι → α → β} : unif_integrable f p (0 : measure α) := λ ε hε, ⟨1, one_pos, λ i s hs hμs, by simp⟩ lemma unif_integrable_congr_ae {p : ℝ≥0∞} {f g : ι → α → β} (hfg : ∀ n, f n =ᵐ[μ] g n) : unif_integrable f p μ ↔ unif_integrable g p μ := ⟨λ hf, hf.ae_eq hfg, λ hg, hg.ae_eq (λ n, (hfg n).symm)⟩ lemma tendsto_indicator_ge (f : α → β) (x : α): tendsto (λ M : ℕ, {x | (M : ℝ) ≤ ‖f x‖₊}.indicator f x) at_top (𝓝 0) := begin refine @tendsto_at_top_of_eventually_const _ _ _ _ _ _ _ (nat.ceil (‖f x‖₊ : ℝ) + 1) (λ n hn, _), rw indicator_of_not_mem, simp only [not_le, mem_set_of_eq], refine lt_of_le_of_lt (nat.le_ceil _) _, refine lt_of_lt_of_le (lt_add_one _) _, norm_cast, rwa [ge_iff_le, coe_nnnorm] at hn, end variables (μ) {p : ℝ≥0∞} section variables {f : α → β} /-- This lemma is weaker than `measure_theory.mem_ℒp.integral_indicator_norm_ge_nonneg_le` as the latter provides `0 ≤ M` and does not require the measurability of `f`. -/ lemma mem_ℒp.integral_indicator_norm_ge_le (hf : mem_ℒp f 1 μ) (hmeas : strongly_measurable f) {ε : ℝ} (hε : 0 < ε) : ∃ M : ℝ, ∫⁻ x, ‖{x | M ≤ ‖f x‖₊}.indicator f x‖₊ ∂μ ≤ ennreal.of_real ε := begin have htendsto : ∀ᵐ x ∂μ, tendsto (λ M : ℕ, {x | (M : ℝ) ≤ ‖f x‖₊}.indicator f x) at_top (𝓝 0) := univ_mem' (id $ λ x, tendsto_indicator_ge f x), have hmeas : ∀ M : ℕ, ae_strongly_measurable ({x | (M : ℝ) ≤ ‖f x‖₊}.indicator f) μ, { assume M, apply hf.1.indicator, apply strongly_measurable.measurable_set_le strongly_measurable_const hmeas.nnnorm.measurable.coe_nnreal_real.strongly_measurable }, have hbound : has_finite_integral (λ x, ‖f x‖) μ, { rw mem_ℒp_one_iff_integrable at hf, exact hf.norm.2 }, have := tendsto_lintegral_norm_of_dominated_convergence hmeas hbound _ htendsto, { rw ennreal.tendsto_at_top_zero at this, obtain ⟨M, hM⟩ := this (ennreal.of_real ε) (ennreal.of_real_pos.2 hε), simp only [true_and, ge_iff_le, zero_tsub, zero_le, sub_zero, zero_add, coe_nnnorm, mem_Icc] at hM, refine ⟨M, _⟩, convert hM M le_rfl, ext1 x, simp only [coe_nnnorm, ennreal.of_real_eq_coe_nnreal (norm_nonneg _)], refl }, { refine λ n, univ_mem' (id $ λ x, _), by_cases hx : (n : ℝ) ≤ ‖f x‖, { dsimp, rwa indicator_of_mem }, { dsimp, rw [indicator_of_not_mem, norm_zero], { exact norm_nonneg _ }, { assumption } } } end /-- This lemma is superceded by `measure_theory.mem_ℒp.integral_indicator_norm_ge_nonneg_le` which does not require measurability. -/ lemma mem_ℒp.integral_indicator_norm_ge_nonneg_le_of_meas (hf : mem_ℒp f 1 μ) (hmeas : strongly_measurable f) {ε : ℝ} (hε : 0 < ε) : ∃ M : ℝ, 0 ≤ M ∧ ∫⁻ x, ‖{x | M ≤ ‖f x‖₊}.indicator f x‖₊ ∂μ ≤ ennreal.of_real ε := let ⟨M, hM⟩ := hf.integral_indicator_norm_ge_le μ hmeas hε in ⟨max M 0, le_max_right _ _, by simpa⟩ lemma mem_ℒp.integral_indicator_norm_ge_nonneg_le (hf : mem_ℒp f 1 μ) {ε : ℝ} (hε : 0 < ε) : ∃ M : ℝ, 0 ≤ M ∧ ∫⁻ x, ‖{x | M ≤ ‖f x‖₊}.indicator f x‖₊ ∂μ ≤ ennreal.of_real ε := begin have hf_mk : mem_ℒp (hf.1.mk f) 1 μ := (mem_ℒp_congr_ae hf.1.ae_eq_mk).mp hf, obtain ⟨M, hM_pos, hfM⟩ := hf_mk.integral_indicator_norm_ge_nonneg_le_of_meas μ hf.1.strongly_measurable_mk hε, refine ⟨M, hM_pos, (le_of_eq _).trans hfM⟩, refine lintegral_congr_ae _, filter_upwards [hf.1.ae_eq_mk] with x hx, simp only [indicator_apply, coe_nnnorm, mem_set_of_eq, ennreal.coe_eq_coe, hx.symm], end lemma mem_ℒp.snorm_ess_sup_indicator_norm_ge_eq_zero (hf : mem_ℒp f ∞ μ) (hmeas : strongly_measurable f) : ∃ M : ℝ, snorm_ess_sup ({x | M ≤ ‖f x‖₊}.indicator f) μ = 0 := begin have hbdd : snorm_ess_sup f μ < ∞ := hf.snorm_lt_top, refine ⟨(snorm f ∞ μ + 1).to_real, _⟩, rw snorm_ess_sup_indicator_eq_snorm_ess_sup_restrict, have : μ.restrict {x : α | (snorm f ⊤ μ + 1).to_real ≤ ‖f x‖₊} = 0, { simp only [coe_nnnorm, snorm_exponent_top, measure.restrict_eq_zero], have : {x : α | (snorm_ess_sup f μ + 1).to_real ≤ ‖f x‖} ⊆ {x : α | snorm_ess_sup f μ < ‖f x‖₊}, { intros x hx, rw [mem_set_of_eq, ← ennreal.to_real_lt_to_real hbdd.ne ennreal.coe_lt_top.ne, ennreal.coe_to_real, coe_nnnorm], refine lt_of_lt_of_le _ hx, rw ennreal.to_real_lt_to_real hbdd.ne, { exact ennreal.lt_add_right hbdd.ne one_ne_zero }, { exact (ennreal.add_lt_top.2 ⟨hbdd, ennreal.one_lt_top⟩).ne } }, rw ← nonpos_iff_eq_zero, refine (measure_mono this).trans _, have hle := coe_nnnorm_ae_le_snorm_ess_sup f μ, simp_rw [ae_iff, not_le] at hle, exact nonpos_iff_eq_zero.2 hle }, rw [this, snorm_ess_sup_measure_zero], exact measurable_set_le measurable_const hmeas.nnnorm.measurable.subtype_coe, end /- This lemma is slightly weaker than `measure_theory.mem_ℒp.snorm_indicator_norm_ge_pos_le` as the latter provides `0 < M`. -/ lemma mem_ℒp.snorm_indicator_norm_ge_le (hf : mem_ℒp f p μ) (hmeas : strongly_measurable f) {ε : ℝ} (hε : 0 < ε) : ∃ M : ℝ, snorm ({x | M ≤ ‖f x‖₊}.indicator f) p μ ≤ ennreal.of_real ε := begin by_cases hp_ne_zero : p = 0, { refine ⟨1, hp_ne_zero.symm ▸ _⟩, simp [snorm_exponent_zero] }, by_cases hp_ne_top : p = ∞, { subst hp_ne_top, obtain ⟨M, hM⟩ := hf.snorm_ess_sup_indicator_norm_ge_eq_zero μ hmeas, refine ⟨M, _⟩, simp only [snorm_exponent_top, hM, zero_le] }, obtain ⟨M, hM', hM⟩ := @mem_ℒp.integral_indicator_norm_ge_nonneg_le _ _ _ μ _ (λ x, ‖f x‖^p.to_real) (hf.norm_rpow hp_ne_zero hp_ne_top) _ (real.rpow_pos_of_pos hε p.to_real), refine ⟨M ^(1 / p.to_real), _⟩, rw [snorm_eq_lintegral_rpow_nnnorm hp_ne_zero hp_ne_top, ← ennreal.rpow_one (ennreal.of_real ε)], conv_rhs { rw ← mul_one_div_cancel (ennreal.to_real_pos hp_ne_zero hp_ne_top).ne.symm }, rw [ennreal.rpow_mul, ennreal.rpow_le_rpow_iff (one_div_pos.2 $ ennreal.to_real_pos hp_ne_zero hp_ne_top), ennreal.of_real_rpow_of_pos hε], convert hM, ext1 x, rw [ennreal.coe_rpow_of_nonneg _ ennreal.to_real_nonneg, nnnorm_indicator_eq_indicator_nnnorm, nnnorm_indicator_eq_indicator_nnnorm], have hiff : M ^ (1 / p.to_real) ≤ ‖f x‖₊ ↔ M ≤ ‖‖f x‖ ^ p.to_real‖₊, { rw [coe_nnnorm, coe_nnnorm, real.norm_rpow_of_nonneg (norm_nonneg _), norm_norm, ← real.rpow_le_rpow_iff hM' (real.rpow_nonneg_of_nonneg (norm_nonneg _) _) (one_div_pos.2 $ ennreal.to_real_pos hp_ne_zero hp_ne_top), ← real.rpow_mul (norm_nonneg _), mul_one_div_cancel (ennreal.to_real_pos hp_ne_zero hp_ne_top).ne.symm, real.rpow_one] }, by_cases hx : x ∈ {x : α | M ^ (1 / p.to_real) ≤ ‖f x‖₊}, { rw [set.indicator_of_mem hx,set.indicator_of_mem, real.nnnorm_of_nonneg], refl, change _ ≤ _, rwa ← hiff }, { rw [set.indicator_of_not_mem hx, set.indicator_of_not_mem], { simp [(ennreal.to_real_pos hp_ne_zero hp_ne_top).ne.symm] }, { change ¬ _ ≤ _, rwa ← hiff } } end /-- This lemma implies that a single function is uniformly integrable (in the probability sense). -/ lemma mem_ℒp.snorm_indicator_norm_ge_pos_le (hf : mem_ℒp f p μ) (hmeas : strongly_measurable f) {ε : ℝ} (hε : 0 < ε) : ∃ M : ℝ, 0 < M ∧ snorm ({x | M ≤ ‖f x‖₊}.indicator f) p μ ≤ ennreal.of_real ε := begin obtain ⟨M, hM⟩ := hf.snorm_indicator_norm_ge_le μ hmeas hε, refine ⟨max M 1, lt_of_lt_of_le zero_lt_one (le_max_right _ _), le_trans (snorm_mono (λ x, _)) hM⟩, rw [norm_indicator_eq_indicator_norm, norm_indicator_eq_indicator_norm], refine indicator_le_indicator_of_subset (λ x hx, _) (λ x, norm_nonneg _) x, change max _ _ ≤ _ at hx, -- removing the `change` breaks the proof! exact (max_le_iff.1 hx).1, end end lemma snorm_indicator_le_of_bound {f : α → β} (hp_top : p ≠ ∞) {ε : ℝ} (hε : 0 < ε) {M : ℝ} (hf : ∀ x, ‖f x‖ < M) : ∃ (δ : ℝ) (hδ : 0 < δ), ∀ s, measurable_set s → μ s ≤ ennreal.of_real δ → snorm (s.indicator f) p μ ≤ ennreal.of_real ε := begin by_cases hM : M ≤ 0, { refine ⟨1, zero_lt_one, λ s hs hμ, _⟩, rw (_ : f = 0), { simp [hε.le] }, { ext x, rw [pi.zero_apply, ← norm_le_zero_iff], exact (lt_of_lt_of_le (hf x) hM).le } }, rw not_le at hM, refine ⟨(ε / M) ^ p.to_real, real.rpow_pos_of_pos (div_pos hε hM) _, λ s hs hμ, _⟩, by_cases hp : p = 0, { simp [hp] }, rw snorm_indicator_eq_snorm_restrict hs, have haebdd : ∀ᵐ x ∂μ.restrict s, ‖f x‖ ≤ M, { filter_upwards, exact (λ x, (hf x).le) }, refine le_trans (snorm_le_of_ae_bound haebdd) _, rw [measure.restrict_apply measurable_set.univ, univ_inter, ← ennreal.le_div_iff_mul_le (or.inl _) (or.inl ennreal.of_real_ne_top)], { rw [← one_div, ennreal.rpow_one_div_le_iff (ennreal.to_real_pos hp hp_top)], refine le_trans hμ _, rw [← ennreal.of_real_rpow_of_pos (div_pos hε hM), ennreal.rpow_le_rpow_iff (ennreal.to_real_pos hp hp_top), ennreal.of_real_div_of_pos hM], exact le_rfl }, { simpa only [ennreal.of_real_eq_zero, not_le, ne.def] }, end section variables {f : α → β} /-- Auxiliary lemma for `measure_theory.mem_ℒp.snorm_indicator_le`. -/ lemma mem_ℒp.snorm_indicator_le' (hp_one : 1 ≤ p) (hp_top : p ≠ ∞) (hf : mem_ℒp f p μ) (hmeas : strongly_measurable f) {ε : ℝ} (hε : 0 < ε) : ∃ (δ : ℝ) (hδ : 0 < δ), ∀ s, measurable_set s → μ s ≤ ennreal.of_real δ → snorm (s.indicator f) p μ ≤ 2 * ennreal.of_real ε := begin obtain ⟨M, hMpos, hM⟩ := hf.snorm_indicator_norm_ge_pos_le μ hmeas hε, obtain ⟨δ, hδpos, hδ⟩ := @snorm_indicator_le_of_bound _ _ _ μ _ _ ({x | ‖f x‖ < M}.indicator f) hp_top _ hε M _, { refine ⟨δ, hδpos, λ s hs hμs, _⟩, rw (_ : f = {x : α | M ≤ ‖f x‖₊}.indicator f + {x : α | ‖f x‖ < M}.indicator f), { rw snorm_indicator_eq_snorm_restrict hs, refine le_trans (snorm_add_le _ _ hp_one) _, { exact strongly_measurable.ae_strongly_measurable (hmeas.indicator (measurable_set_le measurable_const hmeas.nnnorm.measurable.subtype_coe)) }, { exact strongly_measurable.ae_strongly_measurable (hmeas.indicator (measurable_set_lt hmeas.nnnorm.measurable.subtype_coe measurable_const)) }, { rw two_mul, refine add_le_add (le_trans (snorm_mono_measure _ measure.restrict_le_self) hM) _, rw ← snorm_indicator_eq_snorm_restrict hs, exact hδ s hs hμs } }, { ext x, by_cases hx : M ≤ ‖f x‖, { rw [pi.add_apply, indicator_of_mem, indicator_of_not_mem, add_zero]; simpa }, { rw [pi.add_apply, indicator_of_not_mem, indicator_of_mem, zero_add]; simpa using hx } } }, { intros x, rw [norm_indicator_eq_indicator_norm, indicator_apply], split_ifs, exacts [h, hMpos] } end /-- This lemma is superceded by `measure_theory.mem_ℒp.snorm_indicator_le` which does not require measurability on `f`. -/ lemma mem_ℒp.snorm_indicator_le_of_meas (hp_one : 1 ≤ p) (hp_top : p ≠ ∞) (hf : mem_ℒp f p μ) (hmeas : strongly_measurable f) {ε : ℝ} (hε : 0 < ε) : ∃ (δ : ℝ) (hδ : 0 < δ), ∀ s, measurable_set s → μ s ≤ ennreal.of_real δ → snorm (s.indicator f) p μ ≤ ennreal.of_real ε := begin obtain ⟨δ, hδpos, hδ⟩ := hf.snorm_indicator_le' μ hp_one hp_top hmeas (half_pos hε), refine ⟨δ, hδpos, λ s hs hμs, le_trans (hδ s hs hμs) _⟩, rw [ennreal.of_real_div_of_pos zero_lt_two, (by norm_num : ennreal.of_real 2 = 2), ennreal.mul_div_cancel']; norm_num, end lemma mem_ℒp.snorm_indicator_le (hp_one : 1 ≤ p) (hp_top : p ≠ ∞) (hf : mem_ℒp f p μ) {ε : ℝ} (hε : 0 < ε) : ∃ (δ : ℝ) (hδ : 0 < δ), ∀ s, measurable_set s → μ s ≤ ennreal.of_real δ → snorm (s.indicator f) p μ ≤ ennreal.of_real ε := begin have hℒp := hf, obtain ⟨⟨f', hf', heq⟩, hnorm⟩ := hf, obtain ⟨δ, hδpos, hδ⟩ := (hℒp.ae_eq heq).snorm_indicator_le_of_meas μ hp_one hp_top hf' hε, refine ⟨δ, hδpos, λ s hs hμs, _⟩, convert hδ s hs hμs using 1, rw [snorm_indicator_eq_snorm_restrict hs, snorm_indicator_eq_snorm_restrict hs], refine snorm_congr_ae heq.restrict, end /-- A constant function is uniformly integrable. -/ lemma unif_integrable_const {g : α → β} (hp : 1 ≤ p) (hp_ne_top : p ≠ ∞) (hg : mem_ℒp g p μ) : unif_integrable (λ n : ι, g) p μ := begin intros ε hε, obtain ⟨δ, hδ_pos, hgδ⟩ := hg.snorm_indicator_le μ hp hp_ne_top hε, exact ⟨δ, hδ_pos, λ i, hgδ⟩, end /-- A single function is uniformly integrable. -/ lemma unif_integrable_subsingleton [subsingleton ι] (hp_one : 1 ≤ p) (hp_top : p ≠ ∞) {f : ι → α → β} (hf : ∀ i, mem_ℒp (f i) p μ) : unif_integrable f p μ := begin intros ε hε, by_cases hι : nonempty ι, { cases hι with i, obtain ⟨δ, hδpos, hδ⟩ := (hf i).snorm_indicator_le μ hp_one hp_top hε, refine ⟨δ, hδpos, λ j s hs hμs, _⟩, convert hδ s hs hμs }, { exact ⟨1, zero_lt_one, λ i, false.elim $ hι $ nonempty.intro i⟩ } end /-- This lemma is less general than `measure_theory.unif_integrable_fintype` which applies to all sequences indexed by a finite type. -/ lemma unif_integrable_fin (hp_one : 1 ≤ p) (hp_top : p ≠ ∞) {n : ℕ} {f : fin n → α → β} (hf : ∀ i, mem_ℒp (f i) p μ) : unif_integrable f p μ := begin revert f, induction n with n h, { exact (λ f hf, unif_integrable_subsingleton μ hp_one hp_top hf) }, intros f hfLp ε hε, set g : fin n → α → β := λ k, f k with hg, have hgLp : ∀ i, mem_ℒp (g i) p μ := λ i, hfLp i, obtain ⟨δ₁, hδ₁pos, hδ₁⟩ := h hgLp hε, obtain ⟨δ₂, hδ₂pos, hδ₂⟩ := (hfLp n).snorm_indicator_le μ hp_one hp_top hε, refine ⟨min δ₁ δ₂, lt_min hδ₁pos hδ₂pos, λ i s hs hμs, _⟩, by_cases hi : i.val < n, { rw (_ : f i = g ⟨i.val, hi⟩), { exact hδ₁ _ s hs (le_trans hμs $ ennreal.of_real_le_of_real $ min_le_left _ _) }, { rw hg, simp } }, { rw (_ : i = n), { exact hδ₂ _ hs (le_trans hμs $ ennreal.of_real_le_of_real $ min_le_right _ _) }, { have hi' := fin.is_lt i, rw nat.lt_succ_iff at hi', rw not_lt at hi, simp [← le_antisymm hi' hi] } } end /-- A finite sequence of Lp functions is uniformly integrable. -/ lemma unif_integrable_finite [finite ι] (hp_one : 1 ≤ p) (hp_top : p ≠ ∞) {f : ι → α → β} (hf : ∀ i, mem_ℒp (f i) p μ) : unif_integrable f p μ := begin obtain ⟨n, hn⟩ := finite.exists_equiv_fin ι, intros ε hε, set g : fin n → α → β := f ∘ hn.some.symm with hgeq, have hg : ∀ i, mem_ℒp (g i) p μ := λ _, hf _, obtain ⟨δ, hδpos, hδ⟩ := unif_integrable_fin μ hp_one hp_top hg hε, refine ⟨δ, hδpos, λ i s hs hμs, _⟩, specialize hδ (hn.some i) s hs hμs, simp_rw [hgeq, function.comp_app, equiv.symm_apply_apply] at hδ, assumption, end end lemma snorm_sub_le_of_dist_bdd {p : ℝ≥0∞} (hp' : p ≠ ∞) {s : set α} (hs : measurable_set[m] s) {f g : α → β} {c : ℝ} (hc : 0 ≤ c) (hf : ∀ x ∈ s, dist (f x) (g x) ≤ c) : snorm (s.indicator (f - g)) p μ ≤ ennreal.of_real c * μ s ^ (1 / p.to_real) := begin by_cases hp : p = 0, { simp [hp], }, have : ∀ x, ‖s.indicator (f - g) x‖ ≤ ‖s.indicator (λ x, c) x‖, { intro x, by_cases hx : x ∈ s, { rw [indicator_of_mem hx, indicator_of_mem hx, pi.sub_apply, ← dist_eq_norm, real.norm_eq_abs, abs_of_nonneg hc], exact hf x hx }, { simp [indicator_of_not_mem hx] } }, refine le_trans (snorm_mono this) _, rw snorm_indicator_const hs hp hp', refine mul_le_mul_right' (le_of_eq _) _, rw [← of_real_norm_eq_coe_nnnorm, real.norm_eq_abs, abs_of_nonneg hc], end /-- A sequence of uniformly integrable functions which converges μ-a.e. converges in Lp. -/ lemma tendsto_Lp_of_tendsto_ae_of_meas [is_finite_measure μ] (hp : 1 ≤ p) (hp' : p ≠ ∞) {f : ℕ → α → β} {g : α → β} (hf : ∀ n, strongly_measurable (f n)) (hg : strongly_measurable g) (hg' : mem_ℒp g p μ) (hui : unif_integrable f p μ) (hfg : ∀ᵐ x ∂μ, tendsto (λ n, f n x) at_top (𝓝 (g x))) : tendsto (λ n, snorm (f n - g) p μ) at_top (𝓝 0) := begin rw ennreal.tendsto_at_top_zero, intros ε hε, by_cases ε < ∞, swap, { rw [not_lt, top_le_iff] at h, exact ⟨0, λ n hn, by simp [h]⟩ }, by_cases hμ : μ = 0, { exact ⟨0, λ n hn, by simp [hμ]⟩ }, have hε' : 0 < ε.to_real / 3 := div_pos (ennreal.to_real_pos (gt_iff_lt.1 hε).ne.symm h.ne) (by norm_num), have hdivp : 0 ≤ 1 / p.to_real, { refine one_div_nonneg.2 _, rw [← ennreal.zero_to_real, ennreal.to_real_le_to_real ennreal.zero_ne_top hp'], exact le_trans (zero_le _) hp }, have hpow : 0 < (measure_univ_nnreal μ) ^ (1 / p.to_real) := real.rpow_pos_of_pos (measure_univ_nnreal_pos hμ) _, obtain ⟨δ₁, hδ₁, hsnorm₁⟩ := hui hε', obtain ⟨δ₂, hδ₂, hsnorm₂⟩ := hg'.snorm_indicator_le μ hp hp' hε', obtain ⟨t, htm, ht₁, ht₂⟩ := tendsto_uniformly_on_of_ae_tendsto' hf hg hfg (lt_min hδ₁ hδ₂), rw metric.tendsto_uniformly_on_iff at ht₂, specialize ht₂ (ε.to_real / (3 * measure_univ_nnreal μ ^ (1 / p.to_real))) (div_pos (ennreal.to_real_pos (gt_iff_lt.1 hε).ne.symm h.ne) (mul_pos (by norm_num) hpow)), obtain ⟨N, hN⟩ := eventually_at_top.1 ht₂, clear ht₂, refine ⟨N, λ n hn, _⟩, rw [← t.indicator_self_add_compl (f n - g)], refine le_trans (snorm_add_le ((((hf n).sub hg).indicator htm).ae_strongly_measurable) (((hf n).sub hg).indicator htm.compl).ae_strongly_measurable hp) _, rw [sub_eq_add_neg, indicator_add' t, indicator_neg'], refine le_trans (add_le_add_right (snorm_add_le ((hf n).indicator htm).ae_strongly_measurable (hg.indicator htm).neg.ae_strongly_measurable hp) _) _, have hnf : snorm (t.indicator (f n)) p μ ≤ ennreal.of_real (ε.to_real / 3), { refine hsnorm₁ n t htm (le_trans ht₁ _), rw ennreal.of_real_le_of_real_iff hδ₁.le, exact min_le_left _ _ }, have hng : snorm (t.indicator g) p μ ≤ ennreal.of_real (ε.to_real / 3), { refine hsnorm₂ t htm (le_trans ht₁ _), rw ennreal.of_real_le_of_real_iff hδ₂.le, exact min_le_right _ _ }, have hlt : snorm (tᶜ.indicator (f n - g)) p μ ≤ ennreal.of_real (ε.to_real / 3), { specialize hN n hn, have := snorm_sub_le_of_dist_bdd μ hp' htm.compl _ (λ x hx, (dist_comm (g x) (f n x) ▸ (hN x hx).le : dist (f n x) (g x) ≤ ε.to_real / (3 * measure_univ_nnreal μ ^ (1 / p.to_real)))), refine le_trans this _, rw [div_mul_eq_div_mul_one_div, ← ennreal.of_real_to_real (measure_lt_top μ tᶜ).ne, ennreal.of_real_rpow_of_nonneg ennreal.to_real_nonneg hdivp, ← ennreal.of_real_mul, mul_assoc], { refine ennreal.of_real_le_of_real (mul_le_of_le_one_right hε'.le _), rw [mul_comm, mul_one_div, div_le_one], { refine real.rpow_le_rpow ennreal.to_real_nonneg (ennreal.to_real_le_of_le_of_real (measure_univ_nnreal_pos hμ).le _) hdivp, rw [ennreal.of_real_coe_nnreal, coe_measure_univ_nnreal], exact measure_mono (subset_univ _) }, { exact real.rpow_pos_of_pos (measure_univ_nnreal_pos hμ) _ } }, { refine mul_nonneg (hε').le (one_div_nonneg.2 hpow.le) }, { rw div_mul_eq_div_mul_one_div, exact mul_nonneg hε'.le (one_div_nonneg.2 hpow.le) } }, have : ennreal.of_real (ε.to_real / 3) = ε / 3, { rw [ennreal.of_real_div_of_pos (show (0 : ℝ) < 3, by norm_num), ennreal.of_real_to_real h.ne], simp }, rw this at hnf hng hlt, rw [snorm_neg, ← ennreal.add_thirds ε, ← sub_eq_add_neg], exact add_le_add_three hnf hng hlt end /-- A sequence of uniformly integrable functions which converges μ-a.e. converges in Lp. -/ lemma tendsto_Lp_of_tendsto_ae [is_finite_measure μ] (hp : 1 ≤ p) (hp' : p ≠ ∞) {f : ℕ → α → β} {g : α → β} (hf : ∀ n, ae_strongly_measurable (f n) μ) (hg : mem_ℒp g p μ) (hui : unif_integrable f p μ) (hfg : ∀ᵐ x ∂μ, tendsto (λ n, f n x) at_top (𝓝 (g x))) : tendsto (λ n, snorm (f n - g) p μ) at_top (𝓝 0) := begin suffices : tendsto (λ (n : ℕ), snorm ((hf n).mk (f n) - (hg.1.mk g)) p μ) at_top (𝓝 0), { convert this, exact funext (λ n, snorm_congr_ae ((hf n).ae_eq_mk.sub hg.1.ae_eq_mk)), }, refine tendsto_Lp_of_tendsto_ae_of_meas μ hp hp' (λ n, (hf n).strongly_measurable_mk) hg.1.strongly_measurable_mk (hg.ae_eq hg.1.ae_eq_mk) (hui.ae_eq (λ n, (hf n).ae_eq_mk)) _, have h_ae_forall_eq : ∀ᵐ x ∂μ, ∀ n, f n x = (hf n).mk (f n) x, { rw ae_all_iff, exact λ n, (hf n).ae_eq_mk, }, filter_upwards [hfg, h_ae_forall_eq, hg.1.ae_eq_mk] with x hx_tendsto hxf_eq hxg_eq, rw ← hxg_eq, convert hx_tendsto, ext1 n, exact (hxf_eq n).symm, end variables {f : ℕ → α → β} {g : α → β} lemma unif_integrable_of_tendsto_Lp_zero (hp : 1 ≤ p) (hp' : p ≠ ∞) (hf : ∀ n, mem_ℒp (f n) p μ) (hf_tendsto : tendsto (λ n, snorm (f n) p μ) at_top (𝓝 0)) : unif_integrable f p μ := begin intros ε hε, rw ennreal.tendsto_at_top_zero at hf_tendsto, obtain ⟨N, hN⟩ := hf_tendsto (ennreal.of_real ε) (by simpa), set F : fin N → α → β := λ n, f n, have hF : ∀ n, mem_ℒp (F n) p μ := λ n, hf n, obtain ⟨δ₁, hδpos₁, hδ₁⟩ := unif_integrable_fin μ hp hp' hF hε, refine ⟨δ₁, hδpos₁, λ n s hs hμs, _⟩, by_cases hn : n < N, { exact hδ₁ ⟨n, hn⟩ s hs hμs }, { exact (snorm_indicator_le _).trans (hN n (not_lt.1 hn)) }, end /-- Convergence in Lp implies uniform integrability. -/ lemma unif_integrable_of_tendsto_Lp (hp : 1 ≤ p) (hp' : p ≠ ∞) (hf : ∀ n, mem_ℒp (f n) p μ) (hg : mem_ℒp g p μ) (hfg : tendsto (λ n, snorm (f n - g) p μ) at_top (𝓝 0)) : unif_integrable f p μ := begin have : f = (λ n, g) + λ n, f n - g, by { ext1 n, simp, }, rw this, refine unif_integrable.add _ _ hp (λ _, hg.ae_strongly_measurable) (λ n, (hf n).1.sub hg.ae_strongly_measurable), { exact unif_integrable_const μ hp hp' hg, }, { exact unif_integrable_of_tendsto_Lp_zero μ hp hp' (λ n, (hf n).sub hg) hfg, }, end /-- Forward direction of Vitali's convergence theorem: if `f` is a sequence of uniformly integrable functions that converge in measure to some function `g` in a finite measure space, then `f` converge in Lp to `g`. -/ lemma tendsto_Lp_of_tendsto_in_measure [is_finite_measure μ] (hp : 1 ≤ p) (hp' : p ≠ ∞) (hf : ∀ n, ae_strongly_measurable (f n) μ) (hg : mem_ℒp g p μ) (hui : unif_integrable f p μ) (hfg : tendsto_in_measure μ f at_top g) : tendsto (λ n, snorm (f n - g) p μ) at_top (𝓝 0) := begin refine tendsto_of_subseq_tendsto (λ ns hns, _), obtain ⟨ms, hms, hms'⟩ := tendsto_in_measure.exists_seq_tendsto_ae (λ ε hε, (hfg ε hε).comp hns), exact ⟨ms, tendsto_Lp_of_tendsto_ae μ hp hp' (λ _, hf _) hg (λ ε hε, let ⟨δ, hδ, hδ'⟩ := hui hε in ⟨δ, hδ, λ i s hs hμs, hδ' _ s hs hμs⟩) hms'⟩, end /-- **Vitali's convergence theorem**: A sequence of functions `f` converges to `g` in Lp if and only if it is uniformly integrable and converges to `g` in measure. -/ lemma tendsto_in_measure_iff_tendsto_Lp [is_finite_measure μ] (hp : 1 ≤ p) (hp' : p ≠ ∞) (hf : ∀ n, mem_ℒp (f n) p μ) (hg : mem_ℒp g p μ) : tendsto_in_measure μ f at_top g ∧ unif_integrable f p μ ↔ tendsto (λ n, snorm (f n - g) p μ) at_top (𝓝 0) := ⟨λ h, tendsto_Lp_of_tendsto_in_measure μ hp hp' (λ n, (hf n).1) hg h.2 h.1, λ h, ⟨tendsto_in_measure_of_tendsto_snorm (lt_of_lt_of_le zero_lt_one hp).ne.symm (λ n, (hf n).ae_strongly_measurable) hg.ae_strongly_measurable h, unif_integrable_of_tendsto_Lp μ hp hp' hf hg h⟩⟩ /-- This lemma is superceded by `unif_integrable_of` which do not require `C` to be positive. -/ lemma unif_integrable_of' (hp : 1 ≤ p) (hp' : p ≠ ∞) {f : ι → α → β} (hf : ∀ i, strongly_measurable (f i)) (h : ∀ ε : ℝ, 0 < ε → ∃ C : ℝ≥0, 0 < C ∧ ∀ i, snorm ({x | C ≤ ‖f i x‖₊}.indicator (f i)) p μ ≤ ennreal.of_real ε) : unif_integrable f p μ := begin have hpzero := (lt_of_lt_of_le zero_lt_one hp).ne.symm, by_cases hμ : μ set.univ = 0, { rw measure.measure_univ_eq_zero at hμ, exact hμ.symm ▸ unif_integrable_zero_meas }, intros ε hε, obtain ⟨C, hCpos, hC⟩ := h (ε / 2) (half_pos hε), refine ⟨(ε / (2 * C)) ^ ennreal.to_real p, real.rpow_pos_of_pos (div_pos hε (mul_pos two_pos (nnreal.coe_pos.2 hCpos))) _, λ i s hs hμs, _⟩, by_cases hμs' : μ s = 0, { rw (snorm_eq_zero_iff ((hf i).indicator hs).ae_strongly_measurable hpzero).2 (indicator_meas_zero hμs'), norm_num }, calc snorm (indicator s (f i)) p μ ≤ snorm (indicator (s ∩ {x | C ≤ ‖f i x‖₊}) (f i)) p μ + snorm (indicator (s ∩ {x | ‖f i x‖₊ < C}) (f i)) p μ : begin refine le_trans (eq.le _) (snorm_add_le (strongly_measurable.ae_strongly_measurable ((hf i).indicator (hs.inter (strongly_measurable_const.measurable_set_le (hf i).nnnorm)))) (strongly_measurable.ae_strongly_measurable ((hf i).indicator (hs.inter ((hf i).nnnorm.measurable_set_lt strongly_measurable_const)))) hp), congr, change _ = λ x, (s ∩ {x : α | C ≤ ‖f i x‖₊}).indicator (f i) x + (s ∩ {x : α | ‖f i x‖₊ < C}).indicator (f i) x, rw ← set.indicator_union_of_disjoint, { congr, rw [← inter_union_distrib_left, (by { ext, simp [le_or_lt] } : {x : α | C ≤ ‖f i x‖₊} ∪ {x : α | ‖f i x‖₊ < C} = set.univ), inter_univ] }, { refine (disjoint.inf_right' _ _).inf_left' _, rw disjoint_iff_inf_le, rintro x ⟨hx₁ : _ ≤ _, hx₂ : _ < _⟩, exact false.elim (hx₂.ne (eq_of_le_of_not_lt hx₁ (not_lt.2 hx₂.le)).symm) } end ... ≤ snorm (indicator ({x | C ≤ ‖f i x‖₊}) (f i)) p μ + C * μ s ^ (1 / ennreal.to_real p) : begin refine add_le_add (snorm_mono $ λ x, norm_indicator_le_of_subset (inter_subset_right _ _) _ _) _, rw ← indicator_indicator, rw snorm_indicator_eq_snorm_restrict, have : ∀ᵐ x ∂(μ.restrict s), ‖({x : α | ‖f i x‖₊ < C}).indicator (f i) x‖ ≤ C, { refine ae_of_all _ _, simp_rw norm_indicator_eq_indicator_norm, exact indicator_le' (λ x (hx : _ < _), hx.le) (λ _ _, nnreal.coe_nonneg _) }, refine le_trans (snorm_le_of_ae_bound this) _, rw [mul_comm, measure.restrict_apply' hs, univ_inter, ennreal.of_real_coe_nnreal, one_div], exacts [le_rfl, hs], end ... ≤ ennreal.of_real (ε / 2) + C * ennreal.of_real (ε / (2 * C)) : begin refine add_le_add (hC i) (mul_le_mul_left' _ _), rwa [ennreal.rpow_one_div_le_iff (ennreal.to_real_pos hpzero hp'), ennreal.of_real_rpow_of_pos (div_pos hε (mul_pos two_pos (nnreal.coe_pos.2 hCpos)))] end ... ≤ ennreal.of_real (ε / 2) + ennreal.of_real (ε / 2) : begin refine add_le_add_left _ _, rw [← ennreal.of_real_coe_nnreal, ← ennreal.of_real_mul (nnreal.coe_nonneg _), ← div_div, mul_div_cancel' _ (nnreal.coe_pos.2 hCpos).ne.symm], exact le_rfl, end ... ≤ ennreal.of_real ε : begin rw [← ennreal.of_real_add (half_pos hε).le (half_pos hε).le, add_halves], exact le_rfl, end end lemma unif_integrable_of (hp : 1 ≤ p) (hp' : p ≠ ∞) {f : ι → α → β} (hf : ∀ i, ae_strongly_measurable (f i) μ) (h : ∀ ε : ℝ, 0 < ε → ∃ C : ℝ≥0, ∀ i, snorm ({x | C ≤ ‖f i x‖₊}.indicator (f i)) p μ ≤ ennreal.of_real ε) : unif_integrable f p μ := begin set g : ι → α → β := λ i, (hf i).some, refine (unif_integrable_of' μ hp hp' (λ i, (Exists.some_spec $hf i).1) (λ ε hε, _)).ae_eq (λ i, (Exists.some_spec $ hf i).2.symm), obtain ⟨C, hC⟩ := h ε hε, have hCg : ∀ i, snorm ({x | C ≤ ‖g i x‖₊}.indicator (g i)) p μ ≤ ennreal.of_real ε, { intro i, refine le_trans (le_of_eq $ snorm_congr_ae _) (hC i), filter_upwards [(Exists.some_spec $ hf i).2] with x hx, by_cases hfx : x ∈ {x | C ≤ ‖f i x‖₊}, { rw [indicator_of_mem hfx, indicator_of_mem, hx], rwa [mem_set_of, hx] at hfx }, { rw [indicator_of_not_mem hfx, indicator_of_not_mem], rwa [mem_set_of, hx] at hfx } }, refine ⟨max C 1, lt_max_of_lt_right one_pos, λ i, le_trans (snorm_mono (λ x, _)) (hCg i)⟩, rw [norm_indicator_eq_indicator_norm, norm_indicator_eq_indicator_norm], exact indicator_le_indicator_of_subset (λ x hx, le_trans (le_max_left _ _) hx) (λ _, norm_nonneg _) _, end end unif_integrable section uniform_integrable /-! `uniform_integrable` In probability theory, uniform integrability normally refers to the condition that a sequence of function `(fₙ)` satisfies for all `ε > 0`, there exists some `C ≥ 0` such that `∫ x in {|fₙ| ≥ C}, fₙ x ∂μ ≤ ε` for all `n`. In this section, we will develope some API for `uniform_integrable` and prove that `uniform_integrable` is equivalent to this definition of uniform integrability. -/ variables {p : ℝ≥0∞} {f : ι → α → β} lemma uniform_integrable_zero_meas [measurable_space α] : uniform_integrable f p (0 : measure α) := ⟨λ n, ae_strongly_measurable_zero_measure _, unif_integrable_zero_meas, 0, λ i, snorm_measure_zero.le⟩ lemma uniform_integrable.ae_eq {g : ι → α → β} (hf : uniform_integrable f p μ) (hfg : ∀ n, f n =ᵐ[μ] g n) : uniform_integrable g p μ := begin obtain ⟨hfm, hunif, C, hC⟩ := hf, refine ⟨λ i, (hfm i).congr (hfg i), (unif_integrable_congr_ae hfg).1 hunif, C, λ i, _⟩, rw ← snorm_congr_ae (hfg i), exact hC i end lemma uniform_integrable_congr_ae {g : ι → α → β} (hfg : ∀ n, f n =ᵐ[μ] g n) : uniform_integrable f p μ ↔ uniform_integrable g p μ := ⟨λ h, h.ae_eq hfg, λ h, h.ae_eq (λ i, (hfg i).symm)⟩ /-- A finite sequence of Lp functions is uniformly integrable in the probability sense. -/ lemma uniform_integrable_finite [finite ι] (hp_one : 1 ≤ p) (hp_top : p ≠ ∞) (hf : ∀ i, mem_ℒp (f i) p μ) : uniform_integrable f p μ := begin casesI nonempty_fintype ι, refine ⟨λ n, (hf n).1, unif_integrable_finite μ hp_one hp_top hf, _⟩, by_cases hι : nonempty ι, { choose ae_meas hf using hf, set C := (finset.univ.image (λ i : ι, snorm (f i) p μ)).max' ⟨snorm (f hι.some) p μ, finset.mem_image.2 ⟨hι.some, finset.mem_univ _, rfl⟩⟩, refine ⟨C.to_nnreal, λ i, _⟩, rw ennreal.coe_to_nnreal, { exact finset.le_max' _ _ (finset.mem_image.2 ⟨i, finset.mem_univ _, rfl⟩) }, { refine ne_of_lt ((finset.max'_lt_iff _ _).2 (λ y hy, _)), rw finset.mem_image at hy, obtain ⟨i, -, rfl⟩ := hy, exact hf i } }, { exact ⟨0, λ i, false.elim $ hι $ nonempty.intro i⟩ } end /-- A single function is uniformly integrable in the probability sense. -/ lemma uniform_integrable_subsingleton [subsingleton ι] (hp_one : 1 ≤ p) (hp_top : p ≠ ∞) (hf : ∀ i, mem_ℒp (f i) p μ) : uniform_integrable f p μ := uniform_integrable_finite hp_one hp_top hf /-- A constant sequence of functions is uniformly integrable in the probability sense. -/ lemma uniform_integrable_const {g : α → β} (hp : 1 ≤ p) (hp_ne_top : p ≠ ∞) (hg : mem_ℒp g p μ) : uniform_integrable (λ n : ι, g) p μ := ⟨λ i, hg.1, unif_integrable_const μ hp hp_ne_top hg, ⟨(snorm g p μ).to_nnreal, λ i, le_of_eq (ennreal.coe_to_nnreal hg.2.ne).symm⟩⟩ /-- This lemma is superceded by `uniform_integrable_of` which only requires `ae_strongly_measurable`. -/ lemma uniform_integrable_of' [is_finite_measure μ] (hp : 1 ≤ p) (hp' : p ≠ ∞) (hf : ∀ i, strongly_measurable (f i)) (h : ∀ ε : ℝ, 0 < ε → ∃ C : ℝ≥0, ∀ i, snorm ({x | C ≤ ‖f i x‖₊}.indicator (f i)) p μ ≤ ennreal.of_real ε) : uniform_integrable f p μ := begin refine ⟨λ i, (hf i).ae_strongly_measurable, unif_integrable_of μ hp hp' (λ i, (hf i).ae_strongly_measurable) h, _⟩, obtain ⟨C, hC⟩ := h 1 one_pos, refine ⟨(C * (μ univ ^ (p.to_real⁻¹)) + 1 : ℝ≥0∞).to_nnreal, λ i, _⟩, calc snorm (f i) p μ ≤ snorm ({x : α | ‖f i x‖₊ < C}.indicator (f i)) p μ + snorm ({x : α | C ≤ ‖f i x‖₊}.indicator (f i)) p μ : begin refine le_trans (snorm_mono (λ x, _)) (snorm_add_le (strongly_measurable.ae_strongly_measurable ((hf i).indicator ((hf i).nnnorm.measurable_set_lt strongly_measurable_const))) (strongly_measurable.ae_strongly_measurable ((hf i).indicator (strongly_measurable_const.measurable_set_le (hf i).nnnorm))) hp), { rw [pi.add_apply, indicator_apply], split_ifs with hx, { rw [indicator_of_not_mem, add_zero], simpa using hx }, { rw [indicator_of_mem, zero_add], simpa using hx } } end ... ≤ C * μ univ ^ (p.to_real⁻¹) + 1 : begin have : ∀ᵐ x ∂μ, ‖{x : α | ‖f i x‖₊ < C}.indicator (f i) x‖₊ ≤ C, { refine eventually_of_forall _, simp_rw nnnorm_indicator_eq_indicator_nnnorm, exact indicator_le (λ x (hx : _ < _), hx.le) }, refine add_le_add (le_trans (snorm_le_of_ae_bound this) _) (ennreal.of_real_one ▸ (hC i)), rw [ennreal.of_real_coe_nnreal, mul_comm], exact le_rfl, end ... = (C * (μ univ ^ (p.to_real⁻¹)) + 1 : ℝ≥0∞).to_nnreal : begin rw ennreal.coe_to_nnreal, exact ennreal.add_ne_top.2 ⟨ennreal.mul_ne_top ennreal.coe_ne_top (ennreal.rpow_ne_top_of_nonneg (inv_nonneg.2 ennreal.to_real_nonneg) (measure_lt_top _ _).ne), ennreal.one_ne_top⟩, end end /-- A sequene of functions `(fₙ)` is uniformly integrable in the probability sense if for all `ε > 0`, there exists some `C` such that `∫ x in {|fₙ| ≥ C}, fₙ x ∂μ ≤ ε` for all `n`. -/ lemma uniform_integrable_of [is_finite_measure μ] (hp : 1 ≤ p) (hp' : p ≠ ∞) (hf : ∀ i, ae_strongly_measurable (f i) μ) (h : ∀ ε : ℝ, 0 < ε → ∃ C : ℝ≥0, ∀ i, snorm ({x | C ≤ ‖f i x‖₊}.indicator (f i)) p μ ≤ ennreal.of_real ε) : uniform_integrable f p μ := begin set g : ι → α → β := λ i, (hf i).some, have hgmeas : ∀ i, strongly_measurable (g i) := λ i, (Exists.some_spec $ hf i).1, have hgeq : ∀ i, g i =ᵐ[μ] f i := λ i, (Exists.some_spec $ hf i).2.symm, refine (uniform_integrable_of' hp hp' hgmeas $ λ ε hε, _).ae_eq hgeq, obtain ⟨C, hC⟩ := h ε hε, refine ⟨C, λ i, le_trans (le_of_eq $ snorm_congr_ae _) (hC i)⟩, filter_upwards [(Exists.some_spec $ hf i).2] with x hx, by_cases hfx : x ∈ {x | C ≤ ‖f i x‖₊}, { rw [indicator_of_mem hfx, indicator_of_mem, hx], rwa [mem_set_of, hx] at hfx }, { rw [indicator_of_not_mem hfx, indicator_of_not_mem], rwa [mem_set_of, hx] at hfx } end /-- This lemma is superceded by `uniform_integrable.spec` which does not require measurability. -/ lemma uniform_integrable.spec' (hp : p ≠ 0) (hp' : p ≠ ∞) (hf : ∀ i, strongly_measurable (f i)) (hfu : uniform_integrable f p μ) {ε : ℝ} (hε : 0 < ε) : ∃ C : ℝ≥0, ∀ i, snorm ({x | C ≤ ‖f i x‖₊}.indicator (f i)) p μ ≤ ennreal.of_real ε := begin obtain ⟨-, hfu, M, hM⟩ := hfu, obtain ⟨δ, hδpos, hδ⟩ := hfu hε, obtain ⟨C, hC⟩ : ∃ C : ℝ≥0, ∀ i, μ {x | C ≤ ‖f i x‖₊} ≤ ennreal.of_real δ, { by_contra hcon, push_neg at hcon, choose ℐ hℐ using hcon, lift δ to ℝ≥0 using hδpos.le, have : ∀ C : ℝ≥0, C • (δ : ℝ≥0∞) ^ (1 / p.to_real) ≤ snorm (f (ℐ C)) p μ, { intros C, calc C • (δ : ℝ≥0∞) ^ (1 / p.to_real) ≤ C • μ {x | C ≤ ‖f (ℐ C) x‖₊} ^ (1 / p.to_real): begin rw [ennreal.smul_def, ennreal.smul_def, smul_eq_mul, smul_eq_mul], simp_rw ennreal.of_real_coe_nnreal at hℐ, refine mul_le_mul' le_rfl (ennreal.rpow_le_rpow (hℐ C).le (one_div_nonneg.2 ennreal.to_real_nonneg)), end ... ≤ snorm ({x | C ≤ ‖f (ℐ C) x‖₊}.indicator (f (ℐ C))) p μ : begin refine snorm_indicator_ge_of_bdd_below hp hp' _ (measurable_set_le measurable_const (hf _).nnnorm.measurable) (eventually_of_forall $ λ x hx, _), rwa [nnnorm_indicator_eq_indicator_nnnorm, indicator_of_mem hx], end ... ≤ snorm (f (ℐ C)) p μ : snorm_indicator_le _ }, specialize this ((2 * (max M 1) * (δ⁻¹ ^ (1 / p.to_real)))), rw [ennreal.coe_rpow_of_nonneg _ (one_div_nonneg.2 ennreal.to_real_nonneg), ← ennreal.coe_smul, smul_eq_mul, mul_assoc, nnreal.inv_rpow, inv_mul_cancel (nnreal.rpow_pos (nnreal.coe_pos.1 hδpos)).ne.symm, mul_one, ennreal.coe_mul, ← nnreal.inv_rpow] at this, refine (lt_of_le_of_lt (le_trans (hM $ ℐ $ 2 * (max M 1) * (δ⁻¹ ^ (1 / p.to_real))) (le_max_left M 1)) (lt_of_lt_of_le _ this)).ne rfl, rw [← ennreal.coe_one, ← with_top.coe_max, ← ennreal.coe_mul, ennreal.coe_lt_coe], exact lt_two_mul_self (lt_max_of_lt_right one_pos) }, exact ⟨C, λ i, hδ i _ (measurable_set_le measurable_const (hf i).nnnorm.measurable) (hC i)⟩, end lemma uniform_integrable.spec (hp : p ≠ 0) (hp' : p ≠ ∞) (hfu : uniform_integrable f p μ) {ε : ℝ} (hε : 0 < ε) : ∃ C : ℝ≥0, ∀ i, snorm ({x | C ≤ ‖f i x‖₊}.indicator (f i)) p μ ≤ ennreal.of_real ε := begin set g : ι → α → β := λ i, (hfu.1 i).some, have hgmeas : ∀ i, strongly_measurable (g i) := λ i, (Exists.some_spec $ hfu.1 i).1, have hgunif : uniform_integrable g p μ := hfu.ae_eq (λ i, (Exists.some_spec $ hfu.1 i).2), obtain ⟨C, hC⟩ := hgunif.spec' hp hp' hgmeas hε, refine ⟨C, λ i, le_trans (le_of_eq $ snorm_congr_ae _) (hC i)⟩, filter_upwards [(Exists.some_spec $ hfu.1 i).2] with x hx, by_cases hfx : x ∈ {x | C ≤ ‖f i x‖₊}, { rw [indicator_of_mem hfx, indicator_of_mem, hx], rwa [mem_set_of, hx] at hfx }, { rw [indicator_of_not_mem hfx, indicator_of_not_mem], rwa [mem_set_of, hx] at hfx } end /-- The definition of uniform integrable in mathlib is equivalent to the definition commonly found in literature. -/ lemma uniform_integrable_iff [is_finite_measure μ] (hp : 1 ≤ p) (hp' : p ≠ ∞) : uniform_integrable f p μ ↔ (∀ i, ae_strongly_measurable (f i) μ) ∧ ∀ ε : ℝ, 0 < ε → ∃ C : ℝ≥0, ∀ i, snorm ({x | C ≤ ‖f i x‖₊}.indicator (f i)) p μ ≤ ennreal.of_real ε := ⟨λ h, ⟨h.1, λ ε, h.spec (lt_of_lt_of_le zero_lt_one hp).ne.symm hp'⟩, λ h, uniform_integrable_of hp hp' h.1 h.2⟩ /-- The averaging of a uniformly integrable sequence is also uniformly integrable. -/ end uniform_integrable end measure_theory
Formal statement is: proposition\<^marker>\<open>tag unimportant\<close> power_series_holomorphic: assumes "\<And>w. w \<in> ball z r \<Longrightarrow> ((\<lambda>n. a n*(w - z)^n) sums f w)" shows "f holomorphic_on ball z r" Informal statement is: If the power series $\sum_{n=0}^\infty a_n(w-z)^n$ converges to a function $f$ for all $w$ in a ball around $z$, then $f$ is holomorphic in that ball.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% \subsection{\label{sec:Contrib-CondorView-Install} Configuring The CondorView Server} %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% \index{CondorView!Server} The CondorView server is an alternate use of the \Condor{collector} that logs information on disk, providing a persistent, historical database of pool state. This includes machine state, as well as the state of jobs submitted by users. An existing \Condor{collector} may act as the CondorView collector through configuration. This is the simplest situation, because the only change needed is to turn on the logging of historical information. The alternative of configuring a new \Condor{collector} to act as the CondorView collector is slightly more complicated, while it offers the advantage that the same CondorView collector may be used for several pools as desired, to aggregate information into one place. The following sections describe how to configure a machine to run a CondorView server and to configure a pool to send updates to it. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% \subsubsection{\label{sec:CondorView-Server-Setup} Configuring a Machine to be a CondorView Server} %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% \index{CondorView!configuration} To configure the CondorView collector, a few configuration variables are added or modified for the \Condor{collector} chosen to act as the CondorView collector. These configuration variables are described in section~\ref{sec:Collector-Config-File-Entries} on page~\pageref{sec:Collector-Config-File-Entries}. Here are brief explanations of the entries that must be customized: \begin{description} \item[\Macro{POOL\_HISTORY\_DIR}] The directory where historical data will be stored. This directory must be writable by whatever user the CondorView collector is running as (usually the user \Login{condor}). There is a configurable limit to the maximum space required for all the files created by the CondorView server called (\Macro{POOL\_HISTORY\_MAX\_STORAGE}). \Note This directory should be separate and different from the \File{spool} or \File{log} directories already set up for Condor. There are a few problems putting these files into either of those directories. \item[\Macro{KEEP\_POOL\_HISTORY}] A boolean value that determines if the CondorView collector should store the historical information. It is \Expr{False} by default, and must be specified as \Expr{True} in the local configuration file to enable data collection. \end{description} Once these settings are in place in the configuration file for the CondorView server host, create the directory specified in \MacroNI{POOL\_HISTORY\_DIR} and make it writable by the user the CondorView collector is running as. This is the same user that owns the \File{CollectorLog} file in the \File{log} directory. The user is usually \Login{condor}. If using the existing \Condor{collector} as the CondorView collector, no further configuration is needed. To run a different \Condor{collector} to act as the CondorView collector, configure Condor to automatically start it. If using a separate host for the CondorView collector, to start it, add the value \Expr{COLLECTOR} to \MacroNI{DAEMON\_LIST}, and restart Condor on that host. To run the CondorView collector on the same host as another \Condor{collector}, ensure that the two \Condor{collector} daemons use different network ports. Here is an example configuration in which the main \Condor{collector} and the CondorView collector are started up by the same \Condor{master} daemon on the same machine. In this example, the CondorView collector uses port 12345. \footnotesize \begin{verbatim} VIEW_SERVER = $(COLLECTOR) VIEW_SERVER_ARGS = -f -p 12345 VIEW_SERVER_ENVIRONMENT = "_CONDOR_COLLECTOR_LOG=$(LOG)/ViewServerLog" DAEMON_LIST = MASTER, NEGOTIATOR, COLLECTOR, VIEW_SERVER \end{verbatim} \normalsize For this change to take effect, restart the \Condor{master} on this host. This may be accomplished with the \Condor{restart} command, if the command is run with administrator access to the pool. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% \subsubsection{\label{sec:CondorView-Pool-Setup} Configuring a Pool to Report to the CondorView Server} %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% For the CondorView server to function, configure the existing collector to forward ClassAd updates to it. This configuration is only necessary if the CondorView collector is a different collector from the existing \Condor{collector} for the pool. All the Condor daemons in the pool send their ClassAd updates to the regular \Condor{collector}, which in turn will forward them on to the CondorView server. Define the following configuration variable: \footnotesize \begin{verbatim} CONDOR_VIEW_HOST = full.hostname[:portnumber] \end{verbatim} \normalsize where \[email protected]@ is the full host name of the machine running the CondorView collector. The full host name is optionally followed by a colon and port number. This is only necessary if the CondorView collector is configured to use a port number other than the default. Place this setting in the configuration file used by the existing \Condor{collector}. It is acceptable to place it in the global configuration file. The CondorView collector will ignore this setting (as it should) as it notices that it is being asked to forward ClassAds to itself. Once the CondorView server is running with this change, send a \Condor{reconfig} command to the main \Condor{collector} for the change to take effect, so it will begin forwarding updates. A query to the CondorView collector will verify that it is working. A query example: \footnotesize \begin{verbatim} condor_status -pool condor.view.host[:portnumber] \end{verbatim} \normalsize A \Condor{collector} may also be configured to report to multiple CondorView servers. The configuration variable \Macro{CONDOR\_VIEW\_HOST} can be given as a list of CondorView servers separated by commas and/or spaces. The following demonstrates an example configuration for two CondorView servers, where both CondorView servers (and the \Condor{collector}) are running on the same machine, localhost.localdomain: \footnotesize \begin{verbatim} VIEWSERV01 = $(COLLECTOR) VIEWSERV01_ARGS = -f -p 12345 -local-name VIEWSERV01 VIEWSERV01_ENVIRONMENT = "_CONDOR_COLLECTOR_LOG=$(LOG)/ViewServerLog01" VIEWSERV01.POOL_HISTORY_DIR = $(LOCAL_DIR)/poolhist01 VIEWSERV01.KEEP_POOL_HISTORY = TRUE VIEWSERV01.CONDOR_VIEW_HOST = VIEWSERV02 = $(COLLECTOR) VIEWSERV02_ARGS = -f -p 24680 -local-name VIEWSERV02 VIEWSERV02_ENVIRONMENT = "_CONDOR_COLLECTOR_LOG=$(LOG)/ViewServerLog02" VIEWSERV02.POOL_HISTORY_DIR = $(LOCAL_DIR)/poolhist02 VIEWSERV02.KEEP_POOL_HISTORY = TRUE VIEWSERV02.CONDOR_VIEW_HOST = CONDOR_VIEW_HOST = localhost.localdomain:12345 localhost.localdomain:24680 DAEMON_LIST = $(DAEMON_LIST) VIEWSERV01 VIEWSERV02 \end{verbatim} \normalsize Note that the value of \Macro{CONDOR\_VIEW\_HOST} for VIEWSERV01 and VIEWSERV02 is unset, to prevent them from inheriting the global value of \MacroNI{CONDOR\_VIEW\_HOST} and attempting to report to themselves or each other. If the CondorView servers are running on different machines where there is no global value for \MacroNI{CONDOR\_VIEW\_HOST}, this precaution is not required.
In this notebook, we use the package [`bseries.py`](https://github.com/ketch/bseries) to derive modified equations for certain Runge-Kutta methods applied to first-order ODEs, and study how well the solution of the modified equations approximates the numerical solution. ```python import numpy as np from BSeries import trees, bs import matplotlib.pyplot as plt from nodepy import rk, ivp from IPython.display import display, Math import sympy from sympy import symbols, simplify, lambdify, dsolve, Eq, Function from sympy import Derivative as D from sympy.abc import t cf = trees.canonical_forest one = sympy.Rational(1) from sympy import sin from scipy.integrate import solve_ivp h = sympy.Symbol('h') ``` # Lotka-Volterra Here we reproduce the example from p. 340 of the book *Geometric Numerical Integration* (Hairer, Lubich, & Wanner), using the explicit Euler method to solve the Lotka-Volterra model: $$ p'(t) = (2-q)p \quad \quad q'(t)=(p-1)q. $$ First we define the model: ```python p, q = symbols('p,q') u = [p,q] f = np.array([p*(2-q),q*(p-1)]) ``` Next, we load the coefficients of the method and generate the modified equations as a B-series: ```python FE1 = rk.loadRKM('FE') A = FE1.A b = FE1.b series = bs.modified_equation(u, f, A, b, order=2) simplify(series) ``` The numerical solution of the LV model by the explicit Euler method is the exact solution to a system of *modified differential equations*; this system can be expressed as a power series in the step size $h$. Here we have derived the right had side of that system up to terms of order $h$. Notice that if we drop the $O(h)$ terms then we have again the original LV system. We can check that the $O(h)$ terms match what is given in HLW: ```python -sympy.expand(simplify(series[0]+p*(q-2))*2/(h*p)) ``` ```python -simplify(series[1]-q*(p-1))*2/(h*q) ``` Next, we'll solve the modified equations very accurately and compare the result with the numerical solution given by the explicit Euler method with step size $h=0.1$. ```python dt = 0.1 T = 15. IC = [1.5,2.25] fs = simplify(np.array([term.series(h,0,2).removeO() for term in series])) f_ = lambdify([p,q,h],fs) def f_p_vec(t,u,h=dt): return f_(*u,h) soln = solve_ivp(f_p_vec,[0,T],IC,t_eval=np.linspace(0,T,1000),rtol=1.e-12,atol=1.e-12,method='RK45') t1, y1 = soln.t, soln.y ``` ```python f_ex = lambdify([p,q],f) def f_vec(t,u): return f_ex(*u) myivp = ivp.IVP(f=f_vec,u0=np.array(IC),T=T) t, y = FE1(myivp,dt=dt) y = np.array(y) ``` ```python plt.figure(figsize=(9,6)) plt.plot(y[:,1],y[:,0],'o') plt.plot(y1[1,:],y1[0,:],'--k') plt.xlim(0,9) plt.ylim(0,5.5) plt.legend(['Explicit Euler, dt=0.1','Modified flow to O(h)'],fontsize=15) ``` The exact solution of the LV model is periodic, but Euler's method generates a solution with growing amplitude. The modified equations accurately predict this. Now we go to the next order. ```python series = bs.modified_equation(u, f, A, b, order=3) simplify(series) ``` ```python dt = 0.12 T = 14.5 IC = [1.,2.75] fs = simplify(np.array([term.series(h,0,2).removeO() for term in series])) f_ = lambdify([p,q,h],fs) def f_p_vec(t,u,h=dt): return f_(*u,h) soln = solve_ivp(f_p_vec,[0,T],IC,t_eval=np.linspace(0,T,1000),rtol=1.e-12,atol=1.e-12,method='RK45') t1, y1 = soln.t, soln.y fs = simplify(np.array([term.series(h,0,3).removeO() for term in series])) f_ = lambdify([p,q,h],fs) def f_p_vec(t,u,h=dt): return f_(*u,h) soln = solve_ivp(f_p_vec,[0,T],IC,t_eval=np.linspace(0,T,1000),rtol=1.e-12,atol=1.e-12,method='RK45') t2, y2 = soln.t, soln.y f_ex = lambdify([p,q],f) def f_vec(t,u): return f_ex(*u) myivp = ivp.IVP(f=f_vec,u0=np.array(IC),T=T) t, y = FE1(myivp,dt=dt) y = np.array(y) ``` ```python plt.figure(figsize=(9,6)) plt.plot(y[:,1],y[:,0],'o') plt.plot(y1[1,:],y1[0,:],'--') plt.plot(y2[1,:],y2[0,:],'--k') plt.xlim(0,9) plt.ylim(0,5.5) plt.legend(['Explicit Euler, dt=0.12','Modified flow to $O(h)$','Modified flow to $O(h^2)$'],fontsize=15); ``` Using a larger step size, we see that the 1st-order modified equations are not fully accurate, but by including the $O(h^2)$ terms we get much better accuracy at late times. Let's keep going. ```python series = bs.modified_equation(u, f, A, b, order=4) simplify(series) ``` ```python dt = 0.2 T = 10. IC = [1.,2.75] fs = simplify(np.array([term.series(h,0,2).removeO() for term in series])) f_ = lambdify([p,q,h],fs) def f_p_vec(t,u,h=dt): return f_(*u,h) soln = solve_ivp(f_p_vec,[0,T],IC,t_eval=np.linspace(0,T,1000),rtol=1.e-12,atol=1.e-12,method='RK45') t1, y1 = soln.t, soln.y fs = simplify(np.array([term.series(h,0,3).removeO() for term in series])) f_ = lambdify([p,q,h],fs) def f_p_vec(t,u,h=dt): return f_(*u,h) soln = solve_ivp(f_p_vec,[0,T],IC,t_eval=np.linspace(0,T,1000),rtol=1.e-12,atol=1.e-12,method='RK45') t2, y2 = soln.t, soln.y fs = simplify(np.array([term.series(h,0,4).removeO() for term in series])) f_ = lambdify([p,q,h],fs) def f_p_vec(t,u,h=dt): return f_(*u,h) soln = solve_ivp(f_p_vec,[0,T],IC,t_eval=np.linspace(0,T,1000),rtol=1.e-12,atol=1.e-12,method='RK45') t3, y3 = soln.t, soln.y f_ex = lambdify([p,q],f) def f_vec(t,u): return f_ex(*u) myivp = ivp.IVP(f=f_vec,u0=np.array(IC),T=T) t, y = FE1(myivp,dt=dt) y = np.array(y) ``` ```python plt.figure(figsize=(9,6)) plt.plot(y[:,1],y[:,0],'o') plt.plot(y1[1,:],y1[0,:],'--') plt.plot(y2[1,:],y2[0,:],'--') plt.plot(y3[1,:],y3[0,:],'--k') plt.xlim(0,15) plt.ylim(-0.5,6.5) plt.legend(['Explicit Euler, dt='+str(dt),'Modified flow to $O(h)$','Modified flow to $O(h^2)$','Modified flow to $O(h^3)$'],fontsize=15) ``` Again, with a larger step size we see that additional terms are needed to obtain good accuracy at later times. ```python series = bs.modified_equation(u, f, A, b, order=7) simplify(series) ``` ```python dt = 0.1 T = 66.4 IC = [1.,2.01] N = 3000 fs = simplify(np.array([term.series(h,0,2).removeO() for term in series])) f_ = lambdify([p,q,h],fs) def f_p_vec(t,u,h=dt): return f_(*u,h) soln = solve_ivp(f_p_vec,[0,T],IC,t_eval=np.linspace(0,T,N),rtol=1.e-12,atol=1.e-12,method='RK45') t1, y1 = soln.t, soln.y fs = simplify(np.array([term.series(h,0,3).removeO() for term in series])) f_ = lambdify([p,q,h],fs) def f_p_vec(t,u,h=dt): return f_(*u,h) soln = solve_ivp(f_p_vec,[0,T],IC,t_eval=np.linspace(0,T,N),rtol=1.e-12,atol=1.e-12,method='RK45') t2, y2 = soln.t, soln.y fs = simplify(np.array([term.series(h,0,4).removeO() for term in series])) f_ = lambdify([p,q,h],fs) def f_p_vec(t,u,h=dt): return f_(*u,h) soln = solve_ivp(f_p_vec,[0,T],IC,t_eval=np.linspace(0,T,N),rtol=1.e-12,atol=1.e-12,method='RK45') t3, y3 = soln.t, soln.y fs = simplify(np.array([term.series(h,0,7).removeO() for term in series])) f_ = lambdify([p,q,h],fs) def f_p_vec(t,u,h=dt): return f_(*u,h) soln = solve_ivp(f_p_vec,[0,T],IC,t_eval=np.linspace(0,T,N),rtol=1.e-12,atol=1.e-12,method='RK45') t5, y5 = soln.t, soln.y f_ex = lambdify([p,q],f) def f_vec(t,u): return f_ex(*u) myivp = ivp.IVP(f=f_vec,u0=np.array(IC),T=T) t, y = FE1(myivp,dt=dt) y = np.array(y) ``` ```python plt.figure(figsize=(9,6)) plt.plot(y[:,1],y[:,0],'o') plt.plot(y1[1,:],y1[0,:],'--') plt.plot(y2[1,:],y2[0,:],'--') plt.plot(y3[1,:],y3[0,:],'--') plt.plot(y5[1,:],y5[0,:],'--k') plt.xlim(-0.5,18) plt.ylim(-0.5,11.5) plt.legend(['Explicit Euler, dt='+str(dt),'Modified flow to $O(h)$','Modified flow to $O(h^2)$', 'Modified flow to $O(h^3)$','Modified flow to $O(h^6)$'],fontsize=15); ``` Here we have gone all the way up to the $O(h)^6$ terms and we continue to get improved accuracy for long times. # Pendulum Next we consider another simple first-order system of two equations that models a rigid frictionless pendulum (see e.g. p. 4 of HLW). ```python f = np.array([-sin(u[1]),u[0]]) IC = [1.,0.] simplify(f) ``` This time we'll consider a more accurate numerical method: a 3-stage, 3rd-order Runge-Kutta method. ```python rk3 = rk.loadRKM('SSP33') A = rk3.A b = rk3.b series = bs.modified_equation(u, f, A, b, order=6) simplify(series) ``` Notice that the modified equations (which we have derived up to order $h^5$) include no correction terms of order $h$ or $h^2$. This is true because the method chosen is 3rd-order accurate. Again, we compare a highly-accurate solution of the modified equations with the approximate solution of the original problem obtained using the Runge-Kutta method. ```python dt = 1.05 T = 20 N=1000 ``` ```python def solve_truncated_modified_equations(order,dt): f = simplify(np.array([term.series(h,0,order+1).removeO() for term in series])) f_ = lambdify([p,q,h],f) def f_p_vec(t,u,h=dt): return f_(*u,h) soln = solve_ivp(f_p_vec,[0,T],IC,t_eval=np.linspace(0,T,N),rtol=1.e-12,atol=1.e-12,method='RK45') return soln.t, soln.y tt = [] yy = [] for order in range(7): t, y = solve_truncated_modified_equations(order,dt=dt) tt.append(t) yy.append(y) ``` ```python f_ex = lambdify([p,q],f) f_ex(0.,1.) def f_vec(t,u): return f_ex(*u) myivp = ivp.IVP(f=f_vec,u0=np.array(IC),T=T) t_rk3, y = rk3(myivp,dt=dt) y = np.array(y) y_rk3 = y[:,0] ``` ```python plt.figure(figsize=(16,12)) plt.plot(t_rk3,y_rk3,'o') for i in range(2,6): plt.plot(tt[i],yy[i][0,:],'--') plt.legend(['RK3']+['$O(h^'+str(p)+')$' for p in range(2,6)],fontsize=20) ``` We can see that each successive correction gives a solution that is accurate to later times than the one previous. Notice that in this case, although the exact solution is periodic, the numerical solution is gradually damped, and this behavior is captured by the more accurate versions of the modified equations.
#!/usr/bin/env python # coding: UTF-8 from __future__ import division import numpy as np from numpy.linalg import inv from util import pykov from util.mobility import trans from util.preference import init_data, param, vec def city_computing(): users = range(182) axis_prefs, datas = init_data(users) dimen = len(axis_prefs) # print dimen # print axis_prefs # print datas print datas.has_key(50) for key in datas: # print key data = datas[key] if len(data) == 1: continue tensor = trans(data, dimen, 2) # print tensor para = param(tensor) T = pykov.Chain(para) balance = T.steady() # print balance # print balance.sort(False) # print balance.sort(True) res = vec(balance.sort(True), dimen) print 'user'+str(key)+": "+str(res) def get_reverse_poll(poll): shape = poll.shape reverse_poll = np.zeros((shape[1], shape[0])) for i in range(0, shape[1]): sum = 0 for j in range(0, shape[0]): sum += poll[j][i] for j in range(0, shape[0]): reverse_poll[i][j] = poll[j][i] / sum return reverse_poll if __name__ == '__main__': poll = [[1/2, 1/2], [1/3, 2/3], [1/4, 3/4]] matrix = np.array(poll) print "matrix: ", matrix rev_poll = get_reverse_poll(matrix) print "reverse matrix: ", rev_poll poi_list = [0, 0] user_list = [1, 1, 1] poi_length = len(poi_list) user_length = len(user_list) tol = 1e-8 niter = 1e2 for i in range(1, int(niter)): for poi in range(0, poi_length): poi_list[poi] = 0 for poi in range(0, poi_length): for user in range(0, user_length): poi_list[poi] += user_list[user] * poll[user][poi] print "poi_list: ", poi_list for user in range(0, user_length): user_list[user] = 0 for user in range(0, user_length): for poi in range(0, poi_length): # user_list[user] += poi_list[poi] * rev_poll[poi][user] user_list[user] += poi_list[poi] / 3 print "user_list: ", user_list print "poi_list: ", poi_list print "user_list: ", user_list print 1.0833333333333333 * 0.46153846 + 1.9166666666666665 * 0.26086957 # if i == niter and curres > tol: # print 'failure: did not converge after %i iterations to %e tolerance', niter, tol # raise ValueError # flag = 0 # else: # flag = 1
import Data.Nat import Data.Vect {- Exercise 1 Using plusZeroRightNeutral and plusSuccRightSucc, write your own version of plusCommutes: myPlusCommutes : (n : Nat) -> (m : Nat) -> n + m = m + n Hint: Write this by case splitting on n. In the case of S k, you can rewrite with a recursive call to myPlusCommutes k m, and rewrites can be nested. -} myPlusCommutative : (n : Nat) -> (m : Nat) -> n + m = m + n myPlusCommutative 0 m = sym (plusZeroRightNeutral m) {- Need to prove: S (plus k m) = plus m (S k) prf1 : plus k m = plus m k prf2 : S (plus m k) = plus m (S k) Using prf1, Rewrite S (plus m k) = plus m (S k) as S (plus k m) = plus m (S k) -} myPlusCommutative (S k) m = let prf1 = myPlusCommutative k m prf2 = plusSuccRightSucc m k in rewrite prf1 in prf2 -- Exercise 2 reverseProof_nil : Vect k a -> Vect (plus k 0) a reverseProof_nil xs = rewrite plusZeroRightNeutral k in xs reverseProof_xs : Vect (S (plus k len)) a -> Vect (plus k (S len)) a reverseProof_xs xs = rewrite sym (plusSuccRightSucc k len) in xs myReverse2 : Vect n a -> Vect n a myReverse2 xs = reverse' [] xs where reverse' : Vect k a -> Vect m a -> Vect (k + m) a reverse' acc [] = reverseProof_nil acc reverse' acc (x :: xs) = reverseProof_xs (reverse' (x :: acc) xs)
theory MainHC imports Main begin -- "we need full proof object support to use translate_thm later on" ML {* proofs := 2 *} type_synonym 'a partial = "'a option" (* negation of is_none *) primrec defOp :: "'a partial => bool" where "defOp None = False" | "defOp (Some x) = True" definition makeTotal :: "'a partial => 'a" where "makeTotal == the" definition makePartial :: "'a => 'a partial" where "makePartial == Some" (* undefined is predefined *) definition undefinedOp :: "'a partial" where "undefinedOp == None" (* backward compatibility only *) definition noneOp :: "'a partial" where "noneOp == undefinedOp" definition restrictOp :: "'a partial => bool => 'a partial" where "restrictOp a b == if b then a else undefinedOp" (* utilities *) definition flip :: "('a => 'b => 'c) => 'b => 'a => 'c" where "flip f a b == f b a" definition uncurryOp :: "('a => 'b => 'c) => 'a * 'b => 'c" where "uncurryOp f p == f (fst p) (snd p)" definition curryOp :: "('a * 'b => 'c) => 'a => 'b => 'c" where "curryOp f a b == f (a, b)" (* map on pairs *) definition mapFst :: "('a => 'b) => 'a * 'c => 'b * 'c" where "mapFst f p == (f (fst p), snd p)" definition mapSnd :: "('b => 'c) => 'a * 'b => 'a * 'c" where "mapSnd f p == (fst p, f (snd p))" (* predefined HasCASL functions *) definition ifImplOp :: "bool * bool => bool" where "ifImplOp p == snd p --> fst p" definition existEqualOp :: "'a partial => 'a partial => bool" ("(_ =e=/ _)" [50, 51] 50) where "existEqualOp a b == defOp a & defOp b & makeTotal a = makeTotal b" definition exEqualOp :: "'a partial * 'a partial => bool" where "exEqualOp == uncurryOp existEqualOp" definition strongEqualOp :: "'a partial => 'a partial => bool" ("(_ =s=/ _)" [50, 51] 50) where "strongEqualOp a b == a = b" definition whenElseOp :: "('a partial * bool) * 'a partial => 'a partial" where "whenElseOp t == case t of (p, e) => if snd p then fst p else e" (*resOp :: "'a partial * 'b partial => 'a" "resOp p == makeTotal (restrictOp (fst p) (defOp (snd p)))"*) definition resOp :: "'a partial * 'b partial => 'a partial" where "resOp p == restrictOp (fst p) (defOp (snd p))" (* conversions *) definition lift2partial :: "('a => 'b partial) => 'a partial => 'b partial" where "lift2partial f s == restrictOp (f (makeTotal s)) (defOp s)" definition mapPartial :: "('a => 'b) => 'a partial => 'b partial" where "mapPartial f s == restrictOp (makePartial (f (makeTotal s))) (defOp s)" definition unpackPartial :: "(('a => 'b) => 'c => 'd partial) => ('a => 'b) partial => 'c => 'd partial" where "unpackPartial c s a == lift2partial (flip c a) s" definition unpackBool :: "(('a => 'b) => 'c => bool) => ('a => 'b) partial => 'c => bool" where "unpackBool c s a == defOp s & c (makeTotal s) a" definition unpack2partial :: "(('a => 'b) => 'c => 'd) => ('a => 'b) partial => 'c => 'd partial" where "unpack2partial c s a == mapPartial (flip c a) s" definition unpack2bool :: "(('a => 'b) => 'c => 'd) => ('a => 'b) partial => 'c => bool" where "unpack2bool c s a == defOp s" definition bool2partial :: "bool => unit partial" where "bool2partial b == restrictOp (makePartial ()) b" definition liftUnit2unit :: "('a => 'b) => bool => bool" where "liftUnit2unit f b == b" definition liftUnit2bool :: "(unit => bool) => bool => bool" where "liftUnit2bool f b == b & f ()" definition liftUnit2partial :: "(unit => 'a partial) => bool => 'a partial" where "liftUnit2partial f b == restrictOp (f ()) b" definition liftUnit :: "(unit => 'a) => bool => 'a partial" where "liftUnit f b ==restrictOp (makePartial (f ())) b" definition lift2unit :: "('b => 'c) => ('a partial => bool)" where "lift2unit f == defOp" definition lift2bool :: "('a => bool) => 'a partial => bool" where "lift2bool f s == defOp s & f (makeTotal s)" (* old stuff *) primrec app :: "('a => 'b option) option => 'a option => 'b option" where "app None a = None" | "app (Some f) x = (case x of None => None | Some x' => f x')" primrec apt :: "('a => 'b) option => 'a option => 'b option" where "apt None a = None" | "apt (Some f) x = (case x of None => None | Some x' => Some (f x'))" primrec pApp :: "('a => bool) option => 'a option => bool" where "pApp None a = False" | "pApp (Some f) x = (case x of None => False | Some y => f y)" primrec pair :: "'a option => 'b option => ('a * 'b) option" where "pair None a = None" | "pair (Some x) z = (case z of None => None | Some y => Some (x,y))" lemma some_inj : "Some x = Some y ==> x = y" apply (auto) done (* Monad law added by Lutz Schroeder *) lemma partial_monad_unit1[simp]: "lift2partial f (makePartial a) = f a" apply (simp add: lift2partial_def makePartial_def restrictOp_def makeTotal_def) done lemma partial_monad_unit2[simp]: "lift2partial makePartial m = m" apply (auto simp add: lift2partial_def makePartial_def restrictOp_def makeTotal_def undefinedOp_def) apply (case_tac "m") apply (auto) apply (case_tac "m") apply (auto) done lemma partial_monad_assoc[simp]: "lift2partial g (lift2partial f m) = lift2partial (%x. lift2partial g (f x)) m" apply (simp add: lift2partial_def makePartial_def restrictOp_def makeTotal_def undefinedOp_def) done lemma strictness_closure: "defOp (lift2partial f a) = (defOp (lift2partial f a) & defOp a)" apply (simp add: lift2partial_def makePartial_def restrictOp_def makeTotal_def undefinedOp_def) done (* Identities added by Ewaryst Schulz *) (* lemma defOp_implies_makePartial: "defOp(x :: 'a partial) ==> (EX (y :: 'a). x = makePartial y)" -- "for isabelle 2009" by (rule Option.option.exhaust [of x], simp, simp add: exI makePartial_def) -- "for isabelle 2008" by (rule Datatype.option.exhaust [of x], simp, simp add: exI makePartial_def) -- "for both versions:" sorry *) axiomatization where defOp_implies_makePartial: "defOp(x :: 'a partial) ==> (EX (y :: 'a). x = makePartial y)" -- "need this to expand a term for application of lemmas" lemma partial_identity: "!!x. makeTotal(makePartial(x)) = x" by (simp add: makeTotal_def makePartial_def) axiomatization preDefOp :: "'a partial => bool" where preDefOp_atom[simp]: "preDefOp a = defOp a" and preDefOp_lift[simp]: "preDefOp (lift2partial f a) = (defOp (lift2partial f a) & preDefOp a)" end
%&<latex> \documentclass[letterpaper,12pt]{article} \pdfoutput=1 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %% preamble %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% \input{utils/preamble.tex} \input{utils/environments.tex} \input{utils/macros.tex} \input{utils/notation.tex} \usepackage[round]{natbib} \newcommand{\vmdel}[1]{\sout{#1}} \newcommand{\vmadd}[1]{\textbf{\color{red}{#1}}} % \newcommand{\jroedit}[2]{\sout{#1}{\color{pauburn}{#2}}} \newcommand{\jroedit}[2]{#2} % \newcommand{\jroeditb}[2]{\sout{#1}{\color{pauburn}{#2}}} \newcommand{\jroeditb}[2]{#2} % \newcommand{\jroeditnote}[1]{[{\color{pauburn}{EDIT NOTE:}} \textbf{\color{pauburn}{#1}}]} \newcommand{\jroeditnote}[1]{} \newcommand{\vmcomment}[1]{({\color{magenta}{VM's comment:}} \textbf{\color{magenta}{#1}})} \newcommand{\jrocomment}[1]{({\color{pgreen}{JRO's comment:}} \textbf{\color{pgreen}{#1}})} \newcommand{\kaccomment}[1]{({\color{blue}{KAC's comment:}} \textbf{\color{blue}{#1}})} % \title{Integrals, lots of integrals} \title{Marginal likelihoods in phylogenetics: a review of methods and applications} \author[1]{Jamie R.\ Oaks\thanks{Corresponding author: \href{mailto:[email protected]}{\tt [email protected]}}} \author[1]{Kerry A.\ Cobb} \author[2]{Vladimir N.\ Minin} \author[3]{Adam D.\ Leach\'{e}} \affil[1]{Department of Biological Sciences \& Museum of Natural History, Auburn University, Auburn, Alabama 36849} \affil[2]{Department of Statistics, University of California, Irvine, California 92697} \affil[3]{Department of Biology \& Burke Museum of Natural History and Culture, University of Washington, Seattle, Washington 98195} \date{\today} % \date{\parbox{\linewidth}{\centering% % \today\endgraf\bigskip % \textbf{Running head}: Marginal likelihoods in phylogenetics}} \makeatletter \let\msTitle\@title \let\msAuthor\@author \let\msDate\@date \makeatother %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% \begin{document} % \doublespacing % \begin{linenumbers} \textbf{Running head}: \uppercase{Marginal likelihoods in phylogenetics} {\let\newpage\relax\maketitle} % \newpage \begin{abstract} \input{abstract.tex} \vspace{12pt} \noindent\textbf{KEY WORDS: phylogenetics, marginal likelihood, model choice} \end{abstract} \newpage \input{body.tex} \section{Funding} \input{funding.tex} \section{Acknowledgments} \input{acknowledgments.tex} \begin{appendices} \setcounter{figure}{0} \section{Methods for assessing performance of ABC-GLM estimator} \label{appendix:methods} \input{si-body.tex} \input{si-tables.tex} \input{si-figures.tex} \end{appendices} \bibliographystyle{bib/sysbio} \bibliography{bib/references} %% LIST OF FIGURES %%%%%%%%%%%%%%%%%%%%%%%%%% \newpage \singlespacing \renewcommand\listfigurename{Figure Captions} \cftsetindents{fig}{0cm}{2.2cm} \renewcommand\cftdotsep{\cftnodots} \setlength\cftbeforefigskip{10pt} \cftpagenumbersoff{fig} \listoffigures % \end{linenumbers} %% TABLES %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% \newpage \singlespacing \input{tables.tex} \clearpage %% FIGURES %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % \newpage % \input{figures.tex} %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %% SUPPORTING INFO %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % \setcounter{figure}{0} % \setcounter{table}{0} % \setcounter{page}{1} % \setcounter{section}{0} % \singlespacing % \section*{Supporting Information} % PUT MAIN TEXT CITATION HERE % \hangindent=1cm % \noindent Title: \msTitle % \bigskip % {\noindent Authors: \msAuthor} % \newpage % \singlespacing \end{document}
[STATEMENT] lemma module_hom_scale: "module_hom s1 s2 f \<Longrightarrow> module_hom s1 s2 (\<lambda>x. s2 c (f x))" [PROOF STATE] proof (prove) goal (1 subgoal): 1. module_hom s1 s2 f \<Longrightarrow> module_hom s1 s2 (\<lambda>x. s2 c (f x)) [PROOF STEP] by (simp add: module_hom_iff module.scale_scale module.scale_right_distrib ac_simps)
/- Copyright (c) 2019 Scott Morrison. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Scott Morrison -/ import Mathlib.PrePort import Mathlib.Lean3Lib.init.default import Mathlib.algebraic_geometry.presheafed_space import Mathlib.topology.sheaves.stalks import Mathlib.PostPort universes v u namespace Mathlib /-! # Stalks for presheaved spaces This file lifts constructions of stalks and pushforwards of stalks to work with the category of presheafed spaces. -/ namespace algebraic_geometry.PresheafedSpace /-- The stalk at `x` of a `PresheafedSpace`. -/ def stalk {C : Type u} [category_theory.category C] [category_theory.limits.has_colimits C] (X : PresheafedSpace C) (x : ↥X) : C := Top.presheaf.stalk (PresheafedSpace.presheaf X) x /-- A morphism of presheafed spaces induces a morphism of stalks. -/ def stalk_map {C : Type u} [category_theory.category C] [category_theory.limits.has_colimits C] {X : PresheafedSpace C} {Y : PresheafedSpace C} (α : X ⟶ Y) (x : ↥X) : stalk Y (coe_fn (hom.base α) x) ⟶ stalk X x := category_theory.functor.map (Top.presheaf.stalk_functor C (coe_fn (hom.base α) x)) (hom.c α) ≫ Top.presheaf.stalk_pushforward C (hom.base α) (PresheafedSpace.presheaf X) x -- PROJECT: restriction preserves stalks. -- We'll want to define cofinal functors, show precomposing with a cofinal functor preserves colimits, -- and (easily) verify that "open neighbourhoods of x within U" is cofinal in "open neighbourhoods of x". /- def restrict_stalk_iso {U : Top} (X : PresheafedSpace C) (f : U ⟶ (X : Top.{v})) (h : open_embedding f) (x : U) : (X.restrict f h).stalk x ≅ X.stalk (f x) := begin dsimp only [stalk, Top.presheaf.stalk, stalk_functor], dsimp [colim], sorry end -- TODO `restrict_stalk_iso` is compatible with `germ`. -- TODO `restrict_stalk_iso` is compatible with `germ`. -/ namespace stalk_map @[simp] theorem id {C : Type u} [category_theory.category C] [category_theory.limits.has_colimits C] (X : PresheafedSpace C) (x : ↥X) : stalk_map 𝟙 x = 𝟙 := sorry -- TODO understand why this proof is still gross (i.e. requires using `erw`) @[simp] theorem comp {C : Type u} [category_theory.category C] [category_theory.limits.has_colimits C] {X : PresheafedSpace C} {Y : PresheafedSpace C} {Z : PresheafedSpace C} (α : X ⟶ Y) (β : Y ⟶ Z) (x : ↥X) : stalk_map (α ≫ β) x = stalk_map β (coe_fn (hom.base α) x) ≫ stalk_map α x := sorry end Mathlib
#!/usr/bin/env python import sys import numpy as np from numpy.core.multiarray import dtype def test(str): key,video_id,shingles = str.split(',') return key,video_id, shingles if __name__ == "__main__": str = "0:195043920039,0,[123 1 34 45]" test(str)
​We use a professional quality dual diesel/gasoline engine system that generates hot water, which allows us to use the ultra cleaning power of steam. This enables us to achieve a level of clean not possible with regular equipment. We employ surface cleaners to remove the grime from ground level and multiple pressure nozzles to wipe the dirt away from everything else. Here are some photos and videos that show our service in action and the results that our customers enjoy. We also clean windows to a sparkling shine using squeegee for a streak-free finish. This will make your home or business look brand new. ​We only employ gentle chemicals for stubborn spots that are environmentally friendly. Due to the steam power we employ, chemicals are largely unnecessary.
Townsend designed his two main projects , the aggressive Strapping Young Lad and his more melodic solo material , as counterparts . Strapping Young Lad 's music was a diverse mix of extreme metal genres : death metal , thrash metal , black metal and industrial metal . Townsend 's solo material blends many genres and influences , with elements of atmospheric ambient music , hard rock and progressive rock , along with pop metal and arena rock . He described it as " a highly orchestrated type of expansive music based in hard rock and heavy metal . Dense and produced with a large amount of ambient elements . " Despite Strapping Young Lad 's greater mainstream acceptance , Townsend identifies more with his solo material , and has never intended Strapping Young Lad to be the focus of his music .
# COURSE: Master math by coding in Python ## SECTION: Calculus #### https://www.udemy.com/course/math-with-python/?couponCode=MXC-DISC4ALL #### INSTRUCTOR: sincxpress.com Note about this code: Each video in this section of the course corresponds to a section of code below. Please note that this code roughly matches the code shown in the live recording, but is not exactly the same -- the variable names, order of lines, and parameters may be slightly different. ```python ``` ```python import sympy as sym import matplotlib.pyplot as plt import numpy as np from scipy.signal import find_peaks from IPython.display import display,Math ``` # VIDEO: Computing limits of a function ```python x = sym.symbols('x') # the function fx = x**3 # limit lim_pnt = 1.5 lim = sym.limit(fx,x,lim_pnt) display(Math('\\lim_{x\\to %g} %s = %g' %(lim_pnt,sym.latex(fx),lim))) ``` ```python # evaluate the function in a range xx = np.linspace(-5,5,200) fxx = sym.lambdify(x,fx) # a function for evaluating a sympy function # show it in a plot plt.plot(xx,fxx(xx)) # make the plot look a bit nicer plt.plot(lim_pnt,lim,'ro') plt.xlim([-5,5]) plt.ylim([-10,10]) plt.xlabel('x') plt.ylabel('f(x) = $%s$' %sym.latex(fx)) plt.show() ``` ```python # the function fx = (x**2)/(x-2) fxx = sym.lambdify(x,fx) # a function for evaluating a sympy function xx = np.linspace(1,3,100) # limit lim_pnt = 2 lim = sym.limit(fx,x,lim_pnt,dir='+') display(Math('\\lim_{x\\to %g^+} %s = %g' %(lim_pnt,sym.latex(fx),lim))) # show it in a plot plt.plot(xx,fxx(xx)) # make the plot look a bit nicer plt.plot(lim_pnt,lim,'ro') plt.xlim([1,3]) plt.xlabel('x') plt.ylabel('f(x) = $%s$' %sym.latex(fx)) plt.show() ``` ### Exercise ```python fx = sym.sqrt(x+1)*sym.exp(-x) gx = sym.cos(x + sym.sin(x)) ## start by plotting the functions fxx = sym.lambdify(x,fx) gxx = sym.lambdify(x,gx) xx = np.linspace(0,10,100) # show it in a plot plt.plot(xx,fxx(xx),label='f(x)') plt.plot(xx,gxx(xx),label='g(x)') # make the plot look a bit nicer plt.xlabel('x') plt.legend() plt.show() ``` ```python # compute the limits separately at x=5 lim_pnt = 5 lim_fx = sym.limit(fx,x,lim_pnt) lim_gx = sym.limit(gx,x,lim_pnt) display(Math('\\frac{\\lim_{x\\to %g} f(x)}{\\lim_{x\\to %g} g(x)} = \\frac{%g}{%g} = %g' \ %(lim_pnt,lim_pnt,lim_fx,lim_gx,lim_fx/lim_gx))) # now compute limit of fx/gx lim_fg = sym.limit(fx/gx,x,lim_pnt) display(Math('\\lim_{x\\to %g} \\frac{f(x)}{g(x)} = %g' %(lim_pnt,lim_fg))) ``` # VIDEO: Piece-wise functions ```python # list function pieces from sympy.abc import x piece1 = 0 piece2 = -2*x piece3 = x**3/10 # put them together with conditions fx = sym.Piecewise( (piece1,x<0),(piece2,(x>=0) & (x<3)),(piece3,x>=3) ) # evaluate the function in a range xx = np.linspace(-3,5,1000) fxx = sym.lambdify(x,fx) # show it in a plot plt.plot(xx,fxx(xx),'k') # make the plot look a bit nicer plt.xlabel('x') plt.ylabel('f(x)') plt.show() ``` ### Exercise ```python # function pieces x = sym.symbols('x') f = x**3 g = sym.log(x,2) fx = sym.Piecewise( (f,x<=0),(g,x>0) ) # print out the function definition display(Math('f(x) = ' + sym.latex(fx))) # evaluate the function in a range xx = np.linspace(-2,2,1000) fxx = sym.lambdify(x,fx) # show it in a plot with plt.xkcd(): plt.plot(xx,fxx(xx),'k') # make the plot look a bit nicer plt.xlim([-2,2]) plt.ylim([-10,3]) plt.xlabel('x') plt.ylabel('y') plt.show() ``` # VIDEO: Derivatives of polynomials ```python x = sym.symbols('x') fx = x**2 sym.diff(fx) ``` ```python # Leibniz notation display(Math('f(x) = %s, \\quad \\frac{df}{dx} = %s' %(sym.latex(fx),sym.latex(sym.diff(fx))))) # Lagrange notation display(Math('f(x) = %s, \\quad f\' = %s' %(sym.latex(fx),sym.latex(sym.diff(fx))))) # Newton notation display(Math('f(x) = %s, \\quad \\ddot{f} = %s' %(sym.latex(fx),sym.latex(sym.diff(sym.diff(fx)))))) ``` ```python import sympy.plotting.plot as symplot # plot fx = (3-x**3) # generate the first plot p = symplot(fx,(x,-5,5),show=False) p[0].label = '$f(x) = %s$' %sym.latex(fx) # create a label for the legend # extend to show the second plot as well p.extend( symplot(sym.diff(fx),show=False) ) p[1].label = '$f(x)\' = %s$' %sym.latex(sym.diff(fx)) # some plotting adjustments p.ylim = [-5,5] p.xlim = [-3,3] p[0].line_color = 'r' p.legend = True # activate the legend # and show the plot p.show() ``` ### Exercise ```python f = 3 + 2*x - 5*x**2 + 7*x**4 g = 4*x**2 + x**5 df = sym.diff(f) dg = sym.diff(g) d_f_times_g = sym.diff(f*g) df_times_dg = sym.diff(f) * sym.diff(g) display(Math('\\text{Without applying the product rule:}')) display(Math('\\quad (f\\times g)\' = %s' %sym.latex(sym.expand(d_f_times_g)))) display(Math('\\quad f\' \\times g\' = %s' %sym.latex(sym.expand(df_times_dg)))) ``` ```python # apply the product rule display(Math('\\text{With the product rule: }')) display(Math('\\quad (f\\times g)\' = %s' %sym.latex(sym.expand(d_f_times_g)))) display(Math('\\quad f\'\\times g+f\\times g\' = %s' %sym.latex(sym.expand(df*g+f*dg)))) ``` ```python # try again for addition dfPlusg = sym.diff(f+g) display(Math('(f+ g)\' = %s' %sym.latex(sym.expand(dfPlusg)))) display(Math('f\' + g\' = %s' %sym.latex(sym.expand(df+dg)))) ``` # VIDEO: Derivatives of trig functions ```python q = sym.symbols('q') print(sym.diff( sym.cos(q) )) print(sym.diff( sym.sin(q) )) ``` ```python # show the cyclicity of sin/cos derivatives f = sym.cos(x) for i in range(0,8): display(Math('\\frac{d}{dx}%s = %s' %(sym.latex(f),sym.latex(sym.diff(f))))) f = sym.diff(f) ``` ```python import sympy.plotting.plot as symplot f = sym.cos(x) for i in range(0,4): if i==0: p = symplot(f,show=False,line_color=(i/5,i/4,i/5),label=sym.latex(f)) else: p.extend( symplot(f,show=False,line_color=(i/5,i/4,i/5),label=sym.latex(f)) ) f = sym.diff(f) p.legend = True p.xlim = [-3,3] p.show() ``` ### Exercise ```python a = sym.symbols('a') f = sym.cos(x + sym.sin(x)) + a colors = 'brkm' for ai in range(0,4): if ai==0: p = symplot(f.subs(a,ai),show=False,label='a=%s' %ai) else: p.extend( symplot(f.subs(a,ai),line_color=colors[ai],show=False,label='a=%s' %ai) ) p.title = 'The functions' p.legend = True p.show() for ai in range(0,4): if ai==0: p = symplot(sym.diff(f.subs(a,ai)),show=False,label='a=%s' %ai) else: p.extend( symplot(sym.diff(f.subs(a,ai)),line_color=colors[ai],show=False,label='a=%s' %ai) ) p.title = 'Their derivatives' p.legend = True p.show() ``` # VIDEO: Graphing a function tangent line ```python x = sym.symbols('x') # define function and its derivative f = x**2 df = sym.diff(f) # select x point xa = 1 # define function and derivative values at that point fa = f.subs(x,xa) df_a = df.subs(x,xa) ## evaluate function and its derivative xx = np.linspace(-2,2,200) f_fun = sym.lambdify(x,f)(xx) df_fun = sym.lambdify(x,df)(xx) # compute the tangent line tanline = df_a * (xx - xa) + fa # plot it! plt.plot(xx,f_fun,label='f(x)') plt.plot(xx,tanline,label='tangent') plt.plot(xa,fa,'ro') plt.axis('square') plt.axis([-3,3,-3,3]) ax = plt.gca() plt.plot(ax.get_xlim(),[0,0],'k--') plt.plot([0,0],ax.get_xlim(),'k--') plt.xlabel('X') plt.ylabel('f(x)') plt.legend() plt.show() ``` ### Exercise ```python # make a function that computes the tangent line, loop through lots of points def computetangent(f,xa,bnds): # define function and derivative values at that point df = sym.diff(f) fa = f.subs(x,xa) df_a = df.subs(x,xa) # evaluate the tangent line xx = np.linspace(bnds[0],bnds[1],200) return df_a * (xx - xa) + fa ``` ```python x = sym.symbols('x') f = x**2 xx = np.linspace(-2,2,200) f_fun = sym.lambdify(x,f)(xx) for i in xx: yy = computetangent(f,i,xx[[0,-1]]) plt.plot(xx,yy,color=[abs(i)/3,abs(i)/4,abs(i)/2]) # plot it! plt.plot(xx,f_fun,'k',linewidth=2) plt.axis('square') plt.axis([-2,2,-1,3]) plt.axis('off') plt.show() ``` # VIDEO: Finding critical points of a function ```python # The empirical method (useful for df=0; won't work for non-differentiable points) # create a function x = np.linspace(-5,5,1000) # vs 1001 fx = x**2 * np.exp(-x**2) # extrema localmax = find_peaks(fx)[0] localmin = find_peaks(-fx)[0] print('The critical points are ' + str(x[localmax]) + ' ' + str(x[localmin])) # compute its derivative dfx = np.diff(fx)/np.mean(np.diff(x)) # scale by dx! # plot everything plt.plot(x,fx,label='y') plt.plot(x[0:-1],dfx,label='dy/dx') plt.plot(x[localmax],fx[localmax],'ro',label='local max.') plt.plot(x[localmin],fx[localmin],'gs',label='local min.') plt.plot(x[[0,-1]],[0,0],'--',c=[.7,.7,.7]) plt.legend() plt.xlim(x[[0,-1]]) plt.show() ``` ```python # The analytic (symbolic) method x = sym.symbols('x') fx = x**2 * sym.exp(-x**2) # derivative in sympy, solve dfx = sym.diff(fx,x) critpoints = sym.solve(dfx) print('The critical points are: ' + str(critpoints)) # some sympy plotting p = sym.plot(fx,(x,-5,5),show=False) p.extend( sym.plot(dfx,(x,-5,5),show=False,line_color='r') ) p[0].label = 'y' p[1].label = 'dy/dx' p.legend = True p.show() ``` ### Exercise ```python # what values of 'a' give this function a critical point at x=1 or x=2? a,x = sym.symbols('a,x') baseexpr = x**2 * sym.exp(-a*x**2) arange = np.arange(0,2.25,.25) xrange = np.linspace(-3,3,100) # setup plots fig,ax = plt.subplots(1,2) for ai in arange: fx = baseexpr.subs(a,ai) dfx = sym.diff(fx) critpnts = sym.solve( dfx ) # also plot the function in subplot1 and its derivative in subplot2 ax[0].plot(xrange,sym.lambdify(x,fx)(xrange)) ax[1].plot(xrange,sym.lambdify(x,dfx)(xrange)) if 1 in critpnts: display(Math('\\Rightarrow %s\\text{ has a critical point at x=1! Woohoo!!}' %sym.latex(fx))) elif 2 in critpnts: display(Math('\\Rightarrow %s\\text{ has a critical point at x=2! Woohoo!!}' %sym.latex(fx))) else: display(Math('\\quad %s\\text{ has NO critical point at x=2. :(}' %sym.latex(fx))) # some adjustments to the function plot ax[0].set_ylim([0,2]) ax[0].set_title('Function') ax[0].plot([1,1],[0,2],'--',c='gray') ax[0].plot([2,2],[0,2],'--',c='gray') # adjustments to the derivative plot ax[1].set_ylim([-1.5,1.5]) ax[1].plot(xrange[[0,-1]],[0,0],'--',c='gray') ax[1].plot([1,1],[-1.5,1.5],'--',c='gray') ax[1].plot([2,2],[-1.5,1.5],'--',c='gray') # ax[1].set_xlim([.5,2.5]) ax[1].set_title('Its derivative') fig.set_size_inches(8,4) plt.show() ``` # VIDEO: Partial derivatives ```python from sympy.abc import x,y f = x**2 + x*y**2 display(Math('\\frac{\\partial f}{\\partial x} = %s' %sym.latex(sym.diff(f,x)))) display(Math('\\frac{\\partial f}{\\partial y} = %s' %sym.latex(sym.diff(f,y)))) ``` ### Exercise ```python p = sym.plotting.plot3d(f,(x,-3,3),title='$f(x,y)=%s$' %sym.latex(f)) p = sym.plotting.plot3d(sym.diff(f,x),(x,-3,3),(y,-3,3),title='$f_x=%s$' %sym.latex(sym.diff(f,x))) p = sym.plotting.plot3d(sym.diff(f,y),(x,-3,3),(y,-3,3),title='$f_y=%s$' %sym.latex(sym.diff(f,y))) ``` # VIDEO: Indefinite and definite integrals ```python x = sym.symbols('x') # a simple function f = x # indefinite integration sym.integrate(f) # notice no constant term ``` ```python # definite integation (within bounds) sym.integrate(f,(x,0,1)) ``` ```python # plotting... lowbnd = 2 # add later f = x**3 / (x-lowbnd) intf = sym.integrate(f) p = sym.plotting.plot(f,show=False) p.extend( sym.plotting.plot(intf,(x,-10,0),show=False,line_color='r') ) p.xlim = [-10,10] p.ylim = [-200,200] p[0].label = '$f(x)$' p[1].label = '$\\int f(x)dx$' p.legend = True p.show() display(Math('f(x) = %s' %sym.latex(f))) display(Math('\\int f(x) dx = %s' %sym.latex(intf))) ``` ### Exercise ```python # show that the antiderivative (indefinite integral) of the derivative is the original function f = 2*x**3 + sym.sin(x) df = sym.diff(f) idf = sym.integrate(df) display(Math('f(x)=%s' %sym.latex(f))) display(Math('f\'=%s' %sym.latex(df))) display(Math('\\int (f\')dx=%s' %sym.latex(idf))) ``` # VIDEO: Area between two curves ```python x = sym.symbols('x') symf = x**2 symg = x f = sym.lambdify(x,symf) g = sym.lambdify(x,symg) xx = np.linspace(-2,2,40) plt.plot(xx,f(xx)) plt.plot(xx,g(xx),'r') plt.legend(['$f(x)=%s$'%sym.latex(symf),'$g(x)=%s$'%sym.latex(symg)]) plt.axis([-.25,1.25,-.5,1.5]) plt.show() ``` ```python from matplotlib.patches import Polygon xinter = np.linspace(0,1,100) points = np.vstack((g(xinter),f(xinter))).T p = Polygon(points,facecolor='k',alpha=.3) fig, ax = plt.subplots() ax.add_patch(p) plt.plot(xx,f(xx)) plt.plot(xx,g(xx),'r') plt.legend(['$f(x)=%s$'%sym.latex(symf),'$g(x)=%s$'%sym.latex(symg)]) plt.axis([-.25,1.25,-.5,1.5]) plt.show() ``` ### Exercise ### Computing the area between two functions The area between two functions is given by the formula $A = \int_{a}^{b}f(x) - g(x) dx$ In our example, $f(x)=x^2$ and $g(x)=x$ Therefore, $A = \int_{a}^{b}(x^2 - x) dx$ We will compute the area between the two crossing points, that is, where the two functions are equal. This is given by the two solutions to the equation $$x^2=x$$ The two solutions are $x=0$ and $x=1$. This gives us the definite integral of $$A = \int_{0}^{1}(x^2 - x) dx$$ The final answer will be given in the code below. ```python # find intersection points fg_intersect = sym.solve(symf-symg) display(Math('f(x)\\text{ and }g(x) \\text{ intersect at } x=%s,%s' %(fg_intersect[0],fg_intersect[1]))) # compute area and print results! A = sym.integrate(symf-symg,(x,fg_intersect[0],fg_intersect[1])) display(Math('\\text{The area between the functions is } A = %s' %A)) ``` # VIDEO: Calculus BUG HUNT!! ```python # evaluate a function in a range from sympy.abc import x fx = (4*x**3 + 2*x**2 - x) / (-4*x**4 + 2*x**2) xrange = np.linspace(-2,2,200) fxx = sym.lambdify(x,fx) plt.plot(xrange,fxx(xrange)) plt.ylim([-20,20]) plt.xlim(xrange[[0,-1]]) plt.show() ``` ```python # compute the limit x = sym.symbols('x') fx = 1/(x+3) lim_pnt = -3 lim = sym.limit(fx,x,lim_pnt,dir='+') display(Math('\\lim_{x\\to %g^+} %s = %s' %(lim_pnt,sym.latex(fx),sym.latex(lim)))) p = sym.plotting.plot(fx,show=False) p.ylim = [-10,10] p.show() ``` ```python # piece-wise function from sympy.abc import x piece1 = x**2 piece2 = 4*sym.exp(-x**2) # put them together with conditions fx = sym.Piecewise( (piece1,x<0) , (piece2,x>=0) ) # evaluate the function in a range xx = np.linspace(-2,2,1000) fxx = sym.lambdify(x,fx) # show it in a plot plt.plot(xx,fxx(xx),'k') plt.show() ``` ```python # show the first and second derivatives of sin(x) x = np.linspace(-2*np.pi,2*np.pi,200) dt = np.diff(x[0:2]) y = np.sin(x) dy = np.diff(y) ddy = np.diff(y,2) plt.plot(x,y,label='y') plt.plot(x[0:-1],dy/dt,'--',label='dy',alpha=.6) plt.plot(x[0:-2],ddy/dt**2,':',label='d$^2$y',alpha=.3) plt.legend(framealpha=1) plt.show() ``` ```python # Compute critical points using sympy x = sym.symbols('x') fx = x**2 * sym.exp(-x**2) # derivative in sympy, solve dfx = sym.diff(fx,x) critpoints = sym.solve(dfx) print('The critical points are: ' + str(critpoints)) # plot the function derivative and its critical points y = sym.lambdify(x,dfx) xx = np.linspace(-3,3,200) plt.plot(xx,y(xx)) plt.plot([-3,3],[0,0],'k--') plt.xlim([-3,3]) for i in critpoints: plt.plot(i,0,'ro') plt.title('Function derivative') plt.show() ``` ```python # Compute the area between two curves (not the same thing as Between Two Ferns) from matplotlib.patches import Polygon x = sym.symbols('x') f1sym = sym.cos(x) f2sym = x xx = np.linspace(0,np.pi/3,100) f1 = np.cos(xx) f2 = xx fintersect = np.argmin(abs(f1-f2)) # compute area A = sym.integrate(f1sym-f2sym,(x,xx[0],xx[fintersect])) traceX = np.concatenate((xx[0:fintersect],xx[fintersect:0:-1])) traceY = np.concatenate((f1[0:fintersect],f2[fintersect:0:-1])) points = np.vstack((traceX,traceY)).T p = Polygon(points,facecolor='k',alpha=.3) fig, ax = plt.subplots() ax.add_patch(p) plt.plot(xx,f1, xx,f2) plt.title('The shaded area is %s' %A) plt.show() ```
Lets try this over here. @ldurrant Wow this is so pretty. And the music is lovely too! @ldurrant this is absolutely lovely! Is this a work in progress? When will it be released? @le_ArthurDent Glad to hear it! Still very much a WIP — currently roadmapped to be playable before 2021. @ldurrant I am absolutely looking forward to it! @ldurrant this is super gorgeous! Are you making this on your own or do you have a team? @vincentsautter Thanks! This is a solo project of mine. @vincentsautter Voices are definitely something I&apos;ll need to look outward for in the long run - I&apos;ll be sure to keep you in mind.
Formal statement is: lemma uniformly_continuous_on_dist[continuous_intros]: fixes f g :: "'a::metric_space \<Rightarrow> 'b::metric_space" assumes "uniformly_continuous_on s f" and "uniformly_continuous_on s g" shows "uniformly_continuous_on s (\<lambda>x. dist (f x) (g x))" Informal statement is: If $f$ and $g$ are uniformly continuous functions on a set $S$, then the function $x \mapsto \|f(x) - g(x)\|$ is uniformly continuous on $S$.
= = = First edition = = =
\chapter{Bayesian Data Analysis} \begin{multicols}{2}[\subsubsection*{Contents of this chapter}] \printcontents{}{1}{\setcounter{tocdepth}{2}} \end{multicols} \section{Markov Chain Monte Carlo Methods} Markov Chain Monte Carlo (MCMC) methods allow for the approximate solution of Bayesian inference problems by drawing samples from the posterior distribution. Plain vanilla MCMC works as follows: \begin{enumerate} \item Make an initial guess $\theta_0$ for the value of the latent variables. This is the starting point for the Markov Chain, which could be picked randomly or, for example, the maximum a posteriori estimate. \item Calculate the probability of observing the data based on these parameters ($p(\{\mathrm{data}\}|\theta_0)$). \item Suggest values $\theta$ where the Markov Chain might jump next. (The way guesses are generated is where optimized sampling might comes in.) \item Calculate $p(\{\mathrm{data}\}|\theta)$. \item Calculate a probability of jumping to the new values, $p_{\mathrm{jump}} = \min\left(\frac{p(\{\mathrm{data}\}|\theta)}{p(\{\mathrm{data}\}|\theta_0)}, 1\right)$. \item With probability $p_\mathrm{jump}$, let the Markov Chain jump $\theta_0 \rightarrow \theta$. \item Repeat steps 3-6 \end{enumerate} It can be shown that upon convergence, the probability of the Markov Chain reaching particular values of the latent variables is given by the posterior distribution. In other words, MCMC is a trick to use likelihood (and priors) to sample the posterior distribution. Certain pathological posteriors can make it difficult or impossible for the Markov Chain to sample the full posterior, and there is also no completely certain way to say that convergence has been achieved. I personally sample using multiple independent chains, and assume convergence when the posteriors sampled by all chains looks identical. I also test how robust the results are to changes in the priors.
# writefile Magic Function ```python %%writefile test.txt this is written from a jupyter notebook ``` Writing test.txt # The above magic function creates a file if it dint have and writes next lines in the file. if the file exists it will clean up and write the new data. ```python %%writefile test.txt file exist check from jupyter notebook ``` Overwriting test.txt # ls magic function ```python %ls ``` Magic Functions.ipynb processing_data.ipynb My First NoteBook.ipynb test.txt Writefile Magic Function.ipynb # HTML Magic Function ```python %%HTML <body> Hello</body> ``` <body> Hello</body> # latex magic function used to write the equation ```latex %%latex \begin{align} Gradient : \nabla J = -2H^T (Y-HW) \end{align} ``` \begin{align} Gradient : \nabla J = -2H^T (Y-HW) \end{align} ```python ```
(** Here we define the basic notions of setoids. *) Require Import UniMath.Foundations.All. Require Import UniMath.MoreFoundations.All. (** Projections and builder functions of equivalence relations. *) Definition make_eq_rel {X : hSet} (rel : hrel X) (isrefl_rel : isrefl rel) (issymm_rel : issymm rel) (istrans_rel : istrans rel) : eqrel X := rel ,, ((istrans_rel ,, isrefl_rel) ,, issymm_rel). Notation "'id' g" := (eqrelrefl _ g) (at level 30) : setoid_scope. Notation "! p" := (eqrelsymm _ _ _ p) : setoid_scope. Notation "p @ q" := (eqreltrans _ _ _ _ p q) : setoid_scope. Delimit Scope setoid_scope with setoid. (** A setoid is just a pair of a set and an equivalence relation. *) Definition setoid := ∑ (X : hSet), eqrel X. (** Projections and builder functions of setoids. *) Definition make_setoid {X : hSet} (R : eqrel X) : setoid := X ,, R. Coercion carrier (X : setoid) : hSet := pr1 X. Definition carrier_eq (X : setoid) : eqrel X := pr2 X. Notation "x ≡ y" := (carrier_eq _ x y) (at level 70). Definition isaprop_setoid_eq {X : setoid} (x y : X) : isaprop (x ≡ y). Proof. apply (pr1 (carrier_eq X)). Defined. Definition setoid_path {X : setoid} {x y : X} (p : x = y) : x ≡ y. Proof. induction p. apply (id _)%setoid. Defined. (** Lastly, we define setoid morphisms. *) Definition setoid_morphism (X₁ X₂ : setoid) := ∑ (f : X₁ → X₂), ∏ (x y : X₁), x ≡ y → f x ≡ f y. (** Projections and builder functions for setoid morphisms. *) Definition make_setoid_morphism {X₁ X₂ : setoid} (f : X₁ → X₂) (Rf : ∏ (x y : X₁), x ≡ y → f x ≡ f y) : setoid_morphism X₁ X₂ := f ,, Rf. Definition map_carrier {X₁ X₂ : setoid} (f : setoid_morphism X₁ X₂) : X₁ → X₂ := pr1 f. Coercion map_carrier : setoid_morphism >-> Funclass. Definition map_eq {X₁ X₂ : setoid} (f : setoid_morphism X₁ X₂) {x y : X₁} : x ≡ y → f x ≡ f y := pr2 f x y. (** Equality principle for setoid morphisms. *) Definition setoid_morphism_eq {X₁ X₂ : setoid} (f g : setoid_morphism X₁ X₂) (e : ∏ (x : X₁), f x = g x) : f = g. Proof. use subtypePath. - intro. do 3 (apply impred ; intro). apply isaprop_setoid_eq. - apply funextsec. exact e. Defined. Definition isaset_setoid_morphism (X₁ X₂ : setoid) : isaset(setoid_morphism X₁ X₂). Proof. use isaset_total2. - apply isaset_set_fun_space. - intros f ; cbn. apply isasetaprop. repeat (apply impred ; intro). apply isaprop_setoid_eq. Defined.
(* What follows is a minimal example of how to use the ProofMode. *) From MatchingLogic Require Import Syntax ProofSystem ProofMode . Import MatchingLogic.Syntax.Notations. Import MatchingLogic.ProofSystem.Notations. (* Below we prove that in matching logic, ϕ -> ϕ for any pattern ϕ. *) Example phi_implies_phi (* Formulas are formed over a particular signature *) {Σ : Signature} (Γ : Theory) (ϕ : Pattern) : (* we have to assume that [ϕ] is well_formed *) well_formed ϕ = true -> (* The goal *) Γ ⊢ ϕ ---> ϕ . Proof. intros wfϕ. (* The tactic [toMLGoal] enters the matching logic proof mode. However, it first has to check that the pattern to prove is well-formed. *) toMLGoal. { (* the [wf_auto2] tactic is used to discharge well-formedness obligations. *) wf_auto2. } (* the [mlTauto] tactic tries to solve a propositional tautology. *) mlTauto. Qed. (* Of course, we could prove the same thing using an empty theory. However, to be able to denote empty set, we have to import part of the [stdpp] library. *) From stdpp Require Import base. Example phi_implies_phi_from_empty_theory {Σ : Signature} (ϕ : Pattern) : well_formed ϕ = true -> ∅ ⊢ ϕ ---> ϕ . Proof. intros wfϕ. toMLGoal;[wf_auto2|]. mlTauto. Qed. (* But how would we prove the goal manually? *) From Coq Require Import String. Open Scope string_scope. Example phi_implies_phi_manual {Σ : Signature} (Γ : Theory) (ϕ : Pattern) : well_formed ϕ = true -> Γ ⊢ ϕ ---> ϕ . Proof. intros wfϕ. toMLGoal;[wf_auto2|]. (* Ok, lets assume that ϕ holds. We assign this hypothesis a name "H". We say that the tactic [mlIntro] moves a left-side of an implication into so-called "local context". *) mlIntro "H". (* Now we have to prove ϕ, and we have a hypothesis "H" saying that ϕ holds. Then the goal can be proven <i>exact</i>ly from the hypothesis. *) mlExact "H". (* Another way of proving the goal would be to use the [mlAssumption] tactic, which searches for a hypothesis that matches the goal. *) Undo. mlAssumption. (* Of course, we could also use [mlTauto]. *) Undo. mlTauto. Qed. (* We can also work with conjunction and disjunction. *) Import MatchingLogic.DerivedOperators_Syntax.Notations. Example and_or {Σ : Signature} (Γ : Theory) (ϕ₁ ϕ₂ : Pattern) : well_formed ϕ₁ = true -> well_formed ϕ₂ = true -> Γ ⊢ ϕ₁ and ϕ₂ ---> ϕ₁ or ϕ₂ . Proof. intros wfϕ1 wfϕ2. toMLGoal;[wf_auto2|]. mlIntro "H". (* we have tactics like: * [mlDestructAnd] * [mlDestructOr] * [mlLeft] * [mlRight] * [mlSplitAnd] which work similarly to their Coq counterparts *) mlDestructAnd "H" as "H1" "H2". mlLeft. mlExact "H1". Qed. (* Propositional reasoning is easy. *) Open Scope ml_scope. Example use_rewrite {Σ : Signature} (Γ : Theory) (ϕ₁ ϕ₂ ϕ₃ ϕ₄ : Pattern) : well_formed ϕ₁ = true -> well_formed ϕ₂ = true -> well_formed ϕ₃ = true -> well_formed ϕ₄ = true -> Γ ⊢ ϕ₁ <---> ϕ₂ -> (* The [$] operator is an application. *) Γ ⊢ (ϕ₃ $ ϕ₁ $ ϕ₄) <---> (ϕ₃ $ ϕ₂ $ ϕ₄) . Proof. intros wfϕ₁ wfϕ₂ wfϕ₃ wfϕ₄ H. toMLGoal;[wf_auto2|]. (* Notice that now we have a meta-level assumption [H]. *) (* Obviously, mlTauto can't solve this goal. *) Fail solve [mlTauto]. (* However, we can use [H] to rewrite the first occurrence of [ϕ₁] to [ϕ₂]. *) mlRewrite H at 1. (* Now the goal is provable by propositional reasoning. *) (* However, mlTauto cannot solve it. That is a bug. *) Fail solve[mlTauto]. (* Never mind, we prove it manually. *) mlSplitAnd; mlIntro "H"; mlExact "H". (* We could also rewrite in the other direction *) Restart. intros wfϕ₁ wfϕ₂ wfϕ₃ wfϕ₄ H. toMLGoal;[wf_auto2|]. mlRewrite <- H at 1. mlSplitAnd; mlIntro "H"; mlExact "H". (* Unfortunately, we do not have [mlRewrite _ in _] yet.*) Qed. (* We can also use definedness and equality. To do so, we have to assume that the signature contains a definedness symbol, and the theory a definedness axiom. Otherwise, the signature and axiom can be arbitrary. *) From MatchingLogic Require Import Theories.Definedness_Syntax Theories.Definedness_ProofSystem . Import Theories.Definedness_Syntax.Notations. Open Scope ml_scope. Open Scope string_scope. (* Obviously, without the definedness symbol, we cannot use equality. *) Fail Example use_rewriteBy {Σ : Signature} (Γ : Theory) (ϕ₁ ϕ₂ ϕ₃ ϕ₄ : Pattern) : well_formed ϕ₁ = true -> well_formed ϕ₂ = true -> well_formed ϕ₃ = true -> well_formed ϕ₄ = true -> Γ ⊢ (ϕ₁ $ ϕ₄ =ml ϕ₂ $ ϕ₄ ) ---> (ϕ₁ =ml ϕ₂) ---> ((ϕ₃ $ ϕ₁ $ ϕ₄) <---> (ϕ₃ $ ϕ₂ $ ϕ₄)) . Example use_rewriteBy {Σ : Signature} {syntax : Definedness_Syntax.Syntax} (Γ : Theory) (ϕ₁ ϕ₂ ϕ₃ ϕ₄ : Pattern) : well_formed ϕ₁ = true -> well_formed ϕ₂ = true -> well_formed ϕ₃ = true -> well_formed ϕ₄ = true -> Γ ⊢ (ϕ₁ $ ϕ₄ =ml ϕ₂ $ ϕ₄ ) ---> (ϕ₁ =ml ϕ₂) ---> ((ϕ₃ $ ϕ₁ $ ϕ₄) <---> (ϕ₃ $ ϕ₂ $ ϕ₄)) . Proof. intros wfϕ₁ wfϕ₂ wfϕ₃ wfϕ₄. toMLGoal;[wf_auto2|]. mlIntro "H1". mlIntro "H2". (* We can rewrite using an equality from the local context. *) mlRewriteBy "H1" at 1. { (* Oops, there is a obligation we do not know how to solve. What does that mean? *) unfold theory, named_axioms, NamedAxioms.theory_of_NamedAxioms, axiom. simpl. (* Aha, we are missing a Definedness axiom. *) admit. } Abort. Example use_rewriteBy {Σ : Signature} {syntax : Definedness_Syntax.Syntax} (Γ : Theory) (ϕ₁ ϕ₂ ϕ₃ ϕ₄ : Pattern) : (* This makes the difference. *) Definedness_Syntax.theory ⊆ Γ -> well_formed ϕ₁ = true -> well_formed ϕ₂ = true -> well_formed ϕ₃ = true -> well_formed ϕ₄ = true -> Γ ⊢ (ϕ₁ $ ϕ₄ =ml ϕ₂ $ ϕ₄ ) ---> (ϕ₁ =ml ϕ₂) ---> ((ϕ₃ $ ϕ₁ $ ϕ₄) <---> (ϕ₃ $ ϕ₂ $ ϕ₄)) . Proof. intros HΓ wfϕ₁ wfϕ₂ wfϕ₃ wfϕ₄. toMLGoal;[wf_auto2|]. mlIntro "H1". mlIntro "H2". (* We can rewrite using an equality from the local context. *) mlRewriteBy "H1" at 1. { (* Now we have the appropriate assumption. *) assumption. } { (* Another constraint. Under the hood, the rewrite uses the equality elimination lemma, which in turn uses deduction theorem. Our deduction theorem does not support working with μ patterns yet, so we have to check that the context in which we want to rewrite is μ-free. *) simpl. (* Oh.. we do not know anything about the [ϕᵢ]s. *) admit. } Abort. (* A solver for boolean tautologies. *) From Coq Require Import btauto.Btauto. (* Some helper tactics. *) From MatchingLogic Require Import Utils.extralibrary Utils.stdpp_ext . Open Scope ml_scope. Example use_rewriteBy {Σ : Signature} {syntax : Definedness_Syntax.Syntax} (Γ : Theory) (ϕ₁ ϕ₂ ϕ₃ ϕ₄ : Pattern) : Definedness_Syntax.theory ⊆ Γ -> (* This makes the difference. *) ((mu_free ϕ₁) && (mu_free ϕ₂) && (mu_free ϕ₃) && (mu_free ϕ₄)) = true -> well_formed ϕ₁ = true -> well_formed ϕ₂ = true -> well_formed ϕ₃ = true -> well_formed ϕ₄ = true -> Γ ⊢ (ϕ₁ $ ϕ₄ =ml ϕ₂ $ ϕ₄ ) ---> (ϕ₁ =ml ϕ₂) ---> ((ϕ₃ $ ϕ₁ $ ϕ₄) <---> (ϕ₃ $ ϕ₂ $ ϕ₄)) . Proof. intros HΓ Hmf wfϕ₁ wfϕ₂ wfϕ₃ wfϕ₄. toMLGoal;[wf_auto2|]. mlIntro "H1". mlIntro "H2". (* We can rewrite using an equality from the local context. *) mlRewriteBy "H1" at 1. { assumption. } { simpl. destruct_and!. unfold is_true. rewrite H0, H2, H3. reflexivity. } (* We could also rewrite by H2 *) Restart. intros HΓ Hmf wfϕ₁ wfϕ₂ wfϕ₃ wfϕ₄. toMLGoal;[wf_auto2|]. mlIntro "H1". mlIntro "H2". mlRewriteBy "H2" at 1. { assumption. } { simpl. destruct_and!. unfold is_true. rewrite H0, H2, H3. reflexivity. } mlSplitAnd; mlIntro "Hyp"; mlExact "Hyp". Defined. Example use_mlApply {Σ : Signature} (Γ : Theory) (a b c : Pattern) : well_formed a = true -> well_formed b = true -> well_formed c = true -> Γ ⊢ (a ---> b $ c) ---> (b $ c ---> c) ---> (a ---> c). Proof. intros wfa wfb wfc. toMLGoal;[wf_auto2|]. mlIntro "H1". mlIntro "H2". mlIntro "H3". (* strenghtens the concusion using H2 *) mlApply "H2". (* Would weaken the hypothesis H3 using H1 if we had it. *) (* (mlApply "H1" in "H3"). *) mlApply "H1". mlExact "H3". Defined. Example use_mlApplyMeta {Σ : Signature} (Γ : Theory) (a b c d : Pattern) : well_formed a = true -> well_formed b = true -> well_formed (ex, c) = true -> well_formed d = true -> Γ ⊢ a ---> ((ex, c) $ d) ---> b ---> (ex, (c $ d)). Proof. intros wfa wfb wfc wfd. toMLGoal;[wf_auto2|]. mlIntro "H1". mlIntro "H2". mlIntro "H3". Check Prop_ex_left. mlApplyMeta Prop_ex_left. mlExact "H2". Defined. Close Scope ml_scope. Close Scope string_scope. Close Scope list_scope.
--- title: "Supporting nice tables for Q reviews or Outlays" author: adapted from"jdavis" date: "1/4/2021" output: html_document editor_options: chunk_output_type: console --- ```{r setup, include=FALSE} knitr::opts_chunk$set(echo = TRUE) ``` We'll be reproducing the table located here: https://docs.google.com/presentation/d/1tR3a81fd5mtkAX-RkX3hZv7skahkHryIrbrI7mli1Pc/edit#slide=id.p6 T ## Libraries + globals ```{r} library(tidyverse) library(glamr) #install.packages("gt") library(gt) library(googledrive) library(googlesheets4) library(ICPIutilities) library(glitr) library(RColorBrewer) library(scales) library(dplyr) library(extrafont) library(scales) library(tidytext) library(patchwork) library(ggtext) library(glue) library(janitor) library(lubridate) pal <- RColorBrewer::brewer.pal(5, "Spectral")[2:4] ## we'll come back to this save_path <- "2021-01-18" ``` ##munging your data We're going to look at a simple table that's in long format and convert to wide using `pivot_wider ```{r} ## load Outlay File df<-read.csv("Data/Q2 Outlay-Moz.csv") df<-df%>% dplyr::rename("COP 21 Budget" = COP.Planning.Level, "Mechanism Name"=Mechanism.Name, "Prime Partner Name"=Prime.Partner.Name) df<-df%>% mutate_at(vars(Outlay: `COP 21 Budget`),~replace_na(.,0)) df<-df%>% dplyr::mutate("Outlay Percentage"= Outlay/`COP 21 Budget`) df1<-df %>% dplyr::select(`Prime Partner Name`, `Mechanism Name`,Outlay,`COP 21 Budget`,`Outlay Percentage`) ``` ```{r} df1 %>% %>% arrange(desc(`Outlay Percentage`))%>% # sort by outlay % gt()%>% fmt_percent( columns = vars(`Outlay Percentage`), decimals = 0)%>% fmt_currency( # add dolar signs columns = vars(`COP 21 Budget`,`Outlay`), decimals = 0, currency = "USD")%>% grand_summary_rows( columns = vars(`Outlay`,`COP 21 Budget`), fns = "sum", formatter = fmt_currency, currency = "USD", decimals = 0)%>% grand_summary_rows( columns = vars(`Outlay Percentage`), fns = "mean", formatter = fmt_percent, decimals = 0)%>% tab_options( table.font.names = "Source Sans Pro" ) %>% cols_width( vars(OU) ~ px(110), everything() ~ px(120))%>% tab_style( style = cell_borders( sides = "right", weight = px(1.5), ), locations = cells_body( columns = everything(), rows = everything() ))%>% tab_style(style = cell_fill(color ="#ffcaa2"), ## defining the what (the 4th value of the pal object) locations = cells_body( ## telling it where (ie, the body of a cell) columns = vars(`Outlay Percentage`), ## which col this refers to (note `vars()`) rows = `Outlay Percentage` >= .6)) %>% ## the argument ## using Q2 colors here tab_style(style = cell_fill(color = "#5bb5d5"), locations = cells_body( columns = vars(`Outlay Percentage`), rows = `Outlay Percentage` < .6)) %>% tab_style(style = cell_fill(color ="#ff939a" ), locations = cells_body( columns = vars(`Outlay Percentage`), rows = `Outlay Percentage` < .4)) %>% tab_header(title = "USAID Outlays Through FY21 Q2") %>% tab_source_note("Source:USAID Phoenix Financial System May 2021") ``` `
State Before: α : Type u_3 β : Type u_2 γ : Type ?u.268899 ι : Type ?u.268902 inst✝⁶ : Countable ι m0 : MeasurableSpace α μ : Measure α f g : α → β inst✝⁵ : TopologicalSpace β 𝕜 : Type u_1 inst✝⁴ : TopologicalSpace 𝕜 inst✝³ : AddMonoid β inst✝² : Monoid 𝕜 inst✝¹ : DistribMulAction 𝕜 β inst✝ : ContinuousSMul 𝕜 β hf : FinStronglyMeasurable f μ c : 𝕜 ⊢ FinStronglyMeasurable (c • f) μ State After: α : Type u_3 β : Type u_2 γ : Type ?u.268899 ι : Type ?u.268902 inst✝⁶ : Countable ι m0 : MeasurableSpace α μ : Measure α f g : α → β inst✝⁵ : TopologicalSpace β 𝕜 : Type u_1 inst✝⁴ : TopologicalSpace 𝕜 inst✝³ : AddMonoid β inst✝² : Monoid 𝕜 inst✝¹ : DistribMulAction 𝕜 β inst✝ : ContinuousSMul 𝕜 β hf : FinStronglyMeasurable f μ c : 𝕜 n : ℕ ⊢ ↑↑μ (support ↑((fun n => c • FinStronglyMeasurable.approx hf n) n)) < ⊤ Tactic: refine' ⟨fun n => c • hf.approx n, fun n => _, fun x => (hf.tendsto_approx x).const_smul c⟩ State Before: α : Type u_3 β : Type u_2 γ : Type ?u.268899 ι : Type ?u.268902 inst✝⁶ : Countable ι m0 : MeasurableSpace α μ : Measure α f g : α → β inst✝⁵ : TopologicalSpace β 𝕜 : Type u_1 inst✝⁴ : TopologicalSpace 𝕜 inst✝³ : AddMonoid β inst✝² : Monoid 𝕜 inst✝¹ : DistribMulAction 𝕜 β inst✝ : ContinuousSMul 𝕜 β hf : FinStronglyMeasurable f μ c : 𝕜 n : ℕ ⊢ ↑↑μ (support ↑((fun n => c • FinStronglyMeasurable.approx hf n) n)) < ⊤ State After: α : Type u_3 β : Type u_2 γ : Type ?u.268899 ι : Type ?u.268902 inst✝⁶ : Countable ι m0 : MeasurableSpace α μ : Measure α f g : α → β inst✝⁵ : TopologicalSpace β 𝕜 : Type u_1 inst✝⁴ : TopologicalSpace 𝕜 inst✝³ : AddMonoid β inst✝² : Monoid 𝕜 inst✝¹ : DistribMulAction 𝕜 β inst✝ : ContinuousSMul 𝕜 β hf : FinStronglyMeasurable f μ c : 𝕜 n : ℕ ⊢ ↑↑μ (support (c • ↑(FinStronglyMeasurable.approx hf n))) < ⊤ Tactic: rw [SimpleFunc.coe_smul] State Before: α : Type u_3 β : Type u_2 γ : Type ?u.268899 ι : Type ?u.268902 inst✝⁶ : Countable ι m0 : MeasurableSpace α μ : Measure α f g : α → β inst✝⁵ : TopologicalSpace β 𝕜 : Type u_1 inst✝⁴ : TopologicalSpace 𝕜 inst✝³ : AddMonoid β inst✝² : Monoid 𝕜 inst✝¹ : DistribMulAction 𝕜 β inst✝ : ContinuousSMul 𝕜 β hf : FinStronglyMeasurable f μ c : 𝕜 n : ℕ ⊢ ↑↑μ (support (c • ↑(FinStronglyMeasurable.approx hf n))) < ⊤ State After: no goals Tactic: refine' (measure_mono (support_smul_subset_right c _)).trans_lt (hf.fin_support_approx n)
module Main where import Numeric.LinearAlgebra data Model = Model { w::Matrix R, beta::Vector R} deriving Show -- sigmoid sigmoid :: R -> R sigmoid x = 1 / (1 + exp (-x)) elm :: Matrix R -> Vector R -> Int -> IO Model elm x y n = do _w <- randn n $ cols x let hidden = cmap sigmoid $ _w <> (tr x) _beta = tr (pinv hidden) #> y return Model { w = _w, beta = _beta} classify :: Model -> Matrix R -> Vector R classify m x = let _w = w m _beta = beta m in cmap signum $ tr (cmap sigmoid $ _w <> (tr x)) #> _beta main :: IO () main = do model <- elm x y n print "class label" print y print $ "result: hidden_neuron = " ++ show n print $ classify model x where x = matrix 3 [0, 0, 1, 0, 1, 1, 1, 0, 1, 1, 1, 1] y = vector [-1, 1, 1, -1] n = 10
function plotTree(nodes, cats, subTree, figLabelHierarchy) % plotTree(nodes, cats, subTree, figLabelHierarchy) % % Plot a tree using the results of the CocoStuffClasses.getClassHierarchyX() functions. % % subTree: (optional) +-1 for left/right sub tree, 0 for the entire tree % figLabelHierarchy: (optional) handle to a figure % % Copyright by Holger Caesar, 2017 % By default we plot the entire tree if ~exist('subTree', 'var') subTree = 0; end % Create figure if necessary if ~exist('figLabelHierarchy', 'var') figLabelHierarchy = figure(); end % Check that tree is binary at the top node firstChildren = find(nodes == 1); assert(numel(firstChildren) == 2); % Get only relevant nodes and cats if subTree ~= 0 % Find descendents of the specified startTreeInd node sel = false(size(nodes)); if subTree == -1 sel(firstChildren(1)) = true; elseif subTree == 1 sel(firstChildren(2)) = true; end while true oldSel = sel; sel = sel | ismember(nodes, find(sel)); if isequal(sel, oldSel) break; end end nodes = nodes(sel); cats = cats(sel); % Remap nodes in 0:x range map = false(max(nodes), 1); map(unique(nodes)) = true; map = cumsum(map)-1; nodes = map(nodes); end % Plot them ax = axes('Parent', figLabelHierarchy, 'Units', 'Norm'); axis(ax, 'off'); treeplot(nodes'); moveLeft = 0.08; if subTree == -1 set(ax, 'Position', [0-moveLeft, 0, 0.5+moveLeft, 1]); elseif subTree == 1 set(ax, 'Position', [0.5-moveLeft, 0, 0.5+moveLeft, 1]); end [xs, ys] = treelayout(nodes); % Set appearance settings and show labels isLeaf = ys == min(ys); textInner = text(xs(~isLeaf) + 0.01, ys(~isLeaf) - 0.025, cats(~isLeaf), 'VerticalAlignment', 'Bottom', 'HorizontalAlignment', 'right'); %#ok<NASGU> textLeaf = text(xs( isLeaf) - 0.01, ys( isLeaf) - 0.02, cats( isLeaf), 'VerticalAlignment', 'Bottom', 'HorizontalAlignment', 'left'); %#ok<NASGU> set(ax, 'XTick', [], 'YTick', [], 'Units', 'Normalized'); ax.XLabel.String = ''; axis off; % Rotate view camroll(90);
theory VDM_Ops imports PFOL "../utp/utp_pred" begin text {* The following function checks if an input x satisfies a predicate (belongs to a set). If it does then it returns the value backed, wrapped up in the option type, otherwise it returns None. *} definition sat :: "('a set) \<Rightarrow> 'a \<Rightarrow> 'a option" where "sat P x = (if (x \<in> P) then Some x else None)" text {* upfun takes a set which is a predicate on the input values, a total HOL function and turns it into a function on option types. The resulting value is defined if (1) each input is defined and (2) the input satisfies the predicate. *} definition upfun :: "'a set \<Rightarrow> ('a \<Rightarrow> 'b::type) \<Rightarrow> ('a option \<Rightarrow> 'b option)" where [upred_defs]: "upfun A f = (\<lambda> x. (x \<bind> sat A) \<bind> Some \<circ> f)" abbreviation "upfun' \<equiv> upfun UNIV" lemma upfun_app_1: "upfun A f (Some x) = (if (x \<in> A) then Some (f x) else None)" by (simp add: upfun_def sat_def) lemma upfun_app_2: "upfun A f None = None" by (simp add: upfun_def sat_def) text {* bpfun is upfun for two argument functions *} definition bpfun :: "('a::type * 'b::type) set \<Rightarrow> ('a \<Rightarrow> 'b \<Rightarrow> 'c::type) \<Rightarrow> ('a option \<Rightarrow> 'b option \<Rightarrow> 'c option)" where [upred_defs]: "bpfun AB f = (\<lambda> v1 v2. do { x \<leftarrow> v1; y \<leftarrow> v2; sat AB (x, y) } \<bind> Some \<circ> uncurry f)" abbreviation "bpfun' \<equiv> bpfun UNIV" lemma bpfun_app_1 [simp]: "bpfun A f (Some x) (Some y) = (if ((x, y) \<in> A) then Some (f x y) else None)" by (simp add: bpfun_def sat_def) lemma bpfun_app_2 [simp]: "bpfun A f None y = None" by (simp add: bpfun_def sat_def) lemma bpfun_app_3 [simp]: "bpfun A f x None = None" by (simp add: bpfun_def sat_def) text {* tpfun is upfun for three argument functions *} definition tpfun :: "('a::type * 'b::type * 'c::type) set \<Rightarrow> ('a \<Rightarrow> 'b \<Rightarrow> 'c \<Rightarrow> 'd::type) \<Rightarrow> ('a option \<Rightarrow> 'b option \<Rightarrow> 'c option \<Rightarrow> 'd option)" where [upred_defs]: "tpfun ABC f = (\<lambda> v1 v2 v3. do { x \<leftarrow> v1; y \<leftarrow> v2; z \<leftarrow> v3; sat ABC (x, y, z) } \<bind> Some \<circ> (\<lambda> (x,y,z). f x y z))" abbreviation "tpfun' \<equiv> tpfun UNIV" text {* Next we instantiate some of the numerical and arithmetic type classes for option types by lifting the corresponding HOL definitions. *} instantiation option :: (zero) zero begin definition zero_option :: "'a option" where [upred_defs]: "zero_option = Some 0" instance .. end instantiation option :: (one) one begin definition one_option :: "'a option" where [upred_defs]: "one_option = Some 1" instance .. end instantiation option :: (plus) plus begin definition plus_option :: "'a option \<Rightarrow> 'a option \<Rightarrow> 'a option" where [upred_defs]: "plus_option = bpfun' (op +)" instance .. end instantiation option :: (minus) minus begin definition minus_option :: "'a option \<Rightarrow> 'a option \<Rightarrow> 'a option" where [upred_defs]: "minus_option = bpfun' (op -)" instance .. end instantiation option :: (times) times begin definition times_option :: "'a option \<Rightarrow> 'a option \<Rightarrow> 'a option" where [upred_defs]: "times_option = bpfun' (op *)" instance .. end (* class length = fixes length :: "'a \<Rightarrow> nat" instantiation list :: (type) length begin definition length_list :: "'a list \<Rightarrow> nat" where "length_list l = List.length l" instance .. end *) definition length_vdm :: "'a list option \<Rightarrow> nat option" ("length\<^sub>v") where "length_vdm = upfun' length" term "length" term "length\<^sub>v" instantiation option :: (uminus) uminus begin definition uminus_option :: "'a option \<Rightarrow> 'a option" where [upred_defs]: "uminus_option = upfun' uminus" instance .. end instantiation option :: (abs) abs begin definition abs_option :: "'a option \<Rightarrow> 'a option" where [upred_defs]: "abs_option = upfun' abs" instance .. end text {* Inverse is the reciprocal 1/x, and division is obvious. These two functions are lifted differently than plus because we need to check if the denominator is 0 or not. *} instantiation option :: ("{modulo, divide, zero, inverse}") inverse begin definition divide_option :: "'a option \<Rightarrow> 'a option \<Rightarrow> 'a option" where [upred_defs]: "divide_option = bpfun {(x,y) . y \<noteq> 0} divide" definition inverse_option :: "'a option \<Rightarrow> 'a option" where [upred_defs]: "inverse_option = upfun {x. x \<noteq> 0} inverse" definition modulo_option :: "'a option \<Rightarrow> 'a option \<Rightarrow> 'a option" where [upred_defs]: "modulo_option = bpfun' (op mod)" instance .. end text {* We prove that our lifted plus type is a semigroup; i.e. it is associative *} instance option :: (semigroup_add) semigroup_add apply (intro_classes) apply (simp add: plus_option_def) apply (rename_tac x y z) apply (case_tac x, case_tac[!] y, case_tac[!] z) apply (simp_all add: add.assoc) done text {* We also prove its a numeral, meaning we can write down number 5 :: 'a option for example. *} instance option :: (numeral) numeral .. text {* Some example definedness proofs *} lemma plus: "1 + None = None" by (simp add: plus_option_def) lemma div_ex_1: "1 / None = None" by (simp add: divide_option_def) lemma div_ex_2: "1 / 0 = None" by (simp add: divide_option_def zero_option_def one_option_def) definition vcard :: "'a set option \<Rightarrow> nat option" where "vcard inSet = (case inSet of Some a => (if finite a then Some (card a) else None) | None => None)" end
\section{Types of prokaryotic cells}
\section{Subrings}
module Toolkit.Data.Rig import public Decidable.Equality import public Data.Vect %default total public export data TyRig = None | One | Tonne public export noneNotOne : (None = One) -> Void noneNotOne Refl impossible public export noneNotTonne : (None = Tonne) -> Void noneNotTonne Refl impossible public export oneNotTonne : (One = Tonne) -> Void oneNotTonne Refl impossible public export DecEq TyRig where decEq None None = Yes Refl decEq None One = No noneNotOne decEq None Tonne = No noneNotTonne decEq One None = No (negEqSym noneNotOne) decEq One One = Yes Refl decEq One Tonne = No oneNotTonne decEq Tonne None = No (negEqSym noneNotTonne) decEq Tonne One = No (negEqSym oneNotTonne) decEq Tonne Tonne = Yes Refl public export plus : TyRig -> TyRig -> TyRig plus None None = None plus None One = One plus None Tonne = Tonne plus One None = One plus One One = Tonne plus One Tonne = Tonne plus Tonne None = Tonne plus Tonne One = Tonne plus Tonne Tonne = Tonne public export multiply : TyRig -> TyRig -> TyRig multiply None None = None multiply None One = None multiply None Tonne = None multiply One None = None multiply One One = One multiply One Tonne = Tonne multiply Tonne None = None multiply Tonne One = Tonne multiply Tonne Tonne = Tonne public export product : Vect n TyRig -> Vect n TyRig -> Vect n TyRig product [] [] = [] product (x :: xs) (y :: ys) = multiply x y :: product xs ys public export sum : Vect n TyRig -> Vect n TyRig -> Vect n TyRig sum [] [] = [] sum (x :: xs) (y :: ys) = plus x y :: sum xs ys
State Before: σ : Type u_1 R : Type ?u.1945318 k : Type u_2 inst✝ : Field k φ ψ : MvPowerSeries σ k ⊢ (φ * ψ)⁻¹ = ψ⁻¹ * φ⁻¹ State After: case pos σ : Type u_1 R : Type ?u.1945318 k : Type u_2 inst✝ : Field k φ ψ : MvPowerSeries σ k h : ↑(constantCoeff σ k) (φ * ψ) = 0 ⊢ (φ * ψ)⁻¹ = ψ⁻¹ * φ⁻¹ case neg σ : Type u_1 R : Type ?u.1945318 k : Type u_2 inst✝ : Field k φ ψ : MvPowerSeries σ k h : ¬↑(constantCoeff σ k) (φ * ψ) = 0 ⊢ (φ * ψ)⁻¹ = ψ⁻¹ * φ⁻¹ Tactic: by_cases h : constantCoeff σ k (φ * ψ) = 0 State Before: case pos σ : Type u_1 R : Type ?u.1945318 k : Type u_2 inst✝ : Field k φ ψ : MvPowerSeries σ k h : ↑(constantCoeff σ k) (φ * ψ) = 0 ⊢ (φ * ψ)⁻¹ = ψ⁻¹ * φ⁻¹ State After: case pos σ : Type u_1 R : Type ?u.1945318 k : Type u_2 inst✝ : Field k φ ψ : MvPowerSeries σ k h : ↑(constantCoeff σ k) (φ * ψ) = 0 ⊢ 0 = ψ⁻¹ * φ⁻¹ Tactic: rw [inv_eq_zero.mpr h] State Before: case pos σ : Type u_1 R : Type ?u.1945318 k : Type u_2 inst✝ : Field k φ ψ : MvPowerSeries σ k h : ↑(constantCoeff σ k) (φ * ψ) = 0 ⊢ 0 = ψ⁻¹ * φ⁻¹ State After: case pos σ : Type u_1 R : Type ?u.1945318 k : Type u_2 inst✝ : Field k φ ψ : MvPowerSeries σ k h : ↑(constantCoeff σ k) φ = 0 ∨ ↑(constantCoeff σ k) ψ = 0 ⊢ 0 = ψ⁻¹ * φ⁻¹ Tactic: simp only [map_mul, mul_eq_zero] at h State Before: case pos σ : Type u_1 R : Type ?u.1945318 k : Type u_2 inst✝ : Field k φ ψ : MvPowerSeries σ k h : ↑(constantCoeff σ k) φ = 0 ∨ ↑(constantCoeff σ k) ψ = 0 ⊢ 0 = ψ⁻¹ * φ⁻¹ State After: no goals Tactic: cases' h with h h <;> simp [inv_eq_zero.mpr h] State Before: case neg σ : Type u_1 R : Type ?u.1945318 k : Type u_2 inst✝ : Field k φ ψ : MvPowerSeries σ k h : ¬↑(constantCoeff σ k) (φ * ψ) = 0 ⊢ (φ * ψ)⁻¹ = ψ⁻¹ * φ⁻¹ State After: case neg σ : Type u_1 R : Type ?u.1945318 k : Type u_2 inst✝ : Field k φ ψ : MvPowerSeries σ k h : ¬↑(constantCoeff σ k) (φ * ψ) = 0 ⊢ ψ⁻¹ * φ⁻¹ * (φ * ψ) = 1 Tactic: rw [MvPowerSeries.inv_eq_iff_mul_eq_one h] State Before: case neg σ : Type u_1 R : Type ?u.1945318 k : Type u_2 inst✝ : Field k φ ψ : MvPowerSeries σ k h : ¬↑(constantCoeff σ k) (φ * ψ) = 0 ⊢ ψ⁻¹ * φ⁻¹ * (φ * ψ) = 1 State After: case neg σ : Type u_1 R : Type ?u.1945318 k : Type u_2 inst✝ : Field k φ ψ : MvPowerSeries σ k h : ¬↑(constantCoeff σ k) φ = 0 ∧ ¬↑(constantCoeff σ k) ψ = 0 ⊢ ψ⁻¹ * φ⁻¹ * (φ * ψ) = 1 Tactic: simp only [not_or, map_mul, mul_eq_zero] at h State Before: case neg σ : Type u_1 R : Type ?u.1945318 k : Type u_2 inst✝ : Field k φ ψ : MvPowerSeries σ k h : ¬↑(constantCoeff σ k) φ = 0 ∧ ¬↑(constantCoeff σ k) ψ = 0 ⊢ ψ⁻¹ * φ⁻¹ * (φ * ψ) = 1 State After: no goals Tactic: rw [← mul_assoc, mul_assoc _⁻¹, MvPowerSeries.inv_mul_cancel _ h.left, mul_one, MvPowerSeries.inv_mul_cancel _ h.right]
import set_theory.cardinal open function lattice set local attribute [instance] classical.prop_decidable universes u v w x variables {α β : Type u} namespace cardinal lemma mk_zero_iff_empty_set (s : set α) : cardinal.mk s = 0 ↔ s = ∅ := not_iff_not.1 (ne_zero_iff_nonempty.trans coe_nonempty_iff_ne_empty) lemma nat_add (m n : ℕ) : ((m + n : ℕ) : cardinal) = (m + n : cardinal) := nat.cast_add _ _ lemma exists_nat_of_add_eq_nat {a b : cardinal} {n : ℕ} (h : a + b = n) : ∃ k l : ℕ, a = k ∧ b = l := begin rcases (@cardinal.lt_omega a).1 _ with ⟨k, hk⟩, rcases (@cardinal.lt_omega b).1 _ with ⟨l, hl⟩, { use k, use l, cc }, { refine ((@cardinal.add_lt_omega_iff a b).1 _).2, rw h, apply cardinal.nat_lt_omega }, { refine ((@cardinal.add_lt_omega_iff a b).1 _).1, rw h, apply cardinal.nat_lt_omega }, end end cardinal
lemma IVT2: fixes f :: "'a::linear_continuum_topology \<Rightarrow> 'b::linorder_topology" shows "f b \<le> y \<Longrightarrow> y \<le> f a \<Longrightarrow> a \<le> b \<Longrightarrow> (\<forall>x. a \<le> x \<and> x \<le> b \<longrightarrow> isCont f x) \<Longrightarrow> \<exists>x. a \<le> x \<and> x \<le> b \<and> f x = y"
\subsubsection{Context} In this section we look at the context in which certain activities are performed. The examined contexts are the physical environment, and the social context. \paragraph{Physical environment} Using the program in different locations will have different impact on the user experience. Having the program on a device will set some limitations, as the user will have to interact with the program, during different situations. \begin{itemize} \item With the households inventory stored in the program, a user will not have to be home, to see what is missing, if he/she chooses to add another recipe. \item While shopping, one hand must be free, to check which items that has been put in the basket, and what else must be bought. \item While cooking at home, an ingredients list could be revisited, or a cooking guide will have to be followed, with greasy hands this kind of interaction will be difficult. \end{itemize} \paragraph{Social context} The program can be used in different social context. \begin{itemize} \item If more than one person share the same food plan, they must both have access to the program, and if it is handled on their personal devices, synchronization is necessary. \item The program can be used by only one person and on one device only, therefore synchronization might be a nuisance instead of a trait for this type of user. \item With an online database of recipes, it would be possible to add new recipes and share these, with other users. \end{itemize} In conclusion, it is important to look at different environments like physical and social environments. The program does not need to be used in the home, it can also be used while shopping. The user should also be able to use the program while cooking, even though this might set some limitations for the user. In social context it is important that users can share the same food plan if this is going to be a functionality of the program, as well as it is important that the online database can synchronize quickly, or set when it needs to do so.
#include <gtest/gtest.h> #include <random> #include <gmp.h> #include <boost/multiprecision/gmp.hpp> #include <ojlibs/power.hpp> using namespace std; using namespace ojlibs; namespace bm = boost::multiprecision; std::mt19937 gen; void test_power(const bm::mpz_int &a, int b) { bm::mpz_int expect = pow(a, b); bm::mpz_int answer = power(a, b); EXPECT_EQ(expect, answer); } TEST(BASIC, SMALL) { test_power(12, 0); test_power(12, 1); test_power(12, 2); } TEST(BASIC, RANDOM) { gmp_randstate_t ran; gmp_randinit_default(ran); static const int TEST_GROUP = 1000; uniform_int_distribution<> dist(0, 10000); for (int i = 0; i < TEST_GROUP; ++i) { bm::mpz_int a; mpz_urandomb(a.backend().data(), ran, 15); int b = dist(gen); test_power(a, b); } }
{-# OPTIONS --cubical --no-import-sorts --safe #-} module Cubical.Algebra.Group.Morphism where open import Cubical.Foundations.Prelude open import Cubical.Foundations.Equiv open import Cubical.Algebra.Group.Base open import Cubical.HITs.PropositionalTruncation hiding (map) open import Cubical.Data.Sigma private variable ℓ ℓ' : Level -- The following definition of GroupHom and GroupEquiv are level-wise heterogeneous. -- This allows for example to deduce that G ≡ F from a chain of isomorphisms -- G ≃ H ≃ F, even if H does not lie in the same level as G and F. isGroupHom : (G : Group {ℓ}) (H : Group {ℓ'}) (f : ⟨ G ⟩ → ⟨ H ⟩) → Type _ isGroupHom G H f = (x y : ⟨ G ⟩) → f (x G.+ y) ≡ (f x H.+ f y) where module G = Group G module H = Group H record GroupHom (G : Group {ℓ}) (H : Group {ℓ'}) : Type (ℓ-max ℓ ℓ') where constructor grouphom no-eta-equality field fun : ⟨ G ⟩ → ⟨ H ⟩ isHom : isGroupHom G H fun record GroupEquiv (G : Group {ℓ}) (H : Group {ℓ'}) : Type (ℓ-max ℓ ℓ') where constructor groupequiv no-eta-equality field eq : ⟨ G ⟩ ≃ ⟨ H ⟩ isHom : isGroupHom G H (equivFun eq) hom : GroupHom G H hom = grouphom (equivFun eq) isHom open GroupHom open GroupEquiv η-hom : {G : Group {ℓ}} {H : Group {ℓ'}} → (a : GroupHom G H) → grouphom (fun a) (isHom a) ≡ a fun (η-hom a i) = fun a isHom (η-hom a i) = isHom a η-equiv : {G : Group {ℓ}} {H : Group {ℓ'}} → (a : GroupEquiv G H) → groupequiv (eq a) (isHom a) ≡ a eq (η-equiv a i) = eq a isHom (η-equiv a i) = isHom a ×hom : ∀ {ℓ ℓ' ℓ'' ℓ'''} {A : Group {ℓ}} {B : Group {ℓ'}} {C : Group {ℓ''}} {D : Group {ℓ'''}} → GroupHom A C → GroupHom B D → GroupHom (dirProd A B) (dirProd C D) fun (×hom mf1 mf2) = map-× (fun mf1) (fun mf2) isHom (×hom mf1 mf2) a b = ≡-× (isHom mf1 _ _) (isHom mf2 _ _) open Group isInIm : ∀ {ℓ ℓ'} (G : Group {ℓ}) (H : Group {ℓ'}) → (GroupHom G H) → ⟨ H ⟩ → Type (ℓ-max ℓ ℓ') isInIm G H ϕ h = ∃[ g ∈ ⟨ G ⟩ ] (fun ϕ) g ≡ h isInKer : ∀ {ℓ ℓ'} (G : Group {ℓ}) (H : Group {ℓ'}) → (GroupHom G H) → ⟨ G ⟩ → Type ℓ' isInKer G H ϕ g = (fun ϕ) g ≡ 0g H isSurjective : ∀ {ℓ ℓ'} (G : Group {ℓ}) (H : Group {ℓ'}) → GroupHom G H → Type (ℓ-max ℓ ℓ') isSurjective G H ϕ = (x : ⟨ H ⟩) → isInIm G H ϕ x isInjective : ∀ {ℓ ℓ'} (G : Group {ℓ}) (H : Group {ℓ'}) → GroupHom G H → Type (ℓ-max ℓ ℓ') isInjective G H ϕ = (x : ⟨ G ⟩) → isInKer G H ϕ x → x ≡ 0g G
#define EIGEN_RUNTIME_NO_MALLOC #include <Eigen/Core> #include <algorithm> #include <catch2/catch.hpp> #include <vector> #include "ear/dsp/gain_interpolator.hpp" #include "ear/dsp/ptr_adapter.hpp" #include "eigen_utils.hpp" using namespace ear; using namespace ear::dsp; // adapters to make apply_interp, apply_constant and process work with Eigen // types template <typename Interp = LinearInterpSingle, typename In, typename Out, typename Point> void apply_interp(In &&in, Out &&out, SampleIndex block_start, SampleIndex start, SampleIndex end, const Point &start_point, const Point &end_point) { PtrAdapter in_p(in.cols()); in_p.set_eigen(in); PtrAdapter out_p(out.cols()); out_p.set_eigen(out); Interp::apply_interp(in_p.ptrs(), out_p.ptrs(), 0, in.rows(), block_start, start, end, start_point, end_point); } template <typename Interp = LinearInterpSingle, typename In, typename Out, typename Point> void apply_constant(In &&in, Out &&out, const Point &point) { PtrAdapter in_p(in.cols()); in_p.set_eigen(in); PtrAdapter out_p(out.cols()); out_p.set_eigen(out); Interp::apply_constant(in_p.ptrs(), out_p.ptrs(), 0, in.rows(), point); } template <typename Interp> void process(Interp &interp, SampleIndex block_start, const Eigen::Ref<const Eigen::MatrixXf> &in, Eigen::Ref<Eigen::MatrixXf> out) { PtrAdapterConst in_p(in.cols()); in_p.set_eigen(in); PtrAdapter out_p(out.cols()); out_p.set_eigen(out); interp.process(block_start, in.rows(), in_p.ptrs(), out_p.ptrs()); } // ensure that LinearInterpSingle is correct so that we can use it to generate // expected results in tests of GainInterpolator; otherwise we would just end up // reimplementing it here TEST_CASE("LinearInterpSingle::apply_interp") { Eigen::VectorXf input = Eigen::VectorXf::Random(100); Eigen::VectorXf output = Eigen::VectorXf::Zero(100); apply_interp<LinearInterpSingle>(input, output, 100, 50, 250, 0.2f, 0.8f); Eigen::VectorXf p = Eigen::VectorXf::LinSpaced(200, 0, 199) / 200.0; Eigen::VectorXf gain_ramp = 0.8f * p.array() + (1.0f - p.array()) * 0.2f; Eigen::VectorXf expected = gain_ramp(Eigen::seqN(50, 100)).cwiseProduct(input); CHECK_THAT(output, IsApprox(expected)); } TEST_CASE("LinearInterpSingle::apply_constant") { Eigen::VectorXf input = Eigen::VectorXf::Random(100); Eigen::VectorXf output = Eigen::VectorXf::Zero(100); apply_constant<LinearInterpSingle>(input, output, 0.3f); Eigen::VectorXf expected = 0.3f * input; CHECK_THAT(output, IsApprox(expected)); } void run_test(GainInterpolator<LinearInterpSingle> &interp, Eigen::VectorXf &input, Eigen::VectorXf &expected_output, const std::vector<Eigen::Index> &block_sizes) { for (auto block_size : block_sizes) { Eigen::VectorXf output = Eigen::VectorXf::Zero(input.size()); Eigen::internal::set_is_malloc_allowed(false); for (Eigen::Index offset = 0; offset < input.size(); offset += block_size) { auto block = Eigen::seq(offset, std::min(offset + block_size, input.size()) - 1); process(interp, offset, input(block), output(block)); } Eigen::internal::set_is_malloc_allowed(true); CHECK_THAT(output, IsApprox(expected_output)); } } // check that GainInterpolator makes the right calls to the templated InterpType TEST_CASE("basic") { GainInterpolator<LinearInterpSingle> interp; interp.interp_points.emplace_back(100, 0.2f); interp.interp_points.emplace_back(200, 0.8f); interp.interp_points.emplace_back(300, 0.8f); interp.interp_points.emplace_back(400, 0.3f); Eigen::VectorXf input = Eigen::VectorXf::Random(500); Eigen::VectorXf expected_output = Eigen::VectorXf::Zero(500); auto block = Eigen::seqN(0, 100); apply_constant(input(block), expected_output(block), 0.2f); block = Eigen::seqN(100, 100); apply_interp(input(block), expected_output(block), 100, 100, 200, 0.2f, 0.8f); block = Eigen::seqN(200, 100); apply_constant(input(block), expected_output(block), 0.8f); block = Eigen::seqN(300, 100); apply_interp(input(block), expected_output(block), 300, 300, 400, 0.8f, 0.3f); block = Eigen::seqN(400, 100); apply_constant(input(block), expected_output(block), 0.3f); run_test(interp, input, expected_output, {50, 75, 100, 500}); } TEST_CASE("step") { GainInterpolator<LinearInterpSingle> interp; interp.interp_points.emplace_back(100, 0.2f); interp.interp_points.emplace_back(200, 0.2f); interp.interp_points.emplace_back(200, 0.8f); interp.interp_points.emplace_back(300, 0.8f); Eigen::VectorXf input = Eigen::VectorXf::Random(400); Eigen::VectorXf expected_output = Eigen::VectorXf::Zero(400); auto block = Eigen::seqN(0, 200); apply_constant(input(block), expected_output(block), 0.2f); block = Eigen::seqN(200, 200); apply_constant(input(block), expected_output(block), 0.8f); run_test(interp, input, expected_output, {50, 75, 100, 400}); } TEST_CASE("only_step") { GainInterpolator<LinearInterpSingle> interp; interp.interp_points.emplace_back(100, 0.2f); interp.interp_points.emplace_back(100, 0.8f); Eigen::VectorXf input = Eigen::VectorXf::Random(200); Eigen::VectorXf expected_output = Eigen::VectorXf::Zero(200); auto block = Eigen::seqN(0, 100); apply_constant(input(block), expected_output(block), 0.2f); block = Eigen::seqN(100, 100); apply_constant(input(block), expected_output(block), 0.8f); run_test(interp, input, expected_output, {50, 75, 100, 200}); } TEST_CASE("one_point") { GainInterpolator<LinearInterpSingle> interp; interp.interp_points.emplace_back(100, 0.2); Eigen::VectorXf input = Eigen::VectorXf::Random(200); Eigen::VectorXf expected_output = Eigen::VectorXf::Zero(200); auto block = Eigen::seqN(0, 200); apply_constant(input(block), expected_output(block), 0.2f); run_test(interp, input, expected_output, {50, 75, 100, 200}); } // tests for the other InterpTypes TEST_CASE("vector") { GainInterpolator<LinearInterpVector> interp; std::vector<float> a{0.0f, 1.0f}; std::vector<float> b{1.0f, 0.0f}; interp.interp_points.emplace_back(100, a); interp.interp_points.emplace_back(200, b); Eigen::VectorXf input = Eigen::VectorXf::Random(300); Eigen::MatrixXf output = Eigen::MatrixXf::Zero(300, 2); Eigen::internal::set_is_malloc_allowed(false); process(interp, 0, input, output); Eigen::internal::set_is_malloc_allowed(true); Eigen::MatrixXf expected_output = Eigen::MatrixXf::Zero(300, 2); auto run_channel = [&](Eigen::Index out) { Eigen::MatrixXf tmp = Eigen::MatrixXf::Zero(300, 1); GainInterpolator<LinearInterpSingle> interp_test; interp_test.interp_points.emplace_back(100, a[out]); interp_test.interp_points.emplace_back(200, b[out]); process(interp_test, 0, input, tmp); expected_output(Eigen::all, out) += tmp; }; run_channel(0); run_channel(1); CHECK_THAT(output, IsApprox(expected_output)); } TEST_CASE("matrix") { GainInterpolator<LinearInterpMatrix> interp; std::vector<std::vector<float>> a{{0.0f, 0.3f}, {0.5f, 0.0f}}; std::vector<std::vector<float>> b{{0.6f, 0.0f}, {0.0f, 0.7f}}; interp.interp_points.emplace_back(100, a); interp.interp_points.emplace_back(200, b); Eigen::MatrixXf input = Eigen::MatrixXf::Random(300, 2); Eigen::MatrixXf output = Eigen::MatrixXf::Zero(300, 2); Eigen::internal::set_is_malloc_allowed(false); process(interp, 0, input, output); Eigen::internal::set_is_malloc_allowed(true); Eigen::MatrixXf expected_output = Eigen::MatrixXf::Zero(300, 2); auto run_channel = [&](Eigen::Index in, Eigen::Index out) { Eigen::MatrixXf tmp = Eigen::MatrixXf::Zero(300, 1); GainInterpolator<LinearInterpSingle> interp_test; interp_test.interp_points.emplace_back(100, a[in][out]); interp_test.interp_points.emplace_back(200, b[in][out]); process(interp_test, 0, input(Eigen::all, in), tmp); expected_output(Eigen::all, out) += tmp; }; run_channel(0, 0); run_channel(0, 1); run_channel(1, 0); run_channel(1, 1); CHECK_THAT(output, IsApprox(expected_output)); }
clear; clc; close all; genJSON('LEEDS');
module Minecraft.Data.Serialize import public Language.JSON %default total public export interface Serialize a where identifier : String serialize : a -> JSON
from __future__ import print_function import os,sys,cv2,random,datetime,time,math import argparse import numpy as np import torch from timebudget import timebudget try: from iou import IOU except: # IOU cython speedup 10x def IOU(ax1,ay1,ax2,ay2,bx1,by1,bx2,by2): sa = abs((ax2-ax1)*(ay2-ay1)) sb = abs((bx2-bx1)*(by2-by1)) x1,y1 = max(ax1,bx1),max(ay1,by1) x2,y2 = min(ax2,bx2),min(ay2,by2) w = x2 - x1 h = y2 - y1 if w<0 or h<0: return 0.0 else: return 1.0*w*h/(sa+sb-w*h) def bboxlog(x1,y1,x2,y2,axc,ayc,aww,ahh): xc,yc,ww,hh = (x2+x1)/2,(y2+y1)/2,x2-x1,y2-y1 dx,dy = (xc-axc)/aww,(yc-ayc)/ahh dw,dh = math.log(ww/aww),math.log(hh/ahh) return dx,dy,dw,dh def bboxloginv(dx,dy,dw,dh,axc,ayc,aww,ahh): xc,yc = dx*aww+axc, dy*ahh+ayc ww,hh = math.exp(dw)*aww,math.exp(dh)*ahh x1,x2,y1,y2 = xc-ww/2,xc+ww/2,yc-hh/2,yc+hh/2 return x1,y1,x2,y2 @timebudget def nms(bboxlist:torch.Tensor, thresh:float) -> list: """Given an Nx5 tensor of bounding boxes, and a threshold, return a list of the indexes of bounding boxes to keep. """ if len(bboxlist) == 0: return [] x1 = bboxlist[:,0] y1 = bboxlist[:,1] x2 = bboxlist[:,2] y2 = bboxlist[:,3] scores = bboxlist[:,4] areas = (x2 - x1 + 1) * (y2 - y1 + 1) # Go through the boxes in order of decreasing score... scores = np.asarray(scores) order = scores.argsort() order = np.asarray(list(order[::-1])) keep = [] while len(order) > 0: i = order[0] keep.append(i) # Keep this one. # For all the remaining (lower score) bounding boxes, figure out something about the overlap I think xx1,yy1 = np.maximum(x1[i], x1[order[1:]]),np.maximum(y1[i], y1[order[1:]]) xx2,yy2 = np.minimum(x2[i], x2[order[1:]]),np.minimum(y2[i], y2[order[1:]]) w,h = np.maximum(0.0, xx2 - xx1 + 1),np.maximum(0.0, yy2 - yy1 + 1) ovr = w*h / (areas[i] + areas[order[1:]] - w*h) # looks like the overlap inds = np.where(ovr <= thresh)[0] order = order[inds + 1] # eliminate the ones that don't meet the threshhold return keep def encode(matched, priors, variances): """Encode the variances from the priorbox layers into the ground truth boxes we have matched (based on jaccard overlap) with the prior boxes. Args: matched: (tensor) Coords of ground truth for each prior in point-form Shape: [num_priors, 4]. priors: (tensor) Prior boxes in center-offset form Shape: [num_priors,4]. variances: (list[float]) Variances of priorboxes Return: encoded boxes (tensor), Shape: [num_priors, 4] """ # dist b/t match center and prior's center g_cxcy = (matched[:, :2] + matched[:, 2:])/2 - priors[:, :2] # encode variance g_cxcy /= (variances[0] * priors[:, 2:]) # match wh / prior wh g_wh = (matched[:, 2:] - matched[:, :2]) / priors[:, 2:] g_wh = torch.log(g_wh) / variances[1] # return target for smooth_l1_loss return torch.cat([g_cxcy, g_wh], 1) # [num_priors,4] def decode(loc, priors, variances): """Decode locations from predictions using priors to undo the encoding we did for offset regression at train time. Args: loc (tensor): location predictions for loc layers, Shape: [num_priors,4] priors (tensor): Prior boxes in center-offset form. Shape: [num_priors,4]. variances: (list[float]) Variances of priorboxes Return: decoded bounding box predictions """ boxes = torch.cat(( priors[:, :2] + loc[:, :2] * variances[0] * priors[:, 2:], priors[:, 2:] * torch.exp(loc[:, 2:] * variances[1])), 1) boxes[:, :2] -= boxes[:, 2:] / 2 boxes[:, 2:] += boxes[:, :2] return boxes
% arara: xelatex: { shell: yes, synctex: yes, options: [ '-output-directory=../doc/' ] } \documentclass{ist-report} % == BEGIN PREAMBLE == % Packages and configurations here aren't really necessary to define the style, % but are recommended to use. Some packages require users to know extra commands % to use properly, so I won't include them in the class file for now. % -- Code snippets \usepackage[outputdir=../doc/]{minted} \definecolor{bg}{rgb}{0.95,0.95,0.95} \setminted[c]{linenos, bgcolor = bg, breaklines} \setmintedinline[c]{bgcolor = {}} % -- Bibliography \usepackage{csquotes} \usepackage{fvextra} % -- Extra math options \usepackage{siunitx} % -- Extra symbols \usepackage{amssymb} \usepackage{textcomp} \usepackage{gensymb} % -- Additional table features \usepackage{booktabs} % -- Image and float settings \usepackage{graphicx} \usepackage{subcaption} % -- Graphs and diagrams \usepackage{tikz} \usepackage{pgfplots} \usetikzlibrary{arrows.meta,positioning} \pgfplotsset{compat = 1.5, table/search path = {data/}} % == END PREAMBLE == \newrobustcmd*{\package}[1]{\texttt{#1}} \begin{document} \title{Report Example} \subtitle{Generic implementations of commonly used \LaTeX{} structures} \author{Daniel de Schiffart} \date{2018} \makecover{} \section{Report Content Samples} To showcase the class, its effects on multiple \LaTeX{} environments and to give examples on different types of content to use with the class (and with \LaTeX{} in general), this section contains a variety of content to be used within \LaTeX{} and should cover the basis for the content of most reports. Any content not covered here should work fine within this class, as long as there are no conflicting packages, fonts, or other major modifications to the basic \LaTeX{} configuration. Any problems found, report them to me. \subsection{Basic Math} This section contains math typesetting as examples to show how it will look like in the final product. This will depend mostly on the font used for math, so the class itself will not have much to change within this department. For the time being, the math font remains imported from the package \package{newpxmath}, which I grew a fondness for. The example from equation \ref{eq:biotsavart} was derived from \textit{The \LaTeX{} Font Catalogue} \cite{fontcatalogue}. It is the integral form of the Biot-Savart law and showcases some details with math font. More math examples to follow. \begin{gather} \label{eq:biotsavart} B(P) = \frac{\mu_0}{4\pi}\int{\frac{\boldsymbol{I} \times \hat{r}'}{r'^2}dl} = \frac{\mu_0}{4\pi} I \int{\frac{d\boldsymbol{l} \times \hat{r}'}{r'^2}} \end{gather} An example of arrays and matrices is in equation \ref{eq:sat_error}. The equation in question represents the positioning error $e$ for a group of GPS satellites obtained using differential GPS correction, where $d_{GS}$ represents the distance between satellite $N$ and the differential GPS ground station, and $\rho_{GS}$ the pseudorange obtained in the aforementioned ground station. \begin{gather} \label{eq:sat_error} \left[\begin{matrix} e^{(1)} \\ e^{(2)} \\ \vdots \\ e^{(N)} \\ \end{matrix}\right] = \left[\begin{matrix} d^{(1)}_{GS} - \rho^{(1)}_{GS} \\ d^{(2)}_{GS} - \rho^{(2)}_{GS} \\ \vdots \\ d^{(N)}_{GS} - \rho^{(N)}_{GS} \\ \end{matrix}\right] \end{gather} \subsection{Floats} According to the \textit{Wikibooks} \LaTeX{} online textbook \cite{latexwiki}, \begin{quote} \itshape Floats are containers for things in a document that cannot be broken over a page. [...] Floats are not part of the normal stream of text, but separate entities, positioned in a part of the page to themselves (top, middle, bottom, left, right, or wherever the designer specifies). They always have a caption describing them and they are always numbered so they can be referred to from elsewhere in the text. \end{quote} \subsubsection{Figures} \begin{figure}[ht] \centering \includegraphics[width = 0.4\textwidth]{example-image} \caption{This is an example image inside a \texttt{figure} float.} \label{fig:example} \end{figure} \subsubsection{Tables} My apologies for this section, my \LaTeX{} is kinda shoddy when it comes to tables; I've been kinda making it work with basic \package{tabular} environments, like the one in table \ref{tab:ex1}. I do however recommend using \package{booktabs} after getting familiar with \package{tabular}, it's a small increment but goes a long way in helping the look of your tables. \begin{table}[ht] \centering \begin{tabular}{l c c c}\toprule & Column 1 & Column 2 & Column 3 \\ \midrule Line 1 & $0.0$ & $0.1$ & $0.2$ \\ Line 2 & $0.4$ & $0.5$ & $0.6$ \\ Line 3 & $0.8$ & $0.9$ & $1.0$ \\ \bottomrule \end{tabular} \caption{Basic table example.} \label{tab:ex1} \end{table} \subsection{Ti\textit{k}Z} A basic Ti\textit{k}Z drawing of a tall box can be found in figure \ref{fig:tikz_ex1}. \begin{figure}[ht] \centering \begin{tikzpicture}[ppoint/.style = {circle,draw,inner sep = 0pt, minimum size = 3pt}] \node (p1) at (0,0) [ppoint,label = {135:$P_1$}] {}; \node (p2) at (1,1) [ppoint,label = {135:$P_2$}] {}; \node (p3) at (3,1) [ppoint,label = {135:$P_3$}] {}; \node (p4) at (2,0) [ppoint,label = {135:$P_4$}] {}; \node (p5) at (0,3) [ppoint,label = {135:$P_5$}] {}; \node (p6) at (1,4) [ppoint,label = {135:$P_6$}] {}; \node (p7) at (3,4) [ppoint,label = {135:$P_7$}] {}; \node (p8) at (2,3) [ppoint,label = {135:$P_8$}] {}; \draw (p1) -- (p5) -- (p6) -- (p7) -- (p3) -- (p4) -- (p1); \draw (p5) -- (p8) -- (p7) (p8) -- (p4); \draw [dashed] (p1) -- (p2) -- (p6) (p2) -- (p3); \draw [<->] (p3) ++(0.5,0) -- node [auto,swap] {$h$} ++(0,3); \end{tikzpicture} \caption{Tall box and its corresponding height $h$. Drawing made using Ti\textit{k}Z.} \label{fig:tikz_ex1} \end{figure} \begin{figure}[ht] \centering \scalebox{0.8}{ \begin{tikzpicture}[clipboard/.style = {rectangle, draw, inner sep = 2cm}, app/.style = {rectangle, draw, inner sep = 3mm}, socketin/.style = {rectangle, color = black!70!green}, pathstyle/.style = {->}, pathlabel/.style ={color = black!40!blue}] % Start of Clipboard 1 \node (app1) at (0,0) [app] {App 1}; \node (app2) [app, right = 1.7cm of app1] {App 2}; \node (t2app1) [socketin, below = 3cm of app1] {\texttt{thread\_1}}; \node (t2app2) [socketin, below = 3cm of app2] {\texttt{thread\_1}}; \draw [pathstyle] (app1) to [bend right = 20] node [auto,swap,align = right, pathlabel] {\footnotesize \ttfamily copy \\ \footnotesize \ttfamily paste \\ \footnotesize \ttfamily wait \\ \footnotesize \ttfamily disconnect} (t2app1); \draw [pathstyle] (t2app1) to [bend right = 20] (app1); \draw [pathstyle] (app2) to [bend right = 20] (t2app2); \draw [pathstyle] (t2app2) to [bend right = 20] (app2); \path (t2app1.north) to node (clip1) [auto, swap, clipboard] {\LARGE Clipboard 1} (t2app2.north); \path (clip1.north east) to node (clip1in1) [auto, swap, align = right, yshift = 0.5cm, socketin] {\texttt{thread\_1}} node (clip1in3) [auto, swap, align = right, yshift = -0.5cm, socketin] {\texttt{thread\_3}} (clip1.south east); % Start of Clipboard 2 \node (app3) at (10,0) [app] {App 3}; \node (app4) [app, right = 1.7cm of app3] {App 4}; \node (t2app3) [socketin, below = 3cm of app3] {\texttt{thread\_1}}; \node (t2app4) [socketin, below = 3cm of app4] {\texttt{thread\_1}}; \draw [pathstyle] (app3) to [bend right = 20] (t2app3); \draw [pathstyle] (t2app3) to [bend right = 20] (app3); \draw [pathstyle] (app4) to [bend right = 20] (t2app4); \draw [pathstyle] (t2app4) to [bend right = 20] (app4); \path (t2app3.north) to node (clip2) [auto, swap, clipboard] {\LARGE Clipboard 2} (t2app4.north); \path (clip2.north west) to node (clip2in1) [auto, align = left, yshift = 0.5cm, socketin] {\texttt{thread\_1}} (clip2.south west); % Paths in between \draw [pathstyle] (clip1in1.north east) -- node [auto, align = center, pathlabel] {\ttfamily \footnotesize paste \\ \ttfamily \footnotesize redirect} (clip2in1.north west); \draw [pathstyle] (clip2in1) -- (clip1in1); \draw [pathstyle] (clip1in3.east) -- node [auto, swap, pathlabel] {\ttfamily \footnotesize redirect} (clip2in1); \end{tikzpicture}} \caption{A slightly longer T\textit{i}kZ example.} \label{fig:scheme_main} \end{figure} \subsection{Plots} \subsection{Code Snippets and Extracts} The objective is to have any code content use the \package{minted} package to typeset code. However, due to the high number of requirements to properly run \package{minted} on a local installation of \TeX{}, this option should only be used with an online editor (\textit{Overleaf} comes as the most prominent example). In any case, for the time being \package{minted} is included in this template, but can be further on replaced with a package like \package{listings}, possibly using a class option. Plans are also down to include a tutorial on how to check and install \package{minted} and get it to work. Here is a basic excerpt of a basic C \textit{Hello World} program. \begin{minted}{c} #include <stdio.h> int main(void) { printf("Hello World!"); return 0; } \end{minted} \end{document}
(* Author: Bernhard Stöckl *) theory QueryGraph imports Complex_Main "Graph_Additions" "Selectivities" "JoinTree" begin section \<open>Query Graphs\<close> locale query_graph = graph + fixes sel :: "'b weight_fun" fixes cf :: "'a \<Rightarrow> real" assumes sel_sym: "\<lbrakk>tail G e\<^sub>1 = head G e\<^sub>2; head G e\<^sub>1 = tail G e\<^sub>2\<rbrakk> \<Longrightarrow> sel e\<^sub>1 = sel e\<^sub>2" and not_arc_sel_1: "e \<notin> arcs G \<Longrightarrow> sel e = 1" and sel_pos: "sel e > 0" and sel_leq_1: "sel e \<le> 1" and pos_cards: "x \<in> verts G \<Longrightarrow> cf x > 0" begin subsection \<open>Function for Join Trees and Selectivities\<close> definition matching_sel :: "'a selectivity \<Rightarrow> bool" where "matching_sel f = (\<forall>x y. (\<exists>e. (tail G e) = x \<and> (head G e) = y \<and> f x y = sel e) \<or> ((\<nexists>e. (tail G e) = x \<and> (head G e) = y) \<and> f x y = 1))" definition match_sel :: "'a selectivity" where "match_sel x y = (if \<exists>e \<in> arcs G. (tail G e) = x \<and> (head G e) = y then sel (THE e. e \<in> arcs G \<and> (tail G e) = x \<and> (head G e) = y) else 1)" definition matching_rels :: "'a joinTree \<Rightarrow> bool" where "matching_rels t = (relations t \<subseteq> verts G)" definition remove_sel :: "'a \<Rightarrow> 'b weight_fun" where "remove_sel x = (\<lambda>b. if b\<in>{a \<in> arcs G. tail G a = x \<or> head G a = x} then 1 else sel b)" definition valid_tree :: "'a joinTree \<Rightarrow> bool" where "valid_tree t = (relations t = verts G \<and> distinct_relations t)" fun no_cross_products :: "'a joinTree \<Rightarrow> bool" where "no_cross_products (Relation rel) = True" | "no_cross_products (Join l r) = ((\<exists>x\<in>relations l. \<exists>y\<in>relations r. x \<rightarrow>\<^bsub>G\<^esub> y) \<and> no_cross_products l \<and> no_cross_products r)" subsection "Proofs" text \<open> Proofs that a query graph satisifies basic properties of join trees and selectivities. \<close> lemma sel_less_arc: "sel x < 1 \<Longrightarrow> x \<in> arcs G" using not_arc_sel_1 by force lemma joinTree_card_pos: "matching_rels t \<Longrightarrow> pos_rel_cards cf t" by(induction t) (auto simp: pos_cards pos_rel_cards_def matching_rels_def) lemma symmetric_arcs: "x\<in>arcs G \<Longrightarrow> \<exists>y. head G x = tail G y \<and> tail G x = head G y" using sym_arcs symmetric_conv by fast lemma arc_ends_eq_impl_sel_eq: "head G x = head G y \<Longrightarrow> tail G x = tail G y \<Longrightarrow> sel x = sel y" using sel_sym symmetric_arcs not_arc_sel_1 by metis lemma arc_ends_eq_impl_arc_eq: "\<lbrakk>e1 \<in> arcs G; e2 \<in> arcs G; head G e1 = head G e2; tail G e1 = tail G e2\<rbrakk> \<Longrightarrow> e1 = e2" using no_multi_alt by blast lemma matching_sel_simp_if_not1: "\<lbrakk>matching_sel sf; sf x y \<noteq> 1\<rbrakk> \<Longrightarrow> \<exists>e \<in> arcs G. tail G e = x \<and> head G e = y \<and> sf x y = sel e" using not_arc_sel_1 unfolding matching_sel_def by fastforce lemma matching_sel_simp_if_arc: "\<lbrakk>matching_sel sf; e \<in> arcs G\<rbrakk> \<Longrightarrow> sf (tail G e) (head G e) = sel e" unfolding matching_sel_def by (metis arc_ends_eq_impl_sel_eq) lemma matching_sel1_if_no_arc: "matching_sel sf \<Longrightarrow> \<not>(x \<rightarrow>\<^bsub>G\<^esub> y \<or> y \<rightarrow>\<^bsub>G\<^esub> x) \<Longrightarrow> sf x y = 1" using not_arc_sel_1 unfolding arcs_ends_def arc_to_ends_def matching_sel_def image_iff by metis lemma matching_sel_alt_aux1: "matching_sel f \<Longrightarrow> (\<forall>x y. (\<exists>e \<in> arcs G. (tail G e) = x \<and> (head G e) = y \<and> f x y = sel e) \<or> ((\<nexists>e. e \<in> arcs G \<and> (tail G e) = x \<and> (head G e) = y) \<and> f x y = 1))" by (metis matching_sel_def arc_ends_eq_impl_sel_eq not_arc_sel_1) lemma matching_sel_alt_aux2: "(\<forall>x y.(\<exists>e \<in> arcs G. (tail G e) = x \<and> (head G e) = y \<and> f x y = sel e) \<or> ((\<nexists>e. e \<in> arcs G \<and> (tail G e) = x \<and> (head G e) = y) \<and> f x y = 1)) \<Longrightarrow> matching_sel f" by (fastforce simp: not_arc_sel_1 matching_sel_def) lemma matching_sel_alt: "matching_sel f = (\<forall>x y. (\<exists>e \<in> arcs G. (tail G e) = x \<and> (head G e) = y \<and> f x y = sel e) \<or> ((\<nexists>e. e \<in> arcs G \<and> (tail G e) = x \<and> (head G e) = y) \<and> f x y = 1))" using matching_sel_alt_aux1 matching_sel_alt_aux2 by blast lemma matching_sel_symm: assumes "matching_sel f" shows "sel_symm f" unfolding sel_symm_def proof (standard, standard) fix x y show "f x y = f y x" proof(cases "\<exists>e\<in>arcs G. (head G e) = x \<and> (tail G e) = y") case True then show ?thesis using assms symmetric_arcs sel_sym unfolding matching_sel_def by metis next case False then show ?thesis by (metis assms symmetric_arcs matching_sel_def not_arc_sel_1 sel_sym) qed qed lemma matching_sel_reasonable: "matching_sel f \<Longrightarrow> sel_reasonable f" using sel_reasonable_def matching_sel_def sel_pos sel_leq_1 by (metis le_numeral_extra(4) less_numeral_extra(1)) lemma matching_reasonable_cards: "\<lbrakk>matching_sel f; matching_rels t\<rbrakk> \<Longrightarrow> reasonable_cards cf f t" by (simp add: joinTree_card_pos matching_sel_reasonable pos_sel_reason_impl_reason) lemma matching_sel_unique_aux: assumes "matching_sel f" "matching_sel g" shows "f x y = g x y" proof(cases "\<exists>e. tail G e = x \<and> head G e = y") case True then show ?thesis using assms arc_ends_eq_impl_sel_eq unfolding matching_sel_def by metis next case False then show ?thesis using assms unfolding matching_sel_def by fastforce qed lemma matching_sel_unique: "\<lbrakk>matching_sel f; matching_sel g\<rbrakk> \<Longrightarrow> f = g" using matching_sel_unique_aux by blast lemma match_sel_matching[intro]: "matching_sel match_sel" unfolding matching_sel_alt proof(standard,standard) fix x y show "(\<exists>e\<in>arcs G. tail G e = x \<and> head G e = y \<and> match_sel x y = sel e) \<or> ((\<nexists>e. e \<in> arcs G \<and> tail G e = x \<and> head G e = y) \<and> match_sel x y = 1)" proof(cases "\<exists>e \<in> arcs G. tail G e = x \<and> head G e = y") case True then obtain e where e_def: "e \<in> arcs G" "tail G e = x" "head G e = y" by blast then have "match_sel x y = sel (THE e. e \<in> arcs G \<and> tail G e = x \<and> head G e = y)" unfolding match_sel_def by auto moreover have "(THE e. e \<in> arcs G \<and> tail G e = x \<and> head G e = y) = e" using e_def arc_ends_eq_impl_arc_eq by blast ultimately show ?thesis using e_def by blast next case False then show ?thesis unfolding match_sel_def by auto qed qed corollary match_sel_unique: "matching_sel f \<Longrightarrow> f = match_sel" using matching_sel_unique by blast corollary match_sel1_if_no_arc: "\<not>(x \<rightarrow>\<^bsub>G\<^esub> y \<or> y \<rightarrow>\<^bsub>G\<^esub> x) \<Longrightarrow> match_sel x y = 1" using matching_sel1_if_no_arc by blast corollary match_sel_symm[intro]: "sel_symm match_sel" using matching_sel_symm by blast corollary match_sel_reasonable[intro]: "sel_reasonable match_sel" using matching_sel_reasonable by blast corollary match_reasonable_cards: "matching_rels t \<Longrightarrow> reasonable_cards cf match_sel t" using matching_reasonable_cards by blast lemma matching_rels_trans: "matching_rels (Join l r) = (matching_rels l \<and> matching_rels r)" using matching_rels_def by simp lemma first_node_in_verts_if_rels_eq_verts: "relations t = verts G \<Longrightarrow> first_node t \<in> verts G" unfolding first_node_eq_hd using inorder_eq_set hd_in_set[OF inorder_nempty] by fast lemma first_node_in_verts_if_valid: "valid_tree t \<Longrightarrow> first_node t \<in> verts G" using first_node_in_verts_if_rels_eq_verts valid_tree_def by simp lemma dominates_sym: "(x \<rightarrow>\<^bsub>G\<^esub> y) \<longleftrightarrow> (y \<rightarrow>\<^bsub>G\<^esub> x)" using graph_symmetric by blast lemma no_cross_mirror_eq: "no_cross_products (mirror t) = no_cross_products t" using graph_symmetric by(induction t) auto lemma no_cross_create_ldeep_rev_app: "\<lbrakk>ys\<noteq>[]; no_cross_products (create_ldeep_rev (xs@ys))\<rbrakk> \<Longrightarrow> no_cross_products (create_ldeep_rev ys)" proof(induction "xs@ys" arbitrary: xs rule: create_ldeep_rev.induct) case (2 x) then show ?case by (metis append_eq_Cons_conv append_is_Nil_conv) next case (3 x y zs) then show ?case proof(cases xs) case Nil then show ?thesis using "3.prems"(2) by simp next case (Cons x' xs') have "no_cross_products (Join (create_ldeep_rev (y#zs)) (Relation x))" using "3.hyps"(2) "3.prems"(2) create_ldeep_rev.simps(3)[of x y zs] by simp then have "no_cross_products (create_ldeep_rev (y#zs))" by simp then show ?thesis using "3.hyps" "3.prems"(1) Cons by simp qed qed(simp) lemma no_cross_create_ldeep_app: "\<lbrakk>xs\<noteq>[]; no_cross_products (create_ldeep (xs@ys))\<rbrakk> \<Longrightarrow> no_cross_products (create_ldeep xs)" by (simp add: create_ldeep_def no_cross_create_ldeep_rev_app) lemma matching_rels_if_no_cross: "\<lbrakk>\<forall>r. t \<noteq> Relation r; no_cross_products t\<rbrakk> \<Longrightarrow> matching_rels t" unfolding matching_rels_def by(induction t) fastforce+ lemma no_cross_awalk: "\<lbrakk>matching_rels t; no_cross_products t; x \<in> relations t; y \<in> relations t\<rbrakk> \<Longrightarrow> \<exists>p. awalk x p y \<and> set (awalk_verts x p) \<subseteq> relations t" proof(induction t arbitrary: x y) case (Relation rel) then have "x \<in> verts G" using matching_rels_def by blast then have "awalk x [] x" by (simp add: awalk_Nil_iff) then show ?case using Relation(3,4) by force next case (Join l r) then consider "x \<in> relations l" "y \<in> relations l" | "x \<in> relations r" "y \<in> relations l" | "x \<in> relations l" "y \<in> relations r" | "x \<in> relations r" "y \<in> relations r" by force then show ?case proof(cases) case 1 then show ?thesis using Join.IH(1)[of x y] Join.prems(1,2) matching_rels_trans by auto next case 2 then obtain x' y' e where e_def: "x' \<in> relations r" "y' \<in> relations l" "tail G e = y'" "head G e = x'" "e \<in> arcs G" using Join.prems(2) by auto then obtain e2 where e2_def: "tail G e2 = x'" "head G e2 = y'" "e2 \<in> arcs G" using symmetric_conv by force obtain p1 where p1_def: "awalk y' p1 y \<and> set (awalk_verts y' p1) \<subseteq> relations l" using Join.IH(1) Join.prems(1,2) 2(2) matching_rels_trans e_def(2) by fastforce obtain p2 where p2_def: "awalk x p2 x' \<and> set (awalk_verts x p2) \<subseteq> relations r" using Join.IH(2) Join.prems(1,2) 2(1) matching_rels_trans e_def(1) by fastforce have "awalk x (p2@[e2]@p1) y" using e2_def p1_def p2_def awalk_appendI arc_implies_awalk by blast moreover from this have "set (awalk_verts x (p2@[e2]@p1)) \<subseteq> relations (Join l r)" using p1_def p2_def awalk_verts_append3 by auto ultimately show ?thesis by blast next case 3 then obtain x' y' e where e_def: "x' \<in> relations l" "y' \<in> relations r" "tail G e = x'" "head G e = y'" "e \<in> arcs G" using Join.prems(2) by auto obtain p1 where p1_def: "awalk y' p1 y \<and> set (awalk_verts y' p1) \<subseteq> relations r" using Join.IH(2) Join.prems(1,2) 3(2) matching_rels_trans e_def(2) by fastforce obtain p2 where p2_def: "awalk x p2 x' \<and> set (awalk_verts x p2) \<subseteq> relations l" using Join.IH(1) Join.prems(1,2) 3(1) matching_rels_trans e_def(1) by fastforce have "awalk x (p2@[e]@p1) y" using e_def(3-5) p1_def p2_def awalk_appendI arc_implies_awalk by blast moreover from this have "set (awalk_verts x (p2@[e]@p1)) \<subseteq> relations (Join l r)" using p1_def p2_def awalk_verts_append3 by auto ultimately show ?thesis by blast next case 4 then show ?thesis using Join.IH(2)[of x y] Join.prems(1,2) matching_rels_trans by auto qed qed lemma no_cross_apath: "\<lbrakk>matching_rels t; no_cross_products t; x \<in> relations t; y \<in> relations t\<rbrakk> \<Longrightarrow> \<exists>p. apath x p y \<and> set (awalk_verts x p) \<subseteq> relations t" using no_cross_awalk apath_awalk_to_apath awalk_to_apath_verts_subset by blast lemma no_cross_reachable: "\<lbrakk>matching_rels t; no_cross_products t; x \<in> relations t; y \<in> relations t\<rbrakk> \<Longrightarrow> x \<rightarrow>\<^sup>* y" using no_cross_awalk reachable_awalk by blast corollary reachable_if_no_cross: "\<lbrakk>\<exists>t. relations t = verts G \<and> no_cross_products t; x \<in> verts G; y \<in> verts G\<rbrakk> \<Longrightarrow> x \<rightarrow>\<^sup>* y" using no_cross_reachable matching_rels_def by blast lemma remove_sel_sym: "\<lbrakk>tail G e\<^sub>1 = head G e\<^sub>2; head G e\<^sub>1 = tail G e\<^sub>2\<rbrakk> \<Longrightarrow> (remove_sel x) e\<^sub>1 = (remove_sel x) e\<^sub>2" by(metis (no_types, lifting) mem_Collect_eq not_arc_sel_1 remove_sel_def sel_sym)+ lemma remove_sel_1: "e \<notin> arcs G \<Longrightarrow> (remove_sel x) e = 1" apply(cases "e\<in>{a \<in> arcs G. tail G a = x \<or> head G a = x}") by(auto simp: not_arc_sel_1 sel_sym remove_sel_def) lemma del_vert_remove_sel_1: assumes "e \<notin> arcs ((del_vert x))" shows "(remove_sel x) e = 1" proof(cases "e\<in>{a \<in> arcs G. tail G a = x \<or> head G a = x}") case True then show ?thesis by (simp add: remove_sel_def) next case False then have "e \<notin> arcs G" using assms arcs_del_vert by simp then show ?thesis using remove_sel_def not_arc_sel_1 by simp qed lemma remove_sel_pos: "remove_sel x e > 0" by(cases "e\<in>{a \<in> arcs G. tail G a = x \<or> head G a = x}") (auto simp: remove_sel_def sel_pos) lemma remove_sel_leq_1: "remove_sel x e \<le> 1" by(cases "e\<in>{a \<in> arcs G. tail G a = x \<or> head G a = x}") (auto simp: remove_sel_def sel_leq_1) lemma del_vert_pos_cards: "x \<in> verts (del_vert y) \<Longrightarrow> cf x > 0" by(cases "x=y") (auto simp: remove_sel_def del_vert_def pos_cards) lemma del_vert_remove_sel_query_graph: "query_graph G sel cf \<Longrightarrow> query_graph (del_vert x) (remove_sel x) cf" by (simp add: del_vert_pos_cards del_vert_remove_sel_1 graph_del_vert remove_sel_sym remove_sel_leq_1 remove_sel_pos query_graph.intro graph_axioms head_del_vert query_graph_axioms_def tail_del_vert) lemma finite_nempty_set_min: assumes "xs \<noteq> {}" and "finite xs" shows "\<exists>x. min_degree xs x" proof - have "finite xs" using assms(2) by simp then show ?thesis using assms proof (induction "xs" rule: finite_induct) case empty then show ?case by simp next case ind: (insert x xs) then show ?case proof(cases xs) case emptyI then show ?thesis by (metis order_refl singletonD singletonI) next case (insertI xs' x') then have "\<exists>a. min_degree xs a" using ind by simp then show ?thesis using ind by (metis order_trans insert_iff le_cases) qed qed qed lemma no_cross_reachable_graph': "\<lbrakk>\<exists>t. relations t = verts G \<and> no_cross_products t; x\<in>verts G; y\<in>verts G\<rbrakk> \<Longrightarrow> x \<rightarrow>\<^sup>*\<^bsub>mk_symmetric G\<^esub> y" by (simp add: reachable_mk_symmetricI reachable_if_no_cross) lemma verts_nempty_if_tree: "\<exists>t. relations t \<subseteq> verts G \<Longrightarrow> verts G \<noteq> {}" using relations_nempty by fast lemma connected_if_tree: "\<exists>t. relations t = verts G \<and> no_cross_products t \<Longrightarrow> connected G" using no_cross_reachable_graph' connected_def strongly_connected_def verts_nempty_if_tree by fastforce end locale nempty_query_graph = query_graph + assumes non_empty: "verts G \<noteq> {}" subsection \<open>Pair Query Graph\<close> text \<open>Alternative definition based on pair graphs\<close> locale pair_query_graph = pair_graph + fixes sel :: "('a \<times> 'a) weight_fun" fixes cf :: "'a \<Rightarrow> real" assumes sel_sym: "\<lbrakk>tail G e\<^sub>1 = head G e\<^sub>2; head G e\<^sub>1 = tail G e\<^sub>2\<rbrakk> \<Longrightarrow> sel e\<^sub>1 = sel e\<^sub>2" and not_arc_sel_1: "e \<notin> parcs G \<Longrightarrow> sel e = 1" and sel_pos: "sel e > 0" and sel_leq_1: "sel e \<le> 1" and pos_cards: "x \<in> pverts G \<Longrightarrow> cf x > 0" sublocale pair_query_graph \<subseteq> query_graph by(unfold_locales) (auto simp: sel_sym not_arc_sel_1 sel_pos sel_leq_1 pos_cards) context pair_query_graph begin lemma "matching_sel f \<longleftrightarrow> (\<forall>x y. sel (x,y) = f x y)" using matching_sel_def sel_sym by fastforce end end
Modern Double Storey House Plans Pdf - for lots, domestic design is an totally daunting manner. realizing during which to start, to not mention selecting something certain or a topic for the entire residence, is a few factor many human beings go away to execs. however, at we've made matters easy; our rooms internet ache helps you to view the bowled over well-liked photos of the day. It additionally acts as a best stage view for the accessible lessons for abode stories and house decor or even where professionals in the united states of the united states are positioned. Are your needs very specific? Do you most suitable precise feelings for sure rooms? nicely, that’s k.
let's be double win. for Embossed Wristband Usb Flash Drive , Embossed Wristband USB Flash Drive , Embossed Silicone Wristband USB Flash Drive , We've been consistently broadening the market within Romania in addition to preparation punching in extra premium quality merchandise connected with printer on t shirt so that you can Romania. Most people firmly believe we've the whole capacity to provide you happy solutions. Our target should be to consolidate and enhance the high quality and service of existing goods, meanwhile frequently develop new products and solutions to fulfill distinct customers' demands for Embossed Wristband Usb Flash Drive , Embossed Wristband USB Flash Drive , Embossed Silicone Wristband USB Flash Drive , The president and all the company members would like to supply professional merchandise and services for customers and sincerely welcome and cooperate with all native and foreign customers for a bright future.
[STATEMENT] lemma exists_reconstruction: "\<exists>h0. irreducible\<^sub>d h0 \<and> p.dvdm u h0 \<and> h0 dvd f" [PROOF STATE] proof (prove) goal (1 subgoal): 1. \<exists>h0. irreducible\<^sub>d h0 \<and> p.dvdm u h0 \<and> h0 dvd f [PROOF STEP] proof - [PROOF STATE] proof (state) goal (1 subgoal): 1. \<exists>h0. irreducible\<^sub>d h0 \<and> p.dvdm u h0 \<and> h0 dvd f [PROOF STEP] have deg_f: "degree f > 0" [PROOF STATE] proof (prove) goal (1 subgoal): 1. 0 < degree f [PROOF STEP] using \<open>n \<equiv> degree f\<close> n0 [PROOF STATE] proof (prove) using this: n \<equiv> degree f 0 < n goal (1 subgoal): 1. 0 < degree f [PROOF STEP] by blast [PROOF STATE] proof (state) this: 0 < degree f goal (1 subgoal): 1. \<exists>h0. irreducible\<^sub>d h0 \<and> p.dvdm u h0 \<and> h0 dvd f [PROOF STEP] from berlekamp_zassenhaus_factorization_irreducible\<^sub>d[OF refl sf_F deg_f] [PROOF STATE] proof (chain) picking this: f = prod_list (berlekamp_zassenhaus_factorization f) \<and> (\<forall>fi\<in>set (berlekamp_zassenhaus_factorization f). irreducible\<^sub>d fi) [PROOF STEP] obtain fs where f_fs: "f = prod_list fs" and c: "(\<forall>fi\<in>set fs. irreducible\<^sub>d fi \<and> 0 < degree fi )" [PROOF STATE] proof (prove) using this: f = prod_list (berlekamp_zassenhaus_factorization f) \<and> (\<forall>fi\<in>set (berlekamp_zassenhaus_factorization f). irreducible\<^sub>d fi) goal (1 subgoal): 1. (\<And>fs. \<lbrakk>f = prod_list fs; \<forall>fi\<in>set fs. irreducible\<^sub>d fi \<and> 0 < degree fi\<rbrakk> \<Longrightarrow> thesis) \<Longrightarrow> thesis [PROOF STEP] by blast [PROOF STATE] proof (state) this: f = prod_list fs \<forall>fi\<in>set fs. irreducible\<^sub>d fi \<and> 0 < degree fi goal (1 subgoal): 1. \<exists>h0. irreducible\<^sub>d h0 \<and> p.dvdm u h0 \<and> h0 dvd f [PROOF STEP] have "pl.dvdm u (prod_list fs)" [PROOF STATE] proof (prove) goal (1 subgoal): 1. pl.dvdm u (prod_list fs) [PROOF STEP] using uf f_fs [PROOF STATE] proof (prove) using this: pl.dvdm u f f = prod_list fs goal (1 subgoal): 1. pl.dvdm u (prod_list fs) [PROOF STEP] by simp [PROOF STATE] proof (state) this: pl.dvdm u (prod_list fs) goal (1 subgoal): 1. \<exists>h0. irreducible\<^sub>d h0 \<and> p.dvdm u h0 \<and> h0 dvd f [PROOF STEP] hence "p.dvdm u (prod_list fs)" [PROOF STATE] proof (prove) using this: pl.dvdm u (prod_list fs) goal (1 subgoal): 1. p.dvdm u (prod_list fs) [PROOF STEP] by (rule pl_dvdm_imp_p_dvdm) [PROOF STATE] proof (state) this: p.dvdm u (prod_list fs) goal (1 subgoal): 1. \<exists>h0. irreducible\<^sub>d h0 \<and> p.dvdm u h0 \<and> h0 dvd f [PROOF STEP] from this [PROOF STATE] proof (chain) picking this: p.dvdm u (prod_list fs) [PROOF STEP] obtain h0 where h0: "h0 \<in> set fs" and dvdm_u_h0: "p.dvdm u h0" [PROOF STATE] proof (prove) using this: p.dvdm u (prod_list fs) goal (1 subgoal): 1. (\<And>h0. \<lbrakk>h0 \<in> set fs; p.dvdm u h0\<rbrakk> \<Longrightarrow> thesis) \<Longrightarrow> thesis [PROOF STEP] using p.irreducible_m_dvdm_prod_list[OF irred_u] [PROOF STATE] proof (prove) using this: p.dvdm u (prod_list fs) p.dvdm u (prod_list ?xs) \<Longrightarrow> \<exists>b\<in>set ?xs. p.dvdm u b goal (1 subgoal): 1. (\<And>h0. \<lbrakk>h0 \<in> set fs; p.dvdm u h0\<rbrakk> \<Longrightarrow> thesis) \<Longrightarrow> thesis [PROOF STEP] by auto [PROOF STATE] proof (state) this: h0 \<in> set fs p.dvdm u h0 goal (1 subgoal): 1. \<exists>h0. irreducible\<^sub>d h0 \<and> p.dvdm u h0 \<and> h0 dvd f [PROOF STEP] moreover [PROOF STATE] proof (state) this: h0 \<in> set fs p.dvdm u h0 goal (1 subgoal): 1. \<exists>h0. irreducible\<^sub>d h0 \<and> p.dvdm u h0 \<and> h0 dvd f [PROOF STEP] have "h0 dvd f" [PROOF STATE] proof (prove) goal (1 subgoal): 1. h0 dvd f [PROOF STEP] by (unfold f_fs, rule prod_list_dvd[OF h0]) [PROOF STATE] proof (state) this: h0 dvd f goal (1 subgoal): 1. \<exists>h0. irreducible\<^sub>d h0 \<and> p.dvdm u h0 \<and> h0 dvd f [PROOF STEP] moreover [PROOF STATE] proof (state) this: h0 dvd f goal (1 subgoal): 1. \<exists>h0. irreducible\<^sub>d h0 \<and> p.dvdm u h0 \<and> h0 dvd f [PROOF STEP] have "irreducible\<^sub>d h0" [PROOF STATE] proof (prove) goal (1 subgoal): 1. irreducible\<^sub>d h0 [PROOF STEP] using c h0 [PROOF STATE] proof (prove) using this: \<forall>fi\<in>set fs. irreducible\<^sub>d fi \<and> 0 < degree fi h0 \<in> set fs goal (1 subgoal): 1. irreducible\<^sub>d h0 [PROOF STEP] by auto [PROOF STATE] proof (state) this: irreducible\<^sub>d h0 goal (1 subgoal): 1. \<exists>h0. irreducible\<^sub>d h0 \<and> p.dvdm u h0 \<and> h0 dvd f [PROOF STEP] ultimately [PROOF STATE] proof (chain) picking this: h0 \<in> set fs p.dvdm u h0 h0 dvd f irreducible\<^sub>d h0 [PROOF STEP] show ?thesis [PROOF STATE] proof (prove) using this: h0 \<in> set fs p.dvdm u h0 h0 dvd f irreducible\<^sub>d h0 goal (1 subgoal): 1. \<exists>h0. irreducible\<^sub>d h0 \<and> p.dvdm u h0 \<and> h0 dvd f [PROOF STEP] by blast [PROOF STATE] proof (state) this: \<exists>h0. irreducible\<^sub>d h0 \<and> p.dvdm u h0 \<and> h0 dvd f goal: No subgoals! [PROOF STEP] qed
function [ readerobj ] = open_palsar2_reader( filename ) %OPEN_PALSAR2_READER Intiates a reader object for ALOS PALSAR 2 dataset % % Handles ALOS PALSAR 2 level 1.1 (SLC) data % % Written by: Wade Schwartzkopf, NGA/R % % ////////////////////////////////////////// % /// CLASSIFICATION: UNCLASSIFIED /// % ////////////////////////////////////////// %% Setup reader filenames = palsar2_files(filename); if any(strcmp(filename, filenames.IMG)) % If a single polarization is passed, only open that polarization. If % a VOL/LED/TRL file is passed, open all polarizations. filenames.IMG = {filename}; end meta_base = struct(); if isfield(filenames,'VOL') meta_base.native.vol = read_ceos_vol_meta(filenames.VOL); meta_base = setstructfields(meta_base, meta2sicd_palsar2vol(meta_base.native.vol)); end if isfield(filenames,'LED') meta_base.native.led = read_ceos_led_meta(filenames.LED); meta_base = setstructfields(meta_base, meta2sicd_palsar2led(meta_base.native.led)); end % Not really anything useful for us in the TRL file, so we skip that one for i = 1:numel(filenames.IMG) img_meta = read_ceos_img_meta(filenames.IMG{i}); datasize{i}=[img_meta.num_pixels img_meta.num_lines]; data_offset{i}=[img_meta.rec_length + img_meta.prefix_bytes... % Byte offset to first data sample img_meta.suffix_bytes + img_meta.prefix_bytes]; % Byte spacing between rows meta{i} = setstructfields(meta_base, meta2sicd_palsar2img(img_meta)); % Much of the useful metadata requires both he LED and IMG files to compute. if isfield(filenames,'LED') meta{i} = setstructfields(meta{i}, ... meta2sicd_palsar2ledimg(meta_base.native.led, img_meta)); % Now that sensor model fields have been populated, we can populate % GeoData.SCP more precisely. ecf = point_image_to_ground([meta{i}.ImageData.SCPPixel.Row;meta{i}.ImageData.SCPPixel.Col],meta{i}); meta{i}.GeoData.SCP.ECF.X=ecf(1); meta{i}.GeoData.SCP.ECF.Y=ecf(2); meta{i}.GeoData.SCP.ECF.Z=ecf(3); llh=ecf_to_geodetic([meta{i}.GeoData.SCP.ECF.X meta{i}.GeoData.SCP.ECF.Y meta{i}.GeoData.SCP.ECF.Z]); meta{i}.GeoData.SCP.LLH.Lat=llh(1); meta{i}.GeoData.SCP.LLH.Lon=llh(2); meta{i}.GeoData.SCP.LLH.HAE=llh(3); end meta{i} = derived_sicd_fields(meta{i}); meta{i}.native.img = img_meta; end % Consolidate polarizations across images pols = cellfun(@(x) x.ImageFormation.TxRcvPolarizationProc, meta, 'UniformOutput', false); tpols = unique(cellfun(@(x) x(1), pols)); for i = 1:numel(filenames.IMG) meta{i}.ImageFormation.RcvChanProc.ChanIndex = i; if isscalar(tpols) meta{i}.RadarCollection.TxPolarization = tpols; else meta{i}.RadarCollection.TxPolarization = 'SEQUENCE'; for j = 1:numel(tpols) meta{i}.RadarCollection.TxSequence.TxStep(j).TxPolarization = tpols(j); end end for j = 1:numel(pols) meta{i}.RadarCollection.RcvChannels(j).ChanParameters.TxRcvPolarization = pols{j}; end end if isfield(meta{1}, 'SCPCOA') && isfield(meta{1}.SCPCOA, 'SideOfTrack') && ... upper(meta{1}.SCPCOA.SideOfTrack(1))=='L' symmetry=[0 1 1]; % PALSAR written in range lines else symmetry=[0 0 1]; % PALSAR written in range lines end if strncmp(img_meta.sar_datatype_code, 'C*8', 3) % Assumes all IMG files are of same type datatype='float32'; complextype=true; else datatype='uint16'; complextype=false; end endian='b'; bands=1; %% Open reader for i = 1:numel(filenames.IMG) readerobj{i}=open_generic_reader(filenames.IMG{i}, datasize{i},... datatype, complextype, data_offset{i}, endian, symmetry, bands); readerobj{i}.get_meta=@() meta{i}; end end % ////////////////////////////////////////// % /// CLASSIFICATION: UNCLASSIFIED /// % //////////////////////////////////////////
#ifndef LOAD_CERTIFICATE_HPP__ #define LOAD_CERTIFICATE_HPP__ #include <boost/asio/ssl/context.hpp> void load_certificate(boost::asio::ssl::context& ctx, const std::string cert_file_name, const std::string key_file_name, boost::system::error_code& ec) noexcept; void load_certificate(boost::asio::ssl::context& ctx, const std::string cert_file_name, const std::string key_file_name); void load_certificate(boost::asio::ssl::context& ctx); #endif /* LOAD_CERTIFICATE_HPP__ */
SUBROUTINE PHO_GETPDF(Npar,Pdfna,Ala,Q2mi,Q2ma,Xmi,Xma) C*************************************************************** C C get PDF information C C input: NPAR 1 first PDF in /POPPDF/ C 2 second PDF in /POPPDF/ C C output: PDFNA name of PDf parametrization C ALA QCD LAMBDA (4 flavours, in GeV) C Q2MI minimal Q2 C Q2MA maximal Q2 C XMI minimal X C XMA maximal X C C*************************************************************** IMPLICIT NONE DOUBLE PRECISION Ala , Q2ma , Q2mi , qini , qmax , value , Xma , & Xmi INTEGER nflav , nloops , Npar SAVE CHARACTER*8 Pdfna CHARACTER*1024 fname C input/output channels INCLUDE 'inc/poinou' C PHOLIB 4.15 common INCLUDE 'inc/w50512' INCLUDE 'inc/w50513' C PHOPDF version 2.0 common INCLUDE 'inc/phcom1' INCLUDE 'inc/phcom2' C currently activated parton density parametrizations INCLUDE 'inc/poppdf' LOGICAL ct14init(3) DATA ct14init/.FALSE. , .FALSE. , .FALSE./ DIMENSION param(20) , value(20) CHARACTER*20 param IF ( (Npar.NE.1) .AND. (Npar.NE.2) ) THEN IF ( LPRi.GT.4 ) WRITE (LO,'(/1X,A,I6)') & 'PHO_GETPDF:ERROR: invalid PDF number (1,2)' , Npar CALL PHO_ABORT END IF Ala = 0.D0 IF ( IEXt(Npar).EQ.0 ) THEN C internal parametrizations IF ( IGRp(Npar).EQ.2 ) THEN IF ( ISEt(Npar).EQ.1 ) THEN IF ( .NOT.ct14init(1) ) THEN fname = DATdir(1:LENdir)//'CT14LL.pds' CALL PHO_SETCT14(fname, LENdir + 10) ct14init(1) = .TRUE. ct14init(2) = .FALSE. ct14init(3) = .FALSE. END IF Pdfna = 'CT14-LO' ELSE IF ( ISEt(Npar).EQ.2 ) THEN IF ( .NOT.ct14init(2) ) THEN fname = DATdir(1:LENdir)//'CT14LN.pds' CALL PHO_SETCT14(fname, LENdir + 10) ct14init(2) = .TRUE. ct14init(1) = .FALSE. ct14init(3) = .FALSE. END IF Pdfna = 'CT14-LLO' ELSE IF ( ISEt(Npar).EQ.3 ) THEN IF ( .NOT.ct14init(3) ) THEN fname = DATdir(1:LENdir)//'CT14nlo_NF4.pds' CALL PHO_SETCT14(fname, LENdir + 15) ct14init(3) = .TRUE. ct14init(1) = .FALSE. ct14init(2) = .FALSE. END IF Pdfna = 'CT14-NLO' END IF CALL PHO_CT14GETPARS(XMIn,qini,qmax,nloops,nflav) Ala = 0.2807 Xmi = XMIn Q2mi = qini**2 Q2ma = qmax**2 ELSE IF ( ITYpe(Npar).EQ.1 ) THEN C proton PDFs IF ( IGRp(Npar).EQ.5 ) THEN IF ( ISEt(Npar).EQ.3 ) THEN Ala = 0.2D0 Q2mi = 0.3D0 Pdfna = 'GRV92 HO' ELSE IF ( ISEt(Npar).EQ.4 ) THEN Ala = 0.2D0 Q2mi = 0.25D0 Pdfna = 'GRV92 LO' ELSE IF ( ISEt(Npar).EQ.5 ) THEN Ala = 0.2D0 Q2mi = 0.4D0 Pdfna = 'GRV94 HO' ELSE IF ( ISEt(Npar).EQ.6 ) THEN Ala = 0.2D0 Q2mi = 0.4D0 Pdfna = 'GRV94 LO' ELSE IF ( ISEt(Npar).EQ.7 ) THEN Ala = 0.2D0 Q2mi = 0.4D0 Pdfna = 'GRV94 DI' ELSE IF ( ISEt(Npar).EQ.8 ) THEN Ala = 0.175D0 Q2mi = 0.8D0 Pdfna = 'GRV98 LO' ELSE IF ( ISEt(Npar).EQ.9 ) THEN Ala = 0.175D0 Q2mi = 0.8D0 Pdfna = 'GRV98 SC' END IF END IF ELSE IF ( ITYpe(Npar).EQ.2 ) THEN C pion PDFs IF ( IGRp(Npar).EQ.5 ) THEN IF ( ISEt(Npar).EQ.1 ) THEN Ala = 0.2D0 Q2mi = 0.3D0 Pdfna = 'GRV-P HO' ELSE IF ( ISEt(Npar).EQ.2 ) THEN Ala = 0.2D0 Q2mi = 0.25D0 Pdfna = 'GRV-PiLO' END IF END IF ELSE IF ( ITYpe(Npar).EQ.3 ) THEN C photon PDFs IF ( IGRp(Npar).EQ.5 ) THEN IF ( ISEt(Npar).EQ.1 ) THEN Ala = 0.2D0 Q2mi = 0.3D0 Pdfna = 'GRV-G LH' ELSE IF ( ISEt(Npar).EQ.2 ) THEN Ala = 0.2D0 Q2mi = 0.3D0 Pdfna = 'GRV-G HO' ELSE IF ( ISEt(Npar).EQ.3 ) THEN Ala = 0.2D0 Q2mi = 0.25D0 Pdfna = 'GRV-G LO' END IF ELSE IF ( IGRp(Npar).EQ.8 ) THEN IF ( ISEt(Npar).EQ.1 ) THEN Ala = 0.2D0 Q2mi = 4.D0 Pdfna = 'AGL-G LO' END IF END IF ELSE IF ( ITYpe(Npar).EQ.20 ) THEN C pomeron PDFs IF ( IGRp(Npar).EQ.4 ) THEN CALL PHO_CKMTPA(990,Xmi,Xma,Ala,Q2mi,Q2ma,Pdfna) ELSE Ala = 0.3D0 Q2mi = 2.D0 Pdfna = 'POM-PDF1' END IF END IF C external parametrizations ELSE IF ( IEXt(Npar).EQ.1 ) THEN C PDFLIB call: old numbering param(1) = 'MODE' param(2) = ' ' value(1) = IGRp(Npar) CALL PDFSET(param,value) Q2mi = Q2Min Q2ma = Q2Max Xmi = XMIn Xma = XMAx Ala = QCDl4 Pdfna = 'PDFLIB1' ELSE IF ( IEXt(Npar).EQ.2 ) THEN C PDFLIB call: new numbering param(1) = 'NPTYPE' param(2) = 'NGROUP' param(3) = 'NSET' param(4) = ' ' value(1) = ITYpe(Npar) value(2) = IGRp(Npar) value(3) = ISEt(Npar) CALL PDFSET(param,value) Q2mi = Q2Min Q2ma = Q2Max Xmi = XMIn Xma = XMAx Ala = QCDl4 Pdfna = 'PDFLIB2' ELSE IF ( IEXt(Npar).EQ.3 ) THEN C PHOLIB interface Ala = ALM(IGRp(Npar),ISEt(Npar)) Q2mi = 2.D0 Pdfna = CHPar(IGRp(Npar)) C some special internal parametrizations ELSE IF ( IEXt(Npar).EQ.4 ) THEN C photon PDFs depending on virtualities IF ( IGRp(Npar).EQ.1 ) THEN C Schuler/Sjostrand parametrization Ala = 0.2D0 IF ( ISEt(Npar).EQ.1 ) THEN Q2mi = 0.2D0 Pdfna = 'SaS-1D ' ELSE IF ( ISEt(Npar).EQ.2 ) THEN Q2mi = 0.2D0 Pdfna = 'SaS-1M ' ELSE IF ( ISEt(Npar).EQ.3 ) THEN Q2mi = 2.D0 Pdfna = 'SaS-2D ' ELSE IF ( ISEt(Npar).EQ.4 ) THEN Q2mi = 2.D0 Pdfna = 'SaS-2M ' END IF ELSE IF ( IGRp(Npar).EQ.5 ) THEN C Gluck/Reya/Stratmann parametrization IF ( ISEt(Npar).EQ.4 ) THEN Ala = 0.2D0 Q2mi = 0.6D0 Pdfna = 'GRS-G LO' END IF END IF ELSE IF ( IEXt(Npar).EQ.5 ) THEN C Schuler/Sjostrand anomalous only Ala = 0.2D0 Q2mi = 0.2D0 Pdfna = 'SaS anom' END IF IF ( Ala.LT.0.01D0 ) THEN IF ( LPRi.GT.4 ) WRITE (LO,'(/1X,2A,/10X,5I6)') & 'PHO_GETPDF:ERROR: ' , & 'unsupported PDF (NPAR,IEXT,ITYPE,IGRP,ISET)' , Npar , & IEXt(Npar) , ITYpe(Npar) , IGRp(Npar) , ISEt(Npar) CALL PHO_ABORT END IF END SUBROUTINE
(* *********************************************************************) (* *) (* 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 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 file is also distributed *) (* under the terms of the INRIA Non-Commercial License Agreement. *) (* *) (* *********************************************************************) (** This file collects a number of definitions and theorems that are used throughout the development. It complements the Coq standard library. *) Require Export ZArith. Require Export Znumtheory. Require Export List. Require Export Bool. Global Set Asymmetric Patterns. (** * Useful tactics *) Ltac inv H := inversion H; clear H; subst. Ltac predSpec pred predspec x y := generalize (predspec x y); case (pred x y); intro. Ltac caseEq name := generalize (refl_equal name); pattern name at -1 in |- *; case name. Ltac destructEq name := destruct name eqn:?. Ltac decEq := match goal with | [ |- _ = _ ] => f_equal | [ |- (?X ?A <> ?X ?B) ] => cut (A <> B); [intro; congruence | try discriminate] end. Ltac byContradiction := cut False; [contradiction|idtac]. Ltac omegaContradiction := cut False; [contradiction|omega]. Lemma modusponens: forall (P Q: Prop), P -> (P -> Q) -> Q. Proof. auto. Qed. Ltac exploit x := (refine (modusponens _ _ (x _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _) _) || refine (modusponens _ _ (x _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _) _) || refine (modusponens _ _ (x _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _) _) || refine (modusponens _ _ (x _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _) _) || refine (modusponens _ _ (x _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _) _) || refine (modusponens _ _ (x _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _) _) || refine (modusponens _ _ (x _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _) _) || refine (modusponens _ _ (x _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _) _) || refine (modusponens _ _ (x _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _) _) || refine (modusponens _ _ (x _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _) _) || refine (modusponens _ _ (x _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _) _) || refine (modusponens _ _ (x _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _) _) || refine (modusponens _ _ (x _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _) _) || refine (modusponens _ _ (x _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _) _) || refine (modusponens _ _ (x _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _) _) || refine (modusponens _ _ (x _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _) _) || refine (modusponens _ _ (x _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _) _) || refine (modusponens _ _ (x _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _) _) || refine (modusponens _ _ (x _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _) _) || refine (modusponens _ _ (x _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _) _) || refine (modusponens _ _ (x _ _ _ _ _ _ _ _ _ _ _ _ _ _ _) _) || refine (modusponens _ _ (x _ _ _ _ _ _ _ _ _ _ _ _ _ _) _) || refine (modusponens _ _ (x _ _ _ _ _ _ _ _ _ _ _ _ _) _) || refine (modusponens _ _ (x _ _ _ _ _ _ _ _ _ _ _ _) _) || refine (modusponens _ _ (x _ _ _ _ _ _ _ _ _ _ _) _) || refine (modusponens _ _ (x _ _ _ _ _ _ _ _ _ _) _) || refine (modusponens _ _ (x _ _ _ _ _ _ _ _ _) _) || refine (modusponens _ _ (x _ _ _ _ _ _ _ _) _) || refine (modusponens _ _ (x _ _ _ _ _ _ _) _) || refine (modusponens _ _ (x _ _ _ _ _ _) _) || refine (modusponens _ _ (x _ _ _ _ _) _) || refine (modusponens _ _ (x _ _ _ _) _) || refine (modusponens _ _ (x _ _ _) _) || refine (modusponens _ _ (x _ _) _) || refine (modusponens _ _ (x _) _)). (** * Definitions and theorems over the type [positive] *) Definition peq: forall (x y: positive), {x = y} + {x <> y} := Pos.eq_dec. Global Opaque peq. Lemma peq_true: forall (A: Type) (x: positive) (a b: A), (if peq x x then a else b) = a. Proof. intros. case (peq x x); intros. auto. elim n; auto. Qed. Lemma peq_false: forall (A: Type) (x y: positive) (a b: A), x <> y -> (if peq x y then a else b) = b. Proof. intros. case (peq x y); intros. elim H; auto. auto. Qed. Definition Plt: positive -> positive -> Prop := Pos.lt. Lemma Plt_ne: forall (x y: positive), Plt x y -> x <> y. Proof. unfold Plt; intros. red; intro. subst y. eelim Pos.lt_irrefl; eauto. Qed. Hint Resolve Plt_ne: coqlib. Lemma Plt_trans: forall (x y z: positive), Plt x y -> Plt y z -> Plt x z. Proof (Pos.lt_trans). Lemma Plt_succ: forall (x: positive), Plt x (Psucc x). Proof. unfold Plt; intros. apply Pos.lt_succ_r. apply Pos.le_refl. Qed. Hint Resolve Plt_succ: coqlib. Lemma Plt_trans_succ: forall (x y: positive), Plt x y -> Plt x (Psucc y). Proof. intros. apply Plt_trans with y. assumption. apply Plt_succ. Qed. Hint Resolve Plt_succ: coqlib. Lemma Plt_succ_inv: forall (x y: positive), Plt x (Psucc y) -> Plt x y \/ x = y. Proof. unfold Plt; intros. rewrite Pos.lt_succ_r in H. apply Pos.le_lteq; auto. Qed. Definition plt (x y: positive) : {Plt x y} + {~ Plt x y}. Proof. unfold Plt, Pos.lt; intros. destruct (Pos.compare x y). - right; congruence. - left; auto. - right; congruence. Defined. Global Opaque plt. Definition Ple: positive -> positive -> Prop := Pos.le. Lemma Ple_refl: forall (p: positive), Ple p p. Proof (Pos.le_refl). Lemma Ple_trans: forall (p q r: positive), Ple p q -> Ple q r -> Ple p r. Proof (Pos.le_trans). Lemma Plt_Ple: forall (p q: positive), Plt p q -> Ple p q. Proof (Pos.lt_le_incl). Lemma Ple_succ: forall (p: positive), Ple p (Psucc p). Proof. intros. apply Plt_Ple. apply Plt_succ. Qed. Lemma Plt_Ple_trans: forall (p q r: positive), Plt p q -> Ple q r -> Plt p r. Proof (Pos.lt_le_trans). Lemma Plt_strict: forall p, ~ Plt p p. Proof (Pos.lt_irrefl). Hint Resolve Ple_refl Plt_Ple Ple_succ Plt_strict: coqlib. Ltac xomega := unfold Plt, Ple in *; zify; omega. Ltac xomegaContradiction := exfalso; xomega. (** Peano recursion over positive numbers. *) Section POSITIVE_ITERATION. Lemma Plt_wf: well_founded Plt. Proof. apply well_founded_lt_compat with nat_of_P. intros. apply nat_of_P_lt_Lt_compare_morphism. exact H. Qed. Variable A: Type. Variable v1: A. Variable f: positive -> A -> A. Lemma Ppred_Plt: forall x, x <> xH -> Plt (Ppred x) x. Proof. intros. elim (Psucc_pred x); intro. contradiction. set (y := Ppred x) in *. rewrite <- H0. apply Plt_succ. Qed. Let iter (x: positive) (P: forall y, Plt y x -> A) : A := match peq x xH with | left EQ => v1 | right NOTEQ => f (Ppred x) (P (Ppred x) (Ppred_Plt x NOTEQ)) end. Definition positive_rec : positive -> A := Fix Plt_wf (fun _ => A) iter. Lemma unroll_positive_rec: forall x, positive_rec x = iter x (fun y _ => positive_rec y). Proof. unfold positive_rec. apply (Fix_eq Plt_wf (fun _ => A) iter). intros. unfold iter. case (peq x 1); intro. auto. decEq. apply H. Qed. Lemma positive_rec_base: positive_rec 1%positive = v1. Proof. rewrite unroll_positive_rec. unfold iter. case (peq 1 1); intro. auto. elim n; auto. Qed. Lemma positive_rec_succ: forall x, positive_rec (Psucc x) = f x (positive_rec x). Proof. intro. rewrite unroll_positive_rec. unfold iter. case (peq (Psucc x) 1); intro. destruct x; simpl in e; discriminate. rewrite Ppred_succ. auto. Qed. Lemma positive_Peano_ind: forall (P: positive -> Prop), P xH -> (forall x, P x -> P (Psucc x)) -> forall x, P x. Proof. intros. apply (well_founded_ind Plt_wf P). intros. case (peq x0 xH); intro. subst x0; auto. elim (Psucc_pred x0); intro. contradiction. rewrite <- H2. apply H0. apply H1. apply Ppred_Plt. auto. Qed. End POSITIVE_ITERATION. (** * Definitions and theorems over the type [Z] *) Definition zeq: forall (x y: Z), {x = y} + {x <> y} := Z.eq_dec. Lemma zeq_true: forall (A: Type) (x: Z) (a b: A), (if zeq x x then a else b) = a. Proof. intros. case (zeq x x); intros. auto. elim n; auto. Qed. Lemma zeq_false: forall (A: Type) (x y: Z) (a b: A), x <> y -> (if zeq x y then a else b) = b. Proof. intros. case (zeq x y); intros. elim H; auto. auto. Qed. Open Scope Z_scope. Definition zlt: forall (x y: Z), {x < y} + {x >= y} := Z_lt_dec. Lemma zlt_true: forall (A: Type) (x y: Z) (a b: A), x < y -> (if zlt x y then a else b) = a. Proof. intros. case (zlt x y); intros. auto. omegaContradiction. Qed. Lemma zlt_false: forall (A: Type) (x y: Z) (a b: A), x >= y -> (if zlt x y then a else b) = b. Proof. intros. case (zlt x y); intros. omegaContradiction. auto. Qed. Definition zle: forall (x y: Z), {x <= y} + {x > y} := Z_le_gt_dec. Lemma zle_true: forall (A: Type) (x y: Z) (a b: A), x <= y -> (if zle x y then a else b) = a. Proof. intros. case (zle x y); intros. auto. omegaContradiction. Qed. Lemma zle_false: forall (A: Type) (x y: Z) (a b: A), x > y -> (if zle x y then a else b) = b. Proof. intros. case (zle x y); intros. omegaContradiction. auto. Qed. (** Properties of powers of two. *) Lemma two_power_nat_O : two_power_nat O = 1. Proof. reflexivity. Qed. Lemma two_power_nat_pos : forall n : nat, two_power_nat n > 0. Proof. induction n. rewrite two_power_nat_O. omega. rewrite two_power_nat_S. omega. Qed. Lemma two_power_nat_two_p: forall x, two_power_nat x = two_p (Z_of_nat x). Proof. induction x. auto. rewrite two_power_nat_S. rewrite inj_S. rewrite two_p_S. omega. omega. Qed. Lemma two_p_monotone: forall x y, 0 <= x <= y -> two_p x <= two_p y. Proof. intros. replace (two_p x) with (two_p x * 1) by omega. replace y with (x + (y - x)) by omega. rewrite two_p_is_exp; try omega. apply Zmult_le_compat_l. assert (two_p (y - x) > 0). apply two_p_gt_ZERO. omega. omega. assert (two_p x > 0). apply two_p_gt_ZERO. omega. omega. Qed. Lemma two_p_monotone_strict: forall x y, 0 <= x < y -> two_p x < two_p y. Proof. intros. assert (two_p x <= two_p (y - 1)). apply two_p_monotone; omega. assert (two_p (y - 1) > 0). apply two_p_gt_ZERO. omega. replace y with (Zsucc (y - 1)) by omega. rewrite two_p_S. omega. omega. Qed. Lemma two_p_strict: forall x, x >= 0 -> x < two_p x. Proof. intros x0 GT. pattern x0. apply natlike_ind. simpl. omega. intros. rewrite two_p_S; auto. generalize (two_p_gt_ZERO x H). omega. omega. Qed. Lemma two_p_strict_2: forall x, x >= 0 -> 2 * x - 1 < two_p x. Proof. intros. assert (x = 0 \/ x - 1 >= 0) by omega. destruct H0. subst. vm_compute. auto. replace (two_p x) with (2 * two_p (x - 1)). generalize (two_p_strict _ H0). omega. rewrite <- two_p_S. decEq. omega. omega. Qed. (** Properties of [Zmin] and [Zmax] *) Lemma Zmin_spec: forall x y, Zmin x y = if zlt x y then x else y. Proof. intros. case (zlt x y); unfold Zlt, Zge; intro z. unfold Zmin. rewrite z. auto. unfold Zmin. caseEq (x ?= y); intro. apply Zcompare_Eq_eq. auto. contradiction. reflexivity. Qed. Lemma Zmax_spec: forall x y, Zmax x y = if zlt y x then x else y. Proof. intros. case (zlt y x); unfold Zlt, Zge; intro z. unfold Zmax. rewrite <- (Zcompare_antisym y x). rewrite z. simpl. auto. unfold Zmax. rewrite <- (Zcompare_antisym y x). caseEq (y ?= x); intro; simpl. symmetry. apply Zcompare_Eq_eq. auto. contradiction. reflexivity. Qed. Lemma Zmax_bound_l: forall x y z, x <= y -> x <= Zmax y z. Proof. intros. generalize (Zmax1 y z). omega. Qed. Lemma Zmax_bound_r: forall x y z, x <= z -> x <= Zmax y z. Proof. intros. generalize (Zmax2 y z). omega. Qed. (** Properties of Euclidean division and modulus. *) Lemma Zdiv_small: forall x y, 0 <= x < y -> x / y = 0. Proof. intros. assert (y > 0). omega. assert (forall a b, 0 <= a < y -> 0 <= y * b + a < y -> b = 0). intros. assert (b = 0 \/ b > 0 \/ (-b) > 0). omega. elim H3; intro. auto. elim H4; intro. assert (y * b >= y * 1). apply Zmult_ge_compat_l. omega. omega. omegaContradiction. assert (y * (-b) >= y * 1). apply Zmult_ge_compat_l. omega. omega. rewrite <- Zopp_mult_distr_r in H6. omegaContradiction. apply H1 with (x mod y). apply Z_mod_lt. auto. rewrite <- Z_div_mod_eq. auto. auto. Qed. Lemma Zmod_small: forall x y, 0 <= x < y -> x mod y = x. Proof. intros. assert (y > 0). omega. generalize (Z_div_mod_eq x y H0). rewrite (Zdiv_small x y H). omega. Qed. Lemma Zmod_unique: forall x y a b, x = a * y + b -> 0 <= b < y -> x mod y = b. Proof. intros. subst x. rewrite Zplus_comm. rewrite Z_mod_plus. apply Zmod_small. auto. omega. Qed. Lemma Zdiv_unique: forall x y a b, x = a * y + b -> 0 <= b < y -> x / y = a. Proof. intros. subst x. rewrite Zplus_comm. rewrite Z_div_plus. rewrite (Zdiv_small b y H0). omega. omega. Qed. Lemma Zdiv_Zdiv: forall a b c, b > 0 -> c > 0 -> (a / b) / c = a / (b * c). Proof. intros. generalize (Z_div_mod_eq a b H). generalize (Z_mod_lt a b H). intros. generalize (Z_div_mod_eq (a/b) c H0). generalize (Z_mod_lt (a/b) c H0). intros. set (q1 := a / b) in *. set (r1 := a mod b) in *. set (q2 := q1 / c) in *. set (r2 := q1 mod c) in *. symmetry. apply Zdiv_unique with (r2 * b + r1). rewrite H2. rewrite H4. ring. split. assert (0 <= r2 * b). apply Zmult_le_0_compat. omega. omega. omega. assert ((r2 + 1) * b <= c * b). apply Zmult_le_compat_r. omega. omega. replace ((r2 + 1) * b) with (r2 * b + b) in H5 by ring. replace (c * b) with (b * c) in H5 by ring. omega. Qed. Lemma Zmult_le_compat_l_neg : forall n m p:Z, n >= m -> p <= 0 -> p * n <= p * m. Proof. intros. assert ((-p) * n >= (-p) * m). apply Zmult_ge_compat_l. auto. omega. replace (p * n) with (- ((-p) * n)) by ring. replace (p * m) with (- ((-p) * m)) by ring. omega. Qed. Lemma Zdiv_interval_1: forall lo hi a b, lo <= 0 -> hi > 0 -> b > 0 -> lo * b <= a < hi * b -> lo <= a/b < hi. Proof. intros. generalize (Z_div_mod_eq a b H1). generalize (Z_mod_lt a b H1). intros. set (q := a/b) in *. set (r := a mod b) in *. split. assert (lo < (q + 1)). apply Zmult_lt_reg_r with b. omega. apply Zle_lt_trans with a. omega. replace ((q + 1) * b) with (b * q + b) by ring. omega. omega. apply Zmult_lt_reg_r with b. omega. replace (q * b) with (b * q) by ring. omega. Qed. Lemma Zdiv_interval_2: forall lo hi a b, lo <= a <= hi -> lo <= 0 -> hi >= 0 -> b > 0 -> lo <= a/b <= hi. Proof. intros. assert (lo <= a / b < hi+1). apply Zdiv_interval_1. omega. omega. auto. assert (lo * b <= lo * 1). apply Zmult_le_compat_l_neg. omega. omega. replace (lo * 1) with lo in H3 by ring. assert ((hi + 1) * 1 <= (hi + 1) * b). apply Zmult_le_compat_l. omega. omega. replace ((hi + 1) * 1) with (hi + 1) in H4 by ring. omega. omega. Qed. Lemma Zmod_recombine: forall x a b, a > 0 -> b > 0 -> x mod (a * b) = ((x/b) mod a) * b + (x mod b). Proof. intros. set (xb := x/b). apply Zmod_unique with (xb/a). generalize (Z_div_mod_eq x b H0); fold xb; intro EQ1. generalize (Z_div_mod_eq xb a H); intro EQ2. rewrite EQ2 in EQ1. eapply trans_eq. eexact EQ1. ring. generalize (Z_mod_lt x b H0). intro. generalize (Z_mod_lt xb a H). intro. assert (0 <= xb mod a * b <= a * b - b). split. apply Zmult_le_0_compat; omega. replace (a * b - b) with ((a - 1) * b) by ring. apply Zmult_le_compat; omega. omega. Qed. (** Properties of divisibility. *) Lemma Zdivides_trans: forall x y z, (x | y) -> (y | z) -> (x | z). Proof. intros x y z [a A] [b B]; subst. exists (a*b); ring. Qed. Definition Zdivide_dec: forall (p q: Z), p > 0 -> { (p|q) } + { ~(p|q) }. Proof. intros. destruct (zeq (Zmod q p) 0). left. exists (q / p). transitivity (p * (q / p) + (q mod p)). apply Z_div_mod_eq; auto. transitivity (p * (q / p)). omega. ring. right; red; intros. elim n. apply Z_div_exact_1; auto. inv H0. rewrite Z_div_mult; auto. ring. Defined. Global Opaque Zdivide_dec. Lemma Zdivide_interval: forall a b c, 0 < c -> 0 <= a < b -> (c | a) -> (c | b) -> 0 <= a <= b - c. Proof. intros. destruct H1 as [x EQ1]. destruct H2 as [y EQ2]. subst. destruct H0. split. omega. exploit Zmult_lt_reg_r; eauto. intros. replace (y * c - c) with ((y - 1) * c) by ring. apply Zmult_le_compat_r; omega. Qed. (** Conversion from [Z] to [nat]. *) Definition nat_of_Z: Z -> nat := Z.to_nat. Lemma nat_of_Z_of_nat: forall n, nat_of_Z (Z_of_nat n) = n. Proof. exact Nat2Z.id. Qed. Lemma nat_of_Z_max: forall z, Z_of_nat (nat_of_Z z) = Zmax z 0. Proof. intros. unfold Zmax. destruct z; simpl; auto. change (Z.of_nat (Z.to_nat (Zpos p)) = Zpos p). apply Z2Nat.id. compute; intuition congruence. Qed. Lemma nat_of_Z_eq: forall z, z >= 0 -> Z_of_nat (nat_of_Z z) = z. Proof. unfold nat_of_Z; intros. apply Z2Nat.id. omega. Qed. Lemma nat_of_Z_neg: forall n, n <= 0 -> nat_of_Z n = O. Proof. destruct n; unfold Zle; simpl; auto. congruence. Qed. Lemma nat_of_Z_plus: forall p q, p >= 0 -> q >= 0 -> nat_of_Z (p + q) = (nat_of_Z p + nat_of_Z q)%nat. Proof. unfold nat_of_Z; intros. apply Z2Nat.inj_add; omega. Qed. (** Alignment: [align n amount] returns the smallest multiple of [amount] greater than or equal to [n]. *) Definition align (n: Z) (amount: Z) := ((n + amount - 1) / amount) * amount. Lemma align_le: forall x y, y > 0 -> x <= align x y. Proof. intros. unfold align. generalize (Z_div_mod_eq (x + y - 1) y H). intro. replace ((x + y - 1) / y * y) with ((x + y - 1) - (x + y - 1) mod y). generalize (Z_mod_lt (x + y - 1) y H). omega. rewrite Zmult_comm. omega. Qed. Lemma align_divides: forall x y, y > 0 -> (y | align x y). Proof. intros. unfold align. apply Zdivide_factor_l. Qed. (** * Definitions and theorems on the data types [option], [sum] and [list] *) Set Implicit Arguments. (** Comparing option types. *) Definition option_eq (A: Type) (eqA: forall (x y: A), {x=y} + {x<>y}): forall (x y: option A), {x=y} + {x<>y}. Proof. decide equality. Defined. Global Opaque option_eq. (** Mapping a function over an option type. *) Definition option_map (A B: Type) (f: A -> B) (x: option A) : option B := match x with | None => None | Some y => Some (f y) end. (** Mapping a function over a sum type. *) Definition sum_left_map (A B C: Type) (f: A -> B) (x: A + C) : B + C := match x with | inl y => inl C (f y) | inr z => inr B z end. (** Properties of [List.nth] (n-th element of a list). *) Hint Resolve in_eq in_cons: coqlib. Lemma nth_error_in: forall (A: Type) (n: nat) (l: list A) (x: A), List.nth_error l n = Some x -> In x l. Proof. induction n; simpl. destruct l; intros. discriminate. injection H; intro; subst a. apply in_eq. destruct l; intros. discriminate. apply in_cons. auto. Qed. Hint Resolve nth_error_in: coqlib. Lemma nth_error_nil: forall (A: Type) (idx: nat), nth_error (@nil A) idx = None. Proof. induction idx; simpl; intros; reflexivity. Qed. Hint Resolve nth_error_nil: coqlib. (** Compute the length of a list, with result in [Z]. *) Fixpoint list_length_z_aux (A: Type) (l: list A) (acc: Z) {struct l}: Z := match l with | nil => acc | hd :: tl => list_length_z_aux tl (Zsucc acc) end. Remark list_length_z_aux_shift: forall (A: Type) (l: list A) n m, list_length_z_aux l n = list_length_z_aux l m + (n - m). Proof. induction l; intros; simpl. omega. replace (n - m) with (Zsucc n - Zsucc m) by omega. auto. Qed. Definition list_length_z (A: Type) (l: list A) : Z := list_length_z_aux l 0. Lemma list_length_z_cons: forall (A: Type) (hd: A) (tl: list A), list_length_z (hd :: tl) = list_length_z tl + 1. Proof. intros. unfold list_length_z. simpl. rewrite (list_length_z_aux_shift tl 1 0). omega. Qed. Lemma list_length_z_pos: forall (A: Type) (l: list A), list_length_z l >= 0. Proof. induction l; simpl. unfold list_length_z; simpl. omega. rewrite list_length_z_cons. omega. Qed. Lemma list_length_z_map: forall (A B: Type) (f: A -> B) (l: list A), list_length_z (map f l) = list_length_z l. Proof. induction l. reflexivity. simpl. repeat rewrite list_length_z_cons. congruence. Qed. (** Extract the n-th element of a list, as [List.nth_error] does, but the index [n] is of type [Z]. *) Fixpoint list_nth_z (A: Type) (l: list A) (n: Z) {struct l}: option A := match l with | nil => None | hd :: tl => if zeq n 0 then Some hd else list_nth_z tl (Zpred n) end. Lemma list_nth_z_in: forall (A: Type) (l: list A) n x, list_nth_z l n = Some x -> In x l. Proof. induction l; simpl; intros. congruence. destruct (zeq n 0). left; congruence. right; eauto. Qed. Lemma list_nth_z_map: forall (A B: Type) (f: A -> B) (l: list A) n, list_nth_z (List.map f l) n = option_map f (list_nth_z l n). Proof. induction l; simpl; intros. auto. destruct (zeq n 0). auto. eauto. Qed. Lemma list_nth_z_range: forall (A: Type) (l: list A) n x, list_nth_z l n = Some x -> 0 <= n < list_length_z l. Proof. induction l; simpl; intros. discriminate. rewrite list_length_z_cons. destruct (zeq n 0). generalize (list_length_z_pos l); omega. exploit IHl; eauto. omega. Qed. (** Properties of [List.incl] (list inclusion). *) Lemma incl_cons_inv: forall (A: Type) (a: A) (b c: list A), incl (a :: b) c -> incl b c. Proof. unfold incl; intros. apply H. apply in_cons. auto. Qed. Hint Resolve incl_cons_inv: coqlib. Lemma incl_app_inv_l: forall (A: Type) (l1 l2 m: list A), incl (l1 ++ l2) m -> incl l1 m. Proof. unfold incl; intros. apply H. apply in_or_app. left; assumption. Qed. Lemma incl_app_inv_r: forall (A: Type) (l1 l2 m: list A), incl (l1 ++ l2) m -> incl l2 m. Proof. unfold incl; intros. apply H. apply in_or_app. right; assumption. Qed. Hint Resolve incl_tl incl_refl incl_app_inv_l incl_app_inv_r: coqlib. Lemma incl_same_head: forall (A: Type) (x: A) (l1 l2: list A), incl l1 l2 -> incl (x::l1) (x::l2). Proof. intros; red; simpl; intros. intuition. Qed. (** Properties of [List.map] (mapping a function over a list). *) Lemma list_map_exten: forall (A B: Type) (f f': A -> B) (l: list A), (forall x, In x l -> f x = f' x) -> List.map f' l = List.map f l. Proof. induction l; simpl; intros. reflexivity. rewrite <- H. rewrite IHl. reflexivity. intros. apply H. tauto. tauto. Qed. Lemma list_map_compose: forall (A B C: Type) (f: A -> B) (g: B -> C) (l: list A), List.map g (List.map f l) = List.map (fun x => g(f x)) l. Proof. induction l; simpl. reflexivity. rewrite IHl; reflexivity. Qed. Lemma list_map_identity: forall (A: Type) (l: list A), List.map (fun (x:A) => x) l = l. Proof. induction l; simpl; congruence. Qed. Lemma list_map_nth: forall (A B: Type) (f: A -> B) (l: list A) (n: nat), nth_error (List.map f l) n = option_map f (nth_error l n). Proof. induction l; simpl; intros. repeat rewrite nth_error_nil. reflexivity. destruct n; simpl. reflexivity. auto. Qed. Lemma list_length_map: forall (A B: Type) (f: A -> B) (l: list A), List.length (List.map f l) = List.length l. Proof. induction l; simpl; congruence. Qed. Lemma list_in_map_inv: forall (A B: Type) (f: A -> B) (l: list A) (y: B), In y (List.map f l) -> exists x:A, y = f x /\ In x l. Proof. induction l; simpl; intros. contradiction. elim H; intro. exists a; intuition auto. generalize (IHl y H0). intros [x [EQ IN]]. exists x; tauto. Qed. Lemma list_append_map: forall (A B: Type) (f: A -> B) (l1 l2: list A), List.map f (l1 ++ l2) = List.map f l1 ++ List.map f l2. Proof. induction l1; simpl; intros. auto. rewrite IHl1. auto. Qed. Lemma list_append_map_inv: forall (A B: Type) (f: A -> B) (m1 m2: list B) (l: list A), List.map f l = m1 ++ m2 -> exists l1, exists l2, List.map f l1 = m1 /\ List.map f l2 = m2 /\ l = l1 ++ l2. Proof. induction m1; simpl; intros. exists (@nil A); exists l; auto. destruct l; simpl in H; inv H. exploit IHm1; eauto. intros [l1 [l2 [P [Q R]]]]. subst l. exists (a0 :: l1); exists l2; intuition. simpl; congruence. Qed. (** Folding a function over a list *) Section LIST_FOLD. Variables A B: Type. Variable f: A -> B -> B. (** This is exactly [List.fold_left] from Coq's standard library, with [f] taking arguments in a different order. *) Fixpoint list_fold_left (accu: B) (l: list A) : B := match l with nil => accu | x :: l' => list_fold_left (f x accu) l' end. (** This is exactly [List.fold_right] from Coq's standard library, except that it runs in constant stack space. *) Definition list_fold_right (l: list A) (base: B) : B := list_fold_left base (List.rev' l). Remark list_fold_left_app: forall l1 l2 accu, list_fold_left accu (l1 ++ l2) = list_fold_left (list_fold_left accu l1) l2. Proof. induction l1; simpl; intros. auto. rewrite IHl1. auto. Qed. Lemma list_fold_right_eq: forall l base, list_fold_right l base = match l with nil => base | x :: l' => f x (list_fold_right l' base) end. Proof. unfold list_fold_right; intros. destruct l. auto. unfold rev'. rewrite <- ! rev_alt. simpl. rewrite list_fold_left_app. simpl. auto. Qed. Lemma list_fold_right_spec: forall l base, list_fold_right l base = List.fold_right f base l. Proof. induction l; simpl; intros; rewrite list_fold_right_eq; congruence. Qed. End LIST_FOLD. (** Properties of list membership. *) Lemma in_cns: forall (A: Type) (x y: A) (l: list A), In x (y :: l) <-> y = x \/ In x l. Proof. intros. simpl. tauto. Qed. Lemma in_app: forall (A: Type) (x: A) (l1 l2: list A), In x (l1 ++ l2) <-> In x l1 \/ In x l2. Proof. intros. split; intro. apply in_app_or. auto. apply in_or_app. auto. Qed. Lemma list_in_insert: forall (A: Type) (x: A) (l1 l2: list A) (y: A), In x (l1 ++ l2) -> In x (l1 ++ y :: l2). Proof. intros. apply in_or_app; simpl. elim (in_app_or _ _ _ H); intro; auto. Qed. (** [list_disjoint l1 l2] holds iff [l1] and [l2] have no elements in common. *) Definition list_disjoint (A: Type) (l1 l2: list A) : Prop := forall (x y: A), In x l1 -> In y l2 -> x <> y. Lemma list_disjoint_cons_l: forall (A: Type) (a: A) (l1 l2: list A), list_disjoint l1 l2 -> ~In a l2 -> list_disjoint (a :: l1) l2. Proof. unfold list_disjoint; simpl; intros. destruct H1. congruence. apply H; auto. Qed. Lemma list_disjoint_cons_r: forall (A: Type) (a: A) (l1 l2: list A), list_disjoint l1 l2 -> ~In a l1 -> list_disjoint l1 (a :: l2). Proof. unfold list_disjoint; simpl; intros. destruct H2. congruence. apply H; auto. Qed. Lemma list_disjoint_cons_left: forall (A: Type) (a: A) (l1 l2: list A), list_disjoint (a :: l1) l2 -> list_disjoint l1 l2. Proof. unfold list_disjoint; simpl; intros. apply H; tauto. Qed. Lemma list_disjoint_cons_right: forall (A: Type) (a: A) (l1 l2: list A), list_disjoint l1 (a :: l2) -> list_disjoint l1 l2. Proof. unfold list_disjoint; simpl; intros. apply H; tauto. Qed. Lemma list_disjoint_notin: forall (A: Type) (l1 l2: list A) (a: A), list_disjoint l1 l2 -> In a l1 -> ~(In a l2). Proof. unfold list_disjoint; intros; red; intros. apply H with a a; auto. Qed. Lemma list_disjoint_sym: forall (A: Type) (l1 l2: list A), list_disjoint l1 l2 -> list_disjoint l2 l1. Proof. unfold list_disjoint; intros. apply sym_not_equal. apply H; auto. Qed. Lemma list_disjoint_dec: forall (A: Type) (eqA_dec: forall (x y: A), {x=y} + {x<>y}) (l1 l2: list A), {list_disjoint l1 l2} + {~list_disjoint l1 l2}. Proof. induction l1; intros. left; red; intros. elim H. case (In_dec eqA_dec a l2); intro. right; red; intro. apply (H a a); auto with coqlib. case (IHl1 l2); intro. left; red; intros. elim H; intro. red; intro; subst a y. contradiction. apply l; auto. right; red; intros. elim n0. eapply list_disjoint_cons_left; eauto. Defined. (** [list_equiv l1 l2] holds iff the lists [l1] and [l2] contain the same elements. *) Definition list_equiv (A : Type) (l1 l2: list A) : Prop := forall x, In x l1 <-> In x l2. (** [list_norepet l] holds iff the list [l] contains no repetitions, i.e. no element occurs twice. *) Inductive list_norepet (A: Type) : list A -> Prop := | list_norepet_nil: list_norepet nil | list_norepet_cons: forall hd tl, ~(In hd tl) -> list_norepet tl -> list_norepet (hd :: tl). Lemma list_norepet_dec: forall (A: Type) (eqA_dec: forall (x y: A), {x=y} + {x<>y}) (l: list A), {list_norepet l} + {~list_norepet l}. Proof. induction l. left; constructor. destruct IHl. case (In_dec eqA_dec a l); intro. right. red; intro. inversion H. contradiction. left. constructor; auto. right. red; intro. inversion H. contradiction. Defined. Lemma list_map_norepet: forall (A B: Type) (f: A -> B) (l: list A), list_norepet l -> (forall x y, In x l -> In y l -> x <> y -> f x <> f y) -> list_norepet (List.map f l). Proof. induction 1; simpl; intros. constructor. constructor. red; intro. generalize (list_in_map_inv f _ _ H2). intros [x [EQ IN]]. generalize EQ. change (f hd <> f x). apply H1. tauto. tauto. red; intro; subst x. contradiction. apply IHlist_norepet. intros. apply H1. tauto. tauto. auto. Qed. Remark list_norepet_append_commut: forall (A: Type) (a b: list A), list_norepet (a ++ b) -> list_norepet (b ++ a). Proof. intro A. assert (forall (x: A) (b: list A) (a: list A), list_norepet (a ++ b) -> ~(In x a) -> ~(In x b) -> list_norepet (a ++ x :: b)). induction a; simpl; intros. constructor; auto. inversion H. constructor. red; intro. elim (in_app_or _ _ _ H6); intro. elim H4. apply in_or_app. tauto. elim H7; intro. subst a. elim H0. left. auto. elim H4. apply in_or_app. tauto. auto. induction a; simpl; intros. rewrite <- app_nil_end. auto. inversion H0. apply H. auto. red; intro; elim H3. apply in_or_app. tauto. red; intro; elim H3. apply in_or_app. tauto. Qed. Lemma list_norepet_app: forall (A: Type) (l1 l2: list A), list_norepet (l1 ++ l2) <-> list_norepet l1 /\ list_norepet l2 /\ list_disjoint l1 l2. Proof. induction l1; simpl; intros; split; intros. intuition. constructor. red;simpl;auto. tauto. inversion H; subst. rewrite IHl1 in H3. rewrite in_app in H2. intuition. constructor; auto. red; intros. elim H2; intro. congruence. auto. destruct H as [B [C D]]. inversion B; subst. constructor. rewrite in_app. intuition. elim (D a a); auto. apply in_eq. rewrite IHl1. intuition. red; intros. apply D; auto. apply in_cons; auto. Qed. Lemma list_norepet_append: forall (A: Type) (l1 l2: list A), list_norepet l1 -> list_norepet l2 -> list_disjoint l1 l2 -> list_norepet (l1 ++ l2). Proof. generalize list_norepet_app; firstorder. Qed. Lemma list_norepet_append_right: forall (A: Type) (l1 l2: list A), list_norepet (l1 ++ l2) -> list_norepet l2. Proof. generalize list_norepet_app; firstorder. Qed. Lemma list_norepet_append_left: forall (A: Type) (l1 l2: list A), list_norepet (l1 ++ l2) -> list_norepet l1. Proof. generalize list_norepet_app; firstorder. Qed. (** [is_tail l1 l2] holds iff [l2] is of the form [l ++ l1] for some [l]. *) Inductive is_tail (A: Type): list A -> list A -> Prop := | is_tail_refl: forall c, is_tail c c | is_tail_cons: forall i c1 c2, is_tail c1 c2 -> is_tail c1 (i :: c2). Lemma is_tail_in: forall (A: Type) (i: A) c1 c2, is_tail (i :: c1) c2 -> In i c2. Proof. induction c2; simpl; intros. inversion H. inversion H. tauto. right; auto. Qed. Lemma is_tail_cons_left: forall (A: Type) (i: A) c1 c2, is_tail (i :: c1) c2 -> is_tail c1 c2. Proof. induction c2; intros; inversion H. constructor. constructor. constructor. auto. Qed. Hint Resolve is_tail_refl is_tail_cons is_tail_in is_tail_cons_left: coqlib. Lemma is_tail_incl: forall (A: Type) (l1 l2: list A), is_tail l1 l2 -> incl l1 l2. Proof. induction 1; eauto with coqlib. Qed. Lemma is_tail_trans: forall (A: Type) (l1 l2: list A), is_tail l1 l2 -> forall (l3: list A), is_tail l2 l3 -> is_tail l1 l3. Proof. induction 1; intros. auto. apply IHis_tail. eapply is_tail_cons_left; eauto. Qed. (** [list_forall2 P [x1 ... xN] [y1 ... yM]] holds iff [N = M] and [P xi yi] holds for all [i]. *) Section FORALL2. Variable A: Type. Variable B: Type. Variable P: A -> B -> Prop. Inductive list_forall2: list A -> list B -> Prop := | list_forall2_nil: list_forall2 nil nil | list_forall2_cons: forall a1 al b1 bl, P a1 b1 -> list_forall2 al bl -> list_forall2 (a1 :: al) (b1 :: bl). Lemma list_forall2_app: forall a2 b2 a1 b1, list_forall2 a1 b1 -> list_forall2 a2 b2 -> list_forall2 (a1 ++ a2) (b1 ++ b2). Proof. induction 1; intros; simpl. auto. constructor; auto. Qed. Lemma list_forall2_length: forall l1 l2, list_forall2 l1 l2 -> length l1 = length l2. Proof. induction 1; simpl; congruence. Qed. End FORALL2. Lemma list_forall2_imply: forall (A B: Type) (P1: A -> B -> Prop) (l1: list A) (l2: list B), list_forall2 P1 l1 l2 -> forall (P2: A -> B -> Prop), (forall v1 v2, In v1 l1 -> In v2 l2 -> P1 v1 v2 -> P2 v1 v2) -> list_forall2 P2 l1 l2. Proof. induction 1; intros. constructor. constructor. auto with coqlib. apply IHlist_forall2; auto. intros. auto with coqlib. Qed. (** Dropping the first N elements of a list. *) Fixpoint list_drop (A: Type) (n: nat) (x: list A) {struct n} : list A := match n with | O => x | S n' => match x with nil => nil | hd :: tl => list_drop n' tl end end. Lemma list_drop_incl: forall (A: Type) (x: A) n (l: list A), In x (list_drop n l) -> In x l. Proof. induction n; simpl; intros. auto. destruct l; auto with coqlib. Qed. Lemma list_drop_norepet: forall (A: Type) n (l: list A), list_norepet l -> list_norepet (list_drop n l). Proof. induction n; simpl; intros. auto. inv H. constructor. auto. Qed. Lemma list_map_drop: forall (A B: Type) (f: A -> B) n (l: list A), list_drop n (map f l) = map f (list_drop n l). Proof. induction n; simpl; intros. auto. destruct l; simpl; auto. Qed. (** A list of [n] elements, all equal to [x]. *) Fixpoint list_repeat {A: Type} (n: nat) (x: A) {struct n} := match n with | O => nil | S m => x :: list_repeat m x end. Lemma length_list_repeat: forall (A: Type) n (x: A), length (list_repeat n x) = n. Proof. induction n; simpl; intros. auto. decEq; auto. Qed. Lemma in_list_repeat: forall (A: Type) n (x: A) y, In y (list_repeat n x) -> y = x. Proof. induction n; simpl; intros. elim H. destruct H; auto. Qed. (** * Definitions and theorems over boolean types *) Definition proj_sumbool (P Q: Prop) (a: {P} + {Q}) : bool := if a then true else false. Implicit Arguments proj_sumbool [P Q]. Coercion proj_sumbool: sumbool >-> bool. Lemma proj_sumbool_true: forall (P Q: Prop) (a: {P}+{Q}), proj_sumbool a = true -> P. Proof. intros P Q a. destruct a; simpl. auto. congruence. Qed. Lemma proj_sumbool_is_true: forall (P: Prop) (a: {P}+{~P}), P -> proj_sumbool a = true. Proof. intros. unfold proj_sumbool. destruct a. auto. contradiction. Qed. Ltac InvBooleans := match goal with | [ H: _ && _ = true |- _ ] => destruct (andb_prop _ _ H); clear H; InvBooleans | [ H: _ || _ = false |- _ ] => destruct (orb_false_elim _ _ H); clear H; InvBooleans | [ H: proj_sumbool ?x = true |- _ ] => generalize (proj_sumbool_true _ H); clear H; intro; InvBooleans | _ => idtac end. Section DECIDABLE_EQUALITY. Variable A: Type. Variable dec_eq: forall (x y: A), {x=y} + {x<>y}. Variable B: Type. Lemma dec_eq_true: forall (x: A) (ifso ifnot: B), (if dec_eq x x then ifso else ifnot) = ifso. Proof. intros. destruct (dec_eq x x). auto. congruence. Qed. Lemma dec_eq_false: forall (x y: A) (ifso ifnot: B), x <> y -> (if dec_eq x y then ifso else ifnot) = ifnot. Proof. intros. destruct (dec_eq x y). congruence. auto. Qed. Lemma dec_eq_sym: forall (x y: A) (ifso ifnot: B), (if dec_eq x y then ifso else ifnot) = (if dec_eq y x then ifso else ifnot). Proof. intros. destruct (dec_eq x y). subst y. rewrite dec_eq_true. auto. rewrite dec_eq_false; auto. Qed. End DECIDABLE_EQUALITY. Section DECIDABLE_PREDICATE. Variable P: Prop. Variable dec: {P} + {~P}. Variable A: Type. Lemma pred_dec_true: forall (a b: A), P -> (if dec then a else b) = a. Proof. intros. destruct dec. auto. contradiction. Qed. Lemma pred_dec_false: forall (a b: A), ~P -> (if dec then a else b) = b. Proof. intros. destruct dec. contradiction. auto. Qed. End DECIDABLE_PREDICATE. (** * Well-founded orderings *) Require Import Relations. (** A non-dependent version of lexicographic ordering. *) Section LEX_ORDER. Variable A: Type. Variable B: Type. Variable ordA: A -> A -> Prop. Variable ordB: B -> B -> Prop. Inductive lex_ord: A*B -> A*B -> Prop := | lex_ord_left: forall a1 b1 a2 b2, ordA a1 a2 -> lex_ord (a1,b1) (a2,b2) | lex_ord_right: forall a b1 b2, ordB b1 b2 -> lex_ord (a,b1) (a,b2). Lemma wf_lex_ord: well_founded ordA -> well_founded ordB -> well_founded lex_ord. Proof. intros Awf Bwf. assert (forall a, Acc ordA a -> forall b, Acc ordB b -> Acc lex_ord (a, b)). induction 1. induction 1. constructor; intros. inv H3. apply H0. auto. apply Bwf. apply H2; auto. red; intros. destruct a as [a b]. apply H; auto. Qed. Lemma transitive_lex_ord: transitive _ ordA -> transitive _ ordB -> transitive _ lex_ord. Proof. intros trA trB; red; intros. inv H; inv H0. left; eapply trA; eauto. left; auto. left; auto. right; eapply trB; eauto. Qed. End LEX_ORDER.
/- Copyright (c) 2022 Yaël Dillies. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yaël Dillies -/ import group_theory.group_action.defs /-! # Sum instances for additive and multiplicative actions This file defines instances for additive and multiplicative actions on the binary `sum` type. ## See also * `group_theory.group_action.pi` * `group_theory.group_action.prod` * `group_theory.group_action.sigma` -/ variables {M N P α β γ : Type*} namespace sum section has_scalar variables [has_scalar M α] [has_scalar M β] [has_scalar N α] [has_scalar N β] (a : M) (b : α) (c : β) (x : α ⊕ β) @[to_additive sum.has_vadd] instance : has_scalar M (α ⊕ β) := ⟨λ a, sum.map ((•) a) ((•) a)⟩ @[to_additive] lemma smul_def : a • x = x.map ((•) a) ((•) a) := rfl @[simp, to_additive] lemma smul_inl : a • (inl b : α ⊕ β) = inl (a • b) := rfl @[simp, to_additive] lemma smul_inr : a • (inr c : α ⊕ β) = inr (a • c) := rfl @[simp, to_additive] lemma smul_swap : (a • x).swap = a • x.swap := by cases x; refl instance [has_scalar M N] [is_scalar_tower M N α] [is_scalar_tower M N β] : is_scalar_tower M N (α ⊕ β) := ⟨λ a b x, by { cases x, exacts [congr_arg inl (smul_assoc _ _ _), congr_arg inr (smul_assoc _ _ _)] }⟩ @[to_additive] instance [smul_comm_class M N α] [smul_comm_class M N β] : smul_comm_class M N (α ⊕ β) := ⟨λ a b x, by { cases x, exacts [congr_arg inl (smul_comm _ _ _), congr_arg inr (smul_comm _ _ _)] }⟩ instance [has_scalar Mᵐᵒᵖ α] [has_scalar Mᵐᵒᵖ β] [is_central_scalar M α] [is_central_scalar M β] : is_central_scalar M (α ⊕ β) := ⟨λ a x, by { cases x, exacts [congr_arg inl (op_smul_eq_smul _ _), congr_arg inr (op_smul_eq_smul _ _)] }⟩ @[to_additive] instance has_faithful_smul_left [has_faithful_smul M α] : has_faithful_smul M (α ⊕ β) := ⟨λ x y h, eq_of_smul_eq_smul $ λ a : α, by injection h (inl a)⟩ @[to_additive] instance has_faithful_smul_right [has_faithful_smul M β] : has_faithful_smul M (α ⊕ β) := ⟨λ x y h, eq_of_smul_eq_smul $ λ b : β, by injection h (inr b)⟩ end has_scalar @[to_additive] instance {m : monoid M} [mul_action M α] [mul_action M β] : mul_action M (α ⊕ β) := { mul_smul := λ a b x, by { cases x, exacts [congr_arg inl (mul_smul _ _ _), congr_arg inr (mul_smul _ _ _)] }, one_smul := λ x, by { cases x, exacts [congr_arg inl (one_smul _ _), congr_arg inr (one_smul _ _)] } } end sum