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.Sun, 06 Aug 2017 15:19:04 +0200How to assume the sum of some variables is equal to a constant?https://ask.sagemath.org/question/38478/how-to-assume-the-sum-of-some-variables-is-equal-to-a-constant/Suppose I have this expression:
$$\frac{a {\left(t_{1} + t_{2} + t_{3} - 1\right)}}{b} $$
This can be simplified to 0 if we assume $t_1 + t_2 + t_3 = 1$.
How can I accomplish this in Sage? I've tried:
var('t1', 't2', 't3', 'a', 'b')
expr1 = ((t1 + t2 + t3 - 1)*a)/b
expr1.full_simplify()
assume(t1 + t2 + t3 == 1)
expr1.full_simplify()
I expected the second call to`full_simplify()` to return 0 but it returned the same result as the first call, which is $$\frac{a t_{1} + a t_{2} + a t_{3} - a}{b}$$Sat, 05 Aug 2017 08:08:05 +0200https://ask.sagemath.org/question/38478/how-to-assume-the-sum-of-some-variables-is-equal-to-a-constant/Comment by dan_fulea for <p>Suppose I have this expression:</p>
<p>$$\frac{a {\left(t_{1} + t_{2} + t_{3} - 1\right)}}{b} $$</p>
<p>This can be simplified to 0 if we assume $t_1 + t_2 + t_3 = 1$.</p>
<p>How can I accomplish this in Sage? I've tried:</p>
<pre><code>var('t1', 't2', 't3', 'a', 'b')
expr1 = ((t1 + t2 + t3 - 1)*a)/b
expr1.full_simplify()
assume(t1 + t2 + t3 == 1)
expr1.full_simplify()
</code></pre>
<p>I expected the second call to<code>full_simplify()</code> to return 0 but it returned the same result as the first call, which is $$\frac{a t_{1} + a t_{2} + a t_{3} - a}{b}$$</p>
https://ask.sagemath.org/question/38478/how-to-assume-the-sum-of-some-variables-is-equal-to-a-constant/?comment=38480#post-id-38480Note that you can work ( in the sense of algebraic geometry) as follows:
sage: R.<t1,t2,t3,a,b> = PolynomialRing(QQ)
sage: Q = R.quotient( t1+t2+t3-1 ).fraction_field()
sage: expr1 = ((t1 + t2 + t3 - 1)*a)/b
sage: expr1
(t1*a + t2*a + t3*a - a)/b
sage: expr1.parent()
Fraction Field of Multivariate Polynomial Ring in t1, t2, t3, a, b over Rational Field
sage: Q( expr1 )
0
Working in the quotient ring modulo the "assumed relations" will always give the reduced expressions without contorsions.Sat, 05 Aug 2017 12:31:56 +0200https://ask.sagemath.org/question/38478/how-to-assume-the-sum-of-some-variables-is-equal-to-a-constant/?comment=38480#post-id-38480Comment by ensaba for <p>Suppose I have this expression:</p>
<p>$$\frac{a {\left(t_{1} + t_{2} + t_{3} - 1\right)}}{b} $$</p>
<p>This can be simplified to 0 if we assume $t_1 + t_2 + t_3 = 1$.</p>
<p>How can I accomplish this in Sage? I've tried:</p>
<pre><code>var('t1', 't2', 't3', 'a', 'b')
expr1 = ((t1 + t2 + t3 - 1)*a)/b
expr1.full_simplify()
assume(t1 + t2 + t3 == 1)
expr1.full_simplify()
</code></pre>
<p>I expected the second call to<code>full_simplify()</code> to return 0 but it returned the same result as the first call, which is $$\frac{a t_{1} + a t_{2} + a t_{3} - a}{b}$$</p>
https://ask.sagemath.org/question/38478/how-to-assume-the-sum-of-some-variables-is-equal-to-a-constant/?comment=38483#post-id-38483Thanks for the suggestion. Do you have any idea why `assume()` didn't work?Sun, 06 Aug 2017 02:14:37 +0200https://ask.sagemath.org/question/38478/how-to-assume-the-sum-of-some-variables-is-equal-to-a-constant/?comment=38483#post-id-38483Comment by dan_fulea for <p>Suppose I have this expression:</p>
<p>$$\frac{a {\left(t_{1} + t_{2} + t_{3} - 1\right)}}{b} $$</p>
<p>This can be simplified to 0 if we assume $t_1 + t_2 + t_3 = 1$.</p>
<p>How can I accomplish this in Sage? I've tried:</p>
<pre><code>var('t1', 't2', 't3', 'a', 'b')
expr1 = ((t1 + t2 + t3 - 1)*a)/b
expr1.full_simplify()
assume(t1 + t2 + t3 == 1)
expr1.full_simplify()
</code></pre>
<p>I expected the second call to<code>full_simplify()</code> to return 0 but it returned the same result as the first call, which is $$\frac{a t_{1} + a t_{2} + a t_{3} - a}{b}$$</p>
https://ask.sagemath.org/question/38478/how-to-assume-the-sum-of-some-variables-is-equal-to-a-constant/?comment=38485#post-id-38485Asking for `?assume` we see for instance in
EXAMPLES:
Assumptions are typically used to ensure certain relations are
evaluated as true that are not true in general.
that the command is not designed to work with simplifications hand in hand, but rather with special, unstructured conditions that make an integral, a square root, etc. be defined, or to have evaluations of special functions like `sin` and `cos`. To give an unrelated example where we would also "expect more", let us consider...
sage: var('k'); assume( k, 'integer' );
sage: cos( k*pi ) == (-1)^k
cos(pi*k) == (-1)^k
sage: bool( cos( k*pi ) == (-1)^k )
True
We have to **insist** to get the whole information.
In your case just insist to get the information: `bool( expr1 == 0 )` .Sun, 06 Aug 2017 15:19:04 +0200https://ask.sagemath.org/question/38478/how-to-assume-the-sum-of-some-variables-is-equal-to-a-constant/?comment=38485#post-id-38485Answer by ndomes for <p>Suppose I have this expression:</p>
<p>$$\frac{a {\left(t_{1} + t_{2} + t_{3} - 1\right)}}{b} $$</p>
<p>This can be simplified to 0 if we assume $t_1 + t_2 + t_3 = 1$.</p>
<p>How can I accomplish this in Sage? I've tried:</p>
<pre><code>var('t1', 't2', 't3', 'a', 'b')
expr1 = ((t1 + t2 + t3 - 1)*a)/b
expr1.full_simplify()
assume(t1 + t2 + t3 == 1)
expr1.full_simplify()
</code></pre>
<p>I expected the second call to<code>full_simplify()</code> to return 0 but it returned the same result as the first call, which is $$\frac{a t_{1} + a t_{2} + a t_{3} - a}{b}$$</p>
https://ask.sagemath.org/question/38478/how-to-assume-the-sum-of-some-variables-is-equal-to-a-constant/?answer=38479#post-id-38479
var('t1', 't2', 't3', 'a', 'b')
expr1 = ((t1 + t2 + t3 - 1)*a)/b
equ = t1 + t2 + t3 == 1
expr1.subs(solve(equ,t1))Sat, 05 Aug 2017 09:38:02 +0200https://ask.sagemath.org/question/38478/how-to-assume-the-sum-of-some-variables-is-equal-to-a-constant/?answer=38479#post-id-38479Comment by ensaba for <pre><code>var('t1', 't2', 't3', 'a', 'b')
expr1 = ((t1 + t2 + t3 - 1)*a)/b
equ = t1 + t2 + t3 == 1
expr1.subs(solve(equ,t1))
</code></pre>
https://ask.sagemath.org/question/38478/how-to-assume-the-sum-of-some-variables-is-equal-to-a-constant/?comment=38482#post-id-38482Any idea why `assume()` didn't work?Sun, 06 Aug 2017 02:13:58 +0200https://ask.sagemath.org/question/38478/how-to-assume-the-sum-of-some-variables-is-equal-to-a-constant/?comment=38482#post-id-38482