perf: optimize kernel type-checking for have-telescope simplification in Sym.simp
#11967
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR implements a new strategy for simplifying
have-telescopes inSym.simpthat achieves linear kernel type-checking time instead of quadratic.Problem
When simplifying deep
have-telescopes, the previous approach usinghave_congr'produced proofs that type-checked in quadratic time. The simplifier itself was fast, but the kernel became the bottleneck for large telescopes.For example, at n=100:
The quadratic behavior occurred because the kernel creates fresh free variables for each binder when type-checking, destroying sharing and producing O(n²) intermediate terms.
Solution
We transform sequential
have-telescopes into a parallel beta-application form:This parallel form leverages the efficient simplifier for lambdas in
Sym.simp. This form enables:The algorithm has three phases:
toBetaApp: Transform telescope → parallel beta-applicationsimpBetaApp: Simplify usingcongr/congrArg/congrFun'andsimpLambdatoHave: Convert back tohaveformBenchmark Results
Benchmark 1: Chain with all variables used in body
Benchmark 3: Parallel declarations (simplified values)
Benchmark 5: Chain with single dependency
Key observations:
Trade-offs
The optimization targets the critical path: kernel type-checking was the bottleneck preventing scaling to realistic symbolic simulation workloads.