mathverse-complex 0.1.2

MathVerse complex numbers: arithmetic, powers, transcendental functions
Documentation
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
//! Complex matrix operations: arithmetic, decomposition, eigenvalues.

use crate::Complex;

/// Complex matrix with row-major storage.
#[derive(Debug, Clone)]
pub struct ComplexMatrix {
    pub data: Vec<Complex>,
    pub rows: usize,
    pub cols: usize,
}

impl ComplexMatrix {
    /// Create a new complex matrix.
    pub fn new(rows: usize, cols: usize) -> Self {
        ComplexMatrix {
            data: vec![Complex::zero(); rows * cols],
            rows,
            cols,
        }
    }

    /// Create matrix from data.
    pub fn from_data(data: Vec<Complex>, rows: usize, cols: usize) -> Self {
        assert_eq!(data.len(), rows * cols);
        ComplexMatrix { data, rows, cols }
    }

    /// Get element at (row, col).
    pub fn get(&self, row: usize, col: usize) -> Complex {
        self.data[row * self.cols + col]
    }

    /// Set element at (row, col).
    pub fn set(&mut self, row: usize, col: usize, value: Complex) {
        self.data[row * self.cols + col] = value;
    }

    /// Create zero matrix.
    pub fn zeros(rows: usize, cols: usize) -> Self {
        ComplexMatrix::new(rows, cols)
    }

    /// Create identity matrix.
    pub fn identity(n: usize) -> Self {
        let mut matrix = ComplexMatrix::new(n, n);
        for i in 0..n {
            matrix.set(i, i, Complex::one());
        }
        matrix
    }

    /// Matrix addition.
    pub fn add(&self, other: &ComplexMatrix) -> ComplexMatrix {
        assert_eq!(self.rows, other.rows);
        assert_eq!(self.cols, other.cols);
        
        let mut result = ComplexMatrix::new(self.rows, self.cols);
        for i in 0..self.data.len() {
            result.data[i] = self.data[i] + other.data[i];
        }
        result
    }

    /// Matrix subtraction.
    pub fn sub(&self, other: &ComplexMatrix) -> ComplexMatrix {
        assert_eq!(self.rows, other.rows);
        assert_eq!(self.cols, other.cols);
        
        let mut result = ComplexMatrix::new(self.rows, self.cols);
        for i in 0..self.data.len() {
            result.data[i] = self.data[i] - other.data[i];
        }
        result
    }

    /// Scalar multiplication.
    pub fn scale(&self, scalar: Complex) -> ComplexMatrix {
        let mut result = ComplexMatrix::new(self.rows, self.cols);
        for i in 0..self.data.len() {
            result.data[i] = self.data[i] * scalar;
        }
        result
    }

    /// Matrix multiplication.
    pub fn mul(&self, other: &ComplexMatrix) -> ComplexMatrix {
        assert_eq!(self.cols, other.rows);
        
        let mut result = ComplexMatrix::new(self.rows, other.cols);
        
        for i in 0..self.rows {
            for j in 0..other.cols {
                let mut sum = Complex::zero();
                for k in 0..self.cols {
                    sum = sum + self.get(i, k) * other.get(k, j);
                }
                result.set(i, j, sum);
            }
        }
        
        result
    }

    /// Matrix transpose.
    pub fn transpose(&self) -> ComplexMatrix {
        let mut result = ComplexMatrix::new(self.cols, self.rows);
        
        for i in 0..self.rows {
            for j in 0..self.cols {
                result.set(j, i, self.get(i, j));
            }
        }
        
        result
    }

    /// Conjugate transpose (Hermitian transpose).
    pub fn hermitian(&self) -> ComplexMatrix {
        let mut result = ComplexMatrix::new(self.cols, self.rows);
        
        for i in 0..self.rows {
            for j in 0..self.cols {
                result.set(j, i, self.get(i, j).conjugate());
            }
        }
        
        result
    }

    /// Matrix trace.
    pub fn trace(&self) -> Complex {
        assert_eq!(self.rows, self.cols);
        
        let mut sum = Complex::zero();
        for i in 0..self.rows {
            sum = sum + self.get(i, i);
        }
        sum
    }

