Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 892923
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T14:08:17+00:00 2026-05-15T14:08:17+00:00

The mathematica documentation on Evaluate at possible issues says: Evaluate works only on the

  • 0

The mathematica documentation on Evaluate at possible issues says:

Evaluate works only on the first
level, directly inside a held function

Why does Mathematica have this limitation? So if I have an expression with more than one level take this simplified example:

Hold[Plus[Plus[2, 2], 2]]]

Now suppose I want to see what the answer is to the the second Plus, without evaluating anything on levels below it. I’ve tried different things such as:

In[290]:= Hold[Plus[Evaluate[Plus[2, 2]], 2]]
Out[290]= Hold[Evaluate[2+2]+2]

In[287]:= Hold[Plus[ReleaseHold[Hold[Plus[2, 2]]], 2]]
Out[287]= Hold[ReleaseHold[Hold[2+2]]+2]

The first Hold keeps everything unevaluated at and beyond the first level in this case.
The goal is to control evaluation of an expression at each stage from the most inner nested function to the outer one using successive Hold, ReleaseHold and Evaluate functions to achieve that. I know I could use trace to see what happens beyond level one in an expression but that is different and sometimes complex to read with longer expressions.

It seems like the only way is to extract and totally dismantle the expression into lists using Extract, Part or Level; evaluate part of the expression that I want; then reconstruct and re-map the expression back together for each stage. Are there any other approaches or functions for achieving this I could consider?

Edit: This might be a better example to look at the approach of releasing the first hold. With the expression:

Hold[Plus[Plus[2, Plus[2,2]], 2]]]

If you release the first hold and place a hold on a higher level in a expression at the third Plus, to look like this:

in = Plus[Plus[2, Hold[Plus[2,2]]], 2]]]
out = Hold[2+2]+4

You find that Mathematica will evaluate lower levels in the background when you really want it to wait.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T14:08:17+00:00Added an answer on May 15, 2026 at 2:08 pm

    I can’t give the exact reason why Evaluate “works only on the first level, directly inside a held function” but I suspect it’s partly efficiency, in that it would be slow if the evaluator had to scan the complete expression tree of held arguments passed to any function with a Hold* attribute for nested Evaluate expressions and evaluate them, and then recurse and look for Evaluate subexpressions in what it just evaluated, all while keeping the rest of the expression unevaluated, especially when this might not always be what you want to happen anyway.

    Doing what you want is pretty easy using a combination of Extract and ReplacePart though:

    In[51]:= expr = Hold[Plus[Plus[2, 2], 2]];
    
    In[52]:= ReleaseHoldAt[expr_, partspec_] :=
      ReplacePart[expr, partspec -> Extract[expr, partspec]]
    
    In[53]:= ReleaseHoldAt[expr, {1, 1}]
    
    Out[53]= Hold[4 + 2]
    

    This lets us illustrate another reason why it might not make sense for Evaluate to work at any level in an expression passed as an argument to a function with a Hold* attribute, considering the following expression involving i:

    In[82]:= i = 1;
    
    In[83]:= ReleaseHoldAt[Hold[i = 2; j = Plus[i, i]], {1, 2}]
    
    Out[83]= Hold[i = 2; 2]
    

    Note that the value of j would have been 4 if we had evaluated the first part of that expression before the Plus, but the results are different since we are only doing partial evaluation, and i=2 had not been evaluated when we evaluated the subexpression setting j. Sometimes, this may be what you want to happen, but often it is very likely not.

    Keep in mind that even Evaluate in the first level can be defeated by a function that has the attribute HoldAllComplete or by using HoldComplete:

    In[62]:= Hold[Evaluate[Plus[2,2]]]
    Out[62]= Hold[4]
    

    …versus:

    In[63]:= HoldComplete[Evaluate[Plus[2,2]]]
    Out[63]= HoldComplete[Evaluate[2+2]]
    

    Finally, the output of Trace can be a little dense, but you can filter out what you want by using patterns or symbols of interest in the second argument:

    In[88]:= Trace[Plus[Plus[Plus[1,2],3],4],Plus]
    Out[88]= {{{1+2,3},3+3,6},6+4,10}
    
    In[93]:= Trace[Plus[Subtract[Plus[1,2],4],8],_Plus]
    Out[93]= {{{1+2}},-1+8}
    

    HTH!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In Mathematica the command Select only lets define a selection criterion for each element
Is it possible to overlay two or more graphics in Mathematica, if the graphics
Does mathematica have something like select any that gets any element of a list
In Mathematica there are a number of functions that return not only the final
Mathematica documentation states: Text in three-dimensional graphics is placed at a position that corresponds
Mathematica has a function MapThread that behaves like this: MapThread[ f , { {a,b,c}
If I understood the Mathematica documentation correct ( haven't found examples either ) Graphics3D
I've seen it's possible to make a connection between Mathematica and MySQL databases using
In Mathematica, the documentation for ClearAll states: ClearAll[symb1, symb2, ...] clears values, definitions, attributes,
I have already checked all the examples and settings in the Mathematica documentation center,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.