Average Error: 2.2 → 0.4
Time: 12.2s
Precision: binary64
Cost: 3016
\[\left(\left(x + y \cdot z\right) + t \cdot a\right) + \left(a \cdot z\right) \cdot b \]
\[\begin{array}{l} t_1 := z \cdot \left(y + a \cdot b\right) + \left(x + t \cdot a\right)\\ t_2 := \left(t \cdot a + \left(x + y \cdot z\right)\right) + \left(z \cdot a\right) \cdot b\\ \mathbf{if}\;t_2 \leq -\infty:\\ \;\;\;\;t_1\\ \mathbf{elif}\;t_2 \leq 5 \cdot 10^{+301}:\\ \;\;\;\;t_2\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
(FPCore (x y z t a b)
 :precision binary64
 (+ (+ (+ x (* y z)) (* t a)) (* (* a z) b)))
(FPCore (x y z t a b)
 :precision binary64
 (let* ((t_1 (+ (* z (+ y (* a b))) (+ x (* t a))))
        (t_2 (+ (+ (* t a) (+ x (* y z))) (* (* z a) b))))
   (if (<= t_2 (- INFINITY)) t_1 (if (<= t_2 5e+301) t_2 t_1))))
double code(double x, double y, double z, double t, double a, double b) {
	return ((x + (y * z)) + (t * a)) + ((a * z) * b);
}
double code(double x, double y, double z, double t, double a, double b) {
	double t_1 = (z * (y + (a * b))) + (x + (t * a));
	double t_2 = ((t * a) + (x + (y * z))) + ((z * a) * b);
	double tmp;
	if (t_2 <= -((double) INFINITY)) {
		tmp = t_1;
	} else if (t_2 <= 5e+301) {
		tmp = t_2;
	} else {
		tmp = t_1;
	}
	return tmp;
}
public static double code(double x, double y, double z, double t, double a, double b) {
	return ((x + (y * z)) + (t * a)) + ((a * z) * b);
}
public static double code(double x, double y, double z, double t, double a, double b) {
	double t_1 = (z * (y + (a * b))) + (x + (t * a));
	double t_2 = ((t * a) + (x + (y * z))) + ((z * a) * b);
	double tmp;
	if (t_2 <= -Double.POSITIVE_INFINITY) {
		tmp = t_1;
	} else if (t_2 <= 5e+301) {
		tmp = t_2;
	} else {
		tmp = t_1;
	}
	return tmp;
}
def code(x, y, z, t, a, b):
	return ((x + (y * z)) + (t * a)) + ((a * z) * b)
def code(x, y, z, t, a, b):
	t_1 = (z * (y + (a * b))) + (x + (t * a))
	t_2 = ((t * a) + (x + (y * z))) + ((z * a) * b)
	tmp = 0
	if t_2 <= -math.inf:
		tmp = t_1
	elif t_2 <= 5e+301:
		tmp = t_2
	else:
		tmp = t_1
	return tmp
function code(x, y, z, t, a, b)
	return Float64(Float64(Float64(x + Float64(y * z)) + Float64(t * a)) + Float64(Float64(a * z) * b))
end
function code(x, y, z, t, a, b)
	t_1 = Float64(Float64(z * Float64(y + Float64(a * b))) + Float64(x + Float64(t * a)))
	t_2 = Float64(Float64(Float64(t * a) + Float64(x + Float64(y * z))) + Float64(Float64(z * a) * b))
	tmp = 0.0
	if (t_2 <= Float64(-Inf))
		tmp = t_1;
	elseif (t_2 <= 5e+301)
		tmp = t_2;
	else
		tmp = t_1;
	end
	return tmp
end
function tmp = code(x, y, z, t, a, b)
	tmp = ((x + (y * z)) + (t * a)) + ((a * z) * b);
end
function tmp_2 = code(x, y, z, t, a, b)
	t_1 = (z * (y + (a * b))) + (x + (t * a));
	t_2 = ((t * a) + (x + (y * z))) + ((z * a) * b);
	tmp = 0.0;
	if (t_2 <= -Inf)
		tmp = t_1;
	elseif (t_2 <= 5e+301)
		tmp = t_2;
	else
		tmp = t_1;
	end
	tmp_2 = tmp;
end
code[x_, y_, z_, t_, a_, b_] := N[(N[(N[(x + N[(y * z), $MachinePrecision]), $MachinePrecision] + N[(t * a), $MachinePrecision]), $MachinePrecision] + N[(N[(a * z), $MachinePrecision] * b), $MachinePrecision]), $MachinePrecision]
code[x_, y_, z_, t_, a_, b_] := Block[{t$95$1 = N[(N[(z * N[(y + N[(a * b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(x + N[(t * a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$2 = N[(N[(N[(t * a), $MachinePrecision] + N[(x + N[(y * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(N[(z * a), $MachinePrecision] * b), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$2, (-Infinity)], t$95$1, If[LessEqual[t$95$2, 5e+301], t$95$2, t$95$1]]]]
\left(\left(x + y \cdot z\right) + t \cdot a\right) + \left(a \cdot z\right) \cdot b
\begin{array}{l}
t_1 := z \cdot \left(y + a \cdot b\right) + \left(x + t \cdot a\right)\\
t_2 := \left(t \cdot a + \left(x + y \cdot z\right)\right) + \left(z \cdot a\right) \cdot b\\
\mathbf{if}\;t_2 \leq -\infty:\\
\;\;\;\;t_1\\

\mathbf{elif}\;t_2 \leq 5 \cdot 10^{+301}:\\
\;\;\;\;t_2\\

\mathbf{else}:\\
\;\;\;\;t_1\\


\end{array}

Error

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original2.2
Target0.3
Herbie0.4
\[\begin{array}{l} \mathbf{if}\;z < -11820553527347888000:\\ \;\;\;\;z \cdot \left(b \cdot a + y\right) + \left(x + t \cdot a\right)\\ \mathbf{elif}\;z < 4.7589743188364287 \cdot 10^{-122}:\\ \;\;\;\;\left(b \cdot z + t\right) \cdot a + \left(z \cdot y + x\right)\\ \mathbf{else}:\\ \;\;\;\;z \cdot \left(b \cdot a + y\right) + \left(x + t \cdot a\right)\\ \end{array} \]

Derivation

  1. Split input into 2 regimes
  2. if (+.f64 (+.f64 (+.f64 x (*.f64 y z)) (*.f64 t a)) (*.f64 (*.f64 a z) b)) < -inf.0 or 5.0000000000000004e301 < (+.f64 (+.f64 (+.f64 x (*.f64 y z)) (*.f64 t a)) (*.f64 (*.f64 a z) b))

    1. Initial program 46.4

      \[\left(\left(x + y \cdot z\right) + t \cdot a\right) + \left(a \cdot z\right) \cdot b \]
    2. Simplified1.2

      \[\leadsto \color{blue}{\mathsf{fma}\left(y, z, \mathsf{fma}\left(a, \mathsf{fma}\left(z, b, t\right), x\right)\right)} \]
      Proof
      (fma.f64 y z (fma.f64 a (fma.f64 z b t) x)): 0 points increase in error, 0 points decrease in error
      (fma.f64 y z (fma.f64 a (Rewrite<= fma-def_binary64 (+.f64 (*.f64 z b) t)) x)): 2 points increase in error, 0 points decrease in error
      (fma.f64 y z (fma.f64 a (Rewrite<= +-commutative_binary64 (+.f64 t (*.f64 z b))) x)): 0 points increase in error, 0 points decrease in error
      (fma.f64 y z (Rewrite<= fma-def_binary64 (+.f64 (*.f64 a (+.f64 t (*.f64 z b))) x))): 0 points increase in error, 0 points decrease in error
      (fma.f64 y z (+.f64 (Rewrite<= distribute-lft-out_binary64 (+.f64 (*.f64 a t) (*.f64 a (*.f64 z b)))) x)): 0 points increase in error, 5 points decrease in error
      (fma.f64 y z (+.f64 (+.f64 (Rewrite<= *-commutative_binary64 (*.f64 t a)) (*.f64 a (*.f64 z b))) x)): 0 points increase in error, 0 points decrease in error
      (fma.f64 y z (+.f64 (+.f64 (*.f64 t a) (Rewrite<= associate-*l*_binary64 (*.f64 (*.f64 a z) b))) x)): 12 points increase in error, 10 points decrease in error
      (fma.f64 y z (Rewrite<= +-commutative_binary64 (+.f64 x (+.f64 (*.f64 t a) (*.f64 (*.f64 a z) b))))): 0 points increase in error, 0 points decrease in error
      (Rewrite<= fma-def_binary64 (+.f64 (*.f64 y z) (+.f64 x (+.f64 (*.f64 t a) (*.f64 (*.f64 a z) b))))): 0 points increase in error, 0 points decrease in error
      (Rewrite<= associate-+l+_binary64 (+.f64 (+.f64 (*.f64 y z) x) (+.f64 (*.f64 t a) (*.f64 (*.f64 a z) b)))): 0 points increase in error, 0 points decrease in error
      (+.f64 (Rewrite<= +-commutative_binary64 (+.f64 x (*.f64 y z))) (+.f64 (*.f64 t a) (*.f64 (*.f64 a z) b))): 0 points increase in error, 0 points decrease in error
      (Rewrite<= associate-+l+_binary64 (+.f64 (+.f64 (+.f64 x (*.f64 y z)) (*.f64 t a)) (*.f64 (*.f64 a z) b))): 0 points increase in error, 0 points decrease in error
    3. Taylor expanded in z around 0 2.6

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

    if -inf.0 < (+.f64 (+.f64 (+.f64 x (*.f64 y z)) (*.f64 t a)) (*.f64 (*.f64 a z) b)) < 5.0000000000000004e301

    1. Initial program 0.3

      \[\left(\left(x + y \cdot z\right) + t \cdot a\right) + \left(a \cdot z\right) \cdot b \]
  3. Recombined 2 regimes into one program.
  4. Final simplification0.4

    \[\leadsto \begin{array}{l} \mathbf{if}\;\left(t \cdot a + \left(x + y \cdot z\right)\right) + \left(z \cdot a\right) \cdot b \leq -\infty:\\ \;\;\;\;z \cdot \left(y + a \cdot b\right) + \left(x + t \cdot a\right)\\ \mathbf{elif}\;\left(t \cdot a + \left(x + y \cdot z\right)\right) + \left(z \cdot a\right) \cdot b \leq 5 \cdot 10^{+301}:\\ \;\;\;\;\left(t \cdot a + \left(x + y \cdot z\right)\right) + \left(z \cdot a\right) \cdot b\\ \mathbf{else}:\\ \;\;\;\;z \cdot \left(y + a \cdot b\right) + \left(x + t \cdot a\right)\\ \end{array} \]

Alternatives

Alternative 1
Error38.5
Cost1248
\[\begin{array}{l} \mathbf{if}\;t \leq -2.4 \cdot 10^{+157}:\\ \;\;\;\;t \cdot a\\ \mathbf{elif}\;t \leq -2.1446390481893005 \cdot 10^{-88}:\\ \;\;\;\;x\\ \mathbf{elif}\;t \leq -9.503456403107622 \cdot 10^{-119}:\\ \;\;\;\;z \cdot \left(a \cdot b\right)\\ \mathbf{elif}\;t \leq -4.516480278219063 \cdot 10^{-130}:\\ \;\;\;\;x\\ \mathbf{elif}\;t \leq -8.304738556304417 \cdot 10^{-225}:\\ \;\;\;\;y \cdot z\\ \mathbf{elif}\;t \leq -1.6046660222089858 \cdot 10^{-232}:\\ \;\;\;\;x\\ \mathbf{elif}\;t \leq -4.700685452119529 \cdot 10^{-276}:\\ \;\;\;\;y \cdot z\\ \mathbf{elif}\;t \leq 1.977463497887206 \cdot 10^{+65}:\\ \;\;\;\;x\\ \mathbf{else}:\\ \;\;\;\;t \cdot a\\ \end{array} \]
Alternative 2
Error38.4
Cost1248
\[\begin{array}{l} \mathbf{if}\;t \leq -2.4 \cdot 10^{+157}:\\ \;\;\;\;t \cdot a\\ \mathbf{elif}\;t \leq -2.1446390481893005 \cdot 10^{-88}:\\ \;\;\;\;x\\ \mathbf{elif}\;t \leq -1.420602729750542 \cdot 10^{-119}:\\ \;\;\;\;a \cdot \left(z \cdot b\right)\\ \mathbf{elif}\;t \leq -4.516480278219063 \cdot 10^{-130}:\\ \;\;\;\;x\\ \mathbf{elif}\;t \leq -8.304738556304417 \cdot 10^{-225}:\\ \;\;\;\;y \cdot z\\ \mathbf{elif}\;t \leq -1.6046660222089858 \cdot 10^{-232}:\\ \;\;\;\;x\\ \mathbf{elif}\;t \leq -4.700685452119529 \cdot 10^{-276}:\\ \;\;\;\;y \cdot z\\ \mathbf{elif}\;t \leq 1.977463497887206 \cdot 10^{+65}:\\ \;\;\;\;x\\ \mathbf{else}:\\ \;\;\;\;t \cdot a\\ \end{array} \]
Alternative 3
Error27.6
Cost1112
\[\begin{array}{l} t_1 := x + t \cdot a\\ \mathbf{if}\;t \leq -2.1446390481893005 \cdot 10^{-88}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;t \leq -1.420602729750542 \cdot 10^{-119}:\\ \;\;\;\;a \cdot \left(z \cdot b\right)\\ \mathbf{elif}\;t \leq -4.516480278219063 \cdot 10^{-130}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;t \leq -8.304738556304417 \cdot 10^{-225}:\\ \;\;\;\;y \cdot z\\ \mathbf{elif}\;t \leq -1.6046660222089858 \cdot 10^{-232}:\\ \;\;\;\;x\\ \mathbf{elif}\;t \leq -4.700685452119529 \cdot 10^{-276}:\\ \;\;\;\;y \cdot z\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 4
Error20.8
Cost1112
\[\begin{array}{l} t_1 := x + a \cdot \left(z \cdot b\right)\\ t_2 := x + y \cdot z\\ t_3 := x + t \cdot a\\ \mathbf{if}\;t \leq -2.1446390481893005 \cdot 10^{-88}:\\ \;\;\;\;t_3\\ \mathbf{elif}\;t \leq -3.7808494186474514 \cdot 10^{-123}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;t \leq 2.5822304866025677 \cdot 10^{-252}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;t \leq 2.7047987233419005 \cdot 10^{-77}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;t \leq 1.051598008603978 \cdot 10^{+46}:\\ \;\;\;\;t_3\\ \mathbf{elif}\;t \leq 1.65 \cdot 10^{+68}:\\ \;\;\;\;t_2\\ \mathbf{else}:\\ \;\;\;\;t_3\\ \end{array} \]
Alternative 5
Error1.8
Cost1096
\[\begin{array}{l} t_1 := x + a \cdot \left(t + z \cdot b\right)\\ \mathbf{if}\;a \leq -5 \cdot 10^{+164}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;a \leq 10^{+115}:\\ \;\;\;\;z \cdot \left(y + a \cdot b\right) + \left(x + t \cdot a\right)\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 6
Error19.0
Cost844
\[\begin{array}{l} t_1 := a \cdot \left(t + z \cdot b\right)\\ \mathbf{if}\;a \leq -8.6 \cdot 10^{+139}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;a \leq -3.22 \cdot 10^{-72}:\\ \;\;\;\;x + t \cdot a\\ \mathbf{elif}\;a \leq 3.2383649495842186 \cdot 10^{-7}:\\ \;\;\;\;x + y \cdot z\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 7
Error19.0
Cost844
\[\begin{array}{l} \mathbf{if}\;a \leq -8.6 \cdot 10^{+139}:\\ \;\;\;\;t \cdot a + a \cdot \left(z \cdot b\right)\\ \mathbf{elif}\;a \leq -3.22 \cdot 10^{-72}:\\ \;\;\;\;x + t \cdot a\\ \mathbf{elif}\;a \leq 3.2383649495842186 \cdot 10^{-7}:\\ \;\;\;\;x + y \cdot z\\ \mathbf{else}:\\ \;\;\;\;a \cdot \left(t + z \cdot b\right)\\ \end{array} \]
Alternative 8
Error10.7
Cost840
\[\begin{array}{l} t_1 := \left(x + t \cdot a\right) + y \cdot z\\ \mathbf{if}\;t \leq -5.580124078163847 \cdot 10^{-89}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;t \leq -3.7808494186474514 \cdot 10^{-123}:\\ \;\;\;\;x + a \cdot \left(z \cdot b\right)\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 9
Error7.1
Cost840
\[\begin{array}{l} t_1 := \left(x + t \cdot a\right) + y \cdot z\\ \mathbf{if}\;y \leq -1.595379899593193 \cdot 10^{-85}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq 1.9657532737545913 \cdot 10^{-45}:\\ \;\;\;\;x + a \cdot \left(t + z \cdot b\right)\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 10
Error19.1
Cost584
\[\begin{array}{l} t_1 := x + t \cdot a\\ \mathbf{if}\;a \leq -3.22 \cdot 10^{-72}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;a \leq 0.01789350867250985:\\ \;\;\;\;x + y \cdot z\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 11
Error32.7
Cost456
\[\begin{array}{l} \mathbf{if}\;x \leq -120.07613596783145:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq 7394.129865985777:\\ \;\;\;\;t \cdot a\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 12
Error39.6
Cost64
\[x \]

Error

Reproduce

herbie shell --seed 2022300 
(FPCore (x y z t a b)
  :name "Graphics.Rasterific.CubicBezier:cachedBezierAt from Rasterific-0.6.1"
  :precision binary64

  :herbie-target
  (if (< z -11820553527347888000.0) (+ (* z (+ (* b a) y)) (+ x (* t a))) (if (< z 4.7589743188364287e-122) (+ (* (+ (* b z) t) a) (+ (* z y) x)) (+ (* z (+ (* b a) y)) (+ x (* t a)))))

  (+ (+ (+ x (* y z)) (* t a)) (* (* a z) b)))