Documentation

Mathlib.Util.CountHeartbeats

Defines a command wrapper that prints the number of heartbeats used in the enclosed command.

For example

count_heartbeats in
theorem foo : 42 = 6 * 7 := rfl

will produce an info message containing a number around 51. If this number is above the current maxHeartbeats, we also print a Try this: suggestion.

def Mathlib.CountHeartbeats.runTacForHeartbeats (tac : Lean.TSyntax `Lean.Parser.Tactic.tacticSeq) (revert : Bool := true) :

Run a tactic, optionally restoring the original state, and report just the number of heartbeats.

Equations
  • One or more equations did not get rendered due to their size.
Instances For

    Given a List Nat, return the minimum, maximum, and standard deviation.

    Equations
    • One or more equations did not get rendered due to their size.
    Instances For

      Given a List Nat, log an info message with the minimum, maximum, and standard deviation.

      Equations
      • One or more equations did not get rendered due to their size.
      Instances For

        Count the heartbeats used by a tactic, e.g.: count_heartbeats simp.

        Equations
        • One or more equations did not get rendered due to their size.
        Instances For

          count_heartbeats! in tac runs a tactic 10 times, counting the heartbeats used, and logs the range and standard deviation. The tactic count_heartbeats! n in tac runs it n times instead.

          Equations
          • One or more equations did not get rendered due to their size.
          Instances For

            Count the heartbeats used in the enclosed command.

            This is most useful for setting sufficient but reasonable limits via set_option maxHeartbeats for long running declarations.

            If you do so, please resist the temptation to set the limit as low as possible. As the simp set and other features of the library evolve, other contributors will find that their (likely unrelated) changes have pushed the declaration over the limit. count_heartbearts in will automatically suggest a set_option maxHeartbeats via "Try this:" using the least number of the form 2^k * 200000 that suffices.

            Note that that internal heartbeat counter accessible via IO.getNumHeartbeats has granularity 1000 times finer that the limits set by set_option maxHeartbeats. As this is intended as a user command, we divide by 1000.

            Equations
            • One or more equations did not get rendered due to their size.
            Instances For

              Guard the minimal number of heartbeats used in the enclosed command.

              This is most useful in the context of debugging and minimizing an example of a slow declaration. By guarding the number of heartbeats used in the slow declaration, an error message will be generated if a minimization step makes the slow behaviour go away.

              The default number of minimal heartbeats is the value of maxHeartbeats (typically 200000). Alternatively, you can specify a number of heartbeats to guard against, using the syntax guard_min_heartbeats n in cmd.

              Equations
              • One or more equations did not get rendered due to their size.
              Instances For

                Run a command, optionally restoring the original state, and report just the number of heartbeats.

                Equations
                • One or more equations did not get rendered due to their size.
                Instances For

                  count_heartbeats! in cmd runs a command 10 times, reporting the range in heartbeats, and the standard deviation. The command count_heartbeats! n in cmd runs it n times instead.

                  Example usage:

                  count_heartbeats! in
                  def f := 37
                  

                  displays the info message Min: 7 Max: 8 StdDev: 14%.

                  Equations
                  • One or more equations did not get rendered due to their size.
                  Instances For