
(FPCore (c x y) :precision binary64 (* c (log (+ 1 (* (- (pow E x) 1) 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 + N[(N[(N[Power[E, x], $MachinePrecision] - 1), $MachinePrecision] * y), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
c \cdot \log \left(1 + \left({e}^{x} - 1\right) \cdot y\right)
Herbie found 7 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (c x y) :precision binary64 (* c (log (+ 1 (* (- (pow E x) 1) 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 + N[(N[(N[Power[E, x], $MachinePrecision] - 1), $MachinePrecision] * y), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
c \cdot \log \left(1 + \left({e}^{x} - 1\right) \cdot y\right)
(FPCore (c x y) :precision binary64 (if (<= (- (pow E x) 1) -5764607523034235/1152921504606846976) (* (30-log1z0 (* (- 1 (exp x)) y)) c) (* (30-log1z0 (* (* (- (* (- (* 1/6 x) -1/2) x) -1) x) (- y))) c)))
\begin{array}{l}
\mathbf{if}\;{e}^{x} - 1 \leq \frac{-5764607523034235}{1152921504606846976}:\\
\;\;\;\;\mathsf{30\_log1z0}\left(\left(\left(1 - e^{x}\right) \cdot y\right)\right) \cdot c\\
\mathbf{else}:\\
\;\;\;\;\mathsf{30\_log1z0}\left(\left(\left(\left(\left(\frac{1}{6} \cdot x - \frac{-1}{2}\right) \cdot x - -1\right) \cdot x\right) \cdot \left(-y\right)\right)\right) \cdot c\\
\end{array}
if (-.f64 (pow.f64 (E.f64) x) #s(literal 1 binary64)) < -0.0050000000000000001Initial program 41.5%
lift-*.f64N/A
*-commutativeN/A
lower-*.f6441.5%
Applied rewrites56.4%
if -0.0050000000000000001 < (-.f64 (pow.f64 (E.f64) x) #s(literal 1 binary64)) Initial program 41.5%
lift--.f64N/A
flip3--N/A
lower-unsound-/.f64N/A
lower-unsound--.f64N/A
lower-unsound-pow.f64N/A
lift-pow.f64N/A
lift-E.f64N/A
e-exp-1N/A
pow-expN/A
*-lft-identityN/A
lower-exp.f64N/A
lower-unsound-pow.f64N/A
lower-unsound-+.f64N/A
Applied rewrites41.4%
Taylor expanded in x around 0
lower-*.f64N/A
lower-+.f64N/A
lower-*.f64N/A
lower-+.f64N/A
lower-*.f6437.3%
Applied rewrites37.3%
Applied rewrites64.5%
(FPCore (c x y) :precision binary64 (if (<= (- (pow E x) 1) -5764607523034235/1152921504606846976) (* (- (exp x) 1) (* y c)) (* (30-log1z0 (* (* (- (* (- (* 1/6 x) -1/2) x) -1) x) (- y))) c)))
\begin{array}{l}
\mathbf{if}\;{e}^{x} - 1 \leq \frac{-5764607523034235}{1152921504606846976}:\\
\;\;\;\;\left(e^{x} - 1\right) \cdot \left(y \cdot c\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{30\_log1z0}\left(\left(\left(\left(\left(\frac{1}{6} \cdot x - \frac{-1}{2}\right) \cdot x - -1\right) \cdot x\right) \cdot \left(-y\right)\right)\right) \cdot c\\
\end{array}
if (-.f64 (pow.f64 (E.f64) x) #s(literal 1 binary64)) < -0.0050000000000000001Initial program 41.5%
Taylor expanded in y around 0
lower-*.f64N/A
lower-*.f64N/A
lower--.f64N/A
lower-pow.f64N/A
lower-E.f6446.1%
Applied rewrites46.1%
lift-*.f64N/A
lift-*.f64N/A
associate-*r*N/A
*-commutativeN/A
lower-*.f64N/A
lift-pow.f64N/A
lift-E.f64N/A
e-exp-1N/A
pow-expN/A
*-lft-identityN/A
lift-exp.f64N/A
*-commutativeN/A
lower-*.f6445.9%
Applied rewrites45.9%
if -0.0050000000000000001 < (-.f64 (pow.f64 (E.f64) x) #s(literal 1 binary64)) Initial program 41.5%
lift--.f64N/A
flip3--N/A
lower-unsound-/.f64N/A
lower-unsound--.f64N/A
lower-unsound-pow.f64N/A
lift-pow.f64N/A
lift-E.f64N/A
e-exp-1N/A
pow-expN/A
*-lft-identityN/A
lower-exp.f64N/A
lower-unsound-pow.f64N/A
lower-unsound-+.f64N/A
Applied rewrites41.4%
Taylor expanded in x around 0
lower-*.f64N/A
lower-+.f64N/A
lower-*.f64N/A
lower-+.f64N/A
lower-*.f6437.3%
Applied rewrites37.3%
Applied rewrites64.5%
(FPCore (c x y)
:precision binary64
(if (<=
y
-5767152963771295/22181357552966518876627313473144669627491496603006532601363836644916970462445004984319795248833116624779129687691228574631793262592)
(* (30-log1z0 (* (* 1 x) (- y))) c)
(if (<=
y
3916911482881289/100433627766186892221372630771322662657637687111424552206336)
(* (* y c) x)
(*
(30-log1z0 (* (* (- (* (- (* 1/6 x) -1/2) x) -1) x) (- y)))
c))))\begin{array}{l}
\mathbf{if}\;y \leq \frac{-5767152963771295}{22181357552966518876627313473144669627491496603006532601363836644916970462445004984319795248833116624779129687691228574631793262592}:\\
\;\;\;\;\mathsf{30\_log1z0}\left(\left(\left(1 \cdot x\right) \cdot \left(-y\right)\right)\right) \cdot c\\
\mathbf{elif}\;y \leq \frac{3916911482881289}{100433627766186892221372630771322662657637687111424552206336}:\\
\;\;\;\;\left(y \cdot c\right) \cdot x\\
\mathbf{else}:\\
\;\;\;\;\mathsf{30\_log1z0}\left(\left(\left(\left(\left(\frac{1}{6} \cdot x - \frac{-1}{2}\right) \cdot x - -1\right) \cdot x\right) \cdot \left(-y\right)\right)\right) \cdot c\\
\end{array}
if y < -2.6e-115Initial program 41.5%
Taylor expanded in x around 0
lower-*.f64N/A
lower-+.f64N/A
lower-log.f64N/A
lower-E.f64N/A
lower-*.f64N/A
lower-*.f64N/A
lower-pow.f64N/A
lower-log.f64N/A
lower-E.f6436.8%
Applied rewrites36.8%
lift-*.f64N/A
*-commutativeN/A
lower-*.f6436.8%
Applied rewrites64.1%
Taylor expanded in x around 0
Applied rewrites66.1%
if -2.6e-115 < y < 3.9000000000000002e-44Initial program 41.5%
Taylor expanded in x around 0
lower-*.f64N/A
lower-*.f64N/A
lower-*.f64N/A
lower-log.f64N/A
lower-E.f6456.4%
Applied rewrites56.4%
lift-*.f64N/A
lift-*.f64N/A
*-commutativeN/A
lift-*.f64N/A
lift-log.f64N/A
lift-E.f64N/A
log-EN/A
*-rgt-identityN/A
associate-*r*N/A
lower-*.f64N/A
*-commutativeN/A
lower-*.f6461.9%
Applied rewrites61.9%
if 3.9000000000000002e-44 < y Initial program 41.5%
lift--.f64N/A
flip3--N/A
lower-unsound-/.f64N/A
lower-unsound--.f64N/A
lower-unsound-pow.f64N/A
lift-pow.f64N/A
lift-E.f64N/A
e-exp-1N/A
pow-expN/A
*-lft-identityN/A
lower-exp.f64N/A
lower-unsound-pow.f64N/A
lower-unsound-+.f64N/A
Applied rewrites41.4%
Taylor expanded in x around 0
lower-*.f64N/A
lower-+.f64N/A
lower-*.f64N/A
lower-+.f64N/A
lower-*.f6437.3%
Applied rewrites37.3%
Applied rewrites64.5%
(FPCore (c x y)
:precision binary64
(if (<=
y
-5767152963771295/22181357552966518876627313473144669627491496603006532601363836644916970462445004984319795248833116624779129687691228574631793262592)
(* (30-log1z0 (* (* 1 x) (- y))) c)
(if (<=
y
4097692012860425/803469022129495137770981046170581301261101496891396417650688)
(* (* y c) x)
(* (30-log1z0 (* (* (- (* 1/2 x) -1) x) (- y))) c))))\begin{array}{l}
\mathbf{if}\;y \leq \frac{-5767152963771295}{22181357552966518876627313473144669627491496603006532601363836644916970462445004984319795248833116624779129687691228574631793262592}:\\
\;\;\;\;\mathsf{30\_log1z0}\left(\left(\left(1 \cdot x\right) \cdot \left(-y\right)\right)\right) \cdot c\\
\mathbf{elif}\;y \leq \frac{4097692012860425}{803469022129495137770981046170581301261101496891396417650688}:\\
\;\;\;\;\left(y \cdot c\right) \cdot x\\
\mathbf{else}:\\
\;\;\;\;\mathsf{30\_log1z0}\left(\left(\left(\left(\frac{1}{2} \cdot x - -1\right) \cdot x\right) \cdot \left(-y\right)\right)\right) \cdot c\\
\end{array}
if y < -2.6e-115Initial program 41.5%
Taylor expanded in x around 0
lower-*.f64N/A
lower-+.f64N/A
lower-log.f64N/A
lower-E.f64N/A
lower-*.f64N/A
lower-*.f64N/A
lower-pow.f64N/A
lower-log.f64N/A
lower-E.f6436.8%
Applied rewrites36.8%
lift-*.f64N/A
*-commutativeN/A
lower-*.f6436.8%
Applied rewrites64.1%
Taylor expanded in x around 0
Applied rewrites66.1%
if -2.6e-115 < y < 5.0999999999999997e-45Initial program 41.5%
Taylor expanded in x around 0
lower-*.f64N/A
lower-*.f64N/A
lower-*.f64N/A
lower-log.f64N/A
lower-E.f6456.4%
Applied rewrites56.4%
lift-*.f64N/A
lift-*.f64N/A
*-commutativeN/A
lift-*.f64N/A
lift-log.f64N/A
lift-E.f64N/A
log-EN/A
*-rgt-identityN/A
associate-*r*N/A
lower-*.f64N/A
*-commutativeN/A
lower-*.f6461.9%
Applied rewrites61.9%
if 5.0999999999999997e-45 < y Initial program 41.5%
Taylor expanded in x around 0
lower-*.f64N/A
lower-+.f64N/A
lower-log.f64N/A
lower-E.f64N/A
lower-*.f64N/A
lower-*.f64N/A
lower-pow.f64N/A
lower-log.f64N/A
lower-E.f6436.8%
Applied rewrites36.8%
lift-*.f64N/A
*-commutativeN/A
lower-*.f6436.8%
Applied rewrites64.1%
(FPCore (c x y)
:precision binary64
(let* ((t_0 (* (30-log1z0 (* (* 1 x) (- y))) c)))
(if (<=
y
-5767152963771295/22181357552966518876627313473144669627491496603006532601363836644916970462445004984319795248833116624779129687691228574631793262592)
t_0
(if (<= y 210000000000000000) (* (* y c) x) t_0))))\begin{array}{l}
t_0 := \mathsf{30\_log1z0}\left(\left(\left(1 \cdot x\right) \cdot \left(-y\right)\right)\right) \cdot c\\
\mathbf{if}\;y \leq \frac{-5767152963771295}{22181357552966518876627313473144669627491496603006532601363836644916970462445004984319795248833116624779129687691228574631793262592}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq 210000000000000000:\\
\;\;\;\;\left(y \cdot c\right) \cdot x\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
if y < -2.6e-115 or 2.1e17 < y Initial program 41.5%
Taylor expanded in x around 0
lower-*.f64N/A
lower-+.f64N/A
lower-log.f64N/A
lower-E.f64N/A
lower-*.f64N/A
lower-*.f64N/A
lower-pow.f64N/A
lower-log.f64N/A
lower-E.f6436.8%
Applied rewrites36.8%
lift-*.f64N/A
*-commutativeN/A
lower-*.f6436.8%
Applied rewrites64.1%
Taylor expanded in x around 0
Applied rewrites66.1%
if -2.6e-115 < y < 2.1e17Initial program 41.5%
Taylor expanded in x around 0
lower-*.f64N/A
lower-*.f64N/A
lower-*.f64N/A
lower-log.f64N/A
lower-E.f6456.4%
Applied rewrites56.4%
lift-*.f64N/A
lift-*.f64N/A
*-commutativeN/A
lift-*.f64N/A
lift-log.f64N/A
lift-E.f64N/A
log-EN/A
*-rgt-identityN/A
associate-*r*N/A
lower-*.f64N/A
*-commutativeN/A
lower-*.f6461.9%
Applied rewrites61.9%
(FPCore (c x y)
:precision binary64
(*
(copysign 1 c)
(if (<=
(fabs c)
6257774519299541/521481209941628438084722096232800809229175908778479680162851955034721612739414196782949728256)
(* (* y (fabs c)) x)
(* (* x (fabs c)) y))))double code(double c, double x, double y) {
double tmp;
if (fabs(c) <= 1.2e-77) {
tmp = (y * fabs(c)) * x;
} else {
tmp = (x * fabs(c)) * y;
}
return copysign(1.0, c) * tmp;
}
public static double code(double c, double x, double y) {
double tmp;
if (Math.abs(c) <= 1.2e-77) {
tmp = (y * Math.abs(c)) * x;
} else {
tmp = (x * Math.abs(c)) * y;
}
return Math.copySign(1.0, c) * tmp;
}
def code(c, x, y): tmp = 0 if math.fabs(c) <= 1.2e-77: tmp = (y * math.fabs(c)) * x else: tmp = (x * math.fabs(c)) * y return math.copysign(1.0, c) * tmp
function code(c, x, y) tmp = 0.0 if (abs(c) <= 1.2e-77) tmp = Float64(Float64(y * abs(c)) * x); else tmp = Float64(Float64(x * abs(c)) * y); end return Float64(copysign(1.0, c) * tmp) end
function tmp_2 = code(c, x, y) tmp = 0.0; if (abs(c) <= 1.2e-77) tmp = (y * abs(c)) * x; else tmp = (x * abs(c)) * y; end tmp_2 = (sign(c) * abs(1.0)) * tmp; end
code[c_, x_, y_] := N[(N[With[{TMP1 = Abs[1], TMP2 = Sign[c]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision] * If[LessEqual[N[Abs[c], $MachinePrecision], 6257774519299541/521481209941628438084722096232800809229175908778479680162851955034721612739414196782949728256], N[(N[(y * N[Abs[c], $MachinePrecision]), $MachinePrecision] * x), $MachinePrecision], N[(N[(x * N[Abs[c], $MachinePrecision]), $MachinePrecision] * y), $MachinePrecision]]), $MachinePrecision]
\mathsf{copysign}\left(1, c\right) \cdot \begin{array}{l}
\mathbf{if}\;\left|c\right| \leq \frac{6257774519299541}{521481209941628438084722096232800809229175908778479680162851955034721612739414196782949728256}:\\
\;\;\;\;\left(y \cdot \left|c\right|\right) \cdot x\\
\mathbf{else}:\\
\;\;\;\;\left(x \cdot \left|c\right|\right) \cdot y\\
\end{array}
if c < 1.2e-77Initial program 41.5%
Taylor expanded in x around 0
lower-*.f64N/A
lower-*.f64N/A
lower-*.f64N/A
lower-log.f64N/A
lower-E.f6456.4%
Applied rewrites56.4%
lift-*.f64N/A
lift-*.f64N/A
*-commutativeN/A
lift-*.f64N/A
lift-log.f64N/A
lift-E.f64N/A
log-EN/A
*-rgt-identityN/A
associate-*r*N/A
lower-*.f64N/A
*-commutativeN/A
lower-*.f6461.9%
Applied rewrites61.9%
if 1.2e-77 < c Initial program 41.5%
Taylor expanded in x around 0
lower-*.f64N/A
lower-*.f64N/A
lower-*.f64N/A
lower-log.f64N/A
lower-E.f6456.4%
Applied rewrites56.4%
lift-*.f64N/A
lift-*.f64N/A
associate-*r*N/A
lift-*.f64N/A
lift-log.f64N/A
lift-E.f64N/A
log-EN/A
*-rgt-identityN/A
lower-*.f64N/A
*-commutativeN/A
lower-*.f6459.6%
Applied rewrites59.6%
(FPCore (c x y) :precision binary64 (* (* x c) y))
double code(double c, double x, double y) {
return (x * c) * y;
}
module fmin_fmax_functions
implicit none
private
public fmax
public fmin
interface fmax
module procedure fmax88
module procedure fmax44
module procedure fmax84
module procedure fmax48
end interface
interface fmin
module procedure fmin88
module procedure fmin44
module procedure fmin84
module procedure fmin48
end interface
contains
real(8) function fmax88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(4) function fmax44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(8) function fmax84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmax48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
end function
real(8) function fmin88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(4) function fmin44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(8) function fmin84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmin48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
end function
end module
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(Float64(x * c) * y) end
function tmp = code(c, x, y) tmp = (x * c) * y; end
code[c_, x_, y_] := N[(N[(x * c), $MachinePrecision] * y), $MachinePrecision]
\left(x \cdot c\right) \cdot y
Initial program 41.5%
Taylor expanded in x around 0
lower-*.f64N/A
lower-*.f64N/A
lower-*.f64N/A
lower-log.f64N/A
lower-E.f6456.4%
Applied rewrites56.4%
lift-*.f64N/A
lift-*.f64N/A
associate-*r*N/A
lift-*.f64N/A
lift-log.f64N/A
lift-E.f64N/A
log-EN/A
*-rgt-identityN/A
lower-*.f64N/A
*-commutativeN/A
lower-*.f6459.6%
Applied rewrites59.6%
herbie shell --seed 2025271 -o generate:evaluate
(FPCore (c x y)
:name "Logarithmic Transform"
:precision binary64
(* c (log (+ 1 (* (- (pow E x) 1) y)))))