WolframLang: Syntax, Operators Cheatsheet
This page gives a complete list of short syntax in WolframLang.
What is Short Syntax
WolframLang code can be written in FullForm Syntax or short syntax.
Frequently used functions have short syntax. e.g.
FullForm | short syntax |
Plus[3,4] | 3+4 |
Rational[3,4] | 3/4 |
List[3,4] | {3,4} |
Equal[x,y] | x == y |
SameQ[x,y] | x === y |
Greater[x,y] | x > y |
Set[x,3] | x = 3 |
Brackets
[]
-
square brackets are for function arguments. e.g.
Sin[Pi]
()
-
parenthesis are for grouping precedence. e.g.
(3+2)*2
{args}
-
same as
List[args]
〔see WolframLang: List〕
e[[i]]
-
same as
Part[e,i]
\[Name]
-
represent a special character, such as
\[Pi]
(π),\[Element]
(∈), etc. (*blab*)
-
Comment. Can be nested. Can be multi-line.
"abc"
-
double quote is for string delimiter. e.g.
"abc"
Symbol Name
Aaa
-
builtin function names begin with capital letter. e.g.
Sin[Pi]
$Aaa
-
builtin variable names begin with dollar sign. e.g.
$Version
,$ProcessorCount
a`b
-
grave accent mark is context separator for Symbol. (It's a namespace separator. similar to the slash in file path separator, or dot used by golang, python, java.)
x = 3; Context[x] (* Global` *) Global`x (* 3 *)
Expression Separator
expr1;expr2
-
same as
CompoundExpression[expr1,expr2]
Interactive Session
?a
-
same as
Information[a]
〔see WolframLang: Find Function by Name, List All Functions〕
%n
-
nth output.
same as
Out[n]
%
-
same as
Out[-1]
%%
-
same as
Out[-2]
. And so on for%%%
, etc.
Pure Function
body&
-
same as
Function[body]
x|->body
-
same as
Function[x,body]
#
-
same as
Slot[1]
. Use to stand for first parameter of function. #n
-
- if n is a integer, then same as
Slot[n]
. - if n is a string, then same as
Slot[name]
.
- if n is a integer, then same as
##
-
rest parameters.
same as
SlotSequence[]
##n
-
rest parameters, starting with nth argument.
same as
SlotSequence[n]
Function Application
f@x
-
prefix notation. same as
f[x]
x//f
-
postfix notation. same as
f[x]
a~f~b
-
infix notation. same as
f[a,b]
f/@x
-
same as
Map[f,x]
f@@x
-
same as
Apply[f,x]
f@@@x
-
same as
Apply[f,x, {1}]
.
Function Composition
f@*g
-
same as
Composition[f,g]
f/*g
-
same as
RightComposition[f,g]
Assignment (Create Rule)
a=b
-
same as
Set[a,b]
a:=b
-
same as
SetDelayed[a,b]
x//=f
-
same as
ApplyTo[x,f]
same as
x = f[x]
lhs^=rhs
-
same as
UpSet[lhs,rhs]
lhs^:=rhs
-
same as
UpSetDelayed[lhs,rhs]
f/:lhs=rhs
-
same as
TagSet[lhs,rhs]
f/:lhs:=rhs
-
same as
TagSetDelayed[f,lhs,rhs]
Equality
a==b
-
same as
Equal[a,b]
a!=b
-
same as
Unequal[a,b]
a===b
-
same as
SameQ[a,b]
a=!=b
-
same as
UnsameQ[a,b]
String
a<>b
-
same as
StringJoin[a,b]
a~~b
-
same as
StringExpression[a,b]
Read/Write File
Rules
a->b
-
same as
Rule[a,b]
a:>b
-
same as
RuleDelayed[a,b]
a/.b
-
same as
Replace[a,b]
Pattern Matching
_
-
same as
Blank[]
__
-
same as
BlankSequence[]
___
-
same as
BlankNullSequence[]
a_
-
same as
Pattern[a, Blank[]]
a__
-
same as
Pattern[a, BlankSequence[]]
a___
-
same as
Pattern[a, BlankNullSequence[]]
a:b
-
if a is a Symbol, then it's same as
Pattern[a,b]
. if a is a pattern, then it's same asOptional[a,b]
.
p..
-
same as
Repeated[p]
a|b
-
same as
Alternatives[a,b]
p/;t
-
same as
Condition[p,t]
p?t
-
same as
PatternTest[p,t]
Number Literal
digits.digits
-
approximate number (aka float). e.g.
16.8
base^^digits
-
integer in specified base. Base up to 36, using English letters after 9. Letter case does not matter.
2^^10 === 2 2^^11 === 3 16^^a === 10 16^^f === 15 16^^ff === 255 36^^a === 10 36^^z === 35 36^^z1 === 1261
base^^digits.digits
-
approximate number in specified base.
significand*^n
-
scientific notation (significand * 10^n)
1.2*^2 == 120. 3.2*^-2 == 0.032
base^^significand*^n
-
scientific notation in specified base (significand * base^n)
number`
-
machine‐precision approximate number. e.g.
1.23`
number`s
-
arbitrary‐precision number with precision s.
3.1`20 == 3.1
number``s
-
arbitrary‐precision number with accuracy s
3.1``20 == 3.1
Arithmetics
a+b
-
same as
Plus[a,b]
-b
-
same as
Times[-1,b]
a*b
-
same as
Times[a,b]
a b
-
same as
Times[a,b]
if a and b are numbers or symbols. a/b
-
- same as
Rational[a,b]
If a,b are integers - same as
Times[a, Power[b, -1]]
.
- same as
a^b
-
same as
Power[a,b]
Logic, Boolean
a&&b
-
same as
And[a,b]
a||b
-
same as
Or[a,b]
!a
-
same as
Not[a]
Misc
symbol::tag
-
same as
MessageName[symbol,tag]
x \[Element] dom
-
same as
Element[x,dom]
\[Element]
is rendered as ∈ x \[Distributed] dist
-
same as
Distributed[x,dist]
a \[UndirectedEdge] b
-
same as
UndirectedEdge[a,b]
a \[DirectedEdge] b
-
same as
DirectedEdge[a,b]