On Feb 15, 10:59 am, Simon King <simon.k...@uni-jena.de> wrote:
> On 15 Feb., 16:37, Simon King <simon.k...@uni-jena.de> wrote:
>
> > Yep:
> > sage: a = SR(-1)
> > sage: b = SR(-1/5)
> > sage: sage.rings.arith.gcd(a,b)
> > 1  # or 1/5 with my patch.
>
> No, I was mistaken. Everything can be traced back to g_gcd, which is
> called in sage.symbolic.expression.Expression.gcd. At that point, I
> lost track: I can not find the code of g_gcd (even "grep g_gcd" does
> not give me a hint). In particular, I did not change g_gcd, but it
> seems that my patch had a side effect on it.
>

This is undoubtedly the Ginac gcd.  In libs/ginac/decl.pxi:

    # Algorithms
    GEx g_gcd "gcd"(GEx a, GEx b) except +

So it is using the Ginac gcd, and calling it 'g_gcd'.  And all of that
is in a call

cdef extern from "ginac_wrap.h":

which lives in devel/sage/c_lib/include.    I understand nearly
nothing about headers, but I think that

    py_funcs_struct py_funcs "GiNaC::py_funcs"

means that py_gcd is going to be under this.  Notice that Pynac
headers live in $SAGE_ROOT/local/include/pynac.

Anyway, in Ginac the gcd is defined in numeric.cpp, and if we look at
http://pynac.sagemath.org/hg/file/b233d9dadcfa/ginac/numeric.cpp#l1

we get

 /** Greatest Common Divisor.
  2527    *
  2528    *  @return  The GCD of two numbers if both are integer, a
numerical 1
  2529    *  if they are not. */
  2530   const numeric gcd(const numeric &a, const numeric &b)
  2531   {
  2532     verbose("gcd(a,b)");
  2533     PyObject *aa = Number_T_to_pyobject(a.value), *bb =
Number_T_to_pyobject(b.value);
  2534     PyObject *ans = py_funcs.py_gcd(aa, bb);
  2535     if (!ans) py_error("gcd");
  2536     Py_DECREF(aa); Py_DECREF(bb);
  2537     return ans;
  2538   }

Which means that in fact it does use the Sage GCD as in my earlier
post.  And I think it's probable that it uses this in some way to
decide whether to take out a -1?  I'm sorry I can't help further - the
internals and C++ are beyond me.  I don't know if we want to modify
Ginac to change this, though.

- 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

Reply via email to