How can I find the maximum element in a set of numbers (nat) in Isabelle. The max function doesn't work, as it is only defined to take the maximum of two elements. I have an idea of how I could implement it using a reduce like function, but I don't know how to pick one random element from a set.
Asked
Active
Viewed 1,033 times
5
-
1Using sets if you really want to take about lists is pretty cumbersome and often makes the proofs longer. – Lars Noschinski Feb 13 '13 at 07:07
2 Answers
7
The function you are looking for is called Max
. If you are looking for basic constants the guide What's in Main from the official Isabelle documentation is often useful. There is also the find_consts
command which can be used to search for functions by type.

Lars Noschinski
- 3,667
- 16
- 29
-
Just to add to this: search for constants is also available from Isabelle/jEdit's query panel (see [3.4.2, p.30](https://isabelle.in.tum.de/dist/doc/jedit.pdf) in the Isabelle/jEdit manual). If you have an idea what your function's name—or a part of it—could be called you can write `name:
` to search for matching constants. Small caveat: the search is limited to the imported theories. In this case you would have to have theory `Lattices_Big` imported (which seems to be included transitively in `Main`). – FK82 Jun 28 '20 at 07:35
4
If you follow the definition of Max
to theory Big_Operators
in the main HOL library, you will see that it is defined like this:
Max = fold1 max
The combinator fold1
is your "reduce like function" that works on finite sets.
See also theory Finite_Set
and its locale folding
for the mathematical background that is required here to fold over arbitrary sets, instead of concrete lists.

Makarius
- 2,165
- 18
- 20