Average Error: 6.4 → 1.7
Time: 12.1s
Precision: binary64
Cost: 7300
\[ \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}\;z \leq -3.6 \cdot 10^{+127}:\\ \;\;\;\;\frac{-1}{z} \cdot \frac{\frac{1}{x}}{\mathsf{hypot}\left(1, z\right) \cdot y}\\ \mathbf{elif}\;z \leq 9 \cdot 10^{+84}:\\ \;\;\;\;\frac{1}{y \cdot \left(x \cdot \mathsf{fma}\left(z, z, 1\right)\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{1}{z}}{x \cdot \left(z \cdot y\right)}\\ \end{array} \]
(FPCore (x y z) :precision binary64 (/ (/ 1.0 x) (* y (+ 1.0 (* z z)))))
(FPCore (x y z)
 :precision binary64
 (if (<= z -3.6e+127)
   (* (/ -1.0 z) (/ (/ 1.0 x) (* (hypot 1.0 z) y)))
   (if (<= z 9e+84)
     (/ 1.0 (* y (* x (fma z z 1.0))))
     (/ (/ 1.0 z) (* x (* z y))))))
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 (z <= -3.6e+127) {
		tmp = (-1.0 / z) * ((1.0 / x) / (hypot(1.0, z) * y));
	} else if (z <= 9e+84) {
		tmp = 1.0 / (y * (x * fma(z, z, 1.0)));
	} else {
		tmp = (1.0 / z) / (x * (z * y));
	}
	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 (z <= -3.6e+127)
		tmp = Float64(Float64(-1.0 / z) * Float64(Float64(1.0 / x) / Float64(hypot(1.0, z) * y)));
	elseif (z <= 9e+84)
		tmp = Float64(1.0 / Float64(y * Float64(x * fma(z, z, 1.0))));
	else
		tmp = Float64(Float64(1.0 / z) / Float64(x * Float64(z * y)));
	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[z, -3.6e+127], N[(N[(-1.0 / z), $MachinePrecision] * N[(N[(1.0 / x), $MachinePrecision] / N[(N[Sqrt[1.0 ^ 2 + z ^ 2], $MachinePrecision] * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[z, 9e+84], N[(1.0 / N[(y * N[(x * N[(z * z + 1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(1.0 / z), $MachinePrecision] / N[(x * N[(z * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\frac{\frac{1}{x}}{y \cdot \left(1 + z \cdot z\right)}
\begin{array}{l}
\mathbf{if}\;z \leq -3.6 \cdot 10^{+127}:\\
\;\;\;\;\frac{-1}{z} \cdot \frac{\frac{1}{x}}{\mathsf{hypot}\left(1, z\right) \cdot y}\\

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

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


\end{array}

Error

Target

Original6.4
Target5.0
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 3 regimes
  2. if z < -3.59999999999999979e127

    1. Initial program 16.5

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

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

      [Start]16.5

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

      associate-/r* [=>]16.6

      \[ \color{blue}{\frac{\frac{\frac{1}{x}}{y}}{1 + z \cdot z}} \]
    3. Applied egg-rr1.6

      \[\leadsto \color{blue}{\frac{1}{\mathsf{hypot}\left(1, z\right)} \cdot \frac{\frac{1}{x}}{\mathsf{hypot}\left(1, z\right) \cdot y}} \]
    4. Taylor expanded in z around -inf 1.6

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

    if -3.59999999999999979e127 < z < 8.9999999999999994e84

    1. Initial program 1.6

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

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

      [Start]1.6

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

      associate-/l/ [=>]2.0

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

      associate-*l* [=>]1.6

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

      +-commutative [=>]1.6

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

      fma-def [=>]1.6

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

    if 8.9999999999999994e84 < z

    1. Initial program 14.4

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

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

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

      [Start]14.4

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

      *-commutative [=>]14.4

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

      unpow2 [=>]14.4

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

      associate-*r* [<=]7.1

      \[ \frac{\frac{1}{x}}{\color{blue}{z \cdot \left(z \cdot y\right)}} \]
    4. Taylor expanded in x around 0 14.5

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

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

      [Start]14.5

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

      associate-/r* [=>]14.4

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

      unpow2 [=>]14.4

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

      associate-/r* [=>]14.3

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

      associate-/r* [=>]6.7

      \[ \frac{\color{blue}{\frac{\frac{\frac{1}{y}}{z}}{z}}}{x} \]
    6. Taylor expanded in y around 0 14.5

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

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

      [Start]14.5

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

      unpow2 [=>]14.5

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

      associate-*l* [=>]7.4

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

      associate-*r* [=>]2.7

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

      associate-/l/ [<=]2.4

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

      associate-/r* [=>]2.2

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

      associate-/r* [<=]2.3

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;z \leq -3.6 \cdot 10^{+127}:\\ \;\;\;\;\frac{-1}{z} \cdot \frac{\frac{1}{x}}{\mathsf{hypot}\left(1, z\right) \cdot y}\\ \mathbf{elif}\;z \leq 9 \cdot 10^{+84}:\\ \;\;\;\;\frac{1}{y \cdot \left(x \cdot \mathsf{fma}\left(z, z, 1\right)\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{1}{z}}{x \cdot \left(z \cdot y\right)}\\ \end{array} \]

Alternatives

Alternative 1
Error1.5
Cost13504
\[\frac{\frac{\frac{1}{x}}{\mathsf{hypot}\left(1, z\right)}}{\mathsf{hypot}\left(1, z\right) \cdot y} \]
Alternative 2
Error1.7
Cost7241
\[\begin{array}{l} \mathbf{if}\;z \leq -4.8 \cdot 10^{+127} \lor \neg \left(z \leq 1.85 \cdot 10^{+95}\right):\\ \;\;\;\;\frac{\frac{1}{z}}{x \cdot \left(z \cdot y\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{y \cdot \left(x \cdot \mathsf{fma}\left(z, z, 1\right)\right)}\\ \end{array} \]
Alternative 3
Error1.7
Cost969
\[\begin{array}{l} \mathbf{if}\;z \leq -3.4 \cdot 10^{+127} \lor \neg \left(z \leq 5.8 \cdot 10^{+90}\right):\\ \;\;\;\;\frac{\frac{1}{z}}{x \cdot \left(z \cdot y\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{y \cdot \left(x + x \cdot \left(z \cdot z\right)\right)}\\ \end{array} \]
Alternative 4
Error2.2
Cost968
\[\begin{array}{l} \mathbf{if}\;z \leq -0.88:\\ \;\;\;\;\frac{1}{z \cdot \left(y \cdot \left(x \cdot z\right)\right)}\\ \mathbf{elif}\;z \leq 0.88:\\ \;\;\;\;\frac{1 - z \cdot z}{x \cdot y}\\ \mathbf{else}:\\ \;\;\;\;\frac{-1}{\frac{z \cdot y}{\frac{-1}{x \cdot z}}}\\ \end{array} \]
Alternative 5
Error20.5
Cost841
\[\begin{array}{l} t_0 := \frac{1}{x \cdot y}\\ \mathbf{if}\;z \leq -1.92 \cdot 10^{+28} \lor \neg \left(z \leq 3.2 \cdot 10^{+31}\right):\\ \;\;\;\;-1 + \left(1 + t_0\right)\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 6
Error4.2
Cost841
\[\begin{array}{l} \mathbf{if}\;z \leq -1 \lor \neg \left(z \leq 1\right):\\ \;\;\;\;\frac{1}{y \cdot \left(z \cdot \left(x \cdot z\right)\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{x \cdot y}\\ \end{array} \]
Alternative 7
Error2.3
Cost841
\[\begin{array}{l} \mathbf{if}\;z \leq -1 \lor \neg \left(z \leq 1\right):\\ \;\;\;\;\frac{1}{z \cdot \left(y \cdot \left(x \cdot z\right)\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{x \cdot y}\\ \end{array} \]
Alternative 8
Error2.4
Cost840
\[\begin{array}{l} \mathbf{if}\;z \leq -1:\\ \;\;\;\;\frac{1}{z \cdot \left(y \cdot \left(x \cdot z\right)\right)}\\ \mathbf{elif}\;z \leq 1:\\ \;\;\;\;\frac{1}{x \cdot y}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{\left(z \cdot y\right) \cdot \left(x \cdot z\right)}\\ \end{array} \]
Alternative 9
Error2.2
Cost840
\[\begin{array}{l} \mathbf{if}\;z \leq -0.88:\\ \;\;\;\;\frac{1}{z \cdot \left(y \cdot \left(x \cdot z\right)\right)}\\ \mathbf{elif}\;z \leq 0.88:\\ \;\;\;\;\frac{1 - z \cdot z}{x \cdot y}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{\left(z \cdot y\right) \cdot \left(x \cdot z\right)}\\ \end{array} \]
Alternative 10
Error28.7
Cost320
\[\frac{1}{x \cdot y} \]

Error

Reproduce

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