File: Mathlib/Tactic/SlimCheck.lean

full_name: initFn._@.Mathlib.Tactic.SlimCheck._hyg.8
code: initialize registerTraceClass `slim_check.instance
goal: IO Unit

full_name: initFn._@.Mathlib.Tactic.SlimCheck._hyg.43
code: initialize registerTraceClass `slim_check.decoration
goal: IO Unit

full_name: initFn._@.Mathlib.Tactic.SlimCheck._hyg.78
code: initialize registerTraceClass `slim_check.discarded
goal: IO Unit

full_name: initFn._@.Mathlib.Tactic.SlimCheck._hyg.113
code: initialize registerTraceClass `slim_check.success
goal: IO Unit

full_name: initFn._@.Mathlib.Tactic.SlimCheck._hyg.148
code: initialize registerTraceClass `slim_check.shrink.steps
goal: IO Unit

full_name: initFn._@.Mathlib.Tactic.SlimCheck._hyg.183
code: initialize registerTraceClass `slim_check.shrink.candidates
goal: IO Unit

full_name: slimCheckSyntax
code: /--
`slim_check` considers a proof goal and tries to generate examples
that would contradict the statement.

Let's consider the following proof goal.

```lean
xs : List ℕ,
h : ∃ (x : ℕ) (H : x ∈ xs), x < 3
⊢ ∀ (y : ℕ), y ∈ xs → y < 5
```

The local constants will be reverted and an instance will be found for
`Testable (∀ (xs : List ℕ), (∃ x ∈ xs, x < 3) → (∀ y ∈ xs, y < 5))`.
The `Testable` instance is supported by an instance of `Sampleable (List ℕ)`,
`Decidable (x < 3)` and `Decidable (y < 5)`.

Examples will be created in ascending order of size (more or less)

The first counter-examples found will be printed and will result in an error:

```
===================
Found problems!
xs := [1, 28]
x := 1
y := 28
-------------------
```

If `slim_check` successfully tests 100 examples, it acts like
admit. If it gives up or finds a counter-example, it reports an error.

For more information on writing your own `Sampleable` and `Testable`
instances, see `Testing.SlimCheck.Testable`.

Optional arguments given with `slim_check (config : { ... })`
* `numInst` (default 100): number of examples to test properties with
* `maxSize` (default 100): final size argument

Options:
* `set_option trace.slim_check.decoration true`: print the proposition with quantifier annotations
* `set_option trace.slim_check.discarded true`: print the examples discarded because they do not
  satisfy assumptions
* `set_option trace.slim_check.shrink.steps true`: trace the shrinking of counter-example
* `set_option trace.slim_check.shrink.candidates true`: print the lists of candidates considered
  when shrinking each variable
* `set_option trace.slim_check.instance true`: print the instances of `testable` being used to test
  the proposition
* `set_option trace.slim_check.success true`: print the tested samples that satisfy a property
-/
syntax (name := slimCheckSyntax) "slim_check" (config)? : tactic
goal: Lean.ParserDescr

full_name: _aux_Mathlib_Tactic_SlimCheck___elabRules_slimCheckSyntax_1
code: elab_rules : tactic | `(tactic| slim_check $[$cfg]?) => withMainContext do
  let cfg ← elabConfig (mkOptionalNode cfg)
  let (_, g) ← (← getMainGoal).revert ((← getLocalHyps).map (Expr.fvarId!))
  g.withContext do
  let tgt ← g.getType
  let tgt' ← addDecorations tgt
  let cfg := { cfg with
    traceDiscarded := cfg.traceDiscarded || (← isTracingEnabledFor `slim_check.discarded),
    traceSuccesses := cfg.traceSuccesses || (← isTracingEnabledFor `slim_check.success),
    traceShrink := cfg.traceShrink || (← isTracingEnabledFor `slim_check.shrink.steps),
    traceShrinkCandidates := cfg.traceShrinkCandidates
      || (← isTracingEnabledFor `slim_check.shrink.candidates) }
  let inst ← try
    synthInstance (← mkAppM ``Testable #[tgt'])
  catch _ => throwError "\
      Failed to create a `testable` instance for `{tgt}`.\
    \nWhat to do:\
    \n1. make sure that the types you are using have `SlimCheck.SampleableExt` instances\
    \n  (you can use `#sample my_type` if you are unsure);\
    \n2. make sure that the relations and predicates that your proposition use are decidable;\
    \n3. make sure that instances of `SlimCheck.Testable` exist that, when combined,\
    \n  apply to your decorated proposition:\
    \n```\
    \n{tgt'}\
    \n```\
    \n\
    \nUse `set_option trace.Meta.synthInstance true` to understand what instances are missing.\
    \n\
    \nTry this:\
    \nset_option trace.Meta.synthInstance true\
    \n#synth SlimCheck.Testable ({tgt'})"
  let e ← mkAppOptM ``Testable.check #[tgt, toExpr cfg, tgt', inst]
  trace[slim_check.decoration] "[testable decoration]\n  {tgt'}"
  -- Porting note: I have not ported support for `trace.slim_check.instance`.
  -- See the commented out code below from mathlib3 if you would like to implement this.
  --   when_tracing `slim_check.instance   <| do
  --   { inst ← summarize_instance inst >>= pp,
  --     trace!"\n[testable instance]{format.indent inst 2}" },
  let code ← unsafe evalExpr (CoreM PUnit) q(CoreM PUnit) e
  _ ← code
  admitGoal g
goal: Lean.Elab.Tactic.Tactic