mkoeppe / cutgeneratingfunctionology

Python code for computation and experimentation with cut-generating functions, in particular the Gomory-Johnson infinite group problem. By M. Köppe, Y. Zhou, C.Y. Hong, J. Wang with contributions by undergrad programmers
GNU General Public License v2.0
12 stars 11 forks source link

Replace our coho intervals with RealSet in current sage #7

Open mkoeppe opened 6 years ago

mkoeppe commented 5 years ago

A difficulty: RealSet is currently not compatible with ParametricRealField.

sage: from cutgeneratingfunctionology.dff import *
sage: K.<delta, s> = ParametricRealField([1/5, 2])
INFO: 2019-07-03 13:52:08,623 Initialized ParametricRealField(names = ['delta', 's'], values = [1/5, 2])
sage: RealSet.open(delta, s)
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-3-59b90b78b88f> in <module>()
----> 1 RealSet.open(delta, s)

/Users/mkoeppe/s/sage/sage-rebasing/worktree-algebraic-2018-spring/local/lib/python2.7/site-packages/sage/sets/real_set.pyc in open(lower, upper)
   1116             (0, 1)
   1117         """
-> 1118         lower, upper = RealSet._prep(lower, upper)
   1119         return RealSet(InternalRealInterval(lower, False, upper, False))
   1120 

/Users/mkoeppe/s/sage/sage-rebasing/worktree-algebraic-2018-spring/local/lib/python2.7/site-packages/sage/sets/real_set.pyc in _prep(lower, upper)
   1079             lower = infinity
   1080         else:
-> 1081             lower = RLF(lower)
   1082         if upper is None:
   1083             return lower

/Users/mkoeppe/s/sage/sage-rebasing/worktree-algebraic-2018-spring/local/lib/python2.7/site-packages/sage/structure/parent.pyx in sage.structure.parent.Parent.__call__ (build/cythonized/sage/structure/parent.c:9197)()
    898         if mor is not None:
    899             if no_extra_args:
--> 900                 return mor._call_(x)
    901             else:
    902                 return mor._call_with_args(x, args, kwds)

/Users/mkoeppe/s/sage/sage-rebasing/worktree-algebraic-2018-spring/local/lib/python2.7/site-packages/sage/structure/coerce_maps.pyx in sage.structure.coerce_maps.DefaultConvertMap_unique._call_ (build/cythonized/sage/structure/coerce_maps.c:4549)()
    160                 print(type(C), C)
    161                 print(type(C._element_constructor), C._element_constructor)
--> 162             raise
    163 
    164     cpdef Element _call_with_args(self, x, args=(), kwds={}):

/Users/mkoeppe/s/sage/sage-rebasing/worktree-algebraic-2018-spring/local/lib/python2.7/site-packages/sage/structure/coerce_maps.pyx in sage.structure.coerce_maps.DefaultConvertMap_unique._call_ (build/cythonized/sage/structure/coerce_maps.c:4441)()
    155         cdef Parent C = self._codomain
    156         try:
--> 157             return C._element_constructor(x)
    158         except Exception:
    159             if print_warnings:

/Users/mkoeppe/s/sage/sage-rebasing/worktree-algebraic-2018-spring/local/lib/python2.7/site-packages/sage/categories/sets_cat.pyc in _element_constructor_from_element_class(self, *args, **keywords)
    992                 <class 'sage.categories.examples.sets_cat.PrimeNumbers_Inherits_with_category.element_class'>
    993             """
--> 994             return self.element_class(self, *args, **keywords)
    995 
    996         def is_parent_of(self, element):

/Users/mkoeppe/s/sage/sage-rebasing/worktree-algebraic-2018-spring/local/lib/python2.7/site-packages/sage/rings/real_lazy.pyx in sage.rings.real_lazy.LazyWrapper.__init__ (build/cythonized/sage/rings/real_lazy.c:11098)()
    944         self._value = value
    945         if check:
--> 946             self._parent.interval_field()(value)
    947 
    948     def __neg__(self):

