def
definition
def or abbrev
add
show as:
view Lean formalization →
formal statement (Lean)
146def add : LogicRat → LogicRat → LogicRat :=
proof body
Definition body.
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)`. -/