Average Error: 7.8 → 0.7
Time: 10.8s
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 := x \cdot y - z \cdot t\\ \mathbf{if}\;t_1 \leq -\infty:\\ \;\;\;\;\frac{x}{\frac{a}{y}} - \frac{z}{\frac{a}{t}}\\ \mathbf{elif}\;t_1 \leq 5 \cdot 10^{+241}:\\ \;\;\;\;\frac{\mathsf{fma}\left(x, y, z \cdot \left(-t\right)\right)}{a}\\ \mathbf{else}:\\ \;\;\;\;x \cdot \frac{y}{a} - z \cdot \frac{t}{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 y) (* z t))))
   (if (<= t_1 (- INFINITY))
     (- (/ x (/ a y)) (/ z (/ a t)))
     (if (<= t_1 5e+241)
       (/ (fma x y (* z (- t))) a)
       (- (* x (/ y a)) (* z (/ t 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 * y) - (z * t);
	double tmp;
	if (t_1 <= -((double) INFINITY)) {
		tmp = (x / (a / y)) - (z / (a / t));
	} else if (t_1 <= 5e+241) {
		tmp = fma(x, y, (z * -t)) / a;
	} else {
		tmp = (x * (y / a)) - (z * (t / 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(Float64(x * y) - Float64(z * t))
	tmp = 0.0
	if (t_1 <= Float64(-Inf))
		tmp = Float64(Float64(x / Float64(a / y)) - Float64(z / Float64(a / t)));
	elseif (t_1 <= 5e+241)
		tmp = Float64(fma(x, y, Float64(z * Float64(-t))) / a);
	else
		tmp = Float64(Float64(x * Float64(y / a)) - Float64(z * Float64(t / a)));
	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[(x * y), $MachinePrecision] - N[(z * t), $MachinePrecision]), $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+241], N[(N[(x * y + N[(z * (-t)), $MachinePrecision]), $MachinePrecision] / a), $MachinePrecision], N[(N[(x * N[(y / a), $MachinePrecision]), $MachinePrecision] - N[(z * N[(t / a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]
\frac{x \cdot y - z \cdot t}{a}
\begin{array}{l}
t_1 := x \cdot y - z \cdot t\\
\mathbf{if}\;t_1 \leq -\infty:\\
\;\;\;\;\frac{x}{\frac{a}{y}} - \frac{z}{\frac{a}{t}}\\

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

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


\end{array}

Error

Target

Original7.8
Target5.7
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)) < -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 x y) (*.f64 z t)) < 5.00000000000000025e241

    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.00000000000000025e241 < (-.f64 (*.f64 x y) (*.f64 z t))

    1. Initial program 37.1

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

      \[\leadsto \frac{\color{blue}{\left(\mathsf{fma}\left(-t, z, z \cdot t\right) + x \cdot y\right) + z \cdot \left(-t\right)}}{a} \]
    3. Taylor expanded in t around 0 20.4

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

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

      [Start]20.4

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

      +-commutative [=>]20.4

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

      distribute-lft1-in [=>]20.4

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

      metadata-eval [=>]20.4

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

      associate-*r/ [=>]20.4

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

      associate-/r/ [<=]20.4

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

      associate-/l* [<=]37.1

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

      associate-*r* [<=]37.1

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

      *-commutative [<=]37.1

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

      associate-*r* [=>]37.1

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

      metadata-eval [<=]37.1

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

      distribute-rgt1-in [<=]37.1

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

      associate-/l* [=>]20.3

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

      distribute-rgt1-in [=>]20.3

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

      metadata-eval [=>]20.3

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

      mul-1-neg [=>]20.3

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

      *-rgt-identity [<=]20.3

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

      metadata-eval [<=]20.3

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

      distribute-rgt-out [<=]20.3

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

      distribute-neg-frac [<=]20.3

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

      associate-/l* [<=]37.1

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

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

Alternatives

Alternative 1
Error4.3
Cost1864
\[\begin{array}{l} t_1 := \frac{x \cdot y - z \cdot t}{a}\\ \mathbf{if}\;t_1 \leq -\infty:\\ \;\;\;\;\frac{x}{\frac{a}{y}}\\ \mathbf{elif}\;t_1 \leq 10^{+304}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;\frac{-z}{\frac{a}{t}}\\ \end{array} \]
Alternative 2
Error0.8
Cost1737
\[\begin{array}{l} t_1 := x \cdot y - z \cdot t\\ \mathbf{if}\;t_1 \leq -5 \cdot 10^{+218} \lor \neg \left(t_1 \leq 5 \cdot 10^{+241}\right):\\ \;\;\;\;x \cdot \frac{y}{a} - z \cdot \frac{t}{a}\\ \mathbf{else}:\\ \;\;\;\;\frac{t_1}{a}\\ \end{array} \]
Alternative 3
Error0.7
Cost1736
\[\begin{array}{l} t_1 := x \cdot y - z \cdot t\\ \mathbf{if}\;t_1 \leq -\infty:\\ \;\;\;\;\frac{x}{\frac{a}{y}} - \frac{z}{\frac{a}{t}}\\ \mathbf{elif}\;t_1 \leq 5 \cdot 10^{+241}:\\ \;\;\;\;\frac{t_1}{a}\\ \mathbf{else}:\\ \;\;\;\;x \cdot \frac{y}{a} - z \cdot \frac{t}{a}\\ \end{array} \]
Alternative 4
Error20.2
Cost1424
\[\begin{array}{l} \mathbf{if}\;z \cdot t \leq -2 \cdot 10^{+107}:\\ \;\;\;\;t \cdot \left(-\frac{z}{a}\right)\\ \mathbf{elif}\;z \cdot t \leq -2000000000000:\\ \;\;\;\;\frac{x}{\frac{a}{y}}\\ \mathbf{elif}\;z \cdot t \leq -1.5 \cdot 10^{-85}:\\ \;\;\;\;\frac{z \cdot \left(-t\right)}{a}\\ \mathbf{elif}\;z \cdot t \leq 4 \cdot 10^{+28}:\\ \;\;\;\;\frac{x \cdot y}{a}\\ \mathbf{else}:\\ \;\;\;\;\frac{-z}{\frac{a}{t}}\\ \end{array} \]
Alternative 5
Error24.6
Cost1044
\[\begin{array}{l} t_1 := \frac{-t}{\frac{a}{z}}\\ \mathbf{if}\;x \leq -1.08 \cdot 10^{+214}:\\ \;\;\;\;\frac{x}{\frac{a}{y}}\\ \mathbf{elif}\;x \leq -1.02 \cdot 10^{-11}:\\ \;\;\;\;\frac{y}{\frac{a}{x}}\\ \mathbf{elif}\;x \leq -2 \cdot 10^{-47}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq -1.85 \cdot 10^{-165}:\\ \;\;\;\;\frac{x \cdot y}{a}\\ \mathbf{elif}\;x \leq 1.72 \cdot 10^{-40}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;y \cdot \frac{x}{a}\\ \end{array} \]
Alternative 6
Error24.3
Cost1044
\[\begin{array}{l} \mathbf{if}\;x \leq -9.2 \cdot 10^{+213}:\\ \;\;\;\;\frac{x}{\frac{a}{y}}\\ \mathbf{elif}\;x \leq -5.5 \cdot 10^{-11}:\\ \;\;\;\;\frac{y}{\frac{a}{x}}\\ \mathbf{elif}\;x \leq -1.9 \cdot 10^{-146}:\\ \;\;\;\;z \cdot \left(-\frac{t}{a}\right)\\ \mathbf{elif}\;x \leq -1.56 \cdot 10^{-165}:\\ \;\;\;\;\frac{x \cdot y}{a}\\ \mathbf{elif}\;x \leq 2 \cdot 10^{-36}:\\ \;\;\;\;\frac{-t}{\frac{a}{z}}\\ \mathbf{else}:\\ \;\;\;\;y \cdot \frac{x}{a}\\ \end{array} \]
Alternative 7
Error24.4
Cost1044
\[\begin{array}{l} \mathbf{if}\;x \leq -1.45 \cdot 10^{+214}:\\ \;\;\;\;\frac{x}{\frac{a}{y}}\\ \mathbf{elif}\;x \leq -1.34 \cdot 10^{-11}:\\ \;\;\;\;\frac{y}{\frac{a}{x}}\\ \mathbf{elif}\;x \leq -2.9 \cdot 10^{-146}:\\ \;\;\;\;z \cdot \left(-\frac{t}{a}\right)\\ \mathbf{elif}\;x \leq -1.85 \cdot 10^{-165}:\\ \;\;\;\;\frac{x \cdot y}{a}\\ \mathbf{elif}\;x \leq 2.15 \cdot 10^{-40}:\\ \;\;\;\;t \cdot \left(-\frac{z}{a}\right)\\ \mathbf{else}:\\ \;\;\;\;y \cdot \frac{x}{a}\\ \end{array} \]
Alternative 8
Error24.4
Cost1044
\[\begin{array}{l} \mathbf{if}\;x \leq -1.45 \cdot 10^{+214}:\\ \;\;\;\;\frac{x}{\frac{a}{y}}\\ \mathbf{elif}\;x \leq -9.2 \cdot 10^{-12}:\\ \;\;\;\;\frac{y}{\frac{a}{x}}\\ \mathbf{elif}\;x \leq -2.9 \cdot 10^{-145}:\\ \;\;\;\;\frac{-z}{\frac{a}{t}}\\ \mathbf{elif}\;x \leq -1.85 \cdot 10^{-165}:\\ \;\;\;\;\frac{x \cdot y}{a}\\ \mathbf{elif}\;x \leq 4.2 \cdot 10^{-41}:\\ \;\;\;\;t \cdot \left(-\frac{z}{a}\right)\\ \mathbf{else}:\\ \;\;\;\;y \cdot \frac{x}{a}\\ \end{array} \]
Alternative 9
Error32.1
Cost585
\[\begin{array}{l} \mathbf{if}\;a \leq -2.9 \cdot 10^{-254} \lor \neg \left(a \leq 3.55 \cdot 10^{+227}\right):\\ \;\;\;\;y \cdot \frac{x}{a}\\ \mathbf{else}:\\ \;\;\;\;x \cdot \frac{y}{a}\\ \end{array} \]
Alternative 10
Error32.1
Cost585
\[\begin{array}{l} \mathbf{if}\;a \leq -1.85 \cdot 10^{-254} \lor \neg \left(a \leq 2.2 \cdot 10^{-235}\right):\\ \;\;\;\;y \cdot \frac{x}{a}\\ \mathbf{else}:\\ \;\;\;\;\frac{x}{\frac{a}{y}}\\ \end{array} \]
Alternative 11
Error32.1
Cost584
\[\begin{array}{l} \mathbf{if}\;a \leq -6.2 \cdot 10^{-260}:\\ \;\;\;\;\frac{y}{\frac{a}{x}}\\ \mathbf{elif}\;a \leq 5 \cdot 10^{-239}:\\ \;\;\;\;\frac{x}{\frac{a}{y}}\\ \mathbf{else}:\\ \;\;\;\;y \cdot \frac{x}{a}\\ \end{array} \]
Alternative 12
Error31.0
Cost584
\[\begin{array}{l} \mathbf{if}\;a \leq -1.15 \cdot 10^{-73}:\\ \;\;\;\;\frac{y}{\frac{a}{x}}\\ \mathbf{elif}\;a \leq 5 \cdot 10^{-99}:\\ \;\;\;\;\frac{x \cdot y}{a}\\ \mathbf{else}:\\ \;\;\;\;y \cdot \frac{x}{a}\\ \end{array} \]
Alternative 13
Error32.2
Cost320
\[y \cdot \frac{x}{a} \]

Error

Reproduce

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