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

The domain InputForm can be quite useful for manipulating parts
of expressions. For example

axiom
ex1:=integrate(log(x)+x, x)
\begin{equation} \label{eq1}{{2 \ x \ {\log \left({x}\right)}}+{x^2}-{2 \ x}}\over 2\end{equation}
Type: Union(Expression(Integer),...)
axiom
%::InputForm
\begin{equation} \label{eq2}\left(/ \ {\left(+ \ {\left( \ {\left( \ 2 \ x \right)}\ {\left(\log \ x \right)}\right)}\ {\left(+ \ {\left(^\ x \ 2 \right)}\ {\left( \ - 2 \ x \right)}\right)}\right)}\ 2 \right)\end{equation*}
Type: InputForm
axiom
ex2:=interpret((%::InputForm).2.2)
\begin{equation} \label{eq3}2 \ x \ {\log \left({x}\right)}\end{equation}
Type: Expression(Integer)

If you would like to do this with a more common type of expression and hide the details, you can define

axiom
op(n,x) == interpret((x::InputForm).(n+1))
Type: Void

Then manipulating expressions looks like this:

axiom
op(1,ex1)
axiom
Compiling function op with type (PositiveInteger,Expression(Integer)
      ) -> Any
\begin{equation} \label{eq4}{2 \ x \ {\log \left({x}\right)}}+{x^2}-{2 \ x}\end{equation}
Type: Expression(Integer)
axiom
op(1,%)
axiom
Compiling function op with type (PositiveInteger,Any) -> Any
\begin{equation} \label{eq5}2 \ x \ {\log \left({x}\right)}\end{equation}
Type: Expression(Integer)
axiom
(op(1,op(1,ex1))-op(2,op(1,ex1)))/op(2,ex1)
\begin{equation} \label{eq6}{{2 \ x \ {\log \left({x}\right)}}-{x^2}+{2 \ x}}\over 2\end{equation}
Type: Expression(Integer)

Rules and Pattern Matching (from WesterProblemSet)

Trigonometric manipulations---these are typically difficult for students

axiom
r:= cos(3*x)/cos(x)
\begin{equation} \label{eq7}{\cos \left({3 \ x}\right)}\over{\cos \left({x}\right)}\end{equation}
Type: Expression(Integer)

=> cos(x)^2 - 3 sin(x)^2 or similar

axiom
real(complexNormalize(r))
\begin{equation} \label{eq8}-{2 \ {{\sin \left({x}\right)}^2}}+{2 \ {{\cos \left({x}\right)}^2}}- 1\end{equation}
Type: Expression(Integer)

=> 2 cos(2 x) - 1

axiom
real(normalize(simplify(complexNormalize(r))))
\begin{equation} \label{eq9}{2 \ {\cos \left({2 \ x}\right)}}- 1\end{equation}
Type: Expression(Integer)

Use rewrite rules => cos(x)^2 - 3 sin(x)^2

axiom
sincosAngles:= rule
   cos((n | integer?(n)) * x) ==
      cos((n - 1)*x) * cos(x) - sin((n - 1)*x) * sin(x)
   sin((n | integer?(n)) * x) ==
      sin((n - 1)*x) * cos(x) + cos((n - 1)*x) * sin(x)
\begin{equation*} \label{eq10}\begin{array}{@{}l} \displaystyle \left\{{{\cos \left({n \ x}\right)}\mbox{\rm = =}{-{{\sin \left({x}\right)}\ {\sin \left({{\left(n - 1 \right)}\ x}\right)}}+{{\cos \left({x}\right)}\ {\cos \left({{\left(n - 1 \right)}\ x}\right)}}}}, \right. \ \ \displaystyle \left.\:{{\sin \left({n \ x}\right)}\mbox{\rm = =}{{{\cos \left({x}\right)}\ {\sin \left({{\left(n - 1 \right)}\ x}\right)}}+{{\cos \left({{\left(n - 1 \right)}\ x}\right)}\ {\sin \left({x}\right)}}}}\right\} \end{array} \end{equation*}
Type: Ruleset(Integer,Integer,Expression(Integer))

axiom
sincosAngles r
\begin{equation} \label{eq11}-{3 \ {{\sin \left({x}\right)}^2}}+{{\cos \left({x}\right)}^2}\end{equation}
Type: Expression(Integer)

Other Operations

The domain FunctionSpace? includes the following operations:

    isExpt(p,f:Symbol) returns [x, n] if p = x**n and n <> 0 and x = f(a)
    isExpt(p,op:BasicOperator) returns [x, n] if p = x**n and n <> 0 and x = op(a)
    isExpt(p) returns [x, n] if p = x**n and n <> 0
    isMult(p) returns [n, x] if p = n * x and n <> 0
    isPlus(p) returns [m1,...,mn] if p = m1 +...+ mn and n > 1
    isPower(p) returns [x, n] if p = x**n and n <> 0
    isTimes(p) returns [a1,...,an] if p = a1*...*an and n > 1

