
(FPCore (x y) :precision binary64 (- (log (+ 1.0 (exp x))) (* x y)))
double code(double x, double y) {
return log((1.0 + exp(x))) - (x * y);
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = log((1.0d0 + exp(x))) - (x * y)
end function
public static double code(double x, double y) {
return Math.log((1.0 + Math.exp(x))) - (x * y);
}
def code(x, y): return math.log((1.0 + math.exp(x))) - (x * y)
function code(x, y) return Float64(log(Float64(1.0 + exp(x))) - Float64(x * y)) end
function tmp = code(x, y) tmp = log((1.0 + exp(x))) - (x * y); end
code[x_, y_] := N[(N[Log[N[(1.0 + N[Exp[x], $MachinePrecision]), $MachinePrecision]], $MachinePrecision] - N[(x * y), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\log \left(1 + e^{x}\right) - x \cdot y
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 13 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y) :precision binary64 (- (log (+ 1.0 (exp x))) (* x y)))
double code(double x, double y) {
return log((1.0 + exp(x))) - (x * y);
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = log((1.0d0 + exp(x))) - (x * y)
end function
public static double code(double x, double y) {
return Math.log((1.0 + Math.exp(x))) - (x * y);
}
def code(x, y): return math.log((1.0 + math.exp(x))) - (x * y)
function code(x, y) return Float64(log(Float64(1.0 + exp(x))) - Float64(x * y)) end
function tmp = code(x, y) tmp = log((1.0 + exp(x))) - (x * y); end
code[x_, y_] := N[(N[Log[N[(1.0 + N[Exp[x], $MachinePrecision]), $MachinePrecision]], $MachinePrecision] - N[(x * y), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\log \left(1 + e^{x}\right) - x \cdot y
\end{array}
(FPCore (x y) :precision binary64 (if (<= x -42.0) (* x (- y)) (+ (log 2.0) (* x (- (+ 0.5 (* x 0.125)) y)))))
double code(double x, double y) {
double tmp;
if (x <= -42.0) {
tmp = x * -y;
} else {
tmp = log(2.0) + (x * ((0.5 + (x * 0.125)) - y));
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if (x <= (-42.0d0)) then
tmp = x * -y
else
tmp = log(2.0d0) + (x * ((0.5d0 + (x * 0.125d0)) - y))
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (x <= -42.0) {
tmp = x * -y;
} else {
tmp = Math.log(2.0) + (x * ((0.5 + (x * 0.125)) - y));
}
return tmp;
}
def code(x, y): tmp = 0 if x <= -42.0: tmp = x * -y else: tmp = math.log(2.0) + (x * ((0.5 + (x * 0.125)) - y)) return tmp
function code(x, y) tmp = 0.0 if (x <= -42.0) tmp = Float64(x * Float64(-y)); else tmp = Float64(log(2.0) + Float64(x * Float64(Float64(0.5 + Float64(x * 0.125)) - y))); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (x <= -42.0) tmp = x * -y; else tmp = log(2.0) + (x * ((0.5 + (x * 0.125)) - y)); end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[x, -42.0], N[(x * (-y)), $MachinePrecision], N[(N[Log[2.0], $MachinePrecision] + N[(x * N[(N[(0.5 + N[(x * 0.125), $MachinePrecision]), $MachinePrecision] - y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -42:\\
\;\;\;\;x \cdot \left(-y\right)\\
\mathbf{else}:\\
\;\;\;\;\log 2 + x \cdot \left(\left(0.5 + x \cdot 0.125\right) - y\right)\\
\end{array}
\end{array}
if x < -42Initial program 100.0%
log1p-define100.0%
Simplified100.0%
Taylor expanded in x around inf 100.0%
associate-*r*100.0%
neg-mul-1100.0%
*-commutative100.0%
Simplified100.0%
if -42 < x Initial program 97.7%
log1p-define97.8%
Simplified97.8%
Taylor expanded in x around 0 98.5%
Final simplification98.9%
(FPCore (x y) :precision binary64 (fma x (- y) (log1p (exp x))))
double code(double x, double y) {
return fma(x, -y, log1p(exp(x)));
}
function code(x, y) return fma(x, Float64(-y), log1p(exp(x))) end
code[x_, y_] := N[(x * (-y) + N[Log[1 + N[Exp[x], $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(x, -y, \mathsf{log1p}\left(e^{x}\right)\right)
\end{array}
Initial program 98.5%
cancel-sign-sub-inv98.5%
+-commutative98.5%
distribute-lft-neg-out98.5%
distribute-rgt-neg-out98.5%
fma-define98.5%
log1p-define98.5%
Simplified98.5%
Final simplification98.5%
(FPCore (x y) :precision binary64 (if (<= x -78.0) (* x (- y)) (fma x (- y) (log 2.0))))
double code(double x, double y) {
double tmp;
if (x <= -78.0) {
tmp = x * -y;
} else {
tmp = fma(x, -y, log(2.0));
}
return tmp;
}
function code(x, y) tmp = 0.0 if (x <= -78.0) tmp = Float64(x * Float64(-y)); else tmp = fma(x, Float64(-y), log(2.0)); end return tmp end
code[x_, y_] := If[LessEqual[x, -78.0], N[(x * (-y)), $MachinePrecision], N[(x * (-y) + N[Log[2.0], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -78:\\
\;\;\;\;x \cdot \left(-y\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(x, -y, \log 2\right)\\
\end{array}
\end{array}
if x < -78Initial program 100.0%
log1p-define100.0%
Simplified100.0%
Taylor expanded in x around inf 100.0%
associate-*r*100.0%
neg-mul-1100.0%
*-commutative100.0%
Simplified100.0%
if -78 < x Initial program 97.7%
cancel-sign-sub-inv97.7%
+-commutative97.7%
distribute-lft-neg-out97.7%
distribute-rgt-neg-out97.7%
fma-define97.8%
log1p-define97.8%
Simplified97.8%
Taylor expanded in x around 0 97.4%
Final simplification98.2%
(FPCore (x y) :precision binary64 (- (log1p (exp x)) (* x y)))
double code(double x, double y) {
return log1p(exp(x)) - (x * y);
}
public static double code(double x, double y) {
return Math.log1p(Math.exp(x)) - (x * y);
}
def code(x, y): return math.log1p(math.exp(x)) - (x * y)
function code(x, y) return Float64(log1p(exp(x)) - Float64(x * y)) end
code[x_, y_] := N[(N[Log[1 + N[Exp[x], $MachinePrecision]], $MachinePrecision] - N[(x * y), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{log1p}\left(e^{x}\right) - x \cdot y
\end{array}
Initial program 98.5%
log1p-define98.5%
Simplified98.5%
Final simplification98.5%
(FPCore (x y) :precision binary64 (if (<= x -65.0) (* x (- y)) (* y (- (+ (/ (log 2.0) y) (/ (* x (+ 0.5 (* x 0.125))) y)) x))))
double code(double x, double y) {
double tmp;
if (x <= -65.0) {
tmp = x * -y;
} else {
tmp = y * (((log(2.0) / y) + ((x * (0.5 + (x * 0.125))) / y)) - x);
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if (x <= (-65.0d0)) then
tmp = x * -y
else
tmp = y * (((log(2.0d0) / y) + ((x * (0.5d0 + (x * 0.125d0))) / y)) - x)
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (x <= -65.0) {
tmp = x * -y;
} else {
tmp = y * (((Math.log(2.0) / y) + ((x * (0.5 + (x * 0.125))) / y)) - x);
}
return tmp;
}
def code(x, y): tmp = 0 if x <= -65.0: tmp = x * -y else: tmp = y * (((math.log(2.0) / y) + ((x * (0.5 + (x * 0.125))) / y)) - x) return tmp
function code(x, y) tmp = 0.0 if (x <= -65.0) tmp = Float64(x * Float64(-y)); else tmp = Float64(y * Float64(Float64(Float64(log(2.0) / y) + Float64(Float64(x * Float64(0.5 + Float64(x * 0.125))) / y)) - x)); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (x <= -65.0) tmp = x * -y; else tmp = y * (((log(2.0) / y) + ((x * (0.5 + (x * 0.125))) / y)) - x); end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[x, -65.0], N[(x * (-y)), $MachinePrecision], N[(y * N[(N[(N[(N[Log[2.0], $MachinePrecision] / y), $MachinePrecision] + N[(N[(x * N[(0.5 + N[(x * 0.125), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / y), $MachinePrecision]), $MachinePrecision] - x), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -65:\\
\;\;\;\;x \cdot \left(-y\right)\\
\mathbf{else}:\\
\;\;\;\;y \cdot \left(\left(\frac{\log 2}{y} + \frac{x \cdot \left(0.5 + x \cdot 0.125\right)}{y}\right) - x\right)\\
\end{array}
\end{array}
if x < -65Initial program 100.0%
log1p-define100.0%
Simplified100.0%
Taylor expanded in x around inf 100.0%
associate-*r*100.0%
neg-mul-1100.0%
*-commutative100.0%
Simplified100.0%
if -65 < x Initial program 97.7%
log1p-define97.8%
Simplified97.8%
Taylor expanded in x around 0 98.5%
Taylor expanded in y around inf 98.4%
Final simplification98.9%
(FPCore (x y) :precision binary64 (if (<= x -1.4) (* x (- y)) (* y (+ (/ (log 2.0) y) (* x (+ -1.0 (* 0.5 (/ 1.0 y))))))))
double code(double x, double y) {
double tmp;
if (x <= -1.4) {
tmp = x * -y;
} else {
tmp = y * ((log(2.0) / y) + (x * (-1.0 + (0.5 * (1.0 / y)))));
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if (x <= (-1.4d0)) then
tmp = x * -y
else
tmp = y * ((log(2.0d0) / y) + (x * ((-1.0d0) + (0.5d0 * (1.0d0 / y)))))
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (x <= -1.4) {
tmp = x * -y;
} else {
tmp = y * ((Math.log(2.0) / y) + (x * (-1.0 + (0.5 * (1.0 / y)))));
}
return tmp;
}
def code(x, y): tmp = 0 if x <= -1.4: tmp = x * -y else: tmp = y * ((math.log(2.0) / y) + (x * (-1.0 + (0.5 * (1.0 / y))))) return tmp
function code(x, y) tmp = 0.0 if (x <= -1.4) tmp = Float64(x * Float64(-y)); else tmp = Float64(y * Float64(Float64(log(2.0) / y) + Float64(x * Float64(-1.0 + Float64(0.5 * Float64(1.0 / y)))))); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (x <= -1.4) tmp = x * -y; else tmp = y * ((log(2.0) / y) + (x * (-1.0 + (0.5 * (1.0 / y))))); end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[x, -1.4], N[(x * (-y)), $MachinePrecision], N[(y * N[(N[(N[Log[2.0], $MachinePrecision] / y), $MachinePrecision] + N[(x * N[(-1.0 + N[(0.5 * N[(1.0 / y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.4:\\
\;\;\;\;x \cdot \left(-y\right)\\
\mathbf{else}:\\
\;\;\;\;y \cdot \left(\frac{\log 2}{y} + x \cdot \left(-1 + 0.5 \cdot \frac{1}{y}\right)\right)\\
\end{array}
\end{array}
if x < -1.3999999999999999Initial program 100.0%
log1p-define100.0%
Simplified100.0%
Taylor expanded in x around inf 100.0%
associate-*r*100.0%
neg-mul-1100.0%
*-commutative100.0%
Simplified100.0%
if -1.3999999999999999 < x Initial program 97.7%
log1p-define97.8%
Simplified97.8%
Taylor expanded in y around inf 97.7%
log1p-define97.7%
Simplified97.7%
Taylor expanded in x around 0 98.2%
Final simplification98.7%
(FPCore (x y) :precision binary64 (if (<= x -1.4) (* x (- y)) (* y (- (/ (+ (log 2.0) (* x 0.5)) y) x))))
double code(double x, double y) {
double tmp;
if (x <= -1.4) {
tmp = x * -y;
} else {
tmp = y * (((log(2.0) + (x * 0.5)) / y) - x);
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if (x <= (-1.4d0)) then
tmp = x * -y
else
tmp = y * (((log(2.0d0) + (x * 0.5d0)) / y) - x)
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (x <= -1.4) {
tmp = x * -y;
} else {
tmp = y * (((Math.log(2.0) + (x * 0.5)) / y) - x);
}
return tmp;
}
def code(x, y): tmp = 0 if x <= -1.4: tmp = x * -y else: tmp = y * (((math.log(2.0) + (x * 0.5)) / y) - x) return tmp
function code(x, y) tmp = 0.0 if (x <= -1.4) tmp = Float64(x * Float64(-y)); else tmp = Float64(y * Float64(Float64(Float64(log(2.0) + Float64(x * 0.5)) / y) - x)); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (x <= -1.4) tmp = x * -y; else tmp = y * (((log(2.0) + (x * 0.5)) / y) - x); end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[x, -1.4], N[(x * (-y)), $MachinePrecision], N[(y * N[(N[(N[(N[Log[2.0], $MachinePrecision] + N[(x * 0.5), $MachinePrecision]), $MachinePrecision] / y), $MachinePrecision] - x), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.4:\\
\;\;\;\;x \cdot \left(-y\right)\\
\mathbf{else}:\\
\;\;\;\;y \cdot \left(\frac{\log 2 + x \cdot 0.5}{y} - x\right)\\
\end{array}
\end{array}
if x < -1.3999999999999999Initial program 100.0%
log1p-define100.0%
Simplified100.0%
Taylor expanded in x around inf 100.0%
associate-*r*100.0%
neg-mul-1100.0%
*-commutative100.0%
Simplified100.0%
if -1.3999999999999999 < x Initial program 97.7%
log1p-define97.8%
Simplified97.8%
Taylor expanded in y around inf 97.7%
log1p-define97.7%
Simplified97.7%
Taylor expanded in x around 0 98.2%
Final simplification98.7%
(FPCore (x y) :precision binary64 (if (<= x -0.00026) (* x (- y)) (+ (log 2.0) (* x 0.5))))
double code(double x, double y) {
double tmp;
if (x <= -0.00026) {
tmp = x * -y;
} else {
tmp = log(2.0) + (x * 0.5);
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if (x <= (-0.00026d0)) then
tmp = x * -y
else
tmp = log(2.0d0) + (x * 0.5d0)
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (x <= -0.00026) {
tmp = x * -y;
} else {
tmp = Math.log(2.0) + (x * 0.5);
}
return tmp;
}
def code(x, y): tmp = 0 if x <= -0.00026: tmp = x * -y else: tmp = math.log(2.0) + (x * 0.5) return tmp
function code(x, y) tmp = 0.0 if (x <= -0.00026) tmp = Float64(x * Float64(-y)); else tmp = Float64(log(2.0) + Float64(x * 0.5)); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (x <= -0.00026) tmp = x * -y; else tmp = log(2.0) + (x * 0.5); end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[x, -0.00026], N[(x * (-y)), $MachinePrecision], N[(N[Log[2.0], $MachinePrecision] + N[(x * 0.5), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -0.00026:\\
\;\;\;\;x \cdot \left(-y\right)\\
\mathbf{else}:\\
\;\;\;\;\log 2 + x \cdot 0.5\\
\end{array}
\end{array}
if x < -2.59999999999999977e-4Initial program 100.0%
log1p-define100.0%
Simplified100.0%
Taylor expanded in x around inf 100.0%
associate-*r*100.0%
neg-mul-1100.0%
*-commutative100.0%
Simplified100.0%
if -2.59999999999999977e-4 < x Initial program 97.7%
log1p-define97.8%
Simplified97.8%
Taylor expanded in x around 0 98.2%
Taylor expanded in y around 0 71.3%
Final simplification80.3%
(FPCore (x y) :precision binary64 (if (<= x -0.00017) (* x (- y)) (+ (log 2.0) (* x 0.5))))
double code(double x, double y) {
double tmp;
if (x <= -0.00017) {
tmp = x * -y;
} else {
tmp = log(2.0) + (x * 0.5);
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if (x <= (-0.00017d0)) then
tmp = x * -y
else
tmp = log(2.0d0) + (x * 0.5d0)
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (x <= -0.00017) {
tmp = x * -y;
} else {
tmp = Math.log(2.0) + (x * 0.5);
}
return tmp;
}
def code(x, y): tmp = 0 if x <= -0.00017: tmp = x * -y else: tmp = math.log(2.0) + (x * 0.5) return tmp
function code(x, y) tmp = 0.0 if (x <= -0.00017) tmp = Float64(x * Float64(-y)); else tmp = Float64(log(2.0) + Float64(x * 0.5)); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (x <= -0.00017) tmp = x * -y; else tmp = log(2.0) + (x * 0.5); end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[x, -0.00017], N[(x * (-y)), $MachinePrecision], N[(N[Log[2.0], $MachinePrecision] + N[(x * 0.5), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -0.00017:\\
\;\;\;\;x \cdot \left(-y\right)\\
\mathbf{else}:\\
\;\;\;\;\log 2 + x \cdot 0.5\\
\end{array}
\end{array}
if x < -1.7e-4Initial program 100.0%
log1p-define100.0%
Simplified100.0%
Taylor expanded in x around inf 100.0%
associate-*r*100.0%
neg-mul-1100.0%
*-commutative100.0%
Simplified100.0%
if -1.7e-4 < x Initial program 97.7%
log1p-define97.8%
Simplified97.8%
Taylor expanded in x around 0 98.5%
Taylor expanded in y around 0 71.6%
Taylor expanded in x around 0 71.3%
*-commutative71.3%
Simplified71.3%
Final simplification80.3%
(FPCore (x y) :precision binary64 (if (<= x -2e-10) (* x (- y)) (log 2.0)))
double code(double x, double y) {
double tmp;
if (x <= -2e-10) {
tmp = x * -y;
} else {
tmp = log(2.0);
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if (x <= (-2d-10)) then
tmp = x * -y
else
tmp = log(2.0d0)
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (x <= -2e-10) {
tmp = x * -y;
} else {
tmp = Math.log(2.0);
}
return tmp;
}
def code(x, y): tmp = 0 if x <= -2e-10: tmp = x * -y else: tmp = math.log(2.0) return tmp
function code(x, y) tmp = 0.0 if (x <= -2e-10) tmp = Float64(x * Float64(-y)); else tmp = log(2.0); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (x <= -2e-10) tmp = x * -y; else tmp = log(2.0); end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[x, -2e-10], N[(x * (-y)), $MachinePrecision], N[Log[2.0], $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -2 \cdot 10^{-10}:\\
\;\;\;\;x \cdot \left(-y\right)\\
\mathbf{else}:\\
\;\;\;\;\log 2\\
\end{array}
\end{array}
if x < -2.00000000000000007e-10Initial program 100.0%
log1p-define100.0%
Simplified100.0%
Taylor expanded in x around inf 97.8%
associate-*r*97.8%
neg-mul-197.8%
*-commutative97.8%
Simplified97.8%
if -2.00000000000000007e-10 < x Initial program 97.7%
log1p-define97.7%
Simplified97.7%
Taylor expanded in y around inf 97.6%
log1p-define97.6%
Simplified97.6%
Taylor expanded in x around 0 71.2%
Final simplification79.8%
(FPCore (x y) :precision binary64 (- (log 2.0) (* x y)))
double code(double x, double y) {
return log(2.0) - (x * y);
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = log(2.0d0) - (x * y)
end function
public static double code(double x, double y) {
return Math.log(2.0) - (x * y);
}
def code(x, y): return math.log(2.0) - (x * y)
function code(x, y) return Float64(log(2.0) - Float64(x * y)) end
function tmp = code(x, y) tmp = log(2.0) - (x * y); end
code[x_, y_] := N[(N[Log[2.0], $MachinePrecision] - N[(x * y), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\log 2 - x \cdot y
\end{array}
Initial program 98.5%
log1p-define98.5%
Simplified98.5%
Taylor expanded in x around 0 88.8%
Final simplification88.8%
(FPCore (x y) :precision binary64 (* x (- y)))
double code(double x, double y) {
return x * -y;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = x * -y
end function
public static double code(double x, double y) {
return x * -y;
}
def code(x, y): return x * -y
function code(x, y) return Float64(x * Float64(-y)) end
function tmp = code(x, y) tmp = x * -y; end
code[x_, y_] := N[(x * (-y)), $MachinePrecision]
\begin{array}{l}
\\
x \cdot \left(-y\right)
\end{array}
Initial program 98.5%
log1p-define98.5%
Simplified98.5%
Taylor expanded in x around inf 51.2%
associate-*r*51.2%
neg-mul-151.2%
*-commutative51.2%
Simplified51.2%
Final simplification51.2%
(FPCore (x y) :precision binary64 (* x 0.5))
double code(double x, double y) {
return x * 0.5;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = x * 0.5d0
end function
public static double code(double x, double y) {
return x * 0.5;
}
def code(x, y): return x * 0.5
function code(x, y) return Float64(x * 0.5) end
function tmp = code(x, y) tmp = x * 0.5; end
code[x_, y_] := N[(x * 0.5), $MachinePrecision]
\begin{array}{l}
\\
x \cdot 0.5
\end{array}
Initial program 98.5%
log1p-define98.5%
Simplified98.5%
Taylor expanded in y around inf 98.4%
log1p-define98.4%
Simplified98.4%
Taylor expanded in x around 0 82.7%
Taylor expanded in x around inf 35.5%
sub-neg35.5%
associate-*r/35.5%
metadata-eval35.5%
metadata-eval35.5%
Simplified35.5%
Taylor expanded in y around 0 3.5%
Final simplification3.5%
(FPCore (x y) :precision binary64 (if (<= x 0.0) (- (log (+ 1.0 (exp x))) (* x y)) (- (log (+ 1.0 (exp (- x)))) (* (- x) (- 1.0 y)))))
double code(double x, double y) {
double tmp;
if (x <= 0.0) {
tmp = log((1.0 + exp(x))) - (x * y);
} else {
tmp = log((1.0 + exp(-x))) - (-x * (1.0 - y));
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if (x <= 0.0d0) then
tmp = log((1.0d0 + exp(x))) - (x * y)
else
tmp = log((1.0d0 + exp(-x))) - (-x * (1.0d0 - y))
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (x <= 0.0) {
tmp = Math.log((1.0 + Math.exp(x))) - (x * y);
} else {
tmp = Math.log((1.0 + Math.exp(-x))) - (-x * (1.0 - y));
}
return tmp;
}
def code(x, y): tmp = 0 if x <= 0.0: tmp = math.log((1.0 + math.exp(x))) - (x * y) else: tmp = math.log((1.0 + math.exp(-x))) - (-x * (1.0 - y)) return tmp
function code(x, y) tmp = 0.0 if (x <= 0.0) tmp = Float64(log(Float64(1.0 + exp(x))) - Float64(x * y)); else tmp = Float64(log(Float64(1.0 + exp(Float64(-x)))) - Float64(Float64(-x) * Float64(1.0 - y))); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (x <= 0.0) tmp = log((1.0 + exp(x))) - (x * y); else tmp = log((1.0 + exp(-x))) - (-x * (1.0 - y)); end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[x, 0.0], N[(N[Log[N[(1.0 + N[Exp[x], $MachinePrecision]), $MachinePrecision]], $MachinePrecision] - N[(x * y), $MachinePrecision]), $MachinePrecision], N[(N[Log[N[(1.0 + N[Exp[(-x)], $MachinePrecision]), $MachinePrecision]], $MachinePrecision] - N[((-x) * N[(1.0 - y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 0:\\
\;\;\;\;\log \left(1 + e^{x}\right) - x \cdot y\\
\mathbf{else}:\\
\;\;\;\;\log \left(1 + e^{-x}\right) - \left(-x\right) \cdot \left(1 - y\right)\\
\end{array}
\end{array}
herbie shell --seed 2024066
(FPCore (x y)
:name "Logistic regression 2"
:precision binary64
:alt
(if (<= x 0.0) (- (log (+ 1.0 (exp x))) (* x y)) (- (log (+ 1.0 (exp (- x)))) (* (- x) (- 1.0 y))))
(- (log (+ 1.0 (exp x))) (* x y)))