# Equations

Description | Operators | Functions | Variable Methods | Series Manipulation | Psuedo-Logic | See Also

## Description

Since Version 1.1 Draco uses JRuby, a pure Java implementation of the Ruby scripting language, for parsing and solving all equations. Draco's JRuby equation evaluator supports all standard mathematics operators and uses standard order of operations rules.

## Operators

Draco's JRuby implementation supports the following operators and symbols:

Operator | Description
+ | Addition
- | Subtraction
* | Multiplication
/ | Division
** | Power
% | Modulus
( and ) | Parentheses

## Functions

The following basic mathematical functions are available:

Function(x) | Description
abs(x) | Absolute Value
acos(x) | Arc-cosine in radians
acosh(x) | Hyperbolic arc-cosine
asin(x) | Arc-sine in radians
asinh(x) | Hyperbolic arc-sine
atan(x) | Arc-tangent in radians
atan2(y,x) | Arc-tangent of x/y in radians
atanh(x) | Hyperbolic arc-tangent
ceil(x) | Rounded-up value of a floating point number
cos(x) | Cosine of value x (in radians)
cosh(x) | Hyperbolic cosine
erf(x) | Error function of x
erfc(x) | Complimentary error function of x
exp(x) | Exponential (ex)
fact(x) | Factorial
floor(x) | Rounded-down value of a floating point number
hypot(x,y) | Returns the hypotenuse, or sqrt(x**2+y**2)
log(x) | Natural logarithm
log10(x) | Base-10 logarithm
pi() | Value of pi (~3.14...)
rand() | Random floating point value between 0 (inclusive) and 1 (non-inclusive)
round(x) | Rounded-to-nearest-whole value of a floating point number
sign(x) | Returns -1 for negatives, 1 for all others
sin(x) | Sine of x (in radians)
sinh(x) | Hyperbolic sine
sqrt(x) | Square root
tan(x) | Tangent of x in radians
tanh(x) | Hyperbolic tangent

## Variable Methods

Special functions are available for use with variables only. The following functions can be called with any single variable as an argument:

Function | Description
count(var) | Returns the number of observations in a given variable
max(var) | Returns the largest value in a given variable
mean(var) | Computes the mean of the variable
median(var) | Computes the median of the variable
min(var) | Returns the smallest value in a given variable
stdev(var) | Computes the standard deviation of a variable

## Series Manipulation

Draco provides the following functions for series manipulation. These functions are only applicable when setting column values.

Function | Description
back(x1[,x2]) | Inserts the value of variable x1 either 1 step back from the current step, or x2 steps back if x2 is specified.
front(x1[,x2]) | Inserts the value of variable x1 either 1 step forward from the current step, or x2 steps back if x2 is specified.

As an example of the above functions, consider the following variable:

ser0
1
2
3
4
5

If a new variable is created using back(ser0), the data set becomes:

ser0 | ser1
1 |
2 | 1
3 | 2
4 | 3
5 | 4

If a new variable is created using back(ser0,2), the data set becomes:

ser0 | ser1
1 |
2 |
3 | 1
4 | 2
5 | 3

## Logic

Draco previously employed a psuedo-logic system for computing conditional values. The introduction of JRuby for all equation evaluation has removed the need for psuedo-logic.
Any valid JRuby construct can be used for logic. For example, consider the following conditional to be evaluated:
`if(ser0 > 0) do
2*ser0
end
`
In the above example, the selected variable will evaluate to twice the equivalent observation in ser0 when ser0 is greater than zero. All other times, the variable will evaluate to nothing (nil in JRuby). JRuby also supports another syntax for fast, simple logical operations:
`2*ser0 if(ser0 > 0)`
The single line above performs the identical operation as the multiline condition described previously. Furthermore, JRuby also contains the unless keyword (the opposite of if):
`2*ser0 unless(ser0 <= 0)`
The statement above is equivalent to the other two examples.
Logic operators include the following:

Operator | Description
and | Logical AND
not | Logical negation
or | Logical OR
> | Greater than
>= | Greater than or equal to
< | Less than
<= | Less than or equal to
== | Equal
!= | Not equal

## See Also

Variables
Constants Windows
Programming Ruby (Offsite)

Copyright © 2008 Approximatrix, LLC
Text licensed under the Creative Commons Attribution-Share Alike 3.0 License
DracoTM and the Approximatrix logo are trademarks of Approximatrix, LLC
Other trademarks are property of their respective owners