Halcyon Calc - Working With Expressions

One of the key features of Halcyon Calc is its ability to manipulate symbolic expressions. Working with these expressions is described in the following sections:

Entering Expressions:

There are two fundamental ways to enter an expression. You can either type the expression in directly into the command line or you can put your symbols and numbers onto the stack and execute the operations you want on them, slowly building up an expression. In fact, you can mix these two methods together when building very large, complicated expressions.

To enter an expression at the command line, start your expression with the "'" character and then hit the appropriate buttons to type the expression you want. When you start the expression with a single quote, the calculator will switch to algebraic mode (as described in the command line section of the UI Guide). You can rely on that behaviour to assist you when building expressions.

By way of an example, imagine that you want to enter the expression: X3 * sin(Y). To enter this on the command line, press "'", "X", "■^", "3", "x" (multiply), "SIN", "Y" and finally "Enter". The assumption here is that the "Trig" menu is already displayed and the "SIN" button is visible. When you press the different button operations in this example ("■^", "x" and "SIN"), the calculator did not execute the operation but instead appended the operation onto the command line. Before pressing "Enter", the command line should look like:

'X^3*SIN(Y

Note that the closing bracket and the closing single quote is left out. The calculator will fill those in at the end of the expression as required but you can provide them also. After pressing "Enter", the stack will show the expression:

'X^3*SIN(Y)'

The alternate way to build an expression is to push the symbols and numbers onto the stack in the order you want them evaluated and apply the operations to them. So, to build the same expression this way, you could do the following:

  1. Push the symbol 'X' onto the stack.
  2. Push the number "3" onto the stack.
  3. Execute the "■^" operation. This will pop those two items from the stack and perform the power operation on them. Because 'X' is a symbol, the result is an expression in X. Specifically, 'X^3' is pushed onto the stack.
  4. Push the symbol 'Y' onto the stack.
  5. Execute the "SIN" operation. This will pop 'Y' off the stack and perform the sine operation on that symbol. But, because it is working with a symbol, the result is an expression in Y. Specifically, 'SIN(Y)' is pushed onto the stack.
  6. Finally, execute the "x" (multiply) operation. This will pop 'X^3' and 'SIN(Y)' from the stack and perform the multiply on these items. Because both are expressions, the result will also be an expression. Specifically, 'X^3*SIN(Y)' is pushed onto the stack.

The interesting thing is that entering an expression at the command line uses the normal "left to right" syntax which people are used to for mathematical expressions. You can take advantage of this and enter expressions without any symbols if you prefer to work in a non-RPN mode. So, if you want to multiply 10.32 by 23.74, you could enter the expression '10.32*23.74' and then evaluate it. Building an expression one operation at a time is essentially the RPN way of working where you put the arguments you want onto the stack and then operate on them. In this case, some or all of those arguments are symbols or other expressions. Which you use depends on what you find most convenient.

Operator Precedence:

When looking at an expression, it may not be immediately obvious which operations occur in which order. The precedence rules determine this order. The higher the number in the following list, the higher the precedence. An operation with higher precedence will be evaluated first. Operations with equal precedence are evaluated from left to right. You can use brackets to override this evaluation order since the sub-expression in the brackets is evaluated first. The operator precedence order is:

  1. =
  2. OR, XOR
  3. AND, NOT
  4. <, >, ==, , ,
  5. + (add), - (subtract)
  6. x (multiply), / (divide), - (unary negation)
  7. ^ (power),
  8. All other operations not listed here.

An example of unary negation might be '-X' which means the value of X negated. The symbol is the same as subtract but the calculator can tell whether the operation is unary negation or subtraction from the context.

When entering an expression into the command line, make sure you use brackets as necessary to ensure that the expression is evaluated in the order you intend. If you want an operation with lower precedence evaluated before an operation of higher precedence, you must put the operation with lower precedence and its arguments in brackets. If you are building the expression by applying operations to symbols and numbers on the stack, the calculator adds brackets as necessary to ensure that the expression is evaluated in the order in which you execute the operations while building the expression.

Equations:

An expression with a = operation in it is special and is an equation. The equation describes a relationship between the left side and the right side of the expression. When you apply operations to an equation, the calculator does things differently.

Imagine you have the equation 'X=Y' on the stack and then push the number 3. Then, you execute the + operation. The operation is adding 3 to the equation 'X=Y'. What the calculator does is add three to both sides of the equation to preserve the relationship and pushes the result 'X+3=Y+3'.

