Ask Your Question
1

simplify_full sometimes does not like abs and I

asked 2021-11-16 09:29:08 +0100

ortollj gravatar image

updated 2021-11-17 07:38:50 +0100

Hi

Maxima simplify_full() sometimes does not like abs() and Imaginary

var('t')
h(t)=sqrt(  abs( -2*I*cos(t)*sin(t) + 2*sin(t)^2 )  )
#h(t)=sqrt(-2*I*cos(t)*sin(t) + 2*sin(t)^2)

show('h(2) =\t ',h(2),'\t h(2) numerical =\t ',h(2).n())
show('h(t) canonicalize_radical =\t ',h.canonicalize_radical())

show('h(t) =\t ',h.simplify_full())

not only simplify_full does not like abs and I

var('t')
tStart=0
tEnd=4*pi
tRange=(t,tStart,tEnd)
# plot ok  if I replaced by 1
h(t)=sqrt( abs(-4*cos(t)^2 - 8*I*cos(t)*sin(t) + 4*sin(t)^2 + 1) )

N=60
vSub=0
inc=tEnd/(2*N)
hL=[]
vL=[]
for n in range (0,2*N+1) :
    hL.append(h(t).subs(t=vSub).n(10))
    vL.append(vSub)
    #show('h(t) =\t ',h(t),'h(t) num =\t ',h(t).subs(t=vSub).n(10))
    #show(vSub)
    vSub+=inc
show(vL)
show(hL)

plt = parametric_plot3d(  ( cos(t),sin(t),h(t)),
                          tRange,color='blue',thickness=10)
show(plt,aspect_ratio=1)
edit retag flag offensive close merge delete

Comments

And your question is ?

BTW :

sage: var("t")
t
sage: h(t)=sqrt(abs(-2*I*cos(t)*sin(t)+2*sin(t)^2))
sage: h(t).trig_reduce().exponentialize()
sqrt(abs(e^(2*I*t) - 1))
Emmanuel Charpentier gravatar imageEmmanuel Charpentier ( 2021-11-17 18:39:27 +0100 )edit

@Emmanuel Charpentier

I have no question, I just report error which I think should not happen ?

Am I wrong ?

Did you try the 2 codes ?

ortollj gravatar imageortollj ( 2021-11-17 19:01:36 +0100 )edit

I just report error which I think should not happen

So ? In order to report a bug, please consider filing a proper ticket.

Emmanuel Charpentier gravatar imageEmmanuel Charpentier ( 2021-11-18 16:51:32 +0100 )edit

1 Answer

Sort by ยป oldest newest most voted
0

answered 2021-11-18 17:30:50 +0100

Emmanuel Charpentier gravatar image

Did you try the 2 codes ?

The first "code" shows us that Maxima's sign is unhappy with I : file a ticket against Maxima.

The second "code" shows a problem with parametric_plot3d :

sage: parametric_plot3d([cos(t), sin(t), h(t)], (t, 0, 4*pi), aspect_ratio=1)
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-103-49367a62c914> in <module>
----> 1 parametric_plot3d([cos(t), sin(t), h(t)], (t, Integer(0), Integer(4)*pi), aspect_ratio=Integer(1))

/usr/local/sage-9/local/lib/python3.9/site-packages/sage/misc/decorators.py in wrapper(*args, **kwds)
    649                     kwds[new_name] = kwds[old_name]
    650                     del kwds[old_name]
--> 651             return func(*args, **kwds)
    652 
    653         return wrapper

/usr/local/sage-9/local/lib/python3.9/site-packages/sage/plot/plot3d/parametric_plot3d.py in parametric_plot3d(f, urange, vrange, plot_points, boundary_style, **kwds)
   1004         if plot_points == "automatic":
   1005             plot_points = 75
-> 1006         G = _parametric_plot3d_curve(f, urange, plot_points=plot_points, **kwds)
   1007     else:
   1008         if plot_points == "automatic":

