Average Error: 6.1 → 1.7
Time: 11.0s
Precision: binary64
Cost: 7240
\[ \begin{array}{c}[x, y] = \mathsf{sort}([x, y])\\ \end{array} \]
\[\frac{\frac{1}{x}}{y \cdot \left(1 + z \cdot z\right)} \]
\[\begin{array}{l} t_0 := \frac{\frac{1}{z}}{\left(z \cdot y\right) \cdot x}\\ \mathbf{if}\;z \leq -4.027549943135016 \cdot 10^{+36}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq 1.1227731140902065 \cdot 10^{+87}:\\ \;\;\;\;\frac{1}{y \cdot \mathsf{fma}\left(z, z \cdot x, x\right)}\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
(FPCore (x y z) :precision binary64 (/ (/ 1.0 x) (* y (+ 1.0 (* z z)))))
(FPCore (x y z)
 :precision binary64
 (let* ((t_0 (/ (/ 1.0 z) (* (* z y) x))))
   (if (<= z -4.027549943135016e+36)
     t_0
     (if (<= z 1.1227731140902065e+87) (/ 1.0 (* y (fma z (* z x) x))) t_0))))
double code(double x, double y, double z) {
	return (1.0 / x) / (y * (1.0 + (z * z)));
}
double code(double x, double y, double z) {
	double t_0 = (1.0 / z) / ((z * y) * x);
	double tmp;
	if (z <= -4.027549943135016e+36) {
		tmp = t_0;
	} else if (z <= 1.1227731140902065e+87) {
		tmp = 1.0 / (y * fma(z, (z * x), x));
	} else {
		tmp = t_0;
	}
	return tmp;
}
function code(x, y, z)
	return Float64(Float64(1.0 / x) / Float64(y * Float64(1.0 + Float64(z * z))))
end
function code(x, y, z)
	t_0 = Float64(Float64(1.0 / z) / Float64(Float64(z * y) * x))
	tmp = 0.0
	if (z <= -4.027549943135016e+36)
		tmp = t_0;
	elseif (z <= 1.1227731140902065e+87)
		tmp = Float64(1.0 / Float64(y * fma(z, Float64(z * x), x)));
	else
		tmp = t_0;
	end
	return tmp
end
code[x_, y_, z_] := N[(N[(1.0 / x), $MachinePrecision] / N[(y * N[(1.0 + N[(z * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
code[x_, y_, z_] := Block[{t$95$0 = N[(N[(1.0 / z), $MachinePrecision] / N[(N[(z * y), $MachinePrecision] * x), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[z, -4.027549943135016e+36], t$95$0, If[LessEqual[z, 1.1227731140902065e+87], N[(1.0 / N[(y * N[(z * N[(z * x), $MachinePrecision] + x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], t$95$0]]]
\frac{\frac{1}{x}}{y \cdot \left(1 + z \cdot z\right)}
\begin{array}{l}
t_0 := \frac{\frac{1}{z}}{\left(z \cdot y\right) \cdot x}\\
\mathbf{if}\;z \leq -4.027549943135016 \cdot 10^{+36}:\\
\;\;\;\;t_0\\

\mathbf{elif}\;z \leq 1.1227731140902065 \cdot 10^{+87}:\\
\;\;\;\;\frac{1}{y \cdot \mathsf{fma}\left(z, z \cdot x, x\right)}\\

\mathbf{else}:\\
\;\;\;\;t_0\\


\end{array}

Error

Target

Original6.1
Target4.6
Herbie1.7
\[\begin{array}{l} \mathbf{if}\;y \cdot \left(1 + z \cdot z\right) < -\infty:\\ \;\;\;\;\frac{\frac{1}{y}}{\left(1 + z \cdot z\right) \cdot x}\\ \mathbf{elif}\;y \cdot \left(1 + z \cdot z\right) < 8.680743250567252 \cdot 10^{+305}:\\ \;\;\;\;\frac{\frac{1}{x}}{\left(1 + z \cdot z\right) \cdot y}\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{1}{y}}{\left(1 + z \cdot z\right) \cdot x}\\ \end{array} \]

Derivation

  1. Split input into 2 regimes
  2. if z < -4.02754994313501619e36 or 1.1227731140902065e87 < z

    1. Initial program 13.0

      \[\frac{\frac{1}{x}}{y \cdot \left(1 + z \cdot z\right)} \]
    2. Taylor expanded in z around inf 13.0

      \[\leadsto \frac{\frac{1}{x}}{\color{blue}{y \cdot {z}^{2}}} \]
    3. Simplified7.3

      \[\leadsto \frac{\frac{1}{x}}{\color{blue}{z \cdot \left(y \cdot z\right)}} \]
      Proof
      (*.f64 z (*.f64 y z)): 0 points increase in error, 0 points decrease in error
      (Rewrite<= *-commutative_binary64 (*.f64 (*.f64 y z) z)): 0 points increase in error, 0 points decrease in error
      (Rewrite<= associate-*r*_binary64 (*.f64 y (*.f64 z z))): 32 points increase in error, 29 points decrease in error
      (*.f64 y (Rewrite<= unpow2_binary64 (pow.f64 z 2))): 0 points increase in error, 0 points decrease in error
    4. Applied egg-rr2.5

      \[\leadsto \color{blue}{\frac{1}{z \cdot y} \cdot \frac{1}{z \cdot x}} \]
    5. Applied egg-rr2.6

      \[\leadsto \color{blue}{\frac{\frac{1}{z}}{\left(z \cdot y\right) \cdot x}} \]

    if -4.02754994313501619e36 < z < 1.1227731140902065e87

    1. Initial program 0.8

      \[\frac{\frac{1}{x}}{y \cdot \left(1 + z \cdot z\right)} \]
    2. Taylor expanded in x around 0 1.0

      \[\leadsto \color{blue}{\frac{1}{y \cdot \left(\left({z}^{2} + 1\right) \cdot x\right)}} \]
    3. Simplified1.0

      \[\leadsto \color{blue}{\frac{1}{y \cdot \mathsf{fma}\left(z, z \cdot x, x\right)}} \]
      Proof
      (/.f64 1 (*.f64 y (fma.f64 z (*.f64 z x) x))): 0 points increase in error, 0 points decrease in error
      (/.f64 1 (*.f64 y (Rewrite=> fma-udef_binary64 (+.f64 (*.f64 z (*.f64 z x)) x)))): 2 points increase in error, 0 points decrease in error
      (/.f64 1 (*.f64 y (+.f64 (Rewrite<= associate-*l*_binary64 (*.f64 (*.f64 z z) x)) x))): 12 points increase in error, 8 points decrease in error
      (/.f64 1 (*.f64 y (+.f64 (*.f64 (Rewrite<= unpow2_binary64 (pow.f64 z 2)) x) x))): 0 points increase in error, 0 points decrease in error
      (/.f64 1 (*.f64 y (Rewrite=> distribute-lft1-in_binary64 (*.f64 (+.f64 (pow.f64 z 2) 1) x)))): 2 points increase in error, 1 points decrease in error
  3. Recombined 2 regimes into one program.
  4. Final simplification1.7

    \[\leadsto \begin{array}{l} \mathbf{if}\;z \leq -4.027549943135016 \cdot 10^{+36}:\\ \;\;\;\;\frac{\frac{1}{z}}{\left(z \cdot y\right) \cdot x}\\ \mathbf{elif}\;z \leq 1.1227731140902065 \cdot 10^{+87}:\\ \;\;\;\;\frac{1}{y \cdot \mathsf{fma}\left(z, z \cdot x, x\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{1}{z}}{\left(z \cdot y\right) \cdot x}\\ \end{array} \]

Alternatives

Alternative 1
Error1.7
Cost968
\[\begin{array}{l} t_0 := \frac{\frac{1}{z}}{\left(z \cdot y\right) \cdot x}\\ \mathbf{if}\;z \leq -4.027549943135016 \cdot 10^{+36}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq 1.1227731140902065 \cdot 10^{+87}:\\ \;\;\;\;\frac{1}{y \cdot \left(x + z \cdot \left(z \cdot x\right)\right)}\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 2
Error3.9
Cost836
\[\begin{array}{l} \mathbf{if}\;z \cdot z \leq 0.02:\\ \;\;\;\;\frac{1 - z \cdot z}{y \cdot x}\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{\frac{\frac{1}{z}}{x}}{z}}{y}\\ \end{array} \]
Alternative 3
Error2.1
Cost836
\[\begin{array}{l} \mathbf{if}\;z \cdot z \leq 0.02:\\ \;\;\;\;\frac{1 - z \cdot z}{y \cdot x}\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{1}{z}}{\left(z \cdot y\right) \cdot x}\\ \end{array} \]
Alternative 4
Error28.8
Cost320
\[\frac{\frac{1}{y}}{x} \]
Alternative 5
Error28.8
Cost320
\[\frac{\frac{1}{x}}{y} \]
Alternative 6
Error28.8
Cost320
\[\frac{1}{y \cdot x} \]

Error

Reproduce

herbie shell --seed 2022295 
(FPCore (x y z)
  :name "Statistics.Distribution.CauchyLorentz:$cdensity from math-functions-0.1.5.2"
  :precision binary64

  :herbie-target
  (if (< (* y (+ 1.0 (* z z))) (- INFINITY)) (/ (/ 1.0 y) (* (+ 1.0 (* z z)) x)) (if (< (* y (+ 1.0 (* z z))) 8.680743250567252e+305) (/ (/ 1.0 x) (* (+ 1.0 (* z z)) y)) (/ (/ 1.0 y) (* (+ 1.0 (* z z)) x))))

  (/ (/ 1.0 x) (* y (+ 1.0 (* z z)))))