### isabelle

#### How to define a linear ordering on a type?

I'm trying to define a conjunction function for 4-valued logic (false, true, null, and error). In my case the conjunction is equivavlent to min function on linear order false < error < null < true. datatype bool4 = JF | JT | BN | BE instantiation bool4 :: linear_order begin fun leq_bool4 :: "bool4 ⇒ bool4 ⇒ bool" where "leq_bool4 JF b = True" | "leq_bool4 BE b = (b = BE ∨ b = BN ∨ b = JT)" | "leq_bool4 BN b = (b = BN ∨ b = JT)" | "leq_bool4 JT b = (b = JT)" instance proof fix x y z :: bool4 show "x ⊑ x" by (induct x) simp_all show "x ⊑ y ⟹ y ⊑ z ⟹ x ⊑ z" by (induct x; induct y) simp_all show "x ⊑ y ⟹ y ⊑ x ⟹ x = y" by (induct x; induct y) simp_all show "x ⊑ y ∨ y ⊑ x" by (induct x; induct y) simp_all qed end definition and4 :: "bool4 ⇒ bool4 ⇒ bool4" where "and4 a b ≡ minimum a b" I guess there must be an easier way to define a linear order in Isabelle HOL. Could you suggest a simplification of the theory?

You can use the "Datatype_Order_Generator" AFP entry. Then it's as simple as importing "$AFP/Datatype_Order_Generator/Order_Generator" and declaring derive linorder "bool4". Note that the constructors must be declared in the order you want them when defining your datatype. Details on how to download and use the AFP locally can be found here.

### Related Links

Isabelle HOLCF doesn't understand fixrec

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

Is it possible to run Isabelle 2005 proofs with Proof General?

Multicast using Isabelle

Mutual recursion in primcofix

How to prove that addition of a new variable to the expression doesn't change its semantics?

How to define functions with overlapping patterns?

Non-terminating inductive predicates

Parts of mathematics not yet formalized / Isabelle wishlist

Instantiating theorems in Isabelle

Proving a basic identity in Isabelle

Error in an Isabelle function definition taken from lecture notes

Proving the cardinality of a more involved set

Function returns 0 when it should return 1, eliminating parantheses

Isabelle return numbers instead of Suc(Suc( … 0 ))

Finding the `card` function