natWhat about inputs that are not integers?
Principle of induction for nat:
For all x : nat, P(x) if
P(Zero) ( Base Case ) and∀x, P(x) ⇒ P(Succ x) ( Inductive Case )E.g. Let’s prove that for all n1 : nat, P(n1), where
P(n1) = ∀ n2 : nat, to_int (plus_nat n1 n2) ≡ (to_int n1) + (to_int n2)
Base Case: n1 = Zero.
E.g. Let’s prove that for all n1 : nat, P(n1), where
P(n1) = ∀ n2 : nat, to_int (plus_nat n1 n2) ≡ (to_int n1) + (to_int n2)
Base Case: n1 = Zero.
Inductive Case:
mul_natFor any inductive type of the form:
The principle of induction for type t is:
For all x : t, P(x) if:
v : b, P(C₀ v), andx : t, v : b₁, P(x) ⇒ P(C₁(v,x)), andx1, x2 : t, v : b₂, P(x1) and P(x2) ⇒ P(C₂ (v,x1,x2))nat: ∀ n : nat, P(n) if P(Zero) and ∀ m, P(m) ⇒ P(Succ m)
'a list: ∀ ℓ : 'a list', P(ℓ) if P([]) and ∀ x ∈ 'a, ∀ ℓ : 'a list, P(ℓ) => P(x::ℓ)
cs2041.org