MathGroup Archive 2001

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

Search the Archive

Re: How do I eliminate premultipliers of "1." ?

  • To: mathgroup at smc.vnet.net
  • Subject: [mg31189] Re: How do I eliminate premultipliers of "1." ?
  • From: Mirek Gruszkiewicz <gruszkiewicz at ornl.gov>
  • Date: Tue, 16 Oct 2001 01:19:20 -0400 (EDT)
  • Organization: Oak Ridge National Lab, Oak Ridge, TN
  • References: <9q8oeb$co$1@smc.vnet.net> <9qbi0g$2d4$1@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

How about this:

b = 1.;
c = 1.00000000000001;


In[24]:=
c == 1

Out[24]=
True

In[22]:=
b - c == 0

Out[22]=
False

In[21]:=
b - c

Out[21]=
-9.992007221626409`*^-15

In[27]:=
b == c

Out[27]=
True

Not only 1 and 1. will test equal but even 1 and 1.<13 zeros>1 will test equal.

Numbers which give a nonzero difference when subtracted may test Equal !

It is not an outright error, not a  bug, shouldn't even be surprising, since in
this case it works as advertised in the Book. Equal is not the same as , say,
.EQ. in Fortran.  Equal is what WR, Inc. says it is.

SameQ gives exact comparisons,

c === 1., or 1.===1, even 0. === 0

False

Still not the same as .EQ. in Fortran.



Mirek Gruszkiewicz


Alan Mason wrote:

> Hello Brett.
> You can get rid of them by applying a rule.
>
> In[9]:=
> expr = 1.0 a
>
> Out[9]=
> 1. a
>
> In[10]:=
> expr2 = expr /. 1.0 u_:> u
>
> Out[10]=
> a
>
> ..  I agree with you, though.  Mathematica 4.1 even claims that 1.0 == 1 is
> True.
> In[5]:=
> 1.0 \[Equal] 1
>
> Out[5]=
> True
>
> I consider this an outright error. 1.0 means a floating-point approximation
> to 1, whereas 1 is exactly 1
>
> The correct way to treat 1.0/1.0 is somewhat ambiguous.  Does 1.0 stand for
> the same approximation at each appearance?  If so, the ratio should be 1;
> otherwise, it should be 1.0.
>
> Alan
>
> "Brett Patterson" <bap at roe.ac.uk> wrote in message
> news:9q8oeb$co$1 at smc.vnet.net...
> > Consider the following:
> >
> > In[1] := 1 a / 1
> > Out[1] := a
> >
> > In[2] := 1.0 a / 1.0
> > Out[2] := 1. a
> >
> > Now consider these identities:
> >
> > In[3] := (1 / 1) == 1
> > Out[3] := True
> >
> > In[4] := (1.0 / 1.0) == 1.0
> > Out[4] := True
> >
> > In[5] := (1 / 1) == 1.0
> > Out[5] := True
> >
> > In[6] := (1.0 / 1.0) == 1
> > Out[6] := True
> >
> > Given that it is clear mathematically that I want the
> > answer to In[2] to evaluate to just "a", and given that
> > Mathematica is clearly recognizing that 1.0 / 1.0 is the
> > same as 1 / 1, can someone please tell me why Out[2] contains
> > the premultiplier "1." and how to eliminate it in expressions
> > that might contain this superfluous unit multiplier in various places.
> >
> > Thanks!
> >
> > Brett Patterson
> >
> > UK Astronomy Technology Centre
> > The Royal Observatory
> > Blackford Hill
> > Edinburgh EH9 3HJ
> > Scotland
> >



  • Prev by Date: Re: Re: How do I eliminate premultipliers of "1." ?
  • Next by Date: Re: patterns
  • Previous by thread: Re: How do I eliminate premultipliers of "1." ?
  • Next by thread: data files