login  home  contents  what's new  discussion  bug reports     help  links  subscribe  changes  refresh  edit

Edit detail for SandBoxCollect revision 7 of 7

1 2 3 4 5 6 7
Editor: Bill Page
Time: 2014/09/24 23:41:35 GMT+0
Note: more tests

added:

From BillPage Wed Sep 24 23:41:34 +0000 2014
From: Bill Page
Date: Wed, 24 Sep 2014 23:41:34 +0000
Subject: more tests
Message-ID: <20140924234134+0000@axiom-wiki.newsynthesis.org>

\begin{axiom}
)lib COLL
\end{axiom}

\begin{axiom}
ex:=a+b*x+c*x^2
t:=collect(ex,x)
test(reduce(+,t) = ex)
--
ex:=(r[2]-r[1]+1)^3
t:=collect(ex,r[1]+r[2])
test(reduce(+,t) = ex)
--
ex:=(r[2]-r[1]+1)^3
t:=collect(ex,r[2])
test(reduce(+,t) = ex)
--
ex:=1/(r[2]-r[1]+1)^3
t:=collect(ex,1/r[1])
test(reduce(+,t) = ex)
\end{axiom}

Collect terms in x with given factor k.

spad
)abbrev package COLL Collect
I==>Integer
E==>Expression I
K==>Kernel E
Q==>PolynomialCategoryQuotientFunctions( _
      IndexedExponents K, K, I, SparseMultivariatePolynomial(I,K), E)
Collect(): with
    collect:(E,E) -> List E
  == add
