Average Error: 7.7 → 0.8
Time: 10.5s
Precision: binary64
Cost: 7944
\[ \begin{array}{c}[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 -5 \cdot 10^{+302}:\\ \;\;\;\;t_1 - \frac{t}{\frac{a}{z}}\\ \mathbf{elif}\;t_2 \leq 10^{+202}:\\ \;\;\;\;\frac{\mathsf{fma}\left(y, x, z \cdot \left(-t\right)\right)}{a}\\ \mathbf{else}:\\ \;\;\;\;t_1 - \frac{z}{\frac{a}{t}}\\ \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 -5e+302)
     (- t_1 (/ t (/ a z)))
     (if (<= t_2 1e+202) (/ (fma y x (* z (- t))) a) (- t_1 (/ z (/ a t)))))))
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 <= -5e+302) {
		tmp = t_1 - (t / (a / z));
	} else if (t_2 <= 1e+202) {
		tmp = fma(y, x, (z * -t)) / a;
	} else {
		tmp = t_1 - (z / (a / t));
	}
	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 <= -5e+302)
		tmp = Float64(t_1 - Float64(t / Float64(a / z)));
	elseif (t_2 <= 1e+202)
		tmp = Float64(fma(y, x, Float64(z * Float64(-t))) / a);
	else
		tmp = Float64(t_1 - Float64(z / Float64(a / t)));
	end
	return 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, -5e+302], N[(t$95$1 - N[(t / N[(a / z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$2, 1e+202], N[(N[(y * x + N[(z * (-t)), $MachinePrecision]), $MachinePrecision] / a), $MachinePrecision], N[(t$95$1 - N[(z / N[(a / t), $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 -5 \cdot 10^{+302}:\\
\;\;\;\;t_1 - \frac{t}{\frac{a}{z}}\\

\mathbf{elif}\;t_2 \leq 10^{+202}:\\
\;\;\;\;\frac{\mathsf{fma}\left(y, x, z \cdot \left(-t\right)\right)}{a}\\

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


\end{array}

Error

Target

Original7.7
Target5.6
Herbie0.8
\[\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)) < -5e302

    1. Initial program 58.8

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

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

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

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

    if -5e302 < (-.f64 (*.f64 x y) (*.f64 z t)) < 9.999999999999999e201

    1. Initial program 0.8

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

      \[\leadsto \frac{\color{blue}{\mathsf{fma}\left(y, x, z \cdot \left(-t\right)\right)}}{a} \]

    if 9.999999999999999e201 < (-.f64 (*.f64 x y) (*.f64 z t))

    1. Initial program 30.6

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \cdot y - z \cdot t \leq -5 \cdot 10^{+302}:\\ \;\;\;\;\frac{x}{\frac{a}{y}} - \frac{t}{\frac{a}{z}}\\ \mathbf{elif}\;x \cdot y - z \cdot t \leq 10^{+202}:\\ \;\;\;\;\frac{\mathsf{fma}\left(y, x, z \cdot \left(-t\right)\right)}{a}\\ \mathbf{else}:\\ \;\;\;\;\frac{x}{\frac{a}{y}} - \frac{z}{\frac{a}{t}}\\ \end{array} \]

Alternatives

Alternative 1
Error0.7
Cost1736
\[\begin{array}{l} t_1 := x \cdot y - z \cdot t\\ t_2 := \frac{x}{\frac{a}{y}} - \frac{t}{\frac{a}{z}}\\ \mathbf{if}\;t_1 \leq -5 \cdot 10^{+302}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;t_1 \leq 4 \cdot 10^{+266}:\\ \;\;\;\;\frac{t_1}{a}\\ \mathbf{else}:\\ \;\;\;\;t_2\\ \end{array} \]
Alternative 2
Error0.8
Cost1736
\[\begin{array}{l} t_1 := \frac{x}{\frac{a}{y}}\\ t_2 := x \cdot y - z \cdot t\\ \mathbf{if}\;t_2 \leq -5 \cdot 10^{+302}:\\ \;\;\;\;t_1 - \frac{t}{\frac{a}{z}}\\ \mathbf{elif}\;t_2 \leq 10^{+202}:\\ \;\;\;\;\frac{t_2}{a}\\ \mathbf{else}:\\ \;\;\;\;t_1 - \frac{z}{\frac{a}{t}}\\ \end{array} \]
Alternative 3
Error4.8
Cost1608
\[\begin{array}{l} t_1 := x \cdot y - z \cdot t\\ t_2 := \frac{x}{\frac{a}{y}}\\ \mathbf{if}\;t_1 \leq -5 \cdot 10^{+302}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;t_1 \leq 10^{+285}:\\ \;\;\;\;\frac{t_1}{a}\\ \mathbf{else}:\\ \;\;\;\;t_2\\ \end{array} \]
Alternative 4
Error24.5
Cost648
\[\begin{array}{l} t_1 := y \cdot \frac{x}{a}\\ \mathbf{if}\;y \leq -6.297837991418515 \cdot 10^{-131}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq 6.357333334163227 \cdot 10^{-23}:\\ \;\;\;\;\left(-z\right) \cdot \frac{t}{a}\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 5
Error24.3
Cost648
\[\begin{array}{l} t_1 := y \cdot \frac{x}{a}\\ \mathbf{if}\;y \leq -1.0882148179539509 \cdot 10^{-133}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq 6.357333334163227 \cdot 10^{-23}:\\ \;\;\;\;\frac{z \cdot \left(-t\right)}{a}\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 6
Error31.5
Cost584
\[\begin{array}{l} t_1 := \frac{x}{\frac{a}{y}}\\ \mathbf{if}\;a \leq -1 \cdot 10^{-30}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;a \leq 10^{-70}:\\ \;\;\;\;\frac{x \cdot y}{a}\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 7
Error31.6
Cost584
\[\begin{array}{l} \mathbf{if}\;a \leq -1 \cdot 10^{-30}:\\ \;\;\;\;\frac{x}{\frac{a}{y}}\\ \mathbf{elif}\;a \leq 10^{-80}:\\ \;\;\;\;\frac{x \cdot y}{a}\\ \mathbf{else}:\\ \;\;\;\;\frac{y}{\frac{a}{x}}\\ \end{array} \]
Alternative 8
Error33.1
Cost320
\[\frac{x \cdot y}{a} \]

Error

Reproduce

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