# Turn single fraction into multiple fraction expression

I would like to find a way to take an algebraic fraction, where there is only a single numerator and denominator, and to turn it into multiple fractions multiplied by each other. I would like to control both the fractions that are formed, and the ordering of the fractions.

As an example, let's say I have two expressions:

F1 = b*c*d*e
F2 = b*f*g*h*i*k


I would like to divide one by the other, and have the result in terms of multiple fractions, with the fractions determined by my own rules. If I simply divide F1 by F2 in Mathematica, I obtain:

In= F1/F2
Out= (c d e)/(f g h i k)


However, what if I wanted to always group c / f together such that I would get:

In=F1/F2
Out= (d e)/(g h i k)(c/f)


I have attempted to do this using Rule. For example,

In= {F1/F2} /. c/f -> (c/f)


but it still puts the c/f in the same fraction:

Out= {(c d e)/(f g h i k)}


Ideally, I would like to see

Out= (d e)/(g h i k)c/f


with the c/f as a separate fraction, at the end. Additionally, I would like to specify where the c/f lies compared to the (d e)/(g h i k).

The motivation for this is that I have a large multiplication table of different expressions, which I will then paste into a LaTex table. I would like it to be ordered, and for certain expressions to be in fractions.

Something like this?

(F1/F2 /. c/f -> Defer[c/f]) /. aa_*bb_Defer -> Defer[aa]*bb

(* Out= c/f (d e)/(g h i k) *)


Reordering will require a different operator e.g NonCommutativeMultiply on the rhs of the second replacement rule, and then some further formatting to make it look like ordinary multiplication.

--- edit ---

Except formatting NonCommutativeMultiply to look like ordinary multiplication seems to get one into a situation where the display is nice but it won't cut-and-paste the way it looks. Instead we can just use more Defer magic.

(F1/F2 /. c/f -> Defer[c/f]) /. aa_*bb_Defer -> Defer[Defer[aa]*bb]

(* Out= (d e)/(g h i k) c/f *)


--- end edit ---

• Could you provide a MWE for how to incorporate NonCommutativeMultiply into this? – Physics314 Jan 20 '18 at 16:55
• The recursive Defer works really well! What if I want to have more than two multiplied fractions? I am finding that I cannot put multiple arguments in to get something like Out[]= ( e)/( h i k) c/f d/g I tried (F1/F2 /. c/f -> Defer[c/f] /. d/g -> Defer[d/g]) /. aa_*bb_Defer -> Defer[Defer[aa]*bb] and various other iterations, but to no avail. – Physics314 Jan 20 '18 at 17:32
• Could you also clarify exactly how Defer is working here? This would be useful for applying this method further. – Physics314 Jan 20 '18 at 22:15
• I don't actually know much regarding the "how", hence my allusion to magic. As best I understand, it is acting like Hold but less visibly in terms of display. – Daniel Lichtblau Jan 20 '18 at 23:36

Try one of the family of Hold functions (it may be HoldForm) - - the nested Defer will allow cut-and-paste whereas the Hold functions usually keep everything intact. Is the list exhaustive? What are your criteria for "certain expressions to be in fractions"? If the criteria is numeric, there are NHold functions...

• HoldForm is certainly closer to what I need. The problem now is that the fractions are nested within the original numerator: In[] =(F1/F2 /. c/f -> Defer[c/f] /. d/g -> Defer[HoldForm[d/g]]) /. aa_*bb_Defer -> HoldForm[Defer[aa]*bb] Out[] = (e(c/f)/hik) (d/g). Ideally, I would like to remove the c/f from the first numerator. Any ideas? – Physics314 Jan 21 '18 at 12:57
• Earlier you mentioned "certain expressions to be in fractions" and "fractions determined by my own rules". What are your criteria for this part of the desired calculation behavior? If your desired table is definable beforehand, and / or we know the criteria for the variables to remain a fraction or not, then we might be able to normalize the numerator without getting multiples within the table. Specifying c/f behavior explicitly is a better way instead of nested Defer and Hold families of functions (if possible). – Rexie Jan 22 '18 at 19:03