Opened 2 years ago

Last modified 3 months ago

#29961 new defect

random symbolic expression is completely unstable

Reported by: gh-kliem Owned by:
Priority: critical Milestone: sage-9.7
Component: symbolics Keywords: random expression
Cc: Merged in:
Authors: Reviewers:
Report Upstream: N/A Work issues:
Branch: Commit:
Dependencies: Stopgaps:

Status badges

Description

sage.symbolic.random_tests.random_expr is completely unstable.

This breaks a doctest in sage.symbolic.expression_conversions.ExpressionTreeWalker.__init__ when fuzzing the doctests.

Traceback below.

Attachments (1)

crash_kvq1b27w.log (23.4 KB) - added by gh-kliem 15 months ago.
random_expr crashing

Download all attachments as: .zip

Change History (9)

comment:1 Changed 2 years ago by gh-kliem

sage: from sage.symbolic.random_tests import random_expr
sage: foo = random_expr(20, nvars=2)
sage: foo = random_expr(20, nvars=2)
sage: foo = random_expr(20, nvars=2)
sage: set_random_seed(151058820726654196682836430928254760259)
sage: foo = random_expr(20, nvars=2)
sage: foo = random_expr(20, nvars=2)
---------------------------------------------------------------------------
RuntimeError                              Traceback (most recent call last)
/home/jonathan/Applications/sage/local/lib/python3.7/site-packages/sage/interfaces/interface.py in __init__(self, parent, value, is_name, name)
    717             try:
--> 718                 self._name = parent._create(value, name=name)
    719             except (TypeError, RuntimeError, ValueError) as x:

/home/jonathan/Applications/sage/local/lib/python3.7/site-packages/sage/interfaces/maxima_lib.py in _create(self, value, name)
    604             else:
--> 605                 self.set(name, value)
    606         except RuntimeError as error:

/home/jonathan/Applications/sage/local/lib/python3.7/site-packages/sage/interfaces/maxima_lib.py in set(self, var, value)
    513         cmd = '%s : %s$'%(var, value.rstrip(';'))
--> 514         self.eval(cmd)
    515 

/home/jonathan/Applications/sage/local/lib/python3.7/site-packages/sage/interfaces/maxima_lib.py in _eval_line(self, line, locals, reformat, **kwds)
    459                 if statement:
--> 460                     maxima_eval("#$%s$" % statement)
    461         if not reformat:

/home/jonathan/Applications/sage/local/lib/python3.7/site-packages/sage/libs/ecl.pyx in sage.libs.ecl.EclObject.__call__ (build/cythonized/sage/libs/ecl.c:7791)()
    804         lispargs = EclObject(list(args))
--> 805         return ecl_wrap(ecl_safe_apply(self.obj,(<EclObject>lispargs).obj))
    806 

/home/jonathan/Applications/sage/local/lib/python3.7/site-packages/sage/libs/ecl.pyx in sage.libs.ecl.ecl_safe_apply (build/cythonized/sage/libs/ecl.c:5453)()
    376         s = si_coerce_to_base_string(ecl_values(1))
--> 377         raise RuntimeError("ECL says: {}".format(
    378             char_to_str(ecl_base_string_pointer_safe(s))))

RuntimeError: ECL says: Error executing code in Maxima: 

During handling of the above exception, another exception occurred:

TypeError                                 Traceback (most recent call last)
<ipython-input-9-d588645d6f2a> in <module>()
----> 1 foo = random_expr(Integer(20), nvars=Integer(2))

/home/jonathan/Applications/sage/local/lib/python3.7/site-packages/sage/symbolic/random_tests.py in random_expr(size, nvars, ncoeffs, var_frac, internal, nullary, nullary_frac, coeff_generator, verbose)
    286     internal = normalize_prob_list(internal)
    287 
--> 288     return random_expr_helper(size, internal, leaves, verbose)
    289 
    290 

