This PR adds a builtin tactic and a builtin attribute that are required for the tree map. The tactic, `as_aux_lemma`, can generally be used to wrap the proof term generated by a tactic sequence into a separate auxiliary lemma in order to keep the proof term small. This can, in rare cases, be necessary if the proof term will appear multiple times in the encompassing term. The new attribute, `Std.Internal.tree_tac`, is internal and should not be used outside of `Std`. --------- Co-authored-by: Paul Reichert <6992158+datokrat@users.noreply.github.com>
47 lines
1.2 KiB
Text
47 lines
1.2 KiB
Text
/-
|
|
Copyright (c) 2025 Lean FRO, LLC. All rights reserved.
|
|
Released under Apache 2.0 license as described in the file LICENSE.
|
|
Authors: Paul Reichert
|
|
-/
|
|
import Lean.Environment
|
|
import Lean.Meta.Basic
|
|
import Lean.Util.NumObjs
|
|
|
|
open Lean Meta
|
|
|
|
abbrev testProp := ∀ n : Nat, n = 0 + n
|
|
|
|
def thmUsingTactic : testProp := by as_aux_lemma =>
|
|
intro n
|
|
induction n
|
|
· rfl
|
|
· next ih =>
|
|
rw [← Nat.succ_eq_add_one, Nat.add_succ, ← ih]
|
|
|
|
def thmWithoutTactic : testProp := by
|
|
intro n
|
|
induction n
|
|
· rfl
|
|
· next ih =>
|
|
rw [← Nat.succ_eq_add_one, Nat.add_succ, ← ih]
|
|
|
|
open Lean
|
|
|
|
def size (name : Name) : MetaM Nat := do
|
|
let env ← getEnv
|
|
let mut totalSize : Nat := 0
|
|
for (constantName, info) in env.constants do
|
|
if name = constantName then
|
|
if let some e := info.value? then
|
|
let numObjs ← e.numObjs
|
|
totalSize := totalSize + numObjs
|
|
return totalSize
|
|
|
|
/--
|
|
info: as_aux_lemma makes proof term smaller : true
|
|
-/
|
|
#guard_msgs in
|
|
run_meta do
|
|
let sizeUsingTactic ← size `thmUsingTactic
|
|
let sizeWithoutTactic ← size `thmWithoutTactic
|
|
logInfo m!"as_aux_lemma makes proof term smaller : {decide <| sizeUsingTactic < sizeWithoutTactic}"
|