If these conditions are not met, then the above operations return "failed".

For example,

axiom
isMult(3*x)
\begin{equation*} \label{eq12}\left[{coef = 3}, \:{var = x}\right]?\end{equation*}
Type: Union(Record(coef: Integer,var: Kernel(Expression(Integer))),...)

but

axiom
isMult(x*y)
\begin{equation} \label{eq13}\mbox{\tt "failed"}\end{equation}
Type: Union("failed",...)

In the context of Expression Integer, or Polynomial Integer the parameter n must be an Integer. The Symbol y is not an Integer.

Not exactly analogously

axiom
isPower(x**y)
\begin{equation*} \label{eq14}\left[{val ={x^y}}, \:{exponent = 1}\right]?\end{equation*}
Type: Union(Record(val: Expression(Integer),exponent: Integer),...)

whereas

axiom
isPower(x**10)
\begin{equation*} \label{eq15}\left[{val = x}, \:{exponent ={10}}\right]?\end{equation*}
Type: Union(Record(val: Expression(Integer),exponent: Integer),...)

In the first case the Integer is assume to be 1.

We have:

axiom
isTimes(x*y*z)
\begin{equation*} \label{eq16}\left[ z , \: y , \: x \right]?\end{equation*}
Type: Union(List(Polynomial(Integer)),...)
axiom
isPlus(x+y+z*y)
\begin{equation*} \label{eq17}\left[{y \ z}, \: y , \: x \right]?\end{equation*}
Type: Union(List(Polynomial(Integer)),...)

Whereas

axiom
isTimes((x+y)*z)
\begin{equation} \label{eq18}\mbox{\tt "failed"}\end{equation}
Type: Union("failed",...)

That is because the expression is internally treated as a MultivariatePolynomial like this:

axiom
((x+y)*z)::MPOLY([x,y,z],INT)
\begin{equation} \label{eq19}{z \ x}+{z \ y}\end{equation}
Type: MultivariatePolynomial([x,y,z],Integer)

If you say:

axiom
isPlus((x+y)*z)
\begin{equation*} \label{eq20}\left[{y \ z}, \:{x \ z}\right]?\end{equation*}
Type: Union(List(Polynomial(Integer)),...)

perhaps the result makes sense?

For some of the details of these operations I consulted the actual algebra code at:

http://axiom-wiki.newsynthesis.org/axiom--test--1/src/algebra/FspaceSpad

Click on pdf or dvi to see the documentation.

You can also enter expressions like isTimes in the search box on the upper right and see all the places in the algebra where this operation is defined and used.


Some or all expressions may not have rendered properly, because Latex returned the following error:
This is pdfTeXk, Version 3.141592-1.40.3 (Web2C 7.5.6)
 \write18 enabled.
 %&-line parsing enabled.
