## 1 Introduction and Motivation

There are several ways to define constructive real numbers. One of the best-known methods is to define them as Cauchy sequences of rational numbers with a Cauchy modulus. In our case, rather than we are not interested in a specific definition of real numbers, we are interested in their signed digit representation (SD code). Therefore, every quantifier on reals is non-computational, i.e. we write and . Theses decorations just mean that the bounded variable does not appear in the computational content of the proof. Logically one can ignore the decorations. By and we denote variables of reals. Instead of using the concrete real computationally, we use their signed digit representation in the extracted term.

Attention should be paid to the equality between reals numbers. By equality between two reals we mean the “real equality”, which is an equivalence relation and compatible with the usual operators and relations on the reals. The specific definition of the real equality depends on the definition of the real numbers. Generally, the real equality in not the same as the Leibniz equality. For instance, if one defines real numbers as Cauchy sequences with modulus, the real numbers and are equal w.r.t. the real equality but they are not Leibniz equal.

One of the first paper [13] where signed digits are used to represent real numbers, was published by Edwin Wiedmer in 1980.
The SD code of reals is similar to the binary code of reals but in addition to the digits and , the SD code has the digit , which we also denote by .
Since every real can be represented as , where is an integer and , we work on the interval .

A real number in has a binary representation if it can be written as

where and for every .

If one reads one by one the binary representation of a concrete real number, in each step the interval in which the real number is located, is halved. Thus from the binary code one can determine the real number arbitrarily exactly.

On the other hand it is not always possible to compute the binary representation of a given real number or even to compute the binary representation of out of the binary representations of and . Hereby “compute” means to get an algorithm which takes the binary streams of and and gives back the digits of the binary stream one by one in finitely many steps for each digit. That is, to compute finitely many binary digits of can only use finitely many binary digits of and . This is not possible due to the “gaps” in the binary representation. They are illustrated in Figure 1 at , , , and so on. Form the first digit (i.e. or ) of a real , one can decide or , with in general can not be done for constructive reals.

The signed digit code fills these gabs. For a real number it is given by

where for every .

As the illustration in Figure 2 shows, to compute the first signed digit of a real number one has to decide which of the cases , or holds. That this is possible, follows from the Comparability Theorem, which says that for reals , and with one has .

Figure 2 also shows that the SD code of a real number except and is not unique, whereas the binary code is “almost” everywhere unique.

A stream of signed digits is an infinite list of elements in

We will not prove something about signed digit streams directly, but we use the coinductively define predicate , which is given in the next section. For a real number a realiser of is a signed digit stream of . With the Soundness Theorem of program extraction proven in [8, 10, 14] the proofs of the corresponding theorems for the signed digit streams are obtained.

The idea to use coinductive algorithms to describe the operators on the reals goes back to Alberto Ciaffaglione and Pietro Di Gianantonio [4]. The idea to use coinductively defined predicates and the Soundness Theorem in this context is due to Ulrich Berger and Monika Seisenberger [2]. The notation and definitions in this paper are taken from Kenji Miyamoto and Helmut Schwichtenberg [7].

For computing the extraced terms and verifying the correctness of the proofs, we have used the proof assistant Minlog [6] in some cases. After each proof we state its computational content not in the notation of Minlog but in the notation of Haskell, since the runtime of the programs in Haskell is shorter, and one can define the terms in a more readable way.

We now proceed as follows:

In Section 2 we give a definition of and state the two axioms and for this predicate. The two lemmas 1 and 2 are often used in the proofs below. The main result of this work is Theorem 1, the Convergence Theorem, at the end of Section 3. An application of this theorem is shown in Section 4. Here we use Heron’s method together with the Convergence Theorem to get a signed digit representation of the square root of a non-negative real number from its signed digit representation. Section 5 is about potential extensions of this work.

## 2 Formalisation

In this section we use the theory of coinductively defined predicates given in [10, 14] to formalise the statement that a real has an SD representation.

###### Definition 1.

We define as the greaterst fixpoint of

Here is the existential quantifier where the quantified variable does not appear in the computational content.

In a short form we have . Therefore a realiser of has the type

Here we have identified with Sd itself. We define and with C we denote the only constructor of Str. Then in Haskell notation Str is given by

In this notation one easily sees that an element can be interpreted as an SD code with the first digit and tail . Sometimes we abbreviate by only writing .

From the definition of as greatest fixpoint of we get two axioms for .

where is an unary predicate variable. The first axiom says that is a fixpoint of and for obvious reasons it is called the elimination rule. Expressed in elementary formulas it is given by

The type of this axiom is and a realiser of it is given by the destructor with computation rule

The destructor takes a stream and returns a pair consisting of its first digit and its tail. With the projectors and one gets the first digit and the tail, respectively.

The second axiom is called the introduction axiom of and says that is the greatest fixpoint in the a strong sense. We use the following long version:

The type of this axiom depends on the type of the predicate variable :

A realiser of is the corecursion operator . It is given by the computation rule

where for . Here and are the two constructors of the type sum .
If has the form , the corecursion stops and we have as signed digit representation. If it has the form , the corecursion goes further with the new argument . In both cases we have obtained at least the first digit of the stream. With iteration of the corecursion, if necessary, we generate each digit of the stream one by one.

Now we prove two lemmas, which are often used in our proofs:

###### Lemma 1.

The predicate is compatible with the real equality, i.e.

###### Proof.

We apply to the predicate :

As one sees, it is sufficient to prove the second premise. Therefore we show

Let , with and be given. From we get and with and . We now define and and our goal follows directly because of . ∎

In the following proofs this theorem is used tacitly. If one have a model of reals in which the real equality is the same as the Leibniz equality, one do not need this theorem. The extracted term of it is given by

For stream of the form this term is the identity function. Since we always deal only with such streams, we drop this term hereafter.

###### Lemma 2.

###### Proof.

We apply to the predicate

This leads to the formula

In order to prove the goal formula, it is sufficient to prove the second premise. Therefore the new goal formula is

This is almost a tautology. The only part one has to consider is . From and we get and therefore . ∎

Formally the extracted term of this proof is given by

If we use the computation rule of once, we get , which is identified with C itself. Therefore the constructor C is actually the computational content of this lemma.

## 3 Convergence Theorem

The aim of this chapter is to prove the convergence theorem in the SD code. It says that the limit of each convergent sequence in is also in . As extracted term we expect a function which takes a sequence of signed digit streams (i.e. a term of type ) and its modulus of convergence and returns a signed digit stream.

We do the proof step by step and therefore we first prove a few lemmas:

###### Lemma 3.

###### Proof.

Since both formulas are shown analogously we only show the first formula. Therefore we use the introduction axiom of , which is given by

For we insert . Hence it is sufficient to prove the second premise. Let , , , and be given. Our goal is

From we get and with , , and . Independent on and we always get out of , and .
In order to prove the remaining part of the formula, we do case distinction on :

If , we define and . Here and follow directly and we also have

If , we define and . We directly have . In this case we prove . Hence we show , and . and are already given and follows directly from and .

The last case is . Because of , and it is only possible that is equal to and therefore . Hence we define and . Then and are obviously true and is true because has the SD representation .
∎

A realiser of the first formula in this lemma is a function f, which takes a signed digit stream of a real number and returns a signed digit stream of if .

Using the formal definition of the extracted term we get for f the term

where for and is the infinite list with each entry equal to . Another way to characterise this function f is to give its computation rules:

Analogously as extracted term of the second statement of this lemma, we get a function which is characterised by the rules

It takes a signed digit stream of a real and returns a signed digit stream of if .

With this lemma we can now prove the following lemma easily:

###### Lemma 4.

###### Proof.

If we keep the definition of the functions f and g form the computational context of the privios lemma, the computational content of this lemma is given by

Again we give a more readable characterisation of D by the computation rules

###### Lemma 5.

###### Proof.

gives and with . We show only because the proof of is done analogously. Case distinction on leads to the following three cases:

gives ,

gives and

gives .

In each case we get by using Lemma 2 twice.
∎

We denote the extracted term of the proven statement by . From the proof and the fact, that the extracted term of Lemma 2 is given by C, one easily sees that has the following computation rules:

Analogously, the computational content of the statement is characterised by

Before we prove the Convergence Theorem, we have to give a definition of convergence. In this definition the witness of convergence is included:

###### Definition 2.

Let a real , a sequence of reals and a modulus be given. We say convergences to with modulus if

###### Theorem 1.

Let be a sequence of reals in which converges to a real with a modulus , then also is in .

Expressed in a formula:

###### Proof.

We show the equivalent formula

The existence quantifier is an inductively defined predicate and given by . This means that in contrast to the quantified variable is also part of the computational content.

To prove this formula we apply to the predicate

and show the second premise, which is given by

Let , , , and be given. We show

Regardless of the choice of and we get from and with it follows . Therefore in each case we consider as proven.

Specializing to leads to and triple application of gives and such that or in short notation

Now we do case distinction on this representation of .

If has one of the forms , , , or , it follows that . In this case we choose

then and follow directly. Furthermore we define

for all , where , and

for all . The formular is a direct consequence of and it remains to show . We calculate

Lemma 5 gives . Futhermore we have and therefore

Thus implies and Lemma 4 applied twice gives .

If has one of the forms , , , or , it follows . Here we define

The proof in this case is analogous to the proof of the first case.

It remains to consider the case that has one of the forms , , , or . Here we have and we define

The formulars and are obvious. In order to prove

we define

The second part of the conjunction follows from , which is given. And because of

for every , we have by Lemma 4. ∎

We denote the extracted term by Lim. It has the type

It takes the modulus of convergence and the sequence of streams and returns the stream of the limit value. In order to give an at most readable characterisation of Lim, we define the following sets:

R | |||

M | |||

L |

These three sets correspond to the three cases in the proof and therefore we have the following rule for Lim:

Because of readability, we have omitted some brackets, for example shall be read as .
The functions D, and are the computational content of the lemmas above and, as in the proof, between natural numbers means their maximum.

One note that the definition of the new sequence is not unique. For reasons of efficiency one should be flexible with the choice of the new sequence, which is called in the proof above. For example by choosing one can replace by . The efficiency depends on the concrete sequence. In the next section we define the Heron sequence and apply it to Lim. In this case the definition with is most efficient.

Since the definition of this function is not so easy, we give an example for an implementation as a Haskell program. First the sets R and L are realised as Boolean functions:

rAux :: Str -> Bool rAux (SdR :~: SdR :~: v) = True rAux (SdR :~: SdM :~: v) = True rAux (SdR :~: SdL :~: SdR :~: v) = True rAux (SdR :~: SdL :~: SdM :~: v) = True rAux (SdM :~: SdR :~: SdR :~: v) = True rAux (SdM :~: SdR :~: SdM :~: v) = True rAux v = False lAux :: Str -> Bool lAux (SdL :~: SdL :~: v) = True lAux (SdL :~: SdM :~: v) = True lAux (SdL :~: SdR :~: SdL :~: v) = True lAux (SdL :~: SdR :~: SdM :~: v) = True lAux (SdM :~: SdL :~: SdL :~: v) = True lAux (SdM :~: SdL :~: SdM :~: v) = True lAux v = False

Then one can define cCoILim by case distinction:

cCoILim :: (Int -> Int) -> (Int -> Str) -> Str cCoILim m f | rAux (f (m 4)) = SdR :~: (cCoILim n (funcR m f)) | lAux (f (m 4)) = SdL :~: (cCoILim n (funcL m f)) | otherwise = SdM :~: (cCoILim n (funcM m f)) where n = \p -> (m (p+1))

In this implementation the constructor C is denoted by `:~:`

and written as an infix. The tree elements in Sd are given by SdR, SdM and SdL and shall be interpreted by , and , respectively.

## 4 Square Root

###### Definition 3.

We define by the computation rules

Comments

There are no comments yet.