Opened 14 months ago

Closed 5 months ago

#31065 closed defect (invalid)

bug in _fast_float_

Reported by: chapoton Owned by:
Priority: major Milestone: sage-duplicate/invalid/wontfix
Component: symbolics Keywords:
Cc: mjo Merged in:
Authors: Reviewers: Michael Orlitzky
Report Upstream: N/A Work issues:
Branch: Commit:
Dependencies: #32234 Stopgaps:

Status badges

Description

From https://ask.sagemath.org/question/54720/

This can be traced to

sage: var('x,y')                                                                                                                            
(x, y)
sage: f(x,y)=x                                                                                                                              
sage: f._fast_float_(f.arguments())  
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
~/sage/local/lib/python3.8/site-packages/sage/symbolic/expression.pyx in sage.symbolic.expression.Expression.__float__ (build/cythonized/sage/symbolic/expression.cpp:11962)()
   1667         try:
-> 1668             ret = float(self._eval_self(float))
   1669         except TypeError:

~/sage/local/lib/python3.8/site-packages/sage/symbolic/expression.pyx in sage.symbolic.expression.Expression._eval_self (build/cythonized/sage/symbolic/expression.cpp:10176)()
   1417         else:
-> 1418             raise TypeError("Cannot evaluate symbolic expression to a numeric value.")
   1419 

TypeError: Cannot evaluate symbolic expression to a numeric value.

During handling of the above exception, another exception occurred:

TypeError                                 Traceback (most recent call last)
~/sage/local/lib/python3.8/site-packages/sage/symbolic/expression.pyx in sage.symbolic.expression.Expression.__float__ (build/cythonized/sage/symbolic/expression.cpp:12024)()
   1670             try:
-> 1671                 c = (self._eval_self(complex))
   1672                 if imag(c) == 0:

~/sage/local/lib/python3.8/site-packages/sage/symbolic/expression.pyx in sage.symbolic.expression.Expression._eval_self (build/cythonized/sage/symbolic/expression.cpp:10176)()
   1417         else:
-> 1418             raise TypeError("Cannot evaluate symbolic expression to a numeric value.")
   1419 

TypeError: Cannot evaluate symbolic expression to a numeric value.

During handling of the above exception, another exception occurred:

TypeError                                 Traceback (most recent call last)
~/sage/local/lib/python3.8/site-packages/sage/symbolic/expression_conversions.py in symbol(self, ex)
   1682         try:
-> 1683             return self.ff.fast_float_constant(float(ex))
   1684         except TypeError:

~/sage/local/lib/python3.8/site-packages/sage/symbolic/expression.pyx in sage.symbolic.expression.Expression.__float__ (build/cythonized/sage/symbolic/expression.cpp:12155)()
   1676             except TypeError:
-> 1677                 raise TypeError("unable to simplify to float approximation")
   1678         return ret

TypeError: unable to simplify to float approximation

During handling of the above exception, another exception occurred:

NotImplementedError                       Traceback (most recent call last)
<ipython-input-17-9cc701614d56> in <module>
----> 1 f._fast_float_(f.arguments())

~/sage/local/lib/python3.8/site-packages/sage/symbolic/expression.pyx in sage.symbolic.expression.Expression._fast_float_ (build/cythonized/sage/symbolic/expression.cpp:64805)()
  12041         """
  12042         from sage.symbolic.expression_conversions import fast_float
> 12043         return fast_float(self, *vars)
  12044 
  12045     def _fast_callable_(self, etb):

~/sage/local/lib/python3.8/site-packages/sage/symbolic/expression_conversions.py in fast_float(ex, *vars)
   1769         1.4142135623730951
   1770     """
-> 1771     return FastFloatConverter(ex, *vars)()
   1772 
   1773 #################

~/sage/local/lib/python3.8/site-packages/sage/symbolic/expression_conversions.py in __call__(self, ex)
    210         operator = ex.operator()
    211         if operator is None:
--> 212             return self.symbol(ex)
    213 
    214         if operator in arithmetic_operators:

~/sage/local/lib/python3.8/site-packages/sage/symbolic/expression_conversions.py in symbol(self, ex)
   1683             return self.ff.fast_float_constant(float(ex))
   1684         except TypeError:
-> 1685             raise NotImplementedError("free variable: %s" % repr(ex))
   1686 
   1687     def arithmetic(self, ex, operator):

NotImplementedError: free variable: (x, y) |--> x

Change History (5)

comment:1 Changed 11 months ago by gh-cEMRSS

This way might just not be the intended way of doing it, because this works:

sage: var('x,y')
(x,y)
sage: f(x,y)=x
sage: f._fast_float_(f.arguments()[0], f.arguments()[1])
<sage.ext.fast_eval.FastDoubleFunc object at 0x6ffe4139fb20>

I think that it interprets the tuple returned by f.arguments as the variable as opposed to the elements of the tuple, x and y. Thus, x is not specified as a variable, which results in the error.

comment:2 Changed 9 months ago by mkoeppe

  • Milestone changed from sage-9.3 to sage-9.4

Moving to 9.4, as 9.3 has been released.

comment:3 Changed 6 months ago by mkoeppe

  • Cc mjo added
  • Dependencies set to #32234
  • Milestone changed from sage-9.4 to sage-duplicate/invalid/wontfix
  • Status changed from new to needs_review

#32234 removes _fast_float_

comment:4 Changed 6 months ago by mjo

  • Reviewers set to Michael Orlitzky
  • Status changed from needs_review to positive_review

comment:5 Changed 5 months ago by mkoeppe

  • Resolution set to invalid
  • Status changed from positive_review to closed
Note: See TracTickets for help on using tickets.