Zulip Chat Archive
Stream: new members
Topic: noncomputable section help
pblpbl (Aug 21 2024 at 19:29):
Hi, why is lean failing to synthesize Decidable s1 here?
noncomputable section
structure real :=
neg: Bool
dec: Nat
frac: Nat -> Nat
def c (x : real) : real :=
let s1 := ∃ N, ∀ n, n >= N -> x.frac n = 9
if s1 then ⟨x.neg, x.dec + 1, λ n => 0⟩ else x
Yakov Pechersky (Aug 21 2024 at 19:34):
noncomputable section
structure real :=
neg: Bool
dec: Nat
frac: Nat -> Nat
def c (x : real) : real :=
let s1 := ∃ N, ∀ n, n >= N -> x.frac n = 9
have := Classical.propDecidable s1
if s1 then ⟨x.neg, x.dec + 1, λ n => 0⟩ else x
Yakov Pechersky (Aug 21 2024 at 19:34):
noncomputable section
doesn't also open Classical
. So you could also do:
noncomputable section
open Classical
structure real :=
neg: Bool
dec: Nat
frac: Nat -> Nat
def c (x : real) : real :=
let s1 := ∃ N, ∀ n, n >= N -> x.frac n = 9
if s1 then ⟨x.neg, x.dec + 1, λ n => 0⟩ else x
pblpbl (Aug 21 2024 at 20:07):
ok thanks, and where do i get the proof of s1 inside the body of "if s1"? I'd like to apply Nat.find.
edit: found it
def c (x : real) : real :=
let s1 := ∃ N, ∀ n >= N, x.frac n = 9
if h : s1 then
Yakov Pechersky (Aug 21 2024 at 20:31):
import Mathlib.Data.Nat.Find
noncomputable section
open Classical
structure real :=
neg: Bool
dec: Nat
frac: Nat -> Nat
def c (x : real) : real :=
let s1 := ∃ N, ∀ n, n >= N -> x.frac n = 9
if h : s1 then ⟨x.neg, x.dec + 1, λ n => Nat.find h⟩ else x
Last updated: May 02 2025 at 03:31 UTC