?

Average Error: 2.2 → 0.3
Time: 10.3s
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\\ t_2 := \left(t_1 + t \cdot a\right) + \left(a \cdot z\right) \cdot b\\ \mathbf{if}\;b \leq -1 \cdot 10^{-40}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;b \leq 5 \cdot 10^{+70}:\\ \;\;\;\;t_1 + a \cdot \left(t + z \cdot b\right)\\ \mathbf{else}:\\ \;\;\;\;t_2\\ \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))) (t_2 (+ (+ t_1 (* t a)) (* (* a z) b))))
   (if (<= b -1e-40) t_2 (if (<= b 5e+70) (+ t_1 (* a (+ t (* z b)))) t_2))))
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 t_2 = (t_1 + (t * a)) + ((a * z) * b);
	double tmp;
	if (b <= -1e-40) {
		tmp = t_2;
	} else if (b <= 5e+70) {
		tmp = t_1 + (a * (t + (z * b)));
	} else {
		tmp = t_2;
	}
	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) :: t_2
    real(8) :: tmp
    t_1 = x + (y * z)
    t_2 = (t_1 + (t * a)) + ((a * z) * b)
    if (b <= (-1d-40)) then
        tmp = t_2
    else if (b <= 5d+70) then
        tmp = t_1 + (a * (t + (z * b)))
    else
        tmp = t_2
    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 t_2 = (t_1 + (t * a)) + ((a * z) * b);
	double tmp;
	if (b <= -1e-40) {
		tmp = t_2;
	} else if (b <= 5e+70) {
		tmp = t_1 + (a * (t + (z * b)));
	} else {
		tmp = t_2;
	}
	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)
	t_2 = (t_1 + (t * a)) + ((a * z) * b)
	tmp = 0
	if b <= -1e-40:
		tmp = t_2
	elif b <= 5e+70:
		tmp = t_1 + (a * (t + (z * b)))
	else:
		tmp = t_2
	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))
	t_2 = Float64(Float64(t_1 + Float64(t * a)) + Float64(Float64(a * z) * b))
	tmp = 0.0
	if (b <= -1e-40)
		tmp = t_2;
	elseif (b <= 5e+70)
		tmp = Float64(t_1 + Float64(a * Float64(t + Float64(z * b))));
	else
		tmp = t_2;
	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);
	t_2 = (t_1 + (t * a)) + ((a * z) * b);
	tmp = 0.0;
	if (b <= -1e-40)
		tmp = t_2;
	elseif (b <= 5e+70)
		tmp = t_1 + (a * (t + (z * b)));
	else
		tmp = t_2;
	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]}, Block[{t$95$2 = N[(N[(t$95$1 + N[(t * a), $MachinePrecision]), $MachinePrecision] + N[(N[(a * z), $MachinePrecision] * b), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[b, -1e-40], t$95$2, If[LessEqual[b, 5e+70], N[(t$95$1 + N[(a * N[(t + N[(z * b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], t$95$2]]]]
\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\\
t_2 := \left(t_1 + t \cdot a\right) + \left(a \cdot z\right) \cdot b\\
\mathbf{if}\;b \leq -1 \cdot 10^{-40}:\\
\;\;\;\;t_2\\

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

\mathbf{else}:\\
\;\;\;\;t_2\\


\end{array}

Error?

Try it out?

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original2.2
Target0.3
Herbie0.3
\[\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 b < -9.9999999999999993e-41 or 5.0000000000000002e70 < b

    1. Initial program 0.6

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

    if -9.9999999999999993e-41 < b < 5.0000000000000002e70

    1. Initial program 3.4

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

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

      [Start]3.4

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

      rational_best_oopsla_all_46_json_45_simplify-35 [=>]3.4

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

      rational_best_oopsla_all_46_json_45_simplify-82 [=>]3.4

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

      rational_best_oopsla_all_46_json_45_simplify-35 [=>]3.4

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

      rational_best_oopsla_all_46_json_45_simplify-74 [=>]3.4

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

      rational_best_oopsla_all_46_json_45_simplify-7 [=>]0.1

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

      rational_best_oopsla_all_46_json_45_simplify-23 [=>]0.1

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

      rational_best_oopsla_all_46_json_45_simplify-74 [=>]0.1

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

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

Alternatives

Alternative 1
Error20.5
Cost1372
\[\begin{array}{l} t_1 := z \cdot y + x\\ t_2 := t \cdot a + x\\ t_3 := z \cdot \left(a \cdot b + y\right)\\ \mathbf{if}\;z \leq -1.15 \cdot 10^{+212}:\\ \;\;\;\;t_3\\ \mathbf{elif}\;z \leq -1.35 \cdot 10^{-150}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq 1.9 \cdot 10^{-31}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;z \leq 8 \cdot 10^{+20}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq 2.3 \cdot 10^{+123}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;z \leq 2.15 \cdot 10^{+171}:\\ \;\;\;\;t_3\\ \mathbf{elif}\;z \leq 1.12 \cdot 10^{+251}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;t_3\\ \end{array} \]
Alternative 2
Error15.5
Cost1372
\[\begin{array}{l} t_1 := z \cdot y + x\\ t_2 := \left(t + b \cdot z\right) \cdot a + x\\ t_3 := z \cdot \left(a \cdot b + y\right)\\ \mathbf{if}\;z \leq -4.4 \cdot 10^{+211}:\\ \;\;\;\;t_3\\ \mathbf{elif}\;z \leq -9 \cdot 10^{-64}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq 7.2 \cdot 10^{-8}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;z \leq 1.4 \cdot 10^{+20}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq 2 \cdot 10^{+126}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;z \leq 4 \cdot 10^{+171}:\\ \;\;\;\;t_3\\ \mathbf{elif}\;z \leq 1.25 \cdot 10^{+255}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;t_3\\ \end{array} \]
Alternative 3
Error7.9
Cost968
\[\begin{array}{l} t_1 := \left(x + y \cdot z\right) + t \cdot a\\ \mathbf{if}\;y \leq -6.2 \cdot 10^{-71}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq 2.9 \cdot 10^{-24}:\\ \;\;\;\;\left(a \cdot t + x\right) + a \cdot \left(z \cdot b\right)\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 4
Error7.7
Cost968
\[\begin{array}{l} t_1 := \left(x + y \cdot z\right) + t \cdot a\\ \mathbf{if}\;y \leq -5.8 \cdot 10^{-71}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq 2.5 \cdot 10^{-24}:\\ \;\;\;\;\left(t \cdot a + b \cdot \left(z \cdot a\right)\right) + x\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 5
Error2.8
Cost964
\[\begin{array}{l} t_1 := x + y \cdot z\\ \mathbf{if}\;z \leq 2 \cdot 10^{+132}:\\ \;\;\;\;t_1 + a \cdot \left(t + z \cdot b\right)\\ \mathbf{else}:\\ \;\;\;\;t_1 + b \cdot \left(z \cdot a\right)\\ \end{array} \]
Alternative 6
Error7.9
Cost840
\[\begin{array}{l} t_1 := \left(x + y \cdot z\right) + t \cdot a\\ \mathbf{if}\;y \leq -8.5 \cdot 10^{-71}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq 2.9 \cdot 10^{-24}:\\ \;\;\;\;\left(t + b \cdot z\right) \cdot a + x\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 7
Error33.7
Cost720
\[\begin{array}{l} \mathbf{if}\;x \leq -1.55 \cdot 10^{+62}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq -1.35 \cdot 10^{-131}:\\ \;\;\;\;a \cdot t\\ \mathbf{elif}\;x \leq 3.6 \cdot 10^{-293}:\\ \;\;\;\;z \cdot y\\ \mathbf{elif}\;x \leq 1.85 \cdot 10^{+53}:\\ \;\;\;\;a \cdot t\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 8
Error26.2
Cost584
\[\begin{array}{l} \mathbf{if}\;y \leq -1.85 \cdot 10^{+227}:\\ \;\;\;\;z \cdot y\\ \mathbf{elif}\;y \leq 9 \cdot 10^{+29}:\\ \;\;\;\;t \cdot a + x\\ \mathbf{else}:\\ \;\;\;\;z \cdot y\\ \end{array} \]
Alternative 9
Error20.5
Cost584
\[\begin{array}{l} t_1 := z \cdot y + x\\ \mathbf{if}\;y \leq -7.8 \cdot 10^{+68}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq 3.5 \cdot 10^{+29}:\\ \;\;\;\;t \cdot a + x\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 10
Error33.8
Cost456
\[\begin{array}{l} \mathbf{if}\;x \leq -9.5 \cdot 10^{+62}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq 1.95 \cdot 10^{+55}:\\ \;\;\;\;a \cdot t\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 11
Error39.9
Cost64
\[x \]

Error

Reproduce?

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