?

Average Error: 7.3 → 0.7
Time: 9.4s
Precision: binary64
Cost: 1736

?

\[ \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 := \frac{x}{\frac{a}{y}}\\ t_2 := x \cdot y - z \cdot t\\ \mathbf{if}\;t_2 \leq -4 \cdot 10^{+248}:\\ \;\;\;\;t_1 - \frac{z}{\frac{a}{t}}\\ \mathbf{elif}\;t_2 \leq 2 \cdot 10^{+248}:\\ \;\;\;\;\frac{t_2}{a}\\ \mathbf{else}:\\ \;\;\;\;t_1 - t \cdot \frac{z}{a}\\ \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 (/ x (/ a y))) (t_2 (- (* x y) (* z t))))
   (if (<= t_2 -4e+248)
     (- t_1 (/ z (/ a t)))
     (if (<= t_2 2e+248) (/ t_2 a) (- t_1 (* t (/ z a)))))))
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 = x / (a / y);
	double t_2 = (x * y) - (z * t);
	double tmp;
	if (t_2 <= -4e+248) {
		tmp = t_1 - (z / (a / t));
	} else if (t_2 <= 2e+248) {
		tmp = t_2 / a;
	} else {
		tmp = t_1 - (t * (z / a));
	}
	return tmp;
}
real(8) function code(x, y, z, t, a)
    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
    code = ((x * y) - (z * t)) / a
end function
real(8) function code(x, y, z, t, a)
    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) :: t_1
    real(8) :: t_2
    real(8) :: tmp
    t_1 = x / (a / y)
    t_2 = (x * y) - (z * t)
    if (t_2 <= (-4d+248)) then
        tmp = t_1 - (z / (a / t))
    else if (t_2 <= 2d+248) then
        tmp = t_2 / a
    else
        tmp = t_1 - (t * (z / a))
    end if
    code = tmp
end function
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 = x / (a / y);
	double t_2 = (x * y) - (z * t);
	double tmp;
	if (t_2 <= -4e+248) {
		tmp = t_1 - (z / (a / t));
	} else if (t_2 <= 2e+248) {
		tmp = t_2 / a;
	} else {
		tmp = t_1 - (t * (z / a));
	}
	return tmp;
}
def code(x, y, z, t, a):
	return ((x * y) - (z * t)) / a
