[GiNaC-list] Undefine the predefined numeric consant 'I'?
Warren Weckesser
warren.weckesser at gmail.com
Sun Nov 3 03:07:07 CET 2019
On 11/2/19, Vladimir V. Kisil <kisilv at maths.leeds.ac.uk> wrote:
>>>>>> On Fri, 1 Nov 2019 18:19:44 -0400, Warren Weckesser
>>>>>> <warren.weckesser at gmail.com> said:
>
> WW> Is there an easy way to undefine the predefined numeric value
> WW> 'I'? If I define a symbol 'I', use it in an expression, and
> WW> then output that expression to cout after modifying stream with
> WW> csrc, 'I' is converted to 'std::complex<double>(0.0,-1.0)'. I'd
> WW> like the output to be just 'I'.
>
> Would a string substitution be a solution to this?
Not really. The problem is not just the output. Ginac sets 'I' to be
a predefined constant, so the code below prints
e: -3-I*x
de/dI: 0
instead of the desired
e: 3*I^2 - x*I
de/dI: 6*I - x
For now, I'll just disallow the use of 'I' as a user-defined variable.
Warren
-----
#include <iostream>
#include <ginac/ginac.h>
using namespace std;
using namespace GiNaC;
int main(int argc, char *argv[])
{
symbol I("I");
symbol x("x");
symtab table;
table["I"] = I;
table["x"] = x;
parser reader(table);
ex e = reader("3*I*I - x*I");
cout << "e: " << e << endl;
ex de = diff(e, I);
cout << "de/dI: " << de << endl;
return 0;
}
-----
I think for now, the simple rule is "Don't use I". I can add code to
my program that disallows the use of 'I' on input.
Warren
>
> --
> Vladimir V. Kisil http://www.maths.leeds.ac.uk/~kisilv/
> Book: Geometry of Mobius Transformations http://goo.gl/EaG2Vu
> Software: Geometry of cycles http://moebinv.sourceforge.net/
> Jupyter (Colab): https://github.com/vvkisil/MoebInv-notebooks
> Jupyter (CodeOcean): https://codeocean.com/capsule/7952650/tree
> _______________________________________________
> GiNaC-list mailing list
> GiNaC-list at ginac.de
> https://www.cebix.net/mailman/listinfo/ginac-list
>
More information about the GiNaC-list
mailing list