Commit 9052f6f0 authored by Frederic HAN's avatar Frederic HAN
Browse files

add evaluation in * and / and remove it in __call__ args

parent e12da877
......@@ -358,3 +358,5 @@ Changelog
+ Fixes some try/sig_on positions due to some giac errors returned.
- 0.4.8:
+ Fixes to build with sage 6.8
- 0.4.9:
+ Fix a sig_on() pb in Pygen __iter__
......@@ -12,8 +12,8 @@ from libcpp.string cimport string
cdef extern from "giac/giac.h" namespace "giac":
cdef cppclass context:
context()
context()
cdef struct ref_mpz_t:
pass
cdef struct ref_real_object:
......@@ -67,13 +67,13 @@ cdef extern from "giac/giac.h" namespace "giac":
gen(void *ptr,short int subt) except +
gen(gen ) except +
gen (vecteur & v,short int s) except +
gen (ref_vecteur * vptr,short int s) except +
gen (ref_vecteur * vptr,short int s) except +
mpz_t * ref_ZINTptr() except +
gen * ref_MODptr() except +
#
unsigned char type
unsigned char type
signed char subtype
# (the meaning of types from dispatch.h)
# // immediate type (without mem allocation) should be < _ZINT
......@@ -118,7 +118,7 @@ cdef extern from "giac/giac.h" namespace "giac":
ref_algext * __EXTptr # 2 gens for alg. extension (type ext)
# alg ext: 1st gen is a std::vector or a fraction, 2nd gen is
# a/ a std::vector, the minimal monic polynomial (the roots are permutable)
# b/ a real_complex_rootof given by it's min poly and
# b/ a real_complex_rootof given by it's min poly and
# c/ another type meaning that the root is expressed in terms
# of another rootof, in this case ext_reduce should be called
# For 2nd order extension, X^2=d is used if d!=1 mod 4
......@@ -137,18 +137,18 @@ cdef extern from "giac/giac.h" namespace "giac":
ref_grob * __GROBptr
ref_void_pointer * __POINTERptr
#operators
#operators
gen operator[](int i) except +
gen operator[](gen & i) except +
gen operator()(gen & i,context * contextptr) except +
gen operator()(gen & i,gen & progname,context * contextptr) except +
gen operator+(gen & b) except +
gen operator-(gen & b) except +
gen operator*(gen & b) except +
gen operator/(gen & b) except +
gen GIAC_rdiv "rdiv"(gen & a,gen & b) except + # rational division
gen GIAC_eval "eval" (gen &,int , context *) except +
gen GIAC_protecteval "protecteval" (gen , int, context *) except +
......@@ -184,12 +184,11 @@ cdef extern from "misc.h":
int giacgenrichcmp( gen & , gen & , int, context *) except +
#NB: we use the following multiplication otherwise some giac errors make python quit:
#l=giac([1,2]); l.tranpose()*l
gen GIAC_giacmul "giacmul"( gen & , gen & , context *) except +
gen GIAC_giacmod "giacmod"( gen & , gen & , context *) except +
gen GIAC_giacmul "giacmul"( gen & , gen & , context *) except +
gen GIAC_giacdiv "giacdiv"( gen & , gen & , context *) except +
gen GIAC_giacmod "giacmod"( gen & , gen & , context *) except +
#
string browser_help(gen & , int lang) except +
void GIAC_archive "archivegen"( string , gen & , context *) except +
gen GIAC_unarchive "unarchivegen"( string , context *) except +
......@@ -1040,7 +1040,7 @@ cdef class Pygen:
sage: t=clock();l1=[ i+1 for i in l ];t4=clock()-t;"time for a list of 10^6 i+1 ",t4 # doctest: +ELLIPSIS
('time for a list of 10^6 i+1 ', ...)
sage: L=libgiac(range(10))
sage: iter(L).next() # test sig_on_count() Pb with 0.4.8
sage: iter(L).next() # test trac 18841
0
"""
......@@ -1081,8 +1081,6 @@ cdef class Pygen:
def __call__(self, *args):
"""
sage: from giacpy import libgiac
sage: (sqrt(3)/libgiac('x')).factor() # BUGFIX could give 0
sqrt(3)/x
"""
cdef gen result
n=len(args)
......@@ -1101,12 +1099,7 @@ cdef class Pygen:
# it may have left the giac pari locked.
sig_on()
try:
# initialisation of some symbols in a gen ( such as sqrt)
# needs evalutation to get rid of an internal giac format
# Ex: ('sqrt(3)'/libgiac('x')).factor()
# could answer 0 without the following evaluation
result= GIAC_eval((<Pygen>right).gptr[0],<int>1,context_ptr)
result= ((<Pygen>self).gptr[0])(result,context_ptr)
result= ((<Pygen>self).gptr[0])((<Pygen>right).gptr[0],context_ptr)
sig_off()
return _wrap_gen(result)
except:
......@@ -1145,6 +1138,13 @@ cdef class Pygen:
raise RuntimeError
def __mul__(self, right):
"""
sage: from giacpy import libgiac
sage: (sqrt(5)*libgiac('x')).factor() # BUG test could give 0
sqrt(5)*x
sage: (libgiac('x')*sqrt(5)).factor()
sqrt(5)*x
"""
cdef gen result
if isinstance(right,Pygen)==False:
right=Pygen(right)
......@@ -1165,6 +1165,13 @@ cdef class Pygen:
#PB / in python3 is truediv
def __div__(self, right):
"""
sage: from giacpy import libgiac
sage: (sqrt(3)/libgiac('x')).factor() # BUG test could give 0
sqrt(3)/x
sage: (libgiac('x')/sqrt(3)).factor()
sqrt(3)*x/3
"""
cdef gen result
if isinstance(right,Pygen)==False:
right=Pygen(right)
......@@ -1173,8 +1180,7 @@ cdef class Pygen:
try:
sig_on()
#result= GIAC_giacdiv((<Pygen>self).gptr[0] , (<Pygen>right).gptr[0],context_ptr)
result= (<Pygen>self).gptr[0] / (<Pygen>right).gptr[0]
result= GIAC_giacdiv((<Pygen>self).gptr[0] , (<Pygen>right).gptr[0],context_ptr)
sig_off()
return _wrap_gen(result)
except:
......
......@@ -55,7 +55,11 @@ int giacgenrichcmp(gen & a, gen & b, int op, const context * context_ptr){
}
gen giacmul(gen & a, gen & b, const context * context_ptr){
return a*b;
return eval(a*b,context_ptr);
}
gen giacdiv(gen & a, gen & b, const context * context_ptr){
return eval(a/b,context_ptr);
}
gen giacmod(gen & a, gen & b, const context * context_ptr){
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment