01a72ecc338d17eb9cd11099c93e9ba0e20fd3d9
[scilab.git] / scilab / modules / ast / tests / unit_tests / subtraction.tst
1 // ============================================================================
2 // Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
3 // Copyright (C) 2012 - DIGITEO - Antoine ELIAS
4 //
5 //  This file is distributed under the same license as the Scilab package.
6 // ============================================================================
7
8 // <-- CLI SHELL MODE -->
9
10 s = %s;
11 empty = [];
12 r = 2;
13 R = [1,2;3,4];
14 R3(:,:,1) = R;
15 R3(:,:,2) = R';
16 c = 1 + 2*%i;
17 C = [1+2*%i,2+4*%i;3+6*%i,4+8*%i];
18 C3(:,:,1) = C;
19 C3(:,:,2) = C';
20 e = eye();
21 ec = (5+%i) * eye();
22 p = 1 + %s - %s**2;
23 pc = 1 + %s - %s**2 + ( 2 - 3 * %s + 4 * %s**2 ) * %i;
24 P = [2*p, -3*p;4*p,-5*p];
25 PC = [2*pc, -3*pc;4*pc,-5*pc];
26 SP = sparse([1,2;4,5;3,10],[1,2,3]);
27 SPC = sparse([1,2;4,5;3,10],[1,2,3]) * ( 1 + 4*%i);
28
29 i8 = int8(-8);
30 ui8 = uint8(8);
31 I8 = int8([-8 -16 ; -24 -32]);
32 UI8 = uint8([8 16 ; 24 32]);
33
34 I16 = int16([-16 -32 ; -48 -64]);
35 UI16 = uint16([16 32 ; 48 64]);
36 i16 = int16(-16);
37 ui16 = uint16(16);
38
39 i32 = int32(-32);
40 ui32 = uint32(32);
41 I32 = int32([-32 -64 ; -96 -128]);
42 UI32 = uint32([32 64 ; 96 128]);
43
44 assert_checkequal(empty - empty, []);
45 assert_checkequal(empty - r, -2);
46 assert_checkequal(empty - c, -1-%i*2);
47 assert_checkequal(empty - R, [-1,-2;-3,-4]);
48 assert_checkequal(empty - C, [-1-%i*2,-2-%i*4;-3-%i*6,-4-%i*8]);
49 assert_checkequal(empty - e, (-1)*eye());
50 assert_checkequal(empty - ec, (-5-%i)*eye());
51 assert_checkequal(empty - p, -1-s+s^2);
52 assert_checkequal(empty - pc, -1-%i*2+(-1+%i*3)*s+(1-%i*4)*s^2);
53 assert_checkequal(empty - P, [-2-2*s+2*s^2,3+3*s-3*s^2;-4-4*s+4*s^2,5+5*s-5*s^2]);
54 assert_checkequal(empty - PC, [-2-%i*4+(-2+%i*6)*s+(2-%i*8)*s^2,3+%i*6+(3-%i*9)*s+(-3+%i*12)*s^2;-4-%i*8+(-4+%i*12)*s+(4-%i*16)*s^2,5+%i*10+(5-%i*15)*s+(-5+%i*20)*s^2]);
55 assert_checkequal(empty - SP, sparse([1,2;3,10;4,5],[-1;-3;-2],[4,10]));
56 assert_checkequal(empty - SPC, sparse([1,2;3,10;4,5],[-1-%i*4;-3-%i*12;-2-%i*8],[4,10]));
57 assert_checkequal(empty - i8, int8(8));
58 assert_checkequal(empty - I8, int8([8,16;24,32]));
59 assert_checkequal(empty - ui8, uint8(248));
60 assert_checkequal(empty - UI8, uint8([248,240;232,224]));
61 assert_checkequal(empty - i16, int16(16));
62 assert_checkequal(empty - I16, int16([16,32;48,64]));
63 assert_checkequal(empty - ui16, uint16(65520));
64 assert_checkequal(empty - UI16, uint16([65520,65504;65488,65472]));
65 assert_checkequal(empty - i32, int32(32));
66 assert_checkequal(empty - I32, int32([32,64;96,128]));
67 assert_checkequal(empty - ui32, uint32(4294967264));
68 assert_checkequal(empty - UI32, uint32([4294967264,4294967232;4294967200,4294967168]));
69
70 assert_checkequal(r - empty, 2);
71 assert_checkequal(r - r, 0);
72 assert_checkequal(r - c,  1-%i*2);
73 assert_checkequal(r - R, [1,0;-1,-2]);
74 assert_checkequal(r - C, [ 1-%i*2,-%i*4;-1-%i*6,-2-%i*8]);
75 assert_checkequal(r - e, 1);
76 assert_checkequal(r - ec, -3-%i);
77 assert_checkequal(r - p, 1-s+s^2);
78 assert_checkequal(r - pc, 1-%i*2+(-1+%i*3)*s+(1-%i*4)*s^2);
79 assert_checkequal(r - P, [-2*s+2*s^2,5+3*s-3*s^2;-2-4*s+4*s^2,7+5*s-5*s^2]);
80 assert_checkequal(r - PC, [-%i*4+(-2+%i*6)*s+(2-%i*8)*s^2,5+%i*6+(3-%i*9)*s+(-3+%i*12)*s^2;-2-%i*8+(-4+%i*12)*s+(4-%i*16)*s^2,7+%i*10+(5-%i*15)*s+(-5+%i*20)*s^2]);
81 assert_checkequal(r - SP, [2,1,2,2,2,2,2,2,2,2;2,2,2,2,2,2,2,2,2,2;2,2,2,2,2,2,2,2,2,-1;2,2,2,2,0,2,2,2,2,2]);
82 assert_checkequal(r - SPC, [ 2, 1-%i*4, 2, 2, 2, 2, 2, 2, 2, 2; 2, 2, 2, 2, 2, 2, 2, 2, 2, 2; 2, 2, 2, 2, 2, 2, 2, 2, 2,-1-%i*12; 2, 2, 2, 2,-%i*8, 2, 2, 2, 2, 2]);
83 assert_checkequal(r - i8, int8(10));
84 assert_checkequal(r - I8, int8([10,18;26,34]));
85 assert_checkequal(r - ui8, uint8(250));
86 assert_checkequal(r - UI8, uint8([250,242;234,226]));
87 assert_checkequal(r - i16, int16(18));
88 assert_checkequal(r - I16, int16([18,34;50,66]));
89 assert_checkequal(r - ui16, uint16(65522));
90 assert_checkequal(r - UI16, uint16([65522,65506;65490,65474]));
91 assert_checkequal(r - i32, int32(34));
92 assert_checkequal(r - I32, int32([34,66;98,130]));
93 assert_checkequal(r - ui32, uint32(4294967266));
94 assert_checkequal(r - UI32, uint32([4294967266,4294967234;4294967202,4294967170]));
95
96 assert_checkequal(c - empty,  1+%i*2);
97 assert_checkequal(c - r, -1+%i*2);
98 assert_checkequal(c - c, 0*%i);
99 assert_checkequal(c - R, [%i*2,-1+%i*2;-2+%i*2,-3+%i*2]);
100 assert_checkequal(c - C, [0,-1-%i*2;-2-%i*4,-3-%i*6]);
101 assert_checkequal(c - e, %i*2);
102 assert_checkequal(c - ec, -4+%i);
103 assert_checkequal(c - p, %i*2-s+s^2);
104 assert_checkequal(c - pc, (-1+%i*3)*s+(1-%i*4)*s^2);
105 assert_checkequal(c - P, [-1+%i*2-2*s+2*s^2,4+%i*2+3*s-3*s^2;-3+%i*2-4*s+4*s^2,6+%i*2+5*s-5*s^2]);
106 assert_checkequal(c - PC, [-1-%i*2+(-2+%i*6)*s+(2-%i*8)*s^2,4+%i*8+(3-%i*9)*s+(-3+%i*12)*s^2;-3-%i*6+(-4+%i*12)*s+(4-%i*16)*s^2,6+%i*12+(5-%i*15)*s+(-5+%i*20)*s^2]);
107 assert_checkequal(c - SP, [ 1+%i*2,%i*2, 1+%i*2, 1+%i*2, 1+%i*2, 1+%i*2, 1+%i*2, 1+%i*2, 1+%i*2, 1+%i*2; 1+%i*2, 1+%i*2, 1+%i*2, 1+%i*2, 1+%i*2, 1+%i*2, 1+%i*2, 1+%i*2, 1+%i*2, 1+%i*2; 1+%i*2, 1+%i*2, 1+%i*2, 1+%i*2, 1+%i*2, 1+%i*2, 1+%i*2, 1+%i*2, 1+%i*2,-2+%i*2; 1+%i*2, 1+%i*2, 1+%i*2, 1+%i*2,-1+%i*2, 1+%i*2, 1+%i*2, 1+%i*2, 1+%i*2, 1+%i*2]);
108 assert_checkequal(c - SPC, [ 1+%i*2,-%i*2, 1+%i*2, 1+%i*2, 1+%i*2, 1+%i*2, 1+%i*2, 1+%i*2, 1+%i*2, 1+%i*2; 1+%i*2, 1+%i*2, 1+%i*2, 1+%i*2, 1+%i*2, 1+%i*2, 1+%i*2, 1+%i*2, 1+%i*2, 1+%i*2; 1+%i*2, 1+%i*2, 1+%i*2, 1+%i*2, 1+%i*2, 1+%i*2, 1+%i*2, 1+%i*2, 1+%i*2,-2-%i*10; 1+%i*2, 1+%i*2, 1+%i*2, 1+%i*2,-1-%i*6, 1+%i*2, 1+%i*2, 1+%i*2, 1+%i*2, 1+%i*2]);
109
110 assert_checkequal(R - empty, [1,2;3,4]);
111 assert_checkequal(R - r, [-1,0;1,2]);
112 assert_checkequal(R - c, [-%i*2, 1-%i*2; 2-%i*2, 3-%i*2]);
113 assert_checkequal(R - R, [0,0;0,0]);
114 assert_checkequal(R - C, [-%i*2,-%i*4;-%i*6,-%i*8]);
115 assert_checkequal(R - e, [0,2;3,3]);
116 assert_checkequal(R - ec, [-4-%i, 2; 3,-1-%i]);
117 assert_checkequal(R - p, [-s+s^2,1-s+s^2;2-s+s^2,3-s+s^2]);
118 assert_checkequal(R - pc, [-%i*2+(-1+%i*3)*s+(1-%i*4)*s^2,1-%i*2+(-1+%i*3)*s+(1-%i*4)*s^2;2-%i*2+(-1+%i*3)*s+(1-%i*4)*s^2,3-%i*2+(-1+%i*3)*s+(1-%i*4)*s^2]);
119 assert_checkequal(R - P, [-1-2*s+2*s^2,5+3*s-3*s^2;-1-4*s+4*s^2,9+5*s-5*s^2]);
120 assert_checkequal(R - PC, [-1-%i*4+(-2+%i*6)*s+(2-%i*8)*s^2,5+%i*6+(3-%i*9)*s+(-3+%i*12)*s^2;-1-%i*8+(-4+%i*12)*s+(4-%i*16)*s^2,9+%i*10+(5-%i*15)*s+(-5+%i*20)*s^2]);
121 assert_checkequal(R - i8, int8([9,10;11,12]));
122 assert_checkequal(R - I8, int8([9,18;27,36]));
123 assert_checkequal(R - ui8, uint8([249,250;251,252]));
124 assert_checkequal(R - UI8, uint8([249,242;235,228]));
125 assert_checkequal(R - i16, int16([17,18;19,20]));
126 assert_checkequal(R - I16, int16([17,34;51,68]));
127 assert_checkequal(R - ui16, uint16([65521,65522;65523,65524]));
128 assert_checkequal(R - UI16, uint16([65521,65506;65491,65476]));
129 assert_checkequal(R - i32, int32([33,34;35,36]));
130 assert_checkequal(R - I32, int32([33,66;99,132]));
131 assert_checkequal(R - ui32, uint32([4294967265,4294967266;4294967267,4294967268]));
132 assert_checkequal(R - UI32, uint32([4294967265,4294967234;4294967203,4294967172]));
133
134 assert_checkequal(C - empty, [ 1+%i*2, 2+%i*4; 3+%i*6, 4+%i*8]);
135 assert_checkequal(C - r, [-1+%i*2,%i*4; 1+%i*6, 2+%i*8]);
136 assert_checkequal(C - c, [0, 1+%i*2; 2+%i*4, 3+%i*6]);
137 assert_checkequal(C - R, [%i*2,%i*4;%i*6,%i*8]);
138 assert_checkequal(C - C, [0,0;0,0] * %i);
139 assert_checkequal(C - e, [%i*2, 2+%i*4; 3+%i*6, 3+%i*8]);
140 assert_checkequal(C - ec, [-4+%i, 2+%i*4; 3+%i*6,-1+%i*7]);
141 assert_checkequal(C - p, [%i*2-s+s^2,1+%i*4-s+s^2;2+%i*6-s+s^2,3+%i*8-s+s^2]);
142 assert_checkequal(C - pc, [(-1+%i*3)*s+(1-%i*4)*s^2,1+%i*2+(-1+%i*3)*s+(1-%i*4)*s^2;2+%i*4+(-1+%i*3)*s+(1-%i*4)*s^2,3+%i*6+(-1+%i*3)*s+(1-%i*4)*s^2]);
143 assert_checkequal(C - P, [-1+%i*2-2*s+2*s^2,5+%i*4+3*s-3*s^2;-1+%i*6-4*s+4*s^2,9+%i*8+5*s-5*s^2]);
144 assert_checkequal(C - PC, [-1-%i*2+(-2+%i*6)*s+(2-%i*8)*s^2,5+%i*10+(3-%i*9)*s+(-3+%i*12)*s^2;-1-%i*2+(-4+%i*12)*s+(4-%i*16)*s^2,9+%i*18+(5-%i*15)*s+(-5+%i*20)*s^2]);
145
146 assert_checkequal(e - empty, eye());
147 assert_checkequal(e - r, -1);
148 assert_checkequal(e - c, -%i*2);
149 assert_checkequal(e - R, [0,-2;-3,-3]);
150 assert_checkequal(e - C, [-%i*2,-2-%i*4;-3-%i*6,-3-%i*8]);
151 assert_checkequal(e - e, (0)*eye());
152 assert_checkequal(e - ec, (-4-%i)*eye());
153 assert_checkequal(e - p, -s+s^2);
154 assert_checkequal(e - pc, -%i*2+(-1+%i*3)*s+(1-%i*4)*s^2);
155 assert_checkequal(e - P, [-1-2*s+2*s^2,3+3*s-3*s^2;-4-4*s+4*s^2,6+5*s-5*s^2]);
156 assert_checkequal(e - PC, [-1-%i*4+(-2+%i*6)*s+(2-%i*8)*s^2,3+%i*6+(3-%i*9)*s+(-3+%i*12)*s^2;-4-%i*8+(-4+%i*12)*s+(4-%i*16)*s^2,6+%i*10+(5-%i*15)*s+(-5+%i*20)*s^2]);
157 assert_checkequal(e - SP, sparse([1,1;1,2;2,2;3,3;3,10;4,4;4,5],[1;-1;1;1;-3;1;-2],[4,10]));
158 assert_checkequal(e - SPC, sparse([1,1;1,2;2,2;3,3;3,10;4,4;4,5],[ 1;-1-%i*4; 1; 1;-3-%i*12; 1;-2-%i*8],[4,10]));
159
160 assert_checkequal(ec - empty, ( 5+%i)*eye());
161 assert_checkequal(ec - r,  3+%i);
162 assert_checkequal(ec - c,  4-%i);
163 assert_checkequal(ec - R, [ 4+%i,-2;-3, 1+%i]);
164 assert_checkequal(ec - C, [ 4-%i,-2-%i*4;-3-%i*6, 1-%i*7]);
165 assert_checkequal(ec - e, ( 4+%i)*eye());
166 assert_checkequal(ec - ec, (0*%i)*eye());
167 assert_checkequal(ec - p, 4+%i-s+s^2);
168 assert_checkequal(ec - pc, 4-%i+(-1+%i*3)*s+(1-%i*4)*s^2);
169 assert_checkequal(ec - P, [3+%i-2*s+2*s^2,3+3*s-3*s^2;-4-4*s+4*s^2,10+%i+5*s-5*s^2]);
170 assert_checkequal(ec - PC, [3-%i*3+(-2+%i*6)*s+(2-%i*8)*s^2,3+%i*6+(3-%i*9)*s+(-3+%i*12)*s^2;-4-%i*8+(-4+%i*12)*s+(4-%i*16)*s^2,10+%i*11+(5-%i*15)*s+(-5+%i*20)*s^2]);
171 assert_checkequal(ec - SP, sparse([1,1;1,2;2,2;3,3;3,10;4,4;4,5],[ 5+%i;-1; 5+%i; 5+%i;-3; 5+%i;-2],[4,10]));
172 assert_checkequal(ec - SPC, sparse([1,1;1,2;2,2;3,3;3,10;4,4;4,5],[ 5+%i;-1-%i*4; 5+%i; 5+%i;-3-%i*12; 5+%i;-2-%i*8],[4,10]));
173
174 assert_checkequal(p - empty, 1+s-s^2);
175 assert_checkequal(p - r, -1+s-s^2);
176 assert_checkequal(p - c, -%i*2+s-s^2);
177 assert_checkequal(p - R, [s-s^2,-1+s-s^2;-2+s-s^2,-3+s-s^2]);
178 assert_checkequal(p - C, [-%i*2+s-s^2,-1-%i*4+s-s^2;-2-%i*6+s-s^2,-3-%i*8+s-s^2]);
179 assert_checkequal(p - e, s-s^2);
180 assert_checkequal(p - ec, -4-%i+s-s^2);
181 assert_checkequal(p - p, 0*s);
182 assert_checkequal(p - pc, -%i*2+(%i*3)*s+(-%i*4)*s^2);
183 assert_checkequal(p - P, [-1-s+s^2,4+4*s-4*s^2;-3-3*s+3*s^2,6+6*s-6*s^2]);
184 assert_checkequal(p - PC, [-1-%i*4+(-1+%i*6)*s+(1-%i*8)*s^2,4+%i*6+(4-%i*9)*s+(-4+%i*12)*s^2;-3-%i*8+(-3+%i*12)*s+(3-%i*16)*s^2,6+%i*10+(6-%i*15)*s+(-6+%i*20)*s^2]);
185
186 assert_checkequal(pc - empty, 1+%i*2+(1-%i*3)*s+(-1+%i*4)*s^2);
187 assert_checkequal(pc - r, -1+%i*2+(1-%i*3)*s+(-1+%i*4)*s^2);
188 assert_checkequal(pc - c, (1-%i*3)*s+(-1+%i*4)*s^2);
189 assert_checkequal(pc - R, [%i*2+(1-%i*3)*s+(-1+%i*4)*s^2,-1+%i*2+(1-%i*3)*s+(-1+%i*4)*s^2;-2+%i*2+(1-%i*3)*s+(-1+%i*4)*s^2,-3+%i*2+(1-%i*3)*s+(-1+%i*4)*s^2]);
190 assert_checkequal(pc - C, [(1-%i*3)*s+(-1+%i*4)*s^2,-1-%i*2+(1-%i*3)*s+(-1+%i*4)*s^2;-2-%i*4+(1-%i*3)*s+(-1+%i*4)*s^2,-3-%i*6+(1-%i*3)*s+(-1+%i*4)*s^2]);
191 assert_checkequal(pc - e, %i*2+(1-%i*3)*s+(-1+%i*4)*s^2);
192 assert_checkequal(pc - ec, -4+%i+(1-%i*3)*s+(-1+%i*4)*s^2);
193 assert_checkequal(pc - p, %i*2+(-%i*3)*s+(%i*4)*s^2);
194 assert_checkequal(pc - pc, 0*s);
195 assert_checkequal(pc - P, [-1+%i*2+(-1-%i*3)*s+(1+%i*4)*s^2,4+%i*2+(4-%i*3)*s+(-4+%i*4)*s^2;-3+%i*2+(-3-%i*3)*s+(3+%i*4)*s^2,6+%i*2+(6-%i*3)*s+(-6+%i*4)*s^2]);
196 assert_checkequal(pc - PC, [-1-%i*2+(-1+%i*3)*s+(1-%i*4)*s^2,4+%i*8+(4-%i*12)*s+(-4+%i*16)*s^2;-3-%i*6+(-3+%i*9)*s+(3-%i*12)*s^2,6+%i*12+(6-%i*18)*s+(-6+%i*24)*s^2]);
197
198 assert_checkequal(P - empty, [2+2*s-2*s^2,-3-3*s+3*s^2;4+4*s-4*s^2,-5-5*s+5*s^2]);
199 assert_checkequal(P - r, [2*s-2*s^2,-5-3*s+3*s^2;2+4*s-4*s^2,-7-5*s+5*s^2]);
200 assert_checkequal(P - c, [1-%i*2+2*s-2*s^2,-4-%i*2-3*s+3*s^2;3-%i*2+4*s-4*s^2,-6-%i*2-5*s+5*s^2]);
201 assert_checkequal(P - R, [1+2*s-2*s^2,-5-3*s+3*s^2;1+4*s-4*s^2,-9-5*s+5*s^2]);
202 assert_checkequal(P - C, [1-%i*2+2*s-2*s^2,-5-%i*4-3*s+3*s^2;1-%i*6+4*s-4*s^2,-9-%i*8-5*s+5*s^2]);
203 assert_checkequal(P - e, [1+2*s-2*s^2,-3-3*s+3*s^2;4+4*s-4*s^2,-6-5*s+5*s^2]);
204 assert_checkequal(P - ec, [-3-%i+2*s-2*s^2,-3-3*s+3*s^2;4+4*s-4*s^2,-10-%i-5*s+5*s^2]);
205 assert_checkequal(P - p, [1+s-s^2,-4-4*s+4*s^2;3+3*s-3*s^2,-6-6*s+6*s^2]);
206 assert_checkequal(P - pc, [1-%i*2+(1+%i*3)*s+(-1-%i*4)*s^2,-4-%i*2+(-4+%i*3)*s+(4-%i*4)*s^2;3-%i*2+(3+%i*3)*s+(-3-%i*4)*s^2,-6-%i*2+(-6+%i*3)*s+(6-%i*4)*s^2]);
207 assert_checkequal(P - P, [0*s,0*s;0*s,0*s]);
208 assert_checkequal(P - PC, [-%i*4+(%i*6)*s+(-%i*8)*s^2,%i*6+(-%i*9)*s+(%i*12)*s^2;-%i*8+(%i*12)*s+(-%i*16)*s^2,%i*10+(-%i*15)*s+(%i*20)*s^2]);
209
210 assert_checkequal(PC - empty, [2+%i*4+(2-%i*6)*s+(-2+%i*8)*s^2,-3-%i*6+(-3+%i*9)*s+(3-%i*12)*s^2;4+%i*8+(4-%i*12)*s+(-4+%i*16)*s^2,-5-%i*10+(-5+%i*15)*s+(5-%i*20)*s^2]);
211 assert_checkequal(PC - r, [%i*4+(2-%i*6)*s+(-2+%i*8)*s^2,-5-%i*6+(-3+%i*9)*s+(3-%i*12)*s^2;2+%i*8+(4-%i*12)*s+(-4+%i*16)*s^2,-7-%i*10+(-5+%i*15)*s+(5-%i*20)*s^2]);
212 assert_checkequal(PC - c, [1+%i*2+(2-%i*6)*s+(-2+%i*8)*s^2,-4-%i*8+(-3+%i*9)*s+(3-%i*12)*s^2;3+%i*6+(4-%i*12)*s+(-4+%i*16)*s^2,-6-%i*12+(-5+%i*15)*s+(5-%i*20)*s^2]);
213 assert_checkequal(PC - R, [1+%i*4+(2-%i*6)*s+(-2+%i*8)*s^2,-5-%i*6+(-3+%i*9)*s+(3-%i*12)*s^2;1+%i*8+(4-%i*12)*s+(-4+%i*16)*s^2,-9-%i*10+(-5+%i*15)*s+(5-%i*20)*s^2]);
214 assert_checkequal(PC - C, [1+%i*2+(2-%i*6)*s+(-2+%i*8)*s^2,-5-%i*10+(-3+%i*9)*s+(3-%i*12)*s^2;1+%i*2+(4-%i*12)*s+(-4+%i*16)*s^2,-9-%i*18+(-5+%i*15)*s+(5-%i*20)*s^2]);
215 assert_checkequal(PC - e, [1+%i*4+(2-%i*6)*s+(-2+%i*8)*s^2,-3-%i*6+(-3+%i*9)*s+(3-%i*12)*s^2;4+%i*8+(4-%i*12)*s+(-4+%i*16)*s^2,-6-%i*10+(-5+%i*15)*s+(5-%i*20)*s^2]);
216 assert_checkequal(PC - ec, [-3+%i*3+(2-%i*6)*s+(-2+%i*8)*s^2,-3-%i*6+(-3+%i*9)*s+(3-%i*12)*s^2;4+%i*8+(4-%i*12)*s+(-4+%i*16)*s^2,-10-%i*11+(-5+%i*15)*s+(5-%i*20)*s^2]);
217 assert_checkequal(PC - p, [1+%i*4+(1-%i*6)*s+(-1+%i*8)*s^2,-4-%i*6+(-4+%i*9)*s+(4-%i*12)*s^2;3+%i*8+(3-%i*12)*s+(-3+%i*16)*s^2,-6-%i*10+(-6+%i*15)*s+(6-%i*20)*s^2]);
218 assert_checkequal(PC - pc, [1+%i*2+(1-%i*3)*s+(-1+%i*4)*s^2,-4-%i*8+(-4+%i*12)*s+(4-%i*16)*s^2;3+%i*6+(3-%i*9)*s+(-3+%i*12)*s^2,-6-%i*12+(-6+%i*18)*s+(6-%i*24)*s^2]);
219 assert_checkequal(PC - P, [%i*4+(-%i*6)*s+(%i*8)*s^2,-%i*6+(%i*9)*s+(-%i*12)*s^2;%i*8+(-%i*12)*s+(%i*16)*s^2,-%i*10+(%i*15)*s+(-%i*20)*s^2]);
220 assert_checkequal(PC - PC, [0*s,0*s;0*s,0*s]);
221
222 assert_checkequal(SP - empty, sparse([1,2;3,10;4,5],[1;3;2],[4,10]));
223 assert_checkequal(SP - r, [-2,-1,-2,-2,-2,-2,-2,-2,-2,-2;-2,-2,-2,-2,-2,-2,-2,-2,-2,-2;-2,-2,-2,-2,-2,-2,-2,-2,-2,1;-2,-2,-2,-2,0,-2,-2,-2,-2,-2]);
224 assert_checkequal(SP - c, [-1-%i*2,-%i*2,-1-%i*2,-1-%i*2,-1-%i*2,-1-%i*2,-1-%i*2,-1-%i*2,-1-%i*2,-1-%i*2;-1-%i*2,-1-%i*2,-1-%i*2,-1-%i*2,-1-%i*2,-1-%i*2,-1-%i*2,-1-%i*2,-1-%i*2,-1-%i*2;-1-%i*2,-1-%i*2,-1-%i*2,-1-%i*2,-1-%i*2,-1-%i*2,-1-%i*2,-1-%i*2,-1-%i*2, 2-%i*2;-1-%i*2,-1-%i*2,-1-%i*2,-1-%i*2, 1-%i*2,-1-%i*2,-1-%i*2,-1-%i*2,-1-%i*2,-1-%i*2]);
225 assert_checkequal(SP - e, sparse([1,1;1,2;2,2;3,3;3,10;4,4;4,5],[-1;1;-1;-1;3;-1;2],[4,10]));
226 assert_checkequal(SP - ec, sparse([1,1;1,2;2,2;3,3;3,10;4,4;4,5],[-5-%i; 1;-5-%i;-5-%i; 3;-5-%i; 2],[4,10]));
227 assert_checkequal(SP - SP, sparse([],[],[4,10]));
228 assert_checkequal(SP - SPC, sparse([1,2;3,10;4,5],[-%i*4;-%i*12;-%i*8],[4,10]));
229
230 assert_checkequal(SPC - empty, sparse([1,2;3,10;4,5],[ 1+%i*4; 3+%i*12; 2+%i*8],[4,10]));
231 assert_checkequal(SPC - r, [-2,-1+%i*4,-2,-2,-2,-2,-2,-2,-2,-2;-2,-2,-2,-2,-2,-2,-2,-2,-2,-2;-2,-2,-2,-2,-2,-2,-2,-2,-2, 1+%i*12;-2,-2,-2,-2,%i*8,-2,-2,-2,-2,-2]);
232 assert_checkequal(SPC - c, [-1-%i*2,%i*2,-1-%i*2,-1-%i*2,-1-%i*2,-1-%i*2,-1-%i*2,-1-%i*2,-1-%i*2,-1-%i*2;-1-%i*2,-1-%i*2,-1-%i*2,-1-%i*2,-1-%i*2,-1-%i*2,-1-%i*2,-1-%i*2,-1-%i*2,-1-%i*2;-1-%i*2,-1-%i*2,-1-%i*2,-1-%i*2,-1-%i*2,-1-%i*2,-1-%i*2,-1-%i*2,-1-%i*2, 2+%i*10;-1-%i*2,-1-%i*2,-1-%i*2,-1-%i*2, 1+%i*6,-1-%i*2,-1-%i*2,-1-%i*2,-1-%i*2,-1-%i*2]);
233 assert_checkequal(SPC - e, sparse([1,1;1,2;2,2;3,3;3,10;4,4;4,5],[-1; 1+%i*4;-1;-1; 3+%i*12;-1; 2+%i*8],[4,10]));
234 assert_checkequal(SPC - ec, sparse([1,1;1,2;2,2;3,3;3,10;4,4;4,5],[-5-%i; 1+%i*4;-5-%i;-5-%i; 3+%i*12;-5-%i; 2+%i*8],[4,10]));
235 assert_checkequal(SPC - SP, sparse([1,2;3,10;4,5],[%i*4;%i*12;%i*8],[4,10]));
236 assert_checkequal(SPC - SPC, sparse([],[],[4,10]));
237
238 assert_checkequal(i8 - empty, int8(-8));
239 assert_checkequal(i8 - r, int8(-10));
240 assert_checkequal(i8 - R, int8([-9,-10;-11,-12]));
241 assert_checkequal(i8 - i8, int8(0));
242 assert_checkequal(i8 - I8, int8([0,8;16,24]));
243 assert_checkequal(i8 - ui8, uint8(240));
244 assert_checkequal(i8 - UI8, uint8([240,232;224,216]));
245 assert_checkequal(i8 - i16, int16(8));
246 assert_checkequal(i8 - I16, int16([8,24;40,56]));
247 assert_checkequal(i8 - ui16, uint16(65512));
248 assert_checkequal(i8 - UI16, uint16([65512,65496;65480,65464]));
249 assert_checkequal(i8 - i32, int32(24));
250 assert_checkequal(i8 - I32, int32([24,56;88,120]));
251 assert_checkequal(i8 - ui32, uint32(4294967256));
252 assert_checkequal(i8 - UI32, uint32([4294967256,4294967224;4294967192,4294967160]));
253
254 assert_checkequal(I8 - empty, int8([-8,-16;-24,-32]));
255 assert_checkequal(I8 - r, int8([-10,-18;-26,-34]));
256 assert_checkequal(I8 - R, int8([-9,-18;-27,-36]));
257 assert_checkequal(I8 - i8, int8([0,-8;-16,-24]));
258 assert_checkequal(I8 - I8, int8([0,0;0,0]));
259 assert_checkequal(I8 - ui8, uint8([240,232;224,216]));
260 assert_checkequal(I8 - UI8, uint8([240,224;208,192]));
261 assert_checkequal(I8 - i16, int16([8,0;-8,-16]));
262 assert_checkequal(I8 - I16, int16([8,16;24,32]));
263 assert_checkequal(I8 - ui16, uint16([65512,65504;65496,65488]));
264 assert_checkequal(I8 - UI16, uint16([65512,65488;65464,65440]));
265 assert_checkequal(I8 - i32, int32([24,16;8,0]));
266 assert_checkequal(I8 - I32, int32([24,48;72,96]));
267 assert_checkequal(I8 - ui32, uint32([4294967256,4294967248;4294967240,4294967232]));
268 assert_checkequal(I8 - UI32, uint32([4294967256,4294967216;4294967176,4294967136]));
269
270 assert_checkequal(ui8 - empty, uint8(8));
271 assert_checkequal(ui8 - r, uint8(6));
272 assert_checkequal(ui8 - R, uint8([7,6;5,4]));
273 assert_checkequal(ui8 - i8, uint8(16));
274 assert_checkequal(ui8 - I8, uint8([16,24;32,40]));
275 assert_checkequal(ui8 - ui8, uint8(0));
276 assert_checkequal(ui8 - UI8, uint8([0,248;240,232]));
277 assert_checkequal(ui8 - i16, uint16(24));
278 assert_checkequal(ui8 - I16, uint16([24,40;56,72]));
279 assert_checkequal(ui8 - ui16, uint16(65528));
280 assert_checkequal(ui8 - UI16, uint16([65528,65512;65496,65480]));
281 assert_checkequal(ui8 - i32, uint32(40));
282 assert_checkequal(ui8 - I32, uint32([40,72;104,136]));
283 assert_checkequal(ui8 - ui32, uint32(4294967272));
284 assert_checkequal(ui8 - UI32, uint32([4294967272,4294967240;4294967208,4294967176]));
285
286 assert_checkequal(UI8 - empty, uint8([8,16;24,32]));
287 assert_checkequal(UI8 - r, uint8([6,14;22,30]));
288 assert_checkequal(UI8 - R, uint8([7,14;21,28]));
289 assert_checkequal(UI8 - i8, uint8([16,24;32,40]));
290 assert_checkequal(UI8 - I8, uint8([16,32;48,64]));
291 assert_checkequal(UI8 - ui8, uint8([0,8;16,24]));
292 assert_checkequal(UI8 - UI8, uint8([0,0;0,0]));
293 assert_checkequal(UI8 - i16, uint16([24,32;40,48]));
294 assert_checkequal(UI8 - I16, uint16([24,48;72,96]));
295 assert_checkequal(UI8 - ui16, uint16([65528,0;8,16]));
296 assert_checkequal(UI8 - UI16, uint16([65528,65520;65512,65504]));
297 assert_checkequal(UI8 - i32, uint32([40,48;56,64]));
298 assert_checkequal(UI8 - I32, uint32([40,80;120,160]));
299 assert_checkequal(UI8 - ui32, uint32([4294967272,4294967280;4294967288,0]));
300 assert_checkequal(UI8 - UI32, uint32([4294967272,4294967248;4294967224,4294967200]));
301
302 assert_checkequal(i16 - empty, int16(-16));
303 assert_checkequal(i16 - r, int16(-18));
304 assert_checkequal(i16 - R, int16([-17,-18;-19,-20]));
305 assert_checkequal(i16 - i8, int16(-8));
306 assert_checkequal(i16 - I8, int16([-8,0;8,16]));
307 assert_checkequal(i16 - ui8, uint16(65512));
308 assert_checkequal(i16 - UI8, uint16([65512,65504;65496,65488]));
309 assert_checkequal(i16 - i16, int16(0));
310 assert_checkequal(i16 - I16, int16([0,16;32,48]));
311 assert_checkequal(i16 - ui16, uint16(65504));
312 assert_checkequal(i16 - UI16, uint16([65504,65488;65472,65456]));
313 assert_checkequal(i16 - i32, int32(16));
314 assert_checkequal(i16 - I32, int32([16,48;80,112]));
315 assert_checkequal(i16 - ui32, uint32(4294967248));
316 assert_checkequal(i16 - UI32, uint32([4294967248,4294967216;4294967184,4294967152]));
317
318 assert_checkequal(I16 - empty, int16([-16,-32;-48,-64]));
319 assert_checkequal(I16 - r, int16([-18,-34;-50,-66]));
320 assert_checkequal(I16 - R, int16([-17,-34;-51,-68]));
321 assert_checkequal(I16 - i8, int16([-8,-24;-40,-56]));
322 assert_checkequal(I16 - I8, int16([-8,-16;-24,-32]));
323 assert_checkequal(I16 - ui8, uint16([65512,65496;65480,65464]));
324 assert_checkequal(I16 - UI8, uint16([65512,65488;65464,65440]));
325 assert_checkequal(I16 - i16, int16([0,-16;-32,-48]));
326 assert_checkequal(I16 - I16, int16([0,0;0,0]));
327 assert_checkequal(I16 - ui16, uint16([65504,65488;65472,65456]));
328 assert_checkequal(I16 - UI16, uint16([65504,65472;65440,65408]));
329 assert_checkequal(I16 - i32, int32([16,0;-16,-32]));
330 assert_checkequal(I16 - I32, int32([16,32;48,64]));
331 assert_checkequal(I16 - ui32, uint32([4294967248,4294967232;4294967216,4294967200]));
332 assert_checkequal(I16 - UI32, uint32([4294967248,4294967200;4294967152,4294967104]));
333
334 assert_checkequal(ui16 - empty, uint16(16));
335 assert_checkequal(ui16 - r, uint16(14));
336 assert_checkequal(ui16 - R, uint16([15,14;13,12]));
337 assert_checkequal(ui16 - i8, uint16(24));
338 assert_checkequal(ui16 - I8, uint16([24,32;40,48]));
339 assert_checkequal(ui16 - ui8, uint16(8));
340 assert_checkequal(ui16 - UI8, uint16([8,0;65528,65520]));
341 assert_checkequal(ui16 - i16, uint16(32));
342 assert_checkequal(ui16 - I16, uint16([32,48;64,80]));
343 assert_checkequal(ui16 - ui16, uint16(0));
344 assert_checkequal(ui16 - UI16, uint16([0,65520;65504,65488]));
345 assert_checkequal(ui16 - i32, uint32(48));
346 assert_checkequal(ui16 - I32, uint32([48,80;112,144]));
347 assert_checkequal(ui16 - ui32, uint32(4294967280));
348 assert_checkequal(ui16 - UI32, uint32([4294967280,4294967248;4294967216,4294967184]));
349
350 assert_checkequal(UI16 - empty, uint16([16,32;48,64]));
351 assert_checkequal(UI16 - r, uint16([14,30;46,62]));
352 assert_checkequal(UI16 - R, uint16([15,30;45,60]));
353 assert_checkequal(UI16 - i8, uint16([24,40;56,72]));
354 assert_checkequal(UI16 - I8, uint16([24,48;72,96]));
355 assert_checkequal(UI16 - ui8, uint16([8,24;40,56]));
356 assert_checkequal(UI16 - UI8, uint16([8,16;24,32]));
357 assert_checkequal(UI16 - i16, uint16([32,48;64,80]));
358 assert_checkequal(UI16 - I16, uint16([32,64;96,128]));
359 assert_checkequal(UI16 - ui16, uint16([0,16;32,48]));
360 assert_checkequal(UI16 - UI16, uint16([0,0;0,0]));
361 assert_checkequal(UI16 - i32, uint32([48,64;80,96]));
362 assert_checkequal(UI16 - I32, uint32([48,96;144,192]));
363 assert_checkequal(UI16 - ui32, uint32([4294967280,0;16,32]));
364 assert_checkequal(UI16 - UI32, uint32([4294967280,4294967264;4294967248,4294967232]));
365
366 assert_checkequal(i32 - empty, int32(-32));
367 assert_checkequal(i32 - r, int32(-34));
368 assert_checkequal(i32 - R, int32([-33,-34;-35,-36]));
369 assert_checkequal(i32 - i8, int32(-24));
370 assert_checkequal(i32 - I8, int32([-24,-16;-8,0]));
371 assert_checkequal(i32 - ui8, uint32(4294967256));
372 assert_checkequal(i32 - UI8, uint32([4294967256,4294967248;4294967240,4294967232]));
373 assert_checkequal(i32 - i16, int32(-16));
374 assert_checkequal(i32 - I16, int32([-16,0;16,32]));
375 assert_checkequal(i32 - ui16, uint32(4294967248));
376 assert_checkequal(i32 - UI16, uint32([4294967248,4294967232;4294967216,4294967200]));
377 assert_checkequal(i32 - i32, int32(0));
378 assert_checkequal(i32 - I32, int32([0,32;64,96]));
379 assert_checkequal(i32 - ui32, uint32(4294967232));
380 assert_checkequal(i32 - UI32, uint32([4294967232,4294967200;4294967168,4294967136]));
381
382 assert_checkequal(I32 - empty, int32([-32,-64;-96,-128]));
383 assert_checkequal(I32 - r, int32([-34,-66;-98,-130]));
384 assert_checkequal(I32 - R, int32([-33,-66;-99,-132]));
385 assert_checkequal(I32 - i8, int32([-24,-56;-88,-120]));
386 assert_checkequal(I32 - I8, int32([-24,-48;-72,-96]));
387 assert_checkequal(I32 - ui8, uint32([4294967256,4294967224;4294967192,4294967160]));
388 assert_checkequal(I32 - UI8, uint32([4294967256,4294967216;4294967176,4294967136]));
389 assert_checkequal(I32 - i16, int32([-16,-48;-80,-112]));
390 assert_checkequal(I32 - I16, int32([-16,-32;-48,-64]));
391 assert_checkequal(I32 - ui16, uint32([4294967248,4294967216;4294967184,4294967152]));
392 assert_checkequal(I32 - UI16, uint32([4294967248,4294967200;4294967152,4294967104]));
393 assert_checkequal(I32 - i32, int32([0,-32;-64,-96]));
394 assert_checkequal(I32 - I32, int32([0,0;0,0]));
395 assert_checkequal(I32 - ui32, uint32([4294967232,4294967200;4294967168,4294967136]));
396 assert_checkequal(I32 - UI32, uint32([4294967232,4294967168;4294967104,4294967040]));
397
398 assert_checkequal(ui32 - empty, uint32(32));
399 assert_checkequal(ui32 - r, uint32(30));
400 assert_checkequal(ui32 - R, uint32([31,30;29,28]));
401 assert_checkequal(ui32 - i8, uint32(40));
402 assert_checkequal(ui32 - I8, uint32([40,48;56,64]));
403 assert_checkequal(ui32 - ui8, uint32(24));
404 assert_checkequal(ui32 - UI8, uint32([24,16;8,0]));
405 assert_checkequal(ui32 - i16, uint32(48));
406 assert_checkequal(ui32 - I16, uint32([48,64;80,96]));
407 assert_checkequal(ui32 - ui16, uint32(16));
408 assert_checkequal(ui32 - UI16, uint32([16,0;4294967280,4294967264]));
409 assert_checkequal(ui32 - i32, uint32(64));
410 assert_checkequal(ui32 - I32, uint32([64,96;128,160]));
411 assert_checkequal(ui32 - ui32, uint32(0));
412 assert_checkequal(ui32 - UI32, uint32([0,4294967264;4294967232,4294967200]));
413
414 assert_checkequal(UI32 - empty, uint32([32,64;96,128]));
415 assert_checkequal(UI32 - r, uint32([30,62;94,126]));
416 assert_checkequal(UI32 - R, uint32([31,62;93,124]));
417 assert_checkequal(UI32 - i8, uint32([40,72;104,136]));
418 assert_checkequal(UI32 - I8, uint32([40,80;120,160]));
419 assert_checkequal(UI32 - ui8, uint32([24,56;88,120]));
420 assert_checkequal(UI32 - UI8, uint32([24,48;72,96]));
421 assert_checkequal(UI32 - i16, uint32([48,80;112,144]));
422 assert_checkequal(UI32 - I16, uint32([48,96;144,192]));
423 assert_checkequal(UI32 - ui16, uint32([16,48;80,112]));
424 assert_checkequal(UI32 - UI16, uint32([16,32;48,64]));
425 assert_checkequal(UI32 - i32, uint32([64,96;128,160]));
426 assert_checkequal(UI32 - I32, uint32([64,128;192,256]));
427 assert_checkequal(UI32 - ui32, uint32([0,32;64,96]));
428 assert_checkequal(UI32 - UI32, uint32([0,0;0,0]));
429
430
431
432 // OPPOSITE
433
434 // - []
435 assert_checkequal(-[], []);
436 // - eye
437 assert_checkequal(-e, eye() * -1);
438 // - eye complex
439 assert_checkequal(-ec, (-5-%i) * eye());
440 // - double
441 assert_checkequal(-r, -2);
442 // - double complex
443 assert_checkequal(-c, - 1 - 2*%i);
444 // - DOUBLE
445 assert_checkequal(-R, [-1 -2;-3 -4]);
446 // - DOUBLE COMPLEX
447 assert_checkequal(-C, [-1-2*%i -2-4*%i;-3-6*%i -4-8*%i]);
448 // - int
449 assert_checkequal(-i8, int8(8));
450 assert_checkequal(-i16, int16(16));
451 assert_checkequal(-i32, int32(32));
452 assert_checkequal(-ui8, uint8(-8));
453 assert_checkequal(-ui16, uint16(-16));
454 assert_checkequal(-ui32, uint32(-32));
455 // - INT
456 assert_checkequal(-I8, int8([8 16 ; 24 32]));
457 assert_checkequal(-I16, int16([16 32 ; 48 64]));
458 assert_checkequal(-I32, int32([32 64 ; 96 128]));
459 assert_checkequal(-UI8, uint8([-8 -16 ; -24 -32]));
460 assert_checkequal(-UI16, uint16([-16 -32 ; -48 -64]));
461 assert_checkequal(-UI32, uint32([-32 -64 ; -96 -128]));
462 // - SPARSE
463 assert_checkequal(-SP, sparse([1,2;4,5;3,10],[-1,-2,-3]));
464 // - SPARSE COMPLEX
465 assert_checkequal(-SPC, sparse([1,2;4,5;3,10],[1,2,3]) * ( -1 - 4*%i));
466 // - polynom
467 assert_checkequal(-p, -1-%s+%s**2);
468 // - polynom complex
469 assert_checkequal(-pc, - 1 - %s + %s**2 + ( - 2 + 3 * %s - 4 * %s**2 ) * %i);
470 // - POLYNOM
471 assert_checkequal(-P, [-2-2*%s+2*%s**2 3+3*%s-3*%s**2; -4-4*%s+4*%s**2, 5+5*%s-5*%s**2]);
472 // - POLYNOM COMPLEX
473 assert_checkequal(-PC, [-2-2*%s+2*%s**2 3+3*%s-3*%s**2; -4-4*%s+4*%s**2, 5+5*%s-5*%s**2] + ([-4+6*%s-8*%s**2 6-9*%s+12*%s**2; -8+12*%s-16*%s**2 10-15*%s+20*%s**2] * %i));
474