QALC(1) | General Commands Manual | QALC(1) |
qalc - Powerful and easy to use command line calculator
qalc [options] [expression]
Qalculate! is a multi-purpose cross-platform desktop calculator. It is simple to use but provides power and versatility normally reserved for complicated math packages, as well as useful tools for everyday needs (such as currency conversion and percent calculation). Features include a large library of customizable functions, unit calculations and conversion, physical constants, symbolic calculations (including integrals and equations), arbitrary precision, uncertainty propagation, interval arithmetic, plotting, and a user-friendly interface. qalc is the command line interface of Qalculate!.
The program will start in interactive mode if no expression and no file is specified (or interactive mode is explicitly selected).
Commands for RPN mode:
When a line begins with '/', the text that follows is always interpreted as a command.
These settings are changed using the set command (e.g. set base 16) or the -s, --set command line option (e.g. qalc -s "base 16"). Possible values are shown in parenthesis. 1 and 0 can be used instead of on and off, yes and no. If the value is left out, a value of 1 is generally assumed. The default value is marked with '*'.
Algebraic mode:
Calculation:
Enabled objects:
Generic display options:
Numerical display:
Parsing:
Units:
Other:
Mathematical entities:
Numbers
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 explicitly deactivated. 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 "i" (can be changed to a "j"), which represents
the square root of -1. 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 (e.g. "5E3 = 5000"). Sexagesimal
numbers (and time) can be entered directly using colons (e.g. "5:30 =
5.5"). A number immediately preceded "0b", "0o",
"0d" or "0x" are interpreted as a number with base 2, 8,
12 or 16, respectively (e.g. "0x3f = 63").
Intervals
A number interval can be entered using the interval() function, the
uncertainty() function, or using "±" or "+/-"
(e.g. 5±1 = uncertainty(5, 0.2) = interval(4, 6)). If the read
precision option is activated, decimal numbers are interpreted as an
interval between the numbers that are normally rounded to the entered number
(e.g. 1.1 = 1.1±0.05). If interval calculation using variance formula
is activated (default), the interval represents the standard uncertainty
(deviation) of the value.
Vectors and Matrices
A matrix is a two-dimensional rectangular array of mathematical objects.
Vectors are matrices with only one row or column, and thus one-dimensional
sequences of objects. Vectors and matrices are generated by various
functions, or using syntax in the form of [1 2 3 4] and [1 2; 3 4], with
columns separated by space or comma and rows separated by semi-colon, or (1,
2, 3, 4) and ((1, 2), (3, 4)).
Variables/Constants
See the list of variables in the GUI manual or using the command .I list
variables
Functions
See the list of functions in the GUI manual or using the command .I list
functions
Units and Prefixes
See the list of units and prefixes in the GUI manual or using the command .I
list units. Abbreviated, plural and singular forms of unit names and
prefixes are generally allowed. Prefixes must be put immediately before the
unit to be interpreted as prefixes (eg. 5 mm = 0.005 m, but 5 m m = 5 m^2).
For convenience units allow the power operator to be left out (e.g. 5 m2 = 5
m^2), with currencies excluded.
Unknowns
Unknowns are text strings without any associated value. These are temporary
unknown variables with default assumptions. Unknowns can also be explicitly
entered by placing a backslash (\) before a single character (e.g. 5\a +
2\b) or using quotation mark before and after a text string (e.g. 5
"apples" + 2 "bananas"). If unknowns are activated
characters without any associated variable, function or unit in an
expression, will be regarded as an unknown variable.
Date and Time
Date/time values are specified using quoted text string (quotation marks are
not needed for function arguments), using standard date and time format
(YYYY-MM-DDTHH:MM:SS). Some local formats are also supported, but not
recommended. The local time zone are used, unless a time zone is specified
at the end of the time string (Z/UTC/GMT or +/-HH:MM). Date/time supports a
small subset of arithmetic operations. The time units represents calendar
time, instead of average values, when added or subtracted to a date.
Text
This category represent a number of different function argument types, such as
regular text and file names. They can, but do not need to be put in quotes
except when containing the argument separator.
Comments
All text after a hashtag (e.g. (5*2)/2 #calculating triangle area) is treated
as a comment.
Operations and operators (word operators such as AND must be surrounded by space):
Addition (+)
Subtraction (-)
Multiplication (*)
Division (/)
Remainder (%, rem) and modulo (%%, mod)
Returns the remainder after division.
Integer division (//, div)
Rounds the result of division towards zero.
Exponentiation (^, **)
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, and not -2). To
calculate the real root for negative values, use the cbrt() and root()
functions.
10^x (E)
Parenthesis ((, ))
Parellel sum (∥, ||)
Returns the the reciprocal value of a sum of reciprocal values. || is
interpreted as parallel if units are used, otherwise as logical OR.
Logical operators (!, NOT, ||, OR, &&, AND, XOR, NOR, NAND)
Bitwise operators (~, |, &, <<, >>, XOR)
Comparison operators (=, !=, <, <=, >, >=)
Returns 1 if expression is true and 0 if false. The x variable is isolated if
the expression does not evaluate as true or false. Primarily used for
equations and inequalities.
Dot product (.)
Element-wise operators (.*, ./, .^)
Save operator (:=, =)
Saves the expression to the right of the operator as a variable or function
(e.g. var1:=5, func1():=x+y, var1=ln(5)+2). If the colon is omitted the
expression is calculated before it is assigned to the variable.
Evaluation priority order: parenthesis, 10^x, exponentiation, functions, bitwise NOT, logical NOT, multiplication/division/remainder, parallel sum, addition/subtraction, bitwise NOT, bitwise shift, comparisons, bitwise AND, bitwise XOR, bitwise OR, logical AND, logical OR.
The evaluation of short/implicit multiplication without any multiplication sign (e.g. 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)).
In chain mode, expressions are calculated from left to right, ignoring standard order of operations, like the immediate execution mode of a traditional calculator (1+2*3 = (1+2)*3 = 9).
The "to"-operator is used for unit conversion and manipulation of how the result is presented. Place " to " or a right arrow (e.g. "->") followed by one of expressions/commands listed below, at the end of an expression.
Similarly where (or alternatively "/.") can be used at the end (but before "to"), for variable assignments, function replacements, etc. (e.g. "x+y where x=1 and y=2", "x^2=4 where x>0", and "sin(5) where sin()=cos()").
Note that to and where can only be applied to the whole expression. Everything before the operator is always treated as the expression to convert (or apply replacement to), and everything after as the conversion/replacement expression, regardless of any parentheses.
Note that semicolon can be replaced with comma, if comma is not used as decimal or thousands separator.
Basic functions and operators
Units
Physical constants
Uncertainty and interval arithmetic
result with interval arithmetic activated is shown in parenthesis
Algebra
Calculus
Matrices and vectors
Statistics
Time and date
Number bases
The manual of the graphical user interface at https://qalculate.github.io/manual/index.html (includes more details about the syntax and elements supported in mathematical expressions, and various options, and includes a complete list of functions, variables, and units)
Please report any bugs at https://github.com/Qalculate/libqalculate/issues
Hanna Knutsson <hanna.knutsson@protonmail.com>.
13 July 2020 |