?

Average Error: 7.4 → 4.0
Time: 13.1s
Precision: binary64
Cost: 2120

?

\[ \begin{array}{c}[x, y] = \mathsf{sort}([x, y])\\ [z, t] = \mathsf{sort}([z, t])\\ \end{array} \]
\[\frac{x \cdot y - \left(z \cdot 9\right) \cdot t}{a \cdot 2} \]
\[\begin{array}{l} t_1 := x \cdot y - \left(z \cdot 9\right) \cdot t\\ \mathbf{if}\;t_1 \leq -\infty:\\ \;\;\;\;-4.5 \cdot \left(t \cdot \frac{z}{a}\right)\\ \mathbf{elif}\;t_1 \leq 4 \cdot 10^{+307}:\\ \;\;\;\;\frac{t_1}{a \cdot 2}\\ \mathbf{else}:\\ \;\;\;\;x \cdot \frac{-0.5}{\frac{-a}{y}}\\ \end{array} \]
(FPCore (x y z t a)
 :precision binary64
 (/ (- (* x y) (* (* z 9.0) t)) (* a 2.0)))
(FPCore (x y z t a)
 :precision binary64
 (let* ((t_1 (- (* x y) (* (* z 9.0) t))))
   (if (<= t_1 (- INFINITY))
     (* -4.5 (* t (/ z a)))
     (if (<= t_1 4e+307) (/ t_1 (* a 2.0)) (* x (/ -0.5 (/ (- a) y)))))))
double code(double x, double y, double z, double t, double a) {
	return ((x * y) - ((z * 9.0) * t)) / (a * 2.0);
}
double code(double x, double y, double z, double t, double a) {
	double t_1 = (x * y) - ((z * 9.0) * t);
	double tmp;
	if (t_1 <= -((double) INFINITY)) {
		tmp = -4.5 * (t * (z / a));
	} else if (t_1 <= 4e+307) {
		tmp = t_1 / (a * 2.0);
	} else {
		tmp = x * (-0.5 / (-a / y));
	}
	return tmp;
}
public static double code(double x, double y, double z, double t, double a) {
	return ((x * y) - ((z * 9.0) * t)) / (a * 2.0);
}
public static double code(double x, double y, double z, double t, double a) {
	double t_1 = (x * y) - ((z * 9.0) * t);
	double tmp;
	if (t_1 <= -Double.POSITIVE_INFINITY) {
		tmp = -4.5 * (t * (z / a));
	} else if (t_1 <= 4e+307) {
		tmp = t_1 / (a * 2.0);
	} else {
		tmp = x * (-0.5 / (-a / y));
	}
	return tmp;
}
def code(x, y, z, t, a):
	return ((x * y) - ((z * 9.0) * t)) / (a * 2.0)
def code(x, y, z, t, a):
	t_1 = (x * y) - ((z * 9.0) * t)
	tmp = 0
	if t_1 <= -math.inf:
		tmp = -4.5 * (t * (z / a))
	elif t_1 <= 4e+307:
		tmp = t_1 / (a * 2.0)
	else:
		tmp = x * (-0.5 / (-a / y))
	return tmp
function code(x, y, z, t, a)
	return Float64(Float64(Float64(x * y) - Float64(Float64(z * 9.0) * t)) / Float64(a * 2.0))
end
function code(x, y, z, t, a)
	t_1 = Float64(Float64(x * y) - Float64(Float64(z * 9.0) * t))
	tmp = 0.0
	if (t_1 <= Float64(-Inf))
		tmp = Float64(-4.5 * Float64(t * Float64(z / a)));
	elseif (t_1 <= 4e+307)
		tmp = Float64(t_1 / Float64(a * 2.0));
	else
		tmp = Float64(x * Float64(-0.5 / Float64(Float64(-a) / y)));
	end
	return tmp
end
function tmp = code(x, y, z, t, a)
	tmp = ((x * y) - ((z * 9.0) * t)) / (a * 2.0);
end
function tmp_2 = code(x, y, z, t, a)
	t_1 = (x * y) - ((z * 9.0) * t);
	tmp = 0.0;
	if (t_1 <= -Inf)
		tmp = -4.5 * (t * (z / a));
	elseif (t_1 <= 4e+307)
		tmp = t_1 / (a * 2.0);
	else
		tmp = x * (-0.5 / (-a / y));
	end
	tmp_2 = tmp;
