Difference between revisions of "Context Operator Table"

From WeBWorK_wiki
Jump to navigation Jump to search
(Add categories)
(Add link to Default.pm)
Line 153: Line 153:
   
 
|}
 
|}
  +
  +
  +
See <code>[https://github.com/openwebwork/pg/blob/master/lib/Parser/Context/Default.pm pg/lib/Parser/Context/Default.pm]</code> for the full definitions of the operators.
   
 
<br>
 
<br>

Revision as of 07:09, 12 August 2012

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(2) 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.