?

Average Error: 6.2 → 2.2
Time: 11.4s
Precision: binary64
Cost: 7492

?

\[ \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} \mathbf{if}\;y \cdot \left(1 + z \cdot z\right) \leq 5 \cdot 10^{+295}:\\ \;\;\;\;\frac{\frac{1}{x}}{\mathsf{fma}\left(y \cdot z, z, y\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{1}{y}}{z \cdot \left(z \cdot x\right)}\\ \end{array} \]
(FPCore (x y z) :precision binary64 (/ (/ 1.0 x) (* y (+ 1.0 (* z z)))))
(FPCore (x y z)
 :precision binary64
 (if (<= (* y (+ 1.0 (* z z))) 5e+295)
   (/ (/ 1.0 x) (fma (* y z) z y))
   (/ (/ 1.0 y) (* z (* z x)))))
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 tmp;
	if ((y * (1.0 + (z * z))) <= 5e+295) {
		tmp = (1.0 / x) / fma((y * z), z, y);
	} else {
		tmp = (1.0 / y) / (z * (z * x));
	}
	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)
	tmp = 0.0
	if (Float64(y * Float64(1.0 + Float64(z * z))) <= 5e+295)
		tmp = Float64(Float64(1.0 / x) / fma(Float64(y * z), z, y));
	else
		tmp = Float64(Float64(1.0 / y) / Float64(z * Float64(z * x)));
	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_] := If[LessEqual[N[(y * N[(1.0 + N[(z * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 5e+295], N[(N[(1.0 / x), $MachinePrecision] / N[(N[(y * z), $MachinePrecision] * z + y), $MachinePrecision]), $MachinePrecision], N[(N[(1.0 / y), $MachinePrecision] / N[(z * N[(z * x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\frac{\frac{1}{x}}{y \cdot \left(1 + z \cdot z\right)}
\begin{array}{l}
\mathbf{if}\;y \cdot \left(1 + z \cdot z\right) \leq 5 \cdot 10^{+295}:\\
\;\;\;\;\frac{\frac{1}{x}}{\mathsf{fma}\left(y \cdot z, z, y\right)}\\

\mathbf{else}:\\
\;\;\;\;\frac{\frac{1}{y}}{z \cdot \left(z \cdot x\right)}\\


\end{array}

Error?

Target

Original6.2
Target4.9
Herbie2.2
\[\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 (*.f64 y (+.f64 1 (*.f64 z z))) < 4.99999999999999991e295

    1. Initial program 1.9

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

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

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

      [Start]1.9

      \[ \frac{\frac{1}{x}}{\left({z}^{2} + 1\right) \cdot y} \]

      unpow2 [=>]1.9

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

      distribute-lft1-in [<=]1.9

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

      *-commutative [<=]1.9

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

      associate-*r* [=>]0.5

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

      fma-def [=>]0.5

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

    if 4.99999999999999991e295 < (*.f64 y (+.f64 1 (*.f64 z z)))

    1. Initial program 17.2

      \[\frac{\frac{1}{x}}{y \cdot \left(1 + z \cdot z\right)} \]
    2. Simplified12.9

      \[\leadsto \color{blue}{\frac{\frac{\frac{1}{x}}{y}}{1 + z \cdot z}} \]
      Proof

      [Start]17.2

      \[ \frac{\frac{1}{x}}{y \cdot \left(1 + z \cdot z\right)} \]

      associate-/r* [=>]12.9

      \[ \color{blue}{\frac{\frac{\frac{1}{x}}{y}}{1 + z \cdot z}} \]
    3. Taylor expanded in z around inf 14.9

      \[\leadsto \color{blue}{\frac{1}{y \cdot \left({z}^{2} \cdot x\right)}} \]
    4. Simplified6.7

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

      [Start]14.9

      \[ \frac{1}{y \cdot \left({z}^{2} \cdot x\right)} \]

      associate-/r* [=>]14.7

      \[ \color{blue}{\frac{\frac{1}{y}}{{z}^{2} \cdot x}} \]

      unpow2 [=>]14.7

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

      associate-*l* [=>]6.7

      \[ \frac{\frac{1}{y}}{\color{blue}{z \cdot \left(z \cdot x\right)}} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification2.2

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

Alternatives

Alternative 1
Error3.2
Cost1220
\[\begin{array}{l} t_0 := y \cdot \left(1 + z \cdot z\right)\\ \mathbf{if}\;t_0 \leq 5 \cdot 10^{+295}:\\ \;\;\;\;\frac{\frac{1}{x}}{t_0}\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{1}{y}}{z \cdot \left(z \cdot x\right)}\\ \end{array} \]
Alternative 2
Error1.7
Cost969
\[\begin{array}{l} \mathbf{if}\;z \leq -3.25 \cdot 10^{+72} \lor \neg \left(z \leq 530000000000\right):\\ \;\;\;\;\frac{1}{y \cdot \left(z \cdot x\right)} \cdot \frac{1}{z}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{y \cdot \left(x + \left(z \cdot z\right) \cdot x\right)}\\ \end{array} \]
Alternative 3
Error2.2
Cost964
\[\begin{array}{l} \mathbf{if}\;z \cdot z \leq 5 \cdot 10^{-8}:\\ \;\;\;\;\frac{1 - z \cdot z}{y \cdot x}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{y \cdot \left(z \cdot x\right)} \cdot \frac{1}{z}\\ \end{array} \]
Alternative 4
Error4.2
Cost841
\[\begin{array}{l} \mathbf{if}\;z \leq -1 \lor \neg \left(z \leq 1\right):\\ \;\;\;\;\frac{1}{x \cdot \left(z \cdot \left(y \cdot z\right)\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{y \cdot x}\\ \end{array} \]
Alternative 5
Error4.2
Cost841
\[\begin{array}{l} \mathbf{if}\;z \leq -1 \lor \neg \left(z \leq 1\right):\\ \;\;\;\;\frac{1}{z \cdot \left(z \cdot \left(y \cdot x\right)\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{y \cdot x}\\ \end{array} \]
Alternative 6
Error2.4
Cost841
\[\begin{array}{l} \mathbf{if}\;z \leq -1 \lor \neg \left(z \leq 1\right):\\ \;\;\;\;\frac{1}{\left(y \cdot z\right) \cdot \left(z \cdot x\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{y \cdot x}\\ \end{array} \]
Alternative 7
Error2.2
Cost840
\[\begin{array}{l} \mathbf{if}\;z \leq -0.88:\\ \;\;\;\;\frac{1}{\left(y \cdot z\right) \cdot \left(z \cdot x\right)}\\ \mathbf{elif}\;z \leq 0.88:\\ \;\;\;\;\frac{1 - z \cdot z}{y \cdot x}\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{1}{z \cdot x}}{y \cdot z}\\ \end{array} \]
Alternative 8
Error2.0
Cost840
\[\begin{array}{l} \mathbf{if}\;z \leq -0.88:\\ \;\;\;\;\frac{\frac{\frac{1}{x}}{z}}{y \cdot z}\\ \mathbf{elif}\;z \leq 0.88:\\ \;\;\;\;\frac{1 - z \cdot z}{y \cdot x}\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{1}{z \cdot x}}{y \cdot z}\\ \end{array} \]
Alternative 9
Error2.4
Cost836
\[\begin{array}{l} \mathbf{if}\;z \cdot z \leq 5 \cdot 10^{-8}:\\ \;\;\;\;\frac{1 - z \cdot z}{y \cdot x}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{\left(y \cdot z\right) \cdot \left(z \cdot x\right)}\\ \end{array} \]
Alternative 10
Error28.4
Cost320
\[\frac{1}{y \cdot x} \]

Error

Reproduce?

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