lean4-htt/tests/bench/simp_arith1.lean
Paul Reichert 98e4b2882f
refactor: migrate to new ranges (#8841)
This PR migrates usages of `Std.Range` to the new polymorphic ranges.

This PR unfortunately increases the transitive imports for
frequently-used parts of `Init` because the ranges now rely on iterators
in order to provide their functionality for types other than `Nat`.
However, iteration over ranges in compiled code is as efficient as
before in the examples I checked. This is because of a special
`IteratorLoop` implementation provided in the PR for this purpose.

There were two issues that were uncovered during migration:

* In `IndPredBelow.lean`, migrating the last remaining range causes
`compilerTest1.lean` to break. I have minimized the issue and came to
the conclusion it's a compiler bug. Therefore, I have not replaced said
old range usage yet (see #9186).
* In `BRecOn.lean`, we are publicly importing the ranges. Making this
import private should theoretically work, but there seems to be a
problem with the module system, causing the build to panic later in
`Init.Data.Grind.Poly` (see #9185).
* In `FuzzyMatching.lean`, inlining fails with the new ranges, which
would have led to significant slowdown. Therefore, I have not migrated
this file either.
2025-07-07 12:41:53 +00:00

29 lines
917 B
Text

import Lean
open Lean Meta Elab in
elab "largeGoal%" : term =>
let n := 30 -- number of variables
let r := 3 -- number of repetitions
let mkAdd := mkApp2 (mkConst ``Nat.add)
let mkMul := mkApp2 (mkConst ``Nat.mul)
let decls := Array.ofFn fun (i : Fin n) =>
((`x).appendIndexAfter i, (fun _ => pure (mkConst ``Nat)))
withLocalDeclsD decls fun xs => do
let mut e₁ : Expr := mkNatLit 42
let mut e₂ : Expr := mkNatLit 23
for _ in *...r do
for i in *...xs.size do
e₁ := mkAdd (mkMul (mkNatLit i) e₁) xs[i]!
e₂ := mkAdd xs[i]! (mkMul e₂ (mkNatLit (xs.size - i)))
let goal ← mkEq e₁ e₂
let goal := mkNot goal
let goal ← mkForallFVars xs goal
return goal
set_option maxRecDepth 10000
-- manually verified: most time spent in type-checking
-- set_option trace.profiler true
example : largeGoal% := by
intros
simp +arith +decide only