From ChargeCore.SepAlg Require Import SepAlg UUSepAlg.
Set Implicit Arguments.
Unset Strict Implicit.
Set Maximal Implicit Insertion.
Section PartialFun.
(* A partial function is a function from X -> option Y where X equality of members of type X is decidable. *)
Context {X Y : Type}.
Context {RelDec_X : RelDec (@eq X)}.
Context {RDC : RelDec_Correct RelDec_X}.
Definition pfun := X -> option Y.
Definition pfun_eq (f1 f2 : pfun) := forall s, (f1 s) = (f2 s).
Global Instance EquivalencePfun : Equivalence pfun_eq.
Definition emptyFun : pfun := fun _ => None.
Definition pfun_update (f : pfun) (x : X) (y : Y) :=
fun z => if x ?[ eq ] z then Some y else f z.
Definition pfun_in (f : pfun) (x : X) : Prop := exists y, f x = Some y.

Lemma update_commute (f : X -> option Y) (x1 x2 : X) (y1 y2 : Y) (H : x1 <> x2) :
pfun_eq (pfun_update (pfun_update f x1 y1) x2 y2) (pfun_update (pfun_update f x2 y2) x1 y1).