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

?

Percentage Accurate: 91.3% → 97.6%
Time: 11.0s
Precision: binary64
Cost: 964

?

\[\frac{\frac{1}{x}}{y \cdot \left(1 + z \cdot z\right)} \]
\[\begin{array}{l} [x, y] = \mathsf{sort}([x, y])\\ \\ \begin{array}{l} \mathbf{if}\;z \cdot z \leq 2 \cdot 10^{+107}:\\ \;\;\;\;\frac{\frac{1}{x}}{y \cdot \left(1 + z \cdot z\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{1}{y \cdot \left(x \cdot z\right)}}{z}\\ \end{array} \end{array} \]
(FPCore (x y z) :precision binary64 (/ (/ 1.0 x) (* y (+ 1.0 (* z z)))))
NOTE: x and y should be sorted in increasing order before calling this function.
(FPCore (x y z)
 :precision binary64
 (if (<= (* z z) 2e+107)
   (/ (/ 1.0 x) (* y (+ 1.0 (* z z))))
   (/ (/ 1.0 (* y (* x z))) z)))
double code(double x, double y, double z) {
	return (1.0 / x) / (y * (1.0 + (z * z)));
}
assert(x < y);
double code(double x, double y, double z) {
	double tmp;
	if ((z * z) <= 2e+107) {
		tmp = (1.0 / x) / (y * (1.0 + (z * z)));
	} else {
		tmp = (1.0 / (y * (x * z))) / 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
NOTE: x and y should be sorted in increasing order before calling this 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) <= 2d+107) then
        tmp = (1.0d0 / x) / (y * (1.0d0 + (z * z)))
    else
        tmp = (1.0d0 / (y * (x * z))) / 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)));
}
assert x < y;
public static double code(double x, double y, double z) {
	double tmp;
	if ((z * z) <= 2e+107) {
		tmp = (1.0 / x) / (y * (1.0 + (z * z)));
	} else {
		tmp = (1.0 / (y * (x * z))) / z;
	}
	return tmp;
}
def code(x, y, z):
	return (1.0 / x) / (y * (1.0 + (z * z)))
[x, y] = sort([x, y])
def code(x, y, z):
	tmp = 0
	if (z * z) <= 2e+107:
		tmp = (1.0 / x) / (y * (1.0 + (z * z)))
	else:
		tmp = (1.0 / (y * (x * z))) / z
	return tmp
function code(x, y, z)
	return Float64(Float64(1.0 / x) / Float64(y * Float64(1.0 + Float64(z * z))))
end
x, y = sort([x, y])
function code(x, y, z)
	tmp = 0.0
	if (Float64(z * z) <= 2e+107)
		tmp = Float64(Float64(1.0 / x) / Float64(y * Float64(1.0 + Float64(z * z))));
	else
		tmp = Float64(Float64(1.0 / Float64(y * Float64(x * z))) / z);
	end
	return tmp
end
function tmp = code(x, y, z)
	tmp = (1.0 / x) / (y * (1.0 + (z * z)));
end
x, y = num2cell(sort([x, y])){:}
function tmp_2 = code(x, y, z)
	tmp = 0.0;
	if ((z * z) <= 2e+107)
		tmp = (1.0 / x) / (y * (1.0 + (z * z)));
	else
		tmp = (1.0 / (y * (x * z))) / 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]
