AND OR precedence rule
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Mute
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
Hi everyone,
I just realized the precedence rule for AND OR is totally wrong. Am I crazy??
Considering AND as a multiplier and OR as an adder (according to logic gates theory), the following should give me 4 rows as a result, without the need to add parenthesis.
Best,
Fernando Vizcaino
- Labels:
- Bug
- Preparation
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
In order not to go crazy with AND/OR conditions, always put them in parenthesis in a logical way. 😁
It's good practice for whatever language you're writing in.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
Hey @FilipR ,
I agree with you that it's a good practice, but that doesn't correct the issue.
It would be similar to having the following:
2+2x2 = 8
2+(2x2) = 6
As math principles are, logic gates principles should also be consistent here.
Best,
Fernando Vizcaino
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
🤣 I have never thought about it. But after checking I think your right @fmvizcaino !
Does the Formula Tool have a specific programming language or is it an Alteryx creation which is transpiled to a language?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
@fmvizcaino C based but what ever converts it to C ignores precedence. Seems this has been hiding in plain sight 😅 great spot.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
This is defeinetely an interesting use case @fmvizcaino 😀
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
Just ran into this issue myself... also had the same thought: what is going on, am I crazy here?? since it's such a basic principle of logical operators. Apparently it hasn't been corrected yet, so excessive parenthesis it is :)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
Just seeing this --- but not sure what the issue is --- let's look at this in Node.js--
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
Use the boolean/logical OR operator (||) instead of the bitwise OR (|) in your js and you will get the "correct" answer of 4 items (last item in the array should be double mountain per the original post).
The tooltip for the formula syntax specifies that within the alteryx formula tool, the boolean operators are "||" "OR", which should not be applied consecutively but should instead respect precedence as others above noted (AND takes precedence, i.e. is executed first, before OR). This would be analogous to boolean/logical operators in other languages: SQL (AND/OR), Python (and/or), JavaScript (&&/||), etc.
Here's a simple example of the incorrect result being returned within the Formula Tool in test 1, fixed (which shouldn't be necessary) with parenthesis in test 2:
