FFC

Missing precedence rules for And and Or

Bug #1075149 reported by Martin Sandve Alnæs
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
FFC
Fix Released
Undecided
Kristian B. Ølgaard

Bug Description

The code generation in FFC does not consider precedence of the &&/|| operators vs <,>,etc., which may result in wrong results as seen in this case. Suggested fix is to always add () around arguments to && and ||, but I'm not sure I understand how the formatting rules work (strings vs. lambdas in the formatting dict).

from dolfin import *
mesh = UnitSquare(100,100)
x = mesh.ufl_cell().x

f = conditional(Or(And(lt(x[0], 0.5), gt(x[1], 0.3)), lt(x[1], 0.7)), 1, 0)
g = conditional(And(lt(x[0], 0.5), Or(gt(x[1], 0.3), lt(x[1], 0.7))), 1, 0)

fp = project(f, mesh=mesh)
gp = project(g, mesh=mesh)

print fp.vector().norm('l2')
print gp.vector().norm('l2')

plot(fp) # Wrong, looks just like g
plot(gp) # Correct

interactive()

Changed in ffc:
assignee: nobody → Kristian B. Ølgaard (k.b.oelgaard)
status: New → Confirmed
Changed in ffc:
status: Confirmed → Fix Committed
Anders Logg (logg)
Changed in ffc:
status: Fix Committed → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.