?

Average Error: 2.0 → 0.7
Time: 18.7s
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 -5 \cdot 10^{+43}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;b \leq 10^{-153}:\\ \;\;\;\;t_1 + a \cdot \left(z \cdot b + t\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 -5e+43) t_2 (if (<= b 1e-153) (+ t_1 (* a (+ (* z b) t))) 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 <= -5e+43) {
		tmp = t_2;
	} else if (b <= 1e-153) {
		tmp = t_1 + (a * ((z * b) + t));
	} 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 <= (-5d+43)) then
        tmp = t_2
    else if (b <= 1d-153) then
        tmp = t_1 + (a * ((z * b) + t))
    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 <= -5e+43) {
		tmp = t_2;
	} else if (b <= 1e-153) {
		tmp = t_1 + (a * ((z * b) + t));
	} 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 <= -5e+43:
		tmp = t_2
	elif b <= 1e-153:
		tmp = t_1 + (a * ((z * b) + t))
	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 <= -5e+43)
		tmp = t_2;
	elseif (b <= 1e-153)
		tmp = Float64(t_1 + Float64(a * Float64(Float64(z * b) + t)));
	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 <= -5e+43)
		tmp = t_2;
	elseif (b <= 1e-153)
		tmp = t_1 + (a * ((z * b) + t));
	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, -5e+43], t$95$2, If[LessEqual[b, 1e-153], N[(t$95$1 + N[(a * N[(N[(z * b), $MachinePrecision] + t), $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 -5 \cdot 10^{+43}:\\
\;\;\;\;t_2\\

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

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


\end{array}

Error?

Try it out?

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original2.0
Target0.3
Herbie0.7
\[\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 < -5.0000000000000004e43 or 1.00000000000000004e-153 < b

    1. Initial program 1.2

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

    if -5.0000000000000004e43 < b < 1.00000000000000004e-153

    1. Initial program 3.0

      \[\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(z \cdot b + t\right)} \]
      Proof

      [Start]3.0

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

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

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

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

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

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

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

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

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

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

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

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

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

      rational.json-simplify-51 [=>]0.1

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \leq -5 \cdot 10^{+43}:\\ \;\;\;\;\left(\left(x + y \cdot z\right) + t \cdot a\right) + \left(a \cdot z\right) \cdot b\\ \mathbf{elif}\;b \leq 10^{-153}:\\ \;\;\;\;\left(x + y \cdot z\right) + a \cdot \left(z \cdot b + t\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
Error25.7
Cost1112
\[\begin{array}{l} t_1 := t \cdot a + x\\ \mathbf{if}\;x \leq -1.04 \cdot 10^{-75}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq -2.12 \cdot 10^{-128}:\\ \;\;\;\;z \cdot y\\ \mathbf{elif}\;x \leq -1.05 \cdot 10^{-188}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq -2.05 \cdot 10^{-274}:\\ \;\;\;\;z \cdot y\\ \mathbf{elif}\;x \leq 1.5 \cdot 10^{-260}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq 6 \cdot 10^{-136}:\\ \;\;\;\;z \cdot y\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 2
Error21.4
Cost980
\[\begin{array}{l} t_1 := t \cdot a + x\\ t_2 := z \cdot y + x\\ \mathbf{if}\;y \leq -8.5 \cdot 10^{+30}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;y \leq -1.56 \cdot 10^{-43}:\\ \;\;\;\;z \cdot \left(a \cdot b + y\right)\\ \mathbf{elif}\;y \leq -4.5 \cdot 10^{-216}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq 3.3 \cdot 10^{-209}:\\ \;\;\;\;x + b \cdot \left(a \cdot z\right)\\ \mathbf{elif}\;y \leq 0.86:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;t_2\\ \end{array} \]
Alternative 3
Error2.2
Cost964
\[\begin{array}{l} \mathbf{if}\;z \leq 3.8 \cdot 10^{+85}:\\ \;\;\;\;\left(x + y \cdot z\right) + a \cdot \left(z \cdot b + t\right)\\ \mathbf{else}:\\ \;\;\;\;x + z \cdot \left(y + b \cdot a\right)\\ \end{array} \]
Alternative 4
Error33.2
Cost852
\[\begin{array}{l} \mathbf{if}\;x \leq -2.3 \cdot 10^{+72}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq -3.9 \cdot 10^{-45}:\\ \;\;\;\;a \cdot t\\ \mathbf{elif}\;x \leq -9.5 \cdot 10^{-125}:\\ \;\;\;\;z \cdot y\\ \mathbf{elif}\;x \leq -1.2 \cdot 10^{-188}:\\ \;\;\;\;a \cdot t\\ \mathbf{elif}\;x \leq 8.2 \cdot 10^{+80}:\\ \;\;\;\;z \cdot y\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 5
Error20.7
Cost848
\[\begin{array}{l} t_1 := z \cdot y + x\\ \mathbf{if}\;y \leq -8.5 \cdot 10^{+30}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq -3.7 \cdot 10^{-22}:\\ \;\;\;\;z \cdot \left(a \cdot b\right)\\ \mathbf{elif}\;y \leq -7.5 \cdot 10^{-38}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq 21.5:\\ \;\;\;\;t \cdot a + x\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 6
Error19.5
Cost844
\[\begin{array}{l} t_1 := z \cdot y + x\\ \mathbf{if}\;z \leq -1.12 \cdot 10^{-38}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq 5.8 \cdot 10^{-128}:\\ \;\;\;\;t \cdot a + x\\ \mathbf{elif}\;z \leq 10^{+119}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;z \cdot \left(a \cdot b + y\right)\\ \end{array} \]
Alternative 7
Error12.7
Cost840
\[\begin{array}{l} t_1 := x + z \cdot \left(y + b \cdot a\right)\\ \mathbf{if}\;z \leq -3.55 \cdot 10^{-56}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq 2.2 \cdot 10^{-128}:\\ \;\;\;\;t \cdot a + x\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 8
Error8.0
Cost840
\[\begin{array}{l} t_1 := x + z \cdot \left(y + b \cdot a\right)\\ \mathbf{if}\;z \leq -3.5 \cdot 10^{+30}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq 4400000000000:\\ \;\;\;\;\left(x + y \cdot z\right) + t \cdot a\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 9
Error33.0
Cost456
\[\begin{array}{l} \mathbf{if}\;x \leq -9.8 \cdot 10^{+70}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq 5 \cdot 10^{-42}:\\ \;\;\;\;a \cdot t\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 10
Error39.5
Cost64
\[x \]

Error

Reproduce?

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