include "basics/types.ma". include "basics/bool.ma". include "basics/lists/list.ma". include "arithmetics/nat.ma". include "utilities/adt/equal.ma". include "utilities/adt/ordering.ma". include "ASM/Util.ma". inductive table (dom_type: Type[0]) (rng_type: Type[0]): Type[0] ≝ | empty: table dom_type rng_type | node : nat → dom_type → rng_type → table dom_type rng_type → table dom_type rng_type → table dom_type rng_type. definition tbl_height ≝ λdom_type : Type[0]. λrng_type : Type[0]. λthe_table: table dom_type rng_type. match the_table with [ empty ⇒ 0 | node sz key val l r ⇒ sz ]. let rec tbl_size (dom_type : Type[0]) (rng_type : Type[0]) (the_table: table dom_type rng_type) on the_table: nat ≝ match the_table with [ empty ⇒ 0 | node sz key val l r ⇒ S (tbl_size … l) + (tbl_size … r) ]. definition tbl_empty ≝ λdom_type: Type[0]. λrng_type: Type[0]. empty dom_type rng_type. definition tbl_is_empty ≝ λdom_type: Type[0]. λrng_type: Type[0]. λthe_table: table dom_type rng_type. match the_table with [ empty ⇒ true | _ ⇒ false ]. definition tbl_is_empty_p ≝ λdom_type: Type[0]. λrng_type: Type[0]. λthe_table: table dom_type rng_type. match the_table with [ empty ⇒ True | _ ⇒ False ]. let rec tbl_to_list (dom_type: Type[0]) (rng_type: Type[0]) (the_table: table dom_type rng_type) on the_table: list (dom_type × rng_type) ≝ match the_table with [ empty ⇒ [ ] | node sz key val l r ⇒ 〈key, val〉 :: tbl_to_list … l @ tbl_to_list … r ]. let rec tbl_min_binding (key_type: Type[0]) (rng_type: Type[0]) (the_table: table key_type rng_type) (proof: ¬ (tbl_is_empty_p … the_table)) on the_table: key_type × rng_type ≝ match the_table return λx. ¬ (tbl_is_empty_p … x) → key_type × rng_type with [ empty ⇒ λabsurd. ? | node sz key val l r ⇒ λproof. match l return λx. x = l → key_type × rng_type with [ empty ⇒ λproof. 〈key, val〉 | _ ⇒ λproof. tbl_min_binding key_type rng_type l ? ] (refl … l) ] proof. [1: normalize in absurd; elim absurd; #ABSURD @⊥ @ABSURD @I |2: