
(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 13 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))) (t_1 (/ -2.0 (- -1.0 t_0))))
(if (<= x -0.0074)
(/ 1.0 (/ (- t_1 -1.0) (- (pow t_1 2.0) 1.0)))
(if (<= x 0.007)
(*
(fma (fma 0.13333333333333333 (* x x) -0.3333333333333333) (* x x) 1.0)
x)
(- (/ 2.0 (- t_0 -1.0)) 1.0)))))
double code(double x) {
double t_0 = exp((x * -2.0));
double t_1 = -2.0 / (-1.0 - t_0);
double tmp;
if (x <= -0.0074) {
tmp = 1.0 / ((t_1 - -1.0) / (pow(t_1, 2.0) - 1.0));
} else if (x <= 0.007) {
tmp = fma(fma(0.13333333333333333, (x * x), -0.3333333333333333), (x * x), 1.0) * x;
} else {
tmp = (2.0 / (t_0 - -1.0)) - 1.0;
}
return tmp;
}
function code(x) t_0 = exp(Float64(x * -2.0)) t_1 = Float64(-2.0 / Float64(-1.0 - t_0)) tmp = 0.0 if (x <= -0.0074) tmp = Float64(1.0 / Float64(Float64(t_1 - -1.0) / Float64((t_1 ^ 2.0) - 1.0))); elseif (x <= 0.007) tmp = Float64(fma(fma(0.13333333333333333, Float64(x * x), -0.3333333333333333), Float64(x * x), 1.0) * x); else tmp = Float64(Float64(2.0 / Float64(t_0 - -1.0)) - 1.0); end return tmp end
code[x_] := Block[{t$95$0 = N[Exp[N[(x * -2.0), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$1 = N[(-2.0 / N[(-1.0 - t$95$0), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[x, -0.0074], N[(1.0 / N[(N[(t$95$1 - -1.0), $MachinePrecision] / N[(N[Power[t$95$1, 2.0], $MachinePrecision] - 1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[x, 0.007], N[(N[(N[(0.13333333333333333 * N[(x * x), $MachinePrecision] + -0.3333333333333333), $MachinePrecision] * N[(x * x), $MachinePrecision] + 1.0), $MachinePrecision] * x), $MachinePrecision], N[(N[(2.0 / N[(t$95$0 - -1.0), $MachinePrecision]), $MachinePrecision] - 1.0), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := e^{x \cdot -2}\\
t_1 := \frac{-2}{-1 - t\_0}\\
\mathbf{if}\;x \leq -0.0074:\\
\;\;\;\;\frac{1}{\frac{t\_1 - -1}{{t\_1}^{2} - 1}}\\
\mathbf{elif}\;x \leq 0.007:\\
\;\;\;\;\mathsf{fma}\left(\mathsf{fma}\left(0.13333333333333333, x \cdot x, -0.3333333333333333\right), x \cdot x, 1\right) \cdot x\\
\mathbf{else}:\\
\;\;\;\;\frac{2}{t\_0 - -1} - 1\\
\end{array}
\end{array}
if x < -0.0074000000000000003Initial program 100.0%
lift--.f64N/A
lift-/.f64N/A
lift-+.f64N/A
lift-*.f64N/A
lift-exp.f64N/A
flip--N/A
division-flipN/A
lower-/.f64N/A
lower-/.f64N/A
Applied rewrites100.0%
if -0.0074000000000000003 < x < 0.00700000000000000015Initial program 7.8%
Taylor expanded in x around 0
*-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
sub-flipN/A
metadata-evalN/A
lower-fma.f64N/A
unpow2N/A
lower-*.f64N/A
unpow2N/A
lower-*.f64100.0
Applied rewrites100.0%
if 0.00700000000000000015 < x Initial program 100.0%
lift-+.f64N/A
lift-*.f64N/A
lift-exp.f64N/A
add-flipN/A
metadata-evalN/A
sub-negate-revN/A
lower--.f64N/A
lift-exp.f64N/A
*-commutativeN/A
lower-*.f64100.0
Applied rewrites100.0%
(FPCore (x)
:precision binary64
(let* ((t_0 (- (/ 2.0 (- (exp (* x -2.0)) -1.0)) 1.0)))
(if (<= x -0.0074)
(/ 1.0 (/ 1.0 t_0))
(if (<= x 0.007)
(*
(fma (fma 0.13333333333333333 (* x x) -0.3333333333333333) (* x x) 1.0)
x)
t_0))))
double code(double x) {
double t_0 = (2.0 / (exp((x * -2.0)) - -1.0)) - 1.0;
double tmp;
if (x <= -0.0074) {
tmp = 1.0 / (1.0 / t_0);
} else if (x <= 0.007) {
tmp = fma(fma(0.13333333333333333, (x * x), -0.3333333333333333), (x * x), 1.0) * x;
} else {
tmp = t_0;
}
return tmp;
}
function code(x) t_0 = Float64(Float64(2.0 / Float64(exp(Float64(x * -2.0)) - -1.0)) - 1.0) tmp = 0.0 if (x <= -0.0074) tmp = Float64(1.0 / Float64(1.0 / t_0)); elseif (x <= 0.007) tmp = Float64(fma(fma(0.13333333333333333, Float64(x * x), -0.3333333333333333), Float64(x * x), 1.0) * x); else tmp = t_0; end return tmp end
code[x_] := Block[{t$95$0 = N[(N[(2.0 / N[(N[Exp[N[(x * -2.0), $MachinePrecision]], $MachinePrecision] - -1.0), $MachinePrecision]), $MachinePrecision] - 1.0), $MachinePrecision]}, If[LessEqual[x, -0.0074], N[(1.0 / N[(1.0 / t$95$0), $MachinePrecision]), $MachinePrecision], If[LessEqual[x, 0.007], N[(N[(N[(0.13333333333333333 * N[(x * x), $MachinePrecision] + -0.3333333333333333), $MachinePrecision] * N[(x * x), $MachinePrecision] + 1.0), $MachinePrecision] * x), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{2}{e^{x \cdot -2} - -1} - 1\\
\mathbf{if}\;x \leq -0.0074:\\
\;\;\;\;\frac{1}{\frac{1}{t\_0}}\\
\mathbf{elif}\;x \leq 0.007:\\
\;\;\;\;\mathsf{fma}\left(\mathsf{fma}\left(0.13333333333333333, x \cdot x, -0.3333333333333333\right), x \cdot x, 1\right) \cdot x\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if x < -0.0074000000000000003Initial program 100.0%
lift--.f64N/A
lift-/.f64N/A
lift-+.f64N/A
lift-*.f64N/A
lift-exp.f64N/A
flip--N/A
division-flipN/A
lower-/.f64N/A
lower-/.f64N/A
Applied rewrites100.0%
lift-/.f64N/A
lift--.f64N/A
lift-/.f64N/A
lift--.f64N/A
lift-*.f64N/A
lift-exp.f64N/A
lift--.f64N/A
lift-pow.f64N/A
lift-/.f64N/A
lift--.f64N/A
lift-*.f64N/A
lift-exp.f64N/A
division-flipN/A
Applied rewrites100.0%
if -0.0074000000000000003 < x < 0.00700000000000000015Initial program 7.8%
Taylor expanded in x around 0
*-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
sub-flipN/A
metadata-evalN/A
lower-fma.f64N/A
unpow2N/A
lower-*.f64N/A
unpow2N/A
lower-*.f64100.0
Applied rewrites100.0%
if 0.00700000000000000015 < x Initial program 100.0%
lift-+.f64N/A
lift-*.f64N/A
lift-exp.f64N/A
add-flipN/A
metadata-evalN/A
sub-negate-revN/A
lower--.f64N/A
lift-exp.f64N/A
*-commutativeN/A
lower-*.f64100.0
Applied rewrites100.0%
(FPCore (x)
:precision binary64
(let* ((t_0 (- (/ 2.0 (- (exp (* x -2.0)) -1.0)) 1.0)))
(if (<= x -0.0074)
t_0
(if (<= x 0.007)
(*
(fma (fma 0.13333333333333333 (* x x) -0.3333333333333333) (* x x) 1.0)
x)
t_0))))
double code(double x) {
double t_0 = (2.0 / (exp((x * -2.0)) - -1.0)) - 1.0;
double tmp;
if (x <= -0.0074) {
tmp = t_0;
} else if (x <= 0.007) {
tmp = fma(fma(0.13333333333333333, (x * x), -0.3333333333333333), (x * x), 1.0) * x;
} else {
tmp = t_0;
}
return tmp;
}
function code(x) t_0 = Float64(Float64(2.0 / Float64(exp(Float64(x * -2.0)) - -1.0)) - 1.0) tmp = 0.0 if (x <= -0.0074) tmp = t_0; elseif (x <= 0.007) tmp = Float64(fma(fma(0.13333333333333333, Float64(x * x), -0.3333333333333333), Float64(x * x), 1.0) * x); else tmp = t_0; end return tmp end
code[x_] := Block[{t$95$0 = N[(N[(2.0 / N[(N[Exp[N[(x * -2.0), $MachinePrecision]], $MachinePrecision] - -1.0), $MachinePrecision]), $MachinePrecision] - 1.0), $MachinePrecision]}, If[LessEqual[x, -0.0074], t$95$0, If[LessEqual[x, 0.007], N[(N[(N[(0.13333333333333333 * N[(x * x), $MachinePrecision] + -0.3333333333333333), $MachinePrecision] * N[(x * x), $MachinePrecision] + 1.0), $MachinePrecision] * x), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{2}{e^{x \cdot -2} - -1} - 1\\
\mathbf{if}\;x \leq -0.0074:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;x \leq 0.007:\\
\;\;\;\;\mathsf{fma}\left(\mathsf{fma}\left(0.13333333333333333, x \cdot x, -0.3333333333333333\right), x \cdot x, 1\right) \cdot x\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if x < -0.0074000000000000003 or 0.00700000000000000015 < x Initial program 100.0%
lift-+.f64N/A
lift-*.f64N/A
lift-exp.f64N/A
add-flipN/A
metadata-evalN/A
sub-negate-revN/A
lower--.f64N/A
lift-exp.f64N/A
*-commutativeN/A
lower-*.f64100.0
Applied rewrites100.0%
if -0.0074000000000000003 < x < 0.00700000000000000015Initial program 7.8%
Taylor expanded in x around 0
*-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
sub-flipN/A
metadata-evalN/A
lower-fma.f64N/A
unpow2N/A
lower-*.f64N/A
unpow2N/A
lower-*.f64100.0
Applied rewrites100.0%
(FPCore (x) :precision binary64 (if (<= x -1.5) (- (/ 2.0 (fma (fma (fma -1.3333333333333333 x 2.0) x -2.0) x 2.0)) 1.0) (/ 1.0 (fma 0.3333333333333333 x (/ 1.0 x)))))
double code(double x) {
double tmp;
if (x <= -1.5) {
tmp = (2.0 / fma(fma(fma(-1.3333333333333333, x, 2.0), x, -2.0), x, 2.0)) - 1.0;
} else {
tmp = 1.0 / fma(0.3333333333333333, x, (1.0 / x));
}
return tmp;
}
function code(x) tmp = 0.0 if (x <= -1.5) tmp = Float64(Float64(2.0 / fma(fma(fma(-1.3333333333333333, x, 2.0), x, -2.0), x, 2.0)) - 1.0); else tmp = Float64(1.0 / fma(0.3333333333333333, x, Float64(1.0 / x))); end return tmp end
code[x_] := If[LessEqual[x, -1.5], N[(N[(2.0 / N[(N[(N[(-1.3333333333333333 * x + 2.0), $MachinePrecision] * x + -2.0), $MachinePrecision] * x + 2.0), $MachinePrecision]), $MachinePrecision] - 1.0), $MachinePrecision], N[(1.0 / N[(0.3333333333333333 * x + N[(1.0 / x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.5:\\
\;\;\;\;\frac{2}{\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(-1.3333333333333333, x, 2\right), x, -2\right), x, 2\right)} - 1\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{\mathsf{fma}\left(0.3333333333333333, x, \frac{1}{x}\right)}\\
\end{array}
\end{array}
if x < -1.5Initial program 100.0%
Taylor expanded in x around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
sub-flipN/A
*-commutativeN/A
metadata-evalN/A
lower-fma.f64N/A
+-commutativeN/A
lower-fma.f6499.3
Applied rewrites99.3%
if -1.5 < x Initial program 38.9%
lift--.f64N/A
lift-/.f64N/A
lift-+.f64N/A
lift-*.f64N/A
lift-exp.f64N/A
flip--N/A
division-flipN/A
lower-/.f64N/A
lower-/.f64N/A
Applied rewrites38.9%
Taylor expanded in x around 0
lower-/.f64N/A
+-commutativeN/A
lower-fma.f64N/A
pow2N/A
lift-*.f6468.0
Applied rewrites68.0%
Taylor expanded in x around inf
distribute-rgt-inN/A
pow-flipN/A
metadata-evalN/A
pow-plusN/A
metadata-evalN/A
inv-powN/A
lower-fma.f64N/A
lower-/.f6468.1
Applied rewrites68.1%
(FPCore (x) :precision binary64 (if (<= x -1.8) (- (/ 2.0 (* (- (/ 2.0 x) 1.3333333333333333) (* (* x x) x))) 1.0) (/ 1.0 (fma 0.3333333333333333 x (/ 1.0 x)))))
double code(double x) {
double tmp;
if (x <= -1.8) {
tmp = (2.0 / (((2.0 / x) - 1.3333333333333333) * ((x * x) * x))) - 1.0;
} else {
tmp = 1.0 / fma(0.3333333333333333, x, (1.0 / x));
}
return tmp;
}
function code(x) tmp = 0.0 if (x <= -1.8) tmp = Float64(Float64(2.0 / Float64(Float64(Float64(2.0 / x) - 1.3333333333333333) * Float64(Float64(x * x) * x))) - 1.0); else tmp = Float64(1.0 / fma(0.3333333333333333, x, Float64(1.0 / x))); end return tmp end
code[x_] := If[LessEqual[x, -1.8], N[(N[(2.0 / N[(N[(N[(2.0 / x), $MachinePrecision] - 1.3333333333333333), $MachinePrecision] * N[(N[(x * x), $MachinePrecision] * x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - 1.0), $MachinePrecision], N[(1.0 / N[(0.3333333333333333 * x + N[(1.0 / x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.8:\\
\;\;\;\;\frac{2}{\left(\frac{2}{x} - 1.3333333333333333\right) \cdot \left(\left(x \cdot x\right) \cdot x\right)} - 1\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{\mathsf{fma}\left(0.3333333333333333, x, \frac{1}{x}\right)}\\
\end{array}
\end{array}
if x < -1.80000000000000004Initial program 100.0%
Taylor expanded in x around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
sub-flipN/A
*-commutativeN/A
metadata-evalN/A
lower-fma.f64N/A
+-commutativeN/A
lower-fma.f6499.3
Applied rewrites99.3%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f64N/A
lower--.f64N/A
mult-flip-revN/A
lower-/.f64N/A
unpow3N/A
pow2N/A
lower-*.f64N/A
pow2N/A
lift-*.f6499.3
Applied rewrites99.3%
if -1.80000000000000004 < x Initial program 38.9%
lift--.f64N/A
lift-/.f64N/A
lift-+.f64N/A
lift-*.f64N/A
lift-exp.f64N/A
flip--N/A
division-flipN/A
lower-/.f64N/A
lower-/.f64N/A
Applied rewrites38.9%
Taylor expanded in x around 0
lower-/.f64N/A
+-commutativeN/A
lower-fma.f64N/A
pow2N/A
lift-*.f6468.0
Applied rewrites68.0%
Taylor expanded in x around inf
distribute-rgt-inN/A
pow-flipN/A
metadata-evalN/A
pow-plusN/A
metadata-evalN/A
inv-powN/A
lower-fma.f64N/A
lower-/.f6468.1
Applied rewrites68.1%
(FPCore (x) :precision binary64 (if (<= x -1.9) (- (/ 2.0 (fma (fma (* -1.3333333333333333 x) x -2.0) x 2.0)) 1.0) (/ 1.0 (fma 0.3333333333333333 x (/ 1.0 x)))))
double code(double x) {
double tmp;
if (x <= -1.9) {
tmp = (2.0 / fma(fma((-1.3333333333333333 * x), x, -2.0), x, 2.0)) - 1.0;
} else {
tmp = 1.0 / fma(0.3333333333333333, x, (1.0 / x));
}
return tmp;
}
function code(x) tmp = 0.0 if (x <= -1.9) tmp = Float64(Float64(2.0 / fma(fma(Float64(-1.3333333333333333 * x), x, -2.0), x, 2.0)) - 1.0); else tmp = Float64(1.0 / fma(0.3333333333333333, x, Float64(1.0 / x))); end return tmp end
code[x_] := If[LessEqual[x, -1.9], N[(N[(2.0 / N[(N[(N[(-1.3333333333333333 * x), $MachinePrecision] * x + -2.0), $MachinePrecision] * x + 2.0), $MachinePrecision]), $MachinePrecision] - 1.0), $MachinePrecision], N[(1.0 / N[(0.3333333333333333 * x + N[(1.0 / x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.9:\\
\;\;\;\;\frac{2}{\mathsf{fma}\left(\mathsf{fma}\left(-1.3333333333333333 \cdot x, x, -2\right), x, 2\right)} - 1\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{\mathsf{fma}\left(0.3333333333333333, x, \frac{1}{x}\right)}\\
\end{array}
\end{array}
if x < -1.8999999999999999Initial program 100.0%
Taylor expanded in x around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
sub-flipN/A
*-commutativeN/A
metadata-evalN/A
lower-fma.f64N/A
+-commutativeN/A
lower-fma.f6499.3
Applied rewrites99.3%
Taylor expanded in x around inf
lower-*.f6499.3
Applied rewrites99.3%
if -1.8999999999999999 < x Initial program 38.9%
lift--.f64N/A
lift-/.f64N/A
lift-+.f64N/A
lift-*.f64N/A
lift-exp.f64N/A
flip--N/A
division-flipN/A
lower-/.f64N/A
lower-/.f64N/A
Applied rewrites38.9%
Taylor expanded in x around 0
lower-/.f64N/A
+-commutativeN/A
lower-fma.f64N/A
pow2N/A
lift-*.f6468.0
Applied rewrites68.0%
Taylor expanded in x around inf
distribute-rgt-inN/A
pow-flipN/A
metadata-evalN/A
pow-plusN/A
metadata-evalN/A
inv-powN/A
lower-fma.f64N/A
lower-/.f6468.1
Applied rewrites68.1%
(FPCore (x) :precision binary64 (if (<= x -2.0) (- (/ 2.0 (fma (* (* x x) -1.3333333333333333) x 2.0)) 1.0) (/ 1.0 (fma 0.3333333333333333 x (/ 1.0 x)))))
double code(double x) {
double tmp;
if (x <= -2.0) {
tmp = (2.0 / fma(((x * x) * -1.3333333333333333), x, 2.0)) - 1.0;
} else {
tmp = 1.0 / fma(0.3333333333333333, x, (1.0 / x));
}
return tmp;
}
function code(x) tmp = 0.0 if (x <= -2.0) tmp = Float64(Float64(2.0 / fma(Float64(Float64(x * x) * -1.3333333333333333), x, 2.0)) - 1.0); else tmp = Float64(1.0 / fma(0.3333333333333333, x, Float64(1.0 / x))); end return tmp end
code[x_] := If[LessEqual[x, -2.0], N[(N[(2.0 / N[(N[(N[(x * x), $MachinePrecision] * -1.3333333333333333), $MachinePrecision] * x + 2.0), $MachinePrecision]), $MachinePrecision] - 1.0), $MachinePrecision], N[(1.0 / N[(0.3333333333333333 * x + N[(1.0 / x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -2:\\
\;\;\;\;\frac{2}{\mathsf{fma}\left(\left(x \cdot x\right) \cdot -1.3333333333333333, x, 2\right)} - 1\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{\mathsf{fma}\left(0.3333333333333333, x, \frac{1}{x}\right)}\\
\end{array}
\end{array}
if x < -2Initial program 100.0%
Taylor expanded in x around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
sub-flipN/A
*-commutativeN/A
metadata-evalN/A
lower-fma.f64N/A
+-commutativeN/A
lower-fma.f6499.3
Applied rewrites99.3%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f64N/A
pow2N/A
lift-*.f6499.3
Applied rewrites99.3%
if -2 < x Initial program 38.9%
lift--.f64N/A
lift-/.f64N/A
lift-+.f64N/A
lift-*.f64N/A
lift-exp.f64N/A
flip--N/A
division-flipN/A
lower-/.f64N/A
lower-/.f64N/A
Applied rewrites38.9%
Taylor expanded in x around 0
lower-/.f64N/A
+-commutativeN/A
lower-fma.f64N/A
pow2N/A
lift-*.f6468.0
Applied rewrites68.0%
Taylor expanded in x around inf
distribute-rgt-inN/A
pow-flipN/A
metadata-evalN/A
pow-plusN/A
metadata-evalN/A
inv-powN/A
lower-fma.f64N/A
lower-/.f6468.1
Applied rewrites68.1%
(FPCore (x) :precision binary64 (if (<= (- (/ 2.0 (+ 1.0 (exp (* -2.0 x)))) 1.0) -0.5) (- (/ 2.0 (* (* (* x x) x) -1.3333333333333333)) 1.0) (/ 1.0 (fma 0.3333333333333333 x (/ 1.0 x)))))
double code(double x) {
double tmp;
if (((2.0 / (1.0 + exp((-2.0 * x)))) - 1.0) <= -0.5) {
tmp = (2.0 / (((x * x) * x) * -1.3333333333333333)) - 1.0;
} else {
tmp = 1.0 / fma(0.3333333333333333, x, (1.0 / x));
}
return tmp;
}
function code(x) tmp = 0.0 if (Float64(Float64(2.0 / Float64(1.0 + exp(Float64(-2.0 * x)))) - 1.0) <= -0.5) tmp = Float64(Float64(2.0 / Float64(Float64(Float64(x * x) * x) * -1.3333333333333333)) - 1.0); else tmp = Float64(1.0 / fma(0.3333333333333333, x, Float64(1.0 / x))); end return 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], -0.5], N[(N[(2.0 / N[(N[(N[(x * x), $MachinePrecision] * x), $MachinePrecision] * -1.3333333333333333), $MachinePrecision]), $MachinePrecision] - 1.0), $MachinePrecision], N[(1.0 / N[(0.3333333333333333 * x + N[(1.0 / x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\frac{2}{1 + e^{-2 \cdot x}} - 1 \leq -0.5:\\
\;\;\;\;\frac{2}{\left(\left(x \cdot x\right) \cdot x\right) \cdot -1.3333333333333333} - 1\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{\mathsf{fma}\left(0.3333333333333333, x, \frac{1}{x}\right)}\\
\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)) < -0.5Initial program 100.0%
Taylor expanded in x around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
sub-flipN/A
*-commutativeN/A
metadata-evalN/A
lower-fma.f64N/A
+-commutativeN/A
lower-fma.f6499.2
Applied rewrites99.2%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f64N/A
unpow3N/A
pow2N/A
lower-*.f64N/A
pow2N/A
lift-*.f6499.2
Applied rewrites99.2%
if -0.5 < (-.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 38.9%
lift--.f64N/A
lift-/.f64N/A
lift-+.f64N/A
lift-*.f64N/A
lift-exp.f64N/A
flip--N/A
division-flipN/A
lower-/.f64N/A
lower-/.f64N/A
Applied rewrites38.8%
Taylor expanded in x around 0
lower-/.f64N/A
+-commutativeN/A
lower-fma.f64N/A
pow2N/A
lift-*.f6468.0
Applied rewrites68.0%
Taylor expanded in x around inf
distribute-rgt-inN/A
pow-flipN/A
metadata-evalN/A
pow-plusN/A
metadata-evalN/A
inv-powN/A
lower-fma.f64N/A
lower-/.f6468.1
Applied rewrites68.1%
(FPCore (x) :precision binary64 (if (<= x -2.3) (- (/ 2.0 (fma (+ x x) x 2.0)) 1.0) (/ 1.0 (fma 0.3333333333333333 x (/ 1.0 x)))))
double code(double x) {
double tmp;
if (x <= -2.3) {
tmp = (2.0 / fma((x + x), x, 2.0)) - 1.0;
} else {
tmp = 1.0 / fma(0.3333333333333333, x, (1.0 / x));
}
return tmp;
}
function code(x) tmp = 0.0 if (x <= -2.3) tmp = Float64(Float64(2.0 / fma(Float64(x + x), x, 2.0)) - 1.0); else tmp = Float64(1.0 / fma(0.3333333333333333, x, Float64(1.0 / x))); end return tmp end
code[x_] := If[LessEqual[x, -2.3], N[(N[(2.0 / N[(N[(x + x), $MachinePrecision] * x + 2.0), $MachinePrecision]), $MachinePrecision] - 1.0), $MachinePrecision], N[(1.0 / N[(0.3333333333333333 * x + N[(1.0 / x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -2.3:\\
\;\;\;\;\frac{2}{\mathsf{fma}\left(x + x, x, 2\right)} - 1\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{\mathsf{fma}\left(0.3333333333333333, x, \frac{1}{x}\right)}\\
\end{array}
\end{array}
if x < -2.2999999999999998Initial program 100.0%
Taylor expanded in x around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
sub-flipN/A
metadata-evalN/A
*-commutativeN/A
lower-fma.f6499.0
Applied rewrites99.0%
Taylor expanded in x around inf
count-2-revN/A
lower-+.f6499.0
Applied rewrites99.0%
if -2.2999999999999998 < x Initial program 38.9%
lift--.f64N/A
lift-/.f64N/A
lift-+.f64N/A
lift-*.f64N/A
lift-exp.f64N/A
flip--N/A
division-flipN/A
lower-/.f64N/A
lower-/.f64N/A
Applied rewrites38.9%
Taylor expanded in x around 0
lower-/.f64N/A
+-commutativeN/A
lower-fma.f64N/A
pow2N/A
lift-*.f6468.0
Applied rewrites68.0%
Taylor expanded in x around inf
distribute-rgt-inN/A
pow-flipN/A
metadata-evalN/A
pow-plusN/A
metadata-evalN/A
inv-powN/A
lower-fma.f64N/A
lower-/.f6468.1
Applied rewrites68.1%
(FPCore (x) :precision binary64 (if (<= x -2.4) (- (/ 2.0 (* x (+ x x))) 1.0) (/ 1.0 (fma 0.3333333333333333 x (/ 1.0 x)))))
double code(double x) {
double tmp;
if (x <= -2.4) {
tmp = (2.0 / (x * (x + x))) - 1.0;
} else {
tmp = 1.0 / fma(0.3333333333333333, x, (1.0 / x));
}
return tmp;
}
function code(x) tmp = 0.0 if (x <= -2.4) tmp = Float64(Float64(2.0 / Float64(x * Float64(x + x))) - 1.0); else tmp = Float64(1.0 / fma(0.3333333333333333, x, Float64(1.0 / x))); end return tmp end
code[x_] := If[LessEqual[x, -2.4], N[(N[(2.0 / N[(x * N[(x + x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - 1.0), $MachinePrecision], N[(1.0 / N[(0.3333333333333333 * x + N[(1.0 / x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -2.4:\\
\;\;\;\;\frac{2}{x \cdot \left(x + x\right)} - 1\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{\mathsf{fma}\left(0.3333333333333333, x, \frac{1}{x}\right)}\\
\end{array}
\end{array}
if x < -2.39999999999999991Initial program 100.0%
Taylor expanded in x around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
sub-flipN/A
metadata-evalN/A
*-commutativeN/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%
+-commutative99.0
*-commutative99.0
metadata-eval99.0
sub-flip99.0
lift-*.f64N/A
lift-*.f64N/A
associate-*l*N/A
*-commutativeN/A
lower-*.f64N/A
count-2-revN/A
lower-+.f6499.0
Applied rewrites99.0%
if -2.39999999999999991 < x Initial program 38.9%
lift--.f64N/A
lift-/.f64N/A
lift-+.f64N/A
lift-*.f64N/A
lift-exp.f64N/A
flip--N/A
division-flipN/A
lower-/.f64N/A
lower-/.f64N/A
Applied rewrites38.9%
Taylor expanded in x around 0
lower-/.f64N/A
+-commutativeN/A
lower-fma.f64N/A
pow2N/A
lift-*.f6468.0
Applied rewrites68.0%
Taylor expanded in x around inf
distribute-rgt-inN/A
pow-flipN/A
metadata-evalN/A
pow-plusN/A
metadata-evalN/A
inv-powN/A
lower-fma.f64N/A
lower-/.f6468.1
Applied rewrites68.1%
(FPCore (x) :precision binary64 (if (<= (* -2.0 x) 0.2) x (- (/ 2.0 (* x (+ x x))) 1.0)))
double code(double x) {
double tmp;
if ((-2.0 * x) <= 0.2) {
tmp = x;
} else {
tmp = (2.0 / (x * (x + x))) - 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) <= 0.2d0) then
tmp = x
else
tmp = (2.0d0 / (x * (x + x))) - 1.0d0
end if
code = tmp
end function
public static double code(double x) {
double tmp;
if ((-2.0 * x) <= 0.2) {
tmp = x;
} else {
tmp = (2.0 / (x * (x + x))) - 1.0;
}
return tmp;
}
def code(x): tmp = 0 if (-2.0 * x) <= 0.2: tmp = x else: tmp = (2.0 / (x * (x + x))) - 1.0 return tmp
function code(x) tmp = 0.0 if (Float64(-2.0 * x) <= 0.2) tmp = x; else tmp = Float64(Float64(2.0 / Float64(x * Float64(x + x))) - 1.0); end return tmp end
function tmp_2 = code(x) tmp = 0.0; if ((-2.0 * x) <= 0.2) tmp = x; else tmp = (2.0 / (x * (x + x))) - 1.0; end tmp_2 = tmp; end
code[x_] := If[LessEqual[N[(-2.0 * x), $MachinePrecision], 0.2], x, N[(N[(2.0 / N[(x * N[(x + x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - 1.0), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;-2 \cdot x \leq 0.2:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;\frac{2}{x \cdot \left(x + x\right)} - 1\\
\end{array}
\end{array}
if (*.f64 #s(literal -2 binary64) x) < 0.20000000000000001Initial program 38.8%
Taylor expanded in x around 0
Applied rewrites67.9%
if 0.20000000000000001 < (*.f64 #s(literal -2 binary64) x) Initial program 100.0%
Taylor expanded in x around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
sub-flipN/A
metadata-evalN/A
*-commutativeN/A
lower-fma.f6498.8
Applied rewrites98.8%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f64N/A
pow2N/A
lift-*.f6498.7
Applied rewrites98.7%
+-commutative98.7
*-commutative98.7
metadata-eval98.7
sub-flip98.7
lift-*.f64N/A
lift-*.f64N/A
associate-*l*N/A
*-commutativeN/A
lower-*.f64N/A
count-2-revN/A
lower-+.f6498.7
Applied rewrites98.7%
(FPCore (x) :precision binary64 (if (<= (* -2.0 x) 0.2) x (- (/ 2.0 (fma x -2.0 2.0)) 1.0)))
double code(double x) {
double tmp;
if ((-2.0 * x) <= 0.2) {
tmp = x;
} else {
tmp = (2.0 / fma(x, -2.0, 2.0)) - 1.0;
}
return tmp;
}
function code(x) tmp = 0.0 if (Float64(-2.0 * x) <= 0.2) tmp = x; else tmp = Float64(Float64(2.0 / fma(x, -2.0, 2.0)) - 1.0); end return tmp end
code[x_] := If[LessEqual[N[(-2.0 * x), $MachinePrecision], 0.2], x, N[(N[(2.0 / N[(x * -2.0 + 2.0), $MachinePrecision]), $MachinePrecision] - 1.0), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;-2 \cdot x \leq 0.2:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;\frac{2}{\mathsf{fma}\left(x, -2, 2\right)} - 1\\
\end{array}
\end{array}
if (*.f64 #s(literal -2 binary64) x) < 0.20000000000000001Initial program 38.8%
Taylor expanded in x around 0
Applied rewrites67.9%
if 0.20000000000000001 < (*.f64 #s(literal -2 binary64) x) Initial program 100.0%
Taylor expanded in x around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f6497.7
Applied rewrites97.7%
(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.3%
Taylor expanded in x around 0
Applied rewrites52.1%
herbie shell --seed 2025127
(FPCore (x)
:name "Logistic function from Lakshay Garg"
:precision binary64
(- (/ 2.0 (+ 1.0 (exp (* -2.0 x)))) 1.0))