Differentiate(3pm)

๐Ÿ“ฆ
version 0.3 ยท 2 versions
  • 0.3 ยท debian bookworm, debian trixie, ubuntu noble, ubuntu resolute, ubuntu stonking (latest)
  • 0.3 ยท ubuntu jammy
, in debian bookworm, debian trixie, ubuntu noble, ubuntu resolute, ubuntu stonking

๐Ÿ’– 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 write 5*x and not just 5x. 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 calling differentiate, as the tree will often not be in the most compact possible form, and this will affect the readability of output from getExpression and the performance of future calls to differentiate if 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 (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