0
$\begingroup$

In pursuit of a function to force unsimplified fractions

forceden[x_,d_]:=Hold[Evaluate[Numerator[x]d/Denominator@x]/d];

There are many related functions (Holdxxx,Evaluate,Unevaluated,Inactivated...), I can't seem to get any combination of them to work. "HoldFirst" doesn't work for cyring out loud. Of course,

DisplayForm@FractionBox[Numerator[x]d/Denominator@x,d]

works just fine for seeing the thing, but I lose the ability to use this object in calculations. Is there an elegant way to tell Mathematica to "chill out" for the fraction part while still doing the numerator multiplication? (without having to resort to throwing away all the symbolic goodness and "evaluability" of the fraction).

$\endgroup$
6
  • 1
    $\begingroup$ "...HoldFirst doesn't work for crying out loud..." - because it's a function attribute, and not a function itself. Do you have an explicit example that you want to see in a held form? $\endgroup$ – J. M.'s torpor Jan 18 at 2:05
  • $\begingroup$ My bad, intended use of HoldFirst would be as an attribute of Quotient. Still no dice; I think Hold is the wrong word. I want 'Numerator[x]d/Denominator@x' to be fully evaluated and simplified as if it were an isolated expression, and no other simplification to occur. forceden[2/3,9] should yield 6/9 $\endgroup$ – Adam Jan 18 at 7:11
  • 1
    $\begingroup$ Would forceden[r_Rational, d_Integer?Positive] := With[{f = Quotient[d, Denominator[r]]}, Internal`RationalNoReduce[f Numerator[r], d]] suit your needs, then? $\endgroup$ – J. M.'s torpor Jan 18 at 7:46
  • $\begingroup$ Yes! Thank you; going to browse more Internal` functions now $\endgroup$ – Adam Jan 18 at 7:55
  • $\begingroup$ Also, we do not do things like add "[SOLVED]" in titles here. If you don't mind waiting, I will write a more elaborate response later. $\endgroup$ – J. M.'s torpor Jan 18 at 8:00
3
$\begingroup$

OK, just to put it on record: there is an undocumented function, Internal`RationalNoReduce[] (see also Chip's answer here) that effectively allows you to represent a fraction not reduced to lowest terms, but can still act as a number:

Internal`RationalNoReduce[3, 6]
   3/6

N[%]
   0.5

Thus, what the OP wants can be done like so:

forceden[r_Rational, d_Integer?Positive] := With[{f = Quotient[d, Denominator[r]]},
         Internal`RationalNoReduce[f Numerator[r], d]]

For instance,

forceden[2/3, 9]
   6/9
$\endgroup$
1
$\begingroup$

" forceden[2/3,9] should yield 6/9 "

forceden[x_, d_] := 
  Numerator[x] d/Denominator[x]/HoldForm[d]

ff = forceden[2/3, 9]
(*   6/9   *)

ff // ReleaseHold
(*   2/3   *)
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.