-
Notifications
You must be signed in to change notification settings - Fork 0
/
Q-ComplexNumber.html
1117 lines (1072 loc) · 45.6 KB
/
Q-ComplexNumber.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!DOCTYPE html>
<html>
<head>
<title>Q ⟩ ComplexNumber</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width,initial-scale=1.0">
<meta name="description" content="Quantum computing in your browser.">
<meta name="copyright" content="Stewart Smith 2019–2020">
<meta name="keywords" content="
Q, Q.js, Q-js, Qjs, quantum JavaScript,
quantum, quantum physics, quantum mechanics, superposition,
quantum computer, quantum computer programming, quantum computing, QC,
quantum simulator, quantum computer simulator,
qubit, qbit, gate, Hadamard, Bloch, Bloch Sphere,
Web, Web site, website, Web browser, browser, HTML, HTML5, JavaScript, ES6, CSS,
Chrome, Firefox, Safari, Opera, Brave, Edge, WebKit, Blink, Gecko, Mozilla,
Stewart Smith, Stewart, Stew, Stuart, Steven, Steve, Stewdio, stewartsmith, stew_rtsmith, @stew_rtsmith,
Moar, Moar Technologies Corp, MTC,
Google, IBM, Microsoft, Amazon, NASA, DWave, D-Wave,
Quil, OpenQASM,
ProjectQ, Qiskit,
Quantum Development Kit, Cirq, Strawberry Fields, t|ket>,
QCL, Quantum pseudocode, Q#, Q|SI>, Q language, qGCL, QFC, QML, LIQUi|>, Quipper,
Stanford CS 269 Q: Quantum Computer Programming">
<meta name="twitter:card" content="summary_large_image">
<meta name="twitter:site" content="@stew_rtsmith">
<meta name="twitter:creator" content="@stew_rtsmith">
<meta name="twitter:title" content="Q ⟩ ComplexNumber">
<meta name="twitter:description" content="Quantum computing in your browser.">
<meta name="twitter:image" content="https://quantumjavascript.app/assets/Q-website-preview.jpg">
<meta property="og:type" content="website">
<meta property="og:title" content="Q ⟩ ComplexNumber">
<meta property="og:description" content="Quantum computing in your browser.">
<meta property="og:image" content="https://quantumjavascript.app/assets/Q-website-preview.jpg">
<meta property="og:url" content="https://quantumjavascript.app/ComplexNumber.html">
<link rel="canonical" href="https://quantumjavascript.app/ComplexNumber.html">
<link href="assets/Q-favicon-064.png" rel="icon" type="image/png">
<link href="assets/Q-favicon-144.png" rel="apple-touch-icon">
<link rel="stylesheet" href="Q/Q.css">
<link rel="stylesheet" href="Q/Q-Circuit-Editor.css">
<link rel="stylesheet" href="assets/documentation.css">
<script src="https://www.googletagmanager.com/gtag/js" async></script>
<script src="assets/ga.js"></script>
<script src="Q/Q.js"></script>
<script src="Q/Q-ComplexNumber.js"></script>
<script src="Q/Q-Matrix.js"></script>
<script src="Q/Q-Qubit.js"></script>
<script src="Q/Q-Gate.js"></script>
<script src="Q/Q-History.js"></script>
<script src="Q/Q-Circuit.js"></script>
<script src="Q/Q-Circuit-Editor.js"></script>
<script src="assets/navigation.js"></script>
</head>
<body>
<main class="api">
<p>
Source code:
<a href="https://github.com/stewdio/q.js/blob/master/source/Q-ComplexNumber.js?ts=4" target="_blank">
<code>Q-ComplexNumber.js</code>
</a>
</p>
<hr>
<h3 id="Real_numbers">Real numbers ℝ</h3>
<p>
Our regular, ordinary, everyday numbers are called
<a href="https://en.wikipedia.org/wiki/Real_number" target="_blank">real numbers</a>.
These include integers and decimals.
You can visualize real numbers as existing along an infinite number line—with zero in the middle, positive numbers counting up forever to infinity on the right, and negative numbers doing the exact opposite on the left.
</p>
<svg class="complex-plane" viewBox="0 0 600 600">
<use xlink:href="#complex-plane-real">
</svg>
<p>
When a real number is multiplied by itself the product is always positive.
For example, if we choose the number 2 we see that 2 × 2 = 4.
Similarly, had we chosen the negative number -2, the product would still be positive
because two negative numbers multiplied together also produce a positive result;
-2 × -2 = 4.
For brevity we could rewrite these equations as 2<sup>2</sup> = 4 and (-2)<sup>2</sup> = 4, respectively.
</p>
<p>
The <a href="https://en.wikipedia.org/wiki/Square_root" target="_blank">square root</a>
of a real number has two possible answers.
The square root of 4, for example, is both 2 <em>and</em> -2
because both are solutions for <span class="symbol">x</span>
in the equation <span class="symbol">x</span> = √4.
</p>
<h3 id="Imaginary_numbers">Imaginary numbers 𝕀</h3>
<p>
But suppose we wanted to find the square root of a <em>negative</em> number.
Is there any number that could solve for <span class="symbol">x</span>
in the equation <span class="symbol">x</span> = √(-4)?
Sadly, there is not. Or more precisely: there is not any <em>real</em> solution for the square root of a negative number.
</p>
<p>
In his 1991 address on “Creativity in Management”, Monty Python’s John Cleese
articulates Edward de Bono’s concept of the
<a href="https://youtu.be/Pb5oIIPO62g?t=1926" target="_blank">intermediate impossible (32:06)</a>
as a useful stepping stone towards a novel and useful solution.
<a href="https://en.wikipedia.org/wiki/Imaginary_number" target="_blank">Imaginary numbers</a>
might be considered an intermediate impossible.
The symbol <span class="symbol">i</span> is defined as the imaginary solution to the equation
<span class="symbol">x</span> = √(-1),
therefore <span class="symbol">i</span><sup>2</sup> = -1.
With this imaginary device we now have a solution to the above equation
<span class="symbol">x</span> = √(-4)
and that solution is 2<span class="symbol">i</span>.
(And also -2<span class="symbol">i</span>, of course!
We can indicate this “plus or minus” possibility as ±2<span class="symbol">i</span>.)
Let’s inspect this more closely.
</p>
<pre><code>
𝒙 = √(-4)
𝒙 = √( 4 × -1)
𝒙 = √4 × √(-1)
𝒙 = ±2 × √(-1)
𝒙 = ±2 × <span class="symbol">i</span>
𝒙 = ±2<span class="symbol">i</span>
</code></pre>
<p>
2<span class="symbol">i</span> is an
<a href="https://en.wikipedia.org/wiki/Imaginary_number" target="_blank">imaginary number</a>
that consists of a real number multiplier, 2, and
our imaginary solution to √(-1), called <span class="symbol">i</span>.
Like real numbers, imaginary numbers also exist along an infinite number line.
We plotted our real number line horizontally,
so let’s plot our imaginary number line vertically.
</p>
<svg class="complex-plane" viewBox="0 0 600 600">
<use xlink:href="#complex-plane-imaginary">
</svg>
<h3 id="Complex_numbers">Complex numbers ℂ</h3>
<p>
We just saw that multiplying a real number by <span class="symbol">i</span>
yields an imaginary number.
But what if you <em>add</em> a real number to an imaginary one?
Things get <em>complex</em>.
A <a href="https://en.wikipedia.org/wiki/Complex_number" target="_blank">complex number</a>
is a number that can be expressed in the form
<span class="symbol">a</span> + <span class="symbol">bi</span>,
where <span class="symbol">a</span> is the real component and
<span class="symbol">bi</span> is the imaginary component.
Some examples might be 1 + 2<span class="symbol">i</span> or 3 - 4<span class="symbol">i</span>.
</p>
<svg class="complex-plane" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
viewBox="0 0 600 600" style="enable-background:new 0 0 600 600;" xml:space="preserve">
<style type="text/css">
svg #complex-plane {
/*font-family: 'Roboto';*/
/*mix-blend-mode: difference;*/
/*mix-blend-mode: multiply;*/
/*background-blend-mode: screen;*/
stroke-width: 0.5;
stroke-miterlimit: 10;
}
.light {
opacity: 0.5;
}
.lighter {
opacity: 0.15;
}
.lightest {
opacity: 0.05;
}
line.dashed {
stroke-dasharray: 1, 3;
}
line.strong {
stroke-width: 1;
}
.negative-numbers {
opacity: 0.25;
}
#complex-plane-real text,
#complex-plane-real rect,
#complex-plane-real polygon {
fill: var( --Q-color-red );
stroke: none;
}
#complex-plane-real line {
fill: none;
stroke: var( --Q-color-red );
}
#complex-plane-imaginary text,
#complex-plane-imaginary rect,
#complex-plane-imaginary polygon {
fill: var( --Q-color-blue );
stroke: none;
}
#complex-plane-imaginary line {
fill: none;
stroke: var( --Q-color-blue );
}
#examples line {
fill: none;
stroke: var( --Q-color-charcoal );
}
</style>
<g id="complex-plane-real">
<g id="real-overlays">
<rect class="lightest" x="300" width="300" height="600"/>
<rect class="lighter" y="0" width="300" height="600"/>
</g>
<g id="real-ticks">
<g class="lighter">
<line x1="50" y1="290" x2="50" y2="300"/>
<line x1="100" y1="290" x2="100" y2="300"/>
<line x1="150" y1="290" x2="150" y2="300"/>
<line x1="200" y1="290" x2="200" y2="300"/>
<line x1="250" y1="290" x2="250" y2="300"/>
</g>
<line x1="300" y1="290" x2="300" y2="300"/>
<line x1="350" y1="290" x2="350" y2="300"/>
<line x1="373" y1="300" x2="373" y2="310"/>
<line x1="400" y1="290" x2="400" y2="300"/>
<line x1="438" y1="300" x2="438" y2="310"/>
<line x1="450" y1="290" x2="450" y2="300"/>
<line x1="458" y1="300" x2="458" y2="310"/>
<line x1="500" y1="290" x2="500" y2="300"/>
<line x1="550" y1="290" x2="550" y2="300"/>
<g>
<line class="strong" x1="32.2" y1="300" x2="567.8" y2="300"/>
<polygon points="33.6,305 25,300 33.6,295"/>
<polygon points="566.4,305 575,300 566.4,295"/>
</g>
<line class="dashed" x1="300" y1="0" x2="300" y2="260"/>
<line class="dashed" x1="300" y1="300" x2="300" y2="600"/>
</g>
<g id="real-numbers">
<text transform="matrix(1 0 0 1 496 282)">4</text>
<text transform="matrix(1 0 0 1 546 282)">5</text>
<text transform="matrix(1 0 0 1 453 325)" class="symbol">π</text>
<text transform="matrix(1 0 0 1 446 282)">3</text>
<text transform="matrix(1 0 0 1 433 325)" class="symbol">e</text>
<text transform="matrix(1 0 0 1 396 282)">2</text>
<text transform="matrix(1 0 0 1 363 328)">√2</text>
<text transform="matrix(1 0 0 1 347 282)">1</text>
<text transform="matrix(1 0 0 1 296 282)">0</text>
<g class="negative-numbers">
<text transform="matrix(1 0 0 1 240 282)">-1</text>
<text transform="matrix(1 0 0 1 190 282)">-2</text>
<text transform="matrix(1 0 0 1 140 282)">-3</text>
<text transform="matrix(1 0 0 1 90 282)">-4</text>
<text transform="matrix(1 0 0 1 40 282)">-5</text>
</g>
</g>
</g>
<g id="complex-plane-imaginary">
<g id="imaginary-overlays">
<rect class="lightest" width="600" height="300"/>
<rect class="lighter" y="300" width="600" height="300"/>
</g>
<g id="imaginary-ticks">
<line x1="290" y1="50" x2="300" y2="50" />
<line x1="290" y1="100" x2="300" y2="100"/>
<line x1="290" y1="150" x2="300" y2="150"/>
<line x1="290" y1="200" x2="300" y2="200"/>
<line x1="290" y1="250" x2="300" y2="250"/>
<line x1="290" y1="300" x2="300" y2="300"/>
<g class="lighter">
<line x1="290" y1="350" x2="300" y2="350"/>
<line x1="290" y1="400" x2="300" y2="400"/>
<line x1="290" y1="450" x2="300" y2="450"/>
<line x1="290" y1="500" x2="300" y2="500"/>
<line x1="290" y1="550" x2="300" y2="550"/>
</g>
<g>
<line class="strong" x1="300" y1="32.2" x2="300" y2="567.8"/>
<polygon points="295,33.6 300,25 305,33.6"/>
<polygon points="295,566.4 300,575 305,566.4"/>
</g>
<line class="dashed" x1="0" y1="300" x2="260" y2="300"/>
<line class="dashed" x1="300" y1="300" x2="600" y2="300"/>
</g>
<g id="imaginary-numbers">
<text transform="matrix(1 0 0 1 270 55)">5<tspan class="symbol">i</tspan></text>
<text transform="matrix(1 0 0 1 270 105)">4<tspan class="symbol">i</tspan></text>
<text transform="matrix(1 0 0 1 270 205)">2<tspan class="symbol">i</tspan></text>
<text transform="matrix(1 0 0 1 270 155)">3<tspan class="symbol">i</tspan></text>
<text transform="matrix(1 0 0 1 270 255)">1<tspan class="symbol">i</tspan></text>
<text transform="matrix(1 0 0 1 270 305)">0<tspan class="symbol">i</tspan></text>
<g class="negative-numbers">
<text transform="matrix(1 0 0 1 263.5 355)">-1<tspan class="symbol">i</tspan></text>
<text transform="matrix(1 0 0 1 263.5 405)">-2<tspan class="symbol">i</tspan></text>
<text transform="matrix(1 0 0 1 263.5 455)">-3<tspan class="symbol">i</tspan></text>
<text transform="matrix(1 0 0 1 263.5 505)">-4<tspan class="symbol">i</tspan></text>
<text transform="matrix(1 0 0 1 263.5 555)">-5<tspan class="symbol">i</tspan></text>
</g>
</g>
</g>
<g id="examples">
<line class="dashed strong" x1="300" y1="200" x2="350" y2="200"/>
<line class="dashed strong" x1="350" y1="265" x2="350" y2="200"/>
<circle cx="350" cy="200" r="4"/>
<text transform="matrix(1 0 0 1 360 205)">1+2<tspan class="symbol">i</tspan></text>
<line class="dashed strong" x1="300" y1="500" x2="450" y2="500"/>
<line class="dashed strong" x1="450" y1="300" x2="450" y2="500"/>
<circle cx="450" cy="500" r="4"/>
<text transform="matrix(1 0 0 1 460 505)">3-4<tspan class="symbol">i</tspan></text>
</g>
<!-- <use xlink:href="#imaginary-numbers" /> -->
<!-- <use xlink:href="#real-numbers" /> -->
</svg>
<!--
“Quantum Mechanics Concepts: 1 Dirac Notation and Photon Polarisation”
https://youtu.be/pBh7Xqbh5JQ?t=352
Maybe someday add the above video’s bits about a^2 + b^2 = c^2 ?
-->
<p>
This is what the <code>ComplexNumber</code> class was created to handle.
Open up your JavaScript console and paste in the following:
</p>
<pre><code>
var
cat = new <a href="Q.html">Q</a>.ComplexNumber( 1, 2 ),
dog = new <a href="Q.html">Q</a>.ComplexNumber( 3, -4 )
cat.<a href="#.prototype.toText">toText</a>()<span class="comment">// Returns '1 + 2i'</span>
dog.<a href="#.prototype.toText">toText</a>()<span class="comment">// Returns '3 - 4i'</span>
</pre></code>
<p>
Now we have two variables, <code>cat</code> and <code>dog</code>, that we can operate with.
As you might guess, <code>ComplexNumber</code>
includes instance methods for common operations like
addition, subtraction, multiplication, and division.
Try the following lines individually in your JavaScript console:
</p>
<pre><code>
cat.<a href="#.prototype.add">add</a>( dog ).<a href="#.prototype.toText">toText</a>() <span class="comment">// Returns '4 - 2i'</span>
cat.<a href="#.prototype.subtract">subtract</a>( dog ).<a href="#.prototype.toText">toText</a>()<span class="comment">// Returns '-2 + 6i'</span>
cat.<a href="#.prototype.multiply">multiply</a>( dog ).<a href="#.prototype.toText">toText</a>()<span class="comment">// Returns '11 + 2i'</span>
cat.<a href="#.prototype.divide">divide</a>( dog ).<a href="#.prototype.toText">toText</a>() <span class="comment">// Returns '-0.2 + 0.4i'</span>
</pre></code>
<p>
We can now verify that <span class="symbol">i</span><sup>2</sup> = -1.
</p>
<pre><code>
var i = new <a href="Q.html">Q</a>.ComplexNumber( 0, 1 )
i.<a href="#.prototype.toText">toText</a>()<span class="comment">// Returns 'i'</span>
i.<a href="#.prototype.power">power</a>( 2 ).<a href="#.prototype.toText">toText</a>()<span class="comment">// Returns '-1'</span>
</pre></code>
<p>
Operation functions on <code>Q.ComplexNumber</code> instances generally accept as
arguments both sibling instances and pure <code>Number</code> instances, though the
value returned is always an instance of <code>Q.ComplexNumber</code>.
</p>
<hr>
<h3 id="Constructor">Constructor</h3>
<p>
<span class="constructor">ComplexNumber</span>
<code class="value-type">Function([ real: Number or <a href="Q.html">Q</a>.ComplexNumber ][, imaginary: Number ]]) => <a href="Q.html">Q</a>.ComplexNumber</code>
<br>
Expects zero to two arguments.
If the first argument is a <code>ComplexNumber</code>
then that value is cloned and any remaining arguments are ignored.
If either of the arguments are <code>undefined</code> they are assumed to be zero.
If the first argument is not a <code>ComplexNumber</code>
and either of the arguments are not <a href="Q-ComplexNumber.html#.isNumberLike">number-like</a>
then an error is thrown.
</p>
<pre><code>
var
ape = new <a href="Q.html">Q</a>.ComplexNumber(),
bee = new <a href="Q.html">Q</a>.ComplexNumber( 1 ),
elk = new <a href="Q.html">Q</a>.ComplexNumber( 1, 2 ),
fox = new <a href="Q.html">Q</a>.ComplexNumber( elk )
ape.<a href="#.prototype.toText">toText</a>()<span class="comment">// Returns '0'</span>
bee.<a href="#.prototype.toText">toText</a>()<span class="comment">// Returns '1'</span>
elk.<a href="#.prototype.toText">toText</a>()<span class="comment">// Returns '1 + 2i'</span>
fox.<a href="#.prototype.toText">toText</a>()<span class="comment">// Returns '1 + 2i'</span>
elk.<a href="#.prototype.isEqualTo">isEqualTo</a>( fox ) <span class="comment">// Returns true</span>
elk.<a href="#this.index">index</a> === fox.<a href="#.prototype.index">index</a><span class="comment">// Returns false</span>
</pre></code>
<ul class="properties">
<li>
<dt id="this.real">real</dt>
<dd>
<code class="value-type">Number</code>
Traditionally the first argument,
a <a href="Q-ComplexNumber.html#.isNumberLike">number-like</a> value
representing the <em>real</em> component of the
<a href="Q-ComplexNumber.html#Complex_numbers">complex number</a>.
</dd>
</li>
<li>
<dt id="this.imaginary">imaginary</dt>
<dd>
<code class="value-type">Number</code>
Traditionally the second argument,
a <a href="Q-ComplexNumber.html#.isNumberLike">number-like</a> value
representing the <em>imaginary</em> component of the
<a href="Q-ComplexNumber.html#Complex_numbers">complex number</a>.
</dd>
</li>
<li>
<dt id="this.index">index</dt>
<dd>
<code class="value-type">Number</code>
An identification number assigned to the instance,
used for minding the total number of instances created.
</dd>
</li>
</ul>
<hr>
<h3>Static properties</h3>
<ul class="properties">
<li>
<dt id=".help">help</dt>
<dd>
<code class="value-type">Function ⇒ String</code>
Calls and returns the value of
<code><a href="Q.html">Q</a>.<a href="Q.html#help">help</a></code>,
passing <code><a href="Q.html">Q</a>.ComplexNumber</code> as the argument.
</dd>
</li>
<li>
<dt id=".index">index</dt>
<dd>
<code class="value-type">Number</code>
The number of instances created so far.
</dd>
</li>
</ul>
<h4>Constants and constant creation</h4>
<ul class="properties">
<li>
<dt id=".constants">constants</dt>
<dd>
<code class="value-type">Object</code>
Constants are appended <em>directly</em> to the
<code><a href="Q.html">Q</a>.ComplexNumber</code> object.
For convenience they are also appended to this
<code><a href="Q.html">Q</a>.ComplexNumber</code>.constants</code> object
to make looking up constants in the JavaScript console trivial,
and to make iterating across all constants convenient via functions like
<code><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/entries" target="_blank">Object.entries</a></code>,
<code><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/keys" target="_blank">Object.keys</a></code>,
<code><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/values" target="_blank">Object.values</a></code>,
and so on.
<!-- Configured to be unwritable once appended via
<code><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/defineProperty" target="_blank">Object.defineProperty</a></code>
and they are labeled in uppercase to signal to us that this is so. -->
The intention that a property act as a constant is signaled
by its labelling in all-uppercase.
</dd>
</li>
<li>
<dt id=".createConstant">createConstant</dt>
<dd>
<code class="value-type">Function( key: String, value: * )<!-- → undefined --></code>
Appends a property named by <code>key</code>
with a value of <code>value</code>
to both the
<code>Q</code> object
and its <code><a href="#.constants">constants</a></code> property.
</dd>
</li>
<li>
<dt id=".createConstants">createConstants</dt>
<dd>
<code class="value-type">Function( … )</code>
Expects an even number of arguments.
Will use each pair in the sequence of arguments to call
<code><a href="#.createConstant">createConstant</a></code>.
</dd>
</li>
<li>
<dt id=".ZERO">ZERO</dt>
<dd>
<code class="value-type"><a href="Q.html">Q</a>.ComplexNumber</code>
Initialized as
<code>new <a href="Q.html">Q</a>.ComplexNumber( 0, 0 )</code>.
Described as 0.
</dd>
</li>
<li>
<dt id=".ONE">ONE</dt>
<dd>
<code class="value-type"><a href="Q.html">Q</a>.ComplexNumber</code>
Initialized as
<code>new <a href="Q.html">Q</a>.ComplexNumber( 1, 0 )</code>.
Described as 1.
</dd>
</li>
<li>
<dt id=".E">E</dt>
<dd>
<code class="value-type"><a href="Q.html">Q</a>.ComplexNumber</code>
Initialized as
<code>new <a href="Q.html">Q</a>.ComplexNumber( Math.E, 0 )</code>.
Described as <span class="symbol">e</span> ≈ 2.7183.
</dd>
</li>
<li>
<dt id=".PI">PI</dt>
<dd>
<code class="value-type"><a href="Q.html">Q</a>.ComplexNumber</code>
Initialized as
<code>new <a href="Q.html">Q</a>.ComplexNumber( Math.PI, 0 )</code>.
Described as <a href="https://youtu.be/L1eegVTwDS0" target="_blank"><strong>exactly</strong> equal to 3</a>.
</dd>
</li>
<li>
<dt id=".I">I</dt>
<dd>
<code class="value-type"><a href="Q.html">Q</a>.ComplexNumber</code>
Initialized as
<code>new <a href="Q.html">Q</a>.ComplexNumber( 0, 1 )</code>.
Described as <span class="symbol">i</span>.
</dd>
</li>
<li>
<dt id=".EPSILON">EPSILON</dt>
<dd>
<code class="value-type"><a href="Q.html">Q</a>.ComplexNumber</code>
Initialized as
<code>new <a href="Q.html">Q</a>.ComplexNumber( <a href="Q.html">Q</a>.<a href="Q.html#.EPSILON">EPSILON</a>, <a href="Q.html">Q</a>.<a href="Q.html#.EPSILON">EPSILON</a> )</code>.
Described as ≈ 1.3323 × 10<sup>-15</sup> + 1.3323 × 10<sup>-15</sup><span class="symbol">i</span>.
</dd>
</li>
<li>
<dt id=".INFINITY">INFINITY</dt>
<dd>
<code class="value-type"><a href="Q.html">Q</a>.ComplexNumber</code>
Initialized as
<code>new <a href="Q.html">Q</a>.ComplexNumber( Infinity, Infinity )</code>.
Described as <span class="symbol">∞</span> + <span class="symbol">∞i</span>.
</dd>
</li>
<li>
<dt id=".NAN">NAN</dt>
<dd>
<code class="value-type"><a href="Q.html">Q</a>.ComplexNumber</code>
Initialized as
<code>new <a href="Q.html">Q</a>.ComplexNumber( NaN, NaN )</code>.
<code>Array( 16 ).join( NaN ) +' BATMAN!'</code>
</dd>
</li>
</ul>
<h4>Inspection</h4>
<ul class="properties">
<li>
<dt id=".isNumberLike">isNumberLike</dt>
<dd>
<code class="value-type">Function( n: * ) ⇒ Boolean</code>
Returns true if
<code>n</code>’s <code><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/typeof" target="_blank">typeof</a></code> is equal to the <code>String</code> <code>'number'</code>
or if <code>n <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/instanceof" target="_blank">instanceof</a> Number</code> is <code>true</code>,
otherwise returns <code>false</code>.
</dd>
</li>
<li>
<dt id=".isNaN">isNaN</dt>
<dd>
<code class="value-type">Function( c: <a href="Q.html">Q</a>.ComplexNumber ) ⇒ Boolean</code>
Returns <code>true</code> if either of this instance’s
<code><a href="#this.real">real</a></code>
or
<code><a href="#this.real">imaginary</a></code>
components are <code><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/NaN" target="_blank">NaN</a></code>,
otherwise returns <code>false</code>.
</dd>
</li>
<li>
<dt id=".isZero">isZero</dt>
<dd>
<code class="value-type">Function( c: <a href="Q.html">Q</a>.ComplexNumber ) ⇒ Boolean</code>
Returns <code>true</code> if both of this instance’s
<code><a href="#this.real">real</a></code>
and
<code><a href="#this.real">imaginary</a></code>
absolute values are equal to zero,
otherwise returns <code>false</code>.
See <a href="https://en.wikipedia.org/wiki/Signed_zero" target="_blank">“Signed zero”</a> for an explanation of why the <em>absolute</em> value of zero must be taken.
</dd>
</li>
<li>
<dt id=".isFinite">isFinite</dt>
<dd>
<code class="value-type">Function( c: <a href="Q.html">Q</a>.ComplexNumber ) ⇒ Boolean</code>
Returns <code>true</code> if both of this instance’s
<code><a href="#this.real">real</a></code>
and
<code><a href="#this.real">imaginary</a></code>
values are <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/isFinite" target="_blank">finite</a>,
otherwise returns <code>false</code>.
</dd>
</li>
<li>
<dt id=".isInfinite">isInfinite</dt>
<dd>
<code class="value-type">Function( c: <a href="Q.html">Q</a>.ComplexNumber ) ⇒ Boolean</code>
Returns <code>true</code> if both of this instance’s
<code><a href="#this.real">real</a></code>
and
<code><a href="#this.real">imaginary</a></code>
values are not <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/isFinite" target="_blank">finite</a>
and are also not <code><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/isNaN" target="_blank">NaN</a></code>,
otherwise returns <code>false</code>.
</dd>
</li>
<li>
<dt id=".areEqual">areEqual</dt>
<dd>
<code class="value-type">Function( a: Number or <a href="Q.html">Q</a>.ComplexNumber, b: Number or <a href="Q.html">Q</a>.ComplexNumber ) ⇒ Boolean</code>
Returns <code>true</code> if the arguments
<code>a</code> and <code>b</code>
are within
<code><a href="Q.html">Q</a>.<a href="Q.html#.EPSILON">EPSILON</a></code> of each other,
otherwise returns <code>false</code>.
</dd>
</li>
</ul>
<h4>Maths</h4>
<ul class="properties">
<li>
<dt id=".absolute">absolute</dt>
<dd>
<code class="value-type">Function( c: <a href="Q.html">Q</a>.ComplexNumber ) ⇒ Number</code>
Calls and returns the value of <code><a href="Q.html">Q</a>.<a href="Q.html#.hypotenuse">hypotenuse</a></code>
using <code>c</code>’s
<code><a href="#this.real">real</a></code>
and
<code><a href="#this.real">imaginary</a></code>
properties as arguments.
</dd>
</li>
<li>
<dt id=".conjugate">conjugate</dt>
<dd>
<code class="value-type">Function( c: <a href="Q.html">Q</a>.ComplexNumber ) ⇒ <a href="Q.html">Q</a>.ComplexNumber</code>
Returns a new complex number with the values
<code>c.<a href="#this.real">real</a></code>
and
<code>c.<a href="#this.real">imaginary</a> * -1</code>.
</dd>
</li>
<li>
<dt id=".sine">sine</dt>
<dd>
<code class="value-type">Function( c: <a href="Q.html">Q</a>.ComplexNumber ) ⇒ <a href="Q.html">Q</a>.ComplexNumber</code>
Returns the
<a href="https://en.wikipedia.org/wiki/Sine#Sine_with_a_complex_argument" target="_blank">sine</a>
of <code>c</code>.
</dd>
</li>
<li>
<dt id=".cosine">cosine</dt>
<dd>
<code class="value-type">Function( c: <a href="Q.html">Q</a>.ComplexNumber ) ⇒ <a href="Q.html">Q</a>.ComplexNumber</code>
Returns the
<a href="https://en.wikipedia.org/wiki/Trigonometric_functions#In_the_complex_plane" target="_blank">cosine</a>
of <code>c</code>.
</dd>
</li>
<li>
<dt id=".arcCosine">arcCosine</dt>
<dd>
<code class="value-type">Function( c: <a href="Q.html">Q</a>.ComplexNumber ) ⇒ <a href="Q.html">Q</a>.ComplexNumber</code>
Returns the
<a href="https://en.wikipedia.org/wiki/Inverse_trigonometric_functions#Extension_to_complex_plane" target="_blank">arccosine</a>
of <code>c</code>.
</dd>
</li>
<li>
<dt id=".arcTangent">arcTangent</dt>
<dd>
<code class="value-type">Function( c: <a href="Q.html">Q</a>.ComplexNumber ) ⇒ <a href="Q.html">Q</a>.ComplexNumber</code>
Returns the
<a href="https://en.wikipedia.org/wiki/Inverse_trigonometric_functions#Extension_to_complex_plane" target="_blank">arctangent</a>
of <code>c</code>.
</dd>
</li>
<li>
<dt id=".power">power</dt>
<dd>
<code class="value-type">Function( a: Number or <a href="Q.html">Q</a>.ComplexNumber, b: Number or <a href="Q.html">Q</a>.ComplexNumber ) ⇒ <a href="Q.html">Q</a>.ComplexNumber</code>
Returns <code>a</code> raised to the power of <code>b</code>.
</dd>
</li>
<li>
<dt id=".squareRoot">squareRoot</dt>
<dd>
<code class="value-type">Function( c: <a href="Q.html">Q</a>.ComplexNumber ) ⇒ <a href="Q.html">Q</a>.ComplexNumber</code>
Returns the square root of <code>c</code>.
</dd>
</li>
<li>
<dt id=".log">log</dt>
<dd>
<code class="value-type">Function( c: <a href="Q.html">Q</a>.ComplexNumber ) ⇒ <a href="Q.html">Q</a>.ComplexNumber</code>
Returns the log of <code>c</code>.
</dd>
</li>
<li>
<dt id=".operate">operate</dt>
<dd>
<code class="value-type">Function(
name: String,
a: Number or <a href="Q.html">Q</a>.ComplexNumber,
b: Number or <a href="Q.html">Q</a>.ComplexNumber,
numberAndNumber: Function,
numberAndComplex: Function,
complexAndNumber: Function,
complexAndComplex: Function ) ⇒ *</code>
Meta function for performing operations on two values
that may each be either numbers or complex numbers.
The <code>name</code> argument indicates the name of the
operation being performed and is used in error logging
should the operation fail.
The intent is to return a <code><a href="Q.html">Q</a>.ComplexNumber</code>, though this is up to the functions
passed in as it is their return values that are returned.
</dd>
</li>
<li>
<dt id=".multiply">multiply</dt>
<dd>
<code class="value-type">Function( a: Number or <a href="Q.html">Q</a>.ComplexNumber, b: Number or <a href="Q.html">Q</a>.ComplexNumber ) ⇒ <a href="Q.html">Q</a>.ComplexNumber</code>
Uses <code><a href="Q.html">Q</a>.ComplexNumber.<a href="#.operate">operate</a></code>
to return the result of multiplying
<code>a</code> and <code>b</code>.
</dd>
</li>
<li>
<dt id=".divide">divide</dt>
<dd>
<code class="value-type">Function( a: Number or <a href="Q.html">Q</a>.ComplexNumber, b: Number or <a href="Q.html">Q</a>.ComplexNumber ) ⇒ <a href="Q.html">Q</a>.ComplexNumber</code>
Uses <code><a href="Q.html">Q</a>.ComplexNumber.<a href="#.operate">operate</a></code>
to return the result of dividing
<code>a</code> by <code>b</code>.
</dd>
</li>
<li>
<dt id=".add">add</dt>
<dd>
<code class="value-type">Function( a: Number or <a href="Q.html">Q</a>.ComplexNumber, b: Number or <a href="Q.html">Q</a>.ComplexNumber ) ⇒ <a href="Q.html">Q</a>.ComplexNumber</code>
Uses <code><a href="Q.html">Q</a>.ComplexNumber.<a href="#.operate">operate</a></code>
to return the result of adding
<code>a</code> and <code>b</code>.
</dd>
</li>
<li>
<dt id=".subtract">subtract</dt>
<dd>
<code class="value-type">Function( a: Number or <a href="Q.html">Q</a>.ComplexNumber, b: Number or <a href="Q.html">Q</a>.ComplexNumber ) ⇒ <a href="Q.html">Q</a>.ComplexNumber</code>
Uses <code><a href="Q.html">Q</a>.ComplexNumber.<a href="#.operate">operate</a></code>
to return the result of subtracting
<code>b</code> from <code>a</code>.
</dd>
</li>
</ul>
<hr>
<h3 id="Prototype_properties">Prototype properties</h3>
<ul class="properties">
<li>
<dt id=".prototype.clone">clone</dt>
<dd>
<code class="value-type">Function ⇒ <a href="Q.html">Q</a>.ComplexNumber</code>
Returns a new instance with the values for
<code><a href="#this.real">real</a></code>
and
<code><a href="#this.imaginary">imaginary</a></code>
copied from this instance.
</dd>
</li>
<li>
<dt id=".prototype.copy$">copy$</dt>
<dd>
<code class="value-type">Function( c: <a href="Q.html">Q</a>.ComplexNumber ) ⇒ <a href="Q.html">Q</a>.ComplexNumber</code>
Copies the values for
<code><a href="#this.real">real</a></code>
and
<code><a href="#this.imaginary">imaginary</a></code>
from the supplied <code><a href="Q.html">Q</a>.ComplexNumber</code> argument.
</dd>
</li>
</ul>
<h4>Inspections (non-destructive)</h4>
<ul class="properties">
<li>
<dt id=".prototype.isNaN">isNaN</dt>
<dd>
<code class="value-type">Function ⇒ Boolean</code>
Calls and returns the result of the
<a href="#.isNaN"><code>isNaN</code> static method</a>,
passing the calling instance as the argument.
Will return a <code>Boolean</code> value,
thereby halting
<a href="https://en.wikipedia.org/wiki/Fluent_interface" target="_blank">“Fluent interface” method chaining</a>
for this instance.
</dd>
</li>
<li>
<dt id=".prototype.isZero">isZero</dt>
<dd>
<code class="value-type">Function ⇒ Boolean</code>
Calls and returns the result of the
<a href="#.isZero"><code>isZero</code> static method</a>,
passing the calling instance as the argument.
Will return a <code>Boolean</code> value,
thereby halting
<a href="https://en.wikipedia.org/wiki/Fluent_interface" target="_blank">“Fluent interface” method chaining</a>
for this instance.
</dd>
</li>
<li>
<dt id=".prototype.isFinite">isFinite</dt>
<dd>
<code class="value-type">Function ⇒ Boolean</code>
Calls and returns the result of the
<a href="#.isFinite"><code>isFinite</code> static method</a>,
passing the calling instance as the argument.
Will return a <code>Boolean</code> value,
thereby halting
<a href="https://en.wikipedia.org/wiki/Fluent_interface" target="_blank">“Fluent interface” method chaining</a>
for this instance.
</dd>
</li>
<li>
<dt id=".prototype.isInfinite">isInfinite</dt>
<dd>
<code class="value-type">Function ⇒ Boolean</code>
Calls and returns the result of the
<a href="#.isInfinite"><code>isInfinite</code> static method</a>,
passing the calling instance as the argument.
Will return a <code>Boolean</code> value,
thereby halting
<a href="https://en.wikipedia.org/wiki/Fluent_interface" target="_blank">“Fluent interface” method chaining</a>
for this instance.
</dd>
</li>
<li>
<dt id=".prototype.isEqualTo">isEqualTo</dt>
<dd>
<code class="value-type">Function( n: Number or <a href="Q.html">Q</a>.ComplexNumber ) ⇒ Boolean</code>
Calls and returns the result of the
<a href="#.areEqual"><code>areEqual</code> static method</a>,
passing the calling instance as the first argument
and <code>n</code> as the second argument.
Will return a <code>Boolean</code> value,
thereby halting
<a href="https://en.wikipedia.org/wiki/Fluent_interface" target="_blank">“Fluent interface” method chaining</a>
for this instance.
</dd>
</li>
<li>
<dt id=".prototype.reduce">reduce</dt>
<dd>
<code class="value-type">Function ⇒ <a href="Q.html">Q</a>.ComplexNumber or Number</code>
If no <code><a href="#this.imaginary">imaginary</a></code> component exists,
returns a <code>Number</code> representing the <code><a href="Q.html">Q</a>.ComplexNumber <a href="#this.real">real</a></code> component,
otherwise returns the instance itself.
May return a <code>Number</code> value,
thereby halting
<a href="https://en.wikipedia.org/wiki/Fluent_interface" target="_blank">“Fluent interface” method chaining</a>
for this instance.
</dd>
</li>
<li>
<dt id=".prototype.toText">toText</dt>
<dd>
<code class="value-type">Function([ roundToDecimal: Number ]) ⇒ String</code>
Returns the value of this instance expressed as text
in a form similar to
<span class="symbol">a</span>+<span class="symbol">bi</span>.
If <code>roundToDecimal</code> is supplied, will round both the
<code><a href="#this.real">real</a></code>
and
<code><a href="#this.imaginary">imaginary</a></code>
components
by passing themselves and <code>roundToDecimal</code>
to <code><a href="Q.html">Q</a>.<a href="Q.html#.round">round</a></code>
as arguments.
Will return a <code>String</code> value,
thereby halting
<a href="https://en.wikipedia.org/wiki/Fluent_interface" target="_blank">“Fluent interface” method chaining</a>
for this instance.
</dd>
</li>
</ul>
<h4>Maths (non-destructive)</h4>
<ul class="properties">
<li>
<dt id=".prototype.absolute">absolute</dt>
<dd>
<code class="value-type">Function ⇒ Number</code>
Passes this instance as an argument to the
<a href="#.absolute"><code>absolute</code>
static method</a> and returns the result.
Will return a <code>Number</code> value,
thereby halting
<a href="https://en.wikipedia.org/wiki/Fluent_interface" target="_blank">“Fluent interface” method chaining</a>
for this instance.
</dd>
</li>
<li>
<dt id=".prototype.conjugate">conjugate</dt>
<dd>
<code class="value-type">Function ⇒ <a href="Q.html">Q</a>.ComplexNumber</code>
Passes this instance as an argument to the
<a href="#.conjugate"><code>conjugate</code>
static method</a> and returns the result.
</dd>
</li>
<li>
<dt id=".prototype.power">power</dt>
<dd>
<code class="value-type">Function( n: Number or <a href="Q.html">Q</a>.ComplexNumber ) ⇒ <a href="Q.html">Q</a>.ComplexNumber</code>
Passes this instance as the first argument
and <code>n</code> as the second argument
to the
<a href="#.power"><code>power</code>
static method</a> and returns the result.
</dd>
</li>
<li>
<dt id=".prototype.squareRoot">squareRoot</dt>
<dd>
<code class="value-type">Function ⇒ <a href="Q.html">Q</a>.ComplexNumber</code>
Passes this instance as an argument to the
<a href="#.squareRoot"><code>squareRoot</code>
static method</a> and returns the result.
</dd>
</li>
<li>
<dt id=".prototype.log">log</dt>
<dd>
<code class="value-type">Function ⇒ <a href="Q.html">Q</a>.ComplexNumber</code>
Passes this instance as an argument to the
<a href="#.log"><code>log</code>
static method</a> and returns the result.
</dd>
</li>
<li>
<dt id=".prototype.multiply">multiply</dt>
<dd>
<code class="value-type">Function( n: Number or <a href="Q.html">Q</a>.ComplexNumber ) ⇒ <a href="Q.html">Q</a>.ComplexNumber</code>
Passes this instance as the first argument
and <code>n</code> as the second argument
to the
<a href="#.multiply"><code>multiply</code>
static method</a> and returns the result.
</dd>
</li>
<li>
<dt id=".prototype.divide">divide</dt>
<dd>
<code class="value-type">Function( n: Number or <a href="Q.html">Q</a>.ComplexNumber ) ⇒ <a href="Q.html">Q</a>.ComplexNumber</code>
Passes this instance as the first argument
and <code>n</code> as the second argument
to the
<a href="#.divide"><code>divide</code>
static method</a> and returns the result.
</dd>
</li>
<li>
<dt id=".prototype.add">add</dt>
<dd>
<code class="value-type">Function( n: Number or <a href="Q.html">Q</a>.ComplexNumber ) ⇒ <a href="Q.html">Q</a>.ComplexNumber</code>
Passes this instance as the first argument
and <code>n</code> as the second argument
to the
<a href="#.add"><code>add</code>
static method</a> and returns the result.
</dd>
</li>