Zulip Chat Archive

Stream: general

Topic: Semiring mul_add


Iocta (Jun 27 2024 at 02:37):

What do I mean here?

import Mathlib
example {α : Type} [sr : Semiring α] (a x y : α): sr.mul a (sr.add x y) = sr.add (sr.mul a x) (sr.mul a y) := by
  sorry

Yury G. Kudryashov (Jun 27 2024 at 05:33):

Why do you use projections instead of notation? And what do you mean by your question?

Iocta (Jun 27 2024 at 05:57):

Why do you use projections instead of notation?

If I want to pass sr's mul operation into a function like map, how can I do it other than naming sr.mul? List.map (*) doesn't seem to work.

Iocta (Jun 27 2024 at 05:58):

And what do you mean by your question?

I thought simp [mul_add] would work, but it doesn't.

Daniel Weber (Jun 27 2024 at 06:59):

Iocta said:

Why do you use projections instead of notation?

If I want to pass sr's mul operation into a function like map, how can I do it other than naming sr.mul? List.map (*) doesn't seem to work.

def a : List Nat := [1, 2, 3]

#eval a.map (2 * ·)
-- [2, 4, 6]

Daniel Weber (Jun 27 2024 at 07:00):

example {α : Type} [sr : Semiring α] (a x y : α) :
    sr.mul a (sr.add x y) = sr.add (sr.mul a x) (sr.mul a y) := mul_add a x y

Iocta (Jun 27 2024 at 07:07):

What about this case, where it's inside a function?

example {α : Type} [Semiring α] (a x y : α): (fun x y => Mul.mul a (Add.add x y)) = (fun q r => Add.add (Mul.mul a x) (Mul.mul a y)) := by
  sorry

Eric Wieser (Jun 27 2024 at 07:16):

Again, you should not use Mul.mul and Add.add there

Kevin Buzzard (Jun 27 2024 at 07:19):

import Mathlib.Tactic

example {α : Type} [Semiring α] (a : α):
    (fun x y => a * (x + y)) = (fun q r => a * q + a * r) := by
  ext
  rw [mul_add]

(fixing the q,r error, using the usual notation)


Last updated: May 02 2025 at 03:31 UTC