
(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 9 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 (* -2.0 x)) 1.0)))
(if (<= x -1.45)
(- (/ 2.0 (* (* x x) 2.0)) 1.0)
(if (<= x 0.025)
(*
(fma
(*
(fma
(fma -0.05396825396825397 (* x x) 0.13333333333333333)
(* x x)
-0.3333333333333333)
x)
x
1.0)
x)
(*
(/
(- 64.0 (* (pow t_0 3.0) 8.0))
(* (+ (fma (pow t_0 2.0) 4.0 (* t_0 8.0)) 16.0) t_0))
0.5)))))
double code(double x) {
double t_0 = exp((-2.0 * x)) + 1.0;
double tmp;
if (x <= -1.45) {
tmp = (2.0 / ((x * x) * 2.0)) - 1.0;
} else if (x <= 0.025) {
tmp = fma((fma(fma(-0.05396825396825397, (x * x), 0.13333333333333333), (x * x), -0.3333333333333333) * x), x, 1.0) * x;
} else {
tmp = ((64.0 - (pow(t_0, 3.0) * 8.0)) / ((fma(pow(t_0, 2.0), 4.0, (t_0 * 8.0)) + 16.0) * t_0)) * 0.5;
}
return tmp;
}
function code(x) t_0 = Float64(exp(Float64(-2.0 * x)) + 1.0) tmp = 0.0 if (x <= -1.45) tmp = Float64(Float64(2.0 / Float64(Float64(x * x) * 2.0)) - 1.0); elseif (x <= 0.025) tmp = Float64(fma(Float64(fma(fma(-0.05396825396825397, Float64(x * x), 0.13333333333333333), Float64(x * x), -0.3333333333333333) * x), x, 1.0) * x); else tmp = Float64(Float64(Float64(64.0 - Float64((t_0 ^ 3.0) * 8.0)) / Float64(Float64(fma((t_0 ^ 2.0), 4.0, Float64(t_0 * 8.0)) + 16.0) * t_0)) * 0.5); end return tmp end
code[x_] := Block[{t$95$0 = N[(N[Exp[N[(-2.0 * x), $MachinePrecision]], $MachinePrecision] + 1.0), $MachinePrecision]}, If[LessEqual[x, -1.45], N[(N[(2.0 / N[(N[(x * x), $MachinePrecision] * 2.0), $MachinePrecision]), $MachinePrecision] - 1.0), $MachinePrecision], If[LessEqual[x, 0.025], N[(N[(N[(N[(N[(-0.05396825396825397 * N[(x * x), $MachinePrecision] + 0.13333333333333333), $MachinePrecision] * N[(x * x), $MachinePrecision] + -0.3333333333333333), $MachinePrecision] * x), $MachinePrecision] * x + 1.0), $MachinePrecision] * x), $MachinePrecision], N[(N[(N[(64.0 - N[(N[Power[t$95$0, 3.0], $MachinePrecision] * 8.0), $MachinePrecision]), $MachinePrecision] / N[(N[(N[(N[Power[t$95$0, 2.0], $MachinePrecision] * 4.0 + N[(t$95$0 * 8.0), $MachinePrecision]), $MachinePrecision] + 16.0), $MachinePrecision] * t$95$0), $MachinePrecision]), $MachinePrecision] * 0.5), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := e^{-2 \cdot x} + 1\\
\mathbf{if}\;x \leq -1.45:\\
\;\;\;\;\frac{2}{\left(x \cdot x\right) \cdot 2} - 1\\
\mathbf{elif}\;x \leq 0.025:\\
\;\;\;\;\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(-0.05396825396825397, x \cdot x, 0.13333333333333333\right), x \cdot x, -0.3333333333333333\right) \cdot x, x, 1\right) \cdot x\\
\mathbf{else}:\\
\;\;\;\;\frac{64 - {t\_0}^{3} \cdot 8}{\left(\mathsf{fma}\left({t\_0}^{2}, 4, t\_0 \cdot 8\right) + 16\right) \cdot t\_0} \cdot 0.5\\
\end{array}
\end{array}
if x < -1.44999999999999996Initial 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.1
Applied rewrites99.1%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f64N/A
pow2N/A
lift-*.f6499.1
Applied rewrites99.1%
if -1.44999999999999996 < x < 0.025000000000000001Initial program 8.2%
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-*.f648.2
Applied rewrites8.2%
Taylor expanded in x around 0
Applied rewrites99.9%
if 0.025000000000000001 < 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-*.f64N/A
lift-exp.f64N/A
flip3--N/A
lower-/.f64N/A
Applied rewrites100.0%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f64N/A
Applied rewrites100.0%
(FPCore (x)
:precision binary64
(let* ((t_0 (* (- (exp (* x -2.0)) -1.0) 2.0)))
(if (<= x -1.45)
(- (/ 2.0 (* (* x x) 2.0)) 1.0)
(if (<= x 0.021)
(*
(fma
(*
(fma
(fma -0.05396825396825397 (* x x) 0.13333333333333333)
(* x x)
-0.3333333333333333)
x)
x
1.0)
x)
(/ (/ (- 16.0 (pow t_0 2.0)) (+ 4.0 t_0)) t_0)))))
double code(double x) {
double t_0 = (exp((x * -2.0)) - -1.0) * 2.0;
double tmp;
if (x <= -1.45) {
tmp = (2.0 / ((x * x) * 2.0)) - 1.0;
} else if (x <= 0.021) {
tmp = fma((fma(fma(-0.05396825396825397, (x * x), 0.13333333333333333), (x * x), -0.3333333333333333) * x), x, 1.0) * x;
} else {
tmp = ((16.0 - pow(t_0, 2.0)) / (4.0 + t_0)) / t_0;
}
return tmp;
}
function code(x) t_0 = Float64(Float64(exp(Float64(x * -2.0)) - -1.0) * 2.0) tmp = 0.0 if (x <= -1.45) tmp = Float64(Float64(2.0 / Float64(Float64(x * x) * 2.0)) - 1.0); elseif (x <= 0.021) tmp = Float64(fma(Float64(fma(fma(-0.05396825396825397, Float64(x * x), 0.13333333333333333), Float64(x * x), -0.3333333333333333) * x), x, 1.0) * x); else tmp = Float64(Float64(Float64(16.0 - (t_0 ^ 2.0)) / Float64(4.0 + t_0)) / t_0); end return tmp end
code[x_] := Block[{t$95$0 = N[(N[(N[Exp[N[(x * -2.0), $MachinePrecision]], $MachinePrecision] - -1.0), $MachinePrecision] * 2.0), $MachinePrecision]}, If[LessEqual[x, -1.45], N[(N[(2.0 / N[(N[(x * x), $MachinePrecision] * 2.0), $MachinePrecision]), $MachinePrecision] - 1.0), $MachinePrecision], If[LessEqual[x, 0.021], N[(N[(N[(N[(N[(-0.05396825396825397 * N[(x * x), $MachinePrecision] + 0.13333333333333333), $MachinePrecision] * N[(x * x), $MachinePrecision] + -0.3333333333333333), $MachinePrecision] * x), $MachinePrecision] * x + 1.0), $MachinePrecision] * x), $MachinePrecision], N[(N[(N[(16.0 - N[Power[t$95$0, 2.0], $MachinePrecision]), $MachinePrecision] / N[(4.0 + t$95$0), $MachinePrecision]), $MachinePrecision] / t$95$0), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left(e^{x \cdot -2} - -1\right) \cdot 2\\
\mathbf{if}\;x \leq -1.45:\\
\;\;\;\;\frac{2}{\left(x \cdot x\right) \cdot 2} - 1\\
\mathbf{elif}\;x \leq 0.021:\\
\;\;\;\;\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(-0.05396825396825397, x \cdot x, 0.13333333333333333\right), x \cdot x, -0.3333333333333333\right) \cdot x, x, 1\right) \cdot x\\
\mathbf{else}:\\
\;\;\;\;\frac{\frac{16 - {t\_0}^{2}}{4 + t\_0}}{t\_0}\\
\end{array}
\end{array}
if x < -1.44999999999999996Initial 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.1
Applied rewrites99.1%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f64N/A
pow2N/A
lift-*.f6499.1
Applied rewrites99.1%
if -1.44999999999999996 < x < 0.0210000000000000013Initial program 8.2%
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-*.f648.2
Applied rewrites8.2%
Taylor expanded in x around 0
Applied rewrites99.9%
if 0.0210000000000000013 < 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-*.f64N/A
lift-exp.f64N/A
flip--N/A
lower-/.f64N/A
Applied rewrites100.0%
(FPCore (x)
:precision binary64
(let* ((t_0 (* (- (exp (* x -2.0)) -1.0) 2.0)))
(if (<= x -1.45)
(- (/ 2.0 (* (* x x) 2.0)) 1.0)
(if (<= x 0.021)
(*
(fma
(*
(fma
(fma -0.05396825396825397 (* x x) 0.13333333333333333)
(* x x)
-0.3333333333333333)
x)
x
1.0)
x)
(/ (- 4.0 t_0) t_0)))))
double code(double x) {
double t_0 = (exp((x * -2.0)) - -1.0) * 2.0;
double tmp;
if (x <= -1.45) {
tmp = (2.0 / ((x * x) * 2.0)) - 1.0;
} else if (x <= 0.021) {
tmp = fma((fma(fma(-0.05396825396825397, (x * x), 0.13333333333333333), (x * x), -0.3333333333333333) * x), x, 1.0) * x;
} else {
tmp = (4.0 - t_0) / t_0;
}
return tmp;
}
function code(x) t_0 = Float64(Float64(exp(Float64(x * -2.0)) - -1.0) * 2.0) tmp = 0.0 if (x <= -1.45) tmp = Float64(Float64(2.0 / Float64(Float64(x * x) * 2.0)) - 1.0); elseif (x <= 0.021) tmp = Float64(fma(Float64(fma(fma(-0.05396825396825397, Float64(x * x), 0.13333333333333333), Float64(x * x), -0.3333333333333333) * x), x, 1.0) * x); else tmp = Float64(Float64(4.0 - t_0) / t_0); end return tmp end
code[x_] := Block[{t$95$0 = N[(N[(N[Exp[N[(x * -2.0), $MachinePrecision]], $MachinePrecision] - -1.0), $MachinePrecision] * 2.0), $MachinePrecision]}, If[LessEqual[x, -1.45], N[(N[(2.0 / N[(N[(x * x), $MachinePrecision] * 2.0), $MachinePrecision]), $MachinePrecision] - 1.0), $MachinePrecision], If[LessEqual[x, 0.021], N[(N[(N[(N[(N[(-0.05396825396825397 * N[(x * x), $MachinePrecision] + 0.13333333333333333), $MachinePrecision] * N[(x * x), $MachinePrecision] + -0.3333333333333333), $MachinePrecision] * x), $MachinePrecision] * x + 1.0), $MachinePrecision] * x), $MachinePrecision], N[(N[(4.0 - t$95$0), $MachinePrecision] / t$95$0), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left(e^{x \cdot -2} - -1\right) \cdot 2\\
\mathbf{if}\;x \leq -1.45:\\
\;\;\;\;\frac{2}{\left(x \cdot x\right) \cdot 2} - 1\\
\mathbf{elif}\;x \leq 0.021:\\
\;\;\;\;\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(-0.05396825396825397, x \cdot x, 0.13333333333333333\right), x \cdot x, -0.3333333333333333\right) \cdot x, x, 1\right) \cdot x\\
\mathbf{else}:\\
\;\;\;\;\frac{4 - t\_0}{t\_0}\\
\end{array}
\end{array}
if x < -1.44999999999999996Initial 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.1
Applied rewrites99.1%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f64N/A
pow2N/A
lift-*.f6499.1
Applied rewrites99.1%
if -1.44999999999999996 < x < 0.0210000000000000013Initial program 8.2%
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-*.f648.2
Applied rewrites8.2%
Taylor expanded in x around 0
Applied rewrites99.9%
if 0.0210000000000000013 < 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%
(FPCore (x)
:precision binary64
(if (<= x -1.45)
(- (/ 2.0 (* (* x x) 2.0)) 1.0)
(if (<= x 0.022)
(*
(fma
(*
(fma
(fma -0.05396825396825397 (* x x) 0.13333333333333333)
(* x x)
-0.3333333333333333)
x)
x
1.0)
x)
(- (/ 2.0 (- (exp (* x -2.0)) -1.0)) 1.0))))
double code(double x) {
double tmp;
if (x <= -1.45) {
tmp = (2.0 / ((x * x) * 2.0)) - 1.0;
} else if (x <= 0.022) {
tmp = fma((fma(fma(-0.05396825396825397, (x * x), 0.13333333333333333), (x * x), -0.3333333333333333) * x), x, 1.0) * x;
} else {
tmp = (2.0 / (exp((x * -2.0)) - -1.0)) - 1.0;
}
return tmp;
}
function code(x) tmp = 0.0 if (x <= -1.45) tmp = Float64(Float64(2.0 / Float64(Float64(x * x) * 2.0)) - 1.0); elseif (x <= 0.022) tmp = Float64(fma(Float64(fma(fma(-0.05396825396825397, Float64(x * x), 0.13333333333333333), Float64(x * x), -0.3333333333333333) * x), x, 1.0) * 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.45], N[(N[(2.0 / N[(N[(x * x), $MachinePrecision] * 2.0), $MachinePrecision]), $MachinePrecision] - 1.0), $MachinePrecision], If[LessEqual[x, 0.022], N[(N[(N[(N[(N[(-0.05396825396825397 * N[(x * x), $MachinePrecision] + 0.13333333333333333), $MachinePrecision] * N[(x * x), $MachinePrecision] + -0.3333333333333333), $MachinePrecision] * x), $MachinePrecision] * x + 1.0), $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.45:\\
\;\;\;\;\frac{2}{\left(x \cdot x\right) \cdot 2} - 1\\
\mathbf{elif}\;x \leq 0.022:\\
\;\;\;\;\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(-0.05396825396825397, x \cdot x, 0.13333333333333333\right), x \cdot x, -0.3333333333333333\right) \cdot x, x, 1\right) \cdot x\\
\mathbf{else}:\\
\;\;\;\;\frac{2}{e^{x \cdot -2} - -1} - 1\\
\end{array}
\end{array}
if x < -1.44999999999999996Initial 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.1
Applied rewrites99.1%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f64N/A
pow2N/A
lift-*.f6499.1
Applied rewrites99.1%
if -1.44999999999999996 < x < 0.021999999999999999Initial program 8.2%
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-*.f648.2
Applied rewrites8.2%
Taylor expanded in x around 0
Applied rewrites99.9%
if 0.021999999999999999 < 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 (<= x -1.6)
(- (/ 2.0 (* (* x x) 2.0)) 1.0)
(if (<= x 0.007)
(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.6) {
tmp = (2.0 / ((x * x) * 2.0)) - 1.0;
} else if (x <= 0.007) {
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.6) tmp = Float64(Float64(2.0 / Float64(Float64(x * x) * 2.0)) - 1.0); elseif (x <= 0.007) 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.6], N[(N[(2.0 / N[(N[(x * x), $MachinePrecision] * 2.0), $MachinePrecision]), $MachinePrecision] - 1.0), $MachinePrecision], If[LessEqual[x, 0.007], 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.6:\\
\;\;\;\;\frac{2}{\left(x \cdot x\right) \cdot 2} - 1\\
\mathbf{elif}\;x \leq 0.007:\\
\;\;\;\;\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.6000000000000001Initial 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.1
Applied rewrites99.1%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f64N/A
pow2N/A
lift-*.f6499.1
Applied rewrites99.1%
if -1.6000000000000001 < x < 0.00700000000000000015Initial program 8.1%
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.9
Applied rewrites99.9%
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.9%
if 0.00700000000000000015 < 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 (<= (+ 1.0 (exp (* -2.0 x))) 4.0) (fma (fma (* x x) 0.13333333333333333 -0.3333333333333333) (* (* x x) x) x) (- (/ 2.0 (* (* x x) 2.0)) 1.0)))
double code(double x) {
double tmp;
if ((1.0 + exp((-2.0 * x))) <= 4.0) {
tmp = fma(fma((x * x), 0.13333333333333333, -0.3333333333333333), ((x * x) * x), x);
} else {
tmp = (2.0 / ((x * x) * 2.0)) - 1.0;
}
return tmp;
}
function code(x) tmp = 0.0 if (Float64(1.0 + exp(Float64(-2.0 * x))) <= 4.0) tmp = fma(fma(Float64(x * x), 0.13333333333333333, -0.3333333333333333), Float64(Float64(x * x) * x), x); else tmp = Float64(Float64(2.0 / Float64(Float64(x * x) * 2.0)) - 1.0); end return tmp end
code[x_] := If[LessEqual[N[(1.0 + N[Exp[N[(-2.0 * x), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], 4.0], 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[(x * x), $MachinePrecision] * 2.0), $MachinePrecision]), $MachinePrecision] - 1.0), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;1 + e^{-2 \cdot x} \leq 4:\\
\;\;\;\;\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}{\left(x \cdot x\right) \cdot 2} - 1\\
\end{array}
\end{array}
if (+.f64 #s(literal 1 binary64) (exp.f64 (*.f64 #s(literal -2 binary64) x))) < 4Initial program 38.8%
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-*.f6467.8
Applied rewrites67.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 rewrites67.9%
if 4 < (+.f64 #s(literal 1 binary64) (exp.f64 (*.f64 #s(literal -2 binary64) 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%
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
*-commutativeN/A
lower-*.f64N/A
pow2N/A
lift-*.f6499.0
Applied rewrites99.0%
(FPCore (x) :precision binary64 (if (<= (* -2.0 x) 2e-8) x (- (/ 2.0 (* (* x x) 2.0)) 1.0)))
double code(double x) {
double tmp;
if ((-2.0 * x) <= 2e-8) {
tmp = x;
} else {
tmp = (2.0 / ((x * x) * 2.0)) - 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(x)
use fmin_fmax_functions
real(8), intent (in) :: x
real(8) :: tmp
if (((-2.0d0) * x) <= 2d-8) then
tmp = x
else
tmp = (2.0d0 / ((x * x) * 2.0d0)) - 1.0d0
end if
code = tmp
end function
public static double code(double x) {
double tmp;
if ((-2.0 * x) <= 2e-8) {
tmp = x;
} else {
tmp = (2.0 / ((x * x) * 2.0)) - 1.0;
}
return tmp;
}
def code(x): tmp = 0 if (-2.0 * x) <= 2e-8: tmp = x else: tmp = (2.0 / ((x * x) * 2.0)) - 1.0 return tmp
function code(x) tmp = 0.0 if (Float64(-2.0 * x) <= 2e-8) tmp = x; else tmp = Float64(Float64(2.0 / Float64(Float64(x * x) * 2.0)) - 1.0); end return tmp end
function tmp_2 = code(x) tmp = 0.0; if ((-2.0 * x) <= 2e-8) tmp = x; else tmp = (2.0 / ((x * x) * 2.0)) - 1.0; end tmp_2 = tmp; end
code[x_] := If[LessEqual[N[(-2.0 * x), $MachinePrecision], 2e-8], x, N[(N[(2.0 / N[(N[(x * x), $MachinePrecision] * 2.0), $MachinePrecision]), $MachinePrecision] - 1.0), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;-2 \cdot x \leq 2 \cdot 10^{-8}:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;\frac{2}{\left(x \cdot x\right) \cdot 2} - 1\\
\end{array}
\end{array}
if (*.f64 #s(literal -2 binary64) x) < 2e-8Initial program 38.5%
Taylor expanded in x around 0
Applied rewrites68.0%
if 2e-8 < (*.f64 #s(literal -2 binary64) x) Initial program 99.6%
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-*.f6499.6
Applied rewrites99.6%
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.f6498.2
Applied rewrites98.2%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f64N/A
pow2N/A
lift-*.f6497.2
Applied rewrites97.2%
(FPCore (x) :precision binary64 (if (<= (* -2.0 x) 2e-8) x (- (/ -1.0 (+ x -1.0)) 1.0)))
double code(double x) {
double tmp;
if ((-2.0 * x) <= 2e-8) {
tmp = x;
} else {
tmp = (-1.0 / (x + -1.0)) - 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(x)
use fmin_fmax_functions
real(8), intent (in) :: x
real(8) :: tmp
if (((-2.0d0) * x) <= 2d-8) then
tmp = x
else
tmp = ((-1.0d0) / (x + (-1.0d0))) - 1.0d0
end if
code = tmp
end function
public static double code(double x) {
double tmp;
if ((-2.0 * x) <= 2e-8) {
tmp = x;
} else {
tmp = (-1.0 / (x + -1.0)) - 1.0;
}
return tmp;
}
def code(x): tmp = 0 if (-2.0 * x) <= 2e-8: tmp = x else: tmp = (-1.0 / (x + -1.0)) - 1.0 return tmp
function code(x) tmp = 0.0 if (Float64(-2.0 * x) <= 2e-8) tmp = x; else tmp = Float64(Float64(-1.0 / Float64(x + -1.0)) - 1.0); end return tmp end
function tmp_2 = code(x) tmp = 0.0; if ((-2.0 * x) <= 2e-8) tmp = x; else tmp = (-1.0 / (x + -1.0)) - 1.0; end tmp_2 = tmp; end
code[x_] := If[LessEqual[N[(-2.0 * x), $MachinePrecision], 2e-8], x, N[(N[(-1.0 / N[(x + -1.0), $MachinePrecision]), $MachinePrecision] - 1.0), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;-2 \cdot x \leq 2 \cdot 10^{-8}:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;\frac{-1}{x + -1} - 1\\
\end{array}
\end{array}
if (*.f64 #s(literal -2 binary64) x) < 2e-8Initial program 38.5%
Taylor expanded in x around 0
Applied rewrites68.0%
if 2e-8 < (*.f64 #s(literal -2 binary64) x) Initial program 99.6%
Taylor expanded in x around 0
+-commutativeN/A
metadata-evalN/A
fp-cancel-sign-sub-invN/A
metadata-evalN/A
metadata-evalN/A
lower--.f646.4
Applied rewrites6.4%
lift--.f64N/A
flip--N/A
lower-/.f64N/A
pow2N/A
metadata-evalN/A
lower--.f64N/A
pow2N/A
lift-*.f64N/A
lower-+.f646.0
Applied rewrites6.0%
Taylor expanded in x around 0
Applied rewrites96.8%
(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 53.9%
Taylor expanded in x around 0
Applied rewrites52.6%
herbie shell --seed 2025115
(FPCore (x)
:name "Logistic function from Lakshay Garg"
:precision binary64
(- (/ 2.0 (+ 1.0 (exp (* -2.0 x)))) 1.0))