       Re: Re: A harmless and amusing bug

• To: mathgroup at smc.vnet.net
• Subject: [mg76338] Re: [mg76283] Re: A harmless and amusing bug
• From: DrMajorBob <drmajorbob at bigfoot.com>
• Date: Sun, 20 May 2007 02:22:39 -0400 (EDT)
• References: <f2jtne\$cef\$1@smc.vnet.net> <28846535.1179568968945.JavaMail.root@m35>
• Reply-to: drmajorbob at bigfoot.com

```We're not supposed to copy/paste????

That's neither harmless NOR amusing.

Bobby

On Sat, 19 May 2007 03:31:09 -0500, dimitris <dimmechan at yahoo.com> wrote=
:

> I think everything is normal (or quite normal!).
>
> In:=
> y = x /. DSolve[Derivative[x][t] + 2*Derivative[x][t] + x[t] ==
=
> Sin[t], x, t][]
> Out=
> Function[{t}, C/E^t + (t*C)/E^t - Cos[t]/2]
>
> In:=
> z = Function[{t}, C/E^t + (t*C)/E^t - Cos[t]/2] (*pasted
> result*)
> Out=
> Function[{t}, C/E^t + (t*C)/E^t - Cos[t]/2]
>
> In:=
> y === z
> Out=
> False
>
> In:=
> LeafCount /@ {y, z}
> Out=
> {27, 29}
>
> In:=
> FullForm /@ {y, z}
> Out=
> {Function[List[t],Plus[Times[Power[
>     E,Times[-1,
> t]],C],Times[Power[E,Times[-1,t]],t,C],Times[Rational[-1,2],
>       Cos[t]]]],Function[List[t],Plus[Times[Power[E,Times[-1,t]],C[
>           1]],Times[Power[E,Times[-1,t]],t,C],Times[-1,Times[Cos[
>           t],Power[2,-1]]]]]}
>
> The two expressions have different FullForm! So SameQ results in
> False.
>
> What I don't understand however is that neither
>
> FullSimplify[y == z]
>
> nor
>
> FullSimplify[y == z, ComplexityFunction -> LeafCount]
>
> returns True as it should be! Something happens here.
>
> Anyway, what is the reason to use paste?
>
> In:=
> y1 = x /. DSolve[Derivative[x][t] + 2*Derivative[x][t] + x[t] =
==
> Sin[t], x, t][]
> Out=
> Function[{t}, C/E^t + (t*C)/E^t - Cos[t]/2]
>
> In:=
> z1 = %
> Out=
> Function[{t}, C/E^t + (t*C)/E^t - Cos[t]/2]
>
> In:=
> FullSimplify[y1 == z1]
> Out=
> True
>
> In:=
> y1 === z1
> Out=
> True
>
> In:=
> LeafCount /@ {y1, z1}
> Out=
> {27, 27}
>
> Dimitris
>
>
>  /  Fred Simons       :
>> I found this example in a very old notebook of mine and I do not
>> remember if this has already been discussed in this group.
>>
>> The following seems to be a harmless and amusing bug. It happens both=
in
>> Mathematica 5 and in Mathematica 6 under Windows.
>>
>> Execute the following command:
>>
>> y = x /. DSolve[x''[t]+ 2 x'[t]+ x[t]==Sin[t], x, t][]
>>
>> Copy the result, paste it in the following command and execute.
>>
>> z =pasted result
>>
>> Obviously, y equals z. However,
>>
>> SameQ[y,z] --> False
>>
>> So here we have an example of two different Mathematica expressions w=
ith
>> the property that on level 1 all subexpressions are equal:
>>
>> And @@ Table[y[[i]] === z[[i]], {i, 0,2}] --> True
>>
>> It also is an example of two different expressions that convert to th=
e
>> same string:
>>
>> Equal[ToString /@ {y,z}] --> True
>>
>> The expression y has more leaves than can be found at level -1, and
>> anyway less than the number of leaves of the expression z:
>>
>> {LeafCount[#], Length[Level[#, {-1}, Heads->True]]}& /@  {y,z} -->
>> {{27,25},{29,29}}
>>
>> Fred Simons
>> Eindhoven University of Technology
>
>
>

-- =

DrMajorBob at bigfoot.com

```

• Prev by Date: Re: Minimize[] Problem
• Next by Date: Re: Drawing a bounded smooth region with Mathematica
• Previous by thread: Re: Re: A harmless and amusing bug
• Next by thread: Re: Re: Re: Re: Where is the Mathematica