    /// Matrix determinant (for small matrices).
    pub fn determinant(&self) -> Complex {
        assert_eq!(self.rows, self.cols);
        
        match self.rows {
            1 => self.get(0, 0),
            2 => {
                let a = self.get(0, 0);
                let b = self.get(0, 1);
                let c = self.get(1, 0);
                let d = self.get(1, 1);
                a * d - b * c
            }
            3 => {
                let a = self.get(0, 0);
                let b = self.get(0, 1);
                let c = self.get(0, 2);
                let d = self.get(1, 0);
                let e = self.get(1, 1);
                let f = self.get(1, 2);
                let g = self.get(2, 0);
                let h = self.get(2, 1);
                let i = self.get(2, 2);
                
                a * (e * i - f * h) - b * (d * i - f * g) + c * (d * h - e * g)
            }
            _ => {
                // Use LU decomposition for larger matrices
                let (_, u, pivot) = self.lu_decomposition().unwrap();
                let mut det = Complex::one();
                
                for i in 0..self.rows {
                    det = det * u.get(i, i);
                }
                
                // Sign from permutation parity: (-1)^(n - #cycles)
                let mut visited = vec![false; self.rows];
                let mut cycles = 0;
                for i in 0..self.rows {
                    if !visited[i] {
                        cycles += 1;
                        let mut j = i;
                        while !visited[j] {
                            visited[j] = true;
                            j = pivot[j];
                        }
                    }
                }
                if (self.rows - cycles) % 2 == 1 {
                    det = -det;
                }
                
                det
            }
        }
    }

    /// LU decomposition with partial pivoting.
    pub fn lu_decomposition(&self) -> Option<(ComplexMatrix, ComplexMatrix, Vec<usize>)> {
        if self.rows != self.cols {
            return None;
        }
        
        let n = self.rows;
        let mut l = ComplexMatrix::identity(n);
        let mut u = self.clone();
        let mut pivot = (0..n).collect::<Vec<_>>();
        
        for k in 0..n {
            // Find pivot
            let mut max_row = k;
            let mut max_val = u.get(k, k).norm();
            
            for i in (k + 1)..n {
                let val = u.get(i, k).norm();
                if val > max_val {
                    max_val = val;
                    max_row = i;
                }
            }
            
            if max_val < 1e-15 {
                return None; // Singular matrix
            }
            
            // Swap rows
            if max_row != k {
                pivot.swap(k, max_row);
                for j in 0..n {
                    let temp = u.get(k, j);
                    u.set(k, j, u.get(max_row, j));
                    u.set(max_row, j, temp);
                }
            }
            
            // Elimination
            for i in (k + 1)..n {
                let factor = u.get(i, k) / u.get(k, k);
                l.set(i, k, factor);
                
                for j in k..n {
                    let new_val = u.get(i, j) - factor * u.get(k, j);
                    u.set(i, j, new_val);
                }
            }
        }
        
        Some((l, u, pivot))
    }

    /// Solve linear system Ax = b using LU decomposition.
    pub fn solve(&self, b: &[Complex]) -> Option<Vec<Complex>> {
        if self.rows != self.cols || b.len() != self.rows {
            return None;
        }
        
        let (l, u, pivot) = self.lu_decomposition()?;
        let n = self.rows;
        
        // Apply pivot to b
        let mut pb = b.to_vec();
        for i in 0..n {
            pb[i] = b[pivot[i]];
        }
        
        // Forward substitution: Ly = pb
        let mut y = vec![Complex::zero(); n];
        for i in 0..n {
            let mut sum = pb[i];
            for j in 0..i {
                sum = sum - l.get(i, j) * y[j];
            }
            y[i] = sum / l.get(i, i);
        }
        
        // Back substitution: Ux = y
        let mut x = vec![Complex::zero(); n];
        for i in (0..n).rev() {
            let mut sum = y[i];
            for j in (i + 1)..n {
                sum = sum - u.get(i, j) * x[j];
            }
            x[i] = sum / u.get(i, i);
        }
        
        Some(x)
    }

    /// Matrix inverse.
    pub fn inverse(&self) -> Option<ComplexMatrix> {
        if self.rows != self.cols {
            return None;
        }
        
        let n = self.rows;
        let mut result = ComplexMatrix::new(n, n);
        
        // Solve for each column of identity
        for j in 0..n {
            let mut b = vec![Complex::zero(); n];
            b[j] = Complex::one();
            
            if let Some(col) = self.solve(&b) {
                for i in 0..n {
                    result.set(i, j, col[i]);
                }
            } else {
                return None;
            }
        }
        
        Some(result)
    }

