This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Upgrade to Math::Complex 1.48 and Math::Trig 1.13
[perl5.git] / lib / Math / Complex.t
CommitLineData
89d0527d
RM
1#!./perl
2
89d0527d 3#
5aabfad6 4# Regression tests for the Math::Complex pacakge
b42d0ec9
JH
5# -- Raphael Manfredi since Sep 1996
6# -- Jarkko Hietaniemi since Mar 1997
7# -- Daniel S. Lewart since Sep 1997
5aabfad6 8
89d0527d 9BEGIN {
bf5f1b4c
JH
10 if ($ENV{PERL_CORE}) {
11 chdir 't' if -d 't';
12 @INC = '../lib';
13 }
89d0527d 14}
5aabfad6 15
b57c8994 16use Math::Complex 1.48;
89d0527d 17
476757f7
YN
18use vars qw($VERSION);
19
91cb744f 20$VERSION = 1.92;
b42d0ec9 21
fb73857a
PP
22my ($args, $op, $target, $test, $test_set, $try, $val, $zvalue, @set, @val);
23
89d0527d
RM
24$test = 0;
25$| = 1;
fb73857a 26my @script = (
bf5f1b4c 27 'my ($res, $s0,$s1,$s2,$s3,$s4,$s5,$s6,$s7,$s8,$s9,$s10,$z0,$z1,$z2);' .
fb73857a
PP
28 "\n\n"
29);
b42d0ec9 30my $eps = 1e-13;
89d0527d 31
d09ae4e6 32if ($^O eq 'unicos') { # For some reason root() produces very inaccurate
f3ff050f 33 $eps = 1e-10; # results in Cray UNICOS, and occasionally also
d09ae4e6
JH
34} # cos(), sin(), cosh(), sinh(). The division
35 # of doubles is the current suspect.
36
89d0527d 37while (<DATA>) {
0c721ce2
JH
38 s/^\s+//;
39 next if $_ eq '' || /^\#/;
40 chomp;
41 $test_set = 0; # Assume not a test over a set of values
0e505df1 42 if (/^&(.+)/) {
89d0527d
RM
43 $op = $1;
44 next;
45 }
0e505df1 46 elsif (/^\{(.+)\}/) {
89d0527d
RM
47 set($1, \@set, \@val);
48 next;
49 }
50 elsif (s/^\|//) {
0c721ce2 51 $test_set = 1; # Requests we loop over the set...
89d0527d
RM
52 }
53 my @args = split(/:/);
0c721ce2 54 if ($test_set == 1) {
89d0527d
RM
55 my $i;
56 for ($i = 0; $i < @set; $i++) {
0c721ce2
JH
57 # complex number
58 $target = $set[$i];
59 # textual value as found in set definition
60 $zvalue = $val[$i];
89d0527d
RM
61 test($zvalue, $target, @args);
62 }
63 } else {
64 test($op, undef, @args);
65 }
66}
67
b42d0ec9
JH
68#
69
70sub test_mutators {
71 my $op;
72
73 $test++;
74push(@script, <<'EOT');
75{
76 my $z = cplx( 1, 1);
77 $z->Re(2);
78 $z->Im(3);
16357284 79 print "# $test Re(z) = ",$z->Re(), " Im(z) = ", $z->Im(), " z = $z\n";
b42d0ec9
JH
80 print 'not ' unless Re($z) == 2 and Im($z) == 3;
81EOT
82 push(@script, qq(print "ok $test\\n"}\n));
83
84 $test++;
85push(@script, <<'EOT');
86{
87 my $z = cplx( 1, 1);
88 $z->abs(3 * sqrt(2));
16357284 89 print "# $test Re(z) = ",$z->Re(), " Im(z) = ", $z->Im(), " z = $z\n";
b42d0ec9
JH
90 print 'not ' unless (abs($z) - 3 * sqrt(2)) < $eps and
91 (arg($z) - pi / 4 ) < $eps and
92 (Re($z) - 3 ) < $eps and
93 (Im($z) - 3 ) < $eps;
94EOT
95 push(@script, qq(print "ok $test\\n"}\n));
96
97 $test++;
98push(@script, <<'EOT');
99{
100 my $z = cplx( 1, 1);
101 $z->arg(-3 / 4 * pi);
16357284 102 print "# $test Re(z) = ",$z->Re(), " Im(z) = ", $z->Im(), " z = $z\n";
b42d0ec9
JH
103 print 'not ' unless (arg($z) + 3 / 4 * pi) < $eps and
104 (abs($z) - sqrt(2) ) < $eps and
105 (Re($z) + 1 ) < $eps and
106 (Im($z) + 1 ) < $eps;
107EOT
108 push(@script, qq(print "ok $test\\n"}\n));
109}
110
111test_mutators();
112
113my $constants = '
114my $i = cplx(0, 1);
115my $pi = cplx(pi, 0);
116my $pii = cplx(0, pi);
117my $pip2 = cplx(pi/2, 0);
bf5f1b4c 118my $pip4 = cplx(pi/4, 0);
b42d0ec9 119my $zero = cplx(0, 0);
bf5f1b4c 120my $inf = 9**9**9;
b42d0ec9
JH
121';
122
123push(@script, $constants);
124
125
5cd24f17
PP
126# test the divbyzeros
127
0e505df1
JH
128sub test_dbz {
129 for my $op (@_) {
130 $test++;
b42d0ec9 131 push(@script, <<EOT);
16357284
JH
132 eval '$op';
133 (\$bad) = (\$@ =~ /(.+)/);
134 print "# $test op = $op divbyzero? \$bad...\n";
135 print 'not ' unless (\$@ =~ /Division by zero/);
b42d0ec9
JH
136EOT
137 push(@script, qq(print "ok $test\\n";\n));
0e505df1
JH
138 }
139}
140
8c03c583
JH
141# test the logofzeros
142
143sub test_loz {
144 for my $op (@_) {
145 $test++;
b42d0ec9 146 push(@script, <<EOT);
16357284
JH
147 eval '$op';
148 (\$bad) = (\$@ =~ /(.+)/);
149 print "# $test op = $op logofzero? \$bad...\n";
150 print 'not ' unless (\$@ =~ /Logarithm of zero/);
b42d0ec9
JH
151EOT
152 push(@script, qq(print "ok $test\\n";\n));
8c03c583
JH
153 }
154}
155
5cd24f17
PP
156test_dbz(
157 'i/0',
b42d0ec9
JH
158 'acot(0)',
159 'acot(+$i)',
160# 'acoth(-1)', # Log of zero.
161 'acoth(0)',
162 'acoth(+1)',
5cd24f17 163 'acsc(0)',
5cd24f17 164 'acsch(0)',
b42d0ec9
JH
165 'asec(0)',
166 'asech(0)',
b42d0ec9
JH
167 'atan($i)',
168# 'atanh(-1)', # Log of zero.
169 'atanh(+1)',
170 'cot(0)',
171 'coth(0)',
172 'csc(0)',
b42d0ec9 173 'csch(0)',
bf5f1b4c 174 'atan(cplx(0, 1), cplx(1, 0))',
8c03c583
JH
175 );
176
177test_loz(
fb73857a 178 'log($zero)',
1fa12f56 179 'atan(-$i)',
b42d0ec9 180 'acot(-$i)',
8c03c583
JH
181 'atanh(-1)',
182 'acoth(-1)',
5cd24f17
PP
183 );
184
0e505df1
JH
185# test the bad roots
186
187sub test_broot {
5cd24f17
PP
188 for my $op (@_) {
189 $test++;
b42d0ec9 190 push(@script, <<EOT);
16357284
JH
191 eval 'root(2, $op)';
192 (\$bad) = (\$@ =~ /(.+)/);
193 print "# $test op = $op badroot? \$bad...\n";
1fa12f56 194 print 'not ' unless (\$@ =~ /root rank must be/);
b42d0ec9
JH
195EOT
196 push(@script, qq(print "ok $test\\n";\n));
5cd24f17
PP
197 }
198}
199
0e505df1
JH
200test_broot(qw(-3 -2.1 0 0.99));
201
16357284 202sub test_display_format {
476757f7
YN
203 $test++;
204 push @script, <<EOS;
205 print "# package display_format cartesian?\n";
206 print "not " unless Math::Complex->display_format eq 'cartesian';
207 print "ok $test\n";
208EOS
209
16357284
JH
210 push @script, <<EOS;
211 my \$j = (root(1,3))[1];
212
213 \$j->display_format('polar');
214EOS
215
216 $test++;
217 push @script, <<EOS;
476757f7 218 print "# j display_format polar?\n";
16357284
JH
219 print "not " unless \$j->display_format eq 'polar';
220 print "ok $test\n";
221EOS
222
223 $test++;
224 push @script, <<EOS;
225 print "# j = \$j\n";
226 print "not " unless "\$j" eq "[1,2pi/3]";
227 print "ok $test\n";
228
229 my %display_format;
230
231 %display_format = \$j->display_format;
232EOS
233
234 $test++;
235 push @script, <<EOS;
236 print "# display_format{style} polar?\n";
237 print "not " unless \$display_format{style} eq 'polar';
238 print "ok $test\n";
239EOS
240
241 $test++;
242 push @script, <<EOS;
243 print "# keys %display_format == 2?\n";
244 print "not " unless keys %display_format == 2;
245 print "ok $test\n";
246
247 \$j->display_format('style' => 'cartesian', 'format' => '%.5f');
248EOS
249
250 $test++;
251 push @script, <<EOS;
252 print "# j = \$j\n";
253 print "not " unless "\$j" eq "-0.50000+0.86603i";
254 print "ok $test\n";
255
256 %display_format = \$j->display_format;
257EOS
258
259 $test++;
260 push @script, <<EOS;
261 print "# display_format{format} %.5f?\n";
262 print "not " unless \$display_format{format} eq '%.5f';
263 print "ok $test\n";
264EOS
265
266 $test++;
267 push @script, <<EOS;
268 print "# keys %display_format == 3?\n";
269 print "not " unless keys %display_format == 3;
270 print "ok $test\n";
271
272 \$j->display_format('format' => undef);
273EOS
274
275 $test++;
276 push @script, <<EOS;
277 print "# j = \$j\n";
057216a3 278 print "not " unless "\$j" =~ /^-0(?:\\.5(?:0000\\d+)?|\\.49999\\d+)\\+0.86602540\\d+i\$/;
16357284
JH
279 print "ok $test\n";
280
281 \$j->display_format('style' => 'polar', 'polar_pretty_print' => 0);
282EOS
283
284 $test++;
285 push @script, <<EOS;
286 print "# j = \$j\n";
1ab88a68 287 print "not " unless "\$j" =~ /^\\[1,2\\.09439510\\d+\\]\$/;
16357284
JH
288 print "ok $test\n";
289
290 \$j->display_format('style' => 'cartesian', 'format' => '(%.5g)');
291EOS
476757f7 292
16357284
JH
293 $test++;
294 push @script, <<EOS;
295 print "# j = \$j\n";
296 print "not " unless "\$j" eq "(-0.5)+(0.86603)i";
297 print "ok $test\n";
298EOS
476757f7
YN
299
300 $test++;
301 push @script, <<EOS;
302 print "# j display_format cartesian?\n";
303 print "not " unless \$j->display_format eq 'cartesian';
304 print "ok $test\n";
305EOS
16357284
JH
306}
307
308test_display_format();
309
91cb744f
JH
310sub test_remake {
311 $test++;
312 push @script, <<EOS;
313 print "# remake 2+3i\n";
bf5f1b4c 314 \$z = cplx('2+3i');
91cb744f
JH
315 print "not " unless \$z == Math::Complex->make(2,3);
316 print "ok $test\n";
317EOS
318
319 $test++;
320 push @script, <<EOS;
bf5f1b4c
JH
321 print "# make 3i\n";
322 \$z = Math::Complex->make('3i');
91cb744f
JH
323 print "not " unless \$z == cplx(0,3);
324 print "ok $test\n";
325EOS
326
327 $test++;
328 push @script, <<EOS;
bf5f1b4c
JH
329 print "# emake [2,3]\n";
330 \$z = Math::Complex->emake('[2,3]');
331 print "not " unless \$z == cplxe(2,3);
332 print "ok $test\n";
333EOS
334
335 $test++;
336 push @script, <<EOS;
337 print "# make (2,3)\n";
338 \$z = Math::Complex->make('(2,3)');
339 print "not " unless \$z == cplx(2,3);
340 print "ok $test\n";
341EOS
342
343 $test++;
344 push @script, <<EOS;
345 print "# emake [2,3pi/8]\n";
346 \$z = Math::Complex->emake('[2,3pi/8]');
347 print "not " unless \$z == cplxe(2,3*\$pi/8);
91cb744f
JH
348 print "ok $test\n";
349EOS
350
351 $test++;
352 push @script, <<EOS;
bf5f1b4c
JH
353 print "# emake [2]\n";
354 \$z = Math::Complex->emake('[2]');
91cb744f
JH
355 print "not " unless \$z == cplxe(2);
356 print "ok $test\n";
357EOS
358}
359
bf5f1b4c
JH
360sub test_no_args {
361 push @script, <<'EOS';
362{
363 print "# cplx, cplxe, make, emake without arguments\n";
364EOS
365
366 $test++;
367 push @script, <<EOS;
368 my \$z0 = cplx();
369 print ((\$z0->Re() == 0) ? "ok $test\n" : "not ok $test\n");
370EOS
371
372 $test++;
373 push @script, <<EOS;
374 print ((\$z0->Im() == 0) ? "ok $test\n" : "not ok $test\n");
375EOS
376
377 $test++;
378 push @script, <<EOS;
379 my \$z1 = cplxe();
380 print ((\$z1->rho() == 0) ? "ok $test\n" : "not ok $test\n");
381EOS
382
383 $test++;
384 push @script, <<EOS;
385 print ((\$z1->theta() == 0) ? "ok $test\n" : "not ok $test\n");
386EOS
387
388 $test++;
389 push @script, <<EOS;
390 my \$z2 = Math::Complex->make();
391 print ((\$z2->Re() == 0) ? "ok $test\n" : "not ok $test\n");
392EOS
393
394 $test++;
395 push @script, <<EOS;
396 print ((\$z2->Im() == 0) ? "ok $test\n" : "not ok $test\n");
397EOS
398
399 $test++;
400 push @script, <<EOS;
401 my \$z3 = Math::Complex->emake();
402 print ((\$z3->rho() == 0) ? "ok $test\n" : "not ok $test\n");
403EOS
404
405 $test++;
406 push @script, <<EOS;
407 print ((\$z3->theta() == 0) ? "ok $test\n" : "not ok $test\n");
408}
409EOS
410}
411
412sub test_atan2 {
413 push @script, <<'EOS';
414print "# atan2() with some real arguments\n";
415EOS
416 my @real = (-1, 0, 1);
417 for my $x (@real) {
418 for my $y (@real) {
419 next if $x == 0 && $y == 0;
420 $test++;
421 push @script, <<EOS;
422print ((Math::Complex::atan2($y, $x) == CORE::atan2($y, $x)) ? "ok $test\n" : "not ok $test\n");
423EOS
424 }
425 }
426 push @script, <<'EOS';
427 print "# atan2() with some complex arguments\n";
428EOS
429 $test++;
430 push @script, <<EOS;
431 print (abs(atan2(0, cplx(0, 1))) < $eps ? "ok $test\n" : "not ok $test\n");
432EOS
433 $test++;
434 push @script, <<EOS;
435 print (abs(atan2(cplx(0, 1), 0) - \$pip2) < $eps ? "ok $test\n" : "not ok $test\n");
436EOS
437 $test++;
438 push @script, <<EOS;
439 print (abs(atan2(cplx(0, 1), cplx(0, 1)) - \$pip4) < $eps ? "ok $test\n" : "not ok $test\n");
440EOS
441 $test++;
442 push @script, <<EOS;
443 print (abs(atan2(cplx(0, 1), cplx(1, 1)) - cplx(0.553574358897045, 0.402359478108525)) < $eps ? "ok $test\n" : "not ok $test\n");
444EOS
445}
446
447sub test_decplx {
448}
449
91cb744f
JH
450test_remake();
451
bf5f1b4c
JH
452test_no_args();
453
454test_atan2();
455
456test_decplx();
457
89d0527d 458print "1..$test\n";
bf5f1b4c 459#print @script, "\n";
fe82cf6e 460eval join '', @script;
89d0527d
RM
461die $@ if $@;
462
0e505df1
JH
463sub abop {
464 my ($op) = @_;
465
466 push(@script, qq(print "# $op=\n";));
467}
468
89d0527d
RM
469sub test {
470 my ($op, $z, @args) = @_;
0e505df1 471 my ($baop) = 0;
89d0527d
RM
472 $test++;
473 my $i;
0e505df1 474 $baop = 1 if ($op =~ s/;=$//);
89d0527d
RM
475 for ($i = 0; $i < @args; $i++) {
476 $val = value($args[$i]);
fe82cf6e 477 push @script, "\$z$i = $val;\n";
89d0527d
RM
478 }
479 if (defined $z) {
480 $args = "'$op'"; # Really the value
0c721ce2 481 $try = "abs(\$z0 - \$z1) <= $eps ? \$z1 : \$z0";
fe82cf6e
CS
482 push @script, "\$res = $try; ";
483 push @script, "check($test, $args[0], \$res, \$z$#args, $args);\n";
89d0527d
RM
484 } else {
485 my ($try, $args);
486 if (@args == 2) {
487 $try = "$op \$z0";
488 $args = "'$args[0]'";
489 } else {
490 $try = ($op =~ /^\w/) ? "$op(\$z0, \$z1)" : "\$z0 $op \$z1";
491 $args = "'$args[0]', '$args[1]'";
492 }
fe82cf6e
CS
493 push @script, "\$res = $try; ";
494 push @script, "check($test, '$try', \$res, \$z$#args, $args);\n";
0e505df1
JH
495 if (@args > 2 and $baop) { # binary assignment ops
496 $test++;
497 # check the op= works
498 push @script, <<EOB;
499{
affad850 500 my \$za = cplx(ref \$z0 ? \@{\$z0->_cartesian} : (\$z0, 0));
0e505df1 501
affad850 502 my (\$z1r, \$z1i) = ref \$z1 ? \@{\$z1->_cartesian} : (\$z1, 0);
0e505df1 503
fb73857a 504 my \$zb = cplx(\$z1r, \$z1i);
0e505df1
JH
505
506 \$za $op= \$zb;
affad850 507 my (\$zbr, \$zbi) = \@{\$zb->_cartesian};
0e505df1
JH
508
509 check($test, '\$z0 $op= \$z1', \$za, \$z$#args, $args);
510EOB
511 $test++;
512 # check that the rhs has not changed
513 push @script, qq(print "not " unless (\$zbr == \$z1r and \$zbi == \$z1i););
b42d0ec9 514 push @script, qq(print "ok $test\\n";\n);
0e505df1
JH
515 push @script, "}\n";
516 }
89d0527d
RM
517 }
518}
519
520sub set {
521 my ($set, $setref, $valref) = @_;
522 @{$setref} = ();
523 @{$valref} = ();
524 my @set = split(/;\s*/, $set);
525 my @res;
526 my $i;
527 for ($i = 0; $i < @set; $i++) {
528 push(@{$valref}, $set[$i]);
529 my $val = value($set[$i]);
fe82cf6e
CS
530 push @script, "\$s$i = $val;\n";
531 push @{$setref}, "\$s$i";
89d0527d
RM
532 }
533}
534
535sub value {
536 local ($_) = @_;
537 if (/^\s*\((.*),(.*)\)/) {
538 return "cplx($1,$2)";
539 }
b42d0ec9
JH
540 elsif (/^\s*([\-\+]?(?:\d+(\.\d+)?|\.\d+)(?:[e[\-\+]\d+])?)/) {
541 return "cplx($1,0)";
542 }
89d0527d
RM
543 elsif (/^\s*\[(.*),(.*)\]/) {
544 return "cplxe($1,$2)";
545 }
546 elsif (/^\s*'(.*)'/) {
547 my $ex = $1;
548 $ex =~ s/\bz\b/$target/g;
549 $ex =~ s/\br\b/abs($target)/g;
550 $ex =~ s/\bt\b/arg($target)/g;
551 $ex =~ s/\ba\b/Re($target)/g;
552 $ex =~ s/\bb\b/Im($target)/g;
553 return $ex;
554 }
555 elsif (/^\s*"(.*)"/) {
556 return "\"$1\"";
557 }
558 return $_;
559}
560
561sub check {
562 my ($test, $try, $got, $expected, @z) = @_;
0c721ce2 563
16357284 564 print "# @_\n";
0c721ce2
JH
565
566 if ("$got" eq "$expected"
567 ||
568 ($expected =~ /^-?\d/ && $got == $expected)
569 ||
bf5f1b4c
JH
570 (abs(Math::Complex->make($got) - Math::Complex->make($expected)) < $eps)
571 ||
0c721ce2
JH
572 (abs($got - $expected) < $eps)
573 ) {
89d0527d
RM
574 print "ok $test\n";
575 } else {
576 print "not ok $test\n";
577 my $args = (@z == 1) ? "z = $z[0]" : "z0 = $z[0], z1 = $z[1]";
578 print "# '$try' expected: '$expected' got: '$got' for $args\n";
579 }
580}
fb73857a
PP
581
582sub addsq {
583 my ($z1, $z2) = @_;
584 return ($z1 + i*$z2) * ($z1 - i*$z2);
585}
586
587sub subsq {
588 my ($z1, $z2) = @_;
589 return ($z1 + $z2) * ($z1 - $z2);
590}
591
89d0527d 592__END__
0e505df1 593&+;=
89d0527d
RM
594(3,4):(3,4):(6,8)
595(-3,4):(3,-4):(0,0)
596(3,4):-3:(0,4)
5971:(4,2):(5,2)
598[2,0]:[2,pi]:(0,0)
599
600&++
601(2,1):(3,1)
602
0e505df1 603&-;=
89d0527d
RM
604(2,3):(-2,-3)
605[2,pi/2]:[2,-(pi)/2]
6062:[2,0]:(0,0)
607[3,0]:2:(1,0)
6083:(4,5):(-1,-5)
609(4,5):3:(1,5)
0e505df1 610(2,1):(3,5):(-1,-4)
89d0527d
RM
611
612&--
613(1,2):(0,2)
614[2,pi]:[3,pi]
615
0e505df1 616&*;=
89d0527d
RM
617(0,1):(0,1):(-1,0)
618(4,5):(1,0):(4,5)
619[2,2*pi/3]:(1,0):[2,2*pi/3]
6202:(0,1):(0,2)
621(0,1):3:(0,3)
622(0,1):(4,1):(-1,4)
623(2,1):(4,-1):(9,2)
624
0e505df1 625&/;=
89d0527d
RM
626(3,4):(3,4):(1,0)
627(4,-5):1:(4,-5)
6281:(0,1):(0,-1)
629(0,6):(0,2):(3,0)
630(9,2):(4,-1):(2,1)
631[4,pi]:[2,pi/2]:[2,pi/2]
632[2,pi/2]:[4,pi]:[0.5,-(pi)/2]
633
0e505df1
JH
634&**;=
635(2,0):(3,0):(8,0)
636(3,0):(2,0):(9,0)
637(2,3):(4,0):(-119,-120)
ace5de91
GS
638(0,0):(1,0):(0,0)
639(0,0):(2,3):(0,0)
640(1,0):(0,0):(1,0)
641(1,0):(1,0):(1,0)
642(1,0):(2,3):(1,0)
643(2,3):(0,0):(1,0)
644(2,3):(1,0):(2,3)
2820d885 645(0,0):(0,0):(1,0)
0e505df1 646
0c721ce2
JH
647&Re
648(3,4):3
649(-3,4):-3
650[1,pi/2]:0
651
652&Im
653(3,4):4
654(3,-4):-4
655[1,pi/2]:1
656
89d0527d
RM
657&abs
658(3,4):5
659(-3,4):5
660
0c721ce2
JH
661&arg
662[2,0]:0
663[-2,0]:pi
664
89d0527d
RM
665&~
666(4,5):(4,-5)
667(-3,4):(-3,-4)
668[2,pi/2]:[2,-(pi)/2]
669
670&<
671(3,4):(1,2):0
672(3,4):(3,2):0
673(3,4):(3,8):1
674(4,4):(5,129):1
675
676&==
677(3,4):(4,5):0
678(3,4):(3,5):0
679(3,4):(2,4):0
680(3,4):(3,4):1
681
682&sqrt
0c721ce2 683-9:(0,3)
89d0527d
RM
684(-100,0):(0,10)
685(16,-30):(5,-3)
686
affad850 687&_stringify_cartesian
89d0527d
RM
688(-100,0):"-100"
689(0,1):"i"
690(4,-3):"4-3i"
691(4,0):"4"
692(-4,0):"-4"
693(-2,4):"-2+4i"
694(-2,-1):"-2-i"
695
affad850 696&_stringify_polar
89d0527d
RM
697[-1, 0]:"[1,pi]"
698[1, pi/3]:"[1,pi/3]"
699[6, -2*pi/3]:"[6,-2pi/3]"
700[0.5, -9*pi/11]:"[0.5,-9pi/11]"
701
702{ (4,3); [3,2]; (-3,4); (0,2); [2,1] }
703
704|'z + ~z':'2*Re(z)'
705|'z - ~z':'2*i*Im(z)'
706|'z * ~z':'abs(z) * abs(z)'
707
8c03c583 708{ (0.5, 0); (-0.5, 0); (2,3); [3,2]; (-3,2); (0,2); 3; 1.2; (-3, 0); (-2, -1); [2,1] }
89d0527d 709
0c721ce2
JH
710|'(root(z, 4))[1] ** 4':'z'
711|'(root(z, 5))[3] ** 5':'z'
712|'(root(z, 8))[7] ** 8':'z'
bf5f1b4c
JH
713|'(root(z, 8, 0)) ** 8':'z'
714|'(root(z, 8, 7)) ** 8':'z'
89d0527d 715|'abs(z)':'r'
0c721ce2
JH
716|'acot(z)':'acotan(z)'
717|'acsc(z)':'acosec(z)'
fb73857a
PP
718|'acsc(z)':'asin(1 / z)'
719|'asec(z)':'acos(1 / z)'
89d0527d 720|'cbrt(z)':'cbrt(r) * exp(i * t/3)'
89d0527d 721|'cos(acos(z))':'z'
fb73857a 722|'addsq(cos(z), sin(z))':1
89d0527d 723|'cos(z)':'cosh(i*z)'
fb73857a 724|'subsq(cosh(z), sinh(z))':1
0c721ce2
JH
725|'cot(acot(z))':'z'
726|'cot(z)':'1 / tan(z)'
727|'cot(z)':'cotan(z)'
728|'csc(acsc(z))':'z'
729|'csc(z)':'1 / sin(z)'
730|'csc(z)':'cosec(z)'
89d0527d 731|'exp(log(z))':'z'
0c721ce2
JH
732|'exp(z)':'exp(a) * exp(i * b)'
733|'ln(z)':'log(z)'
734|'log(exp(z))':'z'
735|'log(z)':'log(r) + i*t'
89d0527d 736|'log10(z)':'log(z) / log(10)'
89d0527d 737|'logn(z, 2)':'log(z) / log(2)'
0c721ce2
JH
738|'logn(z, 3)':'log(z) / log(3)'
739|'sec(asec(z))':'z'
740|'sec(z)':'1 / cos(z)'
741|'sin(asin(z))':'z'
742|'sin(i * z)':'i * sinh(z)'
743|'sqrt(z) * sqrt(z)':'z'
744|'sqrt(z)':'sqrt(r) * exp(i * t/2)'
745|'tan(atan(z))':'z'
746|'z**z':'exp(z * log(z))'
89d0527d 747
0c721ce2 748{ (1,1); [1,0.5]; (-2, -1); 2; -3; (-1,0.5); (0,0.5); 0.5; (2, 0); (-1, -2) }
89d0527d 749
89d0527d 750|'cosh(acosh(z))':'z'
0c721ce2
JH
751|'coth(acoth(z))':'z'
752|'coth(z)':'1 / tanh(z)'
753|'coth(z)':'cotanh(z)'
754|'csch(acsch(z))':'z'
755|'csch(z)':'1 / sinh(z)'
756|'csch(z)':'cosech(z)'
757|'sech(asech(z))':'z'
758|'sech(z)':'1 / cosh(z)'
759|'sinh(asinh(z))':'z'
89d0527d 760|'tanh(atanh(z))':'z'
89d0527d 761
0c721ce2 762{ (0.2,-0.4); [1,0.5]; -1.2; (-1,0.5); 0.5; (1.1, 0) }
89d0527d 763
89d0527d 764|'acos(cos(z)) ** 2':'z * z'
89d0527d 765|'acosh(cosh(z)) ** 2':'z * z'
0c721ce2
JH
766|'acoth(z)':'acotanh(z)'
767|'acoth(z)':'atanh(1 / z)'
768|'acsch(z)':'acosech(z)'
769|'acsch(z)':'asinh(1 / z)'
770|'asech(z)':'acosh(1 / z)'
771|'asin(sin(z))':'z'
772|'asinh(sinh(z))':'z'
773|'atan(tan(z))':'z'
89d0527d
RM
774|'atanh(tanh(z))':'z'
775
fb73857a
PP
776&log
777(-2.0,0):( 0.69314718055995, 3.14159265358979)
778(-1.0,0):( 0 , 3.14159265358979)
779(-0.5,0):( -0.69314718055995, 3.14159265358979)
780( 0.5,0):( -0.69314718055995, 0 )
781( 1.0,0):( 0 , 0 )
782( 2.0,0):( 0.69314718055995, 0 )
783
784&log
785( 2, 3):( 1.28247467873077, 0.98279372324733)
786(-2, 3):( 1.28247467873077, 2.15879893034246)
787(-2,-3):( 1.28247467873077, -2.15879893034246)
788( 2,-3):( 1.28247467873077, -0.98279372324733)
789
0c721ce2 790&sin
8c03c583
JH
791(-2.0,0):( -0.90929742682568, 0 )
792(-1.0,0):( -0.84147098480790, 0 )
793(-0.5,0):( -0.47942553860420, 0 )
794( 0.0,0):( 0 , 0 )
795( 0.5,0):( 0.47942553860420, 0 )
796( 1.0,0):( 0.84147098480790, 0 )
797( 2.0,0):( 0.90929742682568, 0 )
798
799&sin
0c721ce2
JH
800( 2, 3):( 9.15449914691143, -4.16890695996656)
801(-2, 3):( -9.15449914691143, -4.16890695996656)
802(-2,-3):( -9.15449914691143, 4.16890695996656)
803( 2,-3):( 9.15449914691143, 4.16890695996656)
804
805&cos
8c03c583
JH
806(-2.0,0):( -0.41614683654714, 0 )
807(-1.0,0):( 0.54030230586814, 0 )
808(-0.5,0):( 0.87758256189037, 0 )
809( 0.0,0):( 1 , 0 )
810( 0.5,0):( 0.87758256189037, 0 )
811( 1.0,0):( 0.54030230586814, 0 )
812( 2.0,0):( -0.41614683654714, 0 )
813
814&cos
0c721ce2
JH
815( 2, 3):( -4.18962569096881, -9.10922789375534)
816(-2, 3):( -4.18962569096881, 9.10922789375534)
817(-2,-3):( -4.18962569096881, -9.10922789375534)
818( 2,-3):( -4.18962569096881, 9.10922789375534)
819
820&tan
8c03c583
JH
821(-2.0,0):( 2.18503986326152, 0 )
822(-1.0,0):( -1.55740772465490, 0 )
823(-0.5,0):( -0.54630248984379, 0 )
824( 0.0,0):( 0 , 0 )
825( 0.5,0):( 0.54630248984379, 0 )
826( 1.0,0):( 1.55740772465490, 0 )
827( 2.0,0):( -2.18503986326152, 0 )
828
829&tan
0c721ce2
JH
830( 2, 3):( -0.00376402564150, 1.00323862735361)
831(-2, 3):( 0.00376402564150, 1.00323862735361)
832(-2,-3):( 0.00376402564150, -1.00323862735361)
833( 2,-3):( -0.00376402564150, -1.00323862735361)
834
835&sec
8c03c583
JH
836(-2.0,0):( -2.40299796172238, 0 )
837(-1.0,0):( 1.85081571768093, 0 )
838(-0.5,0):( 1.13949392732455, 0 )
839( 0.0,0):( 1 , 0 )
840( 0.5,0):( 1.13949392732455, 0 )
841( 1.0,0):( 1.85081571768093, 0 )
842( 2.0,0):( -2.40299796172238, 0 )
843
844&sec
0c721ce2
JH
845( 2, 3):( -0.04167496441114, 0.09061113719624)
846(-2, 3):( -0.04167496441114, -0.09061113719624)
847(-2,-3):( -0.04167496441114, 0.09061113719624)
848( 2,-3):( -0.04167496441114, -0.09061113719624)
849
850&csc
8c03c583
JH
851(-2.0,0):( -1.09975017029462, 0 )
852(-1.0,0):( -1.18839510577812, 0 )
853(-0.5,0):( -2.08582964293349, 0 )
854( 0.5,0):( 2.08582964293349, 0 )
855( 1.0,0):( 1.18839510577812, 0 )
856( 2.0,0):( 1.09975017029462, 0 )
857
858&csc
0c721ce2
JH
859( 2, 3):( 0.09047320975321, 0.04120098628857)
860(-2, 3):( -0.09047320975321, 0.04120098628857)
861(-2,-3):( -0.09047320975321, -0.04120098628857)
862( 2,-3):( 0.09047320975321, -0.04120098628857)
863
864&cot
8c03c583
JH
865(-2.0,0):( 0.45765755436029, 0 )
866(-1.0,0):( -0.64209261593433, 0 )
867(-0.5,0):( -1.83048772171245, 0 )
868( 0.5,0):( 1.83048772171245, 0 )
869( 1.0,0):( 0.64209261593433, 0 )
870( 2.0,0):( -0.45765755436029, 0 )
871
872&cot
0c721ce2
JH
873( 2, 3):( -0.00373971037634, -0.99675779656936)
874(-2, 3):( 0.00373971037634, -0.99675779656936)
875(-2,-3):( 0.00373971037634, 0.99675779656936)
876( 2,-3):( -0.00373971037634, 0.99675779656936)
877
878&asin
8c03c583
JH
879(-2.0,0):( -1.57079632679490, 1.31695789692482)
880(-1.0,0):( -1.57079632679490, 0 )
881(-0.5,0):( -0.52359877559830, 0 )
882( 0.0,0):( 0 , 0 )
883( 0.5,0):( 0.52359877559830, 0 )
884( 1.0,0):( 1.57079632679490, 0 )
885( 2.0,0):( 1.57079632679490, -1.31695789692482)
886
887&asin
0c721ce2
JH
888( 2, 3):( 0.57065278432110, 1.98338702991654)
889(-2, 3):( -0.57065278432110, 1.98338702991654)
890(-2,-3):( -0.57065278432110, -1.98338702991654)
891( 2,-3):( 0.57065278432110, -1.98338702991654)
892
893&acos
8c03c583
JH
894(-2.0,0):( 3.14159265358979, -1.31695789692482)
895(-1.0,0):( 3.14159265358979, 0 )
896(-0.5,0):( 2.09439510239320, 0 )
897( 0.0,0):( 1.57079632679490, 0 )
898( 0.5,0):( 1.04719755119660, 0 )
899( 1.0,0):( 0 , 0 )
900( 2.0,0):( 0 , 1.31695789692482)
901
902&acos
0c721ce2
JH
903( 2, 3):( 1.00014354247380, -1.98338702991654)
904(-2, 3):( 2.14144911111600, -1.98338702991654)
905(-2,-3):( 2.14144911111600, 1.98338702991654)
906( 2,-3):( 1.00014354247380, 1.98338702991654)
907
908&atan
8c03c583
JH
909(-2.0,0):( -1.10714871779409, 0 )
910(-1.0,0):( -0.78539816339745, 0 )
911(-0.5,0):( -0.46364760900081, 0 )
912( 0.0,0):( 0 , 0 )
913( 0.5,0):( 0.46364760900081, 0 )
914( 1.0,0):( 0.78539816339745, 0 )
915( 2.0,0):( 1.10714871779409, 0 )
916
917&atan
0c721ce2
JH
918( 2, 3):( 1.40992104959658, 0.22907268296854)
919(-2, 3):( -1.40992104959658, 0.22907268296854)
920(-2,-3):( -1.40992104959658, -0.22907268296854)
921( 2,-3):( 1.40992104959658, -0.22907268296854)
922
923&asec
8c03c583
JH
924(-2.0,0):( 2.09439510239320, 0 )
925(-1.0,0):( 3.14159265358979, 0 )
926(-0.5,0):( 3.14159265358979, -1.31695789692482)
927( 0.5,0):( 0 , 1.31695789692482)
928( 1.0,0):( 0 , 0 )
929( 2.0,0):( 1.04719755119660, 0 )
930
931&asec
0c721ce2
JH
932( 2, 3):( 1.42041072246703, 0.23133469857397)
933(-2, 3):( 1.72118193112276, 0.23133469857397)
934(-2,-3):( 1.72118193112276, -0.23133469857397)
935( 2,-3):( 1.42041072246703, -0.23133469857397)
936
937&acsc
8c03c583
JH
938(-2.0,0):( -0.52359877559830, 0 )
939(-1.0,0):( -1.57079632679490, 0 )
940(-0.5,0):( -1.57079632679490, 1.31695789692482)
941( 0.5,0):( 1.57079632679490, -1.31695789692482)
942( 1.0,0):( 1.57079632679490, 0 )
943( 2.0,0):( 0.52359877559830, 0 )
944
945&acsc
0c721ce2
JH
946( 2, 3):( 0.15038560432786, -0.23133469857397)
947(-2, 3):( -0.15038560432786, -0.23133469857397)
948(-2,-3):( -0.15038560432786, 0.23133469857397)
949( 2,-3):( 0.15038560432786, 0.23133469857397)
950
951&acot
8c03c583
JH
952(-2.0,0):( -0.46364760900081, 0 )
953(-1.0,0):( -0.78539816339745, 0 )
954(-0.5,0):( -1.10714871779409, 0 )
955( 0.5,0):( 1.10714871779409, 0 )
956( 1.0,0):( 0.78539816339745, 0 )
957( 2.0,0):( 0.46364760900081, 0 )
958
959&acot
0c721ce2
JH
960( 2, 3):( 0.16087527719832, -0.22907268296854)
961(-2, 3):( -0.16087527719832, -0.22907268296854)
962(-2,-3):( -0.16087527719832, 0.22907268296854)
963( 2,-3):( 0.16087527719832, 0.22907268296854)
964
965&sinh
8c03c583
JH
966(-2.0,0):( -3.62686040784702, 0 )
967(-1.0,0):( -1.17520119364380, 0 )
968(-0.5,0):( -0.52109530549375, 0 )
969( 0.0,0):( 0 , 0 )
970( 0.5,0):( 0.52109530549375, 0 )
971( 1.0,0):( 1.17520119364380, 0 )
972( 2.0,0):( 3.62686040784702, 0 )
973
974&sinh
0c721ce2
JH
975( 2, 3):( -3.59056458998578, 0.53092108624852)
976(-2, 3):( 3.59056458998578, 0.53092108624852)
977(-2,-3):( 3.59056458998578, -0.53092108624852)
978( 2,-3):( -3.59056458998578, -0.53092108624852)
979
980&cosh
8c03c583
JH
981(-2.0,0):( 3.76219569108363, 0 )
982(-1.0,0):( 1.54308063481524, 0 )
983(-0.5,0):( 1.12762596520638, 0 )
984( 0.0,0):( 1 , 0 )
985( 0.5,0):( 1.12762596520638, 0 )
986( 1.0,0):( 1.54308063481524, 0 )
987( 2.0,0):( 3.76219569108363, 0 )
988
989&cosh
0c721ce2
JH
990( 2, 3):( -3.72454550491532, 0.51182256998738)
991(-2, 3):( -3.72454550491532, -0.51182256998738)
992(-2,-3):( -3.72454550491532, 0.51182256998738)
993( 2,-3):( -3.72454550491532, -0.51182256998738)
994
995&tanh
8c03c583
JH
996(-2.0,0):( -0.96402758007582, 0 )
997(-1.0,0):( -0.76159415595576, 0 )
998(-0.5,0):( -0.46211715726001, 0 )
999( 0.0,0):( 0 , 0 )
1000( 0.5,0):( 0.46211715726001, 0 )
1001( 1.0,0):( 0.76159415595576, 0 )
1002( 2.0,0):( 0.96402758007582, 0 )
1003
1004&tanh
0c721ce2
JH
1005( 2, 3):( 0.96538587902213, -0.00988437503832)
1006(-2, 3):( -0.96538587902213, -0.00988437503832)
1007(-2,-3):( -0.96538587902213, 0.00988437503832)
1008( 2,-3):( 0.96538587902213, 0.00988437503832)
1009
1010&sech
8c03c583
JH
1011(-2.0,0):( 0.26580222883408, 0 )
1012(-1.0,0):( 0.64805427366389, 0 )
1013(-0.5,0):( 0.88681888397007, 0 )
1014( 0.0,0):( 1 , 0 )
1015( 0.5,0):( 0.88681888397007, 0 )
1016( 1.0,0):( 0.64805427366389, 0 )
1017( 2.0,0):( 0.26580222883408, 0 )
1018
1019&sech
0c721ce2
JH
1020( 2, 3):( -0.26351297515839, -0.03621163655877)
1021(-2, 3):( -0.26351297515839, 0.03621163655877)
1022(-2,-3):( -0.26351297515839, -0.03621163655877)
1023( 2,-3):( -0.26351297515839, 0.03621163655877)
1024
1025&csch
8c03c583
JH
1026(-2.0,0):( -0.27572056477178, 0 )
1027(-1.0,0):( -0.85091812823932, 0 )
1028(-0.5,0):( -1.91903475133494, 0 )
1029( 0.5,0):( 1.91903475133494, 0 )
1030( 1.0,0):( 0.85091812823932, 0 )
1031( 2.0,0):( 0.27572056477178, 0 )
1032
1033&csch
0c721ce2
JH
1034( 2, 3):( -0.27254866146294, -0.04030057885689)
1035(-2, 3):( 0.27254866146294, -0.04030057885689)
1036(-2,-3):( 0.27254866146294, 0.04030057885689)
1037( 2,-3):( -0.27254866146294, 0.04030057885689)
1038
1039&coth
8c03c583
JH
1040(-2.0,0):( -1.03731472072755, 0 )
1041(-1.0,0):( -1.31303528549933, 0 )
1042(-0.5,0):( -2.16395341373865, 0 )
1043( 0.5,0):( 2.16395341373865, 0 )
1044( 1.0,0):( 1.31303528549933, 0 )
1045( 2.0,0):( 1.03731472072755, 0 )
1046
1047&coth
0c721ce2
JH
1048( 2, 3):( 1.03574663776500, 0.01060478347034)
1049(-2, 3):( -1.03574663776500, 0.01060478347034)
1050(-2,-3):( -1.03574663776500, -0.01060478347034)
1051( 2,-3):( 1.03574663776500, -0.01060478347034)
1052
1053&asinh
8c03c583
JH
1054(-2.0,0):( -1.44363547517881, 0 )
1055(-1.0,0):( -0.88137358701954, 0 )
1056(-0.5,0):( -0.48121182505960, 0 )
1057( 0.0,0):( 0 , 0 )
1058( 0.5,0):( 0.48121182505960, 0 )
1059( 1.0,0):( 0.88137358701954, 0 )
1060( 2.0,0):( 1.44363547517881, 0 )
1061
1062&asinh
0c721ce2
JH
1063( 2, 3):( 1.96863792579310, 0.96465850440760)
1064(-2, 3):( -1.96863792579310, 0.96465850440761)
1065(-2,-3):( -1.96863792579310, -0.96465850440761)
1066( 2,-3):( 1.96863792579310, -0.96465850440760)
1067
1068&acosh
9bc5fa8d 1069(-2.0,0):( 1.31695789692482, 3.14159265358979)
8c03c583
JH
1070(-1.0,0):( 0, 3.14159265358979)
1071(-0.5,0):( 0, 2.09439510239320)
1072( 0.0,0):( 0, 1.57079632679490)
1073( 0.5,0):( 0, 1.04719755119660)
1074( 1.0,0):( 0 , 0 )
1075( 2.0,0):( 1.31695789692482, 0 )
1076
1077&acosh
0c721ce2 1078( 2, 3):( 1.98338702991654, 1.00014354247380)
9bc5fa8d
JH
1079(-2, 3):( 1.98338702991653, 2.14144911111600)
1080(-2,-3):( 1.98338702991653, -2.14144911111600)
0c721ce2
JH
1081( 2,-3):( 1.98338702991654, -1.00014354247380)
1082
1083&atanh
8c03c583
JH
1084(-2.0,0):( -0.54930614433405, 1.57079632679490)
1085(-0.5,0):( -0.54930614433405, 0 )
1086( 0.0,0):( 0 , 0 )
1087( 0.5,0):( 0.54930614433405, 0 )
1088( 2.0,0):( 0.54930614433405, 1.57079632679490)
1089
1090&atanh
0c721ce2
JH
1091( 2, 3):( 0.14694666622553, 1.33897252229449)
1092(-2, 3):( -0.14694666622553, 1.33897252229449)
1093(-2,-3):( -0.14694666622553, -1.33897252229449)
1094( 2,-3):( 0.14694666622553, -1.33897252229449)
1095
1096&asech
8c03c583
JH
1097(-2.0,0):( 0 , 2.09439510239320)
1098(-1.0,0):( 0 , 3.14159265358979)
9bc5fa8d 1099(-0.5,0):( 1.31695789692482, 3.14159265358979)
8c03c583
JH
1100( 0.5,0):( 1.31695789692482, 0 )
1101( 1.0,0):( 0 , 0 )
1102( 2.0,0):( 0 , 1.04719755119660)
1103
1104&asech
0c721ce2 1105( 2, 3):( 0.23133469857397, -1.42041072246703)
9bc5fa8d
JH
1106(-2, 3):( 0.23133469857397, -1.72118193112276)
1107(-2,-3):( 0.23133469857397, 1.72118193112276)
0c721ce2
JH
1108( 2,-3):( 0.23133469857397, 1.42041072246703)
1109
1110&acsch
8c03c583
JH
1111(-2.0,0):( -0.48121182505960, 0 )
1112(-1.0,0):( -0.88137358701954, 0 )
1113(-0.5,0):( -1.44363547517881, 0 )
1114( 0.5,0):( 1.44363547517881, 0 )
1115( 1.0,0):( 0.88137358701954, 0 )
1116( 2.0,0):( 0.48121182505960, 0 )
1117
1118&acsch
0c721ce2
JH
1119( 2, 3):( 0.15735549884499, -0.22996290237721)
1120(-2, 3):( -0.15735549884499, -0.22996290237721)
1121(-2,-3):( -0.15735549884499, 0.22996290237721)
1122( 2,-3):( 0.15735549884499, 0.22996290237721)
1123
1124&acoth
8c03c583
JH
1125(-2.0,0):( -0.54930614433405, 0 )
1126(-0.5,0):( -0.54930614433405, 1.57079632679490)
1127( 0.5,0):( 0.54930614433405, 1.57079632679490)
1128( 2.0,0):( 0.54930614433405, 0 )
1129
1130&acoth
0c721ce2
JH
1131( 2, 3):( 0.14694666622553, -0.23182380450040)
1132(-2, 3):( -0.14694666622553, -0.23182380450040)
1133(-2,-3):( -0.14694666622553, 0.23182380450040)
1134( 2,-3):( 0.14694666622553, 0.23182380450040)
1135
1136# eof