End Keys.
(* Last_key and Fresh are constructs that work *)
(* for any union map with integer keys *)
(* Should be developed more generally for any union map class *)
(* with a proof that key U = nat, but I can't bother right now *)
Section FreshLastKey.
Variable V : Type.
Implicit Type f : union_map [ordType of nat] V.
Definition last_key f := last 0 (dom f).

(* Specifications: *)
Lemma last_key0 : last_key Unit = 0.
Lemma dom_last_key f :  valid f -> ~~ empb f -> last_key f \in dom f.
Lemma max_key_last f x :
x \in dom f -> {in dom f, forall y, y <= x} -> last_key f = x.
Lemma last_keyPt (x : nat) v : last_key (x \\-> v) = x.
Lemma last_key_mono f1 f2 :
{subset dom f1 <= dom f2} -> last_key f1 <= last_key f2.
Lemma last_keyfUn f1 f2 :
valid (f1 \+ f2) -> last_key f1 <= last_key (f1 \+ f2).
Lemma last_fresh f v : valid f -> last_key (f \+ fresh f \\-> v) = fresh f.
End FreshLastKey.