Here are some examples that I'm using to learn functional programming and develop Formal Proofs using Agda as the proof assistant.
- Exploring notation of booleans, natural numbers and binary
- Add two numbers (natural and binary)
- Incrementing boolean
- Find patterns in binary numbers
Equalities are defined between objects of the same type. Two objects are equal if we have a proof of their equality. In Agda, we can represent this by means of a function which takes two instances of some type M, and maps this to a proof of equality.
- Data types:
Dec, Odd, Even, Empty, Not
- Receiving 2 booleans
a
andb
and a proof thata
is true, proof thatand a b
is true - Given a Bool
b
proof thatnot(not b) ≡ b
- Commutation: proof that
add a b ≡ add b a
- De Morgan's law:
not (and a b) ≡ or (not a) (not b)
- Given 2 booleans
a
andb
and a proof that∀ (e : b ≡ or a (not a))
returns aNat
- Subtraction of
Nat
- Adding
Even
numbers - Proving that a number is
Even
- Proof that doubling a number results in an
Even
number
- reflexivity:
refl : ∀ {r} -> (r == r)
- symmetry:
sym : ∀ {r s} -> (r == s) -> (s == r)
- transitivity:
trans : ∀ {r s t} -> (r == s) -> (s == t) -> (r == t)
- congruency:
cong : ∀ {A B} {m n : A} -> (f : A -> B) -> m ≡ n -> f m ≡ f n
A relation is said to be a congruence for a given function if it is preserved by applying that function. Ife
is evidence thatx ≡ y
, thencong f e
is evidence thatf x ≡ f y
, for any functionf
. - associativity:
assoc : ∀ a b c -> a + (b + c) ≡ (a + b) + c
-- TODO: write about implicit arguments