manipulating output of a quadratic expression after factor to a general form
Subject: manipulating output of a quadratic expression after factor to a general form
From: Stavros Macrakis
Date: Fri, 18 Nov 2011 10:44:16 -0500
Inspired by Horatio's query, I have extended my 'divthru' package to handle
his case. To use it, just save it somewhere and do load("...pathname...").
Divthru means "divide through", and changes things of the form a/b to the
form quotient+remainder/b. It turns out that this is often a useful
transformation.
For example, divthru((x+1)/x) => 1+1/x. In that case, it is the same
result as multthru. But in more complicated cases, it may be different:
(%i1) expr: (x^2+1)/(x+1) $
(%i2) multthru(expr);
(%o2) x^2/(x+1)+1/(x+1)
(%i3) divthru(expr);
(%o3) 2/(x+1)+x-1
Or:
(%i44) expr:(x^2+1)/(x^2-1);
(%o44) (x^2+1)/(x^2-1)
(%i45) multthru(expr);
(%o45) x^2/(x^2-1)+1/(x^2-1)
(%i46) divthru(expr);
(%o46) 2/((x-1)*(x+1))+1 <<< factors by default
(%i47) map(ratsimp,%);
(%o47) 2/(x^2-1)+1 <<< expand each term
(%i48) partfrac(expr,x); <<< another useful
transformation
(%o48) -1/(x+1)+1/(x-1)+1
When the numerator and denominator are taken to powers, it performs divthru
of the bases, not the whole expression:
(%i4) divthru( (x^2+1)^3 / (x+1)^3 );
(%o4) (2/(x+1)+x-1)^3
This is different from dividing out the numerator and denominator as is:
(%i9) dd:divide( num: (x^2+1)^3, denom: (x+1)^3);
(%o9) [x^3-3*x^2+9*x-19,36*x^2+48*x+20]
(%i10) dd[1]+dd[2]/ denom;
(%o10) x^3+(36*x^2+48*x+20)/(x+1)^3-3*x^2+9*x-19
If the powers are different, it takes the common part (min of powers):
(%i5) divthru( (x^2+1)^3 / (x+1)^2 );
(%o5) (x^2+1)*(2/(x+1)+x-1)^2
This works even for symbolic powers:
(%i6) divthru( (x^2+1)^3 / (x+1)^a );
(%o6) (x+1)^min(0,3-a)*(x^2+1)^max(0,3-a)*(2/(x+1)+x-1)^min(3,a)
(%i7) divthru( (x^2+1)^(a+1) / (x+1)^a );
(%o7) (x^2+1)*(2/(x+1)+x-1)^a
The form of the result can be controlled by telling Maxima the relative
value of the exponents:
(%i28) expr:(x-1)^(a+b)/x^a;
(%o28) (x-1)^(b+a)/x^a
(%i29) divthru(expr);
(%o29) (1-1/x)^min(a,b+a)*(x-1)^max(0,b)*x^min(0,b)
(%i30) assume(b>0)$
(%i31) divthru(expr);
(%o31) (1-1/x)^a*(x-1)^b
(%i32) forget(b>0)$assume(b<0)$
(%i34) divthru(expr);
(%o34) (1-1/x)^(b+a)*x^b
Please let me know if you encounter any problems with divthru, or have
ideas on how to improve or extend it.
-s
On Wed, Nov 16, 2011 at 21:41, Stavros Macrakis <macrakis at alum.mit.edu>wrote:
> First of all, welcome to the Maxima community!
>
> Re "why this is not easily possible". There are many ways to represent
> expressions. Factor chooses a canonical one, namely a rational function
> (polynomial divided by polynomial). After all, (x+1)/x = x*(1+1/x^2) =
> (1/x)*(x^2+1) = 1 + 1/x etc. An even simpler case: x^3/y^2 = x*(x/y)^2 =
> (x^(3/2)/y)^2 etc. And for that matter, if it didn't choose a canonical
> form, why wouldn't it return e.g. (x+1)*(1+1/x)/x instead of (x+1)^2/x^2
> or (1+1/x)^2?
>
> In fact, for your example, Maxima doesn't even "think
> of" (2*a*x+b)^2/(4*a^2) as a quotient, but as a product of three
> multiplicands: 1/4, a^-2, and (2*a*x+b)^2.
>
> That said, it certainly *is* possible to transform from one form to the
> other by explicit (programmatic) transformations....
>
> -s
>
>
> On Wed, Nov 16, 2011 at 15:49, <horatio at familiedeskranichs.info> wrote:
>
>> I have this worksheet:
>>
>> Maxima 5.24.0 http://maxima.sourceforge.net
>> using Lisp GNU Common Lisp (GCL) GCL 2.6.7 (a.k.a. GCL)
>> Distributed under the GNU Public License. See the file COPYING.
>> Dedicated to the memory of William Schelter.
>> The function bug_report() provides bug reporting information.
>> (%i1) a * x^2 + b * x + c = 0;
>> 2
>> (%o1) a x + b x + c = 0
>> (%i2) % - c;
>> 2
>> (%o2) a x + b x = - c
>> (%i3) % / a;
>> 2
>> a x + b x c
>> (%o3) ---------- = - -
>> a a
>> (%i4) expand(lhs(%)) = rhs(%);
>> 2 b x c
>> (%o4) x + --- = - -
>> a a
>> (%i5) % + b^2/(2*a)^2;
>> 2 2
>> 2 b x b b c
>> (%o5) x + --- + ---- = ---- - -
>> a 2 2 a
>> 4 a 4 a
>> (%i6) factor(lhs(%)) = rhs(%);
>> 2 2
>> (2 a x + b) b c
>> (%o6) ------------ = ---- - -
>> 2 2 a
>> 4 a 4 a
>> (%i7)
>>
>>
>> but I would like to have the last expression as:
>>
>> (%i7) (x + b/(2*a))^2 = rhs(%);
>>
>>
>> 2
>>
>>
>> b 2 b c
>>
>>
>> (%o7) (x + ---) = ---- - -
>>
>>
>> 2 a 2 a
>>
>>
>> 4 a
>>
>>
>> (%i8)
>>
>> So, if anyone knows a simple solution, or why this is not easily
>> possible, please share.
>> Thank you.
>>
>> _______________________________________________
>> Maxima mailing list
>> Maxima at math.utexas.edu
>> http://www.math.utexas.edu/mailman/listinfo/maxima
>>
>>
>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: divthru.mac
Type: application/octet-stream
Size: 2951 bytes
Desc: not available
URL: <http://www.math.utexas.edu/pipermail/maxima/attachments/20111118/4ff8ca20/attachment-0001.obj>