File: .lake/packages/lean4/src/lean/Lean/Meta/Tactic/Backtrack.lean

full_name: Lean.Meta.Tactic.Backtrack.BacktrackConfig
code: /--
Configuration structure to control the behaviour of `backtrack`:
* control the maximum depth and behaviour (fail or return subgoals) at the maximum depth,
* and hooks allowing
  * modifying intermediate goals before running the external tactic,
  * 'suspending' goals, returning them in the result, and
  * discharging subgoals if the external tactic fails.
-/
structure BacktrackConfig where
  /-- Maximum recursion depth. -/
  maxDepth : Nat := 6
  /-- An arbitrary procedure which can be used to modify the list of goals
  before each attempt to generate alternatives.
  Called as `proc goals curr`, where `goals` are the original goals for `backtracking`,
  and `curr` are the current goals.
  Returning `some l` will replace the current goals with `l` and recurse
  (consuming one step of maximum depth).
  Returning `none` will proceed to generating alternative without changing goals.
  Failure will cause backtracking.
  (defaults to `none`) -/
  proc : List MVarId → List MVarId → MetaM (Option (List MVarId)) := fun _ _ => pure none
  /-- If `suspend g`, then we do not consider alternatives for `g`,
  but return `g` as a new subgoal. (defaults to `false`) -/
  suspend : MVarId → MetaM Bool := fun _ => pure false
  /-- `discharge g` is called on goals for which there were no alternatives.
  If `none` we return `g` as a new subgoal.
  If `some l`, we replace `g` by `l` in the list of active goals, and recurse.
  If failure, we backtrack. (defaults to failure) -/
  discharge : MVarId → MetaM (Option (List MVarId)) := fun _ => failure
  /--
  If we solve any "independent" goals, don't fail.
  See `Lean.MVarId.independent?` for the definition of independence.
  -/
  commitIndependentGoals : Bool := false
goal: Type

full_name: Lean.Meta.Tactic.Backtrack.BacktrackConfig.suspend
code: /--
Configuration structure to control the behaviour of `backtrack`:
* control the maximum depth and behaviour (fail or return subgoals) at the maximum depth,
* and hooks allowing
  * modifying intermediate goals before running the external tactic,
  * 'suspending' goals, returning them in the result, and
  * discharging subgoals if the external tactic fails.
-/
structure BacktrackConfig where
  /-- Maximum recursion depth. -/
  maxDepth : Nat := 6
  /-- An arbitrary procedure which can be used to modify the list of goals
  before each attempt to generate alternatives.
  Called as `proc goals curr`, where `goals` are the original goals for `backtracking`,
  and `curr` are the current goals.
  Returning `some l` will replace the current goals with `l` and recurse
  (consuming one step of maximum depth).
  Returning `none` will proceed to generating alternative without changing goals.
  Failure will cause backtracking.
  (defaults to `none`) -/
  proc : List MVarId → List MVarId → MetaM (Option (List MVarId)) := fun _ _ => pure none
  /-- If `suspend g`, then we do not consider alternatives for `g`,
  but return `g` as a new subgoal. (defaults to `false`) -/
  suspend : MVarId → MetaM Bool := fun _ => pure false
  /-- `discharge g` is called on goals for which there were no alternatives.
  If `none` we return `g` as a new subgoal.
  If `some l`, we replace `g` by `l` in the list of active goals, and recurse.
  If failure, we backtrack. (defaults to failure) -/
  discharge : MVarId → MetaM (Option (List MVarId)) := fun _ => failure
  /--
  If we solve any "independent" goals, don't fail.
  See `Lean.MVarId.independent?` for the definition of independence.
  -/
  commitIndependentGoals : Bool := false
goal: Lean.MVarId → Lean.MetaM Bool

full_name: Lean.Meta.Tactic.Backtrack.BacktrackConfig.discharge
code: /--
Configuration structure to control the behaviour of `backtrack`:
* control the maximum depth and behaviour (fail or return subgoals) at the maximum depth,
* and hooks allowing
  * modifying intermediate goals before running the external tactic,
  * 'suspending' goals, returning them in the result, and
  * discharging subgoals if the external tactic fails.
