Message Boards Message Boards

0
|
6992 Views
|
11 Replies
|
9 Total Likes
View groups...
Share
Share this post:

Why does "ForAll[a,b]" evaluate to b ?

Posted 5 years ago

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".

Attributes[ForAll]
{HoldAll, Protected, ReadProtected}

With the following input

b := x^2 + a^2
ForAll[a, b]

and the output:

ForAll[a, a^2 + x^2]

two questions are arising:

  • Why is "b" evaluated here, despite the Attribute "HoldAll"
  • After "b" is evaluated here, Mathematica recoginizes "b" as not free of "a". Why is "b" assumed to be free of "a" in the first example ?

Thank you for any support.

Regards Uwe

POSTED BY: uwe moehring
11 Replies

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Â…

POSTED BY: Sander Huisman

Even better example:

x = 3
f := x^2
Plot[f, {x, 0, 1}]

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Â…

POSTED BY: Sander Huisman
Posted 5 years ago

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.

Thank you for your support. Regards Uwe

POSTED BY: uwe moehring

You need 'f' to evaluate of courseÂ… otherwise you would not be able to use variables! It is how you evaluate it that HoldAll changesÂ…

POSTED BY: Sander Huisman

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,

In[1]:= SetAttributes[f, HoldAll];

In[2]:= f[x_Plus, y_] := f[Evaluate[Echo[x]], y]

In[3]:= f[2 + 2, 3 + 3]

4

Out[3]= f[4, 3 + 3]

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:

In[4]:= Attributes[f] = {}

Out[4]= {}

In[5]:= f[2 + 2, 3 + 3]

Out[5]= f[4, 6]

So in general you should not expect symbols with the HoldAll attribute to have no evaluation, just non-standard evaluation. Hope this helps!

POSTED BY: Ian Ford
Posted 5 years ago

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.

Best Regards Uwe

POSTED BY: uwe moehring
Posted 5 years ago

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:

And[ForAll[a_, b_], c_] -> ForAll[a, And[b, c]] /; FreeQ[c, a]

In this context, I tested the following expression:

expr := HoldForm[ForAll[a_, b_]]
ReleaseHold[expr]
b_

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[]"

Regards Uwe

POSTED BY: uwe moehring
POSTED BY: Ian Ford
Posted 5 years ago

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[]":

In[163]:= SetAttributes[Formula, HoldAll];
foo[Formula[ForAll[a_, b_] && c_]] :=
Formula[ForAll[a, b && c]] /; FreeQ[Formula[c], a] 

In[169]:= foo[Formula[ForAll[x, A] && B]] 
Out[169]= Formula[ForAll[x, A && B]]

Now substituted "Formular" --> "HoldForm":

In[170]:= foo[HoldForm[ForAll[a_, b_] && c_]] := 
 HoldForm[ForAll[a, b && c]] /; FreeQ[HoldForm[c], a]

In[171]:= foo[HoldForm[ForAll[x, A] && B]]
Out[171]= HoldForm[ForAll[x, A && B]]

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.

But nevertheless, thank you for your help

Regards Uwe

POSTED BY: uwe moehring

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'.

POSTED BY: Sander Huisman
Posted 5 years ago
POSTED BY: uwe moehring
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract