
(FPCore (c x y) :precision binary64 :pre TRUE (* c (log (+ 1.0 (* (- (pow E x) 1.0) y)))))
double code(double c, double x, double y) {
return c * log((1.0 + ((pow(((double) M_E), x) - 1.0) * y)));
}
public static double code(double c, double x, double y) {
return c * Math.log((1.0 + ((Math.pow(Math.E, x) - 1.0) * y)));
}
def code(c, x, y): return c * math.log((1.0 + ((math.pow(math.e, x) - 1.0) * y)))
function code(c, x, y) return Float64(c * log(Float64(1.0 + Float64(Float64((exp(1) ^ x) - 1.0) * y)))) end
function tmp = code(c, x, y) tmp = c * log((1.0 + (((2.71828182845904523536 ^ x) - 1.0) * y))); end
code[c_, x_, y_] := N[(c * N[Log[N[(1.0 + N[(N[(N[Power[E, x], $MachinePrecision] - 1.0), $MachinePrecision] * y), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
f(c, x, y): c in [-inf, +inf], x in [-inf, +inf], y in [-inf, +inf] code: THEORY BEGIN f(c, x, y: real): real = c * (ln(((1) + (((exp(1) ^ x) - (1)) * y)))) END code
c \cdot \log \left(1 + \left({e}^{x} - 1\right) \cdot y\right)
Herbie found 8 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (c x y) :precision binary64 :pre TRUE (* c (log (+ 1.0 (* (- (pow E x) 1.0) y)))))
double code(double c, double x, double y) {
return c * log((1.0 + ((pow(((double) M_E), x) - 1.0) * y)));
}
public static double code(double c, double x, double y) {
return c * Math.log((1.0 + ((Math.pow(Math.E, x) - 1.0) * y)));
}
def code(c, x, y): return c * math.log((1.0 + ((math.pow(math.e, x) - 1.0) * y)))
function code(c, x, y) return Float64(c * log(Float64(1.0 + Float64(Float64((exp(1) ^ x) - 1.0) * y)))) end
function tmp = code(c, x, y) tmp = c * log((1.0 + (((2.71828182845904523536 ^ x) - 1.0) * y))); end
code[c_, x_, y_] := N[(c * N[Log[N[(1.0 + N[(N[(N[Power[E, x], $MachinePrecision] - 1.0), $MachinePrecision] * y), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
f(c, x, y): c in [-inf, +inf], x in [-inf, +inf], y in [-inf, +inf] code: THEORY BEGIN f(c, x, y: real): real = c * (ln(((1) + (((exp(1) ^ x) - (1)) * y)))) END code
c \cdot \log \left(1 + \left({e}^{x} - 1\right) \cdot y\right)
(FPCore (c x y)
:precision binary64
:pre TRUE
(let* ((t_0 (* c (log1p (* (expm1 x) y)))))
(if (<= y -1.5511526834195688e-28)
t_0
(if (<= y 1.106409269880449e-55) (* y (* c (expm1 x))) t_0))))double code(double c, double x, double y) {
double t_0 = c * log1p((expm1(x) * y));
double tmp;
if (y <= -1.5511526834195688e-28) {
tmp = t_0;
} else if (y <= 1.106409269880449e-55) {
tmp = y * (c * expm1(x));
} else {
tmp = t_0;
}
return tmp;
}
public static double code(double c, double x, double y) {
double t_0 = c * Math.log1p((Math.expm1(x) * y));
double tmp;
if (y <= -1.5511526834195688e-28) {
tmp = t_0;
} else if (y <= 1.106409269880449e-55) {
tmp = y * (c * Math.expm1(x));
} else {
tmp = t_0;
}
return tmp;
}
def code(c, x, y): t_0 = c * math.log1p((math.expm1(x) * y)) tmp = 0 if y <= -1.5511526834195688e-28: tmp = t_0 elif y <= 1.106409269880449e-55: tmp = y * (c * math.expm1(x)) else: tmp = t_0 return tmp
function code(c, x, y) t_0 = Float64(c * log1p(Float64(expm1(x) * y))) tmp = 0.0 if (y <= -1.5511526834195688e-28) tmp = t_0; elseif (y <= 1.106409269880449e-55) tmp = Float64(y * Float64(c * expm1(x))); else tmp = t_0; end return tmp end
code[c_, x_, y_] := Block[{t$95$0 = N[(c * N[Log[1 + N[(N[(Exp[x] - 1), $MachinePrecision] * y), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[y, -1.5511526834195688e-28], t$95$0, If[LessEqual[y, 1.106409269880449e-55], N[(y * N[(c * N[(Exp[x] - 1), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], t$95$0]]]
f(c, x, y): c in [-inf, +inf], x in [-inf, +inf], y in [-inf, +inf] code: THEORY BEGIN f(c, x, y: real): real = LET t_0 = (c * (ln(((((exp(x)) - (1)) * y) + (1))))) IN LET tmp_1 = IF (y <= (1106409269880448986171765822828396570300838916253403248766447726993267927555191844216655416972111226111754746531116047854664735489932931417587924638468166449456475675106048583984375e-235)) THEN (y * (c * ((exp(x)) - (1)))) ELSE t_0 ENDIF IN LET tmp = IF (y <= (-1551152683419568771045439616240171027412485134580889752304752284356722060766620163718698677257634699344635009765625e-142)) THEN t_0 ELSE tmp_1 ENDIF IN tmp END code
\begin{array}{l}
t_0 := c \cdot \mathsf{log1p}\left(\mathsf{expm1}\left(x\right) \cdot y\right)\\
\mathbf{if}\;y \leq -1.5511526834195688 \cdot 10^{-28}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq 1.106409269880449 \cdot 10^{-55}:\\
\;\;\;\;y \cdot \left(c \cdot \mathsf{expm1}\left(x\right)\right)\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
if y < -1.5511526834195688e-28 or 1.106409269880449e-55 < y Initial program 42.1%
Applied rewrites93.3%
if -1.5511526834195688e-28 < y < 1.106409269880449e-55Initial program 42.1%
Taylor expanded in y around 0
Applied rewrites74.1%
Applied rewrites77.6%
(FPCore (c x y)
:precision binary64
:pre TRUE
(let* ((t_0 (* c (log (fma (expm1 x) y 1.0)))))
(if (<= y -5.756465638514478e+95)
t_0
(if (<= y 6.6993600723541415e+153) (* y (* c (expm1 x))) t_0))))double code(double c, double x, double y) {
double t_0 = c * log(fma(expm1(x), y, 1.0));
double tmp;
if (y <= -5.756465638514478e+95) {
tmp = t_0;
} else if (y <= 6.6993600723541415e+153) {
tmp = y * (c * expm1(x));
} else {
tmp = t_0;
}
return tmp;
}
function code(c, x, y) t_0 = Float64(c * log(fma(expm1(x), y, 1.0))) tmp = 0.0 if (y <= -5.756465638514478e+95) tmp = t_0; elseif (y <= 6.6993600723541415e+153) tmp = Float64(y * Float64(c * expm1(x))); else tmp = t_0; end return tmp end
code[c_, x_, y_] := Block[{t$95$0 = N[(c * N[Log[N[(N[(Exp[x] - 1), $MachinePrecision] * y + 1.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[y, -5.756465638514478e+95], t$95$0, If[LessEqual[y, 6.6993600723541415e+153], N[(y * N[(c * N[(Exp[x] - 1), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], t$95$0]]]
f(c, x, y): c in [-inf, +inf], x in [-inf, +inf], y in [-inf, +inf] code: THEORY BEGIN f(c, x, y: real): real = LET t_0 = (c * (ln(((((exp(x)) - (1)) * y) + (1))))) IN LET tmp_1 = IF (y <= (6699360072354141475203966126958235020504119986664746420655450416218605553402243332468594199816495235077034820225283496654424754774302170343137135535587328)) THEN (y * (c * ((exp(x)) - (1)))) ELSE t_0 ENDIF IN LET tmp = IF (y <= (-575646563851447818334308706974014366108583700322314004965891818191341923109222785033876646395904)) THEN t_0 ELSE tmp_1 ENDIF IN tmp END code
\begin{array}{l}
t_0 := c \cdot \log \left(\mathsf{fma}\left(\mathsf{expm1}\left(x\right), y, 1\right)\right)\\
\mathbf{if}\;y \leq -5.756465638514478 \cdot 10^{+95}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq 6.6993600723541415 \cdot 10^{+153}:\\
\;\;\;\;y \cdot \left(c \cdot \mathsf{expm1}\left(x\right)\right)\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
if y < -5.7564656385144782e95 or 6.6993600723541415e153 < y Initial program 42.1%
Applied rewrites51.5%
if -5.7564656385144782e95 < y < 6.6993600723541415e153Initial program 42.1%
Taylor expanded in y around 0
Applied rewrites74.1%
Applied rewrites77.6%
(FPCore (c x y) :precision binary64 :pre TRUE (if (<= y 6.6993600723541415e+153) (* y (* c (expm1 x))) (* c (log (+ 1.0 (* x y))))))
double code(double c, double x, double y) {
double tmp;
if (y <= 6.6993600723541415e+153) {
tmp = y * (c * expm1(x));
} else {
tmp = c * log((1.0 + (x * y)));
}
return tmp;
}
public static double code(double c, double x, double y) {
double tmp;
if (y <= 6.6993600723541415e+153) {
tmp = y * (c * Math.expm1(x));
} else {
tmp = c * Math.log((1.0 + (x * y)));
}
return tmp;
}
def code(c, x, y): tmp = 0 if y <= 6.6993600723541415e+153: tmp = y * (c * math.expm1(x)) else: tmp = c * math.log((1.0 + (x * y))) return tmp
function code(c, x, y) tmp = 0.0 if (y <= 6.6993600723541415e+153) tmp = Float64(y * Float64(c * expm1(x))); else tmp = Float64(c * log(Float64(1.0 + Float64(x * y)))); end return tmp end
code[c_, x_, y_] := If[LessEqual[y, 6.6993600723541415e+153], N[(y * N[(c * N[(Exp[x] - 1), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(c * N[Log[N[(1.0 + N[(x * y), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]
f(c, x, y): c in [-inf, +inf], x in [-inf, +inf], y in [-inf, +inf] code: THEORY BEGIN f(c, x, y: real): real = LET tmp = IF (y <= (6699360072354141475203966126958235020504119986664746420655450416218605553402243332468594199816495235077034820225283496654424754774302170343137135535587328)) THEN (y * (c * ((exp(x)) - (1)))) ELSE (c * (ln(((1) + (x * y))))) ENDIF IN tmp END code
\begin{array}{l}
\mathbf{if}\;y \leq 6.6993600723541415 \cdot 10^{+153}:\\
\;\;\;\;y \cdot \left(c \cdot \mathsf{expm1}\left(x\right)\right)\\
\mathbf{else}:\\
\;\;\;\;c \cdot \log \left(1 + x \cdot y\right)\\
\end{array}
if y < 6.6993600723541415e153Initial program 42.1%
Taylor expanded in y around 0
Applied rewrites74.1%
Applied rewrites77.6%
if 6.6993600723541415e153 < y Initial program 42.1%
Taylor expanded in x around 0
Applied rewrites40.1%
(FPCore (c x y) :precision binary64 :pre TRUE (if (<= x -7.417339803987706e-58) (* c (* y (expm1 x))) (* x (* c y))))
double code(double c, double x, double y) {
double tmp;
if (x <= -7.417339803987706e-58) {
tmp = c * (y * expm1(x));
} else {
tmp = x * (c * y);
}
return tmp;
}
public static double code(double c, double x, double y) {
double tmp;
if (x <= -7.417339803987706e-58) {
tmp = c * (y * Math.expm1(x));
} else {
tmp = x * (c * y);
}
return tmp;
}
def code(c, x, y): tmp = 0 if x <= -7.417339803987706e-58: tmp = c * (y * math.expm1(x)) else: tmp = x * (c * y) return tmp
function code(c, x, y) tmp = 0.0 if (x <= -7.417339803987706e-58) tmp = Float64(c * Float64(y * expm1(x))); else tmp = Float64(x * Float64(c * y)); end return tmp end
code[c_, x_, y_] := If[LessEqual[x, -7.417339803987706e-58], N[(c * N[(y * N[(Exp[x] - 1), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(x * N[(c * y), $MachinePrecision]), $MachinePrecision]]
f(c, x, y): c in [-inf, +inf], x in [-inf, +inf], y in [-inf, +inf] code: THEORY BEGIN f(c, x, y: real): real = LET tmp = IF (x <= (-7417339803987706051609638428185765246820801495451024508716982989045805325943245960443833233383756116685077234171247789697125728316515361223759499054164479048267821781337261199951171875e-241)) THEN (c * (y * ((exp(x)) - (1)))) ELSE (x * (c * y)) ENDIF IN tmp END code
\begin{array}{l}
\mathbf{if}\;x \leq -7.417339803987706 \cdot 10^{-58}:\\
\;\;\;\;c \cdot \left(y \cdot \mathsf{expm1}\left(x\right)\right)\\
\mathbf{else}:\\
\;\;\;\;x \cdot \left(c \cdot y\right)\\
\end{array}
if x < -7.4173398039877061e-58Initial program 42.1%
Taylor expanded in y around 0
Applied rewrites74.1%
if -7.4173398039877061e-58 < x Initial program 42.1%
Taylor expanded in x around 0
Applied rewrites56.2%
Applied rewrites62.3%
(FPCore (c x y) :precision binary64 :pre TRUE (* y (* c (expm1 x))))
double code(double c, double x, double y) {
return y * (c * expm1(x));
}
public static double code(double c, double x, double y) {
return y * (c * Math.expm1(x));
}
def code(c, x, y): return y * (c * math.expm1(x))
function code(c, x, y) return Float64(y * Float64(c * expm1(x))) end
code[c_, x_, y_] := N[(y * N[(c * N[(Exp[x] - 1), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
f(c, x, y): c in [-inf, +inf], x in [-inf, +inf], y in [-inf, +inf] code: THEORY BEGIN f(c, x, y: real): real = y * (c * ((exp(x)) - (1))) END code
y \cdot \left(c \cdot \mathsf{expm1}\left(x\right)\right)
Initial program 42.1%
Taylor expanded in y around 0
Applied rewrites74.1%
Applied rewrites77.6%
(FPCore (c x y) :precision binary64 :pre TRUE (* x (* c y)))
double code(double c, double x, double y) {
return x * (c * y);
}
real(8) function code(c, x, y)
use fmin_fmax_functions
real(8), intent (in) :: c
real(8), intent (in) :: x
real(8), intent (in) :: y
code = x * (c * y)
end function
public static double code(double c, double x, double y) {
return x * (c * y);
}
def code(c, x, y): return x * (c * y)
function code(c, x, y) return Float64(x * Float64(c * y)) end
function tmp = code(c, x, y) tmp = x * (c * y); end
code[c_, x_, y_] := N[(x * N[(c * y), $MachinePrecision]), $MachinePrecision]
f(c, x, y): c in [-inf, +inf], x in [-inf, +inf], y in [-inf, +inf] code: THEORY BEGIN f(c, x, y: real): real = x * (c * y) END code
x \cdot \left(c \cdot y\right)
Initial program 42.1%
Taylor expanded in x around 0
Applied rewrites56.2%
Applied rewrites62.3%
(FPCore (c x y) :precision binary64 :pre TRUE (if (<= x -5.742794795096544e+167) (* 0.0 c) (* c (* x y))))
double code(double c, double x, double y) {
double tmp;
if (x <= -5.742794795096544e+167) {
tmp = 0.0 * c;
} else {
tmp = c * (x * y);
}
return tmp;
}
real(8) function code(c, x, y)
use fmin_fmax_functions
real(8), intent (in) :: c
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if (x <= (-5.742794795096544d+167)) then
tmp = 0.0d0 * c
else
tmp = c * (x * y)
end if
code = tmp
end function
public static double code(double c, double x, double y) {
double tmp;
if (x <= -5.742794795096544e+167) {
tmp = 0.0 * c;
} else {
tmp = c * (x * y);
}
return tmp;
}
def code(c, x, y): tmp = 0 if x <= -5.742794795096544e+167: tmp = 0.0 * c else: tmp = c * (x * y) return tmp
function code(c, x, y) tmp = 0.0 if (x <= -5.742794795096544e+167) tmp = Float64(0.0 * c); else tmp = Float64(c * Float64(x * y)); end return tmp end
function tmp_2 = code(c, x, y) tmp = 0.0; if (x <= -5.742794795096544e+167) tmp = 0.0 * c; else tmp = c * (x * y); end tmp_2 = tmp; end
code[c_, x_, y_] := If[LessEqual[x, -5.742794795096544e+167], N[(0.0 * c), $MachinePrecision], N[(c * N[(x * y), $MachinePrecision]), $MachinePrecision]]
f(c, x, y): c in [-inf, +inf], x in [-inf, +inf], y in [-inf, +inf] code: THEORY BEGIN f(c, x, y: real): real = LET tmp = IF (x <= (-574279479509654428513738203990391290412983179384704553627057515023638265121933065921031923646839306755009345843997374291291218962910957683421804481399581996264607186944)) THEN ((0) * c) ELSE (c * (x * y)) ENDIF IN tmp END code
\begin{array}{l}
\mathbf{if}\;x \leq -5.742794795096544 \cdot 10^{+167}:\\
\;\;\;\;0 \cdot c\\
\mathbf{else}:\\
\;\;\;\;c \cdot \left(x \cdot y\right)\\
\end{array}
if x < -5.7427947950965443e167Initial program 42.1%
Applied rewrites51.4%
Applied rewrites25.6%
Taylor expanded in x around 0
Applied rewrites5.9%
Applied rewrites31.2%
if -5.7427947950965443e167 < x Initial program 42.1%
Taylor expanded in x around 0
Applied rewrites56.2%
(FPCore (c x y) :precision binary64 :pre TRUE (* 0.0 c))
double code(double c, double x, double y) {
return 0.0 * c;
}
real(8) function code(c, x, y)
use fmin_fmax_functions
real(8), intent (in) :: c
real(8), intent (in) :: x
real(8), intent (in) :: y
code = 0.0d0 * c
end function
public static double code(double c, double x, double y) {
return 0.0 * c;
}
def code(c, x, y): return 0.0 * c
function code(c, x, y) return Float64(0.0 * c) end
function tmp = code(c, x, y) tmp = 0.0 * c; end
code[c_, x_, y_] := N[(0.0 * c), $MachinePrecision]
f(c, x, y): c in [-inf, +inf], x in [-inf, +inf], y in [-inf, +inf] code: THEORY BEGIN f(c, x, y: real): real = (0) * c END code
0 \cdot c
Initial program 42.1%
Applied rewrites51.4%
Applied rewrites25.6%
Taylor expanded in x around 0
Applied rewrites5.9%
Applied rewrites31.2%
(FPCore (c x y) :precision binary64 :pre TRUE (* c (log1p (* (expm1 x) y))))
double code(double c, double x, double y) {
return c * log1p((expm1(x) * y));
}
public static double code(double c, double x, double y) {
return c * Math.log1p((Math.expm1(x) * y));
}
def code(c, x, y): return c * math.log1p((math.expm1(x) * y))
function code(c, x, y) return Float64(c * log1p(Float64(expm1(x) * y))) end
code[c_, x_, y_] := N[(c * N[Log[1 + N[(N[(Exp[x] - 1), $MachinePrecision] * y), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
f(c, x, y): c in [-inf, +inf], x in [-inf, +inf], y in [-inf, +inf] code: THEORY BEGIN f(c, x, y: real): real = c * (ln(((((exp(x)) - (1)) * y) + (1)))) END code
c \cdot \mathsf{log1p}\left(\mathsf{expm1}\left(x\right) \cdot y\right)
herbie shell --seed 2026089 +o generate:egglog
(FPCore (c x y)
:name "Logarithmic Transform"
:precision binary64
:alt
(* c (log1p (* (expm1 x) y)))
(* c (log (+ 1.0 (* (- (pow E x) 1.0) y)))))