6
$\begingroup$

I undarstand that 1+$MachineEpsilon is actually not equal 1. However, it persists to look like it was equal 1.

In[1]:= 1 + $MachineEpsilon

Out[1]= 1.

This is inappropriate in some cases, as in the following example:

Manipulate[
 Row@{TraditionalForm@HoldForm@Defer@ (1/(x - 1)), "\[Equal]", 
  TraditionalForm@(1/(x - 1))}, {x, 1 + $MachineEpsilon, 2, 
 Appearance -> "Labeled"}]

The above input gives this:

Which very much looks like as if we had some division by zero.

How to fix this? How to display this 1+$MachineEpsilon more accurately?

So far, I've tried this:

In[3]:= N[1 + $MachineEpsilon, $MachinePrecision]

Out[3]= 1.

I fail to understand the above output - 1+$MachineEpsilon is supposed to be a machine number, and therefore it should be accurately representable with $MachinePrecision digits of precision, shouldn't it?

$\endgroup$
  • 2
    $\begingroup$ Perhaps SetOptions[$FrontEndSession, PrintPrecision -> 17]? $\endgroup$ – Michael E2 Jan 12 '15 at 0:31
  • $\begingroup$ @MichaelE2 Sadly, no. See: i61.tinypic.com/f5dgrk.jpg The formula result is ridiculously accurate, but 1. persists. $\endgroup$ – gaazkam Jan 12 '15 at 0:36
  • $\begingroup$ @MichaelE2 Oddly enough, outside Manipulate the precision is correct: i57.tinypic.com/krns3.png $\endgroup$ – gaazkam Jan 12 '15 at 0:46
7
$\begingroup$

I think that the input field that is used to display the current value of x has its own formatting rules and altering them seems difficult. It does not follow PrintPrecision (as in SetOptions[$FrontEndSession, PrintPrecision -> 17], which works for output in an output cell).

So a workaround is to specify the Precision of the displayed x, such that the normal formatting rule shows enough digits. SetPrecision[x, 17] would be sufficient.

Manipulate[
 Row@{TraditionalForm@HoldForm@Defer@(1/(x - 1)), "\[Equal]", 
   TraditionalForm@(1/(x - 1))},
 {x, 1 + $MachineEpsilon, 2, 
   Manipulator[
     Dynamic[SetPrecision[x, 17], (x = #) &], {1 + $MachineEpsilon, 2},
      Appearance -> "Labeled"] &}]

See this answer for some further insight into how the Manipulator is formatted.

$\endgroup$
  • $\begingroup$ Many thanks, it works! BTW: SetPrecision[1 + $MachineEpsilon, MachinePrecision + 1] gives 1.0000000000000002, as it should; but SetPrecision[1 + $MachineEpsilon, MachinePrecision] gives 1. Why? 1+$MachineEpsilon is a machine number, so why can't it be displayed with machine precision? And why does N[1 + $MachineEpsilon, 100] still give 1.? $\endgroup$ – gaazkam Jan 12 '15 at 1:54
  • 1
    $\begingroup$ @gaazkam The precision of 1 + $MachineEpsilon is MachinePrecision, so SetPrecision[1 + $MachineEpsilon, MachinePrecision] does nothing. SetPrecision[x, $MachinePrecision] almost works, but not quite, because 1 + $MachineEpsilon is a little bigger than 1. You could get by with $MachinePrecision + 0.1. It's a bit complicated for a comment, but machine numbers are represented with a finite number of bits and the notion of Precision is relative to the size of x. There are discrete jumps in precision when the exponent changes. N[x, 100] won't increase the precision of x. $\endgroup$ – Michael E2 Jan 12 '15 at 2:46
0
$\begingroup$

Without modifying the precision, you can also just modify the display of the number:

1 + $MachineEpsilon // FullForm
(* 1.0000000000000002` *)

1 + $MachineEpsilon // InputForm
(* 1.0000000000000002 *)

So something like this could work for you:

Manipulate[
  Grid[{{TraditionalForm@HoldForm@Defer@x, "\[Equal]", InputForm@x},
        {TraditionalForm@HoldForm@Defer@(1/(x - 1)), "\[Equal]", TraditionalForm@(1/(x - 1))}}],
  {x, 1 + $MachineEpsilon, 2}]
$\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.