In [1]:
using Symata

Differences from Wolfram / Mathematica

Symata is similar to the Wolfram language. But, there are difference in notation and behavior.

Multiplication

In Symata, multiplication of a number and variable does not require the * symbol. But space between the number and variable is not allowed. All other multiplications requires an explicit *.


In [2]:
[2x + 1, 2 * x + 1, 2 * 3, Cos(x) * Sin(x)]


Out[2]:
$$ \left[ 1 + 2 \ x,1 + 2 \ x,6,\text{Cos} \! \left( x \right) \ \text{Sin} \! \left( x \right) \right] $$

Comments

In Symata, comments are entered with the prefix #. In Mathematica, comments are entered like this (* comment *)


In [3]:
# a = 1
  b = 2

[a,b]

List

Mathematica lists are delimited by { }. Symata lists are delimited by [ ]


In [4]:
[a,b,c]


Out[4]:
$$ \left[ a,b,c \right] $$

Elements in a list may be separated by commas, as above. But, in Symata they may also be separated by a newline after a complete expression. (This does not work if the code is loaded from a file with Get)


In [5]:
[
    a
    c + d
    "cat"
    Expand((x+y)^2)
]


Out[5]:
$$ \left[ a,c + d,\text{"cat"},x^{2} + 2 \ x \ y + y^{2} \right] $$

Functions

Function arguments are delimited by [ ] in Mathematica. In Symata, arguments are delimited by ( )


In [6]:
f(x)


Out[6]:
$$ f \! \left( x \right) $$

Compound expressions

There are several ways to enter compound expressions.


In [7]:
e1 = (1,2,a+b)

e2 = (1,
      2,
      a+b)

e3  = begin
     1;
     2;
     a+b
end

e1 == e2 == e3


Out[7]:
$$ \text{True} $$

Infix notation for Map, Apply, Rule, ReplaceAll, etc.

Map


In [8]:
f % list


Out[8]:
$$ \text{Map} \! \left( f,list \right) $$

In [9]:
f % [a,b,c]


Out[9]:
$$ \left[ f \! \left( a \right) ,f \! \left( b \right) ,f \! \left( c \right) \right] $$

Apply


In [10]:
x .%  y


Out[10]:
$$ \text{Apply} \! \left( x,y \right) $$

In [11]:
f .% g(1,2)


Out[11]:
$$ f \! \left( 1,2 \right) $$

Rule

Rule can be entered in the following ways. The symbol ⇒ can be entered with \Rightarrow[TAB]


In [12]:
[Rule(a,b), a => b , a  b]


Out[12]:
$$ \left[ a \Rightarrow b,a \Rightarrow b,a \Rightarrow b \right] $$

RuleDelayed


In [13]:
[RuleDelayed(a,b),  a .> b]


Out[13]:
$$ \left[ a\text{:>}b,a\text{:>}b \right] $$

ReplaceAll

The short "infix" symbol for ReplaceAll is ./. In Mathematica, it is /.. Also note the parentheses surrounding the rule.


In [14]:
[a, x^2, b^3, (a+b)^3]  ./ ( x_^n_ => g([n],x))


Out[14]:
$$ \left[ a,g \! \left( \left[ 2 \right] ,x \right) ,g \! \left( \left[ 3 \right] ,b \right) ,g \! \left( \left[ 3 \right] ,a + b \right) \right] $$

Patterns

Blank

x_ is a blank matching a single element. y__ is a blank sequence, matching one or more elements


In [15]:
f(x_, y__) := [x,[y]]
f(1,2,3,4)


Out[15]:
$$ \left[ 1, \left[ 2,3,4 \right] \right] $$

Repeated

In Mathematica, Repeated[a] is denoted by a... In Symata, Repeated(a) is denoted by a.... Notice that in Symata, there are three dots instead of two.


In [16]:
[
MatchQ([a, a, b, (a + b)^3, c, c, c], [a..., b, _^3... , c...])
MatchQ([a, a, (a + b)^3, c, c, c], [a..., b, _^3... , c...])
]


Out[16]:
$$ \left[ \text{True},\text{False} \right] $$

Repeated can be used in operator form.


In [17]:
ClearAll(f)
f(x_...) := x

In [18]:
f(3,3,3,3)


Out[18]:
$$ 3 $$

In Mathematica, Repeated[expr,n] matches at least n occurences of expr. In Symata, Repeated(expr,n) does the same.


In [19]:
[
    MatchQ([1,2,3], [Repeated(_Integer,2)])
    MatchQ([1,2,3], [Repeated(_Integer,3)])
]


Out[19]:
$$ \left[ \text{False},\text{True} \right] $$

RepeatedNull

In Symata RepeatedNull must be written in full form. (We have not yet chosen a symbol for it)


In [20]:
MatchQ([], [RepeatedNull(_Integer)])


Out[20]:
$$ \text{True} $$

As in Mathematica, default values of optional arguments are specified using :.


In [21]:
ClearAll(f, a, b)

f(x_, y_:a, z_:b) := [x,y,z]

[
 f(1) == [1,a,b]
 f(1,2) == [1,2,b]
 f(1,2,3) == [1,2,3]
]


Out[21]:
$$ \left[ \text{True},\text{True},\text{True} \right] $$

Named compound Patterns

In Mathematica, names for complex patterns use a colon a:(b_^c_). In Symata, use two colons.


In [22]:
ClearAll(g,a,b)

b^b  ./  (a::(_^_) => g(a))


Out[22]:
$$ g \! \left( b^{b} \right) $$

PatternTest

In Mathematica, PatternTest is given like this p_?PrimeQ. In Symata this is p_`PrimeQ`


In [23]:
countprimes = Count(_`PrimeQ`)  # We use the curried form of Count
countprimes(Range(100))


Out[23]:
$$ 25 $$

You can use a Julia function as the test.


In [24]:
p = _`J( x ->  -1 < x < 1 )`

[
MatchQ(0, p),
MatchQ(.5, p),
MatchQ(-1/2, p),
MatchQ(-1, p)
]


Out[24]:
$$ \left[ \text{True},\text{True},\text{True},\text{False} \right] $$

Alternatives

Alternatives is denoted by the vertical bar |.


In [25]:
ClearAll(f)

f(x_, x_ | y_String) := [x, y]

[ f(2,2) , f(2,"cat"), f(2, 3)]


Out[25]:
$$ \left[ \left[ 2 \right] , \left[ 2,\text{"cat"} \right] ,f \! \left( 2,3 \right) \right] $$

Condition

Condition must be written in full form.


In [26]:
[
MatchQ( -2 , Condition(x_ , x < 0))
MatchQ(  2 , Condition(x_ , x < 0))
]


Out[26]:
$$ \left[ \text{True},\text{False} \right] $$

In [27]:
ClearAll(y)

ReplaceAll([1, 2, 3, "cat"], x_Integer => Condition(y, x > 2))


Out[27]:
$$ \left[ 1,2,y,\text{"cat"} \right] $$

In [28]:
ClearAll(f)

f(x_) :=  Condition(x^2, x > 3)

[f(2), f(4)]


Out[28]:
$$ \left[ f \! \left( 2 \right) ,16 \right] $$

Version and date


In [29]:
VersionInfo()


Symata version     0.4.1-dev.3
Julia version      0.7.0-beta2.1
Python version     2.7.14+
SymPy version      1.0

In [30]:
InputForm(Now())


Out[30]:
2018-07-20T13:17:54.738