# [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

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;

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

>
> --