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

Edit detail for indexed variables revision 1 of 2

1 2
Editor: 127.0.0.1
Time: 2007/11/15 20:12:49 GMT-8
Note: transferred from axiom-developer

changed:
-
I am trying to create formulae for products with, say, p sub k as 
symbols. These are the results from two, at least naively identical formulae:

\begin{axiom}
(1+p[1])*(1+p[2])
product(1+p[k],k=1..2)
\end{axiom}

But perhaps unexpectedly, the 2nd command is interpreted as just $(1+p_k)^2$.

How could one use "product" (or "sum" for that reason) and an indexed way to 
denote variables?

--------------

In Axiom 'product' denotes the *formal product* and in this example is
looking for an expression involving the variable k. For example:

\begin{axiom}
product(sin(k),k=1..3)
\end{axiom}

But despite appearances the symbol $k$ in $p[k]$ in the previous command
is not what Axiom considers a *variable*. In Axiom $p[k]$ is assumed to be
of type symbol, $k$ is assumed to be a variable but variables can be coerced
to be a symbol. Only variables can be assigned values but any symbol can
"stand for" unknown values in expressions.

\begin{axiom}
p[k]
1+p[k]
p[k]:=1
\end{axiom}

Understanding this distinction is somethimes important to understand why
Axiom does what it does. $1+p[k]$ is assumed to be a polynomial over $p[k]$
not $k$.

In fact, much more complicated indexed symbols can be created in Axiom. For
example

\begin{axiom}
P ==> script(p,[[a,b],[c],[d],[e]])
reduce(+, [P for a in 1..3])
\end{axiom}

Within this MathAction Axiom wiki it is also possible to create
symbols that will be displayed as superscripted or subscripted
variables which can be assigned values. In fact any LaTeX symbol
can be generated by using the underscore charact to "protect"
special charactes such as \\. For example

\begin{axiom}
Q:=p_^_\alpha___\beta
1+Q
\end{axiom}

In the above the first underscore protects the second underscore which is
then handled by LaTeX as the beginning of a subscript and next underscore
protects the \\ which begins a Greek letter, etc. Axiom treats the entire
thing as a long variable name. Note however that this only
works here and not within stand alone Axiom.

Probably what you should write is

\begin{axiom}
reduce(*,[1+p[k] for k in 1..2])
\end{axiom}

Here the operation of 'for', creating a sequence, does not treat::

  1+p[k]

as a polynomial over $p[k]$ but the final result is a polynomial.

The same comments apply to sum() which represents a 'formal sum'.

Alternatively, and more generally, one can use BasicOperator
\begin{axiom}
p:=operator 'p
p(1)
p(k)
product(1+p(k),k=1..2)
\end{axiom}

