Tuesday, 11 November 2025

Chapter 8 - Exercise 6

Exercise 8.6

Consider the following mathematical text:

‘If $k$, l and m are integers, $m$ being positive, then one says that $k$ is congruent to l modulo $m$ if $m$ divides $k−l$. We write $k ≡l(\mod  m)$ to indicate that $k$ is congruent to $l$ modulo m$.

Hence $−3 ≡17(\mod 5)$, but not $−3 ≡−17(\mod 5)$.

If $k ≡l(\mod m)$ then also $l ≡k(\mod m)$.

$k ≡l(\mod m)$ if and only if there is an integer $u$ such that $k= l+um$.’

(a) Rewrite the texts in a formal form, as a list of definitions. Assume that $\mathbb{Z}$ is a type. Employ the flag format. Formalise $k ≡l(\mod m)$ as $eqv(k,l,m,u)$, with$u$ a proof that $m$ is positive.

(b) Indicate the scopes of all variables and constants introduced in the formal text.

(c) Identify all instantiations of the parameter lists introduced in the formal text and check that the type conditions are respected.


(a) The following is a flag-format formalisation of the text.

Note the author's solution has $\implies$ instead of $\iff$ for line (6).


(b) The scopes of the variables and constants are as follows:

  • $k,l,m$ have local scope lines (2) to (6).
  • $u$ has local scope lines (3) to (6).
  • $v, p_1, p_2$ have global scope.
  • $\textit{eqv}, q, r$ have global scope.
  • $n$ has scope limited to the expression $(k=l+nm)$ at line (6).


(c) The instantiations of introduced parameter lists are as follows:

  • line (5) $\textit{eqv}(k,l,m,u)$ is an identity instantiation.
  • line (5) $\textit{eqv}(l,k,m,u)$ is not an identity instantiation. The type of $l$ and $k$ match the introduced types $\mathbb{Z}$. The type of $m$ is the expected $\mathbb{Z}$. The type of $u$ is $m>0$ as expected.
  • line (6)  $\textit{eqv}(k,l,m,u)$ is an identity instantiation.
  • line (8)  $\textit{eqv}(-3, 17, 5, v)$ has $-3, 17, 5$ of the expected type $\mathbb{Z}$ and $v$ is of type $m>0$  with $m=5$.
  • line (9)  $\textit{eqv}(-3, -17, 5, v)$ has $-3, -17, 5$ of the expected type $\mathbb{Z}$ and $v$ is of type $m>0$ with $m=5$.


Monday, 10 November 2025

Chapter 8 - Exercise 5

Exercise 8.5

Identify the definitions in the following text and rewrite the text in a formal form, using exclusively the definition format, as demonstrated in Figure 8.8. Assume that $\mathbb{R}$ is a type. Employ the flag format and the set notation $\{x : \mathbb{R} | P x\}$.

‘The real number $r$ is rational if there exist integer numbers $p$ and $q$ with $q \ne 0$ such that $r = p/q$. A real number that is not rational is called irrational. The set of all rational numbers is called $\mathbb{Q}$. Every natural number is rational. The number 0.75 is rational, but $\sqrt{2}$ is irrational.’


The following is the flag format version of the given text.


Note: In line (6) the definition rational is used with an argument that is a natural number, $n : \mathbb{N}$. However the definition of rational at line (3) specifies the argument needing to be of type $\mathbb{R}$. This could be a type-mismatch but we can overlook this because natural numbers are a subset of the real numbers, and so $n \in \mathbb{R}$ .


Chapter 8 - Exercise 4

Exercise 8.4

The following formal text in flag format is about some well-known notions in algebra, where ‘op’ means a binary operation on $S$, in Curried form (cf. Remark 1.2.6).

(a) Translate the text into a more usual format, as you might find in a textbook. Use infix notation when appropriate.

(b) Underline all variables that are bound to a binding variable introduced in the text.

(c) Rewrite lines (1) and (2) in the format $Γ \triangleright a(...) := M : N$ as described in Section 8.5.


(a) 

(1) Given a set $S$ and a binary operator op that takes two elements of $S$ and returns an element of $S$, then $(S,\textit{op})$ is a semigroup if for all $x, y, z \in S$

$$  x \textit{ op }     (y \textit{ op } z) \; = \;  (x \textit{ op } y) \textit{ op } z  $$

(2) Given a semigroup $(S,\textit{op})$, the element $e \in S$ is a unit if for all $x \in S$

$$ x \textit { op } e = x \quad \land \quad e \text{ op } x = x $$

(3) A semigroup $(S,\textit{op})$ is a monoid if there exists an element $e \in S$ that is a unit.

