Message Boards Message Boards


Clearing fractions in an expression where an equality is asserted

Posted 8 years ago
4 Replies
2 Total Likes

Hello It is quite elementary to transform by hand an expression like

$\frac{m}{n}= \frac{p}{q}$ into $ mq - n p = 0 $ where $ m, n, p, q $ can be much longer expressions and $p,q \ne 0$

However with Mathematica I find it far from easy.

expr = m/n == p/q

Code instances such as below I do not like as it tells Mathematica exactly what to do

Numerator[expr[[1]]] Denominator[expr[[2]]] -   Numerator[expr[[2]]] Denominator[expr[[1]]] == 0
 expr /.{ Equal[Times[a_,Power[b_,-1]],Times[c_,Power[d_,-1]]] :> Equal[Plus[Times[-1,a,b],Times[c,d]],0]

This is more promising:

Map[Subtract[#, expr[[2]]] &, expr] // Factor

But to get rid of the denominator in the answer I see no other way than to use a pattern transformation :

% /. Equal[Times[Power[n_,-1],Power[q_,-1],Plus[Times[-1,n_,p_],Times[m_,q_]]],0] :> Equal[Plus[Times[-1,n,p],Times[m,q]],0]

What is the correct way to handle this simplification ?

POSTED BY: wojtek potocki
4 Replies

My approach is usually this:

Numerator @ Together[equation /. Equal -> Subtract] == 0
POSTED BY: Michael Rogers
Posted 8 years ago

Yes quite clever! It took me some time to understand that Together transfers the initial denominators to the new numerator.

POSTED BY: wojtek potocki

You could define your rules this way:

In[226]:= Clear["Global`*"]

In[227]:= expr = m/n == p/q

Out[227]= m/n == p/q

In[228]:= % /. (x_/y_ == w_/z_) -> y z (x/y == w/z)

Out[228]= n q (m/n == p/q)

In[229]:= % /. (x_ (z_ == w_)) -> x z == x w

Out[229]= m q == n p

In[230]:= % /. x_ == y_ -> x - y == 0

Out[230]= -n p + m q == 0
POSTED BY: Kay Herbert
Posted 8 years ago

Thanks Kay

This is OK for the case stritcly limited to m/n == p/q but m,n,p,q may represent much longer expressions. So unless I create four new variables, your solution does not work as in the example below :

expr = (Cos[Pi/4] Power[3 x , (4)^-1])/x^3  == Log[var]/( x y z )

One of the problem is that MMA will evaluate an expression unless held from it and a solution based on pattern matching to change any expression seems to me difficult to generalize.

POSTED BY: wojtek potocki
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
or Discard

Group Abstract Group Abstract