?

Average Error: 6.6 → 1.7
Time: 14.1s
Precision: binary64
Cost: 968

?

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

\mathbf{elif}\;z \leq 8.2 \cdot 10^{+58}:\\
\;\;\;\;\frac{\frac{1}{x}}{y \cdot \left(1 + z \cdot z\right)}\\

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


\end{array}

Error?

Try it out?

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original6.6
Target5.2
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 < -1.6e54

    1. Initial program 14.4

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

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

      [Start]14.4

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

      associate-/r* [=>]14.3

      \[ \color{blue}{\frac{\frac{\frac{1}{x}}{y}}{1 + z \cdot z}} \]
    3. Taylor expanded in z around inf 14.4

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

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

      [Start]14.4

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

      associate-/r* [=>]14.3

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

      unpow2 [=>]14.3

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

      associate-*l* [=>]7.5

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

      \[\leadsto \color{blue}{\frac{1}{z \cdot x} \cdot \frac{1}{y \cdot z}} \]
    6. Applied egg-rr2.6

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

    if -1.6e54 < z < 8.2e58

    1. Initial program 0.7

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

    if 8.2e58 < z

    1. Initial program 13.5

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

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

      [Start]13.5

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

      associate-/l/ [=>]13.6

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

      associate-*l* [=>]14.1

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

      +-commutative [=>]14.1

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

      fma-def [=>]14.1

      \[ \frac{1}{y \cdot \left(\color{blue}{\mathsf{fma}\left(z, z, 1\right)} \cdot x\right)} \]
    3. Applied egg-rr14.1

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

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

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

      [Start]14.1

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

      *-commutative [=>]14.1

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

      *-commutative [=>]14.1

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

      unpow2 [=>]14.1

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

      associate-*r* [=>]8.0

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

      associate-*l* [=>]3.6

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

      *-commutative [=>]3.6

      \[ \frac{1}{\color{blue}{\left(z \cdot x\right)} \cdot \left(z \cdot y\right)} \]
    6. Applied egg-rr3.3

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;z \leq -1.6 \cdot 10^{+54}:\\ \;\;\;\;\frac{\frac{1}{z}}{x \cdot \left(y \cdot z\right)}\\ \mathbf{elif}\;z \leq 8.2 \cdot 10^{+58}:\\ \;\;\;\;\frac{\frac{1}{x}}{y \cdot \left(1 + z \cdot z\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{\frac{z}{\frac{\frac{1}{y}}{z \cdot x}}}\\ \end{array} \]

Alternatives

Alternative 1
Error1.3
Cost13764
\[\begin{array}{l} \mathbf{if}\;y \leq 1.16 \cdot 10^{-42}:\\ \;\;\;\;\frac{1}{\frac{\mathsf{hypot}\left(1, z\right)}{\frac{\frac{\frac{1}{y}}{\mathsf{hypot}\left(1, z\right)}}{x}}}\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{1}{\mathsf{hypot}\left(1, z\right) \cdot \left(y \cdot x\right)}}{\mathsf{hypot}\left(1, z\right)}\\ \end{array} \]
Alternative 2
Error1.9
Cost969
\[\begin{array}{l} \mathbf{if}\;z \leq -2 \cdot 10^{+57} \lor \neg \left(z \leq 5 \cdot 10^{+126}\right):\\ \;\;\;\;\frac{\frac{1}{z}}{x \cdot \left(y \cdot z\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{y \cdot \left(x + x \cdot \left(z \cdot z\right)\right)}\\ \end{array} \]
Alternative 3
Error2.0
Cost968
\[\begin{array}{l} \mathbf{if}\;z \leq -3.2 \cdot 10^{+55}:\\ \;\;\;\;\frac{\frac{1}{z}}{x \cdot \left(y \cdot z\right)}\\ \mathbf{elif}\;z \leq 2.1 \cdot 10^{+129}:\\ \;\;\;\;\frac{1}{y \cdot \left(x + x \cdot \left(z \cdot z\right)\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{\frac{z}{\frac{\frac{1}{y}}{z \cdot x}}}\\ \end{array} \]
Alternative 4
Error4.4
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}{x}}{y}\\ \end{array} \]
Alternative 5
Error4.2
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}{x}}{y}\\ \end{array} \]
Alternative 6
Error4.4
Cost840
\[\begin{array}{l} \mathbf{if}\;z \leq -1:\\ \;\;\;\;\frac{1}{x \cdot \left(z \cdot \left(y \cdot z\right)\right)}\\ \mathbf{elif}\;z \leq 1:\\ \;\;\;\;\frac{\frac{1}{x}}{y}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{y \cdot \left(z \cdot \left(z \cdot x\right)\right)}\\ \end{array} \]
Alternative 7
Error3.4
Cost840
\[\begin{array}{l} \mathbf{if}\;z \leq -1:\\ \;\;\;\;\frac{1}{z \cdot \left(z \cdot \left(y \cdot x\right)\right)}\\ \mathbf{elif}\;z \leq 1:\\ \;\;\;\;\frac{\frac{1}{x}}{y}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{\left(y \cdot z\right) \cdot \left(z \cdot x\right)}\\ \end{array} \]
Alternative 8
Error3.4
Cost840
\[\begin{array}{l} \mathbf{if}\;z \leq -0.86:\\ \;\;\;\;\frac{1}{z \cdot \left(z \cdot \left(y \cdot x\right)\right)}\\ \mathbf{elif}\;z \leq 0.86:\\ \;\;\;\;\frac{1 - z \cdot z}{y \cdot x}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{\left(y \cdot z\right) \cdot \left(z \cdot x\right)}\\ \end{array} \]
Alternative 9
Error2.2
Cost840
\[\begin{array}{l} t_0 := x \cdot \left(y \cdot z\right)\\ \mathbf{if}\;z \leq -0.86:\\ \;\;\;\;\frac{\frac{1}{t_0}}{z}\\ \mathbf{elif}\;z \leq 0.86:\\ \;\;\;\;\frac{1 - z \cdot z}{y \cdot x}\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{1}{z}}{t_0}\\ \end{array} \]
Alternative 10
Error2.2
Cost836
\[\begin{array}{l} \mathbf{if}\;z \cdot z \leq 4 \cdot 10^{-7}:\\ \;\;\;\;\frac{1 - z \cdot z}{y \cdot x}\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{1}{z}}{x \cdot \left(y \cdot z\right)}\\ \end{array} \]
Alternative 11
Error21.1
Cost713
\[\begin{array}{l} \mathbf{if}\;z \leq -9 \cdot 10^{+82} \lor \neg \left(z \leq 1\right):\\ \;\;\;\;\frac{1}{y \cdot \left(z \cdot x\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{1}{x}}{y}\\ \end{array} \]
Alternative 12
Error28.8
Cost320
\[\frac{1}{y \cdot x} \]

Error

Reproduce?

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