Numeric.SpecFunctions:invIncompleteBetaWorker from math-functions-0.1.5.2, G

?

Percentage Accurate: 85.3% → 99.0%
Time: 11.1s
Precision: binary64
Cost: 60560

?

\[x + \frac{e^{y \cdot \log \left(\frac{y}{z + y}\right)}}{y} \]
\[\begin{array}{l} t_0 := x + \frac{e^{-z}}{y}\\ t_1 := \log \left(\frac{y}{y + z}\right)\\ t_2 := \frac{e^{y \cdot t_1}}{y}\\ t_3 := x + \frac{{\left(e^{y}\right)}^{t_1}}{y}\\ \mathbf{if}\;t_2 \leq -10000:\\ \;\;\;\;t_3\\ \mathbf{elif}\;t_2 \leq -5 \cdot 10^{-297}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;t_2 \leq 0:\\ \;\;\;\;t_3\\ \mathbf{elif}\;t_2 \leq 2 \cdot 10^{-29}:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;x + \frac{1}{y}\\ \end{array} \]
(FPCore (x y z)
 :precision binary64
 (+ x (/ (exp (* y (log (/ y (+ z y))))) y)))
(FPCore (x y z)
 :precision binary64
 (let* ((t_0 (+ x (/ (exp (- z)) y)))
        (t_1 (log (/ y (+ y z))))
        (t_2 (/ (exp (* y t_1)) y))
        (t_3 (+ x (/ (pow (exp y) t_1) y))))
   (if (<= t_2 -10000.0)
     t_3
     (if (<= t_2 -5e-297)
       t_0
       (if (<= t_2 0.0) t_3 (if (<= t_2 2e-29) t_0 (+ x (/ 1.0 y))))))))
double code(double x, double y, double z) {
	return x + (exp((y * log((y / (z + y))))) / y);
}
double code(double x, double y, double z) {
	double t_0 = x + (exp(-z) / y);
	double t_1 = log((y / (y + z)));
	double t_2 = exp((y * t_1)) / y;
	double t_3 = x + (pow(exp(y), t_1) / y);
	double tmp;
	if (t_2 <= -10000.0) {
		tmp = t_3;
	} else if (t_2 <= -5e-297) {
		tmp = t_0;
	} else if (t_2 <= 0.0) {
		tmp = t_3;
	} else if (t_2 <= 2e-29) {
		tmp = t_0;
	} else {
		tmp = x + (1.0 / y);
	}
	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 = x + (exp((y * log((y / (z + y))))) / y)
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) :: t_0
    real(8) :: t_1
    real(8) :: t_2
    real(8) :: t_3
    real(8) :: tmp
    t_0 = x + (exp(-z) / y)
    t_1 = log((y / (y + z)))
    t_2 = exp((y * t_1)) / y
    t_3 = x + ((exp(y) ** t_1) / y)
    if (t_2 <= (-10000.0d0)) then
        tmp = t_3
    else if (t_2 <= (-5d-297)) then
        tmp = t_0
    else if (t_2 <= 0.0d0) then
        tmp = t_3
    else if (t_2 <= 2d-29) then
        tmp = t_0
    else
        tmp = x + (1.0d0 / y)
    end if
    code = tmp
end function
public static double code(double x, double y, double z) {
	return x + (Math.exp((y * Math.log((y / (z + y))))) / y);
}
public static double code(double x, double y, double z) {
	double t_0 = x + (Math.exp(-z) / y);
	double t_1 = Math.log((y / (y + z)));
	double t_2 = Math.exp((y * t_1)) / y;
	double t_3 = x + (Math.pow(Math.exp(y), t_1) / y);
	double tmp;
	if (t_2 <= -10000.0) {
		tmp = t_3;
	} else if (t_2 <= -5e-297) {
		tmp = t_0;
	} else if (t_2 <= 0.0) {
		tmp = t_3;
	} else if (t_2 <= 2e-29) {
		tmp = t_0;
	} else {
		tmp = x + (1.0 / y);
	}
	return tmp;
}
def code(x, y, z):
	return x + (math.exp((y * math.log((y / (z + y))))) / y)
def code(x, y, z):
	t_0 = x + (math.exp(-z) / y)
	t_1 = math.log((y / (y + z)))
	t_2 = math.exp((y * t_1)) / y
	t_3 = x + (math.pow(math.exp(y), t_1) / y)
	tmp = 0
	if t_2 <= -10000.0:
		tmp = t_3
	elif t_2 <= -5e-297:
		tmp = t_0
	elif t_2 <= 0.0:
		tmp = t_3
	elif t_2 <= 2e-29:
		tmp = t_0
	else:
		tmp = x + (1.0 / y)
	return tmp
function code(x, y, z)
	return Float64(x + Float64(exp(Float64(y * log(Float64(y / Float64(z + y))))) / y))
