Statistics.Distribution.CauchyLorentz:$cdensity from math-functions-0.1.5.2

?

Percentage Accurate: 90.8% → 97.7%
Time: 14.8s
Precision: binary64
Cost: 964

?

\[ \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 \cdot z \leq 10^{+212}:\\ \;\;\;\;\frac{\frac{\frac{1}{x}}{y}}{1 + z \cdot z}\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{\frac{1}{y}}{z}}{x \cdot z}\\ \end{array} \]
(FPCore (x y z) :precision binary64 (/ (/ 1.0 x) (* y (+ 1.0 (* z z)))))
(FPCore (x y z)
 :precision binary64
 (if (<= (* z z) 1e+212)
   (/ (/ (/ 1.0 x) y) (+ 1.0 (* z z)))
   (/ (/ (/ 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 ((z * z) <= 1e+212) {
		tmp = ((1.0 / x) / y) / (1.0 + (z * z));
	} else {
		tmp = ((1.0 / y) / z) / (x * z);
	}
	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 ((z * z) <= 1d+212) then
        tmp = ((1.0d0 / x) / y) / (1.0d0 + (z * z))
    else
        tmp = ((1.0d0 / y) / z) / (x * z)
    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 ((z * z) <= 1e+212) {
		tmp = ((1.0 / x) / y) / (1.0 + (z * z));
	} else {
		tmp = ((1.0 / y) / z) / (x * z);
	}
	return tmp;
}
def code(x, y, z):
	return (1.0 / x) / (y * (1.0 + (z * z)))
def code(x, y, z):
	tmp = 0
	if (z * z) <= 1e+212:
		tmp = ((1.0 / x) / y) / (1.0 + (z * z))
	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(z * z) <= 1e+212)
		tmp = Float64(Float64(Float64(1.0 / x) / y) / Float64(1.0 + Float64(z * z)));
	else
		tmp = Float64(Float64(Float64(1.0 / y) / z) / Float64(x * z));
	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 ((z * z) <= 1e+212)
		tmp = ((1.0 / x) / y) / (1.0 + (z * z));
	else
		tmp = ((1.0 / y) / z) / (x * z);
	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[(z * z), $MachinePrecision], 1e+212], N[(N[(N[(1.0 / x), $MachinePrecision] / y), $MachinePrecision] / N[(1.0 + N[(z * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(N[(1.0 / y), $MachinePrecision] / z), $MachinePrecision] / N[(x * z), $MachinePrecision]), $MachinePrecision]]
\frac{\frac{1}{x}}{y \cdot \left(1 + z \cdot z\right)}
\begin{array}{l}
\mathbf{if}\;z \cdot z \leq 10^{+212}:\\
\;\;\;\;\frac{\frac{\frac{1}{x}}{y}}{1 + z \cdot z}\\

\mathbf{else}:\\
\;\;\;\;\frac{\frac{\frac{1}{y}}{z}}{x \cdot z}\\


\end{array}

Local Percentage Accuracy vs ?

The average percentage accuracy by input value. Horizontal axis shows value of an input variable; the variable is choosen in the title. Vertical axis is accuracy; higher is better. Red represent the original program, while blue represents Herbie's suggestion. These can be toggled with buttons below the plot. The line is an average while dots represent individual samples.

Herbie found 11 alternatives:

AlternativeAccuracySpeedup

Accuracy vs Speed

The accuracy (vertical axis) and speed (horizontal axis) of each alternatives. Up and to the right is better. The red square shows the initial program, and each blue circle shows an alternative.The line shows the best available speed-accuracy tradeoffs.

Bogosity?

Bogosity

Try it out?

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original90.8%
Target92.6%
Herbie97.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 z z) < 9.9999999999999991e211

    1. Initial program 99.0%

      \[\frac{\frac{1}{x}}{y \cdot \left(1 + z \cdot z\right)} \]
    2. Simplified99.0%

      \[\leadsto \color{blue}{\frac{\frac{\frac{1}{x}}{y}}{1 + z \cdot z}} \]
      Step-by-step derivation

      [Start]99.0%

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

      associate-/r* [=>]99.0%

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

    if 9.9999999999999991e211 < (*.f64 z z)

    1. Initial program 75.1%

      \[\frac{\frac{1}{x}}{y \cdot \left(1 + z \cdot z\right)} \]
    2. Simplified75.0%

      \[\leadsto \color{blue}{\frac{1}{x \cdot \left(y \cdot \mathsf{fma}\left(z, z, 1\right)\right)}} \]
      Step-by-step derivation

      [Start]75.1%

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

      associate-/r* [<=]75.0%

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

      +-commutative [=>]75.0%

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

      fma-def [=>]75.0%

      \[ \frac{1}{x \cdot \left(y \cdot \color{blue}{\mathsf{fma}\left(z, z, 1\right)}\right)} \]
    3. Taylor expanded in z around inf 76.9%

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

      \[\leadsto \frac{1}{\color{blue}{z \cdot \left(z \cdot \left(y \cdot x\right)\right)}} \]
      Step-by-step derivation

      [Start]76.9%

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

      unpow2 [=>]76.9%

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

      *-commutative [=>]76.9%

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

      associate-*l* [<=]73.5%

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

      *-commutative [=>]73.5%

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

      associate-*l* [=>]85.0%

      \[ \frac{1}{\color{blue}{z \cdot \left(z \cdot \left(y \cdot x\right)\right)}} \]
    5. Applied egg-rr94.9%

      \[\leadsto \color{blue}{\frac{\frac{1}{z}}{x \cdot \left(z \cdot y\right)} \cdot 1} \]
      Step-by-step derivation

      [Start]85.0%

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

      clear-num [=>]85.0%

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

      associate-/r/ [=>]85.0%

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

      associate-/r* [=>]85.7%

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

      associate-*r* [=>]94.9%

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

      *-commutative [=>]94.9%

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

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

      \[\leadsto \color{blue}{\frac{\frac{\frac{1}{y}}{z}}{z \cdot x}} \cdot 1 \]
      Step-by-step derivation

      [Start]76.9%

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

      associate-/r* [=>]76.9%

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

      unpow2 [=>]76.9%

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

      associate-*r* [<=]92.8%

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

      *-commutative [<=]92.8%

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

      associate-/r* [=>]97.9%

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

      *-commutative [=>]97.9%

      \[ \frac{\frac{\frac{1}{y}}{z}}{\color{blue}{z \cdot x}} \cdot 1 \]
  3. Recombined 2 regimes into one program.
  4. Final simplification98.6%

    \[\leadsto \begin{array}{l} \mathbf{if}\;z \cdot z \leq 10^{+212}:\\ \;\;\;\;\frac{\frac{\frac{1}{x}}{y}}{1 + z \cdot z}\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{\frac{1}{y}}{z}}{x \cdot z}\\ \end{array} \]

Alternatives

Alternative 1
Accuracy97.7%
Cost964
\[\begin{array}{l} \mathbf{if}\;z \cdot z \leq 10^{+212}:\\ \;\;\;\;\frac{\frac{\frac{1}{x}}{y}}{1 + z \cdot z}\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{\frac{1}{y}}{z}}{x \cdot z}\\ \end{array} \]
Alternative 2
Accuracy98.0%
Cost13632
\[\frac{\frac{1}{x}}{\mathsf{hypot}\left(1, z\right)} \cdot \frac{\frac{1}{y}}{\mathsf{hypot}\left(1, z\right)} \]
Alternative 3
Accuracy97.8%
Cost13504
\[\frac{\frac{1}{x \cdot \mathsf{hypot}\left(1, z\right)}}{\mathsf{hypot}\left(1, z\right) \cdot y} \]
Alternative 4
Accuracy97.8%
Cost964
\[\begin{array}{l} \mathbf{if}\;z \cdot z \leq 2 \cdot 10^{+168}:\\ \;\;\;\;\frac{\frac{1}{x}}{y \cdot \left(1 + z \cdot z\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{\frac{1}{y}}{z}}{x \cdot z}\\ \end{array} \]
Alternative 5
Accuracy93.8%
Cost836
\[\begin{array}{l} \mathbf{if}\;z \cdot z \leq 4 \cdot 10^{-11}:\\ \;\;\;\;\frac{\frac{1}{x}}{y}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{x \cdot \left(z \cdot \left(z \cdot y\right)\right)}\\ \end{array} \]
Alternative 6
Accuracy96.7%
Cost836
\[\begin{array}{l} \mathbf{if}\;z \cdot z \leq 4 \cdot 10^{-11}:\\ \;\;\;\;\frac{\frac{1}{x}}{y}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{z \cdot \left(y \cdot \left(x \cdot z\right)\right)}\\ \end{array} \]
Alternative 7
Accuracy96.8%
Cost836
\[\begin{array}{l} \mathbf{if}\;z \cdot z \leq 4 \cdot 10^{-11}:\\ \;\;\;\;\frac{\frac{1}{x}}{y}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{\left(x \cdot z\right) \cdot \left(z \cdot y\right)}\\ \end{array} \]
Alternative 8
Accuracy97.1%
Cost836
\[\begin{array}{l} \mathbf{if}\;z \cdot z \leq 4 \cdot 10^{-11}:\\ \;\;\;\;\frac{\frac{1}{x}}{y}\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{1}{z}}{x \cdot \left(z \cdot y\right)}\\ \end{array} \]
Alternative 9
Accuracy97.1%
Cost836
\[\begin{array}{l} \mathbf{if}\;z \cdot z \leq 4 \cdot 10^{-11}:\\ \;\;\;\;\frac{\frac{1}{x}}{y}\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{\frac{1}{y}}{z}}{x \cdot z}\\ \end{array} \]
Alternative 10
Accuracy58.6%
Cost320
\[\frac{1}{x \cdot y} \]
Alternative 11
Accuracy58.7%
Cost320
\[\frac{\frac{1}{x}}{y} \]

Reproduce?

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