Higher-level symbolic manipulations

12 views
Skip to first unread message

Ryan Hinton

unread,
Jun 30, 2010, 11:59:42 AM6/30/10
to sage-support
I have a bevy of algebra/calculus to work through for my research. I
have been using Sage to check my derivation for specific instances,
but it would be great if Sage could help me *derive* the results in
the first place.

Here is a simplified example. (Hopefully the mixed math/LaTeX/Sage
syntax makes sense.) I have a multivariate generating function in x1,
x2, ..., xn and a list of exponents {di} where each di can be
considered a vector [di1, di2, ..., din]. Then I have a generating
function like the following.

F1(x) = prod_{di} (1 + ci * x^di)

where {ci} are constants associated with each exponent, and

x^d = x1^di1 * x2^di2 * ... * xn^din.

Now I want to find the functions

ai(x) = xi * F1.derivative(xi) / F1

Can I do this in Sage? I have a fixed but arbitrary (symbolic) number
of variables in my function. I want to create a function based on an
unspecified list of exponents. Then I want an equation for a new list
of functions based on the original function and its derivatives. Can
I do this all symbolically? Is there another CAS that can do it?

Thanks!

- Ryan

pang

unread,
Jun 30, 2010, 1:37:51 PM6/30/10
to sage-support
> Can I do this in Sage?

Sure. Here you have some tips:

{{{id=1|
#Create n variables with names x1, x2 ... xn
#and store them in a list vs
n = 5
vs = var(' '.join('x%d'%j for j in range(5)))
vs
///
(x0, x1, x2, x3, x4)
}}}

{{{id=6|
def pot(vs,ds):
return prod(v^d for v,d in zip(vs,ds))

pot(vs,[1,2,3])
///
x0*x1^2*x2^3
}}}

{{{id=2|
def generating_function(cs):
return prod(1 + c*pot(vs,ds) for ds,c in cs.items())

generating_function({(1,1,0,0,1):3, (1,1,0,0,0):5})
///
(5*x0*x1 + 1)*(3*x0*x1*x4 + 1)
}}}

Ryan Hinton

unread,
Jun 30, 2010, 4:45:01 PM6/30/10
to sage-support
Thanks for the reply! That's a perfect example of what I am doing
now. Can I go one level higher and define my generating function as a
product of terms *while leaving the actual degrees, coefficients, and
even the number of dimensions symbolic*. So instead of getting
something like

(5*x0*x1 + 1)*(3*x0*x1*x4 + 1)

I want to get something like

product(exponent_list, lambda c,d: 1 + c * pot(x, d))

Maybe the second argument should be some kind of a paramaterizable
expression. So what I'm looking for is a "first-class" product/
summation construct, and an arbitrary number of generators for my
formal power sum. Even a way to specify the generic construct

vector_power(x, d)

that will float around in my expressions until I take a derivative.
For example, I want something notionally like the following.

sage: vector_power(x,d).derivative(x[1])
d[1] * vector_power(x,d) / x[1]

So the ``vector_power`` construct would have to know how to use the
power rule of differentiation.

Does this make sense? Is it possible?

Thanks!

- Ryan

Ryan Hinton

unread,
Jun 30, 2010, 5:48:20 PM6/30/10
to sage-support
I may have the answer: no, not directly.

Sage includes Pynac, which wraps GiNaC. GiNaC has indexed
expressions, which just might do exactly what I want. (I don't have
ginsh running to test differentiation.) But it looks like indexed
expressions are not hooked up for use in Sage. I am posting to sage-
devel to investigate further.

- Ryan

pang

unread,
Jun 30, 2010, 5:49:51 PM6/30/10
to sage-support
On 30 jun, 22:45, Ryan Hinton <iob...@email.com> wrote:
> Thanks for the reply!  That's a perfect example of what I am doing
> now.  Can I go one level higher and define my generating function as a
> product of terms *while leaving the actual degrees, coefficients, and
> even the number of dimensions symbolic*.  

I don't know any direct way, but I can suggest:

* Use symbolic variables for the exponents. I understand you need a
potentially infinite number, but maybe you can achieve your goals with
a big finite number, or maybe you can create more variables on the fly
as needed.

* Write some python classes. This could just be a neat way to hide the
creation of variables as they are needed, but with a little more
work...

* Look at sage-combinat. Their Word object behaves in some aspects as
you describe. This could give you inspiration, or maybe something
more:

sage: f = lambda n : add(Integer(n).digits(2)) % 2
sage: Word(f)
word: 0110100110010110100101100110100110010110...

* Wait for someone more inspired to reply.

Good luck!
Reply all
Reply to author
Forward
0 new messages