end
function code(x, y, z)
	t_0 = Float64(x + Float64(exp(Float64(-z)) / y))
	t_1 = log(Float64(y / Float64(y + z)))
	t_2 = Float64(exp(Float64(y * t_1)) / y)
	t_3 = Float64(x + Float64((exp(y) ^ t_1) / y))
	tmp = 0.0
	if (t_2 <= -10000.0)
		tmp = t_3;
	elseif (t_2 <= -5e-297)
		tmp = t_0;
	elseif (t_2 <= 0.0)
		tmp = t_3;
	elseif (t_2 <= 2e-29)
		tmp = t_0;
	else
		tmp = Float64(x + Float64(1.0 / y));
	end
	return tmp
end
function tmp = code(x, y, z)
	tmp = x + (exp((y * log((y / (z + y))))) / y);
end
function tmp_2 = code(x, y, z)
	t_0 = x + (exp(-z) / y);
	t_1 = log((y / (y + z)));
	t_2 = exp((y * t_1)) / y;
	t_3 = x + ((exp(y) ^ t_1) / y);
	tmp = 0.0;
	if (t_2 <= -10000.0)
		tmp = t_3;
	elseif (t_2 <= -5e-297)
		tmp = t_0;
	elseif (t_2 <= 0.0)
		tmp = t_3;
	elseif (t_2 <= 2e-29)
		tmp = t_0;
	else
		tmp = x + (1.0 / y);
	end
	tmp_2 = tmp;
