Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.soft-sys.math.mathematica > #6515 > unrolled thread

Pattern replacement

Started by"Dr. Wolfgang Hintze" <weh@snafu.de>
First post2011-11-18 12:51 +0000
Last post2011-11-18 12:51 +0000
Articles 1 — 1 participant

Back to article view | Back to comp.soft-sys.math.mathematica


Contents

  Pattern replacement "Dr. Wolfgang Hintze" <weh@snafu.de> - 2011-11-18 12:51 +0000

#6515 — Pattern replacement

From"Dr. Wolfgang Hintze" <weh@snafu.de>
Date2011-11-18 12:51 +0000
SubjectPattern replacement
Message-ID<ja5kdf$7pr$1@smc.vnet.net>
My questions are rather elementary.

I wish to replace expressions of the form

-1/2+u by 2u-1
-1/3+u by 3u-1

and so on.

Trying the replacement

(1)    (-1/2+u)/.(-1/q_ + u) -> (q x-1)

does not work, i.e. leaves the original expression unchanged.

Using FullForm[] to reveal the structure gives

(2)    FullForm[Rational[-1, 2] + u]

Now the replacement in explicit form works:

(3)    (-1/2+u)/.(Rational[-1, 2] + u) -> (q u -1)
        Out: -1+q*u

But this is not a nice way to write it.

My questions are

1) Are there better ways to implement the replacement?
2) How do I "undo" FullForm[], i.e. which command produces -1/2+u from 
Rational[-1,2] + u ?
   (I can do it by ToExpression["Rational[-1,2] + u"] but maybe there 
is another way avoiding going to strings).

Thanks in advance
Wolfgang




[toc] | [standalone]


Back to top | Article view | comp.soft-sys.math.mathematica


csiph-web