    /// Check if matrix is Hermitian (equal to its conjugate transpose).
    pub fn is_hermitian(&self, tolerance: f64) -> bool {
        if self.rows != self.cols {
            return false;
        }
        
        let hermitian = self.hermitian();
        
        for i in 0..self.rows {
            for j in 0..self.cols {
                let diff = (self.get(i, j) - hermitian.get(i, j)).norm();
                if diff > tolerance {
                    return false;
                }
            }
        }
        
        true
    }

    /// Check if matrix is unitary (A * A^H = I).
    pub fn is_unitary(&self, tolerance: f64) -> bool {
        if self.rows != self.cols {
            return false;
        }
        
        let hermitian = self.hermitian();
        let product = self.mul(&hermitian);
        let identity = ComplexMatrix::identity(self.rows);
        
        for i in 0..self.rows {
            for j in 0..self.cols {
                let diff = (product.get(i, j) - identity.get(i, j)).norm();
                if diff > tolerance {
                    return false;
                }
            }
        }
        
        true
    }

    /// Frobenius norm.
    pub fn frobenius_norm(&self) -> f64 {
        self.data.iter().map(|c| c.norm_sq()).sum::<f64>().sqrt()
    }

    /// Matrix power A^n.
    pub fn power(&self, n: usize) -> ComplexMatrix {
        if self.rows != self.cols {
            panic!("Matrix must be square");
        }
        
        if n == 0 {
            return ComplexMatrix::identity(self.rows);
        }
        
        let mut result = ComplexMatrix::identity(self.rows);
        let mut base = self.clone();
        let mut exp = n;
        
        while exp > 0 {
            if exp % 2 == 1 {
                result = result.mul(&base);
            }
            base = base.mul(&base);
            exp /= 2;
        }
        
        result
    }

    /// Matrix exponential e^A using Taylor series with scaling-and-squaring:
    /// compute e^(A/2^k) then square k times.
    pub fn exp(&self, iterations: usize) -> ComplexMatrix {
        if self.rows != self.cols {
            panic!("Matrix must be square");
        }
        
        let norm = self.frobenius_norm();
        let mut scale_pow = 0;
        if norm > 1.0 {
            scale_pow = norm.log2().ceil() as usize;
        }
        let scaled = self.scale(Complex::real(1.0 / 2.0_f64.powi(scale_pow as i32)));
        
        let mut result = ComplexMatrix::identity(self.rows);
        let mut term = ComplexMatrix::identity(self.rows);
        let mut factorial: f64 = 1.0;
        
        for n in 1..=iterations {
            factorial *= n as f64;
            term = term.mul(&scaled);
            
            for i in 0..term.data.len() {
                result.data[i] = result.data[i] + term.data[i] / Complex::real(factorial);
            }
        }
        
        for _ in 0..scale_pow {
            result = result.mul(&result);
        }
        
        result
    }