(4) The unit of a semigroup is unique. That is, if $e_1$ and $e_2$ are units of a semigroup then $e_1 = e_2$.


(b) The following shows all the bound variables.


(c) 

(1)

$$ S:*_s, \textit{op}:S \to S \to S \; \triangleright \;  \textit{semigroup}(S, \textit{op}) \; := \; \forall_{x,y,z:S} \left ( \textit{op} \; x \;  (\textit{op} \; y \; z) = \textit{op} \;  (\textit{op} \; x \; y) \; z \right ) \; : \; *_p $$

(2) 

$$ \begin{gather*} S:*_s, \textit{op}:S \to S \to S,  u:\textit{semigroup}(S, \textit{op}), e:S \; \triangleright \\ \\ \textit{unit}(S, \textit{op}, u, e) \; := \; \forall_{x:S} \left ( \textit{op} \; x \; e = x \land \textit{op} \; e \; x =x  \right )  \; : \; *_p  \end{gather*}$$


Sunday, 9 November 2025

Chapter 8 - Exercise 3

Exercise 8.3

Consider the formal text in Exercise 8.2. Describe the partial order representing the dependencies between the definitions given in this text. (Cf. the end of Section 8.5.)


The following is the formal text in Exercise 8.2


There is a partial order because some definitions depend on others, but some don't. 

Let's first list the dependencies.

  • $bounded\text{-}from\text{-}above$ does not depend on another definition
  • $upper\text{-}bound$ does not depend on another definition
  • $least\text{-}upper\text{-}bound$ depends on $upper\text{-}bound$
  • $p_4$ depends on $least\text{-}upper\text{-}bound$
  • $S$ does not depend on another definition
  • $p_6$ depends on $S$
  • $p_7$ depends on $bounded\text{-}from\text{-}above$ and $p_6$ (which depends on $S$)
  • $p_8$ depends on $least\text{-}upper\text{-}bound$ (which depends on $upper\text{-}bound$) and $p_6$ (which depends on $S$)

The following summarises these dependencies visually.

We can see definitions like $S$ and $bounded\text{-}from\text{-}above$ do not depend on other definitions, but are depended on by other definitions.

We can also see some definitions like $p_7$ depend on more than one definition.

Finally, we can see there is no relation between $bounded\text{-}from\text{-}above$ and $S$. This is why the dependencies are a partial order.


Saturday, 8 November 2025

Chapter 8 - Exercise 2

Exercise 8.2

The formal text represented below in flag format, is about a number of well-known notions in analysis, containing some statements with omitted proofs.

(a) Translate the text into a more usual format, as you might find in a textbook. (Note: $∃^1$ expresses unique existence; ‘there exists exactly one ...’.)

(b) Which of the eight lines are formalised definitions? Which are formalised mathematical statements?

(c) Which constants have been introduced in the text and which constants will have been introduced before?

(d) Underline all instantiations of parameter lists in the formal text and explain accurately what has been instantiated for what, and why that is correct.


(a) For a set $V \subseteq \mathbb{R}$, a subset of the real numbers, 

(1) $V$ is bounded from above if there exists a $y \in \mathbb{R}$, such that for all $x \in \mathbb{R}$,  it is true that $ x \in V \implies x \le y $.

(2) For a given $s \in \mathbb{R}$, $s$ is an upper bound of $V$ if for all $x \in R$, it is true that $ x \in V \implies x \le s $.

(3) For a given $s \in \mathbb{R}$, $s$ is a least upper bound of $V$ if $s$ is an upper bound and for all $x \in \mathbb{R}$ it is true that $ x < s $ implies that $x$ is not an upper bound of $V$.

(4) If $V$ is non-empty, and $V$ is bounded from above, then there exists exactly one $s \in \mathbb{R}$ that is the least upper bound of $V$.

(5) $S$ consists of elements $x$ which are elements of $\mathbb{R}$, where each element $x$ is of the form $\frac{n}{n+1}$ where $n$ is some natural number.

(6) That set $S$ is a subset of $\mathbb{R}$.

(7) That set $S$, which is a subset of $\mathbb{R}$, is bounded from above.

(8) The number 1 is the (only) least upper bound of the set $S$, which is a subset of $\mathbb{R}$, 


(b) All the eight lines are formalised definitions because formalised mathematical statements are equivalent to formalised definitions, as explained in Chapter 8 section 9.

However, it can be practical to consider a distinction between a definition that is general in application, and a mathematical statement about specific objects. In this case lines (1), (2),  and (3) can be considered formalised definitions, and (4), (5), (6), (7) and (8) considered formalised mathematical statements about specific objects, here $S$ and $s$.


