Mathematica: output an expression without evaluating it first

In summary, the conversation discusses the use of Mathematica's Format function and the need for a function that can prevent evaluation of certain inputs. The user is looking for a function called DoNotEvaluate that would work as the opposite of putting a semicolon after input, and they provide examples of desired inputs and outputs. The conversation ends with mention of several Mathematica functions that could potentially serve this purpose, but the user notes that they have not found any documentation explaining the process of shielding certain inputs from evaluation.
  • #1
HJ Farnsworth
128
1
Greetings,

I recently discovered Mathematica's Format function, and it has been of great use to me. However, there is one thing that I want to use it to do, that I have yet to be able to. I could do this easily, though, if there is some Mathematica function that works as follows...

If I put a semicolon after inputting something in Mathematica, it evaluates what I input without outputting the result. The function that I am looking for is sort of the inverse of this.

I will call the function DoNotEvaluate[] for the rest of this post. Some simple input and output examples for the function that I am looking for would be...

Input: DoNotEvaluate[Sqrt[4]]
Output: Sqrt[4] - note that the output is not 2.

Input: DoNotEvaluate[Sqrt[2*2]]
Output: Sqrt[2*2] - note that the output is neither Sqrt[4] or 2.

Input: x=2*2; DoNotEvaluate[Sqrt[x]]
Output: Sqrt[4]

Does anyone know of a Mathematica function, or other Mathematica technique, that does what my made-up DoNotEvaluate[] function does?

Thanks for any help you can give.

-HJ Farnsworth
 
Physics news on Phys.org
  • #2
Perhaps one of these or some combination?

http://reference.wolfram.com/mathematica/ref/HoldForm.html
http://reference.wolfram.com/mathematica/ref/HoldAll.html
http://reference.wolfram.com/mathematica/ref/HoldComplete.html
http://reference.wolfram.com/mathematica/ref/HoldAllComplete.html
http://reference.wolfram.com/mathematica/ref/Unevaluated.html

There are even more of these, but I don't think the process of shielding some things from evaluation while getting other things done has been explained in any documentation that I have seen.
 
  • #3
Thank you for the very quick and complete response. That's pretty much what I wanted.

-HJ Farnsworth
 

1. How can I output an expression in Mathematica without evaluating it first?

To output an expression without evaluating it first, you can use the function HoldForm. This will prevent Mathematica from evaluating the expression and instead display it as written.

2. Can I still manipulate the output of an expression if I use HoldForm?

Yes, you can still manipulate the output of an expression even if you use HoldForm. You can use functions such as ReleaseHold or Apply to evaluate the expression after it has been displayed.

3. How do I prevent Mathematica from automatically simplifying my expression when I output it?

If you want to prevent Mathematica from automatically simplifying your expression when you output it, you can use the function FullForm instead of HoldForm. This will display the expression in its full form without any simplification.

4. Is there a way to output an expression without displaying any of its variables?

Yes, you can use the function Defer to output an expression without displaying any of its variables. This will keep the variables in the expression but will not display their values.

5. Can I output multiple expressions without evaluating them first?

Yes, you can output multiple expressions without evaluating them first by using the function HoldForm on each expression and then using Row or Column to display them together.

Similar threads

  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
13
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
6
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
864
  • MATLAB, Maple, Mathematica, LaTeX
Replies
6
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
6
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
1K
Back
Top