    /// Matrix logarithm ln(A) using Taylor series around identity.
    /// Returns `None` if the series cannot converge, i.e. if any eigenvalue
    /// of A is outside the disk |λ - 1| < 1 (checked via a Frobenius-norm
    /// bound on A - I, which is conservative but safe).
    pub fn ln(&self, iterations: usize) -> Option<ComplexMatrix> {
        if self.rows != self.cols {
            panic!("Matrix must be square");
        }
        
        let identity = ComplexMatrix::identity(self.rows);
        let a_minus_i = self.sub(&identity);
        
        // ||A - I||_F >= spectral radius of (A - I); series needs it < 1
        if a_minus_i.frobenius_norm() >= 1.0 {
            return None;
        }
        
        let mut result = ComplexMatrix::zeros(self.rows, self.cols);
        let mut term = a_minus_i.clone();
        
        for n in 1..=iterations {
            let sign = if n % 2 == 0 { -Complex::one() } else { Complex::one() };
            let scalar = sign / Complex::real(n as f64);
            
            for i in 0..result.data.len() {
                result.data[i] = result.data[i] + term.data[i] * scalar;
            }
            
            term = term.mul(&a_minus_i);
        }
        
        Some(result)
    }
}

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn test_matrix_creation() {
        let m = ComplexMatrix::new(2, 3);
        assert_eq!(m.rows, 2);
        assert_eq!(m.cols, 3);
        assert_eq!(m.data.len(), 6);
    }

    #[test]
    fn test_identity() {
        let i = ComplexMatrix::identity(3);
        assert_eq!(i.get(0, 0), Complex::one());
        assert_eq!(i.get(1, 1), Complex::one());
        assert_eq!(i.get(2, 2), Complex::one());
        assert_eq!(i.get(0, 1), Complex::zero());
    }

    #[test]
    fn test_matrix_addition() {
        let mut m1 = ComplexMatrix::new(2, 2);
        m1.set(0, 0, Complex::real(1.0));
        m1.set(0, 1, Complex::real(2.0));
        
        let mut m2 = ComplexMatrix::new(2, 2);
        m2.set(0, 0, Complex::real(3.0));
        m2.set(0, 1, Complex::real(4.0));
        
        let result = m1.add(&m2);
        assert_eq!(result.get(0, 0), Complex::real(4.0));
        assert_eq!(result.get(0, 1), Complex::real(6.0));
    }

    #[test]
    fn test_matrix_multiplication() {
        let mut m1 = ComplexMatrix::new(2, 2);
        m1.set(0, 0, Complex::real(1.0));
        m1.set(0, 1, Complex::real(2.0));
        m1.set(1, 0, Complex::real(3.0));
        m1.set(1, 1, Complex::real(4.0));
        
        let mut m2 = ComplexMatrix::new(2, 2);
        m2.set(0, 0, Complex::real(5.0));
        m2.set(0, 1, Complex::real(6.0));
        m2.set(1, 0, Complex::real(7.0));
        m2.set(1, 1, Complex::real(8.0));
        
        let result = m1.mul(&m2);
        
        assert_eq!(result.get(0, 0), Complex::real(19.0)); // 1*5 + 2*7
        assert_eq!(result.get(0, 1), Complex::real(22.0)); // 1*6 + 2*8
        assert_eq!(result.get(1, 0), Complex::real(43.0)); // 3*5 + 4*7
        assert_eq!(result.get(1, 1), Complex::real(50.0)); // 3*6 + 4*8
    }

    #[test]
    fn test_determinant_2x2() {
        let mut m = ComplexMatrix::new(2, 2);
        m.set(0, 0, Complex::real(1.0));
        m.set(0, 1, Complex::real(2.0));
        m.set(1, 0, Complex::real(3.0));
        m.set(1, 1, Complex::real(4.0));
        
        let det = m.determinant();
        assert_eq!(det, Complex::real(-2.0)); // 1*4 - 2*3
    }

    #[test]
    fn test_transpose() {
        let mut m = ComplexMatrix::new(2, 3);
        m.set(0, 0, Complex::real(1.0));
        m.set(0, 1, Complex::real(2.0));
        m.set(0, 2, Complex::real(3.0));
        m.set(1, 0, Complex::real(4.0));
        m.set(1, 1, Complex::real(5.0));
        m.set(1, 2, Complex::real(6.0));
        
        let t = m.transpose();
        assert_eq!(t.rows, 3);
        assert_eq!(t.cols, 2);
        assert_eq!(t.get(0, 0), Complex::real(1.0));
        assert_eq!(t.get(1, 0), Complex::real(2.0));
        assert_eq!(t.get(0, 1), Complex::real(4.0));
    }

    #[test]
    fn test_hermitian() {
        let mut m = ComplexMatrix::new(2, 2);
        m.set(0, 0, Complex::real(1.0));
        m.set(0, 1, Complex::new(1.0, 2.0));
        m.set(1, 0, Complex::new(1.0, -2.0));
        m.set(1, 1, Complex::real(3.0));
        
        assert!(m.is_hermitian(1e-10));
    }

    #[test]
    fn test_solve() {
        let mut m = ComplexMatrix::new(2, 2);
        m.set(0, 0, Complex::real(2.0));
        m.set(0, 1, Complex::real(1.0));
        m.set(1, 0, Complex::real(1.0));
        m.set(1, 1, Complex::real(1.0));
        
        let b = vec![Complex::real(3.0), Complex::real(2.0)];
        let x = m.solve(&b).unwrap();
        
        // Solution should be [1, 1]
        assert!((x[0].re - 1.0).abs() < 1e-10);
        assert!((x[1].re - 1.0).abs() < 1e-10);
    }

    #[test]
    fn test_inverse() {
        let mut m = ComplexMatrix::new(2, 2);
        m.set(0, 0, Complex::real(2.0));
        m.set(0, 1, Complex::real(1.0));
        m.set(1, 0, Complex::real(1.0));
        m.set(1, 1, Complex::real(1.0));
        
        let inv = m.inverse().unwrap();
        let product = m.mul(&inv);
        
        // Should be close to identity
        assert!((product.get(0, 0) - Complex::one()).norm() < 1e-10);
        assert!((product.get(1, 1) - Complex::one()).norm() < 1e-10);
    }

    #[test]
    fn test_power() {
        let mut m = ComplexMatrix::new(2, 2);
        m.set(0, 0, Complex::real(1.0));
        m.set(0, 1, Complex::real(1.0));
        m.set(1, 0, Complex::real(0.0));
        m.set(1, 1, Complex::real(1.0));
        
        let m2 = m.power(2);
        
        assert_eq!(m2.get(0, 0), Complex::real(1.0));
        assert_eq!(m2.get(0, 1), Complex::real(2.0));
        assert_eq!(m2.get(1, 0), Complex::zero());
        assert_eq!(m2.get(1, 1), Complex::real(1.0));
    }

    #[test]
    fn test_determinant_permutation_sign() {
        // 4x4 permutation matrix swapping rows 0/1: det must be -1
        // (regression: LU path ignored pivot parity)
        let mut m = ComplexMatrix::identity(4);
        for j in 0..4 {
            let t = m.get(0, j);
            m.set(0, j, m.get(1, j));
            m.set(1, j, t);
        }
        let det = m.determinant();
        assert!((det.re + 1.0).abs() < 1e-12);
        assert!(det.im.abs() < 1e-12);

        // 4x4 diag(1,2,3,4) with rows 0/1 swapped: det = -24
        let mut m2 = ComplexMatrix::new(4, 4);
        m2.set(0, 0, Complex::real(1.0));
        m2.set(1, 1, Complex::real(2.0));
        m2.set(2, 2, Complex::real(3.0));
        m2.set(3, 3, Complex::real(4.0));
        for j in 0..4 {
            let t = m2.get(0, j);
            m2.set(0, j, m2.get(1, j));
            m2.set(1, j, t);
        }
        let det2 = m2.determinant();
        assert!((det2.re + 24.0).abs() < 1e-10);
    }

    #[test]
    fn test_matrix_exp() {
        // exp(0) = I
        let zero = ComplexMatrix::new(2, 2);
        let e0 = zero.exp(20);
        assert!((e0.get(0, 0) - Complex::one()).norm() < 1e-10);
        assert!((e0.get(1, 1) - Complex::one()).norm() < 1e-10);

        // exp([[0,1],[0,0]]) = [[1,1],[0,1]]
        let mut m = ComplexMatrix::new(2, 2);
        m.set(0, 1, Complex::one());
        let em = m.exp(20);
        assert!((em.get(0, 0) - Complex::one()).norm() < 1e-10);
        assert!((em.get(0, 1) - Complex::one()).norm() < 1e-10);
        assert!((em.get(1, 0) - Complex::zero()).norm() < 1e-10);
        assert!((em.get(1, 1) - Complex::one()).norm() < 1e-10);

        // exp of large-norm matrix needs scaling-and-squaring: exp(diag(10,10)) = diag(e^10, e^10)
        let mut big = ComplexMatrix::new(2, 2);
        big.set(0, 0, Complex::real(10.0));
        big.set(1, 1, Complex::real(10.0));
        let ebig = big.exp(30);
        let e10 = 10.0_f64.exp();
        assert!((ebig.get(0, 0).re - e10).abs() < 1e-6 * e10);
        assert!((ebig.get(1, 1).re - e10).abs() < 1e-6 * e10);
        assert!((ebig.get(0, 1) - Complex::zero()).norm() < 1e-6 * e10);
    }

    #[test]
    fn test_matrix_ln() {
        // ln(I) = 0
        let i = ComplexMatrix::identity(2);
        let ln_i = i.ln(20).unwrap();
        assert!((ln_i.get(0, 0) - Complex::zero()).norm() < 1e-10);

        // exp(ln(A)) = A for A near identity
        let mut a = ComplexMatrix::new(2, 2);
        a.set(0, 0, Complex::real(1.2));
        a.set(0, 1, Complex::real(0.1));
        a.set(1, 0, Complex::real(-0.2));
        a.set(1, 1, Complex::real(0.8));
        let ln_a = a.ln(40).unwrap();
        let round = ln_a.exp(40);
        for i in 0..2 {
            for j in 0..2 {
                assert!((round.get(i, j) - a.get(i, j)).norm() < 1e-8);
            }
        }

        // ln(10·I) diverges: must return None (regression: silently returned garbage)
        let mut big = ComplexMatrix::new(2, 2);
        big.set(0, 0, Complex::real(10.0));
        big.set(1, 1, Complex::real(10.0));
        assert!(big.ln(20).is_none());
    }
}