
(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 (/ (exp (- z)) y)))) (if (<= y -1.96) t_0 (if (<= y 1.95e-8) (+ x (/ 1.0 y)) t_0))))
double code(double x, double y, double z) {
double t_0 = x + (exp(-z) / y);
double tmp;
if (y <= -1.96) {
tmp = t_0;
} else if (y <= 1.95e-8) {
tmp = x + (1.0 / y);
} else {
tmp = t_0;
}
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 + (exp(-z) / y)
if (y <= (-1.96d0)) then
tmp = t_0
else if (y <= 1.95d-8) then
tmp = x + (1.0d0 / y)
else
tmp = t_0
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double t_0 = x + (Math.exp(-z) / y);
double tmp;
if (y <= -1.96) {
tmp = t_0;
} else if (y <= 1.95e-8) {
tmp = x + (1.0 / y);
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = x + (math.exp(-z) / y) tmp = 0 if y <= -1.96: tmp = t_0 elif y <= 1.95e-8: tmp = x + (1.0 / y) else: tmp = t_0 return tmp
function code(x, y, z) t_0 = Float64(x + Float64(exp(Float64(-z)) / y)) tmp = 0.0 if (y <= -1.96) tmp = t_0; elseif (y <= 1.95e-8) tmp = Float64(x + Float64(1.0 / y)); else tmp = t_0; end return tmp end
function tmp_2 = code(x, y, z) t_0 = x + (exp(-z) / y); tmp = 0.0; if (y <= -1.96) tmp = t_0; elseif (y <= 1.95e-8) tmp = x + (1.0 / y); else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(x + N[(N[Exp[(-z)], $MachinePrecision] / y), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[y, -1.96], t$95$0, If[LessEqual[y, 1.95e-8], N[(x + N[(1.0 / y), $MachinePrecision]), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := x + \frac{e^{-z}}{y}\\
\mathbf{if}\;y \leq -1.96:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq 1.95 \cdot 10^{-8}:\\
\;\;\;\;x + \frac{1}{y}\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if y < -1.96 or 1.94999999999999992e-8 < y Initial program 85.0%
Taylor expanded in y around inf
exp-lowering-exp.f64N/A
mul-1-negN/A
neg-lowering-neg.f64100.0
Simplified100.0%
if -1.96 < y < 1.94999999999999992e-8Initial program 78.8%
Taylor expanded in z around 0
+-commutativeN/A
+-lowering-+.f64N/A
/-lowering-/.f6499.6
Simplified99.6%
Final simplification99.8%
(FPCore (x y z) :precision binary64 (if (<= z -2.05e+186) (/ (fma y x 1.0) y) (if (<= z -920.0) (/ (exp (- z)) y) (+ x (/ 1.0 y)))))
double code(double x, double y, double z) {
double tmp;
if (z <= -2.05e+186) {
tmp = fma(y, x, 1.0) / y;
} else if (z <= -920.0) {
tmp = exp(-z) / y;
} else {
tmp = x + (1.0 / y);
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if (z <= -2.05e+186) tmp = Float64(fma(y, x, 1.0) / y); elseif (z <= -920.0) tmp = Float64(exp(Float64(-z)) / y); else tmp = Float64(x + Float64(1.0 / y)); end return tmp end
code[x_, y_, z_] := If[LessEqual[z, -2.05e+186], N[(N[(y * x + 1.0), $MachinePrecision] / y), $MachinePrecision], If[LessEqual[z, -920.0], N[(N[Exp[(-z)], $MachinePrecision] / y), $MachinePrecision], N[(x + N[(1.0 / y), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -2.05 \cdot 10^{+186}:\\
\;\;\;\;\frac{\mathsf{fma}\left(y, x, 1\right)}{y}\\
\mathbf{elif}\;z \leq -920:\\
\;\;\;\;\frac{e^{-z}}{y}\\
\mathbf{else}:\\
\;\;\;\;x + \frac{1}{y}\\
\end{array}
\end{array}
if z < -2.05e186Initial program 41.1%
Taylor expanded in z around 0
+-commutativeN/A
+-lowering-+.f64N/A
/-lowering-/.f6458.5
Simplified58.5%
Taylor expanded in y around 0
/-lowering-/.f64N/A
+-commutativeN/A
*-commutativeN/A
accelerator-lowering-fma.f6475.6
Simplified75.6%
if -2.05e186 < z < -920Initial program 44.9%
Taylor expanded in y around inf
exp-lowering-exp.f64N/A
mul-1-negN/A
neg-lowering-neg.f6473.0
Simplified73.0%
Taylor expanded in x around 0
/-lowering-/.f64N/A
exp-lowering-exp.f64N/A
neg-lowering-neg.f6473.0
Simplified73.0%
if -920 < z Initial program 93.3%
Taylor expanded in z around 0
+-commutativeN/A
+-lowering-+.f64N/A
/-lowering-/.f6496.1
Simplified96.1%
Final simplification91.3%
(FPCore (x y z)
:precision binary64
(if (<= z -6e+96)
(/ (fma y x 1.0) y)
(if (<= z -1450.0)
(/ (- (fma y (fma y (* x x) x) 1.0) z) y)
(+ x (/ 1.0 y)))))
double code(double x, double y, double z) {
double tmp;
if (z <= -6e+96) {
tmp = fma(y, x, 1.0) / y;
} else if (z <= -1450.0) {
tmp = (fma(y, fma(y, (x * x), x), 1.0) - z) / y;
} else {
tmp = x + (1.0 / y);
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if (z <= -6e+96) tmp = Float64(fma(y, x, 1.0) / y); elseif (z <= -1450.0) tmp = Float64(Float64(fma(y, fma(y, Float64(x * x), x), 1.0) - z) / y); else tmp = Float64(x + Float64(1.0 / y)); end return tmp end
code[x_, y_, z_] := If[LessEqual[z, -6e+96], N[(N[(y * x + 1.0), $MachinePrecision] / y), $MachinePrecision], If[LessEqual[z, -1450.0], N[(N[(N[(y * N[(y * N[(x * x), $MachinePrecision] + x), $MachinePrecision] + 1.0), $MachinePrecision] - z), $MachinePrecision] / y), $MachinePrecision], N[(x + N[(1.0 / y), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -6 \cdot 10^{+96}:\\
\;\;\;\;\frac{\mathsf{fma}\left(y, x, 1\right)}{y}\\
\mathbf{elif}\;z \leq -1450:\\
\;\;\;\;\frac{\mathsf{fma}\left(y, \mathsf{fma}\left(y, x \cdot x, x\right), 1\right) - z}{y}\\
\mathbf{else}:\\
\;\;\;\;x + \frac{1}{y}\\
\end{array}
\end{array}
if z < -6.0000000000000001e96Initial program 50.7%
Taylor expanded in z around 0
+-commutativeN/A
+-lowering-+.f64N/A
/-lowering-/.f6450.2
Simplified50.2%
Taylor expanded in y around 0
/-lowering-/.f64N/A
+-commutativeN/A
*-commutativeN/A
accelerator-lowering-fma.f6459.0
Simplified59.0%
if -6.0000000000000001e96 < z < -1450Initial program 34.9%
Taylor expanded in z around 0
associate-+r+N/A
+-commutativeN/A
+-lowering-+.f64N/A
/-lowering-/.f64N/A
mul-1-negN/A
unsub-negN/A
--lowering--.f64N/A
/-lowering-/.f6411.3
Simplified11.3%
associate-+r-N/A
flip-+N/A
frac-subN/A
/-lowering-/.f64N/A
--lowering--.f64N/A
*-lowering-*.f64N/A
--lowering--.f64N/A
un-div-invN/A
associate-/r*N/A
/-lowering-/.f64N/A
*-lowering-*.f64N/A
*-lowering-*.f64N/A
*-lowering-*.f64N/A
--lowering--.f64N/A
/-lowering-/.f64N/A
*-lowering-*.f64N/A
Applied egg-rr10.4%
Taylor expanded in y around 0
/-lowering-/.f64N/A
+-commutativeN/A
associate--l+N/A
*-commutativeN/A
associate-*l*N/A
*-commutativeN/A
accelerator-lowering-fma.f64N/A
*-lowering-*.f64N/A
--lowering--.f6419.1
Simplified19.1%
Taylor expanded in y around 0
Simplified52.1%
if -1450 < z Initial program 93.3%
Taylor expanded in z around 0
+-commutativeN/A
+-lowering-+.f64N/A
/-lowering-/.f6496.1
Simplified96.1%
Final simplification87.5%
(FPCore (x y z) :precision binary64 (if (<= y -1.15e+70) x (if (<= y 7e-69) (/ 1.0 y) x)))
double code(double x, double y, double z) {
double tmp;
if (y <= -1.15e+70) {
tmp = x;
} else if (y <= 7e-69) {
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 <= (-1.15d+70)) then
tmp = x
else if (y <= 7d-69) 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 <= -1.15e+70) {
tmp = x;
} else if (y <= 7e-69) {
tmp = 1.0 / y;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -1.15e+70: tmp = x elif y <= 7e-69: tmp = 1.0 / y else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if (y <= -1.15e+70) tmp = x; elseif (y <= 7e-69) tmp = Float64(1.0 / y); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= -1.15e+70) tmp = x; elseif (y <= 7e-69) tmp = 1.0 / y; else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -1.15e+70], x, If[LessEqual[y, 7e-69], N[(1.0 / y), $MachinePrecision], x]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.15 \cdot 10^{+70}:\\
\;\;\;\;x\\
\mathbf{elif}\;y \leq 7 \cdot 10^{-69}:\\
\;\;\;\;\frac{1}{y}\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if y < -1.14999999999999997e70 or 7.0000000000000003e-69 < y Initial program 84.4%
Taylor expanded in x around inf
Simplified67.5%
if -1.14999999999999997e70 < y < 7.0000000000000003e-69Initial program 80.1%
Taylor expanded in y around 0
/-lowering-/.f6471.0
Simplified71.0%
(FPCore (x y z) :precision binary64 (if (<= z -5.2e+37) (/ (fma y x 1.0) y) (+ x (/ 1.0 y))))
double code(double x, double y, double z) {
double tmp;
if (z <= -5.2e+37) {
tmp = fma(y, x, 1.0) / y;
} else {
tmp = x + (1.0 / y);
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if (z <= -5.2e+37) tmp = Float64(fma(y, x, 1.0) / y); else tmp = Float64(x + Float64(1.0 / y)); end return tmp end
code[x_, y_, z_] := If[LessEqual[z, -5.2e+37], N[(N[(y * x + 1.0), $MachinePrecision] / y), $MachinePrecision], N[(x + N[(1.0 / y), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -5.2 \cdot 10^{+37}:\\
\;\;\;\;\frac{\mathsf{fma}\left(y, x, 1\right)}{y}\\
\mathbf{else}:\\
\;\;\;\;x + \frac{1}{y}\\
\end{array}
\end{array}
if z < -5.1999999999999998e37Initial program 46.5%
Taylor expanded in z around 0
+-commutativeN/A
+-lowering-+.f64N/A
/-lowering-/.f6441.5
Simplified41.5%
Taylor expanded in y around 0
/-lowering-/.f64N/A
+-commutativeN/A
*-commutativeN/A
accelerator-lowering-fma.f6452.3
Simplified52.3%
if -5.1999999999999998e37 < z Initial program 90.0%
Taylor expanded in z around 0
+-commutativeN/A
+-lowering-+.f64N/A
/-lowering-/.f6492.2
Simplified92.2%
Final simplification85.5%
(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.7%
Taylor expanded in z around 0
+-commutativeN/A
+-lowering-+.f64N/A
/-lowering-/.f6483.7
Simplified83.7%
Final simplification83.7%
(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.7%
Taylor expanded in x around inf
Simplified49.5%
(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 2024199
(FPCore (x y z)
:name "Numeric.SpecFunctions:invIncompleteBetaWorker from math-functions-0.1.5.2, G"
:precision binary64
:alt
(! :herbie-platform default (if (< (/ y (+ z y)) 17788539399477/2500000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000) (+ x (/ (exp (/ -1 z)) y)) (+ x (/ (exp (log (pow (/ y (+ y z)) y))) y))))
(+ x (/ (exp (* y (log (/ y (+ z y))))) y)))