From: amannuc1 on
I am doing some manipulations in Mathematica and end up with
constructs such as "1." in the expressions. I want to convert these to
"1" and thereby eliminate them. However, these examples don't seem to
work. This is Mathematica 7 on OS X.

In[40]:=
Replace[1.(y1-1.yr),1.->1]
Out[40]= 1. (y1-1. yr) (* Nothing happens *)

In[39]:=
ReplaceAll[1.(y1-1.yr),1.->1]
Out[39]= y1-1. yr (* Only first one is replaced *)

Any help is appreciated. Thanks.

-Tony

From: Bob Hanlon on

expr = 1. (y1 - 1. yr);

expr /. x_?NumericQ -> Round[x]

y1-yr

expr // Rationalize

y1-yr

expr /. x_ :> Rationalize[x]

y1-yr


Bob Hanlon

---- amannuc1 <Anthony.J.Mannucci(a)jpl.nasa.gov> wrote:

=============
I am doing some manipulations in Mathematica and end up with
constructs such as "1." in the expressions. I want to convert these to
"1" and thereby eliminate them. However, these examples don't seem to
work. This is Mathematica 7 on OS X.

In[40]:=
Replace[1.(y1-1.yr),1.->1]
Out[40]= 1. (y1-1. yr) (* Nothing happens *)

In[39]:=
ReplaceAll[1.(y1-1.yr),1.->1]
Out[39]= y1-1. yr (* Only first one is replaced *)

Any help is appreciated. Thanks.

-Tony


From: Scot T. Martin on
The problem is that "-1." is not "1".

Also, you need to use the level specification.

In: Replace[1. (y1 - 1. yr), {1. -> 1, -1. -> -1}, Infinity]

Out: y1-yr



On Sat, 26 Dec 2009, amannuc1 wrote:

> I am doing some manipulations in Mathematica and end up with
> constructs such as "1." in the expressions. I want to convert these to
> "1" and thereby eliminate them. However, these examples don't seem to
> work. This is Mathematica 7 on OS X.
>
> In[40]:=
> Replace[1.(y1-1.yr),1.->1]
> Out[40]= 1. (y1-1. yr) (* Nothing happens *)
>
> In[39]:=
> ReplaceAll[1.(y1-1.yr),1.->1]
> Out[39]= y1-1. yr (* Only first one is replaced *)
>
> Any help is appreciated. Thanks.
>
> -Tony
>
>

From: David Park on
expr = 1. (y1 - 1. yr);

Look at the FullForm.

expr // FullForm
Times[1.`,Plus[y1,Times[-1.`,yr]]]

There is a 1. And a -1. and you must have a replacement for each of them.

expr /. {1. -> 1, -1. -> -1}
y1 - yr

expr /. a : (1. | -1.) -> Sign[a]
y1 - yr


Another possible construction is:

expr // Rationalize
y1 - yr

I don't know how you arrived at the initial expression, but if possible you
could try to enter only exact expressions (avoiding numbers with decimal
points, called approximate numbers). Enter approximate numbers only when you
are absolutely forced to. Try to keep all equations symbolic, free of
approximate numbers. Also keep them free of units. Then once you have solved
the equations (if you can do that) then substitute data values with
approximate numbers and units.


David Park
djmpark(a)comcast.net
http://home.comcast.net/~djmpark/


From: amannuc1 [mailto:Anthony.J.Mannucci(a)jpl.nasa.gov]

I am doing some manipulations in Mathematica and end up with
constructs such as "1." in the expressions. I want to convert these to
"1" and thereby eliminate them. However, these examples don't seem to
work. This is Mathematica 7 on OS X.

In[40]:=
Replace[1.(y1-1.yr),1.->1]
Out[40]= 1. (y1-1. yr) (* Nothing happens *)

In[39]:=
ReplaceAll[1.(y1-1.yr),1.->1]
Out[39]= y1-1. yr (* Only first one is replaced *)

Any help is appreciated. Thanks.

-Tony



From: DrMajorBob on
1. (y1 - 1. yr) // Rationalize

y1 - yr

Bobby

On Sat, 26 Dec 2009 18:06:43 -0600, amannuc1
<Anthony.J.Mannucci(a)jpl.nasa.gov> wrote:

> I am doing some manipulations in Mathematica and end up with
> constructs such as "1." in the expressions. I want to convert these to
> "1" and thereby eliminate them. However, these examples don't seem to
> work. This is Mathematica 7 on OS X.
>
> In[40]:=
> Replace[1.(y1-1.yr),1.->1]
> Out[40]= 1. (y1-1. yr) (* Nothing happens *)
>
> In[39]:=
> ReplaceAll[1.(y1-1.yr),1.->1]
> Out[39]= y1-1. yr (* Only first one is replaced *)
>
> Any help is appreciated. Thanks.
>
> -Tony
>


--
DrMajorBob(a)yahoo.com