### 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

Is xsymbols used in Isabelle/JEdit?

Using mono attribute in inductive_set

Where is nat base 10 converted to num base 2?

What can one assume, what is worth assuming in Isar?

Introducing type abbreviations in Isabelle

Isabelle won't generate code for my recursive function without a termination proof

Proving a simple lemma about trees in Isabelle

Why can I prove ⟦ ( ∃ x. P ) ∧ ( ∃ x. Q ) ⟧ ⟹ ∃ x. (P ∧ Q)?

What is a Quotient type pattern in Isabelle?

Avoid matching (λx.x)

Program extraction using native integers/words (not bignums) from Isabelle theory

“String of nat” in Isabelle?

From a 'value' to a 'lemma'

Isabelle/Simpl: Calling a Procedure Twice

let-statement with SOME operator

Does Lueng's RegExp library work with Isabelle/ML? Is there another regex lib devs use for Isabelle/ML?