Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

List.unfold #1158

Open
Seasawher opened this issue Nov 24, 2024 · 2 comments
Open

List.unfold #1158

Seasawher opened this issue Nov 24, 2024 · 2 comments
Labels

Comments

@Seasawher
Copy link
Member

Seasawher commented Nov 24, 2024

Lean では停止保証ができないので定義が難しい。
Haskell では遅延評価なので問題なかった。
これを 帰納的述語の例にできるかも?

@Seasawher
Copy link
Member Author

むりやり停止保証して、Lean で実行可能な関数として定義できないだろうか…?

@Seasawher Seasawher changed the title List.unfold は停止保証できない List.unfold Nov 27, 2024
@Seasawher
Copy link
Member Author

Seasawher commented Nov 27, 2024

無理やり停止保証をしようとした例

cf. Zulip: List.unfold

inductive EventuallyNone {α : Type} (f : α → Option α) : α → Prop where
  | base (h : (f a).isNone) : EventuallyNone f a
  | cons {a'} (h : (f a) = some a') : EventuallyNone f a' → EventuallyNone f a

variable {α β : Type}

/- fail to show termination -/
def List.unfold (a : α) (f : α → Option α) (h : ∀ a, EventuallyNone f a) : List α :=
  match f a with
  | none => []
  | some a' => a' :: List.unfold a' f h

section
/- examples of `EventuallyNone` -/

def prev : Nat → Option Nat
  | 0 => none
  | n + 1 => some n

theorem prev_eventually_none (n : Nat) : EventuallyNone prev n := by
  induction n

  case zero =>
    apply EventuallyNone.base
    rfl

  case succ n ih =>
    apply EventuallyNone.cons
    rfl
    exact ih

end

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant