Average Error: 6.4 → 0.7
Time: 11.5s
Precision: binary64
Cost: 7556
\[ \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 4 \cdot 10^{+304}:\\ \;\;\;\;\frac{\frac{-1}{\mathsf{fma}\left(y \cdot z, z, y\right)}}{-x}\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{1}{y \cdot \left(z \cdot x\right)}}{z}\\ \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))) 4e+304)
   (/ (/ -1.0 (fma (* y z) z y)) (- x))
   (/ (/ 1.0 (* y (* z x))) z)))
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))) <= 4e+304) {
		tmp = (-1.0 / fma((y * z), z, y)) / -x;
	} else {
		tmp = (1.0 / (y * (z * x))) / z;
	}
	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))) <= 4e+304)
		tmp = Float64(Float64(-1.0 / fma(Float64(y * z), z, y)) / Float64(-x));
	else
		tmp = Float64(Float64(1.0 / Float64(y * Float64(z * x))) / z);
	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], 4e+304], N[(N[(-1.0 / N[(N[(y * z), $MachinePrecision] * z + y), $MachinePrecision]), $MachinePrecision] / (-x)), $MachinePrecision], N[(N[(1.0 / N[(y * N[(z * x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / z), $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 4 \cdot 10^{+304}:\\
\;\;\;\;\frac{\frac{-1}{\mathsf{fma}\left(y \cdot z, z, y\right)}}{-x}\\

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


\end{array}

Error

Target

Original6.4
Target5.1
Herbie0.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 (*.f64 y (+.f64 1 (*.f64 z z))) < 3.9999999999999998e304

    1. Initial program 2.0

      \[\frac{\frac{1}{x}}{y \cdot \left(1 + z \cdot z\right)} \]
    2. Applied egg-rr2.0

      \[\leadsto \color{blue}{\frac{\frac{\frac{1}{y}}{\mathsf{fma}\left(z, z, 1\right)}}{-x} \cdot -1} \]
    3. Simplified0.4

      \[\leadsto \color{blue}{\frac{\frac{-1}{\mathsf{fma}\left(y \cdot z, z, y\right)}}{-x}} \]
      Proof
      (/.f64 (/.f64 -1 (fma.f64 (*.f64 y z) z y)) (neg.f64 x)): 0 points increase in error, 0 points decrease in error
      (/.f64 (/.f64 (Rewrite<= metadata-eval (*.f64 1 -1)) (fma.f64 (*.f64 y z) z y)) (neg.f64 x)): 0 points increase in error, 0 points decrease in error
      (/.f64 (/.f64 (*.f64 1 -1) (Rewrite<= fma-def_binary64 (+.f64 (*.f64 (*.f64 y z) z) y))) (neg.f64 x)): 0 points increase in error, 0 points decrease in error
      (/.f64 (/.f64 (*.f64 1 -1) (+.f64 (Rewrite<= associate-*r*_binary64 (*.f64 y (*.f64 z z))) y)) (neg.f64 x)): 11 points increase in error, 0 points decrease in error
      (/.f64 (/.f64 (*.f64 1 -1) (+.f64 (Rewrite=> *-commutative_binary64 (*.f64 (*.f64 z z) y)) y)) (neg.f64 x)): 0 points increase in error, 11 points decrease in error
      (/.f64 (/.f64 (*.f64 1 -1) (Rewrite=> distribute-lft1-in_binary64 (*.f64 (+.f64 (*.f64 z z) 1) y))) (neg.f64 x)): 11 points increase in error, 0 points decrease in error
      (/.f64 (/.f64 (*.f64 1 -1) (*.f64 (Rewrite<= fma-udef_binary64 (fma.f64 z z 1)) y)) (neg.f64 x)): 0 points increase in error, 11 points decrease in error
      (/.f64 (/.f64 (*.f64 1 -1) (Rewrite<= *-commutative_binary64 (*.f64 y (fma.f64 z z 1)))) (neg.f64 x)): 0 points increase in error, 0 points decrease in error
      (/.f64 (Rewrite<= associate-*l/_binary64 (*.f64 (/.f64 1 (*.f64 y (fma.f64 z z 1))) -1)) (neg.f64 x)): 8 points increase in error, 0 points decrease in error
      (/.f64 (*.f64 (Rewrite=> associate-/r*_binary64 (/.f64 (/.f64 1 y) (fma.f64 z z 1))) -1) (neg.f64 x)): 0 points increase in error, 8 points decrease in error
      (Rewrite<= associate-*l/_binary64 (*.f64 (/.f64 (/.f64 (/.f64 1 y) (fma.f64 z z 1)) (neg.f64 x)) -1)): 9 points increase in error, 0 points decrease in error

    if 3.9999999999999998e304 < (*.f64 y (+.f64 1 (*.f64 z z)))

    1. Initial program 18.5

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

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

      \[\leadsto \color{blue}{\frac{\frac{1}{z \cdot \left(z \cdot x\right)}}{y}} \]
      Proof
      (/.f64 (/.f64 -1 (fma.f64 (*.f64 y z) z y)) (neg.f64 x)): 0 points increase in error, 0 points decrease in error
      (/.f64 (/.f64 (Rewrite<= metadata-eval (*.f64 1 -1)) (fma.f64 (*.f64 y z) z y)) (neg.f64 x)): 0 points increase in error, 0 points decrease in error
      (/.f64 (/.f64 (*.f64 1 -1) (Rewrite<= fma-def_binary64 (+.f64 (*.f64 (*.f64 y z) z) y))) (neg.f64 x)): 0 points increase in error, 0 points decrease in error
      (/.f64 (/.f64 (*.f64 1 -1) (+.f64 (Rewrite<= associate-*r*_binary64 (*.f64 y (*.f64 z z))) y)) (neg.f64 x)): 11 points increase in error, 0 points decrease in error
      (/.f64 (/.f64 (*.f64 1 -1) (+.f64 (Rewrite=> *-commutative_binary64 (*.f64 (*.f64 z z) y)) y)) (neg.f64 x)): 0 points increase in error, 11 points decrease in error
      (/.f64 (/.f64 (*.f64 1 -1) (Rewrite=> distribute-lft1-in_binary64 (*.f64 (+.f64 (*.f64 z z) 1) y))) (neg.f64 x)): 11 points increase in error, 0 points decrease in error
      (/.f64 (/.f64 (*.f64 1 -1) (*.f64 (Rewrite<= fma-udef_binary64 (fma.f64 z z 1)) y)) (neg.f64 x)): 0 points increase in error, 11 points decrease in error
      (/.f64 (/.f64 (*.f64 1 -1) (Rewrite<= *-commutative_binary64 (*.f64 y (fma.f64 z z 1)))) (neg.f64 x)): 0 points increase in error, 0 points decrease in error
      (/.f64 (Rewrite<= associate-*l/_binary64 (*.f64 (/.f64 1 (*.f64 y (fma.f64 z z 1))) -1)) (neg.f64 x)): 8 points increase in error, 0 points decrease in error
      (/.f64 (*.f64 (Rewrite=> associate-/r*_binary64 (/.f64 (/.f64 1 y) (fma.f64 z z 1))) -1) (neg.f64 x)): 0 points increase in error, 8 points decrease in error
      (Rewrite<= associate-*l/_binary64 (*.f64 (/.f64 (/.f64 (/.f64 1 y) (fma.f64 z z 1)) (neg.f64 x)) -1)): 9 points increase in error, 0 points decrease in error
    4. Applied egg-rr2.1

      \[\leadsto \color{blue}{-\frac{-1}{z \cdot \left(\left(z \cdot x\right) \cdot y\right)}} \]
    5. Taylor expanded in z around 0 14.1

      \[\leadsto -\color{blue}{\frac{-1}{y \cdot \left({z}^{2} \cdot x\right)}} \]
    6. Simplified5.1

      \[\leadsto -\color{blue}{\frac{\frac{\frac{-1}{z}}{y \cdot x}}{z}} \]
      Proof
      (neg.f64 (/.f64 (/.f64 (/.f64 -1 z) (*.f64 y x)) z)): 0 points increase in error, 0 points decrease in error
      (neg.f64 (/.f64 (/.f64 (/.f64 -1 z) (Rewrite<= *-commutative_binary64 (*.f64 x y))) z)): 4 points increase in error, 0 points decrease in error
      (neg.f64 (/.f64 (Rewrite<= associate-/r*_binary64 (/.f64 -1 (*.f64 z (*.f64 x y)))) z)): 0 points increase in error, 8 points decrease in error
      (neg.f64 (Rewrite=> associate-/l/_binary64 (/.f64 -1 (*.f64 z (*.f64 z (*.f64 x y)))))): 5 points increase in error, 0 points decrease in error
      (neg.f64 (/.f64 -1 (Rewrite<= associate-*l*_binary64 (*.f64 (*.f64 z z) (*.f64 x y))))): 0 points increase in error, 5 points decrease in error
      (neg.f64 (/.f64 -1 (Rewrite=> associate-*r*_binary64 (*.f64 (*.f64 (*.f64 z z) x) y)))): 8 points increase in error, 0 points decrease in error
      (neg.f64 (/.f64 -1 (*.f64 (*.f64 (Rewrite<= unpow2_binary64 (pow.f64 z 2)) x) y))): 4 points increase in error, 4 points decrease in error
      (neg.f64 (/.f64 -1 (Rewrite<= *-commutative_binary64 (*.f64 y (*.f64 (pow.f64 z 2) x))))): 0 points increase in error, 4 points decrease in error
    7. Taylor expanded in z around 0 1.5

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

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

Alternatives

Alternative 1
Error1.0
Cost7492
\[\begin{array}{l} \mathbf{if}\;y \cdot \left(1 + z \cdot z\right) \leq 4 \cdot 10^{+304}:\\ \;\;\;\;\frac{1}{\mathsf{fma}\left(y \cdot z, z, y\right) \cdot x}\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{1}{y \cdot \left(z \cdot x\right)}}{z}\\ \end{array} \]
Alternative 2
Error0.7
Cost7492
\[\begin{array}{l} \mathbf{if}\;y \cdot \left(1 + z \cdot z\right) \leq 4 \cdot 10^{+304}:\\ \;\;\;\;\frac{\frac{1}{x}}{\mathsf{fma}\left(y \cdot z, z, y\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{1}{y \cdot \left(z \cdot x\right)}}{z}\\ \end{array} \]
Alternative 3
Error1.8
Cost1220
\[\begin{array}{l} t_0 := y \cdot \left(1 + z \cdot z\right)\\ \mathbf{if}\;t_0 \leq 4 \cdot 10^{+304}:\\ \;\;\;\;\frac{\frac{1}{x}}{t_0}\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{1}{y \cdot \left(z \cdot x\right)}}{z}\\ \end{array} \]
Alternative 4
Error2.0
Cost968
\[\begin{array}{l} \mathbf{if}\;z \leq -6.8 \cdot 10^{+102}:\\ \;\;\;\;\frac{\frac{1}{y \cdot \left(z \cdot x\right)}}{z}\\ \mathbf{elif}\;z \leq 8 \cdot 10^{+83}:\\ \;\;\;\;\frac{1}{y \cdot \left(x + \left(z \cdot z\right) \cdot x\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{1}{y}}{z} \cdot \frac{1}{z \cdot x}\\ \end{array} \]
Alternative 5
Error4.3
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{\frac{1}{y}}{x}\\ \end{array} \]
Alternative 6
Error4.0
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{\frac{1}{y}}{x}\\ \end{array} \]
Alternative 7
Error5.7
Cost840
\[\begin{array}{l} \mathbf{if}\;z \leq -1:\\ \;\;\;\;\frac{1}{y \cdot \left(\left(z \cdot z\right) \cdot x\right)}\\ \mathbf{elif}\;z \leq 1:\\ \;\;\;\;\frac{\frac{1}{y}}{x}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{x \cdot \left(z \cdot \left(y \cdot z\right)\right)}\\ \end{array} \]
Alternative 8
Error2.4
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{\frac{1 - z \cdot z}{y}}{x}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{z \cdot \left(y \cdot \left(z \cdot x\right)\right)}\\ \end{array} \]
Alternative 9
Error2.2
Cost840
\[\begin{array}{l} \mathbf{if}\;z \leq -0.88:\\ \;\;\;\;\frac{\frac{1}{y}}{z} \cdot \frac{1}{z \cdot x}\\ \mathbf{elif}\;z \leq 0.88:\\ \;\;\;\;\frac{\frac{1 - z \cdot z}{y}}{x}\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{1}{y \cdot \left(z \cdot x\right)}}{z}\\ \end{array} \]
Alternative 10
Error4.4
Cost836
\[\begin{array}{l} \mathbf{if}\;z \cdot z \leq 0.001:\\ \;\;\;\;\frac{\frac{1}{y}}{x}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{y \cdot \left(z \cdot \left(z \cdot x\right)\right)}\\ \end{array} \]
Alternative 11
Error2.5
Cost836
\[\begin{array}{l} \mathbf{if}\;z \cdot z \leq 0.001:\\ \;\;\;\;\frac{\frac{1}{y}}{x}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{\left(y \cdot z\right) \cdot \left(z \cdot x\right)}\\ \end{array} \]
Alternative 12
Error2.4
Cost836
\[\begin{array}{l} \mathbf{if}\;z \cdot z \leq 0.001:\\ \;\;\;\;\frac{\frac{1 - z \cdot z}{y}}{x}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{\left(y \cdot z\right) \cdot \left(z \cdot x\right)}\\ \end{array} \]
Alternative 13
Error2.1
Cost836
\[\begin{array}{l} \mathbf{if}\;z \cdot z \leq 0.001:\\ \;\;\;\;\frac{\frac{1 - z \cdot z}{y}}{x}\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{1}{y \cdot \left(z \cdot x\right)}}{z}\\ \end{array} \]
Alternative 14
Error28.3
Cost320
\[\frac{1}{y \cdot x} \]
Alternative 15
Error28.2
Cost320
\[\frac{\frac{1}{x}}{y} \]
Alternative 16
Error28.2
Cost320
\[\frac{\frac{1}{y}}{x} \]

Error

Reproduce

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