Zulip Chat Archive

Stream: Is there code for X?

Topic: Can't infer nontrivial ℝ


Winston Yin (Aug 31 2022 at 18:41):

Just started exploring the analysis part of mathlib. Why can't Lean infer the instance nontrivial ℝ? How would you prove this?

example (r : ) (hr : 0 < r) : 0 < r / 2 :=
begin
  rw lt_div_iff zero_lt_two,
  rw zero_mul,
  exact hr,
  apply_instance -- why can't Lean infer nontrivial ℝ?
end

Yaël Dillies (Aug 31 2022 at 18:41):

Can you include imports?

Winston Yin (Aug 31 2022 at 18:41):

(sorry, I meant to post this on #general)

Winston Yin (Aug 31 2022 at 18:42):

import geometry.manifold.mfderiv
import analysis.ODE.picard_lindelof

Winston Yin (Aug 31 2022 at 18:42):

Same behaviour with just:

import analysis.ODE.picard_lindelof

Kyle Miller (Aug 31 2022 at 18:45):

I'm finding that

import analysis.ODE.picard_lindelof

example (r : ) (hr : 0 < r) : 0 < r / 2 :=
begin
  rw lt_div_iff zero_lt_two,
  rw zero_mul,
  exact hr,
  apply_instance
end

works just fine on a recent mathlib

Yaël Dillies (Aug 31 2022 at 18:45):

When you mean "why can't Lean infer nontrivial ℝ?", do you mean "why am I presented this goal?"?

Kyle Miller (Aug 31 2022 at 18:49):

I've never really understood what causes rw to need to introduce instance goals (especially since there are a number of others here that it seems to find just fine), but giving it a hint that the lemma is about the reals helps it out:

example (r : ) (hr : 0 < r) : 0 < r / 2 :=
begin
  rw lt_div_iff (zero_lt_two : (0 : ) < _),
  rw zero_mul,
  exact hr,
end

Yaël Dillies (Aug 31 2022 at 18:54):

This is a recurring problem with the zero_lt_... lemmas, so I'm adding a version with the type explicit in #16172.

Adam Topaz (Aug 31 2022 at 18:58):

linarith also works :)

Yaël Dillies (Aug 31 2022 at 18:59):

Or just docs#half_pos

Adam Topaz (Aug 31 2022 at 18:59):

but who can remember that?!

Yaël Dillies (Aug 31 2022 at 18:59):

Me, in fact :stuck_out_tongue_wink:

Winston Yin (Aug 31 2022 at 19:04):

Yaël Dillies said:

When you mean "why can't Lean infer nontrivial ℝ?", do you mean "why am I presented this goal?"?

Yeah. Why would Lean present me with this goal when apply_instance ends up finding it with no extra steps anyway?

Winston Yin (Aug 31 2022 at 19:05):

In the past when I've seen this behaviour it was because my own lemma included an unnecessary / unused typeclass variable

Adam Topaz (Aug 31 2022 at 19:05):

I think the reason has to do with the internals of how rw fills in metavariables.


Last updated: Dec 20 2023 at 11:08 UTC