To: email@example.com Subject: Re: [mg4898] Transformation rule exercise Newsgroups: comp.soft-sys.math.mathematica In-Reply-To: <firstname.lastname@example.org> Organization: University of Maryland, Baltimore County Cc: Bcc:
In article <email@example.com> you write: >> Date: Fri, 4 Oct 1996 00:17:36 -0400 >> From: firstname.lastname@example.org (hall robert) >> To: email@example.com >> Subject: [mg4898] Transformation rule exercise >> ... 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 >>... >> I'm looking for a solution to which the >> authors' hint applies... > >I'm not sure what if the following is what you are looking for. > >g[x_] := ReleaseHold[ Hold[ Plus[3,4,5] ] /. Plus->Times]
Specified input is "a + b + c", specified output is "a b c". In:= g[a + b + c] Out= 60
Nope, that's not it.
Rewriting g so that x appears in the lhs; In:= g[x_] := ReleaseHold[Hold[x] /. Plus -> Times] In:= g[a + b + c] Out= a b c
But ReleaseHold and Hold are unnecessary. One of my original solutions was In:= g[x_] := x /. Plus -> Times In:= g[a + b + c] Out= a b c
Thanks to all who emailed responses, but I think we're wasting our time. I think there's a typo in either the problem or the hint. The two don't seem to be related.
-- Bob Hall | "Know thyself? Absurd direction! firstname.lastname@example.org | Bubbles bear no introspection." -Khushhal Khan Khatak