NOTE: x and y should be sorted in increasing order before calling this function.
code[x_, y_, z_] := If[LessEqual[N[(z * z), $MachinePrecision], 2e+107], N[(N[(1.0 / x), $MachinePrecision] / N[(y * N[(1.0 + N[(z * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(1.0 / N[(y * N[(x * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / z), $MachinePrecision]]
\frac{\frac{1}{x}}{y \cdot \left(1 + z \cdot z\right)}
\begin{array}{l}
[x, y] = \mathsf{sort}([x, y])\\
\\
\begin{array}{l}
\mathbf{if}\;z \cdot z \leq 2 \cdot 10^{+107}:\\
\;\;\;\;\frac{\frac{1}{x}}{y \cdot \left(1 + z \cdot z\right)}\\

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


\end{array}
\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

Original91.3%
Target93.2%
Herbie97.6%
\[\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) < 1.9999999999999999e107

    1. Initial program 99.6%

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

    if 1.9999999999999999e107 < (*.f64 z z)

    1. Initial program 77.9%

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

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

      [Start]77.9%

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

      associate-/r* [<=]77.2%

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

      +-commutative [=>]77.2%

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

      fma-def [=>]77.2%

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

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

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

      [Start]75.2%

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

      unpow2 [=>]75.2%

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

      fma-udef [<=]75.2%

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

      *-commutative [<=]75.2%

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

      associate-*r* [<=]71.5%

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

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

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

      [Start]71.5%

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

      unpow2 [=>]71.5%

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

      associate-*l* [=>]85.4%

      \[ \frac{1}{y \cdot \color{blue}{\left(z \cdot \left(z \cdot x\right)\right)}} \]
    7. Applied egg-rr96.2%

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

      [Start]85.4%

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

      associate-*r* [=>]71.5%

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

      associate-/r* [=>]73.1%

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

      *-un-lft-identity [=>]73.1%

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

      associate-*r* [<=]87.2%

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

      *-commutative [=>]87.2%

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

      times-frac [=>]96.2%

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

      *-commutative [=>]96.2%

      \[ \frac{1}{\color{blue}{x \cdot z}} \cdot \frac{\frac{1}{y}}{z} \]
    8. Applied egg-rr97.2%

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

      [Start]96.2%

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

      associate-*r/ [=>]97.2%

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

      frac-times [=>]97.2%

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

      metadata-eval [=>]97.2%

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

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

Alternatives

Alternative 1
Accuracy97.6%
Cost964
\[\begin{array}{l} \mathbf{if}\;z \cdot z \leq 2 \cdot 10^{+107}:\\ \;\;\;\;\frac{\frac{1}{x}}{y \cdot \left(1 + z \cdot z\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{1}{y \cdot \left(x \cdot z\right)}}{z}\\ \end{array} \]
Alternative 2
Accuracy97.8%
Cost13504
\[\frac{\frac{\frac{1}{y}}{x \cdot \mathsf{hypot}\left(1, z\right)}}{\mathsf{hypot}\left(1, z\right)} \]
Alternative 3
Accuracy97.5%
Cost964
\[\begin{array}{l} \mathbf{if}\;z \cdot z \leq 4 \cdot 10^{+39}:\\ \;\;\;\;\frac{1}{x \cdot \left(y + y \cdot \left(z \cdot z\right)\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{1}{y \cdot \left(x \cdot z\right)}}{z}\\ \end{array} \]
Alternative 4
Accuracy97.6%
Cost964
\[\begin{array}{l} \mathbf{if}\;z \cdot z \leq 4 \cdot 10^{+39}:\\ \;\;\;\;\frac{1}{y \cdot \left(x + x \cdot \left(z \cdot z\right)\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{1}{y \cdot \left(x \cdot z\right)}}{z}\\ \end{array} \]
Alternative 5
Accuracy93.8%
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
Accuracy93.4%
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{\frac{1}{y}}{x}\\ \end{array} \]
Alternative 7
Accuracy96.8%
Cost841
\[\begin{array}{l} \mathbf{if}\;z \leq -1 \lor \neg \left(z \leq 1\right):\\ \;\;\;\;\frac{1}{z \cdot \left(x \cdot \left(y \cdot z\right)\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{1}{y}}{x}\\ \end{array} \]
Alternative 8
Accuracy96.8%
Cost836
\[\begin{array}{l} \mathbf{if}\;z \cdot z \leq 0.0002:\\ \;\;\;\;\frac{1 - z \cdot z}{y \cdot x}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{z \cdot \left(x \cdot \left(y \cdot z\right)\right)}\\ \end{array} \]
Alternative 9
Accuracy96.7%
Cost836
\[\begin{array}{l} \mathbf{if}\;z \cdot z \leq 0.0002:\\ \;\;\;\;\frac{1 - z \cdot z}{y \cdot x}\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{1}{x \cdot z}}{y \cdot z}\\ \end{array} \]
Alternative 10
Accuracy96.8%
Cost836
\[\begin{array}{l} \mathbf{if}\;z \cdot z \leq 0.0002:\\ \;\;\;\;\frac{1 - z \cdot z}{y \cdot x}\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{1}{y \cdot \left(x \cdot z\right)}}{z}\\ \end{array} \]
Alternative 11
Accuracy58.8%
Cost320
\[\frac{1}{y \cdot x} \]

Reproduce?

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