End Subtract.
(* invalid is a purely functional test of invalidO/invalidX *)
Section Invalid.
Variables (K : ordType) (T : Type) (U : union_map_class K T).
Implicit Types (i : ctx U) (t : term T) (ts : seq (term T)).
Definition undefx i t :=
if t is Var n then
if onth (varx i) n is Some x then undefb x else false
else false.
Definition isundef i ts := ~~ uniq (getkeys ts) || has (undefx i) ts.

(* Specifications: *)
Lemma isundef_sound i ts :
all (wf i) ts -> isundef i ts -> ~~ valid (interp i ts).