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