← Back to team overview

ufl team mailing list archive

Re: [Question #224154]: Support for "and" and "or"

 

Question #224154 on UFL changed:
https://answers.launchpad.net/ufl/+question/224154

    Status: Open => Answered

Martin Sandve Alnæs proposed the following answer:
and/or is not possible because of how they work in python.
&/| is bug prone because of their precedence level (see below).
UFL uses And(a,b) and Or(a,b) instead.

In [1]: from ufl import *

In [2]: x = triangle.x[0]
                                                                                                                                                                                   
In [4]: x < 3 & x > 2                                                                                                                                                              
---------------------------------------------------------------------------                                                                                                        
TypeError                                 Traceback (most recent call last)                                                                                                        
<ipython-input-4-1442b929afd2> in <module>()                                                                                                                                       
----> 1 x < 3 & x > 2                                                                                                                                                              
                                                                                                                                                                                   
TypeError: unsupported operand type(s) for &: 'int' and 'Indexed'                                                                                                                  
                                                                                                                                                                                   
In [5]: And(x < 3, x > 2)                                                                                                                                                        
Out[5]: AndCondition(...)

-- 
You received this question notification because you are a member of UFL
Team, which is an answer contact for UFL.