Usage
define MyGroup: Category == Join(MyAdditiveType, ...) with {...}
MyFloat: Join(MyAdditiveType, ...) with {...} == add {...}
Description
The category of types with addition and subtraction operations.
MyAdditiveType is the category of types that provide operations that can be performed in a group.
Remarks
MyAdditiveType provides only the signatures of group operations. There is no statement made about which axioms these operations have to fulfil. MyAdditiveType and MyArithmeticType are useful to provide a ring signatures to domains like SingleFloat, DoubleFloat, and similar types that in many respect behave like rings but are by their imprecise nature not mathematical rings themselves.
Exports of MyAdditiveType
+: (%, %) -> % Returns the sum of its arguments.
-: (%, %) -> % Returns the difference of its arguments.
-: % -> % Returns the negation of its argument.
add!: (%, %) -> % Returns the sum of its arguments.
minus!: (%, %) -> % Returns the difference of its arguments.
minus!: % -> % Returns the negation of its argument.
The category MyAdditiveType also exports equality and inequality testing.
Export of MyAdditiveType
zero?: % -> Boolean
Usage
if zero? x then ...
Parameters
Element to be tested.
Description
Tests whether its argument is 0.
The boolean value of zero? x is identical to the test x = 0 in the type, but might be implemented more efficiently.
Remarks
Note that one would usually not use this function on floating point types. A zero test might fail because of small errors introduced during a computation.
Export of MyAdditiveType
+: (%, %) -> %
Usage
z := x + y
Parameters
Elements to be added.
Description
Returns the sum of its arguments.
Export of MyAdditiveType
-: (%, %) -> %
Usage
z := x - y
Parameters
Elements to be subtracted.
Description
Returns the difference of its arguments.
Export of MyAdditiveType
-: % -> %
Usage
z := - x
Parameters
Element to be negated.
Description
Returns the negation of its argument.
Export of MyAdditiveType
add!: (%, %) -> %
Usage
z := add!(y, z);
z := 0;
for x in somelist repeat z := add!(z, x);
Parameters
Elements to be added.
Description
Returns the sum of its arguments.
Remarks
The function add! is allowed to work destructively on its first argument, i. e., the storage used by y is allowed to be destroyed or reused, so y is lost after this call.
Another destructive operation (provided by the specific type that implements MyAdditiveType) which operates on z is not allowed to have any destructive influence on the x values.
An implementation of this function should take care of constant values of the type appearing in the first argument. In particular, add!(0, x) should not work destructively on the constant 0.
Furthermore, it is allowed to call add!(x, x) to obtain 2x. Implementation of this function should start with
if (x pretend Pointer) = (y pretend Pointer) then ...
The implementation of + will most probably simply return y for 0 + y. So if we just say
add!(x: %, y: %): % == x + y;
foo!(add!(0, y))
Export of MyAdditiveType
minus!: (%, %) -> %
Usage
z := minus!(y, z);
z := 0;
for x in somelist repeat z := minus!(z, x);
Parameters
Elements to be added.
Description
Returns the difference of its arguments.
Remarks
See add!.
Export of MyAdditiveType
minus!: % -> %
Usage
z := minus! x
Parameters
Element to be negated.
Description
Returns the negation of its argument.
Remarks
The storage of x may be destroyed or reused, so x is lost after the call.