-/
structure BacktrackConfig where
  /-- Maximum recursion depth. -/
  maxDepth : Nat := 6
  /-- An arbitrary procedure which can be used to modify the list of goals
  before each attempt to generate alternatives.
  Called as `proc goals curr`, where `goals` are the original goals for `backtracking`,
  and `curr` are the current goals.
  Returning `some l` will replace the current goals with `l` and recurse
  (consuming one step of maximum depth).
  Returning `none` will proceed to generating alternative without changing goals.
  Failure will cause backtracking.
  (defaults to `none`) -/
  proc : List MVarId → List MVarId → MetaM (Option (List MVarId)) := fun _ _ => pure none
  /-- If `suspend g`, then we do not consider alternatives for `g`,
  but return `g` as a new subgoal. (defaults to `false`) -/
  suspend : MVarId → MetaM Bool := fun _ => pure false
  /-- `discharge g` is called on goals for which there were no alternatives.
  If `none` we return `g` as a new subgoal.
  If `some l`, we replace `g` by `l` in the list of active goals, and recurse.
  If failure, we backtrack. (defaults to failure) -/
  discharge : MVarId → MetaM (Option (List MVarId)) := fun _ => failure
  /--
  If we solve any "independent" goals, don't fail.
  See `Lean.MVarId.independent?` for the definition of independence.
  -/
  commitIndependentGoals : Bool := false
goal: Lean.MVarId → Lean.MetaM (Option (List Lean.MVarId))

full_name: Lean.Meta.Tactic.Backtrack.BacktrackConfig.commitIndependentGoals
code: /--
Configuration structure to control the behaviour of `backtrack`:
* control the maximum depth and behaviour (fail or return subgoals) at the maximum depth,
* and hooks allowing
  * modifying intermediate goals before running the external tactic,
  * 'suspending' goals, returning them in the result, and
  * discharging subgoals if the external tactic fails.
-/
structure BacktrackConfig where
  /-- Maximum recursion depth. -/
  maxDepth : Nat := 6
  /-- An arbitrary procedure which can be used to modify the list of goals
  before each attempt to generate alternatives.
  Called as `proc goals curr`, where `goals` are the original goals for `backtracking`,
  and `curr` are the current goals.
  Returning `some l` will replace the current goals with `l` and recurse
  (consuming one step of maximum depth).
  Returning `none` will proceed to generating alternative without changing goals.
  Failure will cause backtracking.
  (defaults to `none`) -/
  proc : List MVarId → List MVarId → MetaM (Option (List MVarId)) := fun _ _ => pure none
  /-- If `suspend g`, then we do not consider alternatives for `g`,
  but return `g` as a new subgoal. (defaults to `false`) -/
  suspend : MVarId → MetaM Bool := fun _ => pure false
  /-- `discharge g` is called on goals for which there were no alternatives.
  If `none` we return `g` as a new subgoal.
  If `some l`, we replace `g` by `l` in the list of active goals, and recurse.
  If failure, we backtrack. (defaults to failure) -/
  discharge : MVarId → MetaM (Option (List MVarId)) := fun _ => failure
  /--
  If we solve any "independent" goals, don't fail.
  See `Lean.MVarId.independent?` for the definition of independence.
  -/
  commitIndependentGoals : Bool := false
goal: Bool

full_name: Lean.Meta.Tactic.Backtrack.BacktrackConfig.maxDepth
code: /--
Configuration structure to control the behaviour of `backtrack`:
* control the maximum depth and behaviour (fail or return subgoals) at the maximum depth,
* and hooks allowing
  * modifying intermediate goals before running the external tactic,
  * 'suspending' goals, returning them in the result, and
  * discharging subgoals if the external tactic fails.
-/
structure BacktrackConfig where
  /-- Maximum recursion depth. -/
  maxDepth : Nat := 6
  /-- An arbitrary procedure which can be used to modify the list of goals
  before each attempt to generate alternatives.
  Called as `proc goals curr`, where `goals` are the original goals for `backtracking`,
  and `curr` are the current goals.
  Returning `some l` will replace the current goals with `l` and recurse
  (consuming one step of maximum depth).
  Returning `none` will proceed to generating alternative without changing goals.
  Failure will cause backtracking.
  (defaults to `none`) -/
  proc : List MVarId → List MVarId → MetaM (Option (List MVarId)) := fun _ _ => pure none
  /-- If `suspend g`, then we do not consider alternatives for `g`,
  but return `g` as a new subgoal. (defaults to `false`) -/
  suspend : MVarId → MetaM Bool := fun _ => pure false
  /-- `discharge g` is called on goals for which there were no alternatives.
  If `none` we return `g` as a new subgoal.
  If `some l`, we replace `g` by `l` in the list of active goals, and recurse.
  If failure, we backtrack. (defaults to failure) -/
  discharge : MVarId → MetaM (Option (List MVarId)) := fun _ => failure
  /--
  If we solve any "independent" goals, don't fail.
  See `Lean.MVarId.independent?` for the definition of independence.
  -/
  commitIndependentGoals : Bool := false
goal: Nat

