Graphics.Rendering.Plot.Render.Plot.Legend:renderLegendOutside from plot-0.2.3.4, B

?

Percentage Accurate: 99.8% → 99.9%
Time: 8.7s
Precision: binary64
Cost: 13376

?

\[x \cdot \left(\left(\left(\left(y + z\right) + z\right) + y\right) + t\right) + y \cdot 5 \]
\[\mathsf{fma}\left(y, 5, x \cdot \mathsf{fma}\left(y + z, 2, t\right)\right) \]
(FPCore (x y z t)
 :precision binary64
 (+ (* x (+ (+ (+ (+ y z) z) y) t)) (* y 5.0)))
(FPCore (x y z t) :precision binary64 (fma y 5.0 (* x (fma (+ y z) 2.0 t))))
double code(double x, double y, double z, double t) {
	return (x * ((((y + z) + z) + y) + t)) + (y * 5.0);
}
double code(double x, double y, double z, double t) {
	return fma(y, 5.0, (x * fma((y + z), 2.0, t)));
}
function code(x, y, z, t)
	return Float64(Float64(x * Float64(Float64(Float64(Float64(y + z) + z) + y) + t)) + Float64(y * 5.0))
end
function code(x, y, z, t)
	return fma(y, 5.0, Float64(x * fma(Float64(y + z), 2.0, t)))
