Message Boards Message Boards

0
|
941 Views
|
5 Replies
|
3 Total Likes
View groups...
Share
Share this post:

Question Regarding the Behavior of ValueQ Function in Mathematica

Posted 4 months ago

Hello everyone,

I've encountered an issue while using Mathematica and I'm hoping to get some clarification here. In my code, I've defined a global variable a[b][1] = x, and then I used the ValueQ[a[b]] function to check if a[b] has a value. However, the result I obtained is True, instead of the expected False.

I've checked some references, including page 39 of the book "Mathematica Programming: An Advanced Introduction", which states that ValueQ[a[b]] should return False. I'm puzzled by this result and would like to understand the reason behind this behaviour.

I've tried to look through the documentation and other resources, but I haven't found a clear explanation for this situation. So, I'd like to ask the community here: Should ValueQ[a[b]] indeed return True in this case? If so, why is there a discrepancy between the statement in "Mathematica programming: an advanced introduction" and the actual behaviour? If not, I might be missing something, and I'd appreciate it if someone could point out my mistake and provide some assistance.

POSTED BY: Hengjian Wang
5 Replies
Posted 4 months ago

ValueQ was updated in 12.2. One gets the book behaviour with the option Method->"Legacy". See documentation for ValueQ, the Details section.

a[b][1] = x;
ValueQ[a[b], Method -> "Legacy"]
POSTED BY: Hans Milton

Thank you very much for your response. It may indeed be due to the "Legacy" option, but I'm still unclear about the specific effects of using "Legacy". This is because I'm not familiar with how the ValueQ function behaved in previous versions. Additionally, I'm puzzled as to why ValueQ[a[b]] returns True, even though a[b] itself hasn't been assigned a value.

Is there any documentation available for older versions? Or is there another method to understand how ValueQ worked in previous versions? I noticed in the "History" section it only mentions updates to the function, but where can I find specific details about what those updates entail?

POSTED BY: Hengjian Wang
Posted 4 months ago

The documentation (http://reference.wolfram.com/language/ref/ValueQ.html) seems pretty clear. ValueQ takes a Method option, and Method has 5 choices: Automatic, "SymbolDefinitionsPresent", "TrialEvaluation", "OwnValuesPresent", and "Legacy". I think the answer to your question is found in the documentation for "Legacy": "match behavior in Version 12.1 and earlier".

POSTED BY: Eric Rimbey

The way I understand the documentation, ValueQ[a[b]] gives False because a[b] has no value, in the sense that you never defined a[b]=something; iif I enter a[b] I get back a[b]. Your definition a[b][1] = x defines a subvalue, not a value, of a[b]. Try ValueQ[a[b][1]].

POSTED BY: Gianluca Gorni

Yes, indeed, the expression ValueQ[a[b][1]] evaluates to True, which aligns with what the book says. However, my question is regarding why ValueQ[a[b]] evaluates differently from what's stated in the book.

I suspect this may be due to version updates, causing changes in the actual behavior of the ValueQ function. However, I couldn't find any relevant information in the official documentation.

POSTED BY: Hengjian Wang
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