Is there a command that will take a rational number and rewrite it in a mixed-number-like form? That is, I'd like to apply a command to something like 10/7 and get the result 1 + 3/7 (or 3/7 + 1 would be fine, too). With polynomial division, the Apart[] command does the trick pretty well, but I haven't been able to find anything comparable for numbers.
|
|
||||
|
|
|
Here is a definition for
Some examples:
Compare with Eli's, which produces
|
|||||||||||
|
|
Another solution based on
This approach produces slightly different results than R.M.'s solution :
|
|||
|
Using the function from the notebook here:
Usage:
|
||||
|
|
|
This should work with any real, rationalizing it (so, it becomes an approximate result)... The integer part of a negative number is considered the floor of the number. I'm not sure what's desired in those cases...
Ok, first, we test it
Works as expected, if you expected the integer part to be the floor (which I don't think it's the most natural thing but I'm not sure) We see that the function can also take machine precision numbers
gives the same result. For consistency with built-ins, the retuned cell has the label with
EDIT Added the
returns what's expected... But we lose the label in these cases |
|||||||||
|
|
Here is an attempt to implement both formatting for entire expressions and basic arithmetic. EDIT: fixed according to Artes' solution.
Now:
|
|||||||||||
|


