Zulip Chat Archive

Stream: new members

Topic: Decasting and distributing to simplify


Shadman Sakib (Aug 27 2021 at 15:58):

import data.complex.basic

open complex

example (a b: ) : 2 * (-(a : ) - (1 / 2) + (b - (1 / 2)) * I) = -2 * a - 1 + 2 * b * I - I :=
begin
  sorry,
end

Shadman Sakib (Aug 27 2021 at 15:59):

How can I decast the 1/2 to simply use ring to prove the goal?

Kyle Miller (Aug 27 2021 at 16:09):

Do you intend for that to be 1 / 2 using integer division? The norm_num tactic will reduce each 1 / 2 to 0 (and I think it's not true unless they're both an actual one-half).

Adam Topaz (Aug 27 2021 at 16:12):

The general strategy for such things:

import data.complex.basic

open complex

example (a b: ) : 2 * (-(a : ) - (1 / 2) + (b - (1 / 2)) * I) = -2 * a - 1 + 2 * b * I - I :=
begin
  field_simp,
  ring,
end

Adam Topaz (Aug 27 2021 at 16:12):

(Note I removed the coercions.

Kyle Miller (Aug 27 2021 at 16:13):

Illustrating the problem:

example : ((1 / 2 : ) : ) = (0 : ) := rfl

Shadman Sakib (Aug 27 2021 at 16:22):

No the 1/2 should be coerced, but I didn't know (1 / 2 : ℤ) : ℂ) = (0 : ℂ)

Shadman Sakib (Aug 27 2021 at 16:23):

Thank you for your help

Johan Commelin (Aug 27 2021 at 16:23):

Should it be coerced from the rationals to C\mathbb C?

Kyle Miller (Aug 27 2021 at 16:27):

Because in that case, this works:

example (a b: ) : 2 * (-(a : ) - (1 / 2 : ) + (b - (1 / 2 : )) * I) = -2 * a - 1 + 2 * b * I - I :=
begin
  field_simp,
  ring,
end

Kyle Miller (Aug 27 2021 at 16:30):

I tend to find the way type ascriptions work to be somewhat counter-intuitive (though it has a logic to it). Since division has type a -> a -> a, by saying you want the result to be a rational, it causes 1 and 2 to be a rational as well. They say casting goes "outside-in".

Adam Topaz (Aug 27 2021 at 17:40):

You're subtracting 1/2 from something that lean knows is a complex number, so lean should know to coerce it to a complex number without any additional arrows


Last updated: Dec 20 2023 at 11:08 UTC