Zulip Chat Archive

Stream: Is there code for X?

Topic: A nonzero function does not change sign


Yongxi Lin (Aaron) (Jan 28 2026 at 07:41):

Do we have sth like this in Mathlib?

import Mathlib

lemma constant_sign {f :   } {s : Set } (hs : IsPreconnected s) (hf : ContinuousOn f s)
    (hfx :  x  s, f x  0) : f '' s  Set.Ioi 0  f '' s  Set.Iio 0 :=
  (hs.image f hf).subset_or_subset isOpen_Ioi isOpen_Iio (by grind)
  (by grind : f '' s  Set.Ioi 0  Set.Iio 0)

lemma constant_sign' {f :   } {s : Set } (hs : IsPreconnected s) (hf : ContinuousOn f s)
    (hfx :  x  s, f x  0) : ( x  s, 0 < f x)   x  s, f x < 0 := by
  rcases constant_sign hs hf hfx with (ha | hb)
  · exact Or.inl fun x hx => by simp_all; grind
  · exact Or.inr fun x hx => by simp_all; grind

If not, does it make sense to make a PR for this? I think one use this lemma quite often, but the proof is somewhat short.

Notification Bot (Jan 28 2026 at 07:47):

This topic was moved here from #Is there code for X? > A nonzero function do not change sign by Yongxi Lin (Aaron).

Violeta Hernández (Jan 29 2026 at 16:12):

This should be generalized from 0 to an arbitrary real, but otherwise I don't see a reason not to have it.

Joseph Myers (Jan 29 2026 at 16:42):

Also, arbitrary domain, and arbitrary LinearOrder OrderTopology codomain, I think.

Michael Rothgang (Jan 29 2026 at 18:49):

I have wanted such a result in the past (e.g., in #16553) --- this would be great to have, in the appropriate generality!

Yongxi Lin (Aaron) (Jan 30 2026 at 03:31):

#34596

Yongxi Lin (Aaron) (Jan 30 2026 at 03:33):

Michael Rothgang said:

I have wanted such a result in the past (e.g., in #16553) --- this would be great to have, in the appropriate generality!

Orientation of manifolds is exactly the kind of application I had in mind for this lemma!


Last updated: Feb 28 2026 at 14:05 UTC