Archive<< September 2020 >>
- TMS FNC UI Pack v3.2 Revealing some highly anticipated components
- Hands-on: Building web design for a RAD Studio TMS WEB Core project
- TMS WEB Core Academic is here for Delphi developers!
- Get started with TMS WEB Core for Visual Studio Code
- Online event: The Theory and Practice of Amazing Desktop Application UI & UX
- TMS FNC Maps updates!
- TMS Subscription Manager v2.1 released
- Documenting your Delphi REST API the easy way
- TMS WEB Core for Visual Studio Code v1.0 released
- Edge Chromium Stable Support!
- Adrian Gallero (22)
- Bart Holvoet (5)
- Bernard Roussely (1)
- Bruno Fierens (261)
- Gjalt Vanhouwaert (6)
- Holger Flick (15)
- Marcos Douglas B. Santos (5)
- Masiha Zemarai (51)
- Nancy Lescouhier (32)
- Pieter Scheldeman (35)
- Roman Yankovsky (2)
- Tunde Keller (10)
- Wagner R. Landgraf (67)
BlogAll Blog Posts | Next Post | Previous Post
Monday, March 20, 2017The unique feature of Analytics library is symbolic derivatives calculation. The library provides the simplest way to get a symbolic derivative expression for almost any complicated expression. There are predefined derivative for all standard functions: trigonometric, hyperbolic, logarithmic and exponential, inverse trigonometric and hyperbolic, and other.
Another fine thing is that any developer can easily define derivative for any other function. Let us consider how to define derivative for special Gamma function (https://en.wikipedia.org/wiki/Gamma_function#General). Its derivative is defined via another special function Digamma (Polygamma function of order 0, https://en.wikipedia.org/wiki/Polygamma_function). Hereafter the Gamma function denoted as G and the Digamma (and Polygamma) as Y. Then, the derivative formula is: d(G(x))/dx = G(x)*Y(x).
To introduce new functional derivative new class must be implemented. In our case, the class is inherited from TSimpleFunctionalDerivative because the function has one argument only. Here is the code of the realized class:
As can be seen from the code, there are only three methods to override. The GetFunctionName method defines that the derivative is for function with name G. The IsRealized functions returns true, that means the class is totally realized and can be used by the Analytics system. And the last method defines the derivation algorithm itself. Namely, it creates the Gamma and Digamma functions with the same argument and, according to the derivative formula above, their product.
TGammaDerivative = class sealed(TSimpleFunctionalDerivative) protected function GetFunctionName(): string; override; function BaseDerivative(argument: TBaseExpression): TBaseExpression; override; public class function IsRealized: boolean; override; end; function TGammaDerivative.GetFunctionName: string; begin result:= 'G'; end; class function TGammaDerivative.IsRealized: boolean; begin result:= true; end; function TGammaDerivative.BaseDerivative(argument: TBaseExpression): TBaseExpression; var ge: TBaseExpression; dge: TBaseExpression; begin ge:= TFunctionExpression.CreateSimple('G', argument); dge:= TFunctionExpression.CreateSimple('Y', argument); result:= TProductExpression.MakeProduct(ge, dge); end;
Now we can calculate derivatives for expressions with the Gamma function. For the simplest case with input string G(x) we get the expected output string G(x)*Y(x). No surprise here, because we just wrote the code, which produces the output.
But the amazing thing is when we trying to calculate the derivative expression for the Gamma function with a composite argument. As example, for the input string G(x^2+1) it produces the output string (G(x^2+1)*Y(x^2+1))*(2*x) which is totally correct for this case. And the output is correct for all the expressions with the Gamma function. It is because the Analytics library cares about other things, like implementing the chain rule for derivation process.
The source code of the example project is available here.
This blog post has not received any comments yet.
All Blog Posts | Next Post | Previous Post