/Users/mkoeppe/s/sage/sage-rebasing/worktree-algebraic-2018-spring/local/lib/python2.7/site-packages/sage/rings/real_mpfi.pyx in sage.rings.real_mpfi.RealIntervalField_class.__call__ (build/cythonized/sage/rings/real_mpfi.c:5998)()
    700         if kwds:
    701             return self.element_class(self, x, **kwds)
--> 702         return Parent.__call__(self, x)
    703 
    704     def algebraic_closure(self):

/Users/mkoeppe/s/sage/sage-rebasing/worktree-algebraic-2018-spring/local/lib/python2.7/site-packages/sage/structure/parent.pyx in sage.structure.parent.Parent.__call__ (build/cythonized/sage/structure/parent.c:9197)()
    898         if mor is not None:
    899             if no_extra_args:
--> 900                 return mor._call_(x)
    901             else:
    902                 return mor._call_with_args(x, args, kwds)

/Users/mkoeppe/s/sage/sage-rebasing/worktree-algebraic-2018-spring/local/lib/python2.7/site-packages/sage/structure/coerce_maps.pyx in sage.structure.coerce_maps.DefaultConvertMap_unique._call_ (build/cythonized/sage/structure/coerce_maps.c:4549)()
    160                 print(type(C), C)
    161                 print(type(C._element_constructor), C._element_constructor)
--> 162             raise
    163 
    164     cpdef Element _call_with_args(self, x, args=(), kwds={}):

/Users/mkoeppe/s/sage/sage-rebasing/worktree-algebraic-2018-spring/local/lib/python2.7/site-packages/sage/structure/coerce_maps.pyx in sage.structure.coerce_maps.DefaultConvertMap_unique._call_ (build/cythonized/sage/structure/coerce_maps.c:4441)()
    155         cdef Parent C = self._codomain
    156         try:
--> 157             return C._element_constructor(x)
    158         except Exception:
    159             if print_warnings:

/Users/mkoeppe/s/sage/sage-rebasing/worktree-algebraic-2018-spring/local/lib/python2.7/site-packages/sage/categories/sets_cat.pyc in _element_constructor_from_element_class(self, *args, **keywords)
    992                 <class 'sage.categories.examples.sets_cat.PrimeNumbers_Inherits_with_category.element_class'>
    993             """
--> 994             return self.element_class(self, *args, **keywords)
    995 
    996         def is_parent_of(self, element):

/Users/mkoeppe/s/sage/sage-rebasing/worktree-algebraic-2018-spring/local/lib/python2.7/site-packages/sage/rings/real_mpfi.pyx in sage.rings.real_mpfi.RealIntervalFieldElement.__init__ (build/cythonized/sage/rings/real_mpfi.c:9331)()
   1246             mpfi_set_ui(self.value, 0)
   1247         else:
-> 1248             mpfi_set_sage(self.value, NULL, x, parent, base)
   1249 
   1250     def __reduce__(self):

/Users/mkoeppe/s/sage/sage-rebasing/worktree-algebraic-2018-spring/local/lib/python2.7/site-packages/sage/rings/convert/mpfi.pyx in sage.rings.convert.mpfi.mpfi_set_sage (build/cythonized/sage/rings/convert/mpfi.c:5512)()
    208 
    209     # Finally, try converting via the corresponding RealField
--> 210     mpfi_set_via_RR(re, x, field)
    211     return return_real(im)
    212 

/Users/mkoeppe/s/sage/sage-rebasing/worktree-algebraic-2018-spring/local/lib/python2.7/site-packages/sage/rings/convert/mpfi.pyx in sage.rings.convert.mpfi.mpfi_set_via_RR (build/cythonized/sage/rings/convert/mpfi.c:6362)()
    290         rb = RIF.__upper_field(x)
    291     except TypeError:
--> 292         raise TypeError(f"unable to convert {x!r} to real interval")
    293     mpfi_interv_fr(re, (<RealNumber>ra).value, (<RealNumber>rb).value)

TypeError: unable to convert (delta)~ to real interval
mkoeppe commented 4 years ago

A difficulty: RealSet is currently not compatible with ParametricRealField.

Fixed in 597c18fe4d2fbbada73dff7e48b37854ea506377

mkoeppe commented 4 years ago

It will certainly need benchmarking.