end
code[x_, y_, z_, t_, a_] := N[(N[(N[(x * y), $MachinePrecision] - N[(N[(z * 9.0), $MachinePrecision] * t), $MachinePrecision]), $MachinePrecision] / N[(a * 2.0), $MachinePrecision]), $MachinePrecision]
code[x_, y_, z_, t_, a_] := Block[{t$95$1 = N[(N[(x * y), $MachinePrecision] - N[(N[(z * 9.0), $MachinePrecision] * t), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$1, (-Infinity)], N[(-4.5 * N[(t * N[(z / a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$1, 4e+307], N[(t$95$1 / N[(a * 2.0), $MachinePrecision]), $MachinePrecision], N[(x * N[(-0.5 / N[((-a) / y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]
\frac{x \cdot y - \left(z \cdot 9\right) \cdot t}{a \cdot 2}
\begin{array}{l}
t_1 := x \cdot y - \left(z \cdot 9\right) \cdot t\\
\mathbf{if}\;t_1 \leq -\infty:\\
\;\;\;\;-4.5 \cdot \left(t \cdot \frac{z}{a}\right)\\

\mathbf{elif}\;t_1 \leq 4 \cdot 10^{+307}:\\
\;\;\;\;\frac{t_1}{a \cdot 2}\\

\mathbf{else}:\\
\;\;\;\;x \cdot \frac{-0.5}{\frac{-a}{y}}\\


\end{array}

Error?

Try it out?

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original7.4
Target5.4
Herbie4.0
\[\begin{array}{l} \mathbf{if}\;a < -2.090464557976709 \cdot 10^{+86}:\\ \;\;\;\;0.5 \cdot \frac{y \cdot x}{a} - 4.5 \cdot \frac{t}{\frac{a}{z}}\\ \mathbf{elif}\;a < 2.144030707833976 \cdot 10^{+99}:\\ \;\;\;\;\frac{x \cdot y - z \cdot \left(9 \cdot t\right)}{a \cdot 2}\\ \mathbf{else}:\\ \;\;\;\;\frac{y}{a} \cdot \left(x \cdot 0.5\right) - \frac{t}{a} \cdot \left(z \cdot 4.5\right)\\ \end{array} \]

Derivation?

  1. Split input into 3 regimes
  2. if (-.f64 (*.f64 x y) (*.f64 (*.f64 z 9) t)) < -inf.0

    1. Initial program 64.0

      \[\frac{x \cdot y - \left(z \cdot 9\right) \cdot t}{a \cdot 2} \]
    2. Simplified63.7

      \[\leadsto \color{blue}{\frac{x \cdot y - z \cdot \left(9 \cdot t\right)}{a \cdot 2}} \]
      Proof

      [Start]64.0

      \[ \frac{x \cdot y - \left(z \cdot 9\right) \cdot t}{a \cdot 2} \]

      associate-*l* [=>]63.7

      \[ \frac{x \cdot y - \color{blue}{z \cdot \left(9 \cdot t\right)}}{a \cdot 2} \]
    3. Taylor expanded in x around 0 63.0

      \[\leadsto \color{blue}{-4.5 \cdot \frac{t \cdot z}{a}} \]
    4. Simplified30.6

      \[\leadsto \color{blue}{-4.5 \cdot \frac{z}{\frac{a}{t}}} \]
      Proof

      [Start]63.0

      \[ -4.5 \cdot \frac{t \cdot z}{a} \]

      *-commutative [=>]63.0

      \[ -4.5 \cdot \frac{\color{blue}{z \cdot t}}{a} \]

      associate-/l* [=>]30.6

      \[ -4.5 \cdot \color{blue}{\frac{z}{\frac{a}{t}}} \]
    5. Applied egg-rr30.8

      \[\leadsto -4.5 \cdot \color{blue}{\left(\frac{z}{a} \cdot t\right)} \]

    if -inf.0 < (-.f64 (*.f64 x y) (*.f64 (*.f64 z 9) t)) < 3.99999999999999994e307

    1. Initial program 0.8

      \[\frac{x \cdot y - \left(z \cdot 9\right) \cdot t}{a \cdot 2} \]

    if 3.99999999999999994e307 < (-.f64 (*.f64 x y) (*.f64 (*.f64 z 9) t))

    1. Initial program 63.7

      \[\frac{x \cdot y - \left(z \cdot 9\right) \cdot t}{a \cdot 2} \]
    2. Taylor expanded in x around inf 63.2

      \[\leadsto \color{blue}{0.5 \cdot \frac{y \cdot x}{a}} \]
    3. Simplified63.2

      \[\leadsto \color{blue}{\frac{0.5}{\frac{a}{y \cdot x}}} \]
      Proof

      [Start]63.2

      \[ 0.5 \cdot \frac{y \cdot x}{a} \]

      *-commutative [<=]63.2

      \[ 0.5 \cdot \frac{\color{blue}{x \cdot y}}{a} \]

      associate-*r/ [=>]63.2

      \[ \color{blue}{\frac{0.5 \cdot \left(x \cdot y\right)}{a}} \]

      associate-/l* [=>]63.2

      \[ \color{blue}{\frac{0.5}{\frac{a}{x \cdot y}}} \]

      *-commutative [=>]63.2

      \[ \frac{0.5}{\frac{a}{\color{blue}{y \cdot x}}} \]
    4. Applied egg-rr32.3

      \[\leadsto \color{blue}{\frac{-0.5}{-\frac{a}{y}} \cdot x} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification4.0

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \cdot y - \left(z \cdot 9\right) \cdot t \leq -\infty:\\ \;\;\;\;-4.5 \cdot \left(t \cdot \frac{z}{a}\right)\\ \mathbf{elif}\;x \cdot y - \left(z \cdot 9\right) \cdot t \leq 4 \cdot 10^{+307}:\\ \;\;\;\;\frac{x \cdot y - \left(z \cdot 9\right) \cdot t}{a \cdot 2}\\ \mathbf{else}:\\ \;\;\;\;x \cdot \frac{-0.5}{\frac{-a}{y}}\\ \end{array} \]

Alternatives

Alternative 1
Error4.2
Cost1352
\[\begin{array}{l} \mathbf{if}\;x \cdot y \leq -\infty:\\ \;\;\;\;0.5 \cdot \frac{x}{\frac{a}{y}}\\ \mathbf{elif}\;x \cdot y \leq 2 \cdot 10^{+248}:\\ \;\;\;\;\frac{x \cdot y + z \cdot \left(t \cdot -9\right)}{a \cdot 2}\\ \mathbf{else}:\\ \;\;\;\;x \cdot \frac{-0.5}{\frac{-a}{y}}\\ \end{array} \]
Alternative 2
Error24.0
Cost977
\[\begin{array}{l} t_1 := 0.5 \cdot \left(x \cdot \frac{y}{a}\right)\\ \mathbf{if}\;x \leq -1.6 \cdot 10^{+73}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq -10000:\\ \;\;\;\;-4.5 \cdot \frac{z}{\frac{a}{t}}\\ \mathbf{elif}\;x \leq -8.8 \cdot 10^{-16} \lor \neg \left(x \leq 4.8 \cdot 10^{-41}\right):\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;-4.5 \cdot \frac{z \cdot t}{a}\\ \end{array} \]
Alternative 3
Error24.2
Cost977
\[\begin{array}{l} \mathbf{if}\;x \leq -1.6 \cdot 10^{+73}:\\ \;\;\;\;0.5 \cdot \frac{x}{\frac{a}{y}}\\ \mathbf{elif}\;x \leq -0.088:\\ \;\;\;\;-4.5 \cdot \frac{z}{\frac{a}{t}}\\ \mathbf{elif}\;x \leq -3.2 \cdot 10^{-15} \lor \neg \left(x \leq 4.5 \cdot 10^{-42}\right):\\ \;\;\;\;0.5 \cdot \left(x \cdot \frac{y}{a}\right)\\ \mathbf{else}:\\ \;\;\;\;-4.5 \cdot \frac{z \cdot t}{a}\\ \end{array} \]
Alternative 4
Error23.7
Cost976
\[\begin{array}{l} t_1 := 0.5 \cdot \frac{y}{\frac{a}{x}}\\ \mathbf{if}\;x \leq -5 \cdot 10^{+61}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq -126:\\ \;\;\;\;-4.5 \cdot \frac{z}{\frac{a}{t}}\\ \mathbf{elif}\;x \leq -2.45 \cdot 10^{-14}:\\ \;\;\;\;0.5 \cdot \left(x \cdot \frac{y}{a}\right)\\ \mathbf{elif}\;x \leq 7.5 \cdot 10^{-54}:\\ \;\;\;\;-4.5 \cdot \frac{z \cdot t}{a}\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 5
Error24.0
Cost976
\[\begin{array}{l} t_1 := 0.5 \cdot \frac{y}{\frac{a}{x}}\\ \mathbf{if}\;x \leq -9.8 \cdot 10^{+61}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq -5300:\\ \;\;\;\;-4.5 \cdot \frac{z}{\frac{a}{t}}\\ \mathbf{elif}\;x \leq -1.65 \cdot 10^{-15}:\\ \;\;\;\;0.5 \cdot \left(x \cdot \frac{y}{a}\right)\\ \mathbf{elif}\;x \leq 3.5 \cdot 10^{-42}:\\ \;\;\;\;\frac{-4.5}{\frac{a}{z \cdot t}}\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 6
Error23.7
Cost976
\[\begin{array}{l} t_1 := 0.5 \cdot \frac{y}{\frac{a}{x}}\\ \mathbf{if}\;x \leq -1.08 \cdot 10^{+63}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq -1.3:\\ \;\;\;\;-4.5 \cdot \frac{z}{\frac{a}{t}}\\ \mathbf{elif}\;x \leq -5 \cdot 10^{-15}:\\ \;\;\;\;0.5 \cdot \left(x \cdot \frac{y}{a}\right)\\ \mathbf{elif}\;x \leq 6.2 \cdot 10^{-54}:\\ \;\;\;\;\frac{z \cdot \left(t \cdot -4.5\right)}{a}\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 7
Error32.5
Cost713
\[\begin{array}{l} \mathbf{if}\;t \leq -2.75 \cdot 10^{-195} \lor \neg \left(t \leq 1.7 \cdot 10^{+48}\right):\\ \;\;\;\;-4.5 \cdot \left(t \cdot \frac{z}{a}\right)\\ \mathbf{else}:\\ \;\;\;\;-4.5 \cdot \left(z \cdot \frac{t}{a}\right)\\ \end{array} \]
Alternative 8
Error32.7
Cost713
\[\begin{array}{l} \mathbf{if}\;t \leq -8 \cdot 10^{-195} \lor \neg \left(t \leq 2.8 \cdot 10^{+48}\right):\\ \;\;\;\;-4.5 \cdot \left(t \cdot \frac{z}{a}\right)\\ \mathbf{else}:\\ \;\;\;\;-4.5 \cdot \frac{z}{\frac{a}{t}}\\ \end{array} \]
Alternative 9
Error32.5
Cost580
\[\begin{array}{l} \mathbf{if}\;t \leq -1 \cdot 10^{-165}:\\ \;\;\;\;-4.5 \cdot \left(t \cdot \frac{z}{a}\right)\\ \mathbf{else}:\\ \;\;\;\;-4.5 \cdot \frac{z \cdot t}{a}\\ \end{array} \]
Alternative 10
Error32.9
Cost448
\[-4.5 \cdot \left(z \cdot \frac{t}{a}\right) \]

Error

Reproduce?

herbie shell --seed 2023018 
(FPCore (x y z t a)
  :name "Diagrams.Solve.Polynomial:cubForm  from diagrams-solve-0.1, I"
  :precision binary64

  :herbie-target
  (if (< a -2.090464557976709e+86) (- (* 0.5 (/ (* y x) a)) (* 4.5 (/ t (/ a z)))) (if (< a 2.144030707833976e+99) (/ (- (* x y) (* z (* 9.0 t))) (* a 2.0)) (- (* (/ y a) (* x 0.5)) (* (/ t a) (* z 4.5)))))

  (/ (- (* x y) (* (* z 9.0) t)) (* a 2.0)))