Test species in axiom/FriCAS.
The species project is written in Aldor. Thus we need to load the libraries explicitly:
fricas
(1) -> )cd /var/lib/zope/combinat/src
The current FriCAS default directory is /var/aw/var/LatexWiki
fricas
)re ../lib/combinat.input
The file ../lib/combinat.input is needed but does not exist.
Let's define a binary tree.
aldor
#includeDir "/var/lib/zope/combinat/include"
#libraryDir "/var/lib/zope/combinat/lib"
#include "combinat"
macro {
E == EmptySetSpecies;
X == SingletonSpecies;
+ == Plus;
* == Times;
}
A(L: LabelType): CombinatorialSpecies L == (E + X*A*A)(L) add;
aldor
Compiling FriCAS source code from file
/var/lib/zope2.10/instance/axiom-wiki/var/LatexWiki/5200085684951427974-25px002.as
using Aldor compiler and options
-O -Fasy -Fao -Flsp -lfricas -Mno-ALDOR_W_WillObsolete -DFriCAS -Y $FRICAS/algebra -I $FRICAS/algebra
Use the system command )set compiler args to change these
options.
"/var/lib/zope2.10/instance/axiom-wiki/var/LatexWiki/5200085684951427974-25px002.as", line 3:
#include "combinat"
^
[L3 C1] #1 (Error) Could not open file `combinat'.
The )library system command was not called after compilation.
aldor
#includeDir "/var/lib/zope/combinat/include"
#libraryDir "/var/lib/zope/combinat/lib"
#assert MacrosCombinat
#assert Axiom
#include "combinat"
macro {
SPECIES == (L: LabelType) -> CombinatorialSpecies L;
V == CycleIndexVariable;
NonNegativeMachineInteger == I;
T == SparseIndexedPowerProduct(V, NonNegativeMachineInteger);
P == SparseDistributedPolynomial(Q, V, T);
}
LinearOrder(L: LabelType): with {
CombinatorialSpecies L;
coerce: % -> List L;
} == List L add {
Rep == List L;
import from Rep;
coerce(x: %): List L == rep x;
local lists(l: List L): Generator List L == generate {
empty? l => yield l;
current := l;
c := first current;
for u in lists(rest l) repeat yield cons(c, u);
assert(not empty? current);
while not empty?(tmp := rest current) repeat {
c := first tmp;
setrest!(current, rest tmp); -- remove c from l
for u in lists l repeat yield cons(c, u);
setrest!(current, tmp); -- put c back into l
current := tmp;
}
}
structures(s: SetSpecies L): Generator % == generate {
for l in lists(s :: List L) repeat yield per l;
}
local LinearOrderIsomorphismType: IsomorphismTypeCategory L
== add {
isomorphismTypes(s: MultiSet L): Generator % == never;
(x:%) = (y:%): Boolean == never;
(tw: TextWriter) << (x: %): TextWriter == never;
}
IsomorphismType: IsomorphismTypeCategory L == LinearOrderIsomorphismType;
generatingSeries: ExponentialGeneratingSeries == {
(stream(1$Q)$DataStream(Q)) :: ExponentialGeneratingSeries;
}
isomorphismTypeGeneratingSeries: OrdinaryGeneratingSeries == {
(stream(1$Z)$DataStream(Z)) :: OrdinaryGeneratingSeries;
}
local cisGenerator: Generator P == generate {
import from I, T, P;
x1: V := 1::V;
for n: I in 0.. repeat yield power(x1, n) :: P;
}
cycleIndexSeries: CycleIndexSeries == cisGenerator :: CycleIndexSeries;
import from String;
expression: SpeciesExpression == leaf("LinearOrder");
}
Cycle(L: LabelType): with {
CombinatorialSpecies L;
coerce: % -> List L;
cycle: List L -> %;
} == List L add {
Rep == List L;
import from I, Rep;
local cisCycle(ao: I): Generator P == generate {
macro PrimePowerProduct == SparseIndexedPowerProduct(I, I);
local multiply(k: PrimePowerProduct): I == {
r: I := 1;
for ep in k repeat {(e, p) := ep; r := r * p^e}
r;
}
local eulerPhi(t: SparseIndexedPowerProduct(I, I)): I == {
phi: I := 1;
for ep in t repeat {
(e, p) := ep;
phi := phi * p^(e-1) * (p-1)
}
phi;
}
local cisCoefficient(n: I): P == BugWorkaround(
PrimePowerProduct has with {
divisors: % -> Generator %;
/: (%, %) -> %;
}
){
import from Z, V, SmallIntegerTools;
nn: PrimePowerProduct := factor n;
p: P := 0;
for m in divisors nn repeat {
k: PrimePowerProduct := nn/m;
q: Q := (eulerPhi(k) :: Z) / (n :: Z);
xk: V := multiply(k) :: V;
t: T := power(xk, multiply m);
p := [q, t]$P + p;
}
p;
}
yield 0$P;
for n:I in 1.. repeat yield cisCoefficient(n);
}
coerce(x: %): List L == rep x;
cycle(l: List L): % == per l;
structures(s: SetSpecies L): Generator % == generate {
import from LinearOrder L;
if not empty? s then {
l: List L := s :: List L;
u := first l;
for t in structures(set rest l)$LinearOrder(L) repeat {
yield per cons(u, t :: List L);
}
}
}
local CycleIsomorphismType: IsomorphismTypeCategory L
== add {
isomorphismTypes(s: MultiSet L): Generator % == never;
(x:%) = (y:%): Boolean == never;
(tw: TextWriter) << (x: %): TextWriter == never;
}
IsomorphismType: IsomorphismTypeCategory L == CycleIsomorphismType;
local cycleOrder(): SeriesOrder == 1 :: SeriesOrder;
egsCycle(ao: I): Generator Q == generate {
import from Z, Q;
yield 0;
for n:I in 1.. repeat yield inv(n :: Z);
}
generatingSeries: ExponentialGeneratingSeries == new(egsCycle, cycleOrder);
ogsCycle(ao: I): Generator Z == generate {yield 0$Z; yield 1$Z};
isomorphismTypeGeneratingSeries: OrdinaryGeneratingSeries == {
new(ogsCycle, cycleOrder);
}
cycleIndexSeries: CycleIndexSeries == new(cisCycle, cycleOrder);
import from String;
expression: SpeciesExpression == leaf("Cycle");
}
aldor
Compiling FriCAS source code from file
/var/lib/zope2.10/instance/axiom-wiki/var/LatexWiki/6373670188426008557-25px003.as
using Aldor compiler and options
-O -Fasy -Fao -Flsp -lfricas -Mno-ALDOR_W_WillObsolete -DFriCAS -Y $FRICAS/algebra -I $FRICAS/algebra
Use the system command )set compiler args to change these
options.
"/var/lib/zope2.10/instance/axiom-wiki/var/LatexWiki/6373670188426008557-25px003.as", line 5:
#include "combinat"
^
[L5 C1] #1 (Error) Could not open file `combinat'.
The )library system command was not called after compilation.
fricas
labels: SetSpecies ACINT := set [i::ACINT for i in 1..3]
There are no library operations named SetSpecies
Use HyperDoc Browse or issue
)what op SetSpecies
to learn if there is any operation containing " SetSpecies " in
its name.
Cannot find a definition or applicable library operation named
SetSpecies with argument type(s)
Variable(ACINT)
Perhaps you should use "@" to indicate the required return type,
or "$" to specify which version of the function you need.
fricas
I := ACMachineInteger
Type: Variable(ACMachineInteger
?)
fricas
Z := ACInteger
Type: Variable(ACInteger
?)
fricas
Q := ACFraction Z
There are no library operations named ACFraction
Use HyperDoc Browse or issue
)what op ACFraction
to learn if there is any operation containing " ACFraction " in
its name.
Cannot find a definition or applicable library operation named
ACFraction with argument type(s)
Variable(ACInteger)
Perhaps you should use "@" to indicate the required return type,
or "$" to specify which version of the function you need.
Let's count how many structures of a certain size exist.
This is encoded in the generating series. Note that this is an
exponential generating series.
fricas
es: ExponentialGeneratingSeries := generatingSeries()$X;
ExponentialGeneratingSeries is not a valid type.
AldorCombinat? can also count the number of isomorphism types of structures.
That is encoded in the isomorphism type series.
fricas
os: OrdinaryGeneratingSeries := isomorphismTypeGeneratingSeries()$X;
OrdinaryGeneratingSeries is not a valid type.
The output of the next command apparently causes a "Proxy Error" on the mathaction server.
This can be avoided by changing the output from LaTeX to ASCII mode:
fricas
)set output tex off
fricas
)set output algebra on
coeffs3: ACList P := [coefficient(cs, i) for i in 0..5]
There are no library operations named ACList
Use HyperDoc Browse or issue
)what op ACList
to learn if there is any operation containing " ACList " in its
name.
Cannot find a definition or applicable library operation named
ACList with argument type(s)
Variable(P)
Perhaps you should use "@" to indicate the required return type,
or "$" to specify which version of the function you need.
P is the polynomial domain in infinitely many variables with rational coefficients.
fricas
p: P := 1$P
P is not a valid type.
Let's do some more advanced stuff with
Aldor-Combinat .
See the
functorial composition testpage
for more details.
Here we compute the
cycle index series
of simple graphs.
fricas
e: S := cycleIndexSeries() $ SetSpecies(Z);
S is not a valid type.
What is the intention of
BugWorkaround
in this code:
local cisCoefficient(n: I): P == BugWorkaround(
PrimePowerProduct has with {
divisors: % -> Generator %;
/: (%, %) -> %;
}
){
import from Z, V, SmallIntegerTools;
...
It results in the message:
L94 C2] #2 (Warning) Suspicious juxtaposition. Check for missing `;'.