# "Strong typing vs. strong testing"

Pascal J. Bourguignon pjb at informatimago.com
Wed Oct 13 23:46:30 CEST 2010

```Steven D'Aprano <steve at REMOVE-THIS-cybersource.com.au> writes:

> On Wed, 13 Oct 2010 17:28:42 +0200, Pascal J. Bourguignon wrote:
>
>>>> But what exactly *is* this number? Is it 0.25, 1.57 or 90?
>>>
>>> That's the wrong question. It's like asking, what exactly "is" the
>>> number twenty-one -- is it "one and twenty", or 21, or 0x15, or 0o25,
>>> or 21.0, or 20.999... recurring, or 63/3, or XXI, or 0b10101, or "vinet
>>> et un", or any one of many other representations.
>>
>> This is not the wrong question.  These are two different things.
>
> Which is why I said it was LIKE asking the second.
>
>
>> In the case of 0.25, 1.57 or 90, you have elements of the same set of
>> real numbers ℝ, which are used to represent the same entity, which IS
>> NOT a number, but an angle.  Angles are not in the ℝ set, but in ℝ/2π,
>> which is an entirely different set with entirely different properties.
>
> It's quite standard to discuss (say) sin(theta) where theta is an element
> of ℝ. The fact that angles can extent to infinity in both directions is
> kind of fundamental to the idea of saying that the trig functions are
> periodic.

You're falling in a trap.  It's costumary in mathematics to ellide the
trivial isomorphims.  But they're still there.

When you're writing:  2+3.4 you have to use the trivial isomorphims
between ℕ and the subset of ℝ called 1.0ℕ, let's call it t, so that when
you write:  2+3.4
you actually mean t(2)+3.4
with t(2) ∈ 1.0ℕ ⊂ ℝ
3.4  ∈ ℝ
and + being the additive operator on ℝ with 0.0 as neutral element.

Similarly, when you write sin(θ) with θ ∈ ℝ
what you actually mean is sin( angle-equivalence-class-of(θ) )
with angle-equivalence-class-of(θ) ∈ ℝ/2π.

As a programmer, it should be obvious to you.

(defstruct angle
(representant 0.0 :type real))

(defun sinus (angle)
...)

(sinus 0.2) --> error

(sinus (make-angle :representant 0.2)) --> 0.19866933079506122

It just happen that

(defun cl:sin (representant)
(sinus (make-angle :representant representant)))

But this should not confuse you, nor the type checking.

>> So you have different pairs of sets and different representationnal
>> mapping.  There's very little in common between an angle of 90 degree,
>> and the number 21.
>
> Would it have been easier to understand if I had made the analogy between
> angles and (say) time? A time of 1 minute and a time of 60 seconds are
> the same time, regardless of what representation you use for it.

Yes, but time has a dimension (time), so you don't confuse it with
random numbers.

>>> Likewise, it doesn't matter whether you write 45° or π/4 radians, the
>>> angle you are describing -- the number -- is the same.
>>
>> No.  The numbers ARE different.  One number is 45, the other is π/4.
>> What is the same, is the angle that is represented.
>
> Fair enough. I worded that badly.

--
__Pascal Bourguignon__                     http://www.informatimago.com/

```