On Feb 15, 9:50 am, Simon King <simon.k...@uni-jena.de> wrote: > Hi! > > Working on #10771 (making gcd and lcm work nicer), I got trouble with > the multiplication of symbolic expressions. The problem seems to boil > down to examples of the following type: > > Without the patch > sage: x = -sqrt(2)-1/5*I > sage: x*x > 1/25*(5*sqrt(2) + I)^2 > > With the patch > sage: x = -sqrt(2)-1/5*I > sage: x*x > 1/25*(-5*sqrt(2) - I)^2 > > In another multiplication example, the patch even results in a > segmentation fault: > sage: F(x) = 1/sqrt(2*pi*1^2)*exp(-1/(2*1^2)*(x-0)^2) > sage: G(x) = 1/sqrt(2*pi*n(1)^2)*exp(-1/(2*n(1)^2)*(x-n(0))^2) > sage: (F-G)**2 > /mnt/local/king/SAGE/sage-4.6.2.alpha4/local/bin/sage-sage: Zeile 300: > 19386 Speicherzugriffsfehler sage-ipython "$@" -i > > The first example seems to indicate that my gcd/lcm patch changes a > sign when pulling a common factor out of a list of symbolic > coefficients. The second example is totally obscure to me. > > I could trac down the code up to a call to new_Expression_from_GEx. > But I have not been able to locate the definition of that function. > > To symbolists: > Please tell me whether (and how) gcd or lcm occur in > new_Expression_from_GEx, or at least show me the code!
This is just the standard thing that makes a Ginac/Pynac expression. I can never remember where/if this is defined, either. At any rate, that is not where the problem is - it must be in how it finds a canonical form of the expression. > What gcd/lcm would be computed in the two examples above, and what is > the expected result? The post-Pynac symbolics are a little weird. Burcin explained it to me this way: 1) Sage creates a symbolic object. 2) Pynac/Ginac makes it. 3) But we don't have Ginac's underlying engine for numbers any more (CLN), so it uses Sage itself for certain things. Hence in symbolic/pynac.pyx we have the following: ################################################################# # GCD ################################################################# import sage.rings.arith cdef public object py_gcd(object n, object k) except +: if PY_TYPE_CHECK(n, Integer) and PY_TYPE_CHECK(k, Integer): if mpz_cmp_si((<Integer>n).value,1) == 0: return n elif mpz_cmp_si((<Integer>k).value,1) == 0: return k return n.gcd(k) if PY_TYPE_CHECK_EXACT(n, Rational) and PY_TYPE_CHECK_EXACT(k, Rational): return n.content(k) try: return sage.rings.arith.gcd(n,k) except (TypeError, ValueError, AttributeError): # some strange meaning in case of weird things with no usual lcm. return 1 So this is what Pynac actually does to get a gcd, I think. If not, then the following remark on the Pynac to-do webpage is relevant (originally from William): Maybe change SAGE's Ginac to make a call to a cython gcd function, then use singular, since singular's gcd over QQ is much better than ginac's, I think, and ginac *only* does GCD over QQ. Actually, just make everything in normal.cpp be implemented via Singular, probably... I hope this helps you track it down. I suspect you are right about what is going on. - kcrisman -- To post to this group, send an email to sage-devel@googlegroups.com To unsubscribe from this group, send an email to sage-devel+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/sage-devel URL: http://www.sagemath.org