A Python CLI application that calculates the determinant of square matrices of any dimension. It uses a hybrid approach: direct closed-form formulas for lower orders (
Note: The CLI interface and user prompts are currently in Italian.
The program dynamically routes the calculation based on the dimension match/case pattern.
For a single-element matrix
Calculated directly via the difference between the main and secondary diagonal products (metodo_diagonale):
For metodo_sarrus):
The determinant is calculated by summing the products of the three main diagonals and subtracting the products of the three secondary diagonals:
For larger matrices, the program performs Laplace Expansion (metodo_laplace) along the first row (
-
Minor Submatrices (
$M_{1j}$ ): For each element$a_{1j}$ in the first row, a new submatrix of order$(N-1) \times (N-1)$ is constructed by removing row$1$ and column$j$ . -
Cofactor Sign: The sign
$(-1)^{1+j}$ alternates based on element coordinate parity (is_posizizone_pari). -
Recursion Base Case: Submatrices are recursively evaluated through
calcolo_determinanteuntil they hit base cases ($N \le 3$ ), avoiding unnecessary decomposition down to$1 \times 1$ .
-
Time Complexity:
$O(N!)$ due to recursive submatrix branching in Laplace expansion. -
Space Complexity:
$O(N^2)$ stack allocation for submatrix slicing during execution.
Note: The program handles matrices up to $10 \times 10$ rapidly. Larger dimensions (e.g. $11 \times 11$) will require noticeable processing time due to factorial expansion.
├── main.py # Core logic, Laplace recursion, and matrix validation
├── input.py # Terminal input parsing and row dimension checking
├── output.py # Terminal UI rendering using Rich (Tables & Panels)
└── determinanti.gif
Requires Python 3.10+ and the rich library.
- Install dependencies:
pip install rich - Run the program:
python main.py
