2.16.1 Context-dependant functions.
Operators + and -
+ (resp -) is an infixed function and ’+’ (resp
’-’) is a prefixed fonction. The result depends on the nature of its
arguments.
Examples with + (all examples except the last one work also
with - instead of +) :
-
input (1,2)+(3,4) or (1,2,3)+4 or 1+2+3+4 or ’+’(1,2,3,4), output 10,
- input 1+i+2+3*i or ’+’(1,i,2,3*i), output 3+4*i,
- input [1,2,3]+[4,1] or [1,2,3]+[4,1,0] or ’+’([1,2,3],[4,1]), output
[5,3,3],
- input [1,2]+[3,4] or ’+’([1,2],[3,4]), output [4,6],
- input [[1,2],[3,4]]+ [[1,2],[3,4]], output [[2,4],[6,8]],
- input [1,2,3]+4 or ’+’([1,2,3],4), output poly1[1,2,7],
- input [1,2,3]+(4,1) or ’+’([1,2,3],4,1), output poly1[1,2,8],
- input "Hel"+"lo" or ’+’("Hel","lo"), output "Hello".
Operator *
* is an infixed function and ’*’
is a prefixed function. The result depends on the nature of its arguments.
Examples with * :
-
input (1,2)*(3,4) or (1,2,3)*4=1*2*3*4 or ’*’(1,2,3,4), output 24,
- input 1*i*2*3*i or ’*’(1,i,2,3*i), output -6,
- input [10,2,3]*[4,1] or [10,2,3]*[4,1,0] or ’+’([10,2,3],[4,1]),
output 42 (scalar product),
- input [1,2]*[3,4]=’*’([1,2],[3,4]), output 11 (scalar product),
- input [[1,2],[3,4]]* [[1,2],[3,4]], output [[7,10],[15,22]],
- input [1,2,3]*4 or ’*’([1,2,3],4), output [4,8,12],
- input [1,2,3]*(4,2) or ’*’([1,2,3],4,2) or [1,2,3]*8, output [8,16,24],
- input (1,2)+i*(2,3) or 1+2+i*2*3, output 3+6*i.
Operator /
/ is an infixed function and ’/’
is a prefixed function. The result depends of the nature of its arguments.
Examples with / :
-
input [10,2,3]/[4,1], output invalid dim
- input [1,2]/[3,4] or ’/’([1,2],[3,4]), output [1/3,1/2],
- input 1/[[1,2],[3,4]] or ’/’(1,[[1,2],[3,4]], output
[[-2,1],[3/2,(-1)/2]],
- input [[1,2],[3,4]]*1/ [[1,2],[3,4]], output [[1,0],[0,1]],
- input [[1,2],[3,4]]/ [[1,2],[3,4]], output [[1,1],[1,1]] (division term
by term),