Zulip Chat Archive
Stream: mathlib4
Topic: field_simp weirdness
Michael Stoll (Dec 26 2023 at 21:52):
Compare
import Mathlib.Tactic.FieldSimp
variable {F} [Field F]
example (a b c : F) (h : c ≠ 0) (h' : a = b) : -a / c = -c⁻¹ * b := by
  field_simp -- ⊢ a = b
  sorry
with
import Mathlib.Tactic.FieldSimp
import Mathlib.Algebra.Field.Basic -- extra import
variable {F} [Field F]
example (a b c : F) (h : c ≠ 0) (h' : a = b) : -a / c = -c⁻¹ * b := by
  field_simp -- ⊢ a = b ∨ c = 0
  sorry
A possible difference: in the first case #synth NoZeroDivisors F says GroupWithZero.noZeroDivisors, but in the second case, it is IsDomain.to_noZeroDivisors F. Still, it is completely unclear to me how this difference would affect field_simp. In any case, I would think that the second behavior does not conform to specifications.
Yury G. Kudryashov (Dec 27 2023 at 01:59):
Unfortunately, field_simp generates code with lots of "aux" lemmas from other files which makes it harder to inspect it.
Mario Carneiro (Dec 27 2023 at 02:03):
those aux lemmas are from simp, they are eq versions of iff lemmas marked @[simp]
Yury G. Kudryashov (Dec 27 2023 at 02:04):
It looks like with Field.Basic, it multiplies by the denominators, then gets a * c = b * c and simplifies it to a = b ∨ c = 0.
Yury G. Kudryashov (Dec 27 2023 at 02:05):
Without Field.Basic, it goes along a different path because, e.g., docs#neg_div' is not available.
Yury G. Kudryashov (Dec 27 2023 at 02:06):
field_simp [*] solves the goal in both cases.
Michael Stoll (Dec 27 2023 at 10:28):
Maybe field_simp should check whether it "knows" that c ≠ 0 when simplifying a * c = b * c? After all, c ≠ 0 is available in the context in the example above.
Ruben Van de Velde (Dec 27 2023 at 10:34):
That's what field_simp [hc] is for
Michael Stoll (Dec 27 2023 at 10:39):
In the example, c occurs in the denominator, and field_simp uses h from the context without being specifically asked to do so to clear denominators (which is, as far as I understand, the expected behavior). So it is natural to expect that it would continue to use h in later simplification steps. (In particular seeing that it works without the extra import...)
Eric Rodriguez (Dec 27 2023 at 11:54):
I thought field_simp didn't inspect the context unless asked to?
Yury G. Kudryashov (Dec 27 2023 at 15:01):
AFAIR, field_simp uses positivity to discharge side goals.
Yury G. Kudryashov (Dec 27 2023 at 15:02):
So, if c ≠ 0 appears as a side goal, then field_simp can discharge it. However, if c = 0 appears as a part of the simplified goal, then field_simp can't use c ≠ 0 to simplify it.
Ruben Van de Velde (Dec 27 2023 at 15:35):
Aha!
Eric Rodriguez (Dec 27 2023 at 16:45):
Maybe then some lemmas that state assumptions using or should be removed from field simp's default set then!
Eric Rodriguez (Dec 27 2023 at 16:46):
I guess the issue is that sometimes they'll be resolved with or_true if its something like a term that is passed in but not findable by positivity
Eric Rodriguez (Dec 27 2023 at 16:46):
So it'll break a fair few proofs
Last updated: May 02 2025 at 03:31 UTC