0
$\begingroup$

I've run into this problem countless times, and it is making Mathematica extremely unusable for me. I input an expression into Mathematica, and it tries to simplify the expression. However, in doing so, it takes a considerable amount of time and then gives me an expression that isn't even the same! Here's the example that's currently giving me trouble: https://goo.gl/KutS4n

I can't find a way to define a function without causing Mathematica to "simplify", since Google searching is only giving me ways to simplify expressions.

Here is the expression giving me trouble:

f[n_] = 1 - ((365!)/((365 - n)!))/365^n - 
  1/365^n Sum[ 
    Binomial[365, 
      k]*((365 - k)!)/((365 - k - (n - 2 k))!)*((n!)/((n - 2 k)!))/
      2^k, {k, 1, Floor[n/2]}]

Edit It seems this will be closed, because Nicholas's solution of just using := works so well in this case. But it doesn't address the underlying issue of why the following two lead to different answers. What is causing this? Is the simplification unstable when numbers as large as 365! are used?

With[{n = 8},
 (1 - ((365!)/((365 - n)!))/365^n - 
   1/365^n Sum[
     Binomial[365, 
       k]*((365 - k)!)/((365 - k - (n - 2 k))!)*((n!)/((n - 2 k)!))/
       2^k, {k, 1, Floor[n/2]}])
 ]
(* 71812618834393/172615601860890625 *)

(1 - ((365!)/((365 - n)!))/365^n - 
   1/365^n Sum[
     Binomial[365, 
       k]*((365 - k)!)/((365 - k - (n - 2 k))!)*((n!)/((n - 2 k)!))/
       2^k, {k, 1, Floor[n/2]}]) /. n -> 8

During evaluation of In[80]:= Infinity::indet: Indeterminate expression 0 ComplexInfinity encountered. >>

(* Indeterminate *)
$\endgroup$
2
$\begingroup$

I found the solution, simply use := to make it evaluate the expression only upon calling. This is mentioned here.

| improve this answer | |
$\endgroup$

Not the answer you're looking for? Browse other questions tagged or ask your own question.