Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

integral of piecewise function: error

I get a weird error when trying to take an integral of a very simple piecewise function:

blah = piecewise([((0, 0.01), 0.0001), ([0.01, 0.02], 0.0002), ((0.02, 0.03), 0.0003)])
blah.integral(x, 0.01, 0.025)

gives:

3.500000000000001e-06

However, adding one more item to the function definition causes an error:

blah = piecewise([((0, 0.01), 0.0001), ([0.01, 0.02], 0.0002), ((0.02, 0.03), 0.0003), ([0.03, 0.04], 0.0004)])
blah.integral(x, 0.01, 0.025)

AttributeError: 'numpy.bool_' object has no attribute 'assume'

Is this a bug or did I make a mistake?

integral of piecewise function: error

I get a weird error when trying to take an integral of a very simple piecewise function:

blah = piecewise([((0, 0.01), 0.0001), ([0.01, 0.02], 0.0002), ((0.02, 0.03), 0.0003)])
blah.integral(x, 0.01, 0.025)

gives:

3.500000000000001e-06

However, adding one more item to the function definition causes an error:

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-132-73d5f18533d2> in <module>()
      1 blah = piecewise([((0, 0.01), 0.0001), ([0.01, 0.02], 0.0002), ((0.02, 0.03), 0.0003), ([0.03, 0.04], 0.0004)])
piecewise([((Integer(0), RealNumber('0.01')), RealNumber('0.0001')), ([RealNumber('0.01'), RealNumber('0.02')], RealNumber('0.0002')), ((RealNumber('0.02'), RealNumber('0.03')), RealNumber('0.0003')), ([RealNumber('0.03'), RealNumber('0.04')], RealNumber('0.0004'))])
----> 2 blah.integral(x, 0.01, 0.025)

RealNumber('0.01'), RealNumber('0.025')) /home/sschyman/Programs/sage-upgrade/local/lib/python2.7/site-packages/sage/symbolic/function_factory.pyc in new_f(ex, *args, **kwds) 400 new_args = list(ex._unpack_operands()) 401 new_args.extend(args) --> 402 return f(ex, *new_args, **kwds) 403 return new_f /home/sschyman/Programs/sage-upgrade/local/lib/python2.7/site-packages/sage/functions/piecewise.pyc in integral(cls, self, parameters, variable, x, a, b, definite) 793 """ 794 if a != None and b != None: --> 795 F = self.integral(x) 796 return F(b) - F(a) 797 /home/sschyman/Programs/sage-upgrade/local/lib/python2.7/site-packages/sage/symbolic/function_factory.pyc in new_f(ex, *args, **kwds) 400 new_args = list(ex._unpack_operands()) 401 new_args.extend(args) --> 402 return f(ex, *new_args, **kwds) 403 return new_f /home/sschyman/Programs/sage-upgrade/local/lib/python2.7/site-packages/sage/functions/piecewise.pyc in integral(cls, self, parameters, variable, x, a, b, definite) 828 else: 829 try: --> 830 assume(start < x) 831 except ValueError: # Assumption is redundant 832 pass /home/sschyman/Programs/sage-upgrade/local/lib/python2.7/site-packages/sage/symbolic/assumptions.pyc in assume(*args) 513 else: 514 try: --> 515 x.assume() 516 except KeyError: 517 raise TypeError("assume not defined for objects of type '%s'"%type(x)) AttributeError: 'numpy.bool_' object has no attribute 'assume''assume'

Is this a bug or did I make a mistake?

integral of piecewise function: error

I get a weird error when trying to take an integral of a very simple piecewise function:

blah = piecewise([((0, 0.01), 0.0001), ([0.01, 0.02], 0.0002), ((0.02, 0.03), 0.0003)])
blah.integral(x, 0.01, 0.025)

gives:

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-132-73d5f18533d2> in <module>()
      1 blah = piecewise([((Integer(0), RealNumber('0.01')), RealNumber('0.0001')), ([RealNumber('0.01'), RealNumber('0.02')], RealNumber('0.0002')), ((RealNumber('0.02'), RealNumber('0.03')), RealNumber('0.0003')), ([RealNumber('0.03'), RealNumber('0.04')], RealNumber('0.0004'))])
----> 2 blah.integral(x, RealNumber('0.01'), RealNumber('0.025'))

/home/sschyman/Programs/sage-upgrade/local/lib/python2.7/site-packages/sage/symbolic/function_factory.pyc in new_f(ex, *args, **kwds)
    400         new_args = list(ex._unpack_operands())
    401         new_args.extend(args)
--> 402         return f(ex, *new_args, **kwds)
    403     return new_f

/home/sschyman/Programs/sage-upgrade/local/lib/python2.7/site-packages/sage/functions/piecewise.pyc in integral(cls, self, parameters, variable, x, a, b, definite)
    793             """
    794             if a != None and b != None:
--> 795                 F = self.integral(x)
    796                 return F(b) - F(a)
    797 

/home/sschyman/Programs/sage-upgrade/local/lib/python2.7/site-packages/sage/symbolic/function_factory.pyc in new_f(ex, *args, **kwds)
    400         new_args = list(ex._unpack_operands())
    401         new_args.extend(args)
--> 402         return f(ex, *new_args, **kwds)
    403     return new_f

/home/sschyman/Programs/sage-upgrade/local/lib/python2.7/site-packages/sage/functions/piecewise.pyc in integral(cls, self, parameters, variable, x, a, b, definite)
    828                     else:
    829                         try:
--> 830                             assume(start < x)
    831                         except ValueError: # Assumption is redundant
    832                             pass

/home/sschyman/Programs/sage-upgrade/local/lib/python2.7/site-packages/sage/symbolic/assumptions.pyc in assume(*args)
    513         else:
    514             try:
--> 515                 x.assume()
    516             except KeyError:
    517                 raise TypeError("assume not defined for objects of type '%s'"%type(x))

AttributeError: 'numpy.bool_' object has no attribute 'assume'

Is this a bug or did I make a mistake?

UPDATE: I uploaded an example to SMC: https://cloud.sagemath.com/projects/34b4b62a-2621-47c8-9bda-cde3a855f995/files/numpy_bool_traceback/