
(FPCore (x y z) :precision binary64 (+ x (/ (exp (* y (log (/ y (+ z y))))) y)))
double code(double x, double y, double z) {
return x + (exp((y * log((y / (z + y))))) / y);
}
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
public static double code(double x, double y, double z) {
return x + (Math.exp((y * Math.log((y / (z + y))))) / y);
}
def code(x, y, z): return x + (math.exp((y * math.log((y / (z + y))))) / y)
function code(x, y, z) return Float64(x + Float64(exp(Float64(y * log(Float64(y / Float64(z + y))))) / y)) end
function tmp = code(x, y, z) tmp = x + (exp((y * log((y / (z + y))))) / y); 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]
\begin{array}{l}
\\
x + \frac{e^{y \cdot \log \left(\frac{y}{z + y}\right)}}{y}
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 5 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y z) :precision binary64 (+ x (/ (exp (* y (log (/ y (+ z y))))) y)))
double code(double x, double y, double z) {
return x + (exp((y * log((y / (z + y))))) / y);
}
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
public static double code(double x, double y, double z) {
return x + (Math.exp((y * Math.log((y / (z + y))))) / y);
}
def code(x, y, z): return x + (math.exp((y * math.log((y / (z + y))))) / y)
function code(x, y, z) return Float64(x + Float64(exp(Float64(y * log(Float64(y / Float64(z + y))))) / y)) end
function tmp = code(x, y, z) tmp = x + (exp((y * log((y / (z + y))))) / y); 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]
\begin{array}{l}
\\
x + \frac{e^{y \cdot \log \left(\frac{y}{z + y}\right)}}{y}
\end{array}
(FPCore (x y z) :precision binary64 (if (or (<= y -1.15e+124) (not (<= y 1.6e-45))) (+ (/ (exp (- z)) y) x) (+ x (/ (pow (exp y) (log (/ y (+ y z)))) y))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -1.15e+124) || !(y <= 1.6e-45)) {
tmp = (exp(-z) / y) + x;
} else {
tmp = x + (pow(exp(y), log((y / (y + z)))) / 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
real(8) :: tmp
if ((y <= (-1.15d+124)) .or. (.not. (y <= 1.6d-45))) then
tmp = (exp(-z) / y) + x
else
tmp = x + ((exp(y) ** log((y / (y + z)))) / y)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((y <= -1.15e+124) || !(y <= 1.6e-45)) {
tmp = (Math.exp(-z) / y) + x;
} else {
tmp = x + (Math.pow(Math.exp(y), Math.log((y / (y + z)))) / y);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -1.15e+124) or not (y <= 1.6e-45): tmp = (math.exp(-z) / y) + x else: tmp = x + (math.pow(math.exp(y), math.log((y / (y + z)))) / y) return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -1.15e+124) || !(y <= 1.6e-45)) tmp = Float64(Float64(exp(Float64(-z)) / y) + x); else tmp = Float64(x + Float64((exp(y) ^ log(Float64(y / Float64(y + z)))) / y)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -1.15e+124) || ~((y <= 1.6e-45))) tmp = (exp(-z) / y) + x; else tmp = x + ((exp(y) ^ log((y / (y + z)))) / y); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -1.15e+124], N[Not[LessEqual[y, 1.6e-45]], $MachinePrecision]], N[(N[(N[Exp[(-z)], $MachinePrecision] / y), $MachinePrecision] + x), $MachinePrecision], N[(x + N[(N[Power[N[Exp[y], $MachinePrecision], N[Log[N[(y / N[(y + z), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]], $MachinePrecision] / y), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.15 \cdot 10^{+124} \lor \neg \left(y \leq 1.6 \cdot 10^{-45}\right):\\
\;\;\;\;\frac{e^{-z}}{y} + x\\
\mathbf{else}:\\
\;\;\;\;x + \frac{{\left(e^{y}\right)}^{\log \left(\frac{y}{y + z}\right)}}{y}\\
\end{array}
\end{array}
if y < -1.14999999999999992e124 or 1.60000000000000004e-45 < y Initial program 78.7%
*-commutative78.7%
exp-to-pow78.7%
+-commutative78.7%
Simplified78.7%
Taylor expanded in y around inf 100.0%
+-commutative100.0%
mul-1-neg100.0%
Simplified100.0%
if -1.14999999999999992e124 < y < 1.60000000000000004e-45Initial program 85.5%
exp-prod99.8%
+-commutative99.8%
Simplified99.8%
Final simplification99.9%
(FPCore (x y z) :precision binary64 (if (or (<= y -1.2) (not (<= y 1.6e-45))) (+ (/ (exp (- z)) y) x) (+ x (/ 1.0 y))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -1.2) || !(y <= 1.6e-45)) {
tmp = (exp(-z) / y) + x;
} 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
real(8) :: tmp
if ((y <= (-1.2d0)) .or. (.not. (y <= 1.6d-45))) then
tmp = (exp(-z) / y) + x
else
tmp = x + (1.0d0 / y)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((y <= -1.2) || !(y <= 1.6e-45)) {
tmp = (Math.exp(-z) / y) + x;
} else {
tmp = x + (1.0 / y);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -1.2) or not (y <= 1.6e-45): tmp = (math.exp(-z) / y) + x else: tmp = x + (1.0 / y) return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -1.2) || !(y <= 1.6e-45)) tmp = Float64(Float64(exp(Float64(-z)) / y) + x); else tmp = Float64(x + Float64(1.0 / y)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -1.2) || ~((y <= 1.6e-45))) tmp = (exp(-z) / y) + x; else tmp = x + (1.0 / y); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -1.2], N[Not[LessEqual[y, 1.6e-45]], $MachinePrecision]], N[(N[(N[Exp[(-z)], $MachinePrecision] / y), $MachinePrecision] + x), $MachinePrecision], N[(x + N[(1.0 / y), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.2 \lor \neg \left(y \leq 1.6 \cdot 10^{-45}\right):\\
\;\;\;\;\frac{e^{-z}}{y} + x\\
\mathbf{else}:\\
\;\;\;\;x + \frac{1}{y}\\
\end{array}
\end{array}
if y < -1.19999999999999996 or 1.60000000000000004e-45 < y Initial program 82.8%
*-commutative82.8%
exp-to-pow82.8%
+-commutative82.8%
Simplified82.8%
Taylor expanded in y around inf 100.0%
+-commutative100.0%
mul-1-neg100.0%
Simplified100.0%
if -1.19999999999999996 < y < 1.60000000000000004e-45Initial program 81.8%
*-commutative81.8%
exp-to-pow81.8%
+-commutative81.8%
Simplified81.8%
Taylor expanded in z around 0 99.3%
+-commutative99.3%
Simplified99.3%
Final simplification99.7%
(FPCore (x y z) :precision binary64 (if (<= y -29000000.0) x (if (<= y 1.75e-131) (/ 1.0 y) x)))
double code(double x, double y, double z) {
double tmp;
if (y <= -29000000.0) {
tmp = x;
} else if (y <= 1.75e-131) {
tmp = 1.0 / y;
} else {
tmp = 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
real(8) :: tmp
if (y <= (-29000000.0d0)) then
tmp = x
else if (y <= 1.75d-131) then
tmp = 1.0d0 / y
else
tmp = x
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (y <= -29000000.0) {
tmp = x;
} else if (y <= 1.75e-131) {
tmp = 1.0 / y;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -29000000.0: tmp = x elif y <= 1.75e-131: tmp = 1.0 / y else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if (y <= -29000000.0) tmp = x; elseif (y <= 1.75e-131) tmp = Float64(1.0 / y); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= -29000000.0) tmp = x; elseif (y <= 1.75e-131) tmp = 1.0 / y; else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -29000000.0], x, If[LessEqual[y, 1.75e-131], N[(1.0 / y), $MachinePrecision], x]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -29000000:\\
\;\;\;\;x\\
\mathbf{elif}\;y \leq 1.75 \cdot 10^{-131}:\\
\;\;\;\;\frac{1}{y}\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if y < -2.9e7 or 1.7500000000000001e-131 < y Initial program 83.8%
*-commutative83.8%
exp-to-pow83.8%
+-commutative83.8%
Simplified83.8%
Taylor expanded in x around inf 65.4%
if -2.9e7 < y < 1.7500000000000001e-131Initial program 79.9%
*-commutative79.9%
exp-to-pow79.9%
+-commutative79.9%
Simplified79.9%
Taylor expanded in z around 0 98.1%
+-commutative98.1%
Simplified98.1%
Taylor expanded in y around 0 85.1%
Final simplification72.7%
(FPCore (x y z) :precision binary64 (+ x (/ 1.0 y)))
double code(double x, double y, double z) {
return x + (1.0 / y);
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = x + (1.0d0 / y)
end function
public static double code(double x, double y, double z) {
return x + (1.0 / y);
}
def code(x, y, z): return x + (1.0 / y)
function code(x, y, z) return Float64(x + Float64(1.0 / y)) end
function tmp = code(x, y, z) tmp = x + (1.0 / y); end
code[x_, y_, z_] := N[(x + N[(1.0 / y), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x + \frac{1}{y}
\end{array}
Initial program 82.3%
*-commutative82.3%
exp-to-pow82.3%
+-commutative82.3%
Simplified82.3%
Taylor expanded in z around 0 83.8%
+-commutative83.8%
Simplified83.8%
Final simplification83.8%
(FPCore (x y z) :precision binary64 x)
double code(double x, double y, double z) {
return x;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = x
end function
public static double code(double x, double y, double z) {
return x;
}
def code(x, y, z): return x
function code(x, y, z) return x end
function tmp = code(x, y, z) tmp = x; end
code[x_, y_, z_] := x
\begin{array}{l}
\\
x
\end{array}
Initial program 82.3%
*-commutative82.3%
exp-to-pow82.3%
+-commutative82.3%
Simplified82.3%
Taylor expanded in x around inf 46.1%
Final simplification46.1%
(FPCore (x y z) :precision binary64 (if (< (/ y (+ z y)) 7.11541576e-315) (+ x (/ (exp (/ -1.0 z)) y)) (+ x (/ (exp (log (pow (/ y (+ y z)) y))) y))))
double code(double x, double y, double z) {
double tmp;
if ((y / (z + y)) < 7.11541576e-315) {
tmp = x + (exp((-1.0 / z)) / y);
} else {
tmp = x + (exp(log(pow((y / (y + z)), y))) / 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
real(8) :: tmp
if ((y / (z + y)) < 7.11541576d-315) then
tmp = x + (exp(((-1.0d0) / z)) / y)
else
tmp = x + (exp(log(((y / (y + z)) ** y))) / y)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((y / (z + y)) < 7.11541576e-315) {
tmp = x + (Math.exp((-1.0 / z)) / y);
} else {
tmp = x + (Math.exp(Math.log(Math.pow((y / (y + z)), y))) / y);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y / (z + y)) < 7.11541576e-315: tmp = x + (math.exp((-1.0 / z)) / y) else: tmp = x + (math.exp(math.log(math.pow((y / (y + z)), y))) / y) return tmp
function code(x, y, z) tmp = 0.0 if (Float64(y / Float64(z + y)) < 7.11541576e-315) tmp = Float64(x + Float64(exp(Float64(-1.0 / z)) / y)); else tmp = Float64(x + Float64(exp(log((Float64(y / Float64(y + z)) ^ y))) / y)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y / (z + y)) < 7.11541576e-315) tmp = x + (exp((-1.0 / z)) / y); else tmp = x + (exp(log(((y / (y + z)) ^ y))) / y); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Less[N[(y / N[(z + y), $MachinePrecision]), $MachinePrecision], 7.11541576e-315], N[(x + N[(N[Exp[N[(-1.0 / z), $MachinePrecision]], $MachinePrecision] / y), $MachinePrecision]), $MachinePrecision], N[(x + N[(N[Exp[N[Log[N[Power[N[(y / N[(y + z), $MachinePrecision]), $MachinePrecision], y], $MachinePrecision]], $MachinePrecision]], $MachinePrecision] / y), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\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}
\end{array}
herbie shell --seed 2024036
(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)))