Imports
/- Copyright (c) 2025 Joseph Tooby-Smith. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Joseph Tooby-Smith -/ module public import Mathlib.Analysis.Complex.Basic

Rational complex numbers

@[expose] public section

Rational complex numbers. This type is mainly used when decidability is needed.

The real part of a RatComplexNum.

The imaginary part of a RatComplexNum.

structure RatComplexNum where fst : snd :
@[ext] lemma ext {x y : RatComplexNum} (h1 : x.1 = y.1) (h2 : x.2 = y.2) : x = y := x:RatComplexNumy:RatComplexNumh1:x.fst = y.fsth2:x.snd = y.sndx = y y:RatComplexNumfst✝:snd✝:h1:{ fst := fst✝, snd := snd✝ }.fst = y.fsth2:{ fst := fst✝, snd := snd✝ }.snd = y.snd{ fst := fst✝, snd := snd✝ } = y fst✝¹:snd✝¹:fst✝:snd✝:h1:{ fst := fst✝¹, snd := snd✝¹ }.fst = { fst := fst✝, snd := snd✝ }.fsth2:{ fst := fst✝¹, snd := snd✝¹ }.snd = { fst := fst✝, snd := snd✝ }.snd{ fst := fst✝¹, snd := snd✝¹ } = { fst := fst✝, snd := snd✝ } fst✝¹:snd✝¹:fst✝:snd✝:h1:fst✝¹ = fst✝h2:snd✝¹ = snd✝{ fst := fst✝¹, snd := snd✝¹ } = { fst := fst✝, snd := snd✝ } fst✝:snd✝:{ fst := fst✝, snd := snd✝ } = { fst := fst✝, snd := snd✝ } All goals completed! 🐙

The equivalence as a type of RatComplexNum with ℚ × ℚ.

