Issue with Sum of Floors in Mathematica - wolfram-mathematica

I'm using Mathematica 8. When I try the command
Sum[r^n Floor[n/2], {n, 0, Infinity}]
I get
r^2/((-1 + r)^2 (1 + r))
which is correct, but starting from 1 instead of 0:
Sum[r^n Floor[n/2], {n, 1, Infinity}]
gives
r/((-1 + r)^2 (1 + r))
which is not. What's going on?

This is a bug. Please submit bug report to WRI (email: support#wolfram.com)

Related

Mathematica FullSimplify[Sqrt[5+2 Sqrt[6]]] yields Sqrt[2]+Sqrt[3] but FullSimplify[-Sqrt[5+2 Sqrt[6]]] is not simplified, why?

I was playing with the (beautiful) polynomial x^4 - 10x^2 + 1.
Look what happens:
In[46]:= f[x_] := x^4 - 10x^2 + 1
a = Sqrt[2];
b = Sqrt[3];
Simplify[f[ a + b]]
Simplify[f[ a - b]]
Simplify[f[-a + b]]
Simplify[f[-a - b]]
Out[49]= 0
Out[50]= 0
Out[51]= 0
Out[52]= 0
In[53]:= Solve[f[x] == 0, x]
Out[53]= {{x->-Sqrt[5-2 Sqrt[6]]},{x->Sqrt[5-2 Sqrt[6]]},{x->-Sqrt[5+2 Sqrt[6]]},{x->Sqrt[5+2 Sqrt[6]]}}
In[54]:= Simplify[Solve[f[x] == 0, x]]
Out[54]= {{x->-Sqrt[5-2 Sqrt[6]]},{x->Sqrt[5-2 Sqrt[6]]},{x->-Sqrt[5+2 Sqrt[6]]},{x->Sqrt[5+2 Sqrt[6]]}}
In[55]:= FullSimplify[Solve[f[x] == 0, x]]
Out[55]= {{x->Sqrt[2]-Sqrt[3]},{x->Sqrt[5-2 Sqrt[6]]},{x->-Sqrt[5+2 Sqrt[6]]},{x->Sqrt[2]+Sqrt[3]}}
Sqrt[5-2 Sqrt[6]] is equal to Sqrt[3]-Sqrt[2].
However, Mathematica's FullSimplify does not simplify Sqrt[5-2 Sqrt[6]].
Question: Should I use other more specialized functions to algebraically solve the equation? If so, which one?
Indeed, Solve doesn't simplify all roots to the max:
A FullSimplify postprocessing step simplifies two roots and leaves two others untouched:
Same initially happens with Roots:
Strange enough, now FullSimplify simplifies all roots:
The reason for this is, I assume, that for the default ComplexityFunction some of the solutions written above in nested radicals are in a sense simpler than the others.
BTW FunctionExpand knows how to deal with those radicals:
FullSimplify[ Solve[x^4-10x^2+1==0,x]
,
ComplexityFunction ->
(StringLength[ToString[
InputForm[#1]]] & )]
gives
{{x -> Sqrt[2] - Sqrt[3]}, {x -> -Sqrt[2] + Sqrt[3]}, {x -> -Sqrt[2] -
Sqrt[3]}, {x -> Sqrt[2] + Sqrt[3]}}

How to get mathematica to carry out a Sum when only part of it is defined?

I'm having a sum like this:
Sum[1 + x[i], {i, 1, n}]
Mathematica doesn't simplify it any more. What would I need to do so it translates it into:
n + Sum[x[i],{i,1,n}]
Maybe this?
Distribute[Sum[1 + x[i], {i, 1, n}]]
which returns:
n + Sum[x[i], {i, 1, n}]
AFAIK Sum simply won't give partial answers. But you can always split off the additive part manually, or semi-automatically. Taking your example,
In[1]:= sigma + (x[i] - X)^2 // Expand
Out[1]= sigma + X^2 - 2 X x[i] + x[i]^2
There's nothing we can do with the parts that contain x[i] without knowing anything about x[i], so we just split off the rest:
In[2]:= Plus ## Cases[%, e_ /; FreeQ[e, x[i]]]
Out[2]= sigma + X^2
In[3]:= Sum[%, {i, 1, n}]
Out[3]= n (sigma + X^2)
Unrelated: It is a good idea never to use symbols starting with capital letters to avoid conflicts with builtins. N has a meaning already, and you shouldn't use it as a variable.
A quick and dirty way would be to use Thread, so for example
Thread[Sum[Expand[sigma + (x[i] - X)^2], {i, 1, n}], Plus, 1]
A simpler way would be
Total[Sum[#, {i, 1, n}] & /# {sigma, x[i]}]
If your expression is longer, this should give you the answer without having to manually split the terms
expr = sigma + (x[i] + i)^2 + Cos[Sin[i - x[i]]];
Total[Sum[#, {i, 1, n}] & /# Level[expr, {1}]]
This can also be done in an easy to understand manner with rules:
sumofsumsrule = Sum[a_+b_,{i_,c_,d_}] :> Sum[a,{i,c,d}]+Sum[b,{i,c,d}];
expandsummandrule = Sum[a_,{i_,c_,d_}] :> Sum[Expand[a],{i,c,d}];
MyRules = {sumofsumsrule, expandsummandrule};
Now, if you are messing around, you can use this (here are some examples):
error = Sum[sigma+(x[i]-X)^2,{i,1,n}]
error /. sumofsumsrule
% /. expandsummandrule
error //. MyRules

Using NProbability[] or Probability[] to work out the probability of 3 or more Heads from 4 coin tosses

Is it possible to work out the probability of 3 or more Head from 4 coin tosses using the Probability or NProbability functions.
This is not a question about the trivial answer to this problem, it is more to get an understanding of how to solve this kind of problem with Mathematica using distributions.
So using 4 random variables from Distribution P
I was hoping something like this would do the trick, but it does not work. I get 0.
P = BernoulliDistribution[0.5];
vars = List[Distributed[a,P],Distributed[b,P],Distributed[c,P],Distributed[c,P]];
NProbability[Count[ {a,b,c,d}, 1] >= 3, vars]
Any ideas would be greatly appreciated.
Not an expert using Mma for statistics here, but this seems to work:
l = TransformedDistribution[
x + y + w + z, {x \[Distributed] BernoulliDistribution[0.5],
y \[Distributed] BernoulliDistribution[0.5],
z \[Distributed] BernoulliDistribution[0.5],
w \[Distributed] BernoulliDistribution[0.5]}];
Table[NProbability[x > i, x \[Distributed] l], {i, -1, 4}]
(*
{1, 0.9375, 0.6875, 0.3125, 0.0625, 0.}
*)
In[10]:= Probability[a + b + c + d >= 3, vars]
Out[10]= 0.3125
Coin flipping is easier described with a BinomialDistribution:
In[12]:= Probability[m >= 3, m \[Distributed] BinomialDistribution[4, 0.5]]
Out[12]= 0.3125

"Not well-formed equation" using Mathematica's Solve

First time using stackOverflow. :)
I'm trying to use mathematica to solve some simply polynomial equations (let's say in one variable) with constraints on the variable, e.g |x| < 1.
When I try something like:
Solve[x^2 == 4 && x^2 < 1, x]
I get an error stating that "x > 0 is not a well-formed equation".
The mathematica solve page even suggests this syntax on its second to last example, so I'm quite confused. (If it's relevant, I have version 7.) Any help would be appreciated.
Thanks!
Solve is not supposed to solve inequalities (M7). You can use Reduce to do that:
In[2]:= Reduce[x^2 == 4 && x^2 < 1, x]
Out[2]= False
Here is an example with Solve:
In[4]:= Solve[x^2 == 4 && x^4 == 16, x]
Out[4]= {{x -> -2}, {x -> 2}}
In Mma v 8:
{Solve[x^2 == 4 && x^2 < 1, x],
Solve[x^2 == 4 && (-1 < x < 1), x]}
(*
->{{},{}}
*)

Finding the Fixed Points of an Iterative Map

I need to find fixed points of iterative map x[n] == 1/2 x[n-1]^2 - Mu.
My approach:
Subscript[g, n_ ][Mu_, x_] := Nest[0.5 * x^2 - Mu, x, n]
fixedPoints[n_] := Solve[Subscript[g, n][Mu, x] == x, x]
Plot[
Evaluate[{x,
Table[Subscript[g, 1][Mu, x], {Mu, 0.5, 4, 0.5}]}
], {x, 0, 0.5}, Frame -> True]
I'll change notation slightly (mostly so I myself can understand it). You might want something like this.
y[n_, mu_, x_] := Nest[#^2/2 - mu &, x, n]
fixedPoints[n_] := Solve[y[n, mu, x] == x, x]
The salient feature is that the "function" being nested now really is a function, in correct format.
Example:
fixedPoints[2]
Out[18]= {{x -> -1 - Sqrt[-3 + 2*mu]},
{x -> -1 + Sqrt[-3 + 2*mu]},
{x -> 1 - Sqrt[ 1 + 2*mu]},
{x -> 1 + Sqrt[ 1 + 2*mu]}}
Daniel Lichtblau
First of all, there is an error in your approach. Nest takes a pure function. Also I would use exact input, i.e. 1/2 instead of 0.5 since Solve is a symbolic rather than numeric solver.
Subscript[g, n_Integer][Mu_, x_] := Nest[Function[z, 1/2 z^2 - Mu], x, n]
Then
In[17]:= fixedPoints[1]
Out[17]= {{x -> 1 - Sqrt[1 + 2 Mu]}, {x -> 1 + Sqrt[1 + 2 Mu]}}
A side note:
Look what happens when you start very near to a fixed point (weird :) :
f[z_, Mu_, n_] := Abs[N#Nest[1/2 #^2 - Mu &, z, n] - z]
g[mu_] := f[1 + Sqrt[1 + 2*mu] - mu 10^-8, mu, 10^4]
Plot[g[mu], {mu, 0, 3}, PlotRange -> {0, 7}]
Edit
In fact, it seems you have an autosimilar structure there:

Resources