using Giac in c++
Modérateur : xcasadmin
using Giac in c++
When programming in c++ using Giac library, how do I create a new real symbolic variable (identifier) and make it constrained to some segment (which in Xcas would be done with 'assume' command)? I need to introduce several constrained variables and then solve a system of nonlinear but rational equations symbolically, with respect to the constraints. As I understand, Giac can do so by computing the Groebner basis. Is it the right way to use the usual function '_solve'?
Re: using Giac in c++
For example gen g("ab");lukamar a écrit :When programming in c++ using Giac library, how do I create a new real symbolic variable (identifier)
and make it constrained to some segment (which in Xcas would be done with 'assume' command)?
Code : Tout sélectionner
intgab.h: bool assume_t_in_ab(const gen & t,const gen & a,const gen & b,bool exclude_a,bool exclude_b,GIAC_CONTEXT);
_solve(makesquence(list_of_equations,list_of_unknowns),contextptr) should indeed do thatI need to introduce several constrained variables and then solve a system of nonlinear but rational equations symbolically, with respect to the constraints. As I understand, Giac can do so by computing the Groebner basis. Is it the right way to use the usual function '_solve'?
Re: using Giac in c++
How to get bounds assumed for a variable most easily? I know about function '_about', but I wonder if there is a more practical function.
Also, I noticed that if I set bounds to a symbol with 'assume_t_in_ab', they're erased after a call to '_solve' with that symbol as one of unknowns. How to make Giac stick to assumption? I need to call '_solve' several times, so now I have to use 'assume_t_in_ab' prior to every call.
Also, I noticed that if I set bounds to a symbol with 'assume_t_in_ab', they're erased after a call to '_solve' with that symbol as one of unknowns. How to make Giac stick to assumption? I need to call '_solve' several times, so now I have to use 'assume_t_in_ab' prior to every call.
Re: using Giac in c++
Perhaps you will find find_range more convenient:lukamar a écrit :How to get bounds assumed for a variable most easily? I know about function '_about', but I wonder if there is a more practical function.
alg_ext.h: int find_range(const gen & g,vecteur & a,GIAC_CONTEXT);
Can you give an example? I tried assume(x>0); then after a call to solve, the assumption on x is kept.Also, I noticed that if I set bounds to a symbol with 'assume_t_in_ab', they're erased after a call to '_solve' with that symbol as one of unknowns. How to make Giac stick to assumption? I need to call '_solve' several times, so now I have to use 'assume_t_in_ab' prior to every call.
Re: using Giac in c++
Yes, you're right. Minimal example works, I've probably overlooked something else.parisse a écrit :Can you give an example? I tried assume(x>0); then after a call to solve, the assumption on x is kept.
But the following may be a bug: when I enter
Code : Tout sélectionner
assume(x>-pi/2 and x<pi/2);solve((x^2-x)/(1+tan(x)^2)=0,x)
Re: using Giac in c++
What is the best way to check that a gen is rational expression (in several variables)? I see that in solve.cc there is a check for rationality in one place, but I fail to understand how it's done.
Re: using Giac in c++
I guess you mean:this code slice:
For each variable in var, It will compute the list of extended variables in eq depending on *it, if the size is != from 1, then eq is not rational w.r.t *it.
By extended variable, I mean x but also sin(x) (since sin(x) is not rational w.r.t. x and can not be reduced further).
Code : Tout sélectionner
// check rational
for (it=var.begin();it!=itend;++it){
if (it->type!=_IDNT) // should not occur!
return vecteur(1,gensizeerr(gettext("Bad var ")+it->print(contextptr)));
vecteur l(rlvarx(eq,*it));
if (l.size()>1)
return vecteur(1,gensizeerr(gen(l).print(contextptr)+gettext(" is not rational w.r.t. ")+it->print(contextptr)));
}
By extended variable, I mean x but also sin(x) (since sin(x) is not rational w.r.t. x and can not be reduced further).
Re: using Giac in c++
Hi again,
what's the difference between 'is_zero' and 'is_exactly_zero' functions? Does the first one return true for numbers small enough? I wonder if I'm using them properly...
what's the difference between 'is_zero' and 'is_exactly_zero' functions? Does the first one return true for numbers small enough? I wonder if I'm using them properly...
Re: using Giac in c++
Yes, that's exactly the difference, is_zero treats numbers smaller than epsilon like 0, unlike is_exactly_zero.
Re: using Giac in c++
Thanks for the clarification. How does is_zero compare with epsilon as it doesn't get a pointer to context?
Re: using Giac in c++
is_zero has a pointer to the context, if you don't pass it, it will use the null context (default parameter).
Re: using Giac in c++
I don't know, valgrind says:
It's probably related to object loading...
Code : Tout sélectionner
==7664== Memcheck, a memory error detector
==7664== Copyright (C) 2002-2011, and GNU GPL'd, by Julian Seward et al.
==7664== Using Valgrind-3.7.0 and LibVEX; rerun with -h for copyright info
==7664== Command: ./a.out
==7664==
==7664== Invalid read of size 1
==7664== at 0x5C312A0: giac::gen::gen(giac::gen const&) (in /usr/lib/libgiac.so.0.0.0)
==7664== by 0x400C54: main (bug.cc:7)
==7664== Address 0x8f460700008 is not stack'd, malloc'd or (recently) free'd
==7664==
=