Expressions are mathematical statements. Mathematical questions are asked through expressions, which contains objects tied together with operators. The result of an expression may also be an expression, if the result is not a single object. Apples and oranges can be mixed, but the result will hold them apart. Qalculate! knows algebra.
In Qalculate! mathematical entities, such as numbers and variables, are referred to as objects. The recognized object types are listed below.
These are the regular numbers composed by digits 0-9 and a decimal sign — a dot, or a comma if it is the default decimal point in the locale/language used. If comma is used as decimal sign, the dot is still kept as an alternative decimal sign, if not explicitely turned off in the preferences dialog with “i”, which represents the square root of -1 (ex. “2 + 3i”). Spaces between digits are ignored (“5 5 = 55”). “E” (or “e”) can be considered as a shortcut for writing many zeroes and is equivalent to multiplication by 10 raised to the power of the right-hand value (ex. “5E3 = 5000”).(to allow it to be used as thousand separator instead). Numbers include integers, real numbers, and complex numbers. The imaginary part of complex numbers are written with as regular number followed by the special variable
Sexagesimal numbers (and time) can be entered directly using colons (ex. “5:30 = 5.5”). A number immediately preceeded “0b”, “0o” or “0x” are interpreted as a number with base 2, 8 or 16, respectively (if the default base is 10, ex. “0x3f = 63”). The number base in can also be selected, either by using the base(), bin(), oct(), hex() and roman() functions, or by setting the base used for all numbers in the whole expression from → → .
A matrix is a two-dimensional rectangular array of mathematical objects. Vectors are matrices with only one row or column, thus one-dimensional sequences of objects, Vectors and matrices are generated by vector(), matrix() and similar functions, or stored in a variable. Syntax in the form of “[1, 2, 3, 4]” and “[[1, 2], [3, 4]]” can also be used.
See Chapter 5, Variables.
See Chapter 6, Functions.
Qalculate! understands abbreviated, plural and singular forms of unit names and prefixes. Prefixes must be put immediately before the unit to be interpreted as prefixes — “5 mm = 0.005 m”, but “5 m m = 5 m^2”. Also, for convenience units allow the power operator to be left out. A number following immediately after a unit is interpreted as an exponent (ex. “5 m2 = 5 m^2”). This does not apply to currencies, as they might be put in front of the quantity. More information in Chapter 7, Units.
Unknowns are text strings without any associated value. If Qalculate! finds a character that are not associated with any variable, function or unit in an expression, then it will be regarded as an unknown variable. These are temporary unknown variables with default assumptions. Unknowns can also be explicitly entered by putting a text string in quotes. This is also necessary for undefined unknown variables with more than one character (ex.“xy” is just one object, while xy means x * y). See Chapter 5, Variables.
This category represent a number of different function argument types, such as regular text, dates and file names. They can, but do not need to be put in quotes except when containing the argument separator (“,” or “;”).
To avoid confusion, functions, units, variables and unknown variables can independently be disabled.
Variables, functions and units are all accessible in the menus and in the variable, function and unit managers, If their names are not remembered. Functions accessed this way has some extra conveniences. If the function has at least one argument, a dialog will pop up where arguments can be entered and a description of the function and its arguments is available.
Qalculate! can handle most commonly used symbols for certain variables, functions and units, even though most are difficult to find on a keyboard. These include π for pi, √ for sqrt, € for euro, and so on. Most importantly it is possible to copy these symbols when used in the result.
The following operators are defined in Qalculate! and may be used in expressions.
Table 3.1. Operators
Adds the right value to the left value.
1 + 1
Subtracts the right value from the left value.
1 − 1
⋅ or *
Multiplies the left value by the right value.
2 * 2
Divides the left value by the right value.
2 / 2
Raises the left value by the right value. Can also be typed as “**”. Note that x^y^z equals x^(y^z), and not (x^y)^z. Note also that for non-integer exponents with negative bases, the principal root is returned and not the real root (“(-8)^(1/3)” equals “1 + 1.73i” instead of -2). To calculate the real root for negative values, use the cbrt() and root() functions.
Multiplies the left value with 10 raised to the power of the right value. Equivalent to the exponential number format in result display. E is as much an operator as part of numbers.
( and )
Evaluates the expression in parenthesis first.
5 * (1 + 1)
Returns 1 for true, if the left value is is less than the right, and 0 for false.
1 < 2
Returns 1 for true, if the left value is greater than the right, and 0 for false.
Less than or equal
≤ or <=
Returns 1 for true, if the left value is less than or equal the right, and 0 for false.
1 <= 2
Greater than or equal
≥ or >=
Returns 1 for true, if the left value is greater than or equal the right, and 0 for false.
1 >= 2
Returns 1 for true, if the left value equals the right, and 0 for false.
1 = 2
≠ or !=
Returns 1 for true, if the left value not equals the right, and 0 for false.
1 != 2
Returns 1 for true, if the value to the right is false, and 0 for false.
|| or OR
Returns 1 for true, if the right or left value is true, and 0 for false.
1>2 || 2>1
&& or AND
Returns 1 for true, if the right and left value is true, and 0 for false.
1>2 && 2>1
Equivalent to -1-x.
~(0010 | 1100)
Bitwise Shift Left
Shifts the bits of the left value x steps to the left, where x is the value on the right. Implemented as a shortcut for shift()
0011 << 1
Bitwise Shift Right
Shifts the bits of the left value x steps to the right, where x is the value on the right. Implemented as a shortcut for shift()
0011 << 1
If a bit is 1 in one of the numbers set it to 1, otherwise 0. Also functions as elementwise logical operator on vectors.
0010 | 1100
If a bit is 1 in both numbers set it to 1, otherwise 0. Also functions as elementwise logical operator on vectors.
1010 & 0011
The operator names “plus”, “minus”, “times”, “per”, “AND” and “OR” may also be used, surrounded by space, for the corresponding operation (ex. “5 plus 2”, but not “5plus2”, equals “5 + 2”). These operator names are localized, but “AND” and “OR” are always available. In addition to these operators there are a couple of shortcuts for certain functions, such as “5!” which equals “factorial(5)”.
The multiplication sign can generally be left out. This is not true for numbers (“5(5) = 25” but “5 5 = 55”). Expressions can also generally be written with or without spaces with the same result (“2xsin(2)” equals “2 x sin(2)” which equals “2*x*sin(2)”), but be careful. The vast number of functions and units means that without separating spaces, the result might not be obvious. To avoid confusion Qalculate! can limit the use of implicit multiplication ( → ), so that space, operator or parenthesis must be put between functions, units and variables (in this mode “esqrt(5)” does not equal “e * sqrt(5)”). Also note that unit prefixes must be put immediately before the unit, to be interpreted as prefixes (“5 mm = 0.005 m”, but “5 m m = 5m^2”). You can see how to expression was interpreted in the history window.
Usually, mathematical expressions are written as normally expected. Standard operator precedence apply. Expressions are evaluated according to the following priorities:
Functions (ex. “sqrt(2)”)
Multiplication and division (*, /)
Addition and subtraction (+, −)
Bitwise NOT (~)
<< and >>
Bitwise AND (&)
Bitwise OR (|)
Comparison (>, <, =, >=, <=)
Logical NOT (!)
Logical AND (&&)
Logical OR (||)
The evaluation of short/implicit multiplication, without any multiplication sign (ex. “5x”, “5(2+3)”), differs depending on the parsing mode. In the conventional mode implicit multiplication does not differ from explicit multiplication (“12/2(1+2) = 12/2*3 = 18”, “5x/5y = 5*x/5*y = xy”). In the “parse implicit multiplication first” mode, implicit multiplication is parsed before explicit multiplication (“12/2(1+2) = 12/(2*3) = 2”, “5x/5y = (5*x)/(5*y) = x/y”). The default adaptive mode works as the “parse implicit multiplication first” mode, unless spaces are found (“1/5x = 1/(5*x)”, but “1/5 x = (1/5)*x”). In the adaptive mode unit expressions are parsed separately (“5 m/5 m/s = (5*m)/(5*(m/s)) = 1 s”). Function arguments without parentheses are an exception, where implicit multiplication in front of variables and units is parsed first regardless of mode (“sqrt 2x = sqrt(2x)”).
If the limit implicit multiplication option is activated, the use of implicit multiplication when parsing expressions and displaying results will be limited to avoid confusion. For example, if this mode is not activated and “integrte(5x)” is accidently typed instead of “integrate(5x)”, the expression is interpreted as “int(e * e * (5 * x) * gr * t)” (displayed in history window). The result will then without any error be “int(2.3940139x * km^2)” instead of “2.5x^2”. If limit implicit multiplication is activated, the mistyped expression would instead show an error telling that “integrte” is not a valid variable, function or unit (unless unknowns is enabled in which case the result will be “5 "integrate" * x”). When implicit multiplication is limited, variables, functions and units must be separated by a space, operator or parenthesis (“xy” does not equal “x * y”).
Putting “ to ” followed by an expression at the end of the mathematical expression is mainly used for unit conversion (see the section called “Conversion”). There are however also some convenient commands that can be typed after “ to ”. Here is a list of possible “to” values:
Convert to unit (e.g. meter, prepend with ? to request the optimal prefix).
Convert to units (e.g. km/h).
Convert to base units.
Convert to optimal unit.
Convert to mixed units (e.g. 5 ft + 8 in).
Show as binary number.
Show as octal number.
Show as hexadecimal number.
Show as binary, octal, decimal and hexadecimal number (opens convert bases dialog with the mathematical expression).
Show as number in combined fractional format.
Show factorized (algebraic or integer factorization).