Zulip Chat Archive
Stream: Is there code for X?
Topic: Finding iteration satisfying a predicate in option if exists
Naruyoko (Jul 02 2023 at 23:50):
Suppose I have the following:
f : S → option S
, which satisfies that for allx : S
, there is somen
such that(λ x, x >>= f)^[n] $ some x = none
, so iteration is finite.- A decidable predicate
P
onS
, maybe asP : set S
withdecidable_pred P
.
Then, how can I concisely write 1) the finiteness of iteration of f
, and 2) the function S → option S
such that:
a) If there is some k
such that (λ x, x >>= f)^[k] $ some x = some z
and z ∈ P
, then return (λ x, x >>= f)^[k₀] $ some x
where k₀
is minimum such k
b) Otherwise, return none
.
In particular, I want to make such a function when S = ℕ
and f x = none
or f x = some z
where z < x
.
Yakov Pechersky (Jul 03 2023 at 02:39):
Express it as a existential, and pass it to docs#Nat.find
Yakov Pechersky (Jul 03 2023 at 02:40):
For the first half. For the second half, wrap the call to Nat.find in a dependent if.
Last updated: Dec 20 2023 at 11:08 UTC