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$

closed as off-topic by march, m_goldberg, user9660, MarcoB, dr.blochwave Jan 5 '16 at 10:12

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "This question arises due to a simple mistake such as a trivial syntax error, incorrect capitalization, spelling mistake, or other typographical error and is unlikely to help any future visitors, or else it is easily found in the documentation." – march, m_goldberg, Community, MarcoB, dr.blochwave
If this question can be reworded to fit the rules in the help center, please edit the question.

2
$\begingroup$

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

$\endgroup$

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