<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array"/>
  <modified type="array">
    <modified>
      <diff>@@ -2,7 +2,7 @@
 % info go to &lt;URL:http://en.wikipedia.org/wiki/Shunting_yard_algorithm&gt;.
 
 -module(calc).
--export([parse/1, evaluate/1, stringify/1, compile/1, simulate/1, simplify/1]).
+-export([parse/1, evaluate/1, stringify/1, compile/1, simulate/1, optimize/1]).
 
 parse(String) -&gt; parse(tokenize(String), [], []).
 
@@ -83,54 +83,54 @@ simulate([Oper|Instructions], [Stack0|[Stack1|Stack]]) -&gt;
     divide    -&gt; simulate(Instructions, [Stack1 / Stack0|Stack])
   end.
 
-simplify({num, Num})                        -&gt; {num, Num};
-simplify({add, Exp0, {uminus, Exp1}})       -&gt; simplify({subtract, simplify(Exp0), simplify(Exp1)});
-simplify({subtract, Exp0, {uminus, Exp1}})  -&gt; simplify({add, simplify(Exp0), simplify(Exp1)});
-simplify({uminus, Exp}) -&gt;
-  Sexp = simplify(Exp),
-  case Sexp of
+optimize({num, Num})                        -&gt; {num, Num};
+optimize({add, Exp0, {uminus, Exp1}})       -&gt; optimize({subtract, optimize(Exp0), optimize(Exp1)});
+optimize({subtract, Exp0, {uminus, Exp1}})  -&gt; optimize({add, optimize(Exp0), optimize(Exp1)});
+optimize({uminus, Exp}) -&gt;
+  Oexp = optimize(Exp),
+  case Oexp of
     {uminus, NestedExp} -&gt; NestedExp;
-    _                   -&gt; {uminus, Sexp}
+    _                   -&gt; {uminus, Oexp}
   end;
-simplify({add, Exp0, Exp1}) -&gt;
-  Sexp0 = simplify(Exp0),
-  Sexp1 = simplify(Exp1),
+optimize({add, Exp0, Exp1}) -&gt;
+  Oexp0 = optimize(Exp0),
+  Oexp1 = optimize(Exp1),
   if
-    Sexp0 == {num, 0} -&gt; Sexp1;
-    Sexp1 == {num, 0} -&gt; Sexp0;
-    true              -&gt; {add, Sexp0, Sexp1}
+    Oexp0 == {num, 0} -&gt; Oexp1;
+    Oexp1 == {num, 0} -&gt; Oexp0;
+    true              -&gt; {add, Oexp0, Oexp1}
   end;
-simplify({subtract, Exp0, Exp1}) -&gt;
-  Sexp0 = simplify(Exp0),
-  Sexp1 = simplify(Exp1),
+optimize({subtract, Exp0, Exp1}) -&gt;
+  Oexp0 = optimize(Exp0),
+  Oexp1 = optimize(Exp1),
   if
-    Sexp0 == {num, 0} -&gt; {uminus, Sexp1};
-    Sexp1 == {num, 0} -&gt; Sexp0;
-    Sexp0 == Sexp1    -&gt; {num, 0};
-    true              -&gt; {subtract, Sexp0, Sexp1}
+    Oexp0 == {num, 0} -&gt; {uminus, Oexp1};
+    Oexp1 == {num, 0} -&gt; Oexp0;
+    Oexp0 == Oexp1    -&gt; {num, 0};
+    true              -&gt; {subtract, Oexp0, Oexp1}
   end;
-simplify({multiply, Exp0, Exp1}) -&gt;
-  Sexp0 = simplify(Exp0),
-  Sexp1 = simplify(Exp1),
+optimize({multiply, Exp0, Exp1}) -&gt;
+  Oexp0 = optimize(Exp0),
+  Oexp1 = optimize(Exp1),
   if
-    Sexp0 == {num, 0}; Sexp1 == {num, 0}  -&gt; {num, 0};
-    Sexp0 == {num, 1}                     -&gt; Sexp1;
-    Sexp1 == {num, 1}                     -&gt; Sexp0;
-    true                                  -&gt; {multiply, Sexp0, Sexp1}
+    Oexp0 == {num, 0}; Oexp1 == {num, 0}  -&gt; {num, 0};
+    Oexp0 == {num, 1}                     -&gt; Oexp1;
+    Oexp1 == {num, 1}                     -&gt; Oexp0;
+    true                                  -&gt; {multiply, Oexp0, Oexp1}
   end;
-simplify({divide, Exp0, Exp1}) -&gt;
-  Sexp0 = simplify(Exp0),
-  Sexp1 = simplify(Exp1),
+optimize({divide, Exp0, Exp1}) -&gt;
+  Oexp0 = optimize(Exp0),
+  Oexp1 = optimize(Exp1),
   if
-    Sexp0 == Sexp1    -&gt; {num, 1};
-    Sexp0 == {num, 0} -&gt; {num, 0};
-    Sexp1 == {num, 1} -&gt; Sexp0;
-    true              -&gt; {divide, Sexp0, Sexp1}
+    Oexp0 == Oexp1    -&gt; {num, 1};
+    Oexp0 == {num, 0} -&gt; {num, 0};
+    Oexp1 == {num, 1} -&gt; Oexp0;
+    true              -&gt; {divide, Oexp0, Oexp1}
   end;
-simplify({Oper, Exp}) -&gt;
-  {Oper, simplify(Exp)};
-simplify({Oper, Exp0, Exp1}) -&gt;
-  {Oper, simplify(Exp0), simplify(Exp1)}.
+optimize({Oper, Exp}) -&gt;
+  {Oper, optimize(Exp)};
+optimize({Oper, Exp0, Exp1}) -&gt;
+  {Oper, optimize(Exp0), optimize(Exp1)}.
 
 tokenize([]) -&gt; [];
 tokenize([H|T]) -&gt;</diff>
      <filename>chapter3/calc.erl</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>48033a62a21a597720a20dc6aaf53b31dd90f53f</id>
    </parent>
  </parents>
  <author>
    <name>John Parker</name>
    <email>jparker@urgetopunt.com</email>
  </author>
  <url>http://github.com/jparker/erlang_programming/commit/568dd7ac88a465529bd3e9d1760d4ee743b87a33</url>
  <id>568dd7ac88a465529bd3e9d1760d4ee743b87a33</id>
  <committed-date>2009-10-09T06:30:22-07:00</committed-date>
  <authored-date>2009-10-09T06:30:22-07:00</authored-date>
  <message>Renamed function simplify() to optimize()</message>
  <tree>d45f76da94ab65d29fa5bc33609bff404a93111c</tree>
  <committer>
    <name>John Parker</name>
    <email>jparker@urgetopunt.com</email>
  </committer>
</commit>
