I do not understand the very early evaluation of ForAll[a,b] to “b”. This should only be evaluated in this way, if it is sure, that “b” is free of “a” (FreeQ[b,a]==True).
ForAll[a, b]
b
Due to the Attribute “HoldAll” of the symbol “ForAll”, it cannot be known, if “b” is finally free of “a”.
Question two:
If b has no definition than the ‘value’ of ‘b’ is just symbolic ‘b’. And since ‘b’ does not contain ‘a’, so ‘b’ is independent of ‘a’, so it evaluates to ‘b’.
That is, what Mathematica is simply doing. But how can Mathematica know so early, that “b” is free of “a”, if “b” should not be evaluated due to the “HoldAll” Attribute ? The expression of “b” perhaps with an included “a” could be assigned later. That is, why the “HoldAll” -Attribute should work properly at this early moment to prevent Mathematica from early simplifications, which are not finally valid with a later assignment to “b”.
I hope, that the whole problem is clear, despite my poor german English.
Thank you for your answer.
You need HoldAll just to have local variables basically. Like plot:
x = 3
Plot[x^2, {x, 0, 1}]
Just to make sure the x in the first argument is interpreted as the variable x in the second argument (and not being replaced by 3). It works the same for ForAll
You want to evaluate ‘f’ for plotting, but using the local ‘x’, rather than the external 'x’ Hope you get the point You need to evaluate the first argument, other you would not be able to any variable
Thank you particular for the second example. It shows, that “f” will be evaluated and “x” is not evaluated with external settings. But why this difference, I do not really understand. If I look to the description of the attribute: “HoldAll is an attribute that specifies that all arguments to a function are to be maintained in an unevaluated form” the different evaluation rules are not really emphasized.
But nevertheless I found, that I can use HoldForm[ForAll[a,b]] alternatively for my intention to analyze “a” and “b” before evaluation by Mathematica.
Perhaps the usage message should be clearer, but a symbol having the attribute HoldAll does not necessarily imply that the arguments will never be evaluated, it means that the unevaluated form of the arguments will be substituted as-is in its definitions rather than evaluated first, then substituted. For example,
Without the HoldAll attribute, the standard evaluation sequence would evaluate f to f, evaluate 2 + 2 to 4, and evaluate 3 + 3 to 6 to get f[4, 6] and then it would look for definitions that match f[4, 6], of which there are none:
Thank you, I have to study your both examples, to really understand the difference between “substituted” and “evaluated” and to get a deeper understanding of the HoldAll attribute.
The same problem, as I described above in the main entry, but now from another viewpoint:
I want to implement the general wellknown rule for quantifiers:
In this example the meaning of the pattern “b_” should be: “Anything” assigned the name “b”.
How can Mathematica assume, that the pattern for “Anything” called “b_” is free of "a__ ", so that the simplification to “b_” is valid ?
Due to this short example, I guess that something goes wrong with the evaluation of “ForAll[]”
The explanation for the behavior you saw in your test is two-fold. First, b_ is not “anything” assigned the name “b”, it is literally the expression Pattern[b, Blank[]]. It will match anything and assign it the name “b” when used in functions like MatchQ, Cases, ReplaceAll or in definitions, but it itself is just a Pattern expression with first argument b and second argument Blank[]. The reason ForAll[a_, b_] simplifies to b_ is because Pattern[a, Blank[]] does not literally appear in the expression Pattern[b, Blank[]]. Put another way, FreeQ[b_, sub_ /; sub === a_] gives True.
In summary, I think there are several definitions of “free” floating around here that need to be distinguished:
A Wolfram Language expression that is free of a pattern: FreeQ[expr, pattern]
A WL expression that is free of a literal subexpression: FreeQ[expr, sub_ /; sub === foo]
A formula in first-order logic that is free of certain variables
Thank you Ian for your workarround and particular for your distingtion according the understanding of “free”. The behavior of your workarround seems to be very similar to “HoldForm[]”:
where the expression can be released now for evaluation with “ReleaseHold[]”
The first two bulletins of your distingtion show how Mathematica is interpreting the word “free of”, I guess due to the internal structure and philosophy of the WL. But the third interpretation is that, what is really needed in symbolic mathematics.
Because of that difference, it is difficult, to implement rules for quantifiers in predicate logic with Mathematica in an intuitive symbolic way.