collect1(x:E,k:K):E == n1:=univariate(x,k)$Q n2:=(leadingMonomial numer n1)/(denom n1) n3:=multivariate(n2,k)$Q
collect2(x:E,k:E,s1:List Equation E):List E == x2:=eval(collect1(eval(x,s1),kernel '%k),[kernel '%k],[k]) x2=0 => [] concat(x2,collect2(x-x2,k,s1))
collect(x,k) == s1:=solve(equation(coerce('%k),k),variables(k)(1))$TransSolvePackage(I) collect2(x,k,s1)
spad
   Compiling FriCAS source code from file 
      /var/lib/zope2.10/instance/axiom-wiki/var/LatexWiki/3893914476593947683-25px001.spad
      using old system compiler.
   COLL abbreviates package Collect 
------------------------------------------------------------------------
   initializing NRLIB COLL for Collect 
   compiling into NRLIB COLL 
   compiling local collect1 : (Expression Integer,Kernel Expression Integer) -> Expression Integer
Time: 0.06 SEC.
compiling local collect2 : (Expression Integer,Expression Integer,List Equation Expression Integer) -> List Expression Integer Time: 0.04 SEC.
compiling exported collect : (Expression Integer,Expression Integer) -> List Expression Integer Time: 0.03 SEC.
(time taken in buildFunctor: 0)
;;; *** |Collect| REDEFINED
;;; *** |Collect| REDEFINED Time: 0 SEC.
Cumulative Statistics for Constructor Collect Time: 0.13 seconds
finalizing NRLIB COLL Processing Collect for Browser database: --->-->Collect(constructor): Not documented!!!! --->-->Collect((collect ((List (Expression (Integer))) (Expression (Integer)) (Expression (Integer))))): Not documented!!!! --->-->Collect(): Missing Description ; compiling file "/var/aw/var/LatexWiki/COLL.NRLIB/COLL.lsp" (written 04 APR 2022 07:55:07 PM):
; /var/aw/var/LatexWiki/COLL.NRLIB/COLL.fasl written ; compilation finished in 0:00:00.022 ------------------------------------------------------------------------ Collect is now explicitly exposed in frame initial Collect will be automatically loaded when needed from /var/aw/var/LatexWiki/COLL.NRLIB/COLL

fricas
ex:=(r[2]-r[1]+1)^3

\label{eq1}\begin{array}{@{}l}
\displaystyle
{{r_{2}}^{3}}+{{\left(-{3 \ {r_{1}}}+ 3 \right)}\ {{r_{2}}^{2}}}+{{\left({3 \ {{r_{1}}^{2}}}-{6 \ {r_{1}}}+ 3 \right)}\ {r_{2}}}-{{r_{1}}^{3}}+ 
\
\
\displaystyle
{3 \ {{r_{1}}^{2}}}-{3 \ {r_{1}}}+ 1 
(1)
Type: Polynomial(Integer)
fricas
t:=collect(ex,r[2]-r[1])

\label{eq2}\begin{array}{@{}l}
\displaystyle
\left[{{{r_{2}}^{3}}-{3 \ {r_{1}}\ {{r_{2}}^{2}}}+{3 \ {{r_{1}}^{2}}\ {r_{2}}}-{{r_{1}}^{3}}}, \:{{3 \ {{r_{2}}^{2}}}-{6 \ {r_{1}}\ {r_{2}}}+{3 \ {{r_{1}}^{2}}}}, \: \right.
\
\
\displaystyle
\left.{{3 \ {r_{2}}}-{3 \ {r_{1}}}}, \: 1 \right] 
(2)
Type: List(Expression(Integer))
fricas
reduce(+,[i::OutputForm for i in t])=(r[2]::OutputForm-r[1]::OutputForm)^3

\label{eq3}\begin{array}{@{}l}
\displaystyle
{
\begin{array}{@{}l}
\displaystyle
{{r_{2}}^{3}}-{3 \ {r_{1}}\ {{r_{2}}^{2}}}+{3 \ {{r_{1}}^{2}}\ {r_{2}}}-{{r_{1}}^{3}}+{3 \ {{r_{2}}^{2}}}-{6 \ {r_{1}}\ {r_{2}}}+{3 \ {{r_{1}}^{2}}}+ 
\
\
\displaystyle
{3 \ {r_{2}}}-{3 \ {r_{1}}}+ 1 
(3)
Type: Equation(OutputForm?)
fricas
test(reduce(+,t) = ex)

\label{eq4} \mbox{\rm true} (4)
Type: Boolean

more tests --Bill Page, Wed, 24 Sep 2014 23:41:34 +0000 reply
fricas
)lib COLL
Collect is already explicitly exposed in frame initial Collect will be automatically loaded when needed from /var/aw/var/LatexWiki/COLL.NRLIB/COLL

fricas
ex:=a+b*x+c*x^2

\label{eq5}{c \ {{x}^{2}}}+{b \  x}+ a(5)
Type: Polynomial(Integer)
fricas
t:=collect(ex,x)

\label{eq6}\left[{c \ {{x}^{2}}}, \:{b \  x}, \: a \right](6)
Type: List(Expression(Integer))
fricas
test(reduce(+,t) = ex)

\label{eq7} \mbox{\rm true} (7)
Type: Boolean
fricas
--
ex:=(r[2]-r[1]+1)^3

\label{eq8}\begin{array}{@{}l}
\displaystyle
{{r_{2}}^{3}}+{{\left(-{3 \ {r_{1}}}+ 3 \right)}\ {{r_{2}}^{2}}}+{{\left({3 \ {{r_{1}}^{2}}}-{6 \ {r_{1}}}+ 3 \right)}\ {r_{2}}}-{{r_{1}}^{3}}+ 
\
\
\displaystyle
{3 \ {{r_{1}}^{2}}}-{3 \ {r_{1}}}+ 1 
(8)
Type: Polynomial(Integer)
fricas
t:=collect(ex,r[1]+r[2])

\label{eq9}\begin{array}{@{}l}
\displaystyle
\left[{-{{r_{2}}^{3}}-{3 \ {r_{1}}\ {{r_{2}}^{2}}}-{3 \ {{r_{1}}^{2}}\ {r_{2}}}-{{r_{1}}^{3}}}, \: \right.
\
\
\displaystyle
\left.{{6 \ {{r_{2}}^{3}}}+{{\left({{12}\ {r_{1}}}+ 3 \right)}\ {{r_{2}}^{2}}}+{{\left({6 \ {{r_{1}}^{2}}}+{6 \ {r_{1}}}\right)}\ {r_{2}}}+{3 \ {{r_{1}}^{2}}}}, \: \right.
\
\
\displaystyle
\left.{-{{12}\ {{r_{2}}^{3}}}+{{\left(-{{12}\ {r_{1}}}-{12}\right)}\ {{r_{2}}^{2}}}+{{\left(-{{12}\ {r_{1}}}- 3 \right)}\ {r_{2}}}-{3 \ {r_{1}}}}, \: \right.
\
\
\displaystyle
\left.{{8 \ {{r_{2}}^{3}}}+{{12}\ {{r_{2}}^{2}}}+{6 \ {r_{2}}}+ 1}\right] 
(9)
Type: List(Expression(Integer))
fricas
test(reduce(+,t) = ex)

\label{eq10} \mbox{\rm true} (10)
Type: Boolean
fricas
--
ex:=(r[2]-r[1]+1)^3

\label{eq11}\begin{array}{@{}l}
\displaystyle
{{r_{2}}^{3}}+{{\left(-{3 \ {r_{1}}}+ 3 \right)}\ {{r_{2}}^{2}}}+{{\left({3 \ {{r_{1}}^{2}}}-{6 \ {r_{1}}}+ 3 \right)}\ {r_{2}}}-{{r_{1}}^{3}}+ 
\
\
\displaystyle
{3 \ {{r_{1}}^{2}}}-{3 \ {r_{1}}}+ 1 
(11)
Type: Polynomial(Integer)
fricas
t:=collect(ex,r[2])

\label{eq12}\begin{array}{@{}l}
\displaystyle
\left[{{r_{2}}^{3}}, \:{{\left(-{3 \ {r_{1}}}+ 3 \right)}\ {{r_{2}}^{2}}}, \:{{\left({3 \ {{r_{1}}^{2}}}-{6 \ {r_{1}}}+ 3 \right)}\ {r_{2}}}, \: \right.
\
\
\displaystyle
\left.{-{{r_{1}}^{3}}+{3 \ {{r_{1}}^{2}}}-{3 \ {r_{1}}}+ 1}\right] (12)
Type: List(Expression(Integer))
fricas
test(reduce(+,t) = ex)

\label{eq13} \mbox{\rm true} (13)
Type: Boolean
fricas
--
ex:=1/(r[2]-r[1]+1)^3

\label{eq14}1 \over{\left(
\begin{array}{@{}l}
\displaystyle
{{r_{2}}^{3}}+{{\left(-{3 \ {r_{1}}}+ 3 \right)}\ {{r_{2}}^{2}}}+{{\left({3 \ {{r_{1}}^{2}}}-{6 \ {r_{1}}}+ 3 \right)}\ {r_{2}}}-{{r_{1}}^{3}}+ 
\
\
\displaystyle
{3 \ {{r_{1}}^{2}}}-{3 \ {r_{1}}}+ 1 
(14)
Type: Fraction(Polynomial(Integer))
fricas
t:=collect(ex,1/r[1])

\label{eq15}\left[ 1 \over{{{r_{2}}^{3}}+{{\left(-{3 \ {r_{1}}}+ 3 \right)}\ {{r_{2}}^{2}}}+{{\left({3 \ {{r_{1}}^{2}}}-{6 \ {r_{1}}}+ 3 \right)}\ {r_{2}}}-{{r_{1}}^{3}}+{3 \ {{r_{1}}^{2}}}-{3 \ {r_{1}}}+ 1}\right](15)
Type: List(Expression(Integer))
fricas
test(reduce(+,t) = ex)

\label{eq16} \mbox{\rm true} (16)
Type: Boolean