rocq-prover / rocq-prover/stdlib
Regression: Importing ZArith leads to setoid_rewrite performance degradation
Nobody has claimed this yet.
- Dominant language
- Rocq Prover
- Stars
- 42
- Forks
- 38
- Avg merge
- 14h 6m
- Merged PRs (30d)
- 3
Description
In the following proof, setoid_rewrite works fine on older versions of the stdlib (sometime between 8.20 and 9.0, I think) but it takes over 30 seconds on more recent versions of the standard library. I don't think the rocq version matters but I have tested with master and a snapshot of master from late February.
From Corelib Require Import PrimInt63 Uint63Axioms.
Require Import Corelib.Strings.PrimString.
Require Import Corelib.BinNums.IntDef.
Require Import Corelib.Numbers.BinNums.
From Corelib Require Import Setoid.
From Stdlib Require Import ZArith.
Axiom N_to_nat : N -> nat.
Axiom N_modulo : N -> N -> N.
Axiom N_mod_0_r : forall x, N_modulo x N0 = N0.
Goal forall x,
Init.Nat.min
(IntDef.Z.to_nat (to_Z PrimString.max_length))
(N_to_nat (N_modulo x N0))
= 0%nat.
Proof.
Timeout 1 setoid_rewrite N_mod_0_r.
Abort.
AFAICT the change is related to Znumtheory pulling in libraries like Ncring but I am not 100% sure. A similar slowdown can be seen when importing just Ncring instead of ZArith in the example above. In that case, the slowdown can be fixed by disabling these typeclass instances:
Remove Hints ring_setoid : typeclass_instances.
Remove Hints ring_plus_comp : typeclass_instances.
Remove Hints ring_mult_comp : typeclass_instances.
Remove Hints ring_sub_comp : typeclass_instances.
But this does not suffice to fix the slowdown when importing all of ZArith.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by running the supplied minimal proof with the current Stdlib, then compare the behavior when importing ZArith versus Ncring. Inspect the Znumtheory and Ncring imports and the listed ring typeclass hints, using the Remove Hints example as a diagnostic. Done means the setoid_rewrite proof no longer exceeds the one-second timeout after importing ZArith.
Written by the indexing model from the issue text.
Assessment
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100