ASKSAGE: Sage Q&A Forum - RSS feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Sat, 31 Aug 2024 21:07:48 +0200find coefficient of generating functions with three variablehttps://ask.sagemath.org/question/79004/find-coefficient-of-generating-functions-with-three-variable/I want to write a sage math code to find the coefficient of $x^{15}d^7r^8$ in the expansion of $$\frac{1}{1-\bigg(
\frac{xd+(xd)^2+(xd)^3}{1+(xd)+(xd)^2+(xd)^3} + \frac{xr+(xr)^2+(xr)^3}{1+xr+(xr)^2+(xr)^3} \bigg)}$$
I use free version of ChatGPT,but it writes always wrong code because it knows SAGE until 2021. Can you help me ?jacopSat, 31 Aug 2024 21:07:48 +0200https://ask.sagemath.org/question/79004/Fastest way to compute the coefficients of this generating function?https://ask.sagemath.org/question/75699/fastest-way-to-compute-the-coefficients-of-this-generating-function/I need the first N coefficients of a certain generating function, with N around 30000. Using the following code, about 2.8 hrs were needed for N=10000, and 20 hrs for N=20000; unfortunately, it looks like N=30000 would require days:
N = 30000
R.<z> = PowerSeriesRing(ZZ, default_prec=N+1)
gf = (1-z)^2 * sum( z^n/(1 - 2*z + z^(n+1))^2 for n in range(N))
coeffs = gf.coefficients()
**Question**: Is there a better (faster!) way to do this in SageMath?
E.g., some alternative to PowerSeriesRing, or some improvement to how I'm using it?
(Aside: The coefficients of this gf are theoretically expected to exhibit a certain phenomenon that doesn't show up until N is around 30000, and I'm just interested in confirming it.)res0001Mon, 29 Jan 2024 21:05:39 +0100https://ask.sagemath.org/question/75699/Finding the coefficient of multivariable generating functionhttps://ask.sagemath.org/question/72418/finding-the-coefficient-of-multivariable-generating-function/I want to find the coefficient of $[a^3b^3c^3]$ in the expansion of $$\bigg[1-\bigg(\frac{a+a^2}{1-(a+a^2)}+\frac{b+b^2}{1-(b+b^2)}+\frac{c+c^2}{1-(c+c^2)}\bigg)\bigg]^{(-1)}$$
I have made research on internet about coefficient of this multivariable generating function, but could not find something valuable. Can you help me to calculate the coefficent using Sagemath ?jacopThu, 10 Aug 2023 16:02:26 +0200https://ask.sagemath.org/question/72418/How to obtain explicit formula of coefficients for generating functionshttps://ask.sagemath.org/question/69227/how-to-obtain-explicit-formula-of-coefficients-for-generating-functions/ Is there any function to obtain an explicit formula of coefficients for generating functions I mean a formula for nth coefficient without specifying any value for nrjdaFri, 16 Jun 2023 21:21:58 +0200https://ask.sagemath.org/question/69227/Expanding a bivariate exponential generating function, part IIhttps://ask.sagemath.org/question/67337/expanding-a-bivariate-exponential-generating-function-part-ii/From FrédéricC's answer to question [66860](https://ask.sagemath.org/question/66860/expanding-a-bivariate-exponential-generating-function/) I learned the following method (needs SageMath >= 9.8):
def egfExpand(egf, size):
y = polygen(QQ, "y")
x = LazyPowerSeriesRing(y.parent(), "x").gen()
return [list(egf(x, y)[n] * factorial(n)) for n in range(size)]
def f(x, y):
return exp(x * y) * exp(x)
#return exp(x * y) * hypergeometric((), (), x)
egfExpand(f, 10)
[[1],
[1, 1],
[1, 2, 1],
[1, 3, 3, 1],
[1, 4, 6, 4, 1],
...]]
But when I work with hypergeometric functions I get the error message:
cannot coerce arguments: no canonical coercion from Lazy Taylor Series Ring in x over Univariate Polynomial Ring in y over Rational Field to Symbolic Ring
The simplest example is when using the second line as definition of f(x, y) (the result should be identical).
What can I do?
Peter LuschnyWed, 05 Apr 2023 11:44:13 +0200https://ask.sagemath.org/question/67337/Expanding a bivariate exponential generating functionhttps://ask.sagemath.org/question/66860/expanding-a-bivariate-exponential-generating-function/Expanding an univariate exponential generating function can be done like this:
def egfExpand1(f, size):
x = var('x')
return taylor(f(x), x, 0, size).power_series(SR).egf_to_ogf().list()
For example egfExpand1(sec, 10) returns [1, 0, 1, 0, 5, 0, 61, 0, 1385, 0, 50521].
But how can I expand a bivariate exponential generating function? Say
def f(x, y): return exp(x * y) * sec(x)
def egfExpand2(f, size):
return ...
The expected output is an integer triangle (i.e. a list of integer lists).
The example would return an unsigned version of A119879, which starts:
1
0, 1
1, 0, 1
0, 3, 0, 1
5, 0, 6, 0, 1
**Edit:**
Frédéric suggested the following solution, slightly rewritten here.
def egfExpand2(f, size):
y = polygen(QQ, "y")
x = LazyPowerSeriesRing(y.parent(), "x").gen()
return [list(f(x, y)[n] * factorial(n)) for n in range(size)]
f = lambda x, y: exp(x * y) * sec(x)
egfExpand2(f, 10)
The univariate case can also be written more elegantly with this method:
def egfExpand1(f, size: int):
x = LazyPowerSeriesRing(QQ, "x").gen()
return [f(x)[n] * factorial(n) for n in range(size)]
egfExpand1(sec, 11)Peter LuschnyThu, 09 Mar 2023 22:38:21 +0100https://ask.sagemath.org/question/66860/How to build a generating serieshttps://ask.sagemath.org/question/56432/how-to-build-a-generating-series/Hello. Forgive me, I'm still a bit new to coding. I want to create a generating q-series for functions I've already defined, which have complex number outputs. These functions are denoted `g(k, n, z)`, where k, n are integers and z in a complex input. I'd like the series `sum([g(k, n, z)*q^n for n in range(1, 100)])` or something along those lines. The error code is:
`---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-35-5dc58c06413b> in <module>
5 return sum([g(k, n, z)*q**n for n in range(Integer(1), Integer(100))])
6
----> 7 G(Integer(2), Integer(1)+i)
<ipython-input-35-5dc58c06413b> in G(k, z)
3 def G(k, z):
4 var('q')
----> 5 return sum([g(k, n, z)*q**n for n in range(Integer(1), Integer(100))])
6
7 G(Integer(2), Integer(1)+i)
<ipython-input-35-5dc58c06413b> in <listcomp>(.0)
3 def G(k, z):
4 var('q')
----> 5 return sum([g(k, n, z)*q**n for n in range(Integer(1), Integer(100))])
6
7 G(Integer(2), Integer(1)+i)
TypeError: unsupported operand type(s) for *: 'NoneType' and 'sage.symbolic.expression.Expression`
I apologize I cannot make the above formatting more clear. Perhaps someone could help me!
Edit: Thank you for editing above error code!FundamentalDomainTue, 30 Mar 2021 17:26:09 +0200https://ask.sagemath.org/question/56432/Set-Intersection Iterationhttps://ask.sagemath.org/question/53246/set-intersection-iteration/Suppose I have two sets with integral elements $A$ = {$a_1, a_2, ... , a_n$} and $B$ = {$b_1, b_2, ... , b_m$}, the cardinalities of which are arbitrarily large, and $a_n > a_{n - 1} > a_{n - 2} > ... > a_1$ and $b_m > b_{m - 1} > b_{m - 2} > ... > b_1$ with $n$ ≠ $m$. Suppose, also, that the intersection of sets $A$ and $B$ is the singleton set {$c$}, and there exists an index $i$ such that $b_{i + 1} > a_n > b_i > b_{i - 1} > ... > b_1$ where $a_n = \sup(A)$.
I want to create a for-loop iteration (or whatever the best approach might be!) that finds the set intersection without generating all the elements of both sets and then determining the set {$c$}. (This is possible because the generating functions I've created yield explicit formulas I can use to calculate specific elements of both sets.)
I wrote some basic code in Sage to calculate elementary set intersection, but for even moderately large cardinalities, the halt time was incredibly long. I'm thinking the following approach might be faster, but I don't know how to write the program using for-/while-loops and if/else constructions (or even if I should do so):
(1) Check if $a_{n - 1}$ ≤ $b_i$. If $a_{n - 1} > b_i$, keep checking conterminous decreasing indices for elements of $A$ (i.e., $a_{n - 2}$, $a_{n - 3}$, etc.) until $a_j$ ≤ $b_i$ for some index $j < n - 1$. If $a_j = b_i$, break and print($a_j$). If not, go to step (2).
(2) When $a_j < b_i$, check conterminous decreasing indices for elements of $B$ (i.e., $b_{i - 1}$, $b_{i - 2}$, etc.) until $a_j$ ≥ $b_k$ for some index $k < i$. If $a_j = b_k$, break and print($b_k$). If not, go to step (3).
(3) Repeat the process in steps (1) and (2) until $a_r = b_s$ for some indices $r$ ≠ $s$; then, break and print($b_s$).
Thanks in advance.u220eTue, 01 Sep 2020 01:38:15 +0200https://ask.sagemath.org/question/53246/How to compute this exponential generating function?https://ask.sagemath.org/question/24713/how-to-compute-this-exponential-generating-function/Yesterday I struggled with the Narayana polynomials which can be computed with Sage (and the help of kcrisman) as
P = lambda n: hypergeometric([-n,-n+1],[2], 1/x).simplify_hypergeometric()
[expand(x^k*P(k)) for k in (0..7)]
Today I want to generate the coefficients of these polynomials by an exponential generating function.
With Maple I have no problems.
egf := 1 + int((sqrt(t)*exp((1+t)*x)*BesselI(1,2*sqrt(t)*x))/x,x);
s := n -> n!*coeff(series(egf,x,n+2),x,n);
seq(print(seq(coeff(s(n),t,j),j=0..n)),n=0..6);
This gives the requested triangle:
1
0, 1
0, 1, 1
0, 1, 3, 1
0, 1, 6, 6, 1
0, 1, 10, 20, 10, 1
0, 1, 15, 50, 50, 15, 1
With Sage I tried:
from sage.symbolic.integration.integral import indefinite_integral
t = var('t')
h = lambda x, t: sqrt(t)*exp((1+t)*x)*bessel_I(1,2*sqrt(t)*x)
egf = 1 + indefinite_integral(h(x,t),x)
taylor(egf, x, 0, 6)
This gives me a TypeError. Perhaps this is the wrong Ansatz.
Any help is appreciated.Peter LuschnyThu, 30 Oct 2014 19:50:23 +0100https://ask.sagemath.org/question/24713/generating serieshttps://ask.sagemath.org/question/7706/generating-series/Hi. I want to create a function which will pick out the coefficients of a generating series. In particular, I have a generating series $\sum_{k=0}^\infty a_kt^k$ defined by an infinite product $\prod_{k=1}^\infty P_k(t)$. How do I just pick out the coefficients a_k?
I'm using Sage 4.5.3 on Mac OS X 10.6.4.
Thanks for the help!!!!!!!!!ben122684Wed, 22 Sep 2010 16:32:42 +0200https://ask.sagemath.org/question/7706/