ASKSAGE: Sage Q&A Forum - Latest question feedhttp://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Fri, 27 Sep 2019 14:34:51 -0500Conjugate multiplication of square roothttp://ask.sagemath.org/question/48086/conjugate-multiplication-of-square-root/ Is there a simple way to simplify a formula using conjugate multiplication of the square roots? For example, when I perform
var('a,b,d')
exp = 1/(a+b*sqrt(d))
exp.full_simplify()
I would like to get
(b*sqrt(d) - a)/(b^2*d - a^2)
but what I actually get is just the form that I started with. Even if I specify the assumptions
assume(d,'real')
assume(d>0)
the conjugate multiplication does not happen automatically. I would like to be able to tell Sage, that I want the conjugate multiplication. In some cases that are relevant to me, the conjugate multiplication would simplify my expressions significantly.TommiFri, 27 Sep 2019 14:34:51 -0500http://ask.sagemath.org/question/48086/Pretty print factorizations as fractionshttp://ask.sagemath.org/question/46864/pretty-print-factorizations-as-fractions/Hi all,
If I have an object whose factorization makes sense when expressed as a fraction, how do I get Sage to pretty print its factorization as a fraction instead of a product of factors? For example,
sage: R.<x> = PolynomialRing(QQ)
sage: f = (x - 1)^2 / (x + 1)
sage: f
(x^2 - 2*x + 1)/(x + 1)
sage: f.factor()
(x + 1)^-1 * (x - 1)^2
but ideally I would like some way to pretty print `f` as `(x - 1)^2/(x + 1)`.
Thanks,
Henryliu.henry.hlSat, 08 Jun 2019 09:31:28 -0500http://ask.sagemath.org/question/46864/Numerical approximation of coefficients in fractionshttp://ask.sagemath.org/question/43158/numerical-approximation-of-coefficients-in-fractions/I am aware that for expressions in the type
$$eq = c_0 + c_1x + c_2x^2...$$
the coefficients of x can be expressed as decimals by doing
eq.polinomial(RR)
however, I noticed that if it is in the form
$$eq = \dfrac{c_0 + c_1x}{c_2 + c_3x}$$
or in any form where it is impossible to express as $c_0 + c_1x^n$ where n is some power of x, the eq.polinomial(RR) only returns an error giving TypeError: fraction must have unit denominator.
How can I approximate $eq = \dfrac{c_0 + c_1x}{c_2 + c_3x}$ where $c_0, c_1, c_2, c_3$ becomes some decimals?
I am aware that $\dfrac{c_0 + c_1x}{c_2 + c_3x}$ is not a polynomial however I do not know what it is.IsamuWed, 25 Jul 2018 20:49:12 -0500http://ask.sagemath.org/question/43158/Can this fraction be simplified ?http://ask.sagemath.org/question/42157/can-this-fraction-be-simplified/During some calculations, I came across a fraction of this kind :
$$\frac{\sqrt{2}+2}{\sqrt{2}+1}$$
Which should be equal to $\sqrt{2}$.
I am surprised to see that Sage can't simplify this fraction with simplify_full :
( (sqrt(2)+2)/(sqrt(2)+1) ).simplify_full()
returns the same. Just to be sure:
bool( (sqrt(2)+2)/(sqrt(2)+1) == sqrt(2) )
returns true
Am I missing a simplification option ? How can I get Sage to simplify this fraction ?
To clarify, the original expression I encountered was this one :
$$\frac{3(x^4+4\sqrt{3}(x^2+6)\sqrt{x^2+3}+24x^2+72)}{\sqrt{3}(x^5+24x^3+72x)+12(x^3+6x)\sqrt{x^2+3}}$$
which is equal to $\frac{\sqrt{3}}{x}$. Sage can show the equality, but cannot simplify the expression (but maybe it's normal, this is not as trivial as the first example...). Substituting $x=1$ in this formula give something very similar to the expression above.
It can be obtained with:
f = 3*(x^4+4*sqrt(3)*(x^2+6)*sqrt(x^2+3)+24*x^2+72)/(sqrt(3)*(x^5+24*x^3+72*x)+12*(x^3+6*x)*sqrt(x^2+3))Florentin JaffredoWed, 25 Apr 2018 05:08:26 -0500http://ask.sagemath.org/question/42157/Run LCM fractionshttp://ask.sagemath.org/question/31915/run-lcm-fractions/ I am doing some matrix multiplications, and as result I get
![image description](http://i.imgur.com/DdUz2Ec.jpg)
Now see position 1,1 of the matrix: I want SageMath to return me a result that has only one fraction (using LCM), not two fractions. Which command should I use?CaterpillarWed, 30 Dec 2015 09:12:07 -0600http://ask.sagemath.org/question/31915/Why is_prime(6/3) results as False?http://ask.sagemath.org/question/26051/why-is_prime63-results-as-false/
sage: (6/3).is_integer()
True
sage: (6/3).is_prime()
FalselogomathFri, 06 Mar 2015 12:46:49 -0600http://ask.sagemath.org/question/26051/how to run fraction elenment in Multivariate Polynomial Ring in over Finite Field ringhttp://ask.sagemath.org/question/10825/how-to-run-fraction-elenment-in-multivariate-polynomial-ring-in-over-finite-field-ring/how to run fraction elenment in Multivariate Polynomial Ring in over Finite Field ring
k.<a> = GF(27);k;k.list();(k.prime_subfield()).list()
k(a+1);k(3/4);k(3/56);k(3);k(5/8);k(5*a);k(a*8);k(5*a)/k(a*8);k(5*a)/k(a*8)==k(5/8)==k(50*a)/k(a*80);k(302*a)/k(a*301)==k(20/121)
frac=k.fraction_field();frac;k.is_integrally_closed();k.integral_closure().list()
F=Frac(k['x,y']);F;F(3*x/4);F(7*x/2-3);F(y)/F(y^2+3)
Fraction Field of Multivariate Polynomial Ring in x, y over Finite Field
in a of size 3^3
0
-x
Traceback (click to the left of this block for traceback)
...
NameError: name 'y' is not defined
k.divides(28*a, 3/4);k(28*a)/k(3/4)
True
Traceback (click to the left of this block for traceback)
...
ZeroDivisionError: division by zero in finite field.
cjshWed, 11 Dec 2013 20:34:24 -0600http://ask.sagemath.org/question/10825/Decimal to fraction?http://ask.sagemath.org/question/10540/decimal-to-fraction/I did .1/8, and the output was 0.0125000000. Is there a way to get it to display as 1/80.bxdinSun, 15 Sep 2013 05:29:57 -0500http://ask.sagemath.org/question/10540/Display decimal as a fraction?http://ask.sagemath.org/question/10301/display-decimal-as-a-fraction/The number 1.5 represents 3/2 in decimal form.
In sage I can get 3/2 to display as a decimal: 3/2.n()
I haven't had any luck converting 1.5 to a fraction.bxdinSun, 30 Jun 2013 13:32:27 -0500http://ask.sagemath.org/question/10301/Get a matrix to display answers as decimals/floats, not fraction?http://ask.sagemath.org/question/10294/get-a-matrix-to-display-answers-as-decimalsfloats-not-fraction/I searched and couldn't find a viable solution:
I successfully executed the following:
<pre>
ma = matrix([[25, 5, 1], [49, 7, 1], [81, 9, 1]])
mb = matrix([[1121], [626], [967]])
show(ma)
show(mb)
ms = ma^-1 * mb
show(ms)
</pre>
Unfotunately though, the statement, show(ms), displays the answer/values as fractions, meaning I have to manually enter each of the value 3 separate times, as part of a float function, i.e., float(fraction/number).
How can I force show(ms), to display the values as decimals?
Also I find the matrix more readable/writable if I can enter each row's values by their own line, instead of the same line, as seen on the the, ma= & mb= statements. I remember I could this with ease in MatLab. I'd appreciate knowing how to that as well.
This post also has an unanswered question if anyone is up for the challenge, :P, j/k:
http://ask.sagemath.org/question/2732/display-y-intercept
bxdinSat, 29 Jun 2013 01:07:37 -0500http://ask.sagemath.org/question/10294/latex(-(x-1)/(x+1)) still brokenhttp://ask.sagemath.org/question/7712/latex-x-1x1-still-broken/I can't understand, why this is still broken
because since a few months this problem
is reported.
sage: latex(-(x-1)/(x+1)) ---> $\frac{-x-1}{x+1}$
sage version 4.5amaleaTue, 28 Sep 2010 22:16:58 -0500http://ask.sagemath.org/question/7712/eliminating fractions and roots from equationshttp://ask.sagemath.org/question/9400/eliminating-fractions-and-roots-from-equations/I'm trying to solve the following equations for $a$ and $c$, where all numbers are real, $0\leq a < 1$ and $0 < c$:
[sqrt(abs((b - 1)*(a + 1)/sqrt(c^2 + abs(b - 1)^2) + a)^2 + abs((a +
1)*c/sqrt(c^2 + abs(b - 1)^2))^2) == a + 1, sqrt(abs(-(b + 1)*(a -
1)/sqrt(c^2 + abs(b + 1)^2) + a)^2 + abs(-(a - 1)*c/sqrt(c^2 + abs(b +
1)^2))^2) == -a + 1]
$$\sqrt{\left|\frac{(b-1)\cdot(a+1)}{\sqrt{c^2+|b-1|^2}+a}\right|^2+\left|\frac{(a+1)\cdot c}{\sqrt{c^2+|b-1|^2}}\right|^2}=a+1$$
$$\sqrt{\left|\frac{-(b+1)\cdot(a-1)}{\sqrt{c^2+|b+1|^2}+a}\right|^2 + \left|\frac{-(a-1)\cdot c}{\sqrt{c^2+|b+1|^2}}\right|^2}=-a+1$$
Now solve itself seems to take forever on this without coming up with a result. On the other hand, I as a human have a pretty good idea how I'd solve such beasts: square both sides to get rid of the outer square roots, then multiply both sides with the common denominator, then move the single remaining square root to one side and all the rest to the other side and square again.
I know that these steps *might* introduce additional solutions, which are valid solutions of the modified system but not of the original one. Nevertheless, I'd like to be able to get at them, probably with some indication how good they are.
I wrote a bit of code to massage my equations for me:
def massage(e):
e = e.simplify().simplify_radical().full_simplify()
e = e.power(2).simplify()
e = e.multiply_both_sides(e.lhs().denominator()).simplify()
e = e.subtract_from_both_sides(e.rhs()).simplify()
e = e.subtract_from_both_sides([
term for term in e.lhs().operands() if 'sqrt' in str(term)][0])
e = e.simplify().power(2).simplify()
e = e.subtract_from_both_sides(e.rhs()).expand()
e = e.simplify().simplify_radical().full_simplify()
return(e)
But this sequence is highly specific to the equations at hand. And the part about how to identify which operand contains the nested square root is plain ugly. **So what better methods are there to perform this kind of equation simplification?** Preferrably in a much more automated way.
*Just for your information:* If I modify my equations using the code above, I am able to get 9 solutions. I'm not sure whether I actually trust them, as I would have expected something else, but there might be something wrong with either my expectation or the way I obtained the euqations.MvGMon, 08 Oct 2012 05:43:35 -0500http://ask.sagemath.org/question/9400/divide numerator and denominator by certain valuehttp://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. matthjesSun, 11 Mar 2012 23:55:24 -0500http://ask.sagemath.org/question/8785/partial fraction decomposition function for multivariate rational expressionshttp://ask.sagemath.org/question/8429/partial-fraction-decomposition-function-for-multivariate-rational-expressions/Hi all:
I'd like to extend Sage's partial fraction decomposition function in the QuotientField class to a function that works on quotients of *multivariate* polynomials. To this end, i've found it convenient to store a rational expression $F = P/(Q_1^{e_1} \cdots Q_m^{e_m})$ as a Python list of the form [P,[Q_1,e_1],...,[Q_m,e_m]], where $Q_1,\ldots,Q_m$ are the irreducible factors of $F$'s denominator. Let's call these special kinds of lists 'widgets'. I have several auxiliary functions that manipulate widgets.
Code design questions for you. Should i make a new class for widgets, and if so, where in the Sage tree of modules should i put this class? If not, where do i put the auxiliary functions that manipulate widgets?
Thanks for your attention.
Alex araichevWed, 02 Nov 2011 13:11:23 -0500http://ask.sagemath.org/question/8429/How to Rationalize the Denominator of a Fraction ?http://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
supertatSat, 08 Oct 2011 20:25:35 -0500http://ask.sagemath.org/question/8362/how to get output in a mixed fraction?http://ask.sagemath.org/question/7583/how-to-get-output-in-a-mixed-fraction/regular rational sage style is like
sage:22/10
i want make it look like (thru pprint it will just look like a mixed on papper)
sage:2+2/10
is this possible?umrenSat, 21 Aug 2010 07:27:07 -0500http://ask.sagemath.org/question/7583/