def code(x, y, z, t, a):
	t_1 = x / (a / y)
	t_2 = (x * y) - (z * t)
	tmp = 0
	if t_2 <= -4e+248:
		tmp = t_1 - (z / (a / t))
	elif t_2 <= 2e+248:
		tmp = t_2 / a
	else:
		tmp = t_1 - (t * (z / a))
	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(x / Float64(a / y))
	t_2 = Float64(Float64(x * y) - Float64(z * t))
	tmp = 0.0
	if (t_2 <= -4e+248)
		tmp = Float64(t_1 - Float64(z / Float64(a / t)));
	elseif (t_2 <= 2e+248)
		tmp = Float64(t_2 / a);
	else
		tmp = Float64(t_1 - Float64(t * Float64(z / a)));
	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 = x / (a / y);
	t_2 = (x * y) - (z * t);
	tmp = 0.0;
	if (t_2 <= -4e+248)
		tmp = t_1 - (z / (a / t));
	elseif (t_2 <= 2e+248)
		tmp = t_2 / a;
	else
		tmp = t_1 - (t * (z / a));
	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[(x / N[(a / y), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$2 = N[(N[(x * y), $MachinePrecision] - N[(z * t), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$2, -4e+248], N[(t$95$1 - N[(z / N[(a / t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$2, 2e+248], N[(t$95$2 / a), $MachinePrecision], N[(t$95$1 - N[(t * N[(z / a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]]
\frac{x \cdot y - z \cdot t}{a}
\begin{array}{l}
t_1 := \frac{x}{\frac{a}{y}}\\
t_2 := x \cdot y - z \cdot t\\
\mathbf{if}\;t_2 \leq -4 \cdot 10^{+248}:\\
\;\;\;\;t_1 - \frac{z}{\frac{a}{t}}\\

\mathbf{elif}\;t_2 \leq 2 \cdot 10^{+248}:\\
\;\;\;\;\frac{t_2}{a}\\

\mathbf{else}:\\
\;\;\;\;t_1 - t \cdot \frac{z}{a}\\


\end{array}

Error?

Try it out?

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original7.3
Target5.4
Herbie0.7
\[\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 3 regimes
  2. if (-.f64 (*.f64 x y) (*.f64 z t)) < -4.00000000000000018e248

    1. Initial program 36.9

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

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

    if -4.00000000000000018e248 < (-.f64 (*.f64 x y) (*.f64 z t)) < 2.00000000000000009e248

    1. Initial program 0.8

      \[\frac{x \cdot y - z \cdot t}{a} \]

    if 2.00000000000000009e248 < (-.f64 (*.f64 x y) (*.f64 z t))

    1. Initial program 40.3

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

      \[\leadsto \color{blue}{\frac{x}{\frac{a}{y}} - \frac{z}{\frac{a}{t}}} \]
    3. Applied egg-rr0.6

      \[\leadsto \frac{x}{\frac{a}{y}} - \color{blue}{\frac{z}{a} \cdot t} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification0.7

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \cdot y - z \cdot t \leq -4 \cdot 10^{+248}:\\ \;\;\;\;\frac{x}{\frac{a}{y}} - \frac{z}{\frac{a}{t}}\\ \mathbf{elif}\;x \cdot y - z \cdot t \leq 2 \cdot 10^{+248}:\\ \;\;\;\;\frac{x \cdot y - z \cdot t}{a}\\ \mathbf{else}:\\ \;\;\;\;\frac{x}{\frac{a}{y}} - t \cdot \frac{z}{a}\\ \end{array} \]

Alternatives

Alternative 1
Error0.7
Cost1737
\[\begin{array}{l} t_1 := x \cdot y - z \cdot t\\ \mathbf{if}\;t_1 \leq -\infty \lor \neg \left(t_1 \leq 2 \cdot 10^{+248}\right):\\ \;\;\;\;\frac{x}{\frac{a}{y}} - t \cdot \frac{z}{a}\\ \mathbf{else}:\\ \;\;\;\;\frac{t_1}{a}\\ \end{array} \]
Alternative 2
Error4.0
Cost1608
\[\begin{array}{l} t_1 := x \cdot y - z \cdot t\\ \mathbf{if}\;t_1 \leq -\infty:\\ \;\;\;\;t \cdot \left(-\frac{z}{a}\right)\\ \mathbf{elif}\;t_1 \leq 5 \cdot 10^{+306}:\\ \;\;\;\;\frac{t_1}{a}\\ \mathbf{else}:\\ \;\;\;\;x \cdot \frac{1}{\frac{a}{y}}\\ \end{array} \]
Alternative 3
Error23.9
Cost912
\[\begin{array}{l} t_1 := \frac{y}{\frac{a}{x}}\\ \mathbf{if}\;x \leq -1.5 \cdot 10^{+62}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq -115:\\ \;\;\;\;\frac{-z}{\frac{a}{t}}\\ \mathbf{elif}\;x \leq -7.2 \cdot 10^{-15}:\\ \;\;\;\;x \cdot \frac{y}{a}\\ \mathbf{elif}\;x \leq 3.1 \cdot 10^{-41}:\\ \;\;\;\;\frac{z \cdot \left(-t\right)}{a}\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 4
Error24.1
Cost780
\[\begin{array}{l} t_1 := \frac{y}{\frac{a}{x}}\\ \mathbf{if}\;x \leq -2.1 \cdot 10^{+62}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq -6 \cdot 10^{-284}:\\ \;\;\;\;t \cdot \left(-\frac{z}{a}\right)\\ \mathbf{elif}\;x \leq 8.2 \cdot 10^{-44}:\\ \;\;\;\;-z \cdot \frac{t}{a}\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 5
Error23.9
Cost649
\[\begin{array}{l} \mathbf{if}\;x \leq -1.62 \cdot 10^{+62} \lor \neg \left(x \leq 7.2 \cdot 10^{-59}\right):\\ \;\;\;\;\frac{y}{\frac{a}{x}}\\ \mathbf{else}:\\ \;\;\;\;-z \cdot \frac{t}{a}\\ \end{array} \]
Alternative 6
Error32.7
Cost320
\[x \cdot \frac{y}{a} \]
Alternative 7
Error32.5
Cost320
\[\frac{y}{\frac{a}{x}} \]

Error

Reproduce?

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