calculus¶
This submodule collects all the basic functionality for calculus contained
within this package. The central ingredient is the Complex type, which allows
to work with rational-number-valued complex numbers. While not perfect, this is
sufficient for many scenarios and much simpler to implement and maintain than
irrational numbers and avoids (most) reliance on rounding.
- class Complex(re: int | Fraction, im: int | Fraction = 0)¶
Bases:
objectRudimentary implementation of a rational-number-valued complex number.
- Parameters:
- abs2() int | Fraction¶
Computes z*conjugate(z) of the complex number z.
- Returns:
Absolute value squared of the current complex number.
- Return type:
int|Fraction
- conjugate()¶
Complex conjugation.
- Returns:
Complex conjugate of the current complex number.
- Return type:
- property imag¶
Returns the imaginary part of the complex number to comply with standard Python number interface.
- phase()¶
Assuming the complex number to be purely real or purely imaginary, this function returns the sign and (for a purely imaginary number) an imaginary unit.
- Returns:
Sign and any overall imaginary unit.
- Return type:
- Raises:
AssertionError – If number is not purely real or purely imaginary.
- property real¶
Returns the real part of the complex number to comply with standard Python number interface.
- class Matrix(components: list[list[Complex]] = None)¶
Bases:
objectBasic implementation of a matrix with complex rational coefficients.
- Parameters:
components (list[list[Complex]], optional) – The rows and columns of the matrix. If
Noneare given, yields an empty matrix which is a valid starting point to build your matrix viaMatrix.extend.
- COL = 1¶
- property M¶
Returns the number of rows.
- property N¶
Returns the number of columns.
- ROW = 0¶
- __getitem__(idx: int | tuple[int | slice, int | slice])¶
Danger
A
sliceranging further than the matrix dimensions will not yield an error.- Raises:
TypeError – Indicates that the chosen indices are not in the expected format.
- __setitem__(idx: int | tuple[int | slice, int | slice], value)¶
Danger
A
sliceranging further than the matrix dimensions will not yield an error as long as the actual size available agrees with value.- Parameters:
- Raises:
AssertionError – Indicates that there was a dimension mismatch.
TypeError – Indicates that the chosen indices are not in the expected format.
- static diag(delems: list[Complex], M=None, N=None)¶
Generalisation of a standard diagonal square matrix.
The user can choose the dimensions freely as long as the diagonal entries fit into the matrix.
- Parameters:
diag (list[Complex]) – Diagonal elements to fill the matrix with.
M (int, optional) – Requested number of rows. Defaults to
None. Otherwise, must be at least the number of delems given.N (int, optional) – Requested number of columns. Defaults to
None. Otherwise, must be at least the number of delems given.
- Returns:
New matrix with diagonal entries set to delems and otherwise zero.
- Return type:
- extend(elems: list[Complex], dim=1)¶
Enlarge the matrix by adding a column or row to the existing matrix.
- Parameters:
- Raises:
AssertionError – Indicates that the dimensions do not match.
NotImplementedError – Indicates that the chosen dim is neither 0 nor 1.
- inverse()¶
Inversion of the matrix.
Uses basic implementation of Gauss elimination for inverse of complex rational square matrix.
- Returns:
The inverse of this matrix.
- Return type:
- Raises:
AssertionError – Indicates that the matrix is not square and thus non-invertible.
- rank(persistent=False)¶
This is an adaptation of
solveomitting any RHS input but allowing for all-zero columns. If persistent isTruetheMatrixis changed into a generalised row-echelon form and any totally zero rows are being dropped. This way only the rows relevant for checks of linear-independence are being kept.
- trace()¶
Computes the generalised trace.
- Returns:
Sum of all the diagonal elements.
- Return type: