?

Average Error: 7.3 → 4.5
Time: 22.4s
Precision: binary64
Cost: 1224

?

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

\mathbf{elif}\;z \cdot t \leq 4 \cdot 10^{+259}:\\
\;\;\;\;y \cdot \frac{x}{a} - \frac{t \cdot z}{a}\\

\mathbf{else}:\\
\;\;\;\;t_1\\


\end{array}

Error?

Try it out?

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original7.3
Target5.6
Herbie4.5
\[\begin{array}{l} \mathbf{if}\;z < -2.468684968699548 \cdot 10^{+170}:\\ \;\;\;\;\frac{y}{a} \cdot x - \frac{t}{a} \cdot z\\ \mathbf{elif}\;z < 6.309831121978371 \cdot 10^{-71}:\\ \;\;\;\;\frac{x \cdot y - z \cdot t}{a}\\ \mathbf{else}:\\ \;\;\;\;\frac{y}{a} \cdot x - \frac{t}{a} \cdot z\\ \end{array} \]

Derivation?

  1. Split input into 2 regimes
  2. if (*.f64 z t) < -inf.0 or 4e259 < (*.f64 z t)

    1. Initial program 51.0

      \[\frac{x \cdot y - z \cdot t}{a} \]
    2. Applied egg-rr64.0

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

      \[\leadsto \color{blue}{\left(-2 \cdot \frac{t \cdot z}{a} + \frac{y \cdot x}{a}\right) - -1 \cdot \frac{t \cdot z}{a}} \]
    4. Simplified51.0

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

      [Start]51.0

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

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

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

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

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

      rational.json-simplify-9 [=>]51.0

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

      \[\leadsto \color{blue}{-1 \cdot \left(t \cdot \left(2 \cdot \frac{z}{a} + -1 \cdot \frac{z}{a}\right)\right)} \]
    6. Simplified4.1

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

      [Start]4.1

      \[ -1 \cdot \left(t \cdot \left(2 \cdot \frac{z}{a} + -1 \cdot \frac{z}{a}\right)\right) \]

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

      \[ \color{blue}{t \cdot \left(\left(2 \cdot \frac{z}{a} + -1 \cdot \frac{z}{a}\right) \cdot -1\right)} \]

      rational.json-simplify-9 [=>]4.1

      \[ t \cdot \color{blue}{\left(-\left(2 \cdot \frac{z}{a} + -1 \cdot \frac{z}{a}\right)\right)} \]

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

      \[ t \cdot \left(-\left(\color{blue}{\frac{z}{a} \cdot 2} + -1 \cdot \frac{z}{a}\right)\right) \]

      rational.json-simplify-47 [=>]4.1

      \[ t \cdot \left(-\color{blue}{\frac{z}{a} \cdot \left(-1 + 2\right)}\right) \]

      metadata-eval [=>]4.1

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

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

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

      rational.json-simplify-6 [=>]4.1

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

    if -inf.0 < (*.f64 z t) < 4e259

    1. Initial program 4.0

      \[\frac{x \cdot y - z \cdot t}{a} \]
    2. Applied egg-rr23.2

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

      \[\leadsto \color{blue}{-1 \cdot \frac{t \cdot z}{a} + y \cdot \left(2 \cdot \frac{x}{a} - \frac{x}{a}\right)} \]
    4. Simplified4.5

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

      [Start]4.5

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

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

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

      rational.json-simplify-9 [=>]4.5

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

      \[\leadsto \color{blue}{-1 \cdot \frac{t \cdot z}{a} + y \cdot \left(2 \cdot \frac{x}{a} - \frac{x}{a}\right)} \]
    6. Simplified4.5

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

      [Start]4.5

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

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

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

      rational.json-simplify-6 [<=]4.5

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

      rational.json-simplify-48 [=>]4.5

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

      metadata-eval [=>]4.5

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

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

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

      rational.json-simplify-6 [=>]4.5

      \[ -1 \cdot \frac{t \cdot z}{a} + y \cdot \color{blue}{\frac{x}{a}} \]

      rational.json-simplify-5 [<=]4.5

      \[ -1 \cdot \frac{t \cdot z}{a} + \color{blue}{\left(y \cdot \frac{x}{a} - 0\right)} \]

      metadata-eval [<=]4.5

      \[ -1 \cdot \frac{t \cdot z}{a} + \left(y \cdot \frac{x}{a} - \color{blue}{\left(0 - 0\right)}\right) \]

      rational.json-simplify-44 [<=]4.5

      \[ -1 \cdot \frac{t \cdot z}{a} + \color{blue}{\left(0 - \left(0 - y \cdot \frac{x}{a}\right)\right)} \]

      rational.json-simplify-12 [<=]4.5

      \[ -1 \cdot \frac{t \cdot z}{a} + \left(0 - \color{blue}{\left(-y \cdot \frac{x}{a}\right)}\right) \]

      rational.json-simplify-12 [<=]4.5

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

      rational.json-simplify-8 [=>]4.5

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

      rational.json-simplify-47 [=>]4.5

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

      rational.json-simplify-1 [<=]4.5

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

      rational.json-simplify-2 [<=]4.5

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

      rational.json-simplify-8 [<=]4.5

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

      rational.json-simplify-13 [<=]4.5

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

      rational.json-simplify-46 [=>]4.5

      \[ \color{blue}{\left(0 - \frac{t \cdot z}{a}\right) - \left(-y \cdot \frac{x}{a}\right)} \]

      rational.json-simplify-42 [=>]4.5

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

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

