Average Error: 6.4 → 1.4
Time: 9.9s
Precision: binary64
Cost: 1220
\[ \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 2 \cdot 10^{+298}:\\ \;\;\;\;\frac{1}{x \cdot \left(y + z \cdot \left(y \cdot z\right)\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{z \cdot \left(y \cdot \left(z \cdot x\right)\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))) 2e+298)
   (/ 1.0 (* x (+ y (* z (* y z)))))
   (/ 1.0 (* z (* y (* 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))) <= 2e+298) {
		tmp = 1.0 / (x * (y + (z * (y * z))));
	} else {
		tmp = 1.0 / (z * (y * (z * x)));
	}
	return tmp;
}
real(8) function code(x, y, z)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    code = (1.0d0 / x) / (y * (1.0d0 + (z * z)))
end function
real(8) function code(x, y, z)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    real(8) :: tmp
    if ((y * (1.0d0 + (z * z))) <= 2d+298) then
        tmp = 1.0d0 / (x * (y + (z * (y * z))))
    else
        tmp = 1.0d0 / (z * (y * (z * x)))
    end if
    code = tmp
end function
public static double code(double x, double y, double z) {
	return (1.0 / x) / (y * (1.0 + (z * z)));
}
public static double code(double x, double y, double z) {
	double tmp;
	if ((y * (1.0 + (z * z))) <= 2e+298) {
		tmp = 1.0 / (x * (y + (z * (y * z))));
	} else {
		tmp = 1.0 / (z * (y * (z * x)));
	}
	return tmp;
}
def code(x, y, z):
	return (1.0 / x) / (y * (1.0 + (z * z)))
def code(x, y, z):
	tmp = 0
	if (y * (1.0 + (z * z))) <= 2e+298:
		tmp = 1.0 / (x * (y + (z * (y * z))))
	else:
		tmp = 1.0 / (z * (y * (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))) <= 2e+298)
		tmp = Float64(1.0 / Float64(x * Float64(y + Float64(z * Float64(y * z)))));
	else
		tmp = Float64(1.0 / Float64(z * Float64(y * Float64(z * x))));
	end
	return tmp
end
function tmp = code(x, y, z)
	tmp = (1.0 / x) / (y * (1.0 + (z * z)));
