[Date Index]
[Thread Index]
[Author Index]
Re: gives wrong result
*To*: mathgroup at smc.vnet.net
*Subject*: [mg125896] Re: gives wrong result
*From*: Bob Hanlon <hanlonr357 at gmail.com>
*Date*: Fri, 6 Apr 2012 05:55:59 -0400 (EDT)
*Delivered-to*: l-mathgroup@mail-archive0.wolfram.com
While Replace only applies to a full expression the question then
becomes which expression. Simplify checks the transformation with all
of the parts of the original expression (i.e., changing the expression
under consideration in the Replace) to see if the overall result is
simpler. Without the default there is no matching subexpression
considered by Simplify.
Bob Hanlon
On Thu, Apr 5, 2012 at 8:21 AM, Yi Wang <tririverwangyi at gmail.com> wrote:
> Dear Bob,
>
> Thanks a lot for your reply! Your suggestion indeed works but I am
> still curious about it:
>
> Because I used Replace instead of ReplaceAll by purpose. This is to
> mean, in the rule I want Mathematica to match the entire expression
> instead of part of it. For example, if I am not using Simplify, but
> instead use the rule directly:
>
> Replace[aa PDD[z, d], aa_. PDD[bb_, cc_] :> -bb PDD[aa, cc]]
>
> I get the (correct) non-zero result. Thus there is still something I
> don't understand in Simplify[].
>
> Thanks again,
> Yi
>
> PS: I am new to this discussion group. Thus I am not sure if directly
> reply to your personal email and cc to the group is appropriate. If
> not, sorry, and let me know so that I will stop doing it to you and
> others.
>
> On Thu, Apr 5, 2012 at 7:38 AM, Bob Hanlon <hanlonr357 at gmail.com> wrote:
>> ClearAll[PDD, try, t, z, aa];
>>
>> PDD[a_?NumericQ, idx_] := 0;
>>
>> t = aa PDD[z, d];
>>
>> try[expr_] := Replace[expr, aa_. PDD[bb_, cc_] :> -bb PDD[aa, cc]];
>>
>> Simplify[t, TransformationFunctions :> {try}]
>>
>> 0
>>
>> The default value for aa in aa_. PDD[bb_, cc_] is one. Consequently,
>> PDD[z, d] by itself matches the LHS of the rule and becomes -z PDD[1,
>> d] which evaluates to zero. Note the behavior if the default is
>> removed:
>>
>> try[expr_] := Replace[expr, aa_ PDD[bb_, cc_] :> -bb PDD[aa, cc]];
>>
>> Simplify[t, TransformationFunctions :> {try}]
>>
>> aa PDD[z, d]
>>
>>
>> Bob Hanlon
>>
>>
>> On Thu, Apr 5, 2012 at 5:52 AM, Yi Wang <tririverwangyi at gmail.com> wrote:
>>> Hi, all,
>>>
>>> I met a problem when using the TransformationFunctions option in Simplify:
>>>
>>> ClearAll[PDD,try,t,z,aa];
>>> PDD[a_?NumericQ, idx_] := 0;
>>> t = aa PDD[z, d];
>>> try[expr_] := Replace[expr, aa_. PDD[bb_, cc_] :> -bb PDD[aa, cc]];
>>> Simplify[t, TransformationFunctions :> {try}]
>>>
>>> I expect Simplify to do nothing, because the replace rule in try[] does not make the function simpler in this special case. However, Simplify[...] returns 0.
>>>
>>> If I delete the line " PDD[a_?NumericQ, idx_] := 0; ", Simplify will give the correct result. However, z (or N[z]) is not a number thus it seems the above line shouldn't matter.
>>>
>>> I also tried several other tests. I found a_?NumberQ, a_?IntegerQ both have the above problem, while a_ListQ has the desired behaviour.
>>>
--
Bob Hanlon
Prev by Date:
**Re: Bug in pattern test, or I did something wrong?**
Next by Date:
**Re: How to generate ``nice'' algebra output from command-line mathematica?**
Previous by thread:
**Re: gives wrong result**
Next by thread:
**netCDF 4?**
| |