Expression, p6

?

Percentage Accurate: 94.3% → 100.0%
Time: 8.8s
Precision: binary64
Cost: 6976

?

\[\left(\left(\left(-14 \leq a \land a \leq -13\right) \land \left(-3 \leq b \land b \leq -2\right)\right) \land \left(3 \leq c \land c \leq 3.5\right)\right) \land \left(12.5 \leq d \land d \leq 13.5\right)\]
\[\left(a + \left(b + \left(c + d\right)\right)\right) \cdot 2 \]
\[\mathsf{fma}\left(1, b + c, d + a\right) \cdot 2 \]
(FPCore (a b c d) :precision binary64 (* (+ a (+ b (+ c d))) 2.0))
(FPCore (a b c d) :precision binary64 (* (fma 1.0 (+ b c) (+ d a)) 2.0))
double code(double a, double b, double c, double d) {
	return (a + (b + (c + d))) * 2.0;
}
double code(double a, double b, double c, double d) {
	return fma(1.0, (b + c), (d + a)) * 2.0;
}
function code(a, b, c, d)
	return Float64(Float64(a + Float64(b + Float64(c + d))) * 2.0)
end
function code(a, b, c, d)
	return Float64(fma(1.0, Float64(b + c), Float64(d + a)) * 2.0)
end
code[a_, b_, c_, d_] := N[(N[(a + N[(b + N[(c + d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * 2.0), $MachinePrecision]
code[a_, b_, c_, d_] := N[(N[(1.0 * N[(b + c), $MachinePrecision] + N[(d + a), $MachinePrecision]), $MachinePrecision] * 2.0), $MachinePrecision]
\left(a + \left(b + \left(c + d\right)\right)\right) \cdot 2
\mathsf{fma}\left(1, b + c, d + a\right) \cdot 2

Local Percentage Accuracy vs ?

The average percentage accuracy by input value. Horizontal axis shows value of an input variable; the variable is choosen in the title. Vertical axis is accuracy; higher is better. Red represent the original program, while blue represents Herbie's suggestion. These can be toggled with buttons below the plot. The line is an average while dots represent individual samples.

Herbie found 8 alternatives:

AlternativeAccuracySpeedup

Accuracy vs Speed

The accuracy (vertical axis) and speed (horizontal axis) of each alternatives. Up and to the right is better. The red square shows the initial program, and each blue circle shows an alternative.The line shows the best available speed-accuracy tradeoffs.

Bogosity?

Bogosity

Target

Original94.3%
Target94.0%
Herbie100.0%
\[\left(a + b\right) \cdot 2 + \left(c + d\right) \cdot 2 \]

Derivation?

  1. Initial program 94.2%

    \[\left(a + \left(b + \left(c + d\right)\right)\right) \cdot 2 \]
  2. Applied egg-rr100.0%

    \[\leadsto \color{blue}{\mathsf{fma}\left(1, b + c, d + a\right)} \cdot 2 \]
    Step-by-step derivation

    [Start]94.2%

    \[ \left(a + \left(b + \left(c + d\right)\right)\right) \cdot 2 \]

    +-commutative [=>]94.2%

    \[ \color{blue}{\left(\left(b + \left(c + d\right)\right) + a\right)} \cdot 2 \]

    associate-+r+ [=>]95.8%

    \[ \left(\color{blue}{\left(\left(b + c\right) + d\right)} + a\right) \cdot 2 \]

    associate-+l+ [=>]100.0%

    \[ \color{blue}{\left(\left(b + c\right) + \left(d + a\right)\right)} \cdot 2 \]

    *-un-lft-identity [=>]100.0%

    \[ \left(\color{blue}{1 \cdot \left(b + c\right)} + \left(d + a\right)\right) \cdot 2 \]

    fma-def [=>]100.0%

    \[ \color{blue}{\mathsf{fma}\left(1, b + c, d + a\right)} \cdot 2 \]
  3. Final simplification100.0%

    \[\leadsto \mathsf{fma}\left(1, b + c, d + a\right) \cdot 2 \]

Alternatives

Alternative 1
Accuracy100.0%
Cost6976
\[\mathsf{fma}\left(1, b + c, d + a\right) \cdot 2 \]
Alternative 2
Accuracy14.9%
Cost580
\[\begin{array}{l} \mathbf{if}\;c + d \leq 15.92:\\ \;\;\;\;\left(d + a\right) \cdot 2\\ \mathbf{else}:\\ \;\;\;\;\left(b + c\right) \cdot 2\\ \end{array} \]
Alternative 3
Accuracy94.3%
Cost576
\[2 \cdot \left(a + \left(b + \left(c + d\right)\right)\right) \]
Alternative 4
Accuracy95.7%
Cost576
\[2 \cdot \left(c + \left(a + \left(b + d\right)\right)\right) \]
Alternative 5
Accuracy100.0%
Cost576
\[2 \cdot \left(c + \left(b + \left(d + a\right)\right)\right) \]
Alternative 6
Accuracy14.3%
Cost452
\[\begin{array}{l} \mathbf{if}\;a \leq -13.8:\\ \;\;\;\;b \cdot 2\\ \mathbf{else}:\\ \;\;\;\;\left(b + c\right) \cdot 2\\ \end{array} \]
Alternative 7
Accuracy12.3%
Cost324
\[\begin{array}{l} \mathbf{if}\;a \leq -13.69:\\ \;\;\;\;b \cdot 2\\ \mathbf{else}:\\ \;\;\;\;c \cdot 2\\ \end{array} \]
Alternative 8
Accuracy6.3%
Cost192
\[b \cdot 2 \]

Reproduce?

herbie shell --seed 2023272 
(FPCore (a b c d)
  :name "Expression, p6"
  :precision binary64
  :pre (and (and (and (and (<= -14.0 a) (<= a -13.0)) (and (<= -3.0 b) (<= b -2.0))) (and (<= 3.0 c) (<= c 3.5))) (and (<= 12.5 d) (<= d 13.5)))

  :herbie-target
  (+ (* (+ a b) 2.0) (* (+ c d) 2.0))

  (* (+ a (+ b (+ c d))) 2.0))