For Perl 5 there is Math::GSL::Roots - Find roots of arbitrary 1-D functions
https://metacpan.org/pod/Math::GSL::Roots
Raku has support for using Perl 5 code or can access the GSL C library directly, can't it?
$fspec = sub {
my ( $x ) = shift;
# here the function has to be inserted in the format
# return leftside - rightside;
return ($x + $x**2) - 4;
};
gsl_root_fsolver_alloc($T); # where T is the solver algorithm, see link for the 6 type constants, e.g. $$gsl_root_fsolver_brent
gsl_root_fsolver_set( $s, $fspec, $x_lower, $x_upper ); # [$x_lower; $x_upper] is search interval
gsl_root_fsolver_iterate($s);
gsl_root_fsolver_iterate($s);
gsl_root_fsolver_iterate($s);
gsl_root_fsolver_iterate($s);
gsl_root_fsolver_iterate($s);
my $result = gsl_root_fsolver_root($s);
gsl_root_fsolver_free (s);
There are enhanced algorithms available (gsl_root_fdfsolver_*), if the derivative of a function is available.
See also https://www.gnu.org/software/gsl/doc/html/roots.html#examples for general usage
Math::Symbolic
. Looks like.new
and.isolate
might do the trick. – EnteritisMath::Symbolic
and noting it doesn't do logarithms, I didn't pay enough attention. Given that the OP equation is a polynomial, perhapsMath::Libgsl::Polynomial
is appropriate? I'm out of my depth -- I just know how to search, I don't know how to use symbolic math systems -- but I think, if someone can confirm it works well enough to solve this equation, it would be nice if that was posted as an answer (regardless of whether or not anyone views it "a neat and concise solution"). – Enteritisuse Math::Polynomial:from<Perl5>
would work well? At first glance this perl module looks notably mature and well maintained. It's essentially a 23 year old codebase, with two lead authors, continual commits, the latest commit a couple months ago, and "no known unresolved issues". The raku moduleMath::Libgsl::Polynomial
is a brand new wrapper of a C library of about the same vintage. I think of this as a really nice contrast/compare situation; there's scope here for a definitive SO on this topic. – Enteritis