Re: "Strong typing vs. strong testing"

T

Tim Bradshaw

Angles aren't "true" units, as they are ratios of two lengths. They
are more of a "pseudo" unit.

That's right, in fact angles are pure numbers. In general any function
which raises its argument to more than one power (for instance anything
with a non-trivial power series (Taylor series) expansion) doesn't make
much sense if its argument has units. Transcendendal functions are all
like that, of course.

For instance sin(x) = x + s^3/6 + O(x^5), so sin(1m) would be 1m +
1m^3/6 + O(m^5), and it doesn't make sense to add metres and cubic
metres (let alone the infinite number of higher-order terms!).
 
T

Thomas A. Russ

Trigonometric functions do take arguments of particular units: radians
or (less often) degrees, with conversion needed if you use the "wrong"
unit.

But radians are dimensionless.

The definition of a radian is length/length (or m/m) which simplifies to
dimensionless.

In fact, the units package in Lisp that I worked on actually handles
this by making "radian" one of the dimensionless "units" precisely so
that one can use degrees and radians with appropriate conversion. But
they remain dimensionless. Interestingly, that also allows one to treat
percent (%) as a dimensionless unit with a conversion factor of 1/100.
 
B

BartC

Thomas A. Russ said:
But radians are dimensionless.

But they are still units, so that you can choose to use radians, degrees or
gradians for literals, so that functions that take angle arguments can
verify they are angles and not just numbers, and so that they can be
displayed appropriately.

You can't do all that if angles are just numbers.
 
T

Tim Bradshaw

You can't do all that if angles are just numbers.

I think that the discussion of percentages is relevant here: angles
//are// just numbers, but you're choosing a particular way of
displaying them (or reading them). 100% //is// 1, and 360° //is// 2π.
So really, like, for instance, number base, they're things that exist
for I/O but not inside the system. At least for the purposes of doing
maths: computer type systems often don't have very much to do with
maths (for instance floating-point numbers are obviously a very
important type, but don't map onto anything that would be interesting
to a theoratical physicist).
 
T

Thomas A. Russ

BartC said:
But they are still units, so that you can choose to use radians, degrees
or gradians for literals, so that functions that take angle arguments
can verify they are angles and not just numbers, and so that they can be
displayed appropriately.

You can't do all that if angles are just numbers.

But if you need to supply the units, that only really helps you when you
actually input them. The problem comes when you have computed
quantities, such as you might get when trying to do more involved
computations.

If you have a system where 10m/1m => 10 then it means you couldn't have
a calculation like 100km*sin(10m/1m) and have it work, because the
dimensionless 10 that you get from the calculation would be incorrect.
You would have to know something else about the division in order to get
the correct dimensionless "units".

This is also an issue in sorting out torque and work, since they also
have the same base units. You can't really tell if N*m is supposed to
be a measure of work or of torque, which also means that you can't use
that to distinguish the results of such a multiplication just by using
dimensional analysis. Often it works, but sometimes you just run into
ambiguity, so IMHO you have to live with that ambiguity in order to
build a computational system that really works.
 
R

RG

"BartC said:
But they are still units

No, they aren't.
so that you can choose to use radians, degrees or gradians

Those aren't units either, any more than a percentage is a unit. They
are just different ways of writing numbers.

All of the following are the same number written in different notations:

0.5
1/2
50%

Likewise, all of the following are the same number written in different
notations:

pi/2
pi/2 radians
90 degrees
100 gradians
1/4 circle
0.25 circle
25% of a circle
25% of 2pi

See?

rg
 
B

BartC

RG said:
No, they aren't.


Those aren't units either, any more than a percentage is a unit. They
are just different ways of writing numbers.

All of the following are the same number written in different notations:

0.5
1/2
50%

Likewise, all of the following are the same number written in different
notations:

pi/2
pi/2 radians
90 degrees
100 gradians
1/4 circle
0.25 circle
25% of a circle
25% of 2pi

See?

But what exactly *is* this number? Is it 0.25, 1.57 or 90?

I can also write 12 inches, 1 foot, 1/3 yards, 1/5280 miles, 304.8 mm and so
on. They are all the same number, roughly 1/131000000 of the polar
circumference of the Earth.

This does depend on the actual size of an arbitrary circle, but that seems
little different from the choice of 0.25, 1.57 or 90 for your quarter
circle.
 
R

RG

"BartC said:
But what exactly *is* this number? Is it 0.25, 1.57 or 90?

It's an irrational number, so it cannot be written out exactly. But
it's approximately 1.57.
I can also write 12 inches, 1 foot, 1/3 yards, 1/5280 miles, 304.8 mm and so
on. They are all the same number, roughly 1/131000000 of the polar
circumference of the Earth.

