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

Organizing constraints in isabelle in order to model a system

Trouble with Int Theory in Isabelle/HOL

How do I do simple multithreading in Isabelle ML?

Isabelle: Proof on difference between 2 lists

Printing out / showing detailed steps of proof methods (like simp) in a proof in isabelle

Defining disjoint union of different types in Isabelle and more

Case names for locale interpretation

“invalid map function” when defining a corecursive tree

Trying to generalize a bit vector that uses typedef, bool list, and nat length

Factoring out a lemma premise as a definition causes failure in proof method (auto) application in isabelle

How do I convert “thm conjI” to an ASCII string I can save to a file?

Express that a function is constant on a set

What's the difference between the empty sort, 'a::{}, and a sort of “type”, 'a::type

How can I pass a ML value as an argument to an outer syntax command?

How to prove the reversion of a doubling function equals the doubling of a reversion function in Isabelle?

Giving a list a partial order in Isabelle/HOLCF