Zulip Chat Archive

Stream: mathlib4

Topic: Random decidability assumption


Patrick Massot (Aug 08 2024 at 14:47):

I’d be grateful if someone can help me explain in MIL why docs#DirectSum.toModule needs decidable equality on the indexing type but docs#DirectSum.linearEquivFunOnFintype doesn’t.

Patrick Massot (Aug 08 2024 at 14:48):

And also why we have this Fintype version but seemingly no Finite version.

Eric Wieser (Aug 08 2024 at 14:50):

Why would we want both a finite version and a fintype version?

Eric Wieser (Aug 08 2024 at 14:51):

(I claim that at least that shouldn't be a general principle; we'd end up needing two different multiplications on Matrix, one for Finite and one for Fintype)

Patrick Massot (Aug 08 2024 at 14:52):

Because Finite is much nicer?

Patrick Massot (Aug 08 2024 at 14:53):

I mean I wouldn’t mind getting rid of the Fintype version.

Eric Wieser (Aug 08 2024 at 14:54):

I think the decidable equality might be accidental, since the docstring for docs#DFinsupp.sumAddHom says no decidable assumption is needed, and indeed docs3#dfinsupp.sum_add_hom does not have that assumption

Eric Wieser (Aug 08 2024 at 14:54):

That is, this looks like a misfiring variable inclusion

Patrick Massot (Aug 08 2024 at 14:54):

I won’t insist on the Fintype vs Finite thing. Right now I am only trying to get a consistent story to explain in my new MIL chapter.

Patrick Massot (Aug 08 2024 at 14:55):

I’ll try to open a Mathlib PR fixing this accidental assumption (unless you would prefer to do it).

Eric Wieser (Aug 08 2024 at 14:55):

In retrospect, I think it's talking about a different decidability assumption

Eric Wieser (Aug 08 2024 at 14:56):

Yes, the reason that assumption is needed is that DFinsupp stores a multiset of its support, and so to sum over the support you need to first deduplicate

Eric Wieser (Aug 08 2024 at 14:57):

So I think the fix here is perhaps just an explanation in the docstrings

Eric Wieser (Aug 08 2024 at 14:58):

Meanwhile, DirectSum.linearEquivFunOnFintype does not need to sum over the support, as it knows that it can just use the underlying function directly; so no decidable equality is needed

Patrick Massot (Aug 08 2024 at 15:13):

Ok, I guess I will stick to my “Note that the direct sum notation is scoped to the DirectSum namespace, and that the universal property of direct sums requires decidable equality on the indexing type (this is somehow an implementation accident).”

Eric Wieser (Aug 08 2024 at 15:40):

I might be biased, but I think decidable equality on the index type is a totally reasonable thing to require in general, and in fact its absence in some functions is more the implementation detail. Using the multivariate polynomial analogy, I think assuming an algorithm to tell the variable names apart is valid except possibly in the case of bad handwriting on a blackboard.

Eric Wieser (Aug 08 2024 at 15:41):

I guess the other way you could spin it is that to mathematicians, Decidable is always an implementation detail

Kevin Buzzard (Aug 08 2024 at 16:10):

Yes, decidability is not taught in mathematics departments and is universally found confusing by my students (as is noncomputability). The less of it we have, the better, in my opinion!

Yury G. Kudryashov (Aug 08 2024 at 18:48):

About decidability: I have a linter in #10235 that detects unneeded Decidable*/Fintype/Encodable assumptions. It needs some work to avoid false positives (most come from structures) and some nolints, but I have no time to finish it.

Edward van de Meent (Aug 08 2024 at 19:07):

what exactly is the accepted practice with regards to these kinds of assumptions?

Edward van de Meent (Aug 08 2024 at 19:11):

i'm not very acquainted with writing linters, but i get the impression that the linter wants you to replace all Decidable parameters with uses of classical? but surely that's not right?

Edward van de Meent (Aug 08 2024 at 19:12):

i thought the whole point of using Decidable instances is so you don't have to assume classical?

Yury G. Kudryashov (Aug 08 2024 at 19:34):

The linter enforces the following rule: if you don't need Decidable to formulate a theorem, then don't use it.

Yury G. Kudryashov (Aug 08 2024 at 19:35):

For definitions, if you don't need Decidable to generate data, then don't use it.

Yury G. Kudryashov (Aug 08 2024 at 19:35):

So, it allows Decidable used to generate data but bans non-classical proofs (several exceptions will be added before we merge it).

Edward van de Meent (Aug 08 2024 at 19:36):

why is the decision being made to ban non-classical proofs?

Yury G. Kudryashov (Aug 08 2024 at 19:38):

Because we decided to focus on classical math to make it easier for mathematicians.

Yury G. Kudryashov (Aug 08 2024 at 19:40):

Non-classical proofs are tolerated (especially if @Mario Carneiro will PR his @[allowed_axioms] attribute and mark lemmas that are supposed to stay non-classical), but most of the library uses Decidable only if it's required for data.

Edward van de Meent (Aug 08 2024 at 19:41):

in what contexts will non-classical proofs be allowed?

