### isabelle

#### Isabelle function to find the longest sequence of members of a relation

I have a relation R :: w => w => bool that is both transitive an irreflexive. I have the axiom Ax1: "finite {x::w. True}". Therefore, for each x there is always a longest sequence of wn R ... R w2 R w1 R x. I need a function F:: w => nat, that -for a given x - gives back the "lenght" of this sequence (or 0 if there is no y such that xRy). How would I go about building one in isabelle. Also: Is Ax1 a good way to axiomatize the "finiteness of type w" or is there a better one?

First of all, a more idiomatic way of writing {x::w. True} is UNIV :: w set. I suggest writing finite (UNIV :: w set), or possibly using the finite type class, although that might make your theorem more difficult to apply because you need a finite instance for your type. I think it's not really necessary or helpful for your use case. I then suggest the following approach: Define an inductive predicate (using inductive) on lists of type w list stating that the first element is x and for each two successive list elements y and z, R y z holds, i.e. the list is an ascending chain w.r.t. R. Show that any list that is such a chain must have distinct elements (cf. distinct :: 'a list ⇒ bool). Show that there are finitely many distinct lists over a finite set. Use the Max operator to find the biggest n such that there exists a list of length n that is an ascending chain w.r.t. R. That this works should be easy since there is at least one such chain, and you've already shown that there are only finitely many chains.

### Related Links

Error when trying to evaluate `coprime`

All available predicates in Isabelle

How do I refer to the current subgoal in Isar?

How to manage all the various proof methods

How to analyze if-expressions in assumptions?

What does `class` do in Isabelle

How to define a linear ordering on a type?

Parsing the content of a cartouche using a “term parser”

Defining finite sets in Isabelle

Find Lemmas used by simp/auto/clarify

Complete proof output in Isabelle

How to prove in HOLCF that double reversion of a list doesn't change it

Organization of `thy` files that come with Isabelle

Error message in Isabelle/HOL

What happens during function proofs

Inner syntax error when using `o` as a variable/function name