Math::...Algebra(3pm)

🌸 Math::...Algebra(3pm) 🌸

okay bestie, welcome to the User Contributed Perl Documentation entry for Math::Symbolic::MiscAlgebra β€” yes the man page header shortens the name all cute like that, don't @ me. pull up a chair, we're doing algebra πŸ’–


✨ NAME ✨

Math::Symbolic::MiscAlgebra β€” miscellaneous algebra routines, like det(). that's it, that's the name 🌟


🌈 SYNOPSIS 🌈

use Math::Symbolic qw/:all/;
use Math::Symbolic::MiscAlgebra qw/:all/; # not loaded by Math::Symbolic

@matrix = (['x*y', 'z*x', 'y*z'],['x', 'z', 'z'],['x', 'x', 'y']);
$det = det @matrix;

@vector = ('x', 'y', 'z');
$solution = solve_linear(\@matrix, \@vector);

πŸ’… DESCRIPTION πŸ’…

so this module hands you a lil bundle of subroutines that are all about algebra β€” like computing the determinant of quadratic matrices, solving linear equation systems, and computing Bell Polynomials. iconic behaviour tbh 🫢

heads up though: the code in here may or may not get refactored into the OO-interface of the Math::Symbolic module at some point in the future. so like, no promises, luv u πŸ™ˆ

πŸŽ€ EXPORT πŸŽ€

None by default. nada. zero. the void. πŸ’€

but you can choose to have any of these routines exported into the calling namespace if you want. and the :all tag exports all of the following:

det
linear_solve
bell_polynomial

πŸ”₯ SUBROUTINES πŸ”₯

⭐ det

det() computes the determinant of a matrix of Math::Symbolic trees (or strings that can be parsed as such, slay). the first argument must be a literal array: det @matrix, where @matrix is an n x n matrix.

⚠️ ngl bestie, real talk: calculating determinants of matrices using the straightforward Laplace algorithm is a slow (O(n!)) operation. like, O(n!). this implementation also cannot make use of the various optimizations that come from the determinant properties, because we're dealing with symbolic matrix elements. so if you've got a matrix of reals, it is strongly suggested that you use Math::MatrixReal or Math::Pari to get the determinant instead β€” those can calculate it using LR decomposition, which is much faster. periodt.

and on a related note, because the numbers here are genuinely unhinged: calculating the determinant of a 20x20 matrix would take over 77146 years if your Perl could do 1 million calculations per second. 😭 and given that we're talking about several method calls per calculation, that's much more than today's computers could do. on the other hand, if you were using this straightforward algorithm with numbers only and in C, you might be done in 26 years β€” alright β€” so please go for the smarter route (better algorithm) instead if you have numbers only. k byeee πŸ¦‹

πŸ’œ linear_solve

Calculates the solutions x (vector) of a linear equation system of the form Ax = b, with A being a matrix, b a vector, and the solution x a vector. the way that math works ✨

Due to implementation limitations:

  • A must be a quadratic matrix
  • b must have a dimension that is equivalent to that of A
  • furthermore, the determinant of A must be non-zero

The algorithm used is devised from Cramer's Rule and is therefore inefficient. the preferred algorithm for this task is Gaussian Elimination. so if you have a matrix and a vector of real numbers, please consider using either Math::MatrixReal or Math::Pari instead. i'm just the messenger πŸ’…

First argument must be a reference to a matrix (array of arrays) of symbolic terms, and the second argument must be a reference to a vector (array) of symbolic terms. Strings will be automatically converted to Math::Symbolic trees, no extra work from you. Returns a reference to the solution vector. 🎁

πŸ¦‹ bell_polynomial

This function returns the nth Bell Polynomial. it uses memoization for a speed increase, because we're efficient like that ⚑

First argument is the n. Second (optional) argument is the variable or variable name to use in the polynomial. it defaults to 'x'.

The Bell Polynomial is defined as follows:

phi_0  (x) = 1
phi_n+1(x) = x * ( phi_n(x) + partial_derivative( phi_n(x), x ) )

Bell Polynomials are Exponential Polynimals (sic, we keep it real in this house 😌) with phi_n(1) = the nth bell number. Please refer to the bell_number() function in the Math::Symbolic::AuxFunctions module for a method of generating these numbers. go lil numbers go πŸ“


πŸ‘‘ AUTHOR πŸ‘‘

Please send feedback, bug reports, and support requests to the Math::Symbolic support mailing list: math-symbolic-support at lists dot sourceforge dot net. and honestly? please consider letting us know how you use Math::Symbolic. Thank you. 🫢

If you're interested in helping with the development or extending the module's functionality, please contact the developers' mailing list: math-symbolic-develop at lists dot sourceforge dot net.

List of contributors β€” legends, every single one πŸ‘‘:

Steffen MΓΌller, symbolic-module at steffen-mueller dot net
Stray Toaster, mwk at users dot sourceforge dot net
Oliver EbenhΓΆh

🌈 SEE ALSO 🌈

New versions of this module can be found on http://steffen-mueller.net or CPAN. The module development takes place on Sourceforge at http://sourceforge.net/projects/math-symbolic/

Math::Symbolic


and that's the whole page bestie, you ate it πŸ’…β­ this was perl v5.40.0, dated 2024-09-16, filed under Math::...Algebra(3pm) β€” go forth and compute those determinants (responsibly, with Math::MatrixReal) πŸŽ€πŸ’–

πŸ“¦ where this page comes from