       Re: ForAll testing equality, and Limit evaluating wrong

• To: mathgroup at smc.vnet.net
• Subject: [mg104592] Re: [mg104512] ForAll testing equality, and Limit evaluating wrong
• From: DrMajorBob <btreat1 at austin.rr.com>
• Date: Wed, 4 Nov 2009 01:38:53 -0500 (EST)
• References: <200911030750.CAA00981@smc.vnet.net>

```If you don't want the Limit computed (and done away with) when f is
symbolic, define

Clear[xTransf]
xTransf[f_?NumericQ] :=
Limit[(E^(-24 I \[Pi] r) (-Cos[12 \[Pi] r] + Cos[24 r \[Pi]] +
12 \[Pi] r Sin[24 \[Pi] r]))/(2 \[Pi]^2 r^2), r -> f]

This means, however, that every single time you compute xTransf[aNumber],
the Limit is computed from scratch.

Here's a timing for 201 calculations:

{First@#, Length@Last@#} &@Timing@Table[xTransf@f, {f, 0, 10, .05}]

{7.98758, 201}

Here's a more efficient definition, with timing for the same evaluated
points:

Clear[xTransf]
xTransf[0 | 0.] =
Limit[(E^(-24 I \[Pi] r) (-Cos[12 \[Pi] r] + Cos[24 r \[Pi]] +
12 \[Pi] r Sin[24 \[Pi] r]))/(2 \[Pi]^2 r^2), r -> 0];
xTransf[f_] =
Limit[(E^(-24 I \[Pi] r) (-Cos[12 \[Pi] r] + Cos[24 r \[Pi]] +
12 \[Pi] r Sin[24 \[Pi] r]))/(2 \[Pi]^2 r^2), r -> f];
{First@#, Length@Last@#} &@Timing@Table[xTransf@f, {f, 0, 10, .05}]

{0.003726, 201}

That's a big difference in speed:

7.98758/.003726

2143.74

Bobby

On Tue, 03 Nov 2009 18:01:46 -0600, Rui Rojo <rui.rojo at gmail.com> wrote:

> I see why it happens, but I don't get why Mathematica removes the "Limit"
> from xTransf when it evaluates it at "f"... Or how I can avoid it, so I
> don't get those kinds of mistakes
>
> On Tue, Nov 3, 2009 at 8:33 PM, DrMajorBob <btreat1 at austin.rr.com> wrote:
>
>> r[Pi] occurs because of copy/paste from e-mail to a notebook, when the
>> line
>>
>>
>> xTransf[f]:=Limit[(E^(-24 I r \[Pi]) (-Cos[12 r \[Pi]] + Cos[24 r \
>> [Pi]] +
>>  12 r \[Pi] Sin[24 r \[Pi]]))/(2 r^2 \[Pi]^2), r->f]
>>
>> So that's an e-mail artifact.
>>
>> You defined xTransf this way:
>>
>>
>>
>> Clear[xTransf, xTransf2]
>> xTransf2[f_] := 36 Sinc[6 Pi f]^2;
>> xTransf[f_] :=
>>  Limit[(E^(-24 I \[Pi] r) (-Cos[12 \[Pi] r] + Cos[24 r \[Pi]] +
>>       12 \[Pi] r Sin[24 \[Pi] r]))/(2 \[Pi]^2 r^2), r -> f]
>>
>> and noticed that this evaluates fine:
>>
>> xTransf
>>
>> 36
>>
>> but this does not (error messages omitted):
>>
>> xTransf[f] /. f -> 0
>>
>> Indeterminate
>>
>> It's easy to see why the error occurs, since this is undefined at f=0:
>>
>> xTransf[f]
>>
>>
>> (E^(-24 I f \[Pi]) (-Cos[12 f \[Pi]] + Cos[24 f \[Pi]] +
>>   12 f \[Pi] Sin[24 f \[Pi]]))/(2 f^2 \[Pi]^2)
>>
>> (We can't divide by zero.)
>>
>> But the limit as f->0 exists, so xTransf can be calculated, and 36 is
>> the result.
>>
>> Bobby
>>
>>
>> On Tue, 03 Nov 2009 16:33:07 -0600, Rui Rojo <rui.rojo at gmail.com> wrote:
>>
>>  Yeah, the first xTransf[f] slipped when copying by hand, and the second
>>> thing I don't see it.  The FullSimplify does what I wanted like you
>>> said.
>>> Thanks :)
>>>
>>> Any comments on the Limit issue?
>>> Rui Rojo
>>>
>>> On Tue, Nov 3, 2009 at 6:34 PM, DrMajorBob <btreat1 at austin.rr.com>
>>> wrote:
>>>
>>>  As is, you posted a scramble for two reasons:
>>>>
>>>> underscore).
>>>>
>>>> 2) The right hand side includes r[Pi] in the second Cos argument,
>>>> indicating that r is a function. In that case, what does it mean for
>>>> r to
>>>> approach f in the Limit?
>>>>
>>>> If I rewrite to eliminate those problems, Simplify doesn't get the
>>>> result
>>>> you want, but FullSimplify does:
>>>>
>>>> Clear[xTransf, xTransf2]
>>>> xTransf2[f_] := 36 Sinc[6 Pi f]^2;
>>>> xTransf[f_] =
>>>>  Limit[(E^(-24 I \[Pi] r) (-Cos[12 \[Pi] r] + Cos[24 r \[Pi]] +
>>>>     12 \[Pi] r Sin[24 \[Pi] r]))/(2 \[Pi]^2 r^2), r -> f];
>>>> diff[i_] = xTransf2[i/24] - xTransf[i/24];
>>>> one = Simplify[diff@i, {i > 0, i \[Element] Integers}]
>>>>
>>>> 36 ((8 (-1 + (-1)^i Cos[(i \[Pi])/2]))/(i^2 \[Pi]^2) +
>>>>  Sinc[(i \[Pi])/4]^2)
>>>>
>>>> FullSimplify[diff@i, {i > 0, i \[Element] Integers}]
>>>>
>>>> 0
>>>>
>>>> One way to work that out almost by hand is:
>>>>
>>>> two = Expand[(i^2 Pi^2)/(8*36) one /. Sinc[any_] :> Sin@any/any]
>>>>
>>>> -1 + (-1)^i Cos[(i \[Pi])/2] + 2 Sin[(i \[Pi])/4]^2
>>>>
>>>> (to eliminate Sinc)
>>>>
>>>> doubleAngle = ReplaceAll[#, Cos[x_] :> Cos[x/2]^2 - Sin[x/2]^2] &;
>>>> three = MapAt[doubleAngle, two, 2] // Expand
>>>>
>>>> -1 + (-1)^i Cos[(i \[Pi])/4]^2 +
>>>>  2 Sin[(i \[Pi])/4]^2 - (-1)^i Sin[(i \[Pi])/4]^2
>>>>
>>>> (to have all the Sin and Cos terms squared)
>>>>
>>>> four = three /. Cos[any_]^2 :> 1 - Sin[any]^2 // Expand // Factor
>>>>
>>>> -(-1 + (-1)^i) (-1 + 2 Sin[(i \[Pi])/4]^2)
>>>>
>>>> Separate into factors:
>>>>
>>>> {minus, five, six} = List @@ four
>>>>
>>>> {-1, -1 + (-1)^i, -1 + 2 Sin[(i \[Pi])/4]^2}
>>>>
>>>> "five" is zero when i is even:
>>>>
>>>> Reduce[five == 0]
>>>>
>>>> (-1)^i == 1
>>>>
>>>> "six" is zero when i is odd:
>>>>
>>>> Reduce[six == 0]
>>>>
>>>> Sin[(i \[Pi])/4] == -(1/Sqrt) || Sin[(i \[Pi])/4] == 1/Sqrt
>>>>
>>>> So the product is zero for all i. (NON-ZERO i, that is, since we
>>>> assumed
>>>> Sinc was defined.)
>>>>
>>>> Bobby
>>>>
>>>>
>>>> On Tue, 03 Nov 2009 01:50:55 -0600, Rui <rui.rojo at gmail.com> wrote:
>>>>
>>>>  I want to prove that xTransf2[f]==xTransf[f] for all f multiple of
>>>>
>>>>> 1/24.
>>>>> xTransf2[f_]:=36 Sinc[6 Pi f]^2 and
>>>>> xTransf[f]:=Limit[(E^(-24 I r \[Pi]) (-Cos[12 r \[Pi]] + Cos[24 r \
>>>>> [Pi]] +
>>>>>  12 r \[Pi] Sin[24 r \[Pi]]))/(2 r^2 \[Pi]^2), r->f]
>>>>>
>>>>> If I do
>>>>> ForAll[f \[Element] Integers, YTransf[f/24] == YTransf2[f/24]]
>>>>> I don't get a result... I can't find a way.
>>>>> In fact, I get
>>>>> (144 E^(-I f \[Pi]) (-2 Cos[(f \[Pi])/2] + 2 Cos[f \[Pi]] +
>>>>>   f \[Pi] Sin[f \[Pi]]))/(f^2 \[Pi]^2) == 36 Sinc[(f \[Pi])/4]^2
>>>>>
>>>>> They are clrealy equal, at least on the 48 points closest to 0,
>>>>> because if I do
>>>>> And @@ ((xTransf[1/24 #] == xTransf2[1/24 #]) & /@ Range[-24, 24])
>>>>> I get "True"
>>>>>
>>>>> Any pretty way to be certain?
>>>>>
>>>>> I've also realised that Mathematica has evaluated Limits with
>>>>> variables, making the "Limit" disappear when for some values of the
>>>>> variables I could get an indetermined result with the evaluated
>>>>> version. For example, the Limit in xTransf
>>>>> xTransf[f]
>>>>> I get
>>>>> (E^(-24 I f \[Pi]) (-Cos[12 f \[Pi]] + Cos[24 f \[Pi]] +
>>>>>  12 f \[Pi] Sin[24 f \[Pi]]))/(2 f^2 \[Pi]^2)
>>>>> without the Limit.
>>>>> So, if I do
>>>>> xTransf[f]/.f->0
>>>>> I get errors but if I do xTransf I get 36
>>>>> ...
>>>>> Hope you can help :)
>>>>>
>>>>>
>>>>>
>>>> --
>>>> DrMajorBob at yahoo.com
>>>>
>>>>
>>
>> --
>> DrMajorBob at yahoo.com
>>

--
DrMajorBob at yahoo.com

```

• Prev by Date: Re: ForAll testing equality, and Limit evaluating wrong
• Next by Date: Re: ForAll testing equality, and Limit evaluating wrong
• Previous by thread: Re: ForAll testing equality, and Limit evaluating wrong
• Next by thread: Re: ForAll testing equality, and Limit evaluating wrong