(c) All constants are introduced in the text, except the following which are introduced before: $*_s, *_p, \mathbb{R}, \mathbb{N}, \emptyset$.

We could argue that $\exists, \exists^1, \forall$ are also constants referencing a lambda-expression, which we've seen in earlier chapters.


(d) The following shows instantiations of parameter lists,

Let's discuss each relevant line.

(3) $upper \text{-} bound(V,u,s)$ is defined in line (2), and in line (3) has $V$ instantiated for $V$, $u$ for $u$, and $s$ for $s$.

(3) The second instance of $upper \text{-} bound$ has $V$ instantiated for $V$, $u$ for $u$, and this time $x$ for $s$. Here $x$ has the compatible type $\mathbb{R}$, and here makes sense as the upper bound refers to all $x \in \mathbb{R}$, albeit $x<s$,

(3) $bounded \text{-} from \text{-} above(V,u)$ is defined in line (1), and here has $V$ instantiated for $V$, and $u$ for $u$.

(4) $least \text{-} upper \text{-} bound(V,u,s)$ is defined in line (4), and here has $V$ instantiated for $V$, $u$ for $u$, and $s$ for $s$. 

(7) Here $bounded \text{-} from \text{-} above(S,p_6)$ has $S$ instantiated for $V$, and $p_6$ instantiated for $u$. This is because the relevant set is $S:= \ldots :*_s$, and $p_6$ is a proof that $S$ is a subset of $\mathbb{R}$.

(8) Here $least \text{-} upper \text{-} bound(S, p_6, 1)$ has $S$ instantiated for $V$, and $p_6$ instantiated for $u$, and 1 for $s$. This is because the relevant set is $S:= \ldots :*_s$, and $p_6$ is a proof that $S$ is a subset of $\mathbb{R}$. The 1 is the specific element of $\mathbb{R}$ the proof $p_8$ makes an assertion about.


Friday, 7 November 2025

Chapter 8 - Exercise 1

Exercise 8.1

In Section 8.7, we gave the name $p(m,n,u)$ to a proof of the proposition

$$∃x,y : \mathbb{Z}. (mx+ny = 1)$$

in the context $Γ ≡ m : \mathbb{N}^+, n : \mathbb{N}^+, u : coprime(m,n)$.

Assume that we have constructed, in context $m : \mathbb{N}^+, n : \mathbb{N}^+$, a proof (i.e. an inhabitant) $q(m,n)$ of the proposition

$$coprime(m,n) ⇒coprime(n,m)$$

Find an inhabitant of

$$∃x,y : \mathbb{Z}. (nx+my = 1)$$

in context $Γ$.


We start with $p$ which is the name given to the proof of the proposition

$$ \exists x,y : \mathbb{Z}. (mx+ny = 1) \tag{i}$$

The name also carries with it the ordered list of arguments $(m,n,u)$. The first two arguments are the positive natural numbers $n$ and $m$ expected by the proof. The third argument is a proof that the first two arguments, $m$ and $n$ (in that order), are co-prime.


We want to prove the proposition

$$ \exists x,y : \mathbb{Z}. (nx+my = 1) \tag{ii}$$

The order of $n$ and $m$ is different to (i), and this means $p(m,n,u)$ is not a proof of (ii).


We are given a proof $q(m,n)$ of the proposition $coprime(m,n) \implies coprime(n,m)$, that is

$$q(m,n) \; : \; coprime(m,n) \implies coprime(n,m)$$

So the proof $q(m,n)$ applied to $u$, the proof $coprime(m,n)$, gives us a proof $coprime(n,m)$.

$$ q(m,n)u \; : \; coprime(n,m)$$

We also check that the context of $q$ allows it to be used in the context in which we apply it to $u$, that is, $\Gamma$. The context of $q$ us a subset of $\Gamma$ so can be used, and it can be used with $u$ because $u$ is defined in $\Gamma$.


If we are to use $p$ as a proof of $∃x,y : \mathbb{Z}. (nx+my = 1)$, the order of the variables $n$ and $m$ require the proof to be of the form $p(n,m,?)$ and not $p(m,n,?)$. The $?$ a proof that $n$ and $m$ (in that order) are co-prime. We have that from above.


And so $p(n,m,q(m,n)u)$ is a proof of the proposition (ii). That is

$$ \Gamma \;  \triangleright \;  p(n,m,q(m,n)u) \; : \; \exists x,y:\mathbb{Z}.(nx + my = 1)$$

We can choose to give this proof a name, $r(m,n.u)$

$$ \Gamma \;  \triangleright \; r(m,n,u) \; := \;  p(n,m,q(m,n)u) \; : \; \exists x,y:\mathbb{Z}.(nx + my = 1)$$