Differentiate(3pm)
๐ Differentiate(3pm) โ the perl manual page, but make it cute ๐
okay bestie, gather round, because this is Math::Calculus::Differentiate and it is literally an Algebraic Differentiation Engine. she does calculus. she does it for you. no cap. ๐งฎโจ
(also for the record this is a User Contributed Perl Documentation page, so you know it's community-made with love ๐ซถ)
โจ NAME โจ
Math::Calculus::Differentiate โ Algebraic Differentiation Engine ๐
๐ธ SYNOPSIS ๐ธ
use Math::Calculus::Differentiate;
# Create an object.
my $exp = Math::Calculus::Differentiate->new;
# Set a variable and expression.
$exp->addVariable('x');
$exp->setExpression('x^2 + 5*x') or die $exp->getError;
# Differentiate and simplify.
$exp->differentiate or die $exp->getError;;
$exp->simplify or die $exp->getError;;
# Print the result.
print $exp->getExpression; # Prints 2*x + 5
like... that's it. that's the whole glow-up. you hand her x^2 + 5*x, she hands you back 2*x + 5. iconic behaviour. ๐
๐ฆ DESCRIPTION ๐ฆ
so here's the vibe: this module takes an algebraic expression, parses it into a tree structure, then messes with that tree so it represents the differentiated function, then simplifies the tree, and then turns the tree back into output in the same form as the input. it's giving "I go in a circle and come out smarter." ๐๐ซ
she supports differentiation of expressions including the +, -, *, / and ^ (raise to power) operators, bracketed expressions to enable correct precedence, and the functions ln, exp, sin, cos, tan, sec, cosec, cot, sinh, cosh, tanh, sech, cosech, coth, asin, acos, atan, asinh, acosh and atanh.
that is a lot of trig. she ate and left no crumbs. ๐
๐ EXPORT ๐
None by default.
๐ METHODS ๐
๐ซถ new
$exp = Math::Calculus::Differentiate->new;
Creates a new instance of the differentiation engine, which can hold an individual expression. think of it as summoning your girl โ she's here, she's fresh, she's ready to hold exactly one (1) expression. โจ
๐ซถ addVariable
$exp->addVariable('x');
Sets a certain named value in the expression as being a variable. heads up bestie: a named value must be an alphabetic character. no numbers, no vibes-based names, just letters. ๐ค
๐ซถ setExpression
$exp->setExpression('x^2 + 5*x);
Takes an expression in human-readable form and stores it internally as a tree structure, checking it is a valid expression that the module can understand in the process.
โ ๏ธ note that the engine is strict about syntax. for example, note above that you must write5*xand not just5x. do not try to be casual with her. she will not accept it. ๐ญ
Whitespace is allowed in the expression, but it does not have any effect on precedence. If you require control of precedence, use brackets; bracketed expressions will always be evaluated first, as you would normally expect. The module follows the BODMAS precedence convention.
Returns undef on failure and a true value on success. ๐ซก
๐ซถ getExpression
$expr = $exp->getExpression;
Returns a textual, human readable representation of the expression that is being stored. it's her little show-and-tell. ๐
๐ซถ differentiate
$exp->differentiate('x');
Differentiates the expression that was stored with setExpression with respect to the variable passed as a parameter. Returns undef on failure and a true value on success. the main character moment. ๐
๐ซถ simplify
$exp->simplify;
Attempts to simplify the expression that is stored internally.
๐ก it is a very good idea to call this after callingdifferentiate, as the tree will often not be in the most compact possible form, and this will affect the readability of output fromgetExpressionand the performance of future calls todifferentiateif you are intending to obtain higher derivatives.
Returns undef on failure and a true value on success. she's not just pretty, she's efficient. ๐
๐ซถ getTraceback
$exp->getTraceback;
When setExpression and differentiate are called, a traceback is generated to describe what these functions did. If an error occurs, this traceback can be extremely useful in helping track down the source of the error. it's the receipts, bestie. keep them. ๐งพโจ
๐ซถ getError
$exp->getError;
When any method other than getTraceback is called, the error message stored is cleared, and then any errors that occur during the execution of the method are stored. If failure occurs, call this method to get a textual representation of the error. ๐
๐ SEE ALSO ๐
The author of this module has a website at <http://www.jwcs.net/~jonathan/>, which has the latest news about the module and a web-based frontend to allow you to test the module out for yourself. go poke at it, it's cute. ๐ฅ๏ธ๐
๐ AUTHOR ๐
Jonathan Worthington, <jonathan@jwcs.net>
๐ COPYRIGHT AND LICENSE ๐
Copyright (C) 2004 by Jonathan Worthington
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.8.1 or, at your option, any later version of Perl 5 you may have available.
and that's the whole page, bestie ๐ซถ this was documented as part of perl v5.36.0 and stamped 2022-11-19. go differentiate something. slay. periodt. ๐ โจ๐
๐ฆ where this page comes from
- debian bookworm: libmath-calculus-differentiate-perl 0.3-4 ยท Artistic-1.0-Perl OR GPL-1.0-or-later
- debian trixie: libmath-calculus-differentiate-perl 0.3-4 ยท Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu noble: libmath-calculus-differentiate-perl 0.3-4 ยท Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu resolute: libmath-calculus-differentiate-perl 0.3-4 ยท Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu stonking: libmath-calculus-differentiate-perl 0.3-4 ยท Artistic-1.0-Perl OR GPL-1.0-or-later
- ๐ girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms