>> unprotect(Top): export(muEC::SYMF): >> SfEval(p[1],x+y+z) >> SfEval(p[2],x+y+z) >> (p[4,2,1] + 3*p[2])*(1/4*p[1] - p[2]) >> Top((p[4,2,1] + 3*p[2])*(1/4*p[1] - p[2])) >> Tos((p[4,2,1] + 3*p[2])*(1/4*p[1] - p[2])) >> Tom((p[4,2,1] + 3*p[2])*(1/4*p[1] - p[2])) >> operators::setTensorSymbol("#"): Sym := examples::SymmetricFunctions(): Sym::Name := hold(Sym): Sym::fixBasesNames(): viewDot(operators::overloaded::dotConversions()) >> SymZ2 := examples::SymmetricFunctions(Dom::IntegerMod(2)): SymZ2::Name := hold(SymZ2): SymZ2::fixBasesNames(): viewDot(operators::overloaded::dotConversions()) >> QSym := examples::QuasiSymmetricFunctions(): QSym::Name := hold(QSym): QSym::fixBasesNames(): NCSF := examples::NonCommutativeSymmetricFunctions(): NCSF::Name := hold(NCSF): NCSF::fixBasesNames(): viewDot(operators::overloaded::dotConversions()) >> reset(): >> 1+1 >> factor(x^100-1) >> sqrt( 14+3*sqrt(3+2*sqrt(5-12*sqrt(3-2*sqrt(2))))) >> simplify( sqrt( 14+3*sqrt(3+2*sqrt(5-12*sqrt(3-2*sqrt(2))))), sqrt ) >> expand( cos(5*x)/(sin(2*x)*cos(x)^2) ); >> res := int( exp(x^2/2), x ); >> simplify( diff( res, x ) ); >> setuserinfo(Sum,10): sum( 1/k^2 + 1/k^3, k=1..infinity ); >> sum( 1/(exp(k)+a)^2, k=1..infinity ); >> limit( sin(x)/x, x=0 ); >> limit( x*ln(x)*(ln(x*exp(x)-x^2))^2/ln(ln(x^2+2*exp(exp(3*x^3*ln(x))))), x=infinity ); >> solve(sin(x) = 1, x); >> p := solve((a*x^2 - 4)*(x - b), x) >> eval(subs(%, [a = 4, b = 2])); >> assume(a<>0): p := solve((a*x^2 - 4)*(x - b), x) >> p := solve((a*x^2 - 4)*(x - b), x, Domain=Dom::Integer) ; >> plot(plot::Function3d(sin(x*(y+a)), x = 0..2*PI, y = -PI..PI, a=-10..10)) >> linalg:: >> combinat::partitions::list(10); >> export(combinat): partitions::count(4); partitions::list(4); >> alias(listPart=combinat::partitions::list): listPart(4); >> p := x+1; >> (x+1)^2 >> expand((x+1)^2) >> P2 := Dom::UnivariatePolynomial(x, Dom::IntegerMod(2)): >> p := P2(x+1); >> domtype(p); >> p^2 >> Q := Dom::Rational: Qx:= Dom::Fraction(Dom::UnivariatePolynomial(x, Q)): F := Dom::AlgebraicExtension(Qx, poly(z^2 - x, [z])): P := Dom::UnivariatePolynomial(u, F): >> P(u*z)*P(z) >> factor(P(u^2 - x^3)) >> reset(): operators::setTensorSymbol("#"): S := examples::SymmetricFunctions(Dom::Rational); >> p1 := S::p([1]); p1([x, y, z]); >> p2 := S::p([2]); p2([x, y, z]) >> p421 := S::p([4, 2, 1]); p421([x,y,z]) >> p2 * p1 * p2 * p421 >> (p421 + 3*p2)*(1/4*p1 - p2) >> domtype(p1); >> S::p >> f := (expr(p421) + 3*expr(p2))*(1/4*expr(p1) - expr(p2)) >> S(f); >> eval(subs(f, p = S::p)) >> expand(S::e([2])([x,y,z])) >> expand(S::m([2, 1])([x,y,z])) >> expand(S::h([2])([x,y,z])) >> expand(S::s([2])([x,y,z])) >> f := S::p([4]); S::e(f); S::h(f); S::s(f); S::m(f) >> S::p([2]) * S::s([2]) >> S::coproduct(S::m([1, 1])) >> S::p([2]) * S::p(S::s([2])); S::s(S::p([2])) * S::s([2]) ; S::p(S::p([2]) * S::s([2])) >> S::p( S::m([1]) * ( S::e([3])*S::s([2]) + 1 )) >> S::e([2, 1, 3]) >> S::s([[3, 3, 1], [2]]) >> S::s([7, 3, 0, 9, 4]) >> K := Dom::ExpressionFieldWithDegreeOneElements([t, q]): S := examples::SymmetricFunctions(K, vHL=t, vMcd=q): >> el := S::QP([3, 2, 1, 1]) >> S::s(el) >> expand(el([q, q*t])) >> export(combinat): >> catalan(i) $ i = 0..10 >> cartesianProduct::list([1,2,3],[a,b],[i,ii,iii]) >> permutations::list([1, 2, 3]) >> subwords::list([a,b,c,d]) >> partitions::list(5) >> partitions::printPretty([3, 2]) >> map(tableaux::list([3, 2]), tableaux::printPretty) >> trees::list(4) >> trees::list(6) >> partitions::count(i) $ i = 0..10 >> partitions::list(5, MinLength = 2, MaxLength = 3); >> bool(partitions::_less([3, 1], [2, 2])) >> g := partitions::generator(4): >> g() >> g() >> g(), g(), g(), g() >> g := partitions::generator(42): g(), g(), g(), g(), g(), g() >> integerVectors::list(10, 3, MinPart = 2, MaxPart = 5, Inner = [2, 4, 2]) >> compositions::list(5, MaxPart = 3, MinPart = 2, MinLength = 2, MaxLength = 3) >> partitions::list(5, MaxSlope = -1) >> partitions::list(9, MinPart = 2, MaxPart = 5) >> integerListsLexTools::list(9, 0, infinity, 2, 5, -infinity, 0) >> fiWords := decomposableObjects( [FiWords = Union(Epsilon, Atom(B), Prod(FiWords, Atom(A)), Prod(FiWords, Atom(A), Atom(B))) ]): >> fiWords::list(4) >> map(fiWords::list(4), p -> [eval(subs(p, Prod = id, Epsilon = null() ))]) >> fiWords := combinat::decomposableObjects( [FiWords = Alias(FiWordsRec, DOM_LIST), FiWordsRec = Union(Epsilon(), Alias(Prod(Atom(A), FiWordsRec), op), Atom(B), Alias(Prod(Atom(B), Atom(A), FiWordsRec), op) ) ]): fiWords::list(4); >> fiWords::count(i) $ i = 0..10 >> fiWords::recurrenceRelation() = 0 >> collect(binaryTrees::grammar::recurrenceRelation(), [u(n), u(n-1)], factor) = 0 >> domain FreeAlgebra inherits Dom::FreeModule(Dom::Rational, combinat::words); category Cat::AlgebraWithBasis(Dom::Rational); one := dom::term([]); mult2Basis := dom::term @ _concat; end_domain: >> x := FreeAlgebra([a, b, c]); y := FreeAlgebra([d, e]) >> 3 * x; x + y; x * y >> x * (2*x + y) + (3 + y/2)^2 >> domain FreeCommutativeAlgebra inherits Dom::FreeModule(Dom::Rational, combinat::words); category Cat::AlgebraWithBasis(Dom::Rational); one := dom::term([]); straightenBasis := dom::term @ sort; mult2Basis := dom::straightenBasis @ _concat; end_domain: >> x := FreeCommutativeAlgebra([a, b]); y := FreeCommutativeAlgebra([c, b, a]) >> x * y; y * x >> x := FreeAlgebra([a]); y := FreeCommutativeAlgebra([a]) >> bool(extop(x) = extop(y)) >> bool(x = y); domtype(x), domtype(y) >> x * y >> FreeAlgebra::basisName := hold(T): FreeCommutativeAlgebra::basisName := hold(S): x, y >> evaluation := FreeAlgebra::moduleMorphism (FreeCommutativeAlgebra::term @ sort): >> x := FreeAlgebra([c, b, a]) + FreeAlgebra([c, a, b]); >> evaluation(x); >> FreeAlgebra::algebraToList := FreeAlgebra::toList: evaluation := FreeAlgebra::algebraMorphism (FreeCommutativeAlgebra::term @ (a -> [a])): >> evaluation(x); >> operators::overloaded::declareConversion( FreeAlgebra, FreeCommutativeAlgebra, evaluation): FreeCommutativeAlgebra(x) >> FreeCommutativeAlgebra([a, b]) + FreeAlgebra([c,b,a]) >> operators::overloaded::declareConversion( FreeAlgebra, FreeCommutativeAlgebra, evaluation, Explicit): FreeCommutativeAlgebra(x); >> FreeCommutativeAlgebra([a, b]) + FreeAlgebra([c,b,a]) >> export(combinat): >> domain FreeAlgebraInteger inherits Dom::FreeModule(Dom::Rational, compositions); category Cat::AlgebraWithBasis(Dom::Rational); basisName := hold(E); exprTerm := dom::exprTermIndex; one := dom::term([]); mult2Basis := dom::term @ _concat; end_domain: domain FreeCommutativeAlgebraInteger inherits Dom::FreeModule(Dom::Rational, partitions); category Cat::AlgebraWithBasis(Dom::Rational); basisName := hold(e); exprTerm := dom::exprTermIndex; one := dom::term([]); straightenBasis := dom::term @ revert @ sort; mult2Basis := dom::straightenBasis @ _concat; end_domain: >> alias(NCSF = FreeAlgebraInteger, SF = FreeCommutativeAlgebraInteger): operators::overloaded::declareConversion(NCSF, SF, NCSF::moduleMorphism(SF::straightenBasis, ImageSet = SF)): >> x := NCSF([1, 3, 2]); >> y := SF ([1, 3, 2]) >> SF(x) >> bool(SF(x)=y) >> SF([1])^10 >> domain SFExp inherits Dom::FreeModule(Dom::Rational, combinat::integerVectors); category Cat::AlgebraWithBasis(Dom::Rational); basisName := hold(e); exprTerm := dom::exprTermIndex; one := dom::term([]); mult2Basis := (v1,v2) -> dom::term(zip(v1,v2,_plus,0)); end_domain: >> SFExp([1]); SFExp([2, 0, 1])*SFExp([1, 1]); SFExp([1])^10 >> SFExp::exprTerm := v -> _mult(dom::basisName.i^v[i] $ i=1..nops(v)): SFExp([1]); SFExp([2, 0, 1])*SFExp([1, 1]); SFExp([1])^10 >> SFExp([1]), SFExp([1, 0]), SFExp([1, 0, 0]); bool(SFExp([1]) = SFExp([1, 0])) >> operators::overloaded::declareConversion(SFExp, SF, SFExp::moduleMorphism( SF::term @ combinat::partitions::fromExp, ImageSet = SF)): operators::overloaded::declareConversion(SF, SFExp, SF::moduleMorphism( SFExp::term @ combinat::partitions::toExp, ImageSet = SFExp)): >> SF([4, 3, 3, 1]), SFExp(SF([4, 3, 3, 1])) >> x := SF([3, 1]): y := SF([4, 3, 2]): x * y, SF( SFExp(x) * SFExp(y) ) >> ( 1 + SF([3, 1])*x ) * SFExp([2, 0]) + SFExp([1]) >> (1+SF([3,1])*x) * SF( SFExp([2,0]) ) + SF( SFExp([1]) ) ; SF( (1+SF([3,1])*x) * SFExp([2,0]) ) + SF( SFExp([1]) ) ; SF( (1+SF([3,1])*x) * SFExp([2,0]) + SFExp([1]) ) ; >> SFExp(NCSF([1, 4, 2, 2])) >> export(combinat): >> domain qShuffleAlgebra(K: DOM_DOMAIN) // The parameter K is the base field // Implementation of the vector space structure inherits Dom::FreeModule(K, words); // This is an algebra with a distinguished basis category Cat::AlgebraWithBasis(K); // Basis elements are printed as W([a,b,a,a]) basisName := hold(W); // The unit of the algebra is the empty word one := dom::term([]); // The binary product of the algebra is defined // by linearity on basis elements mult2Basis := proc(ua: dom::basisIndices, vb: dom::basisIndices) local a, b, u, v; begin // Base case: ua is empty if nops(ua)=0 then return(dom::term(vb)); end_if; // Base case: vb is empty if nops(vb)=0 then return(dom::term(ua)); end_if; // extract u and a from ua u := [op(ua, 1..nops(ua)-1)]; a := ua[nops(ua)]; // extract v and b from vb v := [op(vb, 1..nops(vb)-1)]; b := vb[nops(vb)]; // the recursion formula dom::mapterms(dom::mult2Basis(ua, v), append, b) + dom::mapterms(dom::mult2Basis(u, vb), append, a) * q^nops(vb) end_proc; end_domain: >> W := qShuffleAlgebra(Dom::ExpressionField()): >> W([a])*W([b]); W([b])*W([a]); >> W([b, c, d])*W([2, 3]) >> 1/2*W([b])^3 + W([a])*(1 + W([1, 2])) >> MuPADCategories := {AbelianGroup, AbelianMonoid, AbelianSemiGroup, Algebra, AlgebraWithBasis, BaseCategory, CancellationAbelianMonoid, CommutativeRing, CombinatorialClass, CombinatorialClassWith2DBoxedRepresentation, DecomposableClass, DifferentialRing, EntireRing, EuclideanDomain, FacadeDomain, FactorialDomain, Field, FiniteCollection, GcdDomain, GradedModuleWithBasis, GradedAlgebraWithBasis, GradedCombinatorialClass, GradedHopfAlgebraWithBasis, Group, HomogeneousFiniteProduct, HopfAlgebraWithBasis, HomogeneousFiniteCollection, IntegralDomain, IntegerListsLexClass, LeftModule, Matrix, Module, ModuleWithBasis, Monoid, OrderedSet, PartialDifferentialRing, Polynomial, PrincipalIdealDomain, QuotientField, RightModule, Ring, Rng, SemiRng, SemiRing, SemiGroup, Set, SkewField, SquareMatrix, TreesClass, UnivariatePolynomial, UseOverloading, VectorSpace}: MuPADCategoriesFromUs := { AlgebraWithBasis, CombinatorialClass, CombinatorialClassWith2DBoxedRepresentation, DecomposableClass, FacadeDomain, GradedModuleWithBasis, GradedAlgebraWithBasis, GradedCombinatorialClass, GradedHopfAlgebraWithBasis,HopfAlgebraWithBasis, IntegerListsLexClass, ModuleWithBasis, TreesClass,UseOverloading}: PureMuPADCategories := MuPADCategories minus MuPADCategoriesFromUs: CategoryConstructorName := proc(cat) begin case domtype(cat) of CategoryConstructor do return(op(cat,[1,6,2])) of Category do return(CategoryConstructorName(op(cat,1))): of DOM_EXPR do case type(cat) of "slot" do if op(cat, 1) = hold(Cat) then return(CategoryConstructorName(eval(cat))); else return(); end; of "_if" do return(CategoryConstructorName(op(cat,2)), CategoryConstructorName(op(cat,3))); of "function" do return(CategoryConstructorName(op(cat,0))); end_case; otherwise null(); end_case; end: prog::test(CategoryConstructorName(Cat::UseOverloading), "UseOverloading"): prog::test(CategoryConstructorName(Cat::Algebra(Dom::Rational)), "Algebra"): superCategories := proc(cat: Type::Union(Category, CategoryConstructor)) begin if domtype(cat) = Category then cat := op(cat,1): end_if; map(op(cat,3), CategoryConstructorName) end: dotCategories := proc() begin res := "digraph Categories { node [shape=plaintext, fontcolor=red]; edge [dir = back]; ": for catname in PureMuPADCategories do res := res . catname . " [ fontcolor=black ];\n"; end; for catname in MuPADCategoriesFromUs do res := res . catname . " [ fontcolor=blue ];\n"; end; for catname in Cat::interface do cat := eval(slot(Cat, expr2text(catname))); for super in superCategories(cat) do res := res . super." -> " . CategoryConstructorName(cat). ";\n"; end_for; end_for; res. "}"; end: viewDot(dotCategories()): >> reset(): >> domain FreeAlgebraInteger inherits Dom::FreeModule(Dom::Rational, combinat::compositions); category Cat::GradedHopfAlgebraWithBasis(Dom::Rational); basisName := hold(P); exprTerm := dom::exprTermIndex; one := dom::term([]); mult2Basis := dom::term @ _concat; coproductBasis := proc(compo : dom::basisIndices) local i, tens; begin tens := dom::tensorSquare; tens::mult(tens::plus2(tens::term([[i], []]), tens::term([[], [i]])) $ i in compo); end_proc; end_domain: alias(NCSF = FreeAlgebraInteger) >> tens := operators::coproduct(NCSF([2, 1, 3])) >> operators::setTensorSymbol("ø"): tens >> NCSF([1,2]) ø NCSF([1]) >> tens * (NCSF([1,2]) ø NCSF([1])) >> domtype(tens) >> operators::antipode(NCSF([2, 1, 3])) >> antipodeBasis := comp -> dom::monomial(-1^nops(comp), revert(comp)); >> idTensorAntipode := operators::tensorProductOfMaps( [id, NCSF::antipode], NCSF::tensorSquare, NCSF::tensorSquare): idTensorAntipode(tens) >> es := NCSF::mu @ idTensorAntipode @ NCSF::coproduct: >> es(NCSF([2, 1])); es(NCSF([])); >> domain SubsetsSpaceTools info_str := "Helper tools for the domain 'SubsetsSpace'"; end_domain: >> subsetsOf := S -> combinat::subClass(combinat::subsets, Parameters = S): >> S4 := subsetsOf({1,2,3,4}): S4::list(); >> domain SubsetsSpaceTools::Fundamental(S, Ring) category Cat::AlgebraWithBasis(Ring); inherits Dom::FreeModule(subsetsOf(S), Ring); info_str := "The subset space on the fundamental basis"; basisName := hold(F); mult2Basis := proc(s1: dom::basisIndices, s2: dom::basisIndices) begin dom::term(s1 intersect s2); end_proc; end_domain: >> domain SubsetsSpaceTools::In(S, Ring) category Cat::AlgebraWithBasis(Ring); inherits Dom::FreeModule(subsetsOf(S), Ring); info_str := "The subset space on the 'In' basis"; basisName := hold(In); end_domain: domain SubsetsSpaceTools::Out(S, Ring) category Cat::AlgebraWithBasis(Ring); inherits Dom::FreeModule(subsetsOf(S), Ring); info_str := "The subset space on the 'Out' basis"; basisName := hold(Out); end_domain: >> domain SubsetsSpace(S : DOM_SET, Ring = Dom::Rational : DOM_DOMAIN) category Cat::ModuleWithSeveralBases(Ring); inherits Dom::BaseDomain; info_str := "The subsets space on various bases"; Fundamental := SubsetsSpaceTools::Fundamental(S, Ring); F := dom::Fundamental; // a shortcut In := SubsetsSpaceTools::In(S, Ring); Out := SubsetsSpaceTools::Out(S, Ring); // When possible, define automatically basis changes by // transposition or inversion of matrices. autoDefineBasisChanges := TRUE; basisChangesBasis := table( (dom::In, dom::F) = proc(set : dom::In::basisIndices) : dom::F local xSet; begin dom::F::plus(dom::F::term(xSet) $ xSet in combinat::subsets::list(set)); end_proc); dual := dom; // The dual of this space. // The pairs of dual bases. // The pair [dom::Out, dom::In] will be automatically declared. dualBasesPairs := {[dom::F, dom::F], [dom::In, dom::Out]}; end_domain: >> M1234 := SubsetsSpace({1, 2, 3, 4}): el1 := M1234::F({1, 2}); el2 := M1234::In({1, 2}) >> testtype(el1, M1234), testtype(el2, M1234) >> M1234::In(el1) >> M1234::Out(el2) >> el1*el2 >> operators::scalar(el1, el2) >> M1234::Out({1, 3, 4})*M1234::Out({2, 3}); >> M1234::Out(last(1)) >> Dom::FreeModule([a,b,c]): F := Dom::FreeModule([a,b,c]): >> x := F::term(a) + 3 * F::term(c) >> extop(x); >> x := x + 2 * F::term(b) >> extop(x); >> G := Dom::FreeModule([1,2,3], Dom::ExpressionField(), RankerBasis = [id, id]): >> y := G::term(1) + 3 * G::term(3) >> extop(y) >> operators::setTensorSymbol("#"): H := Dom::TensorProductOfFreeModules([F, G]): >> x # y; >> extop(x # y); >> operators::setTensorSymbol("#"): Sym := examples::SymmetricFunctions(): Sym::Name := hold(Sym): Sym::fixBasesNames(): viewDot(operators::overloaded::dotConversions()) >> SymZ2 := examples::SymmetricFunctions(Dom::IntegerMod(2)): SymZ2::Name := hold(SymZ2): SymZ2::fixBasesNames(): viewDot(operators::overloaded::dotConversions()) >> QSym := examples::QuasiSymmetricFunctions(): QSym::Name := hold(QSym): QSym::fixBasesNames(): NCSF := examples::NonCommutativeSymmetricFunctions(): NCSF::Name := hold(NCSF): NCSF::fixBasesNames(): viewDot(operators::overloaded::dotConversions()) >> S := examples::SymmetricFunctions(): operators::overloaded::declareConversion(DOM_LIST, S::s, S::s::term): mult := operators::_mult: >> mult( [ 3,2,1 ], [2,1])