MathGroup Archive 1996

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

Search the Archive

Transformation rule exercise

  • To: mathgroup at smc.vnet.net
  • Subject: [mg4898] Transformation rule exercise
  • From: rhall2 at umbc.edu (hall robert)
  • Date: Fri, 4 Oct 1996 00:17:36 -0400
  • Sender: owner-wri-mathgroup at wolfram.com

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
	g[x_] = x /. Plus[z___] -> Times[z]
so that 
	g[a + b + c] 
returns 
	a b c
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

==== [MESSAGE SEPARATOR] ====


  • Prev by Date: Accuracy in the function N[expr, n]
  • Next by Date: list splitting
  • Previous by thread: Accuracy in the function N[expr, n]
  • Next by thread: Re: Transformation rule exercise