Hi folks, I like the floor function that is automatically loaded during each terminal session. And I think it's the function sage.calculus.calculus.Function_floor. I'm trying to use that function in the patch up at #5827. In that patch, I implemented a module called "sage/crypto/knapsack" with only the class "Superincreasing" at the moment. In the method "_largest_less_than" of that class, I've imported the above floor function by doing
from sage.calculus.calculus import Function_floor as floor at the beginning of the method. However, when it comes to using the said method, I received this error *** begin Sage transcript *** sage: L = [2, 3, 7, 25, 67, 179, 356, 819] sage: Superincreasing(L)._largest_less_than(207) --------------------------------------------------------------------------- TypeError Traceback (most recent call last) /home/mvngu/.sage/temp/mod.math.washington.edu/9866/_home_mvngu__sage_init_sage_0.py in <module>() /scratch/mvngu/sage-3.4.1.rc3/local/lib/python2.5/site-packages/sage/crypto/knapsack.pyc in _largest_less_than(self, N) 167 high = len(self._seq) - 1 168 while low <= high: --> 169 mid = Integer(floor((low + high) / 2)) 170 if N == self._seq[mid]: 171 return self._seq[mid] /scratch/mvngu/sage-3.4.1.rc3/local/lib/python2.5/site-packages/sage/rings/integer.so in sage.rings.integer.Integer.__init__ (sage/rings/integer.c:6484)() /scratch/mvngu/sage-3.4.1.rc3/local/lib/python2.5/site-packages/sage/calculus/calculus.pyc in _integer_(self, ZZ) 1769 -3 1770 """ -> 1771 return Integer(repr(self)) 1772 1773 def _add_(self, right): /scratch/mvngu/sage-3.4.1.rc3/local/lib/python2.5/site-packages/sage/rings/integer.so in sage.rings.integer.Integer.__init__ (sage/rings/integer.c:6446)() TypeError: unable to convert x (=floor) to an integer *** end Sage transcript *** To get around the problem, I changed the import statement from sage.calculus.calculus import Function_floor as floor to from math import floor But this floor function can return a floating point number, so I would need to coerce its result to type Integer. Did I miss any other import statements to make sage.calculus.calculus import Function_floor return a result of type integer? -- Regards Minh Van Nguyen --~--~---------~--~----~------------~-------~--~----~ To post to this group, send email to sage-devel@googlegroups.com To unsubscribe from this group, send email to sage-devel-unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/sage-devel URLs: http://www.sagemath.org -~----------~----~----~----~------~----~------~--~---