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.
using Symata
FloatFormat(Short);
The following example example is from L. Shifrin.
C
is a tree:
C = [a,[[a1,[a12,b12,c12]],[b2,[a22,b22,c22]],[c3,[a32,b32,c32,d32]]]];
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])
trav(C)
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
Module([prev, prevprev, this],
begin
reset() := (prev = big"1"; prevprev = 1);
reset();
nextFib() := (this = prev + prevprev; prevprev = prev; prev = this)
end
);
reset()
a = Table(nextFib(),[1000]);
a[-1]
Below is another example from L. Shifrin. allsyms
returns all free symbols in expr
.
ClearAll(a,b)
allsyms(expr_) := Cases(expr , s_Symbol => HoldComplete(s),[0,Infinity])
allsyms(a + b * (1 - x))
The Power
function returns the principal root, not necessarily a real root.
[(-8)^(1/3), (-8.0)^(1/3)]
CubeRoot
and Surd
give real roots
[CubeRoot(-8), Surd(-32,5)]
Surd
returns unevaluated if the root is even.
Surd(-8,4)
┌ Warning: Surd::noneg: Surd is not defined for even roots of negative values. └ @ Symata /home/lapeyre/.julia/dev/Symata/src/wrapout.jl:29
or complex
Surd(I,3)
┌ Warning: Surd::preal: The parameter I should be real valued └ @ Symata /home/lapeyre/.julia/dev/Symata/src/wrapout.jl:29
VersionInfo()
Symata version 0.4.6 Julia version 1.6.0-DEV.58 Python version 3.8.3 SymPy version 1.5.1
InputForm(Now())
2020-05-29T22:44:02.976