MathGroup Archive 2006

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

Search the Archive

Re: a simple product, but with "i = 1...n AND i != x"

  • To: mathgroup at smc.vnet.net
  • Subject: [mg70261] Re: a simple product, but with "i = 1...n AND i != x"
  • From: dimmechan at yahoo.com
  • Date: Tue, 10 Oct 2006 06:12:16 -0400 (EDT)

One alternative is to define f as follows:

f[x_, n_] := ReleaseHold[Product[(HoldForm[x - #1] & )[i], {i, 1, n}]
/.
 HoldForm[(a_) - (a_)]*(b___) -> b]

Then for example

f[1, 10]
-362880

f[2,8]
720

Executing Trace[f[1, 3]] will a help you to understand what is going
on.

Below I will try to explain a little the code.

First notice that

aa=Product[(HoldForm[1 - #1] & )[i], {i, 1, 10}]
(1-1) (1-2) (1-3) (1-4) (1-5) (1-6) (1-7) (1-8) (1-9) (1-10)

instead of zero which you would get if you didn't use HoldForm.

Information["#", LongForm -> False]
"# represents the first argument supplied to a pure function. #n
represents the
nth argument."*
Button[More..., ButtonData :> "Slot", Active -> True,
ButtonStyle -> "RefGuideLink"]

Information["HoldForm", LongForm -> False]
"HoldForm[expr] prints as the expression expr, with expr maintained in
an
unevaluated form."*
Button[More..., ButtonData :> "HoldForm", Active -> True,
ButtonStyle -> "RefGuideLink"]

Then let examine the FullForm of aa

FullForm[aa]
Times[HoldForm[Plus[1,Times[-1,1]]],HoldForm[Plus[1,Times[-1,
        2]]],HoldForm[Plus[1,Times[-1,3]]],HoldForm[Plus[1,Times[-1,
        4]]],HoldForm[Plus[1,Times[-1,5]]],HoldForm[Plus[1,Times[-1,
        6]]],HoldForm[Plus[1,Times[-1,7]]],HoldForm[Plus[1,Times[-1,
8]]],HoldForm[Plus[1,Times[-1,9]]],HoldForm[Plus[1,Times[-1,10]]]]

So with a proper pattern matching we can discard (1-1)

bb=aa /. HoldForm[(a_) - (a_)]*(b___) -> b
(1-2) (1-3) (1-4) (1-5) (1-6) (1-7) (1-8) (1-9) (1-10)

Information["___", LongForm -> False]
"___ (three _ characters) or BlankNullSequence[ ] is a pattern object
that can stand for any sequence of zero or more \
Mathematica expressions. ___h or BlankNullSequence[h] can stand for any
sequence of expressions, all of which have head h."*
Button[More..., ButtonData :> "BlankNullSequence", Active -> True,
ButtonStyle -> "RefGuideLink"]

Executing then

ReleaseHold[bb]
-362880

Information["ReleaseHold", LongForm -> False]

"ReleaseHold[expr] removes Hold, HoldForm, HoldPattern and HoldComplete
in expr."*
Button[More..., ButtonData :> "ReleaseHold", Active -> True,
ButtonStyle -> "RefGuideLink"]

Regards
Dimitris


  • Prev by Date: Re: Troubles with Integrate
  • Next by Date: Re: Indefinite integration problem on ArcTanh(f(Cos))
  • Previous by thread: RE: a simple product, but with "i = 1...n AND i != x"
  • Next by thread: Copy input and User Defined Variables