?

Average Error: 7.8 → 4.7
Time: 13.6s
Precision: binary64
Cost: 2632

?

\[ \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 := \frac{x \cdot y - \left(z \cdot 9\right) \cdot t}{a \cdot 2}\\ \mathbf{if}\;t_1 \leq -\infty:\\ \;\;\;\;-4.5 \cdot \frac{z}{\frac{a}{t}}\\ \mathbf{elif}\;t_1 \leq 5 \cdot 10^{+281}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{y}{a}}{\frac{2}{x}}\\ \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)) (* a 2.0))))
   (if (<= t_1 (- INFINITY))
     (* -4.5 (/ z (/ a t)))
     (if (<= t_1 5e+281) t_1 (/ (/ y a) (/ 2.0 x))))))
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)) / (a * 2.0);
	double tmp;
	if (t_1 <= -((double) INFINITY)) {
		tmp = -4.5 * (z / (a / t));
	} else if (t_1 <= 5e+281) {
		tmp = t_1;
	} else {
		tmp = (y / a) / (2.0 / x);
	}
	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)) / (a * 2.0);
	double tmp;
	if (t_1 <= -Double.POSITIVE_INFINITY) {
		tmp = -4.5 * (z / (a / t));
	} else if (t_1 <= 5e+281) {
		tmp = t_1;
	} else {
		tmp = (y / a) / (2.0 / x);
	}
	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)) / (a * 2.0)
	tmp = 0
	if t_1 <= -math.inf:
		tmp = -4.5 * (z / (a / t))
	elif t_1 <= 5e+281:
		tmp = t_1
	else:
		tmp = (y / a) / (2.0 / x)
	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(Float64(x * y) - Float64(Float64(z * 9.0) * t)) / Float64(a * 2.0))
	tmp = 0.0
	if (t_1 <= Float64(-Inf))
		tmp = Float64(-4.5 * Float64(z / Float64(a / t)));
	elseif (t_1 <= 5e+281)
		tmp = t_1;
	else
		tmp = Float64(Float64(y / a) / Float64(2.0 / x));
	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)) / (a * 2.0);
	tmp = 0.0;
	if (t_1 <= -Inf)
		tmp = -4.5 * (z / (a / t));
	elseif (t_1 <= 5e+281)
		tmp = t_1;
	else
		tmp = (y / a) / (2.0 / x);
	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[(N[(x * y), $MachinePrecision] - N[(N[(z * 9.0), $MachinePrecision] * t), $MachinePrecision]), $MachinePrecision] / N[(a * 2.0), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$1, (-Infinity)], N[(-4.5 * N[(z / N[(a / t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$1, 5e+281], t$95$1, N[(N[(y / a), $MachinePrecision] / N[(2.0 / x), $MachinePrecision]), $MachinePrecision]]]]
\frac{x \cdot y - \left(z \cdot 9\right) \cdot t}{a \cdot 2}
\begin{array}{l}
t_1 := \frac{x \cdot y - \left(z \cdot 9\right) \cdot t}{a \cdot 2}\\
\mathbf{if}\;t_1 \leq -\infty:\\
\;\;\;\;-4.5 \cdot \frac{z}{\frac{a}{t}}\\

\mathbf{elif}\;t_1 \leq 5 \cdot 10^{+281}:\\
\;\;\;\;t_1\\

\mathbf{else}:\\
\;\;\;\;\frac{\frac{y}{a}}{\frac{2}{x}}\\


\end{array}

Error?

Try it out?

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original7.8
Target5.7
Herbie4.7
\[\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 (*.f64 x y) (*.f64 (*.f64 z 9) t)) (*.f64 a 2)) < -inf.0

    1. Initial program 64.0

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

      \[\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.6

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

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

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

      [Start]62.7

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

      *-commutative [=>]62.7

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

      associate-/l* [=>]31.4

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

    if -inf.0 < (/.f64 (-.f64 (*.f64 x y) (*.f64 (*.f64 z 9) t)) (*.f64 a 2)) < 5.00000000000000016e281

    1. Initial program 0.7

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

    if 5.00000000000000016e281 < (/.f64 (-.f64 (*.f64 x y) (*.f64 (*.f64 z 9) t)) (*.f64 a 2))

    1. Initial program 49.5

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

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

      [Start]49.5

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

      associate-*l* [=>]48.9

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

      \[\leadsto \color{blue}{0.5 \cdot \frac{y \cdot x}{a}} \]
    4. Simplified31.6

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

      [Start]56.2

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

      associate-/l* [=>]32.2

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

      associate-/r/ [=>]31.6

      \[ 0.5 \cdot \color{blue}{\left(\frac{y}{a} \cdot x\right)} \]
    5. Taylor expanded in y around 0 56.2

      \[\leadsto \color{blue}{0.5 \cdot \frac{y \cdot x}{a}} \]
    6. Simplified32.1

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

      [Start]56.2

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

      metadata-eval [<=]56.2

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

      times-frac [<=]56.2

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

      *-commutative [<=]56.2

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

      associate-*l* [=>]56.1

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

      times-frac [=>]32.1

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

      /-rgt-identity [=>]32.1

      \[ \color{blue}{y} \cdot \frac{x \cdot 0.5}{a} \]
    7. Applied egg-rr31.6

      \[\leadsto \color{blue}{\frac{\frac{y}{a}}{\frac{2}{x}}} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification4.7

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

Alternatives

Alternative 1
Error4.5
Cost1352
\[\begin{array}{l} \mathbf{if}\;x \cdot y \leq -1 \cdot 10^{+178}:\\ \;\;\;\;y \cdot \frac{x \cdot 0.5}{a}\\ \mathbf{elif}\;x \cdot y \leq 6 \cdot 10^{+283}:\\ \;\;\;\;\frac{0.5}{a} \cdot \left(x \cdot y + z \cdot \left(t \cdot -9\right)\right)\\ \mathbf{else}:\\ \;\;\;\;0.5 \cdot \left(x \cdot \frac{y}{a}\right)\\ \end{array} \]
Alternative 2
Error4.4
Cost1352
\[\begin{array}{l} \mathbf{if}\;x \cdot y \leq -1 \cdot 10^{+178}:\\ \;\;\;\;y \cdot \frac{x \cdot 0.5}{a}\\ \mathbf{elif}\;x \cdot y \leq 6 \cdot 10^{+283}:\\ \;\;\;\;\frac{x \cdot y + z \cdot \left(t \cdot -9\right)}{a \cdot 2}\\ \mathbf{else}:\\ \;\;\;\;0.5 \cdot \left(x \cdot \frac{y}{a}\right)\\ \end{array} \]
Alternative 3
Error24.1
Cost1241
\[\begin{array}{l} \mathbf{if}\;y \leq -2 \cdot 10^{-91}:\\ \;\;\;\;0.5 \cdot \left(x \cdot \frac{y}{a}\right)\\ \mathbf{elif}\;y \leq -7.8 \cdot 10^{-224}:\\ \;\;\;\;t \cdot \frac{-4.5}{\frac{a}{z}}\\ \mathbf{elif}\;y \leq -2.7 \cdot 10^{-247}:\\ \;\;\;\;\left(x \cdot y\right) \cdot \frac{0.5}{a}\\ \mathbf{elif}\;y \leq 4000000:\\ \;\;\;\;\frac{-4.5}{a} \cdot \left(z \cdot t\right)\\ \mathbf{elif}\;y \leq 10^{+127} \lor \neg \left(y \leq 1.42 \cdot 10^{+163}\right):\\ \;\;\;\;y \cdot \frac{x \cdot 0.5}{a}\\ \mathbf{else}:\\ \;\;\;\;-4.5 \cdot \frac{t}{\frac{a}{z}}\\ \end{array} \]
Alternative 4
Error23.6
Cost977
\[\begin{array}{l} t_1 := 0.5 \cdot \left(x \cdot \frac{y}{a}\right)\\ \mathbf{if}\;y \leq -2 \cdot 10^{-91}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq 2.2 \cdot 10^{+33}:\\ \;\;\;\;-4.5 \cdot \frac{z \cdot t}{a}\\ \mathbf{elif}\;y \leq 10^{+127} \lor \neg \left(y \leq 1.85 \cdot 10^{+163}\right):\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;-4.5 \cdot \frac{t}{\frac{a}{z}}\\ \end{array} \]
Alternative 5
Error23.9
Cost977
\[\begin{array}{l} \mathbf{if}\;y \leq -2 \cdot 10^{-91}:\\ \;\;\;\;0.5 \cdot \left(x \cdot \frac{y}{a}\right)\\ \mathbf{elif}\;y \leq 2600000:\\ \;\;\;\;-4.5 \cdot \frac{z \cdot t}{a}\\ \mathbf{elif}\;y \leq 7.5 \cdot 10^{+126} \lor \neg \left(y \leq 1.42 \cdot 10^{+163}\right):\\ \;\;\;\;y \cdot \frac{x \cdot 0.5}{a}\\ \mathbf{else}:\\ \;\;\;\;-4.5 \cdot \frac{t}{\frac{a}{z}}\\ \end{array} \]
Alternative 6
Error24.0
Cost977
\[\begin{array}{l} \mathbf{if}\;y \leq -2 \cdot 10^{-91}:\\ \;\;\;\;0.5 \cdot \left(x \cdot \frac{y}{a}\right)\\ \mathbf{elif}\;y \leq 12.5:\\ \;\;\;\;\frac{-4.5}{a} \cdot \left(z \cdot t\right)\\ \mathbf{elif}\;y \leq 8.8 \cdot 10^{+126} \lor \neg \left(y \leq 8.6 \cdot 10^{+163}\right):\\ \;\;\;\;y \cdot \frac{x \cdot 0.5}{a}\\ \mathbf{else}:\\ \;\;\;\;-4.5 \cdot \frac{t}{\frac{a}{z}}\\ \end{array} \]
Alternative 7
Error23.5
Cost976
\[\begin{array}{l} t_1 := 0.5 \cdot \left(x \cdot \frac{y}{a}\right)\\ \mathbf{if}\;y \leq -1.85 \cdot 10^{-91}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq 2 \cdot 10^{+34}:\\ \;\;\;\;-4.5 \cdot \frac{z \cdot t}{a}\\ \mathbf{elif}\;y \leq 9.5 \cdot 10^{+126}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq 1.42 \cdot 10^{+163}:\\ \;\;\;\;-4.5 \cdot \frac{t}{\frac{a}{z}}\\ \mathbf{else}:\\ \;\;\;\;0.5 \cdot \frac{x}{\frac{a}{y}}\\ \end{array} \]
Alternative 8
Error32.9
Cost448
\[-4.5 \cdot \left(z \cdot \frac{t}{a}\right) \]
Alternative 9
Error32.9
Cost448
\[-4.5 \cdot \frac{z}{\frac{a}{t}} \]
Alternative 10
Error32.9
Cost448
\[-4.5 \cdot \frac{z \cdot t}{a} \]

Error

Reproduce?

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