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.Mon, 19 Feb 2024 10:36:59 +0100Is there a command or a way in SageMath to collect more than one common variable in an equation? without specifying those common variable or write them manuallyhttps://ask.sagemath.org/question/76078/is-there-a-command-or-a-way-in-sagemath-to-collect-more-than-one-common-variable-in-an-equation-without-specifying-those-common-variable-or-write-them/Is there a command or a way in SageMath to collect more than one common variable in an equation without specifying those common variable or write them manually, for example I want the following equation
-36*beta*t*exp(-4*beta*t) +14*exp(-4*beta*t)-12*beta*t*exp(-6*beta*t) -18*exp(-6*beta*t)+5
to be written like this
(-36*beta*t+14)*exp(-4*beta*t) +(-12*beta*t-18)*exp(-6*beta*t)+5
I do not to specify the common variables since the code I am running is iteration so I do not know the values what will beSun, 18 Feb 2024 23:37:27 +0100https://ask.sagemath.org/question/76078/is-there-a-command-or-a-way-in-sagemath-to-collect-more-than-one-common-variable-in-an-equation-without-specifying-those-common-variable-or-write-them/Answer by Emmanuel Charpentier for <p>Is there a command or a way in SageMath to collect more than one common variable in an equation without specifying those common variable or write them manually, for example I want the following equation</p>
<pre><code>-36*beta*t*exp(-4*beta*t) +14*exp(-4*beta*t)-12*beta*t*exp(-6*beta*t) -18*exp(-6*beta*t)+5
</code></pre>
<p>to be written like this </p>
<pre><code>(-36*beta*t+14)*exp(-4*beta*t) +(-12*beta*t-18)*exp(-6*beta*t)+5
</code></pre>
<p>I do not to specify the common variables since the code I am running is iteration so I do not know the values what will be</p>
https://ask.sagemath.org/question/76078/is-there-a-command-or-a-way-in-sagemath-to-collect-more-than-one-common-variable-in-an-equation-without-specifying-those-common-variable-or-write-them/?answer=76081#post-id-76081**EDIT :** A previous answer (seriously out of scope...) has been edited out.
Nothing direct, as far as I know.
**Of note :** if you have Mathematica (or the (gratis, but not free) [Wolfram Engine](https://www.wolfram.com/engine/)),
sage: foo._mathematica_().FullSimplify().sage()
-2*(18*beta*t - 7)*e^(-4*beta*t) - 6*(2*beta*t + 3)*e^(-6*beta*t) + 5
does what you want (and some more, such as factoring coefficients).
HTH,Mon, 19 Feb 2024 10:36:59 +0100https://ask.sagemath.org/question/76078/is-there-a-command-or-a-way-in-sagemath-to-collect-more-than-one-common-variable-in-an-equation-without-specifying-those-common-variable-or-write-them/?answer=76081#post-id-76081