SYMDIFF(n)
π math::ca...::symdiff(n) β the whole vibe π
okay bestie, gather round, because we're talking about math::calculus::symdiff, and it is lowkey iconic. It's a Tcl manual page (that's the (n) up in the title, iykyk), and it does symbolic differentiation, which is a fancy way of saying: it does your calculus homework for you and hands back more Tcl code. π
β¨ NAME β¨
math::calculus::symdiff β symbolic differentiation for Tcl π¦
β¨ SYNOPSIS β¨
package require Tcl 8.5 9
package require grammar::aycock 1.0
package require math::calculus::symdiff 1.0.2
math::calculus::symdiff::symdiff expression variable
math::calculus::jacobian variableDict
no cap, that's the whole entrance exam. π«Ά
β¨ DESCRIPTION β¨
So math::calculus::symdiff is the package that gives you a symbolic differentiation facility for Tcl math expressions. The way that this is so useful is that it feeds derivatives to other packages β either the ones that literally require the Jacobian of a set of functions, or the ones that are just more efficient or more stable when you hand them a Jacobian instead of making them figure it out themselves. main character energy for real. π
β¨ PROCEDURES β¨
The package exports two procedures, and yes, we're going through both of them, periodt.
math::calculus::symdiff::symdiff expression variableβ differentiates the given expression with respect to the specified variable. (Peep the EXPRESSIONS section below for the β¨teaβ¨ on which subset of Tcl math expressionsmath::calculus::symdiffwill actually accept.) The result is a Tcl expression that evaluates the derivative. It returns an error if expression is not a well-formed expression, or if it's just plain not differentiable. πmath::calculus::jacobian variableDictβ computes the Jacobian of a system of equations. The system is handed to you in the dictionary variableDict, whose keys are the names of the variables in the system, and whose values are Tcl expressions giving the values of those variables. (Again, EXPRESSIONS below for the acceptable subset of Tcl math expressions β same rules, same energy.) The result is a list of lists: the i'th element of the j'th sublist is the partial derivative of the i'th variable with respect to the j'th variable. It returns an error if any of the expressions can't be differentiated, or if variableDict is not a well-formed dictionary. π
β¨ EXPRESSIONS β¨
ngl, this package is picky in the best way. math::calculus::symdiff accepts only a small subset of the expressions that Tcl commands like expr or if would happily take. Specifically? The only constructs accepted are:
- Floating-point constants, such as
5or3.14159e+00. π’ - References to Tcl variables using
$-substitution. The variable names must consist of alphanumerics and underscores β so heads up, the${...}notation is not accepted. π - Parentheses.
(and), love them. π - The
+,-,*,/, and**operators. - Calls to the functions
acos,asin,atan,atan2,cos,cosh,exp,hypot,log,log10,pow,sin,sinh,sqrt,tan, andtanh. πΈ
and that's it. Command substitution, backslash substitution, and argument expansion are not accepted. do not try it. I'm begging. π«
β¨ EXAMPLES β¨
watch this, it literally eats:
math::calculus::symdiff::symdiff {($a*$x+$b)*($c*$x+$d)} x
==> (($c * (($a * $x) + $b)) + ($a * (($c * $x) + $d)))
math::calculus::jacobian {x {$a * $x + $b * $y}
y {$c * $x + $d * $y}}
==> {{$a} {$b}} {{$c} {$d}}
ate and left no crumbs. π₯
β¨ BUGS, IDEAS, FEEDBACK β¨
okay so real talk: this document, and the package it describes, will undoubtedly contain bugs and other problems. It's giving humble, but it's also giving true. π Please report them in the category math :: calculus of the Tcllib Trackers at [http://core.tcl.tk/tcllib/reportlist]. And please also report any ideas for enhancements you may have for either the package and/or the documentation β they want to hear it. π«Ά
When proposing code changes, please provide unified diffs, i.e. the output of diff -u. (We love a clean diff, no notes.)
Also note: attachments are strongly preferred over inlined patches. You can make an attachment by going to the Edit form of the ticket immediately after its creation, and then using the left-most button in the secondary navigation bar. yw bestie π
β¨ SEE ALSO β¨
math::calculusmath::interpolate
β¨ COPYRIGHT β¨
Copyright (c) 2010 by Kevin B. Kenny <kennykb@acm.org>
Redistribution permitted under the terms of the Open Publication License <http://www.opencontent.org/openpub/>
and that's the whole page, bestie β¨ this lil guide is from tcllib, version 1.0.2, and it lives in section n of the manual β math::ca...::symdiff(n), iconic name, no notes. go differentiate something. mwah. ππ
π
π¦ where this page comes from
- fedora 43: tcllib 2.0-3.fc43 Β· TCL
- fedora 44: tcllib 2.0-4.fc44 Β· TCL
- nixos 26.05: tcllib 2.0
- nixpkgs unstable: tcllib 2.0
- Copyright (c) 2010 by Kevin B\&. Kenny <kennykb@acm\&.org>
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms