You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
def floor_sum(n, m, a, b, x=0): # calc sum_{i=0}^{n-1} floor((ai + b) / m)
while n!=0:(s,m),(t,u),a=divmod(a,m),divmod(b,m),m;x+=(n*n-n)//2*s+n*t;n,b=divmod(m*n+u,a)
return x
print(floor_sum(2**64,1,3,0))
print(floor_sum(2**64,1,355/113,0))
print(floor_sum(2**64,1,sqrt(10),0))
def floor_sum(n, m, a, b, x=0): # calc sum_{i=0}^{n-1} floor((ai + b) / m)
while n!=0:(s,m),(t,u),a=divmod(a,m),divmod(b,m),m;x+=(n*n-n)//2*s+n*t;n,b=divmod(m*n+u,a)
return x
import sympy
print(floor_sum(2**64,1,3,0))
print(floor_sum(2**64,1,sympy.Rational(355,113),0))
print(floor_sum(2**64,1,sympy.sqrt(10),0))
def floor_sum(n, m, a, b, x=0): # calc sum_{i=0}^{n-1} floor((ai + b) / m)
while n!=0:(s,m),(t,u),a=divmod(a,m),divmod(b,m),m;x+=(n*n-n)//2*s+n*t;n,b=divmod(m*n+u,a)
return x
print(floor_sum(2**64,1,3,0))
print(floor_sum(2**64,1,355/113,0))
print(floor_sum(2**64,1,sqrt(10),0))
output:
510423550381407695167391795037087989760
60400120128466577261474695746055412121600/113
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
File /home/sc_serv/sage/src/sage/structure/element.pyx:1871, in sage.structure.element.Element._floordiv_()
1870 try:
-> 1871 python_op = (<object>self)._floordiv_
1872 except AttributeError:
File /home/sc_serv/sage/src/sage/structure/element.pyx:489, in sage.structure.element.Element.__getattr__()
488 """
--> 489 return self.getattr_from_category(name)
490
File /home/sc_serv/sage/src/sage/structure/element.pyx:502, in sage.structure.element.Element.getattr_from_category()
501 cls = P._abstract_element_class
--> 502 return getattr_from_other_class(self, cls, name)
503
File /home/sc_serv/sage/src/sage/cpython/getattr.pyx:362, in sage.cpython.getattr.getattr_from_other_class()
361 dummy_error_message.name = name
--> 362 raise AttributeError(dummy_error_message)
363 attribute = <object>attr
AttributeError: 'sage.symbolic.ring.SymbolicRing' object has no attribute '_SageObject__custom_name'
During handling of the above exception, another exception occurred:
TypeError Traceback (most recent call last)
Cell In [1], line 7
5 print(floor_sum(Integer(2)**Integer(64),Integer(1),Integer(3),Integer(0)))
6 print(floor_sum(Integer(2)**Integer(64),Integer(1),Integer(355)/Integer(113),Integer(0)))
----> 7 print(floor_sum(Integer(2)**Integer(64),Integer(1),sqrt(Integer(10)),Integer(0)))
Cell In [1], line 2, in floor_sum(n, m, a, b, x)
1 def floor_sum(n, m, a, b, x=Integer(0)): # calc sum_{i=0}^{n-1} floor((ai + b) / m)
----> 2 while n!=Integer(0):(s,m),(t,u),a=divmod(a,m),divmod(b,m),m;x+=(n*n-n)//Integer(2)*s+n*t;n,b=divmod(m*n+u,a)
3 return x
File /home/sc_serv/sage/src/sage/structure/element.pyx:2822, in sage.structure.element.RingElement.__divmod__()
2820 except (AttributeError, NotImplementedError):
2821 pass
-> 2822 return (self // other, self % other)
2823
2824 def __invert__(self):
File /home/sc_serv/sage/src/sage/structure/element.pyx:1840, in sage.structure.element.Element.__floordiv__()
1838 return (<Element>left)._floordiv_(right)
1839 if BOTH_ARE_ELEMENT(cl):
-> 1840 return coercion_model.bin_op(left, right, floordiv)
1841
1842 try:
File /home/sc_serv/sage/src/sage/structure/coerce.pyx:1232, in sage.structure.coerce.CoercionModel.bin_op()
1230 self._record_exception()
1231 else:
-> 1232 return PyObject_CallObject(op, xy)
1233
1234 if op is mul:
File /home/sc_serv/sage/src/sage/structure/element.pyx:1838, in sage.structure.element.Element.__floordiv__()
1836 cdef int cl = classify_elements(left, right)
1837 if HAVE_SAME_PARENT(cl):
-> 1838 return (<Element>left)._floordiv_(right)
1839 if BOTH_ARE_ELEMENT(cl):
1840 return coercion_model.bin_op(left, right, floordiv)
File /home/sc_serv/sage/src/sage/structure/element.pyx:1873, in sage.structure.element.Element._floordiv_()
1871 python_op = (<object>self)._floordiv_
1872 except AttributeError:
-> 1873 raise bin_op_exception('//', self, other)
1874 else:
1875 return python_op(other)
TypeError: unsupported operand parent(s) for //: 'Symbolic Ring' and 'Symbolic Ring'
Steps To Reproduce
Expected Behavior
operator.floordiv(a,b) == floor(a/b)
(operator.floordiv
same as//
operator)operator.mod(a,b) == a - floor(a/b)*b
(operator.mod
same as%
operator)divmod(a,b) == (operator.floordiv(a,b), operator.mod(a,b))
example code:
example code for Sympy:
output:
example code 2:
output:
Actual Behavior
operator.floordiv(a,b) != floor(a/b)
(operator.floordiv
same as//
operator)operator.mod(a,b) != a - floor(a/b)*b
(operator.mod
same as%
operator)divmod(a,b) != (operator.floordiv(a,b), operator.mod(a,b))
example code:
output:
example code 2:
output:
Additional Information
sage/src/sage/structure/element.pyx
Lines 1774 to 1872 in 79c047c
sage/src/sage/structure/element.pyx
Lines 1874 to 1972 in 79c047c
sage/src/sage/structure/element.pyx
Lines 2773 to 2837 in 79c047c
Environment
Checklist
The text was updated successfully, but these errors were encountered: