Average Error: 2.0 → 0.2
Time: 8.9s
Precision: binary64
Cost: 1224
\[\left(\left(x + y \cdot z\right) + t \cdot a\right) + \left(a \cdot z\right) \cdot b \]
\[\begin{array}{l} t_1 := x + y \cdot z\\ \mathbf{if}\;z \leq -1.1 \cdot 10^{+57}:\\ \;\;\;\;\left(t \cdot a + t_1\right) + z \cdot \left(b \cdot a\right)\\ \mathbf{elif}\;z \leq 10^{-50}:\\ \;\;\;\;\left(a \cdot \left(b \cdot z\right) + t \cdot a\right) + t_1\\ \mathbf{else}:\\ \;\;\;\;z \cdot \left(y + b \cdot a\right) + \left(x + t \cdot a\right)\\ \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 (+ x (* y z))))
   (if (<= z -1.1e+57)
     (+ (+ (* t a) t_1) (* z (* b a)))
     (if (<= z 1e-50)
       (+ (+ (* a (* b z)) (* t a)) t_1)
       (+ (* z (+ y (* b a))) (+ x (* t a)))))))
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 = x + (y * z);
	double tmp;
	if (z <= -1.1e+57) {
		tmp = ((t * a) + t_1) + (z * (b * a));
	} else if (z <= 1e-50) {
		tmp = ((a * (b * z)) + (t * a)) + t_1;
	} else {
		tmp = (z * (y + (b * a))) + (x + (t * a));
	}
	return tmp;
}
real(8) function code(x, y, z, t, a, b)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    real(8), intent (in) :: t
    real(8), intent (in) :: a
    real(8), intent (in) :: b
    code = ((x + (y * z)) + (t * a)) + ((a * z) * b)
end function
real(8) function code(x, y, z, t, a, b)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    real(8), intent (in) :: t
    real(8), intent (in) :: a
    real(8), intent (in) :: b
    real(8) :: t_1
    real(8) :: tmp
    t_1 = x + (y * z)
    if (z <= (-1.1d+57)) then
        tmp = ((t * a) + t_1) + (z * (b * a))
    else if (z <= 1d-50) then
        tmp = ((a * (b * z)) + (t * a)) + t_1
    else
        tmp = (z * (y + (b * a))) + (x + (t * a))
    end if
    code = tmp
end function
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 = x + (y * z);
	double tmp;
	if (z <= -1.1e+57) {
		tmp = ((t * a) + t_1) + (z * (b * a));
	} else if (z <= 1e-50) {
		tmp = ((a * (b * z)) + (t * a)) + t_1;
	} else {
		tmp = (z * (y + (b * a))) + (x + (t * a));
	}
	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 = x + (y * z)
	tmp = 0
	if z <= -1.1e+57:
		tmp = ((t * a) + t_1) + (z * (b * a))
	elif z <= 1e-50:
		tmp = ((a * (b * z)) + (t * a)) + t_1
	else:
		tmp = (z * (y + (b * a))) + (x + (t * a))
	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(x + Float64(y * z))
	tmp = 0.0
	if (z <= -1.1e+57)
		tmp = Float64(Float64(Float64(t * a) + t_1) + Float64(z * Float64(b * a)));
	elseif (z <= 1e-50)
		tmp = Float64(Float64(Float64(a * Float64(b * z)) + Float64(t * a)) + t_1);
	else
		tmp = Float64(Float64(z * Float64(y + Float64(b * a))) + Float64(x + Float64(t * a)));
	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 = x + (y * z);
	tmp = 0.0;
	if (z <= -1.1e+57)
		tmp = ((t * a) + t_1) + (z * (b * a));
	elseif (z <= 1e-50)
		tmp = ((a * (b * z)) + (t * a)) + t_1;
	else
		tmp = (z * (y + (b * a))) + (x + (t * a));
	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[(x + N[(y * z), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[z, -1.1e+57], N[(N[(N[(t * a), $MachinePrecision] + t$95$1), $MachinePrecision] + N[(z * N[(b * a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[z, 1e-50], N[(N[(N[(a * N[(b * z), $MachinePrecision]), $MachinePrecision] + N[(t * a), $MachinePrecision]), $MachinePrecision] + t$95$1), $MachinePrecision], N[(N[(z * N[(y + N[(b * a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(x + N[(t * a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]
\left(\left(x + y \cdot z\right) + t \cdot a\right) + \left(a \cdot z\right) \cdot b
\begin{array}{l}
t_1 := x + y \cdot z\\
\mathbf{if}\;z \leq -1.1 \cdot 10^{+57}:\\
\;\;\;\;\left(t \cdot a + t_1\right) + z \cdot \left(b \cdot a\right)\\

\mathbf{elif}\;z \leq 10^{-50}:\\
\;\;\;\;\left(a \cdot \left(b \cdot z\right) + t \cdot a\right) + t_1\\

\mathbf{else}:\\
\;\;\;\;z \cdot \left(y + b \cdot a\right) + \left(x + t \cdot a\right)\\


\end{array}

Error

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original2.0
Target0.3
Herbie0.2
\[\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 3 regimes
  2. if z < -1.1e57

    1. Initial program 6.4

      \[\left(\left(x + y \cdot z\right) + t \cdot a\right) + \left(a \cdot z\right) \cdot b \]
    2. Taylor expanded in a around 0 9.5

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

      \[\leadsto \left(\left(x + y \cdot z\right) + t \cdot a\right) + \color{blue}{\left(a \cdot b\right) \cdot z} \]
      Proof
      (*.f64 (*.f64 a b) z): 0 points increase in error, 0 points decrease in error
      (Rewrite<= associate-*r*_binary64 (*.f64 a (*.f64 b z))): 40 points increase in error, 59 points decrease in error

    if -1.1e57 < z < 1.00000000000000001e-50

    1. Initial program 0.5

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

      \[\leadsto \color{blue}{\left(x + y \cdot z\right) + \left(t \cdot a + a \cdot \left(z \cdot b\right)\right)} \]
      Proof
      (+.f64 (+.f64 x (*.f64 y z)) (+.f64 (*.f64 t a) (*.f64 a (*.f64 z b)))): 0 points increase in error, 0 points decrease in error
      (+.f64 (+.f64 x (*.f64 y z)) (+.f64 (*.f64 t a) (Rewrite<= associate-*l*_binary64 (*.f64 (*.f64 a z) b)))): 11 points increase in error, 16 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

    if 1.00000000000000001e-50 < z

    1. Initial program 3.9

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

      \[\leadsto \color{blue}{\left(x + y \cdot z\right) + \left(t \cdot a + a \cdot \left(z \cdot b\right)\right)} \]
      Proof
      (+.f64 (+.f64 x (*.f64 y z)) (+.f64 (*.f64 t a) (*.f64 a (*.f64 z b)))): 0 points increase in error, 0 points decrease in error
      (+.f64 (+.f64 x (*.f64 y z)) (+.f64 (*.f64 t a) (Rewrite<= associate-*l*_binary64 (*.f64 (*.f64 a z) b)))): 11 points increase in error, 16 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 0.2

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

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

Alternatives

Alternative 1
Error0.3
Cost13640
\[\begin{array}{l} t_1 := \left(t \cdot a + \left(x + y \cdot z\right)\right) + b \cdot \left(z \cdot a\right)\\ \mathbf{if}\;b \leq -1 \cdot 10^{+42}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;b \leq 10^{+46}:\\ \;\;\;\;\mathsf{fma}\left(a, t + b \cdot z, \mathsf{fma}\left(y, z, x\right)\right)\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 2
Error19.1
Cost1372
\[\begin{array}{l} t_1 := y \cdot z + t \cdot a\\ t_2 := x + y \cdot z\\ t_3 := z \cdot \left(y + b \cdot a\right)\\ t_4 := x + t \cdot a\\ \mathbf{if}\;x \leq -4.3 \cdot 10^{-126}:\\ \;\;\;\;t_4\\ \mathbf{elif}\;x \leq 4.7 \cdot 10^{-85}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq 6.6 \cdot 10^{-18}:\\ \;\;\;\;t_3\\ \mathbf{elif}\;x \leq 10^{+22}:\\ \;\;\;\;t_4\\ \mathbf{elif}\;x \leq 1.5 \cdot 10^{+27}:\\ \;\;\;\;t_3\\ \mathbf{elif}\;x \leq 4 \cdot 10^{+42}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;x \leq 9 \cdot 10^{+48}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;t_2\\ \end{array} \]
Alternative 3
Error0.2
Cost1224
\[\begin{array}{l} t_1 := z \cdot \left(y + b \cdot a\right) + \left(x + t \cdot a\right)\\ \mathbf{if}\;z \leq -4 \cdot 10^{+57}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq 10^{-50}:\\ \;\;\;\;\left(a \cdot \left(b \cdot z\right) + t \cdot a\right) + \left(x + y \cdot z\right)\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 4
Error0.4
Cost1224
\[\begin{array}{l} t_1 := t \cdot a + \left(x + y \cdot z\right)\\ t_2 := t_1 + b \cdot \left(z \cdot a\right)\\ \mathbf{if}\;b \leq -7.5 \cdot 10^{+77}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;b \leq 2 \cdot 10^{+73}:\\ \;\;\;\;t_1 + z \cdot \left(b \cdot a\right)\\ \mathbf{else}:\\ \;\;\;\;t_2\\ \end{array} \]
Alternative 5
Error33.1
Cost984
\[\begin{array}{l} \mathbf{if}\;x \leq -1.3 \cdot 10^{-16}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq -1.35 \cdot 10^{-59}:\\ \;\;\;\;t \cdot a\\ \mathbf{elif}\;x \leq -4.3 \cdot 10^{-126}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq -1.82 \cdot 10^{-240}:\\ \;\;\;\;y \cdot z\\ \mathbf{elif}\;x \leq -6.8 \cdot 10^{-285}:\\ \;\;\;\;t \cdot a\\ \mathbf{elif}\;x \leq 5.6 \cdot 10^{-18}:\\ \;\;\;\;y \cdot z\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 6
Error16.4
Cost980
\[\begin{array}{l} t_1 := y \cdot z + t \cdot a\\ \mathbf{if}\;x \leq -3.8 \cdot 10^{-126}:\\ \;\;\;\;x + a \cdot \left(t + b \cdot z\right)\\ \mathbf{elif}\;x \leq 4.4 \cdot 10^{-39}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq 1.8 \cdot 10^{-8}:\\ \;\;\;\;x + b \cdot \left(z \cdot a\right)\\ \mathbf{elif}\;x \leq 1.05 \cdot 10^{+25}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq 1.2 \cdot 10^{+230}:\\ \;\;\;\;x + y \cdot z\\ \mathbf{else}:\\ \;\;\;\;x + t \cdot a\\ \end{array} \]
Alternative 7
Error20.2
Cost976
\[\begin{array}{l} t_1 := z \cdot \left(y + b \cdot a\right)\\ \mathbf{if}\;z \leq -0.155:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq 7.5 \cdot 10^{-9}:\\ \;\;\;\;x + t \cdot a\\ \mathbf{elif}\;z \leq 1.15 \cdot 10^{+33}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq 1.55 \cdot 10^{+159}:\\ \;\;\;\;x + z \cdot \left(b \cdot a\right)\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 8
Error9.6
Cost972
\[\begin{array}{l} t_1 := y \cdot z + \left(x + t \cdot a\right)\\ t_2 := x + a \cdot \left(t + b \cdot z\right)\\ \mathbf{if}\;a \leq -2.7 \cdot 10^{+50}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;a \leq 2.75 \cdot 10^{-67}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;a \leq 3.7 \cdot 10^{+65}:\\ \;\;\;\;t_2\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 9
Error2.7
Cost832
\[z \cdot \left(y + b \cdot a\right) + \left(x + t \cdot a\right) \]
Alternative 10
Error25.4
Cost716
\[\begin{array}{l} t_1 := x + t \cdot a\\ \mathbf{if}\;z \leq -5 \cdot 10^{+41}:\\ \;\;\;\;y \cdot z\\ \mathbf{elif}\;z \leq 1.05 \cdot 10^{-7}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq 2.06 \cdot 10^{+37}:\\ \;\;\;\;y \cdot z\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 11
Error19.2
Cost584
\[\begin{array}{l} t_1 := x + y \cdot z\\ \mathbf{if}\;z \leq -4 \cdot 10^{-97}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq 5.2 \cdot 10^{-34}:\\ \;\;\;\;x + t \cdot a\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 12
Error19.6
Cost584
\[\begin{array}{l} \mathbf{if}\;z \leq -1950000:\\ \;\;\;\;z \cdot \left(y + b \cdot a\right)\\ \mathbf{elif}\;z \leq 4.5 \cdot 10^{-34}:\\ \;\;\;\;x + t \cdot a\\ \mathbf{else}:\\ \;\;\;\;x + y \cdot z\\ \end{array} \]
Alternative 13
Error32.7
Cost456
\[\begin{array}{l} \mathbf{if}\;x \leq -1.38 \cdot 10^{-17}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq 5.5 \cdot 10^{-18}:\\ \;\;\;\;t \cdot a\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 14
Error39.7
Cost64
\[x \]

Error

Reproduce

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