Impressum/Kontaktparent nodes: implemented functions

Subtract

testSubtract
|a b r t |
"http://www.microapl.co.uk/apl_help/ch_020_020_040.htm"

"Subtracts one number from another"
self assert: 239 asApl = (240 asApl - 1).
self assert: 239 asApl = (240 asApl - (1 asApl)).

"Subtracts each number in a vector from the corresponding number in a vector of equal size"

a := #(8 4 6) asApl.
b := #(1 0 2) asApl.
r := #(7 4 4) asApl.
self assert: r = (a - b).

"Subtracts 1 from each number in a vector of numbers"
a := #(22 -4 15) asApl.
r := #(21 -5 14) asApl.
self assert: r = (a - 1).
self assert: r = (a - (1 asApl)).

"Subtracts each number in a matrix from a scalar"
t := 9 aplInterval aplReshape:#(3 3).
r := #(99 98 97 96 95 94 93 92 91) aplReshape:#(3 3).
self assert: r = (100 asApl - t).

"Subtracts each number in a matrix from the corresponding number in a matrix of equal size and dimensions"
r := 0 aplReshape:#(3 3).
self assert: r = (t - t).



"Each element in the right argument is subtracted from 1"
a := (Array with:5 with:(4 aplInterval aplReshape:#(2 2)) with:(5 aplInterval))asApl.
r := (Array with:(-4) with:(#(0 -1 -2 -3) aplReshape:#(2 2)) with:(#(0 -1 -2 -3 -4) asApl))asApl.
self assert: r=(1 asApl -a).

"Arguments must be the same length"
self should:[#(2 3) asApl - a] raise: AplLengthError.

"Corresponding elements subtracted"
a := (Array with:(4 aplInterval aplReshape:#(2 2)) with:10 with:(3 aplReshape:#(5))) asApl.
b := (Array with:5 with:(4 aplInterval aplReshape:#(2 2)) with:(5 aplInterval))asApl.
r := (Array with:( #(-4 -3 -2 -1) aplReshape:#(2 2)) with:(#(9 8 7 6) aplReshape:#(2 2)) with:(#(2 1 0 -1 -2 ) asApl))asApl.
self assert: r=(a-b).