pith. machine review for the scientific record. sign in
def

add

definition
show as:
view math explainer →
module
IndisputableMonolith.Foundation.RationalsFromLogic
domain
Foundation
line
146 · github
papers citing
none yet

open explainer

Generate a durable explainer page for this declaration.

open lean source

IndisputableMonolith.Foundation.RationalsFromLogic on GitHub at line 146.

browse module

All declarations in this module, on Recognition.

explainer page

Tracked in the explainer inventory; generation is lazy so crawlers do not trigger LLM jobs.

open explainer

depends on

formal source

 143instance : Neg LogicRat := ⟨neg⟩
 144
 145/-- Addition: `(a/b) + (c/d) = (a*d + c*b) / (b*d)`. -/
 146def add : LogicRat → LogicRat → LogicRat :=
 147  Quotient.lift₂
 148    (fun (p q : PreRat) =>
 149       mk (p.num * q.den + q.num * p.den) (p.den * q.den)
 150         (fun h => p.den_nonzero ((mul_eq_zero.mp h).resolve_right q.den_nonzero)))
 151    (by
 152      rintro ⟨a, b, hb⟩ ⟨c, d, hd⟩ ⟨a', b', hb'⟩ ⟨c', d', hd'⟩ hab hcd
 153      show mk (a * d + c * b) (b * d) _
 154            = mk (a' * d' + c' * b') (b' * d') _
 155      apply sound
 156      show (a * d + c * b) * (b' * d') = (a' * d' + c' * b') * (b * d)
 157      rw [eq_iff_toInt_eq]
 158      simp only [toInt_add, toInt_mul]
 159      have hab' : toInt a * toInt b' = toInt a' * toInt b := by
 160        have := congrArg toInt hab
 161        rwa [toInt_mul, toInt_mul] at this
 162      have hcd' : toInt c * toInt d' = toInt c' * toInt d := by
 163        have := congrArg toInt hcd
 164        rwa [toInt_mul, toInt_mul] at this
 165      linear_combination (toInt d * toInt d') * hab' + (toInt b * toInt b') * hcd')
 166
 167instance : Add LogicRat := ⟨add⟩
 168
 169/-- Multiplication: `(a/b) * (c/d) = (a*c) / (b*d)`. -/
 170def mul : LogicRat → LogicRat → LogicRat :=
 171  Quotient.lift₂
 172    (fun (p q : PreRat) =>
 173       mk (p.num * q.num) (p.den * q.den)
 174         (fun h => p.den_nonzero ((mul_eq_zero.mp h).resolve_right q.den_nonzero)))
 175    (by
 176      rintro ⟨a, b, hb⟩ ⟨c, d, hd⟩ ⟨a', b', hb'⟩ ⟨c', d', hd'⟩ hab hcd