/home/jonathan/Applications/sage/local/lib/python3.7/site-packages/sage/symbolic/random_tests.py in random_expr_helper(n_nodes, internal, leaves, verbose)
    231         if verbose:
    232             print("About to apply %r to %r" % (r[1], children))
--> 233         return r[1](*children)
    234 
    235 def random_expr(size, nvars=1, ncoeffs=None, var_frac=0.5,

/home/jonathan/Applications/sage/local/lib/python3.7/site-packages/sage/symbolic/function.pyx in sage.symbolic.function.BuiltinFunction.__call__ (build/cythonized/sage/symbolic/function.cpp:12269)()
   1136             res = self._evalf_try_(*args)
   1137             if res is None:
-> 1138                 res = super(BuiltinFunction, self).__call__(
   1139                         *args, coerce=coerce, hold=hold)
   1140 

/home/jonathan/Applications/sage/local/lib/python3.7/site-packages/sage/symbolic/function.pyx in sage.symbolic.function.Function.__call__ (build/cythonized/sage/symbolic/function.cpp:7046)()
    600                     (<Expression>args[0])._gobj, hold)
    601         elif self._nargs == 2:
--> 602             res = g_function_eval2(self._serial, (<Expression>args[0])._gobj,
    603                     (<Expression>args[1])._gobj, hold)
    604         elif self._nargs == 3:

/home/jonathan/Applications/sage/local/lib/python3.7/site-packages/sage/symbolic/function.pyx in sage.symbolic.function.BuiltinFunction._evalf_or_eval_ (build/cythonized/sage/symbolic/function.cpp:13419)()
   1224         res = self._evalf_try_(*args)
   1225         if res is None:
-> 1226             return self._eval0_(*args)
   1227         else:
   1228             return res

/home/jonathan/Applications/sage/local/lib/python3.7/site-packages/sage/functions/orthogonal_polys.py in _eval_(self, n, x, *args, **kwds)
   1241             Infinity
   1242         """
-> 1243         ret = self._eval_special_values_(n, x)
   1244         if ret is not None:
   1245             return ret

/home/jonathan/Applications/sage/local/lib/python3.7/site-packages/sage/functions/orthogonal_polys.py in _eval_special_values_(self, n, x)
   1269             return elliptic_kc((x+1)/2)
   1270 
-> 1271         if x == 1:
   1272             from sage.rings.infinity import unsigned_infinity
   1273             return SR(unsigned_infinity)

/home/jonathan/Applications/sage/local/lib/python3.7/site-packages/sage/symbolic/expression.pyx in sage.symbolic.expression.Expression.__nonzero__ (build/cythonized/sage/symbolic/expression.cpp:19537)()
   3126             # lot of basic Sage objects can't be put into maxima.
   3127             from sage.symbolic.relation import test_relation_maxima
-> 3128             return test_relation_maxima(self)
   3129 
   3130         self_is_zero = self._gobj.is_zero()

/home/jonathan/Applications/sage/local/lib/python3.7/site-packages/sage/symbolic/relation.py in test_relation_maxima(relation)
    489         [k is noninteger]
    490     """
--> 491     m = relation._maxima_()
    492 
    493     #Handle some basic cases first

/home/jonathan/Applications/sage/local/lib/python3.7/site-packages/sage/symbolic/expression.pyx in sage.symbolic.expression.Expression._maxima_ (build/cythonized/sage/symbolic/expression.cpp:7813)()
   1004             # Maybe not such a great idea because the "default" interface is another one
   1005             from sage.calculus.calculus import maxima
-> 1006             return super(Expression, self)._interface_(maxima)
   1007         else:
   1008             return super(Expression, self)._interface_(session)

/home/jonathan/Applications/sage/local/lib/python3.7/site-packages/sage/structure/sage_object.pyx in sage.structure.sage_object.SageObject._interface_ (build/cythonized/sage/structure/sage_object.c:5600)()
    682             except Exception:
    683                 raise NotImplementedError("coercion of object %s to %s not implemented:\n%s\n%s" % (repr(self), I))
--> 684         X = I(s)
    685         if c:
    686             try:

/home/jonathan/Applications/sage/local/lib/python3.7/site-packages/sage/misc/lazy_import.pyx in sage.misc.lazy_import.LazyImport.__call__ (build/cythonized/sage/misc/lazy_import.c:3681)()
    351             True
    352         """
--> 353         return self.get_object()(*args, **kwds)
    354 
    355     def __repr__(self):

/home/jonathan/Applications/sage/local/lib/python3.7/site-packages/sage/interfaces/interface.py in __call__(self, x, name)
    294 
    295         if isinstance(x, str):
--> 296             return cls(self, x, name=name)
    297         try:
    298             # Special methods do not and should not have an option to

/home/jonathan/Applications/sage/local/lib/python3.7/site-packages/sage/interfaces/interface.py in __init__(self, parent, value, is_name, name)
    718                 self._name = parent._create(value, name=name)
    719             except (TypeError, RuntimeError, ValueError) as x:
--> 720                 raise TypeError(x)
    721 
    722     def _latex_(self):

TypeError: ECL says: Error executing code in Maxima: 
sage: foo = random_expr(20, nvars=2)
sage: foo = random_expr(20, nvars=2)
sage: foo = random_expr(20, nvars=2)
sage: foo = random_expr(20, nvars=2)
sage: foo = random_expr(20, nvars=2)
sage: foo = random_expr(20, nvars=2)
sage: foo = random_expr(20, nvars=2)
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-16-d588645d6f2a> in <module>()
----> 1 foo = random_expr(Integer(20), nvars=Integer(2))

/home/jonathan/Applications/sage/local/lib/python3.7/site-packages/sage/symbolic/random_tests.py in random_expr(size, nvars, ncoeffs, var_frac, internal, nullary, nullary_frac, coeff_generator, verbose)
    286     internal = normalize_prob_list(internal)
    287 
--> 288     return random_expr_helper(size, internal, leaves, verbose)
    289 
    290 

/home/jonathan/Applications/sage/local/lib/python3.7/site-packages/sage/symbolic/random_tests.py in random_expr_helper(n_nodes, internal, leaves, verbose)
    228             n_spare_nodes = 0
    229         nodes_per_child = random_integer_vector(n_spare_nodes, n_children)
--> 230         children = [random_expr_helper(n+1, internal, leaves, verbose) for n in nodes_per_child]
    231         if verbose:
    232             print("About to apply %r to %r" % (r[1], children))

/home/jonathan/Applications/sage/local/lib/python3.7/site-packages/sage/symbolic/random_tests.py in <listcomp>(.0)
    228             n_spare_nodes = 0
    229         nodes_per_child = random_integer_vector(n_spare_nodes, n_children)
--> 230         children = [random_expr_helper(n+1, internal, leaves, verbose) for n in nodes_per_child]
    231         if verbose:
    232             print("About to apply %r to %r" % (r[1], children))

/home/jonathan/Applications/sage/local/lib/python3.7/site-packages/sage/symbolic/random_tests.py in random_expr_helper(n_nodes, internal, leaves, verbose)
    228             n_spare_nodes = 0
    229         nodes_per_child = random_integer_vector(n_spare_nodes, n_children)
--> 230         children = [random_expr_helper(n+1, internal, leaves, verbose) for n in nodes_per_child]
    231         if verbose:
    232             print("About to apply %r to %r" % (r[1], children))

/home/jonathan/Applications/sage/local/lib/python3.7/site-packages/sage/symbolic/random_tests.py in <listcomp>(.0)
    228             n_spare_nodes = 0
    229         nodes_per_child = random_integer_vector(n_spare_nodes, n_children)
--> 230         children = [random_expr_helper(n+1, internal, leaves, verbose) for n in nodes_per_child]
    231         if verbose:
    232             print("About to apply %r to %r" % (r[1], children))

/home/jonathan/Applications/sage/local/lib/python3.7/site-packages/sage/symbolic/random_tests.py in random_expr_helper(n_nodes, internal, leaves, verbose)
    231         if verbose:
    232             print("About to apply %r to %r" % (r[1], children))
--> 233         return r[1](*children)
    234 
    235 def random_expr(size, nvars=1, ncoeffs=None, var_frac=0.5,

/home/jonathan/Applications/sage/local/lib/python3.7/site-packages/sage/symbolic/function.pyx in sage.symbolic.function.BuiltinFunction.__call__ (build/cythonized/sage/symbolic/function.cpp:12269)()
   1136             res = self._evalf_try_(*args)
   1137             if res is None:
-> 1138                 res = super(BuiltinFunction, self).__call__(
   1139                         *args, coerce=coerce, hold=hold)
   1140 

/home/jonathan/Applications/sage/local/lib/python3.7/site-packages/sage/symbolic/function.pyx in sage.symbolic.function.Function.__call__ (build/cythonized/sage/symbolic/function.cpp:7046)()
    600                     (<Expression>args[0])._gobj, hold)
    601         elif self._nargs == 2:
--> 602             res = g_function_eval2(self._serial, (<Expression>args[0])._gobj,
    603                     (<Expression>args[1])._gobj, hold)
    604         elif self._nargs == 3:

/home/jonathan/Applications/sage/local/lib/python3.7/site-packages/sage/symbolic/function.pyx in sage.symbolic.function.BuiltinFunction._evalf_or_eval_ (build/cythonized/sage/symbolic/function.cpp:13419)()
   1224         res = self._evalf_try_(*args)
   1225         if res is None:
-> 1226             return self._eval0_(*args)
   1227         else:
   1228             return res

/home/jonathan/Applications/sage/local/lib/python3.7/site-packages/sage/functions/other.py in _eval_(self, poly, index)
   2086             raise ValueError('polynomial in one variable required')
   2087         if len(vars) != 1 or not poly.is_polynomial(vars[0]):
-> 2088             raise ValueError('polynomial in one variable required')
   2089 
   2090     def _evalf_(self, poly, index, parent=None, algorithm=None):

ValueError: polynomial in one variable required
sage: foo = random_expr(20, nvars=2)
sage: foo = random_expr(20, nvars=2)
sage: foo = random_expr(20, nvars=2)
sage: foo = random_expr(20, nvars=2)
sage: foo = random_expr(20, nvars=2)
sage: foo = random_expr(20, nvars=2)
sage: foo = random_expr(20, nvars=2)
sage: foo = random_expr(20, nvars=2)
sage: foo = random_expr(20, nvars=2)
sage: foo = random_expr(20, nvars=2)
sage: foo = random_expr(20, nvars=2)
sage: foo = random_expr(20, nvars=2)
sage: foo = random_expr(20, nvars=2)
sage: foo = random_expr(20, nvars=2)
sage: foo = random_expr(20, nvars=2)
sage: foo = random_expr(20, nvars=2)
sage: foo = random_expr(20, nvars=2)
sage: foo = random_expr(20, nvars=2)
sage: foo = random_expr(20, nvars=2)
sage: foo = random_expr(20, nvars=2)
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
/home/jonathan/Applications/sage/local/lib/python3.7/site-packages/sage/symbolic/expression.pyx in sage.symbolic.expression.Expression._div_ (build/cythonized/sage/symbolic/expression.cpp:24413)()
   3802             else:
-> 3803                 x = left._gobj / _right._gobj
   3804             return new_Expression_from_GEx(left._parent, x)

ValueError: power::eval(): division by zero

During handling of the above exception, another exception occurred:

ZeroDivisionError                         Traceback (most recent call last)
<ipython-input-36-d588645d6f2a> in <module>()
----> 1 foo = random_expr(Integer(20), nvars=Integer(2))

/home/jonathan/Applications/sage/local/lib/python3.7/site-packages/sage/symbolic/random_tests.py in random_expr(size, nvars, ncoeffs, var_frac, internal, nullary, nullary_frac, coeff_generator, verbose)
    286     internal = normalize_prob_list(internal)
    287 
--> 288     return random_expr_helper(size, internal, leaves, verbose)
    289 
    290 

/home/jonathan/Applications/sage/local/lib/python3.7/site-packages/sage/symbolic/random_tests.py in random_expr_helper(n_nodes, internal, leaves, verbose)
    228             n_spare_nodes = 0
    229         nodes_per_child = random_integer_vector(n_spare_nodes, n_children)
--> 230         children = [random_expr_helper(n+1, internal, leaves, verbose) for n in nodes_per_child]
    231         if verbose:
    232             print("About to apply %r to %r" % (r[1], children))

/home/jonathan/Applications/sage/local/lib/python3.7/site-packages/sage/symbolic/random_tests.py in <listcomp>(.0)
    228             n_spare_nodes = 0
    229         nodes_per_child = random_integer_vector(n_spare_nodes, n_children)
--> 230         children = [random_expr_helper(n+1, internal, leaves, verbose) for n in nodes_per_child]
    231         if verbose:
    232             print("About to apply %r to %r" % (r[1], children))

/home/jonathan/Applications/sage/local/lib/python3.7/site-packages/sage/symbolic/random_tests.py in random_expr_helper(n_nodes, internal, leaves, verbose)
    228             n_spare_nodes = 0
    229         nodes_per_child = random_integer_vector(n_spare_nodes, n_children)
--> 230         children = [random_expr_helper(n+1, internal, leaves, verbose) for n in nodes_per_child]
    231         if verbose:
    232             print("About to apply %r to %r" % (r[1], children))

/home/jonathan/Applications/sage/local/lib/python3.7/site-packages/sage/symbolic/random_tests.py in <listcomp>(.0)
    228             n_spare_nodes = 0
    229         nodes_per_child = random_integer_vector(n_spare_nodes, n_children)
--> 230         children = [random_expr_helper(n+1, internal, leaves, verbose) for n in nodes_per_child]
    231         if verbose:
    232             print("About to apply %r to %r" % (r[1], children))

/home/jonathan/Applications/sage/local/lib/python3.7/site-packages/sage/symbolic/random_tests.py in random_expr_helper(n_nodes, internal, leaves, verbose)
    228             n_spare_nodes = 0
    229         nodes_per_child = random_integer_vector(n_spare_nodes, n_children)
--> 230         children = [random_expr_helper(n+1, internal, leaves, verbose) for n in nodes_per_child]
    231         if verbose:
    232             print("About to apply %r to %r" % (r[1], children))

/home/jonathan/Applications/sage/local/lib/python3.7/site-packages/sage/symbolic/random_tests.py in <listcomp>(.0)
    228             n_spare_nodes = 0
    229         nodes_per_child = random_integer_vector(n_spare_nodes, n_children)
--> 230         children = [random_expr_helper(n+1, internal, leaves, verbose) for n in nodes_per_child]
    231         if verbose:
    232             print("About to apply %r to %r" % (r[1], children))

/home/jonathan/Applications/sage/local/lib/python3.7/site-packages/sage/symbolic/random_tests.py in random_expr_helper(n_nodes, internal, leaves, verbose)
    228             n_spare_nodes = 0
    229         nodes_per_child = random_integer_vector(n_spare_nodes, n_children)
--> 230         children = [random_expr_helper(n+1, internal, leaves, verbose) for n in nodes_per_child]
    231         if verbose:
    232             print("About to apply %r to %r" % (r[1], children))

/home/jonathan/Applications/sage/local/lib/python3.7/site-packages/sage/symbolic/random_tests.py in <listcomp>(.0)
    228             n_spare_nodes = 0
    229         nodes_per_child = random_integer_vector(n_spare_nodes, n_children)
--> 230         children = [random_expr_helper(n+1, internal, leaves, verbose) for n in nodes_per_child]
    231         if verbose:
    232             print("About to apply %r to %r" % (r[1], children))

/home/jonathan/Applications/sage/local/lib/python3.7/site-packages/sage/symbolic/random_tests.py in random_expr_helper(n_nodes, internal, leaves, verbose)
    231         if verbose:
    232             print("About to apply %r to %r" % (r[1], children))
--> 233         return r[1](*children)
    234 
    235 def random_expr(size, nvars=1, ncoeffs=None, var_frac=0.5,

/home/jonathan/Applications/sage/local/lib/python3.7/site-packages/sage/structure/element.pyx in sage.structure.element.Element.__truediv__ (build/cythonized/sage/structure/element.c:13028)()
   1736             return (<Element>left)._div_(right)
   1737         if BOTH_ARE_ELEMENT(cl):
-> 1738             return coercion_model.bin_op(left, right, truediv)
   1739 
   1740         try:

/home/jonathan/Applications/sage/local/lib/python3.7/site-packages/sage/structure/coerce.pyx in sage.structure.coerce.CoercionModel.bin_op (build/cythonized/sage/structure/coerce.c:10139)()
   1209             self._record_exception()
   1210         else:
-> 1211             return PyObject_CallObject(op, xy)
   1212 
   1213         if op is mul:

/home/jonathan/Applications/sage/local/lib/python3.7/site-packages/sage/structure/element.pyx in sage.structure.element.Element.__truediv__ (build/cythonized/sage/structure/element.c:12993)()
   1734         cdef int cl = classify_elements(left, right)
   1735         if HAVE_SAME_PARENT(cl):
-> 1736             return (<Element>left)._div_(right)
   1737         if BOTH_ARE_ELEMENT(cl):
   1738             return coercion_model.bin_op(left, right, truediv)

/home/jonathan/Applications/sage/local/lib/python3.7/site-packages/sage/symbolic/expression.pyx in sage.symbolic.expression.Expression._div_ (build/cythonized/sage/symbolic/expression.cpp:24493)()
   3807             # See http://docs.cython.org/docs/wrapping_CPlusPlus.html
   3808             if 'division by zero' in str(msg):
-> 3809                 raise ZeroDivisionError("symbolic division by zero")
   3810             else:
   3811                 raise

ZeroDivisionError: symbolic division by zero

comment:2 Changed 22 months ago by mkoeppe

  • Milestone changed from sage-9.2 to sage-9.3

comment:3 Changed 15 months ago by mkoeppe

  • Milestone changed from sage-9.3 to sage-9.4

Moving to 9.4, as 9.3 has been released.

Changed 15 months ago by gh-kliem

random_expr crashing

comment:4 Changed 15 months ago by gh-kliem

As a bonus, GiNac apparently crashes sometimes, when running:

sage: from sage.symbolic.random_tests import *
sage: some_functions = [arcsinh, arctan, arctan2, arctanh,
....: arg, beta, binomial, ceil, conjugate, cos, cosh, cot, coth,
....: elliptic_pi, erf, exp, factorial, floor, heaviside, imag_part,
....: sech, sgn, sin, sinh, tan, tanh, unit_step, zeta, zetaderiv]
sage: my_internal = [(0.6, full_binary, 2), (0.2, full_unary, 1),
....: (0.2, [(1.0,f,f.number_of_arguments()) for f in some_functions])]
sage: set_random_seed(1)
sage: random_expr(50, nvars=3, internal=my_internal,
....:   coeff_generator=CDF.random_element)

This is from a doctest in src/sage/symbollic/random_tests.py. Crash log is attached, but it is rather easy to reproduce, but running the test maybe 20 times.

comment:5 Changed 15 months ago by gh-kliem

  • Priority changed from major to critical

comment:6 Changed 12 months ago by mkoeppe

  • Milestone changed from sage-9.4 to sage-9.5

comment:7 Changed 8 months ago by mkoeppe

  • Milestone changed from sage-9.5 to sage-9.6

comment:8 Changed 3 months ago by mkoeppe

  • Milestone changed from sage-9.6 to sage-9.7
Note: See TracTickets for help on using tickets.