
(FPCore (x) :precision binary64 (- (/ 2.0 (+ 1.0 (exp (* -2.0 x)))) 1.0))
double code(double x) {
return (2.0 / (1.0 + exp((-2.0 * x)))) - 1.0;
}
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(x)
use fmin_fmax_functions
real(8), intent (in) :: x
code = (2.0d0 / (1.0d0 + exp(((-2.0d0) * x)))) - 1.0d0
end function
public static double code(double x) {
return (2.0 / (1.0 + Math.exp((-2.0 * x)))) - 1.0;
}
def code(x): return (2.0 / (1.0 + math.exp((-2.0 * x)))) - 1.0
function code(x) return Float64(Float64(2.0 / Float64(1.0 + exp(Float64(-2.0 * x)))) - 1.0) end
function tmp = code(x) tmp = (2.0 / (1.0 + exp((-2.0 * x)))) - 1.0; end
code[x_] := N[(N[(2.0 / N[(1.0 + N[Exp[N[(-2.0 * x), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - 1.0), $MachinePrecision]
\begin{array}{l}
\\
\frac{2}{1 + e^{-2 \cdot x}} - 1
\end{array}
Herbie found 6 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x) :precision binary64 (- (/ 2.0 (+ 1.0 (exp (* -2.0 x)))) 1.0))
double code(double x) {
return (2.0 / (1.0 + exp((-2.0 * x)))) - 1.0;
}
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(x)
use fmin_fmax_functions
real(8), intent (in) :: x
code = (2.0d0 / (1.0d0 + exp(((-2.0d0) * x)))) - 1.0d0
end function
public static double code(double x) {
return (2.0 / (1.0 + Math.exp((-2.0 * x)))) - 1.0;
}
def code(x): return (2.0 / (1.0 + math.exp((-2.0 * x)))) - 1.0
function code(x) return Float64(Float64(2.0 / Float64(1.0 + exp(Float64(-2.0 * x)))) - 1.0) end
function tmp = code(x) tmp = (2.0 / (1.0 + exp((-2.0 * x)))) - 1.0; end
code[x_] := N[(N[(2.0 / N[(1.0 + N[Exp[N[(-2.0 * x), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - 1.0), $MachinePrecision]
\begin{array}{l}
\\
\frac{2}{1 + e^{-2 \cdot x}} - 1
\end{array}
(FPCore (x)
:precision binary64
(let* ((t_0 (exp (* x -2.0))))
(if (<= x -1.55)
(- (/ 2.0 (* x (+ x x))) 1.0)
(if (<= x 0.0062)
(fma
(fma (* x x) 0.13333333333333333 -0.3333333333333333)
(* (* x x) x)
x)
(/
(/ (- 16.0 (pow (fma t_0 2.0 2.0) 2.0)) (+ 6.0 (* t_0 2.0)))
(* (- t_0 -1.0) 2.0))))))
double code(double x) {
double t_0 = exp((x * -2.0));
double tmp;
if (x <= -1.55) {
tmp = (2.0 / (x * (x + x))) - 1.0;
} else if (x <= 0.0062) {
tmp = fma(fma((x * x), 0.13333333333333333, -0.3333333333333333), ((x * x) * x), x);
} else {
tmp = ((16.0 - pow(fma(t_0, 2.0, 2.0), 2.0)) / (6.0 + (t_0 * 2.0))) / ((t_0 - -1.0) * 2.0);
}
return tmp;
}
function code(x) t_0 = exp(Float64(x * -2.0)) tmp = 0.0 if (x <= -1.55) tmp = Float64(Float64(2.0 / Float64(x * Float64(x + x))) - 1.0); elseif (x <= 0.0062) tmp = fma(fma(Float64(x * x), 0.13333333333333333, -0.3333333333333333), Float64(Float64(x * x) * x), x); else tmp = Float64(Float64(Float64(16.0 - (fma(t_0, 2.0, 2.0) ^ 2.0)) / Float64(6.0 + Float64(t_0 * 2.0))) / Float64(Float64(t_0 - -1.0) * 2.0)); end return tmp end
code[x_] := Block[{t$95$0 = N[Exp[N[(x * -2.0), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[x, -1.55], N[(N[(2.0 / N[(x * N[(x + x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - 1.0), $MachinePrecision], If[LessEqual[x, 0.0062], N[(N[(N[(x * x), $MachinePrecision] * 0.13333333333333333 + -0.3333333333333333), $MachinePrecision] * N[(N[(x * x), $MachinePrecision] * x), $MachinePrecision] + x), $MachinePrecision], N[(N[(N[(16.0 - N[Power[N[(t$95$0 * 2.0 + 2.0), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision] / N[(6.0 + N[(t$95$0 * 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(N[(t$95$0 - -1.0), $MachinePrecision] * 2.0), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := e^{x \cdot -2}\\
\mathbf{if}\;x \leq -1.55:\\
\;\;\;\;\frac{2}{x \cdot \left(x + x\right)} - 1\\
\mathbf{elif}\;x \leq 0.0062:\\
\;\;\;\;\mathsf{fma}\left(\mathsf{fma}\left(x \cdot x, 0.13333333333333333, -0.3333333333333333\right), \left(x \cdot x\right) \cdot x, x\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{\frac{16 - {\left(\mathsf{fma}\left(t\_0, 2, 2\right)\right)}^{2}}{6 + t\_0 \cdot 2}}{\left(t\_0 - -1\right) \cdot 2}\\
\end{array}
\end{array}
if x < -1.55000000000000004Initial program 100.0%
lift-+.f64N/A
lift-*.f64N/A
lift-exp.f64N/A
+-commutativeN/A
metadata-evalN/A
fp-cancel-sign-sub-invN/A
metadata-evalN/A
metadata-evalN/A
lower--.f64N/A
lift-exp.f64N/A
*-commutativeN/A
lower-*.f64100.0
Applied rewrites100.0%
Taylor expanded in x around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
metadata-evalN/A
fp-cancel-sub-sign-invN/A
*-commutativeN/A
metadata-evalN/A
metadata-evalN/A
lower-fma.f6499.0
Applied rewrites99.0%
Taylor expanded in x around inf
count-2-revN/A
pow2N/A
pow2N/A
distribute-lft-outN/A
count-2-revN/A
lower-*.f64N/A
count-2-revN/A
lower-+.f6499.0
Applied rewrites99.0%
if -1.55000000000000004 < x < 0.00619999999999999978Initial program 7.9%
Taylor expanded in x around 0
*-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
lower--.f64N/A
lower-*.f64N/A
unpow2N/A
lower-*.f64N/A
unpow2N/A
lower-*.f6499.8
Applied rewrites99.8%
lift-*.f64N/A
lift-fma.f64N/A
lift--.f64N/A
lift-*.f64N/A
lift-*.f64N/A
lift-*.f64N/A
*-commutativeN/A
+-commutativeN/A
pow2N/A
pow2N/A
*-commutativeN/A
+-commutativeN/A
distribute-rgt-inN/A
Applied rewrites99.8%
if 0.00619999999999999978 < x Initial program 100.0%
lift--.f64N/A
lift-/.f64N/A
lift-+.f64N/A
lift-*.f64N/A
lift-exp.f64N/A
metadata-evalN/A
frac-subN/A
lower-/.f64N/A
Applied rewrites100.0%
Applied rewrites100.0%
(FPCore (x)
:precision binary64
(if (<= x -1.55)
(- (/ 2.0 (* x (+ x x))) 1.0)
(if (<= x 0.0065)
(fma
(fma (* x x) 0.13333333333333333 -0.3333333333333333)
(* (* x x) x)
x)
(/ (- 2.0 (* (exp (* -2.0 x)) 2.0)) (fma (exp (* x -2.0)) 2.0 2.0)))))
double code(double x) {
double tmp;
if (x <= -1.55) {
tmp = (2.0 / (x * (x + x))) - 1.0;
} else if (x <= 0.0065) {
tmp = fma(fma((x * x), 0.13333333333333333, -0.3333333333333333), ((x * x) * x), x);
} else {
tmp = (2.0 - (exp((-2.0 * x)) * 2.0)) / fma(exp((x * -2.0)), 2.0, 2.0);
}
return tmp;
}
function code(x) tmp = 0.0 if (x <= -1.55) tmp = Float64(Float64(2.0 / Float64(x * Float64(x + x))) - 1.0); elseif (x <= 0.0065) tmp = fma(fma(Float64(x * x), 0.13333333333333333, -0.3333333333333333), Float64(Float64(x * x) * x), x); else tmp = Float64(Float64(2.0 - Float64(exp(Float64(-2.0 * x)) * 2.0)) / fma(exp(Float64(x * -2.0)), 2.0, 2.0)); end return tmp end
code[x_] := If[LessEqual[x, -1.55], N[(N[(2.0 / N[(x * N[(x + x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - 1.0), $MachinePrecision], If[LessEqual[x, 0.0065], N[(N[(N[(x * x), $MachinePrecision] * 0.13333333333333333 + -0.3333333333333333), $MachinePrecision] * N[(N[(x * x), $MachinePrecision] * x), $MachinePrecision] + x), $MachinePrecision], N[(N[(2.0 - N[(N[Exp[N[(-2.0 * x), $MachinePrecision]], $MachinePrecision] * 2.0), $MachinePrecision]), $MachinePrecision] / N[(N[Exp[N[(x * -2.0), $MachinePrecision]], $MachinePrecision] * 2.0 + 2.0), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.55:\\
\;\;\;\;\frac{2}{x \cdot \left(x + x\right)} - 1\\
\mathbf{elif}\;x \leq 0.0065:\\
\;\;\;\;\mathsf{fma}\left(\mathsf{fma}\left(x \cdot x, 0.13333333333333333, -0.3333333333333333\right), \left(x \cdot x\right) \cdot x, x\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{2 - e^{-2 \cdot x} \cdot 2}{\mathsf{fma}\left(e^{x \cdot -2}, 2, 2\right)}\\
\end{array}
\end{array}
if x < -1.55000000000000004Initial program 100.0%
lift-+.f64N/A
lift-*.f64N/A
lift-exp.f64N/A
+-commutativeN/A
metadata-evalN/A
fp-cancel-sign-sub-invN/A
metadata-evalN/A
metadata-evalN/A
lower--.f64N/A
lift-exp.f64N/A
*-commutativeN/A
lower-*.f64100.0
Applied rewrites100.0%
Taylor expanded in x around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
metadata-evalN/A
fp-cancel-sub-sign-invN/A
*-commutativeN/A
metadata-evalN/A
metadata-evalN/A
lower-fma.f6499.0
Applied rewrites99.0%
Taylor expanded in x around inf
count-2-revN/A
pow2N/A
pow2N/A
distribute-lft-outN/A
count-2-revN/A
lower-*.f64N/A
count-2-revN/A
lower-+.f6499.0
Applied rewrites99.0%
if -1.55000000000000004 < x < 0.0064999999999999997Initial program 7.9%
Taylor expanded in x around 0
*-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
lower--.f64N/A
lower-*.f64N/A
unpow2N/A
lower-*.f64N/A
unpow2N/A
lower-*.f6499.8
Applied rewrites99.8%
lift-*.f64N/A
lift-fma.f64N/A
lift--.f64N/A
lift-*.f64N/A
lift-*.f64N/A
lift-*.f64N/A
*-commutativeN/A
+-commutativeN/A
pow2N/A
pow2N/A
*-commutativeN/A
+-commutativeN/A
distribute-rgt-inN/A
Applied rewrites99.8%
if 0.0064999999999999997 < x Initial program 100.0%
lift--.f64N/A
lift-/.f64N/A
lift-+.f64N/A
lift-*.f64N/A
lift-exp.f64N/A
metadata-evalN/A
frac-subN/A
lower-/.f64N/A
Applied rewrites100.0%
lift-*.f64N/A
lift--.f64N/A
lift-*.f64N/A
lift-exp.f64N/A
metadata-evalN/A
fp-cancel-sub-signN/A
metadata-evalN/A
*-commutativeN/A
metadata-evalN/A
+-commutativeN/A
*-commutativeN/A
+-commutativeN/A
*-commutativeN/A
distribute-rgt-inN/A
metadata-evalN/A
lower-fma.f64N/A
lift-exp.f64N/A
lift-*.f64100.0
Applied rewrites100.0%
lift-*.f64N/A
lift--.f64N/A
lift-*.f64N/A
lift-exp.f64N/A
metadata-evalN/A
fp-cancel-sub-signN/A
metadata-evalN/A
*-commutativeN/A
metadata-evalN/A
+-commutativeN/A
*-commutativeN/A
+-commutativeN/A
*-commutativeN/A
distribute-rgt-inN/A
metadata-evalN/A
lower-fma.f64N/A
lift-exp.f64N/A
lift-*.f64100.0
Applied rewrites100.0%
Taylor expanded in x around inf
*-commutativeN/A
*-commutativeN/A
lower--.f64N/A
lower-*.f64N/A
*-commutativeN/A
lower-exp.f64N/A
lower-*.f64100.0
Applied rewrites100.0%
(FPCore (x)
:precision binary64
(if (<= x -1.55)
(- (/ 2.0 (* x (+ x x))) 1.0)
(if (<= x 0.008)
(fma
(fma (* x x) 0.13333333333333333 -0.3333333333333333)
(* (* x x) x)
x)
(- (/ 2.0 (- (exp (* x -2.0)) -1.0)) 1.0))))
double code(double x) {
double tmp;
if (x <= -1.55) {
tmp = (2.0 / (x * (x + x))) - 1.0;
} else if (x <= 0.008) {
tmp = fma(fma((x * x), 0.13333333333333333, -0.3333333333333333), ((x * x) * x), x);
} else {
tmp = (2.0 / (exp((x * -2.0)) - -1.0)) - 1.0;
}
return tmp;
}
function code(x) tmp = 0.0 if (x <= -1.55) tmp = Float64(Float64(2.0 / Float64(x * Float64(x + x))) - 1.0); elseif (x <= 0.008) tmp = fma(fma(Float64(x * x), 0.13333333333333333, -0.3333333333333333), Float64(Float64(x * x) * x), x); else tmp = Float64(Float64(2.0 / Float64(exp(Float64(x * -2.0)) - -1.0)) - 1.0); end return tmp end
code[x_] := If[LessEqual[x, -1.55], N[(N[(2.0 / N[(x * N[(x + x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - 1.0), $MachinePrecision], If[LessEqual[x, 0.008], N[(N[(N[(x * x), $MachinePrecision] * 0.13333333333333333 + -0.3333333333333333), $MachinePrecision] * N[(N[(x * x), $MachinePrecision] * x), $MachinePrecision] + x), $MachinePrecision], N[(N[(2.0 / N[(N[Exp[N[(x * -2.0), $MachinePrecision]], $MachinePrecision] - -1.0), $MachinePrecision]), $MachinePrecision] - 1.0), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.55:\\
\;\;\;\;\frac{2}{x \cdot \left(x + x\right)} - 1\\
\mathbf{elif}\;x \leq 0.008:\\
\;\;\;\;\mathsf{fma}\left(\mathsf{fma}\left(x \cdot x, 0.13333333333333333, -0.3333333333333333\right), \left(x \cdot x\right) \cdot x, x\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{2}{e^{x \cdot -2} - -1} - 1\\
\end{array}
\end{array}
if x < -1.55000000000000004Initial program 100.0%
lift-+.f64N/A
lift-*.f64N/A
lift-exp.f64N/A
+-commutativeN/A
metadata-evalN/A
fp-cancel-sign-sub-invN/A
metadata-evalN/A
metadata-evalN/A
lower--.f64N/A
lift-exp.f64N/A
*-commutativeN/A
lower-*.f64100.0
Applied rewrites100.0%
Taylor expanded in x around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
metadata-evalN/A
fp-cancel-sub-sign-invN/A
*-commutativeN/A
metadata-evalN/A
metadata-evalN/A
lower-fma.f6499.0
Applied rewrites99.0%
Taylor expanded in x around inf
count-2-revN/A
pow2N/A
pow2N/A
distribute-lft-outN/A
count-2-revN/A
lower-*.f64N/A
count-2-revN/A
lower-+.f6499.0
Applied rewrites99.0%
if -1.55000000000000004 < x < 0.0080000000000000002Initial program 7.9%
Taylor expanded in x around 0
*-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
lower--.f64N/A
lower-*.f64N/A
unpow2N/A
lower-*.f64N/A
unpow2N/A
lower-*.f6499.8
Applied rewrites99.8%
lift-*.f64N/A
lift-fma.f64N/A
lift--.f64N/A
lift-*.f64N/A
lift-*.f64N/A
lift-*.f64N/A
*-commutativeN/A
+-commutativeN/A
pow2N/A
pow2N/A
*-commutativeN/A
+-commutativeN/A
distribute-rgt-inN/A
Applied rewrites99.8%
if 0.0080000000000000002 < x Initial program 100.0%
lift-+.f64N/A
lift-*.f64N/A
lift-exp.f64N/A
+-commutativeN/A
metadata-evalN/A
fp-cancel-sign-sub-invN/A
metadata-evalN/A
metadata-evalN/A
lower--.f64N/A
lift-exp.f64N/A
*-commutativeN/A
lower-*.f64100.0
Applied rewrites100.0%
(FPCore (x) :precision binary64 (if (<= (- (/ 2.0 (+ 1.0 (exp (* -2.0 x)))) 1.0) -1.0) (- (/ 2.0 (* x (+ x x))) 1.0) x))
double code(double x) {
double tmp;
if (((2.0 / (1.0 + exp((-2.0 * x)))) - 1.0) <= -1.0) {
tmp = (2.0 / (x * (x + x))) - 1.0;
} else {
tmp = 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(x)
use fmin_fmax_functions
real(8), intent (in) :: x
real(8) :: tmp
if (((2.0d0 / (1.0d0 + exp(((-2.0d0) * x)))) - 1.0d0) <= (-1.0d0)) then
tmp = (2.0d0 / (x * (x + x))) - 1.0d0
else
tmp = x
end if
code = tmp
end function
public static double code(double x) {
double tmp;
if (((2.0 / (1.0 + Math.exp((-2.0 * x)))) - 1.0) <= -1.0) {
tmp = (2.0 / (x * (x + x))) - 1.0;
} else {
tmp = x;
}
return tmp;
}
def code(x): tmp = 0 if ((2.0 / (1.0 + math.exp((-2.0 * x)))) - 1.0) <= -1.0: tmp = (2.0 / (x * (x + x))) - 1.0 else: tmp = x return tmp
function code(x) tmp = 0.0 if (Float64(Float64(2.0 / Float64(1.0 + exp(Float64(-2.0 * x)))) - 1.0) <= -1.0) tmp = Float64(Float64(2.0 / Float64(x * Float64(x + x))) - 1.0); else tmp = x; end return tmp end
function tmp_2 = code(x) tmp = 0.0; if (((2.0 / (1.0 + exp((-2.0 * x)))) - 1.0) <= -1.0) tmp = (2.0 / (x * (x + x))) - 1.0; else tmp = x; end tmp_2 = tmp; end
code[x_] := If[LessEqual[N[(N[(2.0 / N[(1.0 + N[Exp[N[(-2.0 * x), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - 1.0), $MachinePrecision], -1.0], N[(N[(2.0 / N[(x * N[(x + x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - 1.0), $MachinePrecision], x]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\frac{2}{1 + e^{-2 \cdot x}} - 1 \leq -1:\\
\;\;\;\;\frac{2}{x \cdot \left(x + x\right)} - 1\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if (-.f64 (/.f64 #s(literal 2 binary64) (+.f64 #s(literal 1 binary64) (exp.f64 (*.f64 #s(literal -2 binary64) x)))) #s(literal 1 binary64)) < -1Initial program 100.0%
lift-+.f64N/A
lift-*.f64N/A
lift-exp.f64N/A
+-commutativeN/A
metadata-evalN/A
fp-cancel-sign-sub-invN/A
metadata-evalN/A
metadata-evalN/A
lower--.f64N/A
lift-exp.f64N/A
*-commutativeN/A
lower-*.f64100.0
Applied rewrites100.0%
Taylor expanded in x around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
metadata-evalN/A
fp-cancel-sub-sign-invN/A
*-commutativeN/A
metadata-evalN/A
metadata-evalN/A
lower-fma.f6499.2
Applied rewrites99.2%
Taylor expanded in x around inf
count-2-revN/A
pow2N/A
pow2N/A
distribute-lft-outN/A
count-2-revN/A
lower-*.f64N/A
count-2-revN/A
lower-+.f6499.2
Applied rewrites99.2%
if -1 < (-.f64 (/.f64 #s(literal 2 binary64) (+.f64 #s(literal 1 binary64) (exp.f64 (*.f64 #s(literal -2 binary64) x)))) #s(literal 1 binary64)) Initial program 39.1%
Taylor expanded in x around 0
Applied rewrites67.4%
(FPCore (x) :precision binary64 (if (<= (- (/ 2.0 (+ 1.0 (exp (* -2.0 x)))) 1.0) -1.0) (- (/ -1.0 (- x 1.0)) 1.0) x))
double code(double x) {
double tmp;
if (((2.0 / (1.0 + exp((-2.0 * x)))) - 1.0) <= -1.0) {
tmp = (-1.0 / (x - 1.0)) - 1.0;
} else {
tmp = 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(x)
use fmin_fmax_functions
real(8), intent (in) :: x
real(8) :: tmp
if (((2.0d0 / (1.0d0 + exp(((-2.0d0) * x)))) - 1.0d0) <= (-1.0d0)) then
tmp = ((-1.0d0) / (x - 1.0d0)) - 1.0d0
else
tmp = x
end if
code = tmp
end function
public static double code(double x) {
double tmp;
if (((2.0 / (1.0 + Math.exp((-2.0 * x)))) - 1.0) <= -1.0) {
tmp = (-1.0 / (x - 1.0)) - 1.0;
} else {
tmp = x;
}
return tmp;
}
def code(x): tmp = 0 if ((2.0 / (1.0 + math.exp((-2.0 * x)))) - 1.0) <= -1.0: tmp = (-1.0 / (x - 1.0)) - 1.0 else: tmp = x return tmp
function code(x) tmp = 0.0 if (Float64(Float64(2.0 / Float64(1.0 + exp(Float64(-2.0 * x)))) - 1.0) <= -1.0) tmp = Float64(Float64(-1.0 / Float64(x - 1.0)) - 1.0); else tmp = x; end return tmp end
function tmp_2 = code(x) tmp = 0.0; if (((2.0 / (1.0 + exp((-2.0 * x)))) - 1.0) <= -1.0) tmp = (-1.0 / (x - 1.0)) - 1.0; else tmp = x; end tmp_2 = tmp; end
code[x_] := If[LessEqual[N[(N[(2.0 / N[(1.0 + N[Exp[N[(-2.0 * x), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - 1.0), $MachinePrecision], -1.0], N[(N[(-1.0 / N[(x - 1.0), $MachinePrecision]), $MachinePrecision] - 1.0), $MachinePrecision], x]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\frac{2}{1 + e^{-2 \cdot x}} - 1 \leq -1:\\
\;\;\;\;\frac{-1}{x - 1} - 1\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if (-.f64 (/.f64 #s(literal 2 binary64) (+.f64 #s(literal 1 binary64) (exp.f64 (*.f64 #s(literal -2 binary64) x)))) #s(literal 1 binary64)) < -1Initial program 100.0%
Taylor expanded in x around 0
+-commutativeN/A
metadata-evalN/A
fp-cancel-sign-sub-invN/A
metadata-evalN/A
metadata-evalN/A
lower--.f645.3
Applied rewrites5.3%
lift--.f64N/A
metadata-evalN/A
fp-cancel-sub-signN/A
metadata-evalN/A
metadata-evalN/A
flip-+N/A
metadata-evalN/A
metadata-evalN/A
lower-/.f64N/A
pow2N/A
metadata-evalN/A
fp-cancel-sign-subN/A
metadata-evalN/A
pow2N/A
lower-fma.f64N/A
lower--.f644.9
Applied rewrites4.9%
Taylor expanded in x around 0
Applied rewrites98.1%
if -1 < (-.f64 (/.f64 #s(literal 2 binary64) (+.f64 #s(literal 1 binary64) (exp.f64 (*.f64 #s(literal -2 binary64) x)))) #s(literal 1 binary64)) Initial program 39.1%
Taylor expanded in x around 0
Applied rewrites67.4%
(FPCore (x) :precision binary64 x)
double code(double x) {
return 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(x)
use fmin_fmax_functions
real(8), intent (in) :: x
code = x
end function
public static double code(double x) {
return x;
}
def code(x): return x
function code(x) return x end
function tmp = code(x) tmp = x; end
code[x_] := x
\begin{array}{l}
\\
x
\end{array}
Initial program 54.6%
Taylor expanded in x around 0
Applied rewrites51.7%
herbie shell --seed 2025116
(FPCore (x)
:name "Logistic function from Lakshay Garg"
:precision binary64
(- (/ 2.0 (+ 1.0 (exp (* -2.0 x)))) 1.0))