end
function tmp_2 = code(x, y, z)
	tmp = 0.0;
	if ((y * (1.0 + (z * z))) <= 2e+298)
		tmp = 1.0 / (x * (y + (z * (y * z))));
	else
		tmp = 1.0 / (z * (y * (z * x)));
	end
	tmp_2 = 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], 2e+298], N[(1.0 / N[(x * N[(y + N[(z * N[(y * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(1.0 / N[(z * N[(y * N[(z * x), $MachinePrecision]), $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 2 \cdot 10^{+298}:\\
\;\;\;\;\frac{1}{x \cdot \left(y + z \cdot \left(y \cdot z\right)\right)}\\

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


\end{array}

Error

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original6.4
Target5.2
Herbie1.4
\[\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))) < 1.9999999999999999e298

    1. Initial program 2.0

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

      \[\leadsto \color{blue}{\frac{1}{x \cdot \left(y \cdot \mathsf{fma}\left(z, z, 1\right)\right)}} \]
      Proof
      (/.f64 1 (*.f64 x (*.f64 y (fma.f64 z z 1)))): 0 points increase in error, 0 points decrease in error
      (/.f64 1 (*.f64 x (*.f64 y (Rewrite<= fma-def_binary64 (+.f64 (*.f64 z z) 1))))): 0 points increase in error, 0 points decrease in error
      (/.f64 1 (*.f64 x (*.f64 y (Rewrite<= +-commutative_binary64 (+.f64 1 (*.f64 z z)))))): 0 points increase in error, 0 points decrease in error
      (Rewrite=> associate-/r*_binary64 (/.f64 (/.f64 1 x) (*.f64 y (+.f64 1 (*.f64 z z))))): 26 points increase in error, 28 points decrease in error
    3. Applied egg-rr6.7

      \[\leadsto \frac{1}{\color{blue}{\left(z \cdot z\right) \cdot \left(y \cdot x\right) + y \cdot x}} \]
    4. Applied egg-rr0.9

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

    if 1.9999999999999999e298 < (*.f64 y (+.f64 1 (*.f64 z z)))

    1. Initial program 17.7

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

      \[\leadsto \color{blue}{\frac{1}{x \cdot \left(y \cdot \mathsf{fma}\left(z, z, 1\right)\right)}} \]
      Proof
      (/.f64 1 (*.f64 x (*.f64 y (fma.f64 z z 1)))): 0 points increase in error, 0 points decrease in error
      (/.f64 1 (*.f64 x (*.f64 y (Rewrite<= fma-def_binary64 (+.f64 (*.f64 z z) 1))))): 0 points increase in error, 0 points decrease in error
      (/.f64 1 (*.f64 x (*.f64 y (Rewrite<= +-commutative_binary64 (+.f64 1 (*.f64 z z)))))): 0 points increase in error, 0 points decrease in error
      (Rewrite=> associate-/r*_binary64 (/.f64 (/.f64 1 x) (*.f64 y (+.f64 1 (*.f64 z z))))): 26 points increase in error, 28 points decrease in error
    3. Taylor expanded in z around inf 14.8

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

      \[\leadsto \frac{1}{\color{blue}{z \cdot \left(y \cdot \left(z \cdot x\right)\right)}} \]
      Proof
      (*.f64 z (*.f64 y (*.f64 z x))): 0 points increase in error, 0 points decrease in error
      (*.f64 z (*.f64 y (Rewrite<= *-commutative_binary64 (*.f64 x z)))): 0 points increase in error, 0 points decrease in error
      (Rewrite=> *-commutative_binary64 (*.f64 (*.f64 y (*.f64 x z)) z)): 0 points increase in error, 0 points decrease in error
      (Rewrite<= associate-*r*_binary64 (*.f64 y (*.f64 (*.f64 x z) z))): 41 points increase in error, 26 points decrease in error
      (*.f64 y (Rewrite<= associate-*r*_binary64 (*.f64 x (*.f64 z z)))): 30 points increase in error, 23 points decrease in error
      (*.f64 y (*.f64 x (Rewrite<= unpow2_binary64 (pow.f64 z 2)))): 0 points increase in error, 0 points decrease in error
      (*.f64 y (Rewrite<= *-commutative_binary64 (*.f64 (pow.f64 z 2) x))): 0 points increase in error, 0 points decrease in error
  3. Recombined 2 regimes into one program.
  4. Final simplification1.4

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

Alternatives

Alternative 1
Error2.2
Cost840
\[\begin{array}{l} t_0 := \frac{1}{z \cdot \left(x \cdot \left(y \cdot z\right)\right)}\\ \mathbf{if}\;z \leq -1:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq 1:\\ \;\;\;\;\frac{\frac{1}{x}}{y}\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 2
Error2.3
Cost840
\[\begin{array}{l} \mathbf{if}\;z \leq -1:\\ \;\;\;\;\frac{1}{z \cdot \left(x \cdot \left(y \cdot z\right)\right)}\\ \mathbf{elif}\;z \leq 1:\\ \;\;\;\;\frac{\frac{1}{x}}{y}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{\left(z \cdot x\right) \cdot \left(y \cdot z\right)}\\ \end{array} \]
Alternative 3
Error2.3
Cost840
\[\begin{array}{l} \mathbf{if}\;z \leq -1:\\ \;\;\;\;\frac{1}{z \cdot \left(y \cdot \left(z \cdot x\right)\right)}\\ \mathbf{elif}\;z \leq 1:\\ \;\;\;\;\frac{\frac{1}{x}}{y}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{\left(z \cdot x\right) \cdot \left(y \cdot z\right)}\\ \end{array} \]
Alternative 4
Error2.2
Cost840
\[\begin{array}{l} \mathbf{if}\;z \leq -1:\\ \;\;\;\;\frac{1}{z \cdot \left(y \cdot \left(z \cdot x\right)\right)}\\ \mathbf{elif}\;z \leq 1:\\ \;\;\;\;\frac{\frac{1}{x}}{y}\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{\frac{1}{x}}{z}}{y \cdot z}\\ \end{array} \]
Alternative 5
Error29.1
Cost320
\[\frac{\frac{1}{y}}{x} \]
Alternative 6
Error29.1
Cost320
\[\frac{1}{y \cdot x} \]

Error

Reproduce

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