logo
Free, unlimited AI code reviews that run on commit
git-lrc git-lrc GitHub Install Now We'd appreciate a star git-lrc - Free, unlimited AI code reviews that run on commit | Product Hunt git-lrc - Free, unlimited AI code reviews that run on commit | Product Hunt

math::calculus::symdiff - Symbolic differentiation for Tcl

Bugs, Ideas, Feedback

       This document, and the package it describes, will undoubtedly contain bugs and  other  problems.   Please
       report     such     in     the     category     math::calculus    of    the    TcllibTrackers
       [http://core.tcl.tk/tcllib/reportlist].  Please also report any ideas for enhancements you may  have  for
       either package and/or documentation.

       When proposing code changes, please provide unifieddiffs, 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.

Description

       The   math::calculus::symdiff   package  provides  a  symbolic  differentiation  facility  for  Tcl  math
       expressions. It is useful for providing derivatives to packages that either require the Jacobian of a set
       of functions or else are more efficient or stable when the Jacobian is provided.

Examples

              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}}

Expressions

       The math::calculus::symdiff package accepts only a small subset of the expressions that are acceptable to
       Tcl commands such as expr or if.  Specifically, the only constructs accepted are:

       •      Floating-point constants such as 5 or 3.14159e+00.

       •      References  to Tcl variable 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.

       Command substitution, backslash substitution, and argument expansion are not accepted.

Name

       math::calculus::symdiff - Symbolic differentiation for Tcl

Procedures

       The math::calculus::symdiff package exports the two procedures:

       math::calculus::symdiff::symdiffexpressionvariable
              Differentiates the given expression with respect to the specified variable. (See Expressions below
              for  a  discussion  of  the  subset   of   Tcl   math   expressions   that   are   acceptable   to
              math::calculus::symdiff.)   The  result is a Tcl expression that evaluates the derivative. Returns
              an error if expression is not a well-formed expression or is not differentiable.

       math::calculus::jacobianvariableDict
              Computes the Jacobian  of  a  system  of  equations.   The  system  is  given  by  the  dictionary
              variableDict,  whose  keys  are  the  names  of  variables in the system, and whose values are Tcl
              expressions giving the values of those variables. (See Expressions below for a discussion  of  the
              subset  of  Tcl  math  expressions that are acceptable to math::calculus::symdiff. 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.  Returns  an  error  if  any  of  the  expressions  cannot  be
              differentiated, or if variableDict is not a well-formed dictionary.

See Also

       math::calculus, math::interpolate

Synopsis

       package require Tcl8.59

       package require grammar::aycock1.0

       package require math::calculus::symdiff1.0.2math::calculus::symdiff::symdiffexpressionvariablemath::calculus::jacobianvariableDict

________________________________________________________________________________________________________________

See Also