lean4-htt/src/Init/Omega
Leonardo de Moura 3bd39ed8b6
perf: a isDefEq friendly Fin.sub (#4421)
The performance issue at #4413 is due to our `Fin.sub` definition.
```
def sub : Fin n → Fin n → Fin n
  | ⟨a, h⟩, ⟨b, _⟩ => ⟨(a + (n - b)) % n, mlt h⟩
```
Thus, the following runs out of stack space
```
example (a : UInt64) : a - 1 = a :=
  rfl
```
at the `isDefEq` test
```
(a.val.val + 18446744073709551615) % 18446744073709551616 =?= a.val.val
```

From the user's perspective, this timeout is unexpected since they are
using small numerals, and none of the other `Fin` basic operations (such
as `Fin.add` and `Fin.mul`) suffer from this problem.

This PR implements an inelegant solution for the performance issue. It
redefines `Fin.sub` as
```
def sub : Fin n → Fin n → Fin n
  | ⟨a, h⟩, ⟨b, _⟩ => ⟨((n - b) + a) % n, mlt h⟩
```
This approach is unattractive because it relies on the fact that
`Nat.add` is defined using recursion on the second argument.

The impact on this repo was small, but we want to evaluate the impact on
Mathlib.

closes #4413
2024-06-11 17:18:11 +00:00
..
Coeffs.lean chore: Std -> Batteries renaming (#4108) 2024-05-08 05:04:25 +00:00
Constraint.lean
Int.lean perf: a isDefEq friendly Fin.sub (#4421) 2024-06-11 17:18:11 +00:00
IntList.lean chore: upstream Std.Data.Int (#3635) 2024-03-11 21:40:48 +00:00
LinearCombo.lean chore: reorganising to reduce imports (#3790) 2024-03-27 11:15:01 +00:00
Logic.lean doc: fix references to Std.Tactic.Omega in comments (#3479) 2024-02-23 16:05:32 +00:00