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.Thu, 17 Jun 2021 22:33:58 +0200How to return only the denominators of a sequence of fractions created by a formulahttps://ask.sagemath.org/question/57604/how-to-return-only-the-denominators-of-a-sequence-of-fractions-created-by-a-formula/With essential help from slelievre, I managed to achieve coding to return the fractional 'density' (if that is the right term) of primes between n^2 and (n+1)^2:
for n in range(1, 51):
a = n^2 + 1
b = (n + 1)^2 + 1
c = 2*n
nprimes = sum(1 for p in prime_range(a, b))
d = f"{nprimes}/{c}"
print(d)
Now I want to extract just the denominators of this sequence so that I can find the LCM of all those denominators and then convert all the fractions to have the same LCM denominator. (I cannot just use 2n to find the LCM because the fractions need to be reduced.) I found the command x.denominator(), but it seems to work for only a single fraction of integers. At least that's what I understand the error message to mean when I try d.denominator() or print(d.denominator()), the error message reading "AttributeError: 'str' object has no attribute 'denominator'".
Any help in showing me how to do this would be greatly appreciated.Jerry CaveneyThu, 17 Jun 2021 22:33:58 +0200https://ask.sagemath.org/question/57604/Get denominator with hold=Truehttps://ask.sagemath.org/question/56811/get-denominator-with-holdtrue/t2=x.mul(1/(x^2-x),hold=True)
t2.denominator()
results in x-1 instead of x*(x-1) or x^2-x. Is there any other way to obtain x^2-x?DammSun, 25 Apr 2021 22:03:53 +0200https://ask.sagemath.org/question/56811/numerator_denominator()https://ask.sagemath.org/question/10615/numerator_denominator/I have a very big rational function and i want to obtain the numerator and denominator.
with .numerator_denominator() it takes forever
with .numerator_denominator(False) not every term is expanded.
with .expand() and .combine() it takes forever and the result is not a single fraction.
I need a single fraction N(x)/D(x) where N and D are polynomials in x, it is not important how big !alessandroWed, 16 Oct 2013 18:58:48 +0200https://ask.sagemath.org/question/10615/divide numerator and denominator by certain valuehttps://ask.sagemath.org/question/8785/divide-numerator-and-denominator-by-certain-value/Hi,
is it somehow possible to divide the numerator and denominator of a fraction by the same value? For example, (a*b + c)/(b*d + a + c) gets (a + c/b)/(d + a/b + c/b) if I divide it by b. matthjesMon, 12 Mar 2012 05:55:24 +0100https://ask.sagemath.org/question/8785/How to Rationalize the Denominator of a Fraction ?https://ask.sagemath.org/question/8362/how-to-rationalize-the-denominator-of-a-fraction/Hi, experts.<br/>
<br/>
Is there any way to rationalize the denomintor of a fraction ?<br/>
<br/>
For example, I tried<br/>
a = 1 / (2 * sqrt(2) + 3)
b = a.simplify_full(); b;
c = a.simplify_factorial(); c;
d = a.simplify_radical(); d;
e = a.simplify_rational(); e;
expecting any of them to return "`3 - 2*sqrt(2)`" or "`-2*sqrt(2) + 3`". <br/>
However, all of the above commands return `1/(2*sqrt(2) + 3)`,<br/>
whose denominator is not rational.<br/>
<br/>
I know<br/>
(1) Sage uses Maxima.<br/>
(2) Standalone version of Maxima can rationalize the denominator by typing "`ratsimp(a), algebraic: true;`".<br/>
(3) Sage accepts "`maxima.ratsimp(a)`", but I don't know how to pass the Maxima option "`algebraic: true;`" to Sage.<br/>
Is there any way to rationalize the denominator with Sage ?<br/>
<br/>
Thanks in advance.<br/>
-Tatsuya
supertatSun, 09 Oct 2011 03:25:35 +0200https://ask.sagemath.org/question/8362/Radical in the denominator?https://ask.sagemath.org/question/7494/radical-in-the-denominator/Is there any way I can get a general complex number to display with the radical in the denominator, rather than having it rationalized? For example (1+i)/sqrt(2).Mike WittSun, 10 Oct 2010 13:00:07 +0200https://ask.sagemath.org/question/7494/