[a number/numbers] [x is natural] [the zero] [0 @ the zero]
[x is nonzero @ x is not equal to 0] [the one] [1 @ the one]
[x is trivial @ x = 0 \/ x = 1] [x is nontrivial @ x is not trivial]

Axiom _ZONat.   0 and 1 are natural numbers and 0 != 1.

[the sum of n and m] [n + m @ the sum of n and m]
[the product of n and m] [n * m @ the product of n and m]

Axiom _AddNum.  For all numbers m,n (m + n) is a number.
Axiom _AddNat.  For all natural numbers m,n (m + n) is natural.
Axiom _AddZero. For all numbers n (0 + n = n and n + 0 = n).

Axiom _MulNum.  For all numbers m,n (m * n) is a number.
Axiom _MulNat.  For all natural numbers m,n (m * n) is natural.
Axiom _MulZero. For all numbers n (0 * n = 0 and n * 0 = 0).
Axiom _MulUnit. For all numbers n (1 * n = n and n * 1 = n).

Axiom AddComm.  For all numbers m,n (m + n = n + m).
Axiom AddAsso.  For all numbers l,m,n (l + (m + n) = (l + m) + n).
Axiom MulComm.  For all numbers m,n (m * n = n * m).
Axiom MulAsso.  For all numbers l,m,n (l * (m * n) = (l * m) * n).

Axiom AddCanc.  Let n,m,l be numbers.
    If (l + n = l + m \/ n + l = m + l) then n = m.

Axiom MulCanc.  Let n,m,l be numbers.
    If (l * n = l * m \/ n * l = m * l) and l is nonzero then n = m.

Axiom AMDistr.  For all numbers l,m,n
    l * (m + n) = (l * m) + (l * n) and
    (m + n) * l = (m * l) + (n * l).

Axiom ZeroAdd.  For all numbers m,n if m + n = 0 then m = 0 and n = 0.
Lemma ZeroMul.  For all numbers m,n if m * n = 0 then m = 0 or n = 0.


[n is lesseq than m] [n <= m @ n is lesseq than m]
[the diff of m and n] [m - n @ the diff of m and n]
[n < m @ n <= m /\ n != m]

Definition DefLE.   Let n,m be numbers.
    n <= m iff for some number l (n + l = m).

Axiom _DefDiff.  Let m,n be numbers and m <= n.
    Then (n - m) is a number and m + (n - m) = n.

Axiom _NatDiff. Let m,n be natural numbers and m <= n.
    Then (n - m) is natural.

Lemma LERefl.   For every number n (n <= n).

Lemma LEAsym.   For all numbers n,m (n <= m /\ m <= n => n = m).
Proof.
    Let n,m be numbers such that (n <= m /\ m <= n).
    We have n + ((m - n) + (n - m)) = n + 0.
    Hence (m - n) = 0 and (n - m) = 0.
qed.

Lemma LETran.   For all numbers n,m,l (n <= m /\ m <= l => n <= l).

Axiom LETotal.  For all numbers n,m (n <= m \/ m < n).

Lemma MonAdd.   Let n,l be numbers.
    If l is nonzero then n < n + l.

Axiom IH.   For all natural numbers n,m (n < m => n -<- m).

Axiom MonMul.   Let n,l be natural numbers.
    If l is nonzero then n <= n * l.


[n divides/divide m] [n | m @ n divides m] [n is dividing m @ n | m]
[a divisor/divisors of n @ a natural number dividing n] [x is prime]
[the quot of m and n] [m / n @ the quot of m and n]

Definition DefDiv. Let n,m be natural numbers.
    n divides m iff for some natural number p (m = n * p).

Axiom _DefQuot. Let m,n be natural numbers and m | n.
    Then n / m is a natural number and m * (n / m) = n.

Definition DefPrime. Let n be a natural number.
    n is prime iff n is nontrivial and
        for every divisor m of n (m = 1 \/ m = n).


Lemma DivTrans. Let l,m,n be natural numbers.
    If l | m and m | n then l | n (by DefDiv,MulAsso).

Lemma DivSum. Let l,m,n be natural numbers.
    If l | m and l | n then l | m + n.
Proof.
    Suppose that l | m and l | n.
    Then m + n = l * ((m / l) + (n / l)) (by AMDistr).
    Hence the thesis (by DefDiv).
qed.

Lemma DivMin. Let l,m,n be natural numbers.
    If l | m and l | m + n then l | n.
Proof.
    Suppose that l | m and l | m + n.
    Take a natural number p equal to m / l.
    Take a natural number q equal to (m + n) / l.
    Case q < p.
        Take a natural number r equal to p - q.
        We have (l * q) = ((l * q) + (l * r)) + n (by AMDistr).
        Then (l * r) + n = 0 (by AddAsso, AddCanc). Hence n = 0.
    end.
    Case p <= q.
        Take a natural number r equal to q - p.
        We have (l * p) + (l * r) = (l * p) + n (by AMDistr).
        Hence the thesis (by AddCanc,DefDiv).
    end.
qed.

Lemma PrimDiv. Every nontrivial natural number k has a prime divisor.
Proof by induction.
    Let k be a nontrivial natural number.
    Case k is prime. Obvious.
    Case k is not prime.
        Take a divisor q of k such that q != 1 and q != k.
        q is nontrivial and q < k.
        Take a prime divisor r of q.
        Then r divides k (by MulAsso, DefDiv).
    end.