Instead, if you have two equations on the stack, 'A=B' and 'C=D' and then execute the + operation, the calculator produces the result 'A+C=B+D'. It adds the left side of each equation and the right side of each equation to produce a result which preserves the relationship. In these examples, the + operation is used to illustrate the point. This works for any operation you can apply to an expression.

Evaluating Expressions:

Once you have created an expression, you probably would like to calculate the value of that expression for some specific values of the symbols. There are three different ways to do so. The first method is to use the "Eval" button. To do this, you first need to store the values you want into the symbols involved. The values can be real numbers, complex numbers or just about anything else. In fact, you can store another expression into one or more of these symbols which would allow you to substitute that new expression for that symbol in the target expression.

Once you have stored the values you want, make sure the expression you want to evaluate is at the top of the stack and press the "Eval" button. That will execute the EVAL operation which pops the expression off of the stack and then looks up the value of any symbol which appears in the expression. If a symbol has a value, its value is substituted into the expression. If the value is itself another symbol or expression, that value is not evaluated. It is just substituted. If the symbol it looks up has no value, then the symbol will remain in the expression. If one of the global constants on the calculator appears in the expression (e, i and π), they will not be replaced with their value but will remain in the expression in symbolic form.

Then, any operations which now have non-symbolic inputs will be evaluated. If possible, the result of "Eval" will be a numeric value. But, if some symbols remain, the result will still be an expression.

Alternatively, you can press the "■→Num" button which executes the →NUM operation. It does almost the exact same thing as executing "Eval", except any global constants (e, i and π) will be replaced by their numeric value. So, use "Eval" if you would like these global constants to remain in the expression and use "→Num" if you want a numeric result.

But, that can make evaluating an expression for different input values difficult. You must store your different input values in each symbol and then evaluate the expression. Also, the expression is popped off the stack so if you did not leave a copy on the stack, you will have to recall it from a variable (if you stored it in one), recall it using "Last" or re-enter it. A simpler way is to use the solver.

The first step in using the solver is to build the expression you would like to work with and put it on the top of the stack. Then, press the "Solv" button, opening the solve menu. Execute the "STEQ operation. This takes the expression from the top of the stack and stores it into a variable called 'EQ', short for equation. Then, execute the "SOLVR operation to use the solver on that equation.

In the solver, you will find that the menu buttons have changed. First, you will see a button for each symbol which appears in the expression. If the expression is an equation, you will then see a "LEFT=" and "RIGHT=" button. If the expression has no = operation in it, then you will just see an "EXPR=" button.

To set a symbol to a particular value, push that value onto the stack and then press the button for the symbol. On the button press, the value is popped off of the stack and stored into that symbol. Do that for each symbol you would like to set. If you are working on an equation, you can press the "LEFT=" and "RIGHT=" to evaluate the left and right hand side of the equation. If the expression is not an equation, you can press the "EXPR=" button to evaluate that expression for those values. The result will be numeric if each symbol has a numeric value. If one or more symbols do not have a value, the result will be an expression in terms of those symbols.

In this mode, you can quickly change the value of your input symbols and generate results for different inputs quickly. Later, you will see how to find the roots of expressions in the solver also.

Solving Quadratic Equations:

A quadratic polynomial can be solved by the calculator directly. To do so, push the expression which is quadratic in some symbol onto the stack. Then push the symbol you would like to solve for and execute the QUAD operation from the "Solv" menu. The roots of the quadratic will be pushed onto the stack as an expression. The result has a positive and a negative root which is expressed in the single expression by using a "s1" symbol. By setting "s1" to 1, the positive root can be evaluated and setting it to -1, the negative root can be found.

As an example, if you solve this quadratic equation in X:

'A*SQ(X)+B*X+C'

the calculator will push this result:

'(-B+s1*√(SQ(B)-4*A*C))/(2*A)'

That is the canonical solution for the roots to the quadratic equation, where s1 represents the ± which appears in the solution.

Note that it will also work with an expression which looks like '(X-3)*(X+8)'. The expression can contain non-polynomial operation like trig and logarithms as long as they are not evaluated in terms of the symbol being solved for. So, '(X-3)*(X+8)/SIN(Y)' is still a quadratic in X (but not in Y).

Finally, QUAD will also work on any polynomial of degree two or more. However, it treats any polynomial as a quadratic and discards the higher degree terms. The answer it provides in those cases is probably not too useful.

