
(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 7 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
(let* ((t_0 (+ x (/ 1.0 y))))
(if (<= y -1.02e+194)
t_0
(if (<= y -1.26)
(+ x (/ 1.0 (* y (exp z))))
(if (<= y 7.2e-20) t_0 (+ x (/ (exp (- z)) y)))))))
double code(double x, double y, double z) {
double t_0 = x + (1.0 / y);
double tmp;
if (y <= -1.02e+194) {
tmp = t_0;
} else if (y <= -1.26) {
tmp = x + (1.0 / (y * exp(z)));
} else if (y <= 7.2e-20) {
tmp = t_0;
} else {
tmp = x + (exp(-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) :: t_0
real(8) :: tmp
t_0 = x + (1.0d0 / y)
if (y <= (-1.02d+194)) then
tmp = t_0
else if (y <= (-1.26d0)) then
tmp = x + (1.0d0 / (y * exp(z)))
else if (y <= 7.2d-20) then
tmp = t_0
else
tmp = x + (exp(-z) / y)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double t_0 = x + (1.0 / y);
double tmp;
if (y <= -1.02e+194) {
tmp = t_0;
} else if (y <= -1.26) {
tmp = x + (1.0 / (y * Math.exp(z)));
} else if (y <= 7.2e-20) {
tmp = t_0;
} else {
tmp = x + (Math.exp(-z) / y);
}
return tmp;
}
def code(x, y, z): t_0 = x + (1.0 / y) tmp = 0 if y <= -1.02e+194: tmp = t_0 elif y <= -1.26: tmp = x + (1.0 / (y * math.exp(z))) elif y <= 7.2e-20: tmp = t_0 else: tmp = x + (math.exp(-z) / y) return tmp
function code(x, y, z) t_0 = Float64(x + Float64(1.0 / y)) tmp = 0.0 if (y <= -1.02e+194) tmp = t_0; elseif (y <= -1.26) tmp = Float64(x + Float64(1.0 / Float64(y * exp(z)))); elseif (y <= 7.2e-20) tmp = t_0; else tmp = Float64(x + Float64(exp(Float64(-z)) / y)); end return tmp end
function tmp_2 = code(x, y, z) t_0 = x + (1.0 / y); tmp = 0.0; if (y <= -1.02e+194) tmp = t_0; elseif (y <= -1.26) tmp = x + (1.0 / (y * exp(z))); elseif (y <= 7.2e-20) tmp = t_0; else tmp = x + (exp(-z) / y); end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(x + N[(1.0 / y), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[y, -1.02e+194], t$95$0, If[LessEqual[y, -1.26], N[(x + N[(1.0 / N[(y * N[Exp[z], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[y, 7.2e-20], t$95$0, N[(x + N[(N[Exp[(-z)], $MachinePrecision] / y), $MachinePrecision]), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := x + \frac{1}{y}\\
\mathbf{if}\;y \leq -1.02 \cdot 10^{+194}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq -1.26:\\
\;\;\;\;x + \frac{1}{y \cdot e^{z}}\\
\mathbf{elif}\;y \leq 7.2 \cdot 10^{-20}:\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;x + \frac{e^{-z}}{y}\\
\end{array}
\end{array}
if y < -1.02e194 or -1.26000000000000001 < y < 7.19999999999999948e-20Initial program 89.7%
exp-prod99.2%
+-commutative99.2%
Simplified99.2%
Taylor expanded in y around inf 99.2%
+-commutative99.2%
Simplified99.2%
if -1.02e194 < y < -1.26000000000000001Initial program 95.1%
*-commutative95.1%
exp-to-pow95.1%
+-commutative95.1%
Simplified95.1%
Taylor expanded in y around inf 97.6%
mul-1-neg97.6%
Simplified97.6%
clear-num97.6%
inv-pow97.6%
exp-neg97.6%
associate-/r/97.6%
/-rgt-identity97.6%
Applied egg-rr97.6%
Taylor expanded in y around 0 97.6%
if 7.19999999999999948e-20 < y Initial program 94.7%
*-commutative94.7%
exp-to-pow94.7%
+-commutative94.7%
Simplified94.7%
Taylor expanded in y around inf 93.6%
mul-1-neg93.6%
Simplified93.6%
Final simplification97.2%
(FPCore (x y z) :precision binary64 (+ x (/ (pow (exp y) (log (/ y (+ y z)))) y)))
double code(double x, double y, double z) {
return x + (pow(exp(y), log((y / (y + z)))) / 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 / (y + z)))) / y)
end function
public static double code(double x, double y, double z) {
return x + (Math.pow(Math.exp(y), Math.log((y / (y + z)))) / y);
}
def code(x, y, z): return x + (math.pow(math.exp(y), math.log((y / (y + z)))) / y)
function code(x, y, z) return Float64(x + Float64((exp(y) ^ log(Float64(y / Float64(y + z)))) / y)) end
function tmp = code(x, y, z) tmp = x + ((exp(y) ^ log((y / (y + z)))) / y); end
code[x_, y_, z_] := 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}
\\
x + \frac{{\left(e^{y}\right)}^{\log \left(\frac{y}{y + z}\right)}}{y}
\end{array}
Initial program 92.3%
exp-prod97.1%
+-commutative97.1%
Simplified97.1%
Final simplification97.1%
(FPCore (x y z) :precision binary64 (if (or (<= y -4.4e+191) (and (not (<= y -1.38)) (<= y 7.2e-20))) (+ x (/ 1.0 y)) (+ x (/ (exp (- z)) y))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -4.4e+191) || (!(y <= -1.38) && (y <= 7.2e-20))) {
tmp = x + (1.0 / y);
} else {
tmp = x + (exp(-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 <= (-4.4d+191)) .or. (.not. (y <= (-1.38d0))) .and. (y <= 7.2d-20)) then
tmp = x + (1.0d0 / y)
else
tmp = x + (exp(-z) / y)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((y <= -4.4e+191) || (!(y <= -1.38) && (y <= 7.2e-20))) {
tmp = x + (1.0 / y);
} else {
tmp = x + (Math.exp(-z) / y);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -4.4e+191) or (not (y <= -1.38) and (y <= 7.2e-20)): tmp = x + (1.0 / y) else: tmp = x + (math.exp(-z) / y) return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -4.4e+191) || (!(y <= -1.38) && (y <= 7.2e-20))) tmp = Float64(x + Float64(1.0 / y)); else tmp = Float64(x + Float64(exp(Float64(-z)) / y)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -4.4e+191) || (~((y <= -1.38)) && (y <= 7.2e-20))) tmp = x + (1.0 / y); else tmp = x + (exp(-z) / y); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -4.4e+191], And[N[Not[LessEqual[y, -1.38]], $MachinePrecision], LessEqual[y, 7.2e-20]]], N[(x + N[(1.0 / y), $MachinePrecision]), $MachinePrecision], N[(x + N[(N[Exp[(-z)], $MachinePrecision] / y), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -4.4 \cdot 10^{+191} \lor \neg \left(y \leq -1.38\right) \land y \leq 7.2 \cdot 10^{-20}:\\
\;\;\;\;x + \frac{1}{y}\\
\mathbf{else}:\\
\;\;\;\;x + \frac{e^{-z}}{y}\\
\end{array}
\end{array}
if y < -4.4e191 or -1.3799999999999999 < y < 7.19999999999999948e-20Initial program 89.7%
exp-prod99.2%
+-commutative99.2%
Simplified99.2%
Taylor expanded in y around inf 99.2%
+-commutative99.2%
Simplified99.2%
if -4.4e191 < y < -1.3799999999999999 or 7.19999999999999948e-20 < y Initial program 94.9%
*-commutative94.9%
exp-to-pow94.9%
+-commutative94.9%
Simplified94.9%
Taylor expanded in y around inf 95.2%
mul-1-neg95.2%
Simplified95.2%
Final simplification97.2%
(FPCore (x y z) :precision binary64 (if (or (<= y -0.0002) (not (<= y 1e-60))) (+ x (/ (pow (/ y (+ y z)) y) y)) (+ x (/ 1.0 y))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -0.0002) || !(y <= 1e-60)) {
tmp = x + (pow((y / (y + z)), y) / y);
} 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 <= (-0.0002d0)) .or. (.not. (y <= 1d-60))) then
tmp = x + (((y / (y + z)) ** y) / y)
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 <= -0.0002) || !(y <= 1e-60)) {
tmp = x + (Math.pow((y / (y + z)), y) / y);
} else {
tmp = x + (1.0 / y);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -0.0002) or not (y <= 1e-60): tmp = x + (math.pow((y / (y + z)), y) / y) else: tmp = x + (1.0 / y) return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -0.0002) || !(y <= 1e-60)) tmp = Float64(x + Float64((Float64(y / Float64(y + z)) ^ y) / y)); else tmp = Float64(x + Float64(1.0 / y)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -0.0002) || ~((y <= 1e-60))) tmp = x + (((y / (y + z)) ^ y) / y); else tmp = x + (1.0 / y); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -0.0002], N[Not[LessEqual[y, 1e-60]], $MachinePrecision]], N[(x + N[(N[Power[N[(y / N[(y + z), $MachinePrecision]), $MachinePrecision], y], $MachinePrecision] / y), $MachinePrecision]), $MachinePrecision], N[(x + N[(1.0 / y), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -0.0002 \lor \neg \left(y \leq 10^{-60}\right):\\
\;\;\;\;x + \frac{{\left(\frac{y}{y + z}\right)}^{y}}{y}\\
\mathbf{else}:\\
\;\;\;\;x + \frac{1}{y}\\
\end{array}
\end{array}
if y < -2.0000000000000001e-4 or 9.9999999999999997e-61 < y Initial program 95.7%
*-commutative95.7%
exp-to-pow95.7%
+-commutative95.7%
Simplified95.7%
if -2.0000000000000001e-4 < y < 9.9999999999999997e-61Initial program 84.6%
exp-prod100.0%
+-commutative100.0%
Simplified100.0%
Taylor expanded in y around inf 100.0%
+-commutative100.0%
Simplified100.0%
Final simplification97.1%
(FPCore (x y z) :precision binary64 (if (<= y -6.8e+15) x (if (<= y 0.078) (/ 1.0 y) x)))
double code(double x, double y, double z) {
double tmp;
if (y <= -6.8e+15) {
tmp = x;
} else if (y <= 0.078) {
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 <= (-6.8d+15)) then
tmp = x
else if (y <= 0.078d0) 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 <= -6.8e+15) {
tmp = x;
} else if (y <= 0.078) {
tmp = 1.0 / y;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -6.8e+15: tmp = x elif y <= 0.078: tmp = 1.0 / y else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if (y <= -6.8e+15) tmp = x; elseif (y <= 0.078) tmp = Float64(1.0 / y); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= -6.8e+15) tmp = x; elseif (y <= 0.078) tmp = 1.0 / y; else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -6.8e+15], x, If[LessEqual[y, 0.078], N[(1.0 / y), $MachinePrecision], x]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -6.8 \cdot 10^{+15}:\\
\;\;\;\;x\\
\mathbf{elif}\;y \leq 0.078:\\
\;\;\;\;\frac{1}{y}\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if y < -6.8e15 or 0.0779999999999999999 < y Initial program 95.2%
exp-prod95.2%
+-commutative95.2%
Simplified95.2%
Taylor expanded in x around inf 76.8%
if -6.8e15 < y < 0.0779999999999999999Initial program 87.7%
exp-prod100.0%
+-commutative100.0%
Simplified100.0%
Taylor expanded in y around 0 78.1%
Final simplification77.3%
(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 92.3%
exp-prod97.1%
+-commutative97.1%
Simplified97.1%
Taylor expanded in y around inf 90.1%
+-commutative90.1%
Simplified90.1%
Final simplification90.1%
(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 92.3%
exp-prod97.1%
+-commutative97.1%
Simplified97.1%
Taylor expanded in x around inf 55.0%
Final simplification55.0%
(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 2024031
(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)))