# How to use SuperLog by loading SMLE.m

I am researching a software reliability model that has many parameters that need to be estimated. I want to use a maximum likelihood estimator (MLE) to estimate those parameters.

After I searched this site for similar problems, I know that SuperLog in SMLE.m package is helpful for MLE. And I find the paper(http://www.tri.org.au/RoseSmithD.pdf), this paper provided code of SMLE.m in Appendix B. I try to copy code from Appendix B and follow instruction in the lower half of page 230, but I still can not get the expected result(See following image).

Can anyone help me? My research is suspended for this point.Thanks in advance.

SMLE.m which I copy from the paper:

(*:Name: SMLE *)
(*:Authors: Colin Rose and Murray D. Smith *)
(*:Version: Mathematica v3, or v4, or later required *)
(*:Legal: Copyright 1999 *)
(*:Summary: Symbolic Maximum Likelihood Estimation *)
BeginPackage["SMLE"]
SuperLog::usage ="SuperLog[On] activates the enhanced Log operator, so that Log[Product[_ _]] objects get converted into sums of logs. SuperLog[Off] switches the enhancement off."
Begin["Private"]
SuperLog[Q_]:=Module[{erk, iii, nnn},
Product[iii,{iii,nnn}]; (* pre-load Product *)
Which[
Q === On,
Unprotect[Log]; Clear[Log];
Log[Product[x_, {k_, a_, b_}]]:=Log[Product[Times[erk, x], {k, a, b}]]/.erk ->1;
Log[Product[HoldPattern[Times[x__]], {k_, a_, b_}]]:=Simplify[Map[Sum[#, {k, a, b}]&, Plus@@Map[Expand[PowerExpand[Log[#]]]&,List[x]]]//.Sum[u_. w_, {kk_, aa_, bb_}] :>u  Sum[w,{kk, aa, bb}] /; FreeQ[u, kk]==True];
Protect[Log]; Print["SuperLog is now On."],
Q === Off,
Unprotect[Log]; Clear[Log]; Protect[Log]; Print["SuperLog is now Off."],
True,
Print["Carumbah! Please use SuperLog[On] or SuperLog[Off]."]
]]
End[]
Protect[ SuperLog ];


Link of SMLE.m : https://www.dropbox.com/s/e8w8yc15z8t3rw1/SMLE.m

• Please, provide code in InputForm rather than $\LaTeX{}$ or images. – Sektor Sep 17 '13 at 7:45

The question is: What do you expect when you set n=10? The computation in the paper is done with unknown n and yields a general simplification. You can easily reproduce this when you Clear[n]. Here is the complete code

(*:Name:SMLE*)
(*:Authors:Colin Rose and Murray D.Smith*)
(*:Version:Mathematica v3,or v4,or later required*)
(*:Summary:Symbolic Maximum Likelihood Estimation*)
BeginPackage["SMLE"];
SuperLog::usage = "SuperLog[On] activates the enhanced Log operator, \
so that Log[Product[_ _]] objects get converted into sums of logs. \
SuperLog[Off] switches the enhancement off."
Begin["Private"];
SuperLog[Q_] :=
Module[{erk, iii, nnn}, Product[iii, {iii, nnn}];(*pre-load Product*)
Which[Q === On, Unprotect[Log]; Clear[Log];
Log[Product[x_, {k_, a_, b_}]] :=
Log[Product[Times[erk, x], {k, a, b}]] /. erk -> 1;
Log[Product[HoldPattern[Times[x__]], {k_, a_, b_}]] :=
Simplify[
Map[Sum[#, {k, a, b}] &,
Plus @@ Map[Expand[PowerExpand[Log[#]]] &, List[x]]] //.
Sum[u_. w_, {kk_, aa_, bb_}] :>
u Sum[w, {kk, aa, bb}] /; FreeQ[u, kk] == True];
Protect[Log]; Print["SuperLog is now On."], Q === Off,
Unprotect[Log]; Clear[Log]; Protect[Log];
Print["SuperLog is now Off."], True,
Print["Carumbah! Please use SuperLog[On] or SuperLog[Off]."]]]
End[];
Protect[SuperLog];
EndPackage[];

L = Product[Exp[-\[Theta]]*\[Theta]^y[i]/y[i]!, {i, 1, n}];
SuperLog[On];
Log[L]


This gives the expected result

Use Log directly after loading SMLE and not SMLELog, like this:

Get["SMLE.m"]
m = Product[Exp[-theta] theta^y[i]/Factorial[y[i]], {i, 1, n}]


SuperLog[On]
Logm = Log[m]


If you use the SMLELog, it does not work: (restart KERNEL fresh):

Get["SMLE.m"]
m = Product[Exp[-theta] theta^y[i]/Factorial[y[i]], {i, 1, n}]
SuperLog[On]
logm = SMLELog[m]


The reason is that the package does not actually define a Log function in SMLE context. What it does is modify the system Log function itself (in System context).

Hence, all what you have to do, is simply use Log and not SMLELog, as there is no such function in SMLE context.