1-- Four explicit square directions separate nonzero complex vectors.2-- Part of Cumulus, the Grace17 mathematics library.3-- Copyright (c) 2026 Grant Passmore.4-- Released under the Apache License 2.0. See LICENSE in the repository root.5-- Authors: Grant Passmore67module Grace.Cumulus.Complex.SquareDirections8import PolynomialStationarity910theorem realLe.zero_of_opposite_bounds (a : Real)11requires positive : realZero ≤ a12requires negative : realZero ≤ -a13shows a = realZero14proof15have shifted := realLe.add_right at realZero, -a, a with*16rw realAddValue.zero_left at shifted17have cancel : -a + a = realZero byring18rw cancel at shifted19have lower := realLe.characterization.forward with positive20have upper := realLe.characterization.forward with shifted21exact RealLe.antisymmetric with upper, lower2223section Complexes24notationring ℂ := (complexCarrier, complexAdd, complexZero, complexNeg, complexMul, complexOne)25notationring R := (ℝ, realAdd, realZero, realNeg, realMul, realOne)2627theorem complexDot.square_pair (a b c d x y : Real)28shows Euclidean.dot((a, b), ℂ[((x, y) * (x, y)) * (c, d)]) = R[(x * x - y * y) * (a * c + b * d) + (x * y + y * x) * (b * c - a * d)]29proof30simp [complexMul.pair, Euclidean.dot, Euclidean.x.pair, Euclidean.y.pair]31ring3233theorem complexDot.square_bounds (a b c d : Real)34requires bounds : ∀ u ∈ ℂ, realZero ≤ Euclidean.dot((a, b), ℂ[(u * u) * (c, d)])35shows R[a * c + b * d] = realZero ∧ R[2* (b * c - a * d)] = realZero36proof37have p1 := complexCarrier.pair at realOne, realZero with*38have pi := complexCarrier.pair at realZero, realOne with*39have pp := complexCarrier.pair at realOne, realOne with*40have pm := complexCarrier.pair at realOne, R[-1] with*41have b1 := bounds with (realOne, realZero), p142have bi := bounds with (realZero, realOne), pi43have bp := bounds with (realOne, realOne), pp44have bm := bounds with (realOne, R[-1]), pm45rw complexDot.square_pair at b146rw complexDot.square_pair at bi47rw complexDot.square_pair at bp48rw complexDot.square_pair at bm49have e1 : R[(1*1 - 0*0) * (a * c + b * d) + (1*0+0*1) * (b * c - a * d)] = R[a * c + b * d] byring50have ei : R[(0*0 - 1*1) * (a * c + b * d) + (0*1+1*0) * (b * c - a * d)] = R[-(a * c + b * d)] byring51have ep : R[(1*1 - 1*1) * (a * c + b * d) + (1*1+1*1) * (b * c - a * d)] = R[2* (b * c - a * d)]52ring53have em : R[(1*1 - (-1) * (-1)) * (a * c + b * d) + (1* (-1) + (-1) *1) * (b * c - a * d)] = R[-(2* (b * c - a * d))]54ring55rw e1 at b156rw ei at bi57rw ep at bp58rw em at bm59have first := realLe.zero_of_opposite_bounds at R[a * c + b * d] with*60have second := realLe.zero_of_opposite_bounds at R[2* (b * c - a * d)] with*61refine⟨first, second⟩6263theorem complexDot.square_direction (z w : Set)64requires first : z ∈ ℂ65requires second : w ∈ ℂ66requires nonzeroZ : z ≠ ℂ[0]67requires nonzeroW : w ≠ ℂ[0]68shows∃ u ∈ ℂ, Euclidean.dot(z, ℂ[(u * u) * w]) < realZero69proof70by_contra noDirection71havering:= complexes.comm_ring72have ordinary := IsCommRing.ring withring73have pointZ := complex.point at z with*74have all : ∀ u ∈ ℂ, realZero ≤ Euclidean.dot(z, ℂ[(u * u) * w])75intros u uIn76have square := IsRing.mul_closed with ordinary, uIn, uIn77have product := IsRing.mul_closed with ordinary, square, second78have point := complex.point with product79by_contra notNonnegative80have negative := realLess.of_not_le with*81apply noDirection82refine⟨u, uIn, negative⟩83have positiveZ := complexNormSquared.positive at z with*84have positiveW := complexNormSquared.positive at w with*85have productPositive := realMulValue.positive at complexNormSquared(z), complexNormSquared(w) with*86have twoPositive : (0:R) < 2bylinarith87have fourPositive := realMulValue.positive at R[2], R[2] with*88have positive := realMulValue.positive at R[2*2], R[complexNormSquared(z) * complexNormSquared(w)] with*89obtain⟨a, aReal, b, bReal, zShape⟩:= complexCarrier.cases at z with*90obtain⟨c, cReal, d, dReal, wShape⟩:= complexCarrier.cases at w with*91have coordinateBounds : ∀ u ∈ ℂ, realZero ≤ Euclidean.dot((a, b), ℂ[(u * u) * (c, d)])92intros u uIn93have bound := all with u, uIn94 rwa [zShape, wShape] at bound95obtain⟨vanishes, imaginaryVanishes⟩:= complexDot.square_bounds at a, b, c, d with*96rw [zShape, wShape, complexNormSquared.pair, complexNormSquared.pair] at positive97have identity : R[(2*2) * ((a * a + b * b) * (c * c + d * d))] = R[(2* (a * c + b * d)) * (2* (a * c + b * d)) + (2* (b * c - a * d)) * (2* (b * c - a * d))]98ring99rw [identity, vanishes, imaginaryVanishes] at positive100have zero : R[(2*0) * (2*0) +0*0] = realZero byring101rw zero at positive102have irrefl := realLess.irreflexive_on103exact irrefl with realZero, positive104105theorem complexDot.small_power_direction (z w : Set) (n : Nat)106requires first : z ∈ ℂ107requires second : w ∈ ℂ108requires nonzeroZ : z ≠ ℂ[0]109requires nonzeroW : w ≠ ℂ[0]110requires small : n ≤ (1:N)111shows∃ u ∈ ℂ, Euclidean.dot(z, ℂ[u ^ succ(n) * w]) < realZero112proof113obtain⟨u, uIn, negative⟩:= complexDot.square_direction at z, w with*114havering:= complexes.comm_ring115have ordinary := IsCommRing.ring withring116have square := IsRing.mul_closed with ordinary, uIn, uIn117have shape := natural.zero_or_successor with*118cases shape with zero | successor119 . have power : ℂ[(u * u) ^ succ(n)] = ℂ[u * u]120rw [zero, monoidPow.succ, monoidPow.zero]121ring122refine⟨ℂ[u * u], square, ?_⟩123 rwa power124 . obtain⟨k, kNat, nShape⟩:= successor125rw nShape at small126have upper : k ≤ (0:N) byarith127have lower := Grace.Cumulus.Nat.Order.LessEqual.zero at k with*128have kZero := LessEqual.antisymmetric at k, (0:N) with*129have nOne : n = (1:N)130rw [nShape, kZero]131rfl132have power : ℂ[u ^ succ(n)] = ℂ[u * u]133rw [nOne, monoidPow.succ, monoidPow.succ, monoidPow.zero]134ring135refine⟨u, uIn, ?_⟩136 rwa power137138end Complexes139