?

Average Error: 0.1 → 0.0
Time: 54.0s
Precision: binary64
Cost: 13120

?

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

Error?

Derivation?

  1. Initial program 0.1

    \[\left(\left(\left(\left(x + y\right) + y\right) + x\right) + z\right) + x \]
  2. Simplified0.1

    \[\leadsto \color{blue}{2 \cdot \left(x + y\right) + \left(x + z\right)} \]
    Proof
  3. Taylor expanded in x around 0 0.1

    \[\leadsto \color{blue}{3 \cdot x + \left(2 \cdot y + z\right)} \]
  4. Simplified0.0

    \[\leadsto \color{blue}{\mathsf{fma}\left(3, x, \mathsf{fma}\left(2, y, z\right)\right)} \]
    Proof

Alternatives

Alternative 1
Error9.4
Cost716
\[\begin{array}{l} t_0 := 2 \cdot y + z\\ \mathbf{if}\;z \leq -1000000000:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq 24000000000:\\ \;\;\;\;2 \cdot \left(y + x\right) + x\\ \mathbf{elif}\;z \leq 7 \cdot 10^{+124}:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;3 \cdot x + z\\ \end{array} \]
Alternative 2
Error9.9
Cost712
\[\begin{array}{l} t_0 := 2 \cdot y + z\\ \mathbf{if}\;y \leq -8 \cdot 10^{+89}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;y \leq 0.02:\\ \;\;\;\;2 \cdot x + \left(z + x\right)\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 3
Error30.5
Cost588
\[\begin{array}{l} \mathbf{if}\;z \leq -4 \cdot 10^{+93}:\\ \;\;\;\;z\\ \mathbf{elif}\;z \leq -2.4 \cdot 10^{-297}:\\ \;\;\;\;2 \cdot y\\ \mathbf{elif}\;z \leq 1.62 \cdot 10^{-46}:\\ \;\;\;\;x \cdot 3\\ \mathbf{else}:\\ \;\;\;\;z\\ \end{array} \]
Alternative 4
Error12.2
Cost584
\[\begin{array}{l} \mathbf{if}\;x \leq -8.2 \cdot 10^{+87}:\\ \;\;\;\;x \cdot 3\\ \mathbf{elif}\;x \leq 2.2 \cdot 10^{+138}:\\ \;\;\;\;2 \cdot y + z\\ \mathbf{else}:\\ \;\;\;\;x \cdot 3\\ \end{array} \]
Alternative 5
Error9.9
Cost584
\[\begin{array}{l} t_0 := 2 \cdot y + z\\ \mathbf{if}\;y \leq -4.8 \cdot 10^{+89}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;y \leq 0.035:\\ \;\;\;\;3 \cdot x + z\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 6
Error0.1
Cost576
\[2 \cdot \left(x + y\right) + \left(x + z\right) \]
Alternative 7
Error29.9
Cost456
\[\begin{array}{l} \mathbf{if}\;z \leq -4.4 \cdot 10^{+94}:\\ \;\;\;\;z\\ \mathbf{elif}\;z \leq 10^{+69}:\\ \;\;\;\;2 \cdot y\\ \mathbf{else}:\\ \;\;\;\;z\\ \end{array} \]
Alternative 8
Error42.2
Cost64
\[z \]

Error

Reproduce?

herbie shell --seed 2023033 
(FPCore (x y z)
  :name "Graphics.Rendering.Plot.Render.Plot.Legend:renderLegendInside from plot-0.2.3.4"
  :precision binary64
  (+ (+ (+ (+ (+ x y) y) x) z) x))