Yury G. Kudryashov (Aug 08 2024 at 19:44):

E.g., Mario formalized something about Turing machines, and one of the points in his paper was that the proof didn't depend on Clasical.choice. If a theorem already relies on Classical.choice (e.g., anything in topology/analysis), then it makes no sense to make the proof "a bit less" classical.

Yury G. Kudryashov (Aug 08 2024 at 19:45):

There are no formal rules for exceptions, but the idea is that in Coq you need to justify why you use classical reasoning, while in Mathlib you need to justify why you avoid it.

Edward van de Meent (Aug 08 2024 at 19:53):

so there's no real reason why, just "because"?

Edward van de Meent (Aug 08 2024 at 19:58):

to be clear, i do think it makes sense that if dependencies of a theorem already use classical, it's ok to continue to do so... it just strikes me as odd that that is used to justify forcing any proof to do so

Eric Wieser (Aug 08 2024 at 19:58):

Yury G. Kudryashov said:

For definitions, if you don't need Decidable to generate data, then don't use it.

In Patrick's original example, we do need this instance to (computably) generate the data.

Kevin Buzzard said:

The less of it we have, the better, in my opinion!

I don't think we should be making things noncomputable just to avoid confusing students, because this can often just create more work for tactic writing, cripple #eval for quick tests (which confuses other students), and prevents kernel reduction (which breaks decide). There are ways to reduce confusion without removing it!

Eric Wieser (Aug 08 2024 at 20:01):

Do you think we can somehow get a "docstring for mathematicians" at docs#DecidableEq ? I can see this being contentious from the FRO's perspective since not all users are mathematicians. Was there any progress towards docstring extension by downstream packages?

Patrick Massot (Aug 08 2024 at 21:11):

Eric Wieser said:

I don't think we should be making things noncomputable just to avoid confusing students, because this can often just create more work for tactic writing, cripple #eval for quick tests (which confuses other students), and prevents kernel reduction (which breaks decide). There are ways to reduce confusion without removing it!

This is not only confusing students, this is confusing professional mathematicians. Crippling #eval confuses students only if you tell students about #eval, which I never did, and I would be surprised if Kevin did. Do you know any proof in Mathlib that actually benefits from those DecidableEq? I am not saying we must get rid of them, but I am far from convinced by your arguments.

Yury G. Kudryashov (Aug 08 2024 at 21:16):

One setting where computability matters is functions about Nat, especially those used in norm_num and other tactic.

Yury G. Kudryashov (Aug 08 2024 at 21:16):

This may include docs#Nat.factorization, hence bits of Finsupp.

Patrick Massot (Aug 08 2024 at 21:21):

I am talking about direct sums of modules here, not computability in general.

Eric Wieser (Aug 08 2024 at 21:27):

I have numerous threads on Zulip (admittedly not in mathlib), where I use direct sums to build computable polynomials in about 20 lines. This depends on decidability, and I think enables rfl for some trivial statements

Eric Wieser (Aug 08 2024 at 21:31):

Patrick Massot said:

Do you know any proof in Mathlib that actually benefits from those DecidableEq?

Speculating for now, I would expect this to be convenient for working with the graded structure of Exterior algebra, since otherwise you end up with a classical decidable instance for Nat when selecting a single element from DirectSum.of

Patrick Massot (Aug 08 2024 at 21:34):

By the way docs#DirectSum.of and docs#DirectSum.lof are also embarassing to explain in succession given the way they disagree on implicitness of arguments.

Patrick Massot (Aug 08 2024 at 21:39):

Maybe the explicit indexing type in the second one is a typo.

Eric Wieser (Aug 08 2024 at 21:47):

I suspect it's there due to elaboration issues; if you want the linear map version, then probably you're not applying it to i and so need to pass the type I instead

Eric Wieser (Aug 08 2024 at 21:48):

Oh, I guess the same is true for the AddMonoidHom, so this is inconsistent however you look at it

Eric Wieser (Aug 08 2024 at 21:49):

In the past I suggested making of a plain unbundled function. Would that be worse in your opinion?

Patrick Massot (Aug 08 2024 at 22:05):

It is definitely inconsistent. And you don’t need to apply it to infer I, it is already given by M (or β).

Kim Morrison (Aug 08 2024 at 23:17):

Edward van de Meent said:

so there's no real reason why, just "because"?

@Edward van de Meent, there's definitely a real reason, which is that nearly all mathematicians (one can of course quibble of what that means) don't care at all (or know!) about decidability, and the decision to have Mathlib be as classical as possible was intentional, and I think highly successful, in making Mathlib appealing and useful to these users.

It is easy to find many people who've looked at other theorem provers libraries and essentially immediately dismissed them as being "about" constructivism or intuitionism or ..., rather than about "mathematics". Preferring classical reasoning in Mathlib is a direct response to this.

Kim Morrison (Aug 08 2024 at 23:18):

We're well aware this makes some people sad, and at the margins are willing to accommodate, but not on the core principle that Mathlib is intended to be primarily classical.


Last updated: May 02 2025 at 03:31 UTC