
Language Explanation
Overview
This language is designed to be unrestrictive in its nature and to follow basic mathematical notation whenever possible. There are countless expressions one can generate using combinations of the below tokens.
Language
Tokens
A token is a group of characters which, when combined, convey a certain mathematical notion. Many tokens are only one character, such as the + and - operators. Other tokens are a fixed length, such as functions sin and cos. Furthermore, there are variable length tokens such as numbers, which are the concatenation of multiple digits, optionally separated by a decimal point: 4096 and 3.1415.
Types
Different inputs can produce different types. There are only a few types to keep in mind when using Xygos Language: Equation, Expression, and Symbol.
The Equation type is the relation of two abstract mathematical expressions. This type can be produced by the use of the =, <, <=, >, and >= operators where the left- and right-hand-sides may also be of the Equation type.
The Expression type is any mathematical expression that does not contain an equation. Expressions can contain functions and operators, but that is not a requirement. Just an integer, say “0”, is the simplest form of the Expression.
The Symbol type is a single, unsigned – meaning it cannot be negative – letter or Greek letter (or infinity). Note that a Symbol can also be considered an Expression, but the inverse is not true. * Some functions require that they process a Symbol as one or more of their arguments.
Symbols
Letters: all members of the English alphabet are considered Symbols. Conventional variables such as x, y, and z are common use cases for the Symbol type. Other times it is helpful to define an arbitrary constant Symbol (such as a) to use in place of a real number (think Pythagorean Theorem). Conventional mathematical constants such as Euler’s constant (e) and Archimedes’ constant (pi) can also be used as Symbols.
The Greek Alphabet: all Greek letters are also Symbols. To invoke a Greek letter it is required to type its full name (see below).
The exhaustive list of Greek letters: alpha, beta, gamma, delta, epsilon, zeta, eta, theta, iota, kappa, lambda, mu, nu, xi, omicron, pi, rho, sigma, tau, upsilon, phi, chi, psi, and omega. Note that only lowercase Greek letters are supported at this time.
Operators
There are 15 operators, all of which can be described by the number of operands on which they operate.
The unary operators are those which apply only to one operand. Some precede their argument while others succeed their argument.
+ defines a positive expression.
Example: +2
Note that this is equivalent to 2. If no negative sign is prepended to a term, it is inferred to be positive.
– defines a negative expression.
Example: -x
! is the factorial operator.
Example: 3!
‘ is our very own derivative operator, taking influence from the prime notation often used in Calculus contexts.
Example: y’
The binary operators apply to two operands.
= defines an equality between two equations.
Example: a^2 + b^2 = c^2
< defines an inequality between two equations, where the left-hand-side is less than the right-hand-side.
Example: ln(2) < sqrt(2)
<= defines an inequality between two equations, where the left-hand-side is less than or equal to the right-hand-side.
Example: 0! <= 1
> defines an inequality between two equations, where the left-hand-side is greater than the right-hand-side.
Example: 3 > 2
>= defines an inequality between two equations, where the left-hand-side is greater than or equal to the right-hand-side.
Example: y >= -x
+ defines a sum between two expressions. (This is the same token as its unary counterpart!)
Example: a + b
– defines a difference between two expressions. (This is the same token as its unary counterpart!)
Example: pi - e
% defines a modulo between two expressions.
Example: 16 % 5
/ defines a quotient between two expressions.
Example: 1/2
* defines a product between two expressions.
Example: 2*5
^ defines a power between two expressions, where the left-hand-side is the base and the right-hand-side is the exponent.
Example: e^x
Note that this operator is right-associative, meaning that consecutive powers are consumed right to left. Here is an example to illustrate: 2^3^4 = 2^(3^4).
*All relational operators (=, <, <=, >, and >=) can be chained together. This means equations like pi > 3 > e are possible.
Operator Precedence
Operators have different precedences. This means that some take priority over others. This system should reinforce that which you have learned throughout algebra. The only exception is the division (/) operator, which has a lower precedence than multiplication (*) in Xygos Language. Here is a descending hierarchy of the precedence system. The smaller the number, the greater the precedence:
! (factorial), ‘ (derivative)
^ (power)
+ (unary plus), - (unary minus)
* (multiplication)
/ (division)
% (modulus)
+ (binary plus), - (binary minus)
= (equals), < (less-than), <= (less-than-or-equals), > (greater-than), >= (greater-than-or-equals)
Here are a few examples to better illustrate the different precedence levels of the operators:
x + 1 <= 2 is equivalent to (x + 1) <= 2.
-5 * x - 6 = x^2 is equivalent to (((-5) * x) - 6) = (x^2).
a*b/c*d is equivalent to (a*b)/(c*d).
-x! is equivalent to -(x!).
Mathematical Functions
The standard set of mathematical functions are included by default. These inclusions span the branches of trigonometry to number theory, yet are not exhaustive.
sin - the trigonometric sine function; operates on an Expression; candidate for parenthesis omittance.
Example: sin(pi/6)
cos - the trigonometric cosine function; operates on an Expression; candidate for parenthesis omittance.
Example: cos(pi/4)
tan - the trigonometric tangent function; operates on an Expression; candidate for parenthesis omittance.
Example: tan(pi/3)
csc - the trigonometric cosecant function; operates on an Expression; candidate for parenthesis omittance.
Example: csc(x)
sec - the trigonometric secant function; operates on an Expression; candidate for parenthesis omittance.
Example: sec(y)
cot - the trigonometric cotangent function; operates on an Expression; candidate for parenthesis omittance.
Example: cot(z)
asin/arcsin - the trigonometric inverse sine function; operates on an Expression; candidate for parenthesis omittance.
Example: arcsin(t^2 + 1)
acos/arccos - the trigonometric inverse cosine function; operates on an Expression; candidate for parenthesis omittance.
Example: arccos(u)
atan/arctan - the trigonometric inverse tangent function; operates on an Expression; candidate for parenthesis omittance.
Example: arctan(w - pi)
acsc/arccsc - the trigonometric inverse cosecant function; operates on an Expression; candidate for parenthesis omittance.
Example: arccsc(-1)
asec/arcsec - the trigonometric inverse secant function; operates on an Expression; candidate for parenthesis omittance.
Example: arcsec(1)
acot/arccot - the trigonometric inverse cotangent function; operates on an Expression; candidate for parenthesis omittance.
Example: arccot(0)
abs - the absolute value function; operates on an Expression; candidate for parenthesis omittance.
Example: abs(x)
exp - the natural exponential function; operates on an Expression; candidate for parenthesis omittance.
Example: exp(x)
log - the logarithm function; operates on Expressions; candidate for parenthesis omittance.
This function can be called with one or two argument(s). The single argument version is inferred to be a base 10 logarithm. The double argument version uses the first argument as the base and the second argument as the operand.
Single argument example: log(x) is the base-10 logarithm of x.
Double argument example: log(2, x) is the base-2 logarithm of x.
ln - the natural logarithm function; operates on an Expression; candidate for parenthesis omittance.
Example: ln(x)
sqrt - the square root function; operates on an Expression; candidate for parenthesis omittance.
Example: sqrt(x)
cbrt - the cube root function; operates on an Expression; candidate for parenthesis omittance.
Example: cbrt(x)
floor - the floor function; operates on an Expression; candidate for parenthesis omittance.
Example: floor(x)
ceil - the ceiling function; operates on an Expression; candidate for parenthesis omittance.
Example: ceil(x)
min - the minimum function; operates on Expressions.
Operates on two or more arguments.
Example: min(x, y)
max - the maximum function; operates on Expressions.
Operates on two or more arguments.
Example: max(x, y, z)
Standard Functions
There are more functions, too. These are tailored to your needs here at Xygos.
lim - defines the two-dimensional limit of an expression.
See below for details.
diff - defines the derivative of an expression, with respect to some variable.
See below for details.
pdiff - defines the partial derivative of an expression, with respect to some variable.
Details coming soon!
int - defines the indefinite/definite integral of an expression, with respect to some variable.
See below for details.
sum - defines the summation, from the lower to upper bounds, of an expression.
Details coming soon!
piecewise - defines a piecewise function.
Details coming soon!
Quirks
Parenthesis Omittance – Functions that expect one argument do not require a pair of parentheses after the name, surrounding the argument. For example, the sine function expects one argument and as such can be written as sinx. Note that when parentheses are omitted the function will bind to expressions with level 3 (see above) precedence or higher. sin -x is equivalent to sin(-x) while sin 3x is equivalent to sin(3)*x.
An added bonus with parenthesis omittance is the idea of function chaining. Complicated composite functions can be written without many layers of nested parentheses, granted the functions qualify for parenthesis omittance. As an example, sinsqrtx is valid syntax and defines the square root of x composed within the sine function. Though it is easier to read when tokens are separated (sin sqrt x).
Case Insensitivity – As an aside, it is beneficial to know that syntax is case insensitive. This means that expressions like pi, Pi, pI, and PI are all equivalent.
Automatically Balanced Parentheses – When writing complicated expressions it is common to have many layers of parentheses. With automatic parenthesis balancing it is not required to close parenthesis pairs (the whole input must be syntactically valid). This means lim(x, 1, (x^2 - 1)/(x - 1 is accepted (equivalent to lim(x, 1, (x^2 - 1)/(x - 1))). The two trailing parentheses are matched to their closest unmatched leading parentheses.
Implicit Multiplication – Implicit multiplication occurs between two expressions that are not separated by an operator. In an effort to keep expressions terse, implicit multiplication steps in to assist. Expressions such as 2*x^2 + 17*x + 21 can be short handed as 2x^2 + 17x + 21. It is even possible to utilize implicit multiplication between Symbols. Consider x * y; it is often helpful to write xy instead. This becomes even more beneficial when considering multiplication with functions. xsin(x) is interpreted as x*sin(x).
Scientific Notation – It is valid to express large quantities using scientific notation. With Xygos Language, scientific notation is composed of three parts: the mantissa, “e”, and the exponent. For example, 1.25e10 represents 1.25 * 10^10. For all intents and purposes, the mantissa is the number that precedes “e”, in this case: “1.25”. The exponent can be negative but is expected to be an integer.
Syntax Examples
Limits
The playground mode can be a powerful tool in your conquest of limits. There are many, many examples out there that can hone your algebraic skills. We will not provide any novel examples in this section, but we will show you how to utilize the syntax of the limit function in order to explore a wider variety of expressions.
There are three main components to the “lim” function – the limit variable, limiting number, and the expression whose limit is under analysis. The limit variable must be a Symbol type, that is, x, y, z, etc. The limiting number is an Expression which does not depend on the limit variable. The analyzed function is another Expression. These three components – limit variable, limiting number, and function – are placeholders for the arguments of the limit (in the stated order). Consider the examples below:
lim(x, 0, x) is the limit of x as x approaches 0.
lim(x, pi/3, sin(x)) is the limit of sin(x) as x approaches pi/3.
lim(t, (1 - sqrt(5))/2, t^2 - t - 1) is the limit of t^2 - t - 1 as t approaches (1 - sqrt(5))/2.
lim(theta, pi/2, 2sin(theta)) is the limit of sin(theta) as theta approaches pi/2.
But what about directed limits? So far, we looked only at undirected limits – those where the limit is approached from both left- and right-hand-sides. Now it is time to look strictly at limits approached from either side.
lim(x, 0 +, 1/x) is the limit of 1/x as x approaches 0 from the right. Notice the extra “+” operator at the end of the second argument. The syntax is very similar for limits approached from the left. lim(x, pi/2 -, tan(x)) is the limit of tan(x) as x approaches pi/2 from the left.
Derivatives
After limits come derivatives. To solve for the derivative of an expression, utilize the “diff” function. It expects one or two argument(s). If invoked with only one argument, the variable of differentiation is inferred; but it can be overridden using the second argument. The expression to differentiate must be an Expression. The differentiation variable must be a Symbol type.
diff(x^2, x) differentiates x^2 with respect to x.
diff(x*sin(x)) differentiates x*sin(x) with respect to x (inferred).
diff(x + y*e^x) differentiates x + y*e^x with respect to x (inferred).
diff(5t^2 - 6t + 12) differentiates 5t^2 - 6t + 12 with respect to t (inferred).
Once you have mastered this section, check out the integrals section.
Integrals
Another big part of Calculus is the idea of the integral. To get comfortable with this idea, work through many problems in the playground mode. This documentation section has two dedicated sub-sections. The first explores the syntax and examples of the indefinite integral and the second tours the definite integral. The syntax is built to complement each other.
Indefinite integrals can be evaluated using the “int” function with two arguments. The first argument is an Expression and defines the integrand, or function to integrate, and the second argument is the integration variable, a Symbol. Note that, unlike derivatives, the integration variable cannot be inferred.
int(2x, x) is the indefinite integral of 2x with respect to x.
int(cos(theta), theta) is the indefinite integral of cos(theta) with respect to theta.
int(2z + 3y - 5, x) is the indefinite integral of 2z + 3y - 5 with respect to x.
Definite integrals are also evaluated using the “int” function. This time, we pass in four arguments. The first two remain the same – they represent the integrand and integration variable. The third argument represents the lower bound while the fourth represents the upper bound. Note that the bounds must be Expressions and cannot depend on the integration variable.
int(x, x, 0, 10) is the definite integral of x with respect to x from x = 0 to 10.
int(sin(x), x, 0, pi) is the definite integral of sin(x) with respect to x from x = 0 to pi.
int(1/t, t, 1, x) is the definite integral of 1/t with respect to t from t = 1 to x.