Problem with changing polar coordinates to cartesian coordinates

Hello,
Before asking my main question, I’m sorry to write mathematics formula and code in the following way, I didn’t find any option to write in the appropriate format.
I want to define the following function, that is in polar coordinates, in cartesian coordinates and then consider its gradient and Hessian.
u_exact (r,θ):= r^(5/3) * (1-r)^(5/2) * (sin(2θ/3))^(5/2) if 0 < θ < 3π/2,
and otherwise its value is zero.
My attempt is as following

from fenics import *
from mshr import *
from math import atan2
domain = Circle(Point(0.,0.),1.0)
mesh = generate_mesh(domain, 5, “cgal”)
x = SpatialCoordinate(mesh)
V = FunctionSpace(mesh, “CG”, 2)
class u_exact(Expression):

def eval(self, values, x):
    values[0] =(pow(pow(x[0],2) + pow(x[1],2),5./6) * pow(1 - sqrt(pow(x[0],2) + pow(x[1],2)),5./2) * pow(sin(2./3*atan2(x[1],x[0])),5./2) if \
    -pi <= atan2(x[1],x[0]) <= -pi/2 ||  0 <= atan2(x[1],x[0])<= pi else 0.0 )       
    return

u1_exact = u_exact(degree=2)
uu_exact = project(u1_exact, V)
g_exact = grad(uu_exact)
H_exact = grad(g_exact)

But I got an error. For some reason, I need to consider cartesian coordinates.
Any help would be greatly appreciated.

You can try

from mshr import *
from ufl import *
from dolfin import * 
import matplotlib.pyplot as plt

domain = Circle(Point(0,0), 1)
mesh = generate_mesh(domain, 50)

x = SpatialCoordinate(mesh)

W = FunctionSpace(mesh, 'CG', 2)

phi = conditional(lt(atan_2(x[1],x[0]),0), atan_2(x[1],x[0])+2*pi, atan_2(x[1],x[0]))

u_exact = conditional(lt(phi,3*pi/2.0),sqrt(x[0]*x[0]+x[1]*x[1])**(5.0/3.0) * (1-sqrt(x[0]*x[0]+x[1]*x[1]))**(5.0/2.0) * (sin(2*phi/3.0))**(5.0/2.0), 0)

u = project(u_exact, W)

plot(u)
plt.show()

Side note: you can write in latex by using the $ symbol $, e.g: y = x^2 comes from $ y = x^2 $.

Many thanks for your help.

Thank you for your note.