Context Operator Table
The operators available to be used in student answers are controlled via the operators
object of the current Context. See Answer Checkers and the Context or the Introduction to Contexts for details about how to alter the list of operators.
The operators and their precedences are listed below. Those shown in grey are not entered directly, but are generated automatically when the proper situation arises.
Operator | Precedence | Associativity | Description |
---|---|---|---|
,
|
0 | left | Separates entries in points, vectors, lists, etc. |
+
|
1 | left | Addition |
-
|
1 | left | Subtraction |
U
|
1.5 | left | Union of intervals and sets |
><
|
2 | left | Cross product of vectors (only in Vector and Matrix contexts)
|
.
|
2 | left | Dot product of vectors (only in Vector and Matrix contexts)
|
*
|
3 | left | Multiplication |
/
|
3 | left | Division |
//
|
3 | left | Division displayed horizontally |
space | 3 | left | Multiplication (generated automatically by implied multiplication) |
u+
|
6 | left | Unary plus (generated automatically when + is used in unary position)
|
u-
|
6 | left | Unary minus (generated automatically when - is used in unary position)
|
^
|
7 | right | Exponentiation |
**
|
7 | right | Exponentiation |
fn
|
7.5 | left | Function call (generated automatically by functions) |
!
|
8 | right | Factorial |
_
|
9 | left | Element extraction (for vectors, matrices, lists, points) |
In addition to these, there are some extra operators used to implement a non-standard precedence arrangement that is designed to allow things like sin 2x
to be interpreted as sin(2x)
rather than as (sin(2)) x
. In the standard precedence settings, these have the precedences or the corresponding operators listed above; in the non-standard precedence, they are as given below. Here, "space" represents an actual space.
Operator | Precedence | Associativity | Description |
---|---|---|---|
space*
|
2.8 | left | Multiplication with preceding space |
* space
|
2.8 | left | Multiplication with trailing space |
space/
|
2.8 | left | Division with preceding space |
/ space
|
2.8 | left | Division with trailing space |
fn
|
2.9 | left | Function call |
space | 3.1 | left | Implied multiplication |
See pg/lib/Parser/Context/Default.pm
for the full definitions of the operators.