MathGroup Archive 2000

[Date Index] [Thread Index] [Author Index]

Search the Archive

RE: Displaying Mixed Numbers

  • To: mathgroup at smc.vnet.net
  • Subject: [mg25148] RE: [mg25124] Displaying Mixed Numbers
  • From: "David Park" <djmp at earthlink.net>
  • Date: Sun, 10 Sep 2000 21:25:42 -0400 (EDT)
  • Sender: owner-wri-mathgroup at wolfram.com

Jim,

By golly, I hope your daughter is actually dipping her toes into
Mathematica!

The trouble with Print is that you can't actually work with the output. Here
is a small system that will actually allow your daughter to do some
arithmetic with mixed fractions.

Mix[x_] := mixform[Quotient[Numerator[x], Denominator[x]],
    Mod[Numerator[x], Denominator[x]]/Denominator[x]]

Format[mixform[x_, y_]] :=
  Which[
    y == 0, x,
    x == 0, y,
    True, SequenceForm[x, y]]

MixEvaluate[x_] := x /. mixform -> Plus

Now let's do some arithmetic. It is a little difficult to duplicate nice
Mathematica formatted output, so I just approximate it.

Mix[5/2] + Mix[7/3]
Mix[MixEvaluate[%]]

2 1/3 + 2 1/2
4 5/6

Mix[5/2] + Mix[7/3] + Mix[5] + Mix[3/4]
Mix[MixEvaluate[%]]

3/4 + 2 1/3 + 2 1/2 + 5
10 7/12

x1 = Mix[2 + 7/8];
x2 = Mix[3/5];
x3 = Mix[7/3];

(x1 + x2)/x3
% // MixEvaluate // Mix

(3/5 + 2 7/8)/(2 1/3)
1 137/280

David Park
djmp at earthlink.net
http://home.earthlink.net/~djmp/

> -----Original Message-----
> From: Jim Graber [mailto:jgraber at my-deja.com]
To: mathgroup at smc.vnet.net
>
> While working with my third grader, I discovered the need
> to make 5/3 display and print as 1 2/3 so she can check her
> homework.
>
> I couldn't find a way to do this easily, so I wrote the following which
> does the job.  Is there an easier or better way?
> Thanks.  Jim Graber
>
> Mix1[x_] := { Quotient[Numerator[x], Denominator[x]],
>     Mod[Numerator[x], Denominator[x]]/Denominator[x]}
>
> Mix[x_] := Print[Mix1[x][[1]], Mix1[x][[2]]];
>
>
> Sent via Deja.com http://www.deja.com/
> Before you buy.
>
>



  • Prev by Date: Re: Re: Security considerations in Mathematica&J/Link
  • Next by Date: RE: Number Combining/Wheeling
  • Previous by thread: Re: Displaying Mixed Numbers
  • Next by thread: Re: Displaying Mixed Numbers