Average Error: 0.1 → 10.5
Time: 5.1s
Precision: binary64
Cost: 6984
\[\left(\left(\left(\left(x + y\right) + y\right) + x\right) + z\right) + x \]
\[\begin{array}{l} t_0 := \mathsf{fma}\left(3, x, 2 \cdot y\right)\\ \mathbf{if}\;x \leq -5.87097160796506 \cdot 10^{+78}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq 5.0335898143874315 \cdot 10^{-79}:\\ \;\;\;\;2 \cdot y + z\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
(FPCore (x y z) :precision binary64 (+ (+ (+ (+ (+ x y) y) x) z) x))
(FPCore (x y z)
 :precision binary64
 (let* ((t_0 (fma 3.0 x (* 2.0 y))))
   (if (<= x -5.87097160796506e+78)
     t_0
     (if (<= x 5.0335898143874315e-79) (+ (* 2.0 y) z) t_0))))
double code(double x, double y, double z) {
	return ((((x + y) + y) + x) + z) + x;
}
double code(double x, double y, double z) {
	double t_0 = fma(3.0, x, (2.0 * y));
	double tmp;
	if (x <= -5.87097160796506e+78) {
		tmp = t_0;
	} else if (x <= 5.0335898143874315e-79) {
		tmp = (2.0 * y) + z;
	} else {
		tmp = t_0;
	}
	return tmp;
}
function code(x, y, z)
	return Float64(Float64(Float64(Float64(Float64(x + y) + y) + x) + z) + x)
end
function code(x, y, z)
	t_0 = fma(3.0, x, Float64(2.0 * y))
	tmp = 0.0
	if (x <= -5.87097160796506e+78)
		tmp = t_0;
	elseif (x <= 5.0335898143874315e-79)
		tmp = Float64(Float64(2.0 * y) + z);
	else
		tmp = t_0;
	end
	return tmp
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_] := Block[{t$95$0 = N[(3.0 * x + N[(2.0 * y), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[x, -5.87097160796506e+78], t$95$0, If[LessEqual[x, 5.0335898143874315e-79], N[(N[(2.0 * y), $MachinePrecision] + z), $MachinePrecision], t$95$0]]]
\left(\left(\left(\left(x + y\right) + y\right) + x\right) + z\right) + x
\begin{array}{l}
t_0 := \mathsf{fma}\left(3, x, 2 \cdot y\right)\\
\mathbf{if}\;x \leq -5.87097160796506 \cdot 10^{+78}:\\
\;\;\;\;t_0\\

\mathbf{elif}\;x \leq 5.0335898143874315 \cdot 10^{-79}:\\
\;\;\;\;2 \cdot y + z\\

\mathbf{else}:\\
\;\;\;\;t_0\\


\end{array}

Error

Derivation

  1. Split input into 2 regimes
  2. if x < -5.8709716079650597e78 or 5.0335898143874315e-79 < x

    1. Initial program 0.1

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

      \[\leadsto \color{blue}{\mathsf{fma}\left(x, 3, \mathsf{fma}\left(y, 2, z\right)\right)} \]
    3. Taylor expanded in z around 0 14.5

      \[\leadsto \color{blue}{3 \cdot x + 2 \cdot y} \]
    4. Applied egg-rr14.4

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

    if -5.8709716079650597e78 < x < 5.0335898143874315e-79

    1. Initial program 0.0

      \[\left(\left(\left(\left(x + y\right) + y\right) + x\right) + z\right) + x \]
    2. Taylor expanded in x around 0 6.7

      \[\leadsto \color{blue}{2 \cdot y + z} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification10.5

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq -5.87097160796506 \cdot 10^{+78}:\\ \;\;\;\;\mathsf{fma}\left(3, x, 2 \cdot y\right)\\ \mathbf{elif}\;x \leq 5.0335898143874315 \cdot 10^{-79}:\\ \;\;\;\;2 \cdot y + z\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(3, x, 2 \cdot y\right)\\ \end{array} \]

Alternatives

Alternative 1
Error30.5
Cost984
\[\begin{array}{l} \mathbf{if}\;y \leq -9.906000573868237 \cdot 10^{+105}:\\ \;\;\;\;2 \cdot y\\ \mathbf{elif}\;y \leq -1.5549344809234205 \cdot 10^{-12}:\\ \;\;\;\;x \cdot 3\\ \mathbf{elif}\;y \leq -1.5724751903470384 \cdot 10^{-58}:\\ \;\;\;\;z\\ \mathbf{elif}\;y \leq -4.625530957357437 \cdot 10^{-189}:\\ \;\;\;\;x \cdot 3\\ \mathbf{elif}\;y \leq 4.7855004166108063 \cdot 10^{-122}:\\ \;\;\;\;z\\ \mathbf{elif}\;y \leq 1.942263938761878 \cdot 10^{+61}:\\ \;\;\;\;x \cdot 3\\ \mathbf{else}:\\ \;\;\;\;2 \cdot y\\ \end{array} \]
Alternative 2
Error10.6
Cost712
\[\begin{array}{l} t_0 := 2 \cdot y + x \cdot 3\\ \mathbf{if}\;x \leq -5.87097160796506 \cdot 10^{+78}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq 5.0335898143874315 \cdot 10^{-79}:\\ \;\;\;\;2 \cdot y + z\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 3
Error10.6
Cost712
\[\begin{array}{l} \mathbf{if}\;x \leq -5.87097160796506 \cdot 10^{+78}:\\ \;\;\;\;x + 2 \cdot \left(x + y\right)\\ \mathbf{elif}\;x \leq 5.0335898143874315 \cdot 10^{-79}:\\ \;\;\;\;2 \cdot y + z\\ \mathbf{else}:\\ \;\;\;\;2 \cdot y + x \cdot 3\\ \end{array} \]
Alternative 4
Error13.1
Cost584
\[\begin{array}{l} \mathbf{if}\;x \leq -1.103738092206764 \cdot 10^{+131}:\\ \;\;\;\;x \cdot 3\\ \mathbf{elif}\;x \leq 6.197589223043809 \cdot 10^{+164}:\\ \;\;\;\;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 -6.515588583622846 \cdot 10^{+76}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;y \leq 1.2365694893506352 \cdot 10^{+78}:\\ \;\;\;\;z + x \cdot 3\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 6
Error31.0
Cost456
\[\begin{array}{l} \mathbf{if}\;x \leq -5.87097160796506 \cdot 10^{+78}:\\ \;\;\;\;x \cdot 3\\ \mathbf{elif}\;x \leq 1.1238387012004244 \cdot 10^{-65}:\\ \;\;\;\;z\\ \mathbf{else}:\\ \;\;\;\;x \cdot 3\\ \end{array} \]
Alternative 7
Error41.6
Cost64
\[z \]

Error

Reproduce

herbie shell --seed 2022228 
(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))