Difference between OR/AND in Filter expressions

I want to hide all tracks that contain either Noise OR Big Synth in the genre tag (semicolon delimitered), however I'm finding that using AND is giving results instead of OR, which seems to make more sense because I don't just want genre tags that contain both. This is the expression:
(NOT genre HAS "noise") OR (NOT genre HAS "Big Synth")

And the AND version:
(NOT genre HAS "noise") AND (NOT genre HAS "Big Synth")

Total tracks, unfiltered: 577
Using OR expression gives me 575
When using AND expression: 413

I guess the AND version is giving correct results yet I don't understand how. I have also read the Filter Syntax docs.

a question about logic.
NOT genre HAS "noise" gives you all files without "noise" (which includes "Big Synth")
NOT genre HAS "Big Synth" gives you all files without "Big Synth (which includes "noise")
And as you link them with OR, you should get all files where either condition becomes true - you seem to have 2 files in which both genres appear.
If you link the 2 conditions with AND then both conditions have to be true so as soon as you find either "noise" or "Big Synth" in genre then that file is not displayed.

1 Like

Isn't either condition what I want? One song could have "noise" and the next song has "Big Synth" - and I wish both of them to be filtered out (ie. hidden from view).

It still sounds like using AND means a song's genre tag most contain "noise" and "Big synth" ...

Oh wait, is the AND combining the results of both sets??? So each parenthesis has it's own 'sub-result' and the AND is merging as one "list", per say?

EDIT: Still not understanding what the OR is doing.

It's a problem of formal logic.
And formal logic does not always follow every-day language conventions.

Yes. Both conditions have to be true to give the result that the whole expression is true.

"OR" also combines both expressions. Only that with "OR" either set has to be true to give an overall result of the whole expression to be true.

See e.g.

And, in the documentation

you find:

Combines the filter expressions <expr1> and <expr2> by logical and or or. Parentheses can be used to group combined expressions.

Example: artist IS Hidden Orchestra OR artist IS The Cinematic Orchestra Lists all files where an artist field is either Hidden Orchestra or The Cinematic Orchestra.

In a way I am glad that set theory, much laughed upon way back when, finally pays off.

2 Likes

Maybe this explanation can help you to understand the logic behind AND and OR.
Just remember the 3 assumptions for the user_name, the score and game_over in this example:

3 Likes

Reading the formal logic makes sense but not when applied to mp3tag. Here's what I've calculated in the hopes that I can be shown the obvious!

Total = 577
(genre HAS "Noise") = 97
(genre HAS "Big Synth") = 69
= 166

(genre HAS "Noise") OR (genre HAS "Big Synth") = 164 (577 - 164 = 413)
(genre HAS "Noise") AND (genre HAS "Big Synth") = 2 (577 - 2 = 575)

^^^ These seem to add-up.

Flipping the logic adds up too:
(NOT genre HAS "Noise") = 480 (480 + 97 = 577)
(NOT genre HAS "Big Synth") = 508 (508 + 69 = 577)

And the final piece:
(NOT genre HAS "Noise") OR (NOT genre HAS "Big Synth") = 575 (577 - 575 = 2)
(NOT genre HAS "Noise") AND (NOT genre HAS "Big Synth") = 413 (577 - 413 = 164


Random examples of track genres:

  1. Big Room; Mainstage; Instrumental; Noise
  2. Big Synth; Instrumental
  3. Bounce; Electro House
  4. Noise; Instrumental

^^^ So I only expect the third track to appear in the result of a (NOT genre HAS "Noise") OR (NOT genre HAS "Big Synth") search.
And only the fourth track to appear when searching `


Maybe I'm over thinking things so missing the obvious. I think I'm not getting how the two expressions in (NOT genre HAS "Noise") OR (NOT genre HAS "Big Synth") are merging results. Trying to picture a venn diagram in my head.

I guess I could just blindly use the AND version ((NOT genre HAS "Noise") AND (NOT genre HAS "Big Synth") ) yet I prefer to understand what's happening for accuracy and learning!

I also intend to grow this expression with more genre omissions. Eg:

(NOT genre HAS "Noise") OR (NOT genre HAS "Big Synth") OR (NOT genre HAS "Instrumental")

I believe this is what I have done?

The following tracks should show because:
1: yes, as it does not have "Big Synth"
2: yes, because it does not have "noise"
3: yes, because it does not have "Big Synth" and does not have "Noise"
4: yes, because it does not have "Big Synth"
Have you tried
NOT (%genre% HAS "Noise" OR %genre% HAS "Big Synth")

OK, so I think I'm understanding what mp3tag is doing regarding the above example. Each expression within the parentheses generates its own 'true' list, then they're combined as one big list at the end with the OR part?

Looks like only the first genre is getting filtered. I suspected this too with the earlier example expressions.
Getting same results with this: NOT (%genre% HAS "Noise")

If the first expression already leads to the result true, then the whole expression is true as you combined it with "OR".

Believe me: MP3tag filters correctly.
It would be up to you to create a suitable test environment to deepen your understanding.
If Mp3tag does not show the results that you expected then check why your expectation and the result does not match.

1 Like

I have used some pretty complex filters in the past to drill down a library of ~25k files to exactly what I was looking for. Standard logic always applies, although often it can seem counter to what we may say in conversation. The more complex the filter, the more accurate you need to be with the terminology. But I can definitely confirm through positive experience that mp3tag applies the filter syntax as it should for all of the operators.

A word of caution in some more complex cases - if any of the fields you are filtering have some of the protected use characters (like $ or %) you have to enclose that operation in double quotation marks. Out of habit I do this most of the time, as there is always a possibility that these characters can exist.

There are tons of websites that have examples of logic. All the fun details specific to how mp3tag uses filters that @ohrenkino mentioned previously here applies in all cases.

As said above the behavior you see is expected and correct.

(NOT genre HAS "noise") OR (NOT genre HAS "Big Synth")

This finds all tracks that either miss the genre "noise" OR "big synth", as long as one or both of these are missing it's matched. Only for the two tracks that have both genres both the left and right part of the condition is false, and false or false is false.

(NOT genre HAS "noise") AND (NOT genre HAS "Big Synth")

This matches all tracks that miss both the genre "noise" AND "big synth". So this is what you want.

1 Like

You mean like quote genre (like "genre") if I'm looking for the word in the genre tag?
And if searching for fa$t then I need to quote like this fa"$"t or "fa$t"?

I don't know if it is working as expected because it's still showing results with those genres.
Eg:

I used (NOT genre HAS "noise") OR (NOT genre HAS "Instrumental") this time.

Could you tell us which results you get if you evalute each of the conditions for each of the selected tracks? Is the result "true" or "false"?

OK, I woke up in the night thinking I understand what's happening. The OR version stops evaluating the other expressions when the first one is true. Then the AND version means the track cannot have any of the genre tag (eg. noise, big synth, instrumental) but it doesn't mean it must not contain all three to evaluate as true.

That is false.
Your problem is the "OR".
Any assembly of conditions joined with OR gets as overall result "true" as soon as 1 of the conditions is "true".
MP3tag does not "stop" evaluating - you only see the overall result..

Sure here are some screenshots:

Blank


`(NOT genre HAS "noise") OR (NOT genre HAS "Instrumental")`


`(NOT genre HAS "noise") AND (NOT genre HAS "Instrumental")`


Hope these help.