How does AND and OR logic actually work when used together in a formula?

This is what I thought is going on but it can’t be true:
I thought the conditions (red circles with numbers) that are surrounding the OR function need to have at leas one true.
so for example, either condition 1 or 2 need to be true in order to show rows that the true condition is true for. And if the condition 1 is true, it wont even check if the condition 2 is true or not, it won’t matter. It will just move on to the next condition.
In this example the next is another set of conditions: 3 and 4. The same goes for them, but between 1 and 2, and 3 and 4 is AND function. And AND function outputs true only if both sets of conditions output true.

Therefore
Set 1 (condition 1 & 2) = true
AND = true
Set 2 (condition 3 & 4) = true

but if:
Set 1 (condition 1 & 2) = true
AND = false
Set 2 (condition 3 & 4) = false

Now when we come to the next set and the next AND function, does that AND function require this entire thing…
Set 1 (condition 1 & 2) = true
AND = true
Set 2 (condition 3 & 4) = true
…to be true and the next set of conditions (5 & 6) to be true. Or how does it work?

If the condition 9 is false, it won’t show any tasks at all no matter if everything before is true?

I’m sure someone can explain this to me in very simple terms but I can’t figure it out, I just wan to know how a program would go trough this step by step. I would appreciate it very much.

1 Like

Line with number 7 should start with a parantheses? (_Team responsible,…,.,.
That way 7 and 8 would be correct…

I might be wrong, but that’s a first guess from me…

That is a good observation, I didn’t think about parentheses, but if I put it there it gives an error “missing close parenthesis” .

So the formula itself works fine, but I have trouble understanding it because the number 9 should be false for a lot of rows but they still show up. So how do they show up if the expression/condition (I don’t know how to call it) is outputs false and it’s right after the AND function. So My guess is that both 9 and the set of 7 and 8 need to output True for a row to be shown.

1 Like

Then try removing the parentheses at the start (beginning) of 8. I believe you still need the one at the beginning of 7.

If I remove it from 8 it looks fine and outputs the same number of rows.

But that’s not even my issue.
I just want to understand how this actually works.
How can a row be displayed if the condition is false…

I am new to coda.io, but have some (just a littlebit) experience with programming in general. Going after the parentheses was my first idea, simply by experience, those things are so easy to overlook.

My best suggestion for you is to first copy the entire formula, and paste it in a texteditor. Then start by adding one layer at a time to the formula, making each step work, one by one, until you managed to fix the entire formula.

By first hand, your formula does seem slightly complicated, so doing it this way may help both in understanding, and also to troubleshoot for errors.

In simple basic terms:
AND → Both criterias must be met, otherwise it gives false.
OR → One or the other or both must be met, otherwise it gives false.

When you look closely in each filter pair that you group together with the logical operator OR / AND, I believe you will manage to see how it goes. This way, checking your filterpair one by one, you will see weather or not you got the logic correct in your formula.

I hope this can be of some help for you.

1 Like

Is there something that leads you to believe the formula is not working as expected? From glancing it seems correct.

What you are probably looking for is the associativity of operators in CFL, i.e. whether an expression like a AND b AND b is parsed as (a AND b) AND c, or as a AND (b AND c). The former is called left-associative, the latter is right-associative. I would imagine that CFL, like most other established programming grammars, uses left-associativity. In any case, it shouldn’t matter at all since both are equivalent. The only case it would matter is if you were depending on a, b, and c to be evaluated in some specific order, in which case you shouldn’t.

1 Like

No there is nothing wrong with the formula.
That’s exactly what I’m looking for; the associativity of operators.

So based on that, would this be a correct order of how things go:

This should be the exact replica of my filter formula but in a simpler format.
There should be 3 bigger sets of conditions: a - d, e - g, h - i and j
Is that right? If it is, now everything makes sense. Thank you!

Hey — without reading too much here’s the overall answer on the associativity of operators.

  • AND — it’s like multiplication (actually it’s called logical multiplication). Just like 0x0=0, 0x1=0, 1x0=0, and only 1x1=1, AND is only true if both are true.

  • OR — it’s called logical addition. Only 0+0=0, otherwise 1+0=1, 0+1=1, and logically 1+1 also gives 1.

  • The order of operation applies just the same way as with arithmetic multiplication and addition. Unless there are brackets, AND is evaluated first, OR second:

a AND b OR c AND d

equals

(a AND b) OR (c AND d)

There’s also short-circuiting:

a AND b AND c AND d... will stop calculating as soon as it finds the first false. Analogically,
a OR b OR c OR d will stop calculating as soon as it finds the first true.|

P.P.S. Wait, the formula in the original post looks a lot like something in my starter template (:

P.S. Each of the a b c etc can be a boolean expression on its own.
Also when unsure, use brackets ().

4 Likes

Is the following true?

(a OR b) AND (c OR d)

Equals

a OR b AND c OR d


Also this:

(a OR b) AND c) OR (d AND e) ADN f

Equals

a OR b AND c OR d AND e AND f
Let’s see if I get this right: It would calculate whether…

  1. b AND c = true
  2. d AND e = true
  3. e AND f = true
    Then it if it’s all true, it would calculate OR operators:
  4. a OR b = true
  5. c OR d = true ← This is confusing because it would make more sense if it checked whether instead of c it checked everything that is in brackets before it, and if that’s false then check if d is true. ← If this is true, then how would you type (a OR b) AND c) OR (d AND e) ADN f without any brackets

P.S. Only learning from the best :saluting_face:

No. Just like

(1 + 2) * (3 + 4) is not equal 1 + 2 * 3 + 4

and

((1 + 2) * 3) + (5 * 6) * 7 is not equal to 1 + 2 * 3 + 5 * 6 * 7

It’s not the associativity in play but the order of operations.

1 Like

Got it! So It cannot be written without brackets because it’s nested.

Yes, you use brackets to control the order of operations :slight_smile:

Here’s the full documentation for JS. Coda is written in JS so it follows pretty much the same order (it’s only that there are fewer operators in Coda, e.g. no bitwise operators)

Here you can learn that e.g. equality has precedence over logical operators, i.e.

a = b AND c = d is evaluated as (a = b) AND (c = d), not a = (b AND c) = d

2 Likes

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.