[sage-support] Re: Higher-level symbolic manipulations
On 30 jun, 22:45, Ryan Hinton 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! -- To post to this group, send email to sage-support@googlegroups.com To unsubscribe from this group, send email to sage-support+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/sage-support URL: http://www.sagemath.org
[sage-support] Re: Higher-level symbolic manipulations
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 On Jun 30, 2:45 pm, Ryan Hinton 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*. 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 > > On Jun 30, 11:37 am, pang wrote: > > > > 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) > > > }}} -- To post to this group, send email to sage-support@googlegroups.com To unsubscribe from this group, send email to sage-support+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/sage-support URL: http://www.sagemath.org
[sage-support] Re: Higher-level symbolic manipulations
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 On Jun 30, 11:37 am, pang wrote: > > 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) > > }}} -- To post to this group, send email to sage-support@googlegroups.com To unsubscribe from this group, send email to sage-support+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/sage-support URL: http://www.sagemath.org
[sage-support] Re: Dirac Comb
> This looks like a bug in the way symbolic sums are handled: > > http://trac.sagemath.org/sage_trac/ticket/9393 > > For a workaround, try renaming your file to have the extension .sage > instead of .py. > > BTW, to any developer reading this: > > A brief search through the tutorial or the FAQ included in Sage didn't > reveal anything to link to, is there a canonical point to refer to for > these questions? Where is the preparser and differences between Python > and Sage documented? > > Cheers, > Burcin Is this what you're looking for? http://www.sagemath.org/doc/developer/coding_in_python.html#sage-preparsing -- Tianwei -- To post to this group, send email to sage-support@googlegroups.com To unsubscribe from this group, send email to sage-support+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/sage-support URL: http://www.sagemath.org
[sage-support] Re: Higher-level symbolic manipulations
> 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) }}} -- To post to this group, send email to sage-support@googlegroups.com To unsubscribe from this group, send email to sage-support+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/sage-support URL: http://www.sagemath.org
[sage-support] Higher-level symbolic manipulations
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 -- To post to this group, send email to sage-support@googlegroups.com To unsubscribe from this group, send email to sage-support+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/sage-support URL: http://www.sagemath.org
Re: [sage-support] Re: Simplification / Latex question
On 06/30/2010 05:06:19 AM, Burcin Erocal wrote: On Fri, 25 Jun 2010 07:53:00 -0700 Mike Witt wrote: > On 06/25/2010 06:07:02 AM, kcrisman wrote: > > Dear Mike, > > > > Just to follow up: > > > > There is further discussion at > > http://trac.sagemath.org/sage_trac/ticket/9329 > > if you are interested in saying exactly what sort of data structure > > would enable you to perform the simplifications you would like to > > without having to create a custom Maxima simplification routine. > > > > - kcrisman > > Well ... I can see how one might work one's way > through the expression, using the operator() and operands() > functions. And, I suppose, I can see how one could then build > up the equivalent expression, having modified one of the > operands in a certain way. So, I don't suppose that there is > actually any need for a custom data structure to do this. As far as I understand from your previous comments, a way to extract the exponential functions from the expression is all you need. You don't really need to walk through the tree. Here is one way to do this: sage: t = exp(x+y)*(x-y)*(exp(y)+exp(z-y)) sage: t (e^(-y + z) + e^y)*(x - y)*e^(x + y) sage: w = SR.wild() sage: t.find(exp(w)) [e^(-y + z), e^(x + y), e^y] You can then change the expressions in the given array and substitute new values for them: sage: t.subs({res[1]: sin(res[1].operands()[0])}) (e^(-y + z) + e^y)*(x - y)*sin(x + y) The .operands()[0] syntax is really cumbersome. We need a shortcut for this. I thought .op(0) worked for pynac expressions before we switched from the maxima backend. > Although ... I guess I'm still a bit confused as to why > this happens, even given the form of the exponential. > > sage: f = e^(2*I*pi*n*x - 2*I*pi*n) > sage: latex(f) > e^{\left(\left(2 I\right) \, \pi n x + \left(-2 I\right) \, \pi > n\right)} > > Still, I shouldn't really get +(-2i) right? This is a bug: http://trac.sagemath.org/sage_trac/ticket/9394 I'll fix this when I have time to work on pynac again. Cheers, Burcin -- To post to this group, send email to sage-support@googlegroups.com To unsubscribe from this group, send email to sage-support+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/sage-support URL: http://www.sagemath.org Thanks. That's a good idea. I'll try that. -Mike -- To post to this group, send email to sage-support@googlegroups.com To unsubscribe from this group, send email to sage-support+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/sage-support URL: http://www.sagemath.org
[sage-support] Re: how to install new Gap package in sage
thank you so much . On Jun 28, 8:23 pm, Simon King wrote: > Hi! > > On Jun 28, 6:58 pm, "A.A" wrote: > > > I am looking for tutorial about how one can install new Gap package in > > sage if this possible . > > In a nutshell: A GAP package should be possible to install just as > usual, with the only exception that you need to perform the > installation in a Sage shell. > > So, the following should work: > > 1. In a terminal session, open the sage shell with the command > sage -sh > in your Unix/Linux shell. > Inside this shell, the command "gap" refers to the GAP program that > belongs to Sage. > > 2. Install your package just as you would usually do. Often, GAP > packages simply need to be unpacked in GAP's pkg directory. You will > find it at $SAGE_ROOT/local/lib/gap-4.4.12/pkg/ (SAGE_ROOT is an > environment variable that yields the directory in which Sage is > installed). > > 3. Leave the sage shell (by exit or by Ctrl-d). Start Sage; it might > then be needed to launch the command > sage: gap_reset_workspace() > in your Sage session. > > 4. Now, the package should work. > > Cheers, > Simon -- To post to this group, send email to sage-support@googlegroups.com To unsubscribe from this group, send email to sage-support+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/sage-support URL: http://www.sagemath.org
[sage-support] pretty print in full output
Hello , I want to ask if there is build in method to use pretty print in full output . i.e (when I do some long calculations the output will truncated , and the pretty print does not render in full output ) thanks -- To post to this group, send email to sage-support@googlegroups.com To unsubscribe from this group, send email to sage-support+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/sage-support URL: http://www.sagemath.org
[sage-support] Re: Simplification / Latex question
> As far as I understand from your previous comments, a way to extract the > exponential functions from the expression is all you need. You don't > really need to walk through the tree. Here is one way to do this: > > sage: t = exp(x+y)*(x-y)*(exp(y)+exp(z-y)) > sage: t > (e^(-y + z) + e^y)*(x - y)*e^(x + y) > sage: w = SR.wild() > sage: t.find(exp(w)) > [e^(-y + z), e^(x + y), e^y] > > You can then change the expressions in the given array and substitute > new values for them: Did you define res in between? Maybe this? Just a guess. sage: res = t.find(exp(w)) > > sage: t.subs({res[1]: sin(res[1].operands()[0])}) > (e^(-y + z) + e^y)*(x - y)*sin(x + y) > > The .operands()[0] syntax is really cumbersome. We need a shortcut for > this. I thought .op(0) worked for pynac expressions before we switched > from the maxima backend. > -- To post to this group, send email to sage-support@googlegroups.com To unsubscribe from this group, send email to sage-support+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/sage-support URL: http://www.sagemath.org
Re: [sage-support] Re: Simplification / Latex question
On Fri, 25 Jun 2010 07:53:00 -0700 Mike Witt wrote: > On 06/25/2010 06:07:02 AM, kcrisman wrote: > > Dear Mike, > > > > Just to follow up: > > > > There is further discussion at > > http://trac.sagemath.org/sage_trac/ticket/9329 > > if you are interested in saying exactly what sort of data structure > > would enable you to perform the simplifications you would like to > > without having to create a custom Maxima simplification routine. > > > > - kcrisman > > Well ... I can see how one might work one's way > through the expression, using the operator() and operands() > functions. And, I suppose, I can see how one could then build > up the equivalent expression, having modified one of the > operands in a certain way. So, I don't suppose that there is > actually any need for a custom data structure to do this. As far as I understand from your previous comments, a way to extract the exponential functions from the expression is all you need. You don't really need to walk through the tree. Here is one way to do this: sage: t = exp(x+y)*(x-y)*(exp(y)+exp(z-y)) sage: t (e^(-y + z) + e^y)*(x - y)*e^(x + y) sage: w = SR.wild() sage: t.find(exp(w)) [e^(-y + z), e^(x + y), e^y] You can then change the expressions in the given array and substitute new values for them: sage: t.subs({res[1]: sin(res[1].operands()[0])}) (e^(-y + z) + e^y)*(x - y)*sin(x + y) The .operands()[0] syntax is really cumbersome. We need a shortcut for this. I thought .op(0) worked for pynac expressions before we switched from the maxima backend. > Although ... I guess I'm still a bit confused as to why > this happens, even given the form of the exponential. > > sage: f = e^(2*I*pi*n*x - 2*I*pi*n) > sage: latex(f) > e^{\left(\left(2 I\right) \, \pi n x + \left(-2 I\right) \, \pi > n\right)} > > Still, I shouldn't really get +(-2i) right? This is a bug: http://trac.sagemath.org/sage_trac/ticket/9394 I'll fix this when I have time to work on pynac again. Cheers, Burcin -- To post to this group, send email to sage-support@googlegroups.com To unsubscribe from this group, send email to sage-support+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/sage-support URL: http://www.sagemath.org
Re: [sage-support] Dirac Comb
On Sat, 26 Jun 2010 16:01:17 +0200 Tobias Katz wrote: > Hi, > > I got a first result, but it only works when I "type" it in the > command line interface. > > import numpy as np > import pylab as pl > > pl.ion() > pl.grid(True) > > var('t n_ ll ul') > > tt=np.arange(0.01,10,0.01) > > f=sin(t)/t > ts=0.5 > fs=sum(f*dirac_delta(t-(2*n_-1)*ts),n_,0,20)/dirac_delta(0) > > fl=lambda t:f > fl=fl(t) > > fsl=lambda t:fs > fsl=fsl(t) > > fslm=map(fsl,tt) > fsld=np.array(fslm) > fsld=map(n,fsld) > > pl.vlines(tt,[0],fsld) > > flm=map(fl,tt) > fld=np.array(flm) > fld=map(n,fld) > > pl.plot(tt,fld,'--',linewidth=.5) > > > > When I run it like > run -i file.py > I get an error: > > AttributeError: 'int' object has no attribute '_maxima_' > > > How can I cast these integers to numbers or what is my mistake? > Is there a better way to do this? This looks like a bug in the way symbolic sums are handled: http://trac.sagemath.org/sage_trac/ticket/9393 For a workaround, try renaming your file to have the extension .sage instead of .py. BTW, to any developer reading this: A brief search through the tutorial or the FAQ included in Sage didn't reveal anything to link to, is there a canonical point to refer to for these questions? Where is the preparser and differences between Python and Sage documented? Cheers, Burcin -- To post to this group, send email to sage-support@googlegroups.com To unsubscribe from this group, send email to sage-support+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/sage-support URL: http://www.sagemath.org
[sage-support] html.table() still leads to texttt error
Dear all, As reported in http://groups.google.com/group/sage-support/browse_thread/thread/b35dc4f890f48677/32bce5d080ef80d1?lnk=gst&q=texttt#32bce5d080ef80d1, the control sequence \texttt leads to an error in Jsmath. This is supposed to be solved in Sage 4.4, but when I use html.table() to display numpy.array data in Sage 4.4.3, I still see the message "Unknown control sequence '\texttt'" instead of the data. Notebook code to reproduce: {{{id=973| import numpy as np /// }}} {{{id=971| fb_names = ['lambdagf', 'wsgexp', 'lambdafac', 'wsexp', 'pc', 'rootdepth', 'mdstore', 'rgdepth', 'ncp'] fb_values_10 = np.array([ 1.56162258e+03, -7.96780914e-01, 1.47235942e+03, -4.19180237e-01, 2.78293356e-01, 1.65211304e+00, 1.e+02, 1.e+00, 7.24037931e+03]) /// }}} {{{id=974| tabledata = [(fb_names[i], fb_values_10[i]) for i in [0..8]] html.table(tabledata,header=False) }}} For some reason, if I replace in the last command the array "tabledata" by copy and paste of the data contained in tabledata, the \texttt is not preparsed any more and the display is correct. It seems to be an error in the interpretation of the numpy.array data. This worked without problems in sage 4.1. Any ideas how to fix this? Thanks a lot, Stan -- To post to this group, send email to sage-support@googlegroups.com To unsubscribe from this group, send email to sage-support+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/sage-support URL: http://www.sagemath.org