/usr/local/sage-9/local/lib/python3.9/site-packages/sage/plot/plot3d/parametric_plot3d.py in _parametric_plot3d_curve(f, urange, plot_points, **kwds)
   1061     """
   1062     from sage.plot.misc import setup_for_eval_on_grid
-> 1063     g, ranges = setup_for_eval_on_grid(f, [urange], plot_points)
   1064     f_x, f_y, f_z = g
   1065     w = [(f_x(u), f_y(u), f_z(u)) for u in xsrange(*ranges[0], include_endpoint=True)]

/usr/local/sage-9/local/lib/python3.9/site-packages/sage/plot/misc.py in setup_for_eval_on_grid(funcs, ranges, plot_points, return_vars)
    149                 vars)
    150     else:
--> 151         return (fast_float(funcs, *vars, **options),
    152                 [tuple(_range + [range_step])
    153                  for _range, range_step in zip(ranges, range_steps)])

/usr/local/sage-9/local/lib/python3.9/site-packages/sage/ext/fast_eval.pyx in sage.ext.fast_eval.fast_float (build/cythonized/sage/ext/fast_eval.c:1617)()
     74 
     75     if isinstance(f, (tuple, list)):
---> 76         return tuple([fast_float(x, *vars, expect_one_var=expect_one_var) for x in f])
     77 
     78     cdef int i

/usr/local/sage-9/local/lib/python3.9/site-packages/sage/ext/fast_eval.pyx in sage.ext.fast_eval.fast_float (build/cythonized/sage/ext/fast_eval.c:1830)()
     86 
     87     try:
---> 88         return fast_callable(f, vars=vars, domain=float,
     89                              expect_one_var=expect_one_var)
     90     except AttributeError:

/usr/local/sage-9/local/lib/python3.9/site-packages/sage/ext/fast_callable.pyx in sage.ext.fast_callable.fast_callable (build/cythonized/sage/ext/fast_callable.c:4518)()
    463 
    464         etb = ExpressionTreeBuilder(vars=vars, domain=domain)
--> 465         et = x._fast_callable_(etb)
    466 
    467     if isinstance(domain, sage.rings.abc.RealField):

/usr/local/sage-9/local/lib/python3.9/site-packages/sage/symbolic/expression.pyx in sage.symbolic.expression.Expression._fast_callable_ (build/cythonized/sage/symbolic/expression.cpp:93084)()
  12625         """
  12626         from sage.symbolic.expression_conversions import fast_callable
> 12627         return fast_callable(self, etb)
  12628 
  12629     def show(self):

/usr/local/sage-9/local/lib/python3.9/site-packages/sage/symbolic/expression_conversions.py in fast_callable(ex, etb)
   1866 
   1867     """
-> 1868     return FastCallableConverter(ex, etb)()
   1869 
   1870 class RingConverter(Converter):

/usr/local/sage-9/local/lib/python3.9/site-packages/sage/symbolic/expression_conversions.py in __call__(self, ex)
    204                 div = self.get_fake_div(ex)
    205                 return self.arithmetic(div, div.operator())
--> 206             return self.arithmetic(ex, operator)
    207         elif operator in relation_operators:
    208             return self.relation(ex, operator)

/usr/local/sage-9/local/lib/python3.9/site-packages/sage/symbolic/expression_conversions.py in arithmetic(self, ex, operator)
   1784             elif exponent == 0.5:
   1785                 from sage.misc.functional import sqrt
-> 1786                 return self.etb.call(sqrt, operands[0])
   1787             elif exponent == -0.5:
   1788                 from sage.misc.functional import sqrt

/usr/local/sage-9/local/lib/python3.9/site-packages/sage/ext/fast_callable.pyx in sage.ext.fast_callable.ExpressionTreeBuilder.call (build/cythonized/sage/ext/fast_callable.c:7029)()
    743             return self(base)**exponent
    744         else:
--> 745             return ExpressionCall(self, fn, [self(a) for a in args])
    746 
    747     def choice(self, cond, iftrue, iffalse):

/usr/local/sage-9/local/lib/python3.9/site-packages/sage/ext/fast_callable.pyx in sage.ext.fast_callable.ExpressionTreeBuilder.__call__ (build/cythonized/sage/ext/fast_callable.c:6116)()
    617             return self.constant(x)
    618 
--> 619         return fc(self)
    620 
    621     def _clean_var(self, v):

/usr/local/sage-9/local/lib/python3.9/site-packages/sage/symbolic/expression.pyx in sage.symbolic.expression.Expression._fast_callable_ (build/cythonized/sage/symbolic/expression.cpp:93084)()
  12625         """
  12626         from sage.symbolic.expression_conversions import fast_callable
> 12627         return fast_callable(self, etb)
  12628 
  12629     def show(self):

/usr/local/sage-9/local/lib/python3.9/site-packages/sage/symbolic/expression_conversions.py in fast_callable(ex, etb)
   1866 
   1867     """
-> 1868     return FastCallableConverter(ex, etb)()
   1869 
   1870 class RingConverter(Converter):

/usr/local/sage-9/local/lib/python3.9/site-packages/sage/symbolic/expression_conversions.py in __call__(self, ex)
    212             return self.tuple(ex)
    213         else:
--> 214             return self.composition(ex, operator)
    215 
    216     def get_fake_div(self, ex):

/usr/local/sage-9/local/lib/python3.9/site-packages/sage/symbolic/expression_conversions.py in composition(self, ex, function)
   1832             {arctan2}(v_0, v_1)
   1833         """
-> 1834         return self.etb.call(function, *ex.operands())
   1835 
   1836     def tuple(self, ex):

