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

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])
 (1)
Type: Polynomial(Integer)
fricas
product(1+p[k],k=1..2)
 (2)
Type: Expression(Integer)

But perhaps unexpectedly, the 2nd command is interpreted as just .

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

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

In FriCAS 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)
 (3)
Type: Expression(Integer)

But despite appearances the symbol in in the previous command is not what FriCAS considers a variable. In FriCAS is assumed to be of type symbol, 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]
 (4)
Type: Symbol
fricas
1+p[k]
 (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 FriCAS does what it does. is assumed to be a polynomial over not .

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

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

Within this MathAction FriCAS 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
 (7)
Type: Variable(p^\alpha_\beta)
fricas
1+Q
 (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. FriCAS treats the entire thing as a long variable name. Note however that this only works here and not within stand alone FriCAS.

Probably what you should write is

fricas
reduce(*,[1+p[k] for k in 1..2])
 (9)
Type: Polynomial(Integer)

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

  1+p[k]


as a polynomial over 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
 (10)
Type: BasicOperator?
fricas
p(1)
 (11)
Type: Expression(Integer)
fricas
p(k)
 (12)
Type: Expression(Integer)
fricas
product(1+p(k),k=1..2)
 (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
 (14)
Type: BasicOperator?
fricas
product(1+p(k),k=1..2)
 (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)
 (16)
Type: BasicOperator?
fricas
[p 1,p 2, p k]
 (17)
Type: List(Expression(Integer))
fricas
product(1+p(k),k=1..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]
 (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.

 Subject:   Be Bold !! ( 15 subscribers )