Revamping the numeric classes

Bjorn Lisper
Wed, 7 Feb 2001 10:18:05 +0100 (MET)

Dylan Thurston:
>Andreas Gruenbacher:
>> It may be the case that using (*) for scaling too is a generally bad
>> idea...

>It may not be type sound to have the same operation, but there should
>be some standard operation for scaling.  (Probably you need
>multi-parameter type classes for this.)

I'd like to point out the connection between the use of +, - on vector
spaces and * for scaling with features in some data parallel languages.  In
these languages, writing a + b where a and b are arrays of numerics is
interpreted as elementwise addition of a and b. This features generalises to
other operations than +, -, other types than numerical ones, and other data
structures than arrays.  Furthermore, some of these languages support
"promotion": "lifting" a "scalar"-typed expression, appearing in a context
where an array (say) is expected, into an array with suitable dimensions
containing copies of the scalar.  Scaling can be seen as a special case of
promotion, if "*" is interpreted elementwise: for instance, 17*a where a is an
array is then seen as an array with elements 17 elementwise multiplied
with a.

Thus, using "*" both for scaling and elementwise multiplication can be made
to work, and it is compatible with the data parallel generalizations of
scaling and use of +, - on vector spaces. But using "*" for inner product is
not compatible with these generalizations.  Preference is probably dependent
on background (mathematician or data parallel programmer...).

Björn Lisper