This is a read only copy of the old FEniCS QA forum. Please visit the new QA forum to ask questions

ufl presedence in print statement

+1 vote

Hi so when printing a ufl form such as

import ufl
x = ufl.Constant(ufl.triangle)
y = ufl.Constant(ufl.triangle)
print(1./(x*y))

This gives the output

1.0 / w_0 * w_1

However as the brackets have disappeared which using standard precedence implies this should be interpreted as

(1.0 / w_0) * w_1

Is this standard behaviour? And does this not lead to ambiguities when interpreting the print statement? If not is there a way to make the print output more verbose as to include more brackets? Obviously the ufl tree is still fine and this is only a feature of the print statement. Thanks I'd appreciate any help.

asked May 2, 2017 by matthewtcollins FEniCS Novice (130 points)

1 Answer

+1 vote

Nice catch. This looks like an issue with ufl printing.

If you try the following:

import ufl
x = ufl.Constant(ufl.triangle)
y = ufl.Constant(ufl.triangle)
f = (1./(x*y))
print type(f)
for o in f.ufl_operands:
  print o

you should see:

<class 'ufl.algebra.Division'>
1.0
w_0 * w_1

So the maths is correct, the printing is misleading.

answered May 2, 2017 by nate FEniCS Expert (17,050 points)
...