Difference of expressions when evaluated in different orders We all know the standard order of operations for math functions
(PEMDAS),
but what if we instead evaluated expressions left-to-right?

The Challenge

Given a string through standard input or through command line args, find the difference between the traditional evaluation (PEMDAS) and the in-order (left-to-right) evaluation of that expression.

Details


You will be given a string in a format such as:

"1 + 2 * 3 ^ 2 - 11 / 2 + 16"

To simplify things, there will be:


a space between each number and operator
no leading or trailing spaces
no decimal numbers or negative numbers (non-negative integers only)
no operators beyond +(plus), -(minus), *(multiply), /(divide), ^(exponentiation)
no parens to worry about
you may remove the spaces if it's easier for you to handle, but no other modification of the input format will be allowed.

You must provide the absolute value of the difference between the two evaluations of the string
Your division can either be floating-point or integer division - both will be accepted
Your program can not use any sort of expression evaluation library.

To clarify - any sort of built-in eval function in which your language evaluates a string that is valid code for the same language IS acceptable
Explanations of your code are preferred
Shortest code by byte count wins
Winner will be chosen Saturday (July 19, 2014)


Examples:

A: 1 + 2 * 3 ^ 2 - 11 / 2 + 16 (using floating-point division)


In traditional order of operations:

1 + 2 * 3 ^ 2 - 11 / 2 + 16   --&gt;   1 + 2 * 9 - 11 / 2 + 16   --&gt;

1 + 18 - 5.5 + 16             --&gt;   29.5

In-order traversal yields:

1 + 2 * 3 ^ 2 - 11 / 2 + 16   --&gt;   3 * 3 ^ 2 - 11 / 2 + 16   --&gt;

9 ^ 2 - 11 / 2 + 16           --&gt;   81 - 11 / 2 + 16          --&gt;

70 / 2 + 16                   --&gt;   35 + 16                   --&gt;

51

Resulting difference: 51 - 29.5 = 21.5


B: 7 - 1 * 3 ^ 2 + 41 / 3 + 2 * 9 * 2  (using integer division)


In traditional order of operations:

7 - 1 * 3 ^ 2 + 41 / 3 + 2 * 9 * 2   --&gt;   7 - 1 * 9 + 41 / 3 + 2 * 9 * 2   --&gt;

7 - 9 + 13 + 18 * 2                  --&gt;   7 - 9 + 13 + 36                  --&gt;

47

In-order traversal yields:

7 - 1 * 3 ^ 2 + 41 / 3 + 2 * 9 * 2   --&gt;   6 * 3 ^ 2 + 41 / 3 + 2 * 9 * 2   --&gt;

18 ^ 2 + 41 / 3 + 2 * 9 * 2          --&gt;   324 + 41 / 3 + 2 * 9 * 2         --&gt;

365 / 3 + 2 * 9 * 2                  --&gt;   121 + 2 * 9 * 2                  --&gt;

123 * 9 * 2                          --&gt;   1107 * 2                         --&gt;

2214

Resulting difference: 2214 - 47 = 2167
Haskell, 281 256 characters

(x:o:y:z)%p|p o=(show(m o(read x)$read y::Float):z)%p|1&lt;3=x:o:(y:z)%p;z%_=z
m"+"=(+);m"-"=(-);m"*"=(*);m"/"=(/);m"^"=(**);m _= \a-&gt;abs.(a-)
l=(%(\_-&gt;1&lt;3))
t e=foldl(%)e$map(\w-&gt;(`elem`w).head)["^","*/","+-"]
d e=l$l e++"~":t e
main=interact$concat.d.words


Brief explaintaion:


% reduces an expression, so long as the operator meets some predicate p
show(m o(read x)$read y::Float) applies an operator to the two string arguments, producing a string result
m maps a string to an operator; note the string "~" is mapped to absolute difference
l computes left-to-right order by applying % once, with a predicate that is always true
t computes traditional order by repeatedly applying % with tests that match operators first of higher precedence, then lower
d computes the two values, then forms a new expression with operator ~ and computes that


Runs:

&amp; echo "1 + 2 * 3 ^ 2 - 11 / 2 + 16" | runhaskell 34599-EvalOrder.hs 
21.5

&amp; echo "7 - 1 * 3 ^ 2 + 41 / 3 + 2 * 9 * 2" | runhaskell 34599-EvalOrder.hs 
2178.3333


(Second result differs from example above because this code always computes in floating point.)