?

Average Error: 2.1 → 2.5
Time: 26.6s
Precision: binary64
Cost: 1092

?

\[\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 -5 \cdot 10^{-166}:\\ \;\;\;\;\left(t_1 + t \cdot a\right) + \left(a \cdot z\right) \cdot b\\ \mathbf{else}:\\ \;\;\;\;t_1 + \left(t \cdot a + a \cdot \left(z \cdot b\right)\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 -5e-166)
     (+ (+ t_1 (* t a)) (* (* a z) b))
     (+ t_1 (+ (* t a) (* a (* z b)))))))
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 <= -5e-166) {
		tmp = (t_1 + (t * a)) + ((a * z) * b);
	} else {
		tmp = t_1 + ((t * a) + (a * (z * b)));
	}
	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 <= (-5d-166)) then
        tmp = (t_1 + (t * a)) + ((a * z) * b)
    else
        tmp = t_1 + ((t * a) + (a * (z * b)))
    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 <= -5e-166) {
		tmp = (t_1 + (t * a)) + ((a * z) * b);
	} else {
		tmp = t_1 + ((t * a) + (a * (z * b)));
	}
	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 <= -5e-166:
		tmp = (t_1 + (t * a)) + ((a * z) * b)
	else:
		tmp = t_1 + ((t * a) + (a * (z * b)))
	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 <= -5e-166)
		tmp = Float64(Float64(t_1 + Float64(t * a)) + Float64(Float64(a * z) * b));
	else
		tmp = Float64(t_1 + Float64(Float64(t * a) + Float64(a * Float64(z * b))));
	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 <= -5e-166)
		tmp = (t_1 + (t * a)) + ((a * z) * b);
	else
		tmp = t_1 + ((t * a) + (a * (z * b)));
	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, -5e-166], N[(N[(t$95$1 + N[(t * a), $MachinePrecision]), $MachinePrecision] + N[(N[(a * z), $MachinePrecision] * b), $MachinePrecision]), $MachinePrecision], N[(t$95$1 + N[(N[(t * a), $MachinePrecision] + N[(a * N[(z * b), $MachinePrecision]), $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 -5 \cdot 10^{-166}:\\
\;\;\;\;\left(t_1 + t \cdot a\right) + \left(a \cdot z\right) \cdot b\\

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


\end{array}

Error?

Try it out?

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original2.1
Target0.3
Herbie2.5
\[\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 z < -5e-166

    1. Initial program 3.0

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

    if -5e-166 < z

    1. Initial program 1.7

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

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

      [Start]1.7

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

      rational.json-simplify-1 [=>]1.7

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

      rational.json-simplify-41 [=>]1.7

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

      rational.json-simplify-2 [=>]1.7

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

      rational.json-simplify-43 [=>]2.2

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

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

Alternatives

Alternative 1
Error18.0
Cost1896
\[\begin{array}{l} t_1 := x + z \cdot \left(y + b \cdot a\right)\\ t_2 := \left(t + b \cdot z\right) \cdot a\\ t_3 := z \cdot y + a \cdot t\\ \mathbf{if}\;x \leq -5.8 \cdot 10^{+176}:\\ \;\;\;\;t \cdot a + x\\ \mathbf{elif}\;x \leq -1.05 \cdot 10^{+49}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq -5.6 \cdot 10^{-111}:\\ \;\;\;\;t_3\\ \mathbf{elif}\;x \leq -1.8 \cdot 10^{-169}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq -7.8 \cdot 10^{-187}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;x \leq 1.35 \cdot 10^{-217}:\\ \;\;\;\;t_3\\ \mathbf{elif}\;x \leq 9.5 \cdot 10^{-103}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq 7 \cdot 10^{-63}:\\ \;\;\;\;t_3\\ \mathbf{elif}\;x \leq 8.6 \cdot 10^{-7}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq 3.4 \cdot 10^{+38}:\\ \;\;\;\;t_2\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 2
Error23.7
Cost1640
\[\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}\;x \leq -1.2 \cdot 10^{+176}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;x \leq -2.35 \cdot 10^{-36}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq -6.6 \cdot 10^{-40}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;x \leq -9.2 \cdot 10^{-154}:\\ \;\;\;\;t_3\\ \mathbf{elif}\;x \leq -2.4 \cdot 10^{-198}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;x \leq -8 \cdot 10^{-253}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq 1.3 \cdot 10^{-183}:\\ \;\;\;\;t_3\\ \mathbf{elif}\;x \leq 4.8 \cdot 10^{-97}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;x \leq 1.5 \cdot 10^{-9}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq 7.8 \cdot 10^{+38}:\\ \;\;\;\;t_2\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 3
Error23.0
Cost1504
\[\begin{array}{l} t_1 := z \cdot y + x\\ t_2 := t \cdot a + x\\ t_3 := \left(t + b \cdot z\right) \cdot a\\ \mathbf{if}\;x \leq -5.2 \cdot 10^{+175}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;x \leq -1.32 \cdot 10^{-36}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq -1 \cdot 10^{-42}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;x \leq -3.4 \cdot 10^{-196}:\\ \;\;\;\;t_3\\ \mathbf{elif}\;x \leq 1.2 \cdot 10^{-183}:\\ \;\;\;\;z \cdot \left(a \cdot b + y\right)\\ \mathbf{elif}\;x \leq 1.76 \cdot 10^{-96}:\\ \;\;\;\;t_3\\ \mathbf{elif}\;x \leq 7.8 \cdot 10^{-7}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq 5.4 \cdot 10^{+38}:\\ \;\;\;\;t_3\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 4
Error20.4
Cost1372
\[\begin{array}{l} t_1 := z \cdot y + x\\ t_2 := z \cdot y + a \cdot t\\ t_3 := t \cdot a + x\\ t_4 := \left(t + b \cdot z\right) \cdot a\\ \mathbf{if}\;x \leq -1.52 \cdot 10^{+175}:\\ \;\;\;\;t_3\\ \mathbf{elif}\;x \leq -9 \cdot 10^{-37}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq -2.25 \cdot 10^{-42}:\\ \;\;\;\;t_3\\ \mathbf{elif}\;x \leq -1.12 \cdot 10^{-149}:\\ \;\;\;\;t_4\\ \mathbf{elif}\;x \leq 9.8 \cdot 10^{-197}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;x \leq 4.2 \cdot 10^{-107}:\\ \;\;\;\;t_4\\ \mathbf{elif}\;x \leq 5.9 \cdot 10^{+38}:\\ \;\;\;\;t_2\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 5
Error8.4
Cost968
\[\begin{array}{l} t_1 := \left(x + y \cdot z\right) + t \cdot a\\ \mathbf{if}\;x \leq -90000:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq 3.95 \cdot 10^{-22}:\\ \;\;\;\;t \cdot a + z \cdot \left(y + b \cdot a\right)\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 6
Error2.7
Cost960
\[\left(x + y \cdot z\right) + \left(t \cdot a + a \cdot \left(z \cdot b\right)\right) \]
Alternative 7
Error33.0
Cost852
\[\begin{array}{l} \mathbf{if}\;x \leq -1.85 \cdot 10^{+32}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq -1.55 \cdot 10^{-193}:\\ \;\;\;\;a \cdot t\\ \mathbf{elif}\;x \leq 7.5 \cdot 10^{-184}:\\ \;\;\;\;z \cdot y\\ \mathbf{elif}\;x \leq 3.1 \cdot 10^{-96}:\\ \;\;\;\;a \cdot t\\ \mathbf{elif}\;x \leq 6.5 \cdot 10^{-22}:\\ \;\;\;\;z \cdot y\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 8
Error33.8
Cost852
\[\begin{array}{l} \mathbf{if}\;x \leq -3.2 \cdot 10^{+36}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq -2.1 \cdot 10^{-194}:\\ \;\;\;\;a \cdot t\\ \mathbf{elif}\;x \leq 1.16 \cdot 10^{-198}:\\ \;\;\;\;z \cdot y\\ \mathbf{elif}\;x \leq 1.8 \cdot 10^{-107}:\\ \;\;\;\;a \cdot \left(z \cdot b\right)\\ \mathbf{elif}\;x \leq 9 \cdot 10^{-21}:\\ \;\;\;\;z \cdot y\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 9
Error8.8
Cost840
\[\begin{array}{l} t_1 := \left(x + y \cdot z\right) + t \cdot a\\ \mathbf{if}\;t \leq -2.6 \cdot 10^{-136}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;t \leq 1.35 \cdot 10^{+58}:\\ \;\;\;\;x + z \cdot \left(y + b \cdot a\right)\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 10
Error2.7
Cost832
\[\left(x + y \cdot z\right) + a \cdot \left(z \cdot b + t\right) \]
Alternative 11
Error20.0
Cost584
\[\begin{array}{l} t_1 := t \cdot a + x\\ \mathbf{if}\;t \leq -2.4 \cdot 10^{+42}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;t \leq 15000:\\ \;\;\;\;z \cdot y + x\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 12
Error33.3
Cost456
\[\begin{array}{l} \mathbf{if}\;x \leq -8.5 \cdot 10^{+42}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq 5.5 \cdot 10^{+38}:\\ \;\;\;\;a \cdot t\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 13
Error25.4
Cost452
\[\begin{array}{l} \mathbf{if}\;z \leq -1.26 \cdot 10^{+69}:\\ \;\;\;\;z \cdot y\\ \mathbf{else}:\\ \;\;\;\;t \cdot a + x\\ \end{array} \]
Alternative 14
Error40.0
Cost64
\[x \]

Error

Reproduce?

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