1-- Squared complex modulus and its Euclidean geometry, without square roots (ZF).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.Norm8import Field9import Geometry.Plane1011theorem complex.point (z : Set)12requires member : z ∈ complexCarrier13shows Euclidean.Point(z)14proof15obtain⟨a, aReal, b, bReal, coordinates⟩:= complexCarrier.cases at z with*16rw coordinates17exact Euclidean.pair.point with*1819theorem complex.of_point (z : Euclidean.Point)20shows z ∈ complexCarrier21proof22have coordinates := Euclidean.coordinates at z with*23rw coordinates24exact complexCarrier.pair with*2526def complexNormSquared (z : Euclidean.Point) : Real:= Euclidean.normSquared(z)2728theorem complexNormSquared.real (z : Set)29requires member : z ∈ complexCarrier30showsReal(complexNormSquared(z))31proof32have point := complex.point with*33unfold complexNormSquared34exact Euclidean.normSquared.real with*3536theorem complexNormSquared.pair (a b : Real)37shows complexNormSquared((a, b)) = a * a + b * b38proof39have horizontal := Euclidean.x.pair at a, b with*40have vertical := Euclidean.y.pair at a, b with*41simp [complexNormSquared, Euclidean.normSquared, Euclidean.dot]4243theorem complexNormSquared.nonnegative (z : Set)44requires member : z ∈ complexCarrier45shows0≤ complexNormSquared(z)46proof47have point := complex.point with*48unfold complexNormSquared49exact Euclidean.normSquared.nonnegative with*5051theorem complexNormSquared.zero_iff (z : Set)52requires member : z ∈ complexCarrier53shows complexNormSquared(z) =0↔ z = complexZero54proof55obtain⟨a, aReal, b, bReal, coordinates⟩:= complexCarrier.cases at z with*56have norm := complexNormSquared.pair at a, b with*57have vanishing := complex.norm_zero_iff at a, b with*58rw [coordinates, norm]59constructor60 . intro zeroNorm61have parts := vanishing.forward with zeroNorm62unfold complexZero63cc64 . intro zeroPoint65unfold complexZero at zeroPoint66have parts := orderedPair.injective with zeroPoint67rw [parts.left, parts.right]68ring6970theorem complexNormSquared.positive (z : Set)71requires member : z ∈ complexCarrier72requires nonzero : z ≠ complexZero73shows0 < complexNormSquared(z)74proof75have nonnegative := complexNormSquared.nonnegative with*76have nonvanishing : complexNormSquared(z) ≠077intro zeroNorm78have zeroPoint := complexNormSquared.zero_iff.forward with*79exact nonzero with zeroPoint80exactReal.positive_of_nonnegative_of_ne_zero with*8182section Arithmetic83notationring ℂ := (complexCarrier, complexAdd, complexZero, complexNeg, complexMul, complexOne)84notationring R := (ℝ, realAdd, realZero, realNeg, realMul, realOne)8586theorem complexNormSquared.zero87shows complexNormSquared(ℂ[0]) = R[0]88proof89unfold complexZero90rw complexNormSquared.pair91ring9293theorem complexNormSquared.one94shows complexNormSquared(ℂ[1]) = R[1]95proof96unfold complexOne97rw complexNormSquared.pair98ring99100theorem complexNormSquared.mul (z w : Set)101requires first : z ∈ ℂ102requires second : w ∈ ℂ103shows complexNormSquared(ℂ[z * w]) = R[complexNormSquared(z) * complexNormSquared(w)]104proof105obtain⟨a, aReal, b, bReal, zPair⟩:= complexCarrier.cases at z with*106obtain⟨c, cReal, d, dReal, wPair⟩:= complexCarrier.cases at w with*107rw [zPair, wPair, complexMul.pair, complexNormSquared.pair, complexNormSquared.pair, complexNormSquared.pair]108ring109110theorem complexNormSquared.neg (z : Set)111requires member : z ∈ ℂ112shows complexNormSquared(ℂ[-z]) = complexNormSquared(z)113proof114obtain⟨a, aReal, b, bReal, coordinates⟩:= complexCarrier.cases at z with*115rw [coordinates, complexNeg.pair, complexNormSquared.pair, complexNormSquared.pair]116ring117118theorem complexNormSquared.parallelogram (z w : Set)119requires first : z ∈ ℂ120requires second : w ∈ ℂ121shows R[complexNormSquared(ℂ[z + w]) + complexNormSquared(ℂ[z - w])] = R[2* (complexNormSquared(z) + complexNormSquared(w))]122proof123obtain⟨a, aReal, b, bReal, zPair⟩:= complexCarrier.cases at z with*124obtain⟨c, cReal, d, dReal, wPair⟩:= complexCarrier.cases at w with*125rw [zPair, wPair]126simp [complexAdd.pair, complexNeg.pair, complexNormSquared.pair]127ring128129theorem complexNormSquared.add_bound (z w : Set)130requires first : z ∈ ℂ131requires second : w ∈ ℂ132shows complexNormSquared(ℂ[z + w]) ≤ R[2* (complexNormSquared(z) + complexNormSquared(w))]133proof134have field := complexes.is_field135havering:= IsField.comm_ring with field136have ordinary := IsCommRing.ring withring137have negated := IsRing.neg_closed with ordinary, second138have difference := IsRing.add_closed with ordinary, first, negated139have sum := IsRing.add_closed with ordinary, first, second140have nonnegative := complexNormSquared.nonnegative with difference141have identity := complexNormSquared.parallelogram with first, second142have bound := realLe.add_left at realZero, complexNormSquared(ℂ[z - w]), complexNormSquared(ℂ[z + w]) with*143 rwa [realAddValue.zero_right, identity] at bound144145theorem complexNormSquared.perturbation (z w : Set)146requires first : z ∈ ℂ147requires second : w ∈ ℂ148shows complexNormSquared(ℂ[z + w]) = R[complexNormSquared(z) +2* Euclidean.dot(z, w) + complexNormSquared(w)]149proof150obtain⟨a, aReal, b, bReal, zPair⟩:= complexCarrier.cases at z with*151obtain⟨c, cReal, d, dReal, wPair⟩:= complexCarrier.cases at w with*152rw [zPair, wPair]153simp [complexAdd.pair, complexNormSquared.pair, Euclidean.dot, Euclidean.x.pair, Euclidean.y.pair]154ring155156theorem complexNormSquared.strict_descent (z w : Set)157requires first : z ∈ ℂ158requires second : w ∈ ℂ159requires descent : R[2* Euclidean.dot(z, w) + complexNormSquared(w)] < R[0]160shows complexNormSquared(ℂ[z + w]) < complexNormSquared(z)161proof162have pointZ := complex.point at z with*163have pointW := complex.point at w with*164have decreasing := realLess.add_left at R[2* Euclidean.dot(z, w) + complexNormSquared(w)], realZero, complexNormSquared(z) with*165have identity := complexNormSquared.perturbation at z, w with*166have regroup : complexNormSquared(ℂ[z + w]) = R[complexNormSquared(z) + (2* Euclidean.dot(z, w) + complexNormSquared(w))]167rw identity168ring169 rwa [← regroup, realAddValue.zero_right] at decreasing170171end Arithmetic172