qed.


Lemma PrimDivProd.  For all natural numbers n,m,p
    if p is prime and p divides (n * m) then p divides n or p divides m.
Proof by induction on ((n + m) + p).
    Let n,m,p be natural numbers.
    Assume that p is prime and p divides (n * m).
    Take a natural number k equal to (n * m) / p.

    Case p <= n.
        Take a natural number q equal to n - p.
        Then p divides q or p divides m (by IH).
        proof.
            We have p * k = (p * m) + (q * m) (by AMDistr).
            Then p divides q * m (by DefDiv, DivMin).
            (n + m) + p = ((q + m) + p) + p (by AddAsso, AddComm).
            Then (q + m) + p < (n + m) + p.
        end.
        If p divides q then p divides n (by DefDiv,DivSum).
        We have the thesis.
    end.

    Case p <= m.
        Take a natural number q equal to m - p.
        Then p divides n or p divides q (by IH).
        proof.
            We have p * k = (p * n) + (n * q) (by MulComm,AMDistr).
            Then p divides n * q (by DefDiv, DivMin).
            (n + m) + p = ((n + q) + p) + p (by AddAsso, AddComm).
            Then (n + q) + p < (n + m) + p.
        end.
        If p divides q then p divides m (by DefDiv,DivSum).
    end.

    Case n < p and m < p.
        Let us prove that k < p.
            Assume the contrary. We have p <= k.
            Take natural numbers a,b,c such that
                a = p - n and b = p - m and c = k - p (by _).
            We have n * m = (((n * m) + (n * b)) + (a * p)) + (p * c) (by AMDistr).
            We have n * m = (n * m) + (((n * b) + (a * p)) + (p * c)) (by AddAsso).
            Then (a * p) = 0. p is nonzero. If a is zero then n = p.
            We have a contradiction.
        end.

        Case k = 0. Obvious.

        Case k = 1.
            We have n * m = p.
            Then n = p or m = p (by MulComm,DefPrime,DefDiv).
        end.

        Case k is nontrivial.
            Take a prime divisor r of k.
            Take a natural number s equal to k / r.

            Let us show that r divides n or r divides m (by IH).
                We have r * (p * s) = n * m.
                Then r divides (n * m).
                Let us prove (n + m) + r < (n + m) + p.
                    We have r <= k.
                    Take a number a equal to k - r.
                    Take a nonzero number b equal to p - k.
                    Then ((n + m) + r) + (a + b) = (n + m) + p (by AddAsso).
                end.
            end.

            Case r divides n.
                Take a natural number q equal to n / r.

                Let us show that p divides q * m.
                    p * (s * r) = (r * q) * m.
                    (p * s) * r = (q * m) * r.
                    p * s = q * m (by MulCanc).
                end.

                Let us show that (q + m) + p < (n + m) + p.
                    q <= n (by MonMul, MulComm).
                    If n = q then r = 1 (by DefPrime,MulCanc).
                    Take a nonzero number d equal to n - q.
                    ((q + d) + m) + p = ((q + m) + p) + d (by AddComm,AddAsso).
                end.

                Then p divides q or p divides m (by IH).
                If p divides q then p divides n.
                Indeed q divides n (by MulComm,DefDiv). end.
            end.

            Case r divides m.
                Take a natural number q equal to m / r.

                Let us show that p divides n * q.
                    p * (s * r) = n * (r * q).
                    (p * s) * r = (n * q) * r.
                    p * s = n * q (by MulCanc).
                end.

                Let us show that (n + q) + p < (n + m) + p.
                    q <= m (by MonMul, MulComm).
                    If m = q then r = 1 (by DefPrime,MulCanc).
                    Take a nonzero number d equal to m - q.
                    (n + (q + d)) + p = ((n + q) + p) + d (by AddComm,AddAsso).
                end.

                Then p divides n or p divides q (by IH).
                If p divides q then p divides m.
                Indeed q divides m (by MulComm,DefDiv). end.
            end.
        end.
    end.
qed.

[x is relatively prime to y]

Definition DefRelPr. Let n,m be natural numbers.
    n,m are relatively prime iff n,m have no common nontrivial divisor.


[x is rational] [the square of n @ n * n]
[the square root of n] [sqrt(n) @ the square root of n]

Definition DefRat. Let q be a number.
    q is rational iff there exist relatively prime natural numbers n,m
        such that m is nonzero and q * m = n.

Axiom _SqrtNum. The square root of any number is a number.
Axiom DefSqrt. The square of the square root of any number n is n.


Theorem Main.
    The square root of any prime natural number p is not rational.
Proof.
    Let p be a prime natural number such that sqrt(p) is rational.
    Take relatively prime natural numbers n,m so that sqrt(p) * m = n.
    Then p * (m * m) = (n * n) (by MulAsso, MulComm, DefSqrt).
    Hence p divides n and p is nontrivial.
    Choose a natural number k equal to n / p.
    Then we have p * (m * m) = p * (k * n).
    m * m = (p * k) * k (by MulCanc, MulComm).
    Hence p divides m * m. Hence p divides m.
    We have a contradiction (by DefRelPr).
qed.


