a が述語で正当であることの意味を定義し、その述語に従う sbinのサブセットに名前を付けることができます。bin次に、 and の代わりに and を使用して関数をProgram Definition記述Program FixpointしDefinitionますFixpoint。再帰関数の場合、関数は構造的に再帰的ではないため、関数の引数のサイズが減少することを証明する手段も必要です。
Require Import Coq.Program.Program.
Fixpoint Legal (b1 : bin) : Prop :=
match b1 with
| O => True
| D O => False
| D b2 => Legal b2
| S (S _) => False
| S b2 => Legal b2
end.
Definition lbin : Type := {b1 : bin | Legal b1}.
Fixpoint to_un (b1 : bin) : nat :=
match b1 with
| O => 0
| D b2 => to_un b2 + to_un b2
| S b2 => Coq.Init.Datatypes.S (to_un b2)
end.
Program Definition zer (b1 : lbin) := O.
Program Fixpoint succ (b1 : lbin) {measure (to_un b1)} : lbin :=
しかし、この単純型付けのアプローチの方がおそらく簡単です。