src/HOL/Data_Structures/Cmp.thy
author nipkow
Thu, 05 Nov 2015 08:27:14 +0100
changeset 61581 00d9682e8dd7
child 61640 44c9198f210c
permissions -rw-r--r--
Convertd to 3-way comparisons
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
61581
00d9682e8dd7 Convertd to 3-way comparisons
nipkow
parents:
diff changeset
     1
(* Author: Tobias Nipkow *)
00d9682e8dd7 Convertd to 3-way comparisons
nipkow
parents:
diff changeset
     2
00d9682e8dd7 Convertd to 3-way comparisons
nipkow
parents:
diff changeset
     3
section {* Three-Way Comparison *}
00d9682e8dd7 Convertd to 3-way comparisons
nipkow
parents:
diff changeset
     4
00d9682e8dd7 Convertd to 3-way comparisons
nipkow
parents:
diff changeset
     5
theory Cmp
00d9682e8dd7 Convertd to 3-way comparisons
nipkow
parents:
diff changeset
     6
imports Main
00d9682e8dd7 Convertd to 3-way comparisons
nipkow
parents:
diff changeset
     7
begin
00d9682e8dd7 Convertd to 3-way comparisons
nipkow
parents:
diff changeset
     8
00d9682e8dd7 Convertd to 3-way comparisons
nipkow
parents:
diff changeset
     9
datatype cmp = LT | EQ | GT
00d9682e8dd7 Convertd to 3-way comparisons
nipkow
parents:
diff changeset
    10
00d9682e8dd7 Convertd to 3-way comparisons
nipkow
parents:
diff changeset
    11
class cmp = linorder +
00d9682e8dd7 Convertd to 3-way comparisons
nipkow
parents:
diff changeset
    12
fixes cmp :: "'a \<Rightarrow> 'a \<Rightarrow> cmp"
00d9682e8dd7 Convertd to 3-way comparisons
nipkow
parents:
diff changeset
    13
assumes LT[simp]: "cmp x y = LT \<longleftrightarrow> x < y"
00d9682e8dd7 Convertd to 3-way comparisons
nipkow
parents:
diff changeset
    14
assumes EQ[simp]: "cmp x y = EQ \<longleftrightarrow> x = y"
00d9682e8dd7 Convertd to 3-way comparisons
nipkow
parents:
diff changeset
    15
assumes GT[simp]: "cmp x y = GT \<longleftrightarrow> x > y"
00d9682e8dd7 Convertd to 3-way comparisons
nipkow
parents:
diff changeset
    16
00d9682e8dd7 Convertd to 3-way comparisons
nipkow
parents:
diff changeset
    17
lemma case_cmp_if[simp]: "(case c of EQ \<Rightarrow> e | LT \<Rightarrow> l | GT \<Rightarrow> g) =
00d9682e8dd7 Convertd to 3-way comparisons
nipkow
parents:
diff changeset
    18
  (if c = LT then l else if c = GT then g else e)"
00d9682e8dd7 Convertd to 3-way comparisons
nipkow
parents:
diff changeset
    19
by(simp split: cmp.split)
00d9682e8dd7 Convertd to 3-way comparisons
nipkow
parents:
diff changeset
    20
00d9682e8dd7 Convertd to 3-way comparisons
nipkow
parents:
diff changeset
    21
end