-
-
Notifications
You must be signed in to change notification settings - Fork 673
Open
Description
A participant in the PREP program noticed that mod is not a symbolic function:
sage: mod(x,4)
ERROR: An unexpected error occurred while tokenizing input
The following traceback may be corrupted or invalid
The error message is: ('EOF in multi-line statement', (4562, 0))
ERROR: An unexpected error occurred while tokenizing input
The following traceback may be corrupted or invalid
The error message is: ('EOF in multi-line statement', (4530, 0))
ERROR: An unexpected error occurred while tokenizing input
The following traceback may be corrupted or invalid
The error message is: ('EOF in multi-line statement', (842, 0))
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
/home/grout/sage-4.5.2/devel/sage-main/sage/functions/<ipython console> in <module>()
/home/grout/sage/local/lib/python2.6/site-packages/sage/rings/finite_rings/integer_mod.so in sage.rings.finite_rings.integer_mod.Mod (sage/rings/finite_rings/integer_mod.c:2633)()
/home/grout/sage/local/lib/python2.6/site-packages/sage/rings/finite_rings/integer_mod.so in sage.rings.finite_rings.integer_mod.IntegerMod (sage/rings/finite_rings/integer_mod.c:2952)()
/home/grout/sage/local/lib/python2.6/site-packages/sage/rings/finite_rings/integer_mod.so in sage.rings.finite_rings.integer_mod.IntegerMod_int.__init__ (sage/rings/finite_rings/integer_mod.c:14249)()
/home/grout/sage/local/lib/python2.6/site-packages/sage/structure/parent.so in sage.structure.parent.Parent.__call__ (sage/structure/parent.c:6407)()
/home/grout/sage/local/lib/python2.6/site-packages/sage/structure/coerce_maps.so in sage.structure.coerce_maps.NamedConvertMap._call_ (sage/structure/coerce_maps.c:4053)()
/home/grout/sage/local/lib/python2.6/site-packages/sage/symbolic/expression.so in sage.symbolic.expression.Expression._integer_ (sage/symbolic/expression.cpp:4026)()
TypeError: unable to convert x (=x) to an integer
Hopefully it should be easy to wrap mod in a symbolic function, something like:
sage: def eval_mod(self, x):
....: if isinstance(x, (int, Integer)):
....: return mod(x,5)
....: return None
....:
sage: f=function('f', eval_func=eval_mod)
sage: f(x)
f(x)
sage: f(13)
3
sage: f(x^2+x+1)
f(x^2 + x + 1)
sage: f(x^2+x+1).subs(x=2)
2
sage: f(x^2+x+1).subs(x=3)
3
sage: f(x^2+x^3).subs(x=1)
2
sage: f(x^2+x^3).subs(x=2)
2
sage: f(x^2+x^3).subs(x=3)
1
See also http://ask.sagemath.org/question/25037/declaring-variable-to-be-in-a-particular-fieldringgroup/
More discussions:
https://groups.google.com/forum/#!searchin/sage-devel/mod|sort:relevance/sage-devel/goNosLk_t9M/xYDgEdIsLYsJ
https://groups.google.com/forum/#!searchin/sage-devel/mod|sort:relevance/sage-devel/g7AdhAyQH-k/O1IGYbNRAQAJ
Component: symbolics
Issue created by migration from https://trac.sagemath.org/ticket/9935