Datasets:
AI4M
/

text
stringlengths
0
3.34M
[GOAL] K : Type u L : Type v M : Type w inst✝³ : Field K inst✝² : Field L inst✝¹ : Field M S : Type u_1 inst✝ : SetLike S K h : SubfieldClass S K s : S x : ℚ ⊢ ↑x ∈ s [PROOFSTEP] simpa only [Rat.cast_def] using div_mem (coe_int_mem s x.num) (coe_nat_mem s x.den) [GOAL] K : Type u L : Type v M : Type w inst✝³ : Field K inst✝² : Field L inst✝¹ : Field M S : Type u_1 inst✝ : SetLike S K h : SubfieldClass S K s : S a : ℚ x : { x // x ∈ s } ⊢ a • ↑x ∈ s [PROOFSTEP] simpa only [Rat.smul_def] using mul_mem (coe_rat_mem s a) x.prop [GOAL] K : Type u L : Type v M : Type w inst✝³ : Field K inst✝² : Field L inst✝¹ : Field M S : Type u_1 inst✝ : SetLike S K h : SubfieldClass S K s : S ⊢ ↑0 = 0 [PROOFSTEP] rfl [GOAL] K : Type u L : Type v M : Type w inst✝³ : Field K inst✝² : Field L inst✝¹ : Field M S : Type u_1 inst✝ : SetLike S K h : SubfieldClass S K s : S ⊢ ↑1 = 1 [PROOFSTEP] rfl [GOAL] K : Type u L : Type v M : Type w inst✝³ : Field K inst✝² : Field L inst✝¹ : Field M S : Type u_1 inst✝ : SetLike S K h : SubfieldClass S K s : S ⊢ ∀ (x y : { x // x ∈ s }), ↑(x + y) = ↑x + ↑y [PROOFSTEP] intros _ _ [GOAL] K : Type u L : Type v M : Type w inst✝³ : Field K inst✝² : Field L inst✝¹ : Field M S : Type u_1 inst✝ : SetLike S K h : SubfieldClass S K s : S x✝ y✝ : { x // x ∈ s } ⊢ ↑(x✝ + y✝) = ↑x✝ + ↑y✝ [PROOFSTEP] rfl [GOAL] K : Type u L : Type v M : Type w inst✝³ : Field K inst✝² : Field L inst✝¹ : Field M S : Type u_1 inst✝ : SetLike S K h : SubfieldClass S K s : S ⊢ ∀ (x y : { x // x ∈ s }), ↑(x * y) = ↑x * ↑y [PROOFSTEP] intros _ _ [GOAL] K : Type u L : Type v M : Type w inst✝³ : Field K inst✝² : Field L inst✝¹ : Field M S : Type u_1 inst✝ : SetLike S K h : SubfieldClass S K s : S x✝ y✝ : { x // x ∈ s } ⊢ ↑(x✝ * y✝) = ↑x✝ * ↑y✝ [PROOFSTEP] rfl [GOAL] K : Type u L : Type v M : Type w inst✝³ : Field K inst✝² : Field L inst✝¹ : Field M S : Type u_1 inst✝ : SetLike S K h : SubfieldClass S K s : S ⊢ ∀ (x : { x // x ∈ s }), ↑(-x) = -↑x [PROOFSTEP] intros _ [GOAL] K : Type u L : Type v M : Type w inst✝³ : Field K inst✝² : Field L inst✝¹ : Field M S : Type u_1 inst✝ : SetLike S K h : SubfieldClass S K s : S x✝ : { x // x ∈ s } ⊢ ↑(-x✝) = -↑x✝ [PROOFSTEP] rfl [GOAL] K : Type u L : Type v M : Type w inst✝³ : Field K inst✝² : Field L inst✝¹ : Field M S : Type u_1 inst✝ : SetLike S K h : SubfieldClass S K s : S ⊢ ∀ (x y : { x // x ∈ s }), ↑(x - y) = ↑x - ↑y [PROOFSTEP] intros _ _ [GOAL] K : Type u L : Type v M : Type w inst✝³ : Field K inst✝² : Field L inst✝¹ : Field M S : Type u_1 inst✝ : SetLike S K h : SubfieldClass S K s : S x✝ y✝ : { x // x ∈ s } ⊢ ↑(x✝ - y✝) = ↑x✝ - ↑y✝ [PROOFSTEP] rfl [GOAL] K : Type u L : Type v M : Type w inst✝³ : Field K inst✝² : Field L inst✝¹ : Field M S : Type u_1 inst✝ : SetLike S K h : SubfieldClass S K s : S ⊢ ∀ (x : { x // x ∈ s }), ↑x⁻¹ = (↑x)⁻¹ [PROOFSTEP] intros _ [GOAL] K : Type u L : Type v M : Type w inst✝³ : Field K inst✝² : Field L inst✝¹ : Field M S : Type u_1 inst✝ : SetLike S K h : SubfieldClass S K s : S x✝ : { x // x ∈ s } ⊢ ↑x✝⁻¹ = (↑x✝)⁻¹ [PROOFSTEP] rfl [GOAL] K : Type u L : Type v M : Type w inst✝³ : Field K inst✝² : Field L inst✝¹ : Field M S : Type u_1 inst✝ : SetLike S K h : SubfieldClass S K s : S ⊢ ∀ (x y : { x // x ∈ s }), ↑(x / y) = ↑x / ↑y [PROOFSTEP] intros _ _ [GOAL] K : Type u L : Type v M : Type w inst✝³ : Field K inst✝² : Field L inst✝¹ : Field M S : Type u_1 inst✝ : SetLike S K h : SubfieldClass S K s : S x✝ y✝ : { x // x ∈ s } ⊢ ↑(x✝ / y✝) = ↑x✝ / ↑y✝ [PROOFSTEP] rfl [GOAL] K : Type u L : Type v M : Type w inst✝³ : Field K inst✝² : Field L inst✝¹ : Field M S : Type u_1 inst✝ : SetLike S K h : SubfieldClass S K s : S ⊢ ∀ (x : { x // x ∈ s }) (n : ℕ), ↑(n • x) = n • ↑x [PROOFSTEP] intros _ _ [GOAL] K : Type u L : Type v M : Type w inst✝³ : Field K inst✝² : Field L inst✝¹ : Field M S : Type u_1 inst✝ : SetLike S K h : SubfieldClass S K s : S x✝ : { x // x ∈ s } n✝ : ℕ ⊢ ↑(n✝ • x✝) = n✝ • ↑x✝ [PROOFSTEP] rfl [GOAL] K : Type u L : Type v M : Type w inst✝³ : Field K inst✝² : Field L inst✝¹ : Field M S : Type u_1 inst✝ : SetLike S K h : SubfieldClass S K s : S ⊢ ∀ (x : { x // x ∈ s }) (n : ℤ), ↑(n • x) = n • ↑x [PROOFSTEP] intros _ _ [GOAL] K : Type u L : Type v M : Type w inst✝³ : Field K inst✝² : Field L inst✝¹ : Field M S : Type u_1 inst✝ : SetLike S K h : SubfieldClass S K s : S x✝ : { x // x ∈ s } n✝ : ℤ ⊢ ↑(n✝ • x✝) = n✝ • ↑x✝ [PROOFSTEP] rfl [GOAL] K : Type u L : Type v M : Type w inst✝³ : Field K inst✝² : Field L inst✝¹ : Field M S : Type u_1 inst✝ : SetLike S K h : SubfieldClass S K s : S ⊢ ∀ (x : { x // x ∈ s }) (n : ℚ), ↑(n • x) = n • ↑x [PROOFSTEP] intros _ _ [GOAL] K : Type u L : Type v M : Type w inst✝³ : Field K inst✝² : Field L inst✝¹ : Field M S : Type u_1 inst✝ : SetLike S K h : SubfieldClass S K s : S x✝ : { x // x ∈ s } n✝ : ℚ ⊢ ↑(n✝ • x✝) = n✝ • ↑x✝ [PROOFSTEP] rfl [GOAL] K : Type u L : Type v M : Type w inst✝³ : Field K inst✝² : Field L inst✝¹ : Field M S : Type u_1 inst✝ : SetLike S K h : SubfieldClass S K s : S ⊢ ∀ (x : { x // x ∈ s }) (n : ℕ), ↑(x ^ n) = ↑x ^ n [PROOFSTEP] intros _ _ [GOAL] K : Type u L : Type v M : Type w inst✝³ : Field K inst✝² : Field L inst✝¹ : Field M S : Type u_1 inst✝ : SetLike S K h : SubfieldClass S K s : S x✝ : { x // x ∈ s } n✝ : ℕ ⊢ ↑(x✝ ^ n✝) = ↑x✝ ^ n✝ [PROOFSTEP] rfl [GOAL] K : Type u L : Type v M : Type w inst✝³ : Field K inst✝² : Field L inst✝¹ : Field M S : Type u_1 inst✝ : SetLike S K h : SubfieldClass S K s : S ⊢ ∀ (x : { x // x ∈ s }) (n : ℤ), ↑(x ^ n) = ↑x ^ n [PROOFSTEP] intros _ _ [GOAL] K : Type u L : Type v M : Type w inst✝³ : Field K inst✝² : Field L inst✝¹ : Field M S : Type u_1 inst✝ : SetLike S K h : SubfieldClass S K s : S x✝ : { x // x ∈ s } n✝ : ℤ ⊢ ↑(x✝ ^ n✝) = ↑x✝ ^ n✝ [PROOFSTEP] rfl [GOAL] K : Type u L : Type v M : Type w inst✝³ : Field K inst✝² : Field L inst✝¹ : Field M S : Type u_1 inst✝ : SetLike S K h : SubfieldClass S K s : S ⊢ ∀ (n : ℕ), ↑↑n = ↑n [PROOFSTEP] intros _ [GOAL] K : Type u L : Type v M : Type w inst✝³ : Field K inst✝² : Field L inst✝¹ : Field M S : Type u_1 inst✝ : SetLike S K h : SubfieldClass S K s : S n✝ : ℕ ⊢ ↑↑n✝ = ↑n✝ [PROOFSTEP] rfl [GOAL] K : Type u L : Type v M : Type w inst✝³ : Field K inst✝² : Field L inst✝¹ : Field M S : Type u_1 inst✝ : SetLike S K h : SubfieldClass S K s : S ⊢ ∀ (n : ℤ), ↑↑n = ↑n [PROOFSTEP] intros _ [GOAL] K : Type u L : Type v M : Type w inst✝³ : Field K inst✝² : Field L inst✝¹ : Field M S : Type u_1 inst✝ : SetLike S K h : SubfieldClass S K s : S n✝ : ℤ ⊢ ↑↑n✝ = ↑n✝ [PROOFSTEP] rfl [GOAL] K : Type u L : Type v M : Type w inst✝³ : Field K inst✝² : Field L inst✝¹ : Field M S : Type u_1 inst✝ : SetLike S K h : SubfieldClass S K s : S ⊢ ∀ (n : ℚ), ↑↑n = ↑n [PROOFSTEP] intros _ [GOAL] K : Type u L : Type v M : Type w inst✝³ : Field K inst✝² : Field L inst✝¹ : Field M S : Type u_1 inst✝ : SetLike S K h : SubfieldClass S K s : S n✝ : ℚ ⊢ ↑↑n✝ = ↑n✝ [PROOFSTEP] rfl [GOAL] K : Type u L : Type v M : Type w inst✝² : Field K inst✝¹ : Field L inst✝ : Field M p q : Subfield K h : (fun s => s.carrier) p = (fun s => s.carrier) q ⊢ p = q [PROOFSTEP] cases p [GOAL] case mk K : Type u L : Type v M : Type w inst✝² : Field K inst✝¹ : Field L inst✝ : Field M q : Subfield K toSubring✝ : Subring K inv_mem'✝ : ∀ (x : K), x ∈ toSubring✝.carrier → x⁻¹ ∈ toSubring✝.carrier h : (fun s => s.carrier) { toSubring := toSubring✝, inv_mem' := inv_mem'✝ } = (fun s => s.carrier) q ⊢ { toSubring := toSubring✝, inv_mem' := inv_mem'✝ } = q [PROOFSTEP] cases q [GOAL] case mk.mk K : Type u L : Type v M : Type w inst✝² : Field K inst✝¹ : Field L inst✝ : Field M toSubring✝¹ : Subring K inv_mem'✝¹ : ∀ (x : K), x ∈ toSubring✝¹.carrier → x⁻¹ ∈ toSubring✝¹.carrier toSubring✝ : Subring K inv_mem'✝ : ∀ (x : K), x ∈ toSubring✝.carrier → x⁻¹ ∈ toSubring✝.carrier h : (fun s => s.carrier) { toSubring := toSubring✝¹, inv_mem' := inv_mem'✝¹ } = (fun s => s.carrier) { toSubring := toSubring✝, inv_mem' := inv_mem'✝ } ⊢ { toSubring := toSubring✝¹, inv_mem' := inv_mem'✝¹ } = { toSubring := toSubring✝, inv_mem' := inv_mem'✝ } [PROOFSTEP] congr [GOAL] case mk.mk.e_toSubring K : Type u L : Type v M : Type w inst✝² : Field K inst✝¹ : Field L inst✝ : Field M toSubring✝¹ : Subring K inv_mem'✝¹ : ∀ (x : K), x ∈ toSubring✝¹.carrier → x⁻¹ ∈ toSubring✝¹.carrier toSubring✝ : Subring K inv_mem'✝ : ∀ (x : K), x ∈ toSubring✝.carrier → x⁻¹ ∈ toSubring✝.carrier h : (fun s => s.carrier) { toSubring := toSubring✝¹, inv_mem' := inv_mem'✝¹ } = (fun s => s.carrier) { toSubring := toSubring✝, inv_mem' := inv_mem'✝ } ⊢ toSubring✝¹ = toSubring✝ [PROOFSTEP] exact SetLike.ext' h [GOAL] K : Type u L : Type v M : Type w inst✝² : Field K inst✝¹ : Field L inst✝ : Field M s t : Subfield K x : K hx : x ∈ s n : ℤ ⊢ x ^ n ∈ s [PROOFSTEP] cases n [GOAL] case ofNat K : Type u L : Type v M : Type w inst✝² : Field K inst✝¹ : Field L inst✝ : Field M s t : Subfield K x : K hx : x ∈ s a✝ : ℕ ⊢ x ^ Int.ofNat a✝ ∈ s [PROOFSTEP] simpa using s.pow_mem hx _ [GOAL] case negSucc K : Type u L : Type v M : Type w inst✝² : Field K inst✝¹ : Field L inst✝ : Field M s t : Subfield K x : K hx : x ∈ s a✝ : ℕ ⊢ x ^ Int.negSucc a✝ ∈ s [PROOFSTEP] simpa [pow_succ] using s.inv_mem (s.mul_mem hx (s.pow_mem hx _)) [GOAL] K : Type u L : Type v M : Type w inst✝² : Field K inst✝¹ : Field L inst✝ : Field M s✝ t : Subfield K f : K →+* L s : Subfield L src✝ : Subring K := Subring.comap f s.toSubring x : K hx : x ∈ { toSubsemiring := src✝.toSubsemiring, neg_mem' := (_ : ∀ {x : K}, x ∈ src✝.carrier → -x ∈ src✝.carrier) }.toSubsemiring.toSubmonoid.toSubsemigroup.carrier ⊢ ↑f x⁻¹ ∈ s [PROOFSTEP] rw [map_inv₀ f] [GOAL] K : Type u L : Type v M : Type w inst✝² : Field K inst✝¹ : Field L inst✝ : Field M s✝ t : Subfield K f : K →+* L s : Subfield L src✝ : Subring K := Subring.comap f s.toSubring x : K hx : x ∈ { toSubsemiring := src✝.toSubsemiring, neg_mem' := (_ : ∀ {x : K}, x ∈ src✝.carrier → -x ∈ src✝.carrier) }.toSubsemiring.toSubmonoid.toSubsemigroup.carrier ⊢ (↑f x)⁻¹ ∈ s [PROOFSTEP] exact s.inv_mem hx [GOAL] K : Type u L : Type v M : Type w inst✝² : Field K inst✝¹ : Field L inst✝ : Field M s✝ t : Subfield K f : K →+* L s : Subfield K src✝ : Subring L := Subring.map f s.toSubring ⊢ ∀ (x : L), x ∈ { toSubsemiring := src✝.toSubsemiring, neg_mem' := (_ : ∀ {x : L}, x ∈ src✝.carrier → -x ∈ src✝.carrier) }.toSubsemiring.toSubmonoid.toSubsemigroup.carrier → x⁻¹ ∈ { toSubsemiring := src✝.toSubsemiring, neg_mem' := (_ : ∀ {x : L}, x ∈ src✝.carrier → -x ∈ src✝.carrier) }.toSubsemiring.toSubmonoid.toSubsemigroup.carrier [PROOFSTEP] rintro _ ⟨x, hx, rfl⟩ [GOAL] case intro.intro K : Type u L : Type v M : Type w inst✝² : Field K inst✝¹ : Field L inst✝ : Field M s✝ t : Subfield K f : K →+* L s : Subfield K src✝ : Subring L := Subring.map f s.toSubring x : K hx : x ∈ s.carrier ⊢ (↑f x)⁻¹ ∈ { toSubsemiring := src✝.toSubsemiring, neg_mem' := (_ : ∀ {x : L}, x ∈ src✝.carrier → -x ∈ src✝.carrier) }.toSubsemiring.toSubmonoid.toSubsemigroup.carrier [PROOFSTEP] exact ⟨x⁻¹, s.inv_mem hx, map_inv₀ f x⟩ [GOAL] K : Type u L : Type v M : Type w inst✝² : Field K inst✝¹ : Field L inst✝ : Field M s✝ t : Subfield K f✝ f : K →+* L s : Subfield K y : L ⊢ y ∈ map f s ↔ ∃ x, x ∈ s ∧ ↑f x = y [PROOFSTEP] unfold map [GOAL] K : Type u L : Type v M : Type w inst✝² : Field K inst✝¹ : Field L inst✝ : Field M s✝ t : Subfield K f✝ f : K →+* L s : Subfield K y : L ⊢ (y ∈ let src := Subring.map f s.toSubring; { toSubring := { toSubsemiring := src.toSubsemiring, neg_mem' := (_ : ∀ {x : L}, x ∈ (Subring.map f s.toSubring).toSubsemiring.toSubmonoid.toSubsemigroup.carrier → -x ∈ (Subring.map f s.toSubring).toSubsemiring.toSubmonoid.toSubsemigroup.carrier) }, inv_mem' := (_ : ∀ (x : L), x ∈ { toSubsemiring := (Subring.map f s.toSubring).toSubsemiring, neg_mem' := (_ : ∀ {x : L}, x ∈ (Subring.map f s.toSubring).toSubsemiring.toSubmonoid.toSubsemigroup.carrier → -x ∈ (Subring.map f s.toSubring).toSubsemiring.toSubmonoid.toSubsemigroup.carrier) }.toSubsemiring.toSubmonoid.toSubsemigroup.carrier → x⁻¹ ∈ { toSubsemiring := (Subring.map f s.toSubring).toSubsemiring, neg_mem' := (_ : ∀ {x : L}, x ∈ (Subring.map f s.toSubring).toSubsemiring.toSubmonoid.toSubsemigroup.carrier → -x ∈ (Subring.map f s.toSubring).toSubsemiring.toSubmonoid.toSubsemigroup.carrier) }.toSubsemiring.toSubmonoid.toSubsemigroup.carrier) }) ↔ ∃ x, x ∈ s ∧ ↑f x = y [PROOFSTEP] simp only [mem_mk, Subring.mem_mk, Subring.mem_toSubsemiring, Subring.mem_map, mem_toSubring] [GOAL] K : Type u L : Type v M : Type w inst✝² : Field K inst✝¹ : Field L inst✝ : Field M g : L →+* M f : K →+* L ⊢ fieldRange f = Subfield.map f ⊤ [PROOFSTEP] ext [GOAL] case h K : Type u L : Type v M : Type w inst✝² : Field K inst✝¹ : Field L inst✝ : Field M g : L →+* M f : K →+* L x✝ : L ⊢ x✝ ∈ fieldRange f ↔ x✝ ∈ Subfield.map f ⊤ [PROOFSTEP] simp [GOAL] K : Type u L : Type v M : Type w inst✝² : Field K inst✝¹ : Field L inst✝ : Field M g : L →+* M f : K →+* L ⊢ Subfield.map g (fieldRange f) = fieldRange (comp g f) [PROOFSTEP] simpa only [fieldRange_eq_map] using (⊤ : Subfield K).map_map g f [GOAL] K : Type u L : Type v M : Type w inst✝² : Field K inst✝¹ : Field L inst✝ : Field M S : Set (Subfield K) src✝ : Subring K := sInf (toSubring '' S) ⊢ ∀ (x : K), x ∈ { toSubsemiring := src✝.toSubsemiring, neg_mem' := (_ : ∀ {x : K}, x ∈ src✝.carrier → -x ∈ src✝.carrier) }.toSubsemiring.toSubmonoid.toSubsemigroup.carrier → x⁻¹ ∈ { toSubsemiring := src✝.toSubsemiring, neg_mem' := (_ : ∀ {x : K}, x ∈ src✝.carrier → -x ∈ src✝.carrier) }.toSubsemiring.toSubmonoid.toSubsemigroup.carrier [PROOFSTEP] rintro x hx [GOAL] K : Type u L : Type v M : Type w inst✝² : Field K inst✝¹ : Field L inst✝ : Field M S : Set (Subfield K) src✝ : Subring K := sInf (toSubring '' S) x : K hx : x ∈ { toSubsemiring := src✝.toSubsemiring, neg_mem' := (_ : ∀ {x : K}, x ∈ src✝.carrier → -x ∈ src✝.carrier) }.toSubsemiring.toSubmonoid.toSubsemigroup.carrier ⊢ x⁻¹ ∈ { toSubsemiring := src✝.toSubsemiring, neg_mem' := (_ : ∀ {x : K}, x ∈ src✝.carrier → -x ∈ src✝.carrier) }.toSubsemiring.toSubmonoid.toSubsemigroup.carrier [PROOFSTEP] apply Subring.mem_sInf.mpr [GOAL] K : Type u L : Type v M : Type w inst✝² : Field K inst✝¹ : Field L inst✝ : Field M S : Set (Subfield K) src✝ : Subring K := sInf (toSubring '' S) x : K hx : x ∈ { toSubsemiring := src✝.toSubsemiring, neg_mem' := (_ : ∀ {x : K}, x ∈ src✝.carrier → -x ∈ src✝.carrier) }.toSubsemiring.toSubmonoid.toSubsemigroup.carrier ⊢ ∀ (p : Subring K), p ∈ toSubring '' S → x⁻¹ ∈ p [PROOFSTEP] rintro _ ⟨p, p_mem, rfl⟩ [GOAL] case intro.intro K : Type u L : Type v M : Type w inst✝² : Field K inst✝¹ : Field L inst✝ : Field M S : Set (Subfield K) src✝ : Subring K := sInf (toSubring '' S) x : K hx : x ∈ { toSubsemiring := src✝.toSubsemiring, neg_mem' := (_ : ∀ {x : K}, x ∈ src✝.carrier → -x ∈ src✝.carrier) }.toSubsemiring.toSubmonoid.toSubsemigroup.carrier p : Subfield K p_mem : p ∈ S ⊢ x⁻¹ ∈ p.toSubring [PROOFSTEP] exact p.inv_mem (Subring.mem_sInf.mp hx p.toSubring ⟨p, p_mem, rfl⟩) [GOAL] K : Type u L : Type v M : Type w inst✝² : Field K inst✝¹ : Field L inst✝ : Field M S : Set (Subfield K) ⊢ ↑(sInf (toSubring '' S)) = ⋂ (s : Subfield K) (_ : s ∈ S), ↑s [PROOFSTEP] ext x [GOAL] case h K : Type u L : Type v M : Type w inst✝² : Field K inst✝¹ : Field L inst✝ : Field M S : Set (Subfield K) x : K ⊢ x ∈ ↑(sInf (toSubring '' S)) ↔ x ∈ ⋂ (s : Subfield K) (_ : s ∈ S), ↑s [PROOFSTEP] rw [Subring.coe_sInf, Set.mem_iInter, Set.mem_iInter] [GOAL] case h K : Type u L : Type v M : Type w inst✝² : Field K inst✝¹ : Field L inst✝ : Field M S : Set (Subfield K) x : K ⊢ (∀ (i : Subring K), x ∈ ⋂ (_ : i ∈ toSubring '' S), ↑i) ↔ ∀ (i : Subfield K), x ∈ ⋂ (_ : i ∈ S), ↑i [PROOFSTEP] exact ⟨fun h s s' ⟨s_mem, s'_eq⟩ => h s.toSubring _ ⟨⟨s, s_mem, rfl⟩, s'_eq⟩, fun h s s' ⟨⟨s'', s''_mem, s_eq⟩, (s'_eq : ↑s = s')⟩ => h s'' _ ⟨s''_mem, by simp [← s_eq, ← s'_eq]⟩⟩ [GOAL] K : Type u L : Type v M : Type w inst✝² : Field K inst✝¹ : Field L inst✝ : Field M S : Set (Subfield K) x : K h : ∀ (i : Subfield K), x ∈ ⋂ (_ : i ∈ S), ↑i s : Subring K s' : Set K x✝ : s' ∈ Set.range fun h => ↑s s'' : Subfield K s''_mem : s'' ∈ S s_eq : s''.toSubring = s s'_eq : ↑s = s' ⊢ (fun h => ↑s'') s''_mem = s' [PROOFSTEP] simp [← s_eq, ← s'_eq] [GOAL] K : Type u L : Type v M : Type w inst✝² : Field K inst✝¹ : Field L inst✝ : Field M s : Set (Subfield K) ⊢ (sInf s).toSubring = ⨅ (t : Subfield K) (_ : t ∈ s), t.toSubring [PROOFSTEP] ext x [GOAL] case h K : Type u L : Type v M : Type w inst✝² : Field K inst✝¹ : Field L inst✝ : Field M s : Set (Subfield K) x : K ⊢ x ∈ (sInf s).toSubring ↔ x ∈ ⨅ (t : Subfield K) (_ : t ∈ s), t.toSubring [PROOFSTEP] rw [mem_toSubring, mem_sInf] [GOAL] case h K : Type u L : Type v M : Type w inst✝² : Field K inst✝¹ : Field L inst✝ : Field M s : Set (Subfield K) x : K ⊢ (∀ (p : Subfield K), p ∈ s → x ∈ p) ↔ x ∈ ⨅ (t : Subfield K) (_ : t ∈ s), t.toSubring [PROOFSTEP] erw [Subring.mem_sInf] [GOAL] case h K : Type u L : Type v M : Type w inst✝² : Field K inst✝¹ : Field L inst✝ : Field M s : Set (Subfield K) x : K ⊢ (∀ (p : Subfield K), p ∈ s → x ∈ p) ↔ ∀ (p : Subring K), (p ∈ Set.range fun t => ⨅ (_ : t ∈ s), t.toSubring) → x ∈ p [PROOFSTEP] exact ⟨fun h p ⟨p', hp⟩ => hp ▸ Subring.mem_sInf.mpr fun p ⟨hp', hp⟩ => hp ▸ h _ hp', fun h p hp => h p.toSubring ⟨p, Subring.ext fun x => ⟨fun hx => Subring.mem_sInf.mp hx _ ⟨hp, rfl⟩, fun hx => Subring.mem_sInf.mpr fun p' ⟨_, p'_eq⟩ => p'_eq ▸ hx⟩⟩⟩ [GOAL] K : Type u L : Type v M : Type w inst✝² : Field K inst✝¹ : Field L inst✝ : Field M S : Set (Subfield K) ⊢ IsGLB S (sInf S) [PROOFSTEP] have : ∀ {s t : Subfield K}, (s : Set K) ≤ t ↔ s ≤ t := by simp [SetLike.coe_subset_coe] [GOAL] K : Type u L : Type v M : Type w inst✝² : Field K inst✝¹ : Field L inst✝ : Field M S : Set (Subfield K) ⊢ ∀ {s t : Subfield K}, ↑s ≤ ↑t ↔ s ≤ t [PROOFSTEP] simp [SetLike.coe_subset_coe] [GOAL] K : Type u L : Type v M : Type w inst✝² : Field K inst✝¹ : Field L inst✝ : Field M S : Set (Subfield K) this : ∀ {s t : Subfield K}, ↑s ≤ ↑t ↔ s ≤ t ⊢ IsGLB S (sInf S) [PROOFSTEP] refine' IsGLB.of_image this _ [GOAL] K : Type u L : Type v M : Type w inst✝² : Field K inst✝¹ : Field L inst✝ : Field M S : Set (Subfield K) this : ∀ {s t : Subfield K}, ↑s ≤ ↑t ↔ s ≤ t ⊢ IsGLB ((fun {x} => ↑x) '' S) ↑(sInf S) [PROOFSTEP] convert isGLB_biInf (s := S) (f := SetLike.coe) [GOAL] case h.e'_4 K : Type u L : Type v M : Type w inst✝² : Field K inst✝¹ : Field L inst✝ : Field M S : Set (Subfield K) this : ∀ {s t : Subfield K}, ↑s ≤ ↑t ↔ s ≤ t ⊢ ↑(sInf S) = ⨅ (x : Subfield K) (_ : x ∈ S), ↑x [PROOFSTEP] exact coe_sInf _ [GOAL] K : Type u L : Type v M : Type w inst✝² : Field K inst✝¹ : Field L inst✝ : Field M s : Set K a✝ b✝ : K x_mem : a✝ ∈ {z | ∃ x x_1 y x_2, x / y = z} y_mem : b✝ ∈ {z | ∃ x x_1 y x_2, x / y = z} ⊢ a✝ * b✝ ∈ {z | ∃ x x_1 y x_2, x / y = z} [PROOFSTEP] obtain ⟨nx, hnx, dx, hdx, rfl⟩ := id x_mem [GOAL] case intro.intro.intro.intro K : Type u L : Type v M : Type w inst✝² : Field K inst✝¹ : Field L inst✝ : Field M s : Set K b✝ : K y_mem : b✝ ∈ {z | ∃ x x_1 y x_2, x / y = z} nx : K hnx : nx ∈ Subring.closure s dx : K hdx : dx ∈ Subring.closure s x_mem : nx / dx ∈ {z | ∃ x x_1 y x_2, x / y = z} ⊢ nx / dx * b✝ ∈ {z | ∃ x x_1 y x_2, x / y = z} [PROOFSTEP] obtain ⟨ny, hny, dy, hdy, rfl⟩ := id y_mem [GOAL] case intro.intro.intro.intro.intro.intro.intro.intro K : Type u L : Type v M : Type w inst✝² : Field K inst✝¹ : Field L inst✝ : Field M s : Set K nx : K hnx : nx ∈ Subring.closure s dx : K hdx : dx ∈ Subring.closure s x_mem : nx / dx ∈ {z | ∃ x x_1 y x_2, x / y = z} ny : K hny : ny ∈ Subring.closure s dy : K hdy : dy ∈ Subring.closure s y_mem : ny / dy ∈ {z | ∃ x x_1 y x_2, x / y = z} ⊢ nx / dx * (ny / dy) ∈ {z | ∃ x x_1 y x_2, x / y = z} [PROOFSTEP] exact ⟨nx * ny, Subring.mul_mem _ hnx hny, dx * dy, Subring.mul_mem _ hdx hdy, (div_mul_div_comm _ _ _ _).symm⟩ [GOAL] K : Type u L : Type v M : Type w inst✝² : Field K inst✝¹ : Field L inst✝ : Field M s : Set K a✝ b✝ : K x_mem : a✝ ∈ { toSubsemigroup := { carrier := {z | ∃ x x_1 y x_2, x / y = z}, mul_mem' := (_ : ∀ {a b : K}, a ∈ {z | ∃ x x_1 y x_2, x / y = z} → b ∈ {z | ∃ x x_1 y x_2, x / y = z} → a * b ∈ {z | ∃ x x_1 y x_2, x / y = z}) }, one_mem' := (_ : ∃ x x_1 y x_2, x / y = 1) }.toSubsemigroup.carrier y_mem : b✝ ∈ { toSubsemigroup := { carrier := {z | ∃ x x_1 y x_2, x / y = z}, mul_mem' := (_ : ∀ {a b : K}, a ∈ {z | ∃ x x_1 y x_2, x / y = z} → b ∈ {z | ∃ x x_1 y x_2, x / y = z} → a * b ∈ {z | ∃ x x_1 y x_2, x / y = z}) }, one_mem' := (_ : ∃ x x_1 y x_2, x / y = 1) }.toSubsemigroup.carrier ⊢ a✝ + b✝ ∈ { toSubsemigroup := { carrier := {z | ∃ x x_1 y x_2, x / y = z}, mul_mem' := (_ : ∀ {a b : K}, a ∈ {z | ∃ x x_1 y x_2, x / y = z} → b ∈ {z | ∃ x x_1 y x_2, x / y = z} → a * b ∈ {z | ∃ x x_1 y x_2, x / y = z}) }, one_mem' := (_ : ∃ x x_1 y x_2, x / y = 1) }.toSubsemigroup.carrier [PROOFSTEP] obtain ⟨nx, hnx, dx, hdx, rfl⟩ := id x_mem [GOAL] case intro.intro.intro.intro K : Type u L : Type v M : Type w inst✝² : Field K inst✝¹ : Field L inst✝ : Field M s : Set K b✝ : K y_mem : b✝ ∈ { toSubsemigroup := { carrier := {z | ∃ x x_1 y x_2, x / y = z}, mul_mem' := (_ : ∀ {a b : K}, a ∈ {z | ∃ x x_1 y x_2, x / y = z} → b ∈ {z | ∃ x x_1 y x_2, x / y = z} → a * b ∈ {z | ∃ x x_1 y x_2, x / y = z}) }, one_mem' := (_ : ∃ x x_1 y x_2, x / y = 1) }.toSubsemigroup.carrier nx : K hnx : nx ∈ Subring.closure s dx : K hdx : dx ∈ Subring.closure s x_mem : nx / dx ∈ { toSubsemigroup := { carrier := {z | ∃ x x_1 y x_2, x / y = z}, mul_mem' := (_ : ∀ {a b : K}, a ∈ {z | ∃ x x_1 y x_2, x / y = z} → b ∈ {z | ∃ x x_1 y x_2, x / y = z} → a * b ∈ {z | ∃ x x_1 y x_2, x / y = z}) }, one_mem' := (_ : ∃ x x_1 y x_2, x / y = 1) }.toSubsemigroup.carrier ⊢ nx / dx + b✝ ∈ { toSubsemigroup := { carrier := {z | ∃ x x_1 y x_2, x / y = z}, mul_mem' := (_ : ∀ {a b : K}, a ∈ {z | ∃ x x_1 y x_2, x / y = z} → b ∈ {z | ∃ x x_1 y x_2, x / y = z} → a * b ∈ {z | ∃ x x_1 y x_2, x / y = z}) }, one_mem' := (_ : ∃ x x_1 y x_2, x / y = 1) }.toSubsemigroup.carrier [PROOFSTEP] obtain ⟨ny, hny, dy, hdy, rfl⟩ := id y_mem [GOAL] case intro.intro.intro.intro.intro.intro.intro.intro K : Type u L : Type v M : Type w inst✝² : Field K inst✝¹ : Field L inst✝ : Field M s : Set K nx : K hnx : nx ∈ Subring.closure s dx : K hdx : dx ∈ Subring.closure s x_mem : nx / dx ∈ { toSubsemigroup := { carrier := {z | ∃ x x_1 y x_2, x / y = z}, mul_mem' := (_ : ∀ {a b : K}, a ∈ {z | ∃ x x_1 y x_2, x / y = z} → b ∈ {z | ∃ x x_1 y x_2, x / y = z} → a * b ∈ {z | ∃ x x_1 y x_2, x / y = z}) }, one_mem' := (_ : ∃ x x_1 y x_2, x / y = 1) }.toSubsemigroup.carrier ny : K hny : ny ∈ Subring.closure s dy : K hdy : dy ∈ Subring.closure s y_mem : ny / dy ∈ { toSubsemigroup := { carrier := {z | ∃ x x_1 y x_2, x / y = z}, mul_mem' := (_ : ∀ {a b : K}, a ∈ {z | ∃ x x_1 y x_2, x / y = z} → b ∈ {z | ∃ x x_1 y x_2, x / y = z} → a * b ∈ {z | ∃ x x_1 y x_2, x / y = z}) }, one_mem' := (_ : ∃ x x_1 y x_2, x / y = 1) }.toSubsemigroup.carrier ⊢ nx / dx + ny / dy ∈ { toSubsemigroup := { carrier := {z | ∃ x x_1 y x_2, x / y = z}, mul_mem' := (_ : ∀ {a b : K}, a ∈ {z | ∃ x x_1 y x_2, x / y = z} → b ∈ {z | ∃ x x_1 y x_2, x / y = z} → a * b ∈ {z | ∃ x x_1 y x_2, x / y = z}) }, one_mem' := (_ : ∃ x x_1 y x_2, x / y = 1) }.toSubsemigroup.carrier [PROOFSTEP] by_cases hx0 : dx = 0 [GOAL] case pos K : Type u L : Type v M : Type w inst✝² : Field K inst✝¹ : Field L inst✝ : Field M s : Set K nx : K hnx : nx ∈ Subring.closure s dx : K hdx : dx ∈ Subring.closure s x_mem : nx / dx ∈ { toSubsemigroup := { carrier := {z | ∃ x x_1 y x_2, x / y = z}, mul_mem' := (_ : ∀ {a b : K}, a ∈ {z | ∃ x x_1 y x_2, x / y = z} → b ∈ {z | ∃ x x_1 y x_2, x / y = z} → a * b ∈ {z | ∃ x x_1 y x_2, x / y = z}) }, one_mem' := (_ : ∃ x x_1 y x_2, x / y = 1) }.toSubsemigroup.carrier ny : K hny : ny ∈ Subring.closure s dy : K hdy : dy ∈ Subring.closure s y_mem : ny / dy ∈ { toSubsemigroup := { carrier := {z | ∃ x x_1 y x_2, x / y = z}, mul_mem' := (_ : ∀ {a b : K}, a ∈ {z | ∃ x x_1 y x_2, x / y = z} → b ∈ {z | ∃ x x_1 y x_2, x / y = z} → a * b ∈ {z | ∃ x x_1 y x_2, x / y = z}) }, one_mem' := (_ : ∃ x x_1 y x_2, x / y = 1) }.toSubsemigroup.carrier hx0 : dx = 0 ⊢ nx / dx + ny / dy ∈ { toSubsemigroup := { carrier := {z | ∃ x x_1 y x_2, x / y = z}, mul_mem' := (_ : ∀ {a b : K}, a ∈ {z | ∃ x x_1 y x_2, x / y = z} → b ∈ {z | ∃ x x_1 y x_2, x / y = z} → a * b ∈ {z | ∃ x x_1 y x_2, x / y = z}) }, one_mem' := (_ : ∃ x x_1 y x_2, x / y = 1) }.toSubsemigroup.carrier [PROOFSTEP] rwa [hx0, div_zero, zero_add] [GOAL] case neg K : Type u L : Type v M : Type w inst✝² : Field K inst✝¹ : Field L inst✝ : Field M s : Set K nx : K hnx : nx ∈ Subring.closure s dx : K hdx : dx ∈ Subring.closure s x_mem : nx / dx ∈ { toSubsemigroup := { carrier := {z | ∃ x x_1 y x_2, x / y = z}, mul_mem' := (_ : ∀ {a b : K}, a ∈ {z | ∃ x x_1 y x_2, x / y = z} → b ∈ {z | ∃ x x_1 y x_2, x / y = z} → a * b ∈ {z | ∃ x x_1 y x_2, x / y = z}) }, one_mem' := (_ : ∃ x x_1 y x_2, x / y = 1) }.toSubsemigroup.carrier ny : K hny : ny ∈ Subring.closure s dy : K hdy : dy ∈ Subring.closure s y_mem : ny / dy ∈ { toSubsemigroup := { carrier := {z | ∃ x x_1 y x_2, x / y = z}, mul_mem' := (_ : ∀ {a b : K}, a ∈ {z | ∃ x x_1 y x_2, x / y = z} → b ∈ {z | ∃ x x_1 y x_2, x / y = z} → a * b ∈ {z | ∃ x x_1 y x_2, x / y = z}) }, one_mem' := (_ : ∃ x x_1 y x_2, x / y = 1) }.toSubsemigroup.carrier hx0 : ¬dx = 0 ⊢ nx / dx + ny / dy ∈ { toSubsemigroup := { carrier := {z | ∃ x x_1 y x_2, x / y = z}, mul_mem' := (_ : ∀ {a b : K}, a ∈ {z | ∃ x x_1 y x_2, x / y = z} → b ∈ {z | ∃ x x_1 y x_2, x / y = z} → a * b ∈ {z | ∃ x x_1 y x_2, x / y = z}) }, one_mem' := (_ : ∃ x x_1 y x_2, x / y = 1) }.toSubsemigroup.carrier [PROOFSTEP] by_cases hy0 : dy = 0 [GOAL] case pos K : Type u L : Type v M : Type w inst✝² : Field K inst✝¹ : Field L inst✝ : Field M s : Set K nx : K hnx : nx ∈ Subring.closure s dx : K hdx : dx ∈ Subring.closure s x_mem : nx / dx ∈ { toSubsemigroup := { carrier := {z | ∃ x x_1 y x_2, x / y = z}, mul_mem' := (_ : ∀ {a b : K}, a ∈ {z | ∃ x x_1 y x_2, x / y = z} → b ∈ {z | ∃ x x_1 y x_2, x / y = z} → a * b ∈ {z | ∃ x x_1 y x_2, x / y = z}) }, one_mem' := (_ : ∃ x x_1 y x_2, x / y = 1) }.toSubsemigroup.carrier ny : K hny : ny ∈ Subring.closure s dy : K hdy : dy ∈ Subring.closure s y_mem : ny / dy ∈ { toSubsemigroup := { carrier := {z | ∃ x x_1 y x_2, x / y = z}, mul_mem' := (_ : ∀ {a b : K}, a ∈ {z | ∃ x x_1 y x_2, x / y = z} → b ∈ {z | ∃ x x_1 y x_2, x / y = z} → a * b ∈ {z | ∃ x x_1 y x_2, x / y = z}) }, one_mem' := (_ : ∃ x x_1 y x_2, x / y = 1) }.toSubsemigroup.carrier hx0 : ¬dx = 0 hy0 : dy = 0 ⊢ nx / dx + ny / dy ∈ { toSubsemigroup := { carrier := {z | ∃ x x_1 y x_2, x / y = z}, mul_mem' := (_ : ∀ {a b : K}, a ∈ {z | ∃ x x_1 y x_2, x / y = z} → b ∈ {z | ∃ x x_1 y x_2, x / y = z} → a * b ∈ {z | ∃ x x_1 y x_2, x / y = z}) }, one_mem' := (_ : ∃ x x_1 y x_2, x / y = 1) }.toSubsemigroup.carrier [PROOFSTEP] rwa [hy0, div_zero, add_zero] [GOAL] case neg K : Type u L : Type v M : Type w inst✝² : Field K inst✝¹ : Field L inst✝ : Field M s : Set K nx : K hnx : nx ∈ Subring.closure s dx : K hdx : dx ∈ Subring.closure s x_mem : nx / dx ∈ { toSubsemigroup := { carrier := {z | ∃ x x_1 y x_2, x / y = z}, mul_mem' := (_ : ∀ {a b : K}, a ∈ {z | ∃ x x_1 y x_2, x / y = z} → b ∈ {z | ∃ x x_1 y x_2, x / y = z} → a * b ∈ {z | ∃ x x_1 y x_2, x / y = z}) }, one_mem' := (_ : ∃ x x_1 y x_2, x / y = 1) }.toSubsemigroup.carrier ny : K hny : ny ∈ Subring.closure s dy : K hdy : dy ∈ Subring.closure s y_mem : ny / dy ∈ { toSubsemigroup := { carrier := {z | ∃ x x_1 y x_2, x / y = z}, mul_mem' := (_ : ∀ {a b : K}, a ∈ {z | ∃ x x_1 y x_2, x / y = z} → b ∈ {z | ∃ x x_1 y x_2, x / y = z} → a * b ∈ {z | ∃ x x_1 y x_2, x / y = z}) }, one_mem' := (_ : ∃ x x_1 y x_2, x / y = 1) }.toSubsemigroup.carrier hx0 : ¬dx = 0 hy0 : ¬dy = 0 ⊢ nx / dx + ny / dy ∈ { toSubsemigroup := { carrier := {z | ∃ x x_1 y x_2, x / y = z}, mul_mem' := (_ : ∀ {a b : K}, a ∈ {z | ∃ x x_1 y x_2, x / y = z} → b ∈ {z | ∃ x x_1 y x_2, x / y = z} → a * b ∈ {z | ∃ x x_1 y x_2, x / y = z}) }, one_mem' := (_ : ∃ x x_1 y x_2, x / y = 1) }.toSubsemigroup.carrier [PROOFSTEP] exact ⟨nx * dy + dx * ny, Subring.add_mem _ (Subring.mul_mem _ hnx hdy) (Subring.mul_mem _ hdx hny), dx * dy, Subring.mul_mem _ hdx hdy, (div_add_div nx ny hx0 hy0).symm⟩ [GOAL] K : Type u L : Type v M : Type w inst✝² : Field K inst✝¹ : Field L inst✝ : Field M s : Set K x : K ⊢ x ∈ { toSubmonoid := { toSubsemigroup := { carrier := {z | ∃ x x_1 y x_2, x / y = z}, mul_mem' := (_ : ∀ {a b : K}, a ∈ {z | ∃ x x_1 y x_2, x / y = z} → b ∈ {z | ∃ x x_1 y x_2, x / y = z} → a * b ∈ {z | ∃ x x_1 y x_2, x / y = z}) }, one_mem' := (_ : ∃ x x_1 y x_2, x / y = 1) }, add_mem' := (_ : ∀ {a b : K}, a ∈ { toSubsemigroup := { carrier := {z | ∃ x x_1 y x_2, x / y = z}, mul_mem' := (_ : ∀ {a b : K}, a ∈ {z | ∃ x x_1 y x_2, x / y = z} → b ∈ {z | ∃ x x_1 y x_2, x / y = z} → a * b ∈ {z | ∃ x x_1 y x_2, x / y = z}) }, one_mem' := (_ : ∃ x x_1 y x_2, x / y = 1) }.toSubsemigroup.carrier → b ∈ { toSubsemigroup := { carrier := {z | ∃ x x_1 y x_2, x / y = z}, mul_mem' := (_ : ∀ {a b : K}, a ∈ {z | ∃ x x_1 y x_2, x / y = z} → b ∈ {z | ∃ x x_1 y x_2, x / y = z} → a * b ∈ {z | ∃ x x_1 y x_2, x / y = z}) }, one_mem' := (_ : ∃ x x_1 y x_2, x / y = 1) }.toSubsemigroup.carrier → a + b ∈ { toSubsemigroup := { carrier := {z | ∃ x x_1 y x_2, x / y = z}, mul_mem' := (_ : ∀ {a b : K}, a ∈ {z | ∃ x x_1 y x_2, x / y = z} → b ∈ {z | ∃ x x_1 y x_2, x / y = z} → a * b ∈ {z | ∃ x x_1 y x_2, x / y = z}) }, one_mem' := (_ : ∃ x x_1 y x_2, x / y = 1) }.toSubsemigroup.carrier), zero_mem' := (_ : ∃ x x_1 y x_2, x / y = 0) }.toSubmonoid.toSubsemigroup.carrier → -x ∈ { toSubmonoid := { toSubsemigroup := { carrier := {z | ∃ x x_1 y x_2, x / y = z}, mul_mem' := (_ : ∀ {a b : K}, a ∈ {z | ∃ x x_1 y x_2, x / y = z} → b ∈ {z | ∃ x x_1 y x_2, x / y = z} → a * b ∈ {z | ∃ x x_1 y x_2, x / y = z}) }, one_mem' := (_ : ∃ x x_1 y x_2, x / y = 1) }, add_mem' := (_ : ∀ {a b : K}, a ∈ { toSubsemigroup := { carrier := {z | ∃ x x_1 y x_2, x / y = z}, mul_mem' := (_ : ∀ {a b : K}, a ∈ {z | ∃ x x_1 y x_2, x / y = z} → b ∈ {z | ∃ x x_1 y x_2, x / y = z} → a * b ∈ {z | ∃ x x_1 y x_2, x / y = z}) }, one_mem' := (_ : ∃ x x_1 y x_2, x / y = 1) }.toSubsemigroup.carrier → b ∈ { toSubsemigroup := { carrier := {z | ∃ x x_1 y x_2, x / y = z}, mul_mem' := (_ : ∀ {a b : K}, a ∈ {z | ∃ x x_1 y x_2, x / y = z} → b ∈ {z | ∃ x x_1 y x_2, x / y = z} → a * b ∈ {z | ∃ x x_1 y x_2, x / y = z}) }, one_mem' := (_ : ∃ x x_1 y x_2, x / y = 1) }.toSubsemigroup.carrier → a + b ∈ { toSubsemigroup := { carrier := {z | ∃ x x_1 y x_2, x / y = z}, mul_mem' := (_ : ∀ {a b : K}, a ∈ {z | ∃ x x_1 y x_2, x / y = z} → b ∈ {z | ∃ x x_1 y x_2, x / y = z} → a * b ∈ {z | ∃ x x_1 y x_2, x / y = z}) }, one_mem' := (_ : ∃ x x_1 y x_2, x / y = 1) }.toSubsemigroup.carrier), zero_mem' := (_ : ∃ x x_1 y x_2, x / y = 0) }.toSubmonoid.toSubsemigroup.carrier [PROOFSTEP] rintro ⟨y, hy, z, hz, x_eq⟩ [GOAL] case intro.intro.intro.intro K : Type u L : Type v M : Type w inst✝² : Field K inst✝¹ : Field L inst✝ : Field M s : Set K x y : K hy : y ∈ Subring.closure s z : K hz : z ∈ Subring.closure s x_eq : y / z = x ⊢ -x ∈ { toSubmonoid := { toSubsemigroup := { carrier := {z | ∃ x x_1 y x_2, x / y = z}, mul_mem' := (_ : ∀ {a b : K}, a ∈ {z | ∃ x x_1 y x_2, x / y = z} → b ∈ {z | ∃ x x_1 y x_2, x / y = z} → a * b ∈ {z | ∃ x x_1 y x_2, x / y = z}) }, one_mem' := (_ : ∃ x x_1 y x_2, x / y = 1) }, add_mem' := (_ : ∀ {a b : K}, a ∈ { toSubsemigroup := { carrier := {z | ∃ x x_1 y x_2, x / y = z}, mul_mem' := (_ : ∀ {a b : K}, a ∈ {z | ∃ x x_1 y x_2, x / y = z} → b ∈ {z | ∃ x x_1 y x_2, x / y = z} → a * b ∈ {z | ∃ x x_1 y x_2, x / y = z}) }, one_mem' := (_ : ∃ x x_1 y x_2, x / y = 1) }.toSubsemigroup.carrier → b ∈ { toSubsemigroup := { carrier := {z | ∃ x x_1 y x_2, x / y = z}, mul_mem' := (_ : ∀ {a b : K}, a ∈ {z | ∃ x x_1 y x_2, x / y = z} → b ∈ {z | ∃ x x_1 y x_2, x / y = z} → a * b ∈ {z | ∃ x x_1 y x_2, x / y = z}) }, one_mem' := (_ : ∃ x x_1 y x_2, x / y = 1) }.toSubsemigroup.carrier → a + b ∈ { toSubsemigroup := { carrier := {z | ∃ x x_1 y x_2, x / y = z}, mul_mem' := (_ : ∀ {a b : K}, a ∈ {z | ∃ x x_1 y x_2, x / y = z} → b ∈ {z | ∃ x x_1 y x_2, x / y = z} → a * b ∈ {z | ∃ x x_1 y x_2, x / y = z}) }, one_mem' := (_ : ∃ x x_1 y x_2, x / y = 1) }.toSubsemigroup.carrier), zero_mem' := (_ : ∃ x x_1 y x_2, x / y = 0) }.toSubmonoid.toSubsemigroup.carrier [PROOFSTEP] exact ⟨-y, Subring.neg_mem _ hy, z, hz, x_eq ▸ neg_div _ _⟩ [GOAL] K : Type u L : Type v M : Type w inst✝² : Field K inst✝¹ : Field L inst✝ : Field M s : Set K x : K ⊢ x ∈ { toSubsemiring := { toSubmonoid := { toSubsemigroup := { carrier := {z | ∃ x x_1 y x_2, x / y = z}, mul_mem' := (_ : ∀ {a b : K}, a ∈ {z | ∃ x x_1 y x_2, x / y = z} → b ∈ {z | ∃ x x_1 y x_2, x / y = z} → a * b ∈ {z | ∃ x x_1 y x_2, x / y = z}) }, one_mem' := (_ : ∃ x x_1 y x_2, x / y = 1) }, add_mem' := (_ : ∀ {a b : K}, a ∈ { toSubsemigroup := { carrier := {z | ∃ x x_1 y x_2, x / y = z}, mul_mem' := (_ : ∀ {a b : K}, a ∈ {z | ∃ x x_1 y x_2, x / y = z} → b ∈ {z | ∃ x x_1 y x_2, x / y = z} → a * b ∈ {z | ∃ x x_1 y x_2, x / y = z}) }, one_mem' := (_ : ∃ x x_1 y x_2, x / y = 1) }.toSubsemigroup.carrier → b ∈ { toSubsemigroup := { carrier := {z | ∃ x x_1 y x_2, x / y = z}, mul_mem' := (_ : ∀ {a b : K}, a ∈ {z | ∃ x x_1 y x_2, x / y = z} → b ∈ {z | ∃ x x_1 y x_2, x / y = z} → a * b ∈ {z | ∃ x x_1 y x_2, x / y = z}) }, one_mem' := (_ : ∃ x x_1 y x_2, x / y = 1) }.toSubsemigroup.carrier → a + b ∈ { toSubsemigroup := { carrier := {z | ∃ x x_1 y x_2, x / y = z}, mul_mem' := (_ : ∀ {a b : K}, a ∈ {z | ∃ x x_1 y x_2, x / y = z} → b ∈ {z | ∃ x x_1 y x_2, x / y = z} → a * b ∈ {z | ∃ x x_1 y x_2, x / y = z}) }, one_mem' := (_ : ∃ x x_1 y x_2, x / y = 1) }.toSubsemigroup.carrier), zero_mem' := (_ : ∃ x x_1 y x_2, x / y = 0) }, neg_mem' := (_ : ∀ {x : K}, x ∈ { toSubmonoid := { toSubsemigroup := { carrier := {z | ∃ x x_1 y x_2, x / y = z}, mul_mem' := (_ : ∀ {a b : K}, a ∈ {z | ∃ x x_1 y x_2, x / y = z} → b ∈ {z | ∃ x x_1 y x_2, x / y = z} → a * b ∈ {z | ∃ x x_1 y x_2, x / y = z}) }, one_mem' := (_ : ∃ x x_1 y x_2, x / y = 1) }, add_mem' := (_ : ∀ {a b : K}, a ∈ { toSubsemigroup := { carrier := {z | ∃ x x_1 y x_2, x / y = z}, mul_mem' := (_ : ∀ {a b : K}, a ∈ {z | ∃ x x_1 y x_2, x / y = z} → b ∈ {z | ∃ x x_1 y x_2, x / y = z} → a * b ∈ {z | ∃ x x_1 y x_2, x / y = z}) }, one_mem' := (_ : ∃ x x_1 y x_2, x / y = 1) }.toSubsemigroup.carrier → b ∈ { toSubsemigroup := { carrier := {z | ∃ x x_1 y x_2, x / y = z}, mul_mem' := (_ : ∀ {a b : K}, a ∈ {z | ∃ x x_1 y x_2, x / y = z} → b ∈ {z | ∃ x x_1 y x_2, x / y = z} → a * b ∈ {z | ∃ x x_1 y x_2, x / y = z}) }, one_mem' := (_ : ∃ x x_1 y x_2, x / y = 1) }.toSubsemigroup.carrier → a + b ∈ { toSubsemigroup := { carrier := {z | ∃ x x_1 y x_2, x / y = z}, mul_mem' := (_ : ∀ {a b : K}, a ∈ {z | ∃ x x_1 y x_2, x / y = z} → b ∈ {z | ∃ x x_1 y x_2, x / y = z} → a * b ∈ {z | ∃ x x_1 y x_2, x / y = z}) }, one_mem' := (_ : ∃ x x_1 y x_2, x / y = 1) }.toSubsemigroup.carrier), zero_mem' := (_ : ∃ x x_1 y x_2, x / y = 0) }.toSubmonoid.toSubsemigroup.carrier → -x ∈ { toSubmonoid := { toSubsemigroup := { carrier := {z | ∃ x x_1 y x_2, x / y = z}, mul_mem' := (_ : ∀ {a b : K}, a ∈ {z | ∃ x x_1 y x_2, x / y = z} → b ∈ {z | ∃ x x_1 y x_2, x / y = z} → a * b ∈ {z | ∃ x x_1 y x_2, x / y = z}) }, one_mem' := (_ : ∃ x x_1 y x_2, x / y = 1) }, add_mem' := (_ : ∀ {a b : K}, a ∈ { toSubsemigroup := { carrier := {z | ∃ x x_1 y x_2, x / y = z}, mul_mem' := (_ : ∀ {a b : K}, a ∈ {z | ∃ x x_1 y x_2, x / y = z} → b ∈ {z | ∃ x x_1 y x_2, x / y = z} → a * b ∈ {z | ∃ x x_1 y x_2, x / y = z}) }, one_mem' := (_ : ∃ x x_1 y x_2, x / y = 1) }.toSubsemigroup.carrier → b ∈ { toSubsemigroup := { carrier := {z | ∃ x x_1 y x_2, x / y = z}, mul_mem' := (_ : ∀ {a b : K}, a ∈ {z | ∃ x x_1 y x_2, x / y = z} → b ∈ {z | ∃ x x_1 y x_2, x / y = z} → a * b ∈ {z | ∃ x x_1 y x_2, x / y = z}) }, one_mem' := (_ : ∃ x x_1 y x_2, x / y = 1) }.toSubsemigroup.carrier → a + b ∈ { toSubsemigroup := { carrier := {z | ∃ x x_1 y x_2, x / y = z}, mul_mem' := (_ : ∀ {a b : K}, a ∈ {z | ∃ x x_1 y x_2, x / y = z} → b ∈ {z | ∃ x x_1 y x_2, x / y = z} → a * b ∈ {z | ∃ x x_1 y x_2, x / y = z}) }, one_mem' := (_ : ∃ x x_1 y x_2, x / y = 1) }.toSubsemigroup.carrier), zero_mem' := (_ : ∃ x x_1 y x_2, x / y = 0) }.toSubmonoid.toSubsemigroup.carrier) }.toSubsemiring.toSubmonoid.toSubsemigroup.carrier → x⁻¹ ∈ { toSubsemiring := { toSubmonoid := { toSubsemigroup := { carrier := {z | ∃ x x_1 y x_2, x / y = z}, mul_mem' := (_ : ∀ {a b : K}, a ∈ {z | ∃ x x_1 y x_2, x / y = z} → b ∈ {z | ∃ x x_1 y x_2, x / y = z} → a * b ∈ {z | ∃ x x_1 y x_2, x / y = z}) }, one_mem' := (_ : ∃ x x_1 y x_2, x / y = 1) }, add_mem' := (_ : ∀ {a b : K}, a ∈ { toSubsemigroup := { carrier := {z | ∃ x x_1 y x_2, x / y = z}, mul_mem' := (_ : ∀ {a b : K}, a ∈ {z | ∃ x x_1 y x_2, x / y = z} → b ∈ {z | ∃ x x_1 y x_2, x / y = z} → a * b ∈ {z | ∃ x x_1 y x_2, x / y = z}) }, one_mem' := (_ : ∃ x x_1 y x_2, x / y = 1) }.toSubsemigroup.carrier → b ∈ { toSubsemigroup := { carrier := {z | ∃ x x_1 y x_2, x / y = z}, mul_mem' := (_ : ∀ {a b : K}, a ∈ {z | ∃ x x_1 y x_2, x / y = z} → b ∈ {z | ∃ x x_1 y x_2, x / y = z} → a * b ∈ {z | ∃ x x_1 y x_2, x / y = z}) }, one_mem' := (_ : ∃ x x_1 y x_2, x / y = 1) }.toSubsemigroup.carrier → a + b ∈ { toSubsemigroup := { carrier := {z | ∃ x x_1 y x_2, x / y = z}, mul_mem' := (_ : ∀ {a b : K}, a ∈ {z | ∃ x x_1 y x_2, x / y = z} → b ∈ {z | ∃ x x_1 y x_2, x / y = z} → a * b ∈ {z | ∃ x x_1 y x_2, x / y = z}) }, one_mem' := (_ : ∃ x x_1 y x_2, x / y = 1) }.toSubsemigroup.carrier), zero_mem' := (_ : ∃ x x_1 y x_2, x / y = 0) }, neg_mem' := (_ : ∀ {x : K}, x ∈ { toSubmonoid := { toSubsemigroup := { carrier := {z | ∃ x x_1 y x_2, x / y = z}, mul_mem' := (_ : ∀ {a b : K}, a ∈ {z | ∃ x x_1 y x_2, x / y = z} → b ∈ {z | ∃ x x_1 y x_2, x / y = z} → a * b ∈ {z | ∃ x x_1 y x_2, x / y = z}) }, one_mem' := (_ : ∃ x x_1 y x_2, x / y = 1) }, add_mem' := (_ : ∀ {a b : K}, a ∈ { toSubsemigroup := { carrier := {z | ∃ x x_1 y x_2, x / y = z}, mul_mem' := (_ : ∀ {a b : K}, a ∈ {z | ∃ x x_1 y x_2, x / y = z} → b ∈ {z | ∃ x x_1 y x_2, x / y = z} → a * b ∈ {z | ∃ x x_1 y x_2, x / y = z}) }, one_mem' := (_ : ∃ x x_1 y x_2, x / y = 1) }.toSubsemigroup.carrier → b ∈ { toSubsemigroup := { carrier := {z | ∃ x x_1 y x_2, x / y = z}, mul_mem' := (_ : ∀ {a b : K}, a ∈ {z | ∃ x x_1 y x_2, x / y = z} → b ∈ {z | ∃ x x_1 y x_2, x / y = z} → a * b ∈ {z | ∃ x x_1 y x_2, x / y = z}) }, one_mem' := (_ : ∃ x x_1 y x_2, x / y = 1) }.toSubsemigroup.carrier → a + b ∈ { toSubsemigroup := { carrier := {z | ∃ x x_1 y x_2, x / y = z}, mul_mem' := (_ : ∀ {a b : K}, a ∈ {z | ∃ x x_1 y x_2, x / y = z} → b ∈ {z | ∃ x x_1 y x_2, x / y = z} → a * b ∈ {z | ∃ x x_1 y x_2, x / y = z}) }, one_mem' := (_ : ∃ x x_1 y x_2, x / y = 1) }.toSubsemigroup.carrier), zero_mem' := (_ : ∃ x x_1 y x_2, x / y = 0) }.toSubmonoid.toSubsemigroup.carrier → -x ∈ { toSubmonoid := { toSubsemigroup := { carrier := {z | ∃ x x_1 y x_2, x / y = z}, mul_mem' := (_ : ∀ {a b : K}, a ∈ {z | ∃ x x_1 y x_2, x / y = z} → b ∈ {z | ∃ x x_1 y x_2, x / y = z} → a * b ∈ {z | ∃ x x_1 y x_2, x / y = z}) }, one_mem' := (_ : ∃ x x_1 y x_2, x / y = 1) }, add_mem' := (_ : ∀ {a b : K}, a ∈ { toSubsemigroup := { carrier := {z | ∃ x x_1 y x_2, x / y = z}, mul_mem' := (_ : ∀ {a b : K}, a ∈ {z | ∃ x x_1 y x_2, x / y = z} → b ∈ {z | ∃ x x_1 y x_2, x / y = z} → a * b ∈ {z | ∃ x x_1 y x_2, x / y = z}) }, one_mem' := (_ : ∃ x x_1 y x_2, x / y = 1) }.toSubsemigroup.carrier → b ∈ { toSubsemigroup := { carrier := {z | ∃ x x_1 y x_2, x / y = z}, mul_mem' := (_ : ∀ {a b : K}, a ∈ {z | ∃ x x_1 y x_2, x / y = z} → b ∈ {z | ∃ x x_1 y x_2, x / y = z} → a * b ∈ {z | ∃ x x_1 y x_2, x / y = z}) }, one_mem' := (_ : ∃ x x_1 y x_2, x / y = 1) }.toSubsemigroup.carrier → a + b ∈ { toSubsemigroup := { carrier := {z | ∃ x x_1 y x_2, x / y = z}, mul_mem' := (_ : ∀ {a b : K}, a ∈ {z | ∃ x x_1 y x_2, x / y = z} → b ∈ {z | ∃ x x_1 y x_2, x / y = z} → a * b ∈ {z | ∃ x x_1 y x_2, x / y = z}) }, one_mem' := (_ : ∃ x x_1 y x_2, x / y = 1) }.toSubsemigroup.carrier), zero_mem' := (_ : ∃ x x_1 y x_2, x / y = 0) }.toSubmonoid.toSubsemigroup.carrier) }.toSubsemiring.toSubmonoid.toSubsemigroup.carrier [PROOFSTEP] rintro ⟨y, hy, z, hz, x_eq⟩ [GOAL] case intro.intro.intro.intro K : Type u L : Type v M : Type w inst✝² : Field K inst✝¹ : Field L inst✝ : Field M s : Set K x y : K hy : y ∈ Subring.closure s z : K hz : z ∈ Subring.closure s x_eq : y / z = x ⊢ x⁻¹ ∈ { toSubsemiring := { toSubmonoid := { toSubsemigroup := { carrier := {z | ∃ x x_1 y x_2, x / y = z}, mul_mem' := (_ : ∀ {a b : K}, a ∈ {z | ∃ x x_1 y x_2, x / y = z} → b ∈ {z | ∃ x x_1 y x_2, x / y = z} → a * b ∈ {z | ∃ x x_1 y x_2, x / y = z}) }, one_mem' := (_ : ∃ x x_1 y x_2, x / y = 1) }, add_mem' := (_ : ∀ {a b : K}, a ∈ { toSubsemigroup := { carrier := {z | ∃ x x_1 y x_2, x / y = z}, mul_mem' := (_ : ∀ {a b : K}, a ∈ {z | ∃ x x_1 y x_2, x / y = z} → b ∈ {z | ∃ x x_1 y x_2, x / y = z} → a * b ∈ {z | ∃ x x_1 y x_2, x / y = z}) }, one_mem' := (_ : ∃ x x_1 y x_2, x / y = 1) }.toSubsemigroup.carrier → b ∈ { toSubsemigroup := { carrier := {z | ∃ x x_1 y x_2, x / y = z}, mul_mem' := (_ : ∀ {a b : K}, a ∈ {z | ∃ x x_1 y x_2, x / y = z} → b ∈ {z | ∃ x x_1 y x_2, x / y = z} → a * b ∈ {z | ∃ x x_1 y x_2, x / y = z}) }, one_mem' := (_ : ∃ x x_1 y x_2, x / y = 1) }.toSubsemigroup.carrier → a + b ∈ { toSubsemigroup := { carrier := {z | ∃ x x_1 y x_2, x / y = z}, mul_mem' := (_ : ∀ {a b : K}, a ∈ {z | ∃ x x_1 y x_2, x / y = z} → b ∈ {z | ∃ x x_1 y x_2, x / y = z} → a * b ∈ {z | ∃ x x_1 y x_2, x / y = z}) }, one_mem' := (_ : ∃ x x_1 y x_2, x / y = 1) }.toSubsemigroup.carrier), zero_mem' := (_ : ∃ x x_1 y x_2, x / y = 0) }, neg_mem' := (_ : ∀ {x : K}, x ∈ { toSubmonoid := { toSubsemigroup := { carrier := {z | ∃ x x_1 y x_2, x / y = z}, mul_mem' := (_ : ∀ {a b : K}, a ∈ {z | ∃ x x_1 y x_2, x / y = z} → b ∈ {z | ∃ x x_1 y x_2, x / y = z} → a * b ∈ {z | ∃ x x_1 y x_2, x / y = z}) }, one_mem' := (_ : ∃ x x_1 y x_2, x / y = 1) }, add_mem' := (_ : ∀ {a b : K}, a ∈ { toSubsemigroup := { carrier := {z | ∃ x x_1 y x_2, x / y = z}, mul_mem' := (_ : ∀ {a b : K}, a ∈ {z | ∃ x x_1 y x_2, x / y = z} → b ∈ {z | ∃ x x_1 y x_2, x / y = z} → a * b ∈ {z | ∃ x x_1 y x_2, x / y = z}) }, one_mem' := (_ : ∃ x x_1 y x_2, x / y = 1) }.toSubsemigroup.carrier → b ∈ { toSubsemigroup := { carrier := {z | ∃ x x_1 y x_2, x / y = z}, mul_mem' := (_ : ∀ {a b : K}, a ∈ {z | ∃ x x_1 y x_2, x / y = z} → b ∈ {z | ∃ x x_1 y x_2, x / y = z} → a * b ∈ {z | ∃ x x_1 y x_2, x / y = z}) }, one_mem' := (_ : ∃ x x_1 y x_2, x / y = 1) }.toSubsemigroup.carrier → a + b ∈ { toSubsemigroup := { carrier := {z | ∃ x x_1 y x_2, x / y = z}, mul_mem' := (_ : ∀ {a b : K}, a ∈ {z | ∃ x x_1 y x_2, x / y = z} → b ∈ {z | ∃ x x_1 y x_2, x / y = z} → a * b ∈ {z | ∃ x x_1 y x_2, x / y = z}) }, one_mem' := (_ : ∃ x x_1 y x_2, x / y = 1) }.toSubsemigroup.carrier), zero_mem' := (_ : ∃ x x_1 y x_2, x / y = 0) }.toSubmonoid.toSubsemigroup.carrier → -x ∈ { toSubmonoid := { toSubsemigroup := { carrier := {z | ∃ x x_1 y x_2, x / y = z}, mul_mem' := (_ : ∀ {a b : K}, a ∈ {z | ∃ x x_1 y x_2, x / y = z} → b ∈ {z | ∃ x x_1 y x_2, x / y = z} → a * b ∈ {z | ∃ x x_1 y x_2, x / y = z}) }, one_mem' := (_ : ∃ x x_1 y x_2, x / y = 1) }, add_mem' := (_ : ∀ {a b : K}, a ∈ { toSubsemigroup := { carrier := {z | ∃ x x_1 y x_2, x / y = z}, mul_mem' := (_ : ∀ {a b : K}, a ∈ {z | ∃ x x_1 y x_2, x / y = z} → b ∈ {z | ∃ x x_1 y x_2, x / y = z} → a * b ∈ {z | ∃ x x_1 y x_2, x / y = z}) }, one_mem' := (_ : ∃ x x_1 y x_2, x / y = 1) }.toSubsemigroup.carrier → b ∈ { toSubsemigroup := { carrier := {z | ∃ x x_1 y x_2, x / y = z}, mul_mem' := (_ : ∀ {a b : K}, a ∈ {z | ∃ x x_1 y x_2, x / y = z} → b ∈ {z | ∃ x x_1 y x_2, x / y = z} → a * b ∈ {z | ∃ x x_1 y x_2, x / y = z}) }, one_mem' := (_ : ∃ x x_1 y x_2, x / y = 1) }.toSubsemigroup.carrier → a + b ∈ { toSubsemigroup := { carrier := {z | ∃ x x_1 y x_2, x / y = z}, mul_mem' := (_ : ∀ {a b : K}, a ∈ {z | ∃ x x_1 y x_2, x / y = z} → b ∈ {z | ∃ x x_1 y x_2, x / y = z} → a * b ∈ {z | ∃ x x_1 y x_2, x / y = z}) }, one_mem' := (_ : ∃ x x_1 y x_2, x / y = 1) }.toSubsemigroup.carrier), zero_mem' := (_ : ∃ x x_1 y x_2, x / y = 0) }.toSubmonoid.toSubsemigroup.carrier) }.toSubsemiring.toSubmonoid.toSubsemigroup.carrier [PROOFSTEP] exact ⟨z, hz, y, hy, x_eq ▸ (inv_div _ _).symm⟩ [GOAL] K : Type u L : Type v M : Type w inst✝² : Field K inst✝¹ : Field L inst✝ : Field M s : Set K x : K ⊢ x ∈ closure s ↔ ∃ y, y ∈ Subring.closure s ∧ ∃ z, z ∈ Subring.closure s ∧ y / z = x [PROOFSTEP] change x ∈ (closure s).carrier ↔ ∃ y ∈ Subring.closure s, ∃ z ∈ Subring.closure s, y / z = x [GOAL] K : Type u L : Type v M : Type w inst✝² : Field K inst✝¹ : Field L inst✝ : Field M s : Set K x : K ⊢ x ∈ (closure s).toSubring.toSubsemiring.toSubmonoid.toSubsemigroup.carrier ↔ ∃ y, y ∈ Subring.closure s ∧ ∃ z, z ∈ Subring.closure s ∧ y / z = x [PROOFSTEP] simp only [closure, exists_prop, Set.mem_setOf_eq] [GOAL] K : Type u L : Type v M : Type w inst✝² : Field K inst✝¹ : Field L inst✝ : Field M s : Set K p : K → Prop x : K h : x ∈ closure s Hs : ∀ (x : K), x ∈ s → p x H1 : p 1 Hadd : ∀ (x y : K), p x → p y → p (x + y) Hneg : ∀ (x : K), p x → p (-x) Hinv : ∀ (x : K), p x → p x⁻¹ Hmul : ∀ (x y : K), p x → p y → p (x * y) ⊢ p x [PROOFSTEP] letI : Subfield K := ⟨⟨⟨⟨⟨p, by intro _ _; exact Hmul _ _⟩, H1⟩, by intro _ _; exact Hadd _ _, @add_neg_self K _ 1 ▸ Hadd _ _ H1 (Hneg _ H1)⟩, by intro _; exact Hneg _⟩, Hinv⟩ [GOAL] K : Type u L : Type v M : Type w inst✝² : Field K inst✝¹ : Field L inst✝ : Field M s : Set K p : K → Prop x : K h : x ∈ closure s Hs : ∀ (x : K), x ∈ s → p x H1 : p 1 Hadd : ∀ (x y : K), p x → p y → p (x + y) Hneg : ∀ (x : K), p x → p (-x) Hinv : ∀ (x : K), p x → p x⁻¹ Hmul : ∀ (x y : K), p x → p y → p (x * y) ⊢ ∀ {a b : K}, a ∈ p → b ∈ p → a * b ∈ p [PROOFSTEP] intro _ _ [GOAL] K : Type u L : Type v M : Type w inst✝² : Field K inst✝¹ : Field L inst✝ : Field M s : Set K p : K → Prop x : K h : x ∈ closure s Hs : ∀ (x : K), x ∈ s → p x H1 : p 1 Hadd : ∀ (x y : K), p x → p y → p (x + y) Hneg : ∀ (x : K), p x → p (-x) Hinv : ∀ (x : K), p x → p x⁻¹ Hmul : ∀ (x y : K), p x → p y → p (x * y) a✝ b✝ : K ⊢ a✝ ∈ p → b✝ ∈ p → a✝ * b✝ ∈ p [PROOFSTEP] exact Hmul _ _ [GOAL] K : Type u L : Type v M : Type w inst✝² : Field K inst✝¹ : Field L inst✝ : Field M s : Set K p : K → Prop x : K h : x ∈ closure s Hs : ∀ (x : K), x ∈ s → p x H1 : p 1 Hadd : ∀ (x y : K), p x → p y → p (x + y) Hneg : ∀ (x : K), p x → p (-x) Hinv : ∀ (x : K), p x → p x⁻¹ Hmul : ∀ (x y : K), p x → p y → p (x * y) ⊢ ∀ {a b : K}, a ∈ { toSubsemigroup := { carrier := p, mul_mem' := (_ : ∀ {a b : K}, p a → p b → p (a * b)) }, one_mem' := H1 }.toSubsemigroup.carrier → b ∈ { toSubsemigroup := { carrier := p, mul_mem' := (_ : ∀ {a b : K}, p a → p b → p (a * b)) }, one_mem' := H1 }.toSubsemigroup.carrier → a + b ∈ { toSubsemigroup := { carrier := p, mul_mem' := (_ : ∀ {a b : K}, p a → p b → p (a * b)) }, one_mem' := H1 }.toSubsemigroup.carrier [PROOFSTEP] intro _ _ [GOAL] K : Type u L : Type v M : Type w inst✝² : Field K inst✝¹ : Field L inst✝ : Field M s : Set K p : K → Prop x : K h : x ∈ closure s Hs : ∀ (x : K), x ∈ s → p x H1 : p 1 Hadd : ∀ (x y : K), p x → p y → p (x + y) Hneg : ∀ (x : K), p x → p (-x) Hinv : ∀ (x : K), p x → p x⁻¹ Hmul : ∀ (x y : K), p x → p y → p (x * y) a✝ b✝ : K ⊢ a✝ ∈ { toSubsemigroup := { carrier := p, mul_mem' := (_ : ∀ {a b : K}, p a → p b → p (a * b)) }, one_mem' := H1 }.toSubsemigroup.carrier → b✝ ∈ { toSubsemigroup := { carrier := p, mul_mem' := (_ : ∀ {a b : K}, p a → p b → p (a * b)) }, one_mem' := H1 }.toSubsemigroup.carrier → a✝ + b✝ ∈ { toSubsemigroup := { carrier := p, mul_mem' := (_ : ∀ {a b : K}, p a → p b → p (a * b)) }, one_mem' := H1 }.toSubsemigroup.carrier [PROOFSTEP] exact Hadd _ _ [GOAL] K : Type u L : Type v M : Type w inst✝² : Field K inst✝¹ : Field L inst✝ : Field M s : Set K p : K → Prop x : K h : x ∈ closure s Hs : ∀ (x : K), x ∈ s → p x H1 : p 1 Hadd : ∀ (x y : K), p x → p y → p (x + y) Hneg : ∀ (x : K), p x → p (-x) Hinv : ∀ (x : K), p x → p x⁻¹ Hmul : ∀ (x y : K), p x → p y → p (x * y) ⊢ ∀ {x : K}, x ∈ { toSubmonoid := { toSubsemigroup := { carrier := p, mul_mem' := (_ : ∀ {a b : K}, p a → p b → p (a * b)) }, one_mem' := H1 }, add_mem' := (_ : ∀ {a b : K}, p a → p b → p (a + b)), zero_mem' := (_ : p 0) }.toSubmonoid.toSubsemigroup.carrier → -x ∈ { toSubmonoid := { toSubsemigroup := { carrier := p, mul_mem' := (_ : ∀ {a b : K}, p a → p b → p (a * b)) }, one_mem' := H1 }, add_mem' := (_ : ∀ {a b : K}, p a → p b → p (a + b)), zero_mem' := (_ : p 0) }.toSubmonoid.toSubsemigroup.carrier [PROOFSTEP] intro _ [GOAL] K : Type u L : Type v M : Type w inst✝² : Field K inst✝¹ : Field L inst✝ : Field M s : Set K p : K → Prop x : K h : x ∈ closure s Hs : ∀ (x : K), x ∈ s → p x H1 : p 1 Hadd : ∀ (x y : K), p x → p y → p (x + y) Hneg : ∀ (x : K), p x → p (-x) Hinv : ∀ (x : K), p x → p x⁻¹ Hmul : ∀ (x y : K), p x → p y → p (x * y) x✝ : K ⊢ x✝ ∈ { toSubmonoid := { toSubsemigroup := { carrier := p, mul_mem' := (_ : ∀ {a b : K}, p a → p b → p (a * b)) }, one_mem' := H1 }, add_mem' := (_ : ∀ {a b : K}, p a → p b → p (a + b)), zero_mem' := (_ : p 0) }.toSubmonoid.toSubsemigroup.carrier → -x✝ ∈ { toSubmonoid := { toSubsemigroup := { carrier := p, mul_mem' := (_ : ∀ {a b : K}, p a → p b → p (a * b)) }, one_mem' := H1 }, add_mem' := (_ : ∀ {a b : K}, p a → p b → p (a + b)), zero_mem' := (_ : p 0) }.toSubmonoid.toSubsemigroup.carrier [PROOFSTEP] exact Hneg _ [GOAL] K : Type u L : Type v M : Type w inst✝² : Field K inst✝¹ : Field L inst✝ : Field M s : Set K p : K → Prop x : K h : x ∈ closure s Hs : ∀ (x : K), x ∈ s → p x H1 : p 1 Hadd : ∀ (x y : K), p x → p y → p (x + y) Hneg : ∀ (x : K), p x → p (-x) Hinv : ∀ (x : K), p x → p x⁻¹ Hmul : ∀ (x y : K), p x → p y → p (x * y) this : Subfield K := { toSubring := { toSubsemiring := { toSubmonoid := { toSubsemigroup := { carrier := p, mul_mem' := (_ : ∀ {a b : K}, p a → p b → p (a * b)) }, one_mem' := H1 }, add_mem' := (_ : ∀ {a b : K}, p a → p b → p (a + b)), zero_mem' := (_ : p 0) }, neg_mem' := (_ : ∀ {x : K}, p x → p (-x)) }, inv_mem' := Hinv } ⊢ p x [PROOFSTEP] exact (closure_le (t := this)).2 Hs h [GOAL] K : Type u L : Type v M : Type w inst✝² : Field K inst✝¹ : Field L inst✝ : Field M ι : Sort u_1 hι : Nonempty ι S : ι → Subfield K hS : Directed (fun x x_1 => x ≤ x_1) S x : K ⊢ x ∈ ⨆ (i : ι), S i ↔ ∃ i, x ∈ S i [PROOFSTEP] refine' ⟨_, fun ⟨i, hi⟩ => (SetLike.le_def.1 <| le_iSup S i) hi⟩ [GOAL] K : Type u L : Type v M : Type w inst✝² : Field K inst✝¹ : Field L inst✝ : Field M ι : Sort u_1 hι : Nonempty ι S : ι → Subfield K hS : Directed (fun x x_1 => x ≤ x_1) S x : K ⊢ x ∈ ⨆ (i : ι), S i → ∃ i, x ∈ S i [PROOFSTEP] suffices x ∈ closure (⋃ i, (S i : Set K)) → ∃ i, x ∈ S i by simpa only [closure_iUnion, closure_eq] [GOAL] K : Type u L : Type v M : Type w inst✝² : Field K inst✝¹ : Field L inst✝ : Field M ι : Sort u_1 hι : Nonempty ι S : ι → Subfield K hS : Directed (fun x x_1 => x ≤ x_1) S x : K this : x ∈ closure (⋃ (i : ι), ↑(S i)) → ∃ i, x ∈ S i ⊢ x ∈ ⨆ (i : ι), S i → ∃ i, x ∈ S i [PROOFSTEP] simpa only [closure_iUnion, closure_eq] [GOAL] K : Type u L : Type v M : Type w inst✝² : Field K inst✝¹ : Field L inst✝ : Field M ι : Sort u_1 hι : Nonempty ι S : ι → Subfield K hS : Directed (fun x x_1 => x ≤ x_1) S x : K ⊢ x ∈ closure (⋃ (i : ι), ↑(S i)) → ∃ i, x ∈ S i [PROOFSTEP] refine' fun hx => closure_induction hx (fun x => Set.mem_iUnion.mp) _ _ _ _ _ [GOAL] case refine'_1 K : Type u L : Type v M : Type w inst✝² : Field K inst✝¹ : Field L inst✝ : Field M ι : Sort u_1 hι : Nonempty ι S : ι → Subfield K hS : Directed (fun x x_1 => x ≤ x_1) S x : K hx : x ∈ closure (⋃ (i : ι), ↑(S i)) ⊢ ∃ i, 1 ∈ S i [PROOFSTEP] exact hι.elim fun i => ⟨i, (S i).one_mem⟩ [GOAL] case refine'_2 K : Type u L : Type v M : Type w inst✝² : Field K inst✝¹ : Field L inst✝ : Field M ι : Sort u_1 hι : Nonempty ι S : ι → Subfield K hS : Directed (fun x x_1 => x ≤ x_1) S x : K hx : x ∈ closure (⋃ (i : ι), ↑(S i)) ⊢ ∀ (x y : K), (∃ i, x ∈ S i) → (∃ i, y ∈ S i) → ∃ i, x + y ∈ S i [PROOFSTEP] rintro x y ⟨i, hi⟩ ⟨j, hj⟩ [GOAL] case refine'_2.intro.intro K : Type u L : Type v M : Type w inst✝² : Field K inst✝¹ : Field L inst✝ : Field M ι : Sort u_1 hι : Nonempty ι S : ι → Subfield K hS : Directed (fun x x_1 => x ≤ x_1) S x✝ : K hx : x✝ ∈ closure (⋃ (i : ι), ↑(S i)) x y : K i : ι hi : x ∈ S i j : ι hj : y ∈ S j ⊢ ∃ i, x + y ∈ S i [PROOFSTEP] obtain ⟨k, hki, hkj⟩ := hS i j [GOAL] case refine'_2.intro.intro.intro.intro K : Type u L : Type v M : Type w inst✝² : Field K inst✝¹ : Field L inst✝ : Field M ι : Sort u_1 hι : Nonempty ι S : ι → Subfield K hS : Directed (fun x x_1 => x ≤ x_1) S x✝ : K hx : x✝ ∈ closure (⋃ (i : ι), ↑(S i)) x y : K i : ι hi : x ∈ S i j : ι hj : y ∈ S j k : ι hki : S i ≤ S k hkj : S j ≤ S k ⊢ ∃ i, x + y ∈ S i [PROOFSTEP] exact ⟨k, (S k).add_mem (hki hi) (hkj hj)⟩ [GOAL] case refine'_3 K : Type u L : Type v M : Type w inst✝² : Field K inst✝¹ : Field L inst✝ : Field M ι : Sort u_1 hι : Nonempty ι S : ι → Subfield K hS : Directed (fun x x_1 => x ≤ x_1) S x : K hx : x ∈ closure (⋃ (i : ι), ↑(S i)) ⊢ ∀ (x : K), (∃ i, x ∈ S i) → ∃ i, -x ∈ S i [PROOFSTEP] rintro x ⟨i, hi⟩ [GOAL] case refine'_3.intro K : Type u L : Type v M : Type w inst✝² : Field K inst✝¹ : Field L inst✝ : Field M ι : Sort u_1 hι : Nonempty ι S : ι → Subfield K hS : Directed (fun x x_1 => x ≤ x_1) S x✝ : K hx : x✝ ∈ closure (⋃ (i : ι), ↑(S i)) x : K i : ι hi : x ∈ S i ⊢ ∃ i, -x ∈ S i [PROOFSTEP] exact ⟨i, (S i).neg_mem hi⟩ [GOAL] case refine'_4 K : Type u L : Type v M : Type w inst✝² : Field K inst✝¹ : Field L inst✝ : Field M ι : Sort u_1 hι : Nonempty ι S : ι → Subfield K hS : Directed (fun x x_1 => x ≤ x_1) S x : K hx : x ∈ closure (⋃ (i : ι), ↑(S i)) ⊢ ∀ (x : K), (∃ i, x ∈ S i) → ∃ i, x⁻¹ ∈ S i [PROOFSTEP] rintro x ⟨i, hi⟩ [GOAL] case refine'_4.intro K : Type u L : Type v M : Type w inst✝² : Field K inst✝¹ : Field L inst✝ : Field M ι : Sort u_1 hι : Nonempty ι S : ι → Subfield K hS : Directed (fun x x_1 => x ≤ x_1) S x✝ : K hx : x✝ ∈ closure (⋃ (i : ι), ↑(S i)) x : K i : ι hi : x ∈ S i ⊢ ∃ i, x⁻¹ ∈ S i [PROOFSTEP] exact ⟨i, (S i).inv_mem hi⟩ [GOAL] case refine'_5 K : Type u L : Type v M : Type w inst✝² : Field K inst✝¹ : Field L inst✝ : Field M ι : Sort u_1 hι : Nonempty ι S : ι → Subfield K hS : Directed (fun x x_1 => x ≤ x_1) S x : K hx : x ∈ closure (⋃ (i : ι), ↑(S i)) ⊢ ∀ (x y : K), (∃ i, x ∈ S i) → (∃ i, y ∈ S i) → ∃ i, x * y ∈ S i [PROOFSTEP] rintro x y ⟨i, hi⟩ ⟨j, hj⟩ [GOAL] case refine'_5.intro.intro K : Type u L : Type v M : Type w inst✝² : Field K inst✝¹ : Field L inst✝ : Field M ι : Sort u_1 hι : Nonempty ι S : ι → Subfield K hS : Directed (fun x x_1 => x ≤ x_1) S x✝ : K hx : x✝ ∈ closure (⋃ (i : ι), ↑(S i)) x y : K i : ι hi : x ∈ S i j : ι hj : y ∈ S j ⊢ ∃ i, x * y ∈ S i [PROOFSTEP] obtain ⟨k, hki, hkj⟩ := hS i j [GOAL] case refine'_5.intro.intro.intro.intro K : Type u L : Type v M : Type w inst✝² : Field K inst✝¹ : Field L inst✝ : Field M ι : Sort u_1 hι : Nonempty ι S : ι → Subfield K hS : Directed (fun x x_1 => x ≤ x_1) S x✝ : K hx : x✝ ∈ closure (⋃ (i : ι), ↑(S i)) x y : K i : ι hi : x ∈ S i j : ι hj : y ∈ S j k : ι hki : S i ≤ S k hkj : S j ≤ S k ⊢ ∃ i, x * y ∈ S i [PROOFSTEP] exact ⟨k, (S k).mul_mem (hki hi) (hkj hj)⟩ [GOAL] K : Type u L : Type v M : Type w inst✝² : Field K inst✝¹ : Field L inst✝ : Field M ι : Sort u_1 hι : Nonempty ι S : ι → Subfield K hS : Directed (fun x x_1 => x ≤ x_1) S x : K ⊢ x ∈ ↑(⨆ (i : ι), S i) ↔ x ∈ ⋃ (i : ι), ↑(S i) [PROOFSTEP] simp [mem_iSup_of_directed hS] [GOAL] K : Type u L : Type v M : Type w inst✝² : Field K inst✝¹ : Field L inst✝ : Field M S : Set (Subfield K) Sne : Set.Nonempty S hS : DirectedOn (fun x x_1 => x ≤ x_1) S x : K ⊢ x ∈ sSup S ↔ ∃ s, s ∈ S ∧ x ∈ s [PROOFSTEP] haveI : Nonempty S := Sne.to_subtype [GOAL] K : Type u L : Type v M : Type w inst✝² : Field K inst✝¹ : Field L inst✝ : Field M S : Set (Subfield K) Sne : Set.Nonempty S hS : DirectedOn (fun x x_1 => x ≤ x_1) S x : K this : Nonempty ↑S ⊢ x ∈ sSup S ↔ ∃ s, s ∈ S ∧ x ∈ s [PROOFSTEP] simp only [sSup_eq_iSup', mem_iSup_of_directed hS.directed_val, Subtype.exists, exists_prop] [GOAL] K : Type u L : Type v M : Type w inst✝² : Field K inst✝¹ : Field L inst✝ : Field M S : Set (Subfield K) Sne : Set.Nonempty S hS : DirectedOn (fun x x_1 => x ≤ x_1) S x : K ⊢ x ∈ ↑(sSup S) ↔ x ∈ ⋃ (s : Subfield K) (_ : s ∈ S), ↑s [PROOFSTEP] simp [mem_sSup_of_directedOn Sne hS] [GOAL] K : Type u L : Type v M : Type w inst✝² : Field K inst✝¹ : Field L inst✝ : Field M s : Subfield K f g : K →+* L src✝ : Subring K := eqLocus f g x : K hx : ↑f x = ↑g x ⊢ ↑f x⁻¹ = ↑g x⁻¹ [PROOFSTEP] rw [map_inv₀ f, map_inv₀ g, hx]
% PQ_SIZE returns the number of elements in the priority queue % % SYNTAX % sz = pq_size(pq) % % INPUT PARAMETERS % pq: a pointer to the priority queue % % OUTPUT PARAMETERS % sz: the number of elements in the priority queue % % DESCRIPTION % Queries the priority queue for the number of elements that it contains. % This number is not the "capacity" or the maximum number of elements which % is possible to insert but rather the number of elements CURRENTLY in the % priority queue % % See also: % PQ_DEMO, PQ_CREATE, PQ_PUSH, PQ_POP, PQ_SIZE, PQ_TOP, PQ_DELETE % % References: % Gormen, T.H. and Leiserson, C.E. and Rivest, R.L., "introduction to % algorithms", 1990, MIT Press/McGraw-Hill, Chapter 6. % Copyright (c) 2008 Andrea Tagliasacchi % All Rights Reserved % email: [email protected] % $Revision: 1.0$ Created on: May 22, 2009
(* Adapted from Compcert 1.9 *) Require Import Coqlib. Require Intv. Require Import AST. Require Import Integers. Require Import Floats. Require Import Values. Require Import Memory. (* Vellvm does not have a global env component. We will provide a mapping from atom to blk.of explicitly. We use atom instead of ident. *) (*Require Import Globalenvs.*) Require Import Metatheory. Require Import alist. Require Import genericvalues. Require Import targetdata. Require Import syntax. Require Import memory_sim. Require Import genericvalues_inject. Require Import vellvm_tactics. Export LLVMgv. Set Implicit Arguments. Module Genv. Section GENV. Variable GV: Type. Record t : Type := mkgenv { genv_vars: list (atom * GV); genv_find_symbol: atom -> option block; genv_find_var_info: block -> option GV; genv_vars_inj: forall id1 id2 b, genv_find_symbol id1 = Some b -> genv_find_symbol id2 = Some b -> id1 = id2 }. Definition find_symbol (ge:t) (id:atom) : option block := ge.(genv_find_symbol) id. Definition find_var_info (ge:t) (b:block) : option GV := ge.(genv_find_var_info) b. End GENV. End Genv. Unset Implicit Arguments. Inductive eventval: Type := | EVint: forall (wz:nat), Int.int wz -> eventval | EVfloat: float -> eventval | EVsingle: float32 -> eventval | EVptr_global: atom -> int32 -> eventval. Definition eventgv := list eventval. Inductive event: Type := | Event_syscall: atom -> list eventgv -> option eventgv -> event . Definition trace := list event. Definition E0 : trace := nil. Definition Eapp (t1 t2: trace) : trace := t1 ++ t2. CoInductive traceinf : Type := | Econsinf: event -> traceinf -> traceinf. Fixpoint Eappinf (t: trace) (T: traceinf) {struct t} : traceinf := match t with | nil => T | ev :: t' => Econsinf ev (Eappinf t' T) end. Lemma E0_left: forall t, Eapp E0 t = t. Proof. auto. Qed. Lemma E0_right: forall t, Eapp t E0 = t. Proof. intros. unfold E0, Eapp. rewrite <- app_nil_end. auto. Qed. Lemma Eapp_assoc: forall t1 t2 t3, Eapp (Eapp t1 t2) t3 = Eapp t1 (Eapp t2 t3). Proof. intros. unfold Eapp, trace. apply app_ass. Qed. Lemma Eappinf_assoc: forall t1 t2 T, Eappinf (Eapp t1 t2) T = Eappinf t1 (Eappinf t2 T). Proof. induction t1; intros; simpl. auto. decEq; auto. Qed. Lemma E0_left_inf: forall T, Eappinf E0 T = T. Proof. auto. Qed. Infix "**" := Eapp (at level 60, right associativity). Infix "***" := Eappinf (at level 60, right associativity). Set Implicit Arguments. Section EVENTVAL. Variable GV: Type. Variable ge: Genv.t GV. Inductive eventval_match: eventval -> typ -> val -> Prop := | ev_match_int: forall wz i, eventval_match (EVint wz i) Tint (Vint wz i) | ev_match_float: forall f, eventval_match (EVfloat f) Tfloat (Vfloat f) | ev_match_single: forall f, eventval_match (EVsingle f) Tsingle (Vsingle f) | ev_match_ptr: forall id b ofs, Genv.find_symbol ge id = Some b -> eventval_match (EVptr_global id ofs) Tint (Vptr b ofs). (** Compatibility with memory injections *) Variable f: block -> option (block * Z). Definition meminj_preserves_globals : Prop := (forall id b, Genv.find_symbol ge id = Some b -> f b = Some(b, 0)) /\ (forall b gv, Genv.find_var_info ge b = Some gv -> f b = Some(b, 0)) /\ (forall b1 b2 delta gv, Genv.find_var_info ge b2 = Some gv -> f b1 = Some(b2, delta) -> b2 = b1). Hypothesis glob_pres: meminj_preserves_globals. (** Validity *) End EVENTVAL. Definition eventgv_match (TD:LLVMtd.TargetData) (ge: Genv.t GenericValue) (egv: eventgv) (t:LLVMsyntax.typ) (gv:GenericValue) : Prop := match flatten_typ TD t with | Some ms => Forall3 (fun ev m g => let '(v, m0) := g in eventval_match ge ev (AST.type_of_chunk m) v /\ m = m0) egv ms gv | None => False end. Definition eventgv_list_match (TD:LLVMtd.TargetData) (ge: Genv.t GenericValue) (egvs: list eventgv) (ts:list LLVMsyntax.typ) (gvs: list GenericValue) : Prop := Forall3 (eventgv_match TD ge) egvs ts gvs.
(* Jakub Pierewoj 1575643 solved all non-stretch exercises *) (** * Maps: Total and Partial Maps *) (** _A lot of text needs written here_... *) (** Maps (aka dictionaries) are ubiquitous data structures in software construction in general and, in particular, in the theory of programming languages. We're going to need them in many places in the coming chapters. They also make a nice case study using several of the ideas we've seen in previous chapters, including building data structures out of higher-order functions (from [Basics] and [Poly]) and the use of reflection in proofs (from [IndProp]). We'll define two flavors of maps: _total_ maps, which include a "default" element to be returned when a key being looked up doesn't exist in the map, and _partial_ maps, which return an [option]. The latter is defined in terms of the former (using [None] as the default element). *) (* ###################################################################### *) (** * Coq's Standard Library *) (** One small digression before we start. Unlike the chapters we have seen so far, this one is not going to [Import] the chapter before it (and, transitively, all the earlier chapters). Instead, in this chapter and from now, on we're going to import the definitions and theorems we need directly from Coq's standard library stuff. You should not notice much difference, though, because we've been careful to name our own definitions and theorems consistently with their counterparts in the standard library. *) Require Import Coq.Arith.Arith. Require Import Coq.Bool.Bool. Require Import Coq.Logic.FunctionalExtensionality. (** Documentation for the standard library can be found at http://coq.inria.fr/library/. *) (** What's the best way to search for things in the library? *) (* ###################################################################### *) (** * Identifiers *) (** First, we need a type of keys for our maps. We repeat the definition of [id]s from the [Lists] chapter, plus the equality comparison function for [id]s and its fundamental property: *) Inductive id : Type := | Id : nat -> id. Definition beq_id id1 id2 := match id1,id2 with | Id n1, Id n2 => beq_nat n1 n2 end. Theorem beq_id_refl : forall id, true = beq_id id id. Proof. intros [n]. simpl. rewrite <- beq_nat_refl. reflexivity. Qed. (** The following useful property of [beq_id] follows from a similar lemma about numbers: *) Theorem beq_id_true_iff : forall id1 id2 : id, beq_id id1 id2 = true <-> id1 = id2. Proof. intros [n1] [n2]. unfold beq_id. rewrite beq_nat_true_iff. split. - (* -> *) intros H. rewrite H. reflexivity. - (* <- *) intros H. inversion H. reflexivity. Qed. (** (Note that [beq_nat_true_iff] was not proved above; it can be found in the standard library.) *) (** Similarly: *) Theorem beq_id_false_iff : forall x y : id, beq_id x y = false <-> x <> y. Proof. intros x y. rewrite <- beq_id_true_iff. rewrite not_true_iff_false. reflexivity. Qed. (** Now this useful variant follows just by rewriting: *) Theorem false_beq_id : forall x y : id, x <> y -> beq_id x y = false. Proof. intros x y. rewrite beq_id_false_iff. intros H. apply H. Qed. (* ###################################################################### *) (** * Total Maps *) (** Our main job in this chapter is to build a definition of partial maps that is similar in behavior to the one we saw in the [Poly] chapter, plus accompanying lemmas about their behavior. This time around, though, we're going to use _functions_ rather than lists of key-value pairs to build maps. The advantage of this representation is that it offers a more _extensional_ view of maps, where two maps that respond to queries in the same way will be represented as literally the same thing (the same function), rather than just "equivalent" data structures. This, in turn, simplifies proofs that use maps. We build partial maps in two steps. First, we define a type of _total maps_ that return a default value when we look up a key that is not present in the map. *) Definition total_map (A:Type) := id -> A. (** Intuitively, a total map over an element type [A] _is_ just a function that can be used to look up [id]s, yielding [A]s. The function [t_empty] yields an empty total map, given a default element, which always returns the default element when applied to any id. *) Definition t_empty {A:Type} (v : A) : total_map A := (fun _ => v). (** More interesting is the [update] function, which (as before) takes a map [m], a key [x], and a value [v] and returns a new map that takes [x] to [v] and takes every other key to whatever [m] does. *) Definition t_update {A:Type} (m : total_map A) (x : id) (v : A) := fun x' => if beq_id x x' then v else m x'. (** This definition is a nice example of higher-order programming. The [t_update] function takes a _function_ [m] and yields a new function [fun x' => ...] that behaves like the desired map. For example, we can build a map taking [id]s to [bool]s, where [Id 3] is mapped to [true] and every other key is mapped to [false], like this: *) Definition examplemap := t_update (t_update (t_empty false) (Id 1) false) (Id 3) true. (** This completes the definition of total maps. Note that we don't need to define a [find] operation because it is just function application! *) Example update_example1 : examplemap (Id 0) = false. Proof. reflexivity. Qed. Example update_example2 : examplemap (Id 1) = false. Proof. reflexivity. Qed. Example update_example3 : examplemap (Id 2) = false. Proof. reflexivity. Qed. Example update_example4 : examplemap (Id 3) = true. Proof. reflexivity. Qed. (** To reason about maps in later chapters, we need to establish several fundamental facts about how they behave. (Even if you don't work the following exercises, make sure you thoroughly understand the statements of the lemmas!) Some of the proofs will require the functional extensionality axiom discussed in the [Logic] chapter. *) (** **** Exercise: 2 stars, optional (t_update_eq) *) (** First, if we update a map [m] at a key [x] with a new value [v] and then look up [x] in the map resulting from the [update], we get back [v]: *) Lemma t_update_eq : forall A (m: total_map A) x v, (t_update m x v) x = v. Proof. (* FILL IN HERE *) Admitted. (** [] *) (** **** Exercise: 2 stars, optional (t_update_neq) *) (** On the other hand, if we update a map [m] at a key [x1] and then look up a _different_ key [x2] in the resulting map, we get the same result that [m] would have given: *) Theorem t_update_neq : forall (X:Type) v x1 x2 (m : total_map X), x1 <> x2 -> (t_update m x1 v) x2 = m x2. Proof. (* FILL IN HERE *) Admitted. (** [] *) (** **** Exercise: 2 stars, optional (t_update_shadow) *) (** If we update a map [m] at a key [x1] with a value [v1] and then update again with the same key [x1] and another value [x2], then the resulting map behaves the same (i.e., it gives the same result whwn applied to any key [x2]) as the simpler map obtained by performing just the second [update] on [m]: *) (* !!! *) Lemma t_update_shadow : forall A (m: total_map A) v1 v2 x, t_update (t_update m x v1) x v2 = t_update m x v2. Proof. intros. simpl. apply functional_extensionality. intros. unfold t_update. destruct (beq_id x x0). - reflexivity. - reflexivity. Qed. (** [] *) (** For the final two lemmas about total maps, it is convenient to use the reflection idioms that we introduced in chapter [IndProp]. We begin by proving a fundamental _reflection lemma_ relating the equality proposition on [id]s with the boolean function [beq_id]. *) (** **** Exercise: 2 stars (beq_idP) *) (** Use the proof of [beq_natP] in chapter [IndProp] as a template to prove the following: *) Lemma beq_idP : forall x y, reflect (x = y) (beq_id x y). Proof. (* FILL IN HERE *) Admitted. (** [] *) (** Now, given [id]s [x1] and [x2], we can use the [destruct (beq_idP x1 x2)] to simultaneously perform case analysis on the result of [beq_id x1 x2] and generate hypotheses about the equality (in the sense of [=]) of [x1] and [x2]. *) (** **** Exercise: 2 stars (t_update_same) *) (** Using the example in chapter [IndProp] as a template, use [beq_idP] to prove the following theorem, which states that if we update a map to assign key [x] the same value as it already has in [m], then the result is equal to [m]: *) Theorem t_update_same : forall X x (m : total_map X), t_update m x (m x) = m. Proof. (* FILL IN HERE *) Admitted. (** [] *) (** **** Exercise: 3 stars, recommended (t_update_permute) *) (** Use [beq_idP] to prove one final property of the [update] function: If we update a map [m] at two distinct keys, it doesn't matter in which order we do the updates. *) Theorem t_update_permute : forall (X:Type) v1 v2 x1 x2 (m : total_map X), x2 <> x1 -> (t_update (t_update m x2 v2) x1 v1) = (t_update (t_update m x1 v1) x2 v2). Proof. (* FILL IN HERE *) Admitted. (** [] *) (* ###################################################################### *) (** * Partial maps *) (** Finally, we can define _partial maps_ on top of total maps. A partial map with elements of type [A] is simply a total map with elements of type [option A] and default element [None]. *) Definition partial_map (A:Type) := total_map (option A). Definition empty {A:Type} : partial_map A := t_empty None. Definition update {A:Type} (m : partial_map A) (x : id) (v : A) := t_update m x (Some v). (** We can now lift all of the basic lemmas about total maps to partial maps. *) Lemma update_eq : forall A (m: partial_map A) x v, (update m x v) x = Some v. Proof. intros. unfold update. rewrite t_update_eq. reflexivity. Qed. Theorem update_neq : forall (X:Type) v x1 x2 (m : partial_map X), x2 <> x1 -> (update m x2 v) x1 = m x1. Proof. intros X v x1 x2 m H. unfold update. rewrite t_update_neq. reflexivity. apply H. Qed. Lemma update_shadow : forall A (m: partial_map A) v1 v2 x, update (update m x v1) x v2 = update m x v2. Proof. intros A m v1 v2 x1. unfold update. rewrite t_update_shadow. reflexivity. Qed. Theorem update_same : forall X v x (m : partial_map X), m x = Some v -> update m x v = m. Proof. intros X v x m H. unfold update. rewrite <- H. apply t_update_same. Qed. Theorem update_permute : forall (X:Type) v1 v2 x1 x2 (m : partial_map X), x2 <> x1 -> (update (update m x2 v2) x1 v1) = (update (update m x1 v1) x2 v2). Proof. intros X v1 v2 x1 x2 m. unfold update. apply t_update_permute. Qed. (** $Date: 2015-12-11 17:17:29 -0500 (Fri, 11 Dec 2015) $ *)
[STATEMENT] lemma liftT_substT_strange: "\<up>\<^sub>\<tau> n k T[n + k \<mapsto>\<^sub>\<tau> U]\<^sub>\<tau> = \<up>\<^sub>\<tau> n (Suc k) T[k \<mapsto>\<^sub>\<tau> \<up>\<^sub>\<tau> n 0 U]\<^sub>\<tau>" [PROOF STATE] proof (prove) goal (1 subgoal): 1. \<up>\<^sub>\<tau> n k T[n + k \<mapsto>\<^sub>\<tau> U]\<^sub>\<tau> = \<up>\<^sub>\<tau> n (Suc k) T[k \<mapsto>\<^sub>\<tau> \<up>\<^sub>\<tau> n 0 U]\<^sub>\<tau> [PROOF STEP] apply (induct T arbitrary: n k) [PROOF STATE] proof (prove) goal (4 subgoals): 1. \<And>x n k. \<up>\<^sub>\<tau> n k (TVar x)[n + k \<mapsto>\<^sub>\<tau> U]\<^sub>\<tau> = \<up>\<^sub>\<tau> n (Suc k) (TVar x)[k \<mapsto>\<^sub>\<tau> \<up>\<^sub>\<tau> n 0 U]\<^sub>\<tau> 2. \<And>n k. \<up>\<^sub>\<tau> n k Top[n + k \<mapsto>\<^sub>\<tau> U]\<^sub>\<tau> = \<up>\<^sub>\<tau> n (Suc k) Top[k \<mapsto>\<^sub>\<tau> \<up>\<^sub>\<tau> n 0 U]\<^sub>\<tau> 3. \<And>T1 T2 n k. \<lbrakk>\<And>n k. \<up>\<^sub>\<tau> n k T1[n + k \<mapsto>\<^sub>\<tau> U]\<^sub>\<tau> = \<up>\<^sub>\<tau> n (Suc k) T1[k \<mapsto>\<^sub>\<tau> \<up>\<^sub>\<tau> n 0 U]\<^sub>\<tau>; \<And>n k. \<up>\<^sub>\<tau> n k T2[n + k \<mapsto>\<^sub>\<tau> U]\<^sub>\<tau> = \<up>\<^sub>\<tau> n (Suc k) T2[k \<mapsto>\<^sub>\<tau> \<up>\<^sub>\<tau> n 0 U]\<^sub>\<tau>\<rbrakk> \<Longrightarrow> \<up>\<^sub>\<tau> n k (T1 \<rightarrow> T2)[n + k \<mapsto>\<^sub>\<tau> U]\<^sub>\<tau> = \<up>\<^sub>\<tau> n (Suc k) (T1 \<rightarrow> T2)[k \<mapsto>\<^sub>\<tau> \<up>\<^sub>\<tau> n 0 U]\<^sub>\<tau> 4. \<And>T1 T2 n k. \<lbrakk>\<And>n k. \<up>\<^sub>\<tau> n k T1[n + k \<mapsto>\<^sub>\<tau> U]\<^sub>\<tau> = \<up>\<^sub>\<tau> n (Suc k) T1[k \<mapsto>\<^sub>\<tau> \<up>\<^sub>\<tau> n 0 U]\<^sub>\<tau>; \<And>n k. \<up>\<^sub>\<tau> n k T2[n + k \<mapsto>\<^sub>\<tau> U]\<^sub>\<tau> = \<up>\<^sub>\<tau> n (Suc k) T2[k \<mapsto>\<^sub>\<tau> \<up>\<^sub>\<tau> n 0 U]\<^sub>\<tau>\<rbrakk> \<Longrightarrow> \<up>\<^sub>\<tau> n k (\<forall><:T1. T2)[n + k \<mapsto>\<^sub>\<tau> U]\<^sub>\<tau> = \<up>\<^sub>\<tau> n (Suc k) (\<forall><:T1. T2)[k \<mapsto>\<^sub>\<tau> \<up>\<^sub>\<tau> n 0 U]\<^sub>\<tau> [PROOF STEP] apply simp_all [PROOF STATE] proof (prove) goal (1 subgoal): 1. \<And>T1 T2 n k. \<lbrakk>\<And>n k. \<up>\<^sub>\<tau> n k T1[n + k \<mapsto>\<^sub>\<tau> U]\<^sub>\<tau> = \<up>\<^sub>\<tau> n (Suc k) T1[k \<mapsto>\<^sub>\<tau> \<up>\<^sub>\<tau> n 0 U]\<^sub>\<tau>; \<And>n k. \<up>\<^sub>\<tau> n k T2[n + k \<mapsto>\<^sub>\<tau> U]\<^sub>\<tau> = \<up>\<^sub>\<tau> n (Suc k) T2[k \<mapsto>\<^sub>\<tau> \<up>\<^sub>\<tau> n 0 U]\<^sub>\<tau>\<rbrakk> \<Longrightarrow> \<up>\<^sub>\<tau> n (Suc k) T2[Suc (n + k) \<mapsto>\<^sub>\<tau> U]\<^sub>\<tau> = \<up>\<^sub>\<tau> n (Suc (Suc k)) T2[Suc k \<mapsto>\<^sub>\<tau> \<up>\<^sub>\<tau> n 0 U]\<^sub>\<tau> [PROOF STEP] apply (thin_tac "\<And>x. PROP P x" for P :: "_ \<Rightarrow> prop") [PROOF STATE] proof (prove) goal (1 subgoal): 1. \<And>T1 T2 n k. (\<And>n k. \<up>\<^sub>\<tau> n k T2[n + k \<mapsto>\<^sub>\<tau> U]\<^sub>\<tau> = \<up>\<^sub>\<tau> n (Suc k) T2[k \<mapsto>\<^sub>\<tau> \<up>\<^sub>\<tau> n 0 U]\<^sub>\<tau>) \<Longrightarrow> \<up>\<^sub>\<tau> n (Suc k) T2[Suc (n + k) \<mapsto>\<^sub>\<tau> U]\<^sub>\<tau> = \<up>\<^sub>\<tau> n (Suc (Suc k)) T2[Suc k \<mapsto>\<^sub>\<tau> \<up>\<^sub>\<tau> n 0 U]\<^sub>\<tau> [PROOF STEP] apply (drule_tac x=n in meta_spec) [PROOF STATE] proof (prove) goal (1 subgoal): 1. \<And>T1 T2 n k. (\<And>k. \<up>\<^sub>\<tau> n k T2[n + k \<mapsto>\<^sub>\<tau> U]\<^sub>\<tau> = \<up>\<^sub>\<tau> n (Suc k) T2[k \<mapsto>\<^sub>\<tau> \<up>\<^sub>\<tau> n 0 U]\<^sub>\<tau>) \<Longrightarrow> \<up>\<^sub>\<tau> n (Suc k) T2[Suc (n + k) \<mapsto>\<^sub>\<tau> U]\<^sub>\<tau> = \<up>\<^sub>\<tau> n (Suc (Suc k)) T2[Suc k \<mapsto>\<^sub>\<tau> \<up>\<^sub>\<tau> n 0 U]\<^sub>\<tau> [PROOF STEP] apply (drule_tac x="Suc k" in meta_spec) [PROOF STATE] proof (prove) goal (1 subgoal): 1. \<And>T1 T2 n k. \<up>\<^sub>\<tau> n (Suc k) T2[n + Suc k \<mapsto>\<^sub>\<tau> U]\<^sub>\<tau> = \<up>\<^sub>\<tau> n (Suc (Suc k)) T2[Suc k \<mapsto>\<^sub>\<tau> \<up>\<^sub>\<tau> n 0 U]\<^sub>\<tau> \<Longrightarrow> \<up>\<^sub>\<tau> n (Suc k) T2[Suc (n + k) \<mapsto>\<^sub>\<tau> U]\<^sub>\<tau> = \<up>\<^sub>\<tau> n (Suc (Suc k)) T2[Suc k \<mapsto>\<^sub>\<tau> \<up>\<^sub>\<tau> n 0 U]\<^sub>\<tau> [PROOF STEP] apply simp [PROOF STATE] proof (prove) goal: No subgoals! [PROOF STEP] done
{-# OPTIONS --without-K --safe #-} open import Definition.Typed.EqualityRelation module Definition.LogicalRelation.Substitution {{eqrel : EqRelSet}} where open import Agda.Primitive open import Definition.Untyped open import Definition.Typed open import Definition.LogicalRelation open import Tools.Embedding open import Tools.Product open import Tools.Unit -- The validity judgements: -- We consider expressions that satisfy these judgments valid ValRel : Setω₂ ValRel = (Γ : Con Term) → (⊩Subst : (Δ : Con Term) → Subst → ⊢ Δ → Setω) → (⊩EqSubst : (Δ : Con Term) → (σ σ′ : Subst) → (⊢Δ : ⊢ Δ) → (⊩Subst Δ σ ⊢Δ) → Setω) → Setω₁ record ⊩ᵛ⁰_/_ (Γ : Con Term) (_⊩_▸_ : ValRel) : Setω₁ where inductive eta-equality constructor VPack field ⊩Subst : (Δ : Con Term) → Subst → ⊢ Δ → Setω ⊩EqSubst : (Δ : Con Term) → (σ σ′ : Subst) → (⊢Δ : ⊢ Δ) → (⊩Subst Δ σ ⊢Δ) → Setω ⊩V : Γ ⊩ ⊩Subst ▸ ⊩EqSubst _⊩ˢ⁰_∷_/_/_ : {R : ValRel} (Δ : Con Term) (σ : Subst) (Γ : Con Term) ([Γ] : ⊩ᵛ⁰ Γ / R) (⊢Δ : ⊢ Δ) → Setω Δ ⊩ˢ⁰ σ ∷ Γ / VPack ⊩Subst ⊩EqSubst ⊩V / ⊢Δ = ⊩Subst Δ σ ⊢Δ _⊩ˢ⁰_≡_∷_/_/_/_ : {R : ValRel} (Δ : Con Term) (σ σ′ : Subst) (Γ : Con Term) ([Γ] : ⊩ᵛ⁰ Γ / R) (⊢Δ : ⊢ Δ) ([σ] : Δ ⊩ˢ⁰ σ ∷ Γ / [Γ] / ⊢Δ) → Setω Δ ⊩ˢ⁰ σ ≡ σ′ ∷ Γ / VPack ⊩Subst ⊩EqSubst ⊩V / ⊢Δ / [σ] = ⊩EqSubst Δ σ σ′ ⊢Δ [σ] -- Validity of types _⊩ᵛ⁰⟨_⟩_/_ : {R : ValRel} (Γ : Con Term) (l : TypeLevel) (A : Term) → ⊩ᵛ⁰ Γ / R → Setω _⊩ᵛ⁰⟨_⟩_/_ Γ l A [Γ] = ∀ {Δ σ} (⊢Δ : ⊢ Δ) ([σ] : Δ ⊩ˢ⁰ σ ∷ Γ / [Γ] / ⊢Δ) → Σω₀ (Δ ⊩⟨ l ⟩ subst σ A) (λ [Aσ] → ∀ {σ′} ([σ′] : Δ ⊩ˢ⁰ σ′ ∷ Γ / [Γ] / ⊢Δ) ([σ≡σ′] : Δ ⊩ˢ⁰ σ ≡ σ′ ∷ Γ / [Γ] / ⊢Δ / [σ]) → Δ ⊩⟨ l ⟩ subst σ A ≡ subst σ′ A / [Aσ]) data _⊩V_▸_ : ValRel where Vε : ε ⊩V (λ Δ σ ⊢Δ → ⊤′) ▸ (λ Δ σ σ′ ⊢Δ [σ] → ⊤′) V∙ : ∀ {Γ A l} → ([Γ] : ⊩ᵛ⁰ Γ / _⊩V_▸_) → ([A] : Γ ⊩ᵛ⁰⟨ l ⟩ A / [Γ]) → Γ ∙ A ⊩V (λ Δ σ ⊢Δ → Σω₂ (Δ ⊩ˢ⁰ tail σ ∷ Γ / [Γ] / ⊢Δ) (λ [tailσ] → (Δ ⊩⟨ l ⟩ head σ ∷ subst (tail σ) A / proj₁ ([A] ⊢Δ [tailσ])))) ▸ (λ Δ σ σ′ ⊢Δ [σ] → (Δ ⊩ˢ⁰ tail σ ≡ tail σ′ ∷ Γ / [Γ] / ⊢Δ / proj₁ [σ]) ×ω₂ (Δ ⊩⟨ l ⟩ head σ ≡ head σ′ ∷ subst (tail σ) A / proj₁ ([A] ⊢Δ (proj₁ [σ])))) ⊩ᵛ : Con Term → Setω₁ ⊩ᵛ Γ = ⊩ᵛ⁰ Γ / _⊩V_▸_ _⊩ˢ_∷_/_/_ : (Δ : Con Term) (σ : Subst) (Γ : Con Term) ([Γ] : ⊩ᵛ Γ) (⊢Δ : ⊢ Δ) → Setω Δ ⊩ˢ σ ∷ Γ / [Γ] / ⊢Δ = Δ ⊩ˢ⁰ σ ∷ Γ / [Γ] / ⊢Δ _⊩ˢ_≡_∷_/_/_/_ : (Δ : Con Term) (σ σ′ : Subst) (Γ : Con Term) ([Γ] : ⊩ᵛ Γ) (⊢Δ : ⊢ Δ) ([σ] : Δ ⊩ˢ σ ∷ Γ / [Γ] / ⊢Δ) → Setω Δ ⊩ˢ σ ≡ σ′ ∷ Γ / [Γ] / ⊢Δ / [σ] = Δ ⊩ˢ⁰ σ ≡ σ′ ∷ Γ / [Γ] / ⊢Δ / [σ] -- Validity of types _⊩ᵛ⟨_⟩_/_ : (Γ : Con Term) (l : TypeLevel) (A : Term) → ⊩ᵛ Γ → Setω Γ ⊩ᵛ⟨ l ⟩ A / [Γ] = Γ ⊩ᵛ⁰⟨ l ⟩ A / [Γ] -- Validity of terms _⊩ᵛ⟨_⟩_∷_/_/_ : (Γ : Con Term) (l : TypeLevel) (t A : Term) ([Γ] : ⊩ᵛ Γ) ([A] : Γ ⊩ᵛ⟨ l ⟩ A / [Γ]) → Setω Γ ⊩ᵛ⟨ l ⟩ t ∷ A / [Γ] / [A] = ∀ {Δ σ} (⊢Δ : ⊢ Δ) ([σ] : Δ ⊩ˢ σ ∷ Γ / [Γ] / ⊢Δ) → Σω₀ (Δ ⊩⟨ l ⟩ subst σ t ∷ subst σ A / proj₁ ([A] ⊢Δ [σ])) λ [tσ] → ∀ {σ′} → Δ ⊩ˢ σ′ ∷ Γ / [Γ] / ⊢Δ → Δ ⊩ˢ σ ≡ σ′ ∷ Γ / [Γ] / ⊢Δ / [σ] → Δ ⊩⟨ l ⟩ subst σ t ≡ subst σ′ t ∷ subst σ A / proj₁ ([A] ⊢Δ [σ]) -- Validity of type equality _⊩ᵛ⟨_⟩_≡_/_/_ : (Γ : Con Term) (l : TypeLevel) (A B : Term) ([Γ] : ⊩ᵛ Γ) ([A] : Γ ⊩ᵛ⟨ l ⟩ A / [Γ]) → Setω Γ ⊩ᵛ⟨ l ⟩ A ≡ B / [Γ] / [A] = ∀ {Δ σ} (⊢Δ : ⊢ Δ) ([σ] : Δ ⊩ˢ σ ∷ Γ / [Γ] / ⊢Δ) → Δ ⊩⟨ l ⟩ subst σ A ≡ subst σ B / proj₁ ([A] ⊢Δ [σ]) -- Validity of term equality _⊩ᵛ⟨_⟩_≡_∷_/_/_ : (Γ : Con Term) (l : TypeLevel) (t u A : Term) ([Γ] : ⊩ᵛ Γ) ([A] : Γ ⊩ᵛ⟨ l ⟩ A / [Γ]) → Setω Γ ⊩ᵛ⟨ l ⟩ t ≡ u ∷ A / [Γ] / [A] = ∀ {Δ σ} → (⊢Δ : ⊢ Δ) ([σ] : Δ ⊩ˢ σ ∷ Γ / [Γ] / ⊢Δ) → Δ ⊩⟨ l ⟩ subst σ t ≡ subst σ u ∷ subst σ A / proj₁ ([A] ⊢Δ [σ]) -- Valid term equality with validity of its type and terms record [_⊩ᵛ⟨_⟩_≡_∷_/_] (Γ : Con Term) (l : TypeLevel) (t u A : Term) ([Γ] : ⊩ᵛ Γ) : Setω where constructor modelsTermEq field [A] : Γ ⊩ᵛ⟨ l ⟩ A / [Γ] [t] : Γ ⊩ᵛ⟨ l ⟩ t ∷ A / [Γ] / [A] [u] : Γ ⊩ᵛ⟨ l ⟩ u ∷ A / [Γ] / [A] [t≡u] : Γ ⊩ᵛ⟨ l ⟩ t ≡ u ∷ A / [Γ] / [A] -- Validity of reduction of terms _⊩ᵛ_⇒_∷_/_ : (Γ : Con Term) (t u A : Term) ([Γ] : ⊩ᵛ Γ) → Setω Γ ⊩ᵛ t ⇒ u ∷ A / [Γ] = ∀ {Δ σ} (⊢Δ : ⊢ Δ) ([σ] : Δ ⊩ˢ σ ∷ Γ / [Γ] / ⊢Δ) → Δ ⊢ subst σ t ⇒ subst σ u ∷ subst σ A _∙″_ : ∀ {Γ A l} → ([Γ] : ⊩ᵛ Γ) → Γ ⊩ᵛ⟨ l ⟩ A / [Γ] → ⊩ᵛ (Γ ∙ A) [Γ] ∙″ [A] = (VPack _ _ (V∙ [Γ] [A])) pattern ε′ = (VPack _ _ Vε) pattern _∙′_ [Γ] [A] = (VPack _ _ (V∙ [Γ] [A]))
Formal statement is: lemma eventually_at_right_real: "a < (b :: real) \<Longrightarrow> eventually (\<lambda>x. x \<in> {a<..<b}) (at_right a)" Informal statement is: If $a < b$, then there exists a neighborhood of $a$ such that all points in that neighborhood are in the interval $(a, b)$.
/- Copyright (c) 2019 Scott Morrison. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Scott Morrison, Bhavik Mehta -/ import category_theory.adjunction.reflective import category_theory.monad.algebra namespace category_theory open category universes v₁ v₂ u₁ u₂ -- morphism levels before object levels. See note [category_theory universes]. variables {C : Type u₁} [category.{v₁} C] {D : Type u₂} [category.{v₂} D] variables {L : C ⥤ D} {R : D ⥤ C} namespace adjunction /-- For a pair of functors `L : C ⥤ D`, `R : D ⥤ C`, an adjunction `h : L ⊣ R` induces a monad on the category `C`. -/ @[simps] def to_monad (h : L ⊣ R) : monad C := { to_functor := L ⋙ R, η' := h.unit, μ' := whisker_right (whisker_left L h.counit) R, assoc' := λ X, by { dsimp, rw [←R.map_comp], simp }, right_unit' := λ X, by { dsimp, rw [←R.map_comp], simp } } /-- For a pair of functors `L : C ⥤ D`, `R : D ⥤ C`, an adjunction `h : L ⊣ R` induces a comonad on the category `D`. -/ @[simps] def to_comonad (h : L ⊣ R) : comonad D := { to_functor := R ⋙ L, ε' := h.counit, δ' := whisker_right (whisker_left R h.unit) L, coassoc' := λ X, by { dsimp, rw ← L.map_comp, simp }, right_counit' := λ X, by { dsimp, rw ← L.map_comp, simp } } /-- The monad induced by the Eilenberg-Moore adjunction is the original monad. -/ @[simps] def adj_to_monad_iso (T : monad C) : T.adj.to_monad ≅ T := monad_iso.mk (nat_iso.of_components (λ X, iso.refl _) (by tidy)) (λ X, by { dsimp, simp }) (λ X, by { dsimp, simp }) /-- The comonad induced by the Eilenberg-Moore adjunction is the original comonad. -/ @[simps] def adj_to_comonad_iso (G : comonad C) : G.adj.to_comonad ≅ G := comonad_iso.mk (nat_iso.of_components (λ X, iso.refl _) (by tidy)) (λ X, by { dsimp, simp }) (λ X, by { dsimp, simp }) end adjunction /-- Gven any adjunction `L ⊣ R`, there is a comparison functor `category_theory.monad.comparison R` sending objects `Y : D` to Eilenberg-Moore algebras for `L ⋙ R` with underlying object `R.obj X`. We later show that this is full when `R` is full, faithful when `R` is faithful, and essentially surjective when `R` is reflective. -/ @[simps] def monad.comparison (h : L ⊣ R) : D ⥤ h.to_monad.algebra := { obj := λ X, { A := R.obj X, a := R.map (h.counit.app X), assoc' := by { dsimp, rw [← R.map_comp, ← adjunction.counit_naturality, R.map_comp], refl } }, map := λ X Y f, { f := R.map f, h' := by { dsimp, rw [← R.map_comp, adjunction.counit_naturality, R.map_comp] } } }. /-- The underlying object of `(monad.comparison R).obj X` is just `R.obj X`. -/ @[simps] def monad.comparison_forget (h : L ⊣ R) : monad.comparison h ⋙ h.to_monad.forget ≅ R := { hom := { app := λ X, 𝟙 _, }, inv := { app := λ X, 𝟙 _, } } lemma monad.left_comparison (h : L ⊣ R) : L ⋙ monad.comparison h = h.to_monad.free := rfl instance [faithful R] (h : L ⊣ R) : faithful (monad.comparison h) := { map_injective' := λ X Y f g w, R.map_injective (congr_arg monad.algebra.hom.f w : _) } instance (T : monad C) : full (monad.comparison T.adj) := { preimage := λ X Y f, ⟨f.f, by simpa using f.h⟩ } instance (T : monad C) : ess_surj (monad.comparison T.adj) := { mem_ess_image := λ X, ⟨{ A := X.A, a := X.a, unit' := by simpa using X.unit, assoc' := by simpa using X.assoc }, ⟨monad.algebra.iso_mk (iso.refl _) (by simp)⟩⟩ } /-- Gven any adjunction `L ⊣ R`, there is a comparison functor `category_theory.comonad.comparison L` sending objects `X : C` to Eilenberg-Moore coalgebras for `L ⋙ R` with underlying object `L.obj X`. -/ @[simps] def comonad.comparison (h : L ⊣ R) : C ⥤ h.to_comonad.coalgebra := { obj := λ X, { A := L.obj X, a := L.map (h.unit.app X), coassoc' := by { dsimp, rw [← L.map_comp, ← adjunction.unit_naturality, L.map_comp], refl } }, map := λ X Y f, { f := L.map f, h' := by { dsimp, rw ← L.map_comp, simp } } } /-- The underlying object of `(comonad.comparison L).obj X` is just `L.obj X`. -/ @[simps] def comonad.comparison_forget {L : C ⥤ D} {R : D ⥤ C} (h : L ⊣ R) : comonad.comparison h ⋙ h.to_comonad.forget ≅ L := { hom := { app := λ X, 𝟙 _, }, inv := { app := λ X, 𝟙 _, } } lemma comonad.left_comparison (h : L ⊣ R) : R ⋙ comonad.comparison h = h.to_comonad.cofree := rfl instance comonad.comparison_faithful_of_faithful [faithful L] (h : L ⊣ R) : faithful (comonad.comparison h) := { map_injective' := λ X Y f g w, L.map_injective (congr_arg comonad.coalgebra.hom.f w : _) } instance (G : comonad C) : full (comonad.comparison G.adj) := { preimage := λ X Y f, ⟨f.f, by simpa using f.h⟩ } instance (G : comonad C) : ess_surj (comonad.comparison G.adj) := { mem_ess_image := λ X, ⟨{ A := X.A, a := X.a, counit' := by simpa using X.counit, coassoc' := by simpa using X.coassoc }, ⟨comonad.coalgebra.iso_mk (iso.refl _) (by simp)⟩⟩ } /-- A right adjoint functor `R : D ⥤ C` is *monadic* if the comparison functor `monad.comparison R` from `D` to the category of Eilenberg-Moore algebras for the adjunction is an equivalence. -/ class monadic_right_adjoint (R : D ⥤ C) extends is_right_adjoint R := (eqv : is_equivalence (monad.comparison (adjunction.of_right_adjoint R))) /-- A left adjoint functor `L : C ⥤ D` is *comonadic* if the comparison functor `comonad.comparison L` from `C` to the category of Eilenberg-Moore algebras for the adjunction is an equivalence. -/ class comonadic_left_adjoint (L : C ⥤ D) extends is_left_adjoint L := (eqv : is_equivalence (comonad.comparison (adjunction.of_left_adjoint L))) noncomputable instance (T : monad C) : monadic_right_adjoint T.forget := ⟨(equivalence.of_fully_faithfully_ess_surj _ : is_equivalence (monad.comparison T.adj))⟩ noncomputable instance (G : comonad C) : comonadic_left_adjoint G.forget := ⟨(equivalence.of_fully_faithfully_ess_surj _ : is_equivalence (comonad.comparison G.adj))⟩ -- TODO: This holds more generally for idempotent adjunctions, not just reflective adjunctions. instance μ_iso_of_reflective [reflective R] : is_iso (adjunction.of_right_adjoint R).to_monad.μ := by { dsimp, apply_instance } attribute [instance] monadic_right_adjoint.eqv attribute [instance] comonadic_left_adjoint.eqv namespace reflective instance [reflective R] (X : (adjunction.of_right_adjoint R).to_monad.algebra) : is_iso ((adjunction.of_right_adjoint R).unit.app X.A) := ⟨⟨X.a, ⟨X.unit, begin dsimp only [functor.id_obj], rw ← (adjunction.of_right_adjoint R).unit_naturality, dsimp only [functor.comp_obj, adjunction.to_monad_coe], rw [unit_obj_eq_map_unit, ←functor.map_comp, ←functor.map_comp], erw X.unit, simp, end⟩⟩⟩ instance comparison_ess_surj [reflective R] : ess_surj (monad.comparison (adjunction.of_right_adjoint R)) := begin refine ⟨λ X, ⟨(left_adjoint R).obj X.A, ⟨_⟩⟩⟩, symmetry, refine monad.algebra.iso_mk _ _, { exact as_iso ((adjunction.of_right_adjoint R).unit.app X.A) }, dsimp only [functor.comp_map, monad.comparison_obj_a, as_iso_hom, functor.comp_obj, monad.comparison_obj_A, monad_to_functor_eq_coe, adjunction.to_monad_coe], rw [←cancel_epi ((adjunction.of_right_adjoint R).unit.app X.A), adjunction.unit_naturality_assoc, adjunction.right_triangle_components, comp_id], apply (X.unit_assoc _).symm, end instance comparison_full [full R] [is_right_adjoint R] : full (monad.comparison (adjunction.of_right_adjoint R)) := { preimage := λ X Y f, R.preimage f.f } end reflective -- It is possible to do this computably since the construction gives the data of the inverse, not -- just the existence of an inverse on each object. /-- Any reflective inclusion has a monadic right adjoint. cf Prop 5.3.3 of [Riehl][riehl2017] -/ @[priority 100] -- see Note [lower instance priority] noncomputable instance monadic_of_reflective [reflective R] : monadic_right_adjoint R := { eqv := equivalence.of_fully_faithfully_ess_surj _ } end category_theory
(* Title: HOL/Auth/n_flash_nodata_cub_lemma_on_inv__22.thy Author: Yongjian Li and Kaiqiang Duan, State Key Lab of Computer Science, Institute of Software, Chinese Academy of Sciences Copyright 2016 State Key Lab of Computer Science, Institute of Software, Chinese Academy of Sciences *) header{*The n_flash_nodata_cub Protocol Case Study*} theory n_flash_nodata_cub_lemma_on_inv__22 imports n_flash_nodata_cub_base begin section{*All lemmas on causal relation between inv__22 and some rule r*} lemma n_PI_Remote_GetVsinv__22: assumes a1: "(\<exists> src. src\<le>N\<and>r=n_PI_Remote_Get src)" and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__22 p__Inv4)" shows "invHoldForRule s f r (invariants N)" (is "?P1 s \<or> ?P2 s \<or> ?P3 s") proof - from a1 obtain src where a1:"src\<le>N\<and>r=n_PI_Remote_Get src" apply fastforce done from a2 obtain p__Inv4 where a2:"p__Inv4\<le>N\<and>f=inv__22 p__Inv4" apply fastforce done have "(src=p__Inv4)\<or>(src~=p__Inv4)" apply (cut_tac a1 a2, auto) done moreover { assume b1: "(src=p__Inv4)" have "?P1 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume b1: "(src~=p__Inv4)" have "?P2 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } ultimately show "invHoldForRule s f r (invariants N)" by satx qed lemma n_PI_Remote_GetXVsinv__22: assumes a1: "(\<exists> src. src\<le>N\<and>r=n_PI_Remote_GetX src)" and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__22 p__Inv4)" shows "invHoldForRule s f r (invariants N)" (is "?P1 s \<or> ?P2 s \<or> ?P3 s") proof - from a1 obtain src where a1:"src\<le>N\<and>r=n_PI_Remote_GetX src" apply fastforce done from a2 obtain p__Inv4 where a2:"p__Inv4\<le>N\<and>f=inv__22 p__Inv4" apply fastforce done have "(src=p__Inv4)\<or>(src~=p__Inv4)" apply (cut_tac a1 a2, auto) done moreover { assume b1: "(src=p__Inv4)" have "?P1 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume b1: "(src~=p__Inv4)" have "?P2 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } ultimately show "invHoldForRule s f r (invariants N)" by satx qed lemma n_NI_NakVsinv__22: assumes a1: "(\<exists> dst. dst\<le>N\<and>r=n_NI_Nak dst)" and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__22 p__Inv4)" shows "invHoldForRule s f r (invariants N)" (is "?P1 s \<or> ?P2 s \<or> ?P3 s") proof - from a1 obtain dst where a1:"dst\<le>N\<and>r=n_NI_Nak dst" apply fastforce done from a2 obtain p__Inv4 where a2:"p__Inv4\<le>N\<and>f=inv__22 p__Inv4" apply fastforce done have "(dst=p__Inv4)\<or>(dst~=p__Inv4)" apply (cut_tac a1 a2, auto) done moreover { assume b1: "(dst=p__Inv4)" have "?P1 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume b1: "(dst~=p__Inv4)" have "?P2 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } ultimately show "invHoldForRule s f r (invariants N)" by satx qed lemma n_NI_Local_Get_Nak__part__0Vsinv__22: assumes a1: "(\<exists> src. src\<le>N\<and>r=n_NI_Local_Get_Nak__part__0 src)" and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__22 p__Inv4)" shows "invHoldForRule s f r (invariants N)" (is "?P1 s \<or> ?P2 s \<or> ?P3 s") proof - from a1 obtain src where a1:"src\<le>N\<and>r=n_NI_Local_Get_Nak__part__0 src" apply fastforce done from a2 obtain p__Inv4 where a2:"p__Inv4\<le>N\<and>f=inv__22 p__Inv4" apply fastforce done have "(src=p__Inv4)\<or>(src~=p__Inv4)" apply (cut_tac a1 a2, auto) done moreover { assume b1: "(src=p__Inv4)" have "?P1 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume b1: "(src~=p__Inv4)" have "?P2 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } ultimately show "invHoldForRule s f r (invariants N)" by satx qed lemma n_NI_Local_Get_Nak__part__1Vsinv__22: assumes a1: "(\<exists> src. src\<le>N\<and>r=n_NI_Local_Get_Nak__part__1 src)" and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__22 p__Inv4)" shows "invHoldForRule s f r (invariants N)" (is "?P1 s \<or> ?P2 s \<or> ?P3 s") proof - from a1 obtain src where a1:"src\<le>N\<and>r=n_NI_Local_Get_Nak__part__1 src" apply fastforce done from a2 obtain p__Inv4 where a2:"p__Inv4\<le>N\<and>f=inv__22 p__Inv4" apply fastforce done have "(src=p__Inv4)\<or>(src~=p__Inv4)" apply (cut_tac a1 a2, auto) done moreover { assume b1: "(src=p__Inv4)" have "?P1 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume b1: "(src~=p__Inv4)" have "?P2 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } ultimately show "invHoldForRule s f r (invariants N)" by satx qed lemma n_NI_Local_Get_Nak__part__2Vsinv__22: assumes a1: "(\<exists> src. src\<le>N\<and>r=n_NI_Local_Get_Nak__part__2 src)" and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__22 p__Inv4)" shows "invHoldForRule s f r (invariants N)" (is "?P1 s \<or> ?P2 s \<or> ?P3 s") proof - from a1 obtain src where a1:"src\<le>N\<and>r=n_NI_Local_Get_Nak__part__2 src" apply fastforce done from a2 obtain p__Inv4 where a2:"p__Inv4\<le>N\<and>f=inv__22 p__Inv4" apply fastforce done have "(src=p__Inv4)\<or>(src~=p__Inv4)" apply (cut_tac a1 a2, auto) done moreover { assume b1: "(src=p__Inv4)" have "?P1 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume b1: "(src~=p__Inv4)" have "?P2 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } ultimately show "invHoldForRule s f r (invariants N)" by satx qed lemma n_NI_Local_Get_Get__part__0Vsinv__22: assumes a1: "(\<exists> src. src\<le>N\<and>r=n_NI_Local_Get_Get__part__0 src)" and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__22 p__Inv4)" shows "invHoldForRule s f r (invariants N)" (is "?P1 s \<or> ?P2 s \<or> ?P3 s") proof - from a1 obtain src where a1:"src\<le>N\<and>r=n_NI_Local_Get_Get__part__0 src" apply fastforce done from a2 obtain p__Inv4 where a2:"p__Inv4\<le>N\<and>f=inv__22 p__Inv4" apply fastforce done have "(src=p__Inv4)\<or>(src~=p__Inv4)" apply (cut_tac a1 a2, auto) done moreover { assume b1: "(src=p__Inv4)" have "?P1 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume b1: "(src~=p__Inv4)" have "?P2 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } ultimately show "invHoldForRule s f r (invariants N)" by satx qed lemma n_NI_Local_Get_Get__part__1Vsinv__22: assumes a1: "(\<exists> src. src\<le>N\<and>r=n_NI_Local_Get_Get__part__1 src)" and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__22 p__Inv4)" shows "invHoldForRule s f r (invariants N)" (is "?P1 s \<or> ?P2 s \<or> ?P3 s") proof - from a1 obtain src where a1:"src\<le>N\<and>r=n_NI_Local_Get_Get__part__1 src" apply fastforce done from a2 obtain p__Inv4 where a2:"p__Inv4\<le>N\<and>f=inv__22 p__Inv4" apply fastforce done have "(src=p__Inv4)\<or>(src~=p__Inv4)" apply (cut_tac a1 a2, auto) done moreover { assume b1: "(src=p__Inv4)" have "?P1 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume b1: "(src~=p__Inv4)" have "?P2 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } ultimately show "invHoldForRule s f r (invariants N)" by satx qed lemma n_NI_Local_Get_Put_HeadVsinv__22: assumes a1: "(\<exists> src. src\<le>N\<and>r=n_NI_Local_Get_Put_Head N src)" and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__22 p__Inv4)" shows "invHoldForRule s f r (invariants N)" (is "?P1 s \<or> ?P2 s \<or> ?P3 s") proof - from a1 obtain src where a1:"src\<le>N\<and>r=n_NI_Local_Get_Put_Head N src" apply fastforce done from a2 obtain p__Inv4 where a2:"p__Inv4\<le>N\<and>f=inv__22 p__Inv4" apply fastforce done have "(src=p__Inv4)\<or>(src~=p__Inv4)" apply (cut_tac a1 a2, auto) done moreover { assume b1: "(src=p__Inv4)" have "?P1 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume b1: "(src~=p__Inv4)" have "?P2 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } ultimately show "invHoldForRule s f r (invariants N)" by satx qed lemma n_NI_Local_Get_PutVsinv__22: assumes a1: "(\<exists> src. src\<le>N\<and>r=n_NI_Local_Get_Put src)" and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__22 p__Inv4)" shows "invHoldForRule s f r (invariants N)" (is "?P1 s \<or> ?P2 s \<or> ?P3 s") proof - from a1 obtain src where a1:"src\<le>N\<and>r=n_NI_Local_Get_Put src" apply fastforce done from a2 obtain p__Inv4 where a2:"p__Inv4\<le>N\<and>f=inv__22 p__Inv4" apply fastforce done have "(src=p__Inv4)\<or>(src~=p__Inv4)" apply (cut_tac a1 a2, auto) done moreover { assume b1: "(src=p__Inv4)" have "?P1 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume b1: "(src~=p__Inv4)" have "?P2 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } ultimately show "invHoldForRule s f r (invariants N)" by satx qed lemma n_NI_Local_Get_Put_DirtyVsinv__22: assumes a1: "(\<exists> src. src\<le>N\<and>r=n_NI_Local_Get_Put_Dirty src)" and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__22 p__Inv4)" shows "invHoldForRule s f r (invariants N)" (is "?P1 s \<or> ?P2 s \<or> ?P3 s") proof - from a1 obtain src where a1:"src\<le>N\<and>r=n_NI_Local_Get_Put_Dirty src" apply fastforce done from a2 obtain p__Inv4 where a2:"p__Inv4\<le>N\<and>f=inv__22 p__Inv4" apply fastforce done have "(src=p__Inv4)\<or>(src~=p__Inv4)" apply (cut_tac a1 a2, auto) done moreover { assume b1: "(src=p__Inv4)" have "?P1 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume b1: "(src~=p__Inv4)" have "?P2 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } ultimately show "invHoldForRule s f r (invariants N)" by satx qed lemma n_NI_Remote_Get_NakVsinv__22: assumes a1: "(\<exists> src dst. src\<le>N\<and>dst\<le>N\<and>src~=dst\<and>r=n_NI_Remote_Get_Nak src dst)" and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__22 p__Inv4)" shows "invHoldForRule s f r (invariants N)" (is "?P1 s \<or> ?P2 s \<or> ?P3 s") proof - from a1 obtain src dst where a1:"src\<le>N\<and>dst\<le>N\<and>src~=dst\<and>r=n_NI_Remote_Get_Nak src dst" apply fastforce done from a2 obtain p__Inv4 where a2:"p__Inv4\<le>N\<and>f=inv__22 p__Inv4" apply fastforce done have "(src=p__Inv4\<and>dst~=p__Inv4)\<or>(src~=p__Inv4\<and>dst=p__Inv4)\<or>(src~=p__Inv4\<and>dst~=p__Inv4)" apply (cut_tac a1 a2, auto) done moreover { assume b1: "(src=p__Inv4\<and>dst~=p__Inv4)" have "?P1 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume b1: "(src~=p__Inv4\<and>dst=p__Inv4)" have "?P2 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume b1: "(src~=p__Inv4\<and>dst~=p__Inv4)" have "?P2 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } ultimately show "invHoldForRule s f r (invariants N)" by satx qed lemma n_NI_Remote_Get_Nak_HomeVsinv__22: assumes a1: "(\<exists> dst. dst\<le>N\<and>r=n_NI_Remote_Get_Nak_Home dst)" and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__22 p__Inv4)" shows "invHoldForRule s f r (invariants N)" (is "?P1 s \<or> ?P2 s \<or> ?P3 s") proof - from a1 obtain dst where a1:"dst\<le>N\<and>r=n_NI_Remote_Get_Nak_Home dst" apply fastforce done from a2 obtain p__Inv4 where a2:"p__Inv4\<le>N\<and>f=inv__22 p__Inv4" apply fastforce done have "(dst=p__Inv4)\<or>(dst~=p__Inv4)" apply (cut_tac a1 a2, auto) done moreover { assume b1: "(dst=p__Inv4)" have "?P1 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume b1: "(dst~=p__Inv4)" have "?P1 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } ultimately show "invHoldForRule s f r (invariants N)" by satx qed lemma n_NI_Remote_Get_PutVsinv__22: assumes a1: "(\<exists> src dst. src\<le>N\<and>dst\<le>N\<and>src~=dst\<and>r=n_NI_Remote_Get_Put src dst)" and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__22 p__Inv4)" shows "invHoldForRule s f r (invariants N)" (is "?P1 s \<or> ?P2 s \<or> ?P3 s") proof - from a1 obtain src dst where a1:"src\<le>N\<and>dst\<le>N\<and>src~=dst\<and>r=n_NI_Remote_Get_Put src dst" apply fastforce done from a2 obtain p__Inv4 where a2:"p__Inv4\<le>N\<and>f=inv__22 p__Inv4" apply fastforce done have "(src=p__Inv4\<and>dst~=p__Inv4)\<or>(src~=p__Inv4\<and>dst=p__Inv4)\<or>(src~=p__Inv4\<and>dst~=p__Inv4)" apply (cut_tac a1 a2, auto) done moreover { assume b1: "(src=p__Inv4\<and>dst~=p__Inv4)" have "?P1 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume b1: "(src~=p__Inv4\<and>dst=p__Inv4)" have "?P2 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume b1: "(src~=p__Inv4\<and>dst~=p__Inv4)" have "?P2 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } ultimately show "invHoldForRule s f r (invariants N)" by satx qed lemma n_NI_Remote_Get_Put_HomeVsinv__22: assumes a1: "(\<exists> dst. dst\<le>N\<and>r=n_NI_Remote_Get_Put_Home dst)" and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__22 p__Inv4)" shows "invHoldForRule s f r (invariants N)" (is "?P1 s \<or> ?P2 s \<or> ?P3 s") proof - from a1 obtain dst where a1:"dst\<le>N\<and>r=n_NI_Remote_Get_Put_Home dst" apply fastforce done from a2 obtain p__Inv4 where a2:"p__Inv4\<le>N\<and>f=inv__22 p__Inv4" apply fastforce done have "(dst=p__Inv4)\<or>(dst~=p__Inv4)" apply (cut_tac a1 a2, auto) done moreover { assume b1: "(dst=p__Inv4)" have "?P3 s" apply (cut_tac a1 a2 b1, simp, rule_tac x="(neg (andForm (eqn (IVar (Field (Para (Field (Ident ''Sta'') ''UniMsg'') p__Inv4) ''Cmd'')) (Const UNI_PutX)) (eqn (IVar (Field (Para (Field (Ident ''Sta'') ''Proc'') p__Inv4) ''CacheState'')) (Const CACHE_E))))" in exI, auto) done then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume b1: "(dst~=p__Inv4)" have "?P3 s" apply (cut_tac a1 a2 b1, simp, rule_tac x="(neg (andForm (eqn (IVar (Field (Para (Field (Ident ''Sta'') ''Proc'') dst) ''CacheState'')) (Const CACHE_E)) (eqn (IVar (Field (Para (Field (Ident ''Sta'') ''UniMsg'') p__Inv4) ''Cmd'')) (Const UNI_PutX))))" in exI, auto) done then have "invHoldForRule s f r (invariants N)" by auto } ultimately show "invHoldForRule s f r (invariants N)" by satx qed lemma n_NI_Local_GetX_Nak__part__0Vsinv__22: assumes a1: "(\<exists> src. src\<le>N\<and>r=n_NI_Local_GetX_Nak__part__0 src)" and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__22 p__Inv4)" shows "invHoldForRule s f r (invariants N)" (is "?P1 s \<or> ?P2 s \<or> ?P3 s") proof - from a1 obtain src where a1:"src\<le>N\<and>r=n_NI_Local_GetX_Nak__part__0 src" apply fastforce done from a2 obtain p__Inv4 where a2:"p__Inv4\<le>N\<and>f=inv__22 p__Inv4" apply fastforce done have "(src=p__Inv4)\<or>(src~=p__Inv4)" apply (cut_tac a1 a2, auto) done moreover { assume b1: "(src=p__Inv4)" have "?P1 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume b1: "(src~=p__Inv4)" have "?P2 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } ultimately show "invHoldForRule s f r (invariants N)" by satx qed lemma n_NI_Local_GetX_Nak__part__1Vsinv__22: assumes a1: "(\<exists> src. src\<le>N\<and>r=n_NI_Local_GetX_Nak__part__1 src)" and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__22 p__Inv4)" shows "invHoldForRule s f r (invariants N)" (is "?P1 s \<or> ?P2 s \<or> ?P3 s") proof - from a1 obtain src where a1:"src\<le>N\<and>r=n_NI_Local_GetX_Nak__part__1 src" apply fastforce done from a2 obtain p__Inv4 where a2:"p__Inv4\<le>N\<and>f=inv__22 p__Inv4" apply fastforce done have "(src=p__Inv4)\<or>(src~=p__Inv4)" apply (cut_tac a1 a2, auto) done moreover { assume b1: "(src=p__Inv4)" have "?P1 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume b1: "(src~=p__Inv4)" have "?P2 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } ultimately show "invHoldForRule s f r (invariants N)" by satx qed lemma n_NI_Local_GetX_Nak__part__2Vsinv__22: assumes a1: "(\<exists> src. src\<le>N\<and>r=n_NI_Local_GetX_Nak__part__2 src)" and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__22 p__Inv4)" shows "invHoldForRule s f r (invariants N)" (is "?P1 s \<or> ?P2 s \<or> ?P3 s") proof - from a1 obtain src where a1:"src\<le>N\<and>r=n_NI_Local_GetX_Nak__part__2 src" apply fastforce done from a2 obtain p__Inv4 where a2:"p__Inv4\<le>N\<and>f=inv__22 p__Inv4" apply fastforce done have "(src=p__Inv4)\<or>(src~=p__Inv4)" apply (cut_tac a1 a2, auto) done moreover { assume b1: "(src=p__Inv4)" have "?P1 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume b1: "(src~=p__Inv4)" have "?P2 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } ultimately show "invHoldForRule s f r (invariants N)" by satx qed lemma n_NI_Local_GetX_GetX__part__0Vsinv__22: assumes a1: "(\<exists> src. src\<le>N\<and>r=n_NI_Local_GetX_GetX__part__0 src)" and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__22 p__Inv4)" shows "invHoldForRule s f r (invariants N)" (is "?P1 s \<or> ?P2 s \<or> ?P3 s") proof - from a1 obtain src where a1:"src\<le>N\<and>r=n_NI_Local_GetX_GetX__part__0 src" apply fastforce done from a2 obtain p__Inv4 where a2:"p__Inv4\<le>N\<and>f=inv__22 p__Inv4" apply fastforce done have "(src=p__Inv4)\<or>(src~=p__Inv4)" apply (cut_tac a1 a2, auto) done moreover { assume b1: "(src=p__Inv4)" have "?P1 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume b1: "(src~=p__Inv4)" have "?P2 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } ultimately show "invHoldForRule s f r (invariants N)" by satx qed lemma n_NI_Local_GetX_GetX__part__1Vsinv__22: assumes a1: "(\<exists> src. src\<le>N\<and>r=n_NI_Local_GetX_GetX__part__1 src)" and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__22 p__Inv4)" shows "invHoldForRule s f r (invariants N)" (is "?P1 s \<or> ?P2 s \<or> ?P3 s") proof - from a1 obtain src where a1:"src\<le>N\<and>r=n_NI_Local_GetX_GetX__part__1 src" apply fastforce done from a2 obtain p__Inv4 where a2:"p__Inv4\<le>N\<and>f=inv__22 p__Inv4" apply fastforce done have "(src=p__Inv4)\<or>(src~=p__Inv4)" apply (cut_tac a1 a2, auto) done moreover { assume b1: "(src=p__Inv4)" have "?P1 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume b1: "(src~=p__Inv4)" have "?P2 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } ultimately show "invHoldForRule s f r (invariants N)" by satx qed lemma n_NI_Local_GetX_PutX_1Vsinv__22: assumes a1: "(\<exists> src. src\<le>N\<and>r=n_NI_Local_GetX_PutX_1 N src)" and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__22 p__Inv4)" shows "invHoldForRule s f r (invariants N)" (is "?P1 s \<or> ?P2 s \<or> ?P3 s") proof - from a1 obtain src where a1:"src\<le>N\<and>r=n_NI_Local_GetX_PutX_1 N src" apply fastforce done from a2 obtain p__Inv4 where a2:"p__Inv4\<le>N\<and>f=inv__22 p__Inv4" apply fastforce done have "(src=p__Inv4)\<or>(src~=p__Inv4)" apply (cut_tac a1 a2, auto) done moreover { assume b1: "(src=p__Inv4)" have "?P3 s" apply (cut_tac a1 a2 b1, simp, rule_tac x="(neg (andForm (eqn (IVar (Field (Field (Ident ''Sta'') ''HomeUniMsg'') ''Cmd'')) (Const UNI_Put)) (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''Dirty'')) (Const false))))" in exI, auto) done then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume b1: "(src~=p__Inv4)" have "?P2 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } ultimately show "invHoldForRule s f r (invariants N)" by satx qed lemma n_NI_Local_GetX_PutX_2Vsinv__22: assumes a1: "(\<exists> src. src\<le>N\<and>r=n_NI_Local_GetX_PutX_2 N src)" and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__22 p__Inv4)" shows "invHoldForRule s f r (invariants N)" (is "?P1 s \<or> ?P2 s \<or> ?P3 s") proof - from a1 obtain src where a1:"src\<le>N\<and>r=n_NI_Local_GetX_PutX_2 N src" apply fastforce done from a2 obtain p__Inv4 where a2:"p__Inv4\<le>N\<and>f=inv__22 p__Inv4" apply fastforce done have "(src=p__Inv4)\<or>(src~=p__Inv4)" apply (cut_tac a1 a2, auto) done moreover { assume b1: "(src=p__Inv4)" have "?P3 s" apply (cut_tac a1 a2 b1, simp, rule_tac x="(neg (andForm (eqn (IVar (Field (Field (Ident ''Sta'') ''HomeUniMsg'') ''Cmd'')) (Const UNI_Put)) (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''Dirty'')) (Const false))))" in exI, auto) done then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume b1: "(src~=p__Inv4)" have "?P2 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } ultimately show "invHoldForRule s f r (invariants N)" by satx qed lemma n_NI_Local_GetX_PutX_3Vsinv__22: assumes a1: "(\<exists> src. src\<le>N\<and>r=n_NI_Local_GetX_PutX_3 N src)" and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__22 p__Inv4)" shows "invHoldForRule s f r (invariants N)" (is "?P1 s \<or> ?P2 s \<or> ?P3 s") proof - from a1 obtain src where a1:"src\<le>N\<and>r=n_NI_Local_GetX_PutX_3 N src" apply fastforce done from a2 obtain p__Inv4 where a2:"p__Inv4\<le>N\<and>f=inv__22 p__Inv4" apply fastforce done have "(src=p__Inv4)\<or>(src~=p__Inv4)" apply (cut_tac a1 a2, auto) done moreover { assume b1: "(src=p__Inv4)" have "?P3 s" apply (cut_tac a1 a2 b1, simp, rule_tac x="(neg (andForm (eqn (IVar (Field (Field (Ident ''Sta'') ''HomeUniMsg'') ''Cmd'')) (Const UNI_Put)) (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''Dirty'')) (Const false))))" in exI, auto) done then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume b1: "(src~=p__Inv4)" have "?P2 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } ultimately show "invHoldForRule s f r (invariants N)" by satx qed lemma n_NI_Local_GetX_PutX_4Vsinv__22: assumes a1: "(\<exists> src. src\<le>N\<and>r=n_NI_Local_GetX_PutX_4 N src)" and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__22 p__Inv4)" shows "invHoldForRule s f r (invariants N)" (is "?P1 s \<or> ?P2 s \<or> ?P3 s") proof - from a1 obtain src where a1:"src\<le>N\<and>r=n_NI_Local_GetX_PutX_4 N src" apply fastforce done from a2 obtain p__Inv4 where a2:"p__Inv4\<le>N\<and>f=inv__22 p__Inv4" apply fastforce done have "(src=p__Inv4)\<or>(src~=p__Inv4)" apply (cut_tac a1 a2, auto) done moreover { assume b1: "(src=p__Inv4)" have "?P3 s" apply (cut_tac a1 a2 b1, simp, rule_tac x="(neg (andForm (eqn (IVar (Field (Field (Ident ''Sta'') ''HomeUniMsg'') ''Cmd'')) (Const UNI_Put)) (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''Dirty'')) (Const false))))" in exI, auto) done then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume b1: "(src~=p__Inv4)" have "?P2 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } ultimately show "invHoldForRule s f r (invariants N)" by satx qed lemma n_NI_Local_GetX_PutX_5Vsinv__22: assumes a1: "(\<exists> src. src\<le>N\<and>r=n_NI_Local_GetX_PutX_5 N src)" and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__22 p__Inv4)" shows "invHoldForRule s f r (invariants N)" (is "?P1 s \<or> ?P2 s \<or> ?P3 s") proof - from a1 obtain src where a1:"src\<le>N\<and>r=n_NI_Local_GetX_PutX_5 N src" apply fastforce done from a2 obtain p__Inv4 where a2:"p__Inv4\<le>N\<and>f=inv__22 p__Inv4" apply fastforce done have "(src=p__Inv4)\<or>(src~=p__Inv4)" apply (cut_tac a1 a2, auto) done moreover { assume b1: "(src=p__Inv4)" have "?P3 s" apply (cut_tac a1 a2 b1, simp, rule_tac x="(neg (andForm (eqn (IVar (Field (Field (Ident ''Sta'') ''HomeUniMsg'') ''Cmd'')) (Const UNI_Put)) (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''Dirty'')) (Const false))))" in exI, auto) done then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume b1: "(src~=p__Inv4)" have "?P2 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } ultimately show "invHoldForRule s f r (invariants N)" by satx qed lemma n_NI_Local_GetX_PutX_6Vsinv__22: assumes a1: "(\<exists> src. src\<le>N\<and>r=n_NI_Local_GetX_PutX_6 N src)" and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__22 p__Inv4)" shows "invHoldForRule s f r (invariants N)" (is "?P1 s \<or> ?P2 s \<or> ?P3 s") proof - from a1 obtain src where a1:"src\<le>N\<and>r=n_NI_Local_GetX_PutX_6 N src" apply fastforce done from a2 obtain p__Inv4 where a2:"p__Inv4\<le>N\<and>f=inv__22 p__Inv4" apply fastforce done have "(src=p__Inv4)\<or>(src~=p__Inv4)" apply (cut_tac a1 a2, auto) done moreover { assume b1: "(src=p__Inv4)" have "?P3 s" apply (cut_tac a1 a2 b1, simp, rule_tac x="(neg (andForm (eqn (IVar (Field (Field (Ident ''Sta'') ''HomeUniMsg'') ''Cmd'')) (Const UNI_Put)) (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''Dirty'')) (Const false))))" in exI, auto) done then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume b1: "(src~=p__Inv4)" have "?P2 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } ultimately show "invHoldForRule s f r (invariants N)" by satx qed lemma n_NI_Local_GetX_PutX_7__part__0Vsinv__22: assumes a1: "(\<exists> src. src\<le>N\<and>r=n_NI_Local_GetX_PutX_7__part__0 N src)" and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__22 p__Inv4)" shows "invHoldForRule s f r (invariants N)" (is "?P1 s \<or> ?P2 s \<or> ?P3 s") proof - from a1 obtain src where a1:"src\<le>N\<and>r=n_NI_Local_GetX_PutX_7__part__0 N src" apply fastforce done from a2 obtain p__Inv4 where a2:"p__Inv4\<le>N\<and>f=inv__22 p__Inv4" apply fastforce done have "(src=p__Inv4)\<or>(src~=p__Inv4)" apply (cut_tac a1 a2, auto) done moreover { assume b1: "(src=p__Inv4)" have "?P3 s" apply (cut_tac a1 a2 b1, simp, rule_tac x="(neg (andForm (eqn (IVar (Field (Field (Ident ''Sta'') ''HomeUniMsg'') ''Cmd'')) (Const UNI_Put)) (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''Dirty'')) (Const false))))" in exI, auto) done then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume b1: "(src~=p__Inv4)" have "?P2 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } ultimately show "invHoldForRule s f r (invariants N)" by satx qed lemma n_NI_Local_GetX_PutX_7__part__1Vsinv__22: assumes a1: "(\<exists> src. src\<le>N\<and>r=n_NI_Local_GetX_PutX_7__part__1 N src)" and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__22 p__Inv4)" shows "invHoldForRule s f r (invariants N)" (is "?P1 s \<or> ?P2 s \<or> ?P3 s") proof - from a1 obtain src where a1:"src\<le>N\<and>r=n_NI_Local_GetX_PutX_7__part__1 N src" apply fastforce done from a2 obtain p__Inv4 where a2:"p__Inv4\<le>N\<and>f=inv__22 p__Inv4" apply fastforce done have "(src=p__Inv4)\<or>(src~=p__Inv4)" apply (cut_tac a1 a2, auto) done moreover { assume b1: "(src=p__Inv4)" have "?P3 s" apply (cut_tac a1 a2 b1, simp, rule_tac x="(neg (andForm (eqn (IVar (Field (Field (Ident ''Sta'') ''HomeUniMsg'') ''Cmd'')) (Const UNI_Put)) (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''Dirty'')) (Const false))))" in exI, auto) done then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume b1: "(src~=p__Inv4)" have "?P2 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } ultimately show "invHoldForRule s f r (invariants N)" by satx qed lemma n_NI_Local_GetX_PutX_7_NODE_Get__part__0Vsinv__22: assumes a1: "(\<exists> src. src\<le>N\<and>r=n_NI_Local_GetX_PutX_7_NODE_Get__part__0 N src)" and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__22 p__Inv4)" shows "invHoldForRule s f r (invariants N)" (is "?P1 s \<or> ?P2 s \<or> ?P3 s") proof - from a1 obtain src where a1:"src\<le>N\<and>r=n_NI_Local_GetX_PutX_7_NODE_Get__part__0 N src" apply fastforce done from a2 obtain p__Inv4 where a2:"p__Inv4\<le>N\<and>f=inv__22 p__Inv4" apply fastforce done have "(src=p__Inv4)\<or>(src~=p__Inv4)" apply (cut_tac a1 a2, auto) done moreover { assume b1: "(src=p__Inv4)" have "?P3 s" apply (cut_tac a1 a2 b1, simp, rule_tac x="(neg (andForm (eqn (IVar (Field (Field (Ident ''Sta'') ''HomeUniMsg'') ''Cmd'')) (Const UNI_Put)) (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''Dirty'')) (Const false))))" in exI, auto) done then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume b1: "(src~=p__Inv4)" have "?P2 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } ultimately show "invHoldForRule s f r (invariants N)" by satx qed lemma n_NI_Local_GetX_PutX_7_NODE_Get__part__1Vsinv__22: assumes a1: "(\<exists> src. src\<le>N\<and>r=n_NI_Local_GetX_PutX_7_NODE_Get__part__1 N src)" and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__22 p__Inv4)" shows "invHoldForRule s f r (invariants N)" (is "?P1 s \<or> ?P2 s \<or> ?P3 s") proof - from a1 obtain src where a1:"src\<le>N\<and>r=n_NI_Local_GetX_PutX_7_NODE_Get__part__1 N src" apply fastforce done from a2 obtain p__Inv4 where a2:"p__Inv4\<le>N\<and>f=inv__22 p__Inv4" apply fastforce done have "(src=p__Inv4)\<or>(src~=p__Inv4)" apply (cut_tac a1 a2, auto) done moreover { assume b1: "(src=p__Inv4)" have "?P3 s" apply (cut_tac a1 a2 b1, simp, rule_tac x="(neg (andForm (eqn (IVar (Field (Field (Ident ''Sta'') ''HomeUniMsg'') ''Cmd'')) (Const UNI_Put)) (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''Dirty'')) (Const false))))" in exI, auto) done then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume b1: "(src~=p__Inv4)" have "?P2 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } ultimately show "invHoldForRule s f r (invariants N)" by satx qed lemma n_NI_Local_GetX_PutX_8_HomeVsinv__22: assumes a1: "(\<exists> src. src\<le>N\<and>r=n_NI_Local_GetX_PutX_8_Home N src)" and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__22 p__Inv4)" shows "invHoldForRule s f r (invariants N)" (is "?P1 s \<or> ?P2 s \<or> ?P3 s") proof - from a1 obtain src where a1:"src\<le>N\<and>r=n_NI_Local_GetX_PutX_8_Home N src" apply fastforce done from a2 obtain p__Inv4 where a2:"p__Inv4\<le>N\<and>f=inv__22 p__Inv4" apply fastforce done have "(src=p__Inv4)\<or>(src~=p__Inv4)" apply (cut_tac a1 a2, auto) done moreover { assume b1: "(src=p__Inv4)" have "?P3 s" apply (cut_tac a1 a2 b1, simp, rule_tac x="(neg (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''HomeShrSet'')) (Const true)))" in exI, auto) done then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume b1: "(src~=p__Inv4)" have "?P2 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } ultimately show "invHoldForRule s f r (invariants N)" by satx qed lemma n_NI_Local_GetX_PutX_8_Home_NODE_GetVsinv__22: assumes a1: "(\<exists> src. src\<le>N\<and>r=n_NI_Local_GetX_PutX_8_Home_NODE_Get N src)" and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__22 p__Inv4)" shows "invHoldForRule s f r (invariants N)" (is "?P1 s \<or> ?P2 s \<or> ?P3 s") proof - from a1 obtain src where a1:"src\<le>N\<and>r=n_NI_Local_GetX_PutX_8_Home_NODE_Get N src" apply fastforce done from a2 obtain p__Inv4 where a2:"p__Inv4\<le>N\<and>f=inv__22 p__Inv4" apply fastforce done have "(src=p__Inv4)\<or>(src~=p__Inv4)" apply (cut_tac a1 a2, auto) done moreover { assume b1: "(src=p__Inv4)" have "?P3 s" apply (cut_tac a1 a2 b1, simp, rule_tac x="(neg (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''HomeShrSet'')) (Const true)))" in exI, auto) done then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume b1: "(src~=p__Inv4)" have "?P2 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } ultimately show "invHoldForRule s f r (invariants N)" by satx qed lemma n_NI_Local_GetX_PutX_8Vsinv__22: assumes a1: "(\<exists> src pp. src\<le>N\<and>pp\<le>N\<and>src~=pp\<and>r=n_NI_Local_GetX_PutX_8 N src pp)" and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__22 p__Inv4)" shows "invHoldForRule s f r (invariants N)" (is "?P1 s \<or> ?P2 s \<or> ?P3 s") proof - from a1 obtain src pp where a1:"src\<le>N\<and>pp\<le>N\<and>src~=pp\<and>r=n_NI_Local_GetX_PutX_8 N src pp" apply fastforce done from a2 obtain p__Inv4 where a2:"p__Inv4\<le>N\<and>f=inv__22 p__Inv4" apply fastforce done have "(src=p__Inv4\<and>pp~=p__Inv4)\<or>(src~=p__Inv4\<and>pp=p__Inv4)\<or>(src~=p__Inv4\<and>pp~=p__Inv4)" apply (cut_tac a1 a2, auto) done moreover { assume b1: "(src=p__Inv4\<and>pp~=p__Inv4)" have "?P3 s" apply (cut_tac a1 a2 b1, simp, rule_tac x="(neg (andForm (eqn (IVar (Field (Field (Ident ''Sta'') ''HomeUniMsg'') ''Cmd'')) (Const UNI_Put)) (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''Dirty'')) (Const false))))" in exI, auto) done then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume b1: "(src~=p__Inv4\<and>pp=p__Inv4)" have "?P2 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume b1: "(src~=p__Inv4\<and>pp~=p__Inv4)" have "?P2 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } ultimately show "invHoldForRule s f r (invariants N)" by satx qed lemma n_NI_Local_GetX_PutX_8_NODE_GetVsinv__22: assumes a1: "(\<exists> src pp. src\<le>N\<and>pp\<le>N\<and>src~=pp\<and>r=n_NI_Local_GetX_PutX_8_NODE_Get N src pp)" and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__22 p__Inv4)" shows "invHoldForRule s f r (invariants N)" (is "?P1 s \<or> ?P2 s \<or> ?P3 s") proof - from a1 obtain src pp where a1:"src\<le>N\<and>pp\<le>N\<and>src~=pp\<and>r=n_NI_Local_GetX_PutX_8_NODE_Get N src pp" apply fastforce done from a2 obtain p__Inv4 where a2:"p__Inv4\<le>N\<and>f=inv__22 p__Inv4" apply fastforce done have "(src=p__Inv4\<and>pp~=p__Inv4)\<or>(src~=p__Inv4\<and>pp=p__Inv4)\<or>(src~=p__Inv4\<and>pp~=p__Inv4)" apply (cut_tac a1 a2, auto) done moreover { assume b1: "(src=p__Inv4\<and>pp~=p__Inv4)" have "?P3 s" apply (cut_tac a1 a2 b1, simp, rule_tac x="(neg (andForm (eqn (IVar (Field (Field (Ident ''Sta'') ''HomeUniMsg'') ''Cmd'')) (Const UNI_Put)) (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''Dirty'')) (Const false))))" in exI, auto) done then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume b1: "(src~=p__Inv4\<and>pp=p__Inv4)" have "?P2 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume b1: "(src~=p__Inv4\<and>pp~=p__Inv4)" have "?P2 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } ultimately show "invHoldForRule s f r (invariants N)" by satx qed lemma n_NI_Local_GetX_PutX_9__part__0Vsinv__22: assumes a1: "(\<exists> src. src\<le>N\<and>r=n_NI_Local_GetX_PutX_9__part__0 N src)" and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__22 p__Inv4)" shows "invHoldForRule s f r (invariants N)" (is "?P1 s \<or> ?P2 s \<or> ?P3 s") proof - from a1 obtain src where a1:"src\<le>N\<and>r=n_NI_Local_GetX_PutX_9__part__0 N src" apply fastforce done from a2 obtain p__Inv4 where a2:"p__Inv4\<le>N\<and>f=inv__22 p__Inv4" apply fastforce done have "(src=p__Inv4)\<or>(src~=p__Inv4)" apply (cut_tac a1 a2, auto) done moreover { assume b1: "(src=p__Inv4)" have "?P3 s" apply (cut_tac a1 a2 b1, simp, rule_tac x="(neg (andForm (eqn (IVar (Field (Field (Ident ''Sta'') ''HomeUniMsg'') ''Cmd'')) (Const UNI_Put)) (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''Dirty'')) (Const false))))" in exI, auto) done then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume b1: "(src~=p__Inv4)" have "?P2 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } ultimately show "invHoldForRule s f r (invariants N)" by satx qed lemma n_NI_Local_GetX_PutX_9__part__1Vsinv__22: assumes a1: "(\<exists> src. src\<le>N\<and>r=n_NI_Local_GetX_PutX_9__part__1 N src)" and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__22 p__Inv4)" shows "invHoldForRule s f r (invariants N)" (is "?P1 s \<or> ?P2 s \<or> ?P3 s") proof - from a1 obtain src where a1:"src\<le>N\<and>r=n_NI_Local_GetX_PutX_9__part__1 N src" apply fastforce done from a2 obtain p__Inv4 where a2:"p__Inv4\<le>N\<and>f=inv__22 p__Inv4" apply fastforce done have "(src=p__Inv4)\<or>(src~=p__Inv4)" apply (cut_tac a1 a2, auto) done moreover { assume b1: "(src=p__Inv4)" have "?P3 s" apply (cut_tac a1 a2 b1, simp, rule_tac x="(neg (andForm (eqn (IVar (Field (Field (Ident ''Sta'') ''HomeUniMsg'') ''Cmd'')) (Const UNI_Put)) (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''Dirty'')) (Const false))))" in exI, auto) done then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume b1: "(src~=p__Inv4)" have "?P2 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } ultimately show "invHoldForRule s f r (invariants N)" by satx qed lemma n_NI_Local_GetX_PutX_10_HomeVsinv__22: assumes a1: "(\<exists> src. src\<le>N\<and>r=n_NI_Local_GetX_PutX_10_Home N src)" and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__22 p__Inv4)" shows "invHoldForRule s f r (invariants N)" (is "?P1 s \<or> ?P2 s \<or> ?P3 s") proof - from a1 obtain src where a1:"src\<le>N\<and>r=n_NI_Local_GetX_PutX_10_Home N src" apply fastforce done from a2 obtain p__Inv4 where a2:"p__Inv4\<le>N\<and>f=inv__22 p__Inv4" apply fastforce done have "(src=p__Inv4)\<or>(src~=p__Inv4)" apply (cut_tac a1 a2, auto) done moreover { assume b1: "(src=p__Inv4)" have "?P3 s" apply (cut_tac a1 a2 b1, simp, rule_tac x="(neg (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''HomeShrSet'')) (Const true)))" in exI, auto) done then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume b1: "(src~=p__Inv4)" have "?P2 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } ultimately show "invHoldForRule s f r (invariants N)" by satx qed lemma n_NI_Local_GetX_PutX_10Vsinv__22: assumes a1: "(\<exists> src pp. src\<le>N\<and>pp\<le>N\<and>src~=pp\<and>r=n_NI_Local_GetX_PutX_10 N src pp)" and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__22 p__Inv4)" shows "invHoldForRule s f r (invariants N)" (is "?P1 s \<or> ?P2 s \<or> ?P3 s") proof - from a1 obtain src pp where a1:"src\<le>N\<and>pp\<le>N\<and>src~=pp\<and>r=n_NI_Local_GetX_PutX_10 N src pp" apply fastforce done from a2 obtain p__Inv4 where a2:"p__Inv4\<le>N\<and>f=inv__22 p__Inv4" apply fastforce done have "(src=p__Inv4\<and>pp~=p__Inv4)\<or>(src~=p__Inv4\<and>pp=p__Inv4)\<or>(src~=p__Inv4\<and>pp~=p__Inv4)" apply (cut_tac a1 a2, auto) done moreover { assume b1: "(src=p__Inv4\<and>pp~=p__Inv4)" have "?P3 s" apply (cut_tac a1 a2 b1, simp, rule_tac x="(neg (andForm (eqn (IVar (Field (Field (Ident ''Sta'') ''HomeUniMsg'') ''Cmd'')) (Const UNI_Put)) (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''Dirty'')) (Const false))))" in exI, auto) done then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume b1: "(src~=p__Inv4\<and>pp=p__Inv4)" have "?P2 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume b1: "(src~=p__Inv4\<and>pp~=p__Inv4)" have "?P2 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } ultimately show "invHoldForRule s f r (invariants N)" by satx qed lemma n_NI_Local_GetX_PutX_11Vsinv__22: assumes a1: "(\<exists> src. src\<le>N\<and>r=n_NI_Local_GetX_PutX_11 N src)" and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__22 p__Inv4)" shows "invHoldForRule s f r (invariants N)" (is "?P1 s \<or> ?P2 s \<or> ?P3 s") proof - from a1 obtain src where a1:"src\<le>N\<and>r=n_NI_Local_GetX_PutX_11 N src" apply fastforce done from a2 obtain p__Inv4 where a2:"p__Inv4\<le>N\<and>f=inv__22 p__Inv4" apply fastforce done have "(src=p__Inv4)\<or>(src~=p__Inv4)" apply (cut_tac a1 a2, auto) done moreover { assume b1: "(src=p__Inv4)" have "?P3 s" apply (cut_tac a1 a2 b1, simp, rule_tac x="(neg (andForm (eqn (IVar (Field (Field (Ident ''Sta'') ''HomeUniMsg'') ''Cmd'')) (Const UNI_Put)) (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''Local'')) (Const true))))" in exI, auto) done then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume b1: "(src~=p__Inv4)" have "?P2 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } ultimately show "invHoldForRule s f r (invariants N)" by satx qed lemma n_NI_Remote_GetX_NakVsinv__22: assumes a1: "(\<exists> src dst. src\<le>N\<and>dst\<le>N\<and>src~=dst\<and>r=n_NI_Remote_GetX_Nak src dst)" and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__22 p__Inv4)" shows "invHoldForRule s f r (invariants N)" (is "?P1 s \<or> ?P2 s \<or> ?P3 s") proof - from a1 obtain src dst where a1:"src\<le>N\<and>dst\<le>N\<and>src~=dst\<and>r=n_NI_Remote_GetX_Nak src dst" apply fastforce done from a2 obtain p__Inv4 where a2:"p__Inv4\<le>N\<and>f=inv__22 p__Inv4" apply fastforce done have "(src=p__Inv4\<and>dst~=p__Inv4)\<or>(src~=p__Inv4\<and>dst=p__Inv4)\<or>(src~=p__Inv4\<and>dst~=p__Inv4)" apply (cut_tac a1 a2, auto) done moreover { assume b1: "(src=p__Inv4\<and>dst~=p__Inv4)" have "?P1 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume b1: "(src~=p__Inv4\<and>dst=p__Inv4)" have "?P2 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume b1: "(src~=p__Inv4\<and>dst~=p__Inv4)" have "?P2 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } ultimately show "invHoldForRule s f r (invariants N)" by satx qed lemma n_NI_Remote_GetX_Nak_HomeVsinv__22: assumes a1: "(\<exists> dst. dst\<le>N\<and>r=n_NI_Remote_GetX_Nak_Home dst)" and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__22 p__Inv4)" shows "invHoldForRule s f r (invariants N)" (is "?P1 s \<or> ?P2 s \<or> ?P3 s") proof - from a1 obtain dst where a1:"dst\<le>N\<and>r=n_NI_Remote_GetX_Nak_Home dst" apply fastforce done from a2 obtain p__Inv4 where a2:"p__Inv4\<le>N\<and>f=inv__22 p__Inv4" apply fastforce done have "(dst=p__Inv4)\<or>(dst~=p__Inv4)" apply (cut_tac a1 a2, auto) done moreover { assume b1: "(dst=p__Inv4)" have "?P1 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume b1: "(dst~=p__Inv4)" have "?P1 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } ultimately show "invHoldForRule s f r (invariants N)" by satx qed lemma n_NI_Remote_GetX_PutXVsinv__22: assumes a1: "(\<exists> src dst. src\<le>N\<and>dst\<le>N\<and>src~=dst\<and>r=n_NI_Remote_GetX_PutX src dst)" and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__22 p__Inv4)" shows "invHoldForRule s f r (invariants N)" (is "?P1 s \<or> ?P2 s \<or> ?P3 s") proof - from a1 obtain src dst where a1:"src\<le>N\<and>dst\<le>N\<and>src~=dst\<and>r=n_NI_Remote_GetX_PutX src dst" apply fastforce done from a2 obtain p__Inv4 where a2:"p__Inv4\<le>N\<and>f=inv__22 p__Inv4" apply fastforce done have "(src=p__Inv4\<and>dst~=p__Inv4)\<or>(src~=p__Inv4\<and>dst=p__Inv4)\<or>(src~=p__Inv4\<and>dst~=p__Inv4)" apply (cut_tac a1 a2, auto) done moreover { assume b1: "(src=p__Inv4\<and>dst~=p__Inv4)" have "?P3 s" apply (cut_tac a1 a2 b1, simp, rule_tac x="(neg (andForm (eqn (IVar (Field (Para (Field (Ident ''Sta'') ''Proc'') dst) ''CacheState'')) (Const CACHE_E)) (eqn (IVar (Field (Field (Ident ''Sta'') ''HomeUniMsg'') ''Cmd'')) (Const UNI_Put))))" in exI, auto) done then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume b1: "(src~=p__Inv4\<and>dst=p__Inv4)" have "?P2 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume b1: "(src~=p__Inv4\<and>dst~=p__Inv4)" have "?P2 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } ultimately show "invHoldForRule s f r (invariants N)" by satx qed lemma n_NI_Remote_GetX_PutX_HomeVsinv__22: assumes a1: "(\<exists> dst. dst\<le>N\<and>r=n_NI_Remote_GetX_PutX_Home dst)" and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__22 p__Inv4)" shows "invHoldForRule s f r (invariants N)" (is "?P1 s \<or> ?P2 s \<or> ?P3 s") proof - from a1 obtain dst where a1:"dst\<le>N\<and>r=n_NI_Remote_GetX_PutX_Home dst" apply fastforce done from a2 obtain p__Inv4 where a2:"p__Inv4\<le>N\<and>f=inv__22 p__Inv4" apply fastforce done have "(dst=p__Inv4)\<or>(dst~=p__Inv4)" apply (cut_tac a1 a2, auto) done moreover { assume b1: "(dst=p__Inv4)" have "?P1 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume b1: "(dst~=p__Inv4)" have "?P1 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } ultimately show "invHoldForRule s f r (invariants N)" by satx qed lemma n_NI_Remote_PutVsinv__22: assumes a1: "(\<exists> dst. dst\<le>N\<and>r=n_NI_Remote_Put dst)" and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__22 p__Inv4)" shows "invHoldForRule s f r (invariants N)" (is "?P1 s \<or> ?P2 s \<or> ?P3 s") proof - from a1 obtain dst where a1:"dst\<le>N\<and>r=n_NI_Remote_Put dst" apply fastforce done from a2 obtain p__Inv4 where a2:"p__Inv4\<le>N\<and>f=inv__22 p__Inv4" apply fastforce done have "(dst=p__Inv4)\<or>(dst~=p__Inv4)" apply (cut_tac a1 a2, auto) done moreover { assume b1: "(dst=p__Inv4)" have "?P1 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume b1: "(dst~=p__Inv4)" have "?P2 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } ultimately show "invHoldForRule s f r (invariants N)" by satx qed lemma n_NI_Remote_PutXVsinv__22: assumes a1: "(\<exists> dst. dst\<le>N\<and>r=n_NI_Remote_PutX dst)" and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__22 p__Inv4)" shows "invHoldForRule s f r (invariants N)" (is "?P1 s \<or> ?P2 s \<or> ?P3 s") proof - from a1 obtain dst where a1:"dst\<le>N\<and>r=n_NI_Remote_PutX dst" apply fastforce done from a2 obtain p__Inv4 where a2:"p__Inv4\<le>N\<and>f=inv__22 p__Inv4" apply fastforce done have "(dst=p__Inv4)\<or>(dst~=p__Inv4)" apply (cut_tac a1 a2, auto) done moreover { assume b1: "(dst=p__Inv4)" have "?P1 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume b1: "(dst~=p__Inv4)" have "?P2 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } ultimately show "invHoldForRule s f r (invariants N)" by satx qed lemma n_PI_Local_Get_GetVsinv__22: assumes a1: "(r=n_PI_Local_Get_Get )" and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__22 p__Inv4)" shows "invHoldForRule s f r (invariants N)" (is "?P1 s \<or> ?P2 s \<or> ?P3 s") proof - from a2 obtain p__Inv4 where a2:"p__Inv4\<le>N\<and>f=inv__22 p__Inv4" apply fastforce done have "?P1 s" proof(cut_tac a1 a2 , auto) qed then show "invHoldForRule s f r (invariants N)" by auto qed lemma n_PI_Local_GetX_GetX__part__0Vsinv__22: assumes a1: "(r=n_PI_Local_GetX_GetX__part__0 )" and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__22 p__Inv4)" shows "invHoldForRule s f r (invariants N)" (is "?P1 s \<or> ?P2 s \<or> ?P3 s") proof - from a2 obtain p__Inv4 where a2:"p__Inv4\<le>N\<and>f=inv__22 p__Inv4" apply fastforce done have "?P1 s" proof(cut_tac a1 a2 , auto) qed then show "invHoldForRule s f r (invariants N)" by auto qed lemma n_PI_Local_GetX_GetX__part__1Vsinv__22: assumes a1: "(r=n_PI_Local_GetX_GetX__part__1 )" and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__22 p__Inv4)" shows "invHoldForRule s f r (invariants N)" (is "?P1 s \<or> ?P2 s \<or> ?P3 s") proof - from a2 obtain p__Inv4 where a2:"p__Inv4\<le>N\<and>f=inv__22 p__Inv4" apply fastforce done have "?P1 s" proof(cut_tac a1 a2 , auto) qed then show "invHoldForRule s f r (invariants N)" by auto qed lemma n_NI_Nak_HomeVsinv__22: assumes a1: "(r=n_NI_Nak_Home )" and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__22 p__Inv4)" shows "invHoldForRule s f r (invariants N)" (is "?P1 s \<or> ?P2 s \<or> ?P3 s") proof - from a2 obtain p__Inv4 where a2:"p__Inv4\<le>N\<and>f=inv__22 p__Inv4" apply fastforce done have "?P1 s" proof(cut_tac a1 a2 , auto) qed then show "invHoldForRule s f r (invariants N)" by auto qed lemma n_NI_Local_PutVsinv__22: assumes a1: "(r=n_NI_Local_Put )" and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__22 p__Inv4)" shows "invHoldForRule s f r (invariants N)" (is "?P1 s \<or> ?P2 s \<or> ?P3 s") proof - from a2 obtain p__Inv4 where a2:"p__Inv4\<le>N\<and>f=inv__22 p__Inv4" apply fastforce done have "?P1 s" proof(cut_tac a1 a2 , auto) qed then show "invHoldForRule s f r (invariants N)" by auto qed lemma n_NI_Local_PutXAcksDoneVsinv__22: assumes a1: "(r=n_NI_Local_PutXAcksDone )" and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__22 p__Inv4)" shows "invHoldForRule s f r (invariants N)" (is "?P1 s \<or> ?P2 s \<or> ?P3 s") proof - from a2 obtain p__Inv4 where a2:"p__Inv4\<le>N\<and>f=inv__22 p__Inv4" apply fastforce done have "?P1 s" proof(cut_tac a1 a2 , auto) qed then show "invHoldForRule s f r (invariants N)" by auto qed lemma n_PI_Local_GetX_PutX__part__0Vsinv__22: assumes a1: "r=n_PI_Local_GetX_PutX__part__0 " and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__22 p__Inv4)" shows "invHoldForRule s f r (invariants N)" apply (rule noEffectOnRule, cut_tac a1 a2, auto) done lemma n_NI_WbVsinv__22: assumes a1: "r=n_NI_Wb " and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__22 p__Inv4)" shows "invHoldForRule s f r (invariants N)" apply (rule noEffectOnRule, cut_tac a1 a2, auto) done lemma n_NI_InvAck_3Vsinv__22: assumes a1: "\<exists> src. src\<le>N\<and>r=n_NI_InvAck_3 N src" and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__22 p__Inv4)" shows "invHoldForRule s f r (invariants N)" apply (rule noEffectOnRule, cut_tac a1 a2, auto) done lemma n_NI_InvAck_1Vsinv__22: assumes a1: "\<exists> src. src\<le>N\<and>r=n_NI_InvAck_1 N src" and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__22 p__Inv4)" shows "invHoldForRule s f r (invariants N)" apply (rule noEffectOnRule, cut_tac a1 a2, auto) done lemma n_PI_Remote_ReplaceVsinv__22: assumes a1: "\<exists> src. src\<le>N\<and>r=n_PI_Remote_Replace src" and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__22 p__Inv4)" shows "invHoldForRule s f r (invariants N)" apply (rule noEffectOnRule, cut_tac a1 a2, auto) done lemma n_PI_Local_ReplaceVsinv__22: assumes a1: "r=n_PI_Local_Replace " and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__22 p__Inv4)" shows "invHoldForRule s f r (invariants N)" apply (rule noEffectOnRule, cut_tac a1 a2, auto) done lemma n_NI_InvAck_existsVsinv__22: assumes a1: "\<exists> src pp. src\<le>N\<and>pp\<le>N\<and>src~=pp\<and>r=n_NI_InvAck_exists src pp" and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__22 p__Inv4)" shows "invHoldForRule s f r (invariants N)" apply (rule noEffectOnRule, cut_tac a1 a2, auto) done lemma n_PI_Remote_PutXVsinv__22: assumes a1: "\<exists> dst. dst\<le>N\<and>r=n_PI_Remote_PutX dst" and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__22 p__Inv4)" shows "invHoldForRule s f r (invariants N)" apply (rule noEffectOnRule, cut_tac a1 a2, auto) done lemma n_NI_InvVsinv__22: assumes a1: "\<exists> dst. dst\<le>N\<and>r=n_NI_Inv dst" and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__22 p__Inv4)" shows "invHoldForRule s f r (invariants N)" apply (rule noEffectOnRule, cut_tac a1 a2, auto) done lemma n_PI_Local_PutXVsinv__22: assumes a1: "r=n_PI_Local_PutX " and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__22 p__Inv4)" shows "invHoldForRule s f r (invariants N)" apply (rule noEffectOnRule, cut_tac a1 a2, auto) done lemma n_PI_Local_Get_PutVsinv__22: assumes a1: "r=n_PI_Local_Get_Put " and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__22 p__Inv4)" shows "invHoldForRule s f r (invariants N)" apply (rule noEffectOnRule, cut_tac a1 a2, auto) done lemma n_NI_ShWbVsinv__22: assumes a1: "r=n_NI_ShWb N " and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__22 p__Inv4)" shows "invHoldForRule s f r (invariants N)" apply (rule noEffectOnRule, cut_tac a1 a2, auto) done lemma n_PI_Local_GetX_PutX_HeadVld__part__0Vsinv__22: assumes a1: "r=n_PI_Local_GetX_PutX_HeadVld__part__0 N " and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__22 p__Inv4)" shows "invHoldForRule s f r (invariants N)" apply (rule noEffectOnRule, cut_tac a1 a2, auto) done lemma n_NI_ReplaceVsinv__22: assumes a1: "\<exists> src. src\<le>N\<and>r=n_NI_Replace src" and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__22 p__Inv4)" shows "invHoldForRule s f r (invariants N)" apply (rule noEffectOnRule, cut_tac a1 a2, auto) done lemma n_PI_Local_GetX_PutX__part__1Vsinv__22: assumes a1: "r=n_PI_Local_GetX_PutX__part__1 " and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__22 p__Inv4)" shows "invHoldForRule s f r (invariants N)" apply (rule noEffectOnRule, cut_tac a1 a2, auto) done lemma n_NI_InvAck_exists_HomeVsinv__22: assumes a1: "\<exists> src. src\<le>N\<and>r=n_NI_InvAck_exists_Home src" and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__22 p__Inv4)" shows "invHoldForRule s f r (invariants N)" apply (rule noEffectOnRule, cut_tac a1 a2, auto) done lemma n_NI_Replace_HomeVsinv__22: assumes a1: "r=n_NI_Replace_Home " and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__22 p__Inv4)" shows "invHoldForRule s f r (invariants N)" apply (rule noEffectOnRule, cut_tac a1 a2, auto) done lemma n_NI_Nak_ClearVsinv__22: assumes a1: "r=n_NI_Nak_Clear " and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__22 p__Inv4)" shows "invHoldForRule s f r (invariants N)" apply (rule noEffectOnRule, cut_tac a1 a2, auto) done lemma n_NI_InvAck_2Vsinv__22: assumes a1: "\<exists> src. src\<le>N\<and>r=n_NI_InvAck_2 N src" and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__22 p__Inv4)" shows "invHoldForRule s f r (invariants N)" apply (rule noEffectOnRule, cut_tac a1 a2, auto) done lemma n_PI_Local_GetX_PutX_HeadVld__part__1Vsinv__22: assumes a1: "r=n_PI_Local_GetX_PutX_HeadVld__part__1 N " and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__22 p__Inv4)" shows "invHoldForRule s f r (invariants N)" apply (rule noEffectOnRule, cut_tac a1 a2, auto) done lemma n_NI_FAckVsinv__22: assumes a1: "r=n_NI_FAck " and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__22 p__Inv4)" shows "invHoldForRule s f r (invariants N)" apply (rule noEffectOnRule, cut_tac a1 a2, auto) done end
module Minecraft.Core %default total -- Forward declaractions for potential recursive interfaces namespace Block public export data Block : (self : Type) -> Type namespace Entity public export data Entity : (self : Type) -> Type namespace Pickup public export data Pickup : (self : Type) -> Type namespace Item public export data Item : (self : Type) -> Type namespace Put public export data Put : (self : Type) -> Type namespace Tangible public export data Tangible : (self : Type) -> Type
/* rng/mrg.c * * Copyright (C) 1996, 1997, 1998, 1999, 2000 James Theiler, Brian Gough * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or (at * your option) any later version. * * This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ #include <config.h> #include <stdlib.h> #include <gsl/gsl_rng.h> /* This is a fifth-order multiple recursive generator. The sequence is, x_n = (a_1 x_{n-1} + a_5 x_{n-5}) mod m with a_1 = 107374182, a_2 = a_3 = a_4 = 0, a_5 = 104480 and m = 2^31-1. We initialize the generator with x_n = s_n MOD m for n = 1..5, where s_n = (69069 * s_{n-1}) mod 2^32, and s_0 = s is the user-supplied seed. NOTE: According to the paper the seeds must lie in the range [0, 2^31 - 2] with at least one non-zero value -- our seeding procedure satisfies these constraints. We then use 6 iterations of the generator to "warm up" the internal state. With this initialization procedure the theoretical value of z_{10006} is 2064828650 for s = 1. The subscript 10006 means (1) seed the generator with s = 1, (2) do the 6 warm-up iterations that are part of the seeding process, (3) then do 10000 actual iterations. The period of this generator is about 2^155. From: P. L'Ecuyer, F. Blouin, and R. Coutre, "A search for good multiple recursive random number generators", ACM Transactions on Modeling and Computer Simulation 3, 87-98 (1993). */ static inline unsigned long int mrg_get (void *vstate); static double mrg_get_double (void *vstate); static void mrg_set (void *state, unsigned long int s); static const long int m = 2147483647; static const long int a1 = 107374182, q1 = 20, r1 = 7; static const long int a5 = 104480, q5 = 20554, r5 = 1727; typedef struct { long int x1, x2, x3, x4, x5; } mrg_state_t; static inline unsigned long int mrg_get (void *vstate) { mrg_state_t *state = (mrg_state_t *) vstate; long int p1, h1, p5, h5; h5 = state->x5 / q5; p5 = a5 * (state->x5 - h5 * q5) - h5 * r5; if (p5 > 0) p5 -= m; h1 = state->x1 / q1; p1 = a1 * (state->x1 - h1 * q1) - h1 * r1; if (p1 < 0) p1 += m; state->x5 = state->x4; state->x4 = state->x3; state->x3 = state->x2; state->x2 = state->x1; state->x1 = p1 + p5; if (state->x1 < 0) state->x1 += m; return state->x1; } static double mrg_get_double (void *vstate) { return mrg_get (vstate) / 2147483647.0 ; } static void mrg_set (void *vstate, unsigned long int s) { /* An entirely adhoc way of seeding! This does **not** come from L'Ecuyer et al */ mrg_state_t *state = (mrg_state_t *) vstate; if (s == 0) s = 1; /* default seed is 1 */ #define LCG(n) ((69069 * n) & 0xffffffffUL) s = LCG (s); state->x1 = s % m; s = LCG (s); state->x2 = s % m; s = LCG (s); state->x3 = s % m; s = LCG (s); state->x4 = s % m; s = LCG (s); state->x5 = s % m; /* "warm it up" with at least 5 calls to go through all the x values */ mrg_get (state); mrg_get (state); mrg_get (state); mrg_get (state); mrg_get (state); mrg_get (state); return; } static const gsl_rng_type mrg_type = {"mrg", /* name */ 2147483646, /* RAND_MAX */ 0, /* RAND_MIN */ sizeof (mrg_state_t), &mrg_set, &mrg_get, &mrg_get_double}; const gsl_rng_type *gsl_rng_mrg = &mrg_type;
For those of you interested in becoming part of the project here is a guide to digging out the data. If your interest is in a particular League then please contact us first so that we can let you know what we've already got. Here is a brief guide to what we are looking for and where to look; with apologies if you are already an experienced researcher! These can be found normally in newspapers covering April/May but be aware that the season may be extended due to bad weather. Also it has been known that a paper will print a Final table at the time of the AGM which may well be in July. Be aware also that tables may appear on non sports pages or as an extra column elsewhere in the paper. These would be the last table published for that season but with apparently outstanding fixtures. Check that the table is not FINAL as some seasons finished with fixtures not completed. If the season continues beyond the table published, we would ask that you check and note the results of fixtures played and update the table manually. • In both the above cases, please check the clubs participating at the beginning of a season as this, in comparing with the final table, will indicate any resignations/evictions during the season. In this unfortunate instance we would request you try and find the name of the champions and, by tracking fixtures, list the clubs who participated during that season. We are looking initially at the setting up of the league and need a summary of where, when and by whom the League was formed. It may well be that a book exists on the history of the League which will cover this and a summary may be constructed from this. Likewise, if the League has disbanded a summary of this should be included in the history text. Should the period you need to cover be considerable we would appreciate it if you would send updates now and again rather than the complete package at the end, especially if you are unable to provide the data on Excel for tables and Word (or compatible) for the history. Thank you once more for your interest and we look forward to hearing from you. Please do not hesitate to contact Mel with any queries. Contact details can be found by clicking this link.
[GOAL] m : Type u_1 n : Type u_2 inst✝⁴ : DecidableEq n inst✝³ : Fintype n inst✝² : DecidableEq m inst✝¹ : Fintype m R : Type v inst✝ : CommRing R M : Matrix n n R ⊢ det M = ∑ σ : Perm n, ↑↑(↑sign σ) * ∏ i : n, M (↑σ i) i [PROOFSTEP] simp [det_apply, Units.smul_def] [GOAL] m : Type u_1 n : Type u_2 inst✝⁴ : DecidableEq n inst✝³ : Fintype n inst✝² : DecidableEq m inst✝¹ : Fintype m R : Type v inst✝ : CommRing R d : n → R ⊢ det (diagonal d) = ∏ i : n, d i [PROOFSTEP] rw [det_apply'] [GOAL] m : Type u_1 n : Type u_2 inst✝⁴ : DecidableEq n inst✝³ : Fintype n inst✝² : DecidableEq m inst✝¹ : Fintype m R : Type v inst✝ : CommRing R d : n → R ⊢ ∑ σ : Perm n, ↑↑(↑sign σ) * ∏ i : n, diagonal d (↑σ i) i = ∏ i : n, d i [PROOFSTEP] refine' (Finset.sum_eq_single 1 _ _).trans _ [GOAL] case refine'_1 m : Type u_1 n : Type u_2 inst✝⁴ : DecidableEq n inst✝³ : Fintype n inst✝² : DecidableEq m inst✝¹ : Fintype m R : Type v inst✝ : CommRing R d : n → R ⊢ ∀ (b : Perm n), b ∈ univ → b ≠ 1 → ↑↑(↑sign b) * ∏ i : n, diagonal d (↑b i) i = 0 [PROOFSTEP] rintro σ - h2 [GOAL] case refine'_1 m : Type u_1 n : Type u_2 inst✝⁴ : DecidableEq n inst✝³ : Fintype n inst✝² : DecidableEq m inst✝¹ : Fintype m R : Type v inst✝ : CommRing R d : n → R σ : Perm n h2 : σ ≠ 1 ⊢ ↑↑(↑sign σ) * ∏ i : n, diagonal d (↑σ i) i = 0 [PROOFSTEP] cases' not_forall.1 (mt Equiv.ext h2) with x h3 [GOAL] case refine'_1.intro m : Type u_1 n : Type u_2 inst✝⁴ : DecidableEq n inst✝³ : Fintype n inst✝² : DecidableEq m inst✝¹ : Fintype m R : Type v inst✝ : CommRing R d : n → R σ : Perm n h2 : σ ≠ 1 x : n h3 : ¬↑σ x = ↑1 x ⊢ ↑↑(↑sign σ) * ∏ i : n, diagonal d (↑σ i) i = 0 [PROOFSTEP] convert mul_zero (ε σ) [GOAL] case h.e'_2.h.e'_6 m : Type u_1 n : Type u_2 inst✝⁴ : DecidableEq n inst✝³ : Fintype n inst✝² : DecidableEq m inst✝¹ : Fintype m R : Type v inst✝ : CommRing R d : n → R σ : Perm n h2 : σ ≠ 1 x : n h3 : ¬↑σ x = ↑1 x ⊢ ∏ i : n, diagonal d (↑σ i) i = 0 [PROOFSTEP] apply Finset.prod_eq_zero (mem_univ x) [GOAL] case h.e'_2.h.e'_6 m : Type u_1 n : Type u_2 inst✝⁴ : DecidableEq n inst✝³ : Fintype n inst✝² : DecidableEq m inst✝¹ : Fintype m R : Type v inst✝ : CommRing R d : n → R σ : Perm n h2 : σ ≠ 1 x : n h3 : ¬↑σ x = ↑1 x ⊢ diagonal d (↑σ x) x = 0 [PROOFSTEP] exact if_neg h3 [GOAL] case refine'_2 m : Type u_1 n : Type u_2 inst✝⁴ : DecidableEq n inst✝³ : Fintype n inst✝² : DecidableEq m inst✝¹ : Fintype m R : Type v inst✝ : CommRing R d : n → R ⊢ ¬1 ∈ univ → ↑↑(↑sign 1) * ∏ i : n, diagonal d (↑1 i) i = 0 [PROOFSTEP] simp [GOAL] case refine'_3 m : Type u_1 n : Type u_2 inst✝⁴ : DecidableEq n inst✝³ : Fintype n inst✝² : DecidableEq m inst✝¹ : Fintype m R : Type v inst✝ : CommRing R d : n → R ⊢ ↑↑(↑sign 1) * ∏ i : n, diagonal d (↑1 i) i = ∏ i : n, d i [PROOFSTEP] simp [GOAL] m : Type u_1 n : Type u_2 inst✝⁴ : DecidableEq n inst✝³ : Fintype n inst✝² : DecidableEq m inst✝¹ : Fintype m R : Type v inst✝ : CommRing R ⊢ det 1 = 1 [PROOFSTEP] rw [← diagonal_one] [GOAL] m : Type u_1 n : Type u_2 inst✝⁴ : DecidableEq n inst✝³ : Fintype n inst✝² : DecidableEq m inst✝¹ : Fintype m R : Type v inst✝ : CommRing R ⊢ det (diagonal fun x => 1) = 1 [PROOFSTEP] simp [-diagonal_one] [GOAL] m : Type u_1 n : Type u_2 inst✝⁵ : DecidableEq n inst✝⁴ : Fintype n inst✝³ : DecidableEq m inst✝² : Fintype m R : Type v inst✝¹ : CommRing R inst✝ : IsEmpty n A : Matrix n n R ⊢ det A = 1 [PROOFSTEP] simp [det_apply] [GOAL] m : Type u_1 n : Type u_2 inst✝⁵ : DecidableEq n inst✝⁴ : Fintype n inst✝³ : DecidableEq m inst✝² : Fintype m R : Type v inst✝¹ : CommRing R inst✝ : IsEmpty n ⊢ det = const (Matrix n n R) 1 [PROOFSTEP] ext [GOAL] case h m : Type u_1 n : Type u_2 inst✝⁵ : DecidableEq n inst✝⁴ : Fintype n inst✝³ : DecidableEq m inst✝² : Fintype m R : Type v inst✝¹ : CommRing R inst✝ : IsEmpty n x✝ : Matrix n n R ⊢ det x✝ = const (Matrix n n R) 1 x✝ [PROOFSTEP] exact det_isEmpty [GOAL] m : Type u_1 n✝ : Type u_2 inst✝⁷ : DecidableEq n✝ inst✝⁶ : Fintype n✝ inst✝⁵ : DecidableEq m inst✝⁴ : Fintype m R : Type v inst✝³ : CommRing R n : Type u_3 inst✝² : Unique n inst✝¹ : DecidableEq n inst✝ : Fintype n A : Matrix n n R ⊢ det A = A default default [PROOFSTEP] simp [det_apply, univ_unique] [GOAL] m : Type u_1 n : Type u_2 inst✝⁵ : DecidableEq n inst✝⁴ : Fintype n inst✝³ : DecidableEq m inst✝² : Fintype m R : Type v inst✝¹ : CommRing R inst✝ : Subsingleton n A : Matrix n n R k : n ⊢ det A = A k k [PROOFSTEP] have := uniqueOfSubsingleton k [GOAL] m : Type u_1 n : Type u_2 inst✝⁵ : DecidableEq n inst✝⁴ : Fintype n inst✝³ : DecidableEq m inst✝² : Fintype m R : Type v inst✝¹ : CommRing R inst✝ : Subsingleton n A : Matrix n n R k : n this : Unique n ⊢ det A = A k k [PROOFSTEP] convert det_unique A [GOAL] m : Type u_1 n : Type u_2 inst✝⁴ : DecidableEq n inst✝³ : Fintype n inst✝² : DecidableEq m inst✝¹ : Fintype m R : Type v inst✝ : CommRing R M N : Matrix n n R p : n → n H : ¬Bijective p ⊢ ∑ σ : Perm n, ↑↑(↑sign σ) * ∏ x : n, M (↑σ x) (p x) * N (p x) x = 0 [PROOFSTEP] obtain ⟨i, j, hpij, hij⟩ : ∃ i j, p i = p j ∧ i ≠ j := by rw [← Finite.injective_iff_bijective, Injective] at H push_neg at H exact H [GOAL] m : Type u_1 n : Type u_2 inst✝⁴ : DecidableEq n inst✝³ : Fintype n inst✝² : DecidableEq m inst✝¹ : Fintype m R : Type v inst✝ : CommRing R M N : Matrix n n R p : n → n H : ¬Bijective p ⊢ ∃ i j, p i = p j ∧ i ≠ j [PROOFSTEP] rw [← Finite.injective_iff_bijective, Injective] at H [GOAL] m : Type u_1 n : Type u_2 inst✝⁴ : DecidableEq n inst✝³ : Fintype n inst✝² : DecidableEq m inst✝¹ : Fintype m R : Type v inst✝ : CommRing R M N : Matrix n n R p : n → n H : ¬∀ ⦃a₁ a₂ : n⦄, p a₁ = p a₂ → a₁ = a₂ ⊢ ∃ i j, p i = p j ∧ i ≠ j [PROOFSTEP] push_neg at H [GOAL] m : Type u_1 n : Type u_2 inst✝⁴ : DecidableEq n inst✝³ : Fintype n inst✝² : DecidableEq m inst✝¹ : Fintype m R : Type v inst✝ : CommRing R M N : Matrix n n R p : n → n H : Exists fun ⦃a₁⦄ => Exists fun ⦃a₂⦄ => p a₁ = p a₂ ∧ a₁ ≠ a₂ ⊢ ∃ i j, p i = p j ∧ i ≠ j [PROOFSTEP] exact H [GOAL] case intro.intro.intro m : Type u_1 n : Type u_2 inst✝⁴ : DecidableEq n inst✝³ : Fintype n inst✝² : DecidableEq m inst✝¹ : Fintype m R : Type v inst✝ : CommRing R M N : Matrix n n R p : n → n H : ¬Bijective p i j : n hpij : p i = p j hij : i ≠ j ⊢ ∑ σ : Perm n, ↑↑(↑sign σ) * ∏ x : n, M (↑σ x) (p x) * N (p x) x = 0 [PROOFSTEP] exact sum_involution (fun σ _ => σ * Equiv.swap i j) (fun σ _ => by have : (∏ x, M (σ x) (p x)) = ∏ x, M ((σ * Equiv.swap i j) x) (p x) := Fintype.prod_equiv (swap i j) _ _ (by simp [apply_swap_eq_self hpij]) simp [this, sign_swap hij, -sign_swap', prod_mul_distrib]) (fun σ _ _ => (not_congr mul_swap_eq_iff).mpr hij) (fun _ _ => mem_univ _) fun σ _ => mul_swap_involutive i j σ [GOAL] m : Type u_1 n : Type u_2 inst✝⁴ : DecidableEq n inst✝³ : Fintype n inst✝² : DecidableEq m inst✝¹ : Fintype m R : Type v inst✝ : CommRing R M N : Matrix n n R p : n → n H : ¬Bijective p i j : n hpij : p i = p j hij : i ≠ j σ : Perm n x✝ : σ ∈ univ ⊢ ↑↑(↑sign σ) * ∏ x : n, M (↑σ x) (p x) * N (p x) x + ↑↑(↑sign ((fun σ x => σ * Equiv.swap i j) σ x✝)) * ∏ x : n, M (↑((fun σ x => σ * Equiv.swap i j) σ x✝) x) (p x) * N (p x) x = 0 [PROOFSTEP] have : (∏ x, M (σ x) (p x)) = ∏ x, M ((σ * Equiv.swap i j) x) (p x) := Fintype.prod_equiv (swap i j) _ _ (by simp [apply_swap_eq_self hpij]) [GOAL] m : Type u_1 n : Type u_2 inst✝⁴ : DecidableEq n inst✝³ : Fintype n inst✝² : DecidableEq m inst✝¹ : Fintype m R : Type v inst✝ : CommRing R M N : Matrix n n R p : n → n H : ¬Bijective p i j : n hpij : p i = p j hij : i ≠ j σ : Perm n x✝ : σ ∈ univ ⊢ ∀ (x : n), M (↑σ x) (p x) = M (↑(σ * Equiv.swap i j) (↑(Equiv.swap i j) x)) (p (↑(Equiv.swap i j) x)) [PROOFSTEP] simp [apply_swap_eq_self hpij] [GOAL] m : Type u_1 n : Type u_2 inst✝⁴ : DecidableEq n inst✝³ : Fintype n inst✝² : DecidableEq m inst✝¹ : Fintype m R : Type v inst✝ : CommRing R M N : Matrix n n R p : n → n H : ¬Bijective p i j : n hpij : p i = p j hij : i ≠ j σ : Perm n x✝ : σ ∈ univ this : ∏ x : n, M (↑σ x) (p x) = ∏ x : n, M (↑(σ * Equiv.swap i j) x) (p x) ⊢ ↑↑(↑sign σ) * ∏ x : n, M (↑σ x) (p x) * N (p x) x + ↑↑(↑sign ((fun σ x => σ * Equiv.swap i j) σ x✝)) * ∏ x : n, M (↑((fun σ x => σ * Equiv.swap i j) σ x✝) x) (p x) * N (p x) x = 0 [PROOFSTEP] simp [this, sign_swap hij, -sign_swap', prod_mul_distrib] [GOAL] m : Type u_1 n : Type u_2 inst✝⁴ : DecidableEq n inst✝³ : Fintype n inst✝² : DecidableEq m inst✝¹ : Fintype m R : Type v inst✝ : CommRing R M N : Matrix n n R ⊢ det (M * N) = ∑ p : n → n, ∑ σ : Perm n, ↑↑(↑sign σ) * ∏ i : n, M (↑σ i) (p i) * N (p i) i [PROOFSTEP] simp only [det_apply', mul_apply, prod_univ_sum, mul_sum, Fintype.piFinset_univ] [GOAL] m : Type u_1 n : Type u_2 inst✝⁴ : DecidableEq n inst✝³ : Fintype n inst✝² : DecidableEq m inst✝¹ : Fintype m R : Type v inst✝ : CommRing R M N : Matrix n n R ⊢ ∑ x : Perm n, ∑ x_1 : n → n, ↑↑(↑sign x) * ∏ x_2 : n, M (↑x x_2) (x_1 x_2) * N (x_1 x_2) x_2 = ∑ x : n → n, ∑ x_1 : Perm n, ↑↑(↑sign x_1) * ∏ x_2 : n, M (↑x_1 x_2) (x x_2) * N (x x_2) x_2 [PROOFSTEP] rw [Finset.sum_comm] [GOAL] m : Type u_1 n : Type u_2 inst✝⁴ : DecidableEq n inst✝³ : Fintype n inst✝² : DecidableEq m inst✝¹ : Fintype m R : Type v inst✝ : CommRing R M N : Matrix n n R f : n → n x✝ : f ∈ univ hbij : ¬f ∈ filter Bijective univ ⊢ ¬Bijective fun i => f i [PROOFSTEP] simpa only [true_and_iff, mem_filter, mem_univ] using hbij [GOAL] m : Type u_1 n : Type u_2 inst✝⁴ : DecidableEq n inst✝³ : Fintype n inst✝² : DecidableEq m inst✝¹ : Fintype m R : Type v inst✝ : CommRing R M N : Matrix n n R x✝³ x✝² : n → n x✝¹ : x✝³ ∈ filter Bijective univ x✝ : x✝² ∈ filter Bijective univ h : (fun p h => ofBijective p (_ : Bijective p)) x✝³ x✝¹ = (fun p h => ofBijective p (_ : Bijective p)) x✝² x✝ ⊢ x✝³ = x✝² [PROOFSTEP] injection h [GOAL] m : Type u_1 n : Type u_2 inst✝⁴ : DecidableEq n inst✝³ : Fintype n inst✝² : DecidableEq m inst✝¹ : Fintype m R : Type v inst✝ : CommRing R M N : Matrix n n R ⊢ ∑ τ : Perm n, ∑ σ : Perm n, ↑↑(↑sign σ) * ∏ i : n, M (↑σ i) (↑τ i) * N (↑τ i) i = ∑ σ : Perm n, ∑ τ : Perm n, (∏ i : n, N (↑σ i) i) * ↑↑(↑sign τ) * ∏ j : n, M (↑τ j) (↑σ j) [PROOFSTEP] simp only [mul_comm, mul_left_comm, prod_mul_distrib, mul_assoc] [GOAL] m : Type u_1 n : Type u_2 inst✝⁴ : DecidableEq n inst✝³ : Fintype n inst✝² : DecidableEq m inst✝¹ : Fintype m R : Type v inst✝ : CommRing R M N : Matrix n n R σ : Perm n x✝ : σ ∈ univ τ : Perm n ⊢ (∏ i : n, N (↑σ i) i) * ↑↑(↑sign τ) * ∏ j : n, M (↑τ j) (↑σ j) = (∏ i : n, N (↑σ i) i) * (↑↑(↑sign σ) * ↑↑(↑sign (↑(Equiv.mulRight σ⁻¹) τ))) * ∏ i : n, M (↑(↑(Equiv.mulRight σ⁻¹) τ) i) i [PROOFSTEP] have : (∏ j, M (τ j) (σ j)) = ∏ j, M ((τ * σ⁻¹) j) j := by rw [← (σ⁻¹ : _ ≃ _).prod_comp] simp only [Equiv.Perm.coe_mul, apply_inv_self, Function.comp_apply] [GOAL] m : Type u_1 n : Type u_2 inst✝⁴ : DecidableEq n inst✝³ : Fintype n inst✝² : DecidableEq m inst✝¹ : Fintype m R : Type v inst✝ : CommRing R M N : Matrix n n R σ : Perm n x✝ : σ ∈ univ τ : Perm n ⊢ ∏ j : n, M (↑τ j) (↑σ j) = ∏ j : n, M (↑(τ * σ⁻¹) j) j [PROOFSTEP] rw [← (σ⁻¹ : _ ≃ _).prod_comp] [GOAL] m : Type u_1 n : Type u_2 inst✝⁴ : DecidableEq n inst✝³ : Fintype n inst✝² : DecidableEq m inst✝¹ : Fintype m R : Type v inst✝ : CommRing R M N : Matrix n n R σ : Perm n x✝ : σ ∈ univ τ : Perm n ⊢ ∏ i : n, M (↑τ (↑σ⁻¹ i)) (↑σ (↑σ⁻¹ i)) = ∏ j : n, M (↑(τ * σ⁻¹) j) j [PROOFSTEP] simp only [Equiv.Perm.coe_mul, apply_inv_self, Function.comp_apply] [GOAL] m : Type u_1 n : Type u_2 inst✝⁴ : DecidableEq n inst✝³ : Fintype n inst✝² : DecidableEq m inst✝¹ : Fintype m R : Type v inst✝ : CommRing R M N : Matrix n n R σ : Perm n x✝ : σ ∈ univ τ : Perm n this : ∏ j : n, M (↑τ j) (↑σ j) = ∏ j : n, M (↑(τ * σ⁻¹) j) j ⊢ (∏ i : n, N (↑σ i) i) * ↑↑(↑sign τ) * ∏ j : n, M (↑τ j) (↑σ j) = (∏ i : n, N (↑σ i) i) * (↑↑(↑sign σ) * ↑↑(↑sign (↑(Equiv.mulRight σ⁻¹) τ))) * ∏ i : n, M (↑(↑(Equiv.mulRight σ⁻¹) τ) i) i [PROOFSTEP] have h : ε σ * ε (τ * σ⁻¹) = ε τ := calc ε σ * ε (τ * σ⁻¹) = ε (τ * σ⁻¹ * σ) := by rw [mul_comm, sign_mul (τ * σ⁻¹)] simp only [Int.cast_mul, Units.val_mul] _ = ε τ := by simp only [inv_mul_cancel_right] [GOAL] m : Type u_1 n : Type u_2 inst✝⁴ : DecidableEq n inst✝³ : Fintype n inst✝² : DecidableEq m inst✝¹ : Fintype m R : Type v inst✝ : CommRing R M N : Matrix n n R σ : Perm n x✝ : σ ∈ univ τ : Perm n this : ∏ j : n, M (↑τ j) (↑σ j) = ∏ j : n, M (↑(τ * σ⁻¹) j) j ⊢ ↑↑(↑sign σ) * ↑↑(↑sign (τ * σ⁻¹)) = ↑↑(↑sign (τ * σ⁻¹ * σ)) [PROOFSTEP] rw [mul_comm, sign_mul (τ * σ⁻¹)] [GOAL] m : Type u_1 n : Type u_2 inst✝⁴ : DecidableEq n inst✝³ : Fintype n inst✝² : DecidableEq m inst✝¹ : Fintype m R : Type v inst✝ : CommRing R M N : Matrix n n R σ : Perm n x✝ : σ ∈ univ τ : Perm n this : ∏ j : n, M (↑τ j) (↑σ j) = ∏ j : n, M (↑(τ * σ⁻¹) j) j ⊢ ↑↑(↑sign (τ * σ⁻¹)) * ↑↑(↑sign σ) = ↑↑(↑sign (τ * σ⁻¹) * ↑sign σ) [PROOFSTEP] simp only [Int.cast_mul, Units.val_mul] [GOAL] m : Type u_1 n : Type u_2 inst✝⁴ : DecidableEq n inst✝³ : Fintype n inst✝² : DecidableEq m inst✝¹ : Fintype m R : Type v inst✝ : CommRing R M N : Matrix n n R σ : Perm n x✝ : σ ∈ univ τ : Perm n this : ∏ j : n, M (↑τ j) (↑σ j) = ∏ j : n, M (↑(τ * σ⁻¹) j) j ⊢ ↑↑(↑sign (τ * σ⁻¹ * σ)) = ↑↑(↑sign τ) [PROOFSTEP] simp only [inv_mul_cancel_right] [GOAL] m : Type u_1 n : Type u_2 inst✝⁴ : DecidableEq n inst✝³ : Fintype n inst✝² : DecidableEq m inst✝¹ : Fintype m R : Type v inst✝ : CommRing R M N : Matrix n n R σ : Perm n x✝ : σ ∈ univ τ : Perm n this : ∏ j : n, M (↑τ j) (↑σ j) = ∏ j : n, M (↑(τ * σ⁻¹) j) j h : ↑↑(↑sign σ) * ↑↑(↑sign (τ * σ⁻¹)) = ↑↑(↑sign τ) ⊢ (∏ i : n, N (↑σ i) i) * ↑↑(↑sign τ) * ∏ j : n, M (↑τ j) (↑σ j) = (∏ i : n, N (↑σ i) i) * (↑↑(↑sign σ) * ↑↑(↑sign (↑(Equiv.mulRight σ⁻¹) τ))) * ∏ i : n, M (↑(↑(Equiv.mulRight σ⁻¹) τ) i) i [PROOFSTEP] simp_rw [Equiv.coe_mulRight, h] [GOAL] m : Type u_1 n : Type u_2 inst✝⁴ : DecidableEq n inst✝³ : Fintype n inst✝² : DecidableEq m inst✝¹ : Fintype m R : Type v inst✝ : CommRing R M N : Matrix n n R σ : Perm n x✝ : σ ∈ univ τ : Perm n this : ∏ j : n, M (↑τ j) (↑σ j) = ∏ j : n, M (↑(τ * σ⁻¹) j) j h : ↑↑(↑sign σ) * ↑↑(↑sign (τ * σ⁻¹)) = ↑↑(↑sign τ) ⊢ (∏ x : n, N (↑σ x) x) * ↑↑(↑sign τ) * ∏ x : n, M (↑τ x) (↑σ x) = (∏ x : n, N (↑σ x) x) * ↑↑(↑sign τ) * ∏ x : n, M (↑(τ * σ⁻¹) x) x [PROOFSTEP] simp only [this] [GOAL] m : Type u_1 n : Type u_2 inst✝⁴ : DecidableEq n inst✝³ : Fintype n inst✝² : DecidableEq m inst✝¹ : Fintype m R : Type v inst✝ : CommRing R M N : Matrix n n R ⊢ ∑ σ : Perm n, ∑ τ : Perm n, (∏ i : n, N (↑σ i) i) * (↑↑(↑sign σ) * ↑↑(↑sign τ)) * ∏ i : n, M (↑τ i) i = det M * det N [PROOFSTEP] simp only [det_apply', Finset.mul_sum, mul_comm, mul_left_comm, mul_assoc] [GOAL] m : Type u_1 n : Type u_2 inst✝⁴ : DecidableEq n inst✝³ : Fintype n inst✝² : DecidableEq m inst✝¹ : Fintype m R : Type v inst✝ : CommRing R M N : Matrix m m R ⊢ det (M * N) = det (N * M) [PROOFSTEP] rw [det_mul, det_mul, mul_comm] [GOAL] m : Type u_1 n : Type u_2 inst✝⁴ : DecidableEq n inst✝³ : Fintype n inst✝² : DecidableEq m inst✝¹ : Fintype m R : Type v inst✝ : CommRing R M N P : Matrix m m R ⊢ det (M * (N * P)) = det (N * (M * P)) [PROOFSTEP] rw [← Matrix.mul_assoc, ← Matrix.mul_assoc, det_mul, det_mul_comm M N, ← det_mul] [GOAL] m : Type u_1 n : Type u_2 inst✝⁴ : DecidableEq n inst✝³ : Fintype n inst✝² : DecidableEq m inst✝¹ : Fintype m R : Type v inst✝ : CommRing R M N P : Matrix m m R ⊢ det (M * N * P) = det (M * P * N) [PROOFSTEP] rw [Matrix.mul_assoc, Matrix.mul_assoc, det_mul, det_mul_comm N P, ← det_mul] [GOAL] m : Type u_1 n : Type u_2 inst✝⁴ : DecidableEq n inst✝³ : Fintype n inst✝² : DecidableEq m inst✝¹ : Fintype m R : Type v inst✝ : CommRing R M : (Matrix m m R)ˣ N : Matrix m m R ⊢ det (↑M * N * ↑M⁻¹) = det N [PROOFSTEP] rw [det_mul_right_comm, Units.mul_inv, one_mul] [GOAL] m : Type u_1 n : Type u_2 inst✝⁴ : DecidableEq n inst✝³ : Fintype n inst✝² : DecidableEq m inst✝¹ : Fintype m R : Type v inst✝ : CommRing R M : Matrix n n R ⊢ det Mᵀ = det M [PROOFSTEP] rw [det_apply', det_apply'] [GOAL] m : Type u_1 n : Type u_2 inst✝⁴ : DecidableEq n inst✝³ : Fintype n inst✝² : DecidableEq m inst✝¹ : Fintype m R : Type v inst✝ : CommRing R M : Matrix n n R ⊢ ∑ σ : Perm n, ↑↑(↑sign σ) * ∏ i : n, Mᵀ (↑σ i) i = ∑ σ : Perm n, ↑↑(↑sign σ) * ∏ i : n, M (↑σ i) i [PROOFSTEP] refine' Fintype.sum_bijective _ inv_involutive.bijective _ _ _ [GOAL] m : Type u_1 n : Type u_2 inst✝⁴ : DecidableEq n inst✝³ : Fintype n inst✝² : DecidableEq m inst✝¹ : Fintype m R : Type v inst✝ : CommRing R M : Matrix n n R ⊢ ∀ (x : Perm n), ↑↑(↑sign x) * ∏ i : n, Mᵀ (↑x i) i = ↑↑(↑sign x⁻¹) * ∏ i : n, M (↑x⁻¹ i) i [PROOFSTEP] intro σ [GOAL] m : Type u_1 n : Type u_2 inst✝⁴ : DecidableEq n inst✝³ : Fintype n inst✝² : DecidableEq m inst✝¹ : Fintype m R : Type v inst✝ : CommRing R M : Matrix n n R σ : Perm n ⊢ ↑↑(↑sign σ) * ∏ i : n, Mᵀ (↑σ i) i = ↑↑(↑sign σ⁻¹) * ∏ i : n, M (↑σ⁻¹ i) i [PROOFSTEP] rw [sign_inv] [GOAL] m : Type u_1 n : Type u_2 inst✝⁴ : DecidableEq n inst✝³ : Fintype n inst✝² : DecidableEq m inst✝¹ : Fintype m R : Type v inst✝ : CommRing R M : Matrix n n R σ : Perm n ⊢ ↑↑(↑sign σ) * ∏ i : n, Mᵀ (↑σ i) i = ↑↑(↑sign σ) * ∏ i : n, M (↑σ⁻¹ i) i [PROOFSTEP] congr 1 [GOAL] case e_a m : Type u_1 n : Type u_2 inst✝⁴ : DecidableEq n inst✝³ : Fintype n inst✝² : DecidableEq m inst✝¹ : Fintype m R : Type v inst✝ : CommRing R M : Matrix n n R σ : Perm n ⊢ ∏ i : n, Mᵀ (↑σ i) i = ∏ i : n, M (↑σ⁻¹ i) i [PROOFSTEP] apply Fintype.prod_equiv σ [GOAL] case e_a.h m : Type u_1 n : Type u_2 inst✝⁴ : DecidableEq n inst✝³ : Fintype n inst✝² : DecidableEq m inst✝¹ : Fintype m R : Type v inst✝ : CommRing R M : Matrix n n R σ : Perm n ⊢ ∀ (x : n), Mᵀ (↑σ x) x = M (↑σ⁻¹ (↑σ x)) (↑σ x) [PROOFSTEP] intros [GOAL] case e_a.h m : Type u_1 n : Type u_2 inst✝⁴ : DecidableEq n inst✝³ : Fintype n inst✝² : DecidableEq m inst✝¹ : Fintype m R : Type v inst✝ : CommRing R M : Matrix n n R σ : Perm n x✝ : n ⊢ Mᵀ (↑σ x✝) x✝ = M (↑σ⁻¹ (↑σ x✝)) (↑σ x✝) [PROOFSTEP] simp [GOAL] m : Type u_1 n : Type u_2 inst✝⁴ : DecidableEq n inst✝³ : Fintype n inst✝² : DecidableEq m inst✝¹ : Fintype m R : Type v inst✝ : CommRing R σ : Perm n M : Matrix n n R ⊢ ↑sign σ • ↑detRowAlternating M = ↑↑(↑sign σ) * det M [PROOFSTEP] simp [Units.smul_def] [GOAL] m : Type u_1 n : Type u_2 inst✝⁴ : DecidableEq n inst✝³ : Fintype n inst✝² : DecidableEq m inst✝¹ : Fintype m R : Type v inst✝ : CommRing R e : n ≃ m A : Matrix m m R ⊢ det (submatrix A ↑e ↑e) = det A [PROOFSTEP] rw [det_apply', det_apply'] [GOAL] m : Type u_1 n : Type u_2 inst✝⁴ : DecidableEq n inst✝³ : Fintype n inst✝² : DecidableEq m inst✝¹ : Fintype m R : Type v inst✝ : CommRing R e : n ≃ m A : Matrix m m R ⊢ ∑ σ : Perm n, ↑↑(↑sign σ) * ∏ i : n, submatrix A (↑e) (↑e) (↑σ i) i = ∑ σ : Perm m, ↑↑(↑sign σ) * ∏ i : m, A (↑σ i) i [PROOFSTEP] apply Fintype.sum_equiv (Equiv.permCongr e) [GOAL] case h m : Type u_1 n : Type u_2 inst✝⁴ : DecidableEq n inst✝³ : Fintype n inst✝² : DecidableEq m inst✝¹ : Fintype m R : Type v inst✝ : CommRing R e : n ≃ m A : Matrix m m R ⊢ ∀ (x : Perm n), ↑↑(↑sign x) * ∏ i : n, submatrix A (↑e) (↑e) (↑x i) i = ↑↑(↑sign (↑(permCongr e) x)) * ∏ i : m, A (↑(↑(permCongr e) x) i) i [PROOFSTEP] intro σ [GOAL] case h m : Type u_1 n : Type u_2 inst✝⁴ : DecidableEq n inst✝³ : Fintype n inst✝² : DecidableEq m inst✝¹ : Fintype m R : Type v inst✝ : CommRing R e : n ≃ m A : Matrix m m R σ : Perm n ⊢ ↑↑(↑sign σ) * ∏ i : n, submatrix A (↑e) (↑e) (↑σ i) i = ↑↑(↑sign (↑(permCongr e) σ)) * ∏ i : m, A (↑(↑(permCongr e) σ) i) i [PROOFSTEP] rw [Equiv.Perm.sign_permCongr e σ] [GOAL] case h m : Type u_1 n : Type u_2 inst✝⁴ : DecidableEq n inst✝³ : Fintype n inst✝² : DecidableEq m inst✝¹ : Fintype m R : Type v inst✝ : CommRing R e : n ≃ m A : Matrix m m R σ : Perm n ⊢ ↑↑(↑sign σ) * ∏ i : n, submatrix A (↑e) (↑e) (↑σ i) i = ↑↑(↑sign σ) * ∏ i : m, A (↑(↑(permCongr e) σ) i) i [PROOFSTEP] congr 1 [GOAL] case h.e_a m : Type u_1 n : Type u_2 inst✝⁴ : DecidableEq n inst✝³ : Fintype n inst✝² : DecidableEq m inst✝¹ : Fintype m R : Type v inst✝ : CommRing R e : n ≃ m A : Matrix m m R σ : Perm n ⊢ ∏ i : n, submatrix A (↑e) (↑e) (↑σ i) i = ∏ i : m, A (↑(↑(permCongr e) σ) i) i [PROOFSTEP] apply Fintype.prod_equiv e [GOAL] case h.e_a.h m : Type u_1 n : Type u_2 inst✝⁴ : DecidableEq n inst✝³ : Fintype n inst✝² : DecidableEq m inst✝¹ : Fintype m R : Type v inst✝ : CommRing R e : n ≃ m A : Matrix m m R σ : Perm n ⊢ ∀ (x : n), submatrix A (↑e) (↑e) (↑σ x) x = A (↑(↑(permCongr e) σ) (↑e x)) (↑e x) [PROOFSTEP] intro i [GOAL] case h.e_a.h m : Type u_1 n : Type u_2 inst✝⁴ : DecidableEq n inst✝³ : Fintype n inst✝² : DecidableEq m inst✝¹ : Fintype m R : Type v inst✝ : CommRing R e : n ≃ m A : Matrix m m R σ : Perm n i : n ⊢ submatrix A (↑e) (↑e) (↑σ i) i = A (↑(↑(permCongr e) σ) (↑e i)) (↑e i) [PROOFSTEP] rw [Equiv.permCongr_apply, Equiv.symm_apply_apply, submatrix_apply] [GOAL] m : Type u_1 n : Type u_2 inst✝⁴ : DecidableEq n inst✝³ : Fintype n inst✝² : DecidableEq m inst✝¹ : Fintype m R : Type v inst✝ : CommRing R σ : Perm n ⊢ det (PEquiv.toMatrix (toPEquiv σ)) = ↑↑(↑sign σ) [PROOFSTEP] rw [← Matrix.mul_one (σ.toPEquiv.toMatrix : Matrix n n R), PEquiv.toPEquiv_mul_matrix, det_permute, det_one, mul_one] [GOAL] m : Type u_1 n : Type u_2 inst✝⁴ : DecidableEq n inst✝³ : Fintype n inst✝² : DecidableEq m inst✝¹ : Fintype m R : Type v inst✝ : CommRing R A : Matrix n n R c : R ⊢ det (c • A) = det ((diagonal fun x => c) * A) [PROOFSTEP] rw [smul_eq_diagonal_mul] [GOAL] m : Type u_1 n : Type u_2 inst✝⁴ : DecidableEq n inst✝³ : Fintype n inst✝² : DecidableEq m inst✝¹ : Fintype m R : Type v inst✝ : CommRing R A : Matrix n n R c : R ⊢ det (diagonal fun x => c) * det A = c ^ Fintype.card n * det A [PROOFSTEP] simp [card_univ] [GOAL] m : Type u_1 n : Type u_2 inst✝⁸ : DecidableEq n inst✝⁷ : Fintype n inst✝⁶ : DecidableEq m inst✝⁵ : Fintype m R : Type v inst✝⁴ : CommRing R α : Type u_3 inst✝³ : Monoid α inst✝² : DistribMulAction α R inst✝¹ : IsScalarTower α R R inst✝ : SMulCommClass α R R c : α A : Matrix n n R ⊢ det (c • A) = c ^ Fintype.card n • det A [PROOFSTEP] rw [← smul_one_smul R c A, det_smul, smul_pow, one_pow, smul_mul_assoc, one_mul] [GOAL] m : Type u_1 n : Type u_2 inst✝⁴ : DecidableEq n inst✝³ : Fintype n inst✝² : DecidableEq m inst✝¹ : Fintype m R : Type v inst✝ : CommRing R A : Matrix n n R ⊢ det (-A) = (-1) ^ Fintype.card n * det A [PROOFSTEP] rw [← det_smul, neg_one_smul] [GOAL] m : Type u_1 n : Type u_2 inst✝⁴ : DecidableEq n inst✝³ : Fintype n inst✝² : DecidableEq m inst✝¹ : Fintype m R : Type v inst✝ : CommRing R A : Matrix n n R ⊢ det (-A) = (-1) ^ Fintype.card n • det A [PROOFSTEP] rw [← det_smul_of_tower, Units.neg_smul, one_smul] [GOAL] m : Type u_1 n : Type u_2 inst✝⁴ : DecidableEq n inst✝³ : Fintype n inst✝² : DecidableEq m inst✝¹ : Fintype m R : Type v inst✝ : CommRing R v : n → R A : Matrix n n R ⊢ (↑of fun i j => v j * A i j) = A * diagonal v [PROOFSTEP] ext [GOAL] case a.h m : Type u_1 n : Type u_2 inst✝⁴ : DecidableEq n inst✝³ : Fintype n inst✝² : DecidableEq m inst✝¹ : Fintype m R : Type v inst✝ : CommRing R v : n → R A : Matrix n n R i✝ x✝ : n ⊢ ↑of (fun i j => v j * A i j) i✝ x✝ = (A * diagonal v) i✝ x✝ [PROOFSTEP] simp [mul_comm] [GOAL] m : Type u_1 n : Type u_2 inst✝⁴ : DecidableEq n inst✝³ : Fintype n inst✝² : DecidableEq m inst✝¹ : Fintype m R : Type v inst✝ : CommRing R v : n → R A : Matrix n n R ⊢ det (A * diagonal v) = (∏ i : n, v i) * det A [PROOFSTEP] rw [det_mul, det_diagonal, mul_comm] [GOAL] m : Type u_1 n : Type u_2 inst✝⁵ : DecidableEq n inst✝⁴ : Fintype n inst✝³ : DecidableEq m inst✝² : Fintype m R : Type v inst✝¹ : CommRing R S : Type w inst✝ : CommRing S f : R →+* S M : Matrix n n R ⊢ ↑f (det M) = det (↑(RingHom.mapMatrix f) M) [PROOFSTEP] simp [Matrix.det_apply', f.map_sum, f.map_prod] [GOAL] m : Type u_1 n : Type u_2 inst✝⁴ : DecidableEq n inst✝³ : Fintype n inst✝² : DecidableEq m inst✝¹ : Fintype m R : Type v inst✝ : CommRing R A : Matrix n n R j : n h : ∀ (i : n), A i j = 0 ⊢ det A = 0 [PROOFSTEP] rw [← det_transpose] [GOAL] m : Type u_1 n : Type u_2 inst✝⁴ : DecidableEq n inst✝³ : Fintype n inst✝² : DecidableEq m inst✝¹ : Fintype m R : Type v inst✝ : CommRing R A : Matrix n n R j : n h : ∀ (i : n), A i j = 0 ⊢ det Aᵀ = 0 [PROOFSTEP] exact det_eq_zero_of_row_eq_zero j h [GOAL] m : Type u_1 n : Type u_2 inst✝⁴ : DecidableEq n inst✝³ : Fintype n inst✝² : DecidableEq m inst✝¹ : Fintype m R : Type v inst✝ : CommRing R M : Matrix n n R i j : n i_ne_j : i ≠ j hij : ∀ (k : n), M k i = M k j ⊢ det M = 0 [PROOFSTEP] rw [← det_transpose, det_zero_of_row_eq i_ne_j] [GOAL] m : Type u_1 n : Type u_2 inst✝⁴ : DecidableEq n inst✝³ : Fintype n inst✝² : DecidableEq m inst✝¹ : Fintype m R : Type v inst✝ : CommRing R M : Matrix n n R i j : n i_ne_j : i ≠ j hij : ∀ (k : n), M k i = M k j ⊢ Mᵀ i = Mᵀ j [PROOFSTEP] exact funext hij [GOAL] m : Type u_1 n : Type u_2 inst✝⁴ : DecidableEq n inst✝³ : Fintype n inst✝² : DecidableEq m inst✝¹ : Fintype m R : Type v inst✝ : CommRing R M : Matrix n n R j : n u v : n → R ⊢ det (updateColumn M j (u + v)) = det (updateColumn M j u) + det (updateColumn M j v) [PROOFSTEP] rw [← det_transpose, ← updateRow_transpose, det_updateRow_add] [GOAL] m : Type u_1 n : Type u_2 inst✝⁴ : DecidableEq n inst✝³ : Fintype n inst✝² : DecidableEq m inst✝¹ : Fintype m R : Type v inst✝ : CommRing R M : Matrix n n R j : n u v : n → R ⊢ det (updateRow Mᵀ j u) + det (updateRow Mᵀ j v) = det (updateColumn M j u) + det (updateColumn M j v) [PROOFSTEP] simp [updateRow_transpose, det_transpose] [GOAL] m : Type u_1 n : Type u_2 inst✝⁴ : DecidableEq n inst✝³ : Fintype n inst✝² : DecidableEq m inst✝¹ : Fintype m R : Type v inst✝ : CommRing R M : Matrix n n R j : n s : R u : n → R ⊢ det (updateColumn M j (s • u)) = s * det (updateColumn M j u) [PROOFSTEP] rw [← det_transpose, ← updateRow_transpose, det_updateRow_smul] [GOAL] m : Type u_1 n : Type u_2 inst✝⁴ : DecidableEq n inst✝³ : Fintype n inst✝² : DecidableEq m inst✝¹ : Fintype m R : Type v inst✝ : CommRing R M : Matrix n n R j : n s : R u : n → R ⊢ s * det (updateRow Mᵀ j u) = s * det (updateColumn M j u) [PROOFSTEP] simp [updateRow_transpose, det_transpose] [GOAL] m : Type u_1 n : Type u_2 inst✝⁴ : DecidableEq n inst✝³ : Fintype n inst✝² : DecidableEq m inst✝¹ : Fintype m R : Type v inst✝ : CommRing R M : Matrix n n R j : n s : R u : n → R ⊢ det (updateColumn (s • M) j u) = s ^ (Fintype.card n - 1) * det (updateColumn M j u) [PROOFSTEP] rw [← det_transpose, ← updateRow_transpose, transpose_smul, det_updateRow_smul'] [GOAL] m : Type u_1 n : Type u_2 inst✝⁴ : DecidableEq n inst✝³ : Fintype n inst✝² : DecidableEq m inst✝¹ : Fintype m R : Type v inst✝ : CommRing R M : Matrix n n R j : n s : R u : n → R ⊢ s ^ (Fintype.card n - 1) * det (updateRow Mᵀ j u) = s ^ (Fintype.card n - 1) * det (updateColumn M j u) [PROOFSTEP] simp [updateRow_transpose, det_transpose] [GOAL] m : Type u_1 n : Type u_2 inst✝⁴ : DecidableEq n inst✝³ : Fintype n inst✝² : DecidableEq m inst✝¹ : Fintype m R : Type v inst✝ : CommRing R A B C : Matrix n n R hC : det C = 1 hA : A = B * C ⊢ det B * det C = det B [PROOFSTEP] rw [hC, mul_one] [GOAL] m : Type u_1 n : Type u_2 inst✝⁴ : DecidableEq n inst✝³ : Fintype n inst✝² : DecidableEq m inst✝¹ : Fintype m R : Type v inst✝ : CommRing R A B C : Matrix n n R hC : det C = 1 hA : A = C * B ⊢ det C * det B = det B [PROOFSTEP] rw [hC, one_mul] [GOAL] m : Type u_1 n : Type u_2 inst✝⁴ : DecidableEq n inst✝³ : Fintype n inst✝² : DecidableEq m inst✝¹ : Fintype m R : Type v inst✝ : CommRing R A : Matrix n n R i j : n hij : i ≠ j ⊢ det (updateRow A i (A i + A j)) = det A [PROOFSTEP] simp [det_updateRow_add, det_zero_of_row_eq hij (updateRow_self.trans (updateRow_ne hij.symm).symm)] [GOAL] m : Type u_1 n : Type u_2 inst✝⁴ : DecidableEq n inst✝³ : Fintype n inst✝² : DecidableEq m inst✝¹ : Fintype m R : Type v inst✝ : CommRing R A : Matrix n n R i j : n hij : i ≠ j ⊢ det (updateColumn A i fun k => A k i + A k j) = det A [PROOFSTEP] rw [← det_transpose, ← updateRow_transpose, ← det_transpose A] [GOAL] m : Type u_1 n : Type u_2 inst✝⁴ : DecidableEq n inst✝³ : Fintype n inst✝² : DecidableEq m inst✝¹ : Fintype m R : Type v inst✝ : CommRing R A : Matrix n n R i j : n hij : i ≠ j ⊢ det (updateRow Aᵀ i fun k => A k i + A k j) = det Aᵀ [PROOFSTEP] exact det_updateRow_add_self Aᵀ hij [GOAL] m : Type u_1 n : Type u_2 inst✝⁴ : DecidableEq n inst✝³ : Fintype n inst✝² : DecidableEq m inst✝¹ : Fintype m R : Type v inst✝ : CommRing R A : Matrix n n R i j : n hij : i ≠ j c : R ⊢ det (updateRow A i (A i + c • A j)) = det A [PROOFSTEP] simp [det_updateRow_add, det_updateRow_smul, det_zero_of_row_eq hij (updateRow_self.trans (updateRow_ne hij.symm).symm)] [GOAL] m : Type u_1 n : Type u_2 inst✝⁴ : DecidableEq n inst✝³ : Fintype n inst✝² : DecidableEq m inst✝¹ : Fintype m R : Type v inst✝ : CommRing R A : Matrix n n R i j : n hij : i ≠ j c : R ⊢ det (updateColumn A i fun k => A k i + c • A k j) = det A [PROOFSTEP] rw [← det_transpose, ← updateRow_transpose, ← det_transpose A] [GOAL] m : Type u_1 n : Type u_2 inst✝⁴ : DecidableEq n inst✝³ : Fintype n inst✝² : DecidableEq m inst✝¹ : Fintype m R : Type v inst✝ : CommRing R A : Matrix n n R i j : n hij : i ≠ j c : R ⊢ det (updateRow Aᵀ i fun k => A k i + c • A k j) = det Aᵀ [PROOFSTEP] exact det_updateRow_add_smul_self Aᵀ hij c [GOAL] m : Type u_1 n : Type u_2 inst✝⁴ : DecidableEq n inst✝³ : Fintype n inst✝² : DecidableEq m inst✝¹ : Fintype m R : Type v inst✝ : CommRing R A B : Matrix n n R s : Finset n ⊢ ∀ (c : n → R), (∀ (i : n), ¬i ∈ s → c i = 0) → ∀ (k : n), ¬k ∈ s → (∀ (i j : n), A i j = B i j + c i * B k j) → det A = det B [PROOFSTEP] induction s using Finset.induction_on generalizing B with | empty => rintro c hs k - A_eq have : ∀ i, c i = 0 := by intro i specialize hs i contrapose! hs simp [hs] congr ext i j rw [A_eq, this, zero_mul, add_zero] | @insert i s _hi ih => intro c hs k hk A_eq have hAi : A i = B i + c i • B k := funext (A_eq i) rw [@ih (updateRow B i (A i)) (Function.update c i 0), hAi, det_updateRow_add_smul_self] · exact mt (fun h => show k ∈ insert i s from h ▸ Finset.mem_insert_self _ _) hk · intro i' hi' rw [Function.update_apply] split_ifs with hi'i · rfl · exact hs i' fun h => hi' ((Finset.mem_insert.mp h).resolve_left hi'i) · exact k · exact fun h => hk (Finset.mem_insert_of_mem h) · intro i' j' rw [updateRow_apply, Function.update_apply] split_ifs with hi'i · simp [hi'i] rw [A_eq, updateRow_ne fun h : k = i => hk <| h ▸ Finset.mem_insert_self k s] [GOAL] m : Type u_1 n : Type u_2 inst✝⁴ : DecidableEq n inst✝³ : Fintype n inst✝² : DecidableEq m inst✝¹ : Fintype m R : Type v inst✝ : CommRing R A B : Matrix n n R s : Finset n ⊢ ∀ (c : n → R), (∀ (i : n), ¬i ∈ s → c i = 0) → ∀ (k : n), ¬k ∈ s → (∀ (i j : n), A i j = B i j + c i * B k j) → det A = det B [PROOFSTEP] induction s using Finset.induction_on generalizing B with | empty => rintro c hs k - A_eq have : ∀ i, c i = 0 := by intro i specialize hs i contrapose! hs simp [hs] congr ext i j rw [A_eq, this, zero_mul, add_zero] | @insert i s _hi ih => intro c hs k hk A_eq have hAi : A i = B i + c i • B k := funext (A_eq i) rw [@ih (updateRow B i (A i)) (Function.update c i 0), hAi, det_updateRow_add_smul_self] · exact mt (fun h => show k ∈ insert i s from h ▸ Finset.mem_insert_self _ _) hk · intro i' hi' rw [Function.update_apply] split_ifs with hi'i · rfl · exact hs i' fun h => hi' ((Finset.mem_insert.mp h).resolve_left hi'i) · exact k · exact fun h => hk (Finset.mem_insert_of_mem h) · intro i' j' rw [updateRow_apply, Function.update_apply] split_ifs with hi'i · simp [hi'i] rw [A_eq, updateRow_ne fun h : k = i => hk <| h ▸ Finset.mem_insert_self k s] [GOAL] case empty m : Type u_1 n : Type u_2 inst✝⁴ : DecidableEq n inst✝³ : Fintype n inst✝² : DecidableEq m inst✝¹ : Fintype m R : Type v inst✝ : CommRing R A B : Matrix n n R ⊢ ∀ (c : n → R), (∀ (i : n), ¬i ∈ ∅ → c i = 0) → ∀ (k : n), ¬k ∈ ∅ → (∀ (i j : n), A i j = B i j + c i * B k j) → det A = det B [PROOFSTEP] | empty => rintro c hs k - A_eq have : ∀ i, c i = 0 := by intro i specialize hs i contrapose! hs simp [hs] congr ext i j rw [A_eq, this, zero_mul, add_zero] [GOAL] case empty m : Type u_1 n : Type u_2 inst✝⁴ : DecidableEq n inst✝³ : Fintype n inst✝² : DecidableEq m inst✝¹ : Fintype m R : Type v inst✝ : CommRing R A B : Matrix n n R ⊢ ∀ (c : n → R), (∀ (i : n), ¬i ∈ ∅ → c i = 0) → ∀ (k : n), ¬k ∈ ∅ → (∀ (i j : n), A i j = B i j + c i * B k j) → det A = det B [PROOFSTEP] rintro c hs k - A_eq [GOAL] case empty m : Type u_1 n : Type u_2 inst✝⁴ : DecidableEq n inst✝³ : Fintype n inst✝² : DecidableEq m inst✝¹ : Fintype m R : Type v inst✝ : CommRing R A B : Matrix n n R c : n → R hs : ∀ (i : n), ¬i ∈ ∅ → c i = 0 k : n A_eq : ∀ (i j : n), A i j = B i j + c i * B k j ⊢ det A = det B [PROOFSTEP] have : ∀ i, c i = 0 := by intro i specialize hs i contrapose! hs simp [hs] [GOAL] m : Type u_1 n : Type u_2 inst✝⁴ : DecidableEq n inst✝³ : Fintype n inst✝² : DecidableEq m inst✝¹ : Fintype m R : Type v inst✝ : CommRing R A B : Matrix n n R c : n → R hs : ∀ (i : n), ¬i ∈ ∅ → c i = 0 k : n A_eq : ∀ (i j : n), A i j = B i j + c i * B k j ⊢ ∀ (i : n), c i = 0 [PROOFSTEP] intro i [GOAL] m : Type u_1 n : Type u_2 inst✝⁴ : DecidableEq n inst✝³ : Fintype n inst✝² : DecidableEq m inst✝¹ : Fintype m R : Type v inst✝ : CommRing R A B : Matrix n n R c : n → R hs : ∀ (i : n), ¬i ∈ ∅ → c i = 0 k : n A_eq : ∀ (i j : n), A i j = B i j + c i * B k j i : n ⊢ c i = 0 [PROOFSTEP] specialize hs i [GOAL] m : Type u_1 n : Type u_2 inst✝⁴ : DecidableEq n inst✝³ : Fintype n inst✝² : DecidableEq m inst✝¹ : Fintype m R : Type v inst✝ : CommRing R A B : Matrix n n R c : n → R k : n A_eq : ∀ (i j : n), A i j = B i j + c i * B k j i : n hs : ¬i ∈ ∅ → c i = 0 ⊢ c i = 0 [PROOFSTEP] contrapose! hs [GOAL] m : Type u_1 n : Type u_2 inst✝⁴ : DecidableEq n inst✝³ : Fintype n inst✝² : DecidableEq m inst✝¹ : Fintype m R : Type v inst✝ : CommRing R A B : Matrix n n R c : n → R k : n A_eq : ∀ (i j : n), A i j = B i j + c i * B k j i : n hs : c i ≠ 0 ⊢ ¬i ∈ ∅ ∧ c i ≠ 0 [PROOFSTEP] simp [hs] [GOAL] case empty m : Type u_1 n : Type u_2 inst✝⁴ : DecidableEq n inst✝³ : Fintype n inst✝² : DecidableEq m inst✝¹ : Fintype m R : Type v inst✝ : CommRing R A B : Matrix n n R c : n → R hs : ∀ (i : n), ¬i ∈ ∅ → c i = 0 k : n A_eq : ∀ (i j : n), A i j = B i j + c i * B k j this : ∀ (i : n), c i = 0 ⊢ det A = det B [PROOFSTEP] congr [GOAL] case empty.e_M m : Type u_1 n : Type u_2 inst✝⁴ : DecidableEq n inst✝³ : Fintype n inst✝² : DecidableEq m inst✝¹ : Fintype m R : Type v inst✝ : CommRing R A B : Matrix n n R c : n → R hs : ∀ (i : n), ¬i ∈ ∅ → c i = 0 k : n A_eq : ∀ (i j : n), A i j = B i j + c i * B k j this : ∀ (i : n), c i = 0 ⊢ A = B [PROOFSTEP] ext i j [GOAL] case empty.e_M.a.h m : Type u_1 n : Type u_2 inst✝⁴ : DecidableEq n inst✝³ : Fintype n inst✝² : DecidableEq m inst✝¹ : Fintype m R : Type v inst✝ : CommRing R A B : Matrix n n R c : n → R hs : ∀ (i : n), ¬i ∈ ∅ → c i = 0 k : n A_eq : ∀ (i j : n), A i j = B i j + c i * B k j this : ∀ (i : n), c i = 0 i j : n ⊢ A i j = B i j [PROOFSTEP] rw [A_eq, this, zero_mul, add_zero] [GOAL] case insert m : Type u_1 n : Type u_2 inst✝⁴ : DecidableEq n inst✝³ : Fintype n inst✝² : DecidableEq m inst✝¹ : Fintype m R : Type v inst✝ : CommRing R A : Matrix n n R i : n s : Finset n _hi : ¬i ∈ s ih : ∀ {B : Matrix n n R} (c : n → R), (∀ (i : n), ¬i ∈ s → c i = 0) → ∀ (k : n), ¬k ∈ s → (∀ (i j : n), A i j = B i j + c i * B k j) → det A = det B B : Matrix n n R ⊢ ∀ (c : n → R), (∀ (i_1 : n), ¬i_1 ∈ insert i s → c i_1 = 0) → ∀ (k : n), ¬k ∈ insert i s → (∀ (i j : n), A i j = B i j + c i * B k j) → det A = det B [PROOFSTEP] | @insert i s _hi ih => intro c hs k hk A_eq have hAi : A i = B i + c i • B k := funext (A_eq i) rw [@ih (updateRow B i (A i)) (Function.update c i 0), hAi, det_updateRow_add_smul_self] · exact mt (fun h => show k ∈ insert i s from h ▸ Finset.mem_insert_self _ _) hk · intro i' hi' rw [Function.update_apply] split_ifs with hi'i · rfl · exact hs i' fun h => hi' ((Finset.mem_insert.mp h).resolve_left hi'i) · exact k · exact fun h => hk (Finset.mem_insert_of_mem h) · intro i' j' rw [updateRow_apply, Function.update_apply] split_ifs with hi'i · simp [hi'i] rw [A_eq, updateRow_ne fun h : k = i => hk <| h ▸ Finset.mem_insert_self k s] [GOAL] case insert m : Type u_1 n : Type u_2 inst✝⁴ : DecidableEq n inst✝³ : Fintype n inst✝² : DecidableEq m inst✝¹ : Fintype m R : Type v inst✝ : CommRing R A : Matrix n n R i : n s : Finset n _hi : ¬i ∈ s ih : ∀ {B : Matrix n n R} (c : n → R), (∀ (i : n), ¬i ∈ s → c i = 0) → ∀ (k : n), ¬k ∈ s → (∀ (i j : n), A i j = B i j + c i * B k j) → det A = det B B : Matrix n n R ⊢ ∀ (c : n → R), (∀ (i_1 : n), ¬i_1 ∈ insert i s → c i_1 = 0) → ∀ (k : n), ¬k ∈ insert i s → (∀ (i j : n), A i j = B i j + c i * B k j) → det A = det B [PROOFSTEP] intro c hs k hk A_eq [GOAL] case insert m : Type u_1 n : Type u_2 inst✝⁴ : DecidableEq n inst✝³ : Fintype n inst✝² : DecidableEq m inst✝¹ : Fintype m R : Type v inst✝ : CommRing R A : Matrix n n R i : n s : Finset n _hi : ¬i ∈ s ih : ∀ {B : Matrix n n R} (c : n → R), (∀ (i : n), ¬i ∈ s → c i = 0) → ∀ (k : n), ¬k ∈ s → (∀ (i j : n), A i j = B i j + c i * B k j) → det A = det B B : Matrix n n R c : n → R hs : ∀ (i_1 : n), ¬i_1 ∈ insert i s → c i_1 = 0 k : n hk : ¬k ∈ insert i s A_eq : ∀ (i j : n), A i j = B i j + c i * B k j ⊢ det A = det B [PROOFSTEP] have hAi : A i = B i + c i • B k := funext (A_eq i) [GOAL] case insert m : Type u_1 n : Type u_2 inst✝⁴ : DecidableEq n inst✝³ : Fintype n inst✝² : DecidableEq m inst✝¹ : Fintype m R : Type v inst✝ : CommRing R A : Matrix n n R i : n s : Finset n _hi : ¬i ∈ s ih : ∀ {B : Matrix n n R} (c : n → R), (∀ (i : n), ¬i ∈ s → c i = 0) → ∀ (k : n), ¬k ∈ s → (∀ (i j : n), A i j = B i j + c i * B k j) → det A = det B B : Matrix n n R c : n → R hs : ∀ (i_1 : n), ¬i_1 ∈ insert i s → c i_1 = 0 k : n hk : ¬k ∈ insert i s A_eq : ∀ (i j : n), A i j = B i j + c i * B k j hAi : A i = B i + c i • B k ⊢ det A = det B [PROOFSTEP] rw [@ih (updateRow B i (A i)) (Function.update c i 0), hAi, det_updateRow_add_smul_self] [GOAL] case insert.hij m : Type u_1 n : Type u_2 inst✝⁴ : DecidableEq n inst✝³ : Fintype n inst✝² : DecidableEq m inst✝¹ : Fintype m R : Type v inst✝ : CommRing R A : Matrix n n R i : n s : Finset n _hi : ¬i ∈ s ih : ∀ {B : Matrix n n R} (c : n → R), (∀ (i : n), ¬i ∈ s → c i = 0) → ∀ (k : n), ¬k ∈ s → (∀ (i j : n), A i j = B i j + c i * B k j) → det A = det B B : Matrix n n R c : n → R hs : ∀ (i_1 : n), ¬i_1 ∈ insert i s → c i_1 = 0 k : n hk : ¬k ∈ insert i s A_eq : ∀ (i j : n), A i j = B i j + c i * B k j hAi : A i = B i + c i • B k ⊢ i ≠ k [PROOFSTEP] exact mt (fun h => show k ∈ insert i s from h ▸ Finset.mem_insert_self _ _) hk [GOAL] case insert.x m : Type u_1 n : Type u_2 inst✝⁴ : DecidableEq n inst✝³ : Fintype n inst✝² : DecidableEq m inst✝¹ : Fintype m R : Type v inst✝ : CommRing R A : Matrix n n R i : n s : Finset n _hi : ¬i ∈ s ih : ∀ {B : Matrix n n R} (c : n → R), (∀ (i : n), ¬i ∈ s → c i = 0) → ∀ (k : n), ¬k ∈ s → (∀ (i j : n), A i j = B i j + c i * B k j) → det A = det B B : Matrix n n R c : n → R hs : ∀ (i_1 : n), ¬i_1 ∈ insert i s → c i_1 = 0 k : n hk : ¬k ∈ insert i s A_eq : ∀ (i j : n), A i j = B i j + c i * B k j hAi : A i = B i + c i • B k ⊢ ∀ (i_1 : n), ¬i_1 ∈ s → update c i 0 i_1 = 0 [PROOFSTEP] intro i' hi' [GOAL] case insert.x m : Type u_1 n : Type u_2 inst✝⁴ : DecidableEq n inst✝³ : Fintype n inst✝² : DecidableEq m inst✝¹ : Fintype m R : Type v inst✝ : CommRing R A : Matrix n n R i : n s : Finset n _hi : ¬i ∈ s ih : ∀ {B : Matrix n n R} (c : n → R), (∀ (i : n), ¬i ∈ s → c i = 0) → ∀ (k : n), ¬k ∈ s → (∀ (i j : n), A i j = B i j + c i * B k j) → det A = det B B : Matrix n n R c : n → R hs : ∀ (i_1 : n), ¬i_1 ∈ insert i s → c i_1 = 0 k : n hk : ¬k ∈ insert i s A_eq : ∀ (i j : n), A i j = B i j + c i * B k j hAi : A i = B i + c i • B k i' : n hi' : ¬i' ∈ s ⊢ update c i 0 i' = 0 [PROOFSTEP] rw [Function.update_apply] [GOAL] case insert.x m : Type u_1 n : Type u_2 inst✝⁴ : DecidableEq n inst✝³ : Fintype n inst✝² : DecidableEq m inst✝¹ : Fintype m R : Type v inst✝ : CommRing R A : Matrix n n R i : n s : Finset n _hi : ¬i ∈ s ih : ∀ {B : Matrix n n R} (c : n → R), (∀ (i : n), ¬i ∈ s → c i = 0) → ∀ (k : n), ¬k ∈ s → (∀ (i j : n), A i j = B i j + c i * B k j) → det A = det B B : Matrix n n R c : n → R hs : ∀ (i_1 : n), ¬i_1 ∈ insert i s → c i_1 = 0 k : n hk : ¬k ∈ insert i s A_eq : ∀ (i j : n), A i j = B i j + c i * B k j hAi : A i = B i + c i • B k i' : n hi' : ¬i' ∈ s ⊢ (if i' = i then 0 else c i') = 0 [PROOFSTEP] split_ifs with hi'i [GOAL] case pos m : Type u_1 n : Type u_2 inst✝⁴ : DecidableEq n inst✝³ : Fintype n inst✝² : DecidableEq m inst✝¹ : Fintype m R : Type v inst✝ : CommRing R A : Matrix n n R i : n s : Finset n _hi : ¬i ∈ s ih : ∀ {B : Matrix n n R} (c : n → R), (∀ (i : n), ¬i ∈ s → c i = 0) → ∀ (k : n), ¬k ∈ s → (∀ (i j : n), A i j = B i j + c i * B k j) → det A = det B B : Matrix n n R c : n → R hs : ∀ (i_1 : n), ¬i_1 ∈ insert i s → c i_1 = 0 k : n hk : ¬k ∈ insert i s A_eq : ∀ (i j : n), A i j = B i j + c i * B k j hAi : A i = B i + c i • B k i' : n hi' : ¬i' ∈ s hi'i : i' = i ⊢ 0 = 0 [PROOFSTEP] rfl [GOAL] case neg m : Type u_1 n : Type u_2 inst✝⁴ : DecidableEq n inst✝³ : Fintype n inst✝² : DecidableEq m inst✝¹ : Fintype m R : Type v inst✝ : CommRing R A : Matrix n n R i : n s : Finset n _hi : ¬i ∈ s ih : ∀ {B : Matrix n n R} (c : n → R), (∀ (i : n), ¬i ∈ s → c i = 0) → ∀ (k : n), ¬k ∈ s → (∀ (i j : n), A i j = B i j + c i * B k j) → det A = det B B : Matrix n n R c : n → R hs : ∀ (i_1 : n), ¬i_1 ∈ insert i s → c i_1 = 0 k : n hk : ¬k ∈ insert i s A_eq : ∀ (i j : n), A i j = B i j + c i * B k j hAi : A i = B i + c i • B k i' : n hi' : ¬i' ∈ s hi'i : ¬i' = i ⊢ c i' = 0 [PROOFSTEP] exact hs i' fun h => hi' ((Finset.mem_insert.mp h).resolve_left hi'i) [GOAL] case insert.k m : Type u_1 n : Type u_2 inst✝⁴ : DecidableEq n inst✝³ : Fintype n inst✝² : DecidableEq m inst✝¹ : Fintype m R : Type v inst✝ : CommRing R A : Matrix n n R i : n s : Finset n _hi : ¬i ∈ s ih : ∀ {B : Matrix n n R} (c : n → R), (∀ (i : n), ¬i ∈ s → c i = 0) → ∀ (k : n), ¬k ∈ s → (∀ (i j : n), A i j = B i j + c i * B k j) → det A = det B B : Matrix n n R c : n → R hs : ∀ (i_1 : n), ¬i_1 ∈ insert i s → c i_1 = 0 k : n hk : ¬k ∈ insert i s A_eq : ∀ (i j : n), A i j = B i j + c i * B k j hAi : A i = B i + c i • B k ⊢ n [PROOFSTEP] exact k [GOAL] case insert.x m : Type u_1 n : Type u_2 inst✝⁴ : DecidableEq n inst✝³ : Fintype n inst✝² : DecidableEq m inst✝¹ : Fintype m R : Type v inst✝ : CommRing R A : Matrix n n R i : n s : Finset n _hi : ¬i ∈ s ih : ∀ {B : Matrix n n R} (c : n → R), (∀ (i : n), ¬i ∈ s → c i = 0) → ∀ (k : n), ¬k ∈ s → (∀ (i j : n), A i j = B i j + c i * B k j) → det A = det B B : Matrix n n R c : n → R hs : ∀ (i_1 : n), ¬i_1 ∈ insert i s → c i_1 = 0 k : n hk : ¬k ∈ insert i s A_eq : ∀ (i j : n), A i j = B i j + c i * B k j hAi : A i = B i + c i • B k ⊢ ¬k ∈ s [PROOFSTEP] exact fun h => hk (Finset.mem_insert_of_mem h) [GOAL] case insert.x m : Type u_1 n : Type u_2 inst✝⁴ : DecidableEq n inst✝³ : Fintype n inst✝² : DecidableEq m inst✝¹ : Fintype m R : Type v inst✝ : CommRing R A : Matrix n n R i : n s : Finset n _hi : ¬i ∈ s ih : ∀ {B : Matrix n n R} (c : n → R), (∀ (i : n), ¬i ∈ s → c i = 0) → ∀ (k : n), ¬k ∈ s → (∀ (i j : n), A i j = B i j + c i * B k j) → det A = det B B : Matrix n n R c : n → R hs : ∀ (i_1 : n), ¬i_1 ∈ insert i s → c i_1 = 0 k : n hk : ¬k ∈ insert i s A_eq : ∀ (i j : n), A i j = B i j + c i * B k j hAi : A i = B i + c i • B k ⊢ ∀ (i_1 j : n), A i_1 j = updateRow B i (A i) i_1 j + update c i 0 i_1 * updateRow B i (A i) k j [PROOFSTEP] intro i' j' [GOAL] case insert.x m : Type u_1 n : Type u_2 inst✝⁴ : DecidableEq n inst✝³ : Fintype n inst✝² : DecidableEq m inst✝¹ : Fintype m R : Type v inst✝ : CommRing R A : Matrix n n R i : n s : Finset n _hi : ¬i ∈ s ih : ∀ {B : Matrix n n R} (c : n → R), (∀ (i : n), ¬i ∈ s → c i = 0) → ∀ (k : n), ¬k ∈ s → (∀ (i j : n), A i j = B i j + c i * B k j) → det A = det B B : Matrix n n R c : n → R hs : ∀ (i_1 : n), ¬i_1 ∈ insert i s → c i_1 = 0 k : n hk : ¬k ∈ insert i s A_eq : ∀ (i j : n), A i j = B i j + c i * B k j hAi : A i = B i + c i • B k i' j' : n ⊢ A i' j' = updateRow B i (A i) i' j' + update c i 0 i' * updateRow B i (A i) k j' [PROOFSTEP] rw [updateRow_apply, Function.update_apply] [GOAL] case insert.x m : Type u_1 n : Type u_2 inst✝⁴ : DecidableEq n inst✝³ : Fintype n inst✝² : DecidableEq m inst✝¹ : Fintype m R : Type v inst✝ : CommRing R A : Matrix n n R i : n s : Finset n _hi : ¬i ∈ s ih : ∀ {B : Matrix n n R} (c : n → R), (∀ (i : n), ¬i ∈ s → c i = 0) → ∀ (k : n), ¬k ∈ s → (∀ (i j : n), A i j = B i j + c i * B k j) → det A = det B B : Matrix n n R c : n → R hs : ∀ (i_1 : n), ¬i_1 ∈ insert i s → c i_1 = 0 k : n hk : ¬k ∈ insert i s A_eq : ∀ (i j : n), A i j = B i j + c i * B k j hAi : A i = B i + c i • B k i' j' : n ⊢ A i' j' = (if i' = i then A i j' else B i' j') + (if i' = i then 0 else c i') * updateRow B i (A i) k j' [PROOFSTEP] split_ifs with hi'i [GOAL] case pos m : Type u_1 n : Type u_2 inst✝⁴ : DecidableEq n inst✝³ : Fintype n inst✝² : DecidableEq m inst✝¹ : Fintype m R : Type v inst✝ : CommRing R A : Matrix n n R i : n s : Finset n _hi : ¬i ∈ s ih : ∀ {B : Matrix n n R} (c : n → R), (∀ (i : n), ¬i ∈ s → c i = 0) → ∀ (k : n), ¬k ∈ s → (∀ (i j : n), A i j = B i j + c i * B k j) → det A = det B B : Matrix n n R c : n → R hs : ∀ (i_1 : n), ¬i_1 ∈ insert i s → c i_1 = 0 k : n hk : ¬k ∈ insert i s A_eq : ∀ (i j : n), A i j = B i j + c i * B k j hAi : A i = B i + c i • B k i' j' : n hi'i : i' = i ⊢ A i' j' = A i j' + 0 * updateRow B i (A i) k j' [PROOFSTEP] simp [hi'i] [GOAL] case neg m : Type u_1 n : Type u_2 inst✝⁴ : DecidableEq n inst✝³ : Fintype n inst✝² : DecidableEq m inst✝¹ : Fintype m R : Type v inst✝ : CommRing R A : Matrix n n R i : n s : Finset n _hi : ¬i ∈ s ih : ∀ {B : Matrix n n R} (c : n → R), (∀ (i : n), ¬i ∈ s → c i = 0) → ∀ (k : n), ¬k ∈ s → (∀ (i j : n), A i j = B i j + c i * B k j) → det A = det B B : Matrix n n R c : n → R hs : ∀ (i_1 : n), ¬i_1 ∈ insert i s → c i_1 = 0 k : n hk : ¬k ∈ insert i s A_eq : ∀ (i j : n), A i j = B i j + c i * B k j hAi : A i = B i + c i • B k i' j' : n hi'i : ¬i' = i ⊢ A i' j' = B i' j' + c i' * updateRow B i (A i) k j' [PROOFSTEP] rw [A_eq, updateRow_ne fun h : k = i => hk <| h ▸ Finset.mem_insert_self k s] [GOAL] m : Type u_1 n✝ : Type u_2 inst✝⁴ : DecidableEq n✝ inst✝³ : Fintype n✝ inst✝² : DecidableEq m inst✝¹ : Fintype m R : Type v inst✝ : CommRing R n : ℕ k : Fin (n + 1) ⊢ ∀ (c : Fin n → R), (∀ (i : Fin n), k < Fin.succ i → c i = 0) → ∀ {M N : Matrix (Fin (Nat.succ n)) (Fin (Nat.succ n)) R}, (∀ (j : Fin (Nat.succ n)), M 0 j = N 0 j) → (∀ (i : Fin n) (j : Fin (Nat.succ n)), M (Fin.succ i) j = N (Fin.succ i) j + c i * M (Fin.castSucc i) j) → det M = det N [PROOFSTEP] refine' Fin.induction _ (fun k ih => _) k [GOAL] case refine'_1 m : Type u_1 n✝ : Type u_2 inst✝⁴ : DecidableEq n✝ inst✝³ : Fintype n✝ inst✝² : DecidableEq m inst✝¹ : Fintype m R : Type v inst✝ : CommRing R n : ℕ k : Fin (n + 1) ⊢ ∀ (c : Fin n → R), (∀ (i : Fin n), 0 < Fin.succ i → c i = 0) → ∀ {M N : Matrix (Fin (Nat.succ n)) (Fin (Nat.succ n)) R}, (∀ (j : Fin (Nat.succ n)), M 0 j = N 0 j) → (∀ (i : Fin n) (j : Fin (Nat.succ n)), M (Fin.succ i) j = N (Fin.succ i) j + c i * M (Fin.castSucc i) j) → det M = det N [PROOFSTEP] intro c hc M N h0 hsucc [GOAL] case refine'_2 m : Type u_1 n✝ : Type u_2 inst✝⁴ : DecidableEq n✝ inst✝³ : Fintype n✝ inst✝² : DecidableEq m inst✝¹ : Fintype m R : Type v inst✝ : CommRing R n : ℕ k✝ : Fin (n + 1) k : Fin n ih : ∀ (c : Fin n → R), (∀ (i : Fin n), Fin.castSucc k < Fin.succ i → c i = 0) → ∀ {M N : Matrix (Fin (Nat.succ n)) (Fin (Nat.succ n)) R}, (∀ (j : Fin (Nat.succ n)), M 0 j = N 0 j) → (∀ (i : Fin n) (j : Fin (Nat.succ n)), M (Fin.succ i) j = N (Fin.succ i) j + c i * M (Fin.castSucc i) j) → det M = det N ⊢ ∀ (c : Fin n → R), (∀ (i : Fin n), Fin.succ k < Fin.succ i → c i = 0) → ∀ {M N : Matrix (Fin (Nat.succ n)) (Fin (Nat.succ n)) R}, (∀ (j : Fin (Nat.succ n)), M 0 j = N 0 j) → (∀ (i : Fin n) (j : Fin (Nat.succ n)), M (Fin.succ i) j = N (Fin.succ i) j + c i * M (Fin.castSucc i) j) → det M = det N [PROOFSTEP] intro c hc M N h0 hsucc [GOAL] case refine'_1 m : Type u_1 n✝ : Type u_2 inst✝⁴ : DecidableEq n✝ inst✝³ : Fintype n✝ inst✝² : DecidableEq m inst✝¹ : Fintype m R : Type v inst✝ : CommRing R n : ℕ k : Fin (n + 1) c : Fin n → R hc : ∀ (i : Fin n), 0 < Fin.succ i → c i = 0 M N : Matrix (Fin (Nat.succ n)) (Fin (Nat.succ n)) R h0 : ∀ (j : Fin (Nat.succ n)), M 0 j = N 0 j hsucc : ∀ (i : Fin n) (j : Fin (Nat.succ n)), M (Fin.succ i) j = N (Fin.succ i) j + c i * M (Fin.castSucc i) j ⊢ det M = det N [PROOFSTEP] congr [GOAL] case refine'_1.e_M m : Type u_1 n✝ : Type u_2 inst✝⁴ : DecidableEq n✝ inst✝³ : Fintype n✝ inst✝² : DecidableEq m inst✝¹ : Fintype m R : Type v inst✝ : CommRing R n : ℕ k : Fin (n + 1) c : Fin n → R hc : ∀ (i : Fin n), 0 < Fin.succ i → c i = 0 M N : Matrix (Fin (Nat.succ n)) (Fin (Nat.succ n)) R h0 : ∀ (j : Fin (Nat.succ n)), M 0 j = N 0 j hsucc : ∀ (i : Fin n) (j : Fin (Nat.succ n)), M (Fin.succ i) j = N (Fin.succ i) j + c i * M (Fin.castSucc i) j ⊢ M = N [PROOFSTEP] ext i j [GOAL] case refine'_1.e_M.a.h m : Type u_1 n✝ : Type u_2 inst✝⁴ : DecidableEq n✝ inst✝³ : Fintype n✝ inst✝² : DecidableEq m inst✝¹ : Fintype m R : Type v inst✝ : CommRing R n : ℕ k : Fin (n + 1) c : Fin n → R hc : ∀ (i : Fin n), 0 < Fin.succ i → c i = 0 M N : Matrix (Fin (Nat.succ n)) (Fin (Nat.succ n)) R h0 : ∀ (j : Fin (Nat.succ n)), M 0 j = N 0 j hsucc : ∀ (i : Fin n) (j : Fin (Nat.succ n)), M (Fin.succ i) j = N (Fin.succ i) j + c i * M (Fin.castSucc i) j i j : Fin (Nat.succ n) ⊢ M i j = N i j [PROOFSTEP] refine' Fin.cases (h0 j) (fun i => _) i [GOAL] case refine'_1.e_M.a.h m : Type u_1 n✝ : Type u_2 inst✝⁴ : DecidableEq n✝ inst✝³ : Fintype n✝ inst✝² : DecidableEq m inst✝¹ : Fintype m R : Type v inst✝ : CommRing R n : ℕ k : Fin (n + 1) c : Fin n → R hc : ∀ (i : Fin n), 0 < Fin.succ i → c i = 0 M N : Matrix (Fin (Nat.succ n)) (Fin (Nat.succ n)) R h0 : ∀ (j : Fin (Nat.succ n)), M 0 j = N 0 j hsucc : ∀ (i : Fin n) (j : Fin (Nat.succ n)), M (Fin.succ i) j = N (Fin.succ i) j + c i * M (Fin.castSucc i) j i✝ j : Fin (Nat.succ n) i : Fin n ⊢ M (Fin.succ i) j = N (Fin.succ i) j [PROOFSTEP] rw [hsucc, hc i (Fin.succ_pos _), zero_mul, add_zero] [GOAL] case refine'_2 m : Type u_1 n✝ : Type u_2 inst✝⁴ : DecidableEq n✝ inst✝³ : Fintype n✝ inst✝² : DecidableEq m inst✝¹ : Fintype m R : Type v inst✝ : CommRing R n : ℕ k✝ : Fin (n + 1) k : Fin n ih : ∀ (c : Fin n → R), (∀ (i : Fin n), Fin.castSucc k < Fin.succ i → c i = 0) → ∀ {M N : Matrix (Fin (Nat.succ n)) (Fin (Nat.succ n)) R}, (∀ (j : Fin (Nat.succ n)), M 0 j = N 0 j) → (∀ (i : Fin n) (j : Fin (Nat.succ n)), M (Fin.succ i) j = N (Fin.succ i) j + c i * M (Fin.castSucc i) j) → det M = det N c : Fin n → R hc : ∀ (i : Fin n), Fin.succ k < Fin.succ i → c i = 0 M N : Matrix (Fin (Nat.succ n)) (Fin (Nat.succ n)) R h0 : ∀ (j : Fin (Nat.succ n)), M 0 j = N 0 j hsucc : ∀ (i : Fin n) (j : Fin (Nat.succ n)), M (Fin.succ i) j = N (Fin.succ i) j + c i * M (Fin.castSucc i) j ⊢ det M = det N [PROOFSTEP] set M' := updateRow M k.succ (N k.succ) with hM' [GOAL] case refine'_2 m : Type u_1 n✝ : Type u_2 inst✝⁴ : DecidableEq n✝ inst✝³ : Fintype n✝ inst✝² : DecidableEq m inst✝¹ : Fintype m R : Type v inst✝ : CommRing R n : ℕ k✝ : Fin (n + 1) k : Fin n ih : ∀ (c : Fin n → R), (∀ (i : Fin n), Fin.castSucc k < Fin.succ i → c i = 0) → ∀ {M N : Matrix (Fin (Nat.succ n)) (Fin (Nat.succ n)) R}, (∀ (j : Fin (Nat.succ n)), M 0 j = N 0 j) → (∀ (i : Fin n) (j : Fin (Nat.succ n)), M (Fin.succ i) j = N (Fin.succ i) j + c i * M (Fin.castSucc i) j) → det M = det N c : Fin n → R hc : ∀ (i : Fin n), Fin.succ k < Fin.succ i → c i = 0 M N : Matrix (Fin (Nat.succ n)) (Fin (Nat.succ n)) R h0 : ∀ (j : Fin (Nat.succ n)), M 0 j = N 0 j hsucc : ∀ (i : Fin n) (j : Fin (Nat.succ n)), M (Fin.succ i) j = N (Fin.succ i) j + c i * M (Fin.castSucc i) j M' : Matrix (Fin (Nat.succ n)) (Fin (Nat.succ n)) R := updateRow M (Fin.succ k) (N (Fin.succ k)) hM' : M' = updateRow M (Fin.succ k) (N (Fin.succ k)) ⊢ det M = det N [PROOFSTEP] have hM : M = updateRow M' k.succ (M' k.succ + c k • M (Fin.castSucc k)) := by ext i j by_cases hi : i = k.succ · simp [hi, hM', hsucc, updateRow_self] rw [updateRow_ne hi, hM', updateRow_ne hi] [GOAL] m : Type u_1 n✝ : Type u_2 inst✝⁴ : DecidableEq n✝ inst✝³ : Fintype n✝ inst✝² : DecidableEq m inst✝¹ : Fintype m R : Type v inst✝ : CommRing R n : ℕ k✝ : Fin (n + 1) k : Fin n ih : ∀ (c : Fin n → R), (∀ (i : Fin n), Fin.castSucc k < Fin.succ i → c i = 0) → ∀ {M N : Matrix (Fin (Nat.succ n)) (Fin (Nat.succ n)) R}, (∀ (j : Fin (Nat.succ n)), M 0 j = N 0 j) → (∀ (i : Fin n) (j : Fin (Nat.succ n)), M (Fin.succ i) j = N (Fin.succ i) j + c i * M (Fin.castSucc i) j) → det M = det N c : Fin n → R hc : ∀ (i : Fin n), Fin.succ k < Fin.succ i → c i = 0 M N : Matrix (Fin (Nat.succ n)) (Fin (Nat.succ n)) R h0 : ∀ (j : Fin (Nat.succ n)), M 0 j = N 0 j hsucc : ∀ (i : Fin n) (j : Fin (Nat.succ n)), M (Fin.succ i) j = N (Fin.succ i) j + c i * M (Fin.castSucc i) j M' : Matrix (Fin (Nat.succ n)) (Fin (Nat.succ n)) R := updateRow M (Fin.succ k) (N (Fin.succ k)) hM' : M' = updateRow M (Fin.succ k) (N (Fin.succ k)) ⊢ M = updateRow M' (Fin.succ k) (M' (Fin.succ k) + c k • M (Fin.castSucc k)) [PROOFSTEP] ext i j [GOAL] case a.h m : Type u_1 n✝ : Type u_2 inst✝⁴ : DecidableEq n✝ inst✝³ : Fintype n✝ inst✝² : DecidableEq m inst✝¹ : Fintype m R : Type v inst✝ : CommRing R n : ℕ k✝ : Fin (n + 1) k : Fin n ih : ∀ (c : Fin n → R), (∀ (i : Fin n), Fin.castSucc k < Fin.succ i → c i = 0) → ∀ {M N : Matrix (Fin (Nat.succ n)) (Fin (Nat.succ n)) R}, (∀ (j : Fin (Nat.succ n)), M 0 j = N 0 j) → (∀ (i : Fin n) (j : Fin (Nat.succ n)), M (Fin.succ i) j = N (Fin.succ i) j + c i * M (Fin.castSucc i) j) → det M = det N c : Fin n → R hc : ∀ (i : Fin n), Fin.succ k < Fin.succ i → c i = 0 M N : Matrix (Fin (Nat.succ n)) (Fin (Nat.succ n)) R h0 : ∀ (j : Fin (Nat.succ n)), M 0 j = N 0 j hsucc : ∀ (i : Fin n) (j : Fin (Nat.succ n)), M (Fin.succ i) j = N (Fin.succ i) j + c i * M (Fin.castSucc i) j M' : Matrix (Fin (Nat.succ n)) (Fin (Nat.succ n)) R := updateRow M (Fin.succ k) (N (Fin.succ k)) hM' : M' = updateRow M (Fin.succ k) (N (Fin.succ k)) i j : Fin (Nat.succ n) ⊢ M i j = updateRow M' (Fin.succ k) (M' (Fin.succ k) + c k • M (Fin.castSucc k)) i j [PROOFSTEP] by_cases hi : i = k.succ [GOAL] case pos m : Type u_1 n✝ : Type u_2 inst✝⁴ : DecidableEq n✝ inst✝³ : Fintype n✝ inst✝² : DecidableEq m inst✝¹ : Fintype m R : Type v inst✝ : CommRing R n : ℕ k✝ : Fin (n + 1) k : Fin n ih : ∀ (c : Fin n → R), (∀ (i : Fin n), Fin.castSucc k < Fin.succ i → c i = 0) → ∀ {M N : Matrix (Fin (Nat.succ n)) (Fin (Nat.succ n)) R}, (∀ (j : Fin (Nat.succ n)), M 0 j = N 0 j) → (∀ (i : Fin n) (j : Fin (Nat.succ n)), M (Fin.succ i) j = N (Fin.succ i) j + c i * M (Fin.castSucc i) j) → det M = det N c : Fin n → R hc : ∀ (i : Fin n), Fin.succ k < Fin.succ i → c i = 0 M N : Matrix (Fin (Nat.succ n)) (Fin (Nat.succ n)) R h0 : ∀ (j : Fin (Nat.succ n)), M 0 j = N 0 j hsucc : ∀ (i : Fin n) (j : Fin (Nat.succ n)), M (Fin.succ i) j = N (Fin.succ i) j + c i * M (Fin.castSucc i) j M' : Matrix (Fin (Nat.succ n)) (Fin (Nat.succ n)) R := updateRow M (Fin.succ k) (N (Fin.succ k)) hM' : M' = updateRow M (Fin.succ k) (N (Fin.succ k)) i j : Fin (Nat.succ n) hi : i = Fin.succ k ⊢ M i j = updateRow M' (Fin.succ k) (M' (Fin.succ k) + c k • M (Fin.castSucc k)) i j [PROOFSTEP] simp [hi, hM', hsucc, updateRow_self] [GOAL] case neg m : Type u_1 n✝ : Type u_2 inst✝⁴ : DecidableEq n✝ inst✝³ : Fintype n✝ inst✝² : DecidableEq m inst✝¹ : Fintype m R : Type v inst✝ : CommRing R n : ℕ k✝ : Fin (n + 1) k : Fin n ih : ∀ (c : Fin n → R), (∀ (i : Fin n), Fin.castSucc k < Fin.succ i → c i = 0) → ∀ {M N : Matrix (Fin (Nat.succ n)) (Fin (Nat.succ n)) R}, (∀ (j : Fin (Nat.succ n)), M 0 j = N 0 j) → (∀ (i : Fin n) (j : Fin (Nat.succ n)), M (Fin.succ i) j = N (Fin.succ i) j + c i * M (Fin.castSucc i) j) → det M = det N c : Fin n → R hc : ∀ (i : Fin n), Fin.succ k < Fin.succ i → c i = 0 M N : Matrix (Fin (Nat.succ n)) (Fin (Nat.succ n)) R h0 : ∀ (j : Fin (Nat.succ n)), M 0 j = N 0 j hsucc : ∀ (i : Fin n) (j : Fin (Nat.succ n)), M (Fin.succ i) j = N (Fin.succ i) j + c i * M (Fin.castSucc i) j M' : Matrix (Fin (Nat.succ n)) (Fin (Nat.succ n)) R := updateRow M (Fin.succ k) (N (Fin.succ k)) hM' : M' = updateRow M (Fin.succ k) (N (Fin.succ k)) i j : Fin (Nat.succ n) hi : ¬i = Fin.succ k ⊢ M i j = updateRow M' (Fin.succ k) (M' (Fin.succ k) + c k • M (Fin.castSucc k)) i j [PROOFSTEP] rw [updateRow_ne hi, hM', updateRow_ne hi] [GOAL] case refine'_2 m : Type u_1 n✝ : Type u_2 inst✝⁴ : DecidableEq n✝ inst✝³ : Fintype n✝ inst✝² : DecidableEq m inst✝¹ : Fintype m R : Type v inst✝ : CommRing R n : ℕ k✝ : Fin (n + 1) k : Fin n ih : ∀ (c : Fin n → R), (∀ (i : Fin n), Fin.castSucc k < Fin.succ i → c i = 0) → ∀ {M N : Matrix (Fin (Nat.succ n)) (Fin (Nat.succ n)) R}, (∀ (j : Fin (Nat.succ n)), M 0 j = N 0 j) → (∀ (i : Fin n) (j : Fin (Nat.succ n)), M (Fin.succ i) j = N (Fin.succ i) j + c i * M (Fin.castSucc i) j) → det M = det N c : Fin n → R hc : ∀ (i : Fin n), Fin.succ k < Fin.succ i → c i = 0 M N : Matrix (Fin (Nat.succ n)) (Fin (Nat.succ n)) R h0 : ∀ (j : Fin (Nat.succ n)), M 0 j = N 0 j hsucc : ∀ (i : Fin n) (j : Fin (Nat.succ n)), M (Fin.succ i) j = N (Fin.succ i) j + c i * M (Fin.castSucc i) j M' : Matrix (Fin (Nat.succ n)) (Fin (Nat.succ n)) R := updateRow M (Fin.succ k) (N (Fin.succ k)) hM' : M' = updateRow M (Fin.succ k) (N (Fin.succ k)) hM : M = updateRow M' (Fin.succ k) (M' (Fin.succ k) + c k • M (Fin.castSucc k)) ⊢ det M = det N [PROOFSTEP] have k_ne_succ : (Fin.castSucc k) ≠ k.succ := (Fin.castSucc_lt_succ k).ne [GOAL] case refine'_2 m : Type u_1 n✝ : Type u_2 inst✝⁴ : DecidableEq n✝ inst✝³ : Fintype n✝ inst✝² : DecidableEq m inst✝¹ : Fintype m R : Type v inst✝ : CommRing R n : ℕ k✝ : Fin (n + 1) k : Fin n ih : ∀ (c : Fin n → R), (∀ (i : Fin n), Fin.castSucc k < Fin.succ i → c i = 0) → ∀ {M N : Matrix (Fin (Nat.succ n)) (Fin (Nat.succ n)) R}, (∀ (j : Fin (Nat.succ n)), M 0 j = N 0 j) → (∀ (i : Fin n) (j : Fin (Nat.succ n)), M (Fin.succ i) j = N (Fin.succ i) j + c i * M (Fin.castSucc i) j) → det M = det N c : Fin n → R hc : ∀ (i : Fin n), Fin.succ k < Fin.succ i → c i = 0 M N : Matrix (Fin (Nat.succ n)) (Fin (Nat.succ n)) R h0 : ∀ (j : Fin (Nat.succ n)), M 0 j = N 0 j hsucc : ∀ (i : Fin n) (j : Fin (Nat.succ n)), M (Fin.succ i) j = N (Fin.succ i) j + c i * M (Fin.castSucc i) j M' : Matrix (Fin (Nat.succ n)) (Fin (Nat.succ n)) R := updateRow M (Fin.succ k) (N (Fin.succ k)) hM' : M' = updateRow M (Fin.succ k) (N (Fin.succ k)) hM : M = updateRow M' (Fin.succ k) (M' (Fin.succ k) + c k • M (Fin.castSucc k)) k_ne_succ : Fin.castSucc k ≠ Fin.succ k ⊢ det M = det N [PROOFSTEP] have M_k : M (Fin.castSucc k) = M' (Fin.castSucc k) := (updateRow_ne k_ne_succ).symm [GOAL] case refine'_2 m : Type u_1 n✝ : Type u_2 inst✝⁴ : DecidableEq n✝ inst✝³ : Fintype n✝ inst✝² : DecidableEq m inst✝¹ : Fintype m R : Type v inst✝ : CommRing R n : ℕ k✝ : Fin (n + 1) k : Fin n ih : ∀ (c : Fin n → R), (∀ (i : Fin n), Fin.castSucc k < Fin.succ i → c i = 0) → ∀ {M N : Matrix (Fin (Nat.succ n)) (Fin (Nat.succ n)) R}, (∀ (j : Fin (Nat.succ n)), M 0 j = N 0 j) → (∀ (i : Fin n) (j : Fin (Nat.succ n)), M (Fin.succ i) j = N (Fin.succ i) j + c i * M (Fin.castSucc i) j) → det M = det N c : Fin n → R hc : ∀ (i : Fin n), Fin.succ k < Fin.succ i → c i = 0 M N : Matrix (Fin (Nat.succ n)) (Fin (Nat.succ n)) R h0 : ∀ (j : Fin (Nat.succ n)), M 0 j = N 0 j hsucc : ∀ (i : Fin n) (j : Fin (Nat.succ n)), M (Fin.succ i) j = N (Fin.succ i) j + c i * M (Fin.castSucc i) j M' : Matrix (Fin (Nat.succ n)) (Fin (Nat.succ n)) R := updateRow M (Fin.succ k) (N (Fin.succ k)) hM' : M' = updateRow M (Fin.succ k) (N (Fin.succ k)) hM : M = updateRow M' (Fin.succ k) (M' (Fin.succ k) + c k • M (Fin.castSucc k)) k_ne_succ : Fin.castSucc k ≠ Fin.succ k M_k : M (Fin.castSucc k) = M' (Fin.castSucc k) ⊢ det M = det N [PROOFSTEP] rw [hM, M_k, det_updateRow_add_smul_self M' k_ne_succ.symm, ih (Function.update c k 0)] [GOAL] case refine'_2._hc m : Type u_1 n✝ : Type u_2 inst✝⁴ : DecidableEq n✝ inst✝³ : Fintype n✝ inst✝² : DecidableEq m inst✝¹ : Fintype m R : Type v inst✝ : CommRing R n : ℕ k✝ : Fin (n + 1) k : Fin n ih : ∀ (c : Fin n → R), (∀ (i : Fin n), Fin.castSucc k < Fin.succ i → c i = 0) → ∀ {M N : Matrix (Fin (Nat.succ n)) (Fin (Nat.succ n)) R}, (∀ (j : Fin (Nat.succ n)), M 0 j = N 0 j) → (∀ (i : Fin n) (j : Fin (Nat.succ n)), M (Fin.succ i) j = N (Fin.succ i) j + c i * M (Fin.castSucc i) j) → det M = det N c : Fin n → R hc : ∀ (i : Fin n), Fin.succ k < Fin.succ i → c i = 0 M N : Matrix (Fin (Nat.succ n)) (Fin (Nat.succ n)) R h0 : ∀ (j : Fin (Nat.succ n)), M 0 j = N 0 j hsucc : ∀ (i : Fin n) (j : Fin (Nat.succ n)), M (Fin.succ i) j = N (Fin.succ i) j + c i * M (Fin.castSucc i) j M' : Matrix (Fin (Nat.succ n)) (Fin (Nat.succ n)) R := updateRow M (Fin.succ k) (N (Fin.succ k)) hM' : M' = updateRow M (Fin.succ k) (N (Fin.succ k)) hM : M = updateRow M' (Fin.succ k) (M' (Fin.succ k) + c k • M (Fin.castSucc k)) k_ne_succ : Fin.castSucc k ≠ Fin.succ k M_k : M (Fin.castSucc k) = M' (Fin.castSucc k) ⊢ ∀ (i : Fin n), Fin.castSucc k < Fin.succ i → update c k 0 i = 0 [PROOFSTEP] intro i hi [GOAL] case refine'_2._hc m : Type u_1 n✝ : Type u_2 inst✝⁴ : DecidableEq n✝ inst✝³ : Fintype n✝ inst✝² : DecidableEq m inst✝¹ : Fintype m R : Type v inst✝ : CommRing R n : ℕ k✝ : Fin (n + 1) k : Fin n ih : ∀ (c : Fin n → R), (∀ (i : Fin n), Fin.castSucc k < Fin.succ i → c i = 0) → ∀ {M N : Matrix (Fin (Nat.succ n)) (Fin (Nat.succ n)) R}, (∀ (j : Fin (Nat.succ n)), M 0 j = N 0 j) → (∀ (i : Fin n) (j : Fin (Nat.succ n)), M (Fin.succ i) j = N (Fin.succ i) j + c i * M (Fin.castSucc i) j) → det M = det N c : Fin n → R hc : ∀ (i : Fin n), Fin.succ k < Fin.succ i → c i = 0 M N : Matrix (Fin (Nat.succ n)) (Fin (Nat.succ n)) R h0 : ∀ (j : Fin (Nat.succ n)), M 0 j = N 0 j hsucc : ∀ (i : Fin n) (j : Fin (Nat.succ n)), M (Fin.succ i) j = N (Fin.succ i) j + c i * M (Fin.castSucc i) j M' : Matrix (Fin (Nat.succ n)) (Fin (Nat.succ n)) R := updateRow M (Fin.succ k) (N (Fin.succ k)) hM' : M' = updateRow M (Fin.succ k) (N (Fin.succ k)) hM : M = updateRow M' (Fin.succ k) (M' (Fin.succ k) + c k • M (Fin.castSucc k)) k_ne_succ : Fin.castSucc k ≠ Fin.succ k M_k : M (Fin.castSucc k) = M' (Fin.castSucc k) i : Fin n hi : Fin.castSucc k < Fin.succ i ⊢ update c k 0 i = 0 [PROOFSTEP] rw [Fin.lt_iff_val_lt_val, Fin.coe_castSucc, Fin.val_succ, Nat.lt_succ_iff] at hi [GOAL] case refine'_2._hc m : Type u_1 n✝ : Type u_2 inst✝⁴ : DecidableEq n✝ inst✝³ : Fintype n✝ inst✝² : DecidableEq m inst✝¹ : Fintype m R : Type v inst✝ : CommRing R n : ℕ k✝ : Fin (n + 1) k : Fin n ih : ∀ (c : Fin n → R), (∀ (i : Fin n), Fin.castSucc k < Fin.succ i → c i = 0) → ∀ {M N : Matrix (Fin (Nat.succ n)) (Fin (Nat.succ n)) R}, (∀ (j : Fin (Nat.succ n)), M 0 j = N 0 j) → (∀ (i : Fin n) (j : Fin (Nat.succ n)), M (Fin.succ i) j = N (Fin.succ i) j + c i * M (Fin.castSucc i) j) → det M = det N c : Fin n → R hc : ∀ (i : Fin n), Fin.succ k < Fin.succ i → c i = 0 M N : Matrix (Fin (Nat.succ n)) (Fin (Nat.succ n)) R h0 : ∀ (j : Fin (Nat.succ n)), M 0 j = N 0 j hsucc : ∀ (i : Fin n) (j : Fin (Nat.succ n)), M (Fin.succ i) j = N (Fin.succ i) j + c i * M (Fin.castSucc i) j M' : Matrix (Fin (Nat.succ n)) (Fin (Nat.succ n)) R := updateRow M (Fin.succ k) (N (Fin.succ k)) hM' : M' = updateRow M (Fin.succ k) (N (Fin.succ k)) hM : M = updateRow M' (Fin.succ k) (M' (Fin.succ k) + c k • M (Fin.castSucc k)) k_ne_succ : Fin.castSucc k ≠ Fin.succ k M_k : M (Fin.castSucc k) = M' (Fin.castSucc k) i : Fin n hi : ↑k ≤ ↑i ⊢ update c k 0 i = 0 [PROOFSTEP] rw [Function.update_apply] [GOAL] case refine'_2._hc m : Type u_1 n✝ : Type u_2 inst✝⁴ : DecidableEq n✝ inst✝³ : Fintype n✝ inst✝² : DecidableEq m inst✝¹ : Fintype m R : Type v inst✝ : CommRing R n : ℕ k✝ : Fin (n + 1) k : Fin n ih : ∀ (c : Fin n → R), (∀ (i : Fin n), Fin.castSucc k < Fin.succ i → c i = 0) → ∀ {M N : Matrix (Fin (Nat.succ n)) (Fin (Nat.succ n)) R}, (∀ (j : Fin (Nat.succ n)), M 0 j = N 0 j) → (∀ (i : Fin n) (j : Fin (Nat.succ n)), M (Fin.succ i) j = N (Fin.succ i) j + c i * M (Fin.castSucc i) j) → det M = det N c : Fin n → R hc : ∀ (i : Fin n), Fin.succ k < Fin.succ i → c i = 0 M N : Matrix (Fin (Nat.succ n)) (Fin (Nat.succ n)) R h0 : ∀ (j : Fin (Nat.succ n)), M 0 j = N 0 j hsucc : ∀ (i : Fin n) (j : Fin (Nat.succ n)), M (Fin.succ i) j = N (Fin.succ i) j + c i * M (Fin.castSucc i) j M' : Matrix (Fin (Nat.succ n)) (Fin (Nat.succ n)) R := updateRow M (Fin.succ k) (N (Fin.succ k)) hM' : M' = updateRow M (Fin.succ k) (N (Fin.succ k)) hM : M = updateRow M' (Fin.succ k) (M' (Fin.succ k) + c k • M (Fin.castSucc k)) k_ne_succ : Fin.castSucc k ≠ Fin.succ k M_k : M (Fin.castSucc k) = M' (Fin.castSucc k) i : Fin n hi : ↑k ≤ ↑i ⊢ (if i = k then 0 else c i) = 0 [PROOFSTEP] split_ifs with hik [GOAL] case pos m : Type u_1 n✝ : Type u_2 inst✝⁴ : DecidableEq n✝ inst✝³ : Fintype n✝ inst✝² : DecidableEq m inst✝¹ : Fintype m R : Type v inst✝ : CommRing R n : ℕ k✝ : Fin (n + 1) k : Fin n ih : ∀ (c : Fin n → R), (∀ (i : Fin n), Fin.castSucc k < Fin.succ i → c i = 0) → ∀ {M N : Matrix (Fin (Nat.succ n)) (Fin (Nat.succ n)) R}, (∀ (j : Fin (Nat.succ n)), M 0 j = N 0 j) → (∀ (i : Fin n) (j : Fin (Nat.succ n)), M (Fin.succ i) j = N (Fin.succ i) j + c i * M (Fin.castSucc i) j) → det M = det N c : Fin n → R hc : ∀ (i : Fin n), Fin.succ k < Fin.succ i → c i = 0 M N : Matrix (Fin (Nat.succ n)) (Fin (Nat.succ n)) R h0 : ∀ (j : Fin (Nat.succ n)), M 0 j = N 0 j hsucc : ∀ (i : Fin n) (j : Fin (Nat.succ n)), M (Fin.succ i) j = N (Fin.succ i) j + c i * M (Fin.castSucc i) j M' : Matrix (Fin (Nat.succ n)) (Fin (Nat.succ n)) R := updateRow M (Fin.succ k) (N (Fin.succ k)) hM' : M' = updateRow M (Fin.succ k) (N (Fin.succ k)) hM : M = updateRow M' (Fin.succ k) (M' (Fin.succ k) + c k • M (Fin.castSucc k)) k_ne_succ : Fin.castSucc k ≠ Fin.succ k M_k : M (Fin.castSucc k) = M' (Fin.castSucc k) i : Fin n hi : ↑k ≤ ↑i hik : i = k ⊢ 0 = 0 [PROOFSTEP] rfl [GOAL] case neg m : Type u_1 n✝ : Type u_2 inst✝⁴ : DecidableEq n✝ inst✝³ : Fintype n✝ inst✝² : DecidableEq m inst✝¹ : Fintype m R : Type v inst✝ : CommRing R n : ℕ k✝ : Fin (n + 1) k : Fin n ih : ∀ (c : Fin n → R), (∀ (i : Fin n), Fin.castSucc k < Fin.succ i → c i = 0) → ∀ {M N : Matrix (Fin (Nat.succ n)) (Fin (Nat.succ n)) R}, (∀ (j : Fin (Nat.succ n)), M 0 j = N 0 j) → (∀ (i : Fin n) (j : Fin (Nat.succ n)), M (Fin.succ i) j = N (Fin.succ i) j + c i * M (Fin.castSucc i) j) → det M = det N c : Fin n → R hc : ∀ (i : Fin n), Fin.succ k < Fin.succ i → c i = 0 M N : Matrix (Fin (Nat.succ n)) (Fin (Nat.succ n)) R h0 : ∀ (j : Fin (Nat.succ n)), M 0 j = N 0 j hsucc : ∀ (i : Fin n) (j : Fin (Nat.succ n)), M (Fin.succ i) j = N (Fin.succ i) j + c i * M (Fin.castSucc i) j M' : Matrix (Fin (Nat.succ n)) (Fin (Nat.succ n)) R := updateRow M (Fin.succ k) (N (Fin.succ k)) hM' : M' = updateRow M (Fin.succ k) (N (Fin.succ k)) hM : M = updateRow M' (Fin.succ k) (M' (Fin.succ k) + c k • M (Fin.castSucc k)) k_ne_succ : Fin.castSucc k ≠ Fin.succ k M_k : M (Fin.castSucc k) = M' (Fin.castSucc k) i : Fin n hi : ↑k ≤ ↑i hik : ¬i = k ⊢ c i = 0 [PROOFSTEP] exact hc _ (Fin.succ_lt_succ_iff.mpr (lt_of_le_of_ne hi (Ne.symm hik))) [GOAL] case refine'_2._h0 m : Type u_1 n✝ : Type u_2 inst✝⁴ : DecidableEq n✝ inst✝³ : Fintype n✝ inst✝² : DecidableEq m inst✝¹ : Fintype m R : Type v inst✝ : CommRing R n : ℕ k✝ : Fin (n + 1) k : Fin n ih : ∀ (c : Fin n → R), (∀ (i : Fin n), Fin.castSucc k < Fin.succ i → c i = 0) → ∀ {M N : Matrix (Fin (Nat.succ n)) (Fin (Nat.succ n)) R}, (∀ (j : Fin (Nat.succ n)), M 0 j = N 0 j) → (∀ (i : Fin n) (j : Fin (Nat.succ n)), M (Fin.succ i) j = N (Fin.succ i) j + c i * M (Fin.castSucc i) j) → det M = det N c : Fin n → R hc : ∀ (i : Fin n), Fin.succ k < Fin.succ i → c i = 0 M N : Matrix (Fin (Nat.succ n)) (Fin (Nat.succ n)) R h0 : ∀ (j : Fin (Nat.succ n)), M 0 j = N 0 j hsucc : ∀ (i : Fin n) (j : Fin (Nat.succ n)), M (Fin.succ i) j = N (Fin.succ i) j + c i * M (Fin.castSucc i) j M' : Matrix (Fin (Nat.succ n)) (Fin (Nat.succ n)) R := updateRow M (Fin.succ k) (N (Fin.succ k)) hM' : M' = updateRow M (Fin.succ k) (N (Fin.succ k)) hM : M = updateRow M' (Fin.succ k) (M' (Fin.succ k) + c k • M (Fin.castSucc k)) k_ne_succ : Fin.castSucc k ≠ Fin.succ k M_k : M (Fin.castSucc k) = M' (Fin.castSucc k) ⊢ ∀ (j : Fin (Nat.succ n)), M' 0 j = N 0 j [PROOFSTEP] rwa [hM', updateRow_ne (Fin.succ_ne_zero _).symm] [GOAL] case refine'_2._hsucc m : Type u_1 n✝ : Type u_2 inst✝⁴ : DecidableEq n✝ inst✝³ : Fintype n✝ inst✝² : DecidableEq m inst✝¹ : Fintype m R : Type v inst✝ : CommRing R n : ℕ k✝ : Fin (n + 1) k : Fin n ih : ∀ (c : Fin n → R), (∀ (i : Fin n), Fin.castSucc k < Fin.succ i → c i = 0) → ∀ {M N : Matrix (Fin (Nat.succ n)) (Fin (Nat.succ n)) R}, (∀ (j : Fin (Nat.succ n)), M 0 j = N 0 j) → (∀ (i : Fin n) (j : Fin (Nat.succ n)), M (Fin.succ i) j = N (Fin.succ i) j + c i * M (Fin.castSucc i) j) → det M = det N c : Fin n → R hc : ∀ (i : Fin n), Fin.succ k < Fin.succ i → c i = 0 M N : Matrix (Fin (Nat.succ n)) (Fin (Nat.succ n)) R h0 : ∀ (j : Fin (Nat.succ n)), M 0 j = N 0 j hsucc : ∀ (i : Fin n) (j : Fin (Nat.succ n)), M (Fin.succ i) j = N (Fin.succ i) j + c i * M (Fin.castSucc i) j M' : Matrix (Fin (Nat.succ n)) (Fin (Nat.succ n)) R := updateRow M (Fin.succ k) (N (Fin.succ k)) hM' : M' = updateRow M (Fin.succ k) (N (Fin.succ k)) hM : M = updateRow M' (Fin.succ k) (M' (Fin.succ k) + c k • M (Fin.castSucc k)) k_ne_succ : Fin.castSucc k ≠ Fin.succ k M_k : M (Fin.castSucc k) = M' (Fin.castSucc k) ⊢ ∀ (i : Fin n) (j : Fin (Nat.succ n)), M' (Fin.succ i) j = N (Fin.succ i) j + update c k 0 i * M' (Fin.castSucc i) j [PROOFSTEP] intro i j [GOAL] case refine'_2._hsucc m : Type u_1 n✝ : Type u_2 inst✝⁴ : DecidableEq n✝ inst✝³ : Fintype n✝ inst✝² : DecidableEq m inst✝¹ : Fintype m R : Type v inst✝ : CommRing R n : ℕ k✝ : Fin (n + 1) k : Fin n ih : ∀ (c : Fin n → R), (∀ (i : Fin n), Fin.castSucc k < Fin.succ i → c i = 0) → ∀ {M N : Matrix (Fin (Nat.succ n)) (Fin (Nat.succ n)) R}, (∀ (j : Fin (Nat.succ n)), M 0 j = N 0 j) → (∀ (i : Fin n) (j : Fin (Nat.succ n)), M (Fin.succ i) j = N (Fin.succ i) j + c i * M (Fin.castSucc i) j) → det M = det N c : Fin n → R hc : ∀ (i : Fin n), Fin.succ k < Fin.succ i → c i = 0 M N : Matrix (Fin (Nat.succ n)) (Fin (Nat.succ n)) R h0 : ∀ (j : Fin (Nat.succ n)), M 0 j = N 0 j hsucc : ∀ (i : Fin n) (j : Fin (Nat.succ n)), M (Fin.succ i) j = N (Fin.succ i) j + c i * M (Fin.castSucc i) j M' : Matrix (Fin (Nat.succ n)) (Fin (Nat.succ n)) R := updateRow M (Fin.succ k) (N (Fin.succ k)) hM' : M' = updateRow M (Fin.succ k) (N (Fin.succ k)) hM : M = updateRow M' (Fin.succ k) (M' (Fin.succ k) + c k • M (Fin.castSucc k)) k_ne_succ : Fin.castSucc k ≠ Fin.succ k M_k : M (Fin.castSucc k) = M' (Fin.castSucc k) i : Fin n j : Fin (Nat.succ n) ⊢ M' (Fin.succ i) j = N (Fin.succ i) j + update c k 0 i * M' (Fin.castSucc i) j [PROOFSTEP] rw [Function.update_apply] [GOAL] case refine'_2._hsucc m : Type u_1 n✝ : Type u_2 inst✝⁴ : DecidableEq n✝ inst✝³ : Fintype n✝ inst✝² : DecidableEq m inst✝¹ : Fintype m R : Type v inst✝ : CommRing R n : ℕ k✝ : Fin (n + 1) k : Fin n ih : ∀ (c : Fin n → R), (∀ (i : Fin n), Fin.castSucc k < Fin.succ i → c i = 0) → ∀ {M N : Matrix (Fin (Nat.succ n)) (Fin (Nat.succ n)) R}, (∀ (j : Fin (Nat.succ n)), M 0 j = N 0 j) → (∀ (i : Fin n) (j : Fin (Nat.succ n)), M (Fin.succ i) j = N (Fin.succ i) j + c i * M (Fin.castSucc i) j) → det M = det N c : Fin n → R hc : ∀ (i : Fin n), Fin.succ k < Fin.succ i → c i = 0 M N : Matrix (Fin (Nat.succ n)) (Fin (Nat.succ n)) R h0 : ∀ (j : Fin (Nat.succ n)), M 0 j = N 0 j hsucc : ∀ (i : Fin n) (j : Fin (Nat.succ n)), M (Fin.succ i) j = N (Fin.succ i) j + c i * M (Fin.castSucc i) j M' : Matrix (Fin (Nat.succ n)) (Fin (Nat.succ n)) R := updateRow M (Fin.succ k) (N (Fin.succ k)) hM' : M' = updateRow M (Fin.succ k) (N (Fin.succ k)) hM : M = updateRow M' (Fin.succ k) (M' (Fin.succ k) + c k • M (Fin.castSucc k)) k_ne_succ : Fin.castSucc k ≠ Fin.succ k M_k : M (Fin.castSucc k) = M' (Fin.castSucc k) i : Fin n j : Fin (Nat.succ n) ⊢ M' (Fin.succ i) j = N (Fin.succ i) j + (if i = k then 0 else c i) * M' (Fin.castSucc i) j [PROOFSTEP] split_ifs with hik [GOAL] case pos m : Type u_1 n✝ : Type u_2 inst✝⁴ : DecidableEq n✝ inst✝³ : Fintype n✝ inst✝² : DecidableEq m inst✝¹ : Fintype m R : Type v inst✝ : CommRing R n : ℕ k✝ : Fin (n + 1) k : Fin n ih : ∀ (c : Fin n → R), (∀ (i : Fin n), Fin.castSucc k < Fin.succ i → c i = 0) → ∀ {M N : Matrix (Fin (Nat.succ n)) (Fin (Nat.succ n)) R}, (∀ (j : Fin (Nat.succ n)), M 0 j = N 0 j) → (∀ (i : Fin n) (j : Fin (Nat.succ n)), M (Fin.succ i) j = N (Fin.succ i) j + c i * M (Fin.castSucc i) j) → det M = det N c : Fin n → R hc : ∀ (i : Fin n), Fin.succ k < Fin.succ i → c i = 0 M N : Matrix (Fin (Nat.succ n)) (Fin (Nat.succ n)) R h0 : ∀ (j : Fin (Nat.succ n)), M 0 j = N 0 j hsucc : ∀ (i : Fin n) (j : Fin (Nat.succ n)), M (Fin.succ i) j = N (Fin.succ i) j + c i * M (Fin.castSucc i) j M' : Matrix (Fin (Nat.succ n)) (Fin (Nat.succ n)) R := updateRow M (Fin.succ k) (N (Fin.succ k)) hM' : M' = updateRow M (Fin.succ k) (N (Fin.succ k)) hM : M = updateRow M' (Fin.succ k) (M' (Fin.succ k) + c k • M (Fin.castSucc k)) k_ne_succ : Fin.castSucc k ≠ Fin.succ k M_k : M (Fin.castSucc k) = M' (Fin.castSucc k) i : Fin n j : Fin (Nat.succ n) hik : i = k ⊢ M' (Fin.succ i) j = N (Fin.succ i) j + 0 * M' (Fin.castSucc i) j [PROOFSTEP] rw [zero_mul, add_zero, hM', hik, updateRow_self] [GOAL] case neg m : Type u_1 n✝ : Type u_2 inst✝⁴ : DecidableEq n✝ inst✝³ : Fintype n✝ inst✝² : DecidableEq m inst✝¹ : Fintype m R : Type v inst✝ : CommRing R n : ℕ k✝ : Fin (n + 1) k : Fin n ih : ∀ (c : Fin n → R), (∀ (i : Fin n), Fin.castSucc k < Fin.succ i → c i = 0) → ∀ {M N : Matrix (Fin (Nat.succ n)) (Fin (Nat.succ n)) R}, (∀ (j : Fin (Nat.succ n)), M 0 j = N 0 j) → (∀ (i : Fin n) (j : Fin (Nat.succ n)), M (Fin.succ i) j = N (Fin.succ i) j + c i * M (Fin.castSucc i) j) → det M = det N c : Fin n → R hc : ∀ (i : Fin n), Fin.succ k < Fin.succ i → c i = 0 M N : Matrix (Fin (Nat.succ n)) (Fin (Nat.succ n)) R h0 : ∀ (j : Fin (Nat.succ n)), M 0 j = N 0 j hsucc : ∀ (i : Fin n) (j : Fin (Nat.succ n)), M (Fin.succ i) j = N (Fin.succ i) j + c i * M (Fin.castSucc i) j M' : Matrix (Fin (Nat.succ n)) (Fin (Nat.succ n)) R := updateRow M (Fin.succ k) (N (Fin.succ k)) hM' : M' = updateRow M (Fin.succ k) (N (Fin.succ k)) hM : M = updateRow M' (Fin.succ k) (M' (Fin.succ k) + c k • M (Fin.castSucc k)) k_ne_succ : Fin.castSucc k ≠ Fin.succ k M_k : M (Fin.castSucc k) = M' (Fin.castSucc k) i : Fin n j : Fin (Nat.succ n) hik : ¬i = k ⊢ M' (Fin.succ i) j = N (Fin.succ i) j + c i * M' (Fin.castSucc i) j [PROOFSTEP] rw [hM', updateRow_ne ((Fin.succ_injective _).ne hik), hsucc] [GOAL] case neg m : Type u_1 n✝ : Type u_2 inst✝⁴ : DecidableEq n✝ inst✝³ : Fintype n✝ inst✝² : DecidableEq m inst✝¹ : Fintype m R : Type v inst✝ : CommRing R n : ℕ k✝ : Fin (n + 1) k : Fin n ih : ∀ (c : Fin n → R), (∀ (i : Fin n), Fin.castSucc k < Fin.succ i → c i = 0) → ∀ {M N : Matrix (Fin (Nat.succ n)) (Fin (Nat.succ n)) R}, (∀ (j : Fin (Nat.succ n)), M 0 j = N 0 j) → (∀ (i : Fin n) (j : Fin (Nat.succ n)), M (Fin.succ i) j = N (Fin.succ i) j + c i * M (Fin.castSucc i) j) → det M = det N c : Fin n → R hc : ∀ (i : Fin n), Fin.succ k < Fin.succ i → c i = 0 M N : Matrix (Fin (Nat.succ n)) (Fin (Nat.succ n)) R h0 : ∀ (j : Fin (Nat.succ n)), M 0 j = N 0 j hsucc : ∀ (i : Fin n) (j : Fin (Nat.succ n)), M (Fin.succ i) j = N (Fin.succ i) j + c i * M (Fin.castSucc i) j M' : Matrix (Fin (Nat.succ n)) (Fin (Nat.succ n)) R := updateRow M (Fin.succ k) (N (Fin.succ k)) hM' : M' = updateRow M (Fin.succ k) (N (Fin.succ k)) hM : M = updateRow M' (Fin.succ k) (M' (Fin.succ k) + c k • M (Fin.castSucc k)) k_ne_succ : Fin.castSucc k ≠ Fin.succ k M_k : M (Fin.castSucc k) = M' (Fin.castSucc k) i : Fin n j : Fin (Nat.succ n) hik : ¬i = k ⊢ N (Fin.succ i) j + c i * M (Fin.castSucc i) j = N (Fin.succ i) j + c i * updateRow M (Fin.succ k) (N (Fin.succ k)) (Fin.castSucc i) j [PROOFSTEP] by_cases hik2 : k < i [GOAL] case pos m : Type u_1 n✝ : Type u_2 inst✝⁴ : DecidableEq n✝ inst✝³ : Fintype n✝ inst✝² : DecidableEq m inst✝¹ : Fintype m R : Type v inst✝ : CommRing R n : ℕ k✝ : Fin (n + 1) k : Fin n ih : ∀ (c : Fin n → R), (∀ (i : Fin n), Fin.castSucc k < Fin.succ i → c i = 0) → ∀ {M N : Matrix (Fin (Nat.succ n)) (Fin (Nat.succ n)) R}, (∀ (j : Fin (Nat.succ n)), M 0 j = N 0 j) → (∀ (i : Fin n) (j : Fin (Nat.succ n)), M (Fin.succ i) j = N (Fin.succ i) j + c i * M (Fin.castSucc i) j) → det M = det N c : Fin n → R hc : ∀ (i : Fin n), Fin.succ k < Fin.succ i → c i = 0 M N : Matrix (Fin (Nat.succ n)) (Fin (Nat.succ n)) R h0 : ∀ (j : Fin (Nat.succ n)), M 0 j = N 0 j hsucc : ∀ (i : Fin n) (j : Fin (Nat.succ n)), M (Fin.succ i) j = N (Fin.succ i) j + c i * M (Fin.castSucc i) j M' : Matrix (Fin (Nat.succ n)) (Fin (Nat.succ n)) R := updateRow M (Fin.succ k) (N (Fin.succ k)) hM' : M' = updateRow M (Fin.succ k) (N (Fin.succ k)) hM : M = updateRow M' (Fin.succ k) (M' (Fin.succ k) + c k • M (Fin.castSucc k)) k_ne_succ : Fin.castSucc k ≠ Fin.succ k M_k : M (Fin.castSucc k) = M' (Fin.castSucc k) i : Fin n j : Fin (Nat.succ n) hik : ¬i = k hik2 : k < i ⊢ N (Fin.succ i) j + c i * M (Fin.castSucc i) j = N (Fin.succ i) j + c i * updateRow M (Fin.succ k) (N (Fin.succ k)) (Fin.castSucc i) j [PROOFSTEP] simp [hc i (Fin.succ_lt_succ_iff.mpr hik2)] [GOAL] case neg m : Type u_1 n✝ : Type u_2 inst✝⁴ : DecidableEq n✝ inst✝³ : Fintype n✝ inst✝² : DecidableEq m inst✝¹ : Fintype m R : Type v inst✝ : CommRing R n : ℕ k✝ : Fin (n + 1) k : Fin n ih : ∀ (c : Fin n → R), (∀ (i : Fin n), Fin.castSucc k < Fin.succ i → c i = 0) → ∀ {M N : Matrix (Fin (Nat.succ n)) (Fin (Nat.succ n)) R}, (∀ (j : Fin (Nat.succ n)), M 0 j = N 0 j) → (∀ (i : Fin n) (j : Fin (Nat.succ n)), M (Fin.succ i) j = N (Fin.succ i) j + c i * M (Fin.castSucc i) j) → det M = det N c : Fin n → R hc : ∀ (i : Fin n), Fin.succ k < Fin.succ i → c i = 0 M N : Matrix (Fin (Nat.succ n)) (Fin (Nat.succ n)) R h0 : ∀ (j : Fin (Nat.succ n)), M 0 j = N 0 j hsucc : ∀ (i : Fin n) (j : Fin (Nat.succ n)), M (Fin.succ i) j = N (Fin.succ i) j + c i * M (Fin.castSucc i) j M' : Matrix (Fin (Nat.succ n)) (Fin (Nat.succ n)) R := updateRow M (Fin.succ k) (N (Fin.succ k)) hM' : M' = updateRow M (Fin.succ k) (N (Fin.succ k)) hM : M = updateRow M' (Fin.succ k) (M' (Fin.succ k) + c k • M (Fin.castSucc k)) k_ne_succ : Fin.castSucc k ≠ Fin.succ k M_k : M (Fin.castSucc k) = M' (Fin.castSucc k) i : Fin n j : Fin (Nat.succ n) hik : ¬i = k hik2 : ¬k < i ⊢ N (Fin.succ i) j + c i * M (Fin.castSucc i) j = N (Fin.succ i) j + c i * updateRow M (Fin.succ k) (N (Fin.succ k)) (Fin.castSucc i) j [PROOFSTEP] rw [updateRow_ne] [GOAL] case neg m : Type u_1 n✝ : Type u_2 inst✝⁴ : DecidableEq n✝ inst✝³ : Fintype n✝ inst✝² : DecidableEq m inst✝¹ : Fintype m R : Type v inst✝ : CommRing R n : ℕ k✝ : Fin (n + 1) k : Fin n ih : ∀ (c : Fin n → R), (∀ (i : Fin n), Fin.castSucc k < Fin.succ i → c i = 0) → ∀ {M N : Matrix (Fin (Nat.succ n)) (Fin (Nat.succ n)) R}, (∀ (j : Fin (Nat.succ n)), M 0 j = N 0 j) → (∀ (i : Fin n) (j : Fin (Nat.succ n)), M (Fin.succ i) j = N (Fin.succ i) j + c i * M (Fin.castSucc i) j) → det M = det N c : Fin n → R hc : ∀ (i : Fin n), Fin.succ k < Fin.succ i → c i = 0 M N : Matrix (Fin (Nat.succ n)) (Fin (Nat.succ n)) R h0 : ∀ (j : Fin (Nat.succ n)), M 0 j = N 0 j hsucc : ∀ (i : Fin n) (j : Fin (Nat.succ n)), M (Fin.succ i) j = N (Fin.succ i) j + c i * M (Fin.castSucc i) j M' : Matrix (Fin (Nat.succ n)) (Fin (Nat.succ n)) R := updateRow M (Fin.succ k) (N (Fin.succ k)) hM' : M' = updateRow M (Fin.succ k) (N (Fin.succ k)) hM : M = updateRow M' (Fin.succ k) (M' (Fin.succ k) + c k • M (Fin.castSucc k)) k_ne_succ : Fin.castSucc k ≠ Fin.succ k M_k : M (Fin.castSucc k) = M' (Fin.castSucc k) i : Fin n j : Fin (Nat.succ n) hik : ¬i = k hik2 : ¬k < i ⊢ Fin.castSucc i ≠ Fin.succ k [PROOFSTEP] apply ne_of_lt [GOAL] case neg.h m : Type u_1 n✝ : Type u_2 inst✝⁴ : DecidableEq n✝ inst✝³ : Fintype n✝ inst✝² : DecidableEq m inst✝¹ : Fintype m R : Type v inst✝ : CommRing R n : ℕ k✝ : Fin (n + 1) k : Fin n ih : ∀ (c : Fin n → R), (∀ (i : Fin n), Fin.castSucc k < Fin.succ i → c i = 0) → ∀ {M N : Matrix (Fin (Nat.succ n)) (Fin (Nat.succ n)) R}, (∀ (j : Fin (Nat.succ n)), M 0 j = N 0 j) → (∀ (i : Fin n) (j : Fin (Nat.succ n)), M (Fin.succ i) j = N (Fin.succ i) j + c i * M (Fin.castSucc i) j) → det M = det N c : Fin n → R hc : ∀ (i : Fin n), Fin.succ k < Fin.succ i → c i = 0 M N : Matrix (Fin (Nat.succ n)) (Fin (Nat.succ n)) R h0 : ∀ (j : Fin (Nat.succ n)), M 0 j = N 0 j hsucc : ∀ (i : Fin n) (j : Fin (Nat.succ n)), M (Fin.succ i) j = N (Fin.succ i) j + c i * M (Fin.castSucc i) j M' : Matrix (Fin (Nat.succ n)) (Fin (Nat.succ n)) R := updateRow M (Fin.succ k) (N (Fin.succ k)) hM' : M' = updateRow M (Fin.succ k) (N (Fin.succ k)) hM : M = updateRow M' (Fin.succ k) (M' (Fin.succ k) + c k • M (Fin.castSucc k)) k_ne_succ : Fin.castSucc k ≠ Fin.succ k M_k : M (Fin.castSucc k) = M' (Fin.castSucc k) i : Fin n j : Fin (Nat.succ n) hik : ¬i = k hik2 : ¬k < i ⊢ Fin.castSucc i < Fin.succ k [PROOFSTEP] rwa [Fin.lt_iff_val_lt_val, Fin.coe_castSucc, Fin.val_succ, Nat.lt_succ_iff, ← not_lt] [GOAL] m : Type u_1 n✝ : Type u_2 inst✝⁴ : DecidableEq n✝ inst✝³ : Fintype n✝ inst✝² : DecidableEq m inst✝¹ : Fintype m R : Type v inst✝ : CommRing R n : ℕ A B : Matrix (Fin (n + 1)) (Fin (n + 1)) R c : Fin n → R A_zero : ∀ (i : Fin (n + 1)), A i 0 = B i 0 A_succ : ∀ (i : Fin (n + 1)) (j : Fin n), A i (Fin.succ j) = B i (Fin.succ j) + c j * A i (Fin.castSucc j) ⊢ det A = det B [PROOFSTEP] rw [← det_transpose A, ← det_transpose B] [GOAL] m : Type u_1 n✝ : Type u_2 inst✝⁴ : DecidableEq n✝ inst✝³ : Fintype n✝ inst✝² : DecidableEq m inst✝¹ : Fintype m R : Type v inst✝ : CommRing R n : ℕ A B : Matrix (Fin (n + 1)) (Fin (n + 1)) R c : Fin n → R A_zero : ∀ (i : Fin (n + 1)), A i 0 = B i 0 A_succ : ∀ (i : Fin (n + 1)) (j : Fin n), A i (Fin.succ j) = B i (Fin.succ j) + c j * A i (Fin.castSucc j) ⊢ det Aᵀ = det Bᵀ [PROOFSTEP] exact det_eq_of_forall_row_eq_smul_add_pred c A_zero fun i j => A_succ j i [GOAL] m : Type u_1 n : Type u_2 inst✝⁶ : DecidableEq n inst✝⁵ : Fintype n inst✝⁴ : DecidableEq m inst✝³ : Fintype m R : Type v inst✝² : CommRing R o : Type u_3 inst✝¹ : Fintype o inst✝ : DecidableEq o M : o → Matrix n n R ⊢ det (blockDiagonal M) = ∏ k : o, det (M k) [PROOFSTEP] simp_rw [det_apply'] -- The right hand side is a product of sums, rewrite it as a sum of products. [GOAL] m : Type u_1 n : Type u_2 inst✝⁶ : DecidableEq n inst✝⁵ : Fintype n inst✝⁴ : DecidableEq m inst✝³ : Fintype m R : Type v inst✝² : CommRing R o : Type u_3 inst✝¹ : Fintype o inst✝ : DecidableEq o M : o → Matrix n n R ⊢ ∑ x : Perm (n × o), ↑↑(↑sign x) * ∏ x_1 : n × o, blockDiagonal M (↑x x_1) x_1 = ∏ x : o, ∑ x_1 : Perm n, ↑↑(↑sign x_1) * ∏ x_2 : n, M x (↑x_1 x_2) x_2 [PROOFSTEP] rw [Finset.prod_sum] [GOAL] m : Type u_1 n : Type u_2 inst✝⁶ : DecidableEq n inst✝⁵ : Fintype n inst✝⁴ : DecidableEq m inst✝³ : Fintype m R : Type v inst✝² : CommRing R o : Type u_3 inst✝¹ : Fintype o inst✝ : DecidableEq o M : o → Matrix n n R ⊢ ∑ x : Perm (n × o), ↑↑(↑sign x) * ∏ x_1 : n × o, blockDiagonal M (↑x x_1) x_1 = ∑ p in pi univ fun x => univ, ∏ x in attach univ, ↑↑(↑sign (p ↑x (_ : ↑x ∈ univ))) * ∏ x_1 : n, M (↑x) (↑(p ↑x (_ : ↑x ∈ univ)) x_1) x_1 [PROOFSTEP] simp_rw [Finset.prod_attach_univ, Finset.univ_pi_univ] -- We claim that the only permutations contributing to the sum are those that -- preserve their second component. [GOAL] m : Type u_1 n : Type u_2 inst✝⁶ : DecidableEq n inst✝⁵ : Fintype n inst✝⁴ : DecidableEq m inst✝³ : Fintype m R : Type v inst✝² : CommRing R o : Type u_3 inst✝¹ : Fintype o inst✝ : DecidableEq o M : o → Matrix n n R ⊢ ∑ x : Perm (n × o), ↑↑(↑sign x) * ∏ x_1 : n × o, blockDiagonal M (↑x x_1) x_1 = ∑ x : (a : o) → a ∈ univ → Perm n, ∏ x_1 : o, ↑↑(↑sign (x x_1 (_ : ↑{ val := x_1, property := (_ : x_1 ∈ univ) } ∈ univ))) * ∏ x_2 : n, M x_1 (↑(x x_1 (_ : ↑{ val := x_1, property := (_ : x_1 ∈ univ) } ∈ univ)) x_2) x_2 [PROOFSTEP] let preserving_snd : Finset (Equiv.Perm (n × o)) := Finset.univ.filter fun σ => ∀ x, (σ x).snd = x.snd [GOAL] m : Type u_1 n : Type u_2 inst✝⁶ : DecidableEq n inst✝⁵ : Fintype n inst✝⁴ : DecidableEq m inst✝³ : Fintype m R : Type v inst✝² : CommRing R o : Type u_3 inst✝¹ : Fintype o inst✝ : DecidableEq o M : o → Matrix n n R preserving_snd : Finset (Perm (n × o)) := filter (fun σ => ∀ (x : n × o), (↑σ x).snd = x.snd) univ ⊢ ∑ x : Perm (n × o), ↑↑(↑sign x) * ∏ x_1 : n × o, blockDiagonal M (↑x x_1) x_1 = ∑ x : (a : o) → a ∈ univ → Perm n, ∏ x_1 : o, ↑↑(↑sign (x x_1 (_ : ↑{ val := x_1, property := (_ : x_1 ∈ univ) } ∈ univ))) * ∏ x_2 : n, M x_1 (↑(x x_1 (_ : ↑{ val := x_1, property := (_ : x_1 ∈ univ) } ∈ univ)) x_2) x_2 [PROOFSTEP] have mem_preserving_snd : ∀ {σ : Equiv.Perm (n × o)}, σ ∈ preserving_snd ↔ ∀ x, (σ x).snd = x.snd := fun {σ} => Finset.mem_filter.trans ⟨fun h => h.2, fun h => ⟨Finset.mem_univ _, h⟩⟩ [GOAL] m : Type u_1 n : Type u_2 inst✝⁶ : DecidableEq n inst✝⁵ : Fintype n inst✝⁴ : DecidableEq m inst✝³ : Fintype m R : Type v inst✝² : CommRing R o : Type u_3 inst✝¹ : Fintype o inst✝ : DecidableEq o M : o → Matrix n n R preserving_snd : Finset (Perm (n × o)) := filter (fun σ => ∀ (x : n × o), (↑σ x).snd = x.snd) univ mem_preserving_snd : ∀ {σ : Perm (n × o)}, σ ∈ preserving_snd ↔ ∀ (x : n × o), (↑σ x).snd = x.snd ⊢ ∑ x : Perm (n × o), ↑↑(↑sign x) * ∏ x_1 : n × o, blockDiagonal M (↑x x_1) x_1 = ∑ x : (a : o) → a ∈ univ → Perm n, ∏ x_1 : o, ↑↑(↑sign (x x_1 (_ : ↑{ val := x_1, property := (_ : x_1 ∈ univ) } ∈ univ))) * ∏ x_2 : n, M x_1 (↑(x x_1 (_ : ↑{ val := x_1, property := (_ : x_1 ∈ univ) } ∈ univ)) x_2) x_2 [PROOFSTEP] rw [← Finset.sum_subset (Finset.subset_univ preserving_snd) _] -- And that these are in bijection with `o → Equiv.Perm m`. [GOAL] m : Type u_1 n : Type u_2 inst✝⁶ : DecidableEq n inst✝⁵ : Fintype n inst✝⁴ : DecidableEq m inst✝³ : Fintype m R : Type v inst✝² : CommRing R o : Type u_3 inst✝¹ : Fintype o inst✝ : DecidableEq o M : o → Matrix n n R preserving_snd : Finset (Perm (n × o)) := filter (fun σ => ∀ (x : n × o), (↑σ x).snd = x.snd) univ mem_preserving_snd : ∀ {σ : Perm (n × o)}, σ ∈ preserving_snd ↔ ∀ (x : n × o), (↑σ x).snd = x.snd ⊢ ∑ x in preserving_snd, ↑↑(↑sign x) * ∏ x_1 : n × o, blockDiagonal M (↑x x_1) x_1 = ∑ x : (a : o) → a ∈ univ → Perm n, ∏ x_1 : o, ↑↑(↑sign (x x_1 (_ : ↑{ val := x_1, property := (_ : x_1 ∈ univ) } ∈ univ))) * ∏ x_2 : n, M x_1 (↑(x x_1 (_ : ↑{ val := x_1, property := (_ : x_1 ∈ univ) } ∈ univ)) x_2) x_2 m : Type u_1 n : Type u_2 inst✝⁶ : DecidableEq n inst✝⁵ : Fintype n inst✝⁴ : DecidableEq m inst✝³ : Fintype m R : Type v inst✝² : CommRing R o : Type u_3 inst✝¹ : Fintype o inst✝ : DecidableEq o M : o → Matrix n n R preserving_snd : Finset (Perm (n × o)) := filter (fun σ => ∀ (x : n × o), (↑σ x).snd = x.snd) univ mem_preserving_snd : ∀ {σ : Perm (n × o)}, σ ∈ preserving_snd ↔ ∀ (x : n × o), (↑σ x).snd = x.snd ⊢ ∀ (x : Perm (n × o)), x ∈ univ → ¬x ∈ preserving_snd → ↑↑(↑sign x) * ∏ x_1 : n × o, blockDiagonal M (↑x x_1) x_1 = 0 [PROOFSTEP] rw [(Finset.sum_bij (fun (σ : ∀ k : o, k ∈ Finset.univ → Equiv.Perm n) _ => prodCongrLeft fun k => σ k (Finset.mem_univ k)) _ _ _ _).symm] [GOAL] m : Type u_1 n : Type u_2 inst✝⁶ : DecidableEq n inst✝⁵ : Fintype n inst✝⁴ : DecidableEq m inst✝³ : Fintype m R : Type v inst✝² : CommRing R o : Type u_3 inst✝¹ : Fintype o inst✝ : DecidableEq o M : o → Matrix n n R preserving_snd : Finset (Perm (n × o)) := filter (fun σ => ∀ (x : n × o), (↑σ x).snd = x.snd) univ mem_preserving_snd : ∀ {σ : Perm (n × o)}, σ ∈ preserving_snd ↔ ∀ (x : n × o), (↑σ x).snd = x.snd ⊢ ∀ (a : (k : o) → k ∈ univ → Perm n) (ha : a ∈ univ), (fun σ x => prodCongrLeft fun k => σ k (_ : k ∈ univ)) a ha ∈ preserving_snd [PROOFSTEP] intro σ _ [GOAL] m : Type u_1 n : Type u_2 inst✝⁶ : DecidableEq n inst✝⁵ : Fintype n inst✝⁴ : DecidableEq m inst✝³ : Fintype m R : Type v inst✝² : CommRing R o : Type u_3 inst✝¹ : Fintype o inst✝ : DecidableEq o M : o → Matrix n n R preserving_snd : Finset (Perm (n × o)) := filter (fun σ => ∀ (x : n × o), (↑σ x).snd = x.snd) univ mem_preserving_snd : ∀ {σ : Perm (n × o)}, σ ∈ preserving_snd ↔ ∀ (x : n × o), (↑σ x).snd = x.snd σ : (k : o) → k ∈ univ → Perm n ha✝ : σ ∈ univ ⊢ (fun σ x => prodCongrLeft fun k => σ k (_ : k ∈ univ)) σ ha✝ ∈ preserving_snd [PROOFSTEP] rw [mem_preserving_snd] [GOAL] m : Type u_1 n : Type u_2 inst✝⁶ : DecidableEq n inst✝⁵ : Fintype n inst✝⁴ : DecidableEq m inst✝³ : Fintype m R : Type v inst✝² : CommRing R o : Type u_3 inst✝¹ : Fintype o inst✝ : DecidableEq o M : o → Matrix n n R preserving_snd : Finset (Perm (n × o)) := filter (fun σ => ∀ (x : n × o), (↑σ x).snd = x.snd) univ mem_preserving_snd : ∀ {σ : Perm (n × o)}, σ ∈ preserving_snd ↔ ∀ (x : n × o), (↑σ x).snd = x.snd σ : (k : o) → k ∈ univ → Perm n ha✝ : σ ∈ univ ⊢ ∀ (x : n × o), (↑((fun σ x => prodCongrLeft fun k => σ k (_ : k ∈ univ)) σ ha✝) x).snd = x.snd [PROOFSTEP] rintro ⟨-, x⟩ [GOAL] case mk m : Type u_1 n : Type u_2 inst✝⁶ : DecidableEq n inst✝⁵ : Fintype n inst✝⁴ : DecidableEq m inst✝³ : Fintype m R : Type v inst✝² : CommRing R o : Type u_3 inst✝¹ : Fintype o inst✝ : DecidableEq o M : o → Matrix n n R preserving_snd : Finset (Perm (n × o)) := filter (fun σ => ∀ (x : n × o), (↑σ x).snd = x.snd) univ mem_preserving_snd : ∀ {σ : Perm (n × o)}, σ ∈ preserving_snd ↔ ∀ (x : n × o), (↑σ x).snd = x.snd σ : (k : o) → k ∈ univ → Perm n ha✝ : σ ∈ univ fst✝ : n x : o ⊢ (↑((fun σ x => prodCongrLeft fun k => σ k (_ : k ∈ univ)) σ ha✝) (fst✝, x)).snd = (fst✝, x).snd [PROOFSTEP] simp only [prodCongrLeft_apply] [GOAL] m : Type u_1 n : Type u_2 inst✝⁶ : DecidableEq n inst✝⁵ : Fintype n inst✝⁴ : DecidableEq m inst✝³ : Fintype m R : Type v inst✝² : CommRing R o : Type u_3 inst✝¹ : Fintype o inst✝ : DecidableEq o M : o → Matrix n n R preserving_snd : Finset (Perm (n × o)) := filter (fun σ => ∀ (x : n × o), (↑σ x).snd = x.snd) univ mem_preserving_snd : ∀ {σ : Perm (n × o)}, σ ∈ preserving_snd ↔ ∀ (x : n × o), (↑σ x).snd = x.snd ⊢ ∀ (a : (k : o) → k ∈ univ → Perm n) (ha : a ∈ univ), ∏ x : o, ↑↑(↑sign (a x (_ : ↑{ val := x, property := (_ : x ∈ univ) } ∈ univ))) * ∏ x_1 : n, M x (↑(a x (_ : ↑{ val := x, property := (_ : x ∈ univ) } ∈ univ)) x_1) x_1 = ↑↑(↑sign ((fun σ x => prodCongrLeft fun k => σ k (_ : k ∈ univ)) a ha)) * ∏ x : n × o, blockDiagonal M (↑((fun σ x => prodCongrLeft fun k => σ k (_ : k ∈ univ)) a ha) x) x [PROOFSTEP] intro σ _ [GOAL] m : Type u_1 n : Type u_2 inst✝⁶ : DecidableEq n inst✝⁵ : Fintype n inst✝⁴ : DecidableEq m inst✝³ : Fintype m R : Type v inst✝² : CommRing R o : Type u_3 inst✝¹ : Fintype o inst✝ : DecidableEq o M : o → Matrix n n R preserving_snd : Finset (Perm (n × o)) := filter (fun σ => ∀ (x : n × o), (↑σ x).snd = x.snd) univ mem_preserving_snd : ∀ {σ : Perm (n × o)}, σ ∈ preserving_snd ↔ ∀ (x : n × o), (↑σ x).snd = x.snd σ : (k : o) → k ∈ univ → Perm n ha✝ : σ ∈ univ ⊢ ∏ x : o, ↑↑(↑sign (σ x (_ : ↑{ val := x, property := (_ : x ∈ univ) } ∈ univ))) * ∏ x_1 : n, M x (↑(σ x (_ : ↑{ val := x, property := (_ : x ∈ univ) } ∈ univ)) x_1) x_1 = ↑↑(↑sign ((fun σ x => prodCongrLeft fun k => σ k (_ : k ∈ univ)) σ ha✝)) * ∏ x : n × o, blockDiagonal M (↑((fun σ x => prodCongrLeft fun k => σ k (_ : k ∈ univ)) σ ha✝) x) x [PROOFSTEP] rw [Finset.prod_mul_distrib, ← Finset.univ_product_univ, Finset.prod_product_right] [GOAL] m : Type u_1 n : Type u_2 inst✝⁶ : DecidableEq n inst✝⁵ : Fintype n inst✝⁴ : DecidableEq m inst✝³ : Fintype m R : Type v inst✝² : CommRing R o : Type u_3 inst✝¹ : Fintype o inst✝ : DecidableEq o M : o → Matrix n n R preserving_snd : Finset (Perm (n × o)) := filter (fun σ => ∀ (x : n × o), (↑σ x).snd = x.snd) univ mem_preserving_snd : ∀ {σ : Perm (n × o)}, σ ∈ preserving_snd ↔ ∀ (x : n × o), (↑σ x).snd = x.snd σ : (k : o) → k ∈ univ → Perm n ha✝ : σ ∈ univ ⊢ (∏ x : o, ↑↑(↑sign (σ x (_ : ↑{ val := x, property := (_ : x ∈ univ) } ∈ univ)))) * ∏ x : o, ∏ x_1 : n, M x (↑(σ x (_ : ↑{ val := x, property := (_ : x ∈ univ) } ∈ univ)) x_1) x_1 = ↑↑(↑sign ((fun σ x => prodCongrLeft fun k => σ k (_ : k ∈ univ)) σ ha✝)) * ∏ y : o, ∏ x : n, blockDiagonal M (↑((fun σ x => prodCongrLeft fun k => σ k (_ : k ∈ univ)) σ ha✝) (x, y)) (x, y) [PROOFSTEP] simp only [sign_prodCongrLeft, Units.coe_prod, Int.cast_prod, blockDiagonal_apply_eq, prodCongrLeft_apply] [GOAL] m : Type u_1 n : Type u_2 inst✝⁶ : DecidableEq n inst✝⁵ : Fintype n inst✝⁴ : DecidableEq m inst✝³ : Fintype m R : Type v inst✝² : CommRing R o : Type u_3 inst✝¹ : Fintype o inst✝ : DecidableEq o M : o → Matrix n n R preserving_snd : Finset (Perm (n × o)) := filter (fun σ => ∀ (x : n × o), (↑σ x).snd = x.snd) univ mem_preserving_snd : ∀ {σ : Perm (n × o)}, σ ∈ preserving_snd ↔ ∀ (x : n × o), (↑σ x).snd = x.snd ⊢ ∀ (a₁ a₂ : (k : o) → k ∈ univ → Perm n) (ha₁ : a₁ ∈ univ) (ha₂ : a₂ ∈ univ), (fun σ x => prodCongrLeft fun k => σ k (_ : k ∈ univ)) a₁ ha₁ = (fun σ x => prodCongrLeft fun k => σ k (_ : k ∈ univ)) a₂ ha₂ → a₁ = a₂ [PROOFSTEP] intro σ σ' _ _ eq [GOAL] m : Type u_1 n : Type u_2 inst✝⁶ : DecidableEq n inst✝⁵ : Fintype n inst✝⁴ : DecidableEq m inst✝³ : Fintype m R : Type v inst✝² : CommRing R o : Type u_3 inst✝¹ : Fintype o inst✝ : DecidableEq o M : o → Matrix n n R preserving_snd : Finset (Perm (n × o)) := filter (fun σ => ∀ (x : n × o), (↑σ x).snd = x.snd) univ mem_preserving_snd : ∀ {σ : Perm (n × o)}, σ ∈ preserving_snd ↔ ∀ (x : n × o), (↑σ x).snd = x.snd σ σ' : (k : o) → k ∈ univ → Perm n ha₁✝ : σ ∈ univ ha₂✝ : σ' ∈ univ eq : (fun σ x => prodCongrLeft fun k => σ k (_ : k ∈ univ)) σ ha₁✝ = (fun σ x => prodCongrLeft fun k => σ k (_ : k ∈ univ)) σ' ha₂✝ ⊢ σ = σ' [PROOFSTEP] ext x hx k [GOAL] case h.h.H m : Type u_1 n : Type u_2 inst✝⁶ : DecidableEq n inst✝⁵ : Fintype n inst✝⁴ : DecidableEq m inst✝³ : Fintype m R : Type v inst✝² : CommRing R o : Type u_3 inst✝¹ : Fintype o inst✝ : DecidableEq o M : o → Matrix n n R preserving_snd : Finset (Perm (n × o)) := filter (fun σ => ∀ (x : n × o), (↑σ x).snd = x.snd) univ mem_preserving_snd : ∀ {σ : Perm (n × o)}, σ ∈ preserving_snd ↔ ∀ (x : n × o), (↑σ x).snd = x.snd σ σ' : (k : o) → k ∈ univ → Perm n ha₁✝ : σ ∈ univ ha₂✝ : σ' ∈ univ eq : (fun σ x => prodCongrLeft fun k => σ k (_ : k ∈ univ)) σ ha₁✝ = (fun σ x => prodCongrLeft fun k => σ k (_ : k ∈ univ)) σ' ha₂✝ x : o hx : x ∈ univ k : n ⊢ ↑(σ x hx) k = ↑(σ' x hx) k [PROOFSTEP] simp only at eq [GOAL] case h.h.H m : Type u_1 n : Type u_2 inst✝⁶ : DecidableEq n inst✝⁵ : Fintype n inst✝⁴ : DecidableEq m inst✝³ : Fintype m R : Type v inst✝² : CommRing R o : Type u_3 inst✝¹ : Fintype o inst✝ : DecidableEq o M : o → Matrix n n R preserving_snd : Finset (Perm (n × o)) := filter (fun σ => ∀ (x : n × o), (↑σ x).snd = x.snd) univ mem_preserving_snd : ∀ {σ : Perm (n × o)}, σ ∈ preserving_snd ↔ ∀ (x : n × o), (↑σ x).snd = x.snd σ σ' : (k : o) → k ∈ univ → Perm n ha₁✝ : σ ∈ univ ha₂✝ : σ' ∈ univ eq : (prodCongrLeft fun k => σ k (_ : k ∈ univ)) = prodCongrLeft fun k => σ' k (_ : k ∈ univ) x : o hx : x ∈ univ k : n ⊢ ↑(σ x hx) k = ↑(σ' x hx) k [PROOFSTEP] have : ∀ k x, prodCongrLeft (fun k => σ k (Finset.mem_univ _)) (k, x) = prodCongrLeft (fun k => σ' k (Finset.mem_univ _)) (k, x) := fun k x => by rw [eq] [GOAL] m : Type u_1 n : Type u_2 inst✝⁶ : DecidableEq n inst✝⁵ : Fintype n inst✝⁴ : DecidableEq m inst✝³ : Fintype m R : Type v inst✝² : CommRing R o : Type u_3 inst✝¹ : Fintype o inst✝ : DecidableEq o M : o → Matrix n n R preserving_snd : Finset (Perm (n × o)) := filter (fun σ => ∀ (x : n × o), (↑σ x).snd = x.snd) univ mem_preserving_snd : ∀ {σ : Perm (n × o)}, σ ∈ preserving_snd ↔ ∀ (x : n × o), (↑σ x).snd = x.snd σ σ' : (k : o) → k ∈ univ → Perm n ha₁✝ : σ ∈ univ ha₂✝ : σ' ∈ univ eq : (prodCongrLeft fun k => σ k (_ : k ∈ univ)) = prodCongrLeft fun k => σ' k (_ : k ∈ univ) x✝ : o hx : x✝ ∈ univ k✝ k : n x : o ⊢ ↑(prodCongrLeft fun k => σ k (_ : k ∈ univ)) (k, x) = ↑(prodCongrLeft fun k => σ' k (_ : k ∈ univ)) (k, x) [PROOFSTEP] rw [eq] [GOAL] case h.h.H m : Type u_1 n : Type u_2 inst✝⁶ : DecidableEq n inst✝⁵ : Fintype n inst✝⁴ : DecidableEq m inst✝³ : Fintype m R : Type v inst✝² : CommRing R o : Type u_3 inst✝¹ : Fintype o inst✝ : DecidableEq o M : o → Matrix n n R preserving_snd : Finset (Perm (n × o)) := filter (fun σ => ∀ (x : n × o), (↑σ x).snd = x.snd) univ mem_preserving_snd : ∀ {σ : Perm (n × o)}, σ ∈ preserving_snd ↔ ∀ (x : n × o), (↑σ x).snd = x.snd σ σ' : (k : o) → k ∈ univ → Perm n ha₁✝ : σ ∈ univ ha₂✝ : σ' ∈ univ eq : (prodCongrLeft fun k => σ k (_ : k ∈ univ)) = prodCongrLeft fun k => σ' k (_ : k ∈ univ) x : o hx : x ∈ univ k : n this : ∀ (k : n) (x : o), ↑(prodCongrLeft fun k => σ k (_ : k ∈ univ)) (k, x) = ↑(prodCongrLeft fun k => σ' k (_ : k ∈ univ)) (k, x) ⊢ ↑(σ x hx) k = ↑(σ' x hx) k [PROOFSTEP] simp only [prodCongrLeft_apply, Prod.mk.inj_iff] at this [GOAL] case h.h.H m : Type u_1 n : Type u_2 inst✝⁶ : DecidableEq n inst✝⁵ : Fintype n inst✝⁴ : DecidableEq m inst✝³ : Fintype m R : Type v inst✝² : CommRing R o : Type u_3 inst✝¹ : Fintype o inst✝ : DecidableEq o M : o → Matrix n n R preserving_snd : Finset (Perm (n × o)) := filter (fun σ => ∀ (x : n × o), (↑σ x).snd = x.snd) univ mem_preserving_snd : ∀ {σ : Perm (n × o)}, σ ∈ preserving_snd ↔ ∀ (x : n × o), (↑σ x).snd = x.snd σ σ' : (k : o) → k ∈ univ → Perm n ha₁✝ : σ ∈ univ ha₂✝ : σ' ∈ univ eq : (prodCongrLeft fun k => σ k (_ : k ∈ univ)) = prodCongrLeft fun k => σ' k (_ : k ∈ univ) x : o hx : x ∈ univ k : n this : ∀ (k : n) (x : o), ↑(σ x (_ : x ∈ univ)) k = ↑(σ' x (_ : x ∈ univ)) k ∧ True ⊢ ↑(σ x hx) k = ↑(σ' x hx) k [PROOFSTEP] exact (this k x).1 [GOAL] m : Type u_1 n : Type u_2 inst✝⁶ : DecidableEq n inst✝⁵ : Fintype n inst✝⁴ : DecidableEq m inst✝³ : Fintype m R : Type v inst✝² : CommRing R o : Type u_3 inst✝¹ : Fintype o inst✝ : DecidableEq o M : o → Matrix n n R preserving_snd : Finset (Perm (n × o)) := filter (fun σ => ∀ (x : n × o), (↑σ x).snd = x.snd) univ mem_preserving_snd : ∀ {σ : Perm (n × o)}, σ ∈ preserving_snd ↔ ∀ (x : n × o), (↑σ x).snd = x.snd ⊢ ∀ (b : n × o ≃ n × o), b ∈ preserving_snd → ∃ a ha, b = (fun σ x => prodCongrLeft fun k => σ k (_ : k ∈ univ)) a ha [PROOFSTEP] intro σ hσ [GOAL] m : Type u_1 n : Type u_2 inst✝⁶ : DecidableEq n inst✝⁵ : Fintype n inst✝⁴ : DecidableEq m inst✝³ : Fintype m R : Type v inst✝² : CommRing R o : Type u_3 inst✝¹ : Fintype o inst✝ : DecidableEq o M : o → Matrix n n R preserving_snd : Finset (Perm (n × o)) := filter (fun σ => ∀ (x : n × o), (↑σ x).snd = x.snd) univ mem_preserving_snd : ∀ {σ : Perm (n × o)}, σ ∈ preserving_snd ↔ ∀ (x : n × o), (↑σ x).snd = x.snd σ : n × o ≃ n × o hσ : σ ∈ preserving_snd ⊢ ∃ a ha, σ = (fun σ x => prodCongrLeft fun k => σ k (_ : k ∈ univ)) a ha [PROOFSTEP] rw [mem_preserving_snd] at hσ [GOAL] m : Type u_1 n : Type u_2 inst✝⁶ : DecidableEq n inst✝⁵ : Fintype n inst✝⁴ : DecidableEq m inst✝³ : Fintype m R : Type v inst✝² : CommRing R o : Type u_3 inst✝¹ : Fintype o inst✝ : DecidableEq o M : o → Matrix n n R preserving_snd : Finset (Perm (n × o)) := filter (fun σ => ∀ (x : n × o), (↑σ x).snd = x.snd) univ mem_preserving_snd : ∀ {σ : Perm (n × o)}, σ ∈ preserving_snd ↔ ∀ (x : n × o), (↑σ x).snd = x.snd σ : n × o ≃ n × o hσ : ∀ (x : n × o), (↑σ x).snd = x.snd ⊢ ∃ a ha, σ = (fun σ x => prodCongrLeft fun k => σ k (_ : k ∈ univ)) a ha [PROOFSTEP] have hσ' : ∀ x, (σ⁻¹ x).snd = x.snd := by intro x conv_rhs => rw [← Perm.apply_inv_self σ x, hσ] [GOAL] m : Type u_1 n : Type u_2 inst✝⁶ : DecidableEq n inst✝⁵ : Fintype n inst✝⁴ : DecidableEq m inst✝³ : Fintype m R : Type v inst✝² : CommRing R o : Type u_3 inst✝¹ : Fintype o inst✝ : DecidableEq o M : o → Matrix n n R preserving_snd : Finset (Perm (n × o)) := filter (fun σ => ∀ (x : n × o), (↑σ x).snd = x.snd) univ mem_preserving_snd : ∀ {σ : Perm (n × o)}, σ ∈ preserving_snd ↔ ∀ (x : n × o), (↑σ x).snd = x.snd σ : n × o ≃ n × o hσ : ∀ (x : n × o), (↑σ x).snd = x.snd ⊢ ∀ (x : n × o), (↑σ⁻¹ x).snd = x.snd [PROOFSTEP] intro x [GOAL] m : Type u_1 n : Type u_2 inst✝⁶ : DecidableEq n inst✝⁵ : Fintype n inst✝⁴ : DecidableEq m inst✝³ : Fintype m R : Type v inst✝² : CommRing R o : Type u_3 inst✝¹ : Fintype o inst✝ : DecidableEq o M : o → Matrix n n R preserving_snd : Finset (Perm (n × o)) := filter (fun σ => ∀ (x : n × o), (↑σ x).snd = x.snd) univ mem_preserving_snd : ∀ {σ : Perm (n × o)}, σ ∈ preserving_snd ↔ ∀ (x : n × o), (↑σ x).snd = x.snd σ : n × o ≃ n × o hσ : ∀ (x : n × o), (↑σ x).snd = x.snd x : n × o ⊢ (↑σ⁻¹ x).snd = x.snd [PROOFSTEP] conv_rhs => rw [← Perm.apply_inv_self σ x, hσ] [GOAL] m : Type u_1 n : Type u_2 inst✝⁶ : DecidableEq n inst✝⁵ : Fintype n inst✝⁴ : DecidableEq m inst✝³ : Fintype m R : Type v inst✝² : CommRing R o : Type u_3 inst✝¹ : Fintype o inst✝ : DecidableEq o M : o → Matrix n n R preserving_snd : Finset (Perm (n × o)) := filter (fun σ => ∀ (x : n × o), (↑σ x).snd = x.snd) univ mem_preserving_snd : ∀ {σ : Perm (n × o)}, σ ∈ preserving_snd ↔ ∀ (x : n × o), (↑σ x).snd = x.snd σ : n × o ≃ n × o hσ : ∀ (x : n × o), (↑σ x).snd = x.snd x : n × o | x.snd [PROOFSTEP] rw [← Perm.apply_inv_self σ x, hσ] [GOAL] m : Type u_1 n : Type u_2 inst✝⁶ : DecidableEq n inst✝⁵ : Fintype n inst✝⁴ : DecidableEq m inst✝³ : Fintype m R : Type v inst✝² : CommRing R o : Type u_3 inst✝¹ : Fintype o inst✝ : DecidableEq o M : o → Matrix n n R preserving_snd : Finset (Perm (n × o)) := filter (fun σ => ∀ (x : n × o), (↑σ x).snd = x.snd) univ mem_preserving_snd : ∀ {σ : Perm (n × o)}, σ ∈ preserving_snd ↔ ∀ (x : n × o), (↑σ x).snd = x.snd σ : n × o ≃ n × o hσ : ∀ (x : n × o), (↑σ x).snd = x.snd x : n × o | x.snd [PROOFSTEP] rw [← Perm.apply_inv_self σ x, hσ] [GOAL] m : Type u_1 n : Type u_2 inst✝⁶ : DecidableEq n inst✝⁵ : Fintype n inst✝⁴ : DecidableEq m inst✝³ : Fintype m R : Type v inst✝² : CommRing R o : Type u_3 inst✝¹ : Fintype o inst✝ : DecidableEq o M : o → Matrix n n R preserving_snd : Finset (Perm (n × o)) := filter (fun σ => ∀ (x : n × o), (↑σ x).snd = x.snd) univ mem_preserving_snd : ∀ {σ : Perm (n × o)}, σ ∈ preserving_snd ↔ ∀ (x : n × o), (↑σ x).snd = x.snd σ : n × o ≃ n × o hσ : ∀ (x : n × o), (↑σ x).snd = x.snd x : n × o | x.snd [PROOFSTEP] rw [← Perm.apply_inv_self σ x, hσ] [GOAL] m : Type u_1 n : Type u_2 inst✝⁶ : DecidableEq n inst✝⁵ : Fintype n inst✝⁴ : DecidableEq m inst✝³ : Fintype m R : Type v inst✝² : CommRing R o : Type u_3 inst✝¹ : Fintype o inst✝ : DecidableEq o M : o → Matrix n n R preserving_snd : Finset (Perm (n × o)) := filter (fun σ => ∀ (x : n × o), (↑σ x).snd = x.snd) univ mem_preserving_snd : ∀ {σ : Perm (n × o)}, σ ∈ preserving_snd ↔ ∀ (x : n × o), (↑σ x).snd = x.snd σ : n × o ≃ n × o hσ : ∀ (x : n × o), (↑σ x).snd = x.snd hσ' : ∀ (x : n × o), (↑σ⁻¹ x).snd = x.snd ⊢ ∃ a ha, σ = (fun σ x => prodCongrLeft fun k => σ k (_ : k ∈ univ)) a ha [PROOFSTEP] have mk_apply_eq : ∀ k x, ((σ (x, k)).fst, k) = σ (x, k) := by intro k x ext · simp only · simp only [hσ] [GOAL] m : Type u_1 n : Type u_2 inst✝⁶ : DecidableEq n inst✝⁵ : Fintype n inst✝⁴ : DecidableEq m inst✝³ : Fintype m R : Type v inst✝² : CommRing R o : Type u_3 inst✝¹ : Fintype o inst✝ : DecidableEq o M : o → Matrix n n R preserving_snd : Finset (Perm (n × o)) := filter (fun σ => ∀ (x : n × o), (↑σ x).snd = x.snd) univ mem_preserving_snd : ∀ {σ : Perm (n × o)}, σ ∈ preserving_snd ↔ ∀ (x : n × o), (↑σ x).snd = x.snd σ : n × o ≃ n × o hσ : ∀ (x : n × o), (↑σ x).snd = x.snd hσ' : ∀ (x : n × o), (↑σ⁻¹ x).snd = x.snd ⊢ ∀ (k : o) (x : n), ((↑σ (x, k)).fst, k) = ↑σ (x, k) [PROOFSTEP] intro k x [GOAL] m : Type u_1 n : Type u_2 inst✝⁶ : DecidableEq n inst✝⁵ : Fintype n inst✝⁴ : DecidableEq m inst✝³ : Fintype m R : Type v inst✝² : CommRing R o : Type u_3 inst✝¹ : Fintype o inst✝ : DecidableEq o M : o → Matrix n n R preserving_snd : Finset (Perm (n × o)) := filter (fun σ => ∀ (x : n × o), (↑σ x).snd = x.snd) univ mem_preserving_snd : ∀ {σ : Perm (n × o)}, σ ∈ preserving_snd ↔ ∀ (x : n × o), (↑σ x).snd = x.snd σ : n × o ≃ n × o hσ : ∀ (x : n × o), (↑σ x).snd = x.snd hσ' : ∀ (x : n × o), (↑σ⁻¹ x).snd = x.snd k : o x : n ⊢ ((↑σ (x, k)).fst, k) = ↑σ (x, k) [PROOFSTEP] ext [GOAL] case h₁ m : Type u_1 n : Type u_2 inst✝⁶ : DecidableEq n inst✝⁵ : Fintype n inst✝⁴ : DecidableEq m inst✝³ : Fintype m R : Type v inst✝² : CommRing R o : Type u_3 inst✝¹ : Fintype o inst✝ : DecidableEq o M : o → Matrix n n R preserving_snd : Finset (Perm (n × o)) := filter (fun σ => ∀ (x : n × o), (↑σ x).snd = x.snd) univ mem_preserving_snd : ∀ {σ : Perm (n × o)}, σ ∈ preserving_snd ↔ ∀ (x : n × o), (↑σ x).snd = x.snd σ : n × o ≃ n × o hσ : ∀ (x : n × o), (↑σ x).snd = x.snd hσ' : ∀ (x : n × o), (↑σ⁻¹ x).snd = x.snd k : o x : n ⊢ ((↑σ (x, k)).fst, k).fst = (↑σ (x, k)).fst [PROOFSTEP] simp only [GOAL] case h₂ m : Type u_1 n : Type u_2 inst✝⁶ : DecidableEq n inst✝⁵ : Fintype n inst✝⁴ : DecidableEq m inst✝³ : Fintype m R : Type v inst✝² : CommRing R o : Type u_3 inst✝¹ : Fintype o inst✝ : DecidableEq o M : o → Matrix n n R preserving_snd : Finset (Perm (n × o)) := filter (fun σ => ∀ (x : n × o), (↑σ x).snd = x.snd) univ mem_preserving_snd : ∀ {σ : Perm (n × o)}, σ ∈ preserving_snd ↔ ∀ (x : n × o), (↑σ x).snd = x.snd σ : n × o ≃ n × o hσ : ∀ (x : n × o), (↑σ x).snd = x.snd hσ' : ∀ (x : n × o), (↑σ⁻¹ x).snd = x.snd k : o x : n ⊢ ((↑σ (x, k)).fst, k).snd = (↑σ (x, k)).snd [PROOFSTEP] simp only [hσ] [GOAL] m : Type u_1 n : Type u_2 inst✝⁶ : DecidableEq n inst✝⁵ : Fintype n inst✝⁴ : DecidableEq m inst✝³ : Fintype m R : Type v inst✝² : CommRing R o : Type u_3 inst✝¹ : Fintype o inst✝ : DecidableEq o M : o → Matrix n n R preserving_snd : Finset (Perm (n × o)) := filter (fun σ => ∀ (x : n × o), (↑σ x).snd = x.snd) univ mem_preserving_snd : ∀ {σ : Perm (n × o)}, σ ∈ preserving_snd ↔ ∀ (x : n × o), (↑σ x).snd = x.snd σ : n × o ≃ n × o hσ : ∀ (x : n × o), (↑σ x).snd = x.snd hσ' : ∀ (x : n × o), (↑σ⁻¹ x).snd = x.snd mk_apply_eq : ∀ (k : o) (x : n), ((↑σ (x, k)).fst, k) = ↑σ (x, k) ⊢ ∃ a ha, σ = (fun σ x => prodCongrLeft fun k => σ k (_ : k ∈ univ)) a ha [PROOFSTEP] have mk_inv_apply_eq : ∀ k x, ((σ⁻¹ (x, k)).fst, k) = σ⁻¹ (x, k) := by intro k x conv_lhs => rw [← Perm.apply_inv_self σ (x, k)] ext · simp only [apply_inv_self] · simp only [hσ'] [GOAL] m : Type u_1 n : Type u_2 inst✝⁶ : DecidableEq n inst✝⁵ : Fintype n inst✝⁴ : DecidableEq m inst✝³ : Fintype m R : Type v inst✝² : CommRing R o : Type u_3 inst✝¹ : Fintype o inst✝ : DecidableEq o M : o → Matrix n n R preserving_snd : Finset (Perm (n × o)) := filter (fun σ => ∀ (x : n × o), (↑σ x).snd = x.snd) univ mem_preserving_snd : ∀ {σ : Perm (n × o)}, σ ∈ preserving_snd ↔ ∀ (x : n × o), (↑σ x).snd = x.snd σ : n × o ≃ n × o hσ : ∀ (x : n × o), (↑σ x).snd = x.snd hσ' : ∀ (x : n × o), (↑σ⁻¹ x).snd = x.snd mk_apply_eq : ∀ (k : o) (x : n), ((↑σ (x, k)).fst, k) = ↑σ (x, k) ⊢ ∀ (k : o) (x : n), ((↑σ⁻¹ (x, k)).fst, k) = ↑σ⁻¹ (x, k) [PROOFSTEP] intro k x [GOAL] m : Type u_1 n : Type u_2 inst✝⁶ : DecidableEq n inst✝⁵ : Fintype n inst✝⁴ : DecidableEq m inst✝³ : Fintype m R : Type v inst✝² : CommRing R o : Type u_3 inst✝¹ : Fintype o inst✝ : DecidableEq o M : o → Matrix n n R preserving_snd : Finset (Perm (n × o)) := filter (fun σ => ∀ (x : n × o), (↑σ x).snd = x.snd) univ mem_preserving_snd : ∀ {σ : Perm (n × o)}, σ ∈ preserving_snd ↔ ∀ (x : n × o), (↑σ x).snd = x.snd σ : n × o ≃ n × o hσ : ∀ (x : n × o), (↑σ x).snd = x.snd hσ' : ∀ (x : n × o), (↑σ⁻¹ x).snd = x.snd mk_apply_eq : ∀ (k : o) (x : n), ((↑σ (x, k)).fst, k) = ↑σ (x, k) k : o x : n ⊢ ((↑σ⁻¹ (x, k)).fst, k) = ↑σ⁻¹ (x, k) [PROOFSTEP] conv_lhs => rw [← Perm.apply_inv_self σ (x, k)] [GOAL] m : Type u_1 n : Type u_2 inst✝⁶ : DecidableEq n inst✝⁵ : Fintype n inst✝⁴ : DecidableEq m inst✝³ : Fintype m R : Type v inst✝² : CommRing R o : Type u_3 inst✝¹ : Fintype o inst✝ : DecidableEq o M : o → Matrix n n R preserving_snd : Finset (Perm (n × o)) := filter (fun σ => ∀ (x : n × o), (↑σ x).snd = x.snd) univ mem_preserving_snd : ∀ {σ : Perm (n × o)}, σ ∈ preserving_snd ↔ ∀ (x : n × o), (↑σ x).snd = x.snd σ : n × o ≃ n × o hσ : ∀ (x : n × o), (↑σ x).snd = x.snd hσ' : ∀ (x : n × o), (↑σ⁻¹ x).snd = x.snd mk_apply_eq : ∀ (k : o) (x : n), ((↑σ (x, k)).fst, k) = ↑σ (x, k) k : o x : n | ((↑σ⁻¹ (x, k)).fst, k) [PROOFSTEP] rw [← Perm.apply_inv_self σ (x, k)] [GOAL] m : Type u_1 n : Type u_2 inst✝⁶ : DecidableEq n inst✝⁵ : Fintype n inst✝⁴ : DecidableEq m inst✝³ : Fintype m R : Type v inst✝² : CommRing R o : Type u_3 inst✝¹ : Fintype o inst✝ : DecidableEq o M : o → Matrix n n R preserving_snd : Finset (Perm (n × o)) := filter (fun σ => ∀ (x : n × o), (↑σ x).snd = x.snd) univ mem_preserving_snd : ∀ {σ : Perm (n × o)}, σ ∈ preserving_snd ↔ ∀ (x : n × o), (↑σ x).snd = x.snd σ : n × o ≃ n × o hσ : ∀ (x : n × o), (↑σ x).snd = x.snd hσ' : ∀ (x : n × o), (↑σ⁻¹ x).snd = x.snd mk_apply_eq : ∀ (k : o) (x : n), ((↑σ (x, k)).fst, k) = ↑σ (x, k) k : o x : n | ((↑σ⁻¹ (x, k)).fst, k) [PROOFSTEP] rw [← Perm.apply_inv_self σ (x, k)] [GOAL] m : Type u_1 n : Type u_2 inst✝⁶ : DecidableEq n inst✝⁵ : Fintype n inst✝⁴ : DecidableEq m inst✝³ : Fintype m R : Type v inst✝² : CommRing R o : Type u_3 inst✝¹ : Fintype o inst✝ : DecidableEq o M : o → Matrix n n R preserving_snd : Finset (Perm (n × o)) := filter (fun σ => ∀ (x : n × o), (↑σ x).snd = x.snd) univ mem_preserving_snd : ∀ {σ : Perm (n × o)}, σ ∈ preserving_snd ↔ ∀ (x : n × o), (↑σ x).snd = x.snd σ : n × o ≃ n × o hσ : ∀ (x : n × o), (↑σ x).snd = x.snd hσ' : ∀ (x : n × o), (↑σ⁻¹ x).snd = x.snd mk_apply_eq : ∀ (k : o) (x : n), ((↑σ (x, k)).fst, k) = ↑σ (x, k) k : o x : n | ((↑σ⁻¹ (x, k)).fst, k) [PROOFSTEP] rw [← Perm.apply_inv_self σ (x, k)] [GOAL] m : Type u_1 n : Type u_2 inst✝⁶ : DecidableEq n inst✝⁵ : Fintype n inst✝⁴ : DecidableEq m inst✝³ : Fintype m R : Type v inst✝² : CommRing R o : Type u_3 inst✝¹ : Fintype o inst✝ : DecidableEq o M : o → Matrix n n R preserving_snd : Finset (Perm (n × o)) := filter (fun σ => ∀ (x : n × o), (↑σ x).snd = x.snd) univ mem_preserving_snd : ∀ {σ : Perm (n × o)}, σ ∈ preserving_snd ↔ ∀ (x : n × o), (↑σ x).snd = x.snd σ : n × o ≃ n × o hσ : ∀ (x : n × o), (↑σ x).snd = x.snd hσ' : ∀ (x : n × o), (↑σ⁻¹ x).snd = x.snd mk_apply_eq : ∀ (k : o) (x : n), ((↑σ (x, k)).fst, k) = ↑σ (x, k) k : o x : n ⊢ ((↑σ⁻¹ (↑σ (↑σ⁻¹ (x, k)))).fst, k) = ↑σ⁻¹ (x, k) [PROOFSTEP] ext [GOAL] case h₁ m : Type u_1 n : Type u_2 inst✝⁶ : DecidableEq n inst✝⁵ : Fintype n inst✝⁴ : DecidableEq m inst✝³ : Fintype m R : Type v inst✝² : CommRing R o : Type u_3 inst✝¹ : Fintype o inst✝ : DecidableEq o M : o → Matrix n n R preserving_snd : Finset (Perm (n × o)) := filter (fun σ => ∀ (x : n × o), (↑σ x).snd = x.snd) univ mem_preserving_snd : ∀ {σ : Perm (n × o)}, σ ∈ preserving_snd ↔ ∀ (x : n × o), (↑σ x).snd = x.snd σ : n × o ≃ n × o hσ : ∀ (x : n × o), (↑σ x).snd = x.snd hσ' : ∀ (x : n × o), (↑σ⁻¹ x).snd = x.snd mk_apply_eq : ∀ (k : o) (x : n), ((↑σ (x, k)).fst, k) = ↑σ (x, k) k : o x : n ⊢ ((↑σ⁻¹ (↑σ (↑σ⁻¹ (x, k)))).fst, k).fst = (↑σ⁻¹ (x, k)).fst [PROOFSTEP] simp only [apply_inv_self] [GOAL] case h₂ m : Type u_1 n : Type u_2 inst✝⁶ : DecidableEq n inst✝⁵ : Fintype n inst✝⁴ : DecidableEq m inst✝³ : Fintype m R : Type v inst✝² : CommRing R o : Type u_3 inst✝¹ : Fintype o inst✝ : DecidableEq o M : o → Matrix n n R preserving_snd : Finset (Perm (n × o)) := filter (fun σ => ∀ (x : n × o), (↑σ x).snd = x.snd) univ mem_preserving_snd : ∀ {σ : Perm (n × o)}, σ ∈ preserving_snd ↔ ∀ (x : n × o), (↑σ x).snd = x.snd σ : n × o ≃ n × o hσ : ∀ (x : n × o), (↑σ x).snd = x.snd hσ' : ∀ (x : n × o), (↑σ⁻¹ x).snd = x.snd mk_apply_eq : ∀ (k : o) (x : n), ((↑σ (x, k)).fst, k) = ↑σ (x, k) k : o x : n ⊢ ((↑σ⁻¹ (↑σ (↑σ⁻¹ (x, k)))).fst, k).snd = (↑σ⁻¹ (x, k)).snd [PROOFSTEP] simp only [hσ'] [GOAL] m : Type u_1 n : Type u_2 inst✝⁶ : DecidableEq n inst✝⁵ : Fintype n inst✝⁴ : DecidableEq m inst✝³ : Fintype m R : Type v inst✝² : CommRing R o : Type u_3 inst✝¹ : Fintype o inst✝ : DecidableEq o M : o → Matrix n n R preserving_snd : Finset (Perm (n × o)) := filter (fun σ => ∀ (x : n × o), (↑σ x).snd = x.snd) univ mem_preserving_snd : ∀ {σ : Perm (n × o)}, σ ∈ preserving_snd ↔ ∀ (x : n × o), (↑σ x).snd = x.snd σ : n × o ≃ n × o hσ : ∀ (x : n × o), (↑σ x).snd = x.snd hσ' : ∀ (x : n × o), (↑σ⁻¹ x).snd = x.snd mk_apply_eq : ∀ (k : o) (x : n), ((↑σ (x, k)).fst, k) = ↑σ (x, k) mk_inv_apply_eq : ∀ (k : o) (x : n), ((↑σ⁻¹ (x, k)).fst, k) = ↑σ⁻¹ (x, k) ⊢ ∃ a ha, σ = (fun σ x => prodCongrLeft fun k => σ k (_ : k ∈ univ)) a ha [PROOFSTEP] refine' ⟨fun k _ => ⟨fun x => (σ (x, k)).fst, fun x => (σ⁻¹ (x, k)).fst, _, _⟩, _, _⟩ [GOAL] case refine'_1 m : Type u_1 n : Type u_2 inst✝⁶ : DecidableEq n inst✝⁵ : Fintype n inst✝⁴ : DecidableEq m inst✝³ : Fintype m R : Type v inst✝² : CommRing R o : Type u_3 inst✝¹ : Fintype o inst✝ : DecidableEq o M : o → Matrix n n R preserving_snd : Finset (Perm (n × o)) := filter (fun σ => ∀ (x : n × o), (↑σ x).snd = x.snd) univ mem_preserving_snd : ∀ {σ : Perm (n × o)}, σ ∈ preserving_snd ↔ ∀ (x : n × o), (↑σ x).snd = x.snd σ : n × o ≃ n × o hσ : ∀ (x : n × o), (↑σ x).snd = x.snd hσ' : ∀ (x : n × o), (↑σ⁻¹ x).snd = x.snd mk_apply_eq : ∀ (k : o) (x : n), ((↑σ (x, k)).fst, k) = ↑σ (x, k) mk_inv_apply_eq : ∀ (k : o) (x : n), ((↑σ⁻¹ (x, k)).fst, k) = ↑σ⁻¹ (x, k) k : o x✝ : k ∈ univ ⊢ LeftInverse (fun x => (↑σ⁻¹ (x, k)).fst) fun x => (↑σ (x, k)).fst [PROOFSTEP] intro x [GOAL] case refine'_1 m : Type u_1 n : Type u_2 inst✝⁶ : DecidableEq n inst✝⁵ : Fintype n inst✝⁴ : DecidableEq m inst✝³ : Fintype m R : Type v inst✝² : CommRing R o : Type u_3 inst✝¹ : Fintype o inst✝ : DecidableEq o M : o → Matrix n n R preserving_snd : Finset (Perm (n × o)) := filter (fun σ => ∀ (x : n × o), (↑σ x).snd = x.snd) univ mem_preserving_snd : ∀ {σ : Perm (n × o)}, σ ∈ preserving_snd ↔ ∀ (x : n × o), (↑σ x).snd = x.snd σ : n × o ≃ n × o hσ : ∀ (x : n × o), (↑σ x).snd = x.snd hσ' : ∀ (x : n × o), (↑σ⁻¹ x).snd = x.snd mk_apply_eq : ∀ (k : o) (x : n), ((↑σ (x, k)).fst, k) = ↑σ (x, k) mk_inv_apply_eq : ∀ (k : o) (x : n), ((↑σ⁻¹ (x, k)).fst, k) = ↑σ⁻¹ (x, k) k : o x✝ : k ∈ univ x : n ⊢ (fun x => (↑σ⁻¹ (x, k)).fst) ((fun x => (↑σ (x, k)).fst) x) = x [PROOFSTEP] simp only [mk_apply_eq, inv_apply_self] [GOAL] case refine'_2 m : Type u_1 n : Type u_2 inst✝⁶ : DecidableEq n inst✝⁵ : Fintype n inst✝⁴ : DecidableEq m inst✝³ : Fintype m R : Type v inst✝² : CommRing R o : Type u_3 inst✝¹ : Fintype o inst✝ : DecidableEq o M : o → Matrix n n R preserving_snd : Finset (Perm (n × o)) := filter (fun σ => ∀ (x : n × o), (↑σ x).snd = x.snd) univ mem_preserving_snd : ∀ {σ : Perm (n × o)}, σ ∈ preserving_snd ↔ ∀ (x : n × o), (↑σ x).snd = x.snd σ : n × o ≃ n × o hσ : ∀ (x : n × o), (↑σ x).snd = x.snd hσ' : ∀ (x : n × o), (↑σ⁻¹ x).snd = x.snd mk_apply_eq : ∀ (k : o) (x : n), ((↑σ (x, k)).fst, k) = ↑σ (x, k) mk_inv_apply_eq : ∀ (k : o) (x : n), ((↑σ⁻¹ (x, k)).fst, k) = ↑σ⁻¹ (x, k) k : o x✝ : k ∈ univ ⊢ Function.RightInverse (fun x => (↑σ⁻¹ (x, k)).fst) fun x => (↑σ (x, k)).fst [PROOFSTEP] intro x [GOAL] case refine'_2 m : Type u_1 n : Type u_2 inst✝⁶ : DecidableEq n inst✝⁵ : Fintype n inst✝⁴ : DecidableEq m inst✝³ : Fintype m R : Type v inst✝² : CommRing R o : Type u_3 inst✝¹ : Fintype o inst✝ : DecidableEq o M : o → Matrix n n R preserving_snd : Finset (Perm (n × o)) := filter (fun σ => ∀ (x : n × o), (↑σ x).snd = x.snd) univ mem_preserving_snd : ∀ {σ : Perm (n × o)}, σ ∈ preserving_snd ↔ ∀ (x : n × o), (↑σ x).snd = x.snd σ : n × o ≃ n × o hσ : ∀ (x : n × o), (↑σ x).snd = x.snd hσ' : ∀ (x : n × o), (↑σ⁻¹ x).snd = x.snd mk_apply_eq : ∀ (k : o) (x : n), ((↑σ (x, k)).fst, k) = ↑σ (x, k) mk_inv_apply_eq : ∀ (k : o) (x : n), ((↑σ⁻¹ (x, k)).fst, k) = ↑σ⁻¹ (x, k) k : o x✝ : k ∈ univ x : n ⊢ (fun x => (↑σ (x, k)).fst) ((fun x => (↑σ⁻¹ (x, k)).fst) x) = x [PROOFSTEP] simp only [mk_inv_apply_eq, apply_inv_self] [GOAL] case refine'_3 m : Type u_1 n : Type u_2 inst✝⁶ : DecidableEq n inst✝⁵ : Fintype n inst✝⁴ : DecidableEq m inst✝³ : Fintype m R : Type v inst✝² : CommRing R o : Type u_3 inst✝¹ : Fintype o inst✝ : DecidableEq o M : o → Matrix n n R preserving_snd : Finset (Perm (n × o)) := filter (fun σ => ∀ (x : n × o), (↑σ x).snd = x.snd) univ mem_preserving_snd : ∀ {σ : Perm (n × o)}, σ ∈ preserving_snd ↔ ∀ (x : n × o), (↑σ x).snd = x.snd σ : n × o ≃ n × o hσ : ∀ (x : n × o), (↑σ x).snd = x.snd hσ' : ∀ (x : n × o), (↑σ⁻¹ x).snd = x.snd mk_apply_eq : ∀ (k : o) (x : n), ((↑σ (x, k)).fst, k) = ↑σ (x, k) mk_inv_apply_eq : ∀ (k : o) (x : n), ((↑σ⁻¹ (x, k)).fst, k) = ↑σ⁻¹ (x, k) ⊢ (fun k x => { toFun := fun x => (↑σ (x, k)).fst, invFun := fun x => (↑σ⁻¹ (x, k)).fst, left_inv := (_ : ∀ (x : n), (↑σ⁻¹ ((↑σ (x, k)).fst, k)).fst = x), right_inv := (_ : ∀ (x : n), (↑σ ((↑σ⁻¹ (x, k)).fst, k)).fst = x) }) ∈ univ [PROOFSTEP] apply Finset.mem_univ [GOAL] case refine'_4 m : Type u_1 n : Type u_2 inst✝⁶ : DecidableEq n inst✝⁵ : Fintype n inst✝⁴ : DecidableEq m inst✝³ : Fintype m R : Type v inst✝² : CommRing R o : Type u_3 inst✝¹ : Fintype o inst✝ : DecidableEq o M : o → Matrix n n R preserving_snd : Finset (Perm (n × o)) := filter (fun σ => ∀ (x : n × o), (↑σ x).snd = x.snd) univ mem_preserving_snd : ∀ {σ : Perm (n × o)}, σ ∈ preserving_snd ↔ ∀ (x : n × o), (↑σ x).snd = x.snd σ : n × o ≃ n × o hσ : ∀ (x : n × o), (↑σ x).snd = x.snd hσ' : ∀ (x : n × o), (↑σ⁻¹ x).snd = x.snd mk_apply_eq : ∀ (k : o) (x : n), ((↑σ (x, k)).fst, k) = ↑σ (x, k) mk_inv_apply_eq : ∀ (k : o) (x : n), ((↑σ⁻¹ (x, k)).fst, k) = ↑σ⁻¹ (x, k) ⊢ σ = (fun σ x => prodCongrLeft fun k => σ k (_ : k ∈ univ)) (fun k x => { toFun := fun x => (↑σ (x, k)).fst, invFun := fun x => (↑σ⁻¹ (x, k)).fst, left_inv := (_ : ∀ (x : n), (↑σ⁻¹ ((↑σ (x, k)).fst, k)).fst = x), right_inv := (_ : ∀ (x : n), (↑σ ((↑σ⁻¹ (x, k)).fst, k)).fst = x) }) (_ : (fun k x => { toFun := fun x => (↑σ (x, k)).fst, invFun := fun x => (↑σ⁻¹ (x, k)).fst, left_inv := (_ : ∀ (x : n), (↑σ⁻¹ ((↑σ (x, k)).fst, k)).fst = x), right_inv := (_ : ∀ (x : n), (↑σ ((↑σ⁻¹ (x, k)).fst, k)).fst = x) }) ∈ univ) [PROOFSTEP] ext ⟨k, x⟩ [GOAL] case refine'_4.H.mk.h₁ m : Type u_1 n : Type u_2 inst✝⁶ : DecidableEq n inst✝⁵ : Fintype n inst✝⁴ : DecidableEq m inst✝³ : Fintype m R : Type v inst✝² : CommRing R o : Type u_3 inst✝¹ : Fintype o inst✝ : DecidableEq o M : o → Matrix n n R preserving_snd : Finset (Perm (n × o)) := filter (fun σ => ∀ (x : n × o), (↑σ x).snd = x.snd) univ mem_preserving_snd : ∀ {σ : Perm (n × o)}, σ ∈ preserving_snd ↔ ∀ (x : n × o), (↑σ x).snd = x.snd σ : n × o ≃ n × o hσ : ∀ (x : n × o), (↑σ x).snd = x.snd hσ' : ∀ (x : n × o), (↑σ⁻¹ x).snd = x.snd mk_apply_eq : ∀ (k : o) (x : n), ((↑σ (x, k)).fst, k) = ↑σ (x, k) mk_inv_apply_eq : ∀ (k : o) (x : n), ((↑σ⁻¹ (x, k)).fst, k) = ↑σ⁻¹ (x, k) k : n x : o ⊢ (↑σ (k, x)).fst = (↑((fun σ x => prodCongrLeft fun k => σ k (_ : k ∈ univ)) (fun k x => { toFun := fun x => (↑σ (x, k)).fst, invFun := fun x => (↑σ⁻¹ (x, k)).fst, left_inv := (_ : ∀ (x : n), (↑σ⁻¹ ((↑σ (x, k)).fst, k)).fst = x), right_inv := (_ : ∀ (x : n), (↑σ ((↑σ⁻¹ (x, k)).fst, k)).fst = x) }) (_ : (fun k x => { toFun := fun x => (↑σ (x, k)).fst, invFun := fun x => (↑σ⁻¹ (x, k)).fst, left_inv := (_ : ∀ (x : n), (↑σ⁻¹ ((↑σ (x, k)).fst, k)).fst = x), right_inv := (_ : ∀ (x : n), (↑σ ((↑σ⁻¹ (x, k)).fst, k)).fst = x) }) ∈ univ)) (k, x)).fst [PROOFSTEP] simp only [coe_fn_mk, prodCongrLeft_apply] [GOAL] case refine'_4.H.mk.h₂ m : Type u_1 n : Type u_2 inst✝⁶ : DecidableEq n inst✝⁵ : Fintype n inst✝⁴ : DecidableEq m inst✝³ : Fintype m R : Type v inst✝² : CommRing R o : Type u_3 inst✝¹ : Fintype o inst✝ : DecidableEq o M : o → Matrix n n R preserving_snd : Finset (Perm (n × o)) := filter (fun σ => ∀ (x : n × o), (↑σ x).snd = x.snd) univ mem_preserving_snd : ∀ {σ : Perm (n × o)}, σ ∈ preserving_snd ↔ ∀ (x : n × o), (↑σ x).snd = x.snd σ : n × o ≃ n × o hσ : ∀ (x : n × o), (↑σ x).snd = x.snd hσ' : ∀ (x : n × o), (↑σ⁻¹ x).snd = x.snd mk_apply_eq : ∀ (k : o) (x : n), ((↑σ (x, k)).fst, k) = ↑σ (x, k) mk_inv_apply_eq : ∀ (k : o) (x : n), ((↑σ⁻¹ (x, k)).fst, k) = ↑σ⁻¹ (x, k) k : n x : o ⊢ (↑σ (k, x)).snd = (↑((fun σ x => prodCongrLeft fun k => σ k (_ : k ∈ univ)) (fun k x => { toFun := fun x => (↑σ (x, k)).fst, invFun := fun x => (↑σ⁻¹ (x, k)).fst, left_inv := (_ : ∀ (x : n), (↑σ⁻¹ ((↑σ (x, k)).fst, k)).fst = x), right_inv := (_ : ∀ (x : n), (↑σ ((↑σ⁻¹ (x, k)).fst, k)).fst = x) }) (_ : (fun k x => { toFun := fun x => (↑σ (x, k)).fst, invFun := fun x => (↑σ⁻¹ (x, k)).fst, left_inv := (_ : ∀ (x : n), (↑σ⁻¹ ((↑σ (x, k)).fst, k)).fst = x), right_inv := (_ : ∀ (x : n), (↑σ ((↑σ⁻¹ (x, k)).fst, k)).fst = x) }) ∈ univ)) (k, x)).snd [PROOFSTEP] simp only [prodCongrLeft_apply, hσ] [GOAL] m : Type u_1 n : Type u_2 inst✝⁶ : DecidableEq n inst✝⁵ : Fintype n inst✝⁴ : DecidableEq m inst✝³ : Fintype m R : Type v inst✝² : CommRing R o : Type u_3 inst✝¹ : Fintype o inst✝ : DecidableEq o M : o → Matrix n n R preserving_snd : Finset (Perm (n × o)) := filter (fun σ => ∀ (x : n × o), (↑σ x).snd = x.snd) univ mem_preserving_snd : ∀ {σ : Perm (n × o)}, σ ∈ preserving_snd ↔ ∀ (x : n × o), (↑σ x).snd = x.snd ⊢ ∀ (x : Perm (n × o)), x ∈ univ → ¬x ∈ preserving_snd → ↑↑(↑sign x) * ∏ x_1 : n × o, blockDiagonal M (↑x x_1) x_1 = 0 [PROOFSTEP] intro σ _ hσ [GOAL] m : Type u_1 n : Type u_2 inst✝⁶ : DecidableEq n inst✝⁵ : Fintype n inst✝⁴ : DecidableEq m inst✝³ : Fintype m R : Type v inst✝² : CommRing R o : Type u_3 inst✝¹ : Fintype o inst✝ : DecidableEq o M : o → Matrix n n R preserving_snd : Finset (Perm (n × o)) := filter (fun σ => ∀ (x : n × o), (↑σ x).snd = x.snd) univ mem_preserving_snd : ∀ {σ : Perm (n × o)}, σ ∈ preserving_snd ↔ ∀ (x : n × o), (↑σ x).snd = x.snd σ : Perm (n × o) a✝ : σ ∈ univ hσ : ¬σ ∈ preserving_snd ⊢ ↑↑(↑sign σ) * ∏ x : n × o, blockDiagonal M (↑σ x) x = 0 [PROOFSTEP] rw [mem_preserving_snd] at hσ [GOAL] m : Type u_1 n : Type u_2 inst✝⁶ : DecidableEq n inst✝⁵ : Fintype n inst✝⁴ : DecidableEq m inst✝³ : Fintype m R : Type v inst✝² : CommRing R o : Type u_3 inst✝¹ : Fintype o inst✝ : DecidableEq o M : o → Matrix n n R preserving_snd : Finset (Perm (n × o)) := filter (fun σ => ∀ (x : n × o), (↑σ x).snd = x.snd) univ mem_preserving_snd : ∀ {σ : Perm (n × o)}, σ ∈ preserving_snd ↔ ∀ (x : n × o), (↑σ x).snd = x.snd σ : Perm (n × o) a✝ : σ ∈ univ hσ : ¬∀ (x : n × o), (↑σ x).snd = x.snd ⊢ ↑↑(↑sign σ) * ∏ x : n × o, blockDiagonal M (↑σ x) x = 0 [PROOFSTEP] obtain ⟨⟨k, x⟩, hkx⟩ := not_forall.mp hσ [GOAL] case intro.mk m : Type u_1 n : Type u_2 inst✝⁶ : DecidableEq n inst✝⁵ : Fintype n inst✝⁴ : DecidableEq m inst✝³ : Fintype m R : Type v inst✝² : CommRing R o : Type u_3 inst✝¹ : Fintype o inst✝ : DecidableEq o M : o → Matrix n n R preserving_snd : Finset (Perm (n × o)) := filter (fun σ => ∀ (x : n × o), (↑σ x).snd = x.snd) univ mem_preserving_snd : ∀ {σ : Perm (n × o)}, σ ∈ preserving_snd ↔ ∀ (x : n × o), (↑σ x).snd = x.snd σ : Perm (n × o) a✝ : σ ∈ univ hσ : ¬∀ (x : n × o), (↑σ x).snd = x.snd k : n x : o hkx : ¬(↑σ (k, x)).snd = (k, x).snd ⊢ ↑↑(↑sign σ) * ∏ x : n × o, blockDiagonal M (↑σ x) x = 0 [PROOFSTEP] rw [Finset.prod_eq_zero (Finset.mem_univ (k, x)), mul_zero] [GOAL] case intro.mk m : Type u_1 n : Type u_2 inst✝⁶ : DecidableEq n inst✝⁵ : Fintype n inst✝⁴ : DecidableEq m inst✝³ : Fintype m R : Type v inst✝² : CommRing R o : Type u_3 inst✝¹ : Fintype o inst✝ : DecidableEq o M : o → Matrix n n R preserving_snd : Finset (Perm (n × o)) := filter (fun σ => ∀ (x : n × o), (↑σ x).snd = x.snd) univ mem_preserving_snd : ∀ {σ : Perm (n × o)}, σ ∈ preserving_snd ↔ ∀ (x : n × o), (↑σ x).snd = x.snd σ : Perm (n × o) a✝ : σ ∈ univ hσ : ¬∀ (x : n × o), (↑σ x).snd = x.snd k : n x : o hkx : ¬(↑σ (k, x)).snd = (k, x).snd ⊢ blockDiagonal M (↑σ (k, x)) (k, x) = 0 [PROOFSTEP] rw [← @Prod.mk.eta _ _ (σ (k, x)), blockDiagonal_apply_ne] [GOAL] case intro.mk.h m : Type u_1 n : Type u_2 inst✝⁶ : DecidableEq n inst✝⁵ : Fintype n inst✝⁴ : DecidableEq m inst✝³ : Fintype m R : Type v inst✝² : CommRing R o : Type u_3 inst✝¹ : Fintype o inst✝ : DecidableEq o M : o → Matrix n n R preserving_snd : Finset (Perm (n × o)) := filter (fun σ => ∀ (x : n × o), (↑σ x).snd = x.snd) univ mem_preserving_snd : ∀ {σ : Perm (n × o)}, σ ∈ preserving_snd ↔ ∀ (x : n × o), (↑σ x).snd = x.snd σ : Perm (n × o) a✝ : σ ∈ univ hσ : ¬∀ (x : n × o), (↑σ x).snd = x.snd k : n x : o hkx : ¬(↑σ (k, x)).snd = (k, x).snd ⊢ (↑σ (k, x)).snd ≠ x [PROOFSTEP] exact hkx [GOAL] m : Type u_1 n : Type u_2 inst✝⁴ : DecidableEq n inst✝³ : Fintype n inst✝² : DecidableEq m inst✝¹ : Fintype m R : Type v inst✝ : CommRing R A : Matrix m m R B : Matrix m n R D : Matrix n n R ⊢ det (fromBlocks A B 0 D) = det A * det D [PROOFSTEP] classical simp_rw [det_apply'] convert Eq.symm <| sum_subset (β := R) (subset_univ ((sumCongrHom m n).range : Set (Perm (Sum m n))).toFinset) ?_ rw [sum_mul_sum] simp_rw [univ_product_univ] rw [(sum_bij (fun (σ : Perm m × Perm n) _ => Equiv.sumCongr σ.fst σ.snd) _ _ _ _).symm] · intro σ₁₂ h simp only erw [Set.mem_toFinset, MonoidHom.mem_range] use σ₁₂ simp only [sumCongrHom_apply] · simp only [forall_prop_of_true, Prod.forall, mem_univ] intro σ₁ σ₂ rw [Fintype.prod_sum_type] simp_rw [Equiv.sumCongr_apply, Sum.map_inr, Sum.map_inl, fromBlocks_apply₁₁, fromBlocks_apply₂₂] rw [mul_mul_mul_comm] congr rw [sign_sumCongr, Units.val_mul, Int.cast_mul] · intro σ₁ σ₂ h₁ h₂ dsimp only intro h have h2 : ∀ x, Perm.sumCongr σ₁.fst σ₁.snd x = Perm.sumCongr σ₂.fst σ₂.snd x := by intro x exact congr_fun (congr_arg toFun h) x simp only [Sum.map_inr, Sum.map_inl, Perm.sumCongr_apply, Sum.forall, Sum.inl.injEq, Sum.inr.injEq] at h2 ext x · exact h2.left x · exact h2.right x · intro σ hσ erw [Set.mem_toFinset, MonoidHom.mem_range] at hσ obtain ⟨σ₁₂, hσ₁₂⟩ := hσ use σ₁₂ rw [← hσ₁₂] simp · rintro σ - hσn have h1 : ¬∀ x, ∃ y, Sum.inl y = σ (Sum.inl x) := by rw [Set.mem_toFinset] at hσn simpa only [Set.MapsTo, Set.mem_range, forall_exists_index, forall_apply_eq_imp_iff'] using mt mem_sumCongrHom_range_of_perm_mapsTo_inl hσn obtain ⟨a, ha⟩ := not_forall.mp h1 cases' hx : σ (Sum.inl a) with a2 b · have hn := (not_exists.mp ha) a2 exact absurd hx.symm hn · rw [Finset.prod_eq_zero (Finset.mem_univ (Sum.inl a)), mul_zero] rw [hx, fromBlocks_apply₂₁, zero_apply] [GOAL] m : Type u_1 n : Type u_2 inst✝⁴ : DecidableEq n inst✝³ : Fintype n inst✝² : DecidableEq m inst✝¹ : Fintype m R : Type v inst✝ : CommRing R A : Matrix m m R B : Matrix m n R D : Matrix n n R ⊢ det (fromBlocks A B 0 D) = det A * det D [PROOFSTEP] simp_rw [det_apply'] [GOAL] m : Type u_1 n : Type u_2 inst✝⁴ : DecidableEq n inst✝³ : Fintype n inst✝² : DecidableEq m inst✝¹ : Fintype m R : Type v inst✝ : CommRing R A : Matrix m m R B : Matrix m n R D : Matrix n n R ⊢ ∑ x : Perm (m ⊕ n), ↑↑(↑sign x) * ∏ x_1 : m ⊕ n, fromBlocks A B 0 D (↑x x_1) x_1 = (∑ x : Perm m, ↑↑(↑sign x) * ∏ x_1 : m, A (↑x x_1) x_1) * ∑ x : Perm n, ↑↑(↑sign x) * ∏ x_1 : n, D (↑x x_1) x_1 [PROOFSTEP] convert Eq.symm <| sum_subset (β := R) (subset_univ ((sumCongrHom m n).range : Set (Perm (Sum m n))).toFinset) ?_ [GOAL] case h.e'_3 m : Type u_1 n : Type u_2 inst✝⁴ : DecidableEq n inst✝³ : Fintype n inst✝² : DecidableEq m inst✝¹ : Fintype m R : Type v inst✝ : CommRing R A : Matrix m m R B : Matrix m n R D : Matrix n n R ⊢ (∑ x : Perm m, ↑↑(↑sign x) * ∏ x_1 : m, A (↑x x_1) x_1) * ∑ x : Perm n, ↑↑(↑sign x) * ∏ x_1 : n, D (↑x x_1) x_1 = ∑ x in Set.toFinset ↑(MonoidHom.range (sumCongrHom m n)), ↑↑(↑sign x) * ∏ x_1 : m ⊕ n, fromBlocks A B 0 D (↑x x_1) x_1 case convert_2 m : Type u_1 n : Type u_2 inst✝⁴ : DecidableEq n inst✝³ : Fintype n inst✝² : DecidableEq m inst✝¹ : Fintype m R : Type v inst✝ : CommRing R A : Matrix m m R B : Matrix m n R D : Matrix n n R ⊢ ∀ (x : Perm (m ⊕ n)), x ∈ univ → ¬x ∈ Set.toFinset ↑(MonoidHom.range (sumCongrHom m n)) → ↑↑(↑sign x) * ∏ x_1 : m ⊕ n, fromBlocks A B 0 D (↑x x_1) x_1 = 0 [PROOFSTEP] rw [sum_mul_sum] [GOAL] case h.e'_3 m : Type u_1 n : Type u_2 inst✝⁴ : DecidableEq n inst✝³ : Fintype n inst✝² : DecidableEq m inst✝¹ : Fintype m R : Type v inst✝ : CommRing R A : Matrix m m R B : Matrix m n R D : Matrix n n R ⊢ ∑ p in univ ×ˢ univ, (↑↑(↑sign p.fst) * ∏ x : m, A (↑p.fst x) x) * (↑↑(↑sign p.snd) * ∏ x : n, D (↑p.snd x) x) = ∑ x in Set.toFinset ↑(MonoidHom.range (sumCongrHom m n)), ↑↑(↑sign x) * ∏ x_1 : m ⊕ n, fromBlocks A B 0 D (↑x x_1) x_1 case convert_2 m : Type u_1 n : Type u_2 inst✝⁴ : DecidableEq n inst✝³ : Fintype n inst✝² : DecidableEq m inst✝¹ : Fintype m R : Type v inst✝ : CommRing R A : Matrix m m R B : Matrix m n R D : Matrix n n R ⊢ ∀ (x : Perm (m ⊕ n)), x ∈ univ → ¬x ∈ Set.toFinset ↑(MonoidHom.range (sumCongrHom m n)) → ↑↑(↑sign x) * ∏ x_1 : m ⊕ n, fromBlocks A B 0 D (↑x x_1) x_1 = 0 [PROOFSTEP] simp_rw [univ_product_univ] [GOAL] case h.e'_3 m : Type u_1 n : Type u_2 inst✝⁴ : DecidableEq n inst✝³ : Fintype n inst✝² : DecidableEq m inst✝¹ : Fintype m R : Type v inst✝ : CommRing R A : Matrix m m R B : Matrix m n R D : Matrix n n R ⊢ ∑ p : Perm m × Perm n, (↑↑(↑sign p.fst) * ∏ x : m, A (↑p.fst x) x) * (↑↑(↑sign p.snd) * ∏ x : n, D (↑p.snd x) x) = ∑ x in Set.toFinset ↑(MonoidHom.range (sumCongrHom m n)), ↑↑(↑sign x) * ∏ x_1 : m ⊕ n, fromBlocks A B 0 D (↑x x_1) x_1 case convert_2 m : Type u_1 n : Type u_2 inst✝⁴ : DecidableEq n inst✝³ : Fintype n inst✝² : DecidableEq m inst✝¹ : Fintype m R : Type v inst✝ : CommRing R A : Matrix m m R B : Matrix m n R D : Matrix n n R ⊢ ∀ (x : Perm (m ⊕ n)), x ∈ univ → ¬x ∈ Set.toFinset ↑(MonoidHom.range (sumCongrHom m n)) → ↑↑(↑sign x) * ∏ x_1 : m ⊕ n, fromBlocks A B 0 D (↑x x_1) x_1 = 0 [PROOFSTEP] rw [(sum_bij (fun (σ : Perm m × Perm n) _ => Equiv.sumCongr σ.fst σ.snd) _ _ _ _).symm] [GOAL] m : Type u_1 n : Type u_2 inst✝⁴ : DecidableEq n inst✝³ : Fintype n inst✝² : DecidableEq m inst✝¹ : Fintype m R : Type v inst✝ : CommRing R A : Matrix m m R B : Matrix m n R D : Matrix n n R ⊢ ∀ (a : Perm m × Perm n) (ha : a ∈ univ), (fun σ x => Equiv.sumCongr σ.fst σ.snd) a ha ∈ Set.toFinset ↑(MonoidHom.range (sumCongrHom m n)) [PROOFSTEP] intro σ₁₂ h [GOAL] m : Type u_1 n : Type u_2 inst✝⁴ : DecidableEq n inst✝³ : Fintype n inst✝² : DecidableEq m inst✝¹ : Fintype m R : Type v inst✝ : CommRing R A : Matrix m m R B : Matrix m n R D : Matrix n n R σ₁₂ : Perm m × Perm n h : σ₁₂ ∈ univ ⊢ (fun σ x => Equiv.sumCongr σ.fst σ.snd) σ₁₂ h ∈ Set.toFinset ↑(MonoidHom.range (sumCongrHom m n)) [PROOFSTEP] simp only [GOAL] m : Type u_1 n : Type u_2 inst✝⁴ : DecidableEq n inst✝³ : Fintype n inst✝² : DecidableEq m inst✝¹ : Fintype m R : Type v inst✝ : CommRing R A : Matrix m m R B : Matrix m n R D : Matrix n n R σ₁₂ : Perm m × Perm n h : σ₁₂ ∈ univ ⊢ Equiv.sumCongr σ₁₂.fst σ₁₂.snd ∈ Set.toFinset ↑(MonoidHom.range (sumCongrHom m n)) [PROOFSTEP] erw [Set.mem_toFinset, MonoidHom.mem_range] [GOAL] m : Type u_1 n : Type u_2 inst✝⁴ : DecidableEq n inst✝³ : Fintype n inst✝² : DecidableEq m inst✝¹ : Fintype m R : Type v inst✝ : CommRing R A : Matrix m m R B : Matrix m n R D : Matrix n n R σ₁₂ : Perm m × Perm n h : σ₁₂ ∈ univ ⊢ ∃ x, ↑(sumCongrHom m n) x = Equiv.sumCongr σ₁₂.fst σ₁₂.snd [PROOFSTEP] use σ₁₂ [GOAL] case h m : Type u_1 n : Type u_2 inst✝⁴ : DecidableEq n inst✝³ : Fintype n inst✝² : DecidableEq m inst✝¹ : Fintype m R : Type v inst✝ : CommRing R A : Matrix m m R B : Matrix m n R D : Matrix n n R σ₁₂ : Perm m × Perm n h : σ₁₂ ∈ univ ⊢ ↑(sumCongrHom m n) σ₁₂ = Equiv.sumCongr σ₁₂.fst σ₁₂.snd [PROOFSTEP] simp only [sumCongrHom_apply] [GOAL] m : Type u_1 n : Type u_2 inst✝⁴ : DecidableEq n inst✝³ : Fintype n inst✝² : DecidableEq m inst✝¹ : Fintype m R : Type v inst✝ : CommRing R A : Matrix m m R B : Matrix m n R D : Matrix n n R ⊢ ∀ (a : Perm m × Perm n) (ha : a ∈ univ), (↑↑(↑sign a.fst) * ∏ x : m, A (↑a.fst x) x) * (↑↑(↑sign a.snd) * ∏ x : n, D (↑a.snd x) x) = ↑↑(↑sign ((fun σ x => Equiv.sumCongr σ.fst σ.snd) a ha)) * ∏ x : m ⊕ n, fromBlocks A B 0 D (↑((fun σ x => Equiv.sumCongr σ.fst σ.snd) a ha) x) x [PROOFSTEP] simp only [forall_prop_of_true, Prod.forall, mem_univ] [GOAL] m : Type u_1 n : Type u_2 inst✝⁴ : DecidableEq n inst✝³ : Fintype n inst✝² : DecidableEq m inst✝¹ : Fintype m R : Type v inst✝ : CommRing R A : Matrix m m R B : Matrix m n R D : Matrix n n R ⊢ ∀ (a : Perm m) (b : Perm n), (↑↑(↑sign a) * ∏ x : m, A (↑a x) x) * (↑↑(↑sign b) * ∏ x : n, D (↑b x) x) = ↑↑(↑sign (Equiv.sumCongr a b)) * ∏ x : m ⊕ n, fromBlocks A B 0 D (↑(Equiv.sumCongr a b) x) x [PROOFSTEP] intro σ₁ σ₂ [GOAL] m : Type u_1 n : Type u_2 inst✝⁴ : DecidableEq n inst✝³ : Fintype n inst✝² : DecidableEq m inst✝¹ : Fintype m R : Type v inst✝ : CommRing R A : Matrix m m R B : Matrix m n R D : Matrix n n R σ₁ : Perm m σ₂ : Perm n ⊢ (↑↑(↑sign σ₁) * ∏ x : m, A (↑σ₁ x) x) * (↑↑(↑sign σ₂) * ∏ x : n, D (↑σ₂ x) x) = ↑↑(↑sign (Equiv.sumCongr σ₁ σ₂)) * ∏ x : m ⊕ n, fromBlocks A B 0 D (↑(Equiv.sumCongr σ₁ σ₂) x) x [PROOFSTEP] rw [Fintype.prod_sum_type] [GOAL] m : Type u_1 n : Type u_2 inst✝⁴ : DecidableEq n inst✝³ : Fintype n inst✝² : DecidableEq m inst✝¹ : Fintype m R : Type v inst✝ : CommRing R A : Matrix m m R B : Matrix m n R D : Matrix n n R σ₁ : Perm m σ₂ : Perm n ⊢ (↑↑(↑sign σ₁) * ∏ x : m, A (↑σ₁ x) x) * (↑↑(↑sign σ₂) * ∏ x : n, D (↑σ₂ x) x) = ↑↑(↑sign (Equiv.sumCongr σ₁ σ₂)) * ((∏ a₁ : m, fromBlocks A B 0 D (↑(Equiv.sumCongr σ₁ σ₂) (Sum.inl a₁)) (Sum.inl a₁)) * ∏ a₂ : n, fromBlocks A B 0 D (↑(Equiv.sumCongr σ₁ σ₂) (Sum.inr a₂)) (Sum.inr a₂)) [PROOFSTEP] simp_rw [Equiv.sumCongr_apply, Sum.map_inr, Sum.map_inl, fromBlocks_apply₁₁, fromBlocks_apply₂₂] [GOAL] m : Type u_1 n : Type u_2 inst✝⁴ : DecidableEq n inst✝³ : Fintype n inst✝² : DecidableEq m inst✝¹ : Fintype m R : Type v inst✝ : CommRing R A : Matrix m m R B : Matrix m n R D : Matrix n n R σ₁ : Perm m σ₂ : Perm n ⊢ (↑↑(↑sign σ₁) * ∏ x : m, A (↑σ₁ x) x) * (↑↑(↑sign σ₂) * ∏ x : n, D (↑σ₂ x) x) = ↑↑(↑sign (Equiv.sumCongr σ₁ σ₂)) * ((∏ x : m, A (↑σ₁ x) x) * ∏ x : n, D (↑σ₂ x) x) [PROOFSTEP] rw [mul_mul_mul_comm] [GOAL] m : Type u_1 n : Type u_2 inst✝⁴ : DecidableEq n inst✝³ : Fintype n inst✝² : DecidableEq m inst✝¹ : Fintype m R : Type v inst✝ : CommRing R A : Matrix m m R B : Matrix m n R D : Matrix n n R σ₁ : Perm m σ₂ : Perm n ⊢ ↑↑(↑sign σ₁) * ↑↑(↑sign σ₂) * ((∏ x : m, A (↑σ₁ x) x) * ∏ x : n, D (↑σ₂ x) x) = ↑↑(↑sign (Equiv.sumCongr σ₁ σ₂)) * ((∏ x : m, A (↑σ₁ x) x) * ∏ x : n, D (↑σ₂ x) x) [PROOFSTEP] congr [GOAL] case e_a m : Type u_1 n : Type u_2 inst✝⁴ : DecidableEq n inst✝³ : Fintype n inst✝² : DecidableEq m inst✝¹ : Fintype m R : Type v inst✝ : CommRing R A : Matrix m m R B : Matrix m n R D : Matrix n n R σ₁ : Perm m σ₂ : Perm n ⊢ ↑↑(↑sign σ₁) * ↑↑(↑sign σ₂) = ↑↑(↑sign (Equiv.sumCongr σ₁ σ₂)) [PROOFSTEP] rw [sign_sumCongr, Units.val_mul, Int.cast_mul] [GOAL] m : Type u_1 n : Type u_2 inst✝⁴ : DecidableEq n inst✝³ : Fintype n inst✝² : DecidableEq m inst✝¹ : Fintype m R : Type v inst✝ : CommRing R A : Matrix m m R B : Matrix m n R D : Matrix n n R ⊢ ∀ (a₁ a₂ : Perm m × Perm n) (ha₁ : a₁ ∈ univ) (ha₂ : a₂ ∈ univ), (fun σ x => Equiv.sumCongr σ.fst σ.snd) a₁ ha₁ = (fun σ x => Equiv.sumCongr σ.fst σ.snd) a₂ ha₂ → a₁ = a₂ [PROOFSTEP] intro σ₁ σ₂ h₁ h₂ [GOAL] m : Type u_1 n : Type u_2 inst✝⁴ : DecidableEq n inst✝³ : Fintype n inst✝² : DecidableEq m inst✝¹ : Fintype m R : Type v inst✝ : CommRing R A : Matrix m m R B : Matrix m n R D : Matrix n n R σ₁ σ₂ : Perm m × Perm n h₁ : σ₁ ∈ univ h₂ : σ₂ ∈ univ ⊢ (fun σ x => Equiv.sumCongr σ.fst σ.snd) σ₁ h₁ = (fun σ x => Equiv.sumCongr σ.fst σ.snd) σ₂ h₂ → σ₁ = σ₂ [PROOFSTEP] dsimp only [GOAL] m : Type u_1 n : Type u_2 inst✝⁴ : DecidableEq n inst✝³ : Fintype n inst✝² : DecidableEq m inst✝¹ : Fintype m R : Type v inst✝ : CommRing R A : Matrix m m R B : Matrix m n R D : Matrix n n R σ₁ σ₂ : Perm m × Perm n h₁ : σ₁ ∈ univ h₂ : σ₂ ∈ univ ⊢ Equiv.sumCongr σ₁.fst σ₁.snd = Equiv.sumCongr σ₂.fst σ₂.snd → σ₁ = σ₂ [PROOFSTEP] intro h [GOAL] m : Type u_1 n : Type u_2 inst✝⁴ : DecidableEq n inst✝³ : Fintype n inst✝² : DecidableEq m inst✝¹ : Fintype m R : Type v inst✝ : CommRing R A : Matrix m m R B : Matrix m n R D : Matrix n n R σ₁ σ₂ : Perm m × Perm n h₁ : σ₁ ∈ univ h₂ : σ₂ ∈ univ h : Equiv.sumCongr σ₁.fst σ₁.snd = Equiv.sumCongr σ₂.fst σ₂.snd ⊢ σ₁ = σ₂ [PROOFSTEP] have h2 : ∀ x, Perm.sumCongr σ₁.fst σ₁.snd x = Perm.sumCongr σ₂.fst σ₂.snd x := by intro x exact congr_fun (congr_arg toFun h) x [GOAL] m : Type u_1 n : Type u_2 inst✝⁴ : DecidableEq n inst✝³ : Fintype n inst✝² : DecidableEq m inst✝¹ : Fintype m R : Type v inst✝ : CommRing R A : Matrix m m R B : Matrix m n R D : Matrix n n R σ₁ σ₂ : Perm m × Perm n h₁ : σ₁ ∈ univ h₂ : σ₂ ∈ univ h : Equiv.sumCongr σ₁.fst σ₁.snd = Equiv.sumCongr σ₂.fst σ₂.snd ⊢ ∀ (x : m ⊕ n), ↑(Perm.sumCongr σ₁.fst σ₁.snd) x = ↑(Perm.sumCongr σ₂.fst σ₂.snd) x [PROOFSTEP] intro x [GOAL] m : Type u_1 n : Type u_2 inst✝⁴ : DecidableEq n inst✝³ : Fintype n inst✝² : DecidableEq m inst✝¹ : Fintype m R : Type v inst✝ : CommRing R A : Matrix m m R B : Matrix m n R D : Matrix n n R σ₁ σ₂ : Perm m × Perm n h₁ : σ₁ ∈ univ h₂ : σ₂ ∈ univ h : Equiv.sumCongr σ₁.fst σ₁.snd = Equiv.sumCongr σ₂.fst σ₂.snd x : m ⊕ n ⊢ ↑(Perm.sumCongr σ₁.fst σ₁.snd) x = ↑(Perm.sumCongr σ₂.fst σ₂.snd) x [PROOFSTEP] exact congr_fun (congr_arg toFun h) x [GOAL] m : Type u_1 n : Type u_2 inst✝⁴ : DecidableEq n inst✝³ : Fintype n inst✝² : DecidableEq m inst✝¹ : Fintype m R : Type v inst✝ : CommRing R A : Matrix m m R B : Matrix m n R D : Matrix n n R σ₁ σ₂ : Perm m × Perm n h₁ : σ₁ ∈ univ h₂ : σ₂ ∈ univ h : Equiv.sumCongr σ₁.fst σ₁.snd = Equiv.sumCongr σ₂.fst σ₂.snd h2 : ∀ (x : m ⊕ n), ↑(Perm.sumCongr σ₁.fst σ₁.snd) x = ↑(Perm.sumCongr σ₂.fst σ₂.snd) x ⊢ σ₁ = σ₂ [PROOFSTEP] simp only [Sum.map_inr, Sum.map_inl, Perm.sumCongr_apply, Sum.forall, Sum.inl.injEq, Sum.inr.injEq] at h2 [GOAL] m : Type u_1 n : Type u_2 inst✝⁴ : DecidableEq n inst✝³ : Fintype n inst✝² : DecidableEq m inst✝¹ : Fintype m R : Type v inst✝ : CommRing R A : Matrix m m R B : Matrix m n R D : Matrix n n R σ₁ σ₂ : Perm m × Perm n h₁ : σ₁ ∈ univ h₂ : σ₂ ∈ univ h : Equiv.sumCongr σ₁.fst σ₁.snd = Equiv.sumCongr σ₂.fst σ₂.snd h2 : (∀ (a : m), ↑σ₁.fst a = ↑σ₂.fst a) ∧ ∀ (b : n), ↑σ₁.snd b = ↑σ₂.snd b ⊢ σ₁ = σ₂ [PROOFSTEP] ext x [GOAL] case h₁.H m : Type u_1 n : Type u_2 inst✝⁴ : DecidableEq n inst✝³ : Fintype n inst✝² : DecidableEq m inst✝¹ : Fintype m R : Type v inst✝ : CommRing R A : Matrix m m R B : Matrix m n R D : Matrix n n R σ₁ σ₂ : Perm m × Perm n h₁ : σ₁ ∈ univ h₂ : σ₂ ∈ univ h : Equiv.sumCongr σ₁.fst σ₁.snd = Equiv.sumCongr σ₂.fst σ₂.snd h2 : (∀ (a : m), ↑σ₁.fst a = ↑σ₂.fst a) ∧ ∀ (b : n), ↑σ₁.snd b = ↑σ₂.snd b x : m ⊢ ↑σ₁.fst x = ↑σ₂.fst x [PROOFSTEP] exact h2.left x [GOAL] case h₂.H m : Type u_1 n : Type u_2 inst✝⁴ : DecidableEq n inst✝³ : Fintype n inst✝² : DecidableEq m inst✝¹ : Fintype m R : Type v inst✝ : CommRing R A : Matrix m m R B : Matrix m n R D : Matrix n n R σ₁ σ₂ : Perm m × Perm n h₁ : σ₁ ∈ univ h₂ : σ₂ ∈ univ h : Equiv.sumCongr σ₁.fst σ₁.snd = Equiv.sumCongr σ₂.fst σ₂.snd h2 : (∀ (a : m), ↑σ₁.fst a = ↑σ₂.fst a) ∧ ∀ (b : n), ↑σ₁.snd b = ↑σ₂.snd b x : n ⊢ ↑σ₁.snd x = ↑σ₂.snd x [PROOFSTEP] exact h2.right x [GOAL] m : Type u_1 n : Type u_2 inst✝⁴ : DecidableEq n inst✝³ : Fintype n inst✝² : DecidableEq m inst✝¹ : Fintype m R : Type v inst✝ : CommRing R A : Matrix m m R B : Matrix m n R D : Matrix n n R ⊢ ∀ (b : m ⊕ n ≃ m ⊕ n), b ∈ Set.toFinset ↑(MonoidHom.range (sumCongrHom m n)) → ∃ a ha, b = (fun σ x => Equiv.sumCongr σ.fst σ.snd) a ha [PROOFSTEP] intro σ hσ [GOAL] m : Type u_1 n : Type u_2 inst✝⁴ : DecidableEq n inst✝³ : Fintype n inst✝² : DecidableEq m inst✝¹ : Fintype m R : Type v inst✝ : CommRing R A : Matrix m m R B : Matrix m n R D : Matrix n n R σ : m ⊕ n ≃ m ⊕ n hσ : σ ∈ Set.toFinset ↑(MonoidHom.range (sumCongrHom m n)) ⊢ ∃ a ha, σ = (fun σ x => Equiv.sumCongr σ.fst σ.snd) a ha [PROOFSTEP] erw [Set.mem_toFinset, MonoidHom.mem_range] at hσ [GOAL] m : Type u_1 n : Type u_2 inst✝⁴ : DecidableEq n inst✝³ : Fintype n inst✝² : DecidableEq m inst✝¹ : Fintype m R : Type v inst✝ : CommRing R A : Matrix m m R B : Matrix m n R D : Matrix n n R σ : m ⊕ n ≃ m ⊕ n hσ : ∃ x, ↑(sumCongrHom m n) x = σ ⊢ ∃ a ha, σ = (fun σ x => Equiv.sumCongr σ.fst σ.snd) a ha [PROOFSTEP] obtain ⟨σ₁₂, hσ₁₂⟩ := hσ [GOAL] case intro m : Type u_1 n : Type u_2 inst✝⁴ : DecidableEq n inst✝³ : Fintype n inst✝² : DecidableEq m inst✝¹ : Fintype m R : Type v inst✝ : CommRing R A : Matrix m m R B : Matrix m n R D : Matrix n n R σ : m ⊕ n ≃ m ⊕ n σ₁₂ : Perm m × Perm n hσ₁₂ : ↑(sumCongrHom m n) σ₁₂ = σ ⊢ ∃ a ha, σ = (fun σ x => Equiv.sumCongr σ.fst σ.snd) a ha [PROOFSTEP] use σ₁₂ [GOAL] case h m : Type u_1 n : Type u_2 inst✝⁴ : DecidableEq n inst✝³ : Fintype n inst✝² : DecidableEq m inst✝¹ : Fintype m R : Type v inst✝ : CommRing R A : Matrix m m R B : Matrix m n R D : Matrix n n R σ : m ⊕ n ≃ m ⊕ n σ₁₂ : Perm m × Perm n hσ₁₂ : ↑(sumCongrHom m n) σ₁₂ = σ ⊢ ∃ ha, σ = (fun σ x => Equiv.sumCongr σ.fst σ.snd) σ₁₂ ha [PROOFSTEP] rw [← hσ₁₂] [GOAL] case h m : Type u_1 n : Type u_2 inst✝⁴ : DecidableEq n inst✝³ : Fintype n inst✝² : DecidableEq m inst✝¹ : Fintype m R : Type v inst✝ : CommRing R A : Matrix m m R B : Matrix m n R D : Matrix n n R σ : m ⊕ n ≃ m ⊕ n σ₁₂ : Perm m × Perm n hσ₁₂ : ↑(sumCongrHom m n) σ₁₂ = σ ⊢ ∃ ha, ↑(sumCongrHom m n) σ₁₂ = (fun σ x => Equiv.sumCongr σ.fst σ.snd) σ₁₂ ha [PROOFSTEP] simp [GOAL] case convert_2 m : Type u_1 n : Type u_2 inst✝⁴ : DecidableEq n inst✝³ : Fintype n inst✝² : DecidableEq m inst✝¹ : Fintype m R : Type v inst✝ : CommRing R A : Matrix m m R B : Matrix m n R D : Matrix n n R ⊢ ∀ (x : Perm (m ⊕ n)), x ∈ univ → ¬x ∈ Set.toFinset ↑(MonoidHom.range (sumCongrHom m n)) → ↑↑(↑sign x) * ∏ x_1 : m ⊕ n, fromBlocks A B 0 D (↑x x_1) x_1 = 0 [PROOFSTEP] rintro σ - hσn [GOAL] case convert_2 m : Type u_1 n : Type u_2 inst✝⁴ : DecidableEq n inst✝³ : Fintype n inst✝² : DecidableEq m inst✝¹ : Fintype m R : Type v inst✝ : CommRing R A : Matrix m m R B : Matrix m n R D : Matrix n n R σ : Perm (m ⊕ n) hσn : ¬σ ∈ Set.toFinset ↑(MonoidHom.range (sumCongrHom m n)) ⊢ ↑↑(↑sign σ) * ∏ x : m ⊕ n, fromBlocks A B 0 D (↑σ x) x = 0 [PROOFSTEP] have h1 : ¬∀ x, ∃ y, Sum.inl y = σ (Sum.inl x) := by rw [Set.mem_toFinset] at hσn simpa only [Set.MapsTo, Set.mem_range, forall_exists_index, forall_apply_eq_imp_iff'] using mt mem_sumCongrHom_range_of_perm_mapsTo_inl hσn [GOAL] m : Type u_1 n : Type u_2 inst✝⁴ : DecidableEq n inst✝³ : Fintype n inst✝² : DecidableEq m inst✝¹ : Fintype m R : Type v inst✝ : CommRing R A : Matrix m m R B : Matrix m n R D : Matrix n n R σ : Perm (m ⊕ n) hσn : ¬σ ∈ Set.toFinset ↑(MonoidHom.range (sumCongrHom m n)) ⊢ ¬∀ (x : m), ∃ y, Sum.inl y = ↑σ (Sum.inl x) [PROOFSTEP] rw [Set.mem_toFinset] at hσn [GOAL] m : Type u_1 n : Type u_2 inst✝⁴ : DecidableEq n inst✝³ : Fintype n inst✝² : DecidableEq m inst✝¹ : Fintype m R : Type v inst✝ : CommRing R A : Matrix m m R B : Matrix m n R D : Matrix n n R σ : Perm (m ⊕ n) hσn : ¬σ ∈ ↑(MonoidHom.range (sumCongrHom m n)) ⊢ ¬∀ (x : m), ∃ y, Sum.inl y = ↑σ (Sum.inl x) [PROOFSTEP] simpa only [Set.MapsTo, Set.mem_range, forall_exists_index, forall_apply_eq_imp_iff'] using mt mem_sumCongrHom_range_of_perm_mapsTo_inl hσn [GOAL] case convert_2 m : Type u_1 n : Type u_2 inst✝⁴ : DecidableEq n inst✝³ : Fintype n inst✝² : DecidableEq m inst✝¹ : Fintype m R : Type v inst✝ : CommRing R A : Matrix m m R B : Matrix m n R D : Matrix n n R σ : Perm (m ⊕ n) hσn : ¬σ ∈ Set.toFinset ↑(MonoidHom.range (sumCongrHom m n)) h1 : ¬∀ (x : m), ∃ y, Sum.inl y = ↑σ (Sum.inl x) ⊢ ↑↑(↑sign σ) * ∏ x : m ⊕ n, fromBlocks A B 0 D (↑σ x) x = 0 [PROOFSTEP] obtain ⟨a, ha⟩ := not_forall.mp h1 [GOAL] case convert_2.intro m : Type u_1 n : Type u_2 inst✝⁴ : DecidableEq n inst✝³ : Fintype n inst✝² : DecidableEq m inst✝¹ : Fintype m R : Type v inst✝ : CommRing R A : Matrix m m R B : Matrix m n R D : Matrix n n R σ : Perm (m ⊕ n) hσn : ¬σ ∈ Set.toFinset ↑(MonoidHom.range (sumCongrHom m n)) h1 : ¬∀ (x : m), ∃ y, Sum.inl y = ↑σ (Sum.inl x) a : m ha : ¬∃ y, Sum.inl y = ↑σ (Sum.inl a) ⊢ ↑↑(↑sign σ) * ∏ x : m ⊕ n, fromBlocks A B 0 D (↑σ x) x = 0 [PROOFSTEP] cases' hx : σ (Sum.inl a) with a2 b [GOAL] case convert_2.intro.inl m : Type u_1 n : Type u_2 inst✝⁴ : DecidableEq n inst✝³ : Fintype n inst✝² : DecidableEq m inst✝¹ : Fintype m R : Type v inst✝ : CommRing R A : Matrix m m R B : Matrix m n R D : Matrix n n R σ : Perm (m ⊕ n) hσn : ¬σ ∈ Set.toFinset ↑(MonoidHom.range (sumCongrHom m n)) h1 : ¬∀ (x : m), ∃ y, Sum.inl y = ↑σ (Sum.inl x) a : m ha : ¬∃ y, Sum.inl y = ↑σ (Sum.inl a) a2 : m hx : ↑σ (Sum.inl a) = Sum.inl a2 ⊢ ↑↑(↑sign σ) * ∏ x : m ⊕ n, fromBlocks A B 0 D (↑σ x) x = 0 [PROOFSTEP] have hn := (not_exists.mp ha) a2 [GOAL] case convert_2.intro.inl m : Type u_1 n : Type u_2 inst✝⁴ : DecidableEq n inst✝³ : Fintype n inst✝² : DecidableEq m inst✝¹ : Fintype m R : Type v inst✝ : CommRing R A : Matrix m m R B : Matrix m n R D : Matrix n n R σ : Perm (m ⊕ n) hσn : ¬σ ∈ Set.toFinset ↑(MonoidHom.range (sumCongrHom m n)) h1 : ¬∀ (x : m), ∃ y, Sum.inl y = ↑σ (Sum.inl x) a : m ha : ¬∃ y, Sum.inl y = ↑σ (Sum.inl a) a2 : m hx : ↑σ (Sum.inl a) = Sum.inl a2 hn : ¬Sum.inl a2 = ↑σ (Sum.inl a) ⊢ ↑↑(↑sign σ) * ∏ x : m ⊕ n, fromBlocks A B 0 D (↑σ x) x = 0 [PROOFSTEP] exact absurd hx.symm hn [GOAL] case convert_2.intro.inr m : Type u_1 n : Type u_2 inst✝⁴ : DecidableEq n inst✝³ : Fintype n inst✝² : DecidableEq m inst✝¹ : Fintype m R : Type v inst✝ : CommRing R A : Matrix m m R B : Matrix m n R D : Matrix n n R σ : Perm (m ⊕ n) hσn : ¬σ ∈ Set.toFinset ↑(MonoidHom.range (sumCongrHom m n)) h1 : ¬∀ (x : m), ∃ y, Sum.inl y = ↑σ (Sum.inl x) a : m ha : ¬∃ y, Sum.inl y = ↑σ (Sum.inl a) b : n hx : ↑σ (Sum.inl a) = Sum.inr b ⊢ ↑↑(↑sign σ) * ∏ x : m ⊕ n, fromBlocks A B 0 D (↑σ x) x = 0 [PROOFSTEP] rw [Finset.prod_eq_zero (Finset.mem_univ (Sum.inl a)), mul_zero] [GOAL] case convert_2.intro.inr m : Type u_1 n : Type u_2 inst✝⁴ : DecidableEq n inst✝³ : Fintype n inst✝² : DecidableEq m inst✝¹ : Fintype m R : Type v inst✝ : CommRing R A : Matrix m m R B : Matrix m n R D : Matrix n n R σ : Perm (m ⊕ n) hσn : ¬σ ∈ Set.toFinset ↑(MonoidHom.range (sumCongrHom m n)) h1 : ¬∀ (x : m), ∃ y, Sum.inl y = ↑σ (Sum.inl x) a : m ha : ¬∃ y, Sum.inl y = ↑σ (Sum.inl a) b : n hx : ↑σ (Sum.inl a) = Sum.inr b ⊢ fromBlocks A B 0 D (↑σ (Sum.inl a)) (Sum.inl a) = 0 [PROOFSTEP] rw [hx, fromBlocks_apply₂₁, zero_apply] [GOAL] m : Type u_1 n : Type u_2 inst✝⁴ : DecidableEq n inst✝³ : Fintype n inst✝² : DecidableEq m inst✝¹ : Fintype m R : Type v inst✝ : CommRing R A : Matrix m m R C : Matrix n m R D : Matrix n n R ⊢ det (fromBlocks A 0 C D) = det A * det D [PROOFSTEP] rw [← det_transpose, fromBlocks_transpose, transpose_zero, det_fromBlocks_zero₂₁, det_transpose, det_transpose] [GOAL] m : Type u_1 n✝ : Type u_2 inst✝⁴ : DecidableEq n✝ inst✝³ : Fintype n✝ inst✝² : DecidableEq m inst✝¹ : Fintype m R : Type v inst✝ : CommRing R n : ℕ A : Matrix (Fin (Nat.succ n)) (Fin (Nat.succ n)) R ⊢ det A = ∑ i : Fin (Nat.succ n), (-1) ^ ↑i * A i 0 * det (submatrix A (Fin.succAbove i) Fin.succ) [PROOFSTEP] rw [Matrix.det_apply, Finset.univ_perm_fin_succ, ← Finset.univ_product_univ] [GOAL] m : Type u_1 n✝ : Type u_2 inst✝⁴ : DecidableEq n✝ inst✝³ : Fintype n✝ inst✝² : DecidableEq m inst✝¹ : Fintype m R : Type v inst✝ : CommRing R n : ℕ A : Matrix (Fin (Nat.succ n)) (Fin (Nat.succ n)) R ⊢ ∑ σ in Finset.map (Equiv.toEmbedding decomposeFin.symm) (univ ×ˢ univ), ↑sign σ • ∏ i : Fin (Nat.succ n), A (↑σ i) i = ∑ i : Fin (Nat.succ n), (-1) ^ ↑i * A i 0 * det (submatrix A (Fin.succAbove i) Fin.succ) [PROOFSTEP] simp only [Finset.sum_map, Equiv.toEmbedding_apply, Finset.sum_product, Matrix.submatrix] [GOAL] m : Type u_1 n✝ : Type u_2 inst✝⁴ : DecidableEq n✝ inst✝³ : Fintype n✝ inst✝² : DecidableEq m inst✝¹ : Fintype m R : Type v inst✝ : CommRing R n : ℕ A : Matrix (Fin (Nat.succ n)) (Fin (Nat.succ n)) R ⊢ ∑ x : Fin (Nat.succ n), ∑ y : Perm (Fin n), ↑sign (↑decomposeFin.symm (x, y)) • ∏ x_1 : Fin (Nat.succ n), A (↑(↑decomposeFin.symm (x, y)) x_1) x_1 = ∑ x : Fin (Nat.succ n), (-1) ^ ↑x * A x 0 * det (↑of fun i j => A (Fin.succAbove x i) (Fin.succ j)) [PROOFSTEP] refine' Finset.sum_congr rfl fun i _ => Fin.cases _ (fun i => _) i [GOAL] case refine'_1 m : Type u_1 n✝ : Type u_2 inst✝⁴ : DecidableEq n✝ inst✝³ : Fintype n✝ inst✝² : DecidableEq m inst✝¹ : Fintype m R : Type v inst✝ : CommRing R n : ℕ A : Matrix (Fin (Nat.succ n)) (Fin (Nat.succ n)) R i : Fin (Nat.succ n) x✝ : i ∈ univ ⊢ ∑ y : Perm (Fin n), ↑sign (↑decomposeFin.symm (0, y)) • ∏ x : Fin (Nat.succ n), A (↑(↑decomposeFin.symm (0, y)) x) x = (-1) ^ ↑0 * A 0 0 * det (↑of fun i j => A (Fin.succAbove 0 i) (Fin.succ j)) [PROOFSTEP] simp only [Fin.prod_univ_succ, Matrix.det_apply, Finset.mul_sum, Equiv.Perm.decomposeFin_symm_apply_zero, Fin.val_zero, one_mul, Equiv.Perm.decomposeFin.symm_sign, Equiv.swap_self, if_true, id.def, eq_self_iff_true, Equiv.Perm.decomposeFin_symm_apply_succ, Fin.succAbove_zero, Equiv.coe_refl, pow_zero, mul_smul_comm, of_apply] -- `univ_perm_fin_succ` gives a different embedding of `Perm (Fin n)` into -- `Perm (Fin n.succ)` than the determinant of the submatrix we want, -- permute `A` so that we get the correct one. [GOAL] case refine'_2 m : Type u_1 n✝ : Type u_2 inst✝⁴ : DecidableEq n✝ inst✝³ : Fintype n✝ inst✝² : DecidableEq m inst✝¹ : Fintype m R : Type v inst✝ : CommRing R n : ℕ A : Matrix (Fin (Nat.succ n)) (Fin (Nat.succ n)) R i✝ : Fin (Nat.succ n) x✝ : i✝ ∈ univ i : Fin n ⊢ ∑ y : Perm (Fin n), ↑sign (↑decomposeFin.symm (Fin.succ i, y)) • ∏ x : Fin (Nat.succ n), A (↑(↑decomposeFin.symm (Fin.succ i, y)) x) x = (-1) ^ ↑(Fin.succ i) * A (Fin.succ i) 0 * det (↑of fun i_1 j => A (Fin.succAbove (Fin.succ i) i_1) (Fin.succ j)) [PROOFSTEP] have : (-1 : R) ^ (i : ℕ) = (Perm.sign i.cycleRange) := by simp [Fin.sign_cycleRange] [GOAL] m : Type u_1 n✝ : Type u_2 inst✝⁴ : DecidableEq n✝ inst✝³ : Fintype n✝ inst✝² : DecidableEq m inst✝¹ : Fintype m R : Type v inst✝ : CommRing R n : ℕ A : Matrix (Fin (Nat.succ n)) (Fin (Nat.succ n)) R i✝ : Fin (Nat.succ n) x✝ : i✝ ∈ univ i : Fin n ⊢ (-1) ^ ↑i = ↑↑(↑sign (Fin.cycleRange i)) [PROOFSTEP] simp [Fin.sign_cycleRange] [GOAL] case refine'_2 m : Type u_1 n✝ : Type u_2 inst✝⁴ : DecidableEq n✝ inst✝³ : Fintype n✝ inst✝² : DecidableEq m inst✝¹ : Fintype m R : Type v inst✝ : CommRing R n : ℕ A : Matrix (Fin (Nat.succ n)) (Fin (Nat.succ n)) R i✝ : Fin (Nat.succ n) x✝ : i✝ ∈ univ i : Fin n this : (-1) ^ ↑i = ↑↑(↑sign (Fin.cycleRange i)) ⊢ ∑ y : Perm (Fin n), ↑sign (↑decomposeFin.symm (Fin.succ i, y)) • ∏ x : Fin (Nat.succ n), A (↑(↑decomposeFin.symm (Fin.succ i, y)) x) x = (-1) ^ ↑(Fin.succ i) * A (Fin.succ i) 0 * det (↑of fun i_1 j => A (Fin.succAbove (Fin.succ i) i_1) (Fin.succ j)) [PROOFSTEP] rw [Fin.val_succ, pow_succ, this, mul_assoc, mul_assoc, mul_left_comm (ε _), ← det_permute, Matrix.det_apply, Finset.mul_sum, Finset.mul_sum] -- now we just need to move the corresponding parts to the same place [GOAL] case refine'_2 m : Type u_1 n✝ : Type u_2 inst✝⁴ : DecidableEq n✝ inst✝³ : Fintype n✝ inst✝² : DecidableEq m inst✝¹ : Fintype m R : Type v inst✝ : CommRing R n : ℕ A : Matrix (Fin (Nat.succ n)) (Fin (Nat.succ n)) R i✝ : Fin (Nat.succ n) x✝ : i✝ ∈ univ i : Fin n this : (-1) ^ ↑i = ↑↑(↑sign (Fin.cycleRange i)) ⊢ ∑ y : Perm (Fin n), ↑sign (↑decomposeFin.symm (Fin.succ i, y)) • ∏ x : Fin (Nat.succ n), A (↑(↑decomposeFin.symm (Fin.succ i, y)) x) x = ∑ x : Perm (Fin n), -1 * (A (Fin.succ i) 0 * ↑sign x • ∏ i_1 : Fin n, ↑of (fun i_2 j => A (Fin.succAbove (Fin.succ i) i_2) (Fin.succ j)) (↑(Fin.cycleRange i) (↑x i_1)) i_1) [PROOFSTEP] refine' Finset.sum_congr rfl fun σ _ => _ [GOAL] case refine'_2 m : Type u_1 n✝ : Type u_2 inst✝⁴ : DecidableEq n✝ inst✝³ : Fintype n✝ inst✝² : DecidableEq m inst✝¹ : Fintype m R : Type v inst✝ : CommRing R n : ℕ A : Matrix (Fin (Nat.succ n)) (Fin (Nat.succ n)) R i✝ : Fin (Nat.succ n) x✝¹ : i✝ ∈ univ i : Fin n this : (-1) ^ ↑i = ↑↑(↑sign (Fin.cycleRange i)) σ : Perm (Fin n) x✝ : σ ∈ univ ⊢ ↑sign (↑decomposeFin.symm (Fin.succ i, σ)) • ∏ x : Fin (Nat.succ n), A (↑(↑decomposeFin.symm (Fin.succ i, σ)) x) x = -1 * (A (Fin.succ i) 0 * ↑sign σ • ∏ i_1 : Fin n, ↑of (fun i_2 j => A (Fin.succAbove (Fin.succ i) i_2) (Fin.succ j)) (↑(Fin.cycleRange i) (↑σ i_1)) i_1) [PROOFSTEP] rw [Equiv.Perm.decomposeFin.symm_sign, if_neg (Fin.succ_ne_zero i)] [GOAL] case refine'_2 m : Type u_1 n✝ : Type u_2 inst✝⁴ : DecidableEq n✝ inst✝³ : Fintype n✝ inst✝² : DecidableEq m inst✝¹ : Fintype m R : Type v inst✝ : CommRing R n : ℕ A : Matrix (Fin (Nat.succ n)) (Fin (Nat.succ n)) R i✝ : Fin (Nat.succ n) x✝¹ : i✝ ∈ univ i : Fin n this : (-1) ^ ↑i = ↑↑(↑sign (Fin.cycleRange i)) σ : Perm (Fin n) x✝ : σ ∈ univ ⊢ (-1 * ↑sign σ) • ∏ x : Fin (Nat.succ n), A (↑(↑decomposeFin.symm (Fin.succ i, σ)) x) x = -1 * (A (Fin.succ i) 0 * ↑sign σ • ∏ i_1 : Fin n, ↑of (fun i_2 j => A (Fin.succAbove (Fin.succ i) i_2) (Fin.succ j)) (↑(Fin.cycleRange i) (↑σ i_1)) i_1) [PROOFSTEP] calc ((-1 * Perm.sign σ : ℤ) • ∏ i', A (Perm.decomposeFin.symm (Fin.succ i, σ) i') i') = (-1 * Perm.sign σ : ℤ) • (A (Fin.succ i) 0 * ∏ i', A ((Fin.succ i).succAbove (Fin.cycleRange i (σ i'))) i'.succ) := by simp only [Fin.prod_univ_succ, Fin.succAbove_cycleRange, Equiv.Perm.decomposeFin_symm_apply_zero, Equiv.Perm.decomposeFin_symm_apply_succ] _ = -1 * (A (Fin.succ i) 0 * (Perm.sign σ : ℤ) • ∏ i', A ((Fin.succ i).succAbove (Fin.cycleRange i (σ i'))) i'.succ) := by simp [mul_assoc, mul_comm, _root_.neg_mul, one_mul, zsmul_eq_mul, neg_inj, neg_smul, Fin.succAbove_cycleRange, mul_left_comm] [GOAL] m : Type u_1 n✝ : Type u_2 inst✝⁴ : DecidableEq n✝ inst✝³ : Fintype n✝ inst✝² : DecidableEq m inst✝¹ : Fintype m R : Type v inst✝ : CommRing R n : ℕ A : Matrix (Fin (Nat.succ n)) (Fin (Nat.succ n)) R i✝ : Fin (Nat.succ n) x✝¹ : i✝ ∈ univ i : Fin n this : (-1) ^ ↑i = ↑↑(↑sign (Fin.cycleRange i)) σ : Perm (Fin n) x✝ : σ ∈ univ ⊢ (-1 * ↑(↑sign σ)) • ∏ i' : Fin (Nat.succ n), A (↑(↑decomposeFin.symm (Fin.succ i, σ)) i') i' = (-1 * ↑(↑sign σ)) • (A (Fin.succ i) 0 * ∏ i' : Fin n, A (Fin.succAbove (Fin.succ i) (↑(Fin.cycleRange i) (↑σ i'))) (Fin.succ i')) [PROOFSTEP] simp only [Fin.prod_univ_succ, Fin.succAbove_cycleRange, Equiv.Perm.decomposeFin_symm_apply_zero, Equiv.Perm.decomposeFin_symm_apply_succ] [GOAL] m : Type u_1 n✝ : Type u_2 inst✝⁴ : DecidableEq n✝ inst✝³ : Fintype n✝ inst✝² : DecidableEq m inst✝¹ : Fintype m R : Type v inst✝ : CommRing R n : ℕ A : Matrix (Fin (Nat.succ n)) (Fin (Nat.succ n)) R i✝ : Fin (Nat.succ n) x✝¹ : i✝ ∈ univ i : Fin n this : (-1) ^ ↑i = ↑↑(↑sign (Fin.cycleRange i)) σ : Perm (Fin n) x✝ : σ ∈ univ ⊢ (-1 * ↑(↑sign σ)) • (A (Fin.succ i) 0 * ∏ i' : Fin n, A (Fin.succAbove (Fin.succ i) (↑(Fin.cycleRange i) (↑σ i'))) (Fin.succ i')) = -1 * (A (Fin.succ i) 0 * ↑(↑sign σ) • ∏ i' : Fin n, A (Fin.succAbove (Fin.succ i) (↑(Fin.cycleRange i) (↑σ i'))) (Fin.succ i')) [PROOFSTEP] simp [mul_assoc, mul_comm, _root_.neg_mul, one_mul, zsmul_eq_mul, neg_inj, neg_smul, Fin.succAbove_cycleRange, mul_left_comm] [GOAL] m : Type u_1 n✝ : Type u_2 inst✝⁴ : DecidableEq n✝ inst✝³ : Fintype n✝ inst✝² : DecidableEq m inst✝¹ : Fintype m R : Type v inst✝ : CommRing R n : ℕ A : Matrix (Fin (Nat.succ n)) (Fin (Nat.succ n)) R ⊢ det A = ∑ j : Fin (Nat.succ n), (-1) ^ ↑j * A 0 j * det (submatrix A Fin.succ (Fin.succAbove j)) [PROOFSTEP] rw [← det_transpose A, det_succ_column_zero] [GOAL] m : Type u_1 n✝ : Type u_2 inst✝⁴ : DecidableEq n✝ inst✝³ : Fintype n✝ inst✝² : DecidableEq m inst✝¹ : Fintype m R : Type v inst✝ : CommRing R n : ℕ A : Matrix (Fin (Nat.succ n)) (Fin (Nat.succ n)) R ⊢ ∑ i : Fin (Nat.succ n), (-1) ^ ↑i * Aᵀ i 0 * det (submatrix Aᵀ (Fin.succAbove i) Fin.succ) = ∑ j : Fin (Nat.succ n), (-1) ^ ↑j * A 0 j * det (submatrix A Fin.succ (Fin.succAbove j)) [PROOFSTEP] refine' Finset.sum_congr rfl fun i _ => _ [GOAL] m : Type u_1 n✝ : Type u_2 inst✝⁴ : DecidableEq n✝ inst✝³ : Fintype n✝ inst✝² : DecidableEq m inst✝¹ : Fintype m R : Type v inst✝ : CommRing R n : ℕ A : Matrix (Fin (Nat.succ n)) (Fin (Nat.succ n)) R i : Fin (Nat.succ n) x✝ : i ∈ univ ⊢ (-1) ^ ↑i * Aᵀ i 0 * det (submatrix Aᵀ (Fin.succAbove i) Fin.succ) = (-1) ^ ↑i * A 0 i * det (submatrix A Fin.succ (Fin.succAbove i)) [PROOFSTEP] rw [← det_transpose] [GOAL] m : Type u_1 n✝ : Type u_2 inst✝⁴ : DecidableEq n✝ inst✝³ : Fintype n✝ inst✝² : DecidableEq m inst✝¹ : Fintype m R : Type v inst✝ : CommRing R n : ℕ A : Matrix (Fin (Nat.succ n)) (Fin (Nat.succ n)) R i : Fin (Nat.succ n) x✝ : i ∈ univ ⊢ (-1) ^ ↑i * Aᵀ i 0 * det (submatrix Aᵀ (Fin.succAbove i) Fin.succ)ᵀ = (-1) ^ ↑i * A 0 i * det (submatrix A Fin.succ (Fin.succAbove i)) [PROOFSTEP] simp only [transpose_apply, transpose_submatrix, transpose_transpose] [GOAL] m : Type u_1 n✝ : Type u_2 inst✝⁴ : DecidableEq n✝ inst✝³ : Fintype n✝ inst✝² : DecidableEq m inst✝¹ : Fintype m R : Type v inst✝ : CommRing R n : ℕ A : Matrix (Fin (Nat.succ n)) (Fin (Nat.succ n)) R i : Fin (Nat.succ n) ⊢ det A = ∑ j : Fin (Nat.succ n), (-1) ^ (↑i + ↑j) * A i j * det (submatrix A (Fin.succAbove i) (Fin.succAbove j)) [PROOFSTEP] simp_rw [pow_add, mul_assoc, ← mul_sum] [GOAL] m : Type u_1 n✝ : Type u_2 inst✝⁴ : DecidableEq n✝ inst✝³ : Fintype n✝ inst✝² : DecidableEq m inst✝¹ : Fintype m R : Type v inst✝ : CommRing R n : ℕ A : Matrix (Fin (Nat.succ n)) (Fin (Nat.succ n)) R i : Fin (Nat.succ n) ⊢ det A = (-1) ^ ↑i * ∑ x : Fin (Nat.succ n), (-1) ^ ↑x * (A i x * det (submatrix A (Fin.succAbove i) (Fin.succAbove x))) [PROOFSTEP] have : det A = (-1 : R) ^ (i : ℕ) * (Perm.sign i.cycleRange⁻¹) * det A := by calc det A = ↑((-1 : ℤˣ) ^ (i : ℕ) * (-1 : ℤˣ) ^ (i : ℕ) : ℤˣ) * det A := by simp _ = (-1 : R) ^ (i : ℕ) * (Perm.sign i.cycleRange⁻¹) * det A := by simp [-Int.units_mul_self] [GOAL] m : Type u_1 n✝ : Type u_2 inst✝⁴ : DecidableEq n✝ inst✝³ : Fintype n✝ inst✝² : DecidableEq m inst✝¹ : Fintype m R : Type v inst✝ : CommRing R n : ℕ A : Matrix (Fin (Nat.succ n)) (Fin (Nat.succ n)) R i : Fin (Nat.succ n) ⊢ det A = (-1) ^ ↑i * ↑↑(↑sign (Fin.cycleRange i)⁻¹) * det A [PROOFSTEP] calc det A = ↑((-1 : ℤˣ) ^ (i : ℕ) * (-1 : ℤˣ) ^ (i : ℕ) : ℤˣ) * det A := by simp _ = (-1 : R) ^ (i : ℕ) * (Perm.sign i.cycleRange⁻¹) * det A := by simp [-Int.units_mul_self] [GOAL] m : Type u_1 n✝ : Type u_2 inst✝⁴ : DecidableEq n✝ inst✝³ : Fintype n✝ inst✝² : DecidableEq m inst✝¹ : Fintype m R : Type v inst✝ : CommRing R n : ℕ A : Matrix (Fin (Nat.succ n)) (Fin (Nat.succ n)) R i : Fin (Nat.succ n) ⊢ det A = ↑↑((-1) ^ ↑i * (-1) ^ ↑i) * det A [PROOFSTEP] simp [GOAL] m : Type u_1 n✝ : Type u_2 inst✝⁴ : DecidableEq n✝ inst✝³ : Fintype n✝ inst✝² : DecidableEq m inst✝¹ : Fintype m R : Type v inst✝ : CommRing R n : ℕ A : Matrix (Fin (Nat.succ n)) (Fin (Nat.succ n)) R i : Fin (Nat.succ n) ⊢ ↑↑((-1) ^ ↑i * (-1) ^ ↑i) * det A = (-1) ^ ↑i * ↑↑(↑sign (Fin.cycleRange i)⁻¹) * det A [PROOFSTEP] simp [-Int.units_mul_self] [GOAL] m : Type u_1 n✝ : Type u_2 inst✝⁴ : DecidableEq n✝ inst✝³ : Fintype n✝ inst✝² : DecidableEq m inst✝¹ : Fintype m R : Type v inst✝ : CommRing R n : ℕ A : Matrix (Fin (Nat.succ n)) (Fin (Nat.succ n)) R i : Fin (Nat.succ n) this : det A = (-1) ^ ↑i * ↑↑(↑sign (Fin.cycleRange i)⁻¹) * det A ⊢ det A = (-1) ^ ↑i * ∑ x : Fin (Nat.succ n), (-1) ^ ↑x * (A i x * det (submatrix A (Fin.succAbove i) (Fin.succAbove x))) [PROOFSTEP] rw [this, mul_assoc] [GOAL] m : Type u_1 n✝ : Type u_2 inst✝⁴ : DecidableEq n✝ inst✝³ : Fintype n✝ inst✝² : DecidableEq m inst✝¹ : Fintype m R : Type v inst✝ : CommRing R n : ℕ A : Matrix (Fin (Nat.succ n)) (Fin (Nat.succ n)) R i : Fin (Nat.succ n) this : det A = (-1) ^ ↑i * ↑↑(↑sign (Fin.cycleRange i)⁻¹) * det A ⊢ (-1) ^ ↑i * (↑↑(↑sign (Fin.cycleRange i)⁻¹) * det A) = (-1) ^ ↑i * ∑ x : Fin (Nat.succ n), (-1) ^ ↑x * (A i x * det (submatrix A (Fin.succAbove i) (Fin.succAbove x))) [PROOFSTEP] congr [GOAL] case e_a m : Type u_1 n✝ : Type u_2 inst✝⁴ : DecidableEq n✝ inst✝³ : Fintype n✝ inst✝² : DecidableEq m inst✝¹ : Fintype m R : Type v inst✝ : CommRing R n : ℕ A : Matrix (Fin (Nat.succ n)) (Fin (Nat.succ n)) R i : Fin (Nat.succ n) this : det A = (-1) ^ ↑i * ↑↑(↑sign (Fin.cycleRange i)⁻¹) * det A ⊢ ↑↑(↑sign (Fin.cycleRange i)⁻¹) * det A = ∑ x : Fin (Nat.succ n), (-1) ^ ↑x * (A i x * det (submatrix A (Fin.succAbove i) (Fin.succAbove x))) [PROOFSTEP] rw [← det_permute, det_succ_row_zero] [GOAL] case e_a m : Type u_1 n✝ : Type u_2 inst✝⁴ : DecidableEq n✝ inst✝³ : Fintype n✝ inst✝² : DecidableEq m inst✝¹ : Fintype m R : Type v inst✝ : CommRing R n : ℕ A : Matrix (Fin (Nat.succ n)) (Fin (Nat.succ n)) R i : Fin (Nat.succ n) this : det A = (-1) ^ ↑i * ↑↑(↑sign (Fin.cycleRange i)⁻¹) * det A ⊢ ∑ j : Fin (Nat.succ n), (-1) ^ ↑j * A (↑(Fin.cycleRange i)⁻¹ 0) j * det (submatrix (fun i_1 => A (↑(Fin.cycleRange i)⁻¹ i_1)) Fin.succ (Fin.succAbove j)) = ∑ x : Fin (Nat.succ n), (-1) ^ ↑x * (A i x * det (submatrix A (Fin.succAbove i) (Fin.succAbove x))) [PROOFSTEP] refine' Finset.sum_congr rfl fun j _ => _ [GOAL] case e_a m : Type u_1 n✝ : Type u_2 inst✝⁴ : DecidableEq n✝ inst✝³ : Fintype n✝ inst✝² : DecidableEq m inst✝¹ : Fintype m R : Type v inst✝ : CommRing R n : ℕ A : Matrix (Fin (Nat.succ n)) (Fin (Nat.succ n)) R i : Fin (Nat.succ n) this : det A = (-1) ^ ↑i * ↑↑(↑sign (Fin.cycleRange i)⁻¹) * det A j : Fin (Nat.succ n) x✝ : j ∈ univ ⊢ (-1) ^ ↑j * A (↑(Fin.cycleRange i)⁻¹ 0) j * det (submatrix (fun i_1 => A (↑(Fin.cycleRange i)⁻¹ i_1)) Fin.succ (Fin.succAbove j)) = (-1) ^ ↑j * (A i j * det (submatrix A (Fin.succAbove i) (Fin.succAbove j))) [PROOFSTEP] rw [mul_assoc, Matrix.submatrix, Matrix.submatrix] [GOAL] case e_a m : Type u_1 n✝ : Type u_2 inst✝⁴ : DecidableEq n✝ inst✝³ : Fintype n✝ inst✝² : DecidableEq m inst✝¹ : Fintype m R : Type v inst✝ : CommRing R n : ℕ A : Matrix (Fin (Nat.succ n)) (Fin (Nat.succ n)) R i : Fin (Nat.succ n) this : det A = (-1) ^ ↑i * ↑↑(↑sign (Fin.cycleRange i)⁻¹) * det A j : Fin (Nat.succ n) x✝ : j ∈ univ ⊢ (-1) ^ ↑j * (A (↑(Fin.cycleRange i)⁻¹ 0) j * det (↑of fun i_1 j_1 => A (↑(Fin.cycleRange i)⁻¹ (Fin.succ i_1)) (Fin.succAbove j j_1))) = (-1) ^ ↑j * (A i j * det (↑of fun i_1 j_1 => A (Fin.succAbove i i_1) (Fin.succAbove j j_1))) [PROOFSTEP] congr [GOAL] case e_a.e_a.e_a.e_a m : Type u_1 n✝ : Type u_2 inst✝⁴ : DecidableEq n✝ inst✝³ : Fintype n✝ inst✝² : DecidableEq m inst✝¹ : Fintype m R : Type v inst✝ : CommRing R n : ℕ A : Matrix (Fin (Nat.succ n)) (Fin (Nat.succ n)) R i : Fin (Nat.succ n) this : det A = (-1) ^ ↑i * ↑↑(↑sign (Fin.cycleRange i)⁻¹) * det A j : Fin (Nat.succ n) x✝ : j ∈ univ ⊢ ↑(Fin.cycleRange i)⁻¹ 0 = i [PROOFSTEP] rw [Equiv.Perm.inv_def, Fin.cycleRange_symm_zero] [GOAL] case e_a.e_a.e_a.e_M.h.e_6.h m : Type u_1 n✝ : Type u_2 inst✝⁴ : DecidableEq n✝ inst✝³ : Fintype n✝ inst✝² : DecidableEq m inst✝¹ : Fintype m R : Type v inst✝ : CommRing R n : ℕ A : Matrix (Fin (Nat.succ n)) (Fin (Nat.succ n)) R i : Fin (Nat.succ n) this : det A = (-1) ^ ↑i * ↑↑(↑sign (Fin.cycleRange i)⁻¹) * det A j : Fin (Nat.succ n) x✝ : j ∈ univ ⊢ (fun i_1 j_1 => A (↑(Fin.cycleRange i)⁻¹ (Fin.succ i_1)) (Fin.succAbove j j_1)) = fun i_1 j_1 => A (Fin.succAbove i i_1) (Fin.succAbove j j_1) [PROOFSTEP] ext i' j' [GOAL] case e_a.e_a.e_a.e_M.h.e_6.h.h.h m : Type u_1 n✝ : Type u_2 inst✝⁴ : DecidableEq n✝ inst✝³ : Fintype n✝ inst✝² : DecidableEq m inst✝¹ : Fintype m R : Type v inst✝ : CommRing R n : ℕ A : Matrix (Fin (Nat.succ n)) (Fin (Nat.succ n)) R i : Fin (Nat.succ n) this : det A = (-1) ^ ↑i * ↑↑(↑sign (Fin.cycleRange i)⁻¹) * det A j : Fin (Nat.succ n) x✝ : j ∈ univ i' j' : Fin n ⊢ A (↑(Fin.cycleRange i)⁻¹ (Fin.succ i')) (Fin.succAbove j j') = A (Fin.succAbove i i') (Fin.succAbove j j') [PROOFSTEP] rw [Equiv.Perm.inv_def, Fin.cycleRange_symm_succ] [GOAL] m : Type u_1 n✝ : Type u_2 inst✝⁴ : DecidableEq n✝ inst✝³ : Fintype n✝ inst✝² : DecidableEq m inst✝¹ : Fintype m R : Type v inst✝ : CommRing R n : ℕ A : Matrix (Fin (Nat.succ n)) (Fin (Nat.succ n)) R j : Fin (Nat.succ n) ⊢ det A = ∑ i : Fin (Nat.succ n), (-1) ^ (↑i + ↑j) * A i j * det (submatrix A (Fin.succAbove i) (Fin.succAbove j)) [PROOFSTEP] rw [← det_transpose, det_succ_row _ j] [GOAL] m : Type u_1 n✝ : Type u_2 inst✝⁴ : DecidableEq n✝ inst✝³ : Fintype n✝ inst✝² : DecidableEq m inst✝¹ : Fintype m R : Type v inst✝ : CommRing R n : ℕ A : Matrix (Fin (Nat.succ n)) (Fin (Nat.succ n)) R j : Fin (Nat.succ n) ⊢ ∑ j_1 : Fin (Nat.succ n), (-1) ^ (↑j + ↑j_1) * Aᵀ j j_1 * det (submatrix Aᵀ (Fin.succAbove j) (Fin.succAbove j_1)) = ∑ i : Fin (Nat.succ n), (-1) ^ (↑i + ↑j) * A i j * det (submatrix A (Fin.succAbove i) (Fin.succAbove j)) [PROOFSTEP] refine' Finset.sum_congr rfl fun i _ => _ [GOAL] m : Type u_1 n✝ : Type u_2 inst✝⁴ : DecidableEq n✝ inst✝³ : Fintype n✝ inst✝² : DecidableEq m inst✝¹ : Fintype m R : Type v inst✝ : CommRing R n : ℕ A : Matrix (Fin (Nat.succ n)) (Fin (Nat.succ n)) R j i : Fin (Nat.succ n) x✝ : i ∈ univ ⊢ (-1) ^ (↑j + ↑i) * Aᵀ j i * det (submatrix Aᵀ (Fin.succAbove j) (Fin.succAbove i)) = (-1) ^ (↑i + ↑j) * A i j * det (submatrix A (Fin.succAbove i) (Fin.succAbove j)) [PROOFSTEP] rw [add_comm, ← det_transpose, transpose_apply, transpose_submatrix, transpose_transpose] [GOAL] m : Type u_1 n : Type u_2 inst✝⁴ : DecidableEq n inst✝³ : Fintype n inst✝² : DecidableEq m inst✝¹ : Fintype m R : Type v inst✝ : CommRing R A : Matrix (Fin 2) (Fin 2) R ⊢ det A = A 0 0 * A 1 1 - A 0 1 * A 1 0 [PROOFSTEP] simp [Matrix.det_succ_row_zero, Fin.sum_univ_succ] [GOAL] m : Type u_1 n : Type u_2 inst✝⁴ : DecidableEq n inst✝³ : Fintype n inst✝² : DecidableEq m inst✝¹ : Fintype m R : Type v inst✝ : CommRing R A : Matrix (Fin 2) (Fin 2) R ⊢ A 0 0 * A 1 1 + -(A 0 1 * A 1 0) = A 0 0 * A 1 1 - A 0 1 * A 1 0 [PROOFSTEP] ring [GOAL] m : Type u_1 n : Type u_2 inst✝⁴ : DecidableEq n inst✝³ : Fintype n inst✝² : DecidableEq m inst✝¹ : Fintype m R : Type v inst✝ : CommRing R A : Matrix (Fin 3) (Fin 3) R ⊢ det A = A 0 0 * A 1 1 * A 2 2 - A 0 0 * A 1 2 * A 2 1 - A 0 1 * A 1 0 * A 2 2 + A 0 1 * A 1 2 * A 2 0 + A 0 2 * A 1 0 * A 2 1 - A 0 2 * A 1 1 * A 2 0 [PROOFSTEP] simp [Matrix.det_succ_row_zero, Fin.sum_univ_succ] [GOAL] m : Type u_1 n : Type u_2 inst✝⁴ : DecidableEq n inst✝³ : Fintype n inst✝² : DecidableEq m inst✝¹ : Fintype m R : Type v inst✝ : CommRing R A : Matrix (Fin 3) (Fin 3) R ⊢ A 0 0 * (A 1 1 * A 2 2 + -(A 1 2 * A 2 1)) + (-(A 0 1 * (A 1 0 * A 2 2 + -(A 1 2 * A 2 0))) + A 0 2 * (A 1 0 * A 2 1 + -(A 1 1 * A 2 0))) = A 0 0 * A 1 1 * A 2 2 - A 0 0 * A 1 2 * A 2 1 - A 0 1 * A 1 0 * A 2 2 + A 0 1 * A 1 2 * A 2 0 + A 0 2 * A 1 0 * A 2 1 - A 0 2 * A 1 1 * A 2 0 [PROOFSTEP] ring
[STATEMENT] lemma openin_diff[intro]: assumes oS: "openin U S" and cT: "closedin U T" shows "openin U (S - T)" [PROOF STATE] proof (prove) goal (1 subgoal): 1. openin U (S - T) [PROOF STEP] proof - [PROOF STATE] proof (state) goal (1 subgoal): 1. openin U (S - T) [PROOF STEP] have "S - T = S \<inter> (topspace U - T)" [PROOF STATE] proof (prove) goal (1 subgoal): 1. S - T = S \<inter> (topspace U - T) [PROOF STEP] using openin_subset[of U S] oS cT [PROOF STATE] proof (prove) using this: openin U S \<Longrightarrow> S \<subseteq> topspace U openin U S closedin U T goal (1 subgoal): 1. S - T = S \<inter> (topspace U - T) [PROOF STEP] by (auto simp: topspace_def openin_subset) [PROOF STATE] proof (state) this: S - T = S \<inter> (topspace U - T) goal (1 subgoal): 1. openin U (S - T) [PROOF STEP] then [PROOF STATE] proof (chain) picking this: S - T = S \<inter> (topspace U - T) [PROOF STEP] show ?thesis [PROOF STATE] proof (prove) using this: S - T = S \<inter> (topspace U - T) goal (1 subgoal): 1. openin U (S - T) [PROOF STEP] using oS cT [PROOF STATE] proof (prove) using this: S - T = S \<inter> (topspace U - T) openin U S closedin U T goal (1 subgoal): 1. openin U (S - T) [PROOF STEP] by (auto simp: closedin_def) [PROOF STATE] proof (state) this: openin U (S - T) goal: No subgoals! [PROOF STEP] qed
function [ d ] = edist( x , y ) %edist euclidean distance between two vectors d = sqrt( sum( (x-y).^2,2 ) );
Jade Plant makes a fine choice for the outdoor landscape, but it is also well-suited for use in outdoor pots and containers. With its upright habit of growth, it is best suited for use as a 'thriller' in the 'spiller-thriller-filler' container combination; plant it near the center of the pot, surrounded by smaller plants and those that spill over the edges. Note that when grown in a container, it may not perform exactly as indicated on the tag - this is to be expected. Also note that when growing plants in outdoor containers and baskets, they may require more frequent waterings than they would in the yard or garden. Be aware that in our climate, this plant may be too tender to survive the winter if left outdoors in a container. Contact our store for more information on how to protect it over the winter months.
Formal statement is: lemma connected_Un_clopen_in_complement: fixes S U :: "'a::metric_space set" assumes "connected S" "connected U" "S \<subseteq> U" and opeT: "openin (top_of_set (U - S)) T" and cloT: "closedin (top_of_set (U - S)) T" shows "connected (S \<union> T)" Informal statement is: If $S$ and $U$ are connected sets with $S \subseteq U$, and $T$ is a clopen subset of $U - S$, then $S \cup T$ is connected.
lemma sets_vimage_algebra2: "f \<in> X \<rightarrow> space M \<Longrightarrow> sets (vimage_algebra X f M) = {f -` A \<inter> X | A. A \<in> sets M}"
/- Presheaf of rings extension. https://stacks.math.columbia.edu/tag/009N -/ import to_mathlib.opens import sheaves.covering.covering import sheaves.presheaf_of_rings import sheaves.presheaf_of_rings_on_basis import sheaves.stalk_of_rings_on_standard_basis universes u v w open topological_space open lattice open covering open stalk_of_rings_on_standard_basis. section presheaf_of_rings_extension variables {α : Type u} [topological_space α] variables {B : set (opens α)} {HB : opens.is_basis B} variables (Bstd : opens.univ ∈ B ∧ ∀ {U V}, U ∈ B → V ∈ B → U ∩ V ∈ B) variables (F : presheaf_of_rings_on_basis α HB) (U : opens α) include Bstd section presheaf_of_rings_on_basis_extension_is_ring @[reducible] def Fext := { s : Π (x ∈ U), stalk_of_rings_on_standard_basis Bstd F x // ∀ (x ∈ U), ∃ (V) (BV : V ∈ B) (Hx : x ∈ V) (σ : F.to_presheaf_on_basis BV), ∀ (y ∈ U ∩ V), s y = λ _, ⟦{U := V, BU := BV, Hx := H.2, s := σ}⟧ } -- Add. private def Fext_add_aux (x : α) : stalk_of_rings_on_standard_basis Bstd F x → stalk_of_rings_on_standard_basis Bstd F x → stalk_of_rings_on_standard_basis Bstd F x := (stalk_of_rings_on_standard_basis.has_add Bstd F x).add private def Fext_add : Fext Bstd F U → Fext Bstd F U → Fext Bstd F U := λ ⟨s₁, Hs₁⟩ ⟨s₂, Hs₂⟩, ⟨λ x Hx, (Fext_add_aux Bstd F x) (s₁ x Hx) (s₂ x Hx), begin intros x Hx, replace Hs₁ := Hs₁ x Hx, replace Hs₂ := Hs₂ x Hx, rcases Hs₁ with ⟨V₁, BV₁, HxV₁, σ₁, Hs₁⟩, rcases Hs₂ with ⟨V₂, BV₂, HxV₂, σ₂, Hs₂⟩, use [V₁ ∩ V₂, Bstd.2 BV₁ BV₂, ⟨HxV₁, HxV₂⟩], let σ₁' := F.res BV₁ (Bstd.2 BV₁ BV₂) (set.inter_subset_left _ _) σ₁, let σ₂' := F.res BV₂ (Bstd.2 BV₁ BV₂) (set.inter_subset_right _ _) σ₂, use [σ₁' + σ₂'], rintros y ⟨HyU, ⟨HyV₁, HyV₂⟩⟩, apply funext, intros Hy, replace Hs₁ := Hs₁ y ⟨HyU, HyV₁⟩, replace Hs₂ := Hs₂ y ⟨HyU, HyV₂⟩, rw Hs₁, rw Hs₂, refl, end⟩ instance Fext_has_add : has_add (Fext Bstd F U) := { add := Fext_add Bstd F U } @[simp] lemma Fext_add.eq (x : α) (Hx : x ∈ U) : ∀ (a b : Fext Bstd F U), (a + b).val x Hx = (a.val x Hx) + (b.val x Hx) := λ ⟨s₁, Hs₁⟩ ⟨s₂, Hs₂⟩, rfl instance Fext_add_semigroup : add_semigroup (Fext Bstd F U) := { add_assoc := λ a b c, subtype.eq $ funext $ λ x, funext $ λ HxU, by simp, ..Fext_has_add Bstd F U } instance Fext_add_comm_semigroup : add_comm_semigroup (Fext Bstd F U) := { add_comm := λ a b, subtype.eq $ funext $ λ x, funext $ λ HxU, by simp, ..Fext_add_semigroup Bstd F U } -- Zero. private def Fext_zero : Fext Bstd F U := ⟨λ x Hx, (stalk_of_rings_on_standard_basis.has_zero Bstd F x).zero, λ x Hx, ⟨opens.univ, Bstd.1, trivial, 0, (λ y Hy, funext $ λ HyU, rfl)⟩⟩ instance Fext_has_zero : has_zero (Fext Bstd F U) := { zero := Fext_zero Bstd F U } @[simp] lemma Fext_zero.eq (x : α) (Hx : x ∈ U) : (0 : Fext Bstd F U).val x Hx = (stalk_of_rings_on_standard_basis.has_zero Bstd F x).zero := rfl instance Fext_add_comm_monoid : add_comm_monoid (Fext Bstd F U) := { zero_add := λ a, subtype.eq $ funext $ λ x, funext $ λ HxU, by simp, add_zero := λ a, subtype.eq $ funext $ λ x, funext $ λ HxU, by simp, ..Fext_has_zero Bstd F U, ..Fext_add_comm_semigroup Bstd F U, } -- Neg. private def Fext_neg_aux (x : α) : stalk_of_rings_on_standard_basis Bstd F x → stalk_of_rings_on_standard_basis Bstd F x := (stalk_of_rings_on_standard_basis.has_neg Bstd F x).neg private def Fext_neg : Fext Bstd F U → Fext Bstd F U := λ ⟨s, Hs⟩, ⟨λ x Hx, (Fext_neg_aux Bstd F x) (s x Hx), begin intros x Hx, replace Hs := Hs x Hx, rcases Hs with ⟨V, BV, HxV, σ, Hs⟩, use [V, BV, HxV, -σ], rintros y ⟨HyU, HyV⟩, apply funext, intros Hy, replace Hs := Hs y ⟨HyU, HyV⟩, rw Hs, refl, end⟩ instance Fext_has_neg : has_neg (Fext Bstd F U) := { neg := Fext_neg Bstd F U, } @[simp] lemma Fext_neg.eq (x : α) (Hx : x ∈ U) : ∀ (a : Fext Bstd F U), (-a).val x Hx = -(a.val x Hx) := λ ⟨s, Hs⟩, rfl instance Fext_add_comm_group : add_comm_group (Fext Bstd F U) := { add_left_neg := λ a, subtype.eq $ funext $ λ x, funext $ λ HxU, by simp, ..Fext_has_neg Bstd F U, ..Fext_add_comm_monoid Bstd F U, } -- Mul. private def Fext_mul_aux (x : α) : stalk_of_rings_on_standard_basis Bstd F x → stalk_of_rings_on_standard_basis Bstd F x → stalk_of_rings_on_standard_basis Bstd F x := (stalk_of_rings_on_standard_basis.has_mul Bstd F x).mul private def Fext_mul : Fext Bstd F U → Fext Bstd F U → Fext Bstd F U := λ ⟨s₁, Hs₁⟩ ⟨s₂, Hs₂⟩, ⟨λ x Hx, (Fext_mul_aux Bstd F x) (s₁ x Hx) (s₂ x Hx), begin intros x Hx, replace Hs₁ := Hs₁ x Hx, replace Hs₂ := Hs₂ x Hx, rcases Hs₁ with ⟨V₁, BV₁, HxV₁, σ₁, Hs₁⟩, rcases Hs₂ with ⟨V₂, BV₂, HxV₂, σ₂, Hs₂⟩, use [V₁ ∩ V₂, Bstd.2 BV₁ BV₂, ⟨HxV₁, HxV₂⟩], let σ₁' := F.res BV₁ (Bstd.2 BV₁ BV₂) (set.inter_subset_left _ _) σ₁, let σ₂' := F.res BV₂ (Bstd.2 BV₁ BV₂) (set.inter_subset_right _ _) σ₂, use [σ₁' * σ₂'], rintros y ⟨HyU, ⟨HyV₁, HyV₂⟩⟩, apply funext, intros Hy, replace Hs₁ := Hs₁ y ⟨HyU, HyV₁⟩, replace Hs₂ := Hs₂ y ⟨HyU, HyV₂⟩, rw Hs₁, rw Hs₂, refl, end⟩ instance Fext_has_mul : has_mul (Fext Bstd F U) := { mul := Fext_mul Bstd F U } @[simp] lemma Fext_mul.eq (x : α) (Hx : x ∈ U) : ∀ (a b : Fext Bstd F U), (a * b).val x Hx = (a.val x Hx) * (b.val x Hx) := λ ⟨s₁, Hs₁⟩ ⟨s₂, Hs₂⟩, rfl instance Fext_mul_semigroup : semigroup (Fext Bstd F U) := { mul_assoc := λ a b c, subtype.eq $ funext $ λ x, funext $ λ HxU, begin simp, apply (stalk_of_rings_on_standard_basis.mul_semigroup Bstd F x).mul_assoc, end, ..Fext_has_mul Bstd F U, } instance Fext_mul_comm_semigroup : comm_semigroup (Fext Bstd F U) := { mul_comm := λ a b, subtype.eq $ funext $ λ x, funext $ λ HxU, begin simp, apply (stalk_of_rings_on_standard_basis.mul_comm_semigroup Bstd F x).mul_comm, end, ..Fext_mul_semigroup Bstd F U, } -- One. private def Fext_one : Fext Bstd F U := ⟨λ x Hx, (stalk_of_rings_on_standard_basis.has_one Bstd F x).one, λ x Hx, ⟨opens.univ, Bstd.1, trivial, 1, (λ y Hy, funext $ λ HyU, rfl)⟩⟩ instance Fext_has_one : has_one (Fext Bstd F U) := { one := Fext_one Bstd F U } instance Fext_mul_comm_monoid : comm_monoid (Fext Bstd F U) := { one_mul := λ a, subtype.eq $ funext $ λ x, funext $ λ HxU, begin simp, apply (stalk_of_rings_on_standard_basis.mul_comm_monoid Bstd F x).one_mul, end, mul_one := λ a, subtype.eq $ funext $ λ x, funext $ λ HxU, begin simp, apply (stalk_of_rings_on_standard_basis.mul_comm_monoid Bstd F x).mul_one, end, ..Fext_has_one Bstd F U, ..Fext_mul_comm_semigroup Bstd F U, } -- Ring instance Fext_comm_ring : comm_ring (Fext Bstd F U) := { left_distrib := λ a b c, subtype.eq $ funext $ λ x, funext $ λ HxU, begin rw Fext_add.eq, repeat { rw Fext_mul.eq, }, rw Fext_add.eq, eapply (stalk_of_rings_on_standard_basis.comm_ring Bstd F x).left_distrib, end, right_distrib := λ a b c, subtype.eq $ funext $ λ x, funext $ λ HxU, begin rw Fext_add.eq, repeat { rw Fext_mul.eq, }, rw Fext_add.eq, eapply (stalk_of_rings_on_standard_basis.comm_ring Bstd F x).right_distrib, end, ..Fext_add_comm_group Bstd F U, ..Fext_mul_comm_monoid Bstd F U, } end presheaf_of_rings_on_basis_extension_is_ring -- F defined in the whole space to F defined on the basis. def presheaf_of_rings_to_presheaf_of_rings_on_basis (F : presheaf_of_rings α) : presheaf_of_rings_on_basis α HB := { F := λ U BU, F U, res := λ U V BU BV HVU, F.res U V HVU, Hid := λ U BU, F.Hid U, Hcomp := λ U V W BU BV BW, F.Hcomp U V W, Fring := λ U BU, F.Fring U, res_is_ring_hom := λ U V BU BV HVU, F.res_is_ring_hom U V HVU, } -- F defined on the bases extended to the whole space. def presheaf_of_rings_extension (F : presheaf_of_rings_on_basis α HB) : presheaf_of_rings α := { F := λ U, {s : Π (x ∈ U), stalk_on_basis F.to_presheaf_on_basis x // ∀ (x ∈ U), ∃ (V) (BV : V ∈ B) (Hx : x ∈ V) (σ : F.to_presheaf_on_basis BV), ∀ (y ∈ U ∩ V), s y = λ _, ⟦{U := V, BU := BV, Hx := H.2, s := σ}⟧}, res := λ U W HWU FU, { val := λ x HxW, (FU.val x $ HWU HxW), property := λ x HxW, begin rcases (FU.property x (HWU HxW)) with ⟨V, ⟨BV, ⟨HxV, ⟨σ, HFV⟩⟩⟩⟩, use [V, BV, HxV, σ], rintros y ⟨HyW, HyV⟩, rw (HFV y ⟨HWU HyW, HyV⟩), end }, Hid := λ U, funext $ λ x, subtype.eq rfl, Hcomp := λ U V W HWV HVU, funext $ λ x, subtype.eq rfl, Fring := λ U, Fext_comm_ring Bstd F U, res_is_ring_hom := λ U V HVU, { map_one := rfl, map_mul := λ x y, subtype.eq $ funext $ λ x, funext $ λ Hx, begin erw Fext_mul.eq, refl, end, map_add := λ x y, subtype.eq $ funext $ λ x, funext $ λ Hx, begin erw Fext_add.eq, refl, end, } } notation F `ᵣₑₓₜ`:1 Bstd := presheaf_of_rings_extension Bstd F end presheaf_of_rings_extension
"""Manzini et al. Multiclass Hard Debias WEFE implementation.""" import logging from copy import deepcopy from typing import Any, Dict, List, Optional, Sequence import numpy as np from sklearn.decomposition import PCA from tqdm import tqdm from wefe.debias.base_debias import BaseDebias from wefe.preprocessing import get_embeddings_from_sets from wefe.utils import check_is_fitted from wefe.word_embedding_model import EmbeddingDict, WordEmbeddingModel logger = logging.getLogger(__name__) class MulticlassHardDebias(BaseDebias): """Generalized version of Hard Debias that enables multiclass debiasing. Generalized refers to the fact that this method extends Hard Debias in order to support more than two types of social target sets within the definitional set. For example, for the case of religion bias, it supports a debias using words associated with Christianity, Islam and Judaism. References ---------- | [1]: Manzini, T., Chong, L. Y., Black, A. W., & Tsvetkov, Y. (2019, June). | Black is to Criminal as Caucasian is to Police: Detecting and Removing Multiclass | Bias in Word Embeddings. | In Proceedings of the 2019 Conference of the North American Chapter of the | Association for Computational Linguistics: Human Language Technologies, | Volume 1 (Long and Short Papers) (pp. 615-621). | [2]: https://github.com/TManzini/DebiasMulticlassWordEmbedding """ def __init__( self, pca_args: Dict[str, Any] = {"n_components": 10}, verbose: bool = False, criterion_name: Optional[str] = None, ) -> None: """Initialize a Multiclass Hard Debias instance. Parameters ---------- pca_args : Dict[str, Any], optional Arguments for the PCA that is calculated internally in the identification of the bias subspace, by default {"n_components": 10} verbose : bool, optional True will print informative messages about the debiasing process, by default False. criterion_name : Optional[str], optional The name of the criterion for which the debias is being executed, e.g. 'Gender'. This will indicate the name of the model returning transform, by default None """ # check pca args if not isinstance(pca_args, dict): raise TypeError(f"pca_args should be a dict, got {pca_args}.") # check verbose if not isinstance(verbose, bool): raise TypeError(f"verbose should be a bool, got {verbose}.") self.pca_args = pca_args self.verbose = verbose if "n_components" in pca_args: self.pca_num_components_ = pca_args["n_components"] else: self.pca_num_components_ = 10 if criterion_name is None or isinstance(criterion_name, str): self.criterion_name_ = criterion_name else: raise ValueError( f"debias_criterion_name should be str, got: {criterion_name}" ) def _identify_bias_subspace( self, definning_sets_embeddings: List[EmbeddingDict], ) -> PCA: matrix = [] for definning_set_dict in definning_sets_embeddings: # Get the center of the current definning pair. set_embeddings = np.array(list(definning_set_dict.values())) center = np.mean(set_embeddings, axis=0) # For each word, embedding in the definning pair: for embedding in definning_set_dict.values(): # Substract the center of the pair to the embedding matrix.append(embedding - center) matrix = np.array(matrix) # type: ignore pca = PCA(**self.pca_args) pca.fit(matrix) if self.verbose: explained_variance = pca.explained_variance_ratio_ if len(explained_variance) > 10: logger.info(f"PCA variance explaned: {explained_variance[0:10]}") else: logger.info(f"PCA variance explaned: {explained_variance}") return pca def _project_onto_subspace(self, vector, subspace): v_b = np.zeros_like(vector) for component in subspace: v_b += np.dot(vector.transpose(), component) * component return v_b def _get_target( self, model: WordEmbeddingModel, target: Optional[Sequence[str]] = None, ) -> List[str]: definitional_words = np.array(self.definitional_sets_).flatten().tolist() if target is not None: # keep only words in the model's vocab. target = list( filter( lambda x: x in model.vocab and x not in definitional_words, target, ) ) else: # indicate that all words are canditates to neutralize. target = list( filter(lambda x: x not in definitional_words, model.vocab.keys(),) ) return target def _neutralize( self, model: WordEmbeddingModel, bias_subspace: np.ndarray, target: Optional[List[str]], ignore: Optional[List[str]], ): if target is not None: target_ = set(target) else: target_ = set(model.vocab.keys()) if ignore is not None and target is None: ignore_ = set(ignore) else: ignore_ = set() for word in tqdm(target_): if word not in ignore_: # get the embedding v = model[word] # neutralize the embedding if the word is not in the definitional words. v_b = self._project_onto_subspace(v, bias_subspace) # neutralize the embedding new_v = (v - v_b) / np.linalg.norm(v - v_b) # update the old values model.update(word, new_v) def _equalize( self, model: WordEmbeddingModel, equalize_sets_embeddings: List[EmbeddingDict], bias_subspace: np.ndarray, ): for equalize_pair_embeddings in equalize_sets_embeddings: words = equalize_pair_embeddings.keys() embeddings = np.array(list(equalize_pair_embeddings.values())) # calculate the mean of the equality set mean = np.mean(embeddings, axis=0) # project the mean in the bias subspace mean_b = self._project_onto_subspace(mean, bias_subspace) # discard the projection from the mean upsilon = mean - mean_b for (word, embedding) in zip(words, embeddings): v_b = self._project_onto_subspace(embedding, bias_subspace) frac = (v_b - mean_b) / np.linalg.norm(v_b - mean_b) new_v = upsilon + np.sqrt(1 - np.sum(np.square(upsilon))) * frac model.update(word, new_v) def fit( self, model: WordEmbeddingModel, definitional_sets: Sequence[Sequence[str]], equalize_sets: Sequence[Sequence[str]], ) -> BaseDebias: """Compute the bias direction and obtains the equalize embedding pairs. Parameters ---------- model : WordEmbeddingModel The word embedding model to debias. definitional_sets : Sequence[Sequence[str]] A sequence of string pairs that will be used to define the bias direction. For example, for the case of gender debias, this list could be [['woman', 'man'], ['girl', 'boy'], ['she', 'he'], ['mother', 'father'], ...]. equalize_pairs : Optional[Sequence[Sequence[str]]], optional A list with pairs of strings, which will be equalized. In the case of passing None, the equalization will be done over the word pairs passed in definitional_sets, by default None. Returns ------- BaseDebias The debias method fitted. """ # ------------------------------------------------------------------------------: # Obtain the embedding of the definitional sets. if self.verbose: print("Obtaining definitional sets.") self.definitional_sets_ = definitional_sets self.definitional_sets_embeddings_ = get_embeddings_from_sets( model=model, sets=definitional_sets, sets_name="definitional", warn_lost_sets=True, normalize=True, verbose=self.verbose, ) # ------------------------------------------------------------------------------: # Identify the bias subspace using the definning sets. if self.verbose: print("Identifying the bias subspace.") self.pca_ = self._identify_bias_subspace(self.definitional_sets_embeddings_,) self.bias_subspace_ = self.pca_.components_[: self.pca_num_components_] # ------------------------------------------------------------------------------ # Equalize embeddings: # Get the equalization sets embeddings. # Note that the equalization sets are the same as the definitional sets. if self.verbose: print("Obtaining equalize pairs.") self.equalize_sets_embeddings_ = get_embeddings_from_sets( model=model, sets=equalize_sets, sets_name="equalize", normalize=True, warn_lost_sets=True, verbose=self.verbose, ) return self def transform( self, model: WordEmbeddingModel, target: Optional[List[str]] = None, ignore: Optional[List[str]] = None, copy: bool = True, ) -> WordEmbeddingModel: """Execute Multiclass Hard Debias over the provided model. Parameters ---------- model : WordEmbeddingModel The word embedding model to debias. target : Optional[List[str]], optional If a set of words is specified in target, the debias method will be performed only on the word embeddings of this set. If `None` is provided, the debias will be performed on all words (except those specified in ignore). by default `None`. ignore : Optional[List[str]], optional If target is `None` and a set of words is specified in ignore, the debias method will perform the debias in all words except those specified in this set, by default `None`. copy : bool, optional If `True`, the debias will be performed on a copy of the model. If `False`, the debias will be applied on the same model delivered, causing its vectors to mutate. **WARNING:** Setting copy with `True` requires RAM at least 2x of the size of the model, otherwise the execution of the debias may raise to `MemoryError`, by default True. Returns ------- WordEmbeddingModel The debiased embedding model. """ self._check_transform_args( model=model, target=target, ignore=ignore, copy=copy, ) check_is_fitted( self, [ "definitional_sets_", "definitional_sets_embeddings_", "pca_", "bias_subspace_", ], ) if self.verbose: print(f"Executing Multiclass Hard Debias on {model.name}") # ------------------------------------------------------------------------------ # Copy if copy: print( "copy argument is True. Transform will attempt to create a copy " "of the original model. This may fail due to lack of memory." ) model = deepcopy(model) print("Model copy created successfully.") else: print( "copy argument is False. The execution of this method will mutate " "the original model." ) # ------------------------------------------------------------------------------ # Neutralize the embeddings provided in target. # if target is None, the debias will be performed in all embeddings. if self.verbose: print("Normalizing embeddings.") model.normalize() # Neutralize the embeddings: if self.verbose: print("Neutralizing embeddings") # get the words that will be debiased. target = self._get_target(model, target) self._neutralize( model=model, bias_subspace=self.bias_subspace_, target=target, ignore=ignore, ) if self.verbose: print("Normalizing embeddings.") model.normalize() # ------------------------------------------------------------------------------ # Equalize embeddings: # Execute the equalization logger.debug("Equalizing embeddings..") self._equalize( model=model, equalize_sets_embeddings=self.equalize_sets_embeddings_, bias_subspace=self.bias_subspace_, ) # ------------------------------------------------------------------------------ if self.verbose: print("Normalizing embeddings.") model.normalize() # ------------------------------------------------------------------------------ # # Generate the new KeyedVectors if self.criterion_name_ is None: new_model_name = f"{model.name}_debiased" else: new_model_name = f"{model.name}_{self.criterion_name_}_debiased" model.name = new_model_name if self.verbose: print("Done!") return model
/- Copyright (c) 2016 Jeremy Avigad. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Jeremy Avigad, Leonardo de Moura, Mario Carneiro, Yaël Dillies -/ import algebra.order.group.defs import algebra.order.monoid.cancel.defs import algebra.order.monoid.canonical.defs import algebra.order.monoid.nat_cast import algebra.order.monoid.with_zero.defs import algebra.order.ring.lemmas import algebra.ring.defs import order.min_max import tactic.nontriviality import data.pi.algebra import algebra.group.units /-! # Ordered rings and semirings > THIS FILE IS SYNCHRONIZED WITH MATHLIB4. > Any changes to this file require a corresponding PR to mathlib4. This file develops the basics of ordered (semi)rings. Each typeclass here comprises * an algebraic class (`semiring`, `comm_semiring`, `ring`, `comm_ring`) * an order class (`partial_order`, `linear_order`) * assumptions on how both interact ((strict) monotonicity, canonicity) For short, * "`+` respects `≤`" means "monotonicity of addition" * "`+` respects `<`" means "strict monotonicity of addition" * "`*` respects `≤`" means "monotonicity of multiplication by a nonnegative number". * "`*` respects `<`" means "strict monotonicity of multiplication by a positive number". ## Typeclasses * `ordered_semiring`: Semiring with a partial order such that `+` and `*` respect `≤`. * `strict_ordered_semiring`: Nontrivial semiring with a partial order such that `+` and `*` respects `<`. * `ordered_comm_semiring`: Commutative semiring with a partial order such that `+` and `*` respect `≤`. * `strict_ordered_comm_semiring`: Nontrivial commutative semiring with a partial order such that `+` and `*` respect `<`. * `ordered_ring`: Ring with a partial order such that `+` respects `≤` and `*` respects `<`. * `ordered_comm_ring`: Commutative ring with a partial order such that `+` respects `≤` and `*` respects `<`. * `linear_ordered_semiring`: Nontrivial semiring with a linear order such that `+` respects `≤` and `*` respects `<`. * `linear_ordered_comm_semiring`: Nontrivial commutative semiring with a linear order such that `+` respects `≤` and `*` respects `<`. * `linear_ordered_ring`: Nontrivial ring with a linear order such that `+` respects `≤` and `*` respects `<`. * `linear_ordered_comm_ring`: Nontrivial commutative ring with a linear order such that `+` respects `≤` and `*` respects `<`. * `canonically_ordered_comm_semiring`: Commutative semiring with a partial order such that `+` respects `≤`, `*` respects `<`, and `a ≤ b ↔ ∃ c, b = a + c`. ## Hierarchy The hardest part of proving order lemmas might be to figure out the correct generality and its corresponding typeclass. Here's an attempt at demystifying it. For each typeclass, we list its immediate predecessors and what conditions are added to each of them. * `ordered_semiring` - `ordered_add_comm_monoid` & multiplication & `*` respects `≤` - `semiring` & partial order structure & `+` respects `≤` & `*` respects `≤` * `strict_ordered_semiring` - `ordered_cancel_add_comm_monoid` & multiplication & `*` respects `<` & nontriviality - `ordered_semiring` & `+` respects `<` & `*` respects `<` & nontriviality * `ordered_comm_semiring` - `ordered_semiring` & commutativity of multiplication - `comm_semiring` & partial order structure & `+` respects `≤` & `*` respects `<` * `strict_ordered_comm_semiring` - `strict_ordered_semiring` & commutativity of multiplication - `ordered_comm_semiring` & `+` respects `<` & `*` respects `<` & nontriviality * `ordered_ring` - `ordered_semiring` & additive inverses - `ordered_add_comm_group` & multiplication & `*` respects `<` - `ring` & partial order structure & `+` respects `≤` & `*` respects `<` * `strict_ordered_ring` - `strict_ordered_semiring` & additive inverses - `ordered_semiring` & `+` respects `<` & `*` respects `<` & nontriviality * `ordered_comm_ring` - `ordered_ring` & commutativity of multiplication - `ordered_comm_semiring` & additive inverses - `comm_ring` & partial order structure & `+` respects `≤` & `*` respects `<` * `strict_ordered_comm_ring` - `strict_ordered_comm_semiring` & additive inverses - `strict_ordered_ring` & commutativity of multiplication - `ordered_comm_ring` & `+` respects `<` & `*` respects `<` & nontriviality * `linear_ordered_semiring` - `strict_ordered_semiring` & totality of the order - `linear_ordered_add_comm_monoid` & multiplication & nontriviality & `*` respects `<` * `linear_ordered_comm_semiring` - `strict_ordered_comm_semiring` & totality of the order - `linear_ordered_semiring` & commutativity of multiplication * `linear_ordered_ring` - `strict_ordered_ring` & totality of the order - `linear_ordered_semiring` & additive inverses - `linear_ordered_add_comm_group` & multiplication & `*` respects `<` - `domain` & linear order structure * `linear_ordered_comm_ring` - `strict_ordered_comm_ring` & totality of the order - `linear_ordered_ring` & commutativity of multiplication - `linear_ordered_comm_semiring` & additive inverses - `is_domain` & linear order structure -/ open function set_option old_structure_cmd true universe u variables {α : Type u} {β : Type*} /-! Note that `order_dual` does not satisfy any of the ordered ring typeclasses due to the `zero_le_one` field. -/ lemma add_one_le_two_mul [has_le α] [semiring α] [covariant_class α α (+) (≤)] {a : α} (a1 : 1 ≤ a) : a + 1 ≤ 2 * a := calc a + 1 ≤ a + a : add_le_add_left a1 a ... = 2 * a : (two_mul _).symm /-- An `ordered_semiring` is a semiring with a partial order such that addition is monotone and multiplication by a nonnegative number is monotone. -/ @[protect_proj, ancestor semiring ordered_add_comm_monoid] class ordered_semiring (α : Type u) extends semiring α, ordered_add_comm_monoid α := (zero_le_one : (0 : α) ≤ 1) (mul_le_mul_of_nonneg_left : ∀ a b c : α, a ≤ b → 0 ≤ c → c * a ≤ c * b) (mul_le_mul_of_nonneg_right : ∀ a b c : α, a ≤ b → 0 ≤ c → a * c ≤ b * c) /-- An `ordered_comm_semiring` is a commutative semiring with a partial order such that addition is monotone and multiplication by a nonnegative number is monotone. -/ @[protect_proj, ancestor ordered_semiring comm_semiring] class ordered_comm_semiring (α : Type u) extends ordered_semiring α, comm_semiring α /-- An `ordered_ring` is a ring with a partial order such that addition is monotone and multiplication by a nonnegative number is monotone. -/ @[protect_proj, ancestor ring ordered_add_comm_group] class ordered_ring (α : Type u) extends ring α, ordered_add_comm_group α := (zero_le_one : 0 ≤ (1 : α)) (mul_nonneg : ∀ a b : α, 0 ≤ a → 0 ≤ b → 0 ≤ a * b) /-- An `ordered_comm_ring` is a commutative ring with a partial order such that addition is monotone and multiplication by a nonnegative number is monotone. -/ @[protect_proj, ancestor ordered_ring comm_ring] class ordered_comm_ring (α : Type u) extends ordered_ring α, comm_ring α /-- A `strict_ordered_semiring` is a nontrivial semiring with a partial order such that addition is strictly monotone and multiplication by a positive number is strictly monotone. -/ @[protect_proj, ancestor semiring ordered_cancel_add_comm_monoid nontrivial] class strict_ordered_semiring (α : Type u) extends semiring α, ordered_cancel_add_comm_monoid α, nontrivial α := (zero_le_one : (0 : α) ≤ 1) (mul_lt_mul_of_pos_left : ∀ a b c : α, a < b → 0 < c → c * a < c * b) (mul_lt_mul_of_pos_right : ∀ a b c : α, a < b → 0 < c → a * c < b * c) /-- A `strict_ordered_comm_semiring` is a commutative semiring with a partial order such that addition is strictly monotone and multiplication by a positive number is strictly monotone. -/ @[protect_proj, ancestor strict_ordered_semiring comm_semiring] class strict_ordered_comm_semiring (α : Type u) extends strict_ordered_semiring α, comm_semiring α /-- A `strict_ordered_ring` is a ring with a partial order such that addition is strictly monotone and multiplication by a positive number is strictly monotone. -/ @[protect_proj, ancestor ring ordered_add_comm_group nontrivial] class strict_ordered_ring (α : Type u) extends ring α, ordered_add_comm_group α, nontrivial α := (zero_le_one : 0 ≤ (1 : α)) (mul_pos : ∀ a b : α, 0 < a → 0 < b → 0 < a * b) /-- A `strict_ordered_comm_ring` is a commutative ring with a partial order such that addition is strictly monotone and multiplication by a positive number is strictly monotone. -/ @[protect_proj, ancestor strict_ordered_ring comm_ring] class strict_ordered_comm_ring (α : Type*) extends strict_ordered_ring α, comm_ring α /-- A `linear_ordered_semiring` is a nontrivial semiring with a linear order such that addition is monotone and multiplication by a positive number is strictly monotone. -/ /- It's not entirely clear we should assume `nontrivial` at this point; it would be reasonable to explore changing this, but be warned that the instances involving `domain` may cause typeclass search loops. -/ @[protect_proj, ancestor strict_ordered_semiring linear_ordered_add_comm_monoid nontrivial] class linear_ordered_semiring (α : Type u) extends strict_ordered_semiring α, linear_ordered_add_comm_monoid α /-- A `linear_ordered_comm_semiring` is a nontrivial commutative semiring with a linear order such that addition is monotone and multiplication by a positive number is strictly monotone. -/ @[protect_proj, ancestor ordered_comm_semiring linear_ordered_semiring] class linear_ordered_comm_semiring (α : Type*) extends strict_ordered_comm_semiring α, linear_ordered_semiring α /-- A `linear_ordered_ring` is a ring with a linear order such that addition is monotone and multiplication by a positive number is strictly monotone. -/ @[protect_proj, ancestor strict_ordered_ring linear_order] class linear_ordered_ring (α : Type u) extends strict_ordered_ring α, linear_order α /-- A `linear_ordered_comm_ring` is a commutative ring with a linear order such that addition is monotone and multiplication by a positive number is strictly monotone. -/ @[protect_proj, ancestor linear_ordered_ring comm_monoid] class linear_ordered_comm_ring (α : Type u) extends linear_ordered_ring α, comm_monoid α section ordered_semiring variables [ordered_semiring α] {a b c d : α} @[priority 100] -- see Note [lower instance priority] instance ordered_semiring.zero_le_one_class : zero_le_one_class α := { ..‹ordered_semiring α› } @[priority 200] -- see Note [lower instance priority] instance ordered_semiring.to_pos_mul_mono : pos_mul_mono α := ⟨λ x a b h, ordered_semiring.mul_le_mul_of_nonneg_left _ _ _ h x.2⟩ @[priority 200] -- see Note [lower instance priority] instance ordered_semiring.to_mul_pos_mono : mul_pos_mono α := ⟨λ x a b h, ordered_semiring.mul_le_mul_of_nonneg_right _ _ _ h x.2⟩ lemma bit1_mono : monotone (bit1 : α → α) := λ a b h, add_le_add_right (bit0_mono h) _ @[simp] lemma pow_nonneg (H : 0 ≤ a) : ∀ (n : ℕ), 0 ≤ a ^ n | 0 := by { rw pow_zero, exact zero_le_one} | (n+1) := by { rw pow_succ, exact mul_nonneg H (pow_nonneg _) } lemma add_le_mul_two_add (a2 : 2 ≤ a) (b0 : 0 ≤ b) : a + (2 + b) ≤ a * (2 + b) := calc a + (2 + b) ≤ a + (a + a * b) : add_le_add_left (add_le_add a2 $ le_mul_of_one_le_left b0 $ one_le_two.trans a2) a ... ≤ a * (2 + b) : by rw [mul_add, mul_two, add_assoc] lemma one_le_mul_of_one_le_of_one_le (ha : 1 ≤ a) (hb : 1 ≤ b) : (1 : α) ≤ a * b := left.one_le_mul_of_le_of_le ha hb $ zero_le_one.trans ha section monotone variables [preorder β] {f g : β → α} lemma monotone_mul_left_of_nonneg (ha : 0 ≤ a) : monotone (λ x, a * x) := λ b c h, mul_le_mul_of_nonneg_left h ha lemma monotone_mul_right_of_nonneg (ha : 0 ≤ a) : monotone (λ x, x * a) := λ b c h, mul_le_mul_of_nonneg_right h ha lemma monotone.mul_const (hf : monotone f) (ha : 0 ≤ a) : monotone (λ x, f x * a) := (monotone_mul_right_of_nonneg ha).comp hf lemma monotone.const_mul (hf : monotone f) (ha : 0 ≤ a) : monotone (λ x, a * f x) := (monotone_mul_left_of_nonneg ha).comp hf lemma antitone.mul_const (hf : antitone f) (ha : 0 ≤ a) : antitone (λ x, f x * a) := (monotone_mul_right_of_nonneg ha).comp_antitone hf lemma antitone.const_mul (hf : antitone f) (ha : 0 ≤ a) : antitone (λ x, a * f x) := (monotone_mul_left_of_nonneg ha).comp_antitone hf lemma monotone.mul (hf : monotone f) (hg : monotone g) (hf₀ : ∀ x, 0 ≤ f x) (hg₀ : ∀ x, 0 ≤ g x) : monotone (f * g) := λ b c h, mul_le_mul (hf h) (hg h) (hg₀ _) (hf₀ _) end monotone lemma bit1_pos [nontrivial α] (h : 0 ≤ a) : 0 < bit1 a := zero_lt_one.trans_le $ bit1_zero.symm.trans_le $ bit1_mono h lemma bit1_pos' (h : 0 < a) : 0 < bit1 a := by { nontriviality, exact bit1_pos h.le } lemma mul_le_one (ha : a ≤ 1) (hb' : 0 ≤ b) (hb : b ≤ 1) : a * b ≤ 1 := one_mul (1 : α) ▸ mul_le_mul ha hb hb' zero_le_one lemma one_lt_mul_of_le_of_lt (ha : 1 ≤ a) (hb : 1 < b) : 1 < a * b := hb.trans_le $ le_mul_of_one_le_left (zero_le_one.trans hb.le) ha lemma one_lt_mul_of_lt_of_le (ha : 1 < a) (hb : 1 ≤ b) : 1 < a * b := ha.trans_le $ le_mul_of_one_le_right (zero_le_one.trans ha.le) hb alias one_lt_mul_of_le_of_lt ← one_lt_mul lemma mul_lt_one_of_nonneg_of_lt_one_left (ha₀ : 0 ≤ a) (ha : a < 1) (hb : b ≤ 1) : a * b < 1 := (mul_le_of_le_one_right ha₀ hb).trans_lt ha lemma mul_lt_one_of_nonneg_of_lt_one_right (ha : a ≤ 1) (hb₀ : 0 ≤ b) (hb : b < 1) : a * b < 1 := (mul_le_of_le_one_left hb₀ ha).trans_lt hb end ordered_semiring section ordered_ring variables [ordered_ring α] {a b c d : α} @[priority 100] -- see Note [lower instance priority] instance ordered_ring.to_ordered_semiring : ordered_semiring α := { mul_le_mul_of_nonneg_left := λ a b c h hc, by simpa only [mul_sub, sub_nonneg] using ordered_ring.mul_nonneg _ _ hc (sub_nonneg.2 h), mul_le_mul_of_nonneg_right := λ a b c h hc, by simpa only [sub_mul, sub_nonneg] using ordered_ring.mul_nonneg _ _ (sub_nonneg.2 h) hc, ..‹ordered_ring α›, ..ring.to_semiring } lemma mul_le_mul_of_nonpos_left (h : b ≤ a) (hc : c ≤ 0) : c * a ≤ c * b := by simpa only [neg_mul, neg_le_neg_iff] using mul_le_mul_of_nonneg_left h (neg_nonneg.2 hc) lemma mul_le_mul_of_nonpos_right (h : b ≤ a) (hc : c ≤ 0) : a * c ≤ b * c := by simpa only [mul_neg, neg_le_neg_iff] using mul_le_mul_of_nonneg_right h (neg_nonneg.2 hc) lemma mul_nonneg_of_nonpos_of_nonpos (ha : a ≤ 0) (hb : b ≤ 0) : 0 ≤ a * b := by simpa only [zero_mul] using mul_le_mul_of_nonpos_right ha hb lemma mul_le_mul_of_nonneg_of_nonpos (hca : c ≤ a) (hbd : b ≤ d) (hc : 0 ≤ c) (hb : b ≤ 0) : a * b ≤ c * d := (mul_le_mul_of_nonpos_right hca hb).trans $ mul_le_mul_of_nonneg_left hbd hc lemma mul_le_mul_of_nonneg_of_nonpos' (hca : c ≤ a) (hbd : b ≤ d) (ha : 0 ≤ a) (hd : d ≤ 0) : a * b ≤ c * d := (mul_le_mul_of_nonneg_left hbd ha).trans $ mul_le_mul_of_nonpos_right hca hd lemma mul_le_mul_of_nonpos_of_nonneg (hac : a ≤ c) (hdb : d ≤ b) (hc : c ≤ 0) (hb : 0 ≤ b) : a * b ≤ c * d := (mul_le_mul_of_nonneg_right hac hb).trans $ mul_le_mul_of_nonpos_left hdb hc lemma mul_le_mul_of_nonpos_of_nonneg' (hca : c ≤ a) (hbd : b ≤ d) (ha : 0 ≤ a) (hd : d ≤ 0) : a * b ≤ c * d := (mul_le_mul_of_nonneg_left hbd ha).trans $ mul_le_mul_of_nonpos_right hca hd lemma mul_le_mul_of_nonpos_of_nonpos (hca : c ≤ a) (hdb : d ≤ b) (hc : c ≤ 0) (hb : b ≤ 0) : a * b ≤ c * d := (mul_le_mul_of_nonpos_right hca hb).trans $ mul_le_mul_of_nonpos_left hdb hc lemma mul_le_mul_of_nonpos_of_nonpos' (hca : c ≤ a) (hdb : d ≤ b) (ha : a ≤ 0) (hd : d ≤ 0) : a * b ≤ c * d := (mul_le_mul_of_nonpos_left hdb ha).trans $ mul_le_mul_of_nonpos_right hca hd section monotone variables [preorder β] {f g : β → α} lemma antitone_mul_left {a : α} (ha : a ≤ 0) : antitone ((*) a) := λ b c b_le_c, mul_le_mul_of_nonpos_left b_le_c ha lemma antitone_mul_right {a : α} (ha : a ≤ 0) : antitone (λ x, x * a) := λ b c b_le_c, mul_le_mul_of_nonpos_right b_le_c ha lemma monotone.const_mul_of_nonpos (hf : monotone f) (ha : a ≤ 0) : antitone (λ x, a * f x) := (antitone_mul_left ha).comp_monotone hf lemma monotone.mul_const_of_nonpos (hf : monotone f) (ha : a ≤ 0) : antitone (λ x, f x * a) := (antitone_mul_right ha).comp_monotone hf lemma antitone.const_mul_of_nonpos (hf : antitone f) (ha : a ≤ 0) : monotone (λ x, a * f x) := (antitone_mul_left ha).comp hf lemma antitone.mul_const_of_nonpos (hf : antitone f) (ha : a ≤ 0) : monotone (λ x, f x * a) := (antitone_mul_right ha).comp hf lemma antitone.mul_monotone (hf : antitone f) (hg : monotone g) (hf₀ : ∀ x, f x ≤ 0) (hg₀ : ∀ x, 0 ≤ g x) : antitone (f * g) := λ b c h, mul_le_mul_of_nonpos_of_nonneg (hf h) (hg h) (hf₀ _) (hg₀ _) lemma monotone.mul_antitone (hf : monotone f) (hg : antitone g) (hf₀ : ∀ x, 0 ≤ f x) (hg₀ : ∀ x, g x ≤ 0) : antitone (f * g) := λ b c h, mul_le_mul_of_nonneg_of_nonpos (hf h) (hg h) (hf₀ _) (hg₀ _) lemma antitone.mul (hf : antitone f) (hg : antitone g) (hf₀ : ∀ x, f x ≤ 0) (hg₀ : ∀ x, g x ≤ 0) : monotone (f * g) := λ b c h, mul_le_mul_of_nonpos_of_nonpos (hf h) (hg h) (hf₀ _) (hg₀ _) end monotone lemma le_iff_exists_nonneg_add (a b : α) : a ≤ b ↔ ∃ c ≥ 0, b = a + c := ⟨λ h, ⟨b - a, sub_nonneg.mpr h, by simp⟩, λ ⟨c, hc, h⟩, by { rw [h, le_add_iff_nonneg_right], exact hc }⟩ end ordered_ring section ordered_comm_ring variables [ordered_comm_ring α] @[priority 100] -- See note [lower instance priority] instance ordered_comm_ring.to_ordered_comm_semiring : ordered_comm_semiring α := { ..ordered_ring.to_ordered_semiring, ..‹ordered_comm_ring α› } end ordered_comm_ring section strict_ordered_semiring variables [strict_ordered_semiring α] {a b c d : α} @[priority 200] -- see Note [lower instance priority] instance strict_ordered_semiring.to_pos_mul_strict_mono : pos_mul_strict_mono α := ⟨λ x a b h, strict_ordered_semiring.mul_lt_mul_of_pos_left _ _ _ h x.prop⟩ @[priority 200] -- see Note [lower instance priority] instance strict_ordered_semiring.to_mul_pos_strict_mono : mul_pos_strict_mono α := ⟨λ x a b h, strict_ordered_semiring.mul_lt_mul_of_pos_right _ _ _ h x.prop⟩ /-- A choice-free version of `strict_ordered_semiring.to_ordered_semiring` to avoid using choice in basic `nat` lemmas. -/ @[reducible] -- See note [reducible non-instances] def strict_ordered_semiring.to_ordered_semiring' [@decidable_rel α (≤)] : ordered_semiring α := { mul_le_mul_of_nonneg_left := λ a b c hab hc, begin obtain rfl | hab := decidable.eq_or_lt_of_le hab, { refl }, obtain rfl | hc := decidable.eq_or_lt_of_le hc, { simp }, { exact (mul_lt_mul_of_pos_left hab hc).le } end, mul_le_mul_of_nonneg_right := λ a b c hab hc, begin obtain rfl | hab := decidable.eq_or_lt_of_le hab, { refl }, obtain rfl | hc := decidable.eq_or_lt_of_le hc, { simp }, { exact (mul_lt_mul_of_pos_right hab hc).le } end, ..‹strict_ordered_semiring α› } @[priority 100] -- see Note [lower instance priority] instance strict_ordered_semiring.to_ordered_semiring : ordered_semiring α := { mul_le_mul_of_nonneg_left := λ _ _ _, begin letI := @strict_ordered_semiring.to_ordered_semiring' α _ (classical.dec_rel _), exact mul_le_mul_of_nonneg_left, end, mul_le_mul_of_nonneg_right := λ _ _ _, begin letI := @strict_ordered_semiring.to_ordered_semiring' α _ (classical.dec_rel _), exact mul_le_mul_of_nonneg_right, end, ..‹strict_ordered_semiring α› } lemma mul_lt_mul (hac : a < c) (hbd : b ≤ d) (hb : 0 < b) (hc : 0 ≤ c) : a * b < c * d := (mul_lt_mul_of_pos_right hac hb).trans_le $ mul_le_mul_of_nonneg_left hbd hc lemma mul_lt_mul' (hac : a ≤ c) (hbd : b < d) (hb : 0 ≤ b) (hc : 0 < c) : a * b < c * d := (mul_le_mul_of_nonneg_right hac hb).trans_lt $ mul_lt_mul_of_pos_left hbd hc @[simp] theorem pow_pos (H : 0 < a) : ∀ (n : ℕ), 0 < a ^ n | 0 := by { nontriviality, rw pow_zero, exact zero_lt_one } | (n+1) := by { rw pow_succ, exact mul_pos H (pow_pos _) } lemma mul_self_lt_mul_self (h1 : 0 ≤ a) (h2 : a < b) : a * a < b * b := mul_lt_mul' h2.le h2 h1 $ h1.trans_lt h2 -- In the next lemma, we used to write `set.Ici 0` instead of `{x | 0 ≤ x}`. -- As this lemma is not used outside this file, -- and the import for `set.Ici` is not otherwise needed until later, -- we choose not to use it here. lemma strict_mono_on_mul_self : strict_mono_on (λ x : α, x * x) {x | 0 ≤ x} := λ x hx y hy hxy, mul_self_lt_mul_self hx hxy -- See Note [decidable namespace] protected lemma decidable.mul_lt_mul'' [@decidable_rel α (≤)] (h1 : a < c) (h2 : b < d) (h3 : 0 ≤ a) (h4 : 0 ≤ b) : a * b < c * d := h4.lt_or_eq_dec.elim (λ b0, mul_lt_mul h1 h2.le b0 $ h3.trans h1.le) (λ b0, by rw [← b0, mul_zero]; exact mul_pos (h3.trans_lt h1) (h4.trans_lt h2)) lemma mul_lt_mul'' : a < c → b < d → 0 ≤ a → 0 ≤ b → a * b < c * d := by classical; exact decidable.mul_lt_mul'' lemma lt_mul_left (hn : 0 < a) (hm : 1 < b) : a < b * a := by { convert mul_lt_mul_of_pos_right hm hn, rw one_mul } lemma lt_mul_right (hn : 0 < a) (hm : 1 < b) : a < a * b := by { convert mul_lt_mul_of_pos_left hm hn, rw mul_one } lemma lt_mul_self (hn : 1 < a) : a < a * a := lt_mul_left (hn.trans_le' zero_le_one) hn section monotone variables [preorder β] {f g : β → α} lemma strict_mono_mul_left_of_pos (ha : 0 < a) : strict_mono (λ x, a * x) := assume b c b_lt_c, mul_lt_mul_of_pos_left b_lt_c ha lemma strict_mono_mul_right_of_pos (ha : 0 < a) : strict_mono (λ x, x * a) := assume b c b_lt_c, mul_lt_mul_of_pos_right b_lt_c ha lemma strict_mono.mul_const (hf : strict_mono f) (ha : 0 < a) : strict_mono (λ x, (f x) * a) := (strict_mono_mul_right_of_pos ha).comp hf lemma strict_mono.const_mul (hf : strict_mono f) (ha : 0 < a) : strict_mono (λ x, a * (f x)) := (strict_mono_mul_left_of_pos ha).comp hf lemma strict_anti.mul_const (hf : strict_anti f) (ha : 0 < a) : strict_anti (λ x, f x * a) := (strict_mono_mul_right_of_pos ha).comp_strict_anti hf lemma strict_anti.const_mul (hf : strict_anti f) (ha : 0 < a) : strict_anti (λ x, a * f x) := (strict_mono_mul_left_of_pos ha).comp_strict_anti hf lemma strict_mono.mul_monotone (hf : strict_mono f) (hg : monotone g) (hf₀ : ∀ x, 0 ≤ f x) (hg₀ : ∀ x, 0 < g x) : strict_mono (f * g) := λ b c h, mul_lt_mul (hf h) (hg h.le) (hg₀ _) (hf₀ _) lemma monotone.mul_strict_mono (hf : monotone f) (hg : strict_mono g) (hf₀ : ∀ x, 0 < f x) (hg₀ : ∀ x, 0 ≤ g x) : strict_mono (f * g) := λ b c h, mul_lt_mul' (hf h.le) (hg h) (hg₀ _) (hf₀ _) lemma strict_mono.mul (hf : strict_mono f) (hg : strict_mono g) (hf₀ : ∀ x, 0 ≤ f x) (hg₀ : ∀ x, 0 ≤ g x) : strict_mono (f * g) := λ b c h, mul_lt_mul'' (hf h) (hg h) (hf₀ _) (hg₀ _) end monotone lemma lt_two_mul_self (ha : 0 < a) : a < 2 * a := lt_mul_of_one_lt_left ha one_lt_two @[priority 100] -- see Note [lower instance priority] instance strict_ordered_semiring.to_no_max_order : no_max_order α := ⟨λ a, ⟨a + 1, lt_add_of_pos_right _ one_pos⟩⟩ end strict_ordered_semiring section strict_ordered_comm_semiring variables [strict_ordered_comm_semiring α] /-- A choice-free version of `strict_ordered_comm_semiring.to_ordered_comm_semiring` to avoid using choice in basic `nat` lemmas. -/ @[reducible] -- See note [reducible non-instances] def strict_ordered_comm_semiring.to_ordered_comm_semiring' [@decidable_rel α (≤)] : ordered_comm_semiring α := { ..‹strict_ordered_comm_semiring α›, ..strict_ordered_semiring.to_ordered_semiring' } @[priority 100] -- see Note [lower instance priority] instance strict_ordered_comm_semiring.to_ordered_comm_semiring : ordered_comm_semiring α := { ..‹strict_ordered_comm_semiring α›, ..strict_ordered_semiring.to_ordered_semiring } end strict_ordered_comm_semiring section strict_ordered_ring variables [strict_ordered_ring α] {a b c : α} @[priority 100] -- see Note [lower instance priority] instance strict_ordered_ring.to_strict_ordered_semiring : strict_ordered_semiring α := { le_of_add_le_add_left := @le_of_add_le_add_left α _ _ _, mul_lt_mul_of_pos_left := λ a b c h hc, by simpa only [mul_sub, sub_pos] using strict_ordered_ring.mul_pos _ _ hc (sub_pos.2 h), mul_lt_mul_of_pos_right := λ a b c h hc, by simpa only [sub_mul, sub_pos] using strict_ordered_ring.mul_pos _ _ (sub_pos.2 h) hc, ..‹strict_ordered_ring α›, ..ring.to_semiring } /-- A choice-free version of `strict_ordered_ring.to_ordered_ring` to avoid using choice in basic `int` lemmas. -/ @[reducible] -- See note [reducible non-instances] def strict_ordered_ring.to_ordered_ring' [@decidable_rel α (≤)] : ordered_ring α := { mul_nonneg := λ a b ha hb, begin obtain ha | ha := decidable.eq_or_lt_of_le ha, { rw [←ha, zero_mul] }, obtain hb | hb := decidable.eq_or_lt_of_le hb, { rw [←hb, mul_zero] }, { exact (strict_ordered_ring.mul_pos _ _ ha hb).le } end, ..‹strict_ordered_ring α›, ..ring.to_semiring } @[priority 100] -- see Note [lower instance priority] instance strict_ordered_ring.to_ordered_ring : ordered_ring α := { mul_nonneg := λ a b, begin letI := @strict_ordered_ring.to_ordered_ring' α _ (classical.dec_rel _), exact mul_nonneg, end, ..‹strict_ordered_ring α› } lemma mul_lt_mul_of_neg_left (h : b < a) (hc : c < 0) : c * a < c * b := by simpa only [neg_mul, neg_lt_neg_iff] using mul_lt_mul_of_pos_left h (neg_pos_of_neg hc) lemma mul_lt_mul_of_neg_right (h : b < a) (hc : c < 0) : a * c < b * c := by simpa only [mul_neg, neg_lt_neg_iff] using mul_lt_mul_of_pos_right h (neg_pos_of_neg hc) lemma mul_pos_of_neg_of_neg {a b : α} (ha : a < 0) (hb : b < 0) : 0 < a * b := by simpa only [zero_mul] using mul_lt_mul_of_neg_right ha hb section monotone variables [preorder β] {f g : β → α} lemma strict_anti_mul_left {a : α} (ha : a < 0) : strict_anti ((*) a) := λ b c b_lt_c, mul_lt_mul_of_neg_left b_lt_c ha lemma strict_anti_mul_right {a : α} (ha : a < 0) : strict_anti (λ x, x * a) := λ b c b_lt_c, mul_lt_mul_of_neg_right b_lt_c ha lemma strict_mono.const_mul_of_neg (hf : strict_mono f) (ha : a < 0) : strict_anti (λ x, a * f x) := (strict_anti_mul_left ha).comp_strict_mono hf lemma strict_mono.mul_const_of_neg (hf : strict_mono f) (ha : a < 0) : strict_anti (λ x, f x * a) := (strict_anti_mul_right ha).comp_strict_mono hf lemma strict_anti.const_mul_of_neg (hf : strict_anti f) (ha : a < 0) : strict_mono (λ x, a * f x) := (strict_anti_mul_left ha).comp hf lemma strict_anti.mul_const_of_neg (hf : strict_anti f) (ha : a < 0) : strict_mono (λ x, f x * a) := (strict_anti_mul_right ha).comp hf end monotone end strict_ordered_ring section strict_ordered_comm_ring variables [strict_ordered_comm_ring α] /-- A choice-free version of `strict_ordered_comm_ring.to_ordered_comm_semiring'` to avoid using choice in basic `int` lemmas. -/ @[reducible] -- See note [reducible non-instances] def strict_ordered_comm_ring.to_ordered_comm_ring' [@decidable_rel α (≤)] : ordered_comm_ring α := { ..‹strict_ordered_comm_ring α›, ..strict_ordered_ring.to_ordered_ring' } @[priority 100] -- See note [lower instance priority] instance strict_ordered_comm_ring.to_strict_ordered_comm_semiring : strict_ordered_comm_semiring α := { ..‹strict_ordered_comm_ring α›, ..strict_ordered_ring.to_strict_ordered_semiring } @[priority 100] -- See note [lower instance priority] instance strict_ordered_comm_ring.to_ordered_comm_ring : ordered_comm_ring α := { ..‹strict_ordered_comm_ring α›, ..strict_ordered_ring.to_ordered_ring } end strict_ordered_comm_ring section linear_ordered_semiring variables [linear_ordered_semiring α] {a b c d : α} @[priority 200] -- see Note [lower instance priority] instance linear_ordered_semiring.to_pos_mul_reflect_lt : pos_mul_reflect_lt α := ⟨λ a b c, (monotone_mul_left_of_nonneg a.2).reflect_lt⟩ @[priority 200] -- see Note [lower instance priority] instance linear_ordered_semiring.to_mul_pos_reflect_lt : mul_pos_reflect_lt α := ⟨λ a b c, (monotone_mul_right_of_nonneg a.2).reflect_lt⟩ local attribute [instance] linear_ordered_semiring.decidable_le linear_ordered_semiring.decidable_lt lemma nonneg_and_nonneg_or_nonpos_and_nonpos_of_mul_nnonneg (hab : 0 ≤ a * b) : (0 ≤ a ∧ 0 ≤ b) ∨ (a ≤ 0 ∧ b ≤ 0) := begin refine decidable.or_iff_not_and_not.2 _, simp only [not_and, not_le], intros ab nab, apply not_lt_of_le hab _, rcases lt_trichotomy 0 a with (ha|rfl|ha), exacts [mul_neg_of_pos_of_neg ha (ab ha.le), ((ab le_rfl).asymm (nab le_rfl)).elim, mul_neg_of_neg_of_pos ha (nab ha.le)] end lemma nonneg_of_mul_nonneg_left (h : 0 ≤ a * b) (hb : 0 < b) : 0 ≤ a := le_of_not_gt $ λ ha, (mul_neg_of_neg_of_pos ha hb).not_le h lemma nonneg_of_mul_nonneg_right (h : 0 ≤ a * b) (ha : 0 < a) : 0 ≤ b := le_of_not_gt $ λ hb, (mul_neg_of_pos_of_neg ha hb).not_le h lemma neg_of_mul_neg_left (h : a * b < 0) (hb : 0 ≤ b) : a < 0 := lt_of_not_ge $ λ ha, (mul_nonneg ha hb).not_lt h lemma neg_of_mul_neg_right (h : a * b < 0) (ha : 0 ≤ a) : b < 0 := lt_of_not_ge $ λ hb, (mul_nonneg ha hb).not_lt h lemma nonpos_of_mul_nonpos_left (h : a * b ≤ 0) (hb : 0 < b) : a ≤ 0 := le_of_not_gt (assume ha : a > 0, (mul_pos ha hb).not_le h) lemma nonpos_of_mul_nonpos_right (h : a * b ≤ 0) (ha : 0 < a) : b ≤ 0 := le_of_not_gt (assume hb : b > 0, (mul_pos ha hb).not_le h) @[simp] lemma zero_le_mul_left (h : 0 < c) : 0 ≤ c * b ↔ 0 ≤ b := by { convert mul_le_mul_left h, simp } @[simp] lemma zero_le_mul_right (h : 0 < c) : 0 ≤ b * c ↔ 0 ≤ b := by { convert mul_le_mul_right h, simp } lemma add_le_mul_of_left_le_right (a2 : 2 ≤ a) (ab : a ≤ b) : a + b ≤ a * b := have 0 < b, from calc 0 < 2 : zero_lt_two ... ≤ a : a2 ... ≤ b : ab, calc a + b ≤ b + b : add_le_add_right ab b ... = 2 * b : (two_mul b).symm ... ≤ a * b : (mul_le_mul_right this).mpr a2 lemma add_le_mul_of_right_le_left (b2 : 2 ≤ b) (ba : b ≤ a) : a + b ≤ a * b := have 0 < a, from calc 0 < 2 : zero_lt_two ... ≤ b : b2 ... ≤ a : ba, calc a + b ≤ a + a : add_le_add_left ba a ... = a * 2 : (mul_two a).symm ... ≤ a * b : (mul_le_mul_left this).mpr b2 lemma add_le_mul (a2 : 2 ≤ a) (b2 : 2 ≤ b) : a + b ≤ a * b := if hab : a ≤ b then add_le_mul_of_left_le_right a2 hab else add_le_mul_of_right_le_left b2 (le_of_not_le hab) lemma add_le_mul' (a2 : 2 ≤ a) (b2 : 2 ≤ b) : a + b ≤ b * a := (le_of_eq (add_comm _ _)).trans (add_le_mul b2 a2) section @[simp] lemma bit0_le_bit0 : bit0 a ≤ bit0 b ↔ a ≤ b := by rw [bit0, bit0, ← two_mul, ← two_mul, mul_le_mul_left (zero_lt_two : 0 < (2:α))] @[simp] lemma bit0_lt_bit0 : bit0 a < bit0 b ↔ a < b := by rw [bit0, bit0, ← two_mul, ← two_mul, mul_lt_mul_left (zero_lt_two : 0 < (2:α))] @[simp] lemma bit1_le_bit1 : bit1 a ≤ bit1 b ↔ a ≤ b := (add_le_add_iff_right 1).trans bit0_le_bit0 @[simp] lemma bit1_lt_bit1 : bit1 a < bit1 b ↔ a < b := (add_lt_add_iff_right 1).trans bit0_lt_bit0 @[simp] lemma one_le_bit1 : (1 : α) ≤ bit1 a ↔ 0 ≤ a := by rw [bit1, le_add_iff_nonneg_left, bit0, ← two_mul, zero_le_mul_left (zero_lt_two : 0 < (2:α))] @[simp] lemma one_lt_bit1 : (1 : α) < bit1 a ↔ 0 < a := by rw [bit1, lt_add_iff_pos_left, bit0, ← two_mul, zero_lt_mul_left (zero_lt_two : 0 < (2:α))] @[simp] lemma zero_le_bit0 : (0 : α) ≤ bit0 a ↔ 0 ≤ a := by rw [bit0, ← two_mul, zero_le_mul_left (zero_lt_two : 0 < (2:α))] @[simp] lemma zero_lt_bit0 : (0 : α) < bit0 a ↔ 0 < a := by rw [bit0, ← two_mul, zero_lt_mul_left (zero_lt_two : 0 < (2:α))] end theorem mul_nonneg_iff_right_nonneg_of_pos (ha : 0 < a) : 0 ≤ a * b ↔ 0 ≤ b := ⟨λ h, nonneg_of_mul_nonneg_right h ha, mul_nonneg ha.le⟩ theorem mul_nonneg_iff_left_nonneg_of_pos (hb : 0 < b) : 0 ≤ a * b ↔ 0 ≤ a := ⟨λ h, nonneg_of_mul_nonneg_left h hb, λ h, mul_nonneg h hb.le⟩ lemma nonpos_of_mul_nonneg_left (h : 0 ≤ a * b) (hb : b < 0) : a ≤ 0 := le_of_not_gt (λ ha, absurd h (mul_neg_of_pos_of_neg ha hb).not_le) lemma nonpos_of_mul_nonneg_right (h : 0 ≤ a * b) (ha : a < 0) : b ≤ 0 := le_of_not_gt (λ hb, absurd h (mul_neg_of_neg_of_pos ha hb).not_le) @[simp] lemma units.inv_pos {u : αˣ} : (0 : α) < ↑u⁻¹ ↔ (0 : α) < u := have ∀ {u : αˣ}, (0 : α) < u → (0 : α) < ↑u⁻¹ := λ u h, (zero_lt_mul_left h).mp $ u.mul_inv.symm ▸ zero_lt_one, ⟨this, this⟩ @[simp] lemma units.inv_neg {u : αˣ} : ↑u⁻¹ < (0 : α) ↔ ↑u < (0 : α) := have ∀ {u : αˣ}, ↑u < (0 : α) → ↑u⁻¹ < (0 : α) := λ u h, neg_of_mul_pos_right (by exact (u.mul_inv.symm ▸ zero_lt_one)) h.le, ⟨this, this⟩ lemma cmp_mul_pos_left (ha : 0 < a) (b c : α) : cmp (a * b) (a * c) = cmp b c := (strict_mono_mul_left_of_pos ha).cmp_map_eq b c lemma cmp_mul_pos_right (ha : 0 < a) (b c : α) : cmp (b * a) (c * a) = cmp b c := (strict_mono_mul_right_of_pos ha).cmp_map_eq b c lemma mul_max_of_nonneg (b c : α) (ha : 0 ≤ a) : a * max b c = max (a * b) (a * c) := (monotone_mul_left_of_nonneg ha).map_max lemma mul_min_of_nonneg (b c : α) (ha : 0 ≤ a) : a * min b c = min (a * b) (a * c) := (monotone_mul_left_of_nonneg ha).map_min lemma max_mul_of_nonneg (a b : α) (hc : 0 ≤ c) : max a b * c = max (a * c) (b * c) := (monotone_mul_right_of_nonneg hc).map_max lemma min_mul_of_nonneg (a b : α) (hc : 0 ≤ c) : min a b * c = min (a * c) (b * c) := (monotone_mul_right_of_nonneg hc).map_min lemma le_of_mul_le_of_one_le {a b c : α} (h : a * c ≤ b) (hb : 0 ≤ b) (hc : 1 ≤ c) : a ≤ b := le_of_mul_le_mul_right (h.trans $ le_mul_of_one_le_right hb hc) $ zero_lt_one.trans_le hc lemma nonneg_le_nonneg_of_sq_le_sq {a b : α} (hb : 0 ≤ b) (h : a * a ≤ b * b) : a ≤ b := le_of_not_gt $ λ hab, (mul_self_lt_mul_self hb hab).not_le h lemma mul_self_le_mul_self_iff {a b : α} (h1 : 0 ≤ a) (h2 : 0 ≤ b) : a ≤ b ↔ a * a ≤ b * b := ⟨mul_self_le_mul_self h1, nonneg_le_nonneg_of_sq_le_sq h2⟩ lemma mul_self_lt_mul_self_iff {a b : α} (h1 : 0 ≤ a) (h2 : 0 ≤ b) : a < b ↔ a * a < b * b := ((@strict_mono_on_mul_self α _).lt_iff_lt h1 h2).symm lemma mul_self_inj {a b : α} (h1 : 0 ≤ a) (h2 : 0 ≤ b) : a * a = b * b ↔ a = b := (@strict_mono_on_mul_self α _).eq_iff_eq h1 h2 end linear_ordered_semiring @[priority 100] -- See note [lower instance priority] instance linear_ordered_comm_semiring.to_linear_ordered_cancel_add_comm_monoid [linear_ordered_comm_semiring α] : linear_ordered_cancel_add_comm_monoid α := { ..‹linear_ordered_comm_semiring α› } section linear_ordered_ring variables [linear_ordered_ring α] {a b c : α} local attribute [instance] linear_ordered_ring.decidable_le linear_ordered_ring.decidable_lt @[priority 100] -- see Note [lower instance priority] instance linear_ordered_ring.to_linear_ordered_semiring : linear_ordered_semiring α := { ..‹linear_ordered_ring α›, ..strict_ordered_ring.to_strict_ordered_semiring } @[priority 100] -- see Note [lower instance priority] instance linear_ordered_ring.to_linear_ordered_add_comm_group : linear_ordered_add_comm_group α := { ..‹linear_ordered_ring α› } @[priority 100] -- see Note [lower instance priority] instance linear_ordered_ring.no_zero_divisors : no_zero_divisors α := { eq_zero_or_eq_zero_of_mul_eq_zero := begin intros a b hab, refine decidable.or_iff_not_and_not.2 (λ h, _), revert hab, cases lt_or_gt_of_ne h.1 with ha ha; cases lt_or_gt_of_ne h.2 with hb hb, exacts [(mul_pos_of_neg_of_neg ha hb).ne.symm, (mul_neg_of_neg_of_pos ha hb).ne, (mul_neg_of_pos_of_neg ha hb).ne, (mul_pos ha hb).ne.symm] end, .. ‹linear_ordered_ring α› } @[priority 100] -- see Note [lower instance priority] --We don't want to import `algebra.ring.basic`, so we cannot use `no_zero_divisors.to_is_domain`. instance linear_ordered_ring.is_domain : is_domain α := { mul_left_cancel_of_ne_zero := λ a b c ha h, begin rw [← sub_eq_zero, ← mul_sub] at h, exact sub_eq_zero.1 ((eq_zero_or_eq_zero_of_mul_eq_zero h).resolve_left ha) end, mul_right_cancel_of_ne_zero := λ a b c hb h, begin rw [← sub_eq_zero, ← sub_mul] at h, exact sub_eq_zero.1 ((eq_zero_or_eq_zero_of_mul_eq_zero h).resolve_right hb) end, .. (infer_instance : nontrivial α) } lemma mul_pos_iff : 0 < a * b ↔ 0 < a ∧ 0 < b ∨ a < 0 ∧ b < 0 := ⟨pos_and_pos_or_neg_and_neg_of_mul_pos, λ h, h.elim (and_imp.2 mul_pos) (and_imp.2 mul_pos_of_neg_of_neg)⟩ lemma mul_neg_iff : a * b < 0 ↔ 0 < a ∧ b < 0 ∨ a < 0 ∧ 0 < b := by rw [← neg_pos, neg_mul_eq_mul_neg, mul_pos_iff, neg_pos, neg_lt_zero] lemma mul_nonneg_iff : 0 ≤ a * b ↔ 0 ≤ a ∧ 0 ≤ b ∨ a ≤ 0 ∧ b ≤ 0 := ⟨nonneg_and_nonneg_or_nonpos_and_nonpos_of_mul_nnonneg, λ h, h.elim (and_imp.2 mul_nonneg) (and_imp.2 mul_nonneg_of_nonpos_of_nonpos)⟩ /-- Out of three elements of a `linear_ordered_ring`, two must have the same sign. -/ lemma mul_nonneg_of_three (a b c : α) : 0 ≤ a * b ∨ 0 ≤ b * c ∨ 0 ≤ c * a := by iterate 3 { rw mul_nonneg_iff }; have := le_total 0 a; have := le_total 0 b; have := le_total 0 c; itauto lemma mul_nonpos_iff : a * b ≤ 0 ↔ 0 ≤ a ∧ b ≤ 0 ∨ a ≤ 0 ∧ 0 ≤ b := by rw [← neg_nonneg, neg_mul_eq_mul_neg, mul_nonneg_iff, neg_nonneg, neg_nonpos] lemma mul_self_nonneg (a : α) : 0 ≤ a * a := (le_total 0 a).elim (λ h, mul_nonneg h h) (λ h, mul_nonneg_of_nonpos_of_nonpos h h) @[simp] lemma neg_le_self_iff : -a ≤ a ↔ 0 ≤ a := by simp [neg_le_iff_add_nonneg, ← two_mul, mul_nonneg_iff, zero_le_one, (zero_lt_two' α).not_le] @[simp] lemma neg_lt_self_iff : -a < a ↔ 0 < a := by simp [neg_lt_iff_pos_add, ← two_mul, mul_pos_iff, zero_lt_one, (zero_lt_two' α).not_lt] @[simp] lemma le_neg_self_iff : a ≤ -a ↔ a ≤ 0 := calc a ≤ -a ↔ -(-a) ≤ -a : by rw neg_neg ... ↔ 0 ≤ -a : neg_le_self_iff ... ↔ a ≤ 0 : neg_nonneg @[simp] lemma lt_neg_self_iff : a < -a ↔ a < 0 := calc a < -a ↔ -(-a) < -a : by rw neg_neg ... ↔ 0 < -a : neg_lt_self_iff ... ↔ a < 0 : neg_pos lemma neg_one_lt_zero : -1 < (0:α) := neg_lt_zero.2 zero_lt_one @[simp] lemma mul_le_mul_left_of_neg {a b c : α} (h : c < 0) : c * a ≤ c * b ↔ b ≤ a := (strict_anti_mul_left h).le_iff_le @[simp] lemma mul_le_mul_right_of_neg {a b c : α} (h : c < 0) : a * c ≤ b * c ↔ b ≤ a := (strict_anti_mul_right h).le_iff_le @[simp] lemma mul_lt_mul_left_of_neg {a b c : α} (h : c < 0) : c * a < c * b ↔ b < a := (strict_anti_mul_left h).lt_iff_lt @[simp] lemma mul_lt_mul_right_of_neg {a b c : α} (h : c < 0) : a * c < b * c ↔ b < a := (strict_anti_mul_right h).lt_iff_lt lemma lt_of_mul_lt_mul_of_nonpos_left (h : c * a < c * b) (hc : c ≤ 0) : b < a := lt_of_mul_lt_mul_left (by rwa [neg_mul, neg_mul, neg_lt_neg_iff]) $ neg_nonneg.2 hc lemma lt_of_mul_lt_mul_of_nonpos_right (h : a * c < b * c) (hc : c ≤ 0) : b < a := lt_of_mul_lt_mul_right (by rwa [mul_neg, mul_neg, neg_lt_neg_iff]) $ neg_nonneg.2 hc lemma cmp_mul_neg_left {a : α} (ha : a < 0) (b c : α) : cmp (a * b) (a * c) = cmp c b := (strict_anti_mul_left ha).cmp_map_eq b c lemma cmp_mul_neg_right {a : α} (ha : a < 0) (b c : α) : cmp (b * a) (c * a) = cmp c b := (strict_anti_mul_right ha).cmp_map_eq b c lemma sub_one_lt (a : α) : a - 1 < a := sub_lt_iff_lt_add.2 (lt_add_one a) @[simp] lemma mul_self_pos {a : α} : 0 < a * a ↔ a ≠ 0 := begin split, { rintro h rfl, rw mul_zero at h, exact h.false }, { intro h, cases h.lt_or_lt with h h, exacts [mul_pos_of_neg_of_neg h h, mul_pos h h] } end lemma mul_self_le_mul_self_of_le_of_neg_le {x y : α} (h₁ : x ≤ y) (h₂ : -x ≤ y) : x * x ≤ y * y := (le_total 0 x).elim (λ h, mul_le_mul h₁ h₁ h (h.trans h₁)) (λ h, le_of_eq_of_le (neg_mul_neg x x).symm (mul_le_mul h₂ h₂ (neg_nonneg.mpr h) ((neg_nonneg.mpr h).trans h₂))) lemma nonneg_of_mul_nonpos_left {a b : α} (h : a * b ≤ 0) (hb : b < 0) : 0 ≤ a := le_of_not_gt (λ ha, absurd h (mul_pos_of_neg_of_neg ha hb).not_le) lemma nonneg_of_mul_nonpos_right {a b : α} (h : a * b ≤ 0) (ha : a < 0) : 0 ≤ b := le_of_not_gt (λ hb, absurd h (mul_pos_of_neg_of_neg ha hb).not_le) lemma pos_of_mul_neg_left {a b : α} (h : a * b < 0) (hb : b ≤ 0) : 0 < a := lt_of_not_ge (λ ha, absurd h (mul_nonneg_of_nonpos_of_nonpos ha hb).not_lt) lemma pos_of_mul_neg_right {a b : α} (h : a * b < 0) (ha : a ≤ 0) : 0 < b := lt_of_not_ge (λ hb, absurd h (mul_nonneg_of_nonpos_of_nonpos ha hb).not_lt) lemma neg_iff_pos_of_mul_neg (hab : a * b < 0) : a < 0 ↔ 0 < b := ⟨pos_of_mul_neg_right hab ∘ le_of_lt, neg_of_mul_neg_left hab ∘ le_of_lt⟩ lemma pos_iff_neg_of_mul_neg (hab : a * b < 0) : 0 < a ↔ b < 0 := ⟨neg_of_mul_neg_right hab ∘ le_of_lt, pos_of_mul_neg_left hab ∘ le_of_lt⟩ /-- The sum of two squares is zero iff both elements are zero. -/ lemma mul_self_add_mul_self_eq_zero {x y : α} : x * x + y * y = 0 ↔ x = 0 ∧ y = 0 := by rw [add_eq_zero_iff', mul_self_eq_zero, mul_self_eq_zero]; apply mul_self_nonneg lemma eq_zero_of_mul_self_add_mul_self_eq_zero (h : a * a + b * b = 0) : a = 0 := (mul_self_add_mul_self_eq_zero.mp h).left end linear_ordered_ring @[priority 100] -- see Note [lower instance priority] instance linear_ordered_comm_ring.to_strict_ordered_comm_ring [d : linear_ordered_comm_ring α] : strict_ordered_comm_ring α := { ..d } @[priority 100] -- see Note [lower instance priority] instance linear_ordered_comm_ring.to_linear_ordered_comm_semiring [d : linear_ordered_comm_ring α] : linear_ordered_comm_semiring α := { .. d, ..linear_ordered_ring.to_linear_ordered_semiring } section linear_ordered_comm_ring variables [linear_ordered_comm_ring α] {a b c d : α} lemma max_mul_mul_le_max_mul_max (b c : α) (ha : 0 ≤ a) (hd: 0 ≤ d) : max (a * b) (d * c) ≤ max a c * max d b := have ba : b * a ≤ max d b * max c a, from mul_le_mul (le_max_right d b) (le_max_right c a) ha (le_trans hd (le_max_left d b)), have cd : c * d ≤ max a c * max b d, from mul_le_mul (le_max_right a c) (le_max_right b d) hd (le_trans ha (le_max_left a c)), max_le (by simpa [mul_comm, max_comm] using ba) (by simpa [mul_comm, max_comm] using cd) end linear_ordered_comm_ring
The next step in the progression toward full blown deflation is emerging. Psychologists who treat the neurotic upper middle class are reporting widespread fee reductions in an attempt to maintain a client base. Even corporate lawyers whose own mothers are afraid to call them lest they be billed for the hours are shifting to offering clients discounted flat fee plans. Their mothers still get billed. The consumer price index has shown the first year to year decline since 1955 but prices can move up and down and not actually reflect inflation or deflation. The actual cost of things depends on real world events like the availability of oil. Of course the price of oil has everything to do with market manipulation and the criminality of that is another issue. Cut backs in things like eating out or not buying a new BMW creates job cuts but not deflation. But once people start cutting wages and especially service fees you can see that deflation is setting in. True inflation or deflation has to do with the management of money supply. To much debt creation is what causes inflation. When huge, unrealistic debt loads can no longer be maintained the money supply gets out of control and starts to collapse. This is deflation and is what defines a Great Depression. Deflation causes the collapse of the entire debt load since the reduction in cash flow makes paying interest and principle impossible. The cash flow crisis then spreads throughout the system dragging down people and businesses who aren’t in debt as well. So you see, lawyers are like the canary in the coal mine or the shark in the fish tank (well you get the idea). Money needs to be injected into the system from the bottom, not the top. It has to be used to create an actual economy and not just more paper on a bank balance sheet. If enough lawyers can’t make the payments on their Mercedes we might get some action.
[STATEMENT] lemma distinct_no_loop2: "\<lbrakk> distinct(vertices f); v \<in> \<V> f; u \<in> \<V> f; u \<noteq> v \<rbrakk> \<Longrightarrow> f \<bullet> v \<noteq> v" [PROOF STATE] proof (prove) goal (1 subgoal): 1. \<lbrakk>distinct (vertices f); v \<in> \<V> f; u \<in> \<V> f; u \<noteq> v\<rbrakk> \<Longrightarrow> f \<bullet> v \<noteq> v [PROOF STEP] apply(frule split_list[of v]) [PROOF STATE] proof (prove) goal (1 subgoal): 1. \<lbrakk>distinct (vertices f); v \<in> \<V> f; u \<in> \<V> f; u \<noteq> v; \<exists>ys zs. vertices f = ys @ v # zs\<rbrakk> \<Longrightarrow> f \<bullet> v \<noteq> v [PROOF STEP] apply(clarsimp simp: nextVertex_def neq_Nil_conv hd_append split:list.splits if_split_asm) [PROOF STATE] proof (prove) goal: No subgoals! [PROOF STEP] done
The assignment is to use the \textbf{Game of Life}(GOL) \footnote{See \cite{gol-wiki} and the references therein. Try playing it at \href{https://playgameoflife.com/}{playgameoflife.com}} as the basis for exploring parallel programming. This document contains: \begin{enumerate} \item[\S\ref{sec:gol}:] An overview of the Game-of-Life. If familiar with GOL, please continue to \S\ref{sec:code}. \item[\S\ref{sec:code}:] An overview of the code repository. \item[\S\ref{sec:tasks}:] The assessable tasks. \end{enumerate} \section{Game of Life}\label{sec:gol} The Game of Life is a cellular automaton devised by the British mathematician John Horton Conway in 1970\cite{gol}. It is a zero-player game, with the game's evolution determined completely by its initial state. A player interacts by creating an initial configuration and observing how it evolves. The game is simple: there is a 2D grid where each cell in the grid can either be alive or dead at any one time. The state of the system at the next time step is determined from the number of nearest neighbours each cell has at the present time (see Fig.\ref{fig:gol}). The evolution of the grid resembles cells moving on a plane. \begin{figure}[!h] \centering \fbox{\includegraphics[width=0.2\textwidth, valign=c]{figs/GOL.grid-500-by-500.step-0010.png}} \fbox{\includegraphics[width=0.2\textwidth, valign=c]{figs/GOL.grid-500-by-500.step-0019.png}} \includegraphics[width=0.1\textwidth, valign=B]{figs/neighbour} \caption{The Game of Life. An example of a large grid at two different times (separated by 9 steps) is shown in the left and middle panels. Here live cells are in black, dead are white. The evolution of the grid is governed by the birth and death of cells, where a cell's state is defined by its 8 neighbouring cells (right panel).} \label{fig:gol} \end{figure} \par The rules for evolving a system to the next time level are as follows: \begin{itemize} \item {\color{ForestGreen}new cell born} if the cell has exactly three live neighbours - \textbf{\color{ForestGreen} ready to breed}. \item {\color{CornflowerBlue}state of cell unchanged} if the cell has exactly two live neighbours - \textbf{\color{CornflowerBlue}content}. \item {\color{Red}dies or stays dead} if the cell has $<2$ live neighbours - \textbf{\color{Red}lonely}. \item {\color{Red}dies or stays dead} if the cell has $>3$ live neighbours - \textbf{\color{Red}overcrowding}. \end{itemize} \par These rules are set so as to generate an equilibrium between living and dead cells. One can explore how altering the rules can affect the evolution of the system. To lax a {\color{ForestGreen} ready to bread} rule coupled with large amounts of {\color{Red}overcrowding allowed} can give rise to grids that quickly fill up with cells only to collapse entirely. \subsection{The ``Life'' in GOL} Using this fairly simple set of rules, some fairly complex structures can emerge\footnote{a nice list of types of structures is found on \href{https://en.wikipedia.org/wiki/Conway\%27s_Game_of_Life}{Wikipedia}}. The game is in fact Turing complete and can simulate a universal constructor or any other Turing machine. We highlight some common structures found in a typical game in Fig.\ref{fig:gol-structures}. \begin{figure}[!h] \centering \includegraphics[height=0.06\textwidth, valign=c]{figs/Game_of_life_loaf.png} \includegraphics[height=0.17\textwidth, valign=c]{figs/Game_of_life_pulsar.png} \includegraphics[height=0.06\textwidth, valign=c]{figs/Game_of_life_animated_glider.png} \includegraphics[height=0.11\textwidth, valign=c]{figs/Game_of_life_glider_gun.svg.png} \caption{Structures in GOL: We show an example of still life (left); oscillating life (middle); travelling life, so-called spaceships (right); and a constructor that generates gilder spaceships (bottom).} \label{fig:gol-structures} \end{figure} GOL may appear chaotic and can remain chaotic for long periods of time (even indefinitely) before settling into a combination of still lifes, oscillators, and spaceships. GOL is in fact undecidable, that is given an initial pattern and a later pattern, no algorithm exists that can tell whether the later pattern is ever going to appear using this IC. This is a corollary of the halting problem: the problem of determining whether a given program will finish running or continue to run forever from an initial input. \par The undecidability of the game depends on the rules and the dimensionality of the grid. For instance, increasing the dimension from 2 to 3 means that the rule for equilibrium goes from 2 neighbours out of 8 to 2 out of 26. You can try exploring the impact rules have on the game using the provided code repository discussed in the following section. \subsection{Grid-based simulations} \label{sec:gol:gridsims} At a basic level, \textbf{GOL} is a simulation of the temporal evolution of a 2-D grid. The rules governing the "life" can be arbitrarily complex and the grid need not be just two dimensional. If one changes a cell from just being alive or dead to having a complex internal state, increases the complexity of the rules and adds one more dimension, \textit{you would have gone from GOL to any number of grid-based codes that are used to model physical processes}. This simple grid-based program should be viewed as the first step in writing more complex grid-based codes. \par As an example, ENZO (\cite{enzo}, repository is located \href{https://github.com/enzo-project/enzo-dev}{here}) is a Adaptive Mesh Refinement (AMR) code using Cartesian coordinates which can be run in one, two, and three dimensions, and supports a wide variety of physics including hydrodynamics, ideal and non-ideal magnetohydrodynamics. GOL would be equivalent to running ENZO in two dimensions where the "fluid" moves on the 2-D surface based on highly simplified equations. \section{Code Repository}\label{sec:code} The code that forms the basis of the assignment is found on the course website. This repository contains the following \begin{itemize} \item basic files like a README, License \item \texttt{Makefile} setup to compile codes with a variety of different flags and features. For a quick tutorial on GNU Make, see \href{https://www.gnu.org/software/make/}{here}. Students are expected to be familiar with Make and the associated commands. Please familiarise yourself with this material. \item Source code in \texttt{src/*c} (\texttt{C/C++}) and \texttt{src/*f90} (\texttt{Fortran}). We expect students to be familiar with \texttt{C/C++} and/or \texttt{Fortran}. All the source code provided is written in \texttt{C} and \texttt{Fortran}. Fortran source codes are noted by having \texttt{\_fort.f90} endings. Please feel free to change the make file to use a \texttt{C++} compiler when compiling the c codes and use C++ syntax if you so desire. \item documentation and \LaTeX\ source code in \texttt{docs} \item a script to produce movies from png files when visualising with the PNG library. \end{itemize} To familiarise yourself with the contents you can see what make options are available and browse the source directory. \begin{center} \begin{minipage}{0.95\textwidth} \small \begin{minted}[frame=single,]{sh} make allinfo # provides all the information of the commands listed below make configinfo # provides the different options available make makecommands # what you can make by typing these commands make buildinfo # current compilers used \end{minted} \end{minipage} \end{center} You'll note that the make file is setup to accept command line arguments that can set compiler families such as \texttt{GCC}, \texttt{CRAY} when you type \texttt{make configinfo}. Try the following \begin{center} \begin{minipage}{0.95\textwidth} \small \begin{minted}[frame=single,]{sh} # use the GNU CC family of compilers, gcc, g++, & gfortran AND # compile the serial version of the code, both C and Fortran sources. make COMPILERTYPE=GCC cpu_serial # use the intel family of compilers and compile the openmp source codes (if present) make COMPILERTYPE=INTEL cpu_openmp # use Cray compilers (useful for systems like magnus) and just compile the C sources make COMPILERTYPE=CRAY cpu_openmp_cc \end{minted} \end{minipage} \end{center} Note that the code does require recent compilers so on machines such as zeus make sure to load a recent gcc compiler using commands such as \texttt{module swap gcc gcc/8.3.0}) \subsection{Source} The common function calls with interface is provided in \texttt{src/common.*}, provide functions like visualising GOL, getting timing information, etc. We recommend students have a look at the prototypes in \texttt{src/common.h}. The key functions are: \begin{center} \begin{minipage}{0.95\textwidth} \small \begin{minted}[frame=single,]{c} /// visualise the game of life void visualise(enum VisualiseType ivisualisechoice, int step, int *grid, int n, int m); /// generate IC void generate_IC(enum ICType ic_choice, int *grid, int n, int m); /// UI void getinput(int argc, char **argv, struct Options *opt); ///GOL stats protoype void game_of_life_stats(struct Options *opt, int steps, int *current_grid); /// GOL prototype void game_of_life(struct Options *opt, int *current_grid, int *next_grid, int n, int m); \end{minted} \end{minipage} \end{center} The \texttt{Fortran} source of \texttt{src/common\_fort.f90} provides a module with the same set of interfaces and subroutines. \begin{center} \begin{minipage}{0.95\textwidth} \small \begin{minted}[frame=single,]{fortran} module gol_common ! ascii visualisation subroutine visualise_ascii(step, grid, n, m) ! png visualisation subroutine visualise_png(step, grid, n, m) ! no visualisation subroutine visualise_none() ! visualisation routine subroutine visualise(ivisualisechoice, step, grid, n, m) ! generate random IC subroutine generate_rand_IC(grid, n, m) ! generate IC subroutine generate_IC(ic_choice, grid, n, m) ! UI subroutine getinput(opt) ! get some basic timing info real*8 function init_time() ! get the elapsed time relative to start subroutine get_elapsed_time(start) end module \end{minted} \end{minipage} \end{center} The main program consists of (here we just highlight the \texttt{C} source as the \texttt{Fortran} source is similar): \begin{center} \begin{minipage}{0.95\textwidth} \begin{minted}[frame=single,]{c} int main(int argc, char **argv) { struct Options *opt = (struct Options *) malloc(sizeof(struct Options)); getinput(argc, argv, opt); // allocate some memory ... // generate initial conditions generate_IC(opt->iictype, grid, n, m); // start GOL while loopt while(current_step != opt->nsteps){ visualise(opt->ivisualisetype, current_step, grid, n, m); game_of_life_stats(opt, current_step, grid); game_of_life(opt, grid, updated_grid, n, m); // swap current and updated grid tmp = grid; grid = updated_grid; updated_grid = tmp; current_step++; } // free mem ... } \end{minted} \begin{comment} \begin{minted}{fortran} ! Fortran code program GameOfLife use gol_common implicit none ... ! get input call getinput(opt) ! allocate some mem ... ! generate IC call generate_IC(opt%iictype, grid, n, m) do while (current_step .ne. nsteps) call visualise(opt%ivisualisetype, current_step, grid, n, m); call game_of_life_stats(opt, current_step, grid); call game_of_life(opt, grid, updated_grid, n, m); ! update current grid grid(:,:) = updated_grid(:,:) current_step = current_step + 1 end do ! deallocate mem .. end program GameOfLife \end{minted} \end{comment} \end{minipage} \end{center} Implementations of the {\color{blue}\texttt{game\_of\_life}} and {\color{blue}\texttt{game\_of\_life\_stats}} functions can be found in \texttt{src/01\_cpu\_serial.c} (\& \texttt{src/01\_cpu\_serial\_fort.f90}). Familiarise yourself with these functions (based on your language of choice). \par Running the code is relatively simple. \begin{center} \begin{minipage}{0.95\textwidth} \small \begin{minted}[frame=single,]{sh} make cpu_serial ./bin/01_cpu_serial "Usage: ./bin/01_gol_cpu_serial <grid height> <grid width> " "[<nsteps> <IC type> <Visualisation type> <Rule type> <Neighbour type>" "<Boundary type> <stats filename>]" ./bin/01_cpu_serial 500 500 4 # run a 500x500 grid for 4 steps giving \end{minted} \fbox{\includegraphics[width=0.2\textwidth, valign=c]{figs/GOL.grid-500-by-500.step-0000.png}} \fbox{\includegraphics[width=0.2\textwidth, valign=c]{figs/GOL.grid-500-by-500.step-0001.png}} \fbox{\includegraphics[width=0.2\textwidth, valign=c]{figs/GOL.grid-500-by-500.step-0002.png}} \fbox{\includegraphics[width=0.2\textwidth, valign=c]{figs/GOL.grid-500-by-500.step-0003.png}} \\ PNG Visualisation of output from GOL. FIlled black squares are living cells. \end{minipage} \end{center} \subsection{Expanded Rules} Although not required for the assignment, you can alter the rules of the game, changing the number of neighbours that decide certain states, even expand the number of neighbours used and change the boundary conditions. A sample of the serial code structured to easily alter the rules for the game is \texttt{src/01\_gol\_serial\_expanded.c}. \par This particular version of the code is an excellent start point for implementing far more complex rules, such as those governing the flow of a fluid or the diffusion of a gas across a surface.
Require Import Crypto.Arithmetic.PrimeFieldTheorems. Require Import Crypto.Specific.solinas64_2e256m189_6limbs.Synthesis. (* TODO : change this to field once field isomorphism happens *) Definition carry : { carry : feBW_loose -> feBW_tight | forall a, phiBW_tight (carry a) = (phiBW_loose a) }. Proof. Set Ltac Profiling. Time synthesize_carry (). Show Ltac Profile. Time Defined. Print Assumptions carry.
module Js.Electron.Window import Control.Monad.Syntax import Data.Foldable.Extras import Js import Js.Object %default total %access export public export record Options where constructor MkOptions title, url : Maybe String width, height : Maybe Nat fullscreen, frame : Bool defaults : Lazy Options defaults = MkOptions Nothing Nothing Nothing Nothing False True public export data Window = MkWindow Ptr Class Window where ptr (MkWindow p) = p close : Window -> JS_IO () close = js "%0.close()" (Ptr -> JS_IO ()) . ptr setTitle : String -> Window -> JS_IO () setTitle title = js "%1.setTitle(%0)" (String -> Ptr -> JS_IO ()) title . ptr loadURL : String -> Window -> JS_IO () loadURL url = js "%1.loadURL(%0)" (String -> Ptr -> JS_IO ()) url . ptr setPosition : Nat -> Nat -> Window -> JS_IO () setPosition x y = js "%2.setPosition(%0, %1)" (Int -> Int -> Ptr -> JS_IO ()) (cast x) (cast y) . ptr centre : Window -> JS_IO () centre = js "%0.center()" (Ptr -> JS_IO ()) . ptr on : String -> JS_IO () -> Window -> JS_IO () on event func = assert_total $ js "(%2).on(%0, %1)" (String -> JsFn (() -> JS_IO ()) -> Ptr -> JS_IO ()) event (MkJsFn $ const func) . ptr onClosed : JS_IO () -> Window -> JS_IO () onClosed = on "closed" create : Options -> JS_IO Window create (MkOptions title url width height fullscreen frame) = do options <- empty iter (flip (set "title") options) title iter (flip (set "width") options) width iter (flip (set "height") options) height set "fullscreen" fullscreen options set "frame" frame options win <- MkWindow <$> js "new electron.BrowserWindow(%0)" (Ptr -> JS_IO Ptr) (ptr options) iter (flip loadURL win) url pure win
set.seed(666) true.mu <- -.1 true.sigma <- .001 N_0 <- 50 y_0 <- rnorm(N_0, mean = true.mu, sd = true.sigma) mu_0 <- 0 kappa_0 <- 5 alpha_0 <- 1 beta_0 <- 1 copy <- FALSE if(copy){ N <- N_0 y <- y_0 }else{ N <- 200 y <- rnorm(N, mean = true.mu, sd = true.sigma) } nu <- 1 eta <- 1
Formal statement is: proposition separate_point_closed: fixes s :: "'a::heine_borel set" assumes "closed s" and "a \<notin> s" shows "\<exists>d>0. \<forall>x\<in>s. d \<le> dist a x" Informal statement is: If $s$ is a closed set and $a \notin s$, then there exists a positive real number $d$ such that for all $x \in s$, we have $d \leq |a - x|$.
module TypesAndFunctions import Data.List import Data.Strings import Data.Vect %default total -- data types data MyNat = MZ | MS MyNat mynat2int : MyNat -> Int mynat2int MZ = 0 mynat2int (MS n) = 1 + mynat2int n partial int2mynat : Int -> MyNat int2mynat 0 = MZ int2mynat n = MS (int2mynat (n - 1)) plus : MyNat -> MyNat -> MyNat plus MZ m = m plus (MS n) m = MS (plus n m) mult : MyNat -> MyNat -> MyNat mult MZ _ = MZ mult (MS n) m = plus m (mult n m) infixr 10 :: data MyList a = Nil | (::) a (MyList a) Show a => Show (MyList a) where show Nil = "Nil" show (x :: xs) = "(Cons " ++ show x ++ " " ++ show xs ++ ")" len : MyList a -> Nat len Nil = Z len (_ :: xs) = S (len xs) fromList : List a -> MyList a fromList [] = Nil fromList (x :: xs) = (::) x (fromList xs) -- where clauses myReverse : List a -> List a myReverse xs = aux xs [] where aux : List a -> List a -> List a aux [] acc = acc aux (x :: xs) acc = aux xs (x :: acc) -- till https://github.com/idris-lang/Idris2/issues/588 is fixed, this -- definition has to be in the top-level data MyLT = Yes | No foo : Int -> Int foo x = case isLT of Yes => x * 2 No => x * 4 where isLT : MyLT isLT = if x < 10 then Yes else No even : Nat -> Bool even Z = True even (S k) = odd k where odd : Nat -> Bool odd Z = False odd (S k) = even k test : List Nat test = [c (S 1), c Z, d (S Z)] where c : Nat -> Nat c x = 42 + x d : Nat -> Nat d y = c (y + 1 + z y) where z : Nat -> Nat z w = y + w -- totality and covering partial from : Maybe a -> a from (Just x) = x -- dependent types isSingleton : Bool -> Type isSingleton False = List Nat isSingleton True = Nat mkSingle : (x : Bool) -> isSingleton x mkSingle False = [] mkSingle True = 0 mysum : (single : Bool) -> isSingleton single -> Nat mysum False [] = 0 mysum False (n :: ns) = n + mysum False ns mysum True d = d -- declaration order and mutual blocks mutual myeven : Nat -> Bool myeven Z = True myeven (S k) = myodd k myodd : Nat -> Bool myodd Z = False myodd (S k) = myeven k greet : HasIO io => io () greet = do putStr "What is your name? " name <- getLine putStrLn $ "Nice to meet you, " ++ name -- laziness {- data Lazy : Type -> Type where Delay : (val : a) -> Lazy a Force : Lazy a -> a -} myIfThenElse : Bool -> Lazy a -> Lazy a -> a myIfThenElse True t e = t myIfThenElse False t e = e -- infinite data types (codata) {- data Stream : Type -> Type where (::) : (e : a) -> Inf (Stream a) -> Stream a -} ones : Stream Nat ones = 1 :: ones -- useful data types {- data List a = Nil | (::) a (List a) data Vect : Nat -> Type -> Type where Nil : Vect Z a (::) : a -> Vect k a -> Vect (S k) a -} {- map : (a -> b) -> List a -> List b map _ [] = [] map f (x :: xs) = f x :: map f xs map : (a -> b) -> Vect n a -> Vect n b map _ [] = [] map f (x :: xs) = f x :: map f xs -} intVec : Vect 5 Int intVec = [1, 2, 3, 4, 5] double : Int -> Int double x = x + x listLookup : Nat -> List a -> Maybe a listLookup _ [] = Nothing listLookup Z (x :: _) = Just x listLookup (S k) (_ :: xs) = listLookup k xs -- tuples {- data Pair : Type -> Type -> Type where MkPair : a -> b -> Pair a b -} fred : (String, Nat) fred = ("Fred", 42) jim : (String, Int, String) jim = ("Jim", 25, "Cambridge") -- dependent pairs (Signma Types) {- data DPair : (a : Type) -> (p : a -> Type) -> Type where MkDPair : {p : a -> Type} -> (x : a) -> p x -> DPair a p -} data DepPair : (a : Type) -> (p : a -> Type) -> Type where MkDepPair : { p : a -> Type } -> (x : a) -> p x -> DepPair a p vec : (n : Nat ** Vect n Int) vec = (3 ** [1, 2, 3]) vec1 : DPair Nat (\n => Vect n Int) vec1 = MkDPair 3 [1, 2, 3] vec2 : DepPair Nat (\n => Vect n Int) vec2 = MkDepPair 3 [1, 2, 3] vec3 : (n : Nat ** Vect n String) vec3 = (_ ** ["Hello", "world"]) vec4 : (n ** Vect n Double) vec4 = (_ ** [1.0, 2.2, -2.1212]) vFilter : (a -> Bool) -> Vect n a -> (p : Nat ** Vect p a) vFilter p [] = (0 ** []) vFilter p (x :: xs) = case p x of False => vFilter p xs True => let (_ ** res) = vFilter p xs in (_ ** (x :: res)) -- let bindings mirror : List a -> List a mirror xs = let xs' = reverse xs in xs ++ xs' data Person = MkPerson String Int showPerson : Person -> String showPerson p = let MkPerson name age = p in name ++ " is " ++ show age ++ " years old" -- list comprehensions pythag : Int -> List (Int, Int, Int) pythag n = [(x, y, z) | z <- [1..n], y <- [1..z], x <- [1..y], x * x + y * y == z * z] -- case expressions partial mySplitAt : Char -> String -> (String, String) mySplitAt c cs = case break (== c) cs of (h, t) => (h, strTail t)
lemma diff_absorb2: "g \<in> o[F](f) \<Longrightarrow> L F (\<lambda>x. f x - g x) = L F (f)"
/- Copyright (c) 2017 Microsoft Corporation. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Leonardo de Moura -/ import Mathlib.PrePort import Mathlib.Lean3Lib.init.meta.default import Mathlib.Lean3Lib.init.data.sigma.lex import Mathlib.Lean3Lib.init.data.nat.lemmas import Mathlib.Lean3Lib.init.data.list.instances import Mathlib.Lean3Lib.init.data.list.qsort universes u v namespace Mathlib /- TODO(Leo): move this lemma, or delete it after we add algebraic normalizer. -/ theorem nat.lt_add_of_zero_lt_left (a : ℕ) (b : ℕ) (h : 0 < b) : a < a + b := (fun (this : a + 0 < a + b) => this) (nat.add_lt_add_left h a) /- TODO(Leo): move this lemma, or delete it after we add algebraic normalizer. -/ theorem nat.zero_lt_one_add (a : ℕ) : 0 < 1 + a := sorry /- TODO(Leo): move this lemma, or delete it after we add algebraic normalizer. -/ theorem nat.lt_add_right (a : ℕ) (b : ℕ) (c : ℕ) : a < b → a < b + c := fun (h : a < b) => lt_of_lt_of_le h (nat.le_add_right b c) /- TODO(Leo): move this lemma, or delete it after we add algebraic normalizer. -/ theorem nat.lt_add_left (a : ℕ) (b : ℕ) (c : ℕ) : a < b → a < c + b := fun (h : a < b) => lt_of_lt_of_le h (nat.le_add_left b c) protected def psum.alt.sizeof {α : Type u} {β : Type v} [SizeOf α] [SizeOf β] : psum α β → ℕ := sorry protected def psum.has_sizeof_alt (α : Type u) (β : Type v) [SizeOf α] [SizeOf β] : SizeOf (psum α β) := { sizeOf := psum.alt.sizeof } end Mathlib
# ЛР №6 # Интерполяция таблично заданных функций ## В8 ```python X = [0.015, 0.681, 1.342, 2.118, 2.671] Y = [-2.417, -3.819, -0.642, 0.848, 2.815] ``` ```python import sympy as sp import numpy as np import matplotlib.pyplot as plt from functools import reduce from tabulate import tabulate ``` ## 1 Построить интерполяционный многочлен Лагранжа. Вычислить $L_4(x_1+x_2)$. Построить график многочлена Лагранжа. ```python def lagrange(n: int): x = sp.Symbol('x') def p(i): res = reduce(lambda m, n: m * n, ((x - X[j])/(X[i] - X[j]) for j in range(len(X)) if i != j)) return res return sp.simplify(sum(p(i) * Y[i] for i in range(n))) ``` ```python print('L(x) =', lagrange(len(X))) print('L4(x1 + x2) =', lagrange(4).subs('x', X[0] + X[1])) x_l = np.linspace(min(X), max(X), 50) y_lag = [lagrange(len(X)).subs({'x': i}) for i in x_l] plt.title("Интерполяционный многочлен Лагранжа") plt.plot(x_l, y_lag, color='black') plt.plot(X, Y, 'o', color='red') plt.grid(True) plt.show() ``` ## 2 Построить таблицы конечных и разделенных разностей. ```python def finite_diffs(): d = [['' for i in range(len(Y))] for j in range(len(Y))] d[0] = [i for i in Y] for i in range(1, len(Y)): for j in range(len(Y) - i): d[i][j] = d[i - 1][j + 1] - d[i - 1][j] return d def divided_diffs(): d = [['' for i in range(len(X))] for j in range(len(X))] d[0] = [i for i in Y] for i in range(1, len(Y)): for j in range(len(Y) - i): d[i][j] = (d[i - 1][j + 1] - d[i - 1][j]) / (X[j + i] - X[j]) return d ``` ```python f_diffs = finite_diffs() f_diffs.insert(0, X) table = [list(item) for item in zip(*f_diffs)] print("\nКонечные разности\n") print(tabulate(table, headers=['xk', 'yk', 'd1', 'd2', 'd3', 'd4'], tablefmt='fancy_grid')) ``` Конечные разности ╒═══════╤════════╤═════════════════════╤════════════════════╤════════════════════╤═══════════════════╕ │ xk │ yk │ d1 │ d2 │ d3 │ d4 │ ╞═══════╪════════╪═════════════════════╪════════════════════╪════════════════════╪═══════════════════╡ │ 0.015 │ -2.417 │ -1.4020000000000001 │ 4.579000000000001 │ -6.266000000000001 │ 8.430000000000001 │ ├───────┼────────┼─────────────────────┼────────────────────┼────────────────────┼───────────────────┤ │ 0.681 │ -3.819 │ 3.177 │ -1.687 │ 2.164 │ │ ├───────┼────────┼─────────────────────┼────────────────────┼────────────────────┼───────────────────┤ │ 1.342 │ -0.642 │ 1.49 │ 0.4770000000000001 │ │ │ ├───────┼────────┼─────────────────────┼────────────────────┼────────────────────┼───────────────────┤ │ 2.118 │ 0.848 │ 1.967 │ │ │ │ ├───────┼────────┼─────────────────────┼────────────────────┼────────────────────┼───────────────────┤ │ 2.671 │ 2.815 │ │ │ │ │ ╘═══════╧════════╧═════════════════════╧════════════════════╧════════════════════╧═══════════════════╛ ```python d_diffs = divided_diffs() d_diffs.insert(0, X) table = [list(item) for item in zip(*d_diffs)] print("\nРазделенные разности\n") print(tabulate(table, headers=['xk', 'yk', 'f1', 'f2', 'f3', 'f4'], tablefmt='fancy_grid')) ``` Разделенные разности ╒═══════╤════════╤════════════════════╤═════════════════════╤════════════════════╤═══════════════════╕ │ xk │ yk │ f1 │ f2 │ f3 │ f4 │ ╞═══════╪════════╪════════════════════╪═════════════════════╪════════════════════╪═══════════════════╡ │ 0.015 │ -2.417 │ -2.105105105105105 │ 5.208333921765079 │ -3.431697224752018 │ 1.905092077757894 │ ├───────┼────────┼────────────────────┼─────────────────────┼────────────────────┼───────────────────┤ │ 0.681 │ -3.819 │ 4.806354009077156 │ -2.0085253418884137 │ 1.6282273337729478 │ │ ├───────┼────────┼────────────────────┼─────────────────────┼────────────────────┼───────────────────┤ │ 1.342 │ -0.642 │ 1.9201030927835057 │ 1.2316470523197525 │ │ │ ├───────┼────────┼────────────────────┼─────────────────────┼────────────────────┼───────────────────┤ │ 2.118 │ 0.848 │ 3.5569620253164564 │ │ │ │ ├───────┼────────┼────────────────────┼─────────────────────┼────────────────────┼───────────────────┤ │ 2.671 │ 2.815 │ │ │ │ │ ╘═══════╧════════╧════════════════════╧═════════════════════╧════════════════════╧═══════════════════╛ ## 3 Построить полином Ньютона и вычислить значение $N_4(x_1+x_2)$. Построить график многочлена Ньютона. ```python def newton(n: int): x = sp.Symbol('x') diffs = divided_diffs() def gen(): mul = 1 for i in range(n): yield diffs[i][0] * mul mul *= x - X[i] return sp.simplify(reduce(lambda x, y: x + y, (i for i in gen()))) ``` ```python print('N(x) =', newton(len(X))) print('N4(x1 + x2) =', newton(4).subs('x', X[0] + X[1])) y_nw = [newton(len(X)).subs({'x': i}) for i in x_l] plt.title("Полином Ньютона") plt.plot(x_l, y_nw, color='black') plt.plot(X, Y, 'o', color='red') plt.grid(True) plt.show() ``` ## 4 Построить интерполяционные сплайны кусочно-линейный и кусочно-квадратичный. Построить графики сплайнов. ```python def linear_spline(): x = sp.Symbol('x') l_splines = [] for i in range(1, len(X)): res = Y[i-1] + (Y[i] - Y[i-1]) * (x - X[i-1]) / (X[i] - X[i-1]) l_splines.append(sp.simplify(res)) return l_splines ``` ```python print('F(x) =', ', '.join(map(str, linear_spline()))) pre_y = linear_spline() y_liner = [] for k in range(1, len(X)): y_liner.extend([pre_y[k-1].subs({'x': j}) for j in x_l if j <= X[k] and j >= X[k-1]]) plt.title("Кусочно-линейный сплайн") plt.plot(x_l, y_liner, color='black') plt.plot(X, Y, 'o', color='red') plt.grid(True) plt.show() ``` ```python def qdr_spline(): x = sp.Symbol('x') q_splines = [] for i in range(2, len(X), 2): a2 = (Y[i] - Y[i - 2])/((X[i] - X[i - 2]) * (X[i] - X[i - 1])) - \ (Y[i - 1] - Y[i - 2])/((X[i - 1] - X[i - 2]) * (X[i] - X[i - 1])) a1 = (Y[i - 1] - Y[i - 2])/(X[i - 1] - X[i - 2]) - \ a2 * (X[i - 1] + X[i - 2]) a0 = Y[i - 2] - a1*X[i - 2] - a2*X[i - 2]**2 q_splines.append(a0 + a1*x + a2*x**2) return q_splines ``` ```python print('F(x) =', ', '.join(map(str, qdr_spline()))) pre_y = qdr_spline() y_qdr = [] for m in x_l: for k in range(2, len(X), 2): if m <= X[k]: y_qdr.append(pre_y[k // 2 - 1].subs({'x': m})) break plt.title("Кусочно-квадратичный сплайн") plt.plot(x_l, y_qdr, color='black') plt.plot(X, Y, 'o', color='red') plt.grid(True) plt.show() ``` ## 5 Построить кубический интерполяционный сплайн. Построить график. ```python def cub_spline(): x = sp.symbols('x') n = len(X) - 1 c_h = [a - b for a, b in zip(X[1:], X[:-1])] c_l = [(a - b) / c for a, b, c in zip(Y[1:], Y[:-1], c_h)] alt_js = [-0.5 * c_h[1] / (c_h[0] + c_h[1])] lamds = [1.5 * (c_l[1] - c_l[0]) / (c_h[0] + c_h[1])] for i in range(2, n): alt_js.append(c_h[i] / (2 * c_h[i] + 2 * c_h[i - 1] + c_h[i - 1] * alt_js[i - 2])) lamds.append((2 * c_l[i] - 3 * c_l[i - 1] - c_h[i - 1] * lamds[i - 2]) / ((2 + alt_js[i - 2]) * c_h[i - 1] + 2 * c_h[i])) c_c = [0] for i in reversed(range(1, n)): c_c.append(alt_js[i - 1] * c_c[-1] + lamds[i - 1]) c_c = list(reversed(c_c)) c_b = [c_l[i] + (2 / 3) * c_c[i] * c_h[i] + (1 / 3) * c_h[i] * c_c[i - 1] for i in range(n)] c_a = list(Y[1:]) c_d = [(c_c[i] - c_c[i - 1]) / (3 * c_h[i]) for i in range(n)] funcs = [sp.simplify(a + b * (x - xi) + c * (x - xi) ** 2 + d * (x - xi) ** 3) for a, b, c, d, xi in zip(c_a, c_b, c_c, c_d, X[1:])] return funcs ``` ```python print('F(x) =', ', '.join(map(str, cub_spline()))) cub = cub_spline() y_cub = [] for k in range(1, len(X)): y_cub.extend([cub[k-1].subs({'x': j}) for j in x_l if j <= X[k] and j >= X[k-1]]) plt.title("Кубический сплайн") plt.plot(x_l, y_cub, color='black') plt.plot(X, Y, 'o', color='red') plt.grid(True) plt.show() ``` ## 6 На одном чертеже с графиком полиномов построить графики сплайнов. ```python plt.plot(x_l, y_lag) plt.plot(x_l, y_nw) plt.plot(x_l, y_liner) plt.plot(x_l, y_qdr) plt.plot(x_l, y_cub) plt.plot(X, Y, 'o', color='black') plt.legend(['Лагранж', 'Ньютон', 'Линейный', 'Квадратичный', 'Кубический', 'Точки']) plt.grid(True) plt.show() ```
lemma diameter_lower_bounded: fixes S :: "'a :: metric_space set" assumes S: "bounded S" and d: "0 < d" "d < diameter S" shows "\<exists>x\<in>S. \<exists>y\<in>S. d < dist x y"
C Copyright(C) 1999-2020 National Technology & Engineering Solutions C of Sandia, LLC (NTESS). Under the terms of Contract DE-NA0003525 with C NTESS, the U.S. Government retains certain rights in this software. C C See packages/seacas/LICENSE for details SUBROUTINE INBRST (MS, MR, N5, N6, N21, N23, JJ, IMTRL, JC, IIN, & IFOUND, IBARST, JMAT, JCENT, NLPB, JFLINE, JLLIST, LINKB, & LINKM, NHOLDM, IHOLDM, NHOLDB, IHOLDB, MERGE, NOROOM) C*********************************************************************** C SUBROUTINE INBRST = INPUTS A BAR SET INTO THE DATABASE C*********************************************************************** DIMENSION IBARST (MS), JMAT (MS), JCENT (MS), NLPB (MS) DIMENSION JFLINE (MS) DIMENSION JLLIST (3 * MS), LINKB (2, MS), LINKM (2, MS + MR) DIMENSION IHOLDM (2, (MS + MR)), IHOLDB (2, MS) DIMENSION IIN (IFOUND) LOGICAL MERGE, NOROOM, ADDLNK IZ = 0 NOROOM = .TRUE. N22 = 0 C ZERO OUT THE LINK ARRAY IF NEEDED IF (JJ .GT. N21) THEN N21 = JJ C FIND THE CORRECT BAR SET NUMBER IF MERGING C SET UP POINTERS FOR MERGING DATA ELSEIF (MERGE) THEN JHOLD = JJ CALL LTSORT (MS, LINKB, JJ, IPNTR, ADDLNK) IF (IPNTR .GT. 0) THEN IF (JHOLD .GT. NHOLDB)NHOLDB = JHOLD CALL LTSORT (MS, IHOLDB, JHOLD, IPNTR, ADDLNK) IF (IPNTR .GT. 0) THEN JJ = IPNTR ELSE JJ = N22 + 1 N22 = JJ WRITE ( * , 10000)JHOLD, JJ ADDLNK = .TRUE. CALL LTSORT (MS, IHOLDB, JHOLD, JJ, ADDLNK) ENDIF ENDIF ENDIF C INPUT THE BAR SET DATA INTO THE DATABASE N5 = N5 + 1 J = N5 IF (J .GT. MS)RETURN ADDLNK = .TRUE. CALL LTSORT (MS, LINKB, JJ, J, ADDLNK) IBARST (J) = JJ JCENT (J) = JC JFLINE (J) = N6 + 1 DO 100 I = 1, IFOUND JJ = IIN (I) IF (JJ .EQ. 0)GOTO 110 N6 = N6 + 1 IF (N6 .GT. MS * 3)RETURN JLLIST (N6) = JJ 100 CONTINUE 110 CONTINUE NLPB (J) = N6 - JFLINE (J) + 1 IF (NLPB (J) .LT. 1) THEN WRITE ( * , 10010)J CALL LTSORT (MS, LINKB, JJ, IZ, ADDLNK) ENDIF ADDLNK = .FALSE. C LINK UP THE MATERIAL C ZERO THE LINK ARRAY IF NEEDED IF (IMTRL .GT. N23) THEN N23 = IMTRL C SET UP POINTERS FOR MERGING DATA ELSEIF (MERGE) THEN JHOLD = IMTRL CALL LTSORT (MS + MR, LINKM, IMTRL, IPNTR, ADDLNK) IF (IPNTR .NE. 0) THEN IF (JHOLD .GT. NHOLDM)NHOLDM = JHOLD ADDLNK = .FALSE. CALL LTSORT ( (MS + MR), IHOLDM, JHOLD, IPNTR, ADDLNK) IF (IPNTR .GT. 0) THEN IMTRL = IPNTR ELSE IMTRL = N23 + 1 N23 = IMTRL WRITE ( * , 10010)JHOLD, IMTRL ADDLNK = .TRUE. CALL LTSORT ( (MS + MR), IHOLDM, JHOLD, IMTRL, ADDLNK) ENDIF ENDIF ENDIF C ADD THE MATERIAL INTO THE DATABASE NOROOM = .FALSE. ADDLNK = .FALSE. CALL LTSORT (MS + MR, LINKM, IMTRL, IPNTR, ADDLNK) ADDLNK = .TRUE. IF (IPNTR .GT. 0) THEN CALL MESAGE (' ') WRITE ( * , 10020)IMTRL, IBARST (J) CALL LTSORT (MS, LINKB, IBARST (J), IZ, ADDLNK) RETURN ELSEIF (IPNTR .EQ. 0) THEN IMINUS = - 1 CALL LTSORT (MS + MR, LINKM, IMTRL, IMINUS, ADDLNK) ENDIF JMAT (J) = IMTRL RETURN 10000 FORMAT (' OLD BAR SET NO:', I5, ' TO NEW BAR SET NO:', I5) 10010 FORMAT (' BAR SET:', I5, ' HAS LESS THAN ONE LINE', / , & ' THIS BAR SET WILL NOT BE INPUT INTO DATABASE') 10020 FORMAT (' MATERIAL:', I5, ' FOR BAR SET:', I5, & ' HAS BEEN DESIGNATED', & / , ' AS A REGION (4 NODE ELEMENT) MATERIAL.', / , & ' ELEMENTS WITH 2 AND 4 NODES CANNOT SHARE MATERIAL ID''S', & / , ' THIS BAR SET WILL NOT BE INPUT INTO DATABASE') END
/- Copyright (c) 2019 Jeremy Avigad. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Jeremy Avigad -/ import order.filter.basic import data.pfun /-! # `tendsto` for relations and partial functions > THIS FILE IS SYNCHRONIZED WITH MATHLIB4. > Any changes to this file require a corresponding PR to mathlib4. This file generalizes `filter` definitions from functions to partial functions and relations. ## Considering functions and partial functions as relations A function `f : α → β` can be considered as the relation `rel α β` which relates `x` and `f x` for all `x`, and nothing else. This relation is called `function.graph f`. A partial function `f : α →. β` can be considered as the relation `rel α β` which relates `x` and `f x` for all `x` for which `f x` exists, and nothing else. This relation is called `pfun.graph' f`. In this regard, a function is a relation for which every element in `α` is related to exactly one element in `β` and a partial function is a relation for which every element in `α` is related to at most one element in `β`. This file leverages this analogy to generalize `filter` definitions from functions to partial functions and relations. ## Notes `set.preimage` can be generalized to relations in two ways: * `rel.preimage` returns the image of the set under the inverse relation. * `rel.core` returns the set of elements that are only related to those in the set. Both generalizations are sensible in the context of filters, so `filter.comap` and `filter.tendsto` get two generalizations each. We first take care of relations. Then the definitions for partial functions are taken as special cases of the definitions for relations. -/ universes u v w namespace filter variables {α : Type u} {β : Type v} {γ : Type w} open_locale filter /-! ### Relations -/ /-- The forward map of a filter under a relation. Generalization of `filter.map` to relations. Note that `rel.core` generalizes `set.preimage`. -/ def rmap (r : rel α β) (l : filter α) : filter β := { sets := {s | r.core s ∈ l}, univ_sets := by simp, sets_of_superset := λ s t hs st, mem_of_superset hs $ rel.core_mono _ st, inter_sets := λ s t hs ht, by simp [rel.core_inter, inter_mem hs ht] } theorem rmap_sets (r : rel α β) (l : filter α) : (l.rmap r).sets = r.core ⁻¹' l.sets := rfl @[simp] theorem mem_rmap (r : rel α β) (l : filter α) (s : set β) : s ∈ l.rmap r ↔ r.core s ∈ l := iff.rfl @[simp] theorem rmap_rmap (r : rel α β) (s : rel β γ) (l : filter α) : rmap s (rmap r l) = rmap (r.comp s) l := filter_eq $ by simp [rmap_sets, set.preimage, rel.core_comp] @[simp] lemma rmap_compose (r : rel α β) (s : rel β γ) : rmap s ∘ rmap r = rmap (r.comp s) := funext $ rmap_rmap _ _ /-- Generic "limit of a relation" predicate. `rtendsto r l₁ l₂` asserts that for every `l₂`-neighborhood `a`, the `r`-core of `a` is an `l₁`-neighborhood. One generalization of `filter.tendsto` to relations. -/ def rtendsto (r : rel α β) (l₁ : filter α) (l₂ : filter β) := l₁.rmap r ≤ l₂ theorem rtendsto_def (r : rel α β) (l₁ : filter α) (l₂ : filter β) : rtendsto r l₁ l₂ ↔ ∀ s ∈ l₂, r.core s ∈ l₁ := iff.rfl /-- One way of taking the inverse map of a filter under a relation. One generalization of `filter.comap` to relations. Note that `rel.core` generalizes `set.preimage`. -/ def rcomap (r : rel α β) (f : filter β) : filter α := { sets := rel.image (λ s t, r.core s ⊆ t) f.sets, univ_sets := ⟨set.univ, univ_mem, set.subset_univ _⟩, sets_of_superset := λ a b ⟨a', ha', ma'a⟩ ab, ⟨a', ha', ma'a.trans ab⟩, inter_sets := λ a b ⟨a', ha₁, ha₂⟩ ⟨b', hb₁, hb₂⟩, ⟨a' ∩ b', inter_mem ha₁ hb₁, (r.core_inter a' b').subset.trans (set.inter_subset_inter ha₂ hb₂)⟩ } theorem rcomap_sets (r : rel α β) (f : filter β) : (rcomap r f).sets = rel.image (λ s t, r.core s ⊆ t) f.sets := rfl theorem rcomap_rcomap (r : rel α β) (s : rel β γ) (l : filter γ) : rcomap r (rcomap s l) = rcomap (r.comp s) l := filter_eq $ begin ext t, simp [rcomap_sets, rel.image, rel.core_comp], split, { rintros ⟨u, ⟨v, vsets, hv⟩, h⟩, exact ⟨v, vsets, set.subset.trans (rel.core_mono _ hv) h⟩ }, rintros ⟨t, tsets, ht⟩, exact ⟨rel.core s t, ⟨t, tsets, set.subset.rfl⟩, ht⟩ end @[simp] lemma rcomap_compose (r : rel α β) (s : rel β γ) : rcomap r ∘ rcomap s = rcomap (r.comp s) := funext $ rcomap_rcomap _ _ theorem rtendsto_iff_le_rcomap (r : rel α β) (l₁ : filter α) (l₂ : filter β) : rtendsto r l₁ l₂ ↔ l₁ ≤ l₂.rcomap r := begin rw rtendsto_def, change (∀ (s : set β), s ∈ l₂.sets → r.core s ∈ l₁) ↔ l₁ ≤ rcomap r l₂, simp [filter.le_def, rcomap, rel.mem_image], split, { exact λ h s t tl₂, mem_of_superset (h t tl₂) }, { exact λ h t tl₂, h _ t tl₂ set.subset.rfl } end -- Interestingly, there does not seem to be a way to express this relation using a forward map. -- Given a filter `f` on `α`, we want a filter `f'` on `β` such that `r.preimage s ∈ f` if -- and only if `s ∈ f'`. But the intersection of two sets satisfying the lhs may be empty. /-- One way of taking the inverse map of a filter under a relation. Generalization of `filter.comap` to relations. -/ def rcomap' (r : rel α β) (f : filter β) : filter α := { sets := rel.image (λ s t, r.preimage s ⊆ t) f.sets, univ_sets := ⟨set.univ, univ_mem, set.subset_univ _⟩, sets_of_superset := λ a b ⟨a', ha', ma'a⟩ ab, ⟨a', ha', ma'a.trans ab⟩, inter_sets := λ a b ⟨a', ha₁, ha₂⟩ ⟨b', hb₁, hb₂⟩, ⟨a' ∩ b', inter_mem ha₁ hb₁, (@rel.preimage_inter _ _ r _ _).trans (set.inter_subset_inter ha₂ hb₂)⟩ } @[simp] lemma mem_rcomap' (r : rel α β) (l : filter β) (s : set α) : s ∈ l.rcomap' r ↔ ∃ t ∈ l, r.preimage t ⊆ s := iff.rfl theorem rcomap'_sets (r : rel α β) (f : filter β) : (rcomap' r f).sets = rel.image (λ s t, r.preimage s ⊆ t) f.sets := rfl @[simp] theorem rcomap'_rcomap' (r : rel α β) (s : rel β γ) (l : filter γ) : rcomap' r (rcomap' s l) = rcomap' (r.comp s) l := filter.ext $ λ t, begin simp [rcomap'_sets, rel.image, rel.preimage_comp], split, { rintro ⟨u, ⟨v, vsets, hv⟩, h⟩, exact ⟨v, vsets, (rel.preimage_mono _ hv).trans h⟩ }, rintro ⟨t, tsets, ht⟩, exact ⟨s.preimage t, ⟨t, tsets, set.subset.rfl⟩, ht⟩ end @[simp] lemma rcomap'_compose (r : rel α β) (s : rel β γ) : rcomap' r ∘ rcomap' s = rcomap' (r.comp s) := funext $ rcomap'_rcomap' _ _ /-- Generic "limit of a relation" predicate. `rtendsto' r l₁ l₂` asserts that for every `l₂`-neighborhood `a`, the `r`-preimage of `a` is an `l₁`-neighborhood. One generalization of `filter.tendsto` to relations. -/ def rtendsto' (r : rel α β) (l₁ : filter α) (l₂ : filter β) := l₁ ≤ l₂.rcomap' r theorem rtendsto'_def (r : rel α β) (l₁ : filter α) (l₂ : filter β) : rtendsto' r l₁ l₂ ↔ ∀ s ∈ l₂, r.preimage s ∈ l₁ := begin unfold rtendsto' rcomap', simp [le_def, rel.mem_image], split, { exact λ h s hs, h _ _ hs set.subset.rfl }, { exact λ h s t ht, mem_of_superset (h t ht) } end theorem tendsto_iff_rtendsto (l₁ : filter α) (l₂ : filter β) (f : α → β) : tendsto f l₁ l₂ ↔ rtendsto (function.graph f) l₁ l₂ := by { simp [tendsto_def, function.graph, rtendsto_def, rel.core, set.preimage] } theorem tendsto_iff_rtendsto' (l₁ : filter α) (l₂ : filter β) (f : α → β) : tendsto f l₁ l₂ ↔ rtendsto' (function.graph f) l₁ l₂ := by { simp [tendsto_def, function.graph, rtendsto'_def, rel.preimage_def, set.preimage] } /-! ### Partial functions -/ /-- The forward map of a filter under a partial function. Generalization of `filter.map` to partial functions. -/ def pmap (f : α →. β) (l : filter α) : filter β := filter.rmap f.graph' l @[simp] lemma mem_pmap (f : α →. β) (l : filter α) (s : set β) : s ∈ l.pmap f ↔ f.core s ∈ l := iff.rfl /-- Generic "limit of a partial function" predicate. `ptendsto r l₁ l₂` asserts that for every `l₂`-neighborhood `a`, the `p`-core of `a` is an `l₁`-neighborhood. One generalization of `filter.tendsto` to partial function. -/ def ptendsto (f : α →. β) (l₁ : filter α) (l₂ : filter β) := l₁.pmap f ≤ l₂ theorem ptendsto_def (f : α →. β) (l₁ : filter α) (l₂ : filter β) : ptendsto f l₁ l₂ ↔ ∀ s ∈ l₂, f.core s ∈ l₁ := iff.rfl theorem ptendsto_iff_rtendsto (l₁ : filter α) (l₂ : filter β) (f : α →. β) : ptendsto f l₁ l₂ ↔ rtendsto f.graph' l₁ l₂ := iff.rfl theorem pmap_res (l : filter α) (s : set α) (f : α → β) : pmap (pfun.res f s) l = map f (l ⊓ 𝓟 s) := begin ext t, simp only [pfun.core_res, mem_pmap, mem_map, mem_inf_principal, imp_iff_not_or], refl end theorem tendsto_iff_ptendsto (l₁ : filter α) (l₂ : filter β) (s : set α) (f : α → β) : tendsto f (l₁ ⊓ 𝓟 s) l₂ ↔ ptendsto (pfun.res f s) l₁ l₂ := by simp only [tendsto, ptendsto, pmap_res] theorem tendsto_iff_ptendsto_univ (l₁ : filter α) (l₂ : filter β) (f : α → β) : tendsto f l₁ l₂ ↔ ptendsto (pfun.res f set.univ) l₁ l₂ := by { rw ← tendsto_iff_ptendsto, simp [principal_univ] } /-- Inverse map of a filter under a partial function. One generalization of `filter.comap` to partial functions. -/ def pcomap' (f : α →. β) (l : filter β) : filter α := filter.rcomap' f.graph' l /-- Generic "limit of a partial function" predicate. `ptendsto' r l₁ l₂` asserts that for every `l₂`-neighborhood `a`, the `p`-preimage of `a` is an `l₁`-neighborhood. One generalization of `filter.tendsto` to partial functions. -/ def ptendsto' (f : α →. β) (l₁ : filter α) (l₂ : filter β) := l₁ ≤ l₂.rcomap' f.graph' theorem ptendsto'_def (f : α →. β) (l₁ : filter α) (l₂ : filter β) : ptendsto' f l₁ l₂ ↔ ∀ s ∈ l₂, f.preimage s ∈ l₁ := rtendsto'_def _ _ _ theorem ptendsto_of_ptendsto' {f : α →. β} {l₁ : filter α} {l₂ : filter β} : ptendsto' f l₁ l₂ → ptendsto f l₁ l₂ := begin rw [ptendsto_def, ptendsto'_def], exact λ h s sl₂, mem_of_superset (h s sl₂) (pfun.preimage_subset_core _ _), end theorem ptendsto'_of_ptendsto {f : α →. β} {l₁ : filter α} {l₂ : filter β} (h : f.dom ∈ l₁) : ptendsto f l₁ l₂ → ptendsto' f l₁ l₂ := begin rw [ptendsto_def, ptendsto'_def], intros h' s sl₂, rw pfun.preimage_eq, exact inter_mem (h' s sl₂) h end end filter
Formal statement is: lemma linear_continuous_compose: fixes f :: "'a::euclidean_space \<Rightarrow> 'b::euclidean_space" and g :: "'b \<Rightarrow> 'c::real_normed_vector" assumes "continuous F f" "linear g" shows "continuous F (\<lambda>x. g(f x))" Informal statement is: If $f$ is a continuous function from a topological space $X$ to a topological space $Y$ and $g$ is a linear function from $Y$ to a normed vector space $Z$, then the composition $g \circ f$ is continuous.
The binomial coefficient $\binom{n+1}{k}$ is equal to $\binom{n}{k} + \binom{n}{k-1}$.
/********************************************************************* * Software License Agreement (BSD License) * * Copyright (c) 2012, Willow Garage, Inc. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * Redistributions in binary form must reproduce the above * copyright notice, this list of conditions and the following * disclaimer in the documentation and/or other materials provided * with the distribution. * * Neither the name of Willow Garage nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. *********************************************************************/ /* Author: Ioan Sucan */ #include <moveit/warehouse/planning_scene_storage.h> #include <moveit/warehouse/state_storage.h> #include <moveit/warehouse/constraints_storage.h> #include <boost/program_options/cmdline.hpp> #include <boost/program_options/options_description.hpp> #include <boost/program_options/parsers.hpp> #include <boost/program_options/variables_map.hpp> #include <moveit/planning_scene_monitor/planning_scene_monitor.h> #include <moveit/robot_state/conversions.h> #include <rclcpp/rclcpp.hpp> static const std::string ROBOT_DESCRIPTION = "robot_description"; static const rclcpp::Logger LOGGER = rclcpp::get_logger("moveit.ros.warehouse.save_to_text"); typedef std::pair<geometry_msgs::msg::Point, geometry_msgs::msg::Quaternion> LinkConstraintPair; typedef std::map<std::string, LinkConstraintPair> LinkConstraintMap; void collectLinkConstraints(const moveit_msgs::msg::Constraints& constraints, LinkConstraintMap& lcmap) { for (const moveit_msgs::msg::PositionConstraint& position_constraint : constraints.position_constraints) { LinkConstraintPair lcp; const moveit_msgs::msg::PositionConstraint& pc = position_constraint; lcp.first = pc.constraint_region.primitive_poses[0].position; lcmap[position_constraint.link_name] = lcp; } for (const moveit_msgs::msg::OrientationConstraint& orientation_constraint : constraints.orientation_constraints) { if (lcmap.count(orientation_constraint.link_name)) { lcmap[orientation_constraint.link_name].second = orientation_constraint.orientation; } else { RCLCPP_WARN(LOGGER, "Orientation constraint for %s has no matching position constraint", orientation_constraint.link_name.c_str()); } } } int main(int argc, char** argv) { rclcpp::init(argc, argv); rclcpp::NodeOptions node_options; node_options.allow_undeclared_parameters(true); node_options.automatically_declare_parameters_from_overrides(true); rclcpp::Node::SharedPtr node = rclcpp::Node::make_shared("save_warehouse_as_text", node_options); boost::program_options::options_description desc; desc.add_options()("help", "Show help message")("host", boost::program_options::value<std::string>(), "Host for the " "DB.")("port", boost::program_options::value<std::size_t>(), "Port for the DB."); boost::program_options::variables_map vm; boost::program_options::store(boost::program_options::parse_command_line(argc, argv, desc), vm); boost::program_options::notify(vm); if (vm.count("help")) { std::cout << desc << std::endl; return 1; } // Set up db warehouse_ros::DatabaseConnection::Ptr conn = moveit_warehouse::loadDatabase(node); if (vm.count("host") && vm.count("port")) conn->setParams(vm["host"].as<std::string>(), vm["port"].as<std::size_t>()); if (!conn->connect()) return 1; planning_scene_monitor::PlanningSceneMonitor psm(node, ROBOT_DESCRIPTION); moveit_warehouse::PlanningSceneStorage pss(conn); moveit_warehouse::RobotStateStorage rss(conn); moveit_warehouse::ConstraintsStorage cs(conn); std::vector<std::string> scene_names; pss.getPlanningSceneNames(scene_names); for (const std::string& scene_name : scene_names) { moveit_warehouse::PlanningSceneWithMetadata pswm; if (pss.getPlanningScene(pswm, scene_name)) { RCLCPP_INFO(LOGGER, "Saving scene '%s'", scene_name.c_str()); psm.getPlanningScene()->setPlanningSceneMsg(static_cast<const moveit_msgs::msg::PlanningScene&>(*pswm)); std::ofstream fout((scene_name + ".scene").c_str()); psm.getPlanningScene()->saveGeometryToStream(fout); fout.close(); std::vector<std::string> robot_state_names; moveit::core::RobotModelConstPtr km = psm.getRobotModel(); // Get start states for scene std::stringstream rsregex; rsregex << ".*" << scene_name << ".*"; rss.getKnownRobotStates(rsregex.str(), robot_state_names); // Get goal constraints for scene std::vector<std::string> constraint_names; std::stringstream csregex; csregex << ".*" << scene_name << ".*"; cs.getKnownConstraints(csregex.str(), constraint_names); if (!(robot_state_names.empty() && constraint_names.empty())) { std::ofstream qfout((scene_name + ".queries").c_str()); qfout << scene_name << std::endl; if (!robot_state_names.empty()) { qfout << "start" << std::endl; qfout << robot_state_names.size() << std::endl; for (const std::string& robot_state_name : robot_state_names) { RCLCPP_INFO(LOGGER, "Saving start state %s for scene %s", robot_state_name.c_str(), scene_name.c_str()); qfout << robot_state_name << std::endl; moveit_warehouse::RobotStateWithMetadata robot_state; rss.getRobotState(robot_state, robot_state_name); moveit::core::RobotState ks(km); moveit::core::robotStateMsgToRobotState(*robot_state, ks, false); ks.printStateInfo(qfout); qfout << "." << std::endl; } } if (!constraint_names.empty()) { qfout << "goal" << std::endl; qfout << constraint_names.size() << std::endl; for (const std::string& constraint_name : constraint_names) { RCLCPP_INFO(LOGGER, "Saving goal %s for scene %s", constraint_name.c_str(), scene_name.c_str()); qfout << "link_constraint" << std::endl; qfout << constraint_name << std::endl; moveit_warehouse::ConstraintsWithMetadata constraints; cs.getConstraints(constraints, constraint_name); LinkConstraintMap lcmap; collectLinkConstraints(*constraints, lcmap); for (std::pair<const std::string, LinkConstraintPair>& iter : lcmap) { std::string link_name = iter.first; LinkConstraintPair lcp = iter.second; qfout << link_name << std::endl; qfout << "xyz " << lcp.first.x << " " << lcp.first.y << " " << lcp.first.z << std::endl; Eigen::Quaterniond orientation(lcp.second.w, lcp.second.x, lcp.second.y, lcp.second.z); Eigen::Vector3d rpy = orientation.matrix().eulerAngles(0, 1, 2); qfout << "rpy " << rpy[0] << " " << rpy[1] << " " << rpy[2] << std::endl; } qfout << "." << std::endl; } } qfout.close(); } } } RCLCPP_INFO(LOGGER, "Done."); rclcpp::spin(node); return 0; }
||| A MonadRef instance with heap and locations indexed by a universe. ||| ||| Note: ||| - We can't make an instance `MonadRef (Loc ts) (RefT ts ts' m)` ||| because `Loc ts : Ty u -> Type` instead of `Type -> Type`... module Control.Monad.Ref.TypedHeap import public Control.Monad.Ref import Data.Vect import public Data.UniverseR %default total %access public export %hide Language.Reflection.Ref %hide Language.Reflection.Universe -- Implementation -------------------------------------------------------------- -- Types -- data Cell : {u : Universe t} -> (a : t) -> Type where MkCell : Nat -> Cell a data RefT : {u : Universe t} -> (m : Type -> Type) -> (a : t) -> Type where Pure : (x : typeOf @{u} a) -> RefT m a Bind : (this : RefT m a) -> (next : a -> RefT m b) -> RefT m b New : (x : typeOf @{u} a) -> RefT m (Cell a) Read : (l : Cell a) -> RefT m a Write : (l : Cell a) -> (x : typeOf @{u} a) -> RefT m () Ref : {u : Universe t} -> (a : t) -> Type Ref {u} = RefT {u} Identity
function [X0,isYout] = VBA_spm_Xadjust(SPMfile,VOIfile,varthresh) % gets the effects of no interest, wrt to which the data has been adjusted % [X0,isYout] = spm_Xadjust(SPMfile,VOIfile,varthresh) % IN: % - SPMfile: name of the SPM file % - VOIfile: name of the VOI file % - varthresh: threshold for PCA on X0 (fraction of explained variance). % Default is 0.95. % OUT: % - X0: confounds matrix % - isYout: vector of indices of scans that were effectively removed from % the GLM using scan-nulling regressors included in the original % confounds matrix. try, varthresh; catch, varthresh = 0.95; end load(SPMfile) load(VOIfile) if isequal(xY.Ic,0) X0 = []; isYout = []; return end Fc = SPM.xCon(xY.Ic); ind = sum(abs(Fc.c),2)==0; X0 = SPM.xX.X(:,ind); % remove scan-nulling regressors n0 = size(X0,2); remove = []; isYout = []; for i=1:n0 X0i = X0(:,i) - X0(1,i); i1 = find(X0i~=0); tmp = zeros(size(X0,1),1); tmp(i1) = 1; if isequal(X0i,tmp) remove = [remove;i]; isYout = [isYout,i1]; end end X0 = X0(:,setdiff(1:size(X0,2),remove)); X0 = bsxfun(@minus,X0,mean(X0,1)); X0 = bsxfun(@rdivide,X0,std(X0,[],1)); if varthresh < 1 [u,s,v] = svd(X0); s2 = diag(s).^2; ev = cumsum(s2./sum(s2)); it = find(ev>=varthresh, 1 ); X0 = [u(:,1:it),ones(size(X0,1),1)./sqrt(size(X0,1))]; end return % the following reproduces the code in spm_regions.m: % sX = SPM.xX.xKXs; % X0 = sX.X*(eye(spm_sp('size',sX,2)) - spm_sp('xpx-',sX)*sf_H(Fc,sX)); % % function H = sf_H(Fc,sX) % if sf_ver(Fc) > 1, % hsqr = sf_Hsqr(Fc,sX); % H = hsqr' * hsqr; % else % H = Fc.c * pinv(Fc.X1o' * Fc.X1o) * Fc.c'; % end % % function hsqr = sf_Hsqr(Fc,sX) % if sf_ver(Fc) > 1, % hsqr = spm_sp('ox',spm_sp('set',Fc.X1o.ukX1o))' * spm_sp('cukx',sX); % else % hsqr = spm_sp('ox',spm_sp('set',Fc.X1o))'*spm_sp('x',sX); % end % % function v = sf_ver(Fc) % if isstruct(Fc.X0), v = 2; else v = 1; end
module Flexidisc.Header.Row import Flexidisc.Header.Type import Flexidisc.OrdList import Flexidisc.OrdList.Row %default total %access public export ||| Proof that a key value pair is part of an `OrdList`. If you don't need the value, use `Label`. ||| ||| @k the inspected key ||| @ty its value ||| @xs the header that contains the information data Row : (k : l) -> (ty : a) -> (xs : Header' l a) -> Type where ||| A wrapper for an OrdList Row R : {xs : OrdList l o a} -> OrdRow k ty xs -> Row k ty (H xs) %name Row lbl, loc, prf, e, elem ||| Map a row and its header simultaneously mapRow : {xs : Header' k a} -> (f : a -> b) -> (loc : Row l ty xs) -> Row l (f ty) (map f xs) mapRow f (R loc) = R $ mapRow f loc ||| Given a proof that an element is in a vector, remove it dropRow : (xs : Header' k a) -> (loc : Row l ty xs) -> Header' k a dropRow (H xs) (R loc) = H (dropOrdRow xs loc) ||| Update a value in the list given it's location and an update function changeType : (xs : Header' k a) -> (loc : Row l old xs) -> (new : a) -> Header' k a changeType (H xs) (R loc) = H . changeValue xs loc
Require Import Crypto.Specific.Framework.RawCurveParameters. Require Import Crypto.Util.LetIn. (*** Modulus : 2^468 - 17 Base: 32 ***) Definition curve : CurveParameters := {| sz := 15%nat; base := 32; bitwidth := 32; s := 2^468; c := [(1, 17)]; carry_chains := None; a24 := None; coef_div_modulus := None; goldilocks := None; karatsuba := None; montgomery := true; freeze := Some false; ladderstep := false; mul_code := None; square_code := None; upper_bound_of_exponent_loose := None; upper_bound_of_exponent_tight := None; allowable_bit_widths := None; freeze_extra_allowable_bit_widths := None; modinv_fuel := None |}. Ltac extra_prove_mul_eq _ := idtac. Ltac extra_prove_square_eq _ := idtac.
/- Copyright (c) 2022 Sébastien Gouëzel. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Sébastien Gouëzel -/ import probability.variance import measure_theory.function.uniform_integrable /-! # Identically distributed random variables Two random variables defined on two (possibly different) probability spaces but taking value in the same space are *identically distributed* if their distributions (i.e., the image probability measures on the target space) coincide. We define this concept and establish its basic properties in this file. ## Main definitions and results * `ident_distrib f g μ ν` registers that the image of `μ` under `f` coincides with the image of `ν` under `g` (and that `f` and `g` are almost everywhere measurable, as otherwise the image measures don't make sense). The measures can be kept implicit as in `ident_distrib f g` if the spaces are registered as measure spaces. * `ident_distrib.comp`: being identically distributed is stable under composition with measurable maps. There are two main kind of lemmas, under the assumption that `f` and `g` are identically distributed: lemmas saying that two quantities computed for `f` and `g` are the same, and lemmas saying that if `f` has some property then `g` also has it. The first kind is registered as `ident_distrib.foo_eq`, the second one as `ident_distrib.foo_snd` (in the latter case, to deduce a property of `f` from one of `g`, use `h.symm.foo_snd` where `h : ident_distrib f g μ ν`). For instance: * `ident_distrib.measure_mem_eq`: if `f` and `g` are identically distributed, then the probabilities that they belong to a given measurable set are the same. * `ident_distrib.integral_eq`: if `f` and `g` are identically distributed, then their integrals are the same. * `ident_distrib.variance_eq`: if `f` and `g` are identically distributed, then their variances are the same. * `ident_distrib.ae_strongly_measurable_snd`: if `f` and `g` are identically distributed and `f` is almost everywhere strongly measurable, then so is `g`. * `ident_distrib.mem_ℒp_snd`: if `f` and `g` are identically distributed and `f` belongs to `ℒp`, then so does `g`. We also register several dot notation shortcuts for convenience. For instance, if `h : ident_distrib f g μ ν`, then `h.sq` states that `f^2` and `g^2` are identically distributed, and `h.norm` states that `‖f‖` and `‖g‖` are identically distributed, and so on. -/ open measure_theory filter finset noncomputable theory open_locale topology big_operators measure_theory ennreal nnreal variables {α β γ δ : Type*} [measurable_space α] [measurable_space β] [measurable_space γ] [measurable_space δ] namespace probability_theory /-- Two functions defined on two (possibly different) measure spaces are identically distributed if their image measures coincide. This only makes sense when the functions are ae measurable (as otherwise the image measures are not defined), so we require this as well in the definition. -/ structure ident_distrib (f : α → γ) (g : β → γ) (μ : measure α . volume_tac) (ν : measure β . volume_tac) : Prop := (ae_measurable_fst : ae_measurable f μ) (ae_measurable_snd : ae_measurable g ν) (map_eq : measure.map f μ = measure.map g ν) namespace ident_distrib open topological_space variables {μ : measure α} {ν : measure β} {f : α → γ} {g : β → γ} protected lemma refl (hf : ae_measurable f μ) : ident_distrib f f μ μ := { ae_measurable_fst := hf, ae_measurable_snd := hf, map_eq := rfl } protected lemma symm (h : ident_distrib f g μ ν) : ident_distrib g f ν μ := { ae_measurable_fst := h.ae_measurable_snd, ae_measurable_snd := h.ae_measurable_fst, map_eq := h.map_eq.symm } protected lemma trans {ρ : measure δ} {h : δ → γ} (h₁ : ident_distrib f g μ ν) (h₂ : ident_distrib g h ν ρ) : ident_distrib f h μ ρ := { ae_measurable_fst := h₁.ae_measurable_fst, ae_measurable_snd := h₂.ae_measurable_snd, map_eq := h₁.map_eq.trans h₂.map_eq } protected lemma comp_of_ae_measurable {u : γ → δ} (h : ident_distrib f g μ ν) (hu : ae_measurable u (measure.map f μ)) : ident_distrib (u ∘ f) (u ∘ g) μ ν := { ae_measurable_fst := hu.comp_ae_measurable h.ae_measurable_fst, ae_measurable_snd := by { rw h.map_eq at hu, exact hu.comp_ae_measurable h.ae_measurable_snd }, map_eq := begin rw [← ae_measurable.map_map_of_ae_measurable hu h.ae_measurable_fst, ← ae_measurable.map_map_of_ae_measurable _ h.ae_measurable_snd, h.map_eq], rwa ← h.map_eq, end } protected lemma comp {u : γ → δ} (h : ident_distrib f g μ ν) (hu : measurable u) : ident_distrib (u ∘ f) (u ∘ g) μ ν := h.comp_of_ae_measurable hu.ae_measurable protected lemma of_ae_eq {g : α → γ} (hf : ae_measurable f μ) (heq : f =ᵐ[μ] g) : ident_distrib f g μ μ := { ae_measurable_fst := hf, ae_measurable_snd := hf.congr heq, map_eq := measure.map_congr heq } lemma measure_mem_eq (h : ident_distrib f g μ ν) {s : set γ} (hs : measurable_set s) : μ (f ⁻¹' s) = ν (g ⁻¹' s) := by rw [← measure.map_apply_of_ae_measurable h.ae_measurable_fst hs, ← measure.map_apply_of_ae_measurable h.ae_measurable_snd hs, h.map_eq] alias measure_mem_eq ← measure_preimage_eq lemma ae_snd (h : ident_distrib f g μ ν) {p : γ → Prop} (pmeas : measurable_set {x | p x}) (hp : ∀ᵐ x ∂μ, p (f x)) : ∀ᵐ x ∂ν, p (g x) := begin apply (ae_map_iff h.ae_measurable_snd pmeas).1, rw ← h.map_eq, exact (ae_map_iff h.ae_measurable_fst pmeas).2 hp, end lemma ae_mem_snd (h : ident_distrib f g μ ν) {t : set γ} (tmeas : measurable_set t) (ht : ∀ᵐ x ∂μ, f x ∈ t) : ∀ᵐ x ∂ν, g x ∈ t := h.ae_snd tmeas ht /-- In a second countable topology, the first function in an identically distributed pair is a.e. strongly measurable. So is the second function, but use `h.symm.ae_strongly_measurable_fst` as `h.ae_strongly_measurable_snd` has a different meaning.-/ /-- If `f` and `g` are identically distributed and `f` is a.e. strongly measurable, so is `g`. -/ lemma ae_strongly_measurable_snd [topological_space γ] [metrizable_space γ] [borel_space γ] (h : ident_distrib f g μ ν) (hf : ae_strongly_measurable f μ) : ae_strongly_measurable g ν := begin refine ae_strongly_measurable_iff_ae_measurable_separable.2 ⟨h.ae_measurable_snd, _⟩, rcases (ae_strongly_measurable_iff_ae_measurable_separable.1 hf).2 with ⟨t, t_sep, ht⟩, refine ⟨closure t, t_sep.closure, _⟩, apply h.ae_mem_snd is_closed_closure.measurable_set, filter_upwards [ht] with x hx using subset_closure hx, end lemma ae_strongly_measurable_iff [topological_space γ] [metrizable_space γ] [borel_space γ] (h : ident_distrib f g μ ν) : ae_strongly_measurable f μ ↔ ae_strongly_measurable g ν := ⟨λ hf, h.ae_strongly_measurable_snd hf, λ hg, h.symm.ae_strongly_measurable_snd hg⟩ lemma ess_sup_eq [conditionally_complete_linear_order γ] [topological_space γ] [opens_measurable_space γ] [order_closed_topology γ] (h : ident_distrib f g μ ν) : ess_sup f μ = ess_sup g ν := begin have I : ∀ a, μ {x : α | a < f x} = ν {x : β | a < g x} := λ a, h.measure_mem_eq measurable_set_Ioi, simp_rw [ess_sup_eq_Inf, I], end lemma lintegral_eq {f : α → ℝ≥0∞} {g : β → ℝ≥0∞} (h : ident_distrib f g μ ν) : ∫⁻ x, f x ∂μ = ∫⁻ x, g x ∂ν := begin change ∫⁻ x, id (f x) ∂μ = ∫⁻ x, id (g x) ∂ν, rw [← lintegral_map' ae_measurable_id h.ae_measurable_fst, ← lintegral_map' ae_measurable_id h.ae_measurable_snd, h.map_eq], end lemma integral_eq [normed_add_comm_group γ] [normed_space ℝ γ] [complete_space γ] [borel_space γ] (h : ident_distrib f g μ ν) : ∫ x, f x ∂μ = ∫ x, g x ∂ν := begin by_cases hf : ae_strongly_measurable f μ, { have A : ae_strongly_measurable id (measure.map f μ), { rw ae_strongly_measurable_iff_ae_measurable_separable, rcases (ae_strongly_measurable_iff_ae_measurable_separable.1 hf).2 with ⟨t, t_sep, ht⟩, refine ⟨ae_measurable_id, ⟨closure t, t_sep.closure, _⟩⟩, rw ae_map_iff h.ae_measurable_fst, { filter_upwards [ht] with x hx using subset_closure hx }, { exact is_closed_closure.measurable_set } }, change ∫ x, id (f x) ∂μ = ∫ x, id (g x) ∂ν, rw [← integral_map h.ae_measurable_fst A], rw h.map_eq at A, rw [← integral_map h.ae_measurable_snd A, h.map_eq] }, { rw integral_non_ae_strongly_measurable hf, rw h.ae_strongly_measurable_iff at hf, rw integral_non_ae_strongly_measurable hf } end lemma snorm_eq [normed_add_comm_group γ] [opens_measurable_space γ] (h : ident_distrib f g μ ν) (p : ℝ≥0∞) : snorm f p μ = snorm g p ν := begin by_cases h0 : p = 0, { simp [h0], }, by_cases h_top : p = ∞, { simp only [h_top, snorm, snorm_ess_sup, ennreal.top_ne_zero, eq_self_iff_true, if_true, if_false], apply ess_sup_eq, exact h.comp (measurable_coe_nnreal_ennreal.comp measurable_nnnorm) }, simp only [snorm_eq_snorm' h0 h_top, snorm', one_div], congr' 1, apply lintegral_eq, exact h.comp (measurable.pow_const (measurable_coe_nnreal_ennreal.comp measurable_nnnorm) p.to_real), end lemma mem_ℒp_snd [normed_add_comm_group γ] [borel_space γ] {p : ℝ≥0∞} (h : ident_distrib f g μ ν) (hf : mem_ℒp f p μ) : mem_ℒp g p ν := begin refine ⟨h.ae_strongly_measurable_snd hf.ae_strongly_measurable, _⟩, rw ← h.snorm_eq, exact hf.2 end lemma mem_ℒp_iff [normed_add_comm_group γ] [borel_space γ] {p : ℝ≥0∞} (h : ident_distrib f g μ ν) : mem_ℒp f p μ ↔ mem_ℒp g p ν := ⟨λ hf, h.mem_ℒp_snd hf, λ hg, h.symm.mem_ℒp_snd hg⟩ lemma integrable_snd [normed_add_comm_group γ] [borel_space γ] (h : ident_distrib f g μ ν) (hf : integrable f μ) : integrable g ν := begin rw ← mem_ℒp_one_iff_integrable at hf ⊢, exact h.mem_ℒp_snd hf end lemma integrable_iff [normed_add_comm_group γ] [borel_space γ] (h : ident_distrib f g μ ν) : integrable f μ ↔ integrable g ν := ⟨λ hf, h.integrable_snd hf, λ hg, h.symm.integrable_snd hg⟩ protected lemma norm [normed_add_comm_group γ] [borel_space γ] (h : ident_distrib f g μ ν) : ident_distrib (λ x, ‖f x‖) (λ x, ‖g x‖) μ ν := h.comp measurable_norm protected lemma nnnorm [normed_add_comm_group γ] [borel_space γ] (h : ident_distrib f g μ ν) : ident_distrib (λ x, ‖f x‖₊) (λ x, ‖g x‖₊) μ ν := h.comp measurable_nnnorm protected lemma pow [has_pow γ ℕ] [has_measurable_pow γ ℕ] (h : ident_distrib f g μ ν) {n : ℕ} : ident_distrib (λ x, (f x) ^ n) (λ x, (g x) ^ n) μ ν := h.comp (measurable_id.pow_const n) protected lemma sq [has_pow γ ℕ] [has_measurable_pow γ ℕ] (h : ident_distrib f g μ ν) : ident_distrib (λ x, (f x) ^ 2) (λ x, (g x) ^ 2) μ ν := h.comp (measurable_id.pow_const 2) protected lemma coe_nnreal_ennreal {f : α → ℝ≥0} {g : β → ℝ≥0} (h : ident_distrib f g μ ν) : ident_distrib (λ x, (f x : ℝ≥0∞)) (λ x, (g x : ℝ≥0∞)) μ ν := h.comp measurable_coe_nnreal_ennreal @[to_additive] lemma mul_const [has_mul γ] [has_measurable_mul γ] (h : ident_distrib f g μ ν) (c : γ) : ident_distrib (λ x, f x * c) (λ x, g x * c) μ ν := h.comp (measurable_mul_const c) @[to_additive] lemma const_mul [has_mul γ] [has_measurable_mul γ] (h : ident_distrib f g μ ν) (c : γ) : ident_distrib (λ x, c * f x) (λ x, c * g x) μ ν := h.comp (measurable_const_mul c) @[to_additive] lemma div_const [has_div γ] [has_measurable_div γ] (h : ident_distrib f g μ ν) (c : γ) : ident_distrib (λ x, f x / c) (λ x, g x / c) μ ν := h.comp (has_measurable_div.measurable_div_const c) @[to_additive] lemma const_div [has_div γ] [has_measurable_div γ] (h : ident_distrib f g μ ν) (c : γ) : ident_distrib (λ x, c / f x) (λ x, c / g x) μ ν := h.comp (has_measurable_div.measurable_const_div c) lemma evariance_eq {f : α → ℝ} {g : β → ℝ} (h : ident_distrib f g μ ν) : evariance f μ = evariance g ν := begin convert (h.sub_const (∫ x, f x ∂μ)).nnnorm.coe_nnreal_ennreal.sq.lintegral_eq, rw h.integral_eq, refl end lemma variance_eq {f : α → ℝ} {g : β → ℝ} (h : ident_distrib f g μ ν) : variance f μ = variance g ν := by { rw [variance, h.evariance_eq], refl, } end ident_distrib section uniform_integrable open topological_space variables {E : Type*} [measurable_space E] [normed_add_comm_group E] [borel_space E] [second_countable_topology E] {μ : measure α} [is_finite_measure μ] /-- This lemma is superceded by `mem_ℒp.uniform_integrable_of_ident_distrib` which only require `ae_strongly_measurable`. -/ lemma mem_ℒp.uniform_integrable_of_ident_distrib_aux {ι : Type*} {f : ι → α → E} {j : ι} {p : ℝ≥0∞} (hp : 1 ≤ p) (hp' : p ≠ ∞) (hℒp : mem_ℒp (f j) p μ) (hfmeas : ∀ i, strongly_measurable (f i)) (hf : ∀ i, ident_distrib (f i) (f j) μ μ) : uniform_integrable f p μ := begin refine uniform_integrable_of' hp hp' hfmeas (λ ε hε, _), by_cases hι : nonempty ι, swap, { exact ⟨0, λ i, false.elim (hι $ nonempty.intro i)⟩ }, obtain ⟨C, hC₁, hC₂⟩ := hℒp.snorm_indicator_norm_ge_pos_le μ (hfmeas _) hε, have hmeas : ∀ i, measurable_set {x | (⟨C, hC₁.le⟩ : ℝ≥0) ≤ ‖f i x‖₊} := λ i, measurable_set_le measurable_const (hfmeas _).measurable.nnnorm, refine ⟨⟨C, hC₁.le⟩, λ i, le_trans (le_of_eq _) hC₂⟩, have : {x : α | (⟨C, hC₁.le⟩ : ℝ≥0) ≤ ‖f i x‖₊}.indicator (f i) = (λ x : E, if (⟨C, hC₁.le⟩ : ℝ≥0) ≤ ‖x‖₊ then x else 0) ∘ (f i), { ext x, simp only [set.indicator, set.mem_set_of_eq] }, simp_rw [coe_nnnorm, this], rw [← snorm_map_measure _ (hf i).ae_measurable_fst, (hf i).map_eq, snorm_map_measure _ (hf j).ae_measurable_fst], { refl }, all_goals { exact ae_strongly_measurable_id.indicator (measurable_set_le measurable_const measurable_nnnorm) }, end /-- A sequence of identically distributed Lᵖ functions is p-uniformly integrable. -/ lemma mem_ℒp.uniform_integrable_of_ident_distrib {ι : Type*} {f : ι → α → E} {j : ι} {p : ℝ≥0∞} (hp : 1 ≤ p) (hp' : p ≠ ∞) (hℒp : mem_ℒp (f j) p μ) (hf : ∀ i, ident_distrib (f i) (f j) μ μ) : uniform_integrable f p μ := begin have hfmeas : ∀ i, ae_strongly_measurable (f i) μ := λ i, (hf i).ae_strongly_measurable_iff.2 hℒp.1, set g : ι → α → E := λ i, (hfmeas i).some, have hgmeas : ∀ i, strongly_measurable (g i) := λ i, (Exists.some_spec $ hfmeas i).1, have hgeq : ∀ i, g i =ᵐ[μ] f i := λ i, (Exists.some_spec $ hfmeas i).2.symm, have hgℒp : mem_ℒp (g j) p μ := hℒp.ae_eq (hgeq j).symm, exact uniform_integrable.ae_eq (mem_ℒp.uniform_integrable_of_ident_distrib_aux hp hp' hgℒp hgmeas $ λ i, (ident_distrib.of_ae_eq (hgmeas i).ae_measurable (hgeq i)).trans ((hf i).trans $ ident_distrib.of_ae_eq (hfmeas j).ae_measurable (hgeq j).symm)) hgeq, end end uniform_integrable end probability_theory
(* Copyright 2021 Joshua M. Cohen 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. *) From mathcomp Require Import all_ssreflect. Require Import mathcomp.algebra.ssralg. Require Import mathcomp.algebra.poly. Require Import mathcomp.algebra.polydiv. Require Import mathcomp.algebra.finalg. Require Import mathcomp.ssreflect.tuple. Require Import mathcomp.field.finfield. Set Implicit Arguments. Unset Strict Implicit. Unset Printing Implicit Defensive. Set Bullet Behavior "Strict Subproofs". (* Construction of finite fields via irreducible polynomials *) Section FieldConstr. Local Open Scope ring_scope. (*Some needed results about the Poly constructor - not general-purpose*) Section MorePoly. Variable R: ringType. Lemma Poly_nil (s: seq R): (all (eq_op^~0) s) = (polyseq (Poly s) == nil). Proof. elim: s => [/=| h t /= IHs]. by rewrite polyseq0. rewrite polyseq_cons. have->: nilp (Poly t) = (polyseq (Poly t) == [::]) by apply /nilP; case : (polyseq (Poly t) == [::]) /eqP. rewrite -IHs. case Allt: (all (eq_op^~ 0) t) =>/=; last by rewrite andbF. case: (h == 0) /eqP => [ eq_h0 | /eqP neq_h0]. by rewrite eq_h0 polyseqC eq_refl. by rewrite polyseqC/= neq_h0. Qed. Lemma Poly_split (s: seq R): ~~(all (eq_op^~ 0) s) -> exists s1, (s == Poly s ++ s1) && (all (eq_op^~ 0) s1). Proof. elim: s => [//| h t/= IHs]. case Allt: (all (eq_op^~ 0) t) =>/=. move=> /nandP[eq_h0 | //]; exists t. rewrite polyseq_cons polyseqC eq_h0. move: Allt; rewrite Poly_nil => /eqP->/=. by rewrite eq_refl. move=> _. rewrite polyseq_cons. have->/=: nilp (Poly t) = false by apply /nilP /eqP; rewrite -Poly_nil Allt. apply negbT, IHs in Allt. case: Allt => [s1 /andP[/eqP t_eq all_s1]]. exists s1. by rewrite {1}t_eq all_s1 eq_refl. Qed. Lemma Poly_cat (s1 s2 : seq R): all (eq_op^~0) s2 -> Poly (s1 ++ s2) = Poly s1. Proof. elim: s1 => [/= all_s2| h t /= IHs all_s2]. by apply poly_inj; rewrite polyseq0; apply /eqP; rewrite -Poly_nil. by move: IHs => /(_ all_s2) ->. Qed. End MorePoly. (* We require that the type is finite so that the resulting field is finite. *) (* We need an integral domain for [irreducible_poly]. *) (* Every finite integral domain is a (finite) field. *) Variable F : finFieldType. Variable p : {poly F}. Variable p_irred: irreducible_poly p. (*A polynomial quotiented by p*) Inductive qpoly : predArgType := Qpoly (qp : {poly F}) of (size qp < size p). Coercion qp (q: qpoly) : {poly F} := let: Qpoly x _ := q in x. Definition qsz (q: qpoly) : size q < size p := let: Qpoly _ x := q in x. Canonical qpoly_subType := [subType for qp]. Definition qpoly_eqMixin := Eval hnf in [eqMixin of qpoly by <:]. Canonical qpoly_eqType := Eval hnf in EqType qpoly qpoly_eqMixin. Definition qpoly_choiceMixin := [choiceMixin of qpoly by <:]. Canonical qpoly_choiceType := Eval hnf in ChoiceType qpoly qpoly_choiceMixin. Definition qpoly_countMixin := [countMixin of qpoly by <:]. Canonical qpoly_countType := Eval hnf in CountType qpoly qpoly_countMixin. Canonical qpoly_subCountType := [subCountType of qpoly]. Lemma qpoly_inj: injective qp. Proof. exact: val_inj. Qed. (* Size of the Finite Field *) (* We prove the cardinality of this set by giving a mapping from qpolys to *) (* tuples of length (size).-1 *) Definition qpoly_seq (q: qpoly) : seq F := q ++ nseq ((size p).-1 - size q) 0. Lemma p_gt_0: 0 < size p. Proof. have lt_01 : 0 < 1 by []. apply (ltn_trans lt_01). by apply p_irred. Qed. Lemma leq_predR m n : 0 < n -> (m <= n.-1) = (m < n). Proof. by case : n => [//|n/= _]; rewrite ltnS. Qed. Lemma qpoly_seq_size q: size (qpoly_seq q) == (size p).-1. Proof. apply /eqP; rewrite /qpoly_seq size_cat size_nseq subnKC //. case : q => [x Szx /=]. by rewrite leq_predR // p_gt_0. Qed. Definition qpoly_tuple q : ((size p).-1).-tuple F := Tuple (qpoly_seq_size q). Definition tuple_poly (t: ((size p).-1).-tuple F) : {poly F} := Poly t. Lemma tuple_poly_size t: size (tuple_poly t) < size p. Proof. have szt: size t = ((size p).-1) by apply size_tuple. have lt_tp: size t < size p by rewrite szt ltn_predL p_gt_0. by apply (leq_ltn_trans (size_Poly t)). Qed. Definition tuple_qpoly (t: ((size p).-1).-tuple F) : qpoly := Qpoly (tuple_poly_size t). Lemma tuple_qpoly_cancel: cancel tuple_qpoly qpoly_tuple. Proof. move=> [t sz_t]; rewrite /qpoly_tuple /tuple_qpoly/=. apply val_inj=>/=. rewrite /tuple_poly/qpoly_seq/=. move: sz_t => /eqP sz_t. case Allt: (all (eq_op^~0) t). have nseqt:=Allt; move: Allt. rewrite Poly_nil => /eqP->/=. symmetry; rewrite subn0 -sz_t; apply /all_pred1P. exact: nseqt. apply negbT, Poly_split in Allt. case : Allt => [tl /andP[/eqP t_eq tl_all]]. rewrite {3}t_eq; f_equal. have <-: size tl = ((size p).-1 - size (Poly t))%N by rewrite -sz_t {1}t_eq size_cat -addnBAC // subnn. by symmetry; apply /all_pred1P. Qed. Lemma qpoly_tuple_cancel: cancel qpoly_tuple tuple_qpoly. Proof. move=> [q q_sz]; rewrite /qpoly_tuple /tuple_qpoly/=. apply val_inj=>/=. rewrite /tuple_poly /qpoly_seq /=. rewrite Poly_cat //; first by apply polyseqK. by apply /all_pred1P; rewrite size_nseq. Qed. Lemma qpoly_tuple_bij: bijective qpoly_tuple. Proof. apply (Bijective qpoly_tuple_cancel tuple_qpoly_cancel). Qed. Definition qpoly_finMixin := CanFinMixin qpoly_tuple_cancel. Canonical qpoly_finType := Eval hnf in FinType qpoly qpoly_finMixin. Lemma qpoly_size: #|qpoly| = (#|F|^((size p).-1))%N. Proof. by rewrite (bij_eq_card qpoly_tuple_bij) card_tuple. Qed. (* Algebraic Structures*) (* Z Module *) Lemma q0_size: size (0 : {poly F}) < size p. Proof. by rewrite size_poly0 p_gt_0. Qed. Lemma q1_size : size (1 : {poly F}) < size p. Proof. by rewrite size_poly1 p_irred. Qed. Definition q0 : qpoly := Qpoly q0_size. Definition q1 : qpoly := Qpoly q1_size. Lemma qadd_size (q1 q2: qpoly) : size (val q1 + val q2) < size p. Proof. apply (leq_ltn_trans (size_add q1 q2)). rewrite gtn_max. by apply /andP; split; apply qsz. Qed. Definition qadd (q1 q2: qpoly) : qpoly := Qpoly (qadd_size q1 q2). Lemma qopp_size (q: qpoly) : size (-(val q)) < size p. Proof. by rewrite size_opp; apply qsz. Qed. Definition qopp (q: qpoly) := Qpoly (qopp_size q). Lemma qaddA : associative qadd. Proof. move=> q1 q2 q3; rewrite /qadd; apply qpoly_inj=>/=. by rewrite GRing.addrA. Qed. Lemma qaddC : commutative qadd. Proof. move=> q1 q2; rewrite /qadd; apply qpoly_inj=>/=. by rewrite GRing.addrC. Qed. Lemma qaddFq : left_id q0 qadd. Proof. move=> q; rewrite /qadd /q0; apply qpoly_inj=>/=. by rewrite GRing.add0r. Qed. Lemma qaddqq : left_inverse q0 qopp qadd. Proof. move=> q; rewrite /qadd /qopp /q0; apply qpoly_inj=>/=. by rewrite GRing.addrC GRing.subrr. Qed. Definition qpoly_zmodMixin := ZmodMixin qaddA qaddC qaddFq qaddqq. Canonical qpoly_zmodType := ZmodType qpoly qpoly_zmodMixin. (* Ring *) Lemma qmul_size (p1 p2: {poly F}) : size ((p1 * p2) %% p) < size p. Proof. by rewrite ltn_modp; apply irredp_neq0. Qed. Definition qmul (q1 q2 : qpoly) : qpoly := Qpoly (qmul_size q1 q2). Lemma qpoly_mulA : associative qmul. Proof. move=> q1 q2 q3; rewrite /qmul; apply qpoly_inj=>/=. by rewrite (GRing.mulrC ((qp q1 * qp q2) %% p)) !modp_mul (GRing.mulrC _ (qp q1 * qp q2)) GRing.mulrA. Qed. Lemma qpoly_mulC: commutative qmul. Proof. move=> q1 q2; rewrite /qmul; apply qpoly_inj=>/=. by rewrite GRing.mulrC. Qed. Lemma qpoly_mul1q: left_id q1 qmul. Proof. move=> q. rewrite /qmul /q1; apply qpoly_inj=>/=. by rewrite GRing.mul1r modp_small //; apply qsz. Qed. Lemma qpoly_mulD : left_distributive qmul qadd. Proof. move=>q1 q2 q3; rewrite /qmul /qadd; apply qpoly_inj=>/=. by rewrite -modpD GRing.mulrDl. Qed. Lemma qpoly_1not0: q1 != q0. Proof. case: (q1 == q0) /eqP => //. rewrite /q0 /q1 /= => [[eq_1_0]]. have neq_1_0:=(GRing.oner_neq0 (poly_ringType F)). move: neq_1_0. by rewrite eq_1_0 eq_refl. Qed. Definition qpoly_comRingMixin := ComRingMixin qpoly_mulA qpoly_mulC qpoly_mul1q qpoly_mulD qpoly_1not0. Canonical qpoly_ringType := RingType qpoly qpoly_comRingMixin. Canonical qpoly_comRingType := ComRingType qpoly qpoly_mulC. (* Now we want to show that inverses exist and are computable. *) (* We do this in several steps *) Definition prime_poly (p: {poly F}) : Prop := forall (q r : {poly F}), p %| (q * r) -> (p %| q) || (p %| r). Lemma irred_is_prime (r : {poly F}): irreducible_poly r -> prime_poly r. Proof. move=> r_irred s t r_div_st. have [[u v]/= bez] := (Bezoutp r s). case r_div_s: (r %| s) =>//=. have rs_coprime: size (gcdp r s) == 1%N; last by rewrite -(Gauss_dvdpr _ rs_coprime). case gcd_sz: (size (gcdp r s) == 1%N) => //. have gcd_div := (dvdp_gcdl r s). apply r_irred in gcd_div; last by apply negbT. move: gcd_div. by rewrite /eqp dvdp_gcd r_div_s !andbF. Qed. Lemma qpoly_zero (q: qpoly) : (q == 0) = (qp q %% p == 0). Proof. case: q => [q q_sz]/=. have->: 0 = q0 by []. by rewrite /q0 modp_small. Qed. (* The following actually shows that any finite integral domain is a field *) Lemma qpoly_mulf_eq0 (q1 q2: qpoly) : (q1 * q2) = 0 -> (q1 == 0) || (q2 == 0). Proof. have->:(q1 * q2) = qmul q1 q2 by []. have->:0 = q0 by []. rewrite /qmul /= => [[/ modp_eq0P p_div_q12]]. rewrite !qpoly_zero. by apply irred_is_prime. Qed. Lemma qpoly_cancel (q1 q2 q3: qpoly): q1 != 0 -> q1 * q2 = q1 * q3 -> q2 = q3. Proof. move=> q1_neq0 q12_13. have q1_sub_q23: q1 * (q2 - q3) = 0 by rewrite GRing.mulrBr q12_13 GRing.subrr. apply qpoly_mulf_eq0 in q1_sub_q23. move: q1_sub_q23 => /orP[ /eqP q1_eq0 | /eqP eq_q23]. by move: q1_neq0; rewrite q1_eq0 eq_refl. by apply GRing.subr0_eq. Qed. (* To show that inverses exist, we define the map f_q(x) = q * x and we show *) (* that this is injective (and thus bijective since the set is finite) *) (* if q != 0 *) Definition qmul_map (q: qpoly) := qmul q. Lemma qmul_map_inj (q: qpoly) : q != 0 -> injective (qmul_map q). Proof. move=> q_neq_0 q1 q2. by apply qpoly_cancel. Qed. Lemma mul_map_bij (q: qpoly): q != 0 -> bijective (qmul_map q). Proof. move=> q_neq_0. by apply injF_bij, qmul_map_inj. Qed. Lemma qpoly_inv_exist (q: qpoly): q != 0 -> exists (inv: qpoly), inv * q = 1. Proof. move=> q_neq_0. apply mul_map_bij in q_neq_0. case : q_neq_0 => g can1 can2. exists (g 1). move: can2 => /( _ 1). by rewrite GRing.mulrC. Qed. (* A (slow) computable inverse function from the above *) Definition qinv (q: qpoly) := nth q0 (enum qpoly) (find (fun x => x * q == 1) (enum qpoly)). Lemma qinv_correct (q: qpoly): q != 0 -> (qinv q) * q = 1. Proof. move=>q_neq_0. apply /eqP; rewrite /qinv. have has_inv: has (fun x => x * q == 1) (enum qpoly); last by apply (nth_find q0) in has_inv. apply /hasP. apply qpoly_inv_exist in q_neq_0. case: q_neq_0 => [inv inv_correct]. exists inv; last by apply /eqP. have inv_count: count_mem inv (enum qpoly) = 1%N by rewrite enumT; apply enumP. apply /count_memPn. by rewrite inv_count. Qed. Lemma qinv_zero: qinv 0 = 0. Proof. have not_has: ~~ has (fun x => x * 0 == 1) (enum qpoly). apply /hasP. by move=>[r _ ]; rewrite GRing.mulr0 eq_sym GRing.oner_eq0. by rewrite /qinv hasNfind // nth_default. Qed. (* The rest of the algebraic structures: *) (* ComUnitRing *) Definition qunit : pred qpoly := fun x => x != q0. Lemma qpoly_mulVr : {in qunit, left_inverse q1 qinv qmul}. Proof. move=> q q_in. by apply qinv_correct. Qed. Lemma qpoly_mulrV : {in qunit, right_inverse q1 qinv qmul}. Proof. move=>q q_in. by rewrite qpoly_mulC; apply qpoly_mulVr. Qed. Lemma qpoly_unitP (q1 q2: qpoly): (q2 * q1) = 1 /\ (q1 * q2) = 1 -> qunit q1. Proof. move=> [q21_1 q12_1]. rewrite /qunit; apply /eqP => q1_eq_0. move: q12_1; rewrite q1_eq_0. by rewrite GRing.mul0r => /eqP; rewrite eq_sym GRing.oner_eq0. Qed. Lemma qpoly_inv0id : {in [predC qunit], qinv =1 id}. Proof. move=>q q_unit. have: ~~ (q != 0) by []. rewrite negbK => /eqP->. by rewrite qinv_zero. Qed. Definition qpoly_unitringmixin := UnitRingMixin qpoly_mulVr qpoly_mulrV qpoly_unitP qpoly_inv0id. Canonical qpoly_unitringtype := UnitRingType qpoly qpoly_unitringmixin. Canonical qpoly_comunitring := [comUnitRingType of qpoly]. (*Integral Domain *) Canonical qpoly_idomaintype := IdomainType qpoly qpoly_mulf_eq0. (* Field *) Lemma qpoly_mulVf : GRing.Field.axiom qinv. Proof. move=> q q_neq_0. by apply qpoly_mulVr. Qed. Lemma qpoly_inv0: qinv 0%R = 0%R. Proof. exact: qinv_zero. Qed. Definition qpoly_fieldmixin := FieldMixin qpoly_mulVf qpoly_inv0. Canonical qpoly_fieldType := FieldType qpoly qpoly_fieldmixin. Canonical qpoly_finFieldType := Eval hnf in [finFieldType of qpoly]. (* Fields over primitive polynomials *) Section Primitive. Definition primitive_poly (p: {poly F}) : Prop := irreducible_poly p /\ p %| 'X^((#|F|^((size p).-1)).-1) - 1 /\ (forall n, p %| 'X^n - 1 -> (n == 0%N) || (((#|F|^((size p).-1)).-1) <= n)). Variable p_prim: primitive_poly p. (* We want to prove that discrete logs exist for all nonzero elements. *) (* We do not consider the trivial case where p = cx for constant c. *) (* This case is not very interesting, since F[X]/(x) is isomorphic to F. *) Variable p_notx: 2 < size p. Lemma qx_size: size (polyX F) < size p. Proof. by rewrite size_polyX. Qed. (* The primitive element x *) Definition qx : qpoly := Qpoly qx_size. Lemma qx_exp (n: nat): qp (qx ^+ n) = ('X^n) %% p. Proof. elim: n => [/= | n /= IHn]. by rewrite GRing.expr0 modp_small // size_poly1; apply p_irred. rewrite !GRing.exprSr. have->: qx ^+ n * qx = qmul (qx ^+ n) qx by []. by rewrite /qmul/= IHn GRing.mulrC modp_mul GRing.mulrC. Qed. (* To show that discrete logs exist, we use the following map and show that is *) (* is bijective. *) Section DlogEx. Lemma qx_neq0: qx != 0. Proof. have->: 0 = q0 by []. rewrite /qx/q0/=. case: (Qpoly qx_size == Qpoly q0_size) /eqP => // [[/eqP eq_x0]]. by rewrite polyX_eq0 in eq_x0. Qed. Lemma qxn_neq0 (n: nat): qx ^+ n != 0. Proof. by apply GRing.expf_neq0, qx_neq0. Qed. Definition dlog_ord := 'I_((#|F|^((size p).-1)).-1). (*Logs only exist for nonzero (or unit) qpolys*) Inductive qpolyNZ : predArgType := Qnz (qq: qpoly) of (qunit qq). Coercion qq (q: qpolyNZ) : qpoly := let: Qnz x _ := q in x. Definition qun (q: qpolyNZ) : qunit q := let: Qnz _ x := q in x. Canonical qpolyNZ_subType := [subType for qq]. Definition qpolyNZ_eqMixin := Eval hnf in [eqMixin of qpolyNZ by <:]. Canonical qpolyNZ_eqType := Eval hnf in EqType qpolyNZ qpolyNZ_eqMixin. Definition qpolyNZ_choiceMixin := [choiceMixin of qpolyNZ by <:]. Canonical qpolyNZ_choiceType := Eval hnf in ChoiceType qpolyNZ qpolyNZ_choiceMixin. Definition qpolyNZ_countMixin := [countMixin of qpolyNZ by <:]. Canonical qpolyNZ_countType := Eval hnf in CountType qpolyNZ qpolyNZ_countMixin. Canonical qpolyNZ_subCountType := [subCountType of qpolyNZ]. Definition qpolyNZ_finMixin := Eval hnf in [finMixin of qpolyNZ by <:]. Canonical qpolyNZ_finType := Eval hnf in FinType qpolyNZ qpolyNZ_finMixin. Canonical subFinType := [subFinType of qpolyNZ]. Lemma qpolyNZ_card: #|qpolyNZ| = #|qpoly|.-1. Proof. have uniq_sz:=(card_finField_unit qpoly_finFieldType). move: uniq_sz; rewrite cardsT/= => <-. by rewrite !card_sub. Qed. Lemma qx_unit : qunit qx. Proof. by rewrite /qunit qx_neq0. Qed. Lemma qpow_unit (n: nat) : qunit (qx ^+ n). Proof. by rewrite /qunit qxn_neq0. Qed. Definition qpow_map (i: dlog_ord) : qpolyNZ := Qnz (qpow_unit i). (* We need to know that p does not divide x^n for any n *) Lemma irred_dvdn_Xn (r: {poly F}) (n: nat): irreducible_poly r -> 2 < size r -> ~~ (r %| 'X^n). Proof. move=> r_irred r_size. elim: n => [| n /= IHn]. rewrite GRing.expr0 dvdp1. by apply /eqP => r_eq_1; rewrite r_eq_1 in r_size. rewrite GRing.exprS. case r_div: (r %| 'X * 'X^n) => //. apply (irred_is_prime r_irred) in r_div. move: r_div => /orP[r_divx | r_divxn]; last by rewrite r_divxn in IHn. apply dvdp_leq in r_divx; last by rewrite polyX_eq0. by move: r_divx; rewrite size_polyX leqNgt r_size. Qed. (* A weaker lemma than [modpD] *) Lemma modpD_wk (d q r : {poly F}): d != 0 -> (q + r) %% d = (q %% d + r %% d) %% d. Proof. move=> d_neq0; rewrite modpD. by rewrite (@modp_small _ (_ + _)) // -modpD ltn_modp. Qed. Lemma qpow_map_bij: bijective qpow_map. Proof. apply inj_card_bij; last by rewrite qpolyNZ_card qpoly_size card_ord leqnn. move=> n1 n2; rewrite /qpow_map/= => [[]]. wlog: n1 n2 / (n1 <= n2). move=> all_eq. case: (orP (leq_total n1 n2)) => [n1_leqn2 | n2_leqn1]. by apply all_eq. by move=> qx_n12; symmetry; apply all_eq. move=> n1_leqn2 qx_n12. have: (qx ^+ n2 - qx ^+ n1 = 0) by rewrite qx_n12 GRing.subrr. rewrite -(subnKC n1_leqn2) GRing.exprD. rewrite -{2}(GRing.mulr1 (qx ^+ n1)) -GRing.mulrBr. move=> /eqP; rewrite GRing.mulf_eq0 => /orP[/eqP xn_eq0|]. by have /eqP qn1_x := (negbTE (qxn_neq0 n1)). rewrite qpoly_zero/= qx_exp GRing.addrC modpD_wk; last by apply irredp_neq0. rewrite modp_mod GRing.addrC -modpD modp_mod => n21_div_p. apply p_prim in n21_div_p. move: n21_div_p => /orP[| n12_big]. rewrite subn_eq0 => n2_leqn1; apply ord_inj; apply /eqP; rewrite eqn_leq. by rewrite n1_leqn2 n2_leqn1. have n2_bound: n2 < (#|F| ^ (size p).-1).-1 by []. have n12_bound: n2 - n1 <= n2 by rewrite leq_subr. have lt_contra:= (leq_ltn_trans (leq_trans n12_big n12_bound) n2_bound). by rewrite ltnn in lt_contra. Qed. (* The inverse map (discrete log)*) Lemma field_gt0: 0 < (#|F|^((size p).-1)).-1. Proof. rewrite -qpoly_size -qpolyNZ_card; apply /card_gt0P. by exists (Qnz qx_unit). Qed. Definition dlog_map (q : qpolyNZ) : dlog_ord := nth (Ordinal field_gt0) (enum dlog_ord) (find (fun i => (qx ^+ (nat_of_ord i) == q)) (enum dlog_ord)). Lemma dlog_map_exist (q: qpolyNZ): exists (i: dlog_ord), (qx ^+ i == q). Proof. case: (qpow_map_bij) => g canqg cangq. exists (g q). move: cangq => /(_ q)/=; rewrite /qpow_map => q_eq. apply (f_equal val) in q_eq. by move: q_eq =>/=->; rewrite eq_refl. Qed. Lemma dlog_map_correct (q: qpolyNZ): (qx ^+ (dlog_map q) = q). Proof. rewrite /dlog_map. have has_dlog: has (fun i =>(qx ^+ (nat_of_ord i) == q)) (enum dlog_ord); last by apply /eqP; apply (nth_find (Ordinal field_gt0)) in has_dlog. apply /hasP. have [n n_log]:=(dlog_map_exist q). exists n => //. have n_count: count_mem n (enum dlog_ord) = 1%N by rewrite enumT; apply enumP. apply /count_memPn. by rewrite n_count. Qed. Lemma dlog_map_can: cancel dlog_map qpow_map. Proof. move=> q; rewrite /qpow_map; apply val_inj=>/=. by rewrite dlog_map_correct. Qed. Lemma qpow_map_can: cancel qpow_map dlog_map. Proof. rewrite -bij_can_sym. exact: dlog_map_can. exact: qpow_map_bij. Qed. Lemma dlog_map_bij: bijective dlog_map. Proof. exact: (bij_can_bij qpow_map_bij qpow_map_can). Qed. Lemma dlog_map_inj: injective dlog_map. Proof. exact: (bij_inj dlog_map_bij). Qed. End DlogEx. (* The full discrete log function, with dlog(0) = 0 *) Definition dlog (q: qpoly) : dlog_ord := (match (qunit q) as u return (qunit q = u -> dlog_ord) with | true => fun q_unit => dlog_map (Qnz q_unit) | false => fun _ => (Ordinal field_gt0) end) erefl. Lemma exp_dlog (q: qpoly): q != 0 -> qx ^+ (dlog q) = q. Proof. move=> q_neq0. have q_unit: qunit q by []. rewrite /dlog; move: erefl. case: {2 3}(qunit q); last by rewrite q_unit. by move=> q_unit'/=; rewrite dlog_map_correct. Qed. Lemma dlog0: nat_of_ord (dlog 0) = 0%N. Proof. rewrite /dlog; move: erefl. have unit_zero: qunit 0 = false by rewrite /qunit eq_refl. case: {2 3}(qunit 0) => //. move=> zero_unit. have: qunit 0 = true by []. by rewrite unit_zero. Qed. Lemma dlog_exp (i: dlog_ord): dlog(qx ^+ i) = i. Proof. have->:qx ^+ i = qpow_map i by []. have->: dlog (qpow_map i) = dlog_map (qpow_map i); last by rewrite qpow_map_can. rewrite /dlog; move: erefl. case: {2 3}(qunit (qpow_map i)) => //. move=> qpow_nunit. have: qunit (qpow_map i) = true by apply qun. by rewrite {1}qpow_nunit. Qed. (* From definition of primitive poly *) Lemma qx_field_sz1: qx ^+ (#|F| ^ (size p).-1).-1 = 1. Proof. apply qpoly_inj =>/=; rewrite qx_exp. case p_prim => [_ [p_div _]]. move: p_div. rewrite /dvdp modpD modNp (@modp_small _ 1); last by rewrite size_poly1 (ltn_trans _ p_notx). by rewrite GRing.subr_eq0 => /eqP. Qed. Lemma qpoly_exp_modn (m n: nat) : m = n %[mod (#|F| ^ (size p).-1).-1] -> qx ^+ m = qx ^+ n. Proof. move=> mn_eqmod. rewrite (divn_eq m (#|F| ^ (size p).-1).-1) (divn_eq n (#|F| ^ (size p).-1).-1). rewrite !GRing.exprD !(mulnC _ ((#|F| ^ (size p).-1).-1)). rewrite !GRing.exprM !qx_field_sz1 !GRing.expr1n !GRing.mul1r. by rewrite mn_eqmod. Qed. End Primitive. End FieldConstr.
[STATEMENT] lemma derived_set_of_infinite_openin: "Hausdorff_space X \<Longrightarrow> X derived_set_of S = {x \<in> topspace X. \<forall>U. x \<in> U \<and> openin X U \<longrightarrow> infinite(S \<inter> U)}" [PROOF STATE] proof (prove) goal (1 subgoal): 1. Hausdorff_space X \<Longrightarrow> X derived_set_of S = {x \<in> topspace X. \<forall>U. x \<in> U \<and> openin X U \<longrightarrow> infinite (S \<inter> U)} [PROOF STEP] using Hausdorff_imp_t1_space t1_space_derived_set_of_infinite_openin [PROOF STATE] proof (prove) using this: Hausdorff_space ?X \<Longrightarrow> t1_space ?X t1_space ?X = (\<forall>S. ?X derived_set_of S = {x \<in> topspace ?X. \<forall>U. x \<in> U \<and> openin ?X U \<longrightarrow> infinite (S \<inter> U)}) goal (1 subgoal): 1. Hausdorff_space X \<Longrightarrow> X derived_set_of S = {x \<in> topspace X. \<forall>U. x \<in> U \<and> openin X U \<longrightarrow> infinite (S \<inter> U)} [PROOF STEP] by fastforce
# Session 2 - Training a Network w/ Tensorflow <p class="lead"> Assignment: Teach a Deep Neural Network to Paint </p> <p class="lead"> Parag K. Mital<br /> <a href="https://www.kadenze.com/courses/creative-applications-of-deep-learning-with-tensorflow/info">Creative Applications of Deep Learning w/ Tensorflow</a><br /> <a href="https://www.kadenze.com/partners/kadenze-academy">Kadenze Academy</a><br /> <a href="https://twitter.com/hashtag/CADL">#CADL</a> </p> This work is licensed under a <a rel="license" href="http://creativecommons.org/licenses/by-nc-sa/4.0/">Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License</a>. # Learning Goals * Learn how to create a Neural Network * Learn to use a neural network to paint an image * Apply creative thinking to the inputs, outputs, and definition of a network # Outline <!-- MarkdownTOC autolink=true autoanchor=true bracket=round --> - [Assignment Synopsis](#assignment-synopsis) - [Part One - Fully Connected Network](#part-one---fully-connected-network) - [Instructions](#instructions) - [Code](#code) - [Variable Scopes](#variable-scopes) - [Part Two - Image Painting Network](#part-two---image-painting-network) - [Instructions](#instructions-1) - [Preparing the Data](#preparing-the-data) - [Cost Function](#cost-function) - [Explore](#explore) - [A Note on Crossvalidation](#a-note-on-crossvalidation) - [Part Three - Learning More than One Image](#part-three---learning-more-than-one-image) - [Instructions](#instructions-2) - [Code](#code-1) - [Part Four - Open Exploration \(Extra Credit\)](#part-four---open-exploration-extra-credit) - [Assignment Submission](#assignment-submission) <!-- /MarkdownTOC --> This next section will just make sure you have the right version of python and the libraries that we'll be using. Don't change the code here but make sure you "run" it (use "shift+enter")! ```python # First check the Python version import sys if sys.version_info < (3,4): print('You are running an older version of Python!\n\n' \ 'You should consider updating to Python 3.4.0 or ' \ 'higher as the libraries built for this course ' \ 'have only been tested in Python 3.4 and higher.\n') print('Try installing the Python 3.5 version of anaconda ' 'and then restart `jupyter notebook`:\n' \ 'https://www.continuum.io/downloads\n\n') # Now get necessary libraries try: import os import numpy as np import matplotlib.pyplot as plt from skimage.transform import resize from skimage import data from scipy.misc import imresize except ImportError: print('You are missing some packages! ' \ 'We will try installing them before continuing!') !pip install "numpy>=1.11.0" "matplotlib>=1.5.1" "scikit-image>=0.11.3" "scikit-learn>=0.17" "scipy>=0.17.0" import os import numpy as np import matplotlib.pyplot as plt from skimage.transform import resize from skimage import data from scipy.misc import imresize print('Done!') # Import Tensorflow try: import tensorflow as tf except ImportError: print("You do not have tensorflow installed!") print("Follow the instructions on the following link") print("to install tensorflow before continuing:") print("") print("https://github.com/pkmital/CADL#installation-preliminaries") # This cell includes the provided libraries from the zip file # and a library for displaying images from ipython, which # we will use to display the gif try: from libs import utils, gif import IPython.display as ipyd except ImportError: print("Make sure you have started notebook in the same directory" + " as the provided zip file which includes the 'libs' folder" + " and the file 'utils.py' inside of it. You will NOT be able" " to complete this assignment unless you restart jupyter" " notebook inside the directory created by extracting" " the zip file or cloning the github repo.") # We'll tell matplotlib to inline any drawn figures like so: %matplotlib inline plt.style.use('ggplot') ``` ```python # Bit of formatting because I don't like the default inline code style: from IPython.core.display import HTML HTML("""<style> .rendered_html code { padding: 2px 4px; color: #c7254e; background-color: #f9f2f4; border-radius: 4px; } </style>""") ``` <style> .rendered_html code { padding: 2px 4px; color: #c7254e; background-color: #f9f2f4; border-radius: 4px; } </style> <a name="assignment-synopsis"></a> # Assignment Synopsis In this assignment, we're going to create our first neural network capable of taking any two continuous values as inputs. Those two values will go through a series of multiplications, additions, and nonlinearities, coming out of the network as 3 outputs. Remember from the last homework, we used convolution to filter an image so that the representations in the image were accentuated. We're not going to be using convolution w/ Neural Networks until the next session, but we're effectively doing the same thing here: using multiplications to accentuate the representations in our data, in order to minimize whatever our cost function is. To find out what those multiplications need to be, we're going to use Gradient Descent and Backpropagation, which will take our cost, and find the appropriate updates to all the parameters in our network to best optimize the cost. In the next session, we'll explore much bigger networks and convolution. This "toy" network is really to help us get up and running with neural networks, and aid our exploration of the different components that make up a neural network. You will be expected to explore manipulations of the neural networks in this notebook as much as possible to help aid your understanding of how they effect the final result. We're going to build our first neural network to understand what color "to paint" given a location in an image, or the row, col of the image. So in goes a row/col, and out goes a R/G/B. In the next lesson, we'll learn what this network is really doing is performing regression. For now, we'll focus on the creative applications of such a network to help us get a better understanding of the different components that make up the neural network. You'll be asked to explore many of the different components of a neural network, including changing the inputs/outputs (i.e. the dataset), the number of layers, their activation functions, the cost functions, learning rate, and batch size. You'll also explore a modification to this same network which takes a 3rd input: an index for an image. This will let us try to learn multiple images at once, though with limited success. We'll now dive right into creating deep neural networks, and I'm going to show you the math along the way. Don't worry if a lot of it doesn't make sense, and it really takes a bit of practice before it starts to come together. <a name="part-one---fully-connected-network"></a> # Part One - Fully Connected Network <a name="instructions"></a> ## Instructions Create the operations necessary for connecting an input to a network, defined by a `tf.Placeholder`, to a series of fully connected, or linear, layers, using the formula: $$\textbf{H} = \phi(\textbf{X}\textbf{W} + \textbf{b})$$ where $\textbf{H}$ is an output layer representing the "hidden" activations of a network, $\phi$ represents some nonlinearity, $\textbf{X}$ represents an input to that layer, $\textbf{W}$ is that layer's weight matrix, and $\textbf{b}$ is that layer's bias. If you're thinking, what is going on? Where did all that math come from? Don't be afraid of it. Once you learn how to "speak" the symbolic representation of the equation, it starts to get easier. And once we put it into practice with some code, it should start to feel like there is some association with what is written in the equation, and what we've written in code. Practice trying to say the equation in a meaningful way: "The output of a hidden layer is equal to some input multiplied by another matrix, adding some bias, and applying a non-linearity". Or perhaps: "The hidden layer is equal to a nonlinearity applied to an input multiplied by a matrix and adding some bias". Explore your own interpretations of the equation, or ways of describing it, and it starts to become much, much easier to apply the equation. The first thing that happens in this equation is the input matrix $\textbf{X}$ is multiplied by another matrix, $\textbf{W}$. This is the most complicated part of the equation. It's performing matrix multiplication, as we've seen from last session, and is effectively scaling and rotating our input. The bias $\textbf{b}$ allows for a global shift in the resulting values. Finally, the nonlinearity of $\phi$ allows the input space to be nonlinearly warped, allowing it to express a lot more interesting distributions of data. Have a look below at some common nonlinearities. If you're unfamiliar with looking at graphs like this, it is common to read the horizontal axis as X, as the input, and the vertical axis as Y, as the output. ```python xs = np.linspace(-6, 6, 100) plt.plot(xs, np.maximum(xs, 0), label='relu') plt.plot(xs, 1 / (1 + np.exp(-xs)), label='sigmoid') plt.plot(xs, np.tanh(xs), label='tanh') plt.xlabel('Input') plt.xlim([-6, 6]) plt.ylabel('Output') plt.ylim([-1.5, 1.5]) plt.title('Common Activation Functions/Nonlinearities') plt.legend(loc='lower right') ``` Remember, having series of linear followed by nonlinear operations is what makes neural networks expressive. By stacking a lot of "linear" + "nonlinear" operations in a series, we can create a deep neural network! Have a look at the output ranges of the above nonlinearity when considering which nonlinearity seems most appropriate. For instance, the `relu` is always above 0, but does not saturate at any value above 0, meaning it can be anything above 0. That's unlike the `sigmoid` which does saturate at both 0 and 1, meaning its values for a single output neuron will always be between 0 and 1. Similarly, the `tanh` saturates at -1 and 1. Choosing between these is often a matter of trial and error. Though you can make some insights depending on your normalization scheme. For instance, if your output is expected to be in the range of 0 to 1, you may not want to use a `tanh` function, which ranges from -1 to 1, but likely would want to use a `sigmoid`. Keep the ranges of these activation functions in mind when designing your network, especially the final output layer of your network. <a name="code"></a> ## Code In this section, we're going to work out how to represent a fully connected neural network with code. First, create a 2D `tf.placeholder` called $\textbf{X}$ with `None` for the batch size and 2 features. Make its `dtype` `tf.float32`. Recall that we use the dimension of `None` for the batch size dimension to say that this dimension can be any number. Here is the docstring for the `tf.placeholder` function, have a look at what args it takes: Help on function placeholder in module `tensorflow.python.ops.array_ops`: ```python placeholder(dtype, shape=None, name=None) ``` Inserts a placeholder for a tensor that will be always fed. **Important**: This tensor will produce an error if evaluated. Its value must be fed using the `feed_dict` optional argument to `Session.run()`, `Tensor.eval()`, or `Operation.run()`. For example: ```python x = tf.placeholder(tf.float32, shape=(1024, 1024)) y = tf.matmul(x, x) with tf.Session() as sess: print(sess.run(y)) # ERROR: will fail because x was not fed. rand_array = np.random.rand(1024, 1024) print(sess.run(y, feed_dict={x: rand_array})) # Will succeed. ``` Args: dtype: The type of elements in the tensor to be fed. shape: The shape of the tensor to be fed (optional). If the shape is not specified, you can feed a tensor of any shape. name: A name for the operation (optional). Returns: A `Tensor` that may be used as a handle for feeding a value, but not evaluated directly. <h3><font color='red'>TODO! COMPLETE THIS SECTION!</font></h3> ```python # Create a placeholder with None x 2 dimensions of dtype tf.float32, and name it "X": X = tf.placeholder(dtype=tf.float32, shape=(None, 2), name='X') ``` Now multiply the tensor using a new variable, $\textbf{W}$, which has 2 rows and 20 columns, so that when it is left mutiplied by $\textbf{X}$, the output of the multiplication is None x 20, giving you 20 output neurons. Recall that the `tf.matmul` function takes two arguments, the left hand ($\textbf{X}$) and right hand side ($\textbf{W}$) of a matrix multiplication. To create $\textbf{W}$, you will use `tf.get_variable` to create a matrix which is `2 x 20` in dimension. Look up the docstrings of functions `tf.get_variable` and `tf.random_normal_initializer` to get familiar with these functions. There are many options we will ignore for now. Just be sure to set the `name`, `shape` (this is the one that has to be [2, 20]), `dtype` (i.e. tf.float32), and `initializer` (the `tf.random_normal_intializer` you should create) when creating your $\textbf{W}$ variable with `tf.get_variable(...)`. For the random normal initializer, often the mean is set to 0, and the standard deviation is set based on the number of neurons. But that really depends on the input and outputs of your network, how you've "normalized" your dataset, what your nonlinearity/activation function is, and what your expected range of inputs/outputs are. Don't worry about the values for the initializer for now, as this part will take a bit more experimentation to understand better! This part is to encourage you to learn how to look up the documentation on Tensorflow, ideally using `tf.get_variable?` in the notebook. If you are really stuck, just scroll down a bit and I've shown you how to use it. <h3><font color='red'>TODO! COMPLETE THIS SECTION!</font></h3> ```python W = tf.get_variable( name='W', shape=[2, 20], initializer=tf.random_normal_initializer(mean=0.0, stddev=0.1)) h = tf.matmul(X, W) ``` And add to this result another new variable, $\textbf{b}$, which has [20] dimensions. These values will be added to every output neuron after the multiplication above. Instead of the `tf.random_normal_initializer` that you used for creating $\textbf{W}$, now use the `tf.constant_initializer`. Often for bias, you'll set the constant bias initialization to 0 or 1. <h3><font color='red'>TODO! COMPLETE THIS SECTION!</font></h3> ```python b = tf.get_variable( name='b', shape=[20], initializer=tf.constant_initializer()) h = tf.nn.bias_add(W, b) ``` ```python tf.nn.bias_add? ``` So far we have done: $$\textbf{X}\textbf{W} + \textbf{b}$$ Finally, apply a nonlinear activation to this output, such as `tf.nn.relu`, to complete the equation: $$\textbf{H} = \phi(\textbf{X}\textbf{W} + \textbf{b})$$ <h3><font color='red'>TODO! COMPLETE THIS SECTION!</font></h3> ```python h = tf.nn.relu(h) ``` Now that we've done all of this work, let's stick it inside a function. I've already done this for you and placed it inside the `utils` module under the function name `linear`. We've already imported the `utils` module so we can call it like so, `utils.linear(...)`. The docstring is copied below, and the code itself. Note that this function is slightly different to the one in the lecture. It does not require you to specify `n_input`, and the input `scope` is called `name`. It also has a few more extras in there including automatically converting a 4-d input tensor to a 2-d tensor so that you can fully connect the layer with a matrix multiply (don't worry about what this means if it doesn't make sense!). ```python utils.linear?? ``` ```python def linear(x, n_output, name=None, activation=None, reuse=None): """Fully connected layer Parameters ---------- x : tf.Tensor Input tensor to connect n_output : int Number of output neurons name : None, optional Scope to apply Returns ------- op : tf.Tensor Output of fully connected layer. """ if len(x.get_shape()) != 2: x = flatten(x, reuse=reuse) n_input = x.get_shape().as_list()[1] with tf.variable_scope(name or "fc", reuse=reuse): W = tf.get_variable( name='W', shape=[n_input, n_output], dtype=tf.float32, initializer=tf.contrib.layers.xavier_initializer()) b = tf.get_variable( name='b', shape=[n_output], dtype=tf.float32, initializer=tf.constant_initializer(0.0)) h = tf.nn.bias_add( name='h', value=tf.matmul(x, W), bias=b) if activation: h = activation(h) return h, W ``` <a name="variable-scopes"></a> ## Variable Scopes Note that since we are using `variable_scope` and explicitly telling the scope which name we would like, if there is *already* a variable created with the same name, then Tensorflow will raise an exception! If this happens, you should consider one of three possible solutions: 1. If this happens while you are interactively editing a graph, you may need to reset the current graph: ```python tf.reset_default_graph() ``` You should really only have to use this if you are in an interactive console! If you are creating Python scripts to run via command line, you should really be using solution 3 listed below, and be explicit with your graph contexts! 2. If this happens and you were not expecting any name conflicts, then perhaps you had a typo and created another layer with the same name! That's a good reason to keep useful names for everything in your graph! 3. More likely, you should be using context managers when creating your graphs and running sessions. This works like so: ```python g = tf.Graph() with tf.Session(graph=g) as sess: Y_pred, W = linear(X, 2, 3, activation=tf.nn.relu) ``` or: ```python g = tf.Graph() with tf.Session(graph=g) as sess, g.as_default(): Y_pred, W = linear(X, 2, 3, activation=tf.nn.relu) ``` You can now write the same process as the above steps by simply calling: ```python h, W = utils.linear( x=X, n_output=20, name='linear', activation=tf.nn.relu) ``` <a name="part-two---image-painting-network"></a> # Part Two - Image Painting Network <a name="instructions-1"></a> ## Instructions Follow along the steps below, first setting up input and output data of the network, $\textbf{X}$ and $\textbf{Y}$. Then work through building the neural network which will try to compress the information in $\textbf{X}$ through a series of linear and non-linear functions so that whatever it is given as input, it minimized the error of its prediction, $\hat{\textbf{Y}}$, and the true output $\textbf{Y}$ through its training process. You'll also create an animated GIF of the training which you'll need to submit for the homework! Through this, we'll explore our first creative application: painting an image. This network is just meant to demonstrate how easily networks can be scaled to more complicated tasks without much modification. It is also meant to get you thinking about neural networks as building blocks that can be reconfigured, replaced, reorganized, and get you thinking about how the inputs and outputs can be anything you can imagine. <a name="preparing-the-data"></a> ## Preparing the Data We'll follow an example that Andrej Karpathy has done in his online demonstration of "image inpainting". What we're going to do is teach the network to go from the location on an image frame to a particular color. So given any position in an image, the network will need to learn what color to paint. Let's first get an image that we'll try to teach a neural network to paint. <h3><font color='red'>TODO! COMPLETE THIS SECTION!</font></h3> ```python # First load an image from skimage.data import astronaut img = astronaut() # Be careful with the size of your image. # Try a fairly small image to begin with, # then come back here and try larger sizes. img = imresize(img, (100, 100)) plt.figure(figsize=(5, 5)) plt.imshow(img) # Make sure you save this image as "reference.png" # and include it in your zipped submission file # so we can tell what image you are trying to paint! plt.imsave(fname='reference.png', arr=img) ``` In the lecture, I showed how to aggregate the pixel locations and their colors using a loop over every pixel position. I put that code into a function `split_image` below. Feel free to experiment with other features for `xs` or `ys`. ```python def split_image(img): # We'll first collect all the positions in the image in our list, xs xs = [] # And the corresponding colors for each of these positions ys = [] # Now loop over the image for row_i in range(img.shape[0]): for col_i in range(img.shape[1]): # And store the inputs xs.append([row_i, col_i]) # And outputs that the network needs to learn to predict ys.append(img[row_i, col_i]) # we'll convert our lists to arrays xs = np.array(xs) ys = np.array(ys) return xs, ys ``` Let's use this function to create the inputs (xs) and outputs (ys) to our network as the pixel locations (xs) and their colors (ys): ```python xs, ys = split_image(img) # and print the shapes xs.shape, ys.shape ``` ((10000, 2), (10000, 3)) Also remember, we should normalize our input values! <h3><font color='red'>TODO! COMPLETE THIS SECTION!</font></h3> ```python # Normalize the input (xs) using its mean and standard deviation # xs = (xs - np.mean(xs)) / np.std(xs) #mean, var = tf.nn.moments(xs, axes=[1]) xs = (xs - np.mean(xs)) / np.std(xs) # Just to make sure you have normalized it correctly: print(np.min(xs), np.max(xs)) assert(np.min(xs) > -3.0 and np.max(xs) < 3.0) ``` -1.71481604244 1.71481604244 Similarly for the output: ```python print(np.min(ys), np.max(ys)) ``` 0 254 We'll normalize the output using a simpler normalization method, since we know the values range from 0-255: ```python ys = ys / 255.0 print(np.min(ys), np.max(ys)) ``` 0.0 0.996078431373 Scaling the image values like this has the advantage that it is still interpretable as an image, unlike if we have negative values. What we're going to do is use regression to predict the value of a pixel given its (row, col) position. So the input to our network is `X = (row, col)` value. And the output of the network is `Y = (r, g, b)`. We can get our original image back by reshaping the colors back into the original image shape. This works because the `ys` are still in order: ```python plt.imshow(ys.reshape(img.shape)) ``` But when we give inputs of (row, col) to our network, it won't know what order they are, because we will randomize them. So it will have to *learn* what color value should be output for any given (row, col). Create 2 placeholders of `dtype` `tf.float32`: one for the input of the network, a `None x 2` dimension placeholder called $\textbf{X}$, and another for the true output of the network, a `None x 3` dimension placeholder called $\textbf{Y}$. <h3><font color='red'>TODO! COMPLETE THIS SECTION!</font></h3> ```python # Let's reset the graph: tf.reset_default_graph() # Create a placeholder of None x 2 dimensions and dtype tf.float32 # This will be the input to the network which takes the row/col X = tf.placeholder(tf.float32, (None, 2), 'X') # Create the placeholder, Y, with 3 output dimensions instead of 2. # This will be the output of the network, the R, G, B values. Y = tf.placeholder(tf.float32, (None, 3), 'Y') ``` Now create a deep neural network that takes your network input $\textbf{X}$ of 2 neurons, multiplies it by a linear and non-linear transformation which makes its shape [None, 20], meaning it will have 20 output neurons. Then repeat the same process again to give you 20 neurons again, and then again and again until you've done 6 layers of 20 neurons. Then finally one last layer which will output 3 neurons, your predicted output, which I've been denoting mathematically as $\hat{\textbf{Y}}$, for a total of 6 hidden layers, or 8 layers total including the input and output layers. Mathematically, we'll be creating a deep neural network that looks just like the previous fully connected layer we've created, but with a few more connections. So recall the first layer's connection is: \begin{align} \textbf{H}_1=\phi(\textbf{X}\textbf{W}_1 + \textbf{b}_1) \\ \end{align} So the next layer will take that output, and connect it up again: \begin{align} \textbf{H}_2=\phi(\textbf{H}_1\textbf{W}_2 + \textbf{b}_2) \\ \end{align} And same for every other layer: \begin{align} \textbf{H}_3=\phi(\textbf{H}_2\textbf{W}_3 + \textbf{b}_3) \\ \textbf{H}_4=\phi(\textbf{H}_3\textbf{W}_4 + \textbf{b}_4) \\ \textbf{H}_5=\phi(\textbf{H}_4\textbf{W}_5 + \textbf{b}_5) \\ \textbf{H}_6=\phi(\textbf{H}_5\textbf{W}_6 + \textbf{b}_6) \\ \end{align} Including the very last layer, which will be the prediction of the network: \begin{align} \hat{\textbf{Y}}=\phi(\textbf{H}_6\textbf{W}_7 + \textbf{b}_7) \end{align} Remember if you run into issues with variable scopes/names, that you cannot recreate a variable with the same name! Revisit the section on <a href='#Variable-Scopes'>Variable Scopes</a> if you get stuck with name issues. <h3><font color='red'>TODO! COMPLETE THIS SECTION!</font></h3> ```python # We'll create 6 hidden layers. Let's create a variable # to say how many neurons we want for each of the layers # (try 20 to begin with, then explore other values) n_neurons = ... # Create the first linear + nonlinear layer which will # take the 2 input neurons and fully connects it to 20 neurons. # Use the `utils.linear` function to do this just like before, # but also remember to give names for each layer, such as # "1", "2", ... "5", or "layer1", "layer2", ... "layer6". h1, W1 = ... # Create another one: h2, W2 = ... # and four more (or replace all of this with a loop if you can!): h3, W3 = ... h4, W4 = ... h5, W5 = ... h6, W6 = ... # Now, make one last layer to make sure your network has 3 outputs: Y_pred, W7 = utils.linear(h6, 3, activation=None, name='pred') ``` ```python assert(X.get_shape().as_list() == [None, 2]) assert(Y_pred.get_shape().as_list() == [None, 3]) assert(Y.get_shape().as_list() == [None, 3]) ``` <a name="cost-function"></a> ## Cost Function Now we're going to work on creating a `cost` function. The cost should represent how much `error` there is in the network, and provide the optimizer this value to help it train the network's parameters using gradient descent and backpropagation. Let's say our error is `E`, then the cost will be: $$cost(\textbf{Y}, \hat{\textbf{Y}}) = \frac{1}{\text{B}} \displaystyle\sum\limits_{b=0}^{\text{B}} \textbf{E}_b $$ where the error is measured as, e.g.: $$\textbf{E} = \displaystyle\sum\limits_{c=0}^{\text{C}} (\textbf{Y}_{c} - \hat{\textbf{Y}}_{c})^2$$ Don't worry if this scares you. This is mathematically expressing the same concept as: "the cost of an actual $\textbf{Y}$, and a predicted $\hat{\textbf{Y}}$ is equal to the mean across batches, of which there are $\text{B}$ total batches, of the sum of distances across $\text{C}$ color channels of every predicted output and true output". Basically, we're trying to see on average, or at least within a single minibatches average, how wrong was our prediction? We create a measure of error for every output feature by squaring the predicted output and the actual output it should have, i.e. the actual color value it should have output for a given input pixel position. By squaring it, we penalize large distances, but not so much small distances. Consider how the square function (i.e., $f(x) = x^2$) changes for a given error. If our color values range between 0-255, then a typical amount of error would be between $0$ and $128^2$. For example if my prediction was (120, 50, 167), and the color should have been (0, 100, 120), then the error for the Red channel is (120 - 0) or 120. And the Green channel is (50 - 100) or -50, and for the Blue channel, (167 - 120) = 47. When I square this result, I get: (120)^2, (-50)^2, and (47)^2. I then add all of these and that is my error, $\textbf{E}$, for this one observation. But I will have a few observations per minibatch. So I add all the error in my batch together, then divide by the number of observations in the batch, essentially finding the mean error of my batch. Let's try to see what the square in our measure of error is doing graphically. ```python error = np.linspace(0.0, 128.0**2, 100) loss = error**2.0 plt.plot(error, loss) plt.xlabel('error') plt.ylabel('loss') ``` This is known as the $l_2$ (pronounced el-two) loss. It doesn't penalize small errors as much as it does large errors. This is easier to see when we compare it with another common loss, the $l_1$ (el-one) loss. It is linear in error, by taking the absolute value of the error. We'll compare the $l_1$ loss with normalized values from $0$ to $1$. So instead of having $0$ to $255$ for our RGB values, we'd have $0$ to $1$, simply by dividing our color values by $255.0$. ```python error = np.linspace(0.0, 1.0, 100) plt.plot(error, error**2, label='l_2 loss') plt.plot(error, np.abs(error), label='l_1 loss') plt.xlabel('error') plt.ylabel('loss') plt.legend(loc='lower right') ``` So unlike the $l_2$ loss, the $l_1$ loss is really quickly upset if there is *any* error at all: as soon as error moves away from $0.0$, to $0.1$, the $l_1$ loss is $0.1$. But the $l_2$ loss is $0.1^2 = 0.01$. Having a stronger penalty on smaller errors often leads to what the literature calls "sparse" solutions, since it favors activations that try to explain as much of the data as possible, rather than a lot of activations that do a sort of good job, but when put together, do a great job of explaining the data. Don't worry about what this means if you are more unfamiliar with Machine Learning. There is a lot of literature surrounding each of these loss functions that we won't have time to get into, but look them up if they interest you. During the lecture, we've seen how to create a cost function using Tensorflow. To create a $l_2$ loss function, you can for instance use tensorflow's `tf.squared_difference` or for an $l_1$ loss function, `tf.abs`. You'll need to refer to the `Y` and `Y_pred` variables only, and your resulting cost should be a single value. Try creating the $l_1$ loss to begin with, and come back here after you have trained your network, to compare the performance with a $l_2$ loss. The equation for computing cost I mentioned above is more succintly written as, for $l_2$ norm: $$cost(\textbf{Y}, \hat{\textbf{Y}}) = \frac{1}{\text{B}} \displaystyle\sum\limits_{b=0}^{\text{B}} \displaystyle\sum\limits_{c=0}^{\text{C}} (\textbf{Y}_{c} - \hat{\textbf{Y}}_{c})^2$$ For $l_1$ norm, we'd have: $$cost(\textbf{Y}, \hat{\textbf{Y}}) = \frac{1}{\text{B}} \displaystyle\sum\limits_{b=0}^{\text{B}} \displaystyle\sum\limits_{c=0}^{\text{C}} \text{abs}(\textbf{Y}_{c} - \hat{\textbf{Y}}_{c})$$ Remember, to understand this equation, try to say it out loud: the $cost$ given two variables, $\textbf{Y}$, the actual output we want the network to have, and $\hat{\textbf{Y}}$ the predicted output from the network, is equal to the mean across $\text{B}$ batches, of the sum of $\textbf{C}$ color channels distance between the actual and predicted outputs. If you're still unsure, refer to the lecture where I've computed this, or scroll down a bit to where I've included the answer. <h3><font color='red'>TODO! COMPLETE THIS SECTION!</font></h3> ```python # first compute the error, the inner part of the summation. # This should be the l1-norm or l2-norm of the distance # between each color channel. error = ... assert(error.get_shape().as_list() == [None, 3]) ``` <h3><font color='red'>TODO! COMPLETE THIS SECTION!</font></h3> ```python # Now sum the error for each feature in Y. # If Y is [Batch, Features], the sum should be [Batch]: sum_error = ... assert(sum_error.get_shape().as_list() == [None]) ``` <h3><font color='red'>TODO! COMPLETE THIS SECTION!</font></h3> ```python # Finally, compute the cost, as the mean error of the batch. # This should be a single value. cost = ... assert(cost.get_shape().as_list() == []) ``` We now need an `optimizer` which will take our `cost` and a `learning_rate`, which says how far along the gradient to move. This optimizer calculates all the gradients in our network with respect to the `cost` variable and updates all of the weights in our network using backpropagation. We'll then create mini-batches of our training data and run the `optimizer` using a `session`. <h3><font color='red'>TODO! COMPLETE THIS SECTION!</font></h3> ```python # Refer to the help for the function optimizer = tf.train....minimize(cost) # Create parameters for the number of iterations to run for (< 100) n_iterations = ... # And how much data is in each minibatch (< 500) batch_size = ... # Then create a session sess = tf.Session() ``` We'll now train our network! The code below should do this for you if you've setup everything else properly. Please read through this and make sure you understand each step! Note that this can take a VERY LONG time depending on the size of your image (make it < 100 x 100 pixels), the number of neurons per layer (e.g. < 30), the number of layers (e.g. < 8), and number of iterations (< 1000). Welcome to Deep Learning :) ```python # Initialize all your variables and run the operation with your session sess.run(tf.global_variables_initializer()) # Optimize over a few iterations, each time following the gradient # a little at a time imgs = [] costs = [] gif_step = n_iterations // 10 step_i = 0 for it_i in range(n_iterations): # Get a random sampling of the dataset idxs = np.random.permutation(range(len(xs))) # The number of batches we have to iterate over n_batches = len(idxs) // batch_size # Now iterate over our stochastic minibatches: for batch_i in range(n_batches): # Get just minibatch amount of data idxs_i = idxs[batch_i * batch_size: (batch_i + 1) * batch_size] # And optimize, also returning the cost so we can monitor # how our optimization is doing. training_cost = sess.run( [cost, optimizer], feed_dict={X: xs[idxs_i], Y: ys[idxs_i]})[0] # Also, every 20 iterations, we'll draw the prediction of our # input xs, which should try to recreate our image! if (it_i + 1) % gif_step == 0: costs.append(training_cost / n_batches) ys_pred = Y_pred.eval(feed_dict={X: xs}, session=sess) img = np.clip(ys_pred.reshape(img.shape), 0, 1) imgs.append(img) # Plot the cost over time fig, ax = plt.subplots(1, 2) ax[0].plot(costs) ax[0].set_xlabel('Iteration') ax[0].set_ylabel('Cost') ax[1].imshow(img) fig.suptitle('Iteration {}'.format(it_i)) plt.show() ``` ```python # Save the images as a GIF _ = gif.build_gif(imgs, saveto='single.gif', show_gif=False) ``` Let's now display the GIF we've just created: ```python ipyd.Image(url='single.gif?{}'.format(np.random.rand()), height=500, width=500) ``` <a name="explore"></a> ## Explore Go back over the previous cells and exploring changing different parameters of the network. I would suggest first trying to change the `learning_rate` parameter to different values and see how the cost curve changes. What do you notice? Try exponents of $10$, e.g. $10^1$, $10^2$, $10^3$... and so on. Also try changing the `batch_size`: $50, 100, 200, 500, ...$ How does it effect how the cost changes over time? Be sure to explore other manipulations of the network, such as changing the loss function to $l_2$ or $l_1$. How does it change the resulting learning? Also try changing the activation functions, the number of layers/neurons, different optimizers, and anything else that you may think of, and try to get a basic understanding on this toy problem of how it effects the network's training. Also try comparing creating a fairly shallow/wide net (e.g. 1-2 layers with many neurons, e.g. > 100), versus a deep/narrow net (e.g. 6-20 layers with fewer neurons, e.g. < 20). What do you notice? <a name="a-note-on-crossvalidation"></a> ## A Note on Crossvalidation The cost curve plotted above is only showing the cost for our "training" dataset. Ideally, we should split our dataset into what are called "train", "validation", and "test" sets. This is done by taking random subsets of the entire dataset. For instance, we partition our dataset by saying we'll only use 80% of it for training, 10% for validation, and the last 10% for testing. Then when training as above, you would only use the 80% of the data you had partitioned, and then monitor accuracy on both the data you have used to train, but also that new 10% of unseen validation data. This gives you a sense of how "general" your network is. If it is performing just as well on that 10% of data, then you know it is doing a good job. Finally, once you are done training, you would test one last time on your "test" dataset. Ideally, you'd do this a number of times, so that every part of the dataset had a chance to be the test set. This would also give you a measure of the variance of the accuracy on the final test. If it changes a lot, you know something is wrong. If it remains fairly stable, then you know that it is a good representation of the model's accuracy on unseen data. We didn't get a chance to cover this in class, as it is less useful for exploring creative applications, though it is very useful to know and to use in practice, as it avoids overfitting/overgeneralizing your network to all of the data. Feel free to explore how to do this on the application above! <a name="part-three---learning-more-than-one-image"></a> # Part Three - Learning More than One Image <a name="instructions-2"></a> ## Instructions We're now going to make use of our Dataset from Session 1 and apply what we've just learned to try and paint every single image in our dataset. How would you guess is the best way to approach this? We could for instance feed in every possible image by having multiple row, col -> r, g, b values. So for any given row, col, we'd have 100 possible r, g, b values. This likely won't work very well as there are many possible values a pixel could take, not just one. What if we also tell the network *which* image's row and column we wanted painted? We're going to try and see how that does. You can execute all of the cells below unchanged to see how this works with the first 100 images of the celeb dataset. But you should replace the images with your own dataset, and vary the parameters of the network to get the best results! I've placed the same code for running the previous algorithm into two functions, `build_model` and `train`. You can directly call the function `train` with a 4-d image shaped as N x H x W x C, and it will collect all of the points of every image and try to predict the output colors of those pixels, just like before. The only difference now is that you are able to try this with a few images at a time. There are a few ways we could have tried to handle multiple images. The way I've shown in the `train` function is to include an additional input neuron for *which* image it is. So as well as receiving the row and column, the network will also receive as input which image it is as a number. This should help the network to better distinguish the patterns it uses, as it has knowledge that helps it separates its process based on which image is fed as input. ```python def build_model(xs, ys, n_neurons, n_layers, activation_fn, final_activation_fn, cost_type): xs = np.asarray(xs) ys = np.asarray(ys) if xs.ndim != 2: raise ValueError( 'xs should be a n_observates x n_features, ' + 'or a 2-dimensional array.') if ys.ndim != 2: raise ValueError( 'ys should be a n_observates x n_features, ' + 'or a 2-dimensional array.') n_xs = xs.shape[1] n_ys = ys.shape[1] X = tf.placeholder(name='X', shape=[None, n_xs], dtype=tf.float32) Y = tf.placeholder(name='Y', shape=[None, n_ys], dtype=tf.float32) current_input = X for layer_i in range(n_layers): current_input = utils.linear( current_input, n_neurons, activation=activation_fn, name='layer{}'.format(layer_i))[0] Y_pred = utils.linear( current_input, n_ys, activation=final_activation_fn, name='pred')[0] if cost_type == 'l1_norm': cost = tf.reduce_mean(tf.reduce_sum( tf.abs(Y - Y_pred), 1)) elif cost_type == 'l2_norm': cost = tf.reduce_mean(tf.reduce_sum( tf.squared_difference(Y, Y_pred), 1)) else: raise ValueError( 'Unknown cost_type: {}. '.format( cost_type) + 'Use only "l1_norm" or "l2_norm"') return {'X': X, 'Y': Y, 'Y_pred': Y_pred, 'cost': cost} ``` ```python def train(imgs, learning_rate=0.0001, batch_size=200, n_iterations=10, gif_step=2, n_neurons=30, n_layers=10, activation_fn=tf.nn.relu, final_activation_fn=tf.nn.tanh, cost_type='l2_norm'): N, H, W, C = imgs.shape all_xs, all_ys = [], [] for img_i, img in enumerate(imgs): xs, ys = split_image(img) all_xs.append(np.c_[xs, np.repeat(img_i, [xs.shape[0]])]) all_ys.append(ys) xs = np.array(all_xs).reshape(-1, 3) xs = (xs - np.mean(xs, 0)) / np.std(xs, 0) ys = np.array(all_ys).reshape(-1, 3) ys = ys / 127.5 - 1 g = tf.Graph() with tf.Session(graph=g) as sess: model = build_model(xs, ys, n_neurons, n_layers, activation_fn, final_activation_fn, cost_type) optimizer = tf.train.AdamOptimizer( learning_rate=learning_rate).minimize(model['cost']) sess.run(tf.global_variables_initializer()) gifs = [] costs = [] step_i = 0 for it_i in range(n_iterations): # Get a random sampling of the dataset idxs = np.random.permutation(range(len(xs))) # The number of batches we have to iterate over n_batches = len(idxs) // batch_size training_cost = 0 # Now iterate over our stochastic minibatches: for batch_i in range(n_batches): # Get just minibatch amount of data idxs_i = idxs[batch_i * batch_size: (batch_i + 1) * batch_size] # And optimize, also returning the cost so we can monitor # how our optimization is doing. cost = sess.run( [model['cost'], optimizer], feed_dict={model['X']: xs[idxs_i], model['Y']: ys[idxs_i]})[0] training_cost += cost print('iteration {}/{}: cost {}'.format( it_i + 1, n_iterations, training_cost / n_batches)) # Also, every 20 iterations, we'll draw the prediction of our # input xs, which should try to recreate our image! if (it_i + 1) % gif_step == 0: costs.append(training_cost / n_batches) ys_pred = model['Y_pred'].eval( feed_dict={model['X']: xs}, session=sess) img = ys_pred.reshape(imgs.shape) gifs.append(img) return gifs ``` <a name="code-1"></a> ## Code Below, I've shown code for loading the first 100 celeb files. Run through the next few cells to see how this works with the celeb dataset, and then come back here and replace the `imgs` variable with your own set of images. For instance, you can try your entire sorted dataset from Session 1 as an N x H x W x C array. Explore! <h3><font color='red'>TODO! COMPLETE THIS SECTION!</font></h3> ```python celeb_imgs = utils.get_celeb_imgs() plt.figure(figsize=(10, 10)) plt.imshow(utils.montage(celeb_imgs).astype(np.uint8)) # It doesn't have to be 100 images, explore! imgs = np.array(celeb_imgs).copy() ``` Explore changing the parameters of the `train` function and your own dataset of images. Note, you do not have to use the dataset from the last assignment! Explore different numbers of images, whatever you prefer. <h3><font color='red'>TODO! COMPLETE THIS SECTION!</font></h3> ```python # Change the parameters of the train function and # explore changing the dataset gifs = train(imgs=imgs) ``` Now we'll create a gif out of the training process. Be sure to call this 'multiple.gif' for your homework submission: ```python montage_gifs = [np.clip(utils.montage( (m * 127.5) + 127.5), 0, 255).astype(np.uint8) for m in gifs] _ = gif.build_gif(montage_gifs, saveto='multiple.gif') ``` And show it in the notebook ```python ipyd.Image(url='multiple.gif?{}'.format(np.random.rand()), height=500, width=500) ``` What we're seeing is the training process over time. We feed in our `xs`, which consist of the pixel values of each of our 100 images, it goes through the neural network, and out come predicted color values for every possible input value. We visualize it above as a gif by seeing how at each iteration the network has predicted the entire space of the inputs. We can visualize just the last iteration as a "latent" space, going from the first image (the top left image in the montage), to the last image, (the bottom right image). ```python final = gifs[-1] final_gif = [np.clip(((m * 127.5) + 127.5), 0, 255).astype(np.uint8) for m in final] gif.build_gif(final_gif, saveto='final.gif') ``` ```python ipyd.Image(url='final.gif?{}'.format(np.random.rand()), height=200, width=200) ``` <a name="part-four---open-exploration-extra-credit"></a> # Part Four - Open Exploration (Extra Credit) I now what you to explore what other possible manipulations of the network and/or dataset you could imagine. Perhaps a process that does the reverse, tries to guess where a given color should be painted? What if it was only taught a certain palette, and had to reason about other colors, how it would interpret those colors? Or what if you fed it pixel locations that weren't part of the training set, or outside the frame of what it was trained on? Or what happens with different activation functions, number of layers, increasing number of neurons or lesser number of neurons? I leave any of these as an open exploration for you. Try exploring this process with your own ideas, materials, and networks, and submit something you've created as a gif! To aid exploration, be sure to scale the image down quite a bit or it will require a much larger machine, and much more time to train. Then whenever you think you may be happy with the process you've created, try scaling up the resolution and leave the training to happen over a few hours/overnight to produce something truly stunning! Make sure to name the result of your gif: "explore.gif", and be sure to include it in your zip file. <h3><font color='red'>TODO! COMPLETE THIS SECTION!</font></h3> ```python # Train a network to produce something, storing every few # iterations in the variable gifs, then export the training # over time as a gif. ... gif.build_gif(montage_gifs, saveto='explore.gif') ``` ```python ipyd.Image(url='explore.gif?{}'.format(np.random.rand()), height=500, width=500) ``` <a name="assignment-submission"></a> # Assignment Submission After you've completed the notebook, create a zip file of the current directory using the code below. This code will make sure you have included this completed ipython notebook and the following files named exactly as: <pre> session-2/ session-2.ipynb single.gif multiple.gif final.gif explore.gif* libs/ utils.py * = optional/extra-credit </pre> You'll then submit this zip file for your second assignment on Kadenze for "Assignment 2: Teach a Deep Neural Network to Paint"! If you have any questions, remember to reach out on the forums and connect with your peers or with me. To get assessed, you'll need to be a premium student! This will allow you to build an online portfolio of all of your work and receive grades. If you aren't already enrolled as a student, register now at http://www.kadenze.com/ and join the [#CADL](https://twitter.com/hashtag/CADL) community to see what your peers are doing! https://www.kadenze.com/courses/creative-applications-of-deep-learning-with-tensorflow/info Also, if you share any of the GIFs on Facebook/Twitter/Instagram/etc..., be sure to use the #CADL hashtag so that other students can find your work! ```python utils.build_submission('session-2.zip', ('reference.png', 'single.gif', 'multiple.gif', 'final.gif', 'session-2.ipynb'), ('explore.gif')) ```
.ds TL "Running Third-Party Software" .ds TI "RELEASE NOTES" .NH "Running Third-Party Software" .PP \*(CO runs many packages from third-party vendors that were designed for use with other operating systems, in particular SCO \*(UN. \*(CO runs these packages, but some require some minor reconfiguration of either the package, of \*(CO, or both, to run smoothly. .PP The following sections describe some of the packages that Mark Williams Company has tested, and gives directions on how to perform these minor reconfigurations. Note that we continually test new packages, so the following list probably is incomplete. For the latest information on what packages run under \*(CO, and how you can run them, telephone the company from which you purchased the software, check the MWC bulletin board, or telephone Mark Williams Company. .SH "General Directions" .PP To install third-party \*(UN software onto \*(CO, be aware of the following general rules: .IP \fB1.\fR 0.3i \*(CO does not support the command .BR custom . To install, you should read the product's manual and determine what must be done to install the product. Some products come with a shell script that performs all the tasks of installation; you can use the Bourne shell .B sh to invoke that script. Other products use .B tar or .BR cpio ; look in your package's installation or release notes for instructions. Please note that when un\fBtar\fRring or \fBcpio\fRing floppy disks from other \*(UN systems, you sometimes must use the complex \*(UN device names that are now supported in this release. For information on floppy-disk device names, see the Lexicon entries for .B fd and .BR "floppy disk" . .IP \fB2.\fR Some third-party packages support many different operating systems, and when you install the package let you pick the operating system from a menu. If this is the case, you should pick \*(CO first, if it is one of the options. If \*(CO is not an option, pick SCO \*(UN; if SCO \*(UN is not available, then Interactive \*(UN; and if none of those are available, then USL \*(UN System V release 3.2. If none of those are available, then select generic \*(UN system V release 2. .IP \fB3.\fR Some packages offer a variety of console devices. If you have a color console, select .BR colorcons . If this is not available, try .BR at386 . If neither is an option, or if you have a monochrome console, then you should select .BR monochrome ; in most cases, this works correctly, even with color devices. .IP \fB4.\fR If possible, install all available terminal types. Some packages require that you reinstall the entire package should you need a terminal type that you have not yet installed. .IP \fB5.\fR The SCO impementation of the link command .B ln will overwrite an existing file by default. This behavior does not comply with the \*(PX. Under \*(CO, you must use the option \fB\-f\fR to force .B ln to overwrite an existing file. Some installation scripts, however, depending upon the non-standard behavior of .BR ln . If this problem arises while you are installing a package, you must edit the installation script and insert the flag \fB\-f\fR where appropriate. .IP \fB6.\fR \*(CO does not support the .B brand utility from SCO. This utility ``brands'' (or serializes) executables using a serial number and license activation key. Any package that requires .B brand for proper installation and execution will not work under \*(CO. .SH "Third-Party Packages" .PP The following gives information on using some of the more popular third-party \*(UN packages under \*(CO. .Sh "Aide de Campe" .PP This package installs and runs correctly. .Sh "BBX Progression/4" .PP The installation of this package requires that you use the command .BR cpio . Because the installation program does not prompt for the two supplementary disks, you must re-issue the command .DM cpio -icB .DE for each disk in the distribution. .PP The newest version from BASIS runs BASIS International's regression suite without error. .Sh "Blast" .PP The package works correctly. .Sh "ccsh" .PP As of this writing, the shell-script compiler .B ccsh does not run under \*(CO 4.2. That is due to the fact that its internal library .B /usr/lib/libccsh.a is not in the COFF format. It does run, however, on release 3.2 of \*(CO. .PP For details, please contact the publisher of .BR ccsh . .Sh "Codebase" .PP The Kernighan-and-Ritchie source compiles. .Sh "Dataflex" .PP This package installs and runs correctly. .Sh "dBASE III" .PP The package works correctly. .Sh "dBASE IV" .PP To install dBASE IV under \*(CO, do the following: .IP \fB1.\fR 0.3i Type the command .DM cd / .DE .IP to change to the root directory. .IP \fB2.\fR Insert System Disk 1 into a floppy-disk drive. .IP \fB3.\fR Type the command .DM tar -xvf /dev/rfva\fIX\fP ./tmp/install .DE where .I X is `0' or `1', depending upon whether you have inserted the system disk into drive 0 (i.e., A:) or 1 (i.e., B:). .IP \fB4.\fR When the file is extracted, issue the following command: .DM cp ./tmp/install ./tmp/coh-install .DE .IP Then, use the editor of your choice to edit file .BR ./tmp/coh-install . Change line 33 from: .DM label=`dd if=$disk count=1 | dd bs=100 count=1 2>/dev/null | tr` .DE .IP to .DM label=`dd if=$disk count=1 | dd bs=100 count=1 2>/dev/null` .DE .IP Save the edited file. .IP \fB5.\fR .I Make sure you are in the root directory! .R This is crucial at this stage to installing correctly. .IP \fB6.\fR Execute the new install script by typing: .DM /bin/sh ./tmp/coh-install /dev/rfva\fIX\fP .DE .IP Once again, substitute `0' or `1' for .I X depending upon which floppy-disk drive you have inserted the system disk. .IP \fB7.\fR Continue doing the installation normally, as described in the documentation that comes with the dBASE-IV package. .IP \fB8.\fR When you have concluded installing dBASE IV, you must execute the following final commands: .DM cd /usr/local/lib/dbaseiv rm dbase1.res ln ./dbase1.res.us ./dbase1.res rm /tmp/coh-install .DE .PP You should now have a working implementation of dBASE IV! .PP Some users have encountered problems with this package's license manager. They report that the first time they added a license to the data base, the license manager corrupted the entry, thus prompting some surly behavior from dBASE when they attempted to use the package. .PP To correct this problem, use the dBASE utility .B editlic to add a second license entry. It appears that dBASE stores and processes this second entry correctly. After you confirm that the new entry functions properly, re-invoke .B editlic and remove the original entry. After that, all appears to work as it should. .PP You may experience some problems with console output and the handling of function keys. If this is the case, you need a version of the dBASE terminal-description file that is corrected for \*(CO. You can obtain this file from site \fBraven\fR on the Intenet, or from the Mark Williams bulletin board. If all else fails, send mail to \[email protected]\fR, and we will mail a copy to you. .PP Some users of dBASE IV have reported that the package, for whatever reason, does not recognize directory or file names that contain capital letters. If dBASE IV has trouble saving files, check the name of the directory, and make sure it is all in lower-case letters. .Sh "FilePro" .PP The package works correctly. .Sh "Flexilint" .PP The tool .B Flexilint compiles and runs under \*(CO release 4.2. .PP To install the package, you must make one small change: edit header file .B custom.h and change the prototype for .B void to .BR int . .Sh "Lotus 1-2-3" .PP To install Lotus 1-2-3, do the following: .IP \fB1.\fR 0.3i Install Lotus by hand with .B tar (not with .BR custom ), as described in the Lotus documentation. .IP \fB2.\fR Before you run the command .BR setup123 , type the following command: .DM echo -n '\033[?8l' .DE The first command set erase mode on the console. .PP The sample files as stored in .B /u/lotus/123.v11/smpfiles/misc will fail if the current working directory is not .BR /u/lotus/123.v11/smpfiles/misc . To enter this directory from within Lotus, use the following command: .DM /WGDD/u/lotus/123.v11/smpfiles/misc .DE As of this writing, graphs did not work because of limitations of the \*(CO console driver. We are working to correct this problem. .Sh "mc \(em MacroCALC" .PP MacroCALC installs and runs correctly under \*(CO 4.0 and 4.2. Users should have no problems installing this package. If you are installing MacroCALC onto \*(CO 4.2, do .I not copy onto your system the .B ansipc termcap entry that comes with the package: the one included with \*(CO 4.2 already works correctly .Sh "RMCobol" .PP RMCobol works out of the box, without modification. You may notice some slight discrepancies with regard to colors and the number of lines on the screen, which are easily corrected by resetting the \*(CO console device. .Sh "SlickEdit" .PP This editor works properly. However, it comes with an internal language that it uses for enhanced editing, macros, etc., that requires a compiler named .BR st . This compiler is on the SlickEdit's distribution disks; however, it is in Microsoft .B a.out binary format, which cannot be executed under \*(CO. .PP SlickEdit works best with a customized terminal-information file that has been prepared by Mark Williams Company. To obtain a copy, contact the Mark Williams BBS as described earlier in these notes. .Sh "TERM Communications Package" .PP Because the distribution disks are not high density, you must use device \fB/dev/fqa\fIX\fR (where \fIX\fR is \fB0\fR or \fB1\^\fR) to load the distribution. .PP When you execute the .B install script after you have loaded the distribution, you must to choose the first option in the index: .DM UNIX System V/386 (Including Altos, AT&T and Interactive) .DE Once installed, our tests show that the package works well. .Sh "WordPerfect and WordPerfect Office" .PP Before you can print anything on your \*(CO system, you must start up and configure the MLP print spooler. Do this before you attempt to install WordPerfect. For details on MLP, see the Lexicon entry for .BR printer . .PP When you load the initial boot disk, if you choose to un-\fBtar\fR the disk using the device .BR /dev/fva0 , .B tar complains: .DM This doesn't look like a tar archive. Skipping to next file... .DE .PP This behavior also occurs with devices .BR /dev/fva0 , .BR /dev/dsk/f03h , .BR /dev/dsk/f0q18dt , and .BR /dev/fd0135ds18 . Note that this does not affect the installation: it is just a curiosity. .PP When you perform the actual installation, in some instances the installation program exhibits strange behavior. It will say: .DM *Please Wait* 0% complete .DE It then prints what appears to be a process id on top of the fragment .BR *Plea , moves the cursor down another line, and prints: .DM *Please Wait* 1% complete .DE The .B 1% stage continues for a lengthy period of time; the floppy-disk drive's light glows, to show that the disk is being read, but otherwise the installation program displays nothing to indicate that useful activity is occurring. Do not panic: the installation program is working; it simply is not updating the screen properly. .PP .\"Once you have gone through the command .\".BR "wpinstall" , .\"you have performed initial installation. .\"At this point, you must install additional printers. .\"The installation program by default selects 299 printers for installation. .\"These include the printers that were installed initially, and others that .\"appear to have been selected at random from the list of available printers. .\"Go through the entire list; un-select the printers you do not have, and .\"select others (if any) that you do have but that were not selected by default. .\".PP If your console is monochrome, insert the command .DM export WPTERM51=scocons .DE into file .BR /etc/profile . If you console is color, insert the command: .DM export WPTERM51=scoconscol .DE WordPerfect expects this variable to be set before it can run correctly. Note that after you insert it, you must log out and log in again before that variable can become part of your environment. .PP If you wish to run either package under X Windows, use the terminal type .B VT102 and insert the following instructions into the file .BR $HOME/.Xdefaults : .DM xterm*VT102.Translations: #override \e <Key> F1 : string(0x1b) string("OP") \en \e <Key> F2 : string(0x1b) string("OQ") \en \e <Key> F3 : string(0x1b) string("OR") \en .DE .PP Some systems have experienced problems with printing under the .B lp spooler, when logged in as anyone other than the superuser. This should not be a problem, but if it is, try switching the WordPerfect spooler command from .B lp to .B "hpr -B" or .BR "lpr -B" , respectively, depending upon whether you have a laser printer or a dot-matrix printer. If all else fails, try the following workaround: .PP .IP \fB1.\fR 0.3i Set WordPerfect's spool command to: .DM cat -u > /tmp/PRINT.ME .DE .IP When WordPerfect prints, it will dump its output into file .BR /tmp/PRINT.ME , instead of sending it directly to the spooler. .IP \fB2.\fR To print WordPerfect's output, open another virtual console and type the command: .DM cat /tmp/PRINT.ME > /dev/lp .DE With WordPerfect Office, you cannot receive mail from within the application because it expects either SCO's MMDF, or a version of .B smail that \*(CO does not yet support.
library(cummeRbund) args = commandArgs(trailingOnly=TRUE) setwd(args[1]) cuff = readCufflinks(args[2]) pdf(file="density-19f-dapto-t1.pdf") csDensity(genes(cuff)) dev.off() pdf(file="scatter-19f-dapto-t1.pdf") csScatter(genes(cuff), 'X19f_dapto','X19f_t1') dev.off() pdf(file="scatter-matrix-19f-dapto-t1.pdf") csScatterMatrix(genes(cuff)) dev.off() pdf(file="volcano-19f-dapto-t1.pdf") csVolcanoMatrix(genes(cuff)) dev.off() gene_diff_data=diffData(genes(cuff)) sig_gene_data = subset(gene_diff_data,significant=='yes') sig_genes = getGenes(cuff,sig_gene_data$gene_id) write.table(sig_gene_data,'sig-diff-genes.csv',sep=',',quote=F) pdf(file="sig-gene-diff-barplot-19f-dapto-t1.pdf") expressionBarplot(sig_genes,logMode=T,showErrorbars=T) dev.off() pdf(file="sig-gene-diff-heatmap-19f-dapto-t1.pdf") csHeatmap(sig_genes,cluster='both') dev.off() plot_list = list() for (i in 1:length(sig_gene_data$gene_id)) { ex_gene = getGene(cuff,sig_gene_data$gene_id[i]) plot_list[[i]] = expressionBarplot(ex_gene,logMode=T,showErrorbars=T) } pdf(file="sig-genes-individual.pdf") for (i in 1:length(sig_gene_data$gene_id)) { print(plot_list[[i]]) } dev.off()
/* * Copyright (C) 2017 Incognito (Edited by ProMetheus) * * 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. */ #include <streamer/config.hpp> #include "../natives.h" #include "../core.h" #include "../utility.h" #include <streamer/pickups.hpp> #include <boost/geometry.hpp> #include <boost/geometry/geometries/geometries.hpp> #include <boost/intrusive_ptr.hpp> #include <boost/scoped_ptr.hpp> #include <boost/unordered_map.hpp> #include <Eigen/Core> STREAMER_BEGIN_NS int CreateDynamicPickup(int id, int type, float x, float y, float z, int worldid, int interiorid, int playerid, float streamDistance, int areaid, int priority) { if (core->getData()->getGlobalMaxItems(STREAMER_TYPE_PICKUP) == core->getData()->pickups.size()) { return 0; } int pickupId = Item::Pickup::identifier.get(); Item::SharedPickup pickup(new Item::Pickup); //pickup->amx = amx; pickup->pickupId = pickupId; pickup->inverseAreaChecking = false; pickup->originalComparableStreamDistance = -1.0f; pickup->positionOffset = Eigen::Vector3f::Zero(); pickup->streamCallbacks = false; pickup->modelId = id; pickup->type = type; pickup->position = Eigen::Vector3f(x, y, z); Utility::addToContainer(pickup->worlds, worldid); Utility::addToContainer(pickup->interiors, interiorid); Utility::addToContainer(pickup->players, playerid); pickup->comparableStreamDistance = streamDistance < STREAMER_STATIC_DISTANCE_CUTOFF ? streamDistance : streamDistance * streamDistance; pickup->streamDistance = streamDistance; Utility::addToContainer(pickup->areas, areaid); pickup->priority = priority; core->getGrid()->addPickup(pickup); core->getData()->pickups.insert(std::make_pair(pickupId, pickup)); return static_cast<cell>(pickupId); } int DestroyDynamicPickup(int id) { boost::unordered_map<int, Item::SharedPickup>::iterator p = core->getData()->pickups.find(id); if (p != core->getData()->pickups.end()) { Utility::destroyPickup(p); return 1; } return 0; } int IsValidDynamicPickup(int id) { boost::unordered_map<int, Item::SharedPickup>::iterator p = core->getData()->pickups.find(id); if (p != core->getData()->pickups.end()) { return 1; } return 0; } STREAMER_END_NS
open import Agda.Primitive using (lzero; lsuc; _⊔_) open import Relation.Binary.PropositionalEquality open import Relation.Binary using (Setoid) import SecondOrder.Arity import SecondOrder.Signature import SecondOrder.Metavariable import SecondOrder.Renaming import SecondOrder.Term import SecondOrder.Substitution import SecondOrder.Instantiation import SecondOrder.Theory module SecondOrder.Equality {ℓ ℓa} {𝔸 : SecondOrder.Arity.Arity} {Σ : SecondOrder.Signature.Signature ℓ 𝔸} (𝕋 : SecondOrder.Theory.Theory Σ ℓa) where open SecondOrder.Metavariable Σ open SecondOrder.Renaming Σ open SecondOrder.Term Σ open SecondOrder.Substitution Σ open SecondOrder.Signature.Signature Σ open SecondOrder.Instantiation Σ open SecondOrder.Theory.Theory 𝕋 record Equation : Set (lsuc ℓ) where constructor make-eq field eq-mv-ctx : MContext -- metavariable context of an equation eq-ctx : VContext -- variable context of an equation eq-sort : sort -- sort of an equation eq-lhs : Term eq-mv-ctx eq-ctx eq-sort -- left-hand side eq-rhs : Term eq-mv-ctx eq-ctx eq-sort -- right-hand side infix 5 make-eq syntax make-eq Θ Γ A s t = Θ ⊕ Γ ∥ s ≋ t ⦂ A -- Instantiate an axiom of 𝕋 to an equation instantiate-axiom : ∀ (ε : ax) {Θ Γ} (I : ax-mv-ctx ε ⇒ⁱ Θ ⊕ Γ) → Equation instantiate-axiom ε {Θ} {Γ} I = Θ ⊕ Γ ∥ [ I ]ⁱ (ax-lhs ε) ≋ [ I ]ⁱ (ax-rhs ε) ⦂ ax-sort ε -- The equality judgement infix 4 ⊢_ data ⊢_ : Equation → Set (lsuc (ℓ ⊔ ℓa)) where -- general rules eq-refl : ∀ {Θ Γ A} {t : Term Θ Γ A} → ⊢ Θ ⊕ Γ ∥ t ≋ t ⦂ A eq-symm : ∀ {Θ Γ A} {s t : Term Θ Γ A} → ⊢ Θ ⊕ Γ ∥ s ≋ t ⦂ A → ⊢ Θ ⊕ Γ ∥ t ≋ s ⦂ A eq-trans : ∀ {Θ Γ A} {s t u : Term Θ Γ A} → ⊢ Θ ⊕ Γ ∥ s ≋ t ⦂ A → ⊢ Θ ⊕ Γ ∥ t ≋ u ⦂ A → ⊢ Θ ⊕ Γ ∥ s ≋ u ⦂ A -- Congruence rule for operations -- the premises are: an operation f, two sets of arguments xs, ys of f that give -- for each argument of f a term in the extended context with the arguments that f binds -- such that xᵢ ≋ yᵢ for each i ∈ oper-arity f -- then f xs ≋ f ys (in the appropriate context) eq-oper : ∀ {Γ Θ} {f : oper} {xs ys : ∀ (i : oper-arg f) → Term Θ (Γ ,, arg-bind f i) (arg-sort f i)} → (∀ i → ⊢ Θ ⊕ (Γ ,, arg-bind f i) ∥ (xs i) ≋ (ys i) ⦂ (arg-sort f i)) → ⊢ Θ ⊕ Γ ∥ (tm-oper f xs) ≋ (tm-oper f ys) ⦂ (oper-sort f) -- Congruence rule for metavariables -- the permises are: a meta-variable M, and two sets of arguments of the appropriate -- sorts and arities to apply M, such that xᵢ ≋ yᵢ -- then M xs ≋ M ys eq-meta : ∀ {Γ Θ} {Γᴹ Aᴹ} {M : [ Γᴹ , Aᴹ ]∈ Θ} {xs ys : ∀ {B : sort} (i : B ∈ Γᴹ) → Term Θ Γ B} → (∀ {B : sort} (i : B ∈ Γᴹ) → ⊢ Θ ⊕ Γ ∥ (xs i) ≋ (ys i) ⦂ B) → ⊢ Θ ⊕ Γ ∥ (tm-meta M xs) ≋ (tm-meta M ys) ⦂ Aᴹ -- equational axiom eq-axiom : ∀ (ε : ax) {Θ Γ} (I : ax-mv-ctx ε ⇒ⁱ Θ ⊕ Γ) → ⊢ instantiate-axiom ε I -- Syntactically equal terms are judgementally equal ≈-≋ : ∀ {Θ Γ A} {s t : Term Θ Γ A} → s ≈ t → ⊢ Θ ⊕ Γ ∥ s ≋ t ⦂ A ≈-≋ (≈-≡ refl) = eq-refl ≈-≋ (≈-meta ξ) = eq-meta (λ i → ≈-≋ (ξ i)) ≈-≋ (≈-oper ξ) = eq-oper (λ i → ≈-≋ (ξ i)) -- terms and judgemental equality form a setoid eq-setoid : ∀ (Γ : VContext) (Θ : MContext) (A : sort) → Setoid ℓ (lsuc (ℓ ⊔ ℓa)) eq-setoid Γ Θ A = record { Carrier = Term Θ Γ A ; _≈_ = λ s t → ⊢ Θ ⊕ Γ ∥ s ≋ t ⦂ A ; isEquivalence = record { refl = eq-refl ; sym = eq-symm ; trans = eq-trans } } -- judgemental equality of substitutions _≋ˢ_ : ∀ {Θ Γ Δ} (σ τ : Θ ⊕ Γ ⇒ˢ Δ) → Set (lsuc (ℓ ⊔ ℓa)) _≋ˢ_ {Θ} {Γ} {Δ} σ τ = ∀ {A} (x : A ∈ Γ) → ⊢ Θ ⊕ Δ ∥ σ x ≋ τ x ⦂ A ≈ˢ-≋ˢ : ∀ {Θ Γ Δ} {σ τ : Θ ⊕ Γ ⇒ˢ Δ} → σ ≈ˢ τ → σ ≋ˢ τ ≈ˢ-≋ˢ ξ = λ x → ≈-≋ (ξ x) -- judgemental equality of metavariable instatiations _≋ⁱ_ : ∀ {Θ Ξ Γ} (I J : Θ ⇒ⁱ Ξ ⊕ Γ) → Set (lsuc (ℓ ⊔ ℓa)) _≋ⁱ_ {Θ} {Ξ} {Γ} I J = ∀ {Γᴹ Aᴹ} (M : [ Γᴹ , Aᴹ ]∈ Θ) → ⊢ Ξ ⊕ (Γ ,, Γᴹ) ∥ I M ≋ J M ⦂ Aᴹ
theory RRC_3T imports OpSem begin datatype PC = L1 | L2 | L3 consts t1 :: T consts t2 :: T consts t3 :: T consts x :: L consts y :: L definition "thrdsvars \<equiv> y \<noteq> x \<and> t1 \<noteq> t2 \<and> t1 \<noteq> t3 \<and> t2 \<noteq> t3 " record mp_state = pc :: "T \<Rightarrow> PC" state :: surrey_state a :: V b :: V r1 :: V definition "update_pc t nv pcf \<equiv> pcf (t := nv)" definition "locals_id s s' \<equiv> a s = a s' \<and> b s = b s' \<and> r1 s = r1 s'" definition prog :: "T \<Rightarrow> mp_state \<Rightarrow> mp_state \<Rightarrow> bool " where "prog t s s' \<equiv> ( if t = t1 then if (pc s) t = L1 then pc s' = update_pc t L2 (pc s) \<and> ((state s) [x := 1]\<^sub>t (state s')) \<and> locals_id s s' else if (pc s) t = L2 then pc s' = update_pc t L3 (pc s) \<and> ((state s) [y :=\<^sup>R 1]\<^sub>t (state s')) \<and> locals_id s s' else False else if t = t2 then if (pc s) t = L1 then pc s' = update_pc t L2 (pc s) \<and> ((state s) [r1 s' \<leftarrow>\<^sup>A y]\<^sub>t (state s')) \<and> a s' = a s \<and> b s' = b s else if (pc s) t = L2 then pc s' = update_pc t L3 (pc s) \<and> ((state s) [x := 2]\<^sub>t (state s')) \<and> locals_id s s' else False else if t = t3 then if (pc s) t = L1 then pc s' = update_pc t L2 (pc s) \<and> ((state s) [a s' \<leftarrow> x]\<^sub>t (state s')) \<and> r1 s' = r1 s \<and> b s' = b s else if (pc s) t = L2 then pc s' = update_pc t L3 (pc s) \<and> ((state s) [b s' \<leftarrow> x]\<^sub>t (state s')) \<and> r1 s' = r1 s \<and> a s' = a s else False else False )" definition prog_inv :: "T \<Rightarrow> PC \<Rightarrow> mp_state \<Rightarrow> bool " where "prog_inv t p s \<equiv> if t = t1 then let t' = t2 in (case p of L1 \<Rightarrow> [\<zero>\<^sub>x 1]\<^sub>0 (state s) \<and> \<not>[y \<approx>\<^sub>t' 1] (state s) \<and> ([\<zero>\<^sub>x 2]\<^sub>0 (state s) \<longrightarrow> [x =\<^sub>t 0] (state s)) | L2 \<Rightarrow> \<not>[y \<approx>\<^sub>t' 1] (state s) \<and> ([\<zero>\<^sub>x 2]\<^sub>0 (state s) \<longrightarrow> [x =\<^sub>t 1] (state s)) | L3 \<Rightarrow> True ) else if t = t2 then (case p of L1 \<Rightarrow> [\<zero>\<^sub>x 2]\<^sub>0 (state s) \<and> [y = 1]\<^sub>t\<lparr>x = 1\<rparr> (state s) | L2 \<Rightarrow> (r1 s = 1 \<longrightarrow> [x =\<^sub>t 1](state s) \<and> enc_t (state s) t x 1) \<and> [\<zero>\<^sub>x 2]\<^sub>0 (state s) | L3 \<Rightarrow> (r1 s = 1 \<longrightarrow> [1 \<hookrightarrow>\<^sub>x 2](state s)) ) else if t = t3 then (case p of L1 \<Rightarrow> True | L2 \<Rightarrow> enc_t (state s) t x (a s) | L3 \<Rightarrow> ((a s) \<noteq> (b s) \<longrightarrow> [(a s) \<leadsto>\<^sub>x (b s)](state s)) ) else False " (*initial_state \<sigma> I*) definition init_map :: "(L \<Rightarrow> V) \<Rightarrow> bool" where "init_map \<phi> \<equiv> \<phi> x = 0 \<and> \<phi> y = 0" definition init_s :: "surrey_state \<Rightarrow> bool" where "init_s ss \<equiv> \<exists> \<phi>. initial_state ss \<phi> \<and> init_map \<phi>" definition init :: "mp_state \<Rightarrow> bool" where "init s \<equiv> (pc s) t1 = L1 \<and> (pc s) t2 = L1 \<and> (pc s) t3 = L1 \<and> a s = 0 \<and> b s = 0 \<and> r1 s = 0 \<and> init_s (state s) \<and> thrdsvars" definition "global s \<equiv> init_val (state s) x 0 \<and> init_val (state s) y 0 \<and> wfs (state s) \<and> [\<one>\<^sub>x 1] (state s) \<and> [\<one>\<^sub>x 2] (state s)" lemmas prog_simp = prog_def prog_inv_def init_def init_s_def init_map_def lemmas mp_simps [simp] = locals_id_def update_pc_def thrdsvars_def lemma goal: assumes "prog_inv t1 L3 s" and "prog_inv t2 L3 s" and "prog_inv t3 L3 s" and "global s" and "thrdsvars" shows "r1 s = 1 \<and> a s = 2 \<longrightarrow> b s \<noteq> 1" using assms apply(simp add: prog_inv_def global_def) using d_vorder_one_way pvord_to_dvord by fastforce lemma init_global : "init s \<Longrightarrow> thrdsvars \<Longrightarrow> global s" apply (simp add: global_def init_val_def prog_simp) apply (elim conjE, intro conjI) apply(unfold writes_on_def value_def initial_state_def mo_def, simp) apply auto[2] using initial_state_def initial_wfs apply blast apply (metis (no_types, lifting) amo_def n_not_Suc_n p_vorder_def value_def write_record.ext_inject write_record.surjective writes_on_var) using p_vorder_def value_def write_record.ext_inject write_record.surjective writes_on_var by (metis amo_def zero_neq_numeral) lemma init_inv : "init s \<Longrightarrow> thrdsvars \<Longrightarrow> prog_inv t1 L1 s \<and> prog_inv t2 L1 s \<and> prog_inv t3 L1 s" apply(frule_tac init_global[where s=s], simp) apply(simp add: init_def global_def prog_inv_def init_s_def init_map_def initial_state_def) apply(simp_all add: value_def initial_state_def init_map_def init_val_def opsem_def) apply(elim conjE, intro conjI) apply(unfold writes_on_def) apply simp+ apply safe apply auto[2] apply(simp add: c_obs_def visible_writes_def value_def p_obs_def) apply(unfold writes_on_def d_obs_def) apply(simp add: c_obs_def visible_writes_def value_def) apply auto apply(simp add: c_obs_def d_obs_t_def d_obs_def value_def lastWr_def visible_writes_def) apply(unfold writes_on_def) apply auto apply (smt Collect_cong lastWr_def last_write_write_on mem_Collect_eq own_ModView snd_conv writes_on_def) by (metis One_nat_def null_def not_p_obs_implies_c_obs old.prod.exhaust p_obs_def prod.collapse value_def var_def visible_var write_record.select_convs(1) zero_neq_one) lemma global_inv: assumes "global s" and "thrdsvars" and "prog_inv t ((pc s) t) s" and "prog t s s'" and "t = t1 \<or> t = t2 \<or> t = t3" shows "global s'" using assms apply(unfold global_def prog_def prog_inv_def thrdsvars_def) apply (elim disjE) apply simp+ apply(cases "pc s t1", simp+) apply(intro conjI) using init_val_pres apply blast using init_val_pres apply auto[1] using wfs_preserved apply blast apply(elim conjE) apply (simp add: amo_intro_step no_val_def) apply (metis amo_Wr_diff_val_pres n_not_Suc_n numeral_2_eq_2) apply(cases "pc s t1", simp+) apply(elim conjE) apply(intro conjI) using init_val_pres apply blast using init_val_pres apply blast using wfs_preserved apply blast apply (metis amo_WrR_pres) apply (metis amo_WrR_pres) apply simp+ apply (smt PC.simps(8) amo_RdA_pres amo_Wr_diff_val_pres amo_intro_step global_def init_val_pres locals_id_def n_not_Suc_n no_val_def wfs_preserved zero_neq_numeral) by (metis amo_RdX_pres init_val_pres wfs_preserved) lemma t1_local : assumes "prog_inv t1 ((pc s) t1) s" and "global s" and "thrdsvars" and "prog t1 s s'" shows "prog_inv t1 ((pc s') t1) s'" using assms apply (simp add: prog_simp global_def) apply(elim conjE) apply(cases "pc s t1") apply simp+ apply(elim conjE, intro conjI) using not_p_obs_WrX_diff_var_pres using d_obs_WrX_set apply blast apply clarsimp apply (meson d_obs_WrX_set no_val_def p_vorder_WrX_p_vorder) by simp+ lemma t1_global : assumes "prog_inv t1 ((pc s) t1) s" and "global s" and "t = t2 \<or> t = t3" and "prog_inv t ((pc s) t) s" and "thrdsvars" and "prog t s s'" shows "prog_inv t1 ((pc s') t1) s'" using assms apply(elim disjE) apply(simp add: prog_simp global_def) apply(cases "pc s t2") apply(cases "pc s t1", simp) apply (metis no_val_RdA_pres dobs_RdA_pres not_pobs_RdA_pres) apply simp+ apply(cases "pc s t1", simp) using dobs_RdA_pres not_pobs_RdA_pres apply blast apply simp apply(cases "pc s t1", simp) apply simp+ apply(cases "pc s t1", simp) apply (intro conjI) apply (metis One_nat_def nat.inject no_val_WrX_diff_val_pres numeral_2_eq_2 zero_neq_one) using not_p_obs_WrX_diff_var_pres apply blast apply clarsimp apply auto using WrX_no_val apply auto[2] using not_p_obs_WrX_diff_var_pres apply blast using WrX_no_val apply blast using not_p_obs_WrX_diff_var_pres apply blast using WrX_no_val apply auto[1] apply(simp add: prog_simp global_def) apply(cases "pc s t3") apply(cases "pc s t1", simp) apply (meson dobs_RdX_pres no_val_Rdx_pres no_val_def not_pobs_RdX_pres p_vorder_RdX_p_vorder) apply(cases "pc s t1") apply simp+ apply (meson dobs_RdX_pres no_val_def not_pobs_RdX_pres p_vorder_RdX_p_vorder) apply auto[2] apply(cases "pc s t1", simp_all) apply (meson dobs_RdX_pres no_val_Rdx_pres no_val_def not_pobs_RdX_pres p_vorder_RdX_p_vorder) apply(cases "pc s t1", simp) apply (smt PC.simps(8) dobs_RdX_pres fun_upd_other mp_simps(2) no_val_def not_pobs_RdX_pres p_vorder_RdX_p_vorder) by simp+ lemma t2_local : assumes "prog_inv t2 ((pc s) t2) s" and "global s" and "thrdsvars" and "prog t2 s s'" shows "prog_inv t2 ((pc s') t2) s'" using assms apply (simp add: prog_simp global_def) apply(case_tac "pc s t2") apply simp+ apply(elim conjE, intro conjI) apply(intro impI conjI) apply simp using c_obs_RdA_d_obs apply blast apply simp using c_obs_RdA_d_obs d_obs_enc wfs_preserved apply blast using amo_def amo_intro_step no_val_def zero_neq_numeral using no_val_RdA_pres apply auto[1] apply (simp add: amo_intro_step no_val_def) using WrX_d_vorder no_val_def apply fastforce by simp lemma t2_global : assumes "prog_inv t2 ((pc s) t2) s" and "global s" and "t = t1 \<or> t = t3" and "prog_inv t ((pc s) t) s" and "thrdsvars" and "prog t s s'" shows "prog_inv t2 ((pc s') t2) s'" using assms apply(elim disjE) apply (simp add: prog_simp global_def) apply(elim conjE) apply(cases "pc s t2") apply simp+ apply(cases "pc s t1") apply(cases "pc s t2", simp) apply(elim conjE, intro conjI) apply (metis One_nat_def nat.inject no_val_WrX_diff_val_pres numeral_2_eq_2 zero_neq_one) using amo_Wr_diff_val_pres using not_p_obs_WrX_diff_var_pres not_p_obs_implies_c_obs apply auto[1] apply simp_all apply (metis c_obs_WrR_intro no_val_WrR_diff_var_pres) apply(cases "pc s t1", simp) apply (metis d_obs_def d_obs_t_def n_not_Suc_n no_val_WrX_diff_val_pres numeral_2_eq_2) apply(cases "pc s t1", auto) using no_val_WrR_diff_var_pres apply force apply (metis dobs_WrR_pres) using enc_pres apply blast using no_val_WrR_diff_var_pres apply force apply(cases "pc s t1", auto) apply(cases "pc s t1", auto) apply (metis WrX_def amo_Wr_diff_val_pres amo_intro_step isWr.simps(2) no_val_def numeral_2_eq_2 opsem_def(3) p_vorder_write_pres pvord_to_dvord) apply (metis assms(4) assms(6) global_def global_inv numeral_1_eq_Suc_0 numeral_One opsem_def(3) p_vorder_WrX_p_vorder pvord_to_dvord thrdsvars_def) apply (metis amo_WrR_pres opsem_def(3) p_vorder_WrR_p_vorder pvord_to_dvord) apply (metis amo_WrR_pres opsem_def(3) p_vorder_WrR_p_vorder pvord_to_dvord) apply (simp add: prog_simp global_def) apply(elim conjE) apply(cases "pc s t3") apply simp+ apply(cases "pc s t1") apply(cases "pc s t2", simp) apply(elim conjE, intro conjI) using no_val_Rdx_pres apply blast using cobs_RdX_diff_var_pres apply blast apply (metis PC.simps(8) RdX_def dobs_Rd_pres enc_pres isRd.simps(1) no_val_Rdx_pres) using d_vorder_RdX_pres apply auto[1] apply(cases "pc s t2", auto) using no_val_Rdx_pres apply blast using cobs_RdX_diff_var_pres apply blast using no_val_Rdx_pres apply blast using dobs_RdX_pres apply blast using enc_pres apply blast using no_val_Rdx_pres apply blast using d_vorder_RdX_pres apply blast apply(cases "pc s t2", simp) using cobs_RdX_diff_var_pres no_val_Rdx_pres apply auto[1] apply (metis PC.simps(8) RdX_def dobs_Rd_pres enc_pres isRd.simps(1) no_val_Rdx_pres) using d_vorder_RdX_pres apply auto[1] apply(cases "pc s t2", simp) using cobs_RdX_diff_var_pres no_val_Rdx_pres apply auto[1] apply (metis PC.simps(8) RdX_def dobs_Rd_pres enc_pres isRd.simps(1) no_val_Rdx_pres) using d_vorder_RdX_pres by auto lemma t3_local : assumes "prog_inv t3 ((pc s) t3) s" and "global s" and "thrdsvars" and "prog t3 s s'" shows "prog_inv t3 ((pc s') t3) s'" using assms apply (simp add: prog_simp global_def) apply(case_tac "pc s t3") apply simp+ using enc_RdX_intro apply blast apply simp apply(elim conjE) defer apply simp using enc_Rdx_p_vorder by blast lemma t3_global: assumes "prog_inv t3 ((pc s) t3) s" and "t = t1 \<or> t = t2" and "prog_inv t ((pc s) t) s" and "thrdsvars" and "prog t s s'" shows "prog_inv t3 ((pc s') t3) s'" using assms apply(elim disjE) apply (simp_all add: prog_simp global_def) apply(case_tac "pc s t1") apply(case_tac "pc s t3") apply simp+ using enc_pres apply blast apply clarsimp using p_vorder_WrX_p_vorder apply blast apply(case_tac "pc s t3") apply simp+ using enc_pres apply blast apply simp+ apply(elim conjE, intro impI, simp) using p_vorder_WrR_p_vorder apply blast apply simp apply(case_tac "pc s t2") apply(case_tac "pc s t3") apply simp+ using enc_pres apply blast apply clarsimp using p_vorder_RdA_p_vorder apply blast apply(case_tac "pc s t3") apply simp+ using enc_pres apply blast apply simp using p_vorder_WrX_p_vorder apply blast by simp theorem final_inv: assumes "wfs (state s)" and "global s" and "thrdsvars" and "t \<in> {t1, t2, t3}" and "t' \<in> {t1, t2, t3}" and "prog_inv t ((pc s) t) s" and "prog_inv t' ((pc s) t') s" and "prog t' s s'" shows "prog_inv t ((pc s') t) s'" using assms apply (simp del: thrdsvars_def) by (meson t1_global t1_local t2_global t2_local t3_global t3_local) end
`is_element/itloc/I` := (n::nonnegint) -> (i) -> type(i,nonnegint) and i < n: `list_elements/itloc/I` := (n::nonnegint) -> [seq(i,i=0..n-1)]: ###################################################################### `is_element/itloc/P` := (n::nonnegint) -> (A) -> type(A,set(nonnegint)) and (nops(A) = 0 or max(0,op(A)) < n): `list_elements/itloc/P` := (n::nonnegint) -> [op(combinat[powerset]({seq(i,i=0..n-1)}))]; `is_leq/itloc/P` := (n::nonnegint) -> (A,B) -> evalb (A minus B = {}); `bot/itloc/P` := (n::nonnegint) -> {}; `top/itloc/P` := (n::nonnegint) -> {seq(i,i=0..n-1)}; `sup/itloc/P` := (n::nonnegint) -> (A,B) -> A union B; `inf/itloc/P` := (n::nonnegint) -> (A,B) -> A intersect B; `angle/itloc/P` := (n::nonnegint) -> (A,B) -> (A = {} or B = {} or max(op(A)) <= min(op(B))); ###################################################################### `is_element/itloc/Q` := (n::nonnegint) -> proc(U) local N,A,b; if not type(U,set(set(nonnegint))) then return false; fi; if n = 0 then return evalb(U minus {{}} = {}); fi; if max(0,op(map(op,U))) >= n then return false; fi; N := `list_elements/itloc/I`(n); for A in U do for b in N minus A do if not(member(A union {b},U)) then return false; fi; od; od; return true; end: `is_leq/itloc/Q` := (n::nonnegint) -> (U,V) -> evalb (V minus U = {}); `itloc/u` := (n::nonnegint) -> proc (A::set(nonnegint)) local BB; BB := `list_elements/itloc`(n) minus A; return map(B -> A union B,BB); end: `bot/itloc/Q` := (n::nonnegint) -> `itloc/u`(n)({}); `top/itloc/Q` := (n::nonnegint) -> {}; `omul/itloc/Q` := (n::nonnegint) -> proc(U,V) local UV; UV := {seq(seq([A,B],B in V),A in U)}; UV := select(AB -> `angle/itloc/P`(n)(op(AB)),UV); return UV; end: `mul/itloc/Q` := (n::nonnegint) -> (U,V) -> map(AB -> AB[1] union AB[2],`omul/itloc/Q`(U,V)); ###################################################################### `is_element/itloc/M` := (n::nonnegint) -> (AB) -> type(AB,list) and nops(AB) = 2 and `is_element/itloc/P`(n)(AB[1]) and `is_element/itloc/P`(n)(AB[2]) and `itloc/angle`(n)(op(AB)); `list_elements/itloc/M` := proc(n::nonnegint) local P,Q,i; P := `list_elements/itloc/P`(n); Q := table(); for i from 0 to n do Q[i] := combinat[powerset]({seq(j,j=i..n-1)}); end: return [seq(seq([A,B],B in Q[max(0,op(A))]),A in P)]; end: `is_leq/itloc/M` := (n::nonnegint) -> (AB0,AB1) -> evalb (`is_leq/itloc/P`(n)(AB0[1],AB1[1]) and `is_leq/itloc/P`(n)(AB0[2],AB1[2])); `bot/itloc/M` := (n::nonnegint) -> [{},{}]; `inf/itloc/M` := (n::nonnegint) -> (AB0,AB1) -> [AB0[1] intersect AB1[1],AB0[2] intersect AB1[2]]; `zeta/itloc` := (n::nonnegint) -> B -> [{},B]; `xi/itloc` := (n::nonnegint) -> A -> [A,{}]; `sigma/itloc` := (n::nonnegint) -> AB -> AB[1] union AB[2]; `alpha/itloc` := (n::nonnegint) -> (i) -> (AB) -> [select(a -> a < i,AB[1]), select(a -> a >= i,AB[1]) union AB[2]]; `beta/itloc` := (n::nonnegint) -> (i) -> (AB) -> [select(a -> a <= i,AB[1]), select(a -> a >= i,AB[1]) union AB[2]]; `gamma/itloc` := (n::nonnegint) -> (i) -> (AB) -> [AB[1] union select(b -> b < i,AB[2]), select(b -> b >= i,AB[2])]; `delta/itloc` := (n::nonnegint) -> (i) -> (AB) -> [AB[1] union select(b -> b <= i,AB[2]), select(b -> b >= i,AB[2])]; ###################################################################### `is_element/itloc/L` := (n::nonnegint) -> proc(U) local N,AB,A,B,a,b,A1,B1,i,j; if not type(U,set(list(set(nonnegint)))) then return false; fi; N := `list_elements/itloc/I`(n); for AB in U do if not(`is_element/itloc/M`(n)(AB)) then return false; fi; od; for AB in U do A,B = op(AB); a := max(0,op(A)); b := min(n-1,op(B)); A1 := {seq(i,i=0..b)} minus A; B1 := {seq(i,i=a..n-1)} minus B; for i in A1 do if not(member([A union {i},B]),U) then return false; fi; od; for j in B1 do if not(member([A,B union {j}]),U) then return false; fi; od; od; return true; end: `is_leq/itloc/L` := (n::nonnegint) -> (U,V) -> evalb (V minus U = {}) `itloc/v` := (n::nonnegint) -> proc (AB::[set(nonnegint),set(nonnegint)]) local a,b,A,A1,A2,A3,B,B1,L; A,B = op(AB); b := min(n-1,op(B)); A1 := {seq(i,i=0..b)} minus A; L := NULL; for A2 in combinat[powerset](A1) do A3 := A union A2; a := max(0,op(A3)); B1 := {seq(j,j=a..n-1)} minus B; L := L,seq([A3,B union B2],B2 in combinat[powerset](B1)); od: return {L}; end:
module Utils.Helpers import Data.SortedSet import Data.SortedMap import Data.List %hide Prelude.toList export setMap : Ord b => (a -> b) -> SortedSet a -> SortedSet b setMap fn setv = fromList $ map fn (toList setv) export mapMap : Ord k2 => ((k1,a) -> (k2, b)) -> SortedMap k1 a -> SortedMap k2 b mapMap fn mapv = fromList $ map fn (toList mapv) export mapValueMap : Ord k => (a -> b) -> SortedMap k a -> SortedMap k b mapValueMap fn mapv = mapMap (\(k,v) => (k, fn v)) mapv export mapFilter : Ord k => ((k,a) -> Bool) -> SortedMap k a -> SortedMap k a mapFilter fn mapv = fromList $ filter fn (toList mapv) export keyFilter : Ord k => (k -> Bool) -> SortedMap k a -> SortedMap k a keyFilter fn mapv = mapFilter (fn . fst) mapv export maybeMap : (a -> b) -> Maybe a -> Maybe b maybeMap _ Nothing = Nothing maybeMap f (Just av) = Just (f av) export [dropDuplicateKeysSemigroup] Semigroup (SortedMap k v) where (<+>) = mergeLeft export [dropDuplicateKeysMonoid] (Ord k) => Monoid (SortedMap k v) using dropDuplicateKeysSemigroup where neutral = empty
Formal statement is: lemma distr_bij_count_space: assumes f: "bij_betw f A B" shows "distr (count_space A) (count_space B) f = count_space B" Informal statement is: If $f$ is a bijection from $A$ to $B$, then the distribution of $B$ is the same as the distribution of $A$ under $f$.
Require Import Crypto.Arithmetic.PrimeFieldTheorems. Require Import Crypto.Specific.solinas32_2e512m569_24limbs.Synthesis. (* TODO : change this to field once field isomorphism happens *) Definition carry : { carry : feBW_loose -> feBW_tight | forall a, phiBW_tight (carry a) = (phiBW_loose a) }. Proof. Set Ltac Profiling. Time synthesize_carry (). Show Ltac Profile. Time Defined. Print Assumptions carry.
theory TheoremD2 imports LocalLexingLemmas Validity Derivations begin context LocalLexing begin definition splits_at :: "('a, 'b) sentence \<Rightarrow> nat \<Rightarrow> ('a, 'b) sentence \<Rightarrow> ('a, 'b) symbol \<Rightarrow> ('a, 'b) sentence \<Rightarrow> bool" where "splits_at \<delta> i \<alpha> N \<beta> = (i < length \<delta> \<and> \<alpha> = take i \<delta> \<and> N = \<delta> ! i \<and> \<beta> = drop (Suc i) \<delta>)" lemma splits_at_combine: "splits_at \<delta> i \<alpha> N \<beta> \<Longrightarrow> \<delta> = \<alpha> @ [N] @ \<beta>" by (simp add: id_take_nth_drop splits_at_def) lemma splits_at_combine_dest: "Derives1 a i r b \<Longrightarrow> splits_at a i \<alpha> N \<beta> \<Longrightarrow> b = \<alpha> @ (snd r) @ \<beta>" by (metis (no_types, lifting) Derives1_drop Derives1_split append_assoc append_eq_conv_conj length_append splits_at_def) lemma Derives1_nonterminal: assumes "Derives1 a i r b" assumes "splits_at a i \<alpha> N \<beta>" shows "fst r = N \<and> is_nonterminal N" proof - from assms have fst: "fst r = N" by (metis Derives1_split append_Cons nth_append_length splits_at_def) then have "is_nonterminal N" by (metis Derives1_def assms(1) prod.collapse rule_nonterminal_type) with fst show ?thesis by auto qed lemma splits_at_ex: "Derives1 \<delta> i r s \<Longrightarrow> \<exists> \<alpha> N \<beta>. splits_at \<delta> i \<alpha> N \<beta>" by (simp add: Derives1_bound splits_at_def) lemma splits_at_\<alpha>: "Derives1 \<delta> i r s \<Longrightarrow> splits_at \<delta> i \<alpha> N \<beta> \<Longrightarrow> \<alpha> = take i \<delta> \<and> \<alpha> = take i s \<and> length \<alpha> = i" by (metis Derives1_split append_eq_conv_conj splits_at_def) lemma LeftDerives1_splits_at_is_word: "LeftDerives1 \<delta> i r s \<Longrightarrow> splits_at \<delta> i \<alpha> N \<beta> \<Longrightarrow> is_word \<alpha>" by (metis LeftDerives1_def leftmost_def splits_at_def) lemma splits_at_\<beta>: "Derives1 \<delta> i r s \<Longrightarrow> splits_at \<delta> i \<alpha> N \<beta> \<Longrightarrow> \<beta> = drop (Suc i) \<delta> \<and> \<beta> = drop (i + length (snd r)) s \<and> length \<beta> = length \<delta> - i - 1" by (metis Derives1_drop Suc_eq_plus1 diff_diff_left length_drop splits_at_def) lemma Derives1_suffix: assumes ab: "Derives1 \<delta> i r (a@b)" assumes split: "splits_at \<delta> i \<alpha> N \<beta>" shows "is_suffix \<beta> b \<or> is_suffix b \<beta>" proof - have drop1: "\<beta> = drop (i + length (snd r)) (a@b)" using ab split splits_at_\<beta> by blast have drop2: "b = drop (length a) (a@b)" by simp show ?thesis proof (cases "(i + length (snd r)) \<le> length a") case True with drop1 drop2 have "is_suffix b \<beta>" by (simp add: is_suffix_def) then show ?thesis by auto next case False then have "length a \<le> (i + length (snd r))" by arith with drop1 drop2 have "is_suffix \<beta> b" by (metis append_Nil append_take_drop_id drop_append drop_eq_Nil is_suffix_def) then show ?thesis by auto qed qed lemma Derives1_skip_prefix: "length a \<le> i \<Longrightarrow> Derives1 (a@b) i r (a@c) \<Longrightarrow> Derives1 b (i - length a) r c" apply (auto simp add: Derives1_def) by (metis append_eq_append_conv_if is_sentence_concat is_sentence_cons is_symbol_def length_drop rule_nonterminal_type) lemma cancel_suffix: assumes "a @ c = b @ d" assumes "length c \<le> length d" shows "a = b @ (take (length d - length c) d)" proof - have "a @ c = (b @ take (length d - length c) d) @ drop (length d - length c) d" by (metis append_assoc append_take_drop_id assms(1)) then show ?thesis by (metis append_eq_append_conv assms(2) diff_diff_cancel length_drop) qed lemma is_sentence_take: "is_sentence y \<Longrightarrow> is_sentence (take n y)" by (metis append_take_drop_id is_sentence_concat) lemma Derives1_skip_suffix: assumes i: "i < length a" assumes D: "Derives1 (a@c) i r (b@c)" shows "Derives1 a i r b" proof - note Derives1_def[where u="a@c" and v="b@c" and i=i and r=r] then have "\<exists>x y N \<alpha>. a @ c = x @ [N] @ y \<and> b @ c = x @ \<alpha> @ y \<and> is_sentence x \<and> is_sentence y \<and> (N, \<alpha>) \<in> \<RR> \<and> r = (N, \<alpha>) \<and> i = length x" using D by blast then obtain x y N \<alpha> where split: "a @ c = x @ [N] @ y \<and> b @ c = x @ \<alpha> @ y \<and> is_sentence x \<and> is_sentence y \<and> (N, \<alpha>) \<in> \<RR> \<and> r = (N, \<alpha>) \<and> i = length x" by blast from split have "length (a@c) = length (x @ [N] @ y)" by auto then have "length a + length c = length x + length y + 1" by simp with split have "length a + length c = i + length y + 1" by simp with i have len_c_y: "length c \<le> length y" by arith let ?y = "take (length y - length c) y" from split have ac: "a @ c = (x @ [N]) @ y" by auto note cancel_suffix[where a=a and c = c and b = "x@[N]" and d = "y", OF ac len_c_y] then have a: "a = x @ [N] @ ?y" by auto from split have bc: "b @ c = (x @ \<alpha>) @ y" by auto note cancel_suffix[where a=b and c = c and b = "x@\<alpha>" and d = "y", OF bc len_c_y] then have b: "b = x @ \<alpha> @ ?y" by auto from split len_c_y a b show ?thesis apply (simp only: Derives1_def) apply (rule_tac x=x in exI) apply (rule_tac x="?y" in exI) apply (rule_tac x="N" in exI) apply (rule_tac x="\<alpha>" in exI) apply auto by (rule is_sentence_take) qed lemma drop_cancel_suffix: "a@c = drop n (b@c) \<Longrightarrow> a = drop n b" proof - assume a1: "a @ c = drop n (b @ c)" have "length (drop n b) = length b + length c - n - length c" by (metis add_diff_cancel_right' diff_commute length_drop) then show ?thesis using a1 by (metis add_diff_cancel_right' append_eq_append_conv drop_append length_append length_drop) qed lemma drop_keep_last: "u \<noteq> [] \<Longrightarrow> u = drop n (a@[X]) \<Longrightarrow> u = drop n a @ [X]" by (metis append_take_drop_id drop_butlast last_appendR snoc_eq_iff_butlast) lemma Derives1_X_is_part_of_rule[consumes 2, case_names Suffix Prefix]: assumes aXb: "Derives1 \<delta> i r (a@[X]@b)" assumes split: "splits_at \<delta> i \<alpha> N \<beta>" assumes prefix: "\<And> \<beta>. \<delta> = a @ [X] @ \<beta> \<Longrightarrow> length a < i \<Longrightarrow> Derives1 \<beta> (i - length a - 1) r b \<Longrightarrow> False" assumes suffix: "\<And> \<alpha>. \<delta> = \<alpha> @ [X] @ b \<Longrightarrow> Derives1 \<alpha> i r a \<Longrightarrow> False" shows "\<exists> u v. a = \<alpha> @ u \<and> b = v @ \<beta> \<and> (snd r) = u@[X]@v" proof - have prefix_or: "is_prefix \<alpha> a \<or> is_proper_prefix a \<alpha>" by (metis Derives1_prefix split aXb is_prefix_eq_proper_prefix) have "is_proper_prefix a \<alpha> \<Longrightarrow> False" proof - assume proper:"is_proper_prefix a \<alpha>" then have "\<exists> u. u \<noteq> [] \<and> \<alpha> = a@u" by (metis is_proper_prefix_def) then obtain u where u: "u \<noteq> [] \<and> \<alpha> = a@u" by blast note splits_at = splits_at_\<alpha>[OF aXb split] splits_at_combine[OF split] from splits_at have \<alpha>1: "\<alpha> = take i \<delta>" by blast from splits_at have \<alpha>2: "\<alpha> = take i (a@[X]@b)" by blast from splits_at have len\<alpha>: "length \<alpha> = i" by blast with proper have lena: "length a < i" using append_eq_conv_conj drop_eq_Nil leI u by auto from u \<alpha>2 have "a@u = take i (a@[X]@b)" by auto with lena have "u = take (i - length a) ([X]@b)" by (simp add: less_or_eq_imp_le) with lena have uX: "u = [X]@(take (i - length a - 1) b)" by (simp add: not_less take_Cons') let ?\<beta> = "(take (i - length a - 1) b) @ [N] @ \<beta>" from splits_at have f1: "\<delta> = \<alpha> @ [N] @ \<beta>" by blast with u uX have f2: "\<delta> = a @ [X] @ ?\<beta>" by simp note skip = Derives1_skip_prefix[where a = "a @ [X]" and b = "?\<beta>" and r = r and i = i and c = b] then have D: "Derives1 ?\<beta> (i - length a - 1) r b" using One_nat_def Suc_leI aXb append_assoc diff_diff_left f2 lena length_Cons length_append length_append_singleton list.size(3) by fastforce note prefix[OF f2 lena D] then show "False" . qed with prefix_or have is_prefix: "is_prefix \<alpha> a" by blast from aXb have aXb': "Derives1 \<delta> i r ((a@[X])@b)" by auto note Derives1_suffix[OF aXb' split] then have suffix_or: "is_suffix \<beta> b \<or> is_proper_suffix b \<beta>" by (metis is_suffix_eq_proper_suffix) have "is_proper_suffix b \<beta> \<Longrightarrow> False" proof - assume proper: "is_proper_suffix b \<beta>" then have "\<exists> u. u \<noteq> [] \<and> \<beta> = u@b" by (metis is_proper_suffix_def) then obtain u where u: "u \<noteq> [] \<and> \<beta> = u@b" by blast note splits_at = splits_at_\<beta>[OF aXb split] splits_at_combine[OF split] from splits_at have \<beta>1: "\<beta> = drop (Suc i) \<delta>" by blast from splits_at have \<beta>2: "\<beta> = drop (i + length (snd r)) (a @ [X] @ b)" by blast from splits_at have len\<beta>: "length \<beta> = length \<delta> - i - 1" by blast with proper have lenb: "length b < length \<beta>" by (metis is_proper_suffix_length_cmp) from u \<beta>2 have "u@b = drop (i + length (snd r)) ((a @ [X]) @ b)" by auto hence "u = drop (i + length (snd r)) (a @ [X])" by (metis drop_cancel_suffix) hence uX: "u = drop (i + length (snd r)) a @ [X]" by (metis drop_keep_last u) let ?\<alpha> = "\<alpha> @ [N] @ (drop (i + length (snd r)) a)" from splits_at have f1: "\<delta> = \<alpha> @ [N] @ \<beta>" by blast with u uX have f2: "\<delta> = ?\<alpha> @ [X] @ b" by simp note skip = Derives1_skip_suffix[where a = "?\<alpha>" and c = "[X]@b" and b="a" and r = r and i = i] have f3: "i < length (\<alpha> @ [N] @ drop (i + length (snd r)) a)" proof - have f1: "1 + i + length b = length [X] + length b + i" by (metis Groups.add_ac(2) Suc_eq_plus1_left length_Cons list.size(3) list.size(4) semiring_normalization_rules(22)) have f2: "length \<delta> - i - 1 = length ((\<alpha> @ [N] @ drop (i + length (snd r)) a) @ [X] @ b) - Suc i" by (metis f2 length_drop splits_at(1)) have "length ([]:: ('a, 'b) symbol list) \<noteq> length \<delta> - i - 1 - length b" by (metis add_diff_cancel_right' append_Nil2 append_eq_append_conv len\<beta> length_append u) then have "length ([]:: ('a, 'b) symbol list) \<noteq> length \<alpha> + length ([N] @ drop (i + length (snd r)) a) - i" using f2 f1 by (metis Suc_eq_plus1_left add_diff_cancel_right' diff_diff_left length_append) then show ?thesis by auto qed from aXb f2 have D: "Derives1 (?\<alpha> @ [X] @ b) i r (a@[X]@b)" by auto note skip[OF f3 D] note suffix[OF f2 skip[OF f3 D]] then show "False" . qed with suffix_or have is_suffix: "is_suffix \<beta> b" by blast from is_prefix have "\<exists> u. a = \<alpha> @ u" by (auto simp add: is_prefix_def) then obtain u where u: "a = \<alpha> @ u" by blast from is_suffix have "\<exists> v. b = v @ \<beta>" by (auto simp add: is_suffix_def) then obtain v where v: "b = v @ \<beta>" by blast from u v splits_at_combine[OF split] aXb have D:"Derives1 (\<alpha>@[N]@\<beta>) i r (\<alpha>@(u@[X]@v)@\<beta>)" by simp from splits_at_\<alpha>[OF aXb split] have i: "length \<alpha> = i" by blast from i have i1: "length \<alpha> \<le> i" and i2: "i \<le> length \<alpha>" by auto note Derives1_skip_suffix[OF _ Derives1_skip_prefix[OF i1 D], simplified, OF i2] then have "Derives1 [N] 0 r (u @ [X] @ v)" by auto then have r: "snd r = u @ [X] @ v" by (metis Derives1_split append_Cons append_Nil length_0_conv list.inject self_append_conv) show ?thesis using u v r by auto qed lemma \<L>\<^sub>P_derives: "a \<in> \<L>\<^sub>P \<Longrightarrow> \<exists> b. derives [\<SS>] (a@b)" by (simp add: \<L>\<^sub>P_def is_derivation_def) lemma \<L>\<^sub>P_leftderives: "a \<in> \<L>\<^sub>P \<Longrightarrow> \<exists> b. leftderives [\<SS>] (a@b)" by (metis \<L>\<^sub>P_derives \<L>\<^sub>P_is_word derives_implies_leftderives_gen) lemma Derives1_rule: "Derives1 a i r b \<Longrightarrow> r \<in> \<RR>" by (auto simp add: Derives1_def) lemma is_prefix_empty[simp]: "is_prefix [] a" by (simp add: is_prefix_def) lemma is_prefix_cons: "is_prefix (x # a) b = (\<exists> c. b = x # c \<and> is_prefix a c)" by (metis append_Cons is_prefix_def) lemma is_prefix_cancel[simp]: "is_prefix (a@b) (a@c) = is_prefix b c" by (metis append_assoc is_prefix_def same_append_eq) lemma is_prefix_chars: "is_prefix a b \<Longrightarrow> is_prefix (chars a) (chars b)" proof (induct a arbitrary: b) case Nil thus ?case by simp next case (Cons x a) from Cons(2) have "\<exists> c. b = x # c \<and> is_prefix a c" by (simp add: is_prefix_cons) then obtain c where c: "b = x # c \<and> is_prefix a c" by blast from c Cons(1) show ?case by simp qed lemma is_prefix_length: "is_prefix a b \<Longrightarrow> length a \<le> length b" by (auto simp add: is_prefix_def) lemma is_prefix_take[simp]: "is_prefix (take n a) a" apply (auto simp add: is_prefix_def) apply (rule_tac x="drop n a" in exI) by simp lemma doc_tokens_length: "doc_tokens p \<Longrightarrow> length (chars p) \<le> length Doc" by (metis doc_tokens_def is_prefix_length) fun count_terminals :: " ('a, 'b) sentence \<Rightarrow> nat" where "count_terminals [] = 0" | "count_terminals (x#xs) = (if (is_terminal x) then Suc (count_terminals xs) else (count_terminals xs))" lemma count_terminals_upper_bound: "count_terminals p \<le> length p" by (induct p, auto) lemma count_terminals_append[simp]: "count_terminals (a@b) = count_terminals a + count_terminals b" by (induct a arbitrary: b, auto) lemma Derives1_count_terminals: assumes D: "Derives1 a i r b" shows "count_terminals b = count_terminals a + count_terminals (snd r)" proof - have "\<exists> \<alpha> N \<beta>. splits_at a i \<alpha> N \<beta>" using D splits_at_ex by simp then obtain \<alpha> N \<beta> where split: "splits_at a i \<alpha> N \<beta>" by blast from D split have N: "is_nonterminal N" by (simp add: Derives1_nonterminal) have a: "a = \<alpha> @ [N] @ \<beta>" by (metis split splits_at_combine) from D split have b: "b = \<alpha> @ (snd r) @ \<beta>" using splits_at_combine_dest by simp show ?thesis apply (simp add: a b) using N by (metis is_terminal_nonterminal) qed lemma Derives1_count_terminals_leq: assumes D: "Derives1 a i r b" shows "count_terminals a \<le> count_terminals b" by (metis Derives1_count_terminals assms le_less_linear not_add_less1) lemma Derivation_count_terminals_leq: "Derivation a E b \<Longrightarrow> count_terminals a \<le> count_terminals b" proof (induct E arbitrary: a) case Nil thus ?case by auto next case (Cons e E) then have "\<exists> x i r. Derives1 a i r x \<and> Derivation x E b" using Derivation.simps(2) by blast then obtain x i r where axb: "Derives1 a i r x \<and> Derivation x E b" by blast from axb have ax: "count_terminals a \<le> count_terminals x" using Derives1_count_terminals_leq by blast from axb have xb: "count_terminals x \<le> count_terminals b" using Cons by simp show ?case using ax xb by arith qed lemma derives_count_terminals_leq: "derives a b \<Longrightarrow> count_terminals a \<le> count_terminals b" using Derivation_count_terminals_leq derives_implies_Derivation by force lemma is_word_cons[simp]: "is_word (x#xs) = (is_terminal x \<and> is_word xs)" by (simp add: is_word_def) lemma count_terminals_of_word: "is_word w \<Longrightarrow> count_terminals w = length w" by (induct w, auto) lemma length_terminals[simp]: "length (terminals p) = length p" by (auto simp add: terminals_def) lemma path_length_is_upper_bound: assumes p: "wellformed_tokens p" assumes \<alpha>: "is_word \<alpha>" assumes derives: "derives (\<alpha>@u) (terminals p)" shows "length \<alpha> \<le> length p" proof - have counts: "count_terminals \<alpha> \<le> count_terminals (terminals p)" using derives derives_count_terminals_leq by fastforce have len1: "length \<alpha> = count_terminals \<alpha>" by (simp add: \<alpha> count_terminals_of_word) have len2: "length (terminals p) = count_terminals (terminals p)" by (simp add: count_terminals_of_word is_word_terminals p) show ?thesis using counts len1 len2 by auto qed lemma is_word_Derives1_index: assumes w: "is_word w" assumes derives1: "Derives1 (w@a) i r b" shows "i \<ge> length w" proof - from derives1 have n: "is_nonterminal ((w@a) ! i)" using Derives1_nonterminal splits_at_def splits_at_ex by auto from w have t: "i < length w \<Longrightarrow> is_terminal ((w@a) ! i)" by (simp add: is_word_is_terminal nth_append) show ?thesis by (metis t n is_terminal_nonterminal less_le_not_le nat_le_linear) qed lemma is_word_Derivation_derivation_ge: assumes w: "is_word w" assumes D: "Derivation (w@a) D b" shows "derivation_ge D (length w)" by (metis D Derivation_leftmost derivation_ge_empty leftmost_Derivation leftmost_append w) lemma derives_word_is_prefix: assumes w: "is_word w" assumes derives: "derives (w@a) b" shows "is_prefix w b" by (metis Derivation_take append_eq_conv_conj derives derives_implies_Derivation is_prefix_take is_word_Derivation_derivation_ge w) lemma terminals_take[simp]: "terminals (take n p) = take n (terminals p)" by (simp add: take_map terminals_def) lemma terminals_drop[simp]: "terminals (drop n p) = drop n (terminals p)" by (simp add: drop_map terminals_def) lemma take_prefix[simp]: "is_prefix a b \<Longrightarrow> take (length a) b = a" by (metis append_eq_conv_conj is_prefix_unsplit) lemma Derives1_drop_prefixword: assumes w: "is_word w" assumes wa_b: "Derives1 (w@a) i r b" shows "Derives1 a (i - length w) r (drop (length w) b)" proof - have i: "length w \<le> i" using wa_b is_word_Derives1_index w by blast have "is_prefix w b" by (metis append_eq_conv_conj i is_prefix_take le_Derives1_take wa_b) then have b: "b = w @ (drop (length w) b)" by (simp add: is_prefix_unsplit) show ?thesis apply (rule_tac Derives1_skip_prefix[OF i]) by (simp add: b[symmetric] wa_b) qed lemma derives1_drop_prefixword: assumes w: "is_word w" assumes wa_b: "derives1 (w@a) b" shows "derives1 a (drop (length w) b)" by (metis Derives1_drop_prefixword Derives1_implies_derives1 derives1_implies_Derives1 w wa_b) lemma derives1_is_word_is_prefix_drop: assumes w: "is_word w" assumes w_a: "is_prefix w a" assumes ab: "derives1 a b" shows "derives1 (drop (length w) a) (drop (length w) b)" by (metis ab append_take_drop_id derives1_drop_prefixword take_prefix w w_a) lemma derives_drop_prefixword_helper: "derives a b \<Longrightarrow> is_word w \<Longrightarrow> is_prefix w a \<Longrightarrow> derives (drop (length w) a) (drop (length w) b)" proof (induct rule: derives_induct) case Base thus ?case by auto next case (Step y z) have is_prefix_w_y: "is_prefix w y" by (metis Step.hyps(1) Step.prems(1) Step.prems(2) derives_word_is_prefix is_prefix_def) thus ?case by (metis Step.hyps(2) Step.hyps(3) Step.prems(1) Step.prems(2) derives1_implies_derives derives1_is_word_is_prefix_drop derives_trans) qed lemma derive_drop_prefixword: "is_word w \<Longrightarrow> derives (w@a) b \<Longrightarrow> derives a (drop (length w) b)" by (metis append_eq_conv_conj derives_drop_prefixword_helper is_prefix_take) lemma thmD2': assumes X: "is_terminal X" assumes p: "doc_tokens p" assumes pX: "(terminals p)@[X] \<in> \<L>\<^sub>P" shows "\<exists> x. pvalid p x \<and> next_symbol x = Some X" proof - from p have wellformed_p: "wellformed_tokens p" by (simp add: doc_tokens_def) have "\<exists> \<omega>. leftderives [\<SS>] (((terminals p)@[X]) @ \<omega>)" using \<L>\<^sub>P_leftderives pX by blast then obtain \<omega> where "leftderives [\<SS>] (((terminals p)@[X]) @ \<omega>)" by blast then have "\<exists> D. LeftDerivation [\<SS>] D (((terminals p)@[X]) @ \<omega>)" using leftderives_implies_LeftDerivation by blast then obtain D where D: "LeftDerivation [\<SS>] D (((terminals p)@[X]) @ \<omega>)" by blast let ?P = "\<lambda> k. (\<exists> a b. LeftDerivation [\<SS>] (take k D) (a@[X]@b) \<and> derives a (terminals p))" have "?P (length D)" apply (rule_tac x="terminals p" in exI) apply (rule_tac x="\<omega>" in exI) using D by simp then show ?thesis proof (induct rule: minimal_witness[where P="?P"]) case (Minimal K) from Minimal(2) obtain a b where aXb: "LeftDerivation [\<SS>] (take K D) (a @ [X] @ b)" and a: "derives a (terminals p)" by blast have KD: "K > 0 \<and> length D > 0" proof (cases "K = 0 \<or> length D = 0") case True hence "take K D = []" by auto with True aXb have "[\<SS>] = a @ [X] @ b" by simp hence "\<SS> = X" by (metis Nil_is_append_conv append_self_conv2 butlast.simps(2) butlast_append hd_append2 list.sel(1) not_Cons_self2) then have "False" using X is_nonterminal_startsymbol is_terminal_nonterminal by auto then show ?thesis by blast next case False thus ?thesis by arith qed then have "take K D = take (K - 1) D @ [D ! (K - 1)]" by (metis Minimal.hyps(1) One_nat_def Suc_less_eq Suc_pred hd_drop_conv_nth le_imp_less_Suc take_hd_drop) (*subtree extraction*) with aXb have "\<exists> \<delta>. LeftDerivation [\<SS>] (take (K - 1) D) \<delta> \<and> LeftDerivation \<delta> [D ! (K - 1)] (a@[X]@b)" using LeftDerivation_append by fastforce then obtain \<delta> where \<delta>1: "LeftDerivation [\<SS>] (take (K - 1) D) \<delta>" and \<delta>2: "LeftDerivation \<delta> [D ! (K - 1)] (a@[X]@b)" by blast from \<delta>2 have "\<exists> i r. LeftDerives1 \<delta> i r (a@[X]@b)" by fastforce then obtain i r where LeftDerives1_\<delta>: "LeftDerives1 \<delta> i r (a@[X]@b)" by blast then have Derives1_\<delta>: "Derives1 \<delta> i r (a@[X]@b)" by (metis LeftDerives1_implies_Derives1) then have "\<exists> \<alpha> N \<beta> . splits_at \<delta> i \<alpha> N \<beta>" by (simp add: splits_at_ex) then obtain \<alpha> N \<beta> where split_\<delta>: "splits_at \<delta> i \<alpha> N \<beta>" by blast have is_word_\<alpha>: "is_word \<alpha>" by (metis LeftDerives1_\<delta> LeftDerives1_splits_at_is_word split_\<delta>) have "\<not> (?P (K - 1))" using KD Minimal(3) by auto with \<delta>1 have min_\<delta>: "\<not> (\<exists> a b. \<delta> = a@[X]@b \<and> derives a (terminals p))" by blast from Derives1_\<delta> split_\<delta> have "\<exists> u v. a = \<alpha> @ u \<and> b = v @ \<beta> \<and> (snd r) = u@[X]@v" proof (induction rule: Derives1_X_is_part_of_rule) case (Suffix \<gamma>) from min_\<delta> Suffix(1) a show ?case by auto next case (Prefix \<gamma>) have "derives \<gamma> (terminals p)" by (metis Derives1_implies_derives1 Prefix(2) a derives1_implies_derives derives_trans) with min_\<delta> Prefix(1) show ?case by auto qed then obtain u v where uXv: "a = \<alpha> @ u \<and> b = v @ \<beta> \<and> (snd r) = u@[X]@v" by blast let ?l = "length \<alpha>" let ?q = "take ?l p" let ?x = "Item r (length u) (charslength ?q) (charslength p)" have "item_rhs ?x = snd r" by (simp add: item_rhs_def) then have item_rhs_x: "item_rhs ?x = u@[X]@v" using uXv by simp have wellformed_x: "wellformed_item ?x" apply (auto simp add: wellformed_item_def) apply (metis Derives1_\<delta> Derives1_rule) apply (rule is_prefix_length) apply (rule is_prefix_chars) apply simp apply (simp add: doc_tokens_length[OF p]) using item_rhs_x by simp from item_rhs_x have next_symbol_x: "next_symbol ?x = Some X" by (auto simp add: next_symbol_def is_complete_def) have len_\<alpha>_p: "length \<alpha> \<le> length p" apply (rule_tac path_length_is_upper_bound[where u=u]) apply (simp add: wellformed_p) apply (simp add: is_word_\<alpha>) using a uXv by blast have item_nonterminal_x: "item_nonterminal ?x = N" apply (simp add: item_nonterminal_def) using Derives1_\<delta> Derives1_nonterminal split_\<delta> by blast have take_terminals: "take (length \<alpha>) (terminals p) = \<alpha>" apply (rule_tac take_prefix) using a derives_word_is_prefix is_word_\<alpha> uXv by blast (*does not seem to properly extract take length u*) have item_dot_x: "item_dot ?x = length u" by simp with item_rhs_x have "take (item_dot ?x) (item_rhs ?x) = u" by simp then have item_\<alpha>_x: "item_\<alpha> ?x = u" using item_\<alpha>_def by metis from wellformed_x next_symbol_x len_\<alpha>_p show ?thesis apply (rule_tac x="?x" in exI) apply (auto simp add: pvalid_def wellformed_p) apply (rule_tac x="length \<alpha>" in exI) apply (auto) using item_nonterminal_x apply (simp) apply (simp add: take_terminals) apply (rule_tac x="\<beta>" in exI) using LeftDerivation_implies_leftderives \<delta>1 is_leftderivation_def split_\<delta> splits_at_combine apply auto[1] using item_\<alpha>_x apply simp by (metis a derive_drop_prefixword is_word_\<alpha> uXv) qed qed lemma admissible_wellformed_tokens: "admissible p \<Longrightarrow> wellformed_tokens p" by (auto simp add: admissible_def \<L>\<^sub>P_wellformed_tokens) lemma chars_append[simp]: "chars (a@b) = (chars a)@(chars b)" by (induct a arbitrary: b, auto) lemma chars_of_token_simp[simp]: "chars_of_token (a, b) = b" by (simp add: chars_of_token_def) lemma is_prefix_append: "is_prefix (a@b) D = (is_prefix a D \<and> is_prefix b (drop (length a) D))" by (metis append_assoc is_prefix_cancel is_prefix_def is_prefix_unsplit) lemma \<PP>_are_doc_tokens: "p \<in> \<PP> \<Longrightarrow> doc_tokens p" proof (induct rule: \<PP>_induct) case Base thus ?case by (simp add: doc_tokens_def wellformed_tokens_def) next case (Induct p k u) from Induct(2)[simplified] show ?case proof (induct rule: limit_induct) case (Init p) from Induct(1)[OF Init] show ?case . next case (Iterate p Y) have Y_is_prefix: "\<And> p. p \<in> Y \<Longrightarrow> is_prefix (chars p) Doc" apply (drule Iterate(1)) by (simp add: doc_tokens_def) have "\<Y> (\<Z> k u) (\<P> k u) k \<subseteq> \<X> k" by (metis \<Z>.simps(2) \<Z>_subset_\<X>) then have 1: "Append (\<Y> (\<Z> k u) (\<P> k u) k) k Y \<subseteq> Append (\<X> k) k Y" by (rule Append_mono, simp) have 2: "p \<in> Append (\<X> k) k Y \<Longrightarrow> doc_tokens p" apply (auto simp add: Append_def) apply (simp add: Iterate) apply (auto simp add: doc_tokens_def admissible_wellformed_tokens is_prefix_append Y_is_prefix) by (metis \<X>_is_prefix snd_conv) show ?case apply (rule 2) by (metis (mono_tags, lifting) "1" Iterate(2) subsetCE) qed qed theorem thmD2: assumes X: "is_terminal X" assumes p: "p \<in> \<PP>" assumes pX: "(terminals p)@[X] \<in> \<L>\<^sub>P" shows "\<exists> x. pvalid p x \<and> next_symbol x = Some X" by (metis X \<PP>_are_doc_tokens p pX thmD2') end end
-- Copyright (c) 2018 Scott Morrison. All rights reserved. -- Released under Apache 2.0 license as described in the file LICENSE. -- Authors: Scott Morrison import category_theory.isomorphism universes v₁ v₂ v₃ u₁ u₂ u₃ -- declare the `v`'s first; see `category_theory.category` for an explanation namespace category_theory variables {C : Type u₁} [𝒞 : category.{v₁} C] {D : Type u₂} [𝒟 : category.{v₂} D] include 𝒞 𝒟 class full (F : C ⥤ D) := (preimage : ∀ {X Y : C} (f : (F.obj X) ⟶ (F.obj Y)), X ⟶ Y) (witness' : ∀ {X Y : C} (f : (F.obj X) ⟶ (F.obj Y)), F.map (preimage f) = f . obviously) restate_axiom full.witness' attribute [simp] full.witness class faithful (F : C ⥤ D) : Prop := (injectivity' : ∀ {X Y : C} {f g : X ⟶ Y} (p : F.map f = F.map g), f = g . obviously) restate_axiom faithful.injectivity' namespace functor def injectivity (F : C ⥤ D) [faithful F] {X Y : C} {f g : X ⟶ Y} (p : F.map f = F.map g) : f = g := faithful.injectivity F p def preimage (F : C ⥤ D) [full F] {X Y : C} (f : F.obj X ⟶ F.obj Y) : X ⟶ Y := full.preimage.{v₁ v₂} f @[simp] lemma image_preimage (F : C ⥤ D) [full F] {X Y : C} (f : F.obj X ⟶ F.obj Y) : F.map (preimage F f) = f := by unfold preimage; obviously end functor section variables {F : C ⥤ D} [full F] [faithful F] {X Y : C} def preimage_iso (f : (F.obj X) ≅ (F.obj Y)) : X ≅ Y := { hom := F.preimage f.hom, inv := F.preimage f.inv, hom_inv_id' := begin apply @faithful.injectivity _ _ _ _ F, obviously, end, inv_hom_id' := begin apply @faithful.injectivity _ _ _ _ F, obviously, end, } @[simp] lemma preimage_iso_hom (f : (F.obj X) ≅ (F.obj Y)) : (preimage_iso f).hom = F.preimage f.hom := rfl @[simp] lemma preimage_iso_inv (f : (F.obj X) ≅ (F.obj Y)) : (preimage_iso f).inv = F.preimage (f.inv) := rfl end class fully_faithful (F : C ⥤ D) extends (full F), (faithful F). @[simp] lemma preimage_id (F : C ⥤ D) [fully_faithful F] (X : C) : F.preimage (𝟙 (F.obj X)) = 𝟙 X := F.injectivity (by simp) end category_theory namespace category_theory variables {C : Type u₁} [𝒞 : category.{v₁} C] include 𝒞 instance full.id : full (functor.id C) := { preimage := λ _ _ f, f } instance : faithful (functor.id C) := by obviously instance : fully_faithful (functor.id C) := { ((by apply_instance) : full (functor.id C)) with } variables {D : Type u₂} [𝒟 : category.{v₂} D] {E : Type u₃} [ℰ : category.{v₃} E] include 𝒟 ℰ variables (F : C ⥤ D) (G : D ⥤ E) instance faithful.comp [faithful F] [faithful G] : faithful (F ⋙ G) := { injectivity' := λ _ _ _ _ p, F.injectivity (G.injectivity p) } instance full.comp [full F] [full G] : full (F ⋙ G) := { preimage := λ _ _ f, F.preimage (G.preimage f) } end category_theory
#pragma once #include "../ParserImpl.hpp" #include <boost/spirit/include/qi.hpp> #include "AxisString.hpp" namespace axis { namespace services { namespace language { namespace primitives { namespace impl { class BlankParserImpl : public axis::services::language::primitives::ParserImpl { public: BlankParserImpl(bool requiredSpace); ~BlankParserImpl(void); private: virtual axis::services::language::parsing::ParseResult DoParse( const axis::services::language::iterators::InputIterator& begin, const axis::services::language::iterators::InputIterator& end, bool trimSpaces = true) const; boost::spirit::qi::rule<axis::services::language::iterators::InputIterator, axis::String()> _blank_rule; const bool _requiredSpace; }; } } } } } // namespace axis::services::language::primitives::impl
{-# OPTIONS --cubical --safe #-} module Relation.Nullary.Discrete where open import Relation.Nullary.Discrete.Base public
function [P, resort] = sort_image_filenames(P) % :Usage: % :: % % [P, indices] = sort_image_filenames(P) % % Not all image name listing functions return imgs in the correct numbered % order! % % This function resorts a string matrix of image file names by image number, % in ascending order % At most, filename can have one number in it, or error is returned % % P can be a string matrix of a cell of string matrices % % .. % Tor Wager, April 2005 % .. % if iscell(P) % if cell, call this function recursively % for i = 1:length(P) % fprintf(1,'%3.0f',i); % P{i} = sort_image_filenames(P{i}); % end % fprintf(1,'\n') % return % end if size(P,1) == 1, return, end nums = []; for j = 1:size(P,1) if iscell(P) [dd,ff,ee]=fileparts(P{j, 1}); else % str matrix [dd,ff,ee]=fileparts(P(j,:)); end % find the last real number in the name tmp = nums_from_text(ff); tmp(tmp ~= real(tmp)) = []; nums(j) = tmp(end); end [n2,resort] = sort(nums); if any(n2-nums) fprintf(1,'Resorting.') P = P(resort,:); end end
Win A Free Holiday In Nevis – Really! Nevis Island Tourism News and Notes. © 2019 Nevis Island Tourism News and Notes. All rights reserved. Website Design by Toledo Computer Repair.
UC Davis affiliates are issued AggieCards to identify themselves as people associated with the university. UCDMC affiliates have a different card. AggieCards replaced the older style Reg card reg cards in Fall 2010 for students; they are optional for faculty, staff, visiting scholars, and retirees. In addition to identifying university affiliates, AggieCards can also be used as US Bank ATM/Debit cards if you open up a US Bank student checking account. Warning: US Bank conducts a hard credit pull if you open an account with them. This is the worst type of credit inquiry. This lowers your credit score and can damage your credit rating. So be careful about opening accounts with them. You can get an AggieCard in 161 Memorial Union, on the first floor across the hall from the MU Information Center between the hours of 10 A.M. to 4 P.M. There is a $15 charge to replace a lost AggieCard. A valid AggieCard can be used to: Check out books from Campus Library Libraries including: Shields Library Shields, Shields Library Reserves Reserves, Physical Sciences Library Physical Sciences and Engineering, Health Sciences Library Carlson Health Sciences and movies from Hart Hall. Ride Unitrans and Yolobus, if youre a registered undergraduate. Undergraduate student fees pay for unlimited bus riding on these services. Gain admission to the ARC if you are a registered student (your student fees pay for a membership) or you have purchased a membership. Get into your Residence halls dorm or the 24 Hour Reading Room. Buy stuff with money from your US Bank student checking account at any place with an wiki:wikipedia:Interlink_(interbank_network) Interlink terminal. This feature is only available if you open up a US Bank student checking account. The card can be used to get cash at an ATM or can be used to make PIN based purchases. It cannot be used for signature purchases like a credit card. Swipe in to the Dining Commons if you have a meal plan. Buy food at the Silo & Davis_Food_Coop Davis Food Coop with Aggie Cash. Identify yourself when using credit card at the Coffee House, Trudys, the Silo, the UC Davis Bookstore Bookstore, and more. Charge stuff to your student account at UC Davis Bookstore campus bookstores, provided you have a second form of photo ID, and are spending more than $5. Charge stuff at the Bike Barn such as repairs and merchandise as long as the purchase is over $5. Additionally, many places will give you a student discount on goods and services if you show them a student ID (like the AggieCard). Some Frat Parties also use AggieCards to keep nonstudents out. If you want to verify that an AggieCard belongs to a registered student, the Registrar has a https://registrar.ucdavis.edu/validation/index.cfm website. This is how the ASUCD Elections Committee verifies that signatures on petitions belong to currently registered students.
Require Import Coq.Logic.FunctionalExtensionality. Require Import Coq.Sets.Image. Definition edge X := X -> X -> Prop. Section bisim. Variables (X: Type) (A: edge X) (Y: Type) (B: edge Y). Definition is_bisimulation (r: X -> Y -> Prop) : Prop := (forall c1 c2 d2, (A c1 c2 /\ r c2 d2 -> exists d1, B d1 d2 /\ r c1 d1)) /\ (forall d1 d2 c2, (B d1 d2 /\ r c2 d2 -> exists c1, A c1 c2 /\ r c1 d1)). End bisim. Lemma bisim_id: forall X A, is_bisimulation X A X A eq. intros X A. unfold is_bisimulation. split. intros c1 c2 d2 [H H0]. exists c1; rewrite H0 in H; auto. intros d1 d2 c2 [H H0]. exists d1. rewrite <- H0 in H; auto. Qed. Definition rel_comp {X Y Z} (r1: X -> Y -> Prop) (r2: Y -> Z -> Prop) := fun x z => exists y, r1 x y /\ r2 y z. Definition rel_inv {X Y} (r: X -> Y -> Prop): Y -> X -> Prop := fun y x => r x y. Lemma bisim_comp: forall X A Y B Z C, forall r1 r2, is_bisimulation X A Y B r1 -> is_bisimulation Y B Z C r2 -> is_bisimulation X A Z C (rel_comp r1 r2). Admitted. Lemma bisim_inv: forall X A Y B, forall r, is_bisimulation X A Y B r -> is_bisimulation Y B X A (rel_inv r). Admitted. Section set_relation. Variables (X: Type) (A: edge X) (a: X) (Y: Type) (B: edge Y) (b: Y). Definition set_equal: Prop := exists r, is_bisimulation X A Y B r /\ r a b. End set_relation. Definition set_member (X: Type) (A: edge X) (a: X) (Y: Type) (B: edge Y) (b: Y): Prop := exists z, set_equal X A a Y B z /\ B z b. Definition set_subset (X: Type) (A: edge X) (a: X) (Y: Type) (B: edge Y) (b: Y): Prop := forall Z C c, set_member Z C c X A a -> set_member Z C c Y B b. Definition sum X Y := (X -> Prop) -> (Y -> Prop) -> Prop. Definition inl {X Y} (a: X): sum X Y := fun p _ => p a. Definition inr {X Y} (b: Y): sum X Y := fun _ q => q b. Definition out {X Y} : sum X Y := fun _ _ => False. Definition opt X := (X -> Prop) -> Prop. Definition some {X} x: opt X := fun f => f x. Definition none {X}: opt X := fun _ => False. Definition cnat := forall X, (X -> X) -> X -> X. Definition zero: cnat := fun f x => x. Definition succ (n: cnat): cnat := fun X f x => f (n X f x). Definition cle (n: cnat) (m: cnat) := forall P: cnat -> Prop, P n -> (forall z, P z -> P (succ z)) -> P m. Definition clt n m := cle (succ n) m. Definition wf_nat n := cle zero n. Proposition inl_inr_disj: forall X Y (x: X) (y: Y), inl (Y := Y) x <> inr y. intros X Y x y H. specialize (equal_f (A := X -> Prop) (B := (Y -> Prop) -> Prop) H (fun _ => False)). intro H0. specialize (equal_f H0 (fun _ => True)). unfold inl, inr. intro H1. rewrite H1. exact I. Qed. Proposition inl_out_disj: forall X Y (x: X), inl (Y := Y) x <> out. intros X Y x H. specialize (equal_f (A := X -> Prop) (B := (Y -> Prop) -> Prop) H (fun _ => True)). intro H0. specialize (equal_f H0 (fun _ => True)). unfold inl, out. intro H1. rewrite <- H1. exact I. Qed. Proposition inr_out_disj: forall X Y (y: Y), inr (X := X) y <> out. intros X Y y H. specialize (equal_f (A := X -> Prop) (B := (Y -> Prop) -> Prop) H (fun _ => True)). intro H0. specialize (equal_f H0 (fun _ => True)). unfold inr, out. intro H1. rewrite <- H1. exact I. Qed. Proposition inl_inj: forall X Y, injective _ _(inl (X := X) (Y := Y)). intros X Y x1 x2 H. specialize (equal_f H (fun z => z = x1)). intro H0. specialize (equal_f H0 (fun _ => True)). unfold inl. intro. symmetry. rewrite <- H1. auto. Qed. Proposition inr_inj: forall X Y, injective _ _ (inr (X := X) (Y := Y)). intros X Y y1 y2 H. specialize (equal_f H (fun _ => True)). intro H0. specialize (equal_f H0 (fun z => z = y2)). unfold inr. intro. rewrite H1. auto. Qed. Goal forall n, cle n n. intros n P H H0. auto. Qed. Goal forall l m n, cle l m -> cle m n -> cle l n. intros l m n H H0 P H1 H2. apply H0. apply H. apply H1. apply H2. apply H2. Qed. (* empty *) Definition empty_c := forall X, (X -> X) -> X -> X. Definition empty_e: edge empty_c := fun _ _ => False. Definition empty_b: empty_c := fun _ x => x. Theorem axiom_empty: forall X A a, ~ set_member X A a empty_c empty_e empty_b. intros X A a H. destruct H as [x [H H0]]. auto. Qed. (* pair *) Section pair. Variables (X: Type) (A: edge X) (a: X) (Y: Type) (B: edge Y) (b: Y). Definition pair_c := sum X Y. Definition pair_e: edge (sum X Y) := fun c1 c2 => (exists a1 a2, c1 = inl a1 /\ c2 = inl a2 /\ A a1 a2) \/ (exists b1 b2, c1 = inr b1 /\ c2 = inr b2 /\ B b1 b2) \/ (c1 = inl a /\ c2 = out) \/ (c1 = inr b /\ c2 = out). Definition pair_b: pair_c := out. End pair. Lemma inl_pair_set_equal: forall Z C c X A a Y B b, set_equal Z C c (pair_c X Y) (pair_e X A a Y B b) (inl a) <-> set_equal Z C c X A a. split; intro H. destruct H as [r [H H0]]. exists (fun z x => r z (inl x)). split; auto; clear H0 c. destruct H as [H H0]. split. clear H0. intros c1 c2 d2. intros H1; destruct H1 as [H1 H2]. specialize (H c1 c2 (inl d2)). destruct H as [d1 H3]. tauto. destruct H3 as [H H3]. assert (exists x1, d1 = inl x1 /\ A x1 d2). destruct H as [H|[H|[H|H]]]. destruct H as [a1 [a2 [H [H5 H6]]]]. exists a1. apply inl_inj in H5. rewrite <- H5 in H6. tauto. destruct H as [_ [b2 [_ [H _]]]]. apply False_ind; apply (inl_inr_disj _ _ d2 b2); auto. apply False_ind; apply (inl_out_disj _ Y d2); tauto. apply False_ind; apply (inl_out_disj _ Y d2); tauto. destruct H0 as [x1 [H0 H4]]. exists x1. rewrite <- H0. tauto. clear H. intros d1 d0 c0 H1. destruct H1 as [H1 H2]. admit. (* if part *) Admitted. Lemma inr_pair_set_equal: forall Z C c X A a Y B b, set_equal Z C c (pair_c X Y) (pair_e X A a Y B b) (inr b) <-> set_equal Z C c Y B b. Admitted. Theorem pair_axiom: forall X A a Y B b Z C c, set_member Z C c (pair_c X Y) (pair_e X A a Y B b) (pair_b X Y) <-> set_equal Z C c X A a \/ set_equal Z C c Y B b. split. (* z in {x, y} -> z = x \/ z = y *) intros H. destruct H as [sb [H H0]]. unfold pair_b in H0. case H0 as [H0| [H0| [H0| H0]]]. (* case 1 *) destruct H0 as [a1 [a2 H0]]. absurd (inl (Y := Y) a2 = out). apply (inl_out_disj X Y a2). symmetry. tauto. (* case 2 *) destruct H0 as [b1 [b2 H0]]. absurd (inr (X := X) b2 = out). apply (inr_out_disj X Y b2). symmetry. tauto. (* case 3 *) destruct H0 as [H0 _]. left. rewrite H0 in H. apply inl_pair_set_equal in H. auto. (* case 4 *) destruct H0 as [H0 _]. right. rewrite H0 in H. apply inr_pair_set_equal in H. auto. (* if part *) intros H. destruct H as [H | H]. (* z = x *) unfold set_member. exists (inl a). split. apply inl_pair_set_equal; auto. unfold pair_e. tauto. (* z = y *) unfold set_member. exists (inr b). split. apply inr_pair_set_equal; auto. unfold pair_e. tauto. Qed. Section pow. Variable X: Type. Variables (A: edge X) (a: X). Definition pow_c := sum X (X -> Prop). Definition pow_e (b1 b2: pow_c): Prop := (exists a1 a2, b1 = inl a1 /\ b2 = inl a2 /\ A a1 a2) \/ (exists a1 p, b1 = inl a1 /\ b2 = inr p /\ A a1 a /\ p a1) \/ (exists p, b1 = inr p /\ b2 = out). Definition pow_b: pow_c := out. End pow. Theorem power_axiom: forall X A a Y B b, set_member X A a (pow_c Y) (pow_e Y B b) (pow_b Y) <-> set_subset X A a Y B b. split. (* x in pow y -> x subset y *) intro H. unfold set_subset. intros Z C c H0. destruct H as [s [H H1]]. destruct H1 as [H1| [H1| H1]]. (* case 1 *) destruct H1 as [a1 [a2 [H1 [H2 H3]]]]. unfold pow_b in H2. absurd (inl a2 = out (Y := Y -> Prop)). apply inl_out_disj. symmetry; auto. (* case 2 *) destruct H1 as [a1 [p [H1 [H2 [H3 H4]]]]]. symmetry in H2. apply inr_out_disj in H2; case H2. (* case 3 *) destruct H1 as [p [H1 _]]. destruct H0 as [u [H0 H2]]. destruct H as [rp [H H3]]. destruct H0 as [r [H0 H4]]. exists b. admit. (* x subset y -> x in pow y *) admit. Admitted. Definition U := (forall X: Type, (X -> X -> Prop) -> X -> Prop) -> Prop. Definition i: forall X: Type, (X -> X -> Prop) -> X -> U. intros X A a f. exact (f X A a). Defined. Definition set (u: U): Prop := exists X A a, u = i X A a. Definition ueq (u1 u2: U): Prop := exists X A a Y B b, u1 = i X A a /\ u2 = i Y B b /\ set_equal X A a Y B b. Definition elt (u1 u2: U): Prop := exists X A a Y B b, u1 = i X A a /\ u2 = i Y B b /\ set_member X A a Y B b.
(* Title: The Graceful Recursive Path Order for Lambda-Free Higher-Order Terms Author: Jasmin Blanchette <jasmin.blanchette at inria.fr>, 2016 Author: Uwe Waldmann <waldmann at mpi-inf.mpg.de>, 2016 Author: Daniel Wand <dwand at mpi-inf.mpg.de>, 2016 Maintainer: Jasmin Blanchette <jasmin.blanchette at inria.fr> *) section \<open>The Graceful Recursive Path Order for Lambda-Free Higher-Order Terms\<close> theory Lambda_Free_RPO_Std imports Lambda_Free_Term Extension_Orders Nested_Multisets_Ordinals.Multiset_More abbrevs ">t" = ">\<^sub>t" and "\<ge>t" = "\<ge>\<^sub>t" begin text \<open> This theory defines the graceful recursive path order (RPO) for \<open>\<lambda>\<close>-free higher-order terms. \<close> subsection \<open>Setup\<close> locale rpo_basis = ground_heads "(>\<^sub>s)" arity_sym arity_var for gt_sym :: "'s \<Rightarrow> 's \<Rightarrow> bool" (infix ">\<^sub>s" 50) and arity_sym :: "'s \<Rightarrow> enat" and arity_var :: "'v \<Rightarrow> enat" + fixes extf :: "'s \<Rightarrow> (('s, 'v) tm \<Rightarrow> ('s, 'v) tm \<Rightarrow> bool) \<Rightarrow> ('s, 'v) tm list \<Rightarrow> ('s, 'v) tm list \<Rightarrow> bool" assumes extf_ext_trans_before_irrefl: "ext_trans_before_irrefl (extf f)" and extf_ext_compat_cons: "ext_compat_cons (extf f)" and extf_ext_compat_list: "ext_compat_list (extf f)" begin lemma extf_ext_trans: "ext_trans (extf f)" by (rule ext_trans_before_irrefl.axioms(1)[OF extf_ext_trans_before_irrefl]) lemma extf_ext: "ext (extf f)" by (rule ext_trans.axioms(1)[OF extf_ext_trans]) lemmas extf_mono_strong = ext.mono_strong[OF extf_ext] lemmas extf_mono = ext.mono[OF extf_ext, mono] lemmas extf_map = ext.map[OF extf_ext] lemmas extf_trans = ext_trans.trans[OF extf_ext_trans] lemmas extf_irrefl_from_trans = ext_trans_before_irrefl.irrefl_from_trans[OF extf_ext_trans_before_irrefl] lemmas extf_compat_append_left = ext_compat_cons.compat_append_left[OF extf_ext_compat_cons] lemmas extf_compat_list = ext_compat_list.compat_list[OF extf_ext_compat_list] definition chkvar :: "('s, 'v) tm \<Rightarrow> ('s, 'v) tm \<Rightarrow> bool" where [simp]: "chkvar t s \<longleftrightarrow> vars_hd (head s) \<subseteq> vars t" end locale rpo = rpo_basis _ _ arity_sym arity_var for arity_sym :: "'s \<Rightarrow> enat" and arity_var :: "'v \<Rightarrow> enat" begin subsection \<open>Inductive Definitions\<close> definition chksubs :: "(('s, 'v) tm \<Rightarrow> ('s, 'v) tm \<Rightarrow> bool) \<Rightarrow> ('s, 'v) tm \<Rightarrow> ('s, 'v) tm \<Rightarrow> bool" where [simp]: "chksubs gt t s \<longleftrightarrow> (case s of App s1 s2 \<Rightarrow> gt t s1 \<and> gt t s2 | _ \<Rightarrow> True)" lemma chksubs_mono[mono]: "gt \<le> gt' \<Longrightarrow> chksubs gt \<le> chksubs gt'" by (auto simp: tm.case_eq_if) force+ inductive gt :: "('s, 'v) tm \<Rightarrow> ('s, 'v) tm \<Rightarrow> bool" (infix ">\<^sub>t" 50) where gt_sub: "is_App t \<Longrightarrow> (fun t >\<^sub>t s \<or> fun t = s) \<or> (arg t >\<^sub>t s \<or> arg t = s) \<Longrightarrow> t >\<^sub>t s" | gt_diff: "head t >\<^sub>h\<^sub>d head s \<Longrightarrow> chkvar t s \<Longrightarrow> chksubs (>\<^sub>t) t s \<Longrightarrow> t >\<^sub>t s" | gt_same: "head t = head s \<Longrightarrow> chksubs (>\<^sub>t) t s \<Longrightarrow> (\<forall>f \<in> ground_heads (head t). extf f (>\<^sub>t) (args t) (args s)) \<Longrightarrow> t >\<^sub>t s" abbreviation ge :: "('s, 'v) tm \<Rightarrow> ('s, 'v) tm \<Rightarrow> bool" (infix "\<ge>\<^sub>t" 50) where "t \<ge>\<^sub>t s \<equiv> t >\<^sub>t s \<or> t = s" inductive gt_sub :: "('s, 'v) tm \<Rightarrow> ('s, 'v) tm \<Rightarrow> bool" where gt_subI: "is_App t \<Longrightarrow> fun t \<ge>\<^sub>t s \<or> arg t \<ge>\<^sub>t s \<Longrightarrow> gt_sub t s" inductive gt_diff :: "('s, 'v) tm \<Rightarrow> ('s, 'v) tm \<Rightarrow> bool" where gt_diffI: "head t >\<^sub>h\<^sub>d head s \<Longrightarrow> chkvar t s \<Longrightarrow> chksubs (>\<^sub>t) t s \<Longrightarrow> gt_diff t s" inductive gt_same :: "('s, 'v) tm \<Rightarrow> ('s, 'v) tm \<Rightarrow> bool" where gt_sameI: "head t = head s \<Longrightarrow> chksubs (>\<^sub>t) t s \<Longrightarrow> (\<forall>f \<in> ground_heads (head t). extf f (>\<^sub>t) (args t) (args s)) \<Longrightarrow> gt_same t s" lemma gt_iff_sub_diff_same: "t >\<^sub>t s \<longleftrightarrow> gt_sub t s \<or> gt_diff t s \<or> gt_same t s" by (subst gt.simps) (auto simp: gt_sub.simps gt_diff.simps gt_same.simps) subsection \<open>Transitivity\<close> lemma gt_fun_imp: "fun t >\<^sub>t s \<Longrightarrow> t >\<^sub>t s" by (cases t) (auto intro: gt_sub) lemma gt_arg_imp: "arg t >\<^sub>t s \<Longrightarrow> t >\<^sub>t s" by (cases t) (auto intro: gt_sub) lemma gt_imp_vars: "t >\<^sub>t s \<Longrightarrow> vars t \<supseteq> vars s" proof (simp only: atomize_imp, rule measure_induct_rule[of "\<lambda>(t, s). size t + size s" "\<lambda>(t, s). t >\<^sub>t s \<longrightarrow> vars t \<supseteq> vars s" "(t, s)", simplified prod.case], simp only: split_paired_all prod.case atomize_imp[symmetric]) fix t s assume ih: "\<And>ta sa. size ta + size sa < size t + size s \<Longrightarrow> ta >\<^sub>t sa \<Longrightarrow> vars ta \<supseteq> vars sa" and t_gt_s: "t >\<^sub>t s" show "vars t \<supseteq> vars s" using t_gt_s proof cases case gt_sub thus ?thesis using ih[of "fun t" s] ih[of "arg t" s] by (meson add_less_cancel_right subsetD size_arg_lt size_fun_lt subsetI tm.set_sel(5,6)) next case gt_diff show ?thesis proof (cases s) case Hd thus ?thesis using gt_diff(2) by (auto elim: hd.set_cases(2)) next case (App s1 s2) thus ?thesis using gt_diff(3) ih[of t s1] ih[of t s2] by simp qed next case gt_same show ?thesis proof (cases s) case Hd thus ?thesis using gt_same(1) vars_head_subseteq by fastforce next case (App s1 s2) thus ?thesis using gt_same(2) ih[of t s1] ih[of t s2] by simp qed qed qed theorem gt_trans: "u >\<^sub>t t \<Longrightarrow> t >\<^sub>t s \<Longrightarrow> u >\<^sub>t s" proof (simp only: atomize_imp, rule measure_induct_rule[of "\<lambda>(u, t, s). {#size u, size t, size s#}" "\<lambda>(u, t, s). u >\<^sub>t t \<longrightarrow> t >\<^sub>t s \<longrightarrow> u >\<^sub>t s" "(u, t, s)", simplified prod.case], simp only: split_paired_all prod.case atomize_imp[symmetric]) fix u t s assume ih: "\<And>ua ta sa. {#size ua, size ta, size sa#} < {#size u, size t, size s#} \<Longrightarrow> ua >\<^sub>t ta \<Longrightarrow> ta >\<^sub>t sa \<Longrightarrow> ua >\<^sub>t sa" and u_gt_t: "u >\<^sub>t t" and t_gt_s: "t >\<^sub>t s" have chkvar: "chkvar u s" by clarsimp (meson u_gt_t t_gt_s gt_imp_vars hd.set_sel(2) vars_head_subseteq subsetCE) have chk_u_s_if: "chksubs (>\<^sub>t) u s" if chk_t_s: "chksubs (>\<^sub>t) t s" proof (cases s) case (App s1 s2) thus ?thesis using chk_t_s by (auto intro: ih[of _ _ s1, OF _ u_gt_t] ih[of _ _ s2, OF _ u_gt_t]) qed auto have fun_u_lt_etc: "is_App u \<Longrightarrow> {#size (fun u), size t, size s#} < {#size u, size t, size s#}" and arg_u_lt_etc: "is_App u \<Longrightarrow> {#size (arg u), size t, size s#} < {#size u, size t, size s#}" by (simp_all add: size_fun_lt size_arg_lt) have u_gt_s_if_ui: "is_App u \<Longrightarrow> fun u \<ge>\<^sub>t t \<or> arg u \<ge>\<^sub>t t \<Longrightarrow> u >\<^sub>t s" using ih[of "fun u" t s, OF fun_u_lt_etc] ih[of "arg u" t s, OF arg_u_lt_etc] gt_arg_imp gt_fun_imp t_gt_s by blast show "u >\<^sub>t s" using t_gt_s proof cases case gt_sub_t_s: gt_sub have u_gt_s_if_chk_u_t: ?thesis if chk_u_t: "chksubs (>\<^sub>t) u t" using gt_sub_t_s(1) proof (cases t) case t: (App t1 t2) show ?thesis using ih[of u t1 s] ih[of u t2 s] gt_sub_t_s(2) chk_u_t unfolding t by auto qed auto show ?thesis using u_gt_t by cases (auto intro: u_gt_s_if_ui u_gt_s_if_chk_u_t) next case gt_diff_t_s: gt_diff show ?thesis using u_gt_t proof cases case gt_diff_u_t: gt_diff have "head u >\<^sub>h\<^sub>d head s" using gt_diff_u_t(1) gt_diff_t_s(1) by (auto intro: gt_hd_trans) thus ?thesis by (rule gt_diff[OF _ chkvar chk_u_s_if[OF gt_diff_t_s(3)]]) next case gt_same_u_t: gt_same have "head u >\<^sub>h\<^sub>d head s" using gt_diff_t_s(1) gt_same_u_t(1) by auto thus ?thesis by (rule gt_diff[OF _ chkvar chk_u_s_if[OF gt_diff_t_s(3)]]) qed (auto intro: u_gt_s_if_ui) next case gt_same_t_s: gt_same show ?thesis using u_gt_t proof cases case gt_diff_u_t: gt_diff have "head u >\<^sub>h\<^sub>d head s" using gt_diff_u_t(1) gt_same_t_s(1) by simp thus ?thesis by (rule gt_diff[OF _ chkvar chk_u_s_if[OF gt_same_t_s(2)]]) next case gt_same_u_t: gt_same have hd_u_s: "head u = head s" using gt_same_u_t(1) gt_same_t_s(1) by simp let ?S = "set (args u) \<union> set (args t) \<union> set (args s)" have gt_trans_args: "\<forall>ua \<in> ?S. \<forall>ta \<in> ?S. \<forall>sa \<in> ?S. ua >\<^sub>t ta \<longrightarrow> ta >\<^sub>t sa \<longrightarrow> ua >\<^sub>t sa" proof clarify fix sa ta ua assume ua_in: "ua \<in> ?S" and ta_in: "ta \<in> ?S" and sa_in: "sa \<in> ?S" and ua_gt_ta: "ua >\<^sub>t ta" and ta_gt_sa: "ta >\<^sub>t sa" show "ua >\<^sub>t sa" by (auto intro!: ih[OF Max_lt_imp_lt_mset ua_gt_ta ta_gt_sa]) (meson ua_in ta_in sa_in Un_iff max.strict_coboundedI1 max.strict_coboundedI2 size_in_args)+ qed have "\<forall>f \<in> ground_heads (head u). extf f (>\<^sub>t) (args u) (args s)" proof (clarify, rule extf_trans[OF _ _ _ gt_trans_args]) fix f assume f_in_grounds: "f \<in> ground_heads (head u)" show "extf f (>\<^sub>t) (args u) (args t)" using f_in_grounds gt_same_u_t(3) by blast show "extf f (>\<^sub>t) (args t) (args s)" using f_in_grounds gt_same_t_s(3) unfolding gt_same_u_t(1) by blast qed auto thus ?thesis by (rule gt_same[OF hd_u_s chk_u_s_if[OF gt_same_t_s(2)]]) qed (auto intro: u_gt_s_if_ui) qed qed subsection \<open>Irreflexivity\<close> theorem gt_irrefl: "\<not> s >\<^sub>t s" proof (standard, induct s rule: measure_induct_rule[of size]) case (less s) note ih = this(1) and s_gt_s = this(2) show False using s_gt_s proof cases case _: gt_sub note is_app = this(1) and si_ge_s = this(2) have s_gt_fun_s: "s >\<^sub>t fun s" and s_gt_arg_s: "s >\<^sub>t arg s" using is_app by (simp_all add: gt_sub) have "fun s >\<^sub>t s \<or> arg s >\<^sub>t s" using si_ge_s is_app s_gt_arg_s s_gt_fun_s by auto moreover { assume fun_s_gt_s: "fun s >\<^sub>t s" have "fun s >\<^sub>t fun s" by (rule gt_trans[OF fun_s_gt_s s_gt_fun_s]) hence False using ih[of "fun s"] is_app size_fun_lt by blast } moreover { assume arg_s_gt_s: "arg s >\<^sub>t s" have "arg s >\<^sub>t arg s" by (rule gt_trans[OF arg_s_gt_s s_gt_arg_s]) hence False using ih[of "arg s"] is_app size_arg_lt by blast } ultimately show False by sat next case gt_diff thus False by (cases "head s") (auto simp: gt_hd_irrefl) next case gt_same note in_grounds = this(3) obtain si where si_in_args: "si \<in> set (args s)" and si_gt_si: "si >\<^sub>t si" using in_grounds by (metis (full_types) all_not_in_conv extf_irrefl_from_trans ground_heads_nonempty gt_trans) have "size si < size s" by (rule size_in_args[OF si_in_args]) thus False by (rule ih[OF _ si_gt_si]) qed qed lemma gt_antisym: "t >\<^sub>t s \<Longrightarrow> \<not> s >\<^sub>t t" using gt_irrefl gt_trans by blast subsection \<open>Subterm Property\<close> lemma gt_sub_fun: "App s t >\<^sub>t s" and gt_sub_arg: "App s t >\<^sub>t t" by (auto intro: gt_sub) theorem gt_proper_sub: "proper_sub s t \<Longrightarrow> t >\<^sub>t s" by (induct t) (auto intro: gt_sub_fun gt_sub_arg gt_trans) subsection \<open>Compatibility with Functions\<close> lemma gt_compat_fun: assumes t'_gt_t: "t' >\<^sub>t t" shows "App s t' >\<^sub>t App s t" proof - have t'_ne_t: "t' \<noteq> t" using gt_antisym t'_gt_t by blast have extf_args_single: "\<forall>f \<in> ground_heads (head s). extf f (>\<^sub>t) (args s @ [t']) (args s @ [t])" by (simp add: extf_compat_list t'_gt_t t'_ne_t) show ?thesis by (rule gt_same) (auto simp: gt_sub gt_sub_fun t'_gt_t intro!: extf_args_single) qed theorem gt_compat_fun_strong: assumes t'_gt_t: "t' >\<^sub>t t" shows "apps s (t' # us) >\<^sub>t apps s (t # us)" proof (induct us rule: rev_induct) case Nil show ?case using t'_gt_t by (auto intro!: gt_compat_fun) next case (snoc u us) note ih = snoc let ?v' = "apps s (t' # us @ [u])" let ?v = "apps s (t # us @ [u])" show ?case proof (rule gt_same) show "chksubs (>\<^sub>t) ?v' ?v" using ih by (auto intro: gt_sub gt_sub_arg) next show "\<forall>f \<in> ground_heads (head ?v'). extf f (>\<^sub>t) (args ?v') (args ?v)" by (metis args_apps extf_compat_list gt_irrefl t'_gt_t) qed simp qed subsection \<open>Compatibility with Arguments\<close> theorem gt_diff_same_compat_arg: assumes extf_compat_snoc: "\<And>f. ext_compat_snoc (extf f)" and diff_same: "gt_diff s' s \<or> gt_same s' s" shows "App s' t >\<^sub>t App s t" proof - { assume "s' >\<^sub>t s" hence "App s' t >\<^sub>t s" using gt_sub_fun gt_trans by blast moreover have "App s' t >\<^sub>t t" by (simp add: gt_sub_arg) ultimately have "chksubs (>\<^sub>t) (App s' t) (App s t)" by auto } note chk_s't_st = this show ?thesis using diff_same proof assume "gt_diff s' s" hence s'_gt_s: "s' >\<^sub>t s" and hd_s'_gt_s: "head s' >\<^sub>h\<^sub>d head s" and chkvar_s'_s: "chkvar s' s" and chk_s'_s: "chksubs (>\<^sub>t) s' s" using gt_diff.cases by (auto simp: gt_iff_sub_diff_same) have chkvar_s't_st: "chkvar (App s' t) (App s t)" using chkvar_s'_s by auto show ?thesis by (rule gt_diff[OF _ chkvar_s't_st chk_s't_st[OF s'_gt_s]]) (simp add: hd_s'_gt_s[simplified]) next assume "gt_same s' s" hence s'_gt_s: "s' >\<^sub>t s" and hd_s'_eq_s: "head s' = head s" and chk_s'_s: "chksubs (>\<^sub>t) s' s" and gts_args: "\<forall>f \<in> ground_heads (head s'). extf f (>\<^sub>t) (args s') (args s)" using gt_same.cases by (auto simp: gt_iff_sub_diff_same, metis) have gts_args_t: "\<forall>f \<in> ground_heads (head (App s' t)). extf f (>\<^sub>t) (args (App s' t)) (args (App s t))" using gts_args ext_compat_snoc.compat_append_right[OF extf_compat_snoc] by simp show ?thesis by (rule gt_same[OF _ chk_s't_st[OF s'_gt_s] gts_args_t]) (simp add: hd_s'_eq_s) qed qed subsection \<open>Stability under Substitution\<close> lemma gt_imp_chksubs_gt: assumes t_gt_s: "t >\<^sub>t s" shows "chksubs (>\<^sub>t) t s" proof - have "is_App s \<Longrightarrow> t >\<^sub>t fun s \<and> t >\<^sub>t arg s" using t_gt_s by (meson gt_sub gt_trans) thus ?thesis by (simp add: tm.case_eq_if) qed theorem gt_subst: assumes wary_\<rho>: "wary_subst \<rho>" shows "t >\<^sub>t s \<Longrightarrow> subst \<rho> t >\<^sub>t subst \<rho> s" proof (simp only: atomize_imp, rule measure_induct_rule[of "\<lambda>(t, s). {#size t, size s#}" "\<lambda>(t, s). t >\<^sub>t s \<longrightarrow> subst \<rho> t >\<^sub>t subst \<rho> s" "(t, s)", simplified prod.case], simp only: split_paired_all prod.case atomize_imp[symmetric]) fix t s assume ih: "\<And>ta sa. {#size ta, size sa#} < {#size t, size s#} \<Longrightarrow> ta >\<^sub>t sa \<Longrightarrow> subst \<rho> ta >\<^sub>t subst \<rho> sa" and t_gt_s: "t >\<^sub>t s" { assume chk_t_s: "chksubs (>\<^sub>t) t s" have "chksubs (>\<^sub>t) (subst \<rho> t) (subst \<rho> s)" proof (cases s) case s: (Hd \<zeta>) show ?thesis proof (cases \<zeta>) case \<zeta>: (Var x) have psub_x_t: "proper_sub (Hd (Var x)) t" using \<zeta> s t_gt_s gt_imp_vars gt_irrefl in_vars_imp_sub by fastforce show ?thesis unfolding \<zeta> s by (rule gt_imp_chksubs_gt[OF gt_proper_sub[OF proper_sub_subst]]) (rule psub_x_t) qed (auto simp: s) next case s: (App s1 s2) have "t >\<^sub>t s1" and "t >\<^sub>t s2" using s chk_t_s by auto thus ?thesis using s by (auto intro!: ih[of t s1] ih[of t s2]) qed } note chk_\<rho>t_\<rho>s_if = this show "subst \<rho> t >\<^sub>t subst \<rho> s" using t_gt_s proof cases case gt_sub_t_s: gt_sub obtain t1 t2 where t: "t = App t1 t2" using gt_sub_t_s(1) by (metis tm.collapse(2)) show ?thesis using gt_sub ih[of t1 s] ih[of t2 s] gt_sub_t_s(2) t by auto next case gt_diff_t_s: gt_diff have "head (subst \<rho> t) >\<^sub>h\<^sub>d head (subst \<rho> s)" by (meson wary_subst_ground_heads gt_diff_t_s(1) gt_hd_def subsetCE wary_\<rho>) moreover have "chkvar (subst \<rho> t) (subst \<rho> s)" unfolding chkvar_def using vars_subst_subseteq[OF gt_imp_vars[OF t_gt_s]] vars_head_subseteq by force ultimately show ?thesis by (rule gt_diff[OF _ _ chk_\<rho>t_\<rho>s_if[OF gt_diff_t_s(3)]]) next case gt_same_t_s: gt_same have hd_\<rho>t_eq_\<rho>s: "head (subst \<rho> t) = head (subst \<rho> s)" using gt_same_t_s(1) by simp { fix f assume f_in_grounds: "f \<in> ground_heads (head (subst \<rho> t))" let ?S = "set (args t) \<union> set (args s)" have extf_args_s_t: "extf f (>\<^sub>t) (args t) (args s)" using gt_same_t_s(3) f_in_grounds wary_\<rho> wary_subst_ground_heads by blast have "extf f (>\<^sub>t) (map (subst \<rho>) (args t)) (map (subst \<rho>) (args s))" proof (rule extf_map[of ?S, OF _ _ _ _ _ _ extf_args_s_t]) have sz_a: "\<forall>ta \<in> ?S. \<forall>sa \<in> ?S. {#size ta, size sa#} < {#size t, size s#}" by (fastforce intro: Max_lt_imp_lt_mset dest: size_in_args) show "\<forall>ta \<in> ?S. \<forall>sa \<in> ?S. ta >\<^sub>t sa \<longrightarrow> subst \<rho> ta >\<^sub>t subst \<rho> sa" using ih sz_a size_in_args by fastforce qed (auto intro!: gt_irrefl elim!: gt_trans) hence "extf f (>\<^sub>t) (args (subst \<rho> t)) (args (subst \<rho> s))" by (auto simp: gt_same_t_s(1) intro: extf_compat_append_left) } hence "\<forall>f \<in> ground_heads (head (subst \<rho> t)). extf f (>\<^sub>t) (args (subst \<rho> t)) (args (subst \<rho> s))" by blast thus ?thesis by (rule gt_same[OF hd_\<rho>t_eq_\<rho>s chk_\<rho>t_\<rho>s_if[OF gt_same_t_s(2)]]) qed qed subsection \<open>Totality on Ground Terms\<close> theorem gt_total_ground: assumes extf_total: "\<And>f. ext_total (extf f)" shows "ground t \<Longrightarrow> ground s \<Longrightarrow> t >\<^sub>t s \<or> s >\<^sub>t t \<or> t = s" proof (simp only: atomize_imp, rule measure_induct_rule[of "\<lambda>(t, s). {# size t, size s #}" "\<lambda>(t, s). ground t \<longrightarrow> ground s \<longrightarrow> t >\<^sub>t s \<or> s >\<^sub>t t \<or> t = s" "(t, s)", simplified prod.case], simp only: split_paired_all prod.case atomize_imp[symmetric]) fix t s :: "('s, 'v) tm" assume ih: "\<And>ta sa. {# size ta, size sa #} < {# size t, size s #} \<Longrightarrow> ground ta \<Longrightarrow> ground sa \<Longrightarrow> ta >\<^sub>t sa \<or> sa >\<^sub>t ta \<or> ta = sa" and gr_t: "ground t" and gr_s: "ground s" let ?case = "t >\<^sub>t s \<or> s >\<^sub>t t \<or> t = s" have "chksubs (>\<^sub>t) t s \<or> s >\<^sub>t t" unfolding chksubs_def tm.case_eq_if using ih[of t "fun s"] ih[of t "arg s"] mset_lt_single_iff by (metis add_mset_lt_right_lt gr_s gr_t ground_arg ground_fun gt_sub size_arg_lt size_fun_lt) moreover have "chksubs (>\<^sub>t) s t \<or> t >\<^sub>t s" unfolding chksubs_def tm.case_eq_if using ih[of "fun t" s] ih[of "arg t" s] by (metis add_mset_lt_left_lt gr_s gr_t ground_arg ground_fun gt_sub size_arg_lt size_fun_lt) moreover { assume chksubs_t_s: "chksubs (>\<^sub>t) t s" and chksubs_s_t: "chksubs (>\<^sub>t) s t" obtain g where g: "head t = Sym g" using gr_t by (metis ground_head hd.collapse(2)) obtain f where f: "head s = Sym f" using gr_s by (metis ground_head hd.collapse(2)) have chkvar_t_s: "chkvar t s" and chkvar_s_t: "chkvar s t" using g f by simp_all { assume g_gt_f: "g >\<^sub>s f" have "t >\<^sub>t s" by (rule gt_diff[OF _ chkvar_t_s chksubs_t_s]) (simp add: g f gt_sym_imp_hd[OF g_gt_f]) } moreover { assume f_gt_g: "f >\<^sub>s g" have "s >\<^sub>t t" by (rule gt_diff[OF _ chkvar_s_t chksubs_s_t]) (simp add: g f gt_sym_imp_hd[OF f_gt_g]) } moreover { assume g_eq_f: "g = f" hence hd_t: "head t = head s" using g f by auto let ?ts = "args t" let ?ss = "args s" have gr_ts: "\<forall>ta \<in> set ?ts. ground ta" using ground_args[OF _ gr_t] by blast have gr_ss: "\<forall>sa \<in> set ?ss. ground sa" using ground_args[OF _ gr_s] by blast { assume ts_eq_ss: "?ts = ?ss" have "t = s" using hd_t ts_eq_ss by (rule tm_expand_apps) } moreover { assume ts_gt_ss: "extf g (>\<^sub>t) ?ts ?ss" have "t >\<^sub>t s" by (rule gt_same[OF hd_t chksubs_t_s]) (auto simp: g ts_gt_ss) } moreover { assume ss_gt_ts: "extf g (>\<^sub>t) ?ss ?ts" have "s >\<^sub>t t" by (rule gt_same[OF hd_t[symmetric] chksubs_s_t]) (auto simp: f[folded g_eq_f] ss_gt_ts) } ultimately have ?case using ih gr_ss gr_ts ext_total.total[OF extf_total, rule_format, of "set ?ts \<union> set ?ss" "(>\<^sub>t)" ?ts ?ss g] by (metis Un_iff in_listsI less_multiset_doubletons size_in_args) } ultimately have ?case using gt_sym_total by blast } ultimately show ?case by fast qed subsection \<open>Well-foundedness\<close> abbreviation gtg :: "('s, 'v) tm \<Rightarrow> ('s, 'v) tm \<Rightarrow> bool" (infix ">\<^sub>t\<^sub>g" 50) where "(>\<^sub>t\<^sub>g) \<equiv> \<lambda>t s. ground t \<and> t >\<^sub>t s" theorem gt_wf: assumes extf_wf: "\<And>f. ext_wf (extf f)" shows "wfP (\<lambda>s t. t >\<^sub>t s)" proof - have ground_wfP: "wfP (\<lambda>s t. t >\<^sub>t\<^sub>g s)" unfolding wfP_iff_no_inf_chain proof assume "\<exists>f. inf_chain (>\<^sub>t\<^sub>g) f" then obtain t where t_bad: "bad (>\<^sub>t\<^sub>g) t" unfolding inf_chain_def bad_def by blast let ?ff = "worst_chain (>\<^sub>t\<^sub>g) (\<lambda>t s. size t > size s)" let ?U_of = "\<lambda>i. if is_App (?ff i) then {fun (?ff i)} \<union> set (args (?ff i)) else {}" note wf_sz = wf_app[OF wellorder_class.wf, of size, simplified] define U where "U = (\<Union>i. ?U_of i)" have gr: "\<And>i. ground (?ff i)" using worst_chain_bad[OF wf_sz t_bad, unfolded inf_chain_def] by fast have gr_fun: "\<And>i. ground (fun (?ff i))" by (rule ground_fun[OF gr]) have gr_args: "\<And>i s. s \<in> set (args (?ff i)) \<Longrightarrow> ground s" by (rule ground_args[OF _ gr]) have gr_u: "\<And>u. u \<in> U \<Longrightarrow> ground u" unfolding U_def by (auto dest: gr_args) (metis (lifting) empty_iff gr_fun) have "\<not> bad (>\<^sub>t\<^sub>g) u" if u_in: "u \<in> ?U_of i" for u i proof let ?ti = "?ff i" assume u_bad: "bad (>\<^sub>t\<^sub>g) u" have sz_u: "size u < size ?ti" proof (cases "?ff i") case Hd thus ?thesis using u_in size_in_args by fastforce next case App thus ?thesis using u_in size_in_args insert_iff size_fun_lt by fastforce qed show False proof (cases i) case 0 thus False using sz_u min_worst_chain_0[OF wf_sz u_bad] by simp next case Suc hence "?ff (i - 1) >\<^sub>t ?ff i" using worst_chain_pred[OF wf_sz t_bad] by simp moreover have "?ff i >\<^sub>t u" proof - have u_in: "u \<in> ?U_of i" using u_in by blast have ffi_ne_u: "?ff i \<noteq> u" using sz_u by fastforce hence "is_App (?ff i) \<Longrightarrow> \<not> sub u (?ff i) \<Longrightarrow> ?ff i >\<^sub>t u" using u_in gt_sub sub_args by auto thus "?ff i >\<^sub>t u" using ffi_ne_u u_in gt_proper_sub sub_args by fastforce qed ultimately have "?ff (i - 1) >\<^sub>t u" by (rule gt_trans) thus False using Suc sz_u min_worst_chain_Suc[OF wf_sz u_bad] gr by fastforce qed qed hence u_good: "\<And>u. u \<in> U \<Longrightarrow> \<not> bad (>\<^sub>t\<^sub>g) u" unfolding U_def by blast have bad_diff_same: "inf_chain (\<lambda>t s. ground t \<and> (gt_diff t s \<or> gt_same t s)) ?ff" unfolding inf_chain_def proof (intro allI conjI) fix i show "ground (?ff i)" by (rule gr) have gt: "?ff i >\<^sub>t ?ff (Suc i)" using worst_chain_pred[OF wf_sz t_bad] by blast have "\<not> gt_sub (?ff i) (?ff (Suc i))" proof assume a: "gt_sub (?ff i) (?ff (Suc i))" hence fi_app: "is_App (?ff i)" and fun_or_arg_fi_ge: "fun (?ff i) \<ge>\<^sub>t ?ff (Suc i) \<or> arg (?ff i) \<ge>\<^sub>t ?ff (Suc i)" unfolding gt_sub.simps by blast+ have "fun (?ff i) \<in> ?U_of i" unfolding U_def using fi_app by auto moreover have "arg (?ff i) \<in> ?U_of i" unfolding U_def using fi_app arg_in_args by force ultimately obtain uij where uij_in: "uij \<in> U" and uij_cases: "uij \<ge>\<^sub>t ?ff (Suc i)" unfolding U_def using fun_or_arg_fi_ge by blast have "\<And>n. ?ff n >\<^sub>t ?ff (Suc n)" by (rule worst_chain_pred[OF wf_sz t_bad, THEN conjunct2]) hence uij_gt_i_plus_3: "uij >\<^sub>t ?ff (Suc (Suc i))" using gt_trans uij_cases by blast have "inf_chain (>\<^sub>t\<^sub>g) (\<lambda>j. if j = 0 then uij else ?ff (Suc (i + j)))" unfolding inf_chain_def by (auto intro!: gr gr_u[OF uij_in] uij_gt_i_plus_3 worst_chain_pred[OF wf_sz t_bad]) hence "bad (>\<^sub>t\<^sub>g) uij" unfolding bad_def by fastforce thus False using u_good[OF uij_in] by sat qed thus "gt_diff (?ff i) (?ff (Suc i)) \<or> gt_same (?ff i) (?ff (Suc i))" using gt unfolding gt_iff_sub_diff_same by sat qed have "wf {(s, t). ground s \<and> ground t \<and> sym (head t) >\<^sub>s sym (head s)}" using gt_sym_wf unfolding wfP_def wf_iff_no_infinite_down_chain by fast moreover have "{(s, t). ground t \<and> gt_diff t s} \<subseteq> {(s, t). ground s \<and> ground t \<and> sym (head t) >\<^sub>s sym (head s)}" proof (clarsimp, intro conjI) fix s t assume gr_t: "ground t" and gt_diff_t_s: "gt_diff t s" thus gr_s: "ground s" using gt_iff_sub_diff_same gt_imp_vars by fastforce show "sym (head t) >\<^sub>s sym (head s)" using gt_diff_t_s ground_head[OF gr_s] ground_head[OF gr_t] by (cases; cases "head s"; cases "head t") (auto simp: gt_hd_def) qed ultimately have wf_diff: "wf {(s, t). ground t \<and> gt_diff t s}" by (rule wf_subset) have diff_O_same: "{(s, t). ground t \<and> gt_diff t s} O {(s, t). ground t \<and> gt_same t s} \<subseteq> {(s, t). ground t \<and> gt_diff t s}" unfolding gt_diff.simps gt_same.simps by clarsimp (metis chksubs_def empty_subsetI gt_diff[unfolded chkvar_def] gt_imp_chksubs_gt gt_same gt_trans) have diff_same_as_union: "{(s, t). ground t \<and> (gt_diff t s \<or> gt_same t s)} = {(s, t). ground t \<and> gt_diff t s} \<union> {(s, t). ground t \<and> gt_same t s}" by auto obtain k where bad_same: "inf_chain (\<lambda>t s. ground t \<and> gt_same t s) (\<lambda>i. ?ff (i + k))" using wf_infinite_down_chain_compatible[OF wf_diff _ diff_O_same, of ?ff] bad_diff_same unfolding inf_chain_def diff_same_as_union[symmetric] by auto hence hd_sym: "\<And>i. is_Sym (head (?ff (i + k)))" unfolding inf_chain_def by (simp add: ground_head) define f where "f = sym (head (?ff k))" have hd_eq_f: "head (?ff (i + k)) = Sym f" for i proof (induct i) case 0 thus ?case by (auto simp: f_def hd.collapse(2)[OF hd_sym, of 0, simplified]) next case (Suc ia) thus ?case using bad_same unfolding inf_chain_def gt_same.simps by simp qed let ?gtu = "\<lambda>t s. t \<in> U \<and> t >\<^sub>t s" have "t \<in> set (args (?ff i)) \<Longrightarrow> t \<in> ?U_of i" for t i unfolding U_def by (cases "is_App (?ff i)", simp_all, metis (lifting) neq_iff size_in_args sub.cases sub_args tm.discI(2)) moreover have "\<And>i. extf f (>\<^sub>t) (args (?ff (i + k))) (args (?ff (Suc i + k)))" using bad_same hd_eq_f unfolding inf_chain_def gt_same.simps by auto ultimately have "\<And>i. extf f ?gtu (args (?ff (i + k))) (args (?ff (Suc i + k)))" using extf_mono_strong[of _ _ "(>\<^sub>t)" "\<lambda>t s. t \<in> U \<and> t >\<^sub>t s"] unfolding U_def by blast hence "inf_chain (extf f ?gtu) (\<lambda>i. args (?ff (i + k)))" unfolding inf_chain_def by blast hence nwf_ext: "\<not> wfP (\<lambda>xs ys. extf f ?gtu ys xs)" unfolding wfP_iff_no_inf_chain by fast have gtu_le_gtg: "?gtu \<le> (>\<^sub>t\<^sub>g)" by (auto intro!: gr_u) have "wfP (\<lambda>s t. ?gtu t s)" unfolding wfP_iff_no_inf_chain proof (intro notI, elim exE) fix f assume bad_f: "inf_chain ?gtu f" hence bad_f0: "bad ?gtu (f 0)" by (rule inf_chain_bad) have "f 0 \<in> U" using bad_f unfolding inf_chain_def by blast hence good_f0: "\<not> bad ?gtu (f 0)" using u_good bad_f inf_chain_bad inf_chain_subset[OF _ gtu_le_gtg] by blast show False using bad_f0 good_f0 by sat qed hence wf_ext: "wfP (\<lambda>xs ys. extf f ?gtu ys xs)" by (rule ext_wf.wf[OF extf_wf, rule_format]) show False using nwf_ext wf_ext by blast qed let ?subst = "subst grounding_\<rho>" have "wfP (\<lambda>s t. ?subst t >\<^sub>t\<^sub>g ?subst s)" by (rule wfP_app[OF ground_wfP]) hence "wfP (\<lambda>s t. ?subst t >\<^sub>t ?subst s)" by (simp add: ground_grounding_\<rho>) thus ?thesis by (auto intro: wfP_subset gt_subst[OF wary_grounding_\<rho>]) qed end end
#pragma once #include <list> #include <string> #include <boost/tokenizer.hpp> #include <boost/lexical_cast.hpp> namespace dawn { inline std::list<std::string> tokenize_string(std::string const& s, char const separator) { std::list<std::string> lst; typedef boost::tokenizer<boost::char_separator<char>> tokenizer; std::string ss; ss.push_back(separator); boost::char_separator<char> sep(ss.data()); tokenizer tok(s, sep); for(tokenizer::iterator i = tok.begin(); i != tok.end(); ++i) lst.push_back(*i); return lst; } template <typename T> std::list<T> tokenize_string_cast(std::string const& s, char const separator) { auto strings = tokenize_string(s, separator); std::list<T> lst; for (std::string const& x : strings) lst.push_back(boost::lexical_cast<T>(x)); return lst; } }
import os from torch.utils.data import Dataset from torch.utils.data import DataLoader import torch import torch.nn as nn import numpy as np import matplotlib.pyplot as plt class MyImageDataset(Dataset): # 画像用 Dataset クラス def __init__(self, data): self.image = data[0] self.label = data[1] def __len__(self): return self.image.shape[0] def __getitem__(self, index):#ローダを介すとtorch tensorになる f_image = self.image[index].numpy().astype(np.float32) # return {'image': f_image, 'label': self.label[index]} return [f_image, self.label[index]] class MyImageNetwork(nn.Module): # 画像識別用ネットワークモデル def __init__(self, num_classes): super().__init__() self.block1 = nn.Sequential( nn.Conv2d(3,64,3), nn.ReLU(), nn.Conv2d(64,64,3), nn.ReLU(), nn.MaxPool2d(2), nn.Dropout(0.25) ) self.block2 = nn.Sequential( nn.Conv2d(64,128,3), nn.ReLU(), nn.Conv2d(128,128,3), nn.ReLU(), nn.MaxPool2d(2), nn.Dropout(0.25) ) self.full_connection = nn.Sequential( # nn.Linear(42, 128), # nn.ReLU(), # nn.Linear(128, 64), # nn.ReLU(), # nn.Dropout(), nn.Linear(42, num_classes) ) self.optimizer = torch.optim.Adam(self.parameters(), lr=3e-4) def forward(self, x): # x = self.block1(x) # x = self.block2(x) # x = torch.flatten(x, start_dim=1) # 値を1次元化 x = self.full_connection(x) return x #クロスエントロピーにはsoftmaxが入ってるらしい # return torch.softmax(x, dim=1) # SoftMax 関数の計算結果を出力 def loss_function(self, estimate, target): return nn.functional.cross_entropy(estimate, target) # 交差エントロピーでクラス判別 def train(loader_train, model_obj, device, total_epoch, epoch): model_obj.train() # モデルを学習モードに変更 correct = 0 log = [] for data, targets in loader_train: data = data.to(device, dtype=torch.float) # GPUを使用するため,to()で明示的に指定 targets = targets.to(device) # 同上 model_obj.optimizer.zero_grad() # 勾配を初期化 outputs = model_obj(data) # 順伝播の計算 loss = model_obj.loss_function(outputs, targets) # 誤差を計算 loss.backward() # 誤差を逆伝播させる model_obj.optimizer.step() # 重みを更新する _, predicted = torch.max(outputs.data, 1) # 確率が最大のラベルを取得 correct += predicted.eq(targets.data.view_as(predicted)).sum() # 正解ならば正解数をカウントアップ log.append(loss.item()) avg_loss = sum(log)/len(log) acc = 1.*correct.item() / len(train_loader.dataset) return avg_loss, acc def test(loader_test, trained_model, device): trained_model.eval() # モデルを推論モードに変更 correct = 0 # 正解率計算用の変数を宣言 log = [] # ミニバッチごとに推論 with torch.no_grad(): # 推論時には勾配は不要 for data, targets in loader_test: data = data.to(device, dtype=torch.float) # GPUを使用するため,to()で明示的に指定 targets = targets.to(device) # 同上 outputs = trained_model(data) # 順伝播の計算 loss = trained_model.loss_function(outputs, targets) # 誤差を計算 _, predicted = torch.max(outputs.data, 1) # 確率が最大のラベルを取得 correct += predicted.eq(targets.data.view_as(predicted)).sum() # 正解ならば正解数をカウントアップ log.append(loss.item()) avg_loss = sum(log)/len(log) acc = 1.*correct.item() / len(test_loader.dataset) return avg_loss, acc if __name__ == '__main__': device = torch.device('cuda' if torch.cuda.is_available() else 'cpu') batch_size = 128 num_classes = 10 epochs = 2000 model = MyImageNetwork(num_classes).to(device) path = './1' if os.path.isfile(path+'/last.pt'): # 以前の学習結果が存在する場合 last_state = torch.load(path+'/last.pt', map_location=device) # データファイルの読み込み model.load_state_dict(last_state['state_dict']) # 学習済ネットワーク変数の代入 last_epoch = last_state['epoch'] # 引き続きのエポック数 min_loss = last_state['loss'] # 最小損失を継承 print('epoch started from', last_epoch) else: last_epoch = 0 min_loss = 1000. # 適当に大きい数を代入 train_data = torch.load('./train.pt') test_data = torch.load('./test.pt') train_dataset = MyImageDataset(train_data) # 訓練用画像データ test_dataset = MyImageDataset(test_data) # 検証用画像データ train_loader = DataLoader(train_dataset, batch_size=batch_size, shuffle=True) test_loader = DataLoader(test_dataset, batch_size=batch_size, shuffle=True) print('Begin train') log = [] #lossとaccを記録するリスト for epoch in range(1, epochs+1): train_loss, train_acc = train(train_loader, model, device, epochs, epoch) test_loss, test_acc = test(test_loader, model, device) log.append([epoch+last_epoch, train_loss, test_loss, train_acc, test_acc]) print('\n<TRAIN> ACC : {}'.format(train_acc)) print('<TEST> ACC : {}'.format(test_acc)) # save_dict = {'state_dict': model.state_dict(), 'epoch': epochs+last_epoch, 'loss': train_loss} # torch.save(save_dict, path+'/last.pt') # # import csv # with open(path+'/log.csv', 'a+') as f: # writer = csv.writer(f, lineterminator='\n') # 改行コード(\n)を指定しておく # f.seek(0) #読み込み位置を先頭に # if len(f.read()) == 0: #先頭に凡例 # writer.writerow(['epochs', 'train_loss', 'test_loss', 'train_acc', 'test_acc']) # writer.writerows(log)
#= parser2: - Julia version: - Author: bramb - Date: 2019-02-28 =# using Query,LibExpat,DataStructures,LightGraphs,MetaGraphs @enum(TextState,TEXT,TAIL) mutable struct Element name::String attributes::Dict{String,String} in_text_divergence::Bool parent::Element Element(name::String) = new(name,Dict{String,String}(),false) end mutable struct Triple element::Element text tail function Triple() element = Element("") text = IOBuffer() tail = IOBuffer(); new(element,text,tail) end end mutable struct Context last_element_is_open::Bool triples::Array{Triple} text tail text_state::TextState open_elements::Array{Element} open_divergence_elements::Array{Element} function Context() last_element_is_open = false triples = [] text = IOBuffer() tail = IOBuffer() text_state = TEXT; open_elements = [] open_divergence_elements = [] new(last_element_is_open,triples,text,tail,text_state,open_elements,open_divergence_elements) end end is_divergence_element(name::String) = name in ["subst", "choice", "app"] function get_triples(xml::String) ctx = Context() cbs = XPCallbacks() cbs.start_element = function(h, name, attrs) # println("<$name>") triple = Triple() triple.element = Element(name) triple.element.in_text_divergence = !isempty(h.data.open_divergence_elements) push!(h.data.triples,triple) h.data.last_element_is_open = true h.data.text_state = TEXT if (!isempty(h.data.open_elements)) parent = h.data.open_elements[1] triple.element.parent = parent end pushfirst!(h.data.open_elements,triple.element) if (is_divergence_element(triple.element.name)) pushfirst!(h.data.open_divergence_elements,triple.element) end end cbs.end_element = function(h, name) # println("</$name>") h.data.text_state = TAIL popfirst!(h.data.open_elements) if (is_divergence_element(name)) popfirst!(h.data.open_divergence_elements) end end cbs.character_data = function(h, txt) # println("\"$txt\"") # now we add to either text or tail, depending on text_state if (h.data.text_state == TEXT) print(h.data.triples[end].text,txt) else print(h.data.triples[end].tail,txt) end end parse(xml,cbs,data = ctx) return ctx.triples end parent(x::Triple) = isdefined(x.element, :parent) ? x.element.parent : "XML" group_triples(triples) = triples |> @groupby(parent(_)) |> collect serialize_text(t::Triple) = String(take!(t.text)) serialize_tail(t::Triple) = String(take!(t.tail)) function serialize_group(g) buf = IOBuffer() if (length(g) > 1) if (g[1].element.in_text_divergence) print(buf,"<|") for t in g print(buf,serialize_text(t),"|") end print(buf,">",serialize_tail(g[end])) else for t in g print(buf,serialize_text(t),serialize_tail(t)) end end else print(buf,serialize_text(g[1]),serialize_tail(g[1])) end return String(take!(buf)) end function serialize_grouped_triples(grouped_triples) serbuf = IOBuffer() for group in grouped_triples print(serbuf,serialize_group(group)) end return String(take!(serbuf)) end @enum(VertexType,TEXTNODE,DIVERGENCE,CONVERGENCE) # function to_graph(grouped_triples::Array{Group{Triple},1}) # mg = MetaGraph(SimpleGraph()) # for group in grouped_triples # for triple in group # text = serialize_text(triple) # @show(text) # if (!isempty(text)) # add_vertices!(mg.graph,1) # v = nv(mg.graph) # set_props!(mg,v,Dict(:type => TEXTNODE,:text => text)) # v>1 && add_edge!(mg.graph, v-1, v) # end # tail = serialize_tail(triple) # @show(tail) # if (!isempty(tail)) # add_vertices!(mg.graph,1) # v = nv(mg.graph) # set_props!(mg,v,Dict(:type => TEXTNODE,:text => tail)) # v>1 && add_edge!(mg.graph, v-1, v) # end # end # end # return mg # end
/** iris_lib.cpp \authors: Rahman Doost-Mohammady : [email protected] Clay Shepard : [email protected] */ #include <string.h> #include <pthread.h> #include <unistd.h> #include <stdio.h> #include <SoapySDR/Device.hpp> #include <SoapySDR/Formats.hpp> #include <SoapySDR/Time.hpp> //#include <boost/format.hpp> #include <iostream> #include <complex> #include <fstream> #include <cmath> #include <time.h> #include <limits> #include "common/utils/LOG/log_extern.h" #include "common_lib.h" #include <chrono> #ifdef __SSE4_1__ #include <smmintrin.h> #endif #ifdef __AVX2__ #include <immintrin.h> #endif #define MOVE_DC #define SAMPLE_RATE_DOWN 1 /*! \brief Iris Configuration */ extern "C" { typedef struct { // -------------------------------- // variables for Iris configuration // -------------------------------- //! Iris device pointer std::vector<SoapySDR::Device *> iris; int device_num; int rx_num_channels; int tx_num_channels; //create a send streamer and a receive streamer //! Iris TX Stream std::vector<SoapySDR::Stream *> txStream; //! Iris RX Stream std::vector<SoapySDR::Stream *> rxStream; //! Sampling rate double sample_rate; //! time offset between transmiter timestamp and receiver timestamp; double tdiff; //! TX forward samples. int tx_forward_nsamps; //166 for 20Mhz // -------------------------------- // Debug and output control // -------------------------------- //! Number of underflows int num_underflows; //! Number of overflows int num_overflows; //! Number of sequential errors int num_seq_errors; //! tx count int64_t tx_count; //! rx count int64_t rx_count; //! timestamp of RX packet openair0_timestamp rx_timestamp; } iris_state_t; } /*! \brief Called to start the Iris lime transceiver. Return 0 if OK, < 0 if error @param device pointer to the device structure specific to the RF hardware target */ static int trx_iris_start(openair0_device *device) { iris_state_t *s = (iris_state_t *) device->priv; long long timeNs = s->iris[0]->getHardwareTime("") + 500000; int flags = 0; //flags |= SOAPY_SDR_HAS_TIME; int r; for(r = 0; r < s->device_num; r++) { int ret = s->iris[r]->activateStream(s->rxStream[r], flags, timeNs, 0); int ret2 = s->iris[r]->activateStream(s->txStream[r]); if(ret < 0 | ret2 < 0) { return -1; } } return 0; } /*! \brief Stop Iris \param card refers to the hardware index to use */ int trx_iris_stop(openair0_device *device) { iris_state_t *s = (iris_state_t *) device->priv; int r; for(r = 0; r < s->device_num; r++) { s->iris[r]->deactivateStream(s->txStream[r]); s->iris[r]->deactivateStream(s->rxStream[r]); } return (0); } /*! \brief Terminate operation of the Iris lime transceiver -- free all associated resources \param device the hardware to use */ static void trx_iris_end(openair0_device *device) { LOG_I(HW, "Closing Iris device.\n"); trx_iris_stop(device); iris_state_t *s = (iris_state_t *) device->priv; int r; for(r = 0; r < s->device_num; r++) { s->iris[r]->closeStream(s->txStream[r]); s->iris[r]->closeStream(s->rxStream[r]); SoapySDR::Device::unmake(s->iris[r]); } } /*! \brief Called to send samples to the Iris RF target @param device pointer to the device structure specific to the RF hardware target @param timestamp The timestamp at whicch the first sample MUST be sent @param buff Buffer which holds the samples @param nsamps number of samples to be sent @param antenna_id index of the antenna if the device has multiple anteannas @param flags flags must be set to TRUE if timestamp parameter needs to be applied */ static int trx_iris_write(openair0_device *device, openair0_timestamp timestamp, void **buff, int nsamps, int cc, int flags) { using namespace std::chrono; static long long int loop = 0; static long time_min = 0, time_max = 0, time_avg = 0; struct timespec tp_start, tp_end; long time_diff; int ret = 0, ret_i = 0; int flag = 0; iris_state_t *s = (iris_state_t *) device->priv; int nsamps2; // aligned to upper 32 or 16 byte boundary #if defined(__x86_64) || defined(__i386__) #ifdef __AVX2__ nsamps2 = (nsamps + 7) >> 3; __m256i buff_tx[2][nsamps2]; #else nsamps2 = (nsamps + 3) >> 2; __m128i buff_tx[2][nsamps2]; #endif #else #error unsupported CPU architecture, iris device cannot be built #endif // bring RX data into 12 LSBs for softmodem RX for(int i = 0; i < cc; i++) { for(int j = 0; j < nsamps2; j++) { #if defined(__x86_64__) || defined(__i386__) #ifdef __AVX2__ buff_tx[i][j] = _mm256_slli_epi16(((__m256i *)buff[i])[j], 4); #else buff_tx[i][j] = _mm_slli_epi16(((__m128i *)buff[i])[j], 4); #endif #endif } } clock_gettime(CLOCK_MONOTONIC_RAW, &tp_start); // This hack was added by cws to help keep packets flowing if(flags) { flag |= SOAPY_SDR_HAS_TIME; } else { long long tempHack = s->iris[0]->getHardwareTime(""); return nsamps; } if(flags == 2 || flags == 1) // start of burst { } else if(flags == 3 | flags == 4) { flag |= SOAPY_SDR_END_BURST; } long long timeNs = SoapySDR::ticksToTimeNs(timestamp, s->sample_rate / SAMPLE_RATE_DOWN); uint32_t *samps[2]; //= (uint32_t **)buff; int r; int m = s->tx_num_channels; for(r = 0; r < s->device_num; r++) { int samples_sent = 0; samps[0] = (uint32_t *) buff_tx[m * r]; if(cc % 2 == 0) { samps[1] = (uint32_t *) buff_tx[m * r + 1]; //cws: it seems another thread can clobber these, so we need to save them locally. } #ifdef IRIS_DEBUG int i; for(i = 200; i < 216; i++) { printf("%d, ", ((int16_t)(samps[0][i] >> 16)) >> 4); } printf("\n"); //printf("\nHardware time before write: %lld, tx_time_stamp: %lld\n", s->iris[0]->getHardwareTime(""), timeNs); #endif ret = s->iris[r]->writeStream(s->txStream[r], (void **) samps, (size_t)(nsamps), flag, timeNs, 1000000); if(ret < 0) { printf("Unable to write stream!\n"); } else { samples_sent = ret; } if(samples_sent != nsamps) { printf("[xmit] tx samples %d != %d\n", samples_sent, nsamps); } } return nsamps; } /*! \brief Receive samples from hardware. Read \ref nsamps samples from each channel to buffers. buff[0] is the array for the first channel. *ptimestamp is the time at which the first sample was received. \param device the hardware to use \param[out] ptimestamp the time at which the first sample was received. \param[out] buff An array of pointers to buffers for received samples. The buffers must be large enough to hold the number of samples \ref nsamps. \param nsamps Number of samples. One sample is 2 byte I + 2 byte Q => 4 byte. \param antenna_id Index of antenna for which to receive samples \returns the number of sample read */ static int trx_iris_read(openair0_device *device, openair0_timestamp *ptimestamp, void **buff, int nsamps, int cc) { int ret = 0; static long long nextTime; static bool nextTimeValid = false; iris_state_t *s = (iris_state_t *) device->priv; bool time_set = false; long long timeNs = 0; int flags; int samples_received; uint32_t *samps[2]; //= (uint32_t **)buff; int r; int m = s->rx_num_channels; int nsamps2; // aligned to upper 32 or 16 byte boundary #if defined(__x86_64) || defined(__i386__) #ifdef __AVX2__ nsamps2 = (nsamps + 7) >> 3; __m256i buff_tmp[2][nsamps2]; #else nsamps2 = (nsamps + 3) >> 2; __m128i buff_tmp[2][nsamps2]; #endif #endif for(r = 0; r < s->device_num; r++) { flags = 0; samples_received = 0; samps[0] = (uint32_t *) buff_tmp[m * r]; if(cc % 2 == 0) { samps[1] = (uint32_t *) buff_tmp[m * r + 1]; } flags = 0; ret = s->iris[r]->readStream(s->rxStream[r], (void **) samps, (size_t)(nsamps), flags, timeNs, 1000000); if(ret < 0) { if(ret == SOAPY_SDR_TIME_ERROR) { printf("[recv] Time Error in tx stream!\n"); } else if(ret == SOAPY_SDR_OVERFLOW | (flags & SOAPY_SDR_END_ABRUPT)) { printf("[recv] Overflow occured!\n"); } else if(ret == SOAPY_SDR_TIMEOUT) { printf("[recv] Timeout occured!\n"); } else if(ret == SOAPY_SDR_STREAM_ERROR) { printf("[recv] Stream (tx) error occured!\n"); } else if(ret == SOAPY_SDR_CORRUPTION) { printf("[recv] Bad packet occured!\n"); } break; } else { samples_received = ret; } if(r == 0) { if(samples_received == ret) // first batch { if(flags & SOAPY_SDR_HAS_TIME) { s->rx_timestamp = SoapySDR::timeNsToTicks(timeNs, s->sample_rate / SAMPLE_RATE_DOWN); *ptimestamp = s->rx_timestamp; nextTime = timeNs; nextTimeValid = true; time_set = true; //printf("1) time set %llu \n", *ptimestamp); } } } if(r == 0) { if(samples_received == nsamps) { if(flags & SOAPY_SDR_HAS_TIME) { s->rx_timestamp = SoapySDR::timeNsToTicks(nextTime, s->sample_rate / SAMPLE_RATE_DOWN); *ptimestamp = s->rx_timestamp; nextTime = timeNs; nextTimeValid = true; time_set = true; } } else if(samples_received < nsamps) { printf("[recv] received %d samples out of %d\n", samples_received, nsamps); } s->rx_count += samples_received; if(s->sample_rate != 0 && nextTimeValid) { if(!time_set) { s->rx_timestamp = SoapySDR::timeNsToTicks(nextTime, s->sample_rate / SAMPLE_RATE_DOWN); *ptimestamp = s->rx_timestamp; //printf("2) time set %llu, nextTime will be %llu \n", *ptimestamp, nextTime); } nextTime += SoapySDR::ticksToTimeNs(samples_received, s->sample_rate / SAMPLE_RATE_DOWN); } } // bring RX data into 12 LSBs for softmodem RX for(int i = 0; i < cc; i++) { for(int j = 0; j < nsamps2; j++) { #if defined(__x86_64__) || defined(__i386__) #ifdef __AVX2__ ((__m256i *)buff[i])[j] = _mm256_srai_epi16(buff_tmp[i][j], 4); #else ((__m128i *)buff[i])[j] = _mm_srai_epi16(buff_tmp[i][j], 4); #endif #endif } } } return samples_received; } /*! \brief Get current timestamp of Iris \param device the hardware to use */ openair0_timestamp get_iris_time(openair0_device *device) { iris_state_t *s = (iris_state_t *) device->priv; return SoapySDR::timeNsToTicks(s->iris[0]->getHardwareTime(""), s->sample_rate); } /*! \brief Compares two variables within precision \param a first variable \param b second variable */ static bool is_equal(double a, double b) { return std::fabs(a - b) < std::numeric_limits<double>::epsilon(); } void *set_freq_thread(void *arg) { openair0_device *device = (openair0_device *) arg; iris_state_t *s = (iris_state_t *) device->priv; int r, i; printf("Setting Iris TX Freq %f, RX Freq %f\n", device->openair0_cfg[0].tx_freq[0], device->openair0_cfg[0].rx_freq[0]); // add check for the number of channels in the cfg for(r = 0; r < s->device_num; r++) { for(i = 0; i < s->iris[r]->getNumChannels(SOAPY_SDR_RX); i++) { if(i < s->rx_num_channels) { s->iris[r]->setFrequency(SOAPY_SDR_RX, i, "RF", device->openair0_cfg[0].rx_freq[i]); } } for(i = 0; i < s->iris[r]->getNumChannels(SOAPY_SDR_TX); i++) { if(i < s->tx_num_channels) { s->iris[r]->setFrequency(SOAPY_SDR_TX, i, "RF", device->openair0_cfg[0].tx_freq[i]); } } } } /*! \brief Set frequencies (TX/RX) \param device the hardware to use \param openair0_cfg RF frontend parameters set by application \param dummy dummy variable not used \returns 0 in success */ int trx_iris_set_freq(openair0_device *device, openair0_config_t *openair0_cfg, int dont_block) { iris_state_t *s = (iris_state_t *) device->priv; pthread_t f_thread; if(dont_block) { pthread_create(&f_thread, NULL, set_freq_thread, (void *) device); } else { int r, i; for(r = 0; r < s->device_num; r++) { printf("Setting Iris TX Freq %f, RX Freq %f\n", openair0_cfg[0].tx_freq[0], openair0_cfg[0].rx_freq[0]); for(i = 0; i < s->iris[r]->getNumChannels(SOAPY_SDR_RX); i++) { if(i < s->rx_num_channels) { s->iris[r]->setFrequency(SOAPY_SDR_RX, i, "RF", openair0_cfg[0].rx_freq[i]); } } for(i = 0; i < s->iris[r]->getNumChannels(SOAPY_SDR_TX); i++) { if(i < s->tx_num_channels) { s->iris[r]->setFrequency(SOAPY_SDR_TX, i, "RF", openair0_cfg[0].tx_freq[i]); } } } } return (0); } /*! \brief Set Gains (TX/RX) \param device the hardware to use \param openair0_cfg RF frontend parameters set by application \returns 0 in success */ int trx_iris_set_gains(openair0_device *device, openair0_config_t *openair0_cfg) { iris_state_t *s = (iris_state_t *) device->priv; int r; for(r = 0; r < s->device_num; r++) { s->iris[r]->setGain(SOAPY_SDR_RX, 0, openair0_cfg[0].rx_gain[0]); s->iris[r]->setGain(SOAPY_SDR_TX, 0, openair0_cfg[0].tx_gain[0]); s->iris[r]->setGain(SOAPY_SDR_RX, 1, openair0_cfg[0].rx_gain[1]); s->iris[r]->setGain(SOAPY_SDR_TX, 1, openair0_cfg[0].tx_gain[1]); } return (0); } /*! \brief Iris RX calibration table */ rx_gain_calib_table_t calib_table_iris[] = { {3500000000.0, 83}, {2660000000.0, 83}, {2580000000.0, 83}, {2300000000.0, 83}, {1880000000.0, 83}, {816000000.0, 83}, {-1, 0} }; /*! \brief Set RX gain offset \param openair0_cfg RF frontend parameters set by application \param chain_index RF chain to apply settings to \returns 0 in success */ void set_rx_gain_offset(openair0_config_t *openair0_cfg, int chain_index, int bw_gain_adjust) { int i = 0; // loop through calibration table to find best adjustment factor for RX frequency double min_diff = 6e9, diff, gain_adj = 0.0; if(bw_gain_adjust == 1) { switch((int) openair0_cfg[0].sample_rate) { case 30720000: break; case 23040000: gain_adj = 1.25; break; case 15360000: gain_adj = 3.0; break; case 7680000: gain_adj = 6.0; break; case 3840000: gain_adj = 9.0; break; case 1920000: gain_adj = 12.0; break; default: printf("unknown sampling rate %d\n", (int) openair0_cfg[0].sample_rate); exit(-1); break; } } while(openair0_cfg->rx_gain_calib_table[i].freq > 0) { diff = fabs(openair0_cfg->rx_freq[chain_index] - openair0_cfg->rx_gain_calib_table[i].freq); printf("cal %d: freq %f, offset %f, diff %f\n", i, openair0_cfg->rx_gain_calib_table[i].freq, openair0_cfg->rx_gain_calib_table[i].offset, diff); if(min_diff > diff) { min_diff = diff; openair0_cfg->rx_gain_offset[chain_index] = openair0_cfg->rx_gain_calib_table[i].offset + gain_adj; } i++; } } /*! \brief print the Iris statistics \param device the hardware to use \returns 0 on success */ int trx_iris_get_stats(openair0_device *device) { return (0); } /*! \brief Reset the Iris statistics \param device the hardware to use \returns 0 on success */ int trx_iris_reset_stats(openair0_device *device) { return (0); } extern "C" { /*! \brief Initialize Openair Iris target. It returns 0 if OK \param device the hardware to use \param openair0_cfg RF frontend parameters set by application */ int device_init(openair0_device *device, openair0_config_t *openair0_cfg) { size_t i, r, card; int bw_gain_adjust = 0; openair0_cfg[0].rx_gain_calib_table = calib_table_iris; iris_state_t *s = (iris_state_t *) malloc(sizeof(iris_state_t)); memset(s, 0, sizeof(iris_state_t)); std::string devFE("DEV"); std::string cbrsFE("CBRS"); std::string wireFormat("WIRE"); // Initialize Iris device device->openair0_cfg = openair0_cfg; SoapySDR::Kwargs args; args["driver"] = "iris"; char *iris_addrs = device->openair0_cfg[0].sdr_addrs; if(iris_addrs == NULL) { s->iris.push_back(SoapySDR::Device::make(args)); } else { char *serial = strtok(iris_addrs, ","); while(serial != NULL) { LOG_I(HW, "Attempting to open Iris device %s\n", serial); args["serial"] = serial; s->iris.push_back(SoapySDR::Device::make(args)); serial = strtok(NULL, ","); } } s->device_num = s->iris.size(); device->type = IRIS_DEV; switch((int) openair0_cfg[0].sample_rate) { case 30720000: //openair0_cfg[0].samples_per_packet = 1024; openair0_cfg[0].tx_sample_advance = 115; openair0_cfg[0].tx_bw = 20e6; openair0_cfg[0].rx_bw = 20e6; break; case 23040000: //openair0_cfg[0].samples_per_packet = 1024; openair0_cfg[0].tx_sample_advance = 113; openair0_cfg[0].tx_bw = 15e6; openair0_cfg[0].rx_bw = 15e6; break; case 15360000: //openair0_cfg[0].samples_per_packet = 1024; openair0_cfg[0].tx_sample_advance = 60; openair0_cfg[0].tx_bw = 10e6; openair0_cfg[0].rx_bw = 10e6; break; case 7680000: //openair0_cfg[0].samples_per_packet = 1024; openair0_cfg[0].tx_sample_advance = 30; openair0_cfg[0].tx_bw = 5e6; openair0_cfg[0].rx_bw = 5e6; break; case 1920000: //openair0_cfg[0].samples_per_packet = 1024; openair0_cfg[0].tx_sample_advance = 20; openair0_cfg[0].tx_bw = 1.4e6; openair0_cfg[0].rx_bw = 1.4e6; break; default: printf("Error: unknown sampling rate %f\n", openair0_cfg[0].sample_rate); exit(-1); break; } printf("tx_sample_advance %d\n", openair0_cfg[0].tx_sample_advance); s->rx_num_channels = openair0_cfg[0].rx_num_channels; s->tx_num_channels = openair0_cfg[0].tx_num_channels; if((s->rx_num_channels == 1 || s->rx_num_channels == 2) && (s->tx_num_channels == 1 || s->tx_num_channels == 2)) { printf("Enabling %d rx and %d tx channel(s) on each device...\n", s->rx_num_channels, s->tx_num_channels); } else { printf("Invalid rx or tx number of channels (%d, %d)\n", s->rx_num_channels, s->tx_num_channels); exit(-1); } for(r = 0; r < s->device_num; r++) { //this is unnecessary -- it will set the correct master clock based on sample rate /* switch ((int) openair0_cfg[0].sample_rate) { case 1920000: s->iris[r]->setMasterClockRate(256 * openair0_cfg[0].sample_rate); break; case 3840000: s->iris[r]->setMasterClockRate(128 * openair0_cfg[0].sample_rate); break; case 7680000: s->iris[r]->setMasterClockRate(64 * openair0_cfg[0].sample_rate); break; case 15360000: s->iris[r]->setMasterClockRate(32 * openair0_cfg[0].sample_rate); break; case 30720000: s->iris[r]->setMasterClockRate(16 * openair0_cfg[0].sample_rate); break; default: printf("Error: unknown sampling rate %f\n", openair0_cfg[0].sample_rate); exit(-1); break; }*/ for(i = 0; i < s->iris[r]->getNumChannels(SOAPY_SDR_RX); i++) { if(i < s->rx_num_channels) { s->iris[r]->setSampleRate(SOAPY_SDR_RX, i, openair0_cfg[0].sample_rate / SAMPLE_RATE_DOWN); #ifdef MOVE_DC printf("Moving DC out of main carrier for rx...\n"); s->iris[r]->setFrequency(SOAPY_SDR_RX, i, "RF", openair0_cfg[0].rx_freq[i] - .75 * openair0_cfg[0].sample_rate); s->iris[r]->setFrequency(SOAPY_SDR_RX, i, "BB", .75 * openair0_cfg[0].sample_rate); #else s->iris[r]->setFrequency(SOAPY_SDR_RX, i, "RF", openair0_cfg[0].rx_freq[i]); #endif set_rx_gain_offset(&openair0_cfg[0], i, bw_gain_adjust); //s->iris[r]->setGain(SOAPY_SDR_RX, i, openair0_cfg[0].rx_gain[i] - openair0_cfg[0].rx_gain_offset[i]); printf("rx gain offset: %f, rx_gain: %f, tx_tgain: %f\n", openair0_cfg[0].rx_gain_offset[i], openair0_cfg[0].rx_gain[i], openair0_cfg[0].tx_gain[i]); if(s->iris[r]->getHardwareInfo()["frontend"].compare(devFE) != 0) { s->iris[r]->setGain(SOAPY_SDR_RX, i, "LNA", openair0_cfg[0].rx_gain[i] - openair0_cfg[0].rx_gain_offset[i]); //s->iris[r]->setGain(SOAPY_SDR_RX, i, "LNA", 0); s->iris[r]->setGain(SOAPY_SDR_RX, i, "LNA1", 30); s->iris[r]->setGain(SOAPY_SDR_RX, i, "LNA2", 17); s->iris[r]->setGain(SOAPY_SDR_RX, i, "TIA", 7); s->iris[r]->setGain(SOAPY_SDR_RX, i, "PGA", 18); s->iris[r]->setGain(SOAPY_SDR_RX, i, "ATTN", 0); } else { s->iris[r]->setGain(SOAPY_SDR_RX, i, "LNA", openair0_cfg[0].rx_gain[i] - openair0_cfg[0].rx_gain_offset[i]); // [0,30] s->iris[r]->setGain(SOAPY_SDR_RX, i, "TIA", 7); // [0,12,6] s->iris[r]->setGain(SOAPY_SDR_RX, i, "PGA", 18); // [-12,19,1] //s->iris[r]->setGain(SOAPY_SDR_RX, i, 50); // [-12,19,1] } s->iris[r]->setDCOffsetMode(SOAPY_SDR_RX, i, true); // move somewhere else } } for(i = 0; i < s->iris[r]->getNumChannels(SOAPY_SDR_TX); i++) { if(i < s->tx_num_channels) { s->iris[r]->setSampleRate(SOAPY_SDR_TX, i, openair0_cfg[0].sample_rate / SAMPLE_RATE_DOWN); #ifdef MOVE_DC printf("Moving DC out of main carrier for tx...\n"); s->iris[r]->setFrequency(SOAPY_SDR_TX, i, "RF", openair0_cfg[0].tx_freq[i] - .75 * openair0_cfg[0].sample_rate); s->iris[r]->setFrequency(SOAPY_SDR_TX, i, "BB", .75 * openair0_cfg[0].sample_rate); #else s->iris[r]->setFrequency(SOAPY_SDR_TX, i, "RF", openair0_cfg[0].tx_freq[i]); #endif if(s->iris[r]->getHardwareInfo()["frontend"].compare(devFE) == 0) { s->iris[r]->setGain(SOAPY_SDR_TX, i, "PAD", openair0_cfg[0].tx_gain[i]); //s->iris[r]->setGain(SOAPY_SDR_TX, i, "PAD", 50); s->iris[r]->setGain(SOAPY_SDR_TX, i, "IAMP", 12); //s->iris[r]->writeSetting("TX_ENABLE_DELAY", "0"); //s->iris[r]->writeSetting("TX_DISABLE_DELAY", "100"); } else { s->iris[r]->setGain(SOAPY_SDR_TX, i, "PAD", openair0_cfg[0].tx_gain[i]); s->iris[r]->setGain(SOAPY_SDR_TX, i, "ATTN", 0); // [-18, 0, 6] dB s->iris[r]->setGain(SOAPY_SDR_TX, i, "IAMP", 6); // [-12, 12, 1] dB //s->iris[r]->setGain(SOAPY_SDR_TX, i, "PAD", 44); //openair0_cfg[0].tx_gain[i]); //s->iris[r]->setGain(SOAPY_SDR_TX, i, "PAD", 35); // [0, 52, 1] dB //s->iris[r]->setGain(SOAPY_SDR_TX, i, "PA1", 17); // 17 ??? dB s->iris[r]->setGain(SOAPY_SDR_TX, i, "PA2", 0); // [0, 17, 17] dB //s->iris[r]->setGain(SOAPY_SDR_TX, i, "PA3", 20); // 33 ??? dB s->iris[r]->writeSetting("TX_ENABLE_DELAY", "0"); s->iris[r]->writeSetting("TX_DISABLE_DELAY", "100"); } // if (openair0_cfg[0].duplex_mode == 0) { // printf("\nFDD: Enable TX antenna override\n"); // s->iris[r]->writeSetting(SOAPY_SDR_TX, i, "TX_ENB_OVERRIDE", // "true"); // From Josh: forces tx switching to be on always transmit regardless of bursts // } } } printf("Actual master clock: %fMHz...\n", (s->iris[r]->getMasterClockRate() / 1e6)); int tx_filt_bw = openair0_cfg[0].tx_bw; int rx_filt_bw = openair0_cfg[0].rx_bw; #ifdef MOVE_DC //the filter is centered around the carrier, so we have to expand it if we have moved the DC tone. tx_filt_bw *= 3; rx_filt_bw *= 3; #endif /* Setting TX/RX BW */ for(i = 0; i < s->tx_num_channels; i++) { if(i < s->iris[r]->getNumChannels(SOAPY_SDR_TX)) { s->iris[r]->setBandwidth(SOAPY_SDR_TX, i, tx_filt_bw); printf("Setting tx bandwidth on channel %zu/%lu: BW %f (readback %f)\n", i, s->iris[r]->getNumChannels(SOAPY_SDR_TX), tx_filt_bw / 1e6, s->iris[r]->getBandwidth(SOAPY_SDR_TX, i) / 1e6); } } for(i = 0; i < s->rx_num_channels; i++) { if(i < s->iris[r]->getNumChannels(SOAPY_SDR_RX)) { s->iris[r]->setBandwidth(SOAPY_SDR_RX, i, rx_filt_bw); printf("Setting rx bandwidth on channel %zu/%lu : BW %f (readback %f)\n", i, s->iris[r]->getNumChannels(SOAPY_SDR_RX), rx_filt_bw / 1e6, s->iris[r]->getBandwidth(SOAPY_SDR_RX, i) / 1e6); } } for(i = 0; i < s->iris[r]->getNumChannels(SOAPY_SDR_TX); i++) { if(i < s->tx_num_channels) { printf("\nUsing SKLK calibration...\n"); s->iris[r]->writeSetting(SOAPY_SDR_TX, i, "CALIBRATE", "SKLK"); } } for(i = 0; i < s->iris[r]->getNumChannels(SOAPY_SDR_RX); i++) { if(i < s->rx_num_channels) { printf("\nUsing SKLK calibration...\n"); s->iris[r]->writeSetting(SOAPY_SDR_RX, i, "CALIBRATE", "SKLK"); } } if(s->iris[r]->getHardwareInfo()["frontend"].compare(devFE) == 0) { for(i = 0; i < s->iris[r]->getNumChannels(SOAPY_SDR_RX); i++) { if(openair0_cfg[0].duplex_mode == 0) { printf("\nFDD: Setting receive antenna to %s\n", s->iris[r]->listAntennas(SOAPY_SDR_RX, i)[1].c_str()); if(i < s->rx_num_channels) { s->iris[r]->setAntenna(SOAPY_SDR_RX, i, "RX"); } } else { printf("\nTDD: Setting receive antenna to %s\n", s->iris[r]->listAntennas(SOAPY_SDR_RX, i)[0].c_str()); if(i < s->rx_num_channels) { s->iris[r]->setAntenna(SOAPY_SDR_RX, i, "TRX"); } } } } //s->iris[r]->writeSetting("TX_SW_DELAY", std::to_string( // -openair0_cfg[0].tx_sample_advance)); //should offset switching to compensate for RF path (Lime) delay -- this will eventually be automated // create tx & rx streamer //const SoapySDR::Kwargs &arg = SoapySDR::Kwargs(); std::map <std::string, std::string> rxStreamArgs; rxStreamArgs["WIRE"] = SOAPY_SDR_CS16; std::vector <size_t> channels; for(i = 0; i < s->rx_num_channels; i++) if(i < s->iris[r]->getNumChannels(SOAPY_SDR_RX)) { channels.push_back(i); } s->rxStream.push_back(s->iris[r]->setupStream(SOAPY_SDR_RX, SOAPY_SDR_CS16, channels));//, rxStreamArgs)); std::vector <size_t> tx_channels = {}; for(i = 0; i < s->tx_num_channels; i++) if(i < s->iris[r]->getNumChannels(SOAPY_SDR_TX)) { tx_channels.push_back(i); } s->txStream.push_back(s->iris[r]->setupStream(SOAPY_SDR_TX, SOAPY_SDR_CS16, tx_channels)); //, arg)); //s->iris[r]->setHardwareTime(0, ""); std::cout << "Front end detected: " << s->iris[r]->getHardwareInfo()["frontend"] << "\n"; for(i = 0; i < s->rx_num_channels; i++) { if(i < s->iris[r]->getNumChannels(SOAPY_SDR_RX)) { printf("RX Channel %zu\n", i); printf("Actual RX sample rate: %fMSps...\n", (s->iris[r]->getSampleRate(SOAPY_SDR_RX, i) / 1e6)); printf("Actual RX frequency: %fGHz...\n", (s->iris[r]->getFrequency(SOAPY_SDR_RX, i) / 1e9)); printf("Actual RX gain: %f...\n", (s->iris[r]->getGain(SOAPY_SDR_RX, i))); printf("Actual RX LNA gain: %f...\n", (s->iris[r]->getGain(SOAPY_SDR_RX, i, "LNA"))); printf("Actual RX PGA gain: %f...\n", (s->iris[r]->getGain(SOAPY_SDR_RX, i, "PGA"))); printf("Actual RX TIA gain: %f...\n", (s->iris[r]->getGain(SOAPY_SDR_RX, i, "TIA"))); if(s->iris[r]->getHardwareInfo()["frontend"].compare(devFE) != 0) { printf("Actual RX LNA1 gain: %f...\n", (s->iris[r]->getGain(SOAPY_SDR_RX, i, "LNA1"))); printf("Actual RX LNA2 gain: %f...\n", (s->iris[r]->getGain(SOAPY_SDR_RX, i, "LNA2"))); } printf("Actual RX bandwidth: %fM...\n", (s->iris[r]->getBandwidth(SOAPY_SDR_RX, i) / 1e6)); printf("Actual RX antenna: %s...\n", (s->iris[r]->getAntenna(SOAPY_SDR_RX, i).c_str())); } } for(i = 0; i < s->tx_num_channels; i++) { if(i < s->iris[r]->getNumChannels(SOAPY_SDR_TX)) { printf("TX Channel %zu\n", i); printf("Actual TX sample rate: %fMSps...\n", (s->iris[r]->getSampleRate(SOAPY_SDR_TX, i) / 1e6)); printf("Actual TX frequency: %fGHz...\n", (s->iris[r]->getFrequency(SOAPY_SDR_TX, i) / 1e9)); printf("Actual TX gain: %f...\n", (s->iris[r]->getGain(SOAPY_SDR_TX, i))); printf("Actual TX PAD gain: %f...\n", (s->iris[r]->getGain(SOAPY_SDR_TX, i, "PAD"))); printf("Actual TX IAMP gain: %f...\n", (s->iris[r]->getGain(SOAPY_SDR_TX, i, "IAMP"))); if(s->iris[r]->getHardwareInfo()["frontend"].compare(devFE) != 0) { printf("Actual TX PA1 gain: %f...\n", (s->iris[r]->getGain(SOAPY_SDR_TX, i, "PA1"))); printf("Actual TX PA2 gain: %f...\n", (s->iris[r]->getGain(SOAPY_SDR_TX, i, "PA2"))); printf("Actual TX PA3 gain: %f...\n", (s->iris[r]->getGain(SOAPY_SDR_TX, i, "PA3"))); } printf("Actual TX bandwidth: %fM...\n", (s->iris[r]->getBandwidth(SOAPY_SDR_TX, i) / 1e6)); printf("Actual TX antenna: %s...\n", (s->iris[r]->getAntenna(SOAPY_SDR_TX, i).c_str())); } } } s->iris[0]->writeSetting("SYNC_DELAYS", ""); for(r = 0; r < s->device_num; r++) { s->iris[r]->setHardwareTime(0, "TRIGGER"); } s->iris[0]->writeSetting("TRIGGER_GEN", ""); for(r = 0; r < s->device_num; r++) { printf("Device timestamp: %f...\n", (s->iris[r]->getHardwareTime("TRIGGER") / 1e9)); } device->priv = s; device->trx_start_func = trx_iris_start; device->trx_write_func = trx_iris_write; device->trx_read_func = trx_iris_read; device->trx_get_stats_func = trx_iris_get_stats; device->trx_reset_stats_func = trx_iris_reset_stats; device->trx_end_func = trx_iris_end; device->trx_stop_func = trx_iris_stop; device->trx_set_freq_func = trx_iris_set_freq; device->trx_set_gains_func = trx_iris_set_gains; device->openair0_cfg = openair0_cfg; s->sample_rate = openair0_cfg[0].sample_rate; // TODO: // init tx_forward_nsamps based iris_time_offset ex if(is_equal(s->sample_rate, (double) 30.72e6)) { s->tx_forward_nsamps = 176; } if(is_equal(s->sample_rate, (double) 15.36e6)) { s->tx_forward_nsamps = 90; } if(is_equal(s->sample_rate, (double) 7.68e6)) { s->tx_forward_nsamps = 50; } LOG_I(HW, "Finished initializing %d Iris device(s).\n", s->device_num); fflush(stdout); return 0; } } /*@}*/
The sequence of real numbers $f_n$ converges to $c$ if and only if the sequence of complex numbers $f_n$ converges to $c$.
Jay @-@ Z appears courtesy of Roc @-@ A @-@ Fella Records and Def Jam Recordings
{-# LANGUAGE FlexibleInstances #-} module Main where import Data.Complex import Debug.Trace data Nav = N Float | S Float | E Float | W Float | L Int | R Int | F Float deriving (Show) data Change = Dir (Complex Float) | Rot (Complex Float) | Move (Complex Float) deriving (Show) degToRot :: Int -> Float degToRot d = fromIntegral (d `div` 90)*pi/2 navToChange :: Nav -> Change navToChange (N m) = Dir $ 0 :+ m navToChange (S m) = Dir $ 0 :+ (-m) navToChange (E m) = Dir $ m :+ 0 navToChange (W m) = Dir $ (-m) :+ 0 navToChange (L d) = Rot $ mkPolar 1.0 (degToRot d) navToChange (R d) = Rot $ mkPolar 1.0 (-(degToRot d)) navToChange (F m) = Move $ mkPolar m 0 instance Read Nav where readsPrec _ ('N':r) = [( N $ read r, "")] readsPrec _ ('S':r) = [( S $ read r, "")] readsPrec _ ('E':r) = [( E $ read r, "")] readsPrec _ ('W':r) = [( W $ read r, "")] readsPrec _ ('L':r) = [( L $ read r, "")] readsPrec _ ('R':r) = [( R $ read r, "")] readsPrec _ ('F':r) = [( F $ read r, "")] getInput :: FilePath -> IO [Nav] getInput = fmap (map read . lines) . readFile dirToComplex :: Nav -> Complex Float dirToComplex (N n) = 0 :+ n dirToComplex (S s) = 0 :+ (-s) dirToComplex (E e) = e :+ 0 dirToComplex (W w) = (-w) :+ 0 dirToComplex _ = undefined solution :: [Nav] -> Int solution navs = round $ abs (dx + ix) + abs (dy + iy) where (dirs, instr) = (filter isDir navs, filter (not . isDir) navs) (dx :+ dy) = sum $ map dirToComplex dirs (ix :+ iy) = instrsToComplex 0 (0 :+ 0) instr isDir :: Nav -> Bool isDir (N _) = True isDir (S _) = True isDir (E _) = True isDir (W _) = True isDir _ = False instrsToComplex :: Float -> Complex Float -> [Nav] -> Complex Float instrsToComplex _ curLoc [] = curLoc instrsToComplex curPhase curLoc ((L d):rest) = instrsToComplex (curPhase + degToRot d) curLoc rest instrsToComplex curPhase curLoc ((R d):rest) = instrsToComplex (curPhase - degToRot d) curLoc rest instrsToComplex curPhase ship ((F m):rest) = instrsToComplex curPhase (ship+rot) rest where rot = mkPolar m curPhase solution2 :: [Nav] -> Int solution2 navs = round $ abs ix + abs iy where (ix :+ iy) = run 0 (10 :+ 1) $ map navToChange navs run :: Complex Float -> Complex Float -> [Change] -> Complex Float run ship _ [] = ship run ship wp (Dir d:rest) = run ship (wp + d) rest run ship wp (Rot r:rest) = run ship (wp*r) rest run ship wp (Move m:rest)= run (ship + m*wp) wp rest main :: IO () main = do getInput "test-input" >>= print . solution getInput "test-input" >>= print . solution2 getInput "input" >>= print . solution getInput "input" >>= print . solution2
------------------------------------------------------------------------ -- The Agda standard library -- -- An explanation about how to use the solver in Tactic.MonoidSolver. ------------------------------------------------------------------------ open import Algebra module README.Tactic.MonoidSolver {a ℓ} (M : Monoid a ℓ) where open Monoid M open import Data.Nat as Nat using (ℕ; suc; zero; _+_) open import Data.Nat.Properties as Properties using (+-0-monoid; +-comm) open import Relation.Binary.Reasoning.Setoid setoid open import Tactic.MonoidSolver using (solve; solve-macro) -- The monoid solver is capable to of solving equations without having -- to specify the equation itself in the proof. example₁ : ∀ x y z → (x ∙ y) ∙ z ≈ x ∙ (y ∙ z) ∙ ε example₁ x y z = solve M -- The solver can also be used in equational reasoning. example₂ : ∀ w x y z → w ≈ x → (w ∙ y) ∙ z ≈ x ∙ (y ∙ z) ∙ ε example₂ w x y z w≈x = begin (w ∙ y) ∙ z ≈⟨ ∙-congʳ (∙-congʳ w≈x) ⟩ (x ∙ y) ∙ z ≈⟨ solve M ⟩ x ∙ (y ∙ z) ∙ ε ∎
module IdrisProject ||| document export plus_reduces : (n : Nat) -> Z + n = n plus_reduces n = Refl export plus_right_id : (n : Nat) -> n + 0 = n plus_right_id Z = Refl plus_right_id (S n) = cong S (plus_right_id n) export plus_reduces_S : (n : Nat) -> (m : Nat) -> n + (S m) = S (n + m) plus_reduces_S Z m = cong S Refl -- cong: congruence, take `f` to show `a = b` iff `(f a) = (f b)` plus_reduces_S (S k) m = cong S (plus_reduces_S k m) export plus_commutes_Z : (m : Nat) -> m = plus m Z plus_commutes_Z 0 = Refl plus_commutes_Z (S k) = cong S (plus_commutes_Z k) export plus_commutes_S : (k : Nat) -> (m : Nat) -> S (plus m k) = plus m (S k) plus_commutes_S k 0 = Refl plus_commutes_S k (S j) = cong S (plus_commutes_S k j) export plus_commutes : (n, m : Nat) -> n + m = m + n plus_commutes Z m = (plus_commutes_Z m) plus_commutes (S k) m = rewrite plus_commutes k m in (plus_commutes_S k m) export sym : forall x, y . (0 rule : x = y) -> y = x sym Refl = Refl export trans : forall x, y, z . (0 l : x = y) -> (0 r : y = z) -> x = z trans Refl Refl = Refl
[STATEMENT] lemma lset_intersect_lnth: "lset xs \<inter> A \<noteq> {} \<Longrightarrow> \<exists>n. enat n < llength xs \<and> lnth xs n \<in> A" [PROOF STATE] proof (prove) goal (1 subgoal): 1. lset xs \<inter> A \<noteq> {} \<Longrightarrow> \<exists>n. enat n < llength xs \<and> lnth xs n \<in> A [PROOF STEP] by (metis disjoint_iff_not_equal in_lset_conv_lnth)
Require Import ssreflect ssrfun ssrbool eqtype ssrnat seq choice fintype. Require Import binomial bigop ssralg poly ssrnum ssrint rat. Require Import polydiv polyorder path interval polyrcf. (** Descates method 2 *) Set Implicit Arguments. Unset Strict Implicit. Unset Printing Implicit Defensive. Import GRing.Theory. Import Num.Theory Num.Def. Local Open Scope ring_scope. (** ** Sign changes *) Section SignChange. Variable R :realDomainType. Implicit Type l: (seq R). Implicit Type p: {poly R}. Definition all_eq0 l := all (fun x => x == 0) l. Definition all_ge0 l:= all (fun x => 0 <= x) l. Definition all_le0 l := all (fun x => x <= 0) l. Definition all_ss a l := all (fun x => 0 <= x * a) l. Definition opp_seq l := [seq - z | z <- l]. Definition filter0 l := [seq z <- l | z != 0]. (** Some helper lemmas *) Lemma product_neg (a b : R): a * b < 0 -> a != 0 /\ b != 0. Proof. case (eqVneq a 0) => ->; first by rewrite mul0r ltrr. case (eqVneq b 0) => -> //; by rewrite mulr0 ltrr. Qed. Lemma square_pos (a: R): a != 0 -> 0 < a * a. Proof. by move => anz; rewrite lt0r sqr_ge0 sqrf_eq0 anz. Qed. Lemma prodNsimpl_ge (a b x: R): b * a < 0 -> 0 <= x * b -> x * a <= 0. Proof. move => pa; move: (square_pos (proj1 (product_neg pa))) => pb. by rewrite - (nmulr_lle0 _ pa) mulrA - (mulrA _ _ b) mulrAC pmulr_lle0. Qed. Lemma prodNsimpl_gt (a b x: R): b * a < 0 -> 0 < x * b -> x * a < 0. Proof. move => pa; move: (square_pos (proj1 (product_neg pa))) => pb. by rewrite - (nmulr_llt0 _ pa) mulrA - (mulrA _ _ b) mulrAC pmulr_llt0. Qed. Lemma prodNsimpl_lt (a b x: R): b * a < 0 -> x * b < 0 -> 0 < x * a. Proof. move => pa; move: (square_pos (proj1 (product_neg pa))) => pb. by rewrite - (nmulr_lgt0 _ pa) mulrA - (mulrA _ _ b) mulrAC pmulr_lgt0. Qed. Lemma all_rev l q: all q l = all q (rev l). Proof. by elim:l => [// | a l hr]; rewrite rev_cons all_rcons /= hr. Qed. Lemma has_split q l: has q l -> exists l1 a l2, [/\ l = l1 ++ a :: l2, q a & all (fun z => ~~(q z)) l1]. Proof. elim:l => // a l Hrec /=; case ha: (q a) => /=. by move => _; exists [::], a, l; split => //. move /Hrec => [l1 [b [l2 [-> pb pc]]]]. by exists (a::l1),b,l2; split => //=; rewrite ha pc. Qed. Lemma has_split_eq l: has (fun z => z != 0) l -> exists l1 a l2, [/\ l = l1 ++ a :: l2, a !=0 & all_eq0 l1]. Proof. move/has_split => [l1 [a [l2 [-> pa pb]]]]; exists l1,a,l2; split => //. by apply /allP => x; move /(allP pb); case (x==0). Qed. Lemma has_split_eq_rev l: has (fun z => z != 0) l -> exists l1 a l2, [/\ l = l1 ++ a :: l2, a !=0 & all_eq0 l2]. Proof. have <- : (has (fun z : R => z != 0)) (rev l) = has (fun z : R => z != 0) l. by elim:l => [// | a l hr]; rewrite rev_cons has_rcons /= hr. move/has_split_eq => [l1 [a [l2 [lv pa pb]]]]; exists (rev l2),a,(rev l1). by rewrite -(cat1s a) catA cats1 -rev_cons -rev_cat -lv revK /all_eq0 -all_rev. Qed. Lemma opp_seqK l: opp_seq (opp_seq l) = l. Proof. by rewrite/opp_seq -map_comp; apply map_id_in => a /=; rewrite opprK. Qed. Definition tail_coef p := p `_(\mu_0 p). Definition lead_tail_coef p := (tail_coef p) * (lead_coef p). Lemma tail_coef0a p: ~~ (root p 0) -> tail_coef p = p`_0. Proof. by move /muNroot; rewrite /tail_coef => ->. Qed. Lemma tail_coef0b p: p`_0 != 0 -> tail_coef p = p`_0. Proof. rewrite - {1} horner_coef0; apply: tail_coef0a. Qed. Lemma tail_coefM (p q: {poly R}): tail_coef (p*q) = (tail_coef p) * (tail_coef q). Proof. rewrite /tail_coef. case pnz: (p!=0); last by rewrite (eqP(negbFE pnz)) mul0r mu0 coef0 mul0r. case qnz: (q!=0); last by rewrite (eqP(negbFE qnz)) mulr0 mu0 coef0 mulr0. rewrite (mu_mul 0 (mulf_neq0 pnz qnz)). move: (mu_spec 0 pnz) (mu_spec 0 qnz); rewrite subr0. set a := (\mu_0 p); set b:= (\mu_0 q); move => [pa v1 ->] [qa v2 ->]. by rewrite mulrACA -exprD 3! coefMXn ! ltnn ! subnn - ! horner_coef0 hornerM. Qed. Lemma lead_tail_coefM (p q: {poly R}): lead_tail_coef (p*q) = (lead_tail_coef p) * (lead_tail_coef q). Proof. by rewrite /lead_tail_coef -mulrACA -tail_coefM lead_coefM. Qed. Lemma lead_tail_coef_opp p: lead_tail_coef (- p) = (lead_tail_coef p). Proof. rewrite - mulrN1 lead_tail_coefM; set one := (X in _ * lead_tail_coef(X)). suff : lead_tail_coef one = 1 by move ->; rewrite mulr1. have ->: one = ((-1)%:P) by rewrite polyC_opp. by rewrite /lead_tail_coef /tail_coef lead_coefC mu_polyC coefC mulN1r opprK. Qed. Lemma mu_spec_supp p: p != 0 -> exists q, [/\ p = q * 'X^ (\mu_0 p), (~~ root q 0), lead_coef p = lead_coef q, tail_coef p = tail_coef q & tail_coef q = q`_0]. Proof. move /(mu_spec 0) => [q pa]; set n := (\mu_0 p) => ->; exists q. rewrite lead_coefM tail_coefM {1 2} subr0 (eqP (monicXn R n)) mulr1 /tail_coef. by rewrite mu_exp mu_XsubC mul1n subr0 coefXn eqxx mulr1 (muNroot pa). Qed. Lemma tail_coefE p: tail_coef p = (head 0 (filter0 p)). Proof. have [-> |] := (eqVneq p 0); first by rewrite /tail_coef mu0 coef0 polyseq0 /=. move /(mu_spec_supp) => [q [pa pb pc pd pe]]; rewrite /filter0. case (eqVneq q 0) => qnz; first by move: pb; rewrite qnz root0. have q0nz: q`_0 != 0 by rewrite - horner_coef0. rewrite pd pe pa polyseqMXn// -cat_nseq filter_cat (eq_in_filter (a2 := pred0)). by rewrite filter_pred0 cat0s nth0; move: q0nz; case q; case => //= a l _ ->. have /allP h: all (pred1 (0:R)) (nseq (\mu_0 p) 0) by rewrite all_pred1_nseq eqxx orbT. by move => x /h /= ->. Qed. Fixpoint changes (s : seq R) : nat := (if s is a :: q then (a * (head 0 q) < 0)%R + changes q else 0)%N. Definition schange (l: seq R) := changes (filter0 l). Lemma schange_sgr l: schange l = schange [seq sgr z | z <- l]. Proof. rewrite /schange /filter0 filter_map; set s1 := [seq z <- l | z != 0]. set s := (filter (preim _ _)); have -> : s l = s1. apply: eq_in_filter => x xl /=. by rewrite sgr_def; case xz: (x!=0); rewrite ?mulr0n ?eqxx ?mulr1n ?signr_eq0. elim: s1 => [ // | a l1 /= ->]; case l1 => /=; first by rewrite !mulr0. by move => b l2; rewrite - sgrM sgr_lt0. Qed. Lemma schange_deriv p (s := (schange p)) (s':= schange p^`()): (s = s' \/ s = s'.+1). Proof. rewrite /s/s'. have [-> | pnz] := (eqVneq p 0); first by rewrite deriv0; left. move: pnz; rewrite - size_poly_gt0 => pz. have eq: polyseq p = p`_0 :: behead p by move: pz; case p => q /=; case q => //. have aux: forall i, p^`()`_i = (nth 0 (behead p)) i *+ i.+1. by move => i; rewrite coef_deriv nth_behead. rewrite schange_sgr (schange_sgr p^`()). have <-: [seq Num.sg z | z <- (behead p)] = [seq Num.sg z | z <- p^`()]. have aux1: size (behead p) = size p^`() by rewrite size_deriv {2} eq. apply: (eq_from_nth (x0 :=0)); first by rewrite !size_map. move => i; rewrite size_map => iz;rewrite (nth_map 0)// (nth_map 0) -?aux1//. by rewrite coef_deriv nth_behead sgrMn mul1r. rewrite eq /= /schange/filter0/filter;case h: (Num.sg p`_0 != 0); last by left. simpl; case h': (_ < 0); [ by rewrite addSn; right | by left]. Qed. Lemma schange0_odd l: last 0 l != 0 -> odd (schange l + (0 < head 0 (filter0 l) * last 0 l)%R). Proof. rewrite /schange. have -> : filter0 l = [seq z <- 0::l | z != 0]. by rewrite /filter0 {2} /filter eqxx. rewrite (lastI 0 l); set b := (last 0 l) => bnz; rewrite filter_rcons bnz. set s := [seq z <- belast 0 l | z != 0]. have: all (fun z => z != 0) s by apply : filter_all. elim: s; first by rewrite /= mulr0 ltrr square_pos //. move => c s /=; set C:= changes _; set d:= head 0 _ => hr /andP [cnz etc]. have dnz: d != 0 by move: etc; rewrite /d; case s => // s' l' /= /andP []. rewrite addnC addnA addnC; move: (hr etc). rewrite -sgr_gt0 - (sgr_gt0 (c*b)) - sgr_lt0 ! sgrM. rewrite /sgr - if_neg - (if_neg (c==0))- (if_neg (b==0)) bnz dnz cnz. by case (d<0); case (b<0); case (c<0); rewrite ?mulrNN ? mulr1 ?mul1r ?ltr01 ?ltrN10 ? ltr10 ? ltr0N1 ?addn0 ? addnS ?addn0//=; move => ->. Qed. Lemma schange_odd p: p != 0 -> odd (schange p + (0 < lead_tail_coef p)%R). Proof. rewrite - lead_coef_eq0 /lead_tail_coef tail_coefE /schange lead_coefE nth_last. by move => h; rewrite schange0_odd. Qed. End SignChange. Section SignChangeRcf. Variable R :rcfType. Implicit Type (p:{poly R}). Lemma noproots_cs p: (forall x, 0 <x -> ~~ root p x) -> 0 < lead_tail_coef p. Proof. move => h. have [pz |pnz]:= (eqVneq p 0); first by move: (h _ ltr01); rewrite pz root0. move: (mu_spec_supp pnz) => [q [pa pb pc pd pe]]. have: {in `[0, +oo[, (forall x, ~~ root q x)}. move => x; rewrite inE andbT; rewrite le0r; case/orP; first by move=>/eqP ->. by move /h; rewrite pa rootM negb_or => /andP []. move/sgp_pinftyP => ha; move: (ha 0); rewrite inE lerr andbT /= => H. rewrite /lead_tail_coef pc pd pe - sgr_gt0 sgrM -/(sgp_pinfty q). by rewrite - horner_coef0 - H // - sgrM sgr_gt0 lt0r sqr_ge0 mulf_neq0. Qed. Definition fact_list p s q := [/\ p = (\prod_(z <- s) ('X - z.1%:P) ^+ (z.2)) * q, (all (fun z => 0 < z) [seq z.1 | z <- s]), (sorted >%R [seq z.1 | z <- s]) & (all (fun z => (0<z)%N ) [seq z.2 | z <- s])]. Lemma poly_split_fact p : { sq : (seq (R * nat) * {poly R}) | fact_list p (sq.1) (sq.2) & ( (p != 0 -> (forall x, 0 <x -> ~~ root (sq.2) x)) /\ (p = 0 -> sq.1 = [::] /\ sq.2 = 0)) }. Proof. case pnz: (p != 0); last first. by exists ([::],p) => //; split => //; rewrite big_nil mul1r. pose sa := [seq z <- rootsR p | 0 <z ]. pose sb := [seq (z, \mu_z p) | z <- sa]. have sav: sa = [seq z.1 | z <- sb]. by rewrite /sb - map_comp; symmetry; apply map_id_in => a. have pa: (all (fun z => 0 < z) [seq z.1 | z <- sb]). by rewrite - sav; apply /allP => x; rewrite mem_filter => /andP []. have pb : (sorted >%R [seq z.1 | z <- sb]). rewrite - sav. apply: sorted_filter => //; [apply: ltr_trans |apply: sorted_roots]. have pc: (all (fun z => (0<z)%N ) [seq z.2 | z <- sb]). apply /allP => x /mapP [t] /mapP [z]; rewrite mem_filter => /andP [z0 z2]. move => -> -> /=; rewrite mu_gt0 //; apply: (root_roots z2). suff: { q | p = (\prod_(z <- sa) ('X - z%:P) ^+ (\mu_z p)) * q & forall x : R, 0 < x -> ~~ root q x}. move => [q qa qb]; exists (sb,q) => //. by split => //;rewrite qa /= big_map; congr (_ * _); apply eq_big. by split => // pz; move: pnz; rewrite pz eqxx. clear sb sav pa pb pc. have: all (root p) sa. apply/allP=> x;rewrite mem_filter =>/andP [_]; apply /root_roots. have: uniq sa by apply:filter_uniq; apply: uniq_roots. have: forall x, root p x -> 0 < x -> (x \in sa). by move=> x rx xp;rewrite mem_filter xp -(roots_on_rootsR pnz) rx. move: sa=> s. elim: s p pnz=>[p _ H _ _| ]. exists p; first by by rewrite big_nil mul1r. move => x xp;apply/negP =>nr; by move: (H _ nr xp). move => a l Hrec /= p p0 rp /andP [nal ul] /andP [ap rap]. have [q rqa pv] := (mu_spec a p0). case q0: (q != 0); last by move:p0; rewrite pv (eqP(negbFE q0)) mul0r eqxx. have q1 x: root q x -> 0 < x -> x \in l. move=> rx xp; case xa: (x == a); first by rewrite -(eqP xa) rx in rqa. by rewrite -[_ \in _]orFb -xa -in_cons rp // pv rootM rx. have q2: all (root q) l. apply/allP=> x xl. case xa: (x ==a); first by move: nal; rewrite - (eqP xa) xl. move /(allP rap): xl. by rewrite pv rootM -[\mu__ _]prednK ?mu_gt0 // root_exp_XsubC xa orbF. have [r qv rq]:= (Hrec q q0 q1 ul q2). exists r => //; rewrite {1} pv {1} qv mulrAC; congr (_ * _). rewrite big_cons mulrC; congr (_ * _). rewrite 2! (big_nth 0) 2! big_mkord; apply: eq_bigr => i _. set b := l`_i;congr (_ ^+ _). have rb: root q b by apply /(allP q2); rewrite mem_nth //. have nr: ~~ root (('X - a%:P) ^+ \mu_a p) b. rewrite /root horner_exp !hornerE expf_neq0 // subr_eq0; apply /eqP => ab. by move: rqa; rewrite - ab rb. rewrite pv mu_mul ? (muNroot nr) //. by rewrite mulf_neq0 // expf_neq0 // monic_neq0 // monicXsubC. Qed. Definition pos_roots p := (s2val (poly_split_fact p)).1. Definition pos_cofactor p := (s2val (poly_split_fact p)).2. Definition npos_roots p := (\sum_(i <- (pos_roots p)) (i.2)) %N. Lemma pos_split1 p (s := pos_roots p) (q:= pos_cofactor p): p != 0 -> [/\ fact_list p s q, (forall x, 0 <x -> ~~ root q x) & q != 0]. Proof. move => h; rewrite /s/q /pos_roots / pos_cofactor. move: (poly_split_fact p) => H; move: (s2valP' H) (s2valP H) => [h1 _] h2. split => //; first by apply: h1. by apply/eqP => qz; move:h2 => [] pv; move: h; rewrite {1} pv qz mulr0 eqxx. Qed. Lemma monicXsubCe (c:R) i : ('X - c%:P) ^+ i \is monic. Proof. apply:monic_exp; exact: monicXsubC. Qed. Lemma monic_prod_XsubCe I rI (P : pred I) (F : I -> R) (G : I -> nat): \prod_(i <- rI | P i) ('X - (F i)%:P )^+ (G i) \is monic. Proof. by apply: monic_prod => i _; exact: monicXsubCe. Qed. Lemma npos_root_parity p: p != 0 -> odd (npos_roots p + (0< lead_tail_coef p)%R). Proof. move => pnz; move: (pos_split1 pnz) => [[pv pb pc] pd qp qnz]. rewrite {2} pv;set r := \prod_(z <- _) _. have rm: r \is monic by apply:monic_prod_XsubCe. rewrite lead_tail_coefM (pmulr_lgt0 _ (noproots_cs qp)) /lead_tail_coef. move: (refl_equal (sgr r`_0)); rewrite - {2} horner_coef0 horner_prod. set X := \prod_(z <- _) _; have ->: X = \prod_(i <- pos_roots p) (- i.1)^+ i.2. by apply: eq_big => // i _; rewrite horner_exp hornerXsubC sub0r. have ->: Num.sg (\prod_(i <- pos_roots p) (- i.1) ^+ i.2) = (-1) ^+ \sum_(i <- pos_roots p) (i.2). move: pb; elim (pos_roots p) => [ _ | i rr /= Hr /andP [pa pb]]. by rewrite !big_nil sgr1. by rewrite !big_cons sgrM sgrX Hr // sgrN (gtr0_sg pa) exprD. move => aux. case (eqVneq r`_0 0) => nr0. by move: aux; rewrite nr0 sgr0 => /eqP; rewrite eq_sym signr_eq0. rewrite (eqP rm) mulr1 (tail_coef0b nr0) -sgr_gt0 aux - signr_odd signr_gt0. by case h: (odd(npos_roots p)); [ rewrite addn0 | rewrite addn1 /= h]. Qed. Lemma size_prod_XsubCe I rI (F : I -> R) (G : I -> nat) : size (\prod_(i <- rI) ('X - (F i)%:P)^+ (G i)) = (\sum_(i <- rI) (G i)).+1. Proof. elim: rI => [| i r /=]; rewrite ? big_nil ? size_poly1 // !big_cons. rewrite size_monicM ? monicXsubCe ? monic_neq0 // ?monic_prod_XsubCe //. by rewrite size_exp_XsubC => ->; rewrite addSn addnS. Qed. Lemma schange_parity p: p != 0 -> odd (npos_roots p) = odd (schange p). Proof. move => pnz. move: (npos_root_parity pnz) (schange_odd pnz). case h: (0 < lead_tail_coef p)%R; last by rewrite !addn0 => ->. by rewrite ! addn1 /= => /negbTE -> /negbTE ->. Qed. Lemma pos_split_deg p: p != 0 -> size p = ((npos_roots p) + (size (pos_cofactor p))) %N. Proof. move /pos_split1 => [[pa _ _ ] _ _ pb]. by rewrite {1} pa size_monicM // ? monic_prod_XsubCe // size_prod_XsubCe addSn. Qed. Lemma npos_roots0 p: (p != 0 /\ p^`() != 0) \/ (npos_roots p = 0)%N. Proof. case (eqVneq p 0) => pnz. right; rewrite /npos_roots /pos_roots. move: (poly_split_fact p) => H; move: (s2valP' H) (s2valP H) => [_ h1] _. by rewrite (proj1 (h1 pnz)) // big_nil. move: (pos_split1 pnz) => [[pa pb pc pd] pe pf]. case (leqP (size p) 1%N) => sp; [right | left]. move: pf sp; rewrite (pos_split_deg pnz) - size_poly_gt0. case: (size (pos_cofactor p)) => //. by move => m _; rewrite addnS ltnS leqn0 addn_eq0 => /andP [/eqP -> _]. split => //. by rewrite -size_poly_eq0 (size_deriv p); move: sp;case: (size p)=> //; case. Qed. Lemma coprimep_prod p I l (F: I-> {poly R}): (all (fun z => coprimep p (F z)) l) -> coprimep p (\prod_(z <- l) (F z)). Proof. elim l; first by rewrite big_nil /= coprimep1. by move => b m Hrec /andP [ap /Hrec]; rewrite big_cons coprimep_mulr ap => ->. Qed. Lemma Gauss_dvdp_prod p (I:eqType) (l: seq I) (F: I-> {poly R}): (all (fun i => (F i) %| p) l) -> (uniq [seq F i | i <- l]) -> (forall i j, i \in l -> j \in l -> (i == j) || coprimep (F i) (F j)) -> \prod_(i <- l) (F i) %| p. Proof. move: p; elim: l. by move => p _ _ _; rewrite big_nil dvd1p. move => a l Hrec p /= /andP [ap dr] /andP [al ul] etc. have aa: coprimep (F a) (\prod_(j <- l) F j). apply: coprimep_prod; apply /allP => x xl. have xal: x \in a :: l by rewrite inE xl orbT. have aa: F x \in [seq F i | i <- l] by apply/mapP; exists x. by move: al;case/orP: (etc _ _ (mem_head a l) xal)=> // /eqP ->; rewrite aa. rewrite big_cons Gauss_dvdp // ap /= Hrec // => i j il jl. by apply: etc; rewrite inE ? il ? jl orbT. Qed. Lemma Gauss_dvdp_prod2 p (l: seq (R * nat)): (all (fun z => ('X - z.1%:P)^+ (z.2) %| p) l) -> (uniq [seq z.1 | z <- l]) -> \prod_(i <- l) ('X - i.1%:P)^+ (i.2) %| p. Proof. move => pa pb. set l2:= [seq z <- l | z.2 != 0%N]. have qc: all (fun z => z.2 !=0%N) l2 by apply: filter_all. have qa:all (fun z => ('X - (z.1)%:P) ^+ z.2 %| p) l2. by apply /allP => x; rewrite mem_filter => /andP [_] /(allP pa). have qb: uniq [seq z.1 | z <- l2]. move: pb;rewrite /l2; elim l => [|x s IHs] //= /andP [Hx Hs]. case (x.2 == 0%N); rewrite /= IHs // andbT; apply /negP. move /mapP => [y]; rewrite mem_filter => /andP [_ ys] xy. move: Hx; rewrite xy; move/negP;case; apply /mapP; exists y => //. have ->: \prod_(i <- l) ('X - (i.1)%:P) ^+ i.2 = \prod_(i <- l2) ('X - (i.1)%:P) ^+ i.2. rewrite big_filter [X in _ = X] big_mkcond /=; apply: eq_bigr => i _. by case h: (i.2 == 0%N) => //=; rewrite (eqP h) expr0. apply:Gauss_dvdp_prod => //. rewrite map_inj_in_uniq. apply: (map_uniq qb). move => i j il jl /= eq1. rewrite (surjective_pairing i) (surjective_pairing j). move: (size_exp_XsubC i.2 (i.1)); rewrite eq1 size_exp_XsubC. move /eq_add_S => ->. have: root (('X - (i.1)%:P) ^+ i.2) (i.1). move: (allP qc _ il); rewrite -lt0n => /prednK <-. by rewrite root_exp_XsubC eqxx. rewrite eq1; move: (allP qc _ jl); rewrite -lt0n => /prednK <-. by rewrite root_exp_XsubC => /eqP ->. move => i j il2 jl2. pose zz:(R * nat) := (0, 0%N). move: (nth_index zz il2)(nth_index zz jl2). move: il2 jl2; rewrite -(index_mem) -(index_mem). set i1 := index i l2; set j1 := index j l2 => ra rb rc rd. set l3 := [seq z.1 | z <- l2]. have ss: size l2 = size l3 by rewrite /l3 size_map. move: (ra) (rb);rewrite ss => ra' rb'. move: (nth_uniq 0 ra' rb' qb) => aux. case eqq: (i1 == j1). by rewrite - rc - rd (eqP eqq) eqxx. apply /orP; right. rewrite coprimep_expl // coprimep_expr // coprimep_XsubC root_XsubC. by rewrite - rc - rd -(nth_map zz 0) // -(nth_map zz 0) // -/l3 eq_sym aux eqq. Qed. Lemma sorted_prop (s: seq R) i j: sorted >%R s -> (i < size s)%N -> (j < size s)%N -> (i < j)%N -> s`_i < s`_j. Proof. move: i j; elim: s => // a l Hrec i j /= pal; case: i; last first. move => i il; case: j => // j jl /=; rewrite ltnS; apply: Hrec => //. apply: (path_sorted pal). clear Hrec; case: j => // j _ jl _;move: a j jl pal. elim:l => // a l Hrec b j /=;case: j => [_ | j jl]; move /andP => [pa pb] //=. by apply:(ltr_trans pa); apply /Hrec. Qed. Lemma pos_root_deriv p: ((npos_roots p) <= (npos_roots p^`()).+1) %N. Proof. case (npos_roots0 p); last by move => ->. move => [pnz dnz]. move: (pos_split1 pnz) => [[pa pb pc pd] pe pf]. set s := pos_roots p; set q := pos_cofactor p. move: (erefl (pos_roots p)); rewrite -{2} /s; case s. by rewrite /npos_roots;move => ->; rewrite big_nil. move=> a l eq1. set r:= [seq z.1 | z <- s]; set r1:= a.1; set rs:= [seq z.1 | z <- l]. set rd:= [seq z.2 | z <- pos_roots p]. have ss: size s = (size l).+1 by rewrite /s eq1. pose zz:(R * nat) := (0, 0%N). have p0: forall i, (i < size s)%N -> (nth zz s i).2 \in rd. move => i qis; apply /mapP; exists (nth zz s i)=> //. by apply /(nthP zz); exists i. have p1: forall i: 'I_(size l)%N, {c : R | c \in `] ((r1::rs)`_i), (rs`_i)[ & (p^`()).[c] = 0}. move: pc;rewrite eq1 /=; move /(pathP 0); rewrite size_map => h. move => [i isl]; move: (h _ isl); rewrite -/r1 -/rs => lt1. have ha: forall j, (j< size s)%N -> (root p (r1 :: rs)`_j). move => j js; rewrite pa rootM /root horner_prod; apply /orP; left. rewrite (big_nth zz) big_mkord -/s (bigD1 (Ordinal js)) //= {1} /s eq1 /=. rewrite horner_exp hornerXsubC -(nth_map _ 0) /= -?ss // subrr expr0n. by rewrite (gtn_eqF (allP pd _ (p0 _ js))) mul0r eqxx. have rp: p.[(a.1 :: rs)`_i] = p.[rs`_i]. have ->: rs`_i = (r1 :: rs)`_(i.+1) by []. by rewrite (eqP (ha _ _ )) ? (eqP (ha _ _ )) //; rewrite ss ltnS // ltnW. exact: (rolle lt1 rp). set l2 := [seq (s2val (p1 i), 1%N) | i <- (enum 'I_(size l)) ]. set l3 := [seq (z.1, z.2.-1) | z <- pos_roots p]. set f2 := \prod_(z <- l2) ('X - (z.1)%:P) ^+ (z.2). set f3 := \prod_(z <- l3) ('X - (z.1)%:P) ^+ (z.2). have p2: forall t, (t < size s)%N -> (r1 :: rs)`_t = (nth zz s t).1. by move => t ts; rewrite - (nth_map zz 0) // /s eq1. have ->: (npos_roots p = (\sum_(i <- l2++l3)i.2).+1)%N. rewrite big_cat - addSn /l3 /l2 ! big_map sum1_card cardE size_enum_ord - ss. rewrite - (sum1_size s) -/s - big_split /=. rewrite /npos_roots ! (big_nth zz) ! big_mkord; apply: eq_bigr. by move => [i iv] _; rewrite add1n (prednK (allP pd _ (p0 _ iv))). have p4: (all (fun z => 0 < z) [seq z0.1 | z0 <- l2 ++ l3]). have aa: forall t, t \in s -> 0 < t.1. by move => t ts; apply: (allP pb); apply /mapP; exists t. apply /allP => x /mapP [y]; rewrite mem_cat => /orP []; last first. by move/mapP => [t /aa h -> ->]. move/mapP => [t] _ -> -> /=; move: (s2valP (p1 t)). rewrite itv_boundlr => /= /andP [lt1 _]; apply: ltr_trans lt1. have ts: (t < size s)%N by rewrite /s eq1 /= ltnS ltnW. by rewrite (p2 _ ts); apply: aa;rewrite mem_nth. have pcc: forall i j, (i <size s)%N -> (j <size s)%N -> (nth zz s i).1 < (nth zz s j).1 -> (i < j)%N. move => i j il jl;case (ltngtP j i) => //; last by move => ->; rewrite ltrr. rewrite - (ltr_asym (nth zz s i).1 (nth zz s j).1); move => ij -> /=. move: pc;rewrite -p2 // - p2 // eq1; set s1 := [seq z.1 | z <- a::l] => ha. have ss1 : size s = size s1 by rewrite /s1 ss size_map. rewrite ss1 in il jl; exact: (sorted_prop ha jl il ij). have p5: f3 %| p^`(). apply:Gauss_dvdp_prod2. apply /allP => x /mapP [y ys -> /=]. have: (('X - (y.1)%:P) ^+ y.2) %| p. rewrite pa; apply:dvdp_mulr. move: (nth_index zz ys) => h; move: ys; rewrite - index_mem => ys. by rewrite (big_nth zz) big_mkord (bigD1 (Ordinal ys)) //= h dvdp_mulIl. move /dvdpP => [q1 ->]; rewrite derivM; apply:dvdp_add;apply:dvdp_mull. set e := y.2; case e => // n /=; rewrite exprS; apply : dvdp_mulIr. rewrite deriv_exp - mulrnAl; apply : dvdp_mulIr. rewrite /l3 -/s -map_comp; apply: (sorted_uniq (@ltr_trans R) (@ltrr R) pc). have xx: forall i: 'I_ (size l), [/\ (i <= size l)%N, (i < size s)%N & (i.+1 < size s)%N]. by move => i; rewrite ss !ltnS ltnW. have p6: f2 %| p^`(). apply:Gauss_dvdp_prod2. apply/allP => x /mapP [t] _ -> /=; move: (s2valP' (p1 t)). by rewrite dvdp_XsubCl /root=> ->; rewrite eqxx. have ->:[seq z.1 | z <- l2] = [seq s2val (p1 i)| i <- enum 'I_(size l)]. by rewrite /l2 - map_comp. rewrite map_inj_uniq; first by apply: enum_uniq. move => i j /= h. move: (xx i) (xx j)=> [isl1 isl isl2] [jsl1 jsl jsl2]. apply: val_inj => /=; apply: anti_leq. move: (s2valP (p1 i)) (s2valP (p1 j)); rewrite !itv_boundlr => /=. rewrite h; move/andP => [lt1 lt2] /andP [lt3 lt4]. move: (ltr_trans lt1 lt4) (ltr_trans lt3 lt2). have ->: rs`_i = (r1 :: rs)`_(i.+1) by []. have ->: rs`_j = (r1 :: rs)`_(j.+1) by []. rewrite !p2 // ? ss ? ltnS //. move /(pcc _ _ isl jsl2) => sa /(pcc _ _ jsl isl2). by rewrite ltnS => ->; rewrite -ltnS sa. have p7: coprimep f2 f3. apply: coprimep_prod; apply /allP => x xl3. rewrite coprimep_sym; apply /coprimep_prod; apply /allP => y yl2. apply:coprimep_expl; apply: coprimep_expr. rewrite coprimep_XsubC root_XsubC; apply /negP => /eqP. move: xl3 => /mapP [k ks] -> /=. rewrite - (nth_index zz ks) -/s; set kis := (index k s). move: yl2; move /mapP => [i] _ -> /= h1. move: (s2valP (p1 i)); rewrite !itv_boundlr => /=; rewrite h1; clear h1. have ->: rs`_i = (r1 :: rs)`_(i.+1) by []. move: (xx i) => [il0 il1 il2]. have il3: (kis < size s)%N by rewrite index_mem. rewrite ! p2 // => /andP [la lb]. move: (pcc _ _ il1 il3 la) (pcc _ _ il3 il2 lb). by rewrite ltnS => lc ld; move: (leq_trans lc ld); rewrite ltnn. have : (f2 * f3) %| p^`() by rewrite Gauss_dvdp // p6 p5. move /dvdpP => [q1]; rewrite mulrC => sd. have sa: p^`() = \prod_(z <- l2++l3) ('X - (z.1)%:P) ^+ z.2 * q1. by rewrite big_cat. move: (pos_split1 dnz) => [[qa qb qc qd] qe qf]. set Fa := \prod_(z <- l2 ++l3) ('X - (z.1)%:P) ^+ z.2. set Fb := \prod_(z <- pos_roots p^`()) ('X - (z.1)%:P) ^+ z.2. set q2:= pos_cofactor p^`(). have Fbm: Fb \is monic by apply:monic_prod_XsubCe. suff cp: coprimep Fa q2. move: (Gauss_dvdpl Fb cp); rewrite - qa {1} sa dvdp_mulIl => h. move: (dvdp_leq (monic_neq0 Fbm) (esym h)). by rewrite /npos_roots ! size_prod_XsubCe. rewrite/Fa coprimep_sym;apply/coprimep_prod /allP => x xl. rewrite coprimep_expr// coprimep_XsubC qe //. by apply (allP p4); apply /mapP; exists x. Qed. Lemma descartes_bis p: p != 0 -> (odd (npos_roots p) = odd (schange p) /\ ((npos_roots p) <= (schange p)) %N). Proof. move => pa; split; first by apply:schange_parity. move: p {2}(size p) (leqnn (size p)) pa => p n; move:p; elim:n. by move => p;rewrite size_poly_leq0 => ->. move => n Hrec p spn pnz. move: (schange_parity pnz) => od. case (npos_roots0 p); [move => [_ dnz] | by move => ->]. move: (leq_trans (lt_size_deriv pnz) spn); rewrite ltnS=> spln. move:(Hrec _ spln dnz); rewrite - ltnS => /(leq_trans (pos_root_deriv p)) eq3. move: od; case (schange_deriv p); move => -> //; move: eq3;set s := schange _. by rewrite leq_eqVlt ltnS;case /orP => // /eqP -> /=;case (odd _). Qed. End SignChangeRcf.
/* ----------------------------------------------------------------------------- * Copyright 2021 Jonathan Haigh * SPDX-License-Identifier: MIT * ---------------------------------------------------------------------------*/ #ifndef SQ_INCLUDE_GUARD_system_linux_SqTypeSchemaImpl_h_ #define SQ_INCLUDE_GUARD_system_linux_SqTypeSchemaImpl_h_ #include "core/typeutil.h" #include "system/SqTypeSchema.gen.h" #include "system/schema.h" #include <gsl/gsl> namespace sq::system::linux { class SqTypeSchemaImpl : public SqTypeSchema<SqTypeSchemaImpl> { public: explicit SqTypeSchemaImpl(const TypeSchema &type_schema); SQ_ND Result get_name() const; SQ_ND Result get_doc() const; SQ_ND Result get_fields() const; SQ_ND Primitive to_primitive() const override; private: gsl::not_null<const TypeSchema *> type_schema_; }; } // namespace sq::system::linux #endif // SQ_INCLUDE_GUARD_system_linux_SqTypeSchemaImpl_h_
\graphicspath{{chapter2-background/images/}} \chapter{Contexte} \label{sec:background}
[STATEMENT] lemma DSourcesA22_L1: "DSources level1 sA22 = {sA11, sA41}" [PROOF STATE] proof (prove) goal (1 subgoal): 1. DSources level1 sA22 = {sA11, sA41} [PROOF STEP] by (simp add: DSources_def AbstrLevel1, auto)
From Domains Require Import Preamble. Declare Scope preorder_scope. Delimit Scope preorder_scope with P. Open Scope preorder_scope. HB.mixin Record PreorderOfType A := {lt : A → A → Prop; ltR : ∀ x, lt x x; ltT : ∀ x y z, lt x y → lt y z → lt x z}. HB.structure Definition Preorder := {A of PreorderOfType A}. Lemma ltT' {A : Preorder.type} : ∀ x y z : A, lt y z → lt x y → lt x z. Proof. by move=>???/[swap]; exact: ltT. Qed. Infix "≤" := lt : preorder_scope.
/- Copyright (c) 2020 Yury G. Kudryashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury G. Kudryashov, Patrick Massot -/ import Mathlib.PrePort import Mathlib.Lean3Lib.init.default import Mathlib.data.set.intervals.basic import Mathlib.data.equiv.mul_add import Mathlib.algebra.pointwise import Mathlib.PostPort universes u namespace Mathlib /-! # (Pre)images of intervals In this file we prove a bunch of trivial lemmas like “if we add `a` to all points of `[b, c]`, then we get `[a + b, a + c]`”. For the functions `x ↦ x ± a`, `x ↦ a ± x`, and `x ↦ -x` we prove lemmas about preimages and images of all intervals. We also prove a few lemmas about images under `x ↦ a * x`, `x ↦ x * a` and `x ↦ x⁻¹`. -/ namespace set /-! ### Preimages under `x ↦ a + x` -/ @[simp] theorem preimage_const_add_Ici {G : Type u} [ordered_add_comm_group G] (a : G) (b : G) : (fun (x : G) => a + x) ⁻¹' Ici b = Ici (b - a) := ext fun (x : G) => iff.symm sub_le_iff_le_add' @[simp] theorem preimage_const_add_Ioi {G : Type u} [ordered_add_comm_group G] (a : G) (b : G) : (fun (x : G) => a + x) ⁻¹' Ioi b = Ioi (b - a) := ext fun (x : G) => iff.symm sub_lt_iff_lt_add' @[simp] theorem preimage_const_add_Iic {G : Type u} [ordered_add_comm_group G] (a : G) (b : G) : (fun (x : G) => a + x) ⁻¹' Iic b = Iic (b - a) := ext fun (x : G) => iff.symm le_sub_iff_add_le' @[simp] theorem preimage_const_add_Iio {G : Type u} [ordered_add_comm_group G] (a : G) (b : G) : (fun (x : G) => a + x) ⁻¹' Iio b = Iio (b - a) := ext fun (x : G) => iff.symm lt_sub_iff_add_lt' @[simp] theorem preimage_const_add_Icc {G : Type u} [ordered_add_comm_group G] (a : G) (b : G) (c : G) : (fun (x : G) => a + x) ⁻¹' Icc b c = Icc (b - a) (c - a) := sorry @[simp] theorem preimage_const_add_Ico {G : Type u} [ordered_add_comm_group G] (a : G) (b : G) (c : G) : (fun (x : G) => a + x) ⁻¹' Ico b c = Ico (b - a) (c - a) := sorry @[simp] theorem preimage_const_add_Ioc {G : Type u} [ordered_add_comm_group G] (a : G) (b : G) (c : G) : (fun (x : G) => a + x) ⁻¹' Ioc b c = Ioc (b - a) (c - a) := sorry @[simp] theorem preimage_const_add_Ioo {G : Type u} [ordered_add_comm_group G] (a : G) (b : G) (c : G) : (fun (x : G) => a + x) ⁻¹' Ioo b c = Ioo (b - a) (c - a) := sorry /-! ### Preimages under `x ↦ x + a` -/ @[simp] theorem preimage_add_const_Ici {G : Type u} [ordered_add_comm_group G] (a : G) (b : G) : (fun (x : G) => x + a) ⁻¹' Ici b = Ici (b - a) := ext fun (x : G) => iff.symm sub_le_iff_le_add @[simp] theorem preimage_add_const_Ioi {G : Type u} [ordered_add_comm_group G] (a : G) (b : G) : (fun (x : G) => x + a) ⁻¹' Ioi b = Ioi (b - a) := ext fun (x : G) => iff.symm sub_lt_iff_lt_add @[simp] theorem preimage_add_const_Iic {G : Type u} [ordered_add_comm_group G] (a : G) (b : G) : (fun (x : G) => x + a) ⁻¹' Iic b = Iic (b - a) := ext fun (x : G) => iff.symm le_sub_iff_add_le @[simp] theorem preimage_add_const_Iio {G : Type u} [ordered_add_comm_group G] (a : G) (b : G) : (fun (x : G) => x + a) ⁻¹' Iio b = Iio (b - a) := ext fun (x : G) => iff.symm lt_sub_iff_add_lt @[simp] theorem preimage_add_const_Icc {G : Type u} [ordered_add_comm_group G] (a : G) (b : G) (c : G) : (fun (x : G) => x + a) ⁻¹' Icc b c = Icc (b - a) (c - a) := sorry @[simp] theorem preimage_add_const_Ico {G : Type u} [ordered_add_comm_group G] (a : G) (b : G) (c : G) : (fun (x : G) => x + a) ⁻¹' Ico b c = Ico (b - a) (c - a) := sorry @[simp] theorem preimage_add_const_Ioc {G : Type u} [ordered_add_comm_group G] (a : G) (b : G) (c : G) : (fun (x : G) => x + a) ⁻¹' Ioc b c = Ioc (b - a) (c - a) := sorry @[simp] theorem preimage_add_const_Ioo {G : Type u} [ordered_add_comm_group G] (a : G) (b : G) (c : G) : (fun (x : G) => x + a) ⁻¹' Ioo b c = Ioo (b - a) (c - a) := sorry /-! ### Preimages under `x ↦ -x` -/ @[simp] theorem preimage_neg_Ici {G : Type u} [ordered_add_comm_group G] (a : G) : -Ici a = Iic (-a) := ext fun (x : G) => le_neg @[simp] theorem preimage_neg_Iic {G : Type u} [ordered_add_comm_group G] (a : G) : -Iic a = Ici (-a) := ext fun (x : G) => neg_le @[simp] theorem preimage_neg_Ioi {G : Type u} [ordered_add_comm_group G] (a : G) : -Ioi a = Iio (-a) := ext fun (x : G) => lt_neg @[simp] theorem preimage_neg_Iio {G : Type u} [ordered_add_comm_group G] (a : G) : -Iio a = Ioi (-a) := ext fun (x : G) => neg_lt @[simp] theorem preimage_neg_Icc {G : Type u} [ordered_add_comm_group G] (a : G) (b : G) : -Icc a b = Icc (-b) (-a) := sorry @[simp] theorem preimage_neg_Ico {G : Type u} [ordered_add_comm_group G] (a : G) (b : G) : -Ico a b = Ioc (-b) (-a) := sorry @[simp] theorem preimage_neg_Ioc {G : Type u} [ordered_add_comm_group G] (a : G) (b : G) : -Ioc a b = Ico (-b) (-a) := sorry @[simp] theorem preimage_neg_Ioo {G : Type u} [ordered_add_comm_group G] (a : G) (b : G) : -Ioo a b = Ioo (-b) (-a) := sorry /-! ### Preimages under `x ↦ x - a` -/ @[simp] theorem preimage_sub_const_Ici {G : Type u} [ordered_add_comm_group G] (a : G) (b : G) : (fun (x : G) => x - a) ⁻¹' Ici b = Ici (b + a) := sorry @[simp] theorem preimage_sub_const_Ioi {G : Type u} [ordered_add_comm_group G] (a : G) (b : G) : (fun (x : G) => x - a) ⁻¹' Ioi b = Ioi (b + a) := sorry @[simp] theorem preimage_sub_const_Iic {G : Type u} [ordered_add_comm_group G] (a : G) (b : G) : (fun (x : G) => x - a) ⁻¹' Iic b = Iic (b + a) := sorry @[simp] theorem preimage_sub_const_Iio {G : Type u} [ordered_add_comm_group G] (a : G) (b : G) : (fun (x : G) => x - a) ⁻¹' Iio b = Iio (b + a) := sorry @[simp] theorem preimage_sub_const_Icc {G : Type u} [ordered_add_comm_group G] (a : G) (b : G) (c : G) : (fun (x : G) => x - a) ⁻¹' Icc b c = Icc (b + a) (c + a) := sorry @[simp] theorem preimage_sub_const_Ico {G : Type u} [ordered_add_comm_group G] (a : G) (b : G) (c : G) : (fun (x : G) => x - a) ⁻¹' Ico b c = Ico (b + a) (c + a) := sorry @[simp] theorem preimage_sub_const_Ioc {G : Type u} [ordered_add_comm_group G] (a : G) (b : G) (c : G) : (fun (x : G) => x - a) ⁻¹' Ioc b c = Ioc (b + a) (c + a) := sorry @[simp] theorem preimage_sub_const_Ioo {G : Type u} [ordered_add_comm_group G] (a : G) (b : G) (c : G) : (fun (x : G) => x - a) ⁻¹' Ioo b c = Ioo (b + a) (c + a) := sorry /-! ### Preimages under `x ↦ a - x` -/ @[simp] theorem preimage_const_sub_Ici {G : Type u} [ordered_add_comm_group G] (a : G) (b : G) : (fun (x : G) => a - x) ⁻¹' Ici b = Iic (a - b) := ext fun (x : G) => le_sub @[simp] theorem preimage_const_sub_Iic {G : Type u} [ordered_add_comm_group G] (a : G) (b : G) : (fun (x : G) => a - x) ⁻¹' Iic b = Ici (a - b) := ext fun (x : G) => sub_le @[simp] theorem preimage_const_sub_Ioi {G : Type u} [ordered_add_comm_group G] (a : G) (b : G) : (fun (x : G) => a - x) ⁻¹' Ioi b = Iio (a - b) := ext fun (x : G) => lt_sub @[simp] theorem preimage_const_sub_Iio {G : Type u} [ordered_add_comm_group G] (a : G) (b : G) : (fun (x : G) => a - x) ⁻¹' Iio b = Ioi (a - b) := ext fun (x : G) => sub_lt @[simp] theorem preimage_const_sub_Icc {G : Type u} [ordered_add_comm_group G] (a : G) (b : G) (c : G) : (fun (x : G) => a - x) ⁻¹' Icc b c = Icc (a - c) (a - b) := sorry @[simp] theorem preimage_const_sub_Ico {G : Type u} [ordered_add_comm_group G] (a : G) (b : G) (c : G) : (fun (x : G) => a - x) ⁻¹' Ico b c = Ioc (a - c) (a - b) := sorry @[simp] theorem preimage_const_sub_Ioc {G : Type u} [ordered_add_comm_group G] (a : G) (b : G) (c : G) : (fun (x : G) => a - x) ⁻¹' Ioc b c = Ico (a - c) (a - b) := sorry @[simp] theorem preimage_const_sub_Ioo {G : Type u} [ordered_add_comm_group G] (a : G) (b : G) (c : G) : (fun (x : G) => a - x) ⁻¹' Ioo b c = Ioo (a - c) (a - b) := sorry /-! ### Images under `x ↦ a + x` -/ @[simp] theorem image_const_add_Ici {G : Type u} [ordered_add_comm_group G] (a : G) (b : G) : (fun (x : G) => a + x) '' Ici b = Ici (a + b) := sorry @[simp] theorem image_const_add_Iic {G : Type u} [ordered_add_comm_group G] (a : G) (b : G) : (fun (x : G) => a + x) '' Iic b = Iic (a + b) := sorry @[simp] theorem image_const_add_Iio {G : Type u} [ordered_add_comm_group G] (a : G) (b : G) : (fun (x : G) => a + x) '' Iio b = Iio (a + b) := sorry @[simp] theorem image_const_add_Ioi {G : Type u} [ordered_add_comm_group G] (a : G) (b : G) : (fun (x : G) => a + x) '' Ioi b = Ioi (a + b) := sorry @[simp] theorem image_const_add_Icc {G : Type u} [ordered_add_comm_group G] (a : G) (b : G) (c : G) : (fun (x : G) => a + x) '' Icc b c = Icc (a + b) (a + c) := sorry @[simp] theorem image_const_add_Ico {G : Type u} [ordered_add_comm_group G] (a : G) (b : G) (c : G) : (fun (x : G) => a + x) '' Ico b c = Ico (a + b) (a + c) := sorry @[simp] theorem image_const_add_Ioc {G : Type u} [ordered_add_comm_group G] (a : G) (b : G) (c : G) : (fun (x : G) => a + x) '' Ioc b c = Ioc (a + b) (a + c) := sorry @[simp] theorem image_const_add_Ioo {G : Type u} [ordered_add_comm_group G] (a : G) (b : G) (c : G) : (fun (x : G) => a + x) '' Ioo b c = Ioo (a + b) (a + c) := sorry /-! ### Images under `x ↦ x + a` -/ @[simp] theorem image_add_const_Ici {G : Type u} [ordered_add_comm_group G] (a : G) (b : G) : (fun (x : G) => x + a) '' Ici b = Ici (a + b) := sorry @[simp] theorem image_add_const_Iic {G : Type u} [ordered_add_comm_group G] (a : G) (b : G) : (fun (x : G) => x + a) '' Iic b = Iic (a + b) := sorry @[simp] theorem image_add_const_Iio {G : Type u} [ordered_add_comm_group G] (a : G) (b : G) : (fun (x : G) => x + a) '' Iio b = Iio (a + b) := sorry @[simp] theorem image_add_const_Ioi {G : Type u} [ordered_add_comm_group G] (a : G) (b : G) : (fun (x : G) => x + a) '' Ioi b = Ioi (a + b) := sorry @[simp] theorem image_add_const_Icc {G : Type u} [ordered_add_comm_group G] (a : G) (b : G) (c : G) : (fun (x : G) => x + a) '' Icc b c = Icc (a + b) (a + c) := sorry @[simp] theorem image_add_const_Ico {G : Type u} [ordered_add_comm_group G] (a : G) (b : G) (c : G) : (fun (x : G) => x + a) '' Ico b c = Ico (a + b) (a + c) := sorry @[simp] theorem image_add_const_Ioc {G : Type u} [ordered_add_comm_group G] (a : G) (b : G) (c : G) : (fun (x : G) => x + a) '' Ioc b c = Ioc (a + b) (a + c) := sorry @[simp] theorem image_add_const_Ioo {G : Type u} [ordered_add_comm_group G] (a : G) (b : G) (c : G) : (fun (x : G) => x + a) '' Ioo b c = Ioo (a + b) (a + c) := sorry /-! ### Images under `x ↦ -x` -/ theorem image_neg_Ici {G : Type u} [ordered_add_comm_group G] (a : G) : Neg.neg '' Ici a = Iic (-a) := sorry theorem image_neg_Iic {G : Type u} [ordered_add_comm_group G] (a : G) : Neg.neg '' Iic a = Ici (-a) := sorry theorem image_neg_Ioi {G : Type u} [ordered_add_comm_group G] (a : G) : Neg.neg '' Ioi a = Iio (-a) := sorry theorem image_neg_Iio {G : Type u} [ordered_add_comm_group G] (a : G) : Neg.neg '' Iio a = Ioi (-a) := sorry theorem image_neg_Icc {G : Type u} [ordered_add_comm_group G] (a : G) (b : G) : Neg.neg '' Icc a b = Icc (-b) (-a) := sorry theorem image_neg_Ico {G : Type u} [ordered_add_comm_group G] (a : G) (b : G) : Neg.neg '' Ico a b = Ioc (-b) (-a) := sorry theorem image_neg_Ioc {G : Type u} [ordered_add_comm_group G] (a : G) (b : G) : Neg.neg '' Ioc a b = Ico (-b) (-a) := sorry theorem image_neg_Ioo {G : Type u} [ordered_add_comm_group G] (a : G) (b : G) : Neg.neg '' Ioo a b = Ioo (-b) (-a) := sorry /-! ### Images under `x ↦ a - x` -/ @[simp] theorem image_const_sub_Ici {G : Type u} [ordered_add_comm_group G] (a : G) (b : G) : (fun (x : G) => a - x) '' Ici b = Iic (a - b) := sorry @[simp] theorem image_const_sub_Iic {G : Type u} [ordered_add_comm_group G] (a : G) (b : G) : (fun (x : G) => a - x) '' Iic b = Ici (a - b) := sorry @[simp] theorem image_const_sub_Ioi {G : Type u} [ordered_add_comm_group G] (a : G) (b : G) : (fun (x : G) => a - x) '' Ioi b = Iio (a - b) := sorry @[simp] theorem image_const_sub_Iio {G : Type u} [ordered_add_comm_group G] (a : G) (b : G) : (fun (x : G) => a - x) '' Iio b = Ioi (a - b) := sorry @[simp] theorem image_const_sub_Icc {G : Type u} [ordered_add_comm_group G] (a : G) (b : G) (c : G) : (fun (x : G) => a - x) '' Icc b c = Icc (a - c) (a - b) := sorry @[simp] theorem image_const_sub_Ico {G : Type u} [ordered_add_comm_group G] (a : G) (b : G) (c : G) : (fun (x : G) => a - x) '' Ico b c = Ioc (a - c) (a - b) := sorry @[simp] theorem image_const_sub_Ioc {G : Type u} [ordered_add_comm_group G] (a : G) (b : G) (c : G) : (fun (x : G) => a - x) '' Ioc b c = Ico (a - c) (a - b) := sorry @[simp] theorem image_const_sub_Ioo {G : Type u} [ordered_add_comm_group G] (a : G) (b : G) (c : G) : (fun (x : G) => a - x) '' Ioo b c = Ioo (a - c) (a - b) := sorry /-! ### Images under `x ↦ x - a` -/ @[simp] theorem image_sub_const_Ici {G : Type u} [ordered_add_comm_group G] (a : G) (b : G) : (fun (x : G) => x - a) '' Ici b = Ici (b - a) := sorry @[simp] theorem image_sub_const_Iic {G : Type u} [ordered_add_comm_group G] (a : G) (b : G) : (fun (x : G) => x - a) '' Iic b = Iic (b - a) := sorry @[simp] theorem image_sub_const_Ioi {G : Type u} [ordered_add_comm_group G] (a : G) (b : G) : (fun (x : G) => x - a) '' Ioi b = Ioi (b - a) := sorry @[simp] theorem image_sub_const_Iio {G : Type u} [ordered_add_comm_group G] (a : G) (b : G) : (fun (x : G) => x - a) '' Iio b = Iio (b - a) := sorry @[simp] theorem image_sub_const_Icc {G : Type u} [ordered_add_comm_group G] (a : G) (b : G) (c : G) : (fun (x : G) => x - a) '' Icc b c = Icc (b - a) (c - a) := sorry @[simp] theorem image_sub_const_Ico {G : Type u} [ordered_add_comm_group G] (a : G) (b : G) (c : G) : (fun (x : G) => x - a) '' Ico b c = Ico (b - a) (c - a) := sorry @[simp] theorem image_sub_const_Ioc {G : Type u} [ordered_add_comm_group G] (a : G) (b : G) (c : G) : (fun (x : G) => x - a) '' Ioc b c = Ioc (b - a) (c - a) := sorry @[simp] theorem image_sub_const_Ioo {G : Type u} [ordered_add_comm_group G] (a : G) (b : G) (c : G) : (fun (x : G) => x - a) '' Ioo b c = Ioo (b - a) (c - a) := sorry /-! ### Multiplication and inverse in a field -/ @[simp] theorem preimage_mul_const_Iio {k : Type u} [linear_ordered_field k] (a : k) {c : k} (h : 0 < c) : (fun (x : k) => x * c) ⁻¹' Iio a = Iio (a / c) := ext fun (x : k) => iff.symm (lt_div_iff h) @[simp] theorem preimage_mul_const_Ioi {k : Type u} [linear_ordered_field k] (a : k) {c : k} (h : 0 < c) : (fun (x : k) => x * c) ⁻¹' Ioi a = Ioi (a / c) := ext fun (x : k) => iff.symm (div_lt_iff h) @[simp] theorem preimage_mul_const_Iic {k : Type u} [linear_ordered_field k] (a : k) {c : k} (h : 0 < c) : (fun (x : k) => x * c) ⁻¹' Iic a = Iic (a / c) := ext fun (x : k) => iff.symm (le_div_iff h) @[simp] theorem preimage_mul_const_Ici {k : Type u} [linear_ordered_field k] (a : k) {c : k} (h : 0 < c) : (fun (x : k) => x * c) ⁻¹' Ici a = Ici (a / c) := ext fun (x : k) => iff.symm (div_le_iff h) @[simp] theorem preimage_mul_const_Ioo {k : Type u} [linear_ordered_field k] (a : k) (b : k) {c : k} (h : 0 < c) : (fun (x : k) => x * c) ⁻¹' Ioo a b = Ioo (a / c) (b / c) := sorry @[simp] theorem preimage_mul_const_Ioc {k : Type u} [linear_ordered_field k] (a : k) (b : k) {c : k} (h : 0 < c) : (fun (x : k) => x * c) ⁻¹' Ioc a b = Ioc (a / c) (b / c) := sorry @[simp] theorem preimage_mul_const_Ico {k : Type u} [linear_ordered_field k] (a : k) (b : k) {c : k} (h : 0 < c) : (fun (x : k) => x * c) ⁻¹' Ico a b = Ico (a / c) (b / c) := sorry @[simp] theorem preimage_mul_const_Icc {k : Type u} [linear_ordered_field k] (a : k) (b : k) {c : k} (h : 0 < c) : (fun (x : k) => x * c) ⁻¹' Icc a b = Icc (a / c) (b / c) := sorry @[simp] theorem preimage_mul_const_Iio_of_neg {k : Type u} [linear_ordered_field k] (a : k) {c : k} (h : c < 0) : (fun (x : k) => x * c) ⁻¹' Iio a = Ioi (a / c) := ext fun (x : k) => iff.symm (div_lt_iff_of_neg h) @[simp] theorem preimage_mul_const_Ioi_of_neg {k : Type u} [linear_ordered_field k] (a : k) {c : k} (h : c < 0) : (fun (x : k) => x * c) ⁻¹' Ioi a = Iio (a / c) := ext fun (x : k) => iff.symm (lt_div_iff_of_neg h) @[simp] theorem preimage_mul_const_Iic_of_neg {k : Type u} [linear_ordered_field k] (a : k) {c : k} (h : c < 0) : (fun (x : k) => x * c) ⁻¹' Iic a = Ici (a / c) := ext fun (x : k) => iff.symm (div_le_iff_of_neg h) @[simp] theorem preimage_mul_const_Ici_of_neg {k : Type u} [linear_ordered_field k] (a : k) {c : k} (h : c < 0) : (fun (x : k) => x * c) ⁻¹' Ici a = Iic (a / c) := ext fun (x : k) => iff.symm (le_div_iff_of_neg h) @[simp] theorem preimage_mul_const_Ioo_of_neg {k : Type u} [linear_ordered_field k] (a : k) (b : k) {c : k} (h : c < 0) : (fun (x : k) => x * c) ⁻¹' Ioo a b = Ioo (b / c) (a / c) := sorry @[simp] theorem preimage_mul_const_Ioc_of_neg {k : Type u} [linear_ordered_field k] (a : k) (b : k) {c : k} (h : c < 0) : (fun (x : k) => x * c) ⁻¹' Ioc a b = Ico (b / c) (a / c) := sorry @[simp] theorem preimage_mul_const_Ico_of_neg {k : Type u} [linear_ordered_field k] (a : k) (b : k) {c : k} (h : c < 0) : (fun (x : k) => x * c) ⁻¹' Ico a b = Ioc (b / c) (a / c) := sorry @[simp] theorem preimage_mul_const_Icc_of_neg {k : Type u} [linear_ordered_field k] (a : k) (b : k) {c : k} (h : c < 0) : (fun (x : k) => x * c) ⁻¹' Icc a b = Icc (b / c) (a / c) := sorry @[simp] theorem preimage_const_mul_Iio {k : Type u} [linear_ordered_field k] (a : k) {c : k} (h : 0 < c) : Mul.mul c ⁻¹' Iio a = Iio (a / c) := ext fun (x : k) => iff.symm (lt_div_iff' h) @[simp] theorem preimage_const_mul_Ioi {k : Type u} [linear_ordered_field k] (a : k) {c : k} (h : 0 < c) : Mul.mul c ⁻¹' Ioi a = Ioi (a / c) := ext fun (x : k) => iff.symm (div_lt_iff' h) @[simp] theorem preimage_const_mul_Iic {k : Type u} [linear_ordered_field k] (a : k) {c : k} (h : 0 < c) : Mul.mul c ⁻¹' Iic a = Iic (a / c) := ext fun (x : k) => iff.symm (le_div_iff' h) @[simp] theorem preimage_const_mul_Ici {k : Type u} [linear_ordered_field k] (a : k) {c : k} (h : 0 < c) : Mul.mul c ⁻¹' Ici a = Ici (a / c) := ext fun (x : k) => iff.symm (div_le_iff' h) @[simp] theorem preimage_const_mul_Ioo {k : Type u} [linear_ordered_field k] (a : k) (b : k) {c : k} (h : 0 < c) : Mul.mul c ⁻¹' Ioo a b = Ioo (a / c) (b / c) := sorry @[simp] theorem preimage_const_mul_Ioc {k : Type u} [linear_ordered_field k] (a : k) (b : k) {c : k} (h : 0 < c) : Mul.mul c ⁻¹' Ioc a b = Ioc (a / c) (b / c) := sorry @[simp] theorem preimage_const_mul_Ico {k : Type u} [linear_ordered_field k] (a : k) (b : k) {c : k} (h : 0 < c) : Mul.mul c ⁻¹' Ico a b = Ico (a / c) (b / c) := sorry @[simp] theorem preimage_const_mul_Icc {k : Type u} [linear_ordered_field k] (a : k) (b : k) {c : k} (h : 0 < c) : Mul.mul c ⁻¹' Icc a b = Icc (a / c) (b / c) := sorry @[simp] theorem preimage_const_mul_Iio_of_neg {k : Type u} [linear_ordered_field k] (a : k) {c : k} (h : c < 0) : Mul.mul c ⁻¹' Iio a = Ioi (a / c) := sorry @[simp] theorem preimage_const_mul_Ioi_of_neg {k : Type u} [linear_ordered_field k] (a : k) {c : k} (h : c < 0) : Mul.mul c ⁻¹' Ioi a = Iio (a / c) := sorry @[simp] theorem preimage_const_mul_Iic_of_neg {k : Type u} [linear_ordered_field k] (a : k) {c : k} (h : c < 0) : Mul.mul c ⁻¹' Iic a = Ici (a / c) := sorry @[simp] theorem preimage_const_mul_Ici_of_neg {k : Type u} [linear_ordered_field k] (a : k) {c : k} (h : c < 0) : Mul.mul c ⁻¹' Ici a = Iic (a / c) := sorry @[simp] theorem preimage_const_mul_Ioo_of_neg {k : Type u} [linear_ordered_field k] (a : k) (b : k) {c : k} (h : c < 0) : Mul.mul c ⁻¹' Ioo a b = Ioo (b / c) (a / c) := sorry @[simp] theorem preimage_const_mul_Ioc_of_neg {k : Type u} [linear_ordered_field k] (a : k) (b : k) {c : k} (h : c < 0) : Mul.mul c ⁻¹' Ioc a b = Ico (b / c) (a / c) := sorry @[simp] theorem preimage_const_mul_Ico_of_neg {k : Type u} [linear_ordered_field k] (a : k) (b : k) {c : k} (h : c < 0) : Mul.mul c ⁻¹' Ico a b = Ioc (b / c) (a / c) := sorry @[simp] theorem preimage_const_mul_Icc_of_neg {k : Type u} [linear_ordered_field k] (a : k) (b : k) {c : k} (h : c < 0) : Mul.mul c ⁻¹' Icc a b = Icc (b / c) (a / c) := sorry theorem image_mul_right_Icc' {k : Type u} [linear_ordered_field k] (a : k) (b : k) {c : k} (h : 0 < c) : (fun (x : k) => x * c) '' Icc a b = Icc (a * c) (b * c) := sorry theorem image_mul_right_Icc {k : Type u} [linear_ordered_field k] {a : k} {b : k} {c : k} (hab : a ≤ b) (hc : 0 ≤ c) : (fun (x : k) => x * c) '' Icc a b = Icc (a * c) (b * c) := sorry theorem image_mul_left_Icc' {k : Type u} [linear_ordered_field k] {a : k} (h : 0 < a) (b : k) (c : k) : Mul.mul a '' Icc b c = Icc (a * b) (a * c) := sorry theorem image_mul_left_Icc {k : Type u} [linear_ordered_field k] {a : k} {b : k} {c : k} (ha : 0 ≤ a) (hbc : b ≤ c) : Mul.mul a '' Icc b c = Icc (a * b) (a * c) := sorry /-- The image under `inv` of `Ioo 0 a` is `Ioi a⁻¹`. -/ theorem image_inv_Ioo_0_left {k : Type u} [linear_ordered_field k] {a : k} (ha : 0 < a) : has_inv.inv '' Ioo 0 a = Ioi (a⁻¹) := sorry
Formal statement is: lemma divide_poly: assumes g: "g \<noteq> 0" shows "(f * g) div g = (f :: 'a poly)" Informal statement is: If $g$ is a nonzero polynomial, then $(f \cdot g) / g = f$.
In 2015 , Fernandez featured in Vicky Singh 's Roy , a romantic thriller , which critic Sarita A. Tanwar described as a " boring , exhausting and pretentious " film . Fernandez played dual roles , Ayesha Aamir , a filmmaker in a relationship with another filmmaker ( played by Arjun Rampal ) and Tia Desai , a girl in love with a thief ( played by Ranbir Kapoor ) . While India TV called it " her best act till date " , critic Rajeev Masand felt that she " appears miscast in a part that required greater range . " Roy failed to meet its box @-@ office expectations , and was a commercial failure . Later that year , she appeared in a guest appearance for the comedy @-@ satire <unk> .
Formal statement is: lemma nth_root_nat_naive_code [code]: "nth_root_nat m n = (if m = 0 \<or> n = 0 then 0 else if m = 1 \<or> n = 1 then n else nth_root_nat_aux m 1 1 n)" Informal statement is: The naive code equation for the nth root of a natural number.
module _ where open import Agda.Builtin.Nat open import Agda.Builtin.Equality data ⊥ : Set where T : Nat → Set T zero = ⊥ T (suc n) = Nat module M (n : Nat) where foo : n ≡ 0 → T n → Nat foo refl t = 0 module M' where bar : ⊥ bar = t bad : ⊥ bad = M'.bar loop : ⊥ loop = M.bad 0
with(plots): with(plottools): great_arc := proc(u,v,hue) local w,r,s,t,d,i; w := [u[2]*v[3]-u[3]*v[2],u[3]*v[1]-u[1]*v[3],u[1]*v[2]-u[2]*v[1]]; r := evalf(sqrt(u[1]^2+u[2]^2+u[3]^2)); d := u[1]*v[1]+u[2]*v[2]+u[3]*v[3]; w := [v[1] - d * u[1]/r^2,v[2] - d * u[2]/r^2,v[3] - d * u[3]/r^2]; s := evalf(sqrt(w[1]^2+w[2]^2+w[3]^2)); w := [r*w[1]/s,r*w[2]/s,r*w[3]/s]; t := evalf(arccos(d/r^2))/10; return(CURVES( [seq([cos(i*t)*u[1]+sin(i*t)*w[1], cos(i*t)*u[2]+sin(i*t)*w[2], cos(i*t)*u[3]+sin(i*t)*w[3]],i=0..10)], COLOR(HUE,hue))); end:
\section{Test} The corpus we use comprise of three different speakers: two men and one woman. Each speaker has 460 samples, where the average duration of each sample is about 4 seconds. For each speaker, we randomly choose $M$ samples to train GMM model. For more deep inspection of the algorithm, M is enumerated from 2 to 5. We then feed the whole corpus to to the algorithm, and test its accuracy. Further more, for the robustness of the result, we repeat the test process 10 times, and average the result. \subsection{Result} \begin{figure}[!ht] \centering \includegraphics[width=\textwidth]{res/plot.pdf} \caption{Accuracy vs Number of samples used for training} \label{fig:result} \end{figure} \begin{table}[!ht] \centering \begin{tabular}{|c|c|c|c|c|} \hline \#Training sample & 2 & 3 & 4 & 5 \\\hline Accuracy & 0.968555 & 0.991293 & 0.997549 & 0.997380 \\\hline \end{tabular} \label{table:result} \end{table} As we can see from the curve ploted, the performance of the algorithm increases as the number of training samples given increases. The accuracy when just using two training samples for each user has reached $96.55\%$, which is supprisingly high with respect to using such small amount of training samples. When using 4 to 5 samples per speaker, the accuracy is above $99.73\%$, which strongly confirmed the effectivenes of MFCC feature and GMM modeling for each speaker. However, further inspection on misclassified samples showed limitation on our test case: all the misclassified samples are within two men speakers, indicates the weakness of the algorithm.
import Data.Vect containsWord : {- LogMessage -} String -> Bool containsWord = const True stringToList : String -> List Char stringToList "" = [] stringToList s = strHead s :: stringToList (strTail s) listToVector : (s : List a) -> Vect (length s) a listToVector [] = Nil listToVector (l::ls) = l :: listToVector (ls) stringToVector : (s : String) -> Vect (length (stringToList s)) Char stringToVector s = listToVector $ stringToList s breakOffWord : Vect (S (a + b)) Char -> (Vect a Char, Vect b Char) breakOffWord (s :: st) = if s == ' ' then (Nil, st) else let (a, b) = breakOffWord st in (s :: a, b)
(* Title: HOL/Auth/n_germanSymIndex_lemma_on_inv__15.thy Author: Yongjian Li and Kaiqiang Duan, State Key Lab of Computer Science, Institute of Software, Chinese Academy of Sciences Copyright 2016 State Key Lab of Computer Science, Institute of Software, Chinese Academy of Sciences *) header{*The n_germanSymIndex Protocol Case Study*} theory n_germanSymIndex_lemma_on_inv__15 imports n_germanSymIndex_base begin section{*All lemmas on causal relation between inv__15 and some rule r*} lemma n_SendInvAckVsinv__15: assumes a1: "(\<exists> i. i\<le>N\<and>r=n_SendInvAck i)" and a2: "(\<exists> p__Inv2. p__Inv2\<le>N\<and>f=inv__15 p__Inv2)" shows "invHoldForRule s f r (invariants N)" (is "?P1 s \<or> ?P2 s \<or> ?P3 s") proof - from a1 obtain i where a1:"i\<le>N\<and>r=n_SendInvAck i" apply fastforce done from a2 obtain p__Inv2 where a2:"p__Inv2\<le>N\<and>f=inv__15 p__Inv2" apply fastforce done have "(i=p__Inv2)\<or>(i~=p__Inv2)" apply (cut_tac a1 a2, auto) done moreover { assume b1: "(i=p__Inv2)" have "?P1 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume b1: "(i~=p__Inv2)" have "?P2 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } ultimately show "invHoldForRule s f r (invariants N)" by satx qed lemma n_RecvInvAckVsinv__15: assumes a1: "(\<exists> i. i\<le>N\<and>r=n_RecvInvAck i)" and a2: "(\<exists> p__Inv2. p__Inv2\<le>N\<and>f=inv__15 p__Inv2)" shows "invHoldForRule s f r (invariants N)" (is "?P1 s \<or> ?P2 s \<or> ?P3 s") proof - from a1 obtain i where a1:"i\<le>N\<and>r=n_RecvInvAck i" apply fastforce done from a2 obtain p__Inv2 where a2:"p__Inv2\<le>N\<and>f=inv__15 p__Inv2" apply fastforce done have "(i=p__Inv2)\<or>(i~=p__Inv2)" apply (cut_tac a1 a2, auto) done moreover { assume b1: "(i=p__Inv2)" have "?P1 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume b1: "(i~=p__Inv2)" have "?P2 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } ultimately show "invHoldForRule s f r (invariants N)" by satx qed lemma n_RecvGntSVsinv__15: assumes a1: "(\<exists> i. i\<le>N\<and>r=n_RecvGntS i)" and a2: "(\<exists> p__Inv2. p__Inv2\<le>N\<and>f=inv__15 p__Inv2)" shows "invHoldForRule s f r (invariants N)" (is "?P1 s \<or> ?P2 s \<or> ?P3 s") proof - from a1 obtain i where a1:"i\<le>N\<and>r=n_RecvGntS i" apply fastforce done from a2 obtain p__Inv2 where a2:"p__Inv2\<le>N\<and>f=inv__15 p__Inv2" apply fastforce done have "(i=p__Inv2)\<or>(i~=p__Inv2)" apply (cut_tac a1 a2, auto) done moreover { assume b1: "(i=p__Inv2)" have "?P1 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume b1: "(i~=p__Inv2)" have "?P2 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } ultimately show "invHoldForRule s f r (invariants N)" by satx qed lemma n_RecvGntEVsinv__15: assumes a1: "(\<exists> i. i\<le>N\<and>r=n_RecvGntE i)" and a2: "(\<exists> p__Inv2. p__Inv2\<le>N\<and>f=inv__15 p__Inv2)" shows "invHoldForRule s f r (invariants N)" (is "?P1 s \<or> ?P2 s \<or> ?P3 s") proof - from a1 obtain i where a1:"i\<le>N\<and>r=n_RecvGntE i" apply fastforce done from a2 obtain p__Inv2 where a2:"p__Inv2\<le>N\<and>f=inv__15 p__Inv2" apply fastforce done have "(i=p__Inv2)\<or>(i~=p__Inv2)" apply (cut_tac a1 a2, auto) done moreover { assume b1: "(i=p__Inv2)" have "?P3 s" apply (cut_tac a1 a2 b1, simp, rule_tac x="(neg (andForm (eqn (IVar (Field (Para (Ident ''Chan3'') p__Inv2) ''Cmd'')) (Const InvAck)) (eqn (IVar (Field (Para (Ident ''Chan2'') p__Inv2) ''Cmd'')) (Const GntE))))" in exI, auto) done then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume b1: "(i~=p__Inv2)" have "?P2 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } ultimately show "invHoldForRule s f r (invariants N)" by satx qed lemma n_SendReqE__part__1Vsinv__15: assumes a1: "\<exists> i. i\<le>N\<and>r=n_SendReqE__part__1 i" and a2: "(\<exists> p__Inv2. p__Inv2\<le>N\<and>f=inv__15 p__Inv2)" shows "invHoldForRule s f r (invariants N)" apply (rule noEffectOnRule, cut_tac a1 a2, auto) done lemma n_StoreVsinv__15: assumes a1: "\<exists> i d. i\<le>N\<and>d\<le>N\<and>r=n_Store i d" and a2: "(\<exists> p__Inv2. p__Inv2\<le>N\<and>f=inv__15 p__Inv2)" shows "invHoldForRule s f r (invariants N)" apply (rule noEffectOnRule, cut_tac a1 a2, auto) done lemma n_SendGntSVsinv__15: assumes a1: "\<exists> i. i\<le>N\<and>r=n_SendGntS i" and a2: "(\<exists> p__Inv2. p__Inv2\<le>N\<and>f=inv__15 p__Inv2)" shows "invHoldForRule s f r (invariants N)" apply (rule noEffectOnRule, cut_tac a1 a2, auto) done lemma n_RecvReqEVsinv__15: assumes a1: "\<exists> i. i\<le>N\<and>r=n_RecvReqE N i" and a2: "(\<exists> p__Inv2. p__Inv2\<le>N\<and>f=inv__15 p__Inv2)" shows "invHoldForRule s f r (invariants N)" apply (rule noEffectOnRule, cut_tac a1 a2, auto) done lemma n_SendInv__part__0Vsinv__15: assumes a1: "\<exists> i. i\<le>N\<and>r=n_SendInv__part__0 i" and a2: "(\<exists> p__Inv2. p__Inv2\<le>N\<and>f=inv__15 p__Inv2)" shows "invHoldForRule s f r (invariants N)" apply (rule noEffectOnRule, cut_tac a1 a2, auto) done lemma n_SendReqE__part__0Vsinv__15: assumes a1: "\<exists> i. i\<le>N\<and>r=n_SendReqE__part__0 i" and a2: "(\<exists> p__Inv2. p__Inv2\<le>N\<and>f=inv__15 p__Inv2)" shows "invHoldForRule s f r (invariants N)" apply (rule noEffectOnRule, cut_tac a1 a2, auto) done lemma n_SendInv__part__1Vsinv__15: assumes a1: "\<exists> i. i\<le>N\<and>r=n_SendInv__part__1 i" and a2: "(\<exists> p__Inv2. p__Inv2\<le>N\<and>f=inv__15 p__Inv2)" shows "invHoldForRule s f r (invariants N)" apply (rule noEffectOnRule, cut_tac a1 a2, auto) done lemma n_SendReqSVsinv__15: assumes a1: "\<exists> i. i\<le>N\<and>r=n_SendReqS i" and a2: "(\<exists> p__Inv2. p__Inv2\<le>N\<and>f=inv__15 p__Inv2)" shows "invHoldForRule s f r (invariants N)" apply (rule noEffectOnRule, cut_tac a1 a2, auto) done lemma n_SendGntEVsinv__15: assumes a1: "\<exists> i. i\<le>N\<and>r=n_SendGntE N i" and a2: "(\<exists> p__Inv2. p__Inv2\<le>N\<and>f=inv__15 p__Inv2)" shows "invHoldForRule s f r (invariants N)" apply (rule noEffectOnRule, cut_tac a1 a2, auto) done lemma n_RecvReqSVsinv__15: assumes a1: "\<exists> i. i\<le>N\<and>r=n_RecvReqS N i" and a2: "(\<exists> p__Inv2. p__Inv2\<le>N\<and>f=inv__15 p__Inv2)" shows "invHoldForRule s f r (invariants N)" apply (rule noEffectOnRule, cut_tac a1 a2, auto) done end
lemma homotopic_into_retract: "\<lbrakk>f ` S \<subseteq> T; g ` S \<subseteq> T; T retract_of U; homotopic_with_canon (\<lambda>x. True) S U f g\<rbrakk> \<Longrightarrow> homotopic_with_canon (\<lambda>x. True) S T f g"
module TestPadded include("preamble.jl") using UnionArrays.Impl: ofsamesize, unpad, Padded @testset "ofsamesize" begin @testset "bigger = $bigger" for (bigger, value) in [ (Float64, UInt8(0)), (NTuple{7, UInt8}, UInt8(0)), ] @testset for smaller in [value, typeof(value)] padded = ofsamesize(bigger, smaller) @test sizeof(padded) == sizeof(bigger) @test unpad(padded) === smaller end end end @testset "convert" begin xs = ofsamesize.(Float64, UInt8.(1:10)) :: Vector @test eltype(xs) <: Padded @test unpad(xs[1]) === UInt8(1) xs[1] = UInt8(2) @test unpad(xs[1]) === UInt8(2) xs[1] = ofsamesize(Float64, UInt8(3)) @test unpad(xs[1]) === UInt8(3) end end # module
Require Import List. Section ListLexOrder. Variable T : Type. Variable cmp : T -> T -> comparison. Fixpoint list_lex_cmp (ls rs : list T) : comparison := match ls , rs with | nil , nil => Eq | nil , _ => Lt | _ , nil => Gt | l :: ls , r :: rs => match cmp l r with | Eq => list_lex_cmp ls rs | x => x end end. End ListLexOrder. Section Sorting. Variable T : Type. Variable cmp : T -> T -> comparison. Section insert. Variable val : T. Fixpoint insert_in_order (ls : list T) : list T := match ls with | nil => val :: nil | l :: ls' => match cmp val l with | Gt => l :: insert_in_order ls' | _ => val :: ls end end. End insert. Fixpoint sort (ls : list T) : list T := match ls with | nil => nil | l :: ls => insert_in_order l (sort ls) end. End Sorting. Lemma insert_in_order_inserts : forall T C x l, exists h t, insert_in_order T C x l = h ++ x :: t /\ l = h ++ t. Proof. clear. induction l; simpl; intros. exists nil; exists nil; eauto. destruct (C x a). exists nil; simpl. eauto. exists nil; simpl. eauto. destruct IHl. destruct H. intuition. subst. rewrite H0. exists (a :: x0). exists x1. simpl; eauto. Qed. Require Import Permutation. Lemma sort_permutation : forall T (C : T -> T -> _) x, Permutation (sort _ C x) x. Proof. induction x; simpl. { reflexivity. } { destruct (insert_in_order_inserts T C a (sort T C x)) as [ ? [ ? ? ] ]. destruct H. rewrite H. rewrite <- Permutation_cons_app. reflexivity. rewrite H0 in *. symmetry; auto. } Qed.
lemma finite_measure_restrict_space: assumes "finite_measure M" and A: "A \<in> sets M" shows "finite_measure (restrict_space M A)"
DEVICE_TO_HOST = 1L HOST_TO_DEVICE = 2L DEVICE_TO_DEVICE = 3L TYPE_INT = 1L TYPE_FLOAT = 2L TYPE_DOUBLE = 3L ARRTYPE_VECTOR = 1L ARRTYPE_MATRIX = 2L global_str2int = function(str) { if (str == "devicetohost") DEVICE_TO_HOST else if (str == "hosttodevice") HOST_TO_DEVICE else if (str == "devicetodevice") DEVICE_TO_DEVICE else if (str == "int") TYPE_INT else if (str == "float") TYPE_FLOAT else if (str == "double") TYPE_DOUBLE else stop("internal error: please report this to the developers") }
\documentclass[10pt,]{scrartcl} \usepackage{lmodern} \usepackage{amssymb,amsmath} \usepackage{ifxetex,ifluatex} \usepackage{fixltx2e} % provides \textsubscript \ifnum 0\ifxetex 1\fi\ifluatex 1\fi=0 % if pdftex \usepackage[T1]{fontenc} \usepackage[utf8]{inputenc} \else % if luatex or xelatex \ifxetex \usepackage{mathspec} \else \usepackage{fontspec} \fi \defaultfontfeatures{Ligatures=TeX,Scale=MatchLowercase} \fi % use upquote if available, for straight quotes in verbatim environments \IfFileExists{upquote.sty}{\usepackage{upquote}}{} % use microtype if available \IfFileExists{microtype.sty}{% \usepackage[]{microtype} \UseMicrotypeSet[protrusion]{basicmath} % disable protrusion for tt fonts }{} \PassOptionsToPackage{hyphens}{url} % url is loaded by hyperref \usepackage[unicode=true]{hyperref} \PassOptionsToPackage{usenames,dvipsnames}{color} % color is loaded by hyperref \hypersetup{ pdftitle={Measuring coherence with Bayesian Networks}, colorlinks=true, linkcolor=blue, citecolor=blue, urlcolor=blue, breaklinks=true} \urlstyle{same} % don't use monospace font for urls \usepackage{graphicx,grffile} \makeatletter \def\maxwidth{\ifdim\Gin@nat@width>\linewidth\linewidth\else\Gin@nat@width\fi} \def\maxheight{\ifdim\Gin@nat@height>\textheight\textheight\else\Gin@nat@height\fi} \makeatother % Scale images if necessary, so that they will not overflow the page % margins by default, and it is still possible to overwrite the defaults % using explicit options in \includegraphics[width, height, ...]{} \setkeys{Gin}{width=\maxwidth,height=\maxheight,keepaspectratio} \IfFileExists{parskip.sty}{% \usepackage{parskip} }{% else \setlength{\parindent}{0pt} \setlength{\parskip}{6pt plus 2pt minus 1pt} } \setlength{\emergencystretch}{3em} % prevent overfull lines \providecommand{\tightlist}{% \setlength{\itemsep}{0pt}\setlength{\parskip}{0pt}} \setcounter{secnumdepth}{5} % Redefines (sub)paragraphs to behave more like sections \ifx\paragraph\undefined\else \let\oldparagraph\paragraph \renewcommand{\paragraph}[1]{\oldparagraph{#1}\mbox{}} \fi \ifx\subparagraph\undefined\else \let\oldsubparagraph\subparagraph \renewcommand{\subparagraph}[1]{\oldsubparagraph{#1}\mbox{}} \fi % set default figure placement to htbp \makeatletter \def\fps@figure{htbp} \makeatother %\documentclass{article} \usepackage[table]{xcolor } % %packages \usepackage{booktabs} \usepackage[sort&compress]{natbib} \usepackage{graphicx} \usepackage{longtable} \usepackage{ragged2e} \usepackage{etex} %\usepackage{yfonts} \usepackage{marvosym} \usepackage[notextcomp]{kpfonts} \usepackage{nicefrac} \newcommand*{\QED}{\hfill \footnotesize {\sc Q.e.d.}} \usepackage[textsize=footnotesize]{todonotes} %\linespread{1.5} \setlength{\parindent}{10pt} \setlength{\parskip}{1pt} %language %\usepackage{times} \usepackage{mathptmx} \usepackage{t1enc} %\usepackage[utf8x]{inputenc} %\usepackage[polish]{babel} %\usepackage{polski} \usepackage{subcaption} %AMS \usepackage{amsfonts} \usepackage{amssymb} \usepackage{amsthm} \usepackage{amsmath} %\usepackage{geometry} %\geometry{a4paper,left=35mm,top=20mm,} %abbreviations \newcommand{\ra}{\rangle} \newcommand{\la}{\langle} \newcommand{\n}{\neg} \newcommand{\et}{\wedge} \newcommand{\jt}{\rightarrow} \newcommand{\ko}[1]{\forall #1\,} \newcommand{\ro}{\leftrightarrow} \newcommand{\exi}[1]{\exists\, {_{#1}}} \newcommand{\pr}{\mathsf{P}} \newcommand{\odds}{\mathsf{Odds}} \newcommand{\ind}{\mathsf{Ind}} \newcommand{\nf}[2]{\nicefrac{#1\,}{#2}} \newcommand{\R}[1]{\texttt{#1}} \newtheorem{q}{\color{blue}Question} \newcommand{\s}[1]{\mbox{\textsf{#1}}} \newtheorem*{reply*}{Reply} \usepackage{enumitem} \newcommand{\question}[1]{\begin{enumerate}[resume,leftmargin=0cm,labelsep=0cm,align=left] \item #1 \end{enumerate}} \usepackage{float} % \setbeamertemplate{blocks}[rounded][shadow=true] % \setbeamertemplate{itemize items}[ball] % \AtBeginPart{} % \AtBeginSection{} % \AtBeginSubsection{} % \AtBeginSubsubsection{} % \setlength{\emergencystretch}{0em} % \setlength{\parskip}{0pt} \title{Measuring coherence with Bayesian Networks} \author{} \date{\vspace{-2.5em}} \begin{document} \maketitle \begin{abstract} \textbf{Abstract.} The notion of coherence is often used in many philosophical, especially epistemological, discussions (for instance, in discussions about the truth-conduciveness of coherence). An explication of the key notion involved seems desirable. We introduce the most prominent coherence measures and a number of counterexamples put forward against them. Then, we point out some common problems that underlie these counterexamples. These observations lead us to a new measure of coherence. Our measure diverges from the known candidates in three important respects: (1) It is not a function of a probabilistic measure and a set of propositions alone, because it is also sensitive to the selection and direction of arrows in a Bayesian network representing an agent's credal state. (2) Unlike in the case of quite a few coherence measures, it is not obtained by taking a mean of some list of intermediate values (such as confirmation levels between subsets of a narration). It is sensitive also to the variance and the minimal values of the intermediate values. (3) The intermediate values used are not confirmation levels, but rather expected and weighted confirmation levels. We apply our measure to the existing counterexamples and compare its performance to the performance of the other measures. It does a better job. \vspace{3mm} \footnotesize \noindent \textbf{Technical remark.} The whole work has been made possible by all those who contributed to the development of \textsf{\textbf{R}} language, and Marco Scutari, the author of \textsf{\textbf{bnlearn}} package, who was kind enough to extend his package with additional features upon our requests. The use of these tools here is essential, because we used the environment to write Bayesian Networks (BNs) for all the counterexamples, all coherence functions as applicable to BNs (including ours), and automated performance analysis and BN visualisation, which otherwise wouldn't be manageable. Our code with a guide can be made available to the reviewer upon request, and will be available open access if the paper is published. \end{abstract} \section{Motivations \& introduction} The notion of coherence is often used in many philosophical, especially epistemological, discussions (for instance, in discussions about the truth-conduciveness of coherence). An explication of the key notion involved seems desirable. There is also a more practical reason to develop a better understanding of the notion: a plausible measure of coherence could be used to better evaluate the quality of some stories or narrations. For example in the legal context we would like to be able to assess the quality of a testimony in the court of law. Focusing only on the probability of a story is to some extent problematic, because from such a perspective, more detailed stories are penalized --- they contain more propositions, so they (usually) have lower probabilities. A plausible coherence measure could be used to asses an important aspect of a narration which so far seems to escape probabilistic analysis. When we talk about the coherence of a set of propositions or about the coherence of a story, we seem to refer to how well their individual pieces fit together. How are we to understand and apply this notion systematically, though? As with beliefs, we can use both a binary and a graded notion of coherence. The binary notion is not very exciting: a set is incoherent just in case it is logically inconsistent.\footnote{There is a related notion in the neighborhood where an agent's degrees of beliefs are coherent just in case it they are probabilistic. We will not use this notion in this paper.} Intuitively, graded coherence should be a generalization of this requirement: logically incoherent sets should have minimal (or at least negative) level of graded coherence. Or, at least, lower coherence than consistent ones. What other requirements should a coherence measure satisfy and how should it be explicated formally, if we want to massage this notion into a more general framework of probabilistic epistemology? Defining a measure of graded coherence in probabilistic terms turned out to be quite a challenge, which resulted in heaps of literature. Also, in reasarch unconnected to and seemingly unaware of the philosophical discussion, in the context of Bayesian networks developed for stories and narrations in legal contexts (C. Vlek et al., 2013, C. Vlek et al. (2014), C. S. Vlek et al. (2015), C. Vlek (2016), Fenton et al. (2013), Fenton et al. (2013)), an approach to coherence has been developed by Vlek. The proposal is to capture the coherence of the story by introducing a single narration root node which becomes an ancestor node to all the other nodes such that the conditional probability of each dependent node given that the state of this root is 1 (that is, the corresponding proposition is assumed to be true), is also 1. This is defended by observing that in such a network previously independent nodes become dependent without any principled reason. This is true, but we don't think this is desirable: one shouldn't introduce probabilistic dependencies by fiat in a model. Moreover, Vlek then identifies coherence of a model with the prior probability of the narration node, and we specifically want to capture the idea that coherence is distinct from probability. For this reason, we think an account of coherence for such practical applications is still missing. We first introduce the main existing coherence measures. Then we describe a lengthy list of counterexamples to these measures. A general discussion of certain common features and issues we observed follows, which leads us to the description of our own coherence measure. Our measure diverges from the known candidates in three important respects: (1) It is not a function of a probabilistic measure and a set of propositions alone, because it is also sensitive to the selection and direction of arrows in a Bayesian Network representing an agent's credal state. (2) Unlike in the case of quite a few coherence measures, it is not obtained by taking a mean of some list of intermediate values (such as confirmation levels between subsets of a narration). It is sensitive also to the variance and the minimal values of the intermediate values. (3) The intermediate values used are not confirmation levels, but rather expected and weighted confirmation levels (read on for details). Finally, we apply our measure to the existing counterexamples and compare its performance to the performance of the other measures. Spoiler alert: it does a better job. \section{Measures} Let's take a look at different approaches to measuring coherence. One thing to keep in mind is that different measures use different scales and have different neutral points, if any (the idea is: the coherence of probabilistically independent propositions should be neither positive nor negative). \subsection{Deviation from independence -- Shogenji} The first measure we present was developed by Tomoji Shogenji (1999, p. 340) and is often called \textit{deviation from independence}. This measure is defined as the ratio between the probability of the conjunction of all claims, and the probability that the conjunction would get if all its conjuncts were probabilistically independent. \begin{align} \tag{Shogenji} \label{coh:Shogenji} C_s(A_1,\dots,A_n)=\frac{P(A_1 \& \dots \& A_n)}{P(A_1)\times\dots\times P(A_n)} \end{align} \noindent \textbf{scale:} {[}0, \(\infty\){]} \noindent \textbf{neutral point:} 1 \noindent This measure was later generalized by Meijs \& Douven (2007). According to this approach, \eqref{coh:Shogenji} is applied not only to the whole set of propositions, but to each non-empty non-singleton subset of the set, and the final value is defined as the average of all sub-values thus obtained. \subsection{Relative overlap -- Olsson \& Glass} The second approach, a \textit{relative overlap} measure, comes from Olsson (2001) and Glass (2002). This measure is defined as the ratio between the intersection of all propositions and their union. It was later generalized in a way analogous to the one used in the generalization of the Shogenji's measure. \begin{align} \tag{Olsson} \label{coh:Olsson} C_o(A_1,\dots,A_n)=\frac{P(A_1 \& \dots \& A_n)}{P(A_1 \vee \dots \vee A_n)} \end{align} \noindent \textbf{scale:} {[}0, 1{]} \noindent \textbf{neutral point:} NO \subsection{Average mutual support} Finally, the most recent approach --- a class of measures called \textit{average mutual support}. The general recipe for such a measure is this. \begin{itemize} \item Given that \(S\) is a set whose coherence is to be measured, let \(P\) indicate the set of all ordered pairs of non-empty, disjoint subsets of \(S\). \item First, define a confirmation measure for the confirmation of a hypothesis \(H\) by evidence \(E\): \(Conf(H,E)\). \item For each pair \(\langle X, Y \rangle \in P\), calculate \(Conf(\bigwedge X, \bigwedge Y)\), where $\bigwedge X$ ($\bigwedge Y$) is the conjunction of all the elements of $X$ ($Y$). \item Take the mean of all the results. \end{itemize}\begin{align*} \mathcal{C}(P) & = mean\left(\left\{Conf(\bigwedge X_i, \bigwedge Y_i) | \langle X_i, Y_i \rangle \in P\right\} \right) \end{align*} \noindent Depending on the choice of a confirmation measure, we achieve different measures of coherence. \subsubsection{Fitelson} Fitelson (2003a, 2003b) uses the following confirmation function: \begin{align*} F(H,E) = \begin{cases} 1 & E\models H, E\not \models \bot \\ -1 & E \models \neg H\\ \frac{P(E|H)-P(E|\neg H)}{P(E|H)+P(E|\neg H)} & \mbox{o/w} \end{cases} \end{align*} \begin{align} \tag{Fitelson} \mathcal{C}_{F}(P) & = mean\left(\left\{F(\bigwedge X_i, \bigwedge Y_i) | \langle X_i, Y_i\rangle \in P\right\} \right) \end{align} \noindent For instance, Fitelson's coherence for two propositions boils down to this: \begin{align} \tag{Fitelson pairs} \mathcal{C}_{F}(X,Y) &= \frac{F(X,Y)+F(Y,X)}{2} \label{coh:Fitelson} \end{align} \noindent \textbf{scale:} {[}-1, 1{]} \noindent \textbf{neutral point:} 0 \subsubsection{Douven and Meij's} Another coherence measure of this type has been introduced by Douven \& Meijs (2007). They use the \textit{difference} confirmation measure: \begin{align*} D(H,E) = P(H|E) - P(H) \end{align*} The resulting definition of coherence is: \begin{align} \tag{DM} \mathcal{C}_{DM}(P) & = mean\left(\left\{D(\bigwedge X_i, \bigwedge Y_i) | \langle X_i, Y_i\rangle \in P\right\} \right) \end{align} For two propositions, the coherence measure boils down to: \begin{align} \tag{DM pairs} \label{coh:DM} C_{DM}(X,Y)= \frac{P(X|Y) - P(X) + P(Y|X) - P(Y)}{2} \end{align} \noindent \textbf{scale:} {[}-1, 1{]} \noindent \textbf{neutral point:} 0 (not explicit) \subsubsection{Roche} Yet another measure, due to Roche (2013, p. 69), starts with the absolute confirmation measure: \begin{align*} A(H,E) = \begin{cases} 1 & E\models H, E\not \models \bot \\ 0 & E \models \neg H\\ P(H|E) & \mbox{o/w} \\ \end{cases} \end{align*} which results in the following coherence measure: \begin{align} \tag{Roche} \mathcal{C}_{R}(P) & = mean\left(\left\{A(\bigwedge X_i, \bigwedge Y_i) | \langle X_i, Y_i\rangle \in P\right\} \right) \end{align} For two propositions, the measure gives the following: \begin{align} \tag{Roche pairs} \label{coh:Roche} C_{R}(X,Y)= \frac{P(X|Y)+P(Y|X)}{2} \end{align} \noindent \textbf{scale:} {[}0, 1{]} \noindent \textbf{neutral point:} 0.5 \section{Challenges} One methodological approach to the discussion about measures of coherence relies on the assumption that various explications proposed in the literature can be criticized by pointing out thought experiments which inspire coherence-related intuitions that disagree with a given coherence measure. Of course, the idea that principled philosophical accounts should be tested against thought experiments that are hopefully easier to agree on than general philosophical claims themselves is debatable. However, this paper does not aim to address this general question. Instead, in line with the discussion, we take the challenges posed by counterexamples seriously, and ask the following question: is there a fairly sensible probabilistic explication of the notion of coherence which is not undermined by the existing counterexamples? This does not mean that we take these examples as some sort of ultimate benchmark. Conceptual explication does have to start somewhere, and key seemingly clear-cut cases against probabilistic explications of coherence seem to be a decent candidate. If you care about the problem, and are worried about the counterexamples, this paper aims to address your concerns. So here is a selection counterexamples put forward against various probabilistic coherence measures in the literaturesudo . We attempted to list those that were picked up in the discussion, a few where both we didn't share the authors' intuitions and the examples were not picked up in further discussion in the literature.\footnote{One example, involving Sarah and her pregnancy (Tomoji Shogenji, 2006), but it focused more on truth-conduciveness of coherence, which is beyond the scope of our paper. We also do not discuss a few other examples involving fossils and voltage (T. Shogenji, 2001; Mark Siebel, 2006). In some respects, they were quite similar to the dice and depth problems that we do discuss, and some of their variants simply did not inspire our agreement. For instance, Siebel thinks that for voltage levels \(\{V=1, V=2\}\) is more coherent than \(\{V=1, V=50\}\), while we think that both sets are maximally incoherent (there might be some claims in the vincinity that are not incoherent, say, focusing on results of separate measurements, but an example along these lines has not been properly formulated in the literature).} \subsection{Penguins} \textbf{The scenario.} A challenge discussed in (Bovens \& Hartmann, 2004, p. 50) and (Meijs \& Douven, 2007) consists of the following set of propositions (instead of \emph{letters} or \emph{abbreviations}, we'll talk about \emph{nodes}, as these will be used later on in Bayesian networks): \begin{table}[H] \centering \begin{tabular}{ll} \toprule node & content\\ \midrule \cellcolor{gray!6}{B} & \cellcolor{gray!6}{Tweety is a bird.}\\ G & Tweety is a grounded animal.\\ \cellcolor{gray!6}{P} & \cellcolor{gray!6}{Tweety is a penguin.}\\ \bottomrule \end{tabular} \end{table} \noindent \textbf{Desiderata.} It seems that the set \{\s{B},\s{G}\}, which doesn't contain the information about Tweety being a penguin, should be less coherent than the one that does contain this information: \{\s{B},\s{G},\s{P}\}. \vspace{2mm} \begin{description} \item[(\s{BG}$<$\s{BGP})] \{\s{B},\s{G}\} should be less coherent than \{\s{B},\s{G},\s{P}\}. \end{description} \vspace{2mm} Another intuition about this scenario (Schippers \& Koscholke, 2019) is that when you consider a set which says that Tweety is both a bird and a penguin: \{\s{B},\s{P}\}, adding proposition about not flying (\s{G}) shouldn't really increase the coherence of the set. It's a well-known fact that penguins don't fly, and so one can deduce \s{G} from \s{P}. Therefore by adding \s{G} explicitly to the set, one wouldn't gain any new information -- so if a set expresses the same information, its coherence shouldn't be different. As \s{G} is not a logical consequence of \s{P}, it can be argued that \{\s{B},\s{P}\} and \{\s{B},\s{P},\s{G}\} represent different information sets, and a slight difference in their coherence is also acceptable. \vspace{2mm} \begin{description} \item[(\s{BP}$\approx$\s{BGP})] \{\s{B},\s{P}\} should have similar coherence to \{\s{B},\s{P},\s{G}\}. \end{description} \vspace{2mm} \subsection{Dunnit} \textbf{The scenario.} Another challenge, introduced by Merricks (1995) goes as follows: Mr.~Dunnit is a suspect in the murder case. Detectives first obtained the following body of evidence: \begin{table}[H] \centering \begin{tabular}{l>{\raggedright\arraybackslash}p{25em}} \toprule node & content\\ \midrule \cellcolor{gray!6}{I} & \cellcolor{gray!6}{Witnesses claim to have seen Dunnit do it (incriminating testimony).}\\ M & Dunnit had a motive for the murder.\\ \cellcolor{gray!6}{W} & \cellcolor{gray!6}{A credible witness claims to have seen Dunnit two hundred miles from the scene of the crime at the time of the murder.}\\ \bottomrule \end{tabular} \end{table} In light of this information they try to assess whether Dunnit is responsible for the crime. \begin{table}[H] \centering \begin{tabular}{l>{\raggedright\arraybackslash}p{25em}} \toprule node & content\\ \midrule \cellcolor{gray!6}{G} & \cellcolor{gray!6}{Dunnit is guilty.}\\ \bottomrule \end{tabular} \end{table} Now, suppose the detectives learn Dunnit has a twin brother. \begin{table}[H] \centering \begin{tabular}{l>{\raggedright\arraybackslash}p{25em}} \toprule node & content\\ \midrule \cellcolor{gray!6}{Tw} & \cellcolor{gray!6}{Dunnit has an identical twin which was seen by the credible witness two hundred miles from the scene of the crime during the murder.}\\ \bottomrule \end{tabular} \end{table} \noindent and compare the coherence of \(\{\)\s{I,M,W,G}\(\}\) with the coherence of \(\{\)\s{I,M,W,G,Tw}\(\}\). \noindent \textbf{Desideratum.} It seems that adding proposition about a twin should increase the coherence of the set. \vspace{2mm} \begin{description} \item[(Dunnit$<$Twin)] $\{$\s{I,M,W,G}$\}$ should be less coherent than $\{$\s{I,M,W,G,Tw}$\}$. \end{description} \vspace{2mm} \subsection{Japanese swords} \textbf{The scenario.} The next challenge comes from (Meijs \& Douven, 2007, p. 414): \begin{quote} We start by considering two situations in both of which it is assumed that a murder has been committed in a street in a big city with 10,000,000 inhabitants, 1,059 of them being Japanese, 1,059 of them owning Samurai swords, and 9 of them both being Japanese and owning Samurai swords. In situation I we assume that the murderer lives in the city and that everyone living in the city is equally likely to be the murderer. In situation II, on the other hand, we make the assumption that the victim was murdered by someone living in the street in which her body was found. In that street live 100 persons, 10 of them being Japanese, 10 owning a Samurai sword, and 9 both being Japanese and owning a Samurai sword. [\dots] [In situation III] we have 12 suspects who all live in the same house, and 10 of them are Japanese, 10 own a Samurai sword, and 9 are both Japanese and Samurai sword owners. \end{quote} The nodes involved are as follows: \begin{table}[H] \centering \begin{tabular}{ll} \toprule node & content\\ \midrule \cellcolor{gray!6}{J} & \cellcolor{gray!6}{The murderer is Japanese.}\\ O & The murderer owns a Samurai sword.\\ \bottomrule \end{tabular} \end{table} And we look at three separate scenarios: (\textsf{1}) The murderer lives in the city, (\textsf{2}) The murderer lives in the street popular amongst Japanese owners of Samurai swords, and (\textsf{3}) The murderer lives in the house with many Japanese owners of Samurai swords. \noindent \textbf{Desiderata.} In all of the above situations the number of Japanese owners of Samurai swords remains the same. However, situations 1 and 2 differ in the relative overlap of \s{J} and \s{O}. Because \s{J} and \s{O} are more correlated in situation 2, it seems more coherent than situation 1. \vspace{2mm} \begin{description} \item[(\s{JO2}$>$\s{JO1})] \{\s{J,O,2}\} should be more coherent than \{\s{J,O,1}\} \end{description} \vspace{2mm} However, bigger overlap, supposedly, doesn't have to indicate higher coherence. In situation 3 \s{J} and \s{O} confirm each other to a lesser extent than in situation 2 (compare \(P(J|O)-P(J)\) and \(P(O|J)-P(O)\) in both cases), and for this reason Douven and Meijs claim that situation 2 is more coherent than situation 3. \vspace{2mm} \begin{description} \item[(\s{JO2}$>$\s{JO3})] \{\s{J,O,2}\} should be more coherent than \{\s{J,O,3}\} \end{description} \vspace{2mm} \subsection{Robbers} \textbf{The scenario.} A challenge put forward by M. Siebel (2004, p. 336) goes as follows: \begin{quote} Let there be ten equiprobable suspects for a murder. All of them previously committed at least one crime, two a robbery, two pickpocketing, and the remaining six both crimes. There is thus a substantial overlap: of the total of eight suspects who committed a robbery, six were also involved in pickpocketing, and conversely. \end{quote} \begin{table}[H] \centering \begin{tabular}{ll} \toprule node & content\\ \midrule \cellcolor{gray!6}{W} & \cellcolor{gray!6}{Real perpetrator status (three possible states).}\\ P & The murderer is a pickpocket.\\ \cellcolor{gray!6}{R} & \cellcolor{gray!6}{The murderer is a robber.}\\ \bottomrule \end{tabular} \end{table} \noindent \textbf{Desiderata.} The first observation is that the set of propositions that corresponds to the situation in which a murderer committed both crimes should be regarded coherent. Most suspects committed both crimes, so this option is even the most probable one. \vspace{2mm} \begin{description} \item[(\s{PR}\textgreater \s{neutral})] \{\s{P,R}\} should be regarded coherent. \end{description} \vspace{2mm} According to M. Siebel (2004, p. 336) committing both crimes by the murderer should also be regarded more coherent than committing only one crime. \vspace{2mm} \begin{description} \item[(\s{PR}$>$\s{P}$\neg$\s{R})] \{\s{P,R}\} should be more coherent than \{\s{P},$\neg$\s{R}\} and \{$\neg$\s{P},\s{R}\}. \end{description} \vspace{2mm} \subsection{The Beatles} \textbf{The scenario.} The challenge has been offered by Tomoji Shogenji (1999, p. 339) to criticize defining coherence in terms of pairwise coherence --- it shows there are jointly incoherent pairwise coherent sets. The scenario consists of the following claims: \begin{table}[H] \centering \begin{tabular}{ll} \toprule node & content\\ \midrule \cellcolor{gray!6}{D} & \cellcolor{gray!6}{Exactly one of the Beatles (John, Paul, George and Ringo) is dead.}\\ J & John is alive.\\ \cellcolor{gray!6}{P} & \cellcolor{gray!6}{Paul is alive.}\\ G & George is alive.\\ \cellcolor{gray!6}{R} & \cellcolor{gray!6}{Ringo is alive.}\\ \bottomrule \end{tabular} \end{table} \noindent \textbf{Desiderata.} The set consisting of all of these propositions is logically inconsistent (even though the propositions are pairwise consistent), so it seems quite intuitive that it should be incoherent. \vspace{2mm} \begin{description} \item[(below neutral)] \{\s{D,J,P,G,R}\} should be incoherent. \end{description} \vspace{2mm} We can make this desideratum a bit stronger by requiring that the coherence score for \{\s{D,J,P,G,R}\} should be minimal. \vspace{2mm} \begin{description} \item[(minimal)] \{\s{D,J,P,G,R}\} should get the lowest possible coherence value. \end{description} \vspace{2mm} \noindent One may argue that some coherence measures also measure the degree of incoherence, therefore logically inconsistent sets don't need to get the minimal score. We'll discuss this issue further in Section \ref{sec:mean}. \subsection{Alicja and books} Prima facie, at least some sets with low posterior probability can be quite coherent, and at least some sets with fairly high posterior probability can have low coherence. To keep track of how various measures perform with respect to this intuition, we developed the following example. We find the example and our intuitions about coherence here rather uncontroversial. \noindent \textbf{The scenario.} Alicja reads (\textsf{R}) 10\% of books she buys, but 15\% of books she buys that Rafal advised (\textsf{A}) her to read. Here, we just have two nodes: \begin{table}[H] \centering \begin{tabular}{ll} \toprule node & content\\ \midrule \cellcolor{gray!6}{A} & \cellcolor{gray!6}{Rafal adviced Alicja to read the book.}\\ R & Alicja read the book.\\ \bottomrule \end{tabular} \end{table} \noindent \textbf{Desiderata. } At least \emph{prima facie}, these conditions seem intuitive: \vspace{2mm} \begin{description} \item[($\s{AR}>\s{A}\neg\s{R}$)] Given that Alicja was advised to read, it's more coherent that she read the book than not. \item[($\s{AR}>\neg\s{AR}$) ] Given that Alicja read the book, it's more coherent that she was advised than not. \item[($\neg\s{A}\neg\s{R}>\s{A}\neg\s{R}$) ] Given that Alicja didn't read the book, it's more coherent that she wasn't advised than that she was. \item[($\neg\s{A}\neg\s{R}>\neg\s{AR}$)] Given that Alicja wasn't advised to read, it's more coherent that she didn't read the book than that she did. \end{description} \vspace{2mm} \subsection{The Witnesses} \textbf{The scenario.}This one comes from (Olsson, 2005, p. 391). Again, equally reliable witnesses try to identify a criminal. Consider the following reports (we extended the original scenario by adding \s{W5}): The problem might be seen as involving subsets of the following nodes: \begin{table}[H] \centering \begin{tabular}{ll} \toprule node & content\\ \midrule \cellcolor{gray!6}{W1} & \cellcolor{gray!6}{Witness no. 1: ‘‘Steve did it’’}\\ W2 & Witness no. 2: ‘‘Steve did it’’\\ \cellcolor{gray!6}{W3} & \cellcolor{gray!6}{Witness no. 3: ‘‘Steve, Martin or David did it’’}\\ W4 & Witness no. 4: ‘‘Steve, John or James did it’’\\ \cellcolor{gray!6}{W5} & \cellcolor{gray!6}{Wittness no. 5: ‘‘Steve, John or Peter did it’’}\\ D & Who committed the deed (6 possible values)\\ \bottomrule \end{tabular} \end{table} Note that this time each proposition has the structure ``Witness no. \(X\) claims that \dots" instead of explicitly stating the witness' testimony. \textbf{Desiderata.} First, we can observe that \s{W1} and \s{W2} fully agree. Testimonies of \s{W3} and \s{W4} overlap only partially, therefore it seems that \{\s{W1},\s{W2}\} is more coherent than \{\s{W3},\s{W4}\}. \vspace{2mm} \begin{description} \item[(\s{W1W2\textgreater W3W4})] \{\s{W1},\s{W2}\} should be more coherent than \{\s{W3},\s{W4}\}. \end{description} \vspace{2mm} Similarly, there is a greater agreement between \s{W4} and \s{W5} than \s{W3} and \s{W4}, so \{\s{W4},\s{W5}\} seems more coherent than \{\s{W3},\s{W4}\}. \vspace{2mm} \begin{description} \item[(\s{W4W5\textgreater W3W4})] \{\s{W4},\s{W5}\} should be more coherent than \{\s{W3},\s{W4}\}. \end{description} \vspace{2mm} \subsection{Depth} \textbf{The scenario.} There are eight equally likely suspects \(1, \dots, 8\), and three equally reliable witnesses \(a, b, c\), each trying to identify the person responsible for the crime. Compare two different situations -- \s{X1} and \s{X2}: \begin{align*} X_1 & = \{a:(1 \vee 2 \vee 3), b:(1\vee 2 \vee 4), c:(1 \vee 3 \vee 4)\}\\ X_2 & = \{a:(1 \vee 2 \vee 3), b:(1\vee 4 \vee 5), c:(1 \vee 6 \vee 7)\}\\ \end{align*} \noindent \textbf{Desiderata.} In \s{X1} witnesses' testimonies have bigger overlap, between each pair of the witnesses 2 suspects are the same, and in \s{X2} only 1 suspect is always the same. Following Schupbach (2008), one may have an intuition that the first situation is more coherent.\todo{add ref}\footnote{One might be worried that considerations of \emph{specificity} go against some of the desiderata. Specificity, along with relative overlap and positive relevance, is claimed to be a factor that plays a role in the assessment of comparative coherence. BOVENS \& HARTMANN give an example where witnesses point to numbered squares. In the first case, one witness indicates squares 21-20, and the other one squares 30-39. In the second case, the ranges are 3-82 and 19-98 respectively. They claim that while the overlap is higher in the second case, this is achieved by the testimonies being fairly unspecific, and so that such an increase in overlap should not result in an increase in coherence. The worry might be that disjunctions are less specific than their disjuncts and so specificity might be a relevant factor in cases such as \emph{the witnesses, japanese swords}, or \emph{depth}. It's not clear what the authors mean by specificity and why it should be a factor in coherence evaluation (instead of, say, posterior probability evaluation based on witness agreement). But say it in fact should, and further suppose, in line with the example, that specificity is proportional to the proportion of possible options excluded by a statement. Note now that in the desiderata that one might have concerns about, either specificity considerations do not have a say, because the compared claims are equally specific, or actually support the desideratum, because the narrations claimed to be more coherent also happen to be more specific. } \vspace{2mm} \begin{description} \item[(\s{X1\textgreater X2})] $X_1$ should be more coherent than $X_2$. \end{description} \vspace{2mm} \subsection{Dice} \textbf{The scenario.} A selection of similar scenarios has been discussed by Akiba (2000), T. Shogenji (2001), and Schippers \& Koscholke (2019). You're either tossing a regular die, or a dodecahedron, \(X\) is the result (there is nothing particular about this choice of dice; \emph{mutatis mutandis} this should hold for other possible pairs of dice as well). Consider the coherence of: \[D = \{X=2, (X=2\vee X=4)\}.\] \noindent \textbf{Desiderata.} In this scenario posterior conditional probabilities are fixed: getting 2 or 4 logically follows from getting 2 (\(P(X=2\vee X=4|X=2)=1\)), and you always have 50\% chance to get 2 given that the outcome was 2 or 4 (\(P(X=2|X=2\vee X=4)=0.5\)). Therefore, according to Schippers \& Koscholke (2019), the coherence of the set \s{D} shouldn't change no matter which die you use. \vspace{2mm} \begin{description} \item[(\s{D=const})] the coherence of \s{D} should not change. \end{description} \vspace{2mm} \section{Observations} \subsection{Coherence scores and outcomes} To be able to clearly see how well the existing measures of coherence deal with the mentioned desiderata, we decided to put all the results together. Our analysis extends the work of Koscholke (2016). In total we have analyzed 17 different desiderata and 7 candidates for a coherence measure (8 including ours, to be discussed later on). This required quite a lot of calculations which are unmanageable by hand, but the reader is invited to replicate our result by inspecting and running the code available in the online documentation. Our underlying strategy is to represent agent's credal states or narrations by means of Bayesian Networks (BNs). For each counterexample, we construct a directed acyclic graph (DAG) capturing natural directions of dependence between the relevant variables. This DAG underlies the BN we use for calculations. One side-effect of this strategy is that while in some cases all the probabilities needed for the construction of a BN were given by the authors, other BNs required some probabilities not specified by the authors. In such cases, we had to come up with fairly intuitive common-sense values. While one might object that this is problematic, we'd like to point out that all the examples present in the literature involve intuitive common-sense values and if this very fact is a problem, it is a problem for the whole discussion in general.\footnote{Moreover, one might insist that a sensitivity analysis should be performed to investigate the impact of such choices on the final results. Fair enough. However, while we did try out various ranges of values (with no undesirable outcome), a systematic pursuit of this goal lies beyond the scope of this paper, and the code we developed can be used as a tool for such investigations.} Each particular scenario is represented by a set of nodes --- usually binary ones, because they correspond to propositions which can be either true or false --- and their appropriate instantiations. Finally, we wrote general functions for each of the measures to calculate the coherence scores for all the scenarios we were interested in. In the following tables you can find coherence scores for various scenarios and measures, a summary of how the measures handle the desiderata, and their success rate for this list of challenges (\textsf{OG} stands for Olsson-Glass, \textsf{OGen} for Olsson-Glass generalized, \textsf{Sh} for Shogenji, \textsf{ShGen} for Shogenji generalized, \textsf{Fit} for Fitelson, \textsf{DM} for Douven-Meijs, \textsf{R} for Roche). \begin{table}[H] \centering \resizebox{\linewidth}{!}{ \begin{tabular}{lrrrrrrr} \toprule & OG & OGen & Sh & ShGen & Fit & DM & R\\ \midrule \cellcolor{gray!6}{Penguins: BGP 111} & \cellcolor{gray!6}{0.010} & \cellcolor{gray!6}{0.015} & \cellcolor{gray!6}{4.000} & \cellcolor{gray!6}{2.010} & \cellcolor{gray!6}{0.453} & \cellcolor{gray!6}{0.255} & \cellcolor{gray!6}{0.255}\\ Penguins: BG 11 & 0.010 & 0.010 & 0.040 & 0.040 & -0.960 & -0.480 & -0.480\\ \cellcolor{gray!6}{Penguins: BP 11} & \cellcolor{gray!6}{0.020} & \cellcolor{gray!6}{0.020} & \cellcolor{gray!6}{2.000} & \cellcolor{gray!6}{2.000} & \cellcolor{gray!6}{0.669} & \cellcolor{gray!6}{0.255} & \cellcolor{gray!6}{0.255}\\ Dunnit: MGWI 1111 & 0.000 & 0.087 & 4.294 & 11.012 & 0.169 & 0.167 & 0.167\\ \cellcolor{gray!6}{Dunnit: MTGWI 11111} & \cellcolor{gray!6}{0.000} & \cellcolor{gray!6}{0.042} & \cellcolor{gray!6}{73.836} & \cellcolor{gray!6}{13.669} & \cellcolor{gray!6}{0.385} & \cellcolor{gray!6}{0.150} & \cellcolor{gray!6}{0.150}\\ Japanese Swords 1: JO 11 & 0.004 & 0.004 & 80.251 & 80.251 & 0.976 & 0.008 & 0.008\\ \cellcolor{gray!6}{Japanese Swords 2: JO 11} & \cellcolor{gray!6}{0.818} & \cellcolor{gray!6}{0.818} & \cellcolor{gray!6}{9.000} & \cellcolor{gray!6}{9.000} & \cellcolor{gray!6}{0.976} & \cellcolor{gray!6}{0.800} & \cellcolor{gray!6}{0.800}\\ Japanese Swords 3: JO 11 & 0.818 & 0.818 & 1.080 & 1.080 & 0.286 & 0.067 & 0.067\\ \cellcolor{gray!6}{Robbers: MIsPMIsR 11} & \cellcolor{gray!6}{0.600} & \cellcolor{gray!6}{0.600} & \cellcolor{gray!6}{0.937} & \cellcolor{gray!6}{0.937} & \cellcolor{gray!6}{-0.143} & \cellcolor{gray!6}{-0.050} & \cellcolor{gray!6}{-0.050}\\ Robbers: MIsPMIsR 10 & 0.250 & 0.250 & 1.250 & 1.250 & 0.571 & 0.125 & 0.125\\ \cellcolor{gray!6}{Robbers: MIsPMIsR 01} & \cellcolor{gray!6}{0.250} & \cellcolor{gray!6}{0.250} & \cellcolor{gray!6}{1.250} & \cellcolor{gray!6}{1.250} & \cellcolor{gray!6}{0.571} & \cellcolor{gray!6}{0.125} & \cellcolor{gray!6}{0.125}\\ Beatles: JPGRD 11111 & 0.000 & 0.202 & 0.000 & 1.423 & -0.036 & 0.025 & 0.025\\ \cellcolor{gray!6}{Books: AR 11} & \cellcolor{gray!6}{0.014} & \cellcolor{gray!6}{0.014} & \cellcolor{gray!6}{1.493} & \cellcolor{gray!6}{1.493} & \cellcolor{gray!6}{0.212} & \cellcolor{gray!6}{0.027} & \cellcolor{gray!6}{0.027}\\ Books: AR 10 & 0.009 & 0.009 & 0.945 & 0.945 & -0.127 & -0.025 & -0.025\\ \cellcolor{gray!6}{Books: AR 01} & \cellcolor{gray!6}{0.100} & \cellcolor{gray!6}{0.100} & \cellcolor{gray!6}{0.995} & \cellcolor{gray!6}{0.995} & \cellcolor{gray!6}{-0.101} & \cellcolor{gray!6}{-0.003} & \cellcolor{gray!6}{-0.003}\\ Books: AR 00 & 0.892 & 0.892 & 1.001 & 1.001 & 0.016 & 0.001 & 0.001\\ \cellcolor{gray!6}{Witness: W1W2 11} & \cellcolor{gray!6}{0.451} & \cellcolor{gray!6}{0.451} & \cellcolor{gray!6}{3.551} & \cellcolor{gray!6}{3.551} & \cellcolor{gray!6}{0.771} & \cellcolor{gray!6}{0.446} & \cellcolor{gray!6}{0.446}\\ Witness: W3W4 11 & 0.187 & 0.187 & 0.740 & 0.740 & -0.234 & -0.110 & -0.110\\ \cellcolor{gray!6}{Witness: W4W5 11} & \cellcolor{gray!6}{0.365} & \cellcolor{gray!6}{0.365} & \cellcolor{gray!6}{1.260} & \cellcolor{gray!6}{1.260} & \cellcolor{gray!6}{0.218} & \cellcolor{gray!6}{0.110} & \cellcolor{gray!6}{0.110}\\ DepthA: T123T124 11 & 0.664 & 0.664 & 1.014 & 1.014 & 0.280 & 0.012 & 0.012\\ \cellcolor{gray!6}{DepthB: T123T145 11} & \cellcolor{gray!6}{0.331} & \cellcolor{gray!6}{0.331} & \cellcolor{gray!6}{0.996} & \cellcolor{gray!6}{0.996} & \cellcolor{gray!6}{-0.047} & \cellcolor{gray!6}{-0.003} & \cellcolor{gray!6}{-0.003}\\ Regular: TTF 11 & 0.500 & 0.500 & 3.000 & 3.000 & 0.833 & 0.500 & 0.500\\ \cellcolor{gray!6}{Dodecahedron: TTF 11} & \cellcolor{gray!6}{0.500} & \cellcolor{gray!6}{0.500} & \cellcolor{gray!6}{6.000} & \cellcolor{gray!6}{6.000} & \cellcolor{gray!6}{0.917} & \cellcolor{gray!6}{0.625} & \cellcolor{gray!6}{0.625}\\ \bottomrule \end{tabular}} \end{table} \begin{table}[H] \centering \resizebox{\linewidth}{!}{ \begin{tabular}{llllllll} \toprule & OG & OGen & Sh & ShGen & Fit & DM & R\\ \midrule \cellcolor{gray!6}{Penguins: BG$<$BGP} & \cellcolor{gray!6}{FALSE} & \cellcolor{gray!6}{TRUE} & \cellcolor{gray!6}{TRUE} & \cellcolor{gray!6}{TRUE} & \cellcolor{gray!6}{TRUE} & \cellcolor{gray!6}{TRUE} & \cellcolor{gray!6}{TRUE}\\ Penguins: BP$\approx$ BGP & TRUE & TRUE & FALSE & TRUE & FALSE & TRUE & TRUE\\ \cellcolor{gray!6}{Dunnit: Dunnit$<$Twin} & \cellcolor{gray!6}{FALSE} & \cellcolor{gray!6}{FALSE} & \cellcolor{gray!6}{TRUE} & \cellcolor{gray!6}{TRUE} & \cellcolor{gray!6}{TRUE} & \cellcolor{gray!6}{FALSE} & \cellcolor{gray!6}{FALSE}\\ Swords: JO2$>$JO1 & TRUE & TRUE & FALSE & FALSE & TRUE & TRUE & TRUE\\ \cellcolor{gray!6}{Swords: JO2$>$JO3} & \cellcolor{gray!6}{FALSE} & \cellcolor{gray!6}{FALSE} & \cellcolor{gray!6}{TRUE} & \cellcolor{gray!6}{TRUE} & \cellcolor{gray!6}{TRUE} & \cellcolor{gray!6}{TRUE} & \cellcolor{gray!6}{TRUE}\\ Robbers: PR$>$P$\neg$R & TRUE & TRUE & FALSE & FALSE & FALSE & FALSE & FALSE\\ \cellcolor{gray!6}{Robbers: PR$>$neutral} & \cellcolor{gray!6}{NA} & \cellcolor{gray!6}{NA} & \cellcolor{gray!6}{FALSE} & \cellcolor{gray!6}{FALSE} & \cellcolor{gray!6}{FALSE} & \cellcolor{gray!6}{FALSE} & \cellcolor{gray!6}{FALSE}\\ Beatles: below neutral & NA & NA & TRUE & FALSE & TRUE & FALSE & TRUE\\ \cellcolor{gray!6}{Beatles: minimal} & \cellcolor{gray!6}{TRUE} & \cellcolor{gray!6}{FALSE} & \cellcolor{gray!6}{TRUE} & \cellcolor{gray!6}{FALSE} & \cellcolor{gray!6}{FALSE} & \cellcolor{gray!6}{FALSE} & \cellcolor{gray!6}{FALSE}\\ Books: AR$>$A$\neg$R & TRUE & TRUE & TRUE & TRUE & TRUE & TRUE & TRUE\\ \cellcolor{gray!6}{Books: AR$>\neg$AR} & \cellcolor{gray!6}{FALSE} & \cellcolor{gray!6}{FALSE} & \cellcolor{gray!6}{TRUE} & \cellcolor{gray!6}{TRUE} & \cellcolor{gray!6}{TRUE} & \cellcolor{gray!6}{TRUE} & \cellcolor{gray!6}{TRUE}\\ Books: $\neg$A$\neg$R$>$A$\neg$R & TRUE & TRUE & TRUE & TRUE & TRUE & TRUE & TRUE\\ \cellcolor{gray!6}{Books: $\neg$A$\neg$R$>\neg$AR} & \cellcolor{gray!6}{TRUE} & \cellcolor{gray!6}{TRUE} & \cellcolor{gray!6}{TRUE} & \cellcolor{gray!6}{TRUE} & \cellcolor{gray!6}{TRUE} & \cellcolor{gray!6}{TRUE} & \cellcolor{gray!6}{TRUE}\\ Witness: W$_1$W$_2>$W$_3$W$_4$ & TRUE & TRUE & TRUE & TRUE & TRUE & TRUE & TRUE\\ \cellcolor{gray!6}{Witness: W$_4$W$_5>$W$_3$W$_4$} & \cellcolor{gray!6}{TRUE} & \cellcolor{gray!6}{TRUE} & \cellcolor{gray!6}{TRUE} & \cellcolor{gray!6}{TRUE} & \cellcolor{gray!6}{TRUE} & \cellcolor{gray!6}{TRUE} & \cellcolor{gray!6}{TRUE}\\ Depth: X$_1>$X$_2$ & TRUE & TRUE & TRUE & TRUE & TRUE & TRUE & TRUE\\ \cellcolor{gray!6}{Dodecahedron: Regular $=$ Dodecahedron} & \cellcolor{gray!6}{TRUE} & \cellcolor{gray!6}{TRUE} & \cellcolor{gray!6}{FALSE} & \cellcolor{gray!6}{FALSE} & \cellcolor{gray!6}{FALSE} & \cellcolor{gray!6}{FALSE} & \cellcolor{gray!6}{FALSE}\\ \bottomrule \end{tabular}} \end{table} \begin{table}[H] \centering \begin{tabular}{rrrrrrr} \toprule OG & OGen & Sh & ShGen & Fit & DM & R\\ \midrule \cellcolor{gray!6}{0.733} & \cellcolor{gray!6}{0.733} & \cellcolor{gray!6}{0.706} & \cellcolor{gray!6}{0.647} & \cellcolor{gray!6}{0.706} & \cellcolor{gray!6}{0.647} & \cellcolor{gray!6}{0.706}\\ \bottomrule \end{tabular} \end{table} Unfortunately, no measure was able to deal with all challenges. Note that the more recent measures, which were developed to improve on the previous ones, didn't really achieve a much higher success rate. Analysing these tables and various counterexamples, we noticed a few general issues. \subsection{Mean}\label{sec:mean} While the challenges have been discussed separately, considering some of them jointly also leads to an insight. Only one counterexample, \textsf{The Beatles}, is logically inconsistent. However, for each measure (except for the basic versions of Olsson's and Shogenji's, which are the earliest measures and unfortunately face other serious difficulties), there is a scenario that scored lower even though it was logically consistent. For example, the generalized Olsson's measure gives a lower value to the scenario that \textsf{Tweety is a bird and a penguin} than to \textsf{The Beatles scenario}. Other measures give lower values to the scenario with a \textsf{murderer who committed both pickpocketing and robbery} than to \textsf{The Beatles}. This result disagrees with our fundamental intuition that a coherence measure should keep track of logical consistency. Our hypothesis is that the cause of this issue is as follows. When you consider the measures that face this problem, you can notice that all of them use subsets of a set (or pairs thereof) and then take the average result calculated for these subsets or pairs of subsets. However, simply taking the mean of results so obtained might be misleading, because a few low values (for the inconsistent subsets), which indicate inconsistency, might be mixed with many positive values (especially if a set is large), and taking the mean of all such results might give a relatively high score, despite involving an inconsistency. Therefore, we believe that a candidate for a coherence measure shouldn't simply take mean mutual confirmation scores. \subsection{Structure} In the existing discussion, each scenario was represented as a set of propositions. However, it seems that usually we do not face sets of propositions but rather scenarios with some more or less explicit narration, which also indicates how the propositions are supposed to be connected. In other words, agents not only report their object-level beliefs, but also have some idea about their structure: which are supposed to support which. This relation rarely is universal in the powerset of the scenario (minus the empty set of course), and so considering support between all possible pairs of propositions in the scenario in calculating coherence might be unfair towards the agent. We penalize her for lack of support even between those propositions which she never thought supported each other. To notice that the selection and direction of support arrows matter, consider two agents whose claims are as follows: \vspace{2mm} \begin{center} \begin{tabular}{lp{9cm}} \textsf{Agent 1} & Tweety is a bird, more specifically a penguin. Because it’s a penguin, it doesn’t fly. \\ \textsf{Agent 2} & Tweety is a bird, and because it’s a bird, it doesn't fly. Therefore Tweety is a penguin. \\ \end{tabular} \end{center} \vspace{2mm} \noindent Even though both of them involve the same atomic propositions, the first narration makes much more sense, and it seems definitely more coherent. It is also quite clear that the difference between narrations lies in the explicitly stated direction of support. The approaches to coherence developed so far do not account for this difference. Moreover, it seems that when we present challenges and our intuitions about the desiderata, we implicitly assume the narration involved is the one that best fits with our background knowledge (so, Agent 1 rather Agent 2 in the case of penguins). However, coherence measures developed so far do not make such a fine-grained distinction between narrations, and so the scenario which states that \textit{Tweety is BGP} (bird, grounded, penguin) gets a lower score because, quite obviously, being a bird disconfirms being a grounded animal. In such a calculation it doesn't matter that no one even suggested this causal relationship. To illustrate this intuition, think about a picture puzzle. Just because a piece from the top right corner doesn't match a piece from the bottom left corner, it doesn't necessarily decrease the coherence of a complete picture. It just means you shouldn't evaluate how well the puzzle is prepared by putting these two pieces next to each other. We believe that only those directions of support which are indicated by the reporting agent, or by background knowledge, should be taken into account when measuring coherence. \section{Structured coherence} Based on these observations we developed our own measure, which we call \textit{structured coherence}. In this section we will describe how we manage to avoid the above mentioned problems. First, a general picture. Our coherence measure will be a function of a series of confirmation scores. This is in line with average mutual support measures which took the coherence of a set to be a function of confirmation scores. One key difference, however, is that average mutual support measures used confirmation scores for all disjoint pairs of non-empty subsets of a given set, and our measure will only rely on the confirmation scores for the support relations indicated by the BN representing a narration. This is because we don't think a narration should be punished for the lack of confirmation between elements that were never intended to be related. Specifically, for any state \(s\) of a child node \(C\) included in a narration, we are interested in the support provided to \(C=s\) by the combinations \(\mathsf{pa}_1, \cdots, \mathsf{pa}_n\) of possible states of its parents. We ignore \(\mathsf{pa}_i\) excluded by the narration. For any remaining combination \(\mathsf{pa}_r\), the pair \(\la C=s, \mathsf{pa}_r\ra\) is assigned a confirmation score, and this score is weighted using the marginal probability of \(\mathsf{pa}_r\). This gives us a set of confirmation scores. This set is then used to calculate coherence, but before we move on to this step, let's go over the earlier moves in a bit more detail. In our calculations we use the \s{Z} confirmation measure (see Crupi et al., 2007, for a detailed study and defense). It results from a normalization of many other measures (in the sense that whichever confirmation measure you start with, after appropriate normalization you end up with \s{Z}) and has nice mathematical properties, such as ranging over \([-1,1]\) and preservation of logical entailment and exclusion. It is defined for hypothesis \(H\) and evidence \(E\) as follows: \begin{align*} \mathsf{prior} & = \pr(H) \\ \mathsf{posterior} & = \pr(H \vert E)\\ \mathsf{d} & = \mathsf{posterior} - \mathsf{prior} \\ Z(\mathsf{posterior,prior}) & = \begin{cases} 0 & \text{if } \mathsf{prior} = \mathsf{posterior}\\ \mathsf{d}/(1-\mathsf{prior}) & \text{if } \mathsf{posterior} > \mathsf{prior} \\ \mathsf{d}/\mathsf{prior} & \text{o/w} \end{cases} \end{align*} \noindent Of course, it might be interesting to see what would happen with the coherence calculations if other confirmation measures are plugged in, but this is beyond the scope of this paper. We use BNs to model the directions of support indicated in the story. A scenario is represented as a selection of instantiated nodes. We'll follow an example as we proceed. The running example employs the BN we constructed for the first scenario in the \textsf{Witness} problem (Figure \ref{fig:w1w2} on page \pageref{fig:w1w2}). Both witnesses testify that Steve is the murderer. Two child nodes, \textsf{W1} and \textsf{W2} correspond to the two testimonies, and as part of the narration, are to be instantiated to \(1\). The root node, \textsf{D} prior to any update represents the agent's initial uncertainty about who committed the Deed (the prior distribution is uniform) and is not instantiated. \begin{itemize} \item To calculate the coherence of a scenario, first find all nodes that have at least one parent. In the example, these are \s{W1} and \s{W2}. \item For each parented node, list all combinations of its states and the states of its parents not excluded by the narration. We do it for \textsf{W1} in the table below this list (Table \ref{t:w1}), in the first two columns. We only consider cases in which \textsf{W1} holds, so we have 1s everywhere in the first column. However, the agent is not supposed to know who committed the deed, so all possible instantiations of \textsf{D} are listed. \item For each parented node and for each combination of possible states: get the prior probability of the child node and get the posterior probability of this child given the parent nodes with their fixed states. In our example the prior probability of \s{W1} is in column \textsf{priorC} (it is constant here), and the posterior probability of \textsf{W1} given different states of \textsf{D} is in column \s{post}. \item Use these values to calculate the \s{Z} confirmation measures. In our example, these values are in column \s{Z}. \item Get the joint probability of these parent node states. In typical cases, this is simply the prior probability. In cases in which narration nodes are actually pieces of evidence that one learns, these should be posterior probabilities obtained by instantiating the narration nodes in the BN and propagating. Such unusual cases will be discussed when we address the \textsf{Witness} problem. In our example, \textsf{priorA} gives the prior probabilities of various states of \textsf{D}, whereas \textsf{priorN} gives the distribution of \textsf{D} that we would obtain if we updated the BN with \textsf{W1} = \textsf{W2} = 1, that is, with the narration in question. \item Normalize these joint probabilities of the parent(s) so that all joint parent probabilities in the variant list add up to 1. In the example, \textsf{weightA} is the result of normalizing \textsf{priorA} and \textsf{weightN} is the result of normalizing \textsf{priorN} (in this case, the probabilities already add up to 1, so these moves don't change anything). \item Weight the Z score by this normalized probability, and sum these weighted Z scores, obtaining what we call the \emph{Expected Connection Strength} of the parented node under consideration. In our example, the last two columns weight \textsf{Z} using \textsf{weightA} and \textsf{weightN} respectively. In normal circumstances, \textsf{ECS} of \textsf{W1} would now be the sum of \textsf{aZ}, but --- as we discuss further on --- in this particular case we should use the updated weights, and so the \textsf{ECS} for \textsf{W1} is the sum of \textsf{nZ}. \end{itemize} As you can see, our approach is a bit similar to \textit{average mutual support} measures, but instead of calculating confirmation of each pair of disjoint subsets, we calculate it only for parents-child pairs. As a result we get a list of \textit{expected connections strengths} of each child in the BN. \begin{table} \begin{table}[H] \centering \resizebox{\linewidth}{!}{ \begin{tabular}{llrrrrrrrrr} \toprule W1 & D & priorC & post & priorA & priorN & weightA & weightN & Z & aZ & nZ\\ \midrule \cellcolor{gray!6}{1} & \cellcolor{gray!6}{Steve} & \cellcolor{gray!6}{0.175} & \cellcolor{gray!6}{0.80} & \cellcolor{gray!6}{0.167} & \cellcolor{gray!6}{0.981} & \cellcolor{gray!6}{0.167} & \cellcolor{gray!6}{0.981} & \cellcolor{gray!6}{0.758} & \cellcolor{gray!6}{0.126} & \cellcolor{gray!6}{0.743}\\ 1 & Martin & 0.175 & 0.05 & 0.167 & 0.004 & 0.167 & 0.004 & -0.714 & -0.119 & -0.003\\ \cellcolor{gray!6}{1} & \cellcolor{gray!6}{David} & \cellcolor{gray!6}{0.175} & \cellcolor{gray!6}{0.05} & \cellcolor{gray!6}{0.167} & \cellcolor{gray!6}{0.004} & \cellcolor{gray!6}{0.167} & \cellcolor{gray!6}{0.004} & \cellcolor{gray!6}{-0.714} & \cellcolor{gray!6}{-0.119} & \cellcolor{gray!6}{-0.003}\\ 1 & John & 0.175 & 0.05 & 0.167 & 0.004 & 0.167 & 0.004 & -0.714 & -0.119 & -0.003\\ \cellcolor{gray!6}{1} & \cellcolor{gray!6}{James} & \cellcolor{gray!6}{0.175} & \cellcolor{gray!6}{0.05} & \cellcolor{gray!6}{0.167} & \cellcolor{gray!6}{0.004} & \cellcolor{gray!6}{0.167} & \cellcolor{gray!6}{0.004} & \cellcolor{gray!6}{-0.714} & \cellcolor{gray!6}{-0.119} & \cellcolor{gray!6}{-0.003}\\ 1 & Peter & 0.175 & 0.05 & 0.167 & 0.004 & 0.167 & 0.004 & -0.714 & -0.119 & -0.003\\ \bottomrule \end{tabular}} \end{table} \caption{ECS calculation table for \s{W1} in the first scenario in the \s{Witness} problem.} \label{t:w1} \end{table} What do we do with the list of \textsf{ECS} scores thus obtained? For the reasons already discussed, we don't want to simply take the mean. The problem is a particular case of a common problem in statistics: how to represent a set of different values in a simple way without distorting the information too much? One easy and accurate solution is to plot all values. The problem is, it gives us no unambiguous way to compare different sets. For such tasks, a single score is desirable. In the context of measuring coherence of a scenario it seems that we should pay special attention to \s{mean}, \s{sd}, and \s{minimum}. The mean gives us an idea of how strong the average support between the elements is. Again, this is in line with the average mutual support measures. However, we also would like to penalise narrations in which support levels are more uneven. If the standard deviation is large, there are some support relations which are weaker than one might guess by looking only at the mean. This is analogous to the idea that merely looking at mean income is misleading if the group comprises three unemployed humans, a university lecturer and Bill Gates. When we look at a narration, special attention should be paid to weaker links, and the weaker such links are, the less trust should be placed in a narration. Presence of strong links doesn't have to make up for the impact of weak links --- after all, adding a logical consequence to a fairly incoherent narration shouldn't increase its coherence much. For this reason, if the standard deviation is high, relying on the mean would overestimate the lower support levels involved in a narration, and so we propose that the penalty to the score should be proportional to standard deviation. One straightforward way to achieve this, is to simply subtract standard deviation in the calculations.\footnote{Of course, there might be other ways to include the impact of standard deviation, but we think that before developing more complicated methods (which perhaps would be quite interesting) it is worthwhile to consider the most straightforward version first.} Moreover, it is crucial how weak the weakest link in a narration is. To take the simplest example, if two elements are logically incoherent, the whole narration is incoherent, even if some of its other elements cohere to a large degree. Imagine two narrations. In the first one, you have a case where all parent-child links except one get the maximal positive score. The remaining one gets the score of -1. We submit that the overall score should be -1. In the second narration all the relations take a value close to -1. We share the intuition that the narration still should have a higher overall score than -1. The presence of an element with the posterior that equals 0 (which is needed for \(Z\) confirmation being -1) destroys the coherence of an otherwise strong narration, and a narration containing such an element is in worse standing than simply a very weakly coherent one. So here's our stab at a mathematical explication of a coherence measure that satisfies the desiderata we just discussed. We are not deeply attached to its particularities and clearly other ways of achieving this goal may we worth pursuing. \begin{itemize} \item If all values are non-negative, i.e. each relation between parents and a child is supportive, then even the weakest point of a story is high enough not to care about it. In such cases we take $\s{mean} - \s{sd}$ as the final result. \item If, however, some values are negative, we need to be more careful. We still look at the difference $\s{mean} - \s{sd}$, but the lower the minimum, the less attention we should pay to it, and the more attention we should pay to the minimum. If the minimum is -1, we want to give it full weight, $1 = \vert \s{min}\vert = - \s{min}$ and ignore (weight by 0) $\s{mean} - \s{sd}$. In general, we propose to use $\vert \s{min}\vert$ as the weight assigned to the minimum, and $1-\vert \s{min}\vert$ to weight $\s{mean} - \s{sd}$. For instance, if the minimum is -0.8, the weight of $\s{mean} - \s{sd}$ should be $-0.8+1 = 0.2$, while if it is $-0.2$, this weight is $0.8$.\footnote{Again, there are other ways to mathematically capture the intuition that the lower minimum, the more attention is to be paid to it, but we decided to take the most straightforward way of doing so for a ride.} Note that $1-\vert \s{min}\vert = 1-\vert \s{min}\vert = 1 - (- \s{min}) = 1+\s{min}$, and so the formula is: \end{itemize} Thus, the full formula is as follows: \footnotesize \begin{align*} \mathsf{Structured}(\mathsf{ECS}) & = \begin{cases} \left[\mathsf{mean}(\mathsf{ECS}) - \textsf{sd}(\mathsf{ECS})\right] \times \left(\textsf{min}(\mathsf{ECS})+1 \right) - \textsf{min}(\mathsf{ECS})^2 & \text{if } min(\mathsf{ECS})<0 \\\mathsf{mean}(\mathsf{ECS}) - \textsf{sd}(\mathsf{ECS}) & \text{o/w} \end{cases} \end{align*} \normalsize This function has a desired property which was missing in most of the other coherence measures. Whenever we encounter a logically inconsistent story, i.e.~a story with the lowest possible minimum (in our measure it is -1), we'll end up with -1 also as the final score. The achieved results are also plausible if the minimum is close to the lowest possible value. Now, let's take this coherence measure for a ride. \section{Handling counterexamples} Using the notation and desiderata already introduced, let's go over BNs for the counterexamples involved, and use the counterexamples to evaluate the performace of the new measure. \subsection{Penguins} We used the distribution used in the original formulation to build three BNs corresponding to the narrations at play (Fig. \ref{fig:BGP}-\ref{fig:BP}).\footnote{Not without concerns. There are around 18 000 species of birds, and around 60 of them are flightless. We couldn't find information about counts, but it seems the probability of being a penguin if one is grounded is overestimated by philosophers. Also, there are many things that are not grounded but are not birds, mostly insects, and there's plenty of them. We did spend some time coming up with plausible ranges of probabilities to correct for such factors, and none of them actually makes a difference to the main point. So, for the sake of simplicity, we leave the original unrealistic distribution in our discussion.} \begin{figure} \hspace{2cm}\scalebox{0.8}{\begin{subfigure}[!ht]{0.4\textwidth} \begin{center}\includegraphics[width=1\linewidth]{coherencePaperRevised_files/figure-latex/unnamed-chunk-12-1} \end{center} \end{subfigure}} \hfill \hspace{-3cm}\begin{subfigure}[!ht]{0.7\textwidth} \begin{table}[H] \centering \begin{tabular}{lr} \toprule B & Pr\\ \midrule \cellcolor{gray!6}{1} & \cellcolor{gray!6}{0.5}\\ 0 & 0.5\\ \bottomrule \end{tabular} \end{table} \begin{table}[H] \centering \begin{tabular}{lrr} \toprule \multicolumn{1}{c}{P} & \multicolumn{2}{c}{B} \\ & 1 & 0\\ \midrule \cellcolor{gray!6}{1} & \cellcolor{gray!6}{0.02} & \cellcolor{gray!6}{0}\\ 0 & 0.98 & 1\\ \bottomrule \end{tabular} \end{table} \begin{table}[H] \centering \begin{tabular}{lllr} \toprule \multicolumn{1}{c}{} & \multicolumn{1}{c}{B} & \multicolumn{1}{c}{P} & \multicolumn{1}{c}{} \\ G & & & Pr\\ \midrule \cellcolor{gray!6}{1} & \cellcolor{gray!6}{1} & \cellcolor{gray!6}{1} & \cellcolor{gray!6}{1.00}\\ 0 & 1 & 1 & 0.00\\ \cellcolor{gray!6}{1} & \cellcolor{gray!6}{0} & \cellcolor{gray!6}{1} & \cellcolor{gray!6}{0.00}\\ 0 & 0 & 1 & 1.00\\ \cellcolor{gray!6}{1} & \cellcolor{gray!6}{1} & \cellcolor{gray!6}{0} & \cellcolor{gray!6}{0.00}\\ 0 & 1 & 0 & 1.00\\ \cellcolor{gray!6}{1} & \cellcolor{gray!6}{0} & \cellcolor{gray!6}{0} & \cellcolor{gray!6}{0.98}\\ 0 & 0 & 0 & 0.02\\ \bottomrule \end{tabular} \end{table} \end{subfigure} \caption{Bayesian network for the \textsf{BGP} scenario.} \label{fig:BGP} \end{figure} \begin{figure} \hspace{2cm}\scalebox{0.6}{ \begin{subfigure}[!ht]{0.4\textwidth} \begin{center}\includegraphics[width=0.7\linewidth]{coherencePaperRevised_files/figure-latex/unnamed-chunk-14-1} \end{center} \end{subfigure} } \hfill \hspace{-3cm}\begin{subfigure}[!ht]{0.7\textwidth} \begin{table}[H] \centering \begin{tabular}{lr} \toprule B & Pr\\ \midrule \cellcolor{gray!6}{1} & \cellcolor{gray!6}{0.5}\\ 0 & 0.5\\ \bottomrule \end{tabular} \end{table} \begin{table}[H] \centering \begin{tabular}{lrr} \toprule \multicolumn{1}{c}{G} & \multicolumn{2}{c}{B} \\ & 1 & 0\\ \midrule \cellcolor{gray!6}{1} & \cellcolor{gray!6}{0.02} & \cellcolor{gray!6}{0.98}\\ 0 & 0.98 & 0.02\\ \bottomrule \end{tabular} \end{table} \end{subfigure} \label{fig-BG} \caption{Bayesian network for the \textsf{BG} scenario.} \end{figure} \begin{figure} \scalebox{0.6}{ \hspace{4cm}\begin{subfigure}[!ht]{0.4\textwidth} \begin{center}\includegraphics{coherencePaperRevised_files/figure-latex/unnamed-chunk-16-1} \end{center} \end{subfigure}} \hfill \hspace{-3cm}\begin{subfigure}[!ht]{0.7\textwidth} \begin{table}[H] \centering \begin{tabular}{lr} \toprule B & Pr\\ \midrule \cellcolor{gray!6}{1} & \cellcolor{gray!6}{0.5}\\ 0 & 0.5\\ \bottomrule \end{tabular} \end{table} \begin{table}[H] \centering \begin{tabular}{lrr} \toprule \multicolumn{1}{c}{P} & \multicolumn{2}{c}{B} \\ & 1 & 0\\ \midrule \cellcolor{gray!6}{1} & \cellcolor{gray!6}{0.02} & \cellcolor{gray!6}{0}\\ 0 & 0.98 & 1\\ \bottomrule \end{tabular} \end{table} \end{subfigure} \caption{Bayesian network for the \textsf{BP} scenario.} \label{fig:BP} \end{figure}\newpage Now, let's calculate the coherences and see if the desiderata are satisfied (the abbreviations we already used are as before, and \textsf{S} stands for \emph{Structured}, our coherence measure): \begin{table}[H] \centering \resizebox{\linewidth}{!}{ \begin{tabular}{lrrrrrrrr} \toprule & OG & OGen & Sh & ShGen & Fit & DM & R & S\\ \midrule \cellcolor{gray!6}{Penguins: BGP 111} & \cellcolor{gray!6}{0.01} & \cellcolor{gray!6}{0.015} & \cellcolor{gray!6}{4.00} & \cellcolor{gray!6}{2.01} & \cellcolor{gray!6}{0.453} & \cellcolor{gray!6}{0.255} & \cellcolor{gray!6}{0.255} & \cellcolor{gray!6}{0.01}\\ Penguins: BG 11 & 0.01 & 0.010 & 0.04 & 0.04 & -0.960 & -0.480 & -0.480 & -0.96\\ \cellcolor{gray!6}{Penguins: BP 11} & \cellcolor{gray!6}{0.02} & \cellcolor{gray!6}{0.020} & \cellcolor{gray!6}{2.00} & \cellcolor{gray!6}{2.00} & \cellcolor{gray!6}{0.669} & \cellcolor{gray!6}{0.255} & \cellcolor{gray!6}{0.255} & \cellcolor{gray!6}{0.01}\\ \bottomrule \end{tabular}} \end{table} \begin{table}[H] \centering \resizebox{\linewidth}{!}{ \begin{tabular}{lllllllll} \toprule & OG & OGen & Sh & ShGen & Fit & DM & R & S\\ \midrule \cellcolor{gray!6}{Penguins: BG$<$BGP} & \cellcolor{gray!6}{FALSE} & \cellcolor{gray!6}{TRUE} & \cellcolor{gray!6}{TRUE} & \cellcolor{gray!6}{TRUE} & \cellcolor{gray!6}{TRUE} & \cellcolor{gray!6}{TRUE} & \cellcolor{gray!6}{TRUE} & \cellcolor{gray!6}{TRUE}\\ Penguins: BP$\approx$ BGP & TRUE & TRUE & FALSE & TRUE & FALSE & TRUE & TRUE & TRUE\\ \bottomrule \end{tabular}} \end{table} \subsection{Dunnit}\label{dunnit-1} Here, we deal with two separate BNs. One, before the \textsf{Twin} node is even considered (Fig. \ref{fig:twinless}), and one with the \textsf{Twin} node (Fig. \ref{fig:twin}). The CPTs for the no-twin version are in agreement with those in the ones in the Twin case. Since the original example didn't specify exact probabilities, we came up with some plausible values. \begin{figure} \scalebox{1.7}{ \begin{subfigure}[!ht]{0.3\textwidth} \begin{center}\includegraphics[width=0.7\linewidth]{coherencePaperRevised_files/figure-latex/unnamed-chunk-19-1} \end{center} \end{subfigure}} \hspace{-0.8cm}\begin{subfigure}[!ht]{0.2\textwidth} \begin{table}[H] \centering \begin{tabular}{lr} \toprule M & Pr\\ \midrule \cellcolor{gray!6}{1} & \cellcolor{gray!6}{0.4}\\ 0 & 0.6\\ \bottomrule \end{tabular} \end{table} \begin{table}[H] \centering \begin{tabular}{lrr} \toprule \multicolumn{1}{c}{G} & \multicolumn{2}{c}{M} \\ & 1 & 0\\ \midrule \cellcolor{gray!6}{1} & \cellcolor{gray!6}{0.05} & \cellcolor{gray!6}{0.005}\\ 0 & 0.95 & 0.995\\ \bottomrule \end{tabular} \end{table} \end{subfigure} \hspace{0.5cm}\begin{subfigure}[!ht]{0.2\textwidth} \begin{table}[H] \centering \begin{tabular}{lrr} \toprule \multicolumn{1}{c}{I} & \multicolumn{2}{c}{G} \\ & 1 & 0\\ \midrule \cellcolor{gray!6}{1} & \cellcolor{gray!6}{0.8} & \cellcolor{gray!6}{0.005}\\ 0 & 0.2 & 0.995\\ \bottomrule \end{tabular} \end{table} \begin{table}[H] \centering \begin{tabular}{lrr} \toprule \multicolumn{1}{c}{W} & \multicolumn{2}{c}{G} \\ & 1 & 0\\ \midrule \cellcolor{gray!6}{1} & \cellcolor{gray!6}{0.012} & \cellcolor{gray!6}{0.207}\\ 0 & 0.988 & 0.793\\ \bottomrule \end{tabular} \end{table} \end{subfigure} \caption{Twin-less BN for the \textsf{Dunnit} problem.} \label{fig:twinless} \end{figure} \begin{figure} \scalebox{1.7}{ \begin{subfigure}[!ht]{0.4\textwidth} \begin{center}\includegraphics[width=0.7\linewidth]{coherencePaperRevised_files/figure-latex/unnamed-chunk-22-1} \end{center} \end{subfigure}} \hspace{-1cm}\begin{subfigure}[!ht]{0.3\textwidth} \begin{table}[H] \centering \begin{tabular}{lllr} \toprule \multicolumn{1}{c}{} & \multicolumn{1}{c}{G} & \multicolumn{1}{c}{Tw} & \multicolumn{1}{c}{} \\ W & & & Pr\\ \midrule \cellcolor{gray!6}{1} & \cellcolor{gray!6}{1} & \cellcolor{gray!6}{1} & \cellcolor{gray!6}{0.200}\\ 0 & 1 & 1 & 0.800\\ \cellcolor{gray!6}{1} & \cellcolor{gray!6}{0} & \cellcolor{gray!6}{1} & \cellcolor{gray!6}{0.400}\\ 0 & 0 & 1 & 0.600\\ \cellcolor{gray!6}{1} & \cellcolor{gray!6}{1} & \cellcolor{gray!6}{0} & \cellcolor{gray!6}{0.005}\\ 0 & 1 & 0 & 0.995\\ \cellcolor{gray!6}{1} & \cellcolor{gray!6}{0} & \cellcolor{gray!6}{0} & \cellcolor{gray!6}{0.200}\\ 0 & 0 & 0 & 0.800\\ \bottomrule \end{tabular} \end{table} \end{subfigure} \caption{BN for the \textsf{Dunnit} problem. The key difference for the twin version lies in the construction of the CPT for \textsf{W}. The table gives conditional probabilities for \textsf{W} given various joint states of \textsf{Tw} and \textsf{G}.} \label{fig:twin} \end{figure} \newpage Coherence calculations result in the following: \begin{table}[H] \centering \resizebox{\linewidth}{!}{ \begin{tabular}{lrrrrrrrr} \toprule & OG & OGen & Sh & ShGen & Fit & DM & R & S\\ \midrule \cellcolor{gray!6}{Dunnit: MGWI 1111} & \cellcolor{gray!6}{0} & \cellcolor{gray!6}{0.087} & \cellcolor{gray!6}{4.294} & \cellcolor{gray!6}{11.012} & \cellcolor{gray!6}{0.169} & \cellcolor{gray!6}{0.167} & \cellcolor{gray!6}{0.167} & \cellcolor{gray!6}{-0.932}\\ Dunnit: MTGWI 11111 & 0 & 0.042 & 73.836 & 13.669 & 0.385 & 0.150 & 0.150 & -0.100\\ \bottomrule \end{tabular}} \end{table} \begin{table}[H] \centering \resizebox{\linewidth}{!}{ \begin{tabular}{lllllllll} \toprule & OG & OGen & Sh & ShGen & Fit & DM & R & S\\ \midrule \cellcolor{gray!6}{Dunnit: Dunnit$<$Twin} & \cellcolor{gray!6}{FALSE} & \cellcolor{gray!6}{FALSE} & \cellcolor{gray!6}{TRUE} & \cellcolor{gray!6}{TRUE} & \cellcolor{gray!6}{TRUE} & \cellcolor{gray!6}{FALSE} & \cellcolor{gray!6}{FALSE} & \cellcolor{gray!6}{TRUE}\\ \bottomrule \end{tabular}} \end{table} \subsection{Japanese swords}\label{japanese-swords-1} There is a common DAG for the three scenarios, but the CPTs differ (Fig. \ref{fig:japanese}). \begin{figure} \scalebox{0.5}{ \hspace{2.5cm}\begin{subfigure}[!ht]{0.4\textwidth} \begin{center}\includegraphics[width=0.7\linewidth]{coherencePaperRevised_files/figure-latex/unnamed-chunk-25-1} \end{center} \end{subfigure}} \hfill \begin{subfigure}[!ht]{0.6\textwidth} \begin{table}[H] \centering \begin{tabular}{lr} \toprule J & Pr\\ \midrule \cellcolor{gray!6}{1} & \cellcolor{gray!6}{0}\\ 0 & 1\\ \bottomrule \end{tabular} \end{table} \begin{table}[H] \centering \begin{tabular}{lrr} \toprule \multicolumn{1}{c}{O} & \multicolumn{2}{c}{J} \\ & 1 & 0\\ \midrule \cellcolor{gray!6}{1} & \cellcolor{gray!6}{0.008} & \cellcolor{gray!6}{0}\\ 0 & 0.992 & 1\\ \bottomrule \end{tabular} \end{table} \caption{Scenario 1.} \end{subfigure} \begin{subfigure}[!ht]{0.4\textwidth} \begin{table}[H] \centering \begin{tabular}{lr} \toprule J & Pr\\ \midrule \cellcolor{gray!6}{1} & \cellcolor{gray!6}{0.1}\\ 0 & 0.9\\ \bottomrule \end{tabular} \end{table} \begin{table}[H] \centering \begin{tabular}{lrr} \toprule \multicolumn{1}{c}{O} & \multicolumn{2}{c}{J} \\ & 1 & 0\\ \midrule \cellcolor{gray!6}{1} & \cellcolor{gray!6}{0.9} & \cellcolor{gray!6}{0.011}\\ 0 & 0.1 & 0.989\\ \bottomrule \end{tabular} \end{table} \caption{Scenario 2.} \end{subfigure} \hfill \begin{subfigure}[!ht]{0.6\textwidth} \begin{table}[H] \centering \begin{tabular}{lr} \toprule J & Pr\\ \midrule \cellcolor{gray!6}{1} & \cellcolor{gray!6}{0.833}\\ 0 & 0.167\\ \bottomrule \end{tabular} \end{table} \begin{table}[H] \centering \begin{tabular}{lrr} \toprule \multicolumn{1}{c}{O} & \multicolumn{2}{c}{J} \\ & 1 & 0\\ \midrule \cellcolor{gray!6}{1} & \cellcolor{gray!6}{0.9} & \cellcolor{gray!6}{0.5}\\ 0 & 0.1 & 0.5\\ \bottomrule \end{tabular} \end{table} \caption{Scenario 3.} \end{subfigure} \caption{A common DAG and three sets of CPTs for the \textsf{Japanese Swords} problem.} \label{fig:japanese} \end{figure} \newpage Coherence calculations yield: \begin{table}[H] \centering \resizebox{\linewidth}{!}{ \begin{tabular}{lrrrrrrrr} \toprule & OG & OGen & Sh & ShGen & Fit & DM & R & S\\ \midrule \cellcolor{gray!6}{Japanese Swords 1: JO 11} & \cellcolor{gray!6}{0.004} & \cellcolor{gray!6}{0.004} & \cellcolor{gray!6}{80.251} & \cellcolor{gray!6}{80.251} & \cellcolor{gray!6}{0.976} & \cellcolor{gray!6}{0.008} & \cellcolor{gray!6}{0.008} & \cellcolor{gray!6}{0.008}\\ Japanese Swords 2: JO 11 & 0.818 & 0.818 & 9.000 & 9.000 & 0.976 & 0.800 & 0.800 & 0.889\\ \cellcolor{gray!6}{Japanese Swords 3: JO 11} & \cellcolor{gray!6}{0.818} & \cellcolor{gray!6}{0.818} & \cellcolor{gray!6}{1.080} & \cellcolor{gray!6}{1.080} & \cellcolor{gray!6}{0.286} & \cellcolor{gray!6}{0.067} & \cellcolor{gray!6}{0.067} & \cellcolor{gray!6}{0.400}\\ \bottomrule \end{tabular}} \end{table} \begin{table}[H] \centering \resizebox{\linewidth}{!}{ \begin{tabular}{lllllllll} \toprule & OG & OGen & Sh & ShGen & Fit & DM & R & S\\ \midrule \cellcolor{gray!6}{Swords: JO2$>$JO1} & \cellcolor{gray!6}{TRUE} & \cellcolor{gray!6}{TRUE} & \cellcolor{gray!6}{FALSE} & \cellcolor{gray!6}{FALSE} & \cellcolor{gray!6}{TRUE} & \cellcolor{gray!6}{TRUE} & \cellcolor{gray!6}{TRUE} & \cellcolor{gray!6}{TRUE}\\ Swords: JO2$>$JO3 & FALSE & FALSE & TRUE & TRUE & TRUE & TRUE & TRUE & TRUE\\ \bottomrule \end{tabular}} \end{table} \subsection{Robbers}\label{robbers-1} The robbers counterexample involves a phenomenon we've already seen: it is not clear whether the information about the prior probabilities is supposed to be part of the narration or not. If we want to include this information in our coherence assessment, we can do this employing a single BN. \begin{figure} \begin{subfigure}[!ht]{0.4\textwidth} \begin{center}\includegraphics{coherencePaperRevised_files/figure-latex/unnamed-chunk-30-1} \end{center} \end{subfigure} \hfill \begin{subfigure}[!ht]{0.6\textwidth} \begin{table}[H] \centering\begingroup\fontsize{9}{11}\selectfont \begin{tabular}{lr} \toprule & Pr\\ \midrule \cellcolor{gray!6}{OnlyP} & \cellcolor{gray!6}{0.2}\\ OnlyR & 0.2\\ \cellcolor{gray!6}{Both} & \cellcolor{gray!6}{0.6}\\ \bottomrule \end{tabular} \endgroup{} \end{table} \begin{table}[H] \centering\begingroup\fontsize{9}{11}\selectfont \begin{tabular}{lrrr} \toprule \multicolumn{1}{c}{MisP} & \multicolumn{3}{c}{WhoMurdered} \\ & OnlyP & OnlyR & Both\\ \midrule \cellcolor{gray!6}{1} & \cellcolor{gray!6}{1} & \cellcolor{gray!6}{0} & \cellcolor{gray!6}{1}\\ 0 & 0 & 1 & 0\\ \bottomrule \end{tabular} \endgroup{} \end{table} \begin{table}[H] \centering\begingroup\fontsize{9}{11}\selectfont \begin{tabular}{lrrr} \toprule \multicolumn{1}{c}{MisR} & \multicolumn{3}{c}{WhoMurdered} \\ & OnlyP & OnlyR & Both\\ \midrule \cellcolor{gray!6}{1} & \cellcolor{gray!6}{0} & \cellcolor{gray!6}{1} & \cellcolor{gray!6}{1}\\ 0 & 1 & 0 & 0\\ \bottomrule \end{tabular} \endgroup{} \end{table} \end{subfigure} \caption{BN for the \textsf{Robbers} problem.} \label{fig:Robbers} \end{figure} \newpage Coherence calculations yield the following results: \begin{table}[H] \centering \resizebox{\linewidth}{!}{ \begin{tabular}{lrrrrrrrr} \toprule & OG & OGen & Sh & ShGen & Fit & DM & R & S\\ \midrule Robbers: MIsPMIsR 11 & 0.60 & 0.60 & 0.937 & 0.937 & -0.143 & -0.050 & -0.050 & 0.6\\ Robbers: MIsPMIsR 10 & 0.25 & 0.25 & 1.250 & 1.250 & 0.571 & 0.125 & 0.125 & -0.6\\ Robbers: MIsPMIsR 01 & 0.25 & 0.25 & 1.250 & 1.250 & 0.571 & 0.125 & 0.125 & -0.6\\ \bottomrule \end{tabular}} \end{table} \begin{table}[H] \centering \resizebox{\linewidth}{!}{ \begin{tabular}{lllllllll} \toprule & OG & OGen & Sh & ShGen & Fit & DM & R & S\\ \midrule Robbers: PR$>$P$\neg$R & TRUE & TRUE & FALSE & FALSE & FALSE & FALSE & FALSE & TRUE\\ Robbers: PR$>$neutral & NA & NA & FALSE & FALSE & FALSE & FALSE & FALSE & TRUE\\ \bottomrule \end{tabular}} \end{table} \subsection{The Beatles}\label{the-beatles-1} \begin{figure} \scalebox{1.6}{ \begin{subfigure}[!ht]{0.4\textwidth} \begin{center}\includegraphics[width=0.7\linewidth]{coherencePaperRevised_files/figure-latex/unnamed-chunk-33-1} \end{center} \end{subfigure}} \hfill \begin{subfigure}[!ht]{0.4\textwidth} \begin{table}[H] \centering \begin{tabular}{lr} \toprule G & Pr\\ \midrule \cellcolor{gray!6}{1} & \cellcolor{gray!6}{0.5}\\ 0 & 0.5\\ \bottomrule \end{tabular} \end{table} \end{subfigure} \caption{Bayesian network for the \textsf{Beatles} scenario.} \end{figure} We assume the prior probability of each individual band member being dead to 0.5 (as in the above table), and the CPT for \textsf{D} is many-dimensional and so difficult to present concisely, but the method is straigtforward: probability 1 is given to \textsf{D} in all combinations of the parents in which exactly one is true, and otherwise \textsf{D} gets conditional probability 0. Coherence calculations give the following results: \begin{table}[H] \centering \resizebox{\linewidth}{!}{ \begin{tabular}{lrrrrrrrr} \toprule & OG & OGen & Sh & ShGen & Fit & DM & R & S\\ \midrule \cellcolor{gray!6}{Beatles: JPGRD 11111} & \cellcolor{gray!6}{0} & \cellcolor{gray!6}{0.202} & \cellcolor{gray!6}{0} & \cellcolor{gray!6}{1.423} & \cellcolor{gray!6}{-0.036} & \cellcolor{gray!6}{0.025} & \cellcolor{gray!6}{0.025} & \cellcolor{gray!6}{-1}\\ \bottomrule \end{tabular}} \end{table} \begin{table}[H] \centering \resizebox{\linewidth}{!}{ \begin{tabular}{lllllllll} \toprule & OG & OGen & Sh & ShGen & Fit & DM & R & S\\ \midrule \cellcolor{gray!6}{Beatles: below neutral} & \cellcolor{gray!6}{NA} & \cellcolor{gray!6}{NA} & \cellcolor{gray!6}{TRUE} & \cellcolor{gray!6}{FALSE} & \cellcolor{gray!6}{TRUE} & \cellcolor{gray!6}{FALSE} & \cellcolor{gray!6}{TRUE} & \cellcolor{gray!6}{TRUE}\\ Beatles: minimal & TRUE & FALSE & TRUE & FALSE & FALSE & FALSE & FALSE & TRUE\\ \bottomrule \end{tabular}} \end{table} \subsection{Alicja and books}\label{alicja-and-books-1} The BN is fairly straightforward (Fig. \ref{fig:books}) and the results are as follows: \begin{figure} \hspace{20mm} \scalebox{0.5}{\begin{subfigure}[!ht]{0.4\textwidth} \begin{center}\includegraphics{coherencePaperRevised_files/figure-latex/unnamed-chunk-36-1} \end{center} \end{subfigure}} \hfill \begin{subfigure}[!ht]{0.6\textwidth} \begin{table}[H] \centering \begin{tabular}{lr} \toprule A & Pr\\ \midrule \cellcolor{gray!6}{1} & \cellcolor{gray!6}{0.01}\\ 0 & 0.99\\ \bottomrule \end{tabular} \end{table} \begin{table}[H] \centering \begin{tabular}{lrr} \toprule \multicolumn{1}{c}{R} & \multicolumn{2}{c}{A} \\ & 1 & 0\\ \midrule \cellcolor{gray!6}{1} & \cellcolor{gray!6}{0.15} & \cellcolor{gray!6}{0.1}\\ 0 & 0.85 & 0.9\\ \bottomrule \end{tabular} \end{table} \end{subfigure} \caption{Bayesian network for the \textsf{Books} problem.} \label{fig:books} \end{figure} \begin{table}[H] \centering \resizebox{\linewidth}{!}{ \begin{tabular}{lrrrrrrrr} \toprule & OG & OGen & Sh & ShGen & Fit & DM & R & S\\ \midrule \cellcolor{gray!6}{Books: AR 11} & \cellcolor{gray!6}{0.014} & \cellcolor{gray!6}{0.014} & \cellcolor{gray!6}{1.493} & \cellcolor{gray!6}{1.493} & \cellcolor{gray!6}{0.212} & \cellcolor{gray!6}{0.027} & \cellcolor{gray!6}{0.027} & \cellcolor{gray!6}{0.055}\\ Books: AR 10 & 0.009 & 0.009 & 0.945 & 0.945 & -0.127 & -0.025 & -0.025 & -0.055\\ \cellcolor{gray!6}{Books: AR 01} & \cellcolor{gray!6}{0.100} & \cellcolor{gray!6}{0.100} & \cellcolor{gray!6}{0.995} & \cellcolor{gray!6}{0.995} & \cellcolor{gray!6}{-0.101} & \cellcolor{gray!6}{-0.003} & \cellcolor{gray!6}{-0.003} & \cellcolor{gray!6}{-0.005}\\ Books: AR 00 & 0.892 & 0.892 & 1.001 & 1.001 & 0.016 & 0.001 & 0.001 & 0.005\\ \bottomrule \end{tabular}} \end{table} \begin{table}[H] \centering \resizebox{\linewidth}{!}{ \begin{tabular}{lllllllll} \toprule & OG & OGen & Sh & ShGen & Fit & DM & R & S\\ \midrule \cellcolor{gray!6}{Books: AR$>$A$\neg$R} & \cellcolor{gray!6}{TRUE} & \cellcolor{gray!6}{TRUE} & \cellcolor{gray!6}{TRUE} & \cellcolor{gray!6}{TRUE} & \cellcolor{gray!6}{TRUE} & \cellcolor{gray!6}{TRUE} & \cellcolor{gray!6}{TRUE} & \cellcolor{gray!6}{TRUE}\\ Books: AR$>\neg$AR & FALSE & FALSE & TRUE & TRUE & TRUE & TRUE & TRUE & TRUE\\ \cellcolor{gray!6}{Books: $\neg$A$\neg$R$>$A$\neg$R} & \cellcolor{gray!6}{TRUE} & \cellcolor{gray!6}{TRUE} & \cellcolor{gray!6}{TRUE} & \cellcolor{gray!6}{TRUE} & \cellcolor{gray!6}{TRUE} & \cellcolor{gray!6}{TRUE} & \cellcolor{gray!6}{TRUE} & \cellcolor{gray!6}{TRUE}\\ Books: $\neg$A$\neg$R$>\neg$AR & TRUE & TRUE & TRUE & TRUE & TRUE & TRUE & TRUE & TRUE\\ \bottomrule \end{tabular}} \end{table} \subsection{The witnesses}\label{the-witnesses-1} Two requirements are associated with this example: both \(\{\)\textsf{W1, W2}\(\}\) and \(\{\)\textsf{W4, W5}\(\}\) should be more coherent than \(\{\)\textsf{W3, W4}\(\}\). The basic idea behind the CPTs we used is that for any particular witness we take the probability of them including the perpetrator in their list to be 0.8, and the probability of including an innocent to be .05. Of course, the example can be run with different conditional probability tables. Let's first take a look at the BN for the first scenario (Fig. \ref{fig:w1w2}). \begin{figure} \scalebox{1.2}{ \hspace{1cm}\begin{subfigure}[!ht]{0.4\textwidth} \begin{center}\includegraphics[width=1\linewidth]{coherencePaperRevised_files/figure-latex/unnamed-chunk-39-1} \end{center} \end{subfigure}} \hfill \begin{subfigure}[!ht]{0.3\textwidth} \begin{table}[H] \centering \begin{tabular}{lr} \toprule D & Pr\\ \midrule \cellcolor{gray!6}{Steve} & \cellcolor{gray!6}{0.167}\\ Martin & 0.167\\ \cellcolor{gray!6}{David} & \cellcolor{gray!6}{0.167}\\ John & 0.167\\ \cellcolor{gray!6}{James} & \cellcolor{gray!6}{0.167}\\ Peter & 0.167\\ \bottomrule \end{tabular} \end{table} \end{subfigure} \centering \begin{subfigure}[!ht]{0.3\textwidth} \begin{table}[H] \centering\begin{table}[H] \centering \begin{tabular}{lrrrrrr} \toprule \multicolumn{1}{c}{W1} & \multicolumn{2}{c}{D} \\ & Steve & Martin & David & John & James & Peter\\ \midrule \cellcolor{gray!6}{\cellcolor{gray!6}{1}} & \cellcolor{gray!6}{\cellcolor{gray!6}{0.8}} & \cellcolor{gray!6}{\cellcolor{gray!6}{0.05}} & \cellcolor{gray!6}{\cellcolor{gray!6}{0.05}} & \cellcolor{gray!6}{\cellcolor{gray!6}{0.05}} & \cellcolor{gray!6}{\cellcolor{gray!6}{0.05}} & \cellcolor{gray!6}{\cellcolor{gray!6}{0.05}}\\ 0 & 0.2 & 0.95 & 0.95 & 0.95 & 0.95 & 0.95\\ \bottomrule \end{tabular} \end{table} \end{table} \end{subfigure} \caption{BN for the \textsf{W1W2} narration in the \textsf{Witness} problem. CPT for \textsf{W2} is identical to the one for \textsf{W1}.} \label{fig:w1w2} \end{figure} The CPT for \textsf{D} is uniform. The table for \textsf{W1} provides the conditional probability of \textsf{W1} listing (\textsf{W1}=1) or not listing (\textsf{W1}=0) a particular person given that the actual value of \textsf{D} is Steve/Martin/\dots. The underlying rule is: if someone is guilty, a witness will mention them with probability \(.8\), and if they aren't, they will be listed with probability \(.05\). In the remaining two BNs for the problem the CPT for \textsf{D} remains the same, and the CPTs for the witness nodes are analogous to the one for \textsf{W1}. The remaining BNs have the following obvious DAGs (Fig. \ref{fig:witness}). \begin{figure}\centering \scalebox{1.2}{ \begin{subfigure}[!ht]{0.4\textwidth} \begin{center}\includegraphics[width=1\linewidth]{coherencePaperRevised_files/figure-latex/unnamed-chunk-42-1} \end{center} \end{subfigure}} \scalebox{1.2}{\begin{subfigure}[!ht]{0.4\textwidth} \begin{center}\includegraphics[width=1\linewidth]{coherencePaperRevised_files/figure-latex/unnamed-chunk-43-1} \end{center} \end{subfigure}} \caption{Two remaining DAGs for the \textsf{Witness} problem.} \label{fig:witness} \end{figure} \newpage We think that what this example illustrates is that we should really carefully think about whose cognitive perspective is taken when we represent a narration using a BN, focusing on whether the BN involves nodes which are not part of the narration whose coherence is to be evaluated. In particular, the probabilistic information about the uniform distribution of guilt probability is not part of any of the three involved narrations, but rather a part of a third-person set-up prior to obtaining any evidence. To evaluate the coherence of a narration, at least for unmentioned assumptions that one doesn't have strong independent reasons to keep, one should think counterfactually, granting the consequences of the narration and asking what would happen if it indeed was true. In our case, a judge who evaluates the coherence of witness testimonies once she has heard them, no longer thinks that the distribution of \textsf{D} is uniform. And this agrees with the counterfactual strategy we just described: it is a consequence of the probabilistic set-up and the content of \textsf{W1} and \textsf{W2} that if \textsf{W1} and \textsf{W2} were true, the distribution for \textsf{D} no longer would be uniform, and so it is unfair to judge the coherence of this scenario without giving up this assumption and updating one's assumptions about \textsf{D}. In such a case, we think, we should update \textsf{D} to what it would be had \textsf{W1} and \textsf{W2} be instantiated with 1s: \begin{table}[H] \centering \begin{tabular}{lrrrrrr} \toprule & Steve & Martin & David & John & James & Peter\\ \midrule \cellcolor{gray!6}{Pr} & \cellcolor{gray!6}{0.981} & \cellcolor{gray!6}{0.004} & \cellcolor{gray!6}{0.004} & \cellcolor{gray!6}{0.004} & \cellcolor{gray!6}{0.004} & \cellcolor{gray!6}{0.004}\\ \bottomrule \end{tabular} \end{table} \noindent and use these updated probabilities to build the weights used in our coherence calculations for this narration (and proceed accordingly, instead updating on another set of narration nodes in the coherence evaluation of other narrations).\footnote{Note however that you should not simply instantiate the BN with \textsf{W1} and \textsf{W2}, propagate and run the coherence calculations on the updated BN. Then both these nodes would get 1s in their respective CPTs and coherence calculations would make all confirmation measures involved in such calculations based on posterior probability equal 1. If narration members have probability one, no other information will be able to confirm it.} Once this strategy is taken, the problem turns out to be not that challenging for any of the coherence measures under discussion. \begin{table}[H] \centering \resizebox{\linewidth}{!}{ \begin{tabular}{lrrrrrrrr} \toprule & OG & OGen & Sh & ShGen & Fit & DM & R & S\\ \midrule \cellcolor{gray!6}{Witness: W1W2 11} & \cellcolor{gray!6}{0.451} & \cellcolor{gray!6}{0.451} & \cellcolor{gray!6}{3.551} & \cellcolor{gray!6}{3.551} & \cellcolor{gray!6}{0.771} & \cellcolor{gray!6}{0.446} & \cellcolor{gray!6}{0.446} & \cellcolor{gray!6}{0.729}\\ Witness: W3W4 11 & 0.187 & 0.187 & 0.740 & 0.740 & -0.234 & -0.110 & -0.110 & 0.494\\ \cellcolor{gray!6}{Witness: W4W5 11} & \cellcolor{gray!6}{0.365} & \cellcolor{gray!6}{0.365} & \cellcolor{gray!6}{1.260} & \cellcolor{gray!6}{1.260} & \cellcolor{gray!6}{0.218} & \cellcolor{gray!6}{0.110} & \cellcolor{gray!6}{0.110} & \cellcolor{gray!6}{0.602}\\ \bottomrule \end{tabular}} \end{table} \begin{table}[H] \centering \resizebox{\linewidth}{!}{ \begin{tabular}{lllllllll} \toprule & OG & OGen & Sh & ShGen & Fit & DM & R & S\\ \midrule \cellcolor{gray!6}{Witness: W$_1$W$_2>$W$_3$W$_4$} & \cellcolor{gray!6}{TRUE} & \cellcolor{gray!6}{TRUE} & \cellcolor{gray!6}{TRUE} & \cellcolor{gray!6}{TRUE} & \cellcolor{gray!6}{TRUE} & \cellcolor{gray!6}{TRUE} & \cellcolor{gray!6}{TRUE} & \cellcolor{gray!6}{TRUE}\\ Witness: W$_4$W$_5>$W$_3$W$_4$ & TRUE & TRUE & TRUE & TRUE & TRUE & TRUE & TRUE & TRUE\\ \bottomrule \end{tabular}} \end{table} \subsection{Depth}\label{depth-1} We start with representing the two scenarios with two fairly natural BNs (\textsf{C} stands for who Committed the crime, \textsf{TXYZ} stands for Testimony that \(X\vee Y \vee Z\)), see Fig. \ref{fig:dod1} and \ref{fig:dod2}. \begin{figure} \scalebox{1.7}{ \begin{subfigure}[!ht]{0.4\textwidth} \begin{center}\includegraphics[width=0.7\linewidth]{coherencePaperRevised_files/figure-latex/unnamed-chunk-46-1} \end{center} \end{subfigure}} \hspace{-1cm}\scalebox{0.6}{\begin{subfigure}[!ht]{0.3\textwidth} \begin{table}[H] \centering \begin{tabular}{lr} \toprule C & Pr\\ \midrule \cellcolor{gray!6}{1} & \cellcolor{gray!6}{0.125}\\ 2 & 0.125\\ \cellcolor{gray!6}{3} & \cellcolor{gray!6}{0.125}\\ 4 & 0.125\\ \cellcolor{gray!6}{5} & \cellcolor{gray!6}{0.125}\\ 6 & 0.125\\ \cellcolor{gray!6}{7} & \cellcolor{gray!6}{0.125}\\ 8 & 0.125\\ \bottomrule \end{tabular} \end{table} \begin{table}[H] \centering \begin{tabular}{lrrrrrrrr} \toprule \multicolumn{1}{c}{T123} & \multicolumn{2}{c}{C} \\ & 1 & 2 & 3 & 4 & 5 & 6 & 7 & 8\\ \midrule \cellcolor{gray!6}{1} & \cellcolor{gray!6}{1} & \cellcolor{gray!6}{1} & \cellcolor{gray!6}{1} & \cellcolor{gray!6}{0} & \cellcolor{gray!6}{0} & \cellcolor{gray!6}{0} & \cellcolor{gray!6}{0} & \cellcolor{gray!6}{0}\\ 0 & 0 & 0 & 0 & 1 & 1 & 1 & 1 & 1\\ \bottomrule \end{tabular} \end{table} \begin{table}[H] \centering \begin{tabular}{lrrrrrrrr} \toprule \multicolumn{1}{c}{T124} & \multicolumn{2}{c}{C} \\ & 1 & 2 & 3 & 4 & 5 & 6 & 7 & 8\\ \midrule \cellcolor{gray!6}{1} & \cellcolor{gray!6}{1} & \cellcolor{gray!6}{1} & \cellcolor{gray!6}{0} & \cellcolor{gray!6}{1} & \cellcolor{gray!6}{0} & \cellcolor{gray!6}{0} & \cellcolor{gray!6}{0} & \cellcolor{gray!6}{0}\\ 0 & 0 & 0 & 1 & 0 & 1 & 1 & 1 & 1\\ \bottomrule \end{tabular} \end{table} \begin{table}[H] \centering \begin{tabular}{lrrrrrrrr} \toprule \multicolumn{1}{c}{T134} & \multicolumn{2}{c}{C} \\ & 1 & 2 & 3 & 4 & 5 & 6 & 7 & 8\\ \midrule \cellcolor{gray!6}{1} & \cellcolor{gray!6}{1} & \cellcolor{gray!6}{0} & \cellcolor{gray!6}{1} & \cellcolor{gray!6}{1} & \cellcolor{gray!6}{0} & \cellcolor{gray!6}{0} & \cellcolor{gray!6}{0} & \cellcolor{gray!6}{0}\\ 0 & 0 & 1 & 0 & 0 & 1 & 1 & 1 & 1\\ \bottomrule \end{tabular} \end{table} \end{subfigure}} \caption{BN for \textsf{X1} in the \textsf{Depth} problem.} \label{fig:dod1} \end{figure} \begin{figure} \scalebox{1.7}{ \begin{subfigure}[!ht]{0.4\textwidth} \begin{center}\includegraphics[width=0.7\linewidth]{coherencePaperRevised_files/figure-latex/unnamed-chunk-48-1} \end{center} \end{subfigure}} \hspace{-1cm}\scalebox{0.6}{\begin{subfigure}[!ht]{0.3\textwidth} \begin{table}[H] \centering \begin{tabular}{lr} \toprule C & Pr\\ \midrule \cellcolor{gray!6}{1} & \cellcolor{gray!6}{0.125}\\ 2 & 0.125\\ \cellcolor{gray!6}{3} & \cellcolor{gray!6}{0.125}\\ 4 & 0.125\\ \cellcolor{gray!6}{5} & \cellcolor{gray!6}{0.125}\\ 6 & 0.125\\ \cellcolor{gray!6}{7} & \cellcolor{gray!6}{0.125}\\ 8 & 0.125\\ \bottomrule \end{tabular} \end{table} \begin{table}[H] \centering \begin{tabular}{lrrrrrrrr} \toprule \multicolumn{1}{c}{T123} & \multicolumn{2}{c}{C} \\ & 1 & 2 & 3 & 4 & 5 & 6 & 7 & 8\\ \midrule \cellcolor{gray!6}{1} & \cellcolor{gray!6}{1} & \cellcolor{gray!6}{1} & \cellcolor{gray!6}{1} & \cellcolor{gray!6}{0} & \cellcolor{gray!6}{0} & \cellcolor{gray!6}{0} & \cellcolor{gray!6}{0} & \cellcolor{gray!6}{0}\\ 0 & 0 & 0 & 0 & 1 & 1 & 1 & 1 & 1\\ \bottomrule \end{tabular} \end{table} \begin{table}[H] \centering \begin{tabular}{lrrrrrrrr} \toprule \multicolumn{1}{c}{T145} & \multicolumn{2}{c}{C} \\ & 1 & 2 & 3 & 4 & 5 & 6 & 7 & 8\\ \midrule \cellcolor{gray!6}{1} & \cellcolor{gray!6}{1} & \cellcolor{gray!6}{0} & \cellcolor{gray!6}{0} & \cellcolor{gray!6}{1} & \cellcolor{gray!6}{1} & \cellcolor{gray!6}{0} & \cellcolor{gray!6}{0} & \cellcolor{gray!6}{0}\\ 0 & 0 & 1 & 1 & 0 & 0 & 1 & 1 & 1\\ \bottomrule \end{tabular} \end{table} \begin{table}[H] \centering \begin{tabular}{lrrrrrrrr} \toprule \multicolumn{1}{c}{T167} & \multicolumn{2}{c}{C} \\ & 1 & 2 & 3 & 4 & 5 & 6 & 7 & 8\\ \midrule \cellcolor{gray!6}{1} & \cellcolor{gray!6}{1} & \cellcolor{gray!6}{0} & \cellcolor{gray!6}{0} & \cellcolor{gray!6}{0} & \cellcolor{gray!6}{0} & \cellcolor{gray!6}{1} & \cellcolor{gray!6}{1} & \cellcolor{gray!6}{0}\\ 0 & 0 & 1 & 1 & 1 & 1 & 0 & 0 & 1\\ \bottomrule \end{tabular} \end{table} \end{subfigure}} \caption{BN for \textsf{X2} in the \textsf{Depth} problem.} \label{fig:dod2} \end{figure} \newpage One effect of dropping the ``the witness testified that'' and using the testimony contents themselves is that the CPTs for the narration nodes are deterministically connected with the root node. In result, the coherence calculations give in the following: \begin{table}[H] \centering \resizebox{\linewidth}{!}{ \begin{tabular}{lrrrrrrrrr} \toprule & OG & OGen & Sh & ShGen & Fit & DM & R & S1 & S2\\ \midrule \cellcolor{gray!6}{Depth: T123T124T134 111} & \cellcolor{gray!6}{0.250} & \cellcolor{gray!6}{0.438} & \cellcolor{gray!6}{2.37} & \cellcolor{gray!6}{1.926} & \cellcolor{gray!6}{0.382} & \cellcolor{gray!6}{0.198} & \cellcolor{gray!6}{0.198} & \cellcolor{gray!6}{-0.25} & \cellcolor{gray!6}{1}\\ Depth: T123T145T167 111 & 0.143 & 0.186 & 2.37 & 1.259 & 0.343 & 0.188 & 0.188 & -0.25 & 1\\ \bottomrule \end{tabular}} \end{table} \begin{table}[H] \centering \resizebox{\linewidth}{!}{ \begin{tabular}{llllllllll} \toprule & OG & OGen & Sh & ShGen & Fit & DM & R & S1 & S2\\ \midrule \cellcolor{gray!6}{Depth: X$_1>$X$_2$} & \cellcolor{gray!6}{TRUE} & \cellcolor{gray!6}{TRUE} & \cellcolor{gray!6}{FALSE} & \cellcolor{gray!6}{TRUE} & \cellcolor{gray!6}{TRUE} & \cellcolor{gray!6}{TRUE} & \cellcolor{gray!6}{TRUE} & \cellcolor{gray!6}{FALSE} & \cellcolor{gray!6}{FALSE}\\ \bottomrule \end{tabular}} \end{table} Note that this time we listed two values for our measure. \textsf{Structured 1} shows the values obtained if we do not update the weighting of the node not included in the narration, and \textsf{Structured 2} is the result of such an updated weighing (analogous to the updating involved in the \textsf{Witness} problem). Now, what are we to make of this? \textsf{Structured 1} is negative. This isn't too surprising: after all, this is the coherence of the narration with the probabilistic assumption that the distribution for \textsf{C} is uniform, and this probabilistic assumption undermines the narration. Why, however, does \textsf{Structured 2} equal 1, and why are the results identical for both narrations? This, upon reflection, isn't too suprising either. If the BN and the narration is supposed to represent a single agent's credal state, there is only one state of \textsf{C} in which the whole narration \(X_1\) is true -- trivially, it is the one in which suspect 1 is guilty, and it is the same unique state of \textsf{C} in which the whole narration \(X_2\) is true. Since seen as narrations these sets have exactly the same truth conditions, there is no surprise in them being equally coherent. What if the sentences in the set are not claims made by one agent and there is no single underlying credal state? We aren't convinced that our tool is optimal for measuring the agreement of multiple witnesses. Instead, there already exists a working measure of such an agreement --- Cohen's \(\kappa\) -- which already gives the desired results. To illustrate, let's think of a simplified situation (devoid of three-dimensional tables) with two witnesses \(w1\) and \(w2\), where the respective sets are \(A = \{1 \vee 2 \vee 3, 1\vee 2 \vee 4\}\) and \(B = \{1 \vee 2 \vee 3, 1\vee 4 \vee 5\}\) and in each set the first proposition comes from \(w1\) and the second from \(w2\). The information for these two sets can be tabulated as follows: \begin{table}[H] \centering \begin{tabular}{lrr} \toprule & w2: suspect & w2: innocent\\ \midrule \cellcolor{gray!6}{w1:suspect} & \cellcolor{gray!6}{2} & \cellcolor{gray!6}{1}\\ w1: innocent & 1 & 4\\ \bottomrule \end{tabular} \end{table} \begin{table}[H] \centering \begin{tabular}{lrr} \toprule & w2: suspect & w2: innocent\\ \midrule \cellcolor{gray!6}{w1: suspect} & \cellcolor{gray!6}{1} & \cellcolor{gray!6}{2}\\ w1: innocent & 2 & 3\\ \bottomrule \end{tabular} \end{table} \noindent Standard calculations using the \textsf{vcd} package results in the following unweighted values of Cohen's \(\kappa\). \begin{table}[H] \centering \begin{tabular}{lrr} \toprule & A & B\\ \midrule \cellcolor{gray!6}{value} & \cellcolor{gray!6}{0.467} & \cellcolor{gray!6}{-0.067}\\ \bottomrule \end{tabular} \end{table} Let's further illustrate our point about the requirement that the BN should represent a single agent's cognitive state. For instance, you can represent, the situation in \(A\) from the perspective of the first witness. This suggests we should focus only on the nodes involved in the narration, and on the fact that from the witness' perspective the suspects are not equally likely. The example doesn't provide us enough information to build a table for \textsf{C}. In fact, no information about the witness attitude towards this node is given, but given they say what they say, it's unlikely they think the distribution is uniform. So let's take one of the witness' own statements as the root (which ones we choose doesn't change the outcome). Clearly (or, at least, hopefully, if we talk about witnesses), the agent thinks her own claim is very likely and evaluates the probability of the other statements in \(A\) or \(B\) from its perspective. This gives us two different BNs, and when we calculate the respective coherences we actually do get the desired result, which isn't too hard for the other measures either. \begin{figure} \hspace{2cm}\scalebox{0.6}{ \begin{subfigure}[!ht]{0.3\textwidth} \begin{center}\includegraphics[width=1\linewidth]{coherencePaperRevised_files/figure-latex/unnamed-chunk-53-1} \end{center} \end{subfigure} }\hfill \begin{subfigure}[!ht]{0.6\textwidth} \begin{table}[H] \centering \begin{tabular}{lr} \toprule T123 & Pr\\ \midrule \cellcolor{gray!6}{1} & \cellcolor{gray!6}{0.98}\\ 0 & 0.02\\ \bottomrule \end{tabular} \end{table} \begin{table}[H] \centering\begingroup\fontsize{9}{11}\selectfont \begin{tabular}{lrr} \toprule \multicolumn{1}{c}{T124} & \multicolumn{2}{c}{T123} \\ & 1 & 0\\ \midrule \cellcolor{gray!6}{1} & \cellcolor{gray!6}{0.667} & \cellcolor{gray!6}{0.2}\\ 0 & 0.333 & 0.8\\ \bottomrule \end{tabular} \endgroup{} \end{table} \end{subfigure} \caption{A witness perspective for the \textsf{agreement} problem, set $A$.} \end{figure} \begin{figure} \hspace{2cm}\scalebox{0.6}{ \begin{subfigure}[!ht]{0.3\textwidth} \begin{center}\includegraphics[width=1\linewidth]{coherencePaperRevised_files/figure-latex/unnamed-chunk-55-1} \end{center} \end{subfigure}} \hfill \begin{subfigure}[!ht]{0.6\textwidth} \begin{table}[H] \centering \begin{tabular}{lr} \toprule T123 & Pr\\ \midrule \cellcolor{gray!6}{1} & \cellcolor{gray!6}{0.98}\\ 0 & 0.02\\ \bottomrule \end{tabular} \end{table} \begin{table}[H] \centering\begingroup\fontsize{9}{11}\selectfont \begin{tabular}{lrr} \toprule \multicolumn{1}{c}{T124} & \multicolumn{2}{c}{T123} \\ & 1 & 0\\ \midrule \cellcolor{gray!6}{1} & \cellcolor{gray!6}{0.333} & \cellcolor{gray!6}{0.4}\\ 0 & 0.667 & 0.6\\ \bottomrule \end{tabular} \endgroup{} \end{table} \end{subfigure} \caption{A witness perspective for the \textsf{agreement} problem, set $B$.} \end{figure} \newpage \begin{table}[H] \centering \resizebox{\linewidth}{!}{ \begin{tabular}{lrrrrrrrr} \toprule & OG & OGen & Sh & ShGen & Fit & DM & R & S\\ \midrule \cellcolor{gray!6}{DepthA: T123T124 11} & \cellcolor{gray!6}{0.664} & \cellcolor{gray!6}{0.664} & \cellcolor{gray!6}{1.014} & \cellcolor{gray!6}{1.014} & \cellcolor{gray!6}{0.280} & \cellcolor{gray!6}{0.012} & \cellcolor{gray!6}{0.012} & \cellcolor{gray!6}{0.027}\\ DepthB: T123T145 11 & 0.331 & 0.331 & 0.996 & 0.996 & -0.047 & -0.003 & -0.003 & -0.004\\ \bottomrule \end{tabular}} \end{table} \begin{table}[H] \centering \resizebox{\linewidth}{!}{ \begin{tabular}{lllllllll} \toprule & OG & OGen & Sh & ShGen & Fit & DM & R & S\\ \midrule \cellcolor{gray!6}{Depth: X$_1>$X$_2$} & \cellcolor{gray!6}{TRUE} & \cellcolor{gray!6}{TRUE} & \cellcolor{gray!6}{TRUE} & \cellcolor{gray!6}{TRUE} & \cellcolor{gray!6}{TRUE} & \cellcolor{gray!6}{TRUE} & \cellcolor{gray!6}{TRUE} & \cellcolor{gray!6}{TRUE}\\ \bottomrule \end{tabular}} \end{table} \subsection{Dice}\label{dice-1} We'll follow the strategy similar to the one we already used. Since neither the example nor the narrations involve information about how probable it is that we're dealing with a regular die, as opposed to a dodecahedron, we avoid using a node representing this. Moreover, if at a given time the agent claims that the result is both two and (two or four), their cognitive situation at that time cannot be represented using uniform distribution for possible toss outcomes. Instead, we start with initial separate BNs for a regular die and a dodecahedron which do have uniform distributions for the \textsf{O} (outcome) node (Fig. \ref{fig:diceBN}), but when weighing the antedecent nodes which are not strictly speaking part of the narration, we use the probabilities updated in light of the narration content itself. \begin{figure} \scalebox{1.3}{\begin{subfigure}[!ht]{0.3\textwidth} \begin{center}\includegraphics[width=1\linewidth]{coherencePaperRevised_files/figure-latex/unnamed-chunk-58-1} \end{center} \end{subfigure}} \hspace{0.2cm}\begin{subfigure}[!ht]{0.25\textwidth} \begin{table}[H] \centering \begin{tabular}{lr} \toprule O & Pr\\ \midrule \cellcolor{gray!6}{1} & \cellcolor{gray!6}{0.167}\\ 2 & 0.167\\ \cellcolor{gray!6}{3} & \cellcolor{gray!6}{0.167}\\ 4 & 0.167\\ \cellcolor{gray!6}{5} & \cellcolor{gray!6}{0.167}\\ 6 & 0.167\\ \bottomrule \end{tabular} \end{table} \caption{Root CPT for the regular die.} \end{subfigure} \hspace{0.2cm} \begin{subfigure}[!ht]{0.25\textwidth} \begin{table}[H] \centering \begin{tabular}{lr} \toprule O & Pr\\ \midrule \cellcolor{gray!6}{1} & \cellcolor{gray!6}{0.083}\\ 2 & 0.083\\ \cellcolor{gray!6}{3} & \cellcolor{gray!6}{0.083}\\ 4 & 0.083\\ \cellcolor{gray!6}{5} & \cellcolor{gray!6}{0.083}\\ 6 & 0.083\\ \cellcolor{gray!6}{7} & \cellcolor{gray!6}{0.083}\\ 8 & 0.083\\ \cellcolor{gray!6}{9} & \cellcolor{gray!6}{0.083}\\ 10 & 0.083\\ \cellcolor{gray!6}{11} & \cellcolor{gray!6}{0.083}\\ 12 & 0.083\\ \bottomrule \end{tabular} \end{table} \caption{Root CPT for the dodecahedron.} \end{subfigure} \begin{subfigure}[!ht]{0.25\textwidth} \begin{table}[H] \centering \begin{tabular}{lrrrrrr} \toprule \multicolumn{1}{c}{T} & \multicolumn{2}{c}{O} \\ & 1 & 2 & 3 & 4 & 5 & 6\\ \midrule \cellcolor{gray!6}{1} & \cellcolor{gray!6}{0} & \cellcolor{gray!6}{1} & \cellcolor{gray!6}{0} & \cellcolor{gray!6}{0} & \cellcolor{gray!6}{0} & \cellcolor{gray!6}{0}\\ 0 & 1 & 0 & 1 & 1 & 1 & 1\\ \bottomrule \end{tabular} \end{table} \begin{table}[H] \centering \begin{tabular}{lrrrrrr} \toprule \multicolumn{1}{c}{TF} & \multicolumn{2}{c}{O} \\ & 1 & 2 & 3 & 4 & 5 & 6\\ \midrule \cellcolor{gray!6}{1} & \cellcolor{gray!6}{0} & \cellcolor{gray!6}{1} & \cellcolor{gray!6}{0} & \cellcolor{gray!6}{1} & \cellcolor{gray!6}{0} & \cellcolor{gray!6}{0}\\ 0 & 1 & 0 & 1 & 0 & 1 & 1\\ \bottomrule \end{tabular} \end{table} \caption{Conditional probabilities for the regular die.} \end{subfigure} \hfill \scalebox{0.8}{\begin{subfigure}[!ht]{0.7\textwidth} \begin{table}[H] \centering \begin{tabular}{lrrrrrrrrrrrr} \toprule \multicolumn{1}{c}{T} & \multicolumn{2}{c}{O} \\ & 1 & 2 & 3 & 4 & 5 & 6 & 7 & 8 & 9 & 10 & 11 & 12\\ \midrule \cellcolor{gray!6}{1} & \cellcolor{gray!6}{0} & \cellcolor{gray!6}{1} & \cellcolor{gray!6}{0} & \cellcolor{gray!6}{0} & \cellcolor{gray!6}{0} & \cellcolor{gray!6}{0} & \cellcolor{gray!6}{0} & \cellcolor{gray!6}{0} & \cellcolor{gray!6}{0} & \cellcolor{gray!6}{0} & \cellcolor{gray!6}{0} & \cellcolor{gray!6}{0}\\ 0 & 1 & 0 & 1 & 1 & 1 & 1 & 1 & 1 & 1 & 1 & 1 & 1\\ \bottomrule \end{tabular} \end{table} \begin{table}[H] \centering \begin{tabular}{lrrrrrrrrrrrr} \toprule \multicolumn{1}{c}{TF} & \multicolumn{2}{c}{O} \\ & 1 & 2 & 3 & 4 & 5 & 6 & 7 & 8 & 9 & 10 & 11 & 12\\ \midrule \cellcolor{gray!6}{1} & \cellcolor{gray!6}{0} & \cellcolor{gray!6}{1} & \cellcolor{gray!6}{0} & \cellcolor{gray!6}{1} & \cellcolor{gray!6}{0} & \cellcolor{gray!6}{0} & \cellcolor{gray!6}{0} & \cellcolor{gray!6}{0} & \cellcolor{gray!6}{0} & \cellcolor{gray!6}{0} & \cellcolor{gray!6}{0} & \cellcolor{gray!6}{0}\\ 0 & 1 & 0 & 1 & 0 & 1 & 1 & 1 & 1 & 1 & 1 & 1 & 1\\ \bottomrule \end{tabular} \end{table} \caption{\large Conditional probabilities for the dodecahedron.} \end{subfigure}} \caption{BNs for the \textsf{dice} problem.} \label{fig:diceBN} \end{figure} \newpage Calculation of coherences of the scenarios in the respective BNs yield the following result: \begin{table}[H] \centering \resizebox{\linewidth}{!}{ \begin{tabular}{lrrrrrrrr} \toprule & OG & OGen & Sh & ShGen & Fit & DM & R & S\\ \midrule \cellcolor{gray!6}{Regular: TTF 11} & \cellcolor{gray!6}{0.5} & \cellcolor{gray!6}{0.5} & \cellcolor{gray!6}{3} & \cellcolor{gray!6}{3} & \cellcolor{gray!6}{0.833} & \cellcolor{gray!6}{0.500} & \cellcolor{gray!6}{0.500} & \cellcolor{gray!6}{1}\\ Dodecahedron: TTF 11 & 0.5 & 0.5 & 6 & 6 & 0.917 & 0.625 & 0.625 & 1\\ \bottomrule \end{tabular}} \end{table} \begin{table}[H] \centering \resizebox{\linewidth}{!}{ \begin{tabular}{lllllllll} \toprule & OG & OGen & Sh & ShGen & Fit & DM & R & S\\ \midrule \cellcolor{gray!6}{Dodecahedron: Regular $=$ Dodecahedron} & \cellcolor{gray!6}{TRUE} & \cellcolor{gray!6}{TRUE} & \cellcolor{gray!6}{FALSE} & \cellcolor{gray!6}{FALSE} & \cellcolor{gray!6}{FALSE} & \cellcolor{gray!6}{FALSE} & \cellcolor{gray!6}{FALSE} & \cellcolor{gray!6}{TRUE}\\ \bottomrule \end{tabular}} \end{table} The measure that we think is appropriate here yields the same result, 1, for both situations. Come to think of it, we don't find this counterintuitive. These are two sentences one of which is a trivial consequence of the other. \section{Conclusions and discussion}\label{conclusions-and-discussion} Let's recall a potential concern that we briefly gestured at in the introduction: perhaps both the intuitions and counterexamples are so diverse that we should abandon any hope of coming up with a single measure of coherence that would satisfy all the desiderata. One argument along these lines has been developed by \todo{Schippers2014}. He first formulates a list of potential desiderata: \vspace{2mm} \begin{description} \item[Independence] Coherence assigned to a probabilistically independent set of propositions should be neutral. \item[Dependence] If all non-empty disjoint pairs of subsets of a set probabilistically support each other (in the sense of $\pr(A\vert B)> \pr(A)$), the coherence assigned to that set should be greater than neutral. If all subsets probabilistically undermine each other, the coherence should be less than the neutral value. \item[Equivalence] The coherence of a set of logically equivalent propositions should be maximal. \item[Inconsistency] The coherence of a set whose all non-empty subsets are logically inconsistent is minimal.\footnote{Note that this condition is much weaker than the one we discussed, according to which a logically inconsistent set should have minimal coherence. Given Schippers' informal statement preceding his formulation, we're not sure if this was intended.} \item[Agreement] If one regular distribution results in all conditional probabilities for disjoint pairs of non-empty subsets ($\pr(\bigwedge \Delta_1 \vert \bigwedge \Delta_2)$) being higher than another ($\pr(\bigwedge \Delta_1 \vert \bigwedge \Delta_2) > \pr'(\bigwedge \Delta_1 \vert \bigwedge \Delta_2)$ for all such pairs of subsets), the coherence resulting from the former should be higher than the latter. \end{description} \vspace{2mm} Then, he points out that not only no existing measure satisfies all these desiderata, but also proves a theorem to the effect that \textbf{Independence} and \textbf{Agreement} exclude each other and so no measure can satisfy all these conditions. The lesson that Shippers draws from this is pluralistic: \begin{quote} \dots given that none of the existing measures satisfies all constraints we might not have been successful in our search for the proper probabilistic measure of coherence [\dots] Therefore, the project of finding the one true measure of coherence is futile: for purely mathematical reasons, there can be no measure that satisfies all constraints [\dots] Hence, we seem well advised to embrace a pluralistic stance with respect to measuring coherence: instead of finding the one true measure of coherence, we might pursue the slightly different project of finding the best representative for different classes of coherence measures. [p. 10] \end{quote} We hesitate in drawing this conclusion. Notice how the impossibility proof goes. Shippers gives two sentences and two distributions, such that the propositions are independent in any of the distributions (and so their set should have the same neutral coherence by \textbf{Independence}), and moreover such that pairwise conditional probabilities are higher in the first distribution than in the second, and so by \textbf{Agreement} the resulting coherence should be higher for the former. We think that this very example suggests that \textbf{Agreement} is a suspicious requirement, because it would require that different probability distributions can result in different coherence scores even if they both preserve probabilistic independence of pairs of disjoint non-empty subsets.\footnote{Moreover, come to think of it, \textbf{Agreement} assigns a lot of weight to conditional probabilities involved. In contrast, our measure uses z confirmation score, and z-scores in the example used in the proof remain equal to zero: the differences in conditional probabilities don't track differences in confirmation levels. So, our measure fails to satisfy \textbf{Agreement}, but the proof fails to show that it would fail to satisfy the conditon if we replaced the conditional probabilities with confirmation scores in the formulation.} In the absence of a convincing argument for the plausibility of \textbf{Agreement} in Shipper's paper, we may equally well take the theorem as an argument against the requirement. Even in the light of the multiplicity of examples, we still think that trying to find one mathematical explication to rule them all might be a useful enterprise. Ultimately, all the coherence results and desiderata yield the following two tables and success rates: \begin{table}[H] \centering \resizebox{\linewidth}{!}{ \begin{tabular}{lrrrrrrrr} \toprule & OG & OGen & Sh & ShGen & Fit & DM & R & S\\ \midrule \cellcolor{gray!6}{Penguins: BGP 111} & \cellcolor{gray!6}{0.010} & \cellcolor{gray!6}{0.015} & \cellcolor{gray!6}{4.000} & \cellcolor{gray!6}{2.010} & \cellcolor{gray!6}{0.453} & \cellcolor{gray!6}{0.255} & \cellcolor{gray!6}{0.255} & \cellcolor{gray!6}{0.010}\\ Penguins: BG 11 & 0.010 & 0.010 & 0.040 & 0.040 & -0.960 & -0.480 & -0.480 & -0.960\\ \cellcolor{gray!6}{Penguins: BP 11} & \cellcolor{gray!6}{0.020} & \cellcolor{gray!6}{0.020} & \cellcolor{gray!6}{2.000} & \cellcolor{gray!6}{2.000} & \cellcolor{gray!6}{0.669} & \cellcolor{gray!6}{0.255} & \cellcolor{gray!6}{0.255} & \cellcolor{gray!6}{0.010}\\ Dunnit: MGWI 1111 & 0.000 & 0.087 & 4.294 & 11.012 & 0.169 & 0.167 & 0.167 & -0.932\\ \cellcolor{gray!6}{Dunnit: MTGWI 11111} & \cellcolor{gray!6}{0.000} & \cellcolor{gray!6}{0.042} & \cellcolor{gray!6}{73.836} & \cellcolor{gray!6}{13.669} & \cellcolor{gray!6}{0.385} & \cellcolor{gray!6}{0.150} & \cellcolor{gray!6}{0.150} & \cellcolor{gray!6}{-0.100}\\ Japanese Swords 1: JO 11 & 0.004 & 0.004 & 80.251 & 80.251 & 0.976 & 0.008 & 0.008 & 0.008\\ \cellcolor{gray!6}{Japanese Swords 2: JO 11} & \cellcolor{gray!6}{0.818} & \cellcolor{gray!6}{0.818} & \cellcolor{gray!6}{9.000} & \cellcolor{gray!6}{9.000} & \cellcolor{gray!6}{0.976} & \cellcolor{gray!6}{0.800} & \cellcolor{gray!6}{0.800} & \cellcolor{gray!6}{0.889}\\ Japanese Swords 3: JO 11 & 0.818 & 0.818 & 1.080 & 1.080 & 0.286 & 0.067 & 0.067 & 0.400\\ \cellcolor{gray!6}{Robbers: MIsPMIsR 11} & \cellcolor{gray!6}{0.600} & \cellcolor{gray!6}{0.600} & \cellcolor{gray!6}{0.937} & \cellcolor{gray!6}{0.937} & \cellcolor{gray!6}{-0.143} & \cellcolor{gray!6}{-0.050} & \cellcolor{gray!6}{-0.050} & \cellcolor{gray!6}{0.600}\\ Robbers: MIsPMIsR 10 & 0.250 & 0.250 & 1.250 & 1.250 & 0.571 & 0.125 & 0.125 & -0.600\\ \cellcolor{gray!6}{Robbers: MIsPMIsR 01} & \cellcolor{gray!6}{0.250} & \cellcolor{gray!6}{0.250} & \cellcolor{gray!6}{1.250} & \cellcolor{gray!6}{1.250} & \cellcolor{gray!6}{0.571} & \cellcolor{gray!6}{0.125} & \cellcolor{gray!6}{0.125} & \cellcolor{gray!6}{-0.600}\\ Beatles: JPGRD 11111 & 0.000 & 0.202 & 0.000 & 1.423 & -0.036 & 0.025 & 0.025 & -1.000\\ \cellcolor{gray!6}{Books: AR 11} & \cellcolor{gray!6}{0.014} & \cellcolor{gray!6}{0.014} & \cellcolor{gray!6}{1.493} & \cellcolor{gray!6}{1.493} & \cellcolor{gray!6}{0.212} & \cellcolor{gray!6}{0.027} & \cellcolor{gray!6}{0.027} & \cellcolor{gray!6}{0.055}\\ Books: AR 10 & 0.009 & 0.009 & 0.945 & 0.945 & -0.127 & -0.025 & -0.025 & -0.055\\ \cellcolor{gray!6}{Books: AR 01} & \cellcolor{gray!6}{0.100} & \cellcolor{gray!6}{0.100} & \cellcolor{gray!6}{0.995} & \cellcolor{gray!6}{0.995} & \cellcolor{gray!6}{-0.101} & \cellcolor{gray!6}{-0.003} & \cellcolor{gray!6}{-0.003} & \cellcolor{gray!6}{-0.005}\\ Books: AR 00 & 0.892 & 0.892 & 1.001 & 1.001 & 0.016 & 0.001 & 0.001 & 0.005\\ \cellcolor{gray!6}{Witness: W1W2 11} & \cellcolor{gray!6}{0.451} & \cellcolor{gray!6}{0.451} & \cellcolor{gray!6}{3.551} & \cellcolor{gray!6}{3.551} & \cellcolor{gray!6}{0.771} & \cellcolor{gray!6}{0.446} & \cellcolor{gray!6}{0.446} & \cellcolor{gray!6}{0.729}\\ Witness: W3W4 11 & 0.187 & 0.187 & 0.740 & 0.740 & -0.234 & -0.110 & -0.110 & 0.494\\ \cellcolor{gray!6}{Witness: W4W5 11} & \cellcolor{gray!6}{0.365} & \cellcolor{gray!6}{0.365} & \cellcolor{gray!6}{1.260} & \cellcolor{gray!6}{1.260} & \cellcolor{gray!6}{0.218} & \cellcolor{gray!6}{0.110} & \cellcolor{gray!6}{0.110} & \cellcolor{gray!6}{0.602}\\ DepthA: T123T124 11 & 0.664 & 0.664 & 1.014 & 1.014 & 0.280 & 0.012 & 0.012 & 0.027\\ \cellcolor{gray!6}{DepthB: T123T145 11} & \cellcolor{gray!6}{0.331} & \cellcolor{gray!6}{0.331} & \cellcolor{gray!6}{0.996} & \cellcolor{gray!6}{0.996} & \cellcolor{gray!6}{-0.047} & \cellcolor{gray!6}{-0.003} & \cellcolor{gray!6}{-0.003} & \cellcolor{gray!6}{-0.004}\\ Regular: TTF 11 & 0.500 & 0.500 & 3.000 & 3.000 & 0.833 & 0.500 & 0.500 & 1.000\\ \cellcolor{gray!6}{Dodecahedron: TTF 11} & \cellcolor{gray!6}{0.500} & \cellcolor{gray!6}{0.500} & \cellcolor{gray!6}{6.000} & \cellcolor{gray!6}{6.000} & \cellcolor{gray!6}{0.917} & \cellcolor{gray!6}{0.625} & \cellcolor{gray!6}{0.625} & \cellcolor{gray!6}{1.000}\\ \bottomrule \end{tabular}} \end{table} \begin{table}[H] \centering \resizebox{\linewidth}{!}{ \begin{tabular}{lllllllll} \toprule & OG & OGen & Sh & ShGen & Fit & DM & R & S\\ \midrule \cellcolor{gray!6}{Penguins: BG$<$BGP} & \cellcolor{gray!6}{FALSE} & \cellcolor{gray!6}{TRUE} & \cellcolor{gray!6}{TRUE} & \cellcolor{gray!6}{TRUE} & \cellcolor{gray!6}{TRUE} & \cellcolor{gray!6}{TRUE} & \cellcolor{gray!6}{TRUE} & \cellcolor{gray!6}{TRUE}\\ Penguins: BP$\approx$ BGP & TRUE & TRUE & FALSE & TRUE & FALSE & TRUE & TRUE & TRUE\\ \cellcolor{gray!6}{Dunnit: Dunnit$<$Twin} & \cellcolor{gray!6}{FALSE} & \cellcolor{gray!6}{FALSE} & \cellcolor{gray!6}{TRUE} & \cellcolor{gray!6}{TRUE} & \cellcolor{gray!6}{TRUE} & \cellcolor{gray!6}{FALSE} & \cellcolor{gray!6}{FALSE} & \cellcolor{gray!6}{TRUE}\\ Swords: JO2$>$JO1 & TRUE & TRUE & FALSE & FALSE & TRUE & TRUE & TRUE & TRUE\\ \cellcolor{gray!6}{Swords: JO2$>$JO3} & \cellcolor{gray!6}{FALSE} & \cellcolor{gray!6}{FALSE} & \cellcolor{gray!6}{TRUE} & \cellcolor{gray!6}{TRUE} & \cellcolor{gray!6}{TRUE} & \cellcolor{gray!6}{TRUE} & \cellcolor{gray!6}{TRUE} & \cellcolor{gray!6}{TRUE}\\ Robbers: PR$>$P$\neg$R & TRUE & TRUE & FALSE & FALSE & FALSE & FALSE & FALSE & TRUE\\ \cellcolor{gray!6}{Robbers: PR$>$neutral} & \cellcolor{gray!6}{NA} & \cellcolor{gray!6}{NA} & \cellcolor{gray!6}{FALSE} & \cellcolor{gray!6}{FALSE} & \cellcolor{gray!6}{FALSE} & \cellcolor{gray!6}{FALSE} & \cellcolor{gray!6}{FALSE} & \cellcolor{gray!6}{TRUE}\\ Beatles: below neutral & NA & NA & TRUE & FALSE & TRUE & FALSE & TRUE & TRUE\\ \cellcolor{gray!6}{Beatles: minimal} & \cellcolor{gray!6}{TRUE} & \cellcolor{gray!6}{FALSE} & \cellcolor{gray!6}{TRUE} & \cellcolor{gray!6}{FALSE} & \cellcolor{gray!6}{FALSE} & \cellcolor{gray!6}{FALSE} & \cellcolor{gray!6}{FALSE} & \cellcolor{gray!6}{TRUE}\\ Books: AR$>$A$\neg$R & TRUE & TRUE & TRUE & TRUE & TRUE & TRUE & TRUE & TRUE\\ \cellcolor{gray!6}{Books: AR$>\neg$AR} & \cellcolor{gray!6}{FALSE} & \cellcolor{gray!6}{FALSE} & \cellcolor{gray!6}{TRUE} & \cellcolor{gray!6}{TRUE} & \cellcolor{gray!6}{TRUE} & \cellcolor{gray!6}{TRUE} & \cellcolor{gray!6}{TRUE} & \cellcolor{gray!6}{TRUE}\\ Books: $\neg$A$\neg$R$>$A$\neg$R & TRUE & TRUE & TRUE & TRUE & TRUE & TRUE & TRUE & TRUE\\ \cellcolor{gray!6}{Books: $\neg$A$\neg$R$>\neg$AR} & \cellcolor{gray!6}{TRUE} & \cellcolor{gray!6}{TRUE} & \cellcolor{gray!6}{TRUE} & \cellcolor{gray!6}{TRUE} & \cellcolor{gray!6}{TRUE} & \cellcolor{gray!6}{TRUE} & \cellcolor{gray!6}{TRUE} & \cellcolor{gray!6}{TRUE}\\ Witness: W$_1$W$_2>$W$_3$W$_4$ & TRUE & TRUE & TRUE & TRUE & TRUE & TRUE & TRUE & TRUE\\ \cellcolor{gray!6}{Witness: W$_4$W$_5>$W$_3$W$_4$} & \cellcolor{gray!6}{TRUE} & \cellcolor{gray!6}{TRUE} & \cellcolor{gray!6}{TRUE} & \cellcolor{gray!6}{TRUE} & \cellcolor{gray!6}{TRUE} & \cellcolor{gray!6}{TRUE} & \cellcolor{gray!6}{TRUE} & \cellcolor{gray!6}{TRUE}\\ Depth: X$_1>$X$_2$ & TRUE & TRUE & TRUE & TRUE & TRUE & TRUE & TRUE & TRUE\\ \cellcolor{gray!6}{Dodecahedron: Regular $=$ Dodecahedron} & \cellcolor{gray!6}{TRUE} & \cellcolor{gray!6}{TRUE} & \cellcolor{gray!6}{FALSE} & \cellcolor{gray!6}{FALSE} & \cellcolor{gray!6}{FALSE} & \cellcolor{gray!6}{FALSE} & \cellcolor{gray!6}{FALSE} & \cellcolor{gray!6}{TRUE}\\ \bottomrule \end{tabular}} \end{table} \begin{table}[H] \centering \begin{tabular}{rrrrrrrr} \toprule OG & OGen & Sh & ShGen & Fit & DM & R & S\\ \midrule \cellcolor{gray!6}{0.733} & \cellcolor{gray!6}{0.733} & \cellcolor{gray!6}{0.706} & \cellcolor{gray!6}{0.647} & \cellcolor{gray!6}{0.706} & \cellcolor{gray!6}{0.647} & \cellcolor{gray!6}{0.706} & \cellcolor{gray!6}{1}\\ \bottomrule \end{tabular} \end{table} Let's recap what we've done. We introduced the most prominent coherence measures and a number of counterexamples put forward against them. Then, we pointed out some common problems they face. These observations helped us develop our own measure. It improves on the existing approaches by using the structure of BNs, and by doing something a bit more sophisticated than taking means. Finally, we argued that this way we managed to avoid many counterexamples that were problematic for other measures. This, in fact turned out to be a balancing act: we agreed with many intuitions behind the counterexamples had doubts about some of them, and a few of the cases needed somewhat more elaborate reflection before our measure gave the desired outcome. We end with a list of tasks for further reearch. One issue that needs further study is whether the structured coherence measure yields desired results in more straightforward cases as compared with empirical results on how real agents assess coherence. Another question is how the measure handles legal cases for which BNs have already been developed (C. Vlek et al., 2013, C. Vlek et al. (2014), C. S. Vlek et al. (2015), C. Vlek (2016), Fenton et al. (2013), Fenton et al. (2013)). It might also be worthwile to investigate what happens if confirmation measures other than \s{Z} are plugged in. Finally, a more general study of the properties of the structured coherence measure would be useful. \newpage \footnotesize \section*{References}\label{references} \addcontentsline{toc}{section}{References} \hypertarget{refs}{} \hypertarget{ref-Akiba2000Shogenjis}{} Akiba, K. (2000). Shogenjis probabilistic measure of coherence is incoherent. \emph{Analysis}, \emph{60}(4), 356--359. \url{https://doi.org/10.1093/analys/60.4.356} \hypertarget{ref-bovens2004bayesian}{} Bovens, L., \& Hartmann, S. (2004). \emph{Bayesian epistemology}. Oxford University Press. \hypertarget{ref-crupi2007BayesianMeasuresEvidential}{} Crupi, V., Tentori, K., \& Gonzalez, M. (2007). On Bayesian measures of evidential Support: theoretical and empirical Issues. \emph{Philosophy of Science}, \emph{74}(2), 229--252. \url{https://doi.org/10.1086/520779} \hypertarget{ref-Douven2007Measuring}{} Douven, I., \& Meijs, W. (2007). Measuring coherence. \emph{Synthese}, \emph{156}(3), 405--425. \url{https://doi.org/10.1007/s11229-006-9131-z} \hypertarget{ref-fenton2013GeneralStructureLegal}{} Fenton, N., Neil, M., \& Lagnado, D. A. (2013). A General Structure for Legal Arguments About Evidence Using Bayesian Networks. \emph{Cognitive Science}, \emph{37}(1), 61--102. \url{https://doi.org/10.1111/cogs.12004} \hypertarget{ref-fitelson2003ProbabilisticTheoryCoherence}{} Fitelson, B. (2003a). A Probabilistic Theory of Coherence. \emph{Analysis}, \emph{63}(3), 194--199. \hypertarget{ref-fitelson2003comments}{} Fitelson, B. (2003b). Comments on jim franklin's the representation of context: Ideas from artificial intelligence (or, more remarks on the contextuality of probability). \emph{Law, Probability and Risk}, \emph{2}(3), 201--204. \hypertarget{ref-glass2002}{} Glass, D. H. (2002). Coherence, Explanation, and Bayesian Networks. In G. Goos, J. Hartmanis, J. van Leeuwen, M. O'Neill, R. F. E. Sutcliffe, C. Ryan, M. Eaton, \& N. J. L. Griffith (Eds.), \emph{Artificial Intelligence and Cognitive Science} (Vol. 2464, pp. 177--182). Springer Berlin Heidelberg. \url{https://doi.org/10.1007/3-540-45750-X_23} \hypertarget{ref-koscholke2016evaluating}{} Koscholke, J. (2016). Evaluating Test Cases for Probabilistic Measures of Coherence. \emph{Erkenntnis}, \emph{81}(1), 155--181. \url{https://doi.org/10.1007/s10670-015-9734-1} \hypertarget{ref-meijs2007}{} Meijs, W., \& Douven, I. (2007). On the alleged impossibility of coherence. \emph{Synthese}, \emph{157}(3), 347--360. \url{https://doi.org/10.1007/s11229-006-9060-x} \hypertarget{ref-Merricks1995}{} Merricks, T. (1995). Warrant entails truth. \emph{Philosophy and Phenomenological Research}, \emph{55}, 841--855. \hypertarget{ref-olsson2001}{} Olsson, E. J. (2001). Why Coherence Is Not Truth-Conducive. \emph{Analysis}, \emph{61}(3), 236--241. \hypertarget{ref-olsson2005}{} Olsson, E. J. (2005). The Impossibility of Coherence. \emph{Erkenntnis}, \emph{63}(3), 387--412. \url{https://doi.org/10.1007/s10670-005-4007-z} \hypertarget{ref-Roche2013Coherence}{} Roche, W. (2013). Coherence and probability: A probabilistic account of coherence. In M. Araszkiewicz \& J. Savelka (Eds.), \emph{Coherence: Insights from philosophy, jurisprudence and artificial intelligence} (pp. 59--91). Dordrecht: Springer. \hypertarget{ref-Schippers2019General}{} Schippers, M., \& Koscholke, J. (2019). A General Framework for Probabilistic Measures of Coherence. \emph{Studia Logica}. \url{https://doi.org/10.1007/s11225-019-09848-3} \hypertarget{ref-Schupbach2008Alleged}{} Schupbach, J. N. (2008). On the alleged impossibility of bayesian coherentism. \emph{Philosophical Studies}, \emph{141}(3), 323--331. \url{https://doi.org/10.1007/s11098-007-9176-y} \hypertarget{ref-shogenji1999}{} Shogenji, T. (1999). Is Coherence Truth Conducive? \emph{Analysis}, \emph{59}(4), 338--345. \hypertarget{ref-Shogenji2001Reply}{} Shogenji, T. (2001). Reply to akiba on the probabilistic measure of coherence. \emph{Analysis}, \emph{61}(2), 147--150. \url{https://doi.org/10.1093/analys/61.2.147} \hypertarget{ref-Shogenji2006Why}{} Shogenji, T. (2006). Why does coherence appear truth-conducive? \emph{Synthese}, \emph{157}(3), 361--372. \url{https://doi.org/10.1007/s11229-006-9062-8} \hypertarget{ref-Siebel2004On-Fitelsons-me}{} Siebel, M. (2004). On Fitelson's measure of coherence. \emph{Analysis}, \emph{64}, 189--190. \hypertarget{ref-siebel2006against}{} Siebel, M. (2006). Against probabilistic measures of coherence. In \emph{Coherence, truth and testimony} (pp. 43--68). Springer. \hypertarget{ref-vlek2016stories}{} Vlek, C. (2016). \emph{When stories and numbers meet in court: Constructing and explaining Bayesian networks for criminal cases with scenarios}. Rijksuniversiteit Groningen. \hypertarget{ref-vlek2015}{} Vlek, C. S., Prakken, H., Renooij, S., \& Bart Verheij. (2015). Representing the quality of crime scenarios in a bayesian network. In A. Rotolo (Ed.), \emph{Legal knowledge and information systems} (pp. 133--140). IOS Press. \hypertarget{ref-vlek2014building}{} Vlek, C., Prakken, H., Renooij, S., \& Verheij, B. (2014). Building bayesian networks for legal evidence with narratives: A case study evaluation. \emph{Artificial Intelligence and Law}, \emph{22}, 375--421. \hypertarget{ref-vlek2013modeling}{} Vlek, C., Prakken, H., Renooij, S., \& Verheij, B. (2013). Modeling crime scenarios in a bayesian network. \emph{Proceedings of the Fourteenth International Conference on Artificial Intelligence and Law}, 150--159. \end{document}
{-# OPTIONS --cubical --safe #-} module Cubical.HITs.Truncation.Properties where open import Cubical.HITs.Truncation.Base open import Cubical.Data.Nat open import Cubical.Data.NatMinusOne open import Cubical.Foundations.Prelude open import Cubical.Foundations.Equiv open import Cubical.Foundations.Isomorphism open import Cubical.Foundations.HLevels open import Cubical.HITs.Sn open import Cubical.Data.Empty open import Cubical.HITs.Susp open import Cubical.HITs.PropositionalTruncation renaming (∥_∥ to ∥_∥₋₁) open import Cubical.HITs.SetTruncation open import Cubical.HITs.GroupoidTruncation open import Cubical.HITs.2GroupoidTruncation private variable ℓ ℓ' : Level A : Type ℓ sphereFill : (n : ℕ) (f : S n → A) → Type _ sphereFill {A = A} n f = Σ[ top ∈ A ] ((x : S n) → top ≡ f x) isSphereFilled : ℕ → Type ℓ → Type ℓ isSphereFilled n A = (f : S n → A) → sphereFill n f isSphereFilled∥∥ : {n : ℕ₋₁} → isSphereFilled (1+ n) (∥ A ∥ n) isSphereFilled∥∥ f = (hub f) , (spoke f) isSphereFilled→isOfHLevel : (n : ℕ) → isSphereFilled n A → isOfHLevel (1 + n) A isSphereFilled→isOfHLevel {A = A} 0 h x y = sym (snd (h f) north) ∙ snd (h f) south where f : Susp ⊥ → A f north = x f south = y f (merid () i) isSphereFilled→isOfHLevel {A = A} (suc n) h x y = isSphereFilled→isOfHLevel n (helper h x y) where helper : {n : ℕ} → isSphereFilled (suc n) A → (x y : A) → isSphereFilled n (x ≡ y) helper {n = n} h x y f = l , r where f' : Susp (S n) → A f' north = x f' south = y f' (merid u i) = f u i u : sphereFill (suc n) f' u = h f' z : A z = fst u p : z ≡ x p = snd u north q : z ≡ y q = snd u south l : x ≡ y l = sym p ∙ q r : (s : S n) → l ≡ f s r s i j = hcomp (λ k → λ { (i = i0) → compPath-filler (sym p) q k j ; (i = i1) → snd u (merid s j) k ; (j = i0) → p (k ∨ (~ i)) ; (j = i1) → q k }) (p ((~ i) ∧ (~ j))) isOfHLevel→isSphereFilled : (n : ℕ) → isOfHLevel (1 + n) A → isSphereFilled n A isOfHLevel→isSphereFilled 0 h f = (f north) , (λ _ → h _ _) isOfHLevel→isSphereFilled {A = A} (suc n) h = helper λ x y → isOfHLevel→isSphereFilled n (h x y) where helper : {n : ℕ} → ((x y : A) → isSphereFilled n (x ≡ y)) → isSphereFilled (suc n) A helper {n = n} h f = l , r where l : A l = f north f' : S n → f north ≡ f south f' x i = f (merid x i) h' : sphereFill n f' h' = h (f north) (f south) f' r : (x : S (suc n)) → l ≡ f x r north = refl r south = h' .fst r (merid x i) j = hcomp (λ k → λ { (i = i0) → f north ; (i = i1) → h' .snd x (~ k) j ; (j = i0) → f north ; (j = i1) → f (merid x i) }) (f (merid x (i ∧ j))) isOfHLevel∥∥ : (n : ℕ₋₁) → isOfHLevel (1 + 1+ n) (∥ A ∥ n) isOfHLevel∥∥ n = isSphereFilled→isOfHLevel (1+ n) isSphereFilled∥∥ ind : {n : ℕ₋₁} {B : ∥ A ∥ n → Type ℓ'} (hB : (x : ∥ A ∥ n) → isOfHLevel (1 + 1+ n) (B x)) (g : (a : A) → B (∣ a ∣)) (x : ∥ A ∥ n) → B x ind hB g (∣ a ∣ ) = g a ind {B = B} hB g (hub f) = isOfHLevel→isSphereFilled _ (hB (hub f)) (λ x → subst B (sym (spoke f x)) (ind hB g (f x)) ) .fst ind {B = B} hB g (spoke f x i) = toPathP {A = λ i → B (spoke f x (~ i))} (sym (isOfHLevel→isSphereFilled _ (hB (hub f)) (λ x → subst B (sym (spoke f x)) (ind hB g (f x))) .snd x)) (~ i) ind2 : {n : ℕ₋₁} {B : ∥ A ∥ n → ∥ A ∥ n → Type ℓ'} (hB : ((x y : ∥ A ∥ n) → isOfHLevel (1 + 1+ n) (B x y))) (g : (a b : A) → B ∣ a ∣ ∣ b ∣) (x y : ∥ A ∥ n) → B x y ind2 {n = n} hB g = ind (λ _ → hLevelPi (1 + 1+ n) (λ _ → hB _ _)) λ a → ind (λ _ → hB _ _) (λ b → g a b) ind3 : {n : ℕ₋₁} {B : (x y z : ∥ A ∥ n) → Type ℓ'} (hB : ((x y z : ∥ A ∥ n) → isOfHLevel (1 + 1+ n) (B x y z))) (g : (a b c : A) → B (∣ a ∣) ∣ b ∣ ∣ c ∣) (x y z : ∥ A ∥ n) → B x y z ind3 {n = n} hB g = ind2 (λ _ _ → hLevelPi (1 + 1+ n) (hB _ _)) λ a b → ind (λ _ → hB _ _ _) (λ c → g a b c) idemTrunc : (n : ℕ₋₁) → isOfHLevel (1 + 1+ n) A → (∥ A ∥ n) ≃ A idemTrunc {A = A} n hA = isoToEquiv (iso f g f-g g-f) where f : ∥ A ∥ n → A f = ind (λ _ → hA) λ a → a g : A → ∥ A ∥ n g = ∣_∣ f-g : ∀ a → f (g a) ≡ a f-g a = refl g-f : ∀ x → g (f x) ≡ x g-f = ind (λ _ → hLevelSuc (1+ n) _ (hLevelPath (1+ n) (isOfHLevel∥∥ n) _ _)) (λ _ → refl) propTrunc≃Trunc-1 : ∥ A ∥₋₁ ≃ ∥ A ∥ neg1 propTrunc≃Trunc-1 = isoToEquiv (iso (elimPropTrunc (λ _ → isOfHLevel∥∥ neg1) ∣_∣) (ind (λ _ → propTruncIsProp) ∣_∣) (ind (λ _ → hLevelSuc 0 _ (hLevelPath 0 (isOfHLevel∥∥ neg1) _ _)) (λ _ → refl)) (elimPropTrunc (λ _ → hLevelSuc 0 _ (hLevelPath 0 propTruncIsProp _ _)) (λ _ → refl))) setTrunc≃Trunc0 : ∥ A ∥₀ ≃ ∥ A ∥ (suc neg1) setTrunc≃Trunc0 = isoToEquiv (iso (elimSetTrunc (λ _ → isOfHLevel∥∥ (suc neg1)) ∣_∣) (ind (λ _ → squash₀) ∣_∣₀) (ind (λ _ → hLevelSuc 1 _ (hLevelPath 1 (isOfHLevel∥∥ (suc neg1)) _ _)) (λ _ → refl)) (elimSetTrunc (λ _ → hLevelSuc 1 _ (hLevelPath 1 squash₀ _ _)) (λ _ → refl))) groupoidTrunc≃Trunc1 : ∥ A ∥₁ ≃ ∥ A ∥ (ℕ→ℕ₋₁ 1) groupoidTrunc≃Trunc1 = isoToEquiv (iso (groupoidTruncElim _ _ (λ _ → isOfHLevel∥∥ (ℕ→ℕ₋₁ 1)) ∣_∣) (ind (λ _ → squash₁) ∣_∣₁) (ind (λ _ → hLevelSuc 2 _ (hLevelPath 2 (isOfHLevel∥∥ (ℕ→ℕ₋₁ 1)) _ _)) (λ _ → refl)) (groupoidTruncElim _ _ (λ _ → hLevelSuc 2 _ (hLevelPath 2 squash₁ _ _)) (λ _ → refl))) 2groupoidTrunc≃Trunc2 : ∥ A ∥₂ ≃ ∥ A ∥ (ℕ→ℕ₋₁ 2) 2groupoidTrunc≃Trunc2 = isoToEquiv (iso (g2TruncElim _ _ (λ _ → isOfHLevel∥∥ (ℕ→ℕ₋₁ 2)) ∣_∣) (ind (λ _ → squash₂) ∣_∣₂) (ind (λ _ → hLevelSuc 3 _ (hLevelPath 3 (isOfHLevel∥∥ (ℕ→ℕ₋₁ 2)) _ _)) (λ _ → refl)) (g2TruncElim _ _ (λ _ → hLevelSuc 3 _ (hLevelPath 3 squash₂ _ _)) (λ _ → refl)))
Formal statement is: lemma setdist_eq_0I: "\<lbrakk>x \<in> S; x \<in> T\<rbrakk> \<Longrightarrow> setdist S T = 0" Informal statement is: If $x$ is in both $S$ and $T$, then the distance between $S$ and $T$ is zero.
function f_x = ParFor7(in1) %PARFOR7 % F_X = PARFOR7(IN1) % This function was generated by the Symbolic Math Toolbox version 8.1. % 16-Jul-2019 11:57:27 u = in1(:,1); uxx = in1(:,5); f_x = (u.*9.981631376631412e-1+uxx.*9.965561702440027+u.*uxx.*1.006065455272619)./(u+9.978905414318433);
Formal statement is: lemma algebraic_int_altdef_ipoly: fixes x :: "'a :: field_char_0" shows "algebraic_int x \<longleftrightarrow> (\<exists>p. poly (map_poly of_int p) x = 0 \<and> lead_coeff p = 1)" Informal statement is: An element $x$ of a field is an algebraic integer if and only if there exists a monic polynomial $p$ with integer coefficients such that $p(x) = 0$.
/- Copyright (c) 2021 Yaël Dillies. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yaël Dillies ! This file was ported from Lean 3 source module data.multiset.locally_finite ! leanprover-community/mathlib commit f16e7a22e11fc09c71f25446ac1db23a24e8a0bd ! Please do not edit these lines, except to modify the commit id ! if you have ported upstream changes. -/ import Mathbin.Data.Finset.LocallyFinite /-! # Intervals as multisets > THIS FILE IS SYNCHRONIZED WITH MATHLIB4. > Any changes to this file require a corresponding PR to mathlib4. This file provides basic results about all the `multiset.Ixx`, which are defined in `order.locally_finite`. Note that intervals of multisets themselves (`multiset.locally_finite_order`) are defined elsewhere. -/ variable {α : Type _} namespace Multiset section Preorder variable [Preorder α] [LocallyFiniteOrder α] {a b c : α} #print Multiset.nodup_Icc /- theorem nodup_Icc : (Icc a b).Nodup := Finset.nodup _ #align multiset.nodup_Icc Multiset.nodup_Icc -/ #print Multiset.nodup_Ico /- theorem nodup_Ico : (Ico a b).Nodup := Finset.nodup _ #align multiset.nodup_Ico Multiset.nodup_Ico -/ #print Multiset.nodup_Ioc /- theorem nodup_Ioc : (Ioc a b).Nodup := Finset.nodup _ #align multiset.nodup_Ioc Multiset.nodup_Ioc -/ #print Multiset.nodup_Ioo /- theorem nodup_Ioo : (Ioo a b).Nodup := Finset.nodup _ #align multiset.nodup_Ioo Multiset.nodup_Ioo -/ #print Multiset.Icc_eq_zero_iff /- @[simp] theorem Icc_eq_zero_iff : Icc a b = 0 ↔ ¬a ≤ b := by rw [Icc, Finset.val_eq_zero, Finset.Icc_eq_empty_iff] #align multiset.Icc_eq_zero_iff Multiset.Icc_eq_zero_iff -/ #print Multiset.Ico_eq_zero_iff /- @[simp] theorem Ico_eq_zero_iff : Ico a b = 0 ↔ ¬a < b := by rw [Ico, Finset.val_eq_zero, Finset.Ico_eq_empty_iff] #align multiset.Ico_eq_zero_iff Multiset.Ico_eq_zero_iff -/ #print Multiset.Ioc_eq_zero_iff /- @[simp] theorem Ioc_eq_zero_iff : Ioc a b = 0 ↔ ¬a < b := by rw [Ioc, Finset.val_eq_zero, Finset.Ioc_eq_empty_iff] #align multiset.Ioc_eq_zero_iff Multiset.Ioc_eq_zero_iff -/ #print Multiset.Ioo_eq_zero_iff /- @[simp] theorem Ioo_eq_zero_iff [DenselyOrdered α] : Ioo a b = 0 ↔ ¬a < b := by rw [Ioo, Finset.val_eq_zero, Finset.Ioo_eq_empty_iff] #align multiset.Ioo_eq_zero_iff Multiset.Ioo_eq_zero_iff -/ alias Icc_eq_zero_iff ↔ _ Icc_eq_zero #align multiset.Icc_eq_zero Multiset.Icc_eq_zero alias Ico_eq_zero_iff ↔ _ Ico_eq_zero #align multiset.Ico_eq_zero Multiset.Ico_eq_zero alias Ioc_eq_zero_iff ↔ _ Ioc_eq_zero #align multiset.Ioc_eq_zero Multiset.Ioc_eq_zero #print Multiset.Ioo_eq_zero /- @[simp] theorem Ioo_eq_zero (h : ¬a < b) : Ioo a b = 0 := eq_zero_iff_forall_not_mem.2 fun x hx => h ((mem_Ioo.1 hx).1.trans (mem_Ioo.1 hx).2) #align multiset.Ioo_eq_zero Multiset.Ioo_eq_zero -/ #print Multiset.Icc_eq_zero_of_lt /- @[simp] theorem Icc_eq_zero_of_lt (h : b < a) : Icc a b = 0 := Icc_eq_zero h.not_le #align multiset.Icc_eq_zero_of_lt Multiset.Icc_eq_zero_of_lt -/ #print Multiset.Ico_eq_zero_of_le /- @[simp] theorem Ico_eq_zero_of_le (h : b ≤ a) : Ico a b = 0 := Ico_eq_zero h.not_lt #align multiset.Ico_eq_zero_of_le Multiset.Ico_eq_zero_of_le -/ #print Multiset.Ioc_eq_zero_of_le /- @[simp] theorem Ioc_eq_zero_of_le (h : b ≤ a) : Ioc a b = 0 := Ioc_eq_zero h.not_lt #align multiset.Ioc_eq_zero_of_le Multiset.Ioc_eq_zero_of_le -/ #print Multiset.Ioo_eq_zero_of_le /- @[simp] theorem Ioo_eq_zero_of_le (h : b ≤ a) : Ioo a b = 0 := Ioo_eq_zero h.not_lt #align multiset.Ioo_eq_zero_of_le Multiset.Ioo_eq_zero_of_le -/ variable (a) #print Multiset.Ico_self /- @[simp] theorem Ico_self : Ico a a = 0 := by rw [Ico, Finset.Ico_self, Finset.empty_val] #align multiset.Ico_self Multiset.Ico_self -/ #print Multiset.Ioc_self /- @[simp] theorem Ioc_self : Ioc a a = 0 := by rw [Ioc, Finset.Ioc_self, Finset.empty_val] #align multiset.Ioc_self Multiset.Ioc_self -/ #print Multiset.Ioo_self /- @[simp] theorem Ioo_self : Ioo a a = 0 := by rw [Ioo, Finset.Ioo_self, Finset.empty_val] #align multiset.Ioo_self Multiset.Ioo_self -/ variable {a b c} #print Multiset.left_mem_Icc /- theorem left_mem_Icc : a ∈ Icc a b ↔ a ≤ b := Finset.left_mem_Icc #align multiset.left_mem_Icc Multiset.left_mem_Icc -/ #print Multiset.left_mem_Ico /- theorem left_mem_Ico : a ∈ Ico a b ↔ a < b := Finset.left_mem_Ico #align multiset.left_mem_Ico Multiset.left_mem_Ico -/ #print Multiset.right_mem_Icc /- theorem right_mem_Icc : b ∈ Icc a b ↔ a ≤ b := Finset.right_mem_Icc #align multiset.right_mem_Icc Multiset.right_mem_Icc -/ #print Multiset.right_mem_Ioc /- theorem right_mem_Ioc : b ∈ Ioc a b ↔ a < b := Finset.right_mem_Ioc #align multiset.right_mem_Ioc Multiset.right_mem_Ioc -/ #print Multiset.left_not_mem_Ioc /- @[simp] theorem left_not_mem_Ioc : a ∉ Ioc a b := Finset.left_not_mem_Ioc #align multiset.left_not_mem_Ioc Multiset.left_not_mem_Ioc -/ #print Multiset.left_not_mem_Ioo /- @[simp] theorem left_not_mem_Ioo : a ∉ Ioo a b := Finset.left_not_mem_Ioo #align multiset.left_not_mem_Ioo Multiset.left_not_mem_Ioo -/ #print Multiset.right_not_mem_Ico /- @[simp] theorem right_not_mem_Ico : b ∉ Ico a b := Finset.right_not_mem_Ico #align multiset.right_not_mem_Ico Multiset.right_not_mem_Ico -/ #print Multiset.right_not_mem_Ioo /- @[simp] theorem right_not_mem_Ioo : b ∉ Ioo a b := Finset.right_not_mem_Ioo #align multiset.right_not_mem_Ioo Multiset.right_not_mem_Ioo -/ #print Multiset.Ico_filter_lt_of_le_left /- theorem Ico_filter_lt_of_le_left [DecidablePred (· < c)] (hca : c ≤ a) : ((Ico a b).filterₓ fun x => x < c) = ∅ := by rw [Ico, ← Finset.filter_val, Finset.Ico_filter_lt_of_le_left hca] rfl #align multiset.Ico_filter_lt_of_le_left Multiset.Ico_filter_lt_of_le_left -/ #print Multiset.Ico_filter_lt_of_right_le /- theorem Ico_filter_lt_of_right_le [DecidablePred (· < c)] (hbc : b ≤ c) : ((Ico a b).filterₓ fun x => x < c) = Ico a b := by rw [Ico, ← Finset.filter_val, Finset.Ico_filter_lt_of_right_le hbc] #align multiset.Ico_filter_lt_of_right_le Multiset.Ico_filter_lt_of_right_le -/ #print Multiset.Ico_filter_lt_of_le_right /- theorem Ico_filter_lt_of_le_right [DecidablePred (· < c)] (hcb : c ≤ b) : ((Ico a b).filterₓ fun x => x < c) = Ico a c := by rw [Ico, ← Finset.filter_val, Finset.Ico_filter_lt_of_le_right hcb] rfl #align multiset.Ico_filter_lt_of_le_right Multiset.Ico_filter_lt_of_le_right -/ #print Multiset.Ico_filter_le_of_le_left /- theorem Ico_filter_le_of_le_left [DecidablePred ((· ≤ ·) c)] (hca : c ≤ a) : ((Ico a b).filterₓ fun x => c ≤ x) = Ico a b := by rw [Ico, ← Finset.filter_val, Finset.Ico_filter_le_of_le_left hca] #align multiset.Ico_filter_le_of_le_left Multiset.Ico_filter_le_of_le_left -/ #print Multiset.Ico_filter_le_of_right_le /- theorem Ico_filter_le_of_right_le [DecidablePred ((· ≤ ·) b)] : ((Ico a b).filterₓ fun x => b ≤ x) = ∅ := by rw [Ico, ← Finset.filter_val, Finset.Ico_filter_le_of_right_le] rfl #align multiset.Ico_filter_le_of_right_le Multiset.Ico_filter_le_of_right_le -/ #print Multiset.Ico_filter_le_of_left_le /- theorem Ico_filter_le_of_left_le [DecidablePred ((· ≤ ·) c)] (hac : a ≤ c) : ((Ico a b).filterₓ fun x => c ≤ x) = Ico c b := by rw [Ico, ← Finset.filter_val, Finset.Ico_filter_le_of_left_le hac] rfl #align multiset.Ico_filter_le_of_left_le Multiset.Ico_filter_le_of_left_le -/ end Preorder section PartialOrder variable [PartialOrder α] [LocallyFiniteOrder α] {a b : α} #print Multiset.Icc_self /- @[simp] theorem Icc_self (a : α) : Icc a a = {a} := by rw [Icc, Finset.Icc_self, Finset.singleton_val] #align multiset.Icc_self Multiset.Icc_self -/ #print Multiset.Ico_cons_right /- theorem Ico_cons_right (h : a ≤ b) : b ::ₘ Ico a b = Icc a b := by classical rw [Ico, ← Finset.insert_val_of_not_mem right_not_mem_Ico, Finset.Ico_insert_right h] rfl #align multiset.Ico_cons_right Multiset.Ico_cons_right -/ #print Multiset.Ioo_cons_left /- theorem Ioo_cons_left (h : a < b) : a ::ₘ Ioo a b = Ico a b := by classical rw [Ioo, ← Finset.insert_val_of_not_mem left_not_mem_Ioo, Finset.Ioo_insert_left h] rfl #align multiset.Ioo_cons_left Multiset.Ioo_cons_left -/ #print Multiset.Ico_disjoint_Ico /- theorem Ico_disjoint_Ico {a b c d : α} (h : b ≤ c) : (Ico a b).Disjoint (Ico c d) := fun x hab hbc => by rw [mem_Ico] at hab hbc exact hab.2.not_le (h.trans hbc.1) #align multiset.Ico_disjoint_Ico Multiset.Ico_disjoint_Ico -/ #print Multiset.Ico_inter_Ico_of_le /- @[simp] theorem Ico_inter_Ico_of_le [DecidableEq α] {a b c d : α} (h : b ≤ c) : Ico a b ∩ Ico c d = 0 := Multiset.inter_eq_zero_iff_disjoint.2 <| Ico_disjoint_Ico h #align multiset.Ico_inter_Ico_of_le Multiset.Ico_inter_Ico_of_le -/ #print Multiset.Ico_filter_le_left /- theorem Ico_filter_le_left {a b : α} [DecidablePred (· ≤ a)] (hab : a < b) : ((Ico a b).filterₓ fun x => x ≤ a) = {a} := by rw [Ico, ← Finset.filter_val, Finset.Ico_filter_le_left hab] rfl #align multiset.Ico_filter_le_left Multiset.Ico_filter_le_left -/ /- warning: multiset.card_Ico_eq_card_Icc_sub_one -> Multiset.card_Ico_eq_card_Icc_sub_one is a dubious translation: lean 3 declaration is forall {α : Type.{u1}} [_inst_1 : PartialOrder.{u1} α] [_inst_2 : LocallyFiniteOrder.{u1} α (PartialOrder.toPreorder.{u1} α _inst_1)] (a : α) (b : α), Eq.{1} Nat (coeFn.{succ u1, succ u1} (AddMonoidHom.{u1, 0} (Multiset.{u1} α) Nat (AddMonoid.toAddZeroClass.{u1} (Multiset.{u1} α) (AddRightCancelMonoid.toAddMonoid.{u1} (Multiset.{u1} α) (AddCancelMonoid.toAddRightCancelMonoid.{u1} (Multiset.{u1} α) (AddCancelCommMonoid.toAddCancelMonoid.{u1} (Multiset.{u1} α) (OrderedCancelAddCommMonoid.toCancelAddCommMonoid.{u1} (Multiset.{u1} α) (Multiset.orderedCancelAddCommMonoid.{u1} α)))))) (AddMonoid.toAddZeroClass.{0} Nat Nat.addMonoid)) (fun (_x : AddMonoidHom.{u1, 0} (Multiset.{u1} α) Nat (AddMonoid.toAddZeroClass.{u1} (Multiset.{u1} α) (AddRightCancelMonoid.toAddMonoid.{u1} (Multiset.{u1} α) (AddCancelMonoid.toAddRightCancelMonoid.{u1} (Multiset.{u1} α) (AddCancelCommMonoid.toAddCancelMonoid.{u1} (Multiset.{u1} α) (OrderedCancelAddCommMonoid.toCancelAddCommMonoid.{u1} (Multiset.{u1} α) (Multiset.orderedCancelAddCommMonoid.{u1} α)))))) (AddMonoid.toAddZeroClass.{0} Nat Nat.addMonoid)) => (Multiset.{u1} α) -> Nat) (AddMonoidHom.hasCoeToFun.{u1, 0} (Multiset.{u1} α) Nat (AddMonoid.toAddZeroClass.{u1} (Multiset.{u1} α) (AddRightCancelMonoid.toAddMonoid.{u1} (Multiset.{u1} α) (AddCancelMonoid.toAddRightCancelMonoid.{u1} (Multiset.{u1} α) (AddCancelCommMonoid.toAddCancelMonoid.{u1} (Multiset.{u1} α) (OrderedCancelAddCommMonoid.toCancelAddCommMonoid.{u1} (Multiset.{u1} α) (Multiset.orderedCancelAddCommMonoid.{u1} α)))))) (AddMonoid.toAddZeroClass.{0} Nat Nat.addMonoid)) (Multiset.card.{u1} α) (Multiset.Ico.{u1} α (PartialOrder.toPreorder.{u1} α _inst_1) _inst_2 a b)) (HSub.hSub.{0, 0, 0} Nat Nat Nat (instHSub.{0} Nat Nat.hasSub) (coeFn.{succ u1, succ u1} (AddMonoidHom.{u1, 0} (Multiset.{u1} α) Nat (AddMonoid.toAddZeroClass.{u1} (Multiset.{u1} α) (AddRightCancelMonoid.toAddMonoid.{u1} (Multiset.{u1} α) (AddCancelMonoid.toAddRightCancelMonoid.{u1} (Multiset.{u1} α) (AddCancelCommMonoid.toAddCancelMonoid.{u1} (Multiset.{u1} α) (OrderedCancelAddCommMonoid.toCancelAddCommMonoid.{u1} (Multiset.{u1} α) (Multiset.orderedCancelAddCommMonoid.{u1} α)))))) (AddMonoid.toAddZeroClass.{0} Nat Nat.addMonoid)) (fun (_x : AddMonoidHom.{u1, 0} (Multiset.{u1} α) Nat (AddMonoid.toAddZeroClass.{u1} (Multiset.{u1} α) (AddRightCancelMonoid.toAddMonoid.{u1} (Multiset.{u1} α) (AddCancelMonoid.toAddRightCancelMonoid.{u1} (Multiset.{u1} α) (AddCancelCommMonoid.toAddCancelMonoid.{u1} (Multiset.{u1} α) (OrderedCancelAddCommMonoid.toCancelAddCommMonoid.{u1} (Multiset.{u1} α) (Multiset.orderedCancelAddCommMonoid.{u1} α)))))) (AddMonoid.toAddZeroClass.{0} Nat Nat.addMonoid)) => (Multiset.{u1} α) -> Nat) (AddMonoidHom.hasCoeToFun.{u1, 0} (Multiset.{u1} α) Nat (AddMonoid.toAddZeroClass.{u1} (Multiset.{u1} α) (AddRightCancelMonoid.toAddMonoid.{u1} (Multiset.{u1} α) (AddCancelMonoid.toAddRightCancelMonoid.{u1} (Multiset.{u1} α) (AddCancelCommMonoid.toAddCancelMonoid.{u1} (Multiset.{u1} α) (OrderedCancelAddCommMonoid.toCancelAddCommMonoid.{u1} (Multiset.{u1} α) (Multiset.orderedCancelAddCommMonoid.{u1} α)))))) (AddMonoid.toAddZeroClass.{0} Nat Nat.addMonoid)) (Multiset.card.{u1} α) (Multiset.Icc.{u1} α (PartialOrder.toPreorder.{u1} α _inst_1) _inst_2 a b)) (OfNat.ofNat.{0} Nat 1 (OfNat.mk.{0} Nat 1 (One.one.{0} Nat Nat.hasOne)))) but is expected to have type forall {α : Type.{u1}} [_inst_1 : PartialOrder.{u1} α] [_inst_2 : LocallyFiniteOrder.{u1} α (PartialOrder.toPreorder.{u1} α _inst_1)] (a : α) (b : α), Eq.{1} ((fun ([email protected]._hyg.403 : Multiset.{u1} α) => Nat) (Multiset.Ico.{u1} α (PartialOrder.toPreorder.{u1} α _inst_1) _inst_2 a b)) (FunLike.coe.{succ u1, succ u1, 1} (AddMonoidHom.{u1, 0} (Multiset.{u1} α) Nat (AddMonoid.toAddZeroClass.{u1} (Multiset.{u1} α) (AddRightCancelMonoid.toAddMonoid.{u1} (Multiset.{u1} α) (AddCancelMonoid.toAddRightCancelMonoid.{u1} (Multiset.{u1} α) (AddCancelCommMonoid.toAddCancelMonoid.{u1} (Multiset.{u1} α) (OrderedCancelAddCommMonoid.toCancelAddCommMonoid.{u1} (Multiset.{u1} α) (Multiset.instOrderedCancelAddCommMonoidMultiset.{u1} α)))))) (AddMonoid.toAddZeroClass.{0} Nat Nat.addMonoid)) (Multiset.{u1} α) (fun (_x : Multiset.{u1} α) => (fun ([email protected]._hyg.403 : Multiset.{u1} α) => Nat) _x) (AddHomClass.toFunLike.{u1, u1, 0} (AddMonoidHom.{u1, 0} (Multiset.{u1} α) Nat (AddMonoid.toAddZeroClass.{u1} (Multiset.{u1} α) (AddRightCancelMonoid.toAddMonoid.{u1} (Multiset.{u1} α) (AddCancelMonoid.toAddRightCancelMonoid.{u1} (Multiset.{u1} α) (AddCancelCommMonoid.toAddCancelMonoid.{u1} (Multiset.{u1} α) (OrderedCancelAddCommMonoid.toCancelAddCommMonoid.{u1} (Multiset.{u1} α) (Multiset.instOrderedCancelAddCommMonoidMultiset.{u1} α)))))) (AddMonoid.toAddZeroClass.{0} Nat Nat.addMonoid)) (Multiset.{u1} α) Nat (AddZeroClass.toAdd.{u1} (Multiset.{u1} α) (AddMonoid.toAddZeroClass.{u1} (Multiset.{u1} α) (AddRightCancelMonoid.toAddMonoid.{u1} (Multiset.{u1} α) (AddCancelMonoid.toAddRightCancelMonoid.{u1} (Multiset.{u1} α) (AddCancelCommMonoid.toAddCancelMonoid.{u1} (Multiset.{u1} α) (OrderedCancelAddCommMonoid.toCancelAddCommMonoid.{u1} (Multiset.{u1} α) (Multiset.instOrderedCancelAddCommMonoidMultiset.{u1} α))))))) (AddZeroClass.toAdd.{0} Nat (AddMonoid.toAddZeroClass.{0} Nat Nat.addMonoid)) (AddMonoidHomClass.toAddHomClass.{u1, u1, 0} (AddMonoidHom.{u1, 0} (Multiset.{u1} α) Nat (AddMonoid.toAddZeroClass.{u1} (Multiset.{u1} α) (AddRightCancelMonoid.toAddMonoid.{u1} (Multiset.{u1} α) (AddCancelMonoid.toAddRightCancelMonoid.{u1} (Multiset.{u1} α) (AddCancelCommMonoid.toAddCancelMonoid.{u1} (Multiset.{u1} α) (OrderedCancelAddCommMonoid.toCancelAddCommMonoid.{u1} (Multiset.{u1} α) (Multiset.instOrderedCancelAddCommMonoidMultiset.{u1} α)))))) (AddMonoid.toAddZeroClass.{0} Nat Nat.addMonoid)) (Multiset.{u1} α) Nat (AddMonoid.toAddZeroClass.{u1} (Multiset.{u1} α) (AddRightCancelMonoid.toAddMonoid.{u1} (Multiset.{u1} α) (AddCancelMonoid.toAddRightCancelMonoid.{u1} (Multiset.{u1} α) (AddCancelCommMonoid.toAddCancelMonoid.{u1} (Multiset.{u1} α) (OrderedCancelAddCommMonoid.toCancelAddCommMonoid.{u1} (Multiset.{u1} α) (Multiset.instOrderedCancelAddCommMonoidMultiset.{u1} α)))))) (AddMonoid.toAddZeroClass.{0} Nat Nat.addMonoid) (AddMonoidHom.addMonoidHomClass.{u1, 0} (Multiset.{u1} α) Nat (AddMonoid.toAddZeroClass.{u1} (Multiset.{u1} α) (AddRightCancelMonoid.toAddMonoid.{u1} (Multiset.{u1} α) (AddCancelMonoid.toAddRightCancelMonoid.{u1} (Multiset.{u1} α) (AddCancelCommMonoid.toAddCancelMonoid.{u1} (Multiset.{u1} α) (OrderedCancelAddCommMonoid.toCancelAddCommMonoid.{u1} (Multiset.{u1} α) (Multiset.instOrderedCancelAddCommMonoidMultiset.{u1} α)))))) (AddMonoid.toAddZeroClass.{0} Nat Nat.addMonoid)))) (Multiset.card.{u1} α) (Multiset.Ico.{u1} α (PartialOrder.toPreorder.{u1} α _inst_1) _inst_2 a b)) (HSub.hSub.{0, 0, 0} ((fun ([email protected]._hyg.403 : Multiset.{u1} α) => Nat) (Multiset.Icc.{u1} α (PartialOrder.toPreorder.{u1} α _inst_1) _inst_2 a b)) ((fun ([email protected]._hyg.403 : Multiset.{u1} α) => Nat) (Multiset.Ico.{u1} α (PartialOrder.toPreorder.{u1} α _inst_1) _inst_2 a b)) ((fun ([email protected]._hyg.403 : Multiset.{u1} α) => Nat) (Multiset.Icc.{u1} α (PartialOrder.toPreorder.{u1} α _inst_1) _inst_2 a b)) (instHSub.{0} ((fun ([email protected]._hyg.403 : Multiset.{u1} α) => Nat) (Multiset.Icc.{u1} α (PartialOrder.toPreorder.{u1} α _inst_1) _inst_2 a b)) instSubNat) (FunLike.coe.{succ u1, succ u1, 1} (AddMonoidHom.{u1, 0} (Multiset.{u1} α) Nat (AddMonoid.toAddZeroClass.{u1} (Multiset.{u1} α) (AddRightCancelMonoid.toAddMonoid.{u1} (Multiset.{u1} α) (AddCancelMonoid.toAddRightCancelMonoid.{u1} (Multiset.{u1} α) (AddCancelCommMonoid.toAddCancelMonoid.{u1} (Multiset.{u1} α) (OrderedCancelAddCommMonoid.toCancelAddCommMonoid.{u1} (Multiset.{u1} α) (Multiset.instOrderedCancelAddCommMonoidMultiset.{u1} α)))))) (AddMonoid.toAddZeroClass.{0} Nat Nat.addMonoid)) (Multiset.{u1} α) (fun (_x : Multiset.{u1} α) => (fun ([email protected]._hyg.403 : Multiset.{u1} α) => Nat) _x) (AddHomClass.toFunLike.{u1, u1, 0} (AddMonoidHom.{u1, 0} (Multiset.{u1} α) Nat (AddMonoid.toAddZeroClass.{u1} (Multiset.{u1} α) (AddRightCancelMonoid.toAddMonoid.{u1} (Multiset.{u1} α) (AddCancelMonoid.toAddRightCancelMonoid.{u1} (Multiset.{u1} α) (AddCancelCommMonoid.toAddCancelMonoid.{u1} (Multiset.{u1} α) (OrderedCancelAddCommMonoid.toCancelAddCommMonoid.{u1} (Multiset.{u1} α) (Multiset.instOrderedCancelAddCommMonoidMultiset.{u1} α)))))) (AddMonoid.toAddZeroClass.{0} Nat Nat.addMonoid)) (Multiset.{u1} α) Nat (AddZeroClass.toAdd.{u1} (Multiset.{u1} α) (AddMonoid.toAddZeroClass.{u1} (Multiset.{u1} α) (AddRightCancelMonoid.toAddMonoid.{u1} (Multiset.{u1} α) (AddCancelMonoid.toAddRightCancelMonoid.{u1} (Multiset.{u1} α) (AddCancelCommMonoid.toAddCancelMonoid.{u1} (Multiset.{u1} α) (OrderedCancelAddCommMonoid.toCancelAddCommMonoid.{u1} (Multiset.{u1} α) (Multiset.instOrderedCancelAddCommMonoidMultiset.{u1} α))))))) (AddZeroClass.toAdd.{0} Nat (AddMonoid.toAddZeroClass.{0} Nat Nat.addMonoid)) (AddMonoidHomClass.toAddHomClass.{u1, u1, 0} (AddMonoidHom.{u1, 0} (Multiset.{u1} α) Nat (AddMonoid.toAddZeroClass.{u1} (Multiset.{u1} α) (AddRightCancelMonoid.toAddMonoid.{u1} (Multiset.{u1} α) (AddCancelMonoid.toAddRightCancelMonoid.{u1} (Multiset.{u1} α) (AddCancelCommMonoid.toAddCancelMonoid.{u1} (Multiset.{u1} α) (OrderedCancelAddCommMonoid.toCancelAddCommMonoid.{u1} (Multiset.{u1} α) (Multiset.instOrderedCancelAddCommMonoidMultiset.{u1} α)))))) (AddMonoid.toAddZeroClass.{0} Nat Nat.addMonoid)) (Multiset.{u1} α) Nat (AddMonoid.toAddZeroClass.{u1} (Multiset.{u1} α) (AddRightCancelMonoid.toAddMonoid.{u1} (Multiset.{u1} α) (AddCancelMonoid.toAddRightCancelMonoid.{u1} (Multiset.{u1} α) (AddCancelCommMonoid.toAddCancelMonoid.{u1} (Multiset.{u1} α) (OrderedCancelAddCommMonoid.toCancelAddCommMonoid.{u1} (Multiset.{u1} α) (Multiset.instOrderedCancelAddCommMonoidMultiset.{u1} α)))))) (AddMonoid.toAddZeroClass.{0} Nat Nat.addMonoid) (AddMonoidHom.addMonoidHomClass.{u1, 0} (Multiset.{u1} α) Nat (AddMonoid.toAddZeroClass.{u1} (Multiset.{u1} α) (AddRightCancelMonoid.toAddMonoid.{u1} (Multiset.{u1} α) (AddCancelMonoid.toAddRightCancelMonoid.{u1} (Multiset.{u1} α) (AddCancelCommMonoid.toAddCancelMonoid.{u1} (Multiset.{u1} α) (OrderedCancelAddCommMonoid.toCancelAddCommMonoid.{u1} (Multiset.{u1} α) (Multiset.instOrderedCancelAddCommMonoidMultiset.{u1} α)))))) (AddMonoid.toAddZeroClass.{0} Nat Nat.addMonoid)))) (Multiset.card.{u1} α) (Multiset.Icc.{u1} α (PartialOrder.toPreorder.{u1} α _inst_1) _inst_2 a b)) (OfNat.ofNat.{0} ((fun ([email protected]._hyg.403 : Multiset.{u1} α) => Nat) (Multiset.Ico.{u1} α (PartialOrder.toPreorder.{u1} α _inst_1) _inst_2 a b)) 1 (instOfNatNat 1))) Case conversion may be inaccurate. Consider using '#align multiset.card_Ico_eq_card_Icc_sub_one Multiset.card_Ico_eq_card_Icc_sub_oneₓ'. -/ theorem card_Ico_eq_card_Icc_sub_one (a b : α) : (Ico a b).card = (Icc a b).card - 1 := Finset.card_Ico_eq_card_Icc_sub_one _ _ #align multiset.card_Ico_eq_card_Icc_sub_one Multiset.card_Ico_eq_card_Icc_sub_one /- warning: multiset.card_Ioc_eq_card_Icc_sub_one -> Multiset.card_Ioc_eq_card_Icc_sub_one is a dubious translation: lean 3 declaration is forall {α : Type.{u1}} [_inst_1 : PartialOrder.{u1} α] [_inst_2 : LocallyFiniteOrder.{u1} α (PartialOrder.toPreorder.{u1} α _inst_1)] (a : α) (b : α), Eq.{1} Nat (coeFn.{succ u1, succ u1} (AddMonoidHom.{u1, 0} (Multiset.{u1} α) Nat (AddMonoid.toAddZeroClass.{u1} (Multiset.{u1} α) (AddRightCancelMonoid.toAddMonoid.{u1} (Multiset.{u1} α) (AddCancelMonoid.toAddRightCancelMonoid.{u1} (Multiset.{u1} α) (AddCancelCommMonoid.toAddCancelMonoid.{u1} (Multiset.{u1} α) (OrderedCancelAddCommMonoid.toCancelAddCommMonoid.{u1} (Multiset.{u1} α) (Multiset.orderedCancelAddCommMonoid.{u1} α)))))) (AddMonoid.toAddZeroClass.{0} Nat Nat.addMonoid)) (fun (_x : AddMonoidHom.{u1, 0} (Multiset.{u1} α) Nat (AddMonoid.toAddZeroClass.{u1} (Multiset.{u1} α) (AddRightCancelMonoid.toAddMonoid.{u1} (Multiset.{u1} α) (AddCancelMonoid.toAddRightCancelMonoid.{u1} (Multiset.{u1} α) (AddCancelCommMonoid.toAddCancelMonoid.{u1} (Multiset.{u1} α) (OrderedCancelAddCommMonoid.toCancelAddCommMonoid.{u1} (Multiset.{u1} α) (Multiset.orderedCancelAddCommMonoid.{u1} α)))))) (AddMonoid.toAddZeroClass.{0} Nat Nat.addMonoid)) => (Multiset.{u1} α) -> Nat) (AddMonoidHom.hasCoeToFun.{u1, 0} (Multiset.{u1} α) Nat (AddMonoid.toAddZeroClass.{u1} (Multiset.{u1} α) (AddRightCancelMonoid.toAddMonoid.{u1} (Multiset.{u1} α) (AddCancelMonoid.toAddRightCancelMonoid.{u1} (Multiset.{u1} α) (AddCancelCommMonoid.toAddCancelMonoid.{u1} (Multiset.{u1} α) (OrderedCancelAddCommMonoid.toCancelAddCommMonoid.{u1} (Multiset.{u1} α) (Multiset.orderedCancelAddCommMonoid.{u1} α)))))) (AddMonoid.toAddZeroClass.{0} Nat Nat.addMonoid)) (Multiset.card.{u1} α) (Multiset.Ioc.{u1} α (PartialOrder.toPreorder.{u1} α _inst_1) _inst_2 a b)) (HSub.hSub.{0, 0, 0} Nat Nat Nat (instHSub.{0} Nat Nat.hasSub) (coeFn.{succ u1, succ u1} (AddMonoidHom.{u1, 0} (Multiset.{u1} α) Nat (AddMonoid.toAddZeroClass.{u1} (Multiset.{u1} α) (AddRightCancelMonoid.toAddMonoid.{u1} (Multiset.{u1} α) (AddCancelMonoid.toAddRightCancelMonoid.{u1} (Multiset.{u1} α) (AddCancelCommMonoid.toAddCancelMonoid.{u1} (Multiset.{u1} α) (OrderedCancelAddCommMonoid.toCancelAddCommMonoid.{u1} (Multiset.{u1} α) (Multiset.orderedCancelAddCommMonoid.{u1} α)))))) (AddMonoid.toAddZeroClass.{0} Nat Nat.addMonoid)) (fun (_x : AddMonoidHom.{u1, 0} (Multiset.{u1} α) Nat (AddMonoid.toAddZeroClass.{u1} (Multiset.{u1} α) (AddRightCancelMonoid.toAddMonoid.{u1} (Multiset.{u1} α) (AddCancelMonoid.toAddRightCancelMonoid.{u1} (Multiset.{u1} α) (AddCancelCommMonoid.toAddCancelMonoid.{u1} (Multiset.{u1} α) (OrderedCancelAddCommMonoid.toCancelAddCommMonoid.{u1} (Multiset.{u1} α) (Multiset.orderedCancelAddCommMonoid.{u1} α)))))) (AddMonoid.toAddZeroClass.{0} Nat Nat.addMonoid)) => (Multiset.{u1} α) -> Nat) (AddMonoidHom.hasCoeToFun.{u1, 0} (Multiset.{u1} α) Nat (AddMonoid.toAddZeroClass.{u1} (Multiset.{u1} α) (AddRightCancelMonoid.toAddMonoid.{u1} (Multiset.{u1} α) (AddCancelMonoid.toAddRightCancelMonoid.{u1} (Multiset.{u1} α) (AddCancelCommMonoid.toAddCancelMonoid.{u1} (Multiset.{u1} α) (OrderedCancelAddCommMonoid.toCancelAddCommMonoid.{u1} (Multiset.{u1} α) (Multiset.orderedCancelAddCommMonoid.{u1} α)))))) (AddMonoid.toAddZeroClass.{0} Nat Nat.addMonoid)) (Multiset.card.{u1} α) (Multiset.Icc.{u1} α (PartialOrder.toPreorder.{u1} α _inst_1) _inst_2 a b)) (OfNat.ofNat.{0} Nat 1 (OfNat.mk.{0} Nat 1 (One.one.{0} Nat Nat.hasOne)))) but is expected to have type forall {α : Type.{u1}} [_inst_1 : PartialOrder.{u1} α] [_inst_2 : LocallyFiniteOrder.{u1} α (PartialOrder.toPreorder.{u1} α _inst_1)] (a : α) (b : α), Eq.{1} ((fun ([email protected]._hyg.403 : Multiset.{u1} α) => Nat) (Multiset.Ioc.{u1} α (PartialOrder.toPreorder.{u1} α _inst_1) _inst_2 a b)) (FunLike.coe.{succ u1, succ u1, 1} (AddMonoidHom.{u1, 0} (Multiset.{u1} α) Nat (AddMonoid.toAddZeroClass.{u1} (Multiset.{u1} α) (AddRightCancelMonoid.toAddMonoid.{u1} (Multiset.{u1} α) (AddCancelMonoid.toAddRightCancelMonoid.{u1} (Multiset.{u1} α) (AddCancelCommMonoid.toAddCancelMonoid.{u1} (Multiset.{u1} α) (OrderedCancelAddCommMonoid.toCancelAddCommMonoid.{u1} (Multiset.{u1} α) (Multiset.instOrderedCancelAddCommMonoidMultiset.{u1} α)))))) (AddMonoid.toAddZeroClass.{0} Nat Nat.addMonoid)) (Multiset.{u1} α) (fun (_x : Multiset.{u1} α) => (fun ([email protected]._hyg.403 : Multiset.{u1} α) => Nat) _x) (AddHomClass.toFunLike.{u1, u1, 0} (AddMonoidHom.{u1, 0} (Multiset.{u1} α) Nat (AddMonoid.toAddZeroClass.{u1} (Multiset.{u1} α) (AddRightCancelMonoid.toAddMonoid.{u1} (Multiset.{u1} α) (AddCancelMonoid.toAddRightCancelMonoid.{u1} (Multiset.{u1} α) (AddCancelCommMonoid.toAddCancelMonoid.{u1} (Multiset.{u1} α) (OrderedCancelAddCommMonoid.toCancelAddCommMonoid.{u1} (Multiset.{u1} α) (Multiset.instOrderedCancelAddCommMonoidMultiset.{u1} α)))))) (AddMonoid.toAddZeroClass.{0} Nat Nat.addMonoid)) (Multiset.{u1} α) Nat (AddZeroClass.toAdd.{u1} (Multiset.{u1} α) (AddMonoid.toAddZeroClass.{u1} (Multiset.{u1} α) (AddRightCancelMonoid.toAddMonoid.{u1} (Multiset.{u1} α) (AddCancelMonoid.toAddRightCancelMonoid.{u1} (Multiset.{u1} α) (AddCancelCommMonoid.toAddCancelMonoid.{u1} (Multiset.{u1} α) (OrderedCancelAddCommMonoid.toCancelAddCommMonoid.{u1} (Multiset.{u1} α) (Multiset.instOrderedCancelAddCommMonoidMultiset.{u1} α))))))) (AddZeroClass.toAdd.{0} Nat (AddMonoid.toAddZeroClass.{0} Nat Nat.addMonoid)) (AddMonoidHomClass.toAddHomClass.{u1, u1, 0} (AddMonoidHom.{u1, 0} (Multiset.{u1} α) Nat (AddMonoid.toAddZeroClass.{u1} (Multiset.{u1} α) (AddRightCancelMonoid.toAddMonoid.{u1} (Multiset.{u1} α) (AddCancelMonoid.toAddRightCancelMonoid.{u1} (Multiset.{u1} α) (AddCancelCommMonoid.toAddCancelMonoid.{u1} (Multiset.{u1} α) (OrderedCancelAddCommMonoid.toCancelAddCommMonoid.{u1} (Multiset.{u1} α) (Multiset.instOrderedCancelAddCommMonoidMultiset.{u1} α)))))) (AddMonoid.toAddZeroClass.{0} Nat Nat.addMonoid)) (Multiset.{u1} α) Nat (AddMonoid.toAddZeroClass.{u1} (Multiset.{u1} α) (AddRightCancelMonoid.toAddMonoid.{u1} (Multiset.{u1} α) (AddCancelMonoid.toAddRightCancelMonoid.{u1} (Multiset.{u1} α) (AddCancelCommMonoid.toAddCancelMonoid.{u1} (Multiset.{u1} α) (OrderedCancelAddCommMonoid.toCancelAddCommMonoid.{u1} (Multiset.{u1} α) (Multiset.instOrderedCancelAddCommMonoidMultiset.{u1} α)))))) (AddMonoid.toAddZeroClass.{0} Nat Nat.addMonoid) (AddMonoidHom.addMonoidHomClass.{u1, 0} (Multiset.{u1} α) Nat (AddMonoid.toAddZeroClass.{u1} (Multiset.{u1} α) (AddRightCancelMonoid.toAddMonoid.{u1} (Multiset.{u1} α) (AddCancelMonoid.toAddRightCancelMonoid.{u1} (Multiset.{u1} α) (AddCancelCommMonoid.toAddCancelMonoid.{u1} (Multiset.{u1} α) (OrderedCancelAddCommMonoid.toCancelAddCommMonoid.{u1} (Multiset.{u1} α) (Multiset.instOrderedCancelAddCommMonoidMultiset.{u1} α)))))) (AddMonoid.toAddZeroClass.{0} Nat Nat.addMonoid)))) (Multiset.card.{u1} α) (Multiset.Ioc.{u1} α (PartialOrder.toPreorder.{u1} α _inst_1) _inst_2 a b)) (HSub.hSub.{0, 0, 0} ((fun ([email protected]._hyg.403 : Multiset.{u1} α) => Nat) (Multiset.Icc.{u1} α (PartialOrder.toPreorder.{u1} α _inst_1) _inst_2 a b)) ((fun ([email protected]._hyg.403 : Multiset.{u1} α) => Nat) (Multiset.Ioc.{u1} α (PartialOrder.toPreorder.{u1} α _inst_1) _inst_2 a b)) ((fun ([email protected]._hyg.403 : Multiset.{u1} α) => Nat) (Multiset.Icc.{u1} α (PartialOrder.toPreorder.{u1} α _inst_1) _inst_2 a b)) (instHSub.{0} ((fun ([email protected]._hyg.403 : Multiset.{u1} α) => Nat) (Multiset.Icc.{u1} α (PartialOrder.toPreorder.{u1} α _inst_1) _inst_2 a b)) instSubNat) (FunLike.coe.{succ u1, succ u1, 1} (AddMonoidHom.{u1, 0} (Multiset.{u1} α) Nat (AddMonoid.toAddZeroClass.{u1} (Multiset.{u1} α) (AddRightCancelMonoid.toAddMonoid.{u1} (Multiset.{u1} α) (AddCancelMonoid.toAddRightCancelMonoid.{u1} (Multiset.{u1} α) (AddCancelCommMonoid.toAddCancelMonoid.{u1} (Multiset.{u1} α) (OrderedCancelAddCommMonoid.toCancelAddCommMonoid.{u1} (Multiset.{u1} α) (Multiset.instOrderedCancelAddCommMonoidMultiset.{u1} α)))))) (AddMonoid.toAddZeroClass.{0} Nat Nat.addMonoid)) (Multiset.{u1} α) (fun (_x : Multiset.{u1} α) => (fun ([email protected]._hyg.403 : Multiset.{u1} α) => Nat) _x) (AddHomClass.toFunLike.{u1, u1, 0} (AddMonoidHom.{u1, 0} (Multiset.{u1} α) Nat (AddMonoid.toAddZeroClass.{u1} (Multiset.{u1} α) (AddRightCancelMonoid.toAddMonoid.{u1} (Multiset.{u1} α) (AddCancelMonoid.toAddRightCancelMonoid.{u1} (Multiset.{u1} α) (AddCancelCommMonoid.toAddCancelMonoid.{u1} (Multiset.{u1} α) (OrderedCancelAddCommMonoid.toCancelAddCommMonoid.{u1} (Multiset.{u1} α) (Multiset.instOrderedCancelAddCommMonoidMultiset.{u1} α)))))) (AddMonoid.toAddZeroClass.{0} Nat Nat.addMonoid)) (Multiset.{u1} α) Nat (AddZeroClass.toAdd.{u1} (Multiset.{u1} α) (AddMonoid.toAddZeroClass.{u1} (Multiset.{u1} α) (AddRightCancelMonoid.toAddMonoid.{u1} (Multiset.{u1} α) (AddCancelMonoid.toAddRightCancelMonoid.{u1} (Multiset.{u1} α) (AddCancelCommMonoid.toAddCancelMonoid.{u1} (Multiset.{u1} α) (OrderedCancelAddCommMonoid.toCancelAddCommMonoid.{u1} (Multiset.{u1} α) (Multiset.instOrderedCancelAddCommMonoidMultiset.{u1} α))))))) (AddZeroClass.toAdd.{0} Nat (AddMonoid.toAddZeroClass.{0} Nat Nat.addMonoid)) (AddMonoidHomClass.toAddHomClass.{u1, u1, 0} (AddMonoidHom.{u1, 0} (Multiset.{u1} α) Nat (AddMonoid.toAddZeroClass.{u1} (Multiset.{u1} α) (AddRightCancelMonoid.toAddMonoid.{u1} (Multiset.{u1} α) (AddCancelMonoid.toAddRightCancelMonoid.{u1} (Multiset.{u1} α) (AddCancelCommMonoid.toAddCancelMonoid.{u1} (Multiset.{u1} α) (OrderedCancelAddCommMonoid.toCancelAddCommMonoid.{u1} (Multiset.{u1} α) (Multiset.instOrderedCancelAddCommMonoidMultiset.{u1} α)))))) (AddMonoid.toAddZeroClass.{0} Nat Nat.addMonoid)) (Multiset.{u1} α) Nat (AddMonoid.toAddZeroClass.{u1} (Multiset.{u1} α) (AddRightCancelMonoid.toAddMonoid.{u1} (Multiset.{u1} α) (AddCancelMonoid.toAddRightCancelMonoid.{u1} (Multiset.{u1} α) (AddCancelCommMonoid.toAddCancelMonoid.{u1} (Multiset.{u1} α) (OrderedCancelAddCommMonoid.toCancelAddCommMonoid.{u1} (Multiset.{u1} α) (Multiset.instOrderedCancelAddCommMonoidMultiset.{u1} α)))))) (AddMonoid.toAddZeroClass.{0} Nat Nat.addMonoid) (AddMonoidHom.addMonoidHomClass.{u1, 0} (Multiset.{u1} α) Nat (AddMonoid.toAddZeroClass.{u1} (Multiset.{u1} α) (AddRightCancelMonoid.toAddMonoid.{u1} (Multiset.{u1} α) (AddCancelMonoid.toAddRightCancelMonoid.{u1} (Multiset.{u1} α) (AddCancelCommMonoid.toAddCancelMonoid.{u1} (Multiset.{u1} α) (OrderedCancelAddCommMonoid.toCancelAddCommMonoid.{u1} (Multiset.{u1} α) (Multiset.instOrderedCancelAddCommMonoidMultiset.{u1} α)))))) (AddMonoid.toAddZeroClass.{0} Nat Nat.addMonoid)))) (Multiset.card.{u1} α) (Multiset.Icc.{u1} α (PartialOrder.toPreorder.{u1} α _inst_1) _inst_2 a b)) (OfNat.ofNat.{0} ((fun ([email protected]._hyg.403 : Multiset.{u1} α) => Nat) (Multiset.Ioc.{u1} α (PartialOrder.toPreorder.{u1} α _inst_1) _inst_2 a b)) 1 (instOfNatNat 1))) Case conversion may be inaccurate. Consider using '#align multiset.card_Ioc_eq_card_Icc_sub_one Multiset.card_Ioc_eq_card_Icc_sub_oneₓ'. -/ theorem card_Ioc_eq_card_Icc_sub_one (a b : α) : (Ioc a b).card = (Icc a b).card - 1 := Finset.card_Ioc_eq_card_Icc_sub_one _ _ #align multiset.card_Ioc_eq_card_Icc_sub_one Multiset.card_Ioc_eq_card_Icc_sub_one /- warning: multiset.card_Ioo_eq_card_Ico_sub_one -> Multiset.card_Ioo_eq_card_Ico_sub_one is a dubious translation: lean 3 declaration is forall {α : Type.{u1}} [_inst_1 : PartialOrder.{u1} α] [_inst_2 : LocallyFiniteOrder.{u1} α (PartialOrder.toPreorder.{u1} α _inst_1)] (a : α) (b : α), Eq.{1} Nat (coeFn.{succ u1, succ u1} (AddMonoidHom.{u1, 0} (Multiset.{u1} α) Nat (AddMonoid.toAddZeroClass.{u1} (Multiset.{u1} α) (AddRightCancelMonoid.toAddMonoid.{u1} (Multiset.{u1} α) (AddCancelMonoid.toAddRightCancelMonoid.{u1} (Multiset.{u1} α) (AddCancelCommMonoid.toAddCancelMonoid.{u1} (Multiset.{u1} α) (OrderedCancelAddCommMonoid.toCancelAddCommMonoid.{u1} (Multiset.{u1} α) (Multiset.orderedCancelAddCommMonoid.{u1} α)))))) (AddMonoid.toAddZeroClass.{0} Nat Nat.addMonoid)) (fun (_x : AddMonoidHom.{u1, 0} (Multiset.{u1} α) Nat (AddMonoid.toAddZeroClass.{u1} (Multiset.{u1} α) (AddRightCancelMonoid.toAddMonoid.{u1} (Multiset.{u1} α) (AddCancelMonoid.toAddRightCancelMonoid.{u1} (Multiset.{u1} α) (AddCancelCommMonoid.toAddCancelMonoid.{u1} (Multiset.{u1} α) (OrderedCancelAddCommMonoid.toCancelAddCommMonoid.{u1} (Multiset.{u1} α) (Multiset.orderedCancelAddCommMonoid.{u1} α)))))) (AddMonoid.toAddZeroClass.{0} Nat Nat.addMonoid)) => (Multiset.{u1} α) -> Nat) (AddMonoidHom.hasCoeToFun.{u1, 0} (Multiset.{u1} α) Nat (AddMonoid.toAddZeroClass.{u1} (Multiset.{u1} α) (AddRightCancelMonoid.toAddMonoid.{u1} (Multiset.{u1} α) (AddCancelMonoid.toAddRightCancelMonoid.{u1} (Multiset.{u1} α) (AddCancelCommMonoid.toAddCancelMonoid.{u1} (Multiset.{u1} α) (OrderedCancelAddCommMonoid.toCancelAddCommMonoid.{u1} (Multiset.{u1} α) (Multiset.orderedCancelAddCommMonoid.{u1} α)))))) (AddMonoid.toAddZeroClass.{0} Nat Nat.addMonoid)) (Multiset.card.{u1} α) (Multiset.Ioo.{u1} α (PartialOrder.toPreorder.{u1} α _inst_1) _inst_2 a b)) (HSub.hSub.{0, 0, 0} Nat Nat Nat (instHSub.{0} Nat Nat.hasSub) (coeFn.{succ u1, succ u1} (AddMonoidHom.{u1, 0} (Multiset.{u1} α) Nat (AddMonoid.toAddZeroClass.{u1} (Multiset.{u1} α) (AddRightCancelMonoid.toAddMonoid.{u1} (Multiset.{u1} α) (AddCancelMonoid.toAddRightCancelMonoid.{u1} (Multiset.{u1} α) (AddCancelCommMonoid.toAddCancelMonoid.{u1} (Multiset.{u1} α) (OrderedCancelAddCommMonoid.toCancelAddCommMonoid.{u1} (Multiset.{u1} α) (Multiset.orderedCancelAddCommMonoid.{u1} α)))))) (AddMonoid.toAddZeroClass.{0} Nat Nat.addMonoid)) (fun (_x : AddMonoidHom.{u1, 0} (Multiset.{u1} α) Nat (AddMonoid.toAddZeroClass.{u1} (Multiset.{u1} α) (AddRightCancelMonoid.toAddMonoid.{u1} (Multiset.{u1} α) (AddCancelMonoid.toAddRightCancelMonoid.{u1} (Multiset.{u1} α) (AddCancelCommMonoid.toAddCancelMonoid.{u1} (Multiset.{u1} α) (OrderedCancelAddCommMonoid.toCancelAddCommMonoid.{u1} (Multiset.{u1} α) (Multiset.orderedCancelAddCommMonoid.{u1} α)))))) (AddMonoid.toAddZeroClass.{0} Nat Nat.addMonoid)) => (Multiset.{u1} α) -> Nat) (AddMonoidHom.hasCoeToFun.{u1, 0} (Multiset.{u1} α) Nat (AddMonoid.toAddZeroClass.{u1} (Multiset.{u1} α) (AddRightCancelMonoid.toAddMonoid.{u1} (Multiset.{u1} α) (AddCancelMonoid.toAddRightCancelMonoid.{u1} (Multiset.{u1} α) (AddCancelCommMonoid.toAddCancelMonoid.{u1} (Multiset.{u1} α) (OrderedCancelAddCommMonoid.toCancelAddCommMonoid.{u1} (Multiset.{u1} α) (Multiset.orderedCancelAddCommMonoid.{u1} α)))))) (AddMonoid.toAddZeroClass.{0} Nat Nat.addMonoid)) (Multiset.card.{u1} α) (Multiset.Ico.{u1} α (PartialOrder.toPreorder.{u1} α _inst_1) _inst_2 a b)) (OfNat.ofNat.{0} Nat 1 (OfNat.mk.{0} Nat 1 (One.one.{0} Nat Nat.hasOne)))) but is expected to have type forall {α : Type.{u1}} [_inst_1 : PartialOrder.{u1} α] [_inst_2 : LocallyFiniteOrder.{u1} α (PartialOrder.toPreorder.{u1} α _inst_1)] (a : α) (b : α), Eq.{1} ((fun ([email protected]._hyg.403 : Multiset.{u1} α) => Nat) (Multiset.Ioo.{u1} α (PartialOrder.toPreorder.{u1} α _inst_1) _inst_2 a b)) (FunLike.coe.{succ u1, succ u1, 1} (AddMonoidHom.{u1, 0} (Multiset.{u1} α) Nat (AddMonoid.toAddZeroClass.{u1} (Multiset.{u1} α) (AddRightCancelMonoid.toAddMonoid.{u1} (Multiset.{u1} α) (AddCancelMonoid.toAddRightCancelMonoid.{u1} (Multiset.{u1} α) (AddCancelCommMonoid.toAddCancelMonoid.{u1} (Multiset.{u1} α) (OrderedCancelAddCommMonoid.toCancelAddCommMonoid.{u1} (Multiset.{u1} α) (Multiset.instOrderedCancelAddCommMonoidMultiset.{u1} α)))))) (AddMonoid.toAddZeroClass.{0} Nat Nat.addMonoid)) (Multiset.{u1} α) (fun (_x : Multiset.{u1} α) => (fun ([email protected]._hyg.403 : Multiset.{u1} α) => Nat) _x) (AddHomClass.toFunLike.{u1, u1, 0} (AddMonoidHom.{u1, 0} (Multiset.{u1} α) Nat (AddMonoid.toAddZeroClass.{u1} (Multiset.{u1} α) (AddRightCancelMonoid.toAddMonoid.{u1} (Multiset.{u1} α) (AddCancelMonoid.toAddRightCancelMonoid.{u1} (Multiset.{u1} α) (AddCancelCommMonoid.toAddCancelMonoid.{u1} (Multiset.{u1} α) (OrderedCancelAddCommMonoid.toCancelAddCommMonoid.{u1} (Multiset.{u1} α) (Multiset.instOrderedCancelAddCommMonoidMultiset.{u1} α)))))) (AddMonoid.toAddZeroClass.{0} Nat Nat.addMonoid)) (Multiset.{u1} α) Nat (AddZeroClass.toAdd.{u1} (Multiset.{u1} α) (AddMonoid.toAddZeroClass.{u1} (Multiset.{u1} α) (AddRightCancelMonoid.toAddMonoid.{u1} (Multiset.{u1} α) (AddCancelMonoid.toAddRightCancelMonoid.{u1} (Multiset.{u1} α) (AddCancelCommMonoid.toAddCancelMonoid.{u1} (Multiset.{u1} α) (OrderedCancelAddCommMonoid.toCancelAddCommMonoid.{u1} (Multiset.{u1} α) (Multiset.instOrderedCancelAddCommMonoidMultiset.{u1} α))))))) (AddZeroClass.toAdd.{0} Nat (AddMonoid.toAddZeroClass.{0} Nat Nat.addMonoid)) (AddMonoidHomClass.toAddHomClass.{u1, u1, 0} (AddMonoidHom.{u1, 0} (Multiset.{u1} α) Nat (AddMonoid.toAddZeroClass.{u1} (Multiset.{u1} α) (AddRightCancelMonoid.toAddMonoid.{u1} (Multiset.{u1} α) (AddCancelMonoid.toAddRightCancelMonoid.{u1} (Multiset.{u1} α) (AddCancelCommMonoid.toAddCancelMonoid.{u1} (Multiset.{u1} α) (OrderedCancelAddCommMonoid.toCancelAddCommMonoid.{u1} (Multiset.{u1} α) (Multiset.instOrderedCancelAddCommMonoidMultiset.{u1} α)))))) (AddMonoid.toAddZeroClass.{0} Nat Nat.addMonoid)) (Multiset.{u1} α) Nat (AddMonoid.toAddZeroClass.{u1} (Multiset.{u1} α) (AddRightCancelMonoid.toAddMonoid.{u1} (Multiset.{u1} α) (AddCancelMonoid.toAddRightCancelMonoid.{u1} (Multiset.{u1} α) (AddCancelCommMonoid.toAddCancelMonoid.{u1} (Multiset.{u1} α) (OrderedCancelAddCommMonoid.toCancelAddCommMonoid.{u1} (Multiset.{u1} α) (Multiset.instOrderedCancelAddCommMonoidMultiset.{u1} α)))))) (AddMonoid.toAddZeroClass.{0} Nat Nat.addMonoid) (AddMonoidHom.addMonoidHomClass.{u1, 0} (Multiset.{u1} α) Nat (AddMonoid.toAddZeroClass.{u1} (Multiset.{u1} α) (AddRightCancelMonoid.toAddMonoid.{u1} (Multiset.{u1} α) (AddCancelMonoid.toAddRightCancelMonoid.{u1} (Multiset.{u1} α) (AddCancelCommMonoid.toAddCancelMonoid.{u1} (Multiset.{u1} α) (OrderedCancelAddCommMonoid.toCancelAddCommMonoid.{u1} (Multiset.{u1} α) (Multiset.instOrderedCancelAddCommMonoidMultiset.{u1} α)))))) (AddMonoid.toAddZeroClass.{0} Nat Nat.addMonoid)))) (Multiset.card.{u1} α) (Multiset.Ioo.{u1} α (PartialOrder.toPreorder.{u1} α _inst_1) _inst_2 a b)) (HSub.hSub.{0, 0, 0} ((fun ([email protected]._hyg.403 : Multiset.{u1} α) => Nat) (Multiset.Ico.{u1} α (PartialOrder.toPreorder.{u1} α _inst_1) _inst_2 a b)) ((fun ([email protected]._hyg.403 : Multiset.{u1} α) => Nat) (Multiset.Ioo.{u1} α (PartialOrder.toPreorder.{u1} α _inst_1) _inst_2 a b)) ((fun ([email protected]._hyg.403 : Multiset.{u1} α) => Nat) (Multiset.Ico.{u1} α (PartialOrder.toPreorder.{u1} α _inst_1) _inst_2 a b)) (instHSub.{0} ((fun ([email protected]._hyg.403 : Multiset.{u1} α) => Nat) (Multiset.Ico.{u1} α (PartialOrder.toPreorder.{u1} α _inst_1) _inst_2 a b)) instSubNat) (FunLike.coe.{succ u1, succ u1, 1} (AddMonoidHom.{u1, 0} (Multiset.{u1} α) Nat (AddMonoid.toAddZeroClass.{u1} (Multiset.{u1} α) (AddRightCancelMonoid.toAddMonoid.{u1} (Multiset.{u1} α) (AddCancelMonoid.toAddRightCancelMonoid.{u1} (Multiset.{u1} α) (AddCancelCommMonoid.toAddCancelMonoid.{u1} (Multiset.{u1} α) (OrderedCancelAddCommMonoid.toCancelAddCommMonoid.{u1} (Multiset.{u1} α) (Multiset.instOrderedCancelAddCommMonoidMultiset.{u1} α)))))) (AddMonoid.toAddZeroClass.{0} Nat Nat.addMonoid)) (Multiset.{u1} α) (fun (_x : Multiset.{u1} α) => (fun ([email protected]._hyg.403 : Multiset.{u1} α) => Nat) _x) (AddHomClass.toFunLike.{u1, u1, 0} (AddMonoidHom.{u1, 0} (Multiset.{u1} α) Nat (AddMonoid.toAddZeroClass.{u1} (Multiset.{u1} α) (AddRightCancelMonoid.toAddMonoid.{u1} (Multiset.{u1} α) (AddCancelMonoid.toAddRightCancelMonoid.{u1} (Multiset.{u1} α) (AddCancelCommMonoid.toAddCancelMonoid.{u1} (Multiset.{u1} α) (OrderedCancelAddCommMonoid.toCancelAddCommMonoid.{u1} (Multiset.{u1} α) (Multiset.instOrderedCancelAddCommMonoidMultiset.{u1} α)))))) (AddMonoid.toAddZeroClass.{0} Nat Nat.addMonoid)) (Multiset.{u1} α) Nat (AddZeroClass.toAdd.{u1} (Multiset.{u1} α) (AddMonoid.toAddZeroClass.{u1} (Multiset.{u1} α) (AddRightCancelMonoid.toAddMonoid.{u1} (Multiset.{u1} α) (AddCancelMonoid.toAddRightCancelMonoid.{u1} (Multiset.{u1} α) (AddCancelCommMonoid.toAddCancelMonoid.{u1} (Multiset.{u1} α) (OrderedCancelAddCommMonoid.toCancelAddCommMonoid.{u1} (Multiset.{u1} α) (Multiset.instOrderedCancelAddCommMonoidMultiset.{u1} α))))))) (AddZeroClass.toAdd.{0} Nat (AddMonoid.toAddZeroClass.{0} Nat Nat.addMonoid)) (AddMonoidHomClass.toAddHomClass.{u1, u1, 0} (AddMonoidHom.{u1, 0} (Multiset.{u1} α) Nat (AddMonoid.toAddZeroClass.{u1} (Multiset.{u1} α) (AddRightCancelMonoid.toAddMonoid.{u1} (Multiset.{u1} α) (AddCancelMonoid.toAddRightCancelMonoid.{u1} (Multiset.{u1} α) (AddCancelCommMonoid.toAddCancelMonoid.{u1} (Multiset.{u1} α) (OrderedCancelAddCommMonoid.toCancelAddCommMonoid.{u1} (Multiset.{u1} α) (Multiset.instOrderedCancelAddCommMonoidMultiset.{u1} α)))))) (AddMonoid.toAddZeroClass.{0} Nat Nat.addMonoid)) (Multiset.{u1} α) Nat (AddMonoid.toAddZeroClass.{u1} (Multiset.{u1} α) (AddRightCancelMonoid.toAddMonoid.{u1} (Multiset.{u1} α) (AddCancelMonoid.toAddRightCancelMonoid.{u1} (Multiset.{u1} α) (AddCancelCommMonoid.toAddCancelMonoid.{u1} (Multiset.{u1} α) (OrderedCancelAddCommMonoid.toCancelAddCommMonoid.{u1} (Multiset.{u1} α) (Multiset.instOrderedCancelAddCommMonoidMultiset.{u1} α)))))) (AddMonoid.toAddZeroClass.{0} Nat Nat.addMonoid) (AddMonoidHom.addMonoidHomClass.{u1, 0} (Multiset.{u1} α) Nat (AddMonoid.toAddZeroClass.{u1} (Multiset.{u1} α) (AddRightCancelMonoid.toAddMonoid.{u1} (Multiset.{u1} α) (AddCancelMonoid.toAddRightCancelMonoid.{u1} (Multiset.{u1} α) (AddCancelCommMonoid.toAddCancelMonoid.{u1} (Multiset.{u1} α) (OrderedCancelAddCommMonoid.toCancelAddCommMonoid.{u1} (Multiset.{u1} α) (Multiset.instOrderedCancelAddCommMonoidMultiset.{u1} α)))))) (AddMonoid.toAddZeroClass.{0} Nat Nat.addMonoid)))) (Multiset.card.{u1} α) (Multiset.Ico.{u1} α (PartialOrder.toPreorder.{u1} α _inst_1) _inst_2 a b)) (OfNat.ofNat.{0} ((fun ([email protected]._hyg.403 : Multiset.{u1} α) => Nat) (Multiset.Ioo.{u1} α (PartialOrder.toPreorder.{u1} α _inst_1) _inst_2 a b)) 1 (instOfNatNat 1))) Case conversion may be inaccurate. Consider using '#align multiset.card_Ioo_eq_card_Ico_sub_one Multiset.card_Ioo_eq_card_Ico_sub_oneₓ'. -/ theorem card_Ioo_eq_card_Ico_sub_one (a b : α) : (Ioo a b).card = (Ico a b).card - 1 := Finset.card_Ioo_eq_card_Ico_sub_one _ _ #align multiset.card_Ioo_eq_card_Ico_sub_one Multiset.card_Ioo_eq_card_Ico_sub_one /- warning: multiset.card_Ioo_eq_card_Icc_sub_two -> Multiset.card_Ioo_eq_card_Icc_sub_two is a dubious translation: lean 3 declaration is forall {α : Type.{u1}} [_inst_1 : PartialOrder.{u1} α] [_inst_2 : LocallyFiniteOrder.{u1} α (PartialOrder.toPreorder.{u1} α _inst_1)] (a : α) (b : α), Eq.{1} Nat (coeFn.{succ u1, succ u1} (AddMonoidHom.{u1, 0} (Multiset.{u1} α) Nat (AddMonoid.toAddZeroClass.{u1} (Multiset.{u1} α) (AddRightCancelMonoid.toAddMonoid.{u1} (Multiset.{u1} α) (AddCancelMonoid.toAddRightCancelMonoid.{u1} (Multiset.{u1} α) (AddCancelCommMonoid.toAddCancelMonoid.{u1} (Multiset.{u1} α) (OrderedCancelAddCommMonoid.toCancelAddCommMonoid.{u1} (Multiset.{u1} α) (Multiset.orderedCancelAddCommMonoid.{u1} α)))))) (AddMonoid.toAddZeroClass.{0} Nat Nat.addMonoid)) (fun (_x : AddMonoidHom.{u1, 0} (Multiset.{u1} α) Nat (AddMonoid.toAddZeroClass.{u1} (Multiset.{u1} α) (AddRightCancelMonoid.toAddMonoid.{u1} (Multiset.{u1} α) (AddCancelMonoid.toAddRightCancelMonoid.{u1} (Multiset.{u1} α) (AddCancelCommMonoid.toAddCancelMonoid.{u1} (Multiset.{u1} α) (OrderedCancelAddCommMonoid.toCancelAddCommMonoid.{u1} (Multiset.{u1} α) (Multiset.orderedCancelAddCommMonoid.{u1} α)))))) (AddMonoid.toAddZeroClass.{0} Nat Nat.addMonoid)) => (Multiset.{u1} α) -> Nat) (AddMonoidHom.hasCoeToFun.{u1, 0} (Multiset.{u1} α) Nat (AddMonoid.toAddZeroClass.{u1} (Multiset.{u1} α) (AddRightCancelMonoid.toAddMonoid.{u1} (Multiset.{u1} α) (AddCancelMonoid.toAddRightCancelMonoid.{u1} (Multiset.{u1} α) (AddCancelCommMonoid.toAddCancelMonoid.{u1} (Multiset.{u1} α) (OrderedCancelAddCommMonoid.toCancelAddCommMonoid.{u1} (Multiset.{u1} α) (Multiset.orderedCancelAddCommMonoid.{u1} α)))))) (AddMonoid.toAddZeroClass.{0} Nat Nat.addMonoid)) (Multiset.card.{u1} α) (Multiset.Ioo.{u1} α (PartialOrder.toPreorder.{u1} α _inst_1) _inst_2 a b)) (HSub.hSub.{0, 0, 0} Nat Nat Nat (instHSub.{0} Nat Nat.hasSub) (coeFn.{succ u1, succ u1} (AddMonoidHom.{u1, 0} (Multiset.{u1} α) Nat (AddMonoid.toAddZeroClass.{u1} (Multiset.{u1} α) (AddRightCancelMonoid.toAddMonoid.{u1} (Multiset.{u1} α) (AddCancelMonoid.toAddRightCancelMonoid.{u1} (Multiset.{u1} α) (AddCancelCommMonoid.toAddCancelMonoid.{u1} (Multiset.{u1} α) (OrderedCancelAddCommMonoid.toCancelAddCommMonoid.{u1} (Multiset.{u1} α) (Multiset.orderedCancelAddCommMonoid.{u1} α)))))) (AddMonoid.toAddZeroClass.{0} Nat Nat.addMonoid)) (fun (_x : AddMonoidHom.{u1, 0} (Multiset.{u1} α) Nat (AddMonoid.toAddZeroClass.{u1} (Multiset.{u1} α) (AddRightCancelMonoid.toAddMonoid.{u1} (Multiset.{u1} α) (AddCancelMonoid.toAddRightCancelMonoid.{u1} (Multiset.{u1} α) (AddCancelCommMonoid.toAddCancelMonoid.{u1} (Multiset.{u1} α) (OrderedCancelAddCommMonoid.toCancelAddCommMonoid.{u1} (Multiset.{u1} α) (Multiset.orderedCancelAddCommMonoid.{u1} α)))))) (AddMonoid.toAddZeroClass.{0} Nat Nat.addMonoid)) => (Multiset.{u1} α) -> Nat) (AddMonoidHom.hasCoeToFun.{u1, 0} (Multiset.{u1} α) Nat (AddMonoid.toAddZeroClass.{u1} (Multiset.{u1} α) (AddRightCancelMonoid.toAddMonoid.{u1} (Multiset.{u1} α) (AddCancelMonoid.toAddRightCancelMonoid.{u1} (Multiset.{u1} α) (AddCancelCommMonoid.toAddCancelMonoid.{u1} (Multiset.{u1} α) (OrderedCancelAddCommMonoid.toCancelAddCommMonoid.{u1} (Multiset.{u1} α) (Multiset.orderedCancelAddCommMonoid.{u1} α)))))) (AddMonoid.toAddZeroClass.{0} Nat Nat.addMonoid)) (Multiset.card.{u1} α) (Multiset.Icc.{u1} α (PartialOrder.toPreorder.{u1} α _inst_1) _inst_2 a b)) (OfNat.ofNat.{0} Nat 2 (OfNat.mk.{0} Nat 2 (bit0.{0} Nat Nat.hasAdd (One.one.{0} Nat Nat.hasOne))))) but is expected to have type forall {α : Type.{u1}} [_inst_1 : PartialOrder.{u1} α] [_inst_2 : LocallyFiniteOrder.{u1} α (PartialOrder.toPreorder.{u1} α _inst_1)] (a : α) (b : α), Eq.{1} ((fun ([email protected]._hyg.403 : Multiset.{u1} α) => Nat) (Multiset.Ioo.{u1} α (PartialOrder.toPreorder.{u1} α _inst_1) _inst_2 a b)) (FunLike.coe.{succ u1, succ u1, 1} (AddMonoidHom.{u1, 0} (Multiset.{u1} α) Nat (AddMonoid.toAddZeroClass.{u1} (Multiset.{u1} α) (AddRightCancelMonoid.toAddMonoid.{u1} (Multiset.{u1} α) (AddCancelMonoid.toAddRightCancelMonoid.{u1} (Multiset.{u1} α) (AddCancelCommMonoid.toAddCancelMonoid.{u1} (Multiset.{u1} α) (OrderedCancelAddCommMonoid.toCancelAddCommMonoid.{u1} (Multiset.{u1} α) (Multiset.instOrderedCancelAddCommMonoidMultiset.{u1} α)))))) (AddMonoid.toAddZeroClass.{0} Nat Nat.addMonoid)) (Multiset.{u1} α) (fun (_x : Multiset.{u1} α) => (fun ([email protected]._hyg.403 : Multiset.{u1} α) => Nat) _x) (AddHomClass.toFunLike.{u1, u1, 0} (AddMonoidHom.{u1, 0} (Multiset.{u1} α) Nat (AddMonoid.toAddZeroClass.{u1} (Multiset.{u1} α) (AddRightCancelMonoid.toAddMonoid.{u1} (Multiset.{u1} α) (AddCancelMonoid.toAddRightCancelMonoid.{u1} (Multiset.{u1} α) (AddCancelCommMonoid.toAddCancelMonoid.{u1} (Multiset.{u1} α) (OrderedCancelAddCommMonoid.toCancelAddCommMonoid.{u1} (Multiset.{u1} α) (Multiset.instOrderedCancelAddCommMonoidMultiset.{u1} α)))))) (AddMonoid.toAddZeroClass.{0} Nat Nat.addMonoid)) (Multiset.{u1} α) Nat (AddZeroClass.toAdd.{u1} (Multiset.{u1} α) (AddMonoid.toAddZeroClass.{u1} (Multiset.{u1} α) (AddRightCancelMonoid.toAddMonoid.{u1} (Multiset.{u1} α) (AddCancelMonoid.toAddRightCancelMonoid.{u1} (Multiset.{u1} α) (AddCancelCommMonoid.toAddCancelMonoid.{u1} (Multiset.{u1} α) (OrderedCancelAddCommMonoid.toCancelAddCommMonoid.{u1} (Multiset.{u1} α) (Multiset.instOrderedCancelAddCommMonoidMultiset.{u1} α))))))) (AddZeroClass.toAdd.{0} Nat (AddMonoid.toAddZeroClass.{0} Nat Nat.addMonoid)) (AddMonoidHomClass.toAddHomClass.{u1, u1, 0} (AddMonoidHom.{u1, 0} (Multiset.{u1} α) Nat (AddMonoid.toAddZeroClass.{u1} (Multiset.{u1} α) (AddRightCancelMonoid.toAddMonoid.{u1} (Multiset.{u1} α) (AddCancelMonoid.toAddRightCancelMonoid.{u1} (Multiset.{u1} α) (AddCancelCommMonoid.toAddCancelMonoid.{u1} (Multiset.{u1} α) (OrderedCancelAddCommMonoid.toCancelAddCommMonoid.{u1} (Multiset.{u1} α) (Multiset.instOrderedCancelAddCommMonoidMultiset.{u1} α)))))) (AddMonoid.toAddZeroClass.{0} Nat Nat.addMonoid)) (Multiset.{u1} α) Nat (AddMonoid.toAddZeroClass.{u1} (Multiset.{u1} α) (AddRightCancelMonoid.toAddMonoid.{u1} (Multiset.{u1} α) (AddCancelMonoid.toAddRightCancelMonoid.{u1} (Multiset.{u1} α) (AddCancelCommMonoid.toAddCancelMonoid.{u1} (Multiset.{u1} α) (OrderedCancelAddCommMonoid.toCancelAddCommMonoid.{u1} (Multiset.{u1} α) (Multiset.instOrderedCancelAddCommMonoidMultiset.{u1} α)))))) (AddMonoid.toAddZeroClass.{0} Nat Nat.addMonoid) (AddMonoidHom.addMonoidHomClass.{u1, 0} (Multiset.{u1} α) Nat (AddMonoid.toAddZeroClass.{u1} (Multiset.{u1} α) (AddRightCancelMonoid.toAddMonoid.{u1} (Multiset.{u1} α) (AddCancelMonoid.toAddRightCancelMonoid.{u1} (Multiset.{u1} α) (AddCancelCommMonoid.toAddCancelMonoid.{u1} (Multiset.{u1} α) (OrderedCancelAddCommMonoid.toCancelAddCommMonoid.{u1} (Multiset.{u1} α) (Multiset.instOrderedCancelAddCommMonoidMultiset.{u1} α)))))) (AddMonoid.toAddZeroClass.{0} Nat Nat.addMonoid)))) (Multiset.card.{u1} α) (Multiset.Ioo.{u1} α (PartialOrder.toPreorder.{u1} α _inst_1) _inst_2 a b)) (HSub.hSub.{0, 0, 0} ((fun ([email protected]._hyg.403 : Multiset.{u1} α) => Nat) (Multiset.Icc.{u1} α (PartialOrder.toPreorder.{u1} α _inst_1) _inst_2 a b)) ((fun ([email protected]._hyg.403 : Multiset.{u1} α) => Nat) (Multiset.Ioo.{u1} α (PartialOrder.toPreorder.{u1} α _inst_1) _inst_2 a b)) ((fun ([email protected]._hyg.403 : Multiset.{u1} α) => Nat) (Multiset.Icc.{u1} α (PartialOrder.toPreorder.{u1} α _inst_1) _inst_2 a b)) (instHSub.{0} ((fun ([email protected]._hyg.403 : Multiset.{u1} α) => Nat) (Multiset.Icc.{u1} α (PartialOrder.toPreorder.{u1} α _inst_1) _inst_2 a b)) instSubNat) (FunLike.coe.{succ u1, succ u1, 1} (AddMonoidHom.{u1, 0} (Multiset.{u1} α) Nat (AddMonoid.toAddZeroClass.{u1} (Multiset.{u1} α) (AddRightCancelMonoid.toAddMonoid.{u1} (Multiset.{u1} α) (AddCancelMonoid.toAddRightCancelMonoid.{u1} (Multiset.{u1} α) (AddCancelCommMonoid.toAddCancelMonoid.{u1} (Multiset.{u1} α) (OrderedCancelAddCommMonoid.toCancelAddCommMonoid.{u1} (Multiset.{u1} α) (Multiset.instOrderedCancelAddCommMonoidMultiset.{u1} α)))))) (AddMonoid.toAddZeroClass.{0} Nat Nat.addMonoid)) (Multiset.{u1} α) (fun (_x : Multiset.{u1} α) => (fun ([email protected]._hyg.403 : Multiset.{u1} α) => Nat) _x) (AddHomClass.toFunLike.{u1, u1, 0} (AddMonoidHom.{u1, 0} (Multiset.{u1} α) Nat (AddMonoid.toAddZeroClass.{u1} (Multiset.{u1} α) (AddRightCancelMonoid.toAddMonoid.{u1} (Multiset.{u1} α) (AddCancelMonoid.toAddRightCancelMonoid.{u1} (Multiset.{u1} α) (AddCancelCommMonoid.toAddCancelMonoid.{u1} (Multiset.{u1} α) (OrderedCancelAddCommMonoid.toCancelAddCommMonoid.{u1} (Multiset.{u1} α) (Multiset.instOrderedCancelAddCommMonoidMultiset.{u1} α)))))) (AddMonoid.toAddZeroClass.{0} Nat Nat.addMonoid)) (Multiset.{u1} α) Nat (AddZeroClass.toAdd.{u1} (Multiset.{u1} α) (AddMonoid.toAddZeroClass.{u1} (Multiset.{u1} α) (AddRightCancelMonoid.toAddMonoid.{u1} (Multiset.{u1} α) (AddCancelMonoid.toAddRightCancelMonoid.{u1} (Multiset.{u1} α) (AddCancelCommMonoid.toAddCancelMonoid.{u1} (Multiset.{u1} α) (OrderedCancelAddCommMonoid.toCancelAddCommMonoid.{u1} (Multiset.{u1} α) (Multiset.instOrderedCancelAddCommMonoidMultiset.{u1} α))))))) (AddZeroClass.toAdd.{0} Nat (AddMonoid.toAddZeroClass.{0} Nat Nat.addMonoid)) (AddMonoidHomClass.toAddHomClass.{u1, u1, 0} (AddMonoidHom.{u1, 0} (Multiset.{u1} α) Nat (AddMonoid.toAddZeroClass.{u1} (Multiset.{u1} α) (AddRightCancelMonoid.toAddMonoid.{u1} (Multiset.{u1} α) (AddCancelMonoid.toAddRightCancelMonoid.{u1} (Multiset.{u1} α) (AddCancelCommMonoid.toAddCancelMonoid.{u1} (Multiset.{u1} α) (OrderedCancelAddCommMonoid.toCancelAddCommMonoid.{u1} (Multiset.{u1} α) (Multiset.instOrderedCancelAddCommMonoidMultiset.{u1} α)))))) (AddMonoid.toAddZeroClass.{0} Nat Nat.addMonoid)) (Multiset.{u1} α) Nat (AddMonoid.toAddZeroClass.{u1} (Multiset.{u1} α) (AddRightCancelMonoid.toAddMonoid.{u1} (Multiset.{u1} α) (AddCancelMonoid.toAddRightCancelMonoid.{u1} (Multiset.{u1} α) (AddCancelCommMonoid.toAddCancelMonoid.{u1} (Multiset.{u1} α) (OrderedCancelAddCommMonoid.toCancelAddCommMonoid.{u1} (Multiset.{u1} α) (Multiset.instOrderedCancelAddCommMonoidMultiset.{u1} α)))))) (AddMonoid.toAddZeroClass.{0} Nat Nat.addMonoid) (AddMonoidHom.addMonoidHomClass.{u1, 0} (Multiset.{u1} α) Nat (AddMonoid.toAddZeroClass.{u1} (Multiset.{u1} α) (AddRightCancelMonoid.toAddMonoid.{u1} (Multiset.{u1} α) (AddCancelMonoid.toAddRightCancelMonoid.{u1} (Multiset.{u1} α) (AddCancelCommMonoid.toAddCancelMonoid.{u1} (Multiset.{u1} α) (OrderedCancelAddCommMonoid.toCancelAddCommMonoid.{u1} (Multiset.{u1} α) (Multiset.instOrderedCancelAddCommMonoidMultiset.{u1} α)))))) (AddMonoid.toAddZeroClass.{0} Nat Nat.addMonoid)))) (Multiset.card.{u1} α) (Multiset.Icc.{u1} α (PartialOrder.toPreorder.{u1} α _inst_1) _inst_2 a b)) (OfNat.ofNat.{0} ((fun ([email protected]._hyg.403 : Multiset.{u1} α) => Nat) (Multiset.Ioo.{u1} α (PartialOrder.toPreorder.{u1} α _inst_1) _inst_2 a b)) 2 (instOfNatNat 2))) Case conversion may be inaccurate. Consider using '#align multiset.card_Ioo_eq_card_Icc_sub_two Multiset.card_Ioo_eq_card_Icc_sub_twoₓ'. -/ theorem card_Ioo_eq_card_Icc_sub_two (a b : α) : (Ioo a b).card = (Icc a b).card - 2 := Finset.card_Ioo_eq_card_Icc_sub_two _ _ #align multiset.card_Ioo_eq_card_Icc_sub_two Multiset.card_Ioo_eq_card_Icc_sub_two end PartialOrder section LinearOrder variable [LinearOrder α] [LocallyFiniteOrder α] {a b c d : α} #print Multiset.Ico_subset_Ico_iff /- theorem Ico_subset_Ico_iff {a₁ b₁ a₂ b₂ : α} (h : a₁ < b₁) : Ico a₁ b₁ ⊆ Ico a₂ b₂ ↔ a₂ ≤ a₁ ∧ b₁ ≤ b₂ := Finset.Ico_subset_Ico_iff h #align multiset.Ico_subset_Ico_iff Multiset.Ico_subset_Ico_iff -/ #print Multiset.Ico_add_Ico_eq_Ico /- theorem Ico_add_Ico_eq_Ico {a b c : α} (hab : a ≤ b) (hbc : b ≤ c) : Ico a b + Ico b c = Ico a c := by rw [add_eq_union_iff_disjoint.2 (Ico_disjoint_Ico le_rfl), Ico, Ico, Ico, ← Finset.union_val, Finset.Ico_union_Ico_eq_Ico hab hbc] #align multiset.Ico_add_Ico_eq_Ico Multiset.Ico_add_Ico_eq_Ico -/ /- warning: multiset.Ico_inter_Ico -> Multiset.Ico_inter_Ico is a dubious translation: lean 3 declaration is forall {α : Type.{u1}} [_inst_1 : LinearOrder.{u1} α] [_inst_2 : LocallyFiniteOrder.{u1} α (PartialOrder.toPreorder.{u1} α (SemilatticeInf.toPartialOrder.{u1} α (Lattice.toSemilatticeInf.{u1} α (LinearOrder.toLattice.{u1} α _inst_1))))] {a : α} {b : α} {c : α} {d : α}, Eq.{succ u1} (Multiset.{u1} α) (Inter.inter.{u1} (Multiset.{u1} α) (Multiset.hasInter.{u1} α (fun (a : α) (b : α) => Eq.decidable.{u1} α _inst_1 a b)) (Multiset.Ico.{u1} α (PartialOrder.toPreorder.{u1} α (SemilatticeInf.toPartialOrder.{u1} α (Lattice.toSemilatticeInf.{u1} α (LinearOrder.toLattice.{u1} α _inst_1)))) _inst_2 a b) (Multiset.Ico.{u1} α (PartialOrder.toPreorder.{u1} α (SemilatticeInf.toPartialOrder.{u1} α (Lattice.toSemilatticeInf.{u1} α (LinearOrder.toLattice.{u1} α _inst_1)))) _inst_2 c d)) (Multiset.Ico.{u1} α (PartialOrder.toPreorder.{u1} α (SemilatticeInf.toPartialOrder.{u1} α (Lattice.toSemilatticeInf.{u1} α (LinearOrder.toLattice.{u1} α _inst_1)))) _inst_2 (LinearOrder.max.{u1} α _inst_1 a c) (LinearOrder.min.{u1} α _inst_1 b d)) but is expected to have type forall {α : Type.{u1}} [_inst_1 : LinearOrder.{u1} α] [_inst_2 : LocallyFiniteOrder.{u1} α (PartialOrder.toPreorder.{u1} α (SemilatticeInf.toPartialOrder.{u1} α (Lattice.toSemilatticeInf.{u1} α (DistribLattice.toLattice.{u1} α (instDistribLattice.{u1} α _inst_1)))))] {a : α} {b : α} {c : α} {d : α}, Eq.{succ u1} (Multiset.{u1} α) (Inter.inter.{u1} (Multiset.{u1} α) (Multiset.instInterMultiset.{u1} α (fun (a : α) (b : α) => instDecidableEq.{u1} α _inst_1 a b)) (Multiset.Ico.{u1} α (PartialOrder.toPreorder.{u1} α (SemilatticeInf.toPartialOrder.{u1} α (Lattice.toSemilatticeInf.{u1} α (DistribLattice.toLattice.{u1} α (instDistribLattice.{u1} α _inst_1))))) _inst_2 a b) (Multiset.Ico.{u1} α (PartialOrder.toPreorder.{u1} α (SemilatticeInf.toPartialOrder.{u1} α (Lattice.toSemilatticeInf.{u1} α (DistribLattice.toLattice.{u1} α (instDistribLattice.{u1} α _inst_1))))) _inst_2 c d)) (Multiset.Ico.{u1} α (PartialOrder.toPreorder.{u1} α (SemilatticeInf.toPartialOrder.{u1} α (Lattice.toSemilatticeInf.{u1} α (DistribLattice.toLattice.{u1} α (instDistribLattice.{u1} α _inst_1))))) _inst_2 (Max.max.{u1} α (LinearOrder.toMax.{u1} α _inst_1) a c) (Min.min.{u1} α (LinearOrder.toMin.{u1} α _inst_1) b d)) Case conversion may be inaccurate. Consider using '#align multiset.Ico_inter_Ico Multiset.Ico_inter_Icoₓ'. -/ theorem Ico_inter_Ico : Ico a b ∩ Ico c d = Ico (max a c) (min b d) := by rw [Ico, Ico, Ico, ← Finset.inter_val, Finset.Ico_inter_Ico] #align multiset.Ico_inter_Ico Multiset.Ico_inter_Ico #print Multiset.Ico_filter_lt /- @[simp] theorem Ico_filter_lt (a b c : α) : ((Ico a b).filterₓ fun x => x < c) = Ico a (min b c) := by rw [Ico, Ico, ← Finset.filter_val, Finset.Ico_filter_lt] #align multiset.Ico_filter_lt Multiset.Ico_filter_lt -/ #print Multiset.Ico_filter_le /- @[simp] theorem Ico_filter_le (a b c : α) : ((Ico a b).filterₓ fun x => c ≤ x) = Ico (max a c) b := by rw [Ico, Ico, ← Finset.filter_val, Finset.Ico_filter_le] #align multiset.Ico_filter_le Multiset.Ico_filter_le -/ /- warning: multiset.Ico_sub_Ico_left -> Multiset.Ico_sub_Ico_left is a dubious translation: lean 3 declaration is forall {α : Type.{u1}} [_inst_1 : LinearOrder.{u1} α] [_inst_2 : LocallyFiniteOrder.{u1} α (PartialOrder.toPreorder.{u1} α (SemilatticeInf.toPartialOrder.{u1} α (Lattice.toSemilatticeInf.{u1} α (LinearOrder.toLattice.{u1} α _inst_1))))] (a : α) (b : α) (c : α), Eq.{succ u1} (Multiset.{u1} α) (HSub.hSub.{u1, u1, u1} (Multiset.{u1} α) (Multiset.{u1} α) (Multiset.{u1} α) (instHSub.{u1} (Multiset.{u1} α) (Multiset.hasSub.{u1} α (fun (a : α) (b : α) => Eq.decidable.{u1} α _inst_1 a b))) (Multiset.Ico.{u1} α (PartialOrder.toPreorder.{u1} α (SemilatticeInf.toPartialOrder.{u1} α (Lattice.toSemilatticeInf.{u1} α (LinearOrder.toLattice.{u1} α _inst_1)))) _inst_2 a b) (Multiset.Ico.{u1} α (PartialOrder.toPreorder.{u1} α (SemilatticeInf.toPartialOrder.{u1} α (Lattice.toSemilatticeInf.{u1} α (LinearOrder.toLattice.{u1} α _inst_1)))) _inst_2 a c)) (Multiset.Ico.{u1} α (PartialOrder.toPreorder.{u1} α (SemilatticeInf.toPartialOrder.{u1} α (Lattice.toSemilatticeInf.{u1} α (LinearOrder.toLattice.{u1} α _inst_1)))) _inst_2 (LinearOrder.max.{u1} α _inst_1 a c) b) but is expected to have type forall {α : Type.{u1}} [_inst_1 : LinearOrder.{u1} α] [_inst_2 : LocallyFiniteOrder.{u1} α (PartialOrder.toPreorder.{u1} α (SemilatticeInf.toPartialOrder.{u1} α (Lattice.toSemilatticeInf.{u1} α (DistribLattice.toLattice.{u1} α (instDistribLattice.{u1} α _inst_1)))))] (a : α) (b : α) (c : α), Eq.{succ u1} (Multiset.{u1} α) (HSub.hSub.{u1, u1, u1} (Multiset.{u1} α) (Multiset.{u1} α) (Multiset.{u1} α) (instHSub.{u1} (Multiset.{u1} α) (Multiset.instSubMultiset.{u1} α (fun (a : α) (b : α) => instDecidableEq.{u1} α _inst_1 a b))) (Multiset.Ico.{u1} α (PartialOrder.toPreorder.{u1} α (SemilatticeInf.toPartialOrder.{u1} α (Lattice.toSemilatticeInf.{u1} α (DistribLattice.toLattice.{u1} α (instDistribLattice.{u1} α _inst_1))))) _inst_2 a b) (Multiset.Ico.{u1} α (PartialOrder.toPreorder.{u1} α (SemilatticeInf.toPartialOrder.{u1} α (Lattice.toSemilatticeInf.{u1} α (DistribLattice.toLattice.{u1} α (instDistribLattice.{u1} α _inst_1))))) _inst_2 a c)) (Multiset.Ico.{u1} α (PartialOrder.toPreorder.{u1} α (SemilatticeInf.toPartialOrder.{u1} α (Lattice.toSemilatticeInf.{u1} α (DistribLattice.toLattice.{u1} α (instDistribLattice.{u1} α _inst_1))))) _inst_2 (Max.max.{u1} α (LinearOrder.toMax.{u1} α _inst_1) a c) b) Case conversion may be inaccurate. Consider using '#align multiset.Ico_sub_Ico_left Multiset.Ico_sub_Ico_leftₓ'. -/ @[simp] theorem Ico_sub_Ico_left (a b c : α) : Ico a b - Ico a c = Ico (max a c) b := by rw [Ico, Ico, Ico, ← Finset.sdiff_val, Finset.Ico_diff_Ico_left] #align multiset.Ico_sub_Ico_left Multiset.Ico_sub_Ico_left /- warning: multiset.Ico_sub_Ico_right -> Multiset.Ico_sub_Ico_right is a dubious translation: lean 3 declaration is forall {α : Type.{u1}} [_inst_1 : LinearOrder.{u1} α] [_inst_2 : LocallyFiniteOrder.{u1} α (PartialOrder.toPreorder.{u1} α (SemilatticeInf.toPartialOrder.{u1} α (Lattice.toSemilatticeInf.{u1} α (LinearOrder.toLattice.{u1} α _inst_1))))] (a : α) (b : α) (c : α), Eq.{succ u1} (Multiset.{u1} α) (HSub.hSub.{u1, u1, u1} (Multiset.{u1} α) (Multiset.{u1} α) (Multiset.{u1} α) (instHSub.{u1} (Multiset.{u1} α) (Multiset.hasSub.{u1} α (fun (a : α) (b : α) => Eq.decidable.{u1} α _inst_1 a b))) (Multiset.Ico.{u1} α (PartialOrder.toPreorder.{u1} α (SemilatticeInf.toPartialOrder.{u1} α (Lattice.toSemilatticeInf.{u1} α (LinearOrder.toLattice.{u1} α _inst_1)))) _inst_2 a b) (Multiset.Ico.{u1} α (PartialOrder.toPreorder.{u1} α (SemilatticeInf.toPartialOrder.{u1} α (Lattice.toSemilatticeInf.{u1} α (LinearOrder.toLattice.{u1} α _inst_1)))) _inst_2 c b)) (Multiset.Ico.{u1} α (PartialOrder.toPreorder.{u1} α (SemilatticeInf.toPartialOrder.{u1} α (Lattice.toSemilatticeInf.{u1} α (LinearOrder.toLattice.{u1} α _inst_1)))) _inst_2 a (LinearOrder.min.{u1} α _inst_1 b c)) but is expected to have type forall {α : Type.{u1}} [_inst_1 : LinearOrder.{u1} α] [_inst_2 : LocallyFiniteOrder.{u1} α (PartialOrder.toPreorder.{u1} α (SemilatticeInf.toPartialOrder.{u1} α (Lattice.toSemilatticeInf.{u1} α (DistribLattice.toLattice.{u1} α (instDistribLattice.{u1} α _inst_1)))))] (a : α) (b : α) (c : α), Eq.{succ u1} (Multiset.{u1} α) (HSub.hSub.{u1, u1, u1} (Multiset.{u1} α) (Multiset.{u1} α) (Multiset.{u1} α) (instHSub.{u1} (Multiset.{u1} α) (Multiset.instSubMultiset.{u1} α (fun (a : α) (b : α) => instDecidableEq.{u1} α _inst_1 a b))) (Multiset.Ico.{u1} α (PartialOrder.toPreorder.{u1} α (SemilatticeInf.toPartialOrder.{u1} α (Lattice.toSemilatticeInf.{u1} α (DistribLattice.toLattice.{u1} α (instDistribLattice.{u1} α _inst_1))))) _inst_2 a b) (Multiset.Ico.{u1} α (PartialOrder.toPreorder.{u1} α (SemilatticeInf.toPartialOrder.{u1} α (Lattice.toSemilatticeInf.{u1} α (DistribLattice.toLattice.{u1} α (instDistribLattice.{u1} α _inst_1))))) _inst_2 c b)) (Multiset.Ico.{u1} α (PartialOrder.toPreorder.{u1} α (SemilatticeInf.toPartialOrder.{u1} α (Lattice.toSemilatticeInf.{u1} α (DistribLattice.toLattice.{u1} α (instDistribLattice.{u1} α _inst_1))))) _inst_2 a (Min.min.{u1} α (LinearOrder.toMin.{u1} α _inst_1) b c)) Case conversion may be inaccurate. Consider using '#align multiset.Ico_sub_Ico_right Multiset.Ico_sub_Ico_rightₓ'. -/ @[simp] theorem Ico_sub_Ico_right (a b c : α) : Ico a b - Ico c b = Ico a (min b c) := by rw [Ico, Ico, Ico, ← Finset.sdiff_val, Finset.Ico_diff_Ico_right] #align multiset.Ico_sub_Ico_right Multiset.Ico_sub_Ico_right end LinearOrder section OrderedCancelAddCommMonoid variable [OrderedCancelAddCommMonoid α] [ExistsAddOfLE α] [LocallyFiniteOrder α] /- warning: multiset.map_add_left_Icc -> Multiset.map_add_left_Icc is a dubious translation: lean 3 declaration is forall {α : Type.{u1}} [_inst_1 : OrderedCancelAddCommMonoid.{u1} α] [_inst_2 : ExistsAddOfLE.{u1} α (AddZeroClass.toHasAdd.{u1} α (AddMonoid.toAddZeroClass.{u1} α (AddRightCancelMonoid.toAddMonoid.{u1} α (AddCancelMonoid.toAddRightCancelMonoid.{u1} α (AddCancelCommMonoid.toAddCancelMonoid.{u1} α (OrderedCancelAddCommMonoid.toCancelAddCommMonoid.{u1} α _inst_1)))))) (Preorder.toLE.{u1} α (PartialOrder.toPreorder.{u1} α (OrderedCancelAddCommMonoid.toPartialOrder.{u1} α _inst_1)))] [_inst_3 : LocallyFiniteOrder.{u1} α (PartialOrder.toPreorder.{u1} α (OrderedCancelAddCommMonoid.toPartialOrder.{u1} α _inst_1))] (a : α) (b : α) (c : α), Eq.{succ u1} (Multiset.{u1} α) (Multiset.map.{u1, u1} α α (HAdd.hAdd.{u1, u1, u1} α α α (instHAdd.{u1} α (AddZeroClass.toHasAdd.{u1} α (AddMonoid.toAddZeroClass.{u1} α (AddRightCancelMonoid.toAddMonoid.{u1} α (AddCancelMonoid.toAddRightCancelMonoid.{u1} α (AddCancelCommMonoid.toAddCancelMonoid.{u1} α (OrderedCancelAddCommMonoid.toCancelAddCommMonoid.{u1} α _inst_1))))))) c) (Multiset.Icc.{u1} α (PartialOrder.toPreorder.{u1} α (OrderedCancelAddCommMonoid.toPartialOrder.{u1} α _inst_1)) _inst_3 a b)) (Multiset.Icc.{u1} α (PartialOrder.toPreorder.{u1} α (OrderedCancelAddCommMonoid.toPartialOrder.{u1} α _inst_1)) _inst_3 (HAdd.hAdd.{u1, u1, u1} α α α (instHAdd.{u1} α (AddZeroClass.toHasAdd.{u1} α (AddMonoid.toAddZeroClass.{u1} α (AddRightCancelMonoid.toAddMonoid.{u1} α (AddCancelMonoid.toAddRightCancelMonoid.{u1} α (AddCancelCommMonoid.toAddCancelMonoid.{u1} α (OrderedCancelAddCommMonoid.toCancelAddCommMonoid.{u1} α _inst_1))))))) c a) (HAdd.hAdd.{u1, u1, u1} α α α (instHAdd.{u1} α (AddZeroClass.toHasAdd.{u1} α (AddMonoid.toAddZeroClass.{u1} α (AddRightCancelMonoid.toAddMonoid.{u1} α (AddCancelMonoid.toAddRightCancelMonoid.{u1} α (AddCancelCommMonoid.toAddCancelMonoid.{u1} α (OrderedCancelAddCommMonoid.toCancelAddCommMonoid.{u1} α _inst_1))))))) c b)) but is expected to have type forall {α : Type.{u1}} [_inst_1 : OrderedCancelAddCommMonoid.{u1} α] [_inst_2 : ExistsAddOfLE.{u1} α (AddZeroClass.toAdd.{u1} α (AddMonoid.toAddZeroClass.{u1} α (AddRightCancelMonoid.toAddMonoid.{u1} α (AddCancelMonoid.toAddRightCancelMonoid.{u1} α (AddCancelCommMonoid.toAddCancelMonoid.{u1} α (OrderedCancelAddCommMonoid.toCancelAddCommMonoid.{u1} α _inst_1)))))) (Preorder.toLE.{u1} α (PartialOrder.toPreorder.{u1} α (OrderedCancelAddCommMonoid.toPartialOrder.{u1} α _inst_1)))] [_inst_3 : LocallyFiniteOrder.{u1} α (PartialOrder.toPreorder.{u1} α (OrderedCancelAddCommMonoid.toPartialOrder.{u1} α _inst_1))] (a : α) (b : α) (c : α), Eq.{succ u1} (Multiset.{u1} α) (Multiset.map.{u1, u1} α α ((fun ([email protected]._hyg.2608 : α) ([email protected]._hyg.2610 : α) => HAdd.hAdd.{u1, u1, u1} α α α (instHAdd.{u1} α (AddZeroClass.toAdd.{u1} α (AddMonoid.toAddZeroClass.{u1} α (AddRightCancelMonoid.toAddMonoid.{u1} α (AddCancelMonoid.toAddRightCancelMonoid.{u1} α (AddCancelCommMonoid.toAddCancelMonoid.{u1} α (OrderedCancelAddCommMonoid.toCancelAddCommMonoid.{u1} α _inst_1))))))) [email protected]._hyg.2608 [email protected]._hyg.2610) c) (Multiset.Icc.{u1} α (PartialOrder.toPreorder.{u1} α (OrderedCancelAddCommMonoid.toPartialOrder.{u1} α _inst_1)) _inst_3 a b)) (Multiset.Icc.{u1} α (PartialOrder.toPreorder.{u1} α (OrderedCancelAddCommMonoid.toPartialOrder.{u1} α _inst_1)) _inst_3 (HAdd.hAdd.{u1, u1, u1} α α α (instHAdd.{u1} α (AddZeroClass.toAdd.{u1} α (AddMonoid.toAddZeroClass.{u1} α (AddRightCancelMonoid.toAddMonoid.{u1} α (AddCancelMonoid.toAddRightCancelMonoid.{u1} α (AddCancelCommMonoid.toAddCancelMonoid.{u1} α (OrderedCancelAddCommMonoid.toCancelAddCommMonoid.{u1} α _inst_1))))))) c a) (HAdd.hAdd.{u1, u1, u1} α α α (instHAdd.{u1} α (AddZeroClass.toAdd.{u1} α (AddMonoid.toAddZeroClass.{u1} α (AddRightCancelMonoid.toAddMonoid.{u1} α (AddCancelMonoid.toAddRightCancelMonoid.{u1} α (AddCancelCommMonoid.toAddCancelMonoid.{u1} α (OrderedCancelAddCommMonoid.toCancelAddCommMonoid.{u1} α _inst_1))))))) c b)) Case conversion may be inaccurate. Consider using '#align multiset.map_add_left_Icc Multiset.map_add_left_Iccₓ'. -/ theorem map_add_left_Icc (a b c : α) : (Icc a b).map ((· + ·) c) = Icc (c + a) (c + b) := by classical rw [Icc, Icc, ← Finset.image_add_left_Icc, Finset.image_val, ((Finset.nodup _).map <| add_right_injective c).dedup] #align multiset.map_add_left_Icc Multiset.map_add_left_Icc /- warning: multiset.map_add_left_Ico -> Multiset.map_add_left_Ico is a dubious translation: lean 3 declaration is forall {α : Type.{u1}} [_inst_1 : OrderedCancelAddCommMonoid.{u1} α] [_inst_2 : ExistsAddOfLE.{u1} α (AddZeroClass.toHasAdd.{u1} α (AddMonoid.toAddZeroClass.{u1} α (AddRightCancelMonoid.toAddMonoid.{u1} α (AddCancelMonoid.toAddRightCancelMonoid.{u1} α (AddCancelCommMonoid.toAddCancelMonoid.{u1} α (OrderedCancelAddCommMonoid.toCancelAddCommMonoid.{u1} α _inst_1)))))) (Preorder.toLE.{u1} α (PartialOrder.toPreorder.{u1} α (OrderedCancelAddCommMonoid.toPartialOrder.{u1} α _inst_1)))] [_inst_3 : LocallyFiniteOrder.{u1} α (PartialOrder.toPreorder.{u1} α (OrderedCancelAddCommMonoid.toPartialOrder.{u1} α _inst_1))] (a : α) (b : α) (c : α), Eq.{succ u1} (Multiset.{u1} α) (Multiset.map.{u1, u1} α α (HAdd.hAdd.{u1, u1, u1} α α α (instHAdd.{u1} α (AddZeroClass.toHasAdd.{u1} α (AddMonoid.toAddZeroClass.{u1} α (AddRightCancelMonoid.toAddMonoid.{u1} α (AddCancelMonoid.toAddRightCancelMonoid.{u1} α (AddCancelCommMonoid.toAddCancelMonoid.{u1} α (OrderedCancelAddCommMonoid.toCancelAddCommMonoid.{u1} α _inst_1))))))) c) (Multiset.Ico.{u1} α (PartialOrder.toPreorder.{u1} α (OrderedCancelAddCommMonoid.toPartialOrder.{u1} α _inst_1)) _inst_3 a b)) (Multiset.Ico.{u1} α (PartialOrder.toPreorder.{u1} α (OrderedCancelAddCommMonoid.toPartialOrder.{u1} α _inst_1)) _inst_3 (HAdd.hAdd.{u1, u1, u1} α α α (instHAdd.{u1} α (AddZeroClass.toHasAdd.{u1} α (AddMonoid.toAddZeroClass.{u1} α (AddRightCancelMonoid.toAddMonoid.{u1} α (AddCancelMonoid.toAddRightCancelMonoid.{u1} α (AddCancelCommMonoid.toAddCancelMonoid.{u1} α (OrderedCancelAddCommMonoid.toCancelAddCommMonoid.{u1} α _inst_1))))))) c a) (HAdd.hAdd.{u1, u1, u1} α α α (instHAdd.{u1} α (AddZeroClass.toHasAdd.{u1} α (AddMonoid.toAddZeroClass.{u1} α (AddRightCancelMonoid.toAddMonoid.{u1} α (AddCancelMonoid.toAddRightCancelMonoid.{u1} α (AddCancelCommMonoid.toAddCancelMonoid.{u1} α (OrderedCancelAddCommMonoid.toCancelAddCommMonoid.{u1} α _inst_1))))))) c b)) but is expected to have type forall {α : Type.{u1}} [_inst_1 : OrderedCancelAddCommMonoid.{u1} α] [_inst_2 : ExistsAddOfLE.{u1} α (AddZeroClass.toAdd.{u1} α (AddMonoid.toAddZeroClass.{u1} α (AddRightCancelMonoid.toAddMonoid.{u1} α (AddCancelMonoid.toAddRightCancelMonoid.{u1} α (AddCancelCommMonoid.toAddCancelMonoid.{u1} α (OrderedCancelAddCommMonoid.toCancelAddCommMonoid.{u1} α _inst_1)))))) (Preorder.toLE.{u1} α (PartialOrder.toPreorder.{u1} α (OrderedCancelAddCommMonoid.toPartialOrder.{u1} α _inst_1)))] [_inst_3 : LocallyFiniteOrder.{u1} α (PartialOrder.toPreorder.{u1} α (OrderedCancelAddCommMonoid.toPartialOrder.{u1} α _inst_1))] (a : α) (b : α) (c : α), Eq.{succ u1} (Multiset.{u1} α) (Multiset.map.{u1, u1} α α ((fun ([email protected]._hyg.2713 : α) ([email protected]._hyg.2715 : α) => HAdd.hAdd.{u1, u1, u1} α α α (instHAdd.{u1} α (AddZeroClass.toAdd.{u1} α (AddMonoid.toAddZeroClass.{u1} α (AddRightCancelMonoid.toAddMonoid.{u1} α (AddCancelMonoid.toAddRightCancelMonoid.{u1} α (AddCancelCommMonoid.toAddCancelMonoid.{u1} α (OrderedCancelAddCommMonoid.toCancelAddCommMonoid.{u1} α _inst_1))))))) [email protected]._hyg.2713 [email protected]._hyg.2715) c) (Multiset.Ico.{u1} α (PartialOrder.toPreorder.{u1} α (OrderedCancelAddCommMonoid.toPartialOrder.{u1} α _inst_1)) _inst_3 a b)) (Multiset.Ico.{u1} α (PartialOrder.toPreorder.{u1} α (OrderedCancelAddCommMonoid.toPartialOrder.{u1} α _inst_1)) _inst_3 (HAdd.hAdd.{u1, u1, u1} α α α (instHAdd.{u1} α (AddZeroClass.toAdd.{u1} α (AddMonoid.toAddZeroClass.{u1} α (AddRightCancelMonoid.toAddMonoid.{u1} α (AddCancelMonoid.toAddRightCancelMonoid.{u1} α (AddCancelCommMonoid.toAddCancelMonoid.{u1} α (OrderedCancelAddCommMonoid.toCancelAddCommMonoid.{u1} α _inst_1))))))) c a) (HAdd.hAdd.{u1, u1, u1} α α α (instHAdd.{u1} α (AddZeroClass.toAdd.{u1} α (AddMonoid.toAddZeroClass.{u1} α (AddRightCancelMonoid.toAddMonoid.{u1} α (AddCancelMonoid.toAddRightCancelMonoid.{u1} α (AddCancelCommMonoid.toAddCancelMonoid.{u1} α (OrderedCancelAddCommMonoid.toCancelAddCommMonoid.{u1} α _inst_1))))))) c b)) Case conversion may be inaccurate. Consider using '#align multiset.map_add_left_Ico Multiset.map_add_left_Icoₓ'. -/ theorem map_add_left_Ico (a b c : α) : (Ico a b).map ((· + ·) c) = Ico (c + a) (c + b) := by classical rw [Ico, Ico, ← Finset.image_add_left_Ico, Finset.image_val, ((Finset.nodup _).map <| add_right_injective c).dedup] #align multiset.map_add_left_Ico Multiset.map_add_left_Ico /- warning: multiset.map_add_left_Ioc -> Multiset.map_add_left_Ioc is a dubious translation: lean 3 declaration is forall {α : Type.{u1}} [_inst_1 : OrderedCancelAddCommMonoid.{u1} α] [_inst_2 : ExistsAddOfLE.{u1} α (AddZeroClass.toHasAdd.{u1} α (AddMonoid.toAddZeroClass.{u1} α (AddRightCancelMonoid.toAddMonoid.{u1} α (AddCancelMonoid.toAddRightCancelMonoid.{u1} α (AddCancelCommMonoid.toAddCancelMonoid.{u1} α (OrderedCancelAddCommMonoid.toCancelAddCommMonoid.{u1} α _inst_1)))))) (Preorder.toLE.{u1} α (PartialOrder.toPreorder.{u1} α (OrderedCancelAddCommMonoid.toPartialOrder.{u1} α _inst_1)))] [_inst_3 : LocallyFiniteOrder.{u1} α (PartialOrder.toPreorder.{u1} α (OrderedCancelAddCommMonoid.toPartialOrder.{u1} α _inst_1))] (a : α) (b : α) (c : α), Eq.{succ u1} (Multiset.{u1} α) (Multiset.map.{u1, u1} α α (HAdd.hAdd.{u1, u1, u1} α α α (instHAdd.{u1} α (AddZeroClass.toHasAdd.{u1} α (AddMonoid.toAddZeroClass.{u1} α (AddRightCancelMonoid.toAddMonoid.{u1} α (AddCancelMonoid.toAddRightCancelMonoid.{u1} α (AddCancelCommMonoid.toAddCancelMonoid.{u1} α (OrderedCancelAddCommMonoid.toCancelAddCommMonoid.{u1} α _inst_1))))))) c) (Multiset.Ioc.{u1} α (PartialOrder.toPreorder.{u1} α (OrderedCancelAddCommMonoid.toPartialOrder.{u1} α _inst_1)) _inst_3 a b)) (Multiset.Ioc.{u1} α (PartialOrder.toPreorder.{u1} α (OrderedCancelAddCommMonoid.toPartialOrder.{u1} α _inst_1)) _inst_3 (HAdd.hAdd.{u1, u1, u1} α α α (instHAdd.{u1} α (AddZeroClass.toHasAdd.{u1} α (AddMonoid.toAddZeroClass.{u1} α (AddRightCancelMonoid.toAddMonoid.{u1} α (AddCancelMonoid.toAddRightCancelMonoid.{u1} α (AddCancelCommMonoid.toAddCancelMonoid.{u1} α (OrderedCancelAddCommMonoid.toCancelAddCommMonoid.{u1} α _inst_1))))))) c a) (HAdd.hAdd.{u1, u1, u1} α α α (instHAdd.{u1} α (AddZeroClass.toHasAdd.{u1} α (AddMonoid.toAddZeroClass.{u1} α (AddRightCancelMonoid.toAddMonoid.{u1} α (AddCancelMonoid.toAddRightCancelMonoid.{u1} α (AddCancelCommMonoid.toAddCancelMonoid.{u1} α (OrderedCancelAddCommMonoid.toCancelAddCommMonoid.{u1} α _inst_1))))))) c b)) but is expected to have type forall {α : Type.{u1}} [_inst_1 : OrderedCancelAddCommMonoid.{u1} α] [_inst_2 : ExistsAddOfLE.{u1} α (AddZeroClass.toAdd.{u1} α (AddMonoid.toAddZeroClass.{u1} α (AddRightCancelMonoid.toAddMonoid.{u1} α (AddCancelMonoid.toAddRightCancelMonoid.{u1} α (AddCancelCommMonoid.toAddCancelMonoid.{u1} α (OrderedCancelAddCommMonoid.toCancelAddCommMonoid.{u1} α _inst_1)))))) (Preorder.toLE.{u1} α (PartialOrder.toPreorder.{u1} α (OrderedCancelAddCommMonoid.toPartialOrder.{u1} α _inst_1)))] [_inst_3 : LocallyFiniteOrder.{u1} α (PartialOrder.toPreorder.{u1} α (OrderedCancelAddCommMonoid.toPartialOrder.{u1} α _inst_1))] (a : α) (b : α) (c : α), Eq.{succ u1} (Multiset.{u1} α) (Multiset.map.{u1, u1} α α ((fun ([email protected]._hyg.2818 : α) ([email protected]._hyg.2820 : α) => HAdd.hAdd.{u1, u1, u1} α α α (instHAdd.{u1} α (AddZeroClass.toAdd.{u1} α (AddMonoid.toAddZeroClass.{u1} α (AddRightCancelMonoid.toAddMonoid.{u1} α (AddCancelMonoid.toAddRightCancelMonoid.{u1} α (AddCancelCommMonoid.toAddCancelMonoid.{u1} α (OrderedCancelAddCommMonoid.toCancelAddCommMonoid.{u1} α _inst_1))))))) [email protected]._hyg.2818 [email protected]._hyg.2820) c) (Multiset.Ioc.{u1} α (PartialOrder.toPreorder.{u1} α (OrderedCancelAddCommMonoid.toPartialOrder.{u1} α _inst_1)) _inst_3 a b)) (Multiset.Ioc.{u1} α (PartialOrder.toPreorder.{u1} α (OrderedCancelAddCommMonoid.toPartialOrder.{u1} α _inst_1)) _inst_3 (HAdd.hAdd.{u1, u1, u1} α α α (instHAdd.{u1} α (AddZeroClass.toAdd.{u1} α (AddMonoid.toAddZeroClass.{u1} α (AddRightCancelMonoid.toAddMonoid.{u1} α (AddCancelMonoid.toAddRightCancelMonoid.{u1} α (AddCancelCommMonoid.toAddCancelMonoid.{u1} α (OrderedCancelAddCommMonoid.toCancelAddCommMonoid.{u1} α _inst_1))))))) c a) (HAdd.hAdd.{u1, u1, u1} α α α (instHAdd.{u1} α (AddZeroClass.toAdd.{u1} α (AddMonoid.toAddZeroClass.{u1} α (AddRightCancelMonoid.toAddMonoid.{u1} α (AddCancelMonoid.toAddRightCancelMonoid.{u1} α (AddCancelCommMonoid.toAddCancelMonoid.{u1} α (OrderedCancelAddCommMonoid.toCancelAddCommMonoid.{u1} α _inst_1))))))) c b)) Case conversion may be inaccurate. Consider using '#align multiset.map_add_left_Ioc Multiset.map_add_left_Iocₓ'. -/ theorem map_add_left_Ioc (a b c : α) : (Ioc a b).map ((· + ·) c) = Ioc (c + a) (c + b) := by classical rw [Ioc, Ioc, ← Finset.image_add_left_Ioc, Finset.image_val, ((Finset.nodup _).map <| add_right_injective c).dedup] #align multiset.map_add_left_Ioc Multiset.map_add_left_Ioc /- warning: multiset.map_add_left_Ioo -> Multiset.map_add_left_Ioo is a dubious translation: lean 3 declaration is forall {α : Type.{u1}} [_inst_1 : OrderedCancelAddCommMonoid.{u1} α] [_inst_2 : ExistsAddOfLE.{u1} α (AddZeroClass.toHasAdd.{u1} α (AddMonoid.toAddZeroClass.{u1} α (AddRightCancelMonoid.toAddMonoid.{u1} α (AddCancelMonoid.toAddRightCancelMonoid.{u1} α (AddCancelCommMonoid.toAddCancelMonoid.{u1} α (OrderedCancelAddCommMonoid.toCancelAddCommMonoid.{u1} α _inst_1)))))) (Preorder.toLE.{u1} α (PartialOrder.toPreorder.{u1} α (OrderedCancelAddCommMonoid.toPartialOrder.{u1} α _inst_1)))] [_inst_3 : LocallyFiniteOrder.{u1} α (PartialOrder.toPreorder.{u1} α (OrderedCancelAddCommMonoid.toPartialOrder.{u1} α _inst_1))] (a : α) (b : α) (c : α), Eq.{succ u1} (Multiset.{u1} α) (Multiset.map.{u1, u1} α α (HAdd.hAdd.{u1, u1, u1} α α α (instHAdd.{u1} α (AddZeroClass.toHasAdd.{u1} α (AddMonoid.toAddZeroClass.{u1} α (AddRightCancelMonoid.toAddMonoid.{u1} α (AddCancelMonoid.toAddRightCancelMonoid.{u1} α (AddCancelCommMonoid.toAddCancelMonoid.{u1} α (OrderedCancelAddCommMonoid.toCancelAddCommMonoid.{u1} α _inst_1))))))) c) (Multiset.Ioo.{u1} α (PartialOrder.toPreorder.{u1} α (OrderedCancelAddCommMonoid.toPartialOrder.{u1} α _inst_1)) _inst_3 a b)) (Multiset.Ioo.{u1} α (PartialOrder.toPreorder.{u1} α (OrderedCancelAddCommMonoid.toPartialOrder.{u1} α _inst_1)) _inst_3 (HAdd.hAdd.{u1, u1, u1} α α α (instHAdd.{u1} α (AddZeroClass.toHasAdd.{u1} α (AddMonoid.toAddZeroClass.{u1} α (AddRightCancelMonoid.toAddMonoid.{u1} α (AddCancelMonoid.toAddRightCancelMonoid.{u1} α (AddCancelCommMonoid.toAddCancelMonoid.{u1} α (OrderedCancelAddCommMonoid.toCancelAddCommMonoid.{u1} α _inst_1))))))) c a) (HAdd.hAdd.{u1, u1, u1} α α α (instHAdd.{u1} α (AddZeroClass.toHasAdd.{u1} α (AddMonoid.toAddZeroClass.{u1} α (AddRightCancelMonoid.toAddMonoid.{u1} α (AddCancelMonoid.toAddRightCancelMonoid.{u1} α (AddCancelCommMonoid.toAddCancelMonoid.{u1} α (OrderedCancelAddCommMonoid.toCancelAddCommMonoid.{u1} α _inst_1))))))) c b)) but is expected to have type forall {α : Type.{u1}} [_inst_1 : OrderedCancelAddCommMonoid.{u1} α] [_inst_2 : ExistsAddOfLE.{u1} α (AddZeroClass.toAdd.{u1} α (AddMonoid.toAddZeroClass.{u1} α (AddRightCancelMonoid.toAddMonoid.{u1} α (AddCancelMonoid.toAddRightCancelMonoid.{u1} α (AddCancelCommMonoid.toAddCancelMonoid.{u1} α (OrderedCancelAddCommMonoid.toCancelAddCommMonoid.{u1} α _inst_1)))))) (Preorder.toLE.{u1} α (PartialOrder.toPreorder.{u1} α (OrderedCancelAddCommMonoid.toPartialOrder.{u1} α _inst_1)))] [_inst_3 : LocallyFiniteOrder.{u1} α (PartialOrder.toPreorder.{u1} α (OrderedCancelAddCommMonoid.toPartialOrder.{u1} α _inst_1))] (a : α) (b : α) (c : α), Eq.{succ u1} (Multiset.{u1} α) (Multiset.map.{u1, u1} α α ((fun ([email protected]._hyg.2923 : α) ([email protected]._hyg.2925 : α) => HAdd.hAdd.{u1, u1, u1} α α α (instHAdd.{u1} α (AddZeroClass.toAdd.{u1} α (AddMonoid.toAddZeroClass.{u1} α (AddRightCancelMonoid.toAddMonoid.{u1} α (AddCancelMonoid.toAddRightCancelMonoid.{u1} α (AddCancelCommMonoid.toAddCancelMonoid.{u1} α (OrderedCancelAddCommMonoid.toCancelAddCommMonoid.{u1} α _inst_1))))))) [email protected]._hyg.2923 [email protected]._hyg.2925) c) (Multiset.Ioo.{u1} α (PartialOrder.toPreorder.{u1} α (OrderedCancelAddCommMonoid.toPartialOrder.{u1} α _inst_1)) _inst_3 a b)) (Multiset.Ioo.{u1} α (PartialOrder.toPreorder.{u1} α (OrderedCancelAddCommMonoid.toPartialOrder.{u1} α _inst_1)) _inst_3 (HAdd.hAdd.{u1, u1, u1} α α α (instHAdd.{u1} α (AddZeroClass.toAdd.{u1} α (AddMonoid.toAddZeroClass.{u1} α (AddRightCancelMonoid.toAddMonoid.{u1} α (AddCancelMonoid.toAddRightCancelMonoid.{u1} α (AddCancelCommMonoid.toAddCancelMonoid.{u1} α (OrderedCancelAddCommMonoid.toCancelAddCommMonoid.{u1} α _inst_1))))))) c a) (HAdd.hAdd.{u1, u1, u1} α α α (instHAdd.{u1} α (AddZeroClass.toAdd.{u1} α (AddMonoid.toAddZeroClass.{u1} α (AddRightCancelMonoid.toAddMonoid.{u1} α (AddCancelMonoid.toAddRightCancelMonoid.{u1} α (AddCancelCommMonoid.toAddCancelMonoid.{u1} α (OrderedCancelAddCommMonoid.toCancelAddCommMonoid.{u1} α _inst_1))))))) c b)) Case conversion may be inaccurate. Consider using '#align multiset.map_add_left_Ioo Multiset.map_add_left_Iooₓ'. -/ theorem map_add_left_Ioo (a b c : α) : (Ioo a b).map ((· + ·) c) = Ioo (c + a) (c + b) := by classical rw [Ioo, Ioo, ← Finset.image_add_left_Ioo, Finset.image_val, ((Finset.nodup _).map <| add_right_injective c).dedup] #align multiset.map_add_left_Ioo Multiset.map_add_left_Ioo /- warning: multiset.map_add_right_Icc -> Multiset.map_add_right_Icc is a dubious translation: lean 3 declaration is forall {α : Type.{u1}} [_inst_1 : OrderedCancelAddCommMonoid.{u1} α] [_inst_2 : ExistsAddOfLE.{u1} α (AddZeroClass.toHasAdd.{u1} α (AddMonoid.toAddZeroClass.{u1} α (AddRightCancelMonoid.toAddMonoid.{u1} α (AddCancelMonoid.toAddRightCancelMonoid.{u1} α (AddCancelCommMonoid.toAddCancelMonoid.{u1} α (OrderedCancelAddCommMonoid.toCancelAddCommMonoid.{u1} α _inst_1)))))) (Preorder.toLE.{u1} α (PartialOrder.toPreorder.{u1} α (OrderedCancelAddCommMonoid.toPartialOrder.{u1} α _inst_1)))] [_inst_3 : LocallyFiniteOrder.{u1} α (PartialOrder.toPreorder.{u1} α (OrderedCancelAddCommMonoid.toPartialOrder.{u1} α _inst_1))] (a : α) (b : α) (c : α), Eq.{succ u1} (Multiset.{u1} α) (Multiset.map.{u1, u1} α α (fun (x : α) => HAdd.hAdd.{u1, u1, u1} α α α (instHAdd.{u1} α (AddZeroClass.toHasAdd.{u1} α (AddMonoid.toAddZeroClass.{u1} α (AddRightCancelMonoid.toAddMonoid.{u1} α (AddCancelMonoid.toAddRightCancelMonoid.{u1} α (AddCancelCommMonoid.toAddCancelMonoid.{u1} α (OrderedCancelAddCommMonoid.toCancelAddCommMonoid.{u1} α _inst_1))))))) x c) (Multiset.Icc.{u1} α (PartialOrder.toPreorder.{u1} α (OrderedCancelAddCommMonoid.toPartialOrder.{u1} α _inst_1)) _inst_3 a b)) (Multiset.Icc.{u1} α (PartialOrder.toPreorder.{u1} α (OrderedCancelAddCommMonoid.toPartialOrder.{u1} α _inst_1)) _inst_3 (HAdd.hAdd.{u1, u1, u1} α α α (instHAdd.{u1} α (AddZeroClass.toHasAdd.{u1} α (AddMonoid.toAddZeroClass.{u1} α (AddRightCancelMonoid.toAddMonoid.{u1} α (AddCancelMonoid.toAddRightCancelMonoid.{u1} α (AddCancelCommMonoid.toAddCancelMonoid.{u1} α (OrderedCancelAddCommMonoid.toCancelAddCommMonoid.{u1} α _inst_1))))))) a c) (HAdd.hAdd.{u1, u1, u1} α α α (instHAdd.{u1} α (AddZeroClass.toHasAdd.{u1} α (AddMonoid.toAddZeroClass.{u1} α (AddRightCancelMonoid.toAddMonoid.{u1} α (AddCancelMonoid.toAddRightCancelMonoid.{u1} α (AddCancelCommMonoid.toAddCancelMonoid.{u1} α (OrderedCancelAddCommMonoid.toCancelAddCommMonoid.{u1} α _inst_1))))))) b c)) but is expected to have type forall {α : Type.{u1}} [_inst_1 : OrderedCancelAddCommMonoid.{u1} α] [_inst_2 : ExistsAddOfLE.{u1} α (AddZeroClass.toAdd.{u1} α (AddMonoid.toAddZeroClass.{u1} α (AddRightCancelMonoid.toAddMonoid.{u1} α (AddCancelMonoid.toAddRightCancelMonoid.{u1} α (AddCancelCommMonoid.toAddCancelMonoid.{u1} α (OrderedCancelAddCommMonoid.toCancelAddCommMonoid.{u1} α _inst_1)))))) (Preorder.toLE.{u1} α (PartialOrder.toPreorder.{u1} α (OrderedCancelAddCommMonoid.toPartialOrder.{u1} α _inst_1)))] [_inst_3 : LocallyFiniteOrder.{u1} α (PartialOrder.toPreorder.{u1} α (OrderedCancelAddCommMonoid.toPartialOrder.{u1} α _inst_1))] (a : α) (b : α) (c : α), Eq.{succ u1} (Multiset.{u1} α) (Multiset.map.{u1, u1} α α (fun (x : α) => HAdd.hAdd.{u1, u1, u1} α α α (instHAdd.{u1} α (AddZeroClass.toAdd.{u1} α (AddMonoid.toAddZeroClass.{u1} α (AddRightCancelMonoid.toAddMonoid.{u1} α (AddCancelMonoid.toAddRightCancelMonoid.{u1} α (AddCancelCommMonoid.toAddCancelMonoid.{u1} α (OrderedCancelAddCommMonoid.toCancelAddCommMonoid.{u1} α _inst_1))))))) x c) (Multiset.Icc.{u1} α (PartialOrder.toPreorder.{u1} α (OrderedCancelAddCommMonoid.toPartialOrder.{u1} α _inst_1)) _inst_3 a b)) (Multiset.Icc.{u1} α (PartialOrder.toPreorder.{u1} α (OrderedCancelAddCommMonoid.toPartialOrder.{u1} α _inst_1)) _inst_3 (HAdd.hAdd.{u1, u1, u1} α α α (instHAdd.{u1} α (AddZeroClass.toAdd.{u1} α (AddMonoid.toAddZeroClass.{u1} α (AddRightCancelMonoid.toAddMonoid.{u1} α (AddCancelMonoid.toAddRightCancelMonoid.{u1} α (AddCancelCommMonoid.toAddCancelMonoid.{u1} α (OrderedCancelAddCommMonoid.toCancelAddCommMonoid.{u1} α _inst_1))))))) a c) (HAdd.hAdd.{u1, u1, u1} α α α (instHAdd.{u1} α (AddZeroClass.toAdd.{u1} α (AddMonoid.toAddZeroClass.{u1} α (AddRightCancelMonoid.toAddMonoid.{u1} α (AddCancelMonoid.toAddRightCancelMonoid.{u1} α (AddCancelCommMonoid.toAddCancelMonoid.{u1} α (OrderedCancelAddCommMonoid.toCancelAddCommMonoid.{u1} α _inst_1))))))) b c)) Case conversion may be inaccurate. Consider using '#align multiset.map_add_right_Icc Multiset.map_add_right_Iccₓ'. -/ theorem map_add_right_Icc (a b c : α) : ((Icc a b).map fun x => x + c) = Icc (a + c) (b + c) := by simp_rw [add_comm _ c] exact map_add_left_Icc _ _ _ #align multiset.map_add_right_Icc Multiset.map_add_right_Icc /- warning: multiset.map_add_right_Ico -> Multiset.map_add_right_Ico is a dubious translation: lean 3 declaration is forall {α : Type.{u1}} [_inst_1 : OrderedCancelAddCommMonoid.{u1} α] [_inst_2 : ExistsAddOfLE.{u1} α (AddZeroClass.toHasAdd.{u1} α (AddMonoid.toAddZeroClass.{u1} α (AddRightCancelMonoid.toAddMonoid.{u1} α (AddCancelMonoid.toAddRightCancelMonoid.{u1} α (AddCancelCommMonoid.toAddCancelMonoid.{u1} α (OrderedCancelAddCommMonoid.toCancelAddCommMonoid.{u1} α _inst_1)))))) (Preorder.toLE.{u1} α (PartialOrder.toPreorder.{u1} α (OrderedCancelAddCommMonoid.toPartialOrder.{u1} α _inst_1)))] [_inst_3 : LocallyFiniteOrder.{u1} α (PartialOrder.toPreorder.{u1} α (OrderedCancelAddCommMonoid.toPartialOrder.{u1} α _inst_1))] (a : α) (b : α) (c : α), Eq.{succ u1} (Multiset.{u1} α) (Multiset.map.{u1, u1} α α (fun (x : α) => HAdd.hAdd.{u1, u1, u1} α α α (instHAdd.{u1} α (AddZeroClass.toHasAdd.{u1} α (AddMonoid.toAddZeroClass.{u1} α (AddRightCancelMonoid.toAddMonoid.{u1} α (AddCancelMonoid.toAddRightCancelMonoid.{u1} α (AddCancelCommMonoid.toAddCancelMonoid.{u1} α (OrderedCancelAddCommMonoid.toCancelAddCommMonoid.{u1} α _inst_1))))))) x c) (Multiset.Ico.{u1} α (PartialOrder.toPreorder.{u1} α (OrderedCancelAddCommMonoid.toPartialOrder.{u1} α _inst_1)) _inst_3 a b)) (Multiset.Ico.{u1} α (PartialOrder.toPreorder.{u1} α (OrderedCancelAddCommMonoid.toPartialOrder.{u1} α _inst_1)) _inst_3 (HAdd.hAdd.{u1, u1, u1} α α α (instHAdd.{u1} α (AddZeroClass.toHasAdd.{u1} α (AddMonoid.toAddZeroClass.{u1} α (AddRightCancelMonoid.toAddMonoid.{u1} α (AddCancelMonoid.toAddRightCancelMonoid.{u1} α (AddCancelCommMonoid.toAddCancelMonoid.{u1} α (OrderedCancelAddCommMonoid.toCancelAddCommMonoid.{u1} α _inst_1))))))) a c) (HAdd.hAdd.{u1, u1, u1} α α α (instHAdd.{u1} α (AddZeroClass.toHasAdd.{u1} α (AddMonoid.toAddZeroClass.{u1} α (AddRightCancelMonoid.toAddMonoid.{u1} α (AddCancelMonoid.toAddRightCancelMonoid.{u1} α (AddCancelCommMonoid.toAddCancelMonoid.{u1} α (OrderedCancelAddCommMonoid.toCancelAddCommMonoid.{u1} α _inst_1))))))) b c)) but is expected to have type forall {α : Type.{u1}} [_inst_1 : OrderedCancelAddCommMonoid.{u1} α] [_inst_2 : ExistsAddOfLE.{u1} α (AddZeroClass.toAdd.{u1} α (AddMonoid.toAddZeroClass.{u1} α (AddRightCancelMonoid.toAddMonoid.{u1} α (AddCancelMonoid.toAddRightCancelMonoid.{u1} α (AddCancelCommMonoid.toAddCancelMonoid.{u1} α (OrderedCancelAddCommMonoid.toCancelAddCommMonoid.{u1} α _inst_1)))))) (Preorder.toLE.{u1} α (PartialOrder.toPreorder.{u1} α (OrderedCancelAddCommMonoid.toPartialOrder.{u1} α _inst_1)))] [_inst_3 : LocallyFiniteOrder.{u1} α (PartialOrder.toPreorder.{u1} α (OrderedCancelAddCommMonoid.toPartialOrder.{u1} α _inst_1))] (a : α) (b : α) (c : α), Eq.{succ u1} (Multiset.{u1} α) (Multiset.map.{u1, u1} α α (fun (x : α) => HAdd.hAdd.{u1, u1, u1} α α α (instHAdd.{u1} α (AddZeroClass.toAdd.{u1} α (AddMonoid.toAddZeroClass.{u1} α (AddRightCancelMonoid.toAddMonoid.{u1} α (AddCancelMonoid.toAddRightCancelMonoid.{u1} α (AddCancelCommMonoid.toAddCancelMonoid.{u1} α (OrderedCancelAddCommMonoid.toCancelAddCommMonoid.{u1} α _inst_1))))))) x c) (Multiset.Ico.{u1} α (PartialOrder.toPreorder.{u1} α (OrderedCancelAddCommMonoid.toPartialOrder.{u1} α _inst_1)) _inst_3 a b)) (Multiset.Ico.{u1} α (PartialOrder.toPreorder.{u1} α (OrderedCancelAddCommMonoid.toPartialOrder.{u1} α _inst_1)) _inst_3 (HAdd.hAdd.{u1, u1, u1} α α α (instHAdd.{u1} α (AddZeroClass.toAdd.{u1} α (AddMonoid.toAddZeroClass.{u1} α (AddRightCancelMonoid.toAddMonoid.{u1} α (AddCancelMonoid.toAddRightCancelMonoid.{u1} α (AddCancelCommMonoid.toAddCancelMonoid.{u1} α (OrderedCancelAddCommMonoid.toCancelAddCommMonoid.{u1} α _inst_1))))))) a c) (HAdd.hAdd.{u1, u1, u1} α α α (instHAdd.{u1} α (AddZeroClass.toAdd.{u1} α (AddMonoid.toAddZeroClass.{u1} α (AddRightCancelMonoid.toAddMonoid.{u1} α (AddCancelMonoid.toAddRightCancelMonoid.{u1} α (AddCancelCommMonoid.toAddCancelMonoid.{u1} α (OrderedCancelAddCommMonoid.toCancelAddCommMonoid.{u1} α _inst_1))))))) b c)) Case conversion may be inaccurate. Consider using '#align multiset.map_add_right_Ico Multiset.map_add_right_Icoₓ'. -/ theorem map_add_right_Ico (a b c : α) : ((Ico a b).map fun x => x + c) = Ico (a + c) (b + c) := by simp_rw [add_comm _ c] exact map_add_left_Ico _ _ _ #align multiset.map_add_right_Ico Multiset.map_add_right_Ico /- warning: multiset.map_add_right_Ioc -> Multiset.map_add_right_Ioc is a dubious translation: lean 3 declaration is forall {α : Type.{u1}} [_inst_1 : OrderedCancelAddCommMonoid.{u1} α] [_inst_2 : ExistsAddOfLE.{u1} α (AddZeroClass.toHasAdd.{u1} α (AddMonoid.toAddZeroClass.{u1} α (AddRightCancelMonoid.toAddMonoid.{u1} α (AddCancelMonoid.toAddRightCancelMonoid.{u1} α (AddCancelCommMonoid.toAddCancelMonoid.{u1} α (OrderedCancelAddCommMonoid.toCancelAddCommMonoid.{u1} α _inst_1)))))) (Preorder.toLE.{u1} α (PartialOrder.toPreorder.{u1} α (OrderedCancelAddCommMonoid.toPartialOrder.{u1} α _inst_1)))] [_inst_3 : LocallyFiniteOrder.{u1} α (PartialOrder.toPreorder.{u1} α (OrderedCancelAddCommMonoid.toPartialOrder.{u1} α _inst_1))] (a : α) (b : α) (c : α), Eq.{succ u1} (Multiset.{u1} α) (Multiset.map.{u1, u1} α α (fun (x : α) => HAdd.hAdd.{u1, u1, u1} α α α (instHAdd.{u1} α (AddZeroClass.toHasAdd.{u1} α (AddMonoid.toAddZeroClass.{u1} α (AddRightCancelMonoid.toAddMonoid.{u1} α (AddCancelMonoid.toAddRightCancelMonoid.{u1} α (AddCancelCommMonoid.toAddCancelMonoid.{u1} α (OrderedCancelAddCommMonoid.toCancelAddCommMonoid.{u1} α _inst_1))))))) x c) (Multiset.Ioc.{u1} α (PartialOrder.toPreorder.{u1} α (OrderedCancelAddCommMonoid.toPartialOrder.{u1} α _inst_1)) _inst_3 a b)) (Multiset.Ioc.{u1} α (PartialOrder.toPreorder.{u1} α (OrderedCancelAddCommMonoid.toPartialOrder.{u1} α _inst_1)) _inst_3 (HAdd.hAdd.{u1, u1, u1} α α α (instHAdd.{u1} α (AddZeroClass.toHasAdd.{u1} α (AddMonoid.toAddZeroClass.{u1} α (AddRightCancelMonoid.toAddMonoid.{u1} α (AddCancelMonoid.toAddRightCancelMonoid.{u1} α (AddCancelCommMonoid.toAddCancelMonoid.{u1} α (OrderedCancelAddCommMonoid.toCancelAddCommMonoid.{u1} α _inst_1))))))) a c) (HAdd.hAdd.{u1, u1, u1} α α α (instHAdd.{u1} α (AddZeroClass.toHasAdd.{u1} α (AddMonoid.toAddZeroClass.{u1} α (AddRightCancelMonoid.toAddMonoid.{u1} α (AddCancelMonoid.toAddRightCancelMonoid.{u1} α (AddCancelCommMonoid.toAddCancelMonoid.{u1} α (OrderedCancelAddCommMonoid.toCancelAddCommMonoid.{u1} α _inst_1))))))) b c)) but is expected to have type forall {α : Type.{u1}} [_inst_1 : OrderedCancelAddCommMonoid.{u1} α] [_inst_2 : ExistsAddOfLE.{u1} α (AddZeroClass.toAdd.{u1} α (AddMonoid.toAddZeroClass.{u1} α (AddRightCancelMonoid.toAddMonoid.{u1} α (AddCancelMonoid.toAddRightCancelMonoid.{u1} α (AddCancelCommMonoid.toAddCancelMonoid.{u1} α (OrderedCancelAddCommMonoid.toCancelAddCommMonoid.{u1} α _inst_1)))))) (Preorder.toLE.{u1} α (PartialOrder.toPreorder.{u1} α (OrderedCancelAddCommMonoid.toPartialOrder.{u1} α _inst_1)))] [_inst_3 : LocallyFiniteOrder.{u1} α (PartialOrder.toPreorder.{u1} α (OrderedCancelAddCommMonoid.toPartialOrder.{u1} α _inst_1))] (a : α) (b : α) (c : α), Eq.{succ u1} (Multiset.{u1} α) (Multiset.map.{u1, u1} α α (fun (x : α) => HAdd.hAdd.{u1, u1, u1} α α α (instHAdd.{u1} α (AddZeroClass.toAdd.{u1} α (AddMonoid.toAddZeroClass.{u1} α (AddRightCancelMonoid.toAddMonoid.{u1} α (AddCancelMonoid.toAddRightCancelMonoid.{u1} α (AddCancelCommMonoid.toAddCancelMonoid.{u1} α (OrderedCancelAddCommMonoid.toCancelAddCommMonoid.{u1} α _inst_1))))))) x c) (Multiset.Ioc.{u1} α (PartialOrder.toPreorder.{u1} α (OrderedCancelAddCommMonoid.toPartialOrder.{u1} α _inst_1)) _inst_3 a b)) (Multiset.Ioc.{u1} α (PartialOrder.toPreorder.{u1} α (OrderedCancelAddCommMonoid.toPartialOrder.{u1} α _inst_1)) _inst_3 (HAdd.hAdd.{u1, u1, u1} α α α (instHAdd.{u1} α (AddZeroClass.toAdd.{u1} α (AddMonoid.toAddZeroClass.{u1} α (AddRightCancelMonoid.toAddMonoid.{u1} α (AddCancelMonoid.toAddRightCancelMonoid.{u1} α (AddCancelCommMonoid.toAddCancelMonoid.{u1} α (OrderedCancelAddCommMonoid.toCancelAddCommMonoid.{u1} α _inst_1))))))) a c) (HAdd.hAdd.{u1, u1, u1} α α α (instHAdd.{u1} α (AddZeroClass.toAdd.{u1} α (AddMonoid.toAddZeroClass.{u1} α (AddRightCancelMonoid.toAddMonoid.{u1} α (AddCancelMonoid.toAddRightCancelMonoid.{u1} α (AddCancelCommMonoid.toAddCancelMonoid.{u1} α (OrderedCancelAddCommMonoid.toCancelAddCommMonoid.{u1} α _inst_1))))))) b c)) Case conversion may be inaccurate. Consider using '#align multiset.map_add_right_Ioc Multiset.map_add_right_Iocₓ'. -/ theorem map_add_right_Ioc (a b c : α) : ((Ioc a b).map fun x => x + c) = Ioc (a + c) (b + c) := by simp_rw [add_comm _ c] exact map_add_left_Ioc _ _ _ #align multiset.map_add_right_Ioc Multiset.map_add_right_Ioc /- warning: multiset.map_add_right_Ioo -> Multiset.map_add_right_Ioo is a dubious translation: lean 3 declaration is forall {α : Type.{u1}} [_inst_1 : OrderedCancelAddCommMonoid.{u1} α] [_inst_2 : ExistsAddOfLE.{u1} α (AddZeroClass.toHasAdd.{u1} α (AddMonoid.toAddZeroClass.{u1} α (AddRightCancelMonoid.toAddMonoid.{u1} α (AddCancelMonoid.toAddRightCancelMonoid.{u1} α (AddCancelCommMonoid.toAddCancelMonoid.{u1} α (OrderedCancelAddCommMonoid.toCancelAddCommMonoid.{u1} α _inst_1)))))) (Preorder.toLE.{u1} α (PartialOrder.toPreorder.{u1} α (OrderedCancelAddCommMonoid.toPartialOrder.{u1} α _inst_1)))] [_inst_3 : LocallyFiniteOrder.{u1} α (PartialOrder.toPreorder.{u1} α (OrderedCancelAddCommMonoid.toPartialOrder.{u1} α _inst_1))] (a : α) (b : α) (c : α), Eq.{succ u1} (Multiset.{u1} α) (Multiset.map.{u1, u1} α α (fun (x : α) => HAdd.hAdd.{u1, u1, u1} α α α (instHAdd.{u1} α (AddZeroClass.toHasAdd.{u1} α (AddMonoid.toAddZeroClass.{u1} α (AddRightCancelMonoid.toAddMonoid.{u1} α (AddCancelMonoid.toAddRightCancelMonoid.{u1} α (AddCancelCommMonoid.toAddCancelMonoid.{u1} α (OrderedCancelAddCommMonoid.toCancelAddCommMonoid.{u1} α _inst_1))))))) x c) (Multiset.Ioo.{u1} α (PartialOrder.toPreorder.{u1} α (OrderedCancelAddCommMonoid.toPartialOrder.{u1} α _inst_1)) _inst_3 a b)) (Multiset.Ioo.{u1} α (PartialOrder.toPreorder.{u1} α (OrderedCancelAddCommMonoid.toPartialOrder.{u1} α _inst_1)) _inst_3 (HAdd.hAdd.{u1, u1, u1} α α α (instHAdd.{u1} α (AddZeroClass.toHasAdd.{u1} α (AddMonoid.toAddZeroClass.{u1} α (AddRightCancelMonoid.toAddMonoid.{u1} α (AddCancelMonoid.toAddRightCancelMonoid.{u1} α (AddCancelCommMonoid.toAddCancelMonoid.{u1} α (OrderedCancelAddCommMonoid.toCancelAddCommMonoid.{u1} α _inst_1))))))) a c) (HAdd.hAdd.{u1, u1, u1} α α α (instHAdd.{u1} α (AddZeroClass.toHasAdd.{u1} α (AddMonoid.toAddZeroClass.{u1} α (AddRightCancelMonoid.toAddMonoid.{u1} α (AddCancelMonoid.toAddRightCancelMonoid.{u1} α (AddCancelCommMonoid.toAddCancelMonoid.{u1} α (OrderedCancelAddCommMonoid.toCancelAddCommMonoid.{u1} α _inst_1))))))) b c)) but is expected to have type forall {α : Type.{u1}} [_inst_1 : OrderedCancelAddCommMonoid.{u1} α] [_inst_2 : ExistsAddOfLE.{u1} α (AddZeroClass.toAdd.{u1} α (AddMonoid.toAddZeroClass.{u1} α (AddRightCancelMonoid.toAddMonoid.{u1} α (AddCancelMonoid.toAddRightCancelMonoid.{u1} α (AddCancelCommMonoid.toAddCancelMonoid.{u1} α (OrderedCancelAddCommMonoid.toCancelAddCommMonoid.{u1} α _inst_1)))))) (Preorder.toLE.{u1} α (PartialOrder.toPreorder.{u1} α (OrderedCancelAddCommMonoid.toPartialOrder.{u1} α _inst_1)))] [_inst_3 : LocallyFiniteOrder.{u1} α (PartialOrder.toPreorder.{u1} α (OrderedCancelAddCommMonoid.toPartialOrder.{u1} α _inst_1))] (a : α) (b : α) (c : α), Eq.{succ u1} (Multiset.{u1} α) (Multiset.map.{u1, u1} α α (fun (x : α) => HAdd.hAdd.{u1, u1, u1} α α α (instHAdd.{u1} α (AddZeroClass.toAdd.{u1} α (AddMonoid.toAddZeroClass.{u1} α (AddRightCancelMonoid.toAddMonoid.{u1} α (AddCancelMonoid.toAddRightCancelMonoid.{u1} α (AddCancelCommMonoid.toAddCancelMonoid.{u1} α (OrderedCancelAddCommMonoid.toCancelAddCommMonoid.{u1} α _inst_1))))))) x c) (Multiset.Ioo.{u1} α (PartialOrder.toPreorder.{u1} α (OrderedCancelAddCommMonoid.toPartialOrder.{u1} α _inst_1)) _inst_3 a b)) (Multiset.Ioo.{u1} α (PartialOrder.toPreorder.{u1} α (OrderedCancelAddCommMonoid.toPartialOrder.{u1} α _inst_1)) _inst_3 (HAdd.hAdd.{u1, u1, u1} α α α (instHAdd.{u1} α (AddZeroClass.toAdd.{u1} α (AddMonoid.toAddZeroClass.{u1} α (AddRightCancelMonoid.toAddMonoid.{u1} α (AddCancelMonoid.toAddRightCancelMonoid.{u1} α (AddCancelCommMonoid.toAddCancelMonoid.{u1} α (OrderedCancelAddCommMonoid.toCancelAddCommMonoid.{u1} α _inst_1))))))) a c) (HAdd.hAdd.{u1, u1, u1} α α α (instHAdd.{u1} α (AddZeroClass.toAdd.{u1} α (AddMonoid.toAddZeroClass.{u1} α (AddRightCancelMonoid.toAddMonoid.{u1} α (AddCancelMonoid.toAddRightCancelMonoid.{u1} α (AddCancelCommMonoid.toAddCancelMonoid.{u1} α (OrderedCancelAddCommMonoid.toCancelAddCommMonoid.{u1} α _inst_1))))))) b c)) Case conversion may be inaccurate. Consider using '#align multiset.map_add_right_Ioo Multiset.map_add_right_Iooₓ'. -/ theorem map_add_right_Ioo (a b c : α) : ((Ioo a b).map fun x => x + c) = Ioo (a + c) (b + c) := by simp_rw [add_comm _ c] exact map_add_left_Ioo _ _ _ #align multiset.map_add_right_Ioo Multiset.map_add_right_Ioo end OrderedCancelAddCommMonoid end Multiset
using Printf using Statistics using LinearAlgebra using DelimitedFiles using IterativeSolvers using SparseArrays using TickTock # rearrange the edge sequence in the increasing order of layer id and starting node id function edge_seq_rearrangement(edge_seq::Array{Int64,2}) layer_list = setdiff(edge_seq[:,4],[]) L = maximum(layer_list) if length(setdiff([i for i = 1:L],layer_list)) != 0 println("please label layers in the order 1, 2, ..., L") end node_list = setdiff(edge_seq[:,1],[]) N = maximum(edge_seq[:,1]) if length(setdiff([i for i = 1:N],node_list)) != 0 println("please label nodes in the order 1, 2, ..., N") end edge_seq_rearranged = zeros(Int64,size(edge_seq)) id = 1 for ell in layer_list edge_list_ell = findall(isequal(ell),edge_seq[:,4]) M = sparse(edge_seq[edge_list_ell,1],edge_seq[edge_list_ell,2],edge_seq[edge_list_ell,3]) inds = findall(!iszero,M) a = getindex.(inds, 1) b = getindex.(inds, 2) edge_seq_rearranged[id:id+length(a)-1,1] = b edge_seq_rearranged[id:id+length(a)-1,2] = a edge_seq_rearranged[id:id+length(a)-1,3] = M[inds] edge_seq_rearranged[id:id+length(a)-1,4] = ell*ones(Int64,length(a)) id = id+length(a) end return edge_seq_rearranged end # solve a set of equations to obtain beta_i, beta_ij, and gamma_ij, for any number of layers # this function is used for rhoA > (rhoA)^o in layer one under a given strategy configuration # input--- # multilayer network in the form of an edge sequanece: edge_seq [node id, node id, edge weight, layer id], where edge weights here are set to be any positive integer # initial strategy configuration: xi_seq [node id, strategy, layer id] # output--- # the first column of "solution" gives beta_ij # the other columns of "solution" gives gamma_ij, where the ll_th column is the strategy assortment between layer 1 and layter ll function beta_gamma(edge_seq::Array{Int64,2}, xi_seq::Array{Int64,2}) N = maximum(edge_seq[:,1]) L = maximum(edge_seq[:,4]) M = spzeros(Float64,N*L,N) for ell = 1:L edge_list_ell = findall(isequal(ell),edge_seq[:,4]) M_ell = sparse(edge_seq[edge_list_ell,1],edge_seq[edge_list_ell,2],edge_seq[edge_list_ell,3],N,N) M[(ell-1)*N+1:ell*N,:] = M_ell end pi = spzeros(Float64,L*N) for ell = 1:L pi_2 = sum(M[(ell-1)*N+1:ell*N,:], dims = 2) pi_2 = pi_2[:,1] pi_transient = spzeros(Float64, N) presence = findall(!iszero,pi_2) pi_transient[presence] = pi_2[presence]/sum(pi_2) pi[(ell-1)*N+1:ell*N] = pi_transient M_transient = M[(ell-1)*N+1:ell*N,:] M_transient[presence,:] = M_transient[presence,:]./pi_2[presence] M[(ell-1)*N+1:ell*N,:] = M_transient end xi = spzeros(Float64,L*N) for ell = 1:L xi_transient = spzeros(Int64,N) presence = findall(isequal(ell),xi_seq[:,3]) xi_transient[xi_seq[presence,1]] = xi_seq[presence,2] xi[(ell-1)*N+1:ell*N] = xi_transient end # obtain beta_i presence_list = findall(!iszero,pi[1:N]) N1 = length(presence_list) absence_list = findall(iszero,pi[1:N]) MatA_i = M[1:N,:]-sparse(Matrix(1.0I, N, N)) pi_list = findall(!isequal(presence_list[1]),[i for i = 1:N]) MatA_i[:,pi_list] = MatA_i[:,pi_list] - MatA_i[:,presence_list[1]]*transpose(pi[pi_list]/pi[presence_list[1]]) MatA_i_reduced = MatA_i[pi_list,pi_list] xi_hat = sum(pi[1:N].*xi[1:N]) MatB_i = (xi_hat*ones(Float64,N)-xi[1:N])*N1 MatB_i_reduced = MatB_i[pi_list] beta_i_solution_reduced = idrs(MatA_i_reduced, MatB_i_reduced) beta_i_solution = zeros(Float64, N) beta_i_solution[pi_list] = beta_i_solution_reduced beta_i_solution[presence_list[1]] = -sum(pi[1:N].*beta_i_solution)/pi[presence_list[1]] # obtain beta_ij Mat1 = M[1:N,:] inds = findall(!iszero,Mat1) a = getindex.(inds, 1) b = getindex.(inds, 2) vec1 = [i for i = 1:N] vec1 = transpose(vec1) X1 = N*(a.-1)*ones(Int64,1,N)+ones(Int64,length(a))*vec1 Y1 = N*(b.-1)*ones(Int64,1,N)+ones(Int64,length(b))*vec1 W1 = Mat1[inds]*ones(Int64,1,N) vec2 = [(i-1)*N for i = 1:N] vec2 = transpose(vec2) X2 = a*ones(Int64,1,N)+ones(Int64,length(a))*vec2 Y2 = b*ones(Int64,1,N)+ones(Int64,length(b))*vec2 W2 = Mat1[inds]*ones(Int64,1,N) X11 = reshape(X1,:,1) Y11 = reshape(Y1,:,1) W11 = reshape(W1,:,1) X22 = reshape(X2,:,1) Y22 = reshape(Y2,:,1) W22 = reshape(W2,:,1) MatA_ij = sparse(X11[:,1],Y11[:,1],W11[:,1],N^2,N^2)/2+sparse(X22[:,1],Y22[:,1],W22[:,1],N^2,N^2)/2 MatA_ij = MatA_ij - sparse(Matrix(1.0I, N*N, N*N)) beta_obtained = [(i-1)*N+i for i = 1:N] beta_missed = setdiff([i for i = 1:N^2], beta_obtained) MatA_ij_reduced = MatA_ij[beta_missed, beta_missed] MatB_ij = -sum(MatA_ij[:,beta_obtained].*transpose(beta_i_solution), dims = 2) Mat = xi_hat*ones(Float64,N,N)*N1/2-xi[1:N]*transpose(xi[1:N])*N1/2 Mat[absence_list,:] = spzeros(Float64,length(absence_list),N) Mat[:,absence_list] = spzeros(Float64,N,length(absence_list)) MatB_ij = MatB_ij+reshape(transpose(Mat),:) MatB_ij_reduced = MatB_ij[beta_missed] beta_ij_solution_reduced = idrs(MatA_ij_reduced, MatB_ij_reduced) beta_ij_solution = zeros(Float64, N*N) beta_ij_solution[beta_missed] = beta_ij_solution_reduced beta_ij_solution[beta_obtained] = beta_i_solution solution = spzeros(Float64, N*N, L) solution[:,1] = beta_ij_solution # obtain gamma_ij if L > 1 for ell = 2:L xi_ell = xi[(ell-1)*N+1:ell*N] pi_ell = pi[(ell-1)*N+1:ell*N] presence_ell = findall(!iszero, pi_ell) N_ell = length(presence_ell) GammaA_ij = sparse(X11[:,1],Y11[:,1],W11[:,1],N^2,N^2)*(N_ell-1)/(N1+N_ell-1) Mat_ell = M[(ell-1)*N+1:ell*N,:] inds_ell = findall(!iszero,Mat_ell) a_ell = getindex.(inds_ell, 1) b_ell = getindex.(inds_ell, 2) vec_ell = [(i-1)*N for i = 1:N] vec_ell = transpose(vec_ell) X_ell = a_ell*ones(Int64,1,N)+ones(Int64,length(a_ell))*vec_ell Y_ell = b_ell*ones(Int64,1,N)+ones(Int64,length(b_ell))*vec_ell W_ell = Mat_ell[inds_ell]*ones(Int64,1,N) X_ellell = reshape(X_ell,:,1) Y_ellell = reshape(Y_ell,:,1) W_ellell = reshape(W_ell,:,1) GammaA_ij = GammaA_ij+sparse(X_ellell[:,1],Y_ellell[:,1],W_ellell[:,1],N^2,N^2)*(N1-1)/(N1+N_ell-1) vec_gamma1 = reshape(ones(Int64, N)*vec1,:) vec_gamma2 = reshape(transpose(vec1)*ones(Int64,1,N),:) X_gamma1 = N*(a.-1)*ones(Int64,1,N*N)+ones(Int64,length(a))*transpose(vec_gamma1) Y_gamma1 = N*(b.-1)*ones(Int64,1,N*N)+ones(Int64,length(b))*transpose(vec_gamma2) W_gamma1 = Mat1[inds]*ones(Int64,1,N*N) vec_gamma3 = [(i-1)*N for i in vec_gamma1] vec_gamma4 = [(i-1)*N for i in vec_gamma2] X_gamma2 = a_ell*ones(Int64,1,N*N)+ones(Int64,length(a_ell))*transpose(vec_gamma3) Y_gamma2 = b_ell*ones(Int64,1,N*N)+ones(Int64,length(b_ell))*transpose(vec_gamma4) W_gamma2 = Mat_ell[inds_ell]*ones(Int64,1,N*N) X_gamma_11 = reshape(X_gamma1,:,1) Y_gamma_11 = reshape(Y_gamma1,:,1) W_gamma_11 = reshape(W_gamma1,:,1) X_gamma_22 = reshape(X_gamma2,:,1) Y_gamma_22 = reshape(Y_gamma2,:,1) W_gamma_22 = reshape(W_gamma2,:,1) GammaA_ij = GammaA_ij + sparse(X_gamma_11[:,1],Y_gamma_11[:,1],W_gamma_11[:,1],N^2,N^2).*sparse(X_gamma_22[:,1],Y_gamma_22[:,1],W_gamma_22[:,1],N^2,N^2)/(N1+N_ell-1) GammaA_ij = GammaA_ij - sparse(Matrix(1.0I, N*N, N*N)) pi_transient = pi[1:N].*pi_ell presence_list = findall(!iszero,pi_transient) absence_list = findall(iszero,pi_transient) GammaA_delete = (presence_list.-1)*N+presence_list GammaA_ij[:,GammaA_delete] = GammaA_ij[:,GammaA_delete] - GammaA_ij[:,GammaA_delete[1]]*transpose(pi[presence_list])/pi[presence_list[1]] pi_list = findall(!isequal(GammaA_delete[1]),[i for i = 1:N*N]) GammaA_ij_reduced = GammaA_ij[pi_list,pi_list] xi_ell_hat = sum(pi_ell.*xi_ell) GammaB_ij = (xi_hat*xi_ell_hat*ones(Float64,N,N) - xi[1:N]*transpose(xi_ell))*N1*N_ell/(N1+N_ell-1) presence1 = findall(iszero, pi[1:N]) presence1 = presence1[:,1] presence_ell = findall(iszero, pi_ell) presence_ell = presence_ell[:,1] GammaB_ij[presence1,:] = spzeros(Float64, length(presence1), N) GammaB_ij[:,presence_ell] = spzeros(Float64, N, length(presence_ell)) GammaB_ij = reshape(transpose(GammaB_ij), :) GammaB_ij_reduced = GammaB_ij[pi_list] gamma_ij_solution_reduced = idrs(GammaA_ij_reduced, GammaB_ij_reduced) gamma_ij_solution = zeros(Float64, N*N) gamma_ij_solution[pi_list] = gamma_ij_solution_reduced gamma_ij_solution[GammaA_delete[1]] = -sum(pi[presence_list].*gamma_ij_solution[GammaA_delete])/pi[presence_list[1]] solution[:,ell] = gamma_ij_solution end end return solution end # provide the value of coefficient of Eq. (2), namely theta and phi # input--- # multilayer network in the form of an edge sequanece: edge_seq [node id, node id, edge weight, layer id] # initial strategy configuration: xi_seq [node id, strategy, layer id] # for an edge between node i and j in layer ll with weight wij_ll, two terms should be added into the edge sequence, i.e. [i j wij_ll ll] and [j i wij_ll ll] # the code here requires wij_ll to be a positive integer # output--- # strategy assortment: theta_phi[:,1] = [theta0, theta1, theta2, theta3], strategy correlation within layer 1 # theta_phi[:,ll] = [phi00, phi01, phi20, phi21], strategy correlation between layer 1 and layer ll # if there are only two layers, in Eq. (2) in the main text, [theta0, theta1, theta2, theta3] = theta_phi[:,1] and [phi00, phi01, phi20, phi21] = theta_phi[:,2] function bc_multilayer_DB(edge_seq::Array{Int64,2}, xi_seq::Array{Int64,2}) edge_seq = edge_seq_rearrangement(edge_seq) solution = beta_gamma(edge_seq, xi_seq) N = maximum(edge_seq[:,1]) L = maximum(edge_seq[:,4]) M = spzeros(Float64,N*L,N) for ell = 1:L edge_list_ell = findall(isequal(ell),edge_seq[:,4]) M_ell = sparse(edge_seq[edge_list_ell,1],edge_seq[edge_list_ell,2],edge_seq[edge_list_ell,3],N,N) M[(ell-1)*N+1:ell*N,:] = M_ell end pi = spzeros(Float64,L*N) for ell = 1:L pi_2 = sum(M[(ell-1)*N+1:ell*N,:], dims = 2) pi_2 = pi_2[:,1] pi_transient = spzeros(Float64, N) presence = findall(!iszero,pi_2) pi_transient[presence] = pi_2[presence]/sum(pi_2) pi[(ell-1)*N+1:ell*N] = pi_transient M_transient = M[(ell-1)*N+1:ell*N,:] M_transient[presence,:] = M_transient[presence,:]./pi_2[presence] M[(ell-1)*N+1:ell*N,:] = M_transient end M1 = M[1:N,:] beta = transpose(reshape(solution[:,1], N, :)) theta1 = sum(pi[1:N].*M1.*beta) M2 = M1*M1 theta2 = sum(pi[1:N].*M2.*beta) M3 = M2*M1 theta3 = sum(pi[1:N].*M3.*beta) theta_phi = zeros(Float64, 4, L) theta_phi[:,1] = [0.0,theta1,theta2,theta3] if L > 1 for ell = 2:L gamma = transpose(reshape(solution[:,ell], N, :)) M_ell = M[(ell-1)*N+1:ell*N,:] phi01 = sum(pi[1:N].*M_ell.*gamma) phi20 = sum(pi[1:N].*M2.*gamma) M_ell21 = M2*M_ell phi21 = sum(pi[1:N].*M_ell21.*gamma) theta_phi[:,ell] = [0,phi01,phi20,phi21] end end return theta_phi end # an example about the using of above functions # see Fig. 5A in the main text, where nodes are labelled and initial strategy configuration is presented in SFig. 2 # the edge sequence is given in the form [node id, node id, edge weight, layer id] edge_seq = [1 6 1 1; 2 6 1 1; 3 6 1 1; 4 6 1 1; 5 6 1 1; 6 1 1 1; 6 2 1 1; 6 3 1 1; 6 4 1 1; 6 5 1 1; 1 2 1 2; 1 3 1 2; 1 4 1 2; 1 5 1 2; 1 6 1 2; 2 1 1 2; 3 1 1 2; 4 1 1 2; 5 1 1 2; 6 1 1 2] # the strategy configuration is given in the form [node id, strategy, layer id] xi_seq = [1 1 1; 2 0 1; 3 0 1; 4 0 1; 5 0 1; 6 0 1; 1 0 2; 2 0 2; 3 0 2; 4 0 2; 5 0 2; 6 1 2] # see Eq.(2) in the main text # theta_phi[:,1] = [theta0, theta1, theta2, theta3], strategy correlation within layer 1 # theta_phi[:,2] = [phi00, phi01, phi20, phi21], strategy correlation between layer 1 and layer 2 theta_phi = bc_multilayer_DB(edge_seq, xi_seq)