?

Average Error: 7.4 → 0.7
Time: 8.7s
Precision: binary64
Cost: 8392

?

\[ \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 \cdot y - z \cdot t}{a}\\ \mathbf{if}\;t_1 \leq -\infty:\\ \;\;\;\;\frac{x}{\frac{a}{y}} - \frac{z}{\frac{a}{t}}\\ \mathbf{elif}\;t_1 \leq 5 \cdot 10^{+305}:\\ \;\;\;\;\frac{\mathsf{fma}\left(x, y, z \cdot \left(-t\right)\right)}{a}\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(-1, \frac{t}{\frac{a}{z}}, \frac{y}{\frac{a}{x}}\right)\\ \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 y) (* z t)) a)))
   (if (<= t_1 (- INFINITY))
     (- (/ x (/ a y)) (/ z (/ a t)))
     (if (<= t_1 5e+305)
       (/ (fma x y (* z (- t))) a)
       (fma -1.0 (/ t (/ a z)) (/ y (/ a x)))))))
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 * y) - (z * t)) / a;
	double tmp;
	if (t_1 <= -((double) INFINITY)) {
		tmp = (x / (a / y)) - (z / (a / t));
	} else if (t_1 <= 5e+305) {
		tmp = fma(x, y, (z * -t)) / a;
	} else {
		tmp = fma(-1.0, (t / (a / z)), (y / (a / x)));
	}
	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(Float64(Float64(x * y) - Float64(z * t)) / a)
	tmp = 0.0
	if (t_1 <= Float64(-Inf))
		tmp = Float64(Float64(x / Float64(a / y)) - Float64(z / Float64(a / t)));
	elseif (t_1 <= 5e+305)
		tmp = Float64(fma(x, y, Float64(z * Float64(-t))) / a);
	else
		tmp = fma(-1.0, Float64(t / Float64(a / z)), Float64(y / Float64(a / x)));
	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[(N[(N[(x * y), $MachinePrecision] - N[(z * t), $MachinePrecision]), $MachinePrecision] / a), $MachinePrecision]}, If[LessEqual[t$95$1, (-Infinity)], N[(N[(x / N[(a / y), $MachinePrecision]), $MachinePrecision] - N[(z / N[(a / t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$1, 5e+305], N[(N[(x * y + N[(z * (-t)), $MachinePrecision]), $MachinePrecision] / a), $MachinePrecision], N[(-1.0 * N[(t / N[(a / z), $MachinePrecision]), $MachinePrecision] + N[(y / N[(a / x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]
\frac{x \cdot y - z \cdot t}{a}
\begin{array}{l}
t_1 := \frac{x \cdot y - z \cdot t}{a}\\
\mathbf{if}\;t_1 \leq -\infty:\\
\;\;\;\;\frac{x}{\frac{a}{y}} - \frac{z}{\frac{a}{t}}\\

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

\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(-1, \frac{t}{\frac{a}{z}}, \frac{y}{\frac{a}{x}}\right)\\


\end{array}

Error?

Target

Original7.4
Target5.6
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 (*.f64 x y) (*.f64 z t)) a) < -inf.0

    1. Initial program 64.0

      \[\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}}} \]

    if -inf.0 < (/.f64 (-.f64 (*.f64 x y) (*.f64 z t)) a) < 5.00000000000000009e305

    1. Initial program 0.7

      \[\frac{x \cdot y - z \cdot t}{a} \]
    2. Simplified0.7

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

      [Start]0.7

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

      fma-neg [=>]0.7

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

      distribute-rgt-neg-in [=>]0.7

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

    if 5.00000000000000009e305 < (/.f64 (-.f64 (*.f64 x y) (*.f64 z t)) a)

    1. Initial program 62.7

      \[\frac{x \cdot y - z \cdot t}{a} \]
    2. Taylor expanded in x around 0 62.7

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

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

      [Start]62.7

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

      fma-def [=>]62.7

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

      associate-/l* [=>]35.7

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

      associate-/l* [=>]1.1

      \[ \mathsf{fma}\left(-1, \frac{t}{\frac{a}{z}}, \color{blue}{\frac{y}{\frac{a}{x}}}\right) \]
  3. Recombined 3 regimes into one program.
  4. Final simplification0.7

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

Alternatives

Alternative 1
Error0.7
Cost7945
\[\begin{array}{l} t_1 := x \cdot y - z \cdot t\\ \mathbf{if}\;t_1 \leq -\infty \lor \neg \left(t_1 \leq 10^{+283}\right):\\ \;\;\;\;\frac{x}{\frac{a}{y}} - \frac{z}{\frac{a}{t}}\\ \mathbf{else}:\\ \;\;\;\;\frac{\mathsf{fma}\left(x, y, z \cdot \left(-t\right)\right)}{a}\\ \end{array} \]
Alternative 2
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 10^{+283}\right):\\ \;\;\;\;\frac{x}{\frac{a}{y}} - \frac{z}{\frac{a}{t}}\\ \mathbf{else}:\\ \;\;\;\;\frac{t_1}{a}\\ \end{array} \]
Alternative 3
Error4.5
Cost1616
\[\begin{array}{l} t_1 := \frac{x \cdot y - z \cdot t}{a}\\ \mathbf{if}\;x \cdot y \leq -1 \cdot 10^{+280}:\\ \;\;\;\;\frac{x}{\frac{a}{y}}\\ \mathbf{elif}\;x \cdot y \leq -2 \cdot 10^{-312}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \cdot y \leq 10^{-246}:\\ \;\;\;\;\left(-t\right) \cdot \frac{z}{a}\\ \mathbf{elif}\;x \cdot y \leq 5 \cdot 10^{+275}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;\frac{y}{\frac{a}{x}}\\ \end{array} \]
Alternative 4
Error24.7
Cost648
\[\begin{array}{l} \mathbf{if}\;y \leq -1.95 \cdot 10^{-149}:\\ \;\;\;\;\frac{x}{\frac{a}{y}}\\ \mathbf{elif}\;y \leq 136000000000:\\ \;\;\;\;\left(-t\right) \cdot \frac{z}{a}\\ \mathbf{else}:\\ \;\;\;\;y \cdot \frac{x}{a}\\ \end{array} \]
Alternative 5
Error32.8
Cost585
\[\begin{array}{l} \mathbf{if}\;a \leq 5 \cdot 10^{-160} \lor \neg \left(a \leq 2 \cdot 10^{+56}\right):\\ \;\;\;\;y \cdot \frac{x}{a}\\ \mathbf{else}:\\ \;\;\;\;\frac{x}{\frac{a}{y}}\\ \end{array} \]
Alternative 6
Error31.3
Cost584
\[\begin{array}{l} \mathbf{if}\;y \leq -2 \cdot 10^{-24}:\\ \;\;\;\;\frac{x}{\frac{a}{y}}\\ \mathbf{elif}\;y \leq 2 \cdot 10^{+14}:\\ \;\;\;\;\frac{x \cdot y}{a}\\ \mathbf{else}:\\ \;\;\;\;y \cdot \frac{x}{a}\\ \end{array} \]
Alternative 7
Error32.9
Cost320
\[y \cdot \frac{x}{a} \]
Alternative 8
Error32.9
Cost320
\[\frac{y}{\frac{a}{x}} \]

Error

Reproduce?

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