Hey Siddhartha, I found your query from your post here.
So p is a trial function and is a UFL object. Your definition of S(p) would need UFL operators to be valid.
def S(pf):
return pow((sqrt(-pf)+1),-1)
(FYI : pow and sqrt are from dolfin or ufl namespaces and not python math ones)
As for U(p), since it is a definite integral, I would consider it a UFL Constant which is a function of a trial function p. I am not too sure what you are trying to implement here - nor the skills to solve what you need. Just useful info I can give you : It should be possible to use assemble() over a form to obtain the definite integral.
Some Ref for valid UFL forms and Operators can be found in documentation here : https://fenics.readthedocs.io/projects/ufl/en/latest/
You can maybe post this at UFL mailing list for better ideas from experts
Cheers.