Alternatives

Alternative 1
Error3.9
Cost1864
\[\begin{array}{l} t_1 := \frac{x \cdot y - z \cdot t}{a}\\ \mathbf{if}\;t_1 \leq -\infty:\\ \;\;\;\;y \cdot \frac{x}{a}\\ \mathbf{elif}\;t_1 \leq 10^{+303}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;t \cdot \left(-\frac{z}{a}\right)\\ \end{array} \]
Alternative 2
Error24.9
Cost912
\[\begin{array}{l} t_1 := t \cdot \left(-\frac{z}{a}\right)\\ t_2 := y \cdot \frac{x}{a}\\ \mathbf{if}\;x \leq -2.4 \cdot 10^{-6}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;x \leq -1.35 \cdot 10^{-63}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq -7.6 \cdot 10^{-104}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;x \leq 650000000:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;t_2\\ \end{array} \]
Alternative 3
Error24.9
Cost912
\[\begin{array}{l} t_1 := y \cdot \frac{x}{a}\\ \mathbf{if}\;x \leq -1 \cdot 10^{-6}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq -3.7 \cdot 10^{-63}:\\ \;\;\;\;t \cdot \left(-\frac{z}{a}\right)\\ \mathbf{elif}\;x \leq -2.15 \cdot 10^{-104}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq 1100000000:\\ \;\;\;\;z \cdot \left(-\frac{t}{a}\right)\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 4
Error30.8
Cost584
\[\begin{array}{l} t_1 := y \cdot \frac{x}{a}\\ \mathbf{if}\;a \leq -3.3 \cdot 10^{-43}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;a \leq 8.2 \cdot 10^{-85}:\\ \;\;\;\;\frac{y \cdot x}{a}\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 5
Error32.2
Cost320
\[y \cdot \frac{x}{a} \]

Error

Reproduce?

herbie shell --seed 2023077 
(FPCore (x y z t a)
  :name "Data.Colour.Matrix:inverse from colour-2.3.3, B"
  :precision binary64

  :herbie-target
  (if (< z -2.468684968699548e+170) (- (* (/ y a) x) (* (/ t a) z)) (if (< z 6.309831121978371e-71) (/ (- (* x y) (* z t)) a) (- (* (/ y a) x) (* (/ t a) z))))

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