full_name: Lean.Meta.Tactic.Backtrack.BacktrackConfig.proc
code: /--
Configuration structure to control the behaviour of `backtrack`:
* control the maximum depth and behaviour (fail or return subgoals) at the maximum depth,
* and hooks allowing
  * modifying intermediate goals before running the external tactic,
  * 'suspending' goals, returning them in the result, and
  * discharging subgoals if the external tactic fails.
-/
structure BacktrackConfig where
  /-- Maximum recursion depth. -/
  maxDepth : Nat := 6
  /-- An arbitrary procedure which can be used to modify the list of goals
  before each attempt to generate alternatives.
  Called as `proc goals curr`, where `goals` are the original goals for `backtracking`,
  and `curr` are the current goals.
  Returning `some l` will replace the current goals with `l` and recurse
  (consuming one step of maximum depth).
  Returning `none` will proceed to generating alternative without changing goals.
  Failure will cause backtracking.
  (defaults to `none`) -/
  proc : List MVarId → List MVarId → MetaM (Option (List MVarId)) := fun _ _ => pure none
  /-- If `suspend g`, then we do not consider alternatives for `g`,
  but return `g` as a new subgoal. (defaults to `false`) -/
  suspend : MVarId → MetaM Bool := fun _ => pure false
  /-- `discharge g` is called on goals for which there were no alternatives.
  If `none` we return `g` as a new subgoal.
  If `some l`, we replace `g` by `l` in the list of active goals, and recurse.
  If failure, we backtrack. (defaults to failure) -/
  discharge : MVarId → MetaM (Option (List MVarId)) := fun _ => failure
  /--
  If we solve any "independent" goals, don't fail.
  See `Lean.MVarId.independent?` for the definition of independence.
  -/
  commitIndependentGoals : Bool := false
goal: List Lean.MVarId → List Lean.MVarId → Lean.MetaM (Option (List Lean.MVarId))

full_name: _private.«.lake».packages.lean4.src.lean.Lean.Meta.Tactic.Backtrack.0.Lean.Meta.Tactic.Backtrack.Backtrack.ppMVarId
code: /--
Pretty print a list of goals.
-/
private def ppMVarId (g : MVarId) : MetaM Format 
goal: Lean.MetaM Lean.Format

full_name: _private.«.lake».packages.lean4.src.lean.Lean.Meta.Tactic.Backtrack.0.Lean.Meta.Tactic.Backtrack.Backtrack.ppMVarIds
code: /--
Pretty print a list of goals.
-/
private def ppMVarIds (gs : List MVarId) : MetaM (List Format) 
goal: Lean.MetaM (List Lean.Format)

full_name: Lean.Meta.Tactic.Backtrack.Backtrack.tryAllM
code: /-- Run a monadic function on every element of a list,
returning the list of elements on which the function fails, and the list of successful results. -/
def tryAllM [Monad m] [Alternative m] (L : List α) (f : α → m β) : m (List α × List β) 
goal: m (List α × List β)

full_name: _private.«.lake».packages.lean4.src.lean.Lean.Meta.Tactic.Backtrack.0.Lean.Meta.Tactic.Backtrack.Backtrack.run
code: /--
* `n : Nat` steps remaining.
* `curr : List MVarId` the current list of unsolved goals.
* `acc : List MVarId` a list of "suspended" goals, which will be returned as subgoals.
-/
  -- `acc` is intentionally a `List` rather than an `Array` so we can share across branches.
private def run (goals : List MVarId) (n : Nat) (curr acc : List MVarId) : MetaM (List MVarId) 
goal: Lean.MetaM (List Lean.MVarId)

full_name: _private.«.lake».packages.lean4.src.lean.Lean.Meta.Tactic.Backtrack.0.Lean.Meta.Tactic.Backtrack.Backtrack.processIndependentGoals
code: /--
A wrapper around `run`, which works on "independent" goals separately first,
to reduce backtracking.
-/
private partial def processIndependentGoals (orig : List MVarId) (goals remaining : List MVarId) :
    MetaM (List MVarId) 
goal: Lean.MetaM (List Lean.MVarId)

full_name: Lean.Meta.Tactic.Backtrack.backtrack
code: /--
Attempts to solve the `goals`, by recursively calling `next` on each
subgoal that appears with a callback to reenter backtracking search.

Further flow control options are available via the `Config` argument.

Returns a list of subgoals which were "suspended" via the `suspend` or
`discharge` hooks in `Config`. In the default configuration, `backtrack`
will either return an empty list or fail.
-/
def backtrack (cfg : BacktrackConfig := {}) (trace : Name := .anonymous)
    (next : MVarId → MetaM (Meta.Iterator (List MVarId)))
    (goals : List MVarId) : MetaM (List MVarId) 
goal: Lean.MetaM (List Lean.MVarId)