Finite Sum Tool

This tool allows you to enter any finite sum (in summation notation) and get its decimal value.

Instructions: Enter whatever you want to sum; then press the "=" button to calculate the sum.

DynamicModule[{sum,run,expression,n,k0,k1},
Module[{tempsum,progress,progressInt,dialog,errors,warnings},
SetOptions[$FrontEnd,DynamicEvaluationTimeout->600];
sum="";
expression=1/k;
n=1;
k0=1;
k1=1000;
Panel[Grid[{{InputField[Dynamic[k1],Number,FieldSize->5],SpanFromLeft,"",""},{Style["Σ",FontSize->96],SpanFromLeft,InputField[Dynamic[expression],FieldSize->10],

(* if this button is pressed, the sum is calculated *)
Button[Style["=",FontSize->48],

(* first error check *)
errors={};
If[(!IntegerQ[k0]||!IntegerQ[k1]),AppendTo[errors,"  Bounds of summation must be integers"]];
If[ToString[expression]=="Null",
AppendTo[errors,"  You must enter something to sum"]];
If[Quiet[Check[expression/.k->k0,"divideby0",{Power::"infy"}]=="divideby0"],
AppendTo[errors,"  Invalid first term: you are dividing by 0"],
If[!NumericQ[expression/.k->k0]||!NumericQ[expression/.k->k1],
AppendTo[errors,"  Invalid summand -- perhaps you have a variable other than k?"]]];

If[Length[errors]>0,

(* if there are errors, pop up a dialog box and don't
 do anything else *)
CreateDialog[Join[{"Error:"},errors,{DefaultButton[]}],Modal->True],

(* otherwise, sum! *)
run=True;
sum="";
FinishDynamic[]; (* get rid of the old sum in the display *)
n=k0;
tempsum=0;
progress=0;
(* progress increments by this amount each time *)
progressInt=1/(k1-k0+1); 

(* create dialog box with progress meter *)
dialog=CreateDialog[{"Calculating...",ProgressIndicator[Dynamic[Refresh[progress,UpdateInterval->1]]],
Button["Stop Calculation",run=False;sum="";DialogReturn[],Method->"Preemptive"]}];

While[run&&(n≤k1),progress+=progressInt;tempsum+=N[expression/.k->n,50];n++];

NotebookClose[dialog];

If[progress==1,sum=N[tempsum,20];FinishDynamic[],sum=""]],Method->"Queued"],

Style[Dynamic[sum],FontSize->24,FontColor->Hue[2/3]]},{"k =",InputField[Dynamic[k0],Number,FieldSize->2]}},
Alignment->{Center,Center}],ImageSize->{640,Automatic}
]
]
]