why precedence over disjunction - qregularexpression

I have a question about operator precedence hierarchy, why "Because sequences have a higher precedence than disjunction, /the|any/ matches the or any but not thany or they"?
I just couldn't understand why this result reflects "precedence over disjunction"?

If the disjunction operator had a higher precedence than grouping together each sequence of characters, than it could operate on the individual characters or subgroups. It could be interpreted as something like /the(e|an)y/

Related

How to choose operator precedence?

In Idris, you can define operators using infix, infixl or infixr, followed by the precedence of the operators then a list of operators, like
infixl 8 +, -
I imagine you can do this in other languages too.
I know what effect precedence has, but how do I choose what precedence to give my operators? What problems might I encounter if I initially choose a precedence that's too high or low?
For most languages the operator precedence table is already defined by the language itself.
Following one of these would guarantee that your code/language is up to what's considered standard.
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Operator_Precedence
https://en.cppreference.com/w/c/language/operator_precedence

How can I determine which regular expressions from a list possibly overlap

I have a table of regular expressions that are in an MySQL table that I match text against.
Is there a way, using MySQL or any other language (preferably Perl) that I can take this list of expressions and determine which of them MAY overlap. This should be independent of whatever text may be supplied to the expressions.
All of the expression have anchors.
Here is an example of what I am trying to get:
Expressions:
^a$
^b$
^ab
^b.*c
^batch
^catch
Result:
'^b.*c' and '^batch' MAY overlap
Thoughts?
Thanks,
Scott
Further explanation:
I have a list of user-created regexes and an imported list of strings that are to be matched against the regexes. In this case the strings are "clean" data (ie they are not user-created but imported from another source - they must not change).
When a user adds to the list of regexes I do not want any collisions on either the existing list of strings nor any future strings (which can not be guessed ahead of time - the only constraints being they are ASCII printable characters no longer than 255 characters).
A brute-force method would be to create a "rainbow" table of all of the permutations of strings and each time a regex is added run all of the regexes against the rainbow table. However I'd like to avoid this (I'm not even sure of the cost) and so was wondering aloud as to the possibility of an algorithm that would AT LEAST show which regexes in a list MAY collide.
I will punt on full REs. Even limiting to BREs and/or MySQL-pre-8.0 will be challenging. Here are some thoughts.
If end-anchored and no + or *, the calculate the length. The fixed-length can be used as a discriminator. Also, it could be used for toning back the "brute force" by perhaps an order of magnitude.
Anything followed by + or * gets turned into .* for simplicity. (Re the "may collide" rule.)
Any RE with explicit characters (including those followed by +) becomes a discriminator in some situations. Eg, ^a.*b$ vs ^a.*c$.
For those anchored at the end, reverse the pattern and test it that way. (I don't know how difficult reversing is.)
If you can say that a particular character must be at any position, then use it as a discriminator: ^a.b.*c$ -- a in pos 1; b in pos 3; c at end. Perhaps this can be extended to character classes: ^\w may match, but ^\d and ^a.*\d$ can't.

Prove that {F,→} is functionally complete

How can I prove that {F,→} is functionally complete?
I am trying to write p∧q using only those symbols but I really have no idea how to solve it.
Any ideas?
Look at the truth table of implication:
If you fix input Q to F (false), the output is the inverse of input P.
Therefore, implication and F can be combined to an inverter.
P implies Q can be written as Q or not P. Both have the same truth tables.
This demonstrates, that implication is equivalent to a disjunction with one inverted input. Using the inverter shown above, we get a disjunction (inclusive or).
Apply De Morgan's laws to see that P implies Q is also equivalent to not (P and not Q). This shows that we can turn an implication into a conjunction.
Disjunction plus negation as well as conjunction combined with negation are functionally complete. Hence, implication combined with a false constant is also functionally complete. Look here for a formal proof.

Reverse Polish Notation

Quick question about reverse polish notation.
Why is 2*3/(2-1)+5*(4-1)?: (original)
23*21-/541-*+
rather than 23*21-/5+41-*?
I am just confusing myself. Personally I'd have adding extra brackets to the original question to make it clear where the 5 is added. If its not there what order do I assume it goes in?
Thanks
If we assume a conventional order of operations, then any multiplications get computed before any additions. So, when you have y+x*z, x*z gets computed first, according to usual order of operations. More explicitly, y+x*z means (y+(x*z)). Thus, 2*3/(2-1)+5*(4-1) means (((2*3)/(2-1))+(5*(4-1))).
If you were to explicitly state up front that you stipulated your order of operations as additions happening before multiplication, then if you wrote 4+5*6 you would mean ((4+5)*6). If you did that, then you could state the distributive law as x*y+z=(x*y)+(x*z). What would expressions mean when you omit operations? Consider xy&z, where & is binary, and the binary operation for xy gets omitted. If the omitted binary operation is *, and & is +, then this would mean that the expressed operation & would happen before the suppressed multiplication operation. Usually, omitted operations get assumed to happen first. So, if you addition had binding priority over multiplication, then it probably would make sense for an expression like xy to mean x+y instead of the more usual x*y. In principle, there seems nothing wrong with letting additions happen before multiplications, so long as you state that you want to do that up front and stick to that convention and its implications in whatever you write. That all said, except for communicating with people who don't understand RPN or PN, I simply don't see why you would write in infix notation once you understand RPN and PN.
It's because multiplication has higher precedence than addition. When you don't have the braces, 5(only) is first multiplied with (4-1) and added to rest of the expression. When you haven't used braces, it is evaluated according to order of precedence only.

Is there any boolean algebra expression that can not be put into 3SAT?

This seems to me pretty obvious, There is not but I might be leaving a special case.
As I see it 1SAT (only one literal per clause) and 2SAT can be easily transformed into 3SAT.
An any clause with more than 3 literas has been proven it can be transformed into 3SAT.
So maybe the question should be asked as:
Do all boolean algebra can be put into SAT? or
can we define boolean algebra with ony these operators? AND OR and NOT
No, there is not.
I will not give the full proof but here is the main idea: Write the given formula in a normal form i.e. conjunction of disjunctions. Use induction on the number of variables on an expression. Pick the longest subexpression with n+1 variables, introduce a new variable for some part of subexpression to leave an expression of n variables, add the constraints for the new variable to the formula, repeat the procedure as many times as needed to have a formula where the longest subexpression has n variables.