
(FPCore (x) :precision binary64 (* (fmod (exp x) (sqrt (cos x))) (exp (- x))))
double code(double x) {
return fmod(exp(x), sqrt(cos(x))) * exp(-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 = mod(exp(x), sqrt(cos(x))) * exp(-x)
end function
def code(x): return math.fmod(math.exp(x), math.sqrt(math.cos(x))) * math.exp(-x)
function code(x) return Float64(rem(exp(x), sqrt(cos(x))) * exp(Float64(-x))) end
code[x_] := N[(N[With[{TMP1 = N[Exp[x], $MachinePrecision], TMP2 = N[Sqrt[N[Cos[x], $MachinePrecision]], $MachinePrecision]}, Mod[Abs[TMP1], Abs[TMP2]] * Sign[TMP1]], $MachinePrecision] * N[Exp[(-x)], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right) \cdot e^{-x}
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 6 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x) :precision binary64 (* (fmod (exp x) (sqrt (cos x))) (exp (- x))))
double code(double x) {
return fmod(exp(x), sqrt(cos(x))) * exp(-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 = mod(exp(x), sqrt(cos(x))) * exp(-x)
end function
def code(x): return math.fmod(math.exp(x), math.sqrt(math.cos(x))) * math.exp(-x)
function code(x) return Float64(rem(exp(x), sqrt(cos(x))) * exp(Float64(-x))) end
code[x_] := N[(N[With[{TMP1 = N[Exp[x], $MachinePrecision], TMP2 = N[Sqrt[N[Cos[x], $MachinePrecision]], $MachinePrecision]}, Mod[Abs[TMP1], Abs[TMP2]] * Sign[TMP1]], $MachinePrecision] * N[Exp[(-x)], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right) \cdot e^{-x}
\end{array}
(FPCore (x)
:precision binary64
(let* ((t_0 (sqrt (cos x))) (t_1 (pow (pow (cos x) -0.25) -1.0)))
(if (<= x -1e-90)
(fma
(* (fmod (exp x) (* t_1 t_1)) (fma 0.5 x -1.0))
x
(fmod (* (+ (+ (pow x -1.0) 0.5) (pow x -2.0)) (* x x)) t_0))
(if (<= x -6e-309)
(* (fmod (* (+ (pow x -1.0) 1.0) x) t_0) 1.0)
(* (fmod x t_0) (exp (- x)))))))
double code(double x) {
double t_0 = sqrt(cos(x));
double t_1 = pow(pow(cos(x), -0.25), -1.0);
double tmp;
if (x <= -1e-90) {
tmp = fma((fmod(exp(x), (t_1 * t_1)) * fma(0.5, x, -1.0)), x, fmod((((pow(x, -1.0) + 0.5) + pow(x, -2.0)) * (x * x)), t_0));
} else if (x <= -6e-309) {
tmp = fmod(((pow(x, -1.0) + 1.0) * x), t_0) * 1.0;
} else {
tmp = fmod(x, t_0) * exp(-x);
}
return tmp;
}
function code(x) t_0 = sqrt(cos(x)) t_1 = (cos(x) ^ -0.25) ^ -1.0 tmp = 0.0 if (x <= -1e-90) tmp = fma(Float64(rem(exp(x), Float64(t_1 * t_1)) * fma(0.5, x, -1.0)), x, rem(Float64(Float64(Float64((x ^ -1.0) + 0.5) + (x ^ -2.0)) * Float64(x * x)), t_0)); elseif (x <= -6e-309) tmp = Float64(rem(Float64(Float64((x ^ -1.0) + 1.0) * x), t_0) * 1.0); else tmp = Float64(rem(x, t_0) * exp(Float64(-x))); end return tmp end
code[x_] := Block[{t$95$0 = N[Sqrt[N[Cos[x], $MachinePrecision]], $MachinePrecision]}, Block[{t$95$1 = N[Power[N[Power[N[Cos[x], $MachinePrecision], -0.25], $MachinePrecision], -1.0], $MachinePrecision]}, If[LessEqual[x, -1e-90], N[(N[(N[With[{TMP1 = N[Exp[x], $MachinePrecision], TMP2 = N[(t$95$1 * t$95$1), $MachinePrecision]}, Mod[Abs[TMP1], Abs[TMP2]] * Sign[TMP1]], $MachinePrecision] * N[(0.5 * x + -1.0), $MachinePrecision]), $MachinePrecision] * x + N[With[{TMP1 = N[(N[(N[(N[Power[x, -1.0], $MachinePrecision] + 0.5), $MachinePrecision] + N[Power[x, -2.0], $MachinePrecision]), $MachinePrecision] * N[(x * x), $MachinePrecision]), $MachinePrecision], TMP2 = t$95$0}, Mod[Abs[TMP1], Abs[TMP2]] * Sign[TMP1]], $MachinePrecision]), $MachinePrecision], If[LessEqual[x, -6e-309], N[(N[With[{TMP1 = N[(N[(N[Power[x, -1.0], $MachinePrecision] + 1.0), $MachinePrecision] * x), $MachinePrecision], TMP2 = t$95$0}, Mod[Abs[TMP1], Abs[TMP2]] * Sign[TMP1]], $MachinePrecision] * 1.0), $MachinePrecision], N[(N[With[{TMP1 = x, TMP2 = t$95$0}, Mod[Abs[TMP1], Abs[TMP2]] * Sign[TMP1]], $MachinePrecision] * N[Exp[(-x)], $MachinePrecision]), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sqrt{\cos x}\\
t_1 := {\left({\cos x}^{-0.25}\right)}^{-1}\\
\mathbf{if}\;x \leq -1 \cdot 10^{-90}:\\
\;\;\;\;\mathsf{fma}\left(\left(\left(e^{x}\right) \bmod \left(t\_1 \cdot t\_1\right)\right) \cdot \mathsf{fma}\left(0.5, x, -1\right), x, \left(\left(\left(\left({x}^{-1} + 0.5\right) + {x}^{-2}\right) \cdot \left(x \cdot x\right)\right) \bmod t\_0\right)\right)\\
\mathbf{elif}\;x \leq -6 \cdot 10^{-309}:\\
\;\;\;\;\left(\left(\left({x}^{-1} + 1\right) \cdot x\right) \bmod t\_0\right) \cdot 1\\
\mathbf{else}:\\
\;\;\;\;\left(x \bmod t\_0\right) \cdot e^{-x}\\
\end{array}
\end{array}
if x < -9.99999999999999995e-91Initial program 20.1%
Taylor expanded in x around 0
*-commutativeN/A
lower-fma.f64N/A
Applied rewrites17.8%
lift-cos.f64N/A
lift-sqrt.f64N/A
pow1/2N/A
metadata-evalN/A
pow-powN/A
sqr-powN/A
unpow-prod-downN/A
lower-*.f64N/A
lower-pow.f64N/A
metadata-evalN/A
lower-pow.f64N/A
lift-cos.f64N/A
lower-pow.f64N/A
metadata-evalN/A
lower-pow.f64N/A
lift-cos.f6417.8
Applied rewrites17.8%
Taylor expanded in x around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
+-commutativeN/A
lower-fma.f6419.0
Applied rewrites19.0%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f64N/A
associate-+r+N/A
lower-+.f64N/A
+-commutativeN/A
lower-+.f64N/A
inv-powN/A
lower-pow.f64N/A
pow-flipN/A
metadata-evalN/A
metadata-evalN/A
lower-pow.f64N/A
metadata-evalN/A
unpow2N/A
lower-*.f6432.9
Applied rewrites32.9%
if -9.99999999999999995e-91 < x < -6.000000000000001e-309Initial program 3.1%
Taylor expanded in x around 0
+-commutativeN/A
metadata-evalN/A
fp-cancel-sign-sub-invN/A
metadata-evalN/A
metadata-evalN/A
lower--.f643.1
Applied rewrites3.1%
Taylor expanded in x around inf
Applied rewrites2.5%
Taylor expanded in x around 0
Applied rewrites2.5%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
lower-+.f64N/A
inv-powN/A
lower-pow.f6416.7
Applied rewrites16.7%
if -6.000000000000001e-309 < x Initial program 5.4%
Taylor expanded in x around 0
+-commutativeN/A
metadata-evalN/A
fp-cancel-sign-sub-invN/A
metadata-evalN/A
metadata-evalN/A
lower--.f6439.0
Applied rewrites39.0%
Taylor expanded in x around inf
Applied rewrites98.7%
(FPCore (x)
:precision binary64
(let* ((t_0 (sqrt (cos x))) (t_1 (pow (pow (cos x) -0.25) -1.0)))
(if (<= x -7.5e-155)
(fma
(* (fmod (exp x) (* t_1 t_1)) (fma 0.5 x -1.0))
x
(fmod (* (+ (+ (pow x -1.0) 0.5) (pow x -2.0)) (* x x)) t_0))
(* (fmod x t_0) (exp (- x))))))
double code(double x) {
double t_0 = sqrt(cos(x));
double t_1 = pow(pow(cos(x), -0.25), -1.0);
double tmp;
if (x <= -7.5e-155) {
tmp = fma((fmod(exp(x), (t_1 * t_1)) * fma(0.5, x, -1.0)), x, fmod((((pow(x, -1.0) + 0.5) + pow(x, -2.0)) * (x * x)), t_0));
} else {
tmp = fmod(x, t_0) * exp(-x);
}
return tmp;
}
function code(x) t_0 = sqrt(cos(x)) t_1 = (cos(x) ^ -0.25) ^ -1.0 tmp = 0.0 if (x <= -7.5e-155) tmp = fma(Float64(rem(exp(x), Float64(t_1 * t_1)) * fma(0.5, x, -1.0)), x, rem(Float64(Float64(Float64((x ^ -1.0) + 0.5) + (x ^ -2.0)) * Float64(x * x)), t_0)); else tmp = Float64(rem(x, t_0) * exp(Float64(-x))); end return tmp end
code[x_] := Block[{t$95$0 = N[Sqrt[N[Cos[x], $MachinePrecision]], $MachinePrecision]}, Block[{t$95$1 = N[Power[N[Power[N[Cos[x], $MachinePrecision], -0.25], $MachinePrecision], -1.0], $MachinePrecision]}, If[LessEqual[x, -7.5e-155], N[(N[(N[With[{TMP1 = N[Exp[x], $MachinePrecision], TMP2 = N[(t$95$1 * t$95$1), $MachinePrecision]}, Mod[Abs[TMP1], Abs[TMP2]] * Sign[TMP1]], $MachinePrecision] * N[(0.5 * x + -1.0), $MachinePrecision]), $MachinePrecision] * x + N[With[{TMP1 = N[(N[(N[(N[Power[x, -1.0], $MachinePrecision] + 0.5), $MachinePrecision] + N[Power[x, -2.0], $MachinePrecision]), $MachinePrecision] * N[(x * x), $MachinePrecision]), $MachinePrecision], TMP2 = t$95$0}, Mod[Abs[TMP1], Abs[TMP2]] * Sign[TMP1]], $MachinePrecision]), $MachinePrecision], N[(N[With[{TMP1 = x, TMP2 = t$95$0}, Mod[Abs[TMP1], Abs[TMP2]] * Sign[TMP1]], $MachinePrecision] * N[Exp[(-x)], $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sqrt{\cos x}\\
t_1 := {\left({\cos x}^{-0.25}\right)}^{-1}\\
\mathbf{if}\;x \leq -7.5 \cdot 10^{-155}:\\
\;\;\;\;\mathsf{fma}\left(\left(\left(e^{x}\right) \bmod \left(t\_1 \cdot t\_1\right)\right) \cdot \mathsf{fma}\left(0.5, x, -1\right), x, \left(\left(\left(\left({x}^{-1} + 0.5\right) + {x}^{-2}\right) \cdot \left(x \cdot x\right)\right) \bmod t\_0\right)\right)\\
\mathbf{else}:\\
\;\;\;\;\left(x \bmod t\_0\right) \cdot e^{-x}\\
\end{array}
\end{array}
if x < -7.5000000000000006e-155Initial program 13.8%
Taylor expanded in x around 0
*-commutativeN/A
lower-fma.f64N/A
Applied rewrites12.3%
lift-cos.f64N/A
lift-sqrt.f64N/A
pow1/2N/A
metadata-evalN/A
pow-powN/A
sqr-powN/A
unpow-prod-downN/A
lower-*.f64N/A
lower-pow.f64N/A
metadata-evalN/A
lower-pow.f64N/A
lift-cos.f64N/A
lower-pow.f64N/A
metadata-evalN/A
lower-pow.f64N/A
lift-cos.f6412.3
Applied rewrites12.3%
Taylor expanded in x around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
+-commutativeN/A
lower-fma.f6413.1
Applied rewrites13.1%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f64N/A
associate-+r+N/A
lower-+.f64N/A
+-commutativeN/A
lower-+.f64N/A
inv-powN/A
lower-pow.f64N/A
pow-flipN/A
metadata-evalN/A
metadata-evalN/A
lower-pow.f64N/A
metadata-evalN/A
unpow2N/A
lower-*.f6423.8
Applied rewrites23.8%
if -7.5000000000000006e-155 < x Initial program 4.8%
Taylor expanded in x around 0
+-commutativeN/A
metadata-evalN/A
fp-cancel-sign-sub-invN/A
metadata-evalN/A
metadata-evalN/A
lower--.f6430.1
Applied rewrites30.1%
Taylor expanded in x around inf
Applied rewrites74.9%
(FPCore (x)
:precision binary64
(let* ((t_0 (sqrt (cos x))) (t_1 (pow (pow (cos x) -0.25) -1.0)))
(if (<= x -7.5e-155)
(fma
(* (fmod (exp x) (* t_1 t_1)) (fma 0.5 x -1.0))
x
(fmod (* (+ (+ (pow x -1.0) 0.5) (pow x -2.0)) (* x x)) t_0))
(* (fmod x t_0) 1.0))))
double code(double x) {
double t_0 = sqrt(cos(x));
double t_1 = pow(pow(cos(x), -0.25), -1.0);
double tmp;
if (x <= -7.5e-155) {
tmp = fma((fmod(exp(x), (t_1 * t_1)) * fma(0.5, x, -1.0)), x, fmod((((pow(x, -1.0) + 0.5) + pow(x, -2.0)) * (x * x)), t_0));
} else {
tmp = fmod(x, t_0) * 1.0;
}
return tmp;
}
function code(x) t_0 = sqrt(cos(x)) t_1 = (cos(x) ^ -0.25) ^ -1.0 tmp = 0.0 if (x <= -7.5e-155) tmp = fma(Float64(rem(exp(x), Float64(t_1 * t_1)) * fma(0.5, x, -1.0)), x, rem(Float64(Float64(Float64((x ^ -1.0) + 0.5) + (x ^ -2.0)) * Float64(x * x)), t_0)); else tmp = Float64(rem(x, t_0) * 1.0); end return tmp end
code[x_] := Block[{t$95$0 = N[Sqrt[N[Cos[x], $MachinePrecision]], $MachinePrecision]}, Block[{t$95$1 = N[Power[N[Power[N[Cos[x], $MachinePrecision], -0.25], $MachinePrecision], -1.0], $MachinePrecision]}, If[LessEqual[x, -7.5e-155], N[(N[(N[With[{TMP1 = N[Exp[x], $MachinePrecision], TMP2 = N[(t$95$1 * t$95$1), $MachinePrecision]}, Mod[Abs[TMP1], Abs[TMP2]] * Sign[TMP1]], $MachinePrecision] * N[(0.5 * x + -1.0), $MachinePrecision]), $MachinePrecision] * x + N[With[{TMP1 = N[(N[(N[(N[Power[x, -1.0], $MachinePrecision] + 0.5), $MachinePrecision] + N[Power[x, -2.0], $MachinePrecision]), $MachinePrecision] * N[(x * x), $MachinePrecision]), $MachinePrecision], TMP2 = t$95$0}, Mod[Abs[TMP1], Abs[TMP2]] * Sign[TMP1]], $MachinePrecision]), $MachinePrecision], N[(N[With[{TMP1 = x, TMP2 = t$95$0}, Mod[Abs[TMP1], Abs[TMP2]] * Sign[TMP1]], $MachinePrecision] * 1.0), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sqrt{\cos x}\\
t_1 := {\left({\cos x}^{-0.25}\right)}^{-1}\\
\mathbf{if}\;x \leq -7.5 \cdot 10^{-155}:\\
\;\;\;\;\mathsf{fma}\left(\left(\left(e^{x}\right) \bmod \left(t\_1 \cdot t\_1\right)\right) \cdot \mathsf{fma}\left(0.5, x, -1\right), x, \left(\left(\left(\left({x}^{-1} + 0.5\right) + {x}^{-2}\right) \cdot \left(x \cdot x\right)\right) \bmod t\_0\right)\right)\\
\mathbf{else}:\\
\;\;\;\;\left(x \bmod t\_0\right) \cdot 1\\
\end{array}
\end{array}
if x < -7.5000000000000006e-155Initial program 13.8%
Taylor expanded in x around 0
*-commutativeN/A
lower-fma.f64N/A
Applied rewrites12.3%
lift-cos.f64N/A
lift-sqrt.f64N/A
pow1/2N/A
metadata-evalN/A
pow-powN/A
sqr-powN/A
unpow-prod-downN/A
lower-*.f64N/A
lower-pow.f64N/A
metadata-evalN/A
lower-pow.f64N/A
lift-cos.f64N/A
lower-pow.f64N/A
metadata-evalN/A
lower-pow.f64N/A
lift-cos.f6412.3
Applied rewrites12.3%
Taylor expanded in x around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
+-commutativeN/A
lower-fma.f6413.1
Applied rewrites13.1%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f64N/A
associate-+r+N/A
lower-+.f64N/A
+-commutativeN/A
lower-+.f64N/A
inv-powN/A
lower-pow.f64N/A
pow-flipN/A
metadata-evalN/A
metadata-evalN/A
lower-pow.f64N/A
metadata-evalN/A
unpow2N/A
lower-*.f6423.8
Applied rewrites23.8%
if -7.5000000000000006e-155 < x Initial program 4.8%
Taylor expanded in x around 0
+-commutativeN/A
metadata-evalN/A
fp-cancel-sign-sub-invN/A
metadata-evalN/A
metadata-evalN/A
lower--.f6430.1
Applied rewrites30.1%
Taylor expanded in x around inf
Applied rewrites74.9%
Taylor expanded in x around 0
Applied rewrites50.0%
(FPCore (x)
:precision binary64
(let* ((t_0 (+ (pow x -1.0) 0.5))
(t_1 (sqrt (cos x)))
(t_2 (pow (pow (cos x) -0.25) -1.0))
(t_3 (* (fmod (exp x) (* t_2 t_2)) (fma 0.5 x -1.0))))
(if (<= x -7.5e-155)
(fma t_3 x (fmod (* (+ t_0 (pow x -2.0)) (* x x)) t_1))
(fma t_3 x (fmod (* t_0 (* x x)) t_1)))))
double code(double x) {
double t_0 = pow(x, -1.0) + 0.5;
double t_1 = sqrt(cos(x));
double t_2 = pow(pow(cos(x), -0.25), -1.0);
double t_3 = fmod(exp(x), (t_2 * t_2)) * fma(0.5, x, -1.0);
double tmp;
if (x <= -7.5e-155) {
tmp = fma(t_3, x, fmod(((t_0 + pow(x, -2.0)) * (x * x)), t_1));
} else {
tmp = fma(t_3, x, fmod((t_0 * (x * x)), t_1));
}
return tmp;
}
function code(x) t_0 = Float64((x ^ -1.0) + 0.5) t_1 = sqrt(cos(x)) t_2 = (cos(x) ^ -0.25) ^ -1.0 t_3 = Float64(rem(exp(x), Float64(t_2 * t_2)) * fma(0.5, x, -1.0)) tmp = 0.0 if (x <= -7.5e-155) tmp = fma(t_3, x, rem(Float64(Float64(t_0 + (x ^ -2.0)) * Float64(x * x)), t_1)); else tmp = fma(t_3, x, rem(Float64(t_0 * Float64(x * x)), t_1)); end return tmp end
code[x_] := Block[{t$95$0 = N[(N[Power[x, -1.0], $MachinePrecision] + 0.5), $MachinePrecision]}, Block[{t$95$1 = N[Sqrt[N[Cos[x], $MachinePrecision]], $MachinePrecision]}, Block[{t$95$2 = N[Power[N[Power[N[Cos[x], $MachinePrecision], -0.25], $MachinePrecision], -1.0], $MachinePrecision]}, Block[{t$95$3 = N[(N[With[{TMP1 = N[Exp[x], $MachinePrecision], TMP2 = N[(t$95$2 * t$95$2), $MachinePrecision]}, Mod[Abs[TMP1], Abs[TMP2]] * Sign[TMP1]], $MachinePrecision] * N[(0.5 * x + -1.0), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[x, -7.5e-155], N[(t$95$3 * x + N[With[{TMP1 = N[(N[(t$95$0 + N[Power[x, -2.0], $MachinePrecision]), $MachinePrecision] * N[(x * x), $MachinePrecision]), $MachinePrecision], TMP2 = t$95$1}, Mod[Abs[TMP1], Abs[TMP2]] * Sign[TMP1]], $MachinePrecision]), $MachinePrecision], N[(t$95$3 * x + N[With[{TMP1 = N[(t$95$0 * N[(x * x), $MachinePrecision]), $MachinePrecision], TMP2 = t$95$1}, Mod[Abs[TMP1], Abs[TMP2]] * Sign[TMP1]], $MachinePrecision]), $MachinePrecision]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := {x}^{-1} + 0.5\\
t_1 := \sqrt{\cos x}\\
t_2 := {\left({\cos x}^{-0.25}\right)}^{-1}\\
t_3 := \left(\left(e^{x}\right) \bmod \left(t\_2 \cdot t\_2\right)\right) \cdot \mathsf{fma}\left(0.5, x, -1\right)\\
\mathbf{if}\;x \leq -7.5 \cdot 10^{-155}:\\
\;\;\;\;\mathsf{fma}\left(t\_3, x, \left(\left(\left(t\_0 + {x}^{-2}\right) \cdot \left(x \cdot x\right)\right) \bmod t\_1\right)\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(t\_3, x, \left(\left(t\_0 \cdot \left(x \cdot x\right)\right) \bmod t\_1\right)\right)\\
\end{array}
\end{array}
if x < -7.5000000000000006e-155Initial program 13.8%
Taylor expanded in x around 0
*-commutativeN/A
lower-fma.f64N/A
Applied rewrites12.3%
lift-cos.f64N/A
lift-sqrt.f64N/A
pow1/2N/A
metadata-evalN/A
pow-powN/A
sqr-powN/A
unpow-prod-downN/A
lower-*.f64N/A
lower-pow.f64N/A
metadata-evalN/A
lower-pow.f64N/A
lift-cos.f64N/A
lower-pow.f64N/A
metadata-evalN/A
lower-pow.f64N/A
lift-cos.f6412.3
Applied rewrites12.3%
Taylor expanded in x around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
+-commutativeN/A
lower-fma.f6413.1
Applied rewrites13.1%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f64N/A
associate-+r+N/A
lower-+.f64N/A
+-commutativeN/A
lower-+.f64N/A
inv-powN/A
lower-pow.f64N/A
pow-flipN/A
metadata-evalN/A
metadata-evalN/A
lower-pow.f64N/A
metadata-evalN/A
unpow2N/A
lower-*.f6423.8
Applied rewrites23.8%
if -7.5000000000000006e-155 < x Initial program 4.8%
Taylor expanded in x around 0
*-commutativeN/A
lower-fma.f64N/A
Applied rewrites4.5%
lift-cos.f64N/A
lift-sqrt.f64N/A
pow1/2N/A
metadata-evalN/A
pow-powN/A
sqr-powN/A
unpow-prod-downN/A
lower-*.f64N/A
lower-pow.f64N/A
metadata-evalN/A
lower-pow.f64N/A
lift-cos.f64N/A
lower-pow.f64N/A
metadata-evalN/A
lower-pow.f64N/A
lift-cos.f644.5
Applied rewrites4.5%
Taylor expanded in x around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
+-commutativeN/A
lower-fma.f644.4
Applied rewrites4.4%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
lower-+.f64N/A
inv-powN/A
lower-pow.f64N/A
unpow2N/A
lower-*.f6430.8
Applied rewrites30.8%
(FPCore (x)
:precision binary64
(let* ((t_0 (sqrt (cos x))) (t_1 (pow (pow (cos x) -0.25) -1.0)))
(if (<= x -5e-144)
(fma
(* (fmod (exp x) (* t_1 t_1)) (fma 0.5 x -1.0))
x
(fmod (* (+ (+ (pow x -1.0) 0.5) (pow x -2.0)) (* x x)) t_0))
(fma
(*
(fmod
(fma (fma 0.5 x 1.0) x 1.0)
(* t_1 (pow (fma 0.125 (* x x) 1.0) -1.0)))
(fma 0.5 x -1.0))
x
(fmod (exp x) t_0)))))
double code(double x) {
double t_0 = sqrt(cos(x));
double t_1 = pow(pow(cos(x), -0.25), -1.0);
double tmp;
if (x <= -5e-144) {
tmp = fma((fmod(exp(x), (t_1 * t_1)) * fma(0.5, x, -1.0)), x, fmod((((pow(x, -1.0) + 0.5) + pow(x, -2.0)) * (x * x)), t_0));
} else {
tmp = fma((fmod(fma(fma(0.5, x, 1.0), x, 1.0), (t_1 * pow(fma(0.125, (x * x), 1.0), -1.0))) * fma(0.5, x, -1.0)), x, fmod(exp(x), t_0));
}
return tmp;
}
function code(x) t_0 = sqrt(cos(x)) t_1 = (cos(x) ^ -0.25) ^ -1.0 tmp = 0.0 if (x <= -5e-144) tmp = fma(Float64(rem(exp(x), Float64(t_1 * t_1)) * fma(0.5, x, -1.0)), x, rem(Float64(Float64(Float64((x ^ -1.0) + 0.5) + (x ^ -2.0)) * Float64(x * x)), t_0)); else tmp = fma(Float64(rem(fma(fma(0.5, x, 1.0), x, 1.0), Float64(t_1 * (fma(0.125, Float64(x * x), 1.0) ^ -1.0))) * fma(0.5, x, -1.0)), x, rem(exp(x), t_0)); end return tmp end
code[x_] := Block[{t$95$0 = N[Sqrt[N[Cos[x], $MachinePrecision]], $MachinePrecision]}, Block[{t$95$1 = N[Power[N[Power[N[Cos[x], $MachinePrecision], -0.25], $MachinePrecision], -1.0], $MachinePrecision]}, If[LessEqual[x, -5e-144], N[(N[(N[With[{TMP1 = N[Exp[x], $MachinePrecision], TMP2 = N[(t$95$1 * t$95$1), $MachinePrecision]}, Mod[Abs[TMP1], Abs[TMP2]] * Sign[TMP1]], $MachinePrecision] * N[(0.5 * x + -1.0), $MachinePrecision]), $MachinePrecision] * x + N[With[{TMP1 = N[(N[(N[(N[Power[x, -1.0], $MachinePrecision] + 0.5), $MachinePrecision] + N[Power[x, -2.0], $MachinePrecision]), $MachinePrecision] * N[(x * x), $MachinePrecision]), $MachinePrecision], TMP2 = t$95$0}, Mod[Abs[TMP1], Abs[TMP2]] * Sign[TMP1]], $MachinePrecision]), $MachinePrecision], N[(N[(N[With[{TMP1 = N[(N[(0.5 * x + 1.0), $MachinePrecision] * x + 1.0), $MachinePrecision], TMP2 = N[(t$95$1 * N[Power[N[(0.125 * N[(x * x), $MachinePrecision] + 1.0), $MachinePrecision], -1.0], $MachinePrecision]), $MachinePrecision]}, Mod[Abs[TMP1], Abs[TMP2]] * Sign[TMP1]], $MachinePrecision] * N[(0.5 * x + -1.0), $MachinePrecision]), $MachinePrecision] * x + N[With[{TMP1 = N[Exp[x], $MachinePrecision], TMP2 = t$95$0}, Mod[Abs[TMP1], Abs[TMP2]] * Sign[TMP1]], $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sqrt{\cos x}\\
t_1 := {\left({\cos x}^{-0.25}\right)}^{-1}\\
\mathbf{if}\;x \leq -5 \cdot 10^{-144}:\\
\;\;\;\;\mathsf{fma}\left(\left(\left(e^{x}\right) \bmod \left(t\_1 \cdot t\_1\right)\right) \cdot \mathsf{fma}\left(0.5, x, -1\right), x, \left(\left(\left(\left({x}^{-1} + 0.5\right) + {x}^{-2}\right) \cdot \left(x \cdot x\right)\right) \bmod t\_0\right)\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(\left(\left(\mathsf{fma}\left(\mathsf{fma}\left(0.5, x, 1\right), x, 1\right)\right) \bmod \left(t\_1 \cdot {\left(\mathsf{fma}\left(0.125, x \cdot x, 1\right)\right)}^{-1}\right)\right) \cdot \mathsf{fma}\left(0.5, x, -1\right), x, \left(\left(e^{x}\right) \bmod t\_0\right)\right)\\
\end{array}
\end{array}
if x < -4.9999999999999998e-144Initial program 14.2%
Taylor expanded in x around 0
*-commutativeN/A
lower-fma.f64N/A
Applied rewrites12.7%
lift-cos.f64N/A
lift-sqrt.f64N/A
pow1/2N/A
metadata-evalN/A
pow-powN/A
sqr-powN/A
unpow-prod-downN/A
lower-*.f64N/A
lower-pow.f64N/A
metadata-evalN/A
lower-pow.f64N/A
lift-cos.f64N/A
lower-pow.f64N/A
metadata-evalN/A
lower-pow.f64N/A
lift-cos.f6412.7
Applied rewrites12.7%
Taylor expanded in x around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
+-commutativeN/A
lower-fma.f6413.5
Applied rewrites13.5%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f64N/A
associate-+r+N/A
lower-+.f64N/A
+-commutativeN/A
lower-+.f64N/A
inv-powN/A
lower-pow.f64N/A
pow-flipN/A
metadata-evalN/A
metadata-evalN/A
lower-pow.f64N/A
metadata-evalN/A
unpow2N/A
lower-*.f6424.6
Applied rewrites24.6%
if -4.9999999999999998e-144 < x Initial program 4.8%
Taylor expanded in x around 0
*-commutativeN/A
lower-fma.f64N/A
Applied rewrites4.5%
lift-cos.f64N/A
lift-sqrt.f64N/A
pow1/2N/A
metadata-evalN/A
pow-powN/A
sqr-powN/A
unpow-prod-downN/A
lower-*.f64N/A
lower-pow.f64N/A
metadata-evalN/A
lower-pow.f64N/A
lift-cos.f64N/A
lower-pow.f64N/A
metadata-evalN/A
lower-pow.f64N/A
lift-cos.f644.5
Applied rewrites4.5%
Taylor expanded in x around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
+-commutativeN/A
lower-fma.f644.5
Applied rewrites4.5%
Taylor expanded in x around 0
+-commutativeN/A
lower-fma.f64N/A
unpow2N/A
lower-*.f644.5
Applied rewrites4.5%
(FPCore (x)
:precision binary64
(fma
(*
(fmod
(fma (fma 0.5 x 1.0) x 1.0)
(* (pow (pow (cos x) -0.25) -1.0) (pow (fma 0.125 (* x x) 1.0) -1.0)))
(fma 0.5 x -1.0))
x
(fmod (exp x) (sqrt (cos x)))))
double code(double x) {
return fma((fmod(fma(fma(0.5, x, 1.0), x, 1.0), (pow(pow(cos(x), -0.25), -1.0) * pow(fma(0.125, (x * x), 1.0), -1.0))) * fma(0.5, x, -1.0)), x, fmod(exp(x), sqrt(cos(x))));
}
function code(x) return fma(Float64(rem(fma(fma(0.5, x, 1.0), x, 1.0), Float64(((cos(x) ^ -0.25) ^ -1.0) * (fma(0.125, Float64(x * x), 1.0) ^ -1.0))) * fma(0.5, x, -1.0)), x, rem(exp(x), sqrt(cos(x)))) end
code[x_] := N[(N[(N[With[{TMP1 = N[(N[(0.5 * x + 1.0), $MachinePrecision] * x + 1.0), $MachinePrecision], TMP2 = N[(N[Power[N[Power[N[Cos[x], $MachinePrecision], -0.25], $MachinePrecision], -1.0], $MachinePrecision] * N[Power[N[(0.125 * N[(x * x), $MachinePrecision] + 1.0), $MachinePrecision], -1.0], $MachinePrecision]), $MachinePrecision]}, Mod[Abs[TMP1], Abs[TMP2]] * Sign[TMP1]], $MachinePrecision] * N[(0.5 * x + -1.0), $MachinePrecision]), $MachinePrecision] * x + N[With[{TMP1 = N[Exp[x], $MachinePrecision], TMP2 = N[Sqrt[N[Cos[x], $MachinePrecision]], $MachinePrecision]}, Mod[Abs[TMP1], Abs[TMP2]] * Sign[TMP1]], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(\left(\left(\mathsf{fma}\left(\mathsf{fma}\left(0.5, x, 1\right), x, 1\right)\right) \bmod \left({\left({\cos x}^{-0.25}\right)}^{-1} \cdot {\left(\mathsf{fma}\left(0.125, x \cdot x, 1\right)\right)}^{-1}\right)\right) \cdot \mathsf{fma}\left(0.5, x, -1\right), x, \left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right)\right)
\end{array}
Initial program 6.7%
Taylor expanded in x around 0
*-commutativeN/A
lower-fma.f64N/A
Applied rewrites6.1%
lift-cos.f64N/A
lift-sqrt.f64N/A
pow1/2N/A
metadata-evalN/A
pow-powN/A
sqr-powN/A
unpow-prod-downN/A
lower-*.f64N/A
lower-pow.f64N/A
metadata-evalN/A
lower-pow.f64N/A
lift-cos.f64N/A
lower-pow.f64N/A
metadata-evalN/A
lower-pow.f64N/A
lift-cos.f646.1
Applied rewrites6.1%
Taylor expanded in x around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
+-commutativeN/A
lower-fma.f646.2
Applied rewrites6.2%
Taylor expanded in x around 0
+-commutativeN/A
lower-fma.f64N/A
unpow2N/A
lower-*.f646.2
Applied rewrites6.2%
herbie shell --seed 2025057
(FPCore (x)
:name "expfmod (used to be hard to sample)"
:precision binary64
(* (fmod (exp x) (sqrt (cos x))) (exp (- x))))