Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Complex

Lean: Hale.Base.Complex | Haskell: Data.Complex

Overview

Complex numbers parameterized by coefficient type. Supports arithmetic operations and conjugation.

API Mapping

LeanHaskellKind
ComplexComplexType
re / imrealPart / imagPartAccessor
ofReal(:+ 0)Constructor
i0 :+ 1Constant
conjugateconjugateFunction
magnitudeSquaredmagnitude ^2Function

Instances

  • Inhabited (Complex a) (requires Inhabited a)
  • ToString (Complex a) (requires ToString a)
  • Add (Complex a) (requires Add a)
  • Neg (Complex a) (requires Neg a)
  • Sub (Complex a) (requires Sub a)
  • Mul (Complex a) (requires Add a, Sub a, Mul a)
  • BEq (Complex a) (derived)
  • Ord (Complex a) (derived)
  • Repr (Complex a) (derived)
  • Hashable (Complex a) (derived)

Proofs & Guarantees

  • conjugate_conjugateconjugate (conjugate z) = z (involution)
  • add_comm'z1 + z2 = z2 + z1

Example

-- Compute magnitude squared of 3 + 4i
Complex.magnitudeSquared ⟨3, 4⟩
-- => 25  (since 3^2 + 4^2 = 25)