MathGroup Archive 2010

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

Search the Archive

Re: Pi day

  • To: mathgroup at smc.vnet.net
  • Subject: [mg108344] Re: Pi day
  • From: DrMajorBob <btreat1 at austin.rr.com>
  • Date: Sun, 14 Mar 2010 05:15:28 -0500 (EST)

Here's a linear programming code that I think should solve the problem  
(correct me if I'm wrong, someone!), but it fails in a peculiar way.

Here's an example with 3-digit numerator and denominator:

n = 3;
ge0 = {0, 1};
eq1 = {1, 0};
numerator = Sum[j v[i, j] 10^(i - 1), {i, n}, {j, n}];
denominator = Sum[j v[i + n, j] 10^(i - 1), {i, n}, {j, n}];
ratio = numerator/denominator;
variables = Flatten@Array[v, {2 n, n}];
c = Coefficient[Pi denominator - numerator, #] & /@ variables;
bounds = ConstantArray[{0, 1}, 2 n^2];
m1 = SparseArray[{row_, col_} /; row == Quotient[col, n, 1] + 1 ->
     1, {2 n, 2 n^2}];
m2 = SparseArray[{row_, col_} /;
      Mod[row - col, n] == 0 &&
       Quotient[col, n^2, 1] == Quotient[row, n, 1] -> 1, {2 n, 2 n^2}];
m = ArrayFlatten[{{m1}, {m2}}];
b = ConstantArray[{1, 0}, Length@m];

"add a column (the new objective) and two inequalities, to minimize \
absolute error";
variables = Flatten@{objective, variables};
MatrixForm[m = ArrayFlatten@{{1, {c, -c}}, {0, m}}];
c = Flatten@{1, 0 c};
PrependTo[bounds, {-10^10, 10^10}];
b = Join[{{0, 1}, {0, 1}}, b];
Dimensions /@ {c, m, b, bounds}

{{19}, {14, 19}, {14, 2}, {19, 2}}

LinearProgramming[c, m, b, bounds]

(fail... with the errors N::meprec and LinearProgramming:lpsiter1... too  
much extra precision and too many iterations needed)

In the first error message, Mathematica says it's reaching  
$MaxExtraPrecision = 50 while evaluating


1/25 (1 - 100/37 (-(1/25) + 107/(100 \[Pi]))) +
  41/37 (-(1/25) + 107/(100 \[Pi])) - 107/(100 \[Pi])

But that's exactly zero:

1/25 (1 - 100/37 (-(1/25) + 107/(100 \[Pi]))) +
   41/37 (-(1/25) + 107/(100 \[Pi])) - 107/(100 \[Pi]) // Simplify

0

The code before "add a column..." produces an LP that works, either in the  
form

LinearProgramming[c, m, b, bounds]

or

LinearProgramming[-c, m, b, bounds]

Those are the WORST approximations of the desired kind, above and below  
Pi... but LP worked perfectly and gave Integer results.

The later code seems to produce the right matrices.

But LP runs into trouble with computing the Real value of an exact zero.  
What's going on?

Bobby

On Sat, 13 Mar 2010 06:55:23 -0600, Tom <tidetabletom at gmail.com> wrote:

> Hello,  I am a high school math teacher and the following puzzle was
> posed by a few math teachers I am in contact with.
>
> Create a fraction whose numerator has the digits 1 - 9 (used once)
> and whose denominator has the digits 1 - 9  (used one) .
>
> Which fraction has a value closest to the value of pi?
>
> I've worked on some "brute force" checks and managed to check all
> possible fractions with 2,3,4,5 and 6 digits.   But after that, there
> are just too many possibilities.
>
> I don't have the programming ability to implement something elegant in
> Mathematica.
>
> Is there anyone who could suggest an approach to find the solution to
> this?
>
> Sincerely,
>
> Tom
>


-- 
DrMajorBob at yahoo.com


  • Prev by Date: Re: plotting many curves {best times}
  • Next by Date: Re: locally changing Options
  • Previous by thread: Re: Pi day
  • Next by thread: Re: Pi day