end
code[x_, y_, z_, t_] := N[(N[(x * N[(N[(N[(N[(y + z), $MachinePrecision] + z), $MachinePrecision] + y), $MachinePrecision] + t), $MachinePrecision]), $MachinePrecision] + N[(y * 5.0), $MachinePrecision]), $MachinePrecision]
code[x_, y_, z_, t_] := N[(y * 5.0 + N[(x * N[(N[(y + z), $MachinePrecision] * 2.0 + t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
x \cdot \left(\left(\left(\left(y + z\right) + z\right) + y\right) + t\right) + y \cdot 5
\mathsf{fma}\left(y, 5, x \cdot \mathsf{fma}\left(y + z, 2, t\right)\right)

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 13 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

Derivation?

  1. Initial program 99.5%

    \[x \cdot \left(\left(\left(\left(y + z\right) + z\right) + y\right) + t\right) + y \cdot 5 \]
  2. Applied egg-rr100.0%

    \[\leadsto \color{blue}{\mathsf{fma}\left(y, 5, x \cdot \mathsf{fma}\left(y + z, 2, t\right)\right)} \]
    Step-by-step derivation

    [Start]99.5%

    \[ x \cdot \left(\left(\left(\left(y + z\right) + z\right) + y\right) + t\right) + y \cdot 5 \]

    +-commutative [=>]99.5%

    \[ \color{blue}{y \cdot 5 + x \cdot \left(\left(\left(\left(y + z\right) + z\right) + y\right) + t\right)} \]

    fma-def [=>]100.0%

    \[ \color{blue}{\mathsf{fma}\left(y, 5, x \cdot \left(\left(\left(\left(y + z\right) + z\right) + y\right) + t\right)\right)} \]

    distribute-rgt-in [=>]96.9%

    \[ \mathsf{fma}\left(y, 5, \color{blue}{\left(\left(\left(y + z\right) + z\right) + y\right) \cdot x + t \cdot x}\right) \]

    associate-+l+ [=>]96.9%

    \[ \mathsf{fma}\left(y, 5, \color{blue}{\left(\left(y + z\right) + \left(z + y\right)\right)} \cdot x + t \cdot x\right) \]

    +-commutative [<=]96.9%

    \[ \mathsf{fma}\left(y, 5, \left(\left(y + z\right) + \color{blue}{\left(y + z\right)}\right) \cdot x + t \cdot x\right) \]

    count-2 [=>]96.9%

    \[ \mathsf{fma}\left(y, 5, \color{blue}{\left(2 \cdot \left(y + z\right)\right)} \cdot x + t \cdot x\right) \]

    distribute-rgt-in [<=]100.0%

    \[ \mathsf{fma}\left(y, 5, \color{blue}{x \cdot \left(2 \cdot \left(y + z\right) + t\right)}\right) \]

    *-commutative [=>]100.0%

    \[ \mathsf{fma}\left(y, 5, x \cdot \left(\color{blue}{\left(y + z\right) \cdot 2} + t\right)\right) \]

    fma-def [=>]100.0%

    \[ \mathsf{fma}\left(y, 5, x \cdot \color{blue}{\mathsf{fma}\left(y + z, 2, t\right)}\right) \]
  3. Final simplification100.0%

    \[\leadsto \mathsf{fma}\left(y, 5, x \cdot \mathsf{fma}\left(y + z, 2, t\right)\right) \]

Alternatives

Alternative 1
Accuracy99.9%
Cost13376
\[\mathsf{fma}\left(y, 5, x \cdot \mathsf{fma}\left(y + z, 2, t\right)\right) \]
Alternative 2
Accuracy99.8%
Cost7104
\[\mathsf{fma}\left(x, t + \left(y + z\right) \cdot 2, y \cdot 5\right) \]
Alternative 3
Accuracy86.2%
Cost1100
\[\begin{array}{l} t_1 := x \cdot \left(t + \left(y + z\right) \cdot 2\right)\\ \mathbf{if}\;x \leq -1.02 \cdot 10^{-166}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq 4.5 \cdot 10^{-244}:\\ \;\;\;\;x \cdot \left(z \cdot 2\right) + y \cdot 5\\ \mathbf{elif}\;x \leq 1450000000000:\\ \;\;\;\;x \cdot \left(t + y \cdot 2\right) + y \cdot 5\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 4
Accuracy86.2%
Cost972
\[\begin{array}{l} t_1 := x \cdot \left(t + \left(y + z\right) \cdot 2\right)\\ \mathbf{if}\;x \leq -1.02 \cdot 10^{-166}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq 9 \cdot 10^{-246}:\\ \;\;\;\;x \cdot \left(z \cdot 2\right) + y \cdot 5\\ \mathbf{elif}\;x \leq 3.2 \cdot 10^{-42}:\\ \;\;\;\;y \cdot 5 + x \cdot t\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 5
Accuracy99.8%
Cost960
\[x \cdot \left(t + \left(y + \left(z + \left(y + z\right)\right)\right)\right) + y \cdot 5 \]
Alternative 6
Accuracy45.0%
Cost849
\[\begin{array}{l} t_1 := 2 \cdot \left(x \cdot z\right)\\ \mathbf{if}\;x \leq -1.5 \cdot 10^{-174}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq 3.6 \cdot 10^{-19}:\\ \;\;\;\;y \cdot 5\\ \mathbf{elif}\;x \leq 1.62 \cdot 10^{+139} \lor \neg \left(x \leq 8.2 \cdot 10^{+267}\right):\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;x \cdot t\\ \end{array} \]
Alternative 7
Accuracy70.8%
Cost845
\[\begin{array}{l} \mathbf{if}\;x \leq -5.8 \cdot 10^{+47}:\\ \;\;\;\;x \cdot \left(\left(y + z\right) \cdot 2\right)\\ \mathbf{elif}\;x \leq -1.5 \cdot 10^{-174} \lor \neg \left(x \leq 4.4 \cdot 10^{-41}\right):\\ \;\;\;\;x \cdot \left(t + z \cdot 2\right)\\ \mathbf{else}:\\ \;\;\;\;y \cdot 5 + x \cdot t\\ \end{array} \]
Alternative 8
Accuracy85.5%
Cost841
\[\begin{array}{l} \mathbf{if}\;x \leq -1.5 \cdot 10^{-174} \lor \neg \left(x \leq 9.6 \cdot 10^{-39}\right):\\ \;\;\;\;x \cdot \left(t + \left(y + z\right) \cdot 2\right)\\ \mathbf{else}:\\ \;\;\;\;y \cdot 5 + x \cdot t\\ \end{array} \]
Alternative 9
Accuracy61.4%
Cost713
\[\begin{array}{l} \mathbf{if}\;x \leq -7.5 \cdot 10^{-156} \lor \neg \left(x \leq 1.75 \cdot 10^{-19}\right):\\ \;\;\;\;x \cdot \left(\left(y + z\right) \cdot 2\right)\\ \mathbf{else}:\\ \;\;\;\;y \cdot 5\\ \end{array} \]
Alternative 10
Accuracy78.4%
Cost713
\[\begin{array}{l} \mathbf{if}\;y \leq -2.4 \cdot 10^{+77} \lor \neg \left(y \leq 350000000\right):\\ \;\;\;\;y \cdot \left(5 + x \cdot 2\right)\\ \mathbf{else}:\\ \;\;\;\;x \cdot \left(t + z \cdot 2\right)\\ \end{array} \]
Alternative 11
Accuracy61.4%
Cost712
\[\begin{array}{l} \mathbf{if}\;x \leq -7.5 \cdot 10^{-156}:\\ \;\;\;\;x \cdot \left(\left(y + z\right) \cdot 2\right)\\ \mathbf{elif}\;x \leq 3.8 \cdot 10^{-34}:\\ \;\;\;\;y \cdot 5\\ \mathbf{else}:\\ \;\;\;\;x \cdot \left(t + y \cdot 2\right)\\ \end{array} \]
Alternative 12
Accuracy47.4%
Cost456
\[\begin{array}{l} \mathbf{if}\;x \leq -1.55 \cdot 10^{-80}:\\ \;\;\;\;x \cdot t\\ \mathbf{elif}\;x \leq 3.6 \cdot 10^{-34}:\\ \;\;\;\;y \cdot 5\\ \mathbf{else}:\\ \;\;\;\;x \cdot t\\ \end{array} \]
Alternative 13
Accuracy30.1%
Cost192
\[y \cdot 5 \]

Reproduce?

herbie shell --seed 2023245 
(FPCore (x y z t)
  :name "Graphics.Rendering.Plot.Render.Plot.Legend:renderLegendOutside from plot-0.2.3.4, B"
  :precision binary64
  (+ (* x (+ (+ (+ (+ y z) z) y) t)) (* y 5.0)))