Skip to content

Commit 069196c

Browse files
committed
Add matrix axioms test for inverses.
1 parent 5e4bac7 commit 069196c

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

tests/LinearAlgebra/Matrix/Numeric/MatrixAxiomsTest.php

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
* - AA⁻¹ = I = A⁻¹A
3232
* - (A⁻¹)⁻¹ = A
3333
* - (AB)⁻¹ = B⁻¹A⁻¹
34+
* - (A + B)⁻¹ ≠ A⁻¹ + B⁻¹
3435
* - A is invertible, Aᵀ is inveritble
3536
* - A is invertible, AAᵀ is inveritble
3637
* - A is invertible, AᵀA is inveritble
@@ -838,6 +839,33 @@ public function testInverseProductIsReverseProductOfInverses(array $A, array $B)
838839
$this->assertEqualsWithDelta($⟮AB⟯⁻¹->getMatrix(), $B⁻¹A⁻¹->getMatrix(), 0.00001);
839840
}
840841

842+
/**
843+
* (A + B)⁻¹ ≠ A⁻¹ + B⁻¹
844+
* The inverse of a sum is not equal to the sum of inverses.
845+
*
846+
* @dataProvider dataProviderForInverse
847+
* @param array $A
848+
* @param array $B
849+
* @throws \Exception
850+
*/
851+
public function testInverseSumIsNotTheSumOfInverses(array $A, array $B)
852+
{
853+
// Given
854+
$A = MatrixFactory::create($A);
855+
$B = MatrixFactory::create($B);
856+
857+
// When
858+
$⟮A+B⟯⁻¹ = $A->add($B)->inverse();
859+
860+
// And
861+
$A⁻¹ = $A->inverse();
862+
$B⁻¹ = $B->inverse();
863+
$⟮A⁻¹+B⁻¹⟯ = $A⁻¹->add($B⁻¹);
864+
865+
// Then
866+
$this->assertNotEqualsWithDelta($⟮A+B⟯⁻¹->getMatrix(), $⟮A⁻¹+B⁻¹⟯ ->getMatrix(), 0.00001);
867+
}
868+
841869
/**
842870
* @test Axiom: A is invertible, Aᵀ is inveritble
843871
* If A is an invertible matrix, then the transpose is also inveritble

0 commit comments

Comments
 (0)