0

I understand Mathematica programs to be a series of steps enclosed in simple parentheses. Each 'step' ends in a semicolon except for the last. The program output is then the output of the last step and intermediate step output is suppressed. I wish to "see the program run", by seeing output for each step. Here is an example.

(
s=5;
f[x_]:=x^2;
g[x_]:=f[x]-5;
g[s] f[s]-s
)

Which evaluates to 495. I'd like to see f[x]=25 and g[x]=20 along the way. Thanks.

John
  • 33
  • 4

1 Answers1

1

Just write your code like this;

code

Update

Note that my code eliminates the parentheses. With them revised code is:

code

Note the Times operators inserted by code editor, showing how the parentheses distort the interpretation of the code.

m_goldberg
  • 107,779
  • 16
  • 103
  • 257
  • Thanks m_goldberg, but this doesn't work. This produces: SetDelayed::write: Tag Times in 25 g[x_] is Protected. – John Nov 28 '20 at 17:37
  • @John. You get that error because you still have code enclosed in parentheses, which you should not because they change the meaning of the code as clearly shown by the code editor. – m_goldberg Nov 28 '20 at 18:09
  • Thanks m_goldberg. What I have submitted is my attempt to illustrate via a small example much longer & more complex code that includes an iterative process (not included here) that defines tolerance limits and loops back. In addition to getting the final result, My understanding is that the only way to run a program like this in Mathematica is to enclose the steps in parentheses. (Is that right?) I want to see some intermediate output and how this changes with each loop. – John Nov 30 '20 at 18:35
  • @John. In the light of your last comment, I would say that your question, as currently posed, is a very poor surrogate for your real problem. Since it's been closed, I recommend abandoning it for now. I also recommend you enter the phase "monitoring evaluation" in the search input field of the Documentation Center and take some time to study the first four hits. If those articles and the links they contain don't provide the info you need, then I suggest you post another question that better describes what you are really trying to do, – m_goldberg Nov 30 '20 at 19:08
  • @John. also, enclosing a CompoundExpression in parentheses doen not make it a program. The notion of program in Mathematica is rather fuzzy and quite different from the concept you have formed from experience you may acquired from programming languages like C or python. – m_goldberg Nov 30 '20 at 19:18
  • Thanks for the suggestions. – John Nov 30 '20 at 21:05
  • @John. I also recommend that you peruse this post which discusses many (but not all) of the ways the Wolfram Language differs from more conventional programming languages. Doing so may help preserve your sanity. Most of them stem from Stephan Wolfram wanting Mathematica to be the world's foremost environment for performing mathematical computation. My belief is that the programming environment was included only as a support for that primary goal. – m_goldberg Dec 01 '20 at 00:50