These aren't numbers, these are lengths. They correspond to a physical
thing out there in the real world. Numbers don't.
This does depend on the actual size of an arbitrary circle, but that seems
little different from the choice of 0.25, 1.57 or 90 for your quarter
circle.

Why does it seem "little different"? That is exactly the difference.
What you're doing in your "1/131000000 of the polar circumference of the
Earth" is taking the number 1/131000000 and using it to describe a
length. But what is 1/131000000? Well, it's the ratio of one foot to
the polar circumference of the earth. It's also the ratio of one apple
to 131000000 apples, or one sheep to 131000000 sheep, or one second to
131000000 seconds. It's the ratio of *anything* to 131000000 of the
same thing. (And, in case you're wondering, 131000000 is the
131000000th successor of zero.)

rg
 
K

Keith Thompson

BartC said:
But what exactly *is* this number? Is it 0.25, 1.57 or 90?

It's approximately 1.57.
I can also write 12 inches, 1 foot, 1/3 yards, 1/5280 miles, 304.8 mm and so
on. They are all the same number, roughly 1/131000000 of the polar
circumference of the Earth.

They aren't bare numbers, they're lengths (actually the same length).
This does depend on the actual size of an arbitrary circle, but that seems
little different from the choice of 0.25, 1.57 or 90 for your quarter
circle.

The radian is defined as a ratio of lengths. That ratio is the same
regardless of the size of the circle. The choice of 1/(2*pi) of the
circumference isn't arbitrary at all; there are sound mathematical
reasons for it. Mathematicians could have chosen to set the full
circumference to 1, for example, but then a lot of computations
would contain additional multiplications and/or divisions by 2*pi.
 
R

RG

Keith Thompson said:
It's approximately 1.57.


They aren't bare numbers, they're lengths (actually the same length).


The radian is defined as a ratio of lengths. That ratio is the same
regardless of the size of the circle. The choice of 1/(2*pi) of the
circumference isn't arbitrary at all; there are sound mathematical
reasons for it. Mathematicians could have chosen to set the full
circumference to 1, for example, but then a lot of computations
would contain additional multiplications and/or divisions by 2*pi.

http://www.math.utah.edu/~palais/pi.pdf

rg
 
M

MRAB

It's approximately 1.57.


They aren't bare numbers, they're lengths (actually the same length).


The radian is defined as a ratio of lengths. That ratio is the same
regardless of the size of the circle. The choice of 1/(2*pi) of the
circumference isn't arbitrary at all; there are sound mathematical
reasons for it. Mathematicians could have chosen to set the full
circumference to 1, for example, but then a lot of computations
would contain additional multiplications and/or divisions by 2*pi.
Being able to 'tag' values can help in some cases, much like the idea
of 'tainting' user input and having that taint propagate until it's
explicitly cleaned. Being able to tag a value as 'radians' can be
helpful. Consider the original purpose of Hungarian notation.
 
D

Dann Corbit

But what exactly *is* this number? Is it 0.25, 1.57 or 90?

I can also write 12 inches, 1 foot, 1/3 yards, 1/5280 miles, 304.8 mm and so
on. They are all the same number, roughly 1/131000000 of the polar
circumference of the Earth.

Those are all units of length.
This does depend on the actual size of an arbitrary circle, but that seems
little different from the choice of 0.25, 1.57 or 90 for your quarter
circle.

Radians are arc length divided by radius. Both of those can have units
attached (e.g. centimeters). But when you divide two lengths, the
length units cancel out and you are left with a pure number.

However, you can think of it as units of rotation measure if you find it
pleasing.

Suppose that you work for $50/Hr. If you work for 10 Hours the wage is
$50 / Hr * 10 * Hr = $500. Notice that the hours have dissappeared from
the equation because they cancelled out.

In a similar way, that's why radians is commonly called a dimentionless
unit. The two lengths have cancelled out.

But in a very real sense it is a measure of rotation. We could call it
a special measure, sort of like the way that e is a special base
compared to all others.

Tempest in a teapot, at any rate.
 
P

Pascal J. Bourguignon

Tim Bradshaw said:
I think that the discussion of percentages is relevant here: angles
//are// just numbers, but you're choosing a particular way of
displaying them (or reading them). 100% //is// 1, and 360° //is// 2π.
So really, like, for instance, number base, they're things that exist
for I/O but not inside the system. At least for the purposes of doing
maths: computer type systems often don't have very much to do with
maths (for instance floating-point numbers are obviously a very
important type, but don't map onto anything that would be interesting
to a theoratical physicist).

Units are really the product of two things: a dimension, and a scale.

You can add values that have the same dimension, even if they don't have
the same unit (this doesn't necessarily make the addition meaningful,
because having the same dimension still doesn't mean they've got the
same semantics, but that's another question).

So for example, you can add meters and inches. Both have the dimension
of length. But meters have the scale of 1/299792458 while inches have
the scale of 254/2997924580000. Scales are not absolute, they're given
in relation to some other scale, so you could also say that:
1 inch = 0.0254 meter, or that the scale of inches with respect to
meters is 10000/254.


So the interesting thing is that some pseudo-units don't have
dimensions. They only have the scale. Radian and Degrees have no
dimension, but they still have scale, with 1 degree = Π/180 radian.



I would argue that angles are not just numbers. There's a notion of
angle that is different from the notion of interest rate. (I have also
vague memories of a mathematical presentation of angles that clearly
distinguished angles from numbers used to represent them).
 
P

Peter Nilsson

Keith Thompson said:
The radian is defined as a ratio of lengths. That ratio
is the same regardless of the size of the circle.  The
choice of 1/(2*pi) of the circumference isn't arbitrary
at all; there are sound mathematical reasons for it.

Yes, but what is pi then?
 Mathematicians could have chosen to set the full
circumference to 1, for example, but then a lot of
computations would contain additional multiplications
and/or divisions by 2*pi.

The formula: circumference = 2 x pi x radius is taught
in primary schools, yet it's actually a very difficult
formula to prove! Most attempts by students collapse
because they assume the formula in advance (pi is the
ratio of circle semi-circumference to its radius.)

Perhaps the most elegant approach is to define arctan x
as the integral from 0 to x of dz/(1 + z^2). The trig
functions and relationships, and their application to
normal geometry, can all be defined and derived from
that alone without any reference to pi. Pi is simply
the constant 4 times arctan 1.
 
R

RG

There's a notion of
angle that is different from the notion of interest rate.

Only because of how they are conventionally used. There's no difference
between sin(0.1) and sin(10%). Likewise there is no difference between
an interest rate of 10% and an interest rate of 0.1. Even an interest
rate of 0.1 radians makes sense if for some unfathomable reason you want
to visualize your interest payment as the relative length of a line
segment and an arc.
(I have also
vague memories of a mathematical presentation of angles that clearly
distinguished angles from numbers used to represent them).

That would be interesting. If you find a pointer please pass it along.

rg
 
R

RG

Peter Nilsson said:
Yes, but what is pi then?


The formula: circumference = 2 x pi x radius is taught
in primary schools, yet it's actually a very difficult
formula to prove!

What's to prove? That's the definition of pi.

rg
 
G

Gregory Ewing

Tim said:
In general any function
which raises its argument to more than one power ... doesn't make
much sense if its argument has units.

That's not true. Consider the distance travelled by a
falling object: y(t) = y0 + v0*t + 0.5*a*t**2. Here t has
dimensions of time, and it's being raised to different
powers in different terms. It works because the
coefficents have dimensions too, and all the terms end up
having the same dimensions.

The commonly used transcendental functions (sin, log, etc.)
happen to take dimensionless arguments, but that's just a
property of those particular functions. (It's probably a
big part of the reason *why* they're commonly used -- they
wouldn't be nearly as general-purpose otherwise.)
 
G

Gregory Ewing

Pascal said:
So the interesting thing is that some pseudo-units don't have
dimensions. They only have the scale.

I don't think the term "pseudo-unit" is particularly necessary.
They're just units in which the powers of all the possible
dimensions are zero. Calling them pseudo-units is like calling
zero a pseudo-number.
 
G

Gregory Ewing

RG said:
Even an interest
rate of 0.1 radians makes sense if for some unfathomable reason you want
to visualize your interest payment as the relative length of a line
segment and an arc.

It could even be quite reasonable if you're presenting it
as a segment of a pie graph.

For what it's worth, the GST rate here recently increased
from 0.7853 to 0.9425 radians. :)
 
G

Gregory Ewing

Dann said:
But in a very real sense it is a measure of rotation. We could call it
a special measure, sort of like the way that e is a special base
compared to all others.

That's not the only thing that radians are useful for, though.
Consider a weight bobbing up and down on a spring, or anything
else with periodic behaviour. It's common to represent its
position in the oscillation cycle in terms of an angle, even
though nothing is actually rotating.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,982
Messages
2,570,185
Members
46,738
Latest member
JinaMacvit

Latest Threads

Top