test: add cbv benchmark for evaluating Decidable.decide (#12467)

This PR adds a benchmark for `cbv` tactic for evaluating
`Decidable.decide` for a `Decidable` instance for a problem of checking
if a number is not a prime power.

The test has been inspired by a recent discussion on the [leanprover
zulip](https://leanprover.zulipchat.com/#narrow/channel/287929-mathlib4/topic/Can't.20decide.20if.2015.20is.20a.20prime.20power/with/572513330).
This commit is contained in:
Wojciech Różowski 2026-02-13 13:25:35 +00:00 committed by GitHub
parent 6ae413a56a
commit f3b8f76ec4
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 47 additions and 0 deletions

View file

@ -0,0 +1,41 @@
import Lean
open Lean
abbrev Nat.Prime (p : Nat) : Prop :=
2 ≤ p ∧ ∀ (m : Nat), m < p → 2 ≤ m → ¬m p
abbrev IsPrimePow (n : Nat) : Prop :=
∃ p ≤ n, ∃ k ≤ n, Nat.Prime p ∧ 0 < k ∧ p ^ k = n
def mkProblemInst (n : Nat) : Expr :=
let n := mkNatLit n
let f := mkApp (mkConst ``IsPrimePow) n
mkApp (mkConst ``Not) f
def runSingleTest (n : Nat) : MetaM Unit := do
let toFeed := mkProblemInst n
let startTime ← IO.monoNanosNow
let mvar ← Meta.mkFreshExprMVar toFeed
let mvar := mvar.mvarId!
let [mvar] ← mvar.applyConst ``of_decide_eq_true | throwError "Could not apply `of_decide_eq_true`"
let executed ← Lean.Meta.Tactic.Cbv.cbvGoal mvar
if (executed.isSome) then
throwError "Did not fully reduce"
let endTime ← IO.monoNanosNow
let ms := (endTime - startTime).toFloat / 1000000.0
let executed ← instantiateMVars (.mvar mvar)
let startTime ← IO.monoNanosNow
Meta.checkWithKernel executed
let endTime ← IO.monoNanosNow
let kernelMs := (endTime - startTime).toFloat / 1000000.0
IO.println s!"cbv: goal_{n}: {ms} ms, kernel: {kernelMs} ms"
set_option maxHeartbeats 400000
def runCbvTests : MetaM Unit := do
IO.println "=== Call-By-Value Tactic Tests ==="
IO.println ""
for n in [6,10,12,14,15,18,20] do
runSingleTest n
#eval runCbvTests

View file

@ -683,3 +683,9 @@
run_config:
<<: *time
cmd: lean ./cbv/dedup.lean
- attributes:
description: cbv tactic (evaluating Decidable.decide)
tags: [other]
run_config:
<<: *time
cmd: lean ./cbv/decide.lean