leanprover-community / leanprover-community/mathlib4

Feature Request: Partial Decision Algorithm

Open
#26,046 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Lean
Stars
4.2k
Forks
1.7k
PR merge metrics
No merged PRs in 30d

Description

Zulip discussions:

This is a feature request to build something like Decidable but which is allowed to not return a definite result for all inputs.

Testcase (working code):

import Mathlib

inductive PartialDecide (α : Prop) : Type
  | decided (prf : α) : PartialDecide α
  | undecided : PartialDecide α

def PartialDecide.result {α : Prop} : PartialDecide α → Prop
  | decided _ => α
  | undecided => True

theorem PartialDecide.prf {α : Prop} : (h : PartialDecide α) → h.result
  | decided prf => prf
  | undecided => trivial

def sumOfKPrimes (k n : ℕ) := ∃ primes : List ℕ, primes.all Nat.Prime ∧ primes.length = k ∧ primes.sum = n

def foo (f : List ℕ) :=
  match f with
  | List.nil => True
  | List.cons s f' => sumOfKPrimes 2 s ∧ (foo f')

def foo_of : (target : List ℕ) → (evidence : List (ℕ × ℕ)) → PartialDecide (foo target)
  | [], [] => .decided trivial
  | [], (e :: et) => .undecided
  | (t :: tt), [] => .undecided
  | (t :: tt), (e :: et) => match foo_of tt et with
      | .decided ih => if h : e.1 + e.2 = t ∧ e.1.Prime ∧ e.2.Prime then
          .decided ⟨⟨[e.1, e.2], by simp [h]⟩, ih⟩ else .undecided
      | .undecided => .undecided

example : foo [13, 18, 20] :=
  (foo_of [13, 18, 20] [(2,11), (5,13), (3,17)]).prf

example : let tg := [13, 18, 20]; foo tg := by
  intro tg
  exact (foo_of tg [(2,11), (5,13), (3,17)]).prf

Note that the above example only has decided which returns the proof, and undecided which returns nothing, but it has also been remarked that it should have three potential outputs: that is, it should also return a proof of the negation.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reading the two linked Zulip discussions and the working Lean testcase in the issue. Clarify the intended API and whether the result should support decided, undecided, and proof-of-negation outcomes. Done means the agreed partial-decision feature is implemented and the testcase, including its examples, works.

Written by the indexing model from the issue text.

Assessment

Domain
tooling
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.