# NeturalMath Language Definition and Syntax

## Expressions

One of the way in which NeturalMath differes from many other programming languages is the concept of expressions. This idea may be among the most difficult for experienced programmers to get their head around, and yet it should come intuitively to many non-technical
individuals. Typical programming languages require that all data exist in a finite state. All data in memory must be repesented by a fixed set of values, or be null (undefined).

Consider the following statement written in C:

int x = 32;
int y = x + 20;
int x = 12;

This statement creates an integer value of 32 and assigns it to a particular area of memory. It then creates a value of twenty, add it to the value of 32 and assigns that to a different area of memory. Last, it reassigns the first area of memory to a value
of 12. If we evaluate the values for

x and

y, we will find that they hold values of 12 and 52 respectivly. While this may seem perfectly intuitive and logical for most programmers, this can create problems for people who have a "common sense" understanding of math.

Consider the following lines of code in NeturalMath:

x = 32
y = x + 20
x = 12

If we evaluate the memory space associated with the variable

x and

y, we will find something very different that the example above. We would still see that

x was assigned a value of 12, but we would see that

y was actually defined a value of

x plus 20. If we evaluate the result of

y using a print command or some other mechanism we will find that it has a value of 32, not 52 like in the example using C. This is because NeturalMath is based on a concept known
as

*Expressions*.

### Expressions and Values

Whenever a variable is assigned a value in NeturalMath, it is actually assigned an expression. In the example above, the variable y is assigned an expression providing its value as a relationship to

x. This means that as

x changes,

y changes along with it. The actual value of

y is not determined until asked for by the system. As long as nothing directly calls upon

y, its result continues to remain unfixed. The variable

x is also assigned to an expression, however in both cases, this expression is a constant value which never changes in the program.

NeturalMath will actually allow the user to create an expression using values which have not yet been defined by the system or assigned a value. The following example illustrates this concept by first declaring

y in terms of

x, then declaring

z in terms of

y (thereby indirectly defining it through

x).

y = x + 10
z = y * 3
x = 10

If we evaluate these statements using MathConsole we can see the following results:

:> y = x + 10
:> print y
error: unable to evaluate variable 'y' because it depends on variable 'x' which is not set
:> printf y
y = x + 10
:> z = y * 3
:> print z
error: unable to evaluate the variable 'z' because it indirectly depends on variable 'x' which is not set
:> x = 10
:> print x
10
:> printf x
x = 10
:> print y
20
:> printf y
y = x + 10
:> print z
60
:> printf z
z = y * 3

### "Fixing" variable assignments

The expression evaluation capabilities of NeturalMath allows the user to define values in terms of other values. This provides the user with an extensive set of tools to express mathematical concepts in a very intuitive way, but as most programmers will be
quick to point out, this capability comes at a performance cost. There may also be cases where it is undesireable to define values in the terms of other values. In other words, we may actually want the value of

y to be defined as the actual

*result* of

x + 3 rather than the same as an expression. NeturalMath provides the

@ operator to make this possible. The example below shows how this works.

:> x = 10
:> y @= x + 3
:> z = x + 3
:> x = 20
:> print x
20
:> print y
13
:> print z
23