Fixpoint unenc s :=
match s with
| lambda (lambda 1) => Some 0
| lambda (lambda (app 0 s)) => match unenc s with Some n => Some (S n) | x=>x end
| _ => None
end.

(* Specifications: *)
Lemma unenc_correct m : (unenc (enc m)) = Some m.
Lemma unenc_correct2 t n : unenc t = Some n -> enc n = t.