Isolating A Symbol In An Expression:

In many cases, you would like to re-arrange an expression so that an expression of some variable (for example, X) is expressed as X=something. The ISOL operation from the "Solv" menu allows you to do this. The key restriction is that the symbol must appear only once in the expression for the result to be an expression independent of that symbol. If the symbol being isolated appears multiple times, only its first appearance in the expression is isolated so the result will still have that symbol in it. For example, the equation 'X+X=3' would result in '3-X', isolating the first X which appears.

If the expression being operated on is not an equation, then an "=0" is appended to make it an equation.

To execute the operation, push the target expression and then the symbol being isolated on the stack. After executing ISOL, those two values will be popped off of the stack and the resulting expression will be pushed onto the stack.

The other restriction is that all operations which must be inverted to isolate the symbol but be "invertible". For example, the inverse of + is -. The inverse of ASIN is SIN. Some inverse operations are expressions and may include "s1", "s2", etc symbols to represent +1/-1 possibilities. Or, they may contain "n1", "n2", etc symbols which represent a periodic solution where you can evaluate them an an infinite number of integer values.

To find a list of invertible functions, refer to the Invertible Operations page.

Finding Roots Of An Expression:

A common operation on an expression is to find a value for a symbol for which the expression evaluates to zero. These are call roots of the expression and the calculator can be used to find these roots. You can either use the ROOT operation from the "Solv" menu or use the solver described in the section on evaluating expressions.

To use the ROOT operation, push the expression you are working with onto the stack, then the symbol for which you would like to find a root, and finally a guess where that root may lie (a great way to find good guesses is to plot the expression - refer to the Working With Plots guide for more information). At a minimum, provide a single real number which is likely near the root. Better, provide a list of two or three real numbers around the root. The algorithm should perform better with more guesses. After executing the operation, the root will be pushed onto the stack. In some cases, the algorithm may run for a very long time and never converge onto a root. In that case, you can press the "Attn" button to interrupt execution. Or, the algorithm may result in an error saying it could not find a root. It could be there is no real root or maybe you should try to improve your guesses.

You can also use the solver to find roots. First, push your guess(es) onto the stack. If you have a single guess, push that real number. If you have two or three guesses, push a list of those real numbers onto the stack. Press the button representing the symbol you would like to solve for to store that guess into the symbol. You do want to store the list into the symbol if you are providing multiple guesses. The press the "" (red shift) button and then the button representing the symbol you would like to solve for. By pressing "■<symbol>", you are instructing the calculator to find a root for that symbol. Again, the search for the root may not be successful and you may have to interrupt it with "Attn" or the calculator may produce an error. If so, refine your guesses and try again. Hopefully, the value of the root will be pushed onto the stack and the calculator will pop up a message to say a root was found. That value is also stored in the symbol itself so you can now evaluate the expression and see that it evaluates to zero (or very nearly zero).

Finding Maxima And Minima Of An Expression:

The solver can be used to find a maximum or a minimum of an expression. To search for a max or min, you must provide a list of three guesses (a great way to find good guesses is to plot the expression - refer to the Working With Plots guide for more information). The lowest and the highest guess must be on either side of the maximum or the minimum and the middle guess should be closer to the max or min than the other two. Create a list with those guesses in it. The guesses can appear in the list in any order.

Press the button representing the symbol you would like to search for a maximum or a minimum in order to store that guess into the symbol. The press the "" (red shift) button and then the button representing the symbol you would like to search. By pressing "■<symbol>", you are instructing the calculator to search for a maximum or a minimum. Note that this is the same method used to search for roots. As long as the three guesses are provided and those guesses surround a maximum or a minimum, the algorithm should return that maximum or minimum. If fewer than three guesses are provided or the guesses do not surround a max or min value, the calculator will search for a root.

The search for the maximum or minimum may not be successful and you may have to interrupt it with "Attn" or the calculator may produce an error. If so, refine your guesses and try again. Hopefully, the calculator does find a maximum or minimum value in which case it pushes the value for the symbol where the max or min was found and pops up a message to say what was found. Also, that value is stored into the symbol replacing the guess which was there before. Evaluate the expression to get the its value at the maximum or minimum found.

Note that this is a local maximum or minimum point. There may be other maxima or minima and there is no guarantee that this is the global maximum or global minimum for the expression.

Manipulating Expressions:

There are many operations which you can use when working with expressions: