Hi All, I'm new to GiNac. Is there a way to execute symbolic differentiation of expressions that includes differential operators ? e.g. suppose an expression ex F = u * dx*u When differentiate that expression F.diff(u) it should result in the expression dx*u - u*dx Regards Kai -- http://echempp.sourceforge.net Kai Ludwig Universität Tübingen Institut für Organische Chemie Auf der Morgenstelle 18 D-72076 Tübingen Tel.: 07071/29-73049 Mail: kai.ludwig@uni-tuebingen.de
Am Freitag, 24. Oktober 2003 10:53 schrieb Kai Ludwig:
Hi All,
I'm new to GiNac. Is there a way to execute symbolic differentiation of expressions that includes differential operators ?
e.g. suppose an expression
ex F = u * dx*u
When differentiate that expression F.diff(u) it should result in the expression
dx*u - u*dx
certainly should be dx*u + u*dx sorry;-) Well - seems to me that I have to write a new function, say dx. Kai -- http://echempp.sourceforge.net Kai Ludwig Universität Tübingen Institut für Organische Chemie Auf der Morgenstelle 18 D-72076 Tübingen Tel.: 07071/29-73049 Mail: kai.ludwig@uni-tuebingen.de
Hi! On Fri, Oct 24, 2003 at 12:59:48PM +0200, Kai Ludwig wrote:
I'm new to GiNac. Is there a way to execute symbolic differentiation of expressions that includes differential operators ?
e.g. suppose an expression
ex F = u * dx*u
When differentiate that expression F.diff(u) it should result in the expression
dx*u + u*dx
I'm still not sure what exactly the rules are that are in effect here, but it seems that "dx" and "u" are noncommutative? diff() requires a symbol as an argument, so the "u" has to be a symbol. GiNaC 1.2 (CVS) has the ability to define noncommutative symbols. This might be a good case for actually testing that feature. :) The "dx" would probably have to be of a newly defined noncommutative class with the same return_type_tinfo as the "u", and an overloaded derivative() member that defines your derivation rules. Bye, Christian -- / Physics is an algorithm \/ http://www.uni-mainz.de/~bauec002/
Hi!
On Fri, Oct 24, 2003 at 12:59:48PM +0200, Kai Ludwig wrote:
I'm new to GiNac. Is there a way to execute symbolic differentiation of expressions that includes differential operators ?
e.g. suppose an expression
ex F = u * dx*u
When differentiate that expression F.diff(u) it should result in the expression
dx*u + u*dx
I'm still not sure what exactly the rules are that are in effect here, but it seems that "dx" and "u" are noncommutative?
Sorry - maybe my question was not precise enough. The shortcut symbol dx means the differential operator d/dx. Applied to a function u gives du/dx. The expression I mentioned comes from functional analysis. F is an operator. I'm asking for an automatic derived expression for the (Frechet-) differential dF/du. I guess, the chain rule (thus, the product rule) also applies to such differentials. Then, dF/du = du/du * du/dx + u * d/du du/dx thus, formally dF/du = du/dx + u * d/dx That's what I meant with dx*u + u*dx ??Kai -- http://echempp.sourceforge.net Kai Ludwig Institut für Organische Chemie Auf der Morgenstelle 18 72076 Tübingen Tel.: 07071/29-73049 Mail: kai.ludwig@uni-tuebingen.de
Hi! On Tue, Nov 18, 2003 at 06:20:30PM +0100, Kai Ludwig wrote:
dF/du = du/du * du/dx + u * d/du du/dx
thus, formally
dF/du = du/dx + u * d/dx
Here's something hacked together that achieves the desired effect for GiNaC 1.2 (treating the dx like a function): const unsigned TINFO_differential = 0x42420001U; DECLARE_FUNCTION_1P(dx) // this is ad-hockery... static ex dx_deriv(const ex & a, unsigned diff_param) { return dx(1); } REGISTER_FUNCTION(dx, derivative_func(dx_deriv). set_return_type(return_types::noncommutative, TINFO_differential)) int main() { symbol u("u", return_types::noncommutative, TINFO_differential); ex F = u * dx(u); cout << F << endl; // "u*dx(u)" cout << F.diff(u) << endl; // "u*dx(1)+dx(u)" } But I don't know if that's general enough for what you have in mind. Bye, Christian -- / Physics is an algorithm \/ http://www.uni-mainz.de/~bauec002/
Christian Bauer wrote:
Hi!
On Tue, Nov 18, 2003 at 06:20:30PM +0100, Kai Ludwig wrote:
dF/du = du/du * du/dx + u * d/du du/dx
thus, formally
dF/du = du/dx + u * d/dx
Here's something hacked together that achieves the desired effect for GiNaC 1.2 (treating the dx like a function):
const unsigned TINFO_differential = 0x42420001U;
DECLARE_FUNCTION_1P(dx)
// this is ad-hockery... static ex dx_deriv(const ex & a, unsigned diff_param) { return dx(1); }
REGISTER_FUNCTION(dx, derivative_func(dx_deriv). set_return_type(return_types::noncommutative, TINFO_differential))
int main() { symbol u("u", return_types::noncommutative, TINFO_differential); ex F = u * dx(u);
cout << F << endl; // "u*dx(u)" cout << F.diff(u) << endl; // "u*dx(1)+dx(u)" }
But I don't know if that's general enough for what you have in mind.
Bye, Christian
Danke ;-) I plan to use GiNaC in a few months within our project... Maybe then I can send you results/questions_hope_not Kai
Hi, Are there any preferences to cite GiNaC in scientific publications ? Kai -- http://echempp.sourceforge.net Kai Ludwig Institut für Organische Chemie Auf der Morgenstelle 18 72076 Tübingen Tel.: 07071/29-73049 Mail: kai.ludwig@uni-tuebingen.de
Hi, there seems to be a problem with the stl set container: int main() { GiNaC::symbol u1( "A" ); GiNaC::symbol u2( "B" ); std::set<GiNaC::symbol> spec; spec.insert(u1); spec.insert(u2); spec.insert(u3); std::set<GiNaC::symbol>::const_iterator s1 = spec.find(u1); // s2 still points to u1 ! std::set<GiNaC::symbol>::const_iterator s2 = spec.find(u2); GiNaC::ex f = pow((*s1),2) + (*s2) + 200*(*s1); std::cout << "f= " << f << std::endl; } Kai -- http://echempp.sourceforge.net Kai Ludwig Institut für Organische Chemie Auf der Morgenstelle 18 72076 Tübingen Tel.: 07071/29-73049 Mail: kai.ludwig@uni-tuebingen.de
Hi! On Fri, 27 Feb 2004, Kai Ludwig wrote:
there seems to be a problem with the stl set container: [...] std::set<GiNaC::symbol> spec; [...]
Please refer to <http://www.ginac.de/FAQ.html#stlcontainers> for a solution to your problem. Regards -richy. -- Richard B. Kreckel <http://www.ginac.de/~kreckel/email.html>
Hi All, Just a simple question - I guess: How can I get the string of a expression ? I saw a get_name() function for symbols but nothing similar for expressions. Kai -- http://echempp.sourceforge.net Kai Ludwig Institut für Organische Chemie Auf der Morgenstelle 18 72076 Tübingen Tel.: 07071/29-73049 Mail: kai.ludwig@uni-tuebingen.de
Hi! On Fri, 27 Feb 2004, Kai Ludwig wrote:
How can I get the string of a expression ? I saw a get_name() function for symbols but nothing similar for expressions.
#include<iostream> #include<sstream> #include<ginac/ginac.h> using namespace std; using namespace GiNaC; int main() { symbol x("x"); symbol y("y"); ex f=x*y; ostringstream o; o << f; string s=o.str(); cout << s << endl; return 0; } Bye, Chris Dams
participants (4)
-
Chris Dams
-
Christian Bauer
-
Kai Ludwig
-
Richard B. Kreckel