/usr/local/sage-9/local/lib/python3.9/site-packages/sage/ext/fast_callable.pyx in sage.ext.fast_callable.ExpressionTreeBuilder.call (build/cythonized/sage/ext/fast_callable.c:7029)()
    743             return self(base)**exponent
    744         else:
--> 745             return ExpressionCall(self, fn, [self(a) for a in args])
    746 
    747     def choice(self, cond, iftrue, iffalse):

/usr/local/sage-9/local/lib/python3.9/site-packages/sage/ext/fast_callable.pyx in sage.ext.fast_callable.ExpressionTreeBuilder.__call__ (build/cythonized/sage/ext/fast_callable.c:6116)()
    617             return self.constant(x)
    618 
--> 619         return fc(self)
    620 
    621     def _clean_var(self, v):

/usr/local/sage-9/local/lib/python3.9/site-packages/sage/symbolic/expression.pyx in sage.symbolic.expression.Expression._fast_callable_ (build/cythonized/sage/symbolic/expression.cpp:93084)()
  12625         """
  12626         from sage.symbolic.expression_conversions import fast_callable
> 12627         return fast_callable(self, etb)
  12628 
  12629     def show(self):

/usr/local/sage-9/local/lib/python3.9/site-packages/sage/symbolic/expression_conversions.py in fast_callable(ex, etb)
   1866 
   1867     """
-> 1868     return FastCallableConverter(ex, etb)()
   1869 
   1870 class RingConverter(Converter):

/usr/local/sage-9/local/lib/python3.9/site-packages/sage/symbolic/expression_conversions.py in __call__(self, ex)
    204                 div = self.get_fake_div(ex)
    205                 return self.arithmetic(div, div.operator())
--> 206             return self.arithmetic(ex, operator)
    207         elif operator in relation_operators:
    208             return self.relation(ex, operator)

/usr/local/sage-9/local/lib/python3.9/site-packages/sage/symbolic/expression_conversions.py in arithmetic(self, ex, operator)
   1794         elif operator == mul_vararg:
   1795             operator = _operator.mul
-> 1796         return reduce(lambda x,y: self.etb.call(operator, x,y), operands)
   1797 
   1798     def symbol(self, ex):

/usr/local/sage-9/local/lib/python3.9/site-packages/sage/symbolic/expression_conversions.py in <lambda>(x, y)
   1794         elif operator == mul_vararg:
   1795             operator = _operator.mul
-> 1796         return reduce(lambda x,y: self.etb.call(operator, x,y), operands)
   1797 
   1798     def symbol(self, ex):

/usr/local/sage-9/local/lib/python3.9/site-packages/sage/ext/fast_callable.pyx in sage.ext.fast_callable.ExpressionTreeBuilder.call (build/cythonized/sage/ext/fast_callable.c:7029)()
    743             return self(base)**exponent
    744         else:
--> 745             return ExpressionCall(self, fn, [self(a) for a in args])
    746 
    747     def choice(self, cond, iftrue, iffalse):

/usr/local/sage-9/local/lib/python3.9/site-packages/sage/ext/fast_callable.pyx in sage.ext.fast_callable.ExpressionTreeBuilder.__call__ (build/cythonized/sage/ext/fast_callable.c:6116)()
    617             return self.constant(x)
    618 
--> 619         return fc(self)
    620 
    621     def _clean_var(self, v):

/usr/local/sage-9/local/lib/python3.9/site-packages/sage/symbolic/expression.pyx in sage.symbolic.expression.Expression._fast_callable_ (build/cythonized/sage/symbolic/expression.cpp:93084)()
  12625         """
  12626         from sage.symbolic.expression_conversions import fast_callable
> 12627         return fast_callable(self, etb)
  12628 
  12629     def show(self):

/usr/local/sage-9/local/lib/python3.9/site-packages/sage/symbolic/expression_conversions.py in fast_callable(ex, etb)
   1866 
   1867     """
-> 1868     return FastCallableConverter(ex, etb)()
   1869 
   1870 class RingConverter(Converter):

/usr/local/sage-9/local/lib/python3.9/site-packages/sage/symbolic/expression_conversions.py in __call__(self, ex)
    203             if getattr(self, 'use_fake_div', False) and (operator is _operator.mul or operator is mul_vararg):
    204                 div = self.get_fake_div(ex)
--> 205                 return self.arithmetic(div, div.operator())
    206             return self.arithmetic(ex, operator)
    207         elif operator in relation_operators:

/usr/local/sage-9/local/lib/python3.9/site-packages/sage/symbolic/expression_conversions.py in arithmetic(self, ex, operator)
   1794         elif operator == mul_vararg:
   1795             operator = _operator.mul