entering extended mode
(./6071826033674697477-16.0px.tex
LaTeX2e <2005/12/01>
Babel <v3.8h> and hyphenation patterns for english, usenglishmax, dumylang, noh
yphenation, arabic, farsi, croatian, ukrainian, russian, bulgarian, czech, slov
ak, danish, dutch, finnish, basque, french, german, ngerman, ibycus, greek, mon
ogreek, ancientgreek, hungarian, italian, latin, mongolian, norsk, icelandic, i
nterlingua, turkish, coptic, romanian, welsh, serbian, slovenian, estonian, esp
eranto, uppersorbian, indonesian, polish, portuguese, spanish, catalan, galicia
n, swedish, ukenglish, pinyin, loaded.
(/usr/share/texmf-texlive/tex/latex/base/article.cls
Document Class: article 2005/09/16 v1.4f Standard LaTeX document class
(/usr/share/texmf-texlive/tex/latex/base/size12.clo))
(/usr/share/texmf-texlive/tex/latex/amsmath/amsmath.sty
For additional information on amsmath, use the `? option.
(/usr/share/texmf-texlive/tex/latex/amsmath/amstext.sty
(/usr/share/texmf-texlive/tex/latex/amsmath/amsgen.sty))
(/usr/share/texmf-texlive/tex/latex/amsmath/amsbsy.sty)
(/usr/share/texmf-texlive/tex/latex/amsmath/amsopn.sty))
(/usr/share/texmf-texlive/tex/latex/amsfonts/amsfonts.sty)
(/usr/share/texmf-texlive/tex/latex/amsfonts/amssymb.sty)
(/usr/share/texmf-texlive/tex/latex/amscls/amsthm.sty)
(/usr/share/texmf-texlive/tex/latex/setspace/setspace.sty
Package: `setspace 6.7 <2000/12/01>
) (/usr/share/texmf-texlive/tex/generic/xypic/xy.sty
(/usr/share/texmf-texlive/tex/generic/xypic/xy.tex Bootstrap'ing: catcodes,
docmode, (/usr/share/texmf-texlive/tex/generic/xypic/xyrecat.tex)
(/usr/share/texmf-texlive/tex/generic/xypic/xyidioms.tex)

Xy-pic version 3.7 <1999/02/16> Copyright (c) 1991-1998 by Kristoffer H. Rose <krisrose@ens-lyon.fr> Xy-pic is free software: see the User's Guide for details.

Loading kernel: messages; fonts; allocations: state, direction, utility macros; pictures: \xy, positions, objects, decorations; kernel objects: directionals, circles, text; options; algorithms: directions, edges, connections; Xy-pic loaded) (/usr/share/texmf-texlive/tex/generic/xypic/xyall.tex Xy-pic option: All features v.3.3 (/usr/share/texmf-texlive/tex/generic/xypic/xycurve.tex Xy-pic option: Curve and Spline extension v.3.7 curve, circles, loaded) (/usr/share/texmf-texlive/tex/generic/xypic/xyframe.tex Xy-pic option: Frame and Bracket extension v.3.7 loaded) (/usr/share/texmf-texlive/tex/generic/xypic/xycmtip.tex Xy-pic option: Computer Modern tip extension v.3.3 (/usr/share/texmf-texlive/tex/generic/xypic/xytips.tex Xy-pic option: More Tips extension v.3.3 loaded) loaded) (/usr/share/texmf-texlive/tex/generic/xypic/xyline.tex Xy-pic option: Line styles extension v.3.6 loaded) (/usr/share/texmf-texlive/tex/generic/xypic/xyrotate.tex Xy-pic option: Rotate and Scale extension v.3.3 loaded) (/usr/share/texmf-texlive/tex/generic/xypic/xycolor.tex Xy-pic option: Colour extension v.3.3 loaded) (/usr/share/texmf-texlive/tex/generic/xypic/xymatrix.tex Xy-pic option: Matrix feature v.3.4 loaded) (/usr/share/texmf-texlive/tex/generic/xypic/xyarrow.tex Xy-pic option: Arrow and Path feature v.3.5 path, \ar, loaded) (/usr/share/texmf-texlive/tex/generic/xypic/xygraph.tex Xy-pic option: Graph feature v.3.7 loaded) loaded)) (/usr/share/texmf-texlive/tex/latex/graphics/graphicx.sty (/usr/share/texmf-texlive/tex/latex/graphics/keyval.sty) (/usr/share/texmf-texlive/tex/latex/graphics/graphics.sty (/usr/share/texmf-texlive/tex/latex/graphics/trig.sty) (/etc/texmf/tex/latex/config/graphics.cfg) (/usr/share/texmf-texlive/tex/latex/graphics/dvips.def))) (/usr/share/texmf-texlive/tex/latex/graphics/color.sty (/etc/texmf/tex/latex/config/color.cfg) (/usr/share/texmf-texlive/tex/latex/graphics/dvipsnam.def)) (/usr/share/texmf-texlive/tex/latex/tools/verbatim.sty) (/usr/share/texmf/tex/latex/graphviz/graphviz.sty (/usr/share/texmf-texlive/tex/latex/psfrag/psfrag.sty)) (/usr/share/texmf/tex/latex/sagetex.sty Writing sage input file 6071826033674697477-16.0px.sage (./6071826033674697477-16.0px.sout)) (/usr/share/texmf-texlive/tex/latex/gnuplottex/gnuplottex.sty (/usr/share/texmf-texlive/tex/latex/base/latexsym.sty) (/usr/share/texmf-texlive/tex/latex/moreverb/moreverb.sty) (/usr/share/texmf-texlive/tex/latex/base/ifthen.sty)) (./6071826033674697477-16.0px.aux) (/usr/share/texmf-texlive/tex/latex/amsfonts/umsa.fd) (/usr/share/texmf-texlive/tex/latex/amsfonts/umsb.fd) (/usr/share/texmf-texlive/tex/latex/base/ulasy.fd)

Package amsmath Warning: Foreign command \over; (amsmath) \frac or \genfrac should be used instead (amsmath) on input line 63.

[1] Missing { inserted. <to be read again> \ l.66 ... x \right)}\right)}\ {\left(+ \ {\left(^\ x \ 2 \right)}\ {\left(*...

Missing } inserted. <inserted text> } l.66 ...ght)}\ {\left(+ \ {\left(^\ x \ 2 \right )}\ {\left(* \ - 2 \ x \...

[2] [3] [4] [5] [6] [7] [8] [9] [10] [11] [12] [13] [14] [15] [16] [17] [18] [19] [20] (./6071826033674697477-16.0px.aux) ) (see the transcript file for additional information) Output written on 6071826033674697477-16.0px.dvi (20 pages, 5776 bytes). Transcript written on 6071826033674697477-16.0px.log.




  Subject:   Be Bold !!
  ( 7 subscribers )  
Please rate this page: