Zulip Chat Archive

Stream: general

Topic: Nat.find


Scott Morrison (Oct 16 2023 at 07:33):

I am about to move docs#Nat.find from Mathlib to Std, and I would like to do a quick :bike: :house: on naming. Currently the docs say:

* `Nat.find_spec` is the proof that `Nat.find hp` satisfies `p`.
* `Nat.find_min` is the proof that if `m < Nat.find hp` then `m` does not satisfy `p`.
* `Nat.find_min'` is the proof that if `m` does satisfy `p` then `Nat.find hp  m`.

I think find_min is an unhelpful name, and the fact that the other half of the specification is then called find_min' is especially unhelpful.

Scott Morrison (Oct 16 2023 at 07:33):

Is everyone happy with find_not_of_lt and find_le?

Mario Carneiro (Oct 16 2023 at 07:35):

find_min and find_min' are not two halves of the specification, they are the same spec written in contrapositive

Scott Morrison (Oct 16 2023 at 07:35):

Oops, indeed! Still, the prime is unhelpful?

Mario Carneiro (Oct 16 2023 at 07:35):

find_spec is the other half of the spec

Mario Carneiro (Oct 16 2023 at 07:36):

I think it should have a name better than find, this does not give an indication that it is finding the minimum element

Scott Morrison (Oct 16 2023 at 07:36):

Nat.findMin?

Mario Carneiro (Oct 16 2023 at 07:37):

makes sense

Mario Carneiro (Oct 16 2023 at 07:37):

is Nat.minimum used? Or is there precedent?

Scott Morrison (Oct 16 2023 at 07:38):

It doesn't seem to be used.

Mario Carneiro (Oct 16 2023 at 07:38):

not even in other namespaces?

Scott Morrison (Oct 16 2023 at 07:38):

An approximate precedent would be List.findIdx and List.findIdx?.

Scott Morrison (Oct 16 2023 at 07:38):

There is List.minimum.

Mario Carneiro (Oct 16 2023 at 07:39):

also WellFounded.min

Mario Carneiro (Oct 16 2023 at 07:39):

what's the ordinal one called

Mario Carneiro (Oct 16 2023 at 07:40):

I think it used to be omin but now it's just an Inf instance

Mario Carneiro (Oct 16 2023 at 07:41):

what is your interest in this function?

Mario Carneiro (Oct 16 2023 at 07:43):

I think there should also be a version of the function which starts the search at a given point

Scott Morrison (Oct 16 2023 at 07:43):

I wanted a def idx_of_mem [DecidableEq α] (xs : List α) (w : y ∈ xs) : Nat := ... and was going to define it via Nat.find.

Mario Carneiro (Oct 16 2023 at 07:44):

isn't that just findIdx?

Scott Morrison (Oct 16 2023 at 07:44):

Well, that returns an Option Nat, but yes, I could also define it in terms of that.

Mario Carneiro (Oct 16 2023 at 07:45):

I would not use Nat.find as a building block unless there wasn't any other structure in the problem. It's not very computationally efficient compared to almost any other strategy

Mario Carneiro (Oct 16 2023 at 07:46):

You said List.findIdx before, is that a thing? I would expect it to have that signature

Scott Morrison (Oct 16 2023 at 07:47):

I guess that does have the right signature. It doesn't take a y \mem xs argument and just returns the length of the list if there's nothing to find.

Mario Carneiro (Oct 16 2023 at 07:47):

it takes a predicate though, the std naming convention would call it findIdxP

Mario Carneiro (Oct 16 2023 at 07:48):

well actually I guess they all do

Scott Morrison (Oct 16 2023 at 07:48):

Oh, yes.

Scott Morrison (Oct 16 2023 at 07:50):

The place I'm using this is only for proving a property, I don't really care about the computational behaviour. I will just replace the implementation of idx_of_mem with something in terms of findIdx?, and not think any further about Nat.find.

Scott Morrison (Oct 16 2023 at 07:50):

Still the names of the lemmas are bad. :-)

Yaël Dillies (Oct 16 2023 at 09:16):

What does Idx even mean? That sounds unhelpfully obscure.

Yaël Dillies (Oct 16 2023 at 09:16):

Anyway, I would go for Nat.find_spec, Nat.of_lt_find, Nat.find_le.

Damiano Testa (Oct 16 2023 at 12:04):

I think that Idx stands for Index, but I also have to remind myself of this every time I see it.


Last updated: Dec 20 2023 at 11:08 UTC