lean4-htt/tests/lean/run/4861.lean
Leonardo de Moura 647a5e9492
perf: use NatPow Int instead of HPow Int Nat Int (#4903)
This modification improves the performance of the example in issue
#4861. It no longer times out but is still expensive.

Here is the analysis of the performance issue: Given `(x : Int)`, to
elaborate `x ^ 1`, a few default instances have to be tried.

First, the homogeneous instance is tried and fails since `Int` does not
implement `Pow Int`. Then, the `NatPow` instance is tried, and it also
fails. The same process is performed for each term of the form `p ^ 1`.
There are seveal of them at #4861. After all of these fail, the lower
priority default instance for numerals is tried, and `x ^ 1` becomes `x
^ (1 : Nat)`. Then, `HPow Int Nat Int` can be applied, and the
elaboration succeeds. However, this process has to be repeated for every
single term of the form `p ^ 1`. The elaborator tries all homogeneous
`HPow` and `NatPow` instances for all `p ^ 1` terms before trying the
lower priority default instance `OfNat`.

This commit ensures `Int` has a `NatPow` instance instead of `HPow Int
Nat Int`. This change shortcuts the process, but it still first tries
the homogeneous `HPow` instance, fails, and then tries `NatPow`. The
elaboration can be made much more efficient by writing `p ^ (1 : Nat)`.
2024-08-03 00:35:04 +00:00

55 lines
2.4 KiB
Text

set_option maxHeartbeats 210000 in
theorem foo (x y z p q : Int) : False :=
have : (1 * x ^ 1 + z ^ 1 * p) *
(1 / 1 * p ^ 1 * x ^ 1 + 1 * q * p ^ 1 * x * z + 1 * q ^ 1 * p ^ 1 * x ^ 1 +
1 * q ^ 1 * p ^ 1 * x * z -
1 * q * p ^ 1 * y ^ 1 +
1 * q ^ 1 * p ^ 1 * x ^ 1 +
1 * q ^ 1 * p ^ 1 * x * z -
1 * q ^ 1 * p ^ 1 * y ^ 1 +
1 * q ^ 1 * p ^ 1 * x ^ 1 +
1 * q ^ 1 * p ^ 1 * x * z -
1 * q ^ 1 * p ^ 1 * y ^ 1 +
1 * q ^ 1 * x ^ 1 -
1 * q ^ 1 * p * y ^ 1) +
z * (1 * y) *
(-(1 / 1 * p ^ 1 * x * y) + 1 * q * p ^ 1 * z * y - 1 * q ^ 1 * p ^ 1 * x * y +
1 * q ^ 1 * p ^ 1 * z * y -
1 * q ^ 1 * p ^ 1 * x * y +
1 * q ^ 1 * p ^ 1 * z * y -
1 * q ^ 1 * p ^ 1 * x * y +
1 / 1 * q ^ 1 * p ^ 1 * z * y) +
(-y ^ 1 + p * x * (1 * z) + q * (1 * z ^ 1)) *
(-(1 / 1 * p ^ 1 * x * z) - 1 * q * p ^ 1 * x ^ 1 - 1 * q ^ 1 * p ^ 1 * x * z -
1 * q ^ 1 * p ^ 1 * x ^ 1 -
1 * q ^ 1 * p ^ 1 * x * z -
1 * q ^ 1 * p ^ 1 * x ^ 1 -
1 * q ^ 1 * p ^ 1 * x * z -
1 * q ^ 1 * p * x ^ 1) =
1 *
(1 / 1 * p ^ 1 * x ^ 1 + 1 * q * p ^ 1 * x * z + 1 * q ^ 1 * p ^ 1 * x ^ 1 +
1 * q ^ 1 * p ^ 1 * x * z -
1 * q * p ^ 1 * y ^ 1 +
1 * q ^ 1 * p ^ 1 * x ^ 1 +
1 * q ^ 1 * p ^ 1 * x * z -
1 * q ^ 1 * p ^ 1 * y ^ 1 +
1 * q ^ 1 * p ^ 1 * x ^ 1 +
1 * q ^ 1 * p ^ 1 * x * z -
1 * q ^ 1 * p ^ 1 * y ^ 1 +
1 * q ^ 1 * x ^ 1 -
1 * q ^ 1 * p * y ^ 1) +
1 *
(-(1 / 1 * p ^ 1 * x * y) + 1 * q * p ^ 1 * z * y - 1 * q ^ 1 * p ^ 1 * x * y +
1 * q ^ 1 * p ^ 1 * z * y -
1 * q ^ 1 * p ^ 1 * x * y +
1 * q ^ 1 * p ^ 1 * z * y -
1 * q ^ 1 * p ^ 1 * x * y +
1 / 1 * q ^ 1 * p ^ 1 * z * y) +
1 *
(-(1 / 1 * p ^ 1 * x * z) - 1 * q * p ^ 1 * x ^ 1 - 1 * q ^ 1 * p ^ 1 * x * z -
1 * q ^ 1 * p ^ 1 * x ^ 1 -
1 * q ^ 1 * p ^ 1 * x * z -
1 * q ^ 1 * p ^ 1 * x ^ 1 -
1 * q ^ 1 * p ^ 1 * x * z -
1 * q ^ 1 * p * x ^ 1) := sorry
sorry