Datasets:
AI4M
/

text
stringlengths
0
3.34M
The George has yet to supply us with with a public email address. You can telephone them on 020 7607 3625 (please mention Fluid London when calling). A link to The George on Fluid London has been sent. Edit the information we hold on The George or learn about upgrading today.
C$$$ SUBPROGRAM DOCUMENTATION BLOCK C . . . . C SUBPROGRAM: W3ERSUNB DECODES SINGLE ERS RPT FROM BUFR MESSAGES C PRGMMR: KEYSER ORG: NP22 DATE: 1999-01-20 C C ABSTRACT: THIS SUBROUTINE DECODES A SINGLE ERS SCATTEROMETER REPORT C FROM BUFR MESSAGES IN A SEQUENTIAL DATA FILE. REPORT IS RETURNED C IN THE FORMAT DESCRIBED IN THE REMARKS 4. PROCESSES ONLY EDITION C 2 OR GREATER MESSAGES. C C PROGRAM HISTORY LOG: C 1998-02-17 KEYSER -- ORIGINAL AUTHOR C 1998-06-15 D. A. KEYSER -- REDEFINED UNITS FOR UNPACKED WORDS 1 C (LATITUDE), 2 (LONGITUDE), 4 (OBS. TIME) AND 11 C (RECEIPT TIME) - ALL TO CONFORM WITH UNPACKED IW3UNPBF C FORMAT AND TO STREAMLINE PROCESSING IN PREPDATA PROGRAM C 1998-09-21 D. A. KEYSER -- SUBROUTINE NOW Y2K AND FORTRAN 90 C COMPLIANT C 1998-10-09 D. A. KEYSER -- ADDED SECONDS TO DECODED REPORT DATE C (ONLY USED IN PRINTS OF REPORT DATE) C 1999-01-20 D. A. KEYSER -- INCORPORATED BOB KISTLER'S CHANGES NEEDED C TO PORT THE CODE TO THE IBM SP C C USAGE: CALL W3ERSUNB(IDATE,IHE,IHL,INDTA,INTBB,INTBD,RDATA,STNID, C $ IRET) C INPUT ARGUMENT LIST: C IDATE - 4-WORD ARRAY HOLDING "CENTRAL" DATE TO PROCESS C - (YYYY, MM, DD, HH) C IHE - NUMBER OF WHOLE HOURS RELATIVE TO "IDATE" FOR DATE OF C - EARLIEST BUFR MESSAGE THAT IS TO BE DECODED; EARLIEST C - DATE IS "IDATE" + "IHE" HOURS (IF "IHE" IS POSITIVE, C - LATEST MESSAGE DATE IS AFTER "IDATE"; IF "IHE" IS C - NEGATIVE LATEST MESSAGE DATE IS PRIOR TO "IDATE") C - EXAMPLE: IF IHE=1, THEN EARLIEST DATE IS 1-HR AFTER C - IDATE; IF IHE=-3, THEN EARLIEST DATE IS 3-HR PRIOR C - TO IDATE C IHL - NUMBER OF WHOLE HOURS RELATIVE TO "IDATE" FOR DATE OF C - LATEST BUFR MESSAGE THAT IS TO BE DECODED; LATEST C - DATE IS "IDATE" + ("IHL" HOURS PLUS 59 MIN) IF "IHL" C - IS POSITIVE (LATEST MESSAGE DATE IS AFTER "IDATE"), C - AND "IDATE" + ("IHL"+1 HOURS MINUS 1 MIN) IF "IHL" C - IS NEGATIVE (LATEST MESSAGE DATE IS PRIOR TO "IDATE") C - EXAMPLE: IF IHL=3, THEN LATEST DATE IS 3-HR 59-MIN C - AFTER IDATE; IF IHL=-2, THEN LATEST DATE IS 1-HR 1-MIN C - PRIOR TO IDATE C INDTA - FORTRAN UNIT NUMBER FOR INPUT DATA FILE C INTBB - FORTRAN UNIT NUMBER FOR BUFR TABLE B FILE C INTBD - FORTRAN UNIT NUMBER FOR BUFR TABLE D FILE C IRET - CONTROLS DEGREE OF UNIT 6 PRINTOUT (.GE. 0 -LIMITED C - PRINTOUT; = -1 SOME ADDITIONAL DIAGNOSTIC PRINTOUT; C = .LT. -1 -EXTENSIVE PRINTOUT) (SEE REMARKS 3.) C C OUTPUT ARGUMENT LIST: C RDATA - SINGLE REPORT RETURNED THE FORMAT DESCRIBED IN THE C - REMARKS 4 SECTION OF THIS DOCBLOCK (MUST BE C - DIMENSIONED TO AT LEAST 14 WORDS BY CALLING PROGRAM) C - (NOTE: DOES NOT INCLUDE STATION ID) C STNID - CHARACTER*8 SINGLE REPORT STATION IDENTIFICATION (UP C - TO 8 CHARACTERS, LEFT-JUSTIFIED) C IRET - RETURN CODE AS FOLLOWS: C IRET = 0 ---> REPORT SUCCESSFULLY RETURNED C IRET > 0 ---> NO REPORT RETURNED DUE TO: C = 1 ---> ALL REPORTS READ IN, END C = 2 ---> EITHER LAT AND/OR LON DESCRIPTOR NOT FOUND, OR C LAT AND/OR LON DATA MISSING C = 3 ---> EITHER SOME/ALL DESCRIPTORS FOR DATE INFORMATION C NOT FOUND, OR SOME/ALL DATE INFORMATION MISSING C C INPUT FILES: C UNIT AA - (WHERE AA IS INDTA ABOVE) FILE HOLDING THE DATA IN C - THE FORM OF SEQUENTIAL RECORDS CONTAINING BUFR MSGS C UNIT BB - (WHERE BB IS INTBB ABOVE) BUFR TABLE B C UNIT CC - (WHERE CC IS INTBD ABOVE) BUFR TABLE D C C OUTPUT FILES: C UNIT 06 - PRINTOUT C C SUBPROGRAMS CALLED: C UNIQUE - ERSUNB01 ERSUNB02 ERSUNB03 ERSUNB04 C LIBRARY: C COMMON - EXIT C W3LIB - W3FI04 W3FI88 W3MOVDAT W3DIFDAT C - GBYTE GBYTES C C REMARKS: 1) A CONDITION CODE (STOP) OF 15 WILL OCCUR IF THE INPUT C DATES FOR START AND/OR STOP TIME ARE SPECIFIED INCORRECTLY. C 2) A CONDITION CODE (STOP) OF 22 WILL OCCUR IF THE C CHARACTERS ON THIS MACHINE ARE NEITHER ASCII NOR EBCDIC. C 3) THE INPUT ARGUMENT "IRET" SHOULD BE SET PRIOR TO EACH C CALL TO THIS SUBROUTINE. C C *************************************************************** C 4) C BELOW IS THE FORMAT OF AN UNPACKED REPORT IN OUTPUT ARRAY RDATA C (EACH WORD REPRESENTS A FULL-WORD ACCORDING TO THE MACHINE) C (NOTE: DOES NOT INCLUDE STATION IDENTIFICATION - SEE OUTPUT C ARGUMENT "STNID" ABOVE) C *************************************************************** C CXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX C FORMAT FOR ERS SCATTEROMETER REPORTS CXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX C HEADER C WORD CONTENT UNIT FORMAT C ---- ---------------------- ------------------- --------- C 1 LATITUDE DEGREES (N+,S-) REAL C 2 LONGITUDE DEGREES EAST REAL C 3 NOT USED ZEROED C 4 OBSERVATION TIME HOURS (UTC) REAL C 5 YEAR/MONTH YYYYMM INTEGER C 6 DAY/HOUR DDHH INTEGER C 7 STATION ELEVATION 10 METERS (CONSTANT) REAL C 8 INSTRUMENT TYPE 99 (MISSING) INTEGER C 9 REPORT TYPE 581 (CONSTANT) INTEGER C 10 NOT USED ZEROED C 11 RECEIPT TIME HOURS (UTC) REAL C 12 NOT USED ZEROED C LEFT-JUSTIFIED C 13 HORIZ. WIND DIRECTION DEGREES REAL C 14 HORIZ. WIND SPEED 0.1 METERS/REC REAL C C MISSING VALUES ARE: C 99999. FOR REAL C 99999 FOR INTEGER (EXCEPT FOR WORDS 5 AND 6, WHERE C MISSING IS 999999) CXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX C C ATTRIBUTES: C LANGUAGE: FORTRAN 90 C MACHINE: IBM-SP, CRAY, SGI C C$$$ SUBROUTINE W3ERSUNB(IDATE,IHE,IHL,INDTA,INTBB,INTBD,RDATA,STNID, $ IRET) C PARAMETER "MAXD" IS THE NUMBER OF EXPANDED DESCRIPTORS C NEEDED TO CONTAIN A SINGLE REPORT (MAXIMUM = 25 FOR ERS C SCATTEROMETER REPORTS) C PARAMETER "MAXR" IS THE NUMBER OF SUBSETS IN A SINGLE BUFR MESSAGE C (MAXIMUM = 500 FOR ERS SCATTEROMETER REPORTS) C PARAMETER "MAXL" IS THE SIZE NEEDED FOR THE ILOC AND SC ARRAYS FOR A C SINGLE REPORT (MAXIMUM = 25 FOR ERS SCATTEROMETER REPORTS) PARAMETER (MAXD = 25, MAXR = 500, MAXL = 25) INTEGER IDATE(4),LSDATE(4),IDATA(14),IPTR(45) INTEGER JDATE(8),K1DATE(8),L1DATE(8) CHARACTER*8 STNID DIMENSION RINC(5) REAL RDATA(*),RDATX(14) COMMON /ERSUBB/IST,KDATE(8),LDATE(8),MSTACK(2,MAXD), $ KDATA(MAXR,MAXD),IPRINT COMMON /ERSUCC/INDEX,ILOC(MAXL),SC(MAXL) cTEMP############# c note: currently the date in sec. 1 appears to be garbage, so we must c date check each individual report here COMMON/TMPTIM/IYEAR,IMNTH,IDAY,IHOUR,IMIN,ISEC cTEMP############# C SAVE C EQUIVALENCE(RDATX,IDATA) DATA ITM/0/,INDTAL/-99/,KOUNT/0/ cTEMP############# c note: currently the date in sec. 1 appears to be garbage, so we must c date check each individual report here DATA ITCNT/0/ cTEMP############# IPRINT = 0 write(*,*) 'Sorry missing date routines, cannot run' iret = 1 RETURN END
lemma lipschitz_on_id [lipschitz_intros]: "1-lipschitz_on U (\<lambda>x. x)"
If a polynomial $p$ divides $1$, then the fractional polynomial $p$ divides $1$.
{-# OPTIONS --without-K #-} module PathStructure.Nat where open import Equivalence open import PathOperations open import Types F : ℕ → ℕ → Set F = ind (λ _ → ℕ → Set) (λ _ r → ind (λ _ → Set) (λ n-1 _ → r n-1) ⊥) ( ind (λ _ → Set) (λ _ _ → ⊥) ⊤) F-lemma : ∀ n → F n n F-lemma = ind (λ n → F n n) (λ _ f → f) _ -- Explicit arguments to prevent code littered with curly brackets. split-path : ∀ x y → x ≡ y → F x y split-path x _ p = tr (F x) p (F-lemma x) merge-path : ∀ x y → F x y → x ≡ y merge-path _ _ f = ind (λ x → ∀ y → F x y → x ≡ y) (λ x r → ind (λ y → F (suc x) y → suc x ≡ y) (λ _ _ f → ap suc (r _ f)) 0-elim) (ind (λ y → F zero y → zero ≡ y) (λ _ _ → 0-elim) (λ _ → refl)) _ _ f -- Lemmas. ap-refl : ∀ {n} (p : n ≡ n) → p ≡ refl → ap suc p ≡ refl ap-refl _ = J (λ p q _ → J (λ x y _ → suc x ≡ suc y) (λ _ → refl) _ _ p ≡ ap suc q) (λ _ → refl) _ refl tr-ap : ∀ m n (f : F m n) → tr (F (suc m)) (ap suc (merge-path m n f)) (F-lemma (suc m)) ≡ tr (F (suc m) ∘ suc) (merge-path m n f) (F-lemma (suc m)) tr-ap m n f = J (λ x y p → tr (F (suc x)) (ap suc p) (F-lemma (suc x)) ≡ tr (F (suc x) ∘ suc) p (F-lemma (suc x))) (λ _ → refl) _ _ (merge-path m n f) split-merge-eq : ∀ {x y} → (x ≡ y) ≃ F x y split-merge-eq {x = x} {y = y} = split-path _ _ , (merge-path _ _ , λ f → ind (λ x → ∀ y (f : F x y) → split-path x y (merge-path x y f) ≡ f) (λ x r → ind (λ y → (f : F (suc x) y) → split-path (suc x) y (merge-path (suc x) y f) ≡ f) (λ y _ f → tr-ap x y f · r y f) (λ b → 0-elim b)) (ind (λ y → (f : F zero y) → split-path zero y (merge-path zero y f) ≡ f) (λ _ _ b → 0-elim b) (λ _ → refl)) x y f) , (merge-path _ _ , J (λ _ _ p → merge-path _ _ (split-path _ _ p) ≡ p) (ind (λ x → merge-path x x (split-path x x refl) ≡ refl) (λ _ → ap-refl _) refl) _ _)
INTERFACE OPERATOR(**) END INTERFACE OPERATOR(**) INTERFACE OPERATOR(*) END INTERFACE OPERATOR(*) INTERFACE OPERATOR(*) END INTERFACE OPERATOR(*) INTERFACE OPERATOR(/) END INTERFACE OPERATOR(/) INTERFACE OPERATOR(+) END INTERFACE OPERATOR(+) INTERFACE OPERATOR(-) END INTERFACE OPERATOR(-) INTERFACE OPERATOR(==) END INTERFACE OPERATOR(==) INTERFACE OPERATOR(//) END INTERFACE OPERATOR(//) INTERFACE OPERATOR(==) END INTERFACE OPERATOR(==) INTERFACE OPERATOR(/=) END INTERFACE OPERATOR(/=) INTERFACE OPERATOR(<) END INTERFACE OPERATOR(<) INTERFACE OPERATOR(<=) END INTERFACE OPERATOR(<=) INTERFACE OPERATOR(>) END INTERFACE OPERATOR(>) INTERFACE OPERATOR(>=) END INTERFACE OPERATOR(>=) INTERFACE OPERATOR(.NOT.) END INTERFACE OPERATOR(.NOT.) INTERFACE OPERATOR(.AND.) END INTERFACE OPERATOR(.AND.) INTERFACE OPERATOR(.OR.) END INTERFACE OPERATOR(.OR.) INTERFACE OPERATOR(.EQV.) END INTERFACE OPERATOR(.EQV.) INTERFACE OPERATOR(.NEQV.) END INTERFACE OPERATOR(.NEQV.) END PROGRAM
From Tealeaves Require Import Categories.TypeFamilies Classes.EqDec_eq Classes.Monoid Classes.Functor Classes.Applicative Data.Product Functors.Writer. Import TypeFamilies.Notations. Import Product.Notations. Import Monoid.Notations. #[local] Generalizable Variables A B C F G ϕ W T. (** * Multisorted DTM typeclass *) (**************************************************************) Section MultisortedDTM_typeclasses. Context `{ix : Index}. (** ** Operations *) (**************************************************************) Section operations. Context (W : Type) (T : K -> Type -> Type) (S : Type -> Type). Class MReturn := mret : forall (A : Type) (k : K), A -> T k A. Class MBind := mbinddt : forall (F : Type -> Type) `{Fmap F} `{Pure F} `{Mult F} {A B : Type}, (forall (k : K), W * A -> F (T k B)) -> S A -> F (S B). End operations. (** ** Definition of Kleisli composition *) (******************************************************************************) Definition compose_dtm {W : Type} {T : K -> Type -> Type} `{mn_op : Monoid_op W} `{mn_unit : Monoid_unit W} `{Fmap F} `{Mult F} `{Pure F} `{Fmap G} `{Mult G} `{Pure G} `{forall k, MBind W T (T k)} {A B C : Type} (g : forall k, W * B -> G (T k C)) (f : forall k, W * A -> F (T k B)) : forall k, W * A -> F (G (T k C)) := fun (k : K) '(w, a) => fmap F (mbinddt W T (T k) G (g ◻ const (incr w))) (f k (w, a)). Infix "⋆dtm" := compose_dtm (at level 40) : tealeaves_scope. Section compose_dtm_lemmas. Context (W : Type) (S : Type -> Type) (T : K -> Type -> Type) `{! MReturn T} `{! MBind W T S} `{! forall k, MBind W T (T k)} {mn_op : Monoid_op W} {mn_unit : Monoid_unit W}. Context `{Applicative G} `{Applicative F} `{! Monoid W} {A B C : Type} (g : forall k, W * B -> G (T k C)) (f : forall k, W * A -> F (T k B)). Lemma compose_dtm_incr : forall (w : W), (fun k => (g ⋆dtm f) k ∘ incr w) = ((fun k => g k ∘ incr w) ⋆dtm (fun k => f k ∘ incr w)). Proof. intros. ext k [w' a]. cbn. do 2 fequal. ext j [w'' b]. unfold compose. cbn. fequal. now rewrite monoid_assoc. Qed. End compose_dtm_lemmas. (** ** Decorated traversable premodule typeclass *) (******************************************************************************) Section PreModule. Context (W : Type) (S : Type -> Type) (T : K -> Type -> Type) `{! MReturn T} `{! MBind W T S} `{! forall k, MBind W T (T k)} {mn_op : Monoid_op W} {mn_unit : Monoid_unit W}. Class DTPreModule := { dtp_monoid :> Monoid W; dtp_mbinddt_mret : forall A, mbinddt W T S (fun a => a) (mret T A ◻ const (extract (W ×))) = @id (S A); dtp_mbinddt_mbinddt : forall (F : Type -> Type) (G : Type -> Type) `{Applicative F} `{Applicative G} `(g : forall k, W * B -> G (T k C)) `(f : forall k, W * A -> F (T k B)), fmap F (mbinddt W T S G g) ∘ mbinddt W T S F f = mbinddt W T S (F ∘ G) (g ⋆dtm f); dtp_mbinddt_morphism : forall (F : Type -> Type) (G : Type -> Type) `{ApplicativeMorphism F G ϕ} `(f : forall k, W * A -> F (T k B)), ϕ (S B) ∘ mbinddt W T S F f = mbinddt W T S G (fun k => ϕ (T k B) ∘ f k); }. End PreModule. (** ** Decorated traversable monad *) (******************************************************************************) Section DTM. Context (W : Type) (T : K -> Type -> Type) `{! MReturn T} `{! forall k, MBind W T (T k)} {mn_op : Monoid_op W} {mn_unit : Monoid_unit W}. Class DTM := { dtm_pre :> forall k, DTPreModule W (T k) T; dtm_mbinddt_comp_mret : forall k F `{Applicative F} `(f : forall k, W * A -> F (T k B)), mbinddt W T (T k) F f ∘ mret T A k = (fun a => f k (Ƶ, a)); }. End DTM. End MultisortedDTM_typeclasses. Arguments mret {ix} _%function_scope {MReturn} {A}%type_scope _ _. Arguments mbinddt {ix} {W}%type_scope {T} (S)%function_scope {MBind} F%function_scope {H H0 H1} {A B}. (** ** Derived operations on DTMs *) (******************************************************************************) Section derived_operations. Context (S : Type -> Type) `{DTPreModule W S T}. (** *** Definitions *) (******************************************************************************) Section definitions. Context {A B : Type} (F : Type -> Type) `{Fmap F} `{Mult F} `{Pure F}. Definition mbindd (f : forall k, W * A -> T k B) : S A -> S B := mbinddt S (fun x => x) f. Definition mfmapdt (f : forall k, W * A -> F B) : S A -> F (S B) := mbinddt S F (fun k => fmap F (mret T k) ∘ f k). Definition mbindt (f : forall k, A -> F (T k B)) : S A -> F (S B) := mbinddt S F (f ◻ const (extract (W ×))). Definition mbind (f : forall k, A -> T k B) : S A -> S B := mbindd (f ◻ const (extract (W ×))). Definition mfmapd (f : forall k, W * A -> B) : S A -> S B := mbindd (fun k => mret T k ∘ f k). Definition mfmapt (f : forall k, A -> F B) : S A -> F (S B) := mbindt (fun k => fmap F (mret T k) ∘ f k). Definition mfmap (f : forall k, A -> B) : S A -> S B := mfmapd (f ◻ const (extract (W ×))). End definitions. Section special_cases. Context {A B : Type} (F : Type -> Type) `{Fmap F} `{Mult F} `{Pure F}. (** *** Rewriting rules for special cases of <<mbinddt>> *) (******************************************************************************) Lemma mbindt_to_mbinddt (f : forall k, A -> F (T k B)): mbindt F f = mbinddt S F (f ◻ const (extract (W ×))). Proof. reflexivity. Qed. Lemma mbindd_to_mbinddt (f : forall k, W * A -> T k B): mbindd f = mbinddt S (fun A => A) f. Proof. reflexivity. Qed. Lemma mfmapdt_to_mbinddt (f : K -> W * A -> F B): mfmapdt F f = mbinddt S F (fun k => fmap F (mret T k) ∘ f k). Proof. reflexivity. Qed. Lemma mbind_to_mbinddt (f : forall k, A -> T k B): mbind f = mbinddt S (fun A => A) (f ◻ const (extract (W ×))). Proof. reflexivity. Qed. Lemma mfmapd_to_mbinddt (f : K -> W * A -> B): mfmapd f = mbinddt S (fun A => A) (mret T ◻ f). Proof. reflexivity. Qed. Lemma mfmapt_to_mbinddt (f : K -> A -> F B): mfmapt F f = mbinddt S F (fun k => fmap F (mret T k) ∘ f k ∘ extract (W ×)). Proof. reflexivity. Qed. Lemma mfmap_to_mbinddt (f : K -> A -> B): mfmap f = mbinddt S (fun A => A) (mret T ◻ f ◻ const (extract (W ×))). Proof. reflexivity. Qed. (** *** Rewriting rules for special cases of <<mbindt>> *) (******************************************************************************) Lemma mbind_to_mbindt (f : forall k, A -> T k B): mbind f = mbindt (fun A => A) f. Proof. reflexivity. Qed. Lemma mfmapt_to_mbindt (f : K -> A -> F B): mfmapt F f = mbindt F (fun k => fmap F (mret T k) ∘ f k). Proof. reflexivity. Qed. Lemma mfmap_to_mbindt (f : K -> A -> B): mfmap f = mbindt (fun A => A) (mret T ◻ f). Proof. reflexivity. Qed. (** *** Rewriting rules for special cases of <<mbindd>> *) (******************************************************************************) Lemma mbind_to_mbindd (f : forall k, A -> T k B): mbind f = mbindd (f ◻ const (extract (W ×))). Proof. reflexivity. Qed. Lemma mfmapd_to_mbindd (f : W * A -k-> B): mfmapd f = mbindd (mret T ◻ f). Proof. reflexivity. Qed. Lemma mfmap_to_mbindd (f : A -k-> B): mfmap f = mbindd (mret T ◻ f ◻ const (extract (W ×))). Proof. reflexivity. Qed. (** *** Special cases of <<mfmapdt>> *) (******************************************************************************) Lemma mfmapd_to_mfmapdt (f : K -> W * A -> B): mfmapd f = mfmapdt (fun A => A) f. Proof. reflexivity. Qed. Lemma mfmap_to_mfmapdt (f : K -> A -> B): mfmap f = mfmapdt (fun A => A) (f ◻ const (extract (W ×))). Proof. reflexivity. Qed. Lemma mfmapt_to_mfmapdt (f : K -> A -> F B): mfmapt F f = mfmapdt F (f ◻ const (extract (W ×))). Proof. reflexivity. Qed. (** *** Special cases of <<mfmapt>> *) (******************************************************************************) Lemma mfmap_to_mfmapt (f : K -> A -> B): mfmap f = mfmapt (fun A => A) f. Proof. reflexivity. Qed. (** *** Special cases of <<mfmapd>> *) (******************************************************************************) Lemma mfmap_to_mfmapd (f : K -> A -> B): mfmap f = mfmapd (f ◻ const (extract (W ×))). Proof. reflexivity. Qed. (** *** Special cases of <<mbind>> *) (******************************************************************************) Lemma mfmap_to_mbind (f : K -> A -> B): mfmap f = mbind (mret T ◻ f). Proof. reflexivity. Qed. End special_cases. End derived_operations. (** ** Composition between <<mbinddt>> and special cases operations *) (** Fusion laws for compositions of the form <<mbinddt ∘ xxx>> or <<xxx ∘ mbinddt>> *) (******************************************************************************) Section derived_operations_composition. Context (S : Type -> Type) `{DTPreModule W S T} `{! DTM W T} `{Applicative F} `{Applicative G} {A B C : Type}. (** *** <<mbinddt>> on the right *) (******************************************************************************) Lemma mbindd_mbinddt: forall (g : forall k, W * B -> T k C) (f : forall k, W * A -> F (T k B)), fmap F (mbindd S g) ∘ mbinddt S F f = mbinddt S F (fun k '(w, a) => fmap F (mbindd (T k) (g ◻ const (incr w))) (f k (w, a))). Proof. intros. rewrite mbindd_to_mbinddt. rewrite (dtp_mbinddt_mbinddt W S T F (fun A => A)). fequal. now rewrite Mult_compose_identity1. Qed. Lemma mfmapdt_mbinddt: forall (g : K -> W * B -> G C) (f : forall k, W * A -> F (T k B)), fmap F (mfmapdt S G g) ∘ mbinddt S F f = mbinddt S (F ∘ G) (fun k '(w, a) => fmap F (mfmapdt (T k) G (g ◻ const (incr w))) (f k (w, a))). Proof. intros. rewrite mfmapdt_to_mbinddt. now rewrite (dtp_mbinddt_mbinddt W S T F G). Qed. Lemma mbindt_mbinddt: forall (g : forall k, B -> G (T k C)) (f : forall k, W * A -> F (T k B)), fmap F (mbindt S G g) ∘ mbinddt S F f = mbinddt S (F ∘ G) (fun k => fmap F (mbindt (T k) G g) ∘ f k). Proof. intros. rewrite mbindt_to_mbinddt. rewrite (dtp_mbinddt_mbinddt W S T F G). fequal. ext k [w a]. unfold compose; cbn. fequal. rewrite mbindt_to_mbinddt. fequal. now ext j [w2 b]. Qed. Lemma mbind_mbinddt: forall (g : forall k, B -> T k C) (f : forall k, W * A -> F (T k B)), fmap F (mbind S g) ∘ mbinddt S F f = mbinddt S F (fun k => fmap F (mbind (T k) g) ∘ f k). Proof. intros. rewrite mbind_to_mbinddt. rewrite (dtp_mbinddt_mbinddt W S T F (fun A => A)). fequal. - now rewrite Mult_compose_identity1. - unfold compose, compose_dtm. ext k [w a]. fequal. rewrite mbind_to_mbinddt. fequal. now ext j [w2 b]. Qed. Lemma mfmapd_mbinddt: forall (g : K -> W * B -> C) (f : forall k, W * A -> F (T k B)), fmap F (mfmapd S g) ∘ mbinddt S F f = mbinddt S F (fun k '(w, a) => fmap F (mfmapd (T k) (g ◻ const (incr w))) (f k (w, a))). Proof. intros. rewrite mfmapd_to_mbinddt. rewrite (dtp_mbinddt_mbinddt W S T F (fun A => A)). fequal. now rewrite Mult_compose_identity1. Qed. Lemma mfmapt_mbinddt: forall (g : K -> B -> G C) (f : forall k, W * A -> F (T k B)), fmap F (mfmapt S G g) ∘ mbinddt S F f = mbinddt S (F ∘ G) (fun k => fmap F (mfmapt (T k) G g) ∘ f k). Proof. intros. rewrite mfmapt_to_mbinddt. rewrite (dtp_mbinddt_mbinddt W S T F G). fequal. ext k [w a]. unfold compose; cbn. fequal. rewrite mfmapt_to_mbinddt. fequal. now ext j [w2 b]. Qed. Lemma mfmap_mbinddt: forall (g : K -> B -> C) (f : forall k, W * A -> F (T k B)), fmap F (mfmap S g) ∘ mbinddt S F f = mbinddt S F (fun k => fmap F (mfmap (T k) g) ∘ f k). Proof. intros. unfold mfmap. rewrite mfmapd_mbinddt. fequal. ext k [w a]. unfold compose; cbn. fequal. fequal. now ext j [w2 b]. Qed. (** *** <<mbinddt>> on the left *) (******************************************************************************) Lemma mbinddt_mbindd: forall (g : forall k, W * B -> G (T k C)) (f : forall k, W * A -> T k B), mbinddt S G g ∘ mbindd S f = mbinddt S G (fun k '(w, a) => mbinddt (T k) G (g ◻ const (incr w)) (f k (w, a))). Proof. intros. rewrite mbindd_to_mbinddt. change (mbinddt S G g) with (fmap (fun A => A) (mbinddt S G g)). rewrite (dtp_mbinddt_mbinddt W S T (fun A => A) G). fequal. now rewrite Mult_compose_identity2. Qed. Lemma mbinddt_mfmapdt: forall (g : forall k, W * B -> G (T k C)) (f : K -> W * A -> F B), fmap F (mbinddt S G g) ∘ mfmapdt S F f = mbinddt S (F ∘ G) (fun k '(w, a) => fmap F (fun b => g k (w, b)) (f k (w, a))). Proof. intros. rewrite mfmapdt_to_mbinddt. rewrite (dtp_mbinddt_mbinddt W S T F G). fequal. ext k [w a]. unfold compose; cbn. compose near (f k (w, a)) on left. rewrite (fun_fmap_fmap F). fequal. ext b. unfold compose; cbn. compose near b on left. rewrite (dtm_mbinddt_comp_mret W T k G). cbn. now simpl_monoid. Qed. Lemma mbinddt_mbindt: forall (g : forall k, W * B -> G (T k C)) (f : forall k, A -> F (T k B)), fmap F (mbinddt S G g) ∘ mbindt S F f = mbinddt S (F ∘ G) (fun k '(w, a) => fmap F (mbinddt (T k) G (g ◻ const (incr w))) (f k a)). Proof. intros. rewrite mbindt_to_mbinddt. now rewrite (dtp_mbinddt_mbinddt W S T F G). Qed. Lemma mbinddt_mbind: forall (g : forall k, W * B -> G (T k C)) (f : forall k, A -> T k B), mbinddt S G g ∘ mbind S f = mbinddt S G (fun k '(w, a) => mbinddt (T k) G (g ◻ const (incr w)) (f k a)). Proof. intros. rewrite mbind_to_mbinddt. change (mbinddt S G g) with (fmap (fun A => A) (mbinddt S G g)). rewrite (dtp_mbinddt_mbinddt W S T (fun A => A) G). fequal. now rewrite Mult_compose_identity2. Qed. Lemma mbinddt_mfmapd: forall (g : forall k, W * B -> G (T k C)) (f : forall k, W * A -> B), mbinddt S G g ∘ mfmapd S f = mbinddt S G (fun k '(w, a) => g k (w, f k (w, a))). Proof. intros. rewrite mfmapd_to_mbinddt. change (mbinddt S G g) with (fmap (fun A => A) (mbinddt S G g)). rewrite (dtp_mbinddt_mbinddt W S T (fun A => A) G). fequal. now rewrite Mult_compose_identity2. ext j [w2 b]. unfold compose; cbn. unfold_ops @Fmap_I. compose near (f j (w2, b)). rewrite (dtm_mbinddt_comp_mret W T j G). unfold compose; cbn. now simpl_monoid. Qed. Lemma mbinddt_mfmapt: forall (g : forall k, W * B -> G (T k C)) (f : K -> A -> F B), fmap F (mbinddt S G g) ∘ mfmapt S F f = mbinddt S (F ∘ G) (fun k '(w, a) => fmap F (fun b => g k (w, b)) (f k a)). Proof. intros. unfold mfmapt. rewrite mbinddt_mbindt. fequal. ext k [w a]. unfold compose. compose near (f k a) on left. rewrite (fun_fmap_fmap F). fequal. rewrite (dtm_mbinddt_comp_mret W T k G). ext b. cbn. now simpl_monoid. Qed. Lemma mbinddt_mfmap: forall (g : forall k, W * B -> G (T k C)) (f : K -> A -> B), mbinddt S G g ∘ mfmap S f = mbinddt S G (fun k '(w, a) => g k (w, f k a)). Proof. intros. unfold mfmap. now rewrite mbinddt_mfmapd. Qed. End derived_operations_composition. (** ** Purity law for <<mbinddt>> *) (******************************************************************************) Section DTM_laws. Context (S : Type -> Type) `{DTPreModule W S T} `{! DTM W T}. (** *** Purity *) (******************************************************************************) Lemma mbinddt_pure: forall (A : Type) `{Applicative F}, mbinddt S F (fun k => pure F ∘ mret T k ∘ extract (W ×)) = pure F (A := S A). Proof. intros. replace (fun (k : K) => pure F ∘ mret T k ∘ extract (W ×)) with (fun (k : K) => pure F ∘ (mret T k ∘ extract (W ×) (A := A))). 2:{ ext k [w a]. easy. } rewrite <- (dtp_mbinddt_morphism W S T (fun x => x) F (ϕ := @pure F _)). now rewrite (dtp_mbinddt_mret W S T). Qed. End DTM_laws. (** * Derived structures on DTMs *) (******************************************************************************) (** ** Some mixed structure composition laws *) (** Composition laws involving one of <<mbindd>>/<<mfmapdt>>/<<mbindt>> and another operation that is not a special cases. *) (******************************************************************************) Section mixed_composition_laws. Context (S : Type -> Type) (F G : Type -> Type) `{Applicative F} `{Applicative G} `{DTPreModule W S T} `{! DTM W T} {A B C : Type}. (** *** <<mbindd>> *) (** Operations with traversals are not special cases of <<mbindd>>. *) (******************************************************************************) Lemma mbindd_mfmapdt: forall (g : forall k, W * B -> T k C) (f : forall k, W * A -> F B), fmap F (mbindd S g) ∘ mfmapdt S F f = mbinddt S F (fun (k : K) '(w, a) => fmap F (fun b => g k (w, b)) (f k (w, a))). Proof. intros. rewrite mfmapdt_to_mbinddt. rewrite mbindd_to_mbinddt. rewrite (dtp_mbinddt_mbinddt W S T F (fun x => x)). fequal. - now rewrite Mult_compose_identity1. - ext k [w a]. unfold compose; cbn. compose near (f k (w, a)) on left. rewrite (fun_fmap_fmap F). fequal. rewrite (dtm_mbinddt_comp_mret W T k (fun A =>A)). ext b. unfold compose; cbn. now simpl_monoid. Qed. Lemma mbindd_mbindt: forall (g : forall k, W * B -> T k C) (f : forall k, A -> F (T k B)), fmap F (mbindd S g) ∘ mbindt S F f = mbinddt S F (fun (k : K) '(w, a) => fmap F (mbindd (T k) (g ◻ const (incr w))) (f k a)). Proof. (* TODO *) Abort. Lemma mbindd_mfmapt: forall (g : forall k, W * B -> T k C) (f : forall k, A -> F B), fmap F (mbindd S g) ∘ mfmapt S F f = mbinddt S F (fun (k : K) '(w, a) => fmap F (fun b => g k (w, b)) (f k a)). Proof. (* TODO *) Abort. (* TODO Also need to put <<mfmapt_mbindd>> somewhere. *) (** *** <<mfmapdt>> *) (** Operations with joins are not special cases of <<mfmapdt>>. *) (******************************************************************************) Lemma mfmapdt_mbindd: forall (g : forall k, W * B -> G C) (f : forall k, W * A -> T k B), mfmapdt S G g ∘ mbindd S f = mbinddt S G (fun (k : K) '(w, a) => mfmapdt (T k) G (g ◻ const (incr w)) (f k (w, a))). Proof. (* TODO *) Abort. Lemma mfmapdt_mbindt: forall (g : forall k, W * B -> G C) (f : forall k, A -> F (T k B)), fmap F (mfmapdt S G g) ∘ mbindt S F f = mbinddt S (F ∘ G) (fun (k : K) '(w, a) => fmap F (mfmapdt (T k) G (g ◻ const (incr w))) (f k a)). Proof. (* TODO *) Abort. Lemma mfmapdt_mbind: forall (g : K -> W * B -> G C) (f : forall k, A -> T k B), mfmapdt S G g ∘ mbind S f = mbinddt S G (fun k '(w, a) => mfmapdt (T k) G (g ◻ const (incr w)) (f k a)). Proof. (* TODO *) Abort. (* TODO Also need to put <<mbind_mfmapdt>> somewhere. *) (** *** <<mbindt>> *) (** Operations with decorations are not special cases of <<mbindt>>. *) (******************************************************************************) Lemma mbindt_mbindd: forall (g : forall k, B -> G (T k C)) (f : forall k, W * A -> T k B), mbindt S G g ∘ mbindd S f = mbinddt S G (fun (k : K) '(w, a) => mbindt (T k) G g (f k (w, a))). Proof. (* TODO *) Abort. Lemma mbindt_mfmapdt: forall (g : forall k, B -> G (T k C)) (f : forall k, W * A -> F B), fmap F (mbindt S G g) ∘ mfmapdt S F f = mbinddt S (F ∘ G) (fun (k : K) '(w, a) => fmap F (g k) (f k (w, a))). Proof. (* TODO *) Abort. (* TODO <<mbindt_mfmapd>> *) (* TODO Also need to put <<mfmapd_mbindt>> somewhere. *) End mixed_composition_laws. (** ** Decorated monads (<<mbindd>>) *) (******************************************************************************) Definition compose_dm `{ix : Index} {W : Type} {T : K -> Type -> Type} `{mn_op : Monoid_op W} `{mn_unit : Monoid_unit W} `{forall k, MBind W T (T k)} {A B C : Type} (g : forall k, W * B -> T k C) (f : forall k, W * A -> T k B) : forall k, W * A -> T k C := fun k '(w, a) => mbindd (T k) (g ◻ const (incr w)) (f k (w, a)). Infix "⋆dm" := compose_dm (at level 40). Section DecoratedMonad. Context (S : Type -> Type) `{DTPreModule W S T} `{! DTM W T} {A B C : Type}. (** *** Composition and identity law *) (******************************************************************************) Theorem mbindd_id: mbindd S (mret T ◻ const (extract (W ×))) = @id (S A). Proof. intros. rewrite mbindd_to_mbinddt. now rewrite <- (dtp_mbinddt_mret W S T). Qed. Theorem mbindd_mbindd: forall (g : W * B ~k~> T C) (f : W * A ~k~> T B), mbindd S g ∘ mbindd S f = mbindd S (fun (k : K) '(w, a) => mbindd (T k) (g ◻ const (incr w)) (f k (w, a))). Proof. intros. rewrite mbindd_to_mbinddt. change_left (fmap (fun x => x) (mbinddt S (fun x : Type => x) g) ∘ (mbinddt S (fun x : Type => x) f)). rewrite (dtp_mbinddt_mbinddt W S T (fun x => x) (fun x => x)). ext t. change (compose_dtm g f) with (fun (k : K) '(w, a) => mbinddt (T k) (fun x : Type => x) (g ◻ const (incr w)) (f k (w, a))). fequal. now rewrite Mult_compose_identity2. Qed. (** *** Right unit law for monads *) (******************************************************************************) Theorem mbindd_comp_mret: forall (k : K) (f : forall k, W * A -> T k B), mbindd (T k) f ∘ mret T k = f k ∘ ret (W ×). Proof. intros. rewrite mbindd_to_mbinddt. now rewrite (dtm_mbinddt_comp_mret W T k (fun A => A)). Qed. (** *** Composition with special cases on the right *) (** Composition with operations <<mbind>>/<<mfmapd>>/<<mfmap>> *) (******************************************************************************) Lemma mbindd_mbind: forall (g : forall k, W * B -> T k C) (f : A ~k~> T B), mbindd S g ∘ mbind S f = mbindd S (fun (k : K) '(w, a) => mbindd (T k) (g ◻ const (incr w)) (f k a)). Proof. intros. rewrite mbind_to_mbindd. now rewrite mbindd_mbindd. Qed. Lemma mbindd_mfmapd: forall (g : forall k, W * B -> T k C) (f : forall k, W * A -> B), mbindd S g ∘ mfmapd S f = mbindd S (fun (k : K) '(w, a) => g k (w, f k (w, a))). Proof. intros. rewrite mfmapd_to_mbindd. rewrite (mbindd_mbindd). fequal. ext k [w a]. unfold compose; cbn. compose near (f k (w, a)). rewrite mbindd_to_mbinddt. rewrite (dtm_mbinddt_comp_mret W T k (fun A => A)). unfold compose; cbn. now simpl_monoid. Qed. Lemma mbindd_mfmap: forall (g : forall k, W * B -> T k C) (f : forall k, A -> B), mbindd S g ∘ mfmap S f = mbindd S (fun (k : K) '(w, a) => g k (w, f k a)). Proof. intros. unfold mfmap. now rewrite (mbindd_mfmapd). Qed. (** *** Composition with special cases on the left *) (******************************************************************************) Lemma mbind_mbindd: forall (g : forall k, B -> T k C) (f : forall k, W * A -> T k B), mbind S g ∘ mbindd S f = mbindd S (fun (k : K) => mbind (T k) g ∘ f k). Proof. intros. rewrite mbind_to_mbindd. rewrite (mbindd_mbindd). fequal. ext k [w a]. unfold compose; cbn. unfold mbind. fequal. now ext j [w2 b]. Qed. Lemma mfmapd_mbindd: forall (g : forall k, W * B -> C) (f : forall k, W * A -> T k B), mfmapd S g ∘ mbindd S f = mbindd S (fun (k : K) '(w, a) => mfmapd (T k) (g ◻ const (incr w)) (f k (w, a))). Proof. intros. rewrite mfmapd_to_mbindd. now rewrite (mbindd_mbindd). Qed. Lemma mfmap_mbindd: forall (g : forall k, B -> T k C) (f : forall k, W * A -> T k B), mbind S g ∘ mbindd S f = mbindd S (fun (k : K) => mbind (T k) g ∘ f k). Proof. intros. rewrite mbind_to_mbindd. rewrite (mbindd_mbindd). fequal. ext k [w a]. unfold compose; cbn. rewrite mbind_to_mbindd. fequal. now ext j [w2 b]. Qed. End DecoratedMonad. (** ** Decorated traversable functors (<<mfmapdt>>) *) (******************************************************************************) Section DecoratedTraversable. Context (S : Type -> Type) `{DTPreModule W S T} `{! DTM W T} {A B C : Type} `{Applicative F} `{Applicative G}. (** *** Composition and identity law *) (******************************************************************************) Theorem mfmapdt_id: mfmapdt S (fun x => x) (const (extract (W ×))) = @id (S A). Proof. intros. unfold mfmapdt. apply (dtp_mbinddt_mret W S T). Qed. Theorem mfmapdt_mfmapdt: forall (g : forall k, W * B -> G C) (f : forall k, W * A -> F B), fmap F (mfmapdt S G g) ∘ mfmapdt S F f = mfmapdt S (F ∘ G) (fun (k : K) '(w, a) => fmap F (fun b => g k (w, b)) (f k (w, a))). Proof. intros. unfold mfmapdt. rewrite (dtp_mbinddt_mbinddt W S T F G). unfold compose_dtm. fequal. ext k [w a]. unfold_ops @Fmap_compose. unfold compose. compose near (f k (w, a)). do 2 rewrite (fun_fmap_fmap F). rewrite (dtm_mbinddt_comp_mret W T k G). fequal. ext b. cbn. now simpl_monoid. Qed. (** *** Composition with <<mret>> *) (******************************************************************************) Lemma mfmapdt_comp_mret: forall (k : K) (f : forall k, W * A -> F B), mfmapdt (T k) F f ∘ mret T k = fmap F (mret T k) ∘ f k ∘ pair Ƶ. Proof. intros. unfold mfmapdt. now rewrite (dtm_mbinddt_comp_mret W T k F). Qed. (** *** Purity *) (******************************************************************************) Lemma mfmapdt_pure: mfmapdt S F (fun k => pure F ∘ extract (W ×)) = pure F (A := S A). Proof. intros. unfold mfmapdt. replace (fun k : K => fmap F (mret T k) ∘ (pure F ∘ extract (prod W))) with (fun (k : K) => (pure F ∘ (mret T k ∘ extract (W ×) (A := A)))). rewrite <- (dtp_mbinddt_morphism W S T (fun x => x) F (ϕ := @pure F _)). now rewrite (dtp_mbinddt_mret W S T). ext k [w a]. unfold compose; cbn. now rewrite (app_pure_natural F). Qed. (** *** Composition with special cases on the right *) (******************************************************************************) Lemma mfmapdt_mfmapt: forall (g : K -> W * B -> G C) (f : K -> A -> F B), fmap F (mfmapdt S G g) ∘ mfmapt S F f = mfmapdt S (F ∘ G) (fun (k : K) '(w, a) => fmap F (fun b => g k (w, b)) (f k a)). Proof. (* TODO *) Abort. Lemma mfmapdt_mfmapd: forall (g : K -> W * B -> G C) (f : K -> W * A -> B), mfmapdt S G g ∘ mfmapd S f = mfmapdt S G (fun k '(w, a) => g k (w, f k (w, a))). Proof. (* TODO *) Abort. (* TODO <<mfmapdt_mfmap>> *) (** *** Composition with other operations on the left *) (******************************************************************************) Lemma mfmapd_mfmapdt: forall (g : K -> W * B -> C) (f : K -> W * A -> F B), fmap F (mfmapd S g) ∘ mfmapdt S F f = mfmapdt S F (fun k '(w, a) => fmap F (fun (b : B) => (g k (w, b))) (f k (w, a))). Proof. (* TODO *) Abort. Lemma mfmapt_mfmapdt: forall (g : K -> B -> C) (f : K -> W * A -> F B), fmap F (mfmap S g) ∘ mfmapdt S F f = mfmapdt S F (fun k => fmap F (g k) ∘ f k). Proof. (* TODO *) Abort. (* TODO <<mfmap_mfmapdt>> *) End DecoratedTraversable. (** ** Traversable monads (<<mbindt>>) *) (******************************************************************************) Section TraversableMonad. Context (S : Type -> Type) `{DTPreModule W S T} `{! DTM W T} {A B C : Type} (F G : Type -> Type) `{Applicative F} `{Applicative G}. (** *** Composition and identity law *) (******************************************************************************) Theorem mbindt_id : mbindt S (fun x => x) (mret T) = @id (S A). Proof. intros. unfold mbindt. now rewrite (dtp_mbinddt_mret W S T). Qed. Theorem mbindt_mbindt : forall (g : forall k, B -> G (T k C)) (f : forall k, A -> F (T k B)), fmap F (mbindt S G g) ∘ mbindt S F f = mbindt S (F ∘ G) (fun (k : K) (a : A) => fmap F (mbindt (T k) G g) (f k a)). Proof. intros. unfold mbindt. rewrite (dtp_mbinddt_mbinddt W S T F G). fequal. ext k [w a]. unfold compose; cbn. repeat fequal. ext k2 [w2 b]. easy. Qed. (** *** Composition with <<mret>> *) (******************************************************************************) Lemma mbindt_comp_mret : forall (k : K) (f : forall k, A -> F (T k B)), mbindt (T k) F f ∘ mret T k = f k. Proof. intros. unfold mbindt. now rewrite (dtm_mbinddt_comp_mret W T k F). Qed. (** *** Purity *) (******************************************************************************) (* TODO *) (** *** Composition with special cases on the right *) (******************************************************************************) (* TODO *) (** *** Composition with special cases on the left *) (******************************************************************************) (* TODO *) End TraversableMonad. (** ** Some more mixed structure composition laws *) (** Composition laws between one of <<mbind>>/<<mfmapd>>/<<mfmapt>> and another operation, neither of which is a special case of the other. *) (******************************************************************************) Section mixed_composition_laws2. Context (S : Type -> Type) (F G : Type -> Type) `{Applicative F} `{Applicative G} `{DTPreModule W S T} `{! DTM W T} {A B C : Type}. (** *** <<mbind>> on the left *) (******************************************************************************) Lemma mbind_mfmapd : forall (g : forall k, B -> T k C) (f : K -> W * A -> B), mbind S g ∘ mfmapd S f = mbindd S (g ◻ f). Proof. intros. rewrite mfmapd_to_mbindd. rewrite mbind_to_mbindd. rewrite (mbindd_mbindd S). fequal. ext k [w a]. unfold compose; cbn. compose near (f k (w, a)) on left. now rewrite (mbindd_comp_mret (T := T)). Qed. Lemma mbind_mfmapt : forall (g : forall k, B -> T k C) (f : K -> A -> F B), fmap F (mbind S g) ∘ mfmapt S F f = mbindt S F (fun k => fmap F (g k) ∘ f k). Proof. intros. rewrite (mfmapt_to_mbindt S F). rewrite mbind_to_mbindt. rewrite (mbindt_mbindt S F (fun A => A)). fequal. - now rewrite Mult_compose_identity1. - ext k a. unfold compose. compose near (f k a) on left. rewrite (fun_fmap_fmap F). fequal. change (mbindt (T k) (fun A0 : Type => A0) g) with (mbind (T k) g). rewrite mbind_to_mbindd. now rewrite mbindd_comp_mret. Qed. (** *** <<mfmapd>> on the left *) (******************************************************************************) Lemma mfmapd_mbind : forall (g : K -> W * B -> C) (f : forall k, A -> T k B), mfmapd S g ∘ mbind S f = mbindd S (fun k '(w, a) => mfmapd (T k) (g ◻ const (incr w)) (f k a)). Proof. intros. rewrite mfmapd_to_mbindd. rewrite mbind_to_mbindd. now rewrite (mbindd_mbindd S). Qed. Lemma mfmapd_mfmapt : forall (g : K -> W * B -> C) (f : forall k, A -> F B), fmap F (mfmapd S g) ∘ mfmapt S F f = mfmapdt S F (fun k '(w, a) => fmap F (fun b => g k (w, b)) (f k a)). Proof. intros. rewrite mfmapd_to_mfmapdt. rewrite mfmapt_to_mfmapdt. rewrite (mfmapdt_mfmapdt S (G := fun A => A)). fequal. now rewrite Mult_compose_identity1. Qed. (** *** <<mfmapt>> on the left *) (******************************************************************************) Lemma mfmapt_mbind : forall (g : K -> B -> G C) (f : forall k, A -> T k B), mfmapt S G g ∘ mbind S f = mbindt S G (fun k => mfmapt (T k) G g ∘ f k). Proof. intros. rewrite mfmapt_to_mbindt. rewrite mbind_to_mbindt. change (mbindt S G (fun k : K => fmap G (mret T k) ∘ g k)) with (fmap (fun A => A) (mbindt S G (fun k : K => fmap G (mret T k) ∘ g k))). rewrite (mbindt_mbindt S (fun A => A) G). fequal. now rewrite Mult_compose_identity2. Qed. Lemma mfmapt_mfmapd : forall (g : K -> B -> G C) (f : forall k, A -> T k B), mfmapt S G g ∘ mbind S f = mbindt S G (fun k => mfmapt (T k) G g ∘ f k). Proof. intros. rewrite mfmapt_to_mbindt. rewrite mbind_to_mbindt. change (mbindt S G (fun k : K => fmap G (mret T k) ∘ g k)) with (fmap (fun A => A) (mbindt S G (fun k : K => fmap G (mret T k) ∘ g k))). rewrite (mbindt_mbindt S (fun A => A) G). fequal. now rewrite Mult_compose_identity2. Qed. End mixed_composition_laws2. (** ** Monads (<<mbind>>) *) (******************************************************************************) Section Monad. Context (S : Type -> Type) `{DTPreModule W S T} `{! DTM W T}. (** *** Composition and identity law *) (******************************************************************************) Theorem mbind_id : forall A, mbind S (fun k => mret T k) = @id (S A). Proof. intros. rewrite mbind_to_mbindd. now rewrite <- (mbindd_id S). Qed. Theorem mbind_mbind {A B C} : forall (g : forall (k : K), B -> T k C) (f : forall (k : K), A -> T k B), mbind S g ∘ mbind S f = mbind S (fun (k : K) (a : A) => mbind (T k) g (f k a)). Proof. intros. do 3 rewrite (mbind_to_mbindd S). rewrite (mbindd_mbindd S). unfold compose; cbn. fequal. ext k [w a]. rewrite (mbind_to_mbindd (T k)). cbn. fequal. now ext j [w2 b]. Qed. (** *** Composition with <<mret>> *) (******************************************************************************) Lemma mbind_comp_mret {A B} : forall (k : K) (f : forall (k : K), A -> T k B) (a : A), mbind (T k) f (mret T k a) = f k a. Proof. intros. rewrite mbind_to_mbindd. compose near a on left. now rewrite mbindd_comp_mret. Qed. (* TODO <<mbind_mfmap>> *) (* TODO <<mfmap_mbind>> *) End Monad. (** ** Decorated functors (<<mfmapd>>) *) (******************************************************************************) Section DecoratedFunctor. Context (S : Type -> Type) `{DTPreModule W S T} `{! DTM W T}. (** *** Composition and identity law *) (******************************************************************************) Theorem mfmapd_id : forall A, mfmapd S (const (extract (W ×))) = @id (S A). Proof. intros. rewrite mfmapd_to_mfmapdt. now rewrite (mfmapdt_id S). Qed. Theorem mfmapd_mfmapd {A B C} : forall (g : K -> W * B -> C) (f : K -> W * A -> B), mfmapd S g ∘ mfmapd S f = mfmapd S (fun (k : K) '(w, a) => g k (w, f k (w, a))). Proof. intros. do 3 rewrite mfmapd_to_mfmapdt. change (mfmapdt S (fun A => A) g) with (fmap (fun A => A) (mfmapdt S (fun A => A) g)). rewrite (mfmapdt_mfmapdt S (G := fun A => A) (F := fun A => A)). unfold compose; cbn. fequal. now rewrite Mult_compose_identity1. Qed. (** *** Composition with <<mret>> *) (******************************************************************************) Lemma mfmapd_comp_mret {A B} : forall (k : K) (f : K -> W * A -> B) (a : A), mfmapd (T k) f (mret T k a) = mret T k (f k (Ƶ, a)). Proof. intros. rewrite mfmapd_to_mfmapdt. compose near a on left. now rewrite (mfmapdt_comp_mret (F := fun A => A)). Qed. (* TODO <<mfmapd_mfmap>> *) (* TODO <<mfmap_mfmapd>> *) End DecoratedFunctor. (** ** Traversable functors (<<mfmapt>>) *) (******************************************************************************) Section TraversableFunctor. Context (S : Type -> Type) `{DTPreModule W S T} `{! DTM W T}. (** *** Composition and identity law *) (******************************************************************************) Theorem mfmapt_id : forall A, mfmapt S (fun A => A) (const (@id A)) = @id (S A). Proof. intros. unfold mfmapt. now rewrite <- (mbindt_id S). Qed. Theorem mfmapt_mfmapt {A B C} : forall `{Applicative G} `{Applicative F} (g : K -> B -> G C) (f : K -> A -> F B), fmap F (mfmapt S G g) ∘ mfmapt S F f = mfmapt S (F ∘ G) (fun (k : K) (a : A) => fmap F (g k) (f k a)). Proof. intros. rewrite (mfmapt_to_mfmapdt S G). rewrite (mfmapt_to_mfmapdt S F). rewrite (mfmapt_to_mfmapdt S (F ∘ G)). rewrite (mfmapdt_mfmapdt S). fequal. now ext k [w a]. Qed. (** *** Composition with <<mret>> *) (******************************************************************************) Lemma mfmapt_comp_mret {A B} : forall `{Applicative F} (k : K) (f : K -> A -> F B) (a : A), mfmapt (T k) F f (mret T k a) = fmap F (mret T k) (f k a). Proof. intros. rewrite (mfmapt_to_mfmapdt (T k)). compose near a on left. now rewrite mfmapdt_comp_mret. Qed. (* TODO <<mfmapt_mfmap>> *) (* TODO <<mfmap_mfmapt>> *) End TraversableFunctor. (** ** Functors (<<mfmap>>) *) (******************************************************************************) Section Functor. Context (S : Type -> Type) `{DTPreModule W S T} `{! DTM W T}. (** *** Composition and identity law *) (******************************************************************************) Theorem mfmap_id : forall A, mfmap S (const (@id A)) = @id (S A). Proof. intros. apply (dtp_mbinddt_mret W S T). Qed. Theorem mfmap_mfmap {A B C} : forall (g : K -> B -> C) (f : K -> A -> B), mfmap S g ∘ mfmap S f = mfmap S (g ⊙ f). Proof. intros. do 3 rewrite mfmap_to_mfmapd. rewrite (mfmapd_mfmapd S). fequal. now ext k [w a]. Qed. (** *** Composition with <<mret>> *) (******************************************************************************) Lemma mfmap_comp_mret {A B} : forall (f : K -> A -> B) (a : A) (k : K), mfmap (T k) f (mret T k a) = mret T k (f k a). Proof. intros. rewrite mfmap_to_mfmapd. now rewrite mfmapd_comp_mret. Qed. End Functor. (** * Targeted operations *) (** In this section we ignore operations involving traversals simply because they are not necessary for System F. *) (******************************************************************************) (** ** Targeted substitution-building combinators: [btg] and [btgd] *) (******************************************************************************) (* TODO : Define a version that works for applicative effects. *) (* #[program] Definition btga `{ix : Index} `{Fmap F} `{Pure F} `{Mult F} {A W : Type} (T : K -> Type -> Type) `{! MReturn T} (j : K) (f : W * A -> F (T j A)) : forall (k : K), W * A -> F (T k A) := fun k '(w, a) => if k == j then f (w, a) else pure F ∘ mret T k a. *) #[program] Definition tgtd `{ix : Index} {A W : Type} (T : K -> Type -> Type) (j : K) (f : W * A -> A) : K -> W * A -> A := fun k '(w, a) => if k == j then f (w, a) else a. #[program] Definition tgt `{ix : Index} {A : Type} (T : K -> Type -> Type) (j : K) (f : A -> A) : K -> A -> A := fun k a => if k == j then f a else a. #[program] Definition btgd `{ix : Index} {A W : Type} (T : K -> Type -> Type) `{! MReturn T} (j : K) (f : W * A -> T j A) : forall (k : K), W * A -> T k A := fun k '(w, a) => if k == j then f (w, a) else mret T k a. #[program] Definition btg `{ix : Index} {A : Type} (T : K -> Type -> Type) `{! MReturn T} (j : K) (f : A -> T j A) : forall (k : K), A -> T k A := fun k => if k == j then f else mret T k. Require Import Coq.Program.Equality. (** ** Lemmas for [btgd], [btg] *) (******************************************************************************) Section btgd_lemmas. Context `{MReturn T} {W A : Type}. Lemma tgtd_eq : forall k (f : W * A -> A), tgtd T k f k = f. Proof. introv. unfold tgtd. ext [w a]. compare values k and k. Qed. Lemma tgtd_neq : forall {k j} (f : W * A -> A), k <> j -> tgtd T j f k = extract (W ×). Proof. introv. unfold tgtd. intro hyp. ext [w a]. compare values k and j. Qed. Lemma tgtd_id (j : K) : tgtd (A := A) T j (extract (W ×)) = const (extract (W ×)). Proof. unfold tgtd. ext k [w a]. compare values k and j. Qed. Lemma tgt_eq : forall k (f : A -> A), tgt T k f k = f. Proof. introv. unfold tgt. ext a. compare values k and k. Qed. Lemma tgt_neq : forall {k j} (f : A -> A), k <> j -> tgt T j f k = @id A. Proof. introv. unfold tgt. intro hyp. ext a. compare values k and j. Qed. Lemma tgt_id (j : K) : tgt (A := A) T j (@id A) = const (@id A). Proof. unfold tgt. ext k a. compare values k and j. Qed. Lemma btgd_eq : forall k (f : W * A -> T k A), btgd T k f k = f. Proof. introv. unfold btgd. ext [w a]. compare values k and k. dependent destruction DESTR_EQ. cbn. reflexivity. Qed. Lemma btgd_neq : forall {k j} (f : W * A -> T j A), k <> j -> btgd T j f k = mret T k ∘ extract (W ×). Proof. introv. unfold btgd. intro hyp. ext [w a]. compare values k and j. Qed. Lemma btgd_id (j : K) : btgd (A := A) T j (mret T j ∘ extract (W ×)) = mret T ◻ const (extract (W ×)). Proof. unfold btgd. ext k [w a]. compare values k and j. Qed. Lemma btg_eq : forall k (f : A -> T k A), btg T k f k = f. Proof. introv. unfold btg. compare values k and k. dependent destruction DESTR_EQ. cbn. reflexivity. Qed. Lemma btg_neq : forall {k j} (f : A -> T j A), k <> j -> btg T j f k = mret T k. Proof. introv. unfold btg. intro hyp. compare values k and j. Qed. Lemma btg_id (j : K) : btg (A := A) T j (mret T j) = mret T. Proof. unfold btg. ext k. compare values k and j. Qed. End btgd_lemmas. (** ** Rewrite Hint registration *) (******************************************************************************) #[export] Hint Rewrite @tgt_eq @tgtd_eq @tgt_id @tgtd_id : tea_tgt. #[export] Hint Rewrite @btgd_eq @btg_eq @btg_id @btgd_id : tea_tgt. #[export] Hint Rewrite @btgd_neq @btg_neq using auto : tea_tgt. #[export] Hint Rewrite @tgt_eq @tgtd_eq @tgt_id @tgtd_id : tea_tgt_eq. #[export] Hint Rewrite @btgd_eq @btg_eq @btg_id @btgd_id : tea_tgt_eq. #[export] Hint Rewrite @tgtd_neq @tgt_neq using auto : tea_tgt_neq. #[export] Hint Rewrite @btgd_neq @btg_neq using auto : tea_tgt_neq. (** ** Derived targeted DTM operations *) (******************************************************************************) Section DTM_targeted. Context (S : Type -> Type) `{DTPreModule W S T} (j : K). (** *** Definitions *) (* For now we ignore traversals because we don't need them for System F. *) (******************************************************************************) Definition kbindd {A} `(f : W * A -> T j A) : S A -> S A := mbindd S (btgd T j f). Definition kbind `(f : A -> T j A) : S A -> S A := mbind S (btg T j f). Definition kfmapd `(f : W * A -> A) : S A -> S A := mfmapd S (tgtd T j f). Definition kfmap `(f : A -> A) : S A -> S A := mfmap S (tgt T j f). Section special_cases. Context {A : Type}. (** *** Rewriting rules for special cases of <<kbindd>> *) (******************************************************************************) Lemma kbind_to_kbindd (f : A -> T j A) : kbind f = kbindd (f ∘ extract (W ×)). Proof. unfold kbind, kbindd. rewrite mbind_to_mbindd. fequal. ext k [w a]. unfold compose; cbn. compare values k and j. - autorewrite with tea_tgt_eq. easy. - autorewrite with tea_tgt_neq. easy. Qed. Lemma kfmapd_to_kbindd (f : W * A -> A) : kfmapd f = kbindd (mret T j ∘ f). Proof. unfold kfmapd, kbindd. rewrite mfmapd_to_mbindd. fequal. ext k [w a]. unfold compose. cbn. compare values k and j. Qed. Lemma kfmap_to_kbindd (f : A -> A) : kfmap f = kbindd (mret T j ∘ f ∘ extract (W ×)). Proof. unfold kfmap, kbindd. rewrite mfmap_to_mbindd. fequal. ext k [w a]. unfold compose. cbn. compare values k and j. cbn. now autorewrite with tea_tgt_eq. now autorewrite with tea_tgt_neq. Qed. (** *** Rewriting rules for special cases of <<kfmapd>> *) (******************************************************************************) Lemma kfmap_to_kfmapd (f : A -> A) : kfmap f = kfmapd (f ∘ extract (W ×)). Proof. unfold kfmap, kbind. unfold kfmapd. rewrite mfmap_to_mfmapd. fequal. ext k. compare values j and k. now autorewrite with tea_tgt_eq. now autorewrite with tea_tgt_neq. Qed. (** *** Rewriting rules for special cases of <<kbind>> *) (******************************************************************************) Lemma kfmap_to_kbind (f : A -> A) : kfmap f = kbind (mret T j ∘ f). Proof. unfold kfmap, kbind. rewrite mfmap_to_mbind. fequal. ext k. compare values j and k. now autorewrite with tea_tgt_eq. now autorewrite with tea_tgt_neq. Qed. End special_cases. End DTM_targeted. (** ** Decorated monad (<<kbindd>>) *) (******************************************************************************) Definition compose_kdm `{ix : Index} {W : Type} {T : K -> Type -> Type} `{mn_op : Monoid_op W} `{mn_unit : Monoid_unit W} `{forall k, MBind W T (T k)} `{! MReturn T} {j : K} {A : Type} (g : W * A -> T j A) (f : W * A -> T j A) : W * A -> T j A := fun '(w, a) => kbindd (T j) j (g ∘ incr w) (f (w, a)). Infix "⋆kdm" := compose_kdm (at level 40). Section DecoratedMonad. Context (S : Type -> Type) `{DTPreModule W S T} `{! DTM W T} {j : K} {A : Type}. (** *** Composition and identity law *) (******************************************************************************) Theorem kbindd_id : kbindd S j (mret T j ∘ (extract (W ×))) = @id (S A). Proof. intros. unfold kbindd. rewrite <- (mbindd_id S). fequal. ext k [w a]. cbn. compare values k and j. Qed. Theorem kbindd_kbindd_eq : forall (g : W * A -> T j A) (f : W * A -> T j A), kbindd S j g ∘ kbindd S j f = kbindd S j (g ⋆kdm f). Proof. intros. unfold kbindd. rewrite (mbindd_mbindd S). fequal. ext k [w a]. cbn. compare values k and j. - cbn. unfold kbindd. fequal. ext k [w' a']. compare values k and j. - compose near a on left. rewrite mbindd_comp_mret. cbn. compare values k and j. Qed. Theorem kbindd_kbindd_neq : forall {i : K} (Hneq : j <> i) (g : W * A -> T i A) (f : W * A -> T j A), kbindd S i g ∘ kbindd S j f = mbindd S (btgd T i g ⋆dm btgd T j f). Proof. intros. unfold kbindd. now rewrite (mbindd_mbindd S). Qed. (** *** Right unit law for monads *) (******************************************************************************) Theorem kbindd_comp_mret_eq : forall (f : W * A -> T j A) (a : A), kbindd (T j) j f (mret T j a) = f (Ƶ, a). Proof. intros. unfold kbindd. compose near a on left. rewrite (mbindd_comp_mret). now autorewrite with tea_tgt_eq. Qed. Theorem kbindd_comp_mret_neq : forall (i : K) (Hneq : j <> i) (f : W * A -> T j A) (a : A), kbindd (T i) j f (mret T i a) = mret T i a. Proof. intros. unfold kbindd. compose near a on left. rewrite (mbindd_comp_mret). now autorewrite with tea_tgt_neq. Qed. (** *** Composition with special cases *) (******************************************************************************) Lemma kfmapd_kbindd : forall (g : W * A -> A) (f : W * A -> T j A), kfmapd S j g ∘ kbindd S j f = kbindd S j (fun '(w, a) => kfmapd (T j) j (g ∘ incr w) (f (w, a))). Proof. intros. rewrite kfmapd_to_kbindd. rewrite kbindd_kbindd_eq. fequal. unfold compose_kdm. ext [w a]. now rewrite kfmapd_to_kbindd. Qed. Lemma kbind_kbindd : forall (g : A -> T j A) (f : W * A -> T j A), kbind S j g ∘ kbindd S j f = kbindd S j (kbind (T j) j g ∘ f). Proof. intros. rewrite kbind_to_kbindd. rewrite kbindd_kbindd_eq. fequal. unfold compose_kdm. ext [w a]. reassociate ->. rewrite extract_incr. now rewrite kbind_to_kbindd. Qed. Lemma kfmap_kbindd : forall (g : A -> A) (f : W * A -> T j A), kfmap S j g ∘ kbindd S j f = kbindd S j (fun '(w, a) => kfmap (T j) j g (f (w, a))). Proof. intros. unfold kfmap, kbindd. rewrite mfmap_to_mbindd. rewrite (mbindd_mbindd S). fequal. ext k [w a]. compare values j and k. - autorewrite with tea_tgt_eq. rewrite mfmap_to_mbindd. fequal. ext k' [w' a']. unfold compose; cbn. reflexivity. - autorewrite with tea_tgt_neq. unfold compose; cbn. compose near a on left. rewrite (mbindd_comp_mret). rewrite tgt_neq; auto. Qed. Lemma kbindd_kfmapd : forall (g : W * A -> T j A) (f : W * A -> A), kbindd S j g ∘ kfmapd S j f = kbindd S j (fun '(w, a) => g (w, f (w, a))). Proof. intros. rewrite kfmapd_to_kbindd. rewrite kbindd_kbindd_eq. fequal. ext (w, a). unfold compose; cbn. rewrite kbindd_comp_mret_eq. unfold compose; cbn. now simpl_monoid. Qed. Lemma kbindd_kbind : forall (g : W * A -> T j A) (f : A -> T j A), kbindd S j g ∘ kbind S j f = kbindd S j (fun '(w, a) => kbindd (T j) j (g ∘ incr w) (f a)). Proof. intros. rewrite kbind_to_kbindd. now rewrite kbindd_kbindd_eq. Qed. (* TODO <<kbindd_kfmap>> *) End DecoratedMonad. (** ** Mixed structure composition laws *) (** Composition laws involving <<kbind>> and <<kfmapd>> *) (******************************************************************************) (* TODO <<kbind_kfmapd>> *) (* TODO <<kfmapd_kbind>> *) (** ** Decorated functors (<<kfmapd>>) *) (******************************************************************************) Section DecoratedFunctor. Context (S : Type -> Type) `{DTPreModule W S T} `{! DTM W T} {j : K}. (** *** Composition and identity law *) (******************************************************************************) Theorem kfmapd_id : forall A, kfmapd S j (extract (W ×)) = @id (S A). Proof. intros. unfold kfmapd. rewrite <- (mfmapd_id S). fequal. ext k. compare values j and k. - now autorewrite with tea_tgt. - now autorewrite with tea_tgt. Qed. Theorem kfmapd_kfmapd : forall A, forall (g : W * A -> A) (f : W * A -> A), kfmapd S j g ∘ kfmapd S j f = kfmapd S j (fun '(w, a) => g (w, f (w, a))). Proof. intros. unfold kfmapd. rewrite (mfmapd_mfmapd S). fequal. ext k [w a]. compare values j and k. - now autorewrite with tea_tgt. - now autorewrite with tea_tgt_neq. Qed. (** *** Composition with <<mret>> *) (******************************************************************************) Lemma kfmapd_comp_mret_eq : forall A, forall (f : W * A -> A) (a : A), kfmapd (T j) j f (mret T j a) = mret T j (f (Ƶ, a)). Proof. intros. unfold kfmapd. rewrite mfmapd_comp_mret. now autorewrite with tea_tgt. Qed. Lemma kfmapd_comp_mret_neq : forall A, forall (k : K) (neq : k <> j) (f : W * A -> A) (a : A), kfmapd (T k) j f (mret T k a) = mret T k a. Proof. intros. unfold kfmapd. rewrite mfmapd_comp_mret. now autorewrite with tea_tgt_neq. Qed. (* TODO <<kfmap_kfmapd>> *) (* TODO <<kfmapd_kfmap>> *) End DecoratedFunctor. (** ** Monads (<<kbind>>) *) (******************************************************************************) Definition compose_km `{ix : Index} {W : Type} {T : K -> Type -> Type} `{forall k, MBind W T (T k)} `{! MReturn T} {j : K} {A : Type} (g : A -> T j A) (f : A -> T j A) : A -> T j A := (kbind (T j) j g ∘ f). Infix "⋆km" := compose_km (at level 40). Section Monad. Context (S : Type -> Type) `{DTPreModule W S T} `{! DTM W T} {j : K}. (** *** Composition and identity law *) (******************************************************************************) Theorem kbind_id : forall A, kbind S j (mret T j) = @id (S A). Proof. intros. unfold kbind. rewrite <- (mbind_id S). fequal. ext k. compare values j and k. - now autorewrite with tea_tgt_eq. - now autorewrite with tea_tgt_neq. Qed. Theorem kbind_kbind : forall A, forall (g f : A -> T j A), kbind S j g ∘ kbind S j f = kbind S j (g ⋆km f). Proof. intros. unfold kbind. rewrite (mbind_mbind S). fequal. ext k a. compare values j and k. - now autorewrite with tea_tgt_eq. - autorewrite with tea_tgt_neq. rewrite (mbind_comp_mret k). now autorewrite with tea_tgt_neq. Qed. (** *** Composition with <<mret>> *) (******************************************************************************) Lemma kbind_comp_mret_eq : forall A, forall (f : A -> T j A) (a : A), kbind (T j) j f (mret T j a) = f a. Proof. intros. unfold kbind. rewrite mbind_comp_mret. now autorewrite with tea_tgt_eq. Qed. Lemma kbind_comp_mret_neq : forall A, forall (i : K) (Hneq : j <> i) (f : A -> T j A) (a : A), kbind (T i) j f (mret T i a) = mret T i a. Proof. intros. unfold kbind. rewrite mbind_comp_mret. now autorewrite with tea_tgt_neq. Qed. (* TODO <<kfmap_kbind>> *) (* TODO <<kbind_kfmap>> *) End Monad. (** ** Functors (<<kfmap>>) *) (******************************************************************************) Section Functor. Context (S : Type -> Type) `{DTPreModule W S T} `{! DTM W T} {j : K}. (** *** Composition and identity law *) (******************************************************************************) Theorem kfmap_id : forall A, kfmap S j (@id A) = @id (S A). Proof. intros. unfold kfmap. rewrite <- (mfmap_id S). fequal. ext k. compare values k and j. now autorewrite with tea_tgt_eq. now autorewrite with tea_tgt_neq. Qed. Theorem kfmap_kfmap : forall (A : Type) (g f : A -> A), kfmap S j g ∘ kfmap S j f = kfmap S j (g ∘ f). Proof. intros. unfold kfmap. rewrite (mfmap_mfmap S). fequal. ext k. unfold Category.comp, kconst_comp. compare values j and k. - now autorewrite with tea_tgt_eq. - now autorewrite with tea_tgt_neq. Qed. (** *** Naturality w.r.t. <<mret>> *) (******************************************************************************) Lemma kfmap_comp_kret_eq {A} : forall (f : A -> A) (a : A), kfmap (T j) j f (mret T j a) = mret T j (f a). Proof. intros. unfold kfmap. rewrite mfmap_comp_mret. now rewrite tgt_eq. Qed. Lemma kfmap_comp_kret_neq {A} : forall (i : K) (Hneq : j <> i) (f : A -> A) (a : A), kfmap (T i) j f (mret T i a) = mret T i a. Proof. intros. unfold kfmap. rewrite mfmap_comp_mret. rewrite tgt_neq; auto. Qed. End Functor. (** ** Notations **) (******************************************************************************) Module Notations. Infix "⋆dtm" := compose_dtm (at level 40) : tealeaves_scope. Infix "⋆kdm" := compose_kdm (at level 40) : tealeaves_scope. Infix "⋆km" := compose_km (at level 40) : tealeaves_scope. End Notations. From Tealeaves Require Import Setlike.Functor Functors.Constant Functors.List Classes.Applicative. Import Setlike.Functor.Notations. Import Categories.TypeFamilies.Notations. Import Data.Sets.Notations. Import Product.Notations. Import Monoid.Notations. Import List.ListNotations. (** * Sorted lists with context *) (******************************************************************************) Section list. Context `{ix : Index} `{Monoid W}. Instance: MReturn (fun k A => list (W * (K * A))) := fun A (k : K) (a : A) => [(Ƶ, (k, a))]. (** This operation is a context- and tag-sensitive substitution operation on lists of annotated values. It is used internally to reason about the interaction between <<mbinddt>> and <<tomlistd>>. *) Fixpoint mbinddt_list `(f : forall (k : K), W * A -> list (W * (K * B))) (l : list (W * (K * A))) : list (W * (K * B)) := match l with | nil => nil | cons (w, (k, a)) rest => fmap list (incr w) (f k (w, a)) ++ mbinddt_list f rest end. Lemma mbinddt_list_nil : forall `(f : forall (k : K), W * A -> list (W * (K * B))), mbinddt_list f nil = nil. Proof. intros. easy. Qed. Lemma mbinddt_list_ret : forall `(f : forall (k : K), W * A -> list (W * (K * B))) (k : K) (a : A), mbinddt_list f (mret (fun k A => list (W * (K * A))) k a) = f k (Ƶ, a). Proof. intros. cbn. List.simpl_list. replace (incr (Ƶ : W)) with (@id (W * (K * B))). - now rewrite (fun_fmap_id list). - ext [w [k2 b]]. cbn. now simpl_monoid. Qed. Lemma mbinddt_list_cons : forall `(f : forall (k : K), W * A -> list (W * (K * B))) (w : W) (k : K) (a : A) (l : list (W * (K * A))), mbinddt_list f ((w, (k, a)) :: l) = fmap list (incr w) (f k (w, a)) ++ mbinddt_list f l. Proof. intros. easy. Qed. Lemma mbinddt_list_app : forall `(f : forall (k : K), W * A -> list (W * (K * B))) (l1 l2 : list (W * (K * A))), mbinddt_list f (l1 ++ l2) = mbinddt_list f l1 ++ mbinddt_list f l2. Proof. intros. induction l1. - easy. - destruct a as [w [k a]]. cbn. rewrite IHl1. now rewrite List.app_assoc. Qed. #[global] Instance : forall `(f : forall (k : K), W * A -> list (W * (K * B))), ApplicativeMorphism (const (list (W * (K * A)))) (const (list (W * (K * B)))) (const (mbinddt_list f)). Proof. intros. eapply ApplicativeMorphism_monoid_morphism. Unshelve. constructor; try typeclasses eauto. - easy. - intros. apply mbinddt_list_app. Qed. End list. (** * The <<Batch>> idiom *) (* This is not the true Batch functor, it has been specialized for its use case with DTMs. TODO: Generalize this so it can live in its own file. *) (******************************************************************************) Import Applicative.Notations. Section Batch. #[local] Generalizable Variables D. #[local] Set Implicit Arguments. Context `{ix : Index} {T : K -> Type -> Type} {W A B : Type}. Inductive Batch C : Type := | Go : C -> Batch C | Ap : forall (k : K), Batch (T k B -> C) -> W * A -> Batch C. Fixpoint fmap_Batch `{f : C -> D} `(c : Batch C) : Batch D := match c with | Go c => Go (f c) | @Ap _ k rest (pair w a) => Ap (@fmap_Batch (T k B -> C) (T k B -> D) (compose f) rest) (w, a) end. #[global] Instance Fmap_Batch : Fmap Batch := @fmap_Batch. Lemma fmap_id_Batch : forall (C : Type), fmap Batch id = @id (Batch C). Proof. intros. ext s. induction s. - easy. - unfold id in *. destruct p. now rewrite <- IHs at 2. Qed. Lemma fmap_fmap_Batch : forall (C D E : Type) (f : C -> D) (g : D -> E), fmap Batch g ∘ fmap Batch f = fmap Batch (g ∘ f). Proof. intros. unfold compose. ext s. generalize dependent E. generalize dependent D. induction s. - easy. - intros. destruct p. cbn. fequal. apply IHs. Qed. #[global, program] Instance Functor_Batch : Functor Batch := {| fun_fmap_id := fmap_id_Batch; fun_fmap_fmap := fmap_fmap_Batch; |}. (** ** Applicative Instance *) (******************************************************************************) #[global] Instance Pure_Batch : Pure Batch := fun (C : Type) (c : C) => Go c. Fixpoint mult_Batch `(jc : Batch C) `(jd : Batch D) : Batch (C * D) := match jd with | Go d => fmap Batch (fun (c : C) => (c, d)) jc | Ap rest (pair w a) => Ap (fmap Batch strength_arrow (mult_Batch jc rest)) (pair w a) end. #[global] Instance Mult_Batch : Mult Batch := fun C D '(c, d) => mult_Batch c d. #[local] Infix "⧆" := Ap (at level 51, left associativity) : tealeaves_scope. Lemma mult_Batch_rw1 : forall `(a : A) `(b : B), Go a ⊗ Go b = Go (a, b). Proof. easy. Qed. Lemma mult_Batch_rw2 : forall `(d : D) `(jc : Batch C), jc ⊗ Go d = fmap Batch (pair_right d) jc. Proof. intros. induction jc; easy. Qed. Lemma mult_Batch_rw3 : forall `(d : D) `(jc : Batch C), Go d ⊗ jc = fmap Batch (pair d) jc. Proof. induction jc. - easy. - destruct p. cbn; change (mult_Batch ?x ?y) with (x ⊗ y). fequal. rewrite IHjc. compose near jc on left. now rewrite (fun_fmap_fmap Batch). Qed. Lemma mult_Batch_rw4 : forall (w : W) (a : A) (k : K) `(jc : @Batch (T k B -> C)) `(d : D), (jc ⧆ (w, a)) ⊗ Go d = fmap Batch (costrength_arrow ∘ pair_right d) jc ⧆ (w, a). Proof. easy. Qed. Lemma mult_Batch_rw5 : forall (w : W) (a : A) (k : K) `(jc : @Batch (T k B -> C)) `(d : D), Go d ⊗ (jc ⧆ (w, a)) = fmap Batch (strength_arrow ∘ pair d) jc ⧆ (w, a). Proof. intros. cbn. change (mult_Batch ?x ?y) with (x ⊗ y) in *. fequal. rewrite (mult_Batch_rw3 d). compose near jc on left. now rewrite (fun_fmap_fmap Batch). Qed. Lemma mult_Batch_rw6 : forall (w1 w2 : W) (a1 a2 : A) (k : K) `(jc : Batch (T k B -> C)) `(jd : Batch (T k B -> D)), (jc ⧆ (w1, a1)) ⊗ (jd ⧆ (w2, a2)) = fmap Batch strength_arrow ((jc ⧆ (w1, a1)) ⊗ jd) ⧆ (w2, a2). Proof. reflexivity. Qed. Lemma app_pure_natural_Batch : forall (C D : Type) (f : C -> D) (x : C), fmap Batch f (pure Batch x) = pure Batch (f x). Proof. easy. Qed. Lemma app_mult_natural_Batch1 : forall (C D E : Type) (f : C -> D) (x : Batch C) (y : Batch E), fmap Batch f x ⊗ y = fmap Batch (map_fst f) (x ⊗ y). Proof. intros. generalize dependent E. induction y. - intros; cbn. compose near x. now do 2 rewrite (fun_fmap_fmap Batch). - destruct p. cbn; change (mult_Batch ?x ?y) with (x ⊗ y). rewrite IHy. compose near (x ⊗ y). do 2 rewrite (fun_fmap_fmap Batch). do 2 fequal. now ext [? ?]. Qed. Lemma app_mult_natural_Batch2 : forall (A B D : Type) (g : B -> D) (x : Batch A) (y : Batch B), x ⊗ fmap Batch g y = fmap Batch (map_snd g) (x ⊗ y). Proof. intros. generalize dependent D. induction y as [ANY any | ANY k rest IH [w a]]. - intros; cbn. compose near x on right. now rewrite (fun_fmap_fmap Batch). - intros; cbn. fequal. change (mult_Batch ?jx ?jy) with (jx ⊗ jy). rewrite IH. compose near (x ⊗ rest). do 2 rewrite (fun_fmap_fmap Batch). fequal. now ext [a' mk]. Qed. Lemma app_mult_natural_Batch : forall (A B C D : Type) (f : A -> C) (g : B -> D) (x : Batch A) (y : Batch B), fmap Batch f x ⊗ fmap Batch g y = fmap Batch (map_tensor f g) (x ⊗ y). Proof. intros. rewrite app_mult_natural_Batch1, app_mult_natural_Batch2. compose near (x ⊗ y) on left. rewrite (fun_fmap_fmap Batch). fequal. now ext [a b]. Qed. Lemma app_assoc_Batch : forall (A B C : Type) (x : Batch A) (y : Batch B) (z : Batch C), fmap Batch associator ((x ⊗ y) ⊗ z) = x ⊗ (y ⊗ z). Proof. intros. induction z as [ANY any | ANY k rest IH [w a]]. - do 2 rewrite mult_Batch_rw2. rewrite (app_mult_natural_Batch2). compose near (x ⊗ y) on left. now rewrite (fun_fmap_fmap Batch). - cbn. repeat change (mult_Batch ?jx ?jy) with (jx ⊗ jy). fequal. rewrite (app_mult_natural_Batch2). rewrite <- IH. compose near (x ⊗ y ⊗ rest). do 2 rewrite (fun_fmap_fmap Batch). compose near (x ⊗ y ⊗ rest) on right. rewrite (fun_fmap_fmap Batch). fequal. now ext [[? ?] ?]. Qed. Lemma app_unital_l_Batch : forall (A : Type) (x : Batch A), fmap Batch left_unitor (pure Batch tt ⊗ x) = x. Proof. intros. induction x as [ANY any | ANY k rest IH [w a]]. - easy. - cbn. change (mult_Batch ?jx ?jy) with (jx ⊗ jy). fequal. compose near (pure Batch tt ⊗ rest). rewrite (fun_fmap_fmap Batch). rewrite <- IH. repeat fequal. auto. Qed. Lemma app_unital_r_Batch : forall (A : Type) (x : Batch A), fmap Batch right_unitor (x ⊗ pure Batch tt) = x. Proof. intros. induction x as [ANY any | ANY k rest IH [w a]]. - easy. - cbn in *. fequal. rewrite <- IH at 2. compose near rest. now do 2 rewrite (fun_fmap_fmap Batch). Qed. Lemma app_mult_pure_Batch : forall (A B : Type) (a : A) (b : B), pure Batch a ⊗ pure Batch b = pure Batch (a, b). Proof. intros. easy. Qed. #[global, program] Instance App_Path : Applicative Batch. Next Obligation. apply app_mult_natural_Batch. Qed. Next Obligation. apply app_assoc_Batch. Qed. Next Obligation. apply app_unital_l_Batch. Qed. Next Obligation. apply app_unital_r_Batch. Qed. End Batch. Arguments Ap {ix} {T}%function_scope {W A B}%type_scope [C]%type_scope {k} _ _. (** ** Notations *) (******************************************************************************) Module Notations2. Infix "⧆" := Ap (at level 51, left associativity) : tealeaves_scope. End Notations2. Import Notations2. (** *** Examples of operations *) (******************************************************************************) Section demo. Context (S : Type -> Type) `{DTPreModule W S T} `{! DTM W T} (A B C X : Type) (a1 a2 : A) (b1 b2 b3 : B) (w1 w2 w3 w4 : W) (c1 c2 c3 c4 : C) (mk1 : C -> X) (mk2 : C -> C -> X) (mk0 : X). (* Check Go a1 ⊗ Go a2 : @Batch _ T W False False (A * A). Compute Go a1 ⊗ Go a2. Compute Go a1 ⊗ (Go mk1 ⧆ (w1, c1)). Compute (Go mk1 ⧆ (w1, c1)) ⊗ (Go mk1 ⧆ (w2, c2)). Compute (Go mk2 ⧆ (w1, c1) ⧆ (w2, c2)) ⊗ (Go mk1 ⧆ (w3, c3)). *) End demo. (** ** Functoriality of [Batch] *) (******************************************************************************) Section functoriality_Batch. Context (S : Type -> Type) `{DTPreModule W S T} `{! DTM W T}. Fixpoint mapfst_Batch {A1 A2 B C} (f : A1 -> A2) `(j : @Batch _ T W A1 B C) : @Batch _ T W A2 B C := match j with | Go a => Go a | Ap rest p => Ap (mapfst_Batch f rest) (map_snd f p) end. End functoriality_Batch. (** * The <<runBatch>> operation *) (******************************************************************************) Fixpoint runBatch {ix : Index} {T : K -> Type -> Type} {W A B : Type} {F : Type -> Type} `{Fmap F} `{Mult F} `{Pure F} (ϕ : forall (k : K), W * A -> F (T k B)) `(j : @Batch ix T W A B C) : F C := match j with | Go a => pure F a | @Ap _ _ _ _ _ _ k rest (pair w a) => runBatch ϕ rest <⋆> ϕ k (w, a) end. Section runBatch_rw. Context (S : Type -> Type) `{DTPreModule W S T} `{! DTM W T}. Context (A B C : Type) `{Applicative F} (f : forall k, W * A -> F (T k B)). Lemma runBatch_rw1 (c : C) : runBatch f (Go c) = pure F c. Proof. reflexivity. Qed. Lemma runBatch_rw2 (k : K) (w : W) (a : A) (rest : Batch (T k B -> C)) : runBatch f (rest ⧆ (w, a)) = runBatch f rest <⋆> f k (w, a). Proof. reflexivity. Qed. End runBatch_rw. (** ** Naturality of of <<runBatch>> *) (******************************************************************************) Section runBatch_naturality. Context (S : Type -> Type) `{DTPreModule W S T} `{! DTM W T} `{Applicative F}. Context (A B C D : Type) `{Applicative F} (ϕ : forall k, W * A -> F (T k B)). Lemma natural_runBatch (f : C -> D) (j : @Batch _ T W A B C) : fmap F f (runBatch ϕ j) = runBatch ϕ (fmap Batch f j). Proof. generalize dependent D. induction j; intros. - cbn. now rewrite (app_pure_natural F). - destruct p. cbn. rewrite fmap_ap. fequal. now rewrite IHj. Qed. End runBatch_naturality. (** ** <<runBatch>> is an applicative morphism **) (******************************************************************************) Section runBatch_morphism. Context (S : Type -> Type) `{DTPreModule W S T} `{! DTM W T}. Context (A B : Type) `{Applicative F} (f : forall k, W * A -> F (T k B)). Lemma appmor_pure_runBatch : forall (C : Type) (c : C), runBatch f (pure Batch c) = pure F c. Proof. easy. Qed. Lemma appmor_mult_runBatch : forall (C D : Type) (x : Batch C) (y : Batch D), runBatch f (x ⊗ y) = runBatch f x ⊗ runBatch f y. Proof. intros. generalize dependent x. induction y. - intros. rewrite mult_Batch_rw2. rewrite runBatch_rw1. rewrite triangle_4. rewrite natural_runBatch; auto. - intros. destruct p. rewrite runBatch_rw2. unfold ap. rewrite (app_mult_natural_r F). rewrite <- (app_assoc F). rewrite <- IHy. clear IHy. compose near (runBatch f (x ⊗ y) ⊗ f k (w, a)). rewrite (fun_fmap_fmap F). cbn. unfold ap. change (mult_Batch ?jx ?jy) with (jx ⊗ jy). rewrite <- natural_runBatch; auto. rewrite (app_mult_natural_l F). compose near (runBatch f (x ⊗ y) ⊗ f k (w, a)) on left. rewrite (fun_fmap_fmap F). fequal. now ext [[? ?] ?]. Qed. #[global] Instance Morphism_store_fold: ApplicativeMorphism Batch F (@runBatch _ T W A B F _ _ _ f). Proof. constructor; try typeclasses eauto. - intros. now rewrite natural_runBatch. - intros. easy. - intros. apply appmor_mult_runBatch. Qed. End runBatch_morphism. (** ** <<runBatch>> commutes with applicative morphisms **) (******************************************************************************) Section runBatch_morphism. #[local] Generalizable All Variables. Context (S : Type -> Type) `{DTPreModule W S T} `{! DTM W T} {A B C : Type} `{Applicative F} `{Applicative G} `{! ApplicativeMorphism F G ψ} (f : forall k, W * A -> F (T k B)). Lemma runBatch_morphism `(j : @Batch _ T W A B C) : @ψ C (runBatch f j) = runBatch (fun k => @ψ (T k B) ∘ f k) j. Proof. induction j. - cbn. now rewrite (appmor_pure F G). - destruct p. cbn. rewrite ap_morphism_1. now rewrite IHj. Qed. End runBatch_morphism. (** * Shape and contents *) (******************************************************************************) (** ** Operations *) (******************************************************************************) Section shape_and_contents. Context (S : Type -> Type) `{DTPreModule W S T} `{! DTM W T}. Definition shape {A} : S A -> S unit := mfmap S (const (const tt)). Definition tomlistd_gen {A} (fake : Type) : S A -> list (W * (K * A)) := mfmapdt (B := fake) S (const (list (W * (K * A)))) (fun k '(w, a) => [(w, (k, a))]). Definition tomlistd {A} : S A -> list (W * (K * A)) := tomlistd_gen False. Definition tomsetd {A} : S A -> W * (K * A) -> Prop := toset list ∘ tomlistd. Definition tomlist {A} : S A -> list (K * A) := fmap list (extract (W ×)) ∘ tomlistd. Definition tomset {A} : S A -> K * A -> Prop := toset list ∘ tomlist. Fixpoint filterk {A} (k : K) (l : list (W * (K * A))) : list (W * A) := match l with | nil => nil | cons (w, (j, a)) ts => if k == j then (w, a) :: filterk k ts else filterk k ts end. Definition toklistd {A} (k : K) : S A -> list (W * A) := filterk k ∘ tomlistd. Definition toksetd {A} (k : K) : S A -> W * A -> Prop := toset list ∘ toklistd k. Definition toklist {A} (k : K) : S A -> list A := fmap list (extract (W ×)) ∘ @toklistd A k. End shape_and_contents. (** ** Notations *) (******************************************************************************) Module Notations3. Notation "x ∈md t" := (tomsetd _ t x) (at level 50) : tealeaves_multi_scope. Notation "x ∈m t" := (tomset _ t x) (at level 50) : tealeaves_multi_scope. End Notations3. Import Notations3. (** ** Rewriting rules for <<filterk>> *) (******************************************************************************) Section rw_filterk. Context `{ix : Index} {W A : Type} (k : K). Implicit Types (l : list (W * (K * A))) (w : W) (a : A). Lemma filterk_nil : filterk k (nil : list (W * (K * A))) = nil. Proof. reflexivity. Qed. Lemma filterk_cons_eq : forall l w a, filterk k (cons (w, (k, a)) l) = (w, a) :: filterk k l. Proof. intros. cbn. compare values k and k. Qed. Lemma filterk_cons_neq : forall l w a j, j <> k -> filterk k (cons (w, (j, a)) l) = filterk k l. Proof. intros. cbn. compare values k and j. Qed. Lemma filterk_app : forall l1 l2, filterk k (l1 ++ l2) = filterk k l1 ++ filterk k l2. Proof. intros. induction l1. - reflexivity. - destruct a as [w [i a]]. compare values i and k. + rewrite <- (List.app_comm_cons l1). rewrite filterk_cons_eq. rewrite filterk_cons_eq. rewrite <- (List.app_comm_cons (filterk k l1)). now rewrite <- IHl1. + rewrite <- (List.app_comm_cons l1). rewrite filterk_cons_neq; auto. rewrite filterk_cons_neq; auto. Qed. End rw_filterk. #[export] Hint Rewrite @filterk_nil @filterk_cons_eq @filterk_cons_neq @filterk_app : tea_list. (** ** Auxiliary lemmas for constant applicative functors *) (******************************************************************************) Section lemmas. #[local] Generalizable Variable M. Context (S : Type -> Type) `{DTPreModule W S T} `{! DTM W T}. Lemma mbinddt_constant_applicative1 `{Monoid M} {B : Type} `(f : forall (k : K), W * A -> const M (T k B)) : mbinddt (B := B) S (const M) f = mbinddt (B := False) S (const M) (f : forall (k : K), W * A -> const M (T k False)). Proof. change_right (fmap (B := S B) (const M) (mfmap S (const exfalso)) ∘ (mbinddt (B := False) S (const M) (f : forall (k : K), W * A -> const M (T k False)))). rewrite (mfmap_mbinddt S (F := const M)). reflexivity. Qed. Lemma mbinddt_constant_applicative2 (fake1 fake2 : Type) `{Monoid M} `(f : forall (k : K), W * A -> const M (T k B)) : mbinddt (B := fake1) S (const M) (f : forall (k : K), W * A -> const M (T k fake1)) = mbinddt (B := fake2) S (const M) (f : forall (k : K), W * A -> const M (T k fake2)). Proof. intros. rewrite (mbinddt_constant_applicative1 (B := fake1)). rewrite (mbinddt_constant_applicative1 (B := fake2)). easy. Qed. Lemma tomlistd_equiv1 : forall (fake : Type) (A : Type), tomlistd_gen S (A := A) False = tomlistd_gen S fake. Proof. intros. unfold tomlistd_gen at 2, mfmapdt. now rewrite (mbinddt_constant_applicative2 fake False). Qed. Lemma tomlistd_equiv : forall (fake1 fake2 : Type) (A : Type), tomlistd_gen S (A := A) fake1 = tomlistd_gen S fake2. Proof. intros. rewrite <- tomlistd_equiv1. rewrite <- (tomlistd_equiv1 fake2). easy. Qed. End lemmas. (** ** Relating <<∈m>> and <<∈md>> *) (******************************************************************************) Section DTM_membership_lemmas. Context (S : Type -> Type) `{DTPreModule W S T} `{! DTM W T}. Lemma ind_iff_in : forall (k : K) (A : Type) (a : A) (t : S A), (k, a) ∈m t <-> exists w, (w, (k, a)) ∈md t. Proof. intros. unfold tomset, tomsetd, tomlist, compose. induction (tomlistd S t). - cbv; split; intros []; easy. - rewrite fmap_list_cons, in_list_cons. rewrite IHl. setoid_rewrite in_list_cons. split; [ intros [Hfst|[w Hrest]] | intros [w [rest1|rest2]]]. + destruct a0 as [w [k' a']]. exists w. left. rewrite Hfst. easy. + exists w. now right. + left. now rewrite <- rest1. + right. rewrite <- IHl. rewrite (in_fmap_iff list). now exists (w, (k, a)). Qed. Corollary ind_implies_in : forall (k : K) (A : Type) (a : A) (w : W) (t : S A), (w, (k, a)) ∈md t -> (k, a) ∈m t. Proof. intros. rewrite ind_iff_in. eauto. Qed. End DTM_membership_lemmas. (** ** Characterizing membership in list operations *) (******************************************************************************) Section DTM_tolist. Context (S : Type -> Type) `{DTPreModule W S T} `{! DTM W T}. Lemma in_filterk_iff : forall (A : Type) (l : list (W * (K * A))) (k : K) (a : A) (w : W), (w, a) ∈ filterk k l <-> (w, (k, a)) ∈ l. Proof. intros. induction l. - cbn. easy. - destruct a0 as [w' [j a']]. cbn. compare values k and j. + cbn. rewrite IHl. clear. split. { intros [hyp1 | hyp2]. - inverts hyp1. now left. - now right. } { intros [hyp1 | hyp2]. - inverts hyp1. now left. - now right. } + rewrite <- IHl. split. { intro hyp. now right. } { intros [hyp1 | hyp2]. - inverts hyp1. contradiction. - auto. } Qed. Lemma ind_iff_in_tomlistd : forall (A : Type) (k : K) (a : A) (w : W) (t : S A), (w, (k, a)) ∈md t <-> (w, (k, a)) ∈ tomlistd S t. Proof. reflexivity. Qed. Lemma in_iff_in_tomlistd : forall (A : Type) (k : K) (a : A) (t : S A), (k, a) ∈m t <-> (k, a) ∈ tomlist S t. Proof. reflexivity. Qed. Lemma ind_iff_in_toklistd : forall (A : Type) (k : K) (a : A) (w : W) (t : S A), (w, (k, a)) ∈md t <-> (w, a) ∈ toklistd S k t. Proof. intros. unfold toklistd. unfold compose. rewrite in_filterk_iff. reflexivity. Qed. Lemma in_iff_in_toklist : forall (A : Type) (k : K) (a : A) (t : S A), (k, a) ∈m t <-> a ∈ toklist S k t. Proof. intros. unfold toklist. unfold compose. rewrite (in_fmap_iff list). split. - intro hyp. rewrite ind_iff_in in hyp. destruct hyp as [w' hyp]. exists (w', a). rewrite ind_iff_in_toklistd in hyp. auto. - intros [[w' a'] [hyp1 hyp2]]. rewrite ind_iff_in. exists w'. rewrite <- ind_iff_in_toklistd in hyp1. cbn in hyp2. now subst. Qed. End DTM_tolist. (** ** Interaction between <<tomlistd>> and <<mret>>/<<mbindd>> *) (******************************************************************************) Section DTM_tolist. Context (S : Type -> Type) `{DTPreModule W S T} `{! DTM W T}. Lemma tomlistd_gen_mret : forall (A B : Type) (a : A) (k : K), tomlistd_gen (T k) B (mret T k a) = [ (Ƶ, (k, a)) ]. Proof. intros. unfold tomlistd_gen. compose near a on left. now rewrite mfmapdt_comp_mret. Qed. Corollary tomlistd_mret : forall (A : Type) (a : A) (k : K), tomlistd (T k) (mret T k a) = [ (Ƶ, (k, a)) ]. Proof. intros. unfold tomlistd. apply tomlistd_gen_mret. Qed. Corollary tomsetd_mret : forall (A : Type) (a : A) (k : K), tomsetd (T k) (mret T k a) = {{ (Ƶ, (k, a)) }}. Proof. intros. unfold tomsetd, compose. rewrite tomlistd_mret. solve_basic_set. Qed. Corollary tomlist_mret : forall (A : Type) (a : A) (k : K), tomlist (T k) (mret T k a) = [ (k, a) ]. Proof. intros. unfold tomlist, compose. rewrite tomlistd_mret. easy. Qed. Corollary tomset_mret : forall (A : Type) (a : A) (k : K), tomset (T k) (mret T k a) = {{ (k, a) }}. Proof. intros. unfold tomset, compose. rewrite tomlist_mret. solve_basic_set. Qed. Lemma tomlistd_gen_mbindd : forall (fake : Type) `(f : forall k, W * A -> T k B) (t : S A), tomlistd_gen S fake (mbindd S f t) = mbinddt_list (fun k '(w, a) => tomlistd_gen (T k) fake (f k (w, a))) (tomlistd_gen S fake t). Proof. intros. unfold tomlistd_gen, mfmapdt. compose near t on left. rewrite (mbinddt_mbindd S). compose near t on right. change (mbinddt_list ?f) with (const (mbinddt_list f) (S fake)). #[local] Set Keyed Unification. (* TODO figure out why this is here. *) rewrite (dtp_mbinddt_morphism W S T (const (list (W * (K * A)))) (const (list (W * (K * B)))) (A := A) (B := fake)). #[local] Unset Keyed Unification. fequal. ext k [w a]. cbn. change (fmap list ?f) with (const (fmap list f) (S B)). List.simpl_list. compose near (f k (w, a)) on right. (* for some reason I can't rewrite without posing first. *) pose (rw := dtp_mbinddt_morphism W (T k) T (const (list (W * (K * B)))) (const (list (W * (K * B)))) (ϕ := (const (fmap list (incr w)))) (A := B) (B := fake)). rewrite rw. fequal. now ext k2 [w2 b]. Qed. Corollary tomlistd_mbindd : forall `(f : forall k, W * A -> T k B) (t : S A), tomlistd S (mbindd S f t) = mbinddt_list (fun k '(w, a) => tomlistd (T k) (f k (w, a))) (tomlistd S t). Proof. intros. unfold tomlistd. apply tomlistd_gen_mbindd. Qed. End DTM_tolist. (** ** Characterizing occurrences post-operation *) (******************************************************************************) Section DTM_membership. Context (S : Type -> Type) `{DTPreModule W S T} `{! DTM W T}. (** *** Occurrences in <<mret>> *) (******************************************************************************) Lemma ind_mret_iff : forall (A : Type) (a1 a2 : A) (k1 k2 : K) (w : W), (w, (k2, a2)) ∈md mret T k1 a1 <-> w = Ƶ /\ k1 = k2 /\ a1 = a2. Proof. intros. rewrite (tomsetd_mret (T k1)). simpl_set. split. - inversion 1; now subst. - introv [? [? ?]]. now subst. Qed. Corollary in_mret_iff : forall (A : Type) (a1 a2 : A) (k1 k2 : K), (k2, a2) ∈m mret T k1 a1 <-> k1 = k2 /\ a1 = a2. Proof. intros. rewrite ind_iff_in. setoid_rewrite ind_mret_iff. firstorder. Qed. Lemma ind_mret_eq_iff : forall (A : Type) (a1 a2 : A) (k : K) (w : W), (w, (k, a2)) ∈md mret T k a1 <-> w = Ƶ /\ a1 = a2. Proof. intros. rewrite ind_mret_iff. clear. firstorder. Qed. Lemma ind_mret_neq_iff : forall (A : Type) (a1 a2 : A) (k j : K) (w : W), k <> j -> (w, (j, a2)) ∈md mret T k a1 <-> False. Proof. intros. rewrite ind_mret_iff. firstorder. Qed. Corollary in_mret_eq_iff : forall (A : Type) (a1 a2 : A) (k : K), (k, a2) ∈m mret T k a1 <-> a1 = a2. Proof. intros. rewrite in_mret_iff. firstorder. Qed. Corollary in_mret_neq_iff : forall (A : Type) (a1 a2 : A) (k j : K), k <> j -> (j, a2) ∈m mret T k a1 <-> False. Proof. intros. rewrite ind_iff_in. setoid_rewrite ind_mret_iff. firstorder. Qed. (** *** Occurrences in <<mbindd>> with context *) (******************************************************************************) Lemma ind_mbindd_iff1 : forall `(f : forall k, W * A -> T k B) (t : S A) (k2 : K) (wtotal : W) (b : B), (wtotal, (k2, b)) ∈md mbindd S f t -> exists (k1 : K) (w1 w2 : W) (a : A), (w1, (k1, a)) ∈md t /\ (w2, (k2, b)) ∈md f k1 (w1, a) /\ wtotal = w1 ● w2. Proof. introv hyp. unfold tomsetd, compose in *. rewrite (tomlistd_mbindd S) in hyp. induction (tomlistd S t). - inversion hyp. - destruct a as [w [k a]]. rewrite mbinddt_list_cons in hyp. rewrite in_list_app in hyp. destruct hyp as [hyp1 | hyp2]. + rewrite (in_fmap_iff list) in hyp1. destruct hyp1 as [[w2 [k2' b']] [hyp1 hyp2]]. inversion hyp2; subst. exists k w w2 a. splits. { rewrite in_list_cons. now left. } { auto. } { easy. } + apply IHl in hyp2. clear IHl. destruct hyp2 as [k1 [w1 [w2 [a' [hyp1 [hyp2 hyp3]] ]]]]. subst. repeat eexists. { rewrite in_list_cons. right. eauto. } { auto. } Qed. Lemma ind_mbindd_iff2 : forall `(f : forall k, W * A -> T k B) (t : S A) (k2 : K) (wtotal : W) (b : B), (exists (k1 : K) (w1 w2 : W) (a : A), (w1, (k1, a)) ∈md t /\ (w2, (k2, b)) ∈md f k1 (w1, a) /\ wtotal = w1 ● w2) -> (wtotal, (k2, b)) ∈md mbindd S f t. Proof. introv [k1 [w1 [w2 [a [hyp1 [hyp2 hyp3]]]]]]. subst. unfold tomsetd, compose in *. rewrite (tomlistd_mbindd S). induction (tomlistd S t). - inversion hyp1. - destruct a0 as [w [k' a']]. rewrite mbinddt_list_cons. simpl_list. rewrite in_list_cons in hyp1. destruct hyp1 as [hyp1 | hyp1]. + inverts hyp1. left. rewrite (in_fmap_iff list). exists (w2, (k2, b)). now splits. + right. now apply IHl in hyp1. Qed. Theorem ind_mbindd_iff : forall `(f : forall k, W * A -> T k B) (t : S A) (k2 : K) (wtotal : W) (b : B), (wtotal, (k2, b)) ∈md mbindd S f t <-> exists (k1 : K) (w1 w2 : W) (a : A), (w1, (k1, a)) ∈md t /\ (w2, (k2, b)) ∈md f k1 (w1, a) /\ wtotal = w1 ● w2. Proof. split; auto using ind_mbindd_iff1, ind_mbindd_iff2. Qed. (** *** Corollaries for other operations *) (******************************************************************************) Corollary ind_mbind_iff : forall `(f : forall k, A -> T k B) (t : S A) (k2 : K) (wtotal : W) (b : B), (wtotal, (k2, b)) ∈md mbind S f t <-> exists (k1 : K) (w1 w2 : W) (a : A), (w1, (k1, a)) ∈md t /\ (w2, (k2, b)) ∈md f k1 a /\ wtotal = w1 ● w2. Proof. intros. rewrite mbind_to_mbindd. apply ind_mbindd_iff. Qed. Corollary ind_mfmapd_iff : forall `(f : forall k, W * A -> B) (t : S A) (k : K) (w : W) (b : B), (w, (k, b)) ∈md mfmapd S f t <-> exists (a : A), (w, (k, a)) ∈md t /\ b = f k (w, a). Proof. intros. unfold mfmapd, compose. setoid_rewrite ind_mbindd_iff. unfold_ops @Fmap_I. setoid_rewrite ind_mret_iff. split. - intros [k1 [w1 [w2 [a [hyp1 [[hyp2 [hyp2' hyp2'']] hyp3]]]]]]. subst. exists a. simpl_monoid. auto. - intros [a [hyp1 hyp2]]. subst. repeat eexists. easy. now simpl_monoid. Qed. Corollary ind_mfmap_iff : forall `(f : K -> A -> B) (t : S A) (k : K) (w : W) (b : B), (w, (k, b)) ∈md mfmap S f t <-> exists (a : A), (w, (k, a)) ∈md t /\ b = f k a. Proof. intros. rewrite (mfmap_to_mfmapd S). rewrite ind_mfmapd_iff. easy. Qed. (** *** Occurrences without context *) (******************************************************************************) Theorem in_mbindd_iff : forall `(f : forall k, W * A -> T k B) (t : S A) (k2 : K) (b : B), (k2, b) ∈m mbindd S f t <-> exists (k1 : K) (w1 : W) (a : A), (w1, (k1, a)) ∈md t /\ (k2, b) ∈m (f k1 (w1, a)). Proof. intros. rewrite ind_iff_in. setoid_rewrite ind_mbindd_iff. split. - intros [wtotal [k1 [w1 [w2 [a [hyp1 [hyp2 hyp3]]]]]]]. exists k1 w1 a. split; [auto|]. apply (ind_implies_in) in hyp2. auto. - intros [k1 [w1 [a [hyp1 hyp2]]]]. rewrite ind_iff_in in hyp2. destruct hyp2 as [w2 rest]. exists (w1 ● w2) k1 w1 w2 a. intuition. Qed. (** *** Corollaries for other operations *) (******************************************************************************) Corollary in_mbind_iff : forall `(f : forall k, A -> T k B) (t : S A) (k2 : K) (b : B), (k2, b) ∈m mbind S f t <-> exists (k1 : K) (a : A), (k1, a) ∈m t /\ (k2, b) ∈m f k1 a. Proof. intros. unfold mbind, compose. setoid_rewrite ind_iff_in. setoid_rewrite ind_mbindd_iff. cbn. split. - firstorder. - intros [k1 [a [[w1 hyp1] [w hyp2]]]]. repeat eexists; eauto. Qed. Corollary in_mfmapd_iff : forall `(f : forall k, W * A -> B) (t : S A) (k : K) (b : B), (k, b) ∈m mfmapd S f t <-> exists (w : W) (a : A), (w, (k, a)) ∈md t /\ b = f k (w, a). Proof. intros. setoid_rewrite ind_iff_in. now setoid_rewrite ind_mfmapd_iff. Qed. Corollary in_mfmap_iff : forall `(f : forall k, A -> B) (t : S A) (k : K) (b : B), (k, b) ∈m mfmap S f t <-> exists (a : A), (k, a) ∈m t /\ b = f k a. Proof. intros. setoid_rewrite ind_iff_in. setoid_rewrite ind_mfmap_iff. firstorder. Qed. End DTM_membership. (** ** Characterizing occurrences post-operation (targetted operations) *) (******************************************************************************) Section DTM_membership_targetted. Context (S : Type -> Type) `{DTPreModule W S T} `{! DTM W T}. Context (j : K) {A : Type}. (** *** Occurrences in <<kbindd>> with context *) (******************************************************************************) Lemma ind_kbindd_eq_iff1 : forall `(f : W * A -> T j A) (t : S A) (wtotal : W) (a2 : A), (wtotal, (j, a2)) ∈md kbindd S j f t -> exists (w1 w2 : W) (a1 : A), (w1, (j, a1)) ∈md t /\ (w2, (j, a2)) ∈md f (w1, a1) /\ wtotal = w1 ● w2. Proof. introv hyp. unfold kbindd in hyp. apply (ind_mbindd_iff1 S) in hyp. destruct hyp as [k1 [w1 [w2 [a [hyp1 [hyp2 hyp3]]]]]]. subst. compare values j and k1. + exists w1 w2 a. splits. { auto. } { rewrite btgd_eq in hyp2. auto. } { reflexivity. } + rewrite btgd_neq in hyp2; auto. unfold compose in hyp2; cbn in hyp2. rewrite ind_mret_iff in hyp2. destructs hyp2. subst. contradiction. Qed. Lemma ind_kbindd_eq_iff2 : forall `(f : W * A -> T j A) (t : S A) (wtotal : W) (a2 : A), (exists (w1 w2 : W) (a1 : A), (w1, (j, a1)) ∈md t /\ (w2, (j, a2)) ∈md f (w1, a1) /\ wtotal = w1 ● w2) -> (wtotal, (j, a2)) ∈md kbindd S j f t. Proof. introv [w1 [w2 [a1 hyp]]]. destructs hyp. unfold kbindd. apply (ind_mbindd_iff2 S). exists j w1 w2 a1. rewrite btgd_eq. auto. Qed. Theorem ind_kbindd_eq_iff : forall `(f : W * A -> T j A) (t : S A) (wtotal : W) (a2 : A), (wtotal, (j, a2)) ∈md kbindd S j f t <-> exists (w1 w2 : W) (a1 : A), (w1, (j, a1)) ∈md t /\ (w2, (j, a2)) ∈md f (w1, a1) /\ wtotal = w1 ● w2. Proof. split; auto using ind_kbindd_eq_iff1, ind_kbindd_eq_iff2. Qed. Lemma ind_kbindd_neq_iff1 : forall (i : K) (Hneq : j <> i) `(f : W * A -> T j A) (t : S A) (wtotal : W) (a2 : A), (wtotal, (i, a2)) ∈md kbindd S j f t -> (wtotal, (i, a2)) ∈md t \/ (exists (w1 w2 : W) (a1 : A), (w1, (j, a1)) ∈md t /\ (w2, (i, a2)) ∈md f (w1, a1) /\ wtotal = w1 ● w2). Proof. introv ? hyp. unfold kbindd in hyp. apply (ind_mbindd_iff1 S) in hyp. destruct hyp as [k1 [w1 [w2 [a [hyp1 [hyp2 hyp3]]]]]]. subst. compare values j and k1. + right. exists w1 w2 a. rewrite btgd_eq in hyp2. splits; auto. + left. rewrite btgd_neq in hyp2; auto. unfold compose in hyp2. cbn in hyp2. rewrite ind_mret_iff in hyp2. destructs hyp2; subst. simpl_monoid. auto. Qed. Lemma ind_kbindd_neq_iff2 : forall (i : K) (Hneq : j <> i) `(f : W * A -> T j A) (t : S A) (wtotal : W) (a2 : A), (wtotal, (i, a2)) ∈md t \/ (exists (w1 w2 : W) (a1 : A), (w1, (j, a1)) ∈md t /\ (w2, (i, a2)) ∈md f (w1, a1) /\ wtotal = w1 ● w2) -> (wtotal, (i, a2)) ∈md kbindd S j f t. Proof. introv ? hyp. destruct hyp as [hyp | hyp]. - apply (ind_mbindd_iff2 S). exists i wtotal Ƶ a2. splits. { auto. } { rewrite btgd_neq; auto. unfold compose; cbn. rewrite ind_mret_iff; auto. } { now simpl_monoid. } - destruct hyp as [w1 [w2 [a1 [hyp1 [hyp2 hyp3]]]]]. subst. apply (ind_mbindd_iff2 S). exists j w1 w2 a1. rewrite btgd_eq. auto. Qed. Theorem ind_kbindd_neq_iff : forall (i : K) (Hneq : j <> i) `(f : W * A -> T j A) (t : S A) (wtotal : W) (a2 : A), (wtotal, (i, a2)) ∈md kbindd S j f t <-> (wtotal, (i, a2)) ∈md t \/ (exists (w1 w2 : W) (a1 : A), (w1, (j, a1)) ∈md t /\ (w2, (i, a2)) ∈md f (w1, a1) /\ wtotal = w1 ● w2). Proof. split; auto using ind_kbindd_neq_iff1, ind_kbindd_neq_iff2. Qed. (** *** Corollaries for <<kbind>>, <<kfmapd>>, and <<kfmap>>*) (******************************************************************************) Corollary ind_kbind_eq_iff : forall `(f : A -> T j A) (t : S A) (wtotal : W) (a2 : A), (wtotal, (j, a2)) ∈md kbind S j f t <-> exists (w1 w2 : W) (a1 : A), (w1, (j, a1)) ∈md t /\ (w2, (j, a2)) ∈md f a1 /\ wtotal = w1 ● w2. Proof. intros. rewrite kbind_to_kbindd. now rewrite (ind_kbindd_eq_iff). Qed. Corollary ind_kbind_neq_iff : forall (i : K) (Hneq : j <> i) `(f : A -> T j A) (t : S A) (wtotal : W) (a2 : A), (wtotal, (i, a2)) ∈md kbind S j f t <-> (wtotal, (i, a2)) ∈md t \/ (exists (w1 w2 : W) (a1 : A), (w1, (j, a1)) ∈md t /\ (w2, (i, a2)) ∈md f a1 /\ wtotal = w1 ● w2). Proof. intros. rewrite kbind_to_kbindd. rewrite ind_kbindd_neq_iff; auto. unfold compose. cbn. easy. Qed. Corollary ind_kfmapd_eq_iff : forall `(f : W * A -> A) (t : S A) (w : W) (a2 : A), (w, (j, a2)) ∈md kfmapd S j f t <-> exists (a1 : A), (w, (j, a1)) ∈md t /\ a2 = f (w, a1). Proof. intros. unfold kfmapd. rewrite (ind_mfmapd_iff S). now rewrite tgtd_eq. Qed. Corollary ind_kfmapd_neq_iff : forall (i : K) (Hneq : j <> i) `(f : W * A -> A) (t : S A) (w : W) (a2 : A), (w, (i, a2)) ∈md kfmapd S j f t <-> (w, (i, a2)) ∈md t. Proof. intros. unfold kfmapd. rewrite (ind_mfmapd_iff S). rewrite tgtd_neq; auto. cbn. split. - intros [a [hyp eq]]; subst. auto. - intros hyp. now (exists a2). Qed. Corollary ind_kfmap_eq_iff : forall `(f : A -> A) (t : S A) (w : W) (a2 : A), (w, (j, a2)) ∈md kfmap S j f t <-> exists (a1 : A), (w, (j, a1)) ∈md t /\ a2 = f a1. Proof. intros. unfold kfmap. rewrite (ind_mfmap_iff S). now rewrite tgt_eq. Qed. Corollary ind_kfmap_neq_iff : forall (i : K) (Hneq : j <> i) `(f : A -> A) (t : S A) (w : W) (a2 : A), (w, (i, a2)) ∈md kfmap S j f t <-> (w, (i, a2)) ∈md t. Proof. intros. unfold kfmap. rewrite (ind_mfmap_iff S). rewrite tgt_neq; auto. split. - intros [a [hyp eq]]; subst. auto. - intros hyp. now (exists a2). Qed. (** *** Occurrences without context *) (******************************************************************************) Theorem in_kbindd_eq_iff : forall `(f : W * A -> T j A) (t : S A) (a2 : A), (j, a2) ∈m kbindd S j f t <-> exists (w1 : W) (a1 : A), (w1, (j, a1)) ∈md t /\ (j, a2) ∈m f (w1, a1). Proof. intros. rewrite ind_iff_in. setoid_rewrite ind_iff_in. setoid_rewrite ind_kbindd_eq_iff. split. - intros [w [w1 [w2 [a1 [hyp1 [hyp2 hyp3]]]]]]. eexists. eexists. split; eauto. - intros [w [a1 [hyp1 [w2 hyp2]]]]. repeat eexists; eauto. Qed. Theorem in_kbindd_neq_iff : forall (i : K) (Hneq : j <> i) `(f : W * A -> T j A) (t : S A) (a2 : A), (i, a2) ∈m kbindd S j f t <-> (i, a2) ∈m t \/ (exists (w1 : W) (a1 : A), (w1, (j, a1)) ∈md t /\ (i, a2) ∈m f (w1, a1)). Proof. intros. rewrite ind_iff_in. setoid_rewrite ind_iff_in. setoid_rewrite ind_kbindd_neq_iff; auto. split. - intros [w [hyp | hyp]]. + left. eauto. + right. destruct hyp as [w1 [w2 [a1 [hyp1 [hyp2 hyp3]]]]]. repeat eexists; eauto. - intros [hyp | hyp]. + destruct hyp as [w hyp]. eexists. left. eauto. + destruct hyp as [w1 [a1 [hyp1 [w2 hyp2]]]]. eexists. right. repeat eexists; eauto. Qed. Corollary in_kbind_eq_iff : forall `(f : A -> T j A) (t : S A) (a2 : A), (j, a2) ∈m kbind S j f t <-> exists (a1 : A), (j, a1) ∈m t /\ (j, a2) ∈m f a1. Proof. intros. rewrite kbind_to_kbindd. rewrite (in_kbindd_eq_iff). setoid_rewrite ind_iff_in at 2. unfold compose. cbn. firstorder. Qed. Corollary in_kbind_neq_iff : forall (i : K) (Hneq : j <> i) `(f : A -> T j A) (t : S A) (a2 : A), (i, a2) ∈m kbind S j f t <-> (i, a2) ∈m t \/ (exists (a1 : A), (j, a1) ∈m t /\ (i, a2) ∈m f a1). Proof. intros. rewrite kbind_to_kbindd. rewrite in_kbindd_neq_iff; auto. split. - intros [hyp|hyp]. + now left. + right. unfold compose in hyp. cbn in hyp. destruct hyp as [? [a1 [hyp1 hyp2]]]. apply ind_implies_in in hyp1. eauto. - intros [hyp|hyp]. + now left. + right. destruct hyp as [a1 [hyp1 hyp2]]. rewrite ind_iff_in in hyp1. destruct hyp1 as [w1 hyp1]. exists w1 a1. auto. Qed. Corollary in_kfmapd_eq_iff : forall `(f : W * A -> A) (t : S A) (a2 : A), (j, a2) ∈m kfmapd S j f t <-> exists (w : W) (a1 : A), (w, (j, a1)) ∈md t /\ a2 = f (w, a1). Proof. intros. unfold kfmapd. rewrite (in_mfmapd_iff S). now rewrite tgtd_eq. Qed. Corollary in_kfmapd_neq_iff : forall (i : K) (Hneq : j <> i) `(f : W * A -> A) (t : S A) (a2 : A), (i, a2) ∈m kfmapd S j f t <-> (i, a2) ∈m t. Proof. intros. unfold kfmapd. rewrite (in_mfmapd_iff S). rewrite tgtd_neq; auto. cbn. split. - intros [w [a [hyp eq]]]; subst. eapply ind_implies_in; eauto. - intros hyp. rewrite ind_iff_in in hyp. destruct hyp as [w hyp]. eauto. Qed. Corollary in_kfmap_eq_iff : forall `(f : A -> A) (t : S A) (a2 : A), (j, a2) ∈m kfmap S j f t <-> exists (a1 : A), (j, a1) ∈m t /\ a2 = f a1. Proof. intros. unfold kfmap. rewrite (in_mfmap_iff S). now rewrite tgt_eq. Qed. Corollary in_kfmap_neq_iff : forall (i : K) (Hneq : j <> i) `(f : A -> A) (t : S A) (a2 : A), (i, a2) ∈m kfmap S j f t <-> (i, a2) ∈m t. Proof. intros. unfold kfmap. rewrite (in_mfmap_iff S). rewrite tgt_neq; auto. split. - intros [a [hyp ?]]; subst. assumption. - intros; now (exists a2). Qed. End DTM_membership_targetted. Import Notations2. (** * Iterating over a DTM *) (******************************************************************************) Section schedule_operation. Context (S : Type -> Type) `{DTPreModule W S T} `{! DTM W T}. Definition schedule {A : Type} (B : Type) : forall (k : K), W * A -> @Batch _ T W A B (T k B) := fun k '(w, a) => Go (@id (T k B)) ⧆ (w, a). Definition iterate {A : Type} (B : Type) : S A -> @Batch _ T W A B (S B) := mbinddt S (@Batch _ T W A B) (schedule B). End schedule_operation. (** ** Representing <<mbinddt>> with <<runBatch>> *) (******************************************************************************) Section iterate. Context (S : Type -> Type) `{DTPreModule W S T} `{! DTM W T}. Theorem mbinddt_to_runBatch : forall `{Applicative F} (A B : Type) (t : S A) (f : forall k, W * A -> F (T k B)), mbinddt S F f t = runBatch f (iterate S B t). Proof. intros. unfold iterate. compose near t on right. rewrite (dtp_mbinddt_morphism W S T Batch F). fequal. ext k [w a]. cbn. now rewrite ap1. Qed. Corollary mbindd_to_runBatch : forall (A B : Type) (t : S A) (f : forall k, W * A -> T k B), mbindd S f t = runBatch (F := fun A => A) f (iterate S B t). Proof. intros. rewrite mbindd_to_mbinddt. now rewrite mbinddt_to_runBatch. Qed. Corollary mbindt_to_runBatch : forall `{Applicative F} (A B : Type) (t : S A) (f : forall k, A -> F (T k B)), mbindt S F f t = runBatch (f ◻ const (extract (W ×))) (iterate S B t). Proof. intros. rewrite mbindt_to_mbinddt. now rewrite mbinddt_to_runBatch. Qed. Corollary mfmapdt_to_runBatch : forall `{Applicative F} (A B : Type) (t : S A) `(f : K -> W * A -> F B), mfmapdt S F f t = runBatch (fun k => fmap F (mret T k) ∘ f k) (iterate S B t). Proof. intros. rewrite mfmapdt_to_mbinddt. now rewrite mbinddt_to_runBatch. Qed. Corollary mbind_to_runBatch : forall (A B : Type) (t : S A) (f : forall k, A -> T k B), mbind S f t = runBatch (F := fun A => A) (f ◻ const (extract (W ×))) (iterate S B t). Proof. intros. rewrite mbind_to_mbinddt. now rewrite mbinddt_to_runBatch. Qed. Corollary mfmapd_to_runBatch `(f : K -> W * A -> B) (t : S A) : mfmapd S f t = runBatch (F := fun A => A) (mret T ◻ f) (iterate S B t). Proof. rewrite mfmapd_to_mbinddt. now rewrite mbinddt_to_runBatch. Qed. Corollary mfmapt_to_runBatch `{Applicative F} `(f : K -> A -> F B) (t : S A) : mfmapt S F f t = runBatch (fun k => fmap F (mret T k) ∘ f k ∘ extract (W ×)) (iterate S B t). Proof. rewrite mfmapt_to_mbinddt. now rewrite mbinddt_to_runBatch. Qed. Corollary mfmap_to_runBatch `(f : K -> A -> B) (t : S A) : mfmap S f t = runBatch (F := fun A => A) (mret T ◻ f ◻ const (extract (W ×))) (iterate S B t). Proof. rewrite mfmap_to_mbinddt. now rewrite mbinddt_to_runBatch. Qed. (** ** Identities for <<tolist>> and <<foldMap>> *) (******************************************************************************) Lemma tomlistd_gen_to_runBatch (fake : Type) `(t : S A) : tomlistd_gen S fake t = runBatch (fun k '(w, a) => [(w, (k, a))]) (iterate S fake t). Proof. unfold tomlistd_gen. now rewrite mfmapdt_to_runBatch. Qed. Lemma tomlistd_to_runBatch (fake : Type) `(t : S A) : tomlistd S t = runBatch (fun k '(w, a) => [(w, (k, a))]) (iterate S fake t). Proof. unfold tomlistd. rewrite (tomlistd_equiv S False fake). now rewrite tomlistd_gen_to_runBatch. Qed. Lemma tomsetd_to_runBatch (fake : Type) `(t : S A) : tomsetd S t = runBatch (F := (@const Type Type (set (W * (K * A))))) (fun k '(w, a) => {{(w, (k, a))}}) (iterate S fake t). Proof. unfold tomsetd, compose. rewrite (tomlistd_to_runBatch fake). change (toset list (A := W * (K * A))) with (const (toset (A := W * (K * A)) list) (S fake)). cbn. (* <- needed for implicit arguments. *) rewrite (runBatch_morphism (F := const (list (W * (K * A)))) (G := const (set (W * (K * A))))). unfold compose. fequal. ext k [w a]. solve_basic_set. Qed. Lemma tomlist_to_runBatch (fake : Type) `(t : S A) : tomlist S t = runBatch (fun k '(w, a) => [(k, a)]) (iterate S fake t). Proof. unfold tomlist. unfold compose. rewrite (tomlistd_to_runBatch fake). change (fmap list ?f) with (const (fmap list f) (S fake)). rewrite (runBatch_morphism (F := const (list (W * (K * A)))) (G := const (list (K * A))) (ψ := const (fmap list (extract (prod W))))). fequal. now ext k [w a]. Qed. (** ** Other identities *) (******************************************************************************) Lemma id_to_runBatch `(t : S A) : t = runBatch (F := fun A => A) (mret T ◻ const (extract (W ×))) (iterate S A t). Proof. change t with (id t) at 1. rewrite <- (dtp_mbinddt_mret W S T). rewrite mbinddt_to_runBatch. reflexivity. Qed. End iterate. (** ** Respectfulness for <<mbindd>> *) (******************************************************************************) Section mbindd_respectful. Context {S : Type -> Type} `{DTPreModule W S T} `{! DTM W T}. Theorem mbindd_respectful : forall A B (t : S A) (f g : forall k, W * A -> T k B), (forall (w : W) (k : K) (a : A), (w, (k, a)) ∈md t -> f k (w, a) = g k (w, a)) -> mbindd S f t = mbindd S g t. Proof. introv hyp. rewrite (tomsetd_to_runBatch S B t) in hyp. do 2 rewrite (mbindd_to_runBatch S). induction (iterate S B t). - easy. - destruct p. do 2 rewrite runBatch_rw2. rewrite runBatch_rw2 in hyp. fequal. + apply IHb. intros. apply hyp. cbn. now left. + apply hyp. now right. Qed. (** *** For equalities with special cases *) (** Corollaries with conclusions of the form <<mbindd t = f t>> for other <<m*>> operations *) (******************************************************************************) Corollary mbindd_respectful_mbind : forall A B (t : S A) (f : forall k, W * A -> T k B) (g : forall k, A -> T k B), (forall (w : W) (k : K) (a : A), (w, (k, a)) ∈md t -> f k (w, a) = g k a) -> mbindd S f t = mbind S g t. Proof. introv hyp. rewrite mbind_to_mbindd. apply mbindd_respectful. introv Hin. unfold compose. cbn. auto. Qed. Corollary mbindd_respectful_mfmapd : forall A B (t : S A) (f : forall k, W * A -> T k B) (g : K -> W * A -> B), (forall (w : W) (k : K) (a : A), (w, (k, a)) ∈md t -> f k (w, a) = mret T k (g k (w, a))) -> mbindd S f t = mfmapd S g t. Proof. introv hyp. rewrite mfmapd_to_mbindd. apply mbindd_respectful. introv Hin. unfold compose. cbn. auto. Qed. Corollary mbindd_respectful_mfmap : forall A B (t : S A) (f : forall k, W * A -> T k B) (g : K -> A -> B), (forall (w : W) (k : K) (a : A), (w, (k, a)) ∈md t -> f k (w, a) = mret T k (g k a)) -> mbindd S f t = mfmap S g t. Proof. introv hyp. rewrite mfmap_to_mbindd. apply mbindd_respectful. introv Hin. unfold compose. cbn. auto. Qed. Corollary mbindd_respectful_id : forall A (t : S A) (f : forall k, W * A -> T k A), (forall (w : W) (k : K) (a : A), (w, (k, a)) ∈md t -> f k (w, a) = mret T k a) -> mbindd S f t = t. Proof. intros. change t with (id t) at 2. rewrite <- (mbindd_id S). eapply mbindd_respectful. unfold compose; cbn. auto. Qed. End mbindd_respectful. (** ** Respectfulness for <<mbindd>> *) (******************************************************************************) Section mbind_respectful. Context {S : Type -> Type} `{DTPreModule W S T} `{! DTM W T}. Lemma mbind_respectful : forall A B (t : S A) (f g : forall k, A -> T k B), (forall (k : K) (a : A), (k, a) ∈m t -> f k a = g k a) -> mbind S f t = mbind S g t. Proof. introv hyp. rewrite mbind_to_mbindd. apply mbindd_respectful. introv premise. apply ind_implies_in in premise. unfold compose; cbn. auto. Qed. (** *** For equalities with other operations *) (** Corollaries with conclusions of the form <<mbind t = f t>> for other <<m*>> operations *) (******************************************************************************) Corollary mbind_respectful_mfmapd : forall A B (t : S A) (f : forall k, A -> T k B) (g : K -> W * A -> B), (forall (k : K) (w : W) (a : A), (w, (k, a)) ∈md t -> f k a = mret T k (g k (w, a))) -> mbind S f t = mfmapd S g t. Proof. intros. rewrite mfmapd_to_mbindd. symmetry. apply mbindd_respectful_mbind. introv Hin. symmetry. unfold compose; cbn. auto. Qed. Corollary mbind_respectful_mfmap : forall A B (t : S A) (f : forall k, A -> T k B) (g : K -> A -> B), (forall (k : K) (a : A), (k, a) ∈m t -> f k a = mret T k (g k a)) -> mbind S f t = mfmap S g t. Proof. intros. rewrite mfmap_to_mbind. symmetry. apply mbind_respectful. introv Hin. symmetry. unfold compose; cbn. auto. Qed. Corollary mbind_respectful_id : forall A (t : S A) (f : forall k, A -> T k A), (forall (k : K) (a : A), (k, a) ∈m t -> f k a = mret T k a) -> mbind S f t = t. Proof. intros. change t with (id t) at 2. rewrite <- (mbind_id S). eapply mbind_respectful. unfold compose; cbn. auto. Qed. End mbind_respectful. (** ** Respectfulness for <<mfmapd>> *) (******************************************************************************) Section mfmapd_respectful. Context {S : Type -> Type} `{DTPreModule W S T} `{! DTM W T}. Lemma mfmapd_respectful : forall A B (t : S A) (f g : K -> W * A -> B), (forall (w : W) (k : K) (a : A), (w, (k, a)) ∈md t -> f k (w, a) = g k (w, a)) -> mfmapd S f t = mfmapd S g t. Proof. introv hyp. do 2 rewrite mfmapd_to_mbindd. apply mbindd_respectful. introv premise. unfold compose; cbn. fequal. auto. Qed. (** *** For equalities with other operations *) (** Corollaries with conclusions of the form <<mfmapd t = f t>> for other <<m*>> operations *) (******************************************************************************) Corollary mfmapd_respectful_mfmap : forall A (t : S A) (f : K -> W * A -> A) (g : K -> A -> A), (forall (w : W) (k : K) (a : A), (w, (k, a)) ∈md t -> f k (w, a) = g k a) -> mfmapd S f t = mfmap S g t. Proof. intros. rewrite mfmap_to_mfmapd. apply mfmapd_respectful. introv Hin. unfold compose; cbn; auto. Qed. Corollary mfmapd_respectful_id : forall A (t : S A) (f : K -> W * A -> A), (forall (w : W) (k : K) (a : A), (w, (k, a)) ∈md t -> f k (w, a) = a) -> mfmapd S f t = t. Proof. intros. change t with (id t) at 2. rewrite <- (mfmapd_id S). eapply mfmapd_respectful. cbn. auto. Qed. End mfmapd_respectful. (** ** Respectfulness for <<mfmap>> *) (******************************************************************************) Section mfmap_respectful. Context {S : Type -> Type} `{DTPreModule W S T} `{! DTM W T}. Lemma mfmap_respectful : forall A B (t : S A) (f g : K -> A -> B), (forall (w : W) (k : K) (a : A), (w, (k, a)) ∈md t -> f k a = g k a) -> mfmap S f t = mfmap S g t. Proof. introv hyp. do 2 rewrite mfmap_to_mfmapd. now apply mfmapd_respectful. Qed. Corollary mfmap_respectful_id : forall A (t : S A) (f : K -> A -> A), (forall (w : W) (k : K) (a : A), (w, (k, a)) ∈md t -> f k a = a) -> mfmap S f t = t. Proof. intros. change t with (id t) at 2. rewrite <- (mfmap_id S). eapply mfmap_respectful. auto. Qed. End mfmap_respectful. (** ** Respectfulness for <<kbindd>> *) (******************************************************************************) Section kbindd_respectful. Context {S : Type -> Type} `{DTPreModule W S T} `{! DTM W T} (j : K). Lemma kbindd_respectful : forall A (t : S A) (f g : W * A -> T j A), (forall (w : W) (a : A), (w, (j, a)) ∈md t -> f (w, a) = g (w, a)) -> kbindd S j f t = kbindd S j g t. Proof. introv hyp. unfold kbindd. apply mbindd_respectful. introv premise. compare values j and k. - do 2 rewrite btgd_eq. auto. - do 2 (rewrite btgd_neq; auto). Qed. (** *** For equalities with special cases *) (******************************************************************************) Corollary kbindd_respectful_kbind : forall A (t : S A) (f : W * A -> T j A) (g : A -> T j A), (forall (w : W) (a : A), (w, (j, a)) ∈md t -> f (w, a) = g a) -> kbindd S j f t = kbind S j g t. Proof. introv hyp. rewrite kbind_to_kbindd. apply kbindd_respectful. introv Hin. apply hyp. auto. Qed. Corollary kbindd_respectful_kfmapd : forall A (t : S A) (f : W * A -> T j A) (g : W * A -> A), (forall (w : W) (a : A), (w, (j, a)) ∈md t -> f (w, a) = mret T j (g (w, a))) -> kbindd S j f t = kfmapd S j g t. Proof. introv hyp. rewrite kfmapd_to_kbindd. apply kbindd_respectful. introv Hin. apply hyp. auto. Qed. Corollary kbindd_respectful_kfmap : forall A (t : S A) (f : W * A -> T j A) (g : A -> A), (forall (w : W) (a : A), (w, (j, a)) ∈md t -> f (w, a) = mret T j (g a)) -> kbindd S j f t = kfmap S j g t. Proof. introv hyp. rewrite kfmap_to_kfmapd. apply kbindd_respectful_kfmapd. introv Hin. apply hyp. auto. Qed. Corollary kbindd_respectful_id : forall A (t : S A) (f : W * A -> T j A), (forall (w : W) (a : A), (w, (j, a)) ∈md t -> f (w, a) = mret T j a) -> kbindd S j f t = t. Proof. introv hyp. change t with (id t) at 2. erewrite <- (kbindd_id S). apply kbindd_respectful. auto. Qed. End kbindd_respectful. (** ** Respectfulness for mixed structures *) (******************************************************************************) Section mixed_respectful. Context {S : Type -> Type} `{DTPreModule W S T} `{! DTM W T} (j : K). Corollary kbind_respectful_kfmapd : forall A (t : S A) (f : A -> T j A) (g : W * A -> A), (forall (w : W) (a : A), (w, (j, a)) ∈md t -> f a = mret T j (g (w, a))) -> kbind S j f t = kfmapd S j g t. Proof. introv hyp. rewrite kfmapd_to_kbindd. rewrite kbind_to_kbindd. apply kbindd_respectful. introv Hin. apply hyp. auto. Qed. End mixed_respectful. (** ** Respectfulness for <<kbind>> *) (******************************************************************************) Section kbindd_respectful. Context {S : Type -> Type} `{DTPreModule W S T} `{! DTM W T} (j : K). Lemma kbind_respectful : forall A (t : S A) (f g : A -> T j A), (forall (a : A), (j, a) ∈m t -> f a = g a) -> kbind S j f t = kbind S j g t. Proof. introv hyp. unfold kbind. apply mbind_respectful. introv premise. compare values j and k. - do 2 rewrite btg_eq. auto. - do 2 (rewrite btg_neq; auto). Qed. (** *** For equalities with special cases *) (******************************************************************************) Corollary kbind_respectful_kfmap : forall A (t : S A) (f : A -> T j A) (g : A -> A), (forall (a : A), (j, a) ∈m t -> f a = mret T j (g a)) -> kbind S j f t = kfmap S j g t. Proof. introv hyp. rewrite kfmap_to_kbind. apply kbind_respectful. introv Hin. apply hyp. auto. Qed. Corollary kbind_respectful_id : forall A (t : S A) (f : A -> T j A), (forall (a : A), (j, a) ∈m t -> f a = mret T j a) -> kbind S j f t = t. Proof. introv hyp. change t with (id t) at 2. rewrite <- (kbind_id S (j := j)). now apply kbind_respectful. Qed. End kbindd_respectful. (** ** Respectfulness for <<kfmapd>> *) (******************************************************************************) Section kfmapd_respectful. Context {S : Type -> Type} `{DTPreModule W S T} `{! DTM W T} (j : K). Lemma kfmapd_respectful : forall A (t : S A) (f g : W * A -> A), (forall (w : W) (a : A), (w, (j, a)) ∈md t -> f (w, a) = g (w, a)) -> kfmapd S j f t = kfmapd S j g t. Proof. introv hyp. unfold kfmapd. apply mfmapd_respectful. introv premise. compare values j and k. - do 2 rewrite tgtd_eq. auto. - do 2 (rewrite tgtd_neq; auto). Qed. (** *** For equalities with other operations *) (******************************************************************************) Corollary kfmapd_respectful_kfmap : forall A (t : S A) (f : W * A -> A) (g : A -> A), (forall (w : W) (a : A), (w, (j, a)) ∈md t -> f (w, a) = g a) -> kfmapd S j f t = kfmap S j g t. Proof. introv hyp. rewrite kfmap_to_kfmapd. apply kfmapd_respectful. auto. Qed. Corollary kfmapd_respectful_id : forall A (t : S A) (f : W * A -> A), (forall (w : W) (a : A), (w, (j, a)) ∈md t -> f (w, a) = a) -> kfmapd S j f t = t. Proof. introv hyp. change t with (id t) at 2. rewrite <- (kfmapd_id (j := j) S). apply kfmapd_respectful. auto. Qed. End kfmapd_respectful. (** ** Respectfulness for <<kfmap>> *) (******************************************************************************) Section kfmap_respectful. Context {S : Type -> Type} `{DTPreModule W S T} `{! DTM W T} (j : K). Lemma kfmap_respectful : forall A (t : S A) (f g : A -> A), (forall (w : W) (a : A), (w, (j, a)) ∈md t -> f a = g a) -> kfmap S j f t = kfmap S j g t. Proof. introv hyp. unfold kfmap. apply mfmap_respectful. introv premise. compare values j and k. - autorewrite with tea_tgt. eauto. - autorewrite with tea_tgt_neq. auto. Qed. Corollary kfmap_respectful_id : forall A (t : S A) (f : A -> A), (forall (w : W) (a : A), (w, (j, a)) ∈md t -> f a = a) -> kfmap S j f t = t. Proof. introv hyp. change t with (id t) at 2. rewrite <- (kfmap_id (j := j) S). apply kfmap_respectful. auto. Qed. End kfmap_respectful.
Formal statement is: lemma emeasure_lborel_box_eq: "emeasure lborel (box l u) = (if \<forall>b\<in>Basis. l \<bullet> b \<le> u \<bullet> b then \<Prod>b\<in>Basis. (u - l) \<bullet> b else 0)" Informal statement is: The Lebesgue measure of a box is the product of the lengths of its sides, if the box is non-empty, and zero otherwise.
/- Copyright (c) 2017 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl ! This file was ported from Lean 3 source module data.set.pairwise.basic ! leanprover-community/mathlib commit c227d107bbada5d0d9d20287e3282c0a7f1651a0 ! Please do not edit these lines, except to modify the commit id ! if you have ported upstream changes. -/ import Mathbin.Data.Set.Function import Mathbin.Logic.Relation import Mathbin.Logic.Pairwise /-! # Relations holding pairwise > THIS FILE IS SYNCHRONIZED WITH MATHLIB4. > Any changes to this file require a corresponding PR to mathlib4. This file develops pairwise relations and defines pairwise disjoint indexed sets. We also prove many basic facts about `pairwise`. It is possible that an intermediate file, with more imports than `logic.pairwise` but not importing `data.set.function` would be appropriate to hold many of these basic facts. ## Main declarations * `set.pairwise_disjoint`: `s.pairwise_disjoint f` states that images under `f` of distinct elements of `s` are either equal or `disjoint`. ## Notes The spelling `s.pairwise_disjoint id` is preferred over `s.pairwise disjoint` to permit dot notation on `set.pairwise_disjoint`, even though the latter unfolds to something nicer. -/ open Set Function variable {α β γ ι ι' : Type _} {r p q : α → α → Prop} section Pairwise variable {f g : ι → α} {s t u : Set α} {a b : α} #print pairwise_on_bool /- theorem pairwise_on_bool (hr : Symmetric r) {a b : α} : Pairwise (r on fun c => cond c a b) ↔ r a b := by simpa [Pairwise, Function.onFun] using @hr a b #align pairwise_on_bool pairwise_on_bool -/ #print pairwise_disjoint_on_bool /- theorem pairwise_disjoint_on_bool [SemilatticeInf α] [OrderBot α] {a b : α} : Pairwise (Disjoint on fun c => cond c a b) ↔ Disjoint a b := pairwise_on_bool Disjoint.symm #align pairwise_disjoint_on_bool pairwise_disjoint_on_bool -/ #print Symmetric.pairwise_on /- theorem Symmetric.pairwise_on [LinearOrder ι] (hr : Symmetric r) (f : ι → α) : Pairwise (r on f) ↔ ∀ ⦃m n⦄, m < n → r (f m) (f n) := ⟨fun h m n hmn => h hmn.Ne, fun h m n hmn => hmn.lt_or_lt.elim (@h _ _) fun h' => hr (h h')⟩ #align symmetric.pairwise_on Symmetric.pairwise_on -/ /- warning: pairwise_disjoint_on -> pairwise_disjoint_on is a dubious translation: lean 3 declaration is forall {α : Type.{u1}} {ι : Type.{u2}} [_inst_1 : SemilatticeInf.{u1} α] [_inst_2 : OrderBot.{u1} α (Preorder.toLE.{u1} α (PartialOrder.toPreorder.{u1} α (SemilatticeInf.toPartialOrder.{u1} α _inst_1)))] [_inst_3 : LinearOrder.{u2} ι] (f : ι -> α), Iff (Pairwise.{u2} ι (Function.onFun.{succ u2, succ u1, 1} ι α Prop (Disjoint.{u1} α (SemilatticeInf.toPartialOrder.{u1} α _inst_1) _inst_2) f)) (forall {{m : ι}} {{n : ι}}, (LT.lt.{u2} ι (Preorder.toLT.{u2} ι (PartialOrder.toPreorder.{u2} ι (SemilatticeInf.toPartialOrder.{u2} ι (Lattice.toSemilatticeInf.{u2} ι (LinearOrder.toLattice.{u2} ι _inst_3))))) m n) -> (Disjoint.{u1} α (SemilatticeInf.toPartialOrder.{u1} α _inst_1) _inst_2 (f m) (f n))) but is expected to have type forall {α : Type.{u2}} {ι : Type.{u1}} [_inst_1 : SemilatticeInf.{u2} α] [_inst_2 : OrderBot.{u2} α (Preorder.toLE.{u2} α (PartialOrder.toPreorder.{u2} α (SemilatticeInf.toPartialOrder.{u2} α _inst_1)))] [_inst_3 : LinearOrder.{u1} ι] (f : ι -> α), Iff (Pairwise.{u1} ι (Function.onFun.{succ u1, succ u2, 1} ι α Prop (Disjoint.{u2} α (SemilatticeInf.toPartialOrder.{u2} α _inst_1) _inst_2) f)) (forall {{m : ι}} {{n : ι}}, (LT.lt.{u1} ι (Preorder.toLT.{u1} ι (PartialOrder.toPreorder.{u1} ι (SemilatticeInf.toPartialOrder.{u1} ι (Lattice.toSemilatticeInf.{u1} ι (DistribLattice.toLattice.{u1} ι (instDistribLattice.{u1} ι _inst_3)))))) m n) -> (Disjoint.{u2} α (SemilatticeInf.toPartialOrder.{u2} α _inst_1) _inst_2 (f m) (f n))) Case conversion may be inaccurate. Consider using '#align pairwise_disjoint_on pairwise_disjoint_onₓ'. -/ theorem pairwise_disjoint_on [SemilatticeInf α] [OrderBot α] [LinearOrder ι] (f : ι → α) : Pairwise (Disjoint on f) ↔ ∀ ⦃m n⦄, m < n → Disjoint (f m) (f n) := Symmetric.pairwise_on Disjoint.symm f #align pairwise_disjoint_on pairwise_disjoint_on /- warning: pairwise_disjoint.mono -> pairwise_disjoint_mono is a dubious translation: lean 3 declaration is forall {α : Type.{u1}} {ι : Type.{u2}} {f : ι -> α} {g : ι -> α} [_inst_1 : SemilatticeInf.{u1} α] [_inst_2 : OrderBot.{u1} α (Preorder.toLE.{u1} α (PartialOrder.toPreorder.{u1} α (SemilatticeInf.toPartialOrder.{u1} α _inst_1)))], (Pairwise.{u2} ι (Function.onFun.{succ u2, succ u1, 1} ι α Prop (Disjoint.{u1} α (SemilatticeInf.toPartialOrder.{u1} α _inst_1) _inst_2) f)) -> (LE.le.{max u2 u1} (ι -> α) (Pi.hasLe.{u2, u1} ι (fun (ᾰ : ι) => α) (fun (i : ι) => Preorder.toLE.{u1} α (PartialOrder.toPreorder.{u1} α (SemilatticeInf.toPartialOrder.{u1} α _inst_1)))) g f) -> (Pairwise.{u2} ι (Function.onFun.{succ u2, succ u1, 1} ι α Prop (Disjoint.{u1} α (SemilatticeInf.toPartialOrder.{u1} α _inst_1) _inst_2) g)) but is expected to have type forall {α : Type.{u2}} {ι : Type.{u1}} {f : ι -> α} {g : ι -> α} [_inst_1 : SemilatticeInf.{u2} α] [_inst_2 : OrderBot.{u2} α (Preorder.toLE.{u2} α (PartialOrder.toPreorder.{u2} α (SemilatticeInf.toPartialOrder.{u2} α _inst_1)))], (Pairwise.{u1} ι (Function.onFun.{succ u1, succ u2, 1} ι α Prop (Disjoint.{u2} α (SemilatticeInf.toPartialOrder.{u2} α _inst_1) _inst_2) f)) -> (LE.le.{max u2 u1} (ι -> α) (Pi.hasLe.{u1, u2} ι (fun (ᾰ : ι) => α) (fun (i : ι) => Preorder.toLE.{u2} α (PartialOrder.toPreorder.{u2} α (SemilatticeInf.toPartialOrder.{u2} α _inst_1)))) g f) -> (Pairwise.{u1} ι (Function.onFun.{succ u1, succ u2, 1} ι α Prop (Disjoint.{u2} α (SemilatticeInf.toPartialOrder.{u2} α _inst_1) _inst_2) g)) Case conversion may be inaccurate. Consider using '#align pairwise_disjoint.mono pairwise_disjoint_monoₓ'. -/ theorem pairwise_disjoint_mono [SemilatticeInf α] [OrderBot α] (hs : Pairwise (Disjoint on f)) (h : g ≤ f) : Pairwise (Disjoint on g) := hs.mono fun i j hij => Disjoint.mono (h i) (h j) hij #align pairwise_disjoint.mono pairwise_disjoint_mono namespace Set #print Set.Pairwise.mono /- theorem Pairwise.mono (h : t ⊆ s) (hs : s.Pairwise r) : t.Pairwise r := fun x xt y yt => hs (h xt) (h yt) #align set.pairwise.mono Set.Pairwise.mono -/ #print Set.Pairwise.mono' /- theorem Pairwise.mono' (H : r ≤ p) (hr : s.Pairwise r) : s.Pairwise p := hr.imp H #align set.pairwise.mono' Set.Pairwise.mono' -/ /- warning: set.pairwise_top -> Set.pairwise_top is a dubious translation: lean 3 declaration is forall {α : Type.{u1}} (s : Set.{u1} α), Set.Pairwise.{u1} α s (Top.top.{u1} (α -> α -> Prop) (Pi.hasTop.{u1, u1} α (fun (ᾰ : α) => α -> Prop) (fun (i : α) => Pi.hasTop.{u1, 0} α (fun (ᾰ : α) => Prop) (fun (i : α) => BooleanAlgebra.toHasTop.{0} Prop Prop.booleanAlgebra)))) but is expected to have type forall {α : Type.{u1}} (s : Set.{u1} α), Set.Pairwise.{u1} α s (Top.top.{u1} (α -> α -> Prop) (Pi.instTopForAll.{u1, u1} α (fun (ᾰ : α) => α -> Prop) (fun (i : α) => Pi.instTopForAll.{u1, 0} α (fun (ᾰ : α) => Prop) (fun (i : α) => BooleanAlgebra.toTop.{0} Prop Prop.booleanAlgebra)))) Case conversion may be inaccurate. Consider using '#align set.pairwise_top Set.pairwise_topₓ'. -/ theorem pairwise_top (s : Set α) : s.Pairwise ⊤ := pairwise_of_forall s _ fun a b => trivial #align set.pairwise_top Set.pairwise_top #print Set.Subsingleton.pairwise /- protected theorem Subsingleton.pairwise (h : s.Subsingleton) (r : α → α → Prop) : s.Pairwise r := fun x hx y hy hne => (hne (h hx hy)).elim #align set.subsingleton.pairwise Set.Subsingleton.pairwise -/ #print Set.pairwise_empty /- @[simp] theorem pairwise_empty (r : α → α → Prop) : (∅ : Set α).Pairwise r := subsingleton_empty.Pairwise r #align set.pairwise_empty Set.pairwise_empty -/ #print Set.pairwise_singleton /- @[simp] theorem pairwise_singleton (a : α) (r : α → α → Prop) : Set.Pairwise {a} r := subsingleton_singleton.Pairwise r #align set.pairwise_singleton Set.pairwise_singleton -/ #print Set.pairwise_iff_of_refl /- theorem pairwise_iff_of_refl [IsRefl α r] : s.Pairwise r ↔ ∀ ⦃a⦄, a ∈ s → ∀ ⦃b⦄, b ∈ s → r a b := forall₄_congr fun a _ b _ => or_iff_not_imp_left.symm.trans <| or_iff_right_of_imp of_eq #align set.pairwise_iff_of_refl Set.pairwise_iff_of_refl -/ alias pairwise_iff_of_refl ↔ pairwise.of_refl _ #align set.pairwise.of_refl Set.Pairwise.of_refl /- warning: set.nonempty.pairwise_iff_exists_forall -> Set.Nonempty.pairwise_iff_exists_forall is a dubious translation: lean 3 declaration is forall {α : Type.{u1}} {ι : Type.{u2}} {r : α -> α -> Prop} {f : ι -> α} [_inst_1 : IsEquiv.{u1} α r] {s : Set.{u2} ι}, (Set.Nonempty.{u2} ι s) -> (Iff (Set.Pairwise.{u2} ι s (Function.onFun.{succ u2, succ u1, 1} ι α Prop r f)) (Exists.{succ u1} α (fun (z : α) => forall (x : ι), (Membership.Mem.{u2, u2} ι (Set.{u2} ι) (Set.hasMem.{u2} ι) x s) -> (r (f x) z)))) but is expected to have type forall {α : Type.{u2}} {ι : Type.{u1}} {r : α -> α -> Prop} {f : ι -> α} [_inst_1 : IsEquiv.{u2} α r] {s : Set.{u1} ι}, (Set.Nonempty.{u1} ι s) -> (Iff (Set.Pairwise.{u1} ι s (Function.onFun.{succ u1, succ u2, 1} ι α Prop r f)) (Exists.{succ u2} α (fun (z : α) => forall (x : ι), (Membership.mem.{u1, u1} ι (Set.{u1} ι) (Set.instMembershipSet.{u1} ι) x s) -> (r (f x) z)))) Case conversion may be inaccurate. Consider using '#align set.nonempty.pairwise_iff_exists_forall Set.Nonempty.pairwise_iff_exists_forallₓ'. -/ theorem Nonempty.pairwise_iff_exists_forall [IsEquiv α r] {s : Set ι} (hs : s.Nonempty) : s.Pairwise (r on f) ↔ ∃ z, ∀ x ∈ s, r (f x) z := by fconstructor · rcases hs with ⟨y, hy⟩ refine' fun H => ⟨f y, fun x hx => _⟩ rcases eq_or_ne x y with (rfl | hne) · apply IsRefl.refl · exact H hx hy hne · rintro ⟨z, hz⟩ x hx y hy hne exact @IsTrans.trans α r _ (f x) z (f y) (hz _ hx) (IsSymm.symm _ _ <| hz _ hy) #align set.nonempty.pairwise_iff_exists_forall Set.Nonempty.pairwise_iff_exists_forall /- warning: set.nonempty.pairwise_eq_iff_exists_eq -> Set.Nonempty.pairwise_eq_iff_exists_eq is a dubious translation: lean 3 declaration is forall {α : Type.{u1}} {ι : Type.{u2}} {s : Set.{u1} α}, (Set.Nonempty.{u1} α s) -> (forall {f : α -> ι}, Iff (Set.Pairwise.{u1} α s (fun (x : α) (y : α) => Eq.{succ u2} ι (f x) (f y))) (Exists.{succ u2} ι (fun (z : ι) => forall (x : α), (Membership.Mem.{u1, u1} α (Set.{u1} α) (Set.hasMem.{u1} α) x s) -> (Eq.{succ u2} ι (f x) z)))) but is expected to have type forall {α : Type.{u2}} {ι : Type.{u1}} {s : Set.{u2} α}, (Set.Nonempty.{u2} α s) -> (forall {f : α -> ι}, Iff (Set.Pairwise.{u2} α s (fun (x : α) (y : α) => Eq.{succ u1} ι (f x) (f y))) (Exists.{succ u1} ι (fun (z : ι) => forall (x : α), (Membership.mem.{u2, u2} α (Set.{u2} α) (Set.instMembershipSet.{u2} α) x s) -> (Eq.{succ u1} ι (f x) z)))) Case conversion may be inaccurate. Consider using '#align set.nonempty.pairwise_eq_iff_exists_eq Set.Nonempty.pairwise_eq_iff_exists_eqₓ'. -/ /-- For a nonempty set `s`, a function `f` takes pairwise equal values on `s` if and only if for some `z` in the codomain, `f` takes value `z` on all `x ∈ s`. See also `set.pairwise_eq_iff_exists_eq` for a version that assumes `[nonempty ι]` instead of `set.nonempty s`. -/ theorem Nonempty.pairwise_eq_iff_exists_eq {s : Set α} (hs : s.Nonempty) {f : α → ι} : (s.Pairwise fun x y => f x = f y) ↔ ∃ z, ∀ x ∈ s, f x = z := hs.pairwise_iff_exists_forall #align set.nonempty.pairwise_eq_iff_exists_eq Set.Nonempty.pairwise_eq_iff_exists_eq #print Set.pairwise_iff_exists_forall /- theorem pairwise_iff_exists_forall [Nonempty ι] (s : Set α) (f : α → ι) {r : ι → ι → Prop} [IsEquiv ι r] : s.Pairwise (r on f) ↔ ∃ z, ∀ x ∈ s, r (f x) z := by rcases s.eq_empty_or_nonempty with (rfl | hne) · simp · exact hne.pairwise_iff_exists_forall #align set.pairwise_iff_exists_forall Set.pairwise_iff_exists_forall -/ #print Set.pairwise_eq_iff_exists_eq /- /-- A function `f : α → ι` with nonempty codomain takes pairwise equal values on a set `s` if and only if for some `z` in the codomain, `f` takes value `z` on all `x ∈ s`. See also `set.nonempty.pairwise_eq_iff_exists_eq` for a version that assumes `set.nonempty s` instead of `[nonempty ι]`. -/ theorem pairwise_eq_iff_exists_eq [Nonempty ι] (s : Set α) (f : α → ι) : (s.Pairwise fun x y => f x = f y) ↔ ∃ z, ∀ x ∈ s, f x = z := pairwise_iff_exists_forall s f #align set.pairwise_eq_iff_exists_eq Set.pairwise_eq_iff_exists_eq -/ /- warning: set.pairwise_union -> Set.pairwise_union is a dubious translation: lean 3 declaration is forall {α : Type.{u1}} {r : α -> α -> Prop} {s : Set.{u1} α} {t : Set.{u1} α}, Iff (Set.Pairwise.{u1} α (Union.union.{u1} (Set.{u1} α) (Set.hasUnion.{u1} α) s t) r) (And (Set.Pairwise.{u1} α s r) (And (Set.Pairwise.{u1} α t r) (forall (a : α), (Membership.Mem.{u1, u1} α (Set.{u1} α) (Set.hasMem.{u1} α) a s) -> (forall (b : α), (Membership.Mem.{u1, u1} α (Set.{u1} α) (Set.hasMem.{u1} α) b t) -> (Ne.{succ u1} α a b) -> (And (r a b) (r b a)))))) but is expected to have type forall {α : Type.{u1}} {r : α -> α -> Prop} {s : Set.{u1} α} {t : Set.{u1} α}, Iff (Set.Pairwise.{u1} α (Union.union.{u1} (Set.{u1} α) (Set.instUnionSet.{u1} α) s t) r) (And (Set.Pairwise.{u1} α s r) (And (Set.Pairwise.{u1} α t r) (forall (a : α), (Membership.mem.{u1, u1} α (Set.{u1} α) (Set.instMembershipSet.{u1} α) a s) -> (forall (b : α), (Membership.mem.{u1, u1} α (Set.{u1} α) (Set.instMembershipSet.{u1} α) b t) -> (Ne.{succ u1} α a b) -> (And (r a b) (r b a)))))) Case conversion may be inaccurate. Consider using '#align set.pairwise_union Set.pairwise_unionₓ'. -/ theorem pairwise_union : (s ∪ t).Pairwise r ↔ s.Pairwise r ∧ t.Pairwise r ∧ ∀ a ∈ s, ∀ b ∈ t, a ≠ b → r a b ∧ r b a := by simp only [Set.Pairwise, mem_union, or_imp, forall_and] exact ⟨fun H => ⟨H.1.1, H.2.2, H.2.1, fun x hx y hy hne => H.1.2 y hy x hx hne.symm⟩, fun H => ⟨⟨H.1, fun x hx y hy hne => H.2.2.2 y hy x hx hne.symm⟩, H.2.2.1, H.2.1⟩⟩ #align set.pairwise_union Set.pairwise_union /- warning: set.pairwise_union_of_symmetric -> Set.pairwise_union_of_symmetric is a dubious translation: lean 3 declaration is forall {α : Type.{u1}} {r : α -> α -> Prop} {s : Set.{u1} α} {t : Set.{u1} α}, (Symmetric.{succ u1} α r) -> (Iff (Set.Pairwise.{u1} α (Union.union.{u1} (Set.{u1} α) (Set.hasUnion.{u1} α) s t) r) (And (Set.Pairwise.{u1} α s r) (And (Set.Pairwise.{u1} α t r) (forall (a : α), (Membership.Mem.{u1, u1} α (Set.{u1} α) (Set.hasMem.{u1} α) a s) -> (forall (b : α), (Membership.Mem.{u1, u1} α (Set.{u1} α) (Set.hasMem.{u1} α) b t) -> (Ne.{succ u1} α a b) -> (r a b)))))) but is expected to have type forall {α : Type.{u1}} {r : α -> α -> Prop} {s : Set.{u1} α} {t : Set.{u1} α}, (Symmetric.{succ u1} α r) -> (Iff (Set.Pairwise.{u1} α (Union.union.{u1} (Set.{u1} α) (Set.instUnionSet.{u1} α) s t) r) (And (Set.Pairwise.{u1} α s r) (And (Set.Pairwise.{u1} α t r) (forall (a : α), (Membership.mem.{u1, u1} α (Set.{u1} α) (Set.instMembershipSet.{u1} α) a s) -> (forall (b : α), (Membership.mem.{u1, u1} α (Set.{u1} α) (Set.instMembershipSet.{u1} α) b t) -> (Ne.{succ u1} α a b) -> (r a b)))))) Case conversion may be inaccurate. Consider using '#align set.pairwise_union_of_symmetric Set.pairwise_union_of_symmetricₓ'. -/ theorem pairwise_union_of_symmetric (hr : Symmetric r) : (s ∪ t).Pairwise r ↔ s.Pairwise r ∧ t.Pairwise r ∧ ∀ a ∈ s, ∀ b ∈ t, a ≠ b → r a b := pairwise_union.trans <| by simp only [hr.iff, and_self_iff] #align set.pairwise_union_of_symmetric Set.pairwise_union_of_symmetric #print Set.pairwise_insert /- theorem pairwise_insert : (insert a s).Pairwise r ↔ s.Pairwise r ∧ ∀ b ∈ s, a ≠ b → r a b ∧ r b a := by simp only [insert_eq, pairwise_union, pairwise_singleton, true_and_iff, mem_singleton_iff, forall_eq] #align set.pairwise_insert Set.pairwise_insert -/ #print Set.pairwise_insert_of_not_mem /- theorem pairwise_insert_of_not_mem (ha : a ∉ s) : (insert a s).Pairwise r ↔ s.Pairwise r ∧ ∀ b ∈ s, r a b ∧ r b a := pairwise_insert.trans <| and_congr_right' <| forall₂_congr fun b hb => by simp [(ne_of_mem_of_not_mem hb ha).symm] #align set.pairwise_insert_of_not_mem Set.pairwise_insert_of_not_mem -/ #print Set.Pairwise.insert /- theorem Pairwise.insert (hs : s.Pairwise r) (h : ∀ b ∈ s, a ≠ b → r a b ∧ r b a) : (insert a s).Pairwise r := pairwise_insert.2 ⟨hs, h⟩ #align set.pairwise.insert Set.Pairwise.insert -/ #print Set.Pairwise.insert_of_not_mem /- theorem Pairwise.insert_of_not_mem (ha : a ∉ s) (hs : s.Pairwise r) (h : ∀ b ∈ s, r a b ∧ r b a) : (insert a s).Pairwise r := (pairwise_insert_of_not_mem ha).2 ⟨hs, h⟩ #align set.pairwise.insert_of_not_mem Set.Pairwise.insert_of_not_mem -/ #print Set.pairwise_insert_of_symmetric /- theorem pairwise_insert_of_symmetric (hr : Symmetric r) : (insert a s).Pairwise r ↔ s.Pairwise r ∧ ∀ b ∈ s, a ≠ b → r a b := by simp only [pairwise_insert, hr.iff a, and_self_iff] #align set.pairwise_insert_of_symmetric Set.pairwise_insert_of_symmetric -/ #print Set.pairwise_insert_of_symmetric_of_not_mem /- theorem pairwise_insert_of_symmetric_of_not_mem (hr : Symmetric r) (ha : a ∉ s) : (insert a s).Pairwise r ↔ s.Pairwise r ∧ ∀ b ∈ s, r a b := by simp only [pairwise_insert_of_not_mem ha, hr.iff a, and_self_iff] #align set.pairwise_insert_of_symmetric_of_not_mem Set.pairwise_insert_of_symmetric_of_not_mem -/ #print Set.Pairwise.insert_of_symmetric /- theorem Pairwise.insert_of_symmetric (hs : s.Pairwise r) (hr : Symmetric r) (h : ∀ b ∈ s, a ≠ b → r a b) : (insert a s).Pairwise r := (pairwise_insert_of_symmetric hr).2 ⟨hs, h⟩ #align set.pairwise.insert_of_symmetric Set.Pairwise.insert_of_symmetric -/ #print Set.Pairwise.insert_of_symmetric_of_not_mem /- theorem Pairwise.insert_of_symmetric_of_not_mem (hs : s.Pairwise r) (hr : Symmetric r) (ha : a ∉ s) (h : ∀ b ∈ s, r a b) : (insert a s).Pairwise r := (pairwise_insert_of_symmetric_of_not_mem hr ha).2 ⟨hs, h⟩ #align set.pairwise.insert_of_symmetric_of_not_mem Set.Pairwise.insert_of_symmetric_of_not_mem -/ #print Set.pairwise_pair /- theorem pairwise_pair : Set.Pairwise {a, b} r ↔ a ≠ b → r a b ∧ r b a := by simp [pairwise_insert] #align set.pairwise_pair Set.pairwise_pair -/ #print Set.pairwise_pair_of_symmetric /- theorem pairwise_pair_of_symmetric (hr : Symmetric r) : Set.Pairwise {a, b} r ↔ a ≠ b → r a b := by simp [pairwise_insert_of_symmetric hr] #align set.pairwise_pair_of_symmetric Set.pairwise_pair_of_symmetric -/ #print Set.pairwise_univ /- theorem pairwise_univ : (univ : Set α).Pairwise r ↔ Pairwise r := by simp only [Set.Pairwise, Pairwise, mem_univ, forall_const] #align set.pairwise_univ Set.pairwise_univ -/ /- warning: set.pairwise_bot_iff -> Set.pairwise_bot_iff is a dubious translation: lean 3 declaration is forall {α : Type.{u1}} {s : Set.{u1} α}, Iff (Set.Pairwise.{u1} α s (Bot.bot.{u1} (α -> α -> Prop) (Pi.hasBot.{u1, u1} α (fun (ᾰ : α) => α -> Prop) (fun (i : α) => Pi.hasBot.{u1, 0} α (fun (ᾰ : α) => Prop) (fun (i : α) => BooleanAlgebra.toHasBot.{0} Prop Prop.booleanAlgebra))))) (Set.Subsingleton.{u1} α s) but is expected to have type forall {α : Type.{u1}} {s : Set.{u1} α}, Iff (Set.Pairwise.{u1} α s (Bot.bot.{u1} (α -> α -> Prop) (Pi.instBotForAll.{u1, u1} α (fun (ᾰ : α) => α -> Prop) (fun (i : α) => Pi.instBotForAll.{u1, 0} α (fun (ᾰ : α) => Prop) (fun (i : α) => BooleanAlgebra.toBot.{0} Prop Prop.booleanAlgebra))))) (Set.Subsingleton.{u1} α s) Case conversion may be inaccurate. Consider using '#align set.pairwise_bot_iff Set.pairwise_bot_iffₓ'. -/ @[simp] theorem pairwise_bot_iff : s.Pairwise (⊥ : α → α → Prop) ↔ (s : Set α).Subsingleton := ⟨fun h a ha b hb => h.Eq ha hb id, fun h => h.Pairwise _⟩ #align set.pairwise_bot_iff Set.pairwise_bot_iff /- warning: set.pairwise.subsingleton -> Set.Pairwise.subsingleton is a dubious translation: lean 3 declaration is forall {α : Type.{u1}} {s : Set.{u1} α}, (Set.Pairwise.{u1} α s (Bot.bot.{u1} (α -> α -> Prop) (Pi.hasBot.{u1, u1} α (fun (ᾰ : α) => α -> Prop) (fun (i : α) => Pi.hasBot.{u1, 0} α (fun (ᾰ : α) => Prop) (fun (i : α) => BooleanAlgebra.toHasBot.{0} Prop Prop.booleanAlgebra))))) -> (Set.Subsingleton.{u1} α s) but is expected to have type forall {α : Type.{u1}} {s : Set.{u1} α}, (Set.Pairwise.{u1} α s (Bot.bot.{u1} (α -> α -> Prop) (Pi.instBotForAll.{u1, u1} α (fun (ᾰ : α) => α -> Prop) (fun (i : α) => Pi.instBotForAll.{u1, 0} α (fun (ᾰ : α) => Prop) (fun (i : α) => BooleanAlgebra.toBot.{0} Prop Prop.booleanAlgebra))))) -> (Set.Subsingleton.{u1} α s) Case conversion may be inaccurate. Consider using '#align set.pairwise.subsingleton Set.Pairwise.subsingletonₓ'. -/ alias pairwise_bot_iff ↔ pairwise.subsingleton _ #align set.pairwise.subsingleton Set.Pairwise.subsingleton #print Set.InjOn.pairwise_image /- theorem InjOn.pairwise_image {s : Set ι} (h : s.InjOn f) : (f '' s).Pairwise r ↔ s.Pairwise (r on f) := by simp (config := { contextual := true }) [h.eq_iff, Set.Pairwise] #align set.inj_on.pairwise_image Set.InjOn.pairwise_image -/ end Set end Pairwise #print pairwise_subtype_iff_pairwise_set /- theorem pairwise_subtype_iff_pairwise_set (s : Set α) (r : α → α → Prop) : (Pairwise fun (x : s) (y : s) => r x y) ↔ s.Pairwise r := by simp only [Pairwise, Set.Pairwise, SetCoe.forall, Ne.def, Subtype.ext_iff, Subtype.coe_mk] #align pairwise_subtype_iff_pairwise_set pairwise_subtype_iff_pairwise_set -/ alias pairwise_subtype_iff_pairwise_set ↔ Pairwise.set_of_subtype Set.Pairwise.subtype #align pairwise.set_of_subtype Pairwise.set_of_subtype #align set.pairwise.subtype Set.Pairwise.subtype namespace Set section PartialOrderBot variable [PartialOrder α] [OrderBot α] {s t : Set ι} {f g : ι → α} #print Set.PairwiseDisjoint /- /-- A set is `pairwise_disjoint` under `f`, if the images of any distinct two elements under `f` are disjoint. `s.pairwise disjoint` is (definitionally) the same as `s.pairwise_disjoint id`. We prefer the latter in order to allow dot notation on `set.pairwise_disjoint`, even though the former unfolds more nicely. -/ def PairwiseDisjoint (s : Set ι) (f : ι → α) : Prop := s.Pairwise (Disjoint on f) #align set.pairwise_disjoint Set.PairwiseDisjoint -/ /- warning: set.pairwise_disjoint.subset -> Set.PairwiseDisjoint.subset is a dubious translation: lean 3 declaration is forall {α : Type.{u1}} {ι : Type.{u2}} [_inst_1 : PartialOrder.{u1} α] [_inst_2 : OrderBot.{u1} α (Preorder.toLE.{u1} α (PartialOrder.toPreorder.{u1} α _inst_1))] {s : Set.{u2} ι} {t : Set.{u2} ι} {f : ι -> α}, (Set.PairwiseDisjoint.{u1, u2} α ι _inst_1 _inst_2 t f) -> (HasSubset.Subset.{u2} (Set.{u2} ι) (Set.hasSubset.{u2} ι) s t) -> (Set.PairwiseDisjoint.{u1, u2} α ι _inst_1 _inst_2 s f) but is expected to have type forall {α : Type.{u2}} {ι : Type.{u1}} [_inst_1 : PartialOrder.{u2} α] [_inst_2 : OrderBot.{u2} α (Preorder.toLE.{u2} α (PartialOrder.toPreorder.{u2} α _inst_1))] {s : Set.{u1} ι} {t : Set.{u1} ι} {f : ι -> α}, (Set.PairwiseDisjoint.{u2, u1} α ι _inst_1 _inst_2 t f) -> (HasSubset.Subset.{u1} (Set.{u1} ι) (Set.instHasSubsetSet.{u1} ι) s t) -> (Set.PairwiseDisjoint.{u2, u1} α ι _inst_1 _inst_2 s f) Case conversion may be inaccurate. Consider using '#align set.pairwise_disjoint.subset Set.PairwiseDisjoint.subsetₓ'. -/ theorem PairwiseDisjoint.subset (ht : t.PairwiseDisjoint f) (h : s ⊆ t) : s.PairwiseDisjoint f := Pairwise.mono h ht #align set.pairwise_disjoint.subset Set.PairwiseDisjoint.subset /- warning: set.pairwise_disjoint.mono_on -> Set.PairwiseDisjoint.mono_on is a dubious translation: lean 3 declaration is forall {α : Type.{u1}} {ι : Type.{u2}} [_inst_1 : PartialOrder.{u1} α] [_inst_2 : OrderBot.{u1} α (Preorder.toLE.{u1} α (PartialOrder.toPreorder.{u1} α _inst_1))] {s : Set.{u2} ι} {f : ι -> α} {g : ι -> α}, (Set.PairwiseDisjoint.{u1, u2} α ι _inst_1 _inst_2 s f) -> (forall {{i : ι}}, (Membership.Mem.{u2, u2} ι (Set.{u2} ι) (Set.hasMem.{u2} ι) i s) -> (LE.le.{u1} α (Preorder.toLE.{u1} α (PartialOrder.toPreorder.{u1} α _inst_1)) (g i) (f i))) -> (Set.PairwiseDisjoint.{u1, u2} α ι _inst_1 _inst_2 s g) but is expected to have type forall {α : Type.{u2}} {ι : Type.{u1}} [_inst_1 : PartialOrder.{u2} α] [_inst_2 : OrderBot.{u2} α (Preorder.toLE.{u2} α (PartialOrder.toPreorder.{u2} α _inst_1))] {s : Set.{u1} ι} {f : ι -> α} {g : ι -> α}, (Set.PairwiseDisjoint.{u2, u1} α ι _inst_1 _inst_2 s f) -> (forall {{i : ι}}, (Membership.mem.{u1, u1} ι (Set.{u1} ι) (Set.instMembershipSet.{u1} ι) i s) -> (LE.le.{u2} α (Preorder.toLE.{u2} α (PartialOrder.toPreorder.{u2} α _inst_1)) (g i) (f i))) -> (Set.PairwiseDisjoint.{u2, u1} α ι _inst_1 _inst_2 s g) Case conversion may be inaccurate. Consider using '#align set.pairwise_disjoint.mono_on Set.PairwiseDisjoint.mono_onₓ'. -/ theorem PairwiseDisjoint.mono_on (hs : s.PairwiseDisjoint f) (h : ∀ ⦃i⦄, i ∈ s → g i ≤ f i) : s.PairwiseDisjoint g := fun a ha b hb hab => (hs ha hb hab).mono (h ha) (h hb) #align set.pairwise_disjoint.mono_on Set.PairwiseDisjoint.mono_on /- warning: set.pairwise_disjoint.mono -> Set.PairwiseDisjoint.mono is a dubious translation: lean 3 declaration is forall {α : Type.{u1}} {ι : Type.{u2}} [_inst_1 : PartialOrder.{u1} α] [_inst_2 : OrderBot.{u1} α (Preorder.toLE.{u1} α (PartialOrder.toPreorder.{u1} α _inst_1))] {s : Set.{u2} ι} {f : ι -> α} {g : ι -> α}, (Set.PairwiseDisjoint.{u1, u2} α ι _inst_1 _inst_2 s f) -> (LE.le.{max u2 u1} (ι -> α) (Pi.hasLe.{u2, u1} ι (fun (ᾰ : ι) => α) (fun (i : ι) => Preorder.toLE.{u1} α (PartialOrder.toPreorder.{u1} α _inst_1))) g f) -> (Set.PairwiseDisjoint.{u1, u2} α ι _inst_1 _inst_2 s g) but is expected to have type forall {α : Type.{u2}} {ι : Type.{u1}} [_inst_1 : PartialOrder.{u2} α] [_inst_2 : OrderBot.{u2} α (Preorder.toLE.{u2} α (PartialOrder.toPreorder.{u2} α _inst_1))] {s : Set.{u1} ι} {f : ι -> α} {g : ι -> α}, (Set.PairwiseDisjoint.{u2, u1} α ι _inst_1 _inst_2 s f) -> (LE.le.{max u2 u1} (ι -> α) (Pi.hasLe.{u1, u2} ι (fun (ᾰ : ι) => α) (fun (i : ι) => Preorder.toLE.{u2} α (PartialOrder.toPreorder.{u2} α _inst_1))) g f) -> (Set.PairwiseDisjoint.{u2, u1} α ι _inst_1 _inst_2 s g) Case conversion may be inaccurate. Consider using '#align set.pairwise_disjoint.mono Set.PairwiseDisjoint.monoₓ'. -/ theorem PairwiseDisjoint.mono (hs : s.PairwiseDisjoint f) (h : g ≤ f) : s.PairwiseDisjoint g := hs.mono_on fun i _ => h i #align set.pairwise_disjoint.mono Set.PairwiseDisjoint.mono /- warning: set.pairwise_disjoint_empty -> Set.pairwiseDisjoint_empty is a dubious translation: lean 3 declaration is forall {α : Type.{u1}} {ι : Type.{u2}} [_inst_1 : PartialOrder.{u1} α] [_inst_2 : OrderBot.{u1} α (Preorder.toLE.{u1} α (PartialOrder.toPreorder.{u1} α _inst_1))] {f : ι -> α}, Set.PairwiseDisjoint.{u1, u2} α ι _inst_1 _inst_2 (EmptyCollection.emptyCollection.{u2} (Set.{u2} ι) (Set.hasEmptyc.{u2} ι)) f but is expected to have type forall {α : Type.{u2}} {ι : Type.{u1}} [_inst_1 : PartialOrder.{u2} α] [_inst_2 : OrderBot.{u2} α (Preorder.toLE.{u2} α (PartialOrder.toPreorder.{u2} α _inst_1))] {f : ι -> α}, Set.PairwiseDisjoint.{u2, u1} α ι _inst_1 _inst_2 (EmptyCollection.emptyCollection.{u1} (Set.{u1} ι) (Set.instEmptyCollectionSet.{u1} ι)) f Case conversion may be inaccurate. Consider using '#align set.pairwise_disjoint_empty Set.pairwiseDisjoint_emptyₓ'. -/ @[simp] theorem pairwiseDisjoint_empty : (∅ : Set ι).PairwiseDisjoint f := pairwise_empty _ #align set.pairwise_disjoint_empty Set.pairwiseDisjoint_empty /- warning: set.pairwise_disjoint_singleton -> Set.pairwiseDisjoint_singleton is a dubious translation: lean 3 declaration is forall {α : Type.{u1}} {ι : Type.{u2}} [_inst_1 : PartialOrder.{u1} α] [_inst_2 : OrderBot.{u1} α (Preorder.toLE.{u1} α (PartialOrder.toPreorder.{u1} α _inst_1))] (i : ι) (f : ι -> α), Set.PairwiseDisjoint.{u1, u2} α ι _inst_1 _inst_2 (Singleton.singleton.{u2, u2} ι (Set.{u2} ι) (Set.hasSingleton.{u2} ι) i) f but is expected to have type forall {α : Type.{u2}} {ι : Type.{u1}} [_inst_1 : PartialOrder.{u2} α] [_inst_2 : OrderBot.{u2} α (Preorder.toLE.{u2} α (PartialOrder.toPreorder.{u2} α _inst_1))] (i : ι) (f : ι -> α), Set.PairwiseDisjoint.{u2, u1} α ι _inst_1 _inst_2 (Singleton.singleton.{u1, u1} ι (Set.{u1} ι) (Set.instSingletonSet.{u1} ι) i) f Case conversion may be inaccurate. Consider using '#align set.pairwise_disjoint_singleton Set.pairwiseDisjoint_singletonₓ'. -/ @[simp] theorem pairwiseDisjoint_singleton (i : ι) (f : ι → α) : PairwiseDisjoint {i} f := pairwise_singleton i _ #align set.pairwise_disjoint_singleton Set.pairwiseDisjoint_singleton /- warning: set.pairwise_disjoint_insert -> Set.pairwiseDisjoint_insert is a dubious translation: lean 3 declaration is forall {α : Type.{u1}} {ι : Type.{u2}} [_inst_1 : PartialOrder.{u1} α] [_inst_2 : OrderBot.{u1} α (Preorder.toLE.{u1} α (PartialOrder.toPreorder.{u1} α _inst_1))] {s : Set.{u2} ι} {f : ι -> α} {i : ι}, Iff (Set.PairwiseDisjoint.{u1, u2} α ι _inst_1 _inst_2 (Insert.insert.{u2, u2} ι (Set.{u2} ι) (Set.hasInsert.{u2} ι) i s) f) (And (Set.PairwiseDisjoint.{u1, u2} α ι _inst_1 _inst_2 s f) (forall (j : ι), (Membership.Mem.{u2, u2} ι (Set.{u2} ι) (Set.hasMem.{u2} ι) j s) -> (Ne.{succ u2} ι i j) -> (Disjoint.{u1} α _inst_1 _inst_2 (f i) (f j)))) but is expected to have type forall {α : Type.{u2}} {ι : Type.{u1}} [_inst_1 : PartialOrder.{u2} α] [_inst_2 : OrderBot.{u2} α (Preorder.toLE.{u2} α (PartialOrder.toPreorder.{u2} α _inst_1))] {s : Set.{u1} ι} {f : ι -> α} {i : ι}, Iff (Set.PairwiseDisjoint.{u2, u1} α ι _inst_1 _inst_2 (Insert.insert.{u1, u1} ι (Set.{u1} ι) (Set.instInsertSet.{u1} ι) i s) f) (And (Set.PairwiseDisjoint.{u2, u1} α ι _inst_1 _inst_2 s f) (forall (j : ι), (Membership.mem.{u1, u1} ι (Set.{u1} ι) (Set.instMembershipSet.{u1} ι) j s) -> (Ne.{succ u1} ι i j) -> (Disjoint.{u2} α _inst_1 _inst_2 (f i) (f j)))) Case conversion may be inaccurate. Consider using '#align set.pairwise_disjoint_insert Set.pairwiseDisjoint_insertₓ'. -/ theorem pairwiseDisjoint_insert {i : ι} : (insert i s).PairwiseDisjoint f ↔ s.PairwiseDisjoint f ∧ ∀ j ∈ s, i ≠ j → Disjoint (f i) (f j) := Set.pairwise_insert_of_symmetric <| symmetric_disjoint.comap f #align set.pairwise_disjoint_insert Set.pairwiseDisjoint_insert #print Set.pairwiseDisjoint_insert_of_not_mem /- theorem pairwiseDisjoint_insert_of_not_mem {i : ι} (hi : i ∉ s) : (insert i s).PairwiseDisjoint f ↔ s.PairwiseDisjoint f ∧ ∀ j ∈ s, Disjoint (f i) (f j) := pairwise_insert_of_symmetric_of_not_mem (symmetric_disjoint.comap f) hi #align set.pairwise_disjoint_insert_of_not_mem Set.pairwiseDisjoint_insert_of_not_mem -/ /- warning: set.pairwise_disjoint.insert -> Set.PairwiseDisjoint.insert is a dubious translation: lean 3 declaration is forall {α : Type.{u1}} {ι : Type.{u2}} [_inst_1 : PartialOrder.{u1} α] [_inst_2 : OrderBot.{u1} α (Preorder.toLE.{u1} α (PartialOrder.toPreorder.{u1} α _inst_1))] {s : Set.{u2} ι} {f : ι -> α}, (Set.PairwiseDisjoint.{u1, u2} α ι _inst_1 _inst_2 s f) -> (forall {i : ι}, (forall (j : ι), (Membership.Mem.{u2, u2} ι (Set.{u2} ι) (Set.hasMem.{u2} ι) j s) -> (Ne.{succ u2} ι i j) -> (Disjoint.{u1} α _inst_1 _inst_2 (f i) (f j))) -> (Set.PairwiseDisjoint.{u1, u2} α ι _inst_1 _inst_2 (Insert.insert.{u2, u2} ι (Set.{u2} ι) (Set.hasInsert.{u2} ι) i s) f)) but is expected to have type forall {α : Type.{u2}} {ι : Type.{u1}} [_inst_1 : PartialOrder.{u2} α] [_inst_2 : OrderBot.{u2} α (Preorder.toLE.{u2} α (PartialOrder.toPreorder.{u2} α _inst_1))] {s : Set.{u1} ι} {f : ι -> α}, (Set.PairwiseDisjoint.{u2, u1} α ι _inst_1 _inst_2 s f) -> (forall {i : ι}, (forall (j : ι), (Membership.mem.{u1, u1} ι (Set.{u1} ι) (Set.instMembershipSet.{u1} ι) j s) -> (Ne.{succ u1} ι i j) -> (Disjoint.{u2} α _inst_1 _inst_2 (f i) (f j))) -> (Set.PairwiseDisjoint.{u2, u1} α ι _inst_1 _inst_2 (Insert.insert.{u1, u1} ι (Set.{u1} ι) (Set.instInsertSet.{u1} ι) i s) f)) Case conversion may be inaccurate. Consider using '#align set.pairwise_disjoint.insert Set.PairwiseDisjoint.insertₓ'. -/ theorem PairwiseDisjoint.insert (hs : s.PairwiseDisjoint f) {i : ι} (h : ∀ j ∈ s, i ≠ j → Disjoint (f i) (f j)) : (insert i s).PairwiseDisjoint f := Set.pairwiseDisjoint_insert.2 ⟨hs, h⟩ #align set.pairwise_disjoint.insert Set.PairwiseDisjoint.insert /- warning: set.pairwise_disjoint.insert_of_not_mem -> Set.PairwiseDisjoint.insert_of_not_mem is a dubious translation: lean 3 declaration is forall {α : Type.{u1}} {ι : Type.{u2}} [_inst_1 : PartialOrder.{u1} α] [_inst_2 : OrderBot.{u1} α (Preorder.toLE.{u1} α (PartialOrder.toPreorder.{u1} α _inst_1))] {s : Set.{u2} ι} {f : ι -> α}, (Set.PairwiseDisjoint.{u1, u2} α ι _inst_1 _inst_2 s f) -> (forall {i : ι}, (Not (Membership.Mem.{u2, u2} ι (Set.{u2} ι) (Set.hasMem.{u2} ι) i s)) -> (forall (j : ι), (Membership.Mem.{u2, u2} ι (Set.{u2} ι) (Set.hasMem.{u2} ι) j s) -> (Disjoint.{u1} α _inst_1 _inst_2 (f i) (f j))) -> (Set.PairwiseDisjoint.{u1, u2} α ι _inst_1 _inst_2 (Insert.insert.{u2, u2} ι (Set.{u2} ι) (Set.hasInsert.{u2} ι) i s) f)) but is expected to have type forall {α : Type.{u2}} {ι : Type.{u1}} [_inst_1 : PartialOrder.{u2} α] [_inst_2 : OrderBot.{u2} α (Preorder.toLE.{u2} α (PartialOrder.toPreorder.{u2} α _inst_1))] {s : Set.{u1} ι} {f : ι -> α}, (Set.PairwiseDisjoint.{u2, u1} α ι _inst_1 _inst_2 s f) -> (forall {i : ι}, (Not (Membership.mem.{u1, u1} ι (Set.{u1} ι) (Set.instMembershipSet.{u1} ι) i s)) -> (forall (j : ι), (Membership.mem.{u1, u1} ι (Set.{u1} ι) (Set.instMembershipSet.{u1} ι) j s) -> (Disjoint.{u2} α _inst_1 _inst_2 (f i) (f j))) -> (Set.PairwiseDisjoint.{u2, u1} α ι _inst_1 _inst_2 (Insert.insert.{u1, u1} ι (Set.{u1} ι) (Set.instInsertSet.{u1} ι) i s) f)) Case conversion may be inaccurate. Consider using '#align set.pairwise_disjoint.insert_of_not_mem Set.PairwiseDisjoint.insert_of_not_memₓ'. -/ theorem PairwiseDisjoint.insert_of_not_mem (hs : s.PairwiseDisjoint f) {i : ι} (hi : i ∉ s) (h : ∀ j ∈ s, Disjoint (f i) (f j)) : (insert i s).PairwiseDisjoint f := (Set.pairwiseDisjoint_insert_of_not_mem hi).2 ⟨hs, h⟩ #align set.pairwise_disjoint.insert_of_not_mem Set.PairwiseDisjoint.insert_of_not_mem /- warning: set.pairwise_disjoint.image_of_le -> Set.PairwiseDisjoint.image_of_le is a dubious translation: lean 3 declaration is forall {α : Type.{u1}} {ι : Type.{u2}} [_inst_1 : PartialOrder.{u1} α] [_inst_2 : OrderBot.{u1} α (Preorder.toLE.{u1} α (PartialOrder.toPreorder.{u1} α _inst_1))] {s : Set.{u2} ι} {f : ι -> α}, (Set.PairwiseDisjoint.{u1, u2} α ι _inst_1 _inst_2 s f) -> (forall {g : ι -> ι}, (LE.le.{max u2 u1} (ι -> α) (Pi.hasLe.{u2, u1} ι (fun (ᾰ : ι) => α) (fun (i : ι) => Preorder.toLE.{u1} α (PartialOrder.toPreorder.{u1} α _inst_1))) (Function.comp.{succ u2, succ u2, succ u1} ι ι α f g) f) -> (Set.PairwiseDisjoint.{u1, u2} α ι _inst_1 _inst_2 (Set.image.{u2, u2} ι ι g s) f)) but is expected to have type forall {α : Type.{u2}} {ι : Type.{u1}} [_inst_1 : PartialOrder.{u2} α] [_inst_2 : OrderBot.{u2} α (Preorder.toLE.{u2} α (PartialOrder.toPreorder.{u2} α _inst_1))] {s : Set.{u1} ι} {f : ι -> α}, (Set.PairwiseDisjoint.{u2, u1} α ι _inst_1 _inst_2 s f) -> (forall {g : ι -> ι}, (LE.le.{max u2 u1} (ι -> α) (Pi.hasLe.{u1, u2} ι (fun (ᾰ : ι) => α) (fun (i : ι) => Preorder.toLE.{u2} α (PartialOrder.toPreorder.{u2} α _inst_1))) (Function.comp.{succ u1, succ u1, succ u2} ι ι α f g) f) -> (Set.PairwiseDisjoint.{u2, u1} α ι _inst_1 _inst_2 (Set.image.{u1, u1} ι ι g s) f)) Case conversion may be inaccurate. Consider using '#align set.pairwise_disjoint.image_of_le Set.PairwiseDisjoint.image_of_leₓ'. -/ theorem PairwiseDisjoint.image_of_le (hs : s.PairwiseDisjoint f) {g : ι → ι} (hg : f ∘ g ≤ f) : (g '' s).PairwiseDisjoint f := by rintro _ ⟨a, ha, rfl⟩ _ ⟨b, hb, rfl⟩ h exact (hs ha hb <| ne_of_apply_ne _ h).mono (hg a) (hg b) #align set.pairwise_disjoint.image_of_le Set.PairwiseDisjoint.image_of_le #print Set.InjOn.pairwiseDisjoint_image /- theorem InjOn.pairwiseDisjoint_image {g : ι' → ι} {s : Set ι'} (h : s.InjOn g) : (g '' s).PairwiseDisjoint f ↔ s.PairwiseDisjoint (f ∘ g) := h.pairwise_image #align set.inj_on.pairwise_disjoint_image Set.InjOn.pairwiseDisjoint_image -/ #print Set.PairwiseDisjoint.range /- theorem PairwiseDisjoint.range (g : s → ι) (hg : ∀ i : s, f (g i) ≤ f i) (ht : s.PairwiseDisjoint f) : (range g).PairwiseDisjoint f := by rintro _ ⟨x, rfl⟩ _ ⟨y, rfl⟩ hxy exact (ht x.2 y.2 fun h => hxy <| congr_arg g <| Subtype.ext h).mono (hg x) (hg y) #align set.pairwise_disjoint.range Set.PairwiseDisjoint.range -/ /- warning: set.pairwise_disjoint_union -> Set.pairwiseDisjoint_union is a dubious translation: lean 3 declaration is forall {α : Type.{u1}} {ι : Type.{u2}} [_inst_1 : PartialOrder.{u1} α] [_inst_2 : OrderBot.{u1} α (Preorder.toLE.{u1} α (PartialOrder.toPreorder.{u1} α _inst_1))] {s : Set.{u2} ι} {t : Set.{u2} ι} {f : ι -> α}, Iff (Set.PairwiseDisjoint.{u1, u2} α ι _inst_1 _inst_2 (Union.union.{u2} (Set.{u2} ι) (Set.hasUnion.{u2} ι) s t) f) (And (Set.PairwiseDisjoint.{u1, u2} α ι _inst_1 _inst_2 s f) (And (Set.PairwiseDisjoint.{u1, u2} α ι _inst_1 _inst_2 t f) (forall {{i : ι}}, (Membership.Mem.{u2, u2} ι (Set.{u2} ι) (Set.hasMem.{u2} ι) i s) -> (forall {{j : ι}}, (Membership.Mem.{u2, u2} ι (Set.{u2} ι) (Set.hasMem.{u2} ι) j t) -> (Ne.{succ u2} ι i j) -> (Disjoint.{u1} α _inst_1 _inst_2 (f i) (f j)))))) but is expected to have type forall {α : Type.{u2}} {ι : Type.{u1}} [_inst_1 : PartialOrder.{u2} α] [_inst_2 : OrderBot.{u2} α (Preorder.toLE.{u2} α (PartialOrder.toPreorder.{u2} α _inst_1))] {s : Set.{u1} ι} {t : Set.{u1} ι} {f : ι -> α}, Iff (Set.PairwiseDisjoint.{u2, u1} α ι _inst_1 _inst_2 (Union.union.{u1} (Set.{u1} ι) (Set.instUnionSet.{u1} ι) s t) f) (And (Set.PairwiseDisjoint.{u2, u1} α ι _inst_1 _inst_2 s f) (And (Set.PairwiseDisjoint.{u2, u1} α ι _inst_1 _inst_2 t f) (forall {{i : ι}}, (Membership.mem.{u1, u1} ι (Set.{u1} ι) (Set.instMembershipSet.{u1} ι) i s) -> (forall {{j : ι}}, (Membership.mem.{u1, u1} ι (Set.{u1} ι) (Set.instMembershipSet.{u1} ι) j t) -> (Ne.{succ u1} ι i j) -> (Disjoint.{u2} α _inst_1 _inst_2 (f i) (f j)))))) Case conversion may be inaccurate. Consider using '#align set.pairwise_disjoint_union Set.pairwiseDisjoint_unionₓ'. -/ theorem pairwiseDisjoint_union : (s ∪ t).PairwiseDisjoint f ↔ s.PairwiseDisjoint f ∧ t.PairwiseDisjoint f ∧ ∀ ⦃i⦄, i ∈ s → ∀ ⦃j⦄, j ∈ t → i ≠ j → Disjoint (f i) (f j) := pairwise_union_of_symmetric <| symmetric_disjoint.comap f #align set.pairwise_disjoint_union Set.pairwiseDisjoint_union /- warning: set.pairwise_disjoint.union -> Set.PairwiseDisjoint.union is a dubious translation: lean 3 declaration is forall {α : Type.{u1}} {ι : Type.{u2}} [_inst_1 : PartialOrder.{u1} α] [_inst_2 : OrderBot.{u1} α (Preorder.toLE.{u1} α (PartialOrder.toPreorder.{u1} α _inst_1))] {s : Set.{u2} ι} {t : Set.{u2} ι} {f : ι -> α}, (Set.PairwiseDisjoint.{u1, u2} α ι _inst_1 _inst_2 s f) -> (Set.PairwiseDisjoint.{u1, u2} α ι _inst_1 _inst_2 t f) -> (forall {{i : ι}}, (Membership.Mem.{u2, u2} ι (Set.{u2} ι) (Set.hasMem.{u2} ι) i s) -> (forall {{j : ι}}, (Membership.Mem.{u2, u2} ι (Set.{u2} ι) (Set.hasMem.{u2} ι) j t) -> (Ne.{succ u2} ι i j) -> (Disjoint.{u1} α _inst_1 _inst_2 (f i) (f j)))) -> (Set.PairwiseDisjoint.{u1, u2} α ι _inst_1 _inst_2 (Union.union.{u2} (Set.{u2} ι) (Set.hasUnion.{u2} ι) s t) f) but is expected to have type forall {α : Type.{u2}} {ι : Type.{u1}} [_inst_1 : PartialOrder.{u2} α] [_inst_2 : OrderBot.{u2} α (Preorder.toLE.{u2} α (PartialOrder.toPreorder.{u2} α _inst_1))] {s : Set.{u1} ι} {t : Set.{u1} ι} {f : ι -> α}, (Set.PairwiseDisjoint.{u2, u1} α ι _inst_1 _inst_2 s f) -> (Set.PairwiseDisjoint.{u2, u1} α ι _inst_1 _inst_2 t f) -> (forall {{i : ι}}, (Membership.mem.{u1, u1} ι (Set.{u1} ι) (Set.instMembershipSet.{u1} ι) i s) -> (forall {{j : ι}}, (Membership.mem.{u1, u1} ι (Set.{u1} ι) (Set.instMembershipSet.{u1} ι) j t) -> (Ne.{succ u1} ι i j) -> (Disjoint.{u2} α _inst_1 _inst_2 (f i) (f j)))) -> (Set.PairwiseDisjoint.{u2, u1} α ι _inst_1 _inst_2 (Union.union.{u1} (Set.{u1} ι) (Set.instUnionSet.{u1} ι) s t) f) Case conversion may be inaccurate. Consider using '#align set.pairwise_disjoint.union Set.PairwiseDisjoint.unionₓ'. -/ theorem PairwiseDisjoint.union (hs : s.PairwiseDisjoint f) (ht : t.PairwiseDisjoint f) (h : ∀ ⦃i⦄, i ∈ s → ∀ ⦃j⦄, j ∈ t → i ≠ j → Disjoint (f i) (f j)) : (s ∪ t).PairwiseDisjoint f := pairwiseDisjoint_union.2 ⟨hs, ht, h⟩ #align set.pairwise_disjoint.union Set.PairwiseDisjoint.union /- warning: set.pairwise_disjoint.elim -> Set.PairwiseDisjoint.elim is a dubious translation: lean 3 declaration is forall {α : Type.{u1}} {ι : Type.{u2}} [_inst_1 : PartialOrder.{u1} α] [_inst_2 : OrderBot.{u1} α (Preorder.toLE.{u1} α (PartialOrder.toPreorder.{u1} α _inst_1))] {s : Set.{u2} ι} {f : ι -> α}, (Set.PairwiseDisjoint.{u1, u2} α ι _inst_1 _inst_2 s f) -> (forall {i : ι} {j : ι}, (Membership.Mem.{u2, u2} ι (Set.{u2} ι) (Set.hasMem.{u2} ι) i s) -> (Membership.Mem.{u2, u2} ι (Set.{u2} ι) (Set.hasMem.{u2} ι) j s) -> (Not (Disjoint.{u1} α _inst_1 _inst_2 (f i) (f j))) -> (Eq.{succ u2} ι i j)) but is expected to have type forall {α : Type.{u2}} {ι : Type.{u1}} [_inst_1 : PartialOrder.{u2} α] [_inst_2 : OrderBot.{u2} α (Preorder.toLE.{u2} α (PartialOrder.toPreorder.{u2} α _inst_1))] {s : Set.{u1} ι} {f : ι -> α}, (Set.PairwiseDisjoint.{u2, u1} α ι _inst_1 _inst_2 s f) -> (forall {i : ι} {j : ι}, (Membership.mem.{u1, u1} ι (Set.{u1} ι) (Set.instMembershipSet.{u1} ι) i s) -> (Membership.mem.{u1, u1} ι (Set.{u1} ι) (Set.instMembershipSet.{u1} ι) j s) -> (Not (Disjoint.{u2} α _inst_1 _inst_2 (f i) (f j))) -> (Eq.{succ u1} ι i j)) Case conversion may be inaccurate. Consider using '#align set.pairwise_disjoint.elim Set.PairwiseDisjoint.elimₓ'. -/ -- classical theorem PairwiseDisjoint.elim (hs : s.PairwiseDisjoint f) {i j : ι} (hi : i ∈ s) (hj : j ∈ s) (h : ¬Disjoint (f i) (f j)) : i = j := hs.Eq hi hj h #align set.pairwise_disjoint.elim Set.PairwiseDisjoint.elim end PartialOrderBot section SemilatticeInfBot variable [SemilatticeInf α] [OrderBot α] {s t : Set ι} {f g : ι → α} /- warning: set.pairwise_disjoint.elim' -> Set.PairwiseDisjoint.elim' is a dubious translation: lean 3 declaration is forall {α : Type.{u1}} {ι : Type.{u2}} [_inst_1 : SemilatticeInf.{u1} α] [_inst_2 : OrderBot.{u1} α (Preorder.toLE.{u1} α (PartialOrder.toPreorder.{u1} α (SemilatticeInf.toPartialOrder.{u1} α _inst_1)))] {s : Set.{u2} ι} {f : ι -> α}, (Set.PairwiseDisjoint.{u1, u2} α ι (SemilatticeInf.toPartialOrder.{u1} α _inst_1) _inst_2 s f) -> (forall {i : ι} {j : ι}, (Membership.Mem.{u2, u2} ι (Set.{u2} ι) (Set.hasMem.{u2} ι) i s) -> (Membership.Mem.{u2, u2} ι (Set.{u2} ι) (Set.hasMem.{u2} ι) j s) -> (Ne.{succ u1} α (Inf.inf.{u1} α (SemilatticeInf.toHasInf.{u1} α _inst_1) (f i) (f j)) (Bot.bot.{u1} α (OrderBot.toHasBot.{u1} α (Preorder.toLE.{u1} α (PartialOrder.toPreorder.{u1} α (SemilatticeInf.toPartialOrder.{u1} α _inst_1))) _inst_2))) -> (Eq.{succ u2} ι i j)) but is expected to have type forall {α : Type.{u2}} {ι : Type.{u1}} [_inst_1 : SemilatticeInf.{u2} α] [_inst_2 : OrderBot.{u2} α (Preorder.toLE.{u2} α (PartialOrder.toPreorder.{u2} α (SemilatticeInf.toPartialOrder.{u2} α _inst_1)))] {s : Set.{u1} ι} {f : ι -> α}, (Set.PairwiseDisjoint.{u2, u1} α ι (SemilatticeInf.toPartialOrder.{u2} α _inst_1) _inst_2 s f) -> (forall {i : ι} {j : ι}, (Membership.mem.{u1, u1} ι (Set.{u1} ι) (Set.instMembershipSet.{u1} ι) i s) -> (Membership.mem.{u1, u1} ι (Set.{u1} ι) (Set.instMembershipSet.{u1} ι) j s) -> (Ne.{succ u2} α (Inf.inf.{u2} α (SemilatticeInf.toInf.{u2} α _inst_1) (f i) (f j)) (Bot.bot.{u2} α (OrderBot.toBot.{u2} α (Preorder.toLE.{u2} α (PartialOrder.toPreorder.{u2} α (SemilatticeInf.toPartialOrder.{u2} α _inst_1))) _inst_2))) -> (Eq.{succ u1} ι i j)) Case conversion may be inaccurate. Consider using '#align set.pairwise_disjoint.elim' Set.PairwiseDisjoint.elim'ₓ'. -/ -- classical theorem PairwiseDisjoint.elim' (hs : s.PairwiseDisjoint f) {i j : ι} (hi : i ∈ s) (hj : j ∈ s) (h : f i ⊓ f j ≠ ⊥) : i = j := hs.elim hi hj fun hij => h hij.eq_bot #align set.pairwise_disjoint.elim' Set.PairwiseDisjoint.elim' /- warning: set.pairwise_disjoint.eq_of_le -> Set.PairwiseDisjoint.eq_of_le is a dubious translation: lean 3 declaration is forall {α : Type.{u1}} {ι : Type.{u2}} [_inst_1 : SemilatticeInf.{u1} α] [_inst_2 : OrderBot.{u1} α (Preorder.toLE.{u1} α (PartialOrder.toPreorder.{u1} α (SemilatticeInf.toPartialOrder.{u1} α _inst_1)))] {s : Set.{u2} ι} {f : ι -> α}, (Set.PairwiseDisjoint.{u1, u2} α ι (SemilatticeInf.toPartialOrder.{u1} α _inst_1) _inst_2 s f) -> (forall {i : ι} {j : ι}, (Membership.Mem.{u2, u2} ι (Set.{u2} ι) (Set.hasMem.{u2} ι) i s) -> (Membership.Mem.{u2, u2} ι (Set.{u2} ι) (Set.hasMem.{u2} ι) j s) -> (Ne.{succ u1} α (f i) (Bot.bot.{u1} α (OrderBot.toHasBot.{u1} α (Preorder.toLE.{u1} α (PartialOrder.toPreorder.{u1} α (SemilatticeInf.toPartialOrder.{u1} α _inst_1))) _inst_2))) -> (LE.le.{u1} α (Preorder.toLE.{u1} α (PartialOrder.toPreorder.{u1} α (SemilatticeInf.toPartialOrder.{u1} α _inst_1))) (f i) (f j)) -> (Eq.{succ u2} ι i j)) but is expected to have type forall {α : Type.{u2}} {ι : Type.{u1}} [_inst_1 : SemilatticeInf.{u2} α] [_inst_2 : OrderBot.{u2} α (Preorder.toLE.{u2} α (PartialOrder.toPreorder.{u2} α (SemilatticeInf.toPartialOrder.{u2} α _inst_1)))] {s : Set.{u1} ι} {f : ι -> α}, (Set.PairwiseDisjoint.{u2, u1} α ι (SemilatticeInf.toPartialOrder.{u2} α _inst_1) _inst_2 s f) -> (forall {i : ι} {j : ι}, (Membership.mem.{u1, u1} ι (Set.{u1} ι) (Set.instMembershipSet.{u1} ι) i s) -> (Membership.mem.{u1, u1} ι (Set.{u1} ι) (Set.instMembershipSet.{u1} ι) j s) -> (Ne.{succ u2} α (f i) (Bot.bot.{u2} α (OrderBot.toBot.{u2} α (Preorder.toLE.{u2} α (PartialOrder.toPreorder.{u2} α (SemilatticeInf.toPartialOrder.{u2} α _inst_1))) _inst_2))) -> (LE.le.{u2} α (Preorder.toLE.{u2} α (PartialOrder.toPreorder.{u2} α (SemilatticeInf.toPartialOrder.{u2} α _inst_1))) (f i) (f j)) -> (Eq.{succ u1} ι i j)) Case conversion may be inaccurate. Consider using '#align set.pairwise_disjoint.eq_of_le Set.PairwiseDisjoint.eq_of_leₓ'. -/ theorem PairwiseDisjoint.eq_of_le (hs : s.PairwiseDisjoint f) {i j : ι} (hi : i ∈ s) (hj : j ∈ s) (hf : f i ≠ ⊥) (hij : f i ≤ f j) : i = j := hs.elim' hi hj fun h => hf <| (inf_of_le_left hij).symm.trans h #align set.pairwise_disjoint.eq_of_le Set.PairwiseDisjoint.eq_of_le end SemilatticeInfBot /-! ### Pairwise disjoint set of sets -/ /- warning: set.pairwise_disjoint_range_singleton -> Set.pairwiseDisjoint_range_singleton is a dubious translation: lean 3 declaration is forall {ι : Type.{u1}}, Set.PairwiseDisjoint.{u1, u1} (Set.{u1} ι) (Set.{u1} ι) (SemilatticeInf.toPartialOrder.{u1} (Set.{u1} ι) (Lattice.toSemilatticeInf.{u1} (Set.{u1} ι) (GeneralizedCoheytingAlgebra.toLattice.{u1} (Set.{u1} ι) (GeneralizedBooleanAlgebra.toGeneralizedCoheytingAlgebra.{u1} (Set.{u1} ι) (BooleanAlgebra.toGeneralizedBooleanAlgebra.{u1} (Set.{u1} ι) (Set.booleanAlgebra.{u1} ι)))))) (GeneralizedBooleanAlgebra.toOrderBot.{u1} (Set.{u1} ι) (BooleanAlgebra.toGeneralizedBooleanAlgebra.{u1} (Set.{u1} ι) (Set.booleanAlgebra.{u1} ι))) (Set.range.{u1, succ u1} (Set.{u1} ι) ι (Singleton.singleton.{u1, u1} ι (Set.{u1} ι) (Set.hasSingleton.{u1} ι))) (id.{succ u1} (Set.{u1} ι)) but is expected to have type forall {ι : Type.{u1}}, Set.PairwiseDisjoint.{u1, u1} (Set.{u1} ι) (Set.{u1} ι) (SemilatticeInf.toPartialOrder.{u1} (Set.{u1} ι) (Lattice.toSemilatticeInf.{u1} (Set.{u1} ι) (GeneralizedCoheytingAlgebra.toLattice.{u1} (Set.{u1} ι) (CoheytingAlgebra.toGeneralizedCoheytingAlgebra.{u1} (Set.{u1} ι) (BiheytingAlgebra.toCoheytingAlgebra.{u1} (Set.{u1} ι) (BooleanAlgebra.toBiheytingAlgebra.{u1} (Set.{u1} ι) (Set.instBooleanAlgebraSet.{u1} ι))))))) (BoundedOrder.toOrderBot.{u1} (Set.{u1} ι) (Preorder.toLE.{u1} (Set.{u1} ι) (PartialOrder.toPreorder.{u1} (Set.{u1} ι) (SemilatticeInf.toPartialOrder.{u1} (Set.{u1} ι) (Lattice.toSemilatticeInf.{u1} (Set.{u1} ι) (GeneralizedCoheytingAlgebra.toLattice.{u1} (Set.{u1} ι) (CoheytingAlgebra.toGeneralizedCoheytingAlgebra.{u1} (Set.{u1} ι) (BiheytingAlgebra.toCoheytingAlgebra.{u1} (Set.{u1} ι) (BooleanAlgebra.toBiheytingAlgebra.{u1} (Set.{u1} ι) (Set.instBooleanAlgebraSet.{u1} ι))))))))) (BooleanAlgebra.toBoundedOrder.{u1} (Set.{u1} ι) (Set.instBooleanAlgebraSet.{u1} ι))) (Set.range.{u1, succ u1} (Set.{u1} ι) ι (Singleton.singleton.{u1, u1} ι (Set.{u1} ι) (Set.instSingletonSet.{u1} ι))) (id.{succ u1} (Set.{u1} ι)) Case conversion may be inaccurate. Consider using '#align set.pairwise_disjoint_range_singleton Set.pairwiseDisjoint_range_singletonₓ'. -/ theorem pairwiseDisjoint_range_singleton : (Set.range (singleton : ι → Set ι)).PairwiseDisjoint id := by rintro _ ⟨a, rfl⟩ _ ⟨b, rfl⟩ h exact disjoint_singleton.2 (ne_of_apply_ne _ h) #align set.pairwise_disjoint_range_singleton Set.pairwiseDisjoint_range_singleton /- warning: set.pairwise_disjoint_fiber -> Set.pairwiseDisjoint_fiber is a dubious translation: lean 3 declaration is forall {α : Type.{u1}} {ι : Type.{u2}} (f : ι -> α) (s : Set.{u1} α), Set.PairwiseDisjoint.{u2, u1} (Set.{u2} ι) α (SemilatticeInf.toPartialOrder.{u2} (Set.{u2} ι) (Lattice.toSemilatticeInf.{u2} (Set.{u2} ι) (GeneralizedCoheytingAlgebra.toLattice.{u2} (Set.{u2} ι) (GeneralizedBooleanAlgebra.toGeneralizedCoheytingAlgebra.{u2} (Set.{u2} ι) (BooleanAlgebra.toGeneralizedBooleanAlgebra.{u2} (Set.{u2} ι) (Set.booleanAlgebra.{u2} ι)))))) (GeneralizedBooleanAlgebra.toOrderBot.{u2} (Set.{u2} ι) (BooleanAlgebra.toGeneralizedBooleanAlgebra.{u2} (Set.{u2} ι) (Set.booleanAlgebra.{u2} ι))) s (fun (a : α) => Set.preimage.{u2, u1} ι α f (Singleton.singleton.{u1, u1} α (Set.{u1} α) (Set.hasSingleton.{u1} α) a)) but is expected to have type forall {α : Type.{u2}} {ι : Type.{u1}} (f : ι -> α) (s : Set.{u2} α), Set.PairwiseDisjoint.{u1, u2} (Set.{u1} ι) α (SemilatticeInf.toPartialOrder.{u1} (Set.{u1} ι) (Lattice.toSemilatticeInf.{u1} (Set.{u1} ι) (GeneralizedCoheytingAlgebra.toLattice.{u1} (Set.{u1} ι) (CoheytingAlgebra.toGeneralizedCoheytingAlgebra.{u1} (Set.{u1} ι) (BiheytingAlgebra.toCoheytingAlgebra.{u1} (Set.{u1} ι) (BooleanAlgebra.toBiheytingAlgebra.{u1} (Set.{u1} ι) (Set.instBooleanAlgebraSet.{u1} ι))))))) (BoundedOrder.toOrderBot.{u1} (Set.{u1} ι) (Preorder.toLE.{u1} (Set.{u1} ι) (PartialOrder.toPreorder.{u1} (Set.{u1} ι) (SemilatticeInf.toPartialOrder.{u1} (Set.{u1} ι) (Lattice.toSemilatticeInf.{u1} (Set.{u1} ι) (GeneralizedCoheytingAlgebra.toLattice.{u1} (Set.{u1} ι) (CoheytingAlgebra.toGeneralizedCoheytingAlgebra.{u1} (Set.{u1} ι) (BiheytingAlgebra.toCoheytingAlgebra.{u1} (Set.{u1} ι) (BooleanAlgebra.toBiheytingAlgebra.{u1} (Set.{u1} ι) (Set.instBooleanAlgebraSet.{u1} ι))))))))) (BooleanAlgebra.toBoundedOrder.{u1} (Set.{u1} ι) (Set.instBooleanAlgebraSet.{u1} ι))) s (fun (a : α) => Set.preimage.{u1, u2} ι α f (Singleton.singleton.{u2, u2} α (Set.{u2} α) (Set.instSingletonSet.{u2} α) a)) Case conversion may be inaccurate. Consider using '#align set.pairwise_disjoint_fiber Set.pairwiseDisjoint_fiberₓ'. -/ theorem pairwiseDisjoint_fiber (f : ι → α) (s : Set α) : s.PairwiseDisjoint fun a => f ⁻¹' {a} := fun a _ b _ h => disjoint_iff_inf_le.mpr fun i ⟨hia, hib⟩ => h <| (Eq.symm hia).trans hib #align set.pairwise_disjoint_fiber Set.pairwiseDisjoint_fiber /- warning: set.pairwise_disjoint.elim_set -> Set.PairwiseDisjoint.elim_set is a dubious translation: lean 3 declaration is forall {α : Type.{u1}} {ι : Type.{u2}} {s : Set.{u2} ι} {f : ι -> (Set.{u1} α)}, (Set.PairwiseDisjoint.{u1, u2} (Set.{u1} α) ι (SemilatticeInf.toPartialOrder.{u1} (Set.{u1} α) (Lattice.toSemilatticeInf.{u1} (Set.{u1} α) (GeneralizedCoheytingAlgebra.toLattice.{u1} (Set.{u1} α) (GeneralizedBooleanAlgebra.toGeneralizedCoheytingAlgebra.{u1} (Set.{u1} α) (BooleanAlgebra.toGeneralizedBooleanAlgebra.{u1} (Set.{u1} α) (Set.booleanAlgebra.{u1} α)))))) (GeneralizedBooleanAlgebra.toOrderBot.{u1} (Set.{u1} α) (BooleanAlgebra.toGeneralizedBooleanAlgebra.{u1} (Set.{u1} α) (Set.booleanAlgebra.{u1} α))) s f) -> (forall {i : ι} {j : ι}, (Membership.Mem.{u2, u2} ι (Set.{u2} ι) (Set.hasMem.{u2} ι) i s) -> (Membership.Mem.{u2, u2} ι (Set.{u2} ι) (Set.hasMem.{u2} ι) j s) -> (forall (a : α), (Membership.Mem.{u1, u1} α (Set.{u1} α) (Set.hasMem.{u1} α) a (f i)) -> (Membership.Mem.{u1, u1} α (Set.{u1} α) (Set.hasMem.{u1} α) a (f j)) -> (Eq.{succ u2} ι i j))) but is expected to have type forall {α : Type.{u1}} {ι : Type.{u2}} {s : Set.{u2} ι} {f : ι -> (Set.{u1} α)}, (Set.PairwiseDisjoint.{u1, u2} (Set.{u1} α) ι (SemilatticeInf.toPartialOrder.{u1} (Set.{u1} α) (Lattice.toSemilatticeInf.{u1} (Set.{u1} α) (GeneralizedCoheytingAlgebra.toLattice.{u1} (Set.{u1} α) (CoheytingAlgebra.toGeneralizedCoheytingAlgebra.{u1} (Set.{u1} α) (BiheytingAlgebra.toCoheytingAlgebra.{u1} (Set.{u1} α) (BooleanAlgebra.toBiheytingAlgebra.{u1} (Set.{u1} α) (Set.instBooleanAlgebraSet.{u1} α))))))) (BoundedOrder.toOrderBot.{u1} (Set.{u1} α) (Preorder.toLE.{u1} (Set.{u1} α) (PartialOrder.toPreorder.{u1} (Set.{u1} α) (SemilatticeInf.toPartialOrder.{u1} (Set.{u1} α) (Lattice.toSemilatticeInf.{u1} (Set.{u1} α) (GeneralizedCoheytingAlgebra.toLattice.{u1} (Set.{u1} α) (CoheytingAlgebra.toGeneralizedCoheytingAlgebra.{u1} (Set.{u1} α) (BiheytingAlgebra.toCoheytingAlgebra.{u1} (Set.{u1} α) (BooleanAlgebra.toBiheytingAlgebra.{u1} (Set.{u1} α) (Set.instBooleanAlgebraSet.{u1} α))))))))) (BooleanAlgebra.toBoundedOrder.{u1} (Set.{u1} α) (Set.instBooleanAlgebraSet.{u1} α))) s f) -> (forall {i : ι} {j : ι}, (Membership.mem.{u2, u2} ι (Set.{u2} ι) (Set.instMembershipSet.{u2} ι) i s) -> (Membership.mem.{u2, u2} ι (Set.{u2} ι) (Set.instMembershipSet.{u2} ι) j s) -> (forall (a : α), (Membership.mem.{u1, u1} α (Set.{u1} α) (Set.instMembershipSet.{u1} α) a (f i)) -> (Membership.mem.{u1, u1} α (Set.{u1} α) (Set.instMembershipSet.{u1} α) a (f j)) -> (Eq.{succ u2} ι i j))) Case conversion may be inaccurate. Consider using '#align set.pairwise_disjoint.elim_set Set.PairwiseDisjoint.elim_setₓ'. -/ -- classical theorem PairwiseDisjoint.elim_set {s : Set ι} {f : ι → Set α} (hs : s.PairwiseDisjoint f) {i j : ι} (hi : i ∈ s) (hj : j ∈ s) (a : α) (hai : a ∈ f i) (haj : a ∈ f j) : i = j := hs.elim hi hj <| not_disjoint_iff.2 ⟨a, hai, haj⟩ #align set.pairwise_disjoint.elim_set Set.PairwiseDisjoint.elim_set /- warning: set.pairwise_disjoint_image_right_iff -> Set.pairwiseDisjoint_image_right_iff is a dubious translation: lean 3 declaration is forall {α : Type.{u1}} {β : Type.{u2}} {γ : Type.{u3}} {f : α -> β -> γ} {s : Set.{u1} α} {t : Set.{u2} β}, (forall (a : α), (Membership.Mem.{u1, u1} α (Set.{u1} α) (Set.hasMem.{u1} α) a s) -> (Function.Injective.{succ u2, succ u3} β γ (f a))) -> (Iff (Set.PairwiseDisjoint.{u3, u1} (Set.{u3} γ) α (SemilatticeInf.toPartialOrder.{u3} (Set.{u3} γ) (Lattice.toSemilatticeInf.{u3} (Set.{u3} γ) (GeneralizedCoheytingAlgebra.toLattice.{u3} (Set.{u3} γ) (GeneralizedBooleanAlgebra.toGeneralizedCoheytingAlgebra.{u3} (Set.{u3} γ) (BooleanAlgebra.toGeneralizedBooleanAlgebra.{u3} (Set.{u3} γ) (Set.booleanAlgebra.{u3} γ)))))) (GeneralizedBooleanAlgebra.toOrderBot.{u3} (Set.{u3} γ) (BooleanAlgebra.toGeneralizedBooleanAlgebra.{u3} (Set.{u3} γ) (Set.booleanAlgebra.{u3} γ))) s (fun (a : α) => Set.image.{u2, u3} β γ (f a) t)) (Set.InjOn.{max u1 u2, u3} (Prod.{u1, u2} α β) γ (fun (p : Prod.{u1, u2} α β) => f (Prod.fst.{u1, u2} α β p) (Prod.snd.{u1, u2} α β p)) (Set.prod.{u1, u2} α β s t))) but is expected to have type forall {α : Type.{u3}} {β : Type.{u2}} {γ : Type.{u1}} {f : α -> β -> γ} {s : Set.{u3} α} {t : Set.{u2} β}, (forall (a : α), (Membership.mem.{u3, u3} α (Set.{u3} α) (Set.instMembershipSet.{u3} α) a s) -> (Function.Injective.{succ u2, succ u1} β γ (f a))) -> (Iff (Set.PairwiseDisjoint.{u1, u3} (Set.{u1} γ) α (SemilatticeInf.toPartialOrder.{u1} (Set.{u1} γ) (Lattice.toSemilatticeInf.{u1} (Set.{u1} γ) (GeneralizedCoheytingAlgebra.toLattice.{u1} (Set.{u1} γ) (CoheytingAlgebra.toGeneralizedCoheytingAlgebra.{u1} (Set.{u1} γ) (BiheytingAlgebra.toCoheytingAlgebra.{u1} (Set.{u1} γ) (BooleanAlgebra.toBiheytingAlgebra.{u1} (Set.{u1} γ) (Set.instBooleanAlgebraSet.{u1} γ))))))) (BoundedOrder.toOrderBot.{u1} (Set.{u1} γ) (Preorder.toLE.{u1} (Set.{u1} γ) (PartialOrder.toPreorder.{u1} (Set.{u1} γ) (SemilatticeInf.toPartialOrder.{u1} (Set.{u1} γ) (Lattice.toSemilatticeInf.{u1} (Set.{u1} γ) (GeneralizedCoheytingAlgebra.toLattice.{u1} (Set.{u1} γ) (CoheytingAlgebra.toGeneralizedCoheytingAlgebra.{u1} (Set.{u1} γ) (BiheytingAlgebra.toCoheytingAlgebra.{u1} (Set.{u1} γ) (BooleanAlgebra.toBiheytingAlgebra.{u1} (Set.{u1} γ) (Set.instBooleanAlgebraSet.{u1} γ))))))))) (BooleanAlgebra.toBoundedOrder.{u1} (Set.{u1} γ) (Set.instBooleanAlgebraSet.{u1} γ))) s (fun (a : α) => Set.image.{u2, u1} β γ (f a) t)) (Set.InjOn.{max u3 u2, u1} (Prod.{u3, u2} α β) γ (fun (p : Prod.{u3, u2} α β) => f (Prod.fst.{u3, u2} α β p) (Prod.snd.{u3, u2} α β p)) (Set.prod.{u3, u2} α β s t))) Case conversion may be inaccurate. Consider using '#align set.pairwise_disjoint_image_right_iff Set.pairwiseDisjoint_image_right_iffₓ'. -/ /- ./././Mathport/Syntax/Translate/Expr.lean:177:8: unsupported: ambiguous notation -/ /-- The partial images of a binary function `f` whose partial evaluations are injective are pairwise disjoint iff `f` is injective . -/ theorem pairwiseDisjoint_image_right_iff {f : α → β → γ} {s : Set α} {t : Set β} (hf : ∀ a ∈ s, Injective (f a)) : (s.PairwiseDisjoint fun a => f a '' t) ↔ (s ×ˢ t).InjOn fun p => f p.1 p.2 := by refine' ⟨fun hs x hx y hy (h : f _ _ = _) => _, fun hs x hx y hy h => _⟩ · suffices x.1 = y.1 by exact Prod.ext this (hf _ hx.1 <| h.trans <| by rw [this]) refine' hs.elim hx.1 hy.1 (not_disjoint_iff.2 ⟨_, mem_image_of_mem _ hx.2, _⟩) rw [h] exact mem_image_of_mem _ hy.2 · refine' disjoint_iff_inf_le.mpr _ rintro _ ⟨⟨a, ha, hab⟩, b, hb, rfl⟩ exact h (congr_arg Prod.fst <| hs (mk_mem_prod hx ha) (mk_mem_prod hy hb) hab) #align set.pairwise_disjoint_image_right_iff Set.pairwiseDisjoint_image_right_iff /- warning: set.pairwise_disjoint_image_left_iff -> Set.pairwiseDisjoint_image_left_iff is a dubious translation: lean 3 declaration is forall {α : Type.{u1}} {β : Type.{u2}} {γ : Type.{u3}} {f : α -> β -> γ} {s : Set.{u1} α} {t : Set.{u2} β}, (forall (b : β), (Membership.Mem.{u2, u2} β (Set.{u2} β) (Set.hasMem.{u2} β) b t) -> (Function.Injective.{succ u1, succ u3} α γ (fun (a : α) => f a b))) -> (Iff (Set.PairwiseDisjoint.{u3, u2} (Set.{u3} γ) β (SemilatticeInf.toPartialOrder.{u3} (Set.{u3} γ) (Lattice.toSemilatticeInf.{u3} (Set.{u3} γ) (GeneralizedCoheytingAlgebra.toLattice.{u3} (Set.{u3} γ) (GeneralizedBooleanAlgebra.toGeneralizedCoheytingAlgebra.{u3} (Set.{u3} γ) (BooleanAlgebra.toGeneralizedBooleanAlgebra.{u3} (Set.{u3} γ) (Set.booleanAlgebra.{u3} γ)))))) (GeneralizedBooleanAlgebra.toOrderBot.{u3} (Set.{u3} γ) (BooleanAlgebra.toGeneralizedBooleanAlgebra.{u3} (Set.{u3} γ) (Set.booleanAlgebra.{u3} γ))) t (fun (b : β) => Set.image.{u1, u3} α γ (fun (a : α) => f a b) s)) (Set.InjOn.{max u1 u2, u3} (Prod.{u1, u2} α β) γ (fun (p : Prod.{u1, u2} α β) => f (Prod.fst.{u1, u2} α β p) (Prod.snd.{u1, u2} α β p)) (Set.prod.{u1, u2} α β s t))) but is expected to have type forall {α : Type.{u3}} {β : Type.{u2}} {γ : Type.{u1}} {f : α -> β -> γ} {s : Set.{u3} α} {t : Set.{u2} β}, (forall (b : β), (Membership.mem.{u2, u2} β (Set.{u2} β) (Set.instMembershipSet.{u2} β) b t) -> (Function.Injective.{succ u3, succ u1} α γ (fun (a : α) => f a b))) -> (Iff (Set.PairwiseDisjoint.{u1, u2} (Set.{u1} γ) β (SemilatticeInf.toPartialOrder.{u1} (Set.{u1} γ) (Lattice.toSemilatticeInf.{u1} (Set.{u1} γ) (GeneralizedCoheytingAlgebra.toLattice.{u1} (Set.{u1} γ) (CoheytingAlgebra.toGeneralizedCoheytingAlgebra.{u1} (Set.{u1} γ) (BiheytingAlgebra.toCoheytingAlgebra.{u1} (Set.{u1} γ) (BooleanAlgebra.toBiheytingAlgebra.{u1} (Set.{u1} γ) (Set.instBooleanAlgebraSet.{u1} γ))))))) (BoundedOrder.toOrderBot.{u1} (Set.{u1} γ) (Preorder.toLE.{u1} (Set.{u1} γ) (PartialOrder.toPreorder.{u1} (Set.{u1} γ) (SemilatticeInf.toPartialOrder.{u1} (Set.{u1} γ) (Lattice.toSemilatticeInf.{u1} (Set.{u1} γ) (GeneralizedCoheytingAlgebra.toLattice.{u1} (Set.{u1} γ) (CoheytingAlgebra.toGeneralizedCoheytingAlgebra.{u1} (Set.{u1} γ) (BiheytingAlgebra.toCoheytingAlgebra.{u1} (Set.{u1} γ) (BooleanAlgebra.toBiheytingAlgebra.{u1} (Set.{u1} γ) (Set.instBooleanAlgebraSet.{u1} γ))))))))) (BooleanAlgebra.toBoundedOrder.{u1} (Set.{u1} γ) (Set.instBooleanAlgebraSet.{u1} γ))) t (fun (b : β) => Set.image.{u3, u1} α γ (fun (a : α) => f a b) s)) (Set.InjOn.{max u3 u2, u1} (Prod.{u3, u2} α β) γ (fun (p : Prod.{u3, u2} α β) => f (Prod.fst.{u3, u2} α β p) (Prod.snd.{u3, u2} α β p)) (Set.prod.{u3, u2} α β s t))) Case conversion may be inaccurate. Consider using '#align set.pairwise_disjoint_image_left_iff Set.pairwiseDisjoint_image_left_iffₓ'. -/ /- ./././Mathport/Syntax/Translate/Expr.lean:177:8: unsupported: ambiguous notation -/ /-- The partial images of a binary function `f` whose partial evaluations are injective are pairwise disjoint iff `f` is injective . -/ theorem pairwiseDisjoint_image_left_iff {f : α → β → γ} {s : Set α} {t : Set β} (hf : ∀ b ∈ t, Injective fun a => f a b) : (t.PairwiseDisjoint fun b => (fun a => f a b) '' s) ↔ (s ×ˢ t).InjOn fun p => f p.1 p.2 := by refine' ⟨fun ht x hx y hy (h : f _ _ = _) => _, fun ht x hx y hy h => _⟩ · suffices x.2 = y.2 by exact Prod.ext (hf _ hx.2 <| h.trans <| by rw [this]) this refine' ht.elim hx.2 hy.2 (not_disjoint_iff.2 ⟨_, mem_image_of_mem _ hx.1, _⟩) rw [h] exact mem_image_of_mem _ hy.1 · refine' disjoint_iff_inf_le.mpr _ rintro _ ⟨⟨a, ha, hab⟩, b, hb, rfl⟩ exact h (congr_arg Prod.snd <| ht (mk_mem_prod ha hx) (mk_mem_prod hb hy) hab) #align set.pairwise_disjoint_image_left_iff Set.pairwiseDisjoint_image_left_iff end Set /- warning: pairwise_disjoint_fiber -> pairwise_disjoint_fiber is a dubious translation: lean 3 declaration is forall {α : Type.{u1}} {ι : Type.{u2}} (f : ι -> α), Pairwise.{u1} α (Function.onFun.{succ u1, succ u2, 1} α (Set.{u2} ι) Prop (Disjoint.{u2} (Set.{u2} ι) (SemilatticeInf.toPartialOrder.{u2} (Set.{u2} ι) (Lattice.toSemilatticeInf.{u2} (Set.{u2} ι) (GeneralizedCoheytingAlgebra.toLattice.{u2} (Set.{u2} ι) (GeneralizedBooleanAlgebra.toGeneralizedCoheytingAlgebra.{u2} (Set.{u2} ι) (BooleanAlgebra.toGeneralizedBooleanAlgebra.{u2} (Set.{u2} ι) (Set.booleanAlgebra.{u2} ι)))))) (GeneralizedBooleanAlgebra.toOrderBot.{u2} (Set.{u2} ι) (BooleanAlgebra.toGeneralizedBooleanAlgebra.{u2} (Set.{u2} ι) (Set.booleanAlgebra.{u2} ι)))) (fun (a : α) => Set.preimage.{u2, u1} ι α f (Singleton.singleton.{u1, u1} α (Set.{u1} α) (Set.hasSingleton.{u1} α) a))) but is expected to have type forall {α : Type.{u2}} {ι : Type.{u1}} (f : ι -> α), Pairwise.{u2} α (Function.onFun.{succ u2, succ u1, 1} α (Set.{u1} ι) Prop (Disjoint.{u1} (Set.{u1} ι) (SemilatticeInf.toPartialOrder.{u1} (Set.{u1} ι) (Lattice.toSemilatticeInf.{u1} (Set.{u1} ι) (GeneralizedCoheytingAlgebra.toLattice.{u1} (Set.{u1} ι) (CoheytingAlgebra.toGeneralizedCoheytingAlgebra.{u1} (Set.{u1} ι) (BiheytingAlgebra.toCoheytingAlgebra.{u1} (Set.{u1} ι) (BooleanAlgebra.toBiheytingAlgebra.{u1} (Set.{u1} ι) (Set.instBooleanAlgebraSet.{u1} ι))))))) (BoundedOrder.toOrderBot.{u1} (Set.{u1} ι) (Preorder.toLE.{u1} (Set.{u1} ι) (PartialOrder.toPreorder.{u1} (Set.{u1} ι) (SemilatticeInf.toPartialOrder.{u1} (Set.{u1} ι) (Lattice.toSemilatticeInf.{u1} (Set.{u1} ι) (GeneralizedCoheytingAlgebra.toLattice.{u1} (Set.{u1} ι) (CoheytingAlgebra.toGeneralizedCoheytingAlgebra.{u1} (Set.{u1} ι) (BiheytingAlgebra.toCoheytingAlgebra.{u1} (Set.{u1} ι) (BooleanAlgebra.toBiheytingAlgebra.{u1} (Set.{u1} ι) (Set.instBooleanAlgebraSet.{u1} ι))))))))) (BooleanAlgebra.toBoundedOrder.{u1} (Set.{u1} ι) (Set.instBooleanAlgebraSet.{u1} ι)))) (fun (a : α) => Set.preimage.{u1, u2} ι α f (Singleton.singleton.{u2, u2} α (Set.{u2} α) (Set.instSingletonSet.{u2} α) a))) Case conversion may be inaccurate. Consider using '#align pairwise_disjoint_fiber pairwise_disjoint_fiberₓ'. -/ theorem pairwise_disjoint_fiber (f : ι → α) : Pairwise (Disjoint on fun a : α => f ⁻¹' {a}) := Set.pairwise_univ.1 <| Set.pairwiseDisjoint_fiber f univ #align pairwise_disjoint_fiber pairwise_disjoint_fiber
module not_tester end module
###################################### # Example of kpik function # Based on example_kpik.m on V. Simoncini's Website ###################################### workspace() include("../src/LargeMatrixEquations.jl") using LargeMatrixEquations nh = 20 n = nh^2 T = diagm(ones(nh)*2)-diagm(ones(nh-1),-1)-diagm(ones(nh-1),1) I = eye(nh,nh) A = sparse(-(kron(T,I)+kron(I,T))) srand(1234) B = randn(n,2) E = eye(n)#sparse(diagm(rand(n),0)) m=100 tol=1e-9 tolY=1e-12 Z,er2=kpik(A,B,tolY=tolY) println(norm(A*Z*Z'*E+E*Z*Z'*A'+B*B'))
/- Copyright (c) 2021 Floris van Doorn. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Floris van Doorn ! This file was ported from Lean 3 source module algebra.order.sub.defs ! leanprover-community/mathlib commit 70d50ecfd4900dd6d328da39ab7ebd516abe4025 ! Please do not edit these lines, except to modify the commit id ! if you have ported upstream changes. -/ import Mathlib.Algebra.CovariantAndContravariant import Mathlib.Algebra.Group.Basic import Mathlib.Algebra.Order.Monoid.Lemmas import Mathlib.Order.Lattice /-! # Ordered Subtraction This file proves lemmas relating (truncated) subtraction with an order. We provide a class `OrderedSub` stating that `a - b ≤ c ↔ a ≤ c + b`. The subtraction discussed here could both be normal subtraction in an additive group or truncated subtraction on a canonically ordered monoid (`ℕ`, `Multiset`, `PartENat`, `ENNReal`, ...) ## Implementation details `OrderedSub` is a mixin type-class, so that we can use the results in this file even in cases where we don't have a `CanonicallyOrderedAddMonoid` instance (even though that is our main focus). Conversely, this means we can use `CanonicallyOrderedAddMonoid` without necessarily having to define a subtraction. The results in this file are ordered by the type-class assumption needed to prove it. This means that similar results might not be close to each other. Furthermore, we don't prove implications if a bi-implication can be proven under the same assumptions. Lemmas using this class are named using `tsub` instead of `sub` (short for "truncated subtraction"). This is to avoid naming conflicts with similar lemmas about ordered groups. We provide a second version of most results that require `[ContravariantClass α α (+) (≤)]`. In the second version we replace this type-class assumption by explicit `AddLECancellable` assumptions. TODO: maybe we should make a multiplicative version of this, so that we can replace some identical lemmas about subtraction/division in `Ordered[Add]CommGroup` with these. TODO: generalize `Nat.le_of_le_of_sub_le_sub_right`, `Nat.sub_le_sub_right_iff`, `Nat.mul_self_sub_mul_self_eq` -/ variable {α β : Type _} /-- `OrderedSub α` means that `α` has a subtraction characterized by `a - b ≤ c ↔ a ≤ c + b`. In other words, `a - b` is the least `c` such that `a ≤ b + c`. This is satisfied both by the subtraction in additive ordered groups and by truncated subtraction in canonically ordered monoids on many specific types. -/ class OrderedSub (α : Type _) [LE α] [Add α] [Sub α] where /-- `a - b` provides a lower bound on `c` such that `a ≤ c + b`. -/ tsub_le_iff_right : ∀ a b c : α, a - b ≤ c ↔ a ≤ c + b #align has_ordered_sub OrderedSub section Add variable [Preorder α] [Add α] [Sub α] [OrderedSub α] {a b c d : α} @[simp] theorem tsub_le_iff_right : a - b ≤ c ↔ a ≤ c + b := OrderedSub.tsub_le_iff_right a b c #align tsub_le_iff_right tsub_le_iff_right /-- See `add_tsub_cancel_right` for the equality if `ContravariantClass α α (+) (≤)`. -/ theorem add_tsub_le_right : a + b - b ≤ a := tsub_le_iff_right.mpr le_rfl #align add_tsub_le_right add_tsub_le_right theorem le_tsub_add : b ≤ b - a + a := tsub_le_iff_right.mp le_rfl #align le_tsub_add le_tsub_add end Add /-! ### Preorder -/ section OrderedAddCommSemigroup section Preorder variable [Preorder α] section AddCommSemigroup variable [AddCommSemigroup α] [Sub α] [OrderedSub α] {a b c d : α} theorem tsub_le_iff_left : a - b ≤ c ↔ a ≤ b + c := by rw [tsub_le_iff_right, add_comm] #align tsub_le_iff_left tsub_le_iff_left theorem le_add_tsub : a ≤ b + (a - b) := tsub_le_iff_left.mp le_rfl #align le_add_tsub le_add_tsub /-- See `add_tsub_cancel_left` for the equality if `ContravariantClass α α (+) (≤)`. -/ theorem add_tsub_le_left : a + b - a ≤ b := tsub_le_iff_left.mpr le_rfl #align add_tsub_le_left add_tsub_le_left theorem tsub_le_tsub_right (h : a ≤ b) (c : α) : a - c ≤ b - c := tsub_le_iff_left.mpr <| h.trans le_add_tsub #align tsub_le_tsub_right tsub_le_tsub_right theorem tsub_le_iff_tsub_le : a - b ≤ c ↔ a - c ≤ b := by rw [tsub_le_iff_left, tsub_le_iff_right] #align tsub_le_iff_tsub_le tsub_le_iff_tsub_le /-- See `tsub_tsub_cancel_of_le` for the equality. -/ theorem tsub_tsub_le : b - (b - a) ≤ a := tsub_le_iff_right.mpr le_add_tsub #align tsub_tsub_le tsub_tsub_le section Cov variable [CovariantClass α α (· + ·) (· ≤ ·)] theorem tsub_le_tsub_left (h : a ≤ b) (c : α) : c - b ≤ c - a := tsub_le_iff_left.mpr <| le_add_tsub.trans <| add_le_add_right h _ #align tsub_le_tsub_left tsub_le_tsub_left theorem tsub_le_tsub (hab : a ≤ b) (hcd : c ≤ d) : a - d ≤ b - c := (tsub_le_tsub_right hab _).trans <| tsub_le_tsub_left hcd _ #align tsub_le_tsub tsub_le_tsub theorem antitone_const_tsub : Antitone fun x => c - x := fun _ _ hxy => tsub_le_tsub rfl.le hxy #align antitone_const_tsub antitone_const_tsub /-- See `add_tsub_assoc_of_le` for the equality. -/ theorem add_tsub_le_assoc : a + b - c ≤ a + (b - c) := by rw [tsub_le_iff_left, add_left_comm] exact add_le_add_left le_add_tsub a #align add_tsub_le_assoc add_tsub_le_assoc /-- See `tsub_add_eq_add_tsub` for the equality. -/ theorem add_tsub_le_tsub_add : a + b - c ≤ a - c + b := by rw [add_comm, add_comm _ b] exact add_tsub_le_assoc #align add_tsub_le_tsub_add add_tsub_le_tsub_add theorem add_le_add_add_tsub : a + b ≤ a + c + (b - c) := by rw [add_assoc] exact add_le_add_left le_add_tsub a #align add_le_add_add_tsub add_le_add_add_tsub theorem le_tsub_add_add : a + b ≤ a - c + (b + c) := by rw [add_comm a, add_comm (a - c)] exact add_le_add_add_tsub #align le_tsub_add_add le_tsub_add_add theorem tsub_le_tsub_add_tsub : a - c ≤ a - b + (b - c) := by rw [tsub_le_iff_left, ← add_assoc, add_right_comm] exact le_add_tsub.trans (add_le_add_right le_add_tsub _) #align tsub_le_tsub_add_tsub tsub_le_tsub_add_tsub theorem tsub_tsub_tsub_le_tsub : c - a - (c - b) ≤ b - a := by rw [tsub_le_iff_left, tsub_le_iff_left, add_left_comm] exact le_tsub_add.trans (add_le_add_left le_add_tsub _) #align tsub_tsub_tsub_le_tsub tsub_tsub_tsub_le_tsub theorem tsub_tsub_le_tsub_add {a b c : α} : a - (b - c) ≤ a - b + c := tsub_le_iff_right.2 <| calc a ≤ a - b + b := le_tsub_add _ ≤ a - b + (c + (b - c)) := add_le_add_left le_add_tsub _ _ = a - b + c + (b - c) := (add_assoc _ _ _).symm #align tsub_tsub_le_tsub_add tsub_tsub_le_tsub_add /-- See `tsub_add_tsub_comm` for the equality. -/ theorem add_tsub_add_le_tsub_add_tsub : a + b - (c + d) ≤ a - c + (b - d) := by rw [add_comm c, tsub_le_iff_left, add_assoc, ← tsub_le_iff_left, ← tsub_le_iff_left] refine' (tsub_le_tsub_right add_tsub_le_assoc c).trans _ rw [add_comm a, add_comm (a - c)] exact add_tsub_le_assoc #align add_tsub_add_le_tsub_add_tsub add_tsub_add_le_tsub_add_tsub /-- See `add_tsub_add_eq_tsub_left` for the equality. -/ theorem add_tsub_add_le_tsub_left : a + b - (a + c) ≤ b - c := by rw [tsub_le_iff_left, add_assoc] exact add_le_add_left le_add_tsub _ #align add_tsub_add_le_tsub_left add_tsub_add_le_tsub_left /-- See `add_tsub_add_eq_tsub_right` for the equality. -/ theorem add_tsub_add_le_tsub_right : a + c - (b + c) ≤ a - b := by rw [tsub_le_iff_left, add_right_comm] exact add_le_add_right le_add_tsub c #align add_tsub_add_le_tsub_right add_tsub_add_le_tsub_right end Cov /-! #### Lemmas that assume that an element is `AddLECancellable` -/ namespace AddLECancellable protected theorem le_add_tsub_swap (hb : AddLECancellable b) : a ≤ b + a - b := hb le_add_tsub #align add_le_cancellable.le_add_tsub_swap AddLECancellable.le_add_tsub_swap protected theorem le_add_tsub (hb : AddLECancellable b) : a ≤ a + b - b := by rw [add_comm] exact hb.le_add_tsub_swap #align add_le_cancellable.le_add_tsub AddLECancellable.le_add_tsub protected theorem le_tsub_of_add_le_left (ha : AddLECancellable a) (h : a + b ≤ c) : b ≤ c - a := ha <| h.trans le_add_tsub #align add_le_cancellable.le_tsub_of_add_le_left AddLECancellable.le_tsub_of_add_le_left protected theorem le_tsub_of_add_le_right (hb : AddLECancellable b) (h : a + b ≤ c) : a ≤ c - b := hb.le_tsub_of_add_le_left <| by rwa [add_comm] #align add_le_cancellable.le_tsub_of_add_le_right AddLECancellable.le_tsub_of_add_le_right end AddLECancellable /-! ### Lemmas where addition is order-reflecting -/ section Contra variable [ContravariantClass α α (· + ·) (· ≤ ·)] theorem le_add_tsub_swap : a ≤ b + a - b := Contravariant.AddLECancellable.le_add_tsub_swap #align le_add_tsub_swap le_add_tsub_swap theorem le_add_tsub' : a ≤ a + b - b := Contravariant.AddLECancellable.le_add_tsub #align le_add_tsub' le_add_tsub' theorem le_tsub_of_add_le_left (h : a + b ≤ c) : b ≤ c - a := Contravariant.AddLECancellable.le_tsub_of_add_le_left h #align le_tsub_of_add_le_left le_tsub_of_add_le_left theorem le_tsub_of_add_le_right (h : a + b ≤ c) : a ≤ c - b := Contravariant.AddLECancellable.le_tsub_of_add_le_right h #align le_tsub_of_add_le_right le_tsub_of_add_le_right end Contra end AddCommSemigroup variable [AddCommMonoid α] [Sub α] [OrderedSub α] {a b c d : α} theorem tsub_nonpos : a - b ≤ 0 ↔ a ≤ b := by rw [tsub_le_iff_left, add_zero] #align tsub_nonpos tsub_nonpos alias tsub_nonpos ↔ _ tsub_nonpos_of_le #align tsub_nonpos_of_le tsub_nonpos_of_le end Preorder /-! ### Partial order -/ variable [PartialOrder α] [AddCommSemigroup α] [Sub α] [OrderedSub α] {a b c d : α} theorem tsub_tsub (b a c : α) : b - a - c = b - (a + c) := by apply le_antisymm · rw [tsub_le_iff_left, tsub_le_iff_left, ← add_assoc, ← tsub_le_iff_left] · rw [tsub_le_iff_left, add_assoc, ← tsub_le_iff_left, ← tsub_le_iff_left] #align tsub_tsub tsub_tsub theorem tsub_add_eq_tsub_tsub (a b c : α) : a - (b + c) = a - b - c := (tsub_tsub _ _ _).symm #align tsub_add_eq_tsub_tsub tsub_add_eq_tsub_tsub theorem tsub_add_eq_tsub_tsub_swap (a b c : α) : a - (b + c) = a - c - b := by rw [add_comm] apply tsub_add_eq_tsub_tsub #align tsub_add_eq_tsub_tsub_swap tsub_add_eq_tsub_tsub_swap theorem tsub_right_comm : a - b - c = a - c - b := by rw [←tsub_add_eq_tsub_tsub, tsub_add_eq_tsub_tsub_swap] #align tsub_right_comm tsub_right_comm /-! ### Lemmas that assume that an element is `AddLECancellable`. -/ namespace AddLECancellable protected theorem tsub_eq_of_eq_add (hb : AddLECancellable b) (h : a = c + b) : a - b = c := le_antisymm (tsub_le_iff_right.mpr h.le) <| by rw [h] exact hb.le_add_tsub #align add_le_cancellable.tsub_eq_of_eq_add AddLECancellable.tsub_eq_of_eq_add protected theorem eq_tsub_of_add_eq (hc : AddLECancellable c) (h : a + c = b) : a = b - c := (hc.tsub_eq_of_eq_add h.symm).symm #align add_le_cancellable.eq_tsub_of_add_eq AddLECancellable.eq_tsub_of_add_eq protected theorem tsub_eq_of_eq_add_rev (hb : AddLECancellable b) (h : a = b + c) : a - b = c := hb.tsub_eq_of_eq_add <| by rw [add_comm, h] #align add_le_cancellable.tsub_eq_of_eq_add_rev AddLECancellable.tsub_eq_of_eq_add_rev @[simp] protected theorem add_tsub_cancel_right (hb : AddLECancellable b) : a + b - b = a := hb.tsub_eq_of_eq_add <| by rw [add_comm] #align add_le_cancellable.add_tsub_cancel_right AddLECancellable.add_tsub_cancel_right @[simp] protected theorem add_tsub_cancel_left (ha : AddLECancellable a) : a + b - a = b := ha.tsub_eq_of_eq_add <| add_comm a b #align add_le_cancellable.add_tsub_cancel_left AddLECancellable.add_tsub_cancel_left protected theorem lt_add_of_tsub_lt_left (hb : AddLECancellable b) (h : a - b < c) : a < b + c := by rw [lt_iff_le_and_ne, ← tsub_le_iff_left] refine' ⟨h.le, _⟩ rintro rfl simp [hb] at h #align add_le_cancellable.lt_add_of_tsub_lt_left AddLECancellable.lt_add_of_tsub_lt_left protected protected theorem lt_tsub_of_add_lt_right (hc : AddLECancellable c) (h : a + c < b) : a < b - c := (hc.le_tsub_of_add_le_right h.le).lt_of_ne <| by rintro rfl exact h.not_le le_tsub_add #align add_le_cancellable.lt_tsub_of_add_lt_right AddLECancellable.lt_tsub_of_add_lt_right protected theorem lt_tsub_of_add_lt_left (ha : AddLECancellable a) (h : a + c < b) : c < b - a := ha.lt_tsub_of_add_lt_right <| by rwa [add_comm] #align add_le_cancellable.lt_tsub_of_add_lt_left AddLECancellable.lt_tsub_of_add_lt_left end AddLECancellable /-! #### Lemmas where addition is order-reflecting. -/ section Contra variable [ContravariantClass α α (· + ·) (· ≤ ·)] theorem tsub_eq_of_eq_add (h : a = c + b) : a - b = c := Contravariant.AddLECancellable.tsub_eq_of_eq_add h #align tsub_eq_of_eq_add tsub_eq_of_eq_add theorem eq_tsub_of_add_eq (h : a + c = b) : a = b - c := Contravariant.AddLECancellable.eq_tsub_of_add_eq h #align eq_tsub_of_add_eq eq_tsub_of_add_eq theorem tsub_eq_of_eq_add_rev (h : a = b + c) : a - b = c := Contravariant.AddLECancellable.tsub_eq_of_eq_add_rev h #align tsub_eq_of_eq_add_rev tsub_eq_of_eq_add_rev @[simp] theorem add_tsub_cancel_right (a b : α) : a + b - b = a := Contravariant.AddLECancellable.add_tsub_cancel_right #align add_tsub_cancel_right add_tsub_cancel_right @[simp] theorem add_tsub_cancel_left (a b : α) : a + b - a = b := Contravariant.AddLECancellable.add_tsub_cancel_left #align add_tsub_cancel_left add_tsub_cancel_left theorem lt_add_of_tsub_lt_left (h : a - b < c) : a < b + c := Contravariant.AddLECancellable.lt_add_of_tsub_lt_left h #align lt_add_of_tsub_lt_left lt_add_of_tsub_lt_left theorem lt_add_of_tsub_lt_right (h : a - c < b) : a < b + c := Contravariant.AddLECancellable.lt_add_of_tsub_lt_right h #align lt_add_of_tsub_lt_right lt_add_of_tsub_lt_right /-- This lemma (and some of its corollaries) also holds for `ENNReal`, but this proof doesn't work for it. Maybe we should add this lemma as field to `OrderedSub`? -/ theorem lt_tsub_of_add_lt_left : a + c < b → c < b - a := Contravariant.AddLECancellable.lt_tsub_of_add_lt_left #align lt_tsub_of_add_lt_left lt_tsub_of_add_lt_left theorem lt_tsub_of_add_lt_right : a + c < b → a < b - c := Contravariant.AddLECancellable.lt_tsub_of_add_lt_right #align lt_tsub_of_add_lt_right lt_tsub_of_add_lt_right end Contra section Both variable [CovariantClass α α (· + ·) (· ≤ ·)] [ContravariantClass α α (· + ·) (· ≤ ·)] theorem add_tsub_add_eq_tsub_right (a c b : α) : a + c - (b + c) = a - b := by refine' add_tsub_add_le_tsub_right.antisymm (tsub_le_iff_right.2 <| le_of_add_le_add_right _) exact c rw [add_assoc] exact le_tsub_add #align add_tsub_add_eq_tsub_right add_tsub_add_eq_tsub_right theorem add_tsub_add_eq_tsub_left (a b c : α) : a + b - (a + c) = b - c := by rw [add_comm a b, add_comm a c, add_tsub_add_eq_tsub_right] #align add_tsub_add_eq_tsub_left add_tsub_add_eq_tsub_left end Both end OrderedAddCommSemigroup /-! ### Lemmas in a linearly ordered monoid. -/ section LinearOrder variable {a b c d : α} [LinearOrder α] [AddCommSemigroup α] [Sub α] [OrderedSub α] /-- See `lt_of_tsub_lt_tsub_right_of_le` for a weaker statement in a partial order. -/ theorem lt_of_tsub_lt_tsub_right (h : a - c < b - c) : a < b := lt_imp_lt_of_le_imp_le (fun h => tsub_le_tsub_right h c) h #align lt_of_tsub_lt_tsub_right lt_of_tsub_lt_tsub_right /-- See `lt_tsub_iff_right_of_le` for a weaker statement in a partial order. -/ theorem lt_tsub_iff_right : a < b - c ↔ a + c < b := lt_iff_lt_of_le_iff_le tsub_le_iff_right #align lt_tsub_iff_right lt_tsub_iff_right /-- See `lt_tsub_iff_left_of_le` for a weaker statement in a partial order. -/ theorem lt_tsub_iff_left : a < b - c ↔ c + a < b := lt_iff_lt_of_le_iff_le tsub_le_iff_left #align lt_tsub_iff_left lt_tsub_iff_left theorem lt_tsub_comm : a < b - c ↔ c < b - a := lt_tsub_iff_left.trans lt_tsub_iff_right.symm #align lt_tsub_comm lt_tsub_comm section Cov variable [CovariantClass α α (· + ·) (· ≤ ·)] /-- See `lt_of_tsub_lt_tsub_left_of_le` for a weaker statement in a partial order. -/ theorem lt_of_tsub_lt_tsub_left (h : a - b < a - c) : c < b := lt_imp_lt_of_le_imp_le (fun h => tsub_le_tsub_left h a) h #align lt_of_tsub_lt_tsub_left lt_of_tsub_lt_tsub_left end Cov end LinearOrder section OrderedAddCommMonoid variable [PartialOrder α] [AddCommMonoid α] [Sub α] [OrderedSub α] @[simp] theorem tsub_zero (a : α) : a - 0 = a := AddLECancellable.tsub_eq_of_eq_add addLECancellable_zero (add_zero _).symm #align tsub_zero tsub_zero end OrderedAddCommMonoid
Many proteins ( in <unk> ~ 33 % ) contain large unstructured but biologically functional segments and can be classified as intrinsically disordered proteins . Predicting and analysing protein disorder is , therefore , an important part of protein structure characterisation .
! ################################################################################################################################## ! Begin MIT license text. ! _______________________________________________________________________________________________________ ! Copyright 2019 Dr William R Case, Jr ([email protected]) ! Permission is hereby granted, free of charge, to any person obtaining a copy of this software and ! associated documentation files (the "Software"), to deal in the Software without restriction, including ! without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell ! copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to ! the following conditions: ! The above copyright notice and this permission notice shall be included in all copies or substantial ! portions of the Software and documentation. ! THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS ! OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, ! FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE ! AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER ! LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, ! OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN ! THE SOFTWARE. ! _______________________________________________________________________________________________________ ! End MIT license text. SUBROUTINE QPLT1 ( OPT, AREA, XSD, YSD ) ! DKQ quadrilateral thin (Kirchoff) plate bending element. This element is based on the following work: ! "Evaluation Of A New Quadrilateral Thin Plate Bending Element", by Jean_louis Batoz and Marbrouk Ben Tahar, ! International Journal For Numerical Methods In Engineering, Vol 18 (1982) pp 1655-1677 ! Element matrices calculated are: ! 1) PTE = element thermal load vectors , if OPT(2) = 'Y' ! 2) SEi, STEi = element stress data recovery matrices, if OPT(3) = 'Y' ! 3) KE = element linea stiffness matrix , if OPT(4) = 'Y' ! 4) PPE = element pressure load matrix , if OPT(5) = 'Y' ! 5) KED = element differen stiff matrix calc , if OPT(6) = 'Y' = 'Y' USE PENTIUM_II_KIND, ONLY : BYTE, LONG, DOUBLE USE IOUNT1, ONLY : F04, WRT_LOG USE SCONTR, ONLY : BLNK_SUB_NAM, MAX_ORDER_GAUSS, NSUB, NTSUB USE TIMDAT, ONLY : TSEC USE SUBR_BEGEND_LEVELS, ONLY : QPLT1_BEGEND USE CONSTANTS_1, ONLY : ZERO, FOUR USE PARAMS, ONLY : IORQ2B USE MODEL_STUF, ONLY : ALPVEC, BE2, DT, EB, EID, KE, PRESS, PPE, PTE, SE2, STE2, SHELL_D, SHELL_DALP USE QPLT1_USE_IFs IMPLICIT NONE CHARACTER(LEN=LEN(BLNK_SUB_NAM)):: SUBR_NAME = 'QPLT1' CHARACTER(46*BYTE) :: IORD_MSG ! Character name of the integration order (used for debug output) CHARACTER(1*BYTE), INTENT(IN) :: OPT(6) ! 'Y'/'N' flags for whether to calc certain elem matrices INTEGER(LONG) :: GAUSS_PT ! Gauss point number (used for DEBUG output in subr SHP2DQ INTEGER(LONG) :: I,J,K,L,M ! DO loop indices INTEGER(LONG), PARAMETER :: ID(12) = (/ 3, & ! ID(1) = 3 means virgin 12x12 elem DOF 1 is MYSTRAN 24X24 elem DOF 3 4, & ! ID(2) = 4 means virgin 12x12 elem DOF 2 is MYSTRAN 24X24 elem DOF 4 5, & ! ID(2) = 5 means virgin 12x12 elem DOF 3 is MYSTRAN 24X24 elem DOF 5 9, & ! ID(3) = 9 means virgin 12x12 elem DOF 4 is MYSTRAN 24X24 elem DOF 9 10, & ! ID(4) = 10 means virgin 12x12 elem DOF 5 is MYSTRAN 24X24 elem DOF 10 11, & ! ID(4) = 11 means virgin 12x12 elem DOF 6 is MYSTRAN 24X24 elem DOF 11 15, & ! ID(5) = 15 means virgin 12x12 elem DOF 7 is MYSTRAN 24X24 elem DOF 15 16, & ! ID(6) = 16 means virgin 12x12 elem DOF 8 is MYSTRAN 24X24 elem DOF 16 17, & ! ID(6) = 17 means virgin 12x12 elem DOF 9 is MYSTRAN 24X24 elem DOF 17 21, & ! ID(7) = 21 means virgin 12x12 elem DOF 10 is MYSTRAN 24X24 elem DOF 21 22, & ! ID(8) = 22 means virgin 12x12 elem DOF 11 is MYSTRAN 24X24 elem DOF 22 23 /) ! ID(8) = 23 means virgin 12x12 elem DOF 12 is MYSTRAN 24X24 elem DOF 23 ! - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - ! Do not change IORD_STRESS_Q4. The algorithm to find Gauss point coords in elem x,y space requires there to be the same number of ! shape functions and Gauss points as elem nodes. INTEGER(LONG), PARAMETER :: IORD_STRESS_Q4 = 2! Gauss integration order for stress/strain recovery matrices ! - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - INTEGER(LONG), PARAMETER :: NUM_NODES = 8 ! DKQ element has 8 nodes (4 are internal) ! Indicator of no output of elem data to BUG file INTEGER(LONG), PARAMETER :: SUBR_BEGEND = QPLT1_BEGEND REAL(DOUBLE) , INTENT(IN) :: AREA ! Element area REAL(DOUBLE) , INTENT(IN) :: XSD(4) ! Diffs in x coords of quad sides in local coords REAL(DOUBLE) , INTENT(IN) :: YSD(4) ! Diffs in y coords of quad sides in local coords REAL(DOUBLE) :: ALP(3) ! Col of ALPVEC REAL(DOUBLE) :: BB(3,12) ! Output from subr BBDKQ, called herein. Strain-displ matrix REAL(DOUBLE) :: DETJ ! An output from subr JAC2D, called herein. Determinant of JAC REAL(DOUBLE) :: DPSHG(2,8) ! Output from subr SHP2DQ. Derivatives of PSH wrt elem isopar coords. REAL(DOUBLE) :: DPSHX(2,8) ! Derivatives of PSH wrt elem x, y coords. REAL(DOUBLE) :: DUM1(3,12) ! Intermediate matrix used in solving for PTE therm lds & KE stiffness REAL(DOUBLE) :: DUM2(12,12) ! Intermediate matrix used in solving for KE element stiffness REAL(DOUBLE) :: DUM3(12) ! Intermediate matrix used in solving for PTE thermal loads REAL(DOUBLE) :: DUM4(12) ! Intermediate matrix used in solving for PTE thermal loads REAL(DOUBLE) :: EALP(3) ! Intermed var used in calc STEi therm stress coeffs REAL(DOUBLE) :: HHH(MAX_ORDER_GAUSS) ! An output from subr ORDER, called herein. Gauss weights. REAL(DOUBLE) :: INTFAC ! An integration factor (constant multiplier for the Gauss integration) REAL(DOUBLE) :: JAC(2,2) ! An output from subr JAC2D, called herein. 2 x 2 Jacobian matrix. REAL(DOUBLE) :: JACI(2,2) ! An output from subr JAC2D, called herein. 2 x 2 Jacobian inverse. REAL(DOUBLE) :: PSH(8) ! Output from subr SHP2DQ. Shape fcn for 8 node serendipity element. REAL(DOUBLE) :: SLN(4) ! Quad side lengths REAL(DOUBLE) :: SSI ! A particular value of SSS REAL(DOUBLE) :: SSJ ! A particular value of SSS REAL(DOUBLE) :: SSS(MAX_ORDER_GAUSS) ! An output from subr ORDER, called herein. Gauss abscissa's. ! ********************************************************************************************************************************** IF (WRT_LOG >= SUBR_BEGEND) THEN CALL OURTIM WRITE(F04,9001) SUBR_NAME,TSEC 9001 FORMAT(1X,A,' BEGN ',F10.3) ENDIF ! ********************************************************************************************************************************** ! Quad side lengths DO I=1,4 SLN(I) = DSQRT(XSD(I)*XSD(I) + YSD(I)*YSD(I)) ENDDO ! ********************************************************************************************************************************** ! Determine element thermal loads. IF (OPT(2) == 'Y') THEN CALL ORDER_GAUSS ( IORQ2B, SSS, HHH ) DO I=1,12 DUM3(I) = ZERO ENDDO GAUSS_PT = 0 IORD_MSG = 'for plate bending strains, IORQ2B = ' DO I=1,IORQ2B DO J=1,IORQ2B GAUSS_PT = GAUSS_PT + 1 SSI = SSS(I) SSJ = SSS(J) CALL SHP2DQ ( I, J, NUM_NODES, SUBR_NAME, IORD_MSG, IORQ2B, SSI, SSJ, 'N', PSH, DPSHG ) CALL JAC2D ( SSI, SSJ, XSD, YSD, 'N', JAC, JACI, DETJ ) CALL MATMULT_FFF ( JACI, DPSHG, 2, 2, 8, DPSHX ) CALL BBDKQ ( DPSHX, XSD, YSD, SLN, I, J, 'bending strains', 'N', BB ) CALL MATMULT_FFF_T ( BB, SHELL_DALP, 3, 12, 1, DUM4 ) INTFAC = DETJ*HHH(I)*HHH(J) DO K=1,12 DUM3(K) = DUM3(K) + INTFAC*DUM4(K) ENDDO ENDDO ENDDO DO J=1,NTSUB DO K=1,12 PTE(ID(K),J) = DUM3(K)*DT(5,J) ENDDO ENDDO ENDIF ! ********************************************************************************************************************************** ! Determine element pressure loads. IF (OPT(5) == 'Y') THEN DO J=1,NSUB PPE( 3,J) = AREA*PRESS(3,J)/FOUR PPE( 9,J) = AREA*PRESS(3,J)/FOUR PPE(15,J) = AREA*PRESS(3,J)/FOUR PPE(21,J) = AREA*PRESS(3,J)/FOUR ENDDO ENDIF ! ********************************************************************************************************************************** ! Calculate SE matrix (3 x 24) for stress data recovery. ! Note: stress recovery matrices only make sense for individual plies (or whole elem if only 1 "ply") IF (OPT(3) == 'Y') THEN ! Bending moment terms (calculated at center of element). Note that engineering forces (moments) are determined from ! the SE2 matrices using FCONV, which was set in calling routine and is negative. SSI = ZERO ! BE2 at element center SSJ = ZERO GAUSS_PT = 1 IORD_MSG = 'for plate bending strains, = ' CALL SHP2DQ ( 1, 1, NUM_NODES, SUBR_NAME, IORD_MSG, 1, SSI, SSJ, 'N', PSH, DPSHG ) CALL JAC2D ( SSI, SSJ, XSD, YSD, 'N', JAC, JACI, DETJ ) CALL MATMULT_FFF ( JACI, DPSHG, 2, 2, 8, DPSHX ) CALL BBDKQ ( DPSHX, XSD, YSD, SLN, 1, 1, 'bending strains', 'N', BB ) DO I=1,3 DO J=1,12 BE2(I,ID(J),1) = BB(I,J) ENDDO ENDDO ! SE2, STE2 generated in elem coords. Then, in LINK9 the stresses, calc'd in elem coords, will be transformed to ply coords CALL MATMULT_FFF ( EB, BB, 3, 3, 12, DUM1 ) ! SE2 at element center DO I=1,3 DO J=1,12 SE2(I,ID(J),1) = DUM1(I,J) ENDDO ENDDO ALP(1) = ALPVEC(1,1) ALP(2) = ALPVEC(2,1) ALP(3) = ALPVEC(3,1) CALL MATMULT_FFF ( EB, ALP, 3, 3, 1, EALP ) DO J=1,NTSUB DO I=1,3 STE2(I,J,1) = EALP(I)*DT(5,J) ENDDO ENDDO ! Generate BE2, SE2 at Gauss points CALL ORDER_GAUSS ( IORQ2B, SSS, HHH ) GAUSS_PT = 0 DO I=1,IORD_STRESS_Q4 DO J=1,IORD_STRESS_Q4 GAUSS_PT = GAUSS_PT + 1 IORD_MSG = 'for plate bending strains, IORD_STRESS_Q4 = ' CALL SHP2DQ ( I, J, NUM_NODES, SUBR_NAME, IORD_MSG, IORD_STRESS_Q4, SSS(I), SSS(J), 'N', PSH, DPSHG ) CALL JAC2D ( SSS(I), SSS(J), XSD, YSD, 'N', JAC, JACI, DETJ ) CALL MATMULT_FFF ( JACI, DPSHG, 2, 2, 8, DPSHX ) CALL BBDKQ ( DPSHX, XSD, YSD, SLN, I, J, 'bending strains', 'N', BB ) DO L=1,3 DO M=1,12 BE2(L,ID(M),GAUSS_PT+1) = BB(L,M) ENDDO ENDDO CALL MATMULT_FFF ( EB, BB, 3, 3, 12, DUM1 ) ! Generate SE2 in element coords (at this point EM is elem coords) DO L=1,3 DO M=1,12 SE2(L,ID(M),GAUSS_PT+1) = DUM1(L,M) ENDDO ENDDO ENDDO ENDDO ENDIF ! ********************************************************************************************************************************** ! Calculate element stiffness matrix KE. IF(OPT(4) == 'Y') THEN CALL ORDER_GAUSS ( IORQ2B, SSS, HHH ) GAUSS_PT = 0 IORD_MSG = 'for plate bending strains, IORQ2B = ' DO I=1,IORQ2B DO J=1,IORQ2B SSI = SSS(I) SSJ = SSS(J) GAUSS_PT = GAUSS_PT + 1 CALL SHP2DQ ( I, J, NUM_NODES, SUBR_NAME, IORD_MSG, IORQ2B, SSI, SSJ, 'Y', PSH, DPSHG ) CALL JAC2D ( SSI, SSJ, XSD, YSD, 'Y', JAC, JACI, DETJ ) CALL MATMULT_FFF ( JACI, DPSHG, 2, 2, 8, DPSHX ) CALL BBDKQ ( DPSHX, XSD, YSD, SLN, I, J, 'bending strains', 'Y', BB ) CALL MATMULT_FFF ( SHELL_D, BB, 3, 3, 12, DUM1 ) CALL MATMULT_FFF_T ( BB, DUM1, 3, 12, 12, DUM2 ) INTFAC = DETJ*HHH(I)*HHH(J) DO K=1,12 DO L=K,12 KE(ID(K),ID(L)) = KE(ID(K),ID(L)) + INTFAC*DUM2(K,L) ENDDO ENDDO ENDDO ENDDO ! Set lower triangular partition equal to upper partition DO I=2,24 DO J=1,I-1 KE(I,J) = KE(J,I) ENDDO ENDDO ENDIF ! ********************************************************************************************************************************** IF (WRT_LOG >= SUBR_BEGEND) THEN CALL OURTIM WRITE(F04,9002) SUBR_NAME,TSEC 9002 FORMAT(1X,A,' END ',F10.3) ENDIF RETURN ! ********************************************************************************************************************************** END SUBROUTINE QPLT1
require(httr) headers = c( `Content-Type` = 'application/x-www-form-urlencoded' ) data = '{"admins":{"names":[], "roles":[]}, "readers":{"names":["joe"],"roles":[]}}' res <- httr::PUT(url = 'http://localhost:5984/test/_security', httr::add_headers(.headers=headers), body = data, httr::authenticate('admin', '123'))
# A script to generate example runtests.jl for exercises, using default settings for # print_runtests from GeneratorUtils and adding in comments. Use this for testing and # development, but to generate a proper runtests.jl, always review the exercise's # canonical-data.json and adapt default_template.jl for that exercise, instead of using this # script which might not be maintained. # Usage: # julia [this file] [path to problem-specifications/] [output dir] # Example: # julia --project=generators generators/GeneratorUtils/examples/generate_defaults.jl ../problem-specifications/ generators/GeneratorUtils/examples/generated_defaults/ using GeneratorUtils using DataStructures: OrderedDict using JSON const problems_dir = ARGS[1] const out_dir = ARGS[2] function print_comments(io::IO, canonical_data::AbstractDict) haskey(canonical_data, "comments") || return nothing println(io, """ # The following lines are top-level comments in canonical-data.json; comments within cases # are not included. Do not include these comments in the exercise's runtests.jl. #""" ) delim = "" for line in canonical_data["comments"] print(io, delim, "# ", line) delim = "\n" end end function main() exercises_dir = joinpath(problems_dir, "exercises/") isdir(exercises_dir) || throw(ArgumentError(exercises_dir * " does not exist.")) mkpath(out_dir) @info "Printing runtests to $out_dir ..." count = 0 for slug in readdir(exercises_dir) print(stderr, "\e[2K\r$slug") # "\e[2K" is the ANSI control sequence to clear a line data_path = joinpath(exercises_dir, slug, "canonical-data.json") isfile(data_path) || continue open(data_path) do data_io canonical_data = tighten(JSON.parse(data_io; dicttype=OrderedDict)) if haskey(canonical_data, "comments") override!( canonical_data; subheader=sprint(print_comments, canonical_data) ) end open(joinpath(out_dir, slug * "_runtests.jl"), "w") do out_io print_runtests(out_io, canonical_data) end end count += 1 end print(stderr, "\e[2K\r") @info "Done. $count runtests printed." end main()
example (foo bar : Option Nat) : False := by have : do { let x ← bar; foo } = bar >>= fun x => foo := rfl admit done
The United States troops at the outposts of the western frontier of the state and in the Indian nation have all been recalled from winter quarters to reinforce the garrison at Fort Smith . The garrison at Fort Smith had been previously transferred to the United States Arsenal in this city ( Little Rock ) . The arsenal is one of the richest depositories of military stores in the United States and is supposed to be the ultimate destination of the <unk> [ sic ] ordered from the frontier .
# Built-in Combinations([1, 2, 3]); # [ [ ], [ 1 ], [ 1, 2 ], [ 1, 2, 3 ], [ 1, 3 ], [ 2 ], [ 2, 3 ], [ 3 ] ] # Note that it handles duplicates Combinations([1, 2, 3, 1]); # [ [ ], [ 1 ], [ 1, 1 ], [ 1, 1, 2 ], [ 1, 1, 2, 3 ], [ 1, 1, 3 ], [ 1, 2 ], [ 1, 2, 3 ], [ 1, 3 ], # [ 2 ], [ 2, 3 ], [ 3 ] ]
import data.fintype -- for finset and finset.sum import data.real.basic universe u variables {R : Type u} [add_comm_monoid R] -- my_sum_to_n eats a summand f(n) and returns the function sending t to f(0)+f(1)+...+f(t-1). -- Chris says use finsets. definition sum_to_n_minus_one (summand : ℕ → R) : ℕ → R := λ n, (finset.range n).sum summand --#reduce sum_to_n_minus_one (λ n, n ^ 2) 1000000 #check finset.range 4 -- finset ℕ #check @finset.sum definition sum_from_a_to_b_minus_one (summand : ℕ → R) (a b : ℕ) : R := (finset.Ico a b).sum summand #eval sum_from_a_to_b_minus_one (id) 4 7 theorem finset.polygon {α : Type*} [decidable_eq α] (X : finset α) (summand : α → ℝ) : abs (X.sum summand) ≤ X.sum (λ a, abs (summand a)) := begin apply finset.induction_on X, { simp }, { intro a, intro s, intro hs, intro ih, sorry } end
/- Copyright (c) 2019 Lucas Allen. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Lucas Allen -/ import tactic.converter.interactive /-! # Tests for the `conv` tactic inside the interactive `conv` monad -/ example (a b c d : ℕ) (h₁ : b = c) (h₂ : a + c = a + d) : a + b = a + d := begin conv { --| a + b = a + d --Conv to the left hand side to_lhs, -- | a + b --Zoom into the left hand side. conv { -- | a + b congr, -- two goals: | a and | b skip, -- | b rw h₁, -- | c }, -- | a + c --At this point, to get back to this position, without zoom, we would need to close --this conv block, and open a new one. rw h₂, -- | a + d }, -- goals accomplished end example : 1 + (5 * 8) - (3 * 14) + (4 * 99 - 45) - 350 = 1 := begin have h₁ : 5 * 8 = 40, from dec_trivial, have h₂ : 3 * 14 = 42, from dec_trivial, have h₃ : 4 * 99 - 45 = 351, from dec_trivial, conv { to_lhs, -- conv to the left hand side conv { -- zooming in to rewrite 4 * 99 - 45 to 351 congr, congr, skip, rw h₃, }, -- returning to the left hand side, note we don't need to open a new conv block conv { -- zooming in to rewrite 3 * 14 to 42 congr, congr, congr, skip, rw h₂, }, -- returning to the left hand side conv { -- zooming in to rewrite 5 * 8 to 40 congr, congr, congr, congr, skip, rw h₁, }, -- returning to the left hand side }, end
[GOAL] G : Type u_1 inst✝¹ : Group G H : Subgroup G inst✝ : Normal H a b : G ha : a ∈ {x | ∀ (y : G), x * y * x⁻¹ * y⁻¹ ∈ H} hb : b ∈ {x | ∀ (y : G), x * y * x⁻¹ * y⁻¹ ∈ H} y : G ⊢ a * b * y * (a * b)⁻¹ * y⁻¹ ∈ H [PROOFSTEP] convert Subgroup.mul_mem _ (ha (b * y * b⁻¹)) (hb y) using 1 [GOAL] case h.e'_4 G : Type u_1 inst✝¹ : Group G H : Subgroup G inst✝ : Normal H a b : G ha : a ∈ {x | ∀ (y : G), x * y * x⁻¹ * y⁻¹ ∈ H} hb : b ∈ {x | ∀ (y : G), x * y * x⁻¹ * y⁻¹ ∈ H} y : G ⊢ a * b * y * (a * b)⁻¹ * y⁻¹ = a * (b * y * b⁻¹) * a⁻¹ * (b * y * b⁻¹)⁻¹ * (b * y * b⁻¹ * y⁻¹) [PROOFSTEP] group [GOAL] G : Type u_1 inst✝¹ : Group G H : Subgroup G inst✝ : Normal H y : G ⊢ 1 * y * 1⁻¹ * y⁻¹ ∈ H [PROOFSTEP] simp [Subgroup.one_mem] [GOAL] G : Type u_1 inst✝¹ : Group G H : Subgroup G inst✝ : Normal H x : G hx : x ∈ { toSubsemigroup := { carrier := {x | ∀ (y : G), x * y * x⁻¹ * y⁻¹ ∈ H}, mul_mem' := (_ : ∀ {a b : G} {ha : a ∈ {x | ∀ (y : G), x * y * x⁻¹ * y⁻¹ ∈ H}} {hb : b ∈ {x | ∀ (y : G), x * y * x⁻¹ * y⁻¹ ∈ H}} {y : G}, a * b * y * (a * b)⁻¹ * y⁻¹ ∈ H) }, one_mem' := (_ : ∀ (y : G), 1 * y * 1⁻¹ * y⁻¹ ∈ H) }.toSubsemigroup.carrier y : G ⊢ x⁻¹ * y * x⁻¹⁻¹ * y⁻¹ ∈ H [PROOFSTEP] specialize hx y⁻¹ [GOAL] G : Type u_1 inst✝¹ : Group G H : Subgroup G inst✝ : Normal H x y : G hx : x * y⁻¹ * x⁻¹ * y⁻¹⁻¹ ∈ H ⊢ x⁻¹ * y * x⁻¹⁻¹ * y⁻¹ ∈ H [PROOFSTEP] rw [mul_assoc, inv_inv] at hx ⊢ [GOAL] G : Type u_1 inst✝¹ : Group G H : Subgroup G inst✝ : Normal H x y : G hx : x * y⁻¹ * (x⁻¹ * y) ∈ H ⊢ x⁻¹ * y * (x * y⁻¹) ∈ H [PROOFSTEP] exact Subgroup.Normal.mem_comm inferInstance hx [GOAL] G : Type u_1 inst✝¹ : Group G H : Subgroup G inst✝ : Normal H ⊢ upperCentralSeriesStep H = comap (mk' H) (center (G ⧸ H)) [PROOFSTEP] ext [GOAL] case h G : Type u_1 inst✝¹ : Group G H : Subgroup G inst✝ : Normal H x✝ : G ⊢ x✝ ∈ upperCentralSeriesStep H ↔ x✝ ∈ comap (mk' H) (center (G ⧸ H)) [PROOFSTEP] rw [mem_comap, mem_center_iff, forall_mk] [GOAL] case h G : Type u_1 inst✝¹ : Group G H : Subgroup G inst✝ : Normal H x✝ : G ⊢ x✝ ∈ upperCentralSeriesStep H ↔ ∀ (x : G), ↑x * ↑(mk' H) x✝ = ↑(mk' H) x✝ * ↑x [PROOFSTEP] apply forall_congr' [GOAL] case h.h G : Type u_1 inst✝¹ : Group G H : Subgroup G inst✝ : Normal H x✝ : G ⊢ ∀ (a : G), x✝ * a * x✝⁻¹ * a⁻¹ ∈ H ↔ ↑a * ↑(mk' H) x✝ = ↑(mk' H) x✝ * ↑a [PROOFSTEP] intro y [GOAL] case h.h G : Type u_1 inst✝¹ : Group G H : Subgroup G inst✝ : Normal H x✝ y : G ⊢ x✝ * y * x✝⁻¹ * y⁻¹ ∈ H ↔ ↑y * ↑(mk' H) x✝ = ↑(mk' H) x✝ * ↑y [PROOFSTEP] rw [coe_mk', ← QuotientGroup.mk_mul, ← QuotientGroup.mk_mul, eq_comm, eq_iff_div_mem, div_eq_mul_inv, mul_inv_rev, mul_assoc] [GOAL] G : Type u_1 inst✝¹ : Group G H : Subgroup G inst✝ : Normal H ⊢ Normal (upperCentralSeriesStep H) [PROOFSTEP] rw [upperCentralSeriesStep_eq_comap_center] [GOAL] G : Type u_1 inst✝¹ : Group G H : Subgroup G inst✝ : Normal H ⊢ Normal (comap (mk' H) (center (G ⧸ H))) [PROOFSTEP] infer_instance [GOAL] G : Type u_1 inst✝¹ : Group G H : Subgroup G inst✝ : Normal H ⊢ upperCentralSeries G 1 = center G [PROOFSTEP] ext [GOAL] case h G : Type u_1 inst✝¹ : Group G H : Subgroup G inst✝ : Normal H x✝ : G ⊢ x✝ ∈ upperCentralSeries G 1 ↔ x✝ ∈ center G [PROOFSTEP] simp only [upperCentralSeries, upperCentralSeriesAux, upperCentralSeriesStep, center, Set.center, mem_mk, mem_bot, Set.mem_setOf_eq] [GOAL] case h G : Type u_1 inst✝¹ : Group G H : Subgroup G inst✝ : Normal H x✝ : G ⊢ (∀ (y : G), x✝ * y * x✝⁻¹ * y⁻¹ = 1) ↔ ∀ (m : G), m * x✝ = x✝ * m [PROOFSTEP] exact forall_congr' fun y => by rw [mul_inv_eq_one, mul_inv_eq_iff_eq_mul, eq_comm] [GOAL] G : Type u_1 inst✝¹ : Group G H : Subgroup G inst✝ : Normal H x✝ y : G ⊢ x✝ * y * x✝⁻¹ * y⁻¹ = 1 ↔ y * x✝ = x✝ * y [PROOFSTEP] rw [mul_inv_eq_one, mul_inv_eq_iff_eq_mul, eq_comm] [GOAL] G : Type u_1 inst✝¹ : Group G H✝ : Subgroup G inst✝ : Normal H✝ H : ℕ → Subgroup G hH : IsAscendingCentralSeries H n : ℕ ⊢ H (n + 1) ≤ upperCentralSeries G (n + 1) [PROOFSTEP] intro x hx [GOAL] G : Type u_1 inst✝¹ : Group G H✝ : Subgroup G inst✝ : Normal H✝ H : ℕ → Subgroup G hH : IsAscendingCentralSeries H n : ℕ x : G hx : x ∈ H (n + 1) ⊢ x ∈ upperCentralSeries G (n + 1) [PROOFSTEP] rw [mem_upperCentralSeries_succ_iff] [GOAL] G : Type u_1 inst✝¹ : Group G H✝ : Subgroup G inst✝ : Normal H✝ H : ℕ → Subgroup G hH : IsAscendingCentralSeries H n : ℕ x : G hx : x ∈ H (n + 1) ⊢ ∀ (y : G), x * y * x⁻¹ * y⁻¹ ∈ upperCentralSeries G n [PROOFSTEP] exact fun y => ascending_central_series_le_upper H hH n (hH.2 x n hx y) [GOAL] G : Type u_1 inst✝¹ : Group G H : Subgroup G inst✝ : Normal H ⊢ Monotone (upperCentralSeries G) [PROOFSTEP] refine' monotone_nat_of_le_succ _ [GOAL] G : Type u_1 inst✝¹ : Group G H : Subgroup G inst✝ : Normal H ⊢ ∀ (n : ℕ), upperCentralSeries G n ≤ upperCentralSeries G (n + 1) [PROOFSTEP] intro n x hx y [GOAL] G : Type u_1 inst✝¹ : Group G H : Subgroup G inst✝ : Normal H n : ℕ x : G hx : x ∈ upperCentralSeries G n y : G ⊢ x * y * x⁻¹ * y⁻¹ ∈ (upperCentralSeriesAux G (Nat.add n 0)).fst [PROOFSTEP] rw [mul_assoc, mul_assoc, ← mul_assoc y x⁻¹ y⁻¹] [GOAL] G : Type u_1 inst✝¹ : Group G H : Subgroup G inst✝ : Normal H n : ℕ x : G hx : x ∈ upperCentralSeries G n y : G ⊢ x * (y * x⁻¹ * y⁻¹) ∈ (upperCentralSeriesAux G (Nat.add n 0)).fst [PROOFSTEP] exact mul_mem hx (Normal.conj_mem (upperCentralSeries_normal G n) x⁻¹ (inv_mem hx) y) [GOAL] G : Type u_1 inst✝¹ : Group G H : Subgroup G inst✝ : Normal H ⊢ Group.IsNilpotent G ↔ ∃ n H, IsAscendingCentralSeries H ∧ H n = ⊤ [PROOFSTEP] constructor [GOAL] case mp G : Type u_1 inst✝¹ : Group G H : Subgroup G inst✝ : Normal H ⊢ Group.IsNilpotent G → ∃ n H, IsAscendingCentralSeries H ∧ H n = ⊤ [PROOFSTEP] rintro ⟨n, nH⟩ [GOAL] case mp.mk.intro G : Type u_1 inst✝¹ : Group G H : Subgroup G inst✝ : Normal H n : ℕ nH : upperCentralSeries G n = ⊤ ⊢ ∃ n H, IsAscendingCentralSeries H ∧ H n = ⊤ [PROOFSTEP] refine' ⟨_, _, upperCentralSeries_isAscendingCentralSeries G, nH⟩ [GOAL] case mpr G : Type u_1 inst✝¹ : Group G H : Subgroup G inst✝ : Normal H ⊢ (∃ n H, IsAscendingCentralSeries H ∧ H n = ⊤) → Group.IsNilpotent G [PROOFSTEP] rintro ⟨n, H, hH, hn⟩ [GOAL] case mpr.intro.intro.intro G : Type u_1 inst✝¹ : Group G H✝ : Subgroup G inst✝ : Normal H✝ n : ℕ H : ℕ → Subgroup G hH : IsAscendingCentralSeries H hn : H n = ⊤ ⊢ Group.IsNilpotent G [PROOFSTEP] use n [GOAL] case h G : Type u_1 inst✝¹ : Group G H✝ : Subgroup G inst✝ : Normal H✝ n : ℕ H : ℕ → Subgroup G hH : IsAscendingCentralSeries H hn : H n = ⊤ ⊢ upperCentralSeries G n = ⊤ [PROOFSTEP] rw [eq_top_iff, ← hn] [GOAL] case h G : Type u_1 inst✝¹ : Group G H✝ : Subgroup G inst✝ : Normal H✝ n : ℕ H : ℕ → Subgroup G hH : IsAscendingCentralSeries H hn : H n = ⊤ ⊢ H n ≤ upperCentralSeries G n [PROOFSTEP] exact ascending_central_series_le_upper H hH n [GOAL] G : Type u_1 inst✝¹ : Group G H✝ : Subgroup G inst✝ : Normal H✝ H : ℕ → Subgroup G n : ℕ hn : H n = ⊤ hasc : IsAscendingCentralSeries H ⊢ IsDescendingCentralSeries fun m => H (n - m) [PROOFSTEP] cases' hasc with h0 hH [GOAL] case intro G : Type u_1 inst✝¹ : Group G H✝ : Subgroup G inst✝ : Normal H✝ H : ℕ → Subgroup G n : ℕ hn : H n = ⊤ h0 : H 0 = ⊥ hH : ∀ (x : G) (n : ℕ), x ∈ H (n + 1) → ∀ (g : G), x * g * x⁻¹ * g⁻¹ ∈ H n ⊢ IsDescendingCentralSeries fun m => H (n - m) [PROOFSTEP] refine' ⟨hn, fun x m hx g => _⟩ [GOAL] case intro G : Type u_1 inst✝¹ : Group G H✝ : Subgroup G inst✝ : Normal H✝ H : ℕ → Subgroup G n : ℕ hn : H n = ⊤ h0 : H 0 = ⊥ hH : ∀ (x : G) (n : ℕ), x ∈ H (n + 1) → ∀ (g : G), x * g * x⁻¹ * g⁻¹ ∈ H n x : G m : ℕ hx : x ∈ (fun m => H (n - m)) m g : G ⊢ x * g * x⁻¹ * g⁻¹ ∈ (fun m => H (n - m)) (m + 1) [PROOFSTEP] dsimp at hx [GOAL] case intro G : Type u_1 inst✝¹ : Group G H✝ : Subgroup G inst✝ : Normal H✝ H : ℕ → Subgroup G n : ℕ hn : H n = ⊤ h0 : H 0 = ⊥ hH : ∀ (x : G) (n : ℕ), x ∈ H (n + 1) → ∀ (g : G), x * g * x⁻¹ * g⁻¹ ∈ H n x : G m : ℕ hx : x ∈ H (n - m) g : G ⊢ x * g * x⁻¹ * g⁻¹ ∈ (fun m => H (n - m)) (m + 1) [PROOFSTEP] by_cases hm : n ≤ m [GOAL] case pos G : Type u_1 inst✝¹ : Group G H✝ : Subgroup G inst✝ : Normal H✝ H : ℕ → Subgroup G n : ℕ hn : H n = ⊤ h0 : H 0 = ⊥ hH : ∀ (x : G) (n : ℕ), x ∈ H (n + 1) → ∀ (g : G), x * g * x⁻¹ * g⁻¹ ∈ H n x : G m : ℕ hx : x ∈ H (n - m) g : G hm : n ≤ m ⊢ x * g * x⁻¹ * g⁻¹ ∈ (fun m => H (n - m)) (m + 1) [PROOFSTEP] rw [tsub_eq_zero_of_le hm, h0, Subgroup.mem_bot] at hx [GOAL] case pos G : Type u_1 inst✝¹ : Group G H✝ : Subgroup G inst✝ : Normal H✝ H : ℕ → Subgroup G n : ℕ hn : H n = ⊤ h0 : H 0 = ⊥ hH : ∀ (x : G) (n : ℕ), x ∈ H (n + 1) → ∀ (g : G), x * g * x⁻¹ * g⁻¹ ∈ H n x : G m : ℕ hx : x = 1 g : G hm : n ≤ m ⊢ x * g * x⁻¹ * g⁻¹ ∈ (fun m => H (n - m)) (m + 1) [PROOFSTEP] subst hx [GOAL] case pos G : Type u_1 inst✝¹ : Group G H✝ : Subgroup G inst✝ : Normal H✝ H : ℕ → Subgroup G n : ℕ hn : H n = ⊤ h0 : H 0 = ⊥ hH : ∀ (x : G) (n : ℕ), x ∈ H (n + 1) → ∀ (g : G), x * g * x⁻¹ * g⁻¹ ∈ H n m : ℕ g : G hm : n ≤ m ⊢ 1 * g * 1⁻¹ * g⁻¹ ∈ (fun m => H (n - m)) (m + 1) [PROOFSTEP] rw [show (1 : G) * g * (1⁻¹ : G) * g⁻¹ = 1 by group] [GOAL] G : Type u_1 inst✝¹ : Group G H✝ : Subgroup G inst✝ : Normal H✝ H : ℕ → Subgroup G n : ℕ hn : H n = ⊤ h0 : H 0 = ⊥ hH : ∀ (x : G) (n : ℕ), x ∈ H (n + 1) → ∀ (g : G), x * g * x⁻¹ * g⁻¹ ∈ H n m : ℕ g : G hm : n ≤ m ⊢ 1 * g * 1⁻¹ * g⁻¹ = 1 [PROOFSTEP] group [GOAL] case pos G : Type u_1 inst✝¹ : Group G H✝ : Subgroup G inst✝ : Normal H✝ H : ℕ → Subgroup G n : ℕ hn : H n = ⊤ h0 : H 0 = ⊥ hH : ∀ (x : G) (n : ℕ), x ∈ H (n + 1) → ∀ (g : G), x * g * x⁻¹ * g⁻¹ ∈ H n m : ℕ g : G hm : n ≤ m ⊢ 1 ∈ (fun m => H (n - m)) (m + 1) [PROOFSTEP] exact Subgroup.one_mem _ [GOAL] case neg G : Type u_1 inst✝¹ : Group G H✝ : Subgroup G inst✝ : Normal H✝ H : ℕ → Subgroup G n : ℕ hn : H n = ⊤ h0 : H 0 = ⊥ hH : ∀ (x : G) (n : ℕ), x ∈ H (n + 1) → ∀ (g : G), x * g * x⁻¹ * g⁻¹ ∈ H n x : G m : ℕ hx : x ∈ H (n - m) g : G hm : ¬n ≤ m ⊢ x * g * x⁻¹ * g⁻¹ ∈ (fun m => H (n - m)) (m + 1) [PROOFSTEP] push_neg at hm [GOAL] case neg G : Type u_1 inst✝¹ : Group G H✝ : Subgroup G inst✝ : Normal H✝ H : ℕ → Subgroup G n : ℕ hn : H n = ⊤ h0 : H 0 = ⊥ hH : ∀ (x : G) (n : ℕ), x ∈ H (n + 1) → ∀ (g : G), x * g * x⁻¹ * g⁻¹ ∈ H n x : G m : ℕ hx : x ∈ H (n - m) g : G hm : m < n ⊢ x * g * x⁻¹ * g⁻¹ ∈ (fun m => H (n - m)) (m + 1) [PROOFSTEP] apply hH [GOAL] case neg.a G : Type u_1 inst✝¹ : Group G H✝ : Subgroup G inst✝ : Normal H✝ H : ℕ → Subgroup G n : ℕ hn : H n = ⊤ h0 : H 0 = ⊥ hH : ∀ (x : G) (n : ℕ), x ∈ H (n + 1) → ∀ (g : G), x * g * x⁻¹ * g⁻¹ ∈ H n x : G m : ℕ hx : x ∈ H (n - m) g : G hm : m < n ⊢ x ∈ H (n - (m + 1) + 1) [PROOFSTEP] convert hx using 1 [GOAL] case h.e'_5 G : Type u_1 inst✝¹ : Group G H✝ : Subgroup G inst✝ : Normal H✝ H : ℕ → Subgroup G n : ℕ hn : H n = ⊤ h0 : H 0 = ⊥ hH : ∀ (x : G) (n : ℕ), x ∈ H (n + 1) → ∀ (g : G), x * g * x⁻¹ * g⁻¹ ∈ H n x : G m : ℕ hx : x ∈ H (n - m) g : G hm : m < n ⊢ H (n - (m + 1) + 1) = H (n - m) [PROOFSTEP] rw [tsub_add_eq_add_tsub (Nat.succ_le_of_lt hm), Nat.succ_sub_succ] [GOAL] G : Type u_1 inst✝¹ : Group G H✝ : Subgroup G inst✝ : Normal H✝ H : ℕ → Subgroup G n : ℕ hn : H n = ⊥ hdesc : IsDescendingCentralSeries H ⊢ IsAscendingCentralSeries fun m => H (n - m) [PROOFSTEP] cases' hdesc with h0 hH [GOAL] case intro G : Type u_1 inst✝¹ : Group G H✝ : Subgroup G inst✝ : Normal H✝ H : ℕ → Subgroup G n : ℕ hn : H n = ⊥ h0 : H 0 = ⊤ hH : ∀ (x : G) (n : ℕ), x ∈ H n → ∀ (g : G), x * g * x⁻¹ * g⁻¹ ∈ H (n + 1) ⊢ IsAscendingCentralSeries fun m => H (n - m) [PROOFSTEP] refine' ⟨hn, fun x m hx g => _⟩ [GOAL] case intro G : Type u_1 inst✝¹ : Group G H✝ : Subgroup G inst✝ : Normal H✝ H : ℕ → Subgroup G n : ℕ hn : H n = ⊥ h0 : H 0 = ⊤ hH : ∀ (x : G) (n : ℕ), x ∈ H n → ∀ (g : G), x * g * x⁻¹ * g⁻¹ ∈ H (n + 1) x : G m : ℕ hx : x ∈ (fun m => H (n - m)) (m + 1) g : G ⊢ x * g * x⁻¹ * g⁻¹ ∈ (fun m => H (n - m)) m [PROOFSTEP] dsimp only at hx ⊢ [GOAL] case intro G : Type u_1 inst✝¹ : Group G H✝ : Subgroup G inst✝ : Normal H✝ H : ℕ → Subgroup G n : ℕ hn : H n = ⊥ h0 : H 0 = ⊤ hH : ∀ (x : G) (n : ℕ), x ∈ H n → ∀ (g : G), x * g * x⁻¹ * g⁻¹ ∈ H (n + 1) x : G m : ℕ hx : x ∈ H (n - (m + 1)) g : G ⊢ x * g * x⁻¹ * g⁻¹ ∈ H (n - m) [PROOFSTEP] by_cases hm : n ≤ m [GOAL] case pos G : Type u_1 inst✝¹ : Group G H✝ : Subgroup G inst✝ : Normal H✝ H : ℕ → Subgroup G n : ℕ hn : H n = ⊥ h0 : H 0 = ⊤ hH : ∀ (x : G) (n : ℕ), x ∈ H n → ∀ (g : G), x * g * x⁻¹ * g⁻¹ ∈ H (n + 1) x : G m : ℕ hx : x ∈ H (n - (m + 1)) g : G hm : n ≤ m ⊢ x * g * x⁻¹ * g⁻¹ ∈ H (n - m) [PROOFSTEP] have hnm : n - m = 0 := tsub_eq_zero_iff_le.mpr hm [GOAL] case pos G : Type u_1 inst✝¹ : Group G H✝ : Subgroup G inst✝ : Normal H✝ H : ℕ → Subgroup G n : ℕ hn : H n = ⊥ h0 : H 0 = ⊤ hH : ∀ (x : G) (n : ℕ), x ∈ H n → ∀ (g : G), x * g * x⁻¹ * g⁻¹ ∈ H (n + 1) x : G m : ℕ hx : x ∈ H (n - (m + 1)) g : G hm : n ≤ m hnm : n - m = 0 ⊢ x * g * x⁻¹ * g⁻¹ ∈ H (n - m) [PROOFSTEP] rw [hnm, h0] [GOAL] case pos G : Type u_1 inst✝¹ : Group G H✝ : Subgroup G inst✝ : Normal H✝ H : ℕ → Subgroup G n : ℕ hn : H n = ⊥ h0 : H 0 = ⊤ hH : ∀ (x : G) (n : ℕ), x ∈ H n → ∀ (g : G), x * g * x⁻¹ * g⁻¹ ∈ H (n + 1) x : G m : ℕ hx : x ∈ H (n - (m + 1)) g : G hm : n ≤ m hnm : n - m = 0 ⊢ x * g * x⁻¹ * g⁻¹ ∈ ⊤ [PROOFSTEP] exact mem_top _ [GOAL] case neg G : Type u_1 inst✝¹ : Group G H✝ : Subgroup G inst✝ : Normal H✝ H : ℕ → Subgroup G n : ℕ hn : H n = ⊥ h0 : H 0 = ⊤ hH : ∀ (x : G) (n : ℕ), x ∈ H n → ∀ (g : G), x * g * x⁻¹ * g⁻¹ ∈ H (n + 1) x : G m : ℕ hx : x ∈ H (n - (m + 1)) g : G hm : ¬n ≤ m ⊢ x * g * x⁻¹ * g⁻¹ ∈ H (n - m) [PROOFSTEP] push_neg at hm [GOAL] case neg G : Type u_1 inst✝¹ : Group G H✝ : Subgroup G inst✝ : Normal H✝ H : ℕ → Subgroup G n : ℕ hn : H n = ⊥ h0 : H 0 = ⊤ hH : ∀ (x : G) (n : ℕ), x ∈ H n → ∀ (g : G), x * g * x⁻¹ * g⁻¹ ∈ H (n + 1) x : G m : ℕ hx : x ∈ H (n - (m + 1)) g : G hm : m < n ⊢ x * g * x⁻¹ * g⁻¹ ∈ H (n - m) [PROOFSTEP] convert hH x _ hx g using 1 [GOAL] case h.e'_5 G : Type u_1 inst✝¹ : Group G H✝ : Subgroup G inst✝ : Normal H✝ H : ℕ → Subgroup G n : ℕ hn : H n = ⊥ h0 : H 0 = ⊤ hH : ∀ (x : G) (n : ℕ), x ∈ H n → ∀ (g : G), x * g * x⁻¹ * g⁻¹ ∈ H (n + 1) x : G m : ℕ hx : x ∈ H (n - (m + 1)) g : G hm : m < n ⊢ H (n - m) = H (n - (m + 1) + 1) [PROOFSTEP] rw [tsub_add_eq_add_tsub (Nat.succ_le_of_lt hm), Nat.succ_sub_succ] [GOAL] G : Type u_1 inst✝¹ : Group G H : Subgroup G inst✝ : Normal H ⊢ Group.IsNilpotent G ↔ ∃ n H, IsDescendingCentralSeries H ∧ H n = ⊥ [PROOFSTEP] rw [nilpotent_iff_finite_ascending_central_series] [GOAL] G : Type u_1 inst✝¹ : Group G H : Subgroup G inst✝ : Normal H ⊢ (∃ n H, IsAscendingCentralSeries H ∧ H n = ⊤) ↔ ∃ n H, IsDescendingCentralSeries H ∧ H n = ⊥ [PROOFSTEP] constructor [GOAL] case mp G : Type u_1 inst✝¹ : Group G H : Subgroup G inst✝ : Normal H ⊢ (∃ n H, IsAscendingCentralSeries H ∧ H n = ⊤) → ∃ n H, IsDescendingCentralSeries H ∧ H n = ⊥ [PROOFSTEP] rintro ⟨n, H, hH, hn⟩ [GOAL] case mp.intro.intro.intro G : Type u_1 inst✝¹ : Group G H✝ : Subgroup G inst✝ : Normal H✝ n : ℕ H : ℕ → Subgroup G hH : IsAscendingCentralSeries H hn : H n = ⊤ ⊢ ∃ n H, IsDescendingCentralSeries H ∧ H n = ⊥ [PROOFSTEP] refine ⟨n, fun m => H (n - m), is_decending_rev_series_of_is_ascending G hn hH, ?_⟩ [GOAL] case mp.intro.intro.intro G : Type u_1 inst✝¹ : Group G H✝ : Subgroup G inst✝ : Normal H✝ n : ℕ H : ℕ → Subgroup G hH : IsAscendingCentralSeries H hn : H n = ⊤ ⊢ (fun m => H (n - m)) n = ⊥ [PROOFSTEP] dsimp only [GOAL] case mp.intro.intro.intro G : Type u_1 inst✝¹ : Group G H✝ : Subgroup G inst✝ : Normal H✝ n : ℕ H : ℕ → Subgroup G hH : IsAscendingCentralSeries H hn : H n = ⊤ ⊢ H (n - n) = ⊥ [PROOFSTEP] rw [tsub_self] [GOAL] case mp.intro.intro.intro G : Type u_1 inst✝¹ : Group G H✝ : Subgroup G inst✝ : Normal H✝ n : ℕ H : ℕ → Subgroup G hH : IsAscendingCentralSeries H hn : H n = ⊤ ⊢ H 0 = ⊥ [PROOFSTEP] exact hH.1 [GOAL] case mpr G : Type u_1 inst✝¹ : Group G H : Subgroup G inst✝ : Normal H ⊢ (∃ n H, IsDescendingCentralSeries H ∧ H n = ⊥) → ∃ n H, IsAscendingCentralSeries H ∧ H n = ⊤ [PROOFSTEP] rintro ⟨n, H, hH, hn⟩ [GOAL] case mpr.intro.intro.intro G : Type u_1 inst✝¹ : Group G H✝ : Subgroup G inst✝ : Normal H✝ n : ℕ H : ℕ → Subgroup G hH : IsDescendingCentralSeries H hn : H n = ⊥ ⊢ ∃ n H, IsAscendingCentralSeries H ∧ H n = ⊤ [PROOFSTEP] refine ⟨n, fun m => H (n - m), is_ascending_rev_series_of_is_descending G hn hH, ?_⟩ [GOAL] case mpr.intro.intro.intro G : Type u_1 inst✝¹ : Group G H✝ : Subgroup G inst✝ : Normal H✝ n : ℕ H : ℕ → Subgroup G hH : IsDescendingCentralSeries H hn : H n = ⊥ ⊢ (fun m => H (n - m)) n = ⊤ [PROOFSTEP] dsimp only [GOAL] case mpr.intro.intro.intro G : Type u_1 inst✝¹ : Group G H✝ : Subgroup G inst✝ : Normal H✝ n : ℕ H : ℕ → Subgroup G hH : IsDescendingCentralSeries H hn : H n = ⊥ ⊢ H (n - n) = ⊤ [PROOFSTEP] rw [tsub_self] [GOAL] case mpr.intro.intro.intro G : Type u_1 inst✝¹ : Group G H✝ : Subgroup G inst✝ : Normal H✝ n : ℕ H : ℕ → Subgroup G hH : IsDescendingCentralSeries H hn : H n = ⊥ ⊢ H 0 = ⊤ [PROOFSTEP] exact hH.1 [GOAL] G : Type u_1 inst✝¹ : Group G H : Subgroup G inst✝ : Normal H n : ℕ ⊢ Normal (lowerCentralSeries G n) [PROOFSTEP] induction' n with d hd [GOAL] case zero G : Type u_1 inst✝¹ : Group G H : Subgroup G inst✝ : Normal H ⊢ Normal (lowerCentralSeries G Nat.zero) [PROOFSTEP] exact (⊤ : Subgroup G).normal_of_characteristic [GOAL] case succ G : Type u_1 inst✝¹ : Group G H : Subgroup G inst✝ : Normal H d : ℕ hd : Normal (lowerCentralSeries G d) ⊢ Normal (lowerCentralSeries G (Nat.succ d)) [PROOFSTEP] exact @Subgroup.commutator_normal _ _ (lowerCentralSeries G d) ⊤ hd _ [GOAL] G : Type u_1 inst✝¹ : Group G H : Subgroup G inst✝ : Normal H ⊢ Antitone (lowerCentralSeries G) [PROOFSTEP] refine' antitone_nat_of_succ_le fun n x hx => _ [GOAL] G : Type u_1 inst✝¹ : Group G H : Subgroup G inst✝ : Normal H n : ℕ x : G hx : x ∈ lowerCentralSeries G (n + 1) ⊢ x ∈ lowerCentralSeries G n [PROOFSTEP] simp only [mem_lowerCentralSeries_succ_iff, exists_prop, mem_top, exists_true_left, true_and_iff] at hx [GOAL] G : Type u_1 inst✝¹ : Group G H : Subgroup G inst✝ : Normal H n : ℕ x : G hx : x ∈ closure {x | ∃ p, p ∈ lowerCentralSeries G n ∧ ∃ q, p * q * p⁻¹ * q⁻¹ = x} ⊢ x ∈ lowerCentralSeries G n [PROOFSTEP] refine' closure_induction hx _ (Subgroup.one_mem _) (@Subgroup.mul_mem _ _ _) (@Subgroup.inv_mem _ _ _) [GOAL] G : Type u_1 inst✝¹ : Group G H : Subgroup G inst✝ : Normal H n : ℕ x : G hx : x ∈ closure {x | ∃ p, p ∈ lowerCentralSeries G n ∧ ∃ q, p * q * p⁻¹ * q⁻¹ = x} ⊢ ∀ (x : G), x ∈ {x | ∃ p, p ∈ lowerCentralSeries G n ∧ ∃ q, p * q * p⁻¹ * q⁻¹ = x} → x ∈ lowerCentralSeries G n [PROOFSTEP] rintro y ⟨z, hz, a, ha⟩ [GOAL] case intro.intro.intro G : Type u_1 inst✝¹ : Group G H : Subgroup G inst✝ : Normal H n : ℕ x : G hx : x ∈ closure {x | ∃ p, p ∈ lowerCentralSeries G n ∧ ∃ q, p * q * p⁻¹ * q⁻¹ = x} y z : G hz : z ∈ lowerCentralSeries G n a : G ha : z * a * z⁻¹ * a⁻¹ = y ⊢ y ∈ lowerCentralSeries G n [PROOFSTEP] rw [← ha, mul_assoc, mul_assoc, ← mul_assoc a z⁻¹ a⁻¹] [GOAL] case intro.intro.intro G : Type u_1 inst✝¹ : Group G H : Subgroup G inst✝ : Normal H n : ℕ x : G hx : x ∈ closure {x | ∃ p, p ∈ lowerCentralSeries G n ∧ ∃ q, p * q * p⁻¹ * q⁻¹ = x} y z : G hz : z ∈ lowerCentralSeries G n a : G ha : z * a * z⁻¹ * a⁻¹ = y ⊢ z * (a * z⁻¹ * a⁻¹) ∈ lowerCentralSeries G n [PROOFSTEP] exact mul_mem hz (Normal.conj_mem (lowerCentralSeries_normal n) z⁻¹ (inv_mem hz) a) [GOAL] G : Type u_1 inst✝¹ : Group G H : Subgroup G inst✝ : Normal H ⊢ IsDescendingCentralSeries (lowerCentralSeries G) [PROOFSTEP] constructor [GOAL] case left G : Type u_1 inst✝¹ : Group G H : Subgroup G inst✝ : Normal H ⊢ lowerCentralSeries G 0 = ⊤ case right G : Type u_1 inst✝¹ : Group G H : Subgroup G inst✝ : Normal H ⊢ ∀ (x : G) (n : ℕ), x ∈ lowerCentralSeries G n → ∀ (g : G), x * g * x⁻¹ * g⁻¹ ∈ lowerCentralSeries G (n + 1) [PROOFSTEP] rfl [GOAL] case right G : Type u_1 inst✝¹ : Group G H : Subgroup G inst✝ : Normal H ⊢ ∀ (x : G) (n : ℕ), x ∈ lowerCentralSeries G n → ∀ (g : G), x * g * x⁻¹ * g⁻¹ ∈ lowerCentralSeries G (n + 1) [PROOFSTEP] intro x n hxn g [GOAL] case right G : Type u_1 inst✝¹ : Group G H : Subgroup G inst✝ : Normal H x : G n : ℕ hxn : x ∈ lowerCentralSeries G n g : G ⊢ x * g * x⁻¹ * g⁻¹ ∈ lowerCentralSeries G (n + 1) [PROOFSTEP] exact commutator_mem_commutator hxn (mem_top g) [GOAL] G : Type u_1 inst✝¹ : Group G H : Subgroup G inst✝ : Normal H ⊢ Group.IsNilpotent G ↔ ∃ n, lowerCentralSeries G n = ⊥ [PROOFSTEP] rw [nilpotent_iff_finite_descending_central_series] [GOAL] G : Type u_1 inst✝¹ : Group G H : Subgroup G inst✝ : Normal H ⊢ (∃ n H, IsDescendingCentralSeries H ∧ H n = ⊥) ↔ ∃ n, lowerCentralSeries G n = ⊥ [PROOFSTEP] constructor [GOAL] case mp G : Type u_1 inst✝¹ : Group G H : Subgroup G inst✝ : Normal H ⊢ (∃ n H, IsDescendingCentralSeries H ∧ H n = ⊥) → ∃ n, lowerCentralSeries G n = ⊥ [PROOFSTEP] rintro ⟨n, H, ⟨h0, hs⟩, hn⟩ [GOAL] case mp.intro.intro.intro.intro G : Type u_1 inst✝¹ : Group G H✝ : Subgroup G inst✝ : Normal H✝ n : ℕ H : ℕ → Subgroup G hn : H n = ⊥ h0 : H 0 = ⊤ hs : ∀ (x : G) (n : ℕ), x ∈ H n → ∀ (g : G), x * g * x⁻¹ * g⁻¹ ∈ H (n + 1) ⊢ ∃ n, lowerCentralSeries G n = ⊥ [PROOFSTEP] use n [GOAL] case h G : Type u_1 inst✝¹ : Group G H✝ : Subgroup G inst✝ : Normal H✝ n : ℕ H : ℕ → Subgroup G hn : H n = ⊥ h0 : H 0 = ⊤ hs : ∀ (x : G) (n : ℕ), x ∈ H n → ∀ (g : G), x * g * x⁻¹ * g⁻¹ ∈ H (n + 1) ⊢ lowerCentralSeries G n = ⊥ [PROOFSTEP] rw [eq_bot_iff, ← hn] [GOAL] case h G : Type u_1 inst✝¹ : Group G H✝ : Subgroup G inst✝ : Normal H✝ n : ℕ H : ℕ → Subgroup G hn : H n = ⊥ h0 : H 0 = ⊤ hs : ∀ (x : G) (n : ℕ), x ∈ H n → ∀ (g : G), x * g * x⁻¹ * g⁻¹ ∈ H (n + 1) ⊢ lowerCentralSeries G n ≤ H n [PROOFSTEP] exact descending_central_series_ge_lower H ⟨h0, hs⟩ n [GOAL] case mpr G : Type u_1 inst✝¹ : Group G H : Subgroup G inst✝ : Normal H ⊢ (∃ n, lowerCentralSeries G n = ⊥) → ∃ n H, IsDescendingCentralSeries H ∧ H n = ⊥ [PROOFSTEP] rintro ⟨n, hn⟩ [GOAL] case mpr.intro G : Type u_1 inst✝¹ : Group G H : Subgroup G inst✝ : Normal H n : ℕ hn : lowerCentralSeries G n = ⊥ ⊢ ∃ n H, IsDescendingCentralSeries H ∧ H n = ⊥ [PROOFSTEP] exact ⟨n, lowerCentralSeries G, lowerCentralSeries_isDescendingCentralSeries, hn⟩ [GOAL] G : Type u_1 inst✝¹ : Group G H : Subgroup G inst✝ : Normal H hG : Group.IsNilpotent G n : ℕ ⊢ upperCentralSeries G n = ⊤ ↔ nilpotencyClass G ≤ n [PROOFSTEP] constructor [GOAL] case mp G : Type u_1 inst✝¹ : Group G H : Subgroup G inst✝ : Normal H hG : Group.IsNilpotent G n : ℕ ⊢ upperCentralSeries G n = ⊤ → nilpotencyClass G ≤ n [PROOFSTEP] intro h [GOAL] case mp G : Type u_1 inst✝¹ : Group G H : Subgroup G inst✝ : Normal H hG : Group.IsNilpotent G n : ℕ h : upperCentralSeries G n = ⊤ ⊢ nilpotencyClass G ≤ n [PROOFSTEP] exact Nat.find_le h [GOAL] case mpr G : Type u_1 inst✝¹ : Group G H : Subgroup G inst✝ : Normal H hG : Group.IsNilpotent G n : ℕ ⊢ nilpotencyClass G ≤ n → upperCentralSeries G n = ⊤ [PROOFSTEP] intro h [GOAL] case mpr G : Type u_1 inst✝¹ : Group G H : Subgroup G inst✝ : Normal H hG : Group.IsNilpotent G n : ℕ h : nilpotencyClass G ≤ n ⊢ upperCentralSeries G n = ⊤ [PROOFSTEP] apply eq_top_iff.mpr [GOAL] case mpr G : Type u_1 inst✝¹ : Group G H : Subgroup G inst✝ : Normal H hG : Group.IsNilpotent G n : ℕ h : nilpotencyClass G ≤ n ⊢ ⊤ ≤ upperCentralSeries G n [PROOFSTEP] rw [← upperCentralSeries_nilpotencyClass] [GOAL] case mpr G : Type u_1 inst✝¹ : Group G H : Subgroup G inst✝ : Normal H hG : Group.IsNilpotent G n : ℕ h : nilpotencyClass G ≤ n ⊢ upperCentralSeries G (nilpotencyClass G) ≤ upperCentralSeries G n [PROOFSTEP] exact upperCentralSeries_mono _ h [GOAL] G : Type u_1 inst✝¹ : Group G H : Subgroup G inst✝ : Normal H hG : Group.IsNilpotent G ⊢ Nat.find (_ : ∃ n H, IsAscendingCentralSeries H ∧ H n = ⊤) = nilpotencyClass G [PROOFSTEP] refine le_antisymm (Nat.find_mono ?_) (Nat.find_mono ?_) [GOAL] case refine_1 G : Type u_1 inst✝¹ : Group G H : Subgroup G inst✝ : Normal H hG : Group.IsNilpotent G ⊢ ∀ (n : ℕ), upperCentralSeries G n = ⊤ → ∃ H, IsAscendingCentralSeries H ∧ H n = ⊤ [PROOFSTEP] intro n hn [GOAL] case refine_1 G : Type u_1 inst✝¹ : Group G H : Subgroup G inst✝ : Normal H hG : Group.IsNilpotent G n : ℕ hn : upperCentralSeries G n = ⊤ ⊢ ∃ H, IsAscendingCentralSeries H ∧ H n = ⊤ [PROOFSTEP] exact ⟨upperCentralSeries G, upperCentralSeries_isAscendingCentralSeries G, hn⟩ [GOAL] case refine_2 G : Type u_1 inst✝¹ : Group G H : Subgroup G inst✝ : Normal H hG : Group.IsNilpotent G ⊢ ∀ (n : ℕ), (∃ H, IsAscendingCentralSeries H ∧ H n = ⊤) → upperCentralSeries G n = ⊤ [PROOFSTEP] rintro n ⟨H, ⟨hH, hn⟩⟩ [GOAL] case refine_2.intro.intro G : Type u_1 inst✝¹ : Group G H✝ : Subgroup G inst✝ : Normal H✝ hG : Group.IsNilpotent G n : ℕ H : ℕ → Subgroup G hH : IsAscendingCentralSeries H hn : H n = ⊤ ⊢ upperCentralSeries G n = ⊤ [PROOFSTEP] rw [← top_le_iff, ← hn] [GOAL] case refine_2.intro.intro G : Type u_1 inst✝¹ : Group G H✝ : Subgroup G inst✝ : Normal H✝ hG : Group.IsNilpotent G n : ℕ H : ℕ → Subgroup G hH : IsAscendingCentralSeries H hn : H n = ⊤ ⊢ H n ≤ upperCentralSeries G n [PROOFSTEP] exact ascending_central_series_le_upper H hH n [GOAL] G : Type u_1 inst✝¹ : Group G H : Subgroup G inst✝ : Normal H hG : Group.IsNilpotent G ⊢ Nat.find (_ : ∃ n H, IsDescendingCentralSeries H ∧ H n = ⊥) = nilpotencyClass G [PROOFSTEP] rw [← least_ascending_central_series_length_eq_nilpotencyClass] [GOAL] G : Type u_1 inst✝¹ : Group G H : Subgroup G inst✝ : Normal H hG : Group.IsNilpotent G ⊢ Nat.find (_ : ∃ n H, IsDescendingCentralSeries H ∧ H n = ⊥) = Nat.find (_ : ∃ n H, IsAscendingCentralSeries H ∧ H n = ⊤) [PROOFSTEP] refine le_antisymm (Nat.find_mono ?_) (Nat.find_mono ?_) [GOAL] case refine_1 G : Type u_1 inst✝¹ : Group G H : Subgroup G inst✝ : Normal H hG : Group.IsNilpotent G ⊢ ∀ (n : ℕ), (∃ H, IsAscendingCentralSeries H ∧ H n = ⊤) → ∃ H, IsDescendingCentralSeries H ∧ H n = ⊥ [PROOFSTEP] rintro n ⟨H, ⟨hH, hn⟩⟩ [GOAL] case refine_1.intro.intro G : Type u_1 inst✝¹ : Group G H✝ : Subgroup G inst✝ : Normal H✝ hG : Group.IsNilpotent G n : ℕ H : ℕ → Subgroup G hH : IsAscendingCentralSeries H hn : H n = ⊤ ⊢ ∃ H, IsDescendingCentralSeries H ∧ H n = ⊥ [PROOFSTEP] refine ⟨fun m => H (n - m), is_decending_rev_series_of_is_ascending G hn hH, ?_⟩ [GOAL] case refine_1.intro.intro G : Type u_1 inst✝¹ : Group G H✝ : Subgroup G inst✝ : Normal H✝ hG : Group.IsNilpotent G n : ℕ H : ℕ → Subgroup G hH : IsAscendingCentralSeries H hn : H n = ⊤ ⊢ (fun m => H (n - m)) n = ⊥ [PROOFSTEP] dsimp only [GOAL] case refine_1.intro.intro G : Type u_1 inst✝¹ : Group G H✝ : Subgroup G inst✝ : Normal H✝ hG : Group.IsNilpotent G n : ℕ H : ℕ → Subgroup G hH : IsAscendingCentralSeries H hn : H n = ⊤ ⊢ H (n - n) = ⊥ [PROOFSTEP] rw [tsub_self] [GOAL] case refine_1.intro.intro G : Type u_1 inst✝¹ : Group G H✝ : Subgroup G inst✝ : Normal H✝ hG : Group.IsNilpotent G n : ℕ H : ℕ → Subgroup G hH : IsAscendingCentralSeries H hn : H n = ⊤ ⊢ H 0 = ⊥ [PROOFSTEP] exact hH.1 [GOAL] case refine_2 G : Type u_1 inst✝¹ : Group G H : Subgroup G inst✝ : Normal H hG : Group.IsNilpotent G ⊢ ∀ (n : ℕ), (∃ H, IsDescendingCentralSeries H ∧ H n = ⊥) → ∃ H, IsAscendingCentralSeries H ∧ H n = ⊤ [PROOFSTEP] rintro n ⟨H, ⟨hH, hn⟩⟩ [GOAL] case refine_2.intro.intro G : Type u_1 inst✝¹ : Group G H✝ : Subgroup G inst✝ : Normal H✝ hG : Group.IsNilpotent G n : ℕ H : ℕ → Subgroup G hH : IsDescendingCentralSeries H hn : H n = ⊥ ⊢ ∃ H, IsAscendingCentralSeries H ∧ H n = ⊤ [PROOFSTEP] refine ⟨fun m => H (n - m), is_ascending_rev_series_of_is_descending G hn hH, ?_⟩ [GOAL] case refine_2.intro.intro G : Type u_1 inst✝¹ : Group G H✝ : Subgroup G inst✝ : Normal H✝ hG : Group.IsNilpotent G n : ℕ H : ℕ → Subgroup G hH : IsDescendingCentralSeries H hn : H n = ⊥ ⊢ (fun m => H (n - m)) n = ⊤ [PROOFSTEP] dsimp only [GOAL] case refine_2.intro.intro G : Type u_1 inst✝¹ : Group G H✝ : Subgroup G inst✝ : Normal H✝ hG : Group.IsNilpotent G n : ℕ H : ℕ → Subgroup G hH : IsDescendingCentralSeries H hn : H n = ⊥ ⊢ H (n - n) = ⊤ [PROOFSTEP] rw [tsub_self] [GOAL] case refine_2.intro.intro G : Type u_1 inst✝¹ : Group G H✝ : Subgroup G inst✝ : Normal H✝ hG : Group.IsNilpotent G n : ℕ H : ℕ → Subgroup G hH : IsDescendingCentralSeries H hn : H n = ⊥ ⊢ H 0 = ⊤ [PROOFSTEP] exact hH.1 [GOAL] G : Type u_1 inst✝¹ : Group G H : Subgroup G inst✝ : Normal H hG : Group.IsNilpotent G ⊢ Nat.find (_ : ∃ n, lowerCentralSeries G n = ⊥) = nilpotencyClass G [PROOFSTEP] rw [← least_descending_central_series_length_eq_nilpotencyClass] [GOAL] G : Type u_1 inst✝¹ : Group G H : Subgroup G inst✝ : Normal H hG : Group.IsNilpotent G ⊢ Nat.find (_ : ∃ n, lowerCentralSeries G n = ⊥) = Nat.find (_ : ∃ n H, IsDescendingCentralSeries H ∧ H n = ⊥) [PROOFSTEP] refine' le_antisymm (Nat.find_mono _) (Nat.find_mono _) [GOAL] case refine'_1 G : Type u_1 inst✝¹ : Group G H : Subgroup G inst✝ : Normal H hG : Group.IsNilpotent G ⊢ ∀ (n : ℕ), (∃ H, IsDescendingCentralSeries H ∧ H n = ⊥) → lowerCentralSeries G n = ⊥ [PROOFSTEP] rintro n ⟨H, ⟨hH, hn⟩⟩ [GOAL] case refine'_1.intro.intro G : Type u_1 inst✝¹ : Group G H✝ : Subgroup G inst✝ : Normal H✝ hG : Group.IsNilpotent G n : ℕ H : ℕ → Subgroup G hH : IsDescendingCentralSeries H hn : H n = ⊥ ⊢ lowerCentralSeries G n = ⊥ [PROOFSTEP] rw [← le_bot_iff, ← hn] [GOAL] case refine'_1.intro.intro G : Type u_1 inst✝¹ : Group G H✝ : Subgroup G inst✝ : Normal H✝ hG : Group.IsNilpotent G n : ℕ H : ℕ → Subgroup G hH : IsDescendingCentralSeries H hn : H n = ⊥ ⊢ lowerCentralSeries G n ≤ H n [PROOFSTEP] exact descending_central_series_ge_lower H hH n [GOAL] case refine'_2 G : Type u_1 inst✝¹ : Group G H : Subgroup G inst✝ : Normal H hG : Group.IsNilpotent G ⊢ ∀ (n : ℕ), lowerCentralSeries G n = ⊥ → ∃ H, IsDescendingCentralSeries H ∧ H n = ⊥ [PROOFSTEP] rintro n h [GOAL] case refine'_2 G : Type u_1 inst✝¹ : Group G H : Subgroup G inst✝ : Normal H hG : Group.IsNilpotent G n : ℕ h : lowerCentralSeries G n = ⊥ ⊢ ∃ H, IsDescendingCentralSeries H ∧ H n = ⊥ [PROOFSTEP] exact ⟨lowerCentralSeries G, ⟨lowerCentralSeries_isDescendingCentralSeries, h⟩⟩ [GOAL] G : Type u_1 inst✝¹ : Group G H : Subgroup G inst✝ : Normal H hG : Group.IsNilpotent G ⊢ lowerCentralSeries G (nilpotencyClass G) = ⊥ [PROOFSTEP] rw [← lowerCentralSeries_length_eq_nilpotencyClass] [GOAL] G : Type u_1 inst✝¹ : Group G H : Subgroup G inst✝ : Normal H hG : Group.IsNilpotent G ⊢ lowerCentralSeries G (Nat.find (_ : ∃ n, lowerCentralSeries G n = ⊥)) = ⊥ [PROOFSTEP] exact Nat.find_spec (nilpotent_iff_lowerCentralSeries.mp hG) [GOAL] G : Type u_1 inst✝¹ : Group G H : Subgroup G inst✝ : Normal H hG : Group.IsNilpotent G n : ℕ ⊢ lowerCentralSeries G n = ⊥ ↔ nilpotencyClass G ≤ n [PROOFSTEP] constructor [GOAL] case mp G : Type u_1 inst✝¹ : Group G H : Subgroup G inst✝ : Normal H hG : Group.IsNilpotent G n : ℕ ⊢ lowerCentralSeries G n = ⊥ → nilpotencyClass G ≤ n [PROOFSTEP] intro h [GOAL] case mp G : Type u_1 inst✝¹ : Group G H : Subgroup G inst✝ : Normal H hG : Group.IsNilpotent G n : ℕ h : lowerCentralSeries G n = ⊥ ⊢ nilpotencyClass G ≤ n [PROOFSTEP] rw [← lowerCentralSeries_length_eq_nilpotencyClass] [GOAL] case mp G : Type u_1 inst✝¹ : Group G H : Subgroup G inst✝ : Normal H hG : Group.IsNilpotent G n : ℕ h : lowerCentralSeries G n = ⊥ ⊢ Nat.find (_ : ∃ n, lowerCentralSeries G n = ⊥) ≤ n [PROOFSTEP] exact Nat.find_le h [GOAL] case mpr G : Type u_1 inst✝¹ : Group G H : Subgroup G inst✝ : Normal H hG : Group.IsNilpotent G n : ℕ ⊢ nilpotencyClass G ≤ n → lowerCentralSeries G n = ⊥ [PROOFSTEP] intro h [GOAL] case mpr G : Type u_1 inst✝¹ : Group G H : Subgroup G inst✝ : Normal H hG : Group.IsNilpotent G n : ℕ h : nilpotencyClass G ≤ n ⊢ lowerCentralSeries G n = ⊥ [PROOFSTEP] apply eq_bot_iff.mpr [GOAL] case mpr G : Type u_1 inst✝¹ : Group G H : Subgroup G inst✝ : Normal H hG : Group.IsNilpotent G n : ℕ h : nilpotencyClass G ≤ n ⊢ lowerCentralSeries G n ≤ ⊥ [PROOFSTEP] rw [← lowerCentralSeries_nilpotencyClass] [GOAL] case mpr G : Type u_1 inst✝¹ : Group G H : Subgroup G inst✝ : Normal H hG : Group.IsNilpotent G n : ℕ h : nilpotencyClass G ≤ n ⊢ lowerCentralSeries G n ≤ lowerCentralSeries G (nilpotencyClass G) [PROOFSTEP] exact lowerCentralSeries_antitone h [GOAL] G : Type u_1 inst✝¹ : Group G H✝ : Subgroup G inst✝ : Normal H✝ H : Subgroup G n : ℕ ⊢ Subgroup.map (Subgroup.subtype H) (lowerCentralSeries { x // x ∈ H } n) ≤ lowerCentralSeries G n [PROOFSTEP] induction' n with d hd [GOAL] case zero G : Type u_1 inst✝¹ : Group G H✝ : Subgroup G inst✝ : Normal H✝ H : Subgroup G ⊢ Subgroup.map (Subgroup.subtype H) (lowerCentralSeries { x // x ∈ H } Nat.zero) ≤ lowerCentralSeries G Nat.zero [PROOFSTEP] simp [GOAL] case succ G : Type u_1 inst✝¹ : Group G H✝ : Subgroup G inst✝ : Normal H✝ H : Subgroup G d : ℕ hd : Subgroup.map (Subgroup.subtype H) (lowerCentralSeries { x // x ∈ H } d) ≤ lowerCentralSeries G d ⊢ Subgroup.map (Subgroup.subtype H) (lowerCentralSeries { x // x ∈ H } (Nat.succ d)) ≤ lowerCentralSeries G (Nat.succ d) [PROOFSTEP] rw [lowerCentralSeries_succ, lowerCentralSeries_succ, MonoidHom.map_closure] [GOAL] case succ G : Type u_1 inst✝¹ : Group G H✝ : Subgroup G inst✝ : Normal H✝ H : Subgroup G d : ℕ hd : Subgroup.map (Subgroup.subtype H) (lowerCentralSeries { x // x ∈ H } d) ≤ lowerCentralSeries G d ⊢ closure (↑(Subgroup.subtype H) '' {x | ∃ p, p ∈ lowerCentralSeries { x // x ∈ H } d ∧ ∃ q, q ∈ ⊤ ∧ p * q * p⁻¹ * q⁻¹ = x}) ≤ closure {x | ∃ p, p ∈ lowerCentralSeries G d ∧ ∃ q, q ∈ ⊤ ∧ p * q * p⁻¹ * q⁻¹ = x} [PROOFSTEP] apply Subgroup.closure_mono [GOAL] case succ.h' G : Type u_1 inst✝¹ : Group G H✝ : Subgroup G inst✝ : Normal H✝ H : Subgroup G d : ℕ hd : Subgroup.map (Subgroup.subtype H) (lowerCentralSeries { x // x ∈ H } d) ≤ lowerCentralSeries G d ⊢ ↑(Subgroup.subtype H) '' {x | ∃ p, p ∈ lowerCentralSeries { x // x ∈ H } d ∧ ∃ q, q ∈ ⊤ ∧ p * q * p⁻¹ * q⁻¹ = x} ⊆ {x | ∃ p, p ∈ lowerCentralSeries G d ∧ ∃ q, q ∈ ⊤ ∧ p * q * p⁻¹ * q⁻¹ = x} [PROOFSTEP] rintro x1 ⟨x2, ⟨x3, hx3, x4, _hx4, rfl⟩, rfl⟩ [GOAL] case succ.h'.intro.intro.intro.intro.intro.intro G : Type u_1 inst✝¹ : Group G H✝ : Subgroup G inst✝ : Normal H✝ H : Subgroup G d : ℕ hd : Subgroup.map (Subgroup.subtype H) (lowerCentralSeries { x // x ∈ H } d) ≤ lowerCentralSeries G d x3 : { x // x ∈ H } hx3 : x3 ∈ lowerCentralSeries { x // x ∈ H } d x4 : { x // x ∈ H } _hx4 : x4 ∈ ⊤ ⊢ ↑(Subgroup.subtype H) (x3 * x4 * x3⁻¹ * x4⁻¹) ∈ {x | ∃ p, p ∈ lowerCentralSeries G d ∧ ∃ q, q ∈ ⊤ ∧ p * q * p⁻¹ * q⁻¹ = x} [PROOFSTEP] exact ⟨x3, hd (mem_map.mpr ⟨x3, hx3, rfl⟩), x4, by simp⟩ [GOAL] G : Type u_1 inst✝¹ : Group G H✝ : Subgroup G inst✝ : Normal H✝ H : Subgroup G d : ℕ hd : Subgroup.map (Subgroup.subtype H) (lowerCentralSeries { x // x ∈ H } d) ≤ lowerCentralSeries G d x3 : { x // x ∈ H } hx3 : x3 ∈ lowerCentralSeries { x // x ∈ H } d x4 : { x // x ∈ H } _hx4 : x4 ∈ ⊤ ⊢ ↑x4 ∈ ⊤ ∧ ↑x3 * ↑x4 * (↑x3)⁻¹ * (↑x4)⁻¹ = ↑(Subgroup.subtype H) (x3 * x4 * x3⁻¹ * x4⁻¹) [PROOFSTEP] simp [GOAL] G : Type u_1 inst✝¹ : Group G H✝ : Subgroup G inst✝ : Normal H✝ H : Subgroup G hG : Group.IsNilpotent G ⊢ Group.IsNilpotent { x // x ∈ H } [PROOFSTEP] rw [nilpotent_iff_lowerCentralSeries] at * [GOAL] G : Type u_1 inst✝¹ : Group G H✝ : Subgroup G inst✝ : Normal H✝ H : Subgroup G hG : ∃ n, lowerCentralSeries G n = ⊥ ⊢ ∃ n, lowerCentralSeries { x // x ∈ H } n = ⊥ [PROOFSTEP] rcases hG with ⟨n, hG⟩ [GOAL] case intro G : Type u_1 inst✝¹ : Group G H✝ : Subgroup G inst✝ : Normal H✝ H : Subgroup G n : ℕ hG : lowerCentralSeries G n = ⊥ ⊢ ∃ n, lowerCentralSeries { x // x ∈ H } n = ⊥ [PROOFSTEP] use n [GOAL] case h G : Type u_1 inst✝¹ : Group G H✝ : Subgroup G inst✝ : Normal H✝ H : Subgroup G n : ℕ hG : lowerCentralSeries G n = ⊥ ⊢ lowerCentralSeries { x // x ∈ H } n = ⊥ [PROOFSTEP] have := lowerCentralSeries_map_subtype_le H n [GOAL] case h G : Type u_1 inst✝¹ : Group G H✝ : Subgroup G inst✝ : Normal H✝ H : Subgroup G n : ℕ hG : lowerCentralSeries G n = ⊥ this : map (Subgroup.subtype H) (lowerCentralSeries { x // x ∈ H } n) ≤ lowerCentralSeries G n ⊢ lowerCentralSeries { x // x ∈ H } n = ⊥ [PROOFSTEP] simp only [hG, SetLike.le_def, mem_map, forall_apply_eq_imp_iff₂, exists_imp] at this [GOAL] case h G : Type u_1 inst✝¹ : Group G H✝ : Subgroup G inst✝ : Normal H✝ H : Subgroup G n : ℕ hG : lowerCentralSeries G n = ⊥ this : ∀ ⦃x : G⦄ (x_1 : { x // x ∈ H }), x_1 ∈ lowerCentralSeries { x // x ∈ H } n ∧ ↑(Subgroup.subtype H) x_1 = x → x ∈ ⊥ ⊢ lowerCentralSeries { x // x ∈ H } n = ⊥ [PROOFSTEP] exact eq_bot_iff.mpr fun x hx => Subtype.ext (this x ⟨hx, rfl⟩) [GOAL] G : Type u_1 inst✝¹ : Group G H✝ : Subgroup G inst✝ : Normal H✝ H : Subgroup G hG : Group.IsNilpotent G ⊢ nilpotencyClass { x // x ∈ H } ≤ nilpotencyClass G [PROOFSTEP] repeat rw [← lowerCentralSeries_length_eq_nilpotencyClass] --- Porting note : Lean needs to be told that predicates are decidable [GOAL] G : Type u_1 inst✝¹ : Group G H✝ : Subgroup G inst✝ : Normal H✝ H : Subgroup G hG : Group.IsNilpotent G ⊢ nilpotencyClass { x // x ∈ H } ≤ nilpotencyClass G [PROOFSTEP] rw [← lowerCentralSeries_length_eq_nilpotencyClass] --- Porting note : Lean needs to be told that predicates are decidable [GOAL] G : Type u_1 inst✝¹ : Group G H✝ : Subgroup G inst✝ : Normal H✝ H : Subgroup G hG : Group.IsNilpotent G ⊢ Nat.find (_ : ∃ n, lowerCentralSeries { x // x ∈ H } n = ⊥) ≤ nilpotencyClass G [PROOFSTEP] rw [← lowerCentralSeries_length_eq_nilpotencyClass] --- Porting note : Lean needs to be told that predicates are decidable [GOAL] G : Type u_1 inst✝¹ : Group G H✝ : Subgroup G inst✝ : Normal H✝ H : Subgroup G hG : Group.IsNilpotent G ⊢ Nat.find (_ : ∃ n, lowerCentralSeries { x // x ∈ H } n = ⊥) ≤ Nat.find (_ : ∃ n, lowerCentralSeries G n = ⊥) [PROOFSTEP] rw [← lowerCentralSeries_length_eq_nilpotencyClass] --- Porting note : Lean needs to be told that predicates are decidable [GOAL] G : Type u_1 inst✝¹ : Group G H✝ : Subgroup G inst✝ : Normal H✝ H : Subgroup G hG : Group.IsNilpotent G ⊢ Nat.find (_ : ∃ n, lowerCentralSeries { x // x ∈ H } n = ⊥) ≤ Nat.find (_ : ∃ n, lowerCentralSeries G n = ⊥) [PROOFSTEP] refine @Nat.find_mono _ _ (Classical.decPred _) (Classical.decPred _) ?_ _ _ [GOAL] G : Type u_1 inst✝¹ : Group G H✝ : Subgroup G inst✝ : Normal H✝ H : Subgroup G hG : Group.IsNilpotent G ⊢ ∀ (n : ℕ), lowerCentralSeries G n = ⊥ → lowerCentralSeries { x // x ∈ H } n = ⊥ [PROOFSTEP] intro n hG [GOAL] G : Type u_1 inst✝¹ : Group G H✝ : Subgroup G inst✝ : Normal H✝ H : Subgroup G hG✝ : Group.IsNilpotent G n : ℕ hG : lowerCentralSeries G n = ⊥ ⊢ lowerCentralSeries { x // x ∈ H } n = ⊥ [PROOFSTEP] have := lowerCentralSeries_map_subtype_le H n [GOAL] G : Type u_1 inst✝¹ : Group G H✝ : Subgroup G inst✝ : Normal H✝ H : Subgroup G hG✝ : Group.IsNilpotent G n : ℕ hG : lowerCentralSeries G n = ⊥ this : map (Subgroup.subtype H) (lowerCentralSeries { x // x ∈ H } n) ≤ lowerCentralSeries G n ⊢ lowerCentralSeries { x // x ∈ H } n = ⊥ [PROOFSTEP] simp only [hG, SetLike.le_def, mem_map, forall_apply_eq_imp_iff₂, exists_imp] at this [GOAL] G : Type u_1 inst✝¹ : Group G H✝ : Subgroup G inst✝ : Normal H✝ H : Subgroup G hG✝ : Group.IsNilpotent G n : ℕ hG : lowerCentralSeries G n = ⊥ this : ∀ ⦃x : G⦄ (x_1 : { x // x ∈ H }), x_1 ∈ lowerCentralSeries { x // x ∈ H } n ∧ ↑(Subgroup.subtype H) x_1 = x → x ∈ ⊥ ⊢ lowerCentralSeries { x // x ∈ H } n = ⊥ [PROOFSTEP] exact eq_bot_iff.mpr fun x hx => Subtype.ext (this x ⟨hx, rfl⟩) [GOAL] G : Type u_1 inst✝² : Group G H✝ : Subgroup G inst✝¹ : Normal H✝ H : Type u_2 inst✝ : Group H f : G →* H h : Function.Surjective ↑f n : ℕ ⊢ Subgroup.map f (upperCentralSeries G n) ≤ upperCentralSeries H n [PROOFSTEP] induction' n with d hd [GOAL] case zero G : Type u_1 inst✝² : Group G H✝ : Subgroup G inst✝¹ : Normal H✝ H : Type u_2 inst✝ : Group H f : G →* H h : Function.Surjective ↑f ⊢ Subgroup.map f (upperCentralSeries G Nat.zero) ≤ upperCentralSeries H Nat.zero [PROOFSTEP] simp [GOAL] case succ G : Type u_1 inst✝² : Group G H✝ : Subgroup G inst✝¹ : Normal H✝ H : Type u_2 inst✝ : Group H f : G →* H h : Function.Surjective ↑f d : ℕ hd : Subgroup.map f (upperCentralSeries G d) ≤ upperCentralSeries H d ⊢ Subgroup.map f (upperCentralSeries G (Nat.succ d)) ≤ upperCentralSeries H (Nat.succ d) [PROOFSTEP] rintro _ ⟨x, hx : x ∈ upperCentralSeries G d.succ, rfl⟩ y' [GOAL] case succ.intro.intro G : Type u_1 inst✝² : Group G H✝ : Subgroup G inst✝¹ : Normal H✝ H : Type u_2 inst✝ : Group H f : G →* H h : Function.Surjective ↑f d : ℕ hd : Subgroup.map f (upperCentralSeries G d) ≤ upperCentralSeries H d x : G hx : x ∈ upperCentralSeries G (Nat.succ d) y' : H ⊢ ↑f x * y' * (↑f x)⁻¹ * y'⁻¹ ∈ (upperCentralSeriesAux H d).fst [PROOFSTEP] rcases h y' with ⟨y, rfl⟩ [GOAL] case succ.intro.intro.intro G : Type u_1 inst✝² : Group G H✝ : Subgroup G inst✝¹ : Normal H✝ H : Type u_2 inst✝ : Group H f : G →* H h : Function.Surjective ↑f d : ℕ hd : Subgroup.map f (upperCentralSeries G d) ≤ upperCentralSeries H d x : G hx : x ∈ upperCentralSeries G (Nat.succ d) y : G ⊢ ↑f x * ↑f y * (↑f x)⁻¹ * (↑f y)⁻¹ ∈ (upperCentralSeriesAux H d).fst [PROOFSTEP] simpa using hd (mem_map_of_mem f (hx y)) [GOAL] G : Type u_1 inst✝² : Group G H✝ : Subgroup G inst✝¹ : Normal H✝ H : Type u_2 inst✝ : Group H f : G →* H n : ℕ ⊢ Subgroup.map f (lowerCentralSeries G n) ≤ lowerCentralSeries H n [PROOFSTEP] induction' n with d hd [GOAL] case zero G : Type u_1 inst✝² : Group G H✝ : Subgroup G inst✝¹ : Normal H✝ H : Type u_2 inst✝ : Group H f : G →* H ⊢ Subgroup.map f (lowerCentralSeries G Nat.zero) ≤ lowerCentralSeries H Nat.zero [PROOFSTEP] simp [Nat.zero_eq] [GOAL] case succ G : Type u_1 inst✝² : Group G H✝ : Subgroup G inst✝¹ : Normal H✝ H : Type u_2 inst✝ : Group H f : G →* H d : ℕ hd : Subgroup.map f (lowerCentralSeries G d) ≤ lowerCentralSeries H d ⊢ Subgroup.map f (lowerCentralSeries G (Nat.succ d)) ≤ lowerCentralSeries H (Nat.succ d) [PROOFSTEP] rintro a ⟨x, hx : x ∈ lowerCentralSeries G d.succ, rfl⟩ [GOAL] case succ.intro.intro G : Type u_1 inst✝² : Group G H✝ : Subgroup G inst✝¹ : Normal H✝ H : Type u_2 inst✝ : Group H f : G →* H d : ℕ hd : Subgroup.map f (lowerCentralSeries G d) ≤ lowerCentralSeries H d x : G hx : x ∈ lowerCentralSeries G (Nat.succ d) ⊢ ↑f x ∈ lowerCentralSeries H (Nat.succ d) [PROOFSTEP] refine closure_induction hx ?_ (by simp [f.map_one, Subgroup.one_mem _]) (fun y z hy hz => by simp [MonoidHom.map_mul, Subgroup.mul_mem _ hy hz]) (fun y hy => by rw [f.map_inv]; exact Subgroup.inv_mem _ hy) [GOAL] G : Type u_1 inst✝² : Group G H✝ : Subgroup G inst✝¹ : Normal H✝ H : Type u_2 inst✝ : Group H f : G →* H d : ℕ hd : Subgroup.map f (lowerCentralSeries G d) ≤ lowerCentralSeries H d x : G hx : x ∈ lowerCentralSeries G (Nat.succ d) ⊢ ↑f 1 ∈ lowerCentralSeries H (Nat.succ d) [PROOFSTEP] simp [f.map_one, Subgroup.one_mem _] [GOAL] G : Type u_1 inst✝² : Group G H✝ : Subgroup G inst✝¹ : Normal H✝ H : Type u_2 inst✝ : Group H f : G →* H d : ℕ hd : Subgroup.map f (lowerCentralSeries G d) ≤ lowerCentralSeries H d x : G hx : x ∈ lowerCentralSeries G (Nat.succ d) y z : G hy : ↑f y ∈ lowerCentralSeries H (Nat.succ d) hz : ↑f z ∈ lowerCentralSeries H (Nat.succ d) ⊢ ↑f (y * z) ∈ lowerCentralSeries H (Nat.succ d) [PROOFSTEP] simp [MonoidHom.map_mul, Subgroup.mul_mem _ hy hz] [GOAL] G : Type u_1 inst✝² : Group G H✝ : Subgroup G inst✝¹ : Normal H✝ H : Type u_2 inst✝ : Group H f : G →* H d : ℕ hd : Subgroup.map f (lowerCentralSeries G d) ≤ lowerCentralSeries H d x : G hx : x ∈ lowerCentralSeries G (Nat.succ d) y : G hy : ↑f y ∈ lowerCentralSeries H (Nat.succ d) ⊢ ↑f y⁻¹ ∈ lowerCentralSeries H (Nat.succ d) [PROOFSTEP] rw [f.map_inv] [GOAL] G : Type u_1 inst✝² : Group G H✝ : Subgroup G inst✝¹ : Normal H✝ H : Type u_2 inst✝ : Group H f : G →* H d : ℕ hd : Subgroup.map f (lowerCentralSeries G d) ≤ lowerCentralSeries H d x : G hx : x ∈ lowerCentralSeries G (Nat.succ d) y : G hy : ↑f y ∈ lowerCentralSeries H (Nat.succ d) ⊢ (↑f y)⁻¹ ∈ lowerCentralSeries H (Nat.succ d) [PROOFSTEP] exact Subgroup.inv_mem _ hy [GOAL] case succ.intro.intro G : Type u_1 inst✝² : Group G H✝ : Subgroup G inst✝¹ : Normal H✝ H : Type u_2 inst✝ : Group H f : G →* H d : ℕ hd : Subgroup.map f (lowerCentralSeries G d) ≤ lowerCentralSeries H d x : G hx : x ∈ lowerCentralSeries G (Nat.succ d) ⊢ ∀ (x : G), x ∈ {g | ∃ g₁, g₁ ∈ lowerCentralSeries G d ∧ ∃ g₂, g₂ ∈ ⊤ ∧ ⁅g₁, g₂⁆ = g} → ↑f x ∈ lowerCentralSeries H (Nat.succ d) [PROOFSTEP] rintro a ⟨y, hy, z, ⟨-, rfl⟩⟩ [GOAL] case succ.intro.intro.intro.intro.intro.intro G : Type u_1 inst✝² : Group G H✝ : Subgroup G inst✝¹ : Normal H✝ H : Type u_2 inst✝ : Group H f : G →* H d : ℕ hd : Subgroup.map f (lowerCentralSeries G d) ≤ lowerCentralSeries H d x : G hx : x ∈ lowerCentralSeries G (Nat.succ d) y : G hy : y ∈ lowerCentralSeries G d z : G ⊢ ↑f ⁅y, z⁆ ∈ lowerCentralSeries H (Nat.succ d) [PROOFSTEP] apply mem_closure.mpr [GOAL] case succ.intro.intro.intro.intro.intro.intro G : Type u_1 inst✝² : Group G H✝ : Subgroup G inst✝¹ : Normal H✝ H : Type u_2 inst✝ : Group H f : G →* H d : ℕ hd : Subgroup.map f (lowerCentralSeries G d) ≤ lowerCentralSeries H d x : G hx : x ∈ lowerCentralSeries G (Nat.succ d) y : G hy : y ∈ lowerCentralSeries G d z : G ⊢ ∀ (K : Subgroup H), {g | ∃ g₁, g₁ ∈ lowerCentralSeries H d ∧ ∃ g₂, g₂ ∈ ⊤ ∧ ⁅g₁, g₂⁆ = g} ⊆ ↑K → ↑f ⁅y, z⁆ ∈ K [PROOFSTEP] exact fun K hK => hK ⟨f y, hd (mem_map_of_mem f hy), by simp [commutatorElement_def]⟩ [GOAL] G : Type u_1 inst✝² : Group G H✝ : Subgroup G inst✝¹ : Normal H✝ H : Type u_2 inst✝ : Group H f : G →* H d : ℕ hd : Subgroup.map f (lowerCentralSeries G d) ≤ lowerCentralSeries H d x : G hx : x ∈ lowerCentralSeries G (Nat.succ d) y : G hy : y ∈ lowerCentralSeries G d z : G K : Subgroup H hK : {g | ∃ g₁, g₁ ∈ lowerCentralSeries H d ∧ ∃ g₂, g₂ ∈ ⊤ ∧ ⁅g₁, g₂⁆ = g} ⊆ ↑K ⊢ ∃ g₂, g₂ ∈ ⊤ ∧ ⁅↑f y, g₂⁆ = ↑f ⁅y, z⁆ [PROOFSTEP] simp [commutatorElement_def] [GOAL] G : Type u_1 inst✝¹ : Group G H : Subgroup G inst✝ : Normal H n : ℕ h : lowerCentralSeries G n ≤ center G ⊢ lowerCentralSeries G (n + 1) = ⊥ [PROOFSTEP] rw [lowerCentralSeries_succ, closure_eq_bot_iff, Set.subset_singleton_iff] [GOAL] G : Type u_1 inst✝¹ : Group G H : Subgroup G inst✝ : Normal H n : ℕ h : lowerCentralSeries G n ≤ center G ⊢ ∀ (y : G), y ∈ {x | ∃ p, p ∈ lowerCentralSeries G n ∧ ∃ q, q ∈ ⊤ ∧ p * q * p⁻¹ * q⁻¹ = x} → y = 1 [PROOFSTEP] rintro x ⟨y, hy1, z, ⟨⟩, rfl⟩ [GOAL] case intro.intro.intro.intro.intro G : Type u_1 inst✝¹ : Group G H : Subgroup G inst✝ : Normal H n : ℕ h : lowerCentralSeries G n ≤ center G y : G hy1 : y ∈ lowerCentralSeries G n z : G ⊢ y * z * y⁻¹ * z⁻¹ = 1 [PROOFSTEP] rw [mul_assoc, ← mul_inv_rev, mul_inv_eq_one, eq_comm] [GOAL] case intro.intro.intro.intro.intro G : Type u_1 inst✝¹ : Group G H : Subgroup G inst✝ : Normal H n : ℕ h : lowerCentralSeries G n ≤ center G y : G hy1 : y ∈ lowerCentralSeries G n z : G ⊢ z * y = y * z [PROOFSTEP] exact mem_center_iff.mp (h hy1) z [GOAL] G : Type u_1 inst✝² : Group G H✝ : Subgroup G inst✝¹ : Normal H✝ H : Type u_2 inst✝ : Group H f : G →* H hf1 : MonoidHom.ker f ≤ center G hH : Group.IsNilpotent H ⊢ Group.IsNilpotent G [PROOFSTEP] rw [nilpotent_iff_lowerCentralSeries] at * [GOAL] G : Type u_1 inst✝² : Group G H✝ : Subgroup G inst✝¹ : Normal H✝ H : Type u_2 inst✝ : Group H f : G →* H hf1 : MonoidHom.ker f ≤ center G hH : ∃ n, lowerCentralSeries H n = ⊥ ⊢ ∃ n, lowerCentralSeries G n = ⊥ [PROOFSTEP] rcases hH with ⟨n, hn⟩ [GOAL] case intro G : Type u_1 inst✝² : Group G H✝ : Subgroup G inst✝¹ : Normal H✝ H : Type u_2 inst✝ : Group H f : G →* H hf1 : MonoidHom.ker f ≤ center G n : ℕ hn : lowerCentralSeries H n = ⊥ ⊢ ∃ n, lowerCentralSeries G n = ⊥ [PROOFSTEP] use n + 1 [GOAL] case h G : Type u_1 inst✝² : Group G H✝ : Subgroup G inst✝¹ : Normal H✝ H : Type u_2 inst✝ : Group H f : G →* H hf1 : MonoidHom.ker f ≤ center G n : ℕ hn : lowerCentralSeries H n = ⊥ ⊢ lowerCentralSeries G (n + 1) = ⊥ [PROOFSTEP] refine' lowerCentralSeries_succ_eq_bot (le_trans ((Subgroup.map_eq_bot_iff _).mp _) hf1) [GOAL] case h G : Type u_1 inst✝² : Group G H✝ : Subgroup G inst✝¹ : Normal H✝ H : Type u_2 inst✝ : Group H f : G →* H hf1 : MonoidHom.ker f ≤ center G n : ℕ hn : lowerCentralSeries H n = ⊥ ⊢ Subgroup.map f (lowerCentralSeries G n) = ⊥ [PROOFSTEP] exact eq_bot_iff.mpr (hn ▸ lowerCentralSeries.map f n) [GOAL] G : Type u_1 inst✝² : Group G H✝ : Subgroup G inst✝¹ : Normal H✝ H : Type u_2 inst✝ : Group H f : G →* H hf1 : MonoidHom.ker f ≤ center G hH : Group.IsNilpotent H ⊢ nilpotencyClass G ≤ nilpotencyClass H + 1 [PROOFSTEP] haveI : IsNilpotent G := isNilpotent_of_ker_le_center f hf1 hH [GOAL] G : Type u_1 inst✝² : Group G H✝ : Subgroup G inst✝¹ : Normal H✝ H : Type u_2 inst✝ : Group H f : G →* H hf1 : MonoidHom.ker f ≤ center G hH : Group.IsNilpotent H this : Group.IsNilpotent G ⊢ nilpotencyClass G ≤ nilpotencyClass H + 1 [PROOFSTEP] rw [← lowerCentralSeries_length_eq_nilpotencyClass] -- Porting note: Lean needs to be told that predicates are decidable [GOAL] G : Type u_1 inst✝² : Group G H✝ : Subgroup G inst✝¹ : Normal H✝ H : Type u_2 inst✝ : Group H f : G →* H hf1 : MonoidHom.ker f ≤ center G hH : Group.IsNilpotent H this : Group.IsNilpotent G ⊢ Nat.find (_ : ∃ n, lowerCentralSeries G n = ⊥) ≤ nilpotencyClass H + 1 [PROOFSTEP] refine @Nat.find_min' _ (Classical.decPred _) _ _ ?_ [GOAL] G : Type u_1 inst✝² : Group G H✝ : Subgroup G inst✝¹ : Normal H✝ H : Type u_2 inst✝ : Group H f : G →* H hf1 : MonoidHom.ker f ≤ center G hH : Group.IsNilpotent H this : Group.IsNilpotent G ⊢ lowerCentralSeries G (nilpotencyClass H + 1) = ⊥ [PROOFSTEP] refine lowerCentralSeries_succ_eq_bot (le_trans ((Subgroup.map_eq_bot_iff _).mp ?_) hf1) [GOAL] G : Type u_1 inst✝² : Group G H✝ : Subgroup G inst✝¹ : Normal H✝ H : Type u_2 inst✝ : Group H f : G →* H hf1 : MonoidHom.ker f ≤ center G hH : Group.IsNilpotent H this : Group.IsNilpotent G ⊢ Subgroup.map f (lowerCentralSeries G (nilpotencyClass H)) = ⊥ [PROOFSTEP] apply eq_bot_iff.mpr [GOAL] G : Type u_1 inst✝² : Group G H✝ : Subgroup G inst✝¹ : Normal H✝ H : Type u_2 inst✝ : Group H f : G →* H hf1 : MonoidHom.ker f ≤ center G hH : Group.IsNilpotent H this : Group.IsNilpotent G ⊢ Subgroup.map f (lowerCentralSeries G (nilpotencyClass H)) ≤ ⊥ [PROOFSTEP] apply le_trans (lowerCentralSeries.map f _) [GOAL] G : Type u_1 inst✝² : Group G H✝ : Subgroup G inst✝¹ : Normal H✝ H : Type u_2 inst✝ : Group H f : G →* H hf1 : MonoidHom.ker f ≤ center G hH : Group.IsNilpotent H this : Group.IsNilpotent G ⊢ lowerCentralSeries H (nilpotencyClass H) ≤ ⊥ [PROOFSTEP] simp only [lowerCentralSeries_nilpotencyClass, le_bot_iff] [GOAL] G : Type u_1 inst✝² : Group G H : Subgroup G inst✝¹ : Normal H G' : Type u_2 inst✝ : Group G' h : Group.IsNilpotent G f : G →* G' hf : Function.Surjective ↑f ⊢ Group.IsNilpotent G' [PROOFSTEP] rcases h with ⟨n, hn⟩ [GOAL] case mk.intro G : Type u_1 inst✝² : Group G H : Subgroup G inst✝¹ : Normal H G' : Type u_2 inst✝ : Group G' f : G →* G' hf : Function.Surjective ↑f n : ℕ hn : upperCentralSeries G n = ⊤ ⊢ Group.IsNilpotent G' [PROOFSTEP] use n [GOAL] case h G : Type u_1 inst✝² : Group G H : Subgroup G inst✝¹ : Normal H G' : Type u_2 inst✝ : Group G' f : G →* G' hf : Function.Surjective ↑f n : ℕ hn : upperCentralSeries G n = ⊤ ⊢ upperCentralSeries G' n = ⊤ [PROOFSTEP] apply eq_top_iff.mpr [GOAL] case h G : Type u_1 inst✝² : Group G H : Subgroup G inst✝¹ : Normal H G' : Type u_2 inst✝ : Group G' f : G →* G' hf : Function.Surjective ↑f n : ℕ hn : upperCentralSeries G n = ⊤ ⊢ ⊤ ≤ upperCentralSeries G' n [PROOFSTEP] calc ⊤ = f.range := symm (f.range_top_of_surjective hf) _ = Subgroup.map f ⊤ := (MonoidHom.range_eq_map _) _ = Subgroup.map f (upperCentralSeries G n) := by rw [hn] _ ≤ upperCentralSeries G' n := upperCentralSeries.map hf n [GOAL] G : Type u_1 inst✝² : Group G H : Subgroup G inst✝¹ : Normal H G' : Type u_2 inst✝ : Group G' f : G →* G' hf : Function.Surjective ↑f n : ℕ hn : upperCentralSeries G n = ⊤ ⊢ Subgroup.map f ⊤ = Subgroup.map f (upperCentralSeries G n) [PROOFSTEP] rw [hn] [GOAL] G : Type u_1 inst✝² : Group G H : Subgroup G inst✝¹ : Normal H G' : Type u_2 inst✝ : Group G' f : G →* G' hf : Function.Surjective ↑f h : Group.IsNilpotent G ⊢ nilpotencyClass G' ≤ nilpotencyClass G [PROOFSTEP] refine @Nat.find_mono _ _ (Classical.decPred _) (Classical.decPred _) ?_ _ _ [GOAL] G : Type u_1 inst✝² : Group G H : Subgroup G inst✝¹ : Normal H G' : Type u_2 inst✝ : Group G' f : G →* G' hf : Function.Surjective ↑f h : Group.IsNilpotent G ⊢ ∀ (n : ℕ), upperCentralSeries G n = ⊤ → upperCentralSeries G' n = ⊤ [PROOFSTEP] intro n hn [GOAL] G : Type u_1 inst✝² : Group G H : Subgroup G inst✝¹ : Normal H G' : Type u_2 inst✝ : Group G' f : G →* G' hf : Function.Surjective ↑f h : Group.IsNilpotent G n : ℕ hn : upperCentralSeries G n = ⊤ ⊢ upperCentralSeries G' n = ⊤ [PROOFSTEP] apply eq_top_iff.mpr [GOAL] G : Type u_1 inst✝² : Group G H : Subgroup G inst✝¹ : Normal H G' : Type u_2 inst✝ : Group G' f : G →* G' hf : Function.Surjective ↑f h : Group.IsNilpotent G n : ℕ hn : upperCentralSeries G n = ⊤ ⊢ ⊤ ≤ upperCentralSeries G' n [PROOFSTEP] calc ⊤ = f.range := symm (f.range_top_of_surjective hf) _ = Subgroup.map f ⊤ := (MonoidHom.range_eq_map _) _ = Subgroup.map f (upperCentralSeries G n) := by rw [hn] _ ≤ upperCentralSeries G' n := upperCentralSeries.map hf n [GOAL] G : Type u_1 inst✝² : Group G H : Subgroup G inst✝¹ : Normal H G' : Type u_2 inst✝ : Group G' f : G →* G' hf : Function.Surjective ↑f h : Group.IsNilpotent G n : ℕ hn : upperCentralSeries G n = ⊤ ⊢ Subgroup.map f ⊤ = Subgroup.map f (upperCentralSeries G n) [PROOFSTEP] rw [hn] [GOAL] G : Type u_1 inst✝³ : Group G H : Subgroup G inst✝² : Normal H H₁ H₂ : Subgroup G inst✝¹ : Normal H₁ inst✝ : Normal H₂ h : H₁ = H₂ ⊢ comap (mk' H₁) (center (G ⧸ H₁)) = comap (mk' H₂) (center (G ⧸ H₂)) [PROOFSTEP] subst h [GOAL] G : Type u_1 inst✝³ : Group G H : Subgroup G inst✝² : Normal H H₁ : Subgroup G inst✝¹ inst✝ : Normal H₁ ⊢ comap (mk' H₁) (center (G ⧸ H₁)) = comap (mk' H₁) (center (G ⧸ H₁)) [PROOFSTEP] rfl [GOAL] G : Type u_1 inst✝¹ : Group G H : Subgroup G inst✝ : Normal H n : ℕ ⊢ comap (mk' (center G)) (upperCentralSeries (G ⧸ center G) n) = upperCentralSeries G (Nat.succ n) [PROOFSTEP] induction' n with n ih [GOAL] case zero G : Type u_1 inst✝¹ : Group G H : Subgroup G inst✝ : Normal H ⊢ comap (mk' (center G)) (upperCentralSeries (G ⧸ center G) Nat.zero) = upperCentralSeries G (Nat.succ Nat.zero) [PROOFSTEP] simp only [Nat.zero_eq, upperCentralSeries_zero, MonoidHom.comap_bot, ker_mk', (upperCentralSeries_one G).symm] [GOAL] case succ G : Type u_1 inst✝¹ : Group G H : Subgroup G inst✝ : Normal H n : ℕ ih : comap (mk' (center G)) (upperCentralSeries (G ⧸ center G) n) = upperCentralSeries G (Nat.succ n) ⊢ comap (mk' (center G)) (upperCentralSeries (G ⧸ center G) (Nat.succ n)) = upperCentralSeries G (Nat.succ (Nat.succ n)) [PROOFSTEP] let Hn := upperCentralSeries (G ⧸ center G) n [GOAL] case succ G : Type u_1 inst✝¹ : Group G H : Subgroup G inst✝ : Normal H n : ℕ ih : comap (mk' (center G)) (upperCentralSeries (G ⧸ center G) n) = upperCentralSeries G (Nat.succ n) Hn : Subgroup (G ⧸ center G) := upperCentralSeries (G ⧸ center G) n ⊢ comap (mk' (center G)) (upperCentralSeries (G ⧸ center G) (Nat.succ n)) = upperCentralSeries G (Nat.succ (Nat.succ n)) [PROOFSTEP] calc comap (mk' (center G)) (upperCentralSeriesStep Hn) = comap (mk' (center G)) (comap (mk' Hn) (center ((G ⧸ center G) ⧸ Hn))) := by rw [upperCentralSeriesStep_eq_comap_center] _ = comap (mk' (comap (mk' (center G)) Hn)) (center (G ⧸ comap (mk' (center G)) Hn)) := QuotientGroup.comap_comap_center _ = comap (mk' (upperCentralSeries G n.succ)) (center (G ⧸ upperCentralSeries G n.succ)) := (comap_center_subst ih) _ = upperCentralSeriesStep (upperCentralSeries G n.succ) := symm (upperCentralSeriesStep_eq_comap_center _) [GOAL] G : Type u_1 inst✝¹ : Group G H : Subgroup G inst✝ : Normal H n : ℕ ih : comap (mk' (center G)) (upperCentralSeries (G ⧸ center G) n) = upperCentralSeries G (Nat.succ n) Hn : Subgroup (G ⧸ center G) := upperCentralSeries (G ⧸ center G) n ⊢ comap (mk' (center G)) (upperCentralSeriesStep Hn) = comap (mk' (center G)) (comap (mk' Hn) (center ((G ⧸ center G) ⧸ Hn))) [PROOFSTEP] rw [upperCentralSeriesStep_eq_comap_center] [GOAL] G : Type u_1 inst✝² : Group G H : Subgroup G inst✝¹ : Normal H inst✝ : Group.IsNilpotent G ⊢ nilpotencyClass G = 0 ↔ Subsingleton G [PROOFSTEP] rw [Group.nilpotencyClass, @Nat.find_eq_zero _ (Classical.decPred _), upperCentralSeries_zero, subsingleton_iff_bot_eq_top, Subgroup.subsingleton_iff] [GOAL] G : Type u_1 inst✝¹ : Group G H : Subgroup G inst✝ : Normal H hH : Group.IsNilpotent G ⊢ nilpotencyClass (G ⧸ center G) = nilpotencyClass G - 1 [PROOFSTEP] generalize hn : Group.nilpotencyClass G = n [GOAL] G : Type u_1 inst✝¹ : Group G H : Subgroup G inst✝ : Normal H hH : Group.IsNilpotent G n : ℕ hn : nilpotencyClass G = n ⊢ nilpotencyClass (G ⧸ center G) = n - 1 [PROOFSTEP] rcases n with (rfl | n) [GOAL] case zero G : Type u_1 inst✝¹ : Group G H : Subgroup G inst✝ : Normal H hH : Group.IsNilpotent G hn : nilpotencyClass G = Nat.zero ⊢ nilpotencyClass (G ⧸ center G) = Nat.zero - 1 [PROOFSTEP] simp [nilpotencyClass_zero_iff_subsingleton] at * [GOAL] case zero G : Type u_1 inst✝¹ : Group G H : Subgroup G inst✝ : Normal H hH : Group.IsNilpotent G hn : Subsingleton G ⊢ Subsingleton (G ⧸ center G) [PROOFSTEP] exact Quotient.instSubsingletonQuotient (leftRel (center G)) [GOAL] case succ G : Type u_1 inst✝¹ : Group G H : Subgroup G inst✝ : Normal H hH : Group.IsNilpotent G n : ℕ hn : nilpotencyClass G = Nat.succ n ⊢ nilpotencyClass (G ⧸ center G) = Nat.succ n - 1 [PROOFSTEP] suffices Group.nilpotencyClass (G ⧸ center G) = n by simpa [GOAL] G : Type u_1 inst✝¹ : Group G H : Subgroup G inst✝ : Normal H hH : Group.IsNilpotent G n : ℕ hn : nilpotencyClass G = Nat.succ n this : nilpotencyClass (G ⧸ center G) = n ⊢ nilpotencyClass (G ⧸ center G) = Nat.succ n - 1 [PROOFSTEP] simpa [GOAL] case succ G : Type u_1 inst✝¹ : Group G H : Subgroup G inst✝ : Normal H hH : Group.IsNilpotent G n : ℕ hn : nilpotencyClass G = Nat.succ n ⊢ nilpotencyClass (G ⧸ center G) = n [PROOFSTEP] apply le_antisymm [GOAL] case succ.a G : Type u_1 inst✝¹ : Group G H : Subgroup G inst✝ : Normal H hH : Group.IsNilpotent G n : ℕ hn : nilpotencyClass G = Nat.succ n ⊢ nilpotencyClass (G ⧸ center G) ≤ n [PROOFSTEP] apply upperCentralSeries_eq_top_iff_nilpotencyClass_le.mp [GOAL] case succ.a G : Type u_1 inst✝¹ : Group G H : Subgroup G inst✝ : Normal H hH : Group.IsNilpotent G n : ℕ hn : nilpotencyClass G = Nat.succ n ⊢ upperCentralSeries (G ⧸ center G) n = ⊤ [PROOFSTEP] apply @comap_injective G _ _ _ (mk' (center G)) (surjective_quot_mk _) [GOAL] case succ.a.a G : Type u_1 inst✝¹ : Group G H : Subgroup G inst✝ : Normal H hH : Group.IsNilpotent G n : ℕ hn : nilpotencyClass G = Nat.succ n ⊢ comap (mk' (center G)) (upperCentralSeries (G ⧸ center G) n) = comap (mk' (center G)) ⊤ [PROOFSTEP] rw [comap_upperCentralSeries_quotient_center, comap_top, ← hn] [GOAL] case succ.a.a G : Type u_1 inst✝¹ : Group G H : Subgroup G inst✝ : Normal H hH : Group.IsNilpotent G n : ℕ hn : nilpotencyClass G = Nat.succ n ⊢ upperCentralSeries G (nilpotencyClass G) = ⊤ [PROOFSTEP] exact upperCentralSeries_nilpotencyClass [GOAL] case succ.a G : Type u_1 inst✝¹ : Group G H : Subgroup G inst✝ : Normal H hH : Group.IsNilpotent G n : ℕ hn : nilpotencyClass G = Nat.succ n ⊢ n ≤ nilpotencyClass (G ⧸ center G) [PROOFSTEP] apply le_of_add_le_add_right [GOAL] case succ.a.bc G : Type u_1 inst✝¹ : Group G H : Subgroup G inst✝ : Normal H hH : Group.IsNilpotent G n : ℕ hn : nilpotencyClass G = Nat.succ n ⊢ n + ?succ.a.a ≤ nilpotencyClass (G ⧸ center G) + ?succ.a.a case succ.a.a G : Type u_1 inst✝¹ : Group G H : Subgroup G inst✝ : Normal H hH : Group.IsNilpotent G n : ℕ hn : nilpotencyClass G = Nat.succ n ⊢ ℕ [PROOFSTEP] calc n + 1 = n.succ := rfl _ = Group.nilpotencyClass G := (symm hn) _ ≤ Group.nilpotencyClass (G ⧸ center G) + 1 := nilpotencyClass_le_of_ker_le_center _ (le_of_eq (ker_mk' _)) _ [GOAL] G : Type u_1 inst✝² : Group G H : Subgroup G inst✝¹ : Normal H hH : Group.IsNilpotent G inst✝ : Nontrivial G ⊢ nilpotencyClass G = nilpotencyClass (G ⧸ center G) + 1 [PROOFSTEP] rw [nilpotencyClass_quotient_center] [GOAL] G : Type u_1 inst✝² : Group G H : Subgroup G inst✝¹ : Normal H hH : Group.IsNilpotent G inst✝ : Nontrivial G ⊢ nilpotencyClass G = nilpotencyClass G - 1 + 1 [PROOFSTEP] rcases h : Group.nilpotencyClass G with ⟨⟩ [GOAL] case zero G : Type u_1 inst✝² : Group G H : Subgroup G inst✝¹ : Normal H hH : Group.IsNilpotent G inst✝ : Nontrivial G h : nilpotencyClass G = Nat.zero ⊢ Nat.zero = Nat.zero - 1 + 1 [PROOFSTEP] exfalso [GOAL] case zero.h G : Type u_1 inst✝² : Group G H : Subgroup G inst✝¹ : Normal H hH : Group.IsNilpotent G inst✝ : Nontrivial G h : nilpotencyClass G = Nat.zero ⊢ False [PROOFSTEP] rw [nilpotencyClass_zero_iff_subsingleton] at h [GOAL] case zero.h G : Type u_1 inst✝² : Group G H : Subgroup G inst✝¹ : Normal H hH : Group.IsNilpotent G inst✝ : Nontrivial G h : Subsingleton G ⊢ False [PROOFSTEP] skip [GOAL] case zero.h G : Type u_1 inst✝² : Group G H : Subgroup G inst✝¹ : Normal H hH : Group.IsNilpotent G inst✝ : Nontrivial G h : Subsingleton G ⊢ False [PROOFSTEP] apply false_of_nontrivial_of_subsingleton G [GOAL] case succ G : Type u_1 inst✝² : Group G H : Subgroup G inst✝¹ : Normal H hH : Group.IsNilpotent G inst✝ : Nontrivial G n✝ : ℕ h : nilpotencyClass G = Nat.succ n✝ ⊢ Nat.succ n✝ = Nat.succ n✝ - 1 + 1 [PROOFSTEP] simp [GOAL] G : Type u_1 inst✝¹ : Group G H : Subgroup G inst✝ : Normal H h : Group.IsNilpotent (G ⧸ center G) ⊢ Group.IsNilpotent G [PROOFSTEP] obtain ⟨n, hn⟩ := h.nilpotent [GOAL] case intro G : Type u_1 inst✝¹ : Group G H : Subgroup G inst✝ : Normal H h : Group.IsNilpotent (G ⧸ center G) n : ℕ hn : upperCentralSeries (G ⧸ center G) n = ⊤ ⊢ Group.IsNilpotent G [PROOFSTEP] use n.succ [GOAL] case h G : Type u_1 inst✝¹ : Group G H : Subgroup G inst✝ : Normal H h : Group.IsNilpotent (G ⧸ center G) n : ℕ hn : upperCentralSeries (G ⧸ center G) n = ⊤ ⊢ upperCentralSeries G (Nat.succ n) = ⊤ [PROOFSTEP] simp [← comap_upperCentralSeries_quotient_center, hn] [GOAL] G✝ : Type u_1 inst✝³ : Group G✝ H : Subgroup G✝ inst✝² : Normal H P : (G : Type u_2) → [inst : Group G] → [inst : Group.IsNilpotent G] → Prop G : Type u_2 inst✝¹ : Group G inst✝ : Group.IsNilpotent G hbase : ∀ (G : Type u_2) [inst : Group G] [inst_1 : Subsingleton G], P G hstep : ∀ (G : Type u_2) [inst : Group G] [inst_1 : Group.IsNilpotent G], P (G ⧸ center G) → P G ⊢ P G [PROOFSTEP] obtain ⟨n, h⟩ : ∃ n, Group.nilpotencyClass G = n := ⟨_, rfl⟩ [GOAL] case intro G✝ : Type u_1 inst✝³ : Group G✝ H : Subgroup G✝ inst✝² : Normal H P : (G : Type u_2) → [inst : Group G] → [inst : Group.IsNilpotent G] → Prop G : Type u_2 inst✝¹ : Group G inst✝ : Group.IsNilpotent G hbase : ∀ (G : Type u_2) [inst : Group G] [inst_1 : Subsingleton G], P G hstep : ∀ (G : Type u_2) [inst : Group G] [inst_1 : Group.IsNilpotent G], P (G ⧸ center G) → P G n : ℕ h : nilpotencyClass G = n ⊢ P G [PROOFSTEP] induction' n with n ih generalizing G [GOAL] case intro.zero G✝¹ : Type u_1 inst✝⁵ : Group G✝¹ H : Subgroup G✝¹ inst✝⁴ : Normal H P : (G : Type u_2) → [inst : Group G] → [inst : Group.IsNilpotent G] → Prop G✝ : Type u_2 inst✝³ : Group G✝ inst✝² : Group.IsNilpotent G✝ hbase : ∀ (G : Type u_2) [inst : Group G] [inst_1 : Subsingleton G], P G hstep : ∀ (G : Type u_2) [inst : Group G] [inst_1 : Group.IsNilpotent G], P (G ⧸ center G) → P G n : ℕ h✝ : nilpotencyClass G✝ = n G : Type u_2 inst✝¹ : Group G inst✝ : Group.IsNilpotent G h : nilpotencyClass G = Nat.zero ⊢ P G [PROOFSTEP] haveI := nilpotencyClass_zero_iff_subsingleton.mp h [GOAL] case intro.zero G✝¹ : Type u_1 inst✝⁵ : Group G✝¹ H : Subgroup G✝¹ inst✝⁴ : Normal H P : (G : Type u_2) → [inst : Group G] → [inst : Group.IsNilpotent G] → Prop G✝ : Type u_2 inst✝³ : Group G✝ inst✝² : Group.IsNilpotent G✝ hbase : ∀ (G : Type u_2) [inst : Group G] [inst_1 : Subsingleton G], P G hstep : ∀ (G : Type u_2) [inst : Group G] [inst_1 : Group.IsNilpotent G], P (G ⧸ center G) → P G n : ℕ h✝ : nilpotencyClass G✝ = n G : Type u_2 inst✝¹ : Group G inst✝ : Group.IsNilpotent G h : nilpotencyClass G = Nat.zero this : Subsingleton G ⊢ P G [PROOFSTEP] exact hbase _ [GOAL] case intro.succ G✝¹ : Type u_1 inst✝⁵ : Group G✝¹ H : Subgroup G✝¹ inst✝⁴ : Normal H P : (G : Type u_2) → [inst : Group G] → [inst : Group.IsNilpotent G] → Prop G✝ : Type u_2 inst✝³ : Group G✝ inst✝² : Group.IsNilpotent G✝ hbase : ∀ (G : Type u_2) [inst : Group G] [inst_1 : Subsingleton G], P G hstep : ∀ (G : Type u_2) [inst : Group G] [inst_1 : Group.IsNilpotent G], P (G ⧸ center G) → P G n✝ : ℕ h✝ : nilpotencyClass G✝ = n✝ n : ℕ ih : ∀ (G : Type u_2) [inst : Group G] [inst_1 : Group.IsNilpotent G], nilpotencyClass G = n → P G G : Type u_2 inst✝¹ : Group G inst✝ : Group.IsNilpotent G h : nilpotencyClass G = Nat.succ n ⊢ P G [PROOFSTEP] have hn : Group.nilpotencyClass (G ⧸ center G) = n := by simp [nilpotencyClass_quotient_center, h] [GOAL] G✝¹ : Type u_1 inst✝⁵ : Group G✝¹ H : Subgroup G✝¹ inst✝⁴ : Normal H P : (G : Type u_2) → [inst : Group G] → [inst : Group.IsNilpotent G] → Prop G✝ : Type u_2 inst✝³ : Group G✝ inst✝² : Group.IsNilpotent G✝ hbase : ∀ (G : Type u_2) [inst : Group G] [inst_1 : Subsingleton G], P G hstep : ∀ (G : Type u_2) [inst : Group G] [inst_1 : Group.IsNilpotent G], P (G ⧸ center G) → P G n✝ : ℕ h✝ : nilpotencyClass G✝ = n✝ n : ℕ ih : ∀ (G : Type u_2) [inst : Group G] [inst_1 : Group.IsNilpotent G], nilpotencyClass G = n → P G G : Type u_2 inst✝¹ : Group G inst✝ : Group.IsNilpotent G h : nilpotencyClass G = Nat.succ n ⊢ nilpotencyClass (G ⧸ center G) = n [PROOFSTEP] simp [nilpotencyClass_quotient_center, h] [GOAL] case intro.succ G✝¹ : Type u_1 inst✝⁵ : Group G✝¹ H : Subgroup G✝¹ inst✝⁴ : Normal H P : (G : Type u_2) → [inst : Group G] → [inst : Group.IsNilpotent G] → Prop G✝ : Type u_2 inst✝³ : Group G✝ inst✝² : Group.IsNilpotent G✝ hbase : ∀ (G : Type u_2) [inst : Group G] [inst_1 : Subsingleton G], P G hstep : ∀ (G : Type u_2) [inst : Group G] [inst_1 : Group.IsNilpotent G], P (G ⧸ center G) → P G n✝ : ℕ h✝ : nilpotencyClass G✝ = n✝ n : ℕ ih : ∀ (G : Type u_2) [inst : Group G] [inst_1 : Group.IsNilpotent G], nilpotencyClass G = n → P G G : Type u_2 inst✝¹ : Group G inst✝ : Group.IsNilpotent G h : nilpotencyClass G = Nat.succ n hn : nilpotencyClass (G ⧸ center G) = n ⊢ P G [PROOFSTEP] exact hstep _ (ih _ hn) [GOAL] G : Type u_1 inst✝¹ : Group G H : Subgroup G inst✝ : Normal H n : ℕ ⊢ derivedSeries G n ≤ lowerCentralSeries G n [PROOFSTEP] induction' n with i ih [GOAL] case zero G : Type u_1 inst✝¹ : Group G H : Subgroup G inst✝ : Normal H ⊢ derivedSeries G Nat.zero ≤ lowerCentralSeries G Nat.zero [PROOFSTEP] simp [GOAL] case succ G : Type u_1 inst✝¹ : Group G H : Subgroup G inst✝ : Normal H i : ℕ ih : derivedSeries G i ≤ lowerCentralSeries G i ⊢ derivedSeries G (Nat.succ i) ≤ lowerCentralSeries G (Nat.succ i) [PROOFSTEP] apply commutator_mono ih [GOAL] case succ G : Type u_1 inst✝¹ : Group G H : Subgroup G inst✝ : Normal H i : ℕ ih : derivedSeries G i ≤ lowerCentralSeries G i ⊢ derivedSeries G i ≤ ⊤ [PROOFSTEP] simp [GOAL] G✝ : Type u_1 inst✝² : Group G✝ H : Subgroup G✝ inst✝¹ : Normal H G : Type u_2 inst✝ : CommGroup G ⊢ Group.IsNilpotent G [PROOFSTEP] use 1 [GOAL] case h G✝ : Type u_1 inst✝² : Group G✝ H : Subgroup G✝ inst✝¹ : Normal H G : Type u_2 inst✝ : CommGroup G ⊢ upperCentralSeries G 1 = ⊤ [PROOFSTEP] rw [upperCentralSeries_one] [GOAL] case h G✝ : Type u_1 inst✝² : Group G✝ H : Subgroup G✝ inst✝¹ : Normal H G : Type u_2 inst✝ : CommGroup G ⊢ center G = ⊤ [PROOFSTEP] apply CommGroup.center_eq_top [GOAL] G✝ : Type u_1 inst✝² : Group G✝ H : Subgroup G✝ inst✝¹ : Normal H G : Type u_2 inst✝ : CommGroup G ⊢ nilpotencyClass G ≤ 1 [PROOFSTEP] apply upperCentralSeries_eq_top_iff_nilpotencyClass_le.mp [GOAL] G✝ : Type u_1 inst✝² : Group G✝ H : Subgroup G✝ inst✝¹ : Normal H G : Type u_2 inst✝ : CommGroup G ⊢ upperCentralSeries G 1 = ⊤ [PROOFSTEP] rw [upperCentralSeries_one] [GOAL] G✝ : Type u_1 inst✝² : Group G✝ H : Subgroup G✝ inst✝¹ : Normal H G : Type u_2 inst✝ : CommGroup G ⊢ center G = ⊤ [PROOFSTEP] apply CommGroup.center_eq_top [GOAL] G : Type u_1 inst✝² : Group G H : Subgroup G inst✝¹ : Normal H inst✝ : Group.IsNilpotent G h : nilpotencyClass G ≤ 1 ⊢ center G = ⊤ [PROOFSTEP] rw [← upperCentralSeries_one] [GOAL] G : Type u_1 inst✝² : Group G H : Subgroup G inst✝¹ : Normal H inst✝ : Group.IsNilpotent G h : nilpotencyClass G ≤ 1 ⊢ upperCentralSeries G 1 = ⊤ [PROOFSTEP] exact upperCentralSeries_eq_top_iff_nilpotencyClass_le.mpr h [GOAL] G : Type u_1 inst✝³ : Group G H : Subgroup G inst✝² : Normal H G₁ : Type u_2 G₂ : Type u_3 inst✝¹ : Group G₁ inst✝ : Group G₂ n : ℕ ⊢ lowerCentralSeries (G₁ × G₂) n = prod (lowerCentralSeries G₁ n) (lowerCentralSeries G₂ n) [PROOFSTEP] induction' n with n ih [GOAL] case zero G : Type u_1 inst✝³ : Group G H : Subgroup G inst✝² : Normal H G₁ : Type u_2 G₂ : Type u_3 inst✝¹ : Group G₁ inst✝ : Group G₂ ⊢ lowerCentralSeries (G₁ × G₂) Nat.zero = prod (lowerCentralSeries G₁ Nat.zero) (lowerCentralSeries G₂ Nat.zero) [PROOFSTEP] simp [GOAL] case succ G : Type u_1 inst✝³ : Group G H : Subgroup G inst✝² : Normal H G₁ : Type u_2 G₂ : Type u_3 inst✝¹ : Group G₁ inst✝ : Group G₂ n : ℕ ih : lowerCentralSeries (G₁ × G₂) n = prod (lowerCentralSeries G₁ n) (lowerCentralSeries G₂ n) ⊢ lowerCentralSeries (G₁ × G₂) (Nat.succ n) = prod (lowerCentralSeries G₁ (Nat.succ n)) (lowerCentralSeries G₂ (Nat.succ n)) [PROOFSTEP] calc lowerCentralSeries (G₁ × G₂) n.succ = ⁅lowerCentralSeries (G₁ × G₂) n, ⊤⁆ := rfl _ = ⁅(lowerCentralSeries G₁ n).prod (lowerCentralSeries G₂ n), ⊤⁆ := by rw [ih] _ = ⁅(lowerCentralSeries G₁ n).prod (lowerCentralSeries G₂ n), (⊤ : Subgroup G₁).prod ⊤⁆ := by simp _ = ⁅lowerCentralSeries G₁ n, (⊤ : Subgroup G₁)⁆.prod ⁅lowerCentralSeries G₂ n, ⊤⁆ := (commutator_prod_prod _ _ _ _) _ = (lowerCentralSeries G₁ n.succ).prod (lowerCentralSeries G₂ n.succ) := rfl [GOAL] G : Type u_1 inst✝³ : Group G H : Subgroup G inst✝² : Normal H G₁ : Type u_2 G₂ : Type u_3 inst✝¹ : Group G₁ inst✝ : Group G₂ n : ℕ ih : lowerCentralSeries (G₁ × G₂) n = prod (lowerCentralSeries G₁ n) (lowerCentralSeries G₂ n) ⊢ ⁅lowerCentralSeries (G₁ × G₂) n, ⊤⁆ = ⁅prod (lowerCentralSeries G₁ n) (lowerCentralSeries G₂ n), ⊤⁆ [PROOFSTEP] rw [ih] [GOAL] G : Type u_1 inst✝³ : Group G H : Subgroup G inst✝² : Normal H G₁ : Type u_2 G₂ : Type u_3 inst✝¹ : Group G₁ inst✝ : Group G₂ n : ℕ ih : lowerCentralSeries (G₁ × G₂) n = prod (lowerCentralSeries G₁ n) (lowerCentralSeries G₂ n) ⊢ ⁅prod (lowerCentralSeries G₁ n) (lowerCentralSeries G₂ n), ⊤⁆ = ⁅prod (lowerCentralSeries G₁ n) (lowerCentralSeries G₂ n), prod ⊤ ⊤⁆ [PROOFSTEP] simp [GOAL] G : Type u_1 inst✝⁵ : Group G H : Subgroup G inst✝⁴ : Normal H G₁ : Type u_2 G₂ : Type u_3 inst✝³ : Group G₁ inst✝² : Group G₂ inst✝¹ : Group.IsNilpotent G₁ inst✝ : Group.IsNilpotent G₂ ⊢ Group.IsNilpotent (G₁ × G₂) [PROOFSTEP] rw [nilpotent_iff_lowerCentralSeries] [GOAL] G : Type u_1 inst✝⁵ : Group G H : Subgroup G inst✝⁴ : Normal H G₁ : Type u_2 G₂ : Type u_3 inst✝³ : Group G₁ inst✝² : Group G₂ inst✝¹ : Group.IsNilpotent G₁ inst✝ : Group.IsNilpotent G₂ ⊢ ∃ n, lowerCentralSeries (G₁ × G₂) n = ⊥ [PROOFSTEP] refine' ⟨max (Group.nilpotencyClass G₁) (Group.nilpotencyClass G₂), _⟩ [GOAL] G : Type u_1 inst✝⁵ : Group G H : Subgroup G inst✝⁴ : Normal H G₁ : Type u_2 G₂ : Type u_3 inst✝³ : Group G₁ inst✝² : Group G₂ inst✝¹ : Group.IsNilpotent G₁ inst✝ : Group.IsNilpotent G₂ ⊢ lowerCentralSeries (G₁ × G₂) (max (nilpotencyClass G₁) (nilpotencyClass G₂)) = ⊥ [PROOFSTEP] rw [lowerCentralSeries_prod, lowerCentralSeries_eq_bot_iff_nilpotencyClass_le.mpr (le_max_left _ _), lowerCentralSeries_eq_bot_iff_nilpotencyClass_le.mpr (le_max_right _ _), bot_prod_bot] [GOAL] G : Type u_1 inst✝⁵ : Group G H : Subgroup G inst✝⁴ : Normal H G₁ : Type u_2 G₂ : Type u_3 inst✝³ : Group G₁ inst✝² : Group G₂ inst✝¹ : Group.IsNilpotent G₁ inst✝ : Group.IsNilpotent G₂ ⊢ nilpotencyClass (G₁ × G₂) = max (nilpotencyClass G₁) (nilpotencyClass G₂) [PROOFSTEP] refine' eq_of_forall_ge_iff fun k => _ [GOAL] G : Type u_1 inst✝⁵ : Group G H : Subgroup G inst✝⁴ : Normal H G₁ : Type u_2 G₂ : Type u_3 inst✝³ : Group G₁ inst✝² : Group G₂ inst✝¹ : Group.IsNilpotent G₁ inst✝ : Group.IsNilpotent G₂ k : ℕ ⊢ nilpotencyClass (G₁ × G₂) ≤ k ↔ max (nilpotencyClass G₁) (nilpotencyClass G₂) ≤ k [PROOFSTEP] simp only [max_le_iff, ← lowerCentralSeries_eq_bot_iff_nilpotencyClass_le, lowerCentralSeries_prod, prod_eq_bot_iff] [GOAL] G : Type u_1 inst✝² : Group G H : Subgroup G inst✝¹ : Normal H η : Type u_2 Gs : η → Type u_3 inst✝ : (i : η) → Group (Gs i) n : ℕ ⊢ lowerCentralSeries ((i : η) → Gs i) n ≤ pi Set.univ fun i => lowerCentralSeries (Gs i) n [PROOFSTEP] let pi := fun f : ∀ i, Subgroup (Gs i) => Subgroup.pi Set.univ f [GOAL] G : Type u_1 inst✝² : Group G H : Subgroup G inst✝¹ : Normal H η : Type u_2 Gs : η → Type u_3 inst✝ : (i : η) → Group (Gs i) n : ℕ pi : ((i : η) → Subgroup (Gs i)) → Subgroup ((i : η) → Gs i) := fun f => Subgroup.pi Set.univ f ⊢ lowerCentralSeries ((i : η) → Gs i) n ≤ Subgroup.pi Set.univ fun i => lowerCentralSeries (Gs i) n [PROOFSTEP] induction' n with n ih [GOAL] case zero G : Type u_1 inst✝² : Group G H : Subgroup G inst✝¹ : Normal H η : Type u_2 Gs : η → Type u_3 inst✝ : (i : η) → Group (Gs i) pi : ((i : η) → Subgroup (Gs i)) → Subgroup ((i : η) → Gs i) := fun f => Subgroup.pi Set.univ f ⊢ lowerCentralSeries ((i : η) → Gs i) Nat.zero ≤ Subgroup.pi Set.univ fun i => lowerCentralSeries (Gs i) Nat.zero [PROOFSTEP] simp [pi_top] [GOAL] case succ G : Type u_1 inst✝² : Group G H : Subgroup G inst✝¹ : Normal H η : Type u_2 Gs : η → Type u_3 inst✝ : (i : η) → Group (Gs i) pi : ((i : η) → Subgroup (Gs i)) → Subgroup ((i : η) → Gs i) := fun f => Subgroup.pi Set.univ f n : ℕ ih : lowerCentralSeries ((i : η) → Gs i) n ≤ Subgroup.pi Set.univ fun i => lowerCentralSeries (Gs i) n ⊢ lowerCentralSeries ((i : η) → Gs i) (Nat.succ n) ≤ Subgroup.pi Set.univ fun i => lowerCentralSeries (Gs i) (Nat.succ n) [PROOFSTEP] calc lowerCentralSeries (∀ i, Gs i) n.succ = ⁅lowerCentralSeries (∀ i, Gs i) n, ⊤⁆ := rfl _ ≤ ⁅pi fun i => lowerCentralSeries (Gs i) n, ⊤⁆ := (commutator_mono ih (le_refl _)) _ = ⁅pi fun i => lowerCentralSeries (Gs i) n, pi fun i => ⊤⁆ := by simp [pi_top] _ ≤ pi fun i => ⁅lowerCentralSeries (Gs i) n, ⊤⁆ := (commutator_pi_pi_le _ _) _ = pi fun i => lowerCentralSeries (Gs i) n.succ := rfl [GOAL] G : Type u_1 inst✝² : Group G H : Subgroup G inst✝¹ : Normal H η : Type u_2 Gs : η → Type u_3 inst✝ : (i : η) → Group (Gs i) pi : ((i : η) → Subgroup (Gs i)) → Subgroup ((i : η) → Gs i) := fun f => Subgroup.pi Set.univ f n : ℕ ih : lowerCentralSeries ((i : η) → Gs i) n ≤ Subgroup.pi Set.univ fun i => lowerCentralSeries (Gs i) n ⊢ ⁅pi fun i => lowerCentralSeries (Gs i) n, ⊤⁆ = ⁅pi fun i => lowerCentralSeries (Gs i) n, pi fun i => ⊤⁆ [PROOFSTEP] simp [pi_top] [GOAL] G : Type u_1 inst✝³ : Group G H : Subgroup G inst✝² : Normal H η : Type u_2 Gs : η → Type u_3 inst✝¹ : (i : η) → Group (Gs i) inst✝ : ∀ (i : η), Group.IsNilpotent (Gs i) n : ℕ h : ∀ (i : η), nilpotencyClass (Gs i) ≤ n ⊢ Group.IsNilpotent ((i : η) → Gs i) [PROOFSTEP] rw [nilpotent_iff_lowerCentralSeries] [GOAL] G : Type u_1 inst✝³ : Group G H : Subgroup G inst✝² : Normal H η : Type u_2 Gs : η → Type u_3 inst✝¹ : (i : η) → Group (Gs i) inst✝ : ∀ (i : η), Group.IsNilpotent (Gs i) n : ℕ h : ∀ (i : η), nilpotencyClass (Gs i) ≤ n ⊢ ∃ n, lowerCentralSeries ((i : η) → Gs i) n = ⊥ [PROOFSTEP] refine' ⟨n, _⟩ [GOAL] G : Type u_1 inst✝³ : Group G H : Subgroup G inst✝² : Normal H η : Type u_2 Gs : η → Type u_3 inst✝¹ : (i : η) → Group (Gs i) inst✝ : ∀ (i : η), Group.IsNilpotent (Gs i) n : ℕ h : ∀ (i : η), nilpotencyClass (Gs i) ≤ n ⊢ lowerCentralSeries ((i : η) → Gs i) n = ⊥ [PROOFSTEP] rw [eq_bot_iff] [GOAL] G : Type u_1 inst✝³ : Group G H : Subgroup G inst✝² : Normal H η : Type u_2 Gs : η → Type u_3 inst✝¹ : (i : η) → Group (Gs i) inst✝ : ∀ (i : η), Group.IsNilpotent (Gs i) n : ℕ h : ∀ (i : η), nilpotencyClass (Gs i) ≤ n ⊢ lowerCentralSeries ((i : η) → Gs i) n ≤ ⊥ [PROOFSTEP] apply le_trans (lowerCentralSeries_pi_le _) [GOAL] G : Type u_1 inst✝³ : Group G H : Subgroup G inst✝² : Normal H η : Type u_2 Gs : η → Type u_3 inst✝¹ : (i : η) → Group (Gs i) inst✝ : ∀ (i : η), Group.IsNilpotent (Gs i) n : ℕ h : ∀ (i : η), nilpotencyClass (Gs i) ≤ n ⊢ (pi Set.univ fun i => lowerCentralSeries (Gs i) n) ≤ ⊥ [PROOFSTEP] rw [← eq_bot_iff, pi_eq_bot_iff] [GOAL] G : Type u_1 inst✝³ : Group G H : Subgroup G inst✝² : Normal H η : Type u_2 Gs : η → Type u_3 inst✝¹ : (i : η) → Group (Gs i) inst✝ : ∀ (i : η), Group.IsNilpotent (Gs i) n : ℕ h : ∀ (i : η), nilpotencyClass (Gs i) ≤ n ⊢ ∀ (i : η), lowerCentralSeries (Gs i) n = ⊥ [PROOFSTEP] intro i [GOAL] G : Type u_1 inst✝³ : Group G H : Subgroup G inst✝² : Normal H η : Type u_2 Gs : η → Type u_3 inst✝¹ : (i : η) → Group (Gs i) inst✝ : ∀ (i : η), Group.IsNilpotent (Gs i) n : ℕ h : ∀ (i : η), nilpotencyClass (Gs i) ≤ n i : η ⊢ lowerCentralSeries (Gs i) n = ⊥ [PROOFSTEP] apply lowerCentralSeries_eq_bot_iff_nilpotencyClass_le.mpr (h i) [GOAL] G : Type u_1 inst✝³ : Group G H : Subgroup G inst✝² : Normal H η : Type u_2 Gs : η → Type u_3 inst✝¹ : (i : η) → Group (Gs i) inst✝ : Finite η n : ℕ ⊢ lowerCentralSeries ((i : η) → Gs i) n = pi Set.univ fun i => lowerCentralSeries (Gs i) n [PROOFSTEP] let pi := fun f : ∀ i, Subgroup (Gs i) => Subgroup.pi Set.univ f [GOAL] G : Type u_1 inst✝³ : Group G H : Subgroup G inst✝² : Normal H η : Type u_2 Gs : η → Type u_3 inst✝¹ : (i : η) → Group (Gs i) inst✝ : Finite η n : ℕ pi : ((i : η) → Subgroup (Gs i)) → Subgroup ((i : η) → Gs i) := fun f => Subgroup.pi Set.univ f ⊢ lowerCentralSeries ((i : η) → Gs i) n = Subgroup.pi Set.univ fun i => lowerCentralSeries (Gs i) n [PROOFSTEP] induction' n with n ih [GOAL] case zero G : Type u_1 inst✝³ : Group G H : Subgroup G inst✝² : Normal H η : Type u_2 Gs : η → Type u_3 inst✝¹ : (i : η) → Group (Gs i) inst✝ : Finite η pi : ((i : η) → Subgroup (Gs i)) → Subgroup ((i : η) → Gs i) := fun f => Subgroup.pi Set.univ f ⊢ lowerCentralSeries ((i : η) → Gs i) Nat.zero = Subgroup.pi Set.univ fun i => lowerCentralSeries (Gs i) Nat.zero [PROOFSTEP] simp [pi_top] [GOAL] case succ G : Type u_1 inst✝³ : Group G H : Subgroup G inst✝² : Normal H η : Type u_2 Gs : η → Type u_3 inst✝¹ : (i : η) → Group (Gs i) inst✝ : Finite η pi : ((i : η) → Subgroup (Gs i)) → Subgroup ((i : η) → Gs i) := fun f => Subgroup.pi Set.univ f n : ℕ ih : lowerCentralSeries ((i : η) → Gs i) n = Subgroup.pi Set.univ fun i => lowerCentralSeries (Gs i) n ⊢ lowerCentralSeries ((i : η) → Gs i) (Nat.succ n) = Subgroup.pi Set.univ fun i => lowerCentralSeries (Gs i) (Nat.succ n) [PROOFSTEP] calc lowerCentralSeries (∀ i, Gs i) n.succ = ⁅lowerCentralSeries (∀ i, Gs i) n, ⊤⁆ := rfl _ = ⁅pi fun i => lowerCentralSeries (Gs i) n, ⊤⁆ := by rw [ih] _ = ⁅pi fun i => lowerCentralSeries (Gs i) n, pi fun i => ⊤⁆ := by simp [pi_top] _ = pi fun i => ⁅lowerCentralSeries (Gs i) n, ⊤⁆ := (commutator_pi_pi_of_finite _ _) _ = pi fun i => lowerCentralSeries (Gs i) n.succ := rfl [GOAL] G : Type u_1 inst✝³ : Group G H : Subgroup G inst✝² : Normal H η : Type u_2 Gs : η → Type u_3 inst✝¹ : (i : η) → Group (Gs i) inst✝ : Finite η pi : ((i : η) → Subgroup (Gs i)) → Subgroup ((i : η) → Gs i) := fun f => Subgroup.pi Set.univ f n : ℕ ih : lowerCentralSeries ((i : η) → Gs i) n = Subgroup.pi Set.univ fun i => lowerCentralSeries (Gs i) n ⊢ ⁅lowerCentralSeries ((i : η) → Gs i) n, ⊤⁆ = ⁅pi fun i => lowerCentralSeries (Gs i) n, ⊤⁆ [PROOFSTEP] rw [ih] [GOAL] G : Type u_1 inst✝³ : Group G H : Subgroup G inst✝² : Normal H η : Type u_2 Gs : η → Type u_3 inst✝¹ : (i : η) → Group (Gs i) inst✝ : Finite η pi : ((i : η) → Subgroup (Gs i)) → Subgroup ((i : η) → Gs i) := fun f => Subgroup.pi Set.univ f n : ℕ ih : lowerCentralSeries ((i : η) → Gs i) n = Subgroup.pi Set.univ fun i => lowerCentralSeries (Gs i) n ⊢ ⁅pi fun i => lowerCentralSeries (Gs i) n, ⊤⁆ = ⁅pi fun i => lowerCentralSeries (Gs i) n, pi fun i => ⊤⁆ [PROOFSTEP] simp [pi_top] [GOAL] G : Type u_1 inst✝⁴ : Group G H : Subgroup G inst✝³ : Normal H η : Type u_2 Gs : η → Type u_3 inst✝² : (i : η) → Group (Gs i) inst✝¹ : Finite η inst✝ : ∀ (i : η), Group.IsNilpotent (Gs i) ⊢ Group.IsNilpotent ((i : η) → Gs i) [PROOFSTEP] cases nonempty_fintype η [GOAL] case intro G : Type u_1 inst✝⁴ : Group G H : Subgroup G inst✝³ : Normal H η : Type u_2 Gs : η → Type u_3 inst✝² : (i : η) → Group (Gs i) inst✝¹ : Finite η inst✝ : ∀ (i : η), Group.IsNilpotent (Gs i) val✝ : Fintype η ⊢ Group.IsNilpotent ((i : η) → Gs i) [PROOFSTEP] rw [nilpotent_iff_lowerCentralSeries] [GOAL] case intro G : Type u_1 inst✝⁴ : Group G H : Subgroup G inst✝³ : Normal H η : Type u_2 Gs : η → Type u_3 inst✝² : (i : η) → Group (Gs i) inst✝¹ : Finite η inst✝ : ∀ (i : η), Group.IsNilpotent (Gs i) val✝ : Fintype η ⊢ ∃ n, lowerCentralSeries ((i : η) → Gs i) n = ⊥ [PROOFSTEP] refine' ⟨Finset.univ.sup fun i => Group.nilpotencyClass (Gs i), _⟩ [GOAL] case intro G : Type u_1 inst✝⁴ : Group G H : Subgroup G inst✝³ : Normal H η : Type u_2 Gs : η → Type u_3 inst✝² : (i : η) → Group (Gs i) inst✝¹ : Finite η inst✝ : ∀ (i : η), Group.IsNilpotent (Gs i) val✝ : Fintype η ⊢ lowerCentralSeries ((i : η) → Gs i) (Finset.sup Finset.univ fun i => nilpotencyClass (Gs i)) = ⊥ [PROOFSTEP] rw [lowerCentralSeries_pi_of_finite, pi_eq_bot_iff] [GOAL] case intro G : Type u_1 inst✝⁴ : Group G H : Subgroup G inst✝³ : Normal H η : Type u_2 Gs : η → Type u_3 inst✝² : (i : η) → Group (Gs i) inst✝¹ : Finite η inst✝ : ∀ (i : η), Group.IsNilpotent (Gs i) val✝ : Fintype η ⊢ ∀ (i : η), lowerCentralSeries (Gs i) (Finset.sup Finset.univ fun i => nilpotencyClass (Gs i)) = ⊥ [PROOFSTEP] intro i [GOAL] case intro G : Type u_1 inst✝⁴ : Group G H : Subgroup G inst✝³ : Normal H η : Type u_2 Gs : η → Type u_3 inst✝² : (i : η) → Group (Gs i) inst✝¹ : Finite η inst✝ : ∀ (i : η), Group.IsNilpotent (Gs i) val✝ : Fintype η i : η ⊢ lowerCentralSeries (Gs i) (Finset.sup Finset.univ fun i => nilpotencyClass (Gs i)) = ⊥ [PROOFSTEP] apply lowerCentralSeries_eq_bot_iff_nilpotencyClass_le.mpr [GOAL] case intro G : Type u_1 inst✝⁴ : Group G H : Subgroup G inst✝³ : Normal H η : Type u_2 Gs : η → Type u_3 inst✝² : (i : η) → Group (Gs i) inst✝¹ : Finite η inst✝ : ∀ (i : η), Group.IsNilpotent (Gs i) val✝ : Fintype η i : η ⊢ nilpotencyClass (Gs i) ≤ Finset.sup Finset.univ fun i => nilpotencyClass (Gs i) [PROOFSTEP] exact @Finset.le_sup _ _ _ _ Finset.univ (fun i => Group.nilpotencyClass (Gs i)) _ (Finset.mem_univ i) [GOAL] G : Type u_1 inst✝⁴ : Group G H : Subgroup G inst✝³ : Normal H η : Type u_2 Gs : η → Type u_3 inst✝² : (i : η) → Group (Gs i) inst✝¹ : Fintype η inst✝ : ∀ (i : η), Group.IsNilpotent (Gs i) ⊢ nilpotencyClass ((i : η) → Gs i) = Finset.sup Finset.univ fun i => nilpotencyClass (Gs i) [PROOFSTEP] apply eq_of_forall_ge_iff [GOAL] case H G : Type u_1 inst✝⁴ : Group G H : Subgroup G inst✝³ : Normal H η : Type u_2 Gs : η → Type u_3 inst✝² : (i : η) → Group (Gs i) inst✝¹ : Fintype η inst✝ : ∀ (i : η), Group.IsNilpotent (Gs i) ⊢ ∀ (c : ℕ), nilpotencyClass ((i : η) → Gs i) ≤ c ↔ (Finset.sup Finset.univ fun i => nilpotencyClass (Gs i)) ≤ c [PROOFSTEP] intro k [GOAL] case H G : Type u_1 inst✝⁴ : Group G H : Subgroup G inst✝³ : Normal H η : Type u_2 Gs : η → Type u_3 inst✝² : (i : η) → Group (Gs i) inst✝¹ : Fintype η inst✝ : ∀ (i : η), Group.IsNilpotent (Gs i) k : ℕ ⊢ nilpotencyClass ((i : η) → Gs i) ≤ k ↔ (Finset.sup Finset.univ fun i => nilpotencyClass (Gs i)) ≤ k [PROOFSTEP] simp only [Finset.sup_le_iff, ← lowerCentralSeries_eq_bot_iff_nilpotencyClass_le, lowerCentralSeries_pi_of_finite, pi_eq_bot_iff, Finset.mem_univ, true_imp_iff] [GOAL] G : Type u_1 inst✝¹ : Group G H : Subgroup G inst✝ : Normal H h : Group.IsNilpotent G ⊢ IsSolvable G [PROOFSTEP] obtain ⟨n, hn⟩ := nilpotent_iff_lowerCentralSeries.1 h [GOAL] case intro G : Type u_1 inst✝¹ : Group G H : Subgroup G inst✝ : Normal H h : Group.IsNilpotent G n : ℕ hn : lowerCentralSeries G n = ⊥ ⊢ IsSolvable G [PROOFSTEP] use n [GOAL] case h G : Type u_1 inst✝¹ : Group G H : Subgroup G inst✝ : Normal H h : Group.IsNilpotent G n : ℕ hn : lowerCentralSeries G n = ⊥ ⊢ derivedSeries G n = ⊥ [PROOFSTEP] rw [eq_bot_iff, ← hn] [GOAL] case h G : Type u_1 inst✝¹ : Group G H : Subgroup G inst✝ : Normal H h : Group.IsNilpotent G n : ℕ hn : lowerCentralSeries G n = ⊥ ⊢ derivedSeries G n ≤ lowerCentralSeries G n [PROOFSTEP] exact derived_le_lower_central n [GOAL] G : Type u_1 inst✝¹ : Group G H : Subgroup G inst✝ : Normal H h : Group.IsNilpotent G ⊢ NormalizerCondition G [PROOFSTEP] rw [normalizerCondition_iff_only_full_group_self_normalizing] [GOAL] G : Type u_1 inst✝¹ : Group G H : Subgroup G inst✝ : Normal H h : Group.IsNilpotent G ⊢ ∀ (H : Subgroup G), normalizer H = H → H = ⊤ [PROOFSTEP] apply @nilpotent_center_quotient_ind _ G _ _ [GOAL] case hbase G : Type u_1 inst✝¹ : Group G H : Subgroup G inst✝ : Normal H h : Group.IsNilpotent G ⊢ ∀ (G : Type u_1) [inst : Group G] [inst_1 : Subsingleton G] (H : Subgroup G), normalizer H = H → H = ⊤ [PROOFSTEP] clear! G [GOAL] case hstep G : Type u_1 inst✝¹ : Group G H : Subgroup G inst✝ : Normal H h : Group.IsNilpotent G ⊢ ∀ (G : Type u_1) [inst : Group G] [inst_1 : Group.IsNilpotent G], (∀ (H : Subgroup (G ⧸ center G)), normalizer H = H → H = ⊤) → ∀ (H : Subgroup G), normalizer H = H → H = ⊤ [PROOFSTEP] clear! G [GOAL] case hbase ⊢ ∀ (G : Type u_1) [inst : Group G] [inst_1 : Subsingleton G] (H : Subgroup G), normalizer H = H → H = ⊤ [PROOFSTEP] intro G _ _ H _ [GOAL] case hbase G : Type u_1 inst✝¹ : Group G inst✝ : Subsingleton G H : Subgroup G a✝ : normalizer H = H ⊢ H = ⊤ [PROOFSTEP] exact @Subsingleton.elim _ Unique.instSubsingleton _ _ [GOAL] case hstep ⊢ ∀ (G : Type u_1) [inst : Group G] [inst_1 : Group.IsNilpotent G], (∀ (H : Subgroup (G ⧸ center G)), normalizer H = H → H = ⊤) → ∀ (H : Subgroup G), normalizer H = H → H = ⊤ [PROOFSTEP] intro G _ _ ih H hH [GOAL] case hstep G : Type u_1 inst✝¹ : Group G inst✝ : Group.IsNilpotent G ih : ∀ (H : Subgroup (G ⧸ center G)), normalizer H = H → H = ⊤ H : Subgroup G hH : normalizer H = H ⊢ H = ⊤ [PROOFSTEP] have hch : center G ≤ H := Subgroup.center_le_normalizer.trans (le_of_eq hH) [GOAL] case hstep G : Type u_1 inst✝¹ : Group G inst✝ : Group.IsNilpotent G ih : ∀ (H : Subgroup (G ⧸ center G)), normalizer H = H → H = ⊤ H : Subgroup G hH : normalizer H = H hch : center G ≤ H ⊢ H = ⊤ [PROOFSTEP] have hkh : (mk' (center G)).ker ≤ H := by simpa using hch [GOAL] G : Type u_1 inst✝¹ : Group G inst✝ : Group.IsNilpotent G ih : ∀ (H : Subgroup (G ⧸ center G)), normalizer H = H → H = ⊤ H : Subgroup G hH : normalizer H = H hch : center G ≤ H ⊢ MonoidHom.ker (mk' (center G)) ≤ H [PROOFSTEP] simpa using hch [GOAL] case hstep G : Type u_1 inst✝¹ : Group G inst✝ : Group.IsNilpotent G ih : ∀ (H : Subgroup (G ⧸ center G)), normalizer H = H → H = ⊤ H : Subgroup G hH : normalizer H = H hch : center G ≤ H hkh : MonoidHom.ker (mk' (center G)) ≤ H ⊢ H = ⊤ [PROOFSTEP] have hsur : Function.Surjective (mk' (center G)) := surjective_quot_mk _ [GOAL] case hstep G : Type u_1 inst✝¹ : Group G inst✝ : Group.IsNilpotent G ih : ∀ (H : Subgroup (G ⧸ center G)), normalizer H = H → H = ⊤ H : Subgroup G hH : normalizer H = H hch : center G ≤ H hkh : MonoidHom.ker (mk' (center G)) ≤ H hsur : Function.Surjective ↑(mk' (center G)) ⊢ H = ⊤ [PROOFSTEP] let H' := H.map (mk' (center G)) [GOAL] case hstep G : Type u_1 inst✝¹ : Group G inst✝ : Group.IsNilpotent G ih : ∀ (H : Subgroup (G ⧸ center G)), normalizer H = H → H = ⊤ H : Subgroup G hH : normalizer H = H hch : center G ≤ H hkh : MonoidHom.ker (mk' (center G)) ≤ H hsur : Function.Surjective ↑(mk' (center G)) H' : Subgroup (G ⧸ center G) := Subgroup.map (mk' (center G)) H ⊢ H = ⊤ [PROOFSTEP] have hH' : H'.normalizer = H' := by apply comap_injective hsur rw [comap_normalizer_eq_of_surjective _ hsur, comap_map_eq_self hkh] exact hH [GOAL] G : Type u_1 inst✝¹ : Group G inst✝ : Group.IsNilpotent G ih : ∀ (H : Subgroup (G ⧸ center G)), normalizer H = H → H = ⊤ H : Subgroup G hH : normalizer H = H hch : center G ≤ H hkh : MonoidHom.ker (mk' (center G)) ≤ H hsur : Function.Surjective ↑(mk' (center G)) H' : Subgroup (G ⧸ center G) := Subgroup.map (mk' (center G)) H ⊢ normalizer H' = H' [PROOFSTEP] apply comap_injective hsur [GOAL] case a G : Type u_1 inst✝¹ : Group G inst✝ : Group.IsNilpotent G ih : ∀ (H : Subgroup (G ⧸ center G)), normalizer H = H → H = ⊤ H : Subgroup G hH : normalizer H = H hch : center G ≤ H hkh : MonoidHom.ker (mk' (center G)) ≤ H hsur : Function.Surjective ↑(mk' (center G)) H' : Subgroup (G ⧸ center G) := Subgroup.map (mk' (center G)) H ⊢ comap (mk' (center G)) (normalizer H') = comap (mk' (center G)) H' [PROOFSTEP] rw [comap_normalizer_eq_of_surjective _ hsur, comap_map_eq_self hkh] [GOAL] case a G : Type u_1 inst✝¹ : Group G inst✝ : Group.IsNilpotent G ih : ∀ (H : Subgroup (G ⧸ center G)), normalizer H = H → H = ⊤ H : Subgroup G hH : normalizer H = H hch : center G ≤ H hkh : MonoidHom.ker (mk' (center G)) ≤ H hsur : Function.Surjective ↑(mk' (center G)) H' : Subgroup (G ⧸ center G) := Subgroup.map (mk' (center G)) H ⊢ normalizer H = H [PROOFSTEP] exact hH [GOAL] case hstep G : Type u_1 inst✝¹ : Group G inst✝ : Group.IsNilpotent G ih : ∀ (H : Subgroup (G ⧸ center G)), normalizer H = H → H = ⊤ H : Subgroup G hH : normalizer H = H hch : center G ≤ H hkh : MonoidHom.ker (mk' (center G)) ≤ H hsur : Function.Surjective ↑(mk' (center G)) H' : Subgroup (G ⧸ center G) := Subgroup.map (mk' (center G)) H hH' : normalizer H' = H' ⊢ H = ⊤ [PROOFSTEP] apply map_injective_of_ker_le (mk' (center G)) hkh le_top [GOAL] case hstep G : Type u_1 inst✝¹ : Group G inst✝ : Group.IsNilpotent G ih : ∀ (H : Subgroup (G ⧸ center G)), normalizer H = H → H = ⊤ H : Subgroup G hH : normalizer H = H hch : center G ≤ H hkh : MonoidHom.ker (mk' (center G)) ≤ H hsur : Function.Surjective ↑(mk' (center G)) H' : Subgroup (G ⧸ center G) := Subgroup.map (mk' (center G)) H hH' : normalizer H' = H' ⊢ Subgroup.map (mk' (center G)) H = Subgroup.map (mk' (center G)) ⊤ [PROOFSTEP] exact (ih H' hH').trans (symm (map_top_of_surjective _ hsur)) [GOAL] G : Type u_1 hG : Group G inst✝ : Finite G p : ℕ hp : Fact (Nat.Prime p) h : IsPGroup p G ⊢ Group.IsNilpotent G [PROOFSTEP] cases' nonempty_fintype G [GOAL] case intro G : Type u_1 hG : Group G inst✝ : Finite G p : ℕ hp : Fact (Nat.Prime p) h : IsPGroup p G val✝ : Fintype G ⊢ Group.IsNilpotent G [PROOFSTEP] classical revert hG apply @Fintype.induction_subsingleton_or_nontrivial _ G _ · intro _ _ _ _ infer_instance · intro G _ _ ih _ h have hcq : Fintype.card (G ⧸ center G) < Fintype.card G := by rw [card_eq_card_quotient_mul_card_subgroup (center G)] apply lt_mul_of_one_lt_right exact Fintype.card_pos_iff.mpr One.nonempty exact (Subgroup.one_lt_card_iff_ne_bot _).mpr (ne_of_gt h.bot_lt_center) have hnq : IsNilpotent (G ⧸ center G) := ih _ hcq (h.to_quotient (center G)) exact of_quotient_center_nilpotent hnq [GOAL] case intro G : Type u_1 hG : Group G inst✝ : Finite G p : ℕ hp : Fact (Nat.Prime p) h : IsPGroup p G val✝ : Fintype G ⊢ Group.IsNilpotent G [PROOFSTEP] revert hG [GOAL] case intro G : Type u_1 inst✝ : Finite G p : ℕ hp : Fact (Nat.Prime p) val✝ : Fintype G ⊢ ∀ [hG : Group G], IsPGroup p G → Group.IsNilpotent G [PROOFSTEP] apply @Fintype.induction_subsingleton_or_nontrivial _ G _ [GOAL] case intro.hbase G : Type u_1 inst✝ : Finite G p : ℕ hp : Fact (Nat.Prime p) val✝ : Fintype G ⊢ ∀ (α : Type u_1) [inst : Fintype α] [inst : Subsingleton α] [hG : Group α], IsPGroup p α → Group.IsNilpotent α [PROOFSTEP] intro _ _ _ _ [GOAL] case intro.hbase G : Type u_1 inst✝² : Finite G p : ℕ hp : Fact (Nat.Prime p) val✝ : Fintype G α✝ : Type u_1 inst✝¹ : Fintype α✝ inst✝ : Subsingleton α✝ hG✝ : Group α✝ ⊢ IsPGroup p α✝ → Group.IsNilpotent α✝ [PROOFSTEP] infer_instance [GOAL] case intro.hstep G : Type u_1 inst✝ : Finite G p : ℕ hp : Fact (Nat.Prime p) val✝ : Fintype G ⊢ ∀ (α : Type u_1) [inst : Fintype α] [inst_1 : Nontrivial α], (∀ (β : Type u_1) [inst_2 : Fintype β], card β < card α → ∀ [hG : Group β], IsPGroup p β → Group.IsNilpotent β) → ∀ [hG : Group α], IsPGroup p α → Group.IsNilpotent α [PROOFSTEP] intro G _ _ ih _ h [GOAL] case intro.hstep G✝ : Type u_1 inst✝² : Finite G✝ p : ℕ hp : Fact (Nat.Prime p) val✝ : Fintype G✝ G : Type u_1 inst✝¹ : Fintype G inst✝ : Nontrivial G ih : ∀ (β : Type u_1) [inst : Fintype β], card β < card G → ∀ [hG : Group β], IsPGroup p β → Group.IsNilpotent β hG✝ : Group G h : IsPGroup p G ⊢ Group.IsNilpotent G [PROOFSTEP] have hcq : Fintype.card (G ⧸ center G) < Fintype.card G := by rw [card_eq_card_quotient_mul_card_subgroup (center G)] apply lt_mul_of_one_lt_right exact Fintype.card_pos_iff.mpr One.nonempty exact (Subgroup.one_lt_card_iff_ne_bot _).mpr (ne_of_gt h.bot_lt_center) [GOAL] G✝ : Type u_1 inst✝² : Finite G✝ p : ℕ hp : Fact (Nat.Prime p) val✝ : Fintype G✝ G : Type u_1 inst✝¹ : Fintype G inst✝ : Nontrivial G ih : ∀ (β : Type u_1) [inst : Fintype β], card β < card G → ∀ [hG : Group β], IsPGroup p β → Group.IsNilpotent β hG✝ : Group G h : IsPGroup p G ⊢ card (G ⧸ center G) < card G [PROOFSTEP] rw [card_eq_card_quotient_mul_card_subgroup (center G)] [GOAL] G✝ : Type u_1 inst✝² : Finite G✝ p : ℕ hp : Fact (Nat.Prime p) val✝ : Fintype G✝ G : Type u_1 inst✝¹ : Fintype G inst✝ : Nontrivial G ih : ∀ (β : Type u_1) [inst : Fintype β], card β < card G → ∀ [hG : Group β], IsPGroup p β → Group.IsNilpotent β hG✝ : Group G h : IsPGroup p G ⊢ card (G ⧸ center G) < card (G ⧸ center G) * card { x // x ∈ center G } [PROOFSTEP] apply lt_mul_of_one_lt_right [GOAL] case ha G✝ : Type u_1 inst✝² : Finite G✝ p : ℕ hp : Fact (Nat.Prime p) val✝ : Fintype G✝ G : Type u_1 inst✝¹ : Fintype G inst✝ : Nontrivial G ih : ∀ (β : Type u_1) [inst : Fintype β], card β < card G → ∀ [hG : Group β], IsPGroup p β → Group.IsNilpotent β hG✝ : Group G h : IsPGroup p G ⊢ 0 < card (G ⧸ center G) case h G✝ : Type u_1 inst✝² : Finite G✝ p : ℕ hp : Fact (Nat.Prime p) val✝ : Fintype G✝ G : Type u_1 inst✝¹ : Fintype G inst✝ : Nontrivial G ih : ∀ (β : Type u_1) [inst : Fintype β], card β < card G → ∀ [hG : Group β], IsPGroup p β → Group.IsNilpotent β hG✝ : Group G h : IsPGroup p G ⊢ 1 < card { x // x ∈ center G } [PROOFSTEP] exact Fintype.card_pos_iff.mpr One.nonempty [GOAL] case h G✝ : Type u_1 inst✝² : Finite G✝ p : ℕ hp : Fact (Nat.Prime p) val✝ : Fintype G✝ G : Type u_1 inst✝¹ : Fintype G inst✝ : Nontrivial G ih : ∀ (β : Type u_1) [inst : Fintype β], card β < card G → ∀ [hG : Group β], IsPGroup p β → Group.IsNilpotent β hG✝ : Group G h : IsPGroup p G ⊢ 1 < card { x // x ∈ center G } [PROOFSTEP] exact (Subgroup.one_lt_card_iff_ne_bot _).mpr (ne_of_gt h.bot_lt_center) [GOAL] case intro.hstep G✝ : Type u_1 inst✝² : Finite G✝ p : ℕ hp : Fact (Nat.Prime p) val✝ : Fintype G✝ G : Type u_1 inst✝¹ : Fintype G inst✝ : Nontrivial G ih : ∀ (β : Type u_1) [inst : Fintype β], card β < card G → ∀ [hG : Group β], IsPGroup p β → Group.IsNilpotent β hG✝ : Group G h : IsPGroup p G hcq : card (G ⧸ center G) < card G ⊢ Group.IsNilpotent G [PROOFSTEP] have hnq : IsNilpotent (G ⧸ center G) := ih _ hcq (h.to_quotient (center G)) [GOAL] case intro.hstep G✝ : Type u_1 inst✝² : Finite G✝ p : ℕ hp : Fact (Nat.Prime p) val✝ : Fintype G✝ G : Type u_1 inst✝¹ : Fintype G inst✝ : Nontrivial G ih : ∀ (β : Type u_1) [inst : Fintype β], card β < card G → ∀ [hG : Group β], IsPGroup p β → Group.IsNilpotent β hG✝ : Group G h : IsPGroup p G hcq : card (G ⧸ center G) < card G hnq : Group.IsNilpotent (G ⧸ center G) ⊢ Group.IsNilpotent G [PROOFSTEP] exact of_quotient_center_nilpotent hnq [GOAL] G : Type u_1 hG : Group G inst✝ : Fintype G e : ((p : { x // x ∈ (Nat.factorization (card G)).support }) → (P : Sylow (↑p) G) → { x // x ∈ ↑P }) ≃* G ⊢ Group.IsNilpotent G [PROOFSTEP] classical let ps := (Fintype.card G).factorization.support have : ∀ (p : ps) (P : Sylow p G), IsNilpotent (↑P : Subgroup G) := by intro p P haveI : Fact (Nat.Prime ↑p) := Fact.mk (Nat.prime_of_mem_factorization (Finset.coe_mem p)) exact P.isPGroup'.isNilpotent exact nilpotent_of_mulEquiv e [GOAL] G : Type u_1 hG : Group G inst✝ : Fintype G e : ((p : { x // x ∈ (Nat.factorization (card G)).support }) → (P : Sylow (↑p) G) → { x // x ∈ ↑P }) ≃* G ⊢ Group.IsNilpotent G [PROOFSTEP] let ps := (Fintype.card G).factorization.support [GOAL] G : Type u_1 hG : Group G inst✝ : Fintype G e : ((p : { x // x ∈ (Nat.factorization (card G)).support }) → (P : Sylow (↑p) G) → { x // x ∈ ↑P }) ≃* G ps : Finset ℕ := (Nat.factorization (card G)).support ⊢ Group.IsNilpotent G [PROOFSTEP] have : ∀ (p : ps) (P : Sylow p G), IsNilpotent (↑P : Subgroup G) := by intro p P haveI : Fact (Nat.Prime ↑p) := Fact.mk (Nat.prime_of_mem_factorization (Finset.coe_mem p)) exact P.isPGroup'.isNilpotent [GOAL] G : Type u_1 hG : Group G inst✝ : Fintype G e : ((p : { x // x ∈ (Nat.factorization (card G)).support }) → (P : Sylow (↑p) G) → { x // x ∈ ↑P }) ≃* G ps : Finset ℕ := (Nat.factorization (card G)).support ⊢ ∀ (p : { x // x ∈ ps }) (P : Sylow (↑p) G), Group.IsNilpotent { x // x ∈ ↑P } [PROOFSTEP] intro p P [GOAL] G : Type u_1 hG : Group G inst✝ : Fintype G e : ((p : { x // x ∈ (Nat.factorization (card G)).support }) → (P : Sylow (↑p) G) → { x // x ∈ ↑P }) ≃* G ps : Finset ℕ := (Nat.factorization (card G)).support p : { x // x ∈ ps } P : Sylow (↑p) G ⊢ Group.IsNilpotent { x // x ∈ ↑P } [PROOFSTEP] haveI : Fact (Nat.Prime ↑p) := Fact.mk (Nat.prime_of_mem_factorization (Finset.coe_mem p)) [GOAL] G : Type u_1 hG : Group G inst✝ : Fintype G e : ((p : { x // x ∈ (Nat.factorization (card G)).support }) → (P : Sylow (↑p) G) → { x // x ∈ ↑P }) ≃* G ps : Finset ℕ := (Nat.factorization (card G)).support p : { x // x ∈ ps } P : Sylow (↑p) G this : Fact (Nat.Prime ↑p) ⊢ Group.IsNilpotent { x // x ∈ ↑P } [PROOFSTEP] exact P.isPGroup'.isNilpotent [GOAL] G : Type u_1 hG : Group G inst✝ : Fintype G e : ((p : { x // x ∈ (Nat.factorization (card G)).support }) → (P : Sylow (↑p) G) → { x // x ∈ ↑P }) ≃* G ps : Finset ℕ := (Nat.factorization (card G)).support this : ∀ (p : { x // x ∈ ps }) (P : Sylow (↑p) G), Group.IsNilpotent { x // x ∈ ↑P } ⊢ Group.IsNilpotent G [PROOFSTEP] exact nilpotent_of_mulEquiv e [GOAL] G : Type u_1 hG : Group G inst✝ : Fintype G ⊢ List.TFAE [Group.IsNilpotent G, NormalizerCondition G, ∀ (H : Subgroup G), IsCoatom H → Normal H, ∀ (p : ℕ), Fact (Nat.Prime p) → ∀ (P : Sylow p G), Normal ↑P, Nonempty (((p : { x // x ∈ (Nat.factorization (card G)).support }) → (P : Sylow (↑p) G) → { x // x ∈ ↑P }) ≃* G)] [PROOFSTEP] tfae_have 1 → 2 [GOAL] case tfae_1_to_2 G : Type u_1 hG : Group G inst✝ : Fintype G ⊢ Group.IsNilpotent G → NormalizerCondition G [PROOFSTEP] exact @normalizerCondition_of_isNilpotent _ _ [GOAL] G : Type u_1 hG : Group G inst✝ : Fintype G tfae_1_to_2 : Group.IsNilpotent G → NormalizerCondition G ⊢ List.TFAE [Group.IsNilpotent G, NormalizerCondition G, ∀ (H : Subgroup G), IsCoatom H → Normal H, ∀ (p : ℕ), Fact (Nat.Prime p) → ∀ (P : Sylow p G), Normal ↑P, Nonempty (((p : { x // x ∈ (Nat.factorization (card G)).support }) → (P : Sylow (↑p) G) → { x // x ∈ ↑P }) ≃* G)] [PROOFSTEP] tfae_have 2 → 3 [GOAL] case tfae_2_to_3 G : Type u_1 hG : Group G inst✝ : Fintype G tfae_1_to_2 : Group.IsNilpotent G → NormalizerCondition G ⊢ NormalizerCondition G → ∀ (H : Subgroup G), IsCoatom H → Normal H [PROOFSTEP] exact fun h H => NormalizerCondition.normal_of_coatom H h [GOAL] G : Type u_1 hG : Group G inst✝ : Fintype G tfae_1_to_2 : Group.IsNilpotent G → NormalizerCondition G tfae_2_to_3 : NormalizerCondition G → ∀ (H : Subgroup G), IsCoatom H → Normal H ⊢ List.TFAE [Group.IsNilpotent G, NormalizerCondition G, ∀ (H : Subgroup G), IsCoatom H → Normal H, ∀ (p : ℕ), Fact (Nat.Prime p) → ∀ (P : Sylow p G), Normal ↑P, Nonempty (((p : { x // x ∈ (Nat.factorization (card G)).support }) → (P : Sylow (↑p) G) → { x // x ∈ ↑P }) ≃* G)] [PROOFSTEP] tfae_have 3 → 4 [GOAL] case tfae_3_to_4 G : Type u_1 hG : Group G inst✝ : Fintype G tfae_1_to_2 : Group.IsNilpotent G → NormalizerCondition G tfae_2_to_3 : NormalizerCondition G → ∀ (H : Subgroup G), IsCoatom H → Normal H ⊢ (∀ (H : Subgroup G), IsCoatom H → Normal H) → ∀ (p : ℕ), Fact (Nat.Prime p) → ∀ (P : Sylow p G), Normal ↑P [PROOFSTEP] intro h p _ P [GOAL] case tfae_3_to_4 G : Type u_1 hG : Group G inst✝ : Fintype G tfae_1_to_2 : Group.IsNilpotent G → NormalizerCondition G tfae_2_to_3 : NormalizerCondition G → ∀ (H : Subgroup G), IsCoatom H → Normal H h : ∀ (H : Subgroup G), IsCoatom H → Normal H p : ℕ _hp✝ : Fact (Nat.Prime p) P : Sylow p G ⊢ Normal ↑P [PROOFSTEP] exact Sylow.normal_of_all_max_subgroups_normal h _ [GOAL] G : Type u_1 hG : Group G inst✝ : Fintype G tfae_1_to_2 : Group.IsNilpotent G → NormalizerCondition G tfae_2_to_3 : NormalizerCondition G → ∀ (H : Subgroup G), IsCoatom H → Normal H tfae_3_to_4 : (∀ (H : Subgroup G), IsCoatom H → Normal H) → ∀ (p : ℕ), Fact (Nat.Prime p) → ∀ (P : Sylow p G), Normal ↑P ⊢ List.TFAE [Group.IsNilpotent G, NormalizerCondition G, ∀ (H : Subgroup G), IsCoatom H → Normal H, ∀ (p : ℕ), Fact (Nat.Prime p) → ∀ (P : Sylow p G), Normal ↑P, Nonempty (((p : { x // x ∈ (Nat.factorization (card G)).support }) → (P : Sylow (↑p) G) → { x // x ∈ ↑P }) ≃* G)] [PROOFSTEP] tfae_have 4 → 5 [GOAL] case tfae_4_to_5 G : Type u_1 hG : Group G inst✝ : Fintype G tfae_1_to_2 : Group.IsNilpotent G → NormalizerCondition G tfae_2_to_3 : NormalizerCondition G → ∀ (H : Subgroup G), IsCoatom H → Normal H tfae_3_to_4 : (∀ (H : Subgroup G), IsCoatom H → Normal H) → ∀ (p : ℕ), Fact (Nat.Prime p) → ∀ (P : Sylow p G), Normal ↑P ⊢ (∀ (p : ℕ), Fact (Nat.Prime p) → ∀ (P : Sylow p G), Normal ↑P) → Nonempty (((p : { x // x ∈ (Nat.factorization (card G)).support }) → (P : Sylow (↑p) G) → { x // x ∈ ↑P }) ≃* G) [PROOFSTEP] exact fun h => Nonempty.intro (Sylow.directProductOfNormal fun {p hp hP} => h p hp hP) [GOAL] G : Type u_1 hG : Group G inst✝ : Fintype G tfae_1_to_2 : Group.IsNilpotent G → NormalizerCondition G tfae_2_to_3 : NormalizerCondition G → ∀ (H : Subgroup G), IsCoatom H → Normal H tfae_3_to_4 : (∀ (H : Subgroup G), IsCoatom H → Normal H) → ∀ (p : ℕ), Fact (Nat.Prime p) → ∀ (P : Sylow p G), Normal ↑P tfae_4_to_5 : (∀ (p : ℕ), Fact (Nat.Prime p) → ∀ (P : Sylow p G), Normal ↑P) → Nonempty (((p : { x // x ∈ (Nat.factorization (card G)).support }) → (P : Sylow (↑p) G) → { x // x ∈ ↑P }) ≃* G) ⊢ List.TFAE [Group.IsNilpotent G, NormalizerCondition G, ∀ (H : Subgroup G), IsCoatom H → Normal H, ∀ (p : ℕ), Fact (Nat.Prime p) → ∀ (P : Sylow p G), Normal ↑P, Nonempty (((p : { x // x ∈ (Nat.factorization (card G)).support }) → (P : Sylow (↑p) G) → { x // x ∈ ↑P }) ≃* G)] [PROOFSTEP] tfae_have 5 → 1 [GOAL] case tfae_5_to_1 G : Type u_1 hG : Group G inst✝ : Fintype G tfae_1_to_2 : Group.IsNilpotent G → NormalizerCondition G tfae_2_to_3 : NormalizerCondition G → ∀ (H : Subgroup G), IsCoatom H → Normal H tfae_3_to_4 : (∀ (H : Subgroup G), IsCoatom H → Normal H) → ∀ (p : ℕ), Fact (Nat.Prime p) → ∀ (P : Sylow p G), Normal ↑P tfae_4_to_5 : (∀ (p : ℕ), Fact (Nat.Prime p) → ∀ (P : Sylow p G), Normal ↑P) → Nonempty (((p : { x // x ∈ (Nat.factorization (card G)).support }) → (P : Sylow (↑p) G) → { x // x ∈ ↑P }) ≃* G) ⊢ Nonempty (((p : { x // x ∈ (Nat.factorization (card G)).support }) → (P : Sylow (↑p) G) → { x // x ∈ ↑P }) ≃* G) → Group.IsNilpotent G [PROOFSTEP] rintro ⟨e⟩ [GOAL] case tfae_5_to_1.intro G : Type u_1 hG : Group G inst✝ : Fintype G tfae_1_to_2 : Group.IsNilpotent G → NormalizerCondition G tfae_2_to_3 : NormalizerCondition G → ∀ (H : Subgroup G), IsCoatom H → Normal H tfae_3_to_4 : (∀ (H : Subgroup G), IsCoatom H → Normal H) → ∀ (p : ℕ), Fact (Nat.Prime p) → ∀ (P : Sylow p G), Normal ↑P tfae_4_to_5 : (∀ (p : ℕ), Fact (Nat.Prime p) → ∀ (P : Sylow p G), Normal ↑P) → Nonempty (((p : { x // x ∈ (Nat.factorization (card G)).support }) → (P : Sylow (↑p) G) → { x // x ∈ ↑P }) ≃* G) e : ((p : { x // x ∈ (Nat.factorization (card G)).support }) → (P : Sylow (↑p) G) → { x // x ∈ ↑P }) ≃* G ⊢ Group.IsNilpotent G [PROOFSTEP] exact isNilpotent_of_product_of_sylow_group e [GOAL] G : Type u_1 hG : Group G inst✝ : Fintype G tfae_1_to_2 : Group.IsNilpotent G → NormalizerCondition G tfae_2_to_3 : NormalizerCondition G → ∀ (H : Subgroup G), IsCoatom H → Normal H tfae_3_to_4 : (∀ (H : Subgroup G), IsCoatom H → Normal H) → ∀ (p : ℕ), Fact (Nat.Prime p) → ∀ (P : Sylow p G), Normal ↑P tfae_4_to_5 : (∀ (p : ℕ), Fact (Nat.Prime p) → ∀ (P : Sylow p G), Normal ↑P) → Nonempty (((p : { x // x ∈ (Nat.factorization (card G)).support }) → (P : Sylow (↑p) G) → { x // x ∈ ↑P }) ≃* G) tfae_5_to_1 : Nonempty (((p : { x // x ∈ (Nat.factorization (card G)).support }) → (P : Sylow (↑p) G) → { x // x ∈ ↑P }) ≃* G) → Group.IsNilpotent G ⊢ List.TFAE [Group.IsNilpotent G, NormalizerCondition G, ∀ (H : Subgroup G), IsCoatom H → Normal H, ∀ (p : ℕ), Fact (Nat.Prime p) → ∀ (P : Sylow p G), Normal ↑P, Nonempty (((p : { x // x ∈ (Nat.factorization (card G)).support }) → (P : Sylow (↑p) G) → { x // x ∈ ↑P }) ≃* G)] [PROOFSTEP] tfae_finish
import numpy as np import matplotlib as mpl mpl.use('TkAgg') import matplotlib.pyplot as plt loss_record = "loss_record.txt" losses_dg = np.loadtxt(loss_record) loss_d = losses_dg[:,0] loss_g = losses_dg[:,1] loss_p = losses_dg[:,2] plt.figure() plt.plot(losses_dg[0:-1:100, 0], 'r-', label='d_loss') plt.xlabel("iteration*100") plt.ylabel("Error") plt.title("Discriminator Losse") plt.savefig("plot_d_loss.jpg") plt.figure() plt.plot(losses_dg[0:-1:100, 1], 'g-', label='g_loss') plt.xlabel("iteration*100") plt.ylabel("Error") plt.title("Generator Losses") plt.savefig("plot_g_loss.jpg") plt.figure() plt.plot(losses_dg[0:-1:100, 2], 'b-', label='dc_loss') plt.xlabel("iteration*100") plt.ylabel("Error") plt.title("DarkChannel Losses") plt.savefig("plot_dc_loss.jpg") plt.show()
lemma degree_of_int [simp]: "degree (of_int k) = 0"
Formal statement is: lemma contour_integrable_subpath_refl [iff]: "f contour_integrable_on (subpath u u g)" Informal statement is: If $f$ is a contour-integrable function on a path $g$, then $f$ is contour-integrable on the subpath of $g$ from $u$ to $u$.
Set Implicit Arguments. Section ADTValue. Variable ADTValue : Type. Require Import Bedrock.Platform.Cito.SemanticsFacts4. Require Import Bedrock.Platform.Cito.ProgramLogic2. Require Import Bedrock.Platform.Cito.Transit. Require Import Bedrock.Platform.Cito.Semantics. Require Import Bedrock.Platform.Cito.GLabel. Require Import Bedrock.Platform.Cito.GLabelMap. Import GLabelMap. Require Import Bedrock.Platform.Cito.GLabelMapFacts. Notation Internal := (@Internal ADTValue). Definition strengthen_specs specs_op specs_ax env_ax := forall (lbl : glabel), find lbl specs_op = find lbl specs_ax \/ exists spec_op spec_ax, find lbl specs_op = Some (Internal spec_op) /\ find lbl specs_ax = Some (Foreign spec_ax) /\ strengthen_op_ax spec_op spec_ax env_ax. Require Import Bedrock.Platform.Cito.GeneralTactics Bedrock.Platform.Cito.GeneralTactics2. Require Import Bedrock.Platform.Cito.Option. Lemma strengthen_specs_strengthen : forall specs_op specs_ax env_op env_ax, strengthen_specs specs_op specs_ax env_ax -> specs_env_agree specs_op env_op -> specs_env_agree specs_ax env_ax -> (forall lbl, fst env_op lbl = fst env_ax lbl) -> strengthen env_op env_ax. Proof. split; intros. eauto. destruct (option_dec (fs_op w)). destruct s. generalize e; intro. eapply H0 in e. openhyp. edestruct (H x0). left. rewrite e0. symmetry. eapply H1. rewrite H5 in H4; clear H5. descend; eauto. rewrite <- H2. eauto. openhyp. rewrite H5 in H4; injection H4; intros; subst. assert (fs_ax w = Some (Foreign x2)). eapply H1. descend; eauto. rewrite <- H2; eauto. right; descend; eauto. destruct (option_dec (fs_ax w)). destruct s. generalize e0; intro. eapply H1 in e0. openhyp. edestruct (H x0). assert (fs_op w = Some x). eapply H0. descend; eauto. rewrite H2; eauto. rewrite H5. eauto. rewrite H6 in e; intuition. openhyp. assert (fs_op w = Some (Internal x1)). eapply H0. descend; eauto. rewrite H2; eauto. rewrite H8 in e; intuition. left; congruence. Qed. Notation Foreign := (@Foreign ADTValue). Definition apply_specs_diff specs specs_diff := update specs (map Foreign specs_diff). Definition strengthen_diff_f specs env_ax k v a := a /\ (find k specs = Some (Foreign v) \/ exists op, find k specs = Some (Internal op) /\ strengthen_op_ax op v env_ax). Definition strengthen_diff specs specs_diff env_ax := fold (strengthen_diff_f specs env_ax) specs_diff True. Lemma strengthen_diff_intro : forall specs_diff env_ax specs, (forall lbl ax, find lbl specs_diff = Some ax -> find lbl specs = Some (Foreign ax) \/ exists op, find lbl specs = Some (Internal op) /\ strengthen_op_ax op ax env_ax) -> strengthen_diff specs specs_diff env_ax. Proof. do 3 intro. (* intros Hforall. *) (* unfold strengthen_diff. *) eapply fold_rec_bis with (P := fun specs_diff (H : Prop) => (forall lbl ax, find lbl specs_diff = Some ax -> find lbl specs = Some (Foreign ax) \/ exists op, find lbl specs = Some (Internal op) /\ strengthen_op_ax op ax env_ax) -> H); simpl. intros m m' a Heqm Ha Hforall. { eapply Ha. intros lbl ax Hfind. rewrite Heqm in Hfind. eauto. } { eauto. } intros k e a m' Hmapsto Hnin Ha Hforall. unfold strengthen_diff_f. split. { eapply Ha. intros lbl ax Hfind. eapply Hforall. eapply find_mapsto_iff. eapply add_mapsto_iff. right. split. { intro Heq; subst. contradict Hnin. eapply MapsTo_In. eapply find_mapsto_iff. eauto. } eapply find_mapsto_iff. eauto. } eapply Hforall. eapply find_mapsto_iff. eapply add_mapsto_iff. left. eauto. Qed. Lemma strengthen_diff_elim : forall specs_diff env_ax specs, strengthen_diff specs specs_diff env_ax -> forall lbl ax, find lbl specs_diff = Some ax -> find lbl specs = Some (Foreign ax) \/ exists op, find lbl specs = Some (Internal op) /\ strengthen_op_ax op ax env_ax. do 3 intro. eapply fold_rec_bis with (P := fun specs_diff (H : Prop) => H -> forall lbl ax, find lbl specs_diff = Some ax -> find lbl specs = Some (Foreign ax) \/ exists op, find lbl specs = Some (Internal op) /\ strengthen_op_ax op ax env_ax); simpl; intros. eapply H0; eauto. rewrite H; eauto. rewrite empty_o in H0; intuition. eapply find_mapsto_iff in H3. eapply add_mapsto_iff in H3. openhyp. subst. destruct H2. openhyp. eauto. right; descend; eauto. eapply H1. destruct H2; eauto. eapply find_mapsto_iff; eauto. Qed. Lemma strengthen_diff_strengthen_specs : forall specs specs_diff env_ax, strengthen_diff specs specs_diff env_ax -> strengthen_specs specs (apply_specs_diff specs specs_diff) env_ax. intros. unfold strengthen_specs. intros. destruct (option_dec (find lbl specs_diff)). destruct s. eapply strengthen_diff_elim in H; eauto. openhyp. left. rewrite H. symmetry. eapply find_mapsto_iff. eapply update_mapsto_iff. left. eapply find_mapsto_iff. rewrite map_o. rewrite e. eauto. right; descend; eauto. eapply find_mapsto_iff. eapply update_mapsto_iff. left. eapply find_mapsto_iff. rewrite map_o. rewrite e. eauto. left. unfold apply_specs_diff. rewrite update_o_1; eauto. nintro. eapply map_4 in H0. eapply In_find_not_None in H0. erewrite e in H0. intuition. Qed. Lemma strengthen_diff_strenghthen : forall specs specs_diff env_op env_ax, strengthen_diff specs specs_diff env_ax -> specs_env_agree specs env_op -> specs_env_agree (apply_specs_diff specs specs_diff) env_ax -> (forall lbl, fst env_op lbl = fst env_ax lbl) -> strengthen env_op env_ax. intros. eapply strengthen_specs_strengthen; eauto. eapply strengthen_diff_strengthen_specs; eauto. Qed. Notation Callee := (@Callee ADTValue). Definition is_pointer_of_label specs (stn : glabel -> option W) w : option Callee := fold (fun k v res => match res with | Some _ => res | None => match stn k with | Some w' => if weq w w' then Some v else None | None => None end end ) specs None. Notation Env := (@Env ADTValue). Definition change_env new_specs (env : Env) : Env := let stn := fst env in let fs := snd env in (stn, fun w => match is_pointer_of_label new_specs stn w with | Some new_spec => Some new_spec | None => fs w end). Notation specs_stn_injective := (@specs_stn_injective ADTValue). Lemma sub_domain_specs_stn_injective : forall specs1 specs2 stn, specs_stn_injective specs1 stn -> sub_domain specs2 specs1 -> specs_stn_injective specs2 stn. unfold ProgramLogic2.specs_stn_injective, sub_domain; intros. eapply H; eauto. Qed. Lemma add_specs_stn_injective : forall specs k v stn, specs_stn_injective (add k v specs) stn -> specs_stn_injective specs stn. intros. eapply sub_domain_specs_stn_injective; eauto. unfold sub_domain; intros. eapply add_in_iff; eauto. Qed. Lemma is_pointer_of_label_intro_elim : forall specs stn w, (forall v, is_pointer_of_label specs stn w = Some v -> exists lbl, find lbl specs = Some v /\ stn lbl = Some w) /\ (forall v lbl, specs_stn_injective specs stn -> find lbl specs = Some v -> stn lbl = Some w -> is_pointer_of_label specs stn w = Some v). do 3 intro. eapply fold_rec_bis with (P := fun specs a => (forall v, a = Some v -> exists lbl, find lbl specs = Some v /\ stn lbl = Some w) /\ (forall v lbl, specs_stn_injective specs stn -> find lbl specs = Some v -> stn lbl = Some w -> a = Some v)); simpl; intros. unfold ProgramLogic2.specs_stn_injective in *. setoid_rewrite H in H0. eapply H0; eauto. split; intros. intuition. rewrite empty_o in H0; intuition. openhyp. split; intros. destruct a. injection H3; intros; subst. edestruct H1; eauto. openhyp. descend; eauto. eapply find_mapsto_iff; eapply add_mapsto_iff. right. split. nintro; subst. eapply find_mapsto_iff in H4; eapply MapsTo_In in H4. contradiction. eapply find_mapsto_iff; eauto. destruct (option_dec (stn k)). destruct s. rewrite e0 in *. destruct (weq w x). subst. injection H3; intros; subst. descend; eauto. eapply find_mapsto_iff; eapply add_mapsto_iff. eauto. intuition. rewrite e0 in *; intuition. destruct a. edestruct H1; eauto. openhyp. eapply find_mapsto_iff in H4; eapply find_mapsto_iff in H6. assert (lbl = x). eapply H3; eauto. eapply MapsTo_In; eauto. eapply add_in_iff; right; eapply MapsTo_In; eauto. subst. eapply add_mapsto_iff in H4; openhyp. subst. eapply MapsTo_In in H6; contradiction. eapply H2; eauto. eapply add_specs_stn_injective; eauto. eapply find_mapsto_iff; eauto. eapply find_mapsto_iff in H4. destruct (option_dec (stn k)). destruct s. rewrite e0 in *. eapply add_mapsto_iff in H4; openhyp. subst. rewrite H5 in e0; injection e0; intros; subst. destruct (weq x x); intuition. destruct (weq w x). subst. contradict H4. eapply H3; eauto. eapply add_in_iff; eauto. eapply add_in_iff; right; eapply MapsTo_In; eauto. eapply H2; eauto. eapply add_specs_stn_injective; eauto. eapply find_mapsto_iff; eauto. rewrite e0 in *. eapply add_mapsto_iff in H4; openhyp. subst. rewrite H5 in e0; intuition. eapply H2; eauto. eapply add_specs_stn_injective; eauto. eapply find_mapsto_iff; eauto. Qed. Lemma is_pointer_of_label_intro : forall specs stn w v lbl, specs_stn_injective specs stn -> find lbl specs = Some v -> stn lbl = Some w -> is_pointer_of_label specs stn w = Some v. eapply is_pointer_of_label_intro_elim; eauto. Qed. Lemma is_pointer_of_label_elim : forall specs stn w v, is_pointer_of_label specs stn w = Some v -> exists lbl, find lbl specs = Some v /\ stn lbl = Some w. eapply is_pointer_of_label_intro_elim; eauto. Qed. Lemma equal_domain_specs_stn_injective : forall specs1 specs2 stn, equal_domain specs1 specs2 -> (specs_stn_injective specs1 stn <-> specs_stn_injective specs2 stn). split; intros. eapply sub_domain_specs_stn_injective; eauto; eapply H. eapply sub_domain_specs_stn_injective; eauto; eapply H. Qed. Lemma equal_domain_sym : forall elt1 elt2 (m1 : t elt1) (m2 : t elt2), equal_domain m1 m2 -> equal_domain m2 m1. unfold equal_domain; intuition. Qed. Lemma change_env_agree : forall specs new_specs, equal_domain new_specs specs -> forall env, specs_env_agree specs env -> specs_env_agree new_specs (change_env new_specs env). Proof. unfold specs_env_agree. intros. openhyp. simpl. split. unfold labels_in_scope in *. intros. eapply H0. eapply H; eauto. split. eapply equal_domain_specs_stn_injective; eauto. unfold specs_fs_agree in *. split; intros. simpl in *. destruct env in *; simpl in *. destruct (option_dec (is_pointer_of_label new_specs o p)). destruct s. rewrite e in *. injection H3; intros; subst. eapply is_pointer_of_label_elim in e; openhyp. descend; eauto. rewrite e in *. eapply H2 in H3; openhyp. eapply find_mapsto_iff in H4; eapply MapsTo_In in H4. eapply H in H4. eapply In_MapsTo in H4; openhyp. assert (is_pointer_of_label new_specs o p = Some x0). eapply is_pointer_of_label_intro; eauto. eapply equal_domain_specs_stn_injective; eauto. eapply find_mapsto_iff; eauto. rewrite e in H5; intuition. openhyp. simpl in *. destruct env; simpl in *. assert (is_pointer_of_label new_specs o p = Some spec). eapply is_pointer_of_label_intro; eauto. eapply equal_domain_specs_stn_injective; eauto. rewrite H5; eauto. Qed. Lemma sub_domain_apply_specs_diff_equal_domain a b : sub_domain b a -> equal_domain (apply_specs_diff a b) a. Proof. unfold apply_specs_diff. unfold equal_domain. intros H. split. { eapply sub_domain_update_sub_domain; eauto. eapply sub_domain_map_1; eauto. } { eapply sub_domain_update_1. eapply sub_domain_refl. } Qed. End ADTValue.
[GOAL] α : Type u_1 x✝ : Bool × ℕ b : Bool n : ℕ ⊢ boddDiv2 (uncurry bit (b, n)) = (b, n) [PROOFSTEP] simp only [bodd_bit, div2_bit, uncurry_apply_pair, boddDiv2_eq] [GOAL] α : Type u_1 n : ℕ ⊢ uncurry bit (boddDiv2 n) = n [PROOFSTEP] simp only [bit_decomp, boddDiv2_eq, uncurry_apply_pair] [GOAL] α : Type u_1 ⊢ ↑natSumNatEquivNat = Sum.elim bit0 bit1 [PROOFSTEP] ext (x | x) [GOAL] case h.inl α : Type u_1 x : ℕ ⊢ ↑natSumNatEquivNat (Sum.inl x) = Sum.elim bit0 bit1 (Sum.inl x) [PROOFSTEP] rfl [GOAL] case h.inr α : Type u_1 x : ℕ ⊢ ↑natSumNatEquivNat (Sum.inr x) = Sum.elim bit0 bit1 (Sum.inr x) [PROOFSTEP] rfl
import numpy as np class OUNoise(object): """Class for Ornstein-Uhlenbeck process, as used for exploration in DDPG. Usage: :: # init self.noise = OUNoise() # generate noise noise = self.noise(logits.shape, eps) For required parameters, you can refer to the stackoverflow page. However, our experiment result shows that (similar to OpenAI SpinningUp) using vanilla gaussian process has little difference from using the Ornstein-Uhlenbeck process. """ def __init__(self, sigma=0.3, theta=0.15, dt=1e-2, x0=None): self.alpha = theta * dt self.beta = sigma * np.sqrt(dt) self.x0 = x0 self.reset() def __call__(self, size, mu=.1): """Generate new noise. Return a ``numpy.ndarray`` which size is equal to ``size``. """ if self.x is None or self.x.shape != size: self.x = 0 r = self.beta * np.random.normal(size=size) self.x = self.x + self.alpha * (mu - self.x) + r return self.x def reset(self): """Reset to the initial state.""" self.x = None
/- Copyright (c) 2018 Guy Leroy. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Sangwoo Jo (aka Jason), Guy Leroy, Johannes Hölzl Greatest common divisor (gcd) and least common multiple (lcm) for integers. This sets up ℤ to be a GCD domain, and introduces rules about `int.gcd`, as well as `int.lcm`. NOTE: If you add rules to this theory, check that the corresponding rules are available for `gcd_domain`. -/ import data.int.basic data.nat.prime algebra.gcd_domain /- Extended Euclidean algorithm -/ namespace nat def xgcd_aux : ℕ → ℤ → ℤ → ℕ → ℤ → ℤ → ℕ × ℤ × ℤ | 0 s t r' s' t' := (r', s', t') | r@(succ _) s t r' s' t' := have r' % r < r, from mod_lt _ $ succ_pos _, let q := r' / r in xgcd_aux (r' % r) (s' - q * s) (t' - q * t) r s t @[simp] theorem xgcd_zero_left {s t r' s' t'} : xgcd_aux 0 s t r' s' t' = (r', s', t') := by simp [xgcd_aux] @[simp] theorem xgcd_aux_rec {r s t r' s' t'} (h : 0 < r) : xgcd_aux r s t r' s' t' = xgcd_aux (r' % r) (s' - (r' / r) * s) (t' - (r' / r) * t) r s t := by cases r; [exact absurd h (lt_irrefl _), {simp only [xgcd_aux], refl}] /-- Use the extended GCD algorithm to generate the `a` and `b` values satisfying `gcd x y = x * a + y * b`. -/ def xgcd (x y : ℕ) : ℤ × ℤ := (xgcd_aux x 1 0 y 0 1).2 /-- The extended GCD `a` value in the equation `gcd x y = x * a + y * b`. -/ def gcd_a (x y : ℕ) : ℤ := (xgcd x y).1 /-- The extended GCD `b` value in the equation `gcd x y = x * a + y * b`. -/ def gcd_b (x y : ℕ) : ℤ := (xgcd x y).2 @[simp] theorem xgcd_aux_fst (x y) : ∀ s t s' t', (xgcd_aux x s t y s' t').1 = gcd x y := gcd.induction x y (by simp) (λ x y h IH s t s' t', by simp [h, IH]; rw ← gcd_rec) theorem xgcd_aux_val (x y) : xgcd_aux x 1 0 y 0 1 = (gcd x y, xgcd x y) := by rw [xgcd, ← xgcd_aux_fst x y 1 0 0 1]; cases xgcd_aux x 1 0 y 0 1; refl theorem xgcd_val (x y) : xgcd x y = (gcd_a x y, gcd_b x y) := by unfold gcd_a gcd_b; cases xgcd x y; refl section parameters (a b : ℕ) private def P : ℕ × ℤ × ℤ → Prop | (r, s, t) := (r : ℤ) = a * s + b * t theorem xgcd_aux_P {r r'} : ∀ {s t s' t'}, P (r, s, t) → P (r', s', t') → P (xgcd_aux r s t r' s' t') := gcd.induction r r' (by simp) $ λ x y h IH s t s' t' p p', begin rw [xgcd_aux_rec h], refine IH _ p, dsimp [P] at *, rw [int.mod_def], generalize : (y / x : ℤ) = k, rw [p, p'], simp [mul_add, mul_comm, mul_left_comm] end theorem gcd_eq_gcd_ab : (gcd a b : ℤ) = a * gcd_a a b + b * gcd_b a b := by have := @xgcd_aux_P a b a b 1 0 0 1 (by simp [P]) (by simp [P]); rwa [xgcd_aux_val, xgcd_val] at this end end nat namespace int theorem nat_abs_div (a b : ℤ) (H : b ∣ a) : nat_abs (a / b) = (nat_abs a) / (nat_abs b) := begin cases (nat.eq_zero_or_pos (nat_abs b)), rw eq_zero_of_nat_abs_eq_zero h, simp, calc nat_abs (a / b) = nat_abs (a / b) * 1 : by rw mul_one ... = nat_abs (a / b) * (nat_abs b / nat_abs b) : by rw nat.div_self h ... = nat_abs (a / b) * nat_abs b / nat_abs b : by rw (nat.mul_div_assoc _ (dvd_refl _)) ... = nat_abs (a / b * b) / nat_abs b : by rw (nat_abs_mul (a / b) b) ... = nat_abs a / nat_abs b : by rw int.div_mul_cancel H, end theorem nat_abs_dvd_abs_iff {i j : ℤ} : i.nat_abs ∣ j.nat_abs ↔ i ∣ j := ⟨assume (H : i.nat_abs ∣ j.nat_abs), dvd_nat_abs.mp (nat_abs_dvd.mp (coe_nat_dvd.mpr H)), assume H : (i ∣ j), coe_nat_dvd.mp (dvd_nat_abs.mpr (nat_abs_dvd.mpr H))⟩ lemma succ_dvd_or_succ_dvd_of_succ_sum_dvd_mul {p : ℕ} (p_prime : nat.prime p) {m n : ℤ} {k l : ℕ} (hpm : ↑(p ^ k) ∣ m) (hpn : ↑(p ^ l) ∣ n) (hpmn : ↑(p ^ (k+l+1)) ∣ m*n) : ↑(p ^ (k+1)) ∣ m ∨ ↑(p ^ (l+1)) ∣ n := have hpm' : p ^ k ∣ m.nat_abs, from int.coe_nat_dvd.1 $ int.dvd_nat_abs.2 hpm, have hpn' : p ^ l ∣ n.nat_abs, from int.coe_nat_dvd.1 $ int.dvd_nat_abs.2 hpn, have hpmn' : (p ^ (k+l+1)) ∣ m.nat_abs*n.nat_abs, by rw ←int.nat_abs_mul; apply (int.coe_nat_dvd.1 $ int.dvd_nat_abs.2 hpmn), let hsd := nat.succ_dvd_or_succ_dvd_of_succ_sum_dvd_mul p_prime hpm' hpn' hpmn' in hsd.elim (λ hsd1, or.inl begin apply int.dvd_nat_abs.1, apply int.coe_nat_dvd.2 hsd1 end) (λ hsd2, or.inr begin apply int.dvd_nat_abs.1, apply int.coe_nat_dvd.2 hsd2 end) theorem dvd_of_mul_dvd_mul_left {i j k : ℤ} (k_non_zero : k ≠ 0) (H : k * i ∣ k * j) : i ∣ j := dvd.elim H (λl H1, by rw mul_assoc at H1; exact ⟨_, eq_of_mul_eq_mul_left k_non_zero H1⟩) theorem dvd_of_mul_dvd_mul_right {i j k : ℤ} (k_non_zero : k ≠ 0) (H : i * k ∣ j * k) : i ∣ j := by rw [mul_comm i k, mul_comm j k] at H; exact dvd_of_mul_dvd_mul_left k_non_zero H section normalization_domain instance : normalization_domain ℤ := { norm_unit := λa:ℤ, if 0 ≤ a then 1 else -1, norm_unit_zero := if_pos (le_refl _), norm_unit_mul := assume a b hna hnb, begin by_cases ha : 0 ≤ a; by_cases hb : 0 ≤ b; simp [ha, hb], exact if_pos (mul_nonneg ha hb), exact if_neg (assume h, hb $ nonneg_of_mul_nonneg_left h $ lt_of_le_of_ne ha hna.symm), exact if_neg (assume h, ha $ nonneg_of_mul_nonneg_right h $ lt_of_le_of_ne hb hnb.symm), exact if_pos (mul_nonneg_of_nonpos_of_nonpos (le_of_not_ge ha) (le_of_not_ge hb)) end, norm_unit_coe_units := assume u, (units_eq_one_or u).elim (assume eq, eq.symm ▸ if_pos zero_le_one) (assume eq, eq.symm ▸ if_neg (not_le_of_gt $ show (-1:ℤ) < 0, by simp [@neg_lt ℤ _ 1 0])), .. (infer_instance : integral_domain ℤ) } lemma norm_unit_of_nonneg {z : ℤ} (h : 0 ≤ z) : norm_unit z = 1 := by unfold norm_unit; exact if_pos h lemma norm_unit_of_neg {z : ℤ} (h : z < 0) : norm_unit z = -1 := by unfold norm_unit; exact if_neg (not_le_of_gt h) lemma norm_unit_nat_coe (n : ℕ) : norm_unit (n : ℤ) = 1 := norm_unit_of_nonneg (coe_nat_le_coe_nat_of_le $ nat.zero_le n) theorem coe_nat_abs_eq_mul_norm_unit {z : ℤ} : (z.nat_abs : ℤ) = z * norm_unit z := begin by_cases 0 ≤ z, { simp [nat_abs_of_nonneg h, norm_unit_of_nonneg h] }, { simp [of_nat_nat_abs_of_nonpos (le_of_not_ge h), norm_unit_of_neg (lt_of_not_ge h)] } end end normalization_domain /-- ℤ specific version of least common multiple. -/ def lcm (i j : ℤ) : ℕ := nat.lcm (nat_abs i) (nat_abs j) theorem lcm_def (i j : ℤ) : lcm i j = nat.lcm (nat_abs i) (nat_abs j) := rfl section gcd_domain theorem gcd_dvd_left (i j : ℤ) : (gcd i j : ℤ) ∣ i := dvd_nat_abs.mp $ coe_nat_dvd.mpr $ nat.gcd_dvd_left _ _ theorem gcd_dvd_right (i j : ℤ) : (gcd i j : ℤ) ∣ j := dvd_nat_abs.mp $ coe_nat_dvd.mpr $ nat.gcd_dvd_right _ _ theorem dvd_gcd {i j k : ℤ} (h1 : k ∣ i) (h2 : k ∣ j) : k ∣ gcd i j := nat_abs_dvd.1 $ coe_nat_dvd.2 $ nat.dvd_gcd (nat_abs_dvd_abs_iff.2 h1) (nat_abs_dvd_abs_iff.2 h2) theorem gcd_mul_lcm (i j : ℤ) : gcd i j * lcm i j = nat_abs (i * j) := by rw [int.gcd, int.lcm, nat.gcd_mul_lcm, nat_abs_mul] instance : gcd_domain ℤ := { gcd := λa b, int.gcd a b, lcm := λa b, int.lcm a b, gcd_dvd_left := assume a b, int.gcd_dvd_left _ _, gcd_dvd_right := assume a b, int.gcd_dvd_right _ _, dvd_gcd := assume a b c, dvd_gcd, norm_unit_gcd := assume a b, norm_unit_nat_coe _, gcd_mul_lcm := by intros; rw [← int.coe_nat_mul, gcd_mul_lcm, coe_nat_abs_eq_mul_norm_unit], lcm_zero_left := assume a, coe_nat_eq_zero.2 $ nat.lcm_zero_left _, lcm_zero_right := assume a, coe_nat_eq_zero.2 $ nat.lcm_zero_right _, .. int.normalization_domain } lemma coe_gcd (i j : ℤ) : ↑(int.gcd i j) = gcd_domain.gcd i j := rfl lemma coe_lcm (i j : ℤ) : ↑(int.lcm i j) = gcd_domain.lcm i j := rfl lemma nat_abs_gcd (i j : ℤ) : nat_abs (gcd_domain.gcd i j) = int.gcd i j := rfl lemma nat_abs_lcm (i j : ℤ) : nat_abs (gcd_domain.lcm i j) = int.lcm i j := rfl end gcd_domain theorem gcd_comm (i j : ℤ) : gcd i j = gcd j i := nat.gcd_comm _ _ theorem gcd_assoc (i j k : ℤ) : gcd (gcd i j) k = gcd i (gcd j k) := nat.gcd_assoc _ _ _ @[simp] theorem gcd_self (i : ℤ) : gcd i i = nat_abs i := by simp [gcd] @[simp] theorem gcd_zero_left (i : ℤ) : gcd 0 i = nat_abs i := by simp [gcd] @[simp] theorem gcd_zero_right (i : ℤ) : gcd i 0 = nat_abs i := by simp [gcd] @[simp] theorem gcd_one_left (i : ℤ) : gcd 1 i = 1 := nat.gcd_one_left _ @[simp] theorem gcd_one_right (i : ℤ) : gcd i 1 = 1 := nat.gcd_one_right _ theorem gcd_mul_left (i j k : ℤ) : gcd (i * j) (i * k) = nat_abs i * gcd j k := by simp [(int.coe_nat_eq_coe_nat_iff _ _).symm, coe_gcd, coe_nat_abs_eq_mul_norm_unit] theorem gcd_mul_right (i j k : ℤ) : gcd (i * j) (k * j) = gcd i k * nat_abs j := by simp [(int.coe_nat_eq_coe_nat_iff _ _).symm, coe_gcd, coe_nat_abs_eq_mul_norm_unit] theorem gcd_pos_of_non_zero_left {i : ℤ} (j : ℤ) (i_non_zero : i ≠ 0) : gcd i j > 0 := nat.gcd_pos_of_pos_left (nat_abs j) (nat_abs_pos_of_ne_zero i_non_zero) theorem gcd_pos_of_non_zero_right (i : ℤ) {j : ℤ} (j_non_zero : j ≠ 0) : gcd i j > 0 := nat.gcd_pos_of_pos_right (nat_abs i) (nat_abs_pos_of_ne_zero j_non_zero) theorem gcd_eq_zero_iff {i j : ℤ} : gcd i j = 0 ↔ i = 0 ∧ j = 0 := by rw [← int.coe_nat_eq_coe_nat_iff, int.coe_nat_zero, coe_gcd, gcd_eq_zero_iff] theorem gcd_div {i j k : ℤ} (H1 : k ∣ i) (H2 : k ∣ j) : gcd (i / k) (j / k) = gcd i j / nat_abs k := by rw [gcd, nat_abs_div i k H1, nat_abs_div j k H2]; exact nat.gcd_div (nat_abs_dvd_abs_iff.mpr H1) (nat_abs_dvd_abs_iff.mpr H2) theorem gcd_dvd_gcd_of_dvd_left {i k : ℤ} (j : ℤ) (H : i ∣ k) : gcd i j ∣ gcd k j := int.coe_nat_dvd.1 $ dvd_gcd (dvd.trans (gcd_dvd_left i j) H) (gcd_dvd_right i j) theorem gcd_dvd_gcd_of_dvd_right {i k : ℤ} (j : ℤ) (H : i ∣ k) : gcd j i ∣ gcd j k := int.coe_nat_dvd.1 $ dvd_gcd (gcd_dvd_left j i) (dvd.trans (gcd_dvd_right j i) H) theorem gcd_dvd_gcd_mul_left (i j k : ℤ) : gcd i j ∣ gcd (k * i) j := gcd_dvd_gcd_of_dvd_left _ (dvd_mul_left _ _) theorem gcd_dvd_gcd_mul_right (i j k : ℤ) : gcd i j ∣ gcd (i * k) j := gcd_dvd_gcd_of_dvd_left _ (dvd_mul_right _ _) theorem gcd_dvd_gcd_mul_left_right (i j k : ℤ) : gcd i j ∣ gcd i (k * j) := gcd_dvd_gcd_of_dvd_right _ (dvd_mul_left _ _) theorem gcd_dvd_gcd_mul_right_right (i j k : ℤ) : gcd i j ∣ gcd i (j * k) := gcd_dvd_gcd_of_dvd_right _ (dvd_mul_right _ _) theorem gcd_eq_left {i j : ℤ} (H : i ∣ j) : gcd i j = nat_abs i := nat.dvd_antisymm (by unfold gcd; exact nat.gcd_dvd_left _ _) (by unfold gcd; exact nat.dvd_gcd (dvd_refl _) (nat_abs_dvd_abs_iff.mpr H)) theorem gcd_eq_right {i j : ℤ} (H : j ∣ i) : gcd i j = nat_abs j := by rw [gcd_comm, gcd_eq_left H] /- lcm -/ theorem lcm_comm (i j : ℤ) : lcm i j = lcm j i := by simp [(int.coe_nat_eq_coe_nat_iff _ _).symm, coe_lcm, lcm_comm] theorem lcm_assoc (i j k : ℤ) : lcm (lcm i j) k = lcm i (lcm j k) := by simp [(int.coe_nat_eq_coe_nat_iff _ _).symm, coe_lcm, lcm_assoc] @[simp] theorem lcm_zero_left (i : ℤ) : lcm 0 i = 0 := by simp [(int.coe_nat_eq_coe_nat_iff _ _).symm, coe_lcm] @[simp] theorem lcm_zero_right (i : ℤ) : lcm i 0 = 0 := by simp [(int.coe_nat_eq_coe_nat_iff _ _).symm, coe_lcm] @[simp] theorem lcm_one_left (i : ℤ) : lcm 1 i = nat_abs i := by simp [(int.coe_nat_eq_coe_nat_iff _ _).symm, coe_lcm, coe_nat_abs_eq_mul_norm_unit] @[simp] theorem lcm_one_right (i : ℤ) : lcm i 1 = nat_abs i := by simp [(int.coe_nat_eq_coe_nat_iff _ _).symm, coe_lcm, coe_nat_abs_eq_mul_norm_unit] @[simp] theorem lcm_self (i : ℤ) : lcm i i = nat_abs i := by simp [(int.coe_nat_eq_coe_nat_iff _ _).symm, coe_lcm, coe_nat_abs_eq_mul_norm_unit] theorem dvd_lcm_left (i j : ℤ) : i ∣ lcm i j := by rw [coe_lcm]; exact dvd_lcm_left _ _ theorem dvd_lcm_right (i j : ℤ) : j ∣ lcm i j := by rw [coe_lcm]; exact dvd_lcm_right _ _ theorem lcm_dvd {i j k : ℤ} : i ∣ k → j ∣ k → (lcm i j : ℤ) ∣ k := by rw [coe_lcm]; exact lcm_dvd end int
[GOAL] R : Type u_1 A : Type u_2 inst✝⁴ : CommSemiring R inst✝³ : NonUnitalSemiring A inst✝² : Module R A inst✝¹ : SMulCommClass R A A inst✝ : IsScalarTower R A A src✝ : A →ₗ[R] A →ₗ[R] A := mul R A ⊢ MulActionHom.toFun { toFun := src✝.toFun, map_smul' := (_ : ∀ (r : R) (x : A), AddHom.toFun src✝.toAddHom (r • x) = ↑(RingHom.id R) r • AddHom.toFun src✝.toAddHom x) } 0 = 0 [PROOFSTEP] ext a [GOAL] case h R : Type u_1 A : Type u_2 inst✝⁴ : CommSemiring R inst✝³ : NonUnitalSemiring A inst✝² : Module R A inst✝¹ : SMulCommClass R A A inst✝ : IsScalarTower R A A src✝ : A →ₗ[R] A →ₗ[R] A := mul R A a : A ⊢ ↑(MulActionHom.toFun { toFun := src✝.toFun, map_smul' := (_ : ∀ (r : R) (x : A), AddHom.toFun src✝.toAddHom (r • x) = ↑(RingHom.id R) r • AddHom.toFun src✝.toAddHom x) } 0) a = ↑0 a [PROOFSTEP] exact zero_mul a [GOAL] R : Type u_1 A : Type u_2 inst✝⁴ : CommSemiring R inst✝³ : NonUnitalSemiring A inst✝² : Module R A inst✝¹ : SMulCommClass R A A inst✝ : IsScalarTower R A A src✝ : A →ₗ[R] A →ₗ[R] A := mul R A ⊢ ∀ (x y : A), MulActionHom.toFun { toMulActionHom := { toFun := src✝.toFun, map_smul' := (_ : ∀ (r : R) (x : A), AddHom.toFun src✝.toAddHom (r • x) = ↑(RingHom.id R) r • AddHom.toFun src✝.toAddHom x) }, map_zero' := (_ : MulActionHom.toFun { toFun := src✝.toFun, map_smul' := (_ : ∀ (r : R) (x : A), AddHom.toFun src✝.toAddHom (r • x) = ↑(RingHom.id R) r • AddHom.toFun src✝.toAddHom x) } 0 = 0), map_add' := (_ : ∀ (x y : A), AddHom.toFun src✝.toAddHom (x + y) = AddHom.toFun src✝.toAddHom x + AddHom.toFun src✝.toAddHom y) }.toMulActionHom (x * y) = MulActionHom.toFun { toMulActionHom := { toFun := src✝.toFun, map_smul' := (_ : ∀ (r : R) (x : A), AddHom.toFun src✝.toAddHom (r • x) = ↑(RingHom.id R) r • AddHom.toFun src✝.toAddHom x) }, map_zero' := (_ : MulActionHom.toFun { toFun := src✝.toFun, map_smul' := (_ : ∀ (r : R) (x : A), AddHom.toFun src✝.toAddHom (r • x) = ↑(RingHom.id R) r • AddHom.toFun src✝.toAddHom x) } 0 = 0), map_add' := (_ : ∀ (x y : A), AddHom.toFun src✝.toAddHom (x + y) = AddHom.toFun src✝.toAddHom x + AddHom.toFun src✝.toAddHom y) }.toMulActionHom x * MulActionHom.toFun { toMulActionHom := { toFun := src✝.toFun, map_smul' := (_ : ∀ (r : R) (x : A), AddHom.toFun src✝.toAddHom (r • x) = ↑(RingHom.id R) r • AddHom.toFun src✝.toAddHom x) }, map_zero' := (_ : MulActionHom.toFun { toFun := src✝.toFun, map_smul' := (_ : ∀ (r : R) (x : A), AddHom.toFun src✝.toAddHom (r • x) = ↑(RingHom.id R) r • AddHom.toFun src✝.toAddHom x) } 0 = 0), map_add' := (_ : ∀ (x y : A), AddHom.toFun src✝.toAddHom (x + y) = AddHom.toFun src✝.toAddHom x + AddHom.toFun src✝.toAddHom y) }.toMulActionHom y [PROOFSTEP] intro a b [GOAL] R : Type u_1 A : Type u_2 inst✝⁴ : CommSemiring R inst✝³ : NonUnitalSemiring A inst✝² : Module R A inst✝¹ : SMulCommClass R A A inst✝ : IsScalarTower R A A src✝ : A →ₗ[R] A →ₗ[R] A := mul R A a b : A ⊢ MulActionHom.toFun { toMulActionHom := { toFun := src✝.toFun, map_smul' := (_ : ∀ (r : R) (x : A), AddHom.toFun src✝.toAddHom (r • x) = ↑(RingHom.id R) r • AddHom.toFun src✝.toAddHom x) }, map_zero' := (_ : MulActionHom.toFun { toFun := src✝.toFun, map_smul' := (_ : ∀ (r : R) (x : A), AddHom.toFun src✝.toAddHom (r • x) = ↑(RingHom.id R) r • AddHom.toFun src✝.toAddHom x) } 0 = 0), map_add' := (_ : ∀ (x y : A), AddHom.toFun src✝.toAddHom (x + y) = AddHom.toFun src✝.toAddHom x + AddHom.toFun src✝.toAddHom y) }.toMulActionHom (a * b) = MulActionHom.toFun { toMulActionHom := { toFun := src✝.toFun, map_smul' := (_ : ∀ (r : R) (x : A), AddHom.toFun src✝.toAddHom (r • x) = ↑(RingHom.id R) r • AddHom.toFun src✝.toAddHom x) }, map_zero' := (_ : MulActionHom.toFun { toFun := src✝.toFun, map_smul' := (_ : ∀ (r : R) (x : A), AddHom.toFun src✝.toAddHom (r • x) = ↑(RingHom.id R) r • AddHom.toFun src✝.toAddHom x) } 0 = 0), map_add' := (_ : ∀ (x y : A), AddHom.toFun src✝.toAddHom (x + y) = AddHom.toFun src✝.toAddHom x + AddHom.toFun src✝.toAddHom y) }.toMulActionHom a * MulActionHom.toFun { toMulActionHom := { toFun := src✝.toFun, map_smul' := (_ : ∀ (r : R) (x : A), AddHom.toFun src✝.toAddHom (r • x) = ↑(RingHom.id R) r • AddHom.toFun src✝.toAddHom x) }, map_zero' := (_ : MulActionHom.toFun { toFun := src✝.toFun, map_smul' := (_ : ∀ (r : R) (x : A), AddHom.toFun src✝.toAddHom (r • x) = ↑(RingHom.id R) r • AddHom.toFun src✝.toAddHom x) } 0 = 0), map_add' := (_ : ∀ (x y : A), AddHom.toFun src✝.toAddHom (x + y) = AddHom.toFun src✝.toAddHom x + AddHom.toFun src✝.toAddHom y) }.toMulActionHom b [PROOFSTEP] ext c [GOAL] case h R : Type u_1 A : Type u_2 inst✝⁴ : CommSemiring R inst✝³ : NonUnitalSemiring A inst✝² : Module R A inst✝¹ : SMulCommClass R A A inst✝ : IsScalarTower R A A src✝ : A →ₗ[R] A →ₗ[R] A := mul R A a b c : A ⊢ ↑(MulActionHom.toFun { toMulActionHom := { toFun := src✝.toFun, map_smul' := (_ : ∀ (r : R) (x : A), AddHom.toFun src✝.toAddHom (r • x) = ↑(RingHom.id R) r • AddHom.toFun src✝.toAddHom x) }, map_zero' := (_ : MulActionHom.toFun { toFun := src✝.toFun, map_smul' := (_ : ∀ (r : R) (x : A), AddHom.toFun src✝.toAddHom (r • x) = ↑(RingHom.id R) r • AddHom.toFun src✝.toAddHom x) } 0 = 0), map_add' := (_ : ∀ (x y : A), AddHom.toFun src✝.toAddHom (x + y) = AddHom.toFun src✝.toAddHom x + AddHom.toFun src✝.toAddHom y) }.toMulActionHom (a * b)) c = ↑(MulActionHom.toFun { toMulActionHom := { toFun := src✝.toFun, map_smul' := (_ : ∀ (r : R) (x : A), AddHom.toFun src✝.toAddHom (r • x) = ↑(RingHom.id R) r • AddHom.toFun src✝.toAddHom x) }, map_zero' := (_ : MulActionHom.toFun { toFun := src✝.toFun, map_smul' := (_ : ∀ (r : R) (x : A), AddHom.toFun src✝.toAddHom (r • x) = ↑(RingHom.id R) r • AddHom.toFun src✝.toAddHom x) } 0 = 0), map_add' := (_ : ∀ (x y : A), AddHom.toFun src✝.toAddHom (x + y) = AddHom.toFun src✝.toAddHom x + AddHom.toFun src✝.toAddHom y) }.toMulActionHom a * MulActionHom.toFun { toMulActionHom := { toFun := src✝.toFun, map_smul' := (_ : ∀ (r : R) (x : A), AddHom.toFun src✝.toAddHom (r • x) = ↑(RingHom.id R) r • AddHom.toFun src✝.toAddHom x) }, map_zero' := (_ : MulActionHom.toFun { toFun := src✝.toFun, map_smul' := (_ : ∀ (r : R) (x : A), AddHom.toFun src✝.toAddHom (r • x) = ↑(RingHom.id R) r • AddHom.toFun src✝.toAddHom x) } 0 = 0), map_add' := (_ : ∀ (x y : A), AddHom.toFun src✝.toAddHom (x + y) = AddHom.toFun src✝.toAddHom x + AddHom.toFun src✝.toAddHom y) }.toMulActionHom b) c [PROOFSTEP] exact mul_assoc a b c [GOAL] R : Type u_1 A : Type u_2 inst✝⁴ : CommSemiring R inst✝³ : NonUnitalSemiring A inst✝² : Module R A inst✝¹ : SMulCommClass R A A inst✝ : IsScalarTower R A A a b : A ⊢ Commute (mulLeft R a) (mulRight R b) [PROOFSTEP] ext c [GOAL] case h R : Type u_1 A : Type u_2 inst✝⁴ : CommSemiring R inst✝³ : NonUnitalSemiring A inst✝² : Module R A inst✝¹ : SMulCommClass R A A inst✝ : IsScalarTower R A A a b c : A ⊢ ↑(mulLeft R a * mulRight R b) c = ↑(mulRight R b * mulLeft R a) c [PROOFSTEP] exact (mul_assoc a c b).symm [GOAL] R : Type u_1 A : Type u_2 inst✝⁴ : CommSemiring R inst✝³ : NonUnitalSemiring A inst✝² : Module R A inst✝¹ : SMulCommClass R A A inst✝ : IsScalarTower R A A a b : A ⊢ mulLeft R (a * b) = comp (mulLeft R a) (mulLeft R b) [PROOFSTEP] ext [GOAL] case h R : Type u_1 A : Type u_2 inst✝⁴ : CommSemiring R inst✝³ : NonUnitalSemiring A inst✝² : Module R A inst✝¹ : SMulCommClass R A A inst✝ : IsScalarTower R A A a b x✝ : A ⊢ ↑(mulLeft R (a * b)) x✝ = ↑(comp (mulLeft R a) (mulLeft R b)) x✝ [PROOFSTEP] simp only [mulLeft_apply, comp_apply, mul_assoc] [GOAL] R : Type u_1 A : Type u_2 inst✝⁴ : CommSemiring R inst✝³ : NonUnitalSemiring A inst✝² : Module R A inst✝¹ : SMulCommClass R A A inst✝ : IsScalarTower R A A a b : A ⊢ mulRight R (a * b) = comp (mulRight R b) (mulRight R a) [PROOFSTEP] ext [GOAL] case h R : Type u_1 A : Type u_2 inst✝⁴ : CommSemiring R inst✝³ : NonUnitalSemiring A inst✝² : Module R A inst✝¹ : SMulCommClass R A A inst✝ : IsScalarTower R A A a b x✝ : A ⊢ ↑(mulRight R (a * b)) x✝ = ↑(comp (mulRight R b) (mulRight R a)) x✝ [PROOFSTEP] simp only [mulRight_apply, comp_apply, mul_assoc] [GOAL] R : Type u_1 A : Type u_2 inst✝² : CommSemiring R inst✝¹ : Semiring A inst✝ : Algebra R A src✝ : A →ₗ[R] A →ₗ[R] A := mul R A ⊢ AddHom.toFun src✝.toAddHom 1 = 1 [PROOFSTEP] ext a [GOAL] case h R : Type u_1 A : Type u_2 inst✝² : CommSemiring R inst✝¹ : Semiring A inst✝ : Algebra R A src✝ : A →ₗ[R] A →ₗ[R] A := mul R A a : A ⊢ ↑(AddHom.toFun src✝.toAddHom 1) a = ↑1 a [PROOFSTEP] exact one_mul a [GOAL] R : Type u_1 A : Type u_2 inst✝² : CommSemiring R inst✝¹ : Semiring A inst✝ : Algebra R A src✝ : A →ₗ[R] A →ₗ[R] A := mul R A ⊢ ∀ (x y : A), OneHom.toFun { toFun := src✝.toFun, map_one' := (_ : AddHom.toFun src✝.toAddHom 1 = 1) } (x * y) = OneHom.toFun { toFun := src✝.toFun, map_one' := (_ : AddHom.toFun src✝.toAddHom 1 = 1) } x * OneHom.toFun { toFun := src✝.toFun, map_one' := (_ : AddHom.toFun src✝.toAddHom 1 = 1) } y [PROOFSTEP] intro a b [GOAL] R : Type u_1 A : Type u_2 inst✝² : CommSemiring R inst✝¹ : Semiring A inst✝ : Algebra R A src✝ : A →ₗ[R] A →ₗ[R] A := mul R A a b : A ⊢ OneHom.toFun { toFun := src✝.toFun, map_one' := (_ : AddHom.toFun src✝.toAddHom 1 = 1) } (a * b) = OneHom.toFun { toFun := src✝.toFun, map_one' := (_ : AddHom.toFun src✝.toAddHom 1 = 1) } a * OneHom.toFun { toFun := src✝.toFun, map_one' := (_ : AddHom.toFun src✝.toAddHom 1 = 1) } b [PROOFSTEP] ext c [GOAL] case h R : Type u_1 A : Type u_2 inst✝² : CommSemiring R inst✝¹ : Semiring A inst✝ : Algebra R A src✝ : A →ₗ[R] A →ₗ[R] A := mul R A a b c : A ⊢ ↑(OneHom.toFun { toFun := src✝.toFun, map_one' := (_ : AddHom.toFun src✝.toAddHom 1 = 1) } (a * b)) c = ↑(OneHom.toFun { toFun := src✝.toFun, map_one' := (_ : AddHom.toFun src✝.toAddHom 1 = 1) } a * OneHom.toFun { toFun := src✝.toFun, map_one' := (_ : AddHom.toFun src✝.toAddHom 1 = 1) } b) c [PROOFSTEP] exact mul_assoc a b c [GOAL] R : Type u_1 A : Type u_2 inst✝² : CommSemiring R inst✝¹ : Semiring A inst✝ : Algebra R A src✝ : A →ₗ[R] A →ₗ[R] A := mul R A ⊢ OneHom.toFun (↑{ toOneHom := { toFun := src✝.toFun, map_one' := (_ : AddHom.toFun src✝.toAddHom 1 = 1) }, map_mul' := (_ : ∀ (a b : A), OneHom.toFun { toFun := src✝.toFun, map_one' := (_ : AddHom.toFun src✝.toAddHom 1 = 1) } (a * b) = OneHom.toFun { toFun := src✝.toFun, map_one' := (_ : AddHom.toFun src✝.toAddHom 1 = 1) } a * OneHom.toFun { toFun := src✝.toFun, map_one' := (_ : AddHom.toFun src✝.toAddHom 1 = 1) } b) }) 0 = 0 [PROOFSTEP] ext a [GOAL] case h R : Type u_1 A : Type u_2 inst✝² : CommSemiring R inst✝¹ : Semiring A inst✝ : Algebra R A src✝ : A →ₗ[R] A →ₗ[R] A := mul R A a : A ⊢ ↑(OneHom.toFun (↑{ toOneHom := { toFun := src✝.toFun, map_one' := (_ : AddHom.toFun src✝.toAddHom 1 = 1) }, map_mul' := (_ : ∀ (a b : A), OneHom.toFun { toFun := src✝.toFun, map_one' := (_ : AddHom.toFun src✝.toAddHom 1 = 1) } (a * b) = OneHom.toFun { toFun := src✝.toFun, map_one' := (_ : AddHom.toFun src✝.toAddHom 1 = 1) } a * OneHom.toFun { toFun := src✝.toFun, map_one' := (_ : AddHom.toFun src✝.toAddHom 1 = 1) } b) }) 0) a = ↑0 a [PROOFSTEP] exact zero_mul a [GOAL] R : Type u_1 A : Type u_2 inst✝² : CommSemiring R inst✝¹ : Semiring A inst✝ : Algebra R A src✝ : A →ₗ[R] A →ₗ[R] A := mul R A ⊢ ∀ (r : R), OneHom.toFun (↑↑{ toMonoidHom := { toOneHom := { toFun := src✝.toFun, map_one' := (_ : AddHom.toFun src✝.toAddHom 1 = 1) }, map_mul' := (_ : ∀ (a b : A), OneHom.toFun { toFun := src✝.toFun, map_one' := (_ : AddHom.toFun src✝.toAddHom 1 = 1) } (a * b) = OneHom.toFun { toFun := src✝.toFun, map_one' := (_ : AddHom.toFun src✝.toAddHom 1 = 1) } a * OneHom.toFun { toFun := src✝.toFun, map_one' := (_ : AddHom.toFun src✝.toAddHom 1 = 1) } b) }, map_zero' := (_ : OneHom.toFun (↑{ toOneHom := { toFun := src✝.toFun, map_one' := (_ : AddHom.toFun src✝.toAddHom 1 = 1) }, map_mul' := (_ : ∀ (a b : A), OneHom.toFun { toFun := src✝.toFun, map_one' := (_ : AddHom.toFun src✝.toAddHom 1 = 1) } (a * b) = OneHom.toFun { toFun := src✝.toFun, map_one' := (_ : AddHom.toFun src✝.toAddHom 1 = 1) } a * OneHom.toFun { toFun := src✝.toFun, map_one' := (_ : AddHom.toFun src✝.toAddHom 1 = 1) } b) }) 0 = 0), map_add' := (_ : ∀ (x y : A), AddHom.toFun src✝.toAddHom (x + y) = AddHom.toFun src✝.toAddHom x + AddHom.toFun src✝.toAddHom y) }) (↑(algebraMap R A) r) = ↑(algebraMap R (End R A)) r [PROOFSTEP] intro r [GOAL] R : Type u_1 A : Type u_2 inst✝² : CommSemiring R inst✝¹ : Semiring A inst✝ : Algebra R A src✝ : A →ₗ[R] A →ₗ[R] A := mul R A r : R ⊢ OneHom.toFun (↑↑{ toMonoidHom := { toOneHom := { toFun := src✝.toFun, map_one' := (_ : AddHom.toFun src✝.toAddHom 1 = 1) }, map_mul' := (_ : ∀ (a b : A), OneHom.toFun { toFun := src✝.toFun, map_one' := (_ : AddHom.toFun src✝.toAddHom 1 = 1) } (a * b) = OneHom.toFun { toFun := src✝.toFun, map_one' := (_ : AddHom.toFun src✝.toAddHom 1 = 1) } a * OneHom.toFun { toFun := src✝.toFun, map_one' := (_ : AddHom.toFun src✝.toAddHom 1 = 1) } b) }, map_zero' := (_ : OneHom.toFun (↑{ toOneHom := { toFun := src✝.toFun, map_one' := (_ : AddHom.toFun src✝.toAddHom 1 = 1) }, map_mul' := (_ : ∀ (a b : A), OneHom.toFun { toFun := src✝.toFun, map_one' := (_ : AddHom.toFun src✝.toAddHom 1 = 1) } (a * b) = OneHom.toFun { toFun := src✝.toFun, map_one' := (_ : AddHom.toFun src✝.toAddHom 1 = 1) } a * OneHom.toFun { toFun := src✝.toFun, map_one' := (_ : AddHom.toFun src✝.toAddHom 1 = 1) } b) }) 0 = 0), map_add' := (_ : ∀ (x y : A), AddHom.toFun src✝.toAddHom (x + y) = AddHom.toFun src✝.toAddHom x + AddHom.toFun src✝.toAddHom y) }) (↑(algebraMap R A) r) = ↑(algebraMap R (End R A)) r [PROOFSTEP] ext a [GOAL] case h R : Type u_1 A : Type u_2 inst✝² : CommSemiring R inst✝¹ : Semiring A inst✝ : Algebra R A src✝ : A →ₗ[R] A →ₗ[R] A := mul R A r : R a : A ⊢ ↑(OneHom.toFun (↑↑{ toMonoidHom := { toOneHom := { toFun := src✝.toFun, map_one' := (_ : AddHom.toFun src✝.toAddHom 1 = 1) }, map_mul' := (_ : ∀ (a b : A), OneHom.toFun { toFun := src✝.toFun, map_one' := (_ : AddHom.toFun src✝.toAddHom 1 = 1) } (a * b) = OneHom.toFun { toFun := src✝.toFun, map_one' := (_ : AddHom.toFun src✝.toAddHom 1 = 1) } a * OneHom.toFun { toFun := src✝.toFun, map_one' := (_ : AddHom.toFun src✝.toAddHom 1 = 1) } b) }, map_zero' := (_ : OneHom.toFun (↑{ toOneHom := { toFun := src✝.toFun, map_one' := (_ : AddHom.toFun src✝.toAddHom 1 = 1) }, map_mul' := (_ : ∀ (a b : A), OneHom.toFun { toFun := src✝.toFun, map_one' := (_ : AddHom.toFun src✝.toAddHom 1 = 1) } (a * b) = OneHom.toFun { toFun := src✝.toFun, map_one' := (_ : AddHom.toFun src✝.toAddHom 1 = 1) } a * OneHom.toFun { toFun := src✝.toFun, map_one' := (_ : AddHom.toFun src✝.toAddHom 1 = 1) } b) }) 0 = 0), map_add' := (_ : ∀ (x y : A), AddHom.toFun src✝.toAddHom (x + y) = AddHom.toFun src✝.toAddHom x + AddHom.toFun src✝.toAddHom y) }) (↑(algebraMap R A) r)) a = ↑(↑(algebraMap R (End R A)) r) a [PROOFSTEP] exact (Algebra.smul_def r a).symm [GOAL] R : Type u_1 A : Type u_2 inst✝² : CommSemiring R inst✝¹ : Semiring A inst✝ : Algebra R A a : A ⊢ mulLeft R a = 0 ↔ a = 0 [PROOFSTEP] constructor [GOAL] case mp R : Type u_1 A : Type u_2 inst✝² : CommSemiring R inst✝¹ : Semiring A inst✝ : Algebra R A a : A ⊢ mulLeft R a = 0 → a = 0 [PROOFSTEP] intro h [GOAL] case mpr R : Type u_1 A : Type u_2 inst✝² : CommSemiring R inst✝¹ : Semiring A inst✝ : Algebra R A a : A ⊢ a = 0 → mulLeft R a = 0 [PROOFSTEP] intro h [GOAL] case mp R : Type u_1 A : Type u_2 inst✝² : CommSemiring R inst✝¹ : Semiring A inst✝ : Algebra R A a : A h : mulLeft R a = 0 ⊢ a = 0 [PROOFSTEP] rw [← mul_one a, ← @mulLeft_apply R _ _ _ _ _ _ a 1, h, LinearMap.zero_apply] [GOAL] case mpr R : Type u_1 A : Type u_2 inst✝² : CommSemiring R inst✝¹ : Semiring A inst✝ : Algebra R A a : A h : a = 0 ⊢ mulLeft R a = 0 [PROOFSTEP] rw [h] [GOAL] case mpr R : Type u_1 A : Type u_2 inst✝² : CommSemiring R inst✝¹ : Semiring A inst✝ : Algebra R A a : A h : a = 0 ⊢ mulLeft R 0 = 0 [PROOFSTEP] exact mulLeft_zero_eq_zero [GOAL] R : Type u_1 A : Type u_2 inst✝² : CommSemiring R inst✝¹ : Semiring A inst✝ : Algebra R A a : A ⊢ mulRight R a = 0 ↔ a = 0 [PROOFSTEP] constructor [GOAL] case mp R : Type u_1 A : Type u_2 inst✝² : CommSemiring R inst✝¹ : Semiring A inst✝ : Algebra R A a : A ⊢ mulRight R a = 0 → a = 0 [PROOFSTEP] intro h [GOAL] case mpr R : Type u_1 A : Type u_2 inst✝² : CommSemiring R inst✝¹ : Semiring A inst✝ : Algebra R A a : A ⊢ a = 0 → mulRight R a = 0 [PROOFSTEP] intro h [GOAL] case mp R : Type u_1 A : Type u_2 inst✝² : CommSemiring R inst✝¹ : Semiring A inst✝ : Algebra R A a : A h : mulRight R a = 0 ⊢ a = 0 [PROOFSTEP] rw [← one_mul a, ← @mulRight_apply R _ _ _ _ _ _ a 1, h, LinearMap.zero_apply] [GOAL] case mpr R : Type u_1 A : Type u_2 inst✝² : CommSemiring R inst✝¹ : Semiring A inst✝ : Algebra R A a : A h : a = 0 ⊢ mulRight R a = 0 [PROOFSTEP] rw [h] [GOAL] case mpr R : Type u_1 A : Type u_2 inst✝² : CommSemiring R inst✝¹ : Semiring A inst✝ : Algebra R A a : A h : a = 0 ⊢ mulRight R 0 = 0 [PROOFSTEP] exact mulRight_zero_eq_zero [GOAL] R : Type u_1 A : Type u_2 inst✝² : CommSemiring R inst✝¹ : Semiring A inst✝ : Algebra R A ⊢ mulLeft R 1 = id [PROOFSTEP] ext [GOAL] case h R : Type u_1 A : Type u_2 inst✝² : CommSemiring R inst✝¹ : Semiring A inst✝ : Algebra R A x✝ : A ⊢ ↑(mulLeft R 1) x✝ = ↑id x✝ [PROOFSTEP] simp only [LinearMap.id_coe, one_mul, id.def, mulLeft_apply] [GOAL] R : Type u_1 A : Type u_2 inst✝² : CommSemiring R inst✝¹ : Semiring A inst✝ : Algebra R A ⊢ mulRight R 1 = id [PROOFSTEP] ext [GOAL] case h R : Type u_1 A : Type u_2 inst✝² : CommSemiring R inst✝¹ : Semiring A inst✝ : Algebra R A x✝ : A ⊢ ↑(mulRight R 1) x✝ = ↑id x✝ [PROOFSTEP] simp only [LinearMap.id_coe, mul_one, id.def, mulRight_apply] [GOAL] R : Type u_1 A : Type u_2 inst✝² : CommSemiring R inst✝¹ : Semiring A inst✝ : Algebra R A a : A n : ℕ ⊢ mulLeft R a ^ n = mulLeft R (a ^ n) [PROOFSTEP] simpa only [mulLeft, ← Algebra.coe_lmul_eq_mul] using ((Algebra.lmul R A).map_pow a n).symm [GOAL] R : Type u_1 A : Type u_2 inst✝² : CommSemiring R inst✝¹ : Semiring A inst✝ : Algebra R A a : A n : ℕ ⊢ mulRight R a ^ n = mulRight R (a ^ n) [PROOFSTEP] simp only [mulRight, ← Algebra.coe_lmul_eq_mul] [GOAL] R : Type u_1 A : Type u_2 inst✝² : CommSemiring R inst✝¹ : Semiring A inst✝ : Algebra R A a : A n : ℕ ⊢ ↑(flip (mul R A)) a ^ n = ↑(flip (mul R A)) (a ^ n) [PROOFSTEP] exact LinearMap.coe_injective (((mulRight R a).coe_pow n).symm ▸ mul_right_iterate a n) [GOAL] R : Type u_1 A : Type u_2 inst✝³ : CommSemiring R inst✝² : Ring A inst✝¹ : Algebra R A inst✝ : NoZeroDivisors A x : A hx : x ≠ 0 ⊢ Function.Injective ↑(mulLeft R x) [PROOFSTEP] letI : Nontrivial A := ⟨⟨x, 0, hx⟩⟩ [GOAL] R : Type u_1 A : Type u_2 inst✝³ : CommSemiring R inst✝² : Ring A inst✝¹ : Algebra R A inst✝ : NoZeroDivisors A x : A hx : x ≠ 0 this : Nontrivial A := { exists_pair_ne := Exists.intro x (Exists.intro 0 hx) } ⊢ Function.Injective ↑(mulLeft R x) [PROOFSTEP] letI := NoZeroDivisors.to_isDomain A [GOAL] R : Type u_1 A : Type u_2 inst✝³ : CommSemiring R inst✝² : Ring A inst✝¹ : Algebra R A inst✝ : NoZeroDivisors A x : A hx : x ≠ 0 this✝ : Nontrivial A := { exists_pair_ne := Exists.intro x (Exists.intro 0 hx) } this : IsDomain A := NoZeroDivisors.to_isDomain A ⊢ Function.Injective ↑(mulLeft R x) [PROOFSTEP] exact mul_right_injective₀ hx [GOAL] R : Type u_1 A : Type u_2 inst✝³ : CommSemiring R inst✝² : Ring A inst✝¹ : Algebra R A inst✝ : NoZeroDivisors A x : A hx : x ≠ 0 ⊢ Function.Injective ↑(mulRight R x) [PROOFSTEP] letI : Nontrivial A := ⟨⟨x, 0, hx⟩⟩ [GOAL] R : Type u_1 A : Type u_2 inst✝³ : CommSemiring R inst✝² : Ring A inst✝¹ : Algebra R A inst✝ : NoZeroDivisors A x : A hx : x ≠ 0 this : Nontrivial A := { exists_pair_ne := Exists.intro x (Exists.intro 0 hx) } ⊢ Function.Injective ↑(mulRight R x) [PROOFSTEP] letI := NoZeroDivisors.to_isDomain A [GOAL] R : Type u_1 A : Type u_2 inst✝³ : CommSemiring R inst✝² : Ring A inst✝¹ : Algebra R A inst✝ : NoZeroDivisors A x : A hx : x ≠ 0 this✝ : Nontrivial A := { exists_pair_ne := Exists.intro x (Exists.intro 0 hx) } this : IsDomain A := NoZeroDivisors.to_isDomain A ⊢ Function.Injective ↑(mulRight R x) [PROOFSTEP] exact mul_left_injective₀ hx [GOAL] R : Type u_1 A : Type u_2 inst✝³ : CommSemiring R inst✝² : Ring A inst✝¹ : Algebra R A inst✝ : NoZeroDivisors A x : A hx : x ≠ 0 ⊢ Function.Injective ↑(↑(mul R A) x) [PROOFSTEP] letI : Nontrivial A := ⟨⟨x, 0, hx⟩⟩ [GOAL] R : Type u_1 A : Type u_2 inst✝³ : CommSemiring R inst✝² : Ring A inst✝¹ : Algebra R A inst✝ : NoZeroDivisors A x : A hx : x ≠ 0 this : Nontrivial A := { exists_pair_ne := Exists.intro x (Exists.intro 0 hx) } ⊢ Function.Injective ↑(↑(mul R A) x) [PROOFSTEP] letI := NoZeroDivisors.to_isDomain A [GOAL] R : Type u_1 A : Type u_2 inst✝³ : CommSemiring R inst✝² : Ring A inst✝¹ : Algebra R A inst✝ : NoZeroDivisors A x : A hx : x ≠ 0 this✝ : Nontrivial A := { exists_pair_ne := Exists.intro x (Exists.intro 0 hx) } this : IsDomain A := NoZeroDivisors.to_isDomain A ⊢ Function.Injective ↑(↑(mul R A) x) [PROOFSTEP] exact mul_right_injective₀ hx
/- Copyright (c) 2021 Shing Tak Lam. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Shing Tak Lam ! This file was ported from Lean 3 source module topology.homotopy.basic ! leanprover-community/mathlib commit 11c53f174270aa43140c0b26dabce5fc4a253e80 ! Please do not edit these lines, except to modify the commit id ! if you have ported upstream changes. -/ import Mathlib.Topology.Algebra.Order.ProjIcc import Mathlib.Topology.ContinuousFunction.Ordered import Mathlib.Topology.CompactOpen import Mathlib.Topology.UnitInterval /-! # Homotopy between functions In this file, we define a homotopy between two functions `f₀` and `f₁`. First we define `ContinuousMap.Homotopy` between the two functions, with no restrictions on the intermediate maps. Then, as in the formalisation in HOL-Analysis, we define `ContinuousMap.HomotopyWith f₀ f₁ P`, for homotopies between `f₀` and `f₁`, where the intermediate maps satisfy the predicate `P`. Finally, we define `ContinuousMap.HomotopyRel f₀ f₁ S`, for homotopies between `f₀` and `f₁` which are fixed on `S`. ## Definitions * `ContinuousMap.Homotopy f₀ f₁` is the type of homotopies between `f₀` and `f₁`. * `ContinuousMap.HomotopyWith f₀ f₁ P` is the type of homotopies between `f₀` and `f₁`, where the intermediate maps satisfy the predicate `P`. * `ContinuousMap.HomotopyEel f₀ f₁ S` is the type of homotopies between `f₀` and `f₁` which are fixed on `S`. For each of the above, we have * `refl f`, which is the constant homotopy from `f` to `f`. * `symm F`, which reverses the homotopy `F`. For example, if `F : ContinuousMap.Homotopy f₀ f₁`, then `F.symm : ContinuousMap.Homotopy f₁ f₀`. * `trans F G`, which concatenates the homotopies `F` and `G`. For example, if `F : ContinuousMap.Homotopy f₀ f₁` and `G : ContinuousMap.Homotopy f₁ f₂`, then `F.trans G : ContinuousMap.Homotopy f₀ f₂`. We also define the relations * `ContinuousMap.Homotopic f₀ f₁` is defined to be `Nonempty (ContinuousMap.Homotopy f₀ f₁)` * `ContinuousMap.HomotopicWith f₀ f₁ P` is defined to be `Nonempty (ContinuousMap.HomotopyWith f₀ f₁ P)` * `ContinuousMap.HomotopicRel f₀ f₁ P` is defined to be `Nonempty (ContinuousMap.HomotopyRel f₀ f₁ P)` and for `ContinuousMap.homotopic` and `ContinuousMap.homotopic_rel`, we also define the `setoid` and `quotient` in `C(X, Y)` by these relations. ## References - [HOL-Analysis formalisation](https://isabelle.in.tum.de/library/HOL/HOL-Analysis/Homotopy.html) -/ noncomputable section universe u v w variable {F : Type _} {X : Type u} {Y : Type v} {Z : Type w} variable [TopologicalSpace X] [TopologicalSpace Y] [TopologicalSpace Z] open unitInterval namespace ContinuousMap /-- `ContinuousMap.Homotopy f₀ f₁` is the type of homotopies from `f₀` to `f₁`. When possible, instead of parametrizing results over `(f : Homotopy f₀ f₁)`, you should parametrize over `{F : Type*} [HomotopyLike F f₀ f₁] (f : F)`. When you extend this structure, make sure to extend `ContinuousMap.HomotopyLike`. -/ structure Homotopy (f₀ f₁ : C(X, Y)) extends C(I × X, Y) where /-- value of the homotopy at 0 -/ map_zero_left : ∀ x, toFun (0, x) = f₀ x /-- value of the homotopy at 1 -/ map_one_left : ∀ x, toFun (1, x) = f₁ x #align continuous_map.homotopy ContinuousMap.Homotopy section /-- `ContinuousMap.HomotopyLike F f₀ f₁` states that `F` is a type of homotopies between `f₀` and `f₁`. You should extend this class when you extend `ContinuousMap.Homotopy`. -/ class HomotopyLike {X Y : outParam (Type _)} [TopologicalSpace X] [TopologicalSpace Y] (F : Type _) (f₀ f₁ : outParam <| C(X, Y)) extends ContinuousMapClass F (I × X) Y where /-- value of the homotopy at 0 -/ map_zero_left (f : F) : ∀ x, f (0, x) = f₀ x /-- value of the homotopy at 1 -/ map_one_left (f : F) : ∀ x, f (1, x) = f₁ x #align continuous_map.homotopy_like ContinuousMap.HomotopyLike end namespace Homotopy section variable {f₀ f₁ : C(X, Y)} instance : HomotopyLike (Homotopy f₀ f₁) f₀ f₁ where coe f := f.toFun coe_injective' f g h := by obtain ⟨⟨_, _⟩, _⟩ := f obtain ⟨⟨_, _⟩, _⟩ := g congr map_continuous f := f.continuous_toFun map_zero_left f := f.map_zero_left map_one_left f := f.map_one_left /- porting note: probably not needed anymore /-- Helper instance for when there's too many metavariables to apply `FunLike.hasCoeToFun` directly. -/ instance : CoeFun (Homotopy f₀ f₁) fun _ => I × X → Y := FunLike.hasCoeToFun -/ @[ext] theorem ext {F G : Homotopy f₀ f₁} (h : ∀ x, F x = G x) : F = G := FunLike.ext _ _ h #align continuous_map.homotopy.ext ContinuousMap.Homotopy.ext /-- See Note [custom simps projection]. We need to specify this projection explicitly in this case, because it is a composition of multiple projections. -/ def Simps.apply (F : Homotopy f₀ f₁) : I × X → Y := F #align continuous_map.homotopy.simps.apply ContinuousMap.Homotopy.Simps.apply initialize_simps_projections Homotopy (toContinuousMap_toFun → apply, -toContinuousMap) /-- Deprecated. Use `map_continuous` instead. -/ protected theorem continuous (F : Homotopy f₀ f₁) : Continuous F := F.continuous_toFun #align continuous_map.homotopy.continuous ContinuousMap.Homotopy.continuous @[simp] theorem apply_zero (F : Homotopy f₀ f₁) (x : X) : F (0, x) = f₀ x := F.map_zero_left x #align continuous_map.homotopy.apply_zero ContinuousMap.Homotopy.apply_zero @[simp] theorem apply_one (F : Homotopy f₀ f₁) (x : X) : F (1, x) = f₁ x := F.map_one_left x #align continuous_map.homotopy.apply_one ContinuousMap.Homotopy.apply_one @[simp] theorem coe_toContinuousMap (F : Homotopy f₀ f₁) : ⇑F.toContinuousMap = F := rfl #align continuous_map.homotopy.coe_to_continuous_map ContinuousMap.Homotopy.coe_toContinuousMap /-- Currying a homotopy to a continuous function fron `I` to `C(X, Y)`. -/ def curry (F : Homotopy f₀ f₁) : C(I, C(X, Y)) := F.toContinuousMap.curry #align continuous_map.homotopy.curry ContinuousMap.Homotopy.curry @[simp] theorem curry_apply (F : Homotopy f₀ f₁) (t : I) (x : X) : F.curry t x = F (t, x) := rfl #align continuous_map.homotopy.curry_apply ContinuousMap.Homotopy.curry_apply /-- Continuously extending a curried homotopy to a function from `ℝ` to `C(X, Y)`. -/ def extend (F : Homotopy f₀ f₁) : C(ℝ, C(X, Y)) := F.curry.IccExtend zero_le_one #align continuous_map.homotopy.extend ContinuousMap.Homotopy.extend theorem extend_apply_of_le_zero (F : Homotopy f₀ f₁) {t : ℝ} (ht : t ≤ 0) (x : X) : F.extend t x = f₀ x := by rw [← F.apply_zero] exact ContinuousMap.congr_fun (Set.IccExtend_of_le_left (zero_le_one' ℝ) F.curry ht) x #align continuous_map.homotopy.extend_apply_of_le_zero ContinuousMap.Homotopy.extend_apply_of_le_zero theorem extend_apply_of_one_le (F : Homotopy f₀ f₁) {t : ℝ} (ht : 1 ≤ t) (x : X) : F.extend t x = f₁ x := by rw [← F.apply_one] exact ContinuousMap.congr_fun (Set.IccExtend_of_right_le (zero_le_one' ℝ) F.curry ht) x #align continuous_map.homotopy.extend_apply_of_one_le ContinuousMap.Homotopy.extend_apply_of_one_le @[simp] theorem extend_apply_coe (F : Homotopy f₀ f₁) (t : I) (x : X) : F.extend t x = F (t, x) := ContinuousMap.congr_fun (Set.Icc_extend_coe (zero_le_one' ℝ) F.curry t) x #align continuous_map.homotopy.extend_apply_coe ContinuousMap.Homotopy.extend_apply_coe @[simp] theorem extend_apply_of_mem_I (F : Homotopy f₀ f₁) {t : ℝ} (ht : t ∈ I) (x : X) : F.extend t x = F (⟨t, ht⟩, x) := ContinuousMap.congr_fun (Set.IccExtend_of_mem (zero_le_one' ℝ) F.curry ht) x set_option linter.uppercaseLean3 false in #align continuous_map.homotopy.extend_apply_of_mem_I ContinuousMap.Homotopy.extend_apply_of_mem_I theorem congr_fun {F G : Homotopy f₀ f₁} (h : F = G) (x : I × X) : F x = G x := ContinuousMap.congr_fun (congr_arg _ h) x #align continuous_map.homotopy.congr_fun ContinuousMap.Homotopy.congr_fun theorem congr_arg (F : Homotopy f₀ f₁) {x y : I × X} (h : x = y) : F x = F y := F.toContinuousMap.congr_arg h #align continuous_map.homotopy.congr_arg ContinuousMap.Homotopy.congr_arg end /-- Given a continuous function `f`, we can define a `Homotopy f f` by `F (t, x) = f x` -/ @[simps] def refl (f : C(X, Y)) : Homotopy f f where toFun x := f x.2 map_zero_left _ := rfl map_one_left _ := rfl #align continuous_map.homotopy.refl ContinuousMap.Homotopy.refl instance : Inhabited (Homotopy (ContinuousMap.id X) (ContinuousMap.id X)) := ⟨Homotopy.refl _⟩ /-- Given a `Homotopy f₀ f₁`, we can define a `Homotopy f₁ f₀` by reversing the homotopy. -/ @[simps] def symm {f₀ f₁ : C(X, Y)} (F : Homotopy f₀ f₁) : Homotopy f₁ f₀ where toFun x := F (σ x.1, x.2) map_zero_left := by norm_num map_one_left := by norm_num #align continuous_map.homotopy.symm ContinuousMap.Homotopy.symm @[simp] theorem symm_symm {f₀ f₁ : C(X, Y)} (F : Homotopy f₀ f₁) : F.symm.symm = F := by ext simp #align continuous_map.homotopy.symm_symm ContinuousMap.Homotopy.symm_symm /-- Given `Homotopy f₀ f₁` and `Homotopy f₁ f₂`, we can define a `Homotopy f₀ f₂` by putting the first homotopy on `[0, 1/2]` and the second on `[1/2, 1]`. -/ def trans {f₀ f₁ f₂ : C(X, Y)} (F : Homotopy f₀ f₁) (G : Homotopy f₁ f₂) : Homotopy f₀ f₂ where toFun x := if (x.1 : ℝ) ≤ 1 / 2 then F.extend (2 * x.1) x.2 else G.extend (2 * x.1 - 1) x.2 continuous_toFun := by refine' continuous_if_le (continuous_induced_dom.comp continuous_fst) continuous_const (F.continuous.comp (by continuity)).continuousOn (G.continuous.comp (by continuity)).continuousOn _ rintro x hx rw [hx] norm_num map_zero_left x := by norm_num map_one_left x := by norm_num #align continuous_map.homotopy.trans ContinuousMap.Homotopy.trans theorem trans_apply {f₀ f₁ f₂ : C(X, Y)} (F : Homotopy f₀ f₁) (G : Homotopy f₁ f₂) (x : I × X) : (F.trans G) x = if h : (x.1 : ℝ) ≤ 1 / 2 then F (⟨2 * x.1, (unitInterval.mul_pos_mem_iff zero_lt_two).2 ⟨x.1.2.1, h⟩⟩, x.2) else G (⟨2 * x.1 - 1, unitInterval.two_mul_sub_one_mem_iff.2 ⟨(not_le.1 h).le, x.1.2.2⟩⟩, x.2) := show ite _ _ _ = _ by split_ifs <;> · rw [extend, ContinuousMap.coe_IccExtend, Set.IccExtend_of_mem] rfl #align continuous_map.homotopy.trans_apply ContinuousMap.Homotopy.trans_apply theorem symm_trans {f₀ f₁ f₂ : C(X, Y)} (F : Homotopy f₀ f₁) (G : Homotopy f₁ f₂) : (F.trans G).symm = G.symm.trans F.symm := by ext ⟨t, _⟩ rw [trans_apply, symm_apply, trans_apply] simp only [coe_symm_eq, symm_apply] split_ifs with h₁ h₂ h₂ . have ht : (t : ℝ) = 1 / 2 := -- porting note: this was proved by linarith in mathlib le_antisymm h₂ (by convert sub_le_comm.mp h₁ using 1; norm_num) simp only [ht] norm_num . congr 2 apply Subtype.ext simp only [coe_symm_eq] linarith . congr 2 apply Subtype.ext simp only [coe_symm_eq] linarith . exfalso -- porting note: this was proved by linarith in mathlib apply h₂ rw [sub_le_comm, not_le] at h₁ convert le_of_lt h₁ using 1 norm_num #align continuous_map.homotopy.symm_trans ContinuousMap.Homotopy.symm_trans /-- Casting a `Homotopy f₀ f₁` to a `Homotopy g₀ g₁` where `f₀ = g₀` and `f₁ = g₁`. -/ @[simps] def cast {f₀ f₁ g₀ g₁ : C(X, Y)} (F : Homotopy f₀ f₁) (h₀ : f₀ = g₀) (h₁ : f₁ = g₁) : Homotopy g₀ g₁ where toFun := F map_zero_left := by simp [← h₀] map_one_left := by simp [← h₁] #align continuous_map.homotopy.cast ContinuousMap.Homotopy.cast /-- If we have a `Homotopy f₀ f₁` and a `Homotopy g₀ g₁`, then we can compose them and get a `Homotopy (g₀.comp f₀) (g₁.comp f₁)`. -/ @[simps] def hcomp {f₀ f₁ : C(X, Y)} {g₀ g₁ : C(Y, Z)} (F : Homotopy f₀ f₁) (G : Homotopy g₀ g₁) : Homotopy (g₀.comp f₀) (g₁.comp f₁) where toFun x := G (x.1, F x) map_zero_left := by simp map_one_left := by simp #align continuous_map.homotopy.hcomp ContinuousMap.Homotopy.hcomp end Homotopy /-- Given continuous maps `f₀` and `f₁`, we say `f₀` and `f₁` are homotopic if there exists a `Homotopy f₀ f₁`. -/ def Homotopic (f₀ f₁ : C(X, Y)) : Prop := Nonempty (Homotopy f₀ f₁) #align continuous_map.homotopic ContinuousMap.Homotopic namespace Homotopic @[refl] theorem refl (f : C(X, Y)) : Homotopic f f := ⟨Homotopy.refl f⟩ #align continuous_map.homotopic.refl ContinuousMap.Homotopic.refl @[symm] theorem symm ⦃f g : C(X, Y)⦄ (h : Homotopic f g) : Homotopic g f := h.map Homotopy.symm #align continuous_map.homotopic.symm ContinuousMap.Homotopic.symm @[trans] theorem trans ⦃f g h : C(X, Y)⦄ (h₀ : Homotopic f g) (h₁ : Homotopic g h) : Homotopic f h := h₀.map2 Homotopy.trans h₁ #align continuous_map.homotopic.trans ContinuousMap.Homotopic.trans theorem hcomp {f₀ f₁ : C(X, Y)} {g₀ g₁ : C(Y, Z)} (h₀ : Homotopic f₀ f₁) (h₁ : Homotopic g₀ g₁) : Homotopic (g₀.comp f₀) (g₁.comp f₁) := h₀.map2 Homotopy.hcomp h₁ #align continuous_map.homotopic.hcomp ContinuousMap.Homotopic.hcomp theorem equivalence : Equivalence (@Homotopic X Y _ _) := ⟨refl, by apply symm, by apply trans⟩ #align continuous_map.homotopic.equivalence ContinuousMap.Homotopic.equivalence end Homotopic /-- The type of homotopies between `f₀ f₁ : C(X, Y)`, where the intermediate maps satisfy the predicate `P : C(X, Y) → Prop` -/ structure HomotopyWith (f₀ f₁ : C(X, Y)) (P : C(X, Y) → Prop) extends Homotopy f₀ f₁ where -- porting note: todo: use `toHomotopy.curry t` /-- the intermediate maps of the homotopy satisfy the property -/ prop' : ∀ t, P ⟨fun x => toFun (t, x), Continuous.comp continuous_toFun (continuous_const.prod_mk continuous_id')⟩ #align continuous_map.homotopy_with ContinuousMap.HomotopyWith namespace HomotopyWith section variable {f₀ f₁ : C(X, Y)} {P : C(X, Y) → Prop} instance : CoeFun (HomotopyWith f₀ f₁ P) fun _ => I × X → Y := ⟨fun F => F.toFun⟩ /- porting note: this lemma seems unnecessary @[simp] theorem coe_toFun (F : HomotopyWith f₀ f₁ P) : ⇑F = F.toFun := by rfl-/ theorem coeFn_injective : @Function.Injective (HomotopyWith f₀ f₁ P) (I × X → Y) (⇑) := by rintro ⟨⟨⟨F, _⟩, _⟩, _⟩ ⟨⟨⟨G, _⟩, _⟩, _⟩ h congr 3 #align continuous_map.homotopy_with.coe_fn_injective ContinuousMap.HomotopyWith.coeFn_injective @[ext] theorem ext {F G : HomotopyWith f₀ f₁ P} (h : ∀ x, F x = G x) : F = G := by apply coeFn_injective funext apply h #align continuous_map.homotopy_with.ext ContinuousMap.HomotopyWith.ext /-- See Note [custom simps projection]. We need to specify this projection explicitly in this case, because it is a composition of multiple projections. -/ def Simps.apply (F : HomotopyWith f₀ f₁ P) : I × X → Y := F #align continuous_map.homotopy_with.simps.apply ContinuousMap.HomotopyWith.Simps.apply initialize_simps_projections HomotopyWith (toHomotopy_toContinuousMap_toFun → apply, -toHomotopy_toContinuousMap) @[continuity] protected theorem continuous (F : HomotopyWith f₀ f₁ P) : Continuous F := F.continuous_toFun #align continuous_map.homotopy_with.continuous ContinuousMap.HomotopyWith.continuous @[simp] theorem apply_zero (F : HomotopyWith f₀ f₁ P) (x : X) : F (0, x) = f₀ x := F.map_zero_left x #align continuous_map.homotopy_with.apply_zero ContinuousMap.HomotopyWith.apply_zero @[simp] theorem apply_one (F : HomotopyWith f₀ f₁ P) (x : X) : F (1, x) = f₁ x := F.map_one_left x #align continuous_map.homotopy_with.apply_one ContinuousMap.HomotopyWith.apply_one @[simp] theorem coe_toContinuousMap (F : HomotopyWith f₀ f₁ P) : ⇑F.toContinuousMap = F := rfl #align continuous_map.homotopy_with.coe_to_continuous_map ContinuousMap.HomotopyWith.coe_toContinuousMap -- porting note: removed @[simp] as it makes the linter timeout theorem coe_toHomotopy (F : HomotopyWith f₀ f₁ P) : ⇑F.toHomotopy = F := rfl #align continuous_map.homotopy_with.coe_to_homotopy ContinuousMap.HomotopyWith.coe_toHomotopy theorem prop (F : HomotopyWith f₀ f₁ P) (t : I) : P (F.toHomotopy.curry t) := F.prop' t #align continuous_map.homotopy_with.prop ContinuousMap.HomotopyWith.prop end variable {P : C(X, Y) → Prop} /-- Given a continuous function `f`, and a proof `h : P f`, we can define a `HomotopyWith f f P` by `F (t, x) = f x` -/ @[simps!] def refl (f : C(X, Y)) (hf : P f) : HomotopyWith f f P := { Homotopy.refl f with prop' := fun _ => hf } #align continuous_map.homotopy_with.refl ContinuousMap.HomotopyWith.refl instance : Inhabited (HomotopyWith (ContinuousMap.id X) (ContinuousMap.id X) fun _ => True) := ⟨HomotopyWith.refl _ trivial⟩ /-- Given a `HomotopyWith f₀ f₁ P`, we can define a `HomotopyWith f₁ f₀ P` by reversing the homotopy. -/ --@[simps] def symm {f₀ f₁ : C(X, Y)} (F : HomotopyWith f₀ f₁ P) : HomotopyWith f₁ f₀ P := { F.toHomotopy.symm with prop' := fun t => F.prop (σ t) } #align continuous_map.homotopy_with.symm ContinuousMap.HomotopyWith.symm @[simp] theorem symm_symm {f₀ f₁ : C(X, Y)} (F : HomotopyWith f₀ f₁ P) : F.symm.symm = F := ext <| Homotopy.congr_fun <| Homotopy.symm_symm _ #align continuous_map.homotopy_with.symm_symm ContinuousMap.HomotopyWith.symm_symm /-- Given `HomotopyWith f₀ f₁ P` and `HomotopyWith f₁ f₂ P`, we can define a `HomotopyWith f₀ f₂ P` by putting the first homotopy on `[0, 1/2]` and the second on `[1/2, 1]`. -/ def trans {f₀ f₁ f₂ : C(X, Y)} (F : HomotopyWith f₀ f₁ P) (G : HomotopyWith f₁ f₂ P) : HomotopyWith f₀ f₂ P := { F.toHomotopy.trans G.toHomotopy with prop' := fun t => by simp only [Homotopy.trans] change P ⟨fun _ => ite ((t : ℝ) ≤ _) _ _, _⟩ split_ifs · exact F.extendProp _ · exact G.extendProp _ } #align continuous_map.homotopy_with.trans ContinuousMap.HomotopyWith.trans theorem trans_apply {f₀ f₁ f₂ : C(X, Y)} (F : HomotopyWith f₀ f₁ P) (G : HomotopyWith f₁ f₂ P) (x : I × X) : (F.trans G) x = if h : (x.1 : ℝ) ≤ 1 / 2 then F (⟨2 * x.1, (unitInterval.mul_pos_mem_iff zero_lt_two).2 ⟨x.1.2.1, h⟩⟩, x.2) else G (⟨2 * x.1 - 1, unitInterval.two_mul_sub_one_mem_iff.2 ⟨(not_le.1 h).le, x.1.2.2⟩⟩, x.2) := Homotopy.trans_apply _ _ _ #align continuous_map.homotopy_with.trans_apply ContinuousMap.HomotopyWith.trans_apply theorem symm_trans {f₀ f₁ f₂ : C(X, Y)} (F : HomotopyWith f₀ f₁ P) (G : HomotopyWith f₁ f₂ P) : (F.trans G).symm = G.symm.trans F.symm := ext <| Homotopy.congr_fun <| Homotopy.symm_trans _ _ #align continuous_map.homotopy_with.symm_trans ContinuousMap.HomotopyWith.symm_trans /-- Casting a `HomotopyWith f₀ f₁ P` to a `HomotopyWith g₀ g₁ P` where `f₀ = g₀` and `f₁ = g₁`. -/ @[simp] def cast {f₀ f₁ g₀ g₁ : C(X, Y)} (F : HomotopyWith f₀ f₁ P) (h₀ : f₀ = g₀) (h₁ : f₁ = g₁) : HomotopyWith g₀ g₁ P := { F.toHomotopy.cast h₀ h₁ with prop' := F.prop } #align continuous_map.homotopy_with.cast ContinuousMap.HomotopyWith.cast end HomotopyWith /-- Given continuous maps `f₀` and `f₁`, we say `f₀` and `f₁` are homotopic with respect to the predicate `P` if there exists a `HomotopyWith f₀ f₁ P`. -/ def HomotopicWith (f₀ f₁ : C(X, Y)) (P : C(X, Y) → Prop) : Prop := Nonempty (HomotopyWith f₀ f₁ P) #align continuous_map.homotopic_with ContinuousMap.HomotopicWith namespace HomotopicWith variable {P : C(X, Y) → Prop} -- porting note: removed @[refl] theorem refl (f : C(X, Y)) (hf : P f) : HomotopicWith f f P := ⟨HomotopyWith.refl f hf⟩ #align continuous_map.homotopic_with.refl ContinuousMap.HomotopicWith.refl @[symm] theorem symm ⦃f g : C(X, Y)⦄ (h : HomotopicWith f g P) : HomotopicWith g f P := ⟨h.some.symm⟩ #align continuous_map.homotopic_with.symm ContinuousMap.HomotopicWith.symm @[trans] theorem trans ⦃f g h : C(X, Y)⦄ (h₀ : HomotopicWith f g P) (h₁ : HomotopicWith g h P) : HomotopicWith f h P := ⟨h₀.some.trans h₁.some⟩ #align continuous_map.homotopic_with.trans ContinuousMap.HomotopicWith.trans end HomotopicWith /-- A `HomotopyRel f₀ f₁ S` is a homotopy between `f₀` and `f₁` which is fixed on the points in `S`. -/ abbrev HomotopyRel (f₀ f₁ : C(X, Y)) (S : Set X) := HomotopyWith f₀ f₁ fun f => ∀ x ∈ S, f x = f₀ x ∧ f x = f₁ x #align continuous_map.homotopy_rel ContinuousMap.HomotopyRel namespace HomotopyRel section variable {f₀ f₁ : C(X, Y)} {S : Set X} theorem eq_fst (F : HomotopyRel f₀ f₁ S) (t : I) {x : X} (hx : x ∈ S) : F (t, x) = f₀ x := (F.prop t x hx).1 #align continuous_map.homotopy_rel.eq_fst ContinuousMap.HomotopyRel.eq_fst theorem eq_snd (F : HomotopyRel f₀ f₁ S) (t : I) {x : X} (hx : x ∈ S) : F (t, x) = f₁ x := (F.prop t x hx).2 #align continuous_map.homotopy_rel.eq_snd ContinuousMap.HomotopyRel.eq_snd theorem fst_eq_snd (F : HomotopyRel f₀ f₁ S) {x : X} (hx : x ∈ S) : f₀ x = f₁ x := F.eq_fst 0 hx ▸ F.eq_snd 0 hx #align continuous_map.homotopy_rel.fst_eq_snd ContinuousMap.HomotopyRel.fst_eq_snd end variable {f₀ f₁ f₂ : C(X, Y)} {S : Set X} /-- Given a map `f : C(X, Y)` and a set `S`, we can define a `HomotopyEel f f S` by setting `F (t, x) = f x` for all `t`. This is defined using `HomotopyWith.refl`, but with the proof filled in. -/ @[simps!] def refl (f : C(X, Y)) (S : Set X) : HomotopyRel f f S := HomotopyWith.refl f fun _ _ => ⟨rfl, rfl⟩ #align continuous_map.homotopy_rel.refl ContinuousMap.HomotopyRel.refl /-- Given a `HomotopyRel f₀ f₁ S`, we can define a `HomotopyRel f₁ f₀ S` by reversing the homotopy. -/ @[simp] def symm (F : HomotopyRel f₀ f₁ S) : HomotopyRel f₁ f₀ S := { HomotopyWith.symm F with prop' := fun _ _ hx => ⟨F.eq_snd _ hx, F.eq_fst _ hx⟩ } #align continuous_map.homotopy_rel.symm ContinuousMap.HomotopyRel.symm -- porting note: removed @[simp] as the linter complains theorem symm_symm (F : HomotopyRel f₀ f₁ S) : F.symm.symm = F := HomotopyWith.symm_symm F #align continuous_map.homotopy_rel.symm_symm ContinuousMap.HomotopyRel.symm_symm /-- Given `HomotopyRel f₀ f₁ S` and `HomotopyRel f₁ f₂ S`, we can define a `HomotopyRel f₀ f₂ S` by putting the first homotopy on `[0, 1/2]` and the second on `[1/2, 1]`. -/ def trans (F : HomotopyRel f₀ f₁ S) (G : HomotopyRel f₁ f₂ S) : HomotopyRel f₀ f₂ S := { Homotopy.trans F.toHomotopy G.toHomotopy with prop' := fun t => by intro x hx simp only [Homotopy.trans] change (⟨fun _ => ite ((t : ℝ) ≤ _) _ _, _⟩ : C(X, Y)) _ = _ ∧ _ = _ split_ifs · simp [(HomotopyWith.extendProp F (2 * t) x hx).1, F.fst_eq_snd hx, G.fst_eq_snd hx] · simp [(HomotopyWith.extendProp G (2 * t - 1) x hx).1, F.fst_eq_snd hx, G.fst_eq_snd hx] } #align continuous_map.homotopy_rel.trans ContinuousMap.HomotopyRel.trans theorem trans_apply (F : HomotopyRel f₀ f₁ S) (G : HomotopyRel f₁ f₂ S) (x : I × X) : (F.trans G) x = if h : (x.1 : ℝ) ≤ 1 / 2 then F (⟨2 * x.1, (unitInterval.mul_pos_mem_iff zero_lt_two).2 ⟨x.1.2.1, h⟩⟩, x.2) else G (⟨2 * x.1 - 1, unitInterval.two_mul_sub_one_mem_iff.2 ⟨(not_le.1 h).le, x.1.2.2⟩⟩, x.2) := Homotopy.trans_apply _ _ _ #align continuous_map.homotopy_rel.trans_apply ContinuousMap.HomotopyRel.trans_apply theorem symm_trans (F : HomotopyRel f₀ f₁ S) (G : HomotopyRel f₁ f₂ S) : (F.trans G).symm = G.symm.trans F.symm := HomotopyWith.ext <| Homotopy.congr_fun <| Homotopy.symm_trans _ _ #align continuous_map.homotopy_rel.symm_trans ContinuousMap.HomotopyRel.symm_trans /-- Casting a `HomotopyRel f₀ f₁ S` to a `HomotopyRel g₀ g₁ S` where `f₀ = g₀` and `f₁ = g₁`. -/ @[simp] def cast {f₀ f₁ g₀ g₁ : C(X, Y)} (F : HomotopyRel f₀ f₁ S) (h₀ : f₀ = g₀) (h₁ : f₁ = g₁) : HomotopyRel g₀ g₁ S := { Homotopy.cast F.toHomotopy h₀ h₁ with prop' := fun t x hx => by simp only [← h₀, ← h₁] exact F.prop t x hx } #align continuous_map.homotopy_rel.cast ContinuousMap.HomotopyRel.cast end HomotopyRel /-- Given continuous maps `f₀` and `f₁`, we say `f₀` and `f₁` are homotopic relative to a set `S` if there exists a `HomotopyRel f₀ f₁ S`. -/ def HomotopicRel (f₀ f₁ : C(X, Y)) (S : Set X) : Prop := Nonempty (HomotopyRel f₀ f₁ S) #align continuous_map.homotopic_rel ContinuousMap.HomotopicRel namespace HomotopicRel variable {S : Set X} -- porting note: removed @[refl] theorem refl (f : C(X, Y)) : HomotopicRel f f S := ⟨HomotopyRel.refl f S⟩ #align continuous_map.homotopic_rel.refl ContinuousMap.HomotopicRel.refl @[symm] theorem symm ⦃f g : C(X, Y)⦄ (h : HomotopicRel f g S) : HomotopicRel g f S := h.map HomotopyRel.symm #align continuous_map.homotopic_rel.symm ContinuousMap.HomotopicRel.symm @[trans] theorem trans ⦃f g h : C(X, Y)⦄ (h₀ : HomotopicRel f g S) (h₁ : HomotopicRel g h S) : HomotopicRel f h S := h₀.map2 HomotopyRel.trans h₁ #align continuous_map.homotopic_rel.trans ContinuousMap.HomotopicRel.trans theorem equivalence : Equivalence fun f g : C(X, Y) => HomotopicRel f g S := ⟨refl, by apply symm, by apply trans⟩ #align continuous_map.homotopic_rel.equivalence ContinuousMap.HomotopicRel.equivalence end HomotopicRel end ContinuousMap
-- Lemma for `Constructive.Axiom.Properties.Base` {-# OPTIONS --without-K --safe #-} module Constructive.Axiom.Properties.Base.Lemma where -- agda-stdlib open import Data.Empty open import Data.Nat import Data.Nat.Properties as ℕₚ open import Data.Product open import Data.Sum as Sum open import Data.Sum.Properties open import Function.Base open import Relation.Binary.PropositionalEquality open import Relation.Nullary -- agda-misc open import Constructive.Combinators open import Constructive.Common -- lemma for `ℕ-llpo⇒mp∨` ℕ≤-any-dec : ∀ {p} {P : ℕ → Set p} → DecU P → DecU (λ n → ∃ λ m → m ≤ n × P m) ℕ≤-any-dec {P = P} P? zero with P? 0 ... | inj₁ P0 = inj₁ (0 , ℕₚ.≤-refl , P0) ... | inj₂ ¬P0 = inj₂ λ {(m , m≤0 , Pm) → ¬P0 (subst P (ℕₚ.n≤0⇒n≡0 m≤0) Pm)} ℕ≤-any-dec P? (suc n) with P? 0 ... | inj₁ P0 = inj₁ (0 , (z≤n , P0)) ... | inj₂ ¬P0 with ℕ≤-any-dec (P? ∘ suc) n ℕ≤-any-dec {P = P} P? (suc n) | inj₂ ¬P0 | inj₁ (m , m≤n , Psm) = inj₁ (suc m , s≤s m≤n , Psm) ℕ≤-any-dec {P = P} P? (suc n) | inj₂ ¬P0 | inj₂ ¬∃m→m≤n×Psm = inj₂ f where f : (∃ λ m → m ≤ suc n × P m) → ⊥ f (zero , m≤sn , Pm) = ¬P0 Pm f (suc m , sm≤sn , Psm) = ¬∃m→m≤n×Psm (m , (ℕₚ.≤-pred sm≤sn , Psm)) private 1+n≰0 : ∀ n → ¬ (suc n ≤ 0) 1+n≰0 n () module _ {p} {P : ℕ → Set p} (P? : DecU P) where ℕ<-any-dec : DecU (λ n → ∃ λ m → m < n × P m) ℕ<-any-dec zero = inj₂ λ {(m , m<0 , _) → 1+n≰0 m m<0} ℕ<-any-dec (suc n) with ℕ≤-any-dec P? n ... | inj₁ (m , m≤n , Pm) = inj₁ (m , s≤s m≤n , Pm) ... | inj₂ ¬∃m→m≤n×Pm = inj₂ (contraposition f ¬∃m→m≤n×Pm) where f : (∃ λ m → suc m ≤ suc n × P m) → ∃ λ m → m ≤ n × P m f (m , sm≤sn , Pm) = m , (ℕₚ.≤-pred sm≤sn , Pm) ℕ≤-all-dec : DecU (λ n → ∀ m → m ≤ n → P m) ℕ≤-all-dec n with ℕ≤-any-dec (¬-DecU P?) n ... | inj₁ (m , m≤n , ¬Pm) = inj₂ λ ∀i→i≤n→Pi → ¬Pm (∀i→i≤n→Pi m m≤n) ... | inj₂ ¬∃m→m≤n׬Pm = inj₁ λ m m≤n → DecU⇒stable P? m λ ¬Pm → ¬∃m→m≤n׬Pm (m , m≤n , ¬Pm) module _ {p} {P : ℕ → Set p} (P? : DecU P) where ℕ<-all-dec : DecU (λ n → ∀ m → m < n → P m) ℕ<-all-dec n with ℕ<-any-dec (¬-DecU P?) n ... | inj₁ (m , m<n , ¬Pm) = inj₂ λ ∀i→i<n→Pi → ¬Pm (∀i→i<n→Pi m m<n) ... | inj₂ ¬∃m→m<n׬Pm = inj₁ λ m m<n → DecU⇒stable P? m λ ¬Pm → ¬∃m→m<n׬Pm (m , m<n , ¬Pm) -- lemma for llpo-ℕ⇒llpo lemma₁ : ∀ {p} {P : ℕ → Set p} → (∀ m n → m ≢ n → P m ⊎ P n) → ∃ (λ n → ¬ P (2 * n)) → ∃ (λ n → ¬ P (suc (2 * n))) → ⊥ lemma₁ ∀mn→m≢n→Pm⊎Pn (m , ¬P2m) (n , ¬P1+2n) with ∀mn→m≢n→Pm⊎Pn (2 * m) (suc (2 * n)) (ℕₚ.even≢odd m n) ... | inj₁ P2m = ¬P2m P2m ... | inj₂ P1+2n = ¬P1+2n P1+2n parity : ℕ → ℕ ⊎ ℕ parity zero = inj₁ zero parity (suc zero) = inj₂ zero parity (suc (suc n)) = Sum.map suc suc (parity n) parity-even : ∀ n → parity (2 * n) ≡ inj₁ n parity-even zero = refl parity-even (suc n) = begin parity (2 * (suc n)) ≡⟨ cong parity (ℕₚ.*-distribˡ-+ 2 1 n) ⟩ parity (2 + 2 * n) ≡⟨⟩ Sum.map suc suc (parity (2 * n)) ≡⟨ cong (Sum.map suc suc) (parity-even n) ⟩ Sum.map suc suc (inj₁ n) ≡⟨⟩ inj₁ (suc n) ∎ where open ≡-Reasoning parity-odd : ∀ n → parity (suc (2 * n)) ≡ inj₂ n parity-odd zero = refl parity-odd (suc n) = begin parity (suc (2 * suc n)) ≡⟨ cong (parity ∘ suc) $ ℕₚ.*-distribˡ-+ 2 1 n ⟩ parity (1 + (2 * 1 + 2 * n)) ≡⟨⟩ parity (2 + (1 + 2 * n)) ≡⟨⟩ Sum.map suc suc (parity (1 + 2 * n)) ≡⟨ cong (Sum.map suc suc) (parity-odd n) ⟩ Sum.map suc suc (inj₂ n) ≡⟨⟩ inj₂ (suc n) ∎ where open ≡-Reasoning Sum-map-injective : ∀ {a b c d} {A : Set a} {B : Set b} {C : Set c} {D : Set d} {f : A → C} {g : B → D} → (∀ {u v} → f u ≡ f v → u ≡ v) → (∀ {u v} → g u ≡ g v → u ≡ v) → ∀ {x y} → Sum.map f g x ≡ Sum.map f g y → x ≡ y Sum-map-injective f-inj g-inj {inj₁ x} {inj₁ x₁} eq = cong inj₁ (f-inj (inj₁-injective eq)) Sum-map-injective f-ing g-inj {inj₂ y} {inj₂ y₁} eq = cong inj₂ (g-inj (inj₂-injective eq)) parity-injective : ∀ {m n} → parity m ≡ parity n → m ≡ n parity-injective {zero} {zero} pm≡pn = refl parity-injective {zero} {suc (suc n)} pm≡pn with parity n parity-injective {zero} {suc (suc n)} () | inj₁ _ parity-injective {zero} {suc (suc n)} () | inj₂ _ parity-injective {suc (suc m)} {zero} pm≡pn with parity m parity-injective {suc (suc m)} {zero} () | inj₁ _ parity-injective {suc (suc m)} {zero} () | inj₂ _ parity-injective {suc zero} {suc zero} pm≡pn = refl parity-injective {suc zero} {suc (suc n)} pm≡pn with parity n parity-injective {suc zero} {suc (suc n)} () | inj₁ _ parity-injective {suc zero} {suc (suc n)} () | inj₂ _ parity-injective {suc (suc m)} {suc zero} pm≡pn with parity m parity-injective {suc (suc m)} {suc zero} () | inj₁ _ parity-injective {suc (suc m)} {suc zero} () | inj₂ _ parity-injective {suc (suc m)} {suc (suc n)} pm≡pn = cong (suc ∘ suc) (parity-injective (Sum-map-injective ℕₚ.suc-injective ℕₚ.suc-injective pm≡pn)) parity-even′ : ∀ {m n} → parity m ≡ inj₁ n → m ≡ 2 * n parity-even′ {m} {n} eq = parity-injective (begin parity m ≡⟨ eq ⟩ inj₁ n ≡⟨ sym $ parity-even n ⟩ parity (2 * n) ∎) where open ≡-Reasoning parity-odd′ : ∀ {m n} → parity m ≡ inj₂ n → m ≡ 1 + 2 * n parity-odd′ {m} {n} eq = parity-injective (begin parity m ≡⟨ eq ⟩ inj₂ n ≡⟨ sym $ parity-odd n ⟩ parity (1 + 2 * n) ∎) where open ≡-Reasoning mix : ℕ ⊎ ℕ → ℕ mix = Sum.[ (λ n → 2 * n) , (λ n → 1 + 2 * n) ] parity-mix : ∀ s → parity (mix s) ≡ s parity-mix (inj₁ n) = parity-even n parity-mix (inj₂ n) = parity-odd n mix-parity : ∀ n → mix (parity n) ≡ n mix-parity n = parity-injective (parity-mix (parity n))
//================================================================================================== /*! @file Defines the meta::primitive_of meta-function @copyright 2016 NumScale SAS Distributed under the Boost Software License, Version 1.0. (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt) **/ //================================================================================================== #ifndef BOOST_SIMD_DETAIL_DISPATCH_META_PRIMITIVE_OF_HPP_INCLUDED #define BOOST_SIMD_DETAIL_DISPATCH_META_PRIMITIVE_OF_HPP_INCLUDED #include <boost/simd/detail/dispatch/detail/primitive_of.hpp> namespace boost { namespace dispatch { /*! @ingroup group-introspection @brief Primitive type computation For any given type @c T, returns the primitive type, i.e the most underlying type of @c T. @tparam Type to extract a primitive from. @par Models: @metafunction @par Semantic: For a given type T, @code using type = boost::dispatch::primitive_of<T>; @endcode is defined so that : @code std::is_same<type, boost::dispatch::value_of_t<type>>::value @endcode evaluates to @c true. Put in another way, primitive_of is a recursive application of value_of so that every nested type are traversed to find the most underlying type of @c T. @see value_of @see model_of **/ template<typename T> struct primitive_of : detail::primitive_of<boost::dispatch::value_of_t<T>, T> {}; template<typename T> using primitive_of_t = typename primitive_of<T>::type; } } #endif
import numpy as np import theano from theano import tensor #========================================================================================= # Data type #========================================================================================= def asarray(x): return np.asarray(x, dtype=theano.config.floatX) def zeros(shape): return np.zeros(shape, dtype=theano.config.floatX) def shared(x, name=None): return theano.shared(np.asarray(x, theano.config.floatX), name=name) def clipping_multiplier(norm, max_norm): """ Multiplier for renormalizing a vector. """ return tensor.switch(norm > max_norm, max_norm/norm, 1) def choice(rng, a, size=1, replace=True, p=None): """ A version of `numpy.random.RandomState.choice` that works with `float32`. """ # Format and Verify input if isinstance(a, int): if a > 0: pop_size = a #population size else: raise ValueError("a must be greater than 0") else: a = np.array(a, ndmin=1, copy=0) if a.ndim != 1: raise ValueError("a must be 1-dimensional") pop_size = a.size if pop_size is 0: raise ValueError("a must be non-empty") if p is not None: p = np.array(p, dtype=p.dtype, ndmin=1, copy=0) if p.ndim != 1: raise ValueError("p must be 1-dimensional") if p.size != pop_size: raise ValueError("a and p must have same size") if np.any(p < 0): raise ValueError("probabilities are not non-negative") if not np.allclose(p.sum(), 1): raise ValueError("probabilities do not sum to 1") # Actual sampling if replace: if p is not None: cdf = p.cumsum() cdf /= cdf[-1] uniform_samples = rng.rand(size) idx = cdf.searchsorted(uniform_samples, side='right') else: idx = rng.randint(0, pop_size, size=size) else: if size > pop_size: raise ValueError(''.join(["Cannot take a larger sample than ", "population when 'replace=False'"])) if p is not None: if np.sum(p > 0) < size: raise ValueError("Fewer non-zero entries in p than size") n_uniq = 0 p = p.copy() found = np.zeros(size, dtype=np.int) while n_uniq < size: x = rng.rand(size - n_uniq) if n_uniq > 0: p[found[0:n_uniq]] = 0 cdf = np.cumsum(p) cdf /= cdf[-1] new = cdf.searchsorted(x, side='right') new = np.unique(new) found[n_uniq:n_uniq + new.size] = new n_uniq += new.size idx = found else: idx = rng.permutation(pop_size)[:size] #Use samples as indices for a if a is array-like #if isinstance(a, int): # print("HERE") assert len(idx) == 1 return idx[0] #else: # return a.take(idx) #========================================================================================= # Output activations #========================================================================================= if hasattr(tensor.nnet, 'relu'): def relu(x): return tensor.nnet.relu(x) else: print("No ReLU, using switch.") def relu(x): return tensor.switch(x > 0, x, 0) #def relu(x): # return tensor.nnet.relu(x) # #return tensor.switch(x > upper, upper, tensor.nnet.relu(x)) def softmax(x, temp=1): y = tensor.exp(x/temp) return y/y.sum(-1, keepdims=True) def log_softmax(x, temp=1): y = x/temp y -= y.max(axis=-1, keepdims=True) return y - tensor.log(tensor.exp(y).sum(axis=-1, keepdims=True)) def normalization(x): x2 = tensor.sqr(x) + 1e-6 return x2/tensor.sum(x2, axis=-1, keepdims=True) def normalization3(x): sh = x.shape x = x.reshape((sh[0]*sh[1], sh[2])) y = normalization(x) y = y.reshape(sh) return y #========================================================================================= # GPU #========================================================================================= def get_processor_type(): """ Test whether the GPU is being used, based on the example in http://deeplearning.net/software/theano/tutorial/using_gpu.html """ rng = np.random.RandomState(1234) n = 10*30*768 x = shared(rng.rand(n)) f = theano.function([], tensor.exp(x)) if np.any([isinstance(x.op, tensor.Elemwise) and ('Gpu' not in type(x.op).__name__) for x in f.maker.fgraph.toposort()]): return 'cpu' return 'gpu'
/- Copyright (c) 2020 Kenny Lau. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kenny Lau -/ import algebra.algebra.tower import data.polynomial.algebra_map /-! # Algebra towers for polynomial This file proves some basic results about the algebra tower structure for the type `polynomial R`. This structure itself is provided elsewhere as `polynomial.is_scalar_tower` -/ universes u v w u₁ variables (R : Type u) (S : Type v) (A : Type w) (B : Type u₁) namespace is_scalar_tower section semiring variables [comm_semiring R] [comm_semiring S] [semiring A] [semiring B] variables [algebra R S] [algebra S A] [algebra S B] [algebra R A] [algebra R B] variables [is_scalar_tower R S A] [is_scalar_tower R S B] variables (R S A) {B} theorem aeval_apply (x : A) (p : polynomial R) : polynomial.aeval x p = polynomial.aeval x (polynomial.map (algebra_map R S) p) := by rw [polynomial.aeval_def, polynomial.aeval_def, polynomial.eval₂_map, algebra_map_eq R S A] end semiring section comm_semiring variables [comm_semiring R] [comm_semiring A] [semiring B] variables [algebra R A] [algebra A B] [algebra R B] [is_scalar_tower R A B] lemma algebra_map_aeval (x : A) (p : polynomial R) : algebra_map A B (polynomial.aeval x p) = polynomial.aeval (algebra_map A B x) p := by rw [polynomial.aeval_def, polynomial.aeval_def, polynomial.hom_eval₂, ←is_scalar_tower.algebra_map_eq] lemma aeval_eq_zero_of_aeval_algebra_map_eq_zero {x : A} {p : polynomial R} (h : function.injective (algebra_map A B)) (hp : polynomial.aeval (algebra_map A B x) p = 0) : polynomial.aeval x p = 0 := begin rw [← algebra_map_aeval, ← (algebra_map A B).map_zero] at hp, exact h hp, end lemma aeval_eq_zero_of_aeval_algebra_map_eq_zero_field {R A B : Type*} [comm_semiring R] [field A] [comm_semiring B] [nontrivial B] [algebra R A] [algebra R B] [algebra A B] [is_scalar_tower R A B] {x : A} {p : polynomial R} (h : polynomial.aeval (algebra_map A B x) p = 0) : polynomial.aeval x p = 0 := aeval_eq_zero_of_aeval_algebra_map_eq_zero R A B (algebra_map A B).injective h end comm_semiring end is_scalar_tower namespace subalgebra open is_scalar_tower section comm_semiring variables (R) {S A} [comm_semiring R] [comm_semiring S] [comm_semiring A] variables [algebra R S] [algebra S A] [algebra R A] [is_scalar_tower R S A] @[simp] end comm_semiring end subalgebra
State Before: K : Type u inst✝² : CommRing K p : ℕ inst✝¹ : Fact (Nat.Prime p) inst✝ : CharP K p x : ℕ × K ⊢ ↑(frobenius (PerfectClosure K p) p) (mk K p x) = mk K p (x.fst, x.snd ^ p) State After: K : Type u inst✝² : CommRing K p : ℕ inst✝¹ : Fact (Nat.Prime p) inst✝ : CharP K p x : ℕ × K ⊢ mk K p x ^ p = mk K p (x.fst, x.snd ^ p) Tactic: simp only [frobenius_def] State Before: K : Type u inst✝² : CommRing K p : ℕ inst✝¹ : Fact (Nat.Prime p) inst✝ : CharP K p x : ℕ × K ⊢ mk K p x ^ p = mk K p (x.fst, x.snd ^ p) State After: case mk K : Type u inst✝² : CommRing K p : ℕ inst✝¹ : Fact (Nat.Prime p) inst✝ : CharP K p n : ℕ x : K ⊢ mk K p (n, x) ^ p = mk K p ((n, x).fst, (n, x).snd ^ p) Tactic: cases' x with n x State Before: case mk K : Type u inst✝² : CommRing K p : ℕ inst✝¹ : Fact (Nat.Prime p) inst✝ : CharP K p n : ℕ x : K ⊢ mk K p (n, x) ^ p = mk K p ((n, x).fst, (n, x).snd ^ p) State After: case mk K : Type u inst✝² : CommRing K p : ℕ inst✝¹ : Fact (Nat.Prime p) inst✝ : CharP K p n : ℕ x : K ⊢ mk K p (n, x) ^ p = mk K p (n, x ^ p) Tactic: dsimp only State Before: case mk K : Type u inst✝² : CommRing K p : ℕ inst✝¹ : Fact (Nat.Prime p) inst✝ : CharP K p n : ℕ x : K ⊢ mk K p (n, x) ^ p = mk K p (n, x ^ p) State After: case mk K : Type u inst✝² : CommRing K p : ℕ inst✝¹ : Fact (Nat.Prime p) inst✝ : CharP K p n : ℕ x : K ⊢ ∀ (p' : ℕ), mk K p (n, x) ^ p' = mk K p (n, x ^ p') Tactic: suffices ∀ p' : ℕ, mk K p (n, x) ^ p' = mk K p (n, x ^ p') by apply this State Before: case mk K : Type u inst✝² : CommRing K p : ℕ inst✝¹ : Fact (Nat.Prime p) inst✝ : CharP K p n : ℕ x : K ⊢ ∀ (p' : ℕ), mk K p (n, x) ^ p' = mk K p (n, x ^ p') State After: case mk K : Type u inst✝² : CommRing K p✝ : ℕ inst✝¹ : Fact (Nat.Prime p✝) inst✝ : CharP K p✝ n : ℕ x : K p : ℕ ⊢ mk K p✝ (n, x) ^ p = mk K p✝ (n, x ^ p) Tactic: intro p State Before: case mk K : Type u inst✝² : CommRing K p✝ : ℕ inst✝¹ : Fact (Nat.Prime p✝) inst✝ : CharP K p✝ n : ℕ x : K p : ℕ ⊢ mk K p✝ (n, x) ^ p = mk K p✝ (n, x ^ p) State After: case mk.zero K : Type u inst✝² : CommRing K p : ℕ inst✝¹ : Fact (Nat.Prime p) inst✝ : CharP K p n : ℕ x : K ⊢ mk K p (n, x) ^ Nat.zero = mk K p (n, x ^ Nat.zero) case mk.succ K : Type u inst✝² : CommRing K p✝ : ℕ inst✝¹ : Fact (Nat.Prime p✝) inst✝ : CharP K p✝ n : ℕ x : K p : ℕ ih : mk K p✝ (n, x) ^ p = mk K p✝ (n, x ^ p) ⊢ mk K p✝ (n, x) ^ Nat.succ p = mk K p✝ (n, x ^ Nat.succ p) Tactic: induction' p with p ih State Before: case mk.zero K : Type u inst✝² : CommRing K p : ℕ inst✝¹ : Fact (Nat.Prime p) inst✝ : CharP K p n : ℕ x : K ⊢ mk K p (n, x) ^ Nat.zero = mk K p (n, x ^ Nat.zero) case mk.succ K : Type u inst✝² : CommRing K p✝ : ℕ inst✝¹ : Fact (Nat.Prime p✝) inst✝ : CharP K p✝ n : ℕ x : K p : ℕ ih : mk K p✝ (n, x) ^ p = mk K p✝ (n, x ^ p) ⊢ mk K p✝ (n, x) ^ Nat.succ p = mk K p✝ (n, x ^ Nat.succ p) State After: case mk.succ K : Type u inst✝² : CommRing K p✝ : ℕ inst✝¹ : Fact (Nat.Prime p✝) inst✝ : CharP K p✝ n : ℕ x : K p : ℕ ih : mk K p✝ (n, x) ^ p = mk K p✝ (n, x ^ p) ⊢ mk K p✝ (n, x) ^ Nat.succ p = mk K p✝ (n, x ^ Nat.succ p) Tactic: case zero => apply R.sound; rw [(frobenius _ _).iterate_map_one, pow_zero] State Before: case mk.succ K : Type u inst✝² : CommRing K p✝ : ℕ inst✝¹ : Fact (Nat.Prime p✝) inst✝ : CharP K p✝ n : ℕ x : K p : ℕ ih : mk K p✝ (n, x) ^ p = mk K p✝ (n, x ^ p) ⊢ mk K p✝ (n, x) ^ Nat.succ p = mk K p✝ (n, x ^ Nat.succ p) State After: no goals Tactic: case succ => rw [pow_succ, ih] symm apply R.sound simp only [pow_succ, (frobenius _ _).iterate_map_mul] State Before: K : Type u inst✝² : CommRing K p : ℕ inst✝¹ : Fact (Nat.Prime p) inst✝ : CharP K p n : ℕ x : K this : ∀ (p' : ℕ), mk K p (n, x) ^ p' = mk K p (n, x ^ p') ⊢ mk K p (n, x) ^ p = mk K p (n, x ^ p) State After: no goals Tactic: apply this State Before: K : Type u inst✝² : CommRing K p : ℕ inst✝¹ : Fact (Nat.Prime p) inst✝ : CharP K p n : ℕ x : K ⊢ mk K p (n, x) ^ Nat.zero = mk K p (n, x ^ Nat.zero) State After: case H K : Type u inst✝² : CommRing K p : ℕ inst✝¹ : Fact (Nat.Prime p) inst✝ : CharP K p n : ℕ x : K ⊢ (↑(frobenius K p)^[n]) 1 = x ^ Nat.zero Tactic: apply R.sound State Before: case H K : Type u inst✝² : CommRing K p : ℕ inst✝¹ : Fact (Nat.Prime p) inst✝ : CharP K p n : ℕ x : K ⊢ (↑(frobenius K p)^[n]) 1 = x ^ Nat.zero State After: no goals Tactic: rw [(frobenius _ _).iterate_map_one, pow_zero] State Before: K : Type u inst✝² : CommRing K p✝ : ℕ inst✝¹ : Fact (Nat.Prime p✝) inst✝ : CharP K p✝ n : ℕ x : K p : ℕ ih : mk K p✝ (n, x) ^ p = mk K p✝ (n, x ^ p) ⊢ mk K p✝ (n, x) ^ Nat.succ p = mk K p✝ (n, x ^ Nat.succ p) State After: K : Type u inst✝² : CommRing K p✝ : ℕ inst✝¹ : Fact (Nat.Prime p✝) inst✝ : CharP K p✝ n : ℕ x : K p : ℕ ih : mk K p✝ (n, x) ^ p = mk K p✝ (n, x ^ p) ⊢ mk K p✝ (n, x) * mk K p✝ (n, x ^ p) = mk K p✝ (n, x ^ Nat.succ p) Tactic: rw [pow_succ, ih] State Before: K : Type u inst✝² : CommRing K p✝ : ℕ inst✝¹ : Fact (Nat.Prime p✝) inst✝ : CharP K p✝ n : ℕ x : K p : ℕ ih : mk K p✝ (n, x) ^ p = mk K p✝ (n, x ^ p) ⊢ mk K p✝ (n, x) * mk K p✝ (n, x ^ p) = mk K p✝ (n, x ^ Nat.succ p) State After: K : Type u inst✝² : CommRing K p✝ : ℕ inst✝¹ : Fact (Nat.Prime p✝) inst✝ : CharP K p✝ n : ℕ x : K p : ℕ ih : mk K p✝ (n, x) ^ p = mk K p✝ (n, x ^ p) ⊢ mk K p✝ (n, x ^ Nat.succ p) = mk K p✝ (n, x) * mk K p✝ (n, x ^ p) Tactic: symm State Before: K : Type u inst✝² : CommRing K p✝ : ℕ inst✝¹ : Fact (Nat.Prime p✝) inst✝ : CharP K p✝ n : ℕ x : K p : ℕ ih : mk K p✝ (n, x) ^ p = mk K p✝ (n, x ^ p) ⊢ mk K p✝ (n, x ^ Nat.succ p) = mk K p✝ (n, x) * mk K p✝ (n, x ^ p) State After: case H K : Type u inst✝² : CommRing K p✝ : ℕ inst✝¹ : Fact (Nat.Prime p✝) inst✝ : CharP K p✝ n : ℕ x : K p : ℕ ih : mk K p✝ (n, x) ^ p = mk K p✝ (n, x ^ p) ⊢ (↑(frobenius K p✝)^[(n, x).fst]) (x ^ Nat.succ p) = (↑(frobenius K p✝)^[(n, x ^ p).fst]) (n, x).snd * (↑(frobenius K p✝)^[(n, x).fst]) (n, x ^ p).snd Tactic: apply R.sound State Before: case H K : Type u inst✝² : CommRing K p✝ : ℕ inst✝¹ : Fact (Nat.Prime p✝) inst✝ : CharP K p✝ n : ℕ x : K p : ℕ ih : mk K p✝ (n, x) ^ p = mk K p✝ (n, x ^ p) ⊢ (↑(frobenius K p✝)^[(n, x).fst]) (x ^ Nat.succ p) = (↑(frobenius K p✝)^[(n, x ^ p).fst]) (n, x).snd * (↑(frobenius K p✝)^[(n, x).fst]) (n, x ^ p).snd State After: no goals Tactic: simp only [pow_succ, (frobenius _ _).iterate_map_mul]
(* Suzuki, Michio - Group Theory. I *) From mathcomp Require Import ssreflect. Require Import Coq.Logic.Description. Require Import Coq.Logic.FinFun. Require Import Coq.Logic.Classical_Prop. Require Import Coq.Logic.FunctionalExtensionality. Require Import Coq.Logic.JMeq. Require Import Coq.Program.Basics. (* Definition 1.1. *) Structure group : Type := make_group { group_carrier : Set; group_inhab : inhabited group_carrier; group_mul : group_carrier -> group_carrier -> group_carrier; group_mul_assoc : forall a b c : group_carrier, group_mul (group_mul a b) c = group_mul a (group_mul b c); group_r_trans : forall a b : group_carrier, exists x : group_carrier, group_mul a x = b; group_l_trans : forall a b : group_carrier, exists y : group_carrier, group_mul y a = b; }. Theorem group_eq (G0 G1 : group) : group_carrier G0 = group_carrier G1 -> JMeq (group_mul G0) (group_mul G1) -> G0 = G1. Proof. move=> Hcarrier Hmul. destruct G0 as [carrier0 inhab0 mul0 mul_assoc0 r_trans0 l_trans0]. destruct G1 as [carrier1 inhab1 mul1 mul_assoc1 r_trans1 l_trans1]. simpl in * |- *. destruct Hcarrier. apply JMeq_eq in Hmul. destruct Hmul. f_equal; apply proof_irrelevance. Qed. (* Definition 1.3. *) Definition is_group_one (G : group) (e : group_carrier G) := forall g : group_carrier G, group_mul G g e = g /\ group_mul G e g = g. (* Theorem 1.2.(ii)' *) Theorem group_one_ex_uni (G : group) : exists! group_one : group_carrier G, is_group_one G group_one. Proof. destruct (group_inhab G) as [a]. destruct (group_r_trans G a a) as [e Hae_eq_a]. destruct (group_l_trans G a a) as [e' He'a_eq_a]. exists e. assert (forall g : group_carrier G, group_mul G g e = g) as He_oner. + move=> g. destruct (group_r_trans G a g) as [u Hau_eq_g]. destruct (group_l_trans G a g) as [v Hva_eq_g]. rewrite -Hva_eq_g. rewrite group_mul_assoc. rewrite Hae_eq_a. by []. assert (forall g : group_carrier G, group_mul G e' g = g) as He'_onel. + move=> g. destruct (group_r_trans G a g) as [u Hau_eq_g]. destruct (group_l_trans G a g) as [v Hva_eq_g]. rewrite -Hau_eq_g. rewrite -group_mul_assoc. rewrite He'a_eq_a. by []. assert (e = e') as He_eq_e'. + rewrite -(He_oner e'). rewrite (He'_onel e). by []. split. + move=> g. split. + apply (He_oner g). + rewrite He_eq_e'. rewrite (He'_onel g). by []. + move=> g Hg_one. destruct (Hg_one e) as [Heg_eq_e Hge_eq_e]. rewrite -(He_oner g). rewrite Hge_eq_e. by []. Qed. Definition group_one (G : group) : group_carrier G := let 'exist one Hone := (constructive_definite_description (is_group_one G) (group_one_ex_uni G)) in one. Theorem group_one_is_group_one (G : group) : is_group_one G (group_one G). Proof. remember (group_one G) as e eqn: H. unfold group_one in H. destruct (constructive_definite_description (is_group_one G) (group_one_ex_uni G)) as [e' He'] in H. rewrite H. exact He'. Qed. Definition are_mut_inv (G : group) (a a' : group_carrier G) := group_mul G a a' = group_one G /\ group_mul G a' a = group_one G. (* Theorem 1.2.(ii)'' *) Theorem group_inv_ex_uni (G : group) (a : group_carrier G) : exists! a' : group_carrier G, are_mut_inv G a a'. Proof. destruct (group_r_trans G a (group_one G)) as [a' Haa'_eq_one]. destruct (group_l_trans G a (group_one G)) as [a'' Ha''a_eq_one]. assert (a' = a'') as Ha'_eq_a''. + rewrite -(proj1 ((group_one_is_group_one G) a'')). rewrite -Haa'_eq_one. rewrite -(group_mul_assoc G a'' a a'). rewrite Ha''a_eq_one. rewrite (proj2 ((group_one_is_group_one G) a')). by []. rewrite -Ha'_eq_a'' in Ha''a_eq_one. exists a'. split. + split. + exact Haa'_eq_one. + exact Ha''a_eq_one. + move=> a''' [Hax_eq_one Hxa_eq_one]. rewrite -(proj1 ((group_one_is_group_one G) a')). rewrite -Hax_eq_one. rewrite -(group_mul_assoc G a' a a'''). rewrite Ha''a_eq_one. rewrite (proj2 ((group_one_is_group_one G) a''')). by []. Qed. Definition group_inv (G : group) : group_carrier G -> group_carrier G := fun a => let 'exist a' Ha' := (constructive_definite_description (are_mut_inv G a) (group_inv_ex_uni G a)) in a'. Theorem group_inv_is_group_inv (G : group) (a : group_carrier G) : are_mut_inv G a (group_inv G a). Proof. remember (group_inv G a) as a' eqn: H. unfold group_inv in H. destruct (constructive_definite_description (are_mut_inv G a) (group_inv_ex_uni G a)) as [a'' Ha''] in H. rewrite H. exact Ha''. Qed. Theorem group_one_mul (G : group) : forall a : group_carrier G, group_mul G (group_one G) a = a. Proof. move=> a. exact (proj2 ((group_one_is_group_one G) a)). Qed. Theorem group_mul_one (G : group) : forall a : group_carrier G, group_mul G a (group_one G) = a. Proof. move=> a. exact (proj1 ((group_one_is_group_one G) a)). Qed. Theorem group_inv_mul (G : group) : forall a : group_carrier G, group_mul G (group_inv G a) a = group_one G. Proof. move=> a. exact (proj2 ((group_inv_is_group_inv G) a)). Qed. Theorem group_mul_inv (G : group) : forall a : group_carrier G, group_mul G a (group_inv G a) = group_one G. Proof. move=> a. exact (proj1 ((group_inv_is_group_inv G) a)). Qed. Theorem group_one_inv (G : group) : group_inv G (group_one G) = group_one G. Proof. pose proof (group_inv_ex_uni G (group_one G)) as Hex_uni. rewrite <- unique_existence in Hex_uni. destruct Hex_uni as [Hex Huni]. apply (Huni (group_inv G (group_one G)) (group_one G)). + exact (group_inv_is_group_inv G (group_one G)). + split; rewrite group_one_mul; reflexivity. Qed. (* Theorem 1.2.(iii).1 *) Theorem group_r_trans_ex_uni (G : group) : forall a b x : group_carrier G, group_mul G a x = b -> x = group_mul G (group_inv G a) b. Proof. move=> a b x Hax_eq_b. rewrite -Hax_eq_b. rewrite -group_mul_assoc. rewrite (proj2 (group_inv_is_group_inv G a)). rewrite (proj2 (group_one_is_group_one G x)). reflexivity. Qed. (* Theorem 1.2.(iii).2 *) Theorem group_l_trans_ex_uni (G : group) : forall a b y : group_carrier G, group_mul G y a = b -> y = group_mul G b (group_inv G a). Proof. move=> a b y Hya_eq_b. rewrite -Hya_eq_b. rewrite group_mul_assoc. rewrite (proj1 (group_inv_is_group_inv G a)). rewrite (proj1 (group_one_is_group_one G y)). reflexivity. Qed. (* Corollary_p4_l7 *) Structure group' : Type := make_group' { group'_carrier : Set; group'_one : group'_carrier; group'_inv : group'_carrier -> group'_carrier; group'_mul : group'_carrier -> group'_carrier -> group'_carrier; group'_mul_assoc : forall a b c : group'_carrier, group'_mul (group'_mul a b) c = group'_mul a (group'_mul b c); group'_one_mul : forall a : group'_carrier, group'_mul group'_one a = a; group'_mul_one : forall a : group'_carrier, group'_mul a group'_one = a; group'_inv_mul : forall a : group'_carrier, group'_mul (group'_inv a) a = group'_one; group'_mul_inv : forall a : group'_carrier, group'_mul a (group'_inv a) = group'_one; }. Theorem group'_eq (G0 G1 : group') : group'_carrier G0 = group'_carrier G1 -> JMeq (group'_mul G0) (group'_mul G1) -> G0 = G1. Proof. move => Hcarrier Hmul. destruct G0 as [carrier0 one0 inv0 mul0 mul_assoc0 one_mul0 mul_one0 inv_mul0 mul_inv0]. destruct G1 as [carrier1 one1 inv1 mul1 mul_assoc1 one_mul1 mul_one1 inv_mul1 mul_inv1]. simpl in * |- *. destruct Hcarrier. apply JMeq_eq in Hmul. destruct Hmul. assert (one0 = one1) as Hone. + rewrite -(one_mul0 one1). rewrite (mul_one1 one0). reflexivity. destruct Hone. assert (inv0 = inv1) as Hinv. + apply functional_extensionality. move=> x. rewrite -(mul_one0 (inv0 x)). rewrite -(mul_inv1 x). rewrite -mul_assoc0. rewrite (inv_mul0 x). rewrite (one_mul0 (inv1 x)). reflexivity. destruct Hinv. f_equal; apply proof_irrelevance. Qed. Definition group_to_group' : group -> group' := fun G => (make_group' (group_carrier G) (group_one G) (group_inv G) (group_mul G) (group_mul_assoc G) (fun a => proj2 (group_one_is_group_one G a)) (fun a => proj1 (group_one_is_group_one G a)) (fun a => proj2 (group_inv_is_group_inv G a)) (fun a => proj1 (group_inv_is_group_inv G a)) ). Theorem group'_to_group_sub_r (G' : group') : forall a b : group'_carrier G', exists x : group'_carrier G', group'_mul G' a x = b. Proof. move=> a b. exists (group'_mul G' (group'_inv G' a) b). rewrite -group'_mul_assoc. rewrite group'_mul_inv. rewrite group'_one_mul. reflexivity. Qed. Theorem group'_to_group_sub_l (G' : group') : forall a b : group'_carrier G', exists y : group'_carrier G', group'_mul G' y a = b. Proof. move=> a b. exists (group'_mul G' b (group'_inv G' a)). rewrite group'_mul_assoc. rewrite group'_inv_mul. rewrite group'_mul_one. reflexivity. Qed. Definition group'_to_group : group' -> group := fun G' => (make_group (group'_carrier G') (inhabits (group'_one G')) (group'_mul G') (group'_mul_assoc G') (group'_to_group_sub_r G') (group'_to_group_sub_l G') ). Theorem group_to_group'_to_group_is_id : compose group'_to_group group_to_group' = id. Proof. apply functional_extensionality. move=> G. destruct G. unfold id. unfold compose. unfold group_to_group'. unfold group'_to_group. simpl. f_equal; apply proof_irrelevance. Qed. Theorem group'_to_group_to_group'_is_id : compose group_to_group' group'_to_group = id. Proof. apply functional_extensionality. move=> G'. destruct G'. unfold id. unfold compose. unfold group_to_group'. unfold group'_to_group. apply group'_eq. simpl. reflexivity. simpl. apply JMeq_refl. Qed. (* Theorem 1.4.1 *) Theorem inv_inv (G : group) : forall a : group_carrier G, group_inv G (group_inv G a) = a. Proof. move=> a. pose proof (group_inv_ex_uni G (group_inv G a)) as H. rewrite <- unique_existence in H. destruct H as [_ Huni]. pose proof (group_inv_is_group_inv G (group_inv G a)) as Hinvinva. pose proof (group_inv_is_group_inv G a) as Ha. unfold are_mut_inv in Ha. rewrite <- and_comm in Ha. fold (are_mut_inv G (group_inv G a) a) in Ha. rewrite -(Huni a (group_inv G (group_inv G a)) Ha Hinvinva). reflexivity. Qed. (* Theorem 1.4.2 *) Theorem group_mul_inv_rev (G : group) : forall a b : group_carrier G, group_inv G (group_mul G a b) = group_mul G (group_inv G b) (group_inv G a). Proof. move=> a b. pose proof (group_inv_ex_uni G (group_mul G a b)) as H. rewrite <- unique_existence in H. destruct H as [_ Huni]. pose proof (group_inv_is_group_inv G (group_mul G a b)) as H1. assert (are_mut_inv G (group_mul G a b) (group_mul G (group_inv G b) (group_inv G a))) as H2. + split. + rewrite (group_mul_assoc G a b (group_mul G (group_inv G b) (group_inv G a))). rewrite -(group_mul_assoc G b (group_inv G b) (group_inv G a)). rewrite (proj1 (group_inv_is_group_inv G b)). rewrite (proj2 (group_one_is_group_one G (group_inv G a))). rewrite (proj1 (group_inv_is_group_inv G a)). reflexivity. + rewrite (group_mul_assoc G (group_inv G b) (group_inv G a) (group_mul G a b)). rewrite -(group_mul_assoc G (group_inv G a) a b). rewrite (proj2 (group_inv_is_group_inv G a)). rewrite (proj2 (group_one_is_group_one G b)). rewrite (proj2 (group_inv_is_group_inv G b)). reflexivity. exact (Huni (group_inv G (group_mul G a b)) (group_mul G (group_inv G b) (group_inv G a)) H1 H2). Qed. (* Definition 2.1 *) Definition subset (S : Set) := S -> Prop. Structure subgroup (G : group) : Type := make_subgroup { subgroup_carrier : subset (group_carrier G); subgroup_inhab : inhabited (sig subgroup_carrier); subgroup_mul_mem : forall a b : group_carrier G, subgroup_carrier a -> subgroup_carrier b -> subgroup_carrier (group_mul G a b); subgroup_inv_mem : forall a : group_carrier G, subgroup_carrier a -> subgroup_carrier (group_inv G a); }. (* (2.2).(a) *) Theorem subgroup_one_mem (G : group) (H : subgroup G) : subgroup_carrier G H (group_one G). Proof. destruct (subgroup_inhab G H) as [Hinhab]. destruct Hinhab as [a Ha_in_H]. pose proof (subgroup_inv_mem G H a Ha_in_H) as Hainv_in_H. pose proof (subgroup_mul_mem G H a (group_inv G a) Ha_in_H Hainv_in_H) as Hmul_in_H. rewrite (proj1 (group_inv_is_group_inv G a)) in Hmul_in_H. exact Hmul_in_H. Qed. Definition subgroup_incl (G : group) (H : subgroup G) : (sig (subgroup_carrier G H)) -> group_carrier G := fun p => let 'exist x Hx := p in x. Theorem subgroup_incl_is_injective (G : group) (H : subgroup G) : Injective (subgroup_incl G H). Proof. move=> [x Hx] [y Hy] Heq. unfold subgroup_incl in Heq. move: Hx Hy. rewrite -Heq. move=> Hx Hy. apply f_equal. apply proof_irrelevance. Qed. Definition subgroup_mul (G : group) (H : subgroup G) : (sig (subgroup_carrier G H)) -> (sig (subgroup_carrier G H)) -> (sig (subgroup_carrier G H)) := fun p q => let 'exist a Ha := p in let 'exist b Hb := q in (exist (subgroup_carrier G H) (group_mul G a b) (subgroup_mul_mem G H a b Ha Hb)). Theorem subgroup_mul_assoc (G : group) (H : subgroup G) : forall a b c : (sig (subgroup_carrier G H)), subgroup_mul G H (subgroup_mul G H a b) c = subgroup_mul G H a (subgroup_mul G H b c). Proof. move=> [a Ha] [b Hb] [c Hc]. apply (subgroup_incl_is_injective G H). unfold subgroup_mul. unfold subgroup_incl. exact (group_mul_assoc G a b c). Qed. Theorem subgroup_group_r_trans (G : group) (H : subgroup G) : forall a b : (sig (subgroup_carrier G H)), exists x : (sig (subgroup_carrier G H)), subgroup_mul G H a x = b. Proof. move=> [a Ha] [b Hb]. set (c := group_mul G (group_inv G a) b). set (Hc := subgroup_mul_mem G H (group_inv G a) b (subgroup_inv_mem G H a Ha) Hb). exists (exist (subgroup_carrier G H) c Hc). apply (subgroup_incl_is_injective G H). unfold subgroup_mul. unfold subgroup_incl. unfold c. rewrite -(group_mul_assoc G). rewrite (group_mul_inv G). rewrite (group_one_mul G). reflexivity. Qed. Theorem subgroup_group_l_trans (G : group) (H : subgroup G) : forall a b : (sig (subgroup_carrier G H)), exists y : (sig (subgroup_carrier G H)), subgroup_mul G H y a = b. Proof. move=> [a Ha] [b Hb]. set (c := group_mul G b (group_inv G a)). set (Hc := subgroup_mul_mem G H b (group_inv G a) Hb (subgroup_inv_mem G H a Ha)). exists (exist (subgroup_carrier G H) c Hc). apply (subgroup_incl_is_injective G H). unfold subgroup_mul. unfold subgroup_incl. unfold c. rewrite (group_mul_assoc G). rewrite (group_inv_mul G). rewrite (group_mul_one G). reflexivity. Qed. (* (2.2).(b) *) Definition subgroup_to_group (G : group) : (subgroup G) -> group := fun H => (make_group (sig (subgroup_carrier G H)) (subgroup_inhab G H) (subgroup_mul G H) (subgroup_mul_assoc G H) (subgroup_group_r_trans G H) (subgroup_group_l_trans G H) ). (* (2.2).(c).1 *) Theorem subgroup_one_is_group_one (G : group) (H : subgroup G) : subgroup_incl G H (group_one (subgroup_to_group G H)) = group_one G. Proof. pose proof (group_one_ex_uni (subgroup_to_group G H)) as Hone_ex_uni. rewrite <- unique_existence in Hone_ex_uni. destruct Hone_ex_uni as [Hone_ex Hone_uni]. set (one0 := group_one (subgroup_to_group G H)). set (one1 := (exist (subgroup_carrier G H) (group_one G) (subgroup_one_mem G H))). assert (one0 = one1) as Hyp0. + assert (is_group_one (subgroup_to_group G H) one1) as His_one. + move=> x. destruct x as [x Hx]. split. + apply subgroup_incl_is_injective. simpl. rewrite (group_mul_one G). reflexivity. + apply subgroup_incl_is_injective. simpl. rewrite (group_one_mul G). reflexivity. + exact (Hone_uni one0 one1 (group_one_is_group_one (subgroup_to_group G H)) His_one). rewrite Hyp0. simpl. reflexivity. Qed. (* (2.2).(c).2 *) Theorem subgroup_inv_is_group_inv (G : group) (H : subgroup G) : compose (subgroup_incl G H) (group_inv (subgroup_to_group G H)) = compose (group_inv G) (subgroup_incl G H). Proof. apply functional_extensionality. move=> [x Hx]. unfold compose. simpl. pose proof (group_inv_ex_uni (subgroup_to_group G H) (exist (subgroup_carrier G H) x Hx)) as Hinv_ex_uni. rewrite <- unique_existence in Hinv_ex_uni. destruct Hinv_ex_uni as [Hinv_ex Hinv_uni]. set (inv0 := group_inv (subgroup_to_group G H) (exist (subgroup_carrier G H) x Hx)). set (inv1 := (exist (subgroup_carrier G H) (group_inv G (subgroup_incl G H (exist (subgroup_carrier G H) x Hx))) (subgroup_inv_mem G H x Hx))). assert (inv0 = inv1) as Hyp0. + assert (are_mut_inv (subgroup_to_group G H) (exist (subgroup_carrier G H) x Hx) inv1) as His_inv. + split. + apply subgroup_incl_is_injective. simpl. rewrite (group_mul_inv G). rewrite (subgroup_one_is_group_one G H). reflexivity. + apply subgroup_incl_is_injective. simpl. rewrite (group_inv_mul G). rewrite (subgroup_one_is_group_one G H). reflexivity. + exact (Hinv_uni inv0 inv1 (group_inv_is_group_inv (subgroup_to_group G H) (exist (subgroup_carrier G H) x Hx)) His_inv). rewrite Hyp0. simpl. reflexivity. Qed. (* (2.3).1 *) Definition maximum_subgroup_carrier (G : group) : subset (group_carrier G) := fun x => True. Theorem maximum_subgroup_inhab (G : group) : inhabited (sig (maximum_subgroup_carrier G)). Proof. destruct (group_inhab G) as [x]. assert (maximum_subgroup_carrier G x) as Hyp. + unfold maximum_subgroup_carrier. exact. exact (inhabits (exist (maximum_subgroup_carrier G) x Hyp)). Qed. Theorem maximum_subgroup_mul_mem (G : group) : forall a b : group_carrier G, maximum_subgroup_carrier G a -> maximum_subgroup_carrier G b -> maximum_subgroup_carrier G (group_mul G a b). Proof. move=> a b Ha Hb. unfold maximum_subgroup_carrier. exact I. Qed. Theorem maximum_subgroup_inv_mem (G : group) : forall a : group_carrier G, maximum_subgroup_carrier G a -> maximum_subgroup_carrier G (group_inv G a). Proof. move=> a Ha. unfold maximum_subgroup_carrier. exact I. Qed. Definition maximum_subgroup (G : group) : subgroup G := (make_subgroup G (maximum_subgroup_carrier G) (maximum_subgroup_inhab G) (maximum_subgroup_mul_mem G) (maximum_subgroup_inv_mem G) ). (* (2.3).2 *) Definition minimum_subgroup_carrier (G : group) : subset (group_carrier G) := fun x => x = group_one G. Theorem minimum_subgroup_carrier_sub0 (G : group) : forall x : group_carrier G, minimum_subgroup_carrier G x -> x = group_one G. Proof. move=> x Hx. unfold minimum_subgroup_carrier in Hx. exact Hx. Qed. Theorem minimum_subgroup_inhab (G : group) : inhabited (sig (minimum_subgroup_carrier G)). Proof. set (one := group_one G). assert (minimum_subgroup_carrier G one) as Hyp. + unfold minimum_subgroup_carrier. unfold one. reflexivity. exact (inhabits (exist (minimum_subgroup_carrier G) one Hyp)). Qed. Theorem minimum_subgroup_mul_mem (G : group) : forall a b : group_carrier G, minimum_subgroup_carrier G a -> minimum_subgroup_carrier G b -> minimum_subgroup_carrier G (group_mul G a b). Proof. unfold minimum_subgroup_carrier. move=> a b Ha Hb. rewrite Ha Hb. rewrite group_mul_one. reflexivity. Qed. Theorem minimum_subgroup_inv_mem (G : group) : forall a : group_carrier G, minimum_subgroup_carrier G a -> minimum_subgroup_carrier G (group_inv G a). Proof. unfold minimum_subgroup_carrier. move=> a Ha. rewrite Ha. exact (group_one_inv G). Qed. Definition minimum_subgroup (G : group) : subgroup G := (make_subgroup G (minimum_subgroup_carrier G) (minimum_subgroup_inhab G) (minimum_subgroup_mul_mem G) (minimum_subgroup_inv_mem G) ). Definition is_proper_subset (S : Set) (T : subset S) := exists s : S, ~(T s). (* Definition 2.4 *) Definition is_proper_subgroup (G : group) (H : subgroup G) := is_proper_subset (group_carrier G) (subgroup_carrier G H).
{-# LANGUAGE TypeOperators #-} {-# LANGUAGE RankNTypes #-} {-# LANGUAGE TypeApplications #-} {-# LANGUAGE AllowAmbiguousTypes #-} {-# LANGUAGE FlexibleInstances #-} {-# LANGUAGE LambdaCase #-} {-# LANGUAGE RecordWildCards #-} {-# LANGUAGE FlexibleContexts #-} {-# LANGUAGE ScopedTypeVariables #-} {-# LANGUAGE GeneralizedNewtypeDeriving #-} {-# LANGUAGE GADTs #-} module Lib where import Numeric import Prelude hiding (and,or,(>)) import Control.Monad.RWS import System.Process import System.Exit import Data.List (intercalate) import qualified Data.Map as M import qualified Data.Vector.Unboxed as V import Statistics.Sample.KernelDensity import Text.Read (readMaybe) -------------------------------------------- -- Basic code-gen infrastructure type a ⊸ b = a -> b data Expr t where Expr :: String -> Expr t -- constant expression Lam :: (Expr a -> Expr t) -> Expr (a -> t) -- lambda App :: Expr (a -> t) -> Expr a -> Expr t -- application BinOp :: (String -> String -> String) -> Expr a -> Expr b -> Expr c UnOp :: (String -> String) -> Expr a -> Expr b If :: Prop -> Expr a -> Expr a -> Expr a -- Let :: P (Expr a) -> (Expr a ⊸ Expr b) -> Expr b Thunk :: P (Expr t) -> Expr t class Representable a where constant :: a -> Expr a instance Representable Bool where constant True = Expr "true" constant False = Expr "false" instance Representable Float where constant = Expr . show instance Fractional (Expr Float) where fromRational x = constant (fromRat x) (/) = BinOp (infixOp "/") instance Num (Expr Float) where abs = UnOp (\x -> "Math.abs(" ++ x ++ ")") (-) = BinOp (infixOp "-") (+) = BinOp (infixOp "+") fromInteger x = constant (fromInteger x) (*) = BinOp (infixOp "*") instance Floating (Expr Float) where sqrt = UnOp (\x -> "Math.sqrt(" ++ x ++ ")") exp = UnOp (\x -> "Math.exp(" ++ x ++ ")") log = UnOp (\x -> "Math.log(" ++ x ++ ")") render :: Expr a -> P String render = \case UnOp op x -> do x' <- render x return (op x') BinOp op x y -> do x' <- render x y' <- render y return (op x' y') Expr x -> return x App (Lam f) x -> render (f x) Lam f -> do x <- newVar body <- render (f (Expr x)) return ("function( " ++ x ++ ") { return " ++ body ++ "; }") Thunk f -> do (x,body) <- censor (\_ -> []) $ listen f x' <- render x return ("function() {\n" ++ unlines body ++ " return " ++ x' ++ ";\n }") App x y -> do x' <- render x y' <- render y return ("(" ++ x' ++ ")(" ++ y' ++ ")") If cond x y -> do c' <- render cond x' <- render x y' <- render y return ("(" ++ c' ++ "?" ++ x' ++ ":" ++ y' ++ ")") -- Let e f -> do -- x <- newVar -- e' <- render =<< e -- works only if f uses its argument at most once. -- fx <- render (f (Expr x)) -- return ("var " ++ x ++ " = "++ e' ++";\n" ++ fx) infixl # (#) :: Expr (a -> b) -> Expr a -> Expr b (#) = App parens :: [Char] -> [Char] parens x = "("++ x ++")" infixOp :: [Char] -> [Char] -> [Char] -> [Char] infixOp op x y = parens x ++ op ++ parens y binFunc :: [Char] -> [Char] -> [Char] -> [Char] binFunc f x y = f ++ "("++ x ++ "," ++ y ++")" unFunc :: [Char] -> [Char] -> [Char] unFunc f x = f ++ "("++ x ++ ")" newtype P a = P (RWS () [String] State a) deriving (Functor,Applicative,Monad,MonadState State, MonadWriter [String]) data State = State {nextVar :: Int} logtrace :: String -> Expr a -> P () logtrace msg x = do x' <- render x emit ("console.log(" ++ show "LOG: " ++ "+" ++ show msg ++ "+ \" \" +" ++ x' ++ ");") compileModel :: String -> P (Expr a) -> String compileModel mainFunc m = unlines (z ++ [x]) where (x,_,z) = runRWS p () (State {nextVar = 0}) (P p) = render (UnOp (unFunc mainFunc) (Thunk m)) and :: Prop -> Prop -> Prop and = BinOp (infixOp "&&") (∧) :: Prop -> Prop -> Prop (∧) = and iff :: Prop -> Prop -> Prop iff = BinOp (infixOp "==") or :: Prop -> Prop -> Prop or = BinOp (infixOp "||") not' :: Prop -> Prop not' = UnOp (\x -> "(!(" ++ x ++ "))") (-->) :: Prop -> Prop -> Prop p --> q = not' p `or` q -- | Allocate a new variable newVar :: P String newVar = do n <- gets nextVar modify $ \State{..} -> State {nextVar = n+1, ..} return ("v" ++ show n) emit :: String -> P () emit x = tell [x] ----------------------------------- -- Types type Vec = [Expr Float] data Distrib a type Ind = Vec type Mat = [Vec] -- type Vec = Expr Vector type Prop = Expr Bool type Pred = Ind -> Prop type Measure = Ind -> Expr Float type Adj = Vec type AP = Measure type CN = Ind -> Prop type VP = Ind -> Prop type NP = VP -> Prop type Quant = CN -> NP ---------------------------------------------------- -- Compositional semantics observe :: Prop -> P () observe = hyp squared :: Num a => a -> a squared x = x*x observeEqual :: Expr Float -> Expr Float -> P () observeEqual x y = do f <- render (negate (squared (x-y))) emit ("factor(" ++ f ++ ");") hyp :: Prop -> P () hyp x = do x' <- render x emit ("hyp(" ++ x' ++ ");") -- | Sample new individual newInd :: P Ind newInd = newIndSuch [] -- | Sample new individual which satisfies some additional predicates newIndSuch :: [Pred] -> P Ind newIndSuch hs = do x <- newVector forM_ hs $ \h -> hyp (h x) return x numberOfDimensions :: Int numberOfDimensions = 2 newVector :: P Vec newVector = mapM (uncurry sampleGaussian) (replicate numberOfDimensions (0,1)) newNormedVector :: P Vec newNormedVector = do xs <- mapM (uncurry sampleGaussian) (replicate numberOfDimensions (0,1)) return ((/ norm xs) <$> xs) cosineDistance :: Vec -> Vec -> Expr Float cosineDistance x y = dotProd x y / (norm x * norm y) norm2 :: Vec -> Expr Float norm2 x = dotProd x x norm :: Vec -> Expr Float norm = sqrt . norm2 newMatrix = mapM (\_ -> newVector) (replicate numberOfDimensions ()) newMatrix :: P Mat satisfyAll :: [Ind] -> [Pred] -> P () satisfyAll xs ps = forM_ xs $ \x -> forM ps $ \p -> hyp (p x) dotProd :: Vec -> Vec -> Expr Float dotProd x y = sum (zipWith (*) x y) vecMatProd :: Vec -> Mat -> Vec vecMatProd v = map (dotProd v) type Scalar = (Vec,Expr Float) newScalarA :: P Scalar newScalarA = do bias <- sampleGaussian 0 1 v <- newNormedVector return (v,bias) sampleGaussian :: Expr Float -> Expr Float -> P (Expr Float) sampleGaussian mu sigma = do v <- newVar let m = Expr v mu' <- render mu sigma' <- render sigma emit ("var " ++ v ++ " = gaussian(" ++ mu' ++ "," ++ sigma' ++ ");") return m newClass :: P Mat newClass = newMatrix forClass :: Mat -> Adj -> AP forClass cl adj x = dotProd (vecMatProd adj cl) x -- -- Alternative for scalar adjectives. We take the measure to be greater than that of a "random" element of the class. -- forClassScalar :: Mat -> Adj -> AP -- forClassScalar cl a x = Let (newIndSuch [isClass cl]) (\y -> adjAP a x - adjAP a y) isClass :: Mat -> Pred isClass clas x = dotProd (head clas) x > 0 adjAP :: Adj -> AP adjAP = dotProd gaussian :: Expr Float -> Expr Float -> Expr Float gaussian mean stdDev = BinOp (binFunc "gaussian") mean stdDev vague :: Float -> Measure -> Measure vague vagueness m x = m x + gaussian 0 (Expr (show vagueness)) newMeasure :: P Measure newMeasure = do (v,bias) <- newScalarA return (\x -> bias + dotProd v x) positive :: Expr Float -> Prop positive x = greaterThan x 0 newPred :: P (Ind -> Prop) newPred = do m <- newMeasure return (\x -> positive (m x)) sample :: Expr (Distrib Bool) -> Expr Bool sample d = Expr "sample" # d bernouilli :: Expr Float -> Expr (Distrib Bool) bernouilli = UnOp (\x -> "Bernoulli({p:" ++ x ++ "})") -- TODO: there is a choice here. -- this is an "intuitionistic" probably (it does not exclude the strong implication) probablyInt :: Expr Float -> Prop -> Prop probablyInt v x = sample (bernouilli v) --> x -- this is a "definite" probably (it excludes the strong implication) probablyDef :: Expr Float -> Prop -> Prop probablyDef v x = If (sample (bernouilli v)) x (not' x) -- "a --> b" -- and "if a then b else (not b)" -- are not the same! expectedPortion :: P Prop -> Expr Float expectedPortion = UnOp (unFunc "expectedPortion") . Thunk genQProb :: Expr Float -> Quant genQProb prob cn vp = expectedPortion p > prob where p = do x <- newInd observe (cn x) return (vp x) many :: Quant many = genQProb 0.6 most :: Quant most = genQProb 0.7 few :: Quant few cn vp = genQProb 0.8 cn (not' . vp) some :: Quant some = genQProb 0.1 every :: Quant every = genQProb 0.99 is :: Measure -> Pred is m x = (m x) > 0 more :: Measure -> Ind -> Ind -> Prop more m x y = (m x) > (m y) greaterThan :: Expr Float -> Expr Float -> Prop greaterThan = BinOp (infixOp ">") (>) :: Expr Float -> Expr Float -> Prop (>) = greaterThan -- equal :: Expr Float -> Expr Float -> Prop -- equal x y = 0.1 > (abs (x - y)) equal :: Expr Float -> Expr Float -> Prop equal x y = 0.1 > (abs (x - y)) disjoint :: Pred -> Pred -> Pred disjoint p q x = not' (p x) `or` not' (q x) subsective :: Adj -> Mat -> Pred subsective a cl x = isClass cl x `and` is (forClass cl a) x -- An alternative semantics for subsective scalars. anything :: Pred anything _ = Expr "true" plot :: String -> [Double] -> IO () plot prefix xs = do let (xs',ys') = kde 64 (V.fromList xs) fname = prefix ++ ".svg" let ls = ["set terminal svg size 350,262 fname 'Verdana' enhanced background rgb 'white'", "set output '" ++ fname ++ "'", "set key off", -- no legend "$data << EOD"] ++ [show x ++ " " ++ show y | (x,y) <- zip (V.toList xs') (V.toList ys')] ++ ["EOD", "plot '$data' with lines"] -- filledcurve putStrLn "Plotting results..." (code,output,errors) <- readProcessWithExitCode "gnuplot" ["-p"] (unlines ls) case code of ExitFailure _ -> do putStrLn "Gnuplot failed with input:" putStrLn (unlines ls) putStrLn "errors:" putStrLn output putStrLn errors ExitSuccess -> putStrLn ("Plot output to " ++ fname) return () class KnownTyp a where isContinuous :: Bool instance KnownTyp Float where isContinuous = True instance KnownTyp Bool where isContinuous = False parseValues :: [String] -> IO [Double] parseValues [] = return [] parseValues (v:vs) = case readMaybe v of Nothing -> putStrLn v >> parseValues vs Just x -> (x:) <$> parseValues vs run :: forall a. KnownTyp a => P (Expr a) -> IO () run model = do putStrLn "Creating model..." rts <- readFile "../Frontend/RTS.wppl" let m = compileModel mainName model funname = "modelFunction" mainName = if isContinuous @a then "mainContinuous" else "mainDiscrete" fname = funname ++ ".wppl" writeFile fname (intercalate "\n\n" [rts,m]) putStrLn "Running webppl..." (code,output,errors) <- readProcessWithExitCode "webppl" [fname] "" case code of ExitFailure _ -> do putStrLn "Webppl failed with errors:" putStrLn output putStrLn errors ExitSuccess -> do putStrLn "Success!" case isContinuous @a of True -> do values <- parseValues (lines output) plot funname values False -> putStrLn output
module GraphClass use VertexClass use IOClass use MathClass use RandomClass implicit none type :: Graph_ ! Group of G(V, E), ! where V is vertex, E is edge ! adjacency matrix integer(int32),allocatable :: AdjacencyMatrix(:,:) ! vertex info type(Vertex_),allocatable :: Vertex(:) ! global info integer(int32),allocatable :: Global_ID(:) integer(int32) :: NumOfVertex=0 contains procedure, public :: add => addGraph ! add vertex or edge procedure, public :: update => updateGraph ! update vertex or edge procedure, public :: show => showGraph procedure, public :: remove => removeGraph procedure, public :: sync => syncGraph end type contains ! ###################################### subroutine removeGraph(obj,onlyVertex) class(Graph_),intent(inout) :: obj logical,optional,intent(in) :: onlyVertex deallocate(obj%vertex) if(present(onlyVertex) )then if(onlyVertex.eqv. .true.)then return endif endif deallocate(obj%AdjacencyMatrix) obj%NumOfVertex=0 end subroutine ! ###################################### ! ###################################### subroutine addGraph(obj,vertex,from, to,between,and) class(Graph_),intent(inout) :: obj type(Vertex_),optional,intent(inout) :: vertex type(Vertex_),allocatable :: vlist(:) integer(int32),optional,intent(in) :: from, to,between,and integer(int32) :: i if(present(vertex) )then obj%NumOfVertex=obj%NumOfVertex+1 vertex%ID = obj%NumOfVertex endif if(present(vertex) )then if(.not. allocated(obj%Vertex) )then allocate(obj%Vertex(1)) obj%Vertex(1) = vertex%copy() if(allocated(obj%AdjacencyMatrix) ) deallocate(obj%AdjacencyMatrix) allocate(obj%AdjacencyMatrix(1,1) ) obj%AdjacencyMatrix(1,1)=0 else allocate(vlist(size(obj%Vertex) ) ) do i=1,size(obj%Vertex,1 ) vlist(i) = obj%Vertex(i)%copy() enddo deallocate(obj%Vertex) allocate(obj%Vertex(size(vlist,1)+1 ) ) do i=1,size(vlist,1) obj%Vertex(i) = vlist(i)%copy() enddo obj%Vertex( size(vlist,1) + 1 ) = vertex%copy() call extend(mat=obj%AdjacencyMatrix,extend1stColumn=.true.,DefaultValue=0) call extend(mat=obj%AdjacencyMatrix,extend2ndColumn=.true.,DefaultValue=0) endif endif if(present(from) .and. present(to) )then obj%AdjacencyMatrix(from, to) = 1 obj%AdjacencyMatrix(to, from) = -1 endif if(present(between) .and. present(and) )then obj%AdjacencyMatrix(between, and) = 1 obj%AdjacencyMatrix(and, between) = 1 endif end subroutine ! ###################################### ! ###################################### subroutine updateGraph(obj,ID,vertex,from, to,between,and) class(Graph_),intent(inout) :: obj type(Vertex_),optional,intent(inout) :: vertex type(Vertex_),allocatable :: vlist(:) integer(int32),intent(in) :: ID integer(int32),optional,intent(in) :: from, to, between,and integer(int32) :: i if(ID > size(obj%vertex) )then print *, "ERROR :: updateGraph >> please add vertex before update." stop else obj%Vertex(ID) = vertex%copy() endif if(present(from) .and. present(to) )then obj%AdjacencyMatrix(from, to) = 1 obj%AdjacencyMatrix(to, from) = -1 endif if(present(between) .and. present(and) )then obj%AdjacencyMatrix(between, and) = 1 obj%AdjacencyMatrix(and, between) = 1 endif end subroutine ! ###################################### ! ###################################### subroutine showGraph(obj,withname) class(Graph_),intent(in) :: obj logical,optional,intent(in)::withname type(IO_) :: f character(200) :: command integer(int32) :: id,n,i,j n=size(obj%vertex) call f%open("./","vertex",".txt") do i=1,n call f%write(str(obj%vertex(i)%x)//" "//str(obj%vertex(i)%y)//" "//str(obj%vertex(i)%z) ) enddo call f%close() call f%open("./","showGraph",".gp") if(present(withname) )then if(withname .eqv. .False.)then do i=1,n command = "set label 'vertex:"//trim(str(i))//"' at "//str(obj%vertex(i)%x)//","//str(obj%vertex(i)%y) call f%write(trim(command) ) enddo else do i=1,n command = "set label 'ID:"//trim(str(i))//" Name: "//trim(obj%vertex(i)%name)& //"' at "//str(obj%vertex(i)%x)//","//str(obj%vertex(i)%y) call f%write(trim(command) ) enddo endif else do i=1,n command = "set label 'ID:"//trim(str(i))//" Name: "//trim(obj%vertex(i)%name)& //"' at "//str(obj%vertex(i)%x)//","//str(obj%vertex(i)%y) call f%write(trim(command) ) enddo endif id=0 do i=1,n do j=1,n if(obj%AdjacencyMatrix (i,j) > 0)then id=id+1 command = "set arrow "//trim(str(id))//" head filled from "& //str(obj%vertex(i)%x)//","//str(obj%vertex(i)%y)//" to "& //str(obj%vertex(j)%x)//","//str(obj%vertex(j)%y) call f%write(trim(command) ) elseif(obj%AdjacencyMatrix (i,j) < 0)then id=id+1 command = "set arrow "//trim(str(id))//" head filled from "& //str(obj%vertex(j)%x)//","//str(obj%vertex(j)%y)//" to "& //str(obj%vertex(i)%x)//","//str(obj%vertex(i)%y) call f%write(trim(command) ) else cycle endif enddo enddo call f%write("unset key") call f%write("plot './vertex.txt'") call f%write("pause -1") call f%close() call system("gnuplot ./showGraph.gp") end subroutine ! ###################################### ! ###################################### subroutine syncGraph(obj,AdjacencyMatrix) class(Graph_),intent(inout) :: obj integer(int32),intent(in)::AdjacencyMatrix(:,:) integer(int32) :: i,j,buf(2) do i=1,size(AdjacencyMatrix,1) do j=1,size(AdjacencyMatrix,2) if(AdjacencyMatrix(i,j) == 0)then cycle endif if(AdjacencyMatrix(i,j)*obj%AdjacencyMatrix(i,j) < 0 )then obj%AdjacencyMatrix(i,j) = 1 obj%AdjacencyMatrix(j,i) = 1 endif if(AdjacencyMatrix(i,j)*obj%AdjacencyMatrix(i,j) > 0 )then cycle endif if(AdjacencyMatrix(i,j)*obj%AdjacencyMatrix(i,j) == 0 )then obj%AdjacencyMatrix(i,j) = obj%AdjacencyMatrix(i,j) + AdjacencyMatrix(i,j) endif enddo enddo end subroutine ! ###################################### end module GraphClass
function spline_test05 ( ) %*****************************************************************************80 % %% TEST05 tests BASIS_MATRIX_BEZIER, BASIS_MATRIX_TMP. % % Licensing: % % This code is distributed under the GNU LGPL license. % % Modified: % % 01 February 2009 % % Author % % John Burkardt % n = 4; ndata = 4; nsample = 4; tdata = [ 0.0E+00, 0.0E+00, 1.0E+00, 1.0E+00 ]'; ydata = [ 7.0E+00, 8.3333333E+00, 10.0E+00, 12.0E+00 ]'; fprintf ( 1, '\n' ); fprintf ( 1, 'TEST05\n' ); fprintf ( 1, ' BASIS_MATRIX_BEZIER sets up the basis\n' ); fprintf ( 1, ' matrix for the uniform Bezier spline.\n' ); mbasis = basis_matrix_bezier ( ); fprintf ( 1, '\n' ); fprintf ( 1, ' TDATA, YDATA\n' ); fprintf ( 1, '\n' ); for i = 1 : ndata fprintf ( 1, '%12f %12f\n', tdata(i), ydata(i) ); end left = 2; fprintf ( 1, '\n' ); fprintf ( 1, ' T, Spline(T)\n' ); fprintf ( 1, '\n' ); for i = 0 : ndata if ( i == 0 ) tlo = tdata(1) - 0.5E+00 * ( tdata(2) - tdata(1) ); thi = tdata(1); elseif ( i < ndata ) tlo = tdata(i); thi = tdata(i+1); elseif ( ndata <= i ) tlo = tdata(ndata); thi = tdata(ndata) + 0.5E+00 * ( tdata(ndata) - tdata(ndata-1) ); end if ( i < ndata ) jhi = nsample - 1; else jhi = nsample; end for j = 0 : jhi tval = ( ( nsample - j ) * tlo ... + ( j ) * thi ) ... / nsample; yval = basis_matrix_tmp ( left, n, mbasis, ndata, tdata, ydata, tval ); if ( 0 < i & j == 0 ) mark = '*'; else mark = ' '; end fprintf ( 1, '%c %12f %12f\n', mark, tval, yval ); end end return end
Formal statement is: lemma asymp_equiv_tendsto_transfer: assumes "f \<sim>[F] g" and "(f \<longlongrightarrow> c) F" shows "(g \<longlongrightarrow> c) F" Informal statement is: If $f$ and $g$ are asymptotically equivalent and $f$ tends to $c$, then $g$ tends to $c$.
= = Plot = =
= = Plot = =
= = Plot = =
= = Plot = =
= = Plot = =
= = Plot = =
= = Plot = =
= = Plot = =
= = Plot = =
= = Plot = =
= = Plot = =
= = Plot = =
--- Day 1: Sonar Sweep --- module SonarSweep import System import System.File import Data.List import Data.String countIncreased : (nums : List Integer) -> List Integer countIncreased nums = zipWith (\a, b => if b > a then 1 else 0) nums $ drop 1 nums countIncreased3 : (nums: List Integer) -> List Integer countIncreased3 nums = countIncreased $ sum <$> transpose [drop 2 nums, drop 1 nums, nums] main : IO () main = do args <- getArgs let (file :: _) = drop 1 args | [] => printLn "No file provided!" (Right symbols) <- readFile file | (Left error) => printLn error let nums = catMaybes $ parsePositive <$> lines symbols (printLn . sum) $ countIncreased nums (printLn . sum) $ countIncreased3 nums
State Before: p : ℕ inst✝ : Fact (Nat.Prime p) F : Polynomial ℤ_[p] a : ℤ_[p] ha : Polynomial.eval a F = 0 z' : ℤ_[p] hz' : Polynomial.eval z' F = 0 hnormz' : ‖z' - a‖ < ‖Polynomial.eval a (↑Polynomial.derivative F)‖ h : ℤ_[p] := z' - a q : ℤ_[p] hq : Polynomial.eval (a + h) F = Polynomial.eval a F + Polynomial.eval a (↑Polynomial.derivative F) * h + q * h ^ 2 ⊢ 0 = Polynomial.eval (a + (z' - a)) F State After: p : ℕ inst✝ : Fact (Nat.Prime p) F : Polynomial ℤ_[p] a : ℤ_[p] ha : Polynomial.eval a F = 0 z' : ℤ_[p] hz' : Polynomial.eval z' F = 0 hnormz' : ‖z' - a‖ < ‖Polynomial.eval a (↑Polynomial.derivative F)‖ h : ℤ_[p] := z' - a q : ℤ_[p] hq : Polynomial.eval (a + h) F = Polynomial.eval a F + Polynomial.eval a (↑Polynomial.derivative F) * h + q * h ^ 2 ⊢ 0 = Polynomial.eval (z' - a + a) F Tactic: rw [add_comm] State Before: p : ℕ inst✝ : Fact (Nat.Prime p) F : Polynomial ℤ_[p] a : ℤ_[p] ha : Polynomial.eval a F = 0 z' : ℤ_[p] hz' : Polynomial.eval z' F = 0 hnormz' : ‖z' - a‖ < ‖Polynomial.eval a (↑Polynomial.derivative F)‖ h : ℤ_[p] := z' - a q : ℤ_[p] hq : Polynomial.eval (a + h) F = Polynomial.eval a F + Polynomial.eval a (↑Polynomial.derivative F) * h + q * h ^ 2 ⊢ 0 = Polynomial.eval (z' - a + a) F State After: no goals Tactic: simp [hz'] State Before: p : ℕ inst✝ : Fact (Nat.Prime p) F : Polynomial ℤ_[p] a : ℤ_[p] ha : Polynomial.eval a F = 0 z' : ℤ_[p] hz' : Polynomial.eval z' F = 0 hnormz' : ‖z' - a‖ < ‖Polynomial.eval a (↑Polynomial.derivative F)‖ h : ℤ_[p] := z' - a q : ℤ_[p] hq : Polynomial.eval (a + h) F = Polynomial.eval a F + Polynomial.eval a (↑Polynomial.derivative F) * h + q * h ^ 2 ⊢ Polynomial.eval (a + h) F = Polynomial.eval a (↑Polynomial.derivative F) * h + q * h ^ 2 State After: no goals Tactic: rw [hq, ha, zero_add] State Before: p : ℕ inst✝ : Fact (Nat.Prime p) F : Polynomial ℤ_[p] a : ℤ_[p] ha : Polynomial.eval a F = 0 z' : ℤ_[p] hz' : Polynomial.eval z' F = 0 hnormz' : ‖z' - a‖ < ‖Polynomial.eval a (↑Polynomial.derivative F)‖ h : ℤ_[p] := z' - a q : ℤ_[p] hq : Polynomial.eval (a + h) F = Polynomial.eval a F + Polynomial.eval a (↑Polynomial.derivative F) * h + q * h ^ 2 ⊢ Polynomial.eval a (↑Polynomial.derivative F) * h + q * h ^ 2 = (Polynomial.eval a (↑Polynomial.derivative F) + q * h) * h State After: no goals Tactic: rw [sq, right_distrib, mul_assoc] State Before: p : ℕ inst✝ : Fact (Nat.Prime p) F : Polynomial ℤ_[p] a : ℤ_[p] ha : Polynomial.eval a F = 0 z' : ℤ_[p] hz' : Polynomial.eval z' F = 0 hnormz' : ‖z' - a‖ < ‖Polynomial.eval a (↑Polynomial.derivative F)‖ h : ℤ_[p] := z' - a q : ℤ_[p] hq : Polynomial.eval (a + h) F = Polynomial.eval a F + Polynomial.eval a (↑Polynomial.derivative F) * h + q * h ^ 2 this✝ : (Polynomial.eval a (↑Polynomial.derivative F) + q * h) * h = 0 hne : ¬h = 0 this : Polynomial.eval a (↑Polynomial.derivative F) + q * h = 0 ⊢ Polynomial.eval a (↑Polynomial.derivative F) = -q * h State After: no goals Tactic: simpa using eq_neg_of_add_eq_zero_left this State Before: p : ℕ inst✝ : Fact (Nat.Prime p) F : Polynomial ℤ_[p] a : ℤ_[p] ha : Polynomial.eval a F = 0 z' : ℤ_[p] hz' : Polynomial.eval z' F = 0 hnormz' : ‖z' - a‖ < ‖Polynomial.eval a (↑Polynomial.derivative F)‖ h : ℤ_[p] := z' - a q : ℤ_[p] hq : Polynomial.eval (a + h) F = Polynomial.eval a F + Polynomial.eval a (↑Polynomial.derivative F) * h + q * h ^ 2 this✝¹ : (Polynomial.eval a (↑Polynomial.derivative F) + q * h) * h = 0 hne : ¬h = 0 this✝ : Polynomial.eval a (↑Polynomial.derivative F) + q * h = 0 this : Polynomial.eval a (↑Polynomial.derivative F) = -q * h ⊢ ‖Polynomial.eval a (↑Polynomial.derivative F)‖ = ‖q‖ * ‖h‖ State After: no goals Tactic: simp [this] State Before: p : ℕ inst✝ : Fact (Nat.Prime p) F : Polynomial ℤ_[p] a : ℤ_[p] ha : Polynomial.eval a F = 0 z' : ℤ_[p] hz' : Polynomial.eval z' F = 0 hnormz' : ‖z' - a‖ < ‖Polynomial.eval a (↑Polynomial.derivative F)‖ h : ℤ_[p] := z' - a q : ℤ_[p] hq : Polynomial.eval (a + h) F = Polynomial.eval a F + Polynomial.eval a (↑Polynomial.derivative F) * h + q * h ^ 2 this✝¹ : (Polynomial.eval a (↑Polynomial.derivative F) + q * h) * h = 0 hne : ¬h = 0 this✝ : Polynomial.eval a (↑Polynomial.derivative F) + q * h = 0 this : Polynomial.eval a (↑Polynomial.derivative F) = -q * h ⊢ ‖q‖ * ‖h‖ ≤ 1 * ‖h‖ State After: case h p : ℕ inst✝ : Fact (Nat.Prime p) F : Polynomial ℤ_[p] a : ℤ_[p] ha : Polynomial.eval a F = 0 z' : ℤ_[p] hz' : Polynomial.eval z' F = 0 hnormz' : ‖z' - a‖ < ‖Polynomial.eval a (↑Polynomial.derivative F)‖ h : ℤ_[p] := z' - a q : ℤ_[p] hq : Polynomial.eval (a + h) F = Polynomial.eval a F + Polynomial.eval a (↑Polynomial.derivative F) * h + q * h ^ 2 this✝¹ : (Polynomial.eval a (↑Polynomial.derivative F) + q * h) * h = 0 hne : ¬h = 0 this✝ : Polynomial.eval a (↑Polynomial.derivative F) + q * h = 0 this : Polynomial.eval a (↑Polynomial.derivative F) = -q * h ⊢ ‖q‖ ≤ 1 Tactic: gcongr State Before: case h p : ℕ inst✝ : Fact (Nat.Prime p) F : Polynomial ℤ_[p] a : ℤ_[p] ha : Polynomial.eval a F = 0 z' : ℤ_[p] hz' : Polynomial.eval z' F = 0 hnormz' : ‖z' - a‖ < ‖Polynomial.eval a (↑Polynomial.derivative F)‖ h : ℤ_[p] := z' - a q : ℤ_[p] hq : Polynomial.eval (a + h) F = Polynomial.eval a F + Polynomial.eval a (↑Polynomial.derivative F) * h + q * h ^ 2 this✝¹ : (Polynomial.eval a (↑Polynomial.derivative F) + q * h) * h = 0 hne : ¬h = 0 this✝ : Polynomial.eval a (↑Polynomial.derivative F) + q * h = 0 this : Polynomial.eval a (↑Polynomial.derivative F) = -q * h ⊢ ‖q‖ ≤ 1 State After: no goals Tactic: apply PadicInt.norm_le_one State Before: p : ℕ inst✝ : Fact (Nat.Prime p) F : Polynomial ℤ_[p] a : ℤ_[p] ha : Polynomial.eval a F = 0 z' : ℤ_[p] hz' : Polynomial.eval z' F = 0 hnormz' : ‖z' - a‖ < ‖Polynomial.eval a (↑Polynomial.derivative F)‖ h : ℤ_[p] := z' - a q : ℤ_[p] hq : Polynomial.eval (a + h) F = Polynomial.eval a F + Polynomial.eval a (↑Polynomial.derivative F) * h + q * h ^ 2 this✝¹ : (Polynomial.eval a (↑Polynomial.derivative F) + q * h) * h = 0 hne : ¬h = 0 this✝ : Polynomial.eval a (↑Polynomial.derivative F) + q * h = 0 this : Polynomial.eval a (↑Polynomial.derivative F) = -q * h ⊢ 1 * ‖h‖ < ‖Polynomial.eval a (↑Polynomial.derivative F)‖ State After: no goals Tactic: simpa State Before: p : ℕ inst✝ : Fact (Nat.Prime p) F : Polynomial ℤ_[p] a : ℤ_[p] ha : Polynomial.eval a F = 0 z' : ℤ_[p] hz' : Polynomial.eval z' F = 0 hnormz' : ‖z' - a‖ < ‖Polynomial.eval a (↑Polynomial.derivative F)‖ h : ℤ_[p] := z' - a q : ℤ_[p] hq : Polynomial.eval (a + h) F = Polynomial.eval a F + Polynomial.eval a (↑Polynomial.derivative F) * h + q * h ^ 2 this✝ : (Polynomial.eval a (↑Polynomial.derivative F) + q * h) * h = 0 this : h = 0 ⊢ z' - a = 0 State After: no goals Tactic: rw [← this]
(*=========================================================================== Specification of CGA screen functions ===========================================================================*) Require Import ssreflect ssrbool ssrnat ssrfun eqtype seq fintype tuple. Require Import procstate procstatemonad bitsrep bitsops bitsprops bitsopsprops. Require Import SPred septac spec spectac safe basic basicprog program basic. Require Import instr instrsyntax instrcodec reader pointsto cursor instrrules macros. Require Import screenspec screenimp. Set Implicit Arguments. Unset Strict Implicit. Import Prenex Implicits. Lemma inlineComputeCharPos_correct col row : col < numCols -> row < numRows -> |-- inlineComputeCharPos_spec col row inlineComputeCharPos. Proof. move => NC NR. rewrite /inlineComputeCharPos_spec/inlineComputeCharPos. autorewrite with push_at. (* We don't unfold OSZCP? anywhere because no rules talk about flags *) (* MOV EDI, screenBase *) rewrite {1}/stateIsAny. specintros => olddi. basicapply MOV_RI_rule. (* SHL EDX, 5 *) basicapply SHL_RI_rule => //. (* ADD EDI, EDX *) basicapply ADD_RR_ruleNoFlags. (* SHL EDX, 2 *) basicapply SHL_RI_rule => //. (* ADD EDI, EDX *) basicapply ADD_RR_ruleNoFlags. (* SHL ECX, 1 *) basicapply SHL_RI_rule => //. (* ADD EDI, ECX *) basicapply ADD_RR_ruleNoFlags; rewrite /stateIsAny; sbazooka. rewrite /charPos/iter !shlB_asMul. rewrite -5!mulB_muln. rewrite -mulB_muln. rewrite !fromNat_mulBn. do 2 rewrite <- addB_addn. rewrite addnA -mulnDr addnC. rewrite addB_addn. reflexivity. Qed. (* Correct placement of unfolding of stateIsAny is tricky. *) Lemma inlineOutputChar_correct col row char : col < numCols -> row < numRows -> |-- inlineOutputChar_spec col row char inlineOutputChar. Proof. move => NC NR. rewrite /inlineOutputChar_spec/inlineOutputChar/charIs. autorewrite with push_at. rewrite {1}/stateIsAny. specintros => olddi oldchar. have ICCP := inlineComputeCharPos_correct NC NR. rewrite /inlineComputeCharPos_spec in ICCP. try_basicapply ICCP. rewrite /stateIsAny. sbazooka. (* MOV BYTE [EDI + 0], EAX *) try_basicapply MOV_MbR_rule. rewrite -> addB0. sbazooka. rewrite /stateIsAny. rewrite -> addB0. sbazooka. Qed. Lemma inlineReadChar_correct col row char : col < numCols -> row < numRows -> |-- inlineReadChar_spec col row char inlineReadChar. Proof. move => NC NR. rewrite /inlineReadChar_spec/inlineReadChar/memIs/interpProgram/charIs. autorewrite with push_at. rewrite {1}/stateIsAny. specintros => oldeax. have ICCP := inlineComputeCharPos_correct NC NR. rewrite /inlineComputeCharPos_spec in ICCP. basicapply ICCP. (* MOV EAX, BYTE [EDI + 0] *) try_basicapply MOV_RMb_rule. rewrite -> addB0. rewrite /BYTEregIs/BYTEregIsAux. sbazooka. rewrite /stateIsAny addB0. sbazooka. Qed.
Formal statement is: lemma emeasure_count_space: assumes "X \<subseteq> A" shows "emeasure (count_space A) X = (if finite X then of_nat (card X) else \<infinity>)" (is "_ = ?M X") Informal statement is: The measure of a finite subset of a countable set is the cardinality of the subset.
{-# OPTIONS --safe --warning=error --without-K #-} open import Functions.Definition open import Orders.WellFounded.Definition module Orders.WellFounded.Induction {a b : _} {A : Set a} {_<_ : Rel {a} {b} A} (wf : WellFounded _<_) where private foldAcc : {c : _} (P : A → Set c) → (∀ x → (∀ y → y < x → P y) → P x) → ∀ z → Accessible _<_ z → P z foldAcc P inductionProof = go where go : (z : A) → (Accessible _<_ z) → P z go z (access prf) = inductionProof z (λ y yLessZ → go y (prf y yLessZ)) rec : {c : _} (P : A → Set c) → (∀ x → (∀ y → y < x → P y) → P x) → (∀ z → P z) rec P inductionProof z = foldAcc P inductionProof _ (wf z)
{-# LANGUAGE AllowAmbiguousTypes #-} {-# LANGUAGE BangPatterns #-} {-# LANGUAGE DataKinds #-} {-# LANGUAGE FlexibleContexts #-} {-# LANGUAGE GADTs #-} {-# LANGUAGE KindSignatures #-} {-# LANGUAGE LambdaCase #-} {-# LANGUAGE RankNTypes #-} {-# LANGUAGE ScopedTypeVariables #-} {-# LANGUAGE TypeApplications #-} {-# LANGUAGE TypeInType #-} {-# LANGUAGE TypeOperators #-} module TensorOps.Learn.NeuralNet.Recurrent ( Network , buildNet , netParams , runNetwork , runNetworkSt , genNet , fullyConnected , ffLayer , stateless , (~*~) , (*~) , (~*) , nmap , trainNetwork , trainNetwork' , networkGradient ) where import Control.Category import Control.DeepSeq import Control.Monad.Primitive import Control.Monad.State import Data.Kind import Data.Singletons import Data.Singletons.Prelude (Sing(..)) import Data.Type.Combinator import Data.Type.Conjunction import Data.Type.Length as TCL import Data.Type.Length.Util as TCL import Data.Type.Nat import Data.Type.Product as TCP import Data.Type.Product.Util as TCP import Data.Type.Sing import Data.Type.Uniform import Data.Type.Vector as TCV import Data.Type.Vector.Util as TCV import Prelude hiding ((.), id) import Statistics.Distribution.Normal import System.Random.MWC import TensorOps.Learn.NeuralNet import TensorOps.NatKind import TensorOps.TOp as TO import TensorOps.Tensor as TT import TensorOps.Types import Type.Class.Higher import Type.Class.Higher.Util import Type.Class.Known import Type.Class.Witness import Type.Family.List import Type.Family.List.Util import Type.Family.Nat import Unsafe.Coerce import qualified TensorOps.Learn.NeuralNet.FeedForward as FF data Network :: ([k] -> Type) -> k -> k -> Type where N :: { _nsSs :: !(Sing ss) , _nsPs :: !(Sing ps) , _nOp :: !(TOp ('[i] ': ss ++ ps) ('[o] ': ss)) , _nState :: !(Prod t ss) , _nParams :: !(Prod t ps) } -> Network t i o instance NFData1 t => NFData (Network t i o) where rnf = \case N _ _ o p s -> o `seq` p `deepseq1` s `deepseq1` () {-# INLINE rnf #-} netParams :: Network t i o -> (forall ss ps. (SingI ss, SingI ps) => Prod t ss -> Prod t ps -> r) -> r netParams = \case N sS sP _ s p -> \f -> f s p \\ sS \\ sP buildNet :: forall ss ps i o t. (SingI ss, SingI ps) => TOp ('[i] ': ss ++ ps) ('[o] ': ss) -- ^ Tensor operation for network -> Prod t ss -- ^ Initial states -> Prod t ps -- ^ Network parameters -> Network t i o buildNet = N sing sing fullyConnected :: forall k (i :: k) (o :: k) (m :: Type -> Type) (t :: [k] -> Type). ( SingI i , SingI o , PrimMonad m , Tensor t ) => Activation k -- ^ Activation function for internal state -> Gen (PrimState m) -> m (Network t i o) fullyConnected a g = (\s w w' b -> buildNet @'[ '[o] ] @'[ '[o,o], '[o,i], '[o] ] fc (s :< Ø) (w' :< w :< b :< Ø) ) <$> genRand (normalDistr 0 0.5) g <*> genRand (normalDistr 0 0.5) g <*> genRand (normalDistr 0 0.5) g <*> genRand (normalDistr 0 0.5) g where fc :: TOp '[ '[i], '[o], [o,o], '[o,i], '[o]] '[ '[o], '[o] ] fc = secondOp @'[ '[i] ] ( firstOp @'[ '[o,i], '[o] ] (TO.swap >>> TO.matVec) >>> firstOp @'[ '[o] ] TO.swap ) >>> firstOp @'[ '[o], '[o] ] (TO.swap >>> TO.matVec) >>> TO.add3 >>> TO.duplicate >>> secondOp @'[ '[o] ] (getAct a) {-# INLINE fc #-} {-# INLINE fullyConnected #-} -- | Convert a neural network from "TensorOps.Learn.NeuralNet.FeedForward" -- to a stateless 'Network'. -- -- Can be thought a functor from the category of stateless neural networks -- to the category of stateful (recurrent) ones. stateless :: FF.Network t i o -> Network t i o stateless = \case FF.N sP o p -> N SNil sP o Ø p {-# INLINE stateless #-} ffLayer :: forall i o m t. (SingI i, SingI o, PrimMonad m, Tensor t) => Gen (PrimState m) -> m (Network t i o) ffLayer g = stateless <$> FF.ffLayer g {-# INLINE ffLayer #-} genNet :: forall k o i m (t :: [k] -> Type). (SingI o, SingI i, PrimMonad m, Tensor t) => [(Integer, (Activation k, Maybe (Activation k)))] -> Activation k -> Maybe (Activation k) -> Gen (PrimState m) -> m (Network t i o) genNet xs0 f fS g = go sing xs0 where go :: forall (j :: k). () => Sing j -> [(Integer, (Activation k, Maybe (Activation k)))] -> m (Network t j o) go sj = (\\ sj) $ \case [] -> fmap (*~ getAct f) $ case fS of Just fS' -> fullyConnected fS' g Nothing -> ffLayer g (x,(f', fS')):xs -> withNatKind x $ \sl -> (\\ sl) $ do n <- go sl xs l <- case fS' of Nothing -> ffLayer g Just fS'' -> fullyConnected fS'' g return $ l *~ getAct f' ~*~ n {-# INLINE go #-} {-# INLINE genNet #-} instance Category (Network t) where id = N SNil SNil idOp Ø Ø (.) = flip (~*~) (~*~) :: forall k (t :: [k] -> Type) a b c. () => Network t a b -> Network t b c -> Network t a c (~*~) = \case N (sSs1 :: Sing ss1) (sPs1 :: Sing ps1) (o1 :: TOp ('[a] ': ss1 ++ ps1) ('[b] ': ss1)) (s1 :: Prod t ss1) (p1 :: Prod t ps1) -> \case N (sSs2 :: Sing ss2) (sPs2 :: Sing ps2) (o2 :: TOp ('[b] ': ss2 ++ ps2) ('[c] ': ss2)) (s2 :: Prod t ss2) (p2 :: Prod t ps2) -> let lSs1 :: Length ss1 lSs1 = singLength sSs1 lSs2 :: Length ss2 lSs2 = singLength sSs2 lPs1 :: Length ps1 lPs1 = singLength sPs1 lPs2 :: Length ps2 lPs2 = singLength sPs2 o :: TOp ('[a] ': (ss2 ++ ss1) ++ (ps1 ++ ps2)) ('[c] ': ss2 ++ ss1) -- all these proofs lol o = (\\ (unsafeCoerce Refl :: ((ss2 ++ ss1) ++ ps1) ++ ps2 :~: (ss2 ++ ss1) ++ (ps1 ++ ps2))) $ (\\ (unsafeCoerce Refl :: ((ss1 ++ ps1) ++ ss2) ++ ps2 :~: (ss1 ++ ps1) ++ (ss2 ++ ps2))) $ (\\ appendAssoc lSs1 lSs2 lPs2 ) $ (\\ appendAssoc lSs2 lSs1 lPs1 ) $ (\\ (lSs2 `TCL.append'` lSs1) `TCL.append'` lPs1) $ (\\ (lSs1 `TCL.append'` lPs1) `TCL.append'` lSs2) $ (\\ lSs1 ) $ (\\ lSs2 ) $ (\\ lSs1 `TCL.append'` lPs1 ) $ (\\ lSs2 `TCL.append'` lPs2 ) $ secondOp @'[ '[a] ] (firstOp @ps2 (TO.swap' lSs2 (lSs1 `TCL.append'` lPs1)) ) >>> firstOp @(ss2 ++ ps2) o1 >>> secondOp @'[ '[b] ] (TO.swap' lSs1 (lSs2 `TCL.append'` lPs2)) >>> firstOp @ss1 o2 in N (sSs2 %:++ sSs1) (sPs1 %:++ sPs2) o (s2 `TCP.append'` s1) (p1 `TCP.append'` p2) infixr 4 ~*~ {-# INLINE (~*~) #-} runNetwork :: (RealFloat (ElemT t), Tensor t) => Network t i o -> t '[i] -> (t '[o], Network t i o) runNetwork (N sS sO o s p) x = (\case y :< s' -> (y, N sS sO o s' p)) . runTOp o $ x :< (s `TCP.append'` p) {-# INLINE runNetwork #-} runNetworkSt :: (RealFloat (ElemT t), Tensor t, MonadState (Network t i o) m) => t '[i] -> m (t '[o]) runNetworkSt x = state $ flip runNetwork x (~*) :: TOp '[ '[a] ] '[ '[b] ] -> Network t b c -> Network t a c f ~* N sS sO o s p = N sS sO (f *>> o) s p infixr 4 ~* {-# INLINE (~*) #-} (*~) :: Network t a b -> TOp '[ '[b] ] '[ '[c] ] -> Network t a c N sS sO o s p *~ f = N sS sO (o >>> firstOp f) s p infixl 5 *~ {-# INLINE (*~) #-} nmap :: SingI o => (forall a. RealFloat a => a -> a) -> Network t i o -> Network t i o nmap f n = n *~ TO.map f {-# INLINE nmap #-} netGrad :: forall k n (t :: [k] -> Type) (i :: k) (o :: k) ss ps. ( Tensor t , RealFloat (ElemT t) , SingI i , SingI o ) => TOp '[ '[o], '[o] ] '[ '[] ] -> Vec n (t '[i]) -> Vec n (t '[o]) -> Sing ss -> Sing ps -> TOp ('[i] ': ss ++ ps) ('[o] ': ss) -> Prod t ss -> Prod t ps -> (Vec n (t '[i]), (Prod t ss, Prod t ps)) netGrad loss xs ys sS sP o s p = (prodToVec' I n grI, splitProd @ps lS grSP) where n :: Nat n n = known \\ xs lS :: Length ss lS = singLength sS lP :: Length ps lP = singLength sP sO :: Sing (Replicate n '[o]) sO = replicateSing (sing :: Sing '[o]) n lI :: Length (Replicate n '[i]) lI = replicateLength @'[i] n lO :: Length (Replicate n '[o]) lO = replicateLength @'[o] n unrolled :: TOp (Replicate n '[i] ++ ss ++ ps) (Replicate n '[o]) unrolled = (\\ sS %:++ sO) $ (\\ sS %:++ sP) $ unroll sS sP o n >>> TO.drop @(Replicate n '[o]) lS o' :: TOp (Replicate n '[i] ++ ss ++ ps ++ Replicate n '[o]) '[ '[] ] o' = (\\ appendAssoc lI (lS `TCL.append'` lP) lO) $ (\\ appendAssoc lS lP lO) $ (\\ lI `TCL.append'` lS `TCL.append'` lP) $ (\\ lO) $ firstOp @(Replicate n '[o]) unrolled >>> rollup @k lS lP loss n xs' :: Prod t (Replicate n '[i] ++ ss ++ ps ++ Replicate n '[o]) xs' = vecToProd' getI (TCV.reverse' xs) `TCP.append'` (s `TCP.append'` ( p `TCP.append'` vecToProd' getI ys ) ) grad :: Prod t (Replicate n '[i] ++ ss ++ ps) grad = (\\ (unsafeCoerce Refl :: Replicate n '[i] ++ ss ++ ps ++ Replicate n '[o] :~: (Replicate n '[i] ++ ss ++ ps) ++ Replicate n '[o] ) ) $ takeProd @(Replicate n '[o]) (lI `TCL.append'` lS `TCL.append'` lP) $ gradTOp o' xs' grI :: Prod t (Replicate n '[i]) grSP :: Prod t (ss ++ ps) (grI, grSP) = splitProd @(ss ++ ps) lI grad {-# INLINE netGrad #-} trainNetwork' :: forall k n (t :: [k] -> Type) (i :: k) (o :: k). ( Tensor t , RealFloat (ElemT t) , SingI i , SingI o ) => TOp '[ '[o], '[o] ] '[ '[] ] -- ^ loss function (input, target) -> ElemT t -- ^ train rate for initial state -> ElemT t -- ^ train rate for network parameters -> Vec n (t '[i]) -- ^ inputs -> Vec n (t '[o]) -- ^ targets -> Network t i o -> Network t i o trainNetwork' loss rS rP xs ys = \case N sS sP o s p -> let (gS, gP) = snd $ netGrad loss xs ys sS sP o s p s' = map1 (f rS) $ zipProd3 (singProd sS) s gS p' = map1 (f rP) $ zipProd3 (singProd sP) p gP in N sS sP o s' p' where f :: forall ns. () => ElemT t -> (Sing :&: t :&: t) ns -> t ns f r !(s1 :&: p1 :&: g1) = TT.zip (\(!p2) (!g2) -> p2 - r * g2) p1 g1 \\ s1 {-# INLINE f #-} {-# INLINE trainNetwork #-} trainNetwork :: forall k (t :: [k] -> Type) (i :: k) (o :: k). ( Tensor t , RealFloat (ElemT t) , SingI i , SingI o ) => TOp '[ '[o], '[o] ] '[ '[] ] -- ^ loss function (input, target) -> ElemT t -- ^ train rate for initial state -> ElemT t -- ^ train rate for network parameters -> [(t '[i], t '[o])] -- ^ inputs and targets -> Network t i o -> Network t i o trainNetwork loss rS rP xsys n = withV xsys $ \v -> let (xs, ys) = TCV.unzip' v in trainNetwork' loss rS rP xs ys n networkGradient :: forall k n (t :: [k] -> Type) (i :: k) (o :: k) r. ( Tensor t , RealFloat (ElemT t) , SingI i , SingI o ) => TOp '[ '[o], '[o] ] '[ '[] ] -- ^ loss function (output, target) -> Vec n (t '[i]) -- ^ inputs -> Vec n (t '[o]) -- ^ targets -> Network t i o -> (forall ss ps. (SingI ss, SingI ps) => Vec n (t '[i]) -> Prod t ss -> Prod t ps -> r) -> r networkGradient loss xs ys = \case N sS sP o s p -> \f -> case netGrad loss xs ys sS sP o s p of (gI, (gS, gP)) -> f gI gS gP \\ sS \\ sP {-# INLINE networkGradient #-} unroll :: forall ss ps i o n. (SingI (ss ++ ps), SingI i) => Sing ss -> Sing ps -> TOp ('[i] ': ss ++ ps) ('[o] ': ss) -> Nat n -> TOp (Replicate n '[i] ++ ss ++ ps) (ss ++ Replicate n '[o]) unroll sS sP o = \case Z_ -> TO.take lS lP \\ appendNil lS S_ (m :: Nat m) -> (\\ (unsafeCoerce Refl :: Replicate m '[i] ++ '[i] ': ss ++ ps :~: '[i] ': Replicate m '[i] ++ ss ++ ps ) ) $ (\\ (unsafeCoerce Refl :: (Replicate m '[i] ++ ss ++ ps) ++ '[ '[o] ] :~: Replicate m '[i] ++ ss ++ (ps >: '[o]) ) ) $ (\\ (unsafeCoerce Refl :: (ss ++ Replicate m '[o]) ++ '[ '[o] ] :~: ss ++ '[o] ': Replicate m '[o] ) ) $ (\\ appendAssoc lS lP (LS LZ :: Length '[ '[o] ])) $ (\\ appendSnoc lP (Proxy @'[o])) $ (\\ replicateLength @'[i] m `TCL.append'` lS `TCL.append'` lP) $ (\\ lS `TCL.append'` replicateLength @'[o] m) $ (\\ replicateLength @'[i] m) $ (\\ lS) $ secondOp @(Replicate m '[i]) @('[i] ': ss ++ ps) @(ss ++ ps >: '[o]) ( (o &&& TO.drop @ps @('[i] ': ss) (LS lS)) >>> TO.swap' (LS LZ) (lS `TCL.append'` lP) ) >>> firstOp @'[ '[o] ] @(Replicate m '[i] ++ ss ++ ps) @(ss ++ Replicate m '[o]) ( unroll sS sP o m ) where lS :: Length ss lS = singLength sS lP :: Length ps lP = singLength sP {-# INLINE unroll #-} rollup :: forall k (ss :: [[k]]) (ps :: [[k]]) (o :: k) (n :: N). () => Length ss -> Length ps -> TOp '[ '[o], '[o] ] '[ '[] ] -> Nat n -> TOp (Replicate n '[o] ++ Replicate n '[o]) '[ '[] ] rollup lS lP loss = \case Z_ -> TO.konst (US UØ) 0 S_ Z_ -> loss S_ (m@(S_ _) :: Nat m) -> let lO :: Length (Replicate m '[o]) lO = replicateLength @'[o] m in (\\ (unsafeCoerce Refl :: Replicate m '[o] ++ '[o] ': '[o] ': Replicate m '[o] :~: '[o] ': Replicate m '[o] ++ '[o] ': Replicate m '[o] ) ) $ (\\ appendSnoc lO (Proxy @'[])) $ (\\ lO) $ (\\ lO `TCL.append'` lO) $ (\\ appendAssoc lO lO (LS LZ :: Length '[ '[] ])) $ secondOp @(Replicate m '[o]) @('[o] ': '[o] ': Replicate m '[o]) @(Replicate m '[o] >: '[]) ( firstOp @(Replicate m '[o]) @('[ '[o], '[o] ]) @('[ '[] ]) loss >>> TO.swap' @'[ '[] ] @(Replicate m '[o]) (LS LZ) lO ) >>> firstOp @'[ '[] ] @(Replicate m '[o] ++ Replicate m '[o]) @'[ '[] ] ( rollup lS lP loss m ) >>> TO.add {-# INLINE rollup #-}
module X [
# ATW relaxation notebook ```python import numpy as np import matplotlib.pyplot as plt import warnings from copy import deepcopy # Global constants f = 1e-4 # [s-1] g = 9.81 # [m s-2] %matplotlib inline plt.rcParams['font.size'] = 14 warnings.simplefilter('ignore') ``` ### Analytical solution Start with the linearized, steady state shallow water equations with linear friction and longshore windstress. Assume cross-shore geostrophic balance. \begin{align} f\mathbf{k}\times\mathbf{u} & = -g\nabla\eta + \frac{1}{h}\left(\tau_y - \mu v\right)\hat{\jmath} \tag{1a} \\ 0 & = \nabla\cdot h\mathbf{u} \tag{1b} \end{align} Taking the curl of (1a) and solving for $\eta$ gives the the Arrested Topography Wave (ATW) of Csanady (1978 *JPO*). I have oriented the problem to $x\to-\infty$ offshore such that $\frac{\partial h}{\partial x} = -s$. $$\frac{\partial^2\eta}{\partial x^2} - \frac{1}{\kappa}\frac{\partial\eta}{\partial y} = 0, \hspace{0.5cm} \frac{1}{\kappa} = \frac{fs}{\mu}\tag{2}$$ The coastal boundary condition (obtained from 1a) requires $u \to 0$ and $h \to 0$ $$\frac{\partial\eta}{\partial x}(0, y) = \frac{\tau_yf}{\mu g} = q_0 \tag{3}$$ Equation (2) is analogous to a constant heat flux boundary condition. The solution is given by Carslaw and Jaeger 1959 (p. 112) $$\eta(x, y) = \frac{\kappa q_0y}{L} + q_0L\left\{\frac{3(x + L)^2 - L^2}{6L^2} - \frac{2}{\pi^2}\sum_{n=1}^\infty\frac{(-1)^n}{n^2}\exp\left(\frac{-\kappa n^2\pi^2y}{L^2}\right)\cos\left(\frac{n\pi(x + L)}{L}\right)\right\} \tag{4}$$ which, as $y\to\infty$, reduces to $$\eta(x, y) = \frac{\kappa q_0y}{L} + q_0L\frac{3(x + L)^2 - L^2}{6L^2} \tag{5}$$ Calculate $\eta$ according to equation (5) ```python def calc_eta(x, y, L, kappa, q_0): """Calculate eta according to equation 5 """ return kappa * q_0 * y / L + q_0 * L * (3 * (x + L)**2 - L**2) / (6 * L**2) ``` Find $\eta$ given problem parameters ```python # Constants L = 1e3 # Slope width [m] tau_y = -1e-4 # Kinematic wind stress [m2 s-2] mu = 1e-2 # Linear friction coefficient [s-1] s = 1 # Shelf slope [dimensionless] # Terms (heat equation analogues) kappa = mu / (f * s) # 'Diffusivity' of eta q_0 = tau_y * f / (mu * g) # 'Flux' of eta through boundary print(q_0) print(kappa) # Coordinates dL = L * 1e-2 xi = np.arange(-L, 0, dL) # x-direction, second coordinate yi = np.arange(0, L, dL) # y-direction, first coordinate x, y = np.meshgrid(xi, yi) # Solution eta = calc_eta(x, y, L, kappa, q_0) ``` -1.0193679918450561e-07 100.0 Plot $\eta$ solution ```python # Plot eta fig, ax = plt.subplots(1, 1, figsize=(10, 10)) ax.contour(xi/L, yi/L, eta, colors='k') for tick in np.arange(0, 1, 0.015): ax.plot([0, 0.005], [tick, tick+0.005], 'k-', clip_on=False) ax.set_xlabel('$\longleftarrow$ $X/L$') ax.set_ylabel('$\longleftarrow$ $Y/L$') ax.xaxis.set_ticks([-1, 0]) ax.yaxis.set_ticks([0, 1]) ax.xaxis.set_ticklabels(['$-L$', 0]) ax.yaxis.set_ticklabels([0, '$L$']) ax.tick_params(direction='out', pad=8) ax.set_xlim([0, -1]) ax.set_ylim([1, 0]) ax.text(0.02, 0.05, 'Low $\eta$', transform=ax.transAxes) ax.text(0.85, 0.9, 'High $\eta$', transform=ax.transAxes) ax.text(0.03, 0.46, '$\\tau_y$', transform=ax.transAxes) ax.arrow(0.04, 0.5, 0, 0.1, transform=ax.transAxes, head_width=0.01, facecolor='k') ax.set_title('Cross-shelf bottom slope (ATW) solution') plt.show() ``` ### Relaxation solution Three schemes: Centered difference $$r_{i, j}^{(n)} = \frac{\eta_{i, j+1}^{(n)} - \eta_{i, j-1}^{(n)}}{2\Delta y} - \kappa\frac{\eta_{i+1, j}^{(n)} - 2\eta_{i, j}^{(n)} + \eta_{i-1, j}^{(n)}}{\Delta x^2}$$ $$\eta_{i, j}^{(n+1)} = \eta_{i, j}^{(n)} - \frac{\mu\Delta x^2}{2\kappa}r_{i, j}^{(n)}$$ Upstream Euler $$r_{i, j}^{(n)} = \frac{\eta_{i, j+1}^{(n)} - \eta_{i, j}^{(n)}}{\Delta y} - \kappa\frac{\eta_{i+1, j}^{(n)} - 2\eta_{i, j}^{(n)} + \eta_{i-1, j}^{(n)}}{\Delta x^2}$$ $$\eta_{i, j}^{(n+1)} = \eta_{i, j}^{(n)} - \frac{\mu}{\left(\frac{2\kappa}{\Delta x} - 1\right)}r_{i, j}^{(n)}$$ Downstream Euler $$r_{i, j}^{(n)} = \frac{\eta_{i, j}^{(n)} - \eta_{i, j-1}^{(n)}}{\Delta y} - \kappa\frac{\eta_{i+1, j}^{(n)} - 2\eta_{i, j}^{(n)} + \eta_{i-1, j}^{(n)}}{\Delta x^2}$$ $$\eta_{i, j}^{(n+1)} = \eta_{i, j}^{(n)} - \frac{\mu}{\left(\frac{2\kappa}{\Delta x} + 1\right)}r_{i, j}^{(n)}$$ Only the downstream Euler is stable. Find $\eta$ by relaxation ```python # Find phi by relaxation # Parameters M = eta.shape[0] # matrix size mu = 1 # SOR convergence parameter TOL = 1e-4 # Convergence tolerance dissipation = 0. # Allocate arrays # Solution eta_soln = calc_eta(x, y, L, kappa, q_0) eta_next = np.copy(eta_soln) # getting the boundary conditions correct here eta = np.zeros(eta.shape) # start from zero to show this is working res = np.zeros(eta.shape) # Make figure array fig, axs = plt.subplots(1, 3, figsize=(17, 6)) N=100 # Relaxation loop for n in range(N): for i in range(1, M-1): # Longshore step for j in range(2, M-1): # Cross-shore step : start from 2 to preserve gradient boundary condition #Downstream Euler : note the switch in i and j, i is dy, j is dx res[i, j] = (eta[i, j] - eta[i-1, j]) / (dL) - kappa * (eta[i, j+1] - 2 * eta[i, j] + eta[i, j-1]) / dL**2 eta_next[i, j] = eta[i, j] - mu / (2 * kappa / dL + 1) * res[i, j] eta = eta_next # move this into the loop for faster convergence if dL**2 * np.max(abs(res)) / np.max(abs(eta)) < TOL and n > 5: # n > 5 just because I'm starting from 0. print('done', n) break # Plot results mesh = axs[0].pcolormesh(xi/L, yi/L, eta_soln) fig.colorbar(mesh, ax=axs[0]) mesh = axs[1].contour(xi/L, yi/L, res, colors='b') fig.colorbar(mesh, ax=axs[1]) mesh=axs[2].pcolormesh(xi/L, yi/L, eta_next) fig.colorbar(mesh, ax=axs[2]) for ax in axs: ax.set_xlim([0, -1]) ax.set_ylim([1, 0]) ``` ```python ```
lemma contour_integral_integral: "contour_integral g f = integral {0..1} (\<lambda>x. f (g x) * vector_derivative g (at x))"
module BiNat.Properties.Minus import BiNat import BiNat.Properties.Plus import BiNat.Properties.Induction import BiNat.Properties.LT import BiNat.Properties.Mult %access public export %default total minusLast00 : (ms, ns : BiNat) -> (tail : List Bit) -> minus' (ms -: O) (ns -: O) tail = minus' ms ns (O :: tail) minusLast00 J J tail = Refl minusLast00 J (ns -: O) tail = Refl minusLast00 J (ns -: I) tail = Refl minusLast00 (ms -: O) J tail = Refl minusLast00 (ms -: I) J tail = Refl minusLast00 (ms -: O) (ns -: O) tail = Refl minusLast00 (ms -: O) (ns -: I) tail = Refl minusLast00 (ms -: I) (ns -: O) tail = Refl minusLast00 (ms -: I) (ns -: I) tail = Refl minusLast10 : (ms, ns : BiNat) -> (tail : List Bit) -> minus' (ms -: I) (ns -: O) tail = minus' ms ns (I :: tail) minusLast10 J J tail = Refl minusLast10 J (ns -: O) tail = Refl minusLast10 J (ns -: I) tail = Refl minusLast10 (ms -: O) J tail = Refl minusLast10 (ms -: I) J tail = Refl minusLast10 (ms -: O) (ns -: O) tail = Refl minusLast10 (ms -: O) (ns -: I) tail = Refl minusLast10 (ms -: I) (ns -: O) tail = Refl minusLast10 (ms -: I) (ns -: I) tail = Refl minusLast11 : (ms, ns : BiNat) -> (tail : List Bit) -> minus' (ms -: I) (ns -: I) tail = minus' ms ns (O :: tail) minusLast11 J J tail = Refl minusLast11 J (ns -: O) tail = Refl minusLast11 J (ns -: I) tail = Refl minusLast11 (ms -: O) J tail = Refl minusLast11 (ms -: I) J tail = Refl minusLast11 (ms -: O) (ns -: O) tail = Refl minusLast11 (ms -: O) (ns -: I) tail = Refl minusLast11 (ms -: I) (ns -: O) tail = Refl minusLast11 (ms -: I) (ns -: I) tail = Refl minusLast01 : (ms, ns : BiNat) -> (tail : List Bit) -> Not (ms = J) -> minus' (ms -: O) (ns -: I) tail = minus' (pred ms) ns (I :: tail) minusLast01 J ns tail notJ = absurd (notJ Refl) minusLast01 (ms -: O) J tail _ = Refl minusLast01 (ms -: I) J tail _ = Refl minusLast01 (ms -: O) (ns -: O) tail _ = Refl minusLast01 (ms -: O) (ns -: I) tail _ = Refl minusLast01 (ms -: I) (ns -: O) tail _ = Refl minusLast01 (ms -: I) (ns -: I) tail _ = Refl minusLast0J : (ms : BiNat) -> (tail : List Bit) -> Not (ms = J) -> minus' (ms -: O) J tail = foldl (-:) (pred ms -: I) tail minusLast0J J tail notJ = absurd (notJ Refl) minusLast0J (ms -: O) tail _ = Refl minusLast0J (ms -: I) tail _ = Refl minusLast1J : (ms : BiNat) -> (tail : List Bit) -> Not (ms = J) -> minus' (ms -: I) J tail = foldl (-:) (ms -: O) tail minusLast1J J tail notJ = absurd (notJ Refl) minusLast1J (ms -: O) tail _ = Refl minusLast1J (ms -: I) tail _ = Refl jMinusIsJ : (n : BiNat) -> minus J n = J jMinusIsJ J = Refl jMinusIsJ (ns -: n) = Refl minusJIsPred : (n : BiNat) -> minus n J = pred n minusJIsPred J = Refl minusJIsPred (J -: O) = Refl minusJIsPred (ns -: n -: O) = rewrite predDashAppendsAcc (ns -: n) [I] in Refl minusJIsPred (J -: I) = Refl minusJIsPred (ns -: n -: I) = Refl minusOfItSelf : (n : BiNat) -> (tail : List Bit) -> minus' n n tail = tailToBiNat tail minusOfItSelf J tail = Refl minusOfItSelf (J -: O) tail = Refl minusOfItSelf (ns -: O -: O) tail = rewrite minusOfItSelf (ns -: O) (O :: tail) in Refl minusOfItSelf (ns -: I -: O) tail = rewrite minusOfItSelf (ns -: I) (O :: tail) in Refl minusOfItSelf (J -: I) tail = Refl minusOfItSelf (ns -: O -: I) tail = rewrite minusOfItSelf (ns -: O) (O :: tail) in Refl minusOfItSelf (ns -: I -: I) tail = rewrite minusOfItSelf (ns -: I) (O :: tail) in Refl minusDashAppendsTail : (m, n : BiNat) -> GT m n -> (tail : List Bit) -> minus' m n tail = foldl (-:) (minus' m n []) tail minusDashAppendsTail J n lt tail impossible minusDashAppendsTail (J -: O) J lt tail = Refl minusDashAppendsTail (ms -: m -: O) J lt tail = Refl minusDashAppendsTail (J -: I) J lt tail = Refl minusDashAppendsTail (ms -: m -: I) J lt tail = Refl minusDashAppendsTail (ms -: O) (ns -: O) (LTAppend ns ms lt O O) tail = rewrite minusLast00 ms ns tail in rewrite minusLast00 ms ns [] in rewrite minusDashAppendsTail ms ns lt (O :: tail) in rewrite minusDashAppendsTail ms ns lt [O] in Refl minusDashAppendsTail (J -: O) (ns -: I) (LTAppend ns J lt I O) tail impossible minusDashAppendsTail (ms -: m -: O) (J -: I) (LTAppend J (ms -: m) lt I O) tail = case lessThanImpliesLTEPred J (ms -: m) lt of LTEEqual _ _ eq => rewrite sym $ eq in Refl LTELessThan _ _ lt2 => rewrite minusDashAppendsTail (pred (ms -: m)) J lt2 (I :: tail) in rewrite minusDashAppendsTail (pred (ms -: m)) J lt2 [I] in Refl minusDashAppendsTail (ms -: m -: O) (ns -: n -: I) (LTAppend (ns -: n) (ms -: m) lt I O) tail = case lessThanImpliesLTEPred (ns -: n) (ms -: m) lt of LTEEqual _ _ eq => rewrite sym $ eq in rewrite minusOfItSelf (ns -: n) (I :: tail) in rewrite minusOfItSelf (ns -: n) [I] in Refl LTELessThan _ _ lt2 => rewrite minusDashAppendsTail (pred (ms -: m)) (ns -: n) lt2 (I :: tail) in rewrite minusDashAppendsTail (pred (ms -: m)) (ns -: n) lt2 [I] in Refl minusDashAppendsTail (ms -: I) (ns -: O) (LTLeading ns ms eq) tail = rewrite eq in rewrite minusLast10 ms ms tail in rewrite minusLast10 ms ms [] in case ms of J => Refl (ms2 -: m) => rewrite minusOfItSelf (ms2 -: m) (I :: tail) in rewrite minusOfItSelf (ms2 -: m) [I] in Refl minusDashAppendsTail (ms -: m -: I) (ns -: O) (LTAppend ns (ms -: m) lt O I) tail = rewrite minusDashAppendsTail (ms -: m) ns lt (I :: tail) in rewrite minusDashAppendsTail (ms -: m) ns lt [I] in Refl minusDashAppendsTail (J -: I) (ns -: I) (LTAppend ns J lt I I) tail impossible minusDashAppendsTail (ms -: m -: I) (ns -: I) (LTAppend ns (ms -: m) lt I I) tail = rewrite minusDashAppendsTail (ms -: m) ns lt (O :: tail) in rewrite minusDashAppendsTail (ms -: m) ns lt [O] in Refl plusNMinusN : (m, n : BiNat) -> minus (plus m n) n = m plusNMinusN J J = Refl plusNMinusN J (J -: O) = Refl plusNMinusN J (ns -: O -: O) = minusOfItSelf (ns -: O) [I] plusNMinusN J (ns -: I -: O) = minusOfItSelf (ns -: I) [I] plusNMinusN J (J -: I) = Refl plusNMinusN J (ns -: O -: I) = minusOfItSelf (ns -: O) [I] plusNMinusN J (ns -: I -: I) = rewrite succDashAppendsAcc ns [O, O] in rewrite predOfDoubled (succ ns) (succIsNotJ ns) in rewrite predOfSucc ns in rewrite minusOfItSelf (ns -: I) [I] in Refl plusNMinusN (J -: O) J = Refl plusNMinusN (ms -: O -: O) J = Refl plusNMinusN (ms -: I -: O) J = Refl plusNMinusN (J -: I) J = Refl plusNMinusN (ms -: O -: I) J = Refl plusNMinusN (ms -: I -: I) J = rewrite succDashAppendsAcc ms [O, O] in rewrite predOfDoubled (succ ms) (succIsNotJ ms) in rewrite predOfSucc ms in Refl plusNMinusN (ms -: O) (ns -: O) = rewrite plusDashAppendsAcc ms ns O [O] in rewrite minusLast00 (plus ms ns) ns [] in rewrite minusDashAppendsTail (plus ms ns) ns (lessThanPlus ns ms) [O] in rewrite plusNMinusN ms ns in Refl plusNMinusN (ms -: O) (ns -: I) = rewrite plusDashAppendsAcc ms ns O [I] in rewrite minusLast11 (plus ms ns) ns [] in rewrite minusDashAppendsTail (plus ms ns) ns (lessThanPlus ns ms) [O] in rewrite plusNMinusN ms ns in Refl plusNMinusN (ms -: I) (ns -: O) = rewrite plusDashAppendsAcc ms ns O [I] in rewrite minusLast10 (plus ms ns) ns [] in rewrite minusDashAppendsTail (plus ms ns) ns (lessThanPlus ns ms) [I] in rewrite plusNMinusN ms ns in Refl plusNMinusN (ms -: I) (ns -: I) = rewrite plusDashAppendsAcc ms ns I [O] in rewrite sym $ succGoesToCarry ms ns [] in rewrite minusLast01 (succ (plus ms ns)) ns [] (succIsNotJ (plus ms ns)) in rewrite predOfSucc (plus ms ns) in rewrite minusDashAppendsTail (plus ms ns) ns (lessThanPlus ns ms) [I] in rewrite plusNMinusN ms ns in Refl minusNPlusN : (m, n : BiNat) -> GT m n -> plus (minus m n) n = m minusNPlusN m n = induction (\k => LT n k -> plus (minus k n) n = k) (\k, pk, lt => case lessThanImpliesLTEPred n (succ k) lt of LTEEqual _ _ eq => rewrite eq in rewrite predOfSucc k in rewrite sym $ jPlusIsSucc k in rewrite plusNMinusN J k in Refl LTELessThan _ _ lt2 => let pk' = pk (replace {P = \z => LT n z} (predOfSucc k) lt2) in replace {P = \z => plus (minus (succ z) n) n = succ k} pk' $ rewrite sym $ jPlusIsSucc (plus (minus k n) n) in rewrite plusAssociative J (minus k n) n in rewrite plusNMinusN (plus J (minus k n)) n in rewrite sym $ plusAssociative J (minus k n) n in rewrite pk' in jPlusIsSucc k ) (\lt => absurd (uninhabited lt)) m succIntoMinus : (m, n : BiNat) -> GT m n -> succ (minus m n) = minus (succ m) n succIntoMinus m n lt = induction (\k => LT n k -> succ (minus k n) = minus (succ k) n) (\k, pk, ltSucc => case lessThanImpliesLTEPred n (succ k) ltSucc of LTEEqual _ _ eq => rewrite eq in rewrite predOfSucc k in rewrite sym $ jPlusIsSucc k in rewrite plusNMinusN J k in rewrite sym $ jPlusIsSucc (plus J k) in rewrite plusAssociative J J k in rewrite plusNMinusN (J -: O) k in Refl LTELessThan _ _ lt => rewrite sym $ minusNPlusN (succ k) n ltSucc in rewrite sym $ jPlusIsSucc (plus (minus (succ k) n) n) in rewrite plusAssociative J (minus (succ k) n) n in rewrite plusNMinusN (plus J (minus (succ k) n)) n in rewrite jPlusIsSucc (minus (succ k) n) in rewrite plusNMinusN (minus (succ k) n) n in Refl ) (absurd . uninhabited) m lt succNMinusNIsJ : (n : BiNat) -> minus (succ n) n = J succNMinusNIsJ J = Refl succNMinusNIsJ (ns -: O) = rewrite minusLast10 ns ns [] in minusOfItSelf ns [I] succNMinusNIsJ (ns -: I) = rewrite succDashAppendsAcc ns [O] in rewrite minusLast01 (succ ns) ns [] (succIsNotJ ns) in rewrite predOfSucc ns in minusOfItSelf ns [I] nMinusPredNIsJ : (n : BiNat) -> minus n (pred n) = J nMinusPredNIsJ J = Refl nMinusPredNIsJ (J -: O) = Refl nMinusPredNIsJ (ns -: n -: O) = rewrite predDashAppendsAcc (ns -: n) [I] in minusOfItSelf (pred (ns -: n)) [I] nMinusPredNIsJ (ns -: I) = rewrite minusLast10 ns ns [] in minusOfItSelf ns [I] minusIntoPlusLeft : (l, m, n : BiNat) -> GT l n -> minus (plus l m) n = plus (minus l n) m minusIntoPlusLeft l m n lt = induction (\k => minus (plus l k) n = plus (minus l n) k) (\k, pk => rewrite sym $ plusJIsSucc k in rewrite plusAssociative l k J in rewrite plusJIsSucc (plus l k) in let nLtLPlusK = lessThanTransitive lt (replace (plusSymmetric k l) (lessThanPlus l k)) in rewrite sym $ succIntoMinus (plus l k) n nLtLPlusK in rewrite pk in rewrite sym $ plusJIsSucc (plus (minus l n) k5) in rewrite sym $ plusAssociative (minus l n) k J in Refl ) ( rewrite plusJIsSucc l in rewrite plusJIsSucc (minus l n) in sym $ succIntoMinus l n lt ) m minusIntoPlusRight : (l, m, n : BiNat) -> GT m n -> minus (plus l m) n = plus l (minus m n) minusIntoPlusRight l m n lt = rewrite plusSymmetric l m in rewrite minusIntoPlusLeft m l n lt in plusSymmetric (minus m n) l minusGreater : (m, n : BiNat) -> LT m n -> (tail : List Bit) -> minus' m n tail = J minusGreater m J lt tail impossible minusGreater J (ns -: n) lt tail = Refl minusGreater (ms -: O) (ns -: O) (LTAppend ms ns lt O O) tail = rewrite minusLast00 ms ns tail in minusGreater ms ns lt (O :: tail) minusGreater (ms -: I) (ns -: O) (LTAppend ms ns lt I O) tail = rewrite minusLast10 ms ns tail in minusGreater ms ns lt (I :: tail) minusGreater (ms -: I) (ns -: I) (LTAppend ms ns lt I I) tail = rewrite minusLast11 ms ns tail in minusGreater ms ns lt (O :: tail) minusGreater (J -: O) (ns -: I) lt tail = Refl minusGreater (ms -: m -: O) (ns -: I) (LTAppend (ms -: m) ns lt O I) tail = let lt2 = lessThanTransitive (predIsLessThan (ms -: m) (JLT ms m)) lt in minusGreater (pred (ms -: m)) ns lt2 (I :: tail) minusGreater (ms -: m -: O) (ns -: I) (LTLeading (ms -: m) ns eq) tail = let lt = replace {P = \z => LT (pred (ms -: m)) z} eq (predIsLessThan (ms -: m) (JLT ms m)) in minusGreater (pred (ms -: m)) ns lt (I :: tail) minusOfSuccs : (m, n : BiNat) -> minus m n = minus (succ m) (succ n) minusOfSuccs J J = Refl minusOfSuccs J (ns -: O) = Refl minusOfSuccs J (ns -: I) = rewrite succDashAppendsAcc ns [O] in rewrite minusGreater J (succ ns) (succGreaterThanJ ns) [O] in Refl minusOfSuccs (J -: O) J = Refl minusOfSuccs (ms -: m -: O) J = rewrite minusDashAppendsTail (ms -: m) J (JLT ms m) [I] in rewrite minusJIsPred (ms -: m) in Refl minusOfSuccs (J -: I) J = Refl minusOfSuccs (ms -: m -: I) J = rewrite succDashAppendsAcc (ms -: m) [O] in rewrite minusLast00 (succ (ms -: m)) J [] in rewrite minusDashAppendsTail (succ (ms -: m)) J (succGreaterThanJ (ms -: m)) [O] in rewrite minusJIsPred (succ (ms -: m)) in rewrite predOfSucc (ms -: m) in Refl minusOfSuccs (ms -: O) (ns -: O) = rewrite minusLast11 ms ns [] in minusLast00 ms ns [] minusOfSuccs (J -: O) (ns -: I) = rewrite succDashAppendsAcc ns [O] in sym $ minusGreater J (succ ns) (succGreaterThanJ ns) [I] minusOfSuccs (ms -: m -: O) (ns -: I) = rewrite succDashAppendsAcc ns [O] in case lessThanOrGTE ns (pred (ms -: m)) of Left nLTpredm => let succnLTm = replace {P = \z => LT (succ ns) z} (succOfPred (ms -: m) uninhabited) $ succKeepsLessThan ns (pred (ms -: m)) nLTpredm in rewrite minusDashAppendsTail (pred (ms -: m)) ns nLTpredm [I] in rewrite minusDashAppendsTail (ms -: m) (succ ns) succnLTm [I] in rewrite minusOfSuccs (pred (ms -: m)) ns in rewrite succOfPred (ms -: m) uninhabited in Refl Right (LTEEqual (pred (ms -: m)) ns eq) => rewrite sym $ succOfPred (ms -: m) uninhabited in rewrite eq in rewrite predOfSucc ns in rewrite minusOfItSelf ns [I] in rewrite minusOfItSelf (succ ns) [I] in Refl Right (LTELessThan (pred (ms -: m)) ns predmLTn) => let mLTsuccn = replace {P = \z => LT z (succ ns)} (succOfPred (ms -: m) uninhabited) $ succKeepsLessThan (pred (ms -: m)) ns predmLTn in rewrite minusGreater (pred (ms -: m)) ns predmLTn [I] in rewrite minusGreater (ms -: m) (succ ns) mLTsuccn [I] in Refl minusOfSuccs (ms -: I) (ns -: O) = rewrite minusLast10 ms ns [] in rewrite succDashAppendsAcc ms [O] in rewrite minusLast01 (succ ms) ns [] (succIsNotJ ms) in rewrite predOfSucc ms in Refl minusOfSuccs (ms -: I) (ns -: I) = rewrite minusLast11 ms ns [] in rewrite succDashAppendsAcc ms [O] in rewrite succDashAppendsAcc ns [O] in rewrite minusLast00 (succ ms) (succ ns) [] in case lessThanOrGTE ns ms of Left gt => rewrite minusDashAppendsTail ms ns gt [O] in rewrite minusDashAppendsTail (succ ms) (succ ns) (succKeepsLessThan ns ms gt) [O] in rewrite minusOfSuccs ms ns in Refl Right (LTEEqual ms ns eq) => rewrite eq in rewrite minusOfItSelf ns [O] in rewrite minusOfItSelf (succ ns) [O] in Refl Right (LTELessThan ms ns lt) => rewrite minusGreater ms ns lt [O] in rewrite minusGreater (succ ms) (succ ns) (succKeepsLessThan ms ns lt) [O] in Refl predIntoMinus' : (m, n : BiNat) -> GT m n -> pred (minus m n) = minus (pred m) n predIntoMinus' m n gt = induction (\k => GT k n -> pred (minus k n) = minus (pred k) n) (\k, pk, nLTsucck => case lessThanImpliesLTEPred n (succ k) nLTsucck of LTEEqual n (pred $ succ k) eq => rewrite eq in rewrite predOfSucc k in rewrite succNMinusNIsJ k in rewrite minusOfItSelf k [] in Refl LTELessThan n (pred $ succ k) lt => let nLTk = replace (predOfSucc k) lt in rewrite sym $ succIntoMinus k n nLTk in rewrite predOfSucc (minus k n) in rewrite predOfSucc k in Refl ) (\gt => absurd $ uninhabited gt) m gt predIntoMinus : (m, n : BiNat) -> pred (minus m n) = minus (pred m) n predIntoMinus m n = case lessThanOrGTE n m of Left gt => predIntoMinus' m n gt Right (LTEEqual m n eq) => rewrite eq in rewrite minusOfItSelf n [] in case predLessThanEqual n of LTEEqual (pred n) n eq2 => rewrite eq2 in sym $ minusOfItSelf n [] LTELessThan (pred n) n lt => rewrite minusGreater (pred n) n lt [] in Refl Right (LTELessThan m n lt) => rewrite minusGreater m n lt [] in let predmLTn = transLTEandLT (predLessThanEqual m) lt in rewrite minusGreater (pred m) n predmLTn [] in Refl predIntoMinusSucc : (m, n : BiNat) -> pred (minus m n) = minus m (succ n) predIntoMinusSucc J n = rewrite jMinusIsJ n in rewrite jMinusIsJ (succ n) in Refl predIntoMinusSucc (ms -: m) n = rewrite predIntoMinus (ms -: m) n in rewrite minusOfSuccs (pred (ms -: m)) n in rewrite succOfPred (ms -: m) uninhabited in Refl minusTwiceLeft : (l, m, n : BiNat) -> minus (minus l m) n = minus l (plus m n) minusTwiceLeft l m n = induction (\k => minus (minus l k) n = minus l (plus k n)) (\k, pk => rewrite sym $ predIntoMinusSucc l k in rewrite sym $ jPlusIsSucc k in rewrite sym $ plusAssociative J k n in rewrite jPlusIsSucc (plus k n) in rewrite sym $ predIntoMinusSucc l (plus k n) in rewrite sym $ predIntoMinus (minus l k) n in rewrite pk in Refl ) ( rewrite minusJIsPred l in rewrite sym $ predIntoMinus l n in rewrite jPlusIsSucc n in rewrite sym $ predIntoMinusSucc l n in Refl ) m minusLessThanOriginal : (m, n : BiNat) -> GT m J -> LT (minus m n) m minusLessThanOriginal m n mgtj = induction (\k => LT (minus m k) m) (\k, pk => let lte1 = predLessThanEqual (minus m k) in replace {P = \z => LT z m} (predIntoMinusSucc m k) (transLTEandLT lte1 pk) ) (replace {P = \z => LT z m} (sym $ minusJIsPred m) (predIsLessThan m mgtj)) n multDistributesMinusLeft : (l, m, n : BiNat) -> GT l m -> mult (minus l m) n = minus (mult l n) (mult m n) multDistributesMinusLeft l m n gt = induction (\k => GT k m -> mult (minus k m) n = minus (mult k n) (mult m n)) (\k, pk, succkGTm => case lessThanImpliesLTEPred m (succ k) succkGTm of LTEEqual _ _ eq => rewrite eq in rewrite predOfSucc k in rewrite succNMinusNIsJ k in rewrite plusJIsSucc n in rewrite predOfSucc n in rewrite multOfSuccLeft k n in rewrite plusNMinusN n (mult k n) in Refl LTELessThan _ _ lt => let mLTk = replace (predOfSucc k) lt in rewrite sym $ succIntoMinus k m mLTk in rewrite multOfSuccLeft (minus k m) n in rewrite pk mLTk in rewrite multOfSuccLeft k n in rewrite minusIntoPlusRight n (mult k n) (mult m n) (multNKeepsLT m k mLTk n) in Refl ) (absurd . uninhabited) l gt multDistributesMinusRight : (l, m, n : BiNat) -> GT m n -> mult l (minus m n) = minus (mult l m) (mult l n) multDistributesMinusRight l m n gt = rewrite multSymmetric l (minus m n) in rewrite multDistributesMinusLeft m n l gt in rewrite multSymmetric l m in rewrite multSymmetric l n in Refl
foo : ? -> Int foo x = 42
State Before: α : Type u β : Type v ι : Type ?u.14579 π : ι → Type ?u.14584 inst✝¹ : TopologicalSpace α inst✝ : TopologicalSpace β s t✝ : Set α hs : IsCompact s U : α → Set α hU : ∀ (x : α), x ∈ s → U x ∈ 𝓝 x t : Finset ↑s ht : s ⊆ ⋃ (x : ↑s) (_ : x ∈ t), U ↑x ⊢ s ⊆ ⋃ (x : α) (_ : x ∈ Finset.image Subtype.val t), U x State After: no goals Tactic: rwa [Finset.set_biUnion_finset_image]
[STATEMENT] lemma expand_arctan_approx: "(\<Sum>k<(numeral n::nat). inverse (f k) * inverse (x ^ k)) = inverse (f 0) + (\<Sum>k<pred_numeral n. inverse (f (k+1)) * inverse (x^k)) / x" "(\<Sum>k<Suc 0. inverse (f k) * inverse (x^k)) = inverse (f 0 :: 'a :: field)" "(\<Sum>k<(0::nat). inverse (f k) * inverse (x^k)) = 0" [PROOF STATE] proof (prove) goal (1 subgoal): 1. (\<Sum>k<numeral n. inverse (f k) * inverse (x ^ k)) = inverse (f 0) + (\<Sum>k<pred_numeral n. inverse (f (k + 1)) * inverse (x ^ k)) / x &&& (\<Sum>k<Suc 0. inverse (f k) * inverse (x ^ k)) = inverse (f 0) &&& (\<Sum>k<0. inverse (f k) * inverse (x ^ k)) = (0::'a) [PROOF STEP] proof - [PROOF STATE] proof (state) goal (3 subgoals): 1. (\<Sum>k<numeral n. inverse (f k) * inverse (x ^ k)) = inverse (f 0) + (\<Sum>k<pred_numeral n. inverse (f (k + 1)) * inverse (x ^ k)) / x 2. (\<Sum>k<Suc 0. inverse (f k) * inverse (x ^ k)) = inverse (f 0) 3. (\<Sum>k<0. inverse (f k) * inverse (x ^ k)) = (0::'a) [PROOF STEP] { [PROOF STATE] proof (state) goal (3 subgoals): 1. (\<Sum>k<numeral n. inverse (f k) * inverse (x ^ k)) = inverse (f 0) + (\<Sum>k<pred_numeral n. inverse (f (k + 1)) * inverse (x ^ k)) / x 2. (\<Sum>k<Suc 0. inverse (f k) * inverse (x ^ k)) = inverse (f 0) 3. (\<Sum>k<0. inverse (f k) * inverse (x ^ k)) = (0::'a) [PROOF STEP] fix m :: nat [PROOF STATE] proof (state) goal (3 subgoals): 1. (\<Sum>k<numeral n. inverse (f k) * inverse (x ^ k)) = inverse (f 0) + (\<Sum>k<pred_numeral n. inverse (f (k + 1)) * inverse (x ^ k)) / x 2. (\<Sum>k<Suc 0. inverse (f k) * inverse (x ^ k)) = inverse (f 0) 3. (\<Sum>k<0. inverse (f k) * inverse (x ^ k)) = (0::'a) [PROOF STEP] have "(\<Sum>k<Suc m. inverse (f k * x^k)) = inverse (f 0) + (\<Sum>k=Suc 0..<Suc m. inverse (f k * x^k))" [PROOF STATE] proof (prove) goal (1 subgoal): 1. (\<Sum>k<Suc m. inverse (f k * x ^ k)) = inverse (f 0) + (\<Sum>k = Suc 0..<Suc m. inverse (f k * x ^ k)) [PROOF STEP] by (subst atLeast0LessThan [symmetric], subst sum.atLeast_Suc_lessThan) simp_all [PROOF STATE] proof (state) this: (\<Sum>k<Suc m. inverse (f k * x ^ k)) = inverse (f 0) + (\<Sum>k = Suc 0..<Suc m. inverse (f k * x ^ k)) goal (3 subgoals): 1. (\<Sum>k<numeral n. inverse (f k) * inverse (x ^ k)) = inverse (f 0) + (\<Sum>k<pred_numeral n. inverse (f (k + 1)) * inverse (x ^ k)) / x 2. (\<Sum>k<Suc 0. inverse (f k) * inverse (x ^ k)) = inverse (f 0) 3. (\<Sum>k<0. inverse (f k) * inverse (x ^ k)) = (0::'a) [PROOF STEP] also [PROOF STATE] proof (state) this: (\<Sum>k<Suc m. inverse (f k * x ^ k)) = inverse (f 0) + (\<Sum>k = Suc 0..<Suc m. inverse (f k * x ^ k)) goal (3 subgoals): 1. (\<Sum>k<numeral n. inverse (f k) * inverse (x ^ k)) = inverse (f 0) + (\<Sum>k<pred_numeral n. inverse (f (k + 1)) * inverse (x ^ k)) / x 2. (\<Sum>k<Suc 0. inverse (f k) * inverse (x ^ k)) = inverse (f 0) 3. (\<Sum>k<0. inverse (f k) * inverse (x ^ k)) = (0::'a) [PROOF STEP] have "(\<Sum>k=Suc 0..<Suc m. inverse (f k * x^k)) = (\<Sum>k<m. inverse (f (k+1) * x^k)) / x" [PROOF STATE] proof (prove) goal (1 subgoal): 1. (\<Sum>k = Suc 0..<Suc m. inverse (f k * x ^ k)) = (\<Sum>k<m. inverse (f (k + 1) * x ^ k)) / x [PROOF STEP] by (subst sum.shift_bounds_Suc_ivl) (simp add: sum_distrib_left divide_inverse algebra_simps atLeast0LessThan power_commutes) [PROOF STATE] proof (state) this: (\<Sum>k = Suc 0..<Suc m. inverse (f k * x ^ k)) = (\<Sum>k<m. inverse (f (k + 1) * x ^ k)) / x goal (3 subgoals): 1. (\<Sum>k<numeral n. inverse (f k) * inverse (x ^ k)) = inverse (f 0) + (\<Sum>k<pred_numeral n. inverse (f (k + 1)) * inverse (x ^ k)) / x 2. (\<Sum>k<Suc 0. inverse (f k) * inverse (x ^ k)) = inverse (f 0) 3. (\<Sum>k<0. inverse (f k) * inverse (x ^ k)) = (0::'a) [PROOF STEP] finally [PROOF STATE] proof (chain) picking this: (\<Sum>k<Suc m. inverse (f k * x ^ k)) = inverse (f 0) + (\<Sum>k<m. inverse (f (k + 1) * x ^ k)) / x [PROOF STEP] have "(\<Sum>k<Suc m. inverse (f k) * inverse (x ^ k)) = inverse (f 0) + (\<Sum>k<m. inverse (f (k + 1)) * inverse (x ^ k)) / x" [PROOF STATE] proof (prove) using this: (\<Sum>k<Suc m. inverse (f k * x ^ k)) = inverse (f 0) + (\<Sum>k<m. inverse (f (k + 1) * x ^ k)) / x goal (1 subgoal): 1. (\<Sum>k<Suc m. inverse (f k) * inverse (x ^ k)) = inverse (f 0) + (\<Sum>k<m. inverse (f (k + 1)) * inverse (x ^ k)) / x [PROOF STEP] by simp [PROOF STATE] proof (state) this: (\<Sum>k<Suc m. inverse (f k) * inverse (x ^ k)) = inverse (f 0) + (\<Sum>k<m. inverse (f (k + 1)) * inverse (x ^ k)) / x goal (3 subgoals): 1. (\<Sum>k<numeral n. inverse (f k) * inverse (x ^ k)) = inverse (f 0) + (\<Sum>k<pred_numeral n. inverse (f (k + 1)) * inverse (x ^ k)) / x 2. (\<Sum>k<Suc 0. inverse (f k) * inverse (x ^ k)) = inverse (f 0) 3. (\<Sum>k<0. inverse (f k) * inverse (x ^ k)) = (0::'a) [PROOF STEP] } [PROOF STATE] proof (state) this: (\<Sum>k<Suc ?m2. inverse (f k) * inverse (x ^ k)) = inverse (f 0) + (\<Sum>k<?m2. inverse (f (k + 1)) * inverse (x ^ k)) / x goal (3 subgoals): 1. (\<Sum>k<numeral n. inverse (f k) * inverse (x ^ k)) = inverse (f 0) + (\<Sum>k<pred_numeral n. inverse (f (k + 1)) * inverse (x ^ k)) / x 2. (\<Sum>k<Suc 0. inverse (f k) * inverse (x ^ k)) = inverse (f 0) 3. (\<Sum>k<0. inverse (f k) * inverse (x ^ k)) = (0::'a) [PROOF STEP] from this[of "pred_numeral n"] [PROOF STATE] proof (chain) picking this: (\<Sum>k<Suc (pred_numeral n). inverse (f k) * inverse (x ^ k)) = inverse (f 0) + (\<Sum>k<pred_numeral n. inverse (f (k + 1)) * inverse (x ^ k)) / x [PROOF STEP] show "(\<Sum>k<numeral n. inverse (f k) * inverse (x^k)) = inverse (f 0) + (\<Sum>k<pred_numeral n. inverse (f (k+1)) * inverse (x^k)) / x" [PROOF STATE] proof (prove) using this: (\<Sum>k<Suc (pred_numeral n). inverse (f k) * inverse (x ^ k)) = inverse (f 0) + (\<Sum>k<pred_numeral n. inverse (f (k + 1)) * inverse (x ^ k)) / x goal (1 subgoal): 1. (\<Sum>k<numeral n. inverse (f k) * inverse (x ^ k)) = inverse (f 0) + (\<Sum>k<pred_numeral n. inverse (f (k + 1)) * inverse (x ^ k)) / x [PROOF STEP] by (simp add: numeral_eq_Suc) [PROOF STATE] proof (state) this: (\<Sum>k<numeral n. inverse (f k) * inverse (x ^ k)) = inverse (f 0) + (\<Sum>k<pred_numeral n. inverse (f (k + 1)) * inverse (x ^ k)) / x goal (2 subgoals): 1. (\<Sum>k<Suc 0. inverse (f k) * inverse (x ^ k)) = inverse (f 0) 2. (\<Sum>k<0. inverse (f k) * inverse (x ^ k)) = (0::'a) [PROOF STEP] qed simp_all
\subsubsection{Variables} \input{sections/programming/common_features/Variables} \subsubsection{Arrays} \input{sections/programming/common_features/Arrays} \subsubsection{If Statements} \input{sections/programming/common_features/If} \subsubsection{Switch Statements} \input{sections/programming/common_features/Switch}
module Noether.Algebra.Actions.Compatible where import Data.Complex import Noether.Lemmata.Prelude import Noether.Lemmata.TypeFu import Noether.Algebra.Single import Noether.Algebra.Tags import Noether.Algebra.Actions.Acts {-| A strategy-parameterized typeclass for a compatible action, where compatibility is defined in the group action sense. A compatible action satisfies a `act` (a' `act` b) = (a `op` a') `act` b -} class CompatibleK (lr :: Side) (op :: k1) (act :: k2) a b (s :: CompatibleE) data CompatibleE = Compatible_Acts_Semigroup { compatible_actor :: Type , compatible_action :: ActsE , compatible_actor_semigroup :: SemigroupE } type family CompatibleS (lr :: Side) (op :: k1) (act :: k2) (a :: Type) (b :: Type) = (r :: CompatibleE) instance (ActsK lr act a b za, SemigroupK op a zs) => CompatibleK lr op act a b (Compatible_Acts_Semigroup a za zs)
/- Copyright (c) 2021 Microsoft Corporation. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Leonardo de Moura -/ import Lean.Meta.AppBuilder import Lean.Class namespace Lean.Meta inductive CongrArgKind where /-- It is a parameter for the congruence theorem, the parameter occurs in the left and right hand sides. -/ | fixed /-- It is not a parameter for the congruence theorem, the theorem was specialized for this parameter. This only happens if the parameter is a subsingleton/proposition, and other parameters depend on it. -/ | fixedNoParam /-- The lemma contains three parameters for this kind of argument `a_i`, `b_i` and `eq_i : a_i = b_i`. `a_i` and `b_i` represent the left and right hand sides, and `eq_i` is a proof for their equality. -/ | eq /-- The congr-simp theorems contains only one parameter for this kind of argument, and congr theorems contains two. They correspond to arguments that are subsingletons/propositions. -/ | cast /-- The lemma contains three parameters for this kind of argument `a_i`, `b_i` and `eq_i : HEq a_i b_i`. `a_i` and `b_i` represent the left and right hand sides, and `eq_i` is a proof for their heterogeneous equality. -/ | heq /-- For congr-simp theorems only. Indicates a decidable instance argument. The lemma contains two arguments [a_i : Decidable ...] [b_i : Decidable ...] -/ | subsingletonInst deriving Inhabited, Repr structure CongrTheorem where type : Expr proof : Expr argKinds : Array CongrArgKind private def addPrimeToFVarUserNames (ys : Array Expr) (lctx : LocalContext) : LocalContext := Id.run do let mut lctx := lctx for y in ys do let decl := lctx.getFVar! y lctx := lctx.setUserName decl.fvarId (decl.userName.appendAfter "'") return lctx private def setBinderInfosD (ys : Array Expr) (lctx : LocalContext) : LocalContext := Id.run do let mut lctx := lctx for y in ys do let decl := lctx.getFVar! y lctx := lctx.setBinderInfo decl.fvarId BinderInfo.default return lctx partial def mkHCongrWithArity (f : Expr) (numArgs : Nat) : MetaM CongrTheorem := do let fType ← inferType f forallBoundedTelescope fType numArgs fun xs _ => forallBoundedTelescope fType numArgs fun ys _ => do if xs.size != numArgs then throwError "failed to generate hcongr theorem, insufficient number of arguments" else let lctx := addPrimeToFVarUserNames ys (← getLCtx) |> setBinderInfosD ys |> setBinderInfosD xs withLCtx lctx (← getLocalInstances) do withNewEqs xs ys fun eqs argKinds => do let mut hs := #[] for x in xs, y in ys, eq in eqs do hs := hs.push x |>.push y |>.push eq let lhs := mkAppN f xs let rhs := mkAppN f ys let congrType ← mkForallFVars hs (← mkHEq lhs rhs) return { type := congrType proof := (← mkProof congrType) argKinds } where withNewEqs {α} (xs ys : Array Expr) (k : Array Expr → Array CongrArgKind → MetaM α) : MetaM α := let rec loop (i : Nat) (eqs : Array Expr) (kinds : Array CongrArgKind) := do if i < xs.size then let x := xs[i]! let y := ys[i]! let xType := (← inferType x).consumeTypeAnnotations let yType := (← inferType y).consumeTypeAnnotations if xType == yType then withLocalDeclD ((`e).appendIndexAfter (i+1)) (← mkEq x y) fun h => loop (i+1) (eqs.push h) (kinds.push CongrArgKind.eq) else withLocalDeclD ((`e).appendIndexAfter (i+1)) (← mkHEq x y) fun h => loop (i+1) (eqs.push h) (kinds.push CongrArgKind.heq) else k eqs kinds loop 0 #[] #[] mkProof (type : Expr) : MetaM Expr := do if let some (_, lhs, _) := type.eq? then mkEqRefl lhs else if let some (_, lhs, _, _) := type.heq? then mkHEqRefl lhs else forallBoundedTelescope type (some 1) fun a type => let a := a[0]! forallBoundedTelescope type (some 1) fun b motive => let b := b[0]! let type := type.bindingBody!.instantiate1 a withLocalDeclD motive.bindingName! motive.bindingDomain! fun eqPr => do let type := type.bindingBody! let motive := motive.bindingBody! let minor ← mkProof type let mut major := eqPr if (← whnf (← inferType eqPr)).isHEq then major ← mkEqOfHEq major let motive ← mkLambdaFVars #[b] motive mkLambdaFVars #[a, b, eqPr] (← mkEqNDRec motive minor major) def mkHCongr (f : Expr) : MetaM CongrTheorem := do mkHCongrWithArity f (← getFunInfo f).getArity /-- Ensure that all dependencies for `congr_arg_kind::Eq` are `congr_arg_kind::Fixed`. -/ private def fixKindsForDependencies (info : FunInfo) (kinds : Array CongrArgKind) : Array CongrArgKind := Id.run do let mut kinds := kinds for i in [:info.paramInfo.size] do for j in [i+1:info.paramInfo.size] do if info.paramInfo[j]!.backDeps.contains i then if kinds[j]! matches CongrArgKind.eq || kinds[j]! matches CongrArgKind.fixed then -- We must fix `i` because there is a `j` that depends on `i` and `j` is not cast-fixed. kinds := kinds.set! i CongrArgKind.fixed break return kinds /-- (Try to) cast expression `e` to the given type using the equations `eqs`. `deps` contains the indices of the relevant equalities. Remark: deps is sorted. -/ private partial def mkCast (e : Expr) (type : Expr) (deps : Array Nat) (eqs : Array (Option Expr)) : MetaM Expr := do let rec go (i : Nat) (type : Expr) : MetaM Expr := do if i < deps.size then match eqs[deps[i]!]! with | none => go (i+1) type | some major => let some (_, lhs, rhs) := (← inferType major).eq? | unreachable! if (← dependsOn type major.fvarId!) then let motive ← mkLambdaFVars #[rhs, major] type let typeNew := type.replaceFVar rhs lhs |>.replaceFVar major (← mkEqRefl lhs) let minor ← go (i+1) typeNew mkEqRec motive minor major else let motive ← mkLambdaFVars #[rhs] type let typeNew := type.replaceFVar rhs lhs let minor ← go (i+1) typeNew mkEqNDRec motive minor major else return e go 0 type private def hasCastLike (kinds : Array CongrArgKind) : Bool := kinds.any fun kind => kind matches CongrArgKind.cast || kind matches CongrArgKind.subsingletonInst private def withNext (type : Expr) (k : Expr → Expr → MetaM α) : MetaM α := do forallBoundedTelescope type (some 1) fun xs type => k xs[0]! type /-- Test whether we should use `subsingletonInst` kind for instances which depend on `eq`. (Otherwise `fixKindsForDependencies`will downgrade them to Fixed -/ private def shouldUseSubsingletonInst (info : FunInfo) (kinds : Array CongrArgKind) (i : Nat) : Bool := Id.run do if info.paramInfo[i]!.isDecInst then for j in info.paramInfo[i]!.backDeps do if kinds[j]! matches CongrArgKind.eq then return true return false /-- If `f` is a class constructor, return a bitmask `m` s.t. `m[i]` is true if the `i`-th parameter corresponds to a subobject field. We use this function to implement the special support for class constructors at `getCongrSimpKinds`. See issue #1808 -/ private def getClassSubobjectMask? (f : Expr) : MetaM (Option (Array Bool)) := do let .const declName _ := f | return none let .ctorInfo val ← getConstInfo declName | return none unless isClass (← getEnv) val.induct do return none forallTelescopeReducing val.type fun xs _ => do let env ← getEnv let mut mask := #[] for i in [:xs.size] do if i < val.numParams then mask := mask.push false else let localDecl ← xs[i]!.fvarId!.getDecl mask := mask.push (isSubobjectField? env val.induct localDecl.userName).isSome return some mask /-- Compute `CongrArgKind`s for a simp congruence theorem. -/ def getCongrSimpKinds (f : Expr) (info : FunInfo) : MetaM (Array CongrArgKind) := do /- The default `CongrArgKind` is `eq`, which allows `simp` to rewrite this argument. However, if there are references from `i` to `j`, we cannot rewrite both `i` and `j`. So we must change the `CongrArgKind` at either `i` or `j`. In principle, if there is a dependency with `i` appearing after `j`, then we set `j` to `fixed` (or `cast`). But there is an optimization: if `i` is a subsingleton, we can fix it instead of `j`, since all subsingletons are equal anyway. The fixing happens in two loops: one for the special cases, and one for the general case. This method has special support for class constructors. For this kind of function, we treat subobject fields as regular parameters instead of instance implicit ones. We added this feature because of issue #1808 -/ let mut result := #[] let mask? ← getClassSubobjectMask? f for i in [:info.paramInfo.size] do if info.resultDeps.contains i then result := result.push .fixed else if info.paramInfo[i]!.isProp then result := result.push .cast else if info.paramInfo[i]!.isInstImplicit then if let some mask := mask? then if h : i < mask.size then if mask[i] then -- Parameter is a subobect field of a class constructor. See comment above. result := result.push .eq continue if shouldUseSubsingletonInst info result i then result := result.push .subsingletonInst else result := result.push .fixed else result := result.push .eq return fixKindsForDependencies info result /-- Create a congruence theorem that is useful for the simplifier and `congr` tactic. -/ partial def mkCongrSimpCore? (f : Expr) (info : FunInfo) (kinds : Array CongrArgKind) (subsingletonInstImplicitRhs : Bool := true) : MetaM (Option CongrTheorem) := do if let some result ← mk? f info kinds then return some result else if hasCastLike kinds then -- Simplify kinds and try again let kinds := kinds.map fun kind => if kind matches CongrArgKind.cast || kind matches CongrArgKind.subsingletonInst then CongrArgKind.fixed else kind mk? f info kinds else return none where /-- Create a congruence theorem that is useful for the simplifier. In this kind of theorem, if the i-th argument is a `cast` argument, then the theorem contains an input `a_i` representing the i-th argument in the left-hand-side, and it appears with a cast (e.g., `Eq.drec ... a_i ...`) in the right-hand-side. The idea is that the right-hand-side of this theorem "tells" the simplifier how the resulting term looks like. -/ mk? (f : Expr) (info : FunInfo) (kinds : Array CongrArgKind) : MetaM (Option CongrTheorem) := do try let fType ← inferType f forallBoundedTelescope fType kinds.size fun lhss _ => do if lhss.size != kinds.size then return none let rec go (i : Nat) (rhss : Array Expr) (eqs : Array (Option Expr)) (hyps : Array Expr) : MetaM CongrTheorem := do if i == kinds.size then let lhs := mkAppN f lhss let rhs := mkAppN f rhss let type ← mkForallFVars hyps (← mkEq lhs rhs) let proof ← mkProof type kinds return { type, proof, argKinds := kinds } else let hyps := hyps.push lhss[i]! match kinds[i]! with | .heq | .fixedNoParam => unreachable! | .eq => let localDecl ← lhss[i]!.fvarId!.getDecl withLocalDecl localDecl.userName localDecl.binderInfo localDecl.type fun rhs => do withLocalDeclD (localDecl.userName.appendBefore "e_") (← mkEq lhss[i]! rhs) fun eq => do go (i+1) (rhss.push rhs) (eqs.push eq) (hyps.push rhs |>.push eq) | .fixed => go (i+1) (rhss.push lhss[i]!) (eqs.push none) hyps | .cast => let rhsType := (← inferType lhss[i]!).replaceFVars (lhss[:rhss.size]) rhss let rhs ← mkCast lhss[i]! rhsType info.paramInfo[i]!.backDeps eqs go (i+1) (rhss.push rhs) (eqs.push none) hyps | .subsingletonInst => -- The `lhs` does not need to instance implicit since it can be inferred from the LHS withNewBinderInfos #[(lhss[i]!.fvarId!, .implicit)] do let rhsType := (← inferType lhss[i]!).replaceFVars (lhss[:rhss.size]) rhss let rhsBi := if subsingletonInstImplicitRhs then .instImplicit else .implicit withLocalDecl (← lhss[i]!.fvarId!.getDecl).userName rhsBi rhsType fun rhs => go (i+1) (rhss.push rhs) (eqs.push none) (hyps.push rhs) return some (← go 0 #[] #[] #[]) catch _ => return none mkProof (type : Expr) (kinds : Array CongrArgKind) : MetaM Expr := do let rec go (i : Nat) (type : Expr) : MetaM Expr := do if i == kinds.size then let some (_, lhs, _) := type.eq? | unreachable! mkEqRefl lhs else withNext type fun lhs type => do match kinds[i]! with | .heq | .fixedNoParam => unreachable! | .fixed => mkLambdaFVars #[lhs] (← go (i+1) type) | .cast => mkLambdaFVars #[lhs] (← go (i+1) type) | .eq => let typeSub := type.bindingBody!.bindingBody!.instantiate #[(← mkEqRefl lhs), lhs] withNext type fun rhs type => withNext type fun heq type => do let motive ← mkLambdaFVars #[rhs, heq] type let proofSub ← go (i+1) typeSub mkLambdaFVars #[lhs, rhs, heq] (← mkEqRec motive proofSub heq) | .subsingletonInst => let typeSub := type.bindingBody!.instantiate #[lhs] withNext type fun rhs type => do let motive ← mkLambdaFVars #[rhs] type let proofSub ← go (i+1) typeSub let heq ← mkAppM ``Subsingleton.elim #[lhs, rhs] mkLambdaFVars #[lhs, rhs] (← mkEqNDRec motive proofSub heq) go 0 type /-- Create a congruence theorem for `f`. The theorem is used in the simplifier. If `subsingletonInstImplicitRhs = true`, the the `rhs` corresponding to `[Decidable p]` parameters is marked as instance implicit. It forces the simplifier to compute the new instance when applying the congruence theorem. For the `congr` tactic we set it to `false`. -/ def mkCongrSimp? (f : Expr) (subsingletonInstImplicitRhs : Bool := true) : MetaM (Option CongrTheorem) := do let f := (← instantiateMVars f).cleanupAnnotations let info ← getFunInfo f mkCongrSimpCore? f info (← getCongrSimpKinds f info) (subsingletonInstImplicitRhs := subsingletonInstImplicitRhs) end Lean.Meta
If $g$ is $o(f)$, then $L(f - g) = L(f)$.
/* Copyright (C) 2021 Atsushi Togo */ /* All rights reserved. */ /* This file is part of phonopy. */ /* 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 phonopy project 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 HOLDER 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. */ #ifndef __phono3py_H__ #define __phono3py_H__ #ifdef MKL_LAPACKE #include <mkl.h> #else #include <lapacke.h> #endif #include "phonoc_array.h" long ph3py_get_interaction(Darray *fc3_normal_squared, const char *g_zero, const Darray *frequencies, const lapack_complex_double *eigenvectors, const long (*triplets)[3], const long num_triplets, const long (*bz_grid_addresses)[3], const long D_diag[3], const long Q[3][3], const double *fc3, const long is_compact_fc3, const double (*svecs)[3], const long multi_dims[2], const long (*multi)[2], const double *masses, const long *p2s_map, const long *s2p_map, const long *band_indices, const long symmetrize_fc3_q, const double cutoff_frequency); long ph3py_get_pp_collision(double *imag_self_energy, const long relative_grid_address[24][4][3], /* thm */ const double *frequencies, const lapack_complex_double *eigenvectors, const long (*triplets)[3], const long num_triplets, const long *triplet_weights, const long (*bz_grid_addresses)[3], /* thm */ const long *bz_map, /* thm */ const long bz_grid_type, const long D_diag[3], const long Q[3][3], const double *fc3, const long is_compact_fc3, const double (*svecs)[3], const long multi_dims[2], const long (*multi)[2], const double *masses, const long *p2s_map, const long *s2p_map, const Larray *band_indices, const Darray *temperatures, const long is_NU, const long symmetrize_fc3_q, const double cutoff_frequency); long ph3py_get_pp_collision_with_sigma( double *imag_self_energy, const double sigma, const double sigma_cutoff, const double *frequencies, const lapack_complex_double *eigenvectors, const long (*triplets)[3], const long num_triplets, const long *triplet_weights, const long (*bz_grid_addresses)[3], const long D_diag[3], const long Q[3][3], const double *fc3, const long is_compact_fc3, const double (*svecs)[3], const long multi_dims[2], const long (*multi)[2], const double *masses, const long *p2s_map, const long *s2p_map, const Larray *band_indices, const Darray *temperatures, const long is_NU, const long symmetrize_fc3_q, const double cutoff_frequency); void ph3py_get_imag_self_energy_at_bands_with_g( double *imag_self_energy, const Darray *fc3_normal_squared, const double *frequencies, const long (*triplets)[3], const long *triplet_weights, const double *g, const char *g_zero, const double temperature, const double cutoff_frequency, const long num_frequency_points, const long frequency_point_index); void ph3py_get_detailed_imag_self_energy_at_bands_with_g( double *detailed_imag_self_energy, double *imag_self_energy_N, double *imag_self_energy_U, const Darray *fc3_normal_squared, const double *frequencies, const long (*triplets)[3], const long *triplet_weights, const long (*bz_grid_addresses)[3], const double *g, const char *g_zero, const double temperature, const double cutoff_frequency); void ph3py_get_real_self_energy_at_bands(double *real_self_energy, const Darray *fc3_normal_squared, const long *band_indices, const double *frequencies, const long (*triplets)[3], const long *triplet_weights, const double epsilon, const double temperature, const double unit_conversion_factor, const double cutoff_frequency); void ph3py_get_real_self_energy_at_frequency_point( double *real_self_energy, const double frequency_point, const Darray *fc3_normal_squared, const long *band_indices, const double *frequencies, const long (*triplets)[3], const long *triplet_weights, const double epsilon, const double temperature, const double unit_conversion_factor, const double cutoff_frequency); void ph3py_get_collision_matrix(double *collision_matrix, const Darray *fc3_normal_squared, const double *frequencies, const long (*triplets)[3], const long *triplets_map, const long *map_q, const long *rotated_grid_points, const double *rotations_cartesian, const double *g, const long num_ir_gp, const long num_gp, const long num_rot, const double temperature, const double unit_conversion_factor, const double cutoff_frequency); void ph3py_get_reducible_collision_matrix(double *collision_matrix, const Darray *fc3_normal_squared, const double *frequencies, const long (*triplets)[3], const long *triplets_map, const long *map_q, const double *g, const long num_gp, const double temperature, const double unit_conversion_factor, const double cutoff_frequency); void ph3py_get_isotope_scattering_strength( double *gamma, const long grid_point, const double *mass_variances, const double *frequencies, const lapack_complex_double *eigenvectors, const long num_grid_points, const long *band_indices, const long num_band, const long num_band0, const double sigma, const double cutoff_frequency); void ph3py_get_thm_isotope_scattering_strength( double *gamma, const long grid_point, const long *ir_grid_points, const long *weights, const double *mass_variances, const double *frequencies, const lapack_complex_double *eigenvectors, const long num_ir_grid_points, const long *band_indices, const long num_band, const long num_band0, const double *integration_weights, const double cutoff_frequency); void ph3py_distribute_fc3(double *fc3, const long target, const long source, const long *atom_mapping, const long num_atom, const double *rot_cart); void ph3py_rotate_delta_fc2(double (*fc3)[3][3][3], const double (*delta_fc2s)[3][3], const double *inv_U, const double (*site_sym_cart)[3][3], const long *rot_map_syms, const long num_atom, const long num_site_sym, const long num_disp); void ph3py_get_permutation_symmetry_fc3(double *fc3, const long num_atom); void ph3py_get_permutation_symmetry_compact_fc3(double *fc3, const long p2s[], const long s2pp[], const long nsym_list[], const long perms[], const long n_satom, const long n_patom); void ph3py_transpose_compact_fc3(double *fc3, const long p2s[], const long s2pp[], const long nsym_list[], const long perms[], const long n_satom, const long n_patom, const long t_type); long ph3py_get_triplets_reciprocal_mesh_at_q(long *map_triplets, long *map_q, const long grid_point, const long mesh[3], const long is_time_reversal, const long num_rot, const long (*rec_rotations)[3][3], const long swappable); long ph3py_get_BZ_triplets_at_q(long (*triplets)[3], const long grid_point, const long (*bz_grid_addresses)[3], const long *bz_map, const long *map_triplets, const long num_map_triplets, const long D_diag[3], const long Q[3][3], const long bz_grid_type); long ph3py_get_integration_weight(double *iw, char *iw_zero, const double *frequency_points, const long num_band0, const long relative_grid_address[24][4][3], const long mesh[3], const long (*triplets)[3], const long num_triplets, const long (*bz_grid_addresses)[3], const long *bz_map, const long bz_grid_type, const double *frequencies1, const long num_band1, const double *frequencies2, const long num_band2, const long tp_type, const long openmp_per_triplets, const long openmp_per_bands); void ph3py_get_integration_weight_with_sigma(double *iw, char *iw_zero, const double sigma, const double sigma_cutoff, const double *frequency_points, const long num_band0, const long (*triplets)[3], const long num_triplets, const double *frequencies, const long num_band, const long tp_type); long ph3py_get_grid_index_from_address(const long address[3], const long mesh[3]); void ph3py_get_gr_grid_addresses(long gr_grid_addresses[][3], const long D_diag[3]); long ph3py_get_reciprocal_rotations(long rec_rotations[48][3][3], const long (*rotations)[3][3], const long num_rot, const long is_time_reversal); long ph3py_transform_rotations(long (*transformed_rots)[3][3], const long (*rotations)[3][3], const long num_rot, const long D_diag[3], const long Q[3][3]); long ph3py_get_snf3x3(long D_diag[3], long P[3][3], long Q[3][3], const long A[3][3]); long ph3py_transform_rotations(long (*transformed_rots)[3][3], const long (*rotations)[3][3], const long num_rot, const long D_diag[3], const long Q[3][3]); long ph3py_get_ir_grid_map(long *ir_grid_map, const long D_diag[3], const long PS[3], const long (*grg_rotations)[3][3], const long num_rot); long ph3py_get_bz_grid_addresses(long (*bz_grid_addresses)[3], long *bz_map, long *bzg2grg, const long D_diag[3], const long Q[3][3], const long PS[3], const double rec_lattice[3][3], const long type); long ph3py_rotate_bz_grid_index(const long bz_grid_index, const long rotation[3][3], const long (*bz_grid_addresses)[3], const long *bz_map, const long D_diag[3], const long PS[3], const long bz_grid_type); void ph3py_symmetrize_collision_matrix(double *collision_matrix, const long num_column, const long num_temp, const long num_sigma); void ph3py_expand_collision_matrix(double *collision_matrix, const long *rot_grid_points, const long *ir_grid_points, const long num_ir_gp, const long num_grid_points, const long num_rot, const long num_sigma, const long num_temp, const long num_band); long ph3py_get_neighboring_gird_points(long *relative_grid_points, const long *grid_points, const long (*relative_grid_address)[3], const long mesh[3], const long (*bz_grid_addresses)[3], const long *bz_map, const long bz_grid_type, const long num_grid_points, const long num_relative_grid_address); long ph3py_get_thm_integration_weights_at_grid_points( double *iw, const double *frequency_points, const long num_band0, const long num_band, const long num_gp, const long (*relative_grid_address)[4][3], const long D_diag[3], const long *grid_points, const long (*bz_grid_addresses)[3], const long *bz_map, const long bz_grid_type, const double *frequencies, const long *gp2irgp_map, const char function); #endif
// graph-tool -- a general graph modification and manipulation thingy // // Copyright (C) 2006-2018 Tiago de Paula Peixoto <[email protected]> // // This program is free software; you can redistribute it and/or // modify it under the terms of the GNU General Public License // as published by the Free Software Foundation; either version 3 // of the License, or (at your option) any later version. // // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // // You should have received a copy of the GNU General Public License // along with this program. If not, see <http://www.gnu.org/licenses/>. #include <boost/python.hpp> #include "graph.hh" using namespace std; using namespace boost; using namespace graph_tool; void adjacency(GraphInterface& g, boost::any index, boost::any weight, python::object odata, python::object oi, python::object oj); void laplacian(GraphInterface& g, boost::any index, boost::any weight, string sdeg, python::object odata, python::object oi, python::object oj); void norm_laplacian(GraphInterface& g, boost::any index, boost::any weight, string sdeg, python::object odata, python::object oi, python::object oj); void incidence(GraphInterface& g, boost::any vindex, boost::any eindex, python::object odata, python::object oi, python::object oj); void transition(GraphInterface& g, boost::any index, boost::any weight, python::object odata, python::object oi, python::object oj); BOOST_PYTHON_MODULE(libgraph_tool_spectral) { using namespace boost::python; docstring_options dopt(true, false); def("adjacency", &adjacency); def("laplacian", &laplacian); def("norm_laplacian", &norm_laplacian); def("incidence", &incidence); def("transition", &transition); }
# Copyright 2016 The TensorFlow Authors All Rights Reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # ============================================================================== """Tests for DSN losses.""" from functools import partial import numpy as np import tensorflow as tf import losses import utils def MaximumMeanDiscrepancySlow(x, y, sigmas): num_samples = x.get_shape().as_list()[0] def AverageGaussianKernel(x, y, sigmas): result = 0 for sigma in sigmas: dist = tf.reduce_sum(tf.square(x - y)) result += tf.exp((-1.0 / (2.0 * sigma)) * dist) return result / num_samples ** 2 total = 0 for i in range(num_samples): for j in range(num_samples): total += AverageGaussianKernel(x[i, :], x[j, :], sigmas) total += AverageGaussianKernel(y[i, :], y[j, :], sigmas) total += -2 * AverageGaussianKernel(x[i, :], y[j, :], sigmas) return total class LogQuaternionLossTest(tf.test.TestCase): def test_log_quaternion_loss_batch(self): with self.test_session(): predictions = tf.random_uniform((10, 4), seed=1) predictions = tf.nn.l2_normalize(predictions, 1) labels = tf.random_uniform((10, 4), seed=1) labels = tf.nn.l2_normalize(labels, 1) params = {'batch_size': 10, 'use_logging': False} x = losses.log_quaternion_loss_batch(predictions, labels, params) self.assertTrue(((10,) == tf.shape(x).eval()).all()) class MaximumMeanDiscrepancyTest(tf.test.TestCase): def test_mmd_name(self): with self.test_session(): x = tf.random_uniform((2, 3), seed=1) kernel = partial(utils.gaussian_kernel_matrix, sigmas=tf.constant([1.])) loss = losses.maximum_mean_discrepancy(x, x, kernel) self.assertEquals(loss.op.name, 'MaximumMeanDiscrepancy/value') def test_mmd_is_zero_when_inputs_are_same(self): with self.test_session(): x = tf.random_uniform((2, 3), seed=1) kernel = partial(utils.gaussian_kernel_matrix, sigmas=tf.constant([1.])) self.assertEquals(0, losses.maximum_mean_discrepancy(x, x, kernel).eval()) def test_fast_mmd_is_similar_to_slow_mmd(self): with self.test_session(): x = tf.constant(np.random.normal(size=(2, 3)), tf.float32) y = tf.constant(np.random.rand(2, 3), tf.float32) cost_old = MaximumMeanDiscrepancySlow(x, y, [1.]).eval() kernel = partial(utils.gaussian_kernel_matrix, sigmas=tf.constant([1.])) cost_new = losses.maximum_mean_discrepancy(x, y, kernel).eval() self.assertAlmostEqual(cost_old, cost_new, delta=1e-5) def test_multiple_sigmas(self): with self.test_session(): x = tf.constant(np.random.normal(size=(2, 3)), tf.float32) y = tf.constant(np.random.rand(2, 3), tf.float32) sigmas = tf.constant([2., 5., 10, 20, 30]) kernel = partial(utils.gaussian_kernel_matrix, sigmas=sigmas) cost_old = MaximumMeanDiscrepancySlow(x, y, [2., 5., 10, 20, 30]).eval() cost_new = losses.maximum_mean_discrepancy(x, y, kernel=kernel).eval() self.assertAlmostEqual(cost_old, cost_new, delta=1e-5) def test_mmd_is_zero_when_distributions_are_same(self): with self.test_session(): x = tf.random_uniform((1000, 10), seed=1) y = tf.random_uniform((1000, 10), seed=3) kernel = partial(utils.gaussian_kernel_matrix, sigmas=tf.constant([100.])) loss = losses.maximum_mean_discrepancy(x, y, kernel=kernel).eval() self.assertAlmostEqual(0, loss, delta=1e-4) if __name__ == '__main__': tf.test.main()
(* author: R. Thiemann *) section \<open>The Sunflower Lemma\<close> text \<open>We formalize the proof of the sunflower lemma of Erdős and Rado~\cite{erdos_rado}, as it is presented in the textbook~\cite[Chapter~6]{book}. We further integrate Exercise 6.2 from the textbook, which provides a lower bound on the existence of sunflowers.\<close> theory Erdos_Rado_Sunflower imports Sunflower begin text \<open>When removing an element from all subsets, then one can afterwards add these elements to a sunflower and get a new sunflower.\<close> lemma sunflower_remove_element_lift: assumes S: "S \<subseteq> { A - {a} | A . A \<in> F \<and> a \<in> A}" and sf: "sunflower S" shows "\<exists> Sa. sunflower Sa \<and> Sa \<subseteq> F \<and> card Sa = card S \<and> Sa = insert a ` S" proof (intro exI[of _ "insert a ` S"] conjI refl) let ?Sa = "insert a ` S" { fix B assume "B \<in> ?Sa" then obtain C where C: "C \<in> S" and B: "B = insert a C" by auto from C S obtain T where "T \<in> F" "a \<in> T" "C = T - {a}" by auto with B have "B = T" by auto with \<open>T \<in> F\<close> have "B \<in> F" by auto } thus SaF: "?Sa \<subseteq> F" by auto have inj: "inj_on (insert a) S" using S by (intro inj_on_inverseI[of _ "\<lambda> B. B - {a}"], auto) thus "card ?Sa = card S" by (rule card_image) show "sunflower ?Sa" unfolding sunflower_def proof (intro allI, intro impI) fix x assume "\<exists>C D. C \<in> ?Sa \<and> D \<in> ?Sa \<and> C \<noteq> D \<and> x \<in> C \<and> x \<in> D" then obtain C D where *: "C \<in> ?Sa" "D \<in> ?Sa" "C \<noteq> D" "x \<in> C" "x \<in> D" by auto from *(1-2) obtain C' D' where **: "C' \<in> S" "D' \<in> S" "C = insert a C'" "D = insert a D'" by auto with \<open>C \<noteq> D\<close> inj have CD': "C' \<noteq> D'" by auto show "\<forall>E. E \<in> ?Sa \<longrightarrow> x \<in> E" proof (cases "x = a") case False with * ** have "x \<in> C'" "x \<in> D'" by auto with ** CD' have "\<exists>C D. C \<in> S \<and> D \<in> S \<and> C \<noteq> D \<and> x \<in> C \<and> x \<in> D" by auto from sf[unfolded sunflower_def, rule_format, OF this] show ?thesis by auto qed auto qed qed text \<open>The sunflower-lemma of Erdős and Rado: if a set has a certain size and all elements have the same cardinality, then a sunflower exists.\<close> lemma Erdos_Rado_sunflower_same_card: assumes "\<forall> A \<in> F. finite A \<and> card A = k" and "card F > (r - 1)^k * fact k" shows "\<exists> S. S \<subseteq> F \<and> sunflower S \<and> card S = r \<and> {} \<notin> S" using assms proof (induct k arbitrary: F) case 0 hence "F = {{}} \<or> F = {}" "card F \<ge> 2" by auto hence False by auto thus ?case by simp next case (Suc k F) define pd_sub :: "'a set set \<Rightarrow> nat \<Rightarrow> bool" where "pd_sub = (\<lambda> G t. G \<subseteq> F \<and> card G = t \<and> pairwise disjnt G \<and> {} \<notin> G)" show ?case proof (cases "\<exists> t G. pd_sub G t \<and> t \<ge> r") case True then obtain t G where pd_sub: "pd_sub G t" and t: "t \<ge> r" by auto from pd_sub[unfolded pd_sub_def] pairwise_disjnt_imp_sunflower have *: "G \<subseteq> F" "card G = t" "sunflower G" "{} \<notin> G" by auto from t \<open>card G = t\<close> obtain H where "H \<subseteq> G" "card H = r" by (metis obtain_subset_with_card_n) with sunflower_subset[OF \<open>H \<subseteq> G\<close>] * show ?thesis by blast next case False define P where "P = (\<lambda> t. \<exists> G. pd_sub G t)" have ex: "\<exists> t. P t" unfolding P_def by (intro exI[of _ 0] exI[of _ "{}"], auto simp: pd_sub_def) have large': "\<And> t. P t \<Longrightarrow> t < r" using False unfolding P_def by auto hence large: "\<And> t. P t \<Longrightarrow> t \<le> r" by fastforce define t where "t = (GREATEST t. P t)" from GreatestI_ex_nat[OF ex large, folded t_def] have Pt: "P t" . from Greatest_le_nat[of P, OF _ large] have greatest: "\<And> s. P s \<Longrightarrow> s \<le> t" unfolding t_def by auto from large'[OF Pt] have tr: "t \<le> r - 1" by simp from Pt[unfolded P_def pd_sub_def] obtain G where cardG: "card G = t" and disj: "pairwise disjnt G" and GF: "G \<subseteq> F" by blast define A where "A = (\<Union> G)" from Suc(3) have "card F > 0" by simp hence "finite F" by (rule card_ge_0_finite) from GF \<open>finite F\<close> have finG: "finite G" by (rule finite_subset) have "card (\<Union> G) \<le> sum card G" by (rule card_Union_le_sum_card, insert Suc(2) GF, auto) also have "\<dots> \<le> of_nat (card G) * Suc k" by (rule sum_bounded_above, insert GF Suc(2), auto) also have "\<dots> \<le> (r - 1) * Suc k" using tr[folded cardG] by (metis id_apply mult_le_mono1 of_nat_eq_id) finally have cardA: "card A \<le> (r - 1) * Suc k" unfolding A_def . { fix B assume *: "B \<in> F" with Suc(2) have nE: "B \<noteq> {}" by auto from Suc(2) have eF: "{} \<notin> F" by auto have "B \<inter> A \<noteq> {}" proof assume dis: "B \<inter> A = {}" hence disj: "pairwise disjnt ({B} \<union> G)" using disj unfolding A_def by (smt (verit, ccfv_SIG) Int_commute Un_iff Union_disjoint disjnt_def pairwise_def singleton_iff) from nE dis have "B \<notin> G" unfolding A_def by auto with finG have c: "card ({B} \<union> G) = Suc t" by (simp add: cardG) have "P (Suc t)" unfolding P_def pd_sub_def by (intro exI[of _ "{B} \<union> G"], insert eF disj c * GF, auto) with greatest show False by force qed } note overlap = this have "F \<noteq> {}" using Suc(2-) by auto with overlap have Ane: "A \<noteq> {}" unfolding A_def by auto have "finite A" unfolding A_def using finG Suc(2-) GF by auto let ?g = "\<lambda> B x. x \<in> B \<inter> A" define f where "f = (\<lambda> B. SOME x. ?g B x)" have "f \<in> F \<rightarrow> A" proof fix B assume "B \<in> F" from overlap[OF this] have "\<exists> x. ?g B x" unfolding A_def by auto from someI_ex[OF this] show "f B \<in> A" unfolding f_def by auto qed from pigeonhole_card[OF this \<open>finite F\<close> \<open>finite A\<close> Ane] obtain a where a: "a \<in> A" and le: "card F \<le> card (f -` {a} \<inter> F) * card A" by auto { fix S assume "S \<in> F" "f S \<in> {a}" with someI_ex[of "?g S"] a overlap[OF this(1)] have "a \<in> S" unfolding f_def by auto } note FaS = this let ?F = "{S - {a} | S . S \<in> F \<and> f S \<in> {a}}" from cardA have "((r - 1) ^ k * fact k) * card A \<le> ((r - 1) ^ k * fact k) * ((r - 1) * Suc k)" by simp also have "\<dots> = (r - 1) ^ (Suc k) * fact (Suc k)" by (metis (no_types, lifting) fact_Suc mult.assoc mult.commute of_nat_id power_Suc2) also have "\<dots> < card (f -` {a} \<inter> F) * card A" using Suc(3) le by auto also have "f -` {a} \<inter> F = {S \<in> F. f S \<in> {a}}" by auto also have "card \<dots> = card ((\<lambda> S. S - {a}) ` {S \<in> F. f S \<in> {a}})" by (subst card_image; intro inj_onI refl, insert FaS) auto also have "(\<lambda> S. S - {a}) ` {S \<in> F. f S \<in> {a}} = ?F" by auto finally have lt: "(r - 1) ^ k * fact k < card ?F" by simp have "\<forall> A \<in> ?F. finite A \<and> card A = k" using Suc(2) FaS by auto from Suc(1)[OF this lt] obtain S where "sunflower S" "card S = r" "S \<subseteq> ?F" by auto from \<open>S \<subseteq> ?F\<close> FaS have "S \<subseteq> {A - {a} |A. A \<in> F \<and> a \<in> A}" by auto from sunflower_remove_element_lift[OF this \<open>sunflower S\<close>] \<open>card S = r\<close> show ?thesis by auto qed qed text \<open>Using @{thm [source] sunflower_card_subset_lift} we can easily replace the condition that the cardinality is exactly @{term k} by the requirement that the cardinality is at most @{term k}. However, then @{term "{} \<notin> S"} cannot be ensured. Consider @{term "(r :: nat) = 1 \<and> (k :: nat) > 0 \<and> F = {{}}"}.\<close> lemma Erdos_Rado_sunflower: assumes "\<forall> A \<in> F. finite A \<and> card A \<le> k" and "card F > (r - 1)^k * fact k" shows "\<exists> S. S \<subseteq> F \<and> sunflower S \<and> card S = r" by (rule sunflower_card_subset_lift[OF _ assms], metis Erdos_Rado_sunflower_same_card) text \<open>We further provide a lower bound on the existence of sunflowers, i.e., Exercise 6.2 of the textbook~\cite{book}. To be more precise, we prove that there is a set of sets of cardinality @{term \<open>(r - 1 :: nat)^k\<close>}, where each element is a set of cardinality @{term k}, such that there is no subset which is a sunflower with cardinality of at least @{term r}.\<close> lemma sunflower_lower_bound: assumes inf: "infinite (UNIV :: 'a set)" and r: "r \<noteq> 0" and rk: "r = 1 \<Longrightarrow> k \<noteq> 0" shows "\<exists> F. card F = (r - 1)^k \<and> finite F \<and> (\<forall> A \<in> F. finite (A :: 'a set) \<and> card A = k) \<and> (\<nexists> S. S \<subseteq> F \<and> sunflower S \<and> card S \<ge> r)" proof (cases "r = 1") case False with r have r: "r > 1" by auto show ?thesis proof (induct k) case 0 have id: "S \<subseteq> {{}} \<longleftrightarrow> (S = {} \<or> S = {{}})" for S :: "'a set set" by auto show ?case using r by (intro exI[of _ "{{}}"], auto simp: id) next case (Suc k) then obtain F where cardF: "card F = (r - 1) ^ k" and fin: "finite F" and AF: "\<And> A. (A :: 'a set) \<in> F \<Longrightarrow> finite A \<and> card A = k" and sf: "\<not> (\<exists>S\<subseteq>F. sunflower S \<and> r \<le> card S)" by metis text \<open>main idea: get @{term "k-1 :: nat"} fresh elements and add one of these to all elements of F\<close> have "finite (\<Union> F)" using fin AF by simp hence "infinite (UNIV - \<Union> F)" using inf by simp from infinite_arbitrarily_large[OF this, of "r - 1"] obtain New where New: "finite New" "card New = r - 1" "New \<inter> \<Union> F = {}" by auto define G where "G = (\<lambda> (A, a). insert a A) ` (F \<times> New)" show ?case proof (intro exI[of _ G] conjI) show "finite G" using New fin unfolding G_def by simp have "card G = card (F \<times> New)" unfolding G_def proof ((subst card_image; (intro refl)?), intro inj_onI, clarsimp, goal_cases) case (1 A a B b) hence ab: "a = b" using New by auto from 1(1) have "insert a A - {a} = insert b B - {a}" by simp also have "insert a A - {a} = A" using New 1 by auto also have "insert b B - {a} = B" using New 1 ab[symmetric] by auto finally show ?case using ab by auto qed also have "\<dots> = card F * card New" using New fin by auto finally show "card G = (r - 1) ^ Suc k" unfolding cardF New by simp { fix B assume "B \<in> G" then obtain a A where G: "a \<in> New" "A \<in> F" "B = insert a A" unfolding G_def by auto with AF[of A] New have "finite B" "card B = Suc k" by (auto simp: card_insert_if) } thus "\<forall>A\<in>G. finite A \<and> card A = Suc k" by auto show "\<not> (\<exists>S\<subseteq>G. sunflower S \<and> r \<le> card S)" proof (intro notI, elim exE conjE) fix S assume *: "S \<subseteq> G" "sunflower S" "r \<le> card S" define g where "g B = (SOME a. a \<in> New \<and> a \<in> B)" for B { fix B assume "B \<in> S" with \<open>S \<subseteq> G\<close> have "B \<in> G" by auto hence "\<exists> a. a \<in> New \<and> a \<in> B" unfolding G_def by auto from someI_ex[OF this, folded g_def] have "g B \<in> New" "g B \<in> B" by auto } note gB = this have "card (g ` S) \<le> card New" by (rule card_mono, insert New gB, auto) also have "\<dots> < r" unfolding New using r by simp also have "\<dots> \<le> card S" by fact finally have "card (g ` S) < card S" . from pigeonhole[OF this] have "\<not> inj_on g S" . then obtain B1 B2 where B12: "B1 \<in> S" "B2 \<in> S" "B1 \<noteq> B2" "g B1 = g B2" unfolding inj_on_def by auto define a where "a = g B2" from B12 gB[of B1] gB[of B2] have a: "a \<in> New" "a \<in> B1" "a \<in> B2" unfolding a_def by auto with B12 have "\<exists>B1 B2. B1 \<in> S \<and> B2 \<in> S \<and> B1 \<noteq> B2 \<and> a \<in> B1 \<and> a \<in> B2" unfolding a_def by blast from \<open>sunflower S\<close>[unfolded sunflower_def, rule_format, OF this] have aS: "B \<in> S \<Longrightarrow> a \<in> B" for B by auto define h where "h B = B - {a}" for B define T where "T = h ` S" have "\<exists>S\<subseteq>F. sunflower S \<and> r \<le> card S" proof (intro exI[of _ T] conjI) { fix B assume "B \<in> S" have hB: "h B = B - {a}" unfolding h_def T_def by auto from aS \<open>B \<in> S\<close> have aB: "a \<in> B" by auto from \<open>B \<in> S\<close> \<open>S \<subseteq> G\<close> obtain a' A where AF: "A \<in> F" and B: "B = insert a' A" and a': "a' \<in> New" unfolding G_def by force from aB B a' New AF a(1) hB AF have "insert a (h B) = B" "h B = A" by auto hence "insert a (h B) = B" "h B \<in> F" "insert a (h B) \<in> S" using AF \<open>B \<in> S\<close> by auto } note main = this have CTS: "C \<in> T \<Longrightarrow> insert a C \<in> S" for C using main unfolding T_def by force show "T \<subseteq> F" unfolding T_def using main by auto have "r \<le> card S" by fact also have "\<dots> = card T" unfolding T_def by (subst card_image, intro inj_on_inverseI[of _ "insert a"], insert main, auto) finally show "r \<le> card T" . show "sunflower T" unfolding sunflower_def proof (intro allI impI, elim exE conjE, goal_cases) case (1 x C C1 C2) from CTS[OF \<open>C1 \<in> T\<close>] CTS[OF \<open>C2 \<in> T\<close>] CTS[OF \<open>C \<in> T\<close>] have *: "insert a C1 \<in> S" "insert a C2 \<in> S" "insert a C \<in> S" by auto from 1 have "insert a C1 \<noteq> insert a C2" using main unfolding T_def by auto hence "\<exists>A B. A \<in> S \<and> B \<in> S \<and> A \<noteq> B \<and> x \<in> A \<and> x \<in> B" using * 1 by auto from \<open>sunflower S\<close>[unfolded sunflower_def, rule_format, OF this *(3)] have "x \<in> insert a C" . with 1 show "x \<in> C" unfolding T_def h_def by auto qed qed with sf show False .. qed qed qed next case r: True with rk have "k \<noteq> 0" by auto then obtain l where k: "k = Suc l" by (cases k, auto) show ?thesis unfolding r k by (intro exI[of _ "{}"], auto) qed text \<open>The difference between the lower and the upper bound on the existence of sunflowers as they have been formalized is @{term \<open>fact k\<close>}. There is more recent work with tighter bounds \cite{sunflower_new}, but we only integrate the initial result of Erdős and Rado in this theory.\<close> text \<open>We further provide the Erdős Rado lemma lifted to obtain non-empty cores or cores of arbitrary cardinality.\<close> lemma Erdos_Rado_sunflower_card_core: assumes "finite E" and "\<forall> A \<in> F. A \<subseteq> E \<and> s \<le> card A \<and> card A \<le> k" and "card F > (card E choose s) * (r - 1)^k * fact k" and "s \<noteq> 0" and "r \<noteq> 0" shows "\<exists> S. S \<subseteq> F \<and> sunflower S \<and> card S = r \<and> card (\<Inter> S) \<ge> s" by (rule sunflower_card_core_lift[OF assms(1) _ assms(2) _ assms(4-5), of "(r - 1)^k * fact k"], rule Erdos_Rado_sunflower, insert assms(3), auto simp: ac_simps) lemma Erdos_Rado_sunflower_nonempty_core: assumes "finite E" and "\<forall> A \<in> F. A \<subseteq> E \<and> card A \<le> k" and "{} \<notin> F" and "card F > card E * (r - 1)^k * fact k" shows "\<exists> S. S \<subseteq> F \<and> sunflower S \<and> card S = r \<and> \<Inter> S \<noteq> {}" by (rule sunflower_nonempty_core_lift[OF assms(1) _ assms(2-3), of "(r - 1)^k * fact k"], rule Erdos_Rado_sunflower, insert assms(4), auto simp: ac_simps) end
From discprob.prob Require Export prob countable stochastic_order. From mathcomp Require Import ssreflect ssrbool ssrfun eqtype choice fintype bigop. Require Export Reals Psatz. (* There are some refinements to this that can be proved: e.g.: we only needf to assume X x >= 0 for x such that Ω x > 0 *) Lemma markov {A} {Ω: distrib A} (X: rrvar Ω) a : (∀ x, X x >= 0) → a > 0 → ex_Ex X → pr_ge X a <= Ex X / a. Proof. intros Hnonneg Hgt0 Hex. cut (a * pr_ge X a <= Ex X). { intros. apply (Rmult_le_reg_l a); first by nra. etransitivity; first eauto. right. field. nra. } rewrite /pr_ge pr_ge_to_indicator. rewrite -Ex_indicator -Ex_scal_l; last apply ex_Ex_indicator. apply Ex_ext_le; auto. * apply ex_Ex_scal_l, ex_Ex_indicator. * intros x. rewrite //=. destruct Rge_dec => //=. ** nra. ** rewrite Rmult_0_r. apply Rge_le; auto. Qed. Lemma chebyshev {A} {Ω: distrib A} (X: rrvar Ω) a : a > 0 → ex_Var X → pr_ge (mkRvar Ω (λ a, Rabs (X a - Ex X))) a <= Var X / a^2. Proof. intros Hgt0 Hvar. specialize (markov (mkRvar Ω (λ a, (X a - Ex X)^2)) (a^2)). intros Hmark. etransitivity; last eapply Hmark. * right. rewrite /pr_ge. apply pr_eq_pred'. intros i. destruct Rge_dec as [Hge1|Hnge1]; destruct Rge_dec as [Hge2|Hnge2]; try (rewrite //=; done). ** exfalso. apply Hnge2. apply Rle_ge. rewrite //= ?Rmult_1_r. apply Rsqr_le_abs_1. apply Rge_le in Hge1. etransitivity; last eapply Hge1. rewrite Rabs_right //; nra. ** exfalso. apply Hnge1. apply Rle_ge. rewrite //=. rewrite -(Rabs_right a); last by nra. apply Rsqr_le_abs_0. apply Rge_le in Hge2. rewrite //= ?Rmult_1_r in Hge2. done. * rewrite //= => i. rewrite Rmult_1_r. apply Rle_ge, Rle_0_sqr. * nra. * destruct Hvar; auto. Qed.
[STATEMENT] lemma word64_bounds: "- (2 ^ (size (x :: word64) - 1)) = (-9223372036854775808 :: int)" "((2 ^ (size (x :: word64) - 1)) - 1) = (9223372036854775807 :: int)" "- (2 ^ (size (y :: 64 signed word) - 1)) = (-9223372036854775808 :: int)" "((2 ^ (size (y :: 64 signed word) - 1)) - 1) = (9223372036854775807 :: int)" [PROOF STATE] proof (prove) goal (1 subgoal): 1. (- (2 ^ (size x - 1)) = - 9223372036854775808 &&& 2 ^ (size x - 1) - 1 = 9223372036854775807) &&& - (2 ^ (size y - 1)) = - 9223372036854775808 &&& 2 ^ (size y - 1) - 1 = 9223372036854775807 [PROOF STEP] by (simp_all add: word_size)
# --- # title: 1001. Grid Illumination # id: problem1001 # author: Indigo # date: 2021-01-30 # difficulty: Hard # categories: Hash Table # link: <https://leetcode.com/problems/grid-illumination/description/> # hidden: true # --- # # You are given a `grid` of size `N x N`, and each cell of this grid has a lamp # that is initially **turned off**. # # You are also given an array of lamp positions `lamps`, where `lamps[i] = # [rowi, coli]` indicates that the lamp at `grid[rowi][coli]` is **turned on**. # When a lamp is turned on, it **illuminates its cell** and **all other cells** # in the same **row, column, or diagonal**. # # Finally, you are given a query array `queries`, where `queries[i] = [rowi, # coli]`. For the `ith` query, determine whether `grid[rowi][coli]` is # illuminated or not. After answering the `ith` query, **turn off** the lamp at # `grid[rowi][coli]` and its **8 adjacent lamps** if they exist. A lamp is # adjacent if its cell shares either a side or corner with `grid[rowi][coli]`. # # Return _an array of integers_`ans` _,_ _ where _`ans[i]` _should be_`1` _ if # the lamp in the _`ith` _query was illuminated, or _`0` _ if the lamp was # not._ # # # # **Example 1:** # # ![](https://assets.leetcode.com/uploads/2020/08/19/illu_1.jpg) # # # # Input: N = 5, lamps = [[0,0],[4,4]], queries = [[1,1],[1,0]] # Output: [1,0] # Explanation: We have the initial grid with all lamps turned off. In the above picture we see the grid after turning on the lamp at grid[0][0] then turning on the lamp at grid[4][4]. # The 0th query asks if the lamp at grid[1][1] is illuminated or not (the blue square). It is illuminated, so set ans[0] = 1. Then, we turn off all lamps in the red square. # ![](https://assets.leetcode.com/uploads/2020/08/19/illu_step1.jpg) # The 1st query asks if the lamp at grid[1][0] is illuminated or not (the blue square). It is not illuminated, so set ans[1] = 1. Then, we turn off all lamps in the red rectangle. # ![](https://assets.leetcode.com/uploads/2020/08/19/illu_step2.jpg) # # # **Example 2:** # # # # Input: N = 5, lamps = [[0,0],[4,4]], queries = [[1,1],[1,1]] # Output: [1,1] # # # **Example 3:** # # # # Input: N = 5, lamps = [[0,0],[0,4]], queries = [[0,4],[0,1],[1,4]] # Output: [1,1,0] # # # # # **Constraints:** # # * `1 <= N <= 109` # * `0 <= lamps.length <= 20000` # * `lamps[i].length == 2` # * `0 <= lamps[i][j] < N` # * `0 <= queries.length <= 20000` # * `queries[i].length == 2` # * `0 <= queries[i][j] < N` # # ## @lc code=start using LeetCode function grid_illumination(N, lamps::Vector{Tuple{Int,Int}}, query::Vector{Tuple{Int,Int}}) function update!(lamp, q) col_illum[lamp[2]] += q row_illum[lamp[1]] += q main_diag_illum[lamp[2]-lamp[1]] += q d_diag_illum[lamp[2]+lamp[1]] += q end dirs = [ -1 -1 -1 0 0 0 1 1 1 1 0 -1 1 0 -1 1 0 -1 ] col_illum = DefaultDict{Int,Int}(0) row_illum = DefaultDict{Int,Int}(0) main_diag_illum = DefaultDict{Int,Int}(0) d_diag_illum = DefaultDict{Int,Int}(0) illum_pos = Set(lamps) res = fill(0, length(query)) for lamp in lamps update!(lamp, 1) end for (idx, q) in enumerate(query) if col_illum[q[2]] > 0 || row_illum[q[1]] > 0 || main_diag_illum[q[2]-q[1]] > 0 || main_diag_illum[q[2]+q[1]] > 0 res[idx] = 1 end for dir in 1:9 new_pos = (q[1] + dirs[1, dir], q[2] + dirs[2, dir]) if new_pos in illum_pos pop!(illum_pos) update!(new_pos, -1) end end end res end ## @lc code=end
theory MultiAssets imports Semantics begin section "Assets" text "We represent Multi-token assets as a function from Token to natural numbers." (* TODO: I want to replace Asset definition with typedef Assets = "{assets. (\<forall> t v. fmlookup assets t = Some v \<longrightarrow> v > 0)} :: ((Token, nat) fmap) set but I need to solve this issue https://isabelle.zulipchat.com/#narrow/stream/238552-Beginner-Questions/topic/Is.20it.20possible.20to.20create.20a.20typedef.20.20of.20a.20typedef.3F/near/340510660 *) typedef Assets = "{assets :: Token \<Rightarrow> nat. True}" by auto setup_lifting type_definition_Assets text " The \<^emph>\<open>asset\<close> definition allows us to create a single-token asset " lift_definition asset :: "Token \<Rightarrow> nat \<Rightarrow> Assets" is "\<lambda>tok val. \<lambda>t. if t = tok then val else 0" by simp text " The \<^emph>\<open>assetValue\<close> definition allow us to obtain how many \<^emph>\<open>tokens\<close> (for a particular token) are in the Assets " lift_definition assetValue :: "Token \<Rightarrow> Assets \<Rightarrow> nat" is "\<lambda>t a. a t" . lemma assetValueOfSingleAsset [simp] : "assetValue tok (asset tok b) = b" by transfer simp lemma assetValueOfDifferentToken [simp] : "tok1 \<noteq> tok2 \<Longrightarrow> assetValue tok1 (asset tok2 b) = 0" by transfer simp lemma assetsEqByValue: "a = b \<longleftrightarrow> (\<forall> tok. assetValue tok a = assetValue tok b)" by transfer auto subsection "Ordering" text " We define partial order for assets instead of total order because we cannot compare values of different tokens. " text "We need to define order because Assets can't be negative, so we can only simplify things like \<^term>\<open>a + (b - a) = b\<close> if \<^term>\<open>a \<le> b\<close>. " instantiation Assets :: ord begin lift_definition less_eq_Assets :: "Assets \<Rightarrow> Assets \<Rightarrow> bool" is "\<lambda>a b. \<forall>t. a t \<le> b t" . lift_definition less_Assets :: "Assets \<Rightarrow> Assets \<Rightarrow> bool" is "\<lambda>a b. (\<forall>rt. a rt \<le> b rt) \<and> (\<exists> st. a st < b st)" . instance .. end instantiation Assets :: preorder begin instance proof fix a b c :: Assets show "a \<le> a" by transfer simp show "a \<le> b \<Longrightarrow> b \<le> c \<Longrightarrow> a \<le> c" using le_trans by transfer blast show "a < b = ( a \<le> b \<and> \<not> b \<le> a)" by transfer (metis leD leI) qed end instantiation Assets :: order begin instance proof fix a b :: Assets show "a \<le> b \<Longrightarrow> b \<le> a \<Longrightarrow> a = b" using le_antisym by transfer blast qed end text "If we create a single asset from a multi-asset, then the single asset is going to be lower or equal to the multi-asset" lemma singleAsset_leq_than_asset: "asset t (assetValue t a) \<le> a" by transfer simp subsection "Arithmetic" instantiation Assets :: zero begin lift_definition zero_Assets :: Assets is "\<lambda>_. 0" by simp instance .. end text "Creating a single asset with 0 tokens is the same as creating the zero_Assets" lemma assetZero [simp] : "asset tok 0 = 0" by transfer auto text "If we try to create a single asset from a negative integer is also the same as creating the zero_Assets" corollary assetOfNegInt [simp] : "(i :: int) \<le> 0 \<Longrightarrow> asset t (nat i) = 0" by simp text "Trying to count the amount of tokens of the zero_Assets is 0" lemma assetValueOfZero [simp] : "assetValue t 0 = 0" by transfer simp instantiation Assets :: plus begin lift_definition plus_Assets :: "Assets \<Rightarrow> Assets \<Rightarrow> Assets" is "\<lambda>x y. \<lambda>tok. x tok + y tok" by auto instance .. end lemma assetsDistributesPlus : "asset tok (a + b) = asset tok a + asset tok b" by transfer auto lemma assetsJoinPlus : "asset tok a + asset tok b = asset tok (a + b)" by (simp add: assetsDistributesPlus) lemma assetValue_distrib : "assetValue tok (a + b) = assetValue tok a + assetValue tok b" by transfer auto instantiation Assets :: minus begin lift_definition minus_Assets :: "Assets \<Rightarrow> Assets \<Rightarrow> Assets" is "\<lambda>x y. \<lambda>tok. x tok - y tok" by auto instance .. end lemma assetsDistributesMinus : "asset tok (a - b) = asset tok a - asset tok b" by transfer auto instantiation Assets :: semigroup_add begin instance proof fix a b c :: Assets show "(a + b) + c = a + (b + c)" by transfer (simp add: Groups.ab_semigroup_add_class.add_ac(1)) qed end instantiation Assets :: ab_semigroup_add begin instance proof fix a b :: Assets show "a + b = b + a" by transfer (simp add: Groups.ab_semigroup_add_class.add.commute) qed end instantiation Assets :: monoid_add begin instance proof fix a :: Assets show "0 + a = a" by transfer auto show "a + 0 = a" by transfer auto qed end (* TODO: This should be included by monoid_add, but for some reason I cannot delete it *) instantiation Assets :: comm_monoid_add begin instance by standard simp end instantiation Assets :: cancel_ab_semigroup_add begin instance proof fix a b c :: Assets show "a + b - a = b" by transfer force show "a - b - c = a - (b + c)" using diff_diff_left by transfer presburger qed end instantiation Assets :: comm_monoid_diff begin instance proof fix a :: Assets show "0 - a = 0" by transfer simp qed end instantiation Assets :: ordered_ab_semigroup_add begin instance proof fix a b c :: Assets show "a \<le> b \<Longrightarrow> c + a \<le> c + b" by transfer simp qed end instantiation Assets :: ordered_ab_semigroup_add_imp_le begin instance proof fix a b c :: Assets show "c + a \<le> c + b \<Longrightarrow> a \<le> b" by transfer simp qed end instantiation Assets :: canonically_ordered_monoid_add begin instance proof fix a b :: Assets (* TODO: See how to make this proof structured *) have "a \<le> b \<Longrightarrow> \<exists>c. b = a + c" apply transfer subgoal for a2 b2 apply (subgoal_tac "\<And> x. a2 x \<le> b2 x \<Longrightarrow> b2 x = a2 x + (b2 x - a2 x)") apply fast by simp done also have "\<exists>c. b = a + c \<Longrightarrow> a \<le> b" by transfer auto then show "(a \<le> b) = (\<exists>c. b = a + c)" using calculation by blast qed end instantiation Assets :: ordered_cancel_comm_monoid_diff begin instance by standard end end
module AutoSearchHide2 import AutoSearchHide1 myZero : Value === 0 myZero = Refl [OneA] A where Value = 1 %hint HintOneA : A HintOneA = OneA -- Want to use the OneA (via HintOneA) instance here. -- `%hide` should block the auto-search from -- including the `HintZeroA` hint into the list of solutions. -- Thus, we don't get into the `multiple solutions` situation. %hide HintZeroA myOne : Value === 1 myOne = Refl
#include "DrawCommand.hpp" #include <vizkit3d_debug_drawings/DrawingManager.hpp> #include <osgViz/Object.h> #include <boost/serialization/export.hpp> namespace vizkit3dDebugDrawings { DrawCommand::DrawCommand(const std::string& drawingChannel) : Command(drawingChannel) { } void DrawCommand::execute(DrawingManager* drawingManager) const { drawingManager->addPrimitive(getDrawingChannel(), createPrimitive()); } DrawCommand::~DrawCommand() { } DrawCommand* DrawCommand::clone() const { //should not be callable, but pure-virtual does not work with orogen. throw std::runtime_error("called DrawCommand clone()"); } }
{-# OPTIONS --allow-unsolved-metas #-} latex : Set latex = {!test!}
[GOAL] V : Type u G : SimpleGraph V ⊢ IsAcyclic G ↔ ∀ ⦃v w : V⦄, Adj G v w → IsBridge G (Quotient.mk (Sym2.Rel.setoid V) (v, w)) [PROOFSTEP] simp_rw [isBridge_iff_adj_and_forall_cycle_not_mem] [GOAL] V : Type u G : SimpleGraph V ⊢ IsAcyclic G ↔ ∀ ⦃v w : V⦄, Adj G v w → Adj G v w ∧ ∀ ⦃u : V⦄ (p : Walk G u u), IsCycle p → ¬Quotient.mk (Sym2.Rel.setoid V) (v, w) ∈ edges p [PROOFSTEP] constructor [GOAL] case mp V : Type u G : SimpleGraph V ⊢ IsAcyclic G → ∀ ⦃v w : V⦄, Adj G v w → Adj G v w ∧ ∀ ⦃u : V⦄ (p : Walk G u u), IsCycle p → ¬Quotient.mk (Sym2.Rel.setoid V) (v, w) ∈ edges p [PROOFSTEP] intro ha v w hvw [GOAL] case mp V : Type u G : SimpleGraph V ha : IsAcyclic G v w : V hvw : Adj G v w ⊢ Adj G v w ∧ ∀ ⦃u : V⦄ (p : Walk G u u), IsCycle p → ¬Quotient.mk (Sym2.Rel.setoid V) (v, w) ∈ edges p [PROOFSTEP] apply And.intro hvw [GOAL] case mp V : Type u G : SimpleGraph V ha : IsAcyclic G v w : V hvw : Adj G v w ⊢ ∀ ⦃u : V⦄ (p : Walk G u u), IsCycle p → ¬Quotient.mk (Sym2.Rel.setoid V) (v, w) ∈ edges p [PROOFSTEP] intro u p hp [GOAL] case mp V : Type u G : SimpleGraph V ha : IsAcyclic G v w : V hvw : Adj G v w u : V p : Walk G u u hp : IsCycle p ⊢ ¬Quotient.mk (Sym2.Rel.setoid V) (v, w) ∈ edges p [PROOFSTEP] cases ha p hp [GOAL] case mpr V : Type u G : SimpleGraph V ⊢ (∀ ⦃v w : V⦄, Adj G v w → Adj G v w ∧ ∀ ⦃u : V⦄ (p : Walk G u u), IsCycle p → ¬Quotient.mk (Sym2.Rel.setoid V) (v, w) ∈ edges p) → IsAcyclic G [PROOFSTEP] rintro hb v (_ | ⟨ha, p⟩) hp [GOAL] case mpr.nil V : Type u G : SimpleGraph V hb : ∀ ⦃v w : V⦄, Adj G v w → Adj G v w ∧ ∀ ⦃u : V⦄ (p : Walk G u u), IsCycle p → ¬Quotient.mk (Sym2.Rel.setoid V) (v, w) ∈ edges p v : V hp : IsCycle nil ⊢ False [PROOFSTEP] exact hp.not_of_nil [GOAL] case mpr.cons V : Type u G : SimpleGraph V hb : ∀ ⦃v w : V⦄, Adj G v w → Adj G v w ∧ ∀ ⦃u : V⦄ (p : Walk G u u), IsCycle p → ¬Quotient.mk (Sym2.Rel.setoid V) (v, w) ∈ edges p v v✝ : V ha : Adj G v v✝ p : Walk G v✝ v hp : IsCycle (cons ha p) ⊢ False [PROOFSTEP] apply (hb ha).2 _ hp [GOAL] case mpr.cons V : Type u G : SimpleGraph V hb : ∀ ⦃v w : V⦄, Adj G v w → Adj G v w ∧ ∀ ⦃u : V⦄ (p : Walk G u u), IsCycle p → ¬Quotient.mk (Sym2.Rel.setoid V) (v, w) ∈ edges p v v✝ : V ha : Adj G v v✝ p : Walk G v✝ v hp : IsCycle (cons ha p) ⊢ Quotient.mk (Sym2.Rel.setoid V) (v, v✝) ∈ edges (cons ha p) [PROOFSTEP] rw [Walk.edges_cons] [GOAL] case mpr.cons V : Type u G : SimpleGraph V hb : ∀ ⦃v w : V⦄, Adj G v w → Adj G v w ∧ ∀ ⦃u : V⦄ (p : Walk G u u), IsCycle p → ¬Quotient.mk (Sym2.Rel.setoid V) (v, w) ∈ edges p v v✝ : V ha : Adj G v v✝ p : Walk G v✝ v hp : IsCycle (cons ha p) ⊢ Quotient.mk (Sym2.Rel.setoid V) (v, v✝) ∈ Quotient.mk (Sym2.Rel.setoid V) (v, v✝) :: edges p [PROOFSTEP] apply List.mem_cons_self [GOAL] V : Type u G : SimpleGraph V ⊢ IsAcyclic G ↔ ∀ ⦃e : Sym2 V⦄, e ∈ edgeSet G → IsBridge G e [PROOFSTEP] simp [isAcyclic_iff_forall_adj_isBridge, Sym2.forall] [GOAL] V : Type u G✝ G : SimpleGraph V h : IsAcyclic G v w : V p q : Path G v w ⊢ p = q [PROOFSTEP] obtain ⟨p, hp⟩ := p [GOAL] case mk V : Type u G✝ G : SimpleGraph V h : IsAcyclic G v w : V q : Path G v w p : Walk G v w hp : IsPath p ⊢ { val := p, property := hp } = q [PROOFSTEP] obtain ⟨q, hq⟩ := q [GOAL] case mk.mk V : Type u G✝ G : SimpleGraph V h : IsAcyclic G v w : V p : Walk G v w hp : IsPath p q : Walk G v w hq : IsPath q ⊢ { val := p, property := hp } = { val := q, property := hq } [PROOFSTEP] rw [Subtype.mk.injEq] [GOAL] case mk.mk V : Type u G✝ G : SimpleGraph V h : IsAcyclic G v w : V p : Walk G v w hp : IsPath p q : Walk G v w hq : IsPath q ⊢ p = q [PROOFSTEP] induction p with | nil => cases (Walk.isPath_iff_eq_nil _).mp hq rfl | cons ph p ih => rw [isAcyclic_iff_forall_adj_isBridge] at h specialize h ph rw [isBridge_iff_adj_and_forall_walk_mem_edges] at h replace h := h.2 (q.append p.reverse) simp only [Walk.edges_append, Walk.edges_reverse, List.mem_append, List.mem_reverse] at h cases' h with h h · cases q with | nil => simp [Walk.isPath_def] at hp | cons _ q => rw [Walk.cons_isPath_iff] at hp hq simp only [Walk.edges_cons, List.mem_cons, Sym2.eq_iff, true_and] at h rcases h with (⟨h, rfl⟩ | ⟨rfl, rfl⟩) | h · cases ih hp.1 q hq.1 rfl · simp at hq · exact absurd (Walk.fst_mem_support_of_mem_edges _ h) hq.2 · rw [Walk.cons_isPath_iff] at hp exact absurd (Walk.fst_mem_support_of_mem_edges _ h) hp.2 [GOAL] case mk.mk V : Type u G✝ G : SimpleGraph V h : IsAcyclic G v w : V p : Walk G v w hp : IsPath p q : Walk G v w hq : IsPath q ⊢ p = q [PROOFSTEP] induction p with | nil => cases (Walk.isPath_iff_eq_nil _).mp hq rfl | cons ph p ih => rw [isAcyclic_iff_forall_adj_isBridge] at h specialize h ph rw [isBridge_iff_adj_and_forall_walk_mem_edges] at h replace h := h.2 (q.append p.reverse) simp only [Walk.edges_append, Walk.edges_reverse, List.mem_append, List.mem_reverse] at h cases' h with h h · cases q with | nil => simp [Walk.isPath_def] at hp | cons _ q => rw [Walk.cons_isPath_iff] at hp hq simp only [Walk.edges_cons, List.mem_cons, Sym2.eq_iff, true_and] at h rcases h with (⟨h, rfl⟩ | ⟨rfl, rfl⟩) | h · cases ih hp.1 q hq.1 rfl · simp at hq · exact absurd (Walk.fst_mem_support_of_mem_edges _ h) hq.2 · rw [Walk.cons_isPath_iff] at hp exact absurd (Walk.fst_mem_support_of_mem_edges _ h) hp.2 [GOAL] case mk.mk.nil V : Type u G✝ G : SimpleGraph V h : IsAcyclic G v w u✝ : V hp : IsPath nil q : Walk G u✝ u✝ hq : IsPath q ⊢ nil = q [PROOFSTEP] | nil => cases (Walk.isPath_iff_eq_nil _).mp hq rfl [GOAL] case mk.mk.nil V : Type u G✝ G : SimpleGraph V h : IsAcyclic G v w u✝ : V hp : IsPath nil q : Walk G u✝ u✝ hq : IsPath q ⊢ nil = q [PROOFSTEP] cases (Walk.isPath_iff_eq_nil _).mp hq [GOAL] case mk.mk.nil.refl V : Type u G✝ G : SimpleGraph V h : IsAcyclic G v w u✝ : V hp hq : IsPath nil ⊢ nil = nil [PROOFSTEP] rfl [GOAL] case mk.mk.cons V : Type u G✝ G : SimpleGraph V h : IsAcyclic G v w u✝ v✝ w✝ : V ph : Adj G u✝ v✝ p : Walk G v✝ w✝ ih : IsPath p → ∀ (q : Walk G v✝ w✝), IsPath q → p = q hp : IsPath (cons ph p) q : Walk G u✝ w✝ hq : IsPath q ⊢ cons ph p = q [PROOFSTEP] | cons ph p ih => rw [isAcyclic_iff_forall_adj_isBridge] at h specialize h ph rw [isBridge_iff_adj_and_forall_walk_mem_edges] at h replace h := h.2 (q.append p.reverse) simp only [Walk.edges_append, Walk.edges_reverse, List.mem_append, List.mem_reverse] at h cases' h with h h · cases q with | nil => simp [Walk.isPath_def] at hp | cons _ q => rw [Walk.cons_isPath_iff] at hp hq simp only [Walk.edges_cons, List.mem_cons, Sym2.eq_iff, true_and] at h rcases h with (⟨h, rfl⟩ | ⟨rfl, rfl⟩) | h · cases ih hp.1 q hq.1 rfl · simp at hq · exact absurd (Walk.fst_mem_support_of_mem_edges _ h) hq.2 · rw [Walk.cons_isPath_iff] at hp exact absurd (Walk.fst_mem_support_of_mem_edges _ h) hp.2 [GOAL] case mk.mk.cons V : Type u G✝ G : SimpleGraph V h : IsAcyclic G v w u✝ v✝ w✝ : V ph : Adj G u✝ v✝ p : Walk G v✝ w✝ ih : IsPath p → ∀ (q : Walk G v✝ w✝), IsPath q → p = q hp : IsPath (cons ph p) q : Walk G u✝ w✝ hq : IsPath q ⊢ cons ph p = q [PROOFSTEP] rw [isAcyclic_iff_forall_adj_isBridge] at h [GOAL] case mk.mk.cons V : Type u G✝ G : SimpleGraph V h : ∀ ⦃v w : V⦄, Adj G v w → IsBridge G (Quotient.mk (Sym2.Rel.setoid V) (v, w)) v w u✝ v✝ w✝ : V ph : Adj G u✝ v✝ p : Walk G v✝ w✝ ih : IsPath p → ∀ (q : Walk G v✝ w✝), IsPath q → p = q hp : IsPath (cons ph p) q : Walk G u✝ w✝ hq : IsPath q ⊢ cons ph p = q [PROOFSTEP] specialize h ph [GOAL] case mk.mk.cons V : Type u G✝ G : SimpleGraph V v w u✝ v✝ w✝ : V ph : Adj G u✝ v✝ p : Walk G v✝ w✝ ih : IsPath p → ∀ (q : Walk G v✝ w✝), IsPath q → p = q hp : IsPath (cons ph p) q : Walk G u✝ w✝ hq : IsPath q h : IsBridge G (Quotient.mk (Sym2.Rel.setoid V) (u✝, v✝)) ⊢ cons ph p = q [PROOFSTEP] rw [isBridge_iff_adj_and_forall_walk_mem_edges] at h [GOAL] case mk.mk.cons V : Type u G✝ G : SimpleGraph V v w u✝ v✝ w✝ : V ph : Adj G u✝ v✝ p : Walk G v✝ w✝ ih : IsPath p → ∀ (q : Walk G v✝ w✝), IsPath q → p = q hp : IsPath (cons ph p) q : Walk G u✝ w✝ hq : IsPath q h : Adj G u✝ v✝ ∧ ∀ (p : Walk G u✝ v✝), Quotient.mk (Sym2.Rel.setoid V) (u✝, v✝) ∈ edges p ⊢ cons ph p = q [PROOFSTEP] replace h := h.2 (q.append p.reverse) [GOAL] case mk.mk.cons V : Type u G✝ G : SimpleGraph V v w u✝ v✝ w✝ : V ph : Adj G u✝ v✝ p : Walk G v✝ w✝ ih : IsPath p → ∀ (q : Walk G v✝ w✝), IsPath q → p = q hp : IsPath (cons ph p) q : Walk G u✝ w✝ hq : IsPath q h : Quotient.mk (Sym2.Rel.setoid V) (u✝, v✝) ∈ edges (append q (reverse p)) ⊢ cons ph p = q [PROOFSTEP] simp only [Walk.edges_append, Walk.edges_reverse, List.mem_append, List.mem_reverse] at h [GOAL] case mk.mk.cons V : Type u G✝ G : SimpleGraph V v w u✝ v✝ w✝ : V ph : Adj G u✝ v✝ p : Walk G v✝ w✝ ih : IsPath p → ∀ (q : Walk G v✝ w✝), IsPath q → p = q hp : IsPath (cons ph p) q : Walk G u✝ w✝ hq : IsPath q h : Quotient.mk (Sym2.Rel.setoid V) (u✝, v✝) ∈ edges q ∨ Quotient.mk (Sym2.Rel.setoid V) (u✝, v✝) ∈ edges p ⊢ cons ph p = q [PROOFSTEP] cases' h with h h [GOAL] case mk.mk.cons.inl V : Type u G✝ G : SimpleGraph V v w u✝ v✝ w✝ : V ph : Adj G u✝ v✝ p : Walk G v✝ w✝ ih : IsPath p → ∀ (q : Walk G v✝ w✝), IsPath q → p = q hp : IsPath (cons ph p) q : Walk G u✝ w✝ hq : IsPath q h : Quotient.mk (Sym2.Rel.setoid V) (u✝, v✝) ∈ edges q ⊢ cons ph p = q [PROOFSTEP] cases q with | nil => simp [Walk.isPath_def] at hp | cons _ q => rw [Walk.cons_isPath_iff] at hp hq simp only [Walk.edges_cons, List.mem_cons, Sym2.eq_iff, true_and] at h rcases h with (⟨h, rfl⟩ | ⟨rfl, rfl⟩) | h · cases ih hp.1 q hq.1 rfl · simp at hq · exact absurd (Walk.fst_mem_support_of_mem_edges _ h) hq.2 [GOAL] case mk.mk.cons.inl V : Type u G✝ G : SimpleGraph V v w u✝ v✝ w✝ : V ph : Adj G u✝ v✝ p : Walk G v✝ w✝ ih : IsPath p → ∀ (q : Walk G v✝ w✝), IsPath q → p = q hp : IsPath (cons ph p) q : Walk G u✝ w✝ hq : IsPath q h : Quotient.mk (Sym2.Rel.setoid V) (u✝, v✝) ∈ edges q ⊢ cons ph p = q [PROOFSTEP] cases q with | nil => simp [Walk.isPath_def] at hp | cons _ q => rw [Walk.cons_isPath_iff] at hp hq simp only [Walk.edges_cons, List.mem_cons, Sym2.eq_iff, true_and] at h rcases h with (⟨h, rfl⟩ | ⟨rfl, rfl⟩) | h · cases ih hp.1 q hq.1 rfl · simp at hq · exact absurd (Walk.fst_mem_support_of_mem_edges _ h) hq.2 [GOAL] case mk.mk.cons.inl.nil V : Type u G✝ G : SimpleGraph V v w u✝ v✝ : V ph : Adj G u✝ v✝ p : Walk G v✝ u✝ ih : IsPath p → ∀ (q : Walk G v✝ u✝), IsPath q → p = q hp : IsPath (cons ph p) hq : IsPath nil h : Quotient.mk (Sym2.Rel.setoid V) (u✝, v✝) ∈ edges nil ⊢ cons ph p = nil [PROOFSTEP] | nil => simp [Walk.isPath_def] at hp [GOAL] case mk.mk.cons.inl.nil V : Type u G✝ G : SimpleGraph V v w u✝ v✝ : V ph : Adj G u✝ v✝ p : Walk G v✝ u✝ ih : IsPath p → ∀ (q : Walk G v✝ u✝), IsPath q → p = q hp : IsPath (cons ph p) hq : IsPath nil h : Quotient.mk (Sym2.Rel.setoid V) (u✝, v✝) ∈ edges nil ⊢ cons ph p = nil [PROOFSTEP] simp [Walk.isPath_def] at hp [GOAL] case mk.mk.cons.inl.cons V : Type u G✝ G : SimpleGraph V v w u✝ v✝¹ w✝ : V ph : Adj G u✝ v✝¹ p : Walk G v✝¹ w✝ ih : IsPath p → ∀ (q : Walk G v✝¹ w✝), IsPath q → p = q hp : IsPath (cons ph p) v✝ : V h✝ : Adj G u✝ v✝ q : Walk G v✝ w✝ hq : IsPath (cons h✝ q) h : Quotient.mk (Sym2.Rel.setoid V) (u✝, v✝¹) ∈ edges (cons h✝ q) ⊢ cons ph p = cons h✝ q [PROOFSTEP] | cons _ q => rw [Walk.cons_isPath_iff] at hp hq simp only [Walk.edges_cons, List.mem_cons, Sym2.eq_iff, true_and] at h rcases h with (⟨h, rfl⟩ | ⟨rfl, rfl⟩) | h · cases ih hp.1 q hq.1 rfl · simp at hq · exact absurd (Walk.fst_mem_support_of_mem_edges _ h) hq.2 [GOAL] case mk.mk.cons.inl.cons V : Type u G✝ G : SimpleGraph V v w u✝ v✝¹ w✝ : V ph : Adj G u✝ v✝¹ p : Walk G v✝¹ w✝ ih : IsPath p → ∀ (q : Walk G v✝¹ w✝), IsPath q → p = q hp : IsPath (cons ph p) v✝ : V h✝ : Adj G u✝ v✝ q : Walk G v✝ w✝ hq : IsPath (cons h✝ q) h : Quotient.mk (Sym2.Rel.setoid V) (u✝, v✝¹) ∈ edges (cons h✝ q) ⊢ cons ph p = cons h✝ q [PROOFSTEP] rw [Walk.cons_isPath_iff] at hp hq [GOAL] case mk.mk.cons.inl.cons V : Type u G✝ G : SimpleGraph V v w u✝ v✝¹ w✝ : V ph : Adj G u✝ v✝¹ p : Walk G v✝¹ w✝ ih : IsPath p → ∀ (q : Walk G v✝¹ w✝), IsPath q → p = q hp : IsPath p ∧ ¬u✝ ∈ Walk.support p v✝ : V h✝ : Adj G u✝ v✝ q : Walk G v✝ w✝ hq : IsPath q ∧ ¬u✝ ∈ Walk.support q h : Quotient.mk (Sym2.Rel.setoid V) (u✝, v✝¹) ∈ edges (cons h✝ q) ⊢ cons ph p = cons h✝ q [PROOFSTEP] simp only [Walk.edges_cons, List.mem_cons, Sym2.eq_iff, true_and] at h [GOAL] case mk.mk.cons.inl.cons V : Type u G✝ G : SimpleGraph V v w u✝ v✝¹ w✝ : V ph : Adj G u✝ v✝¹ p : Walk G v✝¹ w✝ ih : IsPath p → ∀ (q : Walk G v✝¹ w✝), IsPath q → p = q hp : IsPath p ∧ ¬u✝ ∈ Walk.support p v✝ : V h✝ : Adj G u✝ v✝ q : Walk G v✝ w✝ hq : IsPath q ∧ ¬u✝ ∈ Walk.support q h : (v✝¹ = v✝ ∨ u✝ = v✝ ∧ v✝¹ = u✝) ∨ Quotient.mk (Sym2.Rel.setoid V) (u✝, v✝¹) ∈ edges q ⊢ cons ph p = cons h✝ q [PROOFSTEP] rcases h with (⟨h, rfl⟩ | ⟨rfl, rfl⟩) | h [GOAL] case mk.mk.cons.inl.cons.inl.inl.refl V : Type u G✝ G : SimpleGraph V v w u✝ v✝ w✝ : V ph : Adj G u✝ v✝ p : Walk G v✝ w✝ ih : IsPath p → ∀ (q : Walk G v✝ w✝), IsPath q → p = q hp : IsPath p ∧ ¬u✝ ∈ Walk.support p h✝ : Adj G u✝ v✝ q : Walk G v✝ w✝ hq : IsPath q ∧ ¬u✝ ∈ Walk.support q ⊢ cons ph p = cons h✝ q [PROOFSTEP] cases ih hp.1 q hq.1 [GOAL] case mk.mk.cons.inl.cons.inl.inl.refl.refl V : Type u G✝ G : SimpleGraph V v w u✝ v✝ w✝ : V ph : Adj G u✝ v✝ p : Walk G v✝ w✝ ih : IsPath p → ∀ (q : Walk G v✝ w✝), IsPath q → p = q hp : IsPath p ∧ ¬u✝ ∈ Walk.support p h✝ : Adj G u✝ v✝ hq : IsPath p ∧ ¬u✝ ∈ Walk.support p ⊢ cons ph p = cons h✝ p [PROOFSTEP] rfl [GOAL] case mk.mk.cons.inl.cons.inl.inr.intro V : Type u G✝ G : SimpleGraph V v w v✝ w✝ : V p : Walk G v✝ w✝ ih : IsPath p → ∀ (q : Walk G v✝ w✝), IsPath q → p = q ph : Adj G v✝ v✝ hp : IsPath p ∧ ¬v✝ ∈ Walk.support p h✝ : Adj G v✝ v✝ q : Walk G v✝ w✝ hq : IsPath q ∧ ¬v✝ ∈ Walk.support q ⊢ cons ph p = cons h✝ q [PROOFSTEP] simp at hq [GOAL] case mk.mk.cons.inl.cons.inr V : Type u G✝ G : SimpleGraph V v w u✝ v✝¹ w✝ : V ph : Adj G u✝ v✝¹ p : Walk G v✝¹ w✝ ih : IsPath p → ∀ (q : Walk G v✝¹ w✝), IsPath q → p = q hp : IsPath p ∧ ¬u✝ ∈ Walk.support p v✝ : V h✝ : Adj G u✝ v✝ q : Walk G v✝ w✝ hq : IsPath q ∧ ¬u✝ ∈ Walk.support q h : Quotient.mk (Sym2.Rel.setoid V) (u✝, v✝¹) ∈ edges q ⊢ cons ph p = cons h✝ q [PROOFSTEP] exact absurd (Walk.fst_mem_support_of_mem_edges _ h) hq.2 [GOAL] case mk.mk.cons.inr V : Type u G✝ G : SimpleGraph V v w u✝ v✝ w✝ : V ph : Adj G u✝ v✝ p : Walk G v✝ w✝ ih : IsPath p → ∀ (q : Walk G v✝ w✝), IsPath q → p = q hp : IsPath (cons ph p) q : Walk G u✝ w✝ hq : IsPath q h : Quotient.mk (Sym2.Rel.setoid V) (u✝, v✝) ∈ edges p ⊢ cons ph p = q [PROOFSTEP] rw [Walk.cons_isPath_iff] at hp [GOAL] case mk.mk.cons.inr V : Type u G✝ G : SimpleGraph V v w u✝ v✝ w✝ : V ph : Adj G u✝ v✝ p : Walk G v✝ w✝ ih : IsPath p → ∀ (q : Walk G v✝ w✝), IsPath q → p = q hp : IsPath p ∧ ¬u✝ ∈ Walk.support p q : Walk G u✝ w✝ hq : IsPath q h : Quotient.mk (Sym2.Rel.setoid V) (u✝, v✝) ∈ edges p ⊢ cons ph p = q [PROOFSTEP] exact absurd (Walk.fst_mem_support_of_mem_edges _ h) hp.2 [GOAL] V : Type u G : SimpleGraph V h : ∀ (v w : V) (p q : Path G v w), p = q ⊢ IsAcyclic G [PROOFSTEP] intro v c hc [GOAL] V : Type u G : SimpleGraph V h : ∀ (v w : V) (p q : Path G v w), p = q v : V c : Walk G v v hc : IsCycle c ⊢ False [PROOFSTEP] simp only [Walk.isCycle_def, Ne.def] at hc [GOAL] V : Type u G : SimpleGraph V h : ∀ (v w : V) (p q : Path G v w), p = q v : V c : Walk G v v hc : IsTrail c ∧ ¬c = nil ∧ List.Nodup (List.tail (Walk.support c)) ⊢ False [PROOFSTEP] cases c with | nil => cases hc.2.1 rfl | cons ha c' => simp only [Walk.cons_isTrail_iff, Walk.support_cons, List.tail_cons, true_and_iff] at hc specialize h _ _ ⟨c', by simp only [Walk.isPath_def, hc.2]⟩ (Path.singleton ha.symm) rw [Path.singleton, Subtype.mk.injEq] at h simp [h] at hc [GOAL] V : Type u G : SimpleGraph V h : ∀ (v w : V) (p q : Path G v w), p = q v : V c : Walk G v v hc : IsTrail c ∧ ¬c = nil ∧ List.Nodup (List.tail (Walk.support c)) ⊢ False [PROOFSTEP] cases c with | nil => cases hc.2.1 rfl | cons ha c' => simp only [Walk.cons_isTrail_iff, Walk.support_cons, List.tail_cons, true_and_iff] at hc specialize h _ _ ⟨c', by simp only [Walk.isPath_def, hc.2]⟩ (Path.singleton ha.symm) rw [Path.singleton, Subtype.mk.injEq] at h simp [h] at hc [GOAL] case nil V : Type u G : SimpleGraph V h : ∀ (v w : V) (p q : Path G v w), p = q v : V hc : IsTrail nil ∧ ¬nil = nil ∧ List.Nodup (List.tail (Walk.support nil)) ⊢ False [PROOFSTEP] | nil => cases hc.2.1 rfl [GOAL] case nil V : Type u G : SimpleGraph V h : ∀ (v w : V) (p q : Path G v w), p = q v : V hc : IsTrail nil ∧ ¬nil = nil ∧ List.Nodup (List.tail (Walk.support nil)) ⊢ False [PROOFSTEP] cases hc.2.1 rfl [GOAL] case cons V : Type u G : SimpleGraph V h : ∀ (v w : V) (p q : Path G v w), p = q v v✝ : V ha : Adj G v v✝ c' : Walk G v✝ v hc : IsTrail (cons ha c') ∧ ¬cons ha c' = nil ∧ List.Nodup (List.tail (Walk.support (cons ha c'))) ⊢ False [PROOFSTEP] | cons ha c' => simp only [Walk.cons_isTrail_iff, Walk.support_cons, List.tail_cons, true_and_iff] at hc specialize h _ _ ⟨c', by simp only [Walk.isPath_def, hc.2]⟩ (Path.singleton ha.symm) rw [Path.singleton, Subtype.mk.injEq] at h simp [h] at hc [GOAL] case cons V : Type u G : SimpleGraph V h : ∀ (v w : V) (p q : Path G v w), p = q v v✝ : V ha : Adj G v v✝ c' : Walk G v✝ v hc : IsTrail (cons ha c') ∧ ¬cons ha c' = nil ∧ List.Nodup (List.tail (Walk.support (cons ha c'))) ⊢ False [PROOFSTEP] simp only [Walk.cons_isTrail_iff, Walk.support_cons, List.tail_cons, true_and_iff] at hc [GOAL] case cons V : Type u G : SimpleGraph V h : ∀ (v w : V) (p q : Path G v w), p = q v v✝ : V ha : Adj G v v✝ c' : Walk G v✝ v hc : (IsTrail c' ∧ ¬Quotient.mk (Sym2.Rel.setoid V) (v, v✝) ∈ edges c') ∧ List.Nodup (Walk.support c') ⊢ False [PROOFSTEP] specialize h _ _ ⟨c', by simp only [Walk.isPath_def, hc.2]⟩ (Path.singleton ha.symm) [GOAL] V : Type u G : SimpleGraph V h : ∀ (v w : V) (p q : Path G v w), p = q v v✝ : V ha : Adj G v v✝ c' : Walk G v✝ v hc : (IsTrail c' ∧ ¬Quotient.mk (Sym2.Rel.setoid V) (v, v✝) ∈ edges c') ∧ List.Nodup (Walk.support c') ⊢ IsPath c' [PROOFSTEP] simp only [Walk.isPath_def, hc.2] [GOAL] case cons V : Type u G : SimpleGraph V v v✝ : V ha : Adj G v v✝ c' : Walk G v✝ v hc : (IsTrail c' ∧ ¬Quotient.mk (Sym2.Rel.setoid V) (v, v✝) ∈ edges c') ∧ List.Nodup (Walk.support c') h : { val := c', property := (_ : IsPath c') } = Path.singleton (_ : Adj G v✝ v) ⊢ False [PROOFSTEP] rw [Path.singleton, Subtype.mk.injEq] at h [GOAL] case cons V : Type u G : SimpleGraph V v v✝ : V ha : Adj G v v✝ c' : Walk G v✝ v hc : (IsTrail c' ∧ ¬Quotient.mk (Sym2.Rel.setoid V) (v, v✝) ∈ edges c') ∧ List.Nodup (Walk.support c') h : c' = cons (_ : Adj G v✝ v) nil ⊢ False [PROOFSTEP] simp [h] at hc [GOAL] V : Type u G : SimpleGraph V ⊢ IsTree G ↔ Nonempty V ∧ ∀ (v w : V), ∃! p, IsPath p [PROOFSTEP] classical rw [IsTree_iff, isAcyclic_iff_path_unique] constructor · rintro ⟨hc, hu⟩ refine ⟨hc.nonempty, ?_⟩ intro v w let q := (hc v w).some.toPath use q simp only [true_and_iff, Path.isPath] intro p hp specialize hu ⟨p, hp⟩ q exact Subtype.ext_iff.mp hu · rintro ⟨hV, h⟩ refine ⟨Connected.mk ?_, ?_⟩ · intro v w obtain ⟨p, _⟩ := h v w exact p.reachable · rintro v w ⟨p, hp⟩ ⟨q, hq⟩ simp only [ExistsUnique.unique (h v w) hp hq] [GOAL] V : Type u G : SimpleGraph V ⊢ IsTree G ↔ Nonempty V ∧ ∀ (v w : V), ∃! p, IsPath p [PROOFSTEP] rw [IsTree_iff, isAcyclic_iff_path_unique] [GOAL] V : Type u G : SimpleGraph V ⊢ (Connected G ∧ ∀ ⦃v w : V⦄ (p q : Path G v w), p = q) ↔ Nonempty V ∧ ∀ (v w : V), ∃! p, IsPath p [PROOFSTEP] constructor [GOAL] case mp V : Type u G : SimpleGraph V ⊢ (Connected G ∧ ∀ ⦃v w : V⦄ (p q : Path G v w), p = q) → Nonempty V ∧ ∀ (v w : V), ∃! p, IsPath p [PROOFSTEP] rintro ⟨hc, hu⟩ [GOAL] case mp.intro V : Type u G : SimpleGraph V hc : Connected G hu : ∀ ⦃v w : V⦄ (p q : Path G v w), p = q ⊢ Nonempty V ∧ ∀ (v w : V), ∃! p, IsPath p [PROOFSTEP] refine ⟨hc.nonempty, ?_⟩ [GOAL] case mp.intro V : Type u G : SimpleGraph V hc : Connected G hu : ∀ ⦃v w : V⦄ (p q : Path G v w), p = q ⊢ ∀ (v w : V), ∃! p, IsPath p [PROOFSTEP] intro v w [GOAL] case mp.intro V : Type u G : SimpleGraph V hc : Connected G hu : ∀ ⦃v w : V⦄ (p q : Path G v w), p = q v w : V ⊢ ∃! p, IsPath p [PROOFSTEP] let q := (hc v w).some.toPath [GOAL] case mp.intro V : Type u G : SimpleGraph V hc : Connected G hu : ∀ ⦃v w : V⦄ (p q : Path G v w), p = q v w : V q : Path G v w := toPath (Nonempty.some (_ : Reachable G v w)) ⊢ ∃! p, IsPath p [PROOFSTEP] use q [GOAL] case h V : Type u G : SimpleGraph V hc : Connected G hu : ∀ ⦃v w : V⦄ (p q : Path G v w), p = q v w : V q : Path G v w := toPath (Nonempty.some (_ : Reachable G v w)) ⊢ (fun p => IsPath p) ↑q ∧ ∀ (y : Walk G v w), (fun p => IsPath p) y → y = ↑q [PROOFSTEP] simp only [true_and_iff, Path.isPath] [GOAL] case h V : Type u G : SimpleGraph V hc : Connected G hu : ∀ ⦃v w : V⦄ (p q : Path G v w), p = q v w : V q : Path G v w := toPath (Nonempty.some (_ : Reachable G v w)) ⊢ ∀ (y : Walk G v w), IsPath y → y = ↑(toPath (Nonempty.some (_ : Reachable G v w))) [PROOFSTEP] intro p hp [GOAL] case h V : Type u G : SimpleGraph V hc : Connected G hu : ∀ ⦃v w : V⦄ (p q : Path G v w), p = q v w : V q : Path G v w := toPath (Nonempty.some (_ : Reachable G v w)) p : Walk G v w hp : IsPath p ⊢ p = ↑(toPath (Nonempty.some (_ : Reachable G v w))) [PROOFSTEP] specialize hu ⟨p, hp⟩ q [GOAL] case h V : Type u G : SimpleGraph V hc : Connected G v w : V q : Path G v w := toPath (Nonempty.some (_ : Reachable G v w)) p : Walk G v w hp : IsPath p hu : { val := p, property := hp } = q ⊢ p = ↑(toPath (Nonempty.some (_ : Reachable G v w))) [PROOFSTEP] exact Subtype.ext_iff.mp hu [GOAL] case mpr V : Type u G : SimpleGraph V ⊢ (Nonempty V ∧ ∀ (v w : V), ∃! p, IsPath p) → Connected G ∧ ∀ ⦃v w : V⦄ (p q : Path G v w), p = q [PROOFSTEP] rintro ⟨hV, h⟩ [GOAL] case mpr.intro V : Type u G : SimpleGraph V hV : Nonempty V h : ∀ (v w : V), ∃! p, IsPath p ⊢ Connected G ∧ ∀ ⦃v w : V⦄ (p q : Path G v w), p = q [PROOFSTEP] refine ⟨Connected.mk ?_, ?_⟩ [GOAL] case mpr.intro.refine_1 V : Type u G : SimpleGraph V hV : Nonempty V h : ∀ (v w : V), ∃! p, IsPath p ⊢ Preconnected G [PROOFSTEP] intro v w [GOAL] case mpr.intro.refine_1 V : Type u G : SimpleGraph V hV : Nonempty V h : ∀ (v w : V), ∃! p, IsPath p v w : V ⊢ Reachable G v w [PROOFSTEP] obtain ⟨p, _⟩ := h v w [GOAL] case mpr.intro.refine_1.intro V : Type u G : SimpleGraph V hV : Nonempty V h : ∀ (v w : V), ∃! p, IsPath p v w : V p : Walk G v w h✝ : (fun p => IsPath p) p ∧ ∀ (y : Walk G v w), (fun p => IsPath p) y → y = p ⊢ Reachable G v w [PROOFSTEP] exact p.reachable [GOAL] case mpr.intro.refine_2 V : Type u G : SimpleGraph V hV : Nonempty V h : ∀ (v w : V), ∃! p, IsPath p ⊢ ∀ ⦃v w : V⦄ (p q : Path G v w), p = q [PROOFSTEP] rintro v w ⟨p, hp⟩ ⟨q, hq⟩ [GOAL] case mpr.intro.refine_2.mk.mk V : Type u G : SimpleGraph V hV : Nonempty V h : ∀ (v w : V), ∃! p, IsPath p v w : V p : Walk G v w hp : IsPath p q : Walk G v w hq : IsPath q ⊢ { val := p, property := hp } = { val := q, property := hq } [PROOFSTEP] simp only [ExistsUnique.unique (h v w) hp hq] [GOAL] V : Type u G : SimpleGraph V inst✝¹ : Fintype V inst✝ : Fintype ↑(edgeSet G) hG : IsTree G ⊢ Finset.card (edgeFinset G) + 1 = Fintype.card V [PROOFSTEP] have := hG.isConnected.nonempty [GOAL] V : Type u G : SimpleGraph V inst✝¹ : Fintype V inst✝ : Fintype ↑(edgeSet G) hG : IsTree G this : Nonempty V ⊢ Finset.card (edgeFinset G) + 1 = Fintype.card V [PROOFSTEP] inhabit V [GOAL] V : Type u G : SimpleGraph V inst✝¹ : Fintype V inst✝ : Fintype ↑(edgeSet G) hG : IsTree G this : Nonempty V inhabited_h : Inhabited V ⊢ Finset.card (edgeFinset G) + 1 = Fintype.card V [PROOFSTEP] classical have : Finset.card ({ default } : Finset V)ᶜ + 1 = Fintype.card V := by rw [Finset.card_compl, Finset.card_singleton, Nat.sub_add_cancel Fintype.card_pos] rw [← this, add_left_inj] choose f hf hf' using (hG.existsUnique_path · default) refine Eq.symm <| Finset.card_congr (fun w hw => ((f w).firstDart <| ?notNil).edge) (fun a ha => ?memEdges) ?inj ?surj case notNil => exact not_nil_of_ne (by simpa using hw) case memEdges => simp case inj => intros a b ha hb h wlog h' : (f a).length ≤ (f b).length generalizing a b · exact Eq.symm (this _ _ hb ha h.symm (le_of_not_le h')) rw [dart_edge_eq_iff] at h obtain (h | h) := h · exact (congrArg (·.fst) h) · have h1 : ((f a).firstDart <| not_nil_of_ne (by simpa using ha)).snd = b := congrArg (·.snd) h have h3 := congrArg length (hf' _ (((f _).tail _).copy h1 rfl) ?_) rw [length_copy, ← add_left_inj 1, length_tail_add_one] at h3 · exfalso linarith · simp only [ne_eq, eq_mp_eq_cast, id_eq, isPath_copy] exact (hf _).tail _ case surj => simp only [mem_edgeFinset, Finset.mem_compl, Finset.mem_singleton, Sym2.forall, mem_edgeSet] intros x y h wlog h' : (f x).length ≤ (f y).length generalizing x y · rw [Sym2.eq_swap] exact this y x h.symm (le_of_not_le h') refine ⟨y, ?_, dart_edge_eq_mk'_iff.2 <| Or.inr ?_⟩ · rintro rfl rw [← hf' _ nil IsPath.nil, length_nil, ← hf' _ (.cons h .nil) (IsPath.nil.cons <| by simpa using h.ne), length_cons, length_nil] at h' simp [le_zero_iff, Nat.one_ne_zero] at h' rw [← hf' _ (.cons h.symm (f x)) ((cons_isPath_iff _ _).2 ⟨hf _, fun hy => ?contra⟩)] rfl case contra => suffices : (f x).takeUntil y hy = .cons h .nil · rw [← take_spec _ hy] at h' simp [this, hf' _ _ ((hf _).dropUntil hy)] at h' refine (hG.existsUnique_path _ _).unique ((hf _).takeUntil _) ?_ simp [h.ne] [GOAL] V : Type u G : SimpleGraph V inst✝¹ : Fintype V inst✝ : Fintype ↑(edgeSet G) hG : IsTree G this : Nonempty V inhabited_h : Inhabited V ⊢ Finset.card (edgeFinset G) + 1 = Fintype.card V [PROOFSTEP] have : Finset.card ({ default } : Finset V)ᶜ + 1 = Fintype.card V := by rw [Finset.card_compl, Finset.card_singleton, Nat.sub_add_cancel Fintype.card_pos] [GOAL] V : Type u G : SimpleGraph V inst✝¹ : Fintype V inst✝ : Fintype ↑(edgeSet G) hG : IsTree G this : Nonempty V inhabited_h : Inhabited V ⊢ Finset.card {default}ᶜ + 1 = Fintype.card V [PROOFSTEP] rw [Finset.card_compl, Finset.card_singleton, Nat.sub_add_cancel Fintype.card_pos] [GOAL] V : Type u G : SimpleGraph V inst✝¹ : Fintype V inst✝ : Fintype ↑(edgeSet G) hG : IsTree G this✝ : Nonempty V inhabited_h : Inhabited V this : Finset.card {default}ᶜ + 1 = Fintype.card V ⊢ Finset.card (edgeFinset G) + 1 = Fintype.card V [PROOFSTEP] rw [← this, add_left_inj] [GOAL] V : Type u G : SimpleGraph V inst✝¹ : Fintype V inst✝ : Fintype ↑(edgeSet G) hG : IsTree G this✝ : Nonempty V inhabited_h : Inhabited V this : Finset.card {default}ᶜ + 1 = Fintype.card V ⊢ Finset.card (edgeFinset G) = Finset.card {default}ᶜ [PROOFSTEP] choose f hf hf' using (hG.existsUnique_path · default) [GOAL] V : Type u G : SimpleGraph V inst✝¹ : Fintype V inst✝ : Fintype ↑(edgeSet G) hG : IsTree G this✝ : Nonempty V inhabited_h : Inhabited V this : Finset.card {default}ᶜ + 1 = Fintype.card V f : (x : V) → Walk G x default hf : ∀ (x : V), (fun p => IsPath p) (f x) hf' : ∀ (x : V) (y : Walk G x default), (fun p => IsPath p) y → y = f x ⊢ Finset.card (edgeFinset G) = Finset.card {default}ᶜ [PROOFSTEP] refine Eq.symm <| Finset.card_congr (fun w hw => ((f w).firstDart <| ?notNil).edge) (fun a ha => ?memEdges) ?inj ?surj [GOAL] case notNil V : Type u G : SimpleGraph V inst✝¹ : Fintype V inst✝ : Fintype ↑(edgeSet G) hG : IsTree G this✝ : Nonempty V inhabited_h : Inhabited V this : Finset.card {default}ᶜ + 1 = Fintype.card V f : (x : V) → Walk G x default hf : ∀ (x : V), (fun p => IsPath p) (f x) hf' : ∀ (x : V) (y : Walk G x default), (fun p => IsPath p) y → y = f x w : V hw : w ∈ {default}ᶜ ⊢ ¬Nil (f w) case memEdges V : Type u G : SimpleGraph V inst✝¹ : Fintype V inst✝ : Fintype ↑(edgeSet G) hG : IsTree G this✝ : Nonempty V inhabited_h : Inhabited V this : Finset.card {default}ᶜ + 1 = Fintype.card V f : (x : V) → Walk G x default hf : ∀ (x : V), (fun p => IsPath p) (f x) hf' : ∀ (x : V) (y : Walk G x default), (fun p => IsPath p) y → y = f x a : V ha : a ∈ {default}ᶜ ⊢ (fun w hw => Dart.edge (firstDart (f w) (_ : ¬Nil (f w)))) a ha ∈ edgeFinset G case inj V : Type u G : SimpleGraph V inst✝¹ : Fintype V inst✝ : Fintype ↑(edgeSet G) hG : IsTree G this✝ : Nonempty V inhabited_h : Inhabited V this : Finset.card {default}ᶜ + 1 = Fintype.card V f : (x : V) → Walk G x default hf : ∀ (x : V), (fun p => IsPath p) (f x) hf' : ∀ (x : V) (y : Walk G x default), (fun p => IsPath p) y → y = f x ⊢ ∀ (a b : V) (ha : a ∈ {default}ᶜ) (hb : b ∈ {default}ᶜ), (fun w hw => Dart.edge (firstDart (f w) (_ : ¬Nil (f w)))) a ha = (fun w hw => Dart.edge (firstDart (f w) (_ : ¬Nil (f w)))) b hb → a = b case surj V : Type u G : SimpleGraph V inst✝¹ : Fintype V inst✝ : Fintype ↑(edgeSet G) hG : IsTree G this✝ : Nonempty V inhabited_h : Inhabited V this : Finset.card {default}ᶜ + 1 = Fintype.card V f : (x : V) → Walk G x default hf : ∀ (x : V), (fun p => IsPath p) (f x) hf' : ∀ (x : V) (y : Walk G x default), (fun p => IsPath p) y → y = f x ⊢ ∀ (b : Sym2 V), b ∈ edgeFinset G → ∃ a ha, (fun w hw => Dart.edge (firstDart (f w) (_ : ¬Nil (f w)))) a ha = b [PROOFSTEP] case notNil => exact not_nil_of_ne (by simpa using hw) [GOAL] V : Type u G : SimpleGraph V inst✝¹ : Fintype V inst✝ : Fintype ↑(edgeSet G) hG : IsTree G this✝ : Nonempty V inhabited_h : Inhabited V this : Finset.card {default}ᶜ + 1 = Fintype.card V f : (x : V) → Walk G x default hf : ∀ (x : V), (fun p => IsPath p) (f x) hf' : ∀ (x : V) (y : Walk G x default), (fun p => IsPath p) y → y = f x w : V hw : w ∈ {default}ᶜ ⊢ ¬Nil (f w) [PROOFSTEP] case notNil => exact not_nil_of_ne (by simpa using hw) [GOAL] V : Type u G : SimpleGraph V inst✝¹ : Fintype V inst✝ : Fintype ↑(edgeSet G) hG : IsTree G this✝ : Nonempty V inhabited_h : Inhabited V this : Finset.card {default}ᶜ + 1 = Fintype.card V f : (x : V) → Walk G x default hf : ∀ (x : V), (fun p => IsPath p) (f x) hf' : ∀ (x : V) (y : Walk G x default), (fun p => IsPath p) y → y = f x w : V hw : w ∈ {default}ᶜ ⊢ ¬Nil (f w) [PROOFSTEP] exact not_nil_of_ne (by simpa using hw) [GOAL] V : Type u G : SimpleGraph V inst✝¹ : Fintype V inst✝ : Fintype ↑(edgeSet G) hG : IsTree G this✝ : Nonempty V inhabited_h : Inhabited V this : Finset.card {default}ᶜ + 1 = Fintype.card V f : (x : V) → Walk G x default hf : ∀ (x : V), (fun p => IsPath p) (f x) hf' : ∀ (x : V) (y : Walk G x default), (fun p => IsPath p) y → y = f x w : V hw : w ∈ {default}ᶜ ⊢ w ≠ default [PROOFSTEP] simpa using hw [GOAL] case memEdges V : Type u G : SimpleGraph V inst✝¹ : Fintype V inst✝ : Fintype ↑(edgeSet G) hG : IsTree G this✝ : Nonempty V inhabited_h : Inhabited V this : Finset.card {default}ᶜ + 1 = Fintype.card V f : (x : V) → Walk G x default hf : ∀ (x : V), (fun p => IsPath p) (f x) hf' : ∀ (x : V) (y : Walk G x default), (fun p => IsPath p) y → y = f x a : V ha : a ∈ {default}ᶜ ⊢ (fun w hw => Dart.edge (firstDart (f w) (_ : ¬Nil (f w)))) a ha ∈ edgeFinset G case inj V : Type u G : SimpleGraph V inst✝¹ : Fintype V inst✝ : Fintype ↑(edgeSet G) hG : IsTree G this✝ : Nonempty V inhabited_h : Inhabited V this : Finset.card {default}ᶜ + 1 = Fintype.card V f : (x : V) → Walk G x default hf : ∀ (x : V), (fun p => IsPath p) (f x) hf' : ∀ (x : V) (y : Walk G x default), (fun p => IsPath p) y → y = f x ⊢ ∀ (a b : V) (ha : a ∈ {default}ᶜ) (hb : b ∈ {default}ᶜ), (fun w hw => Dart.edge (firstDart (f w) (_ : ¬Nil (f w)))) a ha = (fun w hw => Dart.edge (firstDart (f w) (_ : ¬Nil (f w)))) b hb → a = b case surj V : Type u G : SimpleGraph V inst✝¹ : Fintype V inst✝ : Fintype ↑(edgeSet G) hG : IsTree G this✝ : Nonempty V inhabited_h : Inhabited V this : Finset.card {default}ᶜ + 1 = Fintype.card V f : (x : V) → Walk G x default hf : ∀ (x : V), (fun p => IsPath p) (f x) hf' : ∀ (x : V) (y : Walk G x default), (fun p => IsPath p) y → y = f x ⊢ ∀ (b : Sym2 V), b ∈ edgeFinset G → ∃ a ha, (fun w hw => Dart.edge (firstDart (f w) (_ : ¬Nil (f w)))) a ha = b [PROOFSTEP] case memEdges => simp [GOAL] V : Type u G : SimpleGraph V inst✝¹ : Fintype V inst✝ : Fintype ↑(edgeSet G) hG : IsTree G this✝ : Nonempty V inhabited_h : Inhabited V this : Finset.card {default}ᶜ + 1 = Fintype.card V f : (x : V) → Walk G x default hf : ∀ (x : V), (fun p => IsPath p) (f x) hf' : ∀ (x : V) (y : Walk G x default), (fun p => IsPath p) y → y = f x a : V ha : a ∈ {default}ᶜ ⊢ (fun w hw => Dart.edge (firstDart (f w) (_ : ¬Nil (f w)))) a ha ∈ edgeFinset G [PROOFSTEP] case memEdges => simp [GOAL] V : Type u G : SimpleGraph V inst✝¹ : Fintype V inst✝ : Fintype ↑(edgeSet G) hG : IsTree G this✝ : Nonempty V inhabited_h : Inhabited V this : Finset.card {default}ᶜ + 1 = Fintype.card V f : (x : V) → Walk G x default hf : ∀ (x : V), (fun p => IsPath p) (f x) hf' : ∀ (x : V) (y : Walk G x default), (fun p => IsPath p) y → y = f x a : V ha : a ∈ {default}ᶜ ⊢ (fun w hw => Dart.edge (firstDart (f w) (_ : ¬Nil (f w)))) a ha ∈ edgeFinset G [PROOFSTEP] simp [GOAL] case inj V : Type u G : SimpleGraph V inst✝¹ : Fintype V inst✝ : Fintype ↑(edgeSet G) hG : IsTree G this✝ : Nonempty V inhabited_h : Inhabited V this : Finset.card {default}ᶜ + 1 = Fintype.card V f : (x : V) → Walk G x default hf : ∀ (x : V), (fun p => IsPath p) (f x) hf' : ∀ (x : V) (y : Walk G x default), (fun p => IsPath p) y → y = f x ⊢ ∀ (a b : V) (ha : a ∈ {default}ᶜ) (hb : b ∈ {default}ᶜ), (fun w hw => Dart.edge (firstDart (f w) (_ : ¬Nil (f w)))) a ha = (fun w hw => Dart.edge (firstDart (f w) (_ : ¬Nil (f w)))) b hb → a = b case surj V : Type u G : SimpleGraph V inst✝¹ : Fintype V inst✝ : Fintype ↑(edgeSet G) hG : IsTree G this✝ : Nonempty V inhabited_h : Inhabited V this : Finset.card {default}ᶜ + 1 = Fintype.card V f : (x : V) → Walk G x default hf : ∀ (x : V), (fun p => IsPath p) (f x) hf' : ∀ (x : V) (y : Walk G x default), (fun p => IsPath p) y → y = f x ⊢ ∀ (b : Sym2 V), b ∈ edgeFinset G → ∃ a ha, (fun w hw => Dart.edge (firstDart (f w) (_ : ¬Nil (f w)))) a ha = b [PROOFSTEP] case inj => intros a b ha hb h wlog h' : (f a).length ≤ (f b).length generalizing a b · exact Eq.symm (this _ _ hb ha h.symm (le_of_not_le h')) rw [dart_edge_eq_iff] at h obtain (h | h) := h · exact (congrArg (·.fst) h) · have h1 : ((f a).firstDart <| not_nil_of_ne (by simpa using ha)).snd = b := congrArg (·.snd) h have h3 := congrArg length (hf' _ (((f _).tail _).copy h1 rfl) ?_) rw [length_copy, ← add_left_inj 1, length_tail_add_one] at h3 · exfalso linarith · simp only [ne_eq, eq_mp_eq_cast, id_eq, isPath_copy] exact (hf _).tail _ [GOAL] V : Type u G : SimpleGraph V inst✝¹ : Fintype V inst✝ : Fintype ↑(edgeSet G) hG : IsTree G this✝ : Nonempty V inhabited_h : Inhabited V this : Finset.card {default}ᶜ + 1 = Fintype.card V f : (x : V) → Walk G x default hf : ∀ (x : V), (fun p => IsPath p) (f x) hf' : ∀ (x : V) (y : Walk G x default), (fun p => IsPath p) y → y = f x ⊢ ∀ (a b : V) (ha : a ∈ {default}ᶜ) (hb : b ∈ {default}ᶜ), (fun w hw => Dart.edge (firstDart (f w) (_ : ¬Nil (f w)))) a ha = (fun w hw => Dart.edge (firstDart (f w) (_ : ¬Nil (f w)))) b hb → a = b [PROOFSTEP] case inj => intros a b ha hb h wlog h' : (f a).length ≤ (f b).length generalizing a b · exact Eq.symm (this _ _ hb ha h.symm (le_of_not_le h')) rw [dart_edge_eq_iff] at h obtain (h | h) := h · exact (congrArg (·.fst) h) · have h1 : ((f a).firstDart <| not_nil_of_ne (by simpa using ha)).snd = b := congrArg (·.snd) h have h3 := congrArg length (hf' _ (((f _).tail _).copy h1 rfl) ?_) rw [length_copy, ← add_left_inj 1, length_tail_add_one] at h3 · exfalso linarith · simp only [ne_eq, eq_mp_eq_cast, id_eq, isPath_copy] exact (hf _).tail _ [GOAL] V : Type u G : SimpleGraph V inst✝¹ : Fintype V inst✝ : Fintype ↑(edgeSet G) hG : IsTree G this✝ : Nonempty V inhabited_h : Inhabited V this : Finset.card {default}ᶜ + 1 = Fintype.card V f : (x : V) → Walk G x default hf : ∀ (x : V), (fun p => IsPath p) (f x) hf' : ∀ (x : V) (y : Walk G x default), (fun p => IsPath p) y → y = f x ⊢ ∀ (a b : V) (ha : a ∈ {default}ᶜ) (hb : b ∈ {default}ᶜ), (fun w hw => Dart.edge (firstDart (f w) (_ : ¬Nil (f w)))) a ha = (fun w hw => Dart.edge (firstDart (f w) (_ : ¬Nil (f w)))) b hb → a = b [PROOFSTEP] intros a b ha hb h [GOAL] V : Type u G : SimpleGraph V inst✝¹ : Fintype V inst✝ : Fintype ↑(edgeSet G) hG : IsTree G this✝ : Nonempty V inhabited_h : Inhabited V this : Finset.card {default}ᶜ + 1 = Fintype.card V f : (x : V) → Walk G x default hf : ∀ (x : V), (fun p => IsPath p) (f x) hf' : ∀ (x : V) (y : Walk G x default), (fun p => IsPath p) y → y = f x a b : V ha : a ∈ {default}ᶜ hb : b ∈ {default}ᶜ h : (fun w hw => Dart.edge (firstDart (f w) (_ : ¬Nil (f w)))) a ha = (fun w hw => Dart.edge (firstDart (f w) (_ : ¬Nil (f w)))) b hb ⊢ a = b [PROOFSTEP] wlog h' : (f a).length ≤ (f b).length generalizing a b [GOAL] case inr V : Type u G : SimpleGraph V inst✝¹ : Fintype V inst✝ : Fintype ↑(edgeSet G) hG : IsTree G this✝¹ : Nonempty V inhabited_h : Inhabited V this✝ : Finset.card {default}ᶜ + 1 = Fintype.card V f : (x : V) → Walk G x default hf : ∀ (x : V), (fun p => IsPath p) (f x) hf' : ∀ (x : V) (y : Walk G x default), (fun p => IsPath p) y → y = f x a b : V ha : a ∈ {default}ᶜ hb : b ∈ {default}ᶜ h : (fun w hw => Dart.edge (firstDart (f w) (_ : ¬Nil (f w)))) a ha = (fun w hw => Dart.edge (firstDart (f w) (_ : ¬Nil (f w)))) b hb this : ∀ (a b : V) (ha : a ∈ {default}ᶜ) (hb : b ∈ {default}ᶜ), (fun w hw => Dart.edge (firstDart (f w) (_ : ¬Nil (f w)))) a ha = (fun w hw => Dart.edge (firstDart (f w) (_ : ¬Nil (f w)))) b hb → length (f a) ≤ length (f b) → a = b h' : ¬length (f a) ≤ length (f b) ⊢ a = b [PROOFSTEP] exact Eq.symm (this _ _ hb ha h.symm (le_of_not_le h')) [GOAL] V : Type u G : SimpleGraph V inst✝¹ : Fintype V inst✝ : Fintype ↑(edgeSet G) hG : IsTree G this✝ : Nonempty V inhabited_h : Inhabited V this : Finset.card {default}ᶜ + 1 = Fintype.card V f : (x : V) → Walk G x default hf : ∀ (x : V), (fun p => IsPath p) (f x) hf' : ∀ (x : V) (y : Walk G x default), (fun p => IsPath p) y → y = f x a b : V ha : a ∈ {default}ᶜ hb : b ∈ {default}ᶜ h : (fun w hw => Dart.edge (firstDart (f w) (_ : ¬Nil (f w)))) a ha = (fun w hw => Dart.edge (firstDart (f w) (_ : ¬Nil (f w)))) b hb h' : length (f a) ≤ length (f b) ⊢ a = b [PROOFSTEP] rw [dart_edge_eq_iff] at h [GOAL] V : Type u G : SimpleGraph V inst✝¹ : Fintype V inst✝ : Fintype ↑(edgeSet G) hG : IsTree G this✝ : Nonempty V inhabited_h : Inhabited V this : Finset.card {default}ᶜ + 1 = Fintype.card V f : (x : V) → Walk G x default hf : ∀ (x : V), (fun p => IsPath p) (f x) hf' : ∀ (x : V) (y : Walk G x default), (fun p => IsPath p) y → y = f x a b : V ha : a ∈ {default}ᶜ hb : b ∈ {default}ᶜ h : firstDart (f a) (_ : ¬Nil (f a)) = firstDart (f b) (_ : ¬Nil (f b)) ∨ firstDart (f a) (_ : ¬Nil (f a)) = Dart.symm (firstDart (f b) (_ : ¬Nil (f b))) h' : length (f a) ≤ length (f b) ⊢ a = b [PROOFSTEP] obtain (h | h) := h [GOAL] case inl V : Type u G : SimpleGraph V inst✝¹ : Fintype V inst✝ : Fintype ↑(edgeSet G) hG : IsTree G this✝ : Nonempty V inhabited_h : Inhabited V this : Finset.card {default}ᶜ + 1 = Fintype.card V f : (x : V) → Walk G x default hf : ∀ (x : V), (fun p => IsPath p) (f x) hf' : ∀ (x : V) (y : Walk G x default), (fun p => IsPath p) y → y = f x a b : V ha : a ∈ {default}ᶜ hb : b ∈ {default}ᶜ h' : length (f a) ≤ length (f b) h : firstDart (f a) (_ : ¬Nil (f a)) = firstDart (f b) (_ : ¬Nil (f b)) ⊢ a = b [PROOFSTEP] exact (congrArg (·.fst) h) [GOAL] case inr V : Type u G : SimpleGraph V inst✝¹ : Fintype V inst✝ : Fintype ↑(edgeSet G) hG : IsTree G this✝ : Nonempty V inhabited_h : Inhabited V this : Finset.card {default}ᶜ + 1 = Fintype.card V f : (x : V) → Walk G x default hf : ∀ (x : V), (fun p => IsPath p) (f x) hf' : ∀ (x : V) (y : Walk G x default), (fun p => IsPath p) y → y = f x a b : V ha : a ∈ {default}ᶜ hb : b ∈ {default}ᶜ h' : length (f a) ≤ length (f b) h : firstDart (f a) (_ : ¬Nil (f a)) = Dart.symm (firstDart (f b) (_ : ¬Nil (f b))) ⊢ a = b [PROOFSTEP] have h1 : ((f a).firstDart <| not_nil_of_ne (by simpa using ha)).snd = b := congrArg (·.snd) h [GOAL] V : Type u G : SimpleGraph V inst✝¹ : Fintype V inst✝ : Fintype ↑(edgeSet G) hG : IsTree G this✝ : Nonempty V inhabited_h : Inhabited V this : Finset.card {default}ᶜ + 1 = Fintype.card V f : (x : V) → Walk G x default hf : ∀ (x : V), (fun p => IsPath p) (f x) hf' : ∀ (x : V) (y : Walk G x default), (fun p => IsPath p) y → y = f x a b : V ha : a ∈ {default}ᶜ hb : b ∈ {default}ᶜ h' : length (f a) ≤ length (f b) h : firstDart (f a) (_ : ¬Nil (f a)) = Dart.symm (firstDart (f b) (_ : ¬Nil (f b))) ⊢ a ≠ default [PROOFSTEP] simpa using ha [GOAL] case inr V : Type u G : SimpleGraph V inst✝¹ : Fintype V inst✝ : Fintype ↑(edgeSet G) hG : IsTree G this✝ : Nonempty V inhabited_h : Inhabited V this : Finset.card {default}ᶜ + 1 = Fintype.card V f : (x : V) → Walk G x default hf : ∀ (x : V), (fun p => IsPath p) (f x) hf' : ∀ (x : V) (y : Walk G x default), (fun p => IsPath p) y → y = f x a b : V ha : a ∈ {default}ᶜ hb : b ∈ {default}ᶜ h' : length (f a) ≤ length (f b) h : firstDart (f a) (_ : ¬Nil (f a)) = Dart.symm (firstDart (f b) (_ : ¬Nil (f b))) h1 : (firstDart (f a) (_ : ¬Nil (f a))).toProd.snd = b ⊢ a = b [PROOFSTEP] have h3 := congrArg length (hf' _ (((f _).tail _).copy h1 rfl) ?_) [GOAL] case inr.refine_2 V : Type u G : SimpleGraph V inst✝¹ : Fintype V inst✝ : Fintype ↑(edgeSet G) hG : IsTree G this✝ : Nonempty V inhabited_h : Inhabited V this : Finset.card {default}ᶜ + 1 = Fintype.card V f : (x : V) → Walk G x default hf : ∀ (x : V), (fun p => IsPath p) (f x) hf' : ∀ (x : V) (y : Walk G x default), (fun p => IsPath p) y → y = f x a b : V ha : a ∈ {default}ᶜ hb : b ∈ {default}ᶜ h' : length (f a) ≤ length (f b) h : firstDart (f a) (_ : ¬Nil (f a)) = Dart.symm (firstDart (f b) (_ : ¬Nil (f b))) h1 : (firstDart (f a) (_ : ¬Nil (f a))).toProd.snd = b h3 : length (Walk.copy (tail (f a) (_ : ¬Nil (f a))) h1 (_ : default = default)) = length (f b) ⊢ a = b case inr.refine_1 V : Type u G : SimpleGraph V inst✝¹ : Fintype V inst✝ : Fintype ↑(edgeSet G) hG : IsTree G this✝ : Nonempty V inhabited_h : Inhabited V this : Finset.card {default}ᶜ + 1 = Fintype.card V f : (x : V) → Walk G x default hf : ∀ (x : V), (fun p => IsPath p) (f x) hf' : ∀ (x : V) (y : Walk G x default), (fun p => IsPath p) y → y = f x a b : V ha : a ∈ {default}ᶜ hb : b ∈ {default}ᶜ h' : length (f a) ≤ length (f b) h : firstDart (f a) (_ : ¬Nil (f a)) = Dart.symm (firstDart (f b) (_ : ¬Nil (f b))) h1 : (firstDart (f a) (_ : ¬Nil (f a))).toProd.snd = b ⊢ (fun p => IsPath p) (Walk.copy (tail (f a) (_ : ¬Nil (f a))) h1 (_ : default = default)) [PROOFSTEP] rw [length_copy, ← add_left_inj 1, length_tail_add_one] at h3 [GOAL] case inr.refine_2 V : Type u G : SimpleGraph V inst✝¹ : Fintype V inst✝ : Fintype ↑(edgeSet G) hG : IsTree G this✝ : Nonempty V inhabited_h : Inhabited V this : Finset.card {default}ᶜ + 1 = Fintype.card V f : (x : V) → Walk G x default hf : ∀ (x : V), (fun p => IsPath p) (f x) hf' : ∀ (x : V) (y : Walk G x default), (fun p => IsPath p) y → y = f x a b : V ha : a ∈ {default}ᶜ hb : b ∈ {default}ᶜ h' : length (f a) ≤ length (f b) h : firstDart (f a) (_ : ¬Nil (f a)) = Dart.symm (firstDart (f b) (_ : ¬Nil (f b))) h1 : (firstDart (f a) (_ : ¬Nil (f a))).toProd.snd = b h3✝ : length (tail (f a) (_ : ¬Nil (f a))) = length (f b) h3 : length (f a) = length (f b) + 1 ⊢ a = b [PROOFSTEP] exfalso [GOAL] case inr.refine_2.h V : Type u G : SimpleGraph V inst✝¹ : Fintype V inst✝ : Fintype ↑(edgeSet G) hG : IsTree G this✝ : Nonempty V inhabited_h : Inhabited V this : Finset.card {default}ᶜ + 1 = Fintype.card V f : (x : V) → Walk G x default hf : ∀ (x : V), (fun p => IsPath p) (f x) hf' : ∀ (x : V) (y : Walk G x default), (fun p => IsPath p) y → y = f x a b : V ha : a ∈ {default}ᶜ hb : b ∈ {default}ᶜ h' : length (f a) ≤ length (f b) h : firstDart (f a) (_ : ¬Nil (f a)) = Dart.symm (firstDart (f b) (_ : ¬Nil (f b))) h1 : (firstDart (f a) (_ : ¬Nil (f a))).toProd.snd = b h3✝ : length (tail (f a) (_ : ¬Nil (f a))) = length (f b) h3 : length (f a) = length (f b) + 1 ⊢ False [PROOFSTEP] linarith [GOAL] case inr.refine_1 V : Type u G : SimpleGraph V inst✝¹ : Fintype V inst✝ : Fintype ↑(edgeSet G) hG : IsTree G this✝ : Nonempty V inhabited_h : Inhabited V this : Finset.card {default}ᶜ + 1 = Fintype.card V f : (x : V) → Walk G x default hf : ∀ (x : V), (fun p => IsPath p) (f x) hf' : ∀ (x : V) (y : Walk G x default), (fun p => IsPath p) y → y = f x a b : V ha : a ∈ {default}ᶜ hb : b ∈ {default}ᶜ h' : length (f a) ≤ length (f b) h : firstDart (f a) (_ : ¬Nil (f a)) = Dart.symm (firstDart (f b) (_ : ¬Nil (f b))) h1 : (firstDart (f a) (_ : ¬Nil (f a))).toProd.snd = b ⊢ (fun p => IsPath p) (Walk.copy (tail (f a) (_ : ¬Nil (f a))) h1 (_ : default = default)) [PROOFSTEP] simp only [ne_eq, eq_mp_eq_cast, id_eq, isPath_copy] [GOAL] case inr.refine_1 V : Type u G : SimpleGraph V inst✝¹ : Fintype V inst✝ : Fintype ↑(edgeSet G) hG : IsTree G this✝ : Nonempty V inhabited_h : Inhabited V this : Finset.card {default}ᶜ + 1 = Fintype.card V f : (x : V) → Walk G x default hf : ∀ (x : V), (fun p => IsPath p) (f x) hf' : ∀ (x : V) (y : Walk G x default), (fun p => IsPath p) y → y = f x a b : V ha : a ∈ {default}ᶜ hb : b ∈ {default}ᶜ h' : length (f a) ≤ length (f b) h : firstDart (f a) (_ : ¬Nil (f a)) = Dart.symm (firstDart (f b) (_ : ¬Nil (f b))) h1 : (firstDart (f a) (_ : ¬Nil (f a))).toProd.snd = b ⊢ IsPath (tail (f a) (_ : ¬Nil (f a))) [PROOFSTEP] exact (hf _).tail _ [GOAL] case surj V : Type u G : SimpleGraph V inst✝¹ : Fintype V inst✝ : Fintype ↑(edgeSet G) hG : IsTree G this✝ : Nonempty V inhabited_h : Inhabited V this : Finset.card {default}ᶜ + 1 = Fintype.card V f : (x : V) → Walk G x default hf : ∀ (x : V), (fun p => IsPath p) (f x) hf' : ∀ (x : V) (y : Walk G x default), (fun p => IsPath p) y → y = f x ⊢ ∀ (b : Sym2 V), b ∈ edgeFinset G → ∃ a ha, (fun w hw => Dart.edge (firstDart (f w) (_ : ¬Nil (f w)))) a ha = b [PROOFSTEP] case surj => simp only [mem_edgeFinset, Finset.mem_compl, Finset.mem_singleton, Sym2.forall, mem_edgeSet] intros x y h wlog h' : (f x).length ≤ (f y).length generalizing x y · rw [Sym2.eq_swap] exact this y x h.symm (le_of_not_le h') refine ⟨y, ?_, dart_edge_eq_mk'_iff.2 <| Or.inr ?_⟩ · rintro rfl rw [← hf' _ nil IsPath.nil, length_nil, ← hf' _ (.cons h .nil) (IsPath.nil.cons <| by simpa using h.ne), length_cons, length_nil] at h' simp [le_zero_iff, Nat.one_ne_zero] at h' rw [← hf' _ (.cons h.symm (f x)) ((cons_isPath_iff _ _).2 ⟨hf _, fun hy => ?contra⟩)] rfl case contra => suffices : (f x).takeUntil y hy = .cons h .nil · rw [← take_spec _ hy] at h' simp [this, hf' _ _ ((hf _).dropUntil hy)] at h' refine (hG.existsUnique_path _ _).unique ((hf _).takeUntil _) ?_ simp [h.ne] [GOAL] V : Type u G : SimpleGraph V inst✝¹ : Fintype V inst✝ : Fintype ↑(edgeSet G) hG : IsTree G this✝ : Nonempty V inhabited_h : Inhabited V this : Finset.card {default}ᶜ + 1 = Fintype.card V f : (x : V) → Walk G x default hf : ∀ (x : V), (fun p => IsPath p) (f x) hf' : ∀ (x : V) (y : Walk G x default), (fun p => IsPath p) y → y = f x ⊢ ∀ (b : Sym2 V), b ∈ edgeFinset G → ∃ a ha, (fun w hw => Dart.edge (firstDart (f w) (_ : ¬Nil (f w)))) a ha = b [PROOFSTEP] case surj => simp only [mem_edgeFinset, Finset.mem_compl, Finset.mem_singleton, Sym2.forall, mem_edgeSet] intros x y h wlog h' : (f x).length ≤ (f y).length generalizing x y · rw [Sym2.eq_swap] exact this y x h.symm (le_of_not_le h') refine ⟨y, ?_, dart_edge_eq_mk'_iff.2 <| Or.inr ?_⟩ · rintro rfl rw [← hf' _ nil IsPath.nil, length_nil, ← hf' _ (.cons h .nil) (IsPath.nil.cons <| by simpa using h.ne), length_cons, length_nil] at h' simp [le_zero_iff, Nat.one_ne_zero] at h' rw [← hf' _ (.cons h.symm (f x)) ((cons_isPath_iff _ _).2 ⟨hf _, fun hy => ?contra⟩)] rfl case contra => suffices : (f x).takeUntil y hy = .cons h .nil · rw [← take_spec _ hy] at h' simp [this, hf' _ _ ((hf _).dropUntil hy)] at h' refine (hG.existsUnique_path _ _).unique ((hf _).takeUntil _) ?_ simp [h.ne] [GOAL] V : Type u G : SimpleGraph V inst✝¹ : Fintype V inst✝ : Fintype ↑(edgeSet G) hG : IsTree G this✝ : Nonempty V inhabited_h : Inhabited V this : Finset.card {default}ᶜ + 1 = Fintype.card V f : (x : V) → Walk G x default hf : ∀ (x : V), (fun p => IsPath p) (f x) hf' : ∀ (x : V) (y : Walk G x default), (fun p => IsPath p) y → y = f x ⊢ ∀ (b : Sym2 V), b ∈ edgeFinset G → ∃ a ha, (fun w hw => Dart.edge (firstDart (f w) (_ : ¬Nil (f w)))) a ha = b [PROOFSTEP] simp only [mem_edgeFinset, Finset.mem_compl, Finset.mem_singleton, Sym2.forall, mem_edgeSet] [GOAL] V : Type u G : SimpleGraph V inst✝¹ : Fintype V inst✝ : Fintype ↑(edgeSet G) hG : IsTree G this✝ : Nonempty V inhabited_h : Inhabited V this : Finset.card {default}ᶜ + 1 = Fintype.card V f : (x : V) → Walk G x default hf : ∀ (x : V), (fun p => IsPath p) (f x) hf' : ∀ (x : V) (y : Walk G x default), (fun p => IsPath p) y → y = f x ⊢ ∀ (x y : V), Adj G x y → ∃ a h, Dart.edge (firstDart (f a) (_ : ¬Nil (f a))) = Quotient.mk (Sym2.Rel.setoid V) (x, y) [PROOFSTEP] intros x y h [GOAL] V : Type u G : SimpleGraph V inst✝¹ : Fintype V inst✝ : Fintype ↑(edgeSet G) hG : IsTree G this✝ : Nonempty V inhabited_h : Inhabited V this : Finset.card {default}ᶜ + 1 = Fintype.card V f : (x : V) → Walk G x default hf : ∀ (x : V), (fun p => IsPath p) (f x) hf' : ∀ (x : V) (y : Walk G x default), (fun p => IsPath p) y → y = f x x y : V h : Adj G x y ⊢ ∃ a h, Dart.edge (firstDart (f a) (_ : ¬Nil (f a))) = Quotient.mk (Sym2.Rel.setoid V) (x, y) [PROOFSTEP] wlog h' : (f x).length ≤ (f y).length generalizing x y [GOAL] case inr V : Type u G : SimpleGraph V inst✝¹ : Fintype V inst✝ : Fintype ↑(edgeSet G) hG : IsTree G this✝¹ : Nonempty V inhabited_h : Inhabited V this✝ : Finset.card {default}ᶜ + 1 = Fintype.card V f : (x : V) → Walk G x default hf : ∀ (x : V), (fun p => IsPath p) (f x) hf' : ∀ (x : V) (y : Walk G x default), (fun p => IsPath p) y → y = f x x y : V h : Adj G x y this : ∀ (x y : V), Adj G x y → length (f x) ≤ length (f y) → ∃ a h, Dart.edge (firstDart (f a) (_ : ¬Nil (f a))) = Quotient.mk (Sym2.Rel.setoid V) (x, y) h' : ¬length (f x) ≤ length (f y) ⊢ ∃ a h, Dart.edge (firstDart (f a) (_ : ¬Nil (f a))) = Quotient.mk (Sym2.Rel.setoid V) (x, y) [PROOFSTEP] rw [Sym2.eq_swap] [GOAL] case inr V : Type u G : SimpleGraph V inst✝¹ : Fintype V inst✝ : Fintype ↑(edgeSet G) hG : IsTree G this✝¹ : Nonempty V inhabited_h : Inhabited V this✝ : Finset.card {default}ᶜ + 1 = Fintype.card V f : (x : V) → Walk G x default hf : ∀ (x : V), (fun p => IsPath p) (f x) hf' : ∀ (x : V) (y : Walk G x default), (fun p => IsPath p) y → y = f x x y : V h : Adj G x y this : ∀ (x y : V), Adj G x y → length (f x) ≤ length (f y) → ∃ a h, Dart.edge (firstDart (f a) (_ : ¬Nil (f a))) = Quotient.mk (Sym2.Rel.setoid V) (x, y) h' : ¬length (f x) ≤ length (f y) ⊢ ∃ a h, Dart.edge (firstDart (f a) (_ : ¬Nil (f a))) = Quotient.mk (Sym2.Rel.setoid V) (y, x) [PROOFSTEP] exact this y x h.symm (le_of_not_le h') [GOAL] V : Type u G : SimpleGraph V inst✝¹ : Fintype V inst✝ : Fintype ↑(edgeSet G) hG : IsTree G this✝ : Nonempty V inhabited_h : Inhabited V this : Finset.card {default}ᶜ + 1 = Fintype.card V f : (x : V) → Walk G x default hf : ∀ (x : V), (fun p => IsPath p) (f x) hf' : ∀ (x : V) (y : Walk G x default), (fun p => IsPath p) y → y = f x x y : V h : Adj G x y h' : length (f x) ≤ length (f y) ⊢ ∃ a h, Dart.edge (firstDart (f a) (_ : ¬Nil (f a))) = Quotient.mk (Sym2.Rel.setoid V) (x, y) [PROOFSTEP] refine ⟨y, ?_, dart_edge_eq_mk'_iff.2 <| Or.inr ?_⟩ [GOAL] case refine_1 V : Type u G : SimpleGraph V inst✝¹ : Fintype V inst✝ : Fintype ↑(edgeSet G) hG : IsTree G this✝ : Nonempty V inhabited_h : Inhabited V this : Finset.card {default}ᶜ + 1 = Fintype.card V f : (x : V) → Walk G x default hf : ∀ (x : V), (fun p => IsPath p) (f x) hf' : ∀ (x : V) (y : Walk G x default), (fun p => IsPath p) y → y = f x x y : V h : Adj G x y h' : length (f x) ≤ length (f y) ⊢ ¬y = default [PROOFSTEP] rintro rfl [GOAL] case refine_1 V : Type u G : SimpleGraph V inst✝¹ : Fintype V inst✝ : Fintype ↑(edgeSet G) hG : IsTree G this✝ : Nonempty V inhabited_h : Inhabited V this : Finset.card {default}ᶜ + 1 = Fintype.card V f : (x : V) → Walk G x default hf : ∀ (x : V), (fun p => IsPath p) (f x) hf' : ∀ (x : V) (y : Walk G x default), (fun p => IsPath p) y → y = f x x : V h : Adj G x default h' : length (f x) ≤ length (f default) ⊢ False [PROOFSTEP] rw [← hf' _ nil IsPath.nil, length_nil, ← hf' _ (.cons h .nil) (IsPath.nil.cons <| by simpa using h.ne), length_cons, length_nil] at h' [GOAL] V : Type u G : SimpleGraph V inst✝¹ : Fintype V inst✝ : Fintype ↑(edgeSet G) hG : IsTree G this✝ : Nonempty V inhabited_h : Inhabited V this : Finset.card {default}ᶜ + 1 = Fintype.card V f : (x : V) → Walk G x default hf : ∀ (x : V), (fun p => IsPath p) (f x) hf' : ∀ (x : V) (y : Walk G x default), (fun p => IsPath p) y → y = f x x : V h : Adj G x default h' : length (f x) ≤ 0 ⊢ ¬x ∈ Walk.support nil [PROOFSTEP] simpa using h.ne [GOAL] case refine_1 V : Type u G : SimpleGraph V inst✝¹ : Fintype V inst✝ : Fintype ↑(edgeSet G) hG : IsTree G this✝ : Nonempty V inhabited_h : Inhabited V this : Finset.card {default}ᶜ + 1 = Fintype.card V f : (x : V) → Walk G x default hf : ∀ (x : V), (fun p => IsPath p) (f x) hf' : ∀ (x : V) (y : Walk G x default), (fun p => IsPath p) y → y = f x x : V h : Adj G x default h' : 0 + 1 ≤ 0 ⊢ False [PROOFSTEP] simp [le_zero_iff, Nat.one_ne_zero] at h' [GOAL] case refine_2 V : Type u G : SimpleGraph V inst✝¹ : Fintype V inst✝ : Fintype ↑(edgeSet G) hG : IsTree G this✝ : Nonempty V inhabited_h : Inhabited V this : Finset.card {default}ᶜ + 1 = Fintype.card V f : (x : V) → Walk G x default hf : ∀ (x : V), (fun p => IsPath p) (f x) hf' : ∀ (x : V) (y : Walk G x default), (fun p => IsPath p) y → y = f x x y : V h : Adj G x y h' : length (f x) ≤ length (f y) ⊢ (firstDart (f y) (_ : ¬Nil (f y))).toProd = Prod.swap (x, y) [PROOFSTEP] rw [← hf' _ (.cons h.symm (f x)) ((cons_isPath_iff _ _).2 ⟨hf _, fun hy => ?contra⟩)] [GOAL] case refine_2 V : Type u G : SimpleGraph V inst✝¹ : Fintype V inst✝ : Fintype ↑(edgeSet G) hG : IsTree G this✝ : Nonempty V inhabited_h : Inhabited V this : Finset.card {default}ᶜ + 1 = Fintype.card V f : (x : V) → Walk G x default hf : ∀ (x : V), (fun p => IsPath p) (f x) hf' : ∀ (x : V) (y : Walk G x default), (fun p => IsPath p) y → y = f x x y : V h : Adj G x y h' : length (f x) ≤ length (f y) ⊢ (firstDart (cons (_ : Adj G y x) (f x)) (_ : ¬Nil (cons (_ : Adj G y x) (f x)))).toProd = Prod.swap (x, y) case contra V : Type u G : SimpleGraph V inst✝¹ : Fintype V inst✝ : Fintype ↑(edgeSet G) hG : IsTree G this✝ : Nonempty V inhabited_h : Inhabited V this : Finset.card {default}ᶜ + 1 = Fintype.card V f : (x : V) → Walk G x default hf : ∀ (x : V), (fun p => IsPath p) (f x) hf' : ∀ (x : V) (y : Walk G x default), (fun p => IsPath p) y → y = f x x y : V h : Adj G x y h' : length (f x) ≤ length (f y) hy : y ∈ Walk.support (f x) ⊢ False [PROOFSTEP] rfl [GOAL] case contra V : Type u G : SimpleGraph V inst✝¹ : Fintype V inst✝ : Fintype ↑(edgeSet G) hG : IsTree G this✝ : Nonempty V inhabited_h : Inhabited V this : Finset.card {default}ᶜ + 1 = Fintype.card V f : (x : V) → Walk G x default hf : ∀ (x : V), (fun p => IsPath p) (f x) hf' : ∀ (x : V) (y : Walk G x default), (fun p => IsPath p) y → y = f x x y : V h : Adj G x y h' : length (f x) ≤ length (f y) hy : y ∈ Walk.support (f x) ⊢ False [PROOFSTEP] case contra => suffices : (f x).takeUntil y hy = .cons h .nil · rw [← take_spec _ hy] at h' simp [this, hf' _ _ ((hf _).dropUntil hy)] at h' refine (hG.existsUnique_path _ _).unique ((hf _).takeUntil _) ?_ simp [h.ne] [GOAL] V : Type u G : SimpleGraph V inst✝¹ : Fintype V inst✝ : Fintype ↑(edgeSet G) hG : IsTree G this✝ : Nonempty V inhabited_h : Inhabited V this : Finset.card {default}ᶜ + 1 = Fintype.card V f : (x : V) → Walk G x default hf : ∀ (x : V), (fun p => IsPath p) (f x) hf' : ∀ (x : V) (y : Walk G x default), (fun p => IsPath p) y → y = f x x y : V h : Adj G x y h' : length (f x) ≤ length (f y) hy : y ∈ Walk.support (f x) ⊢ False [PROOFSTEP] case contra => suffices : (f x).takeUntil y hy = .cons h .nil · rw [← take_spec _ hy] at h' simp [this, hf' _ _ ((hf _).dropUntil hy)] at h' refine (hG.existsUnique_path _ _).unique ((hf _).takeUntil _) ?_ simp [h.ne] [GOAL] V : Type u G : SimpleGraph V inst✝¹ : Fintype V inst✝ : Fintype ↑(edgeSet G) hG : IsTree G this✝ : Nonempty V inhabited_h : Inhabited V this : Finset.card {default}ᶜ + 1 = Fintype.card V f : (x : V) → Walk G x default hf : ∀ (x : V), (fun p => IsPath p) (f x) hf' : ∀ (x : V) (y : Walk G x default), (fun p => IsPath p) y → y = f x x y : V h : Adj G x y h' : length (f x) ≤ length (f y) hy : y ∈ Walk.support (f x) ⊢ False [PROOFSTEP] suffices : (f x).takeUntil y hy = .cons h .nil [GOAL] V : Type u G : SimpleGraph V inst✝¹ : Fintype V inst✝ : Fintype ↑(edgeSet G) hG : IsTree G this✝¹ : Nonempty V inhabited_h : Inhabited V this✝ : Finset.card {default}ᶜ + 1 = Fintype.card V f : (x : V) → Walk G x default hf : ∀ (x : V), (fun p => IsPath p) (f x) hf' : ∀ (x : V) (y : Walk G x default), (fun p => IsPath p) y → y = f x x y : V h : Adj G x y h' : length (f x) ≤ length (f y) hy : y ∈ Walk.support (f x) this : takeUntil (f x) y hy = cons h nil ⊢ False [PROOFSTEP] rw [← take_spec _ hy] at h' [GOAL] V : Type u G : SimpleGraph V inst✝¹ : Fintype V inst✝ : Fintype ↑(edgeSet G) hG : IsTree G this✝¹ : Nonempty V inhabited_h : Inhabited V this✝ : Finset.card {default}ᶜ + 1 = Fintype.card V f : (x : V) → Walk G x default hf : ∀ (x : V), (fun p => IsPath p) (f x) hf' : ∀ (x : V) (y : Walk G x default), (fun p => IsPath p) y → y = f x x y : V h : Adj G x y hy : y ∈ Walk.support (f x) h' : length (append (takeUntil (f x) y hy) (dropUntil (f x) y hy)) ≤ length (f y) this : takeUntil (f x) y hy = cons h nil ⊢ False [PROOFSTEP] simp [this, hf' _ _ ((hf _).dropUntil hy)] at h' [GOAL] case this V : Type u G : SimpleGraph V inst✝¹ : Fintype V inst✝ : Fintype ↑(edgeSet G) hG : IsTree G this✝ : Nonempty V inhabited_h : Inhabited V this : Finset.card {default}ᶜ + 1 = Fintype.card V f : (x : V) → Walk G x default hf : ∀ (x : V), (fun p => IsPath p) (f x) hf' : ∀ (x : V) (y : Walk G x default), (fun p => IsPath p) y → y = f x x y : V h : Adj G x y h' : length (f x) ≤ length (f y) hy : y ∈ Walk.support (f x) ⊢ takeUntil (f x) y hy = cons h nil [PROOFSTEP] refine (hG.existsUnique_path _ _).unique ((hf _).takeUntil _) ?_ [GOAL] case this V : Type u G : SimpleGraph V inst✝¹ : Fintype V inst✝ : Fintype ↑(edgeSet G) hG : IsTree G this✝ : Nonempty V inhabited_h : Inhabited V this : Finset.card {default}ᶜ + 1 = Fintype.card V f : (x : V) → Walk G x default hf : ∀ (x : V), (fun p => IsPath p) (f x) hf' : ∀ (x : V) (y : Walk G x default), (fun p => IsPath p) y → y = f x x y : V h : Adj G x y h' : length (f x) ≤ length (f y) hy : y ∈ Walk.support (f x) ⊢ IsPath (cons h nil) [PROOFSTEP] simp [h.ne]
Ross took over an improved team . He had recently signed three players , Milt Schmidt , Bobby Bauer and Woody Dumart , who all grew up together in Kitchener , Ontario , and had them play on the same line , soon nicknamed the Kraut Line in reference to the German heritage of all three . Along with them , Ross had acquired a new goaltender in 1938 , Frank Brimsek ; after Brimsek earned six shutouts in his first eight games , the Bruins traded away Tiny Thompson to allow Brimsek to play . With these players the Bruins finished first in the league in 1937 – 38 ; Ross was named as the second best coach in the league , selected for the end of season All @-@ Star Second Team . The next season the Bruins won 36 of 48 games , and won the Stanley Cup in the playoffs ; Ross was named to the First All @-@ Star Team as the best coach in the league for the season and the team only tied two games , which is tied for the second fewest in a season . He hired the recently retired Cooney Weiland to coach the Bruins for the 1939 – 40 NHL season . The Bruins would win the Cup again in 1941 , and tied their record of only four away losses all season . Ross once again took over as coach of the team before the 1941 – 42 season began , as Weiland became coach of the Hershey Bears of the American Hockey League , and led the team to 25 wins in 48 games , which was enough to earn third place in the league . By this time the Second World War had caused several Bruins players , including the entire Kraut Line and goaltender Brimsek , to enlist in their respective armed forces . The Bruins finished second in the NHL during the 1942 – 43 season with 24 wins in 50 games and Ross was again named in the Second NHL All @-@ Star Team as second best coach in the league . The Bruins missed the playoffs in 1943 – 44 , the first time in ten years they failed to qualify , but returned to the playoffs the next season , something they did for five straight years .
Require Import XR_Rabs. Require Import XR_Rmax. Require Import XR_Rcase_abs. Require Import XR_Rle_dec. Require Import XR_Rle_trans. Require Import XR_Rle_lt_trans. Require Import XR_Rlt_le_trans. Require Import XR_Ropp_le_contravar. Require Import XR_Rnot_le_lt. Local Open Scope R_scope. Lemma RmaxAbs : forall (p q:R) r, p <= q -> q <= r -> Rabs q <= Rmax (Rabs p) (Rabs r). Proof. intros x y z. intros hxy hyz. unfold Rmax. destruct (Rle_dec (Rabs x) (Rabs z)) as [ hm | hm ]. { unfold Rabs in hm ; unfold Rabs. destruct (Rcase_abs x) as [ hx | hx ] ; destruct (Rcase_abs y) as [ hy | hy ] ; destruct (Rcase_abs z) as [ hz | hz ]. { apply Rle_trans with (-x). { apply Ropp_le_contravar. exact hxy. } { exact hm. } } { apply Rle_trans with (-x). { apply Ropp_le_contravar. exact hxy. } { exact hm. } } { exfalso. apply Rlt_irrefl with R0. { apply Rle_lt_trans with z. { apply Rle_trans with y. { exact hy. } { exact hyz. } } { exact hz. } } } { exact hyz. } { exfalso. apply Rlt_irrefl with R0. apply Rle_lt_trans with y. { apply Rle_trans with x. { exact hx. } { exact hxy. } } { exact hy. } } { exfalso. apply Rlt_irrefl with R0. apply Rle_lt_trans with y. { apply Rle_trans with x. { exact hx. } { exact hxy. } } { exact hy. } } { exfalso. apply Rlt_irrefl with R0. apply Rle_lt_trans with z. { apply Rle_trans with y. { exact hy. } { exact hyz. } } { exact hz. } } { exact hyz. } } { unfold Rabs in hm ; unfold Rabs. destruct (Rcase_abs x) as [ hx | hx ] ; destruct (Rcase_abs y) as [ hy | hy ] ; destruct (Rcase_abs z) as [ hz | hz ]. { apply Ropp_le_contravar. exact hxy. } { apply Ropp_le_contravar. exact hxy. } { exfalso. apply Rlt_irrefl with R0. apply Rle_lt_trans with z. { apply Rle_trans with y. { exact hy. } { exact hyz. } } { exact hz. } } { assert (hzx : z < -x). { apply Rnot_le_lt. exact hm. } apply Rle_trans with z. { exact hyz. } { left. exact hzx. } } { exfalso. apply Rlt_irrefl with R0. apply Rle_lt_trans with y. { apply Rle_trans with x. { exact hx. } { exact hxy. } } { exact hy. } } { exfalso. apply Rlt_irrefl with R0. apply Rle_lt_trans with y. { apply Rle_trans with x. { exact hx. } { exact hxy. } } { exact hy. } } { exfalso. apply Rlt_irrefl with R0. apply Rle_lt_trans with z. { apply Rle_trans with y. { exact hy. } { exact hyz. } } { exact hz. } } { assert (hzx : z < x). { apply Rnot_le_lt. exact hm. } exfalso. apply Rlt_irrefl with z. apply Rlt_le_trans with x. { exact hzx. } { apply Rle_trans with y. { exact hxy. } { exact hyz. } } } } Qed.
Fail Definition my_f_equal {A B : Type} (f : A -> B) (a a' : A) (p : a = a') : f a = f a' := eq_ind _ _ (fun a' => f a = f a') _ _ p.
Formal statement is: lemma infdist_Un_min: assumes "A \<noteq> {}" "B \<noteq> {}" shows "infdist x (A \<union> B) = min (infdist x A) (infdist x B)" Informal statement is: If $A$ and $B$ are nonempty sets, then the infimum of the distance from $x$ to $A \cup B$ is the minimum of the infimum of the distance from $x$ to $A$ and the infimum of the distance from $x$ to $B$.
module f90deviceio interface subroutine f90print(N) character(*) :: N !$omp declare target (f90print) end subroutine f90print subroutine f90printi(N,i) character(*) :: N integer :: i !$omp declare target (f90printi) end subroutine f90printi subroutine f90printf(N,f) character(*) :: N real(4) :: f !$omp declare target (f90printf) end subroutine f90printf subroutine f90printd(N,d) character(*) :: N real(8) :: d !$omp declare target (f90printd) end subroutine f90printd end interface end module
[GOAL] m n k : ℕ ⊢ choose (m + n) k = ∑ ij in antidiagonal k, choose m ij.fst * choose n ij.snd [PROOFSTEP] calc (m + n).choose k = ((X + 1) ^ (m + n)).coeff k := by rw [coeff_X_add_one_pow, Nat.cast_id] _ = ((X + 1) ^ m * (X + 1) ^ n).coeff k := by rw [pow_add] _ = ∑ ij : ℕ × ℕ in antidiagonal k, m.choose ij.1 * n.choose ij.2 := by rw [coeff_mul, Finset.sum_congr rfl] simp only [coeff_X_add_one_pow, Nat.cast_id, eq_self_iff_true, imp_true_iff] [GOAL] m n k : ℕ ⊢ choose (m + n) k = coeff ((X + 1) ^ (m + n)) k [PROOFSTEP] rw [coeff_X_add_one_pow, Nat.cast_id] [GOAL] m n k : ℕ ⊢ coeff ((X + 1) ^ (m + n)) k = coeff ((X + 1) ^ m * (X + 1) ^ n) k [PROOFSTEP] rw [pow_add] [GOAL] m n k : ℕ ⊢ coeff ((X + 1) ^ m * (X + 1) ^ n) k = ∑ ij in antidiagonal k, choose m ij.fst * choose n ij.snd [PROOFSTEP] rw [coeff_mul, Finset.sum_congr rfl] [GOAL] m n k : ℕ ⊢ ∀ (x : ℕ × ℕ), x ∈ antidiagonal k → coeff ((X + 1) ^ m) x.fst * coeff ((X + 1) ^ n) x.snd = choose m x.fst * choose n x.snd [PROOFSTEP] simp only [coeff_X_add_one_pow, Nat.cast_id, eq_self_iff_true, imp_true_iff]
/- Copyright (c) 2022 Moritz Doll. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Moritz Doll -/ import analysis.special_functions.integrals import analysis.special_functions.pow import measure_theory.integral.integral_eq_improper import measure_theory.integral.layercake import tactic.positivity /-! # Japanese Bracket In this file, we show that Japanese bracket $(1 + \|x\|^2)^{1/2}$ can be estimated from above and below by $1 + \|x\|$. The functions $(1 + \|x\|^2)^{-r/2}$ and $(1 + |x|)^{-r}$ are integrable provided that `r` is larger than the dimension. ## Main statements * `integrable_one_add_norm`: the function $(1 + |x|)^{-r}$ is integrable * `integrable_jap` the Japanese bracket is integrable -/ noncomputable theory open_locale big_operators nnreal filter topological_space ennreal open asymptotics filter set real measure_theory finite_dimensional variables {E : Type*} [normed_add_comm_group E] lemma sqrt_one_add_norm_sq_le (x : E) : real.sqrt (1 + ∥x∥^2) ≤ 1 + ∥x∥ := sorry lemma one_add_norm_le_sqrt_two_mul_sqrt (x : E) : 1 + ∥x∥ ≤ (real.sqrt 2) * sqrt (1 + ∥x∥^2) := sorry lemma rpow_neg_one_add_norm_sq_le {r : ℝ} (x : E) (hr : 0 < r) : (1 + ∥x∥^2)^(-r/2) ≤ 2^(r/2) * (1 + ∥x∥)^(-r) := sorry lemma le_rpow_one_add_norm_iff_norm_le {r t : ℝ} (hr : 0 < r) (ht : 0 < t) (x : E) : t ≤ (1 + ∥x∥) ^ -r ↔ ∥x∥ ≤ t ^ -r⁻¹ - 1 := sorry variables (E) lemma closed_ball_rpow_sub_one_eq_empty_aux {r t : ℝ} (hr : 0 < r) (ht : 1 < t) : metric.closed_ball (0 : E) (t^(-r⁻¹) - 1) = ∅ := sorry variables [normed_space ℝ E] [finite_dimensional ℝ E] variables {E} lemma finite_integral_rpow_sub_one_pow_aux {r : ℝ} (n : ℕ) (hnr : (n : ℝ) < r) : ∫⁻ (x : ℝ) in Ioc 0 1, ennreal.of_real ((x ^ -r⁻¹ - 1) ^ n) < ∞ := sorry lemma finite_integral_one_add_norm [measure_space E] [borel_space E] [(@volume E _).is_add_haar_measure] {r : ℝ} (hnr : (finrank ℝ E : ℝ) < r) : ∫⁻ (x : E), ennreal.of_real ((1 + ∥x∥) ^ -r) < ∞ := sorry lemma integrable_rpow_neg_one_add_norm [measure_space E] [borel_space E] [(@volume E _).is_add_haar_measure] {r : ℝ} (hnr : (finrank ℝ E : ℝ) < r) : integrable (λ (x : E), (1 + ∥x∥) ^ -r) := sorry lemma mem_ℒp_rpow_neg_one_add_norm [measure_space E] [borel_space E] [(@volume E _).is_add_haar_measure] {r : ℝ} (hnr : (finrank ℝ E : ℝ) < r) : mem_ℒp (λ (x : E), (1 + ∥x∥) ^ -r) 1 := begin rw mem_ℒp_one_iff_integrable, exact integrable_rpow_neg_one_add_norm hnr, end lemma integrable_rpow_neg_one_add_norm_sq [measure_space E] [borel_space E] [(@volume E _).is_add_haar_measure] {r : ℝ} (hnr : (finrank ℝ E : ℝ) < r) : integrable (λ (x : E), (1 + ∥x∥^2) ^ (-r/2)) := sorry lemma mem_ℒp_rpow_neg_one_add_norm_sq [measure_space E] [borel_space E] [(@volume E _).is_add_haar_measure] {r : ℝ} (hnr : (finrank ℝ E : ℝ) < r) : mem_ℒp (λ (x : E), (1 + ∥x∥^2) ^ (-r/2)) 1 := begin rw mem_ℒp_one_iff_integrable, exact integrable_rpow_neg_one_add_norm_sq hnr, end
{-# LANGUAGE BangPatterns #-} module Data.Benchmarks.UnorderedCollections.Distributions ( makeRandomData , makeRandomVariateData -- * Workloads , insertWorkload , deleteWorkload , uniformLookupWorkload , exponentialLookupWorkload , loadOnly , loadAndUniformLookup , loadAndSkewedLookup , loadAndDeleteAll , loadAndDeleteSome , uniformlyMixed ) where import qualified Control.Concurrent.Thread as Th import Control.DeepSeq import Control.Monad import Control.Monad.Reader import Control.Monad.Trans (liftIO) import Data.Benchmarks.UnorderedCollections.Types import qualified Data.Vector as V import qualified Data.Vector.Mutable as MV import qualified Data.Vector.Unboxed as VU import Data.Vector (Vector) import qualified Data.Vector.Algorithms.Shuffle as V import GHC.Conc (numCapabilities) import Statistics.Distribution import Statistics.Distribution.Exponential import System.Random.MWC import Criterion.Collection.Types ------------------------------------------------------------------------------ debug :: (MonadIO m) => String -> m () debug s = liftIO $ putStrLn s ------------------------------------------------------------------------------ makeRandomData :: (NFData k) => (GenIO -> IO k) -> Int -> WorkloadMonad (Vector (k,Int)) makeRandomData !genFunc !n = do rng <- getRNG debug $ "making " ++ show n ++ " data items" keys <- liftIO $ vreplicateM n rng genFunc let !v = keys `V.zip` vals let !_ = forceVector v debug $ "made " ++ show n ++ " data items" return $! v where vals = V.enumFromN 0 n ------------------------------------------------------------------------------ makeRandomVariateData :: (Ord k, NFData k, Variate k) => Int -> WorkloadMonad (Vector (k,Int)) makeRandomVariateData = makeRandomData uniform ------------------------------------------------------------------------------ insertWorkload :: (NFData k) => Vector (k,Int) -> Vector (Operation k) insertWorkload = mapForce $ \(k,v) -> Insert k v ------------------------------------------------------------------------------ deleteWorkload :: (NFData k) => Vector (k,Int) -> Vector (Operation k) deleteWorkload = mapForce $ \(k,_) -> Delete k ------------------------------------------------------------------------------ uniformLookupWorkload :: (NFData k) => Vector (k,Int) -> Int -> WorkloadMonad (Vector (Operation k)) uniformLookupWorkload !vec !ntimes = do rng <- getRNG debug $ "uniformLookupWorkload: generating " ++ show ntimes ++ " lookups" v <- liftIO $ vreplicateM ntimes rng f debug $ "uniformLookupWorkload: done" return v where !n = V.length vec f r = do idx <- pick let (k,_) = V.unsafeIndex vec idx return $ Lookup k where pick = uniformR (0,n-1) r ------------------------------------------------------------------------------ exponentialLookupWorkload :: (NFData k) => Double -> Vector (k,Int) -> Int -> WorkloadMonad (Vector (Operation k)) exponentialLookupWorkload !lambda !vec !ntimes = do rng <- getRNG liftIO $ vreplicateM ntimes rng f where !dist = exponential lambda !n = V.length vec !n1 = n-1 !nd = fromIntegral n f r = do x <- uniformR (0.1, 7.0) r let idx = max 0 . min n1 . round $ nd * density dist x let (k,_) = V.unsafeIndex vec idx return $! Lookup k ------------------------------------------------------------------------------ loadOnly :: (NFData k) => (GenIO -> IO k) -- ^ rng for keys -> WorkloadGenerator (Operation k) loadOnly !genFunc !n = return $ Workload V.empty f where f _ = liftM insertWorkload $ makeRandomData genFunc n ------------------------------------------------------------------------------ loadAndUniformLookup :: (NFData k) => (GenIO -> IO k) -- ^ rng for keys -> WorkloadGenerator (Operation k) loadAndUniformLookup !genFunc !n = do !vals <- makeRandomData genFunc n let !inserts = insertWorkload vals return $! Workload inserts $ uniformLookupWorkload vals ------------------------------------------------------------------------------ loadAndSkewedLookup :: (NFData k) => (GenIO -> IO k) -- ^ rng for keys -> WorkloadGenerator (Operation k) loadAndSkewedLookup !genFunc !n = do !vals <- makeRandomData genFunc n let !inserts = insertWorkload vals return $! Workload inserts $ exponentialLookupWorkload 1.5 vals ------------------------------------------------------------------------------ loadAndDeleteAll :: (NFData k) => (GenIO -> IO k) -- ^ key generator -> WorkloadGenerator (Operation k) loadAndDeleteAll !genFunc !n = do rng <- getRNG !vals <- makeRandomData genFunc n let !inserts = insertWorkload vals let !deletes = deleteWorkload $ V.shuffle rng vals return $ Workload inserts (const $ return deletes) ------------------------------------------------------------------------------ loadAndDeleteSome :: (NFData k) => (GenIO -> IO k) -> WorkloadGenerator (Operation k) loadAndDeleteSome !genFunc !n = do !vals <- makeRandomData genFunc n let !inserts = insertWorkload vals return $ Workload inserts $ f vals where f vals k = do rng <- getRNG return $ deleteWorkload $ V.take k $ V.shuffle rng vals ------------------------------------------------------------------------------ uniformlyMixed :: (NFData k) => (GenIO -> IO k) -> Double -> Double -> WorkloadGenerator (Operation k) uniformlyMixed !genFunc !lookupPercentage !deletePercentage !n = do let !numLookups = ceiling (fromIntegral n * lookupPercentage) let !numDeletes = ceiling (fromIntegral n * deletePercentage) !vals <- makeRandomData genFunc n let !inserts = insertWorkload vals !lookups <- uniformLookupWorkload vals numLookups rng <- getRNG let !deletes = deleteWorkload $ V.take numDeletes $ V.shuffle rng vals let !out = V.shuffle rng $ V.concat [inserts, lookups, deletes] return $! Workload V.empty $ const $ return $ forceVector out ------------------------------------------------------------------------------ -- utilities ------------------------------------------------------------------------------ forceVector :: (NFData k) => Vector k -> Vector k forceVector !vec = V.foldl' force () vec `seq` vec where force x v = x `deepseq` v `deepseq` () mapForce :: (NFData b) => (a -> b) -> Vector a -> Vector b mapForce !f !vIn = let !vOut = V.map f vIn in forceVector vOut -- split a GenIO splitGenIO :: GenIO -> IO GenIO splitGenIO rng = VU.replicateM 256 (uniform rng) >>= initialize -- vector replicateM is slow as dogshit. vreplicateM :: Int -> GenIO -> (GenIO -> IO a) -> IO (Vector a) vreplicateM n origRng act = do rngs <- replicateM numCapabilities (splitGenIO origRng) mv <- MV.new n let actions = map (f mv) (parts `zip` rngs) results <- liftM (map snd) $ mapM Th.forkIO actions _ <- sequence results V.unsafeFreeze mv where parts = partition (n-1) numCapabilities f mv ((low,high),rng) = do f' low where f' !idx | idx > high = return () | otherwise = do x <- act rng MV.unsafeWrite mv idx x f' (idx+1) partition :: Int -> Int -> [(Int,Int)] partition n k = ys `zip` xs where xs = map f [1..k] ys = 0:(map (+1) xs) f i = (i * n) `div` k
import data.real.basic namespace challenges -- basic definitions def upper_bounds (S : set ℝ) : set ℝ := { b | ∀s ∈ S, s ≤ b } def lower_bounds (S : set ℝ) : set ℝ := { b | ∀s ∈ S, b ≤ s } def is_least (S : set ℝ) (l : ℝ) : Prop := l ∈ S ∧ l ∈ lower_bounds S def is_lub (S : set ℝ) (l : ℝ) : Prop := is_least (upper_bounds S) l /-- A set has at most one least upper bound -/ theorem challenge2 (S : set ℝ) (a b : ℝ) (ha : is_lub S a) (hb : is_lub S b) : a = b := begin -- One can unfold the definition of is_lub to find out what `ha` actually says: unfold is_lub at ha, -- one can now unfold the definition of `is_least`: unfold is_least at ha, -- We discover that `ha` is (by definition) a proof of `P ∧ Q`, with -- P := a ∈ upper_bounds S and Q := a ∈ lower_bounds (upper_bounds S). -- So we can do cases on this. cases ha with ha1 ha2, -- We didn't have to do any of that unfolding though. cases hb with hb1 hb2, -- le_antisymm is the proof that a ≤ b and b ≤ a implies a = b. apply le_antisymm, -- Now we have two goals. { -- a ≤ b follows because a is a lower bound for the upper bounds... apply ha2, -- ... and b is an upper bound. assumption}, { -- Similarly b is a lower bound for the upper bounds apply hb2, -- and a is an upper bound. assumption}, end -- Ideas below are by Patrick Massot. -- another approach with WLOG theorem challenge2' (S : set ℝ) (a b : ℝ) (ha : is_lub S a) (hb : is_lub S b) : a = b := begin wlog h : a ≤ b, apply le_antisymm h, apply hb.right, exact ha.left, end -- term mode proof (just write the function directly) theorem challenge2'' (S : set ℝ) (a b : ℝ) (ha : is_lub S a) (hb : is_lub S b) : a = b := le_antisymm (ha.2 _ hb.1) (hb.2 _ ha.1) -- a one-tactic tactic mode proof can be prefixed by `by` instead of begin/end theorem challenge2''' (S : set ℝ) (a b : ℝ) (ha : is_lub S a) (hb : is_lub S b) : a = b := by linarith [hb.2 _ ha.1, ha.2 _ hb.1] -- a two-tactic tactic mode proof can be made into one tactic with { } theorem challenge2'''' (S : set ℝ) (a b : ℝ) (ha : is_lub S a) (hb : is_lub S b) : a = b := by { wlog h: a ≤ b, linarith [hb.2 _ ha.1] } end challenges
"""Platform for Husqvarna Automower camera integration.""" import logging import io import math import numpy as np from PIL import Image, ImageDraw from typing import Optional from homeassistant.config_entries import ConfigEntry from homeassistant.core import HomeAssistant from homeassistant.helpers.entity_platform import AddEntitiesCallback from homeassistant.components.camera import Camera, SUPPORT_ON_OFF from .entity import AutomowerEntity from .vacuum import HusqvarnaAutomowerStateMixin from .const import ( DOMAIN, ENABLE_CAMERA, GPS_TOP_LEFT, GPS_BOTTOM_RIGHT, MOWER_IMG_PATH, MAP_IMG_PATH, ) GpsPoint = tuple[float, float] ImgPoint = tuple[int, int] ImgDimensions = tuple[int, int] _LOGGER = logging.getLogger(__name__) async def async_setup_entry( hass: HomeAssistant, entry: ConfigEntry, async_add_entities: AddEntitiesCallback ) -> None: """Setup select platform.""" session = hass.data[DOMAIN][entry.entry_id] async_add_entities( AutomowerCamera(session, idx, entry) for idx, ent in enumerate(session.data["data"]) ) class AutomowerCamera(HusqvarnaAutomowerStateMixin, Camera, AutomowerEntity): _attr_entity_registry_enabled_default = False _attr_frame_interval: float = 300 def __init__(self, session, idx, entry): Camera.__init__(self) AutomowerEntity.__init__(self, session, idx) self.entry = entry self._position_history = [] self._attr_name = self.mower_name self._attr_unique_id = f"{self.mower_id}_camera" self._image = Image.new(mode="RGB", size=(200, 200)) self._image_bytes = None self._image_to_bytes() self.session = session if self.entry.options.get(ENABLE_CAMERA, False): self.top_left_coord = self.entry.options.get(GPS_TOP_LEFT) self.bottom_right_coord = self.entry.options.get(GPS_BOTTOM_RIGHT) self.session.register_data_callback( lambda data: self._generate_image(data), schedule_immediately=True ) else: self._attr_entity_registry_enabled_default = True r_earth = 6378000 # meters offset = 100 # meters pi = 3.14 lat = AutomowerEntity.get_mower_attributes(self)["positions"][0]["latitude"] lon = AutomowerEntity.get_mower_attributes(self)["positions"][0][ "longitude" ] top_left_lat = lat - (offset / r_earth) * (180 / pi) top_left_lon = lon - (offset / r_earth) * (180 / pi) / math.cos( lat * pi / 180 ) bottom_right_lat = lat + (offset / r_earth) * (180 / pi) bottom_right_lon = lon + (offset / r_earth) * (180 / pi) / math.cos( lat * pi / 180 ) self.top_left_coord = (top_left_lat, top_left_lon) self.bottom_right_coord = (bottom_right_lat, bottom_right_lon) def model(self) -> str: """Return the mower model.""" return self.model async def async_camera_image( self, width: Optional[int] = None, height: Optional[int] = None ) -> Optional[bytes]: return self._image_bytes def _image_to_bytes(self): img_byte_arr = io.BytesIO() self._image.save(img_byte_arr, format="PNG") self._image_bytes = img_byte_arr.getvalue() def turn_on(self): self.session.register_data_callback( lambda data: self._generate_image(data), schedule_immediately=True ) def turn_off(self): self.session.unregister_data_callback(lambda data: self._generate_image(data)) @property def supported_features(self) -> int: return SUPPORT_ON_OFF def _generate_image(self, data: dict): position_history = AutomowerEntity.get_mower_attributes(self)["positions"] location = (position_history[0]["latitude"], position_history[0]["longitude"]) if len(position_history) == 1: self._position_history += position_history position_history = self._position_history else: self._position_history = position_history map_image_path = self.entry.options.get(MAP_IMG_PATH) map_image = Image.open(map_image_path, "r") overlay_path = self.entry.options.get(MOWER_IMG_PATH) overlay_image = Image.open(overlay_path, "r") x1, y1 = self._scale_to_img(location, (map_image.size[0], map_image.size[1])) img_draw = ImageDraw.Draw(map_image) for i in range(len(position_history) - 1, 0, -1): point_1 = ( position_history[i]["latitude"], position_history[i]["longitude"], ) scaled_loc_1 = self._scale_to_img( point_1, (map_image.size[0], map_image.size[1]) ) point_2 = ( position_history[i - 1]["latitude"], position_history[i - 1]["longitude"], ) scaled_loc_2 = self._scale_to_img( point_2, (map_image.size[0], map_image.size[1]) ) plot_points = self._find_points_on_line(scaled_loc_1, scaled_loc_2) for p in range(0, len(plot_points) - 1, 2): img_draw.line((plot_points[p], plot_points[p + 1]), fill="red", width=2) overlay_image = overlay_image.resize((64, 64)) img_w, img_h = overlay_image.size map_image.paste( overlay_image, (x1 - img_w // 2, y1 - img_h // 2), overlay_image ) self._image = map_image self._image_to_bytes() def _find_points_on_line( self, point_1: ImgPoint, point_2: ImgPoint ) -> list[ImgPoint]: dash_length = 10 line_length = math.sqrt( (point_2[0] - point_1[0]) ** 2 + (point_2[1] - point_1[1]) ** 2 ) dashes = int(line_length // dash_length) points = [] points.append(point_1) for i in range(dashes): points.append(self._get_point_on_vector(points[-1], point_2, dash_length)) points.append(point_2) return points def _get_point_on_vector( self, initial_pt: ImgPoint, terminal_pt: ImgPoint, distance: int ) -> ImgPoint: v = np.array(initial_pt, dtype=float) u = np.array(terminal_pt, dtype=float) n = v - u n /= np.linalg.norm(n, 2) point = v - distance * n return tuple(point) def _scale_to_img(self, lat_lon: GpsPoint, h_w: ImgDimensions) -> ImgPoint: """Convert from latitude and longitude to the image pixels.""" old = (self.bottom_right_coord[0], self.top_left_coord[0]) new = (0, h_w[1]) y = ((lat_lon[0] - old[0]) * (new[1] - new[0]) / (old[1] - old[0])) + new[0] old = (self.top_left_coord[1], self.bottom_right_coord[1]) new = (0, h_w[0]) x = ((lat_lon[1] - old[0]) * (new[1] - new[0]) / (old[1] - old[0])) + new[0] return int(x), h_w[1] - int(y)
We have spoken with three people, who are responsible for waste management in three types of stores, from a small grocery store to one of the biggest department stores in the world. We asked them how they tackle waste management and recycling in their businesses on a day-to-day basis. The Hemköp store in Vrigstad is the only one in the area and it has a loyal customer base. Sales amount to approximately 40 million SEK a year. As the store has grown quickly over the years, so has the volume of waste to handle. ICA Supermarket Olskroken is located in central Gothenburg. Sixty people work in the store, which turns over around 175 million SEK a year. Gekås in Ullared is one of Sweden’s most popular places to visit and is thought to be the world’s largest department store of its kind. A department store with 4.8 million customers and sales of 5.3 billion SEK a year certainly generates a lot of waste. Generally speaking, many stores seem to be quite good at compacting and recycling their waste. Awareness is increasing and consumer pressure is making a green environmental profile increasingly important. There is still a lot to do and too many stores continue to rely on a mixed waste containers for all their waste. It is time for a change if these stores are to keep up with the competition and stay attractive to their customers. Contact an expert at Orwak and we will help you improve and streamline your waste management and recycling.
/- Along with the half-finished definition of substitution here is an attempt to define terms using lists instead of vectors. The problem is, since the type "list" does ot say anything about the size of the list, it is possible to use this definition to define terms that apply a function of any arity to a list of any length. To prevent this from happening, we might be able to use an auxiliary well_formed_term definition, and prove that it is preserved after operations like substitution. However, the same well-founded recursion problem reared its head at a certain point -- here it was after writing a really long theorem about the preservation of well-formed-ness. If you wait for it to compile, you can read the error message below on mutual theorem sub_term_well_formed, sub_term_list_well_formed It was too much to think about creating a well-founded relation over these theorems; it takes about two minutes just for Lean to read through the tactics as it is.. I'm pretty sure that this approach is not any easier. -/ structure Language := language :: (relations : Type) (functions : Type ) (arityF : functions → nat) (arityR : relations → nat) variable L : Language variable n : nat universe u inductive term | var : nat → term | apply: L.functions → list term → term mutual def well_formed_term, well_formed_term_list with well_formed_term : term L -> Prop | (term.var L _) := true | (term.apply f l) := ((L.arityF f) = list.length l) ∧ (well_formed_term_list l) with well_formed_term_list : list (term L) → Prop | [] := true | (list.cons t ts) := (well_formed_term t) ∧ well_formed_term_list ts def nat_list_union : list nat → list nat → list nat | [] l := l | (list.cons n ns) l := if n ∈ l then list.cons n (nat_list_union ns l) else nat_list_union ns l def nat_list_remove : nat → list nat → list nat | _ [] := [] | n (list.cons m ms) := if (n=m) then nat_list_remove n ms else list.cons n (nat_list_remove n ms) def nat_list_max : list nat → nat | [] := 0 | (list.cons n ns) := if n ≥ nat_list_max ns then n else nat_list_max ns lemma nat_list_max_is_max : ∀ (l : list nat) (n : nat), n ∈ l → (nat_list_max l) ≥ n := begin intros l n n_in_l, induction l, apply absurd, apply list.not_mem_nil, exact n_in_l, exact not_false, simp [nat_list_max], have ex_mid : (l_hd ≥ nat_list_max l_tl) ∨ ¬ (l_hd ≥ nat_list_max l_tl), by apply decidable.em, cases ex_mid, have n_or : (n = l_hd ∨ n ∈ l_tl), by {apply list.eq_or_mem_of_mem_cons, exact n_in_l}, rewrite if_pos, cases n_or, apply le_of_eq, exact n_or, apply le_trans, apply l_ih, exact n_or, exact ex_mid, exact ex_mid, rewrite if_neg, have n_or : (n = l_hd ∨ n ∈ l_tl), by {apply list.eq_or_mem_of_mem_cons, exact n_in_l}, cases n_or, apply le_trans, have hd_lt : l_hd < nat_list_max l_tl, by {apply iff.mpr, apply lt_iff_not_ge,exact ex_mid}, apply le_of_lt, simp [n_or], exact hd_lt, apply le_of_eq, apply eq.refl, apply l_ih, exact n_or, exact ex_mid end def new_nat_list : list nat → nat := λ l, nat_list_max l + 1 lemma new_is_new : ∀ (l : list nat), ¬ (new_nat_list l ∈ l) := begin simp [new_nat_list], intros l new_in, apply absurd, apply nat.lt_succ_self, exact nat_list_max l, apply not_lt_of_ge, apply nat_list_max_is_max, simp [nat.succ_eq_add_one], exact new_in end mutual def free_vars, free_vars_list with free_vars : (term L) → list nat | (term.var L n) := [n] | (term.apply f l) := free_vars_list l with free_vars_list : list (term L) → list nat | [] := [] | (list.cons t ts) := nat_list_union (free_vars t) (free_vars_list ts) inductive formula : Type | equal : term L → term L → formula | atomic : ∀ r : L.relations, list (term L) → formula | imp : formula → formula → formula | not : formula → formula | forallF : nat → formula → formula open formula def choice: list nat → nat := λ l, 1 + nat_list_max l def sub_list :Type := list (nat × term L) def in_sub_list : nat → sub_list L → Prop | n [] := false | n ((m, _) :: s_tl) := (n=m) ∨ (in_sub_list n s_tl) def find_term_in_sub_list : nat → sub_list L → term L | n [] := term.var L n | n ((m, t) :: sl_tl) := if n =m then t else find_term_in_sub_list n sl_tl def well_formed_sub_list : sub_list L → Prop | [] := true | ((m, t) :: l_tl) := (¬ in_sub_list L m l_tl) ∧ well_formed_term L t ∧ well_formed_sub_list l_tl theorem eq_or_mem_of_mem_cons {n m: nat} {l : sub_list L} {t : term L}: (in_sub_list L n ((m, t) :: l)) → n = m ∨ (in_sub_list L n l) := assume h, h mutual def substitute_term, substitute_term_list with substitute_term : sub_list L → term L → term L | sl (term.var L n) := find_term_in_sub_list L n sl | sl (term.apply f ts) := term.apply f (substitute_term_list sl ts) with substitute_term_list : sub_list L → list (term L ) → list (term L) | sl [] := [] | sl (t :: ts) := (substitute_term sl t) :: (substitute_term_list sl ts) lemma sub_term_list_preserves_length {sl : sub_list L} {ts : list (term L)} : list.length ts = list.length (substitute_term_list L sl ts) := begin induction ts, simp [list.length, substitute_term_list], simp [list.length_cons, substitute_term_list, ts_ih] end lemma rw_well_formed_term_definition : Π {f : L.functions} {ts : list (term L)}, well_formed_term L (term.apply f ts) → L.arityF f = list.length ts ∧ well_formed_term_list L ts := by {simp [well_formed_term], intros f ts, apply id} lemma rw_well_formed_term_list_definition : Π {t ts}, well_formed_term_list L (t :: ts) → well_formed_term L t ∧ (well_formed_term_list L ts) := by {simp [well_formed_term_list], intros t ts wftl,exact wftl} lemma rw_well_formed_sub_list_definition : Π {hd_fst hd_snd tl}, well_formed_sub_list L ((hd_fst, hd_snd) :: tl) → well_formed_term L hd_snd ∧ well_formed_sub_list L tl := by {simp [well_formed_sub_list], intros fst snd tl wfsl, apply and.elim_right, exact wfsl} lemma find_term_well_formed : Π {n : nat} {sl : sub_list L}, well_formed_sub_list L sl → well_formed_term L (find_term_in_sub_list L n sl) := begin intros n sl wfsl, induction sl, simp [find_term_in_sub_list, well_formed_term], cases sl_hd, simp [find_term_in_sub_list], have ex_mid : n = sl_hd_fst ∨ ¬ n = sl_hd_fst, by {apply decidable.em}, cases ex_mid, simp [if_pos ex_mid], apply and.elim_left, apply rw_well_formed_sub_list_definition, exact wfsl, simp [if_neg ex_mid], apply sl_ih, apply and.elim_right, apply rw_well_formed_sub_list_definition, exact wfsl end mutual theorem sub_term_well_formed, sub_term_list_well_formed with sub_term_well_formed : Π {t: term L} {sl : sub_list L}, well_formed_term L t → well_formed_sub_list L sl → well_formed_term L (substitute_term L sl t) | t sl wft wfsl := begin induction t, simp [substitute_term], induction sl, simp [find_term_in_sub_list, well_formed_term], cases sl_hd, simp [find_term_in_sub_list], have ex_mid : t = sl_hd_fst ∨ ¬ t = sl_hd_fst, by apply decidable.em, cases ex_mid, simp [if_pos ex_mid], apply and.elim_left, apply and.elim_right, exact wfsl, simp [if_neg ex_mid], have wf_sl : well_formed_sub_list L sl_tl, by {apply and.elim_right, apply and.elim_right, apply wfsl}, apply sl_ih, exact wf_sl, simp [substitute_term,well_formed_term], apply and.intro, apply eq.trans, apply and.elim_left, apply rw_well_formed_term_definition, exact wft, apply sub_term_list_preserves_length, apply sub_term_list_well_formed, apply and.elim_right, apply rw_well_formed_term_definition, exact wft, exact wfsl end with sub_term_list_well_formed : Π {ts : list (term L)} {sl : sub_list L}, well_formed_term_list L ts → well_formed_sub_list L sl → (well_formed_term_list L (substitute_term_list L sl ts)) | ts sl wftl wfsl := begin repeat {simp [substitute_term_list]}, induction ts, simp [substitute_term_list, substitute_term_list, substitute_term_list], simp [substitute_term_list, well_formed_term_list], apply and.intro, apply sub_term_well_formed, apply and.elim_left, apply rw_well_formed_term_list_definition, exact wftl, exact wfsl, apply ts_ih, apply and.elim_right, apply rw_well_formed_term_list_definition, exact wftl, end definition substitute_formula : list nat → list (term L) → formula L := sorry
// // Copyright (c) 2002-2018 WEINZIERL ENGINEERING GmbH // All rights reserved. // // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT // SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY DAMAGES OR OTHER LIABILITY, // WHETHER IN CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE // #include "pch/kdrive_pch.h" #include "kdrive/baos/core/ServerFunction.h" #include "kdrive/baos/core/Exception.h" #include "kdrive/baos/core/ErrorCodes.h" #include "kdrive/connector/Semaphore.h" #include <Poco/Timestamp.h> #include <boost/assert.hpp> using namespace kdrive::connector; using namespace kdrive::baos; using Poco::Timestamp; using Poco::TimeoutException; /***************************** ** ServerServerFunction ******************************/ ServerFunction::ServerFunction(BaosConnector::Ptr connector) : errorCode_(0), connector_(connector) { BOOST_ASSERT(connector_ && "Invalid Connector"); } ServerFunction::~ServerFunction() { } DataResponse::Ptr ServerFunction::rpc(DataRequest::Ptr request, unsigned long timeout) { DataResponse::Ptr response; connector_->waitSem(timeout); try { ScopedQueueConnectorRxQueue queue(*connector_); send(request); response = receive(queue, timeout); } catch (...) { connector_->setSem(); throw; } connector_->setSem(); return response; } void ServerFunction::send(DataRequest::Ptr request) { if (!connector_) { throw ClientException("Invalid Connector"); } else if (!connector_->isConnected()) { throw ClientException("Connection not available"); } errorCode_ = 0; request_ = request; response_.reset(); connector_->clearRx(); connector_->send(request); } DataResponse::Ptr ServerFunction::receive(Connector& connector, unsigned long timeout) { waitResponse(connector, timeout); validateResponse(); return response_; } void ServerFunction::waitResponse(Connector& connector, unsigned long timeout) { Packet::Ptr packet; Timestamp timestamp; Timestamp::TimeDiff timeoutMicroSeconds = timeout * 1000; bool elapsed = false; while (!elapsed) { Timestamp startTime; packet = connector.waitReceive(timeout); DataResponse::Ptr dataResponse = std::dynamic_pointer_cast<DataResponse>(packet); if (dataResponse) { response_ = dataResponse; elapsed = true; } ErrorResponse::Ptr errorResponse = std::dynamic_pointer_cast<ErrorResponse>(packet); if (errorResponse) { errorCode_ = errorResponse->getErrorCode(); elapsed = true; } // ensure that the request matches the response. if (response_ && (response_->getSubService() != (request_->getSubService() | 0x80))) { elapsed = false; } if (!elapsed) { elapsed = timestamp.isElapsed(timeoutMicroSeconds); } if (!elapsed) { const unsigned long msElapsed = static_cast<unsigned long>(timestamp.elapsed()) / 1000; if (timeout < msElapsed) { elapsed = true; } else { timeout -= msElapsed; } } } } void ServerFunction::validateResponse() { if (errorCode_) { throwBaosServerException(errorCode_); } else if (!response_) { throw TimeoutException(); } }
I’ve read a number of books by Stephen Hawking (pictured) and Leonard Mlodinow, writing both together and separately. I’ve enjoyed them. They’re informative and funny, and they make clear some pretty deep concepts of physics and mathematics—without burdening you with a bunch of equations (that’s some trick). But their new book The Grand Design was a disappointment. It’s a short read, which is fine, though I was surprised when I discovered that the last 25% of the already-short book to be composed of back matter (an exotic form of matter discovered by publishers; it consists of glossaries, indexes, author bios, acknowledgements, and the like).
[GOAL] J : Type w C : Type u inst✝¹ : Category.{v, u} C inst✝ : HasZeroMorphisms C F : J → C B : Bicone F j : J ⊢ Bicone.ι B j ≫ Bicone.π B j = 𝟙 (F j) [PROOFSTEP] simpa using B.ι_π j j [GOAL] J : Type w C : Type u inst✝¹ : Category.{v, u} C inst✝ : HasZeroMorphisms C F : J → C B : Bicone F j j' : J h : j ≠ j' ⊢ Bicone.ι B j ≫ Bicone.π B j' = 0 [PROOFSTEP] simpa [h] using B.ι_π j j' [GOAL] J : Type w C : Type u inst✝¹ : Category.{v, u} C inst✝ : HasZeroMorphisms C F : J → C B : Bicone F ⊢ ∀ ⦃X Y : Discrete J⦄ (f : X ⟶ Y), (Discrete.functor F).map f ≫ (fun j => ι B j.as) Y = (fun j => ι B j.as) X ≫ ((const (Discrete J)).obj B.pt).map f [PROOFSTEP] intro ⟨j⟩ ⟨j'⟩ ⟨⟨f⟩⟩ [GOAL] J : Type w C : Type u inst✝¹ : Category.{v, u} C inst✝ : HasZeroMorphisms C F : J → C B : Bicone F j j' : J f : { as := j }.as = { as := j' }.as ⊢ (Discrete.functor F).map { down := { down := f } } ≫ (fun j => ι B j.as) { as := j' } = (fun j => ι B j.as) { as := j } ≫ ((const (Discrete J)).obj B.pt).map { down := { down := f } } [PROOFSTEP] cases f [GOAL] case refl J : Type w C : Type u inst✝¹ : Category.{v, u} C inst✝ : HasZeroMorphisms C F : J → C B : Bicone F j : J ⊢ (Discrete.functor F).map { down := { down := (_ : { as := j }.as = { as := j }.as) } } ≫ (fun j => ι B j.as) { as := j } = (fun j => ι B j.as) { as := j } ≫ ((const (Discrete J)).obj B.pt).map { down := { down := (_ : { as := j }.as = { as := j }.as) } } [PROOFSTEP] simp [GOAL] J : Type w C : Type u inst✝¹ : Category.{v, u} C inst✝ : HasZeroMorphisms C F f : J → C t : Cone (Discrete.functor f) ht : IsLimit t j j' : J ⊢ (fun j => IsLimit.lift ht (Fan.mk (f j) fun j' => if h : j = j' then eqToHom (_ : f j = f j') else 0)) j ≫ (fun j => NatTrans.app t.π { as := j }) j' = if h : j = j' then eqToHom (_ : f j = f j') else 0 [PROOFSTEP] simp [GOAL] J : Type w C : Type u inst✝¹ : Category.{v, u} C inst✝ : HasZeroMorphisms C F f : J → C t : Bicone f ht : IsLimit (toCone t) j : J j' : Discrete J ⊢ ι t j ≫ NatTrans.app (toCone t).π j' = IsLimit.lift ht (Fan.mk (f j) fun j' => if h : j = j' then eqToHom (_ : f j = f j') else 0) ≫ NatTrans.app (toCone t).π j' [PROOFSTEP] rw [ht.fac] [GOAL] J : Type w C : Type u inst✝¹ : Category.{v, u} C inst✝ : HasZeroMorphisms C F f : J → C t : Bicone f ht : IsLimit (toCone t) j : J j' : Discrete J ⊢ ι t j ≫ NatTrans.app (toCone t).π j' = NatTrans.app (Fan.mk (f j) fun j' => if h : j = j' then eqToHom (_ : f j = f j') else 0).π j' [PROOFSTEP] simp [t.ι_π] [GOAL] J : Type w C : Type u inst✝¹ : Category.{v, u} C inst✝ : HasZeroMorphisms C F f : J → C t : Cocone (Discrete.functor f) ht : IsColimit t j j' : J ⊢ (fun j => NatTrans.app t.ι { as := j }) j ≫ (fun j => IsColimit.desc ht (Cofan.mk (f j) fun j' => if h : j' = j then eqToHom (_ : f j' = f j) else 0)) j' = if h : j = j' then eqToHom (_ : f j = f j') else 0 [PROOFSTEP] simp [GOAL] J : Type w C : Type u inst✝¹ : Category.{v, u} C inst✝ : HasZeroMorphisms C F f : J → C t : Bicone f ht : IsColimit (toCocone t) j : J j' : Discrete J ⊢ NatTrans.app (toCocone t).ι j' ≫ π t j = NatTrans.app (toCocone t).ι j' ≫ IsColimit.desc ht (Cofan.mk (f j) fun j' => if h : j' = j then eqToHom (_ : f j' = f j) else 0) [PROOFSTEP] rw [ht.fac] [GOAL] J : Type w C : Type u inst✝¹ : Category.{v, u} C inst✝ : HasZeroMorphisms C F f : J → C t : Bicone f ht : IsColimit (toCocone t) j : J j' : Discrete J ⊢ NatTrans.app (toCocone t).ι j' ≫ π t j = NatTrans.app (Cofan.mk (f j) fun j' => if h : j' = j then eqToHom (_ : f j' = f j) else 0).ι j' [PROOFSTEP] simp [t.ι_π] [GOAL] J : Type w C : Type u inst✝¹ : Category.{v, u} C inst✝ : HasZeroMorphisms C F : J → C K : Type w' f : J → C c : Bicone f g : K ≃ J k k' : K ⊢ (fun k => ι c (↑g k)) k ≫ (fun k => π c (↑g k)) k' = if h : k = k' then eqToHom (_ : (f ∘ ↑g) k = (f ∘ ↑g) k') else 0 [PROOFSTEP] simp only [c.ι_π] [GOAL] J : Type w C : Type u inst✝¹ : Category.{v, u} C inst✝ : HasZeroMorphisms C F : J → C K : Type w' f : J → C c : Bicone f g : K ≃ J k k' : K ⊢ (if h : ↑g k = ↑g k' then eqToHom (_ : f (↑g k) = f (↑g k')) else 0) = if h : k = k' then eqToHom (_ : (f ∘ ↑g) k = (f ∘ ↑g) k') else 0 [PROOFSTEP] split_ifs with h h' h' [GOAL] case pos J : Type w C : Type u inst✝¹ : Category.{v, u} C inst✝ : HasZeroMorphisms C F : J → C K : Type w' f : J → C c : Bicone f g : K ≃ J k k' : K h : ↑g k = ↑g k' h' : k = k' ⊢ eqToHom (_ : f (↑g k) = f (↑g k')) = eqToHom (_ : (f ∘ ↑g) k = (f ∘ ↑g) k') [PROOFSTEP] simp [Equiv.apply_eq_iff_eq g] at h h' [GOAL] case neg J : Type w C : Type u inst✝¹ : Category.{v, u} C inst✝ : HasZeroMorphisms C F : J → C K : Type w' f : J → C c : Bicone f g : K ≃ J k k' : K h : ↑g k = ↑g k' h' : ¬k = k' ⊢ eqToHom (_ : f (↑g k) = f (↑g k')) = 0 [PROOFSTEP] simp [Equiv.apply_eq_iff_eq g] at h h' [GOAL] case pos J : Type w C : Type u inst✝¹ : Category.{v, u} C inst✝ : HasZeroMorphisms C F : J → C K : Type w' f : J → C c : Bicone f g : K ≃ J k k' : K h : ¬↑g k = ↑g k' h' : k = k' ⊢ 0 = eqToHom (_ : (f ∘ ↑g) k = (f ∘ ↑g) k') [PROOFSTEP] simp [Equiv.apply_eq_iff_eq g] at h h' [GOAL] case neg J : Type w C : Type u inst✝¹ : Category.{v, u} C inst✝ : HasZeroMorphisms C F : J → C K : Type w' f : J → C c : Bicone f g : K ≃ J k k' : K h : ¬↑g k = ↑g k' h' : ¬k = k' ⊢ 0 = 0 [PROOFSTEP] simp [Equiv.apply_eq_iff_eq g] at h h' [GOAL] case pos J : Type w C : Type u inst✝¹ : Category.{v, u} C inst✝ : HasZeroMorphisms C F : J → C K : Type w' f : J → C c : Bicone f g : K ≃ J k k' : K h✝ : ↑g k = ↑g k' h' h : k = k' ⊢ eqToHom (_ : f (↑g k) = f (↑g k')) = eqToHom (_ : (f ∘ ↑g) k = (f ∘ ↑g) k') [PROOFSTEP] tauto [GOAL] case neg J : Type w C : Type u inst✝¹ : Category.{v, u} C inst✝ : HasZeroMorphisms C F : J → C K : Type w' f : J → C c : Bicone f g : K ≃ J k k' : K h✝ : ↑g k = ↑g k' h' : ¬k = k' h : k = k' ⊢ eqToHom (_ : f (↑g k) = f (↑g k')) = 0 [PROOFSTEP] tauto [GOAL] case pos J : Type w C : Type u inst✝¹ : Category.{v, u} C inst✝ : HasZeroMorphisms C F : J → C K : Type w' f : J → C c : Bicone f g : K ≃ J k k' : K h' : k = k' h : ¬k = k' ⊢ 0 = eqToHom (_ : (f ∘ ↑g) k = (f ∘ ↑g) k') [PROOFSTEP] tauto [GOAL] case neg J : Type w C : Type u inst✝¹ : Category.{v, u} C inst✝ : HasZeroMorphisms C F : J → C K : Type w' f : J → C c : Bicone f g : K ≃ J k k' : K h' h : ¬k = k' ⊢ 0 = 0 [PROOFSTEP] tauto [GOAL] J : Type w C : Type u inst✝¹ : Category.{v, u} C inst✝ : HasZeroMorphisms C F : J → C K : Type w' f : J → C c : Bicone f g : K ≃ J ⊢ ∀ (j : Discrete K), NatTrans.app (toCone (whisker c g)).π j = (Iso.refl (toCone (whisker c g)).pt).hom ≫ NatTrans.app ((Cones.postcompose (Discrete.functorComp f ↑g).inv).obj (Cone.whisker (Discrete.functor (Discrete.mk ∘ ↑g)) (toCone c))).π j [PROOFSTEP] aesop_cat [GOAL] J : Type w C : Type u inst✝¹ : Category.{v, u} C inst✝ : HasZeroMorphisms C F : J → C K : Type w' f : J → C c : Bicone f g : K ≃ J ⊢ ∀ (j : Discrete K), NatTrans.app (toCocone (whisker c g)).ι j ≫ (Iso.refl (toCocone (whisker c g)).pt).hom = NatTrans.app ((Cocones.precompose (Discrete.functorComp f ↑g).hom).obj (Cocone.whisker (Discrete.functor (Discrete.mk ∘ ↑g)) (toCocone c))).ι j [PROOFSTEP] aesop_cat [GOAL] J : Type w C : Type u inst✝¹ : Category.{v, u} C inst✝ : HasZeroMorphisms C F : J → C K : Type w' f : J → C c : Bicone f g : K ≃ J ⊢ IsBilimit (whisker c g) ≃ IsBilimit c [PROOFSTEP] refine' equivOfSubsingletonOfSubsingleton (fun hc => ⟨_, _⟩) fun hc => ⟨_, _⟩ [GOAL] case refine'_1 J : Type w C : Type u inst✝¹ : Category.{v, u} C inst✝ : HasZeroMorphisms C F : J → C K : Type w' f : J → C c : Bicone f g : K ≃ J hc : IsBilimit (whisker c g) ⊢ IsLimit (toCone c) [PROOFSTEP] let this := IsLimit.ofIsoLimit hc.isLimit (Bicone.whiskerToCone c g) [GOAL] case refine'_1 J : Type w C : Type u inst✝¹ : Category.{v, u} C inst✝ : HasZeroMorphisms C F : J → C K : Type w' f : J → C c : Bicone f g : K ≃ J hc : IsBilimit (whisker c g) this : IsLimit ((Cones.postcompose (Discrete.functorComp f ↑g).inv).obj (Cone.whisker (Discrete.functor (Discrete.mk ∘ ↑g)) (toCone c))) := IsLimit.ofIsoLimit hc.isLimit (whiskerToCone c g) ⊢ IsLimit (toCone c) [PROOFSTEP] let this := (IsLimit.postcomposeHomEquiv (Discrete.functorComp f g).symm _) this [GOAL] case refine'_1 J : Type w C : Type u inst✝¹ : Category.{v, u} C inst✝ : HasZeroMorphisms C F : J → C K : Type w' f : J → C c : Bicone f g : K ≃ J hc : IsBilimit (whisker c g) this✝ : IsLimit ((Cones.postcompose (Discrete.functorComp f ↑g).inv).obj (Cone.whisker (Discrete.functor (Discrete.mk ∘ ↑g)) (toCone c))) := IsLimit.ofIsoLimit hc.isLimit (whiskerToCone c g) this : (fun x => IsLimit (Cone.whisker (Discrete.functor (Discrete.mk ∘ ↑g)) (toCone c))) this✝ := ↑(IsLimit.postcomposeHomEquiv (Discrete.functorComp f ↑g).symm (Cone.whisker (Discrete.functor (Discrete.mk ∘ ↑g)) (toCone c))) this✝ ⊢ IsLimit (toCone c) [PROOFSTEP] exact IsLimit.ofWhiskerEquivalence (Discrete.equivalence g) this [GOAL] case refine'_2 J : Type w C : Type u inst✝¹ : Category.{v, u} C inst✝ : HasZeroMorphisms C F : J → C K : Type w' f : J → C c : Bicone f g : K ≃ J hc : IsBilimit (whisker c g) ⊢ IsColimit (toCocone c) [PROOFSTEP] let this := IsColimit.ofIsoColimit hc.isColimit (Bicone.whiskerToCocone c g) [GOAL] case refine'_2 J : Type w C : Type u inst✝¹ : Category.{v, u} C inst✝ : HasZeroMorphisms C F : J → C K : Type w' f : J → C c : Bicone f g : K ≃ J hc : IsBilimit (whisker c g) this : IsColimit ((Cocones.precompose (Discrete.functorComp f ↑g).hom).obj (Cocone.whisker (Discrete.functor (Discrete.mk ∘ ↑g)) (toCocone c))) := IsColimit.ofIsoColimit hc.isColimit (whiskerToCocone c g) ⊢ IsColimit (toCocone c) [PROOFSTEP] let this := (IsColimit.precomposeHomEquiv (Discrete.functorComp f g) _) this [GOAL] case refine'_2 J : Type w C : Type u inst✝¹ : Category.{v, u} C inst✝ : HasZeroMorphisms C F : J → C K : Type w' f : J → C c : Bicone f g : K ≃ J hc : IsBilimit (whisker c g) this✝ : IsColimit ((Cocones.precompose (Discrete.functorComp f ↑g).hom).obj (Cocone.whisker (Discrete.functor (Discrete.mk ∘ ↑g)) (toCocone c))) := IsColimit.ofIsoColimit hc.isColimit (whiskerToCocone c g) this : (fun x => IsColimit (Cocone.whisker (Discrete.functor (Discrete.mk ∘ ↑g)) (toCocone c))) this✝ := ↑(IsColimit.precomposeHomEquiv (Discrete.functorComp f ↑g) (Cocone.whisker (Discrete.functor (Discrete.mk ∘ ↑g)) (toCocone c))) this✝ ⊢ IsColimit (toCocone c) [PROOFSTEP] exact IsColimit.ofWhiskerEquivalence (Discrete.equivalence g) this [GOAL] case refine'_3 J : Type w C : Type u inst✝¹ : Category.{v, u} C inst✝ : HasZeroMorphisms C F : J → C K : Type w' f : J → C c : Bicone f g : K ≃ J hc : IsBilimit c ⊢ IsLimit (toCone (whisker c g)) [PROOFSTEP] apply IsLimit.ofIsoLimit _ (Bicone.whiskerToCone c g).symm [GOAL] J : Type w C : Type u inst✝¹ : Category.{v, u} C inst✝ : HasZeroMorphisms C F : J → C K : Type w' f : J → C c : Bicone f g : K ≃ J hc : IsBilimit c ⊢ IsLimit ((Cones.postcompose (Discrete.functorComp f ↑g).inv).obj (Cone.whisker (Discrete.functor (Discrete.mk ∘ ↑g)) (toCone c))) [PROOFSTEP] apply (IsLimit.postcomposeHomEquiv (Discrete.functorComp f g).symm _).symm _ [GOAL] J : Type w C : Type u inst✝¹ : Category.{v, u} C inst✝ : HasZeroMorphisms C F : J → C K : Type w' f : J → C c : Bicone f g : K ≃ J hc : IsBilimit c ⊢ IsLimit (Cone.whisker (Discrete.functor (Discrete.mk ∘ ↑g)) (toCone c)) [PROOFSTEP] exact IsLimit.whiskerEquivalence hc.isLimit (Discrete.equivalence g) [GOAL] case refine'_4 J : Type w C : Type u inst✝¹ : Category.{v, u} C inst✝ : HasZeroMorphisms C F : J → C K : Type w' f : J → C c : Bicone f g : K ≃ J hc : IsBilimit c ⊢ IsColimit (toCocone (whisker c g)) [PROOFSTEP] apply IsColimit.ofIsoColimit _ (Bicone.whiskerToCocone c g).symm [GOAL] J : Type w C : Type u inst✝¹ : Category.{v, u} C inst✝ : HasZeroMorphisms C F : J → C K : Type w' f : J → C c : Bicone f g : K ≃ J hc : IsBilimit c ⊢ IsColimit ((Cocones.precompose (Discrete.functorComp f ↑g).hom).obj (Cocone.whisker (Discrete.functor (Discrete.mk ∘ ↑g)) (toCocone c))) [PROOFSTEP] apply (IsColimit.precomposeHomEquiv (Discrete.functorComp f g) _).symm _ [GOAL] J : Type w C : Type u inst✝¹ : Category.{v, u} C inst✝ : HasZeroMorphisms C F : J → C K : Type w' f : J → C c : Bicone f g : K ≃ J hc : IsBilimit c ⊢ IsColimit (Cocone.whisker (Discrete.functor (Discrete.mk ∘ ↑g)) (toCocone c)) [PROOFSTEP] exact IsColimit.whiskerEquivalence hc.isColimit (Discrete.equivalence g) [GOAL] J : Type w C : Type u inst✝² : Category.{v, u} C inst✝¹ : HasZeroMorphisms C F✝ : J → C K : Type w' inst✝ : HasBiproductsOfShape K C e : J ≃ K F : J → C h : LimitBicone (F ∘ ↑e.symm) c : Bicone (F ∘ ↑e.symm) hc : Bicone.IsBilimit c ⊢ LimitBicone F [PROOFSTEP] simpa only [(· ∘ ·), e.symm_apply_apply] using LimitBicone.mk (c.whisker e) ((c.whiskerIsBilimitIff _).2 hc) [GOAL] J : Type w C : Type u inst✝³ : Category.{v, u} C inst✝² : HasZeroMorphisms C F : J → C inst✝¹ : HasFiniteBiproducts C inst✝ : Finite J ⊢ HasBiproductsOfShape J C [PROOFSTEP] rcases Finite.exists_equiv_fin J with ⟨n, ⟨e⟩⟩ [GOAL] case intro.intro J : Type w C : Type u inst✝³ : Category.{v, u} C inst✝² : HasZeroMorphisms C F : J → C inst✝¹ : HasFiniteBiproducts C inst✝ : Finite J n : ℕ e : J ≃ Fin n ⊢ HasBiproductsOfShape J C [PROOFSTEP] haveI : HasBiproductsOfShape (Fin n) C := HasFiniteBiproducts.out n [GOAL] case intro.intro J : Type w C : Type u inst✝³ : Category.{v, u} C inst✝² : HasZeroMorphisms C F : J → C inst✝¹ : HasFiniteBiproducts C inst✝ : Finite J n : ℕ e : J ≃ Fin n this : HasBiproductsOfShape (Fin n) C ⊢ HasBiproductsOfShape J C [PROOFSTEP] exact hasBiproductsOfShape_of_equiv C e [GOAL] J : Type w C : Type u inst✝³ : Category.{v, u} C inst✝² : HasZeroMorphisms C inst✝¹ : DecidableEq J f : J → C inst✝ : HasBiproduct f j j' : J ⊢ ι f j ≫ π f j' = if h : j = j' then eqToHom (_ : f j = f j') else 0 [PROOFSTEP] convert (biproduct.bicone f).ι_π j j' [GOAL] J : Type w C : Type u inst✝² : Category.{v, u} C inst✝¹ : HasZeroMorphisms C f : J → C inst✝ : HasBiproduct f j : J ⊢ ι f j ≫ π f j = 𝟙 (f j) [PROOFSTEP] simp [biproduct.ι_π] [GOAL] J : Type w C : Type u inst✝² : Category.{v, u} C inst✝¹ : HasZeroMorphisms C f : J → C inst✝ : HasBiproduct f j j' : J h : j ≠ j' ⊢ ι f j ≫ π f j' = 0 [PROOFSTEP] simp [biproduct.ι_π, h] [GOAL] J : Type w C : Type u inst✝² : Category.{v, u} C inst✝¹ : HasZeroMorphisms C f : J → C inst✝ : HasBiproduct f j j' : J w : j = j' ⊢ f j = f j' [PROOFSTEP] simp [w] [GOAL] J : Type w C : Type u inst✝² : Category.{v, u} C inst✝¹ : HasZeroMorphisms C f : J → C inst✝ : HasBiproduct f j j' : J w : j = j' ⊢ eqToHom (_ : f j = f j') ≫ ι f j' = ι f j [PROOFSTEP] cases w [GOAL] case refl J : Type w C : Type u inst✝² : Category.{v, u} C inst✝¹ : HasZeroMorphisms C f : J → C inst✝ : HasBiproduct f j : J ⊢ eqToHom (_ : f j = f j) ≫ ι f j = ι f j [PROOFSTEP] simp -- The `simpNF` linter incorrectly identifies these as simp lemmas that could never apply. -- https://github.com/leanprover-community/mathlib4/issues/5049 -- They are used by `simp` in `biproduct.whisker_equiv` below. [GOAL] J : Type w C : Type u inst✝² : Category.{v, u} C inst✝¹ : HasZeroMorphisms C f : J → C inst✝ : HasBiproduct f j j' : J w : j = j' ⊢ f j = f j' [PROOFSTEP] simp [w] [GOAL] J : Type w C : Type u inst✝² : Category.{v, u} C inst✝¹ : HasZeroMorphisms C f : J → C inst✝ : HasBiproduct f j j' : J w : j = j' ⊢ π f j ≫ eqToHom (_ : f j = f j') = π f j' [PROOFSTEP] cases w [GOAL] case refl J : Type w C : Type u inst✝² : Category.{v, u} C inst✝¹ : HasZeroMorphisms C f : J → C inst✝ : HasBiproduct f j : J ⊢ π f j ≫ eqToHom (_ : f j = f j) = π f j [PROOFSTEP] simp [GOAL] J : Type w C : Type u inst✝² : Category.{v, u} C inst✝¹ : HasZeroMorphisms C f : J → C inst✝ : HasBiproduct f j : Discrete J ⊢ (isoProduct f).hom ≫ limit.π (Discrete.functor f) j = Pi.lift (π f) ≫ limit.π (Discrete.functor f) j [PROOFSTEP] simp [biproduct.isoProduct] [GOAL] J : Type w C : Type u inst✝² : Category.{v, u} C inst✝¹ : HasZeroMorphisms C f : J → C inst✝ : HasBiproduct f j : J ⊢ (isoProduct f).inv ≫ π f j = lift (Pi.π f) ≫ π f j [PROOFSTEP] simp [Iso.inv_comp_eq] [GOAL] J : Type w C : Type u inst✝² : Category.{v, u} C inst✝¹ : HasZeroMorphisms C f : J → C inst✝ : HasBiproduct f j : Discrete J ⊢ colimit.ι (Discrete.functor f) j ≫ (isoCoproduct f).inv = colimit.ι (Discrete.functor f) j ≫ Sigma.desc (ι f) [PROOFSTEP] simp [biproduct.isoCoproduct] [GOAL] J : Type w C : Type u inst✝² : Category.{v, u} C inst✝¹ : HasZeroMorphisms C f : J → C inst✝ : HasBiproduct f j : J ⊢ ι f j ≫ (isoCoproduct f).hom = ι f j ≫ desc (Sigma.ι f) [PROOFSTEP] simp [← Iso.eq_comp_inv] [GOAL] J : Type w C : Type u inst✝³ : Category.{v, u} C inst✝² : HasZeroMorphisms C f g : J → C inst✝¹ : HasBiproduct f inst✝ : HasBiproduct g p : (b : J) → f b ⟶ g b ⊢ map p = map' p [PROOFSTEP] ext [GOAL] case w.w J : Type w C : Type u inst✝³ : Category.{v, u} C inst✝² : HasZeroMorphisms C f g : J → C inst✝¹ : HasBiproduct f inst✝ : HasBiproduct g p : (b : J) → f b ⟶ g b j✝¹ j✝ : J ⊢ ι (fun b => f b) j✝ ≫ map p ≫ π (fun b => g b) j✝¹ = ι (fun b => f b) j✝ ≫ map' p ≫ π (fun b => g b) j✝¹ [PROOFSTEP] dsimp [GOAL] case w.w J : Type w C : Type u inst✝³ : Category.{v, u} C inst✝² : HasZeroMorphisms C f g : J → C inst✝¹ : HasBiproduct f inst✝ : HasBiproduct g p : (b : J) → f b ⟶ g b j✝¹ j✝ : J ⊢ ι (fun b => f b) j✝ ≫ map p ≫ π (fun b => g b) j✝¹ = ι (fun b => f b) j✝ ≫ map' p ≫ π (fun b => g b) j✝¹ [PROOFSTEP] simp only [Discrete.natTrans_app, Limits.IsColimit.ι_map_assoc, Limits.IsLimit.map_π, Category.assoc, ← Bicone.toCone_π_app_mk, ← biproduct.bicone_π, ← Bicone.toCocone_ι_app_mk, ← biproduct.bicone_ι] [GOAL] case w.w J : Type w C : Type u inst✝³ : Category.{v, u} C inst✝² : HasZeroMorphisms C f g : J → C inst✝¹ : HasBiproduct f inst✝ : HasBiproduct g p : (b : J) → f b ⟶ g b j✝¹ j✝ : J ⊢ NatTrans.app (Bicone.toCocone (bicone fun b => f b)).ι { as := j✝ } ≫ NatTrans.app (Bicone.toCone (bicone fun b => f b)).π { as := j✝¹ } ≫ p j✝¹ = p j✝ ≫ NatTrans.app (Bicone.toCocone (bicone fun b => g b)).ι { as := j✝ } ≫ NatTrans.app (Bicone.toCone (bicone fun b => g b)).π { as := j✝¹ } [PROOFSTEP] dsimp [GOAL] case w.w J : Type w C : Type u inst✝³ : Category.{v, u} C inst✝² : HasZeroMorphisms C f g : J → C inst✝¹ : HasBiproduct f inst✝ : HasBiproduct g p : (b : J) → f b ⟶ g b j✝¹ j✝ : J ⊢ ι (fun b => f b) j✝ ≫ π (fun b => f b) j✝¹ ≫ p j✝¹ = p j✝ ≫ ι (fun b => g b) j✝ ≫ π (fun b => g b) j✝¹ [PROOFSTEP] rw [biproduct.ι_π_assoc, biproduct.ι_π] [GOAL] case w.w J : Type w C : Type u inst✝³ : Category.{v, u} C inst✝² : HasZeroMorphisms C f g : J → C inst✝¹ : HasBiproduct f inst✝ : HasBiproduct g p : (b : J) → f b ⟶ g b j✝¹ j✝ : J ⊢ (if h : j✝ = j✝¹ then eqToHom (_ : f j✝ = f j✝¹) else 0) ≫ p j✝¹ = p j✝ ≫ if h : j✝ = j✝¹ then eqToHom (_ : g j✝ = g j✝¹) else 0 [PROOFSTEP] split_ifs with h [GOAL] case pos J : Type w C : Type u inst✝³ : Category.{v, u} C inst✝² : HasZeroMorphisms C f g : J → C inst✝¹ : HasBiproduct f inst✝ : HasBiproduct g p : (b : J) → f b ⟶ g b j✝¹ j✝ : J h : j✝ = j✝¹ ⊢ eqToHom (_ : f j✝ = f j✝¹) ≫ p j✝¹ = p j✝ ≫ eqToHom (_ : g j✝ = g j✝¹) [PROOFSTEP] subst h [GOAL] case pos J : Type w C : Type u inst✝³ : Category.{v, u} C inst✝² : HasZeroMorphisms C f g : J → C inst✝¹ : HasBiproduct f inst✝ : HasBiproduct g p : (b : J) → f b ⟶ g b j✝ : J ⊢ eqToHom (_ : f j✝ = f j✝) ≫ p j✝ = p j✝ ≫ eqToHom (_ : g j✝ = g j✝) [PROOFSTEP] rw [eqToHom_refl, Category.id_comp] [GOAL] case pos J : Type w C : Type u inst✝³ : Category.{v, u} C inst✝² : HasZeroMorphisms C f g : J → C inst✝¹ : HasBiproduct f inst✝ : HasBiproduct g p : (b : J) → f b ⟶ g b j✝ : J ⊢ p j✝ = p j✝ ≫ eqToHom (_ : g j✝ = g j✝) [PROOFSTEP] erw [Category.comp_id] [GOAL] case neg J : Type w C : Type u inst✝³ : Category.{v, u} C inst✝² : HasZeroMorphisms C f g : J → C inst✝¹ : HasBiproduct f inst✝ : HasBiproduct g p : (b : J) → f b ⟶ g b j✝¹ j✝ : J h : ¬j✝ = j✝¹ ⊢ 0 ≫ p j✝¹ = p j✝ ≫ 0 [PROOFSTEP] simp [GOAL] J : Type w C : Type u inst✝³ : Category.{v, u} C inst✝² : HasZeroMorphisms C f g : J → C inst✝¹ : HasBiproduct f inst✝ : HasBiproduct g p : (j : J) → f j ⟶ g j j : J ⊢ ι f j ≫ map p = p j ≫ ι g j [PROOFSTEP] rw [biproduct.map_eq_map'] [GOAL] J : Type w C : Type u inst✝³ : Category.{v, u} C inst✝² : HasZeroMorphisms C f g : J → C inst✝¹ : HasBiproduct f inst✝ : HasBiproduct g p : (j : J) → f j ⟶ g j j : J ⊢ ι f j ≫ map' p = p j ≫ ι g j [PROOFSTEP] apply Limits.IsColimit.ι_map (biproduct.isColimit f) (biproduct.bicone g).toCocone (Discrete.natTrans fun j => p j.as) (Discrete.mk j) [GOAL] J : Type w C : Type u inst✝³ : Category.{v, u} C inst✝² : HasZeroMorphisms C f g : J → C inst✝¹ : HasBiproduct f inst✝ : HasBiproduct g p : (j : J) → f j ⟶ g j P : C k : (j : J) → g j ⟶ P ⊢ map p ≫ desc k = desc fun j => p j ≫ k j [PROOFSTEP] ext [GOAL] case w J : Type w C : Type u inst✝³ : Category.{v, u} C inst✝² : HasZeroMorphisms C f g : J → C inst✝¹ : HasBiproduct f inst✝ : HasBiproduct g p : (j : J) → f j ⟶ g j P : C k : (j : J) → g j ⟶ P j✝ : J ⊢ ι (fun b => f b) j✝ ≫ map p ≫ desc k = ι (fun b => f b) j✝ ≫ desc fun j => p j ≫ k j [PROOFSTEP] simp [GOAL] J : Type w C : Type u inst✝³ : Category.{v, u} C inst✝² : HasZeroMorphisms C f g : J → C inst✝¹ : HasBiproduct f inst✝ : HasBiproduct g P : C k : (j : J) → P ⟶ f j p : (j : J) → f j ⟶ g j ⊢ lift k ≫ map p = lift fun j => k j ≫ p j [PROOFSTEP] ext [GOAL] case w J : Type w C : Type u inst✝³ : Category.{v, u} C inst✝² : HasZeroMorphisms C f g : J → C inst✝¹ : HasBiproduct f inst✝ : HasBiproduct g P : C k : (j : J) → P ⟶ f j p : (j : J) → f j ⟶ g j j✝ : J ⊢ (lift k ≫ map p) ≫ π (fun b => g b) j✝ = (lift fun j => k j ≫ p j) ≫ π (fun b => g b) j✝ [PROOFSTEP] simp [GOAL] J : Type w C : Type u inst✝³ : Category.{v, u} C inst✝² : HasZeroMorphisms C K : Type ?u.108203 f : J → C g : K → C e : J ≃ K w : (j : J) → g (↑e j) ≅ f j inst✝¹ : HasBiproduct f inst✝ : HasBiproduct g k : K ⊢ g k = g (↑e (↑e.symm k)) [PROOFSTEP] simp [GOAL] J : Type w C : Type u inst✝³ : Category.{v, u} C inst✝² : HasZeroMorphisms C K : Type ?u.124125 f : J → C g : K → C e : J ≃ K w : (j : J) → g (↑e j) ≅ f j inst✝¹ : HasBiproduct f inst✝ : HasBiproduct g k : K ⊢ g (↑e (↑e.symm k)) = g k [PROOFSTEP] simp [GOAL] J : Type w C : Type u inst✝³ : Category.{v, u} C inst✝² : HasZeroMorphisms C K : Type u_1 f : J → C g : K → C e : J ≃ K w : (j : J) → g (↑e j) ≅ f j inst✝¹ : HasBiproduct f inst✝ : HasBiproduct g ⊢ (whisker_equiv e w).hom = lift fun k => π f (↑e.symm k) ≫ (w (↑e.symm k)).inv ≫ eqToHom (_ : g (↑e (↑e.symm k)) = g k) [PROOFSTEP] simp only [whisker_equiv_hom] [GOAL] J : Type w C : Type u inst✝³ : Category.{v, u} C inst✝² : HasZeroMorphisms C K : Type u_1 f : J → C g : K → C e : J ≃ K w : (j : J) → g (↑e j) ≅ f j inst✝¹ : HasBiproduct f inst✝ : HasBiproduct g ⊢ (desc fun j => (w j).inv ≫ ι g (↑e j)) = lift fun k => π f (↑e.symm k) ≫ (w (↑e.symm k)).inv ≫ eqToHom (_ : g (↑e (↑e.symm k)) = g k) [PROOFSTEP] ext k j [GOAL] case w.w J : Type w C : Type u inst✝³ : Category.{v, u} C inst✝² : HasZeroMorphisms C K : Type u_1 f : J → C g : K → C e : J ≃ K w : (j : J) → g (↑e j) ≅ f j inst✝¹ : HasBiproduct f inst✝ : HasBiproduct g k : K j : J ⊢ ι (fun j => f j) j ≫ (desc fun j => (w j).inv ≫ ι g (↑e j)) ≫ π g k = ι (fun j => f j) j ≫ (lift fun k => π f (↑e.symm k) ≫ (w (↑e.symm k)).inv ≫ eqToHom (_ : g (↑e (↑e.symm k)) = g k)) ≫ π g k [PROOFSTEP] by_cases h : k = e j [GOAL] case pos J : Type w C : Type u inst✝³ : Category.{v, u} C inst✝² : HasZeroMorphisms C K : Type u_1 f : J → C g : K → C e : J ≃ K w : (j : J) → g (↑e j) ≅ f j inst✝¹ : HasBiproduct f inst✝ : HasBiproduct g k : K j : J h : k = ↑e j ⊢ ι (fun j => f j) j ≫ (desc fun j => (w j).inv ≫ ι g (↑e j)) ≫ π g k = ι (fun j => f j) j ≫ (lift fun k => π f (↑e.symm k) ≫ (w (↑e.symm k)).inv ≫ eqToHom (_ : g (↑e (↑e.symm k)) = g k)) ≫ π g k [PROOFSTEP] subst h [GOAL] case pos J : Type w C : Type u inst✝³ : Category.{v, u} C inst✝² : HasZeroMorphisms C K : Type u_1 f : J → C g : K → C e : J ≃ K w : (j : J) → g (↑e j) ≅ f j inst✝¹ : HasBiproduct f inst✝ : HasBiproduct g j : J ⊢ ι (fun j => f j) j ≫ (desc fun j => (w j).inv ≫ ι g (↑e j)) ≫ π g (↑e j) = ι (fun j => f j) j ≫ (lift fun k => π f (↑e.symm k) ≫ (w (↑e.symm k)).inv ≫ eqToHom (_ : g (↑e (↑e.symm k)) = g k)) ≫ π g (↑e j) [PROOFSTEP] simp [GOAL] case neg J : Type w C : Type u inst✝³ : Category.{v, u} C inst✝² : HasZeroMorphisms C K : Type u_1 f : J → C g : K → C e : J ≃ K w : (j : J) → g (↑e j) ≅ f j inst✝¹ : HasBiproduct f inst✝ : HasBiproduct g k : K j : J h : ¬k = ↑e j ⊢ ι (fun j => f j) j ≫ (desc fun j => (w j).inv ≫ ι g (↑e j)) ≫ π g k = ι (fun j => f j) j ≫ (lift fun k => π f (↑e.symm k) ≫ (w (↑e.symm k)).inv ≫ eqToHom (_ : g (↑e (↑e.symm k)) = g k)) ≫ π g k [PROOFSTEP] simp only [ι_desc_assoc, Category.assoc, ne_eq, lift_π] [GOAL] case neg J : Type w C : Type u inst✝³ : Category.{v, u} C inst✝² : HasZeroMorphisms C K : Type u_1 f : J → C g : K → C e : J ≃ K w : (j : J) → g (↑e j) ≅ f j inst✝¹ : HasBiproduct f inst✝ : HasBiproduct g k : K j : J h : ¬k = ↑e j ⊢ (w j).inv ≫ ι g (↑e j) ≫ π g k = ι (fun j => f j) j ≫ π f (↑e.symm k) ≫ (w (↑e.symm k)).inv ≫ eqToHom (_ : g (↑e (↑e.symm k)) = g k) [PROOFSTEP] rw [biproduct.ι_π_ne, biproduct.ι_π_ne_assoc] [GOAL] case neg J : Type w C : Type u inst✝³ : Category.{v, u} C inst✝² : HasZeroMorphisms C K : Type u_1 f : J → C g : K → C e : J ≃ K w : (j : J) → g (↑e j) ≅ f j inst✝¹ : HasBiproduct f inst✝ : HasBiproduct g k : K j : J h : ¬k = ↑e j ⊢ (w j).inv ≫ 0 = 0 ≫ (w (↑e.symm k)).inv ≫ eqToHom (_ : g (↑e (↑e.symm k)) = g k) [PROOFSTEP] simp [GOAL] case neg.h J : Type w C : Type u inst✝³ : Category.{v, u} C inst✝² : HasZeroMorphisms C K : Type u_1 f : J → C g : K → C e : J ≃ K w : (j : J) → g (↑e j) ≅ f j inst✝¹ : HasBiproduct f inst✝ : HasBiproduct g k : K j : J h : ¬k = ↑e j ⊢ j ≠ ↑e.symm k [PROOFSTEP] rintro rfl [GOAL] case neg.h J : Type w C : Type u inst✝³ : Category.{v, u} C inst✝² : HasZeroMorphisms C K : Type u_1 f : J → C g : K → C e : J ≃ K w : (j : J) → g (↑e j) ≅ f j inst✝¹ : HasBiproduct f inst✝ : HasBiproduct g k : K h : ¬k = ↑e (↑e.symm k) ⊢ False [PROOFSTEP] simp at h [GOAL] case neg.h J : Type w C : Type u inst✝³ : Category.{v, u} C inst✝² : HasZeroMorphisms C K : Type u_1 f : J → C g : K → C e : J ≃ K w : (j : J) → g (↑e j) ≅ f j inst✝¹ : HasBiproduct f inst✝ : HasBiproduct g k : K j : J h : ¬k = ↑e j ⊢ ↑e j ≠ k [PROOFSTEP] exact Ne.symm h [GOAL] J : Type w C : Type u inst✝³ : Category.{v, u} C inst✝² : HasZeroMorphisms C K : Type u_1 f : J → C g : K → C e : J ≃ K w : (j : J) → g (↑e j) ≅ f j inst✝¹ : HasBiproduct f inst✝ : HasBiproduct g ⊢ (whisker_equiv e w).inv = lift fun j => π g (↑e j) ≫ (w j).hom [PROOFSTEP] simp only [whisker_equiv_inv] [GOAL] J : Type w C : Type u inst✝³ : Category.{v, u} C inst✝² : HasZeroMorphisms C K : Type u_1 f : J → C g : K → C e : J ≃ K w : (j : J) → g (↑e j) ≅ f j inst✝¹ : HasBiproduct f inst✝ : HasBiproduct g ⊢ (desc fun k => eqToHom (_ : g k = g (↑e (↑e.symm k))) ≫ (w (↑e.symm k)).hom ≫ ι (fun j => f j) (↑e.symm k)) = lift fun j => π g (↑e j) ≫ (w j).hom [PROOFSTEP] ext j k [GOAL] case w.w J : Type w C : Type u inst✝³ : Category.{v, u} C inst✝² : HasZeroMorphisms C K : Type u_1 f : J → C g : K → C e : J ≃ K w : (j : J) → g (↑e j) ≅ f j inst✝¹ : HasBiproduct f inst✝ : HasBiproduct g j : J k : K ⊢ ι g k ≫ (desc fun k => eqToHom (_ : g k = g (↑e (↑e.symm k))) ≫ (w (↑e.symm k)).hom ≫ ι (fun j => f j) (↑e.symm k)) ≫ π (fun j => f j) j = ι g k ≫ (lift fun j => π g (↑e j) ≫ (w j).hom) ≫ π (fun j => f j) j [PROOFSTEP] by_cases h : k = e j [GOAL] case pos J : Type w C : Type u inst✝³ : Category.{v, u} C inst✝² : HasZeroMorphisms C K : Type u_1 f : J → C g : K → C e : J ≃ K w : (j : J) → g (↑e j) ≅ f j inst✝¹ : HasBiproduct f inst✝ : HasBiproduct g j : J k : K h : k = ↑e j ⊢ ι g k ≫ (desc fun k => eqToHom (_ : g k = g (↑e (↑e.symm k))) ≫ (w (↑e.symm k)).hom ≫ ι (fun j => f j) (↑e.symm k)) ≫ π (fun j => f j) j = ι g k ≫ (lift fun j => π g (↑e j) ≫ (w j).hom) ≫ π (fun j => f j) j [PROOFSTEP] subst h [GOAL] case pos J : Type w C : Type u inst✝³ : Category.{v, u} C inst✝² : HasZeroMorphisms C K : Type u_1 f : J → C g : K → C e : J ≃ K w : (j : J) → g (↑e j) ≅ f j inst✝¹ : HasBiproduct f inst✝ : HasBiproduct g j : J ⊢ ι g (↑e j) ≫ (desc fun k => eqToHom (_ : g k = g (↑e (↑e.symm k))) ≫ (w (↑e.symm k)).hom ≫ ι (fun j => f j) (↑e.symm k)) ≫ π (fun j => f j) j = ι g (↑e j) ≫ (lift fun j => π g (↑e j) ≫ (w j).hom) ≫ π (fun j => f j) j [PROOFSTEP] simp only [ι_desc_assoc, ← eqToHom_iso_hom_naturality_assoc w (e.symm_apply_apply j).symm, Equiv.symm_apply_apply, eqToHom_comp_ι, Category.assoc, bicone_ι_π_self, Category.comp_id, lift_π, bicone_ι_π_self_assoc] [GOAL] case neg J : Type w C : Type u inst✝³ : Category.{v, u} C inst✝² : HasZeroMorphisms C K : Type u_1 f : J → C g : K → C e : J ≃ K w : (j : J) → g (↑e j) ≅ f j inst✝¹ : HasBiproduct f inst✝ : HasBiproduct g j : J k : K h : ¬k = ↑e j ⊢ ι g k ≫ (desc fun k => eqToHom (_ : g k = g (↑e (↑e.symm k))) ≫ (w (↑e.symm k)).hom ≫ ι (fun j => f j) (↑e.symm k)) ≫ π (fun j => f j) j = ι g k ≫ (lift fun j => π g (↑e j) ≫ (w j).hom) ≫ π (fun j => f j) j [PROOFSTEP] simp only [ι_desc_assoc, Category.assoc, ne_eq, lift_π] [GOAL] case neg J : Type w C : Type u inst✝³ : Category.{v, u} C inst✝² : HasZeroMorphisms C K : Type u_1 f : J → C g : K → C e : J ≃ K w : (j : J) → g (↑e j) ≅ f j inst✝¹ : HasBiproduct f inst✝ : HasBiproduct g j : J k : K h : ¬k = ↑e j ⊢ eqToHom (_ : g k = g (↑e (↑e.symm k))) ≫ (w (↑e.symm k)).hom ≫ ι (fun j => f j) (↑e.symm k) ≫ π (fun j => f j) j = ι g k ≫ π g (↑e j) ≫ (w j).hom [PROOFSTEP] rw [biproduct.ι_π_ne, biproduct.ι_π_ne_assoc] [GOAL] case neg J : Type w C : Type u inst✝³ : Category.{v, u} C inst✝² : HasZeroMorphisms C K : Type u_1 f : J → C g : K → C e : J ≃ K w : (j : J) → g (↑e j) ≅ f j inst✝¹ : HasBiproduct f inst✝ : HasBiproduct g j : J k : K h : ¬k = ↑e j ⊢ eqToHom (_ : g k = g (↑e (↑e.symm k))) ≫ (w (↑e.symm k)).hom ≫ 0 = 0 ≫ (w j).hom [PROOFSTEP] simp [GOAL] case neg.h J : Type w C : Type u inst✝³ : Category.{v, u} C inst✝² : HasZeroMorphisms C K : Type u_1 f : J → C g : K → C e : J ≃ K w : (j : J) → g (↑e j) ≅ f j inst✝¹ : HasBiproduct f inst✝ : HasBiproduct g j : J k : K h : ¬k = ↑e j ⊢ k ≠ ↑e j [PROOFSTEP] exact h [GOAL] case neg.h J : Type w C : Type u inst✝³ : Category.{v, u} C inst✝² : HasZeroMorphisms C K : Type u_1 f : J → C g : K → C e : J ≃ K w : (j : J) → g (↑e j) ≅ f j inst✝¹ : HasBiproduct f inst✝ : HasBiproduct g j : J k : K h : ¬k = ↑e j ⊢ ↑e.symm k ≠ j [PROOFSTEP] rintro rfl [GOAL] case neg.h J : Type w C : Type u inst✝³ : Category.{v, u} C inst✝² : HasZeroMorphisms C K : Type u_1 f : J → C g : K → C e : J ≃ K w : (j : J) → g (↑e j) ≅ f j inst✝¹ : HasBiproduct f inst✝ : HasBiproduct g k : K h : ¬k = ↑e (↑e.symm k) ⊢ False [PROOFSTEP] simp at h [GOAL] J : Type w C : Type u inst✝³ : Category.{v, u} C inst✝² : HasZeroMorphisms C ι : Type ?u.135486 f : ι → Type u_1 g : (i : ι) → f i → C inst✝¹ : ∀ (i : ι), HasBiproduct (g i) inst✝ : HasBiproduct fun i => ⨁ g i x✝¹ x✝ : (i : ι) × f i j : ι x : f j j' : ι y : f j' ⊢ (fun X => biproduct.ι (g X.fst) X.snd ≫ biproduct.ι (fun i => ⨁ g i) X.fst) { fst := j, snd := x } ≫ (fun X => biproduct.π (fun i => ⨁ g i) X.fst ≫ biproduct.π (g X.fst) X.snd) { fst := j', snd := y } = if h : { fst := j, snd := x } = { fst := j', snd := y } then eqToHom (_ : g { fst := j, snd := x }.fst { fst := j, snd := x }.snd = g { fst := j', snd := y }.fst { fst := j', snd := y }.snd) else 0 [PROOFSTEP] split_ifs with h [GOAL] case pos J : Type w C : Type u inst✝³ : Category.{v, u} C inst✝² : HasZeroMorphisms C ι : Type ?u.135486 f : ι → Type u_1 g : (i : ι) → f i → C inst✝¹ : ∀ (i : ι), HasBiproduct (g i) inst✝ : HasBiproduct fun i => ⨁ g i x✝¹ x✝ : (i : ι) × f i j : ι x : f j j' : ι y : f j' h : { fst := j, snd := x } = { fst := j', snd := y } ⊢ (fun X => biproduct.ι (g X.fst) X.snd ≫ biproduct.ι (fun i => ⨁ g i) X.fst) { fst := j, snd := x } ≫ (fun X => biproduct.π (fun i => ⨁ g i) X.fst ≫ biproduct.π (g X.fst) X.snd) { fst := j', snd := y } = eqToHom (_ : g { fst := j, snd := x }.fst { fst := j, snd := x }.snd = g { fst := j', snd := y }.fst { fst := j', snd := y }.snd) [PROOFSTEP] obtain ⟨rfl, rfl⟩ := h [GOAL] case pos.refl J : Type w C : Type u inst✝³ : Category.{v, u} C inst✝² : HasZeroMorphisms C ι : Type ?u.135486 f : ι → Type u_1 g : (i : ι) → f i → C inst✝¹ : ∀ (i : ι), HasBiproduct (g i) inst✝ : HasBiproduct fun i => ⨁ g i x✝¹ x✝ : (i : ι) × f i j : ι x : f j ⊢ (fun X => biproduct.ι (g X.fst) X.snd ≫ biproduct.ι (fun i => ⨁ g i) X.fst) { fst := j, snd := x } ≫ (fun X => biproduct.π (fun i => ⨁ g i) X.fst ≫ biproduct.π (g X.fst) X.snd) { fst := j, snd := x } = eqToHom (_ : g { fst := j, snd := x }.fst { fst := j, snd := x }.snd = g { fst := j, snd := x }.fst { fst := j, snd := x }.snd) [PROOFSTEP] simp [GOAL] case neg J : Type w C : Type u inst✝³ : Category.{v, u} C inst✝² : HasZeroMorphisms C ι : Type ?u.135486 f : ι → Type u_1 g : (i : ι) → f i → C inst✝¹ : ∀ (i : ι), HasBiproduct (g i) inst✝ : HasBiproduct fun i => ⨁ g i x✝¹ x✝ : (i : ι) × f i j : ι x : f j j' : ι y : f j' h : ¬{ fst := j, snd := x } = { fst := j', snd := y } ⊢ (fun X => biproduct.ι (g X.fst) X.snd ≫ biproduct.ι (fun i => ⨁ g i) X.fst) { fst := j, snd := x } ≫ (fun X => biproduct.π (fun i => ⨁ g i) X.fst ≫ biproduct.π (g X.fst) X.snd) { fst := j', snd := y } = 0 [PROOFSTEP] simp at h [GOAL] case neg J : Type w C : Type u inst✝³ : Category.{v, u} C inst✝² : HasZeroMorphisms C ι : Type ?u.135486 f : ι → Type u_1 g : (i : ι) → f i → C inst✝¹ : ∀ (i : ι), HasBiproduct (g i) inst✝ : HasBiproduct fun i => ⨁ g i x✝¹ x✝ : (i : ι) × f i j : ι x : f j j' : ι y : f j' h : j = j' → ¬HEq x y ⊢ (fun X => biproduct.ι (g X.fst) X.snd ≫ biproduct.ι (fun i => ⨁ g i) X.fst) { fst := j, snd := x } ≫ (fun X => biproduct.π (fun i => ⨁ g i) X.fst ≫ biproduct.π (g X.fst) X.snd) { fst := j', snd := y } = 0 [PROOFSTEP] by_cases w : j = j' [GOAL] case pos J : Type w C : Type u inst✝³ : Category.{v, u} C inst✝² : HasZeroMorphisms C ι : Type ?u.135486 f : ι → Type u_1 g : (i : ι) → f i → C inst✝¹ : ∀ (i : ι), HasBiproduct (g i) inst✝ : HasBiproduct fun i => ⨁ g i x✝¹ x✝ : (i : ι) × f i j : ι x : f j j' : ι y : f j' h : j = j' → ¬HEq x y w : j = j' ⊢ (fun X => biproduct.ι (g X.fst) X.snd ≫ biproduct.ι (fun i => ⨁ g i) X.fst) { fst := j, snd := x } ≫ (fun X => biproduct.π (fun i => ⨁ g i) X.fst ≫ biproduct.π (g X.fst) X.snd) { fst := j', snd := y } = 0 [PROOFSTEP] cases w [GOAL] case pos.refl J : Type w C : Type u inst✝³ : Category.{v, u} C inst✝² : HasZeroMorphisms C ι : Type ?u.135486 f : ι → Type u_1 g : (i : ι) → f i → C inst✝¹ : ∀ (i : ι), HasBiproduct (g i) inst✝ : HasBiproduct fun i => ⨁ g i x✝¹ x✝ : (i : ι) × f i j : ι x y : f j h : j = j → ¬HEq x y ⊢ (fun X => biproduct.ι (g X.fst) X.snd ≫ biproduct.ι (fun i => ⨁ g i) X.fst) { fst := j, snd := x } ≫ (fun X => biproduct.π (fun i => ⨁ g i) X.fst ≫ biproduct.π (g X.fst) X.snd) { fst := j, snd := y } = 0 [PROOFSTEP] simp at h [GOAL] case pos.refl J : Type w C : Type u inst✝³ : Category.{v, u} C inst✝² : HasZeroMorphisms C ι : Type ?u.135486 f : ι → Type u_1 g : (i : ι) → f i → C inst✝¹ : ∀ (i : ι), HasBiproduct (g i) inst✝ : HasBiproduct fun i => ⨁ g i x✝¹ x✝ : (i : ι) × f i j : ι x y : f j h : ¬x = y ⊢ (fun X => biproduct.ι (g X.fst) X.snd ≫ biproduct.ι (fun i => ⨁ g i) X.fst) { fst := j, snd := x } ≫ (fun X => biproduct.π (fun i => ⨁ g i) X.fst ≫ biproduct.π (g X.fst) X.snd) { fst := j, snd := y } = 0 [PROOFSTEP] simp [biproduct.ι_π_ne _ h] [GOAL] case neg J : Type w C : Type u inst✝³ : Category.{v, u} C inst✝² : HasZeroMorphisms C ι : Type ?u.135486 f : ι → Type u_1 g : (i : ι) → f i → C inst✝¹ : ∀ (i : ι), HasBiproduct (g i) inst✝ : HasBiproduct fun i => ⨁ g i x✝¹ x✝ : (i : ι) × f i j : ι x : f j j' : ι y : f j' h : j = j' → ¬HEq x y w : ¬j = j' ⊢ (fun X => biproduct.ι (g X.fst) X.snd ≫ biproduct.ι (fun i => ⨁ g i) X.fst) { fst := j, snd := x } ≫ (fun X => biproduct.π (fun i => ⨁ g i) X.fst ≫ biproduct.π (g X.fst) X.snd) { fst := j', snd := y } = 0 [PROOFSTEP] simp [biproduct.ι_π_ne_assoc _ w] [GOAL] J : Type w C : Type u inst✝⁴ : Category.{v, u} C inst✝³ : HasZeroMorphisms C f : J → C inst✝² : HasBiproduct f p : J → Prop inst✝¹ : HasBiproduct (Subtype.restrict p f) inst✝ : DecidablePred p j : J ⊢ fromSubtype f p ≫ π f j = if h : p j then π (Subtype.restrict p f) { val := j, property := h } else 0 [PROOFSTEP] ext i [GOAL] case w J : Type w C : Type u inst✝⁴ : Category.{v, u} C inst✝³ : HasZeroMorphisms C f : J → C inst✝² : HasBiproduct f p : J → Prop inst✝¹ : HasBiproduct (Subtype.restrict p f) inst✝ : DecidablePred p j : J i : Subtype p ⊢ ι (Subtype.restrict p f) i ≫ fromSubtype f p ≫ π f j = ι (Subtype.restrict p f) i ≫ if h : p j then π (Subtype.restrict p f) { val := j, property := h } else 0 [PROOFSTEP] dsimp [GOAL] case w J : Type w C : Type u inst✝⁴ : Category.{v, u} C inst✝³ : HasZeroMorphisms C f : J → C inst✝² : HasBiproduct f p : J → Prop inst✝¹ : HasBiproduct (Subtype.restrict p f) inst✝ : DecidablePred p j : J i : Subtype p ⊢ ι (Subtype.restrict p f) i ≫ fromSubtype f p ≫ π f j = ι (Subtype.restrict p f) i ≫ if h : p j then π (Subtype.restrict p f) { val := j, property := h } else 0 [PROOFSTEP] rw [biproduct.fromSubtype, biproduct.ι_desc_assoc, biproduct.ι_π] [GOAL] case w J : Type w C : Type u inst✝⁴ : Category.{v, u} C inst✝³ : HasZeroMorphisms C f : J → C inst✝² : HasBiproduct f p : J → Prop inst✝¹ : HasBiproduct (Subtype.restrict p f) inst✝ : DecidablePred p j : J i : Subtype p ⊢ (if h : ↑i = j then eqToHom (_ : f ↑i = f j) else 0) = ι (Subtype.restrict p f) i ≫ if h : p j then π (Subtype.restrict p f) { val := j, property := h } else 0 [PROOFSTEP] by_cases h : p j [GOAL] case pos J : Type w C : Type u inst✝⁴ : Category.{v, u} C inst✝³ : HasZeroMorphisms C f : J → C inst✝² : HasBiproduct f p : J → Prop inst✝¹ : HasBiproduct (Subtype.restrict p f) inst✝ : DecidablePred p j : J i : Subtype p h : p j ⊢ (if h : ↑i = j then eqToHom (_ : f ↑i = f j) else 0) = ι (Subtype.restrict p f) i ≫ if h : p j then π (Subtype.restrict p f) { val := j, property := h } else 0 [PROOFSTEP] rw [dif_pos h, biproduct.ι_π] [GOAL] case pos J : Type w C : Type u inst✝⁴ : Category.{v, u} C inst✝³ : HasZeroMorphisms C f : J → C inst✝² : HasBiproduct f p : J → Prop inst✝¹ : HasBiproduct (Subtype.restrict p f) inst✝ : DecidablePred p j : J i : Subtype p h : p j ⊢ (if h : ↑i = j then eqToHom (_ : f ↑i = f j) else 0) = if h_1 : i = { val := j, property := h } then eqToHom (_ : Subtype.restrict p f i = Subtype.restrict p f { val := j, property := h }) else 0 [PROOFSTEP] split_ifs with h₁ h₂ h₂ [GOAL] case pos J : Type w C : Type u inst✝⁴ : Category.{v, u} C inst✝³ : HasZeroMorphisms C f : J → C inst✝² : HasBiproduct f p : J → Prop inst✝¹ : HasBiproduct (Subtype.restrict p f) inst✝ : DecidablePred p j : J i : Subtype p h : p j h₁ : ↑i = j h₂ : i = { val := j, property := h } ⊢ eqToHom (_ : f ↑i = f j) = eqToHom (_ : Subtype.restrict p f i = Subtype.restrict p f { val := j, property := h }) case neg J : Type w C : Type u inst✝⁴ : Category.{v, u} C inst✝³ : HasZeroMorphisms C f : J → C inst✝² : HasBiproduct f p : J → Prop inst✝¹ : HasBiproduct (Subtype.restrict p f) inst✝ : DecidablePred p j : J i : Subtype p h : p j h₁ : ↑i = j h₂ : ¬i = { val := j, property := h } ⊢ eqToHom (_ : f ↑i = f j) = 0 case pos J : Type w C : Type u inst✝⁴ : Category.{v, u} C inst✝³ : HasZeroMorphisms C f : J → C inst✝² : HasBiproduct f p : J → Prop inst✝¹ : HasBiproduct (Subtype.restrict p f) inst✝ : DecidablePred p j : J i : Subtype p h : p j h₁ : ¬↑i = j h₂ : i = { val := j, property := h } ⊢ 0 = eqToHom (_ : Subtype.restrict p f i = Subtype.restrict p f { val := j, property := h }) case neg J : Type w C : Type u inst✝⁴ : Category.{v, u} C inst✝³ : HasZeroMorphisms C f : J → C inst✝² : HasBiproduct f p : J → Prop inst✝¹ : HasBiproduct (Subtype.restrict p f) inst✝ : DecidablePred p j : J i : Subtype p h : p j h₁ : ¬↑i = j h₂ : ¬i = { val := j, property := h } ⊢ 0 = 0 [PROOFSTEP] exacts [rfl, False.elim (h₂ (Subtype.ext h₁)), False.elim (h₁ (congr_arg Subtype.val h₂)), rfl] [GOAL] case neg J : Type w C : Type u inst✝⁴ : Category.{v, u} C inst✝³ : HasZeroMorphisms C f : J → C inst✝² : HasBiproduct f p : J → Prop inst✝¹ : HasBiproduct (Subtype.restrict p f) inst✝ : DecidablePred p j : J i : Subtype p h : ¬p j ⊢ (if h : ↑i = j then eqToHom (_ : f ↑i = f j) else 0) = ι (Subtype.restrict p f) i ≫ if h : p j then π (Subtype.restrict p f) { val := j, property := h } else 0 [PROOFSTEP] rw [dif_neg h, dif_neg (show (i : J) ≠ j from fun h₂ => h (h₂ ▸ i.2)), comp_zero] [GOAL] J : Type w C : Type u inst✝⁴ : Category.{v, u} C inst✝³ : HasZeroMorphisms C f : J → C inst✝² : HasBiproduct f p : J → Prop inst✝¹ : HasBiproduct (Subtype.restrict p f) inst✝ : DecidablePred p ⊢ ∀ (j : J), fromSubtype f p ≫ π f j = (lift fun j => if h : p j then π (Subtype.restrict p f) { val := j, property := h } else 0) ≫ π f j [PROOFSTEP] simp [GOAL] J : Type w C : Type u inst✝³ : Category.{v, u} C inst✝² : HasZeroMorphisms C f : J → C inst✝¹ : HasBiproduct f p : J → Prop inst✝ : HasBiproduct (Subtype.restrict p f) j : Subtype p ⊢ fromSubtype f p ≫ π f ↑j = π (Subtype.restrict p f) j [PROOFSTEP] ext [GOAL] case w J : Type w C : Type u inst✝³ : Category.{v, u} C inst✝² : HasZeroMorphisms C f : J → C inst✝¹ : HasBiproduct f p : J → Prop inst✝ : HasBiproduct (Subtype.restrict p f) j j✝ : Subtype p ⊢ ι (Subtype.restrict p f) j✝ ≫ fromSubtype f p ≫ π f ↑j = ι (Subtype.restrict p f) j✝ ≫ π (Subtype.restrict p f) j [PROOFSTEP] rw [biproduct.fromSubtype, biproduct.ι_desc_assoc, biproduct.ι_π, biproduct.ι_π] [GOAL] case w J : Type w C : Type u inst✝³ : Category.{v, u} C inst✝² : HasZeroMorphisms C f : J → C inst✝¹ : HasBiproduct f p : J → Prop inst✝ : HasBiproduct (Subtype.restrict p f) j j✝ : Subtype p ⊢ (if h : ↑j✝ = ↑j then eqToHom (_ : f ↑j✝ = f ↑j) else 0) = if h : j✝ = j then eqToHom (_ : Subtype.restrict p f j✝ = Subtype.restrict p f j) else 0 [PROOFSTEP] split_ifs with h₁ h₂ h₂ [GOAL] case pos J : Type w C : Type u inst✝³ : Category.{v, u} C inst✝² : HasZeroMorphisms C f : J → C inst✝¹ : HasBiproduct f p : J → Prop inst✝ : HasBiproduct (Subtype.restrict p f) j j✝ : Subtype p h₁ : ↑j✝ = ↑j h₂ : j✝ = j ⊢ eqToHom (_ : f ↑j✝ = f ↑j) = eqToHom (_ : Subtype.restrict p f j✝ = Subtype.restrict p f j) case neg J : Type w C : Type u inst✝³ : Category.{v, u} C inst✝² : HasZeroMorphisms C f : J → C inst✝¹ : HasBiproduct f p : J → Prop inst✝ : HasBiproduct (Subtype.restrict p f) j j✝ : Subtype p h₁ : ↑j✝ = ↑j h₂ : ¬j✝ = j ⊢ eqToHom (_ : f ↑j✝ = f ↑j) = 0 case pos J : Type w C : Type u inst✝³ : Category.{v, u} C inst✝² : HasZeroMorphisms C f : J → C inst✝¹ : HasBiproduct f p : J → Prop inst✝ : HasBiproduct (Subtype.restrict p f) j j✝ : Subtype p h₁ : ¬↑j✝ = ↑j h₂ : j✝ = j ⊢ 0 = eqToHom (_ : Subtype.restrict p f j✝ = Subtype.restrict p f j) case neg J : Type w C : Type u inst✝³ : Category.{v, u} C inst✝² : HasZeroMorphisms C f : J → C inst✝¹ : HasBiproduct f p : J → Prop inst✝ : HasBiproduct (Subtype.restrict p f) j j✝ : Subtype p h₁ : ¬↑j✝ = ↑j h₂ : ¬j✝ = j ⊢ 0 = 0 [PROOFSTEP] exacts [rfl, False.elim (h₂ (Subtype.ext h₁)), False.elim (h₁ (congr_arg Subtype.val h₂)), rfl] [GOAL] J : Type w C : Type u inst✝⁴ : Category.{v, u} C inst✝³ : HasZeroMorphisms C f : J → C inst✝² : HasBiproduct f p : J → Prop inst✝¹ : HasBiproduct (Subtype.restrict p f) inst✝ : DecidablePred p j : J ⊢ ι f j ≫ toSubtype f p = if h : p j then ι (Subtype.restrict p f) { val := j, property := h } else 0 [PROOFSTEP] ext i [GOAL] case w J : Type w C : Type u inst✝⁴ : Category.{v, u} C inst✝³ : HasZeroMorphisms C f : J → C inst✝² : HasBiproduct f p : J → Prop inst✝¹ : HasBiproduct (Subtype.restrict p f) inst✝ : DecidablePred p j : J i : Subtype p ⊢ (ι f j ≫ toSubtype f p) ≫ π (Subtype.restrict p f) i = (if h : p j then ι (Subtype.restrict p f) { val := j, property := h } else 0) ≫ π (Subtype.restrict p f) i [PROOFSTEP] rw [biproduct.toSubtype, Category.assoc, biproduct.lift_π, biproduct.ι_π] [GOAL] case w J : Type w C : Type u inst✝⁴ : Category.{v, u} C inst✝³ : HasZeroMorphisms C f : J → C inst✝² : HasBiproduct f p : J → Prop inst✝¹ : HasBiproduct (Subtype.restrict p f) inst✝ : DecidablePred p j : J i : Subtype p ⊢ (if h : j = ↑i then eqToHom (_ : f j = f ↑i) else 0) = (if h : p j then ι (Subtype.restrict p f) { val := j, property := h } else 0) ≫ π (Subtype.restrict p f) i [PROOFSTEP] by_cases h : p j [GOAL] case pos J : Type w C : Type u inst✝⁴ : Category.{v, u} C inst✝³ : HasZeroMorphisms C f : J → C inst✝² : HasBiproduct f p : J → Prop inst✝¹ : HasBiproduct (Subtype.restrict p f) inst✝ : DecidablePred p j : J i : Subtype p h : p j ⊢ (if h : j = ↑i then eqToHom (_ : f j = f ↑i) else 0) = (if h : p j then ι (Subtype.restrict p f) { val := j, property := h } else 0) ≫ π (Subtype.restrict p f) i [PROOFSTEP] rw [dif_pos h, biproduct.ι_π] [GOAL] case pos J : Type w C : Type u inst✝⁴ : Category.{v, u} C inst✝³ : HasZeroMorphisms C f : J → C inst✝² : HasBiproduct f p : J → Prop inst✝¹ : HasBiproduct (Subtype.restrict p f) inst✝ : DecidablePred p j : J i : Subtype p h : p j ⊢ (if h : j = ↑i then eqToHom (_ : f j = f ↑i) else 0) = if h_1 : { val := j, property := h } = i then eqToHom (_ : Subtype.restrict p f { val := j, property := h } = Subtype.restrict p f i) else 0 [PROOFSTEP] split_ifs with h₁ h₂ h₂ [GOAL] case pos J : Type w C : Type u inst✝⁴ : Category.{v, u} C inst✝³ : HasZeroMorphisms C f : J → C inst✝² : HasBiproduct f p : J → Prop inst✝¹ : HasBiproduct (Subtype.restrict p f) inst✝ : DecidablePred p j : J i : Subtype p h : p j h₁ : j = ↑i h₂ : { val := j, property := h } = i ⊢ eqToHom (_ : f j = f ↑i) = eqToHom (_ : Subtype.restrict p f { val := j, property := h } = Subtype.restrict p f i) case neg J : Type w C : Type u inst✝⁴ : Category.{v, u} C inst✝³ : HasZeroMorphisms C f : J → C inst✝² : HasBiproduct f p : J → Prop inst✝¹ : HasBiproduct (Subtype.restrict p f) inst✝ : DecidablePred p j : J i : Subtype p h : p j h₁ : j = ↑i h₂ : ¬{ val := j, property := h } = i ⊢ eqToHom (_ : f j = f ↑i) = 0 case pos J : Type w C : Type u inst✝⁴ : Category.{v, u} C inst✝³ : HasZeroMorphisms C f : J → C inst✝² : HasBiproduct f p : J → Prop inst✝¹ : HasBiproduct (Subtype.restrict p f) inst✝ : DecidablePred p j : J i : Subtype p h : p j h₁ : ¬j = ↑i h₂ : { val := j, property := h } = i ⊢ 0 = eqToHom (_ : Subtype.restrict p f { val := j, property := h } = Subtype.restrict p f i) case neg J : Type w C : Type u inst✝⁴ : Category.{v, u} C inst✝³ : HasZeroMorphisms C f : J → C inst✝² : HasBiproduct f p : J → Prop inst✝¹ : HasBiproduct (Subtype.restrict p f) inst✝ : DecidablePred p j : J i : Subtype p h : p j h₁ : ¬j = ↑i h₂ : ¬{ val := j, property := h } = i ⊢ 0 = 0 [PROOFSTEP] exacts [rfl, False.elim (h₂ (Subtype.ext h₁)), False.elim (h₁ (congr_arg Subtype.val h₂)), rfl] [GOAL] case neg J : Type w C : Type u inst✝⁴ : Category.{v, u} C inst✝³ : HasZeroMorphisms C f : J → C inst✝² : HasBiproduct f p : J → Prop inst✝¹ : HasBiproduct (Subtype.restrict p f) inst✝ : DecidablePred p j : J i : Subtype p h : ¬p j ⊢ (if h : j = ↑i then eqToHom (_ : f j = f ↑i) else 0) = (if h : p j then ι (Subtype.restrict p f) { val := j, property := h } else 0) ≫ π (Subtype.restrict p f) i [PROOFSTEP] rw [dif_neg h, dif_neg (show j ≠ i from fun h₂ => h (h₂.symm ▸ i.2)), zero_comp] [GOAL] J : Type w C : Type u inst✝⁴ : Category.{v, u} C inst✝³ : HasZeroMorphisms C f : J → C inst✝² : HasBiproduct f p : J → Prop inst✝¹ : HasBiproduct (Subtype.restrict p f) inst✝ : DecidablePred p ⊢ ∀ (j : J), ι f j ≫ toSubtype f p = ι f j ≫ desc fun j => if h : p j then ι (Subtype.restrict p f) { val := j, property := h } else 0 [PROOFSTEP] simp [GOAL] J : Type w C : Type u inst✝³ : Category.{v, u} C inst✝² : HasZeroMorphisms C f : J → C inst✝¹ : HasBiproduct f p : J → Prop inst✝ : HasBiproduct (Subtype.restrict p f) j : Subtype p ⊢ ι f ↑j ≫ toSubtype f p = ι (Subtype.restrict p f) j [PROOFSTEP] ext [GOAL] case w J : Type w C : Type u inst✝³ : Category.{v, u} C inst✝² : HasZeroMorphisms C f : J → C inst✝¹ : HasBiproduct f p : J → Prop inst✝ : HasBiproduct (Subtype.restrict p f) j j✝ : Subtype p ⊢ (ι f ↑j ≫ toSubtype f p) ≫ π (Subtype.restrict p f) j✝ = ι (Subtype.restrict p f) j ≫ π (Subtype.restrict p f) j✝ [PROOFSTEP] rw [biproduct.toSubtype, Category.assoc, biproduct.lift_π, biproduct.ι_π, biproduct.ι_π] [GOAL] case w J : Type w C : Type u inst✝³ : Category.{v, u} C inst✝² : HasZeroMorphisms C f : J → C inst✝¹ : HasBiproduct f p : J → Prop inst✝ : HasBiproduct (Subtype.restrict p f) j j✝ : Subtype p ⊢ (if h : ↑j = ↑j✝ then eqToHom (_ : f ↑j = f ↑j✝) else 0) = if h : j = j✝ then eqToHom (_ : Subtype.restrict p f j = Subtype.restrict p f j✝) else 0 [PROOFSTEP] split_ifs with h₁ h₂ h₂ [GOAL] case pos J : Type w C : Type u inst✝³ : Category.{v, u} C inst✝² : HasZeroMorphisms C f : J → C inst✝¹ : HasBiproduct f p : J → Prop inst✝ : HasBiproduct (Subtype.restrict p f) j j✝ : Subtype p h₁ : ↑j = ↑j✝ h₂ : j = j✝ ⊢ eqToHom (_ : f ↑j = f ↑j✝) = eqToHom (_ : Subtype.restrict p f j = Subtype.restrict p f j✝) case neg J : Type w C : Type u inst✝³ : Category.{v, u} C inst✝² : HasZeroMorphisms C f : J → C inst✝¹ : HasBiproduct f p : J → Prop inst✝ : HasBiproduct (Subtype.restrict p f) j j✝ : Subtype p h₁ : ↑j = ↑j✝ h₂ : ¬j = j✝ ⊢ eqToHom (_ : f ↑j = f ↑j✝) = 0 case pos J : Type w C : Type u inst✝³ : Category.{v, u} C inst✝² : HasZeroMorphisms C f : J → C inst✝¹ : HasBiproduct f p : J → Prop inst✝ : HasBiproduct (Subtype.restrict p f) j j✝ : Subtype p h₁ : ¬↑j = ↑j✝ h₂ : j = j✝ ⊢ 0 = eqToHom (_ : Subtype.restrict p f j = Subtype.restrict p f j✝) case neg J : Type w C : Type u inst✝³ : Category.{v, u} C inst✝² : HasZeroMorphisms C f : J → C inst✝¹ : HasBiproduct f p : J → Prop inst✝ : HasBiproduct (Subtype.restrict p f) j j✝ : Subtype p h₁ : ¬↑j = ↑j✝ h₂ : ¬j = j✝ ⊢ 0 = 0 [PROOFSTEP] exacts [rfl, False.elim (h₂ (Subtype.ext h₁)), False.elim (h₁ (congr_arg Subtype.val h₂)), rfl] [GOAL] J : Type w C : Type u inst✝³ : Category.{v, u} C inst✝² : HasZeroMorphisms C f : J → C inst✝¹ : HasBiproduct f p : J → Prop inst✝ : HasBiproduct (Subtype.restrict p f) ⊢ fromSubtype f p ≫ toSubtype f p = 𝟙 (⨁ Subtype.restrict p f) [PROOFSTEP] refine' biproduct.hom_ext _ _ fun j => _ [GOAL] J : Type w C : Type u inst✝³ : Category.{v, u} C inst✝² : HasZeroMorphisms C f : J → C inst✝¹ : HasBiproduct f p : J → Prop inst✝ : HasBiproduct (Subtype.restrict p f) j : Subtype p ⊢ (fromSubtype f p ≫ toSubtype f p) ≫ π (Subtype.restrict p f) j = 𝟙 (⨁ Subtype.restrict p f) ≫ π (Subtype.restrict p f) j [PROOFSTEP] rw [Category.assoc, biproduct.toSubtype_π, biproduct.fromSubtype_π_subtype, Category.id_comp] [GOAL] J : Type w C : Type u inst✝⁴ : Category.{v, u} C inst✝³ : HasZeroMorphisms C f : J → C inst✝² : HasBiproduct f p : J → Prop inst✝¹ : HasBiproduct (Subtype.restrict p f) inst✝ : DecidablePred p ⊢ toSubtype f p ≫ fromSubtype f p = map fun j => if p j then 𝟙 (f j) else 0 [PROOFSTEP] ext1 i [GOAL] case w J : Type w C : Type u inst✝⁴ : Category.{v, u} C inst✝³ : HasZeroMorphisms C f : J → C inst✝² : HasBiproduct f p : J → Prop inst✝¹ : HasBiproduct (Subtype.restrict p f) inst✝ : DecidablePred p i : J ⊢ (toSubtype f p ≫ fromSubtype f p) ≫ π f i = (map fun j => if p j then 𝟙 (f j) else 0) ≫ π f i [PROOFSTEP] by_cases h : p i [GOAL] case pos J : Type w C : Type u inst✝⁴ : Category.{v, u} C inst✝³ : HasZeroMorphisms C f : J → C inst✝² : HasBiproduct f p : J → Prop inst✝¹ : HasBiproduct (Subtype.restrict p f) inst✝ : DecidablePred p i : J h : p i ⊢ (toSubtype f p ≫ fromSubtype f p) ≫ π f i = (map fun j => if p j then 𝟙 (f j) else 0) ≫ π f i [PROOFSTEP] simp [h] [GOAL] case neg J : Type w C : Type u inst✝⁴ : Category.{v, u} C inst✝³ : HasZeroMorphisms C f : J → C inst✝² : HasBiproduct f p : J → Prop inst✝¹ : HasBiproduct (Subtype.restrict p f) inst✝ : DecidablePred p i : J h : ¬p i ⊢ (toSubtype f p ≫ fromSubtype f p) ≫ π f i = (map fun j => if p j then 𝟙 (f j) else 0) ≫ π f i [PROOFSTEP] simp [h] [GOAL] J : Type w C : Type u inst✝³ : Category.{v, u} C inst✝² : HasZeroMorphisms C f : J → C i : J inst✝¹ : HasBiproduct f inst✝ : HasBiproduct (Subtype.restrict (fun j => j ≠ i) f) ⊢ (fromSubtype f fun j => j ≠ i) ≫ π f i = 0 [PROOFSTEP] simp [GOAL] J : Type w C : Type u inst✝³ : Category.{v, u} C inst✝² : HasZeroMorphisms C f : J → C i : J inst✝¹ : HasBiproduct f inst✝ : HasBiproduct (Subtype.restrict (fun j => j ≠ i) f) s : Fork (π f i) 0 ⊢ (Fork.ι s ≫ toSubtype f fun j => j ≠ i) ≫ Fork.ι (KernelFork.ofι (fromSubtype f fun j => j ≠ i) (_ : (fromSubtype f fun j => ¬j = i) ≫ π f i = 0)) = Fork.ι s [PROOFSTEP] apply biproduct.hom_ext [GOAL] case w J : Type w C : Type u inst✝³ : Category.{v, u} C inst✝² : HasZeroMorphisms C f : J → C i : J inst✝¹ : HasBiproduct f inst✝ : HasBiproduct (Subtype.restrict (fun j => j ≠ i) f) s : Fork (π f i) 0 ⊢ ∀ (j : J), ((Fork.ι s ≫ toSubtype f fun j => j ≠ i) ≫ Fork.ι (KernelFork.ofι (fromSubtype f fun j => j ≠ i) (_ : (fromSubtype f fun j => ¬j = i) ≫ π f i = 0))) ≫ π f j = Fork.ι s ≫ π f j [PROOFSTEP] intro j [GOAL] case w J : Type w C : Type u inst✝³ : Category.{v, u} C inst✝² : HasZeroMorphisms C f : J → C i : J inst✝¹ : HasBiproduct f inst✝ : HasBiproduct (Subtype.restrict (fun j => j ≠ i) f) s : Fork (π f i) 0 j : J ⊢ ((Fork.ι s ≫ toSubtype f fun j => j ≠ i) ≫ Fork.ι (KernelFork.ofι (fromSubtype f fun j => j ≠ i) (_ : (fromSubtype f fun j => ¬j = i) ≫ π f i = 0))) ≫ π f j = Fork.ι s ≫ π f j [PROOFSTEP] rw [KernelFork.ι_ofι, Category.assoc, Category.assoc, biproduct.toSubtype_fromSubtype_assoc, biproduct.map_π] [GOAL] case w J : Type w C : Type u inst✝³ : Category.{v, u} C inst✝² : HasZeroMorphisms C f : J → C i : J inst✝¹ : HasBiproduct f inst✝ : HasBiproduct (Subtype.restrict (fun j => j ≠ i) f) s : Fork (π f i) 0 j : J ⊢ (Fork.ι s ≫ π (fun j => f j) j ≫ if j ≠ i then 𝟙 (f j) else 0) = Fork.ι s ≫ π f j [PROOFSTEP] rcases Classical.em (i = j) with (rfl | h) [GOAL] case w.inl J : Type w C : Type u inst✝³ : Category.{v, u} C inst✝² : HasZeroMorphisms C f : J → C i : J inst✝¹ : HasBiproduct f inst✝ : HasBiproduct (Subtype.restrict (fun j => j ≠ i) f) s : Fork (π f i) 0 ⊢ (Fork.ι s ≫ π (fun j => f j) i ≫ if i ≠ i then 𝟙 (f i) else 0) = Fork.ι s ≫ π f i [PROOFSTEP] rw [if_neg (Classical.not_not.2 rfl), comp_zero, comp_zero, KernelFork.condition] [GOAL] case w.inr J : Type w C : Type u inst✝³ : Category.{v, u} C inst✝² : HasZeroMorphisms C f : J → C i : J inst✝¹ : HasBiproduct f inst✝ : HasBiproduct (Subtype.restrict (fun j => j ≠ i) f) s : Fork (π f i) 0 j : J h : ¬i = j ⊢ (Fork.ι s ≫ π (fun j => f j) j ≫ if j ≠ i then 𝟙 (f j) else 0) = Fork.ι s ≫ π f j [PROOFSTEP] rw [if_pos (Ne.symm h), Category.comp_id] [GOAL] J : Type w C : Type u inst✝³ : Category.{v, u} C inst✝² : HasZeroMorphisms C f : J → C i : J inst✝¹ : HasBiproduct f inst✝ : HasBiproduct (Subtype.restrict (fun j => j ≠ i) f) s : Fork (π f i) 0 ⊢ ∀ {m : ((const WalkingParallelPair).obj s.pt).obj WalkingParallelPair.zero ⟶ ((const WalkingParallelPair).obj (KernelFork.ofι (fromSubtype f fun j => j ≠ i) (_ : (fromSubtype f fun j => ¬j = i) ≫ π f i = 0)).pt).obj WalkingParallelPair.zero}, m ≫ Fork.ι (KernelFork.ofι (fromSubtype f fun j => j ≠ i) (_ : (fromSubtype f fun j => ¬j = i) ≫ π f i = 0)) = Fork.ι s → m = Fork.ι s ≫ toSubtype f fun j => j ≠ i [PROOFSTEP] intro m hm [GOAL] J : Type w C : Type u inst✝³ : Category.{v, u} C inst✝² : HasZeroMorphisms C f : J → C i : J inst✝¹ : HasBiproduct f inst✝ : HasBiproduct (Subtype.restrict (fun j => j ≠ i) f) s : Fork (π f i) 0 m : ((const WalkingParallelPair).obj s.pt).obj WalkingParallelPair.zero ⟶ ((const WalkingParallelPair).obj (KernelFork.ofι (fromSubtype f fun j => j ≠ i) (_ : (fromSubtype f fun j => ¬j = i) ≫ π f i = 0)).pt).obj WalkingParallelPair.zero hm : m ≫ Fork.ι (KernelFork.ofι (fromSubtype f fun j => j ≠ i) (_ : (fromSubtype f fun j => ¬j = i) ≫ π f i = 0)) = Fork.ι s ⊢ m = Fork.ι s ≫ toSubtype f fun j => j ≠ i [PROOFSTEP] rw [← hm, KernelFork.ι_ofι, Category.assoc, biproduct.fromSubtype_toSubtype] [GOAL] J : Type w C : Type u inst✝³ : Category.{v, u} C inst✝² : HasZeroMorphisms C f : J → C i : J inst✝¹ : HasBiproduct f inst✝ : HasBiproduct (Subtype.restrict (fun j => j ≠ i) f) s : Fork (π f i) 0 m : ((const WalkingParallelPair).obj s.pt).obj WalkingParallelPair.zero ⟶ ((const WalkingParallelPair).obj (KernelFork.ofι (fromSubtype f fun j => j ≠ i) (_ : (fromSubtype f fun j => ¬j = i) ≫ π f i = 0)).pt).obj WalkingParallelPair.zero hm : m ≫ Fork.ι (KernelFork.ofι (fromSubtype f fun j => j ≠ i) (_ : (fromSubtype f fun j => ¬j = i) ≫ π f i = 0)) = Fork.ι s ⊢ m = m ≫ 𝟙 (⨁ Subtype.restrict (fun j => j ≠ i) f) [PROOFSTEP] exact (Category.comp_id _).symm [GOAL] J : Type w C : Type u inst✝³ : Category.{v, u} C inst✝² : HasZeroMorphisms C f : J → C i : J inst✝¹ : HasBiproduct f inst✝ : HasBiproduct (Subtype.restrict (fun j => j ≠ i) f) ⊢ (ι f i ≫ toSubtype f fun j => j ≠ i) = 0 [PROOFSTEP] simp [GOAL] J : Type w C : Type u inst✝³ : Category.{v, u} C inst✝² : HasZeroMorphisms C f : J → C i : J inst✝¹ : HasBiproduct f inst✝ : HasBiproduct (Subtype.restrict (fun j => j ≠ i) f) s : Cofork (ι f i) 0 ⊢ Cofork.π (CokernelCofork.ofπ (toSubtype f fun j => j ≠ i) (_ : (ι f i ≫ toSubtype f fun j => ¬j = i) = 0)) ≫ (fromSubtype f fun j => j ≠ i) ≫ Cofork.π s = Cofork.π s [PROOFSTEP] apply biproduct.hom_ext' [GOAL] case w J : Type w C : Type u inst✝³ : Category.{v, u} C inst✝² : HasZeroMorphisms C f : J → C i : J inst✝¹ : HasBiproduct f inst✝ : HasBiproduct (Subtype.restrict (fun j => j ≠ i) f) s : Cofork (ι f i) 0 ⊢ ∀ (j : J), ι f j ≫ Cofork.π (CokernelCofork.ofπ (toSubtype f fun j => j ≠ i) (_ : (ι f i ≫ toSubtype f fun j => ¬j = i) = 0)) ≫ (fromSubtype f fun j => j ≠ i) ≫ Cofork.π s = ι f j ≫ Cofork.π s [PROOFSTEP] intro j [GOAL] case w J : Type w C : Type u inst✝³ : Category.{v, u} C inst✝² : HasZeroMorphisms C f : J → C i : J inst✝¹ : HasBiproduct f inst✝ : HasBiproduct (Subtype.restrict (fun j => j ≠ i) f) s : Cofork (ι f i) 0 j : J ⊢ ι f j ≫ Cofork.π (CokernelCofork.ofπ (toSubtype f fun j => j ≠ i) (_ : (ι f i ≫ toSubtype f fun j => ¬j = i) = 0)) ≫ (fromSubtype f fun j => j ≠ i) ≫ Cofork.π s = ι f j ≫ Cofork.π s [PROOFSTEP] rw [CokernelCofork.π_ofπ, biproduct.toSubtype_fromSubtype_assoc, biproduct.ι_map_assoc] [GOAL] case w J : Type w C : Type u inst✝³ : Category.{v, u} C inst✝² : HasZeroMorphisms C f : J → C i : J inst✝¹ : HasBiproduct f inst✝ : HasBiproduct (Subtype.restrict (fun j => j ≠ i) f) s : Cofork (ι f i) 0 j : J ⊢ (if j ≠ i then 𝟙 (f j) else 0) ≫ ι (fun j => f j) j ≫ Cofork.π s = ι f j ≫ Cofork.π s [PROOFSTEP] rcases Classical.em (i = j) with (rfl | h) [GOAL] case w.inl J : Type w C : Type u inst✝³ : Category.{v, u} C inst✝² : HasZeroMorphisms C f : J → C i : J inst✝¹ : HasBiproduct f inst✝ : HasBiproduct (Subtype.restrict (fun j => j ≠ i) f) s : Cofork (ι f i) 0 ⊢ (if i ≠ i then 𝟙 (f i) else 0) ≫ ι (fun j => f j) i ≫ Cofork.π s = ι f i ≫ Cofork.π s [PROOFSTEP] rw [if_neg (Classical.not_not.2 rfl), zero_comp, CokernelCofork.condition] [GOAL] case w.inr J : Type w C : Type u inst✝³ : Category.{v, u} C inst✝² : HasZeroMorphisms C f : J → C i : J inst✝¹ : HasBiproduct f inst✝ : HasBiproduct (Subtype.restrict (fun j => j ≠ i) f) s : Cofork (ι f i) 0 j : J h : ¬i = j ⊢ (if j ≠ i then 𝟙 (f j) else 0) ≫ ι (fun j => f j) j ≫ Cofork.π s = ι f j ≫ Cofork.π s [PROOFSTEP] rw [if_pos (Ne.symm h), Category.id_comp] [GOAL] J : Type w C : Type u inst✝³ : Category.{v, u} C inst✝² : HasZeroMorphisms C f : J → C i : J inst✝¹ : HasBiproduct f inst✝ : HasBiproduct (Subtype.restrict (fun j => j ≠ i) f) s : Cofork (ι f i) 0 ⊢ ∀ {m : ((const WalkingParallelPair).obj (CokernelCofork.ofπ (toSubtype f fun j => j ≠ i) (_ : (ι f i ≫ toSubtype f fun j => ¬j = i) = 0)).pt).obj WalkingParallelPair.one ⟶ ((const WalkingParallelPair).obj s.pt).obj WalkingParallelPair.one}, Cofork.π (CokernelCofork.ofπ (toSubtype f fun j => j ≠ i) (_ : (ι f i ≫ toSubtype f fun j => ¬j = i) = 0)) ≫ m = Cofork.π s → m = (fromSubtype f fun j => j ≠ i) ≫ Cofork.π s [PROOFSTEP] intro m hm [GOAL] J : Type w C : Type u inst✝³ : Category.{v, u} C inst✝² : HasZeroMorphisms C f : J → C i : J inst✝¹ : HasBiproduct f inst✝ : HasBiproduct (Subtype.restrict (fun j => j ≠ i) f) s : Cofork (ι f i) 0 m : ((const WalkingParallelPair).obj (CokernelCofork.ofπ (toSubtype f fun j => j ≠ i) (_ : (ι f i ≫ toSubtype f fun j => ¬j = i) = 0)).pt).obj WalkingParallelPair.one ⟶ ((const WalkingParallelPair).obj s.pt).obj WalkingParallelPair.one hm : Cofork.π (CokernelCofork.ofπ (toSubtype f fun j => j ≠ i) (_ : (ι f i ≫ toSubtype f fun j => ¬j = i) = 0)) ≫ m = Cofork.π s ⊢ m = (fromSubtype f fun j => j ≠ i) ≫ Cofork.π s [PROOFSTEP] rw [← hm, CokernelCofork.π_ofπ, ← Category.assoc, biproduct.fromSubtype_toSubtype] [GOAL] J : Type w C : Type u inst✝³ : Category.{v, u} C inst✝² : HasZeroMorphisms C f : J → C i : J inst✝¹ : HasBiproduct f inst✝ : HasBiproduct (Subtype.restrict (fun j => j ≠ i) f) s : Cofork (ι f i) 0 m : ((const WalkingParallelPair).obj (CokernelCofork.ofπ (toSubtype f fun j => j ≠ i) (_ : (ι f i ≫ toSubtype f fun j => ¬j = i) = 0)).pt).obj WalkingParallelPair.one ⟶ ((const WalkingParallelPair).obj s.pt).obj WalkingParallelPair.one hm : Cofork.π (CokernelCofork.ofπ (toSubtype f fun j => j ≠ i) (_ : (ι f i ≫ toSubtype f fun j => ¬j = i) = 0)) ≫ m = Cofork.π s ⊢ m = 𝟙 (⨁ Subtype.restrict (fun j => j ≠ i) f) ≫ m [PROOFSTEP] exact (Category.id_comp _).symm [GOAL] J : Type w C : Type u inst✝³ : Category.{v, u} C inst✝² : HasZeroMorphisms C K : Type inst✝¹ : Fintype K inst✝ : HasFiniteBiproducts C f : K → C p : Set K ⊢ biproduct.fromSubtype f pᶜ ≫ biproduct.toSubtype f p = 0 [PROOFSTEP] ext j k [GOAL] case w.w J : Type w C : Type u inst✝³ : Category.{v, u} C inst✝² : HasZeroMorphisms C K : Type inst✝¹ : Fintype K inst✝ : HasFiniteBiproducts C f : K → C p : Set K j : Subtype p k : Subtype pᶜ ⊢ biproduct.ι (Subtype.restrict pᶜ f) k ≫ (biproduct.fromSubtype f pᶜ ≫ biproduct.toSubtype f p) ≫ biproduct.π (Subtype.restrict p f) j = biproduct.ι (Subtype.restrict pᶜ f) k ≫ 0 ≫ biproduct.π (Subtype.restrict p f) j [PROOFSTEP] simp only [Category.assoc, biproduct.ι_fromSubtype_assoc, biproduct.ι_toSubtype_assoc, comp_zero, zero_comp] [GOAL] case w.w J : Type w C : Type u inst✝³ : Category.{v, u} C inst✝² : HasZeroMorphisms C K : Type inst✝¹ : Fintype K inst✝ : HasFiniteBiproducts C f : K → C p : Set K j : Subtype p k : Subtype pᶜ ⊢ (if h : p ↑k then biproduct.ι (Subtype.restrict p f) { val := ↑k, property := h } else 0) ≫ biproduct.π (Subtype.restrict p f) j = 0 [PROOFSTEP] erw [dif_neg k.2] [GOAL] case w.w J : Type w C : Type u inst✝³ : Category.{v, u} C inst✝² : HasZeroMorphisms C K : Type inst✝¹ : Fintype K inst✝ : HasFiniteBiproducts C f : K → C p : Set K j : Subtype p k : Subtype pᶜ ⊢ 0 ≫ biproduct.π (Subtype.restrict p f) j = 0 [PROOFSTEP] simp only [zero_comp] [GOAL] J : Type w C : Type u inst✝³ : Category.{v, u} C inst✝² : HasZeroMorphisms C K : Type inst✝¹ : Fintype K inst✝ : HasFiniteBiproducts C f : K → C p : Set K ⊢ ∀ {W' : C} (g' : W' ⟶ ⨁ f) (eq' : g' ≫ biproduct.toSubtype f p = 0), (fun {W} g x => g ≫ biproduct.toSubtype f pᶜ) g' eq' ≫ biproduct.fromSubtype f pᶜ = g' [PROOFSTEP] intro W' g' w [GOAL] J : Type w C : Type u inst✝³ : Category.{v, u} C inst✝² : HasZeroMorphisms C K : Type inst✝¹ : Fintype K inst✝ : HasFiniteBiproducts C f : K → C p : Set K W' : C g' : W' ⟶ ⨁ f w : g' ≫ biproduct.toSubtype f p = 0 ⊢ (fun {W} g x => g ≫ biproduct.toSubtype f pᶜ) g' w ≫ biproduct.fromSubtype f pᶜ = g' [PROOFSTEP] ext j [GOAL] case w J : Type w C : Type u inst✝³ : Category.{v, u} C inst✝² : HasZeroMorphisms C K : Type inst✝¹ : Fintype K inst✝ : HasFiniteBiproducts C f : K → C p : Set K W' : C g' : W' ⟶ ⨁ f w : g' ≫ biproduct.toSubtype f p = 0 j : K ⊢ ((fun {W} g x => g ≫ biproduct.toSubtype f pᶜ) g' w ≫ biproduct.fromSubtype f pᶜ) ≫ biproduct.π f j = g' ≫ biproduct.π f j [PROOFSTEP] simp only [Category.assoc, biproduct.toSubtype_fromSubtype, Pi.compl_apply, biproduct.map_π] [GOAL] case w J : Type w C : Type u inst✝³ : Category.{v, u} C inst✝² : HasZeroMorphisms C K : Type inst✝¹ : Fintype K inst✝ : HasFiniteBiproducts C f : K → C p : Set K W' : C g' : W' ⟶ ⨁ f w : g' ≫ biproduct.toSubtype f p = 0 j : K ⊢ (g' ≫ biproduct.π (fun b => f b) j ≫ if (p j)ᶜ then 𝟙 (f j) else 0) = g' ≫ biproduct.π f j [PROOFSTEP] split_ifs with h [GOAL] case pos J : Type w C : Type u inst✝³ : Category.{v, u} C inst✝² : HasZeroMorphisms C K : Type inst✝¹ : Fintype K inst✝ : HasFiniteBiproducts C f : K → C p : Set K W' : C g' : W' ⟶ ⨁ f w : g' ≫ biproduct.toSubtype f p = 0 j : K h : (p j)ᶜ ⊢ g' ≫ biproduct.π (fun b => f b) j ≫ 𝟙 (f j) = g' ≫ biproduct.π f j [PROOFSTEP] simp [GOAL] case neg J : Type w C : Type u inst✝³ : Category.{v, u} C inst✝² : HasZeroMorphisms C K : Type inst✝¹ : Fintype K inst✝ : HasFiniteBiproducts C f : K → C p : Set K W' : C g' : W' ⟶ ⨁ f w : g' ≫ biproduct.toSubtype f p = 0 j : K h : ¬(p j)ᶜ ⊢ g' ≫ biproduct.π (fun b => f b) j ≫ 0 = g' ≫ biproduct.π f j [PROOFSTEP] replace w := w =≫ biproduct.π _ ⟨j, not_not.mp h⟩ [GOAL] case neg J : Type w C : Type u inst✝³ : Category.{v, u} C inst✝² : HasZeroMorphisms C K : Type inst✝¹ : Fintype K inst✝ : HasFiniteBiproducts C f : K → C p : Set K W' : C g' : W' ⟶ ⨁ f j : K h : ¬(p j)ᶜ w : (g' ≫ biproduct.toSubtype f p) ≫ biproduct.π (Subtype.restrict p f) { val := j, property := (_ : p j) } = 0 ≫ biproduct.π (Subtype.restrict p f) { val := j, property := (_ : p j) } ⊢ g' ≫ biproduct.π (fun b => f b) j ≫ 0 = g' ≫ biproduct.π f j [PROOFSTEP] simpa using w.symm [GOAL] J : Type w C : Type u inst✝³ : Category.{v, u} C inst✝² : HasZeroMorphisms C K : Type inst✝¹ : Fintype K inst✝ : HasFiniteBiproducts C f : K → C p : Set K ⊢ ∀ {W' : C} (g' : W' ⟶ ⨁ f) (eq' : g' ≫ biproduct.toSubtype f p = 0) (m : W' ⟶ ⨁ Subtype.restrict pᶜ f), m ≫ biproduct.fromSubtype f pᶜ = g' → m = (fun {W} g x => g ≫ biproduct.toSubtype f pᶜ) g' eq' [PROOFSTEP] aesop_cat [GOAL] J : Type w C : Type u inst✝³ : Category.{v, u} C inst✝² : HasZeroMorphisms C K : Type inst✝¹ : Fintype K inst✝ : HasFiniteBiproducts C f : K → C p : Set K ⊢ biproduct.fromSubtype f p ≫ biproduct.toSubtype f pᶜ = 0 [PROOFSTEP] ext j k [GOAL] case w.w J : Type w C : Type u inst✝³ : Category.{v, u} C inst✝² : HasZeroMorphisms C K : Type inst✝¹ : Fintype K inst✝ : HasFiniteBiproducts C f : K → C p : Set K j : Subtype pᶜ k : Subtype p ⊢ biproduct.ι (Subtype.restrict p f) k ≫ (biproduct.fromSubtype f p ≫ biproduct.toSubtype f pᶜ) ≫ biproduct.π (Subtype.restrict pᶜ f) j = biproduct.ι (Subtype.restrict p f) k ≫ 0 ≫ biproduct.π (Subtype.restrict pᶜ f) j [PROOFSTEP] simp only [Category.assoc, Pi.compl_apply, biproduct.ι_fromSubtype_assoc, biproduct.ι_toSubtype_assoc, comp_zero, zero_comp] [GOAL] case w.w J : Type w C : Type u inst✝³ : Category.{v, u} C inst✝² : HasZeroMorphisms C K : Type inst✝¹ : Fintype K inst✝ : HasFiniteBiproducts C f : K → C p : Set K j : Subtype pᶜ k : Subtype p ⊢ (if h : (p ↑k)ᶜ then biproduct.ι (Subtype.restrict pᶜ f) { val := ↑k, property := (_ : (p ↑k)ᶜ) } else 0) ≫ biproduct.π (Subtype.restrict pᶜ f) j = 0 [PROOFSTEP] rw [dif_neg] [GOAL] case w.w J : Type w C : Type u inst✝³ : Category.{v, u} C inst✝² : HasZeroMorphisms C K : Type inst✝¹ : Fintype K inst✝ : HasFiniteBiproducts C f : K → C p : Set K j : Subtype pᶜ k : Subtype p ⊢ 0 ≫ biproduct.π (Subtype.restrict pᶜ f) j = 0 case w.w.hnc J : Type w C : Type u inst✝³ : Category.{v, u} C inst✝² : HasZeroMorphisms C K : Type inst✝¹ : Fintype K inst✝ : HasFiniteBiproducts C f : K → C p : Set K j : Subtype pᶜ k : Subtype p ⊢ ¬(p ↑k)ᶜ [PROOFSTEP] simp only [zero_comp] [GOAL] case w.w.hnc J : Type w C : Type u inst✝³ : Category.{v, u} C inst✝² : HasZeroMorphisms C K : Type inst✝¹ : Fintype K inst✝ : HasFiniteBiproducts C f : K → C p : Set K j : Subtype pᶜ k : Subtype p ⊢ ¬(p ↑k)ᶜ [PROOFSTEP] exact not_not.mpr k.2 [GOAL] J : Type w C : Type u inst✝³ : Category.{v, u} C inst✝² : HasZeroMorphisms C K : Type inst✝¹ : Fintype K inst✝ : HasFiniteBiproducts C f : K → C p : Set K ⊢ ∀ {Z' : C} (g' : ⨁ f ⟶ Z') (eq' : biproduct.fromSubtype f p ≫ g' = 0), biproduct.toSubtype f pᶜ ≫ (fun {W} g x => biproduct.fromSubtype f pᶜ ≫ g) g' eq' = g' [PROOFSTEP] intro W g' w [GOAL] J : Type w C : Type u inst✝³ : Category.{v, u} C inst✝² : HasZeroMorphisms C K : Type inst✝¹ : Fintype K inst✝ : HasFiniteBiproducts C f : K → C p : Set K W : C g' : ⨁ f ⟶ W w : biproduct.fromSubtype f p ≫ g' = 0 ⊢ biproduct.toSubtype f pᶜ ≫ (fun {W} g x => biproduct.fromSubtype f pᶜ ≫ g) g' w = g' [PROOFSTEP] ext j [GOAL] case w J : Type w C : Type u inst✝³ : Category.{v, u} C inst✝² : HasZeroMorphisms C K : Type inst✝¹ : Fintype K inst✝ : HasFiniteBiproducts C f : K → C p : Set K W : C g' : ⨁ f ⟶ W w : biproduct.fromSubtype f p ≫ g' = 0 j : K ⊢ biproduct.ι f j ≫ biproduct.toSubtype f pᶜ ≫ (fun {W} g x => biproduct.fromSubtype f pᶜ ≫ g) g' w = biproduct.ι f j ≫ g' [PROOFSTEP] simp only [biproduct.toSubtype_fromSubtype_assoc, Pi.compl_apply, biproduct.ι_map_assoc] [GOAL] case w J : Type w C : Type u inst✝³ : Category.{v, u} C inst✝² : HasZeroMorphisms C K : Type inst✝¹ : Fintype K inst✝ : HasFiniteBiproducts C f : K → C p : Set K W : C g' : ⨁ f ⟶ W w : biproduct.fromSubtype f p ≫ g' = 0 j : K ⊢ (if (p j)ᶜ then 𝟙 (f j) else 0) ≫ biproduct.ι (fun b => f b) j ≫ g' = biproduct.ι f j ≫ g' [PROOFSTEP] split_ifs with h [GOAL] case pos J : Type w C : Type u inst✝³ : Category.{v, u} C inst✝² : HasZeroMorphisms C K : Type inst✝¹ : Fintype K inst✝ : HasFiniteBiproducts C f : K → C p : Set K W : C g' : ⨁ f ⟶ W w : biproduct.fromSubtype f p ≫ g' = 0 j : K h : (p j)ᶜ ⊢ 𝟙 (f j) ≫ biproduct.ι (fun b => f b) j ≫ g' = biproduct.ι f j ≫ g' [PROOFSTEP] simp [GOAL] case neg J : Type w C : Type u inst✝³ : Category.{v, u} C inst✝² : HasZeroMorphisms C K : Type inst✝¹ : Fintype K inst✝ : HasFiniteBiproducts C f : K → C p : Set K W : C g' : ⨁ f ⟶ W w : biproduct.fromSubtype f p ≫ g' = 0 j : K h : ¬(p j)ᶜ ⊢ 0 ≫ biproduct.ι (fun b => f b) j ≫ g' = biproduct.ι f j ≫ g' [PROOFSTEP] replace w := biproduct.ι _ (⟨j, not_not.mp h⟩ : p) ≫= w [GOAL] case neg J : Type w C : Type u inst✝³ : Category.{v, u} C inst✝² : HasZeroMorphisms C K : Type inst✝¹ : Fintype K inst✝ : HasFiniteBiproducts C f : K → C p : Set K W : C g' : ⨁ f ⟶ W j : K h : ¬(p j)ᶜ w : biproduct.ι (Subtype.restrict p f) { val := j, property := (_ : j ∈ p) } ≫ biproduct.fromSubtype f p ≫ g' = biproduct.ι (Subtype.restrict p f) { val := j, property := (_ : j ∈ p) } ≫ 0 ⊢ 0 ≫ biproduct.ι (fun b => f b) j ≫ g' = biproduct.ι f j ≫ g' [PROOFSTEP] simpa using w.symm [GOAL] J : Type w C : Type u inst✝³ : Category.{v, u} C inst✝² : HasZeroMorphisms C K : Type inst✝¹ : Fintype K inst✝ : HasFiniteBiproducts C f : K → C p : Set K ⊢ ∀ {Z' : C} (g' : ⨁ f ⟶ Z') (eq' : biproduct.fromSubtype f p ≫ g' = 0) (m : ⨁ Subtype.restrict pᶜ f ⟶ Z'), biproduct.toSubtype f pᶜ ≫ m = g' → m = (fun {W} g x => biproduct.fromSubtype f pᶜ ≫ g) g' eq' [PROOFSTEP] aesop_cat [GOAL] J : Type inst✝⁴ : Fintype J K : Type inst✝³ : Fintype K C : Type u inst✝² : Category.{v, u} C inst✝¹ : HasZeroMorphisms C inst✝ : HasFiniteBiproducts C f : J → C g : K → C m : (j : J) → (k : K) → f j ⟶ g k k : K ⊢ matrix m ≫ π g k = desc fun j => m j k [PROOFSTEP] ext [GOAL] case w J : Type inst✝⁴ : Fintype J K : Type inst✝³ : Fintype K C : Type u inst✝² : Category.{v, u} C inst✝¹ : HasZeroMorphisms C inst✝ : HasFiniteBiproducts C f : J → C g : K → C m : (j : J) → (k : K) → f j ⟶ g k k : K j✝ : J ⊢ ι (fun j => f j) j✝ ≫ matrix m ≫ π g k = ι (fun j => f j) j✝ ≫ desc fun j => m j k [PROOFSTEP] simp [biproduct.matrix] [GOAL] J : Type inst✝⁴ : Fintype J K : Type inst✝³ : Fintype K C : Type u inst✝² : Category.{v, u} C inst✝¹ : HasZeroMorphisms C inst✝ : HasFiniteBiproducts C f : J → C g : K → C m : (j : J) → (k : K) → f j ⟶ g k j : J ⊢ ι f j ≫ matrix m = lift fun k => m j k [PROOFSTEP] ext [GOAL] case w J : Type inst✝⁴ : Fintype J K : Type inst✝³ : Fintype K C : Type u inst✝² : Category.{v, u} C inst✝¹ : HasZeroMorphisms C inst✝ : HasFiniteBiproducts C f : J → C g : K → C m : (j : J) → (k : K) → f j ⟶ g k j : J j✝ : K ⊢ (ι f j ≫ matrix m) ≫ π (fun k => g k) j✝ = (lift fun k => m j k) ≫ π (fun k => g k) j✝ [PROOFSTEP] simp [biproduct.matrix] [GOAL] J : Type inst✝⁴ : Fintype J K : Type inst✝³ : Fintype K C : Type u inst✝² : Category.{v, u} C inst✝¹ : HasZeroMorphisms C inst✝ : HasFiniteBiproducts C f : J → C g : K → C m : (j : J) → (k : K) → f j ⟶ g k j : J k : K ⊢ components (matrix m) j k = m j k [PROOFSTEP] simp [biproduct.components] [GOAL] J : Type inst✝⁴ : Fintype J K : Type inst✝³ : Fintype K C : Type u inst✝² : Category.{v, u} C inst✝¹ : HasZeroMorphisms C inst✝ : HasFiniteBiproducts C f : J → C g : K → C m : ⨁ f ⟶ ⨁ g ⊢ (matrix fun j k => components m j k) = m [PROOFSTEP] ext [GOAL] case w.w J : Type inst✝⁴ : Fintype J K : Type inst✝³ : Fintype K C : Type u inst✝² : Category.{v, u} C inst✝¹ : HasZeroMorphisms C inst✝ : HasFiniteBiproducts C f : J → C g : K → C m : ⨁ f ⟶ ⨁ g j✝¹ : K j✝ : J ⊢ ι (fun j => f j) j✝ ≫ (matrix fun j k => components m j k) ≫ π (fun k => g k) j✝¹ = ι (fun j => f j) j✝ ≫ m ≫ π (fun k => g k) j✝¹ [PROOFSTEP] simp [biproduct.components] [GOAL] J : Type inst✝⁴ : Fintype J K : Type inst✝³ : Fintype K C : Type u inst✝² : Category.{v, u} C inst✝¹ : HasZeroMorphisms C inst✝ : HasFiniteBiproducts C f : J → C g : K → C m : (j : J) → (k : K) → f j ⟶ g k ⊢ components (matrix m) = m [PROOFSTEP] ext [GOAL] case h.h J : Type inst✝⁴ : Fintype J K : Type inst✝³ : Fintype K C : Type u inst✝² : Category.{v, u} C inst✝¹ : HasZeroMorphisms C inst✝ : HasFiniteBiproducts C f : J → C g : K → C m : (j : J) → (k : K) → f j ⟶ g k x✝¹ : J x✝ : K ⊢ components (matrix m) x✝¹ x✝ = m x✝¹ x✝ [PROOFSTEP] apply biproduct.matrix_components [GOAL] J : Type w C : Type u inst✝² : Category.{v, u} C inst✝¹ : HasZeroMorphisms C f : J → C inst✝ : HasBiproduct f b : Bicone f hb : Bicone.IsBilimit b ⊢ (IsLimit.conePointUniqueUpToIso hb.isLimit (isLimit f)).inv = desc b.ι [PROOFSTEP] refine' biproduct.hom_ext' _ _ fun j => hb.isLimit.hom_ext fun j' => _ [GOAL] J : Type w C : Type u inst✝² : Category.{v, u} C inst✝¹ : HasZeroMorphisms C f : J → C inst✝ : HasBiproduct f b : Bicone f hb : Bicone.IsBilimit b j : J j' : Discrete J ⊢ (ι f j ≫ (IsLimit.conePointUniqueUpToIso hb.isLimit (isLimit f)).inv) ≫ NatTrans.app (Bicone.toCone b).π j' = (ι f j ≫ desc b.ι) ≫ NatTrans.app (Bicone.toCone b).π j' [PROOFSTEP] rw [Category.assoc, IsLimit.conePointUniqueUpToIso_inv_comp, Bicone.toCone_π_app, biproduct.bicone_π, biproduct.ι_desc, biproduct.ι_π, b.toCone_π_app, b.ι_π] [GOAL] J : Type w C : Type u inst✝² : Category.{v, u} C inst✝¹ : HasZeroMorphisms C f : J → C inst✝ : HasBiproduct f b : Bicone f hb : Bicone.IsBilimit b ⊢ lift b.π ≫ desc b.ι = 𝟙 b.pt [PROOFSTEP] rw [← biproduct.conePointUniqueUpToIso_hom f hb, ← biproduct.conePointUniqueUpToIso_inv f hb, Iso.hom_inv_id] [GOAL] J : Type w C : Type u inst✝² : Category.{v, u} C inst✝¹ : HasZeroMorphisms C f : J → C inst✝ : HasBiproduct f b : Bicone f hb : Bicone.IsBilimit b ⊢ desc b.ι ≫ lift b.π = 𝟙 (⨁ f) [PROOFSTEP] rw [← biproduct.conePointUniqueUpToIso_hom f hb, ← biproduct.conePointUniqueUpToIso_inv f hb, Iso.inv_hom_id] [GOAL] J : Type w C : Type u inst✝² : Category.{v, u} C inst✝¹ : HasZeroMorphisms C inst✝ : HasFiniteBiproducts C ⊢ HasZeroObject C [PROOFSTEP] refine' ⟨⟨biproduct Empty.elim, fun X => ⟨⟨⟨0⟩, _⟩⟩, fun X => ⟨⟨⟨0⟩, _⟩⟩⟩⟩ [GOAL] case refine'_1 J : Type w C : Type u inst✝² : Category.{v, u} C inst✝¹ : HasZeroMorphisms C inst✝ : HasFiniteBiproducts C X : C ⊢ ∀ (a : ⨁ Empty.elim ⟶ X), a = default [PROOFSTEP] intro a [GOAL] case refine'_1 J : Type w C : Type u inst✝² : Category.{v, u} C inst✝¹ : HasZeroMorphisms C inst✝ : HasFiniteBiproducts C X : C a : ⨁ Empty.elim ⟶ X ⊢ a = default [PROOFSTEP] apply biproduct.hom_ext' [GOAL] case refine'_1.w J : Type w C : Type u inst✝² : Category.{v, u} C inst✝¹ : HasZeroMorphisms C inst✝ : HasFiniteBiproducts C X : C a : ⨁ Empty.elim ⟶ X ⊢ ∀ (j : Empty), biproduct.ι Empty.elim j ≫ a = biproduct.ι Empty.elim j ≫ default [PROOFSTEP] simp [GOAL] case refine'_2 J : Type w C : Type u inst✝² : Category.{v, u} C inst✝¹ : HasZeroMorphisms C inst✝ : HasFiniteBiproducts C X : C ⊢ ∀ (a : X ⟶ ⨁ Empty.elim), a = default [PROOFSTEP] intro a [GOAL] case refine'_2 J : Type w C : Type u inst✝² : Category.{v, u} C inst✝¹ : HasZeroMorphisms C inst✝ : HasFiniteBiproducts C X : C a : X ⟶ ⨁ Empty.elim ⊢ a = default [PROOFSTEP] apply biproduct.hom_ext [GOAL] case refine'_2.w J : Type w C : Type u inst✝² : Category.{v, u} C inst✝¹ : HasZeroMorphisms C inst✝ : HasFiniteBiproducts C X : C a : X ⟶ ⨁ Empty.elim ⊢ ∀ (j : Empty), a ≫ biproduct.π Empty.elim j = default ≫ biproduct.π Empty.elim j [PROOFSTEP] simp [GOAL] J : Type w C : Type u inst✝² : Category.{v, u} C inst✝¹ : HasZeroMorphisms C inst✝ : Unique J f : J → C j : J ⊢ f default = f j [PROOFSTEP] congr [GOAL] case e_a J : Type w C : Type u inst✝² : Category.{v, u} C inst✝¹ : HasZeroMorphisms C inst✝ : Unique J f : J → C j : J ⊢ default = j [PROOFSTEP] rw [← Unique.uniq] [GOAL] J : Type w C : Type u inst✝² : Category.{v, u} C inst✝¹ : HasZeroMorphisms C inst✝ : Unique J f : J → C j : J ⊢ f j = f default [PROOFSTEP] congr [GOAL] case e_a J : Type w C : Type u inst✝² : Category.{v, u} C inst✝¹ : HasZeroMorphisms C inst✝ : Unique J f : J → C j : J ⊢ j = default [PROOFSTEP] rw [← Unique.uniq] [GOAL] J : Type w C : Type u inst✝¹ : Category.{v, u} C inst✝ : HasZeroMorphisms C P Q X Y : C b : BinaryBicone X Y j j' : WalkingPair ⊢ (fun j => WalkingPair.casesOn j b.inl b.inr) j ≫ (fun j => WalkingPair.casesOn j b.fst b.snd) j' = if h : j = j' then eqToHom (_ : pairFunction X Y j = pairFunction X Y j') else 0 [PROOFSTEP] rcases j with ⟨⟩ [GOAL] case left J : Type w C : Type u inst✝¹ : Category.{v, u} C inst✝ : HasZeroMorphisms C P Q X Y : C b : BinaryBicone X Y j' : WalkingPair ⊢ (fun j => WalkingPair.casesOn j b.inl b.inr) WalkingPair.left ≫ (fun j => WalkingPair.casesOn j b.fst b.snd) j' = if h : WalkingPair.left = j' then eqToHom (_ : pairFunction X Y WalkingPair.left = pairFunction X Y j') else 0 [PROOFSTEP] rcases j' with ⟨⟩ [GOAL] case right J : Type w C : Type u inst✝¹ : Category.{v, u} C inst✝ : HasZeroMorphisms C P Q X Y : C b : BinaryBicone X Y j' : WalkingPair ⊢ (fun j => WalkingPair.casesOn j b.inl b.inr) WalkingPair.right ≫ (fun j => WalkingPair.casesOn j b.fst b.snd) j' = if h : WalkingPair.right = j' then eqToHom (_ : pairFunction X Y WalkingPair.right = pairFunction X Y j') else 0 [PROOFSTEP] rcases j' with ⟨⟩ [GOAL] case left.left J : Type w C : Type u inst✝¹ : Category.{v, u} C inst✝ : HasZeroMorphisms C P Q X Y : C b : BinaryBicone X Y ⊢ (fun j => WalkingPair.casesOn j b.inl b.inr) WalkingPair.left ≫ (fun j => WalkingPair.casesOn j b.fst b.snd) WalkingPair.left = if h : WalkingPair.left = WalkingPair.left then eqToHom (_ : pairFunction X Y WalkingPair.left = pairFunction X Y WalkingPair.left) else 0 [PROOFSTEP] simp [GOAL] case left.right J : Type w C : Type u inst✝¹ : Category.{v, u} C inst✝ : HasZeroMorphisms C P Q X Y : C b : BinaryBicone X Y ⊢ (fun j => WalkingPair.casesOn j b.inl b.inr) WalkingPair.left ≫ (fun j => WalkingPair.casesOn j b.fst b.snd) WalkingPair.right = if h : WalkingPair.left = WalkingPair.right then eqToHom (_ : pairFunction X Y WalkingPair.left = pairFunction X Y WalkingPair.right) else 0 [PROOFSTEP] simp [GOAL] case right.left J : Type w C : Type u inst✝¹ : Category.{v, u} C inst✝ : HasZeroMorphisms C P Q X Y : C b : BinaryBicone X Y ⊢ (fun j => WalkingPair.casesOn j b.inl b.inr) WalkingPair.right ≫ (fun j => WalkingPair.casesOn j b.fst b.snd) WalkingPair.left = if h : WalkingPair.right = WalkingPair.left then eqToHom (_ : pairFunction X Y WalkingPair.right = pairFunction X Y WalkingPair.left) else 0 [PROOFSTEP] simp [GOAL] case right.right J : Type w C : Type u inst✝¹ : Category.{v, u} C inst✝ : HasZeroMorphisms C P Q X Y : C b : BinaryBicone X Y ⊢ (fun j => WalkingPair.casesOn j b.inl b.inr) WalkingPair.right ≫ (fun j => WalkingPair.casesOn j b.fst b.snd) WalkingPair.right = if h : WalkingPair.right = WalkingPair.right then eqToHom (_ : pairFunction X Y WalkingPair.right = pairFunction X Y WalkingPair.right) else 0 [PROOFSTEP] simp [GOAL] J : Type w C : Type u inst✝¹ : Category.{v, u} C inst✝ : HasZeroMorphisms C P Q X Y : C b : BinaryBicone X Y j : Discrete WalkingPair ⊢ NatTrans.app (Bicone.toCone (toBicone b)).π j = (Iso.refl (Bicone.toCone (toBicone b)).pt).hom ≫ NatTrans.app (toCone b).π j [PROOFSTEP] cases' j with as [GOAL] case mk J : Type w C : Type u inst✝¹ : Category.{v, u} C inst✝ : HasZeroMorphisms C P Q X Y : C b : BinaryBicone X Y as : WalkingPair ⊢ NatTrans.app (Bicone.toCone (toBicone b)).π { as := as } = (Iso.refl (Bicone.toCone (toBicone b)).pt).hom ≫ NatTrans.app (toCone b).π { as := as } [PROOFSTEP] cases as [GOAL] case mk.left J : Type w C : Type u inst✝¹ : Category.{v, u} C inst✝ : HasZeroMorphisms C P Q X Y : C b : BinaryBicone X Y ⊢ NatTrans.app (Bicone.toCone (toBicone b)).π { as := WalkingPair.left } = (Iso.refl (Bicone.toCone (toBicone b)).pt).hom ≫ NatTrans.app (toCone b).π { as := WalkingPair.left } [PROOFSTEP] simp [GOAL] case mk.right J : Type w C : Type u inst✝¹ : Category.{v, u} C inst✝ : HasZeroMorphisms C P Q X Y : C b : BinaryBicone X Y ⊢ NatTrans.app (Bicone.toCone (toBicone b)).π { as := WalkingPair.right } = (Iso.refl (Bicone.toCone (toBicone b)).pt).hom ≫ NatTrans.app (toCone b).π { as := WalkingPair.right } [PROOFSTEP] simp [GOAL] J : Type w C : Type u inst✝¹ : Category.{v, u} C inst✝ : HasZeroMorphisms C P Q X Y : C b : BinaryBicone X Y j : Discrete WalkingPair ⊢ NatTrans.app (Bicone.toCocone (toBicone b)).ι j ≫ (Iso.refl (Bicone.toCocone (toBicone b)).pt).hom = NatTrans.app (toCocone b).ι j [PROOFSTEP] cases' j with as [GOAL] case mk J : Type w C : Type u inst✝¹ : Category.{v, u} C inst✝ : HasZeroMorphisms C P Q X Y : C b : BinaryBicone X Y as : WalkingPair ⊢ NatTrans.app (Bicone.toCocone (toBicone b)).ι { as := as } ≫ (Iso.refl (Bicone.toCocone (toBicone b)).pt).hom = NatTrans.app (toCocone b).ι { as := as } [PROOFSTEP] cases as [GOAL] case mk.left J : Type w C : Type u inst✝¹ : Category.{v, u} C inst✝ : HasZeroMorphisms C P Q X Y : C b : BinaryBicone X Y ⊢ NatTrans.app (Bicone.toCocone (toBicone b)).ι { as := WalkingPair.left } ≫ (Iso.refl (Bicone.toCocone (toBicone b)).pt).hom = NatTrans.app (toCocone b).ι { as := WalkingPair.left } [PROOFSTEP] simp [GOAL] case mk.right J : Type w C : Type u inst✝¹ : Category.{v, u} C inst✝ : HasZeroMorphisms C P Q X Y : C b : BinaryBicone X Y ⊢ NatTrans.app (Bicone.toCocone (toBicone b)).ι { as := WalkingPair.right } ≫ (Iso.refl (Bicone.toCocone (toBicone b)).pt).hom = NatTrans.app (toCocone b).ι { as := WalkingPair.right } [PROOFSTEP] simp [GOAL] J : Type w C : Type u inst✝¹ : Category.{v, u} C inst✝ : HasZeroMorphisms C X Y : C b : Bicone (pairFunction X Y) ⊢ ι b WalkingPair.left ≫ π b WalkingPair.left = 𝟙 X [PROOFSTEP] simp [Bicone.ι_π] [GOAL] J : Type w C : Type u inst✝¹ : Category.{v, u} C inst✝ : HasZeroMorphisms C X Y : C b : Bicone (pairFunction X Y) ⊢ ι b WalkingPair.left ≫ π b WalkingPair.right = 0 [PROOFSTEP] simp [Bicone.ι_π] [GOAL] J : Type w C : Type u inst✝¹ : Category.{v, u} C inst✝ : HasZeroMorphisms C X Y : C b : Bicone (pairFunction X Y) ⊢ ι b WalkingPair.right ≫ π b WalkingPair.left = 0 [PROOFSTEP] simp [Bicone.ι_π] [GOAL] J : Type w C : Type u inst✝¹ : Category.{v, u} C inst✝ : HasZeroMorphisms C X Y : C b : Bicone (pairFunction X Y) ⊢ ι b WalkingPair.right ≫ π b WalkingPair.right = 𝟙 Y [PROOFSTEP] simp [Bicone.ι_π] [GOAL] J : Type w C : Type u inst✝¹ : Category.{v, u} C inst✝ : HasZeroMorphisms C X Y : C b : Bicone (pairFunction X Y) j : Discrete WalkingPair ⊢ NatTrans.app (BinaryBicone.toCone (toBinaryBicone b)).π j = (Iso.refl (BinaryBicone.toCone (toBinaryBicone b)).pt).hom ≫ NatTrans.app (toCone b).π j [PROOFSTEP] rcases j with ⟨⟨⟩⟩ [GOAL] case mk.left J : Type w C : Type u inst✝¹ : Category.{v, u} C inst✝ : HasZeroMorphisms C X Y : C b : Bicone (pairFunction X Y) ⊢ NatTrans.app (BinaryBicone.toCone (toBinaryBicone b)).π { as := WalkingPair.left } = (Iso.refl (BinaryBicone.toCone (toBinaryBicone b)).pt).hom ≫ NatTrans.app (toCone b).π { as := WalkingPair.left } [PROOFSTEP] simp [GOAL] case mk.right J : Type w C : Type u inst✝¹ : Category.{v, u} C inst✝ : HasZeroMorphisms C X Y : C b : Bicone (pairFunction X Y) ⊢ NatTrans.app (BinaryBicone.toCone (toBinaryBicone b)).π { as := WalkingPair.right } = (Iso.refl (BinaryBicone.toCone (toBinaryBicone b)).pt).hom ≫ NatTrans.app (toCone b).π { as := WalkingPair.right } [PROOFSTEP] simp [GOAL] J : Type w C : Type u inst✝¹ : Category.{v, u} C inst✝ : HasZeroMorphisms C X Y : C b : Bicone (pairFunction X Y) j : Discrete WalkingPair ⊢ NatTrans.app (BinaryBicone.toCocone (toBinaryBicone b)).ι j ≫ (Iso.refl (BinaryBicone.toCocone (toBinaryBicone b)).pt).hom = NatTrans.app (toCocone b).ι j [PROOFSTEP] rcases j with ⟨⟨⟩⟩ [GOAL] case mk.left J : Type w C : Type u inst✝¹ : Category.{v, u} C inst✝ : HasZeroMorphisms C X Y : C b : Bicone (pairFunction X Y) ⊢ NatTrans.app (BinaryBicone.toCocone (toBinaryBicone b)).ι { as := WalkingPair.left } ≫ (Iso.refl (BinaryBicone.toCocone (toBinaryBicone b)).pt).hom = NatTrans.app (toCocone b).ι { as := WalkingPair.left } [PROOFSTEP] simp [GOAL] case mk.right J : Type w C : Type u inst✝¹ : Category.{v, u} C inst✝ : HasZeroMorphisms C X Y : C b : Bicone (pairFunction X Y) ⊢ NatTrans.app (BinaryBicone.toCocone (toBinaryBicone b)).ι { as := WalkingPair.right } ≫ (Iso.refl (BinaryBicone.toCocone (toBinaryBicone b)).pt).hom = NatTrans.app (toCocone b).ι { as := WalkingPair.right } [PROOFSTEP] simp [GOAL] J : Type w C : Type u inst✝¹ : Category.{v, u} C inst✝ : HasZeroMorphisms C X Y : C b : BinaryBicone X Y x✝ : Bicone.IsBilimit (toBicone b) h : IsLimit (Bicone.toCone (toBicone b)) h' : IsColimit (Bicone.toCocone (toBicone b)) ⊢ (fun h => { isLimit := ↑(toBiconeIsLimit b).symm h.isLimit, isColimit := ↑(toBiconeIsColimit b).symm h.isColimit }) ((fun h => { isLimit := ↑(toBiconeIsLimit b) h.isLimit, isColimit := ↑(toBiconeIsColimit b) h.isColimit }) { isLimit := h, isColimit := h' }) = { isLimit := h, isColimit := h' } [PROOFSTEP] dsimp only [GOAL] J : Type w C : Type u inst✝¹ : Category.{v, u} C inst✝ : HasZeroMorphisms C X Y : C b : BinaryBicone X Y x✝ : Bicone.IsBilimit (toBicone b) h : IsLimit (Bicone.toCone (toBicone b)) h' : IsColimit (Bicone.toCocone (toBicone b)) ⊢ { isLimit := ↑(toBiconeIsLimit b).symm (↑(toBiconeIsLimit b) h), isColimit := ↑(toBiconeIsColimit b).symm (↑(toBiconeIsColimit b) h') } = { isLimit := h, isColimit := h' } [PROOFSTEP] simp [GOAL] J : Type w C : Type u inst✝¹ : Category.{v, u} C inst✝ : HasZeroMorphisms C X Y : C b : BinaryBicone X Y x✝ : IsBilimit b h : IsLimit (toCone b) h' : IsColimit (toCocone b) ⊢ (fun h => { isLimit := ↑(toBiconeIsLimit b) h.isLimit, isColimit := ↑(toBiconeIsColimit b) h.isColimit }) ((fun h => { isLimit := ↑(toBiconeIsLimit b).symm h.isLimit, isColimit := ↑(toBiconeIsColimit b).symm h.isColimit }) { isLimit := h, isColimit := h' }) = { isLimit := h, isColimit := h' } [PROOFSTEP] dsimp only [GOAL] J : Type w C : Type u inst✝¹ : Category.{v, u} C inst✝ : HasZeroMorphisms C X Y : C b : BinaryBicone X Y x✝ : IsBilimit b h : IsLimit (toCone b) h' : IsColimit (toCocone b) ⊢ { isLimit := ↑(toBiconeIsLimit b) (↑(toBiconeIsLimit b).symm h), isColimit := ↑(toBiconeIsColimit b) (↑(toBiconeIsColimit b).symm h') } = { isLimit := h, isColimit := h' } [PROOFSTEP] simp [GOAL] J : Type w C : Type u inst✝¹ : Category.{v, u} C inst✝ : HasZeroMorphisms C X Y : C b : Bicone (pairFunction X Y) x✝ : BinaryBicone.IsBilimit (toBinaryBicone b) h : IsLimit (BinaryBicone.toCone (toBinaryBicone b)) h' : IsColimit (BinaryBicone.toCocone (toBinaryBicone b)) ⊢ (fun h => { isLimit := ↑(toBinaryBiconeIsLimit b).symm h.isLimit, isColimit := ↑(toBinaryBiconeIsColimit b).symm h.isColimit }) ((fun h => { isLimit := ↑(toBinaryBiconeIsLimit b) h.isLimit, isColimit := ↑(toBinaryBiconeIsColimit b) h.isColimit }) { isLimit := h, isColimit := h' }) = { isLimit := h, isColimit := h' } [PROOFSTEP] dsimp only [GOAL] J : Type w C : Type u inst✝¹ : Category.{v, u} C inst✝ : HasZeroMorphisms C X Y : C b : Bicone (pairFunction X Y) x✝ : BinaryBicone.IsBilimit (toBinaryBicone b) h : IsLimit (BinaryBicone.toCone (toBinaryBicone b)) h' : IsColimit (BinaryBicone.toCocone (toBinaryBicone b)) ⊢ { isLimit := ↑(toBinaryBiconeIsLimit b).symm (↑(toBinaryBiconeIsLimit b) h), isColimit := ↑(toBinaryBiconeIsColimit b).symm (↑(toBinaryBiconeIsColimit b) h') } = { isLimit := h, isColimit := h' } [PROOFSTEP] simp [GOAL] J : Type w C : Type u inst✝¹ : Category.{v, u} C inst✝ : HasZeroMorphisms C X Y : C b : Bicone (pairFunction X Y) x✝ : IsBilimit b h : IsLimit (toCone b) h' : IsColimit (toCocone b) ⊢ (fun h => { isLimit := ↑(toBinaryBiconeIsLimit b) h.isLimit, isColimit := ↑(toBinaryBiconeIsColimit b) h.isColimit }) ((fun h => { isLimit := ↑(toBinaryBiconeIsLimit b).symm h.isLimit, isColimit := ↑(toBinaryBiconeIsColimit b).symm h.isColimit }) { isLimit := h, isColimit := h' }) = { isLimit := h, isColimit := h' } [PROOFSTEP] dsimp only [GOAL] J : Type w C : Type u inst✝¹ : Category.{v, u} C inst✝ : HasZeroMorphisms C X Y : C b : Bicone (pairFunction X Y) x✝ : IsBilimit b h : IsLimit (toCone b) h' : IsColimit (toCocone b) ⊢ { isLimit := ↑(toBinaryBiconeIsLimit b) (↑(toBinaryBiconeIsLimit b).symm h), isColimit := ↑(toBinaryBiconeIsColimit b) (↑(toBinaryBiconeIsColimit b).symm h') } = { isLimit := h, isColimit := h' } [PROOFSTEP] simp [GOAL] J : Type w C : Type u inst✝² : Category.{v, u} C inst✝¹ : HasZeroMorphisms C P Q X Y : C inst✝ : HasBinaryBiproduct X Y ⊢ (isoProd X Y).hom = prod.lift fst snd [PROOFSTEP] ext [GOAL] case h₁.h₀ J : Type w C : Type u inst✝² : Category.{v, u} C inst✝¹ : HasZeroMorphisms C P Q X Y : C inst✝ : HasBinaryBiproduct X Y ⊢ inl ≫ (isoProd X Y).hom ≫ prod.fst = inl ≫ prod.lift fst snd ≫ prod.fst [PROOFSTEP] simp [biprod.isoProd] [GOAL] case h₁.h₁ J : Type w C : Type u inst✝² : Category.{v, u} C inst✝¹ : HasZeroMorphisms C P Q X Y : C inst✝ : HasBinaryBiproduct X Y ⊢ inr ≫ (isoProd X Y).hom ≫ prod.fst = inr ≫ prod.lift fst snd ≫ prod.fst [PROOFSTEP] simp [biprod.isoProd] [GOAL] case h₂.h₀ J : Type w C : Type u inst✝² : Category.{v, u} C inst✝¹ : HasZeroMorphisms C P Q X Y : C inst✝ : HasBinaryBiproduct X Y ⊢ inl ≫ (isoProd X Y).hom ≫ prod.snd = inl ≫ prod.lift fst snd ≫ prod.snd [PROOFSTEP] simp [biprod.isoProd] [GOAL] case h₂.h₁ J : Type w C : Type u inst✝² : Category.{v, u} C inst✝¹ : HasZeroMorphisms C P Q X Y : C inst✝ : HasBinaryBiproduct X Y ⊢ inr ≫ (isoProd X Y).hom ≫ prod.snd = inr ≫ prod.lift fst snd ≫ prod.snd [PROOFSTEP] simp [biprod.isoProd] [GOAL] J : Type w C : Type u inst✝² : Category.{v, u} C inst✝¹ : HasZeroMorphisms C P Q X Y : C inst✝ : HasBinaryBiproduct X Y ⊢ (isoProd X Y).inv = lift prod.fst prod.snd [PROOFSTEP] ext [GOAL] case h₀ J : Type w C : Type u inst✝² : Category.{v, u} C inst✝¹ : HasZeroMorphisms C P Q X Y : C inst✝ : HasBinaryBiproduct X Y ⊢ (isoProd X Y).inv ≫ fst = lift prod.fst prod.snd ≫ fst [PROOFSTEP] simp [Iso.inv_comp_eq] [GOAL] case h₁ J : Type w C : Type u inst✝² : Category.{v, u} C inst✝¹ : HasZeroMorphisms C P Q X Y : C inst✝ : HasBinaryBiproduct X Y ⊢ (isoProd X Y).inv ≫ snd = lift prod.fst prod.snd ≫ snd [PROOFSTEP] simp [Iso.inv_comp_eq] [GOAL] J : Type w C : Type u inst✝² : Category.{v, u} C inst✝¹ : HasZeroMorphisms C P Q X Y : C inst✝ : HasBinaryBiproduct X Y ⊢ (isoCoprod X Y).inv = coprod.desc inl inr [PROOFSTEP] ext [GOAL] case h₁.h₀ J : Type w C : Type u inst✝² : Category.{v, u} C inst✝¹ : HasZeroMorphisms C P Q X Y : C inst✝ : HasBinaryBiproduct X Y ⊢ (coprod.inl ≫ (isoCoprod X Y).inv) ≫ fst = (coprod.inl ≫ coprod.desc inl inr) ≫ fst [PROOFSTEP] simp [biprod.isoCoprod] [GOAL] case h₁.h₁ J : Type w C : Type u inst✝² : Category.{v, u} C inst✝¹ : HasZeroMorphisms C P Q X Y : C inst✝ : HasBinaryBiproduct X Y ⊢ (coprod.inl ≫ (isoCoprod X Y).inv) ≫ snd = (coprod.inl ≫ coprod.desc inl inr) ≫ snd [PROOFSTEP] simp [biprod.isoCoprod] [GOAL] case h₂.h₀ J : Type w C : Type u inst✝² : Category.{v, u} C inst✝¹ : HasZeroMorphisms C P Q X Y : C inst✝ : HasBinaryBiproduct X Y ⊢ (coprod.inr ≫ (isoCoprod X Y).inv) ≫ fst = (coprod.inr ≫ coprod.desc inl inr) ≫ fst [PROOFSTEP] simp [biprod.isoCoprod] [GOAL] case h₂.h₁ J : Type w C : Type u inst✝² : Category.{v, u} C inst✝¹ : HasZeroMorphisms C P Q X Y : C inst✝ : HasBinaryBiproduct X Y ⊢ (coprod.inr ≫ (isoCoprod X Y).inv) ≫ snd = (coprod.inr ≫ coprod.desc inl inr) ≫ snd [PROOFSTEP] simp [biprod.isoCoprod] [GOAL] J : Type w C : Type u inst✝² : Category.{v, u} C inst✝¹ : HasZeroMorphisms C P Q X Y : C inst✝ : HasBinaryBiproduct X Y ⊢ (biprod.isoCoprod X Y).hom = biprod.desc coprod.inl coprod.inr [PROOFSTEP] ext [GOAL] case h₀ J : Type w C : Type u inst✝² : Category.{v, u} C inst✝¹ : HasZeroMorphisms C P Q X Y : C inst✝ : HasBinaryBiproduct X Y ⊢ biprod.inl ≫ (biprod.isoCoprod X Y).hom = biprod.inl ≫ biprod.desc coprod.inl coprod.inr [PROOFSTEP] simp [← Iso.eq_comp_inv] [GOAL] case h₁ J : Type w C : Type u inst✝² : Category.{v, u} C inst✝¹ : HasZeroMorphisms C P Q X Y : C inst✝ : HasBinaryBiproduct X Y ⊢ biprod.inr ≫ (biprod.isoCoprod X Y).hom = biprod.inr ≫ biprod.desc coprod.inl coprod.inr [PROOFSTEP] simp [← Iso.eq_comp_inv] [GOAL] J : Type w C : Type u inst✝³ : Category.{v, u} C inst✝² : HasZeroMorphisms C P Q W X Y Z : C inst✝¹ : HasBinaryBiproduct W X inst✝ : HasBinaryBiproduct Y Z f : W ⟶ Y g : X ⟶ Z ⊢ map f g = map' f g [PROOFSTEP] ext [GOAL] case h₀.h₀ J : Type w C : Type u inst✝³ : Category.{v, u} C inst✝² : HasZeroMorphisms C P Q W X Y Z : C inst✝¹ : HasBinaryBiproduct W X inst✝ : HasBinaryBiproduct Y Z f : W ⟶ Y g : X ⟶ Z ⊢ (inl ≫ map f g) ≫ fst = (inl ≫ map' f g) ≫ fst [PROOFSTEP] simp only [mapPair_left, IsColimit.ι_map, IsLimit.map_π, biprod.inl_fst_assoc, Category.assoc, ← BinaryBicone.toCone_π_app_left, ← BinaryBiproduct.bicone_fst, ← BinaryBicone.toCocone_ι_app_left, ← BinaryBiproduct.bicone_inl] [GOAL] case h₀.h₀ J : Type w C : Type u inst✝³ : Category.{v, u} C inst✝² : HasZeroMorphisms C P Q W X Y Z : C inst✝¹ : HasBinaryBiproduct W X inst✝ : HasBinaryBiproduct Y Z f : W ⟶ Y g : X ⟶ Z ⊢ NatTrans.app (BinaryBicone.toCocone (BinaryBiproduct.bicone W X)).ι { as := WalkingPair.left } ≫ NatTrans.app (BinaryBicone.toCone (BinaryBiproduct.bicone W X)).π { as := WalkingPair.left } ≫ f = f ≫ NatTrans.app (BinaryBicone.toCocone (BinaryBiproduct.bicone Y Z)).ι { as := WalkingPair.left } ≫ NatTrans.app (BinaryBicone.toCone (BinaryBiproduct.bicone Y Z)).π { as := WalkingPair.left } [PROOFSTEP] dsimp [GOAL] case h₀.h₀ J : Type w C : Type u inst✝³ : Category.{v, u} C inst✝² : HasZeroMorphisms C P Q W X Y Z : C inst✝¹ : HasBinaryBiproduct W X inst✝ : HasBinaryBiproduct Y Z f : W ⟶ Y g : X ⟶ Z ⊢ inl ≫ fst ≫ f = f ≫ inl ≫ fst [PROOFSTEP] simp [GOAL] case h₀.h₁ J : Type w C : Type u inst✝³ : Category.{v, u} C inst✝² : HasZeroMorphisms C P Q W X Y Z : C inst✝¹ : HasBinaryBiproduct W X inst✝ : HasBinaryBiproduct Y Z f : W ⟶ Y g : X ⟶ Z ⊢ (inl ≫ map f g) ≫ snd = (inl ≫ map' f g) ≫ snd [PROOFSTEP] simp only [mapPair_left, IsColimit.ι_map, IsLimit.map_π, zero_comp, biprod.inl_snd_assoc, Category.assoc, ← BinaryBicone.toCone_π_app_right, ← BinaryBiproduct.bicone_snd, ← BinaryBicone.toCocone_ι_app_left, ← BinaryBiproduct.bicone_inl] [GOAL] case h₀.h₁ J : Type w C : Type u inst✝³ : Category.{v, u} C inst✝² : HasZeroMorphisms C P Q W X Y Z : C inst✝¹ : HasBinaryBiproduct W X inst✝ : HasBinaryBiproduct Y Z f : W ⟶ Y g : X ⟶ Z ⊢ NatTrans.app (BinaryBicone.toCocone (BinaryBiproduct.bicone W X)).ι { as := WalkingPair.left } ≫ NatTrans.app (BinaryBicone.toCone (BinaryBiproduct.bicone W X)).π { as := WalkingPair.right } ≫ NatTrans.app (mapPair f g) { as := WalkingPair.right } = f ≫ NatTrans.app (BinaryBicone.toCocone (BinaryBiproduct.bicone Y Z)).ι { as := WalkingPair.left } ≫ NatTrans.app (BinaryBicone.toCone (BinaryBiproduct.bicone Y Z)).π { as := WalkingPair.right } [PROOFSTEP] simp [GOAL] case h₁.h₀ J : Type w C : Type u inst✝³ : Category.{v, u} C inst✝² : HasZeroMorphisms C P Q W X Y Z : C inst✝¹ : HasBinaryBiproduct W X inst✝ : HasBinaryBiproduct Y Z f : W ⟶ Y g : X ⟶ Z ⊢ (inr ≫ map f g) ≫ fst = (inr ≫ map' f g) ≫ fst [PROOFSTEP] simp only [mapPair_right, biprod.inr_fst_assoc, IsColimit.ι_map, IsLimit.map_π, zero_comp, Category.assoc, ← BinaryBicone.toCone_π_app_left, ← BinaryBiproduct.bicone_fst, ← BinaryBicone.toCocone_ι_app_right, ← BinaryBiproduct.bicone_inr] [GOAL] case h₁.h₀ J : Type w C : Type u inst✝³ : Category.{v, u} C inst✝² : HasZeroMorphisms C P Q W X Y Z : C inst✝¹ : HasBinaryBiproduct W X inst✝ : HasBinaryBiproduct Y Z f : W ⟶ Y g : X ⟶ Z ⊢ NatTrans.app (BinaryBicone.toCocone (BinaryBiproduct.bicone W X)).ι { as := WalkingPair.right } ≫ NatTrans.app (BinaryBicone.toCone (BinaryBiproduct.bicone W X)).π { as := WalkingPair.left } ≫ NatTrans.app (mapPair f g) { as := WalkingPair.left } = g ≫ NatTrans.app (BinaryBicone.toCocone (BinaryBiproduct.bicone Y Z)).ι { as := WalkingPair.right } ≫ NatTrans.app (BinaryBicone.toCone (BinaryBiproduct.bicone Y Z)).π { as := WalkingPair.left } [PROOFSTEP] simp [GOAL] case h₁.h₁ J : Type w C : Type u inst✝³ : Category.{v, u} C inst✝² : HasZeroMorphisms C P Q W X Y Z : C inst✝¹ : HasBinaryBiproduct W X inst✝ : HasBinaryBiproduct Y Z f : W ⟶ Y g : X ⟶ Z ⊢ (inr ≫ map f g) ≫ snd = (inr ≫ map' f g) ≫ snd [PROOFSTEP] simp only [mapPair_right, IsColimit.ι_map, IsLimit.map_π, biprod.inr_snd_assoc, Category.assoc, ← BinaryBicone.toCone_π_app_right, ← BinaryBiproduct.bicone_snd, ← BinaryBicone.toCocone_ι_app_right, ← BinaryBiproduct.bicone_inr] [GOAL] case h₁.h₁ J : Type w C : Type u inst✝³ : Category.{v, u} C inst✝² : HasZeroMorphisms C P Q W X Y Z : C inst✝¹ : HasBinaryBiproduct W X inst✝ : HasBinaryBiproduct Y Z f : W ⟶ Y g : X ⟶ Z ⊢ NatTrans.app (BinaryBicone.toCocone (BinaryBiproduct.bicone W X)).ι { as := WalkingPair.right } ≫ NatTrans.app (BinaryBicone.toCone (BinaryBiproduct.bicone W X)).π { as := WalkingPair.right } ≫ g = g ≫ NatTrans.app (BinaryBicone.toCocone (BinaryBiproduct.bicone Y Z)).ι { as := WalkingPair.right } ≫ NatTrans.app (BinaryBicone.toCone (BinaryBiproduct.bicone Y Z)).π { as := WalkingPair.right } [PROOFSTEP] simp [GOAL] J : Type w C : Type u inst✝³ : Category.{v, u} C inst✝² : HasZeroMorphisms C P Q W X Y Z : C inst✝¹ : HasBinaryBiproduct W X inst✝ : HasBinaryBiproduct Y Z f : W ⟶ Y g : X ⟶ Z ⊢ inl ≫ map f g = f ≫ inl [PROOFSTEP] rw [biprod.map_eq_map'] [GOAL] J : Type w C : Type u inst✝³ : Category.{v, u} C inst✝² : HasZeroMorphisms C P Q W X Y Z : C inst✝¹ : HasBinaryBiproduct W X inst✝ : HasBinaryBiproduct Y Z f : W ⟶ Y g : X ⟶ Z ⊢ inl ≫ map' f g = f ≫ inl [PROOFSTEP] exact IsColimit.ι_map (BinaryBiproduct.isColimit W X) _ _ ⟨WalkingPair.left⟩ [GOAL] J : Type w C : Type u inst✝³ : Category.{v, u} C inst✝² : HasZeroMorphisms C P Q W X Y Z : C inst✝¹ : HasBinaryBiproduct W X inst✝ : HasBinaryBiproduct Y Z f : W ⟶ Y g : X ⟶ Z ⊢ inr ≫ map f g = g ≫ inr [PROOFSTEP] rw [biprod.map_eq_map'] [GOAL] J : Type w C : Type u inst✝³ : Category.{v, u} C inst✝² : HasZeroMorphisms C P Q W X Y Z : C inst✝¹ : HasBinaryBiproduct W X inst✝ : HasBinaryBiproduct Y Z f : W ⟶ Y g : X ⟶ Z ⊢ inr ≫ map' f g = g ≫ inr [PROOFSTEP] exact IsColimit.ι_map (BinaryBiproduct.isColimit W X) _ _ ⟨WalkingPair.right⟩ [GOAL] J : Type w C : Type u inst✝² : Category.{v, u} C inst✝¹ : HasZeroMorphisms C P Q X Y : C inst✝ : HasBinaryBiproduct X Y b : BinaryBicone X Y hb : BinaryBicone.IsBilimit b ⊢ (IsLimit.conePointUniqueUpToIso hb.isLimit (BinaryBiproduct.isLimit X Y)).inv = desc b.inl b.inr [PROOFSTEP] refine' biprod.hom_ext' _ _ (hb.isLimit.hom_ext fun j => _) (hb.isLimit.hom_ext fun j => _) [GOAL] case refine'_1 J : Type w C : Type u inst✝² : Category.{v, u} C inst✝¹ : HasZeroMorphisms C P Q X Y : C inst✝ : HasBinaryBiproduct X Y b : BinaryBicone X Y hb : BinaryBicone.IsBilimit b j : Discrete WalkingPair ⊢ (inl ≫ (IsLimit.conePointUniqueUpToIso hb.isLimit (BinaryBiproduct.isLimit X Y)).inv) ≫ NatTrans.app (BinaryBicone.toCone b).π j = (inl ≫ desc b.inl b.inr) ≫ NatTrans.app (BinaryBicone.toCone b).π j case refine'_2 J : Type w C : Type u inst✝² : Category.{v, u} C inst✝¹ : HasZeroMorphisms C P Q X Y : C inst✝ : HasBinaryBiproduct X Y b : BinaryBicone X Y hb : BinaryBicone.IsBilimit b j : Discrete WalkingPair ⊢ (inr ≫ (IsLimit.conePointUniqueUpToIso hb.isLimit (BinaryBiproduct.isLimit X Y)).inv) ≫ NatTrans.app (BinaryBicone.toCone b).π j = (inr ≫ desc b.inl b.inr) ≫ NatTrans.app (BinaryBicone.toCone b).π j [PROOFSTEP] all_goals simp only [Category.assoc, IsLimit.conePointUniqueUpToIso_inv_comp] rcases j with ⟨⟨⟩⟩ [GOAL] case refine'_1 J : Type w C : Type u inst✝² : Category.{v, u} C inst✝¹ : HasZeroMorphisms C P Q X Y : C inst✝ : HasBinaryBiproduct X Y b : BinaryBicone X Y hb : BinaryBicone.IsBilimit b j : Discrete WalkingPair ⊢ (inl ≫ (IsLimit.conePointUniqueUpToIso hb.isLimit (BinaryBiproduct.isLimit X Y)).inv) ≫ NatTrans.app (BinaryBicone.toCone b).π j = (inl ≫ desc b.inl b.inr) ≫ NatTrans.app (BinaryBicone.toCone b).π j [PROOFSTEP] simp only [Category.assoc, IsLimit.conePointUniqueUpToIso_inv_comp] [GOAL] case refine'_1 J : Type w C : Type u inst✝² : Category.{v, u} C inst✝¹ : HasZeroMorphisms C P Q X Y : C inst✝ : HasBinaryBiproduct X Y b : BinaryBicone X Y hb : BinaryBicone.IsBilimit b j : Discrete WalkingPair ⊢ inl ≫ NatTrans.app (BinaryBicone.toCone (BinaryBiproduct.bicone X Y)).π j = inl ≫ desc b.inl b.inr ≫ NatTrans.app (BinaryBicone.toCone b).π j [PROOFSTEP] rcases j with ⟨⟨⟩⟩ [GOAL] case refine'_2 J : Type w C : Type u inst✝² : Category.{v, u} C inst✝¹ : HasZeroMorphisms C P Q X Y : C inst✝ : HasBinaryBiproduct X Y b : BinaryBicone X Y hb : BinaryBicone.IsBilimit b j : Discrete WalkingPair ⊢ (inr ≫ (IsLimit.conePointUniqueUpToIso hb.isLimit (BinaryBiproduct.isLimit X Y)).inv) ≫ NatTrans.app (BinaryBicone.toCone b).π j = (inr ≫ desc b.inl b.inr) ≫ NatTrans.app (BinaryBicone.toCone b).π j [PROOFSTEP] simp only [Category.assoc, IsLimit.conePointUniqueUpToIso_inv_comp] [GOAL] case refine'_2 J : Type w C : Type u inst✝² : Category.{v, u} C inst✝¹ : HasZeroMorphisms C P Q X Y : C inst✝ : HasBinaryBiproduct X Y b : BinaryBicone X Y hb : BinaryBicone.IsBilimit b j : Discrete WalkingPair ⊢ inr ≫ NatTrans.app (BinaryBicone.toCone (BinaryBiproduct.bicone X Y)).π j = inr ≫ desc b.inl b.inr ≫ NatTrans.app (BinaryBicone.toCone b).π j [PROOFSTEP] rcases j with ⟨⟨⟩⟩ [GOAL] case refine'_1.mk.left J : Type w C : Type u inst✝² : Category.{v, u} C inst✝¹ : HasZeroMorphisms C P Q X Y : C inst✝ : HasBinaryBiproduct X Y b : BinaryBicone X Y hb : BinaryBicone.IsBilimit b ⊢ inl ≫ NatTrans.app (BinaryBicone.toCone (BinaryBiproduct.bicone X Y)).π { as := WalkingPair.left } = inl ≫ desc b.inl b.inr ≫ NatTrans.app (BinaryBicone.toCone b).π { as := WalkingPair.left } case refine'_1.mk.right J : Type w C : Type u inst✝² : Category.{v, u} C inst✝¹ : HasZeroMorphisms C P Q X Y : C inst✝ : HasBinaryBiproduct X Y b : BinaryBicone X Y hb : BinaryBicone.IsBilimit b ⊢ inl ≫ NatTrans.app (BinaryBicone.toCone (BinaryBiproduct.bicone X Y)).π { as := WalkingPair.right } = inl ≫ desc b.inl b.inr ≫ NatTrans.app (BinaryBicone.toCone b).π { as := WalkingPair.right } case refine'_2.mk.left J : Type w C : Type u inst✝² : Category.{v, u} C inst✝¹ : HasZeroMorphisms C P Q X Y : C inst✝ : HasBinaryBiproduct X Y b : BinaryBicone X Y hb : BinaryBicone.IsBilimit b ⊢ inr ≫ NatTrans.app (BinaryBicone.toCone (BinaryBiproduct.bicone X Y)).π { as := WalkingPair.left } = inr ≫ desc b.inl b.inr ≫ NatTrans.app (BinaryBicone.toCone b).π { as := WalkingPair.left } case refine'_2.mk.right J : Type w C : Type u inst✝² : Category.{v, u} C inst✝¹ : HasZeroMorphisms C P Q X Y : C inst✝ : HasBinaryBiproduct X Y b : BinaryBicone X Y hb : BinaryBicone.IsBilimit b ⊢ inr ≫ NatTrans.app (BinaryBicone.toCone (BinaryBiproduct.bicone X Y)).π { as := WalkingPair.right } = inr ≫ desc b.inl b.inr ≫ NatTrans.app (BinaryBicone.toCone b).π { as := WalkingPair.right } [PROOFSTEP] all_goals simp [GOAL] case refine'_1.mk.left J : Type w C : Type u inst✝² : Category.{v, u} C inst✝¹ : HasZeroMorphisms C P Q X Y : C inst✝ : HasBinaryBiproduct X Y b : BinaryBicone X Y hb : BinaryBicone.IsBilimit b ⊢ inl ≫ NatTrans.app (BinaryBicone.toCone (BinaryBiproduct.bicone X Y)).π { as := WalkingPair.left } = inl ≫ desc b.inl b.inr ≫ NatTrans.app (BinaryBicone.toCone b).π { as := WalkingPair.left } [PROOFSTEP] simp [GOAL] case refine'_1.mk.right J : Type w C : Type u inst✝² : Category.{v, u} C inst✝¹ : HasZeroMorphisms C P Q X Y : C inst✝ : HasBinaryBiproduct X Y b : BinaryBicone X Y hb : BinaryBicone.IsBilimit b ⊢ inl ≫ NatTrans.app (BinaryBicone.toCone (BinaryBiproduct.bicone X Y)).π { as := WalkingPair.right } = inl ≫ desc b.inl b.inr ≫ NatTrans.app (BinaryBicone.toCone b).π { as := WalkingPair.right } [PROOFSTEP] simp [GOAL] case refine'_2.mk.left J : Type w C : Type u inst✝² : Category.{v, u} C inst✝¹ : HasZeroMorphisms C P Q X Y : C inst✝ : HasBinaryBiproduct X Y b : BinaryBicone X Y hb : BinaryBicone.IsBilimit b ⊢ inr ≫ NatTrans.app (BinaryBicone.toCone (BinaryBiproduct.bicone X Y)).π { as := WalkingPair.left } = inr ≫ desc b.inl b.inr ≫ NatTrans.app (BinaryBicone.toCone b).π { as := WalkingPair.left } [PROOFSTEP] simp [GOAL] case refine'_2.mk.right J : Type w C : Type u inst✝² : Category.{v, u} C inst✝¹ : HasZeroMorphisms C P Q X Y : C inst✝ : HasBinaryBiproduct X Y b : BinaryBicone X Y hb : BinaryBicone.IsBilimit b ⊢ inr ≫ NatTrans.app (BinaryBicone.toCone (BinaryBiproduct.bicone X Y)).π { as := WalkingPair.right } = inr ≫ desc b.inl b.inr ≫ NatTrans.app (BinaryBicone.toCone b).π { as := WalkingPair.right } [PROOFSTEP] simp [GOAL] J : Type w C : Type u inst✝² : Category.{v, u} C inst✝¹ : HasZeroMorphisms C P Q X Y : C inst✝ : HasBinaryBiproduct X Y b : BinaryBicone X Y hb : BinaryBicone.IsBilimit b ⊢ lift b.fst b.snd ≫ desc b.inl b.inr = 𝟙 b.pt [PROOFSTEP] rw [← biprod.conePointUniqueUpToIso_hom X Y hb, ← biprod.conePointUniqueUpToIso_inv X Y hb, Iso.hom_inv_id] [GOAL] J : Type w C : Type u inst✝² : Category.{v, u} C inst✝¹ : HasZeroMorphisms C P Q X Y : C inst✝ : HasBinaryBiproduct X Y b : BinaryBicone X Y hb : BinaryBicone.IsBilimit b ⊢ desc b.inl b.inr ≫ lift b.fst b.snd = 𝟙 (X ⊞ Y) [PROOFSTEP] rw [← biprod.conePointUniqueUpToIso_hom X Y hb, ← biprod.conePointUniqueUpToIso_inv X Y hb, Iso.inv_hom_id] [GOAL] J : Type w C : Type u inst✝² : Category.{v, u} C inst✝¹ : HasZeroMorphisms C P Q X Y : C inst✝ : HasBinaryBiproduct X Y ⊢ IsIso inl ↔ 𝟙 (X ⊞ Y) = fst ≫ inl [PROOFSTEP] constructor [GOAL] case mp J : Type w C : Type u inst✝² : Category.{v, u} C inst✝¹ : HasZeroMorphisms C P Q X Y : C inst✝ : HasBinaryBiproduct X Y ⊢ IsIso inl → 𝟙 (X ⊞ Y) = fst ≫ inl [PROOFSTEP] intro h [GOAL] case mp J : Type w C : Type u inst✝² : Category.{v, u} C inst✝¹ : HasZeroMorphisms C P Q X Y : C inst✝ : HasBinaryBiproduct X Y h : IsIso inl ⊢ 𝟙 (X ⊞ Y) = fst ≫ inl [PROOFSTEP] have := (cancel_epi (inv biprod.inl : X ⊞ Y ⟶ X)).2 <| @biprod.inl_fst _ _ _ X Y _ [GOAL] case mp J : Type w C : Type u inst✝² : Category.{v, u} C inst✝¹ : HasZeroMorphisms C P Q X Y : C inst✝ : HasBinaryBiproduct X Y h : IsIso inl this : inv inl ≫ inl ≫ fst = inv inl ≫ 𝟙 X ⊢ 𝟙 (X ⊞ Y) = fst ≫ inl [PROOFSTEP] rw [IsIso.inv_hom_id_assoc, Category.comp_id] at this [GOAL] case mp J : Type w C : Type u inst✝² : Category.{v, u} C inst✝¹ : HasZeroMorphisms C P Q X Y : C inst✝ : HasBinaryBiproduct X Y h : IsIso inl this : fst = inv inl ⊢ 𝟙 (X ⊞ Y) = fst ≫ inl [PROOFSTEP] rw [this, IsIso.inv_hom_id] [GOAL] case mpr J : Type w C : Type u inst✝² : Category.{v, u} C inst✝¹ : HasZeroMorphisms C P Q X Y : C inst✝ : HasBinaryBiproduct X Y ⊢ 𝟙 (X ⊞ Y) = fst ≫ inl → IsIso inl [PROOFSTEP] intro h [GOAL] case mpr J : Type w C : Type u inst✝² : Category.{v, u} C inst✝¹ : HasZeroMorphisms C P Q X Y : C inst✝ : HasBinaryBiproduct X Y h : 𝟙 (X ⊞ Y) = fst ≫ inl ⊢ IsIso inl [PROOFSTEP] exact ⟨⟨biprod.fst, biprod.inl_fst, h.symm⟩⟩ [GOAL] J : Type w C : Type u inst✝¹ : Category.{v, u} C inst✝ : HasZeroMorphisms C P Q X Y : C c : BinaryBicone X Y i : IsLimit (toCone c) s : Fork c.fst 0 ⊢ (Fork.ι s ≫ c.snd) ≫ Fork.ι (fstKernelFork c) = Fork.ι s [PROOFSTEP] apply BinaryFan.IsLimit.hom_ext i [GOAL] case h₁ J : Type w C : Type u inst✝¹ : Category.{v, u} C inst✝ : HasZeroMorphisms C P Q X Y : C c : BinaryBicone X Y i : IsLimit (toCone c) s : Fork c.fst 0 ⊢ ((Fork.ι s ≫ c.snd) ≫ Fork.ι (fstKernelFork c)) ≫ BinaryFan.fst (toCone c) = Fork.ι s ≫ BinaryFan.fst (toCone c) [PROOFSTEP] simp [GOAL] case h₂ J : Type w C : Type u inst✝¹ : Category.{v, u} C inst✝ : HasZeroMorphisms C P Q X Y : C c : BinaryBicone X Y i : IsLimit (toCone c) s : Fork c.fst 0 ⊢ ((Fork.ι s ≫ c.snd) ≫ Fork.ι (fstKernelFork c)) ≫ BinaryFan.snd (toCone c) = Fork.ι s ≫ BinaryFan.snd (toCone c) [PROOFSTEP] simp [GOAL] J : Type w C : Type u inst✝¹ : Category.{v, u} C inst✝ : HasZeroMorphisms C P Q X Y : C c : BinaryBicone X Y i : IsLimit (toCone c) s : Fork c.fst 0 m✝ : ((const WalkingParallelPair).obj s.pt).obj WalkingParallelPair.zero ⟶ ((const WalkingParallelPair).obj (fstKernelFork c).pt).obj WalkingParallelPair.zero hm : m✝ ≫ Fork.ι (fstKernelFork c) = Fork.ι s ⊢ m✝ = Fork.ι s ≫ c.snd [PROOFSTEP] simp [← hm] [GOAL] J : Type w C : Type u inst✝¹ : Category.{v, u} C inst✝ : HasZeroMorphisms C P Q X Y : C c : BinaryBicone X Y i : IsLimit (toCone c) s : Fork c.snd 0 ⊢ (Fork.ι s ≫ c.fst) ≫ Fork.ι (sndKernelFork c) = Fork.ι s [PROOFSTEP] apply BinaryFan.IsLimit.hom_ext i [GOAL] case h₁ J : Type w C : Type u inst✝¹ : Category.{v, u} C inst✝ : HasZeroMorphisms C P Q X Y : C c : BinaryBicone X Y i : IsLimit (toCone c) s : Fork c.snd 0 ⊢ ((Fork.ι s ≫ c.fst) ≫ Fork.ι (sndKernelFork c)) ≫ BinaryFan.fst (toCone c) = Fork.ι s ≫ BinaryFan.fst (toCone c) [PROOFSTEP] simp [GOAL] case h₂ J : Type w C : Type u inst✝¹ : Category.{v, u} C inst✝ : HasZeroMorphisms C P Q X Y : C c : BinaryBicone X Y i : IsLimit (toCone c) s : Fork c.snd 0 ⊢ ((Fork.ι s ≫ c.fst) ≫ Fork.ι (sndKernelFork c)) ≫ BinaryFan.snd (toCone c) = Fork.ι s ≫ BinaryFan.snd (toCone c) [PROOFSTEP] simp [GOAL] J : Type w C : Type u inst✝¹ : Category.{v, u} C inst✝ : HasZeroMorphisms C P Q X Y : C c : BinaryBicone X Y i : IsLimit (toCone c) s : Fork c.snd 0 m✝ : ((const WalkingParallelPair).obj s.pt).obj WalkingParallelPair.zero ⟶ ((const WalkingParallelPair).obj (sndKernelFork c).pt).obj WalkingParallelPair.zero hm : m✝ ≫ Fork.ι (sndKernelFork c) = Fork.ι s ⊢ m✝ = Fork.ι s ≫ c.fst [PROOFSTEP] simp [← hm] [GOAL] J : Type w C : Type u inst✝¹ : Category.{v, u} C inst✝ : HasZeroMorphisms C P Q X Y : C c : BinaryBicone X Y i : IsColimit (toCocone c) s : Cofork c.inl 0 ⊢ Cofork.π (inlCokernelCofork c) ≫ c.inr ≫ Cofork.π s = Cofork.π s [PROOFSTEP] apply BinaryCofan.IsColimit.hom_ext i [GOAL] case h₁ J : Type w C : Type u inst✝¹ : Category.{v, u} C inst✝ : HasZeroMorphisms C P Q X Y : C c : BinaryBicone X Y i : IsColimit (toCocone c) s : Cofork c.inl 0 ⊢ BinaryCofan.inl (toCocone c) ≫ Cofork.π (inlCokernelCofork c) ≫ c.inr ≫ Cofork.π s = BinaryCofan.inl (toCocone c) ≫ Cofork.π s [PROOFSTEP] simp [GOAL] case h₂ J : Type w C : Type u inst✝¹ : Category.{v, u} C inst✝ : HasZeroMorphisms C P Q X Y : C c : BinaryBicone X Y i : IsColimit (toCocone c) s : Cofork c.inl 0 ⊢ BinaryCofan.inr (toCocone c) ≫ Cofork.π (inlCokernelCofork c) ≫ c.inr ≫ Cofork.π s = BinaryCofan.inr (toCocone c) ≫ Cofork.π s [PROOFSTEP] simp [GOAL] J : Type w C : Type u inst✝¹ : Category.{v, u} C inst✝ : HasZeroMorphisms C P Q X Y : C c : BinaryBicone X Y i : IsColimit (toCocone c) s : Cofork c.inl 0 m✝ : ((const WalkingParallelPair).obj (inlCokernelCofork c).pt).obj WalkingParallelPair.one ⟶ ((const WalkingParallelPair).obj s.pt).obj WalkingParallelPair.one hm : Cofork.π (inlCokernelCofork c) ≫ m✝ = Cofork.π s ⊢ m✝ = c.inr ≫ Cofork.π s [PROOFSTEP] simp [← hm] [GOAL] J : Type w C : Type u inst✝¹ : Category.{v, u} C inst✝ : HasZeroMorphisms C P Q X Y : C c : BinaryBicone X Y i : IsColimit (toCocone c) s : Cofork c.inr 0 ⊢ Cofork.π (inrCokernelCofork c) ≫ c.inl ≫ Cofork.π s = Cofork.π s [PROOFSTEP] apply BinaryCofan.IsColimit.hom_ext i [GOAL] case h₁ J : Type w C : Type u inst✝¹ : Category.{v, u} C inst✝ : HasZeroMorphisms C P Q X Y : C c : BinaryBicone X Y i : IsColimit (toCocone c) s : Cofork c.inr 0 ⊢ BinaryCofan.inl (toCocone c) ≫ Cofork.π (inrCokernelCofork c) ≫ c.inl ≫ Cofork.π s = BinaryCofan.inl (toCocone c) ≫ Cofork.π s [PROOFSTEP] simp [GOAL] case h₂ J : Type w C : Type u inst✝¹ : Category.{v, u} C inst✝ : HasZeroMorphisms C P Q X Y : C c : BinaryBicone X Y i : IsColimit (toCocone c) s : Cofork c.inr 0 ⊢ BinaryCofan.inr (toCocone c) ≫ Cofork.π (inrCokernelCofork c) ≫ c.inl ≫ Cofork.π s = BinaryCofan.inr (toCocone c) ≫ Cofork.π s [PROOFSTEP] simp [GOAL] J : Type w C : Type u inst✝¹ : Category.{v, u} C inst✝ : HasZeroMorphisms C P Q X Y : C c : BinaryBicone X Y i : IsColimit (toCocone c) s : Cofork c.inr 0 m✝ : ((const WalkingParallelPair).obj (inrCokernelCofork c).pt).obj WalkingParallelPair.one ⟶ ((const WalkingParallelPair).obj s.pt).obj WalkingParallelPair.one hm : Cofork.π (inrCokernelCofork c) ≫ m✝ = Cofork.π s ⊢ m✝ = c.inl ≫ Cofork.π s [PROOFSTEP] simp [← hm] [GOAL] J : Type w C : Type u inst✝² : Category.{v, u} C inst✝¹ : HasZeroMorphisms C P Q X Y : C inst✝ : HasBinaryBiproduct X Y hY : IsZero Y ⊢ biprod.fst ≫ biprod.inl = 𝟙 (X ⊞ Y) [PROOFSTEP] apply CategoryTheory.Limits.biprod.hom_ext [GOAL] case h₀ J : Type w C : Type u inst✝² : Category.{v, u} C inst✝¹ : HasZeroMorphisms C P Q X Y : C inst✝ : HasBinaryBiproduct X Y hY : IsZero Y ⊢ (biprod.fst ≫ biprod.inl) ≫ biprod.fst = 𝟙 (X ⊞ Y) ≫ biprod.fst [PROOFSTEP] simp only [Category.assoc, biprod.inl_fst, Category.comp_id, Category.id_comp, biprod.inl_snd, comp_zero] [GOAL] case h₁ J : Type w C : Type u inst✝² : Category.{v, u} C inst✝¹ : HasZeroMorphisms C P Q X Y : C inst✝ : HasBinaryBiproduct X Y hY : IsZero Y ⊢ (biprod.fst ≫ biprod.inl) ≫ biprod.snd = 𝟙 (X ⊞ Y) ≫ biprod.snd [PROOFSTEP] simp only [Category.assoc, biprod.inl_fst, Category.comp_id, Category.id_comp, biprod.inl_snd, comp_zero] [GOAL] case h₁ J : Type w C : Type u inst✝² : Category.{v, u} C inst✝¹ : HasZeroMorphisms C P Q X Y : C inst✝ : HasBinaryBiproduct X Y hY : IsZero Y ⊢ 0 = biprod.snd [PROOFSTEP] apply hY.eq_of_tgt [GOAL] J : Type w C : Type u inst✝² : Category.{v, u} C inst✝¹ : HasZeroMorphisms C P Q X Y : C inst✝ : HasBinaryBiproduct X Y hY : IsZero X ⊢ biprod.snd ≫ biprod.inr = 𝟙 (X ⊞ Y) [PROOFSTEP] apply CategoryTheory.Limits.biprod.hom_ext [GOAL] case h₀ J : Type w C : Type u inst✝² : Category.{v, u} C inst✝¹ : HasZeroMorphisms C P Q X Y : C inst✝ : HasBinaryBiproduct X Y hY : IsZero X ⊢ (biprod.snd ≫ biprod.inr) ≫ biprod.fst = 𝟙 (X ⊞ Y) ≫ biprod.fst [PROOFSTEP] simp only [Category.assoc, biprod.inr_snd, Category.comp_id, Category.id_comp, biprod.inr_fst, comp_zero] [GOAL] case h₁ J : Type w C : Type u inst✝² : Category.{v, u} C inst✝¹ : HasZeroMorphisms C P Q X Y : C inst✝ : HasBinaryBiproduct X Y hY : IsZero X ⊢ (biprod.snd ≫ biprod.inr) ≫ biprod.snd = 𝟙 (X ⊞ Y) ≫ biprod.snd [PROOFSTEP] simp only [Category.assoc, biprod.inr_snd, Category.comp_id, Category.id_comp, biprod.inr_fst, comp_zero] [GOAL] case h₀ J : Type w C : Type u inst✝² : Category.{v, u} C inst✝¹ : HasZeroMorphisms C P Q X Y : C inst✝ : HasBinaryBiproduct X Y hY : IsZero X ⊢ 0 = biprod.fst [PROOFSTEP] apply hY.eq_of_tgt [GOAL] J : Type w C : Type u inst✝² : Category.{v, u} C inst✝¹ : HasZeroMorphisms C P✝ Q✝ : C inst✝ : HasBinaryBiproducts C P Q : C ⊢ braiding' P Q = braiding P Q [PROOFSTEP] aesop_cat [GOAL] J : Type w C : Type u inst✝² : Category.{v, u} C inst✝¹ : HasZeroMorphisms C P Q : C inst✝ : HasBinaryBiproducts C W X Y Z : C f : X ⟶ Y g : Z ⟶ W ⊢ map f g ≫ (braiding Y W).hom = (braiding X Z).hom ≫ map g f [PROOFSTEP] aesop_cat [GOAL] J : Type w C : Type u inst✝² : Category.{v, u} C inst✝¹ : HasZeroMorphisms C P Q : C inst✝ : HasBinaryBiproducts C W X Y Z : C f : W ⟶ Y g : X ⟶ Z ⊢ (braiding X W).hom ≫ map f g ≫ (braiding Y Z).hom = map g f [PROOFSTEP] aesop_cat [GOAL] J : Type w C : Type u inst✝² : Category.{v, u} C inst✝¹ : HasZeroMorphisms C P✝ Q✝ : C inst✝ : HasBinaryBiproducts C P Q : C ⊢ lift snd fst ≫ lift snd fst = 𝟙 (P ⊞ Q) [PROOFSTEP] aesop_cat [GOAL] J : Type w C : Type u inst✝² : Category.{v, u} C inst✝¹ : HasZeroMorphisms C P✝ Q✝ : C inst✝ : HasBinaryBiproducts C P Q : C ⊢ (braiding P Q).hom ≫ (braiding Q P).hom = 𝟙 (P ⊞ Q) [PROOFSTEP] simp [GOAL] C : Type u inst✝³ : Category.{v, u} C inst✝² : HasZeroMorphisms C inst✝¹ : HasBinaryBiproducts C W X Y Z : C f : W ⟶ Y g : X ⟶ Z inst✝ : IsIso (biprod.map f g) ⊢ f ≫ biprod.inl ≫ inv (biprod.map f g) ≫ biprod.fst = 𝟙 W [PROOFSTEP] have t := congrArg (fun p : W ⊞ X ⟶ W ⊞ X => biprod.inl ≫ p ≫ biprod.fst) (IsIso.hom_inv_id (biprod.map f g)) [GOAL] C : Type u inst✝³ : Category.{v, u} C inst✝² : HasZeroMorphisms C inst✝¹ : HasBinaryBiproducts C W X Y Z : C f : W ⟶ Y g : X ⟶ Z inst✝ : IsIso (biprod.map f g) t : (fun p => biprod.inl ≫ p ≫ biprod.fst) (biprod.map f g ≫ inv (biprod.map f g)) = (fun p => biprod.inl ≫ p ≫ biprod.fst) (𝟙 (W ⊞ X)) ⊢ f ≫ biprod.inl ≫ inv (biprod.map f g) ≫ biprod.fst = 𝟙 W [PROOFSTEP] simp only [Category.id_comp, Category.assoc, biprod.inl_map_assoc] at t [GOAL] C : Type u inst✝³ : Category.{v, u} C inst✝² : HasZeroMorphisms C inst✝¹ : HasBinaryBiproducts C W X Y Z : C f : W ⟶ Y g : X ⟶ Z inst✝ : IsIso (biprod.map f g) t : f ≫ biprod.inl ≫ inv (biprod.map f g) ≫ biprod.fst = biprod.inl ≫ biprod.fst ⊢ f ≫ biprod.inl ≫ inv (biprod.map f g) ≫ biprod.fst = 𝟙 W [PROOFSTEP] simp [t] [GOAL] C : Type u inst✝³ : Category.{v, u} C inst✝² : HasZeroMorphisms C inst✝¹ : HasBinaryBiproducts C W X Y Z : C f : W ⟶ Y g : X ⟶ Z inst✝ : IsIso (biprod.map f g) ⊢ (biprod.inl ≫ inv (biprod.map f g) ≫ biprod.fst) ≫ f = 𝟙 Y [PROOFSTEP] have t := congrArg (fun p : Y ⊞ Z ⟶ Y ⊞ Z => biprod.inl ≫ p ≫ biprod.fst) (IsIso.inv_hom_id (biprod.map f g)) [GOAL] C : Type u inst✝³ : Category.{v, u} C inst✝² : HasZeroMorphisms C inst✝¹ : HasBinaryBiproducts C W X Y Z : C f : W ⟶ Y g : X ⟶ Z inst✝ : IsIso (biprod.map f g) t : (fun p => biprod.inl ≫ p ≫ biprod.fst) (inv (biprod.map f g) ≫ biprod.map f g) = (fun p => biprod.inl ≫ p ≫ biprod.fst) (𝟙 (Y ⊞ Z)) ⊢ (biprod.inl ≫ inv (biprod.map f g) ≫ biprod.fst) ≫ f = 𝟙 Y [PROOFSTEP] simp only [Category.id_comp, Category.assoc, biprod.map_fst] at t [GOAL] C : Type u inst✝³ : Category.{v, u} C inst✝² : HasZeroMorphisms C inst✝¹ : HasBinaryBiproducts C W X Y Z : C f : W ⟶ Y g : X ⟶ Z inst✝ : IsIso (biprod.map f g) t : biprod.inl ≫ inv (biprod.map f g) ≫ biprod.fst ≫ f = biprod.inl ≫ biprod.fst ⊢ (biprod.inl ≫ inv (biprod.map f g) ≫ biprod.fst) ≫ f = 𝟙 Y [PROOFSTEP] simp only [Category.assoc] [GOAL] C : Type u inst✝³ : Category.{v, u} C inst✝² : HasZeroMorphisms C inst✝¹ : HasBinaryBiproducts C W X Y Z : C f : W ⟶ Y g : X ⟶ Z inst✝ : IsIso (biprod.map f g) t : biprod.inl ≫ inv (biprod.map f g) ≫ biprod.fst ≫ f = biprod.inl ≫ biprod.fst ⊢ biprod.inl ≫ inv (biprod.map f g) ≫ biprod.fst ≫ f = 𝟙 Y [PROOFSTEP] simp [t] [GOAL] C : Type u inst✝³ : Category.{v, u} C inst✝² : HasZeroMorphisms C inst✝¹ : HasBinaryBiproducts C W X Y Z : C f : W ⟶ Y g : X ⟶ Z inst✝ : IsIso (biprod.map f g) ⊢ IsIso (biprod.map g f) [PROOFSTEP] rw [← biprod.braiding_map_braiding] [GOAL] C : Type u inst✝³ : Category.{v, u} C inst✝² : HasZeroMorphisms C inst✝¹ : HasBinaryBiproducts C W X Y Z : C f : W ⟶ Y g : X ⟶ Z inst✝ : IsIso (biprod.map f g) ⊢ IsIso ((biprod.braiding X W).hom ≫ biprod.map f g ≫ (biprod.braiding Y Z).hom) [PROOFSTEP] infer_instance
module ImportWarningsB where -- all of the following files have warnings, which should be displayed -- when loading this file import Issue1988 import Issue2243 import Issue708quote import OldCompilerPragmas import RewritingEmptyPragma import Unreachable -- this warning will be ignored {-# REWRITE #-}
# This file was generated, do not modify it. # hide stand = machine(Standardizer(), Xs) W = transform(stand, Xs)
using WGLMakie x₀ = 0.0 Δx = 0.1 fps = 50 nframes = 500 xs = Observable([x₀]) ys = Observable([sin(x₀)]) fig, ax, = lines(ys, figure=(resolution=(500,400),)) limits!(ax, 0, nframes, -1.5, 1.5) @time for i = 1:nframes x = xs[][i] + Δx xs[] = push!(xs[], x) ys[] = push!(ys[], sin(x)) sleep(1 / fps) end fig