initializing giac gen in c++

Librairie C++ de calcul formel/ C++ symbolic computation library

Modérateur : xcasadmin

jocaps
Messages : 118
Inscription : lun. avr. 17, 2017 4:32 pm

initializing giac gen in c++

Message par jocaps » dim. sept. 24, 2017 11:12 am

Hi,

I want to try to regularly write giac dependent c++ code. But there are things that confuses me a bit. First, I don't suppose that there is any (official or unofficial) documentation on using the giac c++ library, is there? This is understandable (since I am sure it is a lot of work for the developrs). Second, I have the following situation:

I have a set of precomputed equations (that I can do in xcas or some other computer algebra software) saved in a text file.
To use these in giac (c++) I just initialize the equation as an expression in giac by typing

Code : Tout sélectionner

eqn=giac::gen(str.c_str(),&ct);
where str is of type std::string that I read from the text file and ct is just a giac::context and eqn of type giac::gen.
Now str has several variables like x1,x2,..etc. and I need to sometimes substitute these variables with some numerical value. So it would be nice to have a gen type that represents these variables. Do I have to initialize x1, x2,..etc. using the constructor like in eqn? Because this way of initializing a gen type looks cumbersome. I have seen that one can use std::cin in istream to initialize a gen variable given by a user, so there must be a faster way to initialize gen e.g.

Code : Tout sélectionner

gen a;
a = "x1"; 
(which does not work)

Should the procedure always be creating a string variable and referring to the address of the string variable in the constructor?

Jose

parisse
Messages : 5731
Inscription : mar. déc. 20, 2005 4:02 pm
Contact :

Re: initializing giac gen in c++

Message par parisse » dim. sept. 24, 2017 3:11 pm

There is some developer documentation here: https://www-fourier.ujf-grenoble.fr/~pa ... ac_us.html
You can initialize gen with numeric values without context pointer (for example gen g=1 or gen g(1.2) or gen g(1.2,3.4) for a complex). For strings, there is a command, string2gen(the_string,false).
If you want to create symbolic variables you can create an identifier:
gen x1=identificateur("x1");
For an expression, you must create it with a context pointer. You must also eval the gen otherwise some operators will not be replaced by their equivalents and some commands may fail.
For vectors, the type is vecteur and you can store a vecteur in a gen.

jocaps
Messages : 118
Inscription : lun. avr. 17, 2017 4:32 pm

Re: initializing giac gen in c++

Message par jocaps » lun. sept. 25, 2017 5:32 am

parisse a écrit :There is some developer documentation here: https://www-fourier.ujf-grenoble.fr/~pa ... ac_us.html
You can initialize gen with numeric values without context pointer (for example gen g=1 or gen g(1.2) or gen g(1.2,3.4) for a complex). For strings, there is a command, string2gen(the_string,false).
If you want to create symbolic variables you can create an identifier:
gen x1=identificateur("x1");
For an expression, you must create it with a context pointer. You must also eval the gen otherwise some operators will not be replaced by their equivalents and some commands may fail.
For vectors, the type is vecteur and you can store a vecteur in a gen.
Thanks this is very helpful. I want to clarify for expressions, let's say my expression is saved as a string str then you advise me to do

Code : Tout sélectionner

giac::context ct;
std::string str("x^2+y^2");
giac::gen eqn(str.c_str(),&ct);
eqn = giac::eval(eqn, &ct);
Yes?

parisse
Messages : 5731
Inscription : mar. déc. 20, 2005 4:02 pm
Contact :

Re: initializing giac gen in c++

Message par parisse » lun. sept. 25, 2017 6:03 am

Exactly!

Répondre