def equivToProd : RatComplexNum × where toFun := fun x => (x.1, x.2) invFun := fun x => x.1, x.2 left_inv := Function.LeftInverse (fun x => { fst := x.1, snd := x.2 }) fun x => (x.fst, x.snd) x:RatComplexNum(fun x => { fst := x.1, snd := x.2 }) ((fun x => (x.fst, x.snd)) x) = x fst✝:snd✝:(fun x => { fst := x.1, snd := x.2 }) ((fun x => (x.fst, x.snd)) { fst := fst✝, snd := snd✝ }) = { fst := fst✝, snd := snd✝ } All goals completed! 🐙 right_inv := Function.RightInverse (fun x => { fst := x.1, snd := x.2 }) fun x => (x.fst, x.snd) x: × (fun x => (x.fst, x.snd)) ((fun x => { fst := x.1, snd := x.2 }) x) = x fst✝:snd✝:(fun x => (x.fst, x.snd)) ((fun x => { fst := x.1, snd := x.2 }) (fst✝, snd✝)) = (fst✝, snd✝) All goals completed! 🐙
instance : DecidableEq RatComplexNum := Equiv.decidableEq equivToProdinstance : Add RatComplexNum where add := fun x y => x.fst + y.fst, x.snd + y.snd@[simp] lemma add_fst (x y : RatComplexNum) : (x + y).fst = x.fst + y.fst := rfl@[simp] lemma add_snd (x y : RatComplexNum) : (x + y).snd = x.snd + y.snd := rflinstance : AddCommGroup RatComplexNum where add_assoc := (a b c : RatComplexNum), a + b + c = a + (b + c) a:RatComplexNumb:RatComplexNumc:RatComplexNuma + b + c = a + (b + c) a:RatComplexNumb:RatComplexNumc:RatComplexNum(a + b + c).fst = (a + (b + c)).fsta:RatComplexNumb:RatComplexNumc:RatComplexNum(a + b + c).snd = (a + (b + c)).snd a:RatComplexNumb:RatComplexNumc:RatComplexNum(a + b + c).fst = (a + (b + c)).fst a:RatComplexNumb:RatComplexNumc:RatComplexNuma.fst + b.fst + c.fst = a.fst + (b.fst + c.fst) All goals completed! 🐙 a:RatComplexNumb:RatComplexNumc:RatComplexNum(a + b + c).snd = (a + (b + c)).snd a:RatComplexNumb:RatComplexNumc:RatComplexNuma.snd + b.snd + c.snd = a.snd + (b.snd + c.snd) All goals completed! 🐙 zero := 0, 0 zero_add := (a : RatComplexNum), 0 + a = a a:RatComplexNum0 + a = a match a with a:RatComplexNuma1:a2:0 + { fst := a1, snd := a2 } = { fst := a1, snd := a2 } a:RatComplexNuma1:a2:(0 + { fst := a1, snd := a2 }).fst = { fst := a1, snd := a2 }.fsta:RatComplexNuma1:a2:(0 + { fst := a1, snd := a2 }).snd = { fst := a1, snd := a2 }.snd a:RatComplexNuma1:a2:(0 + { fst := a1, snd := a2 }).fst = { fst := a1, snd := a2 }.fst a:RatComplexNuma1:a2:0 + a1 = a1 All goals completed! 🐙 a:RatComplexNuma1:a2:(0 + { fst := a1, snd := a2 }).snd = { fst := a1, snd := a2 }.snd a:RatComplexNuma1:a2:0 + a2 = a2 All goals completed! 🐙 add_zero := (a : RatComplexNum), a + 0 = a a:RatComplexNuma + 0 = a match a with a:RatComplexNuma1:a2:{ fst := a1, snd := a2 } + 0 = { fst := a1, snd := a2 } a:RatComplexNuma1:a2:({ fst := a1, snd := a2 } + 0).fst = { fst := a1, snd := a2 }.fsta:RatComplexNuma1:a2:({ fst := a1, snd := a2 } + 0).snd = { fst := a1, snd := a2 }.snd a:RatComplexNuma1:a2:({ fst := a1, snd := a2 } + 0).fst = { fst := a1, snd := a2 }.fst a:RatComplexNuma1:a2:a1 + 0 = a1 All goals completed! 🐙 a:RatComplexNuma1:a2:({ fst := a1, snd := a2 } + 0).snd = { fst := a1, snd := a2 }.snd a:RatComplexNuma1:a2:a2 + 0 = a2 All goals completed! 🐙 neg := fun x => -x.fst, -x.snd nsmul := fun n x => n x.fst, n x.snd zsmul := fun n x => n x.1, n x.2 neg_add_cancel := (a : RatComplexNum), { fst := -a.fst, snd := -a.snd } + a = 0 a:RatComplexNum{ fst := -a.fst, snd := -a.snd } + a = 0 match a with a:RatComplexNuma1:a2:{ fst := -{ fst := a1, snd := a2 }.fst, snd := -{ fst := a1, snd := a2 }.snd } + { fst := a1, snd := a2 } = 0 a:RatComplexNuma1:a2:({ fst := -{ fst := a1, snd := a2 }.fst, snd := -{ fst := a1, snd := a2 }.snd } + { fst := a1, snd := a2 }).fst = fst 0a:RatComplexNuma1:a2:({ fst := -{ fst := a1, snd := a2 }.fst, snd := -{ fst := a1, snd := a2 }.snd } + { fst := a1, snd := a2 }).snd = snd 0 a:RatComplexNuma1:a2:({ fst := -{ fst := a1, snd := a2 }.fst, snd := -{ fst := a1, snd := a2 }.snd } + { fst := a1, snd := a2 }).fst = fst 0 a:RatComplexNuma1:a2:-a1 + a1 = 0 All goals completed! 🐙 a:RatComplexNuma1:a2:({ fst := -{ fst := a1, snd := a2 }.fst, snd := -{ fst := a1, snd := a2 }.snd } + { fst := a1, snd := a2 }).snd = snd 0 a:RatComplexNuma1:a2:-a2 + a2 = 0 All goals completed! 🐙 add_comm := (a b : RatComplexNum), a + b = b + a x:RatComplexNumy:RatComplexNumx + y = y + x x:RatComplexNumy:RatComplexNum(x + y).fst = (y + x).fstx:RatComplexNumy:RatComplexNum(x + y).snd = (y + x).snd x:RatComplexNumy:RatComplexNum(x + y).fst = (y + x).fst x:RatComplexNumy:RatComplexNumx.fst + y.fst = y.fst + x.fst All goals completed! 🐙 x:RatComplexNumy:RatComplexNum(x + y).snd = (y + x).snd x:RatComplexNumy:RatComplexNumx.snd + y.snd = y.snd + x.snd All goals completed! 🐙 nsmul_zero := (x : RatComplexNum), 0 x = 0 x:RatComplexNum0 x = 0; x:RatComplexNum(0 x).fst = fst 0x:RatComplexNum(0 x).snd = snd 0 x:RatComplexNum(0 x).fst = fst 0x:RatComplexNum(0 x).snd = snd 0 All goals completed! 🐙 nsmul_succ := (n : ) (x : RatComplexNum), (n + 1) x = n x + x n:x:RatComplexNum(n + 1) x = n x + x; n:x:RatComplexNum((n + 1) x).fst = (n x + x).fstn:x:RatComplexNum((n + 1) x).snd = (n x + x).snd n:x:RatComplexNum((n + 1) x).fst = (n x + x).fstn:x:RatComplexNum((n + 1) x).snd = (n x + x).snd All goals completed! 🐙 zsmul_zero' := (a : RatComplexNum), 0 a = 0 a:RatComplexNum0 a = 0; a:RatComplexNum(0 a).fst = fst 0a:RatComplexNum(0 a).snd = snd 0 a:RatComplexNum(0 a).fst = fst 0a:RatComplexNum(0 a).snd = snd 0 All goals completed! 🐙 zsmul_succ' := (n : ) (a : RatComplexNum), n.succ a = n a + a n:a:RatComplexNumn.succ a = n a + a n:a:RatComplexNum(n.succ a).fst = (n a + a).fstn:a:RatComplexNum(n.succ a).snd = (n a + a).snd n:a:RatComplexNum(n.succ a).fst = (n a + a).fst n:a:RatComplexNum(n + 1) a.fst = n a.fst + a.fst All goals completed! 🐙 n:a:RatComplexNum(n.succ a).snd = (n a + a).snd n:a:RatComplexNum(n + 1) a.snd = n a.snd + a.snd All goals completed! 🐙 zsmul_neg' := (n : ) (a : RatComplexNum), Int.negSucc n a = { fst := -(n.succ a).fst, snd := -(n.succ a).snd } n:a:RatComplexNumInt.negSucc n a = { fst := -(n.succ a).fst, snd := -(n.succ a).snd }; n:a:RatComplexNum(Int.negSucc n a).fst = { fst := -(n.succ a).fst, snd := -(n.succ a).snd }.fstn:a:RatComplexNum(Int.negSucc n a).snd = { fst := -(n.succ a).fst, snd := -(n.succ a).snd }.snd n:a:RatComplexNum(Int.negSucc n a).fst = { fst := -(n.succ a).fst, snd := -(n.succ a).snd }.fstn:a:RatComplexNum(Int.negSucc n a).snd = { fst := -(n.succ a).fst, snd := -(n.succ a).snd }.snd All goals completed! 🐙instance : Mul RatComplexNum where mul := fun x y => x.fst * y.fst - x.snd * y.snd, x.fst * y.snd + x.snd * y.fst@[simp] lemma mul_fst (x y : RatComplexNum) : (x * y).fst = x.fst * y.fst - x.snd * y.snd := rfl@[simp] lemma mul_snd (x y : RatComplexNum) : (x * y).snd = x.fst * y.snd + x.snd * y.fst := rflinstance : Ring RatComplexNum where one := 1, 0 mul_assoc := (a b c : RatComplexNum), a * b * c = a * (b * c) x:RatComplexNumy:RatComplexNumz:RatComplexNumx * y * z = x * (y * z) x:RatComplexNumy:RatComplexNumz:RatComplexNum(x * y * z).fst = (x * (y * z)).fstx:RatComplexNumy:RatComplexNumz:RatComplexNum(x * y * z).snd = (x * (y * z)).snd x:RatComplexNumy:RatComplexNumz:RatComplexNum(x * y * z).fst = (x * (y * z)).fst x:RatComplexNumy:RatComplexNumz:RatComplexNum(x.fst * y.fst - x.snd * y.snd) * z.fst - (x.fst * y.snd + x.snd * y.fst) * z.snd = x.fst * (y.fst * z.fst - y.snd * z.snd) - x.snd * (y.fst * z.snd + y.snd * z.fst) All goals completed! 🐙 x:RatComplexNumy:RatComplexNumz:RatComplexNum(x * y * z).snd = (x * (y * z)).snd x:RatComplexNumy:RatComplexNumz:RatComplexNum(x.fst * y.fst - x.snd * y.snd) * z.snd + (x.fst * y.snd + x.snd * y.fst) * z.fst = x.fst * (y.fst * z.snd + y.snd * z.fst) + x.snd * (y.fst * z.fst - y.snd * z.snd) All goals completed! 🐙 one_mul := (a : RatComplexNum), 1 * a = a x:RatComplexNum1 * x = x match x with x:RatComplexNumx1:x2:1 * { fst := x1, snd := x2 } = { fst := x1, snd := x2 } x:RatComplexNumx1:x2:(1 * { fst := x1, snd := x2 }).fst = { fst := x1, snd := x2 }.fstx:RatComplexNumx1:x2:(1 * { fst := x1, snd := x2 }).snd = { fst := x1, snd := x2 }.snd x:RatComplexNumx1:x2:(1 * { fst := x1, snd := x2 }).fst = { fst := x1, snd := x2 }.fst x:RatComplexNumx1:x2:1 * x1 - 0 * x2 = x1 All goals completed! 🐙 x:RatComplexNumx1:x2:(1 * { fst := x1, snd := x2 }).snd = { fst := x1, snd := x2 }.snd x:RatComplexNumx1:x2:1 * x2 + 0 * x1 = x2 All goals completed! 🐙 mul_one := (a : RatComplexNum), a * 1 = a x:RatComplexNumx * 1 = x match x with x:RatComplexNumx1:x2:{ fst := x1, snd := x2 } * 1 = { fst := x1, snd := x2 } x:RatComplexNumx1:x2:({ fst := x1, snd := x2 } * 1).fst = { fst := x1, snd := x2 }.fstx:RatComplexNumx1:x2:({ fst := x1, snd := x2 } * 1).snd = { fst := x1, snd := x2 }.snd x:RatComplexNumx1:x2:({ fst := x1, snd := x2 } * 1).fst = { fst := x1, snd := x2 }.fst x:RatComplexNumx1:x2:x1 * 1 - x2 * 0 = x1 All goals completed! 🐙 x:RatComplexNumx1:x2:({ fst := x1, snd := x2 } * 1).snd = { fst := x1, snd := x2 }.snd x:RatComplexNumx1:x2:x1 * 0 + x2 * 1 = x2 All goals completed! 🐙 left_distrib := (a b c : RatComplexNum), a * (b + c) = a * b + a * c a:RatComplexNumb:RatComplexNumc:RatComplexNuma * (b + c) = a * b + a * c match a, b, c with a:RatComplexNumb:RatComplexNumc:RatComplexNuma1:a2:b1:b2:c1:c2:{ fst := a1, snd := a2 } * ({ fst := b1, snd := b2 } + { fst := c1, snd := c2 }) = { fst := a1, snd := a2 } * { fst := b1, snd := b2 } + { fst := a1, snd := a2 } * { fst := c1, snd := c2 } a:RatComplexNumb:RatComplexNumc:RatComplexNuma1:a2:b1:b2:c1:c2:({ fst := a1, snd := a2 } * ({ fst := b1, snd := b2 } + { fst := c1, snd := c2 })).fst = ({ fst := a1, snd := a2 } * { fst := b1, snd := b2 } + { fst := a1, snd := a2 } * { fst := c1, snd := c2 }).fsta:RatComplexNumb:RatComplexNumc:RatComplexNuma1:a2:b1:b2:c1:c2:({ fst := a1, snd := a2 } * ({ fst := b1, snd := b2 } + { fst := c1, snd := c2 })).snd = ({ fst := a1, snd := a2 } * { fst := b1, snd := b2 } + { fst := a1, snd := a2 } * { fst := c1, snd := c2 }).snd a:RatComplexNumb:RatComplexNumc:RatComplexNuma1:a2:b1:b2:c1:c2:({ fst := a1, snd := a2 } * ({ fst := b1, snd := b2 } + { fst := c1, snd := c2 })).fst = ({ fst := a1, snd := a2 } * { fst := b1, snd := b2 } + { fst := a1, snd := a2 } * { fst := c1, snd := c2 }).fst a:RatComplexNumb:RatComplexNumc:RatComplexNuma1:a2:b1:b2:c1:c2:a1 * (b1 + c1) - a2 * (b2 + c2) = a1 * b1 - a2 * b2 + (a1 * c1 - a2 * c2) All goals completed! 🐙 a:RatComplexNumb:RatComplexNumc:RatComplexNuma1:a2:b1:b2:c1:c2:({ fst := a1, snd := a2 } * ({ fst := b1, snd := b2 } + { fst := c1, snd := c2 })).snd = ({ fst := a1, snd := a2 } * { fst := b1, snd := b2 } + { fst := a1, snd := a2 } * { fst := c1, snd := c2 }).snd a:RatComplexNumb:RatComplexNumc:RatComplexNuma1:a2:b1:b2:c1:c2:a1 * (b2 + c2) + a2 * (b1 + c1) = a1 * b2 + a2 * b1 + (a1 * c2 + a2 * c1) All goals completed! 🐙 right_distrib := (a b c : RatComplexNum), (a + b) * c = a * c + b * c a:RatComplexNumb:RatComplexNumc:RatComplexNum(a + b) * c = a * c + b * c match a, b, c with a:RatComplexNumb:RatComplexNumc:RatComplexNumb1:b2:c1:c2:a1:a2:({ fst := b1, snd := b2 } + { fst := c1, snd := c2 }) * { fst := a1, snd := a2 } = { fst := b1, snd := b2 } * { fst := a1, snd := a2 } + { fst := c1, snd := c2 } * { fst := a1, snd := a2 } a:RatComplexNumb:RatComplexNumc:RatComplexNumb1:b2:c1:c2:a1:a2:(({ fst := b1, snd := b2 } + { fst := c1, snd := c2 }) * { fst := a1, snd := a2 }).fst = ({ fst := b1, snd := b2 } * { fst := a1, snd := a2 } + { fst := c1, snd := c2 } * { fst := a1, snd := a2 }).fsta:RatComplexNumb:RatComplexNumc:RatComplexNumb1:b2:c1:c2:a1:a2:(({ fst := b1, snd := b2 } + { fst := c1, snd := c2 }) * { fst := a1, snd := a2 }).snd = ({ fst := b1, snd := b2 } * { fst := a1, snd := a2 } + { fst := c1, snd := c2 } * { fst := a1, snd := a2 }).snd a:RatComplexNumb:RatComplexNumc:RatComplexNumb1:b2:c1:c2:a1:a2:(({ fst := b1, snd := b2 } + { fst := c1, snd := c2 }) * { fst := a1, snd := a2 }).fst = ({ fst := b1, snd := b2 } * { fst := a1, snd := a2 } + { fst := c1, snd := c2 } * { fst := a1, snd := a2 }).fst a:RatComplexNumb:RatComplexNumc:RatComplexNumb1:b2:c1:c2:a1:a2:(b1 + c1) * a1 - (b2 + c2) * a2 = b1 * a1 - b2 * a2 + (c1 * a1 - c2 * a2) All goals completed! 🐙 a:RatComplexNumb:RatComplexNumc:RatComplexNumb1:b2:c1:c2:a1:a2:(({ fst := b1, snd := b2 } + { fst := c1, snd := c2 }) * { fst := a1, snd := a2 }).snd = ({ fst := b1, snd := b2 } * { fst := a1, snd := a2 } + { fst := c1, snd := c2 } * { fst := a1, snd := a2 }).snd a:RatComplexNumb:RatComplexNumc:RatComplexNumb1:b2:c1:c2:a1:a2:(b1 + c1) * a2 + (b2 + c2) * a1 = b1 * a2 + b2 * a1 + (c1 * a2 + c2 * a1) All goals completed! 🐙 zero_mul := (a : RatComplexNum), 0 * a = 0 a:RatComplexNum0 * a = 0 match a with a:RatComplexNuma1:a2:0 * { fst := a1, snd := a2 } = 0 a:RatComplexNuma1:a2:(0 * { fst := a1, snd := a2 }).fst = fst 0a:RatComplexNuma1:a2:(0 * { fst := a1, snd := a2 }).snd = snd 0 a:RatComplexNuma1:a2:(0 * { fst := a1, snd := a2 }).fst = fst 0 a:RatComplexNuma1:a2:0 * a1 - 0 * a2 = 0 All goals completed! 🐙 a:RatComplexNuma1:a2:(0 * { fst := a1, snd := a2 }).snd = snd 0 a:RatComplexNuma1:a2:0 * a2 + 0 * a1 = 0 All goals completed! 🐙 mul_zero := (a : RatComplexNum), a * 0 = 0 a:RatComplexNuma * 0 = 0 match a with a:RatComplexNuma1:a2:{ fst := a1, snd := a2 } * 0 = 0 a:RatComplexNuma1:a2:({ fst := a1, snd := a2 } * 0).fst = fst 0a:RatComplexNuma1:a2:({ fst := a1, snd := a2 } * 0).snd = snd 0 a:RatComplexNuma1:a2:({ fst := a1, snd := a2 } * 0).fst = fst 0 a:RatComplexNuma1:a2:a1 * 0 - a2 * 0 = 0 All goals completed! 🐙 a:RatComplexNuma1:a2:({ fst := a1, snd := a2 } * 0).snd = snd 0 a:RatComplexNuma1:a2:a1 * 0 + a2 * 0 = 0 All goals completed! 🐙 neg_add_cancel := (a : RatComplexNum), -a + a = 0 a:RatComplexNum-a + a = 0 match a with a:RatComplexNuma1:a2:-{ fst := a1, snd := a2 } + { fst := a1, snd := a2 } = 0 a:RatComplexNuma1:a2:(-{ fst := a1, snd := a2 } + { fst := a1, snd := a2 }).fst = fst 0a:RatComplexNuma1:a2:(-{ fst := a1, snd := a2 } + { fst := a1, snd := a2 }).snd = snd 0 a:RatComplexNuma1:a2:(-{ fst := a1, snd := a2 } + { fst := a1, snd := a2 }).fst = fst 0 a:RatComplexNuma1:a2:-a1 + a1 = 0 All goals completed! 🐙 a:RatComplexNuma1:a2:(-{ fst := a1, snd := a2 } + { fst := a1, snd := a2 }).snd = snd 0 a:RatComplexNuma1:a2:-a2 + a2 = 0 All goals completed! 🐙@[simp] lemma one_fst : (1 : RatComplexNum).fst = 1 := rfl@[simp] lemma one_snd : (1 : RatComplexNum).snd = 0 := rfl@[simp] lemma zero_fst : (0 : RatComplexNum).fst = 0 := rfl@[simp] lemma zero_snd : (0 : RatComplexNum).snd = 0 := rfl@[simp] lemma I_mul_toComplexNum (a : RatComplexNum) : I * toComplexNum a = toComplexNum (0, 1 * a) := a:RatComplexNumI * toComplexNum a = toComplexNum ({ fst := 0, snd := 1 } * a) a:RatComplexNumI * (a.fst + a.snd * I) = -a.snd + a.fst * I a:RatComplexNumI * a.fst + I ^ 2 * a.snd = I * a.fst - a.snd a:RatComplexNumI * a.fst + -a.snd = I * a.fst - a.snd All goals completed! 🐙lemma ofNat_mul_toComplexNum (n : ) (a : RatComplexNum) : n * toComplexNum a = toComplexNum (n * a) := n:a:RatComplexNumn * toComplexNum a = toComplexNum (n * a) All goals completed! 🐙a:RatComplexNumb:RatComplexNumha:(a.fst + a.snd * I).re = (b.fst + b.snd * I).re (a.fst + a.snd * I).im = (b.fst + b.snd * I).ima = b a:RatComplexNumb:RatComplexNumha:a.fst = b.fst a.snd = b.snda = b a:RatComplexNumb:RatComplexNumha:a.fst = b.fst a.snd = b.snda.fst = b.fsta:RatComplexNumb:RatComplexNumha:a.fst = b.fst a.snd = b.snda.snd = b.snd a:RatComplexNumb:RatComplexNumha:a.fst = b.fst a.snd = b.snda.fst = b.fst All goals completed! 🐙 a:RatComplexNumb:RatComplexNumha:a.fst = b.fst a.snd = b.snda.snd = b.snd All goals completed! 🐙