math::...symdiff(3tcl)

πŸ“¦
version 2.0 Β· 2 versions
, in debian trixie, ubuntu questing, ubuntu resolute, ubuntu stonking

πŸ’– math::...symdiff β€” the iconic Tcl symbolic differentiation era πŸ’–

okay bestie, gather round, because this one is genuinely giving math girl main character energy. We're talking math::calculus::symdiff, the Tcl package that does symbolic differentiation for you. No cap. It lives in the tcllib fam, and honestly? It ate.


✨ NAME ✨

math::calculus::symdiff β€” Symbolic differentiation for Tcl. That's the whole vibe. πŸ’…


🌸 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

so yeah, you need Tcl 8.5 or 9, you need grammar::aycock at version 1.0, and you need the package itself at 1.0.2. Then you get exactly two procedures to play with. iconic lineup, honestly. πŸŽ€


πŸ¦‹ DESCRIPTION πŸ¦‹

The math::calculus::symdiff package hands you a symbolic differentiation facility for Tcl math expressions. It's the bestie you call when other packages either need the Jacobian of a set of functions, or are just way more efficient or more stable when you hand them the Jacobian. Basically: derivatives on demand, no calculator required. ✨


πŸ‘‘ PROCEDURES πŸ‘‘

The math::calculus::symdiff package exports these two procedures, and yes, they are both serving:

  • math::calculus::symdiff::symdiff expression variable β€” Differentiates the given expression with respect to the specified variable. (The Expressions section below spills the tea on exactly which subset of Tcl math expressions is acceptable here.) What you get back is a Tcl expression that evaluates the derivative. It returns an error if expression is not a well-formed expression or is not differentiable. 🫢
  • math::calculus::jacobian variableDict β€” Computes the Jacobian of a system of equations. The system is given by the dictionary variableDict: the keys are the names of the variables in the system, and the values are Tcl expressions giving the values of those variables. (Again, see Expressions below for the acceptable subset of Tcl math expressions.) 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 cannot be differentiated, or if variableDict is not a well-formed dictionary. πŸ’€

🧚 EXPRESSIONS 🧚

okay this is the part where we do a vibe check on what's allowed, because this package is picky in the cutest way. It only accepts a small subset of the expressions that Tcl commands like expr or if would happily swallow. Specifically, the only constructs accepted are:

  • Floating-point constants such as 5 or 3.14159e+00. ⭐
  • References to Tcl variables using $-substitution. The variable names must consist of alphanumerics and underscores: the ${...} notation is not accepted. πŸ™ˆ
  • Parentheses.
  • The +, -, *, /. and ** operators.
  • Calls to the functions acos, asin, atan, atan2, cos, cosh, exp, hypot, log, log10, pow, sin, sinh. sqrt, tan, and tanh.
and listen β€” command substitution, backslash substitution, and argument expansion are not accepted. at all. don't try it. 🚫

🌈 EXAMPLES 🌈

here's the glow-up in action, bestie:

math::calculus::symdiff::symdiff {($a*$x+$b)*($c*$x+$d)} x
==> (($c * (($a * $x) + $b)) + ($a * (($c * $x) + $d)))
math::calculus::symdiff::jacobian {x {$a * $x + $b * $y}
                         y {$c * $x + $d * $y}}
==> {{$a} {$b}} {{$c} {$d}}

look at that derivative. it ate. periodt. πŸ”₯


πŸ’€ BUGS, IDEAS, FEEDBACK πŸ’€

ngl, this document and the package it describes will undoubtedly contain bugs and other problems. (Their words, not mine, but we respect the honesty.) Please report such in the category math :: calculus of the Tcllib Trackers at http://core.tcl.tk/tcllib/reportlist. πŸ‘‘

Also please report any ideas for enhancements you may have for either the package and/or the documentation. We love a glow-up suggestion. πŸ’œ

When proposing code changes, please provide unified diffs, i.e the output of diff -u. πŸ“

Note further that attachments are strongly preferred over inlined patches. Attachments can be made 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. iykyk. πŸŽ€


πŸ” SEE ALSO πŸ”

  • math::calculus
  • math::interpolate

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 was tcllib, version 1.0.2, page math::...symdiff(3tcl) β€” go differentiate something iconic. mwah. πŸ’…βœ¨πŸ’–

πŸ“¦ where this page comes from