Zulip Chat Archive

Stream: new members

Topic: function definition by uniqueness


Cuong Tran (Nov 26 2021 at 08:56):

I'm sorry for being naive. If we have a theorem: forall x, y exists uniquely z such that p(x, y, z), how can we define a function base on this theorem?

I guess this question has been asked many times but sorry I tried to search but got lost here. Thanks!

Anne Baanen (Nov 26 2021 at 09:02):

You can use docs#Exists.some, which doesn't even need uniqueness! (Although you have no idea which witness you'll get.)

Anne Baanen (Nov 26 2021 at 09:04):

For example (tested):

import logic.basic

noncomputable def choose {p :     Prop} (h :  (n : ), ∃! (k : ), p n k) :    :=
λ n, (h n).exists.some

lemma choose_spec {p :     Prop} (h :  (n : ), ∃! (k : ), p n k) (n : ) :
  p n (choose h n) :=
λ n, (h n).exists.some_spec

Anne Baanen (Nov 26 2021 at 09:07):

Although you might find it easier instead of using exists_unique, to define a function that returns the witness + a lemma stating this is the unique witness satisfying p(x, y, z).

Cuong Tran (Nov 26 2021 at 09:58):

Thank you @Anne Baanen for your keywords. Thank to them, I found this article as well and now have a better insight about Lean non-computable.


Last updated: Dec 20 2023 at 11:08 UTC