end
code[x_, y_, z_] := N[(x + N[(N[Exp[N[(y * N[Log[N[(y / N[(z + y), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]], $MachinePrecision] / y), $MachinePrecision]), $MachinePrecision]
code[x_, y_, z_] := Block[{t$95$0 = N[(x + N[(N[Exp[(-z)], $MachinePrecision] / y), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[Log[N[(y / N[(y + z), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$2 = N[(N[Exp[N[(y * t$95$1), $MachinePrecision]], $MachinePrecision] / y), $MachinePrecision]}, Block[{t$95$3 = N[(x + N[(N[Power[N[Exp[y], $MachinePrecision], t$95$1], $MachinePrecision] / y), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$2, -10000.0], t$95$3, If[LessEqual[t$95$2, -5e-297], t$95$0, If[LessEqual[t$95$2, 0.0], t$95$3, If[LessEqual[t$95$2, 2e-29], t$95$0, N[(x + N[(1.0 / y), $MachinePrecision]), $MachinePrecision]]]]]]]]]
x + \frac{e^{y \cdot \log \left(\frac{y}{z + y}\right)}}{y}
\begin{array}{l}
t_0 := x + \frac{e^{-z}}{y}\\
t_1 := \log \left(\frac{y}{y + z}\right)\\
t_2 := \frac{e^{y \cdot t_1}}{y}\\
t_3 := x + \frac{{\left(e^{y}\right)}^{t_1}}{y}\\
\mathbf{if}\;t_2 \leq -10000:\\
\;\;\;\;t_3\\

\mathbf{elif}\;t_2 \leq -5 \cdot 10^{-297}:\\
\;\;\;\;t_0\\

\mathbf{elif}\;t_2 \leq 0:\\
\;\;\;\;t_3\\

\mathbf{elif}\;t_2 \leq 2 \cdot 10^{-29}:\\
\;\;\;\;t_0\\

\mathbf{else}:\\
\;\;\;\;x + \frac{1}{y}\\


\end{array}

Local Percentage Accuracy?

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.

Try it out?

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original85.3%
Target91.4%
Herbie99.0%
\[\begin{array}{l} \mathbf{if}\;\frac{y}{z + y} < 7.11541576 \cdot 10^{-315}:\\ \;\;\;\;x + \frac{e^{\frac{-1}{z}}}{y}\\ \mathbf{else}:\\ \;\;\;\;x + \frac{e^{\log \left({\left(\frac{y}{y + z}\right)}^{y}\right)}}{y}\\ \end{array} \]

Derivation?

  1. Split input into 3 regimes
  2. if (/.f64 (exp.f64 (*.f64 y (log.f64 (/.f64 y (+.f64 z y))))) y) < -1e4 or -5e-297 < (/.f64 (exp.f64 (*.f64 y (log.f64 (/.f64 y (+.f64 z y))))) y) < 0.0

    1. Initial program 79.8%

      \[x + \frac{e^{y \cdot \log \left(\frac{y}{z + y}\right)}}{y} \]
    2. Simplified99.9%

      \[\leadsto \color{blue}{x + \frac{{\left(e^{y}\right)}^{\log \left(\frac{y}{y + z}\right)}}{y}} \]
      Step-by-step derivation

      [Start]79.8

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

      exp-prod [=>]99.9

      \[ x + \frac{\color{blue}{{\left(e^{y}\right)}^{\log \left(\frac{y}{z + y}\right)}}}{y} \]

      sqr-pow [=>]99.9

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

      sqr-pow [<=]99.9

      \[ x + \frac{\color{blue}{{\left(e^{y}\right)}^{\log \left(\frac{y}{z + y}\right)}}}{y} \]

      +-commutative [=>]99.9

      \[ x + \frac{{\left(e^{y}\right)}^{\log \left(\frac{y}{\color{blue}{y + z}}\right)}}{y} \]

    if -1e4 < (/.f64 (exp.f64 (*.f64 y (log.f64 (/.f64 y (+.f64 z y))))) y) < -5e-297 or 0.0 < (/.f64 (exp.f64 (*.f64 y (log.f64 (/.f64 y (+.f64 z y))))) y) < 1.99999999999999989e-29

    1. Initial program 81.3%

      \[x + \frac{e^{y \cdot \log \left(\frac{y}{z + y}\right)}}{y} \]
    2. Simplified81.3%

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

      [Start]81.3

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

      *-commutative [=>]81.3

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

      exp-prod [=>]81.3

      \[ x + \frac{\color{blue}{{\left(e^{\log \left(\frac{y}{z + y}\right)}\right)}^{y}}}{y} \]

      rem-exp-log [=>]81.3

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

      +-commutative [=>]81.3

      \[ x + \frac{{\left(\frac{y}{\color{blue}{y + z}}\right)}^{y}}{y} \]
    3. Taylor expanded in y around inf 100.0%

      \[\leadsto x + \frac{\color{blue}{e^{-1 \cdot z}}}{y} \]
    4. Simplified100.0%

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

      [Start]100.0

      \[ x + \frac{e^{-1 \cdot z}}{y} \]

      mul-1-neg [=>]100.0

      \[ x + \frac{e^{\color{blue}{-z}}}{y} \]

    if 1.99999999999999989e-29 < (/.f64 (exp.f64 (*.f64 y (log.f64 (/.f64 y (+.f64 z y))))) y)

    1. Initial program 100.0%

      \[x + \frac{e^{y \cdot \log \left(\frac{y}{z + y}\right)}}{y} \]
    2. Simplified100.0%

      \[\leadsto \color{blue}{x + \frac{{\left(e^{y}\right)}^{\log \left(\frac{y}{y + z}\right)}}{y}} \]
      Step-by-step derivation

      [Start]100.0

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

      exp-prod [=>]100.0

      \[ x + \frac{\color{blue}{{\left(e^{y}\right)}^{\log \left(\frac{y}{z + y}\right)}}}{y} \]

      sqr-pow [=>]100.0

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

      sqr-pow [<=]100.0

      \[ x + \frac{\color{blue}{{\left(e^{y}\right)}^{\log \left(\frac{y}{z + y}\right)}}}{y} \]

      +-commutative [=>]100.0

      \[ x + \frac{{\left(e^{y}\right)}^{\log \left(\frac{y}{\color{blue}{y + z}}\right)}}{y} \]
    3. Taylor expanded in y around 0 100.0%

      \[\leadsto x + \frac{\color{blue}{1}}{y} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification100.0%

    \[\leadsto \begin{array}{l} \mathbf{if}\;\frac{e^{y \cdot \log \left(\frac{y}{y + z}\right)}}{y} \leq -10000:\\ \;\;\;\;x + \frac{{\left(e^{y}\right)}^{\log \left(\frac{y}{y + z}\right)}}{y}\\ \mathbf{elif}\;\frac{e^{y \cdot \log \left(\frac{y}{y + z}\right)}}{y} \leq -5 \cdot 10^{-297}:\\ \;\;\;\;x + \frac{e^{-z}}{y}\\ \mathbf{elif}\;\frac{e^{y \cdot \log \left(\frac{y}{y + z}\right)}}{y} \leq 0:\\ \;\;\;\;x + \frac{{\left(e^{y}\right)}^{\log \left(\frac{y}{y + z}\right)}}{y}\\ \mathbf{elif}\;\frac{e^{y \cdot \log \left(\frac{y}{y + z}\right)}}{y} \leq 2 \cdot 10^{-29}:\\ \;\;\;\;x + \frac{e^{-z}}{y}\\ \mathbf{else}:\\ \;\;\;\;x + \frac{1}{y}\\ \end{array} \]

Alternatives

Alternative 1
Accuracy99.2%
Cost7049
\[\begin{array}{l} \mathbf{if}\;y \leq -92000000 \lor \neg \left(y \leq 2.3 \cdot 10^{-29}\right):\\ \;\;\;\;x + \frac{e^{-z}}{y}\\ \mathbf{else}:\\ \;\;\;\;x + \frac{1}{y}\\ \end{array} \]
Alternative 2
Accuracy66.6%
Cost456
\[\begin{array}{l} \mathbf{if}\;y \leq -2.3 \cdot 10^{-40}:\\ \;\;\;\;x\\ \mathbf{elif}\;y \leq 5.8 \cdot 10^{-109}:\\ \;\;\;\;\frac{1}{y}\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 3
Accuracy84.4%
Cost320
\[x + \frac{1}{y} \]
Alternative 4
Accuracy49.6%
Cost64
\[x \]

Error

Reproduce?

herbie shell --seed 2023160 
(FPCore (x y z)
  :name "Numeric.SpecFunctions:invIncompleteBetaWorker from math-functions-0.1.5.2, G"
  :precision binary64

  :herbie-target
  (if (< (/ y (+ z y)) 7.11541576e-315) (+ x (/ (exp (/ -1.0 z)) y)) (+ x (/ (exp (log (pow (/ y (+ y z)) y))) y)))

  (+ x (/ (exp (* y (log (/ y (+ z y))))) y)))