lean-ja / lean-ja/lean-by-example
`termination_by` が必要な例:
Open
Nobody has claimed this yet.
- Dominant language
- Lean
- Stars
- 188
- Forks
- 15
- Avg merge
- 9h 8m
- Merged PRs (30d)
- 6
Description
import Lean
open Std
variable {α : Type} [LE α] [DecidableEq α] [DecidableLE α]
instance : Min α := minOfLe
/-- リストの最小値を先頭に持ってくる -/
@[simp, grind]
def minFirst (xs : List α) : List α :=
match h : xs with
| [] => []
| x :: xs =>
let μ := List.min (x :: xs) (h := by simp)
have mem : μ ∈ x :: xs := by grind [List.min_mem]
let rest := List.erase (x :: xs) μ
have : (μ :: rest).length = (x :: xs).length := by grind
μ :: rest
#guard minFirst [3, 1, 4, 15, 9] = [1, 3, 4, 15, 9]
@[grind =]
theorem minFirst_length (xs : List α) :
(minFirst xs).length = xs.length := by
fun_cases minFirst xs with grind
def selectionSort (xs : List α) : List α :=
let ys := minFirst xs
have : ys.length = xs.length := by grind
match ys with
| [] => []
| z :: zs =>
have : zs.length < ys.length := by grind
z :: selectionSort zs
termination_by xs.length
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
The issue names no target file or test. Start by locating the repository's existing Lean example pages and review how recursive definitions are presented; done means adding the supplied selectionSort example, including its termination_by clause, in the appropriate documentation location.
Written by the indexing model from the issue text.
Assessment
- Domain
- documentation
- Issue type
- Documentation
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100