You can attach a display property so that the argument to p appears as a subscript
\begin{axiom}
displayOfp(l:List OUTFORM):OUTFORM == subscript('p,l)
display(p,displayOfp)
product(1+p(k),k=1..2)
\end{axiom}


You can also attach an evaluation property to handle particular values of the argument
\begin{axiom}
evalOfp(a:EXPR INT):EXPR INT == {one? a => 1 ; kernel(p,a)}
evaluate(p,evalOfp)
[p 1,p 2, p k]
product(1+p(k),k=1..2)
\end{axiom}

From ChristianSievers Tue May 23 07:02:10 -0500 2006
From: Christian Sievers
Date: Tue, 23 May 2006 07:02:10 -0500
Subject: likewise for indexing into lists
Message-ID: <20060523070210-0500@wiki.axiom-developer.org>

This is related:

\begin{axiom}
l:=[1,2,4,8,16]
sum(l.(1+2*k),k=0..2)
sum(elt(l,1+2*k),k=0..2)
reduce(+,[l.(1+2*k) for k in 0..2])
\end{axiom}


I am trying to create formulae for products with, say, p sub k as symbols. These are the results from two, at least naively identical formulae:

fricas
(1+p[1])*(1+p[2])

\label{eq1}{{\left({p_{1}}+ 1 \right)}\ {p_{2}}}+{p_{1}}+ 1(1)
Type: Polynomial(Integer)
fricas
product(1+p[k],k=1..2)

\label{eq2}{{p_{k}}^{2}}+{2 \ {p_{k}}}+ 1(2)
Type: Expression(Integer)

But perhaps unexpectedly, the 2nd command is interpreted as just (1+p_k)^2.

How could one use "product" (or "sum" for that reason) and an indexed way to denote variables?

--------------

In Axiom product denotes the formal product and in this example is looking for an expression involving the variable k. For example:

fricas
product(sin(k),k=1..3)

\label{eq3}{\sin \left({1}\right)}\ {\sin \left({2}\right)}\ {\sin \left({3}\right)}(3)
Type: Expression(Integer)

But despite appearances the symbol k in p[k] in the previous command is not what Axiom considers a variable. In Axiom p[k] is assumed to be of type symbol, k is assumed to be a variable but variables can be coerced to be a symbol. Only variables can be assigned values but any symbol can "stand for" unknown values in expressions.

fricas
p[k]

\label{eq4}p_{k}(4)
Type: Symbol
fricas
1+p[k]

\label{eq5}{p_{k}}+ 1(5)
Type: Polynomial(Integer)
fricas
p[k]:=1
The form on the left hand side of an assignment must be a single variable, a Tuple of variables or a reference to an entry in an object supporting the setelt operation.

Understanding this distinction is somethimes important to understand why Axiom does what it does. 1+p[k] is assumed to be a polynomial over p[k] not k.

In fact, much more complicated indexed symbols can be created in Axiom. For example

fricas
P ==> script(p,[[a,b],[c],[d],[e]])
Type: Void
fricas
reduce(+, [P for a in 1..3])

\label{eq6}{{}_{e}^{d}p_{3, \: b}^{c}}+{{}_{e}^{d}p_{2, \: b}^{c}}+{{}_{e}^{d}p_{1, \: b}^{c}}(6)
Type: Polynomial(Integer)

Within this MathAction? Axiom wiki it is also possible to create symbols that will be displayed as superscripted or subscripted variables which can be assigned values. In fact any LaTeX? symbol can be generated by using the underscore charact to "protect" special charactes such as \. For example

fricas
Q:=p_^_\alpha___\beta

\label{eq7}p^\alpha \<u> \beta(7)
Type: Variable(p^\alpha_\beta)
fricas
1+Q

\label{eq8}p^\alpha \<u> \beta + 1(8)
Type: Polynomial(Integer)

In the above the first underscore protects the second underscore which is then handled by LaTeX? as the beginning of a subscript and next underscore protects the \ which begins a Greek letter, etc. Axiom treats the entire thing as a long variable name. Note however that this only works here and not within stand alone Axiom.

Probably what you should write is

fricas
reduce(*,[1+p[k] for k in 1..2])

\label{eq9}{{\left({p_{1}}+ 1 \right)}\ {p_{2}}}+{p_{1}}+ 1(9)
Type: Polynomial(Integer)

Here the operation of for, creating a sequence, does not treat:

  1+p[k]

as a polynomial over p[k] but the final result is a polynomial.

The same comments apply to sum() which represents a formal sum.

Alternatively, and more generally, one can use BasicOperator?

fricas
p:=operator 'p

\label{eq10}p(10)
Type: BasicOperator?
fricas
p(1)

\label{eq11}p \left({1}\right)(11)
Type: Expression(Integer)
fricas
p(k)

\label{eq12}p \left({k}\right)(12)
Type: Expression(Integer)
fricas
product(1+p(k),k=1..2)

\label{eq13}{{\left({p \left({1}\right)}+ 1 \right)}\ {p \left({2}\right)}}+{p \left({1}\right)}+ 1(13)
Type: Expression(Integer)

You can attach a display property so that the argument to p appears as a subscript

fricas
displayOfp(l:List OUTFORM):OUTFORM == subscript('p,l)
Function declaration displayOfp : List(OutputForm) -> OutputForm has been added to workspace.
Type: Void
fricas
display(p,displayOfp)
fricas
Compiling function displayOfp with type List(OutputForm) -> 
      OutputForm

\label{eq14}p(14)
Type: BasicOperator?
fricas
product(1+p(k),k=1..2)

\label{eq15}{{\left({p_{1}}+ 1 \right)}\ {p_{2}}}+{p_{1}}+ 1(15)
Type: Expression(Integer)

You can also attach an evaluation property to handle particular values of the argument

fricas
evalOfp(a:EXPR INT):EXPR INT == {one? a => 1 ; kernel(p,a)}
Function declaration evalOfp : Expression(Integer) -> Expression( Integer) has been added to workspace.
Type: Void
fricas
evaluate(p,evalOfp)
fricas
Compiling function evalOfp with type Expression(Integer) -> 
      Expression(Integer)

\label{eq16}p(16)
Type: BasicOperator?
fricas
[p 1,p 2, p k]

\label{eq17}\left[ 1, \:{p_{2}}, \:{p_{k}}\right](17)
Type: List(Expression(Integer))
fricas
product(1+p(k),k=1..2)

\label{eq18}{2 \ {p_{2}}}+ 2(18)
Type: Expression(Integer)

likewise for indexing into lists --Christian Sievers, Tue, 23 May 2006 07:02:10 -0500 reply
This is related:

fricas
l:=[1,2,4,8,16]

\label{eq19}\left[ 1, \: 2, \: 4, \: 8, \:{16}\right](19)
Type: List(PositiveInteger?)
fricas
sum(l.(1+2*k),k=0..2)
There are no library operations named l Use HyperDoc Browse or issue )what op l to learn if there is any operation containing " l " in its name.
Cannot find a definition or applicable library operation named l with argument type(s) Polynomial(Integer)
Perhaps you should use "@" to indicate the required return type, or "$" to specify which version of the function you need.