?

Average Error: 2.1 → 1.0
Time: 17.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 := t_1 + a \cdot \left(z \cdot b + t\right)\\ \mathbf{if}\;a \leq -1 \cdot 10^{-193}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;a \leq 10^{-114}:\\ \;\;\;\;\left(t_1 + t \cdot a\right) + \left(a \cdot z\right) \cdot b\\ \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 (* a (+ (* z b) t)))))
   (if (<= a -1e-193)
     t_2
     (if (<= a 1e-114) (+ (+ t_1 (* t a)) (* (* a 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 + (a * ((z * b) + t));
	double tmp;
	if (a <= -1e-193) {
		tmp = t_2;
	} else if (a <= 1e-114) {
		tmp = (t_1 + (t * a)) + ((a * 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 + (a * ((z * b) + t))
    if (a <= (-1d-193)) then
        tmp = t_2
    else if (a <= 1d-114) then
        tmp = (t_1 + (t * a)) + ((a * 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 + (a * ((z * b) + t));
	double tmp;
	if (a <= -1e-193) {
		tmp = t_2;
	} else if (a <= 1e-114) {
		tmp = (t_1 + (t * a)) + ((a * 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 + (a * ((z * b) + t))
	tmp = 0
	if a <= -1e-193:
		tmp = t_2
	elif a <= 1e-114:
		tmp = (t_1 + (t * a)) + ((a * 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(t_1 + Float64(a * Float64(Float64(z * b) + t)))
	tmp = 0.0
	if (a <= -1e-193)
		tmp = t_2;
	elseif (a <= 1e-114)
		tmp = Float64(Float64(t_1 + Float64(t * a)) + Float64(Float64(a * 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 + (a * ((z * b) + t));
	tmp = 0.0;
	if (a <= -1e-193)
		tmp = t_2;
	elseif (a <= 1e-114)
		tmp = (t_1 + (t * a)) + ((a * 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[(t$95$1 + N[(a * N[(N[(z * b), $MachinePrecision] + t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[a, -1e-193], t$95$2, If[LessEqual[a, 1e-114], N[(N[(t$95$1 + N[(t * a), $MachinePrecision]), $MachinePrecision] + N[(N[(a * z), $MachinePrecision] * b), $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 := t_1 + a \cdot \left(z \cdot b + t\right)\\
\mathbf{if}\;a \leq -1 \cdot 10^{-193}:\\
\;\;\;\;t_2\\

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

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


\end{array}

Error?

Try it out?

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original2.1
Target0.4
Herbie1.0
\[\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 a < -1e-193 or 1.0000000000000001e-114 < a

    1. Initial program 2.9

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

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

      [Start]2.9

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -1e-193 < a < 1.0000000000000001e-114

    1. Initial program 0.5

      \[\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 simplification1.0

    \[\leadsto \begin{array}{l} \mathbf{if}\;a \leq -1 \cdot 10^{-193}:\\ \;\;\;\;\left(x + y \cdot z\right) + a \cdot \left(z \cdot b + t\right)\\ \mathbf{elif}\;a \leq 10^{-114}:\\ \;\;\;\;\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) + a \cdot \left(z \cdot b + t\right)\\ \end{array} \]

Alternatives

Alternative 1
Error21.6
Cost1244
\[\begin{array}{l} t_1 := t \cdot a + x\\ t_2 := z \cdot y + x\\ \mathbf{if}\;y \leq -1.32 \cdot 10^{+169}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;y \leq -9.8 \cdot 10^{+126}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq -6.2 \cdot 10^{+75}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;y \leq -1.35 \cdot 10^{-14}:\\ \;\;\;\;a \cdot \left(z \cdot b + t\right)\\ \mathbf{elif}\;y \leq 1.9 \cdot 10^{-127}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq 5.6 \cdot 10^{-33}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;y \leq 3.8 \cdot 10^{+27}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;t_2\\ \end{array} \]
Alternative 2
Error23.8
Cost1240
\[\begin{array}{l} t_1 := z \cdot \left(a \cdot b + y\right)\\ t_2 := t \cdot a + x\\ \mathbf{if}\;x \leq -8.2 \cdot 10^{+83}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;x \leq -1.85 \cdot 10^{-85}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq -8.5 \cdot 10^{-157}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;x \leq 1.55 \cdot 10^{-301}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq 4.5 \cdot 10^{-160}:\\ \;\;\;\;a \cdot \left(z \cdot b + t\right)\\ \mathbf{elif}\;x \leq 2.9 \cdot 10^{-58}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;t_2\\ \end{array} \]
Alternative 3
Error20.1
Cost1240
\[\begin{array}{l} t_1 := t \cdot a + x\\ t_2 := z \cdot y + a \cdot t\\ \mathbf{if}\;x \leq -4 \cdot 10^{+83}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq -2.7 \cdot 10^{-41}:\\ \;\;\;\;z \cdot \left(a \cdot b + y\right)\\ \mathbf{elif}\;x \leq 3.25 \cdot 10^{-40}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;x \leq 4.3 \cdot 10^{-11}:\\ \;\;\;\;z \cdot y + x\\ \mathbf{elif}\;x \leq 1.22 \cdot 10^{+79}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;x \leq 3.6 \cdot 10^{+90}:\\ \;\;\;\;x + \left(z \cdot a\right) \cdot b\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 4
Error27.0
Cost1112
\[\begin{array}{l} t_1 := t \cdot a + x\\ \mathbf{if}\;x \leq -11000000:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq -3.7 \cdot 10^{-70}:\\ \;\;\;\;z \cdot y\\ \mathbf{elif}\;x \leq -9.5 \cdot 10^{-180}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq 4.5 \cdot 10^{-296}:\\ \;\;\;\;z \cdot y\\ \mathbf{elif}\;x \leq 3.9 \cdot 10^{-160}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq 1.4 \cdot 10^{-58}:\\ \;\;\;\;z \cdot y\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 5
Error33.3
Cost984
\[\begin{array}{l} \mathbf{if}\;x \leq -1.2 \cdot 10^{+63}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq -1.6 \cdot 10^{-69}:\\ \;\;\;\;z \cdot y\\ \mathbf{elif}\;x \leq -3.2 \cdot 10^{-170}:\\ \;\;\;\;a \cdot t\\ \mathbf{elif}\;x \leq 3.2 \cdot 10^{-296}:\\ \;\;\;\;z \cdot y\\ \mathbf{elif}\;x \leq 5.2 \cdot 10^{-160}:\\ \;\;\;\;a \cdot t\\ \mathbf{elif}\;x \leq 3.2 \cdot 10^{-40}:\\ \;\;\;\;z \cdot y\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 6
Error20.9
Cost848
\[\begin{array}{l} t_1 := t \cdot a + x\\ t_2 := z \cdot y + x\\ \mathbf{if}\;y \leq -1.3 \cdot 10^{+169}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;y \leq 1.22 \cdot 10^{-127}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq 5.3 \cdot 10^{-34}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;y \leq 2.5 \cdot 10^{+23}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;t_2\\ \end{array} \]
Alternative 7
Error2.6
Cost832
\[\left(x + y \cdot z\right) + a \cdot \left(z \cdot b + t\right) \]
Alternative 8
Error11.3
Cost708
\[\begin{array}{l} \mathbf{if}\;b \leq 8.8 \cdot 10^{+157}:\\ \;\;\;\;\left(x + y \cdot z\right) + t \cdot a\\ \mathbf{else}:\\ \;\;\;\;a \cdot t + \left(z \cdot a\right) \cdot b\\ \end{array} \]
Alternative 9
Error32.2
Cost456
\[\begin{array}{l} \mathbf{if}\;x \leq -6 \cdot 10^{+24}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq 1.45 \cdot 10^{-40}:\\ \;\;\;\;a \cdot t\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 10
Error39.6
Cost64
\[x \]

Error

Reproduce?

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