Ask Your Question
1

coercion code in Sage ?

asked 2022-03-12 07:24:24 +0200

ortollj gravatar image

Hi

why I have to add I in fz(z,zc)=uz+I*vz --> fz(z,zc,I)=uz+I*vz ?

to avoid error ?

var('x,y',domain='real')
var('z',domain='complex')
var('zc',domain='complex',latex_name=r'\overline{z}')

u(x,y)=x*y^2+y*x ;v(x,y)=x^2*y-y*x
fuv(x,y)=u(x,y)+I*v(x,y)

zDic={x:(z+zc)/2,y:(z-zc)/2}
uz(z,zc)=u.subs(zDic)
vz(z,zc)=v.subs(zDic)

show("uz : \t ", uz)
show("vz : \t ", vz)
fz(z,zc)=uz+vz
fz(z,zc)=uz+I*vz
#fz(z,zc,I)=uz+I*vz
edit retag flag offensive close merge delete

Comments

fz(z,zc)=uz+vz was just a test comment it restart and see the error message

ortollj gravatar imageortollj ( 2022-03-12 09:56:55 +0200 )edit

1 Answer

Sort by ยป oldest newest most voted
0

answered 2022-03-12 09:26:44 +0200

Emmanuel Charpentier gravatar image

You use inconsistent notations. This :

uz(z,zc)=u.subs(zDic)
vz(z,zc)=v.subs(zDic)

defines uz and vz as *functions` (well... callable symbolic expressions, to be precise).

sage: uz
(z, zc) |--> 1/8*(z + zc)*(z - zc)^2 + 1/4*(z + zc)*(z - zc)
sage: vz
(z, zc) |--> 1/8*(z + zc)^2*(z - zc) - 1/4*(z + zc)*(z - zc)

So is their sum :

sage: uz + vz
(z, zc) |--> 1/8*(z + zc)^2*(z - zc) + 1/8*(z + zc)*(z - zc)^2

So, f can be defined either by defining f1 as a callable symbolic expression returning the sum of two symbolic expressions, which are the values of the calls to uz and vz :

sage: f1(z, zc) = uz(z, zc) + vz(z, zc) ; f1
(z, zc) |--> 1/8*(z + zc)^2*(z - zc) + 1/8*(z + zc)*(z - zc)^2

or defining f2 as the sum of two callable symbolic expressions. which is a callable symbolic expression :

sage: f2 = uz + vz ; f2
(z, zc) |--> 1/8*(z + zc)^2*(z - zc) + 1/8*(z + zc)*(z - zc)^2

but mixing the two syntaxes is inconsistent :

sage: f3(z, zc) = uz + I*vz
---------------------------------------------------------------------------
RuntimeError                              Traceback (most recent call last)
<ipython-input-41-b7d338745ecf> in <module>
----> 1 __tmp__=var("z,zc"); f3 = symbolic_expression(uz + I*vz).function(z,zc)

/usr/local/sage-9/local/var/lib/sage/venv-python3.9/lib/python3.9/site-packages/sage/structure/element.pyx in sage.structure.element.Element.__mul__ (build/cythonized/sage/structure/element.c:12319)()
   1514             return (<Element>left)._mul_(right)
   1515         if BOTH_ARE_ELEMENT(cl):
-> 1516             return coercion_model.bin_op(left, right, mul)
   1517 
   1518         cdef long value

/usr/local/sage-9/local/var/lib/sage/venv-python3.9/lib/python3.9/site-packages/sage/structure/coerce.pyx in sage.structure.coerce.CoercionModel.bin_op (build/cythonized/sage/structure/coerce.c:10754)()
   1198         # Now coerce to a common parent and do the operation there
   1199         try:
-> 1200             xy = self.canonical_coercion(x, y)
   1201         except TypeError:
   1202             self._record_exception()

/usr/local/sage-9/local/var/lib/sage/venv-python3.9/lib/python3.9/site-packages/sage/structure/coerce.pyx in sage.structure.coerce.CoercionModel.canonical_coercion (build/cythonized/sage/structure/coerce.c:12595)()
   1330                 if x_elt._parent is y_elt._parent:
   1331                     return x_elt,y_elt
-> 1332             self._coercion_error(x, x_map, x_elt, y, y_map, y_elt)
   1333 
   1334         cdef bint x_numeric = isinstance(x, (int, long, float, complex))

/usr/local/sage-9/local/var/lib/sage/venv-python3.9/lib/python3.9/site-packages/sage/structure/coerce.pyx in sage.structure.coerce.CoercionModel._coercion_error (build/cythonized/sage/structure/coerce.c:21330)()
   2029             <class 'str'> 'g'
   2030         """
-> 2031         raise RuntimeError("""There is a bug in the coercion code in Sage.
   2032 Both x (=%r) and y (=%r) are supposed to have identical parents but they don't.
   2033 In fact, x has parent '%s'

RuntimeError: There is a bug in the coercion code in Sage.
Both x (=I) and y (=(z, zc) |--> 1/8*(z + zc)^2*(z - zc) - 1/4*(z + zc)*(z - zc)) are supposed to have identical parents but they don't.
In fact, x has parent 'Symbolic Ring'
whereas y has parent 'Callable function ring with arguments (z, zc)'
Original elements I (parent Number Field in I with defining polynomial x^2 + 1 with I = 1*I) and (z, zc) |--> 1/8*(z + zc)^2*(z - zc) - 1/4*(z + zc)*(z - zc) (parent Callable function ring with arguments (z, zc)) and maps
<class 'sage.structure.coerce_maps.DefaultConvertMap_unique'> (map internal to coercion system -- copy before use)
Coercion map:
  From: Number Field in I with defining polynomial x^2 + 1 with I = 1*I
  To:   Callable function ring with arguments (z, zc)
<class 'NoneType'> None

The error message is pretty well descriptive.

What version of Sage are you using ?

HTH,

edit flag offensive delete link more

Comments

sorry I forgot to precise:Sagemath9.5 Ubutntu 20.04 WSL2 W11

OOps ! ok, I should have written fz(z,zc)=uz(z,zc)+I*vz(z,zc) , thank you.

ortollj gravatar imageortollj ( 2022-03-12 09:49:06 +0200 )edit

In fact I still have the same problem when I must declare f= or f(x,y)= ?, I still haven't really understood when to use f or f(x).

Because for me as I declared uz(z,zc)=u.subs(zDic) and vz(z,zc)=v.subs(zDic), it implies that f=uz+Ivz is actually f(z,zc)=uz(z,zc)+Ivz(z,zc). It is strange that I need to precise it again.

ortollj gravatar imageortollj ( 2022-03-12 13:02:24 +0200 )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: 2022-03-12 07:24:24 +0200

Seen: 54 times

Last updated: Mar 12