src/HOL/Data_Structures/Lookup2.thy
author paulson <lp15@cam.ac.uk>
Thu, 22 Feb 2018 22:58:27 +0000
changeset 67689 2c38ffd6ec71
parent 63411 e051eea34990
child 67965 aaa31cd0caef
permissions -rw-r--r--
type class linordered_nonzero_semiring has new axiom to guarantee characteristic 0

(* Author: Tobias Nipkow *)

section \<open>Function \textit{lookup} for Tree2\<close>

theory Lookup2
imports
  Tree2
  Cmp
  Map_by_Ordered
begin

fun lookup :: "('a::linorder * 'b, 'c) tree \<Rightarrow> 'a \<Rightarrow> 'b option" where
"lookup Leaf x = None" |
"lookup (Node _ l (a,b) r) x =
  (case cmp x a of LT \<Rightarrow> lookup l x | GT \<Rightarrow> lookup r x | EQ \<Rightarrow> Some b)"

lemma lookup_map_of:
  "sorted1(inorder t) \<Longrightarrow> lookup t x = map_of (inorder t) x"
by(induction t) (auto simp: map_of_simps split: option.split)

end