-> 1796         return reduce(lambda x,y: self.etb.call(operator, x,y), operands)
   1797 
   1798     def symbol(self, ex):

/usr/local/sage-9/local/lib/python3.9/site-packages/sage/symbolic/expression_conversions.py in <lambda>(x, y)
   1794         elif operator == mul_vararg:
   1795             operator = _operator.mul
-> 1796         return reduce(lambda x,y: self.etb.call(operator, x,y), operands)
   1797 
   1798     def symbol(self, ex):

/usr/local/sage-9/local/lib/python3.9/site-packages/sage/ext/fast_callable.pyx in sage.ext.fast_callable.ExpressionTreeBuilder.call (build/cythonized/sage/ext/fast_callable.c:7029)()
    743             return self(base)**exponent
    744         else:
--> 745             return ExpressionCall(self, fn, [self(a) for a in args])
    746 
    747     def choice(self, cond, iftrue, iffalse):

/usr/local/sage-9/local/lib/python3.9/site-packages/sage/ext/fast_callable.pyx in sage.ext.fast_callable.ExpressionTreeBuilder.__call__ (build/cythonized/sage/ext/fast_callable.c:6116)()
    617             return self.constant(x)
    618 
--> 619         return fc(self)
    620 
    621     def _clean_var(self, v):

/usr/local/sage-9/local/lib/python3.9/site-packages/sage/symbolic/expression.pyx in sage.symbolic.expression.Expression._fast_callable_ (build/cythonized/sage/symbolic/expression.cpp:93084)()
  12625         """
  12626         from sage.symbolic.expression_conversions import fast_callable
> 12627         return fast_callable(self, etb)
  12628 
  12629     def show(self):

/usr/local/sage-9/local/lib/python3.9/site-packages/sage/symbolic/expression_conversions.py in fast_callable(ex, etb)
   1866 
   1867     """
-> 1868     return FastCallableConverter(ex, etb)()
   1869 
   1870 class RingConverter(Converter):

/usr/local/sage-9/local/lib/python3.9/site-packages/sage/symbolic/expression_conversions.py in __call__(self, ex)
    194         except TypeError as err:
    195             if 'self must be a numeric expression' not in err.args:
--> 196                 raise err
    197 
    198         operator = ex.operator()

/usr/local/sage-9/local/lib/python3.9/site-packages/sage/symbolic/expression_conversions.py in __call__(self, ex)
    191         try:
    192             obj = ex.pyobject()
--> 193             return self.pyobject(ex, obj)
    194         except TypeError as err:
    195             if 'self must be a numeric expression' not in err.args:

/usr/local/sage-9/local/lib/python3.9/site-packages/sage/symbolic/expression_conversions.py in pyobject(self, ex, obj)
   1724         if isinstance(obj, Constant):
   1725             obj = obj.expression()
-> 1726         return self.etb.constant(obj)
   1727 
   1728     def relation(self, ex, operator):

/usr/local/sage-9/local/lib/python3.9/site-packages/sage/ext/fast_callable.pyx in sage.ext.fast_callable.ExpressionTreeBuilder.constant (build/cythonized/sage/ext/fast_callable.c:6370)()
    659         """
    660         if self._domain is not None:
--> 661             c = self._domain(c)
    662         return ExpressionConstant(self, c)
    663 

/usr/local/sage-9/local/lib/python3.9/site-packages/sage/rings/number_field/number_field_element.pyx in sage.rings.number_field.number_field_element.NumberFieldElement.__float__ (build/cythonized/sage/rings/number_field/number_field_element.cpp:19548)()
   1916             if c.imag == 0:
   1917                 return c.real
-> 1918             raise TypeError('unable to coerce to a real number')
   1919 
   1920     def _complex_double_(self, CDF):

TypeError: unable to coerce to a real number

On the other hand, the following call works :

sage: parametric_plot3d([lambda u:cos(u), lambda u:sin(u), lambda u:h(u)], (0, 4*pi), aspect_ratio=1)
Launched html viewer for Graphics3d Object

as does this one :

sage: parametric_plot3d([cos, sin, lambda u:h(u)], (0, 4*pi), aspect_ratio=1)
Launched html viewer for Graphics3d Object

But not this one :

sage: parametric_plot3d([cos, sin, h], (0, 4*pi), aspect_ratio=1)

[ Snip... ]

TypeError: unable to coerce to a real number

This implies that lambda u:h(u) is interpreted as a function for parametric_plot3d purposes, but not h. File a ticket against that...

edit flag offensive delete link more

Comments

Many thanks !

Emmanuel Charpentier gravatar imageEmmanuel Charpentier ( 2021-11-18 19:46:48 +0100 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2021-11-16 09:29:08 +0100

Seen: 273 times

Last updated: Nov 18 '21