MathGroup Archive 1996

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

Search the Archive

Re: Transformation rule exercise

  • To: mathgroup at smc.vnet.net
  • Subject: [mg4968] Re: [mg4898] Transformation rule exercise
  • From: fransm at win.tue.nl (Frans Martens)
  • Date: Thu, 17 Oct 1996 00:40:50 -0400
  • Sender: owner-wri-mathgroup at wolfram.com

Robert Hall wrote

Dear Abbey,

This has baffled me for two days now. It's exercise 4 from p. 113 of
Introduction to Programming with Mathematica, by Gaylord, Kamin &  
Wellin.
The problem is to rewrite
so that 


returns 

The authors provide the following information:
"Hint: You need to maintain the lhs of the transformation rule
unevaluated for purposes of pattern-matching and the rhs of the rule
unevaluated until the rule is used."

Unfortunately, both my solutions violate both clauses of the hint.
   g1[x_] := x /. Plus -> Times
   g2[x_] := x /. Plus[y___, z___] -> Times[y, z]
I could replace Rule with RuleDelayed in either
function (replace -> with :>) but it isn't necessary. The authors 

state that the lhs is evaluated before the rule is applied, and 

Trace[] bears this out. I'm looking for a solution to which the
authors' hint applies, but for the life of me I can't find it.
Am I overlooking something obvious? 


Baffled near Baltimore

-- 

Bob Hall            | "Know thyself? Absurd direction!
rhall2 at gl.umbc.edu  |  Bubbles bear no introspection."  -Khushhal  
Khan Khatak

A solution is

  g[x_] := (x /. Literal[Plus[z___]] :> Times[z])


Frans Martens
Eindhoven University of Technology
The Netherlands


  • Prev by Date: Re: Reading Binary Files
  • Next by Date: Re: Subsets
  • Previous by thread: Re: Transformation rule exercise
  • Next by thread: list splitting