CodePlexProject Hosting for Open Source Software

Symbols are referenced using

The example below helps to illustrate this concept:

x = 3 y = x + 8 z = y def y // returns x + 8 def z // returns y print x // returns 3 print y // returns 11 print z // returns 11 // now we change the definition of y y = x - 5 def y // returns x - 5 def z // returns y print x // returns 3 print y // returns -2 print z // returns -2 // Now we clone the definition of y, instead of referencing it by using symbolic notation z = $y y = x * 12 def y // returns x * 12 def z // returns x - 5 print x // returns 3 print y // returns 36 print z // returns -2

x = a y = 2 * a z = x + y def z

This example will return that z is equal to x+y, not a+(2*a). If we use symbolic notation for x and y, we see a very different output:

x = a y = 2 * a z = $x + $y def z

Here we see that the definition of z is now equal to 3*a. Why is this? First, what happened was that by using symbolic notation, we were able to tell NeturalMath that we wanted to use the expressions for x and y rather than the variables themselves. This meant that we truely were assigning z a value of a+(2*a). Second, as we learned in the previous lesson, NeturalMath will attempt to reduce the complexity of any expression into the simplest possible form. Because 3*a is simpler than a+(2*a), this is what the final value is assigned to. Using this technique, we can combine complex equations into simpler ones and return the reduced output. This is illustrated below:

top = 3 * (x + 2) bottom = x total = $top / $bottom def total // returns 3 + (6 / x)

x = 3 // x is assigned a value of 3 y = x + 3 refValue = y // value assigned standard reference symValue = $y // value assigned to symbol's expression atValue = @y // value assigned to the symbol's computed value def refValue // prints y def symValue // prints x + 3 def atValue // prints 6

Just as symbolic notation ($) indicates that we should use the expression for a variable rather than the variable, value notation (@) indicates that we should use the resulting value of the expression. This would be the same value that would be displayed on screen if the variable was used in a print command. This usage has the same limitations as the print command as well. If the value cannot be determined because it depends on variables which are not yet defined, there is another issue that prevents execution, using value notation will cause NeturalMath to throw an error.

y = x + 3 z = @y // throws an error because x is not defined.

Last edited Nov 27, 2010 at 4:08 PM by zanethorn, version 3