This notebook contains examples from Mathematica Stack Exchange applied to Symata.
Disclaimer to avoid any possible confusion.
Neither Symata nor the Symata language are affiliated in any way with Mathematica and/or the Wolfram language. Symata is an open source project. Mathematica and Wolfram language are software products developed and licensed by WRI.
In [1]:
using Symata
In [2]:
FloatFormat(Short);
The following example example is from L. Shifrin.
C is a tree:
In [3]:
C = [a,[[a1,[a12,b12,c12]],[b2,[a22,b22,c22]],[c3,[a32,b32,c32,d32]]]];
In [4]:
trav(tree_List) := Flatten(trav([], tree), 1)
trav(accum_List, [x_, y_List]) := Map(yy -> trav([accum, x], yy), y)
trav(x_,y_) := Flatten([x,y])
In [5]:
trav(C)
Out[5]:
In this example, Module creates a closure. We want to use big integers, so we use big"1" for one of the values.
This example is also by L. Shifrin
In [6]:
Module([prev, prevprev, this],
begin
reset() := (prev = big"1"; prevprev = 1);
reset();
nextFib() := (this = prev + prevprev; prevprev = prev; prev = this)
end
);
In [7]:
reset()
a = Table(nextFib(),[1000]);
a[-1]
Out[7]:
In [8]:
ClearAll(a,b)
allsyms(expr_) := Cases(expr , s_Symbol => HoldComplete(s),[0,Infinity])
In [9]:
allsyms(a + b * (1 - x))
Out[9]:
The Power function returns the principal root, not necessarily a real root.
In [10]:
[(-8)^(1/3), (-8.0)^(1/3)]
Out[10]:
CubeRoot and Surd give real roots
In [11]:
[CubeRoot(-8), Surd(-32,5)]
Out[11]:
Surd returns unevaluated if the root is even.
In [12]:
Surd(-8,4)
Out[12]:
or complex
In [13]:
Surd(I,3)
Out[13]:
In [14]:
VersionInfo()
In [15]:
InputForm(Now())
Out[15]: