
(FPCore (c x y) :precision binary64 (* 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]
\begin{array}{l}
\\
c \cdot \log \left(1 + \left({e}^{x} - 1\right) \cdot y\right)
\end{array}
Herbie found 7 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (c x y) :precision binary64 (* 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]
\begin{array}{l}
\\
c \cdot \log \left(1 + \left({e}^{x} - 1\right) \cdot y\right)
\end{array}
(FPCore (c x y) :precision binary64 (let* ((t_0 (* c (log1p (* (expm1 x) y))))) (if (<= y -6.6e-14) t_0 (if (<= y 1.8e-22) (* (* 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 <= -6.6e-14) {
tmp = t_0;
} else if (y <= 1.8e-22) {
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 <= -6.6e-14) {
tmp = t_0;
} else if (y <= 1.8e-22) {
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 <= -6.6e-14: tmp = t_0 elif y <= 1.8e-22: 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 <= -6.6e-14) tmp = t_0; elseif (y <= 1.8e-22) tmp = Float64(Float64(y * 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, -6.6e-14], t$95$0, If[LessEqual[y, 1.8e-22], N[(N[(y * c), $MachinePrecision] * N[(Exp[x] - 1), $MachinePrecision]), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := c \cdot \mathsf{log1p}\left(\mathsf{expm1}\left(x\right) \cdot y\right)\\
\mathbf{if}\;y \leq -6.6 \cdot 10^{-14}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq 1.8 \cdot 10^{-22}:\\
\;\;\;\;\left(y \cdot c\right) \cdot \mathsf{expm1}\left(x\right)\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if y < -6.5999999999999996e-14 or 1.7999999999999999e-22 < y Initial program 41.6%
lift-log.f64N/A
lift-+.f64N/A
lift-*.f64N/A
lift--.f64N/A
lift-E.f64N/A
lift-pow.f64N/A
*-commutativeN/A
lower-log1p.f64N/A
*-commutativeN/A
lower-*.f64N/A
pow-to-expN/A
log-EN/A
*-commutativeN/A
lower-expm1.f64N/A
lower-*.f6493.1
Applied rewrites93.1%
lift-*.f64N/A
*-rgt-identity93.1
Applied rewrites93.1%
if -6.5999999999999996e-14 < y < 1.7999999999999999e-22Initial program 41.6%
Taylor expanded in y around 0
associate-*r*N/A
lower-*.f64N/A
lower-*.f64N/A
pow-to-expN/A
log-EN/A
*-commutativeN/A
lower-expm1.f64N/A
lower-*.f6476.9
Applied rewrites76.9%
lift-*.f64N/A
*-commutativeN/A
lower-*.f6476.9
lift-*.f64N/A
*-rgt-identity76.9
Applied rewrites76.9%
(FPCore (c x y) :precision binary64 (let* ((t_0 (* c (log1p (* x y))))) (if (<= y -21000.0) t_0 (if (<= y 1.1) (* (* y c) (expm1 x)) t_0))))
double code(double c, double x, double y) {
double t_0 = c * log1p((x * y));
double tmp;
if (y <= -21000.0) {
tmp = t_0;
} else if (y <= 1.1) {
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((x * y));
double tmp;
if (y <= -21000.0) {
tmp = t_0;
} else if (y <= 1.1) {
tmp = (y * c) * Math.expm1(x);
} else {
tmp = t_0;
}
return tmp;
}
def code(c, x, y): t_0 = c * math.log1p((x * y)) tmp = 0 if y <= -21000.0: tmp = t_0 elif y <= 1.1: tmp = (y * c) * math.expm1(x) else: tmp = t_0 return tmp
function code(c, x, y) t_0 = Float64(c * log1p(Float64(x * y))) tmp = 0.0 if (y <= -21000.0) tmp = t_0; elseif (y <= 1.1) tmp = Float64(Float64(y * 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[(x * y), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[y, -21000.0], t$95$0, If[LessEqual[y, 1.1], N[(N[(y * c), $MachinePrecision] * N[(Exp[x] - 1), $MachinePrecision]), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := c \cdot \mathsf{log1p}\left(x \cdot y\right)\\
\mathbf{if}\;y \leq -21000:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq 1.1:\\
\;\;\;\;\left(y \cdot c\right) \cdot \mathsf{expm1}\left(x\right)\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if y < -21000 or 1.1000000000000001 < y Initial program 41.6%
lift-log.f64N/A
lift-+.f64N/A
lift-*.f64N/A
lift--.f64N/A
lift-E.f64N/A
lift-pow.f64N/A
*-commutativeN/A
lower-log1p.f64N/A
*-commutativeN/A
lower-*.f64N/A
pow-to-expN/A
log-EN/A
*-commutativeN/A
lower-expm1.f64N/A
lower-*.f6493.1
Applied rewrites93.1%
Taylor expanded in x around 0
lift-*.f64N/A
lift-expm1.f64N/A
lift-*.f64N/A
*-rgt-identityN/A
lower-expm1.f6465.5
*-rgt-identity65.5
*-commutative65.5
log-E65.5
pow-to-exp65.5
Applied rewrites65.5%
if -21000 < y < 1.1000000000000001Initial program 41.6%
Taylor expanded in y around 0
associate-*r*N/A
lower-*.f64N/A
lower-*.f64N/A
pow-to-expN/A
log-EN/A
*-commutativeN/A
lower-expm1.f64N/A
lower-*.f6476.9
Applied rewrites76.9%
lift-*.f64N/A
*-commutativeN/A
lower-*.f6476.9
lift-*.f64N/A
*-rgt-identity76.9
Applied rewrites76.9%
(FPCore (c x y)
:precision binary64
(let* ((t_0 (* (log (fma x y 1.0)) c)))
(if (<= y -8.6e+133)
t_0
(if (<= y 1.0)
(* (* y c) (expm1 x))
(if (<= y 3.7e+189) (* c (* y x)) t_0)))))
double code(double c, double x, double y) {
double t_0 = log(fma(x, y, 1.0)) * c;
double tmp;
if (y <= -8.6e+133) {
tmp = t_0;
} else if (y <= 1.0) {
tmp = (y * c) * expm1(x);
} else if (y <= 3.7e+189) {
tmp = c * (y * x);
} else {
tmp = t_0;
}
return tmp;
}
function code(c, x, y) t_0 = Float64(log(fma(x, y, 1.0)) * c) tmp = 0.0 if (y <= -8.6e+133) tmp = t_0; elseif (y <= 1.0) tmp = Float64(Float64(y * c) * expm1(x)); elseif (y <= 3.7e+189) tmp = Float64(c * Float64(y * x)); else tmp = t_0; end return tmp end
code[c_, x_, y_] := Block[{t$95$0 = N[(N[Log[N[(x * y + 1.0), $MachinePrecision]], $MachinePrecision] * c), $MachinePrecision]}, If[LessEqual[y, -8.6e+133], t$95$0, If[LessEqual[y, 1.0], N[(N[(y * c), $MachinePrecision] * N[(Exp[x] - 1), $MachinePrecision]), $MachinePrecision], If[LessEqual[y, 3.7e+189], N[(c * N[(y * x), $MachinePrecision]), $MachinePrecision], t$95$0]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \log \left(\mathsf{fma}\left(x, y, 1\right)\right) \cdot c\\
\mathbf{if}\;y \leq -8.6 \cdot 10^{+133}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq 1:\\
\;\;\;\;\left(y \cdot c\right) \cdot \mathsf{expm1}\left(x\right)\\
\mathbf{elif}\;y \leq 3.7 \cdot 10^{+189}:\\
\;\;\;\;c \cdot \left(y \cdot x\right)\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if y < -8.59999999999999989e133 or 3.70000000000000021e189 < y Initial program 41.6%
lift-*.f64N/A
lift-log.f64N/A
lift-+.f64N/A
lift-*.f64N/A
lift--.f64N/A
lift-E.f64N/A
lift-pow.f64N/A
*-commutativeN/A
lower-*.f64N/A
Applied rewrites50.8%
Taylor expanded in x around 0
lift-*.f64N/A
lift-expm1.f64N/A
lift-*.f64N/A
*-rgt-identityN/A
lower-expm1.f6439.1
*-rgt-identity39.1
*-commutative39.1
log-E39.1
pow-to-exp39.1
Applied rewrites39.1%
if -8.59999999999999989e133 < y < 1Initial program 41.6%
Taylor expanded in y around 0
associate-*r*N/A
lower-*.f64N/A
lower-*.f64N/A
pow-to-expN/A
log-EN/A
*-commutativeN/A
lower-expm1.f64N/A
lower-*.f6476.9
Applied rewrites76.9%
lift-*.f64N/A
*-commutativeN/A
lower-*.f6476.9
lift-*.f64N/A
*-rgt-identity76.9
Applied rewrites76.9%
if 1 < y < 3.70000000000000021e189Initial program 41.6%
lift-log.f64N/A
lift-+.f64N/A
lift-*.f64N/A
lift--.f64N/A
lift-E.f64N/A
lift-pow.f64N/A
*-commutativeN/A
lower-log1p.f64N/A
*-commutativeN/A
lower-*.f64N/A
pow-to-expN/A
log-EN/A
*-commutativeN/A
lower-expm1.f64N/A
lower-*.f6493.1
Applied rewrites93.1%
Taylor expanded in x around 0
lift-*.f64N/A
lift-expm1.f64N/A
lift-*.f64N/A
lift-log1p.f64N/A
lift-*.f64N/A
*-rgt-identityN/A
lower-expm1.f64N/A
*-rgt-identityN/A
*-commutativeN/A
log-EN/A
pow-to-expN/A
lower-*.f64N/A
*-commutativeN/A
lower-log1p.f64N/A
*-commutativeN/A
*-commutativeN/A
lower-*.f6456.0
Applied rewrites56.0%
(FPCore (c x y) :precision binary64 (if (<= y 1.0) (* (* y c) (expm1 x)) (* c (* y x))))
double code(double c, double x, double y) {
double tmp;
if (y <= 1.0) {
tmp = (y * c) * expm1(x);
} else {
tmp = c * (y * x);
}
return tmp;
}
public static double code(double c, double x, double y) {
double tmp;
if (y <= 1.0) {
tmp = (y * c) * Math.expm1(x);
} else {
tmp = c * (y * x);
}
return tmp;
}
def code(c, x, y): tmp = 0 if y <= 1.0: tmp = (y * c) * math.expm1(x) else: tmp = c * (y * x) return tmp
function code(c, x, y) tmp = 0.0 if (y <= 1.0) tmp = Float64(Float64(y * c) * expm1(x)); else tmp = Float64(c * Float64(y * x)); end return tmp end
code[c_, x_, y_] := If[LessEqual[y, 1.0], N[(N[(y * c), $MachinePrecision] * N[(Exp[x] - 1), $MachinePrecision]), $MachinePrecision], N[(c * N[(y * x), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 1:\\
\;\;\;\;\left(y \cdot c\right) \cdot \mathsf{expm1}\left(x\right)\\
\mathbf{else}:\\
\;\;\;\;c \cdot \left(y \cdot x\right)\\
\end{array}
\end{array}
if y < 1Initial program 41.6%
Taylor expanded in y around 0
associate-*r*N/A
lower-*.f64N/A
lower-*.f64N/A
pow-to-expN/A
log-EN/A
*-commutativeN/A
lower-expm1.f64N/A
lower-*.f6476.9
Applied rewrites76.9%
lift-*.f64N/A
*-commutativeN/A
lower-*.f6476.9
lift-*.f64N/A
*-rgt-identity76.9
Applied rewrites76.9%
if 1 < y Initial program 41.6%
lift-log.f64N/A
lift-+.f64N/A
lift-*.f64N/A
lift--.f64N/A
lift-E.f64N/A
lift-pow.f64N/A
*-commutativeN/A
lower-log1p.f64N/A
*-commutativeN/A
lower-*.f64N/A
pow-to-expN/A
log-EN/A
*-commutativeN/A
lower-expm1.f64N/A
lower-*.f6493.1
Applied rewrites93.1%
Taylor expanded in x around 0
lift-*.f64N/A
lift-expm1.f64N/A
lift-*.f64N/A
lift-log1p.f64N/A
lift-*.f64N/A
*-rgt-identityN/A
lower-expm1.f64N/A
*-rgt-identityN/A
*-commutativeN/A
log-EN/A
pow-to-expN/A
lower-*.f64N/A
*-commutativeN/A
lower-log1p.f64N/A
*-commutativeN/A
*-commutativeN/A
lower-*.f6456.0
Applied rewrites56.0%
(FPCore (c x y) :precision binary64 (if (<= c 0.0001) (* (* c y) x) (* (* c x) (* y 1.0))))
double code(double c, double x, double y) {
double tmp;
if (c <= 0.0001) {
tmp = (c * y) * x;
} else {
tmp = (c * x) * (y * 1.0);
}
return tmp;
}
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
real(8) :: tmp
if (c <= 0.0001d0) then
tmp = (c * y) * x
else
tmp = (c * x) * (y * 1.0d0)
end if
code = tmp
end function
public static double code(double c, double x, double y) {
double tmp;
if (c <= 0.0001) {
tmp = (c * y) * x;
} else {
tmp = (c * x) * (y * 1.0);
}
return tmp;
}
def code(c, x, y): tmp = 0 if c <= 0.0001: tmp = (c * y) * x else: tmp = (c * x) * (y * 1.0) return tmp
function code(c, x, y) tmp = 0.0 if (c <= 0.0001) tmp = Float64(Float64(c * y) * x); else tmp = Float64(Float64(c * x) * Float64(y * 1.0)); end return tmp end
function tmp_2 = code(c, x, y) tmp = 0.0; if (c <= 0.0001) tmp = (c * y) * x; else tmp = (c * x) * (y * 1.0); end tmp_2 = tmp; end
code[c_, x_, y_] := If[LessEqual[c, 0.0001], N[(N[(c * y), $MachinePrecision] * x), $MachinePrecision], N[(N[(c * x), $MachinePrecision] * N[(y * 1.0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;c \leq 0.0001:\\
\;\;\;\;\left(c \cdot y\right) \cdot x\\
\mathbf{else}:\\
\;\;\;\;\left(c \cdot x\right) \cdot \left(y \cdot 1\right)\\
\end{array}
\end{array}
if c < 1.00000000000000005e-4Initial program 41.6%
Taylor expanded in y around 0
associate-*r*N/A
lower-*.f64N/A
lower-*.f64N/A
pow-to-expN/A
log-EN/A
*-commutativeN/A
lower-expm1.f64N/A
lower-*.f6476.9
Applied rewrites76.9%
Taylor expanded in x around 0
lift-*.f64N/A
lift-expm1.f64N/A
lift-*.f64N/A
*-rgt-identityN/A
lower-expm1.f6461.6
*-rgt-identity61.6
*-commutative61.6
log-E61.6
pow-to-exp61.6
Applied rewrites61.6%
if 1.00000000000000005e-4 < c Initial program 41.6%
Taylor expanded in x around 0
associate-*r*N/A
log-EN/A
lower-*.f64N/A
lower-*.f64N/A
lower-*.f6459.5
Applied rewrites59.5%
(FPCore (c x y) :precision binary64 (if (<= y 1.8e-22) (* (* c y) x) (* c (* y x))))
double code(double c, double x, double y) {
double tmp;
if (y <= 1.8e-22) {
tmp = (c * y) * x;
} else {
tmp = c * (y * x);
}
return tmp;
}
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
real(8) :: tmp
if (y <= 1.8d-22) then
tmp = (c * y) * x
else
tmp = c * (y * x)
end if
code = tmp
end function
public static double code(double c, double x, double y) {
double tmp;
if (y <= 1.8e-22) {
tmp = (c * y) * x;
} else {
tmp = c * (y * x);
}
return tmp;
}
def code(c, x, y): tmp = 0 if y <= 1.8e-22: tmp = (c * y) * x else: tmp = c * (y * x) return tmp
function code(c, x, y) tmp = 0.0 if (y <= 1.8e-22) tmp = Float64(Float64(c * y) * x); else tmp = Float64(c * Float64(y * x)); end return tmp end
function tmp_2 = code(c, x, y) tmp = 0.0; if (y <= 1.8e-22) tmp = (c * y) * x; else tmp = c * (y * x); end tmp_2 = tmp; end
code[c_, x_, y_] := If[LessEqual[y, 1.8e-22], N[(N[(c * y), $MachinePrecision] * x), $MachinePrecision], N[(c * N[(y * x), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 1.8 \cdot 10^{-22}:\\
\;\;\;\;\left(c \cdot y\right) \cdot x\\
\mathbf{else}:\\
\;\;\;\;c \cdot \left(y \cdot x\right)\\
\end{array}
\end{array}
if y < 1.7999999999999999e-22Initial program 41.6%
Taylor expanded in y around 0
associate-*r*N/A
lower-*.f64N/A
lower-*.f64N/A
pow-to-expN/A
log-EN/A
*-commutativeN/A
lower-expm1.f64N/A
lower-*.f6476.9
Applied rewrites76.9%
Taylor expanded in x around 0
lift-*.f64N/A
lift-expm1.f64N/A
lift-*.f64N/A
*-rgt-identityN/A
lower-expm1.f6461.6
*-rgt-identity61.6
*-commutative61.6
log-E61.6
pow-to-exp61.6
Applied rewrites61.6%
if 1.7999999999999999e-22 < y Initial program 41.6%
lift-log.f64N/A
lift-+.f64N/A
lift-*.f64N/A
lift--.f64N/A
lift-E.f64N/A
lift-pow.f64N/A
*-commutativeN/A
lower-log1p.f64N/A
*-commutativeN/A
lower-*.f64N/A
pow-to-expN/A
log-EN/A
*-commutativeN/A
lower-expm1.f64N/A
lower-*.f6493.1
Applied rewrites93.1%
Taylor expanded in x around 0
lift-*.f64N/A
lift-expm1.f64N/A
lift-*.f64N/A
lift-log1p.f64N/A
lift-*.f64N/A
*-rgt-identityN/A
lower-expm1.f64N/A
*-rgt-identityN/A
*-commutativeN/A
log-EN/A
pow-to-expN/A
lower-*.f64N/A
*-commutativeN/A
lower-log1p.f64N/A
*-commutativeN/A
*-commutativeN/A
lower-*.f6456.0
Applied rewrites56.0%
(FPCore (c x y) :precision binary64 (* (* c y) x))
double code(double c, double x, double y) {
return (c * y) * x;
}
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 = (c * y) * x
end function
public static double code(double c, double x, double y) {
return (c * y) * x;
}
def code(c, x, y): return (c * y) * x
function code(c, x, y) return Float64(Float64(c * y) * x) end
function tmp = code(c, x, y) tmp = (c * y) * x; end
code[c_, x_, y_] := N[(N[(c * y), $MachinePrecision] * x), $MachinePrecision]
\begin{array}{l}
\\
\left(c \cdot y\right) \cdot x
\end{array}
Initial program 41.6%
Taylor expanded in y around 0
associate-*r*N/A
lower-*.f64N/A
lower-*.f64N/A
pow-to-expN/A
log-EN/A
*-commutativeN/A
lower-expm1.f64N/A
lower-*.f6476.9
Applied rewrites76.9%
Taylor expanded in x around 0
lift-*.f64N/A
lift-expm1.f64N/A
lift-*.f64N/A
*-rgt-identityN/A
lower-expm1.f6461.6
*-rgt-identity61.6
*-commutative61.6
log-E61.6
pow-to-exp61.6
Applied rewrites61.6%
(FPCore (c x y) :precision binary64 (* 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]
\begin{array}{l}
\\
c \cdot \mathsf{log1p}\left(\mathsf{expm1}\left(x\right) \cdot y\right)
\end{array}
herbie shell --seed 2025134
(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)))))