Skip to content

Commit

Permalink
feat: golf using module/match_scalars throughout the library (#17365
Browse files Browse the repository at this point in the history
)

50 sample uses of the new (#16593) `module` and `match_scalars` tactics.
  • Loading branch information
hrmacbeth committed Oct 3, 2024
1 parent 4f0309f commit fa42460
Show file tree
Hide file tree
Showing 18 changed files with 118 additions and 163 deletions.
10 changes: 5 additions & 5 deletions Mathlib/Algebra/Polynomial/Module/Basic.lean
Original file line number Diff line number Diff line change
Expand Up @@ -276,8 +276,7 @@ theorem eval_smul (p : R[X]) (q : PolynomialModule R M) (r : R) :
intro i m
induction p using Polynomial.induction_on' with
| h_add _ _ e₁ e₂ => rw [add_smul, map_add, Polynomial.eval_add, e₁, e₂, add_smul]
| h_monomial => rw [monomial_smul_single, eval_single, Polynomial.eval_monomial, eval_single,
smul_comm, ← smul_smul, pow_add, mul_smul]
| h_monomial => simp only [monomial_smul_single, Polynomial.eval_monomial, eval_single]; module

@[simp]
theorem eval_map (f : M →ₗ[R] M') (q : PolynomialModule R M) (r : R) :
Expand All @@ -287,7 +286,8 @@ theorem eval_map (f : M →ₗ[R] M') (q : PolynomialModule R M) (r : R) :
· intro f g e₁ e₂
simp_rw [map_add, e₁, e₂]
· intro i m
rw [map_single, eval_single, eval_single, f.map_smul, ← map_pow, algebraMap_smul]
simp only [map_single, eval_single, f.map_smul]
module

@[simp]
theorem eval_map' (f : M →ₗ[R] M) (q : PolynomialModule R M) (r : R) :
Expand Down Expand Up @@ -324,8 +324,8 @@ theorem comp_eval (p : R[X]) (q : PolynomialModule R M) (r : R) :
· intro _ _ e₁ e₂
simp_rw [map_add, e₁, e₂]
· intro i m
rw [LinearMap.comp_apply, comp_single, eval_single, eval_smul, eval_single, pow_zero, one_smul,
Polynomial.eval_pow]
rw [LinearMap.comp_apply, comp_single, eval_single, eval_smul, eval_single, eval_pow]
module

theorem comp_smul (p p' : R[X]) (q : PolynomialModule R M) :
comp p (p' • q) = p'.comp p • comp p q := by
Expand Down
8 changes: 4 additions & 4 deletions Mathlib/Analysis/Analytic/Meromorphic.lean
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ lemma smul {f : 𝕜 → 𝕜} {g : 𝕜 → E} {x : 𝕜} (hf : MeromorphicAt f
rcases hg with ⟨n, hg⟩
refine ⟨m + n, ?_⟩
convert hf.smul hg using 2 with z
rw [smul_eq_mul, ← mul_smul, mul_assoc, mul_comm (f z), ← mul_assoc, pow_add,
← smul_eq_mul (a' := f z), smul_assoc, Pi.smul_apply']
rw [Pi.smul_apply', smul_eq_mul]
module

lemma mul {f g : 𝕜 → 𝕜} {x : 𝕜} (hf : MeromorphicAt f x) (hg : MeromorphicAt g x) :
MeromorphicAt (f * g) x :=
Expand Down Expand Up @@ -227,8 +227,8 @@ lemma iff_eventuallyEq_zpow_smul_analyticAt {f : 𝕜 → E} {x : 𝕜} : Meromo
∃ (n : ℤ) (g : 𝕜 → E), AnalyticAt 𝕜 g x ∧ ∀ᶠ z in 𝓝[≠] x, f z = (z - x) ^ n • g z := by
refine ⟨fun ⟨n, hn⟩ ↦ ⟨-n, _, ⟨hn, eventually_nhdsWithin_iff.mpr ?_⟩⟩, ?_⟩
· filter_upwards with z hz
rw [← mul_smul, ← zpow_natCast, ← zpow_add₀ (sub_ne_zero.mpr hz), neg_add_cancel,
zpow_zero, one_smul]
match_scalars
field_simp [sub_ne_zero.mpr hz]
· refine fun ⟨n, g, hg_an, hg_eq⟩ ↦ MeromorphicAt.congr ?_ (EventuallyEq.symm hg_eq)
exact (((MeromorphicAt.id x).sub (.const _ x)).zpow _).smul hg_an.meromorphicAt

Expand Down
57 changes: 21 additions & 36 deletions Mathlib/Analysis/Calculus/FDeriv/Symmetric.lean
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,8 @@ theorem Convex.taylor_approx_two_segment {v w : E} (hv : x + v ∈ interior s)
rw [← smul_smul]
apply s_conv.interior.add_smul_mem this _ ht
rw [add_assoc] at hw
rw [add_assoc, ← smul_add]
exact s_conv.add_smul_mem_interior xs hw ⟨hpos, h_lt_1.le⟩
convert s_conv.add_smul_mem_interior xs hw ⟨hpos, h_lt_1.le⟩ using 1
module
-- define a function `g` on `[0,1]` (identified with `[v, v + w]`) such that `g 1 - g 0` is the
-- quantity to be estimated. We will check that its derivative is given by an explicit
-- expression `g'`, that we can bound. Then the desired bound for `g 1 - g 0` follows from the
Expand Down Expand Up @@ -139,14 +139,14 @@ theorem Convex.taylor_approx_two_segment {v w : E} (hv : x + v ∈ interior s)
calc
‖g' t‖ = ‖(f' (x + h • v + (t * h) • w) - f' x - f'' (h • v + (t * h) • w)) (h • w)‖ := by
rw [hg']
have : h * (t * h) = t * (h * h) := by ring
simp only [ContinuousLinearMap.coe_sub', ContinuousLinearMap.map_add, pow_two,
ContinuousLinearMap.add_apply, Pi.smul_apply, smul_sub, smul_add, smul_smul, ← sub_sub,
ContinuousLinearMap.coe_smul', Pi.sub_apply, ContinuousLinearMap.map_smul, this]
congrm ‖?_‖
simp only [ContinuousLinearMap.sub_apply, ContinuousLinearMap.add_apply,
ContinuousLinearMap.smul_apply, map_add, map_smul]
module
_ ≤ ‖f' (x + h • v + (t * h) • w) - f' x - f'' (h • v + (t * h) • w)‖ * ‖h • w‖ :=
(ContinuousLinearMap.le_opNorm _ _)
_ ≤ ε * ‖h • v + (t * h) • w‖ * ‖h • w‖ := by
apply mul_le_mul_of_nonneg_right _ (norm_nonneg _)
gcongr
have H : x + h • v + (t * h) • w ∈ Metric.ball x δ ∩ interior s := by
refine ⟨?_, xt_mem t ⟨ht.1, ht.2.le⟩⟩
rw [add_assoc, add_mem_ball_iff_norm]
Expand All @@ -157,7 +157,7 @@ theorem Convex.taylor_approx_two_segment {v w : E} (hv : x + v ∈ interior s)
apply (norm_add_le _ _).trans
gcongr
simp only [norm_smul, Real.norm_eq_abs, abs_mul, abs_of_nonneg, ht.1, hpos.le, mul_assoc]
exact mul_le_of_le_one_left (mul_nonneg hpos.le (norm_nonneg _)) ht.2.le
exact mul_le_of_le_one_left (by positivity) ht.2.le
_ = ε * ((‖v‖ + ‖w‖) * ‖w‖) * h ^ 2 := by
simp only [norm_smul, Real.norm_eq_abs, abs_mul, abs_of_nonneg, hpos.le]; ring
-- conclude using the mean value inequality
Expand All @@ -169,8 +169,8 @@ theorem Convex.taylor_approx_two_segment {v w : E} (hv : x + v ∈ interior s)
simp only [g, Nat.one_ne_zero, add_zero, one_mul, zero_div, zero_mul, sub_zero,
zero_smul, Ne, not_false_iff, zero_pow, reduceCtorEq]
abel
· simp only [Real.norm_eq_abs, abs_mul, add_nonneg (norm_nonneg v) (norm_nonneg w), abs_of_nonneg,
hpos.le, mul_assoc, norm_nonneg, abs_pow]
· simp (discharger := positivity) only [Real.norm_eq_abs, abs_mul, abs_of_nonneg, abs_pow]
ring

/-- One can get `f'' v w` as the limit of `h ^ (-2)` times the alternate sum of the values of `f`
along the vertices of a quadrilateral with sides `h v` and `h w` based at `x`.
Expand All @@ -183,40 +183,27 @@ theorem Convex.isLittleO_alternate_sum_square {v w : E} (h4v : x + (4 : ℝ) •
fun h => h ^ 2 := by
have A : (1 : ℝ) / 2 ∈ Ioc (0 : ℝ) 1 := ⟨by norm_num, by norm_num⟩
have B : (1 : ℝ) / 2 ∈ Icc (0 : ℝ) 1 := ⟨by norm_num, by norm_num⟩
have C : ∀ w : E, (2 : ℝ) • w = 2 • w := fun w => by simp only [two_smul]
have h2v2w : x + (2 : ℝ) • v + (2 : ℝ) • w ∈ interior s := by
convert s_conv.interior.add_smul_sub_mem h4v h4w B using 1
simp only [smul_sub, smul_smul, one_div, add_sub_add_left_eq_sub, mul_add, add_smul]
norm_num
simp only [show (4 : ℝ) = (2 : ℝ) + (2 : ℝ) by norm_num, _root_.add_smul]
abel
module
have h2vww : x + (2 • v + w) + w ∈ interior s := by
convert h2v2w using 1
simp only [two_smul]
abel
module
have h2v : x + (2 : ℝ) • v ∈ interior s := by
convert s_conv.add_smul_sub_mem_interior xs h4v A using 1
simp only [smul_smul, one_div, add_sub_cancel_left, add_right_inj]
norm_num
module
have h2w : x + (2 : ℝ) • w ∈ interior s := by
convert s_conv.add_smul_sub_mem_interior xs h4w A using 1
simp only [smul_smul, one_div, add_sub_cancel_left, add_right_inj]
norm_num
module
have hvw : x + (v + w) ∈ interior s := by
convert s_conv.add_smul_sub_mem_interior xs h2v2w A using 1
simp only [smul_smul, one_div, add_sub_cancel_left, add_right_inj, smul_add, smul_sub]
norm_num
abel
module
have h2vw : x + (2 • v + w) ∈ interior s := by
convert s_conv.interior.add_smul_sub_mem h2v h2v2w B using 1
simp only [smul_add, smul_sub, smul_smul, ← C]
norm_num
abel
module
have hvww : x + (v + w) + w ∈ interior s := by
convert s_conv.interior.add_smul_sub_mem h2w h2v2w B using 1
rw [one_div, add_sub_add_right_eq_sub, add_sub_cancel_left, inv_smul_smul₀ two_ne_zero,
two_smul]
abel
module
have TA1 := s_conv.taylor_approx_two_segment hf xs hx h2vw h2vww
have TA2 := s_conv.taylor_approx_two_segment hf xs hx hvw hvww
convert TA1.sub TA2 using 1
Expand Down Expand Up @@ -245,11 +232,9 @@ theorem Convex.second_derivative_within_at_symmetric_of_mem_interior {v w : E}
apply C.congr' _ _
· filter_upwards [self_mem_nhdsWithin]
intro h (hpos : 0 < h)
rw [← one_smul ℝ (f'' w v - f'' v w), smul_smul, smul_smul]
congr 1
field_simp [LT.lt.ne' hpos]
match_scalars <;> field_simp
· filter_upwards [self_mem_nhdsWithin] with h (hpos : 0 < h)
field_simp [LT.lt.ne' hpos, SMul.smul]
field_simp
simpa only [sub_eq_zero] using isLittleO_const_const_iff.1 B

end
Expand Down Expand Up @@ -298,8 +283,8 @@ theorem Convex.second_derivative_within_at_symmetric {s : Set E} (s_conv : Conve
s_conv.second_derivative_within_at_symmetric_of_mem_interior hf xs hx (ts w) (ts v)
simp only [ContinuousLinearMap.map_add, ContinuousLinearMap.map_smul, smul_add, smul_smul,
ContinuousLinearMap.add_apply, Pi.smul_apply, ContinuousLinearMap.coe_smul', C] at this
rw [add_assoc, add_assoc, add_right_inj, add_left_comm, add_right_inj, add_right_inj, mul_comm]
at this
have : (t v * t w) • (f'' v) w = (t v * t w) • (f'' w) v := by
linear_combination (norm := module) this
apply smul_right_injective F _ this
simp [(tpos v).ne', (tpos w).ne']

Expand Down
4 changes: 2 additions & 2 deletions Mathlib/Analysis/Calculus/UniformLimitsDeriv.lean
Original file line number Diff line number Diff line change
Expand Up @@ -356,8 +356,8 @@ theorem hasFDerivAt_of_tendstoUniformlyOnFilter [NeBot l]
apply ((this ε hε).filter_mono curry_le_prod).mono
intro n hn
rw [dist_eq_norm] at hn ⊢
rw [← smul_sub] at hn
rwa [sub_zero]
convert hn using 2
module
· -- (Almost) the definition of the derivatives
rw [Metric.tendsto_nhds]
intro ε hε
Expand Down
14 changes: 7 additions & 7 deletions Mathlib/Analysis/Convex/Basic.lean
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import Mathlib.Algebra.Order.Module.OrderedSMul
import Mathlib.Algebra.Order.Module.Synonym
import Mathlib.Analysis.Convex.Star
import Mathlib.LinearAlgebra.AffineSpace.AffineSubspace
import Mathlib.Tactic.FieldSimp
import Mathlib.Tactic.NoncommRing

/-!
# Convex sets and functions in vector spaces
Expand Down Expand Up @@ -158,8 +160,7 @@ theorem convex_segment (x y : E) : Convex 𝕜 [x -[𝕜] y] := by
⟨a * ap + b * aq, a * bp + b * bq, add_nonneg (mul_nonneg ha hap) (mul_nonneg hb haq),
add_nonneg (mul_nonneg ha hbp) (mul_nonneg hb hbq), ?_, ?_⟩
· rw [add_add_add_comm, ← mul_add, ← mul_add, habp, habq, mul_one, mul_one, hab]
· simp_rw [add_smul, mul_smul, smul_add]
exact add_add_add_comm _ _ _ _
· match_scalars <;> noncomm_ring

theorem Convex.linear_image (hs : Convex 𝕜 s) (f : E →ₗ[𝕜] F) : Convex 𝕜 (f '' s) := by
rintro _ ⟨x, hx, rfl⟩ _ ⟨y, hy, rfl⟩ a b ha hb hab
Expand Down Expand Up @@ -406,8 +407,8 @@ theorem convex_openSegment (a b : E) : Convex 𝕜 (openSegment 𝕜 a b) := by
rw [convex_iff_openSegment_subset]
rintro p ⟨ap, bp, hap, hbp, habp, rfl⟩ q ⟨aq, bq, haq, hbq, habq, rfl⟩ z ⟨a, b, ha, hb, hab, rfl⟩
refine ⟨a * ap + b * aq, a * bp + b * bq, by positivity, by positivity, ?_, ?_⟩
· rw [add_add_add_comm, ← mul_add, ← mul_add, habp, habq, mul_one, mul_one, hab]
· simp_rw [add_smul, mul_smul, smul_add, add_add_add_comm]
· linear_combination (norm := noncomm_ring) a * habp + b * habq + hab
· module

end StrictOrderedCommSemiring

Expand All @@ -425,8 +426,7 @@ theorem convex_vadd (a : E) : Convex 𝕜 (a +ᵥ s) ↔ Convex 𝕜 s :=

theorem Convex.add_smul_mem (hs : Convex 𝕜 s) {x y : E} (hx : x ∈ s) (hy : x + y ∈ s) {t : 𝕜}
(ht : t ∈ Icc (0 : 𝕜) 1) : x + t • y ∈ s := by
have h : x + t • y = (1 - t) • x + t • (x + y) := by
rw [smul_add, ← add_assoc, ← add_smul, sub_add_cancel, one_smul]
have h : x + t • y = (1 - t) • x + t • (x + y) := by match_scalars <;> noncomm_ring
rw [h]
exact hs hx hy (sub_nonneg_of_le ht.2) ht.1 (sub_add_cancel _ _)

Expand Down Expand Up @@ -515,7 +515,7 @@ theorem Convex.exists_mem_add_smul_eq (h : Convex 𝕜 s) {x y : E} {p q : 𝕜}
· replace hpq : 0 < p + q :=
(add_nonneg hp hq).lt_of_ne' (mt (add_eq_zero_iff_of_nonneg hp hq).1 hpq)
refine ⟨_, convex_iff_div.1 h hx hy hp hq hpq, ?_⟩
simp only [smul_add, smul_smul, mul_div_cancel₀ _ hpq.ne']
match_scalars <;> field_simp

theorem Convex.add_smul (h_conv : Convex 𝕜 s) {p q : 𝕜} (hp : 0 ≤ p) (hq : 0 ≤ q) :
(p + q) • s = p • s + q • s := (add_smul_subset _ _ _).antisymm <| by
Expand Down
7 changes: 5 additions & 2 deletions Mathlib/Analysis/Convex/Combination.lean
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ theorem Finset.centerMass_empty : (∅ : Finset ι).centerMass w z = 0 := by

theorem Finset.centerMass_pair (hne : i ≠ j) :
({i, j} : Finset ι).centerMass w z = (w i / (w i + w j)) • z i + (w j / (w i + w j)) • z j := by
simp only [centerMass, sum_pair hne, smul_add, (mul_smul _ _ _).symm, div_eq_inv_mul]
simp only [centerMass, sum_pair hne]
module

variable {w}

Expand All @@ -63,7 +64,9 @@ theorem Finset.centerMass_insert (ha : i ∉ t) (hw : ∑ j ∈ t, w j ≠ 0) :
rw [div_mul_eq_mul_div, mul_inv_cancel₀ hw, one_div]

theorem Finset.centerMass_singleton (hw : w i ≠ 0) : ({i} : Finset ι).centerMass w z = z i := by
rw [centerMass, sum_singleton, sum_singleton, ← mul_smul, inv_mul_cancel₀ hw, one_smul]
rw [centerMass, sum_singleton, sum_singleton]
match_scalars
field_simp

@[simp] lemma Finset.centerMass_neg_left : t.centerMass (-w) z = t.centerMass w z := by
simp [centerMass, inv_neg]
Expand Down
7 changes: 3 additions & 4 deletions Mathlib/Analysis/Convex/Jensen.lean
Original file line number Diff line number Diff line change
Expand Up @@ -118,11 +118,10 @@ lemma StrictConvexOn.map_sum_lt (hf : StrictConvexOn 𝕜 s f) (h₀ : ∀ i ∈
have := h₀ k <| by simp
let c := w j + w k
have hc : w j / c + w k / c = 1 := by field_simp
have hcj : c * (w j / c) = w j := by field_simp
have hck : c * (w k / c) = w k := by field_simp
calc f (w j • p j + (w k • p k + ∑ x ∈ u, w x • p x))
_ = f (c • ((w j / c) • p j + (w k / c) • p k) + ∑ x ∈ u, w x • p x) := by
rw [smul_add, ← mul_smul, ← mul_smul, hcj, hck, add_assoc]
congrm f ?_
match_scalars <;> field_simp
_ ≤ c • f ((w j / c) • p j + (w k / c) • p k) + ∑ x ∈ u, w x • f (p x) :=
-- apply the usual Jensen's inequality wrt the weighted average of the two distinguished
-- points and all the other points
Expand All @@ -134,7 +133,7 @@ lemma StrictConvexOn.map_sum_lt (hf : StrictConvexOn 𝕜 s f) (h₀ : ∀ i ∈
-- then apply the definition of strict convexity for the two distinguished points
gcongr; refine hf.2 (hmem _ <| by simp) (hmem _ <| by simp) hjk ?_ ?_ hc <;> positivity
_ = (w j • f (p j) + w k • f (p k)) + ∑ x ∈ u, w x • f (p x) := by
rw [smul_add, ← mul_smul, ← mul_smul, hcj, hck]
match_scalars <;> field_simp
_ = w j • f (p j) + (w k • f (p k) + ∑ x ∈ u, w x • f (p x)) := by abel_nf

/-- Concave **strict Jensen inequality**.
Expand Down
22 changes: 8 additions & 14 deletions Mathlib/Analysis/Convex/Join.lean
Original file line number Diff line number Diff line change
Expand Up @@ -113,19 +113,13 @@ theorem convexJoin_assoc_aux (s t u : Set E) :
rintro _ ⟨z, ⟨x, hx, y, hy, a₁, b₁, ha₁, hb₁, hab₁, rfl⟩, z, hz, a₂, b₂, ha₂, hb₂, hab₂, rfl⟩
obtain rfl | hb₂ := hb₂.eq_or_lt
· refine ⟨x, hx, y, ⟨y, hy, z, hz, left_mem_segment 𝕜 _ _⟩, a₁, b₁, ha₁, hb₁, hab₁, ?_⟩
rw [add_zero] at hab₂
rw [hab₂, one_smul, zero_smul, add_zero]
have ha₂b₁ : 0 ≤ a₂ * b₁ := mul_nonneg ha₂ hb₁
have hab : 0 < a₂ * b₁ + b₂ := add_pos_of_nonneg_of_pos ha₂b₁ hb₂
linear_combination (norm := module) congr(-$hab₂ • (a₁ • x + b₁ • y))
refine
⟨x, hx, (a₂ * b₁ / (a₂ * b₁ + b₂)) • y + (b₂ / (a₂ * b₁ + b₂)) • z,
⟨y, hy, z, hz, _, _, ?_, ?_, ?_, rfl⟩,
a₂ * a₁, a₂ * b₁ + b₂, mul_nonneg ha₂ ha₁, hab.le, ?_, ?_⟩
· exact div_nonneg ha₂b₁ hab.le
· exact div_nonneg hb₂.le hab.le
· rw [← add_div, div_self hab.ne']
· rw [← add_assoc, ← mul_add, hab₁, mul_one, hab₂]
· simp_rw [smul_add, ← mul_smul, mul_div_cancel₀ _ hab.ne', add_assoc]
⟨y, hy, z, hz, _, _, by positivity, by positivity, by field_simp, rfl⟩,
a₂ * a₁, a₂ * b₁ + b₂, by positivity, by positivity, ?_, ?_⟩
· linear_combination a₂ * hab₁ + hab₂
· match_scalars <;> field_simp

theorem convexJoin_assoc (s t u : Set E) :
convexJoin 𝕜 (convexJoin 𝕜 s t) u = convexJoin 𝕜 s (convexJoin 𝕜 t u) := by
Expand Down Expand Up @@ -155,9 +149,9 @@ protected theorem Convex.convexJoin (hs : Convex 𝕜 s) (ht : Convex 𝕜 t) :
rcases hs.exists_mem_add_smul_eq hx₁ hx₂ (mul_nonneg hp ha₁) (mul_nonneg hq ha₂) with ⟨x, hxs, hx⟩
rcases ht.exists_mem_add_smul_eq hy₁ hy₂ (mul_nonneg hp hb₁) (mul_nonneg hq hb₂) with ⟨y, hyt, hy⟩
refine ⟨_, hxs, _, hyt, p * a₁ + q * a₂, p * b₁ + q * b₂, ?_, ?_, ?_, ?_⟩ <;> try positivity
· rwa [add_add_add_comm, ← mul_add, ← mul_add, hab₁, hab₂, mul_one, mul_one]
· rw [hx, hy, add_add_add_comm]
simp only [smul_add, smul_smul]
· linear_combination p * hab₁ + q * hab₂ + hpq
· rw [hx, hy]
module

protected theorem Convex.convexHull_union (hs : Convex 𝕜 s) (ht : Convex 𝕜 t) (hs₀ : s.Nonempty)
(ht₀ : t.Nonempty) : convexHull 𝕜 (s ∪ t) = convexJoin 𝕜 s t :=
Expand Down
23 changes: 9 additions & 14 deletions Mathlib/Analysis/Convex/Side.lean
Original file line number Diff line number Diff line change
Expand Up @@ -333,12 +333,8 @@ theorem _root_.Wbtw.wOppSide₁₃ {s : AffineSubspace R P} {x y z : P} (h : Wbt
rcases ht0.lt_or_eq with (ht0' | rfl); swap
· rw [lineMap_apply_zero]; simp
refine Or.inr (Or.inr ⟨1 - t, t, sub_pos.2 ht1', ht0', ?_⟩)
-- TODO: after lean4#2336 "simp made no progress feature"
-- had to add `_` to several lemmas here. Not sure why!
simp_rw [lineMap_apply _, vadd_vsub_assoc _, vsub_vadd_eq_vsub_sub _,
← neg_vsub_eq_vsub_rev z x, vsub_self _, zero_sub, ← neg_one_smul R (z -ᵥ x),
← add_smul, smul_neg, ← neg_smul, smul_smul]
ring_nf
rw [lineMap_apply, vadd_vsub_assoc, vsub_vadd_eq_vsub_sub, ← neg_vsub_eq_vsub_rev z, vsub_self]
module

theorem _root_.Wbtw.wOppSide₃₁ {s : AffineSubspace R P} {x y z : P} (h : Wbtw R x y z)
(hy : y ∈ s) : s.WOppSide z x :=
Expand Down Expand Up @@ -411,9 +407,9 @@ theorem wOppSide_iff_exists_left {s : AffineSubspace R P} {x y p₁ : P} (h : p
exact SameRay.zero_right _
· refine Or.inr ⟨(-r₁ / r₂) • (p₁ -ᵥ p₁') +ᵥ p₂', s.smul_vsub_vadd_mem _ h hp₁' hp₂',
Or.inr (Or.inr ⟨r₁, r₂, hr₁, hr₂, ?_⟩)⟩
rw [vadd_vsub_assoc, smul_add, ← hr, smul_smul, neg_div, mul_neg,
mul_div_cancel₀ _ hr₂.ne.symm, neg_smul, neg_add_eq_sub, ← smul_sub,
vsub_sub_vsub_cancel_right]
rw [vadd_vsub_assoc, ← vsub_sub_vsub_cancel_right x p₁ p₁']
linear_combination (norm := match_scalars <;> field_simp) hr
ring
· rintro (h' | ⟨h₁, h₂, h₃⟩)
· exact wOppSide_of_left_mem y h'
· exact ⟨p₁, h, h₁, h₂, h₃⟩
Expand Down Expand Up @@ -584,15 +580,14 @@ theorem wOppSide_iff_exists_wbtw {s : AffineSubspace R P} {x y : P} :
· refine ⟨lineMap x y (r₂ / (r₁ + r₂)), ?_, ?_⟩
· have : (r₂ / (r₁ + r₂)) • (y -ᵥ p₂ + (p₂ -ᵥ p₁) - (x -ᵥ p₁)) + (x -ᵥ p₁) =
(r₂ / (r₁ + r₂)) • (p₂ -ᵥ p₁) := by
rw [add_comm (y -ᵥ p₂), smul_sub, smul_add, add_sub_assoc, add_assoc, add_right_eq_self,
div_eq_inv_mul, ← neg_vsub_eq_vsub_rev, smul_neg, ← smul_smul, ← h, smul_smul, ← neg_smul,
← sub_smul, ← div_eq_inv_mul, ← div_eq_inv_mul, ← neg_div, ← sub_div, sub_eq_add_neg,
← neg_add, neg_div, div_self (Left.add_pos hr₁ hr₂).ne.symm, neg_one_smul, neg_add_cancel]
rw [← neg_vsub_eq_vsub_rev p₂ y]
linear_combination (norm := match_scalars <;> field_simp) congr((r₁ + r₂)⁻¹ • $h)
ring
rw [lineMap_apply, ← vsub_vadd x p₁, ← vsub_vadd y p₂, vsub_vadd_eq_vsub_sub, vadd_vsub_assoc,
← vadd_assoc, vadd_eq_add, this]
exact s.smul_vsub_vadd_mem (r₂ / (r₁ + r₂)) hp₂ hp₁ hp₁
· exact Set.mem_image_of_mem _
div_nonneg hr₂.le (Left.add_pos hr₁ hr₂).le,
by positivity,
div_le_one_of_le (le_add_of_nonneg_left hr₁.le) (Left.add_pos hr₁ hr₂).le⟩

theorem SOppSide.exists_sbtw {s : AffineSubspace R P} {x y : P} (h : s.SOppSide x y) :
Expand Down
Loading

0 comments on commit fa42460

Please sign in to comment.