Group Abstract Group Abstract

Message Boards Message Boards

0
|
52 Views
|
7 Replies
|
2 Total Likes
View groups...
Share
Share this post:
GROUPS:

How to divide numerator and denominator by the numerator?

Posted 1 day ago

How to divide numerator and denominator by the numerator?

in = -((8 m^2)/(3 + 10 m^2 + 3 m^4))
Numerator[in]
in /. a_/b_ -> a/Numerator[in]/(b/Numerator[in])

enter image description here

Why is there no change in the result when using the code above?

I aim to derive this expression in fractional form via identical transformation:

-(1/(5/4 + 3/(8 m^2) + (3 m^2)/8))

enter image description here

POSTED BY: Bill Blair
7 Replies
Posted 42 minutes ago

Thank you for the excellent solution, Michael! Your 1/Expand[1/frac] approach is really elegant. I have a follow-up question: I modified your step-by-step method to divide both numerator and denominator by the parameter part of the numerator (excluding the sign and coefficient), and I came up with the following code:

sgn = Simplify[
  Sign[frac], (var = Variables[Numerator@frac][[1]]) \[Element] 
    Reals && var != 0](*wrestle Mma over the sign*)
Sign@(Cases[Numerator[frac] , _?NumericQ, Infinity][[1]])
fac = sgn/((Numerator[
       frac]/((Sign@(Cases[Numerator[frac] , _?NumericQ, 
             Infinity][[1]]))*(Cases[Numerator[frac] , _?NumericQ, 
           Infinity][[1]]))) // 
    Expand)(*construct factor for multiplying*)
newnd = fac*NumeratorDenominator[frac]; (*mult.num.& den.by fac*)
newnd = Expand /@ newnd; (*un-factor the product(s)*)
Divide @@ (newnd // Expand )(*construct new fraction*)

It works, but the code feels quite verbose and the nesting is a bit hard to follow. I was wondering if there's a more concise or optimized way to achieve the same result.

POSTED BY: Bill Blair
Posted 55 minutes ago

Thank you for the detailed explanation! The 1/Expand[1/frac] approach is elegant and exactly what I needed. I wasn't aware that Mathematica would auto-simplify (a b)/(a c) to b/c, which explains why my direct approach failed.

POSTED BY: Updating Name

Try 1/Expand[1/frac].

On more general approaches:

In Mathematica, an expression (a b)/(a c) will auto-simplify to b/c, and there's not much that can be done about common factors that are factored out except to work around it in some way, such as HoldForm, Defer, Inactive or as in the OP, boxes. These are used to keep the division that leads to the auto-simplification from evaluating. Another way is to manipulate a b or a c so that a is not factored out. Common things to try are Expand[a b] and Simplify[a b]. Sometimes there is no way to avoid using the first kind of workaround, such as when the desired output is 1/(1/m).

Here's a step-by-step breakdown of how to multiply the top and bottom of a fraction by the same factor:

frac = -((8 m^2)/(3 + 10 m^2 + 3 m^4));

sgn = Simplify[Sign[frac], m \[Element] Reals && m != 0]; (* wrestle Mma over the sign *)
fac = sgn/Numerator[frac]; (* construct factor for multiplying *)
newnd = fac*NumeratorDenominator[frac]; (* mult. num. & den. by fac *)
newnd = Expand /@ newnd; (* un-factor the product(s) *)
Divide @@ newnd (* construct new fraction *)
(*  -(1/(5/4 + 3/(8 m^2) + (3 m^2)/8))  *)

Here's a quick way that goes along with the default treatment of signs:

1/Expand[Denominator[frac]/Numerator[frac]]
(*  1/(-(5/4) - 3/(8 m^2) - (3 m^2)/8)  *)

Note that Sign[] on an algebraic expression is usually difficult to resolve to a 1 or -1. The following, using an undocumented function, always resolves to 1 or -1 and often agrees with the user's idea of what the leading sign is:

sgn = (-1)^Boole[Internal`SyntacticNegativeQ[frac]]
(*  -1  *)
POSTED BY: Michael Rogers

A couple of ways:

in = -((8 m^2)/(3 + 10 m^2 + 3 m^4));
in /. a_/b_ :>
  -DisplayForm[FractionBox[a/Numerator[in],
     Expand[-b/Numerator[in]]]]
in /. a_/b_ :>
  -Inactive[Divide][a/Numerator[in],
    -Expand[b/Numerator[in]]]
POSTED BY: Gianluca Gorni
Posted 21 hours ago

I aim to derive this expression in fractional form via identical transformation:

-(1/(5/4 + 3/(8 m^2) + (3 m^2)/8))
POSTED BY: Bill Blair

This is one way to do it, but we must strip the formatting away if we need to reuse the result in further calculations:

in = -((8 m^2)/(3 + 10 m^2 + 3 m^4))
Numerator[in]
newForm = 
 in /. a_/b_ -> 
   DisplayForm[FractionBox[a/Numerator[in], (b/Numerator[in])]]
3*newForm
3*newForm /. {FractionBox -> Divide, 
   DisplayForm -> Identity} // Expand
POSTED BY: Gianluca Gorni
Posted 1 day ago

I think it's equivalent to dividing by 1, which Mathematica simplifies:

(n/n)/(d/n) -> 